Skip to content

Scalar

Create

Action Code Details
NaN
not_a_number()
Ï€
pi()
e
e()
Square root of 2
sqrt2()
Positive infinity
positive_infinity()
Negative infinity
negative_infinity()
Float epsilon (smallest representable difference)
?

Create

Action Code Details
Declare unconstrainted integer variable
int x;
Declare constrained integer variable
int<lower=1, upper=10> n;
Declare unconstrained float variable
real x;
Declare unconstrained float with value
real x = 0.5;
Declare unconstrained float variable as NaN
real x = not_a_number();
Declare constrained float variable
real<lower=0, upper=1> prob;

Test

Action Code Details
Is integer equal
x == 5
Not recommended for float types
Approximately equal with proportional tolerance tol
?
Approximately equal with absolute tolerance tol
?
Is NaN
is_nan(x)
Is NaN
is_not_a_number(x)
Is finite
!is_inf(x) && !is_nan(x)
Is infinite
is_inf(x)
Is positive infinity
x > 0 && is_inf(x)
Is negative infinity
x < 0 && is_inf(x)

Derive

Action Code Details
Absolute value
fabs(x)
Threshold (step)
step(x)
0 if x < 0, else 1
Addition
x + y
Subtraction (difference)
x - y
Positive difference
fdim(x, y)
x - y for x >= y, else 0
Absolute difference
fabs(x - y)
Multiplication
x * y
Division
x / y
Reciprocal
inv(x)
1 / x
Multiplication followed by addition of z
fma(x, y, z)
x * y + z
Square (power of 2)
square(x)
x ^ 2
Inverse square (power of -2)
inv_square(x)
x ^ -2
Square root
sqrt(x)
Inverse square root
inv_sqrt(x)
1 / sqrt(x)
Cube root
cbrt(x)
pow(x, 1/3)
Raise to power p
x ^ p
Raise to power p
pow(x, p)
Natural logarithm
log(x)
Base-2 logarithm
log2(x)
Base-10 logarithm
log10(x)
Natural logarithm of reciprocal
-log(x)
log(1/x)
Natural logarithm of (1 - x)
log1m(x)
log(1 - x)
Natural logarithm of 1 - exp(x)
log1m_exp(x)
log(1 - e^x)
Natural logarithm of (1 + x)
log1p(x)
log(1 + x)
Natural logarithm of 1 + exp(x)
log1p_exp(x)
log(1 + e^x)
Multiplication with log
lmultiply(x , p)
p * log(x) for x > 0
Natural exponential
exp(x)
Natural exponential of x - 1
expm1(x)
(e^x) - 1
Min
fmin(x, y)
Max
fmax(x, y)
Modulus
fmod(x, y)
x - floor(x / y) * y
Floor
floor(x)
Ceil
ceil(x)
Round
round(x)
Output is real
Truncate to nearest integer
trunc(x)
Output is real
Log-sum of exponentials
log_sum_exp(x, y)
log(e^x + e^y)
Log-diff of exponentials
log_diff_exp(x, y)
log(e^x - e^y) for x > y
Proportional log-sum of exponentials (used for mixtures)
log_mix(theta, x, y)
log(theta * e^x + (1 - theta) * e^y)
Proportional log-sum of exponentials (used for mixtures)
log_sum_exp(theta + [x, y])
Proportional log-sum of exponentials (used for mixtures)
log_sum_exp(log(theta) + x, log1m(theta) + y)
Logit transform
logit(x)
Inverse logit transform
inv_logit(x)
Natural logarithm of inverse logit
log_inv_logit(x)
Natural logarithm of 1 minus inverse logit
log1m_inv_logit(x)
Binomial coefficient (ncr)
choose(m, k)