TCSLib

4 Error-Correcting Codes — Core Definitions

4.1 Overview

This file documents the foundational definitions for \(q\)-ary block codes over a finite field alphabet \(\alpha \). Throughout, \(\alpha \) is a type carrying instances [Fintype α], [Field α], [DecidableEq α], and [Nonempty α].

4.2 Basic objects: codewords and codes

4.2.1 Codewords

Definition 4.1 Codeword
✓
#

A codeword of length \(n\) over alphabet \(\alpha \) is a function \(c : \mathrm{Fin}\, n \to \alpha \).

Definition 4.2 Pointwise operations
✓
#

Pointwise addition, subtraction, and the all-zero codeword.

4.2.2 Codes and linear codes

Definition 4.3 Code
✓
#

A (block) code of length \(n\) over \(\alpha \) is a finite set (Finset) of codewords.

Definition 4.4 Linear code via generator matrix
✓
#

A code \(C\) is linear with generator matrix \(G\) (shape \(n\times m\)) if every message \(c':\mathrm{Fin}\, m\to \alpha \) maps to a codeword \(Gc'\in C\), and every codeword in \(C\) arises this way.

Definition 4.5 Linear code, existential form
✓
#

Existential version: there exists some \(m\) and generator matrix \(G\) witnessing linearity.

4.3 Distance, weight, and rate

Definition 4.6 \(q\)-ary entropy
✓
#
\[ H_q(p) \; =\; p\log _q(q-1) - p\log _q p - (1-p)\log _q(1-p). \]
Definition 4.7 Hamming distance
✓

Hamming distance between two codewords, wrapping Mathlib’s hammingDist.

Definition 4.8 Distance predicate for a code
✓
#

distance C d holds when \(d\) is the minimum Hamming distance of \(C\): there exist distinct codewords at distance exactly \(d\), and no two distinct codewords are closer than \(d\).

Definition 4.9 Rate
✓
#
\[ R(C) = \frac{\log |C|}{n\log |\alpha |}. \]
Definition 4.10 Weight
✓
#

The Hamming weight of \(c\) is \(d(c, \mathbf{0})\).

Definition 4.11 Maximal size at distance
✓
#

max_size n d A asserts existence of a code of size \(A\) and minimum distance \(d\) that is maximal among all such codes.

Definition 4.12 Hamming ball
✓
#

The Hamming ball of radius \(l\) around \(c\):

\[ B_l(c) = \{ c' : d(c',c) \le l\} , \]

implemented as a Finset.

4.4 Basic lemma: distance vs. block length

Lemma 4.13 Minimum distance is at most the block length
✓
#

Let \(C\) be a code of length \(n\) over an alphabet \(\alpha \) — that is, a finite set of codewords, each a function \(\mathrm{Fin}\, n \to \alpha \) — and let \(d\) be a natural number that is the minimum distance of \(C\): there exist two distinct codewords of \(C\) at Hamming distance exactly \(d\), and every pair of distinct codewords of \(C\) is at Hamming distance at least \(d\). Then \(d \le n\).

4.5 Additional declarations

Lemma 4.14 Positivity of a natural number at least two
✓

Let \(q\) be a natural number with \(q \ge 2\). Then its image in the real numbers satisfies \(0 \lt q\).

Lemma 4.15 One is less than a natural number at least two
✓

For any natural number \(q\) with \(q \ge 2\), the image of \(q\) under the canonical embedding of the naturals into the reals satisfies \(1 \lt q\).

Lemma 4.16 Positivity of \(q-1\) for \(q \ge 2\)
✓

Let \(q\) be a natural number with \(q \ge 2\). Then, regarded as a real number, \(q - 1\) is strictly positive: \(0 \lt q - 1\).

Lemma 4.17 Integers at least two are not one as reals
✓

Let \(q\) be a natural number with \(q \ge 2\). Then, regarded as a real number, \(q \ne 1\).

Lemma 4.18 Positivity of one minus a subunital real
✓

Let \(p\) be a real number with \(p \lt 1\). Then \(1 - p \gt 0\).

Lemma 4.19 Positivity of \(p(1-p)\) on the unit interval
✓

Let \(p\) be a real number with \(0 \lt p \lt 1\). Then \(p(1-p) \gt 0\).

Lemma 4.20 A rate bound below one
✓

Let \(q\) and \(p\) be real numbers with \(q \gt 0\). If \(p \le 1 - 1/q\), then \(p \lt 1\).