4,505
edits
No edit summary |
(Add Reverse Compose to main forms) |
||
Line 1: | Line 1: | ||
'''Function composition''' refers to the "gluing" together of two or more [[function]]s using a [[dyadic operator]] or a [[train]] such that the functions are applied to the [[argument]](s) as normal, but in a particular pattern specific to the used [[operator]]. The term [[wikipedia:function composition|function composition]] comes from [[traditional mathematics]] where it is used for a function <math>h(x)=f(g(x))</math> when written as <math> h(x) = (f \circ g)(x)</math>. APL generalises this idea to [[dyadic function]]s, allowing various patterns of application in addition to the simple application of one [[monadic function]] to the result of another monadic function. | '''Function composition''' refers to the "gluing" together of two or more [[function]]s using a [[dyadic operator]] or a [[train]] such that the functions are applied to the [[argument]](s) as normal, but in a particular pattern specific to the used [[operator]]. The term [[wikipedia:function composition|function composition]] comes from [[traditional mathematics]] where it is used for a function <math>h(x)=f(g(x))</math> when written as <math> h(x) = (f \circ g)(x)</math>. APL generalises this idea to [[dyadic function]]s, allowing various patterns of application in addition to the simple application of one [[monadic function]] to the result of another monadic function. | ||
== Common compositions == | |||
[[Reverse Compose]] and [[Beside]] treat their arguments in an asymmetric way. Their patterns can be visualised as follows: | |||
{| class=wikitable | {| class=wikitable | ||
! | ! Reverse Compose !! Beside | ||
|- | |- | ||
|[[File: | |[[File:F⍛g.png|frameless|200px]]||[[File:F∘g.png|frameless|200px]] | ||
|} | |||
[[Atop (operator)|Atop]] and [[Over]] treat their arguments in a symmetric way. Their patterns can be visualised as follows: | |||
{| class=wikitable | |||
! Atop !! Over | |||
|- | |||
|[[File:F⍤g.png|frameless|200px]]||[[File:F⍥g.png|frameless|200px]] | |||
|} | |} | ||
Line 22: | Line 31: | ||
=== Summary of rules === | === Summary of rules === | ||
The above compositions can be summarised as follows: | |||
<source lang=apl inline> (f⍛g ) ⍵</source> {{←→}} <source lang=apl inline>( f ⍵) g ⍵ </source><br> | |||
<source lang=apl inline>⍺ (f⍛g ) ⍵</source> {{←→}} <source lang=apl inline>( f ⍺) g ⍵ </source><br> | |||
<source lang=apl inline> ( g∘h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | <source lang=apl inline> ( g∘h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | ||
<source lang=apl inline>⍺ ( g∘h) ⍵</source> {{←→}} <source lang=apl inline> ⍺ g ( h ⍵)</source><br> | <source lang=apl inline>⍺ ( g∘h) ⍵</source> {{←→}} <source lang=apl inline> ⍺ g ( h ⍵)</source><br> | ||
<source lang=apl inline> ( g⍤h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | <source lang=apl inline> ( g⍤h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | ||
<source lang=apl inline>⍺ ( g⍤h) ⍵</source> {{←→}} <source lang=apl inline> g (⍺ h ⍵)</source><br> | <source lang=apl inline>⍺ ( g⍤h) ⍵</source> {{←→}} <source lang=apl inline> g (⍺ h ⍵)</source><br> | ||
<source lang=apl inline> ( g⍥h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | <source lang=apl inline> ( g⍥h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | ||
<source lang=apl inline>⍺ ( g⍥h) ⍵</source> {{←→}} <source lang=apl inline>( h ⍺) g ( h ⍵)</source><br> | <source lang=apl inline>⍺ ( g⍥h) ⍵</source> {{←→}} <source lang=apl inline>( h ⍺) g ( h ⍵)</source><br> | ||
<source lang=apl inline> (g h) ⍵</source> {{←→}} <source lang=apl inline> g ( h ⍵)</source><br> | |||
<source lang=apl inline>⍺ (g h) ⍵</source> {{←→}} <source lang=apl inline> g (⍺ h ⍵)</source><br> | |||
<source lang=apl inline> (f g h) ⍵</source> {{←→}} <source lang=apl inline>( f ⍵) g ( h ⍵)</source><br> | <source lang=apl inline> (f g h) ⍵</source> {{←→}} <source lang=apl inline>( f ⍵) g ( h ⍵)</source><br> | ||
<source lang=apl inline>⍺ (f g h) ⍵</source> {{←→}} <source lang=apl inline>(⍺ f ⍵) g (⍺ h ⍵)</source><br> | <source lang=apl inline>⍺ (f g h) ⍵</source> {{←→}} <source lang=apl inline>(⍺ f ⍵) g (⍺ h ⍵)</source><br> | ||
<source lang=apl inline> (A∘g ) ⍵</source> {{←→}} <source lang=apl inline> A g ⍵ </source><br> | |||
<source lang=apl inline> ( g∘A) ⍵</source> {{←→}} <source lang=apl inline> ⍵ g A </source><br> | |||
<source lang=apl inline> (A g h) ⍵</source> {{←→}} <source lang=apl inline> A g ( h ⍵)</source><br> | <source lang=apl inline> (A g h) ⍵</source> {{←→}} <source lang=apl inline> A g ( h ⍵)</source><br> | ||
<source lang=apl inline>⍺ (A g h) ⍵</source> {{←→}} <source lang=apl inline> A g (⍺ h ⍵)</source><br> | <source lang=apl inline>⍺ (A g h) ⍵</source> {{←→}} <source lang=apl inline> A g (⍺ h ⍵)</source><br> | ||
== Additional compositions == | == Additional compositions == |