I have a function which is a function of some scalar variables called :$x,y,t,\rho$ I want to calculate its derivative in the form of : $(\partial_{t}-\partial_{z})^m (\partial_{x} -\partial_{y})^n$ where $m$ and $n$ could be 1,2,3,4 each time.How I can get this derivative correctly?To say the whole thing once: $(\partial_{t}-\partial_{z})^m (\partial_{x} -\partial_{y})^n f(x,y,t,\rho)$,Could anybody help me?

  • 2
    $\begingroup$ I assume that the partial with respect to z is intended to be with respect to ρ then der[m_, n_] = ((D[#, t] - D[#, ρ])^m*(D[#, x] - D[#, y])^n) &@f[x, y, t, ρ]; $\endgroup$
    – Bob Hanlon
    Apr 20, 2022 at 5:25
  • 3
    $\begingroup$ Related: mathematica.stackexchange.com/q/5030/4999 $\endgroup$
    – Michael E2
    Apr 20, 2022 at 5:31
  • $\begingroup$ @Bob Hanlon, It works. Thank you $\endgroup$
    – Ali
    Apr 20, 2022 at 6:12
  • 2
    $\begingroup$ @BobHanlon I think the OP wants the power of an operator, eg (d/dx)^n f(x)=f^{n} (x) giving the n-th derivative, but the code above just gives the power, eg (f'(x))^n. Maybe something with Fold would work. $\endgroup$
    – Hans Olo
    Apr 20, 2022 at 13:49
  • 2
    $\begingroup$ @HansOlo - Thanks for explaining the notation used. I have posted an answer using a nested Nest $\endgroup$
    – Bob Hanlon
    Apr 20, 2022 at 15:15

1 Answer 1


In a comment, Hans Olo stated that the powers used in the notation are intended to indicate the number of times the differential operators are applied. I would then also assume that the product shown is intended to reflect concatenation of the operators. If that is the case, a nested Nest is needed


dOp[func_, m_, n_] :=
 Nest[(D[#, x] - D[#, y]) &, Nest[(D[#, t] - D[#, ρ]) &, func, m], n]

For example,

dOp[f[x, y, t, ρ], 0, 0]

(* f[x, y, t, ρ] *)

dOp[f[x, y, t, ρ], 0, 1]

enter image description here

dOp[f[x, y, t, ρ], 1, 0]

enter image description here

dOp[f[x, y, t, ρ], 2, 2]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.