AI Glossary / MLOps and deployment / Advanced
Asymmetric numeral systems
Definition
Asymmetric numeral systems (ANS) are a family of lossless entropy-coding methods that represent symbols by reversible changes to an integer state and a stream of bits. Developed by Jarek Duda, they allocate coding effort according to symbol probabilities while supporting efficient implementations.
What it means
Appending either binary digit adds one bit. Compression treats unequal probabilities differently: common symbols should usually contribute less information than rare ones.
ANS generalizes the state-update idea so different symbols occupy different shares of the representational space. The probability model remains separate from the actual observed data: the coder uses a model but does not guarantee that the model predicts well.
The family includes range ANS, usually written rANS, and table-based ANS, or tANS. Their implementation techniques differ. ANS is not a single complete file format, and using its name does not specify model tables, block structure or compatibility.
How it works
A coding step combines a symbol with the current integer state to produce a new state. A corresponding decoding step recovers both that symbol and the previous state. The mapping is designed so more probable symbols generally cause less growth in the state's information content.
Practical coders keep the state within a manageable range by transferring bits or bytes between the state and an output stream. This process is often called renormalization. The decoder performs the corresponding inverse operations.
Decoding behaves like a stack, undoing the latest encoding step first. Implementations arrange processing and output accordingly. This matters when probabilities depend on earlier decoded context; a designer must make the required models available in the correct order.
In rANS, arithmetic formulas implement the mapping. Table-based variants precompute transitions for a finite state set. Both need exact agreement about frequencies and state rules. Their speed and compression depend on implementation, alphabet, model precision and workload, not merely the method's name.
Three practical examples
1. Compression engineering: A developer can use an ANS coder as the final stage after another process has converted input into predictable symbols. The earlier representation and probability model still influence total size.
2. Learned compression research: A model can estimate symbol probabilities, which an entropy coder turns into bits. ANS contributes coding mechanics; the learned model supplies the distribution.
3. Format review: An engineer examining an ANS-based format checks frequency-table representation, state initialization and block boundaries to determine whether an independent decoder can reconstruct the data.
Think of it this way
Think of packing tokens onto a reversible numerical stack. Each push changes the stack's state according to a shared rule; each pop reveals the last token and restores the previous state.
Unlike a literal stack of equally sized objects, symbols can have different information costs. A bitstream keeps the state bounded; one small integer cannot hold an unlimited message.
Worked example
Worked example
Consider a toy rANS calculation without finite-state renormalization. Use frequencies f(A) = 3 and f(B) = 1, with total M = 4. Their cumulative starting positions are c(A) = 0 and c(B) = 3.
For symbol s and state x, use the encoding formula x_new = 4 × floor(x/f(s)) + c(s) + (x mod f(s)). Start at x = 10.
Encode A: floor(10/3) = 3 and 10 mod 3 = 1, so the new state is 4 × 3 + 0 + 1 = 13. Encode B next: floor(13/1) = 13 and the remainder is zero, giving 4 × 13 + 3 = 55.
To decode, examine state mod 4. Remainders 0, 1 and 2 identify A; remainder 3 identifies B. For 55, remainder 3 identifies B. The preceding state is f(B) × floor(55/4) + 3 - c(B) = 13.
For 13, remainder 1 identifies A. Its preceding state is 3 × floor(13/4) + 1 - 0 = 10. Decoding has recovered B then A and returned to the initial state.
This demonstrates reversibility and reverse order. It is not a complete bitstream encoder: practical state limits, emitted bytes, termination and frequency metadata are omitted.
Illustrative case study
Illustrative case study - fictional
A fictional research team builds a compressor for model-generated symbol sequences. It chooses rANS but initially assumes it can feed an adaptive probability model in any order.
A small test fails because the decoder reconstructs symbols in an order different from the model updates used during encoding. The team redesigns its block procedure so the required probability information is available consistently at both ends.
It then checks exact reconstruction and measures complete file sizes, including model metadata and state storage. The hypothetical case illustrates the need for a coherent format.
Common misconceptions and mistakes
- Asymmetric does not mean public-key cryptography; ordinary ANS is not encryption.
- ANS is lossless for its input symbols, even when a larger pipeline quantizes data beforehand.
- A small integer state is accompanied by output bits or bytes; it is not unlimited storage.
- Model precision, block overhead and symbol statistics affect compression.
- Basic stack-like decoding order must be accounted for when integrating contextual probability models.
Business use
ANS is relevant when assessing storage formats, media compression components and learned compression systems. Evaluate reference decoding, format documentation and realistic throughput.
Compare total bytes and processor costs under the same modeling assumptions. Small blocks increase relative table and state overhead; larger blocks can complicate random access. For AI applications, verify whether the complete pipeline promises exact data recovery or only approximate reconstruction. An entropy coder's losslessness alone does not settle that question.
People also ask
Is ANS a replacement for a probability model?
No. It represents symbols using a distribution supplied by the surrounding compression design.
Are rANS and tANS interchangeable bitstream formats?
No. They are related approaches with different state mappings and implementation requirements.
Does the decoder always return the original message backwards to the user?
No. The basic coding steps reverse one another, but an implementation can arrange encoding and block handling so the user receives the intended order.
Check your understanding
A toy ANS encoder applies A and then B to its state. Which symbol does the direct inverse state operation recover first?
Answer: B, because decoding first undoes the last encoding step. A complete format must account for this ordering.
Related terms
- Entropy coding
- Arithmetic coding
- Probability model
- Lossless compression
- rANS
- tANS
- renormalisation
Learn next
Repeat the toy calculation with another starting state and verify that decoding returns to it. Then examine how bounded-state renormalization transfers information into bytes instead of allowing the integer to grow indefinitely.
More in MLOps and deployment
- Algorithm BSTW - Algorithm BSTW is a lossless data-compression scheme associated with Jon Bentley, Daniel Sleator, Robert Tarjan and Victor Wei.
- Anamorphic stretch transform - The anamorphic stretch transform (AST) is a signal transformation that uses deliberately nonuniform stretching to reshape a signal for acquisition or...
- AND-parallelism - AND-parallelism means solving required subproblems concurrently when their results must all contribute to the overall solution.
- Audio codec - An audio codec is a method, together with an implementation of that method, for encoding and decoding digital audio.
- Autonomic computing - Autonomic computing is an approach to building computing systems that manage aspects of their own operation according to human-defined goals and policies.
- Average bitrate - Average bitrate is the total number of bits used or transferred divided by the elapsed duration, usually expressed in bits per second.
Sources
Sources: Jarek Duda, Asymmetric numeral systems: entropy coding combining speed of Huffman coding with compression rate of arithmetic coding: https://arxiv.org/abs/1311.2540 ; earlier ANS paper: https://arxiv.org/abs/0902.0271 . The later paper's state mappings, range formulas and stream-renormalisation sections were reviewed; the earlier record was identified for historical context. The example is original.
Previous: Asymmetric multiprocessing Next: Asymmetric relationships