Metadata-Version: 2.4
Name: multiple-integrate
Version: 2.3.0
Summary: Symbolic and numerical definite integration with geometric reductions, coordinate transformations, and convergence analysis.
Author-email: Bhuvanesh Bhatt <bhuvaneshbhatt@gmail.com>
License-Expression: GPL-3.0-only
Project-URL: Homepage, https://github.com/BhuvaneshBhatt/multiple_integrate
Project-URL: Documentation, https://multiple-integrate.readthedocs.io/
Project-URL: Source, https://github.com/BhuvaneshBhatt/multiple_integrate
Project-URL: Issue Tracker, https://github.com/BhuvaneshBhatt/multiple_integrate/issues
Project-URL: Changelog, https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/CHANGELOG.md
Keywords: symbolic mathematics,symbolic computation,integration,definite integration,multiple integrals,multivariate integrals,calculus,sympy,computer algebra,layer-cake formula,co-area formula,numerical integration,quadrature
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: sympy<2,>=1.14
Requires-Dist: mpmath<2,>=1.3
Requires-Dist: semialg>=1.5.1
Requires-Dist: funcprops>=0.5.0
Provides-Extra: numeric
Requires-Dist: numpy>=2.0; extra == "numeric"
Requires-Dist: scipy>=1.15; extra == "numeric"
Provides-Extra: numeric-all
Requires-Dist: numpy>=2.0; extra == "numeric-all"
Requires-Dist: scipy>=1.15; extra == "numeric-all"
Requires-Dist: vegas<7,>=6.2; extra == "numeric-all"
Requires-Dist: qmcpy<3,>=2.4; extra == "numeric-all"
Provides-Extra: gaussian-numeric
Requires-Dist: numpy>=2.0; extra == "gaussian-numeric"
Requires-Dist: scipy>=1.15; extra == "gaussian-numeric"
Provides-Extra: asymptotic
Requires-Dist: asymptotic>=0.2.1; extra == "asymptotic"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: hypothesis>=6; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: hypothesis>=6; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"
Provides-Extra: release
Requires-Dist: build>=1.2; extra == "release"
Requires-Dist: twine>=6; extra == "release"
Provides-Extra: notebook-test
Requires-Dist: nbclient>=0.10; extra == "notebook-test"
Requires-Dist: nbformat>=5.10; extra == "notebook-test"
Requires-Dist: ipykernel>=6; extra == "notebook-test"
Provides-Extra: notebook
Requires-Dist: jupyter>=1.0; extra == "notebook"
Requires-Dist: notebook>=7.0; extra == "notebook"
Requires-Dist: ipykernel>=6.0; extra == "notebook"
Requires-Dist: matplotlib>=3.7; extra == "notebook"
Provides-Extra: docs
Requires-Dist: sphinx<9,>=8; extra == "docs"
Requires-Dist: sphinx-rtd-theme<4,>=3; extra == "docs"
Requires-Dist: myst-parser<5,>=4; extra == "docs"
Provides-Extra: all
Requires-Dist: asymptotic>=0.2.1; extra == "all"
Requires-Dist: funcprops>=0.5.0; extra == "all"
Requires-Dist: semialg>=1.5.1; extra == "all"
Requires-Dist: pytest>=8; extra == "all"
Requires-Dist: hypothesis>=6; extra == "all"
Requires-Dist: ruff>=0.4; extra == "all"
Requires-Dist: mypy>=1.10; extra == "all"
Requires-Dist: jupyter>=1.0; extra == "all"
Requires-Dist: notebook>=7.0; extra == "all"
Requires-Dist: ipykernel>=6.0; extra == "all"
Requires-Dist: matplotlib>=3.7; extra == "all"
Requires-Dist: sphinx<9,>=8; extra == "all"
Requires-Dist: sphinx-rtd-theme<4,>=3; extra == "all"
Requires-Dist: myst-parser<5,>=4; extra == "all"
Dynamic: license-file

# MultipleIntegrate

