>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  Dictionary

20. Rank

The shape ($), tally (#), and rank (#@$), of a noun are illustrated by the noun report , which may be construed as a report covering two years of four quarters of three months each:
   ]report=: i. 2 4 3
 0  1  2
 3  4  5
 6  7  8
 9 10 11

12 13 14
15 16 17
18 19 20
21 22 23

   ($ ; # ; #@$) report        Shape, Number of items, Rank
+-----+-+-+
|2 4 3|2|3|
+-----+-+-+
The last k axes determine a k-cell of a noun; the 0-cells of report are the atoms (such as 4 and 14), the 1-cells are the three-element quarterly reports, and the two-cells (or major cells or items) are the two four-by-three yearly reports.

The rank conjunction " is used in the phrase f"k to apply a function f to each of the k-cells of its argument. For example:
   ,report
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

   ,"2 report
 0  1  2  3  4  5  6  7  8  9 10 11
12 13 14 15 16 17 18 19 20 21 22 23

   <@i. s=: 2 5 
+---------+ 
|0 1 2 3 4|
|5 6 7 8 9|
+---------+
   <@i."0 s
+---+---------+
|0 1|0 1 2 3 4|
+---+---------+
Both the left and right ranks of a dyad may be specified. Thus:
   10 11 12 (,"0 1 ; ,"1 1 ; ,"1) 0 1 2
+--------+--------------+--------------+
|10 0 1 2|10 11 12 0 1 2|10 11 12 0 1 2|
|11 0 1 2|              |              |
|12 0 1 2|              |              |
+--------+--------------+--------------+
The basic characteristics adverb b. is very useful in analyzing functions (or expressions that define them) with respect to their ranks. For example:
   (# b. 0) ; (+/\ b. 0) ; (+/\ % #) b. 0
+-----+-----+-----+
|_ 1 _|_ 0 _|_ _ _|
+-----+-----+-----+

Exercises

20.1   Observe the results of the following uses of the monads produced by the rank conjunction, and comment on them:
a=: i. 3 4 5
<"0 a
<"1 a
<"2 a
<"3 a
< a
<"_1 a
<"_2 a
mean=: +/ % #
mean a
mean"1 a
mean"2 a
Answer: <"k applies < to each cell of rank k , with <"(#$a) a being equivalent to <a . Moreover, a negative value of k specifies a complementary rank that is effectively |k less than the rank of the argument a .

20.2   Use the results of the following experiments to state the relation between the conjunctions @ (Atop) and @: (At), and compare your conclusions with the dictionary definition:
(g=: <"2) a=: i. 3 4 5
|. @: g a
|. @ g a
|: @: (<"1) a
|: @ (<"1) a
Answer: The rank of the function |. @: g is itself infinite and |. therefore applies to the entire list result of g a , consequently reversing it. On the other hand, the function f @ g inherits the rank of g , and |. therefore applies individually to the atoms produced by g , producing no effect.

20.3   Use the results of the following experiments to comment on the use of the rank conjunction in dyads:
b=: 'ABC'
c=: 3 5 $ 'abcdefghijklmno'
c
b,c
b ,"0 1 c
b ,"1 1 c
b ,"1 c



>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  Dictionary