math-functions-0.1.1.2: Special functions and Chebyshev polynomials

Portabilityportable
Stabilityexperimental
Maintainer[email protected]
Safe HaskellNone

Numeric.SpecFunctions

Contents

Description

Special functions and factorials.

Synopsis

Gamma function

logGamma :: Double -> DoubleSource

Compute the logarithm of the gamma function Γ(x). Uses Algorithm AS 245 by Macleod.

Gives an accuracy of 10–12 significant decimal digits, except for small regions around x = 1 and x = 2, where the function goes to zero. For greater accuracy, use logGammaL.

Returns ∞ if the input is outside of the range (0 < x ≤ 1e305).

logGammaL :: Double -> DoubleSource

Compute the logarithm of the gamma function, Γ(x). Uses a Lanczos approximation.

This function is slower than logGamma, but gives 14 or more significant decimal digits of accuracy, except around x = 1 and x = 2, where the function goes to zero.

Returns ∞ if the input is outside of the range (0 < x ≤ 1e305).

incompleteGammaSource

Arguments

:: Double

s

-> Double

x

-> Double 

Compute the normalized lower incomplete gamma function γ(s,x). Normalization means that γ(s,∞)=1. Uses Algorithm AS 239 by Shea.

invIncompleteGamma :: Double -> Double -> DoubleSource

Inverse incomplete gamma function. It's approximately inverse of incompleteGamma for the same s. So following equality approximately holds:

 invIncompleteGamma s . incompleteGamma s = id

For invIncompleteGamma s p s must be positive and p must be in [0,1] range.

Beta function

logBeta :: Double -> Double -> DoubleSource

Compute the natural logarithm of the beta function.

incompleteBetaSource

Arguments

:: Double

p > 0

-> Double

q > 0

-> Double

x, must lie in [0,1] range

-> Double 

Regularized incomplete beta function. Uses algorithm AS63 by Majumder and Bhattachrjee.

incompleteBeta_Source

Arguments

:: Double

logarithm of beta function

-> Double

p > 0

-> Double

q > 0

-> Double

x, must lie in [0,1] range

-> Double 

Regularized incomplete beta function. Same as incompleteBeta but also takes logarithm of beta function as parameter.

invIncompleteBetaSource

Arguments

:: Double

p

-> Double

q

-> Double

a

-> Double 

Compute inverse of regularized incomplete beta function. Uses initial approximation from AS109 and Halley method to solve equation.

Logarithm

log1p :: Double -> DoubleSource

Compute the natural logarithm of 1 + x. This is accurate even for values of x near zero, where use of log(1+x) would lose precision.

log2 :: Int -> IntSource

O(log n) Compute the logarithm in base 2 of the given value.

Factorial

factorial :: Int -> DoubleSource

Compute the factorial function n!. Returns ∞ if the input is above 170 (above which the result cannot be represented by a 64-bit Double).

logFactorial :: Int -> DoubleSource

Compute the natural logarithm of the factorial function. Gives 16 decimal digits of precision.

stirlingError :: Double -> DoubleSource

Calculate the error term of the Stirling approximation. This is only defined for non-negative values.

 stirlingError @n@ = @log(n!) - log(sqrt(2*pi*n)*(n/e)^n)

Combinatorics

choose :: Int -> Int -> DoubleSource

Compute the binomial coefficient n `choose` k. For values of k > 30, this uses an approximation for performance reasons. The approximation is accurate to 12 decimal places in the worst case

Example:

 7 `choose` 3 == 35

References