Table of Contents
Fetching ...

Efficiency of ANS Entropy Encoders

Dmitry Kosolobov

TL;DR

This work provides tight asymptotic bounds on the redundancy of tabled ANS encoders (tANS) and introduces a fixed-accuracy variant of range ANS (rANS). It proves a worst-case redundancy of $O\left(\frac{\sigma}{n}\right)$ bits per symbol for tANS, with a total additive bound of $O(\sigma + r)$ (and even a concrete $\sigma \log e + r$ when expressed over all symbols), along with $\Omega(\sigma + r)$ lower bounds that invalidate the conjectured $O(\frac{\sigma}{n^2})$ redundancy. The paper also presents a new rANS variant with fixed accuracy $k$, giving a redundancy bound of $O\left(\frac{n}{2^k - 1}\log e + r + k\right)$, potentially trading division cost for speed. Together these results clarify the theoretical limits of ANS encoders, guide practical choices between tANS and rANS, and motivate future work on FIFO variants, initialization heuristics, and adaptive/freq-table encoding. The findings have practical impact for compressor design, enabling predictable redundancy and informing speed-accuracy trade-offs in high-performance data compression.

Abstract

Asymmetric Numeral Systems (ANS) is a class of entropy encoders that had an immense impact on the data compression, substituting arithmetic and Huffman coding. It was studied by different authors but the precise asymptotics of its redundancy (in relation to the entropy) was not completely understood. We obtain optimal bounds for the redundancy of the tabled ANS (tANS), the most popular ANS variant. Given a sequence $a_1,a_2,\ldots,a_n$ of symbols from an alphabet $\{0,1,\ldots,σ-1\}$ such that each symbol $a$ occurs in it $f_a$ times and $n=2^r$, the tANS encoder using Duda's ``precise initialization'' to fill tANS tables transforms this sequence into a bit string of the following length (the frequencies are not included in the encoding): $\sum\limits_{a\in[0..σ)}f_a\cdot\log\frac{n}{f_a}+O(σ+r)$, where $O(σ+r)$ can be bounded by $σ\log e+r$. The $r$-bit term is an artifact indispensable to ANS; the rest incurs a redundancy of $O(\fracσ{n})$ bits per symbol. We complement this by examples showing that an $Ω(σ+r)$ redundancy is necessary. We argue that similar examples exist for most adequate initialization methods for tANS. Thus, we refute Duda's conjecture that the redundancy is $O(\fracσ{n^2})$ bits per symbol. We also propose a variant of the range ANS (rANS), called rANS with fixed accuracy, parameterized by $k\ge 1$ that in certain conditions might be faster than the standard rANS because it avoids slow explicit division operations. We bound the redundancy for our rANS variant by $\frac{n}{2^k-1}\log e+r+k$.

Efficiency of ANS Entropy Encoders

TL;DR

This work provides tight asymptotic bounds on the redundancy of tabled ANS encoders (tANS) and introduces a fixed-accuracy variant of range ANS (rANS). It proves a worst-case redundancy of bits per symbol for tANS, with a total additive bound of (and even a concrete when expressed over all symbols), along with lower bounds that invalidate the conjectured redundancy. The paper also presents a new rANS variant with fixed accuracy , giving a redundancy bound of , potentially trading division cost for speed. Together these results clarify the theoretical limits of ANS encoders, guide practical choices between tANS and rANS, and motivate future work on FIFO variants, initialization heuristics, and adaptive/freq-table encoding. The findings have practical impact for compressor design, enabling predictable redundancy and informing speed-accuracy trade-offs in high-performance data compression.

Abstract

Asymmetric Numeral Systems (ANS) is a class of entropy encoders that had an immense impact on the data compression, substituting arithmetic and Huffman coding. It was studied by different authors but the precise asymptotics of its redundancy (in relation to the entropy) was not completely understood. We obtain optimal bounds for the redundancy of the tabled ANS (tANS), the most popular ANS variant. Given a sequence of symbols from an alphabet such that each symbol occurs in it times and , the tANS encoder using Duda's ``precise initialization'' to fill tANS tables transforms this sequence into a bit string of the following length (the frequencies are not included in the encoding): , where can be bounded by . The -bit term is an artifact indispensable to ANS; the rest incurs a redundancy of bits per symbol. We complement this by examples showing that an redundancy is necessary. We argue that similar examples exist for most adequate initialization methods for tANS. Thus, we refute Duda's conjecture that the redundancy is bits per symbol. We also propose a variant of the range ANS (rANS), called rANS with fixed accuracy, parameterized by that in certain conditions might be faster than the standard rANS because it avoids slow explicit division operations. We bound the redundancy for our rANS variant by .
Paper Structure (12 sections, 4 theorems, 26 equations, 5 figures, 1 table, 2 algorithms)

This paper contains 12 sections, 4 theorems, 26 equations, 5 figures, 1 table, 2 algorithms.

Key Result

Theorem 1

Given a sequence $a_1, a_2, \ldots, a_n$ of symbols from an alphabet $[0..\sigma)$ such that each symbol $a$ occurs in it $f_a$ times and $n = 2^r$ for an integer $r$, the ANS encoder using [simplified] Duda's precise initialization transforms this sequence into a bit string of length where the $O(\sigma + r)$ term can be bounded by $\sigma\log e + r$. Thus, we have $O(\frac{\sigma + r}{n})$ redu

Figures (5)

  • Figure 1: A transformation of the number $w_i$ into $w_{i+1}$.
  • Figure 2: A distribution of symbols in a range of length $2^r$.
  • Figure 3: Two cases: $x$ occupies $\lfloor\log f_a\rfloor + 1$ highest bits of $w_i$ (left) or $\lfloor\log f_a\rfloor + 2$ highest bits of $w_i$ (right).
  • Figure 4: A shuffled distribution of symbols. Here, we have $\mathsf{shuffle}[c_b] = 0, \mathsf{shuffle}[c_b+1] = 5, \mathsf{shuffle}[c_b+2] = 7$.
  • Figure 5: Two splits of the state range $[0..2^r)$ into segments. Here $r = 6$. Common first bits of numbers $w_i$ corresponding to the states belonging to the segments A, B, C are written above the respective segments. Observe that the bits start with $11$ only when a state belongs to the segment C. The range $[0..\sigma{-}1)$ is depicted under the segment ii: the encoder receives symbols from the right part $[\sigma/2 - 1..\sigma - 1)$ when the current state is from the segment A, and from the left part $[0..\sigma/2)$ when the state is from the segment C.

Theorems & Definitions (5)

  • Remark 1
  • Theorem 1
  • Theorem 2
  • Theorem 3
  • Theorem 4