Reverse Compose

From APL Wiki
Revision as of 13:19, 5 May 2020 by Marshall (talk | contribs)
Jump to navigation Jump to search

Reverse Compose (), also known as Before, is a primitive operator closely related to Beside (), also known as After. Called dyadically with function operands f and g, it uses f monadically to pre-processes the left argument before applying g between the pre-processed left argument and the given right argument. X f⍛g Y is thus equivalent to (f X) g Y. The operator can be defined as the dop {(⍺⍺ ⍺) ⍵⍵ ⍵}.

Reverse compose was introduced in Extended Dyalog APL, and then adopted into dzaima/APL. Its dyadic case matches to I's Hook (h), which is a reflected form of a J Hook, while Backhook (H) matches the ordinary Hook or Compose: because I's evaluation order is right to left, it considers the "reversed" APL form to be primary.

Common usage

Its plain usage is to pre-process left arguments without needing one or more applications of Commute (). For example, the square of the left argument minus the right argument can be expressed as:

Try it online!

      3×⍨⍛-2
7

It can also be combined with Beside to create the split-compose construct. Here, we take the sign of the left argument and apply it to the absolute value of the right argument:

Try it online!

      3 ¯1 4×⍛×∘|¯2 ¯7 1
2 ¯7 1
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector