Special Functions

This set of functions enables Microsoft SQL Server to perform many essential engineering and statistical functions such as Beta, Gamma, as well as more generic math functions such as Factorial and Hypotenuse.

Function Parameters Description
Beta Double z
Double a
Computes the Euler Beta function evaluated at z,w.
BetaIncomplete Double a
Double b
Double x
Returns the lower incomplete (unregularized) beta function where x is the upper limit of the integral.
BetaLn Double z
Double w
Computes the logarithm of the Euler Beta function evaluated at z,w.
BetaRegularized Double a
Double b
Double x
Returns the regularized lower incomplete beta function where x is the upper limit of the integral.
Binomial Int i
Int k
Computes the binomial coefficient: n choose k. More Information.
BinomialLn Int i
Int k
Computes the natural logarithm of the binomial coefficient: ln(n choose k).
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.
DiGammaInv Double p

Computes the inverse Digamma function: this is the inverse of the logarithm of the gamma function. This function will only return solutions that are positive.

This implementation is based on the bisection method.

Erf Double x The error function (also called the Gauss error function) is a special function (non-elementary) of sigmoid shape which occurs in probability, statistics and partial differential equations. More Information.
Erfc Double x
Calculates the complementary error function.
ErfcInv Double z Calculates the complementary inverse error function evaluated at z. Note - significance is only confirmed to 9 significant figures.
ErfInv Double z Calculates the inverse error function evaluated at z.
ExponentialMinusOne Double power Numerically stable exponential minus one.
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 version FactorialLn 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.

FactorialLn Int x Computes the logarithmic factorial function x -> ln(x!) of an integer number > 0.
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).

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

GammaLn Double z Computes the logarithm of the Gamma function.
GammaLowerIncomplete Double a
Double x
Returns the lower incomplete gamma function gamma where x is the upper limit of the integral.
GammaLowerRegularized Double a
Double x
Returns the lower incomplete regularized gamma function where x is the upper limit of the integral.
GammaUpperIncomplete Double a
Double x
Returns the upper incomplete gamma function where x is the lower limit of the integral.
GammaUpperRegularized Double a
Double x
Returns the upper regularized gamma function where x is the lower limit of the integral.
GeneralHarmonic Int n
Int m
Compute the generalized harmonic number of order n of m.  n is the order parameter and m is the power parameter.
Harmonic Int t Computes the t 'th Harmonic number.
Hypotenuse Double a
Double b
Numerically stable hypotenuse of a right angle triangle, where a and b are two non-hypotenuse sides of a triangle.
Logistic Double p Computes the logistic function. More Information.
Logit Double p Computes the logit function is the inverse of the sigmoidal "logistic" function used in mathematics, especially in statistics. More Information.

 Purchase SQL Math