Revision history [back]

Turning an expression into a multivariate polynomial?

Suppose I have the expression

-a^3x^2 - a^2xy^2 + axy + bx^2 + 2bxy + xy^2


I want to turn this into a polynomial in x and y:

(1-a^2)xy^2+(a+2*b)xy+(b-a^3)x^2


so that I can then extract the coefficients (by setting x=1, y=1 in the list of operands of the new expression). How do I tell Sage which of the four variables will be the polynomial variables?