◀ THE FOLD0ROOT.AI // WORLD II · CO-OP · THE BROADCAST◆ .dlw.fold
THE FOLD / CO-OP / THE BROADCAST / THE TUNSTALL CODE

THE TUNSTALL CODE

variable strings to fixed-length codes — Huffman's dual
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
Tunstall coding is Huffman’s mirror image: where Huffman maps variable-length source symbols to variable-length codes, Tunstall maps variable-length source strings to fixed-length codes. It builds a dictionary by starting with the alphabet and repeatedly splitting the most probable leaf into its children, until it has 2R entries — then every entry gets the same R-bit codeword. Long, likely strings get a whole codeword each, so common runs compress into one fixed block.

LIT verified live: over 200 random streams, greedy parse + fixed-code encode round-trips exactly, and every codeword is the same length (window.__tunstall). FIG no framing; exact.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this at the-broadcast — the channel that wants fixed-size packets, so the coder must pack variable source runs into equal blocks. Tunstall coding is that packer. AVAN (AI) built the instrument: the fattest-leaf dictionary growth, the greedy longest-match parse, the fixed-length codes, and the round-trip check.

Credit as content: Brian Parker Tunstall (1967). The weave: David names the broadcast; I grow the dictionary by splitting the most probable leaf, parse the source greedily, and confirm the fixed-length codes decode back to the exact input.
3 ONE DIMENSION
Start with {0, 1}. Repeatedly take the most probable leaf and split it into leaf+0 and leaf+1. Stop at 2R leaves; give each an R-bit code. Probable strings become single codewords.
4 TWO DIMENSIONS · INTERACTIVE
A Tunstall dictionary for chosen source probabilities; a stream is parsed, coded, and decoded back, with the round-trip and fixed length checked.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: variable source strings, each a fixed-length codeword.
AVAN’s addition (the inverse-companion): compress by mapping variable-length source strings to fixed-length codes — grow a dictionary by splitting the most probable leaf, so likely runs each become one codeword. The inverse of ‘Huffman: variable code, fixed symbol’ is ‘Tunstall: fixed code, variable string.’ Magenta is the variable-length codewords Huffman would emit; green is Tunstall’s equal blocks. Huffman’s dual.
LIT Genuine Tunstall variable-to-fixed coding (Tunstall 1967). Verified live: building the dictionary by repeatedly splitting the most probable leaf to 2^R entries, greedy longest-match parse followed by fixed R-bit coding round-trips to the exact input over 200 random streams, and every codeword is the same length (window.__tunstall.roundTrip && .fixedLength).

FIG No framing: the fattest-leaf dictionary growth, the greedy longest-match parse, the fixed-length codes, and the round-trip check run in-browser and hold. The AVAN inverse is honest — mapping variable-length source strings to fixed-length codes (the dual of Huffman's variable code / fixed symbol) makes likely runs into single codewords; magenta is the variable-length codewords Huffman would emit, green Tunstall's equal blocks. Huffman's dual.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE BROADCAST · David Lee Wise (ROOT0), with AVAN