sagemath / sage

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

TypeError: an error occurred running a Giac command "index.cc index_m i_lex_is_greater Error: Bad Argument Value" #36113

Closed nasser1 closed 1 year ago

nasser1 commented 1 year ago

Steps To Reproduce

I am using sagemath 10.1 on Linux. I have build from source the latest GIAC and installeded it on the system.

build sagemath by telling it to use the system giac.

The sagemath build completed fine with no problem, and I am able to call many integrate commands with giac as algorithm with no problem.

However, on some integrals it gives the following strange exception.

When I try the same exact integral in giac itself on Linux directly, Giac does not generate an error and gives back result.

So on the face of it, it seems the problem is in the interfaces.

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.1, Release Date: 2023-08-20                    │
│ Using Python 3.11.3. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: var('x,y,a,c,b,e,d')
(x, y, a, c, b, e, d)
sage: integrate(x^6/(c*x^4+b*x^2+a)/(e*x^2+d)^(1/2),x, algorithm="giac")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File ~/TMP/sage-10.1/src/sage/interfaces/expect.py:1496, in ExpectElement.__init__(self, parent, value, is_name, name)
   1495 try:
-> 1496     self._name = parent._create(value, name=name)
   1497 # Convert ValueError and RuntimeError to TypeError for
   1498 # coercion to work properly.

File ~/TMP/sage-10.1/src/sage/interfaces/interface.py:516, in Interface._create(self, value, name)
    515 name = self._next_var_name() if name is None else name
--> 516 self.set(name, value)
    517 return name

File ~/TMP/sage-10.1/src/sage/interfaces/giac.py:665, in Giac.set(self, var, value)
    664 cmd = '%s:=%s:;' % (var, value)  # if giac is not in maple mode ( maple_mode(0))
--> 665 out = self.eval(cmd)
    666 if out.find("error") != -1:

File ~/TMP/sage-10.1/src/sage/interfaces/giac.py:652, in Giac.eval(self, code, strip, **kwds)
    651     code = code.replace("\n", "").strip()
--> 652 return Expect.eval(self, code, strip=strip, **kwds).strip()

File ~/TMP/sage-10.1/src/sage/interfaces/expect.py:1390, in Expect.eval(self, code, strip, synchronize, locals, allow_use_file, split_lines, **kwds)
   1389 elif split_lines:
-> 1390     return '\n'.join(self._eval_line(L, allow_use_file=allow_use_file, **kwds)
   1391                      for L in code.split('\n') if L)
   1392 else:

File ~/TMP/sage-10.1/src/sage/interfaces/expect.py:1390, in <genexpr>(.0)
   1389 elif split_lines:
-> 1390     return '\n'.join(self._eval_line(L, allow_use_file=allow_use_file, **kwds)
   1391                      for L in code.split('\n') if L)
   1392 else:

File ~/TMP/sage-10.1/src/sage/interfaces/giac.py:620, in Giac._eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed)
    619     if z.lower().find("error") != -1:
--> 620         raise RuntimeError("an error occurred running a Giac command:\nINPUT:\n%s\nOUTPUT:\n%s" % (line, z))
    621 lines = (line for line in z.splitlines()
    622          if not line.startswith('Evaluation time:'))

RuntimeError: an error occurred running a Giac command:
INPUT:
sage2:=int(sage0,sageVARx):;
OUTPUT:
"index.cc index_m i_lex_is_greater Error: Bad Argument Value"

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In [2], line 1
----> 1 integrate(x**Integer(6)/(c*x**Integer(4)+b*x**Integer(2)+a)/(e*x**Integer(2)+d)**(Integer(1)/Integer(2)),x, algorithm="giac")

File ~/TMP/sage-10.1/src/sage/misc/functional.py:773, in integral(x, *args, **kwds)
    648 """
    649 Return an indefinite or definite integral of an object ``x``.
    650 
   (...)
    770 
    771 """
    772 if hasattr(x, 'integral'):
--> 773     return x.integral(*args, **kwds)
    774 else:
    775     from sage.symbolic.ring import SR

File ~/TMP/sage-10.1/src/sage/symbolic/expression.pyx:13283, in sage.symbolic.expression.Expression.integral()
  13281                 R = SR
  13282         return R(integral(f, v, a, b, **kwds))
> 13283     return integral(self, *args, **kwds)
  13284 
  13285 integrate = integral

File ~/TMP/sage-10.1/src/sage/symbolic/integration/integral.py:1062, in integrate(expression, v, a, b, algorithm, hold)
   1060     if not integrator:
   1061         raise ValueError("Unknown algorithm: %s" % algorithm)
