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.
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 .
Every binary prefix code has expected length at least its source entropy; Shannon lengths achieve expected length strictly below .
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.
Articles by others on the same topic
There are currently no matching articles.