# Revision history [back]

I will say some words here, not in a comment, since the space is more generous. First of all, methods implemented for some objects are often implemented with a special purpose. They may be used in further implemented algorithms, or are implemented to provide a "library usage". The questions assumes tacitly, that the two methods coefficients and monomials of the object f, that i chose in a different way

sage: P.<x> = PolynomialRing(QQ)
sage: f = 11*x^3 - 17*x^7 + 56*x^10 + 9*x^5
sage: f.parent()
Univariate Polynomial Ring in x over Rational Field
sage: type(f)
<class 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint'>


should be related to each other. No, in this case the programmer expects one method. Let us ask for the coefficients and the monomials involved:

sage: f.coefficients()
[11, 9, -17, 56]
sage: f.monomials()
[x^10, x^7, x^5, x^3]


In the doc string of the last method we have the information:

sage: f.monomials??

::::::::::::: many lines then... :::::::::::::

Source:
def monomials(self):
"""
Return the list of the monomials in self in a decreasing order of their degrees.

EXAMPLES::

sage: P.<x> = QQ[]
sage: f = x^2 + (2/3)*x + 1


so it is an intention to sort in this manner. For the coefficients, the natural, "expected" behavior is kept, we can for instance ask for:

sage: f.coefficients()
[11, 9, -17, 56]
sage: f.coefficients(sparse=True)
[11, 9, -17, 56]
sage: f.coefficients(sparse=False)
[0, 0, 0, 11, 0, 9, 0, -17, 0, 0, 56]
sage: f.list()
[0, 0, 0, 11, 0, 9, 0, -17, 0, 0, 56]
sage: f.dict()
{3: 11, 5: 9, 7: -17, 10: 56}


to extract in a way or an other the information on the polynomial.