Given a finite set Σ\Sigma with size q=∣Σ∣q = |\Sigma|, and a integer n∈N+n \in \mathbb{N}_+, a code C⊆ΣnC \subseteq \Sigma^n is a set of strings that are far apart. The set Σ\Sigma is called the alphabet of the code, and nn is called the block length of the code. Strings in CC are called codewords.

For x,y∈Σnx, y \in \Sigma^n, define their Hamming distance as

Δ(x,y)≐∣{i∈[n]:xi≠yi}∣. \Delta(x, y) \doteq | \{ i \in [n] : x_i \neq y_i \} |.

The distance Δ(C)\Delta(C) (or dd for a shorthand) of CC, is defined as the minimum distance between two different codes words in CC:

Δ(C)=d≐min⁡x≠y∈CΔ(x,y). \Delta(C) = d \doteq \min_{x \neq y \in C} \Delta(x, y).

If we store a code x∈Cx \in C, and up to (d−1)/2(d - 1) / 2 bits of xx are corrupted, then we can still recover xx. Denote the ball centered at xx with radius r∈R+r \in \mathbb{R}_+ as

B(x,r)≐{y∈Σn:Δ(y,x)≤r}. \mathcal{B}(x, r) \doteq \{ y \in \Sigma^n : \Delta(y, x) \le r \}.

Fact. For x∈Σnx \in \Sigma^n, r∈R+r \in \mathbb{R}_+, the size (volume) of the ball B(x,r)\mathcal{B}(x, r) is independent of xx and is given by

Vol(r)≐∣B(x,r)∣=∑i=0⌊r⌋(ni)(q−1)i. \mathbb{Vol}(r) \doteq | \mathcal{B}(x, r) | = \sum_{i = 0}^{ \lfloor r \rfloor } \binom{n}{i} (q - 1)^i.

If the code CC has distance Δ(C)=d\Delta(C) = d, then the balls {B(x,(d−1)/2):x∈C}\{ \mathcal{B}(x, (d - 1) / 2) : x \in C \} should be disjoint. Therefore, we can upper bound the size ∣C∣|C| in terms of the size of Σn\Sigma^n, and the volume of the balls.

Theorem (Hamming Bound). Let CC be a code with distance d≥3d \ge 3. Then

∣C∣≤qnVol((d−1)/2). |C| \le \frac{q^n }{ \mathbb{Vol} \Big( (d - 1) / 2 \Big) }.

We are going to prove an estimate of the volume.

Theorem (Estimate of Volume). Let r∈R+r \in \mathbb{R}_+. When r≤n−n/qr \le n - n / q,

qnhq(r/n)−O(log⁡n)≤Vol(r)≤qnhq(⌊r⌋/n), q^{ n h_q ( r / n) - O( \log n) } \le \mathbb{Vol} (r) \le q^{ n h_q ( \lfloor r \rfloor / n)},

where

hq(ϵ)≐(1−ϵ)log⁡q(11−ϵ)+(q−1)ϵq−1log⁡q(q−1ϵ)=(1−ϵ)log⁡q(11−ϵ)+ϵlog⁡q(q−1ϵ). \begin{aligned} h_q (\epsilon) &\doteq (1 - \epsilon) \log_q \left( \frac{1}{1 - \epsilon} \right) + (q - 1) \frac{\epsilon}{q - 1} \log_q \left( \frac{q - 1}{ \epsilon } \right) \\ &= (1 - \epsilon) \log_q \left( \frac{1}{1 - \epsilon} \right) + \epsilon \log_q \left( \frac{q - 1}{ \epsilon } \right). \end{aligned}

When q=2q = 2, we have the following corollary.

Corollary. Let r∈R+r \in \mathbb{R}_+. When r≤n/2r \le n / 2,

2n⋅h2(r/n)−O(log⁡n)≤∑i=0⌊r⌋(ni)≤2n⋅h2(⌊r⌋/n), 2^{ n \cdot h_2 ( r / n) - O( \log n) } \le \sum_{i = 0}^{ \lfloor r \rfloor } \binom{n}{i} \le 2^{ n \cdot h_2 ( \lfloor r \rfloor / n)},

where h2(⋅)h_2( \cdot ) is the Shannon's entropy function.

Observe that by concavity of log⁡q(⋅)\log_q (\cdot), we have

hq(ϵ)≤log⁡q((1−ϵ)11−ϵ+ϵq−1ϵ)=1. h_q (\epsilon) \le \log_q \left( (1 - \epsilon) \frac{1}{1 - \epsilon} + \epsilon \frac{q - 1}{ \epsilon } \right) = 1.

