I am trying to evaluate multiple independent expressions with common parts. I would like Mathematica to somehow give me this common parts. It's probably not so clear, so let me give you an example.
Let's say I want to compute both of those expressions:
x0 = (-b + Sqrt[b²-4ac])/(2a)
x1 = (-b - Sqrt[b²-4ac])/(2a)
a
, b
and c
are three scalars but I don't know their values yet.
What I would like is Mathematica telling me to define:
delta = Sqrt[b²-4ac]
and then I can get:
x0 = (-b + delta)/(2a)
x1 = (-b - delta)/(2a)
Of course this example is easy and can be done manually just by looking at it. But the case I am trying to solve is much more complex in size and cannot be easily done manually.
Here is a concrete example:
t = (-a02 a11 b0+a01 a12 b0+a01 a02 b1-a00 a12 b1-a01^2 b2+a00 a11 b2)/
(a02^2 a11-2 a01 a02 a12+a01^2 a22+a00 (a12^2-a11 a22))
u = (-a12^2 b0+a11 a22 b0+a02 a12 b1-a01 a22 b1-a02 a11 b2+a01 a12 b2)/
(a02^2 a11-2 a01 a02 a12+a01^2 a22+a00 (a12^2-a11 a22))
v = (a02 a12 b0-a01 a22 b0-a02^2 b1+a00 a22 b1+a01 a02 b2-a00 a12 b2)/
(a02^2 a11-2 a01 a02 a12+a00 a12^2+a01^2 a22-a00 a11 a22)
There are clearly some common parts here and there (of course the denominator). I'd like Mathematica to tell me to declare a few intermediate (smaller) expressions to compute the final t,u and v.
Even better would be if it could for example detect that the denominator is the determinant of a 3x3 matrix and tell me that. But maybe this is too difficult. :-)
Coefficient
orCoefficientList
. $\endgroup$candidates = Select[Intersection[Level[x0, Infinity], Level[x1, Infinity]], Depth@# > 3 &]
. But the important thing (I suppose) is the cost of the calc. Impossible to foresee using algebra only $\endgroup$