Skip to main content
QUICK REVIEW

[Paper Review] A tutorial on the range variant of asymmetric numeral systems

James T. Townsend|arXiv (Cornell University)|Jan 24, 2020
Algorithms and Data CompressionComputer Science8 references12 citations
TL;DR

This tutorial presents the range variant of asymmetric numeral systems (rANS), a lossless compression technique that serves as a stack-like alternative to arithmetic coding. It provides a mathematically rigorous derivation of rANS, proving compression rates close to the Shannon limit using intuitive diagrams, pseudocode, and a working Python implementation, with key contributions in clarity, formal correctness, and practical accessibility for researchers and practitioners.

ABSTRACT

This paper is intended to be a brief and accessible introduction to the range variant of asymmetric numeral systems (ANS), a system for lossless compression of sequences which can be used as a drop in replacement for arithmetic coding (AC). Because of the relative simplicity of ANS, we are able to provide enough mathematical detail to rigorously prove that ANS attains a compression rate close to the Shannon limit. Pseudo-code, intuitive interpretation and diagrams are given alongside the mathematical derivations. A working Python demo which accompanies this tutorial is available at https://raw.githubusercontent.com/j-towns/ans-notes/master/rans.py.

Motivation & Objective

  • To provide a clear, mathematically rigorous introduction to the range variant of asymmetric numeral systems (rANS) for researchers and practitioners.
  • To demonstrate that rANS achieves compression rates close to the Shannon limit, matching or exceeding arithmetic coding in efficiency.
  • To present the push and pop operations as inverse functions, enabling efficient encoding and decoding of sequences with minimal information loss.
  • To bridge the gap in academic literature by offering a detailed, accessible tutorial on rANS, which is underrepresented in textbooks despite its use in modern compression systems.

Proposed method

  • Uses a message structure (s, t) where s is an integer and t is a stack of fixed-precision integers, with s ≥ 2^{rs - rt} to ensure decoding accuracy.
  • Defines the pop operation via a function d(s) that maps a state s to a symbol x and a new state s′, using precomputed probability weights and cumulative distribution functions.
  • Employs a quantized probability model with precision r, where probabilities are represented as integers pi / 2^r, enabling efficient arithmetic operations.
  • Derives the inverse push operation by inverting the state transition using d^{-1}(s′; p, c) = 2^r · (s′ ÷ p) + (s′ mod p) + c, ensuring correct state reconstruction.
  • Applies renormalization via renorm_inverse to maintain the message within valid bounds by shifting lower-order bits into the stack t when necessary.
  • Uses a Python demo (available at github.com/j-towns/ans-notes) to illustrate the algorithm with visualizations of state transitions and probability distributions.

Experimental results

Research questions

  • RQ1How can rANS be formally derived and proven to achieve compression rates near the Shannon limit using only elementary mathematics and intuitive explanations?
  • RQ2What is the precise mathematical structure of the rANS state transition function, and how can it be inverted to enable efficient encoding?
  • RQ3How does the stack-like (LIFO) decoding of rANS compare to the queue-like (FIFO) decoding of arithmetic coding in terms of implementation complexity and performance?
  • RQ4What are the necessary and sufficient conditions for maintaining message validity during renormalization in rANS, and how can they be enforced algorithmically?
  • RQ5How can rANS be implemented efficiently in practice using integer arithmetic and bit-level operations, while preserving correctness and compression efficiency?

Key findings

  • The rANS decoder pop operation reduces the message length by at most h(x_n | x_1, ..., x_{n-1}) + ϵ bits per symbol, where ϵ is a small constant, ensuring near-optimal compression.
  • The push and pop functions are exact inverses, guaranteeing lossless compression and enabling a correct encoding procedure via sequential push operations.
  • The inverse state transition d^{-1} is explicitly derived as d^{-1}(s′; p, c) = 2^r · (s′ ÷ p) + (s′ mod p) + c, allowing efficient reconstruction of the original state.
  • The renormalization process in renorm_inverse ensures that the state s remains within the required bounds (2^{rs - rt} ≤ s < 2^{rs}) by shifting bits into the stack t, and this process terminates in at most one iteration due to the factor of 2^{rt} reduction.
  • The overall compression length is bounded by h(x_1, ..., x_N) + Nϵ, proving that rANS achieves compression close to the theoretical Shannon limit.
  • The tutorial provides a working Python implementation and visualizations that demonstrate the mapping between states and symbols, confirming the correctness and practicality of the algorithm.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.