Sage: Ticket #22891: Add giac interface to integrate
https://trac.sagemath.org/ticket/22891
<p>
Provide a <code>giac_integrator</code> function, which relies on the external (but standard) Giac package.
</p>
<p>
A test could be:
</p>
<pre class="wiki">sage: integrate(abs(cos(x)), x, 0, 2*pi, algorithm='giac')
4
</pre><p>
This test is chosen because (at the time or writing) Maxima gives a wrong result (<code>0</code>), <a class="missing wiki">SymPy?</a> gives i don't know (unevaluated), and Fricas (optional package) gives <code>'failed'</code>.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/22891
Trac 1.1.6mforetsThu, 27 Apr 2017 17:49:41 GMT
https://trac.sagemath.org/ticket/22891#comment:1
https://trac.sagemath.org/ticket/22891#comment:1
<p>
(minor, documentation): in <code>symbolic/integration/integral.py</code>, the word <code>EXAMPLES</code> appears two times, first in the usual place, then just after the <code>ALIASES</code>. this is a bit strange. shall we remove the second one?
</p>
TicketmforetsThu, 27 Apr 2017 17:52:50 GMTbranch set
https://trac.sagemath.org/ticket/22891#comment:2
https://trac.sagemath.org/ticket/22891#comment:2
<ul>
<li><strong>branch</strong>
set to <em>u/mforets/t/mforets/giac_integrator</em>
</li>
</ul>
TicketmforetsThu, 27 Apr 2017 18:04:23 GMTstatus changed; commit set
https://trac.sagemath.org/ticket/22891#comment:3
https://trac.sagemath.org/ticket/22891#comment:3
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>commit</strong>
set to <em>8e1af6dd9a52b2c90abe1c170b5a020003612dcb</em>
</li>
</ul>
<p>
setting to review; i've added the new optional keyword <code>algorithm='giac'</code>, and for the moment i wouldn't know if there is something else that needs to be done with respect to this ticket! feedback welcome
</p>
<hr />
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="https://git.sagemath.org/sage.git/commit?id=8e1af6dd9a52b2c90abe1c170b5a020003612dcb"><span class="icon"></span>8e1af6d</a></td><td><code>add giac external integrator</code>
</td></tr></table>
TicketkcrismanThu, 27 Apr 2017 18:15:58 GMT
https://trac.sagemath.org/ticket/22891#comment:4
https://trac.sagemath.org/ticket/22891#comment:4
<p>
Love this. Don't see any obvious problems with the commit (I haven't tested it, though, just reading through).
</p>
<p>
On a related note, can you test out the various tickets at <a class="ext-link" href="https://trac.sagemath.org/wiki/symbolics#Integrationtickets"><span class="icon"></span>https://trac.sagemath.org/wiki/symbolics#Integrationtickets</a> with this? In particular the <code>abs_integrate</code> ones, see e.g. <a class="closed ticket" href="https://trac.sagemath.org/ticket/12731" title="defect: Disable abs_integrate (closed: fixed)">#12731</a>. If the integrator here is powerful enough, it might be time to replace the Maxima integrator with this one; the Maxima one has many errors (though in my opinion is still way better than not having one, as most of those are on relatively "interesting" functions like your example, abs and other stuff with branch issues).
</p>
TicketmforetsThu, 27 Apr 2017 20:54:02 GMT
https://trac.sagemath.org/ticket/22891#comment:5
https://trac.sagemath.org/ticket/22891#comment:5
<p>
we may want to ensure a symbolic integral wrapper, for instance with (cf. <a class="new ticket" href="https://trac.sagemath.org/ticket/22138" title="defect: Wrong Maxima integral result for even exponents (new)">#22138</a>):
</p>
<pre class="wiki">sage: n = var('n')
sage: integral(x^n*sin(x), x, algorithm='giac')
...
NotImplementedError: Unable to parse Giac output: integrate(x^n*sin(x),x)
</pre><p>
but in other cases it already returns unevaluted:
</p>
<pre class="wiki">sage: integrate(log(1+x)/x, x, 0, 1, algorithm='giac')
integrate(ln(x + 1)/x, x, 0, 1)
</pre>
TicketmforetsThu, 27 Apr 2017 21:22:22 GMT
https://trac.sagemath.org/ticket/22891#comment:6
https://trac.sagemath.org/ticket/22891#comment:6
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/22891#comment:4" title="Comment 4">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Love this. Don't see any obvious problems with the commit (I haven't tested it, though, just reading through).
</p>
<p>
On a related note, can you test out the various tickets at <a class="ext-link" href="https://trac.sagemath.org/wiki/symbolics#Integrationtickets"><span class="icon"></span>https://trac.sagemath.org/wiki/symbolics#Integrationtickets</a> with this? In particular the <code>abs_integrate</code> ones, see e.g. <a class="closed ticket" href="https://trac.sagemath.org/ticket/12731" title="defect: Disable abs_integrate (closed: fixed)">#12731</a>. If the integrator here is powerful enough, it might be time to replace the Maxima integrator with this one; the Maxima one has many errors (though in my opinion is still way better than not having one, as most of those are on relatively "interesting" functions like your example, abs and other stuff with branch issues).
</p>
</blockquote>
<p>
:) here are some <a class="ext-link" href="https://gist.github.com/mforets/e82a3de96a17bc80a4a22ad787bdd104"><span class="icon"></span>gist of hard integrals</a>
</p>
TickettscrimTue, 02 May 2017 04:54:09 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/22891#comment:7
https://trac.sagemath.org/ticket/22891#comment:7
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Travis Scrimshaw</em>
</li>
</ul>
<p>
I think this is something that we should get into the next Sage, but we should discuss on another ticket, and possibly sage-devel, switching the default integrator.
</p>
TicketmforetsTue, 02 May 2017 15:03:54 GMT
https://trac.sagemath.org/ticket/22891#comment:8
https://trac.sagemath.org/ticket/22891#comment:8
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/22891#comment:7" title="Comment 7">tscrim</a>:
</p>
<blockquote class="citation">
<p>
I think this is something that we should get into the next Sage, but we should discuss on another ticket, and possibly sage-devel, switching the default integrator.
</p>
</blockquote>
<p>
thanks for the review!
</p>
<p>
yes, IMO some action should be taken (for example to double check with numerical integrator and show a warning if nonsense is detected / dispatch another integrator for known issues eg. abs-trig or some special functions). i am not a big fan of 'blatantly wrong' answers, because from the user's point of view, it makes you loose a lot of confidence on the software.
</p>
TicketkcrismanTue, 02 May 2017 16:00:33 GMT
https://trac.sagemath.org/ticket/22891#comment:9
https://trac.sagemath.org/ticket/22891#comment:9
<p>
Oh yeah, we would want some super testing if we switched the default. But the problem is that currently Maxima's integration for anything involving branches or abs is weak, at least the way we interface with it.
</p>
<p>
As a first approximation, perhaps we could have a system where we removed the <code>abs_integrate</code> option from Maxima and then had Sage use either Sympy or giac as a backup if "integral" was in the returned Maxima output... anyway, that's for sage-devel, for sure.
</p>
TicketvbraunThu, 04 May 2017 21:00:44 GMTstatus, branch changed; resolution set
https://trac.sagemath.org/ticket/22891#comment:10
https://trac.sagemath.org/ticket/22891#comment:10
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>branch</strong>
changed from <em>u/mforets/t/mforets/giac_integrator</em> to <em>8e1af6dd9a52b2c90abe1c170b5a020003612dcb</em>
</li>
</ul>
Ticket