APL Exercises 5 ⎕io←0 throughout. Dyadic ⍳ is the most important APL primitive
and familiarization with it is recommended.
5.0 Drills I Predict the result of each expression before evaluating it.
If you get the idea that ⍵⍳⍵ (←→ ⍳⍨⍵)
is a good and useful computation, you would be right!
5.1 Drills II In general, ⍺⍳⍵ works on left arguments with rank ≥ 1 . The items to be sought are the major cells of ⍺ , the subarrays with rank (⍴⍴⍺)-1 along the first axis of ⍺ . For example, in the most common non-vector case, if ⍺ is a matrix then ⍺⍳⍵ will look for vectors that match a row of ⍺ . x←↑'Curry' 'Thompson' 'Durant' 'Green' 'Iguodala' 'Curry' x Curry Thompson Durant Green Iguodala Curry ⍴x 6 8 Predict the result of each expression before evaluating it.
5.2 Drills III Predict the result of each expression before evaluating it.
5.3 Nub (AKA Unique) The monadic function ∪⍵ produces the nub (unique items) of ⍵ , equivalent to {((⍳≢⍵)=⍵⍳⍵)⌿⍵} . Currently ∪ is defined only on scalars and vectors. Predict the result of each expression before evaluating it.
5.4 Symmetries of the Square The last two sets of drills are different manifestations of the group of symmetries of the square. Indexing by a permutation p is equivalent to multiplication by the boolean matrix B←p∘.=⍳≢p . p←13?13 p B←p∘.=⍳≢p B x←?13⍴100 x[p] ≡ B+.×x Conversely, multiplication by a square boolean matrix B with exactly one 1 in each row and column is equivalent to indexing by the permutation p←B⍳⍤1⊢1 . B←13 13⍴0 ⋄ B[(⍳≢B),¨(≢B)?≢B]←1 B +⌿B +/B p←B⍳⍤1⊢1 x←?13⍴100 (B+.×x) ≡ x[p] Since ⊖ ⌽ ⍉ each transform a matrix
(respectively, flip vertically, flip horizontally, flip diagonally),
they are obviously transformations of a square.
However, the above presents a case that there is an isomorphism
between boolean matrices (of a particular sort) and permutations,
so that ⌽ ⍋ ⍒ too are transformations of a square.
|