APL Exercises 0
Beginnings
⎕io←0 throughout.
0.0 Outer Product (Function Table)
0.0.1 Boolean Functions
Predict the result of each expression before evaluating it.
∘.^ ⍨ 0 1 |
∘.∨ ⍨ 0 1 |
∘.⌊ ⍨ 0 1 |
∘.⌈ ⍨ 0 1 |
∘.= ⍨ 0 1 |
∘.≠ ⍨ 0 1 |
∘.< ⍨ 0 1 |
∘.≤ ⍨ 0 1 |
∘.≥ ⍨ 0 1 |
∘.> ⍨ 0 1 |
∘.⍲ ⍨ 0 1 |
∘.⍱ ⍨ 0 1 |
|
∘.= ⍨ ⍳11 |
∘.≠ ⍨ ⍳11 |
∘.< ⍨ ⍳11 |
∘.≤ ⍨ ⍳11 |
∘.≥ ⍨ ⍳11 |
∘.> ⍨ ⍳11 |
| Which of the function tables are symmetric? (t≡⍉t) |
| What can you say about the functions whose tables are symmetric? |
| If f is a boolean function (with 0-1 arguments and results), ∘.f⍨0 1
is its truth table and the ravel of that is its intrinsic vector.
For f with valence n there are 2*2*n possible intrinsic vectors.
Find an APL function for each of the following intrinsic vectors:
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
|
0.0.2 Arithmetic Functions
Predict the result of each expression before evaluating it.
∘.+ ⍨ ⍳11 |
∘.- ⍨ ⍳11 |
∘.× ⍨ ⍳11 |
∘.÷ ⍨ ⍳11 |
∘.⌊ ⍨ ⍳11 |
∘.⌈ ⍨ ⍳11 |
∘.| ⍨ ⍳11 |
∘.∧ ⍨ ⍳11 |
∘.∨ ⍨ ⍳11 |
∘.! ⍨ ⍳11 |
∘.* ⍨ ⍳11 |
∘.⍟ ⍨ 1+⍳11 |
| Which of the function tables are symmetric? |
| Why is it ∘.⍟ ⍨ 1+⍳11 and not ∘.⍟ ⍨ ⍳11 ? |
| If t←x∘.f y , what is the shape of t ?
| | If x and y are vectors and t←x∘.f y ,
how is t[i;j] computed? |
0.1 Reduction
0.1.1 Boolean Functions
Predict the result of each expression before evaluating it.
odometer←{⍉⍵⊤⍳×/⍵}
b←odometer 5⍴2
∧/b |
∨/b |
⌊/b |
⌈/b |
=/b |
≠/b |
|
≤/b |
≥/b |
>/b |
⍲/b |
⍱/b |
0.1.2 Arithmetic Functions
Predict the result of each expression before evaluating it.
x←1+?7⍴20
+/x |
-/x |
×/x |
÷/x |
⌊/x |
⌈/x |
|/x |
∧/x |
∨/x |
!/x |
*/x |
⍟/x |
0.1.3 Model
| Write a d-operator Reduce
such that (f/v)≡f Reduce v for vector v .
|
0.2 Scan
0.2.1 Boolean Functions
Predict the result of each expression before evaluating it.
b←odometer 5⍴2
∧\b |
∨\b |
⌊\b |
⌈\b |
=\b |
≠\b |
<\b |
≤\b |
≥\b |
>\b |
⍲\b |
⍱\b |
| Describe in words what each
of the above scans does on a boolean vector b .
For example, ∧\b is “all 1s until the first 0; 0 thereafter”. |
0.2.2 Arithmetic Functions
Predict the result of each expression before evaluating it.
x←1+?7⍴20
+\x |
-\x |
×\x |
÷\x |
⌊\x |
⌈\x |
|\x |
∧\x |
∨\x |
!\x |
*\x |
⍟\x |
0.2.3 Model
| Write a d-operator Scan
such that (f\v)≡f Scan v for vector v . |
|