The entropy H(X) = −∑ p_i log₂ p_i of a discrete random variable X is its average information content in bits per symbol and the lower bound on the expected code length of any prefix-free encoding of X.
log2(1/pi) is the information content of symbol xi: rare symbols carry more information. H(X) is its expected value.
Lower bound for compression: every prefix-free code for X has expected code length ∑ipiLi≥H(X), and Shannon’s source coding theorem gives one with <H(X)+1 (Entropy-Optimal Code).
0≤H(X)≤log2n, with H(X)=0 iff one pi=1.
ProofProof with Lagrange multipliers
Maximize H=−∑ipilog2pi subject to ∑ipi−1=0. Lagrangian:
L=−i=1∑npilog2pi+λ(i=1∑npi−1)
With log2p=ln2lnp and (plnp)′=1+lnp:
∂pi∂L=−log2pi−ln21+λ=0⟺log2pi=λ−ln21.
The right-hand side is the same for all i, so all pi are equal.
∂λ∂L=∑ipi−1=0, so pi=1/n.
Maximum, not minimum: ∂pi2∂2H=−piln21<0 and the mixed second derivatives vanish, so H is concave. (The exam allows assuming this; WS 16/17 Task 6.3 asks for the second derivative.)
H(1/n,…,1/n)=log2n. ■
Two values (DBIS Exam WS1516 (not published), Task 6.3): H′(p)=ln21(−(1+lnp)+(1+ln(1−p)))=ln21lnp1−p=0⟺p=21, and H′′(p)=−ln2⋅p(1−p)1<0, so p=1/2 is the maximum, H(1/2)=1 bit.