I have a set of polynomial expressions in multiple variables:
U = x[1] x[2] + x[1] x[3] + x[2] x[3]
F = m1^2 x[1]^2 x[2] + m2^2 x[1] x[2]^2 + m1^2 x[1]^2 x[3] + m1^2 x[1] x[2] x[3] + m2^2 x[1] x[2] x[3] + m3^2 x[1] x[2] x[3] - p^2 x[1] x[2] x[3] + m2^2 x[2]^2 x[3] + m3^2 x[1] x[3]^2 + m3^2 x[2] x[3]^2
G = U + F
The relevant variables in this case (and for all of my examples) are the various "x[i]"-s, where "i" is an integer.
To split the terms in G
, I use this answer.
ClearAll[toList]
toList = # /. {_[a__] :> {a}, a_?AtomQ :> {a}} &;
listresG = toList[G];
What I need:
A way to extract the terms appearing in U
and F
from the expression of G
. I find doing this non-trivial since Mathematica sum does some kind of monomial ordering of its own that might change the place of each term. For eg, in this example, the explicit expression for G
happens to be
G = x[1] x[2] + m1^2 x[1]^2 x[2] + m2^2 x[1] x[2]^2 + x[1] x[3] + m1^2 x[1]^2 x[3] + x[2] x[3] + m1^2 x[1] x[2] x[3] + m2^2 x[1] x[2] x[3] + m3^2 x[1] x[2] x[3] - p^2 x[1] x[2] x[3] + m2^2 x[2]^2 x[3] + m3^2 x[1] x[3]^2 + m3^2 x[2] x[3]^2
which has clearly altered the positioning of the terms relative to where they appear in U
and F
.
I have tried doing Cases[listresG, x[_Integer]*x[_Integer]]
to extract the terms appearing in U
from G
, but this doesn't work.
Subscript[x, n]
with justx[n]
and double index variables with e.g.x[n, m]
orx[n][m]
. The latter formulations are much easier for pattern matching, substitution, etc. $\endgroup$