AFTD Auto-Formalizing Theoretical Domains

op2468_blackburn_zero_deficit_n_two

theoremverifiedformalization

For length n = 2 and alphabet size q = 2m with m >= 1, every non-overlapping code C in Finset (Fin 2 -> Fin q) of size at least (1/4) q^2 has distance 0 to the optimal Blackburn codes: code_dist C, the infimum over optimal Blackburn codes B (pairs with first symbol in I and second outside I, or the reverse, with 2|I| = q) of |C symmDiff B| / q^2, equals 0.

Statement

theorem op2468_blackburn_zero_deficit_n_two (m : ℕ) (hm : 1 ≤ m) :
    let q : ℕ := m * 2
    let lam : ℝ := (2 - 1 : ℝ) / 2
    let c_n : ℝ := lam ^ (2 - 1) / (2 : ℝ)
    let is_nonoverlapping (C : Finset (Fin 2 → Fin q)) : Prop :=
      ∀ u ∈ C, ∀ v ∈ C, ¬ ∃ (k : ℕ) (_ : 0 < k) (_ : k < 2),
        ∀ i : Fin k, u ⟨i.val, by omega⟩ = v ⟨2 - k + i.val, by omega⟩
    let optimal_blackburn : Set (Finset (Fin 2 → Fin q)) :=
      { B | ∃ (I : Finset (Fin q)), 2 * I.card = (2 - 1) * q ∧
        (B = Finset.filter (fun w => (∀ (i : Fin 2), i.val < 2 - 1 → w i ∈ I) ∧
          w ⟨2 - 1, by omega⟩ ∉ I) Finset.univ ∨
         B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧
          (∀ (i : Fin 2), 0 < i.val → w i ∈ I)) Finset.univ) }
    let code_dist (C : Finset (Fin 2 → Fin q)) : ℝ :=
      sInf { ((symmDiff C B).card : ℝ) / (q : ℝ) ^ 2 | B ∈ optimal_blackburn }
    ∀ (C : Finset (Fin 2 → Fin q)), is_nonoverlapping C →
      c_n * (q : ℝ) ^ 2 ≤ (C.card : ℝ) → code_dist C = 0
Formalizes
arXiv:2611.28776, Theorem II.6 (rigidity of the optimal non-overlapping codes), special case n = 2; the proof here is the elementary disjoint-symbol-sets argument, not the paper's.
Verified
29 Nov 2026
Axioms
Classical.choiceQuot.soundpropext

Read back from the Lean

For every natural number $m \ge 1$: Let: - $q = 2m$, - $\lambda = (2 - 1)/2 = 1/2$, - $c_n = \lambda^{2-1} / 2 = 1/4$, - a code $C \subseteq (\text{Fin } 2 \to \text{Fin } q)$ be called *non-overlapping* if for all $u, v \in C$, there is no $k \in \mathbb{N}$ with $0 < k < 2$ such that $u(i) = v(2 - k + i)$ for all $i \in \text{Fin } k$ (which, since $k$ must be $1$, means $u(0) \ne v(1)$ for all $u, v \in C$), - $\text{optimal\_blackburn}$ be the family of codes $B \subseteq (\text{Fin } 2 \to \text{Fin } q)$ for which there exists a subset $I \subseteq \text{Fin } q$ of cardinality $q/2 = m$ (i.e., $2 |I| = q$) such that either: 1. $B = \{w : \text{Fin } 2 \to \text{Fin } q \mid w(0) \in I \text{ and } w(1) \notin I\}$, or 2. $B = \{w : \text{Fin } 2 \to \text{Fin } q \mid w(0) \notin I \text{ and } w(1) \in I\}$, - $\text{code\_dist}(C) = \inf \{ |C \Delta B| / q^2 \mid B \in \text{optimal\_blackburn} \}$. Then for every finset $C$ of words of length 2 over an alphabet of size $q$: if $C$ is non-overlapping, and $|C| \ge c_n q^2 = m^2$, then $\text{code\_dist}(C) = 0$ (which, since $\text{optimal\_blackburn}$ is non-empty and finite, is equivalent to asserting that $C \in \text{optimal\_blackburn}$).

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

