◀ THE FOLD0ROOT.AI // WORLD II · LOOT · THE VAULT◆ .dlw.fold
THE FOLD / LOOT / THE VAULT / THE ZIGZAG

THE ZIGZAG

a subsidy paid by positives to rescue negatives
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
A varint assumes small numbers are cheap, and two’s complement makes −1 the largest number there is. Zigzag interleaves positive and negative so that small magnitudes stay small whichever side of zero they are on.

LIT verified live. Every value from −100,000 to 100,000200,001 of them — maps and maps back with 0 failures: the encoding is a bijection, not an approximation. −1 becomes 1 and costs 1 byte, where the two’s-complement bit pattern would cost 10. That is 9 bytes saved on the most common small negative there is.
2 HOW IT WAS WEAVED · AI + HUMAN
Zigzag is the sint32 and sint64 types in Protocol Buffers, and it exists solely because varints and two’s complement disagree about what “small” means.

AVAN (AI) checked bijectivity across the whole range rather than spot-checking the mapping, because an encoding that is almost reversible is worthless. 200,001 of 200,001 is the claim; the byte counts are the payoff, and the interesting one is that zero costs the same either way — the saving is entirely on the negative side.
3 ONE DIMENSION
The interleave, and what each value costs.
4 TWO DIMENSIONS · INTERACTIVE
Cross zero and watch the cost stay flat.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: a number line folded at zero.
AVAN’s addition (the inverse-companion): the forward reading is that zigzag makes negative numbers cheap. The inverse is that it makes the sign bit expensive for everyone. Every positive value now costs one extra bit of magnitude, because the low bit has been given to the sign — so the encoding is a subsidy paid by common positives to rescue common negatives. Read backwards, this is a bet about your data, and if your values are never negative it is a bet you lose on every single one.
LIT every value from -100,000 to 100,000 - 200,001 of them - maps and maps back with 0 failures, so the encoding is a bijection rather than an approximation, and -1 becomes 1 costing 1 byte where the two's-complement bit pattern would cost 10, saving 9 bytes on the most common small negative there is

FIG Zigzag is the sint32 and sint64 types in Protocol Buffers, and it exists solely because varints and two's complement disagree about what small means. AVAN checked bijectivity across the whole range rather than spot-checking the mapping, because an encoding that is almost reversible is worthless. 200,001 of 200,001 is the claim; the interesting payoff is that zero costs the same either way, so the saving is entirely on the negative side.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE VAULT · David Lee Wise (ROOT0), with AVAN