Balanced ternary

Balanced ternary is a ternary numeral system (i.e. base 3 with three digits) that uses a balanced signed-digit representation of the integers in which the digits have the values −1, 0, and 1. This stands in contrast to the standard (unbalanced) ternary system, in which digits have values 0, 1 and 2. The balanced ternary system can represent all integers without using a separate minus sign; the value of the leading non-zero digit of a number has the sign of the number itself. While binary numerals with digits 0 and 1 provide the simplest positional numeral system for natural numbers (or for positive integers if using 1 and 2 as the digits), balanced ternary provides the simplest self-contained positional numeral system for integers. The balanced ternary system is an example of a non-standard positional numeral system. It was used in some early computers[1] and also in some solutions of balance puzzles.[2]

Different sources use different glyphs used to represent the three digits in balanced ternary. In this article, T (which resembles a ligature of the minus sign and 1) represents −1, while 0 and 1 represent themselves. Other conventions include using '−' and '+' to represent −1 and 1 respectively, or using Greek letter theta (Θ), which resembles a minus sign in a circle, to represent −1. In publications about the Setun computer, −1 is represented as overturned 1: "1".[1]

Balanced ternary makes an early appearance in Michael Stifel's book Arithmetica Integra (1544).[3] It also occurs in the works of Johannes Kepler and Léon Lalanne. Related signed-digit schemes in other bases have been discussed by John Colson, John Leslie, Augustin-Louis Cauchy, and possibly even the ancient Indian Vedas.[2]

Definition

Let denote the set of symbols (also called glyphs or characters) , where the symbol is sometimes used in place of Define an integer-valued function by

[note 1] and

where the right hand sides are integers with their usual (decimal) values. This function, is what rigorously and formally establishes how integer values are assigned to the symbols/glyphs in One benefit of this formalism is that the definition of "the integers" (however they may be defined) is not conflated with any particular system for writing/representing them; in this way, these two distinct (albeit closely related) concepts are kept separate.

The set together with the function forms a balanced signed-digit representation called the balanced ternary system. It can be used to represent integers and real numbers.

Ternary integer evaluation

Let be the Kleene plus of , which is the set of all finite length concatenated strings of one or more symbols (called its digits) where is a non-negative integer and all digits are taken from The start of is the symbol (at the right), its end is (at the left), and its length is . The ternary evaluation is the function defined by assigning to every string the integer

The string represents (with respect to ) the integer The value may alternatively be denoted by The map is surjective but not injective since, for example, However, every integer has exactly one representation under that does not end (on the left) with the symbol i.e.

If and then satisfies:

which shows that satisfies a sort of recurrence relation. This recurrence relation has three initial conditions, one for every where Explicitly, they are and

This implies that for every string

which in words says that leading symbols (to the left in a string with 2 or more symbols) do not affect the resulting value.

The following examples illustrate how some values of can be computed, where (as before) all integer are written in decimal (base 10) and all elements of are just symbols.

and using the above recurrence relation

Conversion to decimal

In the balanced ternary system the value of a digit n places left of the radix point is the product of the digit and 3n. This is useful when converting between decimal and balanced ternary. In the following the strings denoting balanced ternary carry the suffix, bal3. For instance,

10bal3 = 1 × 31 + 0 × 30 = 310
10ᴛbal3 = 1 × 32 + 0 × 31 + (−1) × 30 = 810
−910 = −1 × 32 + 0 × 31 + 0 × 30 = ᴛ00bal3
810 = 1 × 32 + 0 × 31 + (−1) × 30 = 10ᴛbal3

Similarly, the first place to the right of the radix point holds 3−1 = 1/3, the second place holds 3−2 = 1/9, and so on. For instance,

2/310 = −1 + 1/3 = −1 × 30 + 1 × 3−1 = ᴛ.1bal3.
DecBal3ExpansionDecBal3Expansion
000
11+1−1−1
21ᴛ+3−1−2ᴛ1−3+1
310+3−3ᴛ0−3
411+3+1−4ᴛᴛ−3−1
51ᴛᴛ+9−3−1−5ᴛ11−9+3+1
61ᴛ0+9−3−6ᴛ10−9+3
71ᴛ1+9−3+1−7ᴛ1ᴛ−9+3−1
810ᴛ+9−1−8ᴛ01−9+1
9100+9−9ᴛ00−9
10101+9+1−10ᴛ0ᴛ−9−1
1111ᴛ+9+3−1−11ᴛᴛ1−9−3+1
12110+9+3−12ᴛᴛ0−9−3
13111+9+3+1−13ᴛᴛᴛ−9−3−1

