smart_integrate() treats finite SymPy bounds as infinities
Summary
Any bound that is a SymPy Basic object is converted to infinity, including finite
values such as sympy.Integer(0) and sympy.Float(1.0).
Explanation
Lines 186-188 of src/jaff/common/_integrators.py assume that a Basic lower bound
means negative infinity and a Basic upper bound means positive infinity. The public
type signature accepts Basic, however, and SymPy numeric values are also Basic.
This integrates over the entire real line and returns sqrt(pi) rather than the
integral over [0, 1]:
import sympy as sp
from jaff.common._integrators import smart_integrate
x = sp.Symbol("x")
got = smart_integrate(sp.exp(-x**2), x, (sp.Integer(0), sp.Integer(1)))
assert got == pytest.approx(0.746824132812427)
The current result is approximately 1.772453850905516.
Proposed patch
Recognize only sympy.oo and -sympy.oo as infinite. Convert finite SymPy numbers
with float(bound), and reject unresolved symbolic expressions with a descriptive
ValueError. Add tests for Python numeric bounds, SymPy numeric bounds, and each
supported infinite endpoint.
smart_integrate()treats finite SymPy bounds as infinitiesSummary
Any bound that is a SymPy
Basicobject is converted to infinity, including finitevalues such as
sympy.Integer(0)andsympy.Float(1.0).Explanation
Lines 186-188 of
src/jaff/common/_integrators.pyassume that aBasiclower boundmeans negative infinity and a
Basicupper bound means positive infinity. The publictype signature accepts
Basic, however, and SymPy numeric values are alsoBasic.This integrates over the entire real line and returns
sqrt(pi)rather than theintegral over
[0, 1]:The current result is approximately
1.772453850905516.Proposed patch
Recognize only
sympy.ooand-sympy.ooas infinite. Convert finite SymPy numberswith
float(bound), and reject unresolved symbolic expressions with a descriptiveValueError. Add tests for Python numeric bounds, SymPy numeric bounds, and eachsupported infinite endpoint.