lemma in1286_card_prod {q : ℕ} (X Y : Finset (Fin q)) :    (Finset.univ.filter (fun w : Fin 2 → Fin q => w 0 ∈ X ∧ w 1 ∈ Y)).card      = X.card * Y.card := by  rw [← Finset.card_product]  refine Finset.card_nbij' (fun w => (w 0, w 1)) (fun p => ![p.1, p.2]) ?_ ?_ ?_ ?_  · intro w hw    simp only [Finset.coe_filter, Finset.mem_univ, true_and, Set.mem_ofPred_eq,      Finset.coe_product, Set.mem_prod, Finset.mem_coe] at hw ⊢    exact hw  · intro p hp    simp only [Finset.coe_filter, Finset.mem_univ, true_and, Set.mem_ofPred_eq,      Finset.coe_product, Set.mem_prod, Finset.mem_coe] at hp ⊢    simpa using hp  · intro w _    funext i    fin_cases i <;> rfl  · intro p _    rfllemma in1286_card_B1 {q : ℕ} (I : Finset (Fin q)) :    (Finset.univ.filter (fun w : Fin 2 → Fin q => w 0 ∈ I ∧ w 1 ∉ I)).card      = I.card * (q - I.card) := by  have h := in1286_card_prod I Iᶜ  rw [Finset.card_compl, Fintype.card_fin] at h  rw [← h]  congr 1  ext w  simplemma in1286_card_B2 {q : ℕ} (I : Finset (Fin q)) :    (Finset.univ.filter (fun w : Fin 2 → Fin q => w 0 ∉ I ∧ w 1 ∈ I)).card      = (q - I.card) * I.card := by  have h := in1286_card_prod Iᶜ I  rw [Finset.card_compl, Fintype.card_fin] at h  rw [← h]  congr 1  ext w  simplemma in1286_symm {α : Type*} [DecidableEq α] (C B : Finset α) :    (symmDiff C B).card + 2 * (C ∩ B).card = C.card + B.card := by  rw [symmDiff_def, Finset.sup_eq_union, Finset.card_union_of_disjoint disjoint_sdiff_sdiff]  have h1 := Finset.card_sdiff_add_card_inter C B  have h2 := Finset.card_sdiff_add_card_inter B C  rw [Finset.inter_comm] at h2  omegalemma in1286_dev (m : ℕ) (ε : ℝ) (hε : 0 ≤ ε) (cC x y : ℕ) (hxy : x + y ≤ m * 2)    (hC : cC ≤ x * y) (hmx : m ≤ x)    (hcard : (1/4 - ε) * ((m*2 : ℕ) : ℝ)^2 ≤ cC) :    ((x:ℝ) - m) ≤ 2 * Real.sqrt ε * m := by  have hsq := Real.sq_sqrt hε  have hxyR : (x:ℝ) + y ≤ m*2 := by exact_mod_cast hxy  have hCR : (cC:ℝ) ≤ x*y := by exact_mod_cast hC  have hmxR : (m:ℝ) ≤ x := by exact_mod_cast hmx  push_cast at hcard  have hy : (0:ℝ) ≤ y := by positivity  have hx : (0:ℝ) ≤ x := by positivity  have h4 : (2 * Real.sqrt ε * m) ^ 2 = 4 * ε * m ^ 2 := by    calc (2 * Real.sqrt ε * m) ^ 2 = 4 * (Real.sqrt ε ^ 2) * m ^ 2 := by ring      _ = 4 * ε * m ^ 2 := by rw [hsq]  have hxy2 : (x:ℝ) * y ≤ x * (m * 2 - x) := by    apply mul_le_mul_of_nonneg_left _ hx    linarith  have hsq' : ((x:ℝ) - m) ^ 2 ≤ (2 * Real.sqrt ε * m) ^ 2 := by    rw [h4]; nlinarith  have hpos : 0 ≤ 2 * Real.sqrt ε * m := by positivity  nlinarithlemma in1286_upper (m : ℕ) (hm : 1 ≤ m) (ε : ℝ) (hε : 0 ≤ ε)    (C : Finset (Fin 2 → Fin (m*2)))    (hdis : ∀ u ∈ C, ∀ v ∈ C, u 0 ≠ v 1)    (hcard : (1/4 - ε) * ((m*2 : ℕ) : ℝ)^2 ≤ C.card) :    ∃ B : Finset (Fin 2 → Fin (m*2)), (∃ I : Finset (Fin (m*2)), 2 * I.card = m*2 ∧        (B = Finset.univ.filter (fun w => w 0 ∈ I ∧ w 1 ∉ I) ∨         B = Finset.univ.filter (fun w => w 0 ∉ I ∧ w 1 ∈ I))) ∧      ((symmDiff C B).card : ℝ) / ((m*2 : ℕ) : ℝ)^2 ≤ ε + Real.sqrt ε := by  classical  set S0 := C.image (fun w => w 0) with hS0  set S1 := C.image (fun w => w 1) with hS1  have hdisj : Disjoint S0 S1 := by    rw [Finset.disjoint_left]    intro x hx hx'    simp only [S0, S1, Finset.mem_image] at hx hx'    obtain ⟨u, hu, rfl⟩ := hx    obtain ⟨v, hv, hv'⟩ := hx'    exact hdis u hu v hv hv'.symm  have hab : S0.card + S1.card ≤ m*2 := by    rw [← Finset.card_union_of_disjoint hdisj]    simpa using Finset.card_le_univ (S0 ∪ S1)  have hCsub : C ⊆ Finset.univ.filter      (fun w : Fin 2 → Fin (m*2) => w 0 ∈ S0 ∧ w 1 ∈ S1) := by    intro w hw    simp only [Finset.mem_filter, Finset.mem_univ, true_and]    exact ⟨Finset.mem_image_of_mem _ hw, Finset.mem_image_of_mem _ hw⟩  have hCab : C.card ≤ S0.card * S1.card :=    (Finset.card_le_card hCsub).trans (in1286_card_prod S0 S1).le  have hs0 := Real.sqrt_nonneg ε  have hmR : (1:ℝ) ≤ m := by exact_mod_cast hm  have key : ∀ (B : Finset (Fin 2 → Fin (m*2))) (E : ℕ), B.card = m*m →      (C \ B).card ≤ E → (E : ℝ) ≤ 2 * Real.sqrt ε * m * m →      ((symmDiff C B).card : ℝ) / ((m*2 : ℕ) : ℝ)^2 ≤ ε + Real.sqrt ε := by    intro B E hB hE hER    have h1 := in1286_symm C B    have h2 := Finset.card_sdiff_add_card_inter C B    have h3 : (symmDiff C B).card + C.card = m*m + 2 * (C \ B).card := by omega    have h3' : ((symmDiff C B).card : ℝ) + C.card = m*m + 2 * (C \ B).card := by      exact_mod_cast h3    have hE' : ((C \ B).card : ℝ) ≤ E := by exact_mod_cast hE    rw [div_le_iff₀ (by positivity)]    push_cast at hcard ⊢    nlinarith  by_cases ha : m ≤ S0.card  · obtain ⟨I, hIS, hIc⟩ := Finset.exists_subset_card_eq ha    refine ⟨_, ⟨I, by omega, Or.inl rfl⟩, ?_⟩    apply key _ ((S0.card - m) * S1.card)    · rw [in1286_card_B1, hIc, show m * 2 - m = m by omega]    · refine (Finset.card_le_card (t := Finset.univ.filter          (fun w : Fin 2 → Fin (m*2) => w 0 ∈ S0 \ I ∧ w 1 ∈ S1)) ?_).trans        (by rw [in1286_card_prod, Finset.card_sdiff_of_subset hIS, hIc])      intro w hw      simp only [Finset.mem_sdiff, Finset.mem_filter, Finset.mem_univ, true_and, not_and,        not_not] at hw ⊢      obtain ⟨hwC, hwB⟩ := hw      have h0 : w 0 ∈ S0 := Finset.mem_image_of_mem _ hwC      have h1 : w 1 ∈ S1 := Finset.mem_image_of_mem _ hwC      have h1' : w 1 ∉ I := fun h => Finset.disjoint_left.1 hdisj (hIS h) h1      exact ⟨⟨h0, fun h => h1' (hwB h)⟩, h1⟩    · have hb : S1.card ≤ m := by omega      have hx := in1286_dev m ε hε C.card S0.card S1.card hab hCab ha hcard      rw [Nat.cast_mul, Nat.cast_sub ha]      have hbR : (S1.card : ℝ) ≤ m := by exact_mod_cast hb      have : (0:ℝ) ≤ S0.card - m := by        have : (m:ℝ) ≤ S0.card := by exact_mod_cast ha        linarith      calc ((S0.card:ℝ) - m) * S1.card ≤ (2 * Real.sqrt ε * m) * m :=            mul_le_mul hx hbR (by positivity) (by positivity)        _ = _ := by ring  by_cases hb : m ≤ S1.card  · obtain ⟨I, hIS, hIc⟩ := Finset.exists_subset_card_eq hb    refine ⟨_, ⟨I, by omega, Or.inr rfl⟩, ?_⟩    apply key _ (S0.card * (S1.card - m))    · rw [in1286_card_B2, hIc, show m * 2 - m = m by omega]    · refine (Finset.card_le_card (t := Finset.univ.filter          (fun w : Fin 2 → Fin (m*2) => w 0 ∈ S0 ∧ w 1 ∈ S1 \ I)) ?_).trans        (by rw [in1286_card_prod, Finset.card_sdiff_of_subset hIS, hIc])      intro w hw      simp only [Finset.mem_sdiff, Finset.mem_filter, Finset.mem_univ, true_and,        not_and] at hw ⊢      obtain ⟨hwC, hwB⟩ := hw      have h0 : w 0 ∈ S0 := Finset.mem_image_of_mem _ hwC      have h1 : w 1 ∈ S1 := Finset.mem_image_of_mem _ hwC      have h0' : w 0 ∉ I := fun h => Finset.disjoint_left.1 hdisj h0 (hIS h)      exact ⟨h0, h1, hwB h0'⟩    · have hx := in1286_dev m ε hε C.card S1.card S0.card (by omega)        (by rw [Nat.mul_comm S1.card S0.card]; exact hCab) hb hcard      rw [Nat.cast_mul, Nat.cast_sub hb]      have haR : (S0.card : ℝ) ≤ m := by        have : S0.card ≤ m := by omega        exact_mod_cast this      have : (0:ℝ) ≤ S1.card - m := by        have : (m:ℝ) ≤ S1.card := by exact_mod_cast hb        linarith      calc (S0.card:ℝ) * (S1.card - m) ≤ m * (2 * Real.sqrt ε * m) :=            mul_le_mul haR hx this (by positivity)        _ = _ := by ring  · have hsub : S0 ⊆ S1ᶜ := by      intro x hx      rw [Finset.mem_compl]      exact Finset.disjoint_left.1 hdisj hx    obtain ⟨I, hI0, hI1, hIc⟩ := Finset.exists_subsuperset_card_eq hsub (n := m)      (by omega) (by rw [Finset.card_compl, Fintype.card_fin]; omega)    refine ⟨_, ⟨I, by omega, Or.inl rfl⟩, ?_⟩    apply key _ 0    · rw [in1286_card_B1, hIc, show m * 2 - m = m by omega]    · apply le_of_eq      rw [Finset.card_eq_zero, Finset.sdiff_eq_empty_iff_subset]      intro w hw      simp only [Finset.mem_filter, Finset.mem_univ, true_and]      have h0 : w 0 ∈ S0 := Finset.mem_image_of_mem _ hw      have h1 : w 1 ∈ S1 := Finset.mem_image_of_mem _ hw      refine ⟨hI0 h0, fun h => ?_⟩      have := hI1 h      rw [Finset.mem_compl] at this      exact this h1    · push_cast      positivitytheorem op2468_blackburn_zero_deficit_n_two (m : ℕ) (hm : 1 ≤ m) :    let q : ℕ := m * 2    let lam : ℝ := (2 - 1 : ℝ) / 2    let c_n : ℝ := lam ^ (2 - 1) / (2 : ℝ)    let is_nonoverlapping (C : Finset (Fin 2 → Fin q)) : Prop :=      ∀ u ∈ C, ∀ v ∈ C, ¬ ∃ (k : ℕ) (_ : 0 < k) (_ : k < 2),        ∀ i : Fin k, u ⟨i.val, by omega⟩ = v ⟨2 - k + i.val, by omega⟩    let optimal_blackburn : Set (Finset (Fin 2 → Fin q)) :=      { B | ∃ (I : Finset (Fin q)), 2 * I.card = (2 - 1) * q ∧        (B = Finset.filter (fun w => (∀ (i : Fin 2), i.val < 2 - 1 → w i ∈ I) ∧          w ⟨2 - 1, by omega⟩ ∉ I) Finset.univ ∨         B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧          (∀ (i : Fin 2), 0 < i.val → w i ∈ I)) Finset.univ) }    let code_dist (C : Finset (Fin 2 → Fin q)) : ℝ :=      sInf { ((symmDiff C B).card : ℝ) / (q : ℝ) ^ 2 | B ∈ optimal_blackburn }    ∀ (C : Finset (Fin 2 → Fin q)), is_nonoverlapping C →      c_n * (q : ℝ) ^ 2 ≤ (C.card : ℝ) → code_dist C = 0 := by  intro q lam c_n is_nonoverlapping optimal_blackburn code_dist C hC hcard  have hc : c_n = 1 / 4 := by simp only [c_n, lam]; norm_num  have hdis : ∀ u ∈ C, ∀ v ∈ C, u 0 ≠ v 1 := by    intro u hu v hv he    apply hC u hu v hv    refine ⟨1, by norm_num, by norm_num, fun i => ?_⟩    fin_cases i    simpa using he  have hcard' : (1 / 4 - 0) * ((m * 2 : ℕ) : ℝ) ^ 2 ≤ C.card := by    rw [sub_zero, ← hc]; exact hcard  obtain ⟨B, ⟨I, hI, hB⟩, hle⟩ := in1286_upper m hm 0 le_rfl C hdis hcard'  have hB' : B ∈ optimal_blackburn := by    refine ⟨I, by simpa using hI, ?_⟩    rcases hB with rfl | rfl    · left      ext w      simp only [Finset.mem_filter, Finset.mem_univ, true_and]      constructor      · rintro ⟨h0, h1⟩        refine ⟨fun i hi => ?_, h1⟩        have : i = 0 := Fin.ext (by omega)        rw [this]; exact h0      · rintro ⟨h0, h1⟩        exact ⟨h0 0 (by norm_num), h1⟩    · right      ext w      simp only [Finset.mem_filter, Finset.mem_univ, true_and]      constructor      · rintro ⟨h0, h1⟩        refine ⟨h0, fun i hi => ?_⟩        have : i = 1 := Fin.ext (by omega)        rw [this]; exact h1      · rintro ⟨h0, h1⟩        exact ⟨h0, h1 1 (by norm_num)⟩  apply le_antisymm  · refine le_trans (csInf_le ⟨0, ?_⟩ ⟨B, hB', rfl⟩) ?_    · rintro _ ⟨B, -, rfl⟩      positivity    · have h0 : (0:ℝ) + Real.sqrt 0 = 0 := by simp      rw [h0] at hle      exact hle  · apply Real.sInf_nonneg    rintro _ ⟨B, -, rfl⟩    positivity
See it in the graphDiscuss this resultChallenge it