reduce - Maple Help

Home : Support : Online Help : reduce

reduce

reduce a container with a function

 Calling Sequence reduce(fcn, expr) reduce[evalhf](fcn, expr) reduce[scan](fcn, expr) reduce[inplace](fcn, expr) reduce[dimension=n](fcn, expr)

Parameters

 fcn - expression of type appliable; typically, a procedure or name expr - any expression

Description

 • The reduce function applies the reduction operation specified by fcn to the operands or elements of expr.
 • Some options can be specified in square brackets as an index to the reduce function. These options can be used by themselves or in combination with other options.
 • When reducing over an rtable (Array, Vector, or Matrix), if the evalhf option is passed, each evaluation of fcn is evaluated using evalhf.
 • If the scan option is passed, the reduction is performed cumulatively on the elements of expr, producing a result with the same dimensions as expr.
 When expr is an rtable, the inplace option can be used in conjunction with the scan option to compute the result in-place in expr.
 • The dimension option (alternately axis) restricts the reduction along one dimension of an rtable, producing a result with one less dimension than expr.
 The inplace and evalhf options are currently ignored if the dimension option is used.

 • The reduce function is thread safe, provided that evaluating fcn is thread safe.

Examples

 > $\mathrm{reduce}\left(\mathrm{+},\left[1,2,3,4,5\right]\right)$
 ${15}$ (1)
 > $\mathrm{reduce}\left[\mathrm{scan}\right]\left(\mathrm{+},\left[1,2,3,4,5\right]\right)$
 $\left[{1}{,}{3}{,}{6}{,}{10}{,}{15}\right]$ (2)
 > $\mathrm{reduce}\left(\mathrm{+},⟨⟨1|2⟩,⟨3|4⟩⟩\right)$
 ${10}$ (3)
 > $\mathrm{reduce}\left[\mathrm{dimension}=1\right]\left(\mathrm{+},⟨⟨a|b⟩,⟨c|d⟩⟩\right)$
 $\left[\begin{array}{cc}{a}{+}{c}& {b}{+}{d}\end{array}\right]$ (4)
 > $\mathrm{reduce}\left[\mathrm{dimension}=2\right]\left(\mathrm{+},⟨⟨a|b⟩,⟨c|d⟩⟩\right)$
 $\left[\begin{array}{c}{a}{+}{b}\\ {c}{+}{d}\end{array}\right]$ (5)
 > $\mathrm{reduce}\left[\mathrm{dimension}=1,\mathrm{scan}\right]\left(\mathrm{+},⟨⟨a|b⟩,⟨c|d⟩⟩\right)$
 $\left[\begin{array}{cc}{a}& {b}\\ {a}{+}{c}& {b}{+}{d}\end{array}\right]$ (6)
 > $\mathrm{reduce}\left[\mathrm{dimension}=2,\mathrm{scan}\right]\left(\mathrm{+},⟨⟨a|b⟩,⟨c|d⟩⟩\right)$
 $\left[\begin{array}{cc}{a}& {a}{+}{b}\\ {c}& {c}{+}{d}\end{array}\right]$ (7)

Compatibility

 • The reduce command was introduced in Maple 2021.
 • For more information on Maple 2021 changes, see Updates in Maple 2021.