# A simple sum causes division by zero exception

I'm very new to SageMath and did some small experiments yesterday. This is my Code:

```
x, n, r, i = var('x, n, r, i')
f(x, n, r) = x * sum((1 + r) ^ i, i, 1, n)
f(1, 30, 0.0)
```

It works well if `r != 0`

, but will raise a exception of "division by zero" if equal.

My ipynb file: nbviewer.jupyter.org/gist/7sDream/5db3cfd153269fd1a1cacaf0b60f69bb

It seems some optimizations of sum did not consider the range of variable `r`

.
But there is also no change if I added `assume(r >= 0)`

before define `f`

.

So how can I disable this sum optimizations? Or what is wrong with the way I use it?

Curiously :

Interestingly, if we define

`fc = fast_callable( x * sum((1 + r) ^ i, i, 1, n), vars=[x,n,r] )`

, then`fc(1, 30, 0.0)`

evaluates to`NaN`

.Note that the "optimization" takes place at the creation of

`f`

:FWIW,

`sympy`

has an interesting translation :