Sage: Ticket #31418: Incorrect (Maxima) symbolic sum
https://trac.sagemath.org/ticket/31418
<p>
See this <code>ask.sagemath.org</code> <a class="ext-link" href="https://ask.sagemath.org/question/55766/a-simple-sum-causes-division-by-zero-exception/"><span class="icon"></span>question</a> for details.
</p>
<pre class="wiki">sage: sum((1+r)^i, i, 1, n)
((r + 1)^(n + 1) - r - 1)/r
</pre><p>
which is incorrect if <code>r==0</code>.
</p>
<p>
<code>Mathematica</code> faills in the same trap :
</p>
<pre class="wiki">sage: sum((1+r)^i, i, 1, n, algorithm="mathematica")
((r + 1)^n - 1)*(r + 1)/r
</pre><p>
Workaround : use <code>sympy</code> algorithm :
</p>
<pre class="wiki">sage: sum((1+r)^i, i, 1, n, algorithm="sympy")
cases(((r + 1 == 1, n), (1, ((r + 1)^(n + 1) - r - 1)/r)))
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/31418
Trac 1.1.6gh-DaveWitteMorrisFri, 12 Mar 2021 02:51:03 GMT
https://trac.sagemath.org/ticket/31418#comment:1
https://trac.sagemath.org/ticket/31418#comment:1
<p>
I don't think the simplification is actually a bug, because the result is equal to the sum as a symbolic expression, so the code is behaving as advertised. More precisely, <a class="ext-link" href="https://www.ginac.de/tutorial/#Automatic-evaluation"><span class="icon"></span>the rule in ginac</a> is that a simplification can be made if it is "algebraically correct, possibly except for a set of measure zero (e.g. x/x is transformed to 1 although this is incorrect for x=0)".
</p>
<p>
The user in this particular <code>ask.sagemath.org</code> question, seems to be interested in numerical calculations, rather than symbolic manipulations, so perhaps they should have defined a python function, instead of using a symbolic expression.
</p>
<p>
However, I agree that it would be good to have a way to evaluate the symbolic expression at <code>r = 0</code> (without having to take a limit).
</p>
TicketmkoeppeMon, 10 May 2021 17:42:09 GMTmilestone changed
https://trac.sagemath.org/ticket/31418#comment:2
https://trac.sagemath.org/ticket/31418#comment:2
<ul>
<li><strong>milestone</strong>
changed from <em>sage-9.3</em> to <em>sage-9.4</em>
</li>
</ul>
<p>
Moving to 9.4, as 9.3 has been released.
</p>
Ticket