Misplaced Pages

Kraft–McMillan inequality

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Kraft–McMillan theorem)

In coding theory, the Kraft–McMillan inequality gives a necessary and sufficient condition for the existence of a prefix code (in Leon G. Kraft's version) or a uniquely decodable code (in Brockway McMillan's version) for a given set of codeword lengths. Its applications to prefix codes and trees often find use in computer science and information theory. The prefix code can contain either finitely many or infinitely many codewords.

Kraft's inequality was published in Kraft (1949). However, Kraft's paper discusses only prefix codes, and attributes the analysis leading to the inequality to Raymond Redheffer. The result was independently discovered in McMillan (1956). McMillan proves the result for the general case of uniquely decodable codes, and attributes the version for prefix codes to a spoken observation in 1955 by Joseph Leo Doob.

Applications and intuitions

Kraft's inequality limits the lengths of codewords in a prefix code: if one takes an exponential of the length of each valid codeword, the resulting set of values must look like a probability mass function, that is, it must have total measure less than or equal to one. Kraft's inequality can be thought of in terms of a constrained budget to be spent on codewords, with shorter codewords being more expensive. Among the useful properties following from the inequality are the following statements:

  • If Kraft's inequality holds with strict inequality, the code has some redundancy.
  • If Kraft's inequality holds with equality, the code in question is a complete code.
  • If Kraft's inequality does not hold, the code is not uniquely decodable.
  • For every uniquely decodable code, there exists a prefix code with the same length distribution.

Formal statement

Let each source symbol from the alphabet

S = { s 1 , s 2 , , s n } {\displaystyle S=\{\,s_{1},s_{2},\ldots ,s_{n}\,\}}

be encoded into a uniquely decodable code over an alphabet of size r {\displaystyle r} with codeword lengths

1 , 2 , , n . {\displaystyle \ell _{1},\ell _{2},\ldots ,\ell _{n}.}

Then

i = 1 n r i 1. {\displaystyle \sum _{i=1}^{n}r^{-\ell _{i}}\leqslant 1.}

Conversely, for a given set of natural numbers 1 , 2 , , n {\displaystyle \ell _{1},\ell _{2},\ldots ,\ell _{n}} satisfying the above inequality, there exists a uniquely decodable code over an alphabet of size r {\displaystyle r} with those codeword lengths.

Example: binary trees

9, 14, 19, 67 and 76 are leaf nodes at depths of 3, 3, 3, 3 and 2, respectively.

Any binary tree can be viewed as defining a prefix code for the leaves of the tree. Kraft's inequality states that

leaves 2 depth ( ) 1. {\displaystyle \sum _{\ell \in {\text{leaves}}}2^{-{\text{depth}}(\ell )}\leqslant 1.}

Here the sum is taken over the leaves of the tree, i.e. the nodes without any children. The depth is the distance to the root node. In the tree to the right, this sum is

1 4 + 4 ( 1 8 ) = 3 4 1. {\displaystyle {\frac {1}{4}}+4\left({\frac {1}{8}}\right)={\frac {3}{4}}\leqslant 1.}

Proof

Proof for prefix codes

Example for binary tree. Red nodes represent a prefix tree. The method for calculating the number of descendant leaf nodes in the full tree is shown.

First, let us show that the Kraft inequality holds whenever the code for S {\displaystyle S} is a prefix code.

Suppose that 1 2 n {\displaystyle \ell _{1}\leqslant \ell _{2}\leqslant \cdots \leqslant \ell _{n}} . Let A {\displaystyle A} be the full r {\displaystyle r} -ary tree of depth n {\displaystyle \ell _{n}} (thus, every node of A {\displaystyle A} at level < n {\displaystyle <\ell _{n}} has r {\displaystyle r} children, while the nodes at level n {\displaystyle \ell _{n}} are leaves). Every word of length n {\displaystyle \ell \leqslant \ell _{n}} over an r {\displaystyle r} -ary alphabet corresponds to a node in this tree at depth {\displaystyle \ell } . The i {\displaystyle i} th word in the prefix code corresponds to a node v i {\displaystyle v_{i}} ; let A i {\displaystyle A_{i}} be the set of all leaf nodes (i.e. of nodes at depth n {\displaystyle \ell _{n}} ) in the subtree of A {\displaystyle A} rooted at v i {\displaystyle v_{i}} . That subtree being of height n i {\displaystyle \ell _{n}-\ell _{i}} , we have

| A i | = r n i . {\displaystyle |A_{i}|=r^{\ell _{n}-\ell _{i}}.}

Since the code is a prefix code, those subtrees cannot share any leaves, which means that

