Ask Your Question

Revision history [back]

You should use instead:

sage: sum(x^i*ft.coefficient(x, i) for i in [0..5])
1/120*x^5 - 1/6*x^3 + x

Explanation: your original code involves Sage's symbolic sum and i has to be a symbolic variable (you probably declared it as such via var('i')). Now, the method coefficient is expecting an integer, not a symbolic variable. For some reason, it returns always zero for a symbolic variable (IMHO an error message would be more appropriate here):

sage: i = var('i')
sage: ft.coefficient(x, i)
0

Hence the result that you get. On the contrary, the command

sum(x^i*ft.coefficient(x, i) for i in [0..5])

involves Python's sum, for which i is an integer, so that ft.coefficient behaves correctly. For more details, see the documentation returned by sum? (in particular the warning in it).