FLINT3.7.0-dev
Algorithm

Rigorous numerical integration

Cost
For an integrand that is analytic in a neighbourhood of the path and bounded there, O(p)O(p) evaluations at pp bits (Gauss–Legendre degree O(p)O(p) on O(1)O(1) subintervals); with endpoint singularities or near-singularities, O(p2)O(p^2) evaluations in the worst case. Nodes and weights cost O(p2)O(p^2) operations per degree and are cached.

Let ff be a function that is analytic on a neighbourhood of the segment [a,b]⊂C[a, b] \subset \mathbb{C} (except possibly at isolated points where it is integrable) and that can be evaluated in ball arithmetic. The goal is a ball containing I=∫abf(t) dtI = \int_a^b f(t)\,dt whose radius is close to a requested tolerance. Classical numerical integration estimates the error from differences between quadrature rules, which can be fooled; in ball arithmetic, the error must be bounded rigorously, and FLINT does this with bounds of ∣f∣|f| on complex neighbourhoods of the path, following Petras [Pet2002] and [Joh2018a].

Direct enclosure#

If BB is a ball (a box in the complex plane) containing the segment from aa to bb, and FF is a ball containing f(B)f(B), then I∈(b−a)FI \in (b - a) F. This direct enclosure needs only one evaluation of ff on a wide ball and is valid for any integrable ff, but it converges only linearly as the segment shrinks: its radius is about ∣b−a∣⋅∣f′∣⋅∣b−a∣|b - a| \cdot |f'| \cdot |b - a|. It is used for the initial estimate on each subinterval and to stop at segments where ff is so small or the segment so short that the enclosure already meets the tolerance.

Gauss–Legendre quadrature with ellipse bounds#

For [a,b]=[−1,1][a, b] = [-1, 1], the Gauss–Legendre rule of degree nn is

Qn=∑k=1nwkf(xk),Q_n = \sum_{k=1}^{n} w_k f(x_k),

where the nodes xkx_k are the roots of the Legendre polynomial PnP_n and wkw_k are the corresponding weights; it is exact for polynomials of degree less than 2n2n. For ρ>1\rho > 1, let EρE_\rho be the Bernstein ellipse with foci ±1\pm 1 and semi-axes (ρ+ρ−1)/2(\rho + \rho^{-1})/2 and (ρ−ρ−1)/2(\rho - \rho^{-1})/2.

Theorem 1. If ff is analytic inside EρE_\rho and ∣f(z)∣≤M|f(z)| \le M there, then

∣I−Qn∣≤64M15(ρ2−1)ρ2n≤64M15(ρ−1)ρ2n−1.|I - Q_n| \le \frac{64 M}{15 (\rho^2 - 1) \rho^{2n}} \le \frac{64 M}{15 (\rho - 1) \rho^{2n - 1}}.

Proof. The first inequality is due to Trefethen [Tre2008] (see also [Tre2013, Chapter 19]); it follows from the Chebyshev expansion of ff, whose coefficients are bounded by 2Mρ−k2M\rho^{-k}, and the exactness of the rule on polynomials of degree less than 2n2n. The second follows from (ρ2−1)ρ2n=(ρ−1)(ρ+1)ρ2n≥(ρ−1)ρ2n−1(\rho^2 - 1)\rho^{2n} = (\rho - 1)(\rho + 1)\rho^{2n} \ge (\rho - 1)\rho^{2n-1}.

acb_calc_integrate_gl_auto_deg maps the segment to [−1,1][-1, 1] by t=m+δxt = m + \delta x with m=(a+b)/2m = (a + b)/2, δ=(b−a)/2\delta = (b - a)/2, and tries the ellipses with (ρ+ρ−1)/2=X(\rho + \rho^{-1})/2 = X for X=2,4,8,32,512,…X = 2, 4, 8, 32, 512, \ldots (that is, X=2e+1X = 2^{e+1} with e=0,1,2,4,8,…e = 0, 1, 2, 4, 8, \ldots, e<pe < p). For each XX, it evaluates ff once on the box m+δ([−X,X]+[−Y,Y]i)m + \delta([-X, X] + [-Y, Y] i) with Y=X2−1Y = \sqrt{X^2 - 1}, which contains the image of EρE_\rho, with the flag that asks for a proof of analyticity (the evaluator must return a non-finite value if ff might not be analytic in the box; see Rigorous numerical integration). If the result is finite, M=∣δ∣max⁡∣f∣M = |\delta| \max|f| bounds the integrand of the transformed integral, and the smallest degree nn in the list 1,2,4,6,8,12,16,22,32,46,64,…1, 2, 4, 6, 8, 12, 16, 22, 32, 46, 64, \ldots (steps of about 2\sqrt 2, up to the degree limit) for which the bound of Theorem 1 is below the tolerance is recorded. The search stops at the first non-finite evaluation, since larger boxes contain the smaller ones, and otherwise picks the smallest degree over all XX. The rule is then evaluated in ball arithmetic and the bound added to the radius. If no degree works, the function reports failure and the caller bisects.

The nodes and weights are computed with arb_hypgeom_legendre_p_ui_root (an initial isolating interval following Petras, refined by interval Newton iteration on PnP_n with doubling precision) and cached per degree, at a precision that at least doubles plus 30 bits when more precision is needed, in a thread-local cache; only half of them are stored, using the symmetry xn+1−k=−xkx_{n+1-k} = -x_k. Computing them takes O(n2)O(n^2) operations, but in an adaptive integration the same few degrees are used many times.

The choice of ellipses reflects the trade-off in Theorem 1: a larger ρ\rho gives faster convergence, but MM grows, and singularities of ff limit ρ\rho. A pole at distance dd from a segment of half-length hh allows ρ≈1+d/h\rho \approx 1 + d/h for small d/hd/h, so that n≈(pln⁡2)/(2d/h)n \approx (p \ln 2)/(2 d/h) nodes are needed; bisection reduces hh and with it the degree.

Adaptive subdivision#

Algorithm 1: Adaptive integration

Input: ff, aa, bb, a relative goal gg (bits), an absolute tolerance τ\tau, limits on the subdivision depth, the number of evaluations and the degree, and a precision pp.

  1. Compute the direct enclosure vv on [a,b][a, b] and set the working tolerance to τ′=max⁡(τ,2−g∣v∣low)\tau' = \max(\tau, 2^{-g} |v|_{\mathrm{low}}), where ∣v∣low|v|_{\mathrm{low}} is a lower bound for the absolute value.
  2. Keep a stack (or, optionally, a priority queue ordered by radius) of subintervals with their direct enclosures. Repeatedly take a subinterval JJ:

    • if the radius of its direct enclosure is below τ′\tau', or JJ is so short that its endpoints overlap at precision pp, or a limit has been reached, add the direct enclosure to the sum;
    • otherwise, if Gauss–Legendre quadrature with the tolerance τ′\tau' succeeds on JJ, add its result to the sum;
    • otherwise, bisect JJ, compute the direct enclosures of both halves and push them, the one with the larger radius on top.
  3. After each new enclosure uu, update τ′←max⁡(τ′,2−g∣u∣low)\tau' \leftarrow \max(\tau', 2^{-g} |u|_{\mathrm{low}}).
  4. Return the sum, and a status that indicates whether a limit was reached.

The result is always a valid enclosure: every subinterval contributes either a direct enclosure or a Gauss–Legendre result with a rigorous error bound, and the subintervals partition [a,b][a, b]. The tolerance and the limits only affect the work and the radius. The update of τ′\tau' implements the relative goal: the integral over a subinterval with large values gives a lower bound for the magnitude of the result only heuristically (the integrals over different subintervals may cancel), but this only makes the radius larger than requested in such cases, not the result wrong. If the direct enclosure of a subinterval is real, the imaginary part of the Gauss–Legendre result is set to zero, since the integral is then real.

The default limits are a degree of at most 0.5min⁡(g,p)+600.5 \min(g, p) + 60, at most 1000p+p21000p + p^2 evaluations and a depth of at most 2p2p (the stack size; with the depth-first strategy, this bounds the nesting of bisections). Bisection handles singularities at or near the path: near an integrable endpoint singularity, the intervals shrink geometrically towards the singularity, and each level costs one Gauss–Legendre evaluation of low degree on the subinterval adjacent to the one containing the singularity, so about pp levels and O(p)O(p) evaluations per level are needed. Functions that are not analytic, such as ∣t∣|t| or ⌊t⌋\lfloor t \rfloor, can be integrated if the evaluator reports non-analyticity on boxes that contain a discontinuity, so that the integration falls back to direct enclosures on the subintervals that contain such a point. Since the direct enclosure on an interval of length hh containing a jump has radius of order hh (and of order h2h^2 for a kink), about pp (respectively p/2p/2) bisection levels are needed around each such point; it is cheaper to pass these points as endpoints of separate integrals.

Use in FLINT#

Referenced from#

References#

  • [Pet2002] K. Petras. Self-validating integration and approximation of piecewise analytic functions. Journal of Computational and Applied Mathematics 145:2 (2002), 345–359. https://doi.org/10.1016/S0377-0427(01)00586-2
  • [Joh2018a] F. Johansson, "Numerical integration in arbitrary-precision ball arithmetic", preprint (2018), https://arxiv.org/abs/1802.07942
  • [Tre2008] L. N. Trefethen, "Is Gauss Quadrature Better than Clenshaw-Curtis?", SIAM Review, 50:1 (2008), 67-87, https://doi.org/10.1137/060659831
  • [Tre2013] L. N. Trefethen. Approximation Theory and Approximation Practice. SIAM, 2013.
Cite this page

The FLINT team, “Rigorous numerical integration,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/ball-arithmetic/integration.html (generated 2026-11-02).