A i A j = , i j . {\displaystyle A_{i}\cap A_{j}=\varnothing ,\quad i\neq j.}

Thus, given that the total number of nodes at depth n {\displaystyle \ell _{n}} is r n {\displaystyle r^{\ell _{n}}} , we have

| i = 1 n A i | = i = 1 n | A i | = i = 1 n r n i r n {\displaystyle \left|\bigcup _{i=1}^{n}A_{i}\right|=\sum _{i=1}^{n}|A_{i}|=\sum _{i=1}^{n}r^{\ell _{n}-\ell _{i}}\leqslant r^{\ell _{n}}}

from which the result follows.

Conversely, given any ordered sequence of n {\displaystyle n} natural numbers,

1 2 n {\displaystyle \ell _{1}\leqslant \ell _{2}\leqslant \cdots \leqslant \ell _{n}}

satisfying the Kraft inequality, one can construct a prefix code with codeword lengths equal to each i {\displaystyle \ell _{i}} by choosing a word of length i {\displaystyle \ell _{i}} arbitrarily, then ruling out all words of greater length that have it as a prefix. There again, we shall interpret this in terms of leaf nodes of an r {\displaystyle r} -ary tree of depth n {\displaystyle \ell _{n}} . First choose any node from the full tree at depth 1 {\displaystyle \ell _{1}} ; it corresponds to the first word of our new code. Since we are building a prefix code, all the descendants of this node (i.e., all words that have this first word as a prefix) become unsuitable for inclusion in the code. We consider the descendants at depth n {\displaystyle \ell _{n}} (i.e., the leaf nodes among the descendants); there are r n 1 {\displaystyle r^{\ell _{n}-\ell _{1}}} such descendant nodes that are removed from consideration. The next iteration picks a (surviving) node at depth 2 {\displaystyle \ell _{2}} and removes r n 2 {\displaystyle r^{\ell _{n}-\ell _{2}}} further leaf nodes, and so on. After n {\displaystyle n} iterations, we have removed a total of

i = 1 n r n i {\displaystyle \sum _{i=1}^{n}r^{\ell _{n}-\ell _{i}}}

nodes. The question is whether we need to remove more leaf nodes than we actually have available — r n {\displaystyle r^{\ell _{n}}} in all — in the process of building the code. Since the Kraft inequality holds, we have indeed

i = 1 n r n i r n {\displaystyle \sum _{i=1}^{n}r^{\ell _{n}-\ell _{i}}\leqslant r^{\ell _{n}}}

and thus a prefix code can be built. Note that as the choice of nodes at each step is largely arbitrary, many different suitable prefix codes can be built, in general.

Proof of the general case

Now we will prove that the Kraft inequality holds whenever S {\displaystyle S} is a uniquely decodable code. (The converse needs not be proven, since we have already proven it for prefix codes, which is a stronger claim.) The proof is by Jack I. Karush.

We need only prove it when there are finitely many codewords. If there are infinitely many codewords, then any finite subset of it is also uniquely decodable, so it satisfies the Kraft–McMillan inequality. Taking the limit, we have the inequality for the full code.

Denote C = i = 1 n r l i {\displaystyle C=\sum _{i=1}^{n}r^{-l_{i}}} . The idea of the proof is to get an upper bound on C m {\displaystyle C^{m}} for m N {\displaystyle m\in \mathbb {N} } and show that it can only hold for all m {\displaystyle m} if C 1 {\displaystyle C\leq 1} . Rewrite C m {\displaystyle C^{m}} as

C m = ( i = 1 n r l i ) m = i 1 = 1 n i 2 = 1 n i m = 1 n r ( l i 1 + l i 2 + + l i m ) {\displaystyle {\begin{aligned}C^{m}&=\left(\sum _{i=1}^{n}r^{-l_{i}}\right)^{m}\\&=\sum _{i_{1}=1}^{n}\sum _{i_{2}=1}^{n}\cdots \sum _{i_{m}=1}^{n}r^{-\left(l_{i_{1}}+l_{i_{2}}+\cdots +l_{i_{m}}\right)}\\\end{aligned}}}

Consider all m-powers S m {\displaystyle S^{m}} , in the form of words s i 1 s i 2 s i m {\displaystyle s_{i_{1}}s_{i_{2}}\dots s_{i_{m}}} , where i 1 , i 2 , , i m {\displaystyle i_{1},i_{2},\dots ,i_{m}} are indices between 1 and n {\displaystyle n} . Note that, since S was assumed to uniquely decodable, s i 1 s i 2 s i m = s j 1 s j 2 s j m {\displaystyle s_{i_{1}}s_{i_{2}}\dots s_{i_{m}}=s_{j_{1}}s_{j_{2}}\dots s_{j_{m}}} implies i 1 = j 1 , i 2 = j 2 , , i m = j m {\displaystyle i_{1}=j_{1},i_{2}=j_{2},\dots ,i_{m}=j_{m}} . This means that each summand corresponds to exactly one word in S m {\displaystyle S^{m}} . This allows us to rewrite the equation to

