Function rank: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
m (Text replacement - "</code>" to "</source>")
(→‎History: Right date and citation for when SHARP introduced Rank)
 
(7 intermediate revisions by 4 users not shown)
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 [[Rank|ranks]] 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.
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 <syntaxhighlight lang=apl inline>f</syntaxhighlight> may be viewed using <syntaxhighlight lang=apl inline>f b. 0</syntaxhighlight> and another function <syntaxhighlight lang=apl inline>g</syntaxhighlight> may be given those ranks using <syntaxhighlight lang=apl inline>g"f</syntaxhighlight> (<syntaxhighlight lang=apl inline>"</syntaxhighlight> 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 ==


Function rank was first introduced without being given a name in [[SHARP APL]], as a feature of the compositions [[Over|with]] and [[Atop|over]]. New compositions such as <source lang=apl inline>f⍤g</source> were described as "close in the sense that the expression… is applied individually to each subarray argument of <source lang=apl inline>g</source>".<ref>K.E. Iverson. [https://www.jsoftware.com/papers/satn41.htm "Composition and Enclosure"]. SATN 41, 1981-06-20.</ref> The concept of function rank was formalized, and applied to most primitives, when the [[Rank operator]] was introduced to SHARP version 19.0 in 1987.<ref>Bernecky, Robert. [https://dl.acm.org/citation.cfm?id=55632 "An Introduction to Function Rank"]. APL88 Conference Proceedings. ''ACM SIGAPL Quote Quad'', 18(2), December 1987.</ref> In [[J]] every function, primitive or user-defined, has a function rank.
Function rank was first introduced without being given a name in [[SHARP APL]], as a feature of the compositions [[Over|with]] and [[Atop|over]]. New compositions such as <syntaxhighlight lang=apl inline>f⍤g</syntaxhighlight> were described as "close in the sense that the expression… is applied individually to each subarray argument of <syntaxhighlight lang=apl inline>g</syntaxhighlight>".<ref>K.E. Iverson. [https://www.jsoftware.com/papers/satn41.htm "Composition and Enclosure"]. SATN 41, 1981-06-20.</ref> The concept of function rank was formalized, and applied to most primitives, when the [[Rank operator]] was introduced in 1983.<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> In [[J]] every function, primitive or user-defined, has a function rank.


== Definition and properties ==
== Definition and properties ==
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 [[Monad|monadic]] case plus two for the arguments in the [[Dyad|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.
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 [[Primitive function|primitive functions]] are defined by the interpreter.
* 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 compositions]] 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 [[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.
== External links ==
[[J]] resources:
* [https://www.jsoftware.com/help/jforc/loopless_code_i_verbs_have_r.htm Loopless Code I: Verbs Have Rank] from ''J for C Programmers''
* [https://www.jsoftware.com/help/learning/07.htm#03 Intrinsic Ranks] from ''Learning J''
* [https://www.jsoftware.com/help/primer/verb_rank.htm Verb Rank] from the J Primer
* [https://code.jsoftware.com/wiki/Vocabulary/EZRank#The_rank_of_a_verb The rank of a verb] from "Rank in a hurry"


== References ==
== References ==


<references />
<references />
{{APL features}}[[Category:Leading axis theory]][[Category:Function characteristics]]

Latest revision as of 18:06, 29 January 2024

In SHARP APL, Rationalized APL, and J, function rank refers to a built-in property of a function indicating which argument ranks 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 f may be viewed using f b. 0 and another function g may be given those ranks using g"f (" is the Rank operator). Every language with function rank defines "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

Function rank was first introduced without being given a name in SHARP APL, as a feature of the compositions with and over. New compositions such as f⍤g were described as "close in the sense that the expression… is applied individually to each subarray argument of g".[1] The concept of function rank was formalized, and applied to most primitives, when the Rank operator was introduced in 1983.[2] In J every function, primitive or user-defined, has a function rank.

Definition and properties

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 monadic case plus two for the arguments in the dyadic case. These ranks may be 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:

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.

External links

J resources:

References

  1. K.E. Iverson. "Composition and Enclosure". SATN 41, 1981-06-20.
  2. "Language Extensions of May 1983". SATN-45, 1983-05-02.
APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR