Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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,

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]