#math #mathematics #numerics

quadrature

This provides several fast numerical integration methods. This library is pure safe rust, and cross-platform. The double exponential algorithm is naturally adaptive, and does not allocate.

3 releases

Uses old Rust 2015

0.1.2 Jan 9, 2017
0.1.1 Dec 12, 2016
0.1.0 Dec 12, 2016

#2185 in Algorithms

Download history 138/week @ 2023-11-05 101/week @ 2023-11-12 298/week @ 2023-11-19 427/week @ 2023-11-26 424/week @ 2023-12-03 305/week @ 2023-12-10 259/week @ 2023-12-17 313/week @ 2023-12-24 239/week @ 2023-12-31 317/week @ 2024-01-07 240/week @ 2024-01-14 202/week @ 2024-01-21 290/week @ 2024-01-28 281/week @ 2024-02-04 377/week @ 2024-02-11 396/week @ 2024-02-18

1,351 downloads per month
Used in 6 crates

BSD-2-Clause

53KB
971 lines

This library provides fast numerical integration of one dimensional, real valued, functions over finite intervals. It is pure safe rust, and cross-platform.

The primary function is quadrature::integrate, witch uses the double exponential algorithm. It is a port of the Fast Numerical Integration from c++ to rust. The original code is by John D. Cook, and is licensed under the BSD.

The double exponential algorithm is naturally adaptive, it stops calling the integrand when the error is reduced to below the desired threshold. It also does not allocate. No box, no vec, etc. It has a hard coded maximum of approximately 350 function evaluations. This guarantees that the algorithm will return. The error in the algorithm decreases exponentially in the number of function evaluations, specifically O(exp(-cN/log(N))). So if 350 function evaluations is not giving the desired accuracy than the programmer probably needs to give some guidance by splitting up the range at singularities or other preparation techniques.

Other Algorithms

The clenshaw_curtis module provides a integrate function with the same signature as quadrature::integrate. The implemented variant of clenshaw curtis quadrature is adaptive, however the weights change for each adaptation. This unfortunately means that the sum needs to be recalculated for each layer of adaptation. It also does not allocate on the heap, however it does use a [f64; 129] to store the function values. It has a hard coded maximum of approximately 257 function evaluations. This guarantees that the algorithm will return. The clenshaw curtis algorithm exactly integrates polynomials of order N. This implementation starts with an N of approximately 5 and increases up to an N of approximately 257. In general the error in the algorithm decreases exponentially in the number of function evaluations. In summery clenshaw curtis will in general use more stack space and run slower than the double exponential algorithm, unless clenshaw curtis can get the exact solution.

Testing

I have been testing against rust 1.0 with:

> rustup override set 1.0.0
> cargo test
> rustup override set nightly
> cargo test
> cargo bench

It is also tested on travis Build Status. I think bumping rust version is a breaking change, and will be respected in semver.

No runtime deps