In papers in physics and mathematics one often encounters longer mathematical expressions which have to be, for intuition and typesetting, expressed using symbols standing for recurring patterns in the expressions.
Consider for instance a set of equations where "$r^2 + a^2 \cos^2\! \vartheta$" and "$r^2 - 2M r + a^2$" appear at multiple points so we decide to define the symbols $\Sigma \equiv r^2 + a^2 \cos^2 \! \vartheta$ and $\Delta \equiv r^2 - 2M r + a^2$ as placeholders which shorten my expressions. (This example comes from the metric of a spinning black hole.)
Now, when I make computations, I obtain expressions of the sort $$(\Delta + 2Mr - a^2 \sin^2\! \vartheta)(\Sigma -2Mr + a^2 \sin^2\! \vartheta)$$ In Mathematica I write
Sig = r^2 + a^2 Cos[th]^2;
Delt = r^2 - 2 M r + a^2;
expression = (Delt + 2 M r - a^2 Sin[th]^2) (Sig - 2 M r + a^2 Sin[th]^2)
and obtain (r^2 + a^2 Cos[th]^2)(r^2 - 2 M r + a^2)
which is obviously just $\Delta \Sigma$. I would like Mathematica to return $\Delta \Sigma$ automatically, i.e. maximize the amount of the expression which can be "unsubstituted" by the original set of symbols.
A simple replacement rule of the sort expression/.{r^2 - 2 M r + a^2->Delt, r^2 + a^2 Cos[th]^2->Sig}
is not what I am looking for because it does not crack things such as (r(r-2M)+a^2)
or (r^2 + a^2 - a^2 Sin[th]^2)
. One could build a set of replacement rules which somehow list these variations but I do not think it would be able to take care of e.g.
(r^2 - 2 M r + a^2)(r^2 + a^2) - a^2 Sin[th]^2 (r^2 + 2 M r + a^2)
(An example of real output from FullSimplify) to reduce to $\Delta \Sigma - 4 M r a^2 \sin^2 \! \vartheta$.
I think this should be somehow possible through the modification of the ComplexityFunction
and TransformationFunctions
for FullSimplify but it is not clear to me how.
a^2
factors determines whetherexpression
is or is not equivalent toΔ Σ
. As coded above, it is not. $\endgroup$