Reverse Compose

From APL Wiki
Revision as of 21:06, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search

Reverse Compose () is a primitive operator closely related to Beside (<syntaxhighlight lang=apl inline>∘</source>), which appears in Extended Dyalog APL and dzaima/APL. Called dyadically with function operands <syntaxhighlight lang=apl inline>f</source> and <syntaxhighlight lang=apl inline>g</source>, it uses <syntaxhighlight lang=apl inline>f</source> monadically to pre-processes the left argument before applying <syntaxhighlight lang=apl inline>g</source> between the pre-processed left argument and the given right argument. <syntaxhighlight lang=apl inline>X f⍛g Y</source> is thus equivalent to <syntaxhighlight lang=apl inline>(f X) g Y</source>. The operator can be defined as the dop <syntaxhighlight lang=apl inline>{(⍺⍺ ⍺) ⍵⍵ ⍵}</source>. This dyadic definition matches the hook function Before, represented as in BQN.

Unlike Before, the monadic case of Reverse Compose has differed across implementations. When introduced by Extended Dyalog APL, <syntaxhighlight lang=apl inline>f⍛g Y</source> evaluated to <syntaxhighlight lang=apl inline>g Y</source>, but Brudzewsky's later Dyalog APL Vision defines[1] it to be <syntaxhighlight lang=apl inline>Y f g Y</source>, matching Before. This later definition might also be written <syntaxhighlight lang=apl inline>f⍛g</source> <syntaxhighlight lang=apl inline>f⍛g⍨⍨</source> <syntaxhighlight lang=apl inline>g⍨∘f⍨</source>. In dzaima/APL the monadic case is simply an error.

Common usage

Its plain usage is to pre-process left arguments without needing one or more applications of Commute (<syntaxhighlight lang=apl inline>⍨</source>). For example, the square of the left argument minus the right argument can be expressed as:

Try it online!<syntaxhighlight lang=apl>

     3×⍨⍛-2

7

</source>

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 (that is, multiply it with) the absolute value of the right argument: Try it online!<syntaxhighlight lang=apl>

     3 ¯1 4×⍛×∘|¯2 ¯7 1

2 ¯7 1

</source>

References

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