Split composition: Difference between revisions

Jump to navigation Jump to search
353 bytes added ,  13:51, 12 April 2022
Editing; use source blocks
mNo edit summary
(Editing; use source blocks)
Line 1: Line 1:
'''Split-compose''' is a point-free construct, used to pre-process it's argument(s) with the left, and right-most operand before applying the middle operand between the result.
'''Split-compose''' is a point-free construct, used to pre-process its argument(s) with the left and right-most operand before applying the middle operand between the result.


It's definition is specified as <source lang=apl inline>(F x) G (H y)</source>.
Given functions <source lang=apl inline>F</source>, <source lang=apl inline>G</source>, and <source lang=apl inline>H</source>, the split composition on arguments <source lang=apl inline>x</source> and <source lang=apl inline>y</source> is defined as <source lang=apl inline>(F x) G (H y)</source>.


In BQN, the construct can be formed using [[Before]] <code>()</code> and [[After]] <code>()</code>, two [[Function composition|compositional]]  [[operator]]s. In this example, we multiply the range of the left argument, with the absolute value of the right.
In [[BQN]], the construct can be formed using [[Before]] (<code>⊸</code>) and [[After]] (<code>⟜</code>), two [[Function composition|compositional]]  [[operator]]s. In this example, we multiply the range of the left argument, with the absolute value of the right.
    5 ↕⊸×⟜| 5‿¯8‿¯2‿¯5‿3
<source>
⟨ 0 8 4 15 12 ⟩
    5 ↕⊸×⟜| 5‿¯8‿¯2‿¯5‿3
⟨ 0 8 4 15 12 ⟩
</source>


[[Monadic]]ally, the right argument can be [[selfie|duplicated]] and split-compose will be applied asymmetrically, similar to [[hook]]
[[Monadic]]ally, the right argument can be [[selfie|duplicated]] and split-compose will be applied asymmetrically, similar to [[hook]]
    +´⊸÷⟜≠ ↕10  
<source>
⟨ 4.5 ⟩
    +´⊸÷⟜≠ ↕10  
# This is evaluated as (↕10) +´⊸÷⟜≢ ↕10
⟨ 4.5 ⟩
# This is evaluated as (↕10) +´⊸÷⟜≢ ↕10
</source>


Monadically, split-compose is precisely equivalent to a [[fork]].
Monadically, split-compose is precisely equivalent to a [[fork]].


    (+´÷≠) ↕10
<source>
4.5
    (+´÷≠) ↕10
4.5
</source>




Line 23: Line 29:
In [[Dyalog APL]] you may form the expression with [[Beside]] <code>(∘)</code> and [[Commute]] <code>(⍨)</code>
In [[Dyalog APL]] you may form the expression with [[Beside]] <code>(∘)</code> and [[Commute]] <code>(⍨)</code>


g∘h⍨∘f⍨
<source lang=apl>
g∘h⍨∘f⍨


g⍨∘f⍨∘h⍨⍨
g⍨∘f⍨∘h⍨⍨
</source>


For example:
For example:
      ÷⍨∘(+/)⍨∘≢⍨⍨ ⍳10
<source lang=apl>
4.5
    ÷⍨∘(+/)⍨∘≢⍨⍨ ⍳10
4.5
</source>


Whilst these expressions will return the same results (if the functions f,g, & h are pure) the evaluation order is not identical.
Whilst these expressions will return the same results (if the functions f, g, and h are pure) the evaluation order is not identical.


And (most commonly) as a fork:
And (most commonly) as a fork:


f⍤⊣ g h⍤⊢
<source lang=apl>
f⍤⊣ g h⍤⊢
</source>


== See also ==
== See also ==

Navigation menu