Documentation

ArkLib.Data.CodingTheory.Basic

Basics of Coding Theory #

We define a general code C to be a subset of n → R for some finite index set n and some target type R.

We can then specialize this notion to various settings. For [CommSemiring R], we define a linear code to be a linear subspace of n → R. We also define the notion of generator matrix and (parity) check matrix.

Main Definitions #

We define the block length, rate, and distance of C. We prove simple properties of linear codes such as the singleton bound.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      noncomputable def Distance.codeDist {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) :

      The Hamming distance of a code C is the minimum Hamming distance between any two distinct elements of the code. cd We formalize this as the infimum sInf over all d : ℕ such that there exist u v : n → R in the code with u ≠ v and hammingDist u v ≤ d. If none exists, then we define the distance to be 0.

      Equations
      Instances For
        instance Distance.instEDistForall_arkLib {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] :
        EDist (nR)
        Equations
        instance Distance.instDistForall_arkLib {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] :
        Dist (nR)
        Equations
        noncomputable def Distance.eCodeDistNew {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) :
        Equations
        Instances For
          noncomputable def Distance.codeDistNew {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) :
          Equations
          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              noncomputable def Distance.distFromCode {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (u : nR) (C : Set (nR)) :

              The distance from a vector u to a code C is the minimum Hamming distance between u and any element of C.

              Equations
              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  noncomputable def Distance.minDist {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) :
                  Equations
                  Instances For
                    @[simp]
                    theorem Distance.codeDist_empty {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] :
                    @[simp]
                    theorem Distance.codeDist_subsingleton {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] {C : Set (nR)} [Subsingleton C] :
                    @[simp]
                    theorem Distance.codeDist_le_card {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) :
                    theorem Distance.eq_of_lt_codeDist {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] {C : Set (nR)} {u v : nR} (hu : u C) (hv : v C) (huv : Δ₀(u, v) < C‖₀) :
                    u = v

                    If u and v are two codewords of C with distance less than codeDist C, then they are the same.

                    @[simp]
                    theorem Distance.distFromCode_of_empty {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (u : nR) :
                    theorem Distance.distFromCode_eq_top_iff_empty {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (u : nR) (C : Set (nR)) :
                    @[simp]
                    theorem Distance.distFromCode_of_mem {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) {u : nR} (h : u C) :
                    Δ₀(u, C) = 0
                    theorem Distance.distFromCode_eq_zero_iff_mem {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) (u : nR) :
                    Δ₀(u, C) = 0 u C
                    theorem Distance.distFromCode_eq_of_lt_half_codeDist {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) (u : nR) {v w : nR} (hv : v C) (hw : w C) (huv : Δ₀(u, v) < C‖₀ / 2) (hvw : Δ₀(u, w) < C‖₀ / 2) :
                    v = w
                    def Distance.codeDist' {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) [Fintype C] :

                    Computable version of the Hamming distance of a code C, assuming C is a Fintype.

                    The return type is ℕ∞ since we use Finset.min.

                    Equations
                    Instances For
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        @[simp]
                        @[simp]
                        theorem Distance.codeDist'_subsingleton {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] {C : Set (nR)} [Fintype C] [Subsingleton C] :
                        theorem Distance.codeDist'_eq_codeDist {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] {C : Set (nR)} [Fintype C] :
                        def Distance.possibleDistsToC {α : Type u_3} {F : Type u_4} {ι : Type u_5} (w : ιF) (C : Set (ιF)) (δf : (ιF)(ιF)α) :
                        Set α

                        The set of possible distances δf from a vector w to a code C.

                        Equations
                        Instances For
                          def Distance.possibleDists {α : Type u_3} {F : Type u_4} {ι : Type u_5} (C : Set (ιF)) (δf : (ιF)(ιF)α) :
                          Set α

                          The set of possible distances δf between distinct codewords in a code C.

                          • TODO: This allows us to express distance in non-ℝ, which is quite convenient. Extending to (E)Dist forces this into ; give some thought.
                          Equations
                          Instances For
                            noncomputable def Distance.distToCode {α : Type u_3} {F : Type u_4} {ι : Type u_5} [LinearOrder α] [Zero α] (w : ιF) (C : Set (ιF)) (δf : (ιF)(ιF)α) (h : (possibleDistsToC w C δf).Finite) :

                            A generalisation of distFromCode for an arbitrary distance function δf.

                            Equations
                            Instances For
                              theorem Distance.distToCode_of_nonempty {α : Type u_3} [LinearOrder α] [Zero α] {ι : Type u_4} {F : Type u_5} {w : ιF} {C : Set (ιF)} {δf : (ιF)(ιF)α} (h₁ : (possibleDistsToC w C δf).Finite) (h₂ : (possibleDistsToC w C δf).Nonempty) :
                              distToCode w C δf h₁ = ((possibleDistsToC w C δf).toFinset.min' )
                              def Distance.distFromCode' {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) [Fintype C] (u : nR) :

                              Computable version of the distance from a vector u to a code C, assuming C is a Fintype.

                              Equations
                              Instances For
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def codeByGenMatrix {n : Type u_1} {R : Type u_2} {k : Type u_3} [Fintype k] [CommSemiring R] (G : Matrix k n R) :
                                  Submodule R (nR)

                                  Define a linear code from its generator matrix

                                  Equations
                                  Instances For
                                    def codeByCheckMatrix {n : Type u_1} [Fintype n] {R : Type u_2} {k : Type u_3} [CommSemiring R] (H : Matrix k n R) :
                                    Submodule R (nR)

                                    Define a linear code from its (parity) check matrix

                                    Equations
                                    Instances For
                                      noncomputable def linearCodeDist {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] [CommSemiring R] (C : Submodule R (nR)) :

                                      The Hamming distance of a linear code can also be defined as the minimum Hamming norm of a non-zero vector in the code

                                      Equations
                                      Instances For
                                        def linearCodeDist' {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] [CommSemiring R] [DecidableEq n] [Fintype R] (C : Submodule R (nR)) [DecidablePred fun (x : nR) => x C] :

                                        A computable version of the Hamming distance of a linear code C.

                                        Equations
                                        Instances For
                                          def interleaveCode {n : Type u_1} {R : Type u_2} [CommSemiring R] (C : Submodule R (nR)) (ι : Type u_4) :
                                          Submodule R (ι × nR)

                                          The interleaving of a linear code C over index set ι is the submodule spanned by ι × n-matrices whose rows are elements of C.

                                          Equations
                                          Instances For
                                            def Function.interleave₂ {α : Type u_4} {β : Type u_5} (u v : αβ) :
                                            Fin 2 × αβ

                                            Interleave two functions u v : α → β.

                                            Equations
                                            Instances For
                                              def projection {n : Type u_1} {R : Type u_2} (S : Finset n) (w : nR) :
                                              { x : n // x S }R
                                              Equations
                                              Instances For
                                                theorem projection_injective {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] (C : Set (nR)) (nontriv : C‖₀ 1) (S : Finset n) (hS : Fintype.card { x : n // x S } = Fintype.card n - (C‖₀ - 1)) (u v : nR) (hu : u C) (hv : v C) :
                                                projection S u = projection S vu = v
                                                theorem singleton_bound {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] [Finite R] (C : Set (nR)) :

                                                Singleton bound for arbitrary codes

                                                theorem singleton_bound_linear {n : Type u_1} [Fintype n] {R : Type u_2} [DecidableEq R] [Finite R] [DivisionRing R] (C : Submodule R (nR)) :

                                                Singleton bound for linear codes

                                                def RelativeHamming.dist {ι : Type u_3} [Fintype ι] {F : Type u_4} [DecidableEq F] (u v : ιF) :
                                                Equations
                                                Instances For

                                                  δᵣ(u,v) denotes the relative Hamming distance between vectors u and v.

                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For
                                                    @[simp]
                                                    theorem RelativeHamming.relHammingDist_le_one {ι : Type u_3} [Fintype ι] {F : Type u_4} {u v : ιF} [Nonempty ι] [DecidableEq F] :

                                                    The relative Hamming distance between two vectors is at most 1.

                                                    @[simp]
                                                    theorem RelativeHamming.zero_le_relHammingDist {ι : Type u_3} [Fintype ι] {F : Type u_4} {u v : ιF} [Nonempty ι] [DecidableEq F] :

                                                    The relative Hamming distance between two vectors is non-negative.

                                                    The range of the relative Hamming distance function.

                                                    Equations
                                                    Instances For
                                                      @[simp]

                                                      The range of the relative Hamming distance is well-defined.

                                                      @[simp]

                                                      The range of the relative Hamming distance function is finite.

                                                      @[simp]
                                                      theorem RelativeHamming.finite_offDiag {ι : Type u_3} [Fintype ι] {F : Type u_4} {C : Set (ιF)} [Finite F] :

                                                      The set of pairs of distinct elements from a finite set is finite.

                                                      def RelativeHamming.possibleDists {ι : Type u_3} [Fintype ι] {F : Type u_4} [DecidableEq F] (C : Set (ιF)) :

                                                      The set of possible distances between distinct codewords in a code.

                                                      Equations
                                                      Instances For
                                                        @[simp]

                                                        The set of possible distances between distinct codewords in a code is a subset of the range of the relative Hamming distance function.

                                                        @[simp]
                                                        theorem RelativeHamming.finite_possibleDists {ι : Type u_3} [Fintype ι] {F : Type u_4} {C : Set (ιF)} [DecidableEq F] [Nonempty ι] :

                                                        The set of possible distances between distinct codewords in a code is a finite set.

                                                        def RelativeHamming.minRelHammingDistCode {ι : Type u_3} [Fintype ι] {F : Type u_4} [DecidableEq F] [Nonempty ι] (C : Set (ιF)) :

                                                        The minimum relative Hamming distance of a code.

                                                        Equations
                                                        Instances For

                                                          δᵣ C denotes the minimum relative Hamming distance of a code C.

                                                          Equations
                                                          Instances For
                                                            @[simp]

                                                            The range set of possible relative Hamming distances from a vector to a code is a subset of the range of the relative Hamming distance function.

                                                            @[simp]
                                                            theorem RelativeHamming.finite_possibleDistsToC {ι : Type u_3} [Fintype ι] {F : Type u_4} {w : ιF} {C : Set (ιF)} [Nonempty ι] [DecidableEq F] :

                                                            The set of possible relative Hamming distances from a vector to a code is a finite set.

                                                            def RelativeHamming.relHammingDistToCode {ι : Type u_3} [Fintype ι] {F : Type u_4} [Nonempty ι] [DecidableEq F] (w : ιF) (C : Set (ιF)) :

                                                            The relative Hamming distance from a vector to a code.

                                                            Equations
                                                            Instances For
                                                              theorem RelativeHamming.relHammingDistToCode.p {ι : Type u_3} [Fintype ι] {F : Type u_4} [Nonempty ι] [DecidableEq F] (w : ιF) (C : Set (ιF)) (h : (Distance.possibleDistsToC w C dist).Nonempty) :

                                                              δᵣ(w,C) denotes the relative Hamming distance between a vector w and a code C.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                @[simp]
                                                                theorem RelativeHamming.relHammingDistToCode_mem_relHammingDistRange {ι : Type u_3} [Fintype ι] {F : Type u_4} {c : ιF} {C : Set (ιF)} [Nonempty ι] [DecidableEq F] :

                                                                The relative Hamming distances between a vector and a codeword is in the range of the relative Hamming distance function.

                                                                @[reducible, inline]
                                                                abbrev LinearCode (ι : Type u) [Fintype ι] (F : Type v) [Semiring F] :
                                                                Type (max u v)
                                                                Equations
                                                                Instances For
                                                                  noncomputable def LinearCode.wt {F : Type u_3} {ι : Type u_4} [Fintype ι] [DecidableEq F] [Zero F] (v : ιF) :
                                                                  Equations
                                                                  Instances For
                                                                    theorem LinearCode.wt_eq_zero_iff {F : Type u_3} {ι : Type u_4} [Fintype ι] [DecidableEq F] [Zero F] {v : ιF} :
                                                                    wt v = 0 Fintype.card ι = 0 ∀ (i : ι), v i = 0
                                                                    def LinearCode.fromRowGenMat {F : Type u_3} {ι : Type u_5} [Fintype ι] {κ : Type u_6} [Fintype κ] [Semiring F] (G : Matrix κ ι F) :

                                                                    Linear code defined by left multiplication by its generator matrix.

                                                                    Equations
                                                                    Instances For
                                                                      def LinearCode.fromColGenMat {F : Type u_3} {ι : Type u_5} [Fintype ι] {κ : Type u_6} [Fintype κ] [CommRing F] (G : Matrix ι κ F) :

                                                                      Linear code defined by right multiplication by a generator matrix.

                                                                      Equations
                                                                      Instances For
                                                                        noncomputable def LinearCode.dim {F : Type u_3} {ι : Type u_5} [Fintype ι] [Semiring F] (LC : LinearCode ι F) :
                                                                        Equations
                                                                        Instances For
                                                                          theorem LinearCode.rank_eq_dim_fromColGenMat {F : Type u_3} {ι : Type u_5} [Fintype ι] {κ : Type u_6} [Fintype κ] [CommRing F] {G : Matrix κ ι F} :

                                                                          The dimension of a linear code equals the rank of its associated generator matrix.

                                                                          def LinearCode.length {F : Type u_3} {ι : Type u_5} [Fintype ι] [Semiring F] :
                                                                          LinearCode ι F
                                                                          Equations
                                                                          Instances For
                                                                            noncomputable def LinearCode.rate {F : Type u_3} {ι : Type u_5} [Fintype ι] [Semiring F] (LC : LinearCode ι F) :
                                                                            Equations
                                                                            Instances For

                                                                              ρ LC is the rate of the linear code LC.

                                                                              Equations
                                                                              Instances For
                                                                                noncomputable def LinearCode.minWtCodewords {F : Type u_3} {ι : Type u_5} [Fintype ι] [DecidableEq F] [Semiring F] (LC : LinearCode ι F) :

                                                                                The minimum taken over the weight of codewords in a linear code.

                                                                                Equations
                                                                                Instances For
                                                                                  theorem LinearCode.hammingDist_eq_wt_sub {F : Type u_3} {ι : Type u_5} [Fintype ι] [DecidableEq F] [CommRing F] {u v : ιF} :
                                                                                  Δ₀(u, v) = wt (u - v)

                                                                                  The Hamming distance between codewords equals to the weight of their difference.

                                                                                  The min distance of a linear code equals to the minimum of the weights of non-zero codewords.

                                                                                  theorem LinearCode.minDist_UB {F : Type u_3} {ι : Type u_5} [Fintype ι] [DecidableEq F] [CommRing F] {LC : LinearCode ι F} :
                                                                                  theorem LinearCode.singletonBound {F : Type u_3} {ι : Type u_5} [Fintype ι] [DecidableEq F] [Semiring F] (LC : LinearCode ι F) :
                                                                                  theorem poly_eq_zero_of_dist_lt {n k : } {F : Type u_3} [DecidableEq F] [CommRing F] [IsDomain F] {p : Polynomial F} {ωs : Fin nF} (h_deg : p.natDegree < k) (hn : k n) (h_inj : Function.Injective ωs) (h_dist : Δ₀((fun (a : F) => Polynomial.eval a p) ωs, 0) < n - k + 1) :
                                                                                  p = 0