Assume that we would like to encode a set of symbol S={s1,s2,...,sn} into binary strings T={t1,t2,...,tn:ti is a 0, 1 sequence of finite length}, such that ∀i=j, ti is not a prefix of tj. Denote the length of ti as ni. Then the Kraft Inequality states that
i=1∑n2−ni≤1
For convenience, we write ti≪tj if ti is a prefix of tj. Intuitively, we can view a particular sequence ti=ti1ti2...tini as the abbreviation of number 0.ti1ti2...tini. The fact that for j=i, neither ti≪tj nor tj≪ti implies that tj does not lies in the interval [0.ti1ti2...tini,0.ti1ti2...tini+2−ni). As the intervals induced by ti's are mutually exclusive, we can easily conclude that
i=1∑n2−ni≤1
Indeed, the statement of Kraft Inequality can be made stronger such that the inequality holds as long as {t1,t2,...,tn} are uniquely decodable. To verify this, note that for any sequence τ∈T∗ with length k, there are at most only 2k possible combinations. Therefore,
(i=1∑n2−ni)l=k=1∑l⋅nmaxCk2−k
where nmax=max{n1,n2,...,} and Ck≤2k. Hence
(i=1∑n2−ni)l≤l⋅nmax→i=1∑n2−ni≤l1/l⋅nmax1/l
Taking l to infty we get the desired result.
An immediately implication is that Entropy is the lower bound of the encode length of a document. To see this, denote the probability of si as pi. Then