Notes on Trinary: - The conventional trinary representation of a positive number x is given by x = SUM(i>=0) 3^(-i) * t_i, where 0 <= t_i <= 2 for i > 0, and t_0 can be arbitrarily large However, to accomodate exact real representation using interval approximation, we must increase the range from [0,2] to [-2,2]. - Addition: To add two exact reals with a trinary stream expansion, we are working from left to right, so the traditional notion of carrying digits is insufficient. The following outlines an algorithm for the addition of two trinary streams: Suppose you want to add 0.22-120-2... and 0.-120102-2... The first step is just a straightforward addition of each place: 0. 2 2-1 2 0-2 ... + 0.-1 2 0 1 2-2 ... -------------------- 0. 1 4-2 2 2-4 ... Now, this result is correct, but it is no longer in our modified trinary form, as it has digits in the range [-4,4]. However, it is clear that all digits will remain in this range, so we need only worry about converting this result to proper trinary. However, we are processing from left to right, so we have to be a little clever. We implement a sort of "inverse carrying" procedure as follows: We allow for one unit of "elbow room" in the i_th trit (i.e. ensure it is in range [-1,1]) so that we can always put (i+1)st trit into range [-1,1]. Thus we step a two digit window down the line, ensuring that we can always accomdate the move of the next trit into the range [-1,1]. 0. 1 4-2 2 2-4... start 0. 1 1 in [-1,1], no adj. necessary 2 1 4 not in [-1,1], sub 3, incr. 1 to 2 0 1 -2 not in [-1,1], add 3, decr. 1 to 0 2-1 2 not in [-1,1], sub 3, incr. 1 to 2 0-1 2 not in [-1,1], sub 3, incr. -1 to 0 -2-1... -4 not in [-1,1], add 3, decr. -1 to -2 --------------------- 0. 2 0 2 0-2 ... This method works ad infinitum, since any move from the [-4,4] range to the closest edge of the [-1,1] range is at most 3, which means at most a change of 1 in the previous digit. But since the previous digit was ensure to be in [-1,1], adding or subtracting one will always result in a value in [-2,2], the desired range. Note that this method fails for binary (-1 <= t_i <= 1) since there doesn't exist a successful elbow room range. The method does work for all bases >= 3. - Multiplication: Multiplication of two exact reals with a trinary stream expansion is considerably more complicated. Consider the multiplication of a = 0.1-202-1... and b = 0.2-1-210.... First we construct a multiplication table using the digits: | 0. 1-2 0 2-1 ... ---------------------- 0| 0. 0 0 0 0 0 ... .| 0. . . . . . ... 2| 0. 2-4 0 4-2 ... -1| 0.-1 2 0-2 1 ... -2| 0.-2 4 0-4 2 ... 1| 0. 1-2 0 2-1 ... 0| 0. 0 0 0 0 0 ... .| . . . . . . ... .| . . . . . . ... .| . . . . . . ... We can write the product a*b as SUM(i>=0) 3^(-i)*C_i, where C_i is the ith column of the multiplication. Also, as in the addition case, we notice that the range of the digits in the table is [-4,4], since x*y, where x,y is in [-2,2], must lie in [-4,4]. So we are again left with the problem of ensuring that the result of this addition is in fact in trinary as we have defined it (that is, all digits are in [-2,2]. To do this, we take as t_i of a*b the closest integer in [-2,2] to each C_i, and add t_i - C_i to C_(i+1), and do the same for t_(i+1), and so on.