1 | initial version |
Instead of using the symbolic sum
that you mention, you can use Python's built-in sum
that takes an iterable such as a generator expression:
sage: n = 5
sage: sum((j if j % 2 == 0 else j + 1)*x^j for j in range(1,n+1))
6*x^5 + 4*x^4 + 4*x^3 + 2*x^2 + 2*x