<<     >>

APL Exercises 4
Rank Operator
 

⎕io←0 throughout.
 

4.0 Drills I

f⍤r ⊢⍵ applies f to the rank r cells of . A negative r is equivalent to r+⍴⍴⍵ .

For example, ifhas shape 2 3 4 ,
its rank 3 cells have shape 2 3 4 ;
its rank 2 cells have shape 3 4 ;
its rank 1 cells have shape 4 ;
its rank 0 cells have shape .

Predict the result of each expression before evaluating it.

,t←2 3 4⍴⍳24
,⍤3⊢t
,⍤2⊢t
,⍤1⊢t
⊂⍤3⊢t
⊂⍤2⊢t
⊂⍤1⊢t
⊂⍤¯1⊢t
⊂⍤¯2⊢t
↑ ,¨ ⊂⍤3⊢t
↑ ,¨ ⊂⍤2⊢t
↑ ,¨ ⊂⍤1⊢t
+⌿⍤3⊢t
+⌿⍤2⊢t
+⌿⍤1⊢t
+⍀⍤3⊢t
+⍀⍤2⊢t
+⍀⍤1⊢t
⊖⍤3⊢t
⊖⍤2⊢t
⊖⍤1⊢t

4.1 Drills II

⍺ f⍤(r,s) ⊢⍵ applies f to the rank r cells ofagainst the rank s cells of . If an argument has only one cell, that one cell is applied against all the other cells.

Predict the result of each expression before evaluating it. When an expression errors explain why it is so.

10 20 30{⍺⍵}⍤0 1 ⊢3 4⍴⍳12
10 20 30{⍺⍵}⍤1 1 ⊢3 4⍴⍳12
10 20 30{⍺⍵}⍤1   ⊢3 4⍴⍳12
10 20 30{⍺⍵}⍤1 0 ⊢3 4⍴⍳12
10 20 30{⍺⍵}⍤¯1  ⊢3 4⍴⍳12
10 20 30,⍤0 1 ⊢3 4⍴⍳12
10 20 30,⍤1 1 ⊢3 4⍴⍳12
10 20 30,⍤1   ⊢3 4⍴⍳12
10 20 30,⍤1 0 ⊢3 4⍴⍳12
10 20 30+⍤0 1 ⊢3 4⍴⍳12
10 20 30+⍤1 1 ⊢3 4⍴⍳12
10 20 30+⍤1   ⊢3 4⍴⍳12
10 20 30+⍤1 0 ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤0 1 ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤1 1 ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤1   ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤1 0 ⊢3 4⍴⍳12
10 20 30×⍤0 1 ⊢0 1 2 3
10 20 30∘.×0 1 2 3
10 20 30{⍺+⍵}⍤0 1 ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤1 1 ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤1   ⊢3 4⍴⍳12
10 20 30{⍺+⍵}⍤1 0 ⊢3 4⍴⍳12
hyp←{0.5*⍨(⍺*2)+⍵*2}
10 20 30 hyp¨⍤0 1 ⊢3 4⍴⍳12
10 20 30 hyp¨⍤1 1 ⊢3 4⍴⍳12
10 20 30 hyp¨⍤1   ⊢3 4⍴⍳12
10 20 30 hyp¨⍤1 0 ⊢3 4⍴⍳12