Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way is:

R.<x,y>=SR[]
a,b,c=var('a b c')
p=a*x^2 + a*y^2 + b*y^2 + c*y^2 + (2*a*y + b*y)*x
p
a*x^2 + (2*a + b)*x*y + (a + b + c)*y^2

p.coefficients()
[a, 2*a + b, a + b + c]

One way is:

R.<x,y>=SR[]
a,b,c=var('a b c')
p=a*x^2 + a*y^2 + b*y^2 + c*y^2 + (2*a*y + b*y)*x
p
a*x^2 + (2*a + b)*x*y + (a + b + c)*y^2

p.coefficients()
[a, 2*a + b, a + b + c]

See also https://ask.sagemath.org/question/10195/extracting-coefficients-of-multivariate-polynomials/