An integer is divisible by three if and only if the digit in the units place is zero.

We may check the parity of a balanced ternary integer by checking the parity of the sum of all trits. This sum has the same parity as the integer itself.

Balanced ternary can also be extended to fractional numbers similar to how decimal numbers are written to the right of the radix point.[4]

Decimal−0.9−0.8−0.7−0.6−0.5−0.4−0.3−0.2−0.10
Balanced Ternary ᴛ.010ᴛᴛ.1ᴛᴛ1ᴛ.10ᴛ0ᴛ.11ᴛᴛ0. or ᴛ.10.ᴛᴛ110.ᴛ0100.ᴛ11ᴛ0.0ᴛ010
Decimal0.90.80.70.60.50.40.30.20.10
Balanced Ternary 1.0ᴛ011.ᴛ11ᴛ1.ᴛ0101.ᴛᴛ110.1 or 1.0.11ᴛᴛ0.10ᴛ00.1ᴛᴛ10.010ᴛ0

In decimal or binary, integer values and terminating fractions have multiple representations. For example, 1/10 = 0.1 = 0.10 = 0.09. And, 1/2 = 0.12 = 0.102 = 0.012. Some balanced ternary fractions have multiple representations too. For example, 1/6 = 0.1bal3 = 0.01bal3. Certainly, in the decimal and binary, we may omit the rightmost trailing infinite 0s after the radix point and gain a representations of integer or terminating fraction. But, in balanced ternary, we can't omit the rightmost trailing infinite −1s after the radix point in order to gain a representations of integer or terminating fraction.

Donald Knuth[5] has pointed out that truncation and rounding are the same operation in balanced ternarythey produce exactly the same result (a property shared with other balanced numeral systems). The number 1/2 is not exceptional; it has two equally valid representations, and two equally valid truncations: 0.1 (round to 0, and truncate to 0) and 1. (round to 1, and truncate to 1). With an odd radix, double rounding is also equivalent to directly rounding to the final precision, unlike with an even radix.

The basic operationsaddition, subtraction, multiplication, and divisionare done as in regular ternary. Multiplication by two can be done by adding a number to itself, or subtracting itself after a-trit-left-shifting.

An arithmetic shift left of a balanced ternary number is the equivalent of multiplication by a (positive, integral) power of 3; and an arithmetic shift right of a balanced ternary number is the equivalent of division by a (positive, integral) power of 3.

Conversion to and from a fraction

FractionBalanced ternaryFractionBalanced ternary
111/110.01ᴛ11
1/20.11.1/120.01ᴛ
1/30.11/130.01ᴛ
1/40.1ᴛ1/140.01ᴛ0ᴛ1
1/50.1ᴛᴛ11/150.01ᴛᴛ1
1/60.010.11/160.01ᴛᴛ
1/70.0110ᴛᴛ1/170.01ᴛᴛᴛ10ᴛ0ᴛ111ᴛ01
1/80.011/180.0010.01
1/90.011/190.00111ᴛ10100ᴛᴛᴛ1ᴛ0ᴛ
1/100.010ᴛ1/200.0011

The conversion of a repeating balanced ternary number to a fraction is analogous to converting a repeating decimal. For example (because of 111111bal3 = (36 − 1/3 − 1)10):

Irrational numbers

As in any other integer base, algebraic irrationals and transcendental numbers do not terminate or repeat. For example:

The balanced ternary expansions of is given in OEIS as A331313, that of in A331990.

Conversion from ternary

Unbalanced ternary can be converted to balanced ternary notation in two ways:

  • Add 1 trit-by-trit from the first non-zero trit with carry, and then subtract 1 trit-by-trit from the same trit without borrow. For example,
    0213 + 113 = 1023, 1023 − 113 = 1T1bal3 = 710.
  • If a 2 is present in ternary, turn it into 1T. For example,
    02123 = 0010bal3 + 1T00bal3 + 001Tbal3 = 10TTbal3 = 2310
