This is an old version, view current version.

3.13 Combinatorial functions

real beta(real alpha, real beta)
Return 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\). See section appendix for definition of \(\text{B}(\alpha, \beta)\).
Available since 2.25

R beta(T1 x, T2 y)
Vectorized implementation of the beta function
Available since 2.25

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.
Available since 2.10

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)\).
Available since 2.0

R lbeta(T1 x, T2 y)
Vectorized implementation of the lbeta function
Available since 2.25

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,
Available since 2.0, vectorized in 2.13

R lgamma(T x)
natural logarithm of the gamma function applied to x,
Available since 2.0, vectorized in 2.15

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
Available since 2.0, vectorized in 2.13

R trigamma(T x)
trigamma function applied to x. The trigamma function is the second derivative of the natural logarithm of the Gamma function
Available since 2.0, vectorized in 2.13

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} \]
Available since 2.0

R lmgamma(T1 x, T2 y)
Vectorized implementation of the lmgamma function
Available since 2.25

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} \]
Available since 2.0

R gamma_p(T1 x, T2 y)
Vectorized implementation of the gamma_p function
Available since 2.25

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} \]
Available since 2.0

R gamma_q(T1 x, T2 y)
Vectorized implementation of the gamma_q function
Available since 2.25

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). \]
Available since 2.0, deprecated since 2.10

R binomial_coefficient_log(T1 x, T2 y)
Vectorized implementation of the binomial_coefficient_log function
Available since 2.25

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)!}. \]
Available since 2.14

R choose(T1 x, T2 y)
Vectorized implementation of the choose function
Available since 2.25

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)} \]
Available since 2.5

R bessel_first_kind(T1 x, T2 y)
Vectorized implementation of the bessel_first_kind function
Available since 2.25

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)} \]
Available since 2.5

R bessel_second_kind(T1 x, T2 y)
Vectorized implementation of the bessel_second_kind function
Available since 2.25

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 integer 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)} \]
Available since 2.1

R modified_bessel_first_kind(T1 x, T2 y)
Vectorized implementation of the modified_bessel_first_kind function
Available since 2.25

real log_modified_bessel_first_kind(real v, real z)
Return the log of the modified Bessel function of the first kind. v does not have to be an integer.
Available since 2.26

R log_modified_bessel_first_kind(T1 x, T2 y)
Vectorized implementation of the log_modified_bessel_first_kind function
Available since 2.26

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 integer 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)} \]
Available since 2.1

R modified_bessel_second_kind(T1 x, T2 y)
Vectorized implementation of the modified_bessel_second_kind function
Available since 2.25

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)} \]
Available since 2.0

R falling_factorial(T1 x, T2 y)
Vectorized implementation of the falling_factorial function
Available since 2.25

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). \]
Available since 2.10

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} \]
Available since 2.0

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)} \]
Available since 2.20

R rising_factorial(T1 x, T2 y)
Vectorized implementation of the rising_factorial function
Available since 2.25

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} \]
Available since 2.0

R log_rising_factorial(T1 x, T2 y)
Vectorized implementation of the log_rising_factorial function
Available since 2.25