📝 Preview Changes: This page has been modified in this pull request (~1% of content changed).
🎨 Highlighting Legend:
Modified text (yellow) shows changed words/phrases,
added text (green) shows new content, and
new sections (blue) highlight entirely new paragraphs.
Codes
Definition 1 (Binary code) Let \(X\) be a discrete random variable. A binary code for \(X\) assigns each value \(x\) a codeword, a finite string of binary digits, of length \(\ell(x)\).
Definition 2 (Uniquely decodable code) A binary code is uniquely decodable if every finite sequence of codewords, written one after another, can be split back into codewords in only one way.
Definition 3 (Expected length) The expected length of a binary code for \(X\), where \(X\) has probability mass function \(p(x) \stackrel{\text{def}}{=}\mathbb{P}(X=x)\), is
\[L \stackrel{\text{def}}{=}{\mathbb{E}\mathopen{}\left[\ell(X)\right]\mathclose{}} = \sum_{x} p(x) \, \ell(x).\]
The source coding theorem
Theorem 1 (Source coding theorem) Let \(X\) be a discrete random variable that takes finitely many values, at least two of them with positive probability, and let \(H_2(X)\) be its entropy with base-2 logarithms.
Every uniquely decodable binary code for \(X\) has expected length \(L \ge H_2(X)\).
Some uniquely decodable binary code for \(X\) has expected length \(L < H_2(X) + 1\).
Coding blocks of \(n\) independent copies of \(X\) at a time, some uniquely decodable binary code spends, on average, fewer than \(H_2(X) + 1/n\) binary digits per copy.
Coding with the wrong distribution
Theorem 2 (The cost of coding with the wrong distribution) Let \(X\) take finitely many values, with probability mass function \(p\), and let \(q\) be a probability mass function, possibly different from \(p\), with \(q(x) > 0\) wherever \(p(x) > 0\). Suppose a code gives each value \(x\) with \(p(x) > 0\) the length \(\ell(x) = \lceil -\log_2 q(x) \rceil\). Then its expected length \(L\) under \(p\) satisfies
\[H_2(p, q) \le L < H_2(p, q) + 1,\]
where \(H_2(p, q)\) is the cross-entropy of \(q\) relative to \(p\), with base-2 logarithms.
Proof. Every sum here runs over the values \(x\) with \(p(x) > 0\). Rounding up adds less than one binary digit, so for each such \(x\)
\[-\log_2 q(x) \le \ell(x) < -\log_2 q(x) + 1.\]
Multiply each part by \(p(x) > 0\) and sum. Since \(\sum_{x} p(x) = 1\),
\[
-\sum_{x} p(x) \log_2 q(x)
\le \sum_{x} p(x) \, \ell(x)
< -\sum_{x} p(x) \log_2 q(x) + 1.
\]
The middle sum is \(L\), and the outer sums are \(H_2(p, q)\).
Back to top