Hanzi as notation

Read mathematical relationships through meaningful Chinese characters.

Kenneth Iverson wanted notation to help us see relationships and discover mathematics. In Notation as a Tool of Thought, he argued for a language in which useful ways of combining calculations could become familiar written forms. BPL continues that experiment in the array-language tradition he founded with APL.

Chinese offers a distinctive fit. A character can carry a mathematical meaning in a compact written unit. Characters placed after a verb can modify how an action is performed. Readers find meaningful units within uninterrupted runs of characters every day. We can draw on those habits when writing executable mathematics.

The examples assume BPL’s basic notation. Start with the quick introduction for the language itself. Here we concentrate on what Chinese spellings contribute.

Enable Hanzi glyph spellings for this session before running the examples:

•prefs ["hanzi_aliases":$t]

Consider a definition using 是 (shì, “is”), 加 (jiā, “add”), 总 (zǒng, “total”), 除 (chú, “divide”) and 数 (shǔ, “count”):

mean是加总除数
mean 2 4 9
5

“Mean is total divided by count.” The definition states the mathematical relationship in one uninterrupted expression. Chinese readers are accustomed to recognizing meaningful combinations without spaces between words. That familiarity is useful even though mean is an English name and the complete definition follows BPL grammar.

The arithmetic is familiar. We total the values and divide by how many there are. We will return to this definition after looking at how a few characters work together.

Reuse a meaning in new combinations

加 names addition. 乘 (chéng) names multiplication. Both have familiar meanings before we encounter them in a program.

2加3
2乘3
5
6

In 加总, the two characters suggest adding into a total. Replacing 加 with 乘 keeps the same way of combining the values but uses multiplication. We can understand 乘总 from pieces we already know.

加总 2 3 4
乘总 2 3 4
9
24

累 (lěi) suggests accumulation. 加累 keeps the successive sums, and 乘累 keeps the successive products.

加累 2 3 4
乘累 2 3 4
2 5 9
2 6 24

Everyday Chinese writes 累加 and 累乘 with the accumulation character first. BPL puts 累 after the operation, consistently with its other modifiers. The meanings are recognizable even where the formal order differs from ordinary language.

上 (shàng, “upper”) chooses the larger value. 上累 expresses a running maximum with the same accumulation character.

上累 3 1 4 2
3 3 4 4

A naturally postfix modifier

遍 (biàn) appears after verbs in Chinese to suggest doing something throughout a collection. 看遍 (kàn biàn), for example, suggests looking through everything. That postfix position fits BPL’s Each operator particularly well.

For these two groups, 数遍 counts each group and 加总遍 totals each group.

groups是[[1 2] [3 4 5]]
数遍groups
加总遍groups
[2 3]ₓ
3 12

总 and 遍 express different relationships. 总 combines within each group; 遍 applies the calculation throughout the collection of groups. 加总遍 keeps both relationships visible in three characters. We have learned reusable modifiers rather than separate names for “sum each”, “count each” and their many relatives.

Make the mathematics visible

己 (jǐ) refers to oneself. 乘己, with one argument, multiplies that argument by itself. The sum of squares is 加总乘己. Squaring remains visible alongside totaling.

乘己 1 2 3
加总乘己 1 2 3
1 4 9
14

Our opening definition, mean是加总除数, preserves another familiar relationship:

[ (x)=. ]

The total and count describe the same data. Division connects them. Naming the function does not hide the relationship behind a sequence of updates or a loop.

Compare products without hiding multiplication

Ordinary multiplication pairs corresponding values. 表 (biǎo, “table”) instead suggests every pairing in a table.

a是1 2 3
b是4 5 6
a乘b
a乘表b
4 10 18
 4  5  6
 8 10 12
12 15 18

内 (nèi, “inner”) comes from the mathematical term 内积 (nèijī, “inner product”). In 加内乘, multiplication forms paired products and addition combines them. Compare that expression with totaling the ordinary products.

加总 a乘b
a 加内乘 b
32
32

The same multiplication appears in elementwise, outer and inner products. The surrounding characters state what changes about the calculation. In particular, 加内乘 shows the two operations that define a dot product instead of giving the whole calculation an unrelated name.

With 至 (zhì, “to”) for an inclusive range, we can write the familiar multiplication table as 乘表己至9. The characters suggest multiplication, a table and pairing with itself.

乘表己至9
1  2  3  4  5  6  7  8  9
2  4  6  8 10 12 14 16 18
3  6  9 12 15 18 21 24 27
4  8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81

Familiar meanings, precise conventions

Hanzi spellings can be mixed with APL glyphs. These expressions use the same addition and totaling operations.

+/ 2 3 4
加/ 2 3 4
加总 2 3 4
9
9
9

Each Hanzi spelling names a complete existing BPL glyph, including its one- and two-argument meanings. A single character is preferred where it can suggest both meanings or the more common use. Some combinations resemble ordinary Chinese closely; others rely on mathematical convention. Ordinary punctuation remains available, including . for record fields.

Iverson’s goal was to make productive mathematical relationships easy to write, recognize and reuse. Chinese supplies familiar meanings at the level of individual characters and familiar habits for combining them. Once 总, 累 and 遍 are understood, readers can recognize the same structures in calculations they have never seen before.