Playing with expressions and derivatives

How are expressions, derivatives, and equations actually represented in Mathematica?

eq=a x^2+b x+c==0;
eq//FullForm

sol=Solve[eq,x]
FullForm[sol]

der=f'[x]//FullForm
der2=D[u[x,y,z],x,x,y]//FullForm
LHO=D[x[t],t,t]+(ω^2)x[t]==0//FullForm
SchEq=I D[ψ[x,t],t]==-D[ψ[x,t],x,x]/2//FullForm

How to find a derivative in an expression?

Cases[der, Derivative[___][_][___]]
Cases[der2, Derivative[___][_][___]]
(* Function Cases searches by default only at level 1 ! *)
Cases[SchEq, Derivative[___][_][___]]
(* This finds all derivatives at any level *)
Cases[SchEq, Derivative[___][_][___],Infinity] 
(* This finds orders of derivatives *)
orders=Cases[SchEq, Derivative[d___][_][___]->{d},Infinity]

How to construct an array with all combinations of variables for a loop over all derivatives?

variables={x,y,z};
order=2;
list1=Table[variables,{i,1,order}]
list2=Flatten[list1]
list3=Sort[list2]
list4=Subsets[list3,order]
list5=Union[list4]

variables={x,y,z};
order=2;
(* These 3 lines produce the same result, which do you prefer? *)
Union[Subsets[Sort[Flatten[Table[variables,{i,1,order}]]],order]]
Subsets[Table[variables,{i,1,order}]//Flatten//Sort,order]//Union
(Table[variables,{i,1,order}]//Flatten//Sort)~Subsets~order//Union

Change of variables in differential equations

Run TMF064.Package.m first!

ChangeOfVariables[{D[x[t],t,t]+(ω^2)x[t]==0},
{t->T+β,x[t]->α X[T]},
{t},{x},
{T},{X},
showAll=1
]

Example of ordinary differential equation invariant under Galilean transformation

(* in general D[y[x],x,x]==f[x, x D[y[x],x]-y[x]] *)
ChangeOfVariables[{D[y[x],x,x]==f[x,x D[y[x],x]-y[x]]},
{x->X,y[x]->Y[X]+ϵ X},
{x},{y},
{X},{Y},
showAll=1
]

Heat equation

ChangeOfVariables[{D[u[x,t],x,x]==D[u[x,t],t]},
{x->X-2T ϵ,t-> T,u[x,t]->U[X,T]Exp[X ϵ-T ϵ^2]},
{x,t},{u},
{X,T},{U},
showAll=1
]

Hamiltonian of two particles in 1D expressed in the center-of-mass system

ChangeOfVariables[{-D[ψ[X1,X2],X1,X1]/(2*m1)-D[ψ[X1,X2],X2,X2]/(2*m2)==0},
{X1->XT+m2*XR/(m1+m2),X2->XT-m1*XR/(m1+m2),ψ[X1,X2]->Ψ[XT,XR]},
{X1,X2},{ψ},
{XT,XR},{Ψ},
showAll=0
]

3-dimensional Schrödinger equation

SchEq=Expand[ChangeOfVariables[{-1/2(D[ψ[x,y,z],x,x]+D[ψ[x,y,z],y,y]+D[ψ[x,y,z],z,z])+V[Sqrt[x^2+y^2+z^2]]ψ[x,y,z]-Energy ψ[x,y,z]==0},
{x->r Sin[θ]Cos[ϕ],y->r Sin[θ]Sin[ϕ],z->r Cos[θ],ψ[x,y,z] -> χ[r,θ,ϕ]/r},
{x,y,z},{ψ},
{r,θ,ϕ},{χ},
showAll=0
]]

Simplify[SchEq,Assumptions->r>0]

Angular momentum operator in spherical coordinates

FullSimplify[ChangeOfVariables[{-I( y D[ψ[x,y,z],z]-z D[ψ[x,y,z],y])==a1,-I( z D[ψ[x,y,z],x]-x D[ψ[x,y,z],z])==a2,-I( x D[ψ[x,y,z],y]-y D[ψ[x,y,z],x])==a3},
{x->r Sin[θ]Cos[ϕ],y->r Sin[θ]Sin[ϕ],z->r Cos[θ],ψ[x,y,z] -> χ[r,θ,ϕ]},
{x,y,z},{ψ},
{r,θ,ϕ},{χ},
showAll=1
]]

Lx[f_]:=-I( y D[f,z]-z D[f,y])
Ly[f_]:=-I( z D[f,x]-x D[f,z])
Lz[f_]:=-I( x D[f,y]-y D[f,x])

Simplify[Lx[Lx[v[x,y,z]]]+Ly[Ly[v[x,y,z]]]+Lz[Lz[v[x,y,z]]]]

L1[f_]:=I( Sin[ϕ] D[f,θ]-Cot[θ]Cos[ϕ]D[f,ϕ])
L2[f_]:=I( -Cos[ϕ] D[f,θ]-Cot[θ]Sin[ϕ]D[f,ϕ])
L3[f_]:=-I D[f,ϕ]
Simplify[L1[L1[v[r,θ,ϕ]]]+L2[L2[v[r,θ,ϕ]]]+L3[L3[v[r,θ,ϕ]]]]