sagemath / sage

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

error message has maxima code instead of sage code #29608

Open 299dd376-0904-4b01-92dc-d57318e7d9ab opened 4 years ago

299dd376-0904-4b01-92dc-d57318e7d9ab commented 4 years ago

Running sage on the following file bug.sage yields an error message saying that an "example of legal syntax is assume(cos((4*%pi*m+%pi)/2)*z>0)". However, this is not legal syntax, because %pi is a maxima constant, not a sage constant.

# bug.sage
m = var("m");
x = var("x");
y = var("y");
z = var("z");
assume(m, 'integer');
assume(m > 0);
assume(x >= 0);
assume(y >= 0);
assume(z >= 0);
D = cos((4 * m + 1)*arcsin(z/sqrt(x^2 + y^2 + z^2)))/sqrt((x^2 + y^2)/(x^2 + y^2 + z^2));
print(limit(limit(D, x = 0), y = 0));
# ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(cos((4*%pi*m+%pi)/2)*z>0)', see `assume?` for more details)
assume(cos((4*%pi*m+%pi)/2)*z==0);
# SyntaxError: invalid syntax
assume(cos((4*pi*m+pi)/2)*z==0);
# ValueError: Assumption is redundant

Output:

$ sage < bug.sage 
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.0, Release Date: 2020-01-01                     │
│ Using Python 3.8.2. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: ---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python3/dist-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
    984                 L.append(max_minus)
--> 985             return max_to_sr(maxima_eval(([max_limit], L)))
    986         except RuntimeError as error:

/usr/lib/python3/dist-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:7841)()
    818         lispargs = EclObject(list(args))
--> 819         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
    820 

/usr/lib/python3/dist-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:5503)()
    390         s = si_coerce_to_base_string(ecl_values(1))
--> 391         raise RuntimeError("ECL says: {}".format(
    392             char_to_str(ecl_base_string_pointer_safe(s))))

RuntimeError: ECL says: Maxima asks: Is cos((4*%pi*_SAGE_VAR_m+%pi)/2)*_SAGE_VAR_z positive, negative or zero?

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-11-0d1303e560b0> in <module>
----> 1 print(limit(limit(D, x = Integer(0)), y = Integer(0)));

/usr/lib/python3/dist-packages/sage/calculus/calculus.py in limit(ex, dir, taylor, algorithm, **argv)
   1366     if algorithm == 'maxima':
   1367         if dir is None:
-> 1368             l = maxima.sr_limit(ex, v, a)
   1369         elif dir in dir_plus:
   1370             l = maxima.sr_limit(ex, v, a, 'plus')

/usr/lib/python3/dist-packages/sage/interfaces/maxima_lib.py in sr_limit(self, expr, v, a, dir)
    987             s = str(error)
    988             if "Is" in s: # Maxima asked for a condition
--> 989                 self._missing_assumption(s)
    990             else:
    991                 raise

/usr/lib/python3/dist-packages/sage/interfaces/maxima_lib.py in _missing_assumption(self, errstr)
   1032              + errstr[jj+1:k] +">0)', see `assume?` for more details)\n" + errstr
   1033         outstr = outstr.replace('_SAGE_VAR_','')
-> 1034         raise ValueError(outstr)
   1035 
   1036 def is_MaximaLibElement(x):

ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(cos((4*%pi*m+%pi)/2)*z>0)', see `assume?` for more details)
Is cos((4*%pi*m+%pi)/2)*z positive, negative or zero?
sage: sage:   File "<ipython-input-13-7a440a048b66>", line 1
    assume(cos((Integer(4)*%pi*m+%pi)/Integer(2))*z==Integer(0));
                           ^
SyntaxError: invalid syntax

sage: sage: Exiting Sage (CPU time 0m2.26s, Wall time 0m1.83s).
Versions:
$ apt-cache policy sagemath maxima
sagemath:
  Installed: 9.0-4
  Candidate: 9.0-4
  Version table:
 *** 9.0-4 500
        500 http://ftp.uk.debian.org/debian unstable/main amd64 Packages
        100 /var/lib/dpkg/status
maxima:
  Installed: 5.43.2-3
  Candidate: 5.43.2-3
  Version table:
 *** 5.43.2-3 990
        990 http://ftp.uk.debian.org/debian bullseye/main amd64 Packages
        990 http://ftp.uk.debian.org/debian testing/main amd64 Packages
        500 http://ftp.uk.debian.org/debian unstable/main amd64 Packages
        100 /var/lib/dpkg/status

Component: interfaces

Keywords: maxima

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

DaveWitteMorris commented 4 years ago

Changed keywords from none to maxima

DaveWitteMorris commented 4 years ago
comment:1

I opened ticket #29616 to discuss the error about the assumption being redundant, so this ticket can focus on the other issue: can the maxima code (%pi) in the error message be automatically translated to sage syntax (pi) before it is presented to the user?

DaveWitteMorris commented 4 years ago

Description changed:

--- 
+++ 
@@ -1,6 +1,7 @@
-Input `bug.sage`:
+Running sage on the following file `bug.sage` yields an error message saying that an "example of legal syntax is `assume(cos((4*%pi*m+%pi)/2)*z>0)`". However, this is not legal syntax, because `%pi` is a maxima constant, not a sage constant.

+# bug.sage m = var("m"); x = var("x"); y = var("y");

mkoeppe commented 3 years ago
comment:3

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.