Rank (J programming language)
Rank is a generalization of looping as used in scalar (non-array-oriented) programming languages. It is also a generalization of mapcar in the language Lisp and map in modern functional programming languages, and a generalization of scalar extension, inner (matrix) product, and outer product in APL\360. The canonical implementation of rank may be the language J, but it is also available in Dyalog APL, the International Organization for Standardization (ISO) technical standard on Extended APL, and NARS2000. Rank has several different meanings. In general, the concept of rank is used to treat an orthogonal array in terms of its subarrays. For example, a two-dimensional array may be dealt with... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
Rank is a generalization of looping as used in scalar (non-array-oriented) programming languages. It is also a generalization of mapcar in the language Lisp and map in modern functional programming languages, and a generalization of scalar extension, inner (matrix) product, and outer product in APL\360. The canonical implementation of rank may be the language J, but it is also available in Dyalog APL, the International Organization for Standardization (ISO) technical standard on Extended APL, and NARS2000. Rank has several different meanings. In general, the concept of rank is used to treat an orthogonal array in terms of its subarrays. For example, a two-dimensional array may be dealt with at rank 2 as the entire matrix, or at rank 1 to work with its implicit one-dimensional columns or rows, or at rank 0 to work at the level of its individual atoms. Noun rank – The rank of a noun is a nonnegative integer. Verb rank – The rank of a verb is a list of three integers. The rank conjunction – The rank conjunction ( " ) is used to derive a verb with a specific rank. +/ 1 2 3 6 The result is 1 + 2 + 3 , as expected. An N-dimensional integer array can also be created with i. which takes a vector of integers as its arguments. The number of integers defines the dimension and the absolute value of each integer defines the length of the corresponding dimension. i. 3 0 1 2 i. 2 3 0 1 2 3 4 5 i. 2 3 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Now let's reduce a two-dimensional array by addition. +/ i. 2 3 3 5 7 The result is 0 1 2 + 3 4 5 , as expected. Reduction runs down each column, adding together all the numbers in that column. This application of +/ to a two-dimensional array corresponds to the C code fragment: for(j = 0; j Suppose we wanted to add up the items of each row, as in the C code fragment: for(i = 0; i To produce the result 3 12 . We can do this in J without looping simply by using rank. +/"1 i. 2 3 3 12 To illustrate further how rank works in J, we can see the original expression is rank 2. The operator is mapped at the highest rank to the array. +/"2 i. 2 3 3 5 7 It is common to refer to the lower-dimensional arrays by these names, though they are disputed sometimes. 10 + 4 5 6 14 15 16 Here, the verb + has a rank of 0 0 0, the left argument has a rank of 0, and the right argument has a rank of 1 (with a dimension of 3). Thus, the left argument has a rank 0 frame and the right argument has a rank 1 frame (with a dimension 3). The left argument's (empty) frame is a valid suffix for the right argument's frame, so this is a valid operation. The result has a rank of 1 and a dimension of 3. 1 2 3 +"1 1 i. 3 3 1 3 5 4 6 8 7 9 11 If we want instead to add each scalar on the left to each vector on the right, we would do it this way: 1 2 3 +"0 1 i. 3 3 1 2 3 5 6 7 9 10 11 If the right argument is only one number, it is taken as the rank for all three cases. If the right argument is a verb, its rank is used. For example, these all derive the same verb: +"0 0 0 +"0 0 +"0 +"+ If the left argument to the rank conjunction is a noun, a constant verb is created. The body of this verb ignores the values of any arguments and always produces a result which is that noun.
Cite this
"Rank (J programming language)". 1770569766. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1337308553 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy