Difference between revisions of "Reduce"

From APL Wiki
Jump to navigation Jump to search
(Created page with "{{Built-ins|Reduce|/|⌿}}, also called '''Reduction''' or '''Insert''', is a primitive monadic operator which takes a dyadic function operand...")
(No difference)

Revision as of 02:38, 20 July 2020


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 foldr1, in other functional programming languages such as Haskell.


When applied to a vector argument, f/x evaluates to the expression a f b f c f d … where a, b, c, d, … are the elements of x. In general, Reduce reduces one chosen axis (either implied by using the last-axis form f/ or first-axis f, or explicitly by using function axis f/[x]) 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.

External links



APL built-ins [edit]
Primitive functions
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Case convertUnicode convert
Operators SearchReplace