Ask Your Question

Revision history [back]

You can recover the degree of an element using the degree method. Your element u is not homogeneous, so u.degree() raises an error: "ValueError: element is not homogeneous". However, you can get the degree of each term in u: first, u.terms() returns

[a,
 t*e0,
 x*e1,
 y*e2,
 z*e3,
 f01*e0*e1,
 f02*e0*e2,
 f03*e0*e3,
 f12*e1*e2,
 f13*e1*e3,
 f23*e2*e3]

and [x.degree() for x in u.terms()] returns

[0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]

So if you want the terms in degree 1, for example, you can do:

sum(x for x in u.terms() if x.degree() == 1)

which returns

t*e0 + x*e1 + y*e2 + z*e3