Number bases for positional numerals

Before I embark on base three itself, let's start with a look at the smaller naturals and how they fare, as candidates for number base. Generally, the representation of numbers in positional notation involves picking a set of digits, each of which denotes one of the values modulo the number base; while these are typically the numbers from zero through one less than the number base, it's possible (with some limitations) to pick other values differing from each by multiples of the number base.

Base zero is silly: each integer is alone in its equivalence class mod 0, so you need infinitely many digits. All integers are equal mod 1, so we only get one digit. Any representation is then a sequence of instances of our one digit, each muliplied by power(position,1) = 1 and summed: so we get the digit times the representation's length as the number represented. Thus, using 1 as digit, we get the positive integers (if you can recognise when the empty string is present with this meaning, you can also represent the number zero to get the natural numbers). All things considered, neither of these number bases is much use.

Base two allows us the convenience of a non-empty representation of zero: namely as a digit. If we'd used it as such in base one, all representations would have been sequences of zeroes, representing zero: no others would have been representable. However, in higher bases, it proves hugely useful – it enables us to effectively skip a few positions in the digit-sequence used, without the digit used as spacing interfering in the value. We have two equivalence classes mod 2, and 0 is even, so the other digit must be odd. We'll then be able to represent any multiple of that digit, so (again) we naturally take 1 as our digit. This gives us the widely-used binary system: these digits are known as bits. One complication is that you need some out-of-band way to say when you want a negative value, and convention for representing them. The two's complement form is widely adopted for the latter, but the system dealing with the data still needs the out-of-band sign to tell them to read its data that way.

At home in Base Three

As in base two (and all higher), so also in base three, it's very convenient to select 0 as one of our digits: we then need digits equivalent to 1 and 2. A fairly conventional and easy solution is then to use {2,1,0} as digits. You might enjoy playing with that for a while. While 1 makes a winning candidate for its equivalence class, 2 is equivalent to −1 and there's some much nicer symmetry to {1, 0, −1}. This has the nice property of making truncation fair: zeroing the last few digits of a number (or all those, of a fraction's representation, past some point) changes as many numbers upwards as downwards. Using {0,1,2}, that introduces a systematic bias (averaging one in the first position discarded): but {1, 0, −1} avoids that bias. Base three gets called ternary and its digits (whether signed or conventional) get called trits, by analogy with binary's bits (binary digits).

Consider (in decimal) rounding 2.45 to the nearest .1 and to the nearest 1. The latter gives 2: the former gives 2.5. Rounding this last to the nearest 1, we get 3. If we'd started with 2.444445, with arbitrarily many 4s before the 5, and rounded successively at each position, we'd get to 2.45 on the way, and hence end at 3. This is, in fact, a general difficulty with an even base (even if signed). On the other hand, in an even base, we can always truncate to one digit short of where we want to round, and get the right result by rounding that truncated form (because half has a digit to represent it exactly): by contrast, in base 9, 2.444445 is nearer to 3 than to 2 (since 3 −2.444445 is .444444), but if you truncate 2.444445 you'll lose the 5 and get a number nearer to 2 than to 3. However, in an odd base we can use a 0-centered set of digits, which will make truncation be rounding to nearest, which keeps it free of the two defects discussed, one for odd natural bases the other for even bases. Then again, representing 1/2 involves chosing which way you want it rounded… but perhaps that's a sensible thing to require, after all.

Signed trits

Use −1, 0 and +1 as the digits for representing numbers, base three. It may be worth doing experiments in base 9 with {−4, …, 0, …, +4} as digits if you want to learn by playing with arithmetic – and one might sensibly describe signed ternary, by bunching up the digits in pairs, in this form (much as binary is commonly encoded as hexadecimal, bunching up the bits in groups of four). However, for now, I'll use T for −1, 0 for zero and 1 for +1, and stick to ternary, as base three is known. This signed form of it allows representation of arbitrary integers and reals, whether positive or negative, without needing an out-of-band mechanism (such as a leading sign-marker) to tell the reader the difference between positive and negative values. We have T01 as minus eight and 10T as plus eight, without any further complications, so that + and − only serve as binary operators, to combine values, rather than having to also serve as unary operators to set or emphasise the sign.

Our rules for addition of single digits then have T +1 = 0, T+T = T1, 1 +1 = 1T and, as ever, adding 0 makes no difference. By judicious additions of 0 = T +1 and recognition of trebling as shifting left, we can think of the two doublings as: T +T = T +T +T +1 = T0 +1 = T1 and 1 +1 = 1 +1 +1 +T = 10 +T = 1T. We deal with carrying in the usual way, although it may take a little practice to get used to it: 1T +T = 10 +T +T = 10 +T1 = 1, for example.

Multiplying can all be done by adding versions of one operand obtained by shifting and sometimes flipping based on the non-zero digits of the other; for each 1 in the latter, append a zero to the former for each digit after the 1; for each T do the same but flip 1 ↔ T in the other while shifting. Two is thus 1T (a three minus a one) and multiplying it by itself we get 1T0 (shifted left by one) added to T1 (flipped) to get 11 as four (three plus one); multiplying by the same again we get 1T0 +1T = 10T as eight (nine minus one). Multiplying 11 by itself we get 110 +11 = 1TT1 as sixteen (twenty-seven minus nine minus three plus 1); or multiplying 10T by 1T we get 10T0 +T01 = 1TT1, just the same. Roll-over when we have all digits the same and non-zero prepends one at the front and flips the rest, so thirteen plus one, 111 +1 = 1TTT, is twenty-seven minus thirteen, which is to say, fourteen. In particular, this happens at the transition from just below half a power of three to just above it, in contrast to a base using the digits from one up to one less than the base, where roll-over happens at one short of a power of the base.

That roll-over at half has another consequence: we can, of course, represent numbers with fractional parts, approximated by sums of ± powers of a third, that we necessarily separate from the whole number part of a number's denotation by a fractional-part separtor, as we do in decimal (where the marker gets the name decimal point, so you could call the separator a ternary point if you like, even though many cultures will want to use something other than a dot (or point) for the purpose, but I prefer to call it what it is: a separator for the fractional part).

Decimal has an endless tail of nines in the fractional part equivalent to bumping the digit before them all up by 1 (and, since it's not part of the endless tail of nines, it's not a nine, so we can do that without triggering a carry) and flipping those nines to zeros (which can duly be elided, as there's nothing non-zero after them). The corresponding effect in signed ternarry identifies an endless tail of ones in the fractional part with the result of replacing all those ones with minus-one digits (Ts, in my way of writing it) with the preceding digit increased (and, since it's not part of the endless tail of ones, this doesn't involve any carrying); likewise, an endless tail of Ts is equivalent to the result of flipping all those Ts to 1s and decreasing the preceding digit. Unlike the decimal roll-over, you'll notice this is entirely symmetric, reflecting the fact that those endless sequences represent ±half in the preceding digit and the choice between whether to end in endelss 1s or endless Ts is a decision about how you think that half-way value should be rounded by anyone that needs to work with finitely many trits.


Valid CSSValid HTML 5 Written by Eddy.