Nanyan Numerals
December 26, 2020 12:00 pm
If you read the Ancient Chronicle, you’re sure to notice some special symbols in the chapter headings. The chapter number and title both include the Nanyan translation. Though it makes sense that the title is indecipherable, it may seem at first that the number is equally incomprehensible. However, I assure you there is a simple (well, simple in concept anyway) meaning to them.
(To make the numbers easy to render in this post, I’m using the symbols | O Θ to stand for the Nanyan symbols you’ll find in the books.)
If you try to work out the pattern yourself, you might find no discernable pattern at first:
1: |
2: O
3: O|
4: OΘ
5: OΘ|
6: OO|
7: OO||
8: OΘΘ
9: O|O|
10: OOΘ|
11: OOΘ||
12: OΘO|
13: OΘO||
14: OOO||
15: O|OΘ|
But here’s the trick: Each symbol stands for a sequence of numbers and operators in post-fix notation. (If you’re not familiar with post-fix notation, check out the Wikipedia entry.)
|: 1 + *
Θ: 2 *
O: 2
Simply substitute each symbol with its set from left to right. For example, 15 becomes:
2 1 + * 2 2 * 1 + *
The one special rule is if there are not two operands on the stack, just ignore the operator. Thus the sequence becomes:
2
2 1
2 1 + = 3
3 * (ignore operator without two operands)
3 2
3 2 2 * = 3 4
3 4 1
3 4 1 + = 3 5
3 5 * = 15
15 (Done!)
And there you have it.
To reverse this process and find the Nanyan numeral for a given integer, you need to factor the number recursively until you can represent everything with just the numbers 1 and 2.
For example, 15 factors to 3 * 5. Since we don’t have symbols for 3 and 5, we need to iterate. But 3 and 5 are prime. How do we factor them? Simply subtract 1 and factor again.
3 = 2 + 1
5 = 4 + 1 = 2 * 2 + 1
Then convert it to post-fix notation, using the sequences the from the symbols:
3 = 2 1 + *
5 = 2 2 * 1 + *
Now, if you place all the factors in ascending order, the math works out:
2 1 + * 2 2 * 1 + *
Then all we need to do is replace them with the right symbols:
(2) (1 + *) (2) (2 *) (1 + *)
O|OΘ|
The * at the end of the 1 + * handles multiplying primes together when there are more than one of them on the stack. If there’s only one on the stack, the * is ignored. When the factors are ordered this way, it just works.
One of the helpful side effects of this is that if you are trying to figure out the factorization of a prime number, you need only at the | (1 + *) to the end of the previous number. For example:
10: OOΘ| = 2 2 2 * 1 + *
11: OOΘ|| = 2 2 2 * 1 + * 1 + *
For 37, you need only add | to the end of 36:
36: OΘO|O| = 2 2 * 2 1 + * 2 1 + *
37: OΘO|O|| = 2 2 * 2 1 + * 2 1 + * 1 + *
Another interesting property of these numbers is that if you know the symbols for all the prime factors of a number, you need only put them together in ascending order:
33 = 3 * 11 = O|OOΘ|| = 2 1 + * 2 2 2 * 1 + * 1 + *
91 = 7 * 13 = OO||OΘO|| = 2 2 1 + * 1 + * 2 2 * 2 1 + * 1 + *
If you take the time to do the math, it works out perfectly. Just to be sure, when I was designing Nanyan numerals, I created a Python program that does these conversions, and with it I checked many, many numbers. The pattern is always the same.
I will detail more about the Python program on my author website, but for now, I’ll say that being a programmer is very helpful when it comes to these sorts of things. (I highly recommend learning how to code.)
And there you have it: a quick explanation of Nanyan Numerals. They are not the most practical way of writing numbers, but their purpose is not really mathematical but ornamental. There is just something elegant out of being able to represent every integer using only three symbols.
I hope you found this interesting. Happy coding!
Comments