Suppose that after some calculations, I find


What sort of operations do I need to do in Mathematica such that the output becomes


This corresponds to making the replacement \begin{align} a(x)\frac{d^2g}{dx^2}=\frac{d}{dx}\left(a(x)\frac{dg}{dx}\right)-\frac{da}{dx}\frac{dg}{dx} \end{align} and ignoring the $\frac{d}{dx}\left(a(x)\frac{dg}{dx}\right)$ term.

In general, $g[x]$ and $h[x]$ can be anything, with the only commonality being that they are twice differentiated. I'm thinking that the solution will involved Replace[] and Map[], but I'm not sure how to apply them.

Additional Information

I am interested in terms like \begin{align} \frac{a_1(x)^{n_1}a_2(x)^{n_2}\cdots}{a_3(x)^{m_1}a_4(x)^{m_2}\cdots}\frac{d^2g}{dx^2} \end{align} where $a_1$ or $a_3$ might be $g(x)$ itself. Then, the Mathematica code should perform the operation: \begin{align} \frac{a_1(x)^{n_1}a_2(x)^{n_2}\cdots}{a_3(x)^{m_1}a_4(x)^{m_2}\cdots}\frac{d^2g}{dx^2}\to-\frac{d}{dx}\left(\frac{a_1(x)^{n_1}a_2(x)^{n_2}\cdots}{a_3(x)^{m_1}a_4(x)^{m_2}\cdots}\right)\frac{dg}{dx} \end{align}


1 Answer 1


Try the code

rule = Derivative[2][f_][x_] g__ :> -D[f@x, x] D[Times@g, x];
a1[x]/g[x] D[g[x], x, x] + b[x] D[h[x], x, x] + c[x]^2 D[j[x], x, x]; /. rule;

which seems to do what you want. The difficulty was the peculiar FullForm of the Derivative function as seen in rule.

  • $\begingroup$ Ah, that's great! Thanks! $\endgroup$
    – user85503
    Apr 18, 2019 at 18:38
  • 1
    $\begingroup$ @user85503 Note the simpllification. $\endgroup$
    – Somos
    Apr 18, 2019 at 18:41

Your Answer

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

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