why giac integrate result fail to be parsed when using letter e?
Is this a known issue?
When integrand has the letter e
, sagemath fails to parse its output. Even though the same integral works inside giac.
Using sagemath 9.3 and giac 1.7
var('C B A e d x')
integrate((C*x^2+B*x+A)*(-e^2*x^2+d^2)^(1/2)/(e*x+d),x, algorithm="giac")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/usr/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._div_ (build/cythonized/sage/symbolic/expression.cpp:25839)()
3894 else:
-> 3895 x = left._gobj / _right._gobj
3896 return new_Expression_from_GEx(left._parent, x)
ValueError: power::eval(): division by zero
During handling of the above exception, another exception occurred:
ZeroDivisionError Traceback (most recent call last)
/usr/lib/python3.9/site-packages/sage/interfaces/giac.py in _sage_(self, locals)
1131 try:
-> 1132 return symbolic_expression_from_string(result, lsymbols,
1133 accept_sequence=True)
/usr/lib/python3.9/site-packages/sage/calculus/calculus.py in symbolic_expression_from_string(s, syms, accept_sequence)
2407 if isinstance(v,Function)})
-> 2408 return parse_func(s)
2409
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:5837)()
549
--> 550 cpdef parse_sequence(self, s):
551 """
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:5702)()
565 cdef Tokenizer tokens = Tokenizer(s)
--> 566 all = self.p_sequence(tokens)
567 if tokens.next() != EOS:
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_sequence (build/cythonized/sage/misc/parser.c:6404)()
627 tokens.backtrack()
--> 628 obj = self.p_eqn(tokens)
629 elif token == '[':
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_eqn (build/cythonized/sage/misc/parser.c:7394)()
728 """
--> 729 lhs = self.p_expr(tokens)
730 cdef int op = tokens.next()
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:7746)()
768 cdef int op
--> 769 operand1 = self.p_term(tokens)
770 op = tokens.next()
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:8105)()
808 while op == '*' or op == '/':
--> 809 operand2 = self.p_factor(tokens)
810 if op == '*':
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_factor (build/cythonized/sage/misc/parser.c:8461)()
845 tokens.backtrack()
--> 846 return self.p_power(tokens)
847
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_power (build/cythonized/sage/misc/parser.c:8618)()
873 """
--> 874 operand1 = self.p_atom(tokens)
875 cdef int token = tokens.next()
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_atom (build/cythonized/sage/misc/parser.c:9141)()
928 func = self.callable_constructor(name)
--> 929 args, kwds = self.p_args(tokens)
930 token = tokens.next()
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_args (build/cythonized/sage/misc/parser.c:9654)()
965 while token == ',':
--> 966 arg = self.p_arg(tokens)
967 if isinstance(arg, tuple):
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_arg (build/cythonized/sage/misc/parser.c:10081)()
1015 tokens.backtrack()
-> 1016 return self.p_expr(tokens)
1017
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_expr (build/cythonized/sage/misc/parser.c:7746)()
768 cdef int op
--> 769 operand1 = self.p_term(tokens)
770 op = tokens.next()
/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.p_term (build/cythonized/sage/misc/parser.c:8150)()
812 else:
--> 813 operand1 = operand1 / operand2
814 op = tokens.next()
/usr/lib/python3.9/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__truediv__ (build/cythonized/sage/structure/element.c:13162)()
1734 if HAVE_SAME_PARENT(cl):
-> 1735 return (<Element>left)._div_(right)
1736 if BOTH_ARE_ELEMENT(cl):
/usr/lib/python3.9/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._div_ (build/cythonized/sage/symbolic/expression.cpp:25919)()
3900 if 'division by zero' in str(msg):
-> 3901 raise ZeroDivisionError("symbolic division by zero")
3902 else:
ZeroDivisionError: symbolic division by zero
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
<ipython-input-8-35c8b048a377> in <module>
----> 1 integrate((C*x**Integer(2)+B*x+A)*(-e**Integer(2)*x**Integer(2)+d**Integer(2))**(Integer(1)/Integer(2))/(e*x+d),x, algorithm="giac")
/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 giac_integrator(expression, v, a, b)
446 return expression.integrate(v, a, b, hold=True)
447 else:
--> 448 return result._sage_()
/usr/lib/python3.9/site-packages/sage/interfaces/giac.py in _sage_(self, locals)
1134
1135 except Exception:
-> 1136 raise NotImplementedError("Unable to parse Giac output: %s" % result)
1137 else:
1138 return [entry.sage() for entry in self]
NotImplementedError: Unable to parse Giac output: 1/2*(4*A*d*exp(2)^3-4*A*d*exp(1)^4*exp(2)+4*B*d^2*exp(1)^3*exp(2)-4*B*d^2*exp(1)*exp(2)^2)*atan((-1/2*(-2*d*exp(1)-2*sqrt(d^2-x^2*exp(2))*exp(1))/x+exp(2))/sqrt(-exp(1)^4+exp(2)^2))/sqrt(-exp(1)^4+exp(2)^2)/exp(1)^4/exp(1)-1/4*(-2*C*d^3-4*A*d*exp(2)+2*B*d^2*exp(1))*sign(d)*asin(x*exp(2)/d/exp(1))/exp(1)/exp(2)+2*((16*exp(1)^4*C*1/96/exp(1)^5*x-(-24*exp(1)^4*B+24*exp(1)^3*C*d)*1/96/exp(1)^5)*x-(-48*exp(1)^4*A+48*exp(1)^3*d*B-32*exp(1)^2*C*d^2)*1/96/exp(1)^5)*sqrt(d^2-x^2*exp(2))
sage:
Using different letter than e
, now it works.
sage: var('C B A z d x')
(C, B, A, z, d, x)
sage: integrate((C*x^2+B*x+A)*(-z^2*x^2+d^2)^(1/2)/(z*x+d),x, algorithm="giac")
1/6*sqrt(-x^2*z^2 + d^2)*(x*(2*C*x/z - 3*(C*d*z^3 - B*z^4)/z^5) + 2*(2*C*d^2*z^2 - 3*B*d*z^3 + 3*A*z^4)/z^5) + 1/2*(C*d^3 - B*d^2*z + 2*A*d*z^2)*arcsin(x*z/d)*sgn(d)*sgn(z)/(z^2*abs(z))
The original integral works as in inside giac
Welcome to giac readline interface, version 1.7.0
1>> integrate((C*x^2+B*x+A)*(-e^2*x^2+d^2)^(1/2)/(e*x+d),x)
1/2*(4*A*d*exp(2)^3-4*A*d*exp(1)^4*exp(2)+4*B*d^2*exp(1)^3*exp(2)-4*B*d^2*exp(1)*exp(2)^2)*atan((-1/2*(-2*d*exp(1)-2*sqrt(d^2-x^2*exp(2))*exp(1))/x+exp(2))/sqrt(-exp(1)^4+exp(2)^2))/(sqrt(-exp(1)^4+exp(2)^2)*exp(1)^4*exp(1))-1/4*(-2*C*d^3-4*A*d*exp(2)+2*B*d^2*exp(1))*sign(d)*asin(x*exp(2)/(d*exp(1)))/(exp(1)*exp(2))+2*((16*exp(1)^4*C/(96*exp(1)^5)*x-(-24*exp(1)^4*B+24*exp(1)^3*C*d)/(96*exp(1)^5))*x-(-48*exp(1)^4*A+48*exp(1)^3*d*B-32*exp(1)^2*C*d^2)/(96*exp(1)^5))*sqrt(d^2-x^2*exp(2))
// Time 0.06
Also, using e
works when using different CAS than giac. giac uses e
as exp
. I should ask Author of Rubi to change the test files not to use e
as letter in the integrand.
I can't now change letters in the input, as this is part of standard Rubi's test suite. But my question is: Since it works using e
inside giac, should it not also work as is when passing it to giac via sagemath?