First up, I'm new to Mathematica and MathematicaSE, so please correct me if I'm doing anything wrong.
My problem is the following: I have a bunch of complicated polynomials in $3$ variables $x_1,x_2,x_3$ in which I would like to gather up certain terms, namely the following: $$x_3, \hspace{2mm} x_1^2 x_2^2, \hspace{2mm} (x_1^2+x_2^2), \hspace{2mm} (x_1^2-x_2^2)$$ So I'd like to have a function in which I can input a polynomial, for example $3 x_1^4 x_3 - 3 x_2^4 x_3 + 6 x_1^2 x_3^3 - 6 x_2^2 x_3^3$, and the result is $3 (x_1^2 - x_2^2) (x_1^2 + x_2^2) x_3 + 6 (x_1^2 - x_2^2) x_3^3$. I've played around a bit with Collect, Expand and Simplify. The possibilities I've come up with so far are
f[p_]:=Collect[Simplify[ExpandAll[p]], {x3, (x1^2 - x2^2), (x1^2 + x2^2), (x1^2*x2^2)}]
and
f[p_]:=Collect[ExpandAll[p], {x3, (x1^2 - x2^2), (x1^2 + x2^2), (x1^2*x2^2)}, Simplify]
Both these solutions work decently in many cases, though not perfectly. For instance, I've encountered the following example:
p = -x1^10 x3^3 + x1^6 x2^4 x3^3 - x1^4 x2^6 x3^3 + x2^10 x3^3
then for both possibilities of f above, the result is
f[p]=(-x1^10 + x1^6 x2^4 - x1^4 x2^6 + x2^10) x3^3
instead of what I want: $$3 x_3 x_1^2 x_2^2 (x_1^2+x_2^2) (x_1^2-x_2^2) + x_3 (x_1^2+x_2^2)^4$$
I'd appreciate any help!
SymmetricReduction[]
by any chance? It's not a full solution, but it should help you get there. $\endgroup$SymmetricReduction[]
. That's why I only offered it as a first step. $\endgroup$PolynomialReduce[]
might also be of interest. $\endgroup$