- Home
- Library
- Computational Quantum Field Theory
- Integrating a Field-Theory Observable
- Adaptive Quadrature and Numerical Precision
Adaptive Quadrature and Numerical Precision
A numerical loop integral can return an error estimate smaller than the requested tolerance and still be wrong. One reason is that the sampling nodes never encounter a narrow feature. Another is that the integral is accurate but the final subtraction destroys its useful digits. These failures require different repairs.
We develop an adaptive rule whose decisions can be inspected, then evaluate a narrow Gaussian and a small, subtracted bubble remainder. The examples separate integration error, floating-point error, and the uncertainty in an error estimate. The setup needs one-variable integration and a first loop integral; the numerical argument is self-contained.
What an adaptive error indicator measures
On an interval , map the -point Gauss–Legendre rule from :
Its weights and nodes integrate every polynomial of degree at most exactly. Our local approximation is , with indicator
This pair uses eight evaluations: the implementation evaluates the two rules separately. It is a small teaching implementation, rather than an embedded Gauss–Kronrod rule or a reimplementation of QUADPACK. If both rules resolve a smooth function, their difference often detects where more resolution is useful. It is not a rigorous bound for an arbitrary continuous function.
For a partition , form
The algorithm is concrete:
- Evaluate both rules on each initial interval.
- If , report that the indicator meets the target.
- Otherwise remove the interval with the largest , bisect it, and evaluate the two child intervals.
- Replace its contributions to and , then repeat. Stop with a distinct failure status if the evaluation budget is exhausted.
Each bisection costs sixteen new evaluations. A priority queue selects the next interval; accurate summation of the retained contributions reduces accumulation error. An absolute tolerance is indispensable when the integral is zero or close to zero.
The production library scipy.integrate.quad also supplies an absolute error estimate, optional known breakpoints, and evaluation counts, but uses its own QUADPACK algorithms. Its tolerance request cannot guarantee discovery of an unseen sharp feature. See the tested SciPy 1.13.1 documentation, parameters epsabs, epsrel, points, and the final pulse example.
A peak that no initial node sees
Consider
Its exact integral is
indistinguishable from at binary64 precision. With the single initial interval , every node of our pair is far from the peak. All eight function evaluations underflow to zero. The result and indicator are both zero; the requested absolute tolerance is falsely reassuring.
Known structure changes the problem. Introduce breakpoints at , , and . Alternatively set
Integrate the central interval , split at zero. The discarded part of the original domain is bounded by the larger full Gaussian tail . This analytic tail bound is separate from the quadrature indicator.
| Method | Integral | Indicator | Evaluations |
|---|---|---|---|
| G3/G5, no breakpoints | |||
| G3/G5, known peak breakpoints | |||
| G3/G5, rescaled central interval | |||
SciPy quad, no breakpoints |
The last row is a retained failure on this declared input, not a general comparison of integrator quality. The repaired calculations use information about the feature that the blind calls lack. Merely tightening a tolerance cannot force discovery when current observations suggest an identically zero function.
A fixed-energy detector bin uses exactly this Gaussian to measure the vacuum line of a free scalar. Changing the lattice spacing then moves the center of the peak. An accurately integrated line can give a biased continuum bin weight even after the breakpoints have fixed the integration error.
A precise integral followed by an imprecise subtraction
Use the dimensionless Euclidean variable and define
Here is the chapter's subtracted massive bubble. There is no branch ambiguity on this Euclidean interval. Let and subtract its first Taylor term:
The two subtracted terms are of order , whereas is of order . Their subtraction condition number is
In binary64, unit roundoff is . Many relative digits in can therefore be lost even when both larger terms have small relative errors. The scale describes amplification of small input errors, not the exact rounding error in every run.
Using log1p(x) instead of log(1+x) avoids rounding to too early. It does not itself stabilize the subsequent subtraction . For , evaluate the remainder directly:
The code uses and Horner evaluation. Factoring out preserves the small scale instead of creating it by subtracting two numbers of order . Series truncation has its own analytic bound.
The following results compare separate integration and subtraction with the stable remainder integrand. References use exact decimal inputs and independent 80- and 120-digit integration; the binary64 computation uses the corresponding rounded inputs.
| Reference | Relative error, separate terms | Relative error, stable integrand | |
|---|---|---|---|
| at displayed precision | |||
Directly integrating the unstable pointwise difference also has a cost: at and , the adaptive rule exhausts its 99,992 usable evaluations while trying to resolve rounding fluctuations. The stable integrand meets the same requested tolerance with eight evaluations in these two cases. The nearly polynomial integrand becomes easy to integrate once it is represented accurately.
The left panel resolves the peak region that all initial nodes missed. The right panel compares with the decimal-input reference for ; plotted errors have a display floor at . Subdivision and stable arithmetic address different failures.
Reproduction and interpretation
Run python3 examples/computational-qft/numerical-integration/adaptive_quadrature.py from the source distribution to regenerate quadrature-results.json. The companion checks polynomial exactness, interval splitting, budget termination, the Gaussian tail, and high-precision remainder references. Its largest polynomial-rule discrepancy is . All four stable remainders pass a relative-error check, including the result.
The output preserves every final interval and indicator, revealing where evaluations were spent. It does not certify a bound between the nodes. For a loop calculation, first expose known singularities or narrow scales, then choose a quadrature method and a stable expression. Endpoint subtraction and contour deformation treat analytic structure that this smooth Euclidean example avoids.
Exercises
1. Derive the small remainder and its truncation bound
Show that . For , bound the error from truncating the integrand series after degree .
Solution
Since , the alternating logarithm series converges uniformly in this range and can be integrated term by term. The beta integral gives
Therefore
The first coefficients are and . Integrating the pointwise alternating remainder bound yields
The latter is the simple uniform bound retained with the computation. Neither bound controls floating-point rounding or quadrature.
2. Can finite sampled values certify every smooth integrand?
Suppose an algorithm samples finitely many points and observes zero at each. Construct a smooth nonnegative function with the same observations and integral . What additional information would permit a useful deterministic error bound?
Solution
The finite set leaves an open interval without sampled points. Let and choose . Set
This function and all its derivatives vanish at the support boundary. Divide it by its positive integral. The resulting smooth function has integral and vanishes at every sampled node, exactly as the zero function does.
The observations cannot distinguish these functions. A bound needs further assumptions: for example, a known derivative bound, analyticity in a specified complex neighborhood, or known locations and widths for sharp features. Such information can enter an analytic remainder estimate or a guaranteed mesh resolution. The G3/G5 difference alone supplies none of it.
Summary
Adaptive subdivision allocates evaluations according to observed structure. It cannot infer a feature that all its nodes miss, or restore digits already lost inside an integrand or final subtraction. A useful calculation combines analytic information, stable variable changes and arithmetic, an explicit stopping status, and independently controlled reference answers.
References
- SciPy developers, SciPy 1.13.1 Manual,
scipy.integrate.quad, tolerance and breakpoint parameters, QUADPACK notes, and the final sharp-pulse example. The companion's G3/G5 implementation and retained tests are original teaching calculations.
Scrollable formula. Use Left and Right arrow keys to reveal hidden content.
Scrollable table. Use Left and Right arrow keys to reveal hidden columns.
Scrollable figure. Use Left and Right arrow keys to reveal hidden content.