Lably
Skip to content

Arithmetic coding

Form of entropy encoding used in data compression

  • 20 min read
  • 8 chapters

Related on Lably

Through String (computer science), ASCII and Interval (mathematics)

Relationship to entropy

Arithmetic coding achieves compression by subdividing the interval [0, 1) into sub-intervals proportional to symbol probabilities. When symbol probabilities are unequal, more probable symbols receive larger sub-intervals, which require fewer bits to specify a point within. The theoretical limit on this compression is given by the entropy of the source, which Shannon's source coding theorem establishes as the minimum average number of bits per symbol that any lossless method can achieve. Arithmetic coding approaches this limit closely, especially for long messages.

When all symbols are equally likely, each sub-interval has the same size, and no symbol can be represented with fewer bits than any other. In this case the entropy reaches its maximum of log2⁡n bits per symbol (where n is the alphabet size), and no compression is possible. For example, a stream of independent fair coin flips has entropy of exactly 1 bit per symbol – the full cost of storage – so arithmetic coding provides no benefit. Similarly, independent ternary symbols with equal probabilities have entropy of about 1.585 bits per symbol, the maximum for a three-symbol alphabet, and are likewise incompressible.

Compression becomes possible when probabilities are unequal, because the sub-intervals become unequal in size. For instance, a binary source with probabilities 0.9 and 0.1 has entropy of approximately 0.469 bits per symbol. The symbol with probability 0.9 receives 90% of each interval, so most encoding steps barely shrink the interval, and fewer bits are needed to identify the final value. This allows arithmetic coding to achieve a compression ratio of roughly 2.1:1.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Computing and communication