Skip to main content

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 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

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 and numerical backends.

Symbolic integration

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 explains these conventions.

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

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 explains their coverage and meaning.

Numerical integration

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 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 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, numerical method matrix and limitations 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 explains these distinctions.

Principal values and Hadamard finite parts require an explicit prescription. Their finite values do not establish ordinary convergence. The regularization guide 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 and domain requirements explain the checks.

Guides and examples

The executable method example catalog has a representative example for every documented method.

The method reference guide maps mathematical methods to sources and implementation modules.

Executable examples live in examples, and the demo notebook connects the mathematical formulas to calls.

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

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)):

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

This demonstrates the identity and its value; the automatic planner may choose another proved route for the same density. See selected symbolic families for endpoint factors and shifted or truncated gamma moments, and worked integral identities for additional derivations.

Geometry casebook

The examples share these imports:

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

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

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

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

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.

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. The testing guide describes the mathematical, property, slow and packaging checks.

See the release notes for changes and the limitations and known issues for unresolved cases.

MultipleIntegrate is licensed under the GNU General Public License version 3 only (GPL-3.0-only). See LICENSE.

Metadata

Release files for multiple-integrate 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for multiple-integrate 2.3.0
File Size Uploaded Provenance Actions
multiple_integrate-2.3.0.tar.gz 1.0 MB With provenance Details for multiple_integrate-2.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for multiple-integrate 2.3.0
File Interpreter ABI Platform Actions
multiple_integrate-2.3.0-py3-none-any.whl Python 3 none any Details for multiple_integrate-2.3.0-py3-none-any.whl

Total release size: 1.6 MB

Release files / multiple_integrate-2.3.0.tar.gz

Download URL multiple_integrate-2.3.0.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
4336dfda472705c5d70870e839dde41dcf37a647b483292a6f92a4debe6721db
BLAKE2b-256 checksum
How to use checksums
8344d422ac326ec7555f9a045b05e91bdd9af260234de819d7f6cdb7add1c2e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / multiple_integrate-2.3.0-py3-none-any.whl

Download URL multiple_integrate-2.3.0-py3-none-any.whl
Size 559.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5dee93147bb22b7ca198f4af7f1cd24310555a766db6027eead1ada498e0386
BLAKE2b-256 checksum
How to use checksums
e3e6a9cda67ffd14ddc9233671fd326db9a92e80ccaf32f3a5303439af0aad28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for multiple-integrate 2.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for multiple_integrate-2.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page