MultipleIntegrate evaluates definite multiple/multivariate integrals by combining SymPy-based evaluation with geometric reductions, moment rules, coordinate changes and some selected regularization prescriptions. It is useful when the structure of a density or domain supplies more information than a generic antiderivative search. The package supports both symbolic and numerical results.

## Why use it?

A multiple integral is often easier after recognizing a region, separating a radial coordinate, integrating polynomial coordinates exactly or reducing a Gaussian potential to one dimension. MultipleIntegrate performs these reductions before falling back to general integration. Prepared regions and numerical plans reuse validated geometry and compilation across related requests.

The [comparison with SymPy](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/why-multipleintegrate.md) gives independently checked examples of branch cuts, singularities and coupled domains. It distinguishes wrong answers, unevaluated calls, convergent series and time limits, and includes a comparison with SymPy's `polytope_integrate`.

## Installation

```sh
pip install multiple-integrate
pip install 'multiple-integrate[numeric]'
```

Python 3.11 or newer is required. SymPy supplies expressions and fallback integration; `semialg` supplies region geometry and decomposition; `funcprops` supplies function properties; mpmath supplies arbitrary-precision evaluation. The `numeric` extra installs NumPy and SciPy. The `numeric-all` extra also installs VEGAS+ and randomised lattice support. Native Cuba methods require a separately installed Cuba library. See [installation](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/installation.rst) and [numerical backends](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-backends.md).

## Symbolic integration

```python
import sympy as sp
from multiple_integrate import integrate, integrate_result

x, y = sp.symbols("x y", real=True)
assert integrate(x**2 * y, (x, 0, 1), (y, 0, 2)) == sp.Rational(2, 3)

triangle = sp.And(x >= 0, y >= 0, x + y <= 1)
assert integrate(sp.exp(x + y), region=triangle, variables=(x, y)) == 1

result = integrate_result(sp.sin(1/x)/x, (x, 0, 1))
assert result.value == sp.pi/2 - sp.Si(1)
assert result.ordinary_convergent is True
assert result.absolute_convergent is False
```

Integration bounds follow SymPy's innermost-to-outermost order, not the outer-to-inner ordering used, for example, by Mathematica. Reversing explicit bounds changes orientation. A `region=` describes a geometric set with unsigned measure, so an empty fiber contributes zero. Use explicit `variables=` with region objects, and use `measure_dimension` to distinguish ambient volume from curve or surface measure. [Ranges and regions](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/concepts/ranges-and-regions.rst) explains these conventions.

Canonical region objects and parameter families use the same coordinate conventions:

```python
import semialg
from multiple_integrate.parameter_cells import integrate_cells

a = sp.Symbol("a", real=True)
assert integrate(1, region=semialg.Box(((0, 1), (0, 2))), variables=(x, y)) == 2
family = integrate_cells(
    1, region=x**2 <= a, variables=(x,), bounds={x: (-1, 1)}, parameters=(a,),
)
assert family.complete and family.value.subs(a, sp.Rational(1, 4)) == 1
```

`integrate` returns the mathematical value. `integrate_result` adds status, parameter cases, convergence evidence, transformations and unresolved obligations. Conditional results can contain SymPy `Piecewise` expressions; [structured results](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/structured-results.md) explains their coverage and meaning.

## Numerical integration

```python
from multiple_integrate import nintegrate, nintegrate_result

value = nintegrate(sp.exp(x*y), (x, 0, 1), (y, 0, 1))
result = nintegrate_result(
    sp.exp(x*y), (x, 0, 1), (y, 0, 1),
    absolute_tolerance=1e-9, relative_tolerance=1e-9,
)
assert result.success
assert abs(float(result.value) - 1.3179021514544039) < 1e-9
```

Automatic dispatch uses expression features, dimension, region charts, requested precision and singularities. [Certified coarea preprocessing](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-coarea.md) can eliminate radial or affine-profile fiber coordinates before quadrature. It first considers exact formulas or lower-dimensional reductions, then chooses a numerical engine with bounded fallback. Explicit method selection and counted pilot selection are available. [Numerical integration](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-integration.md) describes controls, reusable plans and batches.

