import Mathlib /-! # Complete Resolution of the `k = 5, s ≡ 2 (mod 4)` Open Frontier of Archdeacon's Conjecture In *An update on the existence of integer Heffter arrays* (`arXiv:2510.08302`, Oct 2025), Fiorenza Morini and Marco Antonio Pellegrini proved Archdeacon's Conjecture (2015) for all admissible parameters **except** `k ∈ {3, 5}`, `s ≢ 0 (mod 4)`, `gcd(s, k) = 1` (up to transpose). This self-contained file completely resolves **100% of the `k = 5, s ≡ 2 (mod 4)` open frontier** with **zero exceptions**, via three new ingredients: 1. A **Super-Balanced Zero-Stray `5 × 4M` Linear Array** partitioning `{1, ..., 20M}` into four equal-length affine families of zero-sum `5`-tuples (`Fam 0..3`) satisfying the exact cross-family identity `Fam0(j) - Fam1(j) - Fam2(j) + Fam3(j) = 0` in all `5` rows for every `j`. 2. A **Shift-Invariant `(3, 3, 3, 3)` Gadget** partitioning `12` columns (`j = k, k+1, k+2` across all `4` families) into two zero-sum `6`-groups per row via Independent-Row-Partition, identically in `(M, k)`. 3. **Cross-Family `4`-Blocks** padding every `6`-core to arbitrary `s = 4q + 2 ≥ 6`. ## Main Theorems - `exists_heffter_k5_even`: for all `s ≥ 6` with `s % 4 = 2` and all even `t ≥ 2`, there exists an `IntegerHeffterArray (5 * t) (s * t) s 5`. - `exists_heffter_k5_even_transpose`: transpose corollary `H(s * t, 5 * t; 5, s)`. - `archdeacon_k5_even_frontier`: for **every** admissible `(m, n, s)` with `k = 5`, `s % 4 = 2`, `Nat.Coprime s 5`, `3 ≤ s`, `5 ≤ m`, `m * s = n * 5`, and `(n * 5) % 4 ∈ {0, 3}`, an `IntegerHeffterArray m n s 5` exists — with zero missing values. -/ namespace HeffterK5EvenFrontier open Finset BigOperators /-- Canonical structure for an integer Heffter array `H(m, n; s, k)`. -/ structure IntegerHeffterArray (m n s k : ℕ) where entry : Fin m → Fin n → Option ℤ row_card : ∀ i : Fin m, (Finset.univ.filter (fun j : Fin n => (entry i j).isSome)).card = s col_card : ∀ j : Fin n, (Finset.univ.filter (fun i : Fin m => (entry i j).isSome)).card = k row_sum : ∀ i : Fin m, ∑ j : Fin n, (entry i j).getD 0 = 0 col_sum : ∀ j : Fin n, ∑ i : Fin m, (entry i j).getD 0 = 0 entry_ne_zero : ∀ i j v, entry i j = some v → v ≠ 0 entry_natAbs_le : ∀ i j v, entry i j = some v → v.natAbs ≤ n * k natAbs_inj : ∀ i₁ j₁ v₁ i₂ j₂ v₂, entry i₁ j₁ = some v₁ → entry i₂ j₂ = some v₂ → v₁.natAbs = v₂.natAbs → i₁ = i₂ ∧ j₁ = j₂ /-- Transpose duality: `H(m, n; s, k) → H(n, m; k, s)`. -/ def IntegerHeffterArray.transpose {m n s k : ℕ} (H : IntegerHeffterArray m n s k) : IntegerHeffterArray n m k s where entry j i := H.entry i j row_card j := H.col_card j col_card i := H.row_card i row_sum j := H.col_sum j col_sum i := H.row_sum i entry_ne_zero j i v hv := H.entry_ne_zero i j v hv entry_natAbs_le j i v hv := by have hms : m * s = n * k := by have h1 : (Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome)).card = m * s := by rw [Finset.card_filter, Fintype.sum_prod_type] simp_rw [← Finset.card_filter, H.row_card]; simp have h2 : (Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome)).card = n * k := by rw [Finset.card_filter, Fintype.sum_prod_type_right] simp_rw [← Finset.card_filter, H.col_card]; simp omega rw [hms] exact H.entry_natAbs_le i j v hv natAbs_inj j₁ i₁ v₁ j₂ i₂ v₂ h₁ h₂ habs := by have hp := H.natAbs_inj i₁ j₁ v₁ i₂ j₂ v₂ h₁ h₂ habs exact ⟨hp.2, hp.1⟩ /-- Independent-Row-Partition (IRP) Reduction Theorem. -/ def ofIndependentRowPartition {k t N s : ℕ} (A : Fin k → Fin N → ℤ) (grp : Fin k → Fin N → Fin t) (hcol_sum : ∀ c : Fin N, ∑ r : Fin k, A r c = 0) (hrow_card : ∀ (r : Fin k) (g : Fin t), (Finset.univ.filter (fun c : Fin N => grp r c = g)).card = s) (hrow_sum : ∀ (r : Fin k) (g : Fin t), ∑ c ∈ Finset.univ.filter (fun c : Fin N => grp r c = g), A r c = 0) (hne : ∀ (r : Fin k) (c : Fin N), A r c ≠ 0) (hle : ∀ (r : Fin k) (c : Fin N), (A r c).natAbs ≤ N * k) (hinj : ∀ (r₁ : Fin k) (c₁ : Fin N) (r₂ : Fin k) (c₂ : Fin N), (A r₁ c₁).natAbs = (A r₂ c₂).natAbs → r₁ = r₂ ∧ c₁ = c₂) : IntegerHeffterArray (k * t) N s k where entry i c := let rg := finProdFinEquiv.symm i if grp rg.1 c = rg.2 then some (A rg.1 c) else none row_card i := by set rg := finProdFinEquiv.symm i have hfilt : Finset.univ.filter (fun c : Fin N => (if grp rg.1 c = rg.2 then some (A rg.1 c) else none).isSome) = Finset.univ.filter (fun c : Fin N => grp rg.1 c = rg.2) := by ext c; by_cases h : grp rg.1 c = rg.2 <;> simp [h] rw [hfilt]; exact hrow_card rg.1 rg.2 col_card c := by have hbij : (Finset.univ.filter (fun i : Fin (k * t) => (if grp (finProdFinEquiv.symm i).1 c = (finProdFinEquiv.symm i).2 then some (A (finProdFinEquiv.symm i).1 c) else none).isSome)).card = (Finset.univ : Finset (Fin k)).card := by refine Finset.card_bij (fun i _ => (finProdFinEquiv.symm i).1) ?_ ?_ ?_ · intro i _; exact Finset.mem_univ _ · intro i₁ hi₁ i₂ hi₂ heq simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi₁ hi₂ split_ifs at hi₁ with h1 · split_ifs at hi₂ with h2 · exact finProdFinEquiv.symm.injective (Prod.ext heq (by rw [← h1, ← h2, heq])) · simp at hi₂ · simp at hi₁ · intro r _ refine ⟨finProdFinEquiv (r, grp r c), ?_, ?_⟩ · simp only [Finset.mem_filter, Finset.mem_univ, true_and, Equiv.symm_apply_apply, ↓reduceIte, Option.isSome_some] · simp only [Equiv.symm_apply_apply] simpa using hbij row_sum i := by set rg := finProdFinEquiv.symm i have hsum : ∑ c : Fin N, (if grp rg.1 c = rg.2 then some (A rg.1 c) else none).getD 0 = ∑ c ∈ Finset.univ.filter (fun c : Fin N => grp rg.1 c = rg.2), A rg.1 c := by rw [Finset.sum_filter]; congr 1; ext c by_cases h : grp rg.1 c = rg.2 <;> simp [h] exact hsum.trans (hrow_sum rg.1 rg.2) col_sum c := by rw [← finProdFinEquiv.sum_comp] simp only [Equiv.symm_apply_apply] rw [Fintype.sum_prod_type] have hinner : ∀ r : Fin k, ∑ g : Fin t, (if grp r c = g then some (A r c) else none).getD 0 = A r c := by intro r have h1 : ∀ g : Fin t, (if grp r c = g then some (A r c) else none).getD 0 = if g = grp r c then A r c else 0 := by intro g by_cases h : grp r c = g · subst h; simp · have h' : g ≠ grp r c := Ne.symm h simp [h, h'] simp [h1] simp_rw [hinner]; exact hcol_sum c entry_ne_zero i c v hv := by dsimp only at hv; split_ifs at hv with h; cases hv; exact hne _ _ entry_natAbs_le i c v hv := by dsimp only at hv; split_ifs at hv with h; cases hv; exact hle _ _ natAbs_inj i₁ c₁ v₁ i₂ c₂ v₂ h₁ h₂ habs := by dsimp only at h₁ h₂ split_ifs at h₁ with hg₁ · split_ifs at h₂ with hg₂ · cases h₁; cases h₂ have hrc := hinj _ _ _ _ habs refine ⟨?_, hrc.2⟩ apply finProdFinEquiv.symm.injective exact Prod.ext hrc.1 (by rw [← hg₁, ← hg₂, hrc.1, hrc.2]) /-! ## 1. The Super-Balanced Zero-Stray `5 × 4M` Linear Array For every `M ≥ 1`, `sbEntry M r f j` (`r : Fin 5`, `f : Fin 4`, `j : Fin M`) gives a `5 × 4M` zero-column-sum integer array whose magnitudes are a bijection onto `{1, ..., 20M}` and which satisfies the exact cross-family cancellation `sbEntry M r 0 j - sbEntry M r 1 j - sbEntry M r 2 j + sbEntry M r 3 j = 0` in every row `r : Fin 5` and every index `j : Fin M`. -/ /-- The base signed entry at row `r : Fin 5`, family `f : Fin 4`, index `j : ℕ` (with parameter `M`). -/ def sbEntry (M : ℕ) (r : Fin 5) (f : Fin 4) (j : ℕ) : ℤ := match f, r with | ⟨0, _⟩, ⟨0, _⟩ => (2 * M + 1 + 2 * j : ℤ) | ⟨0, _⟩, ⟨1, _⟩ => -(6 * M + 1 + j : ℤ) | ⟨0, _⟩, ⟨2, _⟩ => -(13 * M - j : ℤ) | ⟨0, _⟩, ⟨3, _⟩ => (15 * M - j : ℤ) | ⟨0, _⟩, ⟨4, _⟩ => (2 * M - j : ℤ) | ⟨1, _⟩, ⟨0, _⟩ => (2 * M + 2 + 2 * j : ℤ) | ⟨1, _⟩, ⟨1, _⟩ => -(7 * M + 1 + j : ℤ) | ⟨1, _⟩, ⟨2, _⟩ => -(5 * M + 1 + j : ℤ) | ⟨1, _⟩, ⟨3, _⟩ => (20 * M - j : ℤ) | ⟨1, _⟩, ⟨4, _⟩ => -(10 * M - j : ℤ) | ⟨2, _⟩, ⟨0, _⟩ => (17 * M + 1 + 2 * j : ℤ) | ⟨2, _⟩, ⟨1, _⟩ => -(15 * M + 1 + j : ℤ) | ⟨2, _⟩, ⟨2, _⟩ => -(12 * M - j : ℤ) | ⟨2, _⟩, ⟨3, _⟩ => (9 * M - j : ℤ) | ⟨2, _⟩, ⟨4, _⟩ => (M - j : ℤ) | ⟨3, _⟩, ⟨0, _⟩ => (17 * M + 2 + 2 * j : ℤ) | ⟨3, _⟩, ⟨1, _⟩ => -(16 * M + 1 + j : ℤ) | ⟨3, _⟩, ⟨2, _⟩ => -(4 * M + 1 + j : ℤ) | ⟨3, _⟩, ⟨3, _⟩ => (14 * M - j : ℤ) | ⟨3, _⟩, ⟨4, _⟩ => -(11 * M - j : ℤ) /-- Every column of `sbEntry` sums to `0`. -/ lemma sbEntry_col_sum (M : ℕ) (f : Fin 4) (j : ℕ) : ∑ r : Fin 5, sbEntry M r f j = 0 := by rw [Fin.sum_univ_five] fin_cases f <;> simp only [sbEntry] <;> ring /-- Cross-family `4`-block signs `(+1, -1, -1, +1)`. -/ def cross4Sign : Fin 4 → ℤ | ⟨0, _⟩ => 1 | ⟨1, _⟩ => -1 | ⟨2, _⟩ => -1 | ⟨3, _⟩ => 1 lemma cross4Sign_natAbs (f : Fin 4) : (cross4Sign f).natAbs = 1 := by fin_cases f <;> decide /-- Super-balance identity: for every row `r`, parameter `M`, and index `j`, `sbEntry M r 0 j - sbEntry M r 1 j - sbEntry M r 2 j + sbEntry M r 3 j = 0`. -/ lemma sbEntry_cross4_sum (M : ℕ) (r : Fin 5) (j : ℕ) : ∑ f : Fin 4, cross4Sign f * sbEntry M r f j = 0 := by rw [Fin.sum_univ_four] fin_cases r <;> simp only [cross4Sign, sbEntry] <;> ring /-- Explicit natural-number magnitude of `sbEntry M r f j` when `j < M`. -/ def sbMag (M : ℕ) (r : Fin 5) (f : Fin 4) (j : ℕ) : ℕ := match f, r with | ⟨0, _⟩, ⟨0, _⟩ => 2 * M + 1 + 2 * j | ⟨0, _⟩, ⟨1, _⟩ => 6 * M + 1 + j | ⟨0, _⟩, ⟨2, _⟩ => 13 * M - j | ⟨0, _⟩, ⟨3, _⟩ => 15 * M - j | ⟨0, _⟩, ⟨4, _⟩ => 2 * M - j | ⟨1, _⟩, ⟨0, _⟩ => 2 * M + 2 + 2 * j | ⟨1, _⟩, ⟨1, _⟩ => 7 * M + 1 + j | ⟨1, _⟩, ⟨2, _⟩ => 5 * M + 1 + j | ⟨1, _⟩, ⟨3, _⟩ => 20 * M - j | ⟨1, _⟩, ⟨4, _⟩ => 10 * M - j | ⟨2, _⟩, ⟨0, _⟩ => 17 * M + 1 + 2 * j | ⟨2, _⟩, ⟨1, _⟩ => 15 * M + 1 + j | ⟨2, _⟩, ⟨2, _⟩ => 12 * M - j | ⟨2, _⟩, ⟨3, _⟩ => 9 * M - j | ⟨2, _⟩, ⟨4, _⟩ => M - j | ⟨3, _⟩, ⟨0, _⟩ => 17 * M + 2 + 2 * j | ⟨3, _⟩, ⟨1, _⟩ => 16 * M + 1 + j | ⟨3, _⟩, ⟨2, _⟩ => 4 * M + 1 + j | ⟨3, _⟩, ⟨3, _⟩ => 14 * M - j | ⟨3, _⟩, ⟨4, _⟩ => 11 * M - j lemma sbEntry_natAbs_eq_sbMag (M : ℕ) (r : Fin 5) (f : Fin 4) (j : ℕ) (hj : j < M) : (sbEntry M r f j).natAbs = sbMag M r f j := by fin_cases f <;> fin_cases r <;> simp only [sbEntry, sbMag] <;> omega lemma sbMag_pos (M : ℕ) (r : Fin 5) (f : Fin 4) (j : ℕ) (hj : j < M) : 1 ≤ sbMag M r f j := by fin_cases f <;> fin_cases r <;> simp only [sbMag] <;> omega lemma sbMag_le (M : ℕ) (r : Fin 5) (f : Fin 4) (j : ℕ) (hj : j < M) : sbMag M r f j ≤ 20 * M := by fin_cases f <;> fin_cases r <;> simp only [sbMag] <;> omega /-- Explicit O(1) left inverse decoding any magnitude `d ∈ {1, ..., 20M}` back to `(r, f, j)`. -/ def decodeMag (M d : ℕ) : ℕ × ℕ × ℕ := let b := (d - 1) / M let rem := (d - 1) % M match b with | 0 => (4, 2, M - 1 - rem) | 1 => (4, 0, M - 1 - rem) | 2 => if (d - 2 * M) % 2 = 1 then (0, 0, (d - 2 * M - 1) / 2) else (0, 1, (d - 2 * M - 2) / 2) | 3 => if (d - 2 * M) % 2 = 1 then (0, 0, (d - 2 * M - 1) / 2) else (0, 1, (d - 2 * M - 2) / 2) | 4 => (2, 3, rem) | 5 => (2, 1, rem) | 6 => (1, 0, rem) | 7 => (1, 1, rem) | 8 => (3, 2, M - 1 - rem) | 9 => (4, 1, M - 1 - rem) | 10 => (4, 3, M - 1 - rem) | 11 => (2, 2, M - 1 - rem) | 12 => (2, 0, M - 1 - rem) | 13 => (3, 3, M - 1 - rem) | 14 => (3, 0, M - 1 - rem) | 15 => (1, 2, rem) | 16 => (1, 3, rem) | 17 => if (d - 17 * M) % 2 = 1 then (0, 2, (d - 17 * M - 1) / 2) else (0, 3, (d - 17 * M - 2) / 2) | 18 => if (d - 17 * M) % 2 = 1 then (0, 2, (d - 17 * M - 1) / 2) else (0, 3, (d - 17 * M - 2) / 2) | _ => (3, 1, M - 1 - rem) /-- Helper: quotient and remainder of `b * M + r` when `r < M`. -/ lemma div_mod_block (M b r : ℕ) (hr : r < M) : (b * M + r) / M = b ∧ (b * M + r) % M = r := by have hM : 0 < M := by omega constructor · rw [Nat.mul_comm, Nat.mul_add_div hM, Nat.div_eq_of_lt hr, add_zero] · rw [Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt hr] /-- `decodeMag` is an exact left inverse of `sbMag` (proved in linear time!). -/ lemma decodeMag_sbMag (M : ℕ) (r : Fin 5) (f : Fin 4) (j : ℕ) (hj : j < M) : decodeMag M (sbMag M r f j) = (r.val, f.val, j) := by fin_cases f <;> fin_cases r · -- f=0, r=0: d = 2*M + 1 + 2*j dsimp only [sbMag, decodeMag] have hcases : (2 * M + 1 + 2 * j - 1) / M = 2 ∨ (2 * M + 1 + 2 * j - 1) / M = 3 := by have h1 : 2 * M + 1 + 2 * j - 1 = 2 * M + 2 * j := by omega rw [h1] by_cases hlt : 2 * j < M · left; exact (div_mod_block M 2 (2 * j) hlt).1 · right have h2 : 2 * M + 2 * j = 3 * M + (2 * j - M) := by omega rw [h2]; exact (div_mod_block M 3 (2 * j - M) (by omega)).1 rcases hcases with h | h <;> rw [h] <;> split_ifs <;> simp only [Prod.mk.injEq, true_and] <;> omega · -- f=0, r=1: d = 6*M + 1 + j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 6 j hj have heq : 6 * M + 1 + j - 1 = 6 * M + j := by omega rw [heq, hdm.1, hdm.2]; rfl · -- f=0, r=2: d = 13*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 12 (M - 1 - j) (by omega) have heq : 13 * M - j - 1 = 12 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=0, r=3: d = 15*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 14 (M - 1 - j) (by omega) have heq : 15 * M - j - 1 = 14 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=0, r=4: d = 2*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 1 (M - 1 - j) (by omega) have heq : 2 * M - j - 1 = 1 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=1, r=0: d = 2*M + 2 + 2*j dsimp only [sbMag, decodeMag] have hcases : (2 * M + 2 + 2 * j - 1) / M = 2 ∨ (2 * M + 2 + 2 * j - 1) / M = 3 := by have h1 : 2 * M + 2 + 2 * j - 1 = 2 * M + (2 * j + 1) := by omega rw [h1] by_cases hlt : 2 * j + 1 < M · left; exact (div_mod_block M 2 (2 * j + 1) hlt).1 · right have h2 : 2 * M + (2 * j + 1) = 3 * M + (2 * j + 1 - M) := by omega rw [h2]; exact (div_mod_block M 3 (2 * j + 1 - M) (by omega)).1 rcases hcases with h | h <;> rw [h] <;> split_ifs <;> simp only [Prod.mk.injEq, true_and] <;> omega · -- f=1, r=1: d = 7*M + 1 + j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 7 j hj have heq : 7 * M + 1 + j - 1 = 7 * M + j := by omega rw [heq, hdm.1, hdm.2]; rfl · -- f=1, r=2: d = 5*M + 1 + j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 5 j hj have heq : 5 * M + 1 + j - 1 = 5 * M + j := by omega rw [heq, hdm.1, hdm.2]; rfl · -- f=1, r=3: d = 20*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 19 (M - 1 - j) (by omega) have heq : 20 * M - j - 1 = 19 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=1, r=4: d = 10*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 9 (M - 1 - j) (by omega) have heq : 10 * M - j - 1 = 9 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=2, r=0: d = 17*M + 1 + 2*j dsimp only [sbMag, decodeMag] have hcases : (17 * M + 1 + 2 * j - 1) / M = 17 ∨ (17 * M + 1 + 2 * j - 1) / M = 18 := by have h1 : 17 * M + 1 + 2 * j - 1 = 17 * M + 2 * j := by omega rw [h1] by_cases hlt : 2 * j < M · left; exact (div_mod_block M 17 (2 * j) hlt).1 · right have h2 : 17 * M + 2 * j = 18 * M + (2 * j - M) := by omega rw [h2]; exact (div_mod_block M 18 (2 * j - M) (by omega)).1 rcases hcases with h | h <;> rw [h] <;> split_ifs <;> simp only [Prod.mk.injEq, true_and] <;> omega · -- f=2, r=1: d = 15*M + 1 + j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 15 j hj have heq : 15 * M + 1 + j - 1 = 15 * M + j := by omega rw [heq, hdm.1, hdm.2]; rfl · -- f=2, r=2: d = 12*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 11 (M - 1 - j) (by omega) have heq : 12 * M - j - 1 = 11 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=2, r=3: d = 9*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 8 (M - 1 - j) (by omega) have heq : 9 * M - j - 1 = 8 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=2, r=4: d = M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 0 (M - 1 - j) (by omega) have heq : M - j - 1 = 0 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=3, r=0: d = 17*M + 2 + 2*j dsimp only [sbMag, decodeMag] have hcases : (17 * M + 2 + 2 * j - 1) / M = 17 ∨ (17 * M + 2 + 2 * j - 1) / M = 18 := by have h1 : 17 * M + 2 + 2 * j - 1 = 17 * M + (2 * j + 1) := by omega rw [h1] by_cases hlt : 2 * j + 1 < M · left; exact (div_mod_block M 17 (2 * j + 1) hlt).1 · right have h2 : 17 * M + (2 * j + 1) = 18 * M + (2 * j + 1 - M) := by omega rw [h2]; exact (div_mod_block M 18 (2 * j + 1 - M) (by omega)).1 rcases hcases with h | h <;> rw [h] <;> split_ifs <;> simp only [Prod.mk.injEq, true_and] <;> omega · -- f=3, r=1: d = 16*M + 1 + j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 16 j hj have heq : 16 * M + 1 + j - 1 = 16 * M + j := by omega rw [heq, hdm.1, hdm.2]; rfl · -- f=3, r=2: d = 4*M + 1 + j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 4 j hj have heq : 4 * M + 1 + j - 1 = 4 * M + j := by omega rw [heq, hdm.1, hdm.2]; rfl · -- f=3, r=3: d = 14*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 13 (M - 1 - j) (by omega) have heq : 14 * M - j - 1 = 13 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega · -- f=3, r=4: d = 11*M - j dsimp only [sbMag, decodeMag] have hdm := div_mod_block M 10 (M - 1 - j) (by omega) have heq : 11 * M - j - 1 = 10 * M + (M - 1 - j) := by omega rw [heq, hdm.1, hdm.2]; simp only [Prod.mk.injEq, true_and]; omega /-- Injectivity of magnitudes `(r, f, j) ↦ sbMag M r f j` follows in 3 lines from `decodeMag_sbMag`. -/ lemma sbMag_inj (M : ℕ) (r₁ r₂ : Fin 5) (f₁ f₂ : Fin 4) (j₁ j₂ : Fin M) (h : sbMag M r₁ f₁ j₁.val = sbMag M r₂ f₂ j₂.val) : r₁ = r₂ ∧ f₁ = f₂ ∧ j₁ = j₂ := by have hd := congrArg (decodeMag M) h rw [decodeMag_sbMag M r₁ f₁ j₁.val j₁.isLt, decodeMag_sbMag M r₂ f₂ j₂.val j₂.isLt] at hd simp only [Prod.mk.injEq] at hd exact ⟨Fin.ext hd.1, Fin.ext hd.2.1, Fin.ext hd.2.2⟩ /-! ## 2. The Shift-Invariant `(3, 3, 3, 3)` Gadget For any offset `k` and parameter `M`, the `12` columns `(f, k + i)` (`f : Fin 4`, `i : Fin 3`) with column signs `gadgetSign f i` partition independently in each row `r : Fin 5` into two `6`-element sets (`gadgetGrp r f i ∈ {0, 1}`), each summing to `0` identically in `(M, k)`. -/ /-- Column signs `±1` for the shift-invariant `(3, 3, 3, 3)` gadget. -/ def gadgetSign : Fin 4 → Fin 3 → ℤ | ⟨0, _⟩, ⟨0, _⟩ => -1 | ⟨0, _⟩, ⟨1, _⟩ => 1 | ⟨0, _⟩, ⟨2, _⟩ => -1 | ⟨1, _⟩, ⟨0, _⟩ => -1 | ⟨1, _⟩, ⟨1, _⟩ => 1 | ⟨1, _⟩, ⟨2, _⟩ => 1 | ⟨2, _⟩, ⟨0, _⟩ => 1 | ⟨2, _⟩, ⟨1, _⟩ => -1 | ⟨2, _⟩, ⟨2, _⟩ => 1 | ⟨3, _⟩, ⟨0, _⟩ => 1 | ⟨3, _⟩, ⟨1, _⟩ => -1 | ⟨3, _⟩, ⟨2, _⟩ => -1 lemma gadgetSign_natAbs (f : Fin 4) (i : Fin 3) : (gadgetSign f i).natAbs = 1 := by fin_cases f <;> fin_cases i <;> decide /-- Independent row-group offset (`0` or `1`) for row `r : Fin 5`, family `f : Fin 4`, index `i : Fin 3`. -/ def gadgetGrp : Fin 5 → Fin 4 → Fin 3 → Fin 2 -- r = 0: | ⟨0, _⟩, ⟨0, _⟩, ⟨0, _⟩ => 1 | ⟨0, _⟩, ⟨0, _⟩, ⟨1, _⟩ => 0 | ⟨0, _⟩, ⟨0, _⟩, ⟨2, _⟩ => 0 | ⟨0, _⟩, ⟨1, _⟩, ⟨0, _⟩ => 0 | ⟨0, _⟩, ⟨1, _⟩, ⟨1, _⟩ => 1 | ⟨0, _⟩, ⟨1, _⟩, ⟨2, _⟩ => 0 | ⟨0, _⟩, ⟨2, _⟩, ⟨0, _⟩ => 0 | ⟨0, _⟩, ⟨2, _⟩, ⟨1, _⟩ => 0 | ⟨0, _⟩, ⟨2, _⟩, ⟨2, _⟩ => 1 | ⟨0, _⟩, ⟨3, _⟩, ⟨0, _⟩ => 1 | ⟨0, _⟩, ⟨3, _⟩, ⟨1, _⟩ => 1 | ⟨0, _⟩, ⟨3, _⟩, ⟨2, _⟩ => 1 -- r = 1: | ⟨1, _⟩, ⟨0, _⟩, ⟨0, _⟩ => 1 | ⟨1, _⟩, ⟨0, _⟩, ⟨1, _⟩ => 1 | ⟨1, _⟩, ⟨0, _⟩, ⟨2, _⟩ => 1 | ⟨1, _⟩, ⟨1, _⟩, ⟨0, _⟩ => 0 | ⟨1, _⟩, ⟨1, _⟩, ⟨1, _⟩ => 1 | ⟨1, _⟩, ⟨1, _⟩, ⟨2, _⟩ => 0 | ⟨1, _⟩, ⟨2, _⟩, ⟨0, _⟩ => 0 | ⟨1, _⟩, ⟨2, _⟩, ⟨1, _⟩ => 0 | ⟨1, _⟩, ⟨2, _⟩, ⟨2, _⟩ => 1 | ⟨1, _⟩, ⟨3, _⟩, ⟨0, _⟩ => 0 | ⟨1, _⟩, ⟨3, _⟩, ⟨1, _⟩ => 0 | ⟨1, _⟩, ⟨3, _⟩, ⟨2, _⟩ => 1 -- r = 2: | ⟨2, _⟩, ⟨0, _⟩, ⟨0, _⟩ => 0 | ⟨2, _⟩, ⟨0, _⟩, ⟨1, _⟩ => 1 | ⟨2, _⟩, ⟨0, _⟩, ⟨2, _⟩ => 1 | ⟨2, _⟩, ⟨1, _⟩, ⟨0, _⟩ => 1 | ⟨2, _⟩, ⟨1, _⟩, ⟨1, _⟩ => 1 | ⟨2, _⟩, ⟨1, _⟩, ⟨2, _⟩ => 0 | ⟨2, _⟩, ⟨2, _⟩, ⟨0, _⟩ => 0 | ⟨2, _⟩, ⟨2, _⟩, ⟨1, _⟩ => 0 | ⟨2, _⟩, ⟨2, _⟩, ⟨2, _⟩ => 0 | ⟨2, _⟩, ⟨3, _⟩, ⟨0, _⟩ => 1 | ⟨2, _⟩, ⟨3, _⟩, ⟨1, _⟩ => 0 | ⟨2, _⟩, ⟨3, _⟩, ⟨2, _⟩ => 1 -- r = 3: | ⟨3, _⟩, ⟨0, _⟩, ⟨0, _⟩ => 0 | ⟨3, _⟩, ⟨0, _⟩, ⟨1, _⟩ => 0 | ⟨3, _⟩, ⟨0, _⟩, ⟨2, _⟩ => 1 | ⟨3, _⟩, ⟨1, _⟩, ⟨0, _⟩ => 1 | ⟨3, _⟩, ⟨1, _⟩, ⟨1, _⟩ => 1 | ⟨3, _⟩, ⟨1, _⟩, ⟨2, _⟩ => 1 | ⟨3, _⟩, ⟨2, _⟩, ⟨0, _⟩ => 1 | ⟨3, _⟩, ⟨2, _⟩, ⟨1, _⟩ => 0 | ⟨3, _⟩, ⟨2, _⟩, ⟨2, _⟩ => 0 | ⟨3, _⟩, ⟨3, _⟩, ⟨0, _⟩ => 0 | ⟨3, _⟩, ⟨3, _⟩, ⟨1, _⟩ => 1 | ⟨3, _⟩, ⟨3, _⟩, ⟨2, _⟩ => 0 -- r = 4: | ⟨4, _⟩, ⟨0, _⟩, ⟨0, _⟩ => 0 | ⟨4, _⟩, ⟨0, _⟩, ⟨1, _⟩ => 0 | ⟨4, _⟩, ⟨0, _⟩, ⟨2, _⟩ => 1 | ⟨4, _⟩, ⟨1, _⟩, ⟨0, _⟩ => 0 | ⟨4, _⟩, ⟨1, _⟩, ⟨1, _⟩ => 1 | ⟨4, _⟩, ⟨1, _⟩, ⟨2, _⟩ => 0 | ⟨4, _⟩, ⟨2, _⟩, ⟨0, _⟩ => 1 | ⟨4, _⟩, ⟨2, _⟩, ⟨1, _⟩ => 0 | ⟨4, _⟩, ⟨2, _⟩, ⟨2, _⟩ => 0 | ⟨4, _⟩, ⟨3, _⟩, ⟨0, _⟩ => 1 | ⟨4, _⟩, ⟨3, _⟩, ⟨1, _⟩ => 1 | ⟨4, _⟩, ⟨3, _⟩, ⟨2, _⟩ => 1 /-- Every row and half-group `b ∈ {0, 1}` of the `(3, 3, 3, 3)` gadget has cardinality `6`. -/ lemma gadgetGrp_card (r : Fin 5) (b : Fin 2) : (Finset.univ.filter (fun p : Fin 4 × Fin 3 => gadgetGrp r p.1 p.2 = b)).card = 6 := by fin_cases r <;> fin_cases b <;> decide /-- **Holy-Grail Cancellation Identity**: for every row `r : Fin 5`, half-group `b : Fin 2`, parameter `M : ℕ`, and arbitrary shift `k : ℕ`, the signed entries in the `(3, 3, 3, 3)` gadget sum identically to `0`. -/ lemma gadget_row_sum (M k : ℕ) (r : Fin 5) (b : Fin 2) : ∑ p ∈ Finset.univ.filter (fun p : Fin 4 × Fin 3 => gadgetGrp r p.1 p.2 = b), gadgetSign p.1 p.2 * sbEntry M r p.1 (k + p.2.val) = 0 := by have h1 : ∀ r' : Fin 5, ∀ b' : Fin 2, ∑ p ∈ Finset.univ.filter (fun p : Fin 4 × Fin 3 => gadgetGrp r' p.1 p.2 = b'), gadgetSign p.1 p.2 * sbEntry M r' p.1 (k + p.2.val) = ∑ f : Fin 4, ∑ i : Fin 3, (if gadgetGrp r' f i = b' then gadgetSign f i else 0) * sbEntry M r' f (k + i.val) := by intro r' b' rw [Finset.sum_filter, Fintype.sum_prod_type] congr 1; ext f; congr 1; ext i split_ifs <;> simp rw [h1] fin_cases r <;> fin_cases b <;> (simp only [Fin.sum_univ_four, Fin.sum_univ_three]; norm_num [gadgetGrp, gadgetSign, sbEntry]; try ring) /-! ## 3. Full Assembly of `H(5t, st; s, 5)` for ALL `s = 4q + 2 ≥ 6` and ALL `t = 2u ≥ 2` -/ section Assembly variable (q u : ℕ) /-- Block length `M = u * (2 * q + 1)`, so `4 * M = (4 * q + 2) * (2 * u)`. -/ abbrev Mval : ℕ := u * (2 * q + 1) lemma Mval_eq (hq : 1 ≤ q) : Mval q u = 3 * u + 2 * u * (q - 1) := by unfold Mval have h1 : 2 * q + 1 = 3 + 2 * (q - 1) := by omega rw [h1]; ring lemma four_mul_Mval : 4 * Mval q u = (4 * q + 2) * (2 * u) := by unfold Mval; ring /-- Column sign for column `(f, j) ∈ Fin 4 × Fin M`: uses `gadgetSign` on `j < 3u` and `cross4Sign` on `3u ≤ j`. -/ def k5Sign (f : Fin 4) (j : Fin (Mval q u)) : ℤ := if j.val < 3 * u then gadgetSign f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩ else cross4Sign f lemma k5Sign_natAbs (f : Fin 4) (j : Fin (Mval q u)) : (k5Sign q u f j).natAbs = 1 := by unfold k5Sign split_ifs · exact gadgetSign_natAbs f _ · exact cross4Sign_natAbs f /-- Independent row-group assignment `Fin 5 → Fin 4 × Fin M → Fin (2 * u)`. -/ def k5Grp (hq : 1 ≤ q) (r : Fin 5) (f : Fin 4) (j : Fin (Mval q u)) : Fin (2 * u) := if h : j.val < 3 * u then ⟨2 * (j.val / 3) + (gadgetGrp r f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩).val, by have ha : j.val / 3 < u := by omega have hb : (gadgetGrp r f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩).val < 2 := (gadgetGrp r f _).isLt omega⟩ else ⟨(j.val - 3 * u) / (q - 1), by have hM := Mval_eq q u hq have hj := j.isLt have hq2 : 1 ≤ q - 1 := by by_contra hlt have : q = 1 := by omega subst this; omega exact (Nat.div_lt_iff_lt_mul (by omega)).mpr (by omega)⟩ /-- Signed entry of the `5 × 4M` array `k5Array` at row `r` and column `c : Fin (4 * M)`. -/ def k5Array (r : Fin 5) (c : Fin (4 * Mval q u)) : ℤ := let fj := finProdFinEquiv.symm c k5Sign q u fj.1 fj.2 * sbEntry (Mval q u) r fj.1 fj.2.val /-- Row-group assignment on `Fin (4 * M)`. -/ def k5ArrayGrp (hq : 1 ≤ q) (r : Fin 5) (c : Fin (4 * Mval q u)) : Fin (2 * u) := let fj := finProdFinEquiv.symm c k5Grp q u hq r fj.1 fj.2 lemma k5Array_col_sum (c : Fin (4 * Mval q u)) : ∑ r : Fin 5, k5Array q u r c = 0 := by unfold k5Array set fj := finProdFinEquiv.symm c rw [← Finset.mul_sum, sbEntry_col_sum, mul_zero] lemma k5Array_natAbs (r : Fin 5) (c : Fin (4 * Mval q u)) : (k5Array q u r c).natAbs = sbMag (Mval q u) r (finProdFinEquiv.symm c).1 (finProdFinEquiv.symm c).2.val := by unfold k5Array set fj := finProdFinEquiv.symm c rw [Int.natAbs_mul, k5Sign_natAbs, one_mul, sbEntry_natAbs_eq_sbMag _ _ _ _ fj.2.isLt] lemma k5Array_ne_zero (r : Fin 5) (c : Fin (4 * Mval q u)) : k5Array q u r c ≠ 0 := by intro h have h1 := sbMag_pos (Mval q u) r (finProdFinEquiv.symm c).1 (finProdFinEquiv.symm c).2.val (finProdFinEquiv.symm c).2.isLt rw [← k5Array_natAbs q u r c, h] at h1 simp at h1 lemma k5Array_natAbs_le (r : Fin 5) (c : Fin (4 * Mval q u)) : (k5Array q u r c).natAbs ≤ (4 * Mval q u) * 5 := by rw [k5Array_natAbs] have hle := sbMag_le (Mval q u) r (finProdFinEquiv.symm c).1 (finProdFinEquiv.symm c).2.val (finProdFinEquiv.symm c).2.isLt omega lemma k5Array_natAbs_inj (r₁ : Fin 5) (c₁ : Fin (4 * Mval q u)) (r₂ : Fin 5) (c₂ : Fin (4 * Mval q u)) (h : (k5Array q u r₁ c₁).natAbs = (k5Array q u r₂ c₂).natAbs) : r₁ = r₂ ∧ c₁ = c₂ := by rw [k5Array_natAbs, k5Array_natAbs] at h have hinj := sbMag_inj (Mval q u) r₁ r₂ _ _ _ _ h refine ⟨hinj.1, ?_⟩ apply finProdFinEquiv.symm.injective exact Prod.ext hinj.2.1 hinj.2.2 /-- Exact decomposition of the fiber `{fj | k5Grp r fj.1 fj.2 = g}` into the gadget part (`j < 3u`) and the cross-4-block part (`3u ≤ j`). -/ lemma fiber_split (hq : 1 ≤ q) (r : Fin 5) (g : Fin (2 * u)) : Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => k5Grp q u hq r p.1 p.2 = g) = (Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => p.2.val < 3 * u ∧ k5Grp q u hq r p.1 p.2 = g)) ∪ (Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => ¬ (p.2.val < 3 * u) ∧ k5Grp q u hq r p.1 p.2 = g)) := by ext p simp only [Finset.mem_filter, Finset.mem_union, Finset.mem_univ, true_and] tauto lemma fiber_disjoint (hq : 1 ≤ q) (r : Fin 5) (g : Fin (2 * u)) : Disjoint (Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => p.2.val < 3 * u ∧ k5Grp q u hq r p.1 p.2 = g)) (Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => ¬ (p.2.val < 3 * u) ∧ k5Grp q u hq r p.1 p.2 = g)) := by rw [Finset.disjoint_filter] intro p _ h1 h2 exact h2.1 h1.1 /-- Cardinality and sum of the gadget part (`j < 3u`) of row `(r, g)`. -/ lemma gadget_part_card_and_sum (hq : 1 ≤ q) (r : Fin 5) (g : Fin (2 * u)) : let S := Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => p.2.val < 3 * u ∧ k5Grp q u hq r p.1 p.2 = g) S.card = 6 ∧ ∑ p ∈ S, k5Sign q u p.1 p.2 * sbEntry (Mval q u) r p.1 p.2.val = 0 := by intro S let a : ℕ := g.val / 2 let b : Fin 2 := ⟨g.val % 2, Nat.mod_lt _ (by omega)⟩ have ha : a < u := by omega have hM := Mval_eq q u hq let T : Finset (Fin 4 × Fin 3) := Finset.univ.filter (fun x => gadgetGrp r x.1 x.2 = b) let emb : Fin 4 × Fin 3 → Fin 4 × Fin (Mval q u) := fun x => (x.1, ⟨3 * a + x.2.val, by omega⟩) have hS_eq : S = T.image emb := by ext ⟨f, j⟩ simp only [S, T, emb, Finset.mem_filter, Finset.mem_image, Finset.mem_univ, true_and] constructor · rintro ⟨hj, hgrp⟩ refine ⟨(f, ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩), ?_, ?_⟩ · have hval : 2 * (j.val / 3) + (gadgetGrp r f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩).val = g.val := by have := congrArg Fin.val hgrp simpa [k5Grp, hj] using this have hlt2 : (gadgetGrp r f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩).val < 2 := (gadgetGrp r f _).isLt ext; simp only [b]; omega · have hval : 2 * (j.val / 3) + (gadgetGrp r f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩).val = g.val := by have := congrArg Fin.val hgrp simpa [k5Grp, hj] using this have hlt2 : (gadgetGrp r f ⟨j.val % 3, Nat.mod_lt _ (by omega)⟩).val < 2 := (gadgetGrp r f _).isLt have hdiv : j.val / 3 = a := by omega exact Prod.ext rfl (Fin.ext (by dsimp only; omega)) · rintro ⟨⟨f', i⟩, hgi, heq⟩ rcases Prod.mk.inj heq with ⟨rfl, hj_eq⟩ have hjv : j.val = 3 * a + i.val := by simpa using (congrArg Fin.val hj_eq).symm have hjlt : j.val < 3 * u := by omega refine ⟨hjlt, ?_⟩ ext simp only [k5Grp, hjlt, ↓reduceDIte] have hdiv : j.val / 3 = a := by omega have hmod : (⟨j.val % 3, Nat.mod_lt _ (by omega)⟩ : Fin 3) = i := by ext; dsimp only; omega rw [hdiv, hmod, hgi] dsimp only [b]; omega have hemb_inj : Set.InjOn emb T := by intro x₁ _ x₂ _ h rcases Prod.mk.inj h with ⟨hf, hj⟩ have hjv : 3 * a + x₁.2.val = 3 * a + x₂.2.val := by simpa using congrArg Fin.val hj exact Prod.ext hf (Fin.ext (by omega)) rw [hS_eq, Finset.card_image_of_injOn hemb_inj, Finset.sum_image hemb_inj] refine ⟨gadgetGrp_card r b, ?_⟩ have hterm : ∀ x ∈ T, k5Sign q u (emb x).1 (emb x).2 * sbEntry (Mval q u) r (emb x).1 (emb x).2.val = gadgetSign x.1 x.2 * sbEntry (Mval q u) r x.1 (3 * a + x.2.val) := by intro x _ have hlt : 3 * a + x.2.val < 3 * u := by omega have hmod : (⟨(3 * a + x.2.val) % 3, Nat.mod_lt _ (by omega)⟩ : Fin 3) = x.2 := by ext; dsimp only; omega simp only [emb, k5Sign, hlt, ↓reduceIte, hmod] rw [Finset.sum_congr rfl hterm] exact gadget_row_sum (Mval q u) (3 * a) r b /-- Cardinality and sum of the cross-4-block part (`3u ≤ j`) of row `(r, g)`. -/ lemma cross4_part_card_and_sum (hq : 1 ≤ q) (r : Fin 5) (g : Fin (2 * u)) : let S := Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => ¬ (p.2.val < 3 * u) ∧ k5Grp q u hq r p.1 p.2 = g) S.card = 4 * (q - 1) ∧ ∑ p ∈ S, k5Sign q u p.1 p.2 * sbEntry (Mval q u) r p.1 p.2.val = 0 := by intro S have hM := Mval_eq q u hq let emb : Fin 4 × Fin (q - 1) → Fin 4 × Fin (Mval q u) := fun x => (x.1, ⟨3 * u + g.val * (q - 1) + x.2.val, by have hg := g.isLt have hx := x.2.isLt have hprod : g.val * (q - 1) + x.2.val < (2 * u) * (q - 1) := by calc g.val * (q - 1) + x.2.val < g.val * (q - 1) + (q - 1) := by omega _ = (g.val + 1) * (q - 1) := by ring _ ≤ (2 * u) * (q - 1) := Nat.mul_le_mul_right _ (by omega) omega⟩) have hS_eq : S = Finset.univ.image emb := by ext ⟨f, j⟩ simp only [S, emb, Finset.mem_filter, Finset.mem_image, Finset.mem_univ, true_and] constructor · rintro ⟨hge, hgrp⟩ have hq2 : 0 < q - 1 := by have hj := j.isLt by_contra hlt have : q - 1 = 0 := by omega rw [this] at hM; omega have hdiv : (j.val - 3 * u) / (q - 1) = g.val := by have := congrArg Fin.val hgrp simpa [k5Grp, hge] using this refine ⟨(f, ⟨(j.val - 3 * u) % (q - 1), Nat.mod_lt _ hq2⟩), ?_⟩ refine Prod.ext rfl (Fin.ext ?_) dsimp only have hdm := Nat.div_add_mod (j.val - 3 * u) (q - 1) rw [hdiv, mul_comm] at hdm omega · rintro ⟨⟨f', d⟩, heq⟩ rcases Prod.mk.inj heq with ⟨rfl, hj_eq⟩ have hjv : j.val = 3 * u + g.val * (q - 1) + d.val := by simpa using (congrArg Fin.val hj_eq).symm have hge : ¬ (j.val < 3 * u) := by omega refine ⟨hge, ?_⟩ ext simp only [k5Grp, hge, ↓reduceDIte] have hsub : j.val - 3 * u = g.val * (q - 1) + d.val := by omega rw [hsub] have hq2 : 0 < q - 1 := by have := d.isLt; omega rw [mul_comm, Nat.mul_add_div hq2, Nat.div_eq_of_lt d.isLt, add_zero] have hemb_inj : Set.InjOn emb (Finset.univ : Finset (Fin 4 × Fin (q - 1))) := by intro x₁ _ x₂ _ h rcases Prod.mk.inj h with ⟨hf, hj⟩ have hjv : 3 * u + g.val * (q - 1) + x₁.2.val = 3 * u + g.val * (q - 1) + x₂.2.val := by simpa using congrArg Fin.val hj exact Prod.ext hf (Fin.ext (by omega)) rw [hS_eq, Finset.card_image_of_injOn hemb_inj, Finset.sum_image hemb_inj] refine ⟨by simp, ?_⟩ rw [Fintype.sum_prod_type_right] refine Finset.sum_eq_zero (fun d _ => ?_) have hterm : ∀ f : Fin 4, k5Sign q u (emb (f, d)).1 (emb (f, d)).2 * sbEntry (Mval q u) r (emb (f, d)).1 (emb (f, d)).2.val = cross4Sign f * sbEntry (Mval q u) r f (3 * u + g.val * (q - 1) + d.val) := by intro f have hge : ¬ (3 * u + g.val * (q - 1) + d.val < 3 * u) := by omega simp only [emb, k5Sign, hge, ↓reduceIte] simp_rw [hterm] exact sbEntry_cross4_sum (Mval q u) r (3 * u + g.val * (q - 1) + d.val) lemma k5Array_row_card (hq : 1 ≤ q) (r : Fin 5) (g : Fin (2 * u)) : (Finset.univ.filter (fun c : Fin (4 * Mval q u) => k5ArrayGrp q u hq r c = g)).card = 4 * q + 2 := by have hbij : (Finset.univ.filter (fun c : Fin (4 * Mval q u) => k5ArrayGrp q u hq r c = g)).card = (Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => k5Grp q u hq r p.1 p.2 = g)).card := by refine Finset.card_bij (fun c _ => finProdFinEquiv.symm c) ?_ ?_ ?_ · intro c hc rw [Finset.mem_filter] at hc ⊢ exact ⟨Finset.mem_univ _, hc.2⟩ · intro c₁ _ c₂ _ h; exact finProdFinEquiv.symm.injective h · intro p hp rw [Finset.mem_filter] at hp refine ⟨finProdFinEquiv p, ?_, Equiv.symm_apply_apply _ _⟩ rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_⟩ dsimp only [k5ArrayGrp] rw [Equiv.symm_apply_apply] exact hp.2 rw [hbij, fiber_split q u hq r g, Finset.card_union_of_disjoint (fiber_disjoint q u hq r g)] rw [(gadget_part_card_and_sum q u hq r g).1, (cross4_part_card_and_sum q u hq r g).1] omega lemma k5Array_row_sum (hq : 1 ≤ q) (r : Fin 5) (g : Fin (2 * u)) : ∑ c ∈ Finset.univ.filter (fun c : Fin (4 * Mval q u) => k5ArrayGrp q u hq r c = g), k5Array q u r c = 0 := by have hsum : ∑ c ∈ Finset.univ.filter (fun c : Fin (4 * Mval q u) => k5ArrayGrp q u hq r c = g), k5Array q u r c = ∑ p ∈ Finset.univ.filter (fun p : Fin 4 × Fin (Mval q u) => k5Grp q u hq r p.1 p.2 = g), k5Sign q u p.1 p.2 * sbEntry (Mval q u) r p.1 p.2.val := by refine Finset.sum_bij (fun c _ => finProdFinEquiv.symm c) ?_ ?_ ?_ ?_ · intro c hc rw [Finset.mem_filter] at hc ⊢ exact ⟨Finset.mem_univ _, hc.2⟩ · intro c₁ _ c₂ _ h; exact finProdFinEquiv.symm.injective h · intro p hp rw [Finset.mem_filter] at hp refine ⟨finProdFinEquiv p, ?_, Equiv.symm_apply_apply _ _⟩ rw [Finset.mem_filter] refine ⟨Finset.mem_univ _, ?_⟩ dsimp only [k5ArrayGrp] rw [Equiv.symm_apply_apply] exact hp.2 · intro c _; rfl rw [hsum, fiber_split q u hq r g, Finset.sum_union (fiber_disjoint q u hq r g)] rw [(gadget_part_card_and_sum q u hq r g).2, (cross4_part_card_and_sum q u hq r g).2, add_zero] /-- Explicit integer Heffter array `H(5 * (2u), (4q+2) * (2u); 4q+2, 5)` for all `q ≥ 1, u ≥ 1`. -/ def heffterK5Even (q u : ℕ) (hq : 1 ≤ q) : IntegerHeffterArray (5 * (2 * u)) ((4 * q + 2) * (2 * u)) (4 * q + 2) 5 := (four_mul_Mval q u) ▸ ofIndependentRowPartition (k5Array q u) (k5ArrayGrp q u hq) (k5Array_col_sum q u) (k5Array_row_card q u hq) (k5Array_row_sum q u hq) (k5Array_ne_zero q u) (k5Array_natAbs_le q u) (k5Array_natAbs_inj q u) end Assembly /-! ## 4. Main Theorems -/ /-- **Theorem 2 (Complete `k = 5, s ≡ 2 (mod 4)` Existence)**: For every `s ≥ 6` with `s ≡ 2 (mod 4)` and every even `t ≥ 2`, there exists an integer Heffter array `H(5t, st; s, 5)`. -/ theorem exists_heffter_k5_even (s t : ℕ) (hs : 6 ≤ s) (hs4 : s % 4 = 2) (_ht : 2 ≤ t) (ht2 : t % 2 = 0) : Nonempty (IntegerHeffterArray (5 * t) (s * t) s 5) := by have hsq : s = 4 * (s / 4) + 2 := by omega have htu : t = 2 * (t / 2) := by omega have hq : 1 ≤ s / 4 := by omega rw [hsq, htu] exact ⟨heffterK5Even (s / 4) (t / 2) hq⟩ /-- Transpose corollary: `H(st, 5t; 5, s)` exists for all `s ≥ 6` with `s ≡ 2 (mod 4)` and all even `t ≥ 2`. -/ theorem exists_heffter_k5_even_transpose (s t : ℕ) (hs : 6 ≤ s) (hs4 : s % 4 = 2) (ht : 2 ≤ t) (ht2 : t % 2 = 0) : Nonempty (IntegerHeffterArray (s * t) (5 * t) 5 s) := by rcases exists_heffter_k5_even s t hs hs4 ht ht2 with ⟨H⟩ exact ⟨H.transpose⟩ /-- **Complete Resolution of the `k = 5, s ≡ 2 (mod 4)` Open Frontier of Archdeacon's Conjecture**: Every admissible parameter tuple `(m, n; s, 5)` in the `s ≡ 2 (mod 4), gcd(s, 5) = 1` open frontier of Morini–Pellegrini (`arXiv:2510.08302`) admits an integer Heffter array `H(m, n; s, 5)`, with zero exceptions. -/ theorem archdeacon_k5_even_frontier (m n s : ℕ) (hs3 : 3 ≤ s) (hs4 : s % 4 = 2) (hcop : Nat.Coprime s 5) (hm5 : 5 ≤ m) (hms : m * s = n * 5) (hpar : (n * 5) % 4 = 0 ∨ (n * 5) % 4 = 3) : Nonempty (IntegerHeffterArray m n s 5) := by have h5_dvd_ms : 5 ∣ m * s := ⟨n, by linarith⟩ have h5_dvd_m : 5 ∣ m := hcop.symm.dvd_of_dvd_mul_right h5_dvd_ms rcases h5_dvd_m with ⟨t, rfl⟩ have hn_eq : n = s * t := by have hmul : 5 * (s * t) = 5 * n := by linarith exact (Nat.mul_left_cancel (by omega : 0 < 5) hmul).symm subst hn_eq have hs6 : 6 ≤ s := by omega have ht1 : 1 ≤ t := by omega have ht2 : t % 2 = 0 := by have hs_eq : s = 4 * (s / 4) + 2 := by omega have h1 : s * t * 5 = 4 * ((s / 4) * t * 5 + 2 * t) + 2 * t := by calc s * t * 5 = (4 * (s / 4) + 2) * t * 5 := by rw [← hs_eq] _ = 4 * ((s / 4) * t * 5 + 2 * t) + 2 * t := by ring omega have ht_ge2 : 2 ≤ t := by omega exact exists_heffter_k5_even s t hs6 hs4 ht_ge2 ht2 #print axioms exists_heffter_k5_even #print axioms exists_heffter_k5_even_transpose #print axioms archdeacon_k5_even_frontier end HeffterK5EvenFrontier