Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Balanced ternary
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Numeral system using the values -1, 0 and 1}} {{numeral systems}} '''Balanced ternary''' is a [[ternary numeral system]] (i.e. base 3 with three [[Numerical digit|digits]]) that uses a balanced [[signed-digit representation]] of the [[integer]]s 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 systems|non-standard positional numeral system]]. It was used in some early computers<ref name=setun/> and has also been used to solve [[balance puzzle]]s.<ref name=hayes/> Different sources use different glyphs to represent the three digits in balanced ternary. In this article, T (which resembles a [[typographical ligature|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 alphabet|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: "<span class="plainlinks"></span><span style="display:inline-block;vertical-align:-0.05em;transform:matrix(-1, 0, 0, -1, 0, 0);">1</span>".<ref name=setun>{{cite book|title=Programming|year=1963|location=Moscow|author=N. A. Krinitsky |author2=G. A. Mironov |author3=G. D. Frolov|editor=M. R. Shura-Bura|language=ru|chapter=Chapter 10. Program-controlled machine Setun}}</ref> Balanced ternary makes an early appearance in [[Michael Stifel]]'s book ''Arithmetica Integra'' (1544).<ref>{{citation | last = Stifel | first = Michael | author-link = Michael Stifel | language = Latin | page = 38 | title = Arithmetica integra | url = https://archive.org/stream/bub_gb_ywkW9hDd7IIC#page/n85/mode/2up | year = 1544| publisher = apud Iohan Petreium }}.</ref> 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 (physicist)|John Leslie]], [[Augustin-Louis Cauchy]], and possibly even the ancient Indian [[Vedas]].<ref name=hayes>{{citation | first=Brian|last=Hayes|authorlink=Brian Hayes (scientist)|title=Third base|journal=American Scientist|url=http://bit-player.org/bph-publications/AmSci-2001-11-Hayes-ternary.pdf|year=2001|volume=89|issue=6|pages=490–494|doi=10.1511/2001.40.3268}}. Reprinted in {{citation|title=Group Theory in the Bedroom, and Other Mathematical Diversions|first=Brian|last=Hayes|authorlink=Brian Hayes (scientist)|publisher=Farrar, Straus and Giroux|year=2008|isbn=9781429938570|pages=179β200|url=https://books.google.com/books?id=1ZkYEFi3DMMC&pg=PA179}}</ref> == Definition == {{See also|Signed-digit representation}} Let <math>\mathcal{D}_{3} := \lbrace \operatorname{T}, 0, 1 \rbrace</math> denote the set of [[Symbol (mathematics)|symbols]] (also called ''glyphs'' or ''characters''), where the symbol <math>\bar{1}</math> is sometimes used in place of <math>\operatorname{T}.</math> Define an [[integer]]-valued function <math>f = f_{\mathcal{D}_{3}} : \mathcal{D}_{3} \to \mathbb{Z}</math> by :<math>\begin{align} f_{}(\operatorname{T}) &= -1, \\ f_{}(0) &= 0, \\ f_{}(1) &= 1, \end{align}</math><ref>The symbols <math>0</math> and <math>1</math> appear twice in the equalities <math>f_{}(0) = 0</math> and <math>f_{}(1) = 1,</math> but these instances do not represent the same thing. The right hand side <math>0</math> and <math>1</math> mean the integers <math>\in\Z,</math> but the instances inside <math>f</math>'s parentheses (which belong to <math>\mathcal{D}_{3}</math>) should be thought of as being nothing more than symbols.</ref> where the right hand sides are integers with their usual values. This function, <math>f_{},</math> is what rigorously and formally establishes how integer values are assigned to the symbols/glyphs in <math>\mathcal{D}_{3}.</math> 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 <math>\mathcal{D}_{3}</math> together with the function <math>f_{}</math> 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 <math>\mathcal{D}_{3}^{+}</math> be the [[Kleene plus]] of <math>\mathcal{D}_{3}</math>, which is the set of all finite length [[concatenation|concatenated]] [[String (computer science)|strings]] <math>d_n \ldots d_0</math> of one or more symbols (called its ''digits'') where <math>n</math> is a non-negative integer and all <math>n + 1</math> digits <math>d_n, \ldots, d_0</math> are taken from <math>\mathcal{D}_{3} = \lbrace \operatorname{T}, 0, 1 \rbrace.</math> The ''start'' of <math>d_n \ldots d_0</math> is the symbol <math>d_0</math> (at the right), its ''end'' is <math>d_n</math> (at the left), and its ''length'' is <math>n + 1</math>. The ''ternary evaluation'' is the function <math>v = v_{3} ~:~ \mathcal{D}_{3}^{+} \to \mathbb{Z}</math> defined by assigning to every string <math>d_n \ldots d_0 \in \mathcal{D}_{3}^{+}</math> the integer :<math>v\left( d_n \ldots d_0 \right) ~=~ \sum_{i=0}^{n} f_{} \left( d_{i} \right) 3^{i}.</math> The string <math>d_n \ldots d_0</math> ''represents'' (with respect to <math>v</math>) the integer <math>v\left( d_n \ldots d_0 \right).</math> The value <math>v\left( d_n \ldots d_0 \right)</math> may alternatively be denoted by <math>{d_n \ldots d_0}_{\operatorname{bal}3}.</math> The map <math>v : \mathcal{D}_{3}^{+} \to \mathbb{Z}</math> is [[Surjective map|surjective]] but not injective since, for example, <math>0 = v(0) = v(00) = v(0 0 0) = \cdots.</math> However, every nonzero integer has exactly one representation under <math>v</math> that does not ''end'' (on the left) with the symbol <math>0,</math> i.e. <math>d_n = 0 .</math> If <math>d_n \ldots d_0 \in \mathcal{D}_{3}^{+}</math> and <math>n > 0</math> then <math>v</math> satisfies: :<math>v\left( d_n d_{n-1} \ldots d_0 \right) ~=~ f_{} \left( d_{n} \right) 3^{n} + v\left( d_{n-1} \ldots d_0 \right)</math> which shows that <math>v</math> satisfies a sort of [[recurrence relation]]. This recurrence relation has the initial condition <math>v\left( \varepsilon \right) = 0</math> where <math>\varepsilon</math> is the empty string. This implies that for every string <math>d_n \ldots d_0 \in \mathcal{D}_{3}^{+},</math> :<math>v\left( 0 d_n \ldots d_0 \right) = v\left( d_n \ldots d_0 \right)</math> which in words says that ''leading'' <math>0</math> 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 <math>v</math> can be computed, where (as before) all integer are written in decimal (base 10) and all elements of <math>\mathcal{D}_{3}^{+}</math> are just symbols. :<math>\begin{alignat}{10} v\left( \operatorname{T} \operatorname{T} \right) &= && f_{}\left( \operatorname{T} \right) 3^{1} + && f_{}\left( \operatorname{T} \right) 3^{0} &&= &&(-1) &&3 &&\,+\, &&(-1) &&1 &&= -4 \\ v\left( \operatorname{T} 1 \right) &= && f_{}\left( \operatorname{T} \right) 3^{1} + && f_{}\left( 1 \right) 3^{0} &&= &&(-1) &&3 &&\,+\, &&(1) &&1 &&= -2 \\ v\left( 1 \operatorname{T} \right) &= && f_{}\left( 1 \right) 3^{1} + && f_{}\left( \operatorname{T} \right) 3^{0} &&= &&(1) &&3 &&\,+\, &&(-1) &&1 &&= 2 \\ v\left( 1 1 \right) &= && f_{}\left( 1 \right) 3^{1} + && f_{}\left( 1 \right) 3^{0} &&= &&(1) &&3 &&\,+\, &&(1) &&1 &&= 4 \\ v\left( 1 \operatorname{T} 0 \right) &= f_{}\left( 1 \right) 3^{2} + && f_{}\left( \operatorname{T} \right) 3^{1} + && f_{}\left( 0 \right) 3^{0} &&= (1) 9 \,+\, &&(-1) &&3 &&\,+\, &&(0) &&1 &&= 6 \\ v\left( 1 0 \operatorname{T} \right) &= f_{}\left( 1 \right) 3^{2} + && f_{}\left( 0 \right) 3^{1} + && f_{}\left( \operatorname{T} \right) 3^{0} &&= (1) 9 \,+\, &&(0) &&3 &&\,+\, &&(-1) &&1 &&= 8 \\ \end{alignat} </math> and using the above recurrence relation :<math>v\left( 1 0 1 \operatorname{T} \right) = f_{}\left( 1 \right) 3^{3} + v\left( 0 1 \operatorname{T} \right) = (1) 27 + v\left( 1 \operatorname{T} \right) = 27 + 2 = 29.</math> == 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 3<sup>''n''</sup>. This is useful when converting between decimal and balanced ternary. In the following the strings denoting balanced ternary carry the suffix, ''bal3''. For instance, : 10<sub>bal3</sub> = 1 Γ 3<sup>1</sup> + 0 Γ 3<sup>0</sup> = 3<sub>dec</sub> : 10π³<sub>bal3</sub> = 1 Γ 3<sup>2</sup> + 0 Γ 3<sup>1</sup> + (β1) Γ 3<sup>0</sup> = 8<sub>dec</sub> : β9<sub>dec</sub> = β1 Γ 3<sup>2</sup> + 0 Γ 3<sup>1</sup> + 0 Γ 3<sup>0</sup> = π³00<sub>bal3</sub> : 8<sub>dec</sub> = 1 Γ 3<sup>2</sup> + 0 Γ 3<sup>1</sup> + (β1) Γ 3<sup>0</sup> = 10π³<sub>bal3</sub> Similarly, the first place to the right of the radix point holds 3<sup>β1</sup> = {{sfrac|1|3}}, the second place holds 3<sup>β2</sup> = {{sfrac|1|9}}, and so on. For instance, : β{{sfrac|2|3}}<sub>dec</sub> = β1 + {{sfrac|1|3}} = β1 Γ 3<sup>0</sup> + 1 Γ 3<sup>β1</sup> = π³.1<sub>bal3</sub>. <div style="display: flex; column-gap: 1em; margin-inline-start: 1.5em;"> {| class="wikitable" style="border: none; text-align:right" ! Dec !! Bal3 !! Expansion |- | 0 || 0 || 0 |- | 1 || 1 || +1 |- | 2 || 1π³ || +3β1 |- | 3 || 10 || +3 |- | 4 || 11 || +3+1 |- | 5 || 1π³π³ || +9β3β1 |- | 6 || 1π³0 || +9β3 |- | 7 || 1π³1 || +9β3+1 |- | 8 || 10π³ || +9β1 |- | 9 || 100 || +9 |- | 10 || 101 || +9+1 |- | 11 || 11π³ || +9+3β1 |- | 12 || 110 || +9+3 |- | 13 || 111 || +9+3+1 |} {| class="wikitable" style="border: none; text-align:right" ! Dec !! Bal3 !! Expansion |- | 0 || 0 || 0 |- | β1 || π³ || β1 |- | β2 || π³1 || β3+1 |- | β3 || π³0 || β3 |- | β4 || π³π³ || β3β1 |- | β5 || π³11 || β9+3+1 |- | β6 || π³10 || β9+3 |- | β7 || π³1π³ || β9+3β1 |- | β8 || π³01 || β9+1 |- | β9 || π³00 || β9 |- | β10 || π³0π³ || β9β1 |- | β11 || π³π³1 || β9β3+1 |- | β12 || π³π³0 || β9β3 |- | β13 || π³π³π³ || β9β3β1 |} </div> An integer is divisible by three if and only if the digit in the units place is zero. We may check the [[Parity (mathematics)|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]].<ref>{{cite web |url=http://www.abhijit.info/tristate/tristate.html |title=Balanced ternary |last=Bhattacharjee |first=Abhijit |date=24 July 2006 |archiveurl=https://web.archive.org/web/20090919053547/http://www.abhijit.info/tristate/tristate.html |archivedate=2009-09-19}}</ref> :{| class="wikitable" |- ! Decimal ! style="text-align: right" | β0.9 ! style="text-align: right" | β0.8 ! style="text-align: right" | β0.7 ! style="text-align: right" | β0.6 ! style="text-align: right" | β0.5 ! style="text-align: right" | β0.4 ! style="text-align: right" | β0.3 ! style="text-align: right" | β0.2 ! style="text-align: right" | β0.1 ! style="text-align: right" | 0 |- ! Balanced Ternary | π³.{{overline|010π³}}||π³.{{overline|1π³π³1}}|| π³.{{overline|10π³0}}|| π³.{{overline|11π³π³}}|| 0.{{overline|π³}} or π³.{{overline|1}} || 0.{{overline|π³π³11}} || 0.{{overline|π³010}} || 0.{{overline|π³11π³}} || 0.{{overline|0π³01}} || 0 |- ! Decimal ! style="text-align: right" | 0.9 ! style="text-align: right" | 0.8 ! style="text-align: right" | 0.7 ! style="text-align: right" | 0.6 ! style="text-align: right" | 0.5 ! style="text-align: right" | 0.4 ! style="text-align: right" | 0.3 ! style="text-align: right" | 0.2 ! style="text-align: right" | 0.1 ! style="text-align: right" | 0 |- ! Balanced Ternary | 1.{{overline|0π³01}}||1.{{overline|π³11π³}}|| 1.{{overline|π³010}}|| 1.{{overline|π³π³11}}|| 0.{{overline|1}} or 1.{{overline|π³}} || 0.{{overline|11π³π³}} || 0.{{overline|10π³0}} || 0.{{overline|1π³π³1}} || 0.{{overline|010π³}} || 0 |} In decimal or binary, integer values and terminating fractions have multiple representations. For example, {{sfrac|1|10}} = 0.1 = 0.1{{overline|0}} = 0.0{{overline|9}}. And, {{sfrac|1|2}} = 0.1<sub>2</sub> = 0.1{{overline|0}}<sub>2</sub> = 0.0{{overline|1}}<sub>2</sub>. Some balanced ternary fractions have multiple representations too. For example, {{sfrac|1|6}} = 0.1{{overline|π³}}<sub>bal3</sub> = 0.0{{overline|1}}<sub>bal3</sub>. 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]]<ref name="Knuth">{{Cite book |last=Knuth |first=Donald |authorlink=Donald Knuth |title=The art of Computer Programming |volume=2 |pages=195β213 |publisher=Addison-Wesley |year=1997 |isbn=0-201-89684-2}}</ref> has pointed out that truncation and rounding are the same operation in balanced ternary—they produce exactly the same result (a property shared with other balanced numeral systems). The number {{sfrac|1|2}} is not exceptional; it has two equally valid representations, and two equally valid truncations: 0.{{overline|1}} (round to 0, and truncate to 0) and 1.{{overline|π³}} (round to 1, and truncate to 1). With an odd [[radix]], [[Rounding#Double rounding|double rounding]] is also equivalent to directly rounding to the final precision, unlike with an even radix. The basic operations—addition, subtraction, multiplication, and division—are 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=== <div style="display: flex; column-gap: 1em; margin-inline-start: 1.5em;"> {| class="wikitable" style="text-align: center;" !Fraction!!colspan="2"|Balanced ternary |- |1||colspan="2"|1 |- |{{sfrac|1|2}}||0.{{overline|1}}||1.{{overline|π³}} |- |{{sfrac|1|3}}||colspan="2"|0.1 |- |{{sfrac|1|4}}||colspan="2"|0.{{overline|1π³}} |- |{{sfrac|1|5}}||colspan="2"|0.{{overline|1π³π³1}} |- |{{sfrac|1|6}}||0.0{{overline|1}}||0.1{{overline|π³}} |- |{{sfrac|1|7}}||colspan="2"|0.{{overline|0110π³π³}} |- |{{sfrac|1|8}}||colspan="2"|0.{{overline|01}} |- |{{sfrac|1|9}}||colspan="2"|0.01 |- |{{sfrac|1|10}}||colspan="2"|0.{{overline|010π³}} |} {| class="wikitable" style="text-align: center;" !Fraction!!colspan="2"|Balanced ternary |- |{{sfrac|1|11}}||colspan="2"|0.{{overline|01π³11}} |- |{{sfrac|1|12}}||colspan="2"|0.0{{overline|1π³}} |- |{{sfrac|1|13}}||colspan="2"|0.{{overline|01π³}} |- |{{sfrac|1|14}}||colspan="2"|0.{{overline|01π³0π³1}} |- |{{sfrac|1|15}}||colspan="2"|0.0{{overline|1π³π³1}} |- |{{sfrac|1|16}}||colspan="2"|0.{{overline|01π³π³}} |- |{{sfrac|1|17}}||colspan="2"|0.{{overline|01π³π³π³10π³0π³111π³01}} |- |{{sfrac|1|18}}||0.00{{overline|1}}||0.01{{overline|π³}} |- |{{sfrac|1|19}}||colspan="2"|0.{{overline|00111π³10100π³π³π³1π³0π³}} |- |{{sfrac|1|20}}||colspan="2"|0.{{overline|0011}} |} </div> The conversion of a repeating balanced ternary number to a fraction is analogous to [[Repeating decimal#Converting repeating decimals to fractions|converting a repeating decimal]]. For example (because of 111111<sub>bal3</sub> = ({{sfrac|3<sup>6</sup> β 1|3 β 1}})<sub>dec</sub>): : <math> 0.1\overline{\mathrm{110TT0} } =\tfrac{\mathrm{1110TT0-1} }{\mathrm{111111\times 1T\times 10}}=\tfrac{\mathrm{1110TTT} } {\mathrm{111111\times 1T0}} =\tfrac{\mathrm{111\times 1000T} } {\mathrm{111\times 1001\times 1T0}} =\tfrac{\mathrm{1111\times 1T}}{\mathrm{1001\times 1T0}} =\tfrac{1111}{10010}=\tfrac{\mathrm{1T1T}}{\mathrm{1TTT0}} =\tfrac{101}{\mathrm{1T10} } </math> === Conversion from unbalanced 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, *: 021<sub>3</sub> + 11<sub>3</sub> = 102<sub>3</sub>, 102<sub>3</sub> β 11<sub>3</sub> = 1T1<sub>bal3</sub> = 7<sub>dec</sub>. *If a 2 is present in ternary, turn it into 1T. For example, *: 0212<sub>3</sub> = 0010<sub>bal3</sub> + 1T00<sub>bal3</sub> + 001T<sub>bal3</sub> = 10TT<sub>bal3</sub> = 23<sub>dec</sub> {| class="wikitable floatright" style=" text-align: center" |- ! Balanced || Logic || Unsigned |- | 1 || True || 2 |- | 0 || Unknown || 1 |- | T || False || 0 |} If the three values of [[Three-valued logic#Kleene logic|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 :<math>b=\left\lfloor \frac{3^n}{2} \right\rfloor</math> which is represented as all ones in either conventional or biased form.<ref>Douglas W. Jones, [http://www.cs.uiowa.edu/~jones/ternary/numbers.shtml Ternary Number Systems], October 15, 2013.</ref> 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 {{nowrap|''x'' + ''y'' β ''b''}} when computed using conventional unsigned ternary arithmetic. Similarly, if ''x'' and ''y'' are conventional unsigned ternary numbers, their sum is {{nowrap|''x'' + ''y'' + ''b''}} when computed using balanced ternary arithmetic. ===Conversion from any integer base to balanced ternary=== We may convert to balanced ternary with the following formula: :<math> \left(a_na_{n-1}\cdots a_1a_0.c_1 c_2 c_3\cdots\right)_b = \sum_{k=0}^n a_kb^k + \sum_{k=1}^\infty c_kb^{-k}. </math> where, : ''a<sub>n</sub>a''<sub>''n''β1</sub>...''a''<sub>1</sub>''a''<sub>0</sub>.''c''<sub>1</sub>''c''<sub>2</sub>''c''<sub>3</sub>... is the original representation in the original numeral system. : ''b'' is the original radix. ''b'' is 10 if converting from decimal. : ''a<sub>k</sub>'' and ''c<sub>k</sub>'' are the digits ''k'' places to the left and right of the radix point respectively. For instance, β25.4<sub>dec</sub> = β(1TΓ101<sup>1</sup> + 1TTΓ101<sup>0</sup> + 11Γ101<sup>β1</sup>) = β(1TΓ101 + 1TT + 11Γ·101) = β10T1.{{overline|11TT}} = T01T.{{overline|TT11}} 1010.1<sub>2</sub> = 1T<sup>10</sup> + 1T<sup>1</sup> + 1T<sup>β1</sup> = 10T + 1T + 0.{{overline|1}} = 101.{{overline|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 property|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 |- align="right" ! + !! T !! 0 !! 1 |- |- ! T | T1 || T || 0 |- ! 0 | T || 0 || 1 |- ! 1 | 0 || 1 || 1T |} | :{| 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 T1 ______________ ________________ ________________ 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.5<sub>dec</sub> = 0.1111...<sub>bal3</sub> or 1.TTTT...<sub>bal3</sub>. 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. :<math>(10\cdot x+y)^{\mathrm{1T}}-100\cdot x^{\mathrm{1T}}=\mathrm{1T0}\cdot x\cdot y+y^{\mathrm{1T}}= \begin{cases} \mathrm{T10}\cdot x+1, & y=\mathrm{T} \\ 0, & y=0 \\ \mathrm{1T0}\cdot x+1, & y=1 \end{cases} </math> 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: :<math>(10\cdot x+y)^{10}-1000\cdot x^{10}=1000\cdot x^{\mathrm{1T}}\cdot y+100\cdot x\cdot y^{\mathrm{1T}}+y^{10}= \begin{cases} \mathrm{T000}\cdot x^{\mathrm{1T}}+100\cdot x+\mathrm{T}, & y=\mathrm{T}\\ 0, & y=0\\ 1000\cdot x^{\mathrm{1T}}+100\cdot x+1, & y=1 \end{cases} </math> 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 {{radic|2|3}} = 1.259921<sub>dec</sub> = 1.1T1 000 111 001 T01 00T 1T1 T10 111<sub>bal3</sub>. ==Irrational numbers== As in any other integer base, algebraic irrationals and transcendental numbers do not terminate or repeat. For example: :{| class="wikitable" !Decimal !! Balanced ternary |- |<math>\sqrt{2}=1.4142135623731\ldots</math> || <math>\sqrt{\mathrm{1T}}=\mathrm{1.11T1TT00T00T01T0T00T00T01TT\ldots}</math> |- |<math>\sqrt{3}=1.7320508075689\ldots</math> || <math>\sqrt{\mathrm{10}}=\mathrm{1T.T1TT10T0000TT1100T0TTT011T0\ldots}</math> |- |<math>\sqrt{5}=2.2360679774998\ldots</math> || <math>\sqrt{\mathrm{1TT}}=\mathrm{1T.1T0101010TTT1TT11010TTT01T1\ldots}</math> |- |<math display="inline">\varphi=\frac{1 + \sqrt{5}}{2}=1.6180339887499\ldots</math> || <math display="inline">\varphi=\frac{1 + \sqrt{\mathrm{1TT}}}{\mathrm{1T}}=\mathrm{1T.T0TT01TT0T10TT11T0011T10011\ldots}</math> |- |<math>\tau=6.28318530717959\ldots</math> || <math>\tau=\mathrm{1T0.10TT0T1100T110TT0T1TT000001}\ldots</math> |- |<math>\pi=3.14159265358979\ldots</math> || <math>\pi=\mathrm{10.011T111T000T011T1101T111111}\ldots</math> |- |<math>e=2.71828182845905\ldots</math> || <math>e=\mathrm{10.T0111TT0T0T111T0111T000T11T}\ldots</math> |} The balanced ternary expansions of <math>\pi</math> is given in [[OEIS]] as {{OEIS link|A331313}}, that of <math>e</math> in {{OEIS link|A331990}}. == Applications == === In computer design === [[File:Balanced ternary operation tables.svg|thumb|Operation tables]]<!--Maybe that "al TRIT piΓΉ alto" table deserves some explanation.--> 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. Knuth wrote that "Perhaps the symmetric properties and simple arithmetic of this number system will prove to be quite important some day,"<ref name="Knuth"/> noting that, {{quote|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 <math>\log_3 2 \approx 63 \%</math> as many digit positions for its representation."<ref name="Knuth"/>}} More recently, balanced ternary numbers have been proposed for some highly-efficient low-resolution implementations of [[artificial neural networks]]. In [[deep learning]], neural nets usually use continuous (floating-point) values, but there are many works investigating quantisation and binarisation to create neural nets that can run with much lower power and/or lower memory requirements. Balanced ternary numbers are proposed to be used for the network parameters, because they are extremely compact, but can naturally represent excitatory/inhibitory/null activation patterns.<ref>{{cite arXiv | last = Li | first = Fengfu | title = Ternary Weight Networks |date = 2022 | class = cs.CV | eprint = 1605.04711 }}</ref><ref>{{cite arxiv | last = Ma | first = Shuming | title = The era of 1-bit LLMs: All large language models are in 1.58 bits | date = 2024 | arxiv = 2402.17764 }}</ref> Balanced ternary may also provide a more natural representation for the [[qutrit]] and quantum computing systems that use it. === 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]]<ref>{{cite journal | last = Andrews | first = George E. | doi = 10.1090/S0273-0979-07-01180-9 | issue = 4 | journal = Bulletin of the American Mathematical Society | mr = 2338365 | pages = 561β573 | series = New Series | title = Euler's "De Partitio numerorum" | volume = 44 | year = 2007| doi-access = free }}</ref> :<math>\prod_{n=0}^{\infty} \left(x^{-3^n}+1+x^{3^n}\right)=\sum_{n=-\infty}^{\infty}x^n.</math> Balanced ternary has other applications besides computing. For example, a classical two-pan [[Weighing scale#Balance|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 (60<sub>dec</sub> = 1T1T0<sub>bal3</sub>) 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Β€ (7<sub>dec</sub> = 1T1<sub>bal3</sub>), the buyer pays 1Β€ + 9Β€ and receives 3Β€ in change. ==See also== * [[Signed-digit representation]] * [[Methods of computing square roots]] * [[Numeral system]] * [[Qutrit]] * [[Salamis Tablet]] * [[Ternary computer]] ** [[Setun]], a ternary computer * [[Ternary logic]] * [[Generalized balanced ternary]] ==References== {{reflist}} {{reflist|group=note}} ==External links== {{commons category|Balanced ternary}} *[http://www.computer-museum.ru/english/setun.htm Development of ternary computers at Moscow State University] *[https://web.archive.org/web/20090312094241/http://abhijit.info/tristate/tristate.html Representation of Fractional Numbers in Balanced Ternary] *[https://www.americanscientist.org/article/third-base "Third base"], ternary and balanced ternary number systems *[https://web.archive.org/web/20110712221950/http://www.hostsrv.com/webmaa/app1/MSP/webm1010/ternary.msp The Balanced Ternary Number System] (includes decimal integer to balanced ternary converter) *{{OEIS el|1=A182929|2=The binomial triangle reduced to balanced ternary lists|formalname=The rows of the binomial triangle reduced to balanced ternary lists encoded as decimal numbers}} *[http://userpages.wittenberg.edu/bshelburne/BalancedTernaryTalkSu09.pdf Balanced (Signed) Ternary Notation] {{Webarchive|url=https://web.archive.org/web/20160303182504/http://userpages.wittenberg.edu/bshelburne/BalancedTernaryTalkSu09.pdf |date=2016-03-03 }} by Brian J. Shelburne (PDF file) *[http://www.mortati.com/glusker/fowler/ The ternary calculating machine of Thomas Fowler] by Mark Glusker [[Category:Computer arithmetic]] [[Category:Non-standard positional numeral systems]] [[Category:Ternary computers]] [[Category:Numeral systems]] [[de:TernΓ€rsystem#Balanciert]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation
(
edit
)
Template:Cite arXiv
(
edit
)
Template:Cite arxiv
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Commons category
(
edit
)
Template:Nowrap
(
edit
)
Template:Numeral systems
(
edit
)
Template:OEIS el
(
edit
)
Template:OEIS link
(
edit
)
Template:Overline
(
edit
)
Template:Quote
(
edit
)
Template:Radic
(
edit
)
Template:Reflist
(
edit
)
Template:See also
(
edit
)
Template:Sfrac
(
edit
)
Template:Short description
(
edit
)
Template:Sidebar with collapsible groups
(
edit
)
Template:Sister project
(
edit
)
Template:Webarchive
(
edit
)