Exploring Math
Kenneth E. Iverson
Copyright © 1996-2002 Jsoftware Inc. All rights reserved.
Table Of Contents
Chapter 1
Exploration ...................................................................... 1
A. Introduction .................................................................................... 1
B. Ramble Or Research ....................................................................... 6
What Is Math.................................................................... 9
A. Relations ......................................................................................... 9
B. Proofs.............................................................................................. 13
C. Summary......................................................................................... 14
Function Tables .............................................................. 17
Grammar And Spelling ................................................... 23
A. Introduction .................................................................................... 23
B. The Use Of Grammar...................................................................... 24
C. Punctuation And Other Rules ......................................................... 25
D. Spelling........................................................................................... 27
Reports ............................................................................ 29
A. Introduction .................................................................................... 29
B. Transposition .................................................................................. 31
Terminology .................................................................... 33
Decimal and Other Number Systems ............................ 37
A. Introduction .................................................................................... 37
B. Addition .......................................................................................... 42
C. Multiplication.................................................................................. 44
D. Subtraction...................................................................................... 45
Recursion ........................................................................ 47
Proofs .............................................................................. 53
A. Introduction .................................................................................... 53
B. Inductive Proof ............................................................................... 56
Tools ................................................................................ 61
A. Introduction .................................................................................... 61
B. Editing............................................................................................. 62
C. Script Windows .............................................................................. 62
Coordinates and Visualization....................................... 63
A. Introduction .................................................................................... 63
C. Plotting Multiple Figures ................................................................ 67
D. Plotting Functions........................................................................... 68
Linear Functions ............................................................. 73
A. Distributivity................................................................................... 73
B. Linearity.......................................................................................... 74
C. Linear Vector Functions ................................................................. 75
D. Inner Product .................................................................................. 76
E. Why The Name “Linear”? .............................................................. 77
Representations of Functions ....................................... 81
A. Introduction .................................................................................... 81
Polynomials..................................................................... 85
A. Coefficients Representation............................................................ 85
B. Roots Representation ...................................................................... 86
C. Versatility........................................................................................ 87
D. Parity............................................................................................... 89
E. Linearity .......................................................................................... 90
F. Polynomial Approximations............................................................ 92
Arithmetic ........................................................................ 95
A. Introduction .................................................................................... 95
B. Insidious Inverses ........................................................................... 95
C. Rational Numbers ........................................................................... 96
D. Irrational Numbers.......................................................................... 97
E. Complex Numbers .......................................................................... 97
Complex Numbers .......................................................... 99
A. Introduction .................................................................................... 99
B. Addition .......................................................................................... 100
C. Multiplication.................................................................................. 101
D. Powers and Roots ........................................................................... 103
E. Division........................................................................................... 104
Calculus........................................................................... 107
A. Secant Slope ................................................................................... 107
B. Derivative........................................................................................ 108
C. Polynomials .................................................................................... 109
D. Differential Equations..................................................................... 110
E. The Exponential Family.................................................................. 112
Inverses and Equations.................................................. 115
A. Inverse Functions............................................................................ 115
B. Monotonic Functions ...................................................................... 116
C. Under .............................................................................................. 117
D. Equations ........................................................................................ 118
Readings.......................................................................... 121
A. Introduction .................................................................................... 121
B. Phrases ............................................................................................ 121
C. Sample Topics................................................................................. 121
D. Vocabulary and Definitions............................................................ 122
References ...................................................................... 123
Index ................................................................................ 125
1
Chapter
1
Exploration
Something lost behind the ranges
Lost and waiting for you. Go!
Kipling
A. Introduction
Exploring a city or wild park on foot is more fun, and often more instructive, than
studying it in books, lectures, or pictures. A map or other guide may be helpful,
but it is important to be able to experiment, choosing your own path, approaching
points of interest from various directions. This can give you a sense of the lay of
the land that is more useful, and more lasting, than any fixed tour of “important
points” laid out by someone else.
Matters other than landscapes may also be explored, effectively and enjoyably.
For example, to learn about clockwork, begin not with diagrams and discussions
of balance wheels, springs, and escapements, but rather with an actual old-style,
wind-up alarm clock. Explore it by first finding what can be done with it. Can
you: reset the time? make it run faster? stop it? or reset the hour hand
independently of the minute hand?
Having learned what it can do, explore the matter of how it does it, by removing
its cover, studying the works, and finally taking it apart and re-assembling it. You
may, of course, not be skillful enough to get it working again.
Exploration can also be applied to other devices that may be more interesting or
more easily available to you: toasters, typewriters, electrical toggle switches, or
door locks. But do not forget your own safety—danger lurks in electrical devices
as well as in wilderness parks. Finally, in choosing a device for exploration,
favour the older models: modern typewriters and digital clocks may be totally
inscrutable. At least one author (Ivan Illich) has claimed to see a sinister motive
in this, claiming that modern design is deliberately inscrutable in order to keep
ordinary people like us in ignorance.
But can exploration be applied to abstract, non-physical notions such as math?
Yes it can. With an ordinary hand-calculator you can explore the relation between
multiplication and addition by using it to multiply two by three, then to add two
plus two plus two, and then comparing the results. If the calculator has a button
for power, you can even explore that less-familiar notion by doing two to the
power three, and comparing the result with two times two times two.
2
Exploring Math
But the abilities of a calculator are limited, and for a general exploration of math
we will use a computer equipped with suitable software called J. It is available
from Website http://www.jsoftware.com . We will assume that you have J at hand
on a computer, and will simply show examples of exploring math with it:
3+2
5
3*2
6
3-2
1
These examples are in a uniformly-spaced font (Courier) that differs from the
Roman font used elsewhere. We will use this difference to append comments to
some of the examples. In typing the examples on your computer, enter only the
part in Courier (followed by pressing the Enter key), but do not enter anything
that appears in Roman. Thus:
3+2
5
three=:3
three+2
5
Addition
Assign the name three to 3
Use the assigned name in a sentence
b=:2
b*b
4
In experiments on a sequence of numbers, it will be easier to make the entries and
to compare the results if we treat them as a list. This may be illustrated as follows:
2*0
0
2*1
2
2*2
4
2*0,1,2,3,4,5
0 2 4 6 8 10
a=:0,1,2,3,4,5
2*a
0 2 4 6 8 10
a+a
0 2 4 6 8 10
Comparisons can be shown more clearly by using the equals function as follows:
(2*a)=(a+a)
1 1 1 1 1 1
a^2
0 1 4 9 16 25
a*a
0 1 4 9 16 25
(a^3)=(a*a*a)
1 1 1 1 1 1
Chapter 1 Exploration
3
The list a to the power 2 (that is, the square)
The cube equals a product of three factors
Lists of integers (whole numbers) are so useful that a special function is provided
for making them. Enter the following expressions, and comment on the results:
The first six non-negative integers (whole numbers)
Read aloud as a is (the list) i.6
The integers in (repeatable) random order
The even numbers (divisible by 2)
The odd numbers
i.6
0 1 2 3 4 5
a=:i.6
b=:?.~6
b
5 1 2 4 3 0
a+b
5 2 4 7 7 5
a*b
0 1 4 12 12 0
2*a
0 2 4 6 8 10
1+2*a
1 3 5 7 9 11
a=b
0 1 1 0 0 0
As shown by the last result, the lists a and b are not equal, but they are similar in
the sense that one can be obtained from the other by shuffling or permuting the
items. It is rather easy to see that a and b are similar, but for longer lists similarity
is not so easy to spot. For example, are the following lists similar?
p=:2 15 9 10 4 0 13 13 18 7 10 16 0 1 10 13 0 7 1 8
q=:7 4 7 13 0 10 1 1 2 13 13 15 0 10 9 18 10 8 0 16
A good general method for determining similarity is to first sort each list to
ascending order, and then compare the results:
sort=: /:~
sort p
0 0 0 1 1 2 4 7 7 8 9 10 10 10 13 13 13 15 16 18
sort q
0 0 0 1 1 2 4 7 7 8 9 10 10 10 13 13 13 15 16 18
4
Exploring Math
(sort p)=(sort q)
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(sort p)-:(sort q)
1
The last sentence above uses -: to match the two lists, giving 1 if they agree in
every item, and 0 otherwise. This makes a comparison possible without reading
all the items that result from an equals comparison.
Exercises are commonly used by a student or teacher to test a student’s
understanding, in order to decide what best to do next. We will also use them to
suggest further exploration. A few tips on carrying out such explorations:
Before pressing the enter key, think through what the result should be;
experiments will teach much more if this rule is always followed.
On the other hand, do not hesitate to try anything you choose; the result may be
unintelligible or it may be an error message, but no serious harm can occur.
Use lists in experiments. Their results often show interesting patterns.
Do not hesitate to try things totally unknown. For example:
%:a
0 1 1.41421 1.73205 2 2.23607
This result will probably convince you that you have discovered the symbol for
the square root, and you might experiment further as follows:
roots=:%:a
roots*roots
0 1 2 3 4 5
• However, do not spend too much time on results that may be, at the moment,
beyond your powers. It may be better to defer further exploration until you
have learned some further math (such as complex numbers). For example:
%:-a
0 0j1 0j1.41421 0j1.73205 0j2 0j2.23607
• Explore a complex sentence by experimenting with its parts. For example:
i:4
_4 _3 _2 _1 0 1 2 3 4
i: 3
_3 _2 _1 0 1 2 3
Function for symmetric lists
+:3
6
>: +:3
7
>:@+:3
of) g
7
The function f@g is f atop (applied to the result
Chapter 1 Exploration
5
i.@>:@+:3
0 1 2 3 4 5 6
]3
3
Identity function
Exercises
1. What are the commonly-used names for the functions (or verbs) denoted here
by + * -
[plus times minus or addition multiplication (or product) subtraction]
2. Enter plus=:+ to assign the name plus to the addition function, and then
experiment with the following expressions:
3 plus 4 * 2
11
zero=:0
one=:1
two=:2
three=:3
four=:4
times=:*
three plus four times two
3. As illustrated by the preceding exercise, much math could be expressed in
English words without forcing students to learn the “difficult” special notation
of math. Would you prefer to stick to English words?
4. Experiment with the following editing facilities for correcting errors:
• Correct a line being entered by using the cursor keys (marked with
arrows) to move the cursor to any point, and then type or erase (using the
delete or backspace keys). The cursor need not be returned to the end of
the line before entering the line.
• Revise any line by moving the cursor up to it and pressing enter to bring it
down to the input area for editing.
Not only is it important to think through the expected result of an experiment
before executing it on the computer, but it is also a good practice to look for
patterns in any lists or tables you may see. Then verify your observations by
doing calculations by hand for short lists, and then test them more thoroughly on
the computer. For example, the list of odd numbers:
1+2*a
1 3 5 7 9 1
may be added by hand to give 36. Now add only the first five of the list, the first
four, and so on down to the first one.
Do you see a pattern in these results? If not, compare them with the following list
of squares:
(1+a)*(1+a)
1 4 9 16 25 36
6
Exploring Math
It appears that for any value of n, the sum of the first n odd numbers is simply the
square of n. This may be tested further as follows:
n=:20
a=:i.n
odds=:1+2*a
odds
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
sum=:+/
sum odds
400
n*n
400
The sum function +/ gives the sum of its arguments, but calculation of the
subtotals (the sum of the first one, the first two, etc.) would provide a more
thorough test. Thus:
sum\ odds
1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361
400
(1+a)*(1+a)
1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361
400
Hereafter we will suggest many experiments without showing the results,
expecting students to use the computer to produce them.
B. Ramble or Research
The main point of this book is to introduce a new tool for exploring math, and to
foster its use by applying it to a variety of topics. In other words, it provides a
ramble through a variety of topics rather than a systematic study of any one of
them.
Rambles through any subject can be much more rewarding, and more self-
directed, if one has a systematic knowledge of at least some aspect of it. For
example, amateur shell-collecting is more interesting to one with some knowledge
of molluscs and their classification; walks through parks are more rewarding to
one with some systematic knowledge of plant, animal, or insect life; and walks
through hills and mountains are made more interesting by a knowledge of
elementary geology.
However, any book on rambling would surely fail if stuffed with serious
digressions on the systematic study of each interesting point as it is discovered. It
is better to provide the reader with effective but unobtrusive pointers to other
sources.
Books 2 and 3 provide deeper studies of two branches of math: arithmetic and
calculus. Being that branch of math that deals with whole numbers, arithmetic is
the most elementary and accessible of subjects in math but, as treated in Book 2,
Chapter 1 Exploration
7
it also provides simple introductions to many more advanced topics, including
proofs, permutations, polynomials, logic, and sets.
These books are easy to consult because they use the same J notation. Moreover,
they incorporate more systematic introductions and discussions of the notation
itself. Further texts of this character include Reiter’s Fractals, Visualization and J
[1], and Concrete Math Companion [2].
On the other hand, treatments in conventional notation of a wide variety of topics
are more readily available in libraries. Use of them in conjunction with the
present text will require sometimes difficult translations between J and
conventional notation. However, the effort of translation is often richly repaid (as
it is in translating from one natural language to another) by deeper understanding
of the matters under discussion.
In fact, a deep appreciation of the method of exploration proposed here may best
be found in an attempt to write a companion volume to some chosen conventional
text. Some guidance in such an endeavour is provided by Concrete Math
Companion [2], published as a companion to Concrete Mathematics [3].
9
Chapter
2
What Is Math
math is the short form of mathematics, for
which the British use maths, preserving
the ugly plural form for a singular noun.
A. Relations
It is commonly thought that math is about numbers. So it is, but numbers are not
the only, nor even the most important, concern of math. It would be more accurate
to say that math is concerned with relations, and with proofs of relations.
Although the first chapter dealt only with numbers, it should be clear that the
interesting aspects were the relations between results. For example:
The first six non-negative integers
The integers in random order
The relation between multiplication and
The lists a and b are not equal
a=:i.6
b=:?.~6
b
5 1 2 4 3 0
3*a
0 3 6 9 12 15
a+a+a
0 3 6 9 12 15
(3*a)=(a+a+a)
addition
1 1 1 1 1 1
a=b
0 1 1 0 0 0
sort=:/:~
sort b
0 1 2 3 4 5
sort a
0 1 2 3 4 5
(sort a)=(sort b)
1 1 1 1 1 1
But are similar; one is a permutation of the other
10
Exploring Math
We will further illustrate this matter of relations by examples that do not concern
numbers. For example, the word 'POST' is said to be an anagram of the word
'SPOT' because the letters of 'SPOT' can be permuted to give the word 'POST'.
Thus 'SPOT' and 'POST' are similar in the sense already defined for lists. The
similarity of these words may be tested as follows:
w=:'SPOT'
x=:'POST'
sort w
OPST
sort x
OPST
(sort w)=(sort x)
1 1 1 1
Sorting w produces OPST. Is it an anagram? We will say that it is, although it is not
an English word.
You could (and should) attempt to write down all distinct anagrams of 'SPOT',
finding a surprising number of English words among them. However, this might
be rather difficult to do; in a long list of words it is easy to overlook repetitions,
and you may not even know how many anagrams to expect all together.
We will now use the anagram function A. for this purpose. Its left argument
chooses one of many permutations to apply to the list right argument. Thus:
w
SPOT
8 A. w
POST
12 A. 8 A. w
SPOT
The permutation 12 A. is the inverse of 8 A.
0 1 2 3 4 5 6 7 8 A. w
SPOT
SPTO
SOPT
SOTP
STPO
STOP
PSOT
PSTO
POST
30 A. w
|index error
| 30 A.w
The last result shows that there is a limit to the valid left argument; properly so,
since there is a limit to the number of different permutations of a list. But how
many are there? In the case of a two-item list 'AB' there are clearly only two
possibilities, the identity permutation that leaves the list unchanged, and the one
that gives 'BA'. Thus:
Chapter 2 What is Math
11
0 1 A. 'AB'
AB
BA
Write down all permutations of the list 'ABC' to convince yourself that there are
six possible permutations. Thus:
(i.6)A.'ABC'
ABC
ACB
BAC
BCA
CAB
CBA
Exercises
1. Produce all anagrams of various three-letter English words to find those
words that have the largest number of proper English words among their
anagrams.
2. Did you find any word more prolific than 'APT'?
3. Find all English words among the anagrams of 'SPOT'.
In solving the last exercise above, it was necessary to find the largest left
argument of A. permitted. This could be done by experiment. Thus:
22 A. 'SPOT'
TOSP
23 A. 'SPOT'
TOPS
24 A. 'SPOT'
|index error
| 24 A.'SPOT'
(i.24)A.'SPOT'
SPOT
SPTO
SOPT
SOTP
STOP
STOP
PSOT
PSTO
POST
POTS
PTSO
PTOS
OSPT
OSTP
OPST
OPTS
12
Exploring Math
OTSP
OTPS
TSPO
TSOP
TPSO
TPOS
TOSP
TOPS
But what is the general relation between the number of permutations and the
number of items in the list to be permuted? Although we are dealing with English
words and anagrams rather than with numbers, this is a proper mathematical
question because it concerns relations. The question can be answered in the
following steps:
In a four-letter word, the first position in an anagram can be filled in any one of
four ways.
Having filled the first position, the next can be filled from the remaining three
letters in three different ways.
The next position can be filled in two ways.
The last position can be filled in one way.
The total number of ways is the product of these, that is, four times three times
two times one.
This product over all integers up to a certain limit (4 in the present example) is so
useful that it is given its own name (factorial) and symbol (!). Thus:
!4
24
4*3*2*1
24
!0 1 2 3 4 5 6 7
1 1 2 6 24 120 720 5040
The number of items in a list is a function that is also provided with a symbol:
w3=:'APT'
#w3
3
i.!#w3
0 1 2 3 4 5
(i.!#w3)A.w3
APT
ATP
PAT
PTA
TAP
TPA
Exercises
Chapter 2 What is Math
13
4. Comment on the following experiments:
sort=:/:~
w=:'SPOT'
sort w
table=:(i.!#w)A. w
# table sort table
5. A table with more rows than columns may be displayed more compactly by
transposing it. Try the following:
transpose=:|:
transpose table
The function A. applies to lists of numbers as well as to lists of letters (words),
and when applied to lists such as i.3 and i.4 produces tables that show its
behaviour more clearly. The following experiment uses the link function (;) to
box tables and link them together for more convenient comparison:
i=:i.24
(i A. 'SPOT');(i A. 'ABCD');(i A. 0 1 2 3)
+----+----+-------+
|SPOT|ABCD|0 1 2 3|
|SPTO|ABDC|0 1 3 2|
|SOPT|ACBD|0 2 1 3|
|SOTP|ACDB|0 2 3 1|
|STPO|ADBC|0 3 1 2|
|STOP|ADCB|0 3 2 1|
|PSOT|BACD|1 0 2 3|
|PSTO|BADC|1 0 3 2|
|POST|BCAD|1 2 0 3|
|POTS|BCDA|1 2 3 0|
|PTSO|BDAC|1 3 0 2|
|PTOS|BDCA|1 3 2 0|
|OSPT|CABD|2 0 1 3|
|OSTP|CADB|2 0 3 1|
|OPST|CBAD|2 1 0 3|
|OPTS|CBDA|2 1 3 0|
|OTSP|CDAB|2 3 0 1|
|OTPS|CDBA|2 3 1 0|
|TSPO|DABC|3 0 1 2|
|TSOP|DACB|3 0 2 1|
|TPSO|DBAC|3 1 0 2|
|TPOS|DBCA|3 1 2 0|
|TOSP|DCAB|3 2 0 1|
|TOPS|DCBA|3 2 1 0|
+----+----+-------+
B. Proofs
Although proofs are an important (and many would say the essential) part of
mathematics, we will spend little time on them in this book.
In introducing his book Proofs and Refutations: The Logic of Mathematical
Discovery [4], Imre Lakatos makes the following point:
Its modest aim is to elaborate the point that informal, quasi-
empirical, mathematics does not grow through a monotonous
increase of the number of indubitably established theorems but
14
Exploring Math
through the incessant improvement of guesses [Italics added] by
speculation and criticism, by the logic of proofs and refutations.
The main point of the present book is to exploit a new tool for the exploration of
relations and patterns that can be used by both mathematicians and laymen to find
those guesses that are amenable to, and worthy of, proof. We will defer further
discussion of proofs to Chapter 9, partly to allow the reader to garner guesses that
can be used to illuminate the discussion.
We will, however, recommend the reading of Lakatos at any point. The book is
highly entertaining, instructive, and readable by any layman with the patience to
look up the meanings of a small number of words such as polyhedron, polygon,
and convex.
The following quotes from Lakatos reflect his view of the importance of
guessing:
Just send me the thereoms, then I shall find the proofs.
Chrysippus
I have had my results for a long time, but I do not yet know how I am to
arrive at them.
Gauss
If only I had the theorems! Then I should find the proofs easily enough.
Riemann
I hope that now all of you see that proofs, even though they may not
prove, certainly do help to improve our conjecture.
Lakatos
On the other hand those who, because of the usual deductive
presentation of mathematics, come to believe that the path of discovery
is from axioms and/or definitions to proofs and theorems, may
completely forget about the possibility and importance of naive
guessing.
Lakatos
Exercises
6. Read the three pages of Section C, Chapter 5, of Book 2.
C. Summary
In brief, we will interpret math in the following sense: it concerns relations, and
provides languages for expressing them, as well as for expressing transformations
on tangible representations.
For example, the first four counting numbers can be represented by the list of
symbols
1 2 3 4:
! 1 2 3 4
1 2 6 24
A transformation (or function)
*/\ 1 2 3 4
1 2 6 24
Chapter 2 What is Math
15
A second transformation
(! 1 2 3 4)=(*/\ 1 2 3 4)
1 1 1 1
Equivalent to the first
17
Chapter
3
Function Tables
The pleasures of the table
belong to all ages
Jean Anthelme Brillat-Savarin
and make it plain upon tables
that he may run that readeth it
Habakkuk
The effect of multiplication can be shown rather neatly in a succession of
products of a list as follows:
a=: i.6
0*a
0 0 0 0 0 0
1*a
0 1 2 3 4 5
2*a
0 2 4 6 8 10
However, a more perspicuous table of products with each item of a can be
prepared as follows:
a*/a
0 0 0 0 0 0
0 1 2 3 4 5
0 2 4 6 8 10
0 3 6 9 12 15
0 4 8 12 16 20
0 5 10 15 20 25
Similar tables can be prepared for other known functions. For example:
(a*/a);(a+/a);(a-/a)
+---------------+------------+----------------+
|0 0 0 0 0 0|0 1 2 3 4 5|0 _1 _2 _3 _4 _5|
|0 1 2 3 4 5|1 2 3 4 5 6|1 0 _1 _2 _3 _4|
|0 2 4 6 8 10|2 3 4 5 6 7|2 1 0 _1 _2 _3|
|0 3 6 9 12 15|3 4 5 6 7 8|3 2 1 0 _1 _2|
|0 4 8 12 16 20|4 5 6 7 8 9|4 3 2 1 0 _1|
|0 5 10 15 20 25|5 6 7 8 9 10|5 4 3 2 1 0|
+---------------+------------+----------------+
18
Exploring Math
Much can be learned from such tables. For example, the multiplication table is
symmetric, that is, each row is the same as the corresponding column, and its
transpose (|:a*/a) is the same as the table a*/a itself. This implies that the
arguments of multiplication may be exchanged without changing the product, or,
as we say, multiplication is commutative. The same may be said of addition, but
not of subtraction, which is non-commutative, as is obvious from its table. Tables
for both negative and positive arguments are even more interesting. For example,
try each of the three tables with the following symmetric argument:
i: 6
_6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6
Note how the multiplication table is broken into quadrants of exclusively positive
or exclusively negative numbers by the row and column of zeros, and try to
explain why this occurs.
The symbol / in the sentence a*/a denotes an adverb, because it applies to the
verb * to produce a related verb (that is in turn used to produce a table).
It is much easier to interpret a table if it is bordered by its arguments. We will use
a second adverb called table for this purpose. For example:
b=:2 3 5 7 11
a *table b Bordered multiplication table
+-+--------------+
| | 2 3 5 7 11|
+-+--------------+
|0| 0 0 0 0 0|
|1| 2 3 5 7 11|
|2| 4 6 10 14 22|
|3| 6 9 15 21 33|
|4| 8 12 20 28 44|
|5|10 15 25 35 55|
+-+--------------+
+table~ a Bordered addition table
+-+------------+
| |0 1 2 3 4 5|
+-+------------+
|0|0 1 2 3 4 5|
|1|1 2 3 4 5 6|
|2|2 3 4 5 6 7|
|3|3 4 5 6 7 8|
|4|4 5 6 7 8 9|
|5|5 6 7 8 9 10|
+-+------------+
*table~ i:6
+--+-----------------------------------------------+
| | _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6|
+--+-----------------------------------------------+
|_6| 36 30 24 18 12 6 0 _6 _12 _18 _24 _30 _36|
|_5| 30 25 20 15 10 5 0 _5 _10 _15 _20 _25 _30|
|_4| 24 20 16 12 8 4 0 _4 _8 _12 _16 _20 _24|
|_3| 18 15 12 9 6 3 0 _3 _6 _9 _12 _15 _18|
|_2| 12 10 8 6 4 2 0 _2 _4 _6 _8 _10 _12|
|_1| 6 5 4 3 2 1 0 _1 _2 _3 _4 _5 _6|
| 0| 0 0 0 0 0 0 0 0 0 0 0 0 0|
Chapter 3 Function Tables 19
| 1| _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6|
| 2|_12 _10 _8 _6 _4 _2 0 2 4 6 8 10 12|
| 3|_18 _15 _12 _9 _6 _3 0 3 6 9 12 15 18|
| 4|_24 _20 _16 _12 _8 _4 0 4 8 12 16 20 24|
| 5|_30 _25 _20 _15 _10 _5 0 5 10 15 20 25 30|
| 6|_36 _30 _24 _18 _12 _6 0 6 12 18 24 30 36|
+--+-----------------------------------------------+
Tables also provide an interesting and effective way to explore unfamiliar functions.
Often, the display of a bordered function table provides a precise and easily-remembered
definition of the function. For example:
Relation
table~ a) Relations
+-+-----------+-+-----------+-+-----------+
| |0 1 2 3 4 5| |0 1 2 3 4 5| |0 1 2 3 4 5|
+-+-----------+-+-----------+-+-----------+
|0|0 1 1 1 1 1|0|1 0 0 0 0 0|0|0 0 0 0 0 0|
|1|0 0 1 1 1 1|1|0 1 0 0 0 0|1|1 0 0 0 0 0|
|2|0 0 0 1 1 1|2|0 0 1 0 0 0|2|1 1 0 0 0 0|
|3|0 0 0 0 1 1|3|0 0 0 1 0 0|3|1 1 1 0 0 0|
|4|0 0 0 0 0 1|4|0 0 0 0 1 0|4|1 1 1 1 0 0|
|5|0 0 0 0 0 0|5|0 0 0 0 0 1|5|1 1 1 1 1 0|
+-+-----------+-+-----------+-+-----------+
Power and “outof”
(^table~ a),.(!table~ a)
+-+-------------------+-+------------+
| |0 1 2 3 4 5| |0 1 2 3 4 5|
+-+-------------------+-+------------+
|0|1 0 0 0 0 0|0|1 1 1 1 1 1|
|1|1 1 1 1 1 1|1|0 1 2 3 4 5|
|2|1 2 4 8 16 32|2|0 0 1 3 6 10|
|3|1 3 9 27 81 243|3|0 0 0 1 4 10|
|4|1 4 16 64 256 1024|4|0 0 0 0 1 5|
|5|1 5 25 125 625 3125|5|0 0 0 0 0 1|
+-+-------------------+-+------------+
%: table~ a
+-+-----------------------------------+
| |0 1 2 3 4 5|
+-+-----------------------------------+
Roots
20
Exploring Math
|0|0 1 _ _ _ _|
|1|0 1 2 3 4 5|
|2|0 1 1.41421 1.73205 2 2.23607|
|3|0 1 1.25992 1.44225 1.5874 1.70998|
|4|0 1 1.18921 1.31607 1.41421 1.49535|
|5|0 1 1.1487 1.24573 1.31951 1.37973|
+-+-----------------------------------+
Exercises
1. Produce and examine bordered tables for the following functions:
<. >.
<: >:
%
2.
Produce and examine bordered tables for the following “commuted”
functions:
<.~ >.~
<:~ >:~
%~
3. Produce and examine bordered tables for the following Greatest Common
Divisor and Least Common Multiple functions:
+. *.
In particular, apply them to the argument 0 1 (as in +.table 0 1) and note
that with the interpretation of “true” for 1 and “false” for 0 (as was done by
Boole), they then represent the logical functions “or” and “and”
4. Explain the equality denoted by the following sentence:
(e>:/e)=(e>/e)+.(e=/e=:s 6)
5. First enter:
at=:+/~ e
mt=:*/~ e
st=:-/~ e
dt=:%/~ e
trans=:|:
Then comment on the results of the following:
at-:trans at
mt-trans mt
st+trans st
dt*trans dt
The following exercises suggest a sequence of experiments that should be tried
only after reviewing the tips on explorations given in Chapter 1:
6. a=:i.6
+:a
-:a
(+:a)-(-:a)
(+:--:)a
Exercises
Double minus half
Dmh=:+:--:
Dmh a
7. Contrast the result of the following sentence with those of Exercise 6:
+:--:a
Chapter 3 Function Tables 21
+/%#)a
8.
Average=:+/%#
Average a
Average 3 1 4 1 6
9. Re-enter the sentence (a*/a);(a+/a);(a-/a) from the beginning of this
chapter, and compare the result with the following:
a(*/;+/;-/)a
f=:*/;+/;-/
a f a
f~ a
23
Chapter
4
Grammar And Spelling
The level is low
but it has not fallen
Jacques Barzun
I can spell all the words that I use
and my grammar’s as good as my neighbour’s
W.S. Gilbert
A. Introduction
We have already made significant use of J, why trouble us now with its grammar?
On the other hand, if grammar is important, why was it not treated first?
In learning our native language we spend years at it and become quite proficient
before we even hear of grammar. However, grammar becomes important for more
advanced use of the language in clear writing and speaking. Moreover, the
teaching of grammar relies on many examples of the use of the language that
would not be familiar to a beginner.
Similarly, more advanced and independent writing in J will require knowledge of
its grammar. Moreover, we will find it helpful to refer to sentences from earlier
chapters to illustrate and motivate discussions of the grammar.
In learning a second language a student has the advantage of already appreciating
the purposes and value of language, as well as some knowledge of grammar from
her native tongue. On the other hand, one may be seriously misled by such
knowledge, and the student is sometimes best advised to forget her native
language as much as possible: one may know too many things that are not true.
The beginner in J will already know much of two relevant languages: English,
and Mathematical Notation (to be referred to as MN). The knowledge of English
grammar is very helpful, especially when we recognize certain analogies between:
• English verbs (action words) and functions such as + and - and *
• Nouns on which verbs act, and the arguments (such as 3 and 4 and 'STOP') to
which functions apply
• Pronouns such as a and b and mt used in the preceding chapter, and pronouns
such as “it” and “she” used in English
• Adverbs (such as table in the preceding chapter) that apply to verbs
(functions) to produce different, but related, verbs
24
Exploring Math
Knowledge of MN can be very helpful, particularly in providing familiarity with
numbers and symbols for common functions, and with some of the purposes of
math. On the other hand, MN can be very misleading because it shows little
concern for simple and consistent grammar. For example:
• The simple forms a+b and a*b used for some functions of two arguments is
abandoned in others, as in xn for the x^n used in J, and in (n
number of ways of choosing m things from n)
m) for m!n (the
• The rule that a function of one argument precedes its argument (as in -b and
sqrt b) is abandoned in the case of the factorial (n!). In J this is written as
!n.
• The ambivalent use of the minus sign to denote two different functions as
determined by the number of arguments provided (subtraction in a-b, and
negation in -b) is not extended to all functions as it is in J. For example, a%b
and %b denote divided by and reciprocal; a^b and ^b denote power and
exponential; and a+/b and +/b denote the addition table and sum over.
• The imposition of hierarchical rules of execution for certain functions: power
is performed before multiplication and division, which are performed before
addition and subtraction. The reasons for the development of such rules in
MN lie in the expressions used for polynomials, and will be discussed further
in the corresponding chapter.
B. The Use of Grammar
The rules of grammar determine how a sentence is to be parsed, that is, the order
in which its parts are to be interpreted or executed. In particular, these rules cover
the use of punctuation, which can make an enormous difference, as illustrated by
the following sentences:
The teacher said George was stupid
The teacher, said George, was stupid
The punctuation in J is provided by parentheses, as illustrated by the following
sentences from Chapter 2:
a=:i.6
b=:?.~6
(3*a)=(a+a+a)
1 1 1 1 1 1
3*a=a+a+a
3 0 0 0 0 0
Removal of the punctuation yields a quite different result
The parsing of a sentence does not depend on the particular word used, but only
on the class to which it belongs. Thus the English examples used above would be
parsed without change if the nouns farmer and Mary were substituted for the
nouns teacher and George. Similarly, the sentence (3*b)=(b+b+b) would parse
the same as (3*a)=(a+a+a).
The classes concerned are called the parts of speech. J has only six parts of
speech (including the punctuation provided by parentheses), all of which have
Chapter 4 Grammar and Spelling
25
been used in earlier chapters. For example, the nouns 3 and 2, and the verbs + and
* and - occur in the first three sentences in Chapter 1, and the copula =:
(analogous to the copulas is and are in English) occurs in the next.
As in English, an adverb applies to a verb to produce a related verb. Examples
occurring in Chapter 1 are:
The adverb / which inserts its argument function between items of the noun to
which it applies. For example, +/1 2 3 4 is equivalent to 1+2+3+4, and the
function +/ may therefore be called the sum function.
The adverb \ which uses its argument function to scan all prefixes of its noun
argument: +/\1 2 3 is equivalent to (+/1),(+/1 2),(+/1 2 3).
In English, the phrase “run and hide” uses the copulative conjunction “and” to
produce a new verb that is a composition of the actions described by the verbs
“run” and “hide”. In J, @: is a conjunction that applies its first argument verb to
the result of its second argument verb. For example:
a
0 1 2 3 4 5
b
5 1 2 4 3 0
a-b
_5 0 0 _1 1 5
+/a-b
0
a +/@:- b
0
sumdif=:+/@:-
1 2 3 4 5 sumdif 2 3 5 7 11
_13
Exercises
1. Search earlier chapters for further examples of the various parts of speech.
2. State the effect of the adverb ~ in the sentences a-~b and a^~b.
C. Punctuation and Other Rules
In J, a sentence can be completely punctuated so that the only grammatical rule
needed to parse it concerns the use of parentheses. For example, the area of a
rectangular field can be computed as follows:
Length=:8
Width=:6
Area=:Length*Width
Area
48
26
Exploring Math
If instead the width and the length of the roll of wire available to enclose the field
are given, the area may be computed as follows:
Roll=:32
Sides=:Roll-(Width+Width)
Length=:Sides%2
Length*Width
60
Extent available for other two sides
Area for given roll and width
The whole may be re-expressed as a single sentence punctuated as follows:
Area=:((Roll-(Width+Width))%2)*Width
Although long names such as Width and Roll can be helpful in understanding the
point of a sentence, they can also obscure its structure. Briefer (but still
mnemonic) names may be substituted:
W=:Width
P=:Roll
field
A=:((P-(W+W))%2)*W
An abbreviation for the perimeter of the
Other grammatical rules make it possible to omit some parentheses. The next rule
(after the rule for parentheses) is:
• A sentence is executed from right to left
Consequently, the phrase (P-(W+W)) may be re-written as (P-W+W). Hence:
A=:((P-W+W)%2)*W
This can be further simplified by using the fact that multiplication is
commutative:
A=:W*((P-W+W)%2)
A=:W*(P-W+W)%2
Since division is not commutative, this trick cannot be repeated, but because
division by two is equal to multiplication by one-half, we have:
A=:W*(P-W+W)*0.5
A=:W*0.5*(P-W+W)
A=:W*0.5*P-W+W
Although an unparenthesized sentence or phrase is executed from right to left, it is
easily read from left to right. To illustrate this we will use the right-to-left
execution rules to fully parenthesize the last sentence above:
A=:(W*(0.5*(P-(W+W))))
This can now be read from left to right as follows: A is W times the value of the
entire phrase that follows it, which in turn is 0.5 times the phrase that follows it,
and so on.
The foregoing example made no use of adverbs and conjunctions, and for a
sentence that does include them we need a further rule:
• Adverbs and conjunctions are applied before verbs.
For example:
Chapter 4 Grammar and Spelling
27
+/a*b is equivalent to (+/)a*b
^&3 a+b is equivalent to (^&3)a+b
A complete formal statement of the grammar of J may be found in J Dictionary
[5], which is also available on the computer by using the Help menu. This
statement of the grammar should perhaps be studied at some point, but it is
probably better to begin by reviewing familiar sentences and trying to apply the
grammatical rules to them. You might review the sentences of earlier chapters as
follows:
• Modify and simplify them, using the methods suggested in the foregoing
examples (as well as any others that occur to you).
• Try to read the resulting sentences from left to right, using English to
paraphrase them.
• Assign values to any names used in the sentences so that they may be entered
for execution. If you modify a sentence in any way that changes its meaning,
you will probably be alerted to the fact by seeing a different result upon
entering it.
The following Exercises highlight points that you might well miss in your review.
Exercises
3. Comment on the sentence a=:0,1,2,3,4,5 used in Chapter 1 to introduce the
first example of a list.
[The comma denotes a catenate verb that appends one list (or a single item) to
another. Also experiment with other forms of catenate as in:
b=:i.-6
a,b
a,.b
a,:b
a;b
Called stitch
Called laminate
Called link ]
4. Why is it possible to enter a list of numbers as in a=:0 1 2 3 4 5 as well as
by using the catenate function as in Exercise 3?
[Certain results that can be produced by functions can also be entered more
simply as constants. For example:
3-5
3+8%10
3%5
3+j.4
2,3,5,7
This sentence
this constant
is equivalent to
_2
3.8
3r5
3j4
2 3 5 7 ]
5. Read the first five pages of Part II (Grammar) of J Dictionary [5] (also
available in Help, as described in Chapter 10).
D. Spelling
The many words in English are each represented by one or more letters from a
rather small alphabet. The words (nouns, verbs, etc.) of J are each represented by
28
Exploring Math
one or more characters from an alphabet of letters and other symbols. For
example:
+ +. +: & i. A.
Every word of more than one character ends with a dot or a colon.
Any other sequence beginning with a letter and continuing with letters or digits
(but not ending with a dot or colon) is a name that may be used with a copula, as
in the following examples:
a=:i.6
plus=:+
g=:/\
Pronoun
Proverb
Pro-adverb
p3=:^&2
Proverb
The representation of numbers is illustrated by:
2 and 2.4 and 0.4
_2 and _2.4 and _0.4
A decimal point must be preceded by a negative sign or at least one digit. As
shown in Exercise 4, an r may be used in a number to denote a rational fraction
(as in 2r3 for two-thirds), and a list may be represented by a list of numbers (as in
2.3 2r3 4).
The spelling rules of J determine how words are formed from the string of
characters that comprise a sentence. They can be clarified by applying the word-
formation verb to a (quoted) sentence. For example:
;: '+/4 3 2 1*/i.6'
+-+-+-------+-+-+--+-+
|+|/|4 3 2 1|*|/|i.|6|
+-+-+-------+-+-+--+-+
It should also be noted that redundant spaces may be inserted in a sentence to
improve readability, as in a=: i. 6 instead of a=:i.6 .
29
Chapter
5
Reports
Cornelius the centurion,
a man of good report
Acts
A. Introduction
If a is a list of twelve monthly receipts for a year, then a quarter-by-month report
of the same receipts can be obtained as follows:
]qm=:4 3$ a=:1 7 4 5 2 0 6 6 9 3 5 8
1 7 4
5 2 0
6 6 9
3 5 8
The sum over the quarters is given by:
+/qm
15 20 21
A two-year report for constant receipts of 10 can be obtained by:
ten=:2 4 3$10
ten
10 10 10
10 10 10
10 10 10
10 10 10
10 10 10
10 10 10
10 10 10
10 10 10
A more realistic report can be obtained by applying the repeatable random
generator to this array:
30
Exploring Math
yqm=:?.ten
yqm
1 7 4
5 2 0
6 6 9
3 5 8
0 0 5
6 0 3
0 4 6
5 9 8
The sums over the years of this report are:
+/yqm
1 7 9
11 2 3
6 10 15
8 14 16
Because yqm has three categories or axes, we call it a rank-3 report or array. Its
rank-2 cells are the two quarter-by-month tables seen in its display, and its rank-1
cells are the eight rows (arranged, in effect, in a 2 by 4 array).
The sums over the quarters in each year are the sums over the two rank-2 cells,
yielding a 2 by 3 array (for the two years and three months in each quarter). Thus:
+/"2 yqm
15 20 21
11 13 22
Similarly, the sums over the three months in each quarter are a 2 by 4 array given
by:
+/"1 yqm
12 7 21 16
5 9 10 22
Exercises
1. Enter the foregoing expressions, and verify that they reproduce the foregoing
results.
2. The function ?. reproduced the same result because it is a repeatable random
number generator. Try the expression ?ten several times to show that the
results do not repeat.
3. Predict and verify the results of +/"3 yqm and +/"0 yqm.
4. Experiment with the box function, as in <3 4 5 and ar;br;cr
365 1996 29
bv10i bv10&> ar;br;cr
0 3 6 5
1 9 9 6
0 0 2 9
N +/ bv10i bv10&> ar;br;cr
2 3 9 0
a+b+c
2390
Padding can also be provided more directly, using the fact that the simple opening
of a boxed list pads it, albeit on the wrong side:
>ar;br;cr
3 6 5 0
1 9 9 6
2 9 0 0
pad=:|."1@:(|.&>)
pad ar;br;cr
0 3 6 5
44
Exploring Math
1 9 9 6
0 0 2 9
C. Multiplication
The commonly-taught methods for addition and multiplication both interleave
carries with other computations: in multiplication, each item of the multiplier is
applied to the multiplicand and the carries are propagated to give a list of results
which are then added to lists for the other items of the multiplier, producing a
further sequence of carries. However, as in addition, the carries can all be
segregated in a final normalization. For example:
a=:365 [ b=:1996
ar=:bv10i a [ br=:bv10i b
t=:ar*/br
t
3 27 27 18
6 54 54 36
5 45 45 30
This table of products may now be summed to collect those corresponding to the
same powers of ten, that is, diagonally as follows:
s=:3,(27+6),(27+54+5),(18+54+45),(36+45),30
s
3 33 86 117 81 30
(10#.s),(a*b)
728540 728540
This may also be expressed by using the oblique adverb /., which applies its
function argument to each of the diagonals. Thus:
]s=:+//.t
3 33 86 117 81 30
Exercises
10. Carry out by hand the process defined by +//.ar*/br for various values of ar
and br, and test the correctness of the resulting products.
11. Experiment with the expression :
r=:0&=
f 0
1
However, it would seem more straightforward to define q as the constant 1 as
follows:
q=:1
f 0
│domain error
│ f 0
A problem arises because 1 is a noun, not a function, and the arguments in the
gerund p`q must both be functions. We therefore need a function that returns the
constant value 1 when applied to any argument. Such constant functions are
commonly needed, and are produced by the rank conjunction ("), used in Chapter
5 to modify a function, as in <"2. Thus:
1"0 x=:i.4
1 1 1 1
1"_ x
1
Rank 0 produces a result for each atom of x
Infinite rank gives a single result for any argument
x"1 'Now is the time'
Chapter 8 Recursion
49
0 1 2 3
The function q may therefore be redefined as follows:
q=:1"_
f"0 (4 3 2 1 0)
24 6 2 1 1
Finally, f (of rank 0) may be redefined compactly as follows:
f=:(]*f@:<:)`(1"_)@.(0&=)"0
f 4 3 2 1 0
24 6 2 1 1
As a second example of recursive definition we will define the sum of the first n
odd numbers, first met in Chapter 1:
sod=:0"_`(>:@+:@<: + sod@<:)@.*
sod 4
16
sod"0 i.6
0 1 4 9 16 25
The definition of sod may be interpreted as follows: When the argument n is 0,
then the signum on the right returns 0, choosing the leading function in the
gerund, giving a result of 0; otherwise, the result is the nth odd number (that is,
>:@:+:@:<:) plus the sum for an argument n-1 (that is, sod@<:).
Exercises
2. For convenience, certain constant functions are provided directly, without the
need for the rank operator. Experiment with the constant functions _9: and
_8: and so on through 9:. Use 1: and 0: to simplify the definitions of f and
sod above.
3. Because increment (>:) is the inverse of decrement (<:), the expression
>:@+:@<: is of the form gi@f@g, where gi is the inverse of g. We say that
this is a case of applying f under g, and denote it by f&.g. Use this fact to
simplify the definition of sod, and check the resulting behaviour.
Recursive definition essentially specifies a function in terms of the same function
applied to a simpler case, and its use can enormously simplify many definitions.
For example, the Tower of Hanoi puzzle is stated as follows:
A set of n drilled discs of different diameters stacked as a pyramid on a peg A
is to be moved one at a time to a peg C without ever placing a larger on a
smaller. A third peg B may be used as intermediary.
The process for two discs may be expressed by the table:
50
Exploring Math
AB
AC
BC
which is to be interpreted row-by-row as follows:
Move (the top) disc from A to B
Move from A to C
Move from B to C
The case of n discs can be expressed in terms of the case of one fewer as follows:
Move n-1 discs to the intermediary peg B, then move the remaining largest disc to
C, and finally move the n-1 discs from B to C.We will use this fact to make a
recursive definition as follows:
H=:m`b@.(1&=@[)
m=:(<:@[ H 1: A. ]) , b@] , <:@[ H 2: A. ]
b=:,:@(0 2&{)@]
p=:'ABC' Pegs
1 H p
AC
2 H p
AB
AC
BC
|: 3 H p Transposed table
AACABBA
CBBCACC
Exercises
4. Use discs and pegs (or numbered cards and labelled positions on a table) to
carry out the instructions in the foregoing tables to verify that they provide
proper solutions to the Hanoi puzzle. Also enter the expression |: 3 H p and
test it as well.
5. Give an expression for the number of moves required for n discs.
6. Explain the behaviour of the definition of H, using experiments to show the
permutation provided by the function A., the selection provided by the
indexing function {, and the purpose of the monadic function ,:. Also
redefine the main function m, using indexing to perform the necessary
permutations.
7. Experiment with the function HV=: |:@H.
8. Read the definition of agenda in [5], and experiment with the use of $: for
self-reference in recursive definitions.
9. Compare the following recursively-defined function n with the first definition
of NORM in the preceding chapter:
f=:(0:,10&|) + <.@(%&10) , 0:
g=:+/@(*./\@(0&=)) }. ]
h=:*./@(10&>)
n=:n@f`g@.h
Chapter 8 Recursion
51
53
Chapter
9
Proofs
Drug thy memories, lest thou learn it,
lest thy heart be put to proof
Tennyson
A. Introduction
It is probably advisable to begin by reviewing the brief discussion of proofs at the
end of Chapter 2.
The final experiment of Chapter 1 showed a relation between the sum of the first
n odd numbers and the square of n. We will first reproduce it here:
n=:20
odds=:1+2*a=:i.n=:20
odds
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
(+/odds),(n*n)
400 400
+/\odds
1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361
400
(1+a)*(1+a)
1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361
400
But is the indicated relation true for any positive integer n? If you are already
convinced that it is, any proof may seem pointless. However, you might still ask
why it is true. The following should be helpful in answering this:
q=:1+2*i.n=:6
r=:|.q
q,:r
1 3 5 7 9 11
11 9 7 5 3 1
First six odd numbers
Odds in reverse order
54
Exploring Math
(+/q);(+/r);(q+r);(2%~q+r);(+/2%~q+r)
+--+--+-----------------+-----------+--+
|36|36|12 12 12 12 12 12|6 6 6 6 6 6|36|
+--+--+-----------------+-----------+--+
The foregoing shows the rather obvious fact that sums over a list, over the
reversed list, and over one-half of the sum of the lists all agree. But the half-sum
of the lists has a pattern whose sum is easily expressed as a product:
(2%~q+r);(n#n);(+/n#n);(n*n)
+-----------+-----------+--+--+
|6 6 6 6 6 6|6 6 6 6 6 6|36|36|
+-----------+-----------+--+--+
The last agreement (between +/n#n and n*n) is based on the fact that
multiplication is defined as repeated addition.
The foregoing attempted to show why two results were equal by exhibiting their
equivalence to other results, where the equivalence was already known or
obvious. This is perhaps the only way to answer the question why. However, the
equivalences assumed may be made clearer by laying out the steps of the
argument as a proof, that is, as a succession of equivalent statements annotated by
the justification of the equivalence of each to the one preceding it. Thus:
+/q=:1+2*i.n
+/|.q
2%~(+/q)+(+/|.q)
2%~+/(q+|.q)
+/2%~(q+|.q)
+/(n#n)
n*n
Summation is symmetric (unaffected by ordering)
Half sum of equals is an identity
Summation is symmetric
Summation distributes over division
The definition of multiplication
Such a list of supposedly equivalent sentences can be tested (for careless errors)
by assigning a suitable value to the argument n, entering them on the computer,
and comparing the results.
This putative proof has not proved anything but it has, as Lakatos would say,
broken the original conjecture into a collection of sub-conjectures, each of which
may be profitably examined. Consider the first assertion that summation is
symmetric, and gives the same result when applied to any permutation of a list.
This may be tested as follows:
q=:1+2*i.n=:6
117 A. q
1 11 9 5 7 3
_1 A. q
11 9 7 5 3 1
(+/q),(+/117 A. q),(+/_1 A. q)
36 36 36
But why is summation symmetric? We may, for example, ask whether the notion
applies to other functions, as in product over (*/), maximum over (>./), and
Chapter 9 Proofs
55
subtraction over
(-/), beginning with the following tests:
r=:|.q
(+/q),(*/q),(>./q),(-/q)
36 10395 11 _6
(+/r),(*/r),(>./r),(-/r)
36 10395 11 6
What is it about the functions +, *, and >. that make +/, */, and >./ symmetric?
The answer is that they are both associative and commutative. These matters are
examined further in Exercises, but the main point is that any conjecture may lead
to further sub-conjectures that can be identified and pursued until the reader
reaches assertions that are satisfying to him. As Lakatos shows, assertions
satisfactory for one reader (or purpose) may not be satisfactory for another.
Exercises
1. Addition is said to be associative because a sequence of additions can be
associated by parenthesizing them in any way without changing the result. For
example, +/1 2 3 4 and (1+(2+(3+4))) and ((1+2)+(3+4)) and
(1+(2+3)+4) are all equal. Test the associativity of addition by entering a
variety of equivalent expressions.
2. Repeat Exercise 1 for product and maximum.
3. The completely parenthesized form of +/q is 1+(3+(5+(7+(9+11)))), and
the corresponding form of +/117 A. q) is 1+(11+(9+(5+(7+3)))). Write a
sequence of sentences [such as 1+(3+(5+(7+(11+9))))]that uses only
associativity and commutativity to move from the first expression to the last,
and enter them all to test their equivalence.
4. Use the words Comm and Assoc to annotate your solution to Exercise 3 to
provide a formal proof of the equivalence of +/q and +/117 A. q.
5. The proof that +/q is equivalent to n*n is completely formal except for one
omission. Complete it.
Following Lakatos’s point that a formal or informal proof may suggest further
lines of inquiry, we note that the list sum q+|.q gave items with a common value.
This is, of course, a proposition that is not true for every list q, but depends upon
some property of q. What is that property?
The point is that q is an arithmetic progression; successive items increase by the
addition of a fixed constant (in this case 2). The sum of the first and last items
therefore equals the sum of the item just following the first and just preceding the
last, and so on for further pairs. This is more easily stated (and seen) by reversing
the list to bring corresponding pairs together. Thus:
q,:|.q
1 3 5 7 9 11
11 9 7 5 3 1
56
Exploring Math
+/q,:|.q
12 12 12 12 12 12
The method of proof can therefore be applied to find expressions equal to the sum
of any geometric progression. For example:
g=:i.n=:6
g,:|.g
0 1 2 3 4 5
5 4 3 2 1 0
+/g,:|.g
5 5 5 5 5 5
(n*n-1)%2
15
+/g
15
b=:4 [ s=:3 [ n=:7
h=:b+s*i.n
h
4 7 10 13 16 19 22
+/(h,:|.h)%2
13 13 13 13 13 13 13
b+(s*n-1)%2
13
n*b+(s*n-1)%2
91
+/h
91
An AP beginning at b with steps of size s
Exercises
6. Write formal proofs for each of the foregoing results.
7. Define a function f such that f b,s,n gives the mean of the arithmetic
progression beginning at b and continuing with increments s for a total of n
items.
B. Inductive Proof
An inductive proof of the equivalence of two functions proceeds by first assuming
that they are equal for some unstated value of the integer argument n, and using
that assumption (called the induction hypothesis) to prove that they are therefore
equal for the next argument n+1. It is then shown that they are indeed equal for
some specific argument n=:k. It therefore follows that they are equal for all
values k, k+1, k+2, and so on without limit. For example:
Chapter 9 Proofs
57
ssq=:+/@*:@i.@>:"0
ssq 5
55
Sum of squares of first 6 non-negative integers
ssq i.6
0 1 5 14 30 55
Using rational constants (such as 2r6 for 2%6), we then define a putative
equivalent function g, adopt the induction hypothesis that f n is equal to g n, and
use it to prove that f n+1 equals g n+1:
g=:(1r6&*)+(3r6&*@(^&2))+(2r6&*@(^&3))
ssq n+1
+/ *: i. >: n+1
(+/*:i.>:n)+(*:n+1)
(ssq n)+(*:n+1)
(g n)+(*:n+1)
Definition of ssq
(Sum of first terms) plus last term
Definition of ssq
Induction hypothesis
Definition of g
(1r6*n)+(3r6*n^2)+(2r6*n^3)+(*:n+1)
(1r6*n)+(3r6*n^2)+(2r6*n^3)+1+(2*n)+(n^2)
(1r6*n+1)+(3r6*(n+1)^2)+(2r6*(n+1)^3)
g n+1
Definition of g
The lines of the foregoing proof that are not annotated concern the use of
manipulations from elementary algebra, including the expansion of the square and
the cube of the sum n+1. The inductive proof may now be completed by showing
that the functions are equal for the argument 0.
Exercises
8. Enter n=:6, and then enter the lines of the foregoing proof to verify that they
each give the same result. It is advisable to enter such a sequence in a “text”
or “script” file, then execute it, observe the result, and return to the script file
to correct any errors and re-try. To open the script file, hold down the control
key and press n; to execute it, hold down both the control and shift and press
w; to see the result, switch to the execute window by holding down control
and pressing the tab key; return to the script window by the same action.
9. Define the function s=: +/@:i.@>: and an equivalent function t that does
not use summation. Give an inductive proof that they are equivalent.
A recursive definition of a function f provides a clear statement of the value of
f n+1 in terms of the value of f n; this fact is obviously valuable in the
construction of an inductive proof.
But how does one find a function such as g? This matter will be treated in Chapter
14. But for present use in further experiments with inductive proofs, we provide
the following methods.
The function g is an example of a polynomial, a sum of weighted powers of the
argument, the weights being 0 1r6 3r6 2r6. They may be obtained as follows:
]w=: (ssq a) %. a ^/ a=: i.5
58
Exploring Math
_2.99066e_14 0.1666667 0.5 0.3333333 _6.50591e_14
6*w
_1.7944e_13 1 3 2 _3.90354e_13
Because %. (matrix divide) produces its results by approximation, the extreme
items of 6*w are not quite zero. They can be “zeroed” by the following function,
in which the first argument specifies the tolerance in number of decimal digits:
ZERO=: ] * |@] > 10&^@-@[
8 ZERO 6*w
0 1 3 2 0
14 ZERO 6*w
_1.7944e_13 1 3 2 _3.91687e_13
For convenience in experimenting with a variety of functions, we will adopt from
Section F of Chapter 14 the conjunction FIT, so defined that n FIT f x gives the
n-item list of coefficients of a polynomial that best fits the function f at the points
x. For example:
V=:] ^/ i.@[
FIT=:2 : 'y. %. (x. & V)'
3 FIT ^
^ %. 3&V
]c=:3 FIT ^ b=:0.2*i.5
1.00238 0.9203119 0.7569838
c p. b
1.00238 1.21672 1.49162 1.82708 2.2231
^ b
1 1.2214 1.49182 1.82212 2.22554
As remarked, g is an example of a polynomial, and the coefficients produced by
FIT can (preferably after being zeroed) be used with the polynomial function p.
to produce an equivalent function. Thus:
]c=: 8 ZERO 4 FIT ssq a=:i.5
0 0.1666667 0.5 0.3333333 0
c p. i.8
0 1 5 14 30 55 91 140
g i. 8
0 1 5 14 30 55 91 140
Exercises
Chapter 9 Proofs
59
10. Study the discussion of proofs in Section D of Chapter 5 of Book 2.
11. Find a function equivalent to the sum of cubes, and construct an inductive
proof of the equivalence.
[]c=: 8 ZERO 5 FIT scubes x=:i.6]
12. For many functions, the coefficients for an equivalent or approximate
polynomial may be conveniently obtained by using the Taylor adverb t., as in
f t. i.6. Experiment with this for the functions:
]
(^&4-^&2)
^&4
(>:^4:)
(<:^4:) ^
61
Chapter
10
Tools
Without tools he is nothing,
with tools he is all
Carlyle
A. Introduction
This chapter concerns tools for exploration. They are fully treated in Burke’s J
User Manual (available on-line under the help menu in the J system), but should
themselves be explored in the manner used for math in preceding chapters.
For example, an overall view of the tools available may be obtained by dropping
the menus. This can be done by clicking the mouse on each of them, but they can
also be dropped by first pressing the alt key, then the down arrow, then the left or
right arrow to move over the menus. The alt key will roll up a menu.
With a menu dropped, use the up and down arrows to select an item, and press
enter to execute it. Alternatively, an underscored letter in an item can be entered
to execute it. Some menu items can be invoked directly (without dropping the
menu) by pressing a key (usually while holding down the control key), as
indicated to the right of the item’s name.
For example, (as shown in the help menu), the F1 key may be pressed to display
the J vocabulary, and any entry in the vocabulary may be chosen for display by
double-clicking on it with the mouse. A definition is then displayed, and may also
be printed by using Print topic in the file menu.
Exercises
1. Using items from the help menu, display and read various pages from the User
Manual, including Chapter 1.
2. Display and read a few sections from the introduction to the J dictionary
3. Read the section on grammar in the J dictionary.
62
Exploring Math
B. Editing
As remarked in Chapter 1, a previously entered line can be brought to the input
area for editing and re-entry by moving the cursor up to it and pressing enter.
Moreover, a line containing any phrase can be found by pressing Control f to
highlight the search entry box, entering the phrase in it, and pressing enter.
Repeated searches on the same phrase will find successive occurrences of it.
Pressing Control d drops a menu of previous entries; one may be selected for use
by pressing the up arrow.
C. Script Windows
Enter Control n to open a script window, enter one or more J sentences in it, and
press Control-Shift w to execute the sentences. The execution occurs in the
execution window, and can be viewed by entering Control Tab to switch back to
it.
A window may be saved as a file (under the name shown on the window) by
pressing Control s, and can be re-opened at any time by pressing Control o. It can
also be saved under any chosen name by using Save As or Save Copy As from the
file menu.
Select the item Session Manager from the User Manual, and from it select the
item Script Windows. Read the discussion of their use.
Exercises
63
Chapter
11
Coordinates and Visualization
It was their belief that, if they stared long enough at these
mystic curves and angles, red ink would turn into black.
Alva Johnson
A. Introduction
Take a sheet of graph or squared paper (ruled with equidistant vertical and
horizontal lines), choose some point of intersection as the origin to be labelled
0 0, and label vertical lines from left to right and horizontal lines from bottom to
top with symmetric integers as follows:
i: 9
_9 _8 _7 _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 7 8 9
Any point of intersection may then be labelled by two coordinates, the first (or x)
coordinate specifying the vertical line through it, and the second (or y) coordinate
the horizontal. Such a coordinate system makes it possible to describe geometric
figures, and leads to analytic or coordinate geometry. For example:
p=:3 4
q=:9 4
r=:6 8
s=:9 7
t=:8 6.
is=:p,q,:r
rt=:p,q,:s
qd=:p,q,s,:r
pg=:p,q,s,r,:t
A single point
Isosceles triangle
Right (-angled) triangle
Quadrilateral
Pentagon
Properties of the geometric figures can be obtained from their coordinate
representations. For example:
disp=:1&|. - ]
Rotate by 1 and subtract
64
Exploring Math
disp is
6 0
_3 4
_3 _4
length=:+/&.*:"1
length p
5
length disp is
6 5 5
Displacements from vertex to vertex
Length according to Pythagoras
Length or distance from origin
Lengths of sides of isosceles triangle
heron=:%:@(*/@:(semip,semip-])) Heron’s formula for area
semip=: 2:%~+/
heron length disp rt
9
Semi-perimeter
Area of the right triangle
area=:heron@:length@:disp
area rt
9
Area function using Heron
area is
12
Area of the isosceles triangle
Exercises
1. Plot the points p through t on graph paper, and join the appropriate points by
straight lines to show the figures is through pg . Then use the base and
altitude of each triangle to compute their areas, and compare with the results
of Heron’s formula.
2. Use the AHD[6] to examine the etymology of the several terms used for
figures that differ only in the number of their sides (or angles or vertices), and
suggest a compact common terminology.
[3-gon, 4-gon, and n-gon (from polygon)]
3. A vertex may be shifted to the left by subtracting a vector with a zero final
element. Plot the following triangles, and use both base-times-altitude and
Heron’s formula to compute their areas:
rts=:p,q,:r-8 0
is=:p,q,:s-8 0
Although plotting polygons by hand may be instructive, it is also convenient to
use the computer to plot them. We begin by normalizing the coordinates of a
figure:
• sliding them to bring the lowest point to 0 0
• sizing them to no more than 1 in magnitude
• doubling and subtracting 1 to bring them between _1 and 1
•
ravelling them to form a list for use by the plotting function
slide=:] -"1 <./
size=:] %"1 >./
scale=:,@(<:@+:@size@slide)
slide is
Chapter 11 Coordinates and Visualization
65
0 0
6 0
3 4
size slide is
0 0
1 0
0.5 1
<: +: size slide is
_1 _1
1 _1
0 1
scale is
_1 _1 1 _1 0 1
The following steps introduced the necessary graphing functions, and use them to
display the isosceles triangle:
load 'graph'
gdopen'a' Opens graph window labeled 'a'. Use mouse to return focus
to J
gdpolygon scale is
gdshow''
We then superpose a red right triangle and, finally, clear the window:
255 0 0 gdpolygon scale rt Colors red, green, blue; intensity 0-255
gdshow''
gclear 'a'
A graphics window may be closed by clicking the upper right corner with the
mouse.
The functions provided by the graphics file may be displayed by entering
names_z_'' . However, they should for the moment be treated as tools, whose
internal workings may be ignored provided that their effects are sufficiently
understood.
It will be found most convenient to enter a sequence of graphics commands in a
script window (opened by entering Control n), and to execute them by using the
drop-down run menu.
66
Exploring Math
To learn more about the use of graphics, use the mouse to drop the Studio menu
in J, then click on Labs, and then on Graph Utilities.
Exercises
4. Enter the foregoing sequence of graphics sentences in a script window, and
use the “Selection” option from the run menu to execute it.
5. Display each of the polygons defined in this section in various colors; in
particular, display rt in red and (without clearing the window) -:is in green.
6. Permute the coordinates of the polygons (as in 1 A. pg), and discuss the
appearance of the resulting figures.
7. Enter rot=:^@j.@rfd@[*], and rfd=:%&180p_1, and experiment with rot by
plotting the results of the following forms:
45 rot rt
45&rot&.> rt;is;rts
8. Experiment with, and comment on, the function rotate introduced by the
graphics file.
B. Visualization
The examples of Section A illustrate the fact that the coordinate representation
and the graphic representation of figures are complementary; each provides
certain advantages. For example, the graph of Exercise 6 shows how easy it is to
distinguish an “improper” polygon (in which sides cross), a matter that would not
be easy to spot in a table of coordinates.
On the other hand, for the computation of properties such as areas, coordinates
are far superior. For the particular triangles rt and is (and even for rts and iss
plotted by hand in Exercise 3) the computation of area appears simple, but this
simplicity is deceptive, as illustrated by the rotated figure of rts in Exercise 7.
Moreover, the determinant function provides an even simpler statement of area
than does Heron’s formula, and yields additional important information. Thus:
det=:-/ . *
rt,"1 (0.5)
3 4 0.5
9 4 0.5
9 7 0.5
det rt,"1 (0.5)
9
det (1 A. rt),"1 (0.5)
_9
AREA=:det@(,"1&0.5)
AREA rt
9
Exercises
Chapter 11 Coordinates and Visualization
67
9. If you are familiar with the computation of determinants from high school,
check the foregoing results by hand.
10. The result of AREA is positive if the coordinates are in counter-clockwise order
(when plotted), and are negative if clockwise. Test this for various triangles.
11. What is the significance of a zero result from AREA?
12. Enter t=:?.7 2$10 to generate a random table of seven points. Referring to
these points by the letters A through G, determine which of the last five lie on
opposite sides of the line determined by the first two.
[Enter L=:0 1 { t, and compare signs of
the areas of the triangles C,L and D,L, etc.]
13. Compute the area of the pentagon pg of Section A.
[Referring to the points by A-E, compute the three (signed)
areas A,B,:C and A,C,:D and A,D,:E and add them]
C. Plotting Multiple Figures
As illustrated by Exercise 4, different figures may be displayed together.
However, as seen from the same exercise, they are scaled independently, and
therefore do not give a satisfactory picture.
We will now rectify this by developing functions that will handle arguments of
the form rt;is;pg, and scale the whole according to the requirements of the
entire collection. It suffices to modify the functions slide, size, and scale so as
to apply to each box (that is, under (&.) open (>)), and to find the maxima and
minima after razing the argument (by applying ;). Thus:
SLIDE=:] -"1&.> <@(<./@;)
SIZE=:] %"1&.> <@(>./@;)
SCALE=:,&.>@(<:@+:&.>@SIZE@SLIDE)
We may then proceed with experiments such as the following (which plots the isosceles
triangle together with the right-triangle displaced two places up and to the right:
POLY=:gdpolygon&>
color=:0 255 0;255 0 0
gdopen''
color POLY SCALE is;2+rt
gdshow''
14. Experiment with the plotting of multiple figures, using expressions of the
form:
Exercises
(255 0 0;0 0 255) POLY SCALE rt;pg
15. Enter SCALE