The inequality holds with equality when hq(ϵ)h_q(\epsilon) is maximized, i.e., when 1−ϵ=ϵ/(q−1)1 - \epsilon = \epsilon / (q - 1), i.e., 1−ϵ=1/q1 - \epsilon = 1 / q.

Rate of the Code

Based on the theorems of Hamming bound, and the estimate of the volume, we have

∣C∣≤qnVol((d−1)/2)⟹nhq((d/2−1/2)/n)+log⁡q∣C∣≤n+O(log⁡n)⟺hq((d/2−1/2)/n)+log⁡q∣C∣n≤1+O(log⁡qnn)⟹hq(d/2n)+log⁡q∣C∣n≤1+O(log⁡qnn). \begin{aligned} |C| \le \frac{q^n }{ \mathbb{Vol} \Big( (d - 1) / 2 \Big) } &\Longrightarrow n h_q( \lparen d / 2 - 1 / 2 \rparen / n) + \log_q |C| \le n + O(\log n) \\ &\Longleftrightarrow h_q( \lparen d / 2 - 1 / 2 \rparen / n) + \frac{ \log_q |C| }{ n } \le 1 + O\left(\frac{ \log_q n }{ n } \right) \\ &\Longrightarrow h_q( d / 2 n) + \frac{ \log_q |C| }{ n } \le 1 + O\left(\frac{ \log_q n }{ n } \right). \end{aligned}

The last ⟺\Longleftrightarrow holds, since

