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 Distance is at most block length
#

If a code \(C\) has minimum distance \(d\), then \(d \le n\).

4.5 Additional declarations

Lemma 4.14 Alphabet size positive

If \(q \ge 2\), then \(q \gt 0\) as a real number.

Lemma 4.15 Alphabet size exceeds one

If \(q \ge 2\), then \(1 \lt q\) as a real number.

Lemma 4.16 \(q-1\) positive

If \(q \ge 2\), then \(0 \lt q - 1\) as a real number.

Lemma 4.17 Alphabet size differs from one

If \(q \ge 2\), then \(q \ne 1\) as a real number.

Lemma 4.18 \(1-p\) positive when \(p \lt 1\)

If \(p \lt 1\), then \(0 \lt 1 - p\).

Lemma 4.19 \(p(1-p)\) positive

If \(0 \lt p\) and \(p \lt 1\), then \(0 \lt p(1 - p)\).

Lemma 4.20 Below \(1 - 1/q\) implies below one

If \(0 \lt q\) and \(p \le 1 - 1/q\), then \(p \lt 1\).