# How to calculate an iterated derivative in Mathematica?

I try to calculate an inverse Mellin transform for $$s^n \Gamma(s)$$: $$x\frac{\mathrm{d}}{\mathrm{d}x}\left(x\frac{\mathrm{d}}{\mathrm{d}x}\left(e^{-x}\right)\right)$$ for $$n=2$$ for $$n$$ as $$\left(x\text{}\frac{\partial }{\partial x}\right)^ne^{-x}$$ I try NestList and Do but it does not work; it is simple but I don't know how to do it.

• Have you seen InverseMellinTransform[] already? Feb 4 at 10:57
• Can you show what you tried with NestList and Do so we can see where the issue is? Feb 4 at 10:58
• Possible duplicate: (214105). Also related: (67184), (71643), (125277). Feb 4 at 19:05

One way is:

f[n_] := If[n == 0, E^-x, (-1)^n*Nest[x D[#, x] &, x D[Exp[-x], x], n - 1] // Simplify]

(*for n >= 0 and n is integer *)

f[2]
(*E^-x (-1 + x) x*)

Grid[{Table[f[n], {n, 0, 5}], Table[InverseMellinTransform[s^n Gamma[s], s, x], {n, 0, 5}]}, Frame -> All]


• hi @Mariusz Iwaniuk I LIKE YOUR METHOD IT IS MORE SIMPLE IT IS P0SSIBLE TO GET THE FORMULA INCLUSIVE WHEN F(0) WHEN N=0 GIVE AND ERROR THAT THE VALUES OBVIOSLY IS THE FUNCTION ITSELF, AND IT IS POSSIBLE TO GET THE TERM WHE N=0 THANKS Feb 5 at 11:19
• @capea. I edited the answer. Feb 6 at 11:01
• Thanks @Mariusz Iwaniuk works fine Feb 6 at 19:22
\$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

Clear["Global*"]


There are multiple ways of implementing the differential operator

dOp1[f_, n_Integer?NonNegative, sym : _Symbol : x] :=
Nest[Simplify[sym*D[#, sym]] &, f, n]

dOp2[f_, n_Integer?NonNegative, sym : _Symbol : x] :=
Sum[StirlingS2[n, k]*sym^k*D[f, {sym, k}], {k, 0, n}]

dOp3[f_, n_Integer?NonNegative, sym : _Symbol : x] :=
D[f /. sym :> E^sym, {sym, n}] /. sym :> Log[sym]


Comparing the implementations

And@@Table[dOp1[f[x], n] == dOp2[f[x], n] == dOp3[f[x], n], {n, 0, 15}] //
Simplify

(* True *)


For the special case of f[x] == E^-x

And@@With[{f = E^-x},
Table[dOp1[f, n] == dOp2[f, n] == dOp3[f, n] ==
(-1)^n*InverseMellinTransform[s^n Gamma[s], s, x], {n, 0, 15}] //
Simplify]

(* True *)


You are basically differentiating with respect to Log[x], which is possible using the ResourceFunction "ChainD":

ResourceFunction["ChainD"][Exp[-x],{Log[x],2}]
`

-E^-x x + E^-x x^2