# Replacement of polynomial variable with differential operator

I have a very simple question.

If I have a polynomial in x say, $f(x)$, how to construct the differential operator $f(\frac{d}{dx})$?

Failed Attempt:

In[739]:= f[x] = a0 + a1*x + a2*x^2 + a3*x^3;

f[x] /. {x -> Function@D[#, x], x^n_ -> Function@D[#, {x, n}]}

Out[740]= a0 + a1 (\!$$\*SubscriptBox[\(\[PartialD]$$, $$x$$]#1\) &) + a2 (\!$$\*SubscriptBox[\(\[PartialD]$$, $${x, 2}$$]#1\) &) + a3 (\!$$\*SubscriptBox[\(\[PartialD]$$, $${x, 3}$$]#1\) &)

• If $f(x)=2$, do you want $f(\frac{d}{dx})(x)$ to be $2x$ or $2$? Apr 15 '18 at 14:48
• @Carl Woll I want it to be $2$ Apr 15 '18 at 21:10
• Ok, thanks, then my differential operator paclet would not be of interest to you. Apr 15 '18 at 21:20

f[x] = a0 + a1*x + a2*x^2 + a3*x^3;
f1[x_] = (f[x] /. {x -> D[#, x], x^n_ -> D[#, {x, n}]}) &;
f1[x][Exp[m x]]


a0 + a1 E^(m x) m + a2 E^(m x) m^2 + a3 E^(m x) m^3

Rules can be shortened using the _. pattern. A function can be defined as

g[y_] := f[x] /. {x^n_. -> D[y, {x, n}]}


For example, g[x^4] gives

a0 + 4*a1*x^3 + 12*a2*x^2 + 24*a3*x

• ha ha, I am 10 seconds early :) Apr 15 '18 at 11:35