import Mathlib /-! # Globally Simple Rectangular Integer Relative Heffter Arrays & Orthogonal Cyclic Cycle Decompositions of Complete Multipartite Graphs This foundational library establishes the general theory of **integer relative Heffter arrays** `H_t(m, n; s, k)` and **globally simple integer relative Heffter arrays** `SH_t(m, n; s, k)` (Costa–Morini–Pasotti–Pellegrini 2020; Costa–Pasotti–Pellegrini 2020) and their direct graph-theoretic consequence: **orthogonal cyclic `s`-cycle and `k`-cycle decompositions of the complete multipartite graph `K_{((2nk + t)/t) × t}`**. ## Main Definitions & Results 1. `relHalfMax N t`, `relStep N t`, `relHalfSet N t`: exact positive half-set of `ZMod (2 * N + t) \ J` where `J` is the unique subgroup of order `t` (`t ∣ 2 * N`), with exact cardinality theorem `relHalfSet_card : (relHalfSet N t).card = N`. 2. `IntRelativeHeffterArray m n s k t`: partially filled `m × n` integer matrix with `s` filled cells per row, `k` per column, zero row/column sums over `ℤ`, and magnitudes in bijection with `relHalfSet (n * k) t`. 3. **Necessary Admissibility Parity Theorem (`IntRelativeHeffterArray.even_halfSet_sum`)**: the sum of all elements in `relHalfSet (n * k) t` is necessarily even. 4. `GloballySimpleRelativeHeffterArray m n s k t`: every row (left-to-right) and column (top-to-bottom) has pairwise distinct partial sums in `ZMod (2 * (n * k) + t)`. 5. **General Automatic Simplicity (`isSimpleList_of_length_le_five_rel`, `globallySimpleRel_of_le_five`)**: for EVERY `t ≥ 1`, every integer relative Heffter array with `s ≤ 5` and `k ≤ 5` is automatically globally simple. 6. **General Length-6 & Length-7 Reductions (`isSimpleList_of_len_six_rel`, `isSimpleList_of_len_seven_rel`)**: exact reduction of global simplicity modulo any `v` (with `2 * |x| < v`) to 3 (resp. 7) length-3 sub-sum inequalities avoiding `{0, ±v}`. 7. **Complete Multipartite Graph Bridge (`toOrthogonalCyclicMultipartiteDecomps`)**: every `GloballySimpleRelativeHeffterArray m n s k t` constructs an explicit pair of **orthogonal cyclic** `s`-cycle and `k`-cycle decompositions of the complete multipartite graph `K_{((2nk + t)/t) × t}`. 8. **Sparse Relative Block-Diagonal Assembly (`ofSeamAndUniformBlocksRelSimple`, `ofSeamAndUniformBlocksRelSimpleKLe5`, `ofUniformBlocksRelSimpleKLe5`)**. -/ namespace RelativeRay3x6T3T4 open Finset /-! ## 1. Relative Half-Set Arithmetic (`ZMod (2N + t) \ J`) -/ /-- Upper bound `⌊(2N + t - 1)/2⌋` for positive representatives of `ZMod (2N + t) \ J`. -/ def relHalfMax (N t : ℕ) : ℕ := (2 * N + t - 1) / 2 /-- Generator `q = (2N + t) / t` of the order-`t` subgroup `J ≤ ZMod (2N + t)`. -/ def relStep (N t : ℕ) : ℕ := (2 * N + t) / t /-- Exact positive half-set of `ZMod (2N + t) \ J`: all `d ∈ {1, …, relHalfMax N t}` not divisible by `relStep N t`. -/ def relHalfSet (N t : ℕ) : Finset ℕ := (Finset.Icc 1 (relHalfMax N t)).filter (fun d => ¬ (relStep N t ∣ d)) lemma relStep_mul (N t : ℕ) (ht : 0 < t) (hdiv : t ∣ 2 * N) : t * relStep N t = 2 * N + t := by rcases hdiv with ⟨c, hc⟩ have hq : relStep N t = c + 1 := by unfold relStep rw [hc, show t * c + t = t * (c + 1) by ring, Nat.mul_div_cancel_left _ ht] rw [hq, hc]; ring lemma relStep_pos (N t : ℕ) (ht : 0 < t) (hdiv : t ∣ 2 * N) : 0 < relStep N t := by have h := relStep_mul N t ht hdiv by_contra h0 have hq0 : relStep N t = 0 := by omega rw [hq0, mul_zero] at h; omega lemma two_mul_le_of_le_relHalfMax {N t d : ℕ} (ht : 0 < t) (hd : d ≤ relHalfMax N t) : 2 * d < 2 * N + t := by unfold relHalfMax at hd; omega lemma le_relHalfMax_of_two_mul_lt {N t d : ℕ} (_ht : 0 < t) (hd : 2 * d < 2 * N + t) : d ≤ relHalfMax N t := by unfold relHalfMax; omega /-- **Exact Half-Set Cardinality Theorem**: for every `t ≥ 1` dividing `2 * N`, `(relHalfSet N t).card = N`. -/ theorem relHalfSet_card (N t : ℕ) (ht : 0 < t) (hdiv : t ∣ 2 * N) : (relHalfSet N t).card = N := by unfold relHalfSet let r := (t - 1) / 2 let q := relStep N t have hq_mul : t * q = 2 * N + t := relStep_mul N t ht hdiv have hq_pos : 0 < q := relStep_pos N t ht hdiv have hmax : relHalfMax N t = N + r := by unfold relHalfMax; dsimp only [r]; omega have hmult : (Finset.Icc 1 (relHalfMax N t)).filter (fun d => q ∣ d) = (Finset.Icc 1 r).image (fun k => k * q) := by ext d simp only [Finset.mem_filter, Finset.mem_Icc, Finset.mem_image] constructor · rintro ⟨⟨hd1, hd2⟩, ⟨k, rfl⟩⟩ refine ⟨k, ⟨?_, ?_⟩, mul_comm k q⟩ · by_contra hk0; have : k = 0 := by omega subst this; simp at hd1 · by_contra hkr have hkge : r + 1 ≤ k := by omega have h2r : 2 * (r + 1) ≥ t := by dsimp only [r]; omega have hmul1 : t * q ≤ 2 * (r + 1) * q := Nat.mul_le_mul_right q h2r have hmul2 : 2 * (r + 1) * q ≤ 2 * (k * q) := by have h1 : (r + 1) * q ≤ k * q := Nat.mul_le_mul_right q hkge calc 2 * (r + 1) * q = 2 * ((r + 1) * q) := by ring _ ≤ 2 * (k * q) := by omega have hlt : 2 * (q * k) < 2 * N + t := two_mul_le_of_le_relHalfMax ht hd2 rw [mul_comm q k] at hlt omega · rintro ⟨k, ⟨hk1, hkr⟩, rfl⟩ refine ⟨⟨?_, ?_⟩, ⟨k, mul_comm k q⟩⟩ · exact Nat.mul_pos (by omega) hq_pos · apply le_relHalfMax_of_two_mul_lt ht have h2r : 2 * r ≤ t - 1 := by dsimp only [r]; omega have h1 : 2 * (k * q) ≤ (t - 1) * q := by have : 2 * k ≤ t - 1 := by omega calc 2 * (k * q) = (2 * k) * q := by ring _ ≤ (t - 1) * q := Nat.mul_le_mul_right q this have h2 : (t - 1) * q + q = t * q := by have : (t - 1) + 1 = t := by omega calc (t - 1) * q + q = ((t - 1) + 1) * q := by ring _ = t * q := by rw [this] omega have hsum := Finset.sum_filter_add_sum_filter_not (Finset.Icc 1 (relHalfMax N t)) (fun d => q ∣ d) (fun _ => (1 : ℕ)) simp only [Finset.sum_const, smul_eq_mul, mul_one] at hsum rw [hmult, Finset.card_image_of_injective _ (fun a b hab => Nat.eq_of_mul_eq_mul_right hq_pos hab)] at hsum simp only [Nat.card_Icc] at hsum dsimp only [q] at hsum omega lemma relHalfMax_three (M : ℕ) : relHalfMax (12 * M) 3 = 12 * M + 1 := by unfold relHalfMax; omega lemma relStep_three (M : ℕ) : relStep (12 * M) 3 = 8 * M + 1 := by unfold relStep; omega lemma relHalfMax_four_even (M : ℕ) : relHalfMax (12 * M) 4 = 12 * M + 1 := by unfold relHalfMax; omega lemma relStep_four_even (M : ℕ) : relStep (12 * M) 4 = 6 * M + 1 := by unfold relStep; omega lemma relHalfMax_four_odd (M : ℕ) : relHalfMax (12 * M + 6) 4 = 12 * M + 7 := by unfold relHalfMax; omega lemma relStep_four_odd (M : ℕ) : relStep (12 * M + 6) 4 = 6 * M + 4 := by unfold relStep; omega /-! ## 2. Integer Relative Heffter Arrays `H_t(m, n; s, k)` -/ /-- An **integer relative Heffter array** `H_t(m, n; s, k)` relative to the order-`t` subgroup of `ZMod (2 * (n * k) + t)`. -/ structure IntRelativeHeffterArray (m n s k t : ℕ) where entry : Fin m → Fin n → Option ℤ ht_pos : 0 < t ht_div : t ∣ 2 * (n * k) 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 nonzero : ∀ i j x, entry i j = some x → x ≠ 0 mag_le : ∀ i j x, entry i j = some x → x.natAbs ≤ relHalfMax (n * k) t not_subgrp : ∀ i j x, entry i j = some x → ¬ (relStep (n * k) t ∣ x.natAbs) mag_inj : ∀ i₁ j₁ i₂ j₂ x₁ x₂, entry i₁ j₁ = some x₁ → entry i₂ j₂ = some x₂ → x₁.natAbs = x₂.natAbs → i₁ = i₂ ∧ j₁ = j₂ lemma IntRelativeHeffterArray.mul_eq {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) : 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 [show (Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome)) = (Finset.univ.sigma (fun i : Fin m => Finset.univ.filter (fun j : Fin n => (H.entry i j).isSome))).map ⟨fun ⟨i, j⟩ => (i, j), fun ⟨_, _⟩ ⟨_, _⟩ h => by cases h; rfl⟩ by ext ⟨i, j⟩; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Finset.mem_sigma] exact ⟨fun h => ⟨⟨i, j⟩, h, rfl⟩, fun ⟨⟨_, _⟩, h, heq⟩ => by cases heq; exact h⟩] rw [Finset.card_map, Finset.card_sigma] simp [H.row_card] have h2 : (Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome)).card = n * k := by rw [show (Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome)) = (Finset.univ.sigma (fun j : Fin n => Finset.univ.filter (fun i : Fin m => (H.entry i j).isSome))).map ⟨fun ⟨j, i⟩ => (i, j), fun ⟨_, _⟩ ⟨_, _⟩ h => by cases h; rfl⟩ by ext ⟨i, j⟩; simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Finset.mem_sigma] exact ⟨fun h => ⟨⟨j, i⟩, h, rfl⟩, fun ⟨⟨_, _⟩, h, heq⟩ => by cases heq; exact h⟩] rw [Finset.card_map, Finset.card_sigma] simp [H.col_card] omega /-- Every integer `d ∈ relHalfSet (n * k) t` appears as `|x|` for a unique filled cell of `H`. -/ lemma IntRelativeHeffterArray.mag_surj {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (d : ℕ) (hd : d ∈ relHalfSet (n * k) t) : ∃ i : Fin m, ∃ j : Fin n, ∃ x : ℤ, H.entry i j = some x ∧ x.natAbs = d := by let S := Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome) have hScard : S.card = n * k := by rw [show S = (Finset.univ.sigma (fun j : Fin n => Finset.univ.filter (fun i : Fin m => (H.entry i j).isSome))).map ⟨fun ⟨j, i⟩ => (i, j), fun ⟨_, _⟩ ⟨_, _⟩ h => by cases h; rfl⟩ by ext ⟨i, j⟩; simp only [S, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Finset.mem_sigma] exact ⟨fun h => ⟨⟨j, i⟩, h, rfl⟩, fun ⟨⟨_, _⟩, h, heq⟩ => by cases heq; exact h⟩] rw [Finset.card_map, Finset.card_sigma] simp [H.col_card] let f : Fin m × Fin n → ℕ := fun p => ((H.entry p.1 p.2).getD 0).natAbs have hsub : S.image f ⊆ relHalfSet (n * k) t := by intro y hy rcases Finset.mem_image.mp hy with ⟨⟨i, j⟩, hp, rfl⟩ have hsome : (H.entry i j).isSome := (Finset.mem_filter.mp hp).2 rcases Option.isSome_iff_exists.mp hsome with ⟨x, hx⟩ have hf : f (i, j) = x.natAbs := by simp [f, hx] rw [hf] have hnz : x ≠ 0 := H.nonzero i j x hx simp only [relHalfSet, Finset.mem_filter, Finset.mem_Icc] exact ⟨⟨by omega, H.mag_le i j x hx⟩, H.not_subgrp i j x hx⟩ have hinj : Set.InjOn f S := by intro ⟨i₁, j₁⟩ h₁ ⟨i₂, j₂⟩ h₂ heq rcases Option.isSome_iff_exists.mp (Finset.mem_filter.mp h₁).2 with ⟨x₁, hx₁⟩ rcases Option.isSome_iff_exists.mp (Finset.mem_filter.mp h₂).2 with ⟨x₂, hx₂⟩ have habs : x₁.natAbs = x₂.natAbs := by simpa [f, hx₁, hx₂] using heq rcases H.mag_inj i₁ j₁ i₂ j₂ x₁ x₂ hx₁ hx₂ habs with ⟨rfl, rfl⟩ rfl have hcard_eq : (S.image f).card = (relHalfSet (n * k) t).card := by rw [Finset.card_image_of_injOn hinj, hScard, relHalfSet_card (n * k) t H.ht_pos H.ht_div] have hEq : S.image f = relHalfSet (n * k) t := Finset.eq_of_subset_of_card_le hsub hcard_eq.ge have hdmem : d ∈ S.image f := hEq.symm ▸ hd rcases Finset.mem_image.mp hdmem with ⟨⟨i, j⟩, hp, hfd⟩ rcases Option.isSome_iff_exists.mp (Finset.mem_filter.mp hp).2 with ⟨x, hx⟩ exact ⟨i, j, x, hx, by simpa [f, hx] using hfd⟩ /-- **Necessary Admissibility Parity Theorem**: in any integer relative Heffter array `H_t(m, n; s, k)`, the sum of all magnitudes in `relHalfSet (n * k) t` is necessarily even. -/ theorem IntRelativeHeffterArray.even_halfSet_sum {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) : Even (∑ d ∈ relHalfSet (n * k) t, d) := by let S := Finset.univ.filter (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome) let f : Fin m × Fin n → ℕ := fun p => ((H.entry p.1 p.2).getD 0).natAbs have htotal : ∑ p ∈ S, (H.entry p.1 p.2).getD 0 = 0 := by have h1 : ∑ p ∈ S, (H.entry p.1 p.2).getD 0 = ∑ p : Fin m × Fin n, (H.entry p.1 p.2).getD 0 := by rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun p : Fin m × Fin n => (H.entry p.1 p.2).isSome)] have h0 : ∑ p ∈ Finset.univ.filter (fun p : Fin m × Fin n => ¬(H.entry p.1 p.2).isSome), (H.entry p.1 p.2).getD 0 = 0 := by apply Finset.sum_eq_zero; intro p hp have hnone : H.entry p.1 p.2 = none := Option.not_isSome_iff_eq_none.mp (Finset.mem_filter.mp hp).2 simp [hnone] dsimp only [S]; omega rw [h1, Fintype.sum_prod_type] simp [H.row_sum] have hbij : ∑ d ∈ relHalfSet (n * k) t, d = ∑ p ∈ S, f p := by have hScard : S.card = n * k := by rw [show S = (Finset.univ.sigma (fun j : Fin n => Finset.univ.filter (fun i : Fin m => (H.entry i j).isSome))).map ⟨fun ⟨j, i⟩ => (i, j), fun ⟨_, _⟩ ⟨_, _⟩ h => by cases h; rfl⟩ by ext ⟨i, j⟩; simp only [S, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Finset.mem_sigma] exact ⟨fun h => ⟨⟨j, i⟩, h, rfl⟩, fun ⟨⟨_, _⟩, h, heq⟩ => by cases heq; exact h⟩] rw [Finset.card_map, Finset.card_sigma] simp [H.col_card] have hsub : S.image f ⊆ relHalfSet (n * k) t := by intro y hy rcases Finset.mem_image.mp hy with ⟨⟨i, j⟩, hp, rfl⟩ rcases Option.isSome_iff_exists.mp (Finset.mem_filter.mp hp).2 with ⟨x, hx⟩ have hf : f (i, j) = x.natAbs := by simp [f, hx] rw [hf] have hnz := H.nonzero i j x hx simp only [relHalfSet, Finset.mem_filter, Finset.mem_Icc] exact ⟨⟨by omega, H.mag_le i j x hx⟩, H.not_subgrp i j x hx⟩ have hinj : Set.InjOn f S := by intro ⟨i₁, j₁⟩ h₁ ⟨i₂, j₂⟩ h₂ heq rcases Option.isSome_iff_exists.mp (Finset.mem_filter.mp h₁).2 with ⟨x₁, hx₁⟩ rcases Option.isSome_iff_exists.mp (Finset.mem_filter.mp h₂).2 with ⟨x₂, hx₂⟩ rcases H.mag_inj i₁ j₁ i₂ j₂ x₁ x₂ hx₁ hx₂ (by simpa [f, hx₁, hx₂] using heq) with ⟨rfl, rfl⟩ rfl have hEq : S.image f = relHalfSet (n * k) t := Finset.eq_of_subset_of_card_le hsub (by rw [Finset.card_image_of_injOn hinj, hScard, relHalfSet_card (n * k) t H.ht_pos H.ht_div]) rw [← hEq, Finset.sum_image hinj] have h2 : (2 : ℤ) ∣ ∑ p ∈ S, ((f p : ℤ) - (H.entry p.1 p.2).getD 0) := by apply Finset.dvd_sum intro p _ dsimp only [f] rcases Int.natAbs_eq ((H.entry p.1 p.2).getD 0) with hpos | hneg · exact ⟨0, by omega⟩ · exact ⟨((H.entry p.1 p.2).getD 0).natAbs, by omega⟩ rw [Finset.sum_sub_distrib, htotal, sub_zero] at h2 rw [hbij] rcases h2 with ⟨w, hw⟩ have hcast : ((∑ p ∈ S, f p : ℕ) : ℤ) = 2 * w := by rw [Nat.cast_sum]; exact hw have hw0 : 0 ≤ w := by omega refine ⟨w.toNat, ?_⟩ omega /-- Transpose of an integer relative Heffter array `H_t(m, n; s, k)` is `H_t(n, m; k, s)`. -/ def IntRelativeHeffterArray.transpose {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) : IntRelativeHeffterArray n m k s t where entry j i := H.entry i j ht_pos := H.ht_pos ht_div := by rw [H.mul_eq]; exact H.ht_div row_card := H.col_card col_card := H.row_card row_sum := H.col_sum col_sum := H.row_sum nonzero j i x h := H.nonzero i j x h mag_le j i x h := by rw [H.mul_eq]; exact H.mag_le i j x h not_subgrp j i x h := by rw [H.mul_eq]; exact H.not_subgrp i j x h mag_inj j₁ i₁ j₂ i₂ x₁ x₂ h₁ h₂ habs := by have := H.mag_inj i₁ j₁ i₂ j₂ x₁ x₂ h₁ h₂ habs exact ⟨this.2, this.1⟩ /-! ## 3. Ordered Row/Column Lists & Global Simplicity Modulo `2nk + t` -/ lemma length_filterMap_finRange {n : ℕ} {α : Type*} (f : Fin n → Option α) : ((List.finRange n).filterMap f).length = (Finset.univ.filter (fun j : Fin n => (f j).isSome)).card := by have hnodup : (List.finRange n).Nodup := List.nodup_finRange n have h1 : ((List.finRange n).filterMap f).length = ((List.finRange n).filter (fun j => (f j).isSome)).length := by clear hnodup induction (List.finRange n) with | nil => rfl | cons a l ih => simp only [List.filterMap_cons, List.filter_cons] cases hf : f a with | none => simp [ih] | some x => simp [ih] rw [h1] have h2 : ((List.finRange n).filter (fun j => (f j).isSome)).toFinset = Finset.univ.filter (fun j : Fin n => (f j).isSome) := by ext j; simp rw [← h2, List.toFinset_card_of_nodup (hnodup.filter _)] lemma sum_filterMap_finRange {n : ℕ} (f : Fin n → Option ℤ) : ((List.finRange n).filterMap f).sum = ∑ j : Fin n, (f j).getD 0 := by have hsum : ∀ l : List (Fin n), (l.filterMap f).sum = (l.map (fun j => (f j).getD 0)).sum := by intro l induction l with | nil => rfl | cons a t ih => simp only [List.filterMap_cons, List.map_cons, List.sum_cons] cases hf : f a with | none => simp [ih] | some x => simp [ih] rw [hsum, ← Fin.sum_univ_def] lemma nodup_map_natAbs_filterMap {α : Type*} {l : List α} (hl : l.Nodup) (f : α → Option ℤ) (hinj : ∀ a₁ a₂ x₁ x₂, f a₁ = some x₁ → f a₂ = some x₂ → x₁.natAbs = x₂.natAbs → a₁ = a₂) : ((l.filterMap f).map Int.natAbs).Nodup := by induction l with | nil => simp | cons a t ih => rw [List.nodup_cons] at hl simp only [List.filterMap_cons] cases hf : f a with | none => exact ih hl.2 | some x => simp only [List.map_cons, List.nodup_cons] refine ⟨?_, ih hl.2⟩ intro hmem simp only [List.mem_map, List.mem_filterMap] at hmem rcases hmem with ⟨y, ⟨b, hb, hfb⟩, hy⟩ have hab : a = b := hinj a b x y hf hfb hy.symm exact hl.1 (hab ▸ hb) /-- The filled entries of row `i` of `H`, listed left-to-right. -/ def rowFilled {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (i : Fin m) : List ℤ := (List.finRange n).filterMap (fun j => H.entry i j) /-- The filled entries of column `j` of `H`, listed top-to-bottom. -/ def colFilled {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (j : Fin n) : List ℤ := (List.finRange m).filterMap (fun i => H.entry i j) lemma rowFilled_length {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (i : Fin m) : (rowFilled H i).length = s := by rw [rowFilled, length_filterMap_finRange, H.row_card i] lemma colFilled_length {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (j : Fin n) : (colFilled H j).length = k := by rw [colFilled, length_filterMap_finRange, H.col_card j] lemma rowFilled_sum {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (i : Fin m) : (rowFilled H i).sum = 0 := by rw [rowFilled, sum_filterMap_finRange, H.row_sum i] lemma colFilled_sum {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (j : Fin n) : (colFilled H j).sum = 0 := by rw [colFilled, sum_filterMap_finRange, H.col_sum j] lemma rowFilled_mem_bounds {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (i : Fin m) {x : ℤ} (hx : x ∈ rowFilled H i) : 1 ≤ x.natAbs ∧ x.natAbs ≤ relHalfMax (n * k) t ∧ ¬ (relStep (n * k) t ∣ x.natAbs) := by simp only [rowFilled, List.mem_filterMap, List.mem_finRange, true_and] at hx rcases hx with ⟨j, hj⟩ have hnz := H.nonzero i j x hj exact ⟨by omega, H.mag_le i j x hj, H.not_subgrp i j x hj⟩ lemma colFilled_mem_bounds {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (j : Fin n) {x : ℤ} (hx : x ∈ colFilled H j) : 1 ≤ x.natAbs ∧ x.natAbs ≤ relHalfMax (n * k) t ∧ ¬ (relStep (n * k) t ∣ x.natAbs) := by simp only [colFilled, List.mem_filterMap, List.mem_finRange, true_and] at hx rcases hx with ⟨i, hi⟩ have hnz := H.nonzero i j x hi exact ⟨by omega, H.mag_le i j x hi, H.not_subgrp i j x hi⟩ lemma rowFilled_mag_nodup {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (i : Fin m) : ((rowFilled H i).map Int.natAbs).Nodup := nodup_map_natAbs_filterMap (List.nodup_finRange n) (fun j => H.entry i j) (fun j₁ j₂ x₁ x₂ h₁ h₂ habs => (H.mag_inj i j₁ i j₂ x₁ x₂ h₁ h₂ habs).2) lemma colFilled_mag_nodup {m n s k t : ℕ} (H : IntRelativeHeffterArray m n s k t) (j : Fin n) : ((colFilled H j).map Int.natAbs).Nodup := nodup_map_natAbs_filterMap (List.nodup_finRange m) (fun i => H.entry i j) (fun i₁ i₂ x₁ x₂ h₁ h₂ habs => (H.mag_inj i₁ j i₂ j x₁ x₂ h₁ h₂ habs).1) def partialSumsZMod (v : ℕ) (L : List ℤ) : List (ZMod v) := List.map (fun (x : ℤ) => (x : ZMod v)) (L.scanl (· + ·) (0 : ℤ)).tail /-- A list `L : List ℤ` is **simple modulo `v`** if its `L.length` nonempty prefix sums `P₁, …, P_L` are pairwise distinct in `ZMod v`. -/ def IsSimpleList (v : ℕ) (L : List ℤ) : Prop := (partialSumsZMod v L).Nodup /-- A **globally simple integer relative Heffter array** `SH_t(m, n; s, k)`: every row (left-to-right) and every column (top-to-bottom) has pairwise distinct partial sums in `ZMod (2 * (n * k) + t)`. -/ structure GloballySimpleRelativeHeffterArray (m n s k t : ℕ) extends IntRelativeHeffterArray m n s k t where row_simple : ∀ i : Fin m, IsSimpleList (2 * (n * k) + t) (rowFilled toIntRelativeHeffterArray i) col_simple : ∀ j : Fin n, IsSimpleList (2 * (n * k) + t) (colFilled toIntRelativeHeffterArray j) /-- Transpose preserves global simplicity (`SH_t(m, n; s, k)` yields `SH_t(n, m; k, s)`). -/ def GloballySimpleRelativeHeffterArray.transpose {m n s k t : ℕ} (H : GloballySimpleRelativeHeffterArray m n s k t) : GloballySimpleRelativeHeffterArray n m k s t where toIntRelativeHeffterArray := H.toIntRelativeHeffterArray.transpose row_simple j := by rw [H.mul_eq]; exact H.col_simple j col_simple i := by rw [H.mul_eq]; exact H.row_simple i /-- Dimension cast for globally simple relative Heffter arrays. -/ def GloballySimpleRelativeHeffterArray.cast {m₁ n₁ m₂ n₂ s k t : ℕ} (hm : m₁ = m₂) (hn : n₁ = n₂) (H : GloballySimpleRelativeHeffterArray m₁ n₁ s k t) : GloballySimpleRelativeHeffterArray m₂ n₂ s k t := by subst hm; subst hn; exact H /-! ## 4. Sub-Sum Characterization, Automatic `s, k ≤ 5`, and Length 6 / 7 Criteria (Arbitrary `v`) -/ lemma partialSumsZMod_length (v : ℕ) (L : List ℤ) : (partialSumsZMod v L).length = L.length := by simp [partialSumsZMod] lemma scanl_add_getElem (L : List ℤ) (a : ℤ) (i : ℕ) (hi : i ≤ L.length) : (L.scanl (· + ·) a)[i]'(by simp; omega) = a + (L.take i).sum := by induction L generalizing a i with | nil => have hi0 : i = 0 := by simpa using hi subst hi0; simp | cons x t ih => cases i with | zero => simp | succ i' => simp only [List.scanl_cons, List.getElem_cons_succ, List.take_succ_cons, List.sum_cons] rw [ih (a + x) i' (by simpa using hi)] ring lemma partialSumsZMod_getElem (v : ℕ) (L : List ℤ) (i : ℕ) (hi : i < L.length) : (partialSumsZMod v L)[i]'(by rw [partialSumsZMod_length]; exact hi) = (((L.take (i + 1)).sum : ℤ) : ZMod v) := by have h1 : (List.map (fun (x : ℤ) => (x : ZMod v)) (L.scanl (· + ·) (0 : ℤ)).tail)[i]'(by simp; omega) = (((L.scanl (· + ·) (0 : ℤ)).tail[i]'(by simp; omega) : ℤ) : ZMod v) := List.getElem_map (f := fun (x : ℤ) => (x : ZMod v)) exact h1.trans (by rw [List.getElem_tail, scanl_add_getElem L 0 (i + 1) hi, zero_add]) lemma sum_take_sub (L : List ℤ) {a b : ℕ} (hab : a ≤ b) : (L.take b).sum - (L.take a).sum = ((L.drop a).take (b - a)).sum := by have hsplit : L.take b = L.take a ++ (L.drop a).take (b - a) := by rw [← List.take_add, Nat.add_sub_cancel' hab] rw [hsplit, List.sum_append] ring /-- **Sub-Sum Characterization**: A list `L : List ℤ` with `L.sum = 0` is simple modulo `v` if and only if every proper nonempty contiguous sub-block `(L.drop a).take (b - a)` (`0 ≤ a < b ≤ L.length`, `(a, b) ≠ (0, L.length)`) has non-zero sum in `ZMod v`. -/ theorem isSimpleList_iff_subsum_ne_zero (v : ℕ) (L : List ℤ) (hsum : L.sum = 0) : IsSimpleList v L ↔ ∀ a b : ℕ, a < b → b ≤ L.length → ¬ (a = 0 ∧ b = L.length) → ((((L.drop a).take (b - a)).sum : ℤ) : ZMod v) ≠ 0 := by rw [IsSimpleList, List.nodup_iff_injective_getElem] constructor · intro hinj a b hab hb hne hzero cases a with | zero => have hbLt : b < L.length := by omega have hlen : (partialSumsZMod v L).length = L.length := partialSumsZMod_length v L have heq : (partialSumsZMod v L)[b - 1]'(by omega) = (partialSumsZMod v L)[L.length - 1]'(by omega) := by rw [partialSumsZMod_getElem v L (b - 1) (by omega), partialSumsZMod_getElem v L (L.length - 1) (by omega)] rw [Nat.sub_add_cancel (by omega : 1 ≤ b), Nat.sub_add_cancel (by omega : 1 ≤ L.length)] rw [List.take_length, hsum, Int.cast_zero] simpa using hzero have hidx := congrArg Fin.val (hinj (a₁ := ⟨b - 1, by omega⟩) (a₂ := ⟨L.length - 1, by omega⟩) heq) simp at hidx; omega | succ a' => have hlen : (partialSumsZMod v L).length = L.length := partialSumsZMod_length v L have heq : (partialSumsZMod v L)[a']'(by omega) = (partialSumsZMod v L)[b - 1]'(by omega) := by rw [partialSumsZMod_getElem v L a' (by omega), partialSumsZMod_getElem v L (b - 1) (by omega)] rw [Nat.sub_add_cancel (by omega : 1 ≤ b)] have hsub := sum_take_sub L (a := a' + 1) (b := b) (by omega) have hcast : (((L.take b).sum : ℤ) : ZMod v) - (((L.take (a' + 1)).sum : ℤ) : ZMod v) = 0 := by rw [← Int.cast_sub, hsub]; exact hzero exact (sub_eq_zero.mp hcast).symm have hidx := congrArg Fin.val (hinj (a₁ := ⟨a', by omega⟩) (a₂ := ⟨b - 1, by omega⟩) heq) simp at hidx; omega · intro hsub ⟨i, hi⟩ ⟨j, hj⟩ heq have hlen : (partialSumsZMod v L).length = L.length := partialSumsZMod_length v L have hiL : i < L.length := by omega have hjL : j < L.length := by omega ext; dsimp only by_contra hne wlog hlt : i < j generalizing i j · exact this j hj i hi heq.symm hjL hiL (Ne.symm hne) (by omega) dsimp only at heq rw [partialSumsZMod_getElem v L i hiL, partialSumsZMod_getElem v L j hjL] at heq have hdiff : ((((L.drop (i + 1)).take ((j + 1) - (i + 1))).sum : ℤ) : ZMod v) = 0 := by rw [← sum_take_sub L (by omega : i + 1 ≤ j + 1), Int.cast_sub, heq, sub_self] exact hsub (i + 1) (j + 1) (by omega) (by omega) (by omega) hdiff lemma int_cast_zmod_ne_zero_of_abs_lt {v : ℕ} {x : ℤ} (hx0 : x ≠ 0) (hxlt : x.natAbs < v) : (x : ZMod v) ≠ 0 := by intro h have hdvd : (v : ℤ) ∣ x := (ZMod.intCast_zmod_eq_zero_iff_dvd x v).mp h have hdvdNat : v ∣ x.natAbs := Int.natCast_dvd.mp hdvd have hle : v ≤ x.natAbs := Nat.le_of_dvd (Nat.pos_of_ne_zero (Int.natAbs_ne_zero.mpr hx0)) hdvdNat omega lemma int_cast_zmod_ne_zero_of_abs_lt_two_mul {v : ℕ} {x : ℤ} (hx0 : x ≠ 0) (hxp : x ≠ (v : ℤ)) (hxm : x ≠ -(v : ℤ)) (hxlt : x.natAbs < 2 * v) : (x : ZMod v) ≠ 0 := by intro h have hdvd : (v : ℤ) ∣ x := (ZMod.intCast_zmod_eq_zero_iff_dvd x v).mp h rcases hdvd with ⟨q, hq⟩ have hqabs : x.natAbs = v * q.natAbs := by rw [hq, Int.natAbs_mul, Int.natAbs_natCast] have hqlt : q.natAbs < 2 := by nlinarith have hqnat : q.natAbs = 0 ∨ q.natAbs = 1 := by omega rcases hqnat with h0 | h1 · have : q = 0 := Int.natAbs_eq_zero.mp h0 subst this; exact hx0 (by omega) · rcases Int.natAbs_eq q with hp | hn · rw [h1, Nat.cast_one] at hp; rw [hp, mul_one] at hq; exact hxp hq · rw [h1, Nat.cast_one] at hn; rw [hn, mul_neg_one] at hq; exact hxm hq lemma sum_one_ne_zero_mod_gen {v : ℕ} {a : ℤ} (ha1 : 1 ≤ a.natAbs) (ha2 : 2 * a.natAbs < v) : (a : ZMod v) ≠ 0 := int_cast_zmod_ne_zero_of_abs_lt (by omega) (by omega) lemma sum_two_ne_zero_mod_gen {v : ℕ} {a b : ℤ} (_ha1 : 1 ≤ a.natAbs) (ha2 : 2 * a.natAbs < v) (_hb1 : 1 ≤ b.natAbs) (hb2 : 2 * b.natAbs < v) (hdiff : a.natAbs ≠ b.natAbs) : ((a + b : ℤ) : ZMod v) ≠ 0 := by apply int_cast_zmod_ne_zero_of_abs_lt · intro h0; apply hdiff; have : a = -b := by omega rw [this, Int.natAbs_neg] · have : (a + b).natAbs ≤ a.natAbs + b.natAbs := Int.natAbs_add_le a b omega lemma sum_three_ne_zero_mod_gen {v : ℕ} {a b c : ℤ} (ha2 : 2 * a.natAbs < v) (hb2 : 2 * b.natAbs < v) (hc2 : 2 * c.natAbs < v) (h0 : a + b + c ≠ 0) (hp : a + b + c ≠ (v : ℤ)) (hm : a + b + c ≠ -(v : ℤ)) : ((a + b + c : ℤ) : ZMod v) ≠ 0 := by apply int_cast_zmod_ne_zero_of_abs_lt_two_mul h0 hp hm have h1 : (a + b + c).natAbs ≤ (a + b).natAbs + c.natAbs := Int.natAbs_add_le (a + b) c have h2 : (a + b).natAbs ≤ a.natAbs + b.natAbs := Int.natAbs_add_le a b omega /-- **General Automatic Simplicity for Length `≤ 5`**: for ANY modulus `v` and any zero-sum list of length `≤ 5` with pairwise distinct magnitudes satisfying `1 ≤ |x|` and `2 * |x| < v`, the list is automatically simple modulo `v`. -/ theorem isSimpleList_of_length_le_five_rel {v : ℕ} (L : List ℤ) (hlen : L.length ≤ 5) (hsum : L.sum = 0) (hbnd : ∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < v) (hnodup : (L.map Int.natAbs).Nodup) : IsSimpleList v L := by rw [isSimpleList_iff_subsum_ne_zero v L hsum] intro a b hab hb hne have hcomp : ((L.drop a).take (b - a)).sum = -((L.take a).sum + (L.drop b).sum) := by have hL : L = L.take a ++ (L.drop a).take (b - a) ++ L.drop b := by have h1 : L.take b = L.take a ++ (L.drop a).take (b - a) := by rw [← List.take_add, Nat.add_sub_cancel' (by omega : a ≤ b)] rw [← h1, List.take_append_drop] have hs := congrArg List.sum hL rw [hsum, List.sum_append, List.sum_append] at hs omega have hlen12 : ∀ (M : List ℤ), (M.length = 1 ∨ M.length = 2) → (∀ x ∈ M, 1 ≤ x.natAbs ∧ 2 * x.natAbs < v) → (M.map Int.natAbs).Nodup → ((M.sum : ℤ) : ZMod v) ≠ 0 := by intro M hMl hMb hMn rcases hMl with h1 | h2 · rcases List.length_eq_one_iff.mp h1 with ⟨x, rfl⟩ simp only [List.sum_cons, List.sum_nil, add_zero] have hx := hMb x (by simp) exact sum_one_ne_zero_mod_gen hx.1 hx.2 · rcases List.length_eq_two.mp h2 with ⟨x, y, rfl⟩ simp only [List.sum_cons, List.sum_nil, add_zero] have hx := hMb x (by simp) have hy := hMb y (by simp) have hxy : x.natAbs ≠ y.natAbs := by simp only [List.map_cons, List.map_nil, List.nodup_cons, List.mem_cons, List.not_mem_nil, or_false] at hMn exact hMn.1 exact sum_two_ne_zero_mod_gen hx.1 hx.2 hy.1 hy.2 hxy by_cases hsmall : b - a ≤ 2 · apply hlen12 ((L.drop a).take (b - a)) · simp only [List.length_take, List.length_drop]; omega · intro x hx; exact hbnd x (List.mem_of_mem_drop (List.mem_of_mem_take hx)) · have hsub : ((L.drop a).take (b - a)).Sublist L := (List.take_sublist (b - a) (L.drop a)).trans (List.drop_sublist a L) exact hnodup.sublist (hsub.map Int.natAbs) · let M := L.take a ++ L.drop b have hMsum : ((L.drop a).take (b - a)).sum = -M.sum := by rw [hcomp, List.sum_append] rw [hMsum, Int.cast_neg, neg_ne_zero] apply hlen12 M · simp only [M, List.length_append, List.length_take, List.length_drop]; omega · intro x hx simp only [M, List.mem_append] at hx rcases hx with hx1 | hx2 · exact hbnd x (List.mem_of_mem_take hx1) · exact hbnd x (List.mem_of_mem_drop hx2) · have hMsub : M.Sublist L := by have hL : L = L.take a ++ (L.drop a).take (b - a) ++ L.drop b := by have h1 : L.take b = L.take a ++ (L.drop a).take (b - a) := by rw [← List.take_add, Nat.add_sub_cancel' (by omega : a ≤ b)] rw [← h1, List.take_append_drop] conv_rhs => rw [hL] rw [List.append_assoc] exact List.Sublist.append_left (List.sublist_append_right _ _) _ exact hnodup.sublist (hMsub.map Int.natAbs) /-- Every integer relative Heffter array `H_t(m, n; s, k)` with `s ≤ 5` and `k ≤ 5` is automatically globally simple `SH_t(m, n; s, k)` (for every `t ≥ 1`). -/ def globallySimpleRel_of_le_five {m n s k t : ℕ} (hs : s ≤ 5) (hk : k ≤ 5) (H : IntRelativeHeffterArray m n s k t) : GloballySimpleRelativeHeffterArray m n s k t where toIntRelativeHeffterArray := H row_simple i := isSimpleList_of_length_le_five_rel (rowFilled H i) (by rw [rowFilled_length]; exact hs) (rowFilled_sum H i) (fun _ hx => ⟨(rowFilled_mem_bounds H i hx).1, two_mul_le_of_le_relHalfMax H.ht_pos (rowFilled_mem_bounds H i hx).2.1⟩) (rowFilled_mag_nodup H i) col_simple j := isSimpleList_of_length_le_five_rel (colFilled H j) (by rw [colFilled_length]; exact hk) (colFilled_sum H j) (fun _ hx => ⟨(colFilled_mem_bounds H j hx).1, two_mul_le_of_le_relHalfMax H.ht_pos (colFilled_mem_bounds H j hx).2.1⟩) (colFilled_mag_nodup H j) /-- **General Length-6 Simplicity Reduction** (arbitrary modulus `v`): a zero-sum 6-element list with pairwise distinct magnitudes satisfying `1 ≤ |x|` and `2 * |x| < v` is simple modulo `v` if its 3 contiguous length-3 sub-sums avoid `{0, ±v}`. -/ theorem isSimpleList_of_len_six_rel {v : ℕ} (x₀ x₁ x₂ x₃ x₄ x₅ : ℤ) (hsum : x₀ + x₁ + x₂ + x₃ + x₄ + x₅ = 0) (hbnd : ∀ x ∈ ([x₀, x₁, x₂, x₃, x₄, x₅] : List ℤ), 1 ≤ x.natAbs ∧ 2 * x.natAbs < v) (hnodup : (([x₀, x₁, x₂, x₃, x₄, x₅] : List ℤ).map Int.natAbs).Nodup) (h012 : x₀ + x₁ + x₂ ≠ 0 ∧ x₀ + x₁ + x₂ ≠ (v : ℤ) ∧ x₀ + x₁ + x₂ ≠ -(v : ℤ)) (h123 : x₁ + x₂ + x₃ ≠ 0 ∧ x₁ + x₂ + x₃ ≠ (v : ℤ) ∧ x₁ + x₂ + x₃ ≠ -(v : ℤ)) (h234 : x₂ + x₃ + x₄ ≠ 0 ∧ x₂ + x₃ + x₄ ≠ (v : ℤ) ∧ x₂ + x₃ + x₄ ≠ -(v : ℤ)) : IsSimpleList v [x₀, x₁, x₂, x₃, x₄, x₅] := by have hLsum : ([x₀, x₁, x₂, x₃, x₄, x₅] : List ℤ).sum = 0 := by simp; omega rw [isSimpleList_iff_subsum_ne_zero v _ hLsum] have b0 := hbnd x₀ (by simp); have b1 := hbnd x₁ (by simp); have b2 := hbnd x₂ (by simp) have b3 := hbnd x₃ (by simp); have b4 := hbnd x₄ (by simp); have b5 := hbnd x₅ (by simp) simp only [List.map_cons, List.map_nil, List.nodup_cons, List.mem_cons, List.not_mem_nil, or_false, not_or] at hnodup rcases hnodup with ⟨⟨n01, n02, n03, n04, n05⟩, ⟨n12, n13, n14, n15⟩, ⟨n23, n24, n25⟩, ⟨n34, n35⟩, n45, _⟩ intro a b hab hb hne simp only [List.length_cons, List.length_nil] at hb hne have ha_lt : a < 6 := by omega have hb_le : b ≤ 6 := hb interval_cases a <;> interval_cases b all_goals simp only [List.drop_succ_cons, List.drop_zero, List.take_succ_cons, List.take_zero, List.sum_cons, List.sum_nil, add_zero] · exact sum_one_ne_zero_mod_gen b0.1 b0.2 · exact sum_two_ne_zero_mod_gen b0.1 b0.2 b1.1 b1.2 n01 · rw [show x₀ + (x₁ + x₂) = x₀ + x₁ + x₂ by ring] exact sum_three_ne_zero_mod_gen b0.2 b1.2 b2.2 h012.1 h012.2.1 h012.2.2 · rw [show x₀ + (x₁ + (x₂ + x₃)) = -(x₄ + x₅) by omega, Int.cast_neg, neg_ne_zero] exact sum_two_ne_zero_mod_gen b4.1 b4.2 b5.1 b5.2 n45 · rw [show x₀ + (x₁ + (x₂ + (x₃ + x₄))) = -x₅ by omega, Int.cast_neg, neg_ne_zero] exact sum_one_ne_zero_mod_gen b5.1 b5.2 · exact absurd ⟨rfl, rfl⟩ hne · exact sum_one_ne_zero_mod_gen b1.1 b1.2 · exact sum_two_ne_zero_mod_gen b1.1 b1.2 b2.1 b2.2 n12 · rw [show x₁ + (x₂ + x₃) = x₁ + x₂ + x₃ by ring] exact sum_three_ne_zero_mod_gen b1.2 b2.2 b3.2 h123.1 h123.2.1 h123.2.2 · rw [show x₁ + (x₂ + (x₃ + x₄)) = -(x₀ + x₅) by omega, Int.cast_neg, neg_ne_zero] exact sum_two_ne_zero_mod_gen b0.1 b0.2 b5.1 b5.2 n05 · rw [show x₁ + (x₂ + (x₃ + (x₄ + x₅))) = -x₀ by omega, Int.cast_neg, neg_ne_zero] exact sum_one_ne_zero_mod_gen b0.1 b0.2 · exact sum_one_ne_zero_mod_gen b2.1 b2.2 · exact sum_two_ne_zero_mod_gen b2.1 b2.2 b3.1 b3.2 n23 · rw [show x₂ + (x₃ + x₄) = x₂ + x₃ + x₄ by ring] exact sum_three_ne_zero_mod_gen b2.2 b3.2 b4.2 h234.1 h234.2.1 h234.2.2 · rw [show x₂ + (x₃ + (x₄ + x₅)) = -(x₀ + x₁) by omega, Int.cast_neg, neg_ne_zero] exact sum_two_ne_zero_mod_gen b0.1 b0.2 b1.1 b1.2 n01 · exact sum_one_ne_zero_mod_gen b3.1 b3.2 · exact sum_two_ne_zero_mod_gen b3.1 b3.2 b4.1 b4.2 n34 · rw [show x₃ + (x₄ + x₅) = -(x₀ + x₁ + x₂) by omega, Int.cast_neg, neg_ne_zero] exact sum_three_ne_zero_mod_gen b0.2 b1.2 b2.2 h012.1 h012.2.1 h012.2.2 · exact sum_one_ne_zero_mod_gen b4.1 b4.2 · exact sum_two_ne_zero_mod_gen b4.1 b4.2 b5.1 b5.2 n45 · exact sum_one_ne_zero_mod_gen b5.1 b5.2 /-- **General Length-7 Simplicity Reduction** (arbitrary modulus `v`): a zero-sum 7-element list with pairwise distinct magnitudes satisfying `1 ≤ |x|` and `2 * |x| < v` is simple modulo `v` if its 7 non-trivial length-3 sub-sums avoid `{0, ±v}`. -/ theorem isSimpleList_of_len_seven_rel {v : ℕ} (x₀ x₁ x₂ x₃ x₄ x₅ x₆ : ℤ) (hsum : x₀ + x₁ + x₂ + x₃ + x₄ + x₅ + x₆ = 0) (hbnd : ∀ x ∈ ([x₀, x₁, x₂, x₃, x₄, x₅, x₆] : List ℤ), 1 ≤ x.natAbs ∧ 2 * x.natAbs < v) (hnodup : (([x₀, x₁, x₂, x₃, x₄, x₅, x₆] : List ℤ).map Int.natAbs).Nodup) (h012 : x₀ + x₁ + x₂ ≠ 0 ∧ x₀ + x₁ + x₂ ≠ (v : ℤ) ∧ x₀ + x₁ + x₂ ≠ -(v : ℤ)) (h123 : x₁ + x₂ + x₃ ≠ 0 ∧ x₁ + x₂ + x₃ ≠ (v : ℤ) ∧ x₁ + x₂ + x₃ ≠ -(v : ℤ)) (h234 : x₂ + x₃ + x₄ ≠ 0 ∧ x₂ + x₃ + x₄ ≠ (v : ℤ) ∧ x₂ + x₃ + x₄ ≠ -(v : ℤ)) (h345 : x₃ + x₄ + x₅ ≠ 0 ∧ x₃ + x₄ + x₅ ≠ (v : ℤ) ∧ x₃ + x₄ + x₅ ≠ -(v : ℤ)) (h456 : x₄ + x₅ + x₆ ≠ 0 ∧ x₄ + x₅ + x₆ ≠ (v : ℤ) ∧ x₄ + x₅ + x₆ ≠ -(v : ℤ)) (h056 : x₀ + x₅ + x₆ ≠ 0 ∧ x₀ + x₅ + x₆ ≠ (v : ℤ) ∧ x₀ + x₅ + x₆ ≠ -(v : ℤ)) (h016 : x₀ + x₁ + x₆ ≠ 0 ∧ x₀ + x₁ + x₆ ≠ (v : ℤ) ∧ x₀ + x₁ + x₆ ≠ -(v : ℤ)) : IsSimpleList v [x₀, x₁, x₂, x₃, x₄, x₅, x₆] := by have hLsum : ([x₀, x₁, x₂, x₃, x₄, x₅, x₆] : List ℤ).sum = 0 := by simp; omega rw [isSimpleList_iff_subsum_ne_zero v _ hLsum] have b0 := hbnd x₀ (by simp); have b1 := hbnd x₁ (by simp); have b2 := hbnd x₂ (by simp) have b3 := hbnd x₃ (by simp); have b4 := hbnd x₄ (by simp); have b5 := hbnd x₅ (by simp) have b6 := hbnd x₆ (by simp) simp only [List.map_cons, List.map_nil, List.nodup_cons, List.mem_cons, List.not_mem_nil, or_false, not_or] at hnodup rcases hnodup with ⟨⟨n01, n02, n03, n04, n05, n06⟩, ⟨n12, n13, n14, n15, n16⟩, ⟨n23, n24, n25, n26⟩, ⟨n34, n35, n36⟩, ⟨n45, n46⟩, n56, _⟩ intro a b hab hb hne simp only [List.length_cons, List.length_nil] at hb hne have ha_lt : a < 7 := by omega have hb_le : b ≤ 7 := hb interval_cases a <;> interval_cases b all_goals simp only [List.drop_succ_cons, List.drop_zero, List.take_succ_cons, List.take_zero, List.sum_cons, List.sum_nil, add_zero] · exact sum_one_ne_zero_mod_gen b0.1 b0.2 · exact sum_two_ne_zero_mod_gen b0.1 b0.2 b1.1 b1.2 n01 · rw [show x₀ + (x₁ + x₂) = x₀ + x₁ + x₂ by ring] exact sum_three_ne_zero_mod_gen b0.2 b1.2 b2.2 h012.1 h012.2.1 h012.2.2 · rw [show x₀ + (x₁ + (x₂ + x₃)) = -(x₄ + x₅ + x₆) by omega, Int.cast_neg, neg_ne_zero] exact sum_three_ne_zero_mod_gen b4.2 b5.2 b6.2 h456.1 h456.2.1 h456.2.2 · rw [show x₀ + (x₁ + (x₂ + (x₃ + x₄))) = -(x₅ + x₆) by omega, Int.cast_neg, neg_ne_zero] exact sum_two_ne_zero_mod_gen b5.1 b5.2 b6.1 b6.2 n56 · rw [show x₀ + (x₁ + (x₂ + (x₃ + (x₄ + x₅)))) = -x₆ by omega, Int.cast_neg, neg_ne_zero] exact sum_one_ne_zero_mod_gen b6.1 b6.2 · exact absurd ⟨rfl, rfl⟩ hne · exact sum_one_ne_zero_mod_gen b1.1 b1.2 · exact sum_two_ne_zero_mod_gen b1.1 b1.2 b2.1 b2.2 n12 · rw [show x₁ + (x₂ + x₃) = x₁ + x₂ + x₃ by ring] exact sum_three_ne_zero_mod_gen b1.2 b2.2 b3.2 h123.1 h123.2.1 h123.2.2 · rw [show x₁ + (x₂ + (x₃ + x₄)) = -(x₀ + x₅ + x₆) by omega, Int.cast_neg, neg_ne_zero] exact sum_three_ne_zero_mod_gen b0.2 b5.2 b6.2 h056.1 h056.2.1 h056.2.2 · rw [show x₁ + (x₂ + (x₃ + (x₄ + x₅))) = -(x₀ + x₆) by omega, Int.cast_neg, neg_ne_zero] exact sum_two_ne_zero_mod_gen b0.1 b0.2 b6.1 b6.2 n06 · rw [show x₁ + (x₂ + (x₃ + (x₄ + (x₅ + x₆)))) = -x₀ by omega, Int.cast_neg, neg_ne_zero] exact sum_one_ne_zero_mod_gen b0.1 b0.2 · exact sum_one_ne_zero_mod_gen b2.1 b2.2 · exact sum_two_ne_zero_mod_gen b2.1 b2.2 b3.1 b3.2 n23 · rw [show x₂ + (x₃ + x₄) = x₂ + x₃ + x₄ by ring] exact sum_three_ne_zero_mod_gen b2.2 b3.2 b4.2 h234.1 h234.2.1 h234.2.2 · rw [show x₂ + (x₃ + (x₄ + x₅)) = -(x₀ + x₁ + x₆) by omega, Int.cast_neg, neg_ne_zero] exact sum_three_ne_zero_mod_gen b0.2 b1.2 b6.2 h016.1 h016.2.1 h016.2.2 · rw [show x₂ + (x₃ + (x₄ + (x₅ + x₆))) = -(x₀ + x₁) by omega, Int.cast_neg, neg_ne_zero] exact sum_two_ne_zero_mod_gen b0.1 b0.2 b1.1 b1.2 n01 · exact sum_one_ne_zero_mod_gen b3.1 b3.2 · exact sum_two_ne_zero_mod_gen b3.1 b3.2 b4.1 b4.2 n34 · rw [show x₃ + (x₄ + x₅) = x₃ + x₄ + x₅ by ring] exact sum_three_ne_zero_mod_gen b3.2 b4.2 b5.2 h345.1 h345.2.1 h345.2.2 · rw [show x₃ + (x₄ + (x₅ + x₆)) = -(x₀ + x₁ + x₂) by omega, Int.cast_neg, neg_ne_zero] exact sum_three_ne_zero_mod_gen b0.2 b1.2 b2.2 h012.1 h012.2.1 h012.2.2 · exact sum_one_ne_zero_mod_gen b4.1 b4.2 · exact sum_two_ne_zero_mod_gen b4.1 b4.2 b5.1 b5.2 n45 · rw [show x₄ + (x₅ + x₆) = x₄ + x₅ + x₆ by ring] exact sum_three_ne_zero_mod_gen b4.2 b5.2 b6.2 h456.1 h456.2.1 h456.2.2 · exact sum_one_ne_zero_mod_gen b5.1 b5.2 · exact sum_two_ne_zero_mod_gen b5.1 b5.2 b6.1 b6.2 n56 · exact sum_one_ne_zero_mod_gen b6.1 b6.2 /-! ## 5. Complete Multipartite Graph `K_{((2nk+t)/t) × t}` Orthogonal Cyclic Cycle Decompositions -/ /-- A simple `L`-cycle in the complete graph on `ZMod v`, specified by `L` pairwise distinct vertices `verts : Fin L ↪ ZMod v`. -/ structure SimpleCycle (v L : ℕ) where verts : Fin L ↪ ZMod v /-- The set of `L` edges of a simple `L`-cycle (consecutive pairs modulo `L`), shifted by `g : ZMod v`. -/ def SimpleCycle.edgesShift {v L : ℕ} [NeZero L] (C : SimpleCycle v L) (g : ZMod v) : Finset (Sym2 (ZMod v)) := Finset.univ.image (fun t : Fin L => s(C.verts t + g, C.verts ⟨(t.val + 1) % L, Nat.mod_lt _ (NeZero.pos L)⟩ + g)) /-- An unordered pair `e = s(u, w)` is an edge of the **complete multipartite graph** `K_{(v/t) × t}` on vertex set `ZMod v` (whose independent parts are the `v / t` cosets of the order-`t` subgroup `J`) iff `t * (w - u) ≠ 0` in `ZMod v` (equivalently `u - w ∉ J`). -/ def IsMultipartiteEdge (v t : ℕ) (e : Sym2 (ZMod v)) : Prop := Sym2.lift ⟨fun u w => (t : ZMod v) * (w - u) ≠ 0, fun u w => by apply propext; dsimp only have : (t : ZMod v) * (u - w) = -((t : ZMod v) * (w - u)) := by ring rw [this, neg_ne_zero]⟩ e lemma isMultipartiteEdge_mk (v t : ℕ) (u w : ZMod v) : IsMultipartiteEdge v t s(u, w) ↔ (t : ZMod v) * (w - u) ≠ 0 := Iff.rfl lemma isMultipartiteEdge_not_isDiag {v t : ℕ} {e : Sym2 (ZMod v)} (he : IsMultipartiteEdge v t e) : ¬ e.IsDiag := by induction e using Sym2.ind with | _ u w => rw [Sym2.mk_isDiag_iff] intro h; subst h rw [isMultipartiteEdge_mk, sub_self, mul_zero] at he exact he rfl /-- A **cyclic `L`-cycle decomposition** of the complete multipartite graph `K_{(v/t) × t}` on `ZMod v` with `B` base cycles: every edge of every translated cycle lies in `K_{(v/t) × t}`, and every edge of `K_{(v/t) × t}` belongs to a **unique** translated cycle `base i + g`. -/ structure CyclicMultipartiteCycleDecomp (v t B L : ℕ) [NeZero L] where base : Fin B → SimpleCycle v L edge_in_graph : ∀ (i : Fin B) (g : ZMod v) (e : Sym2 (ZMod v)), e ∈ (base i).edgesShift g → IsMultipartiteEdge v t e partition : ∀ e : Sym2 (ZMod v), IsMultipartiteEdge v t e → ∃! p : Fin B × ZMod v, e ∈ (base p.1).edgesShift p.2 /-- Two cyclic cycle decompositions `D₁` (of `s`-cycles) and `D₂` (of `k`-cycles) of the complete multipartite graph `K_{(v/t) × t}` are **orthogonal** if every cycle of `D₁` shares **at most one edge** with every cycle of `D₂`. -/ def OrthogonalCyclicMultipartiteDecomps {v t m n s k : ℕ} [NeZero s] [NeZero k] (D₁ : CyclicMultipartiteCycleDecomp v t m s) (D₂ : CyclicMultipartiteCycleDecomp v t n k) : Prop := ∀ (i : Fin m) (a : ZMod v) (j : Fin n) (b : ZMod v), (((D₁.base i).edgesShift a) ∩ ((D₂.base j).edgesShift b)).card ≤ 1 /-- Construct a `SimpleCycle` from a simple zero-sum list `L` of length `ℓ`. -/ def simpleCycleOfList {v ℓ : ℕ} (L : List ℤ) (hlen : L.length = ℓ) (hsimp : IsSimpleList v L) : SimpleCycle v ℓ where verts := ⟨fun t => (partialSumsZMod v L)[t.val]'(by rw [partialSumsZMod_length, hlen]; exact t.isLt), by intro t₁ t₂ heq have hinj := List.nodup_iff_injective_getElem.mp hsimp have h := hinj (a₁ := ⟨t₁.val, by rw [partialSumsZMod_length, hlen]; exact t₁.isLt⟩) (a₂ := ⟨t₂.val, by rw [partialSumsZMod_length, hlen]; exact t₂.isLt⟩) heq exact Fin.ext (by simpa using congrArg Fin.val h)⟩ /-- Helper: consecutive step in `simpleCycleOfList` equals the next list element in `ZMod v`. -/ lemma simpleCycleOfList_step {v ℓ : ℕ} [NeZero ℓ] (L : List ℤ) (hlen : L.length = ℓ) (hsum : L.sum = 0) (hsimp : IsSimpleList v L) (t : Fin ℓ) : (simpleCycleOfList L hlen hsimp).verts ⟨(t.val + 1) % ℓ, Nat.mod_lt _ (NeZero.pos ℓ)⟩ - (simpleCycleOfList L hlen hsimp).verts t = ((L[(t.val + 1) % ℓ]'(by rw [hlen]; exact Nat.mod_lt _ (NeZero.pos ℓ)) : ℤ) : ZMod v) := by change (partialSumsZMod v L)[(t.val + 1) % ℓ]'(by rw [partialSumsZMod_length, hlen]; exact Nat.mod_lt _ (NeZero.pos ℓ)) - (partialSumsZMod v L)[t.val]'(by rw [partialSumsZMod_length, hlen]; exact t.isLt) = _ rw [partialSumsZMod_getElem v L ((t.val + 1) % ℓ) (by rw [hlen]; exact Nat.mod_lt _ (NeZero.pos ℓ)), partialSumsZMod_getElem v L t.val (by rw [hlen]; exact t.isLt)] by_cases hlast : t.val + 1 < ℓ · have hmod : (t.val + 1) % ℓ = t.val + 1 := Nat.mod_eq_of_lt hlast simp only [hmod] have htake : L.take (t.val + 1 + 1) = L.take (t.val + 1) ++ [L[t.val + 1]'(by omega)] := by rw [List.take_add_one, List.getElem?_eq_getElem (by omega : t.val + 1 < L.length)] rfl rw [htake, List.sum_append, List.sum_singleton, Int.cast_add] ring · have htEq : t.val + 1 = ℓ := by omega simp only [htEq, Nat.mod_self, zero_add] have htakeL : L.take ℓ = L := by rw [← hlen, List.take_length] rw [htakeL, hsum, Int.cast_zero, sub_zero] have h1 : L.take 1 = [L[0]'(by omega)] := by cases L with | nil => simp at hlen; exact absurd hlen.symm (NeZero.ne ℓ) | cons x xs => simp rw [h1, List.sum_singleton] lemma mul_t_ne_zero_of_not_dvd_relStep {N t : ℕ} (ht : 0 < t) (hdiv : t ∣ 2 * N) {x : ℤ} (hx_not : ¬ (relStep N t ∣ x.natAbs)) : (t : ZMod (2 * N + t)) * (x : ZMod (2 * N + t)) ≠ 0 := by intro h0 have hcast : ((t * x : ℤ) : ZMod (2 * N + t)) = 0 := by push_cast; exact h0 have hdvdZ : ((2 * N + t : ℕ) : ℤ) ∣ (t * x : ℤ) := (ZMod.intCast_zmod_eq_zero_iff_dvd (t * x) (2 * N + t)).mp hcast have hdvdN : (2 * N + t) ∣ (t * x).natAbs := Int.natCast_dvd.mp hdvdZ rw [Int.natAbs_mul, Int.natAbs_natCast, ← relStep_mul N t ht hdiv] at hdvdN exact hx_not ((Nat.mul_dvd_mul_iff_left ht).mp hdvdN) /-- Every non-subgroup element `u : ZMod (2N + t)` (`t * u ≠ 0`) equals `±(d : ZMod (2N + t))` for a **unique** `d ∈ relHalfSet N t`. -/ lemma zmod_rel_diff_unique {N t : ℕ} (ht : 0 < t) (hdiv : t ∣ 2 * N) (u : ZMod (2 * N + t)) (hu : (t : ZMod (2 * N + t)) * u ≠ 0) : ∃! d : ℕ, d ∈ relHalfSet N t ∧ (u = (d : ZMod (2 * N + t)) ∨ u = -(d : ZMod (2 * N + t))) := by have : NeZero (2 * N + t) := ⟨by omega⟩ have hval_lt : u.val < 2 * N + t := ZMod.val_lt u have hq_mul : t * relStep N t = 2 * N + t := relStep_mul N t ht hdiv have hnot_q : ¬ (relStep N t ∣ u.val) := by rintro ⟨a, ha⟩ apply hu have hcast : ((t * u.val : ℕ) : ZMod (2 * N + t)) = 0 := by rw [ha, show t * (relStep N t * a) = (t * relStep N t) * a by ring, hq_mul] simp simpa [Nat.cast_mul, ZMod.natCast_zmod_val] using hcast have hval_pos : 0 < u.val := by by_contra h0; have : u.val = 0 := by omega exact hnot_q ⟨0, by omega⟩ have hne_half : 2 * u.val ≠ 2 * N + t := by intro heq have ht_even : 2 ∣ t := by omega rcases ht_even with ⟨r, rfl⟩ have hr : u.val = r * relStep N (2 * r) := by have : 2 * u.val = 2 * (r * relStep N (2 * r)) := by rw [heq, ← hq_mul]; ring omega exact hnot_q ⟨r, by rw [hr, mul_comm]⟩ have hcast : ((u.val : ℕ) : ZMod (2 * N + t)) = u := ZMod.natCast_zmod_val u by_cases hlt : 2 * u.val < 2 * N + t · refine ⟨u.val, ⟨Finset.mem_filter.mpr ⟨Finset.mem_Icc.mpr ⟨hval_pos, le_relHalfMax_of_two_mul_lt ht hlt⟩, hnot_q⟩, Or.inl hcast.symm⟩, ?_⟩ rintro d ⟨hdmem, h1 | h2⟩ · have hd_lt : d < 2 * N + t := by have := two_mul_le_of_le_relHalfMax ht (Finset.mem_Icc.mp (Finset.mem_filter.mp hdmem).1).2 omega have := congrArg ZMod.val h1 rw [ZMod.val_natCast_of_lt hd_lt] at this; exact this.symm · have hd2 := two_mul_le_of_le_relHalfMax ht (Finset.mem_Icc.mp (Finset.mem_filter.mp hdmem).1).2 have hsum : u + (d : ZMod (2 * N + t)) = 0 := by rw [h2]; ring have hcast2 : (((u.val + d : ℕ) : ZMod (2 * N + t))) = 0 := by push_cast; rw [hcast]; exact hsum have hdvd : (2 * N + t) ∣ (u.val + d) := (ZMod.natCast_eq_zero_iff _ _).mp hcast2 have hge := Nat.le_of_dvd (by omega) hdvd omega · let d₀ := 2 * N + t - u.val have hd₀_2lt : 2 * d₀ < 2 * N + t := by omega have hd₀_pos : 1 ≤ d₀ := by omega have hd₀_not_q : ¬ (relStep N t ∣ d₀) := by rintro ⟨a, ha⟩ apply hnot_q have : relStep N t ∣ (2 * N + t) := ⟨t, by rw [← hq_mul, mul_comm]⟩ have hsub : u.val = (2 * N + t) - d₀ := by omega rw [hsub] exact Nat.dvd_sub this ⟨a, ha⟩ have hneg : u = -(d₀ : ZMod (2 * N + t)) := by have hadd : u + (d₀ : ZMod (2 * N + t)) = 0 := by rw [← hcast, ← Nat.cast_add, show u.val + d₀ = 2 * N + t by omega] exact ZMod.natCast_self (2 * N + t) exact eq_neg_of_add_eq_zero_left hadd refine ⟨d₀, ⟨Finset.mem_filter.mpr ⟨Finset.mem_Icc.mpr ⟨hd₀_pos, le_relHalfMax_of_two_mul_lt ht hd₀_2lt⟩, hd₀_not_q⟩, Or.inr hneg⟩, ?_⟩ rintro d ⟨hdmem, h1 | h2⟩ · have hd2 := two_mul_le_of_le_relHalfMax ht (Finset.mem_Icc.mp (Finset.mem_filter.mp hdmem).1).2 have := congrArg ZMod.val h1 rw [ZMod.val_natCast_of_lt (by omega : d < 2 * N + t)] at this omega · have hd2 := two_mul_le_of_le_relHalfMax ht (Finset.mem_Icc.mp (Finset.mem_filter.mp hdmem).1).2 have heq : (d : ZMod (2 * N + t)) = (d₀ : ZMod (2 * N + t)) := neg_inj.mp (h2.symm.trans hneg) have := congrArg ZMod.val heq rw [ZMod.val_natCast_of_lt (by omega : d < 2 * N + t), ZMod.val_natCast_of_lt (by omega : d₀ < 2 * N + t)] at this exact this /-- For `x, y : ℤ` with `1 ≤ |x|, |y|` and `2 * |x|, 2 * |y| < v`, `x ≡ ±y (mod v)` implies `|x| = |y|`. -/ lemma int_abs_eq_of_zmod_eq_or_neg_gen {v : ℕ} {x y : ℤ} (hx1 : 1 ≤ x.natAbs) (hx2 : 2 * x.natAbs < v) (hy1 : 1 ≤ y.natAbs) (hy2 : 2 * y.natAbs < v) (h : (x : ZMod v) = (y : ZMod v) ∨ (x : ZMod v) = -(y : ZMod v)) : x.natAbs = y.natAbs := by have hcast : ∀ z : ℤ, (z : ZMod v) = (z.natAbs : ZMod v) ∨ (z : ZMod v) = -(z.natAbs : ZMod v) := by intro z; rcases Int.natAbs_eq z with hp | hn · left; conv_lhs => rw [hp]; simp only [Int.cast_natCast] · right; conv_lhs => rw [hn]; simp only [Int.cast_neg, Int.cast_natCast] have hcases : (x.natAbs : ZMod v) = (y.natAbs : ZMod v) ∨ (x.natAbs : ZMod v) = -(y.natAbs : ZMod v) := by rcases hcast x with hx' | hx' <;> rcases hcast y with hy' | hy' <;> rcases h with h1 | h2 · left; rw [← hx', h1, hy'] · right; rw [← hx', h2, hy'] · right; rw [← hx', h1, hy'] · left; rw [← hx', h2, hy', neg_neg] · right; exact neg_eq_iff_eq_neg.mp (hx'.symm.trans (h1.trans hy')) · left; exact neg_inj.mp (hx'.symm.trans (h2.trans (congrArg Neg.neg hy'))) · left; exact neg_inj.mp (hx'.symm.trans (h1.trans hy')) · right; exact neg_eq_iff_eq_neg.mp (hx'.symm.trans (h2.trans (by rw [hy', neg_neg]))) have : NeZero v := ⟨by omega⟩ rcases hcases with heq | hneg · have := congrArg ZMod.val heq rw [ZMod.val_natCast_of_lt (by omega : x.natAbs < v), ZMod.val_natCast_of_lt (by omega : y.natAbs < v)] at this exact this · have hsum : ((x.natAbs + y.natAbs : ℕ) : ZMod v) = 0 := by push_cast; rw [hneg]; ring have hdvd : v ∣ (x.natAbs + y.natAbs) := (ZMod.natCast_eq_zero_iff _ _).mp hsum have hge := Nat.le_of_dvd (by omega) hdvd omega /-- Helper: given `Sym2` equality `s(a, b) = s(c, d)` in an additive group, the differences `b - a` and `d - c` agree up to sign. -/ lemma sym2_eq_diff_or_neg {G : Type*} [AddCommGroup G] {a b c d : G} (h : s(a, b) = s(c, d)) : b - a = d - c ∨ b - a = -(d - c) := by rcases Sym2.eq_iff.mp h with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ · left; rfl · right; abel /-- General `Sym2` shift uniqueness (works for BOTH odd and even modulus `v`!): if `2 * (b - a) ≠ 0` in `ZMod v`, then `s(a + g₁, b + g₁) = s(a + g₂, b + g₂)` forces `g₁ = g₂`. -/ lemma sym2_shift_unique_gen {v : ℕ} {a b g₁ g₂ u w : ZMod v} (h2step : (2 : ZMod v) * (b - a) ≠ 0) (h1 : s(a + g₁, b + g₁) = s(u, w)) (h2 : s(a + g₂, b + g₂) = s(u, w)) : g₁ = g₂ := by have heq : s(a + g₁, b + g₁) = s(a + g₂, b + g₂) := h1.trans h2.symm rcases Sym2.eq_iff.mp heq with ⟨ha, _⟩ | ⟨hab, hba⟩ · exact add_left_cancel ha · apply absurd _ h2step have : (b + g₁) - (a + g₁) = (a + g₂) - (b + g₂) := by rw [hab, hba] have hsub : b - a = -(b - a) := by calc b - a = (b + g₁) - (a + g₁) := by ring _ = (a + g₂) - (b + g₂) := this _ = -(b - a) := by ring calc (2 : ZMod v) * (b - a) = (b - a) + (b - a) := by ring _ = (b - a) + -(b - a) := by nth_rw 2 [hsub] _ = 0 := add_neg_cancel _ /-- Build the cyclic `s`-cycle decomposition of the complete multipartite graph `K_{((2nk + t)/t) × t}` from the rows of `SH_t(m, n; s, k)`. -/ def GloballySimpleRelativeHeffterArray.rowCycleDecomp {m n s k t : ℕ} [NeZero s] (H : GloballySimpleRelativeHeffterArray m n s k t) : CyclicMultipartiteCycleDecomp (2 * (n * k) + t) t m s where base i := simpleCycleOfList (rowFilled H.toIntRelativeHeffterArray i) (rowFilled_length H.toIntRelativeHeffterArray i) (H.row_simple i) edge_in_graph i g e he := by simp only [SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] at he rcases he with ⟨idx, rfl⟩ rw [isMultipartiteEdge_mk, add_sub_add_right_eq_sub] rw [simpleCycleOfList_step (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i) (rowFilled_length _ i) (rowFilled_sum _ i) (H.row_simple i) idx] have hmem : (rowFilled H.toIntRelativeHeffterArray i)[(idx.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) ∈ rowFilled H.toIntRelativeHeffterArray i := List.getElem_mem _ have hb := rowFilled_mem_bounds H.toIntRelativeHeffterArray i hmem exact mul_t_ne_zero_of_not_dvd_relStep H.ht_pos H.ht_div hb.2.2 partition e he := by induction e using Sym2.ind with | _ u w => rw [isMultipartiteEdge_mk] at he obtain ⟨d, ⟨hdmem, hdiff⟩, _⟩ := zmod_rel_diff_unique H.ht_pos H.ht_div (w - u) he obtain ⟨i₀, j₀, x₀, hx₀, hxabs⟩ := H.mag_surj d hdmem have hx_mem : x₀ ∈ rowFilled H.toIntRelativeHeffterArray i₀ := by simp only [rowFilled, List.mem_filterMap, List.mem_finRange, true_and] exact ⟨j₀, hx₀⟩ obtain ⟨idx, hidx_lt, hidx_eq⟩ := List.mem_iff_getElem.mp hx_mem have hlen_i₀ : (rowFilled H.toIntRelativeHeffterArray i₀).length = s := rowFilled_length _ i₀ let t₀ : Fin s := ⟨(idx + s - 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ have ht₀_next : (t₀.val + 1) % s = idx := by have hidx_s : idx < s := by omega dsimp only [t₀] cases idx with | zero => have hs1 : 1 ≤ s := NeZero.pos s rw [Nat.zero_add, Nat.mod_eq_of_lt (by omega : s - 1 < s), Nat.sub_add_cancel hs1, Nat.mod_self] | succ k' => rw [show k' + 1 + s - 1 = k' + s by omega, Nat.add_mod_right, Nat.mod_eq_of_lt (by omega : k' < s), Nat.mod_eq_of_lt hidx_s] let C₀ := simpleCycleOfList (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i₀) (rowFilled_length _ i₀) (H.row_simple i₀) have hstep₀ : C₀.verts ⟨(t₀.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ - C₀.verts t₀ = (x₀ : ZMod (2 * (n * k) + t)) := by rw [simpleCycleOfList_step _ _ (rowFilled_sum _ i₀)] congr 1; simp only [ht₀_next]; exact hidx_eq have hwu_x₀ : w - u = (x₀ : ZMod (2 * (n * k) + t)) ∨ w - u = -(x₀ : ZMod (2 * (n * k) + t)) := by rcases Int.natAbs_eq x₀ with hpos | hneg <;> rcases hdiff with h1 | h2 · left; rw [h1, ← hxabs]; conv_rhs => rw [hpos]; simp only [Int.cast_natCast] · right; rw [h2, ← hxabs]; conv_rhs => rw [hpos]; simp only [Int.cast_natCast] · right; rw [h1, ← hxabs]; conv_rhs => rw [hneg]; simp only [Int.cast_neg, Int.cast_natCast, neg_neg] · left; rw [h2, ← hxabs]; conv_rhs => rw [hneg]; simp only [Int.cast_neg, Int.cast_natCast] have hex_g : ∃ g₀ : ZMod (2 * (n * k) + t), s(u, w) ∈ C₀.edgesShift g₀ := by rcases hwu_x₀ with hpos | hneg · refine ⟨u - C₀.verts t₀, ?_⟩ simp only [SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] refine ⟨t₀, ?_⟩ rw [Sym2.eq_iff]; left refine ⟨by ring, ?_⟩ have : C₀.verts ⟨(t₀.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ - C₀.verts t₀ = w - u := hstep₀.trans hpos.symm calc C₀.verts ⟨(t₀.val + 1) % s, _⟩ + (u - C₀.verts t₀) = (C₀.verts ⟨(t₀.val + 1) % s, _⟩ - C₀.verts t₀) + u := by ring _ = (w - u) + u := by rw [this] _ = w := by ring · refine ⟨w - C₀.verts t₀, ?_⟩ simp only [SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] refine ⟨t₀, ?_⟩ rw [Sym2.eq_iff]; right refine ⟨by ring, ?_⟩ have : C₀.verts ⟨(t₀.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ - C₀.verts t₀ = u - w := by rw [hstep₀]; calc (x₀ : ZMod (2 * (n * k) + t)) = -(w - u) := by rw [hneg, neg_neg] _ = u - w := by ring calc C₀.verts ⟨(t₀.val + 1) % s, _⟩ + (w - C₀.verts t₀) = (C₀.verts ⟨(t₀.val + 1) % s, _⟩ - C₀.verts t₀) + w := by ring _ = (u - w) + w := by rw [this] _ = u := by ring rcases hex_g with ⟨g₀, hg₀⟩ refine ⟨(i₀, g₀), hg₀, ?_⟩ rintro ⟨i₁, g₁⟩ hmem₁ simp only [SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] at hmem₁ rcases hmem₁ with ⟨t₁, ht₁⟩ have hdiff₁ := sym2_eq_diff_or_neg ht₁ let C₁ := simpleCycleOfList (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i₁) (rowFilled_length _ i₁) (H.row_simple i₁) have hstep₁ := simpleCycleOfList_step (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i₁) (rowFilled_length _ i₁) (rowFilled_sum _ i₁) (H.row_simple i₁) t₁ let x₁ := (rowFilled H.toIntRelativeHeffterArray i₁)[(t₁.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) have hstep₁' : (C₁.verts ⟨(t₁.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ + g₁) - (C₁.verts t₁ + g₁) = (x₁ : ZMod (2 * (n * k) + t)) := by rw [add_sub_add_right_eq_sub]; exact hstep₁ rw [hstep₁'] at hdiff₁ have hx₁_mem : x₁ ∈ rowFilled H.toIntRelativeHeffterArray i₁ := List.getElem_mem _ have hb₁ := rowFilled_mem_bounds H.toIntRelativeHeffterArray i₁ hx₁_mem have hb₀ := rowFilled_mem_bounds H.toIntRelativeHeffterArray i₀ hx_mem have hx₁_eq_x₀ : (x₁ : ZMod (2 * (n * k) + t)) = (x₀ : ZMod (2 * (n * k) + t)) ∨ (x₁ : ZMod (2 * (n * k) + t)) = -(x₀ : ZMod (2 * (n * k) + t)) := by rcases hdiff₁ with hd1' | hd2' <;> rcases hwu_x₀ with hp | hn · left; exact hd1'.trans hp · right; exact hd1'.trans hn · right; rw [hd2', hp] · left; rw [hd2', hn, neg_neg] have habs_eq : x₁.natAbs = x₀.natAbs := int_abs_eq_of_zmod_eq_or_neg_gen hb₁.1 (two_mul_le_of_le_relHalfMax H.ht_pos hb₁.2.1) hb₀.1 (two_mul_le_of_le_relHalfMax H.ht_pos hb₀.2.1) hx₁_eq_x₀ simp only [rowFilled, List.mem_filterMap, List.mem_finRange, true_and] at hx₁_mem rcases hx₁_mem with ⟨j₁, hj₁⟩ have hij : i₀ = i₁ ∧ j₀ = j₁ := H.mag_inj i₀ j₀ i₁ j₁ x₀ x₁ hx₀ hj₁ habs_eq.symm rcases hij with ⟨rfl, rfl⟩ have ht_eq : t₁ = t₀ := by have hinj_nod := List.nodup_iff_injective_getElem.mp (rowFilled_mag_nodup H.toIntRelativeHeffterArray i₀) have hidx_eq' : ((t₁.val + 1) % s) = ((t₀.val + 1) % s) := by have hget : ((rowFilled H.toIntRelativeHeffterArray i₀).map Int.natAbs)[(t₁.val + 1) % s]'(by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) = ((rowFilled H.toIntRelativeHeffterArray i₀).map Int.natAbs)[(t₀.val + 1) % s]'(by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) := by simp only [List.getElem_map] have hx0_at : (rowFilled H.toIntRelativeHeffterArray i₀)[(t₀.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) = x₀ := by simp only [ht₀_next]; exact hidx_eq rw [hx0_at]; exact habs_eq exact congrArg Fin.val (hinj_nod (a₁ := ⟨(t₁.val + 1) % s, by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)⟩) (a₂ := ⟨(t₀.val + 1) % s, by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)⟩) hget) ext have ht1l := t₁.isLt; have ht0l := t₀.isLt by_cases h1 : t₁.val + 1 < s <;> by_cases h2 : t₀.val + 1 < s · rw [Nat.mod_eq_of_lt h1, Nat.mod_eq_of_lt h2] at hidx_eq'; omega · have : t₀.val + 1 = s := by omega rw [Nat.mod_eq_of_lt h1, this, Nat.mod_self] at hidx_eq'; omega · have : t₁.val + 1 = s := by omega rw [this, Nat.mod_self, Nat.mod_eq_of_lt h2] at hidx_eq'; omega · omega subst ht_eq simp only [SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] at hg₀ rcases hg₀ with ⟨t₀', ht₀'⟩ have ht₀'_eq : t₀' = t₀ := by have hdiff₀' := sym2_eq_diff_or_neg ht₀' have hstep₀' := simpleCycleOfList_step (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i₀) (rowFilled_length _ i₀) (rowFilled_sum _ i₀) (H.row_simple i₀) t₀' let x₀' := (rowFilled H.toIntRelativeHeffterArray i₀)[(t₀'.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) have hstep₀'' : (C₀.verts ⟨(t₀'.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ + g₀) - (C₀.verts t₀' + g₀) = (x₀' : ZMod (2 * (n * k) + t)) := by rw [add_sub_add_right_eq_sub]; exact hstep₀' rw [hstep₀''] at hdiff₀' have hx₀'_mem : x₀' ∈ rowFilled H.toIntRelativeHeffterArray i₀ := List.getElem_mem _ have hb₀' := rowFilled_mem_bounds H.toIntRelativeHeffterArray i₀ hx₀'_mem have hx₀'_eq : (x₀' : ZMod (2 * (n * k) + t)) = (x₀ : ZMod (2 * (n * k) + t)) ∨ (x₀' : ZMod (2 * (n * k) + t)) = -(x₀ : ZMod (2 * (n * k) + t)) := by rcases hdiff₀' with hd1' | hd2' <;> rcases hwu_x₀ with hp | hn · left; exact hd1'.trans hp · right; exact hd1'.trans hn · right; rw [hd2', hp] · left; rw [hd2', hn, neg_neg] have habs' := int_abs_eq_of_zmod_eq_or_neg_gen hb₀'.1 (two_mul_le_of_le_relHalfMax H.ht_pos hb₀'.2.1) hb₀.1 (two_mul_le_of_le_relHalfMax H.ht_pos hb₀.2.1) hx₀'_eq have hinj_nod := List.nodup_iff_injective_getElem.mp (rowFilled_mag_nodup H.toIntRelativeHeffterArray i₀) have hidx_eq' : ((t₀'.val + 1) % s) = ((t₀.val + 1) % s) := by have hget : ((rowFilled H.toIntRelativeHeffterArray i₀).map Int.natAbs)[(t₀'.val + 1) % s]'(by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) = ((rowFilled H.toIntRelativeHeffterArray i₀).map Int.natAbs)[(t₀.val + 1) % s]'(by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) := by simp only [List.getElem_map] have hx0_at : (rowFilled H.toIntRelativeHeffterArray i₀)[(t₀.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) = x₀ := by simp only [ht₀_next]; exact hidx_eq rw [hx0_at]; exact habs' exact congrArg Fin.val (hinj_nod (a₁ := ⟨(t₀'.val + 1) % s, by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)⟩) (a₂ := ⟨(t₀.val + 1) % s, by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)⟩) hget) ext have h1l := t₀'.isLt; have h0l := t₀.isLt by_cases h1 : t₀'.val + 1 < s <;> by_cases h2 : t₀.val + 1 < s · rw [Nat.mod_eq_of_lt h1, Nat.mod_eq_of_lt h2] at hidx_eq'; omega · have : t₀.val + 1 = s := by omega rw [Nat.mod_eq_of_lt h1, this, Nat.mod_self] at hidx_eq'; omega · have : t₀'.val + 1 = s := by omega rw [this, Nat.mod_self, Nat.mod_eq_of_lt h2] at hidx_eq'; omega · omega subst ht₀'_eq have h2step_nz : (2 : ZMod (2 * (n * k) + t)) * (C₀.verts ⟨(t₀.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ - C₀.verts t₀) ≠ 0 := by rw [hstep₀] have hcast2 : (2 : ZMod (2 * (n * k) + t)) * (x₀ : ZMod (2 * (n * k) + t)) = ((2 * x₀ : ℤ) : ZMod (2 * (n * k) + t)) := by push_cast; rfl rw [hcast2] apply int_cast_zmod_ne_zero_of_abs_lt · have := hb₀.1; omega · have h2x := two_mul_le_of_le_relHalfMax H.ht_pos hb₀.2.1 rw [Int.natAbs_mul]; simpa using h2x have hg_eq : g₁ = g₀ := sym2_shift_unique_gen h2step_nz ht₁ ht₀' exact Prod.ext rfl hg_eq /-- Cast a `CyclicMultipartiteCycleDecomp` along a vertex-count equality. -/ def CyclicMultipartiteCycleDecomp.cast {v₁ v₂ t B L : ℕ} [NeZero L] (hv : v₁ = v₂) (D : CyclicMultipartiteCycleDecomp v₁ t B L) : CyclicMultipartiteCycleDecomp v₂ t B L := by subst hv; exact D /-- Build the cyclic `k`-cycle decomposition of `K_{((2nk + t)/t) × t}` from the columns of `H`. -/ def GloballySimpleRelativeHeffterArray.colCycleDecomp {m n s k t : ℕ} [NeZero k] (H : GloballySimpleRelativeHeffterArray m n s k t) : CyclicMultipartiteCycleDecomp (2 * (n * k) + t) t n k := CyclicMultipartiteCycleDecomp.cast (congrArg (fun x => 2 * x + t) H.mul_eq) H.transpose.rowCycleDecomp lemma colCycleDecomp_base_eq {m n s k t : ℕ} [NeZero k] (H : GloballySimpleRelativeHeffterArray m n s k t) (j : Fin n) : H.colCycleDecomp.base j = simpleCycleOfList (v := 2 * (n * k) + t) (colFilled H.toIntRelativeHeffterArray j) (colFilled_length _ j) (H.col_simple j) := by have aux : ∀ (v : ℕ) (hv : 2 * (m * s) + t = v) (hsimple : ∀ j : Fin n, IsSimpleList v (colFilled H.toIntRelativeHeffterArray j)), (CyclicMultipartiteCycleDecomp.cast hv H.transpose.rowCycleDecomp).base j = simpleCycleOfList (v := v) (colFilled H.toIntRelativeHeffterArray j) (colFilled_length _ j) (hsimple j) := by intro v hv hsimple; subst hv simp only [CyclicMultipartiteCycleDecomp.cast, GloballySimpleRelativeHeffterArray.rowCycleDecomp, GloballySimpleRelativeHeffterArray.transpose, IntRelativeHeffterArray.transpose, rowFilled, colFilled] exact aux (2 * (n * k) + t) (congrArg (fun x => 2 * x + t) H.mul_eq) H.col_simple /-- **Costa–Pasotti–Pellegrini (2020) Fundamental Multipartite Decomposition Theorem**: Every globally simple integer relative Heffter array `SH_t(m, n; s, k)` yields a pair of **orthogonal cyclic** `s`-cycle and `k`-cycle decompositions of the complete multipartite graph `K_{((2nk + t)/t) × t}`. -/ theorem GloballySimpleRelativeHeffterArray.toOrthogonalCyclicMultipartiteDecomps {m n s k t : ℕ} [NeZero s] [NeZero k] (H : GloballySimpleRelativeHeffterArray m n s k t) : OrthogonalCyclicMultipartiteDecomps H.rowCycleDecomp H.colCycleDecomp := by intro i a j b rw [Finset.card_le_one_iff] intro e₁ e₂ he₁ he₂ rw [Finset.mem_inter] at he₁ he₂ rcases he₁ with ⟨he₁R, he₁C⟩ rcases he₂ with ⟨he₂R, he₂C⟩ simp only [rowCycleDecomp, SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] at he₁R he₂R rcases he₁R with ⟨t₁, rfl⟩ rcases he₂R with ⟨t₂, rfl⟩ rw [colCycleDecomp_base_eq] at he₁C he₂C simp only [SimpleCycle.edgesShift, Finset.mem_image, Finset.mem_univ, true_and] at he₁C he₂C rcases he₁C with ⟨c₁, hc₁⟩ rcases he₂C with ⟨c₂, hc₂⟩ have hcell : ∀ (idx : Fin s) (c : Fin k), s((simpleCycleOfList (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i) (rowFilled_length _ i) (H.row_simple i)).verts idx + a, (simpleCycleOfList (v := 2 * (n * k) + t) (rowFilled H.toIntRelativeHeffterArray i) (rowFilled_length _ i) (H.row_simple i)).verts ⟨(idx.val + 1) % s, Nat.mod_lt _ (NeZero.pos s)⟩ + a) = s((simpleCycleOfList (v := 2 * (n * k) + t) (colFilled H.toIntRelativeHeffterArray j) (colFilled_length _ j) (H.col_simple j)).verts c + b, (simpleCycleOfList (v := 2 * (n * k) + t) (colFilled H.toIntRelativeHeffterArray j) (colFilled_length _ j) (H.col_simple j)).verts ⟨(c.val + 1) % k, Nat.mod_lt _ (NeZero.pos k)⟩ + b) → H.entry i j = some ((rowFilled H.toIntRelativeHeffterArray i)[(idx.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s))) := by intro idx c heq have hdiff := sym2_eq_diff_or_neg heq rw [add_sub_add_right_eq_sub, add_sub_add_right_eq_sub] at hdiff rw [simpleCycleOfList_step _ _ (rowFilled_sum _ i), simpleCycleOfList_step _ _ (colFilled_sum _ j)] at hdiff let xr := (rowFilled H.toIntRelativeHeffterArray i)[(idx.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) let xc := (colFilled H.toIntRelativeHeffterArray j)[(c.val + 1) % k]'(by rw [colFilled_length]; exact Nat.mod_lt _ (NeZero.pos k)) have hxr_mem : xr ∈ rowFilled H.toIntRelativeHeffterArray i := List.getElem_mem _ have hxc_mem : xc ∈ colFilled H.toIntRelativeHeffterArray j := List.getElem_mem _ have hbr := rowFilled_mem_bounds H.toIntRelativeHeffterArray i hxr_mem have hbc := colFilled_mem_bounds H.toIntRelativeHeffterArray j hxc_mem have habs : xr.natAbs = xc.natAbs := int_abs_eq_of_zmod_eq_or_neg_gen hbr.1 (two_mul_le_of_le_relHalfMax H.ht_pos hbr.2.1) hbc.1 (two_mul_le_of_le_relHalfMax H.ht_pos hbc.2.1) hdiff simp only [rowFilled, List.mem_filterMap, List.mem_finRange, true_and] at hxr_mem simp only [colFilled, List.mem_filterMap, List.mem_finRange, true_and] at hxc_mem rcases hxr_mem with ⟨j', hj'⟩ rcases hxc_mem with ⟨i', hi'⟩ rcases H.mag_inj i j' i' j xr xc hj' hi' habs with ⟨_, rfl⟩ exact hj' have h1 := hcell t₁ c₁ hc₁.symm have h2 := hcell t₂ c₂ hc₂.symm have hval_eq : (rowFilled H.toIntRelativeHeffterArray i)[(t₁.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) = (rowFilled H.toIntRelativeHeffterArray i)[(t₂.val + 1) % s]'(by rw [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) := Option.some.inj (h1.symm.trans h2) have hinj_nod := List.nodup_iff_injective_getElem.mp (rowFilled_mag_nodup H.toIntRelativeHeffterArray i) have hidx_eq : (t₁.val + 1) % s = (t₂.val + 1) % s := by have hget : ((rowFilled H.toIntRelativeHeffterArray i).map Int.natAbs)[(t₁.val + 1) % s]'(by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) = ((rowFilled H.toIntRelativeHeffterArray i).map Int.natAbs)[(t₂.val + 1) % s]'(by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)) := by simp only [List.getElem_map]; exact congrArg Int.natAbs hval_eq exact congrArg Fin.val (hinj_nod (a₁ := ⟨(t₁.val + 1) % s, by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)⟩) (a₂ := ⟨(t₂.val + 1) % s, by simp [rowFilled_length]; exact Nat.mod_lt _ (NeZero.pos s)⟩) hget) have ht_eq : t₁ = t₂ := by ext have h1l := t₁.isLt; have h2l := t₂.isLt by_cases ha1 : t₁.val + 1 < s <;> by_cases ha2 : t₂.val + 1 < s · rw [Nat.mod_eq_of_lt ha1, Nat.mod_eq_of_lt ha2] at hidx_eq; omega · have : t₂.val + 1 = s := by omega rw [Nat.mod_eq_of_lt ha1, this, Nat.mod_self] at hidx_eq; omega · have : t₁.val + 1 = s := by omega rw [this, Nat.mod_self, Nat.mod_eq_of_lt ha2] at hidx_eq; omega · omega subst ht_eq; rfl /-! ## 6. Sparse Block-Diagonal Seam + Uniform-Block Relative Assembly -/ /-- Slot placement function: maps `(r, c)` to `some e` iff `rowOf c e = r`. -/ def slotOfPlacement {m n k : ℕ} (rowOf : Fin n → Fin k → Fin m) (r : Fin m) (c : Fin n) : Option (Fin k) := (List.finRange k).find? (fun e => decide (rowOf c e = r)) lemma slotOfPlacement_eq_some_iff {m n k : ℕ} (rowOf : Fin n → Fin k → Fin m) (hinj : ∀ c, Function.Injective (rowOf c)) (r : Fin m) (c : Fin n) (e : Fin k) : slotOfPlacement rowOf r c = some e ↔ rowOf c e = r := by constructor · intro h have hpred := List.find?_some (p := fun e' => decide (rowOf c e' = r)) h exact of_decide_eq_true hpred · intro h have hex : ∃ e' ∈ List.finRange k, decide (rowOf c e' = r) = true := ⟨e, List.mem_finRange e, decide_eq_true h⟩ rcases List.find?_isSome.mpr hex |> Option.isSome_iff_exists.mp with ⟨e', he'⟩ have hpred : rowOf c e' = r := of_decide_eq_true (List.find?_some (p := fun e'' => decide (rowOf c e'' = r)) he') have : e' = e := hinj c (hpred.trans h.symm) rw [← this]; exact he' lemma slotOfPlacement_map_getD {m n k : ℕ} (rowOf : Fin n → Fin k → Fin m) (hinj : ∀ c, Function.Injective (rowOf c)) (r : Fin m) (c : Fin n) (f : Fin k → ℤ) : ((slotOfPlacement rowOf r c).map f).getD 0 = ∑ e : Fin k, if rowOf c e = r then f e else 0 := by by_cases hex : ∃ e : Fin k, rowOf c e = r · rcases hex with ⟨e₀, he₀⟩ have hslot : slotOfPlacement rowOf r c = some e₀ := (slotOfPlacement_eq_some_iff rowOf hinj r c e₀).mpr he₀ rw [hslot, Option.map_some, Option.getD_some, Finset.sum_eq_single e₀] · simp [he₀] · intro e _ hne have : rowOf c e ≠ r := fun h => hne (hinj c (h.trans he₀.symm)) simp [this] · intro h; exact absurd (Finset.mem_univ e₀) h · push Not at hex have hnone : slotOfPlacement rowOf r c = none := by cases hs : slotOfPlacement rowOf r c with | none => rfl | some e => exact absurd ((slotOfPlacement_eq_some_iff rowOf hinj r c e).mp hs) (hex e) rw [hnone, Option.map_none, Option.getD_none] symm exact Finset.sum_eq_zero (fun e _ => by simp [hex e]) lemma sparse_col_card {m n k : ℕ} (slot : Fin m → Fin n → Option (Fin k)) (huniq : ∀ c e, ∃! r : Fin m, slot r c = some e) (c : Fin n) (f : Fin k → ℤ) : (Finset.univ.filter (fun r : Fin m => ((slot r c).map f).isSome)).card = k := by have hbij : (Finset.univ.filter (fun r : Fin m => ((slot r c).map f).isSome)).card = (Finset.univ : Finset (Fin k)).card := by refine Finset.card_bij (fun r hr => (Option.isSome_iff_exists.mp (by have := (Finset.mem_filter.mp hr).2 simpa using this)).choose) ?_ ?_ ?_ · intro r _; exact Finset.mem_univ _ · intro r₁ hr₁ r₂ hr₂ heq have h1 := (Option.isSome_iff_exists.mp (by simpa using (Finset.mem_filter.mp hr₁).2)).choose_spec have h2 := (Option.isSome_iff_exists.mp (by simpa using (Finset.mem_filter.mp hr₂).2)).choose_spec rw [heq] at h1 exact ((huniq c _).unique h1 h2) · intro e _ obtain ⟨r, hr, _⟩ := huniq c e refine ⟨r, Finset.mem_filter.mpr ⟨Finset.mem_univ r, by simp [hr]⟩, ?_⟩ have hspec := (Option.isSome_iff_exists.mp (by simp [hr] : (slot r c).isSome)).choose_spec exact Option.some.inj (hspec.symm.trans hr) simpa using hbij lemma sparse_col_sum {m n k : ℕ} (slot : Fin m → Fin n → Option (Fin k)) (huniq : ∀ c e, ∃! r : Fin m, slot r c = some e) (c : Fin n) (f : Fin k → ℤ) : ∑ r : Fin m, ((slot r c).map f).getD 0 = ∑ e : Fin k, f e := by have h1 : ∑ r : Fin m, ((slot r c).map f).getD 0 = ∑ r ∈ Finset.univ.filter (fun r : Fin m => (slot r c).isSome), ((slot r c).map f).getD 0 := by rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun r : Fin m => (slot r c).isSome)] have h0 : ∑ r ∈ Finset.univ.filter (fun r : Fin m => ¬ (slot r c).isSome), ((slot r c).map f).getD 0 = 0 := by apply Finset.sum_eq_zero; intro r hr have hnone : slot r c = none := Option.not_isSome_iff_eq_none.mp (Finset.mem_filter.mp hr).2 simp [hnone] omega rw [h1] refine Finset.sum_bij (fun r hr => (Option.isSome_iff_exists.mp (Finset.mem_filter.mp hr).2).choose) ?_ ?_ ?_ ?_ · intro r _; exact Finset.mem_univ _ · intro r₁ hr₁ r₂ hr₂ heq have h1' := (Option.isSome_iff_exists.mp (Finset.mem_filter.mp hr₁).2).choose_spec have h2' := (Option.isSome_iff_exists.mp (Finset.mem_filter.mp hr₂).2).choose_spec rw [heq] at h1' exact (huniq c _).unique h1' h2' · intro e _ obtain ⟨r, hr, _⟩ := huniq c e refine ⟨r, Finset.mem_filter.mpr ⟨Finset.mem_univ r, by simp [hr]⟩, ?_⟩ have hspec := (Option.isSome_iff_exists.mp (by simp [hr] : (slot r c).isSome)).choose_spec exact Option.some.inj (hspec.symm.trans hr) · intro r hr obtain ⟨e, he⟩ := Option.isSome_iff_exists.mp (Finset.mem_filter.mp hr).2 have hspec := (Option.isSome_iff_exists.mp (Finset.mem_filter.mp hr).2).choose_spec have hch : (Option.isSome_iff_exists.mp (Finset.mem_filter.mp hr).2).choose = e := Option.some.inj (hspec.symm.trans he) conv_lhs => rw [he] simp only [Option.map_some, Option.getD_some] exact congrArg f hch.symm /-- Helper: `filterMap` over `finRange (a + b)` splits into `finRange a` and shifted `finRange b`. -/ lemma filterMap_finRange_add {a b : ℕ} {α : Type*} (f : Fin (a + b) → Option α) : (List.finRange (a + b)).filterMap f = (List.finRange a).filterMap (fun i => f ⟨i.val, by omega⟩) ++ (List.finRange b).filterMap (fun j => f ⟨a + j.val, by omega⟩) := by have hsplit : List.finRange (a + b) = (List.finRange a).map (fun i => ⟨i.val, by omega⟩) ++ (List.finRange b).map (fun j => ⟨a + j.val, by omega⟩) := by apply List.ext_getElem · simp · intro idx h1 h2 have hidx : idx < a + b := by simpa using h1 simp only [List.getElem_finRange] by_cases hlt : idx < a · rw [List.getElem_append_left (by simp; exact hlt)] simp · rw [List.getElem_append_right (by simp; omega)] simp only [List.length_map, List.length_finRange, List.getElem_map, List.getElem_finRange, Fin.val_cast] exact Fin.ext (by simp only [Fin.val_cast]; omega) rw [hsplit, List.filterMap_append, List.filterMap_map, List.filterMap_map] rfl lemma filterMap_finRange_none {n : ℕ} {α : Type*} (f : Fin n → Option α) (hnone : ∀ i : Fin n, f i = none) : (List.finRange n).filterMap f = [] := by rw [List.filterMap_eq_nil_iff] intro i _; exact hnone i lemma filterMap_finRange_mul_block {m₁ B : ℕ} {α : Type*} (b₀ : Fin B) (f : Fin (m₁ * B) → Option α) (hzero : ∀ j : Fin (m₁ * B), j.val / m₁ ≠ b₀.val → f j = none) (hm₁ : 0 < m₁) : (List.finRange (m₁ * B)).filterMap f = (List.finRange m₁).filterMap (fun c => f ⟨m₁ * b₀.val + c.val, by have := b₀.isLt; have := c.isLt; nlinarith⟩) := by have hdecomp : m₁ * B = (m₁ * b₀.val + m₁) + (m₁ * (B - b₀.val - 1)) := by have := b₀.isLt have : B = b₀.val + 1 + (B - b₀.val - 1) := by omega conv_lhs => rw [this] ring have h1 : ∀ (n : ℕ) (h : n = m₁ * B) (g : Fin n → Option α), (List.finRange n).filterMap g = (List.finRange (m₁ * B)).filterMap (fun j => g ⟨j.val, by omega⟩) := by intro n h g; subst h; rfl rw [← h1 ((m₁ * b₀.val + m₁) + m₁ * (B - b₀.val - 1)) hdecomp.symm (fun j => f ⟨j.val, by omega⟩)] rw [filterMap_finRange_add, filterMap_finRange_add] have hleft : (List.finRange (m₁ * b₀.val)).filterMap (fun i => f ⟨i.val, by omega⟩) = [] := by apply filterMap_finRange_none intro i; apply hzero dsimp only have hi := i.isLt have hdiv : i.val / m₁ < b₀.val := Nat.div_lt_of_lt_mul (by linarith) omega have hright : (List.finRange (m₁ * (B - b₀.val - 1))).filterMap (fun j => f ⟨m₁ * b₀.val + m₁ + j.val, by omega⟩) = [] := by apply filterMap_finRange_none intro j; apply hzero dsimp only have hdiv : b₀.val + 1 ≤ (m₁ * b₀.val + m₁ + j.val) / m₁ := (Nat.le_div_iff_mul_le hm₁).mpr (by nlinarith) omega rw [hleft, hright, List.nil_append, List.append_nil] noncomputable def ofSeamAndUniformBlocksRelSimple {ι : Type*} {m₀ n₀ m₁ n₁ B s k t : ℕ} (ht_pos : 0 < t) (ht_div : t ∣ 2 * ((n₀ + n₁ * B) * k)) (A : Fin k → ι → ℤ) (seamCol : Fin n₀ → ι) (seamSgn : Fin n₀ → ℤ) (seamSlot : Fin m₀ → Fin n₀ → Option (Fin k)) (blkCol : Fin B → Fin n₁ → ι) (blkSgn : Fin B → Fin n₁ → ℤ) (blkSlot : Fin B → Fin m₁ → Fin n₁ → Option (Fin k)) (hm₁ : 0 < m₁) (hn₁ : 0 < n₁) (hA_col : ∀ x, ∑ e : Fin k, A e x = 0) (hA_nz : ∀ e x, A e x ≠ 0) (hA_le : ∀ e x, (A e x).natAbs ≤ relHalfMax ((n₀ + n₁ * B) * k) t) (hA_nsub : ∀ e x, ¬ (relStep ((n₀ + n₁ * B) * k) t ∣ (A e x).natAbs)) (hA_inj : ∀ e₁ x₁ e₂ x₂, (A e₁ x₁).natAbs = (A e₂ x₂).natAbs → e₁ = e₂ ∧ x₁ = x₂) (hsSgn : ∀ c, (seamSgn c).natAbs = 1) (hbSgn : ∀ b c, (blkSgn b c).natAbs = 1) (hseam_rc : ∀ r, (Finset.univ.filter (fun c => (seamSlot r c).isSome)).card = s) (hseam_cu : ∀ c e, ∃! r : Fin m₀, seamSlot r c = some e) (hseam_rs : ∀ r, ∑ c : Fin n₀, ((seamSlot r c).map (fun e => seamSgn c * A e (seamCol c))).getD 0 = 0) (hblk_rc : ∀ b r, (Finset.univ.filter (fun c => (blkSlot b r c).isSome)).card = s) (hblk_cu : ∀ b c e, ∃! r : Fin m₁, blkSlot b r c = some e) (hblk_rs : ∀ b r, ∑ c : Fin n₁, ((blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))).getD 0 = 0) (hseam_inj : Function.Injective seamCol) (hblk_inj : ∀ b₁ c₁ b₂ c₂, blkCol b₁ c₁ = blkCol b₂ c₂ → b₁ = b₂ ∧ c₁ = c₂) (hdisj : ∀ c₀ b c₁, seamCol c₀ ≠ blkCol b c₁) (hseam_rsimp : ∀ r : Fin m₀, let L := (List.finRange n₀).filterMap (fun c => (seamSlot r c).map (fun e => seamSgn c * A e (seamCol c))) L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * ((n₀ + n₁ * B) * k) + t) L) (hblk_rsimp : ∀ (b : Fin B) (r : Fin m₁), let L := (List.finRange n₁).filterMap (fun c => (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))) L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * ((n₀ + n₁ * B) * k) + t) L) (hseam_csimp : ∀ c : Fin n₀, let L := (List.finRange m₀).filterMap (fun r => (seamSlot r c).map (fun e => seamSgn c * A e (seamCol c))) L.length = k → L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * ((n₀ + n₁ * B) * k) + t) L) (hblk_csimp : ∀ (b : Fin B) (c : Fin n₁), let L := (List.finRange m₁).filterMap (fun r => (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))) L.length = k → L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * ((n₀ + n₁ * B) * k) + t) L) : GloballySimpleRelativeHeffterArray (m₀ + m₁ * B) (n₀ + n₁ * B) s k t := by let entry : Fin (m₀ + m₁ * B) → Fin (n₀ + n₁ * B) → Option ℤ := fun i j => if hi : i.val < m₀ then if hj : j.val < n₀ then (seamSlot ⟨i.val, hi⟩ ⟨j.val, hj⟩).map (fun e => seamSgn ⟨j.val, hj⟩ * A e (seamCol ⟨j.val, hj⟩)) else none else if hj : j.val < n₀ then none else if hbm : (i.val - m₀) / m₁ = (j.val - n₀) / n₁ then have hbB : (i.val - m₀) / m₁ < B := Nat.div_lt_of_lt_mul (by have := i.isLt; omega) let b : Fin B := ⟨(i.val - m₀) / m₁, hbB⟩ let r : Fin m₁ := ⟨(i.val - m₀) % m₁, Nat.mod_lt _ hm₁⟩ let c : Fin n₁ := ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩ (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c)) else none let H : IntRelativeHeffterArray (m₀ + m₁ * B) (n₀ + n₁ * B) s k t := { entry := entry ht_pos := ht_pos ht_div := ht_div row_card := fun i => by by_cases hi : i.val < m₀ · have hbij : (Finset.univ.filter (fun j : Fin (n₀ + n₁ * B) => (entry i j).isSome)).card = (Finset.univ.filter (fun c : Fin n₀ => (seamSlot ⟨i.val, hi⟩ c).isSome)).card := by refine Finset.card_bij (fun j hj => ⟨j.val, by have h := (Finset.mem_filter.mp hj).2 by_contra hge simp only [entry, dif_pos hi, dif_neg hge] at h simp at h⟩) ?_ ?_ ?_ · intro j hj have h := (Finset.mem_filter.mp hj).2 have hjlt : j.val < n₀ := by by_contra hge; simp only [entry, dif_pos hi, dif_neg hge] at h; simp at h simp only [entry, dif_pos hi, dif_pos hjlt] at h exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, by simpa using h⟩ · intro j₁ _ j₂ _ heq; exact Fin.ext (by simpa using congrArg Fin.val heq) · intro c hc refine ⟨⟨c.val, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, rfl⟩ simp only [entry, dif_pos hi, dif_pos c.isLt] simpa using (Finset.mem_filter.mp hc).2 rw [hbij, hseam_rc] · have hbB : (i.val - m₀) / m₁ < B := Nat.div_lt_of_lt_mul (by have := i.isLt; omega) let b : Fin B := ⟨(i.val - m₀) / m₁, hbB⟩ let r : Fin m₁ := ⟨(i.val - m₀) % m₁, Nat.mod_lt _ hm₁⟩ have hbij : (Finset.univ.filter (fun j : Fin (n₀ + n₁ * B) => (entry i j).isSome)).card = (Finset.univ.filter (fun c : Fin n₁ => (blkSlot b r c).isSome)).card := by refine Finset.card_bij (fun j _ => ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩) ?_ ?_ ?_ · intro j hj have h := (Finset.mem_filter.mp hj).2 have hjge : ¬ (j.val < n₀) := by intro hlt; simp only [entry, dif_neg hi, dif_pos hlt] at h; simp at h have hbm : (i.val - m₀) / m₁ = (j.val - n₀) / n₁ := by by_contra hne; simp only [entry, dif_neg hi, dif_neg hjge, dif_neg hne] at h; simp at h simp only [entry, dif_neg hi, dif_neg hjge, dif_pos hbm] at h exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, by simpa [b, r] using h⟩ · intro j₁ hj₁ j₂ hj₂ heq have h1 := (Finset.mem_filter.mp hj₁).2 have h2 := (Finset.mem_filter.mp hj₂).2 have hj1ge : ¬ (j₁.val < n₀) := by intro hlt; simp only [entry, dif_neg hi, dif_pos hlt] at h1; simp at h1 have hj2ge : ¬ (j₂.val < n₀) := by intro hlt; simp only [entry, dif_neg hi, dif_pos hlt] at h2; simp at h2 have hbm1 : (i.val - m₀) / m₁ = (j₁.val - n₀) / n₁ := by by_contra hne; simp only [entry, dif_neg hi, dif_neg hj1ge, dif_neg hne] at h1; simp at h1 have hbm2 : (i.val - m₀) / m₁ = (j₂.val - n₀) / n₁ := by by_contra hne; simp only [entry, dif_neg hi, dif_neg hj2ge, dif_neg hne] at h2; simp at h2 have hmod : (j₁.val - n₀) % n₁ = (j₂.val - n₀) % n₁ := congrArg Fin.val heq have hdiv : (j₁.val - n₀) / n₁ = (j₂.val - n₀) / n₁ := by omega have hd1 := Nat.div_add_mod (j₁.val - n₀) n₁ have hd2 := Nat.div_add_mod (j₂.val - n₀) n₁ rw [hdiv, hmod] at hd1 exact Fin.ext (by omega) · intro c hc let jval := n₀ + n₁ * b.val + c.val have hjlt : jval < n₀ + n₁ * B := by have := b.isLt; have := c.isLt; dsimp only [jval]; nlinarith have hjge : ¬ (jval < n₀) := by dsimp only [jval]; omega have hdiv : (jval - n₀) / n₁ = b.val := by rw [show jval - n₀ = c.val + n₁ * b.val by dsimp only [jval]; omega] rw [Nat.add_mul_div_left _ _ hn₁, Nat.div_eq_of_lt c.isLt, zero_add] have hmod : (jval - n₀) % n₁ = c.val := by rw [show jval - n₀ = c.val + n₁ * b.val by dsimp only [jval]; omega] rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt c.isLt] refine ⟨⟨jval, hjlt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, Fin.ext hmod⟩ have hbm : (i.val - m₀) / m₁ = (jval - n₀) / n₁ := hdiv.symm simp only [entry, dif_neg hi, dif_neg hjge, dif_pos hbm] have hceq : (⟨(jval - n₀) % n₁, Nat.mod_lt _ hn₁⟩ : Fin n₁) = c := Fin.ext hmod rw [hceq] simpa [b, r] using (Finset.mem_filter.mp hc).2 rw [hbij, hblk_rc] col_card := fun j => by by_cases hj : j.val < n₀ · have hbij : (Finset.univ.filter (fun i : Fin (m₀ + m₁ * B) => (entry i j).isSome)).card = (Finset.univ.filter (fun r : Fin m₀ => ((seamSlot r ⟨j.val, hj⟩).map (fun e => seamSgn ⟨j.val, hj⟩ * A e (seamCol ⟨j.val, hj⟩))).isSome)).card := by refine Finset.card_bij (fun i hi' => ⟨i.val, by have h := (Finset.mem_filter.mp hi').2 by_contra hge; simp only [entry, dif_neg hge, dif_pos hj] at h; simp at h⟩) ?_ ?_ ?_ · intro i hi' have h := (Finset.mem_filter.mp hi').2 have hilt : i.val < m₀ := by by_contra hge; simp only [entry, dif_neg hge, dif_pos hj] at h; simp at h simp only [entry, dif_pos hilt, dif_pos hj] at h exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, h⟩ · intro i₁ _ i₂ _ heq; exact Fin.ext (by simpa using congrArg Fin.val heq) · intro r hr refine ⟨⟨r.val, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, rfl⟩ simp only [entry, dif_pos r.isLt, dif_pos hj] exact (Finset.mem_filter.mp hr).2 rw [hbij]; exact sparse_col_card seamSlot hseam_cu ⟨j.val, hj⟩ _ · have hbB : (j.val - n₀) / n₁ < B := Nat.div_lt_of_lt_mul (by have := j.isLt; omega) let b : Fin B := ⟨(j.val - n₀) / n₁, hbB⟩ let c : Fin n₁ := ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩ have hbij : (Finset.univ.filter (fun i : Fin (m₀ + m₁ * B) => (entry i j).isSome)).card = (Finset.univ.filter (fun r : Fin m₁ => ((blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))).isSome)).card := by refine Finset.card_bij (fun i _ => ⟨(i.val - m₀) % m₁, Nat.mod_lt _ hm₁⟩) ?_ ?_ ?_ · intro i hi' have h := (Finset.mem_filter.mp hi').2 have hige : ¬ (i.val < m₀) := by intro hlt; simp only [entry, dif_pos hlt, dif_neg hj] at h; simp at h have hbm : (i.val - m₀) / m₁ = (j.val - n₀) / n₁ := by by_contra hne; simp only [entry, dif_neg hige, dif_neg hj, dif_neg hne] at h; simp at h simp only [entry, dif_neg hige, dif_neg hj, dif_pos hbm] at h have hbeq : (⟨(i.val - m₀) / m₁, Nat.div_lt_of_lt_mul (by have := i.isLt; omega)⟩ : Fin B) = b := Fin.ext hbm rw [hbeq] at h exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, h⟩ · intro i₁ hi₁ i₂ hi₂ heq have h1 := (Finset.mem_filter.mp hi₁).2 have h2 := (Finset.mem_filter.mp hi₂).2 have hi1ge : ¬ (i₁.val < m₀) := by intro hlt; simp only [entry, dif_pos hlt, dif_neg hj] at h1; simp at h1 have hi2ge : ¬ (i₂.val < m₀) := by intro hlt; simp only [entry, dif_pos hlt, dif_neg hj] at h2; simp at h2 have hbm1 : (i₁.val - m₀) / m₁ = (j.val - n₀) / n₁ := by by_contra hne; simp only [entry, dif_neg hi1ge, dif_neg hj, dif_neg hne] at h1; simp at h1 have hbm2 : (i₂.val - m₀) / m₁ = (j.val - n₀) / n₁ := by by_contra hne; simp only [entry, dif_neg hi2ge, dif_neg hj, dif_neg hne] at h2; simp at h2 have hmod : (i₁.val - m₀) % m₁ = (i₂.val - m₀) % m₁ := congrArg Fin.val heq have hdiv : (i₁.val - m₀) / m₁ = (i₂.val - m₀) / m₁ := by omega have hd1 := Nat.div_add_mod (i₁.val - m₀) m₁ have hd2 := Nat.div_add_mod (i₂.val - m₀) m₁ rw [hdiv, hmod] at hd1 exact Fin.ext (by omega) · intro r hr let ival := m₀ + m₁ * b.val + r.val have hilt : ival < m₀ + m₁ * B := by have := b.isLt; have := r.isLt; dsimp only [ival]; nlinarith have hige : ¬ (ival < m₀) := by dsimp only [ival]; omega have hdiv : (ival - m₀) / m₁ = b.val := by rw [show ival - m₀ = r.val + m₁ * b.val by dsimp only [ival]; omega] rw [Nat.add_mul_div_left _ _ hm₁, Nat.div_eq_of_lt r.isLt, zero_add] have hmod : (ival - m₀) % m₁ = r.val := by rw [show ival - m₀ = r.val + m₁ * b.val by dsimp only [ival]; omega] rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt r.isLt] refine ⟨⟨ival, hilt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, Fin.ext hmod⟩ have hbm : (ival - m₀) / m₁ = (j.val - n₀) / n₁ := hdiv simp only [entry, dif_neg hige, dif_neg hj, dif_pos hbm] have hbeq : (⟨(ival - m₀) / m₁, Nat.div_lt_of_lt_mul (by omega)⟩ : Fin B) = b := Fin.ext hdiv have hreq : (⟨(ival - m₀) % m₁, Nat.mod_lt _ hm₁⟩ : Fin m₁) = r := Fin.ext hmod rw [hbeq, hreq] exact (Finset.mem_filter.mp hr).2 rw [hbij]; exact sparse_col_card (blkSlot b) (hblk_cu b) c _ row_sum := fun i => by by_cases hi : i.val < m₀ · refine Eq.trans ?_ (hseam_rs ⟨i.val, hi⟩) rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun j : Fin (n₀ + n₁ * B) => j.val < n₀)] have h0 : ∑ j ∈ Finset.univ.filter (fun j : Fin (n₀ + n₁ * B) => ¬ j.val < n₀), (entry i j).getD 0 = 0 := Finset.sum_eq_zero (fun j hj => by have hge := (Finset.mem_filter.mp hj).2 simp only [entry, dif_pos hi, dif_neg hge, Option.getD_none]) rw [h0, add_zero] refine Finset.sum_bij (fun j hj => ⟨j.val, (Finset.mem_filter.mp hj).2⟩) (fun _ _ => Finset.mem_univ _) (fun _ _ _ _ h => Fin.ext (by simpa using congrArg Fin.val h)) (fun c _ => ⟨⟨c.val, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, c.isLt⟩, rfl⟩) (fun j hj => by have hlt := (Finset.mem_filter.mp hj).2 simp only [entry, dif_pos hi, dif_pos hlt]) · have hbB : (i.val - m₀) / m₁ < B := Nat.div_lt_of_lt_mul (by have := i.isLt; omega) let b : Fin B := ⟨(i.val - m₀) / m₁, hbB⟩ let r : Fin m₁ := ⟨(i.val - m₀) % m₁, Nat.mod_lt _ hm₁⟩ refine Eq.trans ?_ (hblk_rs b r) let P : Fin (n₀ + n₁ * B) → Prop := fun j => ¬ j.val < n₀ ∧ (i.val - m₀) / m₁ = (j.val - n₀) / n₁ rw [← Finset.sum_filter_add_sum_filter_not Finset.univ P] have h0 : ∑ j ∈ Finset.univ.filter (fun j => ¬ P j), (entry i j).getD 0 = 0 := by apply Finset.sum_eq_zero; intro j hj have hnp := (Finset.mem_filter.mp hj).2 by_cases hjlt : j.val < n₀ · simp only [entry, dif_neg hi, dif_pos hjlt, Option.getD_none] · have hne : (i.val - m₀) / m₁ ≠ (j.val - n₀) / n₁ := fun heq => hnp ⟨hjlt, heq⟩ simp only [entry, dif_neg hi, dif_neg hjlt, dif_neg hne, Option.getD_none] rw [h0, add_zero] refine Finset.sum_bij (fun j _ => ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩) (fun _ _ => Finset.mem_univ _) ?_ ?_ ?_ · intro j₁ hj₁ j₂ hj₂ heq rcases (Finset.mem_filter.mp hj₁).2 with ⟨hge1, hdiv1⟩ rcases (Finset.mem_filter.mp hj₂).2 with ⟨hge2, hdiv2⟩ have hmod : (j₁.val - n₀) % n₁ = (j₂.val - n₀) % n₁ := congrArg Fin.val heq have hdiv : (j₁.val - n₀) / n₁ = (j₂.val - n₀) / n₁ := by omega have hd1 := Nat.div_add_mod (j₁.val - n₀) n₁ have hd2 := Nat.div_add_mod (j₂.val - n₀) n₁ rw [hdiv, hmod] at hd1 exact Fin.ext (by omega) · intro c _ let jval := n₀ + n₁ * b.val + c.val have hjlt : jval < n₀ + n₁ * B := by have := b.isLt; have := c.isLt; dsimp only [jval]; nlinarith have hdiv : (jval - n₀) / n₁ = b.val := by rw [show jval - n₀ = c.val + n₁ * b.val by dsimp only [jval]; omega] rw [Nat.add_mul_div_left _ _ hn₁, Nat.div_eq_of_lt c.isLt, zero_add] have hmod : (jval - n₀) % n₁ = c.val := by rw [show jval - n₀ = c.val + n₁ * b.val by dsimp only [jval]; omega] rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt c.isLt] refine ⟨⟨jval, hjlt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by exact ⟨by dsimp only [jval]; omega, hdiv.symm⟩⟩, Fin.ext hmod⟩ · intro j hj rcases (Finset.mem_filter.mp hj).2 with ⟨hge, hdiv⟩ simp only [entry, dif_neg hi, dif_neg hge, dif_pos hdiv, b, r] col_sum := fun j => by by_cases hj : j.val < n₀ · rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun i : Fin (m₀ + m₁ * B) => i.val < m₀)] have h0 : ∑ i ∈ Finset.univ.filter (fun i : Fin (m₀ + m₁ * B) => ¬ i.val < m₀), (entry i j).getD 0 = 0 := Finset.sum_eq_zero (fun i hi => by simp only [entry, dif_neg (Finset.mem_filter.mp hi).2, dif_pos hj, Option.getD_none]) rw [h0, add_zero] have hbij : ∑ i ∈ Finset.univ.filter (fun i : Fin (m₀ + m₁ * B) => i.val < m₀), (entry i j).getD 0 = ∑ r : Fin m₀, ((seamSlot r ⟨j.val, hj⟩).map (fun e => seamSgn ⟨j.val, hj⟩ * A e (seamCol ⟨j.val, hj⟩))).getD 0 := Finset.sum_bij (fun i hi => ⟨i.val, (Finset.mem_filter.mp hi).2⟩) (fun _ _ => Finset.mem_univ _) (fun _ _ _ _ h => Fin.ext (by simpa using congrArg Fin.val h)) (fun r _ => ⟨⟨r.val, by omega⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, r.isLt⟩, rfl⟩) (fun i hi => by simp only [entry, dif_pos (Finset.mem_filter.mp hi).2, dif_pos hj]) rw [hbij, sparse_col_sum seamSlot hseam_cu ⟨j.val, hj⟩, ← Finset.mul_sum, hA_col, mul_zero] · have hbB : (j.val - n₀) / n₁ < B := Nat.div_lt_of_lt_mul (by have := j.isLt; omega) let b : Fin B := ⟨(j.val - n₀) / n₁, hbB⟩ let c : Fin n₁ := ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩ let P : Fin (m₀ + m₁ * B) → Prop := fun i => ¬ i.val < m₀ ∧ (i.val - m₀) / m₁ = (j.val - n₀) / n₁ rw [← Finset.sum_filter_add_sum_filter_not Finset.univ P] have h0 : ∑ i ∈ Finset.univ.filter (fun i => ¬ P i), (entry i j).getD 0 = 0 := by apply Finset.sum_eq_zero; intro i hi have hnp := (Finset.mem_filter.mp hi).2 by_cases hilt : i.val < m₀ · simp only [entry, dif_pos hilt, dif_neg hj, Option.getD_none] · have hne : (i.val - m₀) / m₁ ≠ (j.val - n₀) / n₁ := fun heq => hnp ⟨hilt, heq⟩ simp only [entry, dif_neg hilt, dif_neg hj, dif_neg hne, Option.getD_none] rw [h0, add_zero] have hbij : ∑ i ∈ Finset.univ.filter P, (entry i j).getD 0 = ∑ r : Fin m₁, ((blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))).getD 0 := by refine Finset.sum_bij (fun i _ => ⟨(i.val - m₀) % m₁, Nat.mod_lt _ hm₁⟩) (fun _ _ => Finset.mem_univ _) ?_ ?_ ?_ · intro i₁ hi₁ i₂ hi₂ heq rcases (Finset.mem_filter.mp hi₁).2 with ⟨hge1, hdiv1⟩ rcases (Finset.mem_filter.mp hi₂).2 with ⟨hge2, hdiv2⟩ have hmod : (i₁.val - m₀) % m₁ = (i₂.val - m₀) % m₁ := congrArg Fin.val heq have hdiv : (i₁.val - m₀) / m₁ = (i₂.val - m₀) / m₁ := by omega have hd1 := Nat.div_add_mod (i₁.val - m₀) m₁ have hd2 := Nat.div_add_mod (i₂.val - m₀) m₁ rw [hdiv, hmod] at hd1 exact Fin.ext (by omega) · intro r _ let ival := m₀ + m₁ * b.val + r.val have hilt : ival < m₀ + m₁ * B := by have := b.isLt; have := r.isLt; dsimp only [ival]; nlinarith have hdiv : (ival - m₀) / m₁ = b.val := by rw [show ival - m₀ = r.val + m₁ * b.val by dsimp only [ival]; omega] rw [Nat.add_mul_div_left _ _ hm₁, Nat.div_eq_of_lt r.isLt, zero_add] have hmod : (ival - m₀) % m₁ = r.val := by rw [show ival - m₀ = r.val + m₁ * b.val by dsimp only [ival]; omega] rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt r.isLt] refine ⟨⟨ival, hilt⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, by exact ⟨by dsimp only [ival]; omega, hdiv⟩⟩, Fin.ext hmod⟩ · intro i hi rcases (Finset.mem_filter.mp hi).2 with ⟨hge, hdiv⟩ simp only [entry, dif_neg hge, dif_neg hj, dif_pos hdiv] have hbeq : (⟨(i.val - m₀) / m₁, Nat.div_lt_of_lt_mul (by have := i.isLt; omega)⟩ : Fin B) = b := Fin.ext hdiv rw [hbeq] rw [hbij, sparse_col_sum (blkSlot b) (hblk_cu b) c, ← Finset.mul_sum, hA_col, mul_zero] nonzero := fun i j x hx => by dsimp only [entry] at hx by_cases hi : i.val < m₀ · by_cases hj : j.val < n₀ · simp only [dif_pos hi, dif_pos hj] at hx rcases Option.map_eq_some_iff.mp hx with ⟨e, _, rfl⟩ exact mul_ne_zero (by have := hsSgn ⟨j.val, hj⟩; omega) (hA_nz e _) · simp only [dif_pos hi, dif_neg hj] at hx; cases hx · by_cases hj : j.val < n₀ · simp only [dif_neg hi, dif_pos hj] at hx; cases hx · by_cases hbm : (i.val - m₀) / m₁ = (j.val - n₀) / n₁ · simp only [dif_neg hi, dif_neg hj, dif_pos hbm] at hx rcases Option.map_eq_some_iff.mp hx with ⟨e, _, rfl⟩ have h1 := hbSgn ⟨(i.val - m₀) / m₁, Nat.div_lt_of_lt_mul (by have := i.isLt; omega)⟩ ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩ exact mul_ne_zero (by omega) (hA_nz e _) · simp only [dif_neg hi, dif_neg hj, dif_neg hbm] at hx; cases hx mag_le := fun i j x hx => by dsimp only [entry] at hx by_cases hi : i.val < m₀ · by_cases hj : j.val < n₀ · simp only [dif_pos hi, dif_pos hj] at hx rcases Option.map_eq_some_iff.mp hx with ⟨e, _, rfl⟩ rw [Int.natAbs_mul, hsSgn, one_mul]; exact hA_le e _ · simp only [dif_pos hi, dif_neg hj] at hx; cases hx · by_cases hj : j.val < n₀ · simp only [dif_neg hi, dif_pos hj] at hx; cases hx · by_cases hbm : (i.val - m₀) / m₁ = (j.val - n₀) / n₁ · simp only [dif_neg hi, dif_neg hj, dif_pos hbm] at hx rcases Option.map_eq_some_iff.mp hx with ⟨e, _, rfl⟩ rw [Int.natAbs_mul, hbSgn, one_mul]; exact hA_le e _ · simp only [dif_neg hi, dif_neg hj, dif_neg hbm] at hx; cases hx not_subgrp := fun i j x hx => by dsimp only [entry] at hx by_cases hi : i.val < m₀ · by_cases hj : j.val < n₀ · simp only [dif_pos hi, dif_pos hj] at hx rcases Option.map_eq_some_iff.mp hx with ⟨e, _, rfl⟩ rw [Int.natAbs_mul, hsSgn, one_mul]; exact hA_nsub e _ · simp only [dif_pos hi, dif_neg hj] at hx; cases hx · by_cases hj : j.val < n₀ · simp only [dif_neg hi, dif_pos hj] at hx; cases hx · by_cases hbm : (i.val - m₀) / m₁ = (j.val - n₀) / n₁ · simp only [dif_neg hi, dif_neg hj, dif_pos hbm] at hx rcases Option.map_eq_some_iff.mp hx with ⟨e, _, rfl⟩ rw [Int.natAbs_mul, hbSgn, one_mul]; exact hA_nsub e _ · simp only [dif_neg hi, dif_neg hj, dif_neg hbm] at hx; cases hx mag_inj := fun i₁ j₁ i₂ j₂ x₁ x₂ h₁ h₂ heq => by dsimp only [entry] at h₁ h₂ by_cases hi1 : i₁.val < m₀ <;> by_cases hj1 : j₁.val < n₀ <;> by_cases hi2 : i₂.val < m₀ <;> by_cases hj2 : j₂.val < n₀ all_goals simp only [dif_pos, dif_neg, hi1, hj1, hi2, hj2, not_false_eq_true] at h₁ h₂ all_goals try cases h₁ all_goals try cases h₂ · rcases Option.map_eq_some_iff.mp h₁ with ⟨e₁, hs1, rfl⟩ rcases Option.map_eq_some_iff.mp h₂ with ⟨e₂, hs2, rfl⟩ rw [Int.natAbs_mul, Int.natAbs_mul, hsSgn, hsSgn, one_mul, one_mul] at heq rcases hA_inj e₁ _ e₂ _ heq with ⟨rfl, hx⟩ have hj_eq : (⟨j₁.val, hj1⟩ : Fin n₀) = ⟨j₂.val, hj2⟩ := hseam_inj hx have hjv : j₁ = j₂ := Fin.ext (by simpa using congrArg Fin.val hj_eq) rw [hj_eq] at hs1 have hr_eq : (⟨i₁.val, hi1⟩ : Fin m₀) = ⟨i₂.val, hi2⟩ := (hseam_cu _ e₁).unique hs1 hs2 exact ⟨Fin.ext (by simpa using congrArg Fin.val hr_eq), hjv⟩ · by_cases hbm2 : (i₂.val - m₀) / m₁ = (j₂.val - n₀) / n₁ · simp only [dif_pos hbm2] at h₂ rcases Option.map_eq_some_iff.mp h₁ with ⟨e₁, _, rfl⟩ rcases Option.map_eq_some_iff.mp h₂ with ⟨e₂, _, rfl⟩ rw [Int.natAbs_mul, Int.natAbs_mul, hsSgn, hbSgn, one_mul, one_mul] at heq exact absurd (hA_inj e₁ _ e₂ _ heq).2 (hdisj _ _ _) · simp only [dif_neg hbm2] at h₂; cases h₂ · by_cases hbm1 : (i₁.val - m₀) / m₁ = (j₁.val - n₀) / n₁ · simp only [dif_pos hbm1] at h₁ rcases Option.map_eq_some_iff.mp h₁ with ⟨e₁, _, rfl⟩ rcases Option.map_eq_some_iff.mp h₂ with ⟨e₂, _, rfl⟩ rw [Int.natAbs_mul, Int.natAbs_mul, hbSgn, hsSgn, one_mul, one_mul] at heq exact absurd (hA_inj e₁ _ e₂ _ heq).2.symm (hdisj _ _ _) · simp only [dif_neg hbm1] at h₁; cases h₁ · by_cases hbm1 : (i₁.val - m₀) / m₁ = (j₁.val - n₀) / n₁ · by_cases hbm2 : (i₂.val - m₀) / m₁ = (j₂.val - n₀) / n₁ · simp only [dif_pos hbm1] at h₁ simp only [dif_pos hbm2] at h₂ rcases Option.map_eq_some_iff.mp h₁ with ⟨e₁, hs1, rfl⟩ rcases Option.map_eq_some_iff.mp h₂ with ⟨e₂, hs2, rfl⟩ rw [Int.natAbs_mul, Int.natAbs_mul, hbSgn, hbSgn, one_mul, one_mul] at heq rcases hA_inj e₁ _ e₂ _ heq with ⟨rfl, hx⟩ rcases hblk_inj _ _ _ _ hx with ⟨hb_eq, hc_eq⟩ have hb_val : (i₁.val - m₀) / m₁ = (i₂.val - m₀) / m₁ := congrArg Fin.val hb_eq have hc_val : (j₁.val - n₀) % n₁ = (j₂.val - n₀) % n₁ := congrArg Fin.val hc_eq have hj_eq : j₁ = j₂ := by have hdiv : (j₁.val - n₀) / n₁ = (j₂.val - n₀) / n₁ := by omega have hd1 := Nat.div_add_mod (j₁.val - n₀) n₁ have hd2 := Nat.div_add_mod (j₂.val - n₀) n₁ rw [hdiv, hc_val] at hd1 exact Fin.ext (by omega) rw [hb_eq, hc_eq] at hs1 have hr_eq := (hblk_cu _ _ e₁).unique hs1 hs2 have hr_val : (i₁.val - m₀) % m₁ = (i₂.val - m₀) % m₁ := congrArg Fin.val hr_eq have hi_eq : i₁ = i₂ := by have hd1 := Nat.div_add_mod (i₁.val - m₀) m₁ have hd2 := Nat.div_add_mod (i₂.val - m₀) m₁ rw [hb_val, hr_val] at hd1 exact Fin.ext (by omega) exact ⟨hi_eq, hj_eq⟩ · simp only [dif_neg hbm2] at h₂; cases h₂ · simp only [dif_neg hbm1] at h₁; cases h₁ } exact { toIntRelativeHeffterArray := H row_simple := fun i => by have hsum_i := rowFilled_sum H i have hbnd_i : ∀ x ∈ rowFilled H i, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t := fun x hx => ⟨(rowFilled_mem_bounds H i hx).1, two_mul_le_of_le_relHalfMax H.ht_pos (rowFilled_mem_bounds H i hx).2.1⟩ have hnod_i := rowFilled_mag_nodup H i by_cases hi : i.val < m₀ · have hrow : rowFilled H i = (List.finRange n₀).filterMap (fun c => (seamSlot ⟨i.val, hi⟩ c).map (fun e => seamSgn c * A e (seamCol c))) := by rw [rowFilled, filterMap_finRange_add] have hright : (List.finRange (n₁ * B)).filterMap (fun j => H.entry i ⟨n₀ + j.val, by omega⟩) = [] := by apply filterMap_finRange_none; intro j have hge : ¬ (n₀ + j.val < n₀) := by omega simp only [H, entry, dif_pos hi, dif_neg hge] rw [hright, List.append_nil] congr 1; funext c; simp only [H, entry, dif_pos hi, dif_pos c.isLt] rw [hrow] at hsum_i hbnd_i hnod_i ⊢ exact hseam_rsimp ⟨i.val, hi⟩ hsum_i hbnd_i hnod_i · have hbB : (i.val - m₀) / m₁ < B := Nat.div_lt_of_lt_mul (by have := i.isLt; omega) let b : Fin B := ⟨(i.val - m₀) / m₁, hbB⟩ let r : Fin m₁ := ⟨(i.val - m₀) % m₁, Nat.mod_lt _ hm₁⟩ have hrow : rowFilled H i = (List.finRange n₁).filterMap (fun c => (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))) := by rw [rowFilled, filterMap_finRange_add] have hleft : (List.finRange n₀).filterMap (fun c => H.entry i ⟨c.val, by omega⟩) = [] := by apply filterMap_finRange_none; intro c simp only [H, entry, dif_neg hi, dif_pos c.isLt] rw [hleft, List.nil_append] rw [filterMap_finRange_mul_block b _ (fun j hne => by have hge : ¬ (n₀ + j.val < n₀) := by omega have hbm : (i.val - m₀) / m₁ ≠ (n₀ + j.val - n₀) / n₁ := by rw [Nat.add_sub_cancel_left]; exact hne.symm simp only [H, entry, dif_neg hi, dif_neg hge, dif_neg hbm]) hn₁] congr 1; funext c have hge : ¬ (n₀ + (n₁ * b.val + c.val) < n₀) := by omega have hdiv : (n₀ + (n₁ * b.val + c.val) - n₀) / n₁ = b.val := by rw [Nat.add_sub_cancel_left, show n₁ * b.val + c.val = c.val + n₁ * b.val by omega] rw [Nat.add_mul_div_left _ _ hn₁, Nat.div_eq_of_lt c.isLt, zero_add] have hmod : (n₀ + (n₁ * b.val + c.val) - n₀) % n₁ = c.val := by rw [Nat.add_sub_cancel_left, show n₁ * b.val + c.val = c.val + n₁ * b.val by omega] rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt c.isLt] have hbm : (i.val - m₀) / m₁ = (n₀ + (n₁ * b.val + c.val) - n₀) / n₁ := hdiv.symm simp only [H, entry, dif_neg hi, dif_neg hge, dif_pos hbm] have hceq : (⟨(n₀ + (n₁ * b.val + c.val) - n₀) % n₁, Nat.mod_lt _ hn₁⟩ : Fin n₁) = c := Fin.ext hmod rw [hceq] rw [hrow] at hsum_i hbnd_i hnod_i ⊢ exact hblk_rsimp b r hsum_i hbnd_i hnod_i col_simple := fun j => by have hlen_j := colFilled_length H j have hsum_j := colFilled_sum H j have hbnd_j : ∀ x ∈ colFilled H j, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t := fun x hx => ⟨(colFilled_mem_bounds H j hx).1, two_mul_le_of_le_relHalfMax H.ht_pos (colFilled_mem_bounds H j hx).2.1⟩ have hnod_j := colFilled_mag_nodup H j by_cases hj : j.val < n₀ · have hcol : colFilled H j = (List.finRange m₀).filterMap (fun r => (seamSlot r ⟨j.val, hj⟩).map (fun e => seamSgn ⟨j.val, hj⟩ * A e (seamCol ⟨j.val, hj⟩))) := by rw [colFilled, filterMap_finRange_add] have hright : (List.finRange (m₁ * B)).filterMap (fun i => H.entry ⟨m₀ + i.val, by omega⟩ j) = [] := by apply filterMap_finRange_none; intro i have hge : ¬ (m₀ + i.val < m₀) := by omega simp only [H, entry, dif_neg hge, dif_pos hj] rw [hright, List.append_nil] congr 1; funext r; simp only [H, entry, dif_pos r.isLt, dif_pos hj] rw [hcol] at hlen_j hsum_j hbnd_j hnod_j ⊢ exact hseam_csimp ⟨j.val, hj⟩ hlen_j hsum_j hbnd_j hnod_j · have hbB : (j.val - n₀) / n₁ < B := Nat.div_lt_of_lt_mul (by have := j.isLt; omega) let b : Fin B := ⟨(j.val - n₀) / n₁, hbB⟩ let c : Fin n₁ := ⟨(j.val - n₀) % n₁, Nat.mod_lt _ hn₁⟩ have hcol : colFilled H j = (List.finRange m₁).filterMap (fun r => (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))) := by rw [colFilled, filterMap_finRange_add] have hleft : (List.finRange m₀).filterMap (fun r => H.entry ⟨r.val, by omega⟩ j) = [] := by apply filterMap_finRange_none; intro r simp only [H, entry, dif_pos r.isLt, dif_neg hj] rw [hleft, List.nil_append] rw [filterMap_finRange_mul_block b _ (fun i hne => by have hge : ¬ (m₀ + i.val < m₀) := by omega have hbm : (m₀ + i.val - m₀) / m₁ ≠ (j.val - n₀) / n₁ := by rw [Nat.add_sub_cancel_left]; exact hne simp only [H, entry, dif_neg hge, dif_neg hj, dif_neg hbm]) hm₁] congr 1; funext r have hge : ¬ (m₀ + (m₁ * b.val + r.val) < m₀) := by omega have hdiv : (m₀ + (m₁ * b.val + r.val) - m₀) / m₁ = b.val := by rw [Nat.add_sub_cancel_left, show m₁ * b.val + r.val = r.val + m₁ * b.val by omega] rw [Nat.add_mul_div_left _ _ hm₁, Nat.div_eq_of_lt r.isLt, zero_add] have hmod : (m₀ + (m₁ * b.val + r.val) - m₀) % m₁ = r.val := by rw [Nat.add_sub_cancel_left, show m₁ * b.val + r.val = r.val + m₁ * b.val by omega] rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt r.isLt] have hbm : (m₀ + (m₁ * b.val + r.val) - m₀) / m₁ = (j.val - n₀) / n₁ := hdiv simp only [H, entry, dif_neg hge, dif_neg hj, dif_pos hbm] have hbeq : (⟨(m₀ + (m₁ * b.val + r.val) - m₀) / m₁, Nat.div_lt_of_lt_mul (by have := b.isLt; have := r.isLt; rw [Nat.add_sub_cancel_left]; nlinarith)⟩ : Fin B) = b := Fin.ext hdiv have hreq : (⟨(m₀ + (m₁ * b.val + r.val) - m₀) % m₁, Nat.mod_lt _ hm₁⟩ : Fin m₁) = r := Fin.ext hmod rw [hbeq, hreq] rw [hcol] at hlen_j hsum_j hbnd_j hnod_j ⊢ exact hblk_csimp b c hlen_j hsum_j hbnd_j hnod_j } /-- Convenience wrapper for `k ≤ 5`: columns are automatically simple modulo `2 * N + t`. -/ noncomputable def ofSeamAndUniformBlocksRelSimpleKLe5 {ι : Type*} {m₀ n₀ m₁ n₁ B s k t : ℕ} (ht_pos : 0 < t) (ht_div : t ∣ 2 * ((n₀ + n₁ * B) * k)) (hk5 : k ≤ 5) (A : Fin k → ι → ℤ) (seamCol : Fin n₀ → ι) (seamSgn : Fin n₀ → ℤ) (seamSlot : Fin m₀ → Fin n₀ → Option (Fin k)) (blkCol : Fin B → Fin n₁ → ι) (blkSgn : Fin B → Fin n₁ → ℤ) (blkSlot : Fin B → Fin m₁ → Fin n₁ → Option (Fin k)) (hm₁ : 0 < m₁) (hn₁ : 0 < n₁) (hA_col : ∀ x, ∑ e : Fin k, A e x = 0) (hA_nz : ∀ e x, A e x ≠ 0) (hA_le : ∀ e x, (A e x).natAbs ≤ relHalfMax ((n₀ + n₁ * B) * k) t) (hA_nsub : ∀ e x, ¬ (relStep ((n₀ + n₁ * B) * k) t ∣ (A e x).natAbs)) (hA_inj : ∀ e₁ x₁ e₂ x₂, (A e₁ x₁).natAbs = (A e₂ x₂).natAbs → e₁ = e₂ ∧ x₁ = x₂) (hsSgn : ∀ c, (seamSgn c).natAbs = 1) (hbSgn : ∀ b c, (blkSgn b c).natAbs = 1) (hseam_rc : ∀ r, (Finset.univ.filter (fun c => (seamSlot r c).isSome)).card = s) (hseam_cu : ∀ c e, ∃! r : Fin m₀, seamSlot r c = some e) (hseam_rs : ∀ r, ∑ c : Fin n₀, ((seamSlot r c).map (fun e => seamSgn c * A e (seamCol c))).getD 0 = 0) (hblk_rc : ∀ b r, (Finset.univ.filter (fun c => (blkSlot b r c).isSome)).card = s) (hblk_cu : ∀ b c e, ∃! r : Fin m₁, blkSlot b r c = some e) (hblk_rs : ∀ b r, ∑ c : Fin n₁, ((blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))).getD 0 = 0) (hseam_inj : Function.Injective seamCol) (hblk_inj : ∀ b₁ c₁ b₂ c₂, blkCol b₁ c₁ = blkCol b₂ c₂ → b₁ = b₂ ∧ c₁ = c₂) (hdisj : ∀ c₀ b c₁, seamCol c₀ ≠ blkCol b c₁) (hseam_rsimp : ∀ r : Fin m₀, let L := (List.finRange n₀).filterMap (fun c => (seamSlot r c).map (fun e => seamSgn c * A e (seamCol c))) L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * ((n₀ + n₁ * B) * k) + t) L) (hblk_rsimp : ∀ (b : Fin B) (r : Fin m₁), let L := (List.finRange n₁).filterMap (fun c => (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))) L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * ((n₀ + n₁ * B) * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * ((n₀ + n₁ * B) * k) + t) L) : GloballySimpleRelativeHeffterArray (m₀ + m₁ * B) (n₀ + n₁ * B) s k t := ofSeamAndUniformBlocksRelSimple ht_pos ht_div A seamCol seamSgn seamSlot blkCol blkSgn blkSlot hm₁ hn₁ hA_col hA_nz hA_le hA_nsub hA_inj hsSgn hbSgn hseam_rc hseam_cu hseam_rs hblk_rc hblk_cu hblk_rs hseam_inj hblk_inj hdisj hseam_rsimp hblk_rsimp (fun _ hlen hsum hbnd hnod => isSimpleList_of_length_le_five_rel _ (by omega) hsum hbnd hnod) (fun _ _ hlen hsum hbnd hnod => isSimpleList_of_length_le_five_rel _ (by omega) hsum hbnd hnod) /-- Zero-seam pure uniform-block relative assembly (`m₀ = 0, n₀ = 0`, `k ≤ 5`). -/ noncomputable def ofUniformBlocksRelSimpleKLe5 {ι : Type*} {m₁ n₁ B s k t : ℕ} (ht_pos : 0 < t) (ht_div : t ∣ 2 * (n₁ * B * k)) (hk5 : k ≤ 5) (A : Fin k → ι → ℤ) (blkCol : Fin B → Fin n₁ → ι) (blkSgn : Fin B → Fin n₁ → ℤ) (blkSlot : Fin B → Fin m₁ → Fin n₁ → Option (Fin k)) (hm₁ : 0 < m₁) (hn₁ : 0 < n₁) (hA_col : ∀ x, ∑ e : Fin k, A e x = 0) (hA_nz : ∀ e x, A e x ≠ 0) (hA_le : ∀ e x, (A e x).natAbs ≤ relHalfMax (n₁ * B * k) t) (hA_nsub : ∀ e x, ¬ (relStep (n₁ * B * k) t ∣ (A e x).natAbs)) (hA_inj : ∀ e₁ x₁ e₂ x₂, (A e₁ x₁).natAbs = (A e₂ x₂).natAbs → e₁ = e₂ ∧ x₁ = x₂) (hbSgn : ∀ b c, (blkSgn b c).natAbs = 1) (hblk_rc : ∀ b r, (Finset.univ.filter (fun c => (blkSlot b r c).isSome)).card = s) (hblk_cu : ∀ b c e, ∃! r : Fin m₁, blkSlot b r c = some e) (hblk_rs : ∀ b r, ∑ c : Fin n₁, ((blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))).getD 0 = 0) (hblk_inj : ∀ b₁ c₁ b₂ c₂, blkCol b₁ c₁ = blkCol b₂ c₂ → b₁ = b₂ ∧ c₁ = c₂) (hblk_rsimp : ∀ (b : Fin B) (r : Fin m₁), let L := (List.finRange n₁).filterMap (fun c => (blkSlot b r c).map (fun e => blkSgn b c * A e (blkCol b c))) L.sum = 0 → (∀ x ∈ L, 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * (n₁ * B * k) + t) → (L.map Int.natAbs).Nodup → IsSimpleList (2 * (n₁ * B * k) + t) L) : GloballySimpleRelativeHeffterArray (m₁ * B) (n₁ * B) s k t := GloballySimpleRelativeHeffterArray.cast (Nat.zero_add _) (Nat.zero_add _) (ofSeamAndUniformBlocksRelSimpleKLe5 (m₀ := 0) (n₀ := 0) ht_pos (by simpa using ht_div) hk5 A (fun c => Fin.elim0 c) (fun c => Fin.elim0 c) (fun r => Fin.elim0 r) blkCol blkSgn blkSlot hm₁ hn₁ hA_col hA_nz (by simpa using hA_le) (by simpa using hA_nsub) hA_inj (fun c => Fin.elim0 c) hbSgn (fun r => Fin.elim0 r) (fun c => Fin.elim0 c) (fun r => Fin.elim0 r) hblk_rc hblk_cu hblk_rs (fun c₁ => Fin.elim0 c₁) hblk_inj (fun c₀ => Fin.elim0 c₀) (fun r => Fin.elim0 r) (by simpa using hblk_rsimp)) /-! ## 7. Zero-Stray Super-Balanced Column Systems for `t = 3` and `t = 4` (`n = 4M`, `k = 3`) -/ def rel3EvenEntry (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : ℤ := match p.1, e with | ⟨0, _⟩, ⟨0, _⟩ => (1 + 2 * p.2.val : ℤ) | ⟨0, _⟩, ⟨1, _⟩ => -(11 * M + 2 + p.2.val : ℤ) | ⟨0, _⟩, ⟨2, _⟩ => (11 * M + 1 - p.2.val : ℤ) | ⟨1, _⟩, ⟨0, _⟩ => (2 + 2 * p.2.val : ℤ) | ⟨1, _⟩, ⟨1, _⟩ => -(8 * M + 2 + p.2.val : ℤ) | ⟨1, _⟩, ⟨2, _⟩ => (8 * M - p.2.val : ℤ) | ⟨2, _⟩, ⟨0, _⟩ => (3 * M + 1 + 2 * p.2.val : ℤ) | ⟨2, _⟩, ⟨1, _⟩ => -(6 * M + 1 + p.2.val : ℤ) | ⟨2, _⟩, ⟨2, _⟩ => (3 * M - p.2.val : ℤ) | ⟨3, _⟩, ⟨0, _⟩ => (3 * M + 2 + 2 * p.2.val : ℤ) | ⟨3, _⟩, ⟨1, _⟩ => (6 * M - p.2.val : ℤ) | ⟨3, _⟩, ⟨2, _⟩ => -(9 * M + 2 + p.2.val : ℤ) def rel3EvenMag (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : ℕ := match p.1, e with | ⟨0, _⟩, ⟨0, _⟩ => 1 + 2 * p.2.val | ⟨0, _⟩, ⟨1, _⟩ => 11 * M + 2 + p.2.val | ⟨0, _⟩, ⟨2, _⟩ => 11 * M + 1 - p.2.val | ⟨1, _⟩, ⟨0, _⟩ => 2 + 2 * p.2.val | ⟨1, _⟩, ⟨1, _⟩ => 8 * M + 2 + p.2.val | ⟨1, _⟩, ⟨2, _⟩ => 8 * M - p.2.val | ⟨2, _⟩, ⟨0, _⟩ => 3 * M + 1 + 2 * p.2.val | ⟨2, _⟩, ⟨1, _⟩ => 6 * M + 1 + p.2.val | ⟨2, _⟩, ⟨2, _⟩ => 3 * M - p.2.val | ⟨3, _⟩, ⟨0, _⟩ => 3 * M + 2 + 2 * p.2.val | ⟨3, _⟩, ⟨1, _⟩ => 6 * M - p.2.val | ⟨3, _⟩, ⟨2, _⟩ => 9 * M + 2 + p.2.val lemma rel3EvenEntry_col_sum (M : ℕ) (p : Fin 4 × Fin M) : ∑ e : Fin 3, rel3EvenEntry M e p = 0 := by rcases p with ⟨f, j⟩ rw [Fin.sum_univ_three] fin_cases f <;> (simp only [rel3EvenEntry]; omega) lemma rel3EvenEntry_natAbs_eq (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : (rel3EvenEntry M e p).natAbs = rel3EvenMag M e p := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel3EvenEntry, rel3EvenMag]; omega) lemma rel3EvenMag_pos (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : 0 < rel3EvenMag M e p := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel3EvenMag]; omega) lemma rel3EvenMag_le (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : rel3EvenMag M e p ≤ 12 * M + 1 := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel3EvenMag]; omega) lemma rel3EvenMag_ne_hole (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : rel3EvenMag M e p ≠ 8 * M + 1 := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel3EvenMag]; omega) lemma rel3EvenMag_not_dvd (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : ¬ (8 * M + 1 ∣ rel3EvenMag M e p) := by have hpos := rel3EvenMag_pos M e p have hle := rel3EvenMag_le M e p have hne := rel3EvenMag_ne_hole M e p rintro ⟨c, hc⟩ rcases p with ⟨_, j⟩; have hj := j.isLt have hc0 : c ≠ 0 := by intro h; rw [h, mul_zero] at hc; omega have hc1 : c ≠ 1 := by intro h; rw [h, mul_one] at hc; exact hne hc have hc2 : 2 ≤ c := by omega have hge : 2 * (8 * M + 1) ≤ (8 * M + 1) * c := by calc 2 * (8 * M + 1) = (8 * M + 1) * 2 := by ring _ ≤ (8 * M + 1) * c := Nat.mul_le_mul_left _ hc2 omega def decodeRel3EvenMag (M d : ℕ) : ℕ × ℕ × ℕ := if d ≤ 2 * M then if d % 2 = 1 then (0, 0, (d - 1) / 2) else (0, 1, (d - 2) / 2) else if d ≤ 3 * M then (2, 2, 3 * M - d) else if d ≤ 5 * M then if (d - 3 * M) % 2 = 1 then (0, 2, (d - 3 * M - 1) / 2) else (0, 3, (d - 3 * M - 2) / 2) else if d ≤ 6 * M then (1, 3, 6 * M - d) else if d ≤ 7 * M then (1, 2, d - 6 * M - 1) else if d ≤ 8 * M then (2, 1, 8 * M - d) else if d ≤ 9 * M + 1 then (1, 1, d - 8 * M - 2) else if d ≤ 10 * M + 1 then (2, 3, d - 9 * M - 2) else if d ≤ 11 * M + 1 then (2, 0, 11 * M + 1 - d) else (1, 0, d - 11 * M - 2) lemma decodeRel3EvenMag_spec (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : decodeRel3EvenMag M (rel3EvenMag M e p) = (e.val, p.1.val, p.2.val) := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> ( dsimp only [rel3EvenMag] unfold decodeRel3EvenMag repeat (first | rw [if_pos (by omega)] | rw [if_neg (by omega)]) simp only [Prod.mk.injEq] exact ⟨by decide, by decide, by omega⟩) lemma rel3EvenEntry_natAbs_inj (M : ℕ) (e₁ : Fin 3) (p₁ : Fin 4 × Fin M) (e₂ : Fin 3) (p₂ : Fin 4 × Fin M) (h : (rel3EvenEntry M e₁ p₁).natAbs = (rel3EvenEntry M e₂ p₂).natAbs) : e₁ = e₂ ∧ p₁ = p₂ := by rw [rel3EvenEntry_natAbs_eq, rel3EvenEntry_natAbs_eq] at h have hd := congrArg (decodeRel3EvenMag M) h rw [decodeRel3EvenMag_spec, decodeRel3EvenMag_spec] at hd simp only [Prod.mk.injEq] at hd exact ⟨Fin.ext hd.1, Prod.ext (Fin.ext hd.2.1) (Fin.ext hd.2.2)⟩ def rel4EvenEntry (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : ℤ := match p.1, e with | ⟨0, _⟩, ⟨0, _⟩ => (1 + 2 * p.2.val : ℤ) | ⟨0, _⟩, ⟨1, _⟩ => (10 * M + 1 - p.2.val : ℤ) | ⟨0, _⟩, ⟨2, _⟩ => -(10 * M + 2 + p.2.val : ℤ) | ⟨1, _⟩, ⟨0, _⟩ => (2 + 2 * p.2.val : ℤ) | ⟨1, _⟩, ⟨1, _⟩ => (6 * M - p.2.val : ℤ) | ⟨1, _⟩, ⟨2, _⟩ => -(6 * M + 2 + p.2.val : ℤ) | ⟨2, _⟩, ⟨0, _⟩ => (2 * M + 1 + 2 * p.2.val : ℤ) | ⟨2, _⟩, ⟨1, _⟩ => (9 * M + 1 - p.2.val : ℤ) | ⟨2, _⟩, ⟨2, _⟩ => -(11 * M + 2 + p.2.val : ℤ) | ⟨3, _⟩, ⟨0, _⟩ => (2 * M + 2 + 2 * p.2.val : ℤ) | ⟨3, _⟩, ⟨1, _⟩ => (5 * M - p.2.val : ℤ) | ⟨3, _⟩, ⟨2, _⟩ => -(7 * M + 2 + p.2.val : ℤ) def rel4EvenMag (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : ℕ := match p.1, e with | ⟨0, _⟩, ⟨0, _⟩ => 1 + 2 * p.2.val | ⟨0, _⟩, ⟨1, _⟩ => 10 * M + 1 - p.2.val | ⟨0, _⟩, ⟨2, _⟩ => 10 * M + 2 + p.2.val | ⟨1, _⟩, ⟨0, _⟩ => 2 + 2 * p.2.val | ⟨1, _⟩, ⟨1, _⟩ => 6 * M - p.2.val | ⟨1, _⟩, ⟨2, _⟩ => 6 * M + 2 + p.2.val | ⟨2, _⟩, ⟨0, _⟩ => 2 * M + 1 + 2 * p.2.val | ⟨2, _⟩, ⟨1, _⟩ => 9 * M + 1 - p.2.val | ⟨2, _⟩, ⟨2, _⟩ => 11 * M + 2 + p.2.val | ⟨3, _⟩, ⟨0, _⟩ => 2 * M + 2 + 2 * p.2.val | ⟨3, _⟩, ⟨1, _⟩ => 5 * M - p.2.val | ⟨3, _⟩, ⟨2, _⟩ => 7 * M + 2 + p.2.val lemma rel4EvenEntry_col_sum (M : ℕ) (p : Fin 4 × Fin M) : ∑ e : Fin 3, rel4EvenEntry M e p = 0 := by rcases p with ⟨f, j⟩ rw [Fin.sum_univ_three] fin_cases f <;> (simp only [rel4EvenEntry]; omega) lemma rel4EvenEntry_natAbs_eq (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : (rel4EvenEntry M e p).natAbs = rel4EvenMag M e p := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel4EvenEntry, rel4EvenMag]; omega) lemma rel4EvenMag_pos (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : 0 < rel4EvenMag M e p := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel4EvenMag]; omega) lemma rel4EvenMag_le (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : rel4EvenMag M e p ≤ 12 * M + 1 := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel4EvenMag]; omega) lemma rel4EvenMag_ne_hole (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : rel4EvenMag M e p ≠ 6 * M + 1 := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> (simp only [rel4EvenMag]; omega) lemma rel4EvenMag_not_dvd (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : ¬ (6 * M + 1 ∣ rel4EvenMag M e p) := by have hpos := rel4EvenMag_pos M e p have hle := rel4EvenMag_le M e p have hne := rel4EvenMag_ne_hole M e p rintro ⟨c, hc⟩ rcases p with ⟨_, j⟩; have hj := j.isLt have hc0 : c ≠ 0 := by intro h; rw [h, mul_zero] at hc; omega have hc1 : c ≠ 1 := by intro h; rw [h, mul_one] at hc; exact hne hc have hc2 : 2 ≤ c := by omega have hge : 2 * (6 * M + 1) ≤ (6 * M + 1) * c := by calc 2 * (6 * M + 1) = (6 * M + 1) * 2 := by ring _ ≤ (6 * M + 1) * c := Nat.mul_le_mul_left _ hc2 omega def decodeRel4EvenMag (M d : ℕ) : ℕ × ℕ × ℕ := if d ≤ 2 * M then if d % 2 = 1 then (0, 0, (d - 1) / 2) else (0, 1, (d - 2) / 2) else if d ≤ 4 * M then if d % 2 = 1 then (0, 2, (d - 2 * M - 1) / 2) else (0, 3, (d - 2 * M - 2) / 2) else if d ≤ 5 * M then (1, 3, 5 * M - d) else if d ≤ 6 * M then (1, 1, 6 * M - d) else if d ≤ 7 * M + 1 then (2, 1, d - 6 * M - 2) else if d ≤ 8 * M + 1 then (2, 3, d - 7 * M - 2) else if d ≤ 9 * M + 1 then (1, 2, 9 * M + 1 - d) else if d ≤ 10 * M + 1 then (1, 0, 10 * M + 1 - d) else if d ≤ 11 * M + 1 then (2, 0, d - 10 * M - 2) else (2, 2, d - 11 * M - 2) lemma decodeRel4EvenMag_spec (M : ℕ) (e : Fin 3) (p : Fin 4 × Fin M) : decodeRel4EvenMag M (rel4EvenMag M e p) = (e.val, p.1.val, p.2.val) := by rcases p with ⟨f, j⟩; have hj := j.isLt fin_cases f <;> fin_cases e <;> ( dsimp only [rel4EvenMag] unfold decodeRel4EvenMag repeat (first | rw [if_pos (by omega)] | rw [if_neg (by omega)]) simp only [Prod.mk.injEq] exact ⟨by decide, by decide, by omega⟩) lemma rel4EvenEntry_natAbs_inj (M : ℕ) (e₁ : Fin 3) (p₁ : Fin 4 × Fin M) (e₂ : Fin 3) (p₂ : Fin 4 × Fin M) (h : (rel4EvenEntry M e₁ p₁).natAbs = (rel4EvenEntry M e₂ p₂).natAbs) : e₁ = e₂ ∧ p₁ = p₂ := by rw [rel4EvenEntry_natAbs_eq, rel4EvenEntry_natAbs_eq] at h have hd := congrArg (decodeRel4EvenMag M) h rw [decodeRel4EvenMag_spec, decodeRel4EvenMag_spec] at hd simp only [Prod.mk.injEq] at hd exact ⟨Fin.ext hd.1, Prod.ext (Fin.ext hd.2.1) (Fin.ext hd.2.2)⟩ /-! ## 8. Universal 4-Pair `4 × 8` Gadget (`univ4x8`) & Odd `6 × 12` Seams -/ def univ4x8Sgn : Fin 8 → ℤ | ⟨0, _⟩ => 1 | ⟨1, _⟩ => -1 | ⟨2, _⟩ => 1 | ⟨3, _⟩ => -1 | ⟨4, _⟩ => 1 | ⟨5, _⟩ => -1 | ⟨6, _⟩ => 1 | ⟨7, _⟩ => -1 lemma univ4x8Sgn_natAbs (c : Fin 8) : (univ4x8Sgn c).natAbs = 1 := by fin_cases c <;> decide def univ4x8Row : Fin 8 → Fin 3 → Fin 4 | ⟨0, _⟩ => ![0, 1, 2] | ⟨1, _⟩ => ![0, 1, 2] | ⟨2, _⟩ => ![1, 0, 3] | ⟨3, _⟩ => ![1, 0, 3] | ⟨4, _⟩ => ![2, 0, 3] | ⟨5, _⟩ => ![2, 0, 3] | ⟨6, _⟩ => ![3, 1, 2] | ⟨7, _⟩ => ![3, 1, 2] def univ4x8Slot (r : Fin 4) (c : Fin 8) : Option (Fin 3) := slotOfPlacement univ4x8Row r c lemma univ4x8Row_inj (c : Fin 8) : Function.Injective (univ4x8Row c) := by revert c; decide lemma univ4x8Slot_row_card (r : Fin 4) : (Finset.univ.filter (fun c : Fin 8 => (univ4x8Slot r c).isSome)).card = 6 := by revert r; decide lemma univ4x8Slot_col_uniq (c : Fin 8) (e : Fin 3) : ∃! r : Fin 4, univ4x8Slot r c = some e := by refine ⟨univ4x8Row c e, (slotOfPlacement_eq_some_iff univ4x8Row univ4x8Row_inj _ c e).mpr rfl, ?_⟩ intro r hr; exact ((slotOfPlacement_eq_some_iff univ4x8Row univ4x8Row_inj r c e).mp hr).symm lemma univ4x8_filterMap_row (r : Fin 4) (f : Fin 8 → Fin 3 → ℤ) : (List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (f c)) = match r with | ⟨0, _⟩ => [f ⟨0, by omega⟩ ⟨0, by omega⟩, f ⟨1, by omega⟩ ⟨0, by omega⟩, f ⟨2, by omega⟩ ⟨1, by omega⟩, f ⟨3, by omega⟩ ⟨1, by omega⟩, f ⟨4, by omega⟩ ⟨1, by omega⟩, f ⟨5, by omega⟩ ⟨1, by omega⟩] | ⟨1, _⟩ => [f ⟨0, by omega⟩ ⟨1, by omega⟩, f ⟨1, by omega⟩ ⟨1, by omega⟩, f ⟨2, by omega⟩ ⟨0, by omega⟩, f ⟨3, by omega⟩ ⟨0, by omega⟩, f ⟨6, by omega⟩ ⟨1, by omega⟩, f ⟨7, by omega⟩ ⟨1, by omega⟩] | ⟨2, _⟩ => [f ⟨0, by omega⟩ ⟨2, by omega⟩, f ⟨1, by omega⟩ ⟨2, by omega⟩, f ⟨4, by omega⟩ ⟨0, by omega⟩, f ⟨5, by omega⟩ ⟨0, by omega⟩, f ⟨6, by omega⟩ ⟨2, by omega⟩, f ⟨7, by omega⟩ ⟨2, by omega⟩] | ⟨3, _⟩ => [f ⟨2, by omega⟩ ⟨2, by omega⟩, f ⟨3, by omega⟩ ⟨2, by omega⟩, f ⟨4, by omega⟩ ⟨2, by omega⟩, f ⟨5, by omega⟩ ⟨2, by omega⟩, f ⟨6, by omega⟩ ⟨0, by omega⟩, f ⟨7, by omega⟩ ⟨0, by omega⟩] := by fin_cases r <;> rfl def univ4x8Col (M j₀ : ℕ) (hj : j₀ + 2 ≤ M) : Fin 8 → Fin 4 × Fin M | ⟨0, _⟩ => (0, ⟨j₀, by omega⟩) | ⟨1, _⟩ => (0, ⟨j₀ + 1, by omega⟩) | ⟨2, _⟩ => (1, ⟨j₀, by omega⟩) | ⟨3, _⟩ => (1, ⟨j₀ + 1, by omega⟩) | ⟨4, _⟩ => (2, ⟨j₀, by omega⟩) | ⟨5, _⟩ => (2, ⟨j₀ + 1, by omega⟩) | ⟨6, _⟩ => (3, ⟨j₀, by omega⟩) | ⟨7, _⟩ => (3, ⟨j₀ + 1, by omega⟩) lemma univ4x8_rel3Even_row_sum (M j₀ : ℕ) (hj : j₀ + 2 ≤ M) (r : Fin 4) : ∑ c : Fin 8, ((univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel3EvenEntry M e (univ4x8Col M j₀ hj c))).getD 0 = 0 := by rw [← sum_filterMap_finRange, univ4x8_filterMap_row] fin_cases r <;> (simp only [List.sum_cons, List.sum_nil, add_zero, univ4x8Sgn, univ4x8Col, rel3EvenEntry]; omega) lemma univ4x8_rel3Even_row_simple (M j₀ : ℕ) (hj : j₀ + 2 ≤ M) (r : Fin 4) (hsum : ((List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel3EvenEntry M e (univ4x8Col M j₀ hj c)))).sum = 0) (hbnd : ∀ x ∈ (List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel3EvenEntry M e (univ4x8Col M j₀ hj c))), 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * (12 * M) + 3) (hnod : (((List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel3EvenEntry M e (univ4x8Col M j₀ hj c)))).map Int.natAbs).Nodup) : IsSimpleList (2 * (12 * M) + 3) ((List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel3EvenEntry M e (univ4x8Col M j₀ hj c)))) := by rw [univ4x8_filterMap_row] at hsum hbnd hnod ⊢ fin_cases r <;> ( dsimp only at hsum hbnd hnod ⊢ apply isSimpleList_of_len_six_rel _ _ _ _ _ _ (by simp only [List.sum_cons, List.sum_nil, add_zero] at hsum; omega) hbnd hnod all_goals (simp only [univ4x8Sgn, univ4x8Col, rel3EvenEntry]; omega)) lemma univ4x8_rel4Even_row_sum (M j₀ : ℕ) (hj : j₀ + 2 ≤ M) (r : Fin 4) : ∑ c : Fin 8, ((univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel4EvenEntry M e (univ4x8Col M j₀ hj c))).getD 0 = 0 := by rw [← sum_filterMap_finRange, univ4x8_filterMap_row] fin_cases r <;> (simp only [List.sum_cons, List.sum_nil, add_zero, univ4x8Sgn, univ4x8Col, rel4EvenEntry]; omega) lemma univ4x8_rel4Even_row_simple (M j₀ : ℕ) (hj : j₀ + 2 ≤ M) (r : Fin 4) (hsum : ((List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel4EvenEntry M e (univ4x8Col M j₀ hj c)))).sum = 0) (hbnd : ∀ x ∈ (List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel4EvenEntry M e (univ4x8Col M j₀ hj c))), 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * (12 * M) + 4) (hnod : (((List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel4EvenEntry M e (univ4x8Col M j₀ hj c)))).map Int.natAbs).Nodup) : IsSimpleList (2 * (12 * M) + 4) ((List.finRange 8).filterMap (fun c => (univ4x8Slot r c).map (fun e => univ4x8Sgn c * rel4EvenEntry M e (univ4x8Col M j₀ hj c)))) := by rw [univ4x8_filterMap_row] at hsum hbnd hnod ⊢ fin_cases r <;> ( dsimp only at hsum hbnd hnod ⊢ apply isSimpleList_of_len_six_rel _ _ _ _ _ _ (by simp only [List.sum_cons, List.sum_nil, add_zero] at hsum; omega) hbnd hnod all_goals (simp only [univ4x8Sgn, univ4x8Col, rel4EvenEntry]; omega)) def oddSeam12Col (M : ℕ) (hM : 3 ≤ M) : Fin 12 → Fin 4 × Fin M | ⟨0, _⟩ => (⟨0, by omega⟩, ⟨0, by omega⟩) | ⟨1, _⟩ => (⟨0, by omega⟩, ⟨1, by omega⟩) | ⟨2, _⟩ => (⟨0, by omega⟩, ⟨2, by omega⟩) | ⟨3, _⟩ => (⟨1, by omega⟩, ⟨0, by omega⟩) | ⟨4, _⟩ => (⟨1, by omega⟩, ⟨1, by omega⟩) | ⟨5, _⟩ => (⟨1, by omega⟩, ⟨2, by omega⟩) | ⟨6, _⟩ => (⟨2, by omega⟩, ⟨0, by omega⟩) | ⟨7, _⟩ => (⟨2, by omega⟩, ⟨1, by omega⟩) | ⟨8, _⟩ => (⟨2, by omega⟩, ⟨2, by omega⟩) | ⟨9, _⟩ => (⟨3, by omega⟩, ⟨0, by omega⟩) | ⟨10, _⟩ => (⟨3, by omega⟩, ⟨1, by omega⟩) | ⟨11, _⟩ => (⟨3, by omega⟩, ⟨2, by omega⟩) def rel3OddSeamSgn : 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 lemma rel3OddSeamSgn_natAbs (c : Fin 12) : (rel3OddSeamSgn c).natAbs = 1 := by fin_cases c <;> decide def rel3OddSeamRow : Fin 12 → Fin 3 → Fin 6 | ⟨0, _⟩ => ![0, 3, 2] | ⟨1, _⟩ => ![4, 2, 0] | ⟨2, _⟩ => ![2, 4, 3] | ⟨3, _⟩ => ![1, 0, 5] | ⟨4, _⟩ => ![2, 4, 3] | ⟨5, _⟩ => ![0, 3, 5] | ⟨6, _⟩ => ![1, 5, 4] | ⟨7, _⟩ => ![4, 3, 5] | ⟨8, _⟩ => ![4, 1, 5] | ⟨9, _⟩ => ![1, 3, 2] | ⟨10, _⟩ => ![1, 0, 2] | ⟨11, _⟩ => ![0, 5, 1] def rel3OddSeamSlot (r : Fin 6) (c : Fin 12) : Option (Fin 3) := slotOfPlacement rel3OddSeamRow r c lemma rel3OddSeamRow_inj (c : Fin 12) : Function.Injective (rel3OddSeamRow c) := by revert c; decide lemma rel3OddSeamSlot_row_card (r : Fin 6) : (Finset.univ.filter (fun c : Fin 12 => (rel3OddSeamSlot r c).isSome)).card = 6 := by revert r; decide lemma rel3OddSeamSlot_col_uniq (c : Fin 12) (e : Fin 3) : ∃! r : Fin 6, rel3OddSeamSlot r c = some e := by refine ⟨rel3OddSeamRow c e, (slotOfPlacement_eq_some_iff rel3OddSeamRow rel3OddSeamRow_inj _ c e).mpr rfl, ?_⟩ intro r hr; exact ((slotOfPlacement_eq_some_iff rel3OddSeamRow rel3OddSeamRow_inj r c e).mp hr).symm lemma rel3OddSeam_filterMap_row (r : Fin 6) (f : Fin 12 → Fin 3 → ℤ) : (List.finRange 12).filterMap (fun c => (rel3OddSeamSlot r c).map (f c)) = match r with | ⟨0, _⟩ => [f ⟨0, by omega⟩ ⟨0, by omega⟩, f ⟨1, by omega⟩ ⟨2, by omega⟩, f ⟨3, by omega⟩ ⟨1, by omega⟩, f ⟨5, by omega⟩ ⟨0, by omega⟩, f ⟨10, by omega⟩ ⟨1, by omega⟩, f ⟨11, by omega⟩ ⟨0, by omega⟩] | ⟨1, _⟩ => [f ⟨3, by omega⟩ ⟨0, by omega⟩, f ⟨6, by omega⟩ ⟨0, by omega⟩, f ⟨8, by omega⟩ ⟨1, by omega⟩, f ⟨9, by omega⟩ ⟨0, by omega⟩, f ⟨10, by omega⟩ ⟨0, by omega⟩, f ⟨11, by omega⟩ ⟨2, by omega⟩] | ⟨2, _⟩ => [f ⟨0, by omega⟩ ⟨2, by omega⟩, f ⟨1, by omega⟩ ⟨1, by omega⟩, f ⟨2, by omega⟩ ⟨0, by omega⟩, f ⟨4, by omega⟩ ⟨0, by omega⟩, f ⟨9, by omega⟩ ⟨2, by omega⟩, f ⟨10, by omega⟩ ⟨2, by omega⟩] | ⟨3, _⟩ => [f ⟨0, by omega⟩ ⟨1, by omega⟩, f ⟨2, by omega⟩ ⟨2, by omega⟩, f ⟨4, by omega⟩ ⟨2, by omega⟩, f ⟨5, by omega⟩ ⟨1, by omega⟩, f ⟨7, by omega⟩ ⟨1, by omega⟩, f ⟨9, by omega⟩ ⟨1, by omega⟩] | ⟨4, _⟩ => [f ⟨1, by omega⟩ ⟨0, by omega⟩, f ⟨2, by omega⟩ ⟨1, by omega⟩, f ⟨4, by omega⟩ ⟨1, by omega⟩, f ⟨6, by omega⟩ ⟨2, by omega⟩, f ⟨7, by omega⟩ ⟨0, by omega⟩, f ⟨8, by omega⟩ ⟨0, by omega⟩] | ⟨5, _⟩ => [f ⟨3, by omega⟩ ⟨2, by omega⟩, f ⟨5, by omega⟩ ⟨2, by omega⟩, f ⟨6, by omega⟩ ⟨1, by omega⟩, f ⟨7, by omega⟩ ⟨2, by omega⟩, f ⟨8, by omega⟩ ⟨2, by omega⟩, f ⟨11, by omega⟩ ⟨1, by omega⟩] := by fin_cases r <;> rfl lemma rel3OddSeam_row_sum (M : ℕ) (hM : 3 ≤ M) (r : Fin 6) : ∑ c : Fin 12, ((rel3OddSeamSlot r c).map (fun e => rel3OddSeamSgn c * rel3EvenEntry M e (oddSeam12Col M hM c))).getD 0 = 0 := by rw [← sum_filterMap_finRange, rel3OddSeam_filterMap_row] fin_cases r <;> (simp only [List.sum_cons, List.sum_nil, add_zero, rel3OddSeamSgn, oddSeam12Col, rel3EvenEntry]; omega) lemma rel3OddSeam_row_simple (M : ℕ) (hM : 3 ≤ M) (r : Fin 6) (hsum : ((List.finRange 12).filterMap (fun c => (rel3OddSeamSlot r c).map (fun e => rel3OddSeamSgn c * rel3EvenEntry M e (oddSeam12Col M hM c)))).sum = 0) (hbnd : ∀ x ∈ (List.finRange 12).filterMap (fun c => (rel3OddSeamSlot r c).map (fun e => rel3OddSeamSgn c * rel3EvenEntry M e (oddSeam12Col M hM c))), 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * (12 * M) + 3) (hnod : (((List.finRange 12).filterMap (fun c => (rel3OddSeamSlot r c).map (fun e => rel3OddSeamSgn c * rel3EvenEntry M e (oddSeam12Col M hM c)))).map Int.natAbs).Nodup) : IsSimpleList (2 * (12 * M) + 3) ((List.finRange 12).filterMap (fun c => (rel3OddSeamSlot r c).map (fun e => rel3OddSeamSgn c * rel3EvenEntry M e (oddSeam12Col M hM c)))) := by rw [rel3OddSeam_filterMap_row] at hsum hbnd hnod ⊢ fin_cases r <;> ( dsimp only at hsum hbnd hnod ⊢ apply isSimpleList_of_len_six_rel _ _ _ _ _ _ (by simp only [List.sum_cons, List.sum_nil, add_zero] at hsum; omega) hbnd hnod all_goals (simp only [rel3OddSeamSgn, oddSeam12Col, rel3EvenEntry]; omega)) def rel4OddSeamSgn : 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 lemma rel4OddSeamSgn_natAbs (c : Fin 12) : (rel4OddSeamSgn c).natAbs = 1 := by fin_cases c <;> decide def rel4OddSeamRow : Fin 12 → Fin 3 → Fin 6 | ⟨0, _⟩ => ![5, 2, 4] | ⟨1, _⟩ => ![1, 0, 2] | ⟨2, _⟩ => ![1, 5, 2] | ⟨3, _⟩ => ![5, 4, 3] | ⟨4, _⟩ => ![0, 2, 5] | ⟨5, _⟩ => ![1, 0, 3] | ⟨6, _⟩ => ![3, 0, 1] | ⟨7, _⟩ => ![0, 1, 4] | ⟨8, _⟩ => ![4, 2, 5] | ⟨9, _⟩ => ![3, 4, 2] | ⟨10, _⟩ => ![4, 5, 3] | ⟨11, _⟩ => ![1, 0, 3] def rel4OddSeamSlot (r : Fin 6) (c : Fin 12) : Option (Fin 3) := slotOfPlacement rel4OddSeamRow r c lemma rel4OddSeamRow_inj (c : Fin 12) : Function.Injective (rel4OddSeamRow c) := by revert c; decide lemma rel4OddSeamSlot_row_card (r : Fin 6) : (Finset.univ.filter (fun c : Fin 12 => (rel4OddSeamSlot r c).isSome)).card = 6 := by revert r; decide lemma rel4OddSeamSlot_col_uniq (c : Fin 12) (e : Fin 3) : ∃! r : Fin 6, rel4OddSeamSlot r c = some e := by refine ⟨rel4OddSeamRow c e, (slotOfPlacement_eq_some_iff rel4OddSeamRow rel4OddSeamRow_inj _ c e).mpr rfl, ?_⟩ intro r hr; exact ((slotOfPlacement_eq_some_iff rel4OddSeamRow rel4OddSeamRow_inj r c e).mp hr).symm lemma rel4OddSeam_filterMap_row (r : Fin 6) (f : Fin 12 → Fin 3 → ℤ) : (List.finRange 12).filterMap (fun c => (rel4OddSeamSlot r c).map (f c)) = match r with | ⟨0, _⟩ => [f ⟨1, by omega⟩ ⟨1, by omega⟩, f ⟨4, by omega⟩ ⟨0, by omega⟩, f ⟨5, by omega⟩ ⟨1, by omega⟩, f ⟨6, by omega⟩ ⟨1, by omega⟩, f ⟨7, by omega⟩ ⟨0, by omega⟩, f ⟨11, by omega⟩ ⟨1, by omega⟩] | ⟨1, _⟩ => [f ⟨1, by omega⟩ ⟨0, by omega⟩, f ⟨2, by omega⟩ ⟨0, by omega⟩, f ⟨5, by omega⟩ ⟨0, by omega⟩, f ⟨6, by omega⟩ ⟨2, by omega⟩, f ⟨7, by omega⟩ ⟨1, by omega⟩, f ⟨11, by omega⟩ ⟨0, by omega⟩] | ⟨2, _⟩ => [f ⟨0, by omega⟩ ⟨1, by omega⟩, f ⟨1, by omega⟩ ⟨2, by omega⟩, f ⟨2, by omega⟩ ⟨2, by omega⟩, f ⟨4, by omega⟩ ⟨1, by omega⟩, f ⟨8, by omega⟩ ⟨1, by omega⟩, f ⟨9, by omega⟩ ⟨2, by omega⟩] | ⟨3, _⟩ => [f ⟨3, by omega⟩ ⟨2, by omega⟩, f ⟨5, by omega⟩ ⟨2, by omega⟩, f ⟨6, by omega⟩ ⟨0, by omega⟩, f ⟨9, by omega⟩ ⟨0, by omega⟩, f ⟨10, by omega⟩ ⟨2, by omega⟩, f ⟨11, by omega⟩ ⟨2, by omega⟩] | ⟨4, _⟩ => [f ⟨0, by omega⟩ ⟨2, by omega⟩, f ⟨3, by omega⟩ ⟨1, by omega⟩, f ⟨7, by omega⟩ ⟨2, by omega⟩, f ⟨8, by omega⟩ ⟨0, by omega⟩, f ⟨9, by omega⟩ ⟨1, by omega⟩, f ⟨10, by omega⟩ ⟨0, by omega⟩] | ⟨5, _⟩ => [f ⟨0, by omega⟩ ⟨0, by omega⟩, f ⟨2, by omega⟩ ⟨1, by omega⟩, f ⟨3, by omega⟩ ⟨0, by omega⟩, f ⟨4, by omega⟩ ⟨2, by omega⟩, f ⟨8, by omega⟩ ⟨2, by omega⟩, f ⟨10, by omega⟩ ⟨1, by omega⟩] := by fin_cases r <;> rfl lemma rel4OddSeam_row_sum (M : ℕ) (hM : 3 ≤ M) (r : Fin 6) : ∑ c : Fin 12, ((rel4OddSeamSlot r c).map (fun e => rel4OddSeamSgn c * rel4EvenEntry M e (oddSeam12Col M hM c))).getD 0 = 0 := by rw [← sum_filterMap_finRange, rel4OddSeam_filterMap_row] fin_cases r <;> (simp only [List.sum_cons, List.sum_nil, add_zero, rel4OddSeamSgn, oddSeam12Col, rel4EvenEntry]; omega) lemma rel4OddSeam_row_simple (M : ℕ) (hM : 3 ≤ M) (r : Fin 6) (hsum : ((List.finRange 12).filterMap (fun c => (rel4OddSeamSlot r c).map (fun e => rel4OddSeamSgn c * rel4EvenEntry M e (oddSeam12Col M hM c)))).sum = 0) (hbnd : ∀ x ∈ (List.finRange 12).filterMap (fun c => (rel4OddSeamSlot r c).map (fun e => rel4OddSeamSgn c * rel4EvenEntry M e (oddSeam12Col M hM c))), 1 ≤ x.natAbs ∧ 2 * x.natAbs < 2 * (12 * M) + 4) (hnod : (((List.finRange 12).filterMap (fun c => (rel4OddSeamSlot r c).map (fun e => rel4OddSeamSgn c * rel4EvenEntry M e (oddSeam12Col M hM c)))).map Int.natAbs).Nodup) : IsSimpleList (2 * (12 * M) + 4) ((List.finRange 12).filterMap (fun c => (rel4OddSeamSlot r c).map (fun e => rel4OddSeamSgn c * rel4EvenEntry M e (oddSeam12Col M hM c)))) := by rw [rel4OddSeam_filterMap_row] at hsum hbnd hnod ⊢ fin_cases r <;> ( dsimp only at hsum hbnd hnod ⊢ apply isSimpleList_of_len_six_rel _ _ _ _ _ _ (by simp only [List.sum_cons, List.sum_nil, add_zero] at hsum; omega) hbnd hnod all_goals (simp only [rel4OddSeamSgn, oddSeam12Col, rel4EvenEntry]; omega)) /-! ## 9. Complete Assembly for Ray `(k = 3, s = 6, t = 3)`: All `K ≥ 2` -/ noncomputable def gs_rel3_3_6_even (B : ℕ) : GloballySimpleRelativeHeffterArray (2 * (2 * B)) (4 * (2 * B)) 6 3 3 := by let M := 2 * B let blkCol : Fin B → Fin 8 → Fin 4 × Fin M := fun b => univ4x8Col M (2 * b.val) (by have := b.isLt; omega) let decodeCol : Fin 4 × Fin M → ℕ × ℕ := fun p => (p.2.val / 2, 2 * p.1.val + p.2.val % 2) have hdecBlk : ∀ b c, decodeCol (blkCol b c) = (b.val, c.val) := by intro b c; fin_cases c <;> (simp only [blkCol, univ4x8Col, decodeCol, Prod.mk.injEq]; omega) have hN : 8 * B * 3 = 12 * M := by omega refine GloballySimpleRelativeHeffterArray.cast (by omega) (by omega) (ofUniformBlocksRelSimpleKLe5 (m₁ := 4) (n₁ := 8) (B := B) (s := 6) (k := 3) (t := 3) (by omega) ⟨16 * B, by omega⟩ (by omega) (rel3EvenEntry M) blkCol (fun _ c => univ4x8Sgn c) (fun _ r c => univ4x8Slot r c) (by omega) (by omega) (rel3EvenEntry_col_sum M) (fun e x h => by have hp := rel3EvenMag_pos M e x; rw [← rel3EvenEntry_natAbs_eq] at hp; rw [h] at hp; simp at hp) (fun e x => by rw [hN, relHalfMax_three, rel3EvenEntry_natAbs_eq]; exact rel3EvenMag_le M e x) (fun e x => by rw [hN, relStep_three, rel3EvenEntry_natAbs_eq]; exact rel3EvenMag_not_dvd M e x) (rel3EvenEntry_natAbs_inj M) (fun _ c => univ4x8Sgn_natAbs c) (fun _ r => univ4x8Slot_row_card r) (fun _ c e => univ4x8Slot_col_uniq c e) (fun b r => univ4x8_rel3Even_row_sum M (2 * b.val) (by have := b.isLt; omega) r) (fun b₁ c₁ b₂ c₂ h => by have hd := congrArg decodeCol h; rw [hdecBlk, hdecBlk] at hd simp only [Prod.mk.injEq] at hd; exact ⟨Fin.ext hd.1, Fin.ext hd.2⟩) (fun b r hsum hbnd hnod => by rw [hN] at hbnd ⊢ exact univ4x8_rel3Even_row_simple M (2 * b.val) (by have := b.isLt; omega) r hsum hbnd hnod)) noncomputable def gs_rel3_3_6_odd (Q : ℕ) : GloballySimpleRelativeHeffterArray (2 * (2 * Q + 3)) (4 * (2 * Q + 3)) 6 3 3 := by let M := 2 * Q + 3 have hM3 : 3 ≤ M := by omega let seamCol := oddSeam12Col M hM3 let blkCol : Fin Q → Fin 8 → Fin 4 × Fin M := fun q => univ4x8Col M (3 + 2 * q.val) (by have := q.isLt; omega) let decodeCol : Fin 4 × Fin M → ℕ × ℕ × ℕ := fun p => if p.2.val < 3 then (0, 0, 3 * p.1.val + p.2.val) else (1, (p.2.val - 3) / 2, 2 * p.1.val + (p.2.val - 3) % 2) have hdecSeam : ∀ c : Fin 12, decodeCol (seamCol c) = (0, 0, c.val) := by intro c; fin_cases c <;> simp only [seamCol, oddSeam12Col, decodeCol] <;> rfl have hdecBlk : ∀ q c, decodeCol (blkCol q c) = (1, q.val, c.val) := by intro q c; fin_cases c <;> ( simp only [blkCol, univ4x8Col, decodeCol] rw [if_neg (by omega)] simp only [Prod.mk.injEq, true_and]; omega) have hN : (12 + 8 * Q) * 3 = 12 * M := by omega refine GloballySimpleRelativeHeffterArray.cast (by omega) (by omega) (ofSeamAndUniformBlocksRelSimpleKLe5 (m₀ := 6) (n₀ := 12) (m₁ := 4) (n₁ := 8) (B := Q) (s := 6) (k := 3) (t := 3) (by omega) ⟨8 * M, by omega⟩ (by omega) (rel3EvenEntry M) seamCol rel3OddSeamSgn rel3OddSeamSlot blkCol (fun _ c => univ4x8Sgn c) (fun _ r c => univ4x8Slot r c) (by omega) (by omega) (rel3EvenEntry_col_sum M) (fun e x h => by have hp := rel3EvenMag_pos M e x; rw [← rel3EvenEntry_natAbs_eq] at hp; rw [h] at hp; simp at hp) (fun e x => by rw [hN, relHalfMax_three, rel3EvenEntry_natAbs_eq]; exact rel3EvenMag_le M e x) (fun e x => by rw [hN, relStep_three, rel3EvenEntry_natAbs_eq]; exact rel3EvenMag_not_dvd M e x) (rel3EvenEntry_natAbs_inj M) rel3OddSeamSgn_natAbs (fun _ c => univ4x8Sgn_natAbs c) rel3OddSeamSlot_row_card rel3OddSeamSlot_col_uniq (rel3OddSeam_row_sum M hM3) (fun _ r => univ4x8Slot_row_card r) (fun _ c e => univ4x8Slot_col_uniq c e) (fun q r => univ4x8_rel3Even_row_sum M (3 + 2 * q.val) (by have := q.isLt; omega) r) (fun c₁ c₂ h => by have hd := congrArg decodeCol h; rw [hdecSeam, hdecSeam] at hd simp only [Prod.mk.injEq, true_and] at hd; exact Fin.ext hd) (fun b₁ c₁ b₂ c₂ h => by have hd := congrArg decodeCol h; rw [hdecBlk, hdecBlk] at hd simp only [Prod.mk.injEq, true_and] at hd; exact ⟨Fin.ext hd.1, Fin.ext hd.2⟩) (fun c₀ b c₁ h => by have hd := congrArg decodeCol h; rw [hdecSeam, hdecBlk] at hd; simp at hd) (fun r hsum hbnd hnod => by rw [hN] at hbnd ⊢; exact rel3OddSeam_row_simple M hM3 r hsum hbnd hnod) (fun q r hsum hbnd hnod => by rw [hN] at hbnd ⊢ exact univ4x8_rel3Even_row_simple M (3 + 2 * q.val) (by have := q.isLt; omega) r hsum hbnd hnod)) /-- **Main Theorem (Globally Simple Relative Ray `(k = 3, s = 6, t = 3)`)**: For every `K ≥ 2`, `SH_3(2K, 4K; 6, 3)` exists. -/ theorem exists_gs_rel3_heffter_3_6 (K : ℕ) (hK : 2 ≤ K) : Nonempty (GloballySimpleRelativeHeffterArray (2 * K) (4 * K) 6 3 3) := by by_cases hpar : K % 2 = 0 · have hEq : K = 2 * (K / 2) := by omega rw [hEq]; exact ⟨gs_rel3_3_6_even (K / 2)⟩ · have hEq : K = 2 * ((K - 3) / 2) + 3 := by omega rw [hEq]; exact ⟨gs_rel3_3_6_odd ((K - 3) / 2)⟩ private lemma two_mul_sum_Icc_one (N : ℕ) : 2 * ∑ x ∈ Finset.Icc 1 N, x = N * (N + 1) := by induction N with | zero => simp | succ k ih => have hIcc : Finset.Icc 1 (k + 1) = insert (k + 1) (Finset.Icc 1 k) := by ext x; simp only [Finset.mem_Icc, Finset.mem_insert]; omega rw [hIcc, Finset.sum_insert (by simp), mul_add, ih] ring /-- **Exact Parity Obstruction (`t = 3`, `(s, k) = (6, 3)`)**: When `m * 6 = n * 3`, the relative half-set `{1..6m+1} \ {4m+1}` has sum `18 m² + 5 m ≡ m (mod 2)`, so any integer relative Heffter array `H_3(m, n; 6, 3)` requires `2 ∣ m`. -/ theorem rel3_ray_3_6_even_necessary (m n : ℕ) (hmn : m * 6 = n * 3) (H : IntRelativeHeffterArray m n 6 3 3) : 2 ∣ m := by have hN : n * 3 = 6 * m := by omega have hev := H.even_halfSet_sum rw [hN] at hev have hset : relHalfSet (6 * m) 3 = (Finset.Icc 1 (6 * m + 1)).erase (4 * m + 1) := by ext x simp only [relHalfSet, Finset.mem_filter, Finset.mem_erase, Finset.mem_Icc] have hmax : relHalfMax (6 * m) 3 = 6 * m + 1 := by simp only [relHalfMax]; omega have hstep : relStep (6 * m) 3 = 4 * m + 1 := by simp only [relStep]; omega rw [hmax, hstep] constructor · rintro ⟨⟨h1, h2⟩, hnd⟩ refine ⟨?_, h1, h2⟩ intro heq; rw [heq] at hnd; exact hnd (dvd_refl _) · rintro ⟨hne, h1, h2⟩ refine ⟨⟨h1, h2⟩, ?_⟩ rintro ⟨c, hc⟩ have hc0 : c ≠ 0 := by intro h; rw [h, mul_zero] at hc; omega have hc1 : c ≠ 1 := by intro h; rw [h, mul_one] at hc; exact hne hc have hc2 : 2 ≤ c := by omega have hge : 2 * (4 * m + 1) ≤ (4 * m + 1) * c := by calc 2 * (4 * m + 1) = (4 * m + 1) * 2 := by ring _ ≤ (4 * m + 1) * c := Nat.mul_le_mul_left _ hc2 omega have hmem : 4 * m + 1 ∈ Finset.Icc 1 (6 * m + 1) := by simp only [Finset.mem_Icc]; omega have hsum_add : (∑ x ∈ relHalfSet (6 * m) 3, x) + (4 * m + 1) = ∑ x ∈ Finset.Icc 1 (6 * m + 1), x := by rw [hset, add_comm] exact Finset.add_sum_erase (Finset.Icc 1 (6 * m + 1)) id hmem have htri := two_mul_sum_Icc_one (6 * m + 1) have hsum_eq : ∑ x ∈ Finset.Icc 1 (6 * m + 1), x = (6 * m + 1) * (3 * m + 1) := by have h2 : 2 * ((6 * m + 1) * (3 * m + 1)) = (6 * m + 1) * (6 * m + 1 + 1) := by ring omega have htot : (∑ x ∈ relHalfSet (6 * m) 3, x) + (4 * m + 1) = 18 * (m * m) + 9 * m + 1 := by rw [hsum_add, hsum_eq]; ring rcases hev with ⟨r, hr⟩ omega /-- **Complete Exact Characterization of Globally Simple Relative Ray `(k = 3, s = 6, t = 3)`**: For EVERY `m ≥ 3` with `m * 6 = n * 3`, `SH_3(m, n; 6, 3)` exists **if and only if** `2 ∣ m`. -/ theorem gs_rel3_ray_3_6_complete (m n : ℕ) (hm : 3 ≤ m) (hmn : m * 6 = n * 3) : Nonempty (GloballySimpleRelativeHeffterArray m n 6 3 3) ↔ 2 ∣ m := by constructor · rintro ⟨H⟩ exact rel3_ray_3_6_even_necessary m n hmn H.toIntRelativeHeffterArray · rintro ⟨K, rfl⟩ have hn : n = 4 * K := by omega subst hn exact exists_gs_rel3_heffter_3_6 K (by omega) /-- **Transpose Characterization (`t = 3`)**: For EVERY `n ≥ 3` with `m * 3 = n * 6`, `SH_3(m, n; 3, 6)` exists **if and only if** `2 ∣ n`. -/ theorem gs_rel3_ray_3_6_complete_transpose (m n : ℕ) (hn : 3 ≤ n) (hmn : m * 3 = n * 6) : Nonempty (GloballySimpleRelativeHeffterArray m n 3 6 3) ↔ 2 ∣ n := by constructor · rintro ⟨H⟩ exact (gs_rel3_ray_3_6_complete n m hn hmn.symm).mp ⟨H.transpose⟩ · intro hn2 obtain ⟨H⟩ := (gs_rel3_ray_3_6_complete n m hn hmn.symm).mpr hn2 exact ⟨H.transpose⟩ /-- **Multipartite Graph-Theoretic Corollary (`t = 3`)**: For EVERY `K ≥ 2`, the complete multipartite graph `K_{(8K + 1) × 3}` admits a pair of **orthogonal cyclic** `6`-cycle and `3`-cycle decompositions. -/ theorem orthogonal_cyclic_multipartite_6_3_t3 (K : ℕ) (hK : 2 ≤ K) : ∃ (D₆ : CyclicMultipartiteCycleDecomp (2 * (4 * K * 3) + 3) 3 (2 * K) 6) (D₃ : CyclicMultipartiteCycleDecomp (2 * (4 * K * 3) + 3) 3 (4 * K) 3), OrthogonalCyclicMultipartiteDecomps D₆ D₃ := by obtain ⟨H⟩ := exists_gs_rel3_heffter_3_6 K hK exact ⟨H.rowCycleDecomp, H.colCycleDecomp, H.toOrthogonalCyclicMultipartiteDecomps⟩ /-! ## 10. Complete Assembly for Ray `(k = 3, s = 6, t = 4)`: All `K ≥ 2` -/ noncomputable def gs_rel4_3_6_even (B : ℕ) : GloballySimpleRelativeHeffterArray (2 * (2 * B)) (4 * (2 * B)) 6 3 4 := by let M := 2 * B let blkCol : Fin B → Fin 8 → Fin 4 × Fin M := fun b => univ4x8Col M (2 * b.val) (by have := b.isLt; omega) let decodeCol : Fin 4 × Fin M → ℕ × ℕ := fun p => (p.2.val / 2, 2 * p.1.val + p.2.val % 2) have hdecBlk : ∀ b c, decodeCol (blkCol b c) = (b.val, c.val) := by intro b c; fin_cases c <;> (simp only [blkCol, univ4x8Col, decodeCol, Prod.mk.injEq]; omega) have hN : 8 * B * 3 = 12 * M := by omega refine GloballySimpleRelativeHeffterArray.cast (by omega) (by omega) (ofUniformBlocksRelSimpleKLe5 (m₁ := 4) (n₁ := 8) (B := B) (s := 6) (k := 3) (t := 4) (by omega) ⟨12 * B, by omega⟩ (by omega) (rel4EvenEntry M) blkCol (fun _ c => univ4x8Sgn c) (fun _ r c => univ4x8Slot r c) (by omega) (by omega) (rel4EvenEntry_col_sum M) (fun e x h => by have hp := rel4EvenMag_pos M e x; rw [← rel4EvenEntry_natAbs_eq] at hp; rw [h] at hp; simp at hp) (fun e x => by rw [hN, relHalfMax_four_even, rel4EvenEntry_natAbs_eq]; exact rel4EvenMag_le M e x) (fun e x => by rw [hN, relStep_four_even, rel4EvenEntry_natAbs_eq]; exact rel4EvenMag_not_dvd M e x) (rel4EvenEntry_natAbs_inj M) (fun _ c => univ4x8Sgn_natAbs c) (fun _ r => univ4x8Slot_row_card r) (fun _ c e => univ4x8Slot_col_uniq c e) (fun b r => univ4x8_rel4Even_row_sum M (2 * b.val) (by have := b.isLt; omega) r) (fun b₁ c₁ b₂ c₂ h => by have hd := congrArg decodeCol h; rw [hdecBlk, hdecBlk] at hd simp only [Prod.mk.injEq] at hd; exact ⟨Fin.ext hd.1, Fin.ext hd.2⟩) (fun b r hsum hbnd hnod => by rw [hN] at hbnd ⊢ exact univ4x8_rel4Even_row_simple M (2 * b.val) (by have := b.isLt; omega) r hsum hbnd hnod)) noncomputable def gs_rel4_3_6_odd (Q : ℕ) : GloballySimpleRelativeHeffterArray (2 * (2 * Q + 3)) (4 * (2 * Q + 3)) 6 3 4 := by let M := 2 * Q + 3 have hM3 : 3 ≤ M := by omega let seamCol := oddSeam12Col M hM3 let blkCol : Fin Q → Fin 8 → Fin 4 × Fin M := fun q => univ4x8Col M (3 + 2 * q.val) (by have := q.isLt; omega) let decodeCol : Fin 4 × Fin M → ℕ × ℕ × ℕ := fun p => if p.2.val < 3 then (0, 0, 3 * p.1.val + p.2.val) else (1, (p.2.val - 3) / 2, 2 * p.1.val + (p.2.val - 3) % 2) have hdecSeam : ∀ c : Fin 12, decodeCol (seamCol c) = (0, 0, c.val) := by intro c; fin_cases c <;> simp only [seamCol, oddSeam12Col, decodeCol] <;> rfl have hdecBlk : ∀ q c, decodeCol (blkCol q c) = (1, q.val, c.val) := by intro q c; fin_cases c <;> ( simp only [blkCol, univ4x8Col, decodeCol] rw [if_neg (by omega)] simp only [Prod.mk.injEq, true_and]; omega) have hN : (12 + 8 * Q) * 3 = 12 * M := by omega refine GloballySimpleRelativeHeffterArray.cast (by omega) (by omega) (ofSeamAndUniformBlocksRelSimpleKLe5 (m₀ := 6) (n₀ := 12) (m₁ := 4) (n₁ := 8) (B := Q) (s := 6) (k := 3) (t := 4) (by omega) ⟨6 * M, by omega⟩ (by omega) (rel4EvenEntry M) seamCol rel4OddSeamSgn rel4OddSeamSlot blkCol (fun _ c => univ4x8Sgn c) (fun _ r c => univ4x8Slot r c) (by omega) (by omega) (rel4EvenEntry_col_sum M) (fun e x h => by have hp := rel4EvenMag_pos M e x; rw [← rel4EvenEntry_natAbs_eq] at hp; rw [h] at hp; simp at hp) (fun e x => by rw [hN, relHalfMax_four_even, rel4EvenEntry_natAbs_eq]; exact rel4EvenMag_le M e x) (fun e x => by rw [hN, relStep_four_even, rel4EvenEntry_natAbs_eq]; exact rel4EvenMag_not_dvd M e x) (rel4EvenEntry_natAbs_inj M) rel4OddSeamSgn_natAbs (fun _ c => univ4x8Sgn_natAbs c) rel4OddSeamSlot_row_card rel4OddSeamSlot_col_uniq (rel4OddSeam_row_sum M hM3) (fun _ r => univ4x8Slot_row_card r) (fun _ c e => univ4x8Slot_col_uniq c e) (fun q r => univ4x8_rel4Even_row_sum M (3 + 2 * q.val) (by have := q.isLt; omega) r) (fun c₁ c₂ h => by have hd := congrArg decodeCol h; rw [hdecSeam, hdecSeam] at hd simp only [Prod.mk.injEq, true_and] at hd; exact Fin.ext hd) (fun b₁ c₁ b₂ c₂ h => by have hd := congrArg decodeCol h; rw [hdecBlk, hdecBlk] at hd simp only [Prod.mk.injEq, true_and] at hd; exact ⟨Fin.ext hd.1, Fin.ext hd.2⟩) (fun c₀ b c₁ h => by have hd := congrArg decodeCol h; rw [hdecSeam, hdecBlk] at hd; simp at hd) (fun r hsum hbnd hnod => by rw [hN] at hbnd ⊢; exact rel4OddSeam_row_simple M hM3 r hsum hbnd hnod) (fun q r hsum hbnd hnod => by rw [hN] at hbnd ⊢ exact univ4x8_rel4Even_row_simple M (3 + 2 * q.val) (by have := q.isLt; omega) r hsum hbnd hnod)) /-- **Main Theorem (Globally Simple Relative Ray `(k = 3, s = 6, t = 4)`)**: For every `K ≥ 2`, `SH_4(2K, 4K; 6, 3)` exists. -/ theorem exists_gs_rel4_heffter_3_6 (K : ℕ) (hK : 2 ≤ K) : Nonempty (GloballySimpleRelativeHeffterArray (2 * K) (4 * K) 6 3 4) := by by_cases hpar : K % 2 = 0 · have hEq : K = 2 * (K / 2) := by omega rw [hEq]; exact ⟨gs_rel4_3_6_even (K / 2)⟩ · have hEq : K = 2 * ((K - 3) / 2) + 3 := by omega rw [hEq]; exact ⟨gs_rel4_3_6_odd ((K - 3) / 2)⟩ /-- **Complete Even-Row Resolution of Globally Simple Relative Ray `(k = 3, s = 6, t = 4)`**: For EVERY `m ≥ 3` with `2 ∣ m` and `m * 6 = n * 3` (equivalently `m = 2K, n = 4K`, `K ≥ 2`), `SH_4(m, n; 6, 3)` exists. -/ theorem gs_rel4_ray_3_6_complete (m n : ℕ) (hm : 3 ≤ m) (hm2 : 2 ∣ m) (hmn : m * 6 = n * 3) : Nonempty (GloballySimpleRelativeHeffterArray m n 6 3 4) := by rcases hm2 with ⟨K, rfl⟩ have hn : n = 4 * K := by omega subst hn exact exists_gs_rel4_heffter_3_6 K (by omega) /-- **Transpose Corollary (`t = 4`)**: For EVERY `n ≥ 3` with `2 ∣ n` and `m * 3 = n * 6`, `SH_4(m, n; 3, 6)` exists. -/ theorem gs_rel4_ray_3_6_complete_transpose (m n : ℕ) (hn : 3 ≤ n) (hn2 : 2 ∣ n) (hmn : m * 3 = n * 6) : Nonempty (GloballySimpleRelativeHeffterArray m n 3 6 4) := by obtain ⟨H⟩ := gs_rel4_ray_3_6_complete n m hn hn2 hmn.symm exact ⟨H.transpose⟩ /-- **Multipartite Graph-Theoretic Corollary (`t = 4`)**: For EVERY `K ≥ 2`, the complete multipartite graph `K_{(6K + 1) × 4}` admits a pair of **orthogonal cyclic** `6`-cycle and `3`-cycle decompositions. -/ theorem orthogonal_cyclic_multipartite_6_3_t4 (K : ℕ) (hK : 2 ≤ K) : ∃ (D₆ : CyclicMultipartiteCycleDecomp (2 * (4 * K * 3) + 4) 4 (2 * K) 6) (D₃ : CyclicMultipartiteCycleDecomp (2 * (4 * K * 3) + 4) 4 (4 * K) 3), OrthogonalCyclicMultipartiteDecomps D₆ D₃ := by obtain ⟨H⟩ := exists_gs_rel4_heffter_3_6 K hK exact ⟨H.rowCycleDecomp, H.colCycleDecomp, H.toOrthogonalCyclicMultipartiteDecomps⟩ #print axioms exists_gs_rel3_heffter_3_6 #print axioms gs_rel3_ray_3_6_complete #print axioms gs_rel3_ray_3_6_complete_transpose #print axioms orthogonal_cyclic_multipartite_6_3_t3 #print axioms exists_gs_rel4_heffter_3_6 #print axioms gs_rel4_ray_3_6_complete #print axioms gs_rel4_ray_3_6_complete_transpose #print axioms orthogonal_cyclic_multipartite_6_3_t4 end RelativeRay3x6T3T4