Skip to main content

Ternary Computing Concepts

Why Ternary?​

Modern computing is built entirely on binary -- ones and zeros, true and false, on and off. But binary is not the mathematically optimal number system. That distinction belongs to ternary, the base-3 system, which achieves the lowest radix economy of any integer base. Trinity is built on this mathematical foundation.

Information Density​

The information content of a single digit in any base is measured by its Shannon entropy: log2(base) bits per digit. For binary, this is exactly 1 bit per digit. For ternary, it is log2(3) = 1.585 bits per digit -- a 58.5% improvement over binary for each individual symbol.

This metric, known as radix economy, asks: given a fixed "budget" of hardware (where cost scales with the number of distinct states per digit times the number of digits needed), which base represents numbers most efficiently? The continuous optimum is Euler's number e = 2.718..., and among integers, 3 is the closest. Ternary achieves 100% radix efficiency, while binary reaches only 94.7% and quaternary (base-4) drops to 91.0%.

In practical terms, a ternary digit (called a trit) carries more information than a binary digit (a bit). Fewer trits are needed to represent the same range of values, which translates directly into denser storage and fewer operations.

Balanced Ternary​

Trinity uses balanced ternary, where each trit takes a value from the set {-1, 0, +1} rather than the conventional {0, 1, 2}. This representation has several elegant properties:

  • Negation is trivial. To negate a balanced ternary number, simply flip the sign of every trit. There is no need for two's complement or special handling of signed values.
  • Rounding is built in. Truncating a balanced ternary number automatically rounds to the nearest value, unlike binary truncation which always rounds down.
  • Zero has a unique representation. There is no distinction between positive and negative zero.

These properties make balanced ternary particularly well-suited for arithmetic, signal processing, and neural network weights where symmetric value ranges are natural.

Why {-1, 0, +1} Instead of {0, 1, 2}?​

Conventional ternary uses {0, 1, 2}, but balanced ternary uses {-1, 0, +1}. The choice is deliberate and gives three concrete advantages:

  1. Negation is a sign flip. In conventional ternary, negating a number requires a borrow chain (like subtraction). In balanced ternary, you flip every trit: +1 becomes -1, -1 becomes +1, and 0 stays 0. One pass, no carries.
  2. Multiplication by zero means "don't care." A zero trit naturally creates sparsity. In a neural network weight matrix, zero trits skip computation entirely. This gives you free pruning without any special mechanism.
  3. Symmetry around zero eliminates bias. The value range is symmetric: -1 and +1 are equidistant from zero. There is no inherent positive or negative skew. This matters for weight initialization and signal processing.

Memory Savings in Practice​

To make the density advantage concrete, consider a codebook of 10,000 concepts. Each concept is a 4000-dimensional vector.

FormatBytes per elementTotal size
float32 (standard)4.0 bytes160 MB
int8 (quantized)1.0 byte40 MB
Ternary packed (Trinity)0.2 bytes (1.58 bits)1.6 MB

That is a 100x savings over float32. The packed ternary format stores the same information in a fraction of the space because each trit needs only 1.58 bits instead of 32.

Energy Efficiency and Compute​

In the context of neural networks and large language models, ternary weights {-1, 0, +1} eliminate the need for multiplication entirely. Multiplying by +1 is a no-op, multiplying by -1 is a sign flip, and multiplying by 0 zeros out the value. This reduces matrix-vector products to pure addition and subtraction, dramatically lowering power consumption and silicon area compared to floating-point arithmetic.

The BitNet b1.58 architecture exploits this directly: model weights are quantized to ternary values, achieving memory savings of approximately 20x compared to float32 while maintaining competitive model quality.

Connection to Trinity​

The Trinity framework implements these ideas in a practical computing system. At its core is a Vector Symbolic Architecture (VSA) that performs hyperdimensional computing with ternary vectors. The HybridBigInt storage format packs trits at 1.58 bits each using an efficient 2-bit encoding. The Ternary Virtual Machine executes stack-based bytecode natively in ternary. And the Firebird engine performs LLM inference using ternary BitNet weights.

The mathematical justification for all of this traces back to a single identity: the golden ratio squared plus its reciprocal squared equals exactly three. This is the Trinity Identity, and it connects the golden ratio -- the constant of optimal proportion -- to the number three -- the optimal computing base. It is the theoretical anchor for the entire project.

Further Reading​