Function rank: Difference between revisions
Jump to navigation
Jump to search
no edit summary
Miraheze>Adám Brudzewsky m (Text replacement - "</code>" to "</source>") |
Miraheze>Marshall No edit summary |
||
Line 1: | Line 1: | ||
In [[SHARP APL]], [[Rationalized APL]], and [[J]], function rank refers to a built-in property of a function indicating which argument [[ | In [[SHARP APL]], [[Rationalized APL]], and [[J]], '''function rank''' refers to a built-in property of a function indicating which argument [[rank]]s it accepts. A function will be applied as though it were given that rank with the [[Rank operator]]. The function rank may also have other observable effects: in [[J]], the ranks of <source lang=apl inline>f</source> may be viewed using <source lang=apl inline>f b. 0</source> and another function <source lang=apl inline>g</source> may be given those ranks using <source lang=apl inline>g"f</source> (<source lang=apl inline>"</source> is the Rank operator). Every language with function rank defines [[Close composition|"close" composition operators]] which inherit the rank of their right operand—the [[derived function]] produced by such a composition has ranks derived from that function's ranks. | ||
== History == | == History == | ||
Line 9: | Line 9: | ||
A function with rank applies only to cells of the appropriate rank. In order to operate on those cells it will map over arguments of larger rank as though the [[Rank operator]] were applied to it. | A function with rank applies only to cells of the appropriate rank. In order to operate on those cells it will map over arguments of larger rank as though the [[Rank operator]] were applied to it. | ||
As the Rank operator accepts up to three specified ranks in its right argument, a function with a defined function rank has three ranks, one for the argument in the [[ | As the Rank operator accepts up to three specified ranks in its right argument, a function with a defined function rank has three ranks, one for the argument in the [[monadic]] case plus two for the arguments in the [[dyadic]] case. These ranks may be [[Infinity|infinite]], or larger than the [[maximum rank]] if there is one, in which case they have no effect on the function's application. | ||
A function's rank is obtained from its definition: | A function's rank is obtained from its definition: | ||
* Ranks of [[ | * Ranks of [[primitive function]]s are defined by the interpreter. | ||
* The ranks of a [[derived function]] are determined by its operands. For most operators they are infinite; for [[close | * The ranks of a [[derived function]] are determined by its operands. For most operators they are infinite; for [[close composition]]s they are obtained from the right argument, and for functions derived from the [[Rank operator]] they are obtained from the right operand. | ||
* The ranks of a [[user-defined function]] are infinite. | * The ranks of a [[user-defined function]] are infinite. | ||
It is not possible to modify the ranks of a function. Instead, apply the [[Rank operator]] to create a new function which has the given rank, but functions like the left operand on arrays of that rank. Notably, given a function is defined with a particular rank, it is impossible to make it work on arrays of a higher rank. Applying Rank with larger numbers will produce a function whose rank is higher, but the function's results will be no different: the inner function will still map over cells because it retains its rank. | It is not possible to modify the ranks of a function. Instead, apply the [[Rank operator]] to create a new function which has the given rank, but functions like the left operand on arrays of that rank. Notably, given a function is defined with a particular rank, it is impossible to make it work on arrays of a higher rank. Applying Rank with larger numbers will produce a function whose rank is higher, but the function's results will be no different: the inner function will still map over cells because it retains its rank. |