Opened 2 years ago

Closed 2 years ago

#22891 closed enhancement (fixed)

Add giac interface to integrate

Reported by: mforets Owned by:
Priority: major Milestone: sage-8.0
Component: calculus Keywords: giac, integrate, symbolics
Cc: Merged in:
Authors: Marcelo Forets Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 8e1af6d (Commits) Commit: 8e1af6dd9a52b2c90abe1c170b5a020003612dcb
Dependencies: Stopgaps:

Description

Provide a giac_integrator function, which relies on the external (but standard) Giac package.

A test could be:

sage: integrate(abs(cos(x)), x, 0, 2*pi, algorithm='giac')
4

This test is chosen because (at the time or writing) Maxima gives a wrong result (0), SymPy? gives i don't know (unevaluated), and Fricas (optional package) gives 'failed'.

Change History (10)

comment:1 Changed 2 years ago by mforets

(minor, documentation): in symbolic/integration/integral.py, the word EXAMPLES appears two times, first in the usual place, then just after the ALIASES. this is a bit strange. shall we remove the second one?

comment:2 Changed 2 years ago by mforets

  • Branch set to u/mforets/t/mforets/giac_integrator

comment:3 Changed 2 years ago by mforets

  • Commit set to 8e1af6dd9a52b2c90abe1c170b5a020003612dcb
  • Status changed from new to needs_review

setting to review; i've added the new optional keyword algorithm='giac', 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


New commits:

8e1af6dadd giac external integrator

comment:4 follow-up: Changed 2 years ago by kcrisman

Love this. Don't see any obvious problems with the commit (I haven't tested it, though, just reading through).

On a related note, can you test out the various tickets at https://trac.sagemath.org/wiki/symbolics#Integrationtickets with this? In particular the abs_integrate ones, see e.g. #12731. 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).

comment:5 Changed 2 years ago by mforets

we may want to ensure a symbolic integral wrapper, for instance with (cf. #22138):

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)

but in other cases it already returns unevaluted:

sage: integrate(log(1+x)/x, x, 0, 1, algorithm='giac')
integrate(ln(x + 1)/x, x, 0, 1)

comment:6 in reply to: ↑ 4 Changed 2 years ago by mforets

Replying to kcrisman:

Love this. Don't see any obvious problems with the commit (I haven't tested it, though, just reading through).

On a related note, can you test out the various tickets at https://trac.sagemath.org/wiki/symbolics#Integrationtickets with this? In particular the abs_integrate ones, see e.g. #12731. 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).

:) here are some gist of hard integrals

comment:7 follow-up: Changed 2 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

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.

comment:8 in reply to: ↑ 7 Changed 2 years ago by mforets

Replying to tscrim:

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.

thanks for the review!

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.

Last edited 2 years ago by mforets (previous) (diff)

comment:9 Changed 2 years ago by kcrisman

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.

As a first approximation, perhaps we could have a system where we removed the abs_integrate 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.

comment:10 Changed 2 years ago by vbraun

  • Branch changed from u/mforets/t/mforets/giac_integrator to 8e1af6dd9a52b2c90abe1c170b5a020003612dcb
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.