Asymmetric numeral systems
Jarek Duda
cs.IT, cs.CR, math.GM
2009-02-03
Extends numeral systems to arbitrary distributions: one-state, table-driven entropy coding with arithmetic-coding precision at Huffman speed, plus encryption and error correction.
The last stage of any compressor is an entropy coder: a model supplies symbol probabilities, and the coder turns the symbol stream into the shortest possible bit stream. In 2009 both mainstream options had hard flaws. Huffman coding is fast but approximates every probability with a power of two, losing precision on everything else. Arithmetic and range coding are exact, but they track an interval with two numbers and multiply per symbol, which caps throughput.
Jarek Duda (Jagiellonian University) started from a different observation: standard numeral systems are already optimal coders for equiprobable symbols, so generalizing them to arbitrary distributions yields an exact coder that runs on a single natural number.
The entire encoder state is one natural number x; coding a symbol is a single bijective map on x. Arithmetic coding stores each symbol's information at the most significant position by choosing a subinterval; ANS stores it at the least significant position. Split {0, ..., x-1} into n subsets with sizes close to x·qs (qs being the symbol probability), and instead of giving each symbol one contiguous block as in range coding, spread the subsets uniformly across the range. Decoding reads which subset x falls in to recover the symbol, and the index inside the subset becomes the new x; encoding one step turns x into roughly x/qs, storing lg(1/qs) bits, with precision limited only by how far xs drifts from x·qs.
Three concrete forms:
Encryption falls out of the random initialization: the key seeds the PRNG that builds the tables, so each key produces a different coder. Verifying a key requires rebuilding the whole table first, and the author notes that initialization cost can be set deliberately, around 0.1 s per key, making each brute-force attempt orders of magnitude more expensive than with standard ciphers.
For error correction, add a forbidden symbol with probability pd to the table. After a transmission error the decoder emits a near-random symbol stream, and each step has probability pd of hitting a forbidden state and flagging the error. Correction becomes path tracing; once pd passes a threshold, the number of candidate corrections stops growing exponentially, giving expected linear (or N lg N) correction time.
| Item | ANS | Reference |
| Coder states | 1 | arithmetic/range coding: 2 |
| Bits per table lookup | 8, table under 100 kB | Huffman: 1 symbol per step |
| Gap to Shannon entropy | tunable below 1/1000 bit/symbol | author calls own bounds 10-100x pessimistic |
| Error-correction redundancy (pb=0.01) | near 0.088 bit/bit | (7,4) Hamming: 0.75, silently losing 16 bits/kB |
| Correction time | expected linear or N lg N | LDPC, framed as solving an NP problem |
The bias of output digits is about (b-1)·n/(b²·ln b·l); with l between 10^5 and 10^6, tables stay cache-sized and observing the effect would take gigabytes of output. The practical correction threshold sits above the Shannon limit, needing up to twice its redundancy as the noise level approaches 0.5. The paper contains no direct throughput benchmark against arithmetic coding; it points to Matt Mahoney's fpaqa/fpaqc implementations.
A single state delivers arithmetic-coding compression at table-lookup speed, with encryption and error correction sharing the same tables. The lineage matters: zstd, LZFSE, and JPEG XL all carry direct descendants of this coder as their entropy stage, so anyone using those compressors today is running these ideas underneath. Methodologically it is not an incremental patch on arithmetic coding; it moves where the information is stored.
Author-acknowledged: no explicit formulas beyond the binary case, so tables are mandatory; a changed probability distribution forces reinitialization, and adaptive coding means either storing many tables or a two-pass backward encode, since encoding and decoding run in opposite directions. The statistics section repeatedly calls its own estimates very rough; the 1/x state distribution is explicitly unproven, only simulation-matched, and pathological cases exist where the coder stays trapped in a subset of states.
The cryptography and error-correction sections deserve more skepticism. The crypto part is the author listing attack surfaces and countermeasures himself, admitting the list may be incomplete, with no formal analysis and no measurements behind the "faster than standard block ciphers" claim. The correction thresholds rely on Gaussian approximations, and practical variants need redundancy above Shannon's limit. The whole paper reads as single-author working notes in the first person, with many conclusions resting on "numerical simulations show".