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.
Side note: I think what I want was the default implementation at some time since code that I wrote on version=9.8 was based on the fact that it works like I want it. But now after updating to 10.5 the function raises IndexErrors (understandably).