-> 1062     return integrator(expression, v, a, b)
   1063 if a is None:
   1064     return indefinite_integral(expression, v, hold=hold)

File ~/TMP/sage-10.1/src/sage/symbolic/integration/external.py:251, in giac_integrator(expression, v, a, b)
    249 ex = expression._giac_()
    250 if a is None:
--> 251     result = ex.integrate(v._giac_())
    252 else:
    253     result = ex.integrate(v._giac_(), a._giac_(), b._giac_())

File ~/TMP/sage-10.1/src/sage/interfaces/giac.py:1179, in GiacElement.integral(self, var, min, max)
   1148 r"""
   1149 Return the integral of self with respect to the variable x.
   1150 
   (...)
   1176     -2*sin(y)
   1177 """
   1178 if min is None:
-> 1179     return giac('int(%s,%s)' % (self.name(), var))
   1180 if max is None:
   1181     raise ValueError("neither or both of min/max must be specified")

File ~/TMP/sage-10.1/src/sage/interfaces/interface.py:298, in Interface.__call__(self, x, name)
    295         pass
    297 if isinstance(x, str):
--> 298     return cls(self, x, name=name)
    299 try:
    300     # Special methods do not and should not have an option to
    301     # set the name directly, as the identifier assigned by the
    302     # interface should stay consistent. An identifier with a
    303     # user-assigned name might change its value, so we return a
    304     # new element.
    305     result = self._coerce_from_special_method(x)

File ~/TMP/sage-10.1/src/sage/interfaces/expect.py:1501, in ExpectElement.__init__(self, parent, value, is_name, name)
   1499 except (RuntimeError, ValueError) as x:
   1500     self._session_number = -1
-> 1501     raise TypeError(*x.args)
   1502 except BaseException:
   1503     self._session_number = -1

TypeError: an error occurred running a Giac command:
INPUT:
sage2:=int(sage0,sageVARx):;
OUTPUT:
"index.cc index_m i_lex_is_greater Error: Bad Argument Value"
sage: 

The following is the same command using giac

>giac
// Using locale /usr/local/share/locale/
// en_US.UTF-8
Welcome to giac readline interface, version 1.9.0-57
(c) 2002,2023 B. Parisse & others
Homepage http://www-fourier.univ-grenoble-alpes.fr/~parisse/giac.html
Released under the GPL license 3.0 or above
See http://www.gnu.org for license details
May contain BSD licensed software parts (lapack, atlas, tinymt)
-------------------------------------------------
Press CTRL and D simultaneously to finish session
Type ?commandname for help
*** Type xcas to launch a light version of Xcas ***

0>> integrate(x^6/(c*x^4+b*x^2+a)/(e*x^2+d)^(1/2),x)
2*2*c^2/(8*exp(1)*c^3)*x*sqrt(d+x^2*exp(1))+2*(2*b*exp(1/2)^2+c*d)/8/exp(1/2)^3/c^2*ln((sqrt(d+x^2*exp(1))-exp(1/2)*x)^2)
// Time 0.37
1>> 

Version information

>which giac
/usr/local/bin/giac

>giac --version
// Using locale /usr/local/share/locale/
// en_US.UTF-8
// /usr/local/share/locale/
// giac
// UTF-8
// Maximum number of parallel threads 10
// (c) 2001, 2021 B. Parisse & others
1.9.0-57
>
>
>which sage
/home/me/TMP/sage-10.1/sage
>sage --version
SageMath version 10.1, Release Date: 2023-08-20
>

>uname -a
Linux me-virtualbox 6.1.31-2-MANJARO #1 SMP PREEMPT_DYNAMIC Sun Jun  4 12:31:46 UTC 2023 x86_64 GNU/Linux

Note also that when using "maxima" or "fricas" as algorithm on the same integral, no error shows up.

Expected Behavior

Expected is that it sagemath return the same output given by giac and not an exception.

Actual Behavior

An exception is thrown by sagemath calling giac on this integral.

Additional Information

I have also the sagemath configuration log file and the full build log file if needed.

Environment

- **OS**: Linux Manjaro  Linux me-virtualbox 6.1.31-2-MANJARO
- **Sage Version**: 10.1 build from source.

Checklist

nasser1 commented 1 year ago

I found the problem is actually in giac ! So closing this issue, It turned out "e" is taken as "exp(1)" by giac. So when I tried the following

0>> integrate(x^6/(c*x^4+b*x^2+a)/(ee*x^2+d)^(1/2),x) 
"index.cc index_m i_lex_is_greater Error: Bad Argument Value"

I got the error. So the error was being generated by giac, not sagemath.

Closing this issue now.