Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Symbolics have a method .poly:

sage: var('x,y')
(x, y)
sage: p = x*y + x^2*y^2
sage: p.poly(x)
x^2*y^2 + x*y
sage: p.poly(x).coefficients()
[[y, 1], [y^2, 2]]

Multivariate polynomial rings have a method .polnomial()

sage: A.<x,y> = QQ[]
sage: p = x*y + x^2*y^2
sage: p.polynomial(x)
y^2*x^2 + y*x
sage: p.polynomial(x).list()
[0, y, y^2]

Both methods collect only with respect to one variable, so you may need to iterate.