Reduction Functions

A reduction function is a function that takes a sequence of values and calculates a single result value, the reduction.

reduction = Reduce(value[1], …, value[n])

In the border case n=0 the reduction function is applied to an empty sequence of values:

neutral = Reduce()

This defines a "neutral" element of the reduction.

A reduction function can be defined by repeatedly combining two values with a combine function. For example if we use the addition as the combine function we get the sum of the input values:

tmp[0] = 0

tmp[i] = tmp[i-1] + value[i]

reduction = tmp[n]

A reduction function can also be defined based on existing reduction functions.

Minimum

The Minimum reduction function returns the minimum of all input values:

combine(a, b) = min(a, b)

The Minimum is available for all numeric data types.

Maximum

The Maximum reduction function returns the maximum of all input values:

combine(a, b) = max(a, b)

The Maximum is available for all numeric data types.

Count

The reduction function returns the number of samples:

Count(values[1], …, values[n]) = n

Add

The Add reduction function returns the sum of all input values:

combine(a, b) = a + b

Average

The Average reduction function calculates the average over the input values. This is simply the sum of the samples divided by the number of the samples:

Average(values) = Add(values) / Count(values)

Integral

The Integral reduction function calculates the area under the signal curve from the time of the first sample to the time of the last sample selected. It assumes step interpolation, i.e. it is the sum over the rectangles extending to the right of each sample:

r_i = s_i * (t_i+1 - t_i)

Here s_i is the value and t_i is the time of the sample at index i. The rectangle of the last sample is not included in the sum as it extends past the end time of the range.