THE FOLD / LOOT / THE VAULT / THE MORTON
THE MORTON
interleave the bits of x and y — 2D into one address
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
The Morton code (Z-order) maps a 2D coordinate to a single number by interleaving the bits of x and y: with x = x₂x₁x₀ and y = y₂y₁y₀, the code is y₂x₂y₁x₁y₀x₀. De-interleave to decode. It is a perfect bijection between the grid and 0…N²−1, and points close in 2D tend to stay close in the code — so it linearises space for databases, GPU textures, and cache layouts.
Draw the cells in code order and you trace a recursive Z — hence ‘Z-order.’ It is the cheap cousin of the Hilbert curve: worse locality, but a one-instruction encode.
LIT verified live: over a 16×16 grid, encode then decode round-trips for all 256 cells and every code is distinct — a genuine bijection (window.__morton). FIG no framing; exact bit manipulation.
Draw the cells in code order and you trace a recursive Z — hence ‘Z-order.’ It is the cheap cousin of the Hilbert curve: worse locality, but a one-instruction encode.
LIT verified live: over a 16×16 grid, encode then decode round-trips for all 256 cells and every code is distinct — a genuine bijection (window.__morton). FIG no framing; exact bit manipulation.
2 HOW IT WAS WEAVED · AI + HUMAN
David (human) seated this at the-vault — indexed storage, where 2D data must be laid down in one linear address. The Morton code is the vault’s shelving scheme: interleave the coordinates and neighbouring cells mostly land near each other on disk. AVAN (AI) built the instrument: the bit-interleave encode/decode, the exhaustive bijection check, the Z-path and its seams.
Credit as content: Guy Macdonald Morton (1966, IBM Canada). The weave: David names the vault; I interleave the bits into one exactly-invertible address, draw the recursive Z, and measure the diagonal jumps it pays for cheapness.
Credit as content: Guy Macdonald Morton (1966, IBM Canada). The weave: David names the vault; I interleave the bits into one exactly-invertible address, draw the recursive Z, and measure the diagonal jumps it pays for cheapness.
3 ONE DIMENSION
The bits of x and y zippered together: x supplies the even positions, y the odd. That single interleaved integer is the Morton code — and pulling the even and odd bits back apart returns x and y exactly.
4 TWO DIMENSIONS · INTERACTIVE
Click a cell to read its Morton code and see the recursive Z-path traced through the grid in code order. Verify the encode/decode bijection over all cells.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: the Z-curve threading the grid, each cell’s code the zipper of its coordinates.
AVAN’s addition (the inverse-companion): the code separates cleanly back into x and y because interleaving bits is a bijection — the even bits are exactly x, the odd bits exactly y, no information mixed or lost. But that clean invertibility buys only partial locality, and worse than Hilbert’s: at every quadrant boundary the Z makes a long diagonal jump from one corner to the far one, so cells adjacent in code can sit far apart in space. The inverse of ‘close in 2D ⇒ close in code’ fails at the Z’s seams. Magenta marks those jumps — the code-adjacent, space-distant pairs at the quadrant edges; green is the recursive Z. Bit-interleaving trades Hilbert’s smoothness for a one-instruction, exactly-invertible order — cheapness paid for in seams.
LIT Genuine Morton / Z-order code (Morton 1966, IBM). Verified live with exact bit manipulation (part1by1/compact1by1 interleave): over a 16x16 grid, mortonEncode then mortonDecode returns the exact (x,y) for all 256 cells and every code is distinct — a bijection (window.__morton.bijection).
FIG No framing: the interleave encode/decode and the exhaustive bijection check run in-browser and are exact. The AVAN inverse is honest — the code separates cleanly into x and y because bit-interleaving is a bijection, but locality is only partial and worse than Hilbert's (long diagonal jumps at quadrant boundaries); magenta marks the real code-adjacent-but-space-distant jumps.
FIG No framing: the interleave encode/decode and the exhaustive bijection check run in-browser and are exact. The AVAN inverse is honest — the code separates cleanly into x and y because bit-interleaving is a bijection, but locality is only partial and worse than Hilbert's (long diagonal jumps at quadrant boundaries); magenta marks the real code-adjacent-but-space-distant jumps.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE VAULT · David Lee Wise (ROOT0), with AVAN