Unique decodability means that every encoded message has at most one decomposition into codewords.
A code is decipherable, or uniquely decodable, when every finite concatenation of codewords has at most one decomposition into source codewords.
A decipherable code is suffix-free when no codeword is a proper suffix of another. Reversing all its words gives a prefix code. Consequently it is uniquely decipherable: read a concatenation from the right, where the last codeword is determined uniquely, and continue by induction.
For a fixed source distribution and code alphabet, an optimal uniquely decodable code minimizes expected codeword length. Huffman coding gives an optimal binary prefix code, and the equivalence of attainable uniquely-decodable and prefix-code lengths gives the same minimum for both classes.
In a prefix code no codeword is the prefix of another, so concatenated messages have unique instantaneous decoding.
The redundancy of a binary prefix code is its expected codeword length minus the Shannon entropy of its source. It measures the excess number of binary digits per source symbol above the information lower bound. For a full prefix tree of a code, let be the probability of visiting an interior node and let be the conditional probability of taking its zero branch. Thenwhere is binary entropy. The first identity counts one digit for each visited interior node. The second follows by expanding : the interior terms telescope, leaving the negative sum of leaf probability logarithms. The final identity follows by subtraction. It makes nonnegativity immediate and proves that zero redundancy occurs exactly when each positive-mass branch decision is balanced. Consequently the leaf probabilities then equal .
For positive source probabilities in a fixed order, let and . The Shannon-Fano-Elias code uses the first binary digits of the midpoint , using the terminating-zero expansion at dyadic rationals. Its dyadic interval contains and has width at most , so it lies inside the probability cell . These cells are disjoint, whereas a codeword that is a prefix of another has a dyadic interval containing the other interval. The code is therefore a prefix code. Since , averaging proves . This is a direct cumulative construction and does not require sorting the probabilities or constructing a Huffman tree.
A prefix code whose codewords use a three-symbol alphabet, conventionally . No complete codeword is a prefix of another, permitting sequential decoding by following a code tree to a tree leaf. Its expected codeword length is trits per source symbol. For source probabilities , the codewords give expected codeword length trits.
For a finite source alphabet with at least two symbols and strictly positive weights, every ternary prefix code minimizing weighted codeword length has all internal vertices of outdegree three, except possibly one of outdegree two whose tree children are deepest tree leaves.
To prove this, let be the greatest tree leaf depth. A missing tree child at any depth would permit moving a deepest tree leaf into that vacant branch, strictly reducing its positive weighted cost. Thus all internal vertices above depth have three tree children. Tree parents at depth have only tree leaves as tree children; one tree child would permit contraction and strict improvement. If two such tree parents each had two tree children, move one tree child of the second into the first tree parent's third slot, preserving its depth, and contract the second tree parent's remaining tree child. This again strictly improves cost. There is therefore at most one binary tree parent. If the number of symbols is an odd number, the leaf-count formula for a full ternary tree forces to be an even integer; since , there is no binary tree parent.
Strict positivity matters. For probabilities , the prefix code minimizes expected codeword length at one trit, yet has unary vertices and a deepest tree leaf without a sibling codeword. Removing or rearranging zero-weight branches can select a reduced minimizer, but arbitrary minimizers need not have the positive-weight shape.
Replacing every quaternary digit by its fixed two-bit representation preserves the prefix code property: a binary prefix between translated codewords would end at an even position and hence imply a quaternary prefix. Thus a translated quaternary Huffman code cannot beat binary Huffman coding in expected codeword length.
For the reverse bound, binary prefix code lengths give candidate quaternary lengths . Since , the Kraft inequality supplies such a quaternary prefix code. Optimality of quaternary Huffman coding and give . These quantities are expected codeword lengths for the same source probability distribution.
For a success index with geometric distribution of parameter , write , . Encode by ones followed by zero, then encode in exactly bits. This prefix code has length . Since , its expected length is the displayed expression, at most . Thus a very rare success can be communicated in approximately the logarithm of its inverse probability, rather than one bit per trial.
// Target: quantum-theory.bigb
The prefix tree of a code has vertices corresponding to prefixes of codewords, with one edge for each next symbol. The root represents the empty word. In a prefix code, complete codewords are leaves, and their depths are their codeword lengths.
// Target: computer-science.bigb
The lengths of every decipherable binary code satisfyConversely, any positive integer lengths satisfying this bound can be realized by a prefix code.
The lengths of a finite uniquely decodable code satisfy , even when the code is not a prefix code. Distinct concatenations of codewords remain distinct; counting the possible binary strings of each total length bounds by . Taking th roots proves the claim.
Prescribed positive word lengths admit a decipherable code if and only if they admit a prefix code. Counting length- concatenations of words proves the Kraft inequality for any decipherable code; choosing free vertices of the ordered -ary tree constructs a prefix code whenever this inequality holds. Each prefix code has unique decodability.
If a decipherable binary code has codewords of lengths , thenThis follows by applying the entropy lower bound with the uniform source distribution.
Shannon-Fano coding comprises two related prefix code constructions. Shannon coding assigns lengths to symbols of probability ; Fano coding recursively partitions the ordered symbols into groups of nearly equal total probability and assigns a bit at each partition.
Recursively split an ordered list of positive source probabilities into contiguous blocks, choosing each cut to minimize the difference between the total masses of the two children. The resulting binary prefix code has expected codeword length less than , where is its source Shannon entropy. If the probabilities were in nonincreasing order, its expected length is less than .
To prove this, an interior node of mass with child masses contributes to the expected path length and to the Shannon entropy, by the chain rule for information entropy. The inequality bounds that node's redundancy by . If the cut is between probabilities , shifting the cut by one position cannot improve the imbalance. On the heavier side this gives or , respectively; a singleton heavier side gives the same inequality directly. Thus .
Every original inter-symbol gap is used once in the recursive tree. Summing over gaps bounds total redundancy by . In sorted order it is instead at most . These are expected-length guarantees, not an assertion that the resulting code is always optimal.
For source probabilities , Shannon coding chooses binary lengths . They satisfy , so the Kraft inequality ensures that a binary prefix code with these lengths exists.
Its expected length obeys , where is the source entropy. For probabilities , the words achieve the lengths exactly. The construction rounds each information content up separately; Huffman coding can improve the expected length by optimizing the whole code tree.[ref]
A Mathematical Theory of Communication by Claude Shannon. Part I, discrete noiseless coding and codeword lengths
Order source probabilities as , putand take the first binary digits of as the codeword for symbol . Since for , two cumulative probabilities cannot lie in the same dyadic interval selected by the earlier codeword. The resulting code is prefix-free.
If the Shannon length is and is the length of any binary decipherable code, thenThus the probability that the Shannon code loses to another code by or more bits decreases exponentially in .
For a finite source alphabet with probabilities and binary prefix code lengths , the expected length satisfiesTo see this, let by Kraft inequality and put . Direct calculation givesusing nonnegativity of relative entropy. Thus the information entropy measures the unavoidable average description length, rather than the length of every individual message.
If at least two symbols have positive probability, the Shannon lengths are positive, satisfy Kraft inequality, and obey . For a one-symbol source, ; if codewords must have positive length, a one-bit codeword has expected length , so the strict upper bound requires that separate convention or a nontrivial alphabet.
For a complete binary prefix code with lengths , the Kraft inequality is an equality: . Put . The difference between expected codeword length and Shannon entropy isThe Kullback-Leibler divergence is nonnegative and vanishes exactly when . Hence a complete code is entropy-tight exactly for its dyadic matching source. For example, lengths match probabilities . Being an optimal prefix code among symbol-by-symbol codes is a weaker condition and does not imply this equality.
For a finite-alphabet memoryless classical information source with information entropy , every uniquely decodable code for blocks of source symbols has expected binary length at least . This follows from Kraft inequality for uniquely decodable codes and the entropy lower bound for prefix codes.
If at least two source symbols have positive probability, give each positive-probability block Shannon length . These lengths satisfy Kraft inequality, so a prefix code exists, and independence givesThus coding longer blocks approaches the information entropy in expected bits per source symbol. This is an average-length statement: rare blocks can have long codewords.
For a source with only one possible symbol, a one-bit codeword for each length- block gives rate when positive codeword lengths are required. The limiting theorem therefore remains true, although the strict one-block bound needs the nontrivial-alphabet assumption. Countably infinite alphabets require additional care about finite information entropy and the chosen code construction.
Articles by others on the same topic
There are currently no matching articles.