# Reduction of differential operators

Suppose my code outputs the expression

$$\frac{f^{(0,2)}(r,\phi )+r \left(f^{(1,0)}(r,\phi )+r f^{(2,0)}(r,\phi )\right)}{r^2}$$

This is simply the Laplacian $$\nabla^2f(r, \phi)$$. Is there a way for Mathematica to recognize and simplify this?

• I do not know how this will work. How is Mathematica going to know that $\nabla^2(r,\phi)$ is Laplacian in polar coordinates vs. $\nabla^2(x,y)$ in cartesian coordinates? i.e. if you managed to convert it to that form, how will you use it? When you tell M now to give you the Laplacian, you have to tell it the coordinates system. if you just want this for typestting and not for code, use Latex. That is what I do. – Nasser Jan 12 at 18:23
• @Nasser You can specify the coordinates for the Laplacian. This problem arises when my output is four lines of algebra and I'd like it to reduce to something that is more recognizable – Histoscienology Jan 12 at 18:40
• People here generally like users to post code as Mathematica code instead of just 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 – Michael E2 Jan 12 at 19:13

You'd have to write the result with an inactive Laplacian[], or it will expand.

Example:

expr = Laplacian[r f[r, θ], {r, θ}, "Polar"]
(*
2*Derivative[1, 0][f][r, θ] +
(f[r, θ] + Derivative[0, 2][f][r, θ] + r*Derivative[1, 0][f][r, θ])/r +
r*Derivative[2, 0][f][r, θ]
*)


Transformation functions:

xfLaplacian[{f_, h_}, v_List, chart_] :=
Function[e,
e /. First@
Solve[Laplacian[f, v, chart] == Inactive[Laplacian][f, v, chart],
D[h @@ v, {First@v, 2}]]] /.
HoldPattern[s_Solve] :> With[{sol = s}, sol /; True];
xfLaplacian[f_, v_List, chart_] :=
Function[e,
e /. First@
Solve[Laplacian[f, v, chart] == Inactive[Laplacian][f, v, chart],
D[f, {First@v, 2}]]] /.
HoldPattern[s_Solve] :> With[{sol = s}, sol /; True];


Tests:

Simplify[expr,
TransformationFunctions -> {Automatic, xfLaplacian[f[r, θ], {r, θ}, "Polar"]}]
(*  f[r, θ]/r + r*Inactive[Laplacian][f[r, θ], {r, θ}, "Polar"] +
2*Derivative[1, 0][f][r, θ]  *)

Simplify[expr,
TransformationFunctions -> {Automatic, xfLaplacian[{r f[r, θ], f}, {r, θ}, "Polar"]}]
(*  Inactive[Laplacian][r f[r, θ], {r, θ}, "Polar"]  *)


For Solve to work in xfLaplacian[], the derivative has to be a fairly simple expression, which is why the head f needs to be specified in this last example.