Ask Your Question

How to sort terms in symbolic expression of polynomial?

asked 2017-03-15 17:24:42 +0200

ablmf gravatar image

I have a symbolic expression in the following form

s =2*z^3 + z^2 + z

How can I tell sage to print s as the following form?

z + z^2 +  2*z^3
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-03-15 18:10:10 +0200

tmonteil gravatar image

updated 2017-03-15 18:11:05 +0200

I guess symbolic expressions do not have this feature. However, for polynomial rings, the order of the monomials has some importance (e.g. in the computation of a Groebner basis). Hence, you could transform your symbolic expression into a polynomial belonging to some polynomial ring with an appropriate ordering. Note that since ordering of monomials usually matters for multivariate polynomial rings, we have to construct a multivariate polynomial rings with one variable instead of an univeriate polynomial ring. Here is how:

sage: z = SR.var('z')
sage: s =2*z^3 + z^2 + z
sage: s
2*z^3 + z^2 + z
sage: s.parent()
Symbolic Ring

sage: R.<z>=PolynomialRing(ZZ,1,order='neglex')
sage: R(s)
z + z^2 + 2*z^3
sage: R(s).parent()
Multivariate Polynomial Ring in z over Integer Ring

To see which orders are available, you can do:

sage: sage.rings.polynomial.term_order?
edit flag offensive delete link more


How to convert a symbolic polynomial to a member of polynomial ring? Does sage has such a function?

ablmf gravatar imageablmf ( 2017-03-18 00:47:33 +0200 )edit

The line

sage: R(s)

does exactly this. It converts the symbolic polynomial s as an element of R.

tmonteil gravatar imagetmonteil ( 2017-03-18 22:17:22 +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-03-15 17:24:42 +0200

Seen: 1,539 times

Last updated: Mar 15 '17