Ternary numeral system

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

The ternary numeral system (also called base 3) has three as its base. Analogous to a bit, a ternary digit is a trit (trinary digit). One trit is equivalent to log2 3 (about 1.58496) bits of information.

Although ternary most often refers to a system in which the three digits are all non–negative numbers, specifically 0, 1, and 2, the adjective also lends its name to the balanced ternary system, comprising the digits −1, 0 and +1, used in comparison logic and ternary computers.

Comparison to other bases[edit]

A ternary multiplication table
× 1 2 10 11 12 20 21 22 100
1 1 2 10 11 12 20 21 22 100
2 2 11 20 22 101 110 112 121 200
10 10 20 100 110 120 200 210 220 1000
11 11 22 110 121 202 220 1001 1012 1100
12 12 101 120 202 221 1010 1022 1111 1200
20 20 110 200 220 1010 1100 1120 1210 2000
21 21 112 210 1001 1022 1120 1211 2002 2100
22 22 121 220 1012 1111 1210 2002 2101 2200
100 100 200 1000 1100 1200 2000 2100 2200 10000

Representations of integer numbers in ternary do not get uncomfortably lengthy as quickly as in binary. For example, decimal 365 corresponds to binary 101101101 (nine digits) and to ternary 111112 (six digits). However, they are still far less compact than the corresponding representations in bases such as decimal – see below for a compact way to codify ternary using nonary and septemvigesimal.

Numbers from 1 to 27 in standard ternary
Ternary 1 2 10 11 12 20 21 22 100
Binary 1 10 11 100 101 110 111 1000 1001
Decimal 1 2 3 4 5 6 7 8 9
Ternary 101 102 110 111 112 120 121 122 200
Binary 1010 1011 1100 1101 1110 1111 10000 10001 10010
Decimal 10 11 12 13 14 15 16 17 18
Ternary 201 202 210 211 212 220 221 222 1000
Binary 10011 10100 10101 10110 10111 11000 11001 11010 11011
Decimal 19 20 21 22 23 24 25 26 27
Powers of 3 in ternary
Ternary 1 10 100 1000 10000
Binary 1 11 1001 11011 1010001
Decimal 1 3 9 27 81
Power 30 31 32 33 34
Ternary 100000 1000000 10000000 100000000 1000000000
Binary 11110011 1011011001 100010001011 1100110100001 100110011100011
Decimal 243 729 2187 6561 19683
Power 35 36 37 38 39

As for rational numbers, ternary offers a convenient way to represent 1/3 (as opposed to its cumbersome representation as an infinite string of recurring digits in decimal); but a major drawback is that, in turn, ternary does not offer a finite representation for 1/2 (nor for 1/4, 1/8, etc.), because 2 is not a prime factor of the base; as with base 2, 1/10 is not representable exactly (that would need e.g. base 10); nor is 1/6.

Fractions in ternary
Fraction 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/10 1/11 1/12 1/13
Ternary 0.1 0.1 0.02 0.0121 0.01 0.010212 0.01 0.01 0.0022 0.00211 0.002 0.002
Binary 0.1 0.01 0.01 0.0011 0.001 0.001 0.001 0.000111 0.00011 0.0001011101 0.0001 0.000100111011
Decimal 0.5 0.3 0.25 0.2 0.16 0.142857 0.125 0.1 0.1 0.09 0.083 0.076923

Sum of the digits in ternary as opposed to binary[edit]

The value of a binary number with n bits that are all 1 is 2n − 1.

Similarly, for a number N(b, d) with base b and d digits, all of which are the maximal digit value b − 1, we can write:

N(b, d) = (b − 1)bd−1 + (b − 1)bd−2 + … + (b − 1)b1 + (b − 1)b0,
N(b, d) = (b − 1)(bd−1 + bd−2 + … + b1 + 1),
N(b, d) = (b − 1)M.
bM = bd + bd−1 + … + b2 + b1 and
M = −bd−1 − bd−2 − … − b1 − 1, so
bM − M = bd − 1, or
M = bd − 1/b − 1.

Then

N(b, d) = (b − 1)M,
N(b, d) = (b − 1)(bd − 1)/b − 1, and
N(b, d) = bd − 1.

For a three-digit ternary number, N(3, 3) = 33 − 1 = 26 = 2 × 32 + 2 × 31 + 2 × 30 = 18 + 6 + 2.

Compact ternary representation: base 9 and 27[edit]

Nonary (base 9, each digit is two ternary digits) or septemvigesimal (base 27, each digit is three ternary digits) can be used for compact representation of ternary, similar to how octal and hexadecimal systems are used in place of binary.

Practical usage[edit]

