Ask Your Question

Revision history [back]

Note that it is also possible to do this in a genuine Polynomial Ring, instead of the (sometimes weird) Symbolic Ring:

sage: mylist = [1,4,2,3,6,12,21,6,2]
sage: n = len(mylist)
sage: R = PolynomialRing(ZZ, ['x%s'%i for i in range(n)]); R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8 over Integer Ring
sage: P = sum((mylist[i]*R('x%s'%i)) for i in range(n)) ; P
x0 + 4*x1 + 2*x2 + 3*x3 + 6*x4 + 12*x5 + 21*x6 + 6*x7 + 2*x8
sage: P(range(n))
285

Note that it is also possible to do this in a genuine Polynomial Ring, instead of the (sometimes weird) Symbolic Ring:

sage: mylist = [1,4,2,3,6,12,21,6,2]
sage: n = len(mylist)
sage: R = PolynomialRing(ZZ, ['x%s'%i for i in range(n)]); n, 'x'); R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8 over Integer Ring
sage: P = sum((mylist[i]*R('x%s'%i)) sum(c*R.gen(i) for i i, c in range(n)) ; enumerate(mylist)); P
x0 + 4*x1 + 2*x2 + 3*x3 + 6*x4 + 12*x5 + 21*x6 + 6*x7 + 2*x8
sage: P(range(n))
285