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. The balanced ternary system is an example of a non-standard positional numeral system. It was used in some early computers and has also been used to solve balance puzzles. Different sources use different glyphs 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". Balanced ternary makes an early appearance in Michael Stifel's book Arithmetica Integra (1544). 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.
Definition
Let 𝒟3:={T,0,1} denote the set of symbols (also called glyphs or characters), where the symbol 1¯ is sometimes used in place of T. Define an integer-valued function f=f𝒟3:𝒟3→ℤ by
f(T)=−1,f(0)=0,f(1)=1, where the right hand sides are integers with their usual values. This function, f, is what rigorously and formally establishes how integer values are assigned to the symbols/glyphs in 𝒟3. 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 𝒟3 together with the function f 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 𝒟3+ be the Kleene plus of 𝒟3, which is the set of all finite length concatenated strings dn…d0 of one or more symbols (called its digits) where n is a non-negative integer and all n+1 digits dn,…,d0 are taken from 𝒟3={T,0,1}. The start of dn…d0 is the symbol d0 (at the right), its end is dn (at the left), and its length is n+1. The ternary evaluation is the function v=v3 : 𝒟3+→ℤ defined by assigning to every string dn…d0∈𝒟3+ the integer
v(dn…d0) = ∑i=0nf(di)3i. The string dn…d0 represents (with respect to v) the integer v(dn…d0). The value v(dn…d0) may alternatively be denoted by dn…d0bal3. The map v:𝒟3+→ℤ is surjective but not injective since, for example, 0=v(0)=v(00)=v(000)=⋯. However, every nonzero integer has exactly one representation under v that does not end (on the left) with the symbol 0, i.e. dn=0. If dn…d0∈𝒟3+ and n>0 then v satisfies:
v(dndn−1…d0) = f(dn)3n+v(dn−1…d0) which shows that v satisfies a sort of recurrence relation. This recurrence relation has the initial condition v(ε)=0 where ε is the empty string. This implies that for every string dn…d0∈𝒟3+,
v(0dn…d0)=v(dn…d0) which in words says that leading 0 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 v can be computed, where (as before) all integer are written in decimal (base 10) and all elements of 𝒟3+ are just symbols.
v(TT)=f(T)31+f(T)30=(−1)3+(−1)1=−4v(T1)=f(T)31+f(1)30=(−1)3+(1)1=−2v(1T)=f(1)31+f(T)30=(1)3+(−1)1=2v(11)=f(1)31+f(1)30=(1)3+(1)1=4v(1T0)=f(1)32+f(T)31+f(0)30=(1)9+(−1)3+(0)1=6v(10T)=f(1)32+f(0)31+f(T)30=(1)9+(0)3+(−1)1=8 and using the above recurrence relation
v(101T)=f(1)33+v(01T)=(1)27+v(1T)=27+2=29.
Conversions to/from other representations
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 = 3dec 10𝖳bal3 = 1 × 32 + 0 × 31 + (−1) × 30 = 8dec −9dec = −1 × 32 + 0 × 31 + 0 × 30 = 𝖳00bal3 8dec = 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/3dec = −1 + 1/3 = −1 × 30 + 1 × 3−1 = 𝖳.1bal3.
An integer is divisible by three if and only if the digit in the units place is zero. The parity of a balanced ternary integer may be checked 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.
… excerpt ends here. Continue reading the full article.
