I'm trying to workout a long expression with derivations, the thing is I can't seem to transfer this problem to code.

What I need is a operator $D = l^\mu \frac{\partial}{\partial x^\mu} $ where $l^\mu$ is a vector. Problem is I have long expression, for expample I need to write a equation $$(D + \epsilon + \kappa + \gamma )(D -\omega + \kappa)\phi == 0, $$ where all functions $(\epsilon, \gamma, \kappa, \phi) = (\epsilon(x^i), \gamma(x^i), \kappa(x^i), \phi(x^i)) $.

For this reasons defining $D$ as

DD = Sum[l[[i]] D[#,x[[i]]],{i,1,4}]&

Is not usefull because I would have to expand eqaution for $\phi$ and then rewrite is in terms $D[\epsilon,\kappa,\gamma,\phi]...$. Note that I choose to wtite $D$ as $DD$ in code so it isn't confused with Mathematicas derivative funciton.

There are other expressions which I need to write out and other derivatives. Is there any way to define $D$ so that I can just write the equation and get the result?


1 Answer 1



x = {a, b, c, d};
l = {1, 2, 3, 4};
DD = l . D[#, {x}]&

and then use prefix notation to approximate your expression:

(DD[#] + ε + κ + γ &) @ (DD[#] - ω + κ &) @ φ
  • $\begingroup$ Yes, but it becomes very difficult to write out the equations in terms of $DD[expr]$. I would like if it were possible to define $DD$ in such way, where we can just write out the expression and $DD$ is automatically mapped to expressions. $\endgroup$
    – Nitaa a
    Mar 13, 2022 at 10:11
  • $\begingroup$ I guess I still don't understand what you need. What do you mean by mapping automatically? Can you give an example of what you need? $\endgroup$
    – Roman
    Mar 13, 2022 at 10:12
  • $\begingroup$ Considering the equation give above I would like to write (having already defined $𝑒𝑒,𝑔𝑔,𝑦𝑦,𝑜𝑜,𝑘𝑘,𝑝ℎ$ as functions of $𝑥^𝑖$) (DD + ee + gg + yy)(D-oo+kk)ph ==0. Now I would like automatically get the expressions as DD[DD[ ph]] + DD[ ee ph] + DD[ gg ph] + DD[ kk ph] + ee kk ph + gg kk ph - DD[ oo ph] - ee oo ph - gg oo ph + DD[ ph yy] + kk ph yy - oo ph yy == 0 which is the written out form. Or define $DD$ in such a way, that this is done automatically, which was my original question. $\endgroup$
    – Nitaa a
    Mar 13, 2022 at 10:19
  • $\begingroup$ Automatically means not having to rewrite the expressions by hand. $\endgroup$
    – Nitaa a
    Mar 13, 2022 at 10:25
  • 1
    $\begingroup$ ok maybe now I got it, please see update $\endgroup$
    – Roman
    Mar 13, 2022 at 11:14

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.