4,501
edits
m (Text replacement - "<source" to "<syntaxhighlight") |
|||
(One intermediate revision by the same user not shown) | |||
Line 23: | Line 23: | ||
|} | |} | ||
The operator represented by [[Jot]] (< | The operator represented by [[Jot]] (<syntaxhighlight lang=apl inline>∘</syntaxhighlight>, in this context called [[Bind]]) and the 3-train can also be used with constant arrays, then treating the arrays (<syntaxhighlight lang=apl inline>A</syntaxhighlight>) as constant functions, much as if they were used as operands to the [[Constant]] operator (<syntaxhighlight lang=apl inline>A⍨</syntaxhighlight>): | ||
{| class=wikitable | {| class=wikitable | ||
! Bind !! 3-train | ! Bind !! 3-train | ||
Line 33: | Line 33: | ||
The above compositions can be summarised as follows: | The above compositions can be summarised as follows: | ||
< | <syntaxhighlight lang=apl inline> (f⍛g ) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>( f ⍵) g ⍵ </syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ (f⍛g ) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>( f ⍺) g ⍵ </syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> ( g∘h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ ( g∘h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> ⍺ g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> ( g⍤h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ ( g⍤h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> g (⍺ h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> ( g⍥h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ ( g⍥h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>( h ⍺) g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> ( g h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ ( g h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> g (⍺ h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> (f g h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>( f ⍵) g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ (f g h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>(⍺ f ⍵) g (⍺ h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> (A∘g ) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> A g ⍵ </syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> ( g∘A) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> ⍵ g A </syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline> (A g h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> A g ( h ⍵)</syntaxhighlight><br> | ||
< | <syntaxhighlight lang=apl inline>⍺ (A g h) ⍵</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline> A g (⍺ h ⍵)</syntaxhighlight><br> | ||
== Additional compositions == | == Additional compositions == | ||
Additional compositions are possible, even without using an argument more than once or applying a function to its own result. However, most of these are rather trivial shuffled-around versions of the above three. For example, one could define an operator identical to Atop, only that it applies the right operand to the result of the left operand, that is < | Additional compositions are possible, even without using an argument more than once or applying a function to its own result. However, most of these are rather trivial shuffled-around versions of the above three. For example, one could define an operator identical to Atop, only that it applies the right operand to the result of the left operand, that is <syntaxhighlight lang=apl inline>{⍵⍵ ⍺ ⍺⍺ ⍵}</syntaxhighlight>. | ||
When Dyalog added Atop and Over, it was with the reasoning that these were the only compositions where the leftmost function acted as the "root" function in the evaluation tree, while the arguments were used each on their respective sides of the constituent functions: | When Dyalog added Atop and Over, it was with the reasoning that these were the only compositions where the leftmost function acted as the "root" function in the evaluation tree, while the arguments were used each on their respective sides of the constituent functions: | ||
Line 61: | Line 61: | ||
[[File:AllCompositions.png|427px]] | [[File:AllCompositions.png|427px]] | ||
Of note here is < | Of note here is <syntaxhighlight lang=apl inline>f⍨∘g⍨</syntaxhighlight> which is equivalent to — although with swapped operands — [[Reverse-compose]] <syntaxhighlight lang=apl inline>⍛</syntaxhighlight> (also called ''Before''), and the mirrored version of Beside <syntaxhighlight lang=apl inline>∘</syntaxhighlight> (also known as ''Compose'' and ''After''), because it is the only such variation that has been implemented, namely in [[dzaima/APL]] and [[Extended Dyalog APL]]. | ||
A compositional operator that isn't just a shuffled around version of the basic three, is one that applies one operand between the other operand's dyadic result and the result of that other operand's result when [[swap]]ped: < | A compositional operator that isn't just a shuffled around version of the basic three, is one that applies one operand between the other operand's dyadic result and the result of that other operand's result when [[swap]]ped: <syntaxhighlight lang=apl inline>{(⍵ ⍵⍵ ⍺) ⍺⍺ (⍺ ⍵⍵ ⍵)}</syntaxhighlight>. This operator can for example be used to implement [[wikipedia:three-way comparison|three-way comparison]]: | ||
[https://tio.run/##SyzI0U2pTMzJT///P1jhUdsEhWqNR71bFYAYQu3SBBFApKABIuDiWzVruZJzC8BadIMfdS7hetQ3FcQxUjBWMFEASRn//w8A Try it online!]< | [https://tio.run/##SyzI0U2pTMzJT///P1jhUdsEhWqNR71bFYAYQu3SBBFApKABIuDiWzVruZJzC8BadIMfdS7hetQ3FcQxUjBWMFEASRn//w8A Try it online!]<syntaxhighlight lang=apl> | ||
S ← {(⍵ ⍵⍵ ⍺) ⍺⍺ (⍺ ⍵⍵ ⍵)} | S ← {(⍵ ⍵⍵ ⍺) ⍺⍺ (⍺ ⍵⍵ ⍵)} | ||
cmp ← -S≤ | cmp ← -S≤ | ||
Line 73: | Line 73: | ||
4 cmp 3 | 4 cmp 3 | ||
1 | 1 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]], [[NARS2000]], [[ngn/apl]]}} | ||
== External links == | == External links == |