sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 450 forks source link

Incorrect (Maxima) symbolic sum #31418

Open 7822f248-ba56-45f1-ab3d-4de7482bdf9f opened 3 years ago

7822f248-ba56-45f1-ab3d-4de7482bdf9f commented 3 years ago

See this ask.sagemath.org question for details.

sage: sum((1+r)^i, i, 1, n)
((r + 1)^(n + 1) - r - 1)/r

which is incorrect if r==0.

Mathematica faills in the same trap :

sage: sum((1+r)^i, i, 1, n, algorithm="mathematica")
((r + 1)^n - 1)*(r + 1)/r

Workaround : use sympy algorithm :

sage: sum((1+r)^i, i, 1, n, algorithm="sympy")
cases(((r + 1 == 1, n), (1, ((r + 1)^(n + 1) - r - 1)/r)))

Upstream: Not yet reported upstream; Will do shortly.

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/31418

DaveWitteMorris commented 3 years ago
comment:1

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, the rule in ginac 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)".

The user in this particular ask.sagemath.org 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.

However, I agree that it would be good to have a way to evaluate the symbolic expression at r = 0 (without having to take a limit).

mkoeppe commented 3 years ago
comment:2

Moving to 9.4, as 9.3 has been released.