Commute: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 7: Line 7:
       1 -⍨ 1 2 3
       1 -⍨ 1 2 3
0 1 2
0 1 2
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}
Double:
Double:
Line 13: Line 13:
       +⍨1 2 3
       +⍨1 2 3
2 4 6
2 4 6
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[NARS2000]]}}


[[Commute]] can be used to emulate a monadic <source lang=apl inline>f g h</source> [[Fork]] when combined with [[Compose]] (note the following code is not workable APL, but a series of evaluations):
[[Commute]] can be used to emulate a monadic <source lang=apl inline>f g h</syntaxhighlight> [[Fork]] when combined with [[Compose]] (note the following code is not workable APL, but a series of evaluations):
<source lang=apl>
<source lang=apl>
g⍨∘f⍨∘h⍨ x   
g⍨∘f⍨∘h⍨ x   
Line 24: Line 24:
(h x) g⍨ (f x)  
(h x) g⍨ (f x)  
(f x) g (h x) ⍝ the last ⍨ is being used dyadically, i.e. Swap
(f x) g (h x) ⍝ the last ⍨ is being used dyadically, i.e. Swap
</source>
</syntaxhighlight>


== History ==
== History ==


The Commute operator was defined in [[Operators and Functions]] in 1978, and taken up by [[NARS]] as a result. [[Dyalog]], influenced by NARS, included the operator early on. While it didn't appear in [[SHARP APL]], it was included in [[J]] as "Reflex/Passive" (<source lang=j inline>~</source>).
The Commute operator was defined in [[Operators and Functions]] in 1978, and taken up by [[NARS]] as a result. [[Dyalog]], influenced by NARS, included the operator early on. While it didn't appear in [[SHARP APL]], it was included in [[J]] as "Reflex/Passive" (<source lang=j inline>~</syntaxhighlight>).


== External links ==
== External links ==

Revision as of 20:57, 10 September 2022

Commute () is a monadic operator that takes a dyadic function as operand and modifies how the argument(s) of its derived functions are used. If the derived function is used monadically, the argument is also used as left argument. This usage is also known as Self or, more informally, Selfie. If the derived function is used dyadically, the arguments are swapped. This usage is also known as Swap. The glyph is also used for Constant.

Examples

This decrements from the vector: <source lang=apl>

     1 -⍨ 1 2 3

0 1 2 </syntaxhighlight>

Double: <source lang=apl>

     +⍨1 2 3

2 4 6 </syntaxhighlight>

Commute can be used to emulate a monadic <source lang=apl inline>f g h</syntaxhighlight> Fork when combined with Compose (note the following code is not workable APL, but a series of evaluations): <source lang=apl> g⍨∘f⍨∘h⍨ x x g⍨∘f⍨∘h x ⍝ the last ⍨ is being used monadically, i.e. Selfie x g⍨∘f⍨ h x (h x) g⍨∘f x ⍝ the last ⍨ is being used dyadically, i.e. Swap (h x) g⍨ (f x) (f x) g (h x) ⍝ the last ⍨ is being used dyadically, i.e. Swap </syntaxhighlight>

History

The Commute operator was defined in Operators and Functions in 1978, and taken up by NARS as a result. Dyalog, influenced by NARS, included the operator early on. While it didn't appear in SHARP APL, it was included in J as "Reflex/Passive" (<source lang=j inline>~</syntaxhighlight>).

External links

Lessons

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
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 axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector