Balanced Ternary
Quoth Donald Knuth: “Perhaps the prettiest number system of all is balanced ternary.”
Balanced ternary is a fascinating, non-standard positional number system. I’m assuming you’re familiar with positional number systems, like decimal and binary, and can recognize that 10base-2 = 2base-10. Ternary is base-3, so 10base-3 = 3base-10. Ternary uses 0, 1 and 2. Balanced ternary, on the other hand, uses -1, 0 and +1 (i.e., it’s “balanced” around zero). Other than that, it’s a positional system just like decimal, binary and ordinary ternary, with three as the base number.
This means balanced ternary can represent negative and positive numbers without using a separate minus sign. If we adopt + as shorthand for +1 and - as shorthand for -1, we get this system:
-++- 0 - 3^3 + 3^2 + 3 - 1 -16 -++0 0 - 3^3 + 3^2 + 3 -15 -+++ 0 - 3^3 + 3^2 + 3 + 1 -14 0--- 0 - 3^2 - 3 - 1 -13 0--0 0 - 3^2 - 3 -12 0--+ 0 - 3^2 - 3 + 1 -11 0-0- 0 - 3^2 - 1 -10 0-00 0 - 3^2 -9 0-0+ 0 - 3^2 + 1 -8 0-+- 0 - 3^2 + 3 - 1 -7 0-+0 0 - 3^2 + 3 -6 0-++ 0 - 3^2 + 3 + 1 -5 00-- 0 - 3 - 1 -4 00-0 0 - 3 -3 00-+ 0 - 3 + 1 -2 000- 0 - 1 -1 0000 0 0 000+ 1 1 00+- 3^1 - 1 2 00+0 3^1 3 00++ 3^1 + 1 4 0+-- 3^2 - 3^1 - 1 5 0+-0 3^2 - 3^1 6 0+-+ 3^2 - 3^1 + 1 7 0+0- 3^2 - 1 8 0+00 3^2 9 0+0+ 3^2 + 1 10 0++- 3^2 + 3 - 1 11 0++0 3^2 + 3 12 0+++ 3^2 + 3 + 1 13 +--- 3^3 - 3^2 - 3 - 1 14 +--0 3^3 - 3^2 - 3 15 +--+ 3^3 - 3^2 - 3 + 1 16
Counting in balanced ternary is actually kind of relaxing; I wrote the above table by hand, but I think it’s error-free. There are some neat things about this system, like the fact that there is no separate minus sign, yet we’re both below and above zero. From the above table, it looks like we can negate a number by inverting pluses and minuses, leaving zeroes alone. And I’m pretty sure that if I removed all the labels and didn’t tell you about balanced ternary, finding out what the sequence stands for and how it progresses would be a decent brain teaser.
Wikipedia has more: the leading non-zero digit is the sign of the entire number; comparing two numbers is as simple as starting with the most significant digit and comparing each digit until you find two digits that are different, which indicates whether one number is larger than, smaller than, or equal to the other; and rounding is the same as truncating, so you can just cut off the trits that you don’t want from the end of the number.
There was actually an experimental Soviet computer, Setun, that used balanced ternary.
Well, I thought it was neat.