Processing math: 100%
Ask Your Question
1

How to sort terms in symbolic expression of polynomial?

asked 8 years ago

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
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

tmonteil gravatar image

updated 8 years ago

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?
Preview: (hide)
link

Comments

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

ablmf gravatar imageablmf ( 8 years ago )

The line

sage: R(s)

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

tmonteil gravatar imagetmonteil ( 8 years ago )

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

Stats

Asked: 8 years ago

Seen: 1,964 times

Last updated: Mar 15 '17