Ask Your Question

How to sort terms in symbolic expression of polynomial?

asked 2017-03-15 11:24:42 -0500

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 12:10:10 -0500

tmonteil gravatar image

updated 2017-03-15 12:11:05 -0500

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-17 18:47:33 -0500 )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 16:17:22 -0500 )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 11:24:42 -0500

Seen: 33 times

Last updated: Mar 15