Let's say I have :


where a and b are constant

I would need to get

(a*d2/dx2 + b*d/dx)u[x]

Can anyone tell me how I could to proceed?

  • 1
    $\begingroup$ Do you mean you just want the output to be formatted in TraditionalForm? Then this could be a duplicate of How to make traditional output for derivatives. But I guess you want the factorization with u appearing only once on the right. Is that the main issue? In that case, is it OK to always assume that x is the independent variable? $\endgroup$
    – Jens
    Jun 11, 2014 at 18:40
  • $\begingroup$ Hi Jens, Yes I want to factorize u[x] where x is independent variable and u[x] represent u is a function of x $\endgroup$
    – user15881
    Jun 11, 2014 at 19:12

1 Answer 1


Since the desired form is not valid Mathematica code (for the operations it is supposed to represent), it has to be done using strings and/or HoldForm. Here is one way:

First I define the expression to be transformed:

expr = a*u''[x]+b*u'[x];

Then define the formatting of a variable dOp that is supposed to represent the differential operator or its powers. This is done using Format - for the first power and i-th powers separately.

ClearAll[dOp, i];

Power[dOp, i_] ^:= dOp[i];

Format[dOp] = "d/dx";

Format[dOp[i_]] := "d" <> # <> "/dx" <> # &[ToString[i]];

HoldForm[(#) u[x]] &[expr /. u -> (Exp[dOp #] &) /. x -> 0]

(b d/dx+a d2/dx2) u[x]

The last instruction takes expr and replaces u by an exponential function whose derivative with respect to x can then be calculated and yields appropriate powers of dOp. The above formatting then kicks in and gets applied to these powers.

At that stage, we have the form (b d/dx+a d2/dx2). Lastly, the function u[x] has to be put back at the end. This is done by the left-most part of the last line, HoldForm[(#) u[x]]& which then wraps the differential operator so that the order is maintained with u[x] on the right-hand side of the output. The HoldForm is added last because the previous manipulations wouldn't work if carried out inside of HoldForm.

  • $\begingroup$ Wonderful, thank you very much. $\endgroup$
    – user15881
    Jun 11, 2014 at 21:44
  • $\begingroup$ OK, since it works for you I added some explanations, too... $\endgroup$
    – Jens
    Jun 11, 2014 at 22:22

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.