How to get Polynomial Coefficients

Hi

I would like to get the value of coeffs of x^5 + px^3 + qx^2 + rx + s something like [1,0, b - 2/5a^2,...] I do not understand what means the coefficients() outputs in the code below ??

forget()
import math
for v in var( 'a,b,c,d,e' ):    assume( v, 'rational' )
for v in var( 'p,q,r,s' ):    assume( v, 'rational' )
x = PolynomialRing(RationalField(), 'x').gen()
t = PolynomialRing(RationalField(), 't').gen()
Pt= t^5 + a*t^4 + b*t^3 + c*t^2 + d*t + e
vChgt=t==x-a/5
P=Pt.substitute(vChgt)
#Px= x^5          + p*x^3 + q*x^2 + r*x + s
show(P.factor())
show(P.factor().coefficients(sparse=False))
show(P.factor().list())
P.factor()

edit retag close merge delete

Sort by ยป oldest newest most voted

The following works:

sage: P.coefficients(x, sparse=0)
[4/3125*a^5 - 1/125*a^3*b + 1/25*a^2*c - 1/5*a*d + e,
-3/125*a^4 + 3/25*a^2*b - 2/5*a*c + d,
4/25*a^3 - 3/5*a*b + c,
-2/5*a^2 + b,
0,
1]


The variable x has to be specified, if some other variables are present, and we want the coefficients only with respect to x.

Note that the coefficient on the pythonical place zero corresponds to the zero degree (i.e. free) coefficient of P. So the leading coefficient is on the pythonical fifth place. In order to get "the other list" [1,0, b - 2/5a^2,...], just take the reverse list.

sage: C = P.coefficients(x, sparse=0)
sage: C . reverse()
sage: C[0:3]
[1, 0, -2/5*a^2 + b]

more

Thank you Dan_fulea

( 2017-09-18 01:06:59 -0500 )edit