Ask Your Question

Revision history [back]

I don't know about using Sage's symbolic sum, but this seems to work (based on the documentation for Sage's function, obtained by looking at function? and also at https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/var.html#sage.calculus.var.function):

sage: def ev(self, x):
....:     if x == 0:
....:         return 1
....:     else:
....:         return sum(1+self(j) for j in range(x))
....: 
sage: f = function("f", nargs=1, eval_func=ev)

I don't know about using Sage's symbolic sum, but this seems to work (based (idea based on the documentation for Sage's function, obtained by looking at function? and also at https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/var.html#sage.calculus.var.function):

sage: def ev(self, x):
....:     if x == 0:
....:         return 1
....:     else:
....:         return sum(1+self(j) for j in range(x))
....: 
sage: f = function("f", nargs=1, eval_func=ev)