Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the faster libgiac interface for "giac" integration #38686

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sage/calculus/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
Ensure that :issue:`25626` is fixed. As the form of the answer is dependent of
the giac version, we simplify it (see :issue:`34037`). ::

sage: # needs sage.libs.giac
sage: t = SR.var('t')
sage: integrate(exp(t)/(t + 1)^2, t, algorithm='giac').full_simplify()
((t + 1)*Ei(t + 1) - e^(t + 1))/(t*e + e)
Expand Down
1 change: 1 addition & 0 deletions src/sage/functions/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ def integral(self, parameters, variable, x=None, a=None, b=None, definite=False,

Check that the algorithm keyword can be used::

sage: # needs sage.libs.giac
sage: ex = piecewise([([0, 1], 1), ((1, oo), 1/x**2)])
sage: integral(ex, x, 0, 100, algorithm='giac')
199/100
Expand Down
44 changes: 3 additions & 41 deletions src/sage/symbolic/integration/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,53 +214,13 @@ def fricas_integrator(expression, v, a=None, b=None, noPole=True):
return result


def giac_integrator(expression, v, a=None, b=None):
r"""
Integration using Giac.

EXAMPLES::

sage: from sage.symbolic.integration.external import giac_integrator
sage: giac_integrator(sin(x), x)
-cos(x)
sage: giac_integrator(1/(x^2+6), x, -oo, oo)
1/6*sqrt(6)*pi

TESTS::

sage: giac_integrator(e^(-x^2)*log(x), x)
integrate(e^(-x^2)*log(x), x)

Check that :issue:`30133` is fixed::

sage: ee = SR.var('e')
sage: giac_integrator(ee^x, x)
e^x/log(e)
sage: y = SR.var('π')
sage: giac_integrator(cos(y), y)
sin(π)

Check that :issue:`29966` is fixed::

sage: giac_integrator(sqrt(x + sqrt(x)), x)
1/12*(2*sqrt(x)*(4*sqrt(x) + 1) - 3)*sqrt(x + sqrt(x))...
"""
ex = expression._giac_()
if a is None:
result = ex.integrate(v._giac_())
else:
result = ex.integrate(v._giac_(), a._giac_(), b._giac_())
if 'integrate' in format(result) or 'integration' in format(result):
return expression.integrate(v, a, b, hold=True)
return result._sage_()


def libgiac_integrator(expression, v, a=None, b=None):
r"""
Integration using libgiac.

EXAMPLES::

sage: # needs sage.libs.giac
sage: import sage.libs.giac
...
sage: from sage.symbolic.integration.external import libgiac_integrator
Expand All @@ -272,12 +232,14 @@ def libgiac_integrator(expression, v, a=None, b=None):

TESTS::

sage: # needs sage.libs.giac
sage: libgiac_integrator(e^(-x^2)*log(x), x)
integrate(e^(-x^2)*log(x), x)

The following integral fails with the Giac Pexpect interface, but works
with libgiac (:issue:`31873`)::

sage: # needs sage.libs.giac
sage: a, x = var('a,x')
sage: f = sec(2*a*x)
sage: F = libgiac_integrator(f, x)
Expand Down
9 changes: 6 additions & 3 deletions src/sage/symbolic/integration/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
available_integrators['sympy'] = external.sympy_integrator
available_integrators['mathematica_free'] = external.mma_free_integrator
available_integrators['fricas'] = external.fricas_integrator
available_integrators['giac'] = external.giac_integrator
available_integrators['giac'] = external.libgiac_integrator
available_integrators['libgiac'] = external.libgiac_integrator

######################################################
Expand Down Expand Up @@ -59,6 +59,7 @@ def __init__(self):

Check for :issue:`28913`::

sage: # needs sage.libs.giac
sage: Ex = (1-2*x^(1/3))^(3/4)/x
sage: integrate(Ex, x, algorithm='giac') # long time
4*(-2*x^(1/3) + 1)^(3/4) + 6*arctan((-2*x^(1/3) + 1)^(1/4)) - 3*log((-2*x^(1/3) + 1)^(1/4) + 1) + 3*log(abs((-2*x^(1/3) + 1)^(1/4) - 1))
Expand Down Expand Up @@ -200,6 +201,7 @@ def __init__(self):

Check for :issue:`32354`::

sage: # needs sage.libs.giac
sage: ex = 1/max_symbolic(x, 1)**2
sage: integral(ex, x, 0, 2, algorithm='giac')
3/2
Expand Down Expand Up @@ -467,9 +469,9 @@ def integrate(expression, v=None, a=None, b=None, algorithm=None, hold=False):

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

- ``'giac'`` -- use Giac
- ``'giac'`` -- use libgiac

- ``'libgiac'`` -- use libgiac
- ``'libgiac'`` -- use libgiac (alias for ``'giac'``)

To prevent automatic evaluation, use the ``hold`` argument.

Expand Down Expand Up @@ -690,6 +692,7 @@ def integrate(expression, v=None, a=None, b=None, algorithm=None, hold=False):

Using Giac to integrate the absolute value of a trigonometric expression::

sage: # needs sage.libs.giac
sage: integrate(abs(cos(x)), x, 0, 2*pi, algorithm='giac')
4
sage: result = integrate(abs(cos(x)), x, 0, 2*pi)
Expand Down
Loading