Namespaces

Types

Type SpecialFunctions

Namespace MathNet.Numerics

This partial implementation of the SpecialFunctions class contains all methods related to the error function.

Methods

Public static methods

double BetaLn(double a, double b)

Parameters
return double
double a
double b

double BetaRegularized(double a, double b, double x)

Parameters
return double
double a
double b
double x

double Binomial(int n, int k)

Computes the binomial coefficient: n choose k.
Parameters
return double The binomial coefficient: n choose k.
int n A nonnegative value n.
int k A nonnegative value h.

double BinomialLn(int n, int k)

Computes the natural logarithm of the binomial coefficient: ln(n choose k).
Parameters
return double The logarithmic binomial coefficient: ln(n choose k).
int n A nonnegative value n.
int k A nonnegative value h.

double DiGamma(double x)

Computes the Digamma function which is mathematically defined as the derivative of the logarithm of the gamma function. This implementation is based on Jose Bernardo Algorithm AS 103: Psi ( Digamma ) Function, Applied Statistics, Volume 25, Number 3, 1976, pages 315-317. Using the modifications as in Tom Minka's lightspeed toolbox.
Parameters
return double The value of the DiGamma function at x.
double x The argument of the digamma function.

double Erf(double x)

Calculates the error function.
Parameters
return double the error function evaluated at given value.
double x The value to evaluate.

double Erfc(double x)

Calculates the complementary error function.
Parameters
return double the complementary error function evaluated at given value.
double x The value to evaluate.

double ErfcInv(double z)

Calculates the complementary inverse error function evaluated at z.
We have tested this implementation against the arbitrary precision mpmath library and found cases where we can only guarantee 9 significant figures correct.
Parameters
return double The complementary inverse error function evaluated at given value.
double z value to evaluate.

double ExponentialMinusOne(double power)

Numerically stable exponential minus one, i.e. x -> exp(x)-1
Parameters
return double Returns exp(power)-1.
double power A number specifying a power.

double Factorial(int x)

Computes the factorial function x -> x! of an integer number > 0. The function can represent all number up to 22! exactly, all numbers up to 170! using a double representation. All larger values will overflow.
If you need to multiply or divide various such factorials, consider using the logarithmic versionFactorialLn instead so you can add instead of multiply and subtract instead of divide, and then exponentiate the result using Exp. This will also circumvent the problem that factorials become very large even for small parameters.
Parameters
return double A value value! for value > 0
int x

double FactorialLn(int x)

Computes the logarithmic factorial function x -> ln(x!) of an integer number > 0.
Parameters
return double A value value! for value > 0
int x

double Gamma(double z)

Computes the Gamma function.

This implementation of the computation of the gamma and logarithm of the gamma function follows the derivation in "An Analysis Of The Lanczos Gamma Approximation", Glendon Ralph Pugh, 2004. We use the implementation listed on p. 116 which should achieve an accuracy of 16 floating point digits. Although 16 digit accuracy should be sufficient for double values, improving accuracy is possible (see p. 126 in Pugh).

Our unit tests suggest that the accuracy of the Gamma function is correct up to 13 floating point digits.

Parameters
return double The logarithm of the gamma function.
double z The argument of the gamma function.

double GammaLn(double z)

Computes the logarithm of the Gamma function.

This implementation of the computation of the gamma and logarithm of the gamma function follows the derivation in "An Analysis Of The Lanczos Gamma Approximation", Glendon Ralph Pugh, 2004. We use the implementation listed on p. 116 which achieves an accuracy of 16 floating point digits. Although 16 digit accuracy should be sufficient for double values, improving accuracy is possible (see p. 126 in Pugh).

Our unit tests suggest that the accuracy of the Gamma function is correct up to 14 floating point digits.

Parameters
return double The logarithm of the gamma function.
double z The argument of the gamma function.

double Hypotenuse(double a, double b)

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)
Parameters
return double Returns sqrt(a2 + b2) without underflow/overflow.
double a The length of side a of the triangle.
double b The length of side b of the triangle.

double IncompleteGamma(double x, double z, bool reg)

Parameters
return double
double x
double z
bool reg