In certain analog logic, the state of the circuit is often expressed ternary. This is most commonly seen in CMOS circuits, and also in transistor–transistor logic with totem-pole output. The output is said to either be low (grounded), high, or open (high-Z). In this configuration the output of the circuit is actually not connected to any voltage reference at all. Where the signal is usually grounded to a certain reference, or at a certain voltage level, the state is said to be high impedance because it is open and serves its own reference. Thus, the actual voltage level is sometimes unpredictable.

A rare "ternary point" is used to denote fractional parts of an inning in baseball. Since each inning consists of three outs, each out is considered one third of an inning and is denoted as .1. For example, if a player pitched all of the 4th, 5th and 6th innings, plus 2 outs of the 7th inning, his Innings pitched column for that game would be listed as 3.2, meaning ​3 23. In this usage, only the fractional part of the number is written in ternary form.

Ternary numbers can be used to convey self–similar structures like the Sierpinski triangle or the Cantor set conveniently. Additionally, it turns out that the ternary representation is useful for defining the Cantor set and related point sets, because of the way the Cantor set is constructed. The Cantor set consists of the points from 0 to 1 that have a ternary expression that does not contain any instance of the digit 1.[1][2] Any terminating expansion in the ternary system is equivalent to the expression that is identical up to the term preceding the last non-zero term followed by the term one less than the last nonzero term of the first expression, followed by an infinite tail of twos. For example: 0.1020 is equivalent to 0.1012222... because the expansions are the same until the "two" of the first expression, the two was decremented in the second expansion, and trailing zeros were replaced with trailing twos in the second expression.

Ternary is the integer base with the lowest radix economy, followed closely by binary and quaternary. It has been used for some computing systems because of this efficiency. It is also used to represent three-option trees, such as phone menu systems, which allow a simple path to any branch.

A form of redundant binary representation called balanced ternary or signed-digit representation is sometimes used in low-level software and hardware to accomplish fast addition of integers because it can eliminate carries.[3]

Binary-coded ternary[edit]

Simulation of ternary computers using binary computers, or interfacing between ternary and binary computers, can involve use of binary-coded ternary (BCT) numbers, with two bits used to encode each trit.[4][5] BCT encoding is analogous to binary-coded decimal (BCD) encoding. If the trit values 0, 1 and 2 are encoded 00, 01 and 10, conversion in either direction between binary-coded ternary and binary can be done in logarithmic time.[6] A library of C code supporting BCT arithmetic is available.[7]

Tryte[edit]

Some ternary computers such as the Setun defined a tryte to be six trits[8] or approximately 9.5 bits (holding more information than the de facto binary byte).[9]

See also[edit]

References[edit]

  1. ^ Soltanifar, Mohsen (2006). "On A sequence of cantor Fractals". Rose Hulman Undergraduate Mathematics Journal. 7 (1). Paper 9.
  2. ^ Soltanifar, Mohsen (2006). "A Different Description of A Family of Middle–α Cantor Sets". American Journal of Undergraduate Research. 5 (2): 9–12.
  3. ^ Phatak, D. S.; Koren, I. (1994). "Hybrid signed–digit number systems: a unified framework for redundant number representations with bounded carry propagation chains" (PDF). IEEE Transactions on Computers. 43 (8): 880–891. doi:10.1109/12.295850.
  4. ^ Frieder, Gideon; Luk, Clement (February 1975). "Algorithms for Binary Coded Balanced and Ordinary Ternary Operations". IEEE Transactions on Computers. C-24 (2): 212–215. doi:10.1109/T-C.1975.224188.
  5. ^ Parhami, Behrooz; McKeown, Michael (2013-11-03). "Arithmetic with Binary-Encoded Balanced Ternary Numbers". Proceedings 2013 Asilomar Conference on Signals, Systems and Computers. Pacific Grove, CA, USA: 1130–1133.
  6. ^ Jones, Douglas W. (June 2016). "Binary Coded Ternary and its Inverse".
  7. ^ Jones, Douglas W. (2015-12-29). "Ternary Data Types for C Programmers".
  8. ^ Impagliazzo, John; Proydakov, Eduard (2011-09-06). Perspectives on Soviet and Russian Computing: First IFIP WG 9.7 Conference, SoRuCom 2006, Petrozavodsk, Russia, July 3—7, 2006, Revised Selected Papers. Springer. ISBN 978-3-64222816-2.
  9. ^ Brousentsov, N. P.; Maslov, S. P.; Ramil Alvarez, J.; Zhogolev, E. A. "Development of ternary computers at Moscow State University". Retrieved 2010-01-20.

Further reading[edit]

External links[edit]