C m = = 1 m m a x q r {\displaystyle C^{m}=\sum _{\ell =1}^{m\cdot \ell _{max}}q_{\ell }\,r^{-\ell }}

where q {\displaystyle q_{\ell }} is the number of codewords in S m {\displaystyle S^{m}} of length {\displaystyle \ell } and m a x {\displaystyle \ell _{max}} is the length of the longest codeword in S {\displaystyle S} . For an r {\displaystyle r} -letter alphabet there are only r {\displaystyle r^{\ell }} possible words of length {\displaystyle \ell } , so q r {\displaystyle q_{\ell }\leq r^{\ell }} . Using this, we upper bound C m {\displaystyle C^{m}} :

C m = = 1 m m a x q r = 1 m m a x r r = m m a x {\displaystyle {\begin{aligned}C^{m}&=\sum _{\ell =1}^{m\cdot \ell _{max}}q_{\ell }\,r^{-\ell }\\&\leq \sum _{\ell =1}^{m\cdot \ell _{max}}r^{\ell }\,r^{-\ell }=m\cdot \ell _{max}\end{aligned}}}

Taking the m {\displaystyle m} -th root, we get

C = i = 1 n r l i ( m m a x ) 1 m {\displaystyle C=\sum _{i=1}^{n}r^{-l_{i}}\leq \left(m\cdot \ell _{max}\right)^{\frac {1}{m}}}

This bound holds for any m N {\displaystyle m\in \mathbb {N} } . The right side is 1 asymptotically, so i = 1 n r l i 1 {\displaystyle \sum _{i=1}^{n}r^{-l_{i}}\leq 1} must hold (otherwise the inequality would be broken for a large enough m {\displaystyle m} ).

Alternative construction for the converse

Given a sequence of n {\displaystyle n} natural numbers,

1 2 n {\displaystyle \ell _{1}\leqslant \ell _{2}\leqslant \cdots \leqslant \ell _{n}}

satisfying the Kraft inequality, we can construct a prefix code as follows. Define the i codeword, Ci, to be the first i {\displaystyle \ell _{i}} digits after the radix point (e.g. decimal point) in the base r representation of

j = 1 i 1 r j . {\displaystyle \sum _{j=1}^{i-1}r^{-\ell _{j}}.}

Note that by Kraft's inequality, this sum is never more than 1. Hence the codewords capture the entire value of the sum. Therefore, for j > i, the first i {\displaystyle \ell _{i}} digits of Cj form a larger number than Ci, so the code is prefix free.

Generalizations

The following generalization is found in.

Theorem — If C , D {\textstyle C,D} are uniquely decodable, and every codeword in C {\textstyle C} is a concatenation of codewords in D {\textstyle D} , then c C r | c | c D r | c | {\displaystyle \sum _{c\in C}r^{-|c|}\leq \sum _{c\in D}r^{-|c|}}

The previous theorem is the special case when D = { a 1 , , a r } {\displaystyle D=\{a_{1},\dots ,a_{r}\}} .

Proof

Let Q C ( x ) {\textstyle Q_{C}(x)} be the generating function for the code. That is, Q C ( x ) := c C x | c | {\displaystyle Q_{C}(x):=\sum _{c\in C}x^{|c|}}

By a counting argument, the k {\textstyle k} -th coefficient of Q C n {\textstyle Q_{C}^{n}} is the number of strings of length n {\textstyle n} with code length k {\textstyle k} . That is, Q C n ( x ) = k 0 x k # ( strings of length  n  with  C -codes of length  k ) {\displaystyle Q_{C}^{n}(x)=\sum _{k\geq 0}x^{k}\#({\text{strings of length }}n{\text{ with }}C{\text{-codes of length }}k)} Similarly,
1 1 Q C ( x ) = 1 + Q C ( x ) + Q C ( x ) 2 + = k 0 x k # ( strings with  C -codes of length  k ) {\displaystyle {\frac {1}{1-Q_{C}(x)}}=1+Q_{C}(x)+Q_{C}(x)^{2}+\cdots =\sum _{k\geq 0}x^{k}\#({\text{strings with }}C{\text{-codes of length }}k)}

