ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 09 Apr 2021 22:27:43 +0200How to reorder terms in a polynomial to follow a specific order.https://ask.sagemath.org/question/56566/how-to-reorder-terms-in-a-polynomial-to-follow-a-specific-order/ Hi everyone,
I have code in Sagemath that will give me various polynomials. However, I need these polynomials to be ordered in a specific way. For example, my code will output a polynomial that looks like this:
t^2-t+1
but I need it to be outputted like this:
1-t+t^2.
Is there any way to do this? Thanks, I appreciate the help.Fri, 09 Apr 2021 00:44:31 +0200https://ask.sagemath.org/question/56566/how-to-reorder-terms-in-a-polynomial-to-follow-a-specific-order/Comment by Max Alekseyev for <p>Hi everyone,</p>
<p>I have code in Sagemath that will give me various polynomials. However, I need these polynomials to be ordered in a specific way. For example, my code will output a polynomial that looks like this:</p>
<p>t^2-t+1</p>
<p>but I need it to be outputted like this:</p>
<p>1-t+t^2.</p>
<p>Is there any way to do this? Thanks, I appreciate the help.</p>
https://ask.sagemath.org/question/56566/how-to-reorder-terms-in-a-polynomial-to-follow-a-specific-order/?comment=56567#post-id-56567This is answered in https://stackoverflow.com/questions/36598435/Fri, 09 Apr 2021 01:08:27 +0200https://ask.sagemath.org/question/56566/how-to-reorder-terms-in-a-polynomial-to-follow-a-specific-order/?comment=56567#post-id-56567Answer by mwageringel for <p>Hi everyone,</p>
<p>I have code in Sagemath that will give me various polynomials. However, I need these polynomials to be ordered in a specific way. For example, my code will output a polynomial that looks like this:</p>
<p>t^2-t+1</p>
<p>but I need it to be outputted like this:</p>
<p>1-t+t^2.</p>
<p>Is there any way to do this? Thanks, I appreciate the help.</p>
https://ask.sagemath.org/question/56566/how-to-reorder-terms-in-a-polynomial-to-follow-a-specific-order/?answer=56582#post-id-56582For displaying the polynomial, you could convert it to a power series, which are ordered the other way around:
sage: var('t');
sage: f = t^2 - t + 1
sage: R = PowerSeriesRing(QQ, 't')
sage: print(R(f))
1 - t + t^2
Fri, 09 Apr 2021 22:27:43 +0200https://ask.sagemath.org/question/56566/how-to-reorder-terms-in-a-polynomial-to-follow-a-specific-order/?answer=56582#post-id-56582