`nintegrate` returns a numerical value and raises when the request cannot meet its contract. `nintegrate_result` reports the value, estimated error, error kind, tolerance status, evaluation count, precision, method and stopping reason. Domain and integrability evidence are separate from numerical uncertainty. A small estimated error does not prove convergence or provide a rigorous enclosure.

## Capabilities and requirements

| Integral or region | Support | Main requirements and limits |
|---|---|---|
| Boxes and nested bounds | Symbolic reductions and numerical quadrature | Bound order, orientation and singularities must be resolved. |
| Polynomial polygons and polytopes | Exact moments, prepared geometry and batches, including higher dimensions | Supported convex rational geometry; complexity grows with dimension and degree. |
| Balls, disks and ellipsoids | Polynomial moments, radial reductions, selected exponential and trig kernels | Each formula checks its shape, parameter and convergence hypotheses. |
| Gaussian densities and potentials | Rectangle probabilities, polygon and ellipse reductions, screened and softened attraction kernels | Selected covariance, clipping and kernel families; some answers use named probability functions or one-dimensional integrals. |
| Piecewise densities and Boolean regions | First-match branches, supported disjoint partitions and parameter cases | Incomplete partitions and unproved branch domains retain unresolved results. |
| Curves, surfaces and flux | Certified charts, graph surfaces, selected implicit surfaces and ellipsoid densities | Regularity, coverage, Jacobians and orientation require evidence. |
| Singular and improper integrals | Supported endpoint transformations, tails and geometric reductions | Arbitrary intersecting singular sets are not generally resolved. |
| Principal values, finite parts and distributions | Explicit prescriptions and selected exact reductions | Prescriptions have distinct semantics, ordinary quadrature cannot supply them implicitly. |
| Low-dimensional numerical integration | Adaptive cubature, Genz–Malik, Gauss–Kronrod, nested Gaussian and tanh-sinh rules | Backend dimension and precision limits apply. |
| Higher-dimensional numerical integration | Scrambled Sobol, randomized lattices, VEGAS+, sparse grids and native Cuba methods | Statistical or heuristic uncertainty depends on the method. |
| Oscillatory numerical integration | Levin collocation, periodic rules and supported multidimensional phase reductions | Coupled Levin blocks support two or three dimensions; arbitrary stationary manifolds are difficult. |
| Rigourous numerical enclosures | Exact rational and outward-rounded interval bounds on supported charts | Supported function ranges, pole exclusion and resource limits must be proved. |

See the [symbolic capability guide](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/capabilities.md), [numerical method matrix](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/implemented-capabilities.md) and [limitations](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/limitations.md) for precise boundaries. Rigorous charts use package-owned rational arithmetic and outward dyadic rounding.

## Results, assumptions and prescriptions

For symbolic integration, use `assumptions=` or symbol-attached assumptions to state the prerequisites of the requested parameter cell. Temporary SymPy `assuming(...)` facts are excluded from package proof queries and refinement, keeping cached evidence inside its declared scope.

Convergence evidence can be summarised across parameter cases only when those cases provably cover the requested domain. Missing equality fibers, conflicting facts and unresolved cells prevent a global conclusion. For example, the whole-plane integral of `exp(-x**2-y**2+x/a)` has value `pi*exp(1/(4*a**2))` for real `a!=0`. The structured result retains `Ne(a, 0)` and the unresolved `a=0` fiber. Nonzero conditions cannot replace positivity conditions required for Gaussian decay. [Structured results](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/structured-results.md) explains these distinctions.

Principal values and Hadamard finite parts require an explicit prescription. Their finite values do not establish ordinary convergence. The [regularization guide](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/regularization.md) explains cutoff semantics.

`Boole(condition)` constructs the SymPy indicator `Piecewise((1, condition), (0, True))`; both forms use supported geometry and first-match branch rules.

## Limits and evidence

General symbolic multiple integration has no universal algorithm. Integrals involving arbitrary implicit surfaces, unresolved parameter geometry, nonseparable singularities and general oscillatory improper tails can remain unsupported or unevaluated. Nested rules and polynomial geometry can become expensive as dimension grows, while sampling methods can miss narrow features.

