Skip to content

Commit

Permalink
Trac #24028: Held definite integrals don't translate to SymPy
Browse files Browse the repository at this point in the history
{{{
sage: from sympy import sympify
sage: integral(x, x, 0, 1, hold=True)
integrate(x, x, 0, 1)
sage: sympify(_)
...
ValueError: Invalid limits given: (x, 0, 1)

sage: integral(x, x, 0, 1, hold=True)._sympy_()
...
ValueError: Invalid limits given: (x, 0, 1)
}}}

URL: https://trac.sagemath.org/24028
Reported by: rws
Ticket author(s): Ralf Stephan
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager authored and vbraun committed Dec 17, 2017
2 parents e70eba2 + 75edb7b commit 63b1669
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/sage/interfaces/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _sympysage_integral(self):
sage: sx = Symbol('x')
sage: assert integral(x, x, hold=True)._sympy_() == Integral(sx, sx)
sage: assert integral(x, x, hold=True) == Integral(sx, sx)._sage_()
sage: assert integral(x, x, 0, 1, hold=True)._sympy_() == Integral(sx, (sx,0,1)) # known bug
sage: assert integral(x, x, 0, 1, hold=True)._sympy_() == Integral(sx, (sx,0,1))
sage: assert integral(x, x, 0, 1, hold=True) == Integral(sx, (sx,0,1))._sage_()
"""
from sage.misc.functional import integral
Expand Down
26 changes: 21 additions & 5 deletions src/sage/symbolic/integration/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _print_latex_(self, f, x):
class DefiniteIntegral(BuiltinFunction):
def __init__(self):
"""
Symbolic function representing a definite integral.
The symbolic function representing a definite integral.
EXAMPLES::
Expand All @@ -156,7 +156,7 @@ def __init__(self):

def _eval_(self, f, x, a, b):
"""
Returns the results of symbolic evaluation of the integral
Return the results of symbolic evaluation of the integral
EXAMPLES::
Expand Down Expand Up @@ -185,7 +185,7 @@ def _eval_(self, f, x, a, b):

def _evalf_(self, f, x, a, b, parent=None, algorithm=None):
"""
Returns numerical approximation of the integral
Return a numerical approximation of the integral
EXAMPLES::
Expand All @@ -209,7 +209,7 @@ def _evalf_(self, f, x, a, b, parent=None, algorithm=None):

def _tderivative_(self, f, x, a, b, diff_param=None):
"""
Returns derivative of symbolic integration
Return the derivative of symbolic integration
EXAMPLES::
Expand All @@ -233,7 +233,7 @@ def _tderivative_(self, f, x, a, b, diff_param=None):

def _print_latex_(self, f, x, a, b):
r"""
Returns LaTeX expression for integration of a symbolic function.
Convert this integral to LaTeX notation
EXAMPLES::
Expand All @@ -254,6 +254,22 @@ def _print_latex_(self, f, x, a, b):
dx_str = "{d %s}"%(latex(x))
return "\\int_{%s}^{%s} %s\\,%s"%(latex(a), latex(b), latex(f), dx_str)

def _sympy_(self, f, x, a, b):
"""
Convert this integral to the equivalent SymPy object
The resulting SymPy integral can be evaluated using ``doit()``.
EXAMPLES::
sage: integral(x, x, 0, 1, hold=True)._sympy_()
Integral(x, (x, 0, 1))
sage: _.doit()
1/2
"""
from sympy.integrals import Integral
return Integral(f, (x, a, b))

definite_integral = DefiniteIntegral()


Expand Down

0 comments on commit 63b1669

Please sign in to comment.