| 12.1 |
These exercises are grouped by topic and organized
like the section, with programs that are first to be read
and then to be rewritten. However, a reader already familiar
with a given topic might begin by writing.
A. Properties of numbers
| pn=: >:@i. |
Positive numbers (e.g. pn 9) |
| rt=: pn |/ pn |
Remainder table |
| dt=: 0&=@rt |
Divisibility table |
| nd=: +/@dt |
Number of divisors |
| prt=: 2&=@nd |
Prime test |
| prsel=: prt # pn |
Prime select |
| N=: >:@pn |
Numbers greater than 1 |
| rtt=: ,@(N */ N) |
Ravelled times table |
| aprt=: -.@(N e. rtt) |
Alternative test and selection
(primes do not occur in the times table for N) |
| apsel=: aprt # N |
|
| pfac=: q: |
Prime factors |
| first=: p:@i. |
First primes |
B. Coordinate Geometry
Do experiments on the vector (or point) p=: 3 4
and the triangle represented by the
table tri=: 3 2$ 3 4 6 5 7 2
| L=: %:@:(+/)@:*:"1 |
Length of vector (See rank in the dictionary
or in Section 20 of the Introduction) |
| LR=:L"1 |
Length of rows in table |
| disp=: ] - 1&|. |
Displacement between rows |
| LS=: LR@disp |
Lengths of sides of figure |
| sp=: -:@(+/)@LS |
Semiperimeter (try sp tri) |
| H=: %:@(*/)@(sp,sp-LS) |
Heron's formula for area |
| det=: -/ . * |
Determinant (See dictionary) |
| SA=: det@(,.&0.5) |
Signed area. Try SA@|. |
| sa=:det@(],.%@!@<:@#) |
General signed volume; try on the tetrahedron |
| tet=:?4 3$9 |
as well as on the triangle tri . |
|