Compute the binomial coefficient n `choose` k. For
values of k > 50, this uses an approximation for performance
reasons. The approximation is accurate to 12 decimal places in the
worst case
Example:
7 `choose` 3 == 35:: a typeCtrl KGHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11
Modulemath-functions-0.3.4.4Haskell2010
Internal module with implementation of special functions.
Compute the binomial coefficient n `choose` k. For
values of k > 50, this uses an approximation for performance
reasons. The approximation is accurate to 12 decimal places in the
worst case
Example:
7 `choose` 3 == 35Calculate binomial coefficient using exact formula
Compute ψ(x), the first logarithmic derivative of the gamma function.
\psi(x) = \frac{d}{dx} \ln \left(\Gamma(x)\right) = \frac{\Gamma'(x)}{\Gamma(x)}
Uses Algorithm AS 103 by Bernardo, based on Minka's C implementation.
Error function.
\operatorname{erf}(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} \exp(-t^2) dt
Function limits are:
\begin{aligned}
&\operatorname{erf}(-\infty) &=& -1 \\
&\operatorname{erf}(0) &=& \phantom{-}\,0 \\
&\operatorname{erf}(+\infty) &=& \phantom{-}\,1 \\
\end{aligned}
Complementary error function.
\operatorname{erfc}(x) = 1 - \operatorname{erf}(x)
Function limits are:
\begin{aligned}
&\operatorname{erf}(-\infty) &=&\, 2 \\
&\operatorname{erf}(0) &=&\, 1 \\
&\operatorname{erf}(+\infty) &=&\, 0 \\
\end{aligned}
Compute the factorial function n!. Returns +∞ if the input is above 170 (above which the result cannot be represented by a 64-bit Double).
Regularized incomplete beta function.
I(x;a,b) = \frac{1}{B(a,b)} \int_0^x t^{a-1}(1-t)^{b-1}\,dt
Uses algorithm AS63 by Majumder and Bhattachrjee and quadrature approximation for large p and q.
incompleteBeta_ Regularized incomplete beta function. Same as incompleteBeta but also takes logarithm of beta function as parameter.
Compute the normalized lower incomplete gamma function γ(z,x). Normalization means that γ(z,∞)=1
\gamma(z,x) = \frac{1}{\Gamma(z)}\int_0^{x}t^{z-1}e^{-t}\,dt
Uses Algorithm AS 239 by Shea.
Inverse of erf.
Inverse of erfc.
Compute inverse of regularized incomplete beta function. Uses initial approximation from AS109, AS64 and Halley method to solve equation.
Inverse incomplete gamma function. It's approximately inverse of incompleteGamma for the same z. So following equality approximately holds:
invIncompleteGamma z . incompleteGamma z ≈ idCompute log(1+x)-x:
O(log n) Compute the logarithm in base 2 of the given value.
Compute the natural logarithm of the beta function.
B(a,b) = \int_0^1 t^{a-1}(1-t)^{b-1}\,dt = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}
Compute logarithm of the binomial coefficient.
Quickly compute the natural logarithm of n choose k, with
no checking.
Less numerically stable:
exp $ lg (n+1) - lg (k+1) - lg (n-k+1)
where lg = logGamma . fromIntegralCompute the natural logarithm of the factorial function. Gives 16 decimal digits of precision.
Compute the logarithm of the gamma function, Γ(x).
\Gamma(x) = \int_0^{\infty}t^{x-1}e^{-t}\,dt = (x - 1)!
This implementation uses Lanczos approximation. It gives 14 or more significant decimal digits, 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).
Compute the log gamma correction factor for Stirling
approximation for x ≥ 10. This correction factor is
suitable for an alternate (but less numerically accurate)
definition of logGamma:
\log\Gamma(x) = \frac{1}{2}\log(2\pi) + (x-\frac{1}{2})\log x - x + \operatorname{logGammaCorrection}(x)
Deprecated. Use logGamma instead
Synonym for logGamma. Retained for compatibility
Compute sinc function sin(x)/x
Calculate the error term of the Stirling approximation. This is only defined for non-negative values.
\operatorname{stirlingError}(n) = \log(n!) - \log(\sqrt{2\pi n}\frac{n}{e}^n)