quad-rs
Adaptive real and complex numerical integration.
quad-rs provides adaptive Gauss–Kronrod quadrature for real intervals,
complex contours, and user-defined parameterised integration paths.
The crate is designed around three core ideas:
- integrands are ordinary Rust types implementing [
Integrable], - integration domains are represented by finite contour pieces,
- adaptive refinement is driven by local Gauss–Kronrod error estimates.
Features
- Real-valued integration over finite intervals.
- Complex contour integration.
- Piecewise-linear contours.
- Circular arcs and closed half-disk contours.
- Local contour indentation around poles.
- Scalar, complex, vector, matrix, and array-valued outputs via
[
IntegrationOutput]. - Optional storage of quadrature samples for diagnostics and plotting.
Real integration
use ;
;
let result = integrate_real?;
println!;
println!;
Complex contour integration
use Complex;
use ;
;
let contour = upper_half_disk_offset;
let result = integrate_complex?;
println!;
Contour deformation
Known poles can be avoided by locally replacing part of a line segment with a small circular indentation.
use Complex;
use ;
let contour = real_axis
.indent;
This is useful for Cauchy principal values, Green's functions, residue
calculations, and i0⁺/i0⁻ prescriptions.
Configuration
[IntegratorConfig] controls tolerances, quadrature order, error reduction,
singularity handling, and whether quadrature samples are stored.
use ;
let config = default
.with_absolute_tolerance
.with_relative_tolerance
.with_error_norm
.store_segment_data;
Infinite and oscillatory integrals
The current algorithms operate on finite contour pieces.
Infinite-domain integrals should be handled by truncating the domain, providing a custom parameterised contour piece, or using problem-specific transformations. Highly oscillatory integrals may require manual splitting at known periods or specialized quadrature strategies.
Examples
The examples/ directory includes demonstrations of:
- Gaussian quadrature over a real interval,
- vector-valued integration,
- Fresnel-type oscillatory integrals,
- Cauchy's integral formula,
- residue-theorem calculations,
- indented pole contours,
- Sommerfeld-style branch-point integrals,
- Bromwich inversion,
- half-disk Fourier contours.
Crate structure
Most users only need:
- [
integrate_real], - [
integrate_complex], - [
IntegratorConfig], - [
Integrable], - [
Contour] and related contour constructors.
Lower-level types such as segment heaps and Gauss–Kronrod internals are implementation details.
License: MIT OR Apache-2.0