Certificates reconstruct their mathematical claims during replay. Exact results, conditional formulas, ordinary convergence, prescribed regularization, numerical consistency and rigourous enclosure are separate claims. [Certification](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/certification.md) and [domain requirements](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/domain-requirements.md) explain the checks.

## Guides and examples

The [executable method example catalog](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/method-examples.md) has a representative example for every documented method.

The [method reference guide](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/method-references.md) maps mathematical methods to sources and implementation modules.

- [Supported regions and measures](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/supported-regions.md)
- [Bounded series evaluation](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/series-evaluation.md)
- [Selected symbolic families](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/selected-symbolic-families.md)
- [Exact fast methods and budgets](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/performance-methods.md)
- [Parameterized integration](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/parameterized-integration.md)
- [Result semantics and certification](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/certification.md)
- [Regularization](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/regularization.md)
- [Polygon and polytope boundary reduction](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/boundary-reduction.md)
- [Nonseparable improper integration](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/nonseparable-improper.md)
- [Laurent moments, clips and tangencies](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/laurent-clips-and-tangencies.md)
- [Nonlinear moments and singularities](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/nonlinear-moments-and-singularities.md)
- [Sectors and contact charts](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/sectors-and-contact-charts.md)
- [Limitations and known issues](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/limitations.md)

Executable examples live in [examples](https://github.com/BhuvaneshBhatt/multiple_integrate/tree/main/examples), and the [demo notebook](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/notebooks/multiple_integration.ipynb) connects the mathematical formulas to calls.

The following guides cover public interfaces, certified transformations and numerical evaluation:

- [Quick start](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/quickstart.rst)
- [API reference](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/api.md)
- [Polynomial polytopes and reusable moments](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/polynomial-polytopes.md)
- [Symbolic coarea reductions](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/coarea.md)
- [Numerical integration](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-integration.md)
- [Certified numerical coarea](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-coarea.md)
- [Numerical backends and uncertainty](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-backends.md)
- [Numerical method controls](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/numerical-method-controls.md)
- [Numerical precision and dimension limits](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/implemented-capabilities.md)
- [Prepared symbolic and numerical kernels](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/prepared-kernel-performance.md)
- [Design, performance contracts and measurements](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/design-and-performance.md)
- [Domain requirements and counterexamples](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/domain-requirements.md)
- [Worked values and convergence prescriptions](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/worked-integral-identities.md)
- [Stratified maps and truncated Gaussians](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/stratified-maps-and-truncated-gaussians.md)
- [Polynomial folds and certified moments](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/polynomial-folds-and-certified-moments.md)
- [Sheared folds and boundary formulas](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/sheared-folds-and-boundary-formulas.md)
- [Fold products and simplex enclosures](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/fold-products-and-simplex-enclosures.md)

## Worked examples

### Layer-cake identity

For a nonnegative density `f`, the layer-cake identity is
`integral(f) = integral_0^infinity volume({f > t}) dt`, with infinite values
allowed by Tonelli's theorem. For `f=exp(-g)` and `g>=0`, an equivalent form is `integral(exp(-g)) = integral_0^infinity exp(-t)*volume({g < t}) dt`.
For the positive-quadrant superellipse `g=x**4+y**4`, the sublevel area is
`Gamma(1/4)**2*sqrt(t)/(8*sqrt(pi))`:

<!-- layer-cake-start -->
```python
import sympy as sp

from multiple_integrate import integrate_result

x, y = sp.symbols("x y", real=True)
t = sp.Symbol("t", positive=True)
area = sp.gamma(sp.Rational(1, 4)) ** 2 * sp.sqrt(t) / (8 * sp.sqrt(sp.pi))
layer_value = sp.integrate(sp.exp(-t) * area, (t, 0, sp.oo))
result = integrate_result(sp.exp(-(x**4 + y**4)), (x, 0, sp.oo), (y, 0, sp.oo))
assert sp.simplify(result.value - layer_value) == 0
assert sp.simplify(layer_value - sp.gamma(sp.Rational(1, 4)) ** 2 / 16) == 0
```
<!-- layer-cake-end -->

This demonstrates the identity and its value; the automatic planner may choose
another proved route for the same density. See [selected symbolic families](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/selected-symbolic-families.md) for endpoint factors and shifted or truncated gamma moments, and [worked integral identities](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/worked-integral-identities.md) for additional derivations.

<!-- geometry-casebook-start -->
## Geometry casebook

The examples share these imports:

```python
from dataclasses import replace
import mpmath as mp
import semialg
import sympy as sp
from multiple_integrate import IntegrationOutcome, integrate_result, regularized_result
from multiple_integrate.parameter_cells import ParameterCell, integrate_cells
from multiple_integrate.regularization import HadamardFinitePart, verify_regularization_result
```

### Parameter cells and graph contact

```python
x, y, a, b = sp.symbols("x y a b", real=True)
result = integrate_cells(
    1,
    region=sp.And(x >= 0, x <= a, y >= 0, y <= b - x**2),
    variables=(x, y),
    parameters=(a, b),
    assumptions=sp.And(a > 0, b >= a**2),
    cells=(ParameterCell(b > a**2), ParameterCell(sp.Eq(b, a**2), {b: a**2})),
)
assert sp.simplify(result.cases[0].value - (a * b - a**3 / 3)) == 0
assert sp.simplify(result.cases[1].value - 2 * a**3 / 3) == 0
```

### Cusp contact and divergence

```python
x, y = sp.symbols("x y", real=True)
base = x**3 - y**2
horn = sp.And(x > 0, x < 1, y**2 <= x**3)
result = integrate_result(base ** -sp.Rational(1, 2), region=horn, variables=(x, y))
divergent = integrate_result(x**2 / base, region=horn, variables=(x, y))
assert sp.simplify(sp.expand_func(result.value) - sp.pi) == 0
assert result.absolute_convergent is True
assert divergent.outcome is IntegrationOutcome.DIVERGENT
```

### Exact finite radial series

```python
x, y, z = sp.symbols("x y z", real=True)
rho = x**2 + y**2 + z**2
result = integrate_result(
    sp.exp(-rho) / (2 + rho), region=semialg.Ball((0, 0, 0), 1), variables=(x, y, z)
)
assert result.value.has(sp.Sum) and result.absolute_convergent is True
with mp.workdps(35):
    reference = 4 * mp.pi * mp.quad(lambda r: r**2 * mp.exp(-r * r) / (2 + r * r), [0, 1])
    assert abs(mp.mpf(str(result.value.evalf(30))) - reference) < mp.mpf("1e-25")
```

### Clipped polygon finite part

```python
x, y = sp.symbols("x y", real=True)
polygon = sp.And(x >= 0, y >= 0, x <= sp.Rational(1, 2), x + y <= 1)
result = regularized_result(
    1 / (x * y),
    region=polygon,
    variables=(x, y),
    regularization=HadamardFinitePart(hypersurface=x * y),
)
assert sp.simplify(result.value + sp.pi**2 / 12 - sp.log(2) ** 2) == 0
assert verify_regularization_result(result).valid
assert not verify_regularization_result(replace(result, value=result.value + 1)).valid
```

For an ordinary result inspect `result.outcome`, `result.complete`, `result.coverage`, and `result.convergence_evidence`; for a family inspect each child in `result.diagnostics['cell_results']`. A finite-part answer describes its specified cutoff and does not prove ordinary convergence.
<!-- geometry-casebook-end -->

## Contributing

Contributions – whether they are bug reports, suggestions, or code for bugfixes or improvements – are welcome!

For development setup, architecture and extension guidance, see [Contributing](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/contributing.md). The [testing guide](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/testing.md) describes the mathematical, property, slow and packaging checks.

See the [release notes](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/CHANGELOG.md) for changes and the [limitations and known issues](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/docs/limitations.md) for unresolved cases.

MultipleIntegrate is licensed under the GNU General Public License version 3 only (GPL-3.0-only). See [LICENSE](https://github.com/BhuvaneshBhatt/multiple_integrate/blob/main/LICENSE).
