HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleintegration-0.2.1Haskell98

Numeric.Integration.TanhSinh

An implementation of Takahashi and Mori's Tanh-Sinh quadrature.

Tanh-Sinh provides good results across a wide-range 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 1e-6 $ parTrap sin (pi/2) pi
Result {result = 0.9999999999999312, errorEstimate = 2.721789573237518e-10, evaluations = 25}
ghci> confidence $ absolute 1e-6 $ 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 1e-6 $ trap (recip . sqrt . sin) 0 1
Result {result = 2.03480500404275, errorEstimate = 6.349514558579017e-8, evaluations = 49}

See John D. Cook's "Care and Treatment of Singularities" for a sense of how more naïve quadrature schemes fare.

  • 1 type
  • 11 values
  • Packageintegration-0.2.1
  • Exports12
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceTanhSinh.hs

Quadrature methods

7 declarations
datadata Result
#

Integral with an result and an estimate of the error such that (result - errorEstimate, result + errorEstimate) probably bounds the actual answer.

Instances4Eq, Ord, Read, Show
  • Eq ResultDefined in integration-0.2.1 · Numeric.Integration.TanhSinh
  • Ord ResultDefined in integration-0.2.1 · Numeric.Integration.TanhSinh
  • Read ResultDefined in integration-0.2.1 · Numeric.Integration.TanhSinh
  • Show ResultDefined in integration-0.2.1 · Numeric.Integration.TanhSinh

Estimated error bounds

2 declarations

Confidence intervals

1 declaration

Changes of variables

2 declarations
valuenonNegative
  1. :: (Double -> Double) -> Double -> Double -> r
  2. -> Double -> Double
  3. -> r
#

Integrate a function from 0 to infinity by using the change of variables x = t/(1-t)

This works much better than just clipping the interval at some arbitrary large number.

valueeverywhere
  1. :: (Double -> Double) -> Double -> Double -> r
  2. -> Double -> Double
  3. -> r
#

Integrate from -inf to inf using tanh-sinh 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.