Ask Your Question

Revision history [back]

Quick proposition:

sage: L = [1, 3, 2]
sage: sum([b*x^a for a,b in list(enumerate(reversed(L)))])
x^2 + 3*x + 2

Quick I am not sure that Sage shoud contain a function for each such feature, it will lead to a huge namespace, making tab completion unusable. Here is a quick proposition:

sage: L = [1, 3, 2]
sage: sum([b*x^a for a,b in list(enumerate(reversed(L)))])
enumerate(reversed(L))])
x^2 + 3*x + 2

I am not sure that Sage shoud contain a function for each such feature, it will lead to a huge global namespace, making tab completion unusable. Here is a quick proposition:

sage: L = [1, 3, 2]
sage: sum([b*x^a for a,b in enumerate(reversed(L))])
x^2 + 3*x + 2

Or, if you want a function, define:

sage: poly2sym = lambda L : sum([b*x^a for a,b in enumerate(reversed(L))])
sage: poly2sym([1, 3, 2])
x^2 + 3*x + 2

Now, if you want genuine polynomials (not symbolic functions), you can define the polynomial ring you want and build a polynomial from a list as follows:

sage: R.<x> = PolynomialRing(QQ)
sage: R
Univariate Polynomial Ring in x over Rational Field

sage: R([1, 3, 2])
2*x^2 + 3*x + 1

As you can see, the order is not the one you wanted, so you can do:

sage: R(list(reversed([1, 3, 2])))
x^2 + 3*x + 2

And again:

poly2sym = lambda L : R(list(reversed(L)))

But then, you should understand that the prouced object are genuine polynomials, not symbolic expressions as before.