qn⋅hq((d−1)/(2n))=(q−1)r(nr)r(nn−r)n−rr≐(d−1)/(2)≥(q−1)r′(nr′)r′(nn−r′)n−r′q−1/(2)(nr′)−1/(2)(n−r′n−r)n−r′r′≐d/2=qn⋅hq(d/(2n))(nn−r′)n−r′q−1/2(nr′)−1/2(n−r′n−r)n−r′⟹n⋅hq(d/(2n))≤n⋅hq((d−1)/(2n))+log⁡q(q1/2(nr′)1/2(n−rn−r′)n−r′), \begin{aligned} q^{ n \cdot h_q( \lparen d - 1 \rparen / (2n) ) } &= (q - 1)^r \left(\frac{n}{r} \right)^r \left(\frac{n}{n - r} \right)^{n - r} & \quad r \doteq (d - 1) / (2) \\ &\ge (q - 1)^{r'} \left(\frac{n}{r'} \right)^{r'} \left(\frac{n}{n - r'} \right)^{n - r'} q^{ - 1 / (2) } \left(\frac{n}{r'} \right)^{-1 / (2) } \left(\frac{n - r'}{n - r} \right)^{n - r'} & \quad r' \doteq d / 2 \\ &= q^{ n \cdot h_q( d / (2n) ) } \left(\frac{n}{n - r'} \right)^{n - r'} q^{ - 1 / 2 } \left(\frac{n}{r'} \right)^{-1 / 2 } \left(\frac{n - r'}{n - r} \right)^{n - r'} \\ \Longrightarrow n \cdot h_q( d / (2n) ) &\le n \cdot h_q( \lparen d - 1 \rparen / (2n) ) + \log_q \left( q^{ 1 / 2 } \left(\frac{n}{r'} \right)^{ 1 / 2 } \left(\frac{n - r}{n - r'} \right)^{n - r'} \right), \end{aligned}

and

log⁡q(q1/2(nr′)1/2(n−rn−r′)n−r′)=O(1+log⁡qn+log⁡q(1+1/2n−r′)n−r′)=O(log⁡qn). \log_q \left( q^{ 1 / 2 } \left(\frac{n}{r'} \right)^{ 1 / 2 } \left(\frac{n - r}{n - r'} \right)^{n - r'} \right) = O \left( 1 + \log_q n + \log_q \left( 1 + \frac{1 / 2}{n - r'} \right)^{n - r'} \right) = O \left( \log_q n \right) .

Define the rate of the code R=log⁡q∣C∣nR = \frac{ \log_q |C| }{ n }, and relative distance of the code as δ=dn\delta = \frac{d}{n}, we get

R+hq(δ/2)≤1+O(log⁡qnn). R + h_q( \delta / 2) \le 1 + O\left( \frac{\log_q n }{n} \right).

In what's follows, we prove the inequalities for volume estimation. WLOG, we assume that rr is an integer.

Upper Bound

Theorem. For 0≤r≤n⋅(1−1/q)0 \le r \le n \cdot (1 - 1 / q), it holds that Vol(r)≤qnhq(r/n)\mathbb{Vol} (r) \le q^{n h_q(r / n)}.

Algebraic Approach

(q−1)r(nr)r(nn−r)n−r=(q−1)r(nr)r(nn−r)n−r(rn+n−rn)n≥(q−1)r(nr)r(nn−r)n−r∑i=0r(ni)(rn)i(n−rn)n−i≥∑i=0r(ni)(q−1)i((nr)r−i(n−rn)r−i(q−1)r−i)≥∑i=0r(ni)(q−1)i=Vol(r), \begin{aligned} (q - 1)^{ r } \left( \frac{n}{r} \right)^{ r } \left( \frac{ n }{ n - r } \right)^{n - r } &= (q - 1)^{ r } \left( \frac{n}{r} \right)^{ r } \left( \frac{ n }{ n - r } \right)^{n - r } \left( \frac{r}{n} + \frac{n - r}{n} \right)^n \\ &\ge (q - 1)^{ r } \left( \frac{n}{r} \right)^{ r } \left( \frac{ n }{ n - r } \right)^{n - r } \sum_{i = 0}^{ r} \binom{ n }{i} \left( \frac{r}{n} \right)^i \left( \frac{n - r }{n } \right)^{n - i} \\ &\ge \sum_{i = 0}^{ r} \binom{ n }{i} (q - 1)^{ i } \left( \left( \frac{n}{r} \right)^{ r - i} \left( \frac{n - r }{n } \right)^{r - i} (q - 1)^{r - i} \right) \\ &\ge \sum_{i = 0}^{ r} \binom{ n }{i} (q - 1)^{ i } \\ &= \mathbb{Vol}(r), \end{aligned}

where the last inequality follows from that

nr⋅n−rn⋅(q−1)=(nr−1)⋅(q−1)≥1, \frac{n}{r} \cdot \frac{n - r}{ n } \cdot (q - 1) = \Big( \frac{n}{r} - 1 \Big) \cdot (q - 1)\ge 1,

as r/n≤1−1/q=q/(q−1)r / n \le 1 - 1 / q = q / (q - 1).

Finally, let ϵ≐rn\epsilon \doteq \frac{r}{n}, we have

log⁡Vol(r)≤r⋅log⁡(q−1)+r⋅log⁡1ϵ+(n−r)⋅log⁡11−ϵ=n(ϵ⋅log⁡(q−1)+ϵ⋅log⁡1ϵ+(1−ϵ)⋅log⁡11−ϵ)=n(ϵ⋅log⁡(q−1)+H2(ϵ))=(log⁡q)⋅n⋅hq(ϵ), \begin{aligned} \log \mathbb{Vol}(r) &\le r \cdot \log (q - 1) + r \cdot \log \frac{1}{\epsilon} + (n - r) \cdot \log \frac{1}{1 - \epsilon} \\ &= n \left( \epsilon \cdot \log (q - 1) + \epsilon \cdot \log \frac{1}{\epsilon} + (1 - \epsilon) \cdot \log \frac{1}{1 - \epsilon} \right) \\ &= n \Big( \epsilon \cdot \log (q - 1) + \mathbb{H}_2(\epsilon) \Big) \\ &= (\log q) \cdot n \cdot h_q (\epsilon), \end{aligned}

which proves the claim.

Entropy

We rely on sub-additivity of entropy.

Let XX and YY be discrete random variables, then

  1. H(X,Y)≤H(X)+H(Y)H( X, Y ) \le H(X) + H(Y).
  2. H(X∣Y)≤H(X)H(X | Y) \le H(X).

Proof. Consider the ball B(1n,r)\mathcal{B}(1^n, r), and a uniform random point X=(X1,...,Xn)X = (X_1, ..., X_n) in the ball B(1n,r)\mathcal{B}(1^n, r). Its entropy is

H(X)=log⁡Vol(r). H(X) = \log \mathbb{Vol}(r).

We write Y=X1Y = X_1. By sub-additivity of entropy and by symmetry,

H(X)≤H(X1)+H(X2)+...+H(Xn)=nH(Y). \begin{aligned} H(X) &\le H(X_1) + H(X_2) + ... + H(X_n) &= n H(Y). \end{aligned}

Let ϵ≐Pr⁡[Y≠1]\epsilon \doteq \Pr[ Y \neq 1] be the probability that YY is not 11. Further, by symmetry, Pr⁡[Y=i]\Pr[Y = i] has equal probability for each i≠1i \neq 1. Hence,

H(Y)=Pr⁡[Y=1]⋅log⁡(1Pr⁡[Y=1])+∑i≠1Pr⁡[Y=i]⋅log⁡(1Pr⁡[Y=i])=(1−ϵ)⋅log⁡(11−ϵ)+ϵ⋅log⁡(q−1ϵ) \begin{aligned} H(Y) &= \Pr[ Y = 1] \cdot \log \left( \frac{1}{\Pr[ Y = 1]}\right) + \sum_{i \neq 1} \Pr[ Y = i ] \cdot \log \left( \frac{1}{\Pr[ Y = i]}\right) \\ % &= (1 - \epsilon) \cdot \log \left( \frac{1}{1 - \epsilon} \right) + \epsilon \cdot \sum_{i \neq 1} \frac{ \Pr[ Y = i ] }{ \epsilon } \cdot \log \left( \frac{1}{\Pr[ Y = i]}\right) \\ % &\le (1 - \epsilon) \cdot \log \left( \frac{1}{1 - \epsilon} \right) + \epsilon \cdot \log \left( \sum_{i \neq 1} \frac{ \Pr[ Y = i ] }{ \epsilon } \frac{1}{\Pr[ Y = i]}\right) \\ &= (1 - \epsilon) \cdot \log \left( \frac{1}{1 - \epsilon} \right) + \epsilon \cdot \log \left( \frac{ q - 1 }{ \epsilon } \right) \\ \end{aligned}

where then entropy of YY is maximized when YY is uniform of the elements that are not 1. Further, it can be verified that ϵ<r/n\epsilon < r / n. As hq(ϵ)h_q (\epsilon) increases for ϵ<1−1/q\epsilon < 1 - 1 / q, hence

H(Y)≤(1−r/n)⋅log⁡(11−r/n)+rn⋅log⁡(q−1r/n). H(Y) \le (1 - r / n) \cdot \log \left( \frac{1}{1 - r / n} \right) + \frac{r}{n} \cdot \log \left( \frac{ q - 1 }{ r / n } \right).

□\square

Lower Bound

Theorem. For r∈R+r \in \mathbb{R}_+, it holds that Vol(r)≥qnhq(r/n)−O(log⁡n)\mathbb{Vol} (r) \ge q^{ n h_q ( r / n) - O( \log n) }.

We rely on the Stirling's approximation.

Fact. For n∈N+n \in \mathbb{N}_+, 2πn(ne)n≤n!≤en(ne)n\sqrt{2 \pi n} \left(\frac{n}{e} \right)^n \le n! \le e \sqrt{n} \left(\frac{n}{e} \right)^n.

Proof. First, assume that r∈N+r \in \mathbb{N}_+. It holds that

Vol(r)≥(nr)(q−1)r≥2πn(ne)ner(re)ren−r(n−re)n−r(q−1)r=(q−1)r(nr)r(nn−r)n−r2πne4r(n−r)=qnhq(r/n)−O(log⁡n) \begin{aligned} \mathbb{Vol} (r) &\ge \binom{n}{r} (q - 1)^r \\ &\ge \frac{ \sqrt{2 \pi n } \left(\frac{n}{e} \right)^n }{ e \sqrt{r} \left(\frac{r}{e} \right)^r e \sqrt{n - r} \left(\frac{n - r}{e} \right)^{n - r} } (q - 1)^r \\ &= (q - 1)^r \left(\frac{n}{r} \right)^r \left(\frac{n}{n - r} \right)^{n - r} \sqrt{ \frac{2 \pi n }{e^4 r (n - r)} } \\ &= q^{n h_q ( r / n) - O(\log n) } \end{aligned}

Assume that r∈R+r \in \mathbb{R}_+. Let r′=⌊r⌋r' = \lfloor r \rfloor. Then

Vol(r)≥Vol(r′)≥qnhq(r′/n)−O(log⁡n). \begin{aligned} \mathbb{Vol} (r) \ge \mathbb{Vol} ( r' ) \ge q^{n h_q ( r' / n) - O(\log n) }. \end{aligned}

But

qnhq(r/n)qnhq(r′/n)≤(q−1)⋅(nr′)⋅(n−rn−r′)n−r′∈qO(log⁡qn). \begin{aligned} \frac{ q^{n h_q ( r / n)} }{ q^{n h_q ( r' / n)} } \le (q - 1) \cdot \left(\frac{n}{r'} \right) \cdot \left(\frac{n - r}{n - r'} \right)^{n - r'} \in q^{ O \left( \log_q n \right) } . \end{aligned}

□\square

Hence, the upper bound is rather tight.

Reference

[1] Anup Rao, Coding Theory Lecture 3: The Volume Bound and Finite Fields