Ask Your Question

Force Convert a Polynomial Ring into Multivariate Polynomial

asked 2017-10-19 19:24:02 +0200

Jayesh Badwaik gravatar image

I have the following code

xi = var('xi')
eta = var('eta')
P = 3*eta  - 1
Pr = P.polynomial(QQ)

which gives the output


I would like to get the output in terms of both xi and eta that is, I want the output to be [-1,0,3]. How to force that? The reason I ask this is because my P is actually a mode in list of polyomials and generally function of both xi and eta and for different modes, either one or the other variable might not be there in the expression at all, and I want a general way to get the coefficients in a list corresponding to the coefficients of the terms 1,xi,eta,xi^2,xi *eta, eta^2 and so on.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-19 22:55:34 +0200

slelievre gravatar image

If possible, avoid using symbolic variables (with var).

Instead, define a polynomial ring, and work there.

To get the coefficients in a multivariate polynomial ring, use list.

This will give you a list of pairs (c, m) where c is a coefficient and m is a monomial.

Here is an example, to give you an idea.

sage: R.<xi, eta> = PolynomialRing(QQ)
sage: P = 3*eta  - 1
sage: Q = 5 * eta * xi - 7 * eta^2 + 2 * xi^3 - 1
sage: list(P)
[(3, eta), (-1, 1)]
sage: list(Q)
[(2, xi^3), (5, xi*eta), (-7, eta^2), (-1, 1)]
edit flag offensive delete link more


Thanks, I finally did something similar .

Jayesh Badwaik gravatar imageJayesh Badwaik ( 2017-10-20 10:12:21 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-10-19 19:21:36 +0200

Seen: 329 times

Last updated: Oct 19 '17