import Mathlib /-! # Integer Heffter Arrays: Core Definitions, Necessary Conditions, and Independent-Row-Partition Reduction This file formalizes the core theory of **integer Heffter arrays** `H(m, n; s, k)` introduced by Dan Archdeacon (2015), establishes all universal necessary conditions for Archdeacon's Conjecture, proves transpose duality, and establishes the **Independent-Row-Partition (IRP) Reduction Theorem** together with the generic linear `4`-block and `12`-block splitting lemmas that power our complete resolution of the even-parameter open frontier (`k ∈ {3, 5}`, `s ≡ 2 (mod 4)`) of Morini–Pellegrini (`arXiv:2510.08302`, Oct 2025). ## Main Results - `IntegerHeffterArray m n s k`: canonical structure for an integer Heffter array. - `IntegerHeffterArray.ms_eq_nk`: double counting `m * s = n * k`. - `IntegerHeffterArray.magnitudes_eq_Icc`: the magnitudes of filled cells are exactly `{1, ..., n * k}`. - `IntegerHeffterArray.existsUnique_magnitude`: every `d ∈ {1, ..., n * k}` appears as `|v|` in a unique cell. - `IntegerHeffterArray.three_le_s` / `three_le_k`: non-trivial rows/columns have size `≥ 3`. - `IntegerHeffterArray.nk_mod_four`: parity obstruction `n * k % 4 = 0 ∨ n * k % 4 = 3`. - `IntegerHeffterArray.necessary_conditions`: full bundle of Archdeacon's necessary conditions. - `IntegerHeffterArray.transpose`: transpose duality `H(m, n; s, k) → H(n, m; k, s)`. - `ofIndependentRowPartition`: the Independent-Row-Partition Reduction Theorem turning any zero-column-sum `k × N` array with independent zero-sum `s`-partitions of each row into an `IntegerHeffterArray (k * t) N s k`. - `linear_four_block_sum` & `linear_twelve_block_split`: universal affine-progression block lemmas. -/ namespace HeffterArrays open Finset BigOperators /-- An integer Heffter array `H(m, n; s, k)`: an `m × n` partially filled matrix with integer entries such that: - every row has `s` filled cells summing to `0`, - every column has `k` filled cells summing to `0`, - filled entries are nonzero with distinct absolute values in `{1, ..., n * k}` (which by double counting automatically surjects onto `{1, ..., n * 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₂ namespace IntegerHeffterArray variable {m n s k : ℕ} (H : IntegerHeffterArray m n s k) /-- The finite set of filled cell coordinates `(i, j)`. -/ def filledCells : Finset (Fin m × Fin n) := Finset.univ.filter (fun p => (H.entry p.1 p.2).isSome) /-- The signed value at cell `(i, j)`, defaulting to `0` on empty cells. -/ def val (i : Fin m) (j : Fin n) : ℤ := (H.entry i j).getD 0 lemma mem_filledCells {i : Fin m} {j : Fin n} : (i, j) ∈ H.filledCells ↔ (H.entry i j).isSome := by simp [filledCells] lemma val_eq_of_entry {i : Fin m} {j : Fin n} {v : ℤ} (hv : H.entry i j = some v) : H.val i j = v := by simp [val, hv] lemma val_eq_zero_of_none {i : Fin m} {j : Fin n} (h : H.entry i j = none) : H.val i j = 0 := by simp [val, h] lemma val_ne_zero_of_mem {p : Fin m × Fin n} (hp : p ∈ H.filledCells) : H.val p.1 p.2 ≠ 0 := by rw [mem_filledCells] at hp cases h : H.entry p.1 p.2 with | none => simp [h] at hp | some v => rw [H.val_eq_of_entry h] exact H.entry_ne_zero p.1 p.2 v h lemma natAbs_pos_of_mem {p : Fin m × Fin n} (hp : p ∈ H.filledCells) : 1 ≤ (H.val p.1 p.2).natAbs := by have hne := H.val_ne_zero_of_mem hp exact Int.natAbs_pos.mpr hne lemma natAbs_le_of_mem {p : Fin m × Fin n} (hp : p ∈ H.filledCells) : (H.val p.1 p.2).natAbs ≤ n * k := by rw [mem_filledCells] at hp cases h : H.entry p.1 p.2 with | none => simp [h] at hp | some v => rw [H.val_eq_of_entry h] exact H.entry_natAbs_le p.1 p.2 v h lemma natAbs_injOn_filledCells : Set.InjOn (fun p : Fin m × Fin n => (H.val p.1 p.2).natAbs) H.filledCells := by intro p₁ hp₁ p₂ hp₂ heq rw [Finset.mem_coe, mem_filledCells] at hp₁ hp₂ cases h₁ : H.entry p₁.1 p₁.2 with | none => simp [h₁] at hp₁ | some v₁ => cases h₂ : H.entry p₂.1 p₂.2 with | none => simp [h₂] at hp₂ | some v₂ => simp only [val, h₁, h₂, Option.getD_some] at heq have hpair := H.natAbs_inj p₁.1 p₁.2 v₁ p₂.1 p₂.2 v₂ h₁ h₂ heq exact Prod.ext hpair.1 hpair.2 /-- Counting filled cells by rows gives `m * s`. -/ lemma filledCells_card_rows : H.filledCells.card = m * s := by have h1 : H.filledCells.card = ∑ i : Fin m, (Finset.univ.filter (fun j : Fin n => (H.entry i j).isSome)).card := by rw [filledCells, Finset.card_filter, Fintype.sum_prod_type] congr 1; ext i rw [Finset.card_filter] rw [h1] simp [H.row_card] /-- Counting filled cells by columns gives `n * k`. -/ lemma filledCells_card_cols : H.filledCells.card = n * k := by have h1 : H.filledCells.card = ∑ j : Fin n, (Finset.univ.filter (fun i : Fin m => (H.entry i j).isSome)).card := by rw [filledCells, Finset.card_filter, Fintype.sum_prod_type_right] congr 1; ext j rw [Finset.card_filter] rw [h1] simp [H.col_card] /-- Double counting of filled cells: `m * s = n * k`. -/ theorem ms_eq_nk (H : IntegerHeffterArray m n s k) : m * s = n * k := by rw [← H.filledCells_card_rows, H.filledCells_card_cols] /-- Row sparsity bound: if `m > 0`, then `s ≤ n`. -/ theorem s_le_n (H : IntegerHeffterArray m n s k) (hm : 0 < m) : s ≤ n := by let i₀ : Fin m := ⟨0, hm⟩ calc s = (Finset.univ.filter (fun j : Fin n => (H.entry i₀ j).isSome)).card := (H.row_card i₀).symm _ ≤ (Finset.univ : Finset (Fin n)).card := Finset.card_filter_le _ _ _ = n := by simp /-- Column sparsity bound: if `n > 0`, then `k ≤ m`. -/ theorem k_le_m (H : IntegerHeffterArray m n s k) (hn : 0 < n) : k ≤ m := by let j₀ : Fin n := ⟨0, hn⟩ calc k = (Finset.univ.filter (fun i : Fin m => (H.entry i j₀).isSome)).card := (H.col_card j₀).symm _ ≤ (Finset.univ : Finset (Fin m)).card := Finset.card_filter_le _ _ _ = m := by simp /-- The set of magnitudes of all filled cells is exactly `{1, ..., n * k}`. -/ theorem magnitudes_eq_Icc : H.filledCells.image (fun p => (H.val p.1 p.2).natAbs) = Finset.Icc 1 (n * k) := by apply Finset.eq_of_subset_of_card_le · intro d hd rcases Finset.mem_image.mp hd with ⟨p, hp, rfl⟩ exact Finset.mem_Icc.mpr ⟨H.natAbs_pos_of_mem hp, H.natAbs_le_of_mem hp⟩ · rw [Finset.card_image_of_injOn H.natAbs_injOn_filledCells, H.filledCells_card_cols, Nat.card_Icc] omega /-- Every integer `d ∈ {1, ..., n * k}` occurs as `|v|` in a unique filled cell. -/ theorem existsUnique_magnitude (d : ℕ) (hd1 : 1 ≤ d) (hd2 : d ≤ n * k) : ∃! p : Fin m × Fin n, ∃ v : ℤ, H.entry p.1 p.2 = some v ∧ v.natAbs = d := by have hmem : d ∈ H.filledCells.image (fun p => (H.val p.1 p.2).natAbs) := by rw [H.magnitudes_eq_Icc] exact Finset.mem_Icc.mpr ⟨hd1, hd2⟩ rcases Finset.mem_image.mp hmem with ⟨p, hp, hpd⟩ rw [mem_filledCells] at hp cases hv : H.entry p.1 p.2 with | none => simp [hv] at hp | some v => refine ⟨p, ⟨v, hv, ?_⟩, ?_⟩ · simpa [val, hv] using hpd · rintro q ⟨w, hw, hwd⟩ have hvd : v.natAbs = d := by simpa [val, hv] using hpd have hpair := H.natAbs_inj q.1 q.2 w p.1 p.2 v hw hv (hwd.trans hvd.symm) exact Prod.ext hpair.1 hpair.2 /-- Total sum of all entries in the array is `0`. -/ lemma sum_filledCells_eq_zero : ∑ p ∈ H.filledCells, H.val p.1 p.2 = 0 := by have h1 : ∑ p ∈ H.filledCells, H.val p.1 p.2 = ∑ p : Fin m × Fin n, H.val p.1 p.2 := by apply Finset.sum_subset (Finset.subset_univ _) intro p _ hp rw [mem_filledCells] at hp cases h : H.entry p.1 p.2 with | none => exact H.val_eq_zero_of_none h | some v => simp [h] at hp rw [h1, Fintype.sum_prod_type] simp [val, H.row_sum] /-- Parity lemma: the sum of `1..N` is even iff `N % 4 = 0 ∨ N % 4 = 3`. -/ lemma sum_Icc_even_iff (N : ℕ) : Even (∑ d ∈ Finset.Icc 1 N, d) ↔ N % 4 = 0 ∨ N % 4 = 3 := by have h2 : 2 * ∑ d ∈ Finset.Icc 1 N, d = N * (N + 1) := by induction N with | zero => simp | succ a ih => rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ a + 1), Nat.mul_add, ih] ring constructor · rintro ⟨t, ht⟩ have h4 : N * (N + 1) = 4 * t := by omega have hmod : (N * (N + 1)) % 4 = 0 := by omega have hN : N % 4 = 0 ∨ N % 4 = 1 ∨ N % 4 = 2 ∨ N % 4 = 3 := by omega rcases hN with h | h | h | h · left; exact h · exfalso have : (N * (N + 1)) % 4 = 2 := by rw [Nat.mul_mod, Nat.add_mod, h] omega · exfalso have : (N * (N + 1)) % 4 = 2 := by rw [Nat.mul_mod, Nat.add_mod, h] omega · right; exact h · intro h have h4 : 4 ∣ N * (N + 1) := by rcases h with h | h · exact dvd_mul_of_dvd_left (Nat.dvd_of_mod_eq_zero h) _ · refine dvd_mul_of_dvd_right ?_ _ omega rcases h4 with ⟨t, ht⟩ refine ⟨t, ?_⟩ omega /-- Necessary parity condition for Archdeacon's Conjecture: `n * k % 4 = 0 ∨ n * k % 4 = 3`. -/ theorem nk_mod_four (H : IntegerHeffterArray m n s k) : n * k % 4 = 0 ∨ n * k % 4 = 3 := by rw [← sum_Icc_even_iff] have hsum_abs : ∑ d ∈ Finset.Icc 1 (n * k), d = ∑ p ∈ H.filledCells, (H.val p.1 p.2).natAbs := by rw [← H.magnitudes_eq_Icc, Finset.sum_image (by intro x hx y hy hxy exact H.natAbs_injOn_filledCells hx hy hxy)] have hpar : Even (∑ p ∈ H.filledCells, ((H.val p.1 p.2).natAbs : ℤ)) := by have hdiff : ∑ p ∈ H.filledCells, ((H.val p.1 p.2).natAbs : ℤ) - ∑ p ∈ H.filledCells, H.val p.1 p.2 = ∑ p ∈ H.filledCells, (((H.val p.1 p.2).natAbs : ℤ) - H.val p.1 p.2) := by rw [Finset.sum_sub_distrib] rw [H.sum_filledCells_eq_zero, sub_zero] at hdiff rw [hdiff] refine Finset.even_sum _ (fun p _ => ?_) have h2 : (2 : ℤ) ∣ ((H.val p.1 p.2).natAbs : ℤ) - H.val p.1 p.2 := by rcases Int.natAbs_eq (H.val p.1 p.2) with h | h · rw [← h, sub_self]; exact dvd_zero 2 · have : ((H.val p.1 p.2).natAbs : ℤ) - H.val p.1 p.2 = 2 * ((H.val p.1 p.2).natAbs : ℤ) := by omega rw [this]; exact dvd_mul_right 2 _ rcases h2 with ⟨c, hc⟩ exact ⟨c, by omega⟩ rw [hsum_abs] rcases hpar with ⟨c, hc⟩ have hcast : ((∑ p ∈ H.filledCells, (H.val p.1 p.2).natAbs : ℕ) : ℤ) = c + c := by simpa [Nat.cast_sum] using hc have hc0 : 0 ≤ c := by omega refine ⟨c.toNat, ?_⟩ omega /-- Every row in a non-empty Heffter array (`m > 0`, `s > 0`) has at least `3` filled cells. -/ theorem three_le_s (H : IntegerHeffterArray m n s k) (hm : 0 < m) (hs : 0 < s) : 3 ≤ s := by let i₀ : Fin m := ⟨0, hm⟩ let S : Finset (Fin n) := Finset.univ.filter (fun j : Fin n => (H.entry i₀ j).isSome) have hcard : S.card = s := H.row_card i₀ have hsum : ∑ j ∈ S, H.val i₀ j = 0 := by have h0 := H.row_sum i₀ have hsub : ∑ j ∈ S, H.val i₀ j = ∑ j : Fin n, H.val i₀ j := by apply Finset.sum_subset (Finset.subset_univ _) intro j _ hj simp only [S, Finset.mem_filter, Finset.mem_univ, true_and] at hj cases h : H.entry i₀ j with | none => exact H.val_eq_zero_of_none h | some v => simp [h] at hj rw [hsub]; exact h0 by_contra hlt push Not at hlt have hs12 : s = 1 ∨ s = 2 := by omega rcases hs12 with hs1 | hs2 · rw [hs1] at hcard rcases Finset.card_eq_one.mp hcard with ⟨j, hj⟩ rw [hj, Finset.sum_singleton] at hsum have hmem : (i₀, j) ∈ H.filledCells := by have : j ∈ S := by simp [hj] simpa [S, filledCells] using this exact H.val_ne_zero_of_mem hmem hsum · rw [hs2] at hcard rcases Finset.card_eq_two.mp hcard with ⟨j₁, j₂, hne, hpair⟩ rw [hpair, Finset.sum_pair hne] at hsum have hm1 : j₁ ∈ S := by simp [hpair] have hm2 : j₂ ∈ S := by simp [hpair] simp only [S, Finset.mem_filter, Finset.mem_univ, true_and] at hm1 hm2 cases hv1 : H.entry i₀ j₁ with | none => simp [hv1] at hm1 | some v₁ => cases hv2 : H.entry i₀ j₂ with | none => simp [hv2] at hm2 | some v₂ => rw [H.val_eq_of_entry hv1, H.val_eq_of_entry hv2] at hsum have habs : v₁.natAbs = v₂.natAbs := by have : v₁ = -v₂ := by omega rw [this, Int.natAbs_neg] have heq := (H.natAbs_inj i₀ j₁ v₁ i₀ j₂ v₂ hv1 hv2 habs).2 exact hne heq /-- Transpose duality: transposing an `H(m, n; s, k)` yields an `H(n, m; k, s)`. -/ def transpose (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 rw [H.ms_eq_nk] 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⟩ /-- Every column in a non-empty Heffter array (`n > 0`, `k > 0`) has at least `3` filled cells. -/ theorem three_le_k (H : IntegerHeffterArray m n s k) (hn : 0 < n) (hk : 0 < k) : 3 ≤ k := H.transpose.three_le_s hn hk /-- Full bundle of Archdeacon's necessary conditions for non-empty integer Heffter arrays. -/ theorem necessary_conditions (H : IntegerHeffterArray m n s k) (hm : 0 < m) (hn : 0 < n) (hs : 0 < s) (hk : 0 < k) : 3 ≤ s ∧ s ≤ n ∧ 3 ≤ k ∧ k ≤ m ∧ m * s = n * k ∧ (n * k % 4 = 0 ∨ n * k % 4 = 3) := ⟨H.three_le_s hm hs, H.s_le_n hm, H.three_le_k hn hk, H.k_le_m hn, H.ms_eq_nk, H.nk_mod_four⟩ end IntegerHeffterArray /-! ## Independent-Row-Partition (IRP) Reduction Theorem Suppose we have a `k × N` integer array `A : Fin k → Fin N → ℤ` whose columns sum to `0` and whose `k * N` entries have distinct positive magnitudes in `{1, ..., N * k}`. If, **independently for each row `r : Fin k`**, we assign each column `c : Fin N` to a row-group `grp r c : Fin t` such that every fiber `{c | grp r c = g}` has cardinality `s` and sum `0`, then placing `A r c` at row `(r, grp r c) ∈ Fin k × Fin t ≃ Fin (k * t)` and column `c` yields an `IntegerHeffterArray (k * t) N s k`! -/ /-- **Independent-Row-Partition (IRP) Reduction Theorem**: constructs an `IntegerHeffterArray (k * t) N s k` from a zero-column-sum `k × N` array `A` and independent zero-sum `s`-partitions `grp r : Fin N → Fin t` of each row. -/ 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 · have hpair : finProdFinEquiv.symm i₁ = finProdFinEquiv.symm i₂ := Prod.ext heq (by rw [← h1, ← h2, heq]) exact finProdFinEquiv.symm.injective hpair · 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]) /-! ## Universal Linear Block Lemmas (`4`-Blocks and `12`-Blocks) For any affine progression `f(j) = a + b * j`: - **4-block** `(+, -, -, +)` on `4` consecutive indices sums to `0`. - **12-block** on `12` consecutive indices partitions into two `6`-element zero-sum sets: - Group 0: `+{0, 5, 6}`, `-{1, 2, 8}` (`0 + 5 + 6 = 11 = 1 + 2 + 8`) - Group 1: `+{3, 9, 10}`, `-{4, 7, 11}` (`3 + 9 + 10 = 22 = 4 + 7 + 11`) -/ /-- The sign of offset `i : Fin 4` in a linear `4`-block `(+, -, -, +)`. -/ def block4Sign : Fin 4 → ℤ | ⟨0, _⟩ => 1 | ⟨1, _⟩ => -1 | ⟨2, _⟩ => -1 | ⟨3, _⟩ => 1 /-- Every linear progression summed over a `4`-block with signs `(+, -, -, +)` vanishes identically. -/ theorem linear_four_block_sum (a b : ℤ) : ∑ i : Fin 4, block4Sign i * (a + b * (i : ℤ)) = 0 := by rw [Fin.sum_univ_four] simp only [block4Sign, Fin.val_zero, Fin.val_one, Fin.val_two] change 1 * (a + b * 0) + -1 * (a + b * 1) + -1 * (a + b * 2) + 1 * (a + b * 3) = 0 ring /-- The sign of offset `i : Fin 12` in our magic `12`-block partition. -/ def block12Sign : Fin 12 → ℤ | ⟨0, _⟩ => 1 | ⟨1, _⟩ => -1 | ⟨2, _⟩ => -1 | ⟨3, _⟩ => 1 | ⟨4, _⟩ => -1 | ⟨5, _⟩ => 1 | ⟨6, _⟩ => 1 | ⟨7, _⟩ => -1 | ⟨8, _⟩ => -1 | ⟨9, _⟩ => 1 | ⟨10, _⟩ => 1 | ⟨11, _⟩ => -1 /-- The group (`0` or `1`) of offset `i : Fin 12` in our magic `12`-block partition: Group `0` = `{0, 1, 2, 5, 6, 8}`, Group `1` = `{3, 4, 7, 9, 10, 11}`. -/ def block12Group : Fin 12 → Fin 2 | ⟨0, _⟩ => 0 | ⟨1, _⟩ => 0 | ⟨2, _⟩ => 0 | ⟨3, _⟩ => 1 | ⟨4, _⟩ => 1 | ⟨5, _⟩ => 0 | ⟨6, _⟩ => 0 | ⟨7, _⟩ => 1 | ⟨8, _⟩ => 0 | ⟨9, _⟩ => 1 | ⟨10, _⟩ => 1 | ⟨11, _⟩ => 1 /-- Each group in the magic `12`-block has cardinality `6`. -/ theorem block12Group_card (g : Fin 2) : (Finset.univ.filter (fun i : Fin 12 => block12Group i = g)).card = 6 := by fin_cases g <;> decide /-- Every linear progression summed over Group `0` or Group `1` of the magic `12`-block vanishes identically. -/ theorem linear_twelve_block_sum (a b : ℤ) (g : Fin 2) : ∑ i ∈ Finset.univ.filter (fun i : Fin 12 => block12Group i = g), block12Sign i * (a + b * (i : ℤ)) = 0 := by fin_cases g · dsimp only have hfilt : Finset.univ.filter (fun i : Fin 12 => block12Group i = ⟨0, by omega⟩) = {⟨0, by omega⟩, ⟨1, by omega⟩, ⟨2, by omega⟩, ⟨5, by omega⟩, ⟨6, by omega⟩, ⟨8, by omega⟩} := by decide rw [hfilt] simp [block12Sign] ring · dsimp only have hfilt : Finset.univ.filter (fun i : Fin 12 => block12Group i = ⟨1, by omega⟩) = {⟨3, by omega⟩, ⟨4, by omega⟩, ⟨7, by omega⟩, ⟨9, by omega⟩, ⟨10, by omega⟩, ⟨11, by omega⟩} := by decide rw [hfilt] simp [block12Sign] ring #print axioms IntegerHeffterArray.necessary_conditions #print axioms IntegerHeffterArray.magnitudes_eq_Icc #print axioms IntegerHeffterArray.existsUnique_magnitude #print axioms IntegerHeffterArray.transpose #print axioms ofIndependentRowPartition #print axioms linear_four_block_sum #print axioms linear_twelve_block_sum end HeffterArrays