Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To add to the diversity of answers here, another valid approach is to add a single line to what you already have:

f(x)=x^2
g(x)=x*f(x)
k=var('k')
sum(g(k),k,0,4)

This will return 100. The point is that you can use this syntax to sum the values of a proper function, but not arbitrary Python expressions.