Coding theory is the mathematics of surviving error — sending a message through a noisy channel and recovering it intact even when some symbols get corrupted. The RAID levels you recognized, the parity in your kernel, the witness that locates a fault — all of it lives here. This primer stays in base 3: trits, not bits. Three states { −, 0, + }, balanced around zero — and a parity that doesn't just say that an error happened but which way it broke.
Send a message across any real channel — wire, radio, disk, DNA, a copied corpus — and some symbols flip. The naïve fix is to repeat: send everything three times, take the majority. It works, but it's wasteful — you tripled the data to survive one flip. Coding theory asks the sharper question: what is the least redundancy that still recovers the message? The answer is to add a few carefully-computed check symbols that constrain the whole, so a corruption breaks a constraint and reveals itself. Not brute repetition — structured redundancy.
A bit holds 2 states; a trit holds 3. So one trit carries log₂3 ≈ 1.585 bits of information — more per symbol. And n trits encode 3ⁿ values: 3, 9, 27, 81… Balanced ternary makes each trit { −1, 0, +1 }, symmetric about zero — which gives the codes a property binary can't have cleanly: an error has not just a magnitude but a sign, a direction. A flipped trit went up or down, and balanced-ternary parity can tell which.
| symbol | states | info each | n symbols encode |
|---|---|---|---|
| bit | 2 (0,1) | 1.000 bit | 2ⁿ |
| trit | 3 (−0+) | 1.585 bit | 3ⁿ |
The Hamming distance between two words is the number of positions where they differ. It is the master quantity of coding theory, because it sets everything: if every pair of valid codewords is at least distance d apart, then the code detects d−1 errors and corrects ⌊(d−1)/2⌋. Intuition: spread your valid codewords far apart in symbol-space, and a corrupted word is still closest to the one you meant — so you snap it back. Bigger minimum distance = more errors survived, paid for in redundancy.
The simplest real code: add one check trit equal to the negative sum of the data trits (mod 3, balanced). Now the total of all trits is ≡ 0. Corrupt any one trit and the total is no longer zero — error detected. The beautiful part, unique to balanced ternary: the leftover total isn't just "nonzero," it's itself a trit — 0 means clean, +1 or −1 tells you the direction the error pushed. The check residue is a tiny compass. Try it:
Parity detects but can't say where. The ternary Hamming code can. Using r = 2 check trits over 4 total — written [4, 2, 3]₃ — it carries 2 data trits and corrects 1 error by pointing at its position. The check trits form an address: when an error occurs, the pattern of failed checks is the coordinate of the broken trit, in balanced ternary. This is your kernel's "3 locates" in its native habitat — the witness that doesn't just see a fault but names it. The same structure scales: more check trits, larger codes, more errors located.
Some codes are perfect: they pack codewords so tightly that every possible word is within correcting-distance of exactly one codeword — no symbol-space wasted, no gaps. Perfect codes are rare and precious; only a handful exist. One of them is ternary: the Golay code [11, 6, 5]₃ — 6 data trits inside 11, corrects 2 errors, and tiles the space flawlessly. It's one of the most elegant objects in the field, and it lives in base 3. When you reached for ternary as the substrate of a witness kernel, you reached toward the base that hosts a perfect code — not a reason in itself, but a sign you were in good territory.
Coding theory is the floor under everything you've been building: parity is your single witness; the Hamming code is "3 locates"; distance-d codes are "tolerate d−1 faults" = the RAID progression; independence reappears as the rule that errors must be uncorrelated or a burst defeats the code (which is why real systems interleave — spreading correlated errors apart so the code sees them as separate). Same skeleton you've met all series: redundancy across independent parts, a residue that witnesses, a bound on how much corruption truth survives. Now you have the field's name for it — and it speaks ternary.