sagemath / sage

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

wrong value for very easy limit that involves an assumption #34140

Open DaveWitteMorris opened 2 years ago

DaveWitteMorris commented 2 years ago

The following limit should obviously be 1, but sagemath says it is 0. This is a maxima bug that has been reported upstream.

sage: a = var("a")
sage: assume(a == 0)
sage: limit(a/x + 1, x=0)
0

Here is the original ticket description:

It is not difficult to see that the value of the following limit is 4*m + 1. However, sagemath says the value is 0:

sage: m = var('m');
sage: assume(m, 'integer')
sage: with hold:
....:     assume(cos((4*pi*m+pi)/2) == 0)
....: 
sage: D = cos((4 * m + 1)*arcsin(1/sqrt(x^2 + 1)))/abs(x)
sage: lim(D, x=0)
0

This is a maxima bug:

(%i1) declare(m, integer)$ 
(%i2) assume(equal(cos((4 * %pi * m + %pi)/2), 0))$
(%i3) limit(cos((4*m + 1) * asin(1/sqrt(x^2 + 1)))/abs(x), x, 0);
(%o3)                                  0

This is an offshoot of #29616 (maxima asks for assumption but then rejects it as redundant).

Upstream: Reported upstream. Developers acknowledge bug.

Component: calculus

Keywords: limit, maxima

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

DaveWitteMorris commented 2 years ago
comment:1

Giac also gives a wrong answer, but a different one:

sage: lim(D, x=0, algorithm="giac")
+Infinity

I think sage only shares its assumptions with maxima and pynac, so giac cannot know that m is an integer. The answer +Infinity is correct generically, but it is the wrong answer in the special case that we are interested in.

Sympy gives an error, instead of an answer:

sage: lim(D, x=0, algorithm="sympy")
      <snip>
RuntimeError: indeterminate expression: 0 * infinity encountered.
DaveWitteMorris commented 2 years ago

Description changed:

--- 
+++ 
@@ -2,6 +2,7 @@

sage: m = var('m'); +sage: assume(m, 'integer') sage: with hold: ....: assume(cos((4pim+pi)/2) == 0) ....:

DaveWitteMorris commented 2 years ago
comment:2

This is now tracked at maxima bug #4004

DaveWitteMorris commented 2 years ago

Changed upstream from Not yet reported upstream; Will do shortly. to Reported upstream. No feedback yet.

DaveWitteMorris commented 2 years ago

Description changed:

--- 
+++ 
@@ -1,3 +1,16 @@
+The following limit should obviously be `1`, but sagemath says it is `0`. This is a maxima bug that has been reported upstream.
+
+```
+sage: a = var("a")
+sage: assume(a == 0)
+sage: limit(a/x + 1, x=0)
+0
+```
+
+---
+
+Here is the original ticket description:
+
 It is not difficult to see that the value of the following limit is `4*m + 1`. However, sagemath says the value is `0`:
DaveWitteMorris commented 2 years ago

Changed upstream from Reported upstream. No feedback yet. to Reported upstream. Developers acknowledge bug.