BalancedLogicUnsigned
1True2
0Unknown1
TFalse0

If the three values of ternary logic are false, unknown and true, and these are mapped to balanced ternary as T, 0 and 1 and to conventional unsigned ternary values as 0, 1 and 2, then balanced ternary can be viewed as a biased number system analogous to the offset binary system. If the ternary number has n trits, then the bias b is

which is represented as all ones in either conventional or biased form.[6]

As a result, if these two representations are used for balanced and unsigned ternary numbers, an unsigned n-trit positive ternary value can be converted to balanced form by adding the bias b and a positive balanced number can be converted to unsigned form by subtracting the bias b. Furthermore, if x and y are balanced numbers, their balanced sum is x + yb when computed using conventional unsigned ternary arithmetic. Similarly, if x and y are conventional unsigned ternary numbers, their sum is x + y + b when computed using balanced ternary arithmetic.

Conversion to balanced ternary from any integer base

We may convert to balanced ternary with the following formula:

where,

anan−1...a1a0.c1c2c3... is the original representation in the original numeral system.
b is the original radix. b is 10 if converting from decimal.
ak and ck are the digits k places to the left and right of the radix point respectively.

For instance,

 −25.410 = −(1T×1011 + 1TT×1010 + 11×101−1)
          = −(1T×101 + 1TT + 11÷101)
          = −10T1.11TT
          =  T01T.TT11
 1010.12 = 1T10 + 1T1 + 1T−1
           = 10T + 1T + 0.1
           = 101.1

Addition, subtraction and multiplication and division

The single-trit addition, subtraction, multiplication and division tables are shown below. For subtraction and division, which are not commutative, the first operand is given to the left of the table, while the second is given at the top. For instance, the answer to 1  T = 1T is found in the bottom left corner of the subtraction table.

:{| class="wikitable" style="width: 8em; text-align: center;"
Addition
+T01
T T1T0
0 T01
1 011T

|

:{| class="wikitable" style="width: 8em; text-align: center;"
|+ Subtraction
|- align="right"
! − !! T !! 0 !! 1
|-
! T
| 0 || T || T1
|-
! 0
| 1 || 0 || T
|-
! 1
| 1T || 1 || 0
|}

|

:{| class="wikitable" style="width: 8em; text-align: center;"
|+ Multiplication
|- align="right"
! × !! T !! 0 !! 1
|-
|-
! T 
| 1 || 0 || T
|-
! 0 
| 0 || 0 || 0
|-
! 1 
| T || 0 || 1
|}

|

:{| class="wikitable" style="text-align: center;"
|+ Division
|- align="right"
! ÷ !! T !! 1
|-
|-
! T
| 1 || T
|-
! 0
| 0 || 0
|-
! 1
| T || 1
|}

|}

Multi-trit addition and subtraction

Multi-trit addition and subtraction is analogous to that of binary and decimal. Add and subtract trit by trit, and add the carry appropriately. For example:

           1TT1TT.1TT1              1TT1TT.1TT1            1TT1TT.1TT1          1TT1TT.1TT1
         +   11T1.T                −  11T1.T              −  11T1.T     →     +   TT1T.1
        ______________          ______________                               _______________
           1T0T10.0TT1              1T1001.TTT1                                 1T1001.TTT1
         +   1T                   +  T  T1                                    + T  T
         ______________         ________________                             ________________
           1T1110.0TT1              1110TT.TTT1                                 1110TT.TTT1
         +   T                    + T   1                                     + T   1
         ______________         ________________                             ________________
           1T0110.0TT1               1100T.TTT1                                  1100T.TTT1

Multi-trit multiplication

Multi-trit multiplication is analogous to that of binary and decimal.

       1TT1.TT
   ×   T11T.1
   _____________
        1TT.1TT multiply 1
       T11T.11  multiply T
      1TT1T.T   multiply 1
     1TT1TT     multiply 1
    T11T11      multiply T
   _____________
    0T0000T.10T

Multi-trit division

Balanced ternary division is analogous to that of binary and decimal.

However, 0.510 = 0.1111...bal3 or 1.TTTT...bal3. If the dividend over the plus or minus half divisor, the trit of the quotient must be 1 or T. If the dividend is between the plus and minus of half the divisor, the trit of the quotient is 0. The magnitude of the dividend must be compared with that of half the divisor before setting the quotient trit. For example,

                         1TT1.TT      quotient
0.5 × divisor  T01.0 _____________                
      divisor T11T.1 ) T0000T.10T     dividend             
                      T11T1                        T000 < T010, set 1
                     _______
                       1T1T0
                       1TT1T                      1T1T0 > 10T0, set T 
                      _______
                         111T
                        1TT1T                      111T > 10T0, set T
                       _______
                          T00.1
                         T11T.1                    T001 < T010, set 1
                        ________
                          1T1.00
                          1TT.1T                  1T100 > 10T0, set T
                         ________
                           1T.T1T
                           1T.T1T                 1TT1T > 10T0, set T
                          ________
                                0

Another example,

                           1TTT
       0.5 × divisor 1T  _______
            Divisor  11  )1T01T                   1T = 1T, but 1T.01 > 1T, set 1
                          11
                         _____
                          T10                    T10 < T1, set T
                           TT
                         ______
                           T11                   T11 < T1, set T
                            TT
                          ______
                             TT                   TT < T1, set T
                             TT
                            ____
                              0

Another example,

                           101.TTTTTTTTT… 
                        or 100.111111111… 
       0.5 × divisor 1T  _________________
            divisor  11  )111T                    11 > 1T, set 1
                          11
                         _____
                            1                     T1 < 1 < 1T, set 0
                           ___
                            1T                    1T = 1T, trits end, set 1.TTTTTTTTT… or 0.111111111…

Square roots and cube roots

The process of extracting the square root in balanced ternary is analogous to that in decimal or binary.

As in division, we should check the value of half the divisor first. For example,

                             1. 1 1 T 1 T T 0 0 ... 
                           _________________________
                          √ 1T                          1<1T<11, set 1
                           − 1
                            _____
                  1×10=10    1.0T                       1.0T>0.10, set 1
                      1T0   −1.T0
                            ________
                  11×10=110    1T0T                     1T0T>110, set 1
                       10T0   −10T0
                              ________
                 111×10=1110    T1T0T                   T1T0T<TTT0, set T
                       100T0   −T0010
                               _________
                111T×10=111T0    1TTT0T                 1TTT0T>111T0, set 1
                       10T110   −10T110
                                __________
               111T1×10=111T10    TT1TT0T               TT1TT0T<TTT1T0, set T
                       100TTT0   −T001110
                                 ___________
              111T1T×10=111T1T0    T001TT0T             T001TT0T<TTT1T10, set T
                       10T11110   −T01TTTT0
                                  ____________
               111T1TT×10=111T1TT0    T001T0T           TTT1T110<T001T0T<111T1TT0, set 0
                                     −      T           Return 1
                                     ___________
             111T1TT0×10=111T1TT00    T001T000T         TTT1T1100<T001T000T<111T1TT00, set 0
                                     −        T         Return 1
                                     _____________
           111T1TT00*10=111T1TT000    T001T00000T
                                             ... 

Extraction of the cube root in balanced ternary is similarly analogous to extraction in decimal or binary:

Like division, we should check the value of half the divisor first too. For example:

                              1.  1   T  1  0 ... 
                            _____________________
                          ³√ 1T
                            − 1                 1<1T<10T,set 1
                            _______
                              1.000
              1×100=100      −0.100             borrow 100×, do division
                             _______
                      1TT     1.T00             1T00>1TT, set 1
          1×1×1000+1=1001    −1.001
                             __________
                                T0T000
            11×100            −   1100           borrow 100×, do division
                              _________
                     10T000     TT1T00           TT1T00<T01000, set T
       11×11×1000+1=1TT1001   −T11T00T
                              ____________
                                1TTT01000
           11T×100             −    11T00        borrow 100×, do division
                               ___________
                   1T1T01TT     1TTTT0100        1TTTT0100>1T1T01TT, set 1
    11T×11T×1000+1=11111001    − 11111001
                               ______________
                                    1T10T000
          11T1×100                 −  11T100      borrow 100×, do division
                                   __________
                      10T0T01TT     1T0T0T00      T01010T11<1T0T0T00<10T0T01TT, set 0
    11T1×11T1×1000+1=1TT1T11001    −  TT1T00      return 100×
                                   _____________
                                    1T10T000000
                                        ... 

Hence 32 = 1.25992110 = 1.1T1 000 111 001 T01 00T 1T1 T10 111bal3.

Applications

In computer design

In the early days of computing, a few experimental Soviet computers were built with balanced ternary instead of binary, the most famous being the Setun, built by Nikolay Brusentsov and Sergei Sobolev. The notation has a number of computational advantages over traditional binary and ternary. Particularly, the plus–minus consistency cuts down the carry rate in multi-digit multiplication, and the rounding–truncation equivalence cuts down the carry rate in rounding on fractions. In balanced ternary, the one-digit multiplication table remains one-digit and has no carry and the addition table has only two carries out of nine entries, compared to unbalanced ternary with one and three respectively.

"The complexity of arithmetic circuitry for balanced ternary arithmetic is not much greater than it is for the binary system, and a given number requires only as many digit positions for its representation."[5]
"Perhaps the symmetric properties and simple arithmetic of this number system will prove to be quite important some day."[5]

Other applications

The theorem that every integer has a unique representation in balanced ternary was used by Leonhard Euler to justify the identity of formal power series[7]

Balanced ternary has other applications besides computing. For example, a classical two-pan balance, with one weight for each power of 3, can weigh relatively heavy objects accurately with a small number of weights, by moving weights between the two pans and the table. For example, with weights for each power of 3 through 81, a 60-gram object (6010 = 1T1T0bal3) will be balanced perfectly with an 81 gram weight in the other pan, the 27 gram weight in its own pan, the 9 gram weight in the other pan, the 3 gram weight in its own pan, and the 1 gram weight set aside.

Similarly, consider a currency system with coins worth 1¤, 3¤, 9¤, 27¤, 81¤. If the buyer and the seller each have only one of each kind of coin, any transaction up to 121¤ is possible. For example, if the price is 7¤ (710 = 1T1bal3), the buyer pays 1¤ + 9¤ and receives 3¤ in change.

They may also provide a more natural representation for the qutrit and systems that use it.

See also

References

  1. N.A.Krinitsky; G.A.Mironov; G.D.Frolov (1963). "Chapter 10. Program-controlled machine Setun". In M.R.Shura-Bura (ed.). Programming (in Russian). Moscow.
  2. Hayes, Brian (2001), "Third base" (PDF), American Scientist, 89 (6): 490–494, doi:10.1511/2001.40.3268. Reprinted in Hayes, Brian (2008), Group Theory in the Bedroom, and Other Mathematical Diversions, Farrar, Straus and Giroux, pp. 179–200, ISBN 9781429938570
  3. Stifel, Michael (1544), Arithmetica integra (in Latin), p. 38.
  4. Bhattacharjee, Abhijit (24 July 2006). "Balanced ternary". Archived from the original on 2009-09-19.
  5. Knuth, Donald (1997). The art of Computer Programming. 2. Addison-Wesley. pp. 195–213. ISBN 0-201-89684-2.
  6. Douglas W. Jones, Ternary Number Systems, October 15, 2013.
  7. Andrews, George E. (2007). "Euler's "De Partitio numerorum"". Bulletin of the American Mathematical Society. New Series. 44 (4): 561–573. doi:10.1090/S0273-0979-07-01180-9. MR 2338365.
  1. The symbol appears twice in the equality but these instances do not represent the same thing. The right hand side means the integer zero but the instance of inside 's parentheses (which belongs to ) should be thought of as being nothing more than a symbol (without meaning). The reason for this is because although this article happened to choose (it is this choice introduced the ambiguity), this set could, for example, have instead been chosen to consist of the symbols This ambiguity can be removed by replacing "" with the sentence " is equal to the integer zero" or with "" where the symbol denotes the usual integer value in base ten. The same is true of the symbol in the equality
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.