Reduce

, also called Reduction or Insert, is a primitive monadic operator which takes a dyadic function operand, inserts it between the elements of the argument, and evaluates it into a single array in right-to-left order. This operation is known as Fold, or more specifically, in other functional programming languages such as Haskell.

Description
When applied to a vector argument,  evaluates to the expression   where   are the elements of. In general, Reduce reduces one chosen axis (either implied by using the last-axis form  or first-axis , or explicitly by using function axis  ) by evaluating each vector along the chosen axis into a scalar.

In nested array model, Reduce has a strong property that the reduced axis is removed from the shape of the argument, which forces it to enclose each non-simple result in the returned array.

In leading axis model, Reduce only has the first-axis form, and it reduces the major cells of the entire array, not the individual elements. It does not enclose the result either. Instead, reduction over an axis other than the first is performed via the Rank operator, which mixes the results into a flat array.

Examples
Reduce is mainly used for aggregation, such as sum (using Add) or product (using Times). If used with Subtract, it computes the alternating sum, since $$a-(b-(c-(d-\cdots))) = a-b+c-d+\cdots$$. Using with Divide gives similar effect, returning the alternating product $$a\div(b\div(c\div(d\div\cdots))) = a\div b\times c\div d\times\cdots$$.

Reduction by Minimum or Maximum gives the minimum or maximum over several numbers. Same goes for And, Or, GCD, LCM, and XOR (Not Equal on Booleans).

Although Reduce is  in nature, one can use it like , where a designated starting value is modified by the rest of the values in sequence. In this case, the start value (enclosed if not a simple scalar) is attached to the right end of the vector of "modifiers", and then the entire vector is reduced.

Reduction over an empty axis gives the identity element of the operand.

FinnAPL idiom library contains over 100 entries which use Reduce in some way.

Lessons

 * APL Cultivation

Documentation

 * Dyalog
 * APLX
 * J Dictionary, NuVoc
 * BQN