A binary code assigns a finite bit string to each source symbol. Use nonempty codewords for an unframed variable-length stream. The code is uniquely decodable if no two distinct finite sequences of source symbols produce the same concatenated bit string. It is a prefix-free code if no codeword is an initial segment of a different codeword.
To prove unique decoding of a prefix code, suppose two concatenations agree. Their first codewords both begin the same bit string, so the shorter is a prefix of the longer. The prefix condition forces the first codewords to be equal. Cancel them and repeat. Since the codewords are nonempty, this process ends with both symbol sequences exhausted at the same time; otherwise a nonempty remainder could not equal the empty string. Hence the source sequences agree.
The code is not a prefix code, since is a prefix of . Nevertheless it is uniquely decodable: decode from the right. A final forces the last codeword to be , whereas a final forces it to be . Removing that final word recursively gives a unique parsing. Thus the converse fails.
Put and let be the largest length. Expanding sums over all strings of source symbols, where is the total code length. By unique decodability, the concatenations of length in this sum are all distinct, so there are at most of them. Since ,
Taking th roots and sending to infinity proves the Kraft–McMillan inequality
Now is a probability distribution. With base-two logarithms, Gibbs inequality gives
Terms with contribute zero. Therefore
The normalization by is important: the raw numbers need not sum to one.
For the nontrivial case , every and
The probability ordering makes . At a dyadic number, choose the terminating binary expansion followed by zeros. Let be the first bits of , and let
be its binary cylinder interval.
Suppose and were a prefix of . Since , the numbers and would have the same first bits, so both would lie in . In particular . But
a contradiction. A later word cannot be a shorter prefix of an earlier word because the lengths are nondecreasing; equal-length coincidences were also excluded. Thus the cumulative Shannon code is a prefix code.
The ceiling inequalities give
Multiply by and sum to obtain
For a one-symbol deterministic source the displayed construction assigns the empty word and gives . This zero-bit convention is valid when the number of source emissions is supplied separately. It is not an unframed uniquely decodable code: concatenating different numbers of empty words gives the same bit string. If positive-length unframed words are required, the shortest deterministic code has length , so the strict upper bound requires the nontrivial-source assumption.

Articles by others on the same topic (0)

There are currently no matching articles.