Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is an answer using the list command and some list comprehensions.

var('x y')
R.<x,y>=PolynomialRing(RR)
q=x^2*y^2+x+x^2*y+y^2
terms=list(q)
ans=[t[1] for t in terms if (t[1].degree(x) % 2)==0 and (t[1].degree(y) % 2==0)]
sum(ans)

Here is an answer using the list command and some list comprehensions.

var('x y')
R.<x,y>=PolynomialRing(RR)
q=x^2*y^2+x+x^2*y+y^2
terms=list(q)
ans=[t[1] ans=[t[0]*t[1] for t in terms if (t[1].degree(x) % 2)==0 and (t[1].degree(y) % 2==0)]
sum(ans)

This will also keep the coefficients.