 ## Ternary numbers are a base 3 numeral system.

Base 10 is famously well suited to those of us who count on our fingers. Base 2 dominates computing technology because binary devices are simple and reliable, with just two stable states on or off. The cultural preference for base 10 and the engineering advantages of base 2 have nothing to do with any intrinsic properties of the decimal and binary numbering systems.

Base 3, on the other hand, does have a genuine mathematical distinction in its favor. By one plausible measure, it is the most efficient of all integer bases; it offers the most economical way of representing numbers as it is closer than binary to the most economical radix base(2.718) to represent arbitrary numbers, when economy is measured as the product of the radix and the number of digits needed to express a given range of values.

While you can see at a glance whether a binary number is even or odd by looking at the last digit, it is subtler with ternary in which a numeral represents an even number if the numeral has an even number of 1s.

### Balanced Ternary

The digits of a balanced ternary numeral are coefficients of powers of 3, but instead of coming from the set {0, 1, 2}, the digits are {N, 0 and 1}. They are balanced because they are arranged symmetrically about zero.

Every number, both positive and negative, can be represented in this scheme, and each number has only one such representation. The balanced ternary counting sequence begins: 0, 1, 1N, 10, 11, 1NN, 1N0, 1N1. Going in the opposite direction, the first few negative numbers are N, N1, N0, NN, N11, N10, N1N. Note that negative values are easy to recognize because the leading trit is always negative.

Arithmetic is nearly as simple as it is with binary numbers; in particular, the multiplication table is trivial. Addition and subtraction are essentially the same operation: Just negate one number and then add. Negation itself is also effortless: Change every N into a 1, and vice versa. Rounding is mere truncation: Setting the least-significant trits to 0 automatically rounds to the closest power of 3.

Perhaps the prettiest number system of all is the balanced ternary notation. Donald E. Knuth, The Art of Computer Programming

## Notes on Ternary Logic.

Along with ternary arithmetic, a computer built of ternary hardware can also exploit ternary logic. Consider the task of comparing two numbers. In a machine based on binary logic, comparison is often a two-stage process. First you ask, "Is x less than y?"; depending on the answer, you may then have to ask a second question, such as "Is x equal to y?" Ternary logic simplifies the process: A single comparison can yield any of three possible outcomes: "less," "equal" and "greater."

### Reversible Gates

• NOP: The most dull gate (number 8) this does not change the input. It is its own complement. Applying it any number of times get you back to your intial value.
• NEG Gate: Balanced ternary gates have a tighter relationship between logical and mathmatical negation. The are the same bitwise operator. It is its own complement. Applying it multiple time every even application brings back the intial value.
• INC and DEC Gate: These gates can arithmetically be thought of as single trit increment or decrement without carry, but with roll over. These gates are also complementary . Every 3 applications of either one of these gates in a row bring back the intial value.
• Gate 2 & 6: The these gates are most intuitively expressed as combinations of NEG, INC and DEC.

### Single Input Gates

+0-NumberNameDefinitions
----13FalseNEG(LAX(LAX))
--0-12NEG(LAX)
--+-11DEC(DEC(LAX))
-0--10AbnNEG(LAX(DEC))
-00-9DEC(LAX(NEG))
-0+-8NegNEG
-+--7isZDEC(DEC(LAX(DEC)))
-+0-6IncDEC(DEC)
-++-5DEC(NEG(LAX(NEG)))
0---4NEG(LAX(NEG))
0-0-3DEC(LAX(DEC))
0-+-2DecDEC
00--1DEC(LAX)
0000ClearDEC(LAX(LAX))
00+1NEG(DEC(LAX))
0+-2NEG(DEC)
0+03NEG(DEC(LAX(DEC)))
0++4LAX(NEG)
+--5FloorDEC(DEC(LAX(NEG)))
+-06DEC(NEG)
+-+7DEC(NEG(LAX(DEC)))
+0-8NOPNEG(NEG)
+009FlatNEG(DEC(LAX(NEG)))
+0+10AbsLAX(DEC)
++-11CeilDEC(NEG(LAX))
++012LaxLAX
+++13TrueLAX(LAX)

Incoming: ternary logic