Ask Your Question

Revision history [back]

If you are willing to work with polynomials, you can do this. There may be ways to speed up the following. First define the polynomial ring and the indeterminates:

sage: R.<A_123, A_12_34, A_124> = QQ[]

Now define the expression:

sage: a = -A_123^5*A_124^3*A_12_34^4 - 2*A_123^4*A_124^4*A_12_34^4 - A_123^3*A_124^5*A_12_34^4

Note that "for m in a" prints out useful information: pairs (coefficient, monomial):

sage: for m in a: print(m)
(-1, A_123^5*A_12_34^4*A_124^3)
(-2, A_123^4*A_12_34^4*A_124^4)
(-1, A_123^3*A_12_34^4*A_124^5)
sage: sum(m[0]*m[1] for m in a)
-A_123^5*A_12_34^4*A_124^3 - 2*A_123^4*A_12_34^4*A_124^4 - A_123^3*A_12_34^4*A_124^5
sage: sum(m[0]*m[1] for m in a) == a
True

Now pick out the terms where all of the exponents are even:

sage: sum(m[0]*m[1] for m in a if all(x%2 == 0 for x in m[1].exponents()[0]))
-2*A_123^4*A_12_34^4*A_124^4