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
(section)
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!
== 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}}
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)