Say I have an expression of the form:


Is there a Mathematica function, similar to Expand or Simplify that would take this expression and return:

$$ f(r) \frac{d}{dr}\frac{rf'(r)}{h(r)} $$

For context, I am using Mathematica to help me calculate the Einstein field equations, but I want to solve the equations myself. I would like Mathematica to give them to me in the second, more digestible form.

  • $\begingroup$ Well, Mathematica is able to recognize that the forms are identical, i.e. (-r f[r] f'[r] h'[r])/h[r]^2 + f[r] (r f''[r] + f'[r])/h[r] == f[r] D[r f'[r]/h[r], r] // FullSimplify, but I've generally had a pretty hard time getting one symbolic expression to be in an exact format. Since they're equivalent Mathematica is usually happy to just deal with whatever it considers to be the "simplest", in its terms, but not necessarily your terms. $\endgroup$
    – ktm
    Jan 30, 2018 at 22:21
  • $\begingroup$ Actually, things may be even worse than as described by @user6014. Consider D[f[r], r] g[r] + D[g[r], r] f[r], which has a LeafCount of 15, and D[f[r] g[r], r], which has a LeafCount of 8. However, even it FullSimplify could transform the first expression into the second, Mathematica automatically would transform it back to the first expression! $\endgroup$
    – bbgodfrey
    Jan 31, 2018 at 2:36
  • 2
    $\begingroup$ People here generally like users to post code as Mathematica code instead of images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this this meta Q&A helpful $\endgroup$
    – Michael E2
    Jan 31, 2018 at 3:05
  • $\begingroup$ @MichaelE2 I was wondering that. I am on mobile atm, but I'll change the formulas to code when I can. $\endgroup$
    – Andrea
    Jan 31, 2018 at 10:29

1 Answer 1


In some cases you can use DSolve to try and reduce your expression by guessing an appropriate form. For example, the form g[x] f'[x] + f[x] g'[x] can be integrated, so we just try the following:

DSolve[g[x] f'[x] + f[x] g'[x] == y'[x], y[x], x]
(*{{y[x] -> C[1] + f[x] g[x]}}*)

So by guessing that g[x] f'[x] + f[x] g'[x] can be written as the derivative of some other thing, DSolve found the integrated version. However, this only works if you can guess the correct integrated form and even then there's no guarantee that DSolve will find something nice.


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.