Entropy

Definition

The entropy of a random variable XX is defined as

H[X]=E[log⁡21Pr⁡[X]] \mathbf{H}[X] = \mathbb{E} \left[ \log_2 \frac{1}{\Pr[X] } \right]

Here we adopt the convention that 0log⁡0=00 \log 0 = 0, as lim⁡x→0+xlog⁡x=lim⁡x→∞1xlog⁡1x=0\lim_{x \rightarrow 0^+} x \log x = \lim_{x \rightarrow \infty} \frac{1 }{ x } \log \frac{1 }{ x } = 0.

Properties

The entropy is oblivious to the specific values XX takes and is only sensitive to the probabilities with which XX takes these values. Further, the entropy of a random variable may not reflect the whether a random variable is concentrated at its mean or not.

Example.

  1. X1={e1000,with probability 0.50,with probability 0.5X_1 = \begin{cases} e^{1000}, \text{with probability 0.5} \\ 0, \text{with probability 0.5} \end{cases}
  2. X2={1,with probability 0.5−1,with probability 0.5X_2 = \begin{cases} 1, \text{with probability 0.5} \\ -1, \text{with probability 0.5} \end{cases}

Both H[X1]=H[X2]=0.5log⁡22+0.5log⁡22=1\mathbf{H}[X_1] = \mathbf{H}[X_2] = 0.5 \log_2 2 + 0.5 \log_2 2 = 1.

The binary entropy function H(p)\mathbf{H}(p) of a Bernoulli random variable XX that takes value 11 with probability pp is

H(p)=plog⁡21p+(1−p)log⁡211−p=−plog⁡2p−(1−p)log⁡2(1−p) \begin{aligned} \mathbf{H}(p) = &p \log_2 \frac{1}{p} + (1 - p) \log_2 \frac{1}{1 - p} \\ = &-p \log_2 p - (1 - p) \log_2 (1 - p) \end{aligned}

By concavity of log⁡2(⋅)\log_2(\cdot ), we know that

H(p)≤log⁡2(p1p+(1−p)11−p)=1 \begin{aligned} \mathbf{H}(p) &\le \log_2 \left( p \frac{1}{p} + (1 - p) \frac{1}{1 - p} \right) &= 1 \end{aligned}

The equality holds when p=0.5p = 0.5.

Some interesting values:

  • p=0.5p = 0.5, H(p)=1\mathbf{H}(p) = 1
  • p=0.2/0.8p = 0.2/0.8, H(p)≈0.7\mathbf{H}(p) \approx 0.7
  • p=0.1/0.9p = 0.1/0.9, H(p)≈0.5\mathbf{H}(p) \approx 0.5

Lemma. Given a discrete range U\mathcal{U}, the entropy of a random variable XX defined on U\mathcal{U} is maximized when XX has uniform distribution, i.e.,

H(X)≤log⁡∣U∣ \mathbf{H} (X) \le \log |\mathcal{U}|

Proof.

H(X)=∑xp(x)log⁡1p(x)≤log⁡∑xp(x)1p(x)=log⁡∣U∣ \begin{aligned} \mathbf{H} (X) &= \sum_{x} p(x) \log \frac{1}{p(x) } \\ &\le \log \sum_{x} p(x) \frac{1}{p(x) } \\ &= \log |\mathcal{U}| \end{aligned}

The inequality holds with equality only when p(x)=1/∣U∣p(x) = 1/ |\mathcal{U}|.

■\blacksquare

Lemma. Let p(x)p(x) and q(x)q(x) be two distributions and λ∈[0,1]\lambda \in [0, 1], then

H(λp(x)+(1−λ)q(x))≥λH(p(x))+(1−λ)H(q(x)) \mathbf{H} (\lambda p(x) + (1 - \lambda) q(x) ) \ge \lambda \mathbf{H}(p(x) ) + (1 - \lambda) \mathbf{H} (q(x) )

Proof.

λH(p(x))+(1−λ)H(q(x))=∑x(λp(x)log⁡1p(x)+(1−λ)q(x)log⁡1q(x))=(λp(x)+(1−λ)q(x))∑x(λp(x)λp(x)+(1−λ)q(x)log⁡1p(x)+(1−λ)q(x)λp(x)+(1−λ)q(x)log⁡1q(x))≤∑x(λp(x)+(1−λ)q(x))log⁡1λp(x)+(1−λ)q(x)=H(λp(x)+(1−λ)q(x)) \begin{aligned} \lambda \mathbf{H}(p(x) ) + (1 - \lambda) \mathbf{H} (q(x) ) &= \sum_{x} \left( \lambda p(x) \log \frac{1}{p(x)} + (1 - \lambda) q(x) \log \frac{1}{q(x) } \right) \\ &= ( \lambda p(x) + (1 - \lambda) q(x) )\sum_{x} \left( \frac{ \lambda p(x) }{ \lambda p(x) + (1 - \lambda) q(x) } \log \frac{1}{p(x)} + \frac{(1 - \lambda) q(x) }{ \lambda p(x) + (1 - \lambda) q(x) } \log \frac{1}{q(x) } \right) \\ &\le \sum_{x} ( \lambda p(x) + (1 - \lambda) q(x) ) \log \frac{1}{ \lambda p(x) + (1 - \lambda) q(x) } \\ &= \mathbf{H} ( \lambda p(x) + (1 - \lambda) q(x) ) \end{aligned}

■\blacksquare

Lemma. For two independent random variables XX and YY, we have

E[log⁡21Pr⁡[X+Y]]=E[log⁡21Pr⁡[X]]+E[log⁡21Pr⁡[Y]], \mathbb{E} \left[ \log_2 \frac{1}{\Pr[X + Y] } \right] = \mathbb{E} \left[ \log_2 \frac{1}{\Pr[X] } \right] + \mathbb{E} \left[ \log_2 \frac{1}{\Pr[Y] } \right],

i.e.,

H[X+Y]=H[X]+H[Y]. \mathbf{H}[X + Y] = \mathbf{H}[X] + \mathbf{H}[Y].

Proof. We prove it for the case of discrete random variables.

E[log⁡21Pr⁡[X+Y]]=∑x,yp(x,y)log⁡21p(x,y)=∑x,yp(x)p(y)(log⁡21p(x)+log⁡21p(y))=∑xp(x)∑yp(y)log⁡21p(x)+∑yp(y)∑xp(x)log⁡21p(y)=E[log⁡21Pr⁡[X]]+E[log⁡21Pr⁡[Y]] \begin{array}{rrl} &\mathbb{E} \left[ \log_2 \frac{1}{\Pr[X + Y] } \right] &= \sum_{x, y} p(x, y) \log_2 \frac{1}{p(x, y)} \\ &&= \sum_{x, y} p(x) p(y) \left( \log_2 \frac{1}{p(x)} + \log_2 \frac{1}{p(y) } \right) \\ &&= \sum_{x} p(x) \sum_{y} p(y) \log_2 \frac{1}{p(x)} + \sum_{y} p(y) \sum_{x} p(x) \log_2 \frac{1}{p(y) } \\ &&= \mathbb{E} \left[ \log_2 \frac{1}{\Pr[X] } \right] + \mathbb{E} \left[ \log_2 \frac{1}{\Pr[Y] } \right] \end{array}

■\blacksquare

Joint Entropy and Conditional Entropy

Definition. Given random variable XX and YY, the joint entropy H(X,Y)\mathbf{H}(X, Y) with a distribution p(x,y)p(x, y) is defined as

H(X,Y)=E[log⁡1p(x,y)]. \mathbf{H}(X,Y) = \mathbb{E}\left[ \log \frac{1}{p(x, y)} \right].

When XX and YY are discrete random variables, it is equivalent to

H(X,Y)=∑x∈X∑y∈Yp(x,y)log⁡1p(x,y). \mathbf{H}(X,Y) = \sum_{x \in \mathcal{X} } \sum_{y \in \mathcal{Y} } p(x, y) \log \frac{1}{p(x, y) }.

Definition. The conditional entropy H(Y∣X)\mathbf{H}(Y \mid X) with a distribution p(x,y)p(x, y) is defined as

H(Y∣X)=∑x∈Xp(x)⋅H(Y∣X=x)=∑x∈Xp(x)⋅∑y∈Yp(y∣x)log⁡1p(y∣x)=∑x∈X∑y∈Yp(x,y)log⁡1p(y∣x)=E[log⁡1p(y∣x)] \begin{aligned} \mathbf{H}(Y \mid X) &= \sum_{x \in \mathcal{X} } p(x) \cdot \mathbf{H} (Y \mid X = x) \\ &= \sum_{x \in \mathcal{X} } p(x) \cdot \sum_{y \in \mathcal{Y} } p(y \mid x) \log \frac{1}{p(y \mid x) } \\ &= \sum_{x \in \mathcal{X} } \sum_{y \in \mathcal{Y} } p(x, y) \log \frac{1}{p(y \mid x) } \\ &= \mathbb{E} \left[ \log \frac{1}{p(y \mid x) } \right] \end{aligned}
  • Remark. Conditioned on X=xX = x, YY is a random variable and therefore we can define its Entropy as H(Y∣X=x)\mathbf{H}(Y \mid X = x). The conditional entropy H(Y∣X)\mathbf{H}(Y \mid X) is the average of the H(Y∣X=x)\mathbf{H}(Y \mid X = x) over the distribution of XX, i.e., the average uncertainty in YY after we had observed XX. Both H(Y∣X)\mathbf{H}(Y \mid X) and H(Y∣X=x)\mathbf{H}(Y \mid X = x) represent a value. This is different from the conditional expectation: E[Y∣X]\mathbb{E}[Y \mid X] is a random variable and E[Y∣X=x]\mathbb{E}[Y \mid X = x] is a value.

Chain Rule. For random variable XX and YY, it holds that

H(X,Y)=∑x∈X∑y∈Yp(x,y)log⁡1p(x,y)=∑x∈X∑y∈Yp(x,y)log⁡1p(y∣x)p(x)=∑x∈X∑y∈Yp(x,y)log⁡1p(y∣x)+∑x∈X∑y∈Yp(x,y)log⁡1p(x)=H(Y∣X)+H(X) \begin{aligned} \mathbf{H}(X, Y) &= \sum_{x \in \mathcal{X} } \sum_{y \in \mathcal{Y} } p(x, y) \log \frac{1}{p(x, y) } \\ &= \sum_{x \in \mathcal{X} } \sum_{y \in \mathcal{Y} } p(x, y) \log \frac{1}{p(y \mid x) p(x) } \\ &= \sum_{x \in \mathcal{X} } \sum_{y \in \mathcal{Y} } p(x, y) \log \frac{1}{p(y \mid x) } + \sum_{x \in \mathcal{X} } \sum_{y \in \mathcal{Y} } p(x, y) \log \frac{1}{ p(x) } \\ &= \mathbf{H}(Y \mid X) + \mathbf{H}(X) \end{aligned}

Corollaries

H(X)+H(Y∣X)=H(Y)+H(X∣Y) \mathbf{H}(X) + \mathbf{H}(Y \mid X) = \mathbf{H}(Y) + \mathbf{H}(X \mid Y)

Or

H(X)−H(X∣Y)=H(Y)−H(Y∣X) \mathbf{H}(X) - \mathbf{H}(X \mid Y)= \mathbf{H}(Y) - \mathbf{H}(Y \mid X)

Binomial Distribution

We study the relationship of binomial distribution B(n,p)B(n, p) and entropy. As a rule of thumb, for reasonably large nn (say, n≥100n \ge 100) and moderate size of pp (e.g., 0.1≤p≤0.90.1 \le p \le 0.9), the probability is concentrated on the interval [np−n,np+n][np - \sqrt n, np + \sqrt n].

N=100,p=0.5N = 100, p = 0.5.

N=100,p=0.3N = 100, p = 0.3.

N=100,p=0.1N = 100, p = 0.1.

N=1000,p=0.1N = 1000, p = 0.1. Note that

Pr⁡[100−1000≤X≤100+1000]≈0.9993 \Pr[ 100 - \sqrt{1000} \le X \le 100 + \sqrt{1000} ] \approx 0.9993

Lemma. For n∈Z+n\in \mathbf{Z}^+, k∈[n]k \in [n], it holds that

(nk)≥1n+12nH(kn) \binom{n}{k} \ge \frac{1}{n + 1} 2^{n \mathbf{H}(\frac{k}{n} ) }

Proof. Define q=knq = \frac{k}{n}. Then

(q+(1−q))n=∑i=0n(ni)qi(1−q)n−i \begin{aligned} (q + (1 - q))^n &= \sum_{i = 0}^n \binom{n}{i} q^i (1 - q)^{n - i} \end{aligned}

The summation consists of (n+1)(n + 1) terms. We claim that

(nk)qk(1−q)n−k \binom{n}{k} q^k (1 - q)^{n - k}

is the largest one. For i∈[n]i \in [n],

(ni+1)qi+1(1−q)n−i−1(ni)qi(1−q)n−i=n−ii+1q1−q \frac{ \binom{n}{i + 1} q^{i + 1} (1 - q)^{n - i - 1} }{ \binom{n}{i } q^{i} (1 - q)^{n - i } } = \frac{n - i }{i + 1} \frac{ q}{1 - q}

The ratio is at least 11 when n−ii+1≥1−qq\frac{n - i}{i + 1} \ge \frac{1 - q}{ q }. We see that when i=nq−1=k−1i = nq - 1 = k - 1, it holds that

n−ii+1=n−nq+1nq≥1−qq \frac{n - i}{i + 1} = \frac{n - nq + 1}{ n q} \ge \frac{1 - q}{ q }

and when i=ki = k,

n−ii+1=n−nqnq+1<1−qq \frac{n - i}{i + 1} = \frac{n - nq}{ n q + 1} < \frac{1 - q}{ q }

Therefore,

(nk)qk(1−q)n−k=(nk)2klog⁡2q2(n−k)log⁡2(1−q)=(nk)2n[qlog⁡2q+(1−q)log⁡2(1−q)]≥1n+1 \begin{aligned} \binom{n}{k} q^k (1 - q)^{n - k} &= \binom{n}{k} 2^{k \log_2 q} 2^{ (n - k )\log_2 (1 - q)} \\ &= \binom{n}{k} 2^{ n [ q \log_2 q + (1 - q )\log_2 (1 - q) ]} \\ &\ge \frac{1}{n + 1} \end{aligned}

■\blacksquare

Extracting Random Bits

Consider a uniform random variable XX at [0,m−1][0, m - 1]. By definition we know that

H[X]=∑i=0m−11mlog⁡211m=log⁡2m \mathbf{H}[X] = \sum_{i = 0}^{m - 1} \frac{1}{m} \log_2 \frac{1}{\frac{1}{m} } = \log_2 m

Given XX as an input, the following algorithm outputs a binary string ss, such that each bit of ss can be interpreted as the outcome of independently Bernoulli random variables with probability 0.50.5.

On the high level, we divide mm into intervals of powers of 2. When XX falls into an interval, we return a binary number that is within the range of that interval. Specifically, we rewrite

m=2dk+2dk−1+...+2d1 m = 2^{d_k} + 2^{d_{k - 1} } + ... + 2^{d_1}

where ⌊H[X]⌋=⌊log⁡2m⌋=dk>dk−1>...>d1≥0\lfloor \mathbf{H}[X] \rfloor = \lfloor \log_2 m \rfloor = d_k > d_{k - 1} > ... > d_1 \ge 0 are the indexes of non-zero bits in the binary representation of mm. The extraction is as follows:

Algorithm 1.

  1. for i←ki \leftarrow k down-to 11 do:
  2. \quad if X<2diX < 2^{d_i} then:
  3. \quad \quad return a did_i-bit binary representation of XX;
  4. \quad else:
  5. \quad \quad X←X−2diX \leftarrow X - 2^{d_i};

Example (m=13m = 13). It is interesting to note that when X=12X = 12, our proposed extraction method return no random bit, as 0<200 < 2^0. In this case our proposed method has wasted some randomness.

Question to ponder: Come up with some method that uses nn i.i.d. XX's to extract binary string with expected length close to nH[X]n \mathbf{H}[X].

Let ss be the binary string returned by Algorithm 1.

Theorem 1.

⌊log⁡2m⌋−1≤E[∣s∣]≤log⁡2m \lfloor \log_2 m \rfloor - 1 \le \mathbf{E}[|s|] \le \log_2 m

Proof. It is easy to see that

E[∣s∣]=∑i=1kdi2dim \mathbf{E}[|s| ] = \sum_{i = 1}^k d_i \frac{2^{d_i} }{m }

which depends on mm. To show the upper bound,

∑i=1kdi2dim−log⁡2m=∑i=1k2dimlog⁡22dim≤0 \begin{array}{lll} \sum_{i = 1}^k d_i \frac{2^{d_i} }{m } - \log_2 m = \sum_{i = 1}^k \frac{2^{d_i} }{m } \log_2 \frac{2^{d_i} }{m } \le 0 \end{array}

The inequality follows from log⁡22dim≤0\log_2 \frac{2^{d_i} }{m } \le 0 for 1≤i≤k1 \le i \le k.

To show the lower bound, define the function

f(m)=∑i=1kdi2dim f(m) = \sum_{i = 1}^k d_i \frac{2^{d_i} }{m }

We prove by induction on mm that f(m)≥⌊log⁡2m⌋−1=dk−1f(m) \ge \lfloor \log_2 m \rfloor - 1 = d_k - 1. The cases holds trivially when m=1m = 1. Now suppose it holds for all integer less than mm. We prove that it holds for mm.

Case 1. m=2dkm = 2^{d_k}. Then f(m)=dk=log⁡2mf(m) = d_k = \log_2 m.

Case 2. m>2dkm > 2^{d_k}. Now

f(m)=∑i=1kdi2dim=dk2dkm+(∑i=1k−1di2dim−2dk)m−2dkm \begin{aligned} f(m) &= \sum_{i = 1}^k d_i \frac{2^{d_i} }{m } \\ &= d_k \frac{2^{d_k} }{m} + \left( \sum_{i = 1}^{k - 1} d_i \frac{2^{d_i} }{m - 2^{d_k} } \right) \frac{m - 2^{d_k} }{m} \\ \end{aligned}

But ∑i=1k−12di=m−2dk\sum_{i = 1}^{k - 1} 2^{d_i} = m - 2^{d_k}. It follows by induction

∑i=1k−1di2dim−2dk=f(m−2dk)≥dk−1−1 \sum_{i = 1}^{k - 1} d_i \frac{2^{d_i} }{m - 2^{d_k} } = f(m - 2^{d_k}) \ge d_{k - 1} - 1

Finally,

f(m)≥dk2dkm+(dk−1−1)m−2dkm=dk+(dk−1−dk−1)m−2dkm=dk−(dk+1−dk−1)(1−2dkm)≥dk−(dk+1−dk−1)(1−2dk2dk+2dk−1)=dk−(dk+1−dk−1)(2dk−12dk+2dk−1)=dk−(dk−dk−1+12dk−dk−1+1)≥dk−(dk−dk−1+12dk−dk−1)≥dk−1 \begin{aligned} f(m) &\ge d_k \frac{2^{d_k} }{m} + \left( d_{k - 1} -1 \right) \frac{m - 2^{d_k} }{m} \\ &= d_k + \left( d_{k - 1}- d_k -1 \right) \frac{m - 2^{d_k} }{m} \\ &= d_k - \left( d_k + 1 - d_{k - 1} \right) \left( 1 - \frac{ 2^{d_k} }{m} \right)\\ &\ge d_k - \left( d_k + 1 - d_{k - 1} \right) \left( 1 - \frac{ 2^{d_k} }{2^{d_k} + 2^{d_{k - 1} } } \right)\\ &= d_k - \left( d_k + 1 - d_{k - 1} \right) \left( \frac{ 2^{d_{k - 1} } }{2^{d_k} + 2^{d_{k - 1} } } \right)\\ &= d_k - \left( \frac{ d_k - d_{k - 1} + 1 }{2^{d_k - d_{k - 1} } + 1 } \right)\\ &\ge d_k - \left( \frac{ d_k - d_{k - 1} + 1 }{2^{d_k - d_{k - 1} } } \right)\\ &\ge d_k - 1 \end{aligned}

The last inequality holds since dk−1≤dk−1d_{k - 1} \le d_k - 1 and the function f(x)=x+12xf(x) = \frac{x + 1}{2^x} decreases when x≥1x \ge 1.

■\blacksquare

Binary Strings

To illustrate the idea of entropy, we study another example of random bit extraction.

Problem. Let tt be an nn-bit binary string each bit of which is interpreted as the outcome of independent bias coin flip that comes up head probability p≤0.5p \le 0.5. Given tt as input, we want to output a binary string ss (not necessary of length nn) of independent unbiased random bits.

Theorem. There is an extraction algorithm, such that,

  1. ∀δ∈(0,1)\forall \delta \in (0, 1), ∃N>0\exists N > 0, s.t.s.t., ∀n≥N\forall n \ge N, E[∣s∣]≥(1−δ)nH(p)\mathbf{E}[|s|] \ge (1 - \delta) n\mathbf{H}(p).
  2. ∀n>0\forall n > 0, E[∣s∣]≤nH(p)\mathbf{E}[|s|] \le n\mathbf{H}(p).

The theorem states that the expected length of ss approximates nH(p)n\mathbf{H}(p). Equivalently,

lim⁡n→∞E[∣s∣]n=H(p) \lim_{n \rightarrow \infty} \frac{\mathbf{E}[|s|]}{n} = \mathbf{H}(p)

Proof. Define the random variable ZZ to be the number of ones in tt. For any integer k≥0k \ge 0, there are (nk)\binom{n}{k} strings with kk ones. We can map these strings to {0,1,...,(nk)−1}\{0, 1, ..., \binom{n}{k} - 1 \}. Conditioned on Z=kZ = k, the mapping of tt is uniform on {0,1,...,(nk)−1}\{0, 1, ..., \binom{n}{k} - 1 \}. We can use Algorithm 1 to return a binary string ss. Now its expected length is

E[∣s∣]=∑k=1nE[∣s∣∣Z=k]Pr⁡[Z=k] \mathbf{E}[|s|] = \sum_{k = 1}^n \mathbf{E}\left[ |s| \mid Z = k \right] \Pr[Z = k]

Further, by Hoeffding's inequality, it holds that for 0<ϵ<p0 < \epsilon < p,

Pr⁡[∣Z−np∣≥nϵ]≤exp⁡(−2nϵ2) \Pr[ |Z - np | \ge n\epsilon] \le \exp\left(- 2 n \epsilon^2 \right)

By setting the failure probability exp⁡(−2nϵ2)=δ/2\exp(-2 n \epsilon^2) = \delta / 2, we get ϵ=ln⁡2δ2n\epsilon = \sqrt{\frac{\ln \frac{2}{\delta} }{2n} }.

Let LB=⌈np−nϵ⌉LB = \lceil np - n\epsilon \rceil and UB=⌊np+nϵ⌋UB = \lfloor np + n\epsilon \rfloor. Observing that ZZ is an integer, we have

Pr⁡[LB≤Z≤UB]=Pr⁡[np−nϵ≤Z≤np+nϵ]≥1−δ/2 \begin{array}{rl} \Pr[LB \le Z \le UB] &= \Pr[np - n\epsilon \le Z \le np + n\epsilon] \\ &\ge 1 - \delta/2 \end{array}

As p≤0.5p \le 0.5, it holds that

n=⌈n/2−nϵ⌉+⌊n/2+nϵ⌋≥⌈np−nϵ⌉+⌊np+nϵ⌋ n = \lceil n/2 - n\epsilon \rceil + \lfloor n/2 + n\epsilon \rfloor \ge \lceil np - n\epsilon \rceil + \lfloor np + n\epsilon \rfloor

Therefore,

LB≤UB≤n−LB LB \le UB \le n - LB \\

Since (nk)\binom{n}{k} increase for k<n/2k < n / 2 and decrease k>n/2k > n / 2, it holds that

(nLB)≤(nUB) \binom{n}{LB} \le \binom{n}{UB}

For LB≤k≤UBLB \le k \le UB, we have

(nLB)≤(nk) \binom{n}{LB} \le \binom{n}{k}

Define q=LBnq = \frac{ LB }{n},

(nLB)≥1n+12nH(LBn)≥1n+12nH(p−ϵ) \binom{n}{LB} \ge \frac{1}{n + 1} 2^{n \mathbf{H}( \frac{ LB }{n} ) } \ge \frac{1}{n + 1} 2^{n\mathbf{H}(p - \epsilon)}

By Theorem 1, we have

E[∣s∣]=∑k=1nE[∣s∣∣Z=k]Pr⁡[Z=k]≥∑k=LBUBE[∣s∣∣Z=k]Pr⁡[Z=k]≥∑k=LBUB(⌊log⁡2(nk)⌋−1)(nk)pk(1−p)n−k≥∑k=LBUB(⌊log⁡2(nLB)⌋−1)(nk)pk(1−p)n−k=(⌊log⁡2(nLB)⌋−1)Pr⁡[LB≤Z≤UB]≥(nH(p−ϵ)−log⁡2(n+1))(1−δ/2)=(H(p−ϵ)H(p)−log⁡2(n+1)nH(p))(1−δ/2)⋅n⋅H(p)=(H(p−ln⁡2δ2n)H(p)−log⁡2(n+1)nH(p))(1−δ/2)⋅n⋅H(p) \begin{aligned} \mathbf{E}[|s|] &= \sum_{k = 1}^n \mathbf{E}\left[ |s| \mid Z = k \right] \Pr[Z = k] \\ &\ge \sum_{k = LB}^{UB} \mathbf{E}\left[ |s| \mid Z = k \right] \Pr[Z = k] \\ &\ge \sum_{k = LB }^{UB } \left( \left\lfloor \log_2 \binom{n}{k} \right\rfloor - 1 \right) \binom{n}{k} p^k (1 - p)^{n - k} \\ &\ge \sum_{k = LB }^{UB } \left( \left\lfloor \log_2 \binom{n}{ LB } \right\rfloor - 1 \right) \binom{n}{k} p^k (1 - p)^{n - k} \\ &= \left( \left\lfloor \log_2 \binom{n}{ LB } \right\rfloor - 1 \right) \Pr[LB \le Z \le UB] \\ &\ge \left( n \mathbf{H}(p - \epsilon) - \log_2 (n + 1) \right) (1- \delta / 2) \\ &= \left( \frac{\mathbf{H}(p - \epsilon)}{\mathbf{H}(p) } - \frac{\log_2 (n + 1) }{ n\mathbf{H}(p) }\right) (1- \delta / 2 ) \cdot n \cdot \mathbf{H}(p) \\ &= \left( \frac{\mathbf{H} \left(p - \sqrt{\frac{\ln \frac{2}{\delta} }{2n} } \right) }{\mathbf{H}(p) } - \frac{\log_2 (n + 1) }{ n\mathbf{H}(p) }\right) (1- \delta / 2 ) \cdot n \cdot \mathbf{H}(p) \\ \end{aligned}

∃N>0\exists N > 0, s.t., ∀n>N\forall n > N, (H(p−ln⁡2δ2n)H(p)−log⁡2(n+1)nH(p))≥(1−δ/2)\left( \frac{\mathbf{H} \left(p - \sqrt{\frac{\ln \frac{2}{\delta} }{2n} } \right) }{\mathbf{H}(p) } - \frac{\log_2 (n + 1) }{ n\mathbf{H}(p) }\right) \ge (1 - \delta / 2), which finishes the proof of lower bound.

As for the upper bound, observe that

(nk)pk(1−p)n−k≤1 \binom{n}{k} p^k ( 1- p)^{n - k} \le 1

Therefore, (nk)≤p−k(1−p)−(n−k)\binom{n}{k} \le p^{-k} ( 1- p)^{-(n - k) }. Thus, we have

E[∣s∣]=∑k=1nE[∣s∣∣Z=k]Pr⁡[Z=k]≤∑k=1n(log⁡2(nk))(nk)pk(1−p)n−k≤∑k=1n(nk)pk(1−p)n−klog⁡21pk(1−p)n−k \begin{aligned} \mathbf{E}[|s|] &= \sum_{k = 1}^n \mathbf{E}\left[ |s| \mid Z = k \right] \Pr[Z = k] \\ &\le \sum_{k = 1}^n \left( \log_2 \binom{n}{k} \right) \binom{n}{k} p^k (1 - p)^{n - k} \\ &\le \sum_{k = 1}^n \binom{n}{k} p^k (1 - p)^{n - k} \log_2 \frac{1}{ p^k (1 - p)^{n - k} } \end{aligned}

The last term is exactly the entropy of the string. By independence of the bits, we know that it is equal to nH(p)n \mathbf{H}(p).

Remark: we may also prove it algebraically.

E[∣s∣]≤∑k=0n(nk)pk(1−p)n−klog⁡21pk(1−p)n−k=∑k=1n(nk)pk(1−p)n−klog⁡21pk+∑k=0n(nk)pk(1−p)n−klog⁡21(1−p)n−k=(plog⁡21p)∑k=1n(nk)kpk−1(1−p)n−k+((1−p)log⁡211−p)∑k=0n−1(nk)(n−k)pk(1−p)n−k−1=(plog⁡21p)[(x+(1−p))n]x=p′+((1−p)log⁡211−p)[(p+x)n]x=1−p′=nH(p) \begin{aligned} \mathbf{E}[|s|] &\le \sum_{k = 0}^n \binom{n}{k} p^k (1 - p)^{n - k} \log_2 \frac{1}{ p^k (1 - p)^{n - k} } \\ &= \sum_{k = 1}^n \binom{n}{k} p^k (1 - p)^{n - k} \log_2 \frac{1}{ p^k } + \sum_{k = 0}^n \binom{n}{k} p^k (1 - p)^{n - k} \log_2 \frac{1}{ (1 - p)^{n - k} } \\ &= \left( p \log_2 \frac{1}{p} \right) \sum_{k = 1}^n \binom{n}{k} k p^{k - 1} (1 - p)^{n - k} \\ &\quad + \left( ( 1- p) \log_2 \frac{1}{ 1 - p } \right) \sum_{k = 0}^{n - 1} \binom{n}{k} (n - k) p^k (1 - p)^{n - k - 1} \\ &= \left( p \log_2 \frac{1}{p} \right) [(x + (1 - p))^n]_{x = p}' + \left( (1 - p) \log_2 \frac{1}{ 1 - p } \right) [(p + x)^n]_{x = 1-p}' \\ &= n \mathbf{H}(p) \end{aligned}

■\blacksquare

Reference.

[1] S. Har-Peled, “Chapter 26 Entropy, Randomness, and Information,” p. 6.
[2] M. Mitzenmacher and E. Upfal, Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge: Cambridge University Press, 2005.