Five rules for a weight alphabet
You will learn
What values a ternary weight may take, how five measured rules leave one formula, and what a sixth rule removes from it.
The spec golden_sieve.t27 gives a ternary weight five measured rules and a sixth that narrows what they leave. S1: the number of values is a power of three; S2: at most two trits, as a third gave no significant gain. S3: one accumulator lane, so any two weights have a rational ratio: plus and minus phi pass as a common scale, while 1 and phi need two lanes. S4: at most six input bits per neuron, a trade, not a law, says the spec; S5: no DSP48E1 or SRL16E cells, for which openXC7 wrote a wrong bitstream while every tool said OK. The five leave TNF(k, b) with 3 or 9 levels, and S6 removes the 9-level form: on every integer ladder the top weight outweighs the others added, so one input decides. The browser runs all 3 tests and all 8 invariants.
Try it
Run the tests; then change MAX_TRITS to 3 in the source and see which two checks fail. In the spec frame, trits size a float exponent, not a weight: find exp_values of tnf4 and the test that says which offset is not finite.

The Golden Sieve as a t27 spec: five predicates a ternary weight alphabet must pass, compiled by t27c as WebAssembly in your browser. Seven backends; every test runs in the page.
specs/numeric/tnf4.t27
// SPDX-License-Identifier: Apache-2.0
// tnf4.t27 -- TNF4: Ternary Network Float, 4-bit class (bottom rung).
// Balanced-ternary exponent = 2 trits (3^2 = 9 offsets, exponent +-4, ~2.4
// decades), 1-bit mantissa, NO regime decode.
// layout: [ sign(1) | E = 2 balanced-ternary trits | M = 1 bit ]
//
// Positioning (the 4-bit rung is unique): the format-to-beat here is NOT tekum
// but **BitNet-1.58 ternary WEIGHTS** {-1,0,+1} -- a weight quantizer, not a real
// format. TNF4 is a genuine 4-bit REAL number (magnitude + ~2.4-decade range),
// so it plays the ACTIVATION/value role next to BitNet's weight role, exactly as
// tri_compute_bitnet.t27 attests (ternary weights x GF/TF activations). Against
// the binary 4-bit leader MXFP4 it trades block-scale range for a native ternary
// exponent and no block-decode. phi^2 + 1/phi^2 = 3 | TRINITY
module triformat_tnf4 {
use base::types;
const EXP_TRITS: u32 = 2;
const MANT_BITS: u32 = 1;
const EXP_OFFSET: u32 = 4; // (3^2 - 1) / 2
const OFFSET_MAX: u32 = 8; // 3^2 - 1 (reserved special row)
// 2-trit exponent field -> unsigned offset in [0,8].
fn exp_offset(t0: u32, t1: u32) -> u32 {
return t0 + (3 * t1);
}
fn is_finite(offset: u32) -> bool {
return offset != OFFSET_MAX;
}
fn exp_values() -> u32 {
return 9;
}
// ---- Tests / invariants ----
test offset_range {
assert(exp_offset(0, 0) == 0, "min offset (exponent -4)");
assert(exp_offset(2, 2) == 8, "max offset (reserved special)");
assert(exp_offset(1, 1) == 4, "center offset = exponent 0 (unity)");
}
test finiteness {
assert(is_finite(4) == true, "unity finite");
assert(is_finite(8) == false, "offset 8 special");
assert(exp_values() == 9, "3^2 exponent values (~2.4 decades) in 2 trits");
}
}
All lessons
Module 1 · Lab: our own research
A number format of our own, an honest scoreboard, and a model's tables multiplied on the board.
Module 2 · AI numbers: the MX block
How AI chips keep weights in a few bits: one shared scale per block, the scale byte itself, and what one outlier does to its neighbours.
Module 3 · Ternary weights
Weights that are only minus, zero or plus a scale, the five rules a ternary alphabet must pass, and a test pass that checked nothing.
Module 4 · The Ternary Network Float
A rule the compiler enforces before any test runs, and a 17-bit float whose exponent is four balanced trits.
Module 5 · Arithmetic on signed numbers
Multiply two signed numbers, add them when their signs differ, and do both at once in a multiply-accumulate.
Module 6 · Parts of a neuron
A ReLU that bends at zero, a power of two for softmax, and an argmax that names the answer.
Module 7 · Learning from a mistake
A loss that prices a wrong guess in bits, one step that moves a weight against its gradient, and the hidden layer that XOR needs.
Module 8 · BitNet: ternary networks
A threshold that squeezes a sum back to three values, one neuron that becomes a different function when its weights change, and a neuron that reads its inputs 27 trits at a time.
Module 9 · The ternary MAC as a chip
The 27-trit dot product as wires with no register, the same sum added into a register on every clock, and a small whole network to close the course.