why ECL says: Error executing code in Maxima: expt: undefined: 0 to a negative exponent

asked 2021-06-02 06:22:00 +0200

Nasser gravatar image

updated 2021-06-02 06:22:44 +0200

Why the error ECL says: Error executing code in Maxima: expt: undefined: 0 to a negative exponent shows up in this example? When running the same integral in maxima, no error is given. (it can't integrate it, but no error).

This happens when adding assume on a variable. Using sagemath 9.3 and maxima 5.44 on Linux

sage: var('x a')
(x, a)
sage: integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x, algorithm="maxima")
integrate(arcsin(x/a)^(3/2)/sqrt(a^2 - x^2), x)

No problem. But now notice what happens when adding assume.

sage: assume(a>0)
sage: integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x, algorithm="maxima")
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-4-ac342accae00> in <module>
----> 1 integrate(arcsin(x/a)**(Integer(3)/Integer(2))/(a**Integer(2)-x**Integer(2))**(Integer(1)/Integer(2)),x, algorithm="maxima")

/usr/lib/python3.9/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
    757     """
    758     if hasattr(x, 'integral'):
--> 759         return x.integral(*args, **kwds)
    760     else:
    761         from sage.symbolic.ring import SR

/usr/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:66867)()
  12645                     R = SR
  12646             return R(integral(f, v, a, b, **kwds))
> 12647         return integral(self, *args, **kwds)
  12648 
  12649     integrate = integral

/usr/lib/python3.9/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
    988         if not integrator:
    989             raise ValueError("Unknown algorithm: %s" % algorithm)
--> 990         return integrator(expression, v, a, b)
    991     if a is None:
    992         return indefinite_integral(expression, v, hold=hold)

/usr/lib/python3.9/site-packages/sage/symbolic/integration/external.py in maxima_integrator(expression, v, a, b)
     42         expression = SR(expression)
     43     if a is None:
---> 44         result = maxima.sr_integral(expression, v)
     45     else:
     46         result = maxima.sr_integral(expression, v, a, b)

/usr/lib/python3.9/site-packages/sage/interfaces/maxima_lib.py in sr_integral(self, *args)
    787         """
    788         try:
--> 789             return max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args])))
    790         except RuntimeError as error:
    791             s = str(error)

/usr/lib/python3.9/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:8632)()
    852         """
    853         lispargs = EclObject(list(args))
--> 854         return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
    855 
    856     def __richcmp__(left, right, int op):

/usr/lib/python3.9/site-packages/sage/libs/ecl.pyx in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:5914)()
    363 
    364     if error != NULL:
--> 365         raise RuntimeError("ECL says: {}".format(
    366             ecl_string_to_python(error)))
    367     else:

RuntimeError: ECL says: Error executing code in Maxima: expt: undefined: 0 to a negative exponent.
sage:

Now the same thing inside maxima itself causes no problem after adding assume

>maxima
;;; Loading #P"/usr/lib/ecl-20.4.24/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib/ecl-20.4.24/sockets.fas"
Maxima 5.44.0 http://maxima.sourceforge.net
using Lisp ECL 20.4.24
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x)                        
;
                                       x 3/2
                              / arcsin(-)
                              [        a
(%o1)                         I ------------- dx
                              ]       2    2
                              / sqrt(a  - x )
(%i2) assume(a>0);
(%o2)                               [a > 0]
(%i3) integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x)                    
;
                                       x 3/2
                              / arcsin(-)
                              [        a
(%o3)                         I ------------- dx
                              ]       2    2
                              / sqrt(a  - x )
(%i4)

Why does sagemath gives exception when using assume but maxima itself does not? Is this a known issue?

edit retag flag offensive close merge delete

Comments

Your first example yields

integrate(arcsin(x/a)^(3/2)/sqrt(a^2 - x^2), x)

not a result. Do you need to specify the method as maxima? As

var('a')
assume(a>0)
integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x)

yields a result.

tolga gravatar imagetolga ( 2021-06-02 09:56:36 +0200 )edit

Thanks, but the default have changed from maxima to giac in current sagemath (it used to be maxima in earlier versions). I need to test maxima specifically. The default is giac

sage: integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x)
2/5*abs(a)*arcsin(x/a)^(5/2)/a
enter code here
sage: integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x,algorithm="giac")
2/5*abs(a)*arcsin(x/a)^(5/2)/a

and with assume

sage: assume(a>0)
sage: integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x,algorithm="giac")
2/5*arcsin(x/a)^(5/2)
sage: integrate(arcsin(x/a)^(3/2)/(a^2-x^2)^(1/2),x)
2/5*arcsin(x/a)^(5/2)

So, yes, I need to use Maxima for this example. I am using sagemath 9.3 with giac 1 ...(more)

Nasser gravatar imageNasser ( 2021-06-02 10:10:59 +0200 )edit

Thanks, but the default have changed from maxima to giac in current sagemath (it used to be maxima in earlier versions). I need to test maxima specifically. The default is giac

Huh ? From sage.symbolic.integration.integral.integrate? :

   * "algorithm" - (default: 'maxima') one of

        * 'maxima' - use maxima (the default)

        * 'sympy' - use sympy (also in Sage)

        * 'mathematica_free' - use http://integrals.wolfram.com/

        * 'fricas' - use FriCAS (the optional fricas spkg has to be
          installed)

        * 'giac' - use Giac

Where is this change of default documented ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-06-02 11:48:48 +0200 )edit

BTW :

sage: integrate(x^(k-1)*e^(-x/theta)/(gamma(k)*theta^k), x)                     
-x^k*gamma(k, x/theta)/(theta^k*(x/theta)^k*gamma(k))
sage: integrate(x^(k-1)*e^(-x/theta)/(gamma(k)*theta^k), x, algorithm="giac")   
integrate(x^(k - 1)*e^(-x/theta)/(theta^k*gamma(k)), x)
sage: integrate(x^(k-1)*e^(-x/theta)/(gamma(k)*theta^k), x, 0, oo)              
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)

...

ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(theta>0)', see `assume?` for more details)
Is theta positive or ne...
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-06-02 11:56:05 +0200 )edit