# Indefinite order of differential operator

In the latest version of Mathematica, D can compute derivatives of symbolic order, that is, the $n^{\text{th}}$ (partial) derivative, returning an expression containing $n$, without the need to specify the value of $n$.

My question is, does there exist any way to expand the functionality a little further to compute something like $(\partial_x-1)^n f(x)$?

My present attempt is to consider it as a composition of the same operation $n$ times:

Nest[D[#, x] - # &, f[x], n]


But in this way one has to set the value of $n$ first, which is not what I want.

Update

For the information of those interested, the first five results are given by

TableForm[Table[{StringTemplate["n = "][i], Nest[D[#, x] - # &, f[x], i]}, {i, 5}], TableAlignments -> Right] Yes they are summation of binomials. But my point is how to get an expression with an un-value-set $n$.

Additionally, as I mentioned in the comment, e.g., $f(x)=x^m \mathrm e^{-x}$, I hope to verify an identity of LaguerreL: • What would you get then? Certainly nothing better than Sum[Binomial[k, n] (-1)^(n - k) D[f[x], {x, k}], {k, 0, n}] unless you specify f. But something like $(\partial_x-g(x))^n f(x)$ would be definitely more interesting. – Henrik Schumacher Aug 17 '18 at 9:36
• @HenrikSchumacher I assume that in this case the $1$ was the Identity operator. – rhermans Aug 17 '18 at 9:41
• @HenrikSchumacher say, $f(x)=x^m \mathrm e^{-x}$. – Αλέξανδρος Ζεγγ Aug 17 '18 at 9:50

Consider the operator:

op = Exp[x] D[Exp[-x] #, x]&;


Operating on a function $f(x)$ gives:

Simplify[op @ f[x]]


-f[x] + f'[x]

which is the desired shift operation. Clearly, nesting the above operation yields:

op @* op -> (Exp[x] D[Exp[-x] #, {x, 2}]&)
op @* op @* op -> (Exp[x] D[Exp[-x] #, {x,3}]&)


and so on. So, we can define a shift operator with:

shiftD[expr_, {x_, shift_, n_}] := Simplify @ Replace[
Exp[shift x] D[Exp[-shift x] expr, {x, n}],
Exp[shift x] Inactive[Sum][e_, iter_] :> Sum[Exp[shift x] e, iter]
]


Example:

r = shiftD[f[x], {x, 1, n}];
r //TeXForm


$\sum _{K(1)=0}^n (-1)^{K(1)} \binom{n}{K(1)} \frac{\partial ^{n-K(1)}f(x)}{\partial x^{n-K(1)}}$

Compare to explicit values for n:

r1 = NestList[D[#, x] - #&, f[x], 3]
r2 = Table[r, {n, 0, 3}]

r1 === r2


{f[x], -f[x] + f'[x], f[x] - 2 f'[x] + f''[x], -f[x] + 3 f'[x] - 3 f''[x] + f'''[x]}

{f[x], -f[x] + f'[x], f[x] - 2 f'[x] + f''[x], -f[x] + 3 f'[x] - 3 f''[x] + f'''[x]}

True

One can generalize this to arbitrary shifts:

shiftD[expr_, {x_, shift_, n_}] := With[{int = Integrate[shift, x]},
Simplify @ Replace[
Exp[int] D[Exp[-int] expr, {x, n}],
Exp[int] Inactive[Sum][e_, iter_] :> Sum[Exp[int] e, iter]
]
]


For example:

r = shiftD[f[x], {x, x, n}];
r //TeXForm


$\sum _{K(1)=0}^n \sqrt{\pi } e^{\frac{x^2}{2}} 2^{K(1)} x^{-K(1)} \binom{n}{K(1)} \frac{\partial ^{n-K(1)}f(x)}{\partial x^{n-K(1)}} \, _2\tilde{F}_2\left(\frac{1}{2},1;\frac{1}{2} (-K(1)-1)+1,1-\frac{K(1)}{2};-\frac{x^2}{2}\right)$

Compare:

r1 = Simplify @ NestList[D[#, x] - # x&, f[x], 3]
r2 = Table[r, {n, 0, 3}]

r1 === r2


{f[x], -x f[x] + f'[x], (-1 + x^2) f[x] - 2 x f'[x] + f''[x], -x (-3 + x^2) f[x] + 3 (-1 + x^2) f'[x] - 3 x f''[x] + f'''[x]}

{f[x], -x f[x] + f'[x], (-1 + x^2) f[x] - 2 x f'[x] + f''[x], -x (-3 + x^2) f[x] + 3 (-1 + x^2) f'[x] - 3 x f''[x] + f'''[x]}

True