This is an old version, view current version.

## 6.6 Reductions

### 6.6.1 Log sum of exponents

real log_sum_exp(vector x)
The natural logarithm of the sum of the exponentials of the elements in x
Available since 2.0

real log_sum_exp(row_vector x)
The natural logarithm of the sum of the exponentials of the elements in x
Available since 2.0

real log_sum_exp(matrix x)
The natural logarithm of the sum of the exponentials of the elements in x
Available since 2.0

### 6.6.2 Minimum and maximum

real min(vector x)
The minimum value in x, or $$+\infty$$ if x is empty
Available since 2.0

real min(row_vector x)
The minimum value in x, or $$+\infty$$ if x is empty
Available since 2.0

real min(matrix x)
The minimum value in x, or $$+\infty$$ if x is empty
Available since 2.0

real max(vector x)
The maximum value in x, or $$-\infty$$ if x is empty
Available since 2.0

real max(row_vector x)
The maximum value in x, or $$-\infty$$ if x is empty
Available since 2.0

real max(matrix x)
The maximum value in x, or $$-\infty$$ if x is empty
Available since 2.0

### 6.6.3 Sums and products

real sum(vector x)
The sum of the values in x, or 0 if x is empty
Available since 2.0

real sum(row_vector x)
The sum of the values in x, or 0 if x is empty
Available since 2.0

real sum(matrix x)
The sum of the values in x, or 0 if x is empty
Available since 2.0

real prod(vector x)
The product of the values in x, or 1 if x is empty
Available since 2.0

real prod(row_vector x)
The product of the values in x, or 1 if x is empty
Available since 2.0

real prod(matrix x)
The product of the values in x, or 1 if x is empty
Available since 2.0

### 6.6.4 Sample moments

Full definitions are provided for sample moments in section array reductions.

real mean(vector x)
The sample mean of the values in x; see section array reductions for details.
Available since 2.0

real mean(row_vector x)
The sample mean of the values in x; see section array reductions for details.
Available since 2.0

real mean(matrix x)
The sample mean of the values in x; see section array reductions for details.
Available since 2.0

real variance(vector x)
The sample variance of the values in x; see section array reductions for details.
Available since 2.0

real variance(row_vector x)
The sample variance of the values in x; see section array reductions for details.
Available since 2.0

real variance(matrix x)
The sample variance of the values in x; see section array reductions for details.
Available since 2.0

real sd(vector x)
The sample standard deviation of the values in x; see section array reductions for details.
Available since 2.0

real sd(row_vector x)
The sample standard deviation of the values in x; see section array reductions for details.
Available since 2.0

real sd(matrix x)
The sample standard deviation of the values in x; see section array reductions for details.
Available since 2.0

### 6.6.5 Quantile

Produces sample quantiles corresponding to the given probabilities. The smallest observation corresponds to a probability of 0 and the largest to a probability of 1.

Implements algorithm 7 from Hyndman, R. J. and Fan, Y., Sample quantiles in Statistical Packages (R’s default quantile function).

real quantile(data vector x, data real p)
The p-th quantile of x
Available since 2.27

array[] real quantile(data vector x, data array[] real p)
An array containing the quantiles of x given by the array of probabilities p
Available since 2.27

real quantile(data row_vector x, data real p)
The p-th quantile of x
Available since 2.27

array[] real quantile(data row_vector x, data array[] real p)
An array containing the quantiles of x given by the array of probabilities p
Available since 2.27