Teaching with an Executable Notation
Vector 11:4, page 76
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 76
This paper concerns the use in teaching of a mathematical notation (or language) that is not only effective in analysis and exposition, but is also directly executable on small computers. Because the language is executable, the computer can be used to explore and elucidate topics with a clarity that can only be appreciated from direct experience of its use.
One mark of an effective teacher of mathematics (or of the use of mathematics in related fields) is a propensity to formulate any problem in mathematical language, and to conduct further analysis and exposition in that language. The ability to do this requires mastery of the language of an order different from that required for passive reading, or even from writing (or developing procedures or programs) in a specific topic.
Such mastery is gained from repeated attempts to use the language in this way in a variety of topics, and from digressions to explore the language itself under the stimulus of new problems. This suggests that anyone wishing to use a new language in exposition might approach learning it in a manner different from that appropriate to the more casual reader or writer.
This paper is an attempt to provide such an introduction to the executable mathematical language J. It proceeds by developing some topic in the language; then digresses to explore some new language entity encountered, using it in one or more topics, and thereby returning again to the thread of some topic.
It is organized by sections that begin by using the language to explore some thread, and includes series of exercises. The reader is urged to treat these exercises in four passes:
- Study the given sentences and results.
- Enter the sentences on the computer and experiment with related sentences that might throw light on the matter.
- Study the J dictionary [1] or other references suggested in the questions.
- Read the answers and discussions provided in Appendix A.
A. The Elements of J¶
The examples in this section introduce all major aspects of J, that is, all of the parts of speech:
10+1.5
11.5
price=.10 NB. price is 10 (use of copula)
markup=. 1.5
price+markup NB. Verb with pronouns
11.5
prices=. 10 NB. Collective noun
markups=. 1.5 1 3.75
p=. prices [ m=. markups
p+m NB. Convenience of short names
11.5 7 28.75
+/m
6.25
sum=. +/
sum m
6.25
p^3
1000 216 15625
cube=. ^&3
cube p
1000 216 15625
(10^2)+(3^3) NB. Use of parentheses
127
x=. 0 1 2 3 4
(1+(2*x)+(x^2)) = ((x+1)^2) NB. Identity
1 1 1 1 1
pi=. 3.14159
A.1 Explain the use of the abbreviation NB.
A.2 The grammatical terms (such as pronoun, verb, and part of speech) used here are from English. State the corresponding terms used in maths.
A.3 State the effect of the slash (as in +/m). Also state the name given to such an entity in maths, and suggest a corresponding term suitable to J.
A.4 Repeat Ex. A.3 for &.
A.5 Repeat Ex. A.3 for the parentheses.
A.6 State the purpose of [.
B. Elementary Functions¶
The phrase elementary functions is commonly used to refer to a loosely-defined collection of functions that includes at least the trigonometric functions, the exponential, the square, and the square root. They are elementary in two senses:
They are rather easily defined (or approximated) in terms of addition, multiplication, and integer powers.
They serve as "building blocks" to define a wide variety of functions and computational procedures needed in applied mathematics.
These elementary functions are all both monadic (applying to a single argument) and scalar (applying to a single element). We will extend the notion in two ways. Firstly, because of the convenience provided by collectives (lists, tables, and higher-rank arrays), we will include verbs that generate and manipulate arrays:
a=. i. 4 [ b=. i. 3 4
square=. ^&2
sqrt=. ^&0.5
square a
0 1 4 9
sqrt b
0 1 1.41421 1.73205
2 2.23607 2.44949 2.64575
2.82843 3 3.16228 3.31662
exp=. 2.71828&^
exp a
1 2.71828 7.38905 20.0855
sine=. 1&o.
cos=. 2&o.
((square@sine) + (square@cos)) a
1 1 1 1
|. b
|: b
B.1 Annotate the preceding sentences, stating clearly what each of the verbs do. Note that the results of the last two sentences are not shown, but may be obtained by entering all on a computer.
B.2 Experiment with other members of the family of verbs obtained by bonding left arguments (such as 0 through 7) to the dyad o. and state the function performed by each. Also state the mnemonic scheme used in assigning the "codes" used in the left arguments.
Secondly, we include dyadic functions (such as addition, subtraction, multiplication, and division) that are also essential building blocks. Just as addition and multiplication tables prove useful in displaying interesting properties of those functions in elementary arithmetic, so do corresponding verb tables illuminate more general dyadic functions. In what follows, some of the results are not shown, but can be obtained by using the computer:
a=. 2 3 5 [ b=. 0 1 2 3
a */ b
0 2 4 6
0 3 6 9
0 5 10 15
b %/ b
0 0 0 0
_ 1 0.5 0.333333 NB. The symbol _ denotes infinity
_ 2 1 0.666667
_ 3 1.5 1
b !/ b
1 1 1 1
0 1 2 3
0 0 1 3
0 0 0 1
over=. ({.;}.)@":@,
by=. ' '&;@,.@[,.]
a by b over a */ b
┌─┬─────────┐
│ │0 1 2 3│
├─┼─────────┤
│2│0 2 4 6│
│3│0 3 6 9│
│5│0 5 10 15│
└─┴─────────┘
tba=. 1 :'[by]over x. /'
a * tba b
┌─┬─────────┐
│ │0 1 2 3│
├─┼─────────┤
│2│0 2 4 6│
│3│0 3 6 9│
│5│0 5 10 15│
└─┴─────────┘
t=. tba
b ! b
(i.10) !t (i.10)
b -t b
b ^t b
B.3 Annotate the preceding sentences.
B.4 Enter s=. ( i. 9) - 4 to obtain a list of integers symmetric about zero, and use it instead of a and b in the preceding sentences to explore the resulting verb tables.
B.5 Use the format function in expressions such as 8.3 ": b%/b to produce a more readable division table.
A verb applied to two arguments is said to be dyadic or to have valence 2, and a verb applied to a single argument is monadic with valence 1. The minus sign used in mathematics is ambivalent, representing the dyad subtraction when supplied with two arguments, and the monad negation when supplied with one.
In J such ambivalence is extended to all verbs, the applied valence of any verb being determined by context. For example:
x=. 2 3 5 7
y=. 0 1 2 3
x-y
2 2 3 4
-y
0 _1 _2 _3
x%y
_ 3 2.5 2.33333
%y
_ 1 0.5 0.333333
x^y
1 3 25 343
^y
1 2.71828 7.38906 20.0855
+/y
6
x+/y
2 3 4 5
3 4 5 6
5 6 7 8
7 8 9 10
3|.y
3 0 1 2
|.y
3 2 1 0
x<y
0 0 0 0
<y
┌───────┐
│0 1 2 3│
└───────┘
(< 1 0 2 |: i.2 3 4), (< |: i.2 3 4)
┌───────────┬─────┐
│ 0 1 2 3│ 0 12│
│12 13 14 15│ 4 16│
│ │ 8 20│
│ 4 5 6 7│ │
│16 17 18 19│ 1 13│
│ │ 5 17│
│ 8 9 10 11│ 9 21│
│20 21 22 23│ │
│ │ 2 14│
│ │ 6 18│
│ │10 22│
│ │ │
│ │ 3 15│
│ │ 7 19│
│ │11 23│
└───────────┴─────┘
B.6 Annotate the preceding sentences.
B.7 Explore relations between other monads and dyads.
C. Tables and Rank¶
The verb tables of the preceding section are said to be of rank two, and to have two axes. Each row of such a table is a list (of rank 1), and each element of the list is an atom (of rank 0). More generally, an array of higher rank (such as the rank 4 array produced by i. 2 3 4 5) "contains" cells of lower rank.
The rank conjunction (denoted by ") constrains a verb to apply to each cell of specified rank. For example:
]a=. i. 2 3 4
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
+/"1 a
6 22 38
54 70 86
mean=. +/ % #
mean 2 3 4 5
3.5
+/a
12 14 16 18
20 22 24 26
28 30 32 34
+/"2 a
12 15 18 21
48 51 54 57
(mean a);(mean"2 a);(mean"1 a)
┌───────────┬───────────┬──────────────┐
│ 6 7 8 9│ 4 5 6 7│ 1.5 5.5 9.5│
│10 11 12 13│16 17 18 19│13.5 17.5 21.5│
│14 15 16 17│ │ │
└───────────┴───────────┴──────────────┘
Functions of ranks 0 and 1 are also called scalar and vector functions, respectively.
C.1 Annotate the preceding sentences.
C.2 The monad , ravels its argument. Experiment with ravels of various ranks.
C.3 Experiment with box (<) of various ranks.
The rank conjunction can be used to specify the ranks of each argument of a dyad. For example:
]b=. 0{a
0 1 2 3
4 5 6 7
8 9 10 11
3 4 5 *"0 1 b
0 3 6 9
16 20 24 28
40 45 50 55
2 3 5 7 *"1 1 b
0 3 10 21
8 15 30 49
16 27 50 77
]c=. 3 4 $'abcdefghijkl'
abcd
efgh
ijkl
'ABC' ,"0 1 c
Aabcd
Befgh
Cijkl
C.4 Annotate the preceding sentences.
C.5 Consult the definition of the rank conjunction in the dictionary, and experiment with further uses of it.
D. Writing¶
Anyone wishing to use a new language well should make early attempts at writing on some topic of interest. Because of limited knowledge of the language this may prove frustrating and seemingly fruitless. Nevertheless, it should be attempted: even failed attempts will alert a student to facilities in the language whose significance would otherwise be missed.
For example, a student attempting to produce subtotals (partial sums) in a treatment of accounting might happen upon the prefix adverb:
receipts=. 3 1 4 2 7 6
sum=. +/
sum receipts
23
sum \ receipts
3 4 8 10 17 23
scan=. \
max=. >./
max scan receipts
3 3 4 4 7 7
< scan receipts
┌─┬───┬─────┬───────┬─────────┬───────────┐
│3│3 1│3 1 4│3 1 4 2│3 1 4 2 7│3 1 4 2 7 6│
└─┴───┴─────┴───────┴─────────┴───────────┘
As a consequence the student would be alerted to, and perhaps explore, related partitions such as \. and /.. Later attempts at treating polynomials might lead to the table c*/d for the product of all pairs of elements of the coefficient lists c and d as a first step in computing the coefficients of the product polynomial, and finally, to the need for diagonal sums of the table:
c=. 1 2 1 [ d=. 1 3 3 1
c*/d
1 3 3 1
2 6 6 2
1 3 3 1
sum/.c*/d
1 5 10 10 5 1
</.c*/d
┌─┬───┬─────┬─────┬───┬─┐
│1│3 2│3 6 1│1 6 3│2 3│1│
└─┴───┴─────┴─────┴───┴─┘
Beginning attempts at writing should begin at the beginning of a topic, not in medias res. Moreover, it is well to choose topics which themselves enjoy wide application, For example:
Calculus · Difference Calculus · Linear Functions · Polynomials · Classification and sets · Directed Graphs · Permutations
Introductory treatments of these topics are presented in the Dictionary of J.
D.1 Annotate the J sentences in this section.
E. Properties of Functions¶
The terms distributivity, commutativity, and associativity are used in maths to describe properties of scalar dyadic functions. We will use them in the same way, but will extend the notion of distributivity to the distribution of a monadic function over a dyad, and will introduce the terms uniformity and symmetry to cover important properties of functions of higher rank.
It is commonly said that the dyad * distributes over addition because:
This relation might also be expressed by saying that the monad a&* (or the monad *&c) distributes over addition:
In the case of a non-commutative dyad such as division (%), the statements in terms of the monads a&% and %&c are to be preferred over a statement about the dyad %, since one of them distributes over addition and the other does not.
E.1 Enter a=. 3 1 2 4 [ b=. 2 3 5 7 [ c=. 4 3 2 1 and experiment to determine the distributivity over both addition and subtraction of the following monads:
E.2 Test the distributivity of the incrementation a&+ over maximum (>.) and the distributivity of the minimum a&<. over maximum. The commute or cross adverb ~ reverses the sense of its verb argument. For example:
Consequently, a test for the commutativity of a function f may be written as f=f~. For example:
E.3 State a characteristic common to the verb tables of all commutative functions.
E.4 Enter the following sentences, and comment on the differing behaviours of the function + (which is associative), and - (which is not):
b=. 1 0 0 1 0 1 0 0
x=. 1 2 3 4 5 6 7 8
b <;.1 x
┌─────┬───┬─────┐
│1 2 3│4 5│6 7 8│
└─────┴───┴─────┘
(b +/;.1 x);(+/b+/;.1 x);(+/x)
┌──────┬──┬──┐
│6 9 21│36│36│
└──────┴──┴──┘
(b -/;.1 x);(-/b-/;.1 x);(-/x)
┌──────┬──┬──┐
│2 _1 7│10│_4│
└──────┴──┴──┘
A function f is uniform if the shape of its result agrees with the shape of its argument, i.e., if g=. $ -: $@f is a tautology (true for any argument).
A monadic vector function is said to be symmetric if it yields the same result when applied to any permutation of its argument. For example:
]a=. 3 A. b=. 2 3 5 7 11
2 3 7 11 5
(+/a);(+/b)
┌──┬──┐
│28│28│
└──┴──┘
(-/a);(-/b)
┌─┬─┐
│0│8│
└─┴─┘
The final result illustrates the fact that -/ (the alternating sum) is not symmetric. A monad f/ is symmetric if and only if the dyad is both associative and commutative.
Chapter 2 of Arithmetic [2] provides discussion of further properties of verbs, including inverses and identity elements. Make and experiment with expressions to illustrate these notions.
E.5 Enter the following sentences, and comment on the results:
E.6 Enter the following sentences and comment:
E.7 Enter and comment upon:
F. Proofs¶
The results of:
might suggest that the sum of the first n odd numbers equals the square of n, and the following use of the prefix scan adverb would tend to confirm the conjecture:
Insight into why the relation holds for any n can be provided by a sequence of equivalent sentences that differ in simple steps:
Such a sequence constitutes an informal proof that the last sentence is equivalent to the first, a proof that can be made formal by annotations that state why each sentence is equivalent to the one that precedes it. For example:
+/odds
+/|.odds Summation is symmetric
+/(odds+|.odds)%2 Sum of equals divided by 2
+/(n # 2*n)%2 n copies of the sum 2*n
+/n#n 2*n divided by 2 is n
n*n Definition of times in terms of addition
Inductive proofs may be written similarly, by stating and using an inductive hypothesis. For example:
The assumption that the hypothesis is true for some value of n is first used to prove that it must then be true for n+1. Finally, it is shown to be true for some value of n; in the present instance, when n=.1 the value of +/1 clearly equals 1^2. Thus:
+/1+2*i.n+1
(+/1+2*i.n)+(1+2*n) Addition is associative
(n^2)+(1+2*n) Induction hypothesis
(n^2)+(2*n)+1 Addition is commutative
(n+1)^2 Expansion of square
F.1 Enter the following sentences and prove the identity that they suggest:
We conclude with a somewhat longer proof of the associativity of the matrix product. The matrix product is a collection of sums of products, and we begin with its definition in terms of the dot conjunction (which provides a range of useful "dot products" based on functions other than sum and product):
The dot conjunction is itself defined (in [1]) as follows:
For the present case of ordinary matrix product on matrices, v is *, and (since its left rank lv is zero) this simplifies to u@(*"1 _), thus applying multiplication by each row vector of the left argument to the entire right argument. The effect is to weight each row of the right argument by the corresponding element of a given row of the left argument before applying summation (u=. +/) over the weighted result. For example:
t=. *"1 _
s=. +/"2
q=. 4+r=. i. 2 2
q;r;(q t r);(s q t r);(q mp r)
┌───┬───┬─────┬─────┬─────┐
│4 5│0 1│ 0 4│10 19│10 19│
│6 7│2 3│10 15│14 27│14 27│
│ │ │ │ │ │
│ │ │ 0 6│ │ │
│ │ │14 21│ │ │
└───┴───┴─────┴─────┴─────┘
We will first illustrate the fact that mp is associative:
p=. 4+q
p;q;r;((p mp q) mp r); (p mp (q mp r))
┌─────┬───┬───┬───────┬───────┐
│ 8 9│4 5│0 1│206 395│206 395│
│10 11│6 7│2 3│254 487│254 487│
└─────┴───┴───┴───────┴───────┘
and then show a sequence of simple transitions from (p mp q) mp r to p mp (q mp r), displaying the explicit results for only the first two sentences:
(pmp q) mp r
206 395
254 487
(s p t q) mp r
206 395
254 487
s (s p t q) t r
s s (p t q) t
s s p t (q t r)
s p t (s q t r)
s p t (q mp r)
p mp (q mp r)
F.2 Annotate the foregoing informal proof.
G. Plan of Study¶
This introduction should be supplemented by treatments of various topics in the manner illustrated for linear functions in the succeeding chapter.
Because the main purpose is to learn to use executable notation in exposition, the reader is urged to approach each topic in the following steps:
- Read the English language statement of the matter to be addressed.
- Before reading further, attempt to treat the matter in whatever language is most congenial; if this is not J, then translate your work to J and try it on the computer; if it is J, first experiment with the result and then translate to conventional maths to better appreciate notational questions.
- Read the further text and associated exercises and answers, and compare them with your own work.
[Ed: Chapter 2 to follow in Vector 12.1.]
Appendix A: Answers to Chapter 1¶
A.1 The abbreviation NB. (nota bene) precedes a comment, which is ignored in J.
A.2 In maths a pronoun such as x is called a variable to emphasize that in a sentence that expresses an identity or other relation the relation holds for any value assigned to x, that is, when x changes or varies.
This terminology is used even when it is clear that the name (such as pi in the final sentence) is not expected to vary but to remain constant. The term variable is particularly inappropriate for a name such as sum used as a proverb.
In maths the terms function (from the past participle of the Latin fungi, to perform) and operator are used in the sense that verb is used in J.
Since formal grammatical rules are not imposed on sentences in maths, there appears to be no analogue to the phrase part of speech.
A.3 The slash applies to a verb (such as + or *) to produce a related verb (such as sum or product over), and therefore acts like an adverb in English. In maths it would be called a functional or operator (a usage that conflicts with the use of operator as a synonym for function).
A.4 The & is an example of a conjunction. In the phrase ^&3 it "joins" the verb ^ (power) to the right argument 3 to produce the verb to be called cube.
In a phrase such as -&| it acts like the copulative conjunction and in English to define a verb as a sequence of actions (as in run and hide), in this case subtraction of the magnitudes of the arguments. Enter the following sentences on the computer:
A.5 Parentheses are used in J as they are in maths, to prescribe the order of execution of a sentence; they are analogous to punctuation in English. See the discussion of punctuation on page 5 of the dictionary of J. Note particularly the discussion of the fork, and experiment with its use.
A.6 The verb denoted by the left bracket is called left, and yields its left argument. In its use above it serves to unite two sentences in a single sentence and might be pronounced as and, as in "p is prices and m is markups".
B.1 The verb i. produces lists, tables, and higher-rank arrays of successive integers. The verb |. reverses the order of the items or major cells of an array, and |: (called transpose) reverses the order of the axes of its argument. See Section II.A of the dictionary.
B.2 Find the circle function (denoted by o.) in the vocabulary on the back cover of the dictionary, and use the indicated page number to find the table of circle functions. Note that the odd functions (sine, tangent, hyperbolic sine, and hyperbolic tangent) are encoded by odd integers, and the even functions by even integers. If you are not familiar with the notion of odd and even functions, find the conjunctions even and odd, and consult their definitions.
B.3 The verbs */ and %/ provide multiplication and division tables. Note that the entries for division by zero are all infinite (denoted by _).
The outof function ! yields binomial coefficients, and b!/b therefore yields Pascal’s triangle, completed by meaningful zeros.
The functions by and over provide a more readable display of verb tables. Their definitions must first be found (Look up by in the index of the dictionary) and entered in the computer. They should be treated as utility functions, for use rather than for immediate study.
The utility adverb tba is defined in terms of the verbs by and over, as shown on page 35 of the dictionary.
B.4 Note the symmetry (or skew-symmetry) of some of the tables resulting from s, as well as the interesting division into quadrants. Note particularly the results of 0^0 and 0%0 and 0!0.
Also note the useful extension of ! to negative arguments, an extension based on the gamma function.
B.5 Although the result of the format function appears like a numeric table, it is actually a table of characters. Confirm this by applying $ to determine its shape, and by trying to apply an arithmetic function (such as *:) to it. Also use do=. ". to produce a corresponding numeric table.
B.6 For mnemonic reasons, the monadic and dyadic cases of verbs are chosen so that they are related in some way, or so that their functions are suggested by the symbol used. Thus:
(-y) = (0-y)
(%y) = (1%y)
(^y) = (e^y) NB. Where e=. ^1 is Euler's number
+/y NB. plus over y
x+/y NB. plus over each pair
|.y NB. Reversal
3|.y NB. Rotation
<y NB. < squeezes into box
x<y NB. Narrow end to smaller
C.1 The items or major cells of an array are the cells of rank one less, and +/ "inserts" the function + between the items of the argument. Therefore +/ a adds the two 3 by 4 tables of a.
Since +/"2 applies to each of the rank 2 cells of a, it adds their items (that is, the rows) to produce a 2 by 4 result.
Similar remarks apply to the function mean. Since the semicolon boxes its left argument and catenates it with the right argument (first boxing it if it is simple) it can be used as illustrated to provide a compact display of several results.
E.2 Use both positive and negative values for a and for the arguments of the dyads.
E.3 They are symmetric about the diagonal, that is, t-: |:t.
E.4 -/b -/ ;. 1 x is equivalent to (1-2-3) - (4-5) - (6-7-8) which (because - is non-associative) does not equal -/x. Note that 1-2-3 is 1-(2-3). See Section IIE of the dictionary.
E.5 These expressions illustrate the use of the power conjunction to provide repeated application of its argument (or of its inverse if the right argument of the conjunction is negative). The first two functions are uniform, but the others are not.
E.6 Entry of a function alone (without an accompanying argument) displays the function itself, showing that the inverse of +: (double) is -: (halve), and that the inverse of ^ (exponential) is ^. (natural log). See 9!:3 of Appendix E of the dictionary for alternative forms of display.
E.7 The adverb b. yields certain basic properties of its argument, its inverse for the argument _1 and its ranks (in the order monadic, left, right) for the argument 0.
F.1 See Section D of Chapter 5 of Arithmetic [2].