Ask Your Question
3

some output from integrate using giac gives Malformed expression

asked 2021-05-17 04:14:45 +0100

Nasser gravatar image

updated 2021-05-17 04:49:13 +0100

Using sagemath 9.3 on Linux.

Some calls to integrate using giac as algorithm do not get assigned to the variable on the LHS. i.e. when doing anti=integrate(....), then typing anti gives NameError. This happens because giac return the result of integrate with strange warning mesagaes before, even thought the actual antiderivative is returned at the end. But It is not possible to capture this due to the error sagemath have parsing the output from giac.

There are many such cases. I will show one below.

When using giac directly, the result of integrate is assigned to the variable. The version of giac is Giac/Xcas 1.7 on Linux

>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.3, Release Date: 2021-05-09                     │
│ Using Python 3.9.4. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘
sage: var('x b')
(x, b)
sage: anti=integrate((-b*x+2)^(5/2)*x^(1/2),x, algorithm="giac")
---------------------------------------------------------------------------
SyntaxError                               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:5724)()
    567         if tokens.next() != EOS:
--> 568             self.parse_error(tokens)
    569         if len(all) == 1 and isinstance(all, list):

/usr/lib/python3.9/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_error (build/cythonized/sage/misc/parser.c:10208)()
   1018     cdef parse_error(self, Tokenizer tokens, msg="Malformed expression"):
-> 1019         raise SyntaxError(msg, tokens.s, tokens.pos)
   1020 

SyntaxError: Malformed expression

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-2-eb4066502734> in <module>
----> 1 anti=integrate((-b*x+Integer(2))**(Integer(5)/Integer(2))*x**(Integer(1)/Integer(2)),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: Warning, choosing root of [1,0,%%%{4,[1,1]%%%}+%%%{4,[1,0]%%%}+%%%{-4,[0,1]%%%}+%%%{-8,[0,0]%%%},0,%%%{6,[2,2]%%%}+%%%{4,[2,1]%%%}+%%%{6,[2,0]%%%}+%%%{-4,[1,2]%%%}+%%%{-28,[1,1]%%%}+%%%{-8,[1,0]%%%}+%%%{6,[0,2]%%%}+%%%{8,[0,1]%%%}+%%%{24,[0,0]%%%},0,%%%{4,[3,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0,4]%%%}+%%%{-8,[0,3]%%%}+%%%{24,[0,2]%%%}+%%%{-32,[0,1]%%%}+%%%{16,[0,0]%%%}] at parameters values [-2.28782047657,4.66774101928]
Warning, choosing root of [1,0,%%%{4,[1,1]%%%}+%%%{4,[1,0]%%%}+%%%{-4,[0,1]%%%}+%%%{-8,[0,0]%%%},0,%%%{6,[2,2]%%%}+%%%{4,[2,1]%%%}+%%%{6,[2,0]%%%}+%%%{-4,[1,2]%%%}+%%%{-28,[1,1]%%%}+%%%{-8,[1,0]%%%}+%%%{6,[0,2]%%%}+%%%{8,[0,1]%%%}+%%%{24,[0,0]%%%},0,%%%{4,[3,3]%%%}+%%%{-4,[3,2]%%%}+%%%{-4,[3,1]%%%}+%%%{4,[3,0]%%%}+%%%{4,[2,3]%%%}+%%%{-64,[2,2]%%%}+%%%{20,[2,1]%%%}+%%%{8,[2,0]%%%}+%%%{-4,[1,3]%%%}+%%%{-20,[1,2]%%%}+%%%{128,[1,1]%%%}+%%%{-16,[1,0]%%%}+%%%{-4,[0,3]%%%}+%%%{8,[0,2]%%%}+%%%{16,[0,1]%%%}+%%%{-32,[0,0]%%%},0,%%%{1,[4,4]%%%}+%%%{-4,[4,3]%%%}+%%%{6,[4,2]%%%}+%%%{-4,[4,1]%%%}+%%%{1,[4,0]%%%}+%%%{4,[3,4]%%%}+%%%{-12,[3,3]%%%}+%%%{20,[3,2]%%%}+%%%{-20,[3,1]%%%}+%%%{8,[3,0]%%%}+%%%{6,[2,4]%%%}+%%%{-20,[2,3]%%%}+%%%{46,[2,2]%%%}+%%%{-40,[2,1]%%%}+%%%{24,[2,0]%%%}+%%%{4,[1,4]%%%}+%%%{-20,[1,3]%%%}+%%%{40,[1,2]%%%}+%%%{-48,[1,1]%%%}+%%%{32,[1,0]%%%}+%%%{1,[0,4]%%%}+%%%{-8,[0,3]%%%}+%%%{24,[0,2]%%%}+%%%{-32,[0,1]%%%}+%%%{16,[0,0]%%%}] at parameters values [-10.7897139532,38.2197840363]

1/b*(2*b^3*abs(b)/b^2*(2*(((-90*b^11/1440/b^14*sqrt(-b*x+2)*sqrt(-b*x+2)+750*b^11/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*x+2)-2445*b^11/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*x+2)+4185*b^11/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-35/8/b^2/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-12*b^2*abs(b)/b^2*(2*((12*b^5/144/b^7*sqrt(-b*x+2)*sqrt(-b*x+2)-78*b^5/144/b^7)*sqrt(-b*x+2)*sqrt(-b*x+2)+198*b^5/144/b^7)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-5/2/b/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-24*b*abs(b)/b^2/b*(2*(1/8*sqrt(-b*x+2)*sqrt(-b*x+2)-5/8)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)+6*b/4/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-16*abs(b)/b^2*(1/2*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-2*b/2/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2)))))
sage: anti
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-66894d4540d1> in <module>
----> 1 anti

NameError: name 'anti' is not defined
sage:

You can see that giac actually solved this integral, but from sagemath, it is not possible to obtain the last result above due to the parsing errors.

Here are few more examples, where they all give same errors in sagemath

integrate((-b*x+2)^(5/2)/x^(3/2),x, algorithm="giac")
integrate((-b*x+2)^(5/2)/x^(5/2),x, algorithm="giac")

Since I run integration test for giac using sagemath, all these integrals now assigned as failed, even though using giac directly, the output is captured ok.

Is there a way to resolve this in sagemath or should giac clean its return result somehow to allow sagemath to process it correctly?

Btw, this is not the only problem interfacing to giac, There are examples, where sagemath returns back the input (i.e. meaning the integrate did not evaluate), while when using giac directly, it does work (but gives warnings)

Here is an example

sage: var('x b a')
(x, b, a)
sage: anti=integrate(1/(a-I*a*x)^(3/4)/(a+I*a*x)^(9/4),x, algorithm="giac")
sage: anti
integrate(1/((I*a*x + a)^(9/4)*(-I*a*x + a)^(3/4)), x)

While in giac itself, it gives

13>> anti=integrate(1/(a-i*a*x)^(3/4)/(a+i*a*x)^(9/4),x)
Warning, choosing root of [1,0,%%%{4,[1,1]%%%}+%%%{4,[1,0]%%%}+%%%{-4,[0,1]%%%}+%%%{-8,[0,0]%%%},0,%%%{6,[2,2]%%%}+%%%{4,[2,1]%%%}+%%%{6,[2,0]%%%}+%%%{-4,[1,2]%%%}+%%%{-28,[1,1]%%%}+%%%{-8,[1,0]%%%}+%%%{6,[0,2]%%%}+%%%{8,[0,1]%%%}+%%%{24,[0,0]%%%},0,%%%{4,[3,3]%%%}+%%%{-4,[3,2]%%%}+%%%{-4,[3,1]%%%}+%%%{4,[3,0]%%%}+%%%{4,[2,3]%%%}+%%%{-64,[2,2]%%%}+%%%{20,[2,1]%%%}+%%%{8,[2,0]%%%}+%%%{-4,[1,3]%%%}+%%%{-20,[1,2]%%%}+%%%{128,[1,1]%%%}+%%%{-16,[1,0]%%%}+%%%{-4,[0,3]%%%}+%%%{8,[0,2]%%%}+%%%{16,[0,1]%%%}+%%%{-32,[0,0]%%%},0,%%%{1,[4,4]%%%}+%%%{-4,[4,3]%%%}+%%%{6,[4,2]%%%}+%%%{-4,[4,1]%%%}+%%%{1,[4,0]%%%}+%%%{4,[3,4]%%%}+%%%{-12,[3,3]%%%}+%%%{20,[3,2]%%%}+%%%{-20,[3,1]%%%}+%%%{8,[3,0]%%%}+%%%{6,[2,4]%%%}+%%%{-20,[2,3]%%%}+%%%{46,[2,2]%%%}+%%%{-40,[2,1]%%%}+%%%{24,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[0,4]%%%}+%%%{-8,[0,3]%%%}+%%%{24,[0,2]%%%}+%%%{-32,[0,1]%%%}+%%%{16,[0,0]%%%}] at parameters values [-26.2540012896,71.1075269701]
Warning, choosing root of [1,0,%%%{4,[1,1]%%%}+%%%{4,[1,0]%%%}+%%%{-4,[0,1]%%%}+%%%{-8,[0,0]%%%},0,%%%{6,[2,2]%%%}+%%%{4,[2,1]%%%}+%%%{6,[2,0]%%%}+%%%{-4,[1,2]%%%}+%%%{-28,[1,1]%%%}+%%%{-8,[1,0]%%%}+%%%{6,[0,2]%%%}+%%%{8,[0,1]%%%}+%%%{24,[0,0]%%%},0,%%%{4,[3,3]%%%}+%%%{-4,[3,2]%%%}+%%%{-4,[3,1]%%%}+%%%{4,[3,0]%%%}+%%%{4,[2,3]%%%}+%%%{-64,[2,2]%%%}+%%%{20,[2,1]%%%}+%%%{8,[2,0]%%%}+%%%{-4,[1,3]%%%}+%%%{-20,[1,2]%%%}+%%%{128,[1,1]%%%}+%%%{-16,[1,0]%%%}+%%%{-4,[0,3]%%%}+%%%{8,[0,2]%%%}+%%%{16,[0,1]%%%}+%%%{-32,[0,0]%%%},0,%%%{1,[4,4]%%%}+%%%{-4,[4,3]%%%}+%%%{6,[4,2]%%%}+%%%{-4,[4,1]%%%}+%%%{1,[4,0]%%%}+%%%{4,[3,4]%%%}+%%%{-12,[3,3]%%%}+%%%{20,[3,2]%%%}+%%%{-20,[3,1]%%%}+%%%{8,[3,0]%%%}+%%%{6,[2,4]%%%}+%%%{-20,[2,3]%%%}+%%%{46,[2,2]%%%}+%%%{-40,[2,1]%%%}+%%%{24,[2,0]%%%}+%%%{4,[1,4]%%%}+%%%{-20,[1,3]%%%}+%%%{40,[1,2]%%%}+%%%{-48,[1,1]%%%}+%%%{32,[1,0]%%%}+%%%{1,[0,4]%%%}+%%%{-8,[0,3]%%%}+%%%{24,[0,2]%%%}+%%%{-32,[0,1]%%%}+%%%{16,[0,0]%%%}] at parameters values [-11.5307277958,27.1490779156]
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}+%%%{128,[1,1]%%%}+%%%{-16,[1,0]%%%}+%%%{-4,[0,3]%%%}+%%%{8,[0,2]%%%}+%%%{16,[0,1]%%%}+%%%{-32,[0,0]%%%},0,%%%{1,[4,4]%%%}+%%%{-4,[4,3]%%%}+%%%{6,[4,2]%%%}+%%%{-4,[4,1]%%%}+%%%{1,[4,0]%%%}+%%%{4,[3,4]%%%}+%%%{-12,[3,3]%%%}+%%%{20,[3,2]%%%}+%%%{-20,[3,1]%%%}+%%%{8,[3,0]%%%}+%%%{6,[2,4]%%%}+%%%{-20,[2,3]%%%}+%%%{46,[2,2]%%%}+%%%{-40,[2,1]%%%}+%%%{24,[2,0]%%%}+%%%{4,[1,4]%%%}+%%%{-20,[1,3]%%%}+%%%{40,[1,2]%%%}+%%%{-48,[1,1]%%%}+%%%{32,[1,0]%%%}+%%%{1,[0,4]%%%}+%%%{-8,[0,3]%%%}+%%%{24,[0,2]%%%}+%%%{-32,[0,1]%%%}+%%%{16,[0,0]%%%}] at parameters values [-50.7246053959,13.8581410125]

Evaluation time: 15.34
1/b*(2*b^3*abs(b)/b^2*(2*((((5040*b^19/100800/b^23*sqrt(-b*x+2)*sqrt(-b*x+2)-51660*b^19/100800/b^23)*sqrt(-b*x+2)*sqrt(-b*x+2)+215460*b^19/100800/b^23)*sqrt(-b*x+2)*sqrt(-b*x+2)-469350*b^19/100800/b^23)*sqrt(-b*x+2)*sqrt(-b*x+2)+607950*b^19/100800/b^23)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-63/8/b^3/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-12*b^2*abs(b)/b^2*(2*(((-90*b^11/1440/b^14*sqrt(-b*x+2)*sqrt(-b*x+2)+750*b^11/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*x+2)-2445*b^11/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*x+2)+4185*b^11/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-35/8/b^2/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))+24*b*abs(b)/b^2*(2*((12*b^5/144/b^7*sqrt(-b*x+2)*sqrt(-b*x+2)-78*b^5/144/b^7)*sqrt(-b*x+2)*sqrt(-b*x+2)+198*b^5/144/b^7)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-5/2/b/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))+16*abs(b)/b^2/b*(2*(1/8*sqrt(-b*x+2)*sqrt(-b*x+2)-5/8)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)+6*b/4/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2)))))=(integrate(4/(2*i*a^3*((((-i)*a*x+a)^(1/4))^4-a)*(-(((-i)*a*x+a)^(1/4))^4+2*a)^(1/4)/a+i*a^3*(i*((((-i)*a*x+a)^(1/4))^4-a)/a)^2*(-(((-i)*a*x+a)^(1/4))^4+2*a)^(1/4)+(-i)*a^3*(-(((-i)*a*x+a)^(1/4))^4+2*a)^(1/4))/4*(-i)*a*(((-i)*a*x+a)^(1/4))^-3,x))
// Time 15.34
14>>

It looks like it is because giac generates these warning messages. Same as above example.

Because of this, many integrals show as failed when using sagemath with giac.

Is there a way to configure giac from inside sagemath may be to turn off these warnings? May be if there is, this will make all these integrals now work.

I do not know giac well, and do not even know where to ask about giac itself.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
3

answered 2021-05-17 06:29:36 +0100

slelievre gravatar image

updated 2021-05-17 12:10:07 +0100

It turns out @Sébastien hit that bug when comparing various integration engines while answering Ask Sage question 50885: integrate sqrt(x+sqrt(x)).

Having checked it did not correspond to existing tickets, he opened one for that:

Bernard Parisse, the main Giac developer, posted there that that problem is already fixed in Giac.

When Sage uses a Giac version with such warnings, silencing them would be nice, see comment 9 by @vdelecroix at Sage Trac ticket 29966.

Regarding where to ask about Giac:

  • as @tmonteil recalls, Giac bugs are worth tracking on the Sage side too when relevant
  • the main Giac developer participates in relevant Sage discussions and Sage Trac tickets
  • the main discussion venue for Giac itself is the Giac/Xcas forum
  • Giac bugs, feature requests and questions can be discussed there

Related:

edit flag offensive delete link more

Comments

I agree that giac issues should eventually be reported at giac, but giac issues appearing in Sage should be reported to Sage, which will report it to giac, and take the opportunity to add some doctests in its own code.

tmonteil gravatar imagetmonteil ( 2021-05-17 10:28:28 +0100 )edit
2

answered 2021-05-17 19:09:07 +0100

Emmanuel Charpentier gravatar image

updated 2021-05-18 08:56:35 +0100

The problem is not the warnings, but our conversion to Sage :

sage: Ex=(-b*x+2)^(5/2)*x^(1/2)
sage: %time GI=libgiac(Ex).integrate(libgiac(x))
CPU times: user 17.1 s, sys: 412 ms, total: 17.6 s
Wall time: 17.6 s
sage: GI
GI
1/b*(2*b^3*abs(b)/b^2*(2*(((-90*b^11*1/1440/b^14*sqrt(-b*x+2)*sqrt(-b*x+2)+750*b^11*1/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*x+2)-2445*b^11*1/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*x+2)+4185*b^11*1/1440/b^14)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-35/8/b^2/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-12*b^2*abs(b)/b^2*(2*((12*b^5*1/144/b^7*sqrt(-b*x+2)*sqrt(-b*x+2)-78*b^5*1/144/b^7)*sqrt(-b*x+2)*sqrt(-b*x+2)+198*b^5*1/144/b^7)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-5/2/b/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-24*b/b*abs(b)/b^2*(2*(1/8*sqrt(-b*x+2)*sqrt(-b*x+2)-5/8)*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)+6*b/4/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2))))-16*abs(b)/b^2*(1/2*sqrt(-b*x+2)*sqrt(-b*(-b*x+2)+2*b)-2*b/2/sqrt(-b)*ln(abs(sqrt(-b*(-b*x+2)+2*b)-sqrt(-b)*sqrt(-b*x+2)))))

After a bit of exploration ('not shown), it turns out that giacs's ln is problematic. So we can work around this. Awful version :

sage: SR(str(GI).replace("ln","log")).simplify_full()
1/24*((6*b^3*x^3 - 34*b^2*x^2 + 59*b*x - 15)*sqrt(b^2*x)*sqrt(-b*x + 2) - 30*sqrt(-b)*log(abs(sqrt(-b*x + 2)*sqrt(-b) - sqrt(b^2*x))))/(b*abs(b))

$$ \frac{{\left(6 \, b^{3} x^{3} - 34 \, b^{2} x^{2} + 59 \, b x - 15\right)} \sqrt{b^{2} x} \sqrt{-b x + 2} - 30 \, \sqrt{-b} \log\left({\left| \sqrt{-b x + 2} \sqrt{-b} - \sqrt{b^{2} x} \right|}\right)}{24 \, b {\left| b \right|}} $$

In fact, all the Sage-accessible integrators need a bit nudging to obtain usable results. Meditate the results of the following code (unLaTeXable by this site's tools) :

var("b")
Ex = (-b*x+2)^(5/2)*x^(1/2)
from time import time as systime
t0 = systime()
with assuming(b<0): MN = Ex.integrate(x).simplify_full()
M0 = Ex.subs(b==0).integrate(x).simplify_full()
with assuming(b>0): MP = Ex.integrate(x).simplify_full()
M = cases([(b<0, MN), (b==0, M0), (b>0, MP)]).function(x)
tM=systime()
S = Ex.integrate(x, algorithm="sympy").function(x)
tS= systime()
G = SR(str(libgiac(Ex).integrate(libgiac(x))).replace("ln","log"))\
    .simplify_full().function(x)
tG = systime()
Fl = [u.function(x) for u in Ex.integrate(x, algorithm="fricas")]
tF = systime()
Sqrt = function("Sqrt")
MM = mathematica.Integrate(Ex, x)\
                .sage().substitute_function(Sqrt,sqrt).function(x)
tMM = systime()

TR = table(rows=[["Sage", round(tM-t0,3), M],
                 ["Sympy", round(tS-tM, 3), S],
                 ["Giac", round(tG-tS, 3), G],
                 ["Fricas", round(tF-tG, 3), matrix([[Fl[0]],[Fl[1]]])],
                 ["Mathematica", round(tMM-tF, 3), MM]],
           header_row=["Integrator","time", "result"])

Comments later (France's curfew ahead..).

EDIT :

As announced, a few comments :

  • Fricas' answer is (probably) incomplete : both expressions rederive to Ex, but their validity limits are not stated. This is to be explored within the original Fricas interface, with a probable followup ticket.

  • Giac library's answer as well as Sympy's in the case $\frac{\left|bx\right|}{2}>1$ are a figment of their respective authors' imagination: the derivatives of the proposed expression cannot be proved equal to Ex (but I have not computed their quotients or ratios, just plotted a few numerical cases). Deriving the other expressions with respect to x give expressions which can be proved equal to Ex.

  • It is probably not a coincidence if these two incorrect answers are obtained after a much longer time than "correct" ones...

  • Using cases expressions proved surprisingly heavy. For example, the subs and plot methods don't work at all. The diff method does surprising things. This has to be enhanced : ticket ahoy ! (But this one is difficult to report correctly...).

  • A peek at the answer given by Wolframl alpha gives hints on the origin of the different antiderivative forms given bu=y the different CASes.

  • <rant> Mathjax is no sufficient substitute to $\LaTeX$...</rant>.

In conclusion :

CASes are a big help, but you MUST check their answers by any means available (including numerical ones, which cannot prove you right but can prove you wrong) And a great strength of Sage is the availability of a common framework and interface to various CASes.

edit flag offensive delete link more

Comments

Since your call GI=libgiac(Ex).integrate(libgiac(x)) works, and integrate(Ex),x, algorithm="giac") does not work, should I then change my sagemath script which tests giac to use your method instead for all test problems?

Nasser gravatar imageNasser ( 2021-05-17 20:06:43 +0100 )edit

actually after more testing, calling libgiac(Ex).integrate(libgiac(x)) causes some problems. it returns some functions named different than when calling integrate with algorithm="giac". For example, it now uses asin instead of arcsin, and for the rest of the trig functions. This causes a problem, since expecting arcsin and not asin. I could rename these, but I do not know what other math names could change. So I think I will stick with calling integrate using algorithm="giac" for now and wait for fix in next sagemath version 9.4 when it comes out for these problems.

Nasser gravatar imageNasser ( 2021-05-17 21:59:37 +0100 )edit

Nasser,

do you plan to file a ticket on this and patch it yourself ? Thisx=would probably be an "easy" ticket.

Anyway, Giac library's answer (as well as Sympy's in the case $\frac{\left|bx\right|}{2}>1$) is a figment of their respective authors' imaginatoipn: the derivatives of the proposed expression cannot be proved equal to Ex. Deriving the other expressions with respect to x give exressions which can be proved equal to Ex.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-05-18 00:29:17 +0100 )edit

according to the first answer above, there is already a ticket on this? At least this is what I understood. I do not plan to use libgiac(Ex).integrate(libgiac(x)) since the output needs more modification. So I will wait for the interface to giac to be fixed in 9.4, which is what the first answer indicated is the case. If you meant something else, please clarify.

Nasser gravatar imageNasser ( 2021-05-18 00:44:12 +0100 )edit

@Emmanuel Charpentier -- about mathjax on ask sage: sometimes escaping the backslashes works, e.g. typing \\stuff instead of \stuff.

slelievre gravatar imageslelievre ( 2021-05-18 07:37:00 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-05-17 04:14:45 +0100

Seen: 311 times

Last updated: May 18 '21