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

12. Reading and Writing

Translating to and from a known language provides useful beginning exercises in learning a new one. The following provides examples.

Cover the right side of the page and make a serious attempt to translate the sentences on the left to English; that is, state succinctly in English what the verb defined by each sentence does. Use any available aids, including the dictionary and experimentation on the computer:

f1=: <: Decrement (monad); Less or equal
f2=: f1&9Less or equal 9
f3=: f2 *. >:&2Interval test 2 to 9 (inclusive)
f4=: f3 *. <. = ]In 2 to 9 and integer
f5=: f3 +. <. = ]In 2 to 9 or integer
g1=: %&1.8Divide by 1.8
g2=: g1^:_1Multiply by 1.8
g3=: -&32Subtract 32
g4=: g3^:_1Add 32
g5=: g1@g3Celsius from Fahrenheit
g6=: g5^:_1Fahrenheit from Celsius
h1=: >./Maximum over list (monad)
h2=: h1-<./ Spread. Try h2 b with the parabola: b=:(-&2 * -&3) -:i.12
h3=: h1@]-i.@[*h2@]%<:@[Grid. Try 10 h3 b
h4=: h3 <:/ ] Barchart. Try 10 h4 b
h5=: {&' *' @ h4Barchart. Try 10 h5 b

After entering the foregoing definitions, enter each verb name alone to display its definition, and learn to interpret the resulting displays. To see several forms of display, first enter 9!:3 (2 4 5) .

Cover the left side of the page, and translate the English definitions on the right back into J.


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 .

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