Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The first syntax is symbolic summation:

sage: var('a,b,i')
sage: sum(2^i, i, a, b)
-2^a + 2^(b + 1)

It will always try to evaluate the sum symbolically. If you use something that doesn't understand symbolic variables (like GF(8), which is implemented by polybori) then you get the "unable to convert to integer" error. Because polybori can only exponentiate by integers, and not by formal variables.

The second syntax is Python's list creation and summation of lists:

sage: [ 2^j for j in range(0,3) ]
[1, 2, 4]
sage: sum(_)
7

Note that the variable inside the list comprehension (which I called j here) is automatically created and will overwrite other variables. In your second example, calling the inner variable i overwrites the previously-defined symbolic variable var('i')