Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I create a proper **dense** PolynomialRing over any ring?

I know that PolynomialRing has the keyword "sparse" which defaults to False.

sage: S = PolynomialRing(QQ, "x", sparse=False)
sage: S is PolynomialRing(QQ, "x")
True

But the output of .coefficients() is still sparse in the sense that it does only show non-zero coefficients

sage: p = S([1, 0, 2])
sage: p.coefficients()
[1, 2]

I know that I could reconstruct the polynomial using .exponents()

sage: p.exponents()
[0, 2]
sage: x = S.gen()
sage: p == sum(coef*x**exp for coef, exp in zip(p.coefficients(), p.exponents())
True

But is there an easy way to make .coefficients() return the true list of coefficients, i.e., [1, 0, 2]? Right now I would need it for a PolynomialRing over QQ but a solution for any ring would be ideal.