T27.AI

Blog

The ternary machine: a course where every widget is a compiled t27 spec

2026-10-11 · 4 min read

[the widgets run in the browser; the TRI-27 modules follow the pinned emulator, the rest teaches with small numbers] Course 8 on t27.ai: 27 lessons from why base 3 is cheapest (39 against 40 for every number up to 999999) through balanced ternary, Kleene logic, adders, multiplying without a multiplier, five trits in a byte, the TRI-27 instruction word and a ternary machine, to neurons with weights -1, 0, +1.

Title card, no illustration yet, for: The ternary machine: a course where every widget is a compiled t27 spec
View the title card at full size
#t27#Ternary#Course

t27.ai has a new course, the eighth: The ternary machine. It starts from why base 3 at all and ends with neurons whose weights are -1, 0 and +1, in 27 lessons of 9 modules. Each lesson opens a widget to press, and every number a widget shows is computed by a t27 spec compiled to WebAssembly in your browser, not written into the page.

Why three, and what the argument leaves out

Price a digit by how many states it must tell apart, and a number costs base times digits. The first widget runs radix_economy.t27: every number up to 999999 costs 39 in base 3 and 40 in bases 2 and 4, because b / ln b is smallest at e and 3 is the nearest whole base. The lesson also says what that model omits: binary won because two-state parts are cheap, fast and robust.

Balanced ternary does arithmetic without special cases

With digits -1, 0 and +1 a number needs no sign, negation flips every trit, and cutting trits is already rounding. Adding is a full adder per place; the figure below is the ripple-carry widget's opening case, drawn from the same compiled trits.t27 the widget runs.

carry in00+++0x = 13000+++y = 100000+sum = 1400+−−−1392781243
13 + 1 in balanced ternary, six places: the ones place makes 2 = 3 - 1, a carry of +1 ripples through three places, and +++ becomes +---, which is 14. Every tile is trit_at(), carry_into() or full_sum() of the compiled trits.t27.

Multiplying by a trit is a switch: copy, drop or flip. That is the reason ternary neural networks are cheap in hardware, and the course ends there: a MAC that only adds and subtracts, a neuron that can answer not sure, a bar detector and a small layer.

The TRI-27 machine, as the emulator really runs it

Two modules leave the toy world. The instruction word is the 32-bit word the pinned Trinity emulator decodes: 47 of 256 opcode bytes mean something and the other 209 decode as NOP. The widgets call encode(), opcode_of() and the rest from specs/isa/ternary_encoding.t27. A ternary machine of three 9-trit registers then runs a loop that ends itself on a three-way jump.

How it is built

The logic is two new specs in gHashTag/t27, trits.t27 and radix_economy.t27: 21 tests, every one executing its asserts, 8 negative controls caught. They read balanced trits through the offset 111...1 in base 3, so no signed division is needed. The 27 widgets share one drawing kit that computes nothing; scripts/widget-logic.mjs holds every compiled logic.js to the spec beside it. Lesson texts quote only numbers the specs or widgets produce, and where a lesson spec is a different machine, such as the binary adders built from ternary neurons, the text says so.

What this does not settle

Receipts

Work with me

Need arithmetic built for your constraints?

I design low-precision and ternary formats, synthesizable RTL, independent reference models and bit-exact vectors. Existing measured cores can also be licensed.