Documentation

Complexity.Foundations.Data.Code.BerlekampWelch

The Berlekamp–Welch decoder #

Let w : ι → F be a received word that differs from the values i ↦ p (α i) of a polynomial p of degree less than k at no more than e of the distinct points α i. The Berlekamp–Welch decoder [WB86], [GRS19] looks for a monic error locator E of degree e and a polynomial Q of degree less than e + k with Q (α i) = w i * E (α i) at every point: the key equations (Cslib.Code.BerlekampWelch.IsSolution). They have a solution, with E vanishing at the errors and Q = p * E (Cslib.Code.BerlekampWelch.exists_isSolution). Conversely, if 2 e + k ≤ n, then for every solution Q - p * E has degree less than e + k and vanishes at the at least n - e ≥ e + k points without errors, so Q = p * E and p is the quotient Q /ₘ E (Cslib.Code.BerlekampWelch.IsSolution.divByMonic_eq).

The decoder Cslib.Code.berlekampWelch takes a solution (E, Q), and returns the quotient Q /ₘ E after checking, as in [GRS19], that E divides Q and that the values of the quotient are within distance e of w; it fails, returning none, when there is no solution or a check fails. The checks make it sound for every received word: an output p has degree less than k, its values are within distance e of w, and p * E solves the key equations together with E (Cslib.Code.degree_lt_of_berlekampWelch_eq_some, Cslib.Code.hammingDist_le_of_berlekampWelch_eq_some, Cslib.Code.exists_isSolution_mul_of_berlekampWelch_eq_some). In particular, it fails on a received word with no polynomial of degree less than k within distance e (Cslib.Code.berlekampWelch_eq_none_of_forall_lt_hammingDist). With distinct points and 2 e + k ≤ n it is also complete: it returns p whenever the values of p are within distance e of w (Cslib.Code.berlekampWelch_eq_some), so its outputs are exactly those polynomials (Cslib.Code.berlekampWelch_eq_some_iff). Reed–Solomon codes of dimension k are therefore uniquely decoded up to (n - k) / 2 errors, the largest number below half their minimum distance n - k + 1, and the decoder reports failure beyond that radius when no codeword is close.

The key equations are a system of n linear equations in the 2 e + k unknown coefficients of E and Q; in the literature they are solved by Gaussian elimination. This module proves the correctness of the decoder only: Cslib.Code.berlekampWelch chooses a solution noncomputably, and no running time is formalized.

Main definitions #

Main results #

References #

structure Cslib.Code.BerlekampWelch.IsSolution {F : Type u_1} {ι : Type u_2} [Field F] (α w : ι → F) (e k : ℕ) (E Q : Polynomial F) :

(E, Q) solves the Berlekamp–Welch key equations for the received word w with evaluation points α, e errors and dimension k: the error locator E is monic of degree e, Q has degree less than e + k, and Q (α i) = w i * E (α i) at every point.

  • monic : E.Monic

    The error locator E is monic.

  • natDegree_eq : E.natDegree = e

    The error locator E has degree exactly e.

  • degree_lt : Q.degree < ↑(e + k)

    The polynomial Q, which stands for p * E, has degree less than e + k.

  • eval_eq (i : ι) : Polynomial.eval (α i) Q = w i * Polynomial.eval (α i) E

    The key equations: Q (α i) = w i * E (α i) at every point.

Instances For
    theorem Cslib.Code.BerlekampWelch.IsSolution.degree_divByMonic_lt {F : Type u_1} {ι : Type u_2} [Field F] {α w : ι → F} {e k : ℕ} {E Q : Polynomial F} (h : IsSolution α w e k E Q) :
    (Q /ₘ E).degree < ↑k

    The quotient Q /ₘ E of a solution of the key equations has degree less than k.

    theorem Cslib.Code.BerlekampWelch.exists_isSolution {F : Type u_1} {ι : Type u_2} [Field F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} [Fintype ι] [DecidableEq F] (hp : p.degree < ↑k) (he : hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w ≤ e) :
    ∃ (E : Polynomial F) (Q : Polynomial F), IsSolution α w e k E Q

    If the received word w is within distance e of the values of a polynomial p of degree less than k, the key equations have a solution: E is the product of X - α i over the points i where w is wrong, times a power of X that brings its degree to e, and Q = p * E.

    theorem Cslib.Code.BerlekampWelch.IsSolution.eq_mul {F : Type u_1} {ι : Type u_2} [Field F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} [Fintype ι] [DecidableEq F] (hα : Function.Injective α) (hn : 2 * e + k ≤ Fintype.card ι) (hp : p.degree < ↑k) (he : hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w ≤ e) {E Q : Polynomial F} (h : IsSolution α w e k E Q) :
    Q = p * E

    Correctness of the key equations. With distinct points, if 2 e + k ≤ n and the received word w is within distance e of the values of a polynomial p of degree less than k, every solution (E, Q) of the key equations has Q = p * E.

    theorem Cslib.Code.BerlekampWelch.IsSolution.divByMonic_eq {F : Type u_1} {ι : Type u_2} [Field F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} [Fintype ι] [DecidableEq F] (hα : Function.Injective α) (hn : 2 * e + k ≤ Fintype.card ι) (hp : p.degree < ↑k) (he : hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w ≤ e) {E Q : Polynomial F} (h : IsSolution α w e k E Q) :
    Q /ₘ E = p

    With distinct points, if 2 e + k ≤ n and the received word is within distance e of the values of a polynomial p of degree less than k, every solution (E, Q) of the key equations gives p = Q /ₘ E.

    noncomputable def Cslib.Code.berlekampWelch {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] (α : ι → F) (e k : ℕ) (w : ι → F) :

    The Berlekamp–Welch decoder for e errors and dimension k with evaluation points α: for a solution (E, Q) of the key equations for the received word w, the quotient Q /ₘ E if E divides Q and the values of the quotient are within distance e of w, and none when a check fails or the key equations have no solution. The solution is chosen noncomputably; this definition makes no claim about how it is found.

    Instances For
      theorem Cslib.Code.exists_isSolution_mul_of_berlekampWelch_eq_some {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} (h : berlekampWelch α e k w = some p) :
      ∃ (E : Polynomial F), BerlekampWelch.IsSolution α w e k E (p * E)

      Soundness of the Berlekamp–Welch decoder. Whatever the received word, an output p of the decoder comes with an error locator E such that (E, p * E) solves the key equations.

      theorem Cslib.Code.degree_lt_of_berlekampWelch_eq_some {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} (h : berlekampWelch α e k w = some p) :
      p.degree < ↑k

      Soundness of the Berlekamp–Welch decoder. Whatever the received word, an output of the decoder has degree less than k.

      theorem Cslib.Code.hammingDist_le_of_berlekampWelch_eq_some {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} (h : berlekampWelch α e k w = some p) :
      hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w ≤ e

      Soundness of the Berlekamp–Welch decoder. Whatever the received word w, the values of an output of the decoder are within distance e of w.

      theorem Cslib.Code.berlekampWelch_eq_none_of_forall_lt_hammingDist {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} (h : ∀ (p : Polynomial F), p.degree < ↑k → e < hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w) :

      Failure detection. If the values of no polynomial of degree less than k are within distance e of the received word w, the Berlekamp–Welch decoder returns none.

      theorem Cslib.Code.berlekampWelch_eq_some {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} (hα : Function.Injective α) (hn : 2 * e + k ≤ Fintype.card ι) (hp : p.degree < ↑k) (he : hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w ≤ e) :
      berlekampWelch α e k w = some p

      The Berlekamp–Welch decoder corrects e errors when 2 e + k ≤ n: with distinct points, if the received word w is within distance e of the values of a polynomial p of degree less than k, the decoder returns p.

      theorem Cslib.Code.berlekampWelch_eq_some_iff {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} {p : Polynomial F} (hα : Function.Injective α) (hn : 2 * e + k ≤ Fintype.card ι) :
      berlekampWelch α e k w = some p ↔ p.degree < ↑k ∧ hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w ≤ e

      The outputs of the Berlekamp–Welch decoder when 2 e + k ≤ n: with distinct points, the decoder returns p exactly when p has degree less than k and its values are within distance e of the received word.

      theorem Cslib.Code.berlekampWelch_eq_none_iff {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} (hα : Function.Injective α) (hn : 2 * e + k ≤ Fintype.card ι) :
      berlekampWelch α e k w = none ↔ ∀ (p : Polynomial F), p.degree < ↑k → e < hammingDist (fun (i : ι) => Polynomial.eval (α i) p) w

      Failures of the Berlekamp–Welch decoder when 2 e + k ≤ n: with distinct points, the decoder returns none exactly when the values of no polynomial of degree less than k are within distance e of the received word.

      theorem Cslib.Code.berlekampWelch_eq_some_of_mem_reedSolomon {F : Type u_1} {ι : Type u_2} [Field F] [Fintype ι] [DecidableEq F] {α w : ι → F} {e k : ℕ} (hα : Function.Injective α) (hn : 2 * e + k ≤ Fintype.card ι) {c : ι → F} (hc : c ∈ reedSolomon α k) (he : hammingDist c w ≤ e) :
      ∃ (p : Polynomial F), p.degree < ↑k ∧ (fun (i : ι) => Polynomial.eval (α i) p) = c ∧ berlekampWelch α e k w = some p

      Unique decoding of Reed–Solomon codes. With distinct points, if 2 e + k ≤ n and the received word w is within distance e of a codeword c of the Reed–Solomon code of dimension k, the Berlekamp–Welch decoder returns a polynomial of degree less than k whose values are c.