Every time you rip a CD with FLAC, sequence a genome, or download satellite imagery, a tiny algorithm works behind the scenes: it takes a list of small non-negative integers and squeezes them into as few bits as possible. That algorithm is Golomb-Rice coding, and its key property is remarkable — it is provably optimal for a precise family of distributions.
The key insight is that not all integers are equally likely. When you record the silence between musical notes, the differences between consecutive audio samples cluster near zero. When a sequencing machine counts short DNA runs, most runs are short. Nature keeps handing us numbers where small values dominate and large values are rare — a pattern captured precisely by the geometric distribution.
A fixed-width code wastes this structure entirely: it assigns the same 8 bits to the number 0 as to the number 200. Variable-length codes exploit the skew: frequent small numbers get short codes; rare large numbers get long ones. Golomb coding — invented by Solomon Golomb in 1966 and refined by Robert Rice in the 1970s — is the unique family of codes that achieves the Shannon entropy lower bound for geometric distributions, meaning no lossless code can compress them further.
The mathematical proof is elegant: if you know only that your numbers come from a geometric distribution with some parameter p, the optimal code length for the number n is ⌊n /p)⌋ + 1 bits. Golomb coding achieves this exactly, without knowing p in advance — just by choosing the right divisor m.
Comments
Loading comments...