Function composition: Difference between revisions
Jump to navigation
Jump to search
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. 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. 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 == | == Common compositions == | ||
[[Reverse Compose]] and [[Beside]] treat their arguments in an asymmetric way. Their patterns can be visualised as follows: | [[Reverse Compose]] and [[Beside]] treat their arguments in an asymmetric way. They can be seen as using a [[monadic function]] to pre-process the left or right argument, respectively, before proceeding to apply a main function. Their patterns can be visualised as follows: | ||
{| class=wikitable | {| class=wikitable | ||
Line 9: | Line 9: | ||
|} | |} | ||
[[Atop (operator)|Atop]] and [[Over]] treat their arguments in a symmetric way. Their patterns can be visualised as follows: | [[Atop (operator)|Atop]] and [[Over]] treat their arguments in a symmetric way. They can be seen as using a monadic function to post-process the result or pre-process the argument(s) of a main function. Their patterns can be visualised as follows: | ||
{| class=wikitable | {| class=wikitable | ||
! Atop !! Over | ! Atop !! Over | ||
Line 16: | Line 16: | ||
|} | |} | ||
[[Tacit_programming#trains|Trains]] provide a way to apply a function to the result(s) of one (for 2-trains) or two (for 3-trains) other functions. These patterns are also called Atop and Fork, and can be visualised as follows: | |||
{| class=wikitable | {| class=wikitable | ||
! 2-train !! 3-train | ! 2-train !! 3-train | ||
Line 23: | Line 23: | ||
|} | |} | ||
The <source lang=apl inline>∘</source> | The operator represented by [[Jot]] (<source lang=apl inline>∘</source>, in this context called [[Bind]]) and the 3-train can also be used with constant arrays, then treating the arrays (<source lang=apl inline>A</source>) as constant functions, much as if they were used as operands to the [[Constant]] operator (<source lang=apl inline>A⍨</source>): | ||
{| class=wikitable | {| class=wikitable | ||
! Bind !! 3-train | ! Bind !! 3-train |