joint_code_dist_ge
If C ⊆ Fin n → Fin q is a (c, c') joint error-correcting and detecting code, then any two distinct codewords x₁, x₂ ∈ C have Hamming distance at least 2 * c + c' + 1.
Statement
lemma joint_code_dist_ge {n q c c' : ℕ} (C : Finset (Fin n → Fin q))
(hC : is_joint_error_correcting_detecting c c' C)
{x₁ x₂ : Fin n → Fin q} (hx₁ : x₁ ∈ C) (hx₂ : x₂ ∈ C) (hne : x₁ ≠ x₂) :
2 * c + c' + 1 ≤ hammingDist x₁ x₂- Source
- arXiv:2611.18156, Proposition III.5
- Verified
- 23 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 3
- is_joint_error_correcting_detectingGiven implicit parameters n and q, a code C : Finset (Fin n → Fin q) is a (c, c') joint error-correcting and detecting code if distinct…
- hamming_ballGiven implicit parameters n and q, the Hamming ball
hamming_ball r xof radius r centered at x : Fin n → Fin q is the finite set… - hamming_ringGiven implicit parameters n and q, the (c, c') Hamming ring
hamming_ring c c' xcentered at x : Fin n → Fin q is the finite set (Finset)…
- Used by 1
- joint_perfect_code_min_distGiven implicit parameters n, q, c, and c', if C : Finset (Fin n → Fin q) is a (c, c') joint perfect code with 2 ≤ C.card, then…
Read back from the Lean
For any natural numbers n, q, c, and c', and any finite subset C of words (functions from Fin n to Fin q), if C satisfies the joint error-correcting and detecting property with parameters c and c' (that is, for any two distinct codewords in C, their closed Hamming balls of radius c are disjoint; and for any two codewords in C, the closed Hamming ball of radius c around the first is disjoint from the Hamming ring of inner radius c + 1 and outer radius c + c' around the second), then for any two distinct codewords x₁, x₂ ∈ C, the Hamming distance between x₁ and x₂ is at least 2 * c + c' + 1.
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
The proof, explained
The proof proceeds by contradiction: assuming two distinct codewords x₁, x₂ have Hamming distance d < 2 * c + c' + 1, we construct a hybrid word y that copies x₂ on a chosen subset S of coordinates where they differ and copies x₁ elsewhere. If d ≤ 2 * c, choosing |S| = ⌊d / 2⌋ places y within distance c of both x₁ and x₂, contradicting the disjointness of the error-correcting balls around distinct codewords. If d > 2 * c, choosing |S| = c places y at distance c from x₁ and at distance d - c from x₂, which falls strictly into the error-detecting ring of radii between c + 1 and c + c' around x₂, contradicting the disjointness of the error-correcting ball and the error-detecting ring.
For the hybrid word y that agrees with x₂ on S and x₁ elsewhere, the Hamming distance d(x₁, y) equals |S|.
We introduce y as the word taking the value x₂(i) when i ∈ S and x₁(i) when i ∉ S. For any index i, x₁(i) ≠ y(i) holds if and only if i ∈ S, because on S they differ by assumption (hS), while outside S they coincide. Extensionality and case analysis on i ∈ S show that the set of coordinates where x₁ and y differ is exactly S. By definition of Hamming distance, d(x₁, y) = |S|.
uses
Finset.mem_filter,Finset.mem_univ,true_andintro y have h1 : (Finset.univ.filter (fun i => x₁ i ≠ y i)) = S := by ext i simp only [Finset.mem_filter, Finset.mem_univ, true_and] dsimp [y] split_ifs with hi · simp [hi, hS i hi] · simp [hi] have hd : hammingDist x₁ y = S.card := by unfold hammingDist rw [h1] refine ⟨hd, ?_⟩
The Hamming distance d(x₂, y) equals d(x₁, x₂) - |S|.
For each coordinate i, x₂(i) ≠ y(i) holds if and only if i ∉ S and x₁(i) ≠ x₂(i), since y(i) = x₂(i) on S. Thus the set of coordinates where x₂ and y differ is {i | x₁(i) ≠ x₂(i)} \ S. Since S is a subset of the coordinates where x₁ and x₂ differ, the cardinality of this difference set equals |{i | x₁(i) ≠ x₂(i)}| - |S| = d(x₁, x₂) - |S|.
uses
Finset.mem_filter,Finset.mem_univ,Finset.mem_sdiff,ne_comm,Finset.card_sdiff_of_subsethave h2 : (Finset.univ.filter (fun i => x₂ i ≠ y i)) = (Finset.univ.filter (fun i => x₁ i ≠ x₂ i)) \ S := by ext i simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_sdiff] dsimp [y] split_ifs with hi · simp [hi] · simp [hi, ne_comm] unfold hammingDist rw [h2] have h_sub : S ⊆ Finset.univ.filter (fun i => x₁ i ≠ x₂ i) := by intro i hi simp only [Finset.mem_filter, Finset.mem_univ, true_and] exact hS i hi exact Finset.card_sdiff_of_subset h_sub
Assume for contradiction that d(x₁, x₂) < 2 * c + c' + 1, and split into the cases d(x₁, x₂) ≤ 2 * c and d(x₁, x₂) > 2 * c.
We argue by contradiction, assuming d(x₁, x₂) < 2 * c + c' + 1. We let D be the set of coordinates where x₁ and x₂ differ, so |D| = d(x₁, x₂). We then split into two cases according to whether d(x₁, x₂) ≤ 2 * c.
by_contra! h_lt let D := Finset.univ.filter (fun i => x₁ i ≠ x₂ i) have hD : D.card = hammingDist x₁ x₂ := rfl by_cases h_le2 : hammingDist x₁ x₂ ≤ 2 * c
If d(x₁, x₂) ≤ 2 * c, there exists a word in the intersection of the error-correcting balls B(x₁, c) and B(x₂, c), contradicting error correction.
Since ⌊d(x₁, x₂) / 2⌋ ≤ |D|, we can choose a subset S ⊆ D of cardinality ⌊d(x₁, x₂) / 2⌋. The helper lemma yields a hybrid word y with d(x₁, y) = |S| ≤ c and d(x₂, y) = d(x₁, x₂) - |S| ≤ c by linear integer arithmetic from d(x₁, x₂) ≤ 2 * c. Hence y belongs to both Hamming balls B(x₁, c) and B(x₂, c). However, distinct codewords in a joint code have disjoint error-correcting balls of radius c, a contradiction.
uses
Finset.exists_subset_card_eq,joint_code_dist_ge_helper,Finset.disjoint_left· obtain ⟨S, hSD, hScard⟩ := Finset.exists_subset_card_eq (by omega : hammingDist x₁ x₂ / 2 ≤ D.card) have hS : ∀ i ∈ S, x₁ i ≠ x₂ i := fun i hi => (Finset.mem_filter.mp (hSD hi)).2 have ⟨hy1, hy2⟩ := joint_code_dist_ge_helper x₁ x₂ S hS have h_disj := hC.1 x₁ hx₁ x₂ hx₂ hne rw [Finset.disjoint_left] at h_disj apply h_disj (a := fun i => if i ∈ S then x₂ i else x₁ i) · simp only [hamming_ball, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy1, hScard] omega · simp only [hamming_ball, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy2, hScard] omega
If d(x₁, x₂) > 2 * c, there exists a word in the intersection of the error-correcting ball B(x₁, c) and the error-detecting ring Ring(x₂, c, c'), contradicting error detection.
Since d(x₁, x₂) > 2 * c, we have c ≤ |D|, so we can choose a subset S ⊆ D of cardinality c. The helper lemma yields a hybrid word y with d(x₁, y) = c, so y belongs to the ball B(x₁, c). Moreover, d(x₂, y) = d(x₁, x₂) - c. Since 2 * c < d(x₁, x₂) < 2 * c + c' + 1, linear arithmetic gives c + 1 ≤ d(x₂, y) ≤ c + c', so y belongs to the ring Ring(x₂, c, c'). This contradicts the joint code condition that B(x₁, c) and Ring(x₂, c, c') are disjoint.
uses
Finset.exists_subset_card_eq,joint_code_dist_ge_helper,Finset.disjoint_left· obtain ⟨S, hSD, hScard⟩ := Finset.exists_subset_card_eq (by omega : c ≤ D.card) have hS : ∀ i ∈ S, x₁ i ≠ x₂ i := fun i hi => (Finset.mem_filter.mp (hSD hi)).2 have ⟨hy1, hy2⟩ := joint_code_dist_ge_helper x₁ x₂ S hS have h_disj := hC.2 x₁ hx₁ x₂ hx₂ rw [Finset.disjoint_left] at h_disj apply h_disj (a := fun i => if i ∈ S then x₂ i else x₁ i) · simp only [hamming_ball, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy1, hScard] · simp only [hamming_ring, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy2, hScard] constructor <;> omega
Finset.card_sdiff_of_subset- If s ⊆ t, the cardinality of the difference t \ s is |t| - |s|.
Finset.disjoint_left- Two finite sets are disjoint if and only if no element of the first belongs to the second.
Finset.exists_subset_card_eq- A finite set of size at least k contains a subset of cardinality exactly k.
Finset.mem_filter- An element belongs to a filtered finite set if and only if it belongs to the base set and satisfies the predicate.
Finset.mem_sdiff- An element belongs to the set difference s \ t if and only if it belongs to s and does not belong to t.
Finset.mem_univ- Every element of a finite type belongs to the universal finite set univ.
joint_code_dist_ge_helper- For codewords x₁ and x₂ and a subset S of coordinates where they differ, the hybrid word y taking values from x₂ on S and x₁ elsewhere satisfies d(x₁, y) = |S| and d(x₂, y) = d(x₁, x₂) - |S|.
ne_comm- Inequality is symmetric: a ≠ b if and only if b ≠ a.
true_and- Conjunction with True simplifies to the proposition itself: (True ∧ p) = p.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
lemma joint_code_dist_ge_helper {n q : ℕ} (x₁ x₂ : Fin n → Fin q) (S : Finset (Fin n)) (hS : ∀ i ∈ S, x₁ i ≠ x₂ i) : let y : Fin n → Fin q := fun i => if i ∈ S then x₂ i else x₁ i hammingDist x₁ y = S.card ∧ hammingDist x₂ y = hammingDist x₁ x₂ - S.card := by intro y have h1 : (Finset.univ.filter (fun i => x₁ i ≠ y i)) = S := by ext i simp only [Finset.mem_filter, Finset.mem_univ, true_and] dsimp [y] split_ifs with hi · simp [hi, hS i hi] · simp [hi] have hd : hammingDist x₁ y = S.card := by unfold hammingDist rw [h1] refine ⟨hd, ?_⟩ have h2 : (Finset.univ.filter (fun i => x₂ i ≠ y i)) = (Finset.univ.filter (fun i => x₁ i ≠ x₂ i)) \ S := by ext i simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_sdiff] dsimp [y] split_ifs with hi · simp [hi] · simp [hi, ne_comm] unfold hammingDist rw [h2] have h_sub : S ⊆ Finset.univ.filter (fun i => x₁ i ≠ x₂ i) := by intro i hi simp only [Finset.mem_filter, Finset.mem_univ, true_and] exact hS i hi exact Finset.card_sdiff_of_subset h_sub/-- Distinct codewords in a (c, c') joint error-correcting and detecting code have Hamming distance at least 2c + c' + 1. -/lemma joint_code_dist_ge {n q c c' : ℕ} (C : Finset (Fin n → Fin q)) (hC : is_joint_error_correcting_detecting c c' C) {x₁ x₂ : Fin n → Fin q} (hx₁ : x₁ ∈ C) (hx₂ : x₂ ∈ C) (hne : x₁ ≠ x₂) : 2 * c + c' + 1 ≤ hammingDist x₁ x₂ := by by_contra! h_lt let D := Finset.univ.filter (fun i => x₁ i ≠ x₂ i) have hD : D.card = hammingDist x₁ x₂ := rfl by_cases h_le2 : hammingDist x₁ x₂ ≤ 2 * c · obtain ⟨S, hSD, hScard⟩ := Finset.exists_subset_card_eq (by omega : hammingDist x₁ x₂ / 2 ≤ D.card) have hS : ∀ i ∈ S, x₁ i ≠ x₂ i := fun i hi => (Finset.mem_filter.mp (hSD hi)).2 have ⟨hy1, hy2⟩ := joint_code_dist_ge_helper x₁ x₂ S hS have h_disj := hC.1 x₁ hx₁ x₂ hx₂ hne rw [Finset.disjoint_left] at h_disj apply h_disj (a := fun i => if i ∈ S then x₂ i else x₁ i) · simp only [hamming_ball, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy1, hScard] omega · simp only [hamming_ball, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy2, hScard] omega · obtain ⟨S, hSD, hScard⟩ := Finset.exists_subset_card_eq (by omega : c ≤ D.card) have hS : ∀ i ∈ S, x₁ i ≠ x₂ i := fun i hi => (Finset.mem_filter.mp (hSD hi)).2 have ⟨hy1, hy2⟩ := joint_code_dist_ge_helper x₁ x₂ S hS have h_disj := hC.2 x₁ hx₁ x₂ hx₂ rw [Finset.disjoint_left] at h_disj apply h_disj (a := fun i => if i ∈ S then x₂ i else x₁ i) · simp only [hamming_ball, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy1, hScard] · simp only [hamming_ring, Finset.mem_filter, Finset.mem_univ, true_and] rw [hy2, hScard] constructor <;> omega