# replicate recursive sum

i have a function defined as

https://imgur.com/a/SfF2Edl.png

how can i replicate this function in sagemath using the sum function? i know it can be done in pure python with recursion but then whats the point of sagemath and symbolic calculation?

what ive tried so far is:

```
f(x) = 1 if x == 0 else sum(1+f(j-1), j, 0, x-1)
```

but i get the following error:

```
NameError: name 'f' is not defined
```

now i know its not possible to use recursion on a variable like this but there must be some tricky way to go about doing that (i hope so and thats why im here)

thanks in advance

Welcome to Ask Sage! Thank you for your question.

To post links as a new user, insert spaces in them, and someone with enough "karma" can fix them.

Something like: https ://example .com

done replaced with a link, thanks

Homework ?

If so, try to solve it yourself. One (big (fat)) hint : recurrence...

Another hint : try to write

`f`

as a pure Python function (probably horribly inefficient...) (or do it by hand on paper (or in your head)), then see what its value is for the few first positive integers. Illumination should ensue quickly, and the point of your (probable) homework is probably toprovewhat these numerical results hint at...Yet another one : try to think of ways to write efficiently your Python function. There are lots of way to do it, and t's a good exercise...

Bonus question : what happens if x is

nota non-negative integer ? What should you add to your Python implementation ?Other bonus question : explain the error message returned by your first attempt.