Content deleted Content added
Ex.function (talk | contribs) m →Square roots and cube roots: Added missing wikilink |
→Multi-trit division: typo Tag: possibly inaccurate edit summary |
||
(140 intermediate revisions by 49 users not shown) | |||
Line 1:
{{Short description|Numeral system using the values -1, 0 and 1}}
{{numeral systems}}
'''Balanced ternary''' is a [[
Different sources use different glyphs
Balanced ternary makes an early appearance in [[Michael Stifel]]'s book ''Arithmetica Integra'' (1544).<ref>{{citation
Line 11 ⟶ 12:
| 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>
==
{{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> =
:
: −9<sub>
: 8<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>
<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 ||
|-
| 3 || 10 || +3
|-
| 4 || 11 || +3+1
|-
| 5 ||
|-
| 6 ||
|-
| 7 ||
|-
| 8 ||
|-
| 9 || 100 || +9
|-
| 10 || 101 || +9+1
|-
| 11 ||
|-
| 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
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
|
|-
! Decimal
! 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|
|}
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|
[[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.
Line 88 ⟶ 225:
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>
: <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>
*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>
|-
! Balanced || Logic || Unsigned
Line 157 ⟶ 302:
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
We may convert to balanced ternary with the following formula:
Line 171 ⟶ 316:
For instance,
−25.4<sub>
= −(1T×101<sup>1</sup> +
= −(1T×101 + 1TT + 11×0.{{overline|010T}})
= −(1T1T + 1TT + 0.{{overline|11TT}})
= −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 ==
Line 257 ⟶ 411:
______________ ______________ _______________
1T0T10.0TT1 1T1001.TTT1 1T1001.TTT1
+ 1T + T
______________ ________________ ________________
1T1110.0TT1 1110TT.TTT1 1110TT.TTT1
Line 266 ⟶ 420:
===Multi-trit multiplication===
Multi-trit multiplication is analogous to that
1TT1.TT
Line 280 ⟶ 434:
===Multi-trit division===
Balanced ternary division is analogous to
However, 0.5<sub>
1TT1.TT quotient
Line 322 ⟶ 476:
0
Another example,
101.
or 100.
0.5 × divisor 1T _________________
divisor 11 )111T 11 > 1T, set 1
Line 330 ⟶ 484:
1 T1 < 1 < 1T, set 0
___
1T 1T = 1T, trits end, set 1.
In balanced ternary, there is a simpler division method that does not require comparing the remainders and operates directly according to the rules. This method originated from [[Donald Knuth]] trial [https://dfns.dyalog.com/n_bt.htm quotient method], but this method is not perfect. Later, it was improved by other scholars, completely abandoning the judgment of semi-closed intervals and instead using the condition of whether the highest bit of the remainder of each round of division is 0 to determine whether the round of division is over, and named it the double trial quotient method: the core logic is to split the dividend into two vectors (p and s), where the number of digits of p is at most the same as the divisor q, and s is the vector of the remaining digits; then according to the rule (double positive or double negative gives a positive quotient, one positive and one negative gives a negative quotient, and the others are 0), the quotient is subtracted at most once or twice in each round of division. If the highest bit of the remainder p is still not 0 after subtraction once, it needs to be subtracted again. If the highest bit of the remainder p is 0, the round of division is over, and the bit is the double quotient. The value is doubled and the result is given to register r; then the remainder p Shift left one bit, discard the highest bit of the previous round's divisor (already 0), pull one bit of s to supplement it, and get the new remainder p to carry on to the next round. The result r (3 times magnified) is shifted right one bit and supplemented with 0. Then, when s is exhausted, the result r and the dividend p constitute the final quotient and remainder.
+
++0- ++
_____________ _______
+0- )+0++0+ +- )+0+
-0+ -+
____________ ______
0+-+ 0++
-0+ -+
____________ ______
00-0 +-
000 -+
____________ ______
-0+ 0
+0-
____________ Add +0 and +- ,quotient get +--
0
==Square roots and cube roots==
Line 375 ⟶ 546:
...
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}=
\begin{cases}
0, & y=0\\
\end{cases}
Line 387 ⟶ 558:
1. 1 T 1 0 ...
_____________________
− 1 1<1T<10T,set 1
_______
Line 416 ⟶ 587:
1T10T000000
...
Hence {{radic|2|3}}<sub>dec</sub> = {{radic|1T|10}}<sub>bal3</sub> = 1.259921<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
| class = cs.CL
| eprint = 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==
* [[
* [[Methods of computing square roots]]
* [[
* [[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://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]]
|