3.14 Composed functions
The functions in this section are equivalent in theory to combinations of other functions. In practice, they are implemented to be more efficient and more numerically stable than defining them directly using more basic Stan functions.
R
expm1
(T x)
natural exponential of x minus 1
Available since 2.0, vectorized in 2.13
real
fma
(real x, real y, real z)
Return z plus the result of x multiplied by y. \[ \text{fma}(x,y,z) =
(x \times y) + z \]
Available since 2.0
real
multiply_log
(real x, real y)
Warning: This function is deprecated and should be replaced with
lmultiply
. Return the product of x and the natural logarithm of y.
\[ \mathrm{multiply\_log}(x,y) = \begin{cases} 0 & \text{if } x = y =
0 \\ x \log y & \text{if } x, y \neq 0 \\ \text{NaN} &
\text{otherwise} \end{cases} \]
Available since 2.0, deprecated since 2.10, scheduled for removal in 2.32
R
multiply_log
(T1 x, T2 y)
Vectorized implementation of the multiply_log
function
Available since 2.25
real
ldexp
(real x, int y)
Return the product of x and two raised to the y power. \[
\text{ldexp}(x,y) = x 2^y \]
Available since 2.25
R
ldexp
(T1 x, T2 y)
Vectorized implementation of the ldexp
function
Available since 2.25
real
lmultiply
(real x, real y)
Return the product of x and the natural logarithm of y. \[
\text{lmultiply}(x,y) = \begin{cases} 0 & \text{if } x = y = 0 \\ x
\log y & \text{if } x, y \neq 0 \\ \text{NaN} & \text{otherwise}
\end{cases} \]
Available since 2.10
R
lmultiply
(T1 x, T2 y)
Vectorized implementation of the lmultiply
function
Available since 2.25
R
log1p
(T x)
natural logarithm of 1 plus x
Available since 2.0, vectorized in 2.13
R
log1m
(T x)
natural logarithm of 1 minus x
Available since 2.0, vectorized in 2.13
R
log1p_exp
(T x)
natural logarithm of one plus the natural exponentiation of x
Available since 2.0, vectorized in 2.13
R
log1m_exp
(T x)
logarithm of one minus the natural exponentiation of x
Available since 2.0, vectorized in 2.13
real
log_diff_exp
(real x, real y)
Return the natural logarithm of the difference of the natural
exponentiation of x and the natural exponentiation of y. \[
\mathrm{log\_diff\_exp}(x,y) = \begin{cases} \log(\exp(x)-\exp(y)) &
\text{if } x > y \\[6pt] \textrm{NaN} & \text{otherwise} \end{cases}
\]
Available since 2.0
R
log_diff_exp
(T1 x, T2 y)
Vectorized implementation of the log_diff_exp
function
Available since 2.25
real
log_mix
(real theta, real lp1, real lp2)
Return the log mixture of the log densities lp1 and lp2 with mixing
proportion theta, defined by \[\begin{eqnarray*}
\mathrm{log\_mix}(\theta, \lambda_1, \lambda_2) & = & \log \!\left(
\theta \exp(\lambda_1) + \left( 1 - \theta \right) \exp(\lambda_2)
\right) \\[3pt] & = & \mathrm{log\_sum\_exp}\!\left(\log(\theta) +
\lambda_1, \ \log(1 - \theta) + \lambda_2\right). \end{eqnarray*}\]
Available since 2.6
real
log_sum_exp
(real x, real y)
Return the natural logarithm of the sum of the natural exponentiation
of x and the natural exponentiation of y. \[
\mathrm{log\_sum\_exp}(x,y) = \log(\exp(x)+\exp(y)) \]
Available since 2.0
R
log_inv_logit
(T x)
natural logarithm of the inverse logit function of x
Available since 2.0, vectorized in 2.13
R
log_inv_logit_diff
(T1 x, T2 y)
natural logarithm of the difference of the inverse logit function of x and the inverse logit function of y
Available since 2.25
R
log1m_inv_logit
(T x)
natural logarithm of 1 minus the inverse logit function of x
Available since 2.0, vectorized in 2.13