Sage shell is different from the Pytyhon shell, and the function sum
is different too. In Sage, it tries to find a symbolic sum, that's why the second argument needs to be a variable. In your first code block, you are essentially trying to evaluate
[sum(f, 1, 1, 20), sum(f, 2, 1, 20)]
From the mathematical point of view, how do you sum over 1
? That's why Sage gives you an error. Notice that in the last code block, when you use the variable n
, Sage is able to calculate the sum.