Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you want to work only in the symbolic ring, you can use the collect method:

sage: x, y, z = var("x y z")
sage: poly =  x^3*y*z + x^2*y^2 + 3*x^3 + 2*x^2 + x*y + x*z + 1
sage: poly.collect(x)
(y*z + 3)*x^3 + (y^2 + 2)*x^2 + x*(y + z) + 1

It is also possible to extract the coefficients of each power of $x$:

sage: poly.coefficients(x)
[[1, 0], [y + z, 1], [y^2 + 2, 2], [y*z + 3, 3]]

or just

sage: poly.coefficients(x,sparse=False)
[1, y + z, y^2 + 2, y*z + 3]