This is an old version, view current version.

## 3.13 Combinatorial Functions

real inc_beta(real alpha, real beta, real x)
Return the regularized incomplete beta function up to x applied to alpha and beta. See section appendix for a definition.

real lbeta(real alpha, real beta)
Return the natural logarithm of the beta function applied to alpha and beta. The beta function, $$\text{B}(\alpha,\beta)$$, computes the normalizing constant for the beta distribution, and is defined for $$\alpha > 0$$ and $$\beta > 0$$. $\text{lbeta}(\alpha,\beta) = \log \Gamma(a) + \log \Gamma(b) - \log \Gamma(a+b)$ See section appendix for definition of $$\text{B}(\alpha, \beta)$$.

R tgamma(T x)
gamma function applied to x. The gamma function is the generalization of the factorial function to continuous variables, defined so that $$\Gamma(n+1) = n!$$. See for a full definition of $$\Gamma(x)$$. The function is defined for positive numbers and non-integral negative numbers,

R lgamma(T x)
natural logarithm of the gamma function applied to x,

R digamma(T x)
digamma function applied to x. The digamma function is the derivative of the natural logarithm of the Gamma function. The function is defined for positive numbers and non-integral negative numbers

R trigamma(T x)
trigamma function applied to x. The trigamma function is the second derivative of the natural logarithm of the Gamma function

real lmgamma(int n, real x)
Return the natural logarithm of the multivariate gamma function $$\Gamma_n$$ with n dimensions applied to x. $\text{lmgamma}(n,x) = \begin{cases} \frac{n(n-1)}{4} \log \pi + \sum_{j=1}^n \log \Gamma\left(x + \frac{1 - j}{2}\right) & \text{if } x\not\in \{\dots,-3,-2,-1,0\}\\ \textrm{error} & \text{otherwise} \end{cases}$

real gamma_p(real a, real z)
Return the normalized lower incomplete gamma function of a and z defined for positive a and nonnegative z. $\mathrm{gamma\_p}(a,z) = \begin{cases} \frac{1}{\Gamma(a)}\int_0^zt^{a-1}e^{-t}dt & \text{if } a > 0, z \geq 0 \\ \textrm{error} & \text{otherwise} \end{cases}$

real gamma_q(real a, real z)
Return the normalized upper incomplete gamma function of a and z defined for positive a and nonnegative z. $\mathrm{gamma\_q}(a,z) = \begin{cases} \frac{1}{\Gamma(a)}\int_z^\infty t^{a-1}e^{-t}dt & \text{if } a > 0, z \geq 0 \\[6pt] \textrm{error} & \text{otherwise} \end{cases}$

real binomial_coefficient_log(real x, real y)
Warning: This function is deprecated and should be replaced with lchoose. Return the natural logarithm of the binomial coefficient of x and y. For non-negative integer inputs, the binomial coefficient function is written as $$\binom{x}{y}$$ and pronounced “x choose y.” This function generalizes to real numbers using the gamma function. For $$0 \leq y \leq x$$, $\mathrm{binomial\_coefficient\_log}(x,y) = \log\Gamma(x+1) - \log\Gamma(y+1) - \log\Gamma(x-y+1).$

int choose(int x, int y)
Return the binomial coefficient of x and y. For non-negative integer inputs, the binomial coefficient function is written as $$\binom{x}{y}$$ and pronounced “x choose y.” In its the antilog of the lchoose function but returns an integer rather than a real number with no non-zero decimal places. For $$0 \leq y \leq x$$, the binomial coefficient function can be defined via the factorial function $\text{choose}(x,y) = \frac{x!}{\left(y!\right)\left(x - y\right)!}.$

real bessel_first_kind(int v, real x)
Return the Bessel function of the first kind with order v applied to x. $\mathrm{bessel\_first\_kind}(v,x) = J_v(x),$ where $J_v(x)=\left(\frac{1}{2}x\right)^v \sum_{k=0}^\infty \frac{\left(-\frac{1}{4}x^2\right)^k}{k!\, \Gamma(v+k+1)}$

real bessel_second_kind(int v, real x)
Return the Bessel function of the second kind with order v applied to x defined for positive x and v. For $$x,v > 0$$, $\mathrm{bessel\_second\_kind}(v,x) = \begin{cases} Y_v(x) & \text{if } x > 0 \\ \textrm{error} & \text{otherwise} \end{cases}$ where $Y_v(x)=\frac{J_v(x)\cos(v\pi)-J_{-v}(x)}{\sin(v\pi)}$

real modified_bessel_first_kind(int v, real z)
Return the modified Bessel function of the first kind with order v applied to z defined for all z and v. $\mathrm{modified\_bessel\_first\_kind}(v,z) = I_v(z)$ where ${I_v}(z) = \left(\frac{1}{2}z\right)^v\sum_{k=0}^\infty \frac{\left(\frac{1}{4}z^2\right)^k}{k!\Gamma(v+k+1)}$

real modified_bessel_second_kind(int v, real z)
Return the modified Bessel function of the second kind with order v applied to z defined for positive z and v. $\mathrm{modified\_bessel\_second\_kind}(v,z) = \begin{cases} K_v(z) & \text{if } z > 0 \\ \textrm{error} & \text{if } z \leq 0 \end{cases}$ where ${K_v}(z) = \frac{\pi}{2}\cdot\frac{I_{-v}(z) - I_{v}(z)}{\sin(v\pi)}$

real falling_factorial(real x, real n)
Return the falling factorial of x with power n defined for positive x and real n. $\mathrm{falling\_factorial}(x,n) = \begin{cases} (x)_n & \text{if } x > 0 \\ \textrm{error} & \text{if } x \leq 0 \end{cases}$ where $(x)_n=\frac{\Gamma(x+1)}{\Gamma(x-n+1)}$

real lchoose(real x, real y)
Return the natural logarithm of the generalized binomial coefficient of x and y. For non-negative integer inputs, the binomial coefficient function is written as $$\binom{x}{y}$$ and pronounced “x choose y.” This function generalizes to real numbers using the gamma function. For $$0 \leq y \leq x$$, $\mathrm{binomial\_coefficient\_log}(x,y) = \log\Gamma(x+1) - \log\Gamma(y+1) - \log\Gamma(x-y+1).$

real log_falling_factorial(real x, real n)
Return the log of the falling factorial of x with power n defined for positive x and real n. $\mathrm{log\_falling\_factorial}(x,n) = \begin{cases} \log (x)_n & \text{if } x > 0 \\ \textrm{error} & \text{if } x \leq 0 \end{cases}$

real rising_factorial(real x, int n)
Return the rising factorial of x with power n defined for positive x and integer n. $\mathrm{rising\_factorial}(x,n) = \begin{cases} x^{(n)} & \text{if } x > 0 \\ \textrm{error} & \text{if } x \leq 0 \end{cases}$ where $x^{(n)}=\frac{\Gamma(x+n)}{\Gamma(x)}$

real log_rising_factorial(real x, real n)
Return the log of the rising factorial of x with power n defined for positive x and real n. $\mathrm{log\_rising\_factorial}(x,n) = \begin{cases} \log x^{(n)} & \text{if } x > 0 \\ \textrm{error} & \text{if } x \leq 0 \end{cases}$