Error Function (:math:`\text{erf}`)
The error function \text{erf}(x) is a non-elementary function that occurs in probability, statistics, and partial differential equations. It represents the integral of the Gaussian (Normal) distribution.
- Definition: \text{erf}(x) = \cfrac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt
- Asymptotes: The function approaches 1 as x \to \infty and
-1 as x \to -\infty. * Physics: It is the primary solution for heat diffusion problems in infinite or semi-infinite media where an initial temperature step exists.
Example 1C#

Gamma Function :math:`\Gamma(z)`
The Gamma function generalizes the factorial to real and complex numbers. For any positive integer n, \Gamma(n) = (n-1)!.
- Functional Equation: \Gamma(z+1) = z\Gamma(z).
- LnGamma: Because \Gamma(z) grows extremely fast, the natural logarithm of Gamma (\text{Log-Gamma}) is used in computation to prevent floating-point overflow.
Example 2C#

Regularized Incomplete Gamma (P and Q)
These are the normalized versions of the incomplete Gamma integral, ensuring the output stays within the range [0, 1].
- Lower Regularized (P):
- Upper Regularized (Q):
- Relationship:
These are the CDF and Survival functions of the Gamma distribution.
Example 3C#

LnGamma :math:`\text{LnGamma}`
Definition and Purpose
The :math:\text{LnGamma} function, denoted as \ln\Gamma(z), is the natural logarithm of the Gamma function. While it might seem redundant to have a separate function for the log of an existing function, it is essential for numerical computing.
- The Overflow Problem: The Gamma function \Gamma(z) grows at a "factorial" rate. For example, \Gamma(172) is approximately 1.24 \times 10^{307}, which is the limit of double-precision floating-point numbers. Any value larger than 171 will result in an Inf (overflow) error.
- The Solution: By working in "log-space," we can handle calculations involving massive factorials without crashing the program.
Mathematical Properties
- Stirling's Approximation: For large z, \text{LnGamma} is often approximated as:
- Derivatives: The first derivative of \ln\Gamma(z) is called the Digamma function (\psi), and the second derivative is the Trigamma function. The general derivative of order n is the Polygamma function.
Application: Bayesian Statistics
In Bayesian inference and likelihood calculations, we often multiply many probabilities together, many of which involve Gamma functions (like in the Beta or Gamma distributions). Multiplying many tiny numbers leads to "underflow." Instead, we sum the \text{LnGamma} values to stay within a safe numerical range.
Example 4C#
Beta Function :math:`B(x, y)`
The Beta function, also known as the Euler integral of the first kind, is closely related to the Gamma function and binomial coefficients.
- Identity: B(x, y) = \cfrac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}
- Application: Used extensively in Bayesian inference as the conjugate prior for Bernoulli and Binomial distributions.
Example 5C#

Generalized Hypergeometric Function :math:`{}_pF_q`
This series provides a unified framework for almost all special functions. By varying the number and values of numerator (p) and denominator (q) parameters, one can derive Bessel, Legendre, and Laguerre functions.
- Pochhammer Symbol: The series uses rising factorials (a)_n.
- Gauss Hypergeometric: The most common form is {}_2F_1(a, b; c; z).
Example 6C#
