# $$\Gamma$$¶

You can use the $$\Gamma$$ function to calculate both the Gamma function and the upper incomplete gamma function. The calculated values depends on the number of supplied parameters.

You can use the \gammafn backslash command to insert this function.

The following variants of this function are available:

• $$\text{complex } \Gamma \left ( \text{<value>} \right )$$

• $$\text{complex } \Gamma \left ( \text{<s>}, \text{<z>} \right )$$

Where $$\text{<value>}$$, $$\text{<s>}$$, and $$\text{<z>}$$ can be any basic type. The incomplete gamma function is defined over the range $$\Re \left (s \right ) \geq 0$$ and $$\Re \left ( z \right ) \geq 0$$ and will return NaN or generate an error for which the values are not defined.

Note that run-time type conversion allows the result of this function to be assigned to any basic type provided the returned value is compatible with that type.

The $$\Gamma$$ function is defined by the integral:

$\Gamma \left ( v \right ) = \int_{0}^{\infty} x ^ { v - 1 } e ^ {-x} d x$

The upper incomplete gamma function is defined by the integral:

$\Gamma \left ( s, z \right ) = \int_{z}^{\infty} t ^ { s - 1 } e ^ {-t} dt$

Aion also included optimized versions of the gamma function for real and for complex parameters. Aion will also automatically detect usage of the gamma function or upper incomplete gamma function with $$\ln$$ or $$\log$$ functions, as shown below, and will optimize the underlying implementation to compute log-gamma or log-incomplete gamma directly.

$x = \log _ b \Gamma \left (x \right )$
$x = \ln \Gamma \left (x \right )$
$x = \log _ b \Gamma \left ( s, z \right )$
$x = \ln \Gamma \left ( s, z \right )$

For clarity, Aion also makes the $$\text{lnGamma}$$ function available.

The gamma function is calculated using Lanczos approximation [4]. The upper incomplete gamma function is calculated using continued fractions using the algorithm described in [7].

The examples below show how you can use the $$\Gamma$$ function:

$a = \Gamma \; 5$
$\text{a = 24}$
$e = \frac{1}{\Gamma \left ( 1, 1 \right )}$
$e = 2.71828$