Skip to content

smart_integrate() treats finite SymPy bounds as infinities #106

Description

@BenWibking

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-code-auditIssues found by AI code audit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions