question on list comprehensions

Josiah Carlson jcarlson at
Sun Oct 17 20:42:19 EDT 2004

> Yes, as with integrals, the sum of an nth degree poly is (n+1)th degree. 
> The n+2 coefficients for the sum from 0 to k can be determined by actually 
> summing the poly for each of 0 to n+1 and equating the n+2 partial sume to 
> the result poly (with powers evaluated) to get n+2 equations in n+2 
> unknowns.  Even with integral coefficients in the poly to be summed, the 
> coefficients are generally non-integral rationals and can get pretty nasty 
> to calculate, so for exact results, it may well be easier and faster to 
> write and run a program.

As long as you can solve a k+1 degree polynomial with linear algebra
(via gaussian elimination, etc.), you can find:
    sum([i**k for i in xrange(1, n+1)])
... with little issue (if you know the trick).

 - Josiah

More information about the Python-list mailing list