Portability  portable 

Stability  provisional 
Maintainer  Edward Kmett <ekmett@gmail.com> 
Safe Haskell  None 
An implementation of Takahashi and Mori's TanhSinh quadrature.
TanhSinh provides good results across a widerange of functions and is pretty much as close to a universal quadrature scheme as is possible. It is also robust against error in the presence of singularities at the endpoints of the integral.
The change of basis is precomputed, and information is gained quadratically in the number of digits.
ghci> absolute 1e6 $ parTrap sin (pi/2) pi Result {result = 0.9999999999999312, errorEstimate = 2.721789573237518e10, evaluations = 25}
ghci> confidence $ absolute 1e6 $ trap sin (pi/2) pi (0.9999999997277522,1.0000000002721101)
Unlike most quadrature schemes, this method is also fairly robust against singularities at the end points.
ghci> absolute 1e6 $ trap (recip . sqrt . sin) 0 1 Result {result = 2.03480500404275, errorEstimate = 6.349514558579017e8, evaluations = 49}
See John D. Cook's "Care and Treatment of Singularities" for a sense of how more naïve quadrature schemes fare.
 trap :: (Double > Double) > Double > Double > [Result]
 simpson :: (Double > Double) > Double > Double > [Result]
 trap' :: Strategy [Double] > (Double > Double) > Double > Double > [Result]
 simpson' :: Strategy [Double] > (Double > Double) > Double > Double > [Result]
 parTrap :: (Double > Double) > Double > Double > [Result]
 parSimpson :: (Double > Double) > Double > Double > [Result]
 data Result = Result {
 result :: !Double
 errorEstimate :: !Double
 evaluations :: !Int
 absolute :: Double > [Result] > Result
 relative :: Double > [Result] > Result
 confidence :: Result > (Double, Double)
 nonNegative :: ((Double > Double) > Double > Double > r) > (Double > Double) > r
 everywhere :: ((Double > Double) > Double > Double > r) > (Double > Double) > r
Quadrature methods
trap :: (Double > Double) > Double > Double > [Result]Source
Integration using a truncated trapezoid rule under tanhsinh quadrature
simpson :: (Double > Double) > Double > Double > [Result]Source
Integration using a truncated Simpson's rule under tanhsinh quadrature
trap' :: Strategy [Double] > (Double > Double) > Double > Double > [Result]Source
Integration using a truncated trapezoid rule and tanhsinh quadrature with a specified evaluation strategy
simpson' :: Strategy [Double] > (Double > Double) > Double > Double > [Result]Source
Integration using a truncated Simpson's rule under tanhsinh quadrature with a specified evaluation strategy
parTrap :: (Double > Double) > Double > Double > [Result]Source
Integration using a truncated trapezoid rule under tanhsinh quadrature with buffered parallel evaluation
parSimpson :: (Double > Double) > Double > Double > [Result]Source
Integration using a truncated Simpson's rule under tanhsinh quadrature with buffered parallel evaluation
Integral with an result and an estimate of the error such that
(result  errorEstimate, result + errorEstimate)
probably bounds
the actual answer.
Result  

Estimated error bounds
absolute :: Double > [Result] > ResultSource
Filter a list of results using a specified absolute error bound
relative :: Double > [Result] > ResultSource
Filter a list of results using a specified relative error bound
Confidence intervals
confidence :: Result > (Double, Double)Source
Convert a Result to a confidence interval
Changes of variables
nonNegative :: ((Double > Double) > Double > Double > r) > (Double > Double) > rSource
Integrate a function from 0 to infinity by using the change of variables x = t/(1t)
This works much better than just clipping the interval at some arbitrary large number.
everywhere :: ((Double > Double) > Double > Double > r) > (Double > Double) > rSource
Integrate from inf to inf using tanhsinh quadrature after using the change of variables x = tan t
everywhere trap (\x > exp(x*x))
This works much better than just clipping the interval at arbitrary large and small numbers.