Since the code is uniquely decodable, any power of Q C {\textstyle Q_{C}} is absolutely bounded by r | x | + r 2 | x | 2 + = r | x | 1 r | x | {\textstyle r|x|+r^{2}|x|^{2}+\cdots ={\frac {r|x|}{1-r|x|}}} , so each of Q C , Q C 2 , {\textstyle Q_{C},Q_{C}^{2},\dots } and 1 1 Q C ( x ) {\textstyle {\frac {1}{1-Q_{C}(x)}}} is analytic in the disk | x | < 1 / r {\textstyle |x|<1/r} .

We claim that for all x ( 0 , 1 / r ) {\textstyle x\in (0,1/r)} , Q C n Q D n + Q D n + 1 + {\displaystyle Q_{C}^{n}\leq Q_{D}^{n}+Q_{D}^{n+1}+\cdots }

The left side is k 0 x k # ( strings of length  n  with  C -codes of length  k ) {\displaystyle \sum _{k\geq 0}x^{k}\#({\text{strings of length }}n{\text{ with }}C{\text{-codes of length }}k)} and the right side is

k 0 x k # ( strings of length n  with  D -codes of length  k ) {\displaystyle \sum _{k\geq 0}x^{k}\#({\text{strings of length}}\geq n{\text{ with }}D{\text{-codes of length }}k)}

Now, since every codeword in C {\textstyle C} is a concatenation of codewords in D {\textstyle D} , and D {\textstyle D} is uniquely decodable, each string of length n {\textstyle n} with C {\textstyle C} -code c 1 c n {\textstyle c_{1}\dots c_{n}} of length k {\textstyle k} corresponds to a unique string s c 1 s c n {\textstyle s_{c_{1}}\dots s_{c_{n}}} whose D {\textstyle D} -code is c 1 c n {\textstyle c_{1}\dots c_{n}} . The string has length at least n {\textstyle n} .

Therefore, the coefficients on the left are less or equal to the coefficients on the right.

Thus, for all x ( 0 , 1 / r ) {\textstyle x\in (0,1/r)} , and all n = 1 , 2 , {\textstyle n=1,2,\dots } , we have Q C Q D ( 1 Q D ) 1 / n {\displaystyle Q_{C}\leq {\frac {Q_{D}}{(1-Q_{D})^{1/n}}}} Taking n {\textstyle n\to \infty } limit, we have Q C ( x ) Q D ( x ) {\textstyle Q_{C}(x)\leq Q_{D}(x)} for all x ( 0 , 1 / r ) {\textstyle x\in (0,1/r)} .

Since Q C ( 1 / r ) {\textstyle Q_{C}(1/r)} and Q D ( 1 / r ) {\textstyle Q_{D}(1/r)} both converge, we have Q C ( 1 / r ) Q D ( 1 / r ) {\textstyle Q_{C}(1/r)\leq Q_{D}(1/r)} by taking the limit and applying Abel's theorem.

There is a generalization to quantum code.

Notes

  1. Cover, Thomas M.; Thomas, Joy A. (2006), "Data Compression", Elements of Information Theory (2nd ed.), John Wiley & Sons, Inc, pp. 108–109, doi:10.1002/047174882X.ch5, ISBN 978-0-471-24195-9
  2. De Rooij, Steven; Grünwald, Peter D. (2011), "LUCKINESS AND REGRET IN MINIMUM DESCRIPTION LENGTH INFERENCE", Philosophy of Statistics (1st ed.), Elsevier, p. 875, ISBN 978-0-080-93096-1
  3. Karush, J. (April 1961). "A simple proof of an inequality of McMillan (Corresp.)". IEEE Transactions on Information Theory. 7 (2): 118. doi:10.1109/TIT.1961.1057625. ISSN 0018-9448.
  4. Cover, Thomas M.; Thomas, Joy A. (2006). Elements of information theory (2nd ed.). Hoboken, N.J: Wiley-Interscience. ISBN 978-0-471-24195-9.
  5. Foldes, Stephan (2008-06-21). "On McMillan's theorem about uniquely decipherable codes". arXiv:0806.3277 .
  6. Schumacher, Benjamin; Westmoreland, Michael D. (2001-09-10). "Indeterminate-length quantum coding". Physical Review A. 64 (4): 042304. arXiv:quant-ph/0011014. Bibcode:2001PhRvA..64d2304S. doi:10.1103/PhysRevA.64.042304. S2CID 53488312.

References

  • McMillan, Brockway (1956), "Two inequalities implied by unique decipherability", IEEE Trans. Inf. Theory, 2 (4): 115–116, doi:10.1109/TIT.1956.1056818.

See also

Categories: