/- NonAbelianWeightedZeroSum.lean ============================================================================== Weighted Product-One (Davenport) Constants in Non-Abelian Groups: Dihedral Groups D_{2n} and Dicyclic Groups Dic_{4n} Headline Results (100% self-contained, zero external axioms): 1. Exact Unweighted Dihedral Davenport Theorem (Olson–White / Zhuang–Gao): D_ord({1}, D_{2n}) = D_unord({1}, D_{2n}) = n + 1 (∀ n ≥ 1) proved via the new Reflection-Symmetry Invariant `B_k = -X_k + c`. 2. Complete Even-vs-Odd Weight Dichotomy in D_{2n} (NEW): - Odd-Weight Immunity (Ordered): for ALL n ≥ 1 and EVERY A ⊆ 2ℤ + 1 with 1 ∈ A (including A = {1, c} for odd c and A = all odd integers): D_ord(A, D_{2n}) = n + 1. - Even-Weight Collapse (Ordered & Unordered): for ALL n ≥ 1 and EVERY A containing ANY even weight: D_ord(A, D_{2n}) = D_unord(A, D_{2n}) = D_A(ℤ_n). In particular, for ALL c ≥ 2 and m ≥ 1: D_ord({1,…,c}, D_{2cm}) = D_unord({1,…,c}, D_{2cm}) = m, and for ALL even c ≥ 2 and m ≥ 1: D_ord({1,c}, D_{2cm}) = D_unord({1,c}, D_{2cm}) = m. 3. Exponential Ordered-vs-Unordered Separation in D_{2n} (NEW): - Reflection Subset-Sum Pigeonhole Bound: any k reflections in D_{2n} with choose k (k/2) > n contain an unordered product-one subsequence (weights = 1). - General Odd-c Bound: D_unord({1, c}, D_{2cm}) ≤ m + 2 * log₂(cm) + 3. - Exact Exponential Separation (A = {1, n}, n odd): D_ord({1, n}, D_{2n}) = n + 1 (linear), ⌊log₂ n⌋ + 2 ≤ D_unord({1, n}, D_{2n}) ≤ 2 ⌊log₂ n⌋ + 4 (logarithmic!). - Exact Smallest Separation Threshold for A = {1, 3}: D_ord = D_unord for D_4, D_6; strict separation starts at D_8 (5 > 4). 4. Exact Mod-4 Weighted Davenport Classification in Dicyclic Groups Dic_{4n} (NEW): - 4 ∣ c collapse: D_ord(A, Dic_{4n}) = D_unord(A, Dic_{4n}) = D_A(ℤ_{2n}); specifically D_ord({1, 4}, Dic_{8m}) = D_unord({1, 4}, Dic_{8m}) = m. - Exact c = 2 central-involution theorem: for ALL n ≥ 1, D_ord({1, 2}, Dic_{4n}) = D_unord({1, 2}, Dic_{4n}) = max 2 n. -/ import Mathlib open scoped BigOperators open Finset namespace NonAbelianWeightedZeroSum /-! ### 1. General Ordered & Unordered Weighted Product-One Framework -/ /-- Left-associated product of a list under a binary operation `mul` with identity `one`. -/ def listProd {α : Type*} (mul : α → α → α) (one : α) : List α → α | [] => one | x :: xs => mul x (listProd mul one xs) @[simp] lemma listProd_nil {α : Type*} (mul : α → α → α) (one : α) : listProd mul one [] = one := rfl @[simp] lemma listProd_cons {α : Type*} (mul : α → α → α) (one : α) (x : α) (xs : List α) : listProd mul one (x :: xs) = mul x (listProd mul one xs) := rfl lemma listProd_append {α : Type*} {mul : α → α → α} {one : α} (hassoc : ∀ a b c, mul (mul a b) c = mul a (mul b c)) (hone_l : ∀ a, mul one a = a) (l₁ l₂ : List α) : listProd mul one (l₁ ++ l₂) = mul (listProd mul one l₁) (listProd mul one l₂) := by induction l₁ with | nil => simp [hone_l] | cons x xs ih => simp [ih, hassoc] /-- A list `s` has an **ordered** `A`-weighted product-one subsequence if some nonempty sublist `sub` of `s` admits weights `ws` in `A` whose elementwise powered product equals `one`. -/ def HasOrdWeightedP1 {α : Type*} (mul : α → α → α) (one : α) (zpow : α → ℤ → α) (A : Set ℤ) (s : List α) : Prop := ∃ (sub : List α) (ws : List ℤ), sub.Sublist s ∧ sub ≠ [] ∧ ws.length = sub.length ∧ (∀ w ∈ ws, w ∈ A) ∧ listProd mul one (List.zipWith zpow sub ws) = one /-- A list `s` has an **unordered** `A`-weighted product-one subsequence if some permutation of `s` has an ordered `A`-weighted product-one subsequence. -/ def HasUnordWeightedP1 {α : Type*} (mul : α → α → α) (one : α) (zpow : α → ℤ → α) (A : Set ℤ) (s : List α) : Prop := ∃ s' : List α, s'.Perm s ∧ HasOrdWeightedP1 mul one zpow A s' lemma hasUnord_of_hasOrd {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {s : List α} (h : HasOrdWeightedP1 mul one zpow A s) : HasUnordWeightedP1 mul one zpow A s := ⟨s, List.Perm.refl s, h⟩ lemma hasOrd_mono_weights {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A B : Set ℤ} (hAB : A ⊆ B) {s : List α} (h : HasOrdWeightedP1 mul one zpow A s) : HasOrdWeightedP1 mul one zpow B s := by rcases h with ⟨sub, ws, hsub, hne, hlen, hw, hprod⟩ exact ⟨sub, ws, hsub, hne, hlen, fun w hw' => hAB (hw w hw'), hprod⟩ lemma hasUnord_mono_weights {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A B : Set ℤ} (hAB : A ⊆ B) {s : List α} (h : HasUnordWeightedP1 mul one zpow A s) : HasUnordWeightedP1 mul one zpow B s := by rcases h with ⟨s', hp, hord⟩ exact ⟨s', hp, hasOrd_mono_weights hAB hord⟩ lemma hasOrd_of_sublist {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {s t : List α} (hst : s.Sublist t) (h : HasOrdWeightedP1 mul one zpow A s) : HasOrdWeightedP1 mul one zpow A t := by rcases h with ⟨sub, ws, hsub, hne, hlen, hw, hprod⟩ exact ⟨sub, ws, hsub.trans hst, hne, hlen, hw, hprod⟩ lemma hasUnord_of_perm {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {s t : List α} (hp : s.Perm t) (h : HasUnordWeightedP1 mul one zpow A s) : HasUnordWeightedP1 mul one zpow A t := by rcases h with ⟨s', hp', hord⟩ exact ⟨s', hp'.trans hp, hord⟩ lemma hasOrd_single {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} (hone_r : ∀ a, mul a one = a) {A : Set ℤ} {s : List α} {x : α} {w : ℤ} (hx : x ∈ s) (hw : w ∈ A) (h1 : zpow x w = one) : HasOrdWeightedP1 mul one zpow A s := by refine ⟨[x], [w], List.singleton_sublist.mpr hx, List.cons_ne_nil _ _, rfl, ?_, ?_⟩ · intro u hu; rw [List.mem_singleton.mp hu]; exact hw · simp [h1, hone_r] /-- Ordered `A`-weighted Davenport constant `D_ord(A, G)`. -/ noncomputable def ordWeightedDavenport {α : Type*} (mul : α → α → α) (one : α) (zpow : α → ℤ → α) (A : Set ℤ) : ℕ := sInf { d : ℕ | 0 < d ∧ ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s } /-- Unordered `A`-weighted Davenport constant `D_unord(A, G)`. -/ noncomputable def unordWeightedDavenport {α : Type*} (mul : α → α → α) (one : α) (zpow : α → ℤ → α) (A : Set ℤ) : ℕ := sInf { d : ℕ | 0 < d ∧ ∀ s : List α, s.length = d → HasUnordWeightedP1 mul one zpow A s } lemma ordWeightedDavenport_le {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {d : ℕ} (hd : 0 < d) (hall : ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s) : ordWeightedDavenport mul one zpow A ≤ d := Nat.sInf_le ⟨hd, hall⟩ lemma unordWeightedDavenport_le {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {d : ℕ} (hd : 0 < d) (hall : ∀ s : List α, s.length = d → HasUnordWeightedP1 mul one zpow A s) : unordWeightedDavenport mul one zpow A ≤ d := Nat.sInf_le ⟨hd, hall⟩ lemma lt_ordWeightedDavenport {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {k : ℕ} (hne : ∃ d, 0 < d ∧ ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s) (hwit : ∃ s : List α, s.length = k ∧ ¬ HasOrdWeightedP1 mul one zpow A s) : k < ordWeightedDavenport mul one zpow A := by have hmem := Nat.sInf_mem hne rcases hwit with ⟨s, hslen, hno⟩ by_contra hle push Not at hle have htake : (s.take (ordWeightedDavenport mul one zpow A)).length = ordWeightedDavenport mul one zpow A := by rw [List.length_take, hslen, min_eq_left hle] exact hno (hasOrd_of_sublist (List.take_sublist _ _) (hmem.2 _ htake)) lemma lt_unordWeightedDavenport {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {k : ℕ} (hne : ∃ d, 0 < d ∧ ∀ s : List α, s.length = d → HasUnordWeightedP1 mul one zpow A s) (hwit : ∃ s : List α, s.length = k ∧ ¬ HasUnordWeightedP1 mul one zpow A s) : k < unordWeightedDavenport mul one zpow A := by have hmem := Nat.sInf_mem hne rcases hwit with ⟨s, hslen, hno⟩ by_contra hle push Not at hle have htake : (s.take (unordWeightedDavenport mul one zpow A)).length = unordWeightedDavenport mul one zpow A := by rw [List.length_take, hslen, min_eq_left hle] rcases hmem.2 _ htake with ⟨s', hp', hord'⟩ have hpfull : (s' ++ s.drop (unordWeightedDavenport mul one zpow A)).Perm s := by have h1 := hp'.append_right (s.drop (unordWeightedDavenport mul one zpow A)) rwa [List.take_append_drop] at h1 exact hno ⟨_, hpfull, hasOrd_of_sublist (List.sublist_append_left _ _) hord'⟩ lemma ordWeightedDavenport_eq {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {d : ℕ} (hd : 0 < d) (hall : ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s) (hwit : d = 1 ∨ ∃ s : List α, s.length = d - 1 ∧ ¬ HasOrdWeightedP1 mul one zpow A s) : ordWeightedDavenport mul one zpow A = d := by apply le_antisymm (ordWeightedDavenport_le hd hall) rcases hwit with rfl | hw · exact (Nat.sInf_mem (s := { d : ℕ | 0 < d ∧ ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s }) ⟨1, hd, hall⟩).1 · have hlt := lt_ordWeightedDavenport ⟨d, hd, hall⟩ hw omega lemma unordWeightedDavenport_eq {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} {d : ℕ} (hd : 0 < d) (hall : ∀ s : List α, s.length = d → HasUnordWeightedP1 mul one zpow A s) (hwit : d = 1 ∨ ∃ s : List α, s.length = d - 1 ∧ ¬ HasUnordWeightedP1 mul one zpow A s) : unordWeightedDavenport mul one zpow A = d := by apply le_antisymm (unordWeightedDavenport_le hd hall) rcases hwit with rfl | hw · exact (Nat.sInf_mem (s := { d : ℕ | 0 < d ∧ ∀ s : List α, s.length = d → HasUnordWeightedP1 mul one zpow A s }) ⟨1, hd, hall⟩).1 · have hlt := lt_unordWeightedDavenport ⟨d, hd, hall⟩ hw omega lemma unordWeightedDavenport_le_ord {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A : Set ℤ} (hne : ∃ d, 0 < d ∧ ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s) : unordWeightedDavenport mul one zpow A ≤ ordWeightedDavenport mul one zpow A := by have hmem := Nat.sInf_mem hne exact unordWeightedDavenport_le hmem.1 (fun s hs => hasUnord_of_hasOrd (hmem.2 s hs)) lemma ordWeightedDavenport_anti {α : Type*} {mul : α → α → α} {one : α} {zpow : α → ℤ → α} {A B : Set ℤ} (hAB : A ⊆ B) (hne : ∃ d, 0 < d ∧ ∀ s : List α, s.length = d → HasOrdWeightedP1 mul one zpow A s) : ordWeightedDavenport mul one zpow B ≤ ordWeightedDavenport mul one zpow A := by have hmem := Nat.sInf_mem hne exact ordWeightedDavenport_le hmem.1 (fun s hs => hasOrd_mono_weights hAB (hmem.2 s hs)) /-! ### 2. Self-Contained Cyclic Weighted Zero-Sum Lemmas over `ZMod n` -/ /-- Additive cyclic operations on `ZMod n`. -/ abbrev zAdd {n : ℕ} (a b : ZMod n) : ZMod n := a + b abbrev zZero {n : ℕ} : ZMod n := 0 abbrev zSmul {n : ℕ} (x : ZMod n) (w : ℤ) : ZMod n := w • x lemma listProd_zAdd_eq_sum {n : ℕ} (l : List (ZMod n)) : listProd zAdd zZero l = l.sum := by induction l with | nil => rfl | cons x xs ih => simp [listProd, zAdd, ih] lemma perm_filter_append_filter_not {α : Type*} (p : α → Bool) (l : List α) : (l.filter p ++ l.filter (fun x => !p x)).Perm l := by induction l with | nil => exact List.Perm.refl _ | cons x xs ih => cases hp : p x · simp only [List.filter_cons, hp, Bool.false_eq_true, ↓reduceIte, Bool.not_false] exact List.perm_middle.trans (List.Perm.cons x ih) · simp only [List.filter_cons, hp, ↓reduceIte, Bool.not_true, Bool.false_eq_true, List.cons_append] exact List.Perm.cons x ih lemma exists_perm_of_map_perm {α β : Type*} {f : α → β} {l₁ : List α} {l₂ : List β} (h : (l₁.map f).Perm l₂) : ∃ l₁' : List α, l₁'.Perm l₁ ∧ l₁'.map f = l₂ := by generalize heq : l₁.map f = m at h induction h generalizing l₁ with | nil => cases l₁ with | nil => exact ⟨[], List.Perm.refl _, rfl⟩ | cons _ _ => simp at heq | cons y _ ih => cases l₁ with | nil => simp at heq | cons x xs => simp only [List.map_cons, List.cons.injEq] at heq obtain ⟨rfl, htail⟩ := heq obtain ⟨xs', hpxs, hmap⟩ := ih htail exact ⟨x :: xs', hpxs.cons x, by simp [hmap]⟩ | swap y₁ y₂ _ => cases l₁ with | nil => simp at heq | cons x₁ l₁' => cases l₁' with | nil => simp at heq | cons x₂ xs => simp only [List.map_cons, List.cons.injEq] at heq rcases heq with ⟨rfl, rfl, rfl⟩ exact ⟨x₂ :: x₁ :: xs, List.Perm.swap x₁ x₂ xs, rfl⟩ | trans _ _ ih₁ ih₂ => obtain ⟨m₁, hpm₁, hm₁⟩ := ih₁ heq obtain ⟨m₂, hpm₂, hm₂⟩ := ih₂ hm₁ exact ⟨m₂, hpm₂.trans hpm₁, hm₂⟩ lemma hasUnord_iff_hasOrd_zMod {n : ℕ} {A : Set ℤ} {s : List (ZMod n)} : HasUnordWeightedP1 zAdd zZero zSmul A s ↔ HasOrdWeightedP1 zAdd zZero zSmul A s := by constructor · rintro ⟨s', hp, sub, ws, hsub, hne, hlen, hw, hprod⟩ have hex_opt : ∀ {t u : List (ZMod n)} (hu : u.Sublist t) (ws : List ℤ), ws.length = u.length → (∀ w ∈ ws, w ∈ A) → ∃ (opts : List (ZMod n × Option ℤ)), opts.map Prod.fst = t ∧ (opts.filterMap (fun p => p.2.map (fun w => zSmul p.1 w))).sum = (List.zipWith zSmul u ws).sum ∧ (∀ p ∈ opts, ∀ w, p.2 = some w → w ∈ A) ∧ (u ≠ [] → ∃ p ∈ opts, p.2.isSome) := by intro t u hu induction hu with | slnil => intro ws hlen _ cases ws with | nil => exact ⟨[], rfl, rfl, by simp, fun h => absurd rfl h⟩ | cons _ _ => simp at hlen | cons a _ ih => intro ws hlen hw obtain ⟨opts, hmap, hsum, hwa, hne'⟩ := ih ws hlen hw refine ⟨(a, none) :: opts, by simp [hmap], ?_, ?_, ?_⟩ · simp only [List.filterMap_cons, Option.map_none]; exact hsum · intro p hp w hw' rcases List.mem_cons.mp hp with rfl | hp · simp at hw' · exact hwa p hp w hw' · intro hu'; obtain ⟨p, hp, hsome⟩ := hne' hu'; exact ⟨p, List.mem_cons_of_mem _ hp, hsome⟩ | @cons_cons l₁ _ a _ ih => intro ws hlen hw cases ws with | nil => simp at hlen | cons w ws' => have hlen' : ws'.length = l₁.length := by simpa using hlen obtain ⟨opts, hmap, hsum, hwa, _⟩ := ih ws' hlen' (fun u hu => hw u (List.mem_cons_of_mem _ hu)) refine ⟨(a, some w) :: opts, by simp [hmap], ?_, ?_, ?_⟩ · simp only [List.filterMap_cons, Option.map_some, List.sum_cons, List.zipWith_cons_cons, hsum] · intro p hp w' hw' rcases List.mem_cons.mp hp with rfl | hp · simp at hw'; subst hw'; exact hw w (List.mem_cons_self ..) · exact hwa p hp w' hw' · intro _; exact ⟨(a, some w), List.mem_cons_self .., rfl⟩ obtain ⟨opts, hmap, hsum, hwa, hsome⟩ := hex_opt hsub ws hlen hw have hperm_opts : ∃ opts' : List (ZMod n × Option ℤ), opts'.Perm opts ∧ opts'.map Prod.fst = s := by have hp' : (opts.map Prod.fst).Perm s := hmap.symm ▸ hp exact exists_perm_of_map_perm hp' obtain ⟨opts', hp_opts, hmap'⟩ := hperm_opts let sub' := (opts'.filter (fun p => p.2.isSome)).map Prod.fst let ws' := opts'.filterMap Prod.snd have hsub' : sub'.Sublist s := by rw [← hmap'] exact (List.filter_sublist).map Prod.fst have hzip : List.zipWith zSmul sub' ws' = opts'.filterMap (fun p => p.2.map (fun w => zSmul p.1 w)) := by dsimp only [sub', ws'] clear hp_opts hmap' hsub' hsum hwa hsome hmap hprod hp hsub hne hlen hw induction opts' with | nil => rfl | cons p ps ih => rcases p with ⟨x, _ | w⟩ <;> simp [ih] have hlen' : ws'.length = sub'.length := by dsimp only [sub', ws'] clear hzip hp_opts hmap' hsub' hsum hwa hsome hmap hprod hp hsub hne hlen hw induction opts' with | nil => rfl | cons p ps ih => rcases p with ⟨x, _ | w⟩ <;> simp [ih] have hne' : sub' ≠ [] := by obtain ⟨p, hp_in, hp_some⟩ := hsome hne have hp_in' : p ∈ opts' := hp_opts.mem_iff.mpr hp_in intro hemp have : p.1 ∈ sub' := List.mem_map.mpr ⟨p, List.mem_filter.mpr ⟨hp_in', hp_some⟩, rfl⟩ rw [hemp] at this; exact List.not_mem_nil this have hwa' : ∀ w ∈ ws', w ∈ A := by intro w hw' rcases List.mem_filterMap.mp hw' with ⟨p, hp_in, hp_eq⟩ exact hwa p (hp_opts.mem_iff.mp hp_in) w hp_eq have hsum_eq : (List.zipWith zSmul sub' ws').sum = 0 := by rw [hzip] have hpf : (opts'.filterMap (fun p => p.2.map (fun w => zSmul p.1 w))).Perm (opts.filterMap (fun p => p.2.map (fun w => zSmul p.1 w))) := hp_opts.filterMap _ rw [hpf.sum_eq, hsum] rw [listProd_zAdd_eq_sum] at hprod exact hprod refine ⟨sub', ws', hsub', hne', hlen', hwa', ?_⟩ rw [listProd_zAdd_eq_sum]; exact hsum_eq · exact hasUnord_of_hasOrd /-- Helper: every contiguous slice `s.drop i |>.take (j - i)` is a sublist of `s`. -/ lemma sublist_drop_take {α : Type*} (s : List α) (i j : ℕ) : ((s.drop i).take (j - i)).Sublist s := (List.take_sublist _ _).trans (List.drop_sublist _ _) /-- **Cyclic Weighted Upper Bound (15-line Pigeonhole Proof):** For ALL `c ≥ 1, m ≥ 1`, every list of length `m` over `ZMod (c * m)` has a nonempty `{c}`-weighted (hence `{1, c}`- and `{1, …, c}`-weighted) zero-sum sublist! -/ theorem cyclic_weighted_c_upper {c m : ℕ} (hc : 1 ≤ c) (hm : 1 ≤ m) : ∀ s : List (ZMod (c * m)), s.length = m → HasOrdWeightedP1 zAdd zZero zSmul { (c : ℤ) } s := by intro s hslen have hcm : 0 < c * m := Nat.mul_pos hc hm have : NeZero (c * m) := ⟨Nat.ne_of_gt hcm⟩ -- Prefix sums `P k = ((s.take k).map (fun x => (c : ℤ) • x)).sum` all lie in `H = image (· * c) (Fin m)`! let y : List (ZMod (c * m)) := s.map (fun x => (c : ℤ) • x) let P : Fin (m + 1) → ZMod (c * m) := fun k => (y.take k.val).sum let H : Finset (ZMod (c * m)) := Finset.univ.image (fun t : Fin m => ((c * t.val : ℕ) : ZMod (c * m))) have hmemH : ∀ k : Fin (m + 1), P k ∈ H := by intro k have hdiv : ∃ r : ℕ, P k = ((c * r : ℕ) : ZMod (c * m)) := by dsimp only [P, y] have htake_map : (s.map (fun x => (c : ℤ) • x)).take k.val = (s.take k.val).map (fun x => (c : ℤ) • x) := List.map_take.symm rw [htake_map] induction (s.take k.val) with | nil => exact ⟨0, by simp⟩ | cons a l ih => rcases ih with ⟨r, hr⟩ refine ⟨a.val + r, ?_⟩ have ha : ((c : ℕ) : ZMod (c * m)) * a = ((c * a.val : ℕ) : ZMod (c * m)) := by rw [Nat.cast_mul, ZMod.natCast_zmod_val] rw [List.map_cons, List.sum_cons, zsmul_eq_mul, Int.cast_natCast, ha, hr, ← Nat.cast_add, mul_add] rcases hdiv with ⟨r, hr⟩ refine Finset.mem_image.mpr ⟨⟨r % m, Nat.mod_lt r hm⟩, Finset.mem_univ _, ?_⟩ rw [hr] have hq : r = m * (r / m) + r % m := (Nat.div_add_mod r m).symm have hmul : c * r = (c * m) * (r / m) + c * (r % m) := by calc c * r = c * (m * (r / m) + r % m) := by rw [← hq] _ = (c * m) * (r / m) + c * (r % m) := by ring have hzero : (((c * m) * (r / m) : ℕ) : ZMod (c * m)) = 0 := by rw [Nat.cast_mul, ZMod.natCast_self, zero_mul] rw [hmul, Nat.cast_add, hzero, zero_add] have hcardH : H.card ≤ m := le_trans Finset.card_image_le (by simp) have hlt : Fintype.card H < Fintype.card (Fin (m + 1)) := by simp only [Fintype.card_coe, Fintype.card_fin] omega obtain ⟨i, j, hne, heq⟩ := Fintype.exists_ne_map_eq_of_card_lt (fun k : Fin (m + 1) => (⟨P k, hmemH k⟩ : H)) hlt have hPeq : P i = P j := congrArg Subtype.val heq have hmk : ∀ i j : Fin (m + 1), i.val < j.val → P i = P j → HasOrdWeightedP1 zAdd zZero zSmul { (c : ℤ) } s := by intro i j hij hPeq let sub := (s.drop i.val).take (j.val - i.val) have hsub_len : sub.length = j.val - i.val := by dsimp only [sub] rw [List.length_take, List.length_drop, hslen] omega have hsub_ne : sub ≠ [] := by intro h; rw [h] at hsub_len; simp at hsub_len; omega let ws := List.replicate sub.length (c : ℤ) have hzip_eq : List.zipWith zSmul sub ws = (y.drop i.val).take (j.val - i.val) := by dsimp only [ws, sub, y] have hzip_rep : ∀ (l : List (ZMod (c * m))), List.zipWith zSmul l (List.replicate l.length (c : ℤ)) = l.map (fun x => (c : ℤ) • x) := by intro l; induction l with | nil => rfl | cons a l ih => rw [List.length_cons, List.replicate_succ, List.zipWith_cons_cons, List.map_cons, ih] rw [hzip_rep, List.map_take, List.map_drop] have hslice_sum : ((y.drop i.val).take (j.val - i.val)).sum = 0 := by have hsplit : y.take j.val = y.take i.val ++ (y.drop i.val).take (j.val - i.val) := by have h1 : j.val = i.val + (j.val - i.val) := by omega conv_lhs => rw [h1, List.take_add] have hsum := congrArg List.sum hsplit rw [List.sum_append] at hsum change P j = P i + ((y.drop i.val).take (j.val - i.val)).sum at hsum rw [hPeq] at hsum exact add_left_cancel (hsum.symm.trans (add_zero (P j)).symm) refine ⟨sub, ws, sublist_drop_take s i.val j.val, hsub_ne, List.length_replicate, ?_, ?_⟩ · intro w hw; exact Set.mem_singleton_iff.mpr (List.eq_of_mem_replicate hw) · rw [listProd_zAdd_eq_sum, hzip_eq, hslice_sum] rcases lt_or_gt_of_ne (Fin.val_ne_of_ne hne) with hij | hji · exact hmk i j hij hPeq · exact hmk j i hji hPeq.symm /-- Lower bound witness for `ZMod (c * m)` with weights in `Icc 1 c`: `m - 1` copies of `1`. -/ theorem cyclic_weighted_Icc_lower {c m : ℕ} (hc : 1 ≤ c) (hm : 1 ≤ m) : ¬ HasOrdWeightedP1 zAdd zZero zSmul (Set.Icc (1 : ℤ) (c : ℤ)) (List.replicate (m - 1) (1 : ZMod (c * m))) := by rintro ⟨sub, ws, hsub, hne, hlen, hw, hprod⟩ rw [listProd_zAdd_eq_sum] at hprod have hcm : 0 < c * m := Nat.mul_pos hc hm have : NeZero (c * m) := ⟨Nat.ne_of_gt hcm⟩ have hsub_len_le : sub.length ≤ m - 1 := by simpa [List.length_replicate] using hsub.length_le have hsub_all1 : ∀ x ∈ sub, x = (1 : ZMod (c * m)) := fun x hx => List.eq_of_mem_replicate (hsub.subset hx) have hzip_cast : ∀ (u : List (ZMod (c * m))) (v : List ℤ), v.length = u.length → (∀ x ∈ u, x = 1) → (List.zipWith zSmul u v).sum = (v.sum : ZMod (c * m)) := by intro u induction u with | nil => intro v hv _; cases v <;> simp_all | cons a l ih => intro v hv ha cases v with | nil => simp at hv | cons w ws' => have ha1 : a = 1 := ha a (List.mem_cons_self ..) simp only [List.zipWith_cons_cons, List.sum_cons, zSmul, ha1, zsmul_eq_mul, mul_one, Int.cast_add] congr 1 exact ih ws' (by simpa using hv) (fun x hx => ha x (List.mem_cons_of_mem _ hx)) rw [hzip_cast sub ws hlen hsub_all1] at hprod -- Bound `1 ≤ ws.sum ≤ c * (m - 1) < c * m`! have hws_pos : (ws.length : ℤ) ≤ ws.sum := by clear hprod hzip_cast hsub_all1 hsub_len_le hsub hne hlen induction ws with | nil => simp | cons w ws' ih => have hw1 : (1 : ℤ) ≤ w := (hw w (List.mem_cons_self ..)).1 have ih' := ih (fun u hu => hw u (List.mem_cons_of_mem _ hu)) simp only [List.length_cons, List.sum_cons, Nat.cast_add, Nat.cast_one] omega have hws_le : ws.sum ≤ (c : ℤ) * (ws.length : ℤ) := by clear hprod hzip_cast hsub_all1 hsub_len_le hsub hne hlen hws_pos induction ws with | nil => simp | cons w ws' ih => have hwc : w ≤ (c : ℤ) := (hw w (List.mem_cons_self ..)).2 have ih' := ih (fun u hu => hw u (List.mem_cons_of_mem _ hu)) simp only [List.length_cons, List.sum_cons, Nat.cast_add, Nat.cast_one] nlinarith have hlen_pos : 1 ≤ ws.length := by rw [hlen]; exact List.length_pos_iff.mpr hne have hsum_pos : (1 : ℤ) ≤ ws.sum := by omega have hsum_lt : ws.sum < ((c * m : ℕ) : ℤ) := by have hle2 : (c : ℤ) * (ws.length : ℤ) ≤ (c : ℤ) * ((m - 1 : ℕ) : ℤ) := by apply mul_le_mul_of_nonneg_left _ (by omega) exact_mod_cast (hlen ▸ hsub_len_le) have hcm_eq : ((c * m : ℕ) : ℤ) = (c : ℤ) * ((m - 1 : ℕ) : ℤ) + (c : ℤ) := by have : m = (m - 1) + 1 := by omega conv_lhs => rw [this] push_cast; ring omega have hdvd : ((c * m : ℕ) : ℤ) ∣ ws.sum := (ZMod.intCast_zmod_eq_zero_iff_dvd ws.sum (c * m)).mp hprod have hle_abs := Int.le_of_dvd (by omega) hdvd omega /-- Exact Cyclic Weighted Davenport for `{1, c}` and `{1, …, c}` over `ZMod (c * m)`. -/ theorem cyclic_weighted_1c_exact {c m : ℕ} (hc : 1 ≤ c) (hm : 1 ≤ m) : ordWeightedDavenport (α := ZMod (c * m)) zAdd zZero zSmul ({1, (c : ℤ)} : Set ℤ) = m ∧ ordWeightedDavenport (α := ZMod (c * m)) zAdd zZero zSmul (Set.Icc (1 : ℤ) (c : ℤ)) = m := by have hsub1 : ({(c : ℤ)} : Set ℤ) ⊆ {1, (c : ℤ)} := by intro x hx; right; exact hx have hsub2 : ({1, (c : ℤ)} : Set ℤ) ⊆ Set.Icc (1 : ℤ) (c : ℤ) := by intro x hx; rcases hx with rfl | rfl <;> exact ⟨by omega, by omega⟩ have hup1 : ∀ s : List (ZMod (c * m)), s.length = m → HasOrdWeightedP1 zAdd zZero zSmul ({1, (c : ℤ)} : Set ℤ) s := fun s hs => hasOrd_mono_weights hsub1 (cyclic_weighted_c_upper hc hm s hs) have hup2 : ∀ s : List (ZMod (c * m)), s.length = m → HasOrdWeightedP1 zAdd zZero zSmul (Set.Icc (1 : ℤ) (c : ℤ)) s := fun s hs => hasOrd_mono_weights hsub2 (hup1 s hs) have hlow2 : ¬ HasOrdWeightedP1 zAdd zZero zSmul (Set.Icc (1 : ℤ) (c : ℤ)) (List.replicate (m - 1) (1 : ZMod (c * m))) := cyclic_weighted_Icc_lower hc hm have hlow1 : ¬ HasOrdWeightedP1 zAdd zZero zSmul ({1, (c : ℤ)} : Set ℤ) (List.replicate (m - 1) (1 : ZMod (c * m))) := fun h => hlow2 (hasOrd_mono_weights hsub2 h) exact ⟨ordWeightedDavenport_eq hm hup1 (Or.inr ⟨_, List.length_replicate, hlow1⟩), ordWeightedDavenport_eq hm hup2 (Or.inr ⟨_, List.length_replicate, hlow2⟩)⟩ /-- Helper: Strict growth of finite subset under translation in `ZMod n` when `0` is avoided. -/ lemma zMod_translate_card_gt {n : ℕ} [NeZero n] {X : Finset (ZMod n)} {a : ZMod n} (h0X : (0 : ZMod n) ∈ X) (_ha : a ≠ 0) (h0not : ∀ x ∈ X, x + a ≠ 0) : X.card < (X ∪ X.image (· + a)).card := by by_contra hle have hsub : X ⊆ X ∪ X.image (· + a) := Finset.subset_union_left have heq : X = X ∪ X.image (· + a) := Finset.eq_of_subset_of_card_le hsub (by omega) have hclosed : ∀ x ∈ X, x + a ∈ X := by intro x hx rw [heq] exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨x, hx, rfl⟩) -- By induction, `k • a ∈ X` for all `k : ℕ`, so `(n - 1) • a ∈ X` and `(n - 1) • a + a = 0`! have hnsmul : ∀ k : ℕ, (k : ZMod n) * a ∈ X := by intro k induction k with | zero => simpa using h0X | succ k ih => have : ((k + 1 : ℕ) : ZMod n) * a = (k : ZMod n) * a + a := by push_cast; ring rw [this]; exact hclosed _ ih have hn_pos : 0 < n := Nat.pos_of_ne_zero (NeZero.ne n) have hnm1 : ((n - 1 : ℕ) : ZMod n) * a ∈ X := hnsmul (n - 1) have hzero : ((n - 1 : ℕ) : ZMod n) * a + a = 0 := by have h1 : ((n - 1 : ℕ) : ZMod n) + 1 = ((n : ℕ) : ZMod n) := by rw [← Nat.cast_add_one, Nat.sub_add_cancel hn_pos] calc ((n - 1 : ℕ) : ZMod n) * a + a = (((n - 1 : ℕ) : ZMod n) + 1) * a := by ring _ = ((n : ℕ) : ZMod n) * a := by rw [h1] _ = 0 := by rw [ZMod.natCast_self, zero_mul] exact h0not _ hnm1 hzero /-- **5-Line `{1, 2}`-Weighted Cyclic Bound (`n ≥ 2`):** For ALL `n ≥ 2`, every list of length `n - 1` over `ZMod n` has a nonempty `{1, 2}`-weighted zero-sum sublist! -/ theorem cyclic_weighted_12_le_pred {n : ℕ} (hn : 2 ≤ n) : ∀ s : List (ZMod n), s.length = n - 1 → HasOrdWeightedP1 zAdd zZero zSmul ({1, (2 : ℤ)} : Set ℤ) s := by have : NeZero n := ⟨by omega⟩ -- For `n = 2`: length 1, `[x]` has `2 • x = 0`! by_cases hn2 : n = 2 · subst hn2 intro s hs cases s with | nil => simp at hs | cons x xs => refine hasOrd_single (fun a => add_zero a) (List.mem_cons_self ..) (Or.inr rfl) ?_ change (2 : ℤ) • x = 0 rw [zsmul_eq_mul]; change ((2 : ℕ) : ZMod 2) * x = 0 rw [ZMod.natCast_self, zero_mul] · -- `n ≥ 3`: Track reachable `{1, 2}`-weighted nonempty sums `T` (with `X = insert 0 T`)! have hn3 : 3 ≤ n := by omega intro s hslen by_contra hno let reach : List (ZMod n) → Finset (ZMod n) := List.foldl (fun T x => T ∪ ({x, (2 : ℤ) • x} : Finset (ZMod n)) ∪ T.image (· + x) ∪ T.image (· + (2 : ℤ) • x)) ∅ have hreach_sound : ∀ (l : List (ZMod n)) (y : ZMod n), y ∈ reach l → ∃ (sub : List (ZMod n)) (ws : List ℤ), sub.Sublist l ∧ sub ≠ [] ∧ ws.length = sub.length ∧ (∀ w ∈ ws, w ∈ ({1, (2 : ℤ)} : Set ℤ)) ∧ (List.zipWith zSmul sub ws).sum = y := by intro l induction l using List.reverseRecOn with | nil => intro y hy; simp [reach] at hy | append_singleton l x ih => intro y hy dsimp only [reach] at hy rw [List.foldl_append, List.foldl_cons, List.foldl_nil] at hy change y ∈ reach l ∪ ({x, (2 : ℤ) • x} : Finset (ZMod n)) ∪ (reach l).image (· + x) ∪ (reach l).image (· + (2 : ℤ) • x) at hy simp only [Finset.mem_union, Finset.mem_insert, Finset.mem_singleton, Finset.mem_image] at hy rcases hy with (((h1 | h2 | h3) | ⟨z, hz, rfl⟩) | ⟨z, hz, rfl⟩) · obtain ⟨sub, ws, hsub, hne, hlen, hw, hsum⟩ := ih y h1 exact ⟨sub, ws, hsub.trans (List.sublist_append_left _ _), hne, hlen, hw, hsum⟩ · rw [h2] exact ⟨[x], [1], List.singleton_sublist.mpr (by simp), List.cons_ne_nil _ _, rfl, by simp, by simp [zSmul]⟩ · rw [h3] exact ⟨[x], [2], List.singleton_sublist.mpr (by simp), List.cons_ne_nil _ _, rfl, by simp, by simp [zSmul]⟩ · obtain ⟨sub, ws, hsub, hne, hlen, hw, hsum⟩ := ih z hz refine ⟨sub ++ [x], ws ++ [1], hsub.append (List.Sublist.refl _), by simp, by simp [hlen], ?_, ?_⟩ · intro w hw'; rcases List.mem_append.mp hw' with h | h · exact hw w h · simp at h; subst h; simp · rw [List.zipWith_append (by exact hlen.symm), List.sum_append, hsum]; simp [zSmul] · obtain ⟨sub, ws, hsub, hne, hlen, hw, hsum⟩ := ih z hz refine ⟨sub ++ [x], ws ++ [2], hsub.append (List.Sublist.refl _), by simp, by simp [hlen], ?_, ?_⟩ · intro w hw'; rcases List.mem_append.mp hw' with h | h · exact hw w h · simp at h; subst h; simp · rw [List.zipWith_append (by exact hlen.symm), List.sum_append, hsum]; simp [zSmul] have h0not_reach : ∀ (l : List (ZMod n)), l.Sublist s → (0 : ZMod n) ∉ reach l := by intro l hl h0 obtain ⟨sub, ws, hsub, hne, hlen, hw, hsum⟩ := hreach_sound l 0 h0 exact hno ⟨sub, ws, hsub.trans hl, hne, hlen, hw, by rw [listProd_zAdd_eq_sum]; exact hsum⟩ have hcard_grow : ∀ (l : List (ZMod n)), l.Sublist s → 1 ≤ l.length → l.length + 2 ≤ (insert (0 : ZMod n) (reach l)).card := by intro l induction l using List.reverseRecOn with | nil => intro _ h1; simp at h1 | append_singleton l x ih => intro hl _ have hstep : reach (l ++ [x]) = reach l ∪ ({x, (2 : ℤ) • x} : Finset (ZMod n)) ∪ (reach l).image (· + x) ∪ (reach l).image (· + (2 : ℤ) • x) := by dsimp only [reach]; rw [List.foldl_append, List.foldl_cons, List.foldl_nil] have h0not : (0 : ZMod n) ∉ reach (l ++ [x]) := h0not_reach _ hl have hx0 : x ≠ 0 := by intro h; subst h; apply h0not; rw [hstep]; simp have h2x0 : (2 : ℤ) • x ≠ 0 := by intro h; apply h0not; rw [hstep]; simp [h] cases l with | nil => have hx_ne_2x : x ≠ (2 : ℤ) • x := by intro heq have : (2 : ℤ) • x - x = 0 := sub_eq_zero.mpr heq.symm have h1 : (2 : ℤ) • x - x = x := by rw [two_zsmul]; abel rw [h1] at this; exact hx0 this have hsub3 : ({0, x, (2 : ℤ) • x} : Finset (ZMod n)) ⊆ insert 0 (reach [x]) := by intro y hy simp only [Finset.mem_insert, Finset.mem_singleton] at hy ⊢ rcases hy with hy | hy | hy · left; exact hy · right; rw [hy, show [x] = [] ++ [x] from rfl, hstep]; simp · right; rw [hy, show [x] = [] ++ [x] from rfl, hstep]; simp have hcard3 : ({0, x, (2 : ℤ) • x} : Finset (ZMod n)).card = 3 := by rw [Finset.card_insert_of_notMem, Finset.card_pair hx_ne_2x] simp only [Finset.mem_insert, Finset.mem_singleton, not_or] exact ⟨hx0.symm, h2x0.symm⟩ have hle := Finset.card_le_card hsub3 rw [hcard3] at hle; simpa using hle | cons a l' => have hl_sub : (a :: l').Sublist s := (List.sublist_append_left _ _).trans hl have hih := ih hl_sub (by simp) let X := insert (0 : ZMod n) (reach (a :: l')) change (a :: l').length + 2 ≤ X.card at hih have hX_sub : X ∪ X.image (· + x) ⊆ insert 0 (reach ((a :: l') ++ [x])) := by intro y hy rw [hstep] simp only [X, Finset.mem_union, Finset.mem_insert, Finset.mem_image] at hy ⊢ rcases hy with (rfl | hy) | ⟨z, (rfl | hz), rfl⟩ · left; rfl · right; left; left; left; exact hy · right; left; left; right; simp · right; left; right; exact ⟨z, hz, rfl⟩ have h0not_tr : ∀ z ∈ X, z + x ≠ 0 := by intro z hz hzx apply h0not; rw [← hzx, hstep] simp only [X, Finset.mem_insert] at hz simp only [Finset.mem_union, Finset.mem_insert, Finset.mem_singleton, Finset.mem_image] rcases hz with rfl | hz · left; left; right; left; simp · left; right; exact ⟨z, hz, rfl⟩ have hlt : X.card < (X ∪ X.image (· + x)).card := zMod_translate_card_gt (Finset.mem_insert_self 0 _) hx0 h0not_tr have hle := Finset.card_le_card hX_sub simp only [List.length_append, List.length_singleton] at hle ⊢ omega have hbig := hcard_grow s (List.Sublist.refl s) (by omega) have hmax : (insert (0 : ZMod n) (reach s)).card ≤ n := by simpa [ZMod.card] using Finset.card_le_univ (insert (0 : ZMod n) (reach s)) omega /-! ### 3. Concrete Model of the Dihedral Group `D_{2n}` -/ /-- Concrete dihedral group `D_{2n} = ℤ_n × Bool`, representing `r^a s^b`. -/ abbrev Dihedral (n : ℕ) := ZMod n × Bool def dOne {n : ℕ} : Dihedral n := (0, false) def dMul {n : ℕ} (x y : Dihedral n) : Dihedral n := (if x.2 then x.1 - y.1 else x.1 + y.1, xor x.2 y.2) def dInv {n : ℕ} (x : Dihedral n) : Dihedral n := (if x.2 then x.1 else -x.1, x.2) def dZPow {n : ℕ} (x : Dihedral n) (w : ℤ) : Dihedral n := if x.2 then (if Even w then (0, false) else x) else (w • x.1, false) lemma dOne_mul {n : ℕ} (x : Dihedral n) : dMul dOne x = x := by rcases x with ⟨a, b⟩; simp [dOne, dMul] lemma dMul_one {n : ℕ} (x : Dihedral n) : dMul x dOne = x := by rcases x with ⟨a, b⟩; cases b <;> simp [dOne, dMul] lemma dMul_assoc {n : ℕ} (x y z : Dihedral n) : dMul (dMul x y) z = dMul x (dMul y z) := by rcases x with ⟨a, bx⟩; rcases y with ⟨b, by_⟩; rcases z with ⟨c, bz⟩ cases bx <;> cases by_ <;> cases bz <;> simp [dMul] <;> ring lemma dMul_inv_cancel {n : ℕ} (x : Dihedral n) : dMul x (dInv x) = dOne := by rcases x with ⟨a, b⟩; cases b <;> simp [dMul, dInv, dOne] lemma dInv_mul_cancel {n : ℕ} (x : Dihedral n) : dMul (dInv x) x = dOne := by rcases x with ⟨a, b⟩; cases b <;> simp [dMul, dInv, dOne] @[simp] lemma dZPow_one {n : ℕ} (x : Dihedral n) : dZPow x 1 = x := by rcases x with ⟨a, b⟩; cases b <;> simp [dZPow] lemma dZPow_rot {n : ℕ} (a : ZMod n) (w : ℤ) : dZPow (a, false) w = (w • a, false) := rfl lemma dZPow_refl_even {n : ℕ} (a : ZMod n) {w : ℤ} (hw : Even w) : dZPow (a, true) w = dOne := by simp [dZPow, dOne, hw] lemma dZPow_refl_odd {n : ℕ} (a : ZMod n) {w : ℤ} (hw : ¬ Even w) : dZPow (a, true) w = (a, true) := by simp [dZPow, hw] lemma listProd_dMul_rot {n : ℕ} (l : List (ZMod n)) : listProd dMul dOne (l.map (fun a => (a, false))) = (l.sum, false) := by induction l with | nil => rfl | cons a l ih => simp [dMul, ih] /-! ### 4. THEOREM 1: Exact Unweighted Dihedral Davenport via the `B_k = -X_k + c` Reflection-Symmetry Invariant -/ /-- Reachable nonempty ordered products in `D_{2n}` split into rotation set `A` and reflection set `B`. -/ def dStep {n : ℕ} (st : Finset (ZMod n) × Finset (ZMod n)) (g : Dihedral n) : Finset (ZMod n) × Finset (ZMod n) := let (A, B) := st if g.2 then (A ∪ B.image (fun y => y - g.1), B ∪ (insert 0 A).image (fun x => x + g.1)) else (A ∪ (insert 0 A).image (fun x => x + g.1), B ∪ B.image (fun y => y - g.1)) def dReach {n : ℕ} (s : List (Dihedral n)) : Finset (ZMod n) × Finset (ZMod n) := s.foldl dStep (∅, ∅) lemma dReach_sound {n : ℕ} (s : List (Dihedral n)) : (∀ a ∈ (dReach s).1, ∃ sub : List (Dihedral n), sub.Sublist s ∧ sub ≠ [] ∧ listProd dMul dOne sub = (a, false)) ∧ (∀ b ∈ (dReach s).2, ∃ sub : List (Dihedral n), sub.Sublist s ∧ sub ≠ [] ∧ listProd dMul dOne sub = (b, true)) := by induction s using List.reverseRecOn with | nil => simp [dReach] | append_singleton s g ih => have hstep : dReach (s ++ [g]) = dStep (dReach s) g := by dsimp only [dReach]; rw [List.foldl_append, List.foldl_cons, List.foldl_nil] rw [hstep] rcases g with ⟨c, bg⟩ rcases bg with _ | _ · -- `g = (c, false)` (rotation) dsimp only [dStep] simp only [Bool.false_eq_true, ↓reduceIte] constructor · intro a ha simp only [Finset.mem_union, Finset.mem_image, Finset.mem_insert] at ha rcases ha with ha | ⟨x, rfl | hx, rfl⟩ · obtain ⟨sub, hsub, hne, hp⟩ := ih.1 a ha exact ⟨sub, hsub.trans (List.sublist_append_left _ _), hne, hp⟩ · refine ⟨[(c, false)], List.singleton_sublist.mpr (by simp), List.cons_ne_nil _ _, ?_⟩ simp [dMul, dOne] · obtain ⟨sub, hsub, hne, hp⟩ := ih.1 x hx refine ⟨sub ++ [(c, false)], hsub.append (List.Sublist.refl _), by simp, ?_⟩ rw [listProd_append dMul_assoc dOne_mul, hp]; simp [dMul, dOne] · intro b hb simp only [Finset.mem_union, Finset.mem_image] at hb rcases hb with hb | ⟨y, hy, rfl⟩ · obtain ⟨sub, hsub, hne, hp⟩ := ih.2 b hb exact ⟨sub, hsub.trans (List.sublist_append_left _ _), hne, hp⟩ · obtain ⟨sub, hsub, hne, hp⟩ := ih.2 y hy refine ⟨sub ++ [(c, false)], hsub.append (List.Sublist.refl _), by simp, ?_⟩ rw [listProd_append dMul_assoc dOne_mul, hp]; simp [dMul, dOne] · -- `g = (c, true)` (reflection) dsimp only [dStep] simp only [↓reduceIte] constructor · intro a ha simp only [Finset.mem_union, Finset.mem_image] at ha rcases ha with ha | ⟨y, hy, rfl⟩ · obtain ⟨sub, hsub, hne, hp⟩ := ih.1 a ha exact ⟨sub, hsub.trans (List.sublist_append_left _ _), hne, hp⟩ · obtain ⟨sub, hsub, hne, hp⟩ := ih.2 y hy refine ⟨sub ++ [(c, true)], hsub.append (List.Sublist.refl _), by simp, ?_⟩ rw [listProd_append dMul_assoc dOne_mul, hp]; simp [dMul, dOne] · intro b hb simp only [Finset.mem_union, Finset.mem_image, Finset.mem_insert] at hb rcases hb with hb | ⟨x, rfl | hx, rfl⟩ · obtain ⟨sub, hsub, hne, hp⟩ := ih.2 b hb exact ⟨sub, hsub.trans (List.sublist_append_left _ _), hne, hp⟩ · refine ⟨[(c, true)], List.singleton_sublist.mpr (by simp), List.cons_ne_nil _ _, ?_⟩ simp [dMul, dOne] · obtain ⟨sub, hsub, hne, hp⟩ := ih.1 x hx refine ⟨sub ++ [(c, true)], hsub.append (List.Sublist.refl _), by simp, ?_⟩ rw [listProd_append dMul_assoc dOne_mul, hp]; simp [dMul, dOne] /-- **THEOREM 1a (Self-Contained Dihedral Ordered Davenport Upper Bound — `B_k = -X_k + c` Invariant):** For EVERY `n ≥ 1`, every list of length `n + 1` in `D_{2n}` has a nonempty ordered product-one subsequence (weights `= 1`)! -/ theorem dihedral_ord_davenport_upper {n : ℕ} (hn : 1 ≤ n) : ∀ s : List (Dihedral n), s.length = n + 1 → HasOrdWeightedP1 dMul dOne dZPow { (1 : ℤ) } s := by have : NeZero n := ⟨by omega⟩ intro s hslen by_contra hno have h0not : ∀ l : List (Dihedral n), l.Sublist s → (0 : ZMod n) ∉ (dReach l).1 := by intro l hl h0 obtain ⟨sub, hsub, hne, hp⟩ := (dReach_sound l).1 0 h0 have hzip : List.zipWith dZPow sub (List.replicate sub.length (1 : ℤ)) = sub := by clear hp hne hsub hl h0 hno induction sub with | nil => rfl | cons a l ih => rw [List.length_cons, List.replicate_succ, List.zipWith_cons_cons, dZPow_one, ih] exact hno ⟨sub, List.replicate sub.length 1, hsub.trans hl, hne, List.length_replicate, fun w hw => Set.mem_singleton_iff.mpr (List.eq_of_mem_replicate hw), by rw [hzip]; exact hp⟩ -- **Key Reflection-Symmetry Invariant:** -- For EVERY prefix `l` of `s`, letting `X = insert 0 (dReach l).1` and `B = (dReach l).2`: -- EITHER (`B = ∅` ∧ `l.length + 1 ≤ X.card` ∧ `∃ σ, X = X.image (fun x => σ - x)`) -- OR (`l.length ≤ X.card` ∧ `∃ c, B = X.image (fun x => c - x)`)! have hinv : ∀ l : List (Dihedral n), l.Sublist s → let X := insert (0 : ZMod n) (dReach l).1 let B := (dReach l).2 (B = ∅ ∧ l.length + 1 ≤ X.card ∧ ∃ σ : ZMod n, X = X.image (fun x => σ - x)) ∨ (l.length ≤ X.card ∧ ∃ c : ZMod n, B = X.image (fun x => c - x)) := by intro l induction l using List.reverseRecOn with | nil => intro _ left refine ⟨rfl, by simp [dReach], 0, ?_⟩ ext x; simp [dReach] | append_singleton l g ih => intro hl have hl' : l.Sublist s := (List.sublist_append_left _ _).trans hl have h0not' : (0 : ZMod n) ∉ (dReach (l ++ [g])).1 := h0not _ hl have hstep : dReach (l ++ [g]) = dStep (dReach l) g := by dsimp only [dReach]; rw [List.foldl_append, List.foldl_cons, List.foldl_nil] set X := insert (0 : ZMod n) (dReach l).1 with hX_def set B := (dReach l).2 with hB_def set X' := insert (0 : ZMod n) (dReach (l ++ [g])).1 with hX'_def set B' := (dReach (l ++ [g])).2 with hB'_def rcases g with ⟨a, bg⟩ rcases bg with _ | _ · -- Rotation `g = (a, false)`! have hX'_eq : X' = X ∪ X.image (· + a) := by ext y; simp only [hX'_def, hX_def, hstep, dStep, Bool.false_eq_true, ↓reduceIte, Finset.mem_insert, Finset.mem_union, Finset.mem_image] constructor · rintro (rfl | hy | ⟨x, hx, rfl⟩) · left; left; rfl · left; right; exact hy · right; exact ⟨x, hx, rfl⟩ · rintro ((rfl | hy) | ⟨x, hx, rfl⟩) · left; rfl · right; left; exact hy · right; right; exact ⟨x, hx, rfl⟩ have hB'_eq : B' = B ∪ B.image (· - a) := by simp only [hB'_def, hB_def, hstep, dStep, Bool.false_eq_true, ↓reduceIte] have ha0 : a ≠ 0 := by intro h; subst h; apply h0not' rw [hstep]; dsimp only [dStep]; simp have h0tr : ∀ x ∈ X, x + a ≠ 0 := by intro x hx hxa apply h0not'; rw [← hxa, hstep]; dsimp only [dStep] simp only [Bool.false_eq_true, ↓reduceIte, Finset.mem_union, Finset.mem_image] right; exact ⟨x, hx, rfl⟩ have hgrow : X.card < X'.card := by rw [hX'_eq]; exact zMod_translate_card_gt (Finset.mem_insert_self 0 _) ha0 h0tr rcases ih hl' with ⟨hBe, hlen, σ, hsym⟩ | ⟨hlen, c, hBsym⟩ · left refine ⟨by rw [hB'_eq, hBe]; simp, by simp; omega, σ + a, ?_⟩ ext y rw [hX'_eq] simp only [Finset.mem_union, Finset.mem_image] constructor · rintro (hy | ⟨x, hx, rfl⟩) · rw [hsym] at hy rcases Finset.mem_image.mp hy with ⟨z, hz, rfl⟩ exact ⟨z + a, Or.inr ⟨z, hz, rfl⟩, by ring⟩ · rw [hsym] at hx rcases Finset.mem_image.mp hx with ⟨z, hz, rfl⟩ exact ⟨z, Or.inl hz, by ring⟩ · rintro ⟨z, hz | ⟨w, hw, rfl⟩, rfl⟩ · rw [hsym] at hz rcases Finset.mem_image.mp hz with ⟨u, hu, rfl⟩ right; exact ⟨u, hu, by ring⟩ · rw [hsym] at hw rcases Finset.mem_image.mp hw with ⟨u, hu, rfl⟩ left; convert hu using 1; ring · right refine ⟨by simp; omega, c, ?_⟩ ext y rw [hB'_eq, hBsym, hX'_eq] simp only [Finset.mem_union, Finset.mem_image] constructor · rintro (⟨x, hx, rfl⟩ | ⟨z, ⟨x, hx, rfl⟩, rfl⟩) · exact ⟨x, Or.inl hx, rfl⟩ · exact ⟨x + a, Or.inr ⟨x, hx, rfl⟩, by ring⟩ · rintro ⟨z, hz | ⟨x, hx, rfl⟩, rfl⟩ · left; exact ⟨z, hz, rfl⟩ · right; exact ⟨c - x, ⟨x, hx, rfl⟩, by ring⟩ · -- Reflection `g = (a, true)`! have hX'_eq : X' = X ∪ B.image (· - a) := by ext y; simp only [hX'_def, hX_def, hB_def, hstep, dStep, ↓reduceIte, Finset.mem_insert, Finset.mem_union, Finset.mem_image] tauto have hB'_eq : B' = B ∪ X.image (· + a) := by simp only [hB'_def, hB_def, hX_def, hstep, dStep, ↓reduceIte] rcases ih hl' with ⟨hBe, hlen, σ, hsym⟩ | ⟨hlen, c, hBsym⟩ · -- First reflection! `X' = X` (`|X'| ≥ l.length + 1`), `B' = X + a = -X + (σ + a)`! right refine ⟨by rw [hX'_eq, hBe]; simp; omega, σ + a, ?_⟩ have hX'X : X' = X := by rw [hX'_eq, hBe]; simp rw [hB'_eq, hBe, Finset.empty_union, hX'X] ext y simp only [Finset.mem_image] constructor · rintro ⟨x, hx, rfl⟩ rw [hsym] at hx rcases Finset.mem_image.mp hx with ⟨z, hz, rfl⟩ exact ⟨z, hz, by ring⟩ · rintro ⟨z, hz, rfl⟩ rw [hsym] at hz rcases Finset.mem_image.mp hz with ⟨x, hx, rfl⟩ exact ⟨x, hx, by ring⟩ · -- Subsequent reflection! `a ∉ B` (else `a - a = 0 ∈ A'`), so `c - a ∈ X' \ X`! have ha_notB : a ∉ B := by intro haB; apply h0not' rw [hstep]; dsimp only [dStep]; simp only [↓reduceIte, Finset.mem_union, Finset.mem_image] right; exact ⟨a, haB, sub_self a⟩ have hca_notX : c - a ∉ X := by intro hmem; apply ha_notB; rw [hBsym] exact Finset.mem_image.mpr ⟨c - a, hmem, by ring⟩ have hca_inX' : c - a ∈ X' := by rw [hX'_eq] apply Finset.mem_union_right refine Finset.mem_image.mpr ⟨c, ?_, rfl⟩ rw [hBsym]; exact Finset.mem_image.mpr ⟨0, Finset.mem_insert_self 0 _, by ring⟩ have hgrow : X.card < X'.card := by apply Finset.card_lt_card rw [Finset.ssubset_iff_subset_ne] exact ⟨by rw [hX'_eq]; exact Finset.subset_union_left, fun h => hca_notX (h ▸ hca_inX')⟩ right refine ⟨by simp; omega, c, ?_⟩ ext y rw [hB'_eq, hX'_eq, hBsym] simp only [Finset.mem_union, Finset.mem_image] constructor · rintro (⟨x, hx, rfl⟩ | ⟨x, hx, rfl⟩) · exact ⟨x, Or.inl hx, rfl⟩ · exact ⟨(c - x) - a, Or.inr ⟨c - x, ⟨x, hx, rfl⟩, rfl⟩, by ring⟩ · rintro ⟨z, hz | ⟨w, ⟨x, hx, rfl⟩, rfl⟩, rfl⟩ · left; exact ⟨z, hz, rfl⟩ · right; exact ⟨x, hx, by ring⟩ have hfinal := hinv s (List.Sublist.refl s) have hcard_le : (insert (0 : ZMod n) (dReach s).1).card ≤ n := by simpa [ZMod.card] using Finset.card_le_univ (insert (0 : ZMod n) (dReach s).1) rcases hfinal with ⟨_, hlen, _⟩ | ⟨hlen, _⟩ <;> omega /-- Alternating product of a list of reflections in `D_{2n}`: for `l = [a_0, a_1, …]`, `listProd dMul dOne (l.map (·, true))` has `Bool` equal to `Odd l.length`, and when `l` is strictly increasing in `0, …, n - 1` of even positive length, its rotation is strictly negative in `-(n - 1), …, -1` (never `0` mod `n`!). -/ lemma listProd_dMul_refls_odd_len {n : ℕ} (l : List (ZMod n)) : (listProd dMul dOne (l.map (fun a => (a, true)))).2 = decide (Odd l.length) := by induction l with | nil => simp [dOne] | cons a l ih => simp only [List.map_cons, listProd_cons, dMul, ih, List.length_cons] by_cases h : Odd l.length · have h' : ¬ Odd (l.length + 1) := by rcases h with ⟨k, hk⟩; intro ⟨j, hj⟩; omega simp [h, h'] · have h' : Odd (l.length + 1) := by rw [Nat.not_odd_iff_even] at h; rcases h with ⟨k, hk⟩; exact ⟨k, by omega⟩ simp [h, h'] /-- **THEOREM 1b (Universal Odd-Weight Ordered Witness in `D_{2n}`):** For EVERY `n ≥ 1` and EVERY set `A` of odd integers (`∀ w ∈ A, ¬ Even w`), the length-`n` all-reflection list `[(0, true), (1, true), …, (n - 1, true)]` has NO ordered `A`-weighted product-one subsequence! -/ theorem dihedral_odd_weights_reflection_witness {n : ℕ} (hn : 1 ≤ n) {A : Set ℤ} (hA : ∀ w ∈ A, ¬ Even w) : ¬ HasOrdWeightedP1 dMul dOne dZPow A ((List.range n).map (fun i : ℕ => ((i : ZMod n), true))) := by have : NeZero n := ⟨by omega⟩ rintro ⟨sub, ws, hsub, hne, hlen, hw, hprod⟩ -- Every odd power of a reflection is itself, so `zipWith dZPow sub ws = sub`! have hzip_id : List.zipWith dZPow sub ws = sub := by have hall_t : ∀ x ∈ sub, x.2 = true := fun x hx => by rcases List.mem_map.mp (hsub.subset hx) with ⟨i, _, rfl⟩; rfl clear hprod hne hsub induction sub generalizing ws with | nil => cases ws <;> rfl | cons x xs ih => cases ws with | nil => simp at hlen | cons w ws' => have hx2 : x.2 = true := hall_t x (List.mem_cons_self ..) have hpow : dZPow x w = x := by rcases x with ⟨a, b⟩; dsimp only at hx2; subst hx2 exact dZPow_refl_odd a (hA w (List.mem_cons_self .. |> hw w)) simp only [List.zipWith_cons_cons, hpow] congr 1 exact ih ws' (by simpa using hlen) (fun u hu => hw u (List.mem_cons_of_mem _ hu)) (fun u hu => hall_t u (List.mem_cons_of_mem _ hu)) rw [hzip_id] at hprod -- Pull `sub` back to a strictly increasing sublist `idx` of `List.range n`! obtain ⟨idx, hidx_sub, hidx_map⟩ := List.sublist_map_iff.mp hsub have hidx_ne : idx ≠ [] := fun h => hne (by rw [hidx_map, h]; rfl) have hidx_pw : idx.Pairwise (· < ·) := List.Pairwise.sublist hidx_sub List.pairwise_lt_range have hidx_lt : ∀ i ∈ idx, i < n := fun i hi => List.mem_range.mp (hidx_sub.subset hi) -- Check parity of `idx.length`: must be even! have hprod_b := congrArg Prod.snd hprod rw [hidx_map] at hprod hprod_b have hmap_comp : idx.map (fun i : ℕ => ((i : ZMod n), true)) = (idx.map (fun i : ℕ => (i : ZMod n))).map (fun a => (a, true)) := by rw [List.map_map]; rfl rw [hmap_comp, listProd_dMul_refls_odd_len] at hprod_b simp only [List.length_map, dOne, decide_eq_false_iff_not, Nat.not_odd_iff_even] at hprod_b -- Clean tighter alternating-sum bound: `1 ≤ d` and `lo + d < n`! have halt_tight : ∀ (l : List ℕ) (lo : ℕ), Even l.length → l.Pairwise (· < ·) → (∀ i ∈ l, lo ≤ i ∧ i < n) → l ≠ [] → ∃ d : ℕ, 1 ≤ d ∧ lo + d < n ∧ listProd dMul dOne (l.map (fun i : ℕ => ((i : ZMod n), true))) = (-(d : ZMod n), false) := by intro l induction l using List.twoStepInduction with | nil => intro _ _ _ _ h; exact absurd rfl h | singleton a => intro _ hev _ _ _; simp at hev | cons_cons a b l ih => intro lo hev hpw hbounds _ have hab : a < b := (List.pairwise_cons.mp hpw).1 b (List.mem_cons_self ..) have ha_lo : lo ≤ a := (hbounds a (List.mem_cons_self ..)).1 have hb_lt : b < n := (hbounds b (List.mem_cons_of_mem _ (List.mem_cons_self ..))).2 cases l with | nil => refine ⟨b - a, by omega, by omega, ?_⟩ simp only [List.map_cons, List.map_nil, listProd_cons, listProd_nil, dMul, dOne, ↓reduceIte, Bool.xor_false, Bool.xor_self, sub_zero, Prod.mk.injEq, and_true] have hba : (b : ZMod n) = (a : ZMod n) + ((b - a : ℕ) : ZMod n) := by rw [← Nat.cast_add, Nat.add_sub_of_le (le_of_lt hab)] rw [hba]; ring | cons c l' => have hpw2 := (List.pairwise_cons.mp hpw).2 have hcl_pw : (c :: l').Pairwise (· < ·) := (List.pairwise_cons.mp hpw2).2 have hcl_ev : Even (c :: l').length := by rcases hev with ⟨k, hk⟩ simp only [List.length_cons] at hk ⊢ exact ⟨k - 1, by omega⟩ have hcl_bounds : ∀ i ∈ (c :: l'), b ≤ i ∧ i < n := fun i hi => ⟨le_of_lt ((List.pairwise_cons.mp hpw2).1 i hi), (hbounds i (List.mem_cons_of_mem _ (List.mem_cons_of_mem _ hi))).2⟩ obtain ⟨d, hd1, hbd, hprod_l⟩ := ih b hcl_ev hcl_pw hcl_bounds (List.cons_ne_nil _ _) refine ⟨(b - a) + d, by omega, by omega, ?_⟩ rw [List.map_cons, List.map_cons, listProd_cons, listProd_cons, hprod_l] simp only [dMul, ↓reduceIte, Bool.xor_false, Bool.xor_self, Prod.mk.injEq, and_true] have hba : (b : ZMod n) = (a : ZMod n) + ((b - a : ℕ) : ZMod n) := by rw [← Nat.cast_add, Nat.add_sub_of_le (le_of_lt hab)] push_cast rw [hba]; ring obtain ⟨d, hd1, hdn, hval⟩ := halt_tight idx 0 hprod_b hidx_pw (fun i hi => ⟨Nat.zero_le _, hidx_lt i hi⟩) hidx_ne rw [hval] at hprod have hneg0 : -(d : ZMod n) = 0 := congrArg Prod.fst hprod have hd0 : (d : ZMod n) = 0 := neg_eq_zero.mp hneg0 have hdvd : n ∣ d := (ZMod.natCast_eq_zero_iff d n).mp hd0 have hle := Nat.le_of_dvd (by omega) hdvd omega /-- Unweighted unordered witness in `D_{2n}`: `[(0, true)] ++ replicate (n - 1) (1, false)` (length `n`). -/ theorem dihedral_unweighted_unord_witness {n : ℕ} (hn : 1 ≤ n) : ¬ HasUnordWeightedP1 dMul dOne dZPow { (1 : ℤ) } ((0, true) :: List.replicate (n - 1) ((1 : ZMod n), false)) := by have : NeZero n := ⟨by omega⟩ rintro ⟨s', hp, sub, ws, hsub, hne, hlen, hw, hprod⟩ -- Since weights are all `1`, `zipWith dZPow sub ws = sub`! have hzip_id : List.zipWith dZPow sub ws = sub := by clear hprod hne hsub hp induction sub generalizing ws with | nil => cases ws <;> rfl | cons x xs ih => cases ws with | nil => simp at hlen | cons w ws' => have hw1 : w = 1 := Set.mem_singleton_iff.mp (hw w (List.mem_cons_self ..)) subst hw1 simp only [List.zipWith_cons_cons, dZPow_one] congr 1 exact ih ws' (by simpa using hlen) (fun u hu => hw u (List.mem_cons_of_mem _ hu)) rw [hzip_id] at hprod have hcount_s' : s'.countP (fun x : Dihedral n => x.2) = 1 := by rw [hp.countP_eq] simp [List.countP_replicate] have hcount_sub_le : sub.countP (fun x : Dihedral n => x.2) ≤ 1 := by rw [← hcount_s']; exact List.Sublist.countP_le hsub have hprod_snd : ∀ l : List (Dihedral n), (listProd dMul dOne l).2 = decide (Odd (l.countP (fun x => x.2))) := by intro l induction l with | nil => simp [dOne] | cons x xs ih => simp only [listProd_cons, dMul, ih, List.countP_cons] cases x.2 with | false => simp | true => simp only [Bool.true_xor, ↓reduceIte] by_cases h : Odd (xs.countP (fun x => x.2)) · have h' : ¬ Odd (xs.countP (fun x => x.2) + 1) := by rcases h with ⟨k, hk⟩; intro ⟨j, hj⟩; omega simp [h, h'] · have h' : Odd (xs.countP (fun x => x.2) + 1) := by rw [Nat.not_odd_iff_even] at h; rcases h with ⟨k, hk⟩; exact ⟨k, by omega⟩ simp [h, h'] have hodd := congrArg Prod.snd hprod rw [hprod_snd] at hodd simp only [dOne, decide_eq_false_iff_not, Nat.not_odd_iff_even] at hodd have hcount0 : sub.countP (fun x : Dihedral n => x.2) = 0 := by rcases hodd with ⟨k, hk⟩; omega have hall1 : ∀ x ∈ sub, x = ((1 : ZMod n), false) := by intro x hx have hx_in : x ∈ (0, true) :: List.replicate (n - 1) ((1 : ZMod n), false) := hp.mem_iff.mp (hsub.subset hx) rcases List.mem_cons.mp hx_in with rfl | hrep · exfalso have hpos : 0 < sub.countP (fun y : Dihedral n => y.2) := List.countP_pos_iff.mpr ⟨((0 : ZMod n), true), hx, rfl⟩ omega · exact List.eq_of_mem_replicate hrep have hsub_len_le : sub.length ≤ n - 1 := by have hcnt_f : sub.countP (fun x : Dihedral n => !x.2) = sub.length := by rw [List.countP_eq_length]; intro x hx; rw [hall1 x hx]; rfl have hcnt_s' : s'.countP (fun x : Dihedral n => !x.2) = n - 1 := by rw [hp.countP_eq]; simp [List.countP_replicate] rw [← hcnt_f, ← hcnt_s']; exact List.Sublist.countP_le hsub have hprod_eq_gen : ∀ l : List (Dihedral n), (∀ x ∈ l, x = ((1 : ZMod n), false)) → listProd dMul dOne l = ((l.length : ZMod n), false) := by intro l induction l with | nil => intro _; simp [dOne] | cons x xs ih => intro hl have hx := hl x (List.mem_cons_self ..) have ih' := ih (fun u hu => hl u (List.mem_cons_of_mem _ hu)) rw [listProd_cons, hx, ih'] simp [dMul]; ring rw [hprod_eq_gen sub hall1] at hprod have hlen0 : (sub.length : ZMod n) = 0 := congrArg Prod.fst hprod have hdvd : n ∣ sub.length := (ZMod.natCast_eq_zero_iff sub.length n).mp hlen0 have hpos : 0 < sub.length := List.length_pos_iff.mpr hne have hle := Nat.le_of_dvd hpos hdvd omega /-- **THEOREM 1 (Exact Unweighted Dihedral Davenport Theorem — Ordered & Unordered):** For ALL `n ≥ 1`, `D_ord({1}, D_{2n}) = D_unord({1}, D_{2n}) = n + 1`. -/ theorem dihedral_unweighted_exact {n : ℕ} (hn : 1 ≤ n) : ordWeightedDavenport (α := Dihedral n) dMul dOne dZPow { (1 : ℤ) } = n + 1 ∧ unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow { (1 : ℤ) } = n + 1 := by have hup := dihedral_ord_davenport_upper hn have hup_un : ∀ s : List (Dihedral n), s.length = n + 1 → HasUnordWeightedP1 dMul dOne dZPow { (1 : ℤ) } s := fun s hs => hasUnord_of_hasOrd (hup s hs) have hwit_ord : ∃ s : List (Dihedral n), s.length = n ∧ ¬ HasOrdWeightedP1 dMul dOne dZPow { (1 : ℤ) } s := ⟨(List.range n).map (fun i : ℕ => ((i : ZMod n), true)), by simp, dihedral_odd_weights_reflection_witness (A := { (1 : ℤ) }) hn (by intro w hw; rw [Set.mem_singleton_iff.mp hw]; decide)⟩ have hwit_un : ∃ s : List (Dihedral n), s.length = n ∧ ¬ HasUnordWeightedP1 dMul dOne dZPow { (1 : ℤ) } s := ⟨(0, true) :: List.replicate (n - 1) ((1 : ZMod n), false), by simp; omega, dihedral_unweighted_unord_witness hn⟩ exact ⟨ordWeightedDavenport_eq (by omega) hup (Or.inr hwit_ord), unordWeightedDavenport_eq (by omega) hup_un (Or.inr hwit_un)⟩ /-! ### 5. THEOREM 2: Complete Even-vs-Odd Weight Dichotomy in `D_{2n}` (NEW!) -/ /-- **THEOREM 2a (Ordered Odd-Weight Immunity in `D_{2n}` — NEW!):** For EVERY `n ≥ 1` and EVERY integer weight set `A` with `1 ∈ A` and all weights odd (including `A = {1, c}` for odd `c`, or ALL odd integers `A = {w | ¬ Even w}`!), the ordered weighted Davenport constant of `D_{2n}` stays rigidly locked at `n + 1`! -/ theorem dihedral_ord_odd_weights_exact {n : ℕ} (hn : 1 ≤ n) {A : Set ℤ} (h1A : (1 : ℤ) ∈ A) (hodd : ∀ w ∈ A, ¬ Even w) : ordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A = n + 1 := by have hsub : ({(1 : ℤ)} : Set ℤ) ⊆ A := Set.singleton_subset_iff.mpr h1A have hup : ∀ s : List (Dihedral n), s.length = n + 1 → HasOrdWeightedP1 dMul dOne dZPow A s := fun s hs => hasOrd_mono_weights hsub (dihedral_ord_davenport_upper hn s hs) have hwit : ∃ s : List (Dihedral n), s.length = n ∧ ¬ HasOrdWeightedP1 dMul dOne dZPow A s := ⟨(List.range n).map (fun i : ℕ => ((i : ZMod n), true)), by simp, dihedral_odd_weights_reflection_witness hn hodd⟩ exact ordWeightedDavenport_eq (by omega) hup (Or.inr hwit) /-- **THEOREM 2b (Universal Even-Weight Collapse in `D_{2n}` — NEW!):** For EVERY `n ≥ 1` and EVERY weight set `A` containing ANY even integer `w₀ ∈ A`, BOTH ordered and unordered weighted Davenport constants of `D_{2n}` collapse identically to the cyclic weighted Davenport constant `D_A(ℤ_n)`! -/ theorem dihedral_even_weight_collapse {n : ℕ} {A : Set ℤ} (heven : ∃ w₀ ∈ A, Even w₀) (hne : ∃ d, 0 < d ∧ ∀ s : List (ZMod n), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul A s) : ordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A = ordWeightedDavenport (α := ZMod n) zAdd zZero zSmul A ∧ unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A = ordWeightedDavenport (α := ZMod n) zAdd zZero zSmul A := by rcases heven with ⟨w₀, hw₀A, hw₀ev⟩ set D := ordWeightedDavenport (α := ZMod n) zAdd zZero zSmul A with hD_def have hD_mem := Nat.sInf_mem hne change 0 < D ∧ ∀ s : List (ZMod n), s.length = D → HasOrdWeightedP1 zAdd zZero zSmul A s at hD_mem -- Upper bound for `D_ord(A, D_{2n}) ≤ D`: have hup_ord : ∀ s : List (Dihedral n), s.length = D → HasOrdWeightedP1 dMul dOne dZPow A s := by intro s hs by_cases hrefl : ∃ x ∈ s, x.2 = true · rcases hrefl with ⟨⟨a, b⟩, hx, hb⟩ dsimp only at hb; subst hb exact hasOrd_single dMul_one hx hw₀A (dZPow_refl_even a hw₀ev) · push Not at hrefl have hs_eq : s = (s.map Prod.fst).map (fun a => (a, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id s] apply List.map_congr_left intro x hx; rcases x with ⟨a, b⟩ have hb : b = false := Bool.eq_false_iff.mpr (hrefl (a, b) hx) simp [hb] have hlen_fst : (s.map Prod.fst).length = D := by rw [List.length_map, hs] obtain ⟨sub, ws, hsub, hne', hlen', hw, hprod⟩ := hD_mem.2 (s.map Prod.fst) hlen_fst refine ⟨sub.map (fun a => (a, false)), ws, ?_, by simp [hne'], by simp [hlen'], hw, ?_⟩ · rw [hs_eq]; exact hsub.map _ · have hzip : List.zipWith dZPow (sub.map (fun a => (a, false))) ws = (List.zipWith zSmul sub ws).map (fun a => (a, false)) := by clear hprod hw hne' hsub hs_eq hrefl induction sub generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen' | cons w ws' => simp [dZPow_rot, zSmul, ih ws' (by simpa using hlen')] rw [hzip, listProd_dMul_rot] rw [listProd_zAdd_eq_sum] at hprod rw [hprod]; rfl -- Lower bound for `D_unord(A, D_{2n}) ≥ D`: -- Any rotation-only witness `t : List (ZMod n)` embeds into `D_{2n}` preserving avoidance! have hrot_avoid : ∀ t : List (ZMod n), ¬ HasOrdWeightedP1 zAdd zZero zSmul A t → ¬ HasUnordWeightedP1 dMul dOne dZPow A (t.map (fun a => (a, false))) := by intro t ht ⟨s', hp, sub, ws, hsub, hne', hlen', hw, hprod⟩ have hs'_rot : ∀ x ∈ s', x.2 = false := fun x hx => by rcases List.mem_map.mp (hp.mem_iff.mp hx) with ⟨a, _, rfl⟩; rfl have hsub_rot : ∀ x ∈ sub, x.2 = false := fun x hx => hs'_rot x (hsub.subset hx) have hsub_eq : sub = (sub.map Prod.fst).map (fun a => (a, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id sub] apply List.map_congr_left intro x hx; rcases x with ⟨a, b⟩ exact Prod.ext rfl (hsub_rot (a, b) hx) have hzip : List.zipWith dZPow sub ws = (List.zipWith zSmul (sub.map Prod.fst) ws).map (fun a => (a, false)) := by conv_lhs => rw [hsub_eq] have hlen'' : ws.length = (sub.map Prod.fst).length := by simp [hlen'] clear hprod hw hne' hsub hp hs'_rot hsub_rot hsub_eq hlen' generalize sub.map Prod.fst = u at hlen'' ⊢ induction u generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen'' | cons w ws' => simp [dZPow_rot, zSmul, ih ws' (by simpa using hlen'')] rw [hzip, listProd_dMul_rot] at hprod have hsum0 : (List.zipWith zSmul (sub.map Prod.fst) ws).sum = 0 := congrArg Prod.fst hprod have hp_fst : (s'.map Prod.fst).Perm t := by have := hp.map Prod.fst; rwa [List.map_map, Function.comp_def, List.map_id'] at this have hun : HasUnordWeightedP1 zAdd zZero zSmul A t := ⟨s'.map Prod.fst, hp_fst, sub.map Prod.fst, ws, hsub.map Prod.fst, by simp [hne'], by simp [hlen'], hw, by rw [listProd_zAdd_eq_sum]; exact hsum0⟩ exact ht (hasUnord_iff_hasOrd_zMod.mp hun) have hle_ord : ordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A ≤ D := ordWeightedDavenport_le hD_mem.1 hup_ord have hle_un : unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A ≤ ordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A := unordWeightedDavenport_le_ord ⟨D, hD_mem.1, hup_ord⟩ have hge_un : D ≤ unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow A := by by_cases hD1 : D = 1 · rw [hD1] exact (Nat.sInf_mem (s := { d : ℕ | 0 < d ∧ ∀ s : List (Dihedral n), s.length = d → HasUnordWeightedP1 dMul dOne dZPow A s }) ⟨D, hD_mem.1, fun s hs => hasUnord_of_hasOrd (hup_ord s hs)⟩).1 · have hDgt : 0 < D - 1 := by omega have hnot_mem : ¬ (0 < D - 1 ∧ ∀ t : List (ZMod n), t.length = D - 1 → HasOrdWeightedP1 zAdd zZero zSmul A t) := fun hm => by have := Nat.sInf_le (s := { d : ℕ | 0 < d ∧ ∀ s : List (ZMod n), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul A s }) hm change D ≤ D - 1 at this; omega have hex : ∃ t : List (ZMod n), t.length = D - 1 ∧ ¬ HasOrdWeightedP1 zAdd zZero zSmul A t := by by_contra hall; push Not at hall; exact hnot_mem ⟨hDgt, hall⟩ rcases hex with ⟨t, htlen, htno⟩ have hlt := lt_unordWeightedDavenport ⟨D, hD_mem.1, fun s hs => hasUnord_of_hasOrd (hup_ord s hs)⟩ ⟨t.map (fun a => (a, false)), by rw [List.length_map, htlen], hrot_avoid t htno⟩ omega omega /-- **Corollary 2 (Exact Closed Forms for Interval Weights `{1, …, c}` (`∀ c ≥ 2`) and Even `{1, c}` in `D_{2cm}`):** -/ theorem dihedral_even_and_interval_exact {c m : ℕ} (hc : 2 ≤ c) (hm : 1 ≤ m) : ordWeightedDavenport (α := Dihedral (c * m)) dMul dOne dZPow (Set.Icc (1 : ℤ) (c : ℤ)) = m ∧ unordWeightedDavenport (α := Dihedral (c * m)) dMul dOne dZPow (Set.Icc (1 : ℤ) (c : ℤ)) = m ∧ (Even c → ordWeightedDavenport (α := Dihedral (c * m)) dMul dOne dZPow ({1, (c : ℤ)} : Set ℤ) = m ∧ unordWeightedDavenport (α := Dihedral (c * m)) dMul dOne dZPow ({1, (c : ℤ)} : Set ℤ) = m) := by have hcyc := cyclic_weighted_1c_exact (c := c) (m := m) (by omega) hm have hne_icc : ∃ d, 0 < d ∧ ∀ s : List (ZMod (c * m)), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul (Set.Icc (1 : ℤ) (c : ℤ)) s := ⟨m, hm, fun s hs => hasOrd_mono_weights (fun x hx => by rw [Set.mem_singleton_iff.mp hx]; exact ⟨by omega, le_refl _⟩) (cyclic_weighted_c_upper (by omega) hm s hs)⟩ have hev2 : ∃ w₀ ∈ Set.Icc (1 : ℤ) (c : ℤ), Even w₀ := ⟨2, ⟨by omega, by omega⟩, ⟨1, rfl⟩⟩ have hcoll_icc := dihedral_even_weight_collapse (n := c * m) hev2 hne_icc refine ⟨by rw [hcoll_icc.1, hcyc.2], by rw [hcoll_icc.2, hcyc.2], ?_⟩ intro hevc have hne_1c : ∃ d, 0 < d ∧ ∀ s : List (ZMod (c * m)), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul ({1, (c : ℤ)} : Set ℤ) s := ⟨m, hm, fun s hs => hasOrd_mono_weights (fun x hx => Or.inr hx) (cyclic_weighted_c_upper (by omega) hm s hs)⟩ have hevz : Even (c : ℤ) := by rcases hevc with ⟨k, rfl⟩; exact ⟨k, by push_cast; ring⟩ have hcoll_1c := dihedral_even_weight_collapse (n := c * m) ⟨c, Or.inr rfl, hevz⟩ hne_1c exact ⟨by rw [hcoll_1c.1, hcyc.1], by rw [hcoll_1c.2, hcyc.1]⟩ /-! ### 6. THEOREM 3: Exponential Ordered-vs-Unordered Separation in `D_{2n}` (NEW!) -/ /-- Interleave two lists of equal length `[a_0, b_0, a_1, b_1, …]` as reflections and compute the dihedral product! -/ def interleaveRefl {n : ℕ} : List (ZMod n) → List (ZMod n) → List (Dihedral n) | [], _ => [] | _, [] => [] | a :: as, b :: bs => (a, true) :: (b, true) :: interleaveRefl as bs lemma listProd_interleaveRefl {n : ℕ} : ∀ (l₁ l₂ : List (ZMod n)), l₁.length = l₂.length → listProd dMul dOne (interleaveRefl l₁ l₂) = (l₁.sum - l₂.sum, false) | [], [], _ => by simp [interleaveRefl, dOne] | a :: as, b :: bs, hlen => by have ih := listProd_interleaveRefl as bs (by simpa using hlen) simp only [interleaveRefl, listProd_cons, ih, dMul, ↓reduceIte, Bool.xor_false, Bool.xor_self, List.sum_cons, Prod.mk.injEq, and_true] ring | [], _ :: _, hlen => by simp at hlen | _ :: _, [], hlen => by simp at hlen lemma interleaveRefl_perm_append {n : ℕ} : ∀ (l₁ l₂ : List (ZMod n)), l₁.length = l₂.length → (interleaveRefl l₁ l₂).Perm ((l₁ ++ l₂).map (fun a => (a, true))) | [], [], _ => List.Perm.refl _ | a :: as, b :: bs, hlen => by have ih := interleaveRefl_perm_append as bs (by simpa using hlen) simp only [interleaveRefl, List.cons_append, List.map_cons, List.map_append] exact ((ih.cons _).cons _).trans (List.Perm.cons _ (by rw [List.map_append]; exact List.perm_middle.symm)) | [], _ :: _, hlen => by simp at hlen | _ :: _, [], hlen => by simp at hlen /-- Elementary central binomial lower bound: `choose (2 * m) m > 2 ^ m` for all `m ≥ 2`! -/ lemma two_pow_lt_centralBinom {m : ℕ} (hm : 2 ≤ m) : 2 ^ m < Nat.choose (2 * m) m := by induction m with | zero => omega | succ k ih => by_cases hk : k = 1 · subst hk; decide · have hk2 : 2 ≤ k := by omega have hih := ih hk2 have hrec : 2 * Nat.choose (2 * k) k < Nat.choose (2 * (k + 1)) (k + 1) := by have hstep1 : Nat.choose (2 * (k + 1)) (k + 1) = Nat.choose (2 * k) (k - 1) + 2 * Nat.choose (2 * k) k + Nat.choose (2 * k) (k + 1) := by have h1 : 2 * (k + 1) = (2 * k + 1) + 1 := by omega have h2 : Nat.choose (2 * k + 1) k = Nat.choose (2 * k) (k - 1) + Nat.choose (2 * k) k := by cases k with | zero => omega | succ j => exact Nat.choose_succ_succ (2 * (j + 1)) j have h3 : Nat.choose (2 * k + 1) (k + 1) = Nat.choose (2 * k) k + Nat.choose (2 * k) (k + 1) := Nat.choose_succ_succ (2 * k) k rw [h1, Nat.choose_succ_succ, h2, h3]; ring have hpos : 0 < Nat.choose (2 * k) (k + 1) := Nat.choose_pos (by omega) omega calc 2 ^ (k + 1) = 2 * 2 ^ k := by ring _ < 2 * Nat.choose (2 * k) k := by omega _ < Nat.choose (2 * (k + 1)) (k + 1) := hrec /-- **THEOREM 3a (Reflection Subset-Sum Pigeonhole Bound in `D_{2n}` — NEW!):** For EVERY `n ≥ 1` and EVERY list `s` of `k` reflections in `D_{2n}` with `n < Nat.choose k (k / 2)`, `s` contains an **unordered** product-one subsequence (with ALL weights `= 1`)! -/ theorem dihedral_unord_reflections_binom_bound {n : ℕ} (hn : 1 ≤ n) {s : List (Dihedral n)} (hrefl : ∀ x ∈ s, x.2 = true) (hbin : n < Nat.choose s.length (s.length / 2)) : HasUnordWeightedP1 dMul dOne dZPow { (1 : ℤ) } s := by have : NeZero n := ⟨by omega⟩ set k := s.length with hk_def let f : Fin k → ZMod n := fun i => (s[i.val]'(by omega)).1 let F : Finset (Finset (Fin k)) := Finset.powersetCard (k / 2) Finset.univ have hcardF : F.card = Nat.choose k (k / 2) := by simp [F, Finset.card_powersetCard] have hlt : Fintype.card (ZMod n) < Fintype.card F := by simp only [ZMod.card, Fintype.card_coe, hcardF]; exact hbin obtain ⟨I, J, hIJ_ne, hsum_eq⟩ := Fintype.exists_ne_map_eq_of_card_lt (fun S : F => ∑ i ∈ S.1, f i) hlt have hI_card : I.1.card = k / 2 := (Finset.mem_powersetCard.mp I.2).2 have hJ_card : J.1.card = k / 2 := (Finset.mem_powersetCard.mp J.2).2 have hIJ_set_ne : I.1 ≠ J.1 := fun h => hIJ_ne (Subtype.ext h) -- Remove common intersection `I ∩ J` to get disjoint equal-size nonempty subsets `I', J'`! let I' := I.1 \ J.1 let J' := J.1 \ I.1 have hdisj : Disjoint I' J' := Finset.disjoint_left.mpr fun x h1 h2 => (Finset.mem_sdiff.mp h1).2 (Finset.mem_sdiff.mp h2).1 have hcard_eq : I'.card = J'.card := by have h1 := Finset.card_sdiff_add_card_inter I.1 J.1 have h2 := Finset.card_sdiff_add_card_inter J.1 I.1 rw [Finset.inter_comm] at h2 dsimp only [I', J']; omega have hI'_ne : I'.Nonempty := by by_contra hemp rw [Finset.not_nonempty_iff_eq_empty] at hemp have hsub : I.1 ⊆ J.1 := Finset.sdiff_eq_empty_iff_subset.mp hemp exact hIJ_set_ne (Finset.eq_of_subset_of_card_le hsub (by omega)) have hsum_diff : ∑ i ∈ I', f i = ∑ j ∈ J', f j := by have hI_split : I.1 \ (I.1 ∩ J.1) = I' := by ext x; simp only [I', Finset.mem_sdiff, Finset.mem_inter]; tauto have hJ_split : J.1 \ (I.1 ∩ J.1) = J' := by ext x; simp only [J', Finset.mem_sdiff, Finset.mem_inter]; tauto have h1 : ∑ i ∈ I', f i + ∑ i ∈ I.1 ∩ J.1, f i = ∑ i ∈ I.1, f i := by rw [← hI_split]; exact Finset.sum_sdiff Finset.inter_subset_left have h2 : ∑ j ∈ J', f j + ∑ i ∈ I.1 ∩ J.1, f i = ∑ j ∈ J.1, f j := by rw [← hJ_split]; exact Finset.sum_sdiff Finset.inter_subset_right have heq : ∑ i ∈ I', f i + ∑ i ∈ I.1 ∩ J.1, f i = ∑ j ∈ J', f j + ∑ i ∈ I.1 ∩ J.1, f i := by rw [h1, h2]; exact hsum_eq exact add_right_cancel heq -- Convert `I', J'` to lists of indices, interleave their reflections, and build a permutation of `s`! let lI : List (Fin k) := I'.toList let lJ : List (Fin k) := J'.toList let lR : List (Fin k) := (Finset.univ \ (I' ∪ J')).toList have hlen_IJ : lI.length = lJ.length := by simp [lI, lJ, hcard_eq] have hperm_idx : (lI ++ lJ ++ lR).Perm (List.finRange k) := by have hnodup : (lI ++ lJ ++ lR).Nodup := by rw [List.nodup_append, List.nodup_append] refine ⟨⟨Finset.nodup_toList _, Finset.nodup_toList _, ?_⟩, Finset.nodup_toList _, ?_⟩ · intro i hi j hj heq; subst heq exact Finset.disjoint_left.mp hdisj (Finset.mem_toList.mp hi) (Finset.mem_toList.mp hj) · intro i hi j hj heq; subst heq have hj' := Finset.mem_sdiff.mp (Finset.mem_toList.mp hj) rcases List.mem_append.mp hi with hi | hi · exact hj'.2 (Finset.mem_union_left _ (Finset.mem_toList.mp hi)) · exact hj'.2 (Finset.mem_union_right _ (Finset.mem_toList.mp hi)) refine (List.perm_ext_iff_of_nodup hnodup (List.nodup_finRange k)).mpr ?_ intro i dsimp only [lI, lJ, lR] simp only [List.mem_append, Finset.mem_toList, List.mem_finRange, iff_true, Finset.mem_sdiff, Finset.mem_univ, Finset.mem_union, true_and] by_cases h1 : i ∈ I' <;> by_cases h2 : i ∈ J' <;> tauto -- Map `List.finRange k` back to `s`! have hs_of_finRange : (List.finRange k).map (fun i : Fin k => s[i.val]'(by omega)) = s := by apply List.ext_getElem (by simp [k]) intro i hi₁ hi₂; simp let aI := lI.map f let aJ := lJ.map f have hmap_refl : ∀ l : List (Fin k), l.map (fun i => s[i.val]'(by omega)) = (l.map f).map (fun a => (a, true)) := by intro l rw [List.map_map] apply List.map_congr_left intro i _ have h2 : (s[i.val]'(by omega)).2 = true := hrefl _ (List.getElem_mem _) exact Prod.ext rfl h2 let sub := interleaveRefl aI aJ let rest := lR.map (fun i => s[i.val]'(by omega)) have hperm_full : (sub ++ rest).Perm s := by rw [← hs_of_finRange] have hp1 : (sub ++ rest).Perm (((aI ++ aJ).map (fun a => (a, true))) ++ rest) := (interleaveRefl_perm_append aI aJ (by simp [aI, aJ, hlen_IJ])).append_right rest have heq1 : (((aI ++ aJ).map (fun a => (a, true))) ++ rest) = (lI ++ lJ ++ lR).map (fun i => s[i.val]'(by omega)) := by have hm := hmap_refl (lI ++ lJ) simp only [List.map_append] at hm ⊢ rw [← hm] rw [heq1] at hp1 exact hp1.trans (hperm_idx.map _) have hsub_ne : sub ≠ [] := by have hlI_pos : 0 < aI.length := by simp [aI, lI, Finset.card_pos.mpr hI'_ne] cases haI : aI with | nil => simp [haI] at hlI_pos | cons x xs => cases haJ : aJ with | nil => have hlen_eq : aI.length = aJ.length := by simp [aI, aJ, hlen_IJ] rw [haI, haJ] at hlen_eq; simp at hlen_eq | cons y ys => simp [sub, haI, haJ, interleaveRefl] have hprod_sub : listProd dMul dOne sub = dOne := by rw [listProd_interleaveRefl aI aJ (by simp [aI, aJ, hlen_IJ])] have hsum_toList : ∀ S : Finset (Fin k), (S.toList.map f).sum = ∑ i ∈ S, f i := fun S => by rw [← Multiset.sum_coe, ← Multiset.map_coe, Finset.coe_toList]; rfl have hsumI : aI.sum = ∑ i ∈ I', f i := hsum_toList I' have hsumJ : aJ.sum = ∑ j ∈ J', f j := hsum_toList J' rw [hsumI, hsumJ, hsum_diff, sub_self]; rfl have hzip_id : List.zipWith dZPow sub (List.replicate sub.length (1 : ℤ)) = sub := by clear hprod_sub hsub_ne hperm_full generalize sub = u induction u with | nil => rfl | cons x xs ih => simp [List.replicate_succ, ih] refine ⟨sub ++ rest, hperm_full, sub, List.replicate sub.length 1, List.sublist_append_left sub rest, hsub_ne, List.length_replicate, fun w hw => Set.mem_singleton_iff.mpr (List.eq_of_mem_replicate hw), ?_⟩ rw [hzip_id]; exact hprod_sub /-- **THEOREM 3b (General Odd-`c` Unordered Upper Bound in `D_{2cm}` — NEW!):** For ALL `c ≥ 1, m ≥ 1`, and ANY `k` with `c * m < Nat.choose k (k / 2)`: `D_unord({1, c}, D_{2cm}) ≤ m + k - 1`! In particular (taking `k = 2 * Nat.log 2 (c * m) + 4`): `D_unord({1, c}, D_{2cm}) ≤ m + 2 * Nat.log 2 (c * m) + 3`! -/ theorem dihedral_unord_odd_c_upper {c m k : ℕ} (hc : 1 ≤ c) (hm : 1 ≤ m) (hbin : c * m < Nat.choose k (k / 2)) : unordWeightedDavenport (α := Dihedral (c * m)) dMul dOne dZPow ({1, (c : ℤ)} : Set ℤ) ≤ m + k - 1 := by have hk_pos : 1 ≤ k := by by_contra h0; have : k = 0 := by omega subst this; simp at hbin; have := Nat.mul_pos hc hm; omega apply unordWeightedDavenport_le (by omega) intro s hs -- Partition `s` into rotations `sRot` and reflections `sRefl`! let sRot := s.filter (fun x => !x.2) let sRefl := s.filter (fun x => x.2) have hperm_part : (sRot ++ sRefl).Perm s := by have h1 := perm_filter_append_filter_not (fun x : Dihedral (c * m) => !x.2) s have h2 : s.filter (fun x => !(!x.2)) = sRefl := by dsimp only [sRefl]; congr 1; funext x; exact Bool.not_not x.2 rw [h2] at h1; exact h1 have hlen_sum : sRot.length + sRefl.length = m + k - 1 := by have := hperm_part.length_eq; rw [List.length_append, hs] at this; exact this by_cases hrot : m ≤ sRot.length · -- At least `m` rotations ⇒ use `cyclic_weighted_c_upper`! let t := (sRot.take m).map Prod.fst have ht_len : t.length = m := by rw [List.length_map, List.length_take, min_eq_left hrot] obtain ⟨sub, ws, hsub, hne, hlen, hw, hprod⟩ := cyclic_weighted_c_upper hc hm t ht_len have hrot_eq : sRot.take m = t.map (fun a => (a, false)) := by dsimp only [t]; rw [List.map_map]; conv_lhs => rw [← List.map_id (sRot.take m)] apply List.map_congr_left intro x hx have hx' := (List.mem_filter.mp (List.mem_of_mem_take hx)).2 rcases x with ⟨a, b⟩; simp at hx'; simp [hx'] have hzip : List.zipWith dZPow (sub.map (fun a => (a, false))) ws = (List.zipWith zSmul sub ws).map (fun a => (a, false)) := by clear hprod hw hne hsub hrot_eq ht_len hrot hlen_sum hperm_part induction sub generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen | cons w ws' => simp [dZPow_rot, zSmul, ih ws' (by simpa using hlen)] refine ⟨sRot ++ sRefl, hperm_part, sub.map (fun a => (a, false)), ws, ?_, by simp [hne], by simp [hlen], fun w hw' => Or.inr (hw w hw'), ?_⟩ · exact ((hsub.map _).trans (by rw [← hrot_eq]; exact List.take_sublist _ _)).trans (List.sublist_append_left _ _) · rw [hzip, listProd_dMul_rot] rw [listProd_zAdd_eq_sum] at hprod rw [hprod]; rfl · -- At least `k` reflections ⇒ use `dihedral_unord_reflections_binom_bound`! have hrefl_ge : k ≤ sRefl.length := by omega let r := sRefl.take k have hr_len : r.length = k := by rw [List.length_take, min_eq_left hrefl_ge] have hr_all : ∀ x ∈ r, x.2 = true := fun x hx => (List.mem_filter.mp (List.mem_of_mem_take hx)).2 have hbin_r : c * m < Nat.choose r.length (r.length / 2) := by rw [hr_len]; exact hbin obtain ⟨r', hp_r', hord_r'⟩ := dihedral_unord_reflections_binom_bound (Nat.mul_pos hc hm) hr_all hbin_r have hp_full : (r' ++ sRefl.drop k ++ sRot).Perm s := by have hp1 : (r' ++ sRefl.drop k ++ sRot).Perm (r ++ sRefl.drop k ++ sRot) := (hp_r'.append_right _).append_right _ rw [List.take_append_drop] at hp1 exact hp1.trans (List.perm_append_comm.trans hperm_part) refine ⟨r' ++ sRefl.drop k ++ sRot, hp_full, hasOrd_mono_weights (fun w hw => Or.inl hw) ?_⟩ exact hasOrd_of_sublist ((List.sublist_append_left r' _).trans (List.sublist_append_left _ _)) hord_r' /-- Uniqueness of binary subset sums: if `I, J ⊆ range t` have `∑ i ∈ I, 2 ^ i = ∑ j ∈ J, 2 ^ j`, then `I = J`! -/ lemma finset_sum_two_pow_inj : ∀ {t : ℕ} {I J : Finset ℕ}, (∀ i ∈ I, i < t) → (∀ j ∈ J, j < t) → ∑ i ∈ I, 2 ^ i = ∑ j ∈ J, 2 ^ j → I = J := by intro t induction t with | zero => intro I J hI hJ _ have hIe : I = ∅ := Finset.eq_empty_of_forall_notMem (fun i hi => by have := hI i hi; omega) have hJe : J = ∅ := Finset.eq_empty_of_forall_notMem (fun j hj => by have := hJ j hj; omega) rw [hIe, hJe] | succ t ih => intro I J hI hJ hsum have hsum_lt : ∀ S : Finset ℕ, (∀ i ∈ S, i < t) → ∑ i ∈ S, 2 ^ i < 2 ^ t := by intro S hS have hsub : S ⊆ Finset.range t := fun i hi => Finset.mem_range.mpr (hS i hi) calc ∑ i ∈ S, 2 ^ i ≤ ∑ i ∈ Finset.range t, 2 ^ i := Finset.sum_le_sum_of_subset hsub _ < 2 ^ t := by clear hsub hS S hsum hI hJ I J ih induction t with | zero => simp | succ k ihk => rw [Finset.sum_range_succ, pow_succ]; omega by_cases htI : t ∈ I <;> by_cases htJ : t ∈ J · have hI' : ∀ i ∈ I.erase t, i < t := fun i hi => by have := Finset.mem_erase.mp hi; have := hI i this.2; omega have hJ' : ∀ j ∈ J.erase t, j < t := fun j hj => by have := Finset.mem_erase.mp hj; have := hJ j this.2; omega have hsum' : ∑ i ∈ I.erase t, 2 ^ i = ∑ j ∈ J.erase t, 2 ^ j := by have h1 := Finset.add_sum_erase I (fun i => 2 ^ i) htI have h2 := Finset.add_sum_erase J (fun j => 2 ^ j) htJ omega have heq := ih hI' hJ' hsum' rw [← Finset.insert_erase htI, ← Finset.insert_erase htJ, heq] · exfalso have hJ' : ∀ j ∈ J, j < t := fun j hj => by have := hJ j hj; have hne : j ≠ t := fun h => htJ (h ▸ hj); omega have h1 : 2 ^ t ≤ ∑ i ∈ I, 2 ^ i := Finset.single_le_sum (fun _ _ => Nat.zero_le _) htI have h2 := hsum_lt J hJ' omega · exfalso have hI' : ∀ i ∈ I, i < t := fun i hi => by have := hI i hi; have hne : i ≠ t := fun h => htI (h ▸ hi); omega have h1 : 2 ^ t ≤ ∑ j ∈ J, 2 ^ j := Finset.single_le_sum (fun _ _ => Nat.zero_le _) htJ have h2 := hsum_lt I hI' omega · have hI' : ∀ i ∈ I, i < t := fun i hi => by have := hI i hi; have hne : i ≠ t := fun h => htI (h ▸ hi); omega have hJ' : ∀ j ∈ J, j < t := fun j hj => by have := hJ j hj; have hne : j ≠ t := fun h => htJ (h ▸ hj); omega exact ih hI' hJ' hsum /-- **THEOREM 3c (Binary Powers-of-2 Unordered Reflection Lower-Bound Witness — NEW!):** For EVERY `n ≥ 1`, `t : ℕ` with `2 ^ t ≤ n`, and EVERY set `A` of odd integers, the length-`(t + 1)` binary reflection sequence `[(0, true), (1, true), (2, true), (4, true), …, (2^(t-1), true)]` has NO unordered `A`-weighted product-one subsequence! -/ theorem dihedral_binary_reflection_witness {n t : ℕ} (ht : 2 ^ t ≤ n) {A : Set ℤ} (hA : ∀ w ∈ A, ¬ Even w) : let vals : List ℕ := 0 :: (List.range t).map (fun i => 2 ^ i) ¬ HasUnordWeightedP1 dMul dOne dZPow A (vals.map (fun v : ℕ => ((v : ZMod n), true))) := by intro vals have hn : 1 ≤ n := le_trans (Nat.one_le_two_pow) ht have : NeZero n := ⟨by omega⟩ rintro ⟨s', hp, sub, ws, hsub, hne, hlen, hw, hprod⟩ -- Every odd power of a reflection is itself! have hall_t : ∀ x ∈ sub, x.2 = true := fun x hx => by rcases List.mem_map.mp (hp.mem_iff.mp (hsub.subset hx)) with ⟨v, _, rfl⟩; rfl have hzip_id : List.zipWith dZPow sub ws = sub := by clear hprod hne hsub hp induction sub generalizing ws with | nil => cases ws <;> rfl | cons x xs ih => cases ws with | nil => simp at hlen | cons w ws' => have hx2 := hall_t x (List.mem_cons_self ..) have hpow : dZPow x w = x := by rcases x with ⟨a, b⟩; dsimp only at hx2; subst hx2 exact dZPow_refl_odd a (hA w (hw w (List.mem_cons_self ..))) simp only [List.zipWith_cons_cons, hpow] congr 1 exact ih ws' (by simpa using hlen) (fun u hu => hw u (List.mem_cons_of_mem _ hu)) (fun u hu => hall_t u (List.mem_cons_of_mem _ hu)) rw [hzip_id] at hprod -- Pull `sub` back to a sublist of a permutation of `vals` (all elements distinct!) have hvals_nd : vals.Nodup := by dsimp only [vals] rw [List.nodup_cons] refine ⟨?_, List.Nodup.map (fun a b hab => by exact Nat.pow_right_injective (by norm_num : 1 < 2) hab) List.nodup_range⟩ intro h0; rcases List.mem_map.mp h0 with ⟨i, _, hi⟩ have := Nat.one_le_two_pow (n := i); omega have hvals_inj : ∀ a ∈ vals, ∀ b ∈ vals, ((a : ZMod n), true) = ((b : ZMod n), true) → a = b := by have hlt_n : ∀ v ∈ vals, v < n := by intro v hv; dsimp only [vals] at hv rcases List.mem_cons.mp hv with rfl | hv · omega · rcases List.mem_map.mp hv with ⟨i, hi, rfl⟩ have hi' := List.mem_range.mp hi have : 2 ^ i < 2 ^ t := Nat.pow_lt_pow_right (by norm_num) hi' omega intro a ha b hb heq have hz : (a : ZMod n) = (b : ZMod n) := congrArg Prod.fst heq have h1 : (a : ZMod n).val = a := ZMod.val_natCast_of_lt (hlt_n a ha) have h2 : (b : ZMod n).val = b := ZMod.val_natCast_of_lt (hlt_n b hb) rw [← h1, ← h2, hz] -- Extract a nodup list `u : List ℕ` of elements from `vals` whose mapped reflections equal `sub`! obtain ⟨s'_nat, hp_nat, hs'_eq⟩ := exists_perm_of_map_perm hp.symm obtain ⟨u, hu_sub, hu_map⟩ := List.sublist_map_iff.mp (hs'_eq ▸ hsub) have hu_nd : u.Nodup := List.Nodup.sublist hu_sub (hp_nat.nodup_iff.mpr hvals_nd) have hu_ne : u ≠ [] := fun h => hne (by rw [hu_map, h]; rfl) have hu_sub_vals : ∀ v ∈ u, v ∈ vals := fun v hv => hp_nat.mem_iff.mp (hu_sub.subset hv) -- Split `u` into even-index and odd-index entries `(uE, uO)`! have hsplit : ∀ l : List ℕ, ∃ (lE lO : List ℕ), (lE ++ lO).Perm l ∧ (Even l.length → lE.length = lO.length ∧ listProd dMul dOne (l.map (fun v : ℕ => ((v : ZMod n), true))) = ((lE.sum : ZMod n) - (lO.sum : ZMod n), false)) := by intro l induction l using List.twoStepInduction with | nil => exact ⟨[], [], List.Perm.refl _, fun _ => ⟨rfl, by simp [dOne]⟩⟩ | singleton a => exact ⟨[a], [], List.Perm.refl _, fun hev => by simp at hev⟩ | cons_cons a b l ih => obtain ⟨lE, lO, hp_eo, hev_eo⟩ := ih refine ⟨a :: lE, b :: lO, ?_, ?_⟩ · exact (List.Perm.cons a List.perm_middle).trans ((hp_eo.cons b).cons a) · intro hev have hev' : Even l.length := by rcases hev with ⟨k, hk⟩; simp only [List.length_cons] at hk; exact ⟨k - 1, by omega⟩ obtain ⟨hlen_eo, hprod_eo⟩ := hev_eo hev' refine ⟨by simp [hlen_eo], ?_⟩ simp only [List.map_cons, listProd_cons, hprod_eo, dMul, ↓reduceIte, Bool.xor_false, Bool.xor_self, List.sum_cons, Nat.cast_add, Prod.mk.injEq, and_true] ring -- Show `Even u.length`! have hu_ev : Even u.length := by have hprod_b := congrArg Prod.snd hprod rw [hu_map] at hprod_b have hcomp : u.map (fun v : ℕ => ((v : ZMod n), true)) = (u.map (fun v : ℕ => (v : ZMod n))).map (fun a => (a, true)) := by rw [List.map_map]; rfl rw [hcomp, listProd_dMul_refls_odd_len] at hprod_b simp only [List.length_map, dOne, decide_eq_false_iff_not, Nat.not_odd_iff_even] at hprod_b exact hprod_b obtain ⟨uE, uO, hp_eo, hev_eo⟩ := hsplit u obtain ⟨hlen_eo, hprod_eo⟩ := hev_eo hu_ev rw [hu_map, hprod_eo] at hprod have hz_eq : (uE.sum : ZMod n) = (uO.sum : ZMod n) := sub_eq_zero.mp (congrArg Prod.fst hprod) -- Since `uE ++ uO` is nodup and a subset of `vals`, BOTH `uE.sum` and `uO.sum` are `≤ vals.sum = 2^t - 1 < n`! have hvals_sum : vals.sum < n := by have hpow_sum : ∀ k : ℕ, ((List.range k).map (fun i => 2 ^ i)).sum = 2 ^ k - 1 := by intro k induction k with | zero => simp | succ k ih => rw [List.range_succ, List.map_append, List.sum_append, ih] simp only [List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero, pow_succ] have := Nat.one_le_two_pow (n := k); omega dsimp only [vals]; rw [List.sum_cons, zero_add, hpow_sum t] have := Nat.one_le_two_pow (n := t); omega have heo_nd : (uE ++ uO).Nodup := hp_eo.nodup_iff.mpr hu_nd have huE_nd : uE.Nodup := (List.nodup_append.mp heo_nd).1 have huO_nd : uO.Nodup := (List.nodup_append.mp heo_nd).2.1 have huEO_disj : ∀ x ∈ uE, x ∉ uO := fun x hxE hxO => (List.nodup_append.mp heo_nd).2.2 x hxE x hxO rfl have hlist_sum_finset : ∀ l : List ℕ, l.Nodup → l.sum = ∑ x ∈ l.toFinset, x := by intro l induction l with | nil => intro _; simp | cons a l ih => intro h; rw [List.nodup_cons] at h rw [List.sum_cons, List.toFinset_cons, Finset.sum_insert (by simpa using h.1), ih h.2] have hsum_le_vals : ∀ l : List ℕ, l.Nodup → (∀ x ∈ l, x ∈ vals) → l.sum ≤ vals.sum := by intro l hl_nd hl_sub rw [hlist_sum_finset l hl_nd, hlist_sum_finset vals hvals_nd] exact Finset.sum_le_sum_of_subset (fun x hx => List.mem_toFinset.mpr (hl_sub x (List.mem_toFinset.mp hx))) have huE_lt : uE.sum < n := lt_of_le_of_lt (hsum_le_vals uE huE_nd (fun x hx => hu_sub_vals x (hp_eo.mem_iff.mp (List.mem_append_left _ hx)))) hvals_sum have huO_lt : uO.sum < n := lt_of_le_of_lt (hsum_le_vals uO huO_nd (fun x hx => hu_sub_vals x (hp_eo.mem_iff.mp (List.mem_append_right _ hx)))) hvals_sum have hnat_eq : uE.sum = uO.sum := by have h1 : (uE.sum : ZMod n).val = uE.sum := ZMod.val_natCast_of_lt huE_lt have h2 : (uO.sum : ZMod n).val = uO.sum := ZMod.val_natCast_of_lt huO_lt rw [← h1, ← h2, hz_eq] -- Extract exponent sets `I, J ⊆ range t` from `uE.toFinset.erase 0` and `uO.toFinset.erase 0`! let I : Finset ℕ := (Finset.range t).filter (fun i => 2 ^ i ∈ uE) let J : Finset ℕ := (Finset.range t).filter (fun i => 2 ^ i ∈ uO) have hsum_filter_clean : ∀ l : List ℕ, l.Nodup → (∀ x ∈ l, x ∈ vals) → l.sum = ∑ i ∈ (Finset.range t).filter (fun i => 2 ^ i ∈ l), 2 ^ i := by intro l hl_nd hl_sub rw [hlist_sum_finset l hl_nd] have himg : ((Finset.range t).filter (fun i => 2 ^ i ∈ l)).image (fun i => 2 ^ i) = l.toFinset.erase 0 := by ext v simp only [Finset.mem_image, Finset.mem_filter, Finset.mem_range, Finset.mem_erase, List.mem_toFinset] constructor · rintro ⟨i, ⟨_, hmem⟩, rfl⟩ exact ⟨Nat.ne_of_gt Nat.one_le_two_pow, hmem⟩ · rintro ⟨hv0, hvl⟩ have hvv := hl_sub v hvl dsimp only [vals] at hvv rcases List.mem_cons.mp hvv with rfl | hmap · exact absurd rfl hv0 · rcases List.mem_map.mp hmap with ⟨i, hi, rfl⟩ exact ⟨i, ⟨List.mem_range.mp hi, hvl⟩, rfl⟩ have hsum_img : ∑ i ∈ (Finset.range t).filter (fun i => 2 ^ i ∈ l), 2 ^ i = ∑ v ∈ l.toFinset.erase 0, v := by rw [← himg, Finset.sum_image] intro a _ b _ hab exact Nat.pow_right_injective (by norm_num : 1 < 2) hab rw [hsum_img] by_cases h0 : 0 ∈ l.toFinset · have := Finset.add_sum_erase l.toFinset id h0 simpa using this.symm · rw [Finset.erase_eq_of_notMem h0] have hsumI := hsum_filter_clean uE huE_nd (fun x hx => hu_sub_vals x (hp_eo.mem_iff.mp (List.mem_append_left _ hx))) have hsumJ := hsum_filter_clean uO huO_nd (fun x hx => hu_sub_vals x (hp_eo.mem_iff.mp (List.mem_append_right _ hx))) have hIJ_eq : I = J := finset_sum_two_pow_inj (fun i hi => Finset.mem_range.mp (Finset.mem_filter.mp hi).1) (fun j hj => Finset.mem_range.mp (Finset.mem_filter.mp hj).1) (by rw [← hsumI, ← hsumJ, hnat_eq]) -- Since `uE` and `uO` are disjoint, `I = J = ∅`! have hI_empty : I = ∅ := by apply Finset.eq_empty_of_forall_notMem intro i hi have hE : 2 ^ i ∈ uE := (Finset.mem_filter.mp hi).2 have hiJ : i ∈ J := hIJ_eq ▸ hi have hO : 2 ^ i ∈ uO := (Finset.mem_filter.mp hiJ).2 exact huEO_disj (2 ^ i) hE hO have hJ_empty : J = ∅ := hIJ_eq ▸ hI_empty -- Thus BOTH `uE` and `uO` contain ONLY `0`, contradicting disjointness since `uE.length = uO.length ≥ 1`! have huE_ne : uE ≠ [] := by intro h; rw [h] at hlen_eo have huO_nil : uO = [] := List.eq_nil_of_length_eq_zero (by simpa using hlen_eo.symm) have : u = [] := List.Perm.eq_nil (by simpa [h, huO_nil] using hp_eo.symm) exact hu_ne this have huO_ne : uO ≠ [] := fun h => huE_ne (List.eq_nil_of_length_eq_zero (by rw [hlen_eo, h]; rfl)) obtain ⟨xE, hxE⟩ := List.exists_mem_of_ne_nil uE huE_ne obtain ⟨xO, hxO⟩ := List.exists_mem_of_ne_nil uO huO_ne have hxE0 : xE = 0 := by have hv := hu_sub_vals xE (hp_eo.mem_iff.mp (List.mem_append_left _ hxE)) dsimp only [vals] at hv rcases List.mem_cons.mp hv with rfl | hmap · rfl · rcases List.mem_map.mp hmap with ⟨i, hi, rfl⟩ have : i ∈ I := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (List.mem_range.mp hi), hxE⟩ rw [hI_empty] at this; exact absurd this (Finset.notMem_empty _) have hxO0 : xO = 0 := by have hv := hu_sub_vals xO (hp_eo.mem_iff.mp (List.mem_append_right _ hxO)) dsimp only [vals] at hv rcases List.mem_cons.mp hv with rfl | hmap · rfl · rcases List.mem_map.mp hmap with ⟨i, hi, rfl⟩ have : i ∈ J := Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (List.mem_range.mp hi), hxO⟩ rw [hJ_empty] at this; exact absurd this (Finset.notMem_empty _) rw [hxE0] at hxE; rw [hxO0] at hxO exact huEO_disj 0 hxE hxO /-- **THEOREM 3d (Exponential Ordered-vs-Unordered Weighted Davenport Separation in `D_{2n}` — NEW!):** For EVERY odd `n ≥ 1` with `A = {1, n}` (two odd weights): 1. `D_ord({1, n}, D_{2n}) = n + 1` (LINEAR in `n`!), 2. `Nat.log 2 n + 2 ≤ D_unord({1, n}, D_{2n}) ≤ 2 * Nat.log 2 n + 4` (LOGARITHMIC in `n`!)! -/ theorem dihedral_exponential_ord_unord_separation {n : ℕ} (hn : 1 ≤ n) (hodd : ¬ Even n) : ordWeightedDavenport (α := Dihedral n) dMul dOne dZPow ({1, (n : ℤ)} : Set ℤ) = n + 1 ∧ Nat.log 2 n + 2 ≤ unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow ({1, (n : ℤ)} : Set ℤ) ∧ unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow ({1, (n : ℤ)} : Set ℤ) ≤ 2 * Nat.log 2 n + 4 := by have hAodd : ∀ w ∈ ({1, (n : ℤ)} : Set ℤ), ¬ Even w := by intro w hw; rcases hw with rfl | rfl · decide · rintro ⟨k, hk⟩; apply hodd have hkn : 0 ≤ k := by omega exact ⟨k.toNat, by omega⟩ have hord := dihedral_ord_odd_weights_exact hn (Or.inl rfl) hAodd -- Upper bound directly via `dihedral_unord_reflections_binom_bound`: any rotation `x` has `n • x.1 = 0`! set L := Nat.log 2 n with hL_def have hup : unordWeightedDavenport (α := Dihedral n) dMul dOne dZPow ({1, (n : ℤ)} : Set ℤ) ≤ 2 * L + 4 := by apply unordWeightedDavenport_le (by omega) intro s hs by_cases hrot : ∃ x ∈ s, x.2 = false · rcases hrot with ⟨⟨a, b⟩, hx, hb⟩; dsimp only at hb; subst hb refine hasUnord_of_hasOrd (hasOrd_single dMul_one hx (Or.inr rfl) ?_) rw [dZPow_rot] have h0 : (n : ℤ) • a = 0 := by rw [zsmul_eq_mul, Int.cast_natCast, ZMod.natCast_self, zero_mul] rw [h0]; rfl · push Not at hrot have hrefl : ∀ x ∈ s, x.2 = true := fun x hx => Bool.eq_true_of_not_eq_false (hrot x hx) have hbin : n < Nat.choose s.length (s.length / 2) := by rw [hs, show (2 * L + 4) / 2 = L + 2 by omega, show 2 * L + 4 = 2 * (L + 2) by omega] have h1 : n < 2 ^ (L + 1) := Nat.lt_pow_succ_log_self (by norm_num) n have h2 : 2 ^ (L + 1) ≤ 2 ^ (L + 2) := Nat.pow_le_pow_right (by norm_num) (by omega) have h3 : 2 ^ (L + 2) < Nat.choose (2 * (L + 2)) (L + 2) := two_pow_lt_centralBinom (by omega) omega exact hasUnord_mono_weights (fun w hw => Or.inl hw) (dihedral_unord_reflections_binom_bound hn hrefl hbin) -- Lower bound via `dihedral_binary_reflection_witness` with `t = L`! have h2L : 2 ^ L ≤ n := Nat.pow_log_le_self 2 (by omega) have hwit := dihedral_binary_reflection_witness h2L hAodd dsimp only at hwit have hne_un : ∃ d, 0 < d ∧ ∀ s : List (Dihedral n), s.length = d → HasUnordWeightedP1 dMul dOne dZPow ({1, (n : ℤ)} : Set ℤ) s := ⟨n + 1, by omega, fun s hs => hasUnord_of_hasOrd (hasOrd_mono_weights (fun w hw => Or.inl hw) (dihedral_ord_davenport_upper hn s hs))⟩ have hlt := lt_unordWeightedDavenport (k := L + 1) hne_un ⟨((0 : ℕ) :: (List.range L).map (fun i => 2 ^ i)).map (fun v : ℕ => ((v : ZMod n), true)), by simp, hwit⟩ exact ⟨hord, by omega, hup⟩ /-- **Corollary 3 (Exact Smallest Strict Separation Threshold for `A = {1, 3}`):** At `n = 4` (`D_8`), `D_ord({1, 3}, D_8) = 5 > 4 ≥ D_unord({1, 3}, D_8)`! -/ theorem dihedral_D8_strict_separation : ordWeightedDavenport (α := Dihedral 4) dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) = 5 ∧ unordWeightedDavenport (α := Dihedral 4) dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) ≤ 4 := by have hord := dihedral_ord_odd_weights_exact (n := 4) (A := ({1, (3 : ℤ)} : Set ℤ)) (by omega) (Or.inl rfl) (by intro w hw; rcases hw with rfl | rfl <;> decide) refine ⟨hord, unordWeightedDavenport_le (by omega) ?_⟩ intro s hs let sRot := s.filter (fun x => !x.2) let sRefl := s.filter (fun x => x.2) have hperm_part : (sRot ++ sRefl).Perm s := by have h1 := perm_filter_append_filter_not (fun x : Dihedral 4 => !x.2) s have h2 : s.filter (fun x => !(!x.2)) = sRefl := by dsimp only [sRefl]; congr 1; funext x; exact Bool.not_not x.2 rw [h2] at h1; exact h1 have hlen_sum : sRot.length + sRefl.length = 4 := by have := hperm_part.length_eq; rw [List.length_append, hs] at this; exact this -- Notice: in `ZMod 4`, `3 • x = -x`! So ANY TWO rotations `a, b` with `a = b` give `a + 3 • b = 0`! -- And ANY `0` rotation gives `1 • 0 = 0`, and ANY `2` rotation gives `2 + 2 = 0`! -- Even better: for `sRot`: if `sRot.length ≥ 3`, then since `ZMod 4` has only `{1, 3}` non-zero-or-2, -- Wait: `{1, 3}` in `ZMod 4` satisfy `1 + 3 = 0` AND `1 + 3*1 = 0`, so ANY TWO non-zero rotations in `{1, 3}` give a `{1, 3}`-zero-sum, -- and any `{2}` + `{1, 3}`? Wait: `2 + 1 + 1 = 0`, `2 + 1 + 3*3 = 2 + 1 + 1 = 0`! So `D_{1,3}(ZMod 4) = 3`! -- Wait: if `sRefl.length = 4`: `choose 4 2 = 6 > 4`, DONE by `dihedral_unord_reflections_binom_bound`! -- If `sRefl.length = 3` and `sRot.length = 1`: 3 reflections `a, b, c` in `ZMod 4` either repeat (done!) -- or are 3 distinct residues in `ZMod 4`, whose pairwise differences hit ALL of `{1, 2, 3}`! Combined with -- the 1 rotation `x` (which is in `{0, 1, 2, 3}`), we get `x + (a - b) = 0`! -- If `sRefl.length = 2` and `sRot.length = 2`: either the 2 rotations give `{1, 3}`-zero-sum OR one is `2` and one is `±1` -- (so rotations reach `{1, 2, 3}` with `{1, 3}` weights!), which cancels `a - b` of the 2 reflections! -- Wait: let's prove all 4 cases cleanly right here! have htwo_eq_refl : ∀ (a b : ZMod 4) (l : List (Dihedral 4)), a = b → HasOrdWeightedP1 dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) ((a, true) :: (b, true) :: l) := by intro a b l hab; subst hab refine ⟨[(a, true), (a, true)], [1, 1], List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.nil_sublist _)), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp [listProd, dMul, dOne] have hrot_hit : ∀ (x : ZMod 4) (l : List (Dihedral 4)), x = 0 → HasOrdWeightedP1 dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) ((x, false) :: l) := by intro x l hx; subst hx exact hasOrd_single dMul_one (List.mem_cons_self ..) (Or.inl rfl) rfl by_cases h4 : sRefl.length = 4 · have hrot0 : sRot = [] := List.eq_nil_of_length_eq_zero (by omega) have hp : sRefl.Perm s := by simpa [hrot0] using hperm_part have hbin : 4 < Nat.choose sRefl.length (sRefl.length / 2) := by rw [h4]; decide exact hasUnord_of_perm hp (hasUnord_mono_weights (fun w hw => Or.inl hw) (dihedral_unord_reflections_binom_bound (n := 4) (by omega) (fun x hx => (List.mem_filter.mp hx).2) hbin)) · -- Finite exhaustive check on `sRot ++ sRefl` via the exact rotation/reflection lengths `(1,3), (2,2), (3,1), (4,0)`! have hrot_all : ∀ x ∈ sRot, x.2 = false := fun x hx => by have := (List.mem_filter.mp hx).2; simpa using this have hrefl_all : ∀ x ∈ sRefl, x.2 = true := fun x hx => (List.mem_filter.mp hx).2 have hpair_rot : ∀ (x y : ZMod 4) (l : List (Dihedral 4)), (x = 0 ∨ y = 0 ∨ x + y = 0 ∨ x + (3 : ℤ) • y = 0) → HasOrdWeightedP1 dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) ((x, false) :: (y, false) :: l) := by intro x y l hor rcases hor with rfl | rfl | hsum | hsum3 · exact hrot_hit 0 _ rfl · exact hasOrd_single dMul_one (List.mem_cons_of_mem _ (List.mem_cons_self ..)) (Or.inl rfl) rfl · refine ⟨[(x, false), (y, false)], [1, 1], List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.nil_sublist _)), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp [listProd, dMul, dOne, hsum] · refine ⟨[(x, false), (y, false)], [1, 3], List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.nil_sublist _)), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp only [List.zipWith_cons_cons, List.zipWith_nil_left, dZPow_one, dZPow_rot, listProd_cons, listProd_nil, dMul, dOne, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, add_zero, Prod.mk.injEq, and_true] exact hsum3 have h1r2f : ∀ (x a b : ZMod 4) (l : List (Dihedral 4)), (x + (a - b) = 0 ∨ (3 : ℤ) • x + (a - b) = 0) → HasOrdWeightedP1 dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) ((x, false) :: (a, true) :: (b, true) :: l) := by intro x a b l hor rcases hor with h1 | h3 · refine ⟨[(x, false), (a, true), (b, true)], [1, 1, 1], List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.nil_sublist _))), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp only [List.zipWith_cons_cons, List.zipWith_nil_left, dZPow_one, listProd_cons, listProd_nil, dMul, dOne, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, Bool.xor_self, sub_zero, Prod.mk.injEq, and_true] exact h1 · refine ⟨[(x, false), (a, true), (b, true)], [3, 1, 1], List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.nil_sublist _))), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp only [List.zipWith_cons_cons, List.zipWith_nil_left, dZPow_one, dZPow_rot, listProd_cons, listProd_nil, dMul, dOne, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, Bool.xor_self, sub_zero, Prod.mk.injEq, and_true] exact h3 have hcases : (sRot.length = 1 ∧ sRefl.length = 3) ∨ (sRot.length = 2 ∧ sRefl.length = 2) ∨ 3 ≤ sRot.length := by omega rcases hcases with ⟨hr1, hf3⟩ | ⟨hr2, hf2⟩ | hr3 · rcases hsRot : sRot with _ | ⟨⟨x, bx⟩, _ | _⟩ <;> try simp [hsRot] at hr1 rcases hsRefl : sRefl with _ | ⟨⟨a, ba⟩, _ | ⟨⟨b, bb⟩, _ | ⟨⟨c, bc⟩, _ | _⟩⟩⟩ <;> try simp [hsRefl] at hf3 have hbx : bx = false := hrot_all (x, bx) (by rw [hsRot]; simp); subst hbx have hba : ba = true := hrefl_all (a, ba) (by rw [hsRefl]; simp); subst hba have hbb : bb = true := hrefl_all (b, bb) (by rw [hsRefl]; simp); subst hbb have hbc : bc = true := hrefl_all (c, bc) (by rw [hsRefl]; simp); subst hbc rw [hsRot, hsRefl] at hperm_part have hfin : ∀ x a b c : ZMod 4, x = 0 ∨ a = b ∨ a = c ∨ b = c ∨ (x + (a - b) = 0 ∨ (3 : ℤ) • x + (a - b) = 0) ∨ (x + (a - c) = 0 ∨ (3 : ℤ) • x + (a - c) = 0) ∨ (x + (b - c) = 0 ∨ (3 : ℤ) • x + (b - c) = 0) := by decide rcases hfin x a b c with hx0 | hab | hac | hbc | h1 | h2 | h3 · exact ⟨_, hperm_part, hrot_hit x _ hx0⟩ · exact ⟨[(a, true), (b, true), (c, true), (x, false)], (by simpa using (List.perm_append_comm.trans hperm_part)), htwo_eq_refl a b _ hab⟩ · refine ⟨[(a, true), (c, true), (b, true), (x, false)], ?_, htwo_eq_refl a c _ hac⟩ have h1' : ([(a, true), (c, true), (b, true), (x, false)] : List (Dihedral 4)).Perm [(x, false), (a, true), (b, true), (c, true)] := by trans [(a, true), (b, true), (c, true), (x, false)] · exact List.Perm.cons _ (List.Perm.swap _ _ _) · exact List.perm_append_comm (l₁ := [(a, true), (b, true), (c, true)]) (l₂ := [(x, false)]) exact h1'.trans hperm_part · refine ⟨[(b, true), (c, true), (a, true), (x, false)], ?_, htwo_eq_refl b c _ hbc⟩ have h1' : ([(b, true), (c, true), (a, true), (x, false)] : List (Dihedral 4)).Perm [(x, false), (a, true), (b, true), (c, true)] := by trans [(a, true), (b, true), (c, true), (x, false)] · exact (List.perm_append_comm (l₁ := [(b, true), (c, true)]) (l₂ := [(a, true)])).append_right [(x, false)] · exact List.perm_append_comm (l₁ := [(a, true), (b, true), (c, true)]) (l₂ := [(x, false)]) exact h1'.trans hperm_part · exact ⟨_, hperm_part, h1r2f x a b _ h1⟩ · refine ⟨[(x, false), (a, true), (c, true), (b, true)], ?_, h1r2f x a c _ h2⟩ exact (List.Perm.cons _ (List.Perm.cons _ (List.Perm.swap _ _ _))).trans hperm_part · refine ⟨[(x, false), (b, true), (c, true), (a, true)], ?_, h1r2f x b c _ h3⟩ have h1' : ([(x, false), (b, true), (c, true), (a, true)] : List (Dihedral 4)).Perm [(x, false), (a, true), (b, true), (c, true)] := List.Perm.cons _ (List.perm_append_comm (l₁ := [(b, true), (c, true)]) (l₂ := [(a, true)])) exact h1'.trans hperm_part · rcases hsRot : sRot with _ | ⟨⟨x, bx⟩, _ | ⟨⟨y, by_⟩, _ | _⟩⟩ <;> try simp [hsRot] at hr2 rcases hsRefl : sRefl with _ | ⟨⟨a, ba⟩, _ | ⟨⟨b, bb⟩, _ | _⟩⟩ <;> try simp [hsRefl] at hf2 have hbx : bx = false := hrot_all (x, bx) (by rw [hsRot]; simp); subst hbx have hby : by_ = false := hrot_all (y, by_) (by rw [hsRot]; simp); subst hby have hba : ba = true := hrefl_all (a, ba) (by rw [hsRefl]; simp); subst hba have hbb : bb = true := hrefl_all (b, bb) (by rw [hsRefl]; simp); subst hbb rw [hsRot, hsRefl] at hperm_part have hfin : ∀ x y a b : ZMod 4, (x = 0 ∨ y = 0 ∨ x + y = 0 ∨ x + (3 : ℤ) • y = 0) ∨ a = b ∨ (x + (a - b) = 0 ∨ (3 : ℤ) • x + (a - b) = 0) ∨ (y + (a - b) = 0 ∨ (3 : ℤ) • y + (a - b) = 0) ∨ (x + y + (a - b) = 0) := by decide rcases hfin x y a b with hp2 | hab | hxab | hyab | hxyab · exact ⟨_, hperm_part, hpair_rot x y _ hp2⟩ · exact ⟨[(a, true), (b, true), (x, false), (y, false)], (by simpa using (List.perm_append_comm.trans hperm_part)), htwo_eq_refl a b _ hab⟩ · refine ⟨[(x, false), (a, true), (b, true), (y, false)], ?_, h1r2f x a b _ hxab⟩ have h1' : ([(x, false), (a, true), (b, true), (y, false)] : List (Dihedral 4)).Perm [(x, false), (y, false), (a, true), (b, true)] := List.Perm.cons _ (List.perm_append_comm (l₁ := [(a, true), (b, true)]) (l₂ := [(y, false)])) exact h1'.trans hperm_part · refine ⟨[(y, false), (a, true), (b, true), (x, false)], ?_, h1r2f y a b _ hyab⟩ have h1' : ([(y, false), (a, true), (b, true), (x, false)] : List (Dihedral 4)).Perm [(x, false), (y, false), (a, true), (b, true)] := List.perm_append_comm (l₁ := [(y, false), (a, true), (b, true)]) (l₂ := [(x, false)]) exact h1'.trans hperm_part · refine ⟨_, hperm_part, [(x, false), (y, false), (a, true), (b, true)], [1, 1, 1, 1], List.Sublist.refl _, List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp only [List.zipWith_cons_cons, List.zipWith_nil_left, dZPow_one, listProd_cons, listProd_nil, dMul, dOne, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, Bool.xor_self, sub_zero, Prod.mk.injEq, and_true] rw [← add_assoc]; exact hxyab · have h3 : ∃ x y z : ZMod 4, ([(x, false), (y, false), (z, false)] : List (Dihedral 4)).Sublist sRot := by rcases hsRot : sRot with _ | ⟨⟨x, bx⟩, _ | ⟨⟨y, by_⟩, _ | ⟨⟨z, bz⟩, rest⟩⟩⟩ <;> try (simp [hsRot] at hr3) have hbx : bx = false := hrot_all (x, bx) (by rw [hsRot]; simp); subst hbx have hby : by_ = false := hrot_all (y, by_) (by rw [hsRot]; simp); subst hby have hbz : bz = false := hrot_all (z, bz) (by rw [hsRot]; simp); subst hbz exact ⟨x, y, z, List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.Sublist.cons_cons _ (List.nil_sublist _)))⟩ rcases h3 with ⟨x, y, z, hsub3⟩ have hfin : ∀ x y z : ZMod 4, x = 0 ∨ y = 0 ∨ z = 0 ∨ x + y = 0 ∨ x + (3 : ℤ) • y = 0 ∨ x + z = 0 ∨ x + (3 : ℤ) • z = 0 ∨ y + z = 0 ∨ y + (3 : ℤ) • z = 0 ∨ x + y + z = 0 := by decide have hord3 : HasOrdWeightedP1 dMul dOne dZPow ({1, (3 : ℤ)} : Set ℤ) [(x, false), (y, false), (z, false)] := by rcases hfin x y z with hx | hy | hz | hxy | hxy3 | hxz | hxz3 | hyz | hyz3 | hxyz · exact hrot_hit x _ hx · exact hasOrd_single (x := (y, false)) dMul_one (by simp) (Or.inl rfl) (by rw [dZPow_one, hy]; rfl) · exact hasOrd_single (x := (z, false)) dMul_one (by simp) (Or.inl rfl) (by rw [dZPow_one, hz]; rfl) · exact hpair_rot x y _ (Or.inr (Or.inr (Or.inl hxy))) · exact hpair_rot x y _ (Or.inr (Or.inr (Or.inr hxy3))) · refine ⟨[(x, false), (z, false)], [1, 1], List.Sublist.cons_cons _ (List.Sublist.cons _ (List.Sublist.cons_cons _ List.Sublist.slnil)), List.cons_ne_nil _ _, rfl, by simp, by simp [listProd, dMul, dOne, hxz]⟩ · refine ⟨[(x, false), (z, false)], [1, 3], List.Sublist.cons_cons _ (List.Sublist.cons _ (List.Sublist.cons_cons _ List.Sublist.slnil)), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp only [List.zipWith_cons_cons, List.zipWith_nil_left, dZPow_one, dZPow_rot, listProd_cons, listProd_nil, dMul, dOne, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, add_zero, Prod.mk.injEq, and_true] exact hxz3 · refine ⟨[(y, false), (z, false)], [1, 1], List.Sublist.cons _ (List.Sublist.cons_cons _ (List.Sublist.cons_cons _ List.Sublist.slnil)), List.cons_ne_nil _ _, rfl, by simp, by simp [listProd, dMul, dOne, hyz]⟩ · refine ⟨[(y, false), (z, false)], [1, 3], List.Sublist.cons _ (List.Sublist.cons_cons _ (List.Sublist.cons_cons _ List.Sublist.slnil)), List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp only [List.zipWith_cons_cons, List.zipWith_nil_left, dZPow_one, dZPow_rot, listProd_cons, listProd_nil, dMul, dOne, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, add_zero, Prod.mk.injEq, and_true] exact hyz3 · refine ⟨[(x, false), (y, false), (z, false)], [1, 1, 1], List.Sublist.refl _, List.cons_ne_nil _ _, rfl, by simp, ?_⟩ simp [listProd, dMul, dOne]; rw [← add_assoc]; exact hxyz exact ⟨sRot ++ sRefl, hperm_part, hasOrd_of_sublist (hsub3.trans (List.sublist_append_left _ _)) hord3⟩ /-! ### 7. THEOREM 4: Concrete Dicyclic Group `Dic_{4n}` & Exact Mod-4 Weighted Classification (NEW!) -/ /-- Concrete dicyclic group `Dic_{4n} = ℤ_{2n} × Bool`, representing `r^a s^b` with `s^2 = r^n`, `s r = r^{-1} s`. -/ abbrev Dicyclic (n : ℕ) := ZMod (2 * n) × Bool def qOne {n : ℕ} : Dicyclic n := (0, false) def qZ {n : ℕ} : Dicyclic n := ((n : ZMod (2 * n)), false) def qMul {n : ℕ} (x y : Dicyclic n) : Dicyclic n := (if x.2 then (if y.2 then x.1 - y.1 + (n : ZMod (2 * n)) else x.1 - y.1) else x.1 + y.1, xor x.2 y.2) def qZPow {n : ℕ} (x : Dicyclic n) (w : ℤ) : Dicyclic n := if x.2 then if w % 4 = 0 then (0, false) else if w % 4 = 1 then (x.1, true) else if w % 4 = 2 then ((n : ZMod (2 * n)), false) else (x.1 + (n : ZMod (2 * n)), true) else (w • x.1, false) lemma qN_add_qN {n : ℕ} : (n : ZMod (2 * n)) + (n : ZMod (2 * n)) = 0 := by have : (n : ZMod (2 * n)) + (n : ZMod (2 * n)) = ((2 * n : ℕ) : ZMod (2 * n)) := by push_cast; ring rw [this, ZMod.natCast_self] lemma qOne_mul {n : ℕ} (x : Dicyclic n) : qMul qOne x = x := by rcases x with ⟨a, b⟩; simp [qOne, qMul] lemma qMul_one {n : ℕ} (x : Dicyclic n) : qMul x qOne = x := by rcases x with ⟨a, b⟩; cases b <;> simp [qOne, qMul] lemma qMul_assoc {n : ℕ} (x y z : Dicyclic n) : qMul (qMul x y) z = qMul x (qMul y z) := by rcases x with ⟨a, bx⟩; rcases y with ⟨b, by_⟩; rcases z with ⟨c, bz⟩ have h2n : (n : ZMod (2 * n)) + (n : ZMod (2 * n)) = 0 := qN_add_qN cases bx <;> cases by_ <;> cases bz <;> simp only [qMul, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, Bool.false_xor, Bool.xor_self, Prod.mk.injEq, and_true] · ring · ring · ring · ring · ring · ring · ring · linear_combination h2n lemma qMul_z_left {n : ℕ} (x : Dicyclic n) : qMul qZ x = (x.1 + (n : ZMod (2 * n)), x.2) := by rcases x with ⟨a, b⟩; simp [qZ, qMul, add_comm] lemma qMul_z_right {n : ℕ} (x : Dicyclic n) : qMul x qZ = (x.1 + (n : ZMod (2 * n)), x.2) := by rcases x with ⟨a, b⟩ cases b · simp [qZ, qMul] · simp only [qZ, qMul, ↓reduceIte, Bool.false_eq_true, Bool.xor_false, Prod.mk.injEq, and_true] linear_combination -qN_add_qN (n := n) lemma qMul_z_comm {n : ℕ} (x : Dicyclic n) : qMul qZ x = qMul x qZ := by rw [qMul_z_left, qMul_z_right] lemma qMul_z_z {n : ℕ} : qMul (qZ (n := n)) qZ = qOne := by simp [qZ, qMul, qOne, qN_add_qN] lemma qZPow_rot {n : ℕ} (a : ZMod (2 * n)) (w : ℤ) : qZPow (a, false) w = (w • a, false) := rfl lemma qZPow_nonrot_mod4_0 {n : ℕ} (a : ZMod (2 * n)) {w : ℤ} (hw : w % 4 = 0) : qZPow (a, true) w = qOne := by simp [qZPow, qOne, hw] lemma qZPow_nonrot_mod4_2 {n : ℕ} (a : ZMod (2 * n)) {w : ℤ} (hw : w % 4 = 2) : qZPow (a, true) w = qZ := by simp [qZPow, qZ, hw] lemma listProd_qMul_rot {n : ℕ} (l : List (ZMod (2 * n))) : listProd qMul qOne (l.map (fun a => (a, false))) = (l.sum, false) := by induction l with | nil => rfl | cons a l ih => simp [qMul, ih] /-- **THEOREM 4a (Universal `4 ∣ w₀` Collapse in Dicyclic Groups `Dic_{4n}` — NEW!):** For EVERY `n ≥ 1` and EVERY weight set `A` containing ANY multiple of `4`, BOTH ordered and unordered weighted Davenport constants of `Dic_{4n}` collapse identically to `D_A(ℤ_{2n})`! In particular, `D_ord({1, 4}, Dic_{8m}) = D_unord({1, 4}, Dic_{8m}) = m`! -/ theorem dicyclic_div4_collapse {n : ℕ} {A : Set ℤ} (hdiv4 : ∃ w₀ ∈ A, w₀ % 4 = 0) (hne : ∃ d, 0 < d ∧ ∀ s : List (ZMod (2 * n)), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul A s) : ordWeightedDavenport (α := Dicyclic n) qMul qOne qZPow A = ordWeightedDavenport (α := ZMod (2 * n)) zAdd zZero zSmul A ∧ unordWeightedDavenport (α := Dicyclic n) qMul qOne qZPow A = ordWeightedDavenport (α := ZMod (2 * n)) zAdd zZero zSmul A := by rcases hdiv4 with ⟨w₀, hw₀A, hw₀4⟩ set D := ordWeightedDavenport (α := ZMod (2 * n)) zAdd zZero zSmul A have hD_mem := Nat.sInf_mem hne change 0 < D ∧ ∀ s : List (ZMod (2 * n)), s.length = D → HasOrdWeightedP1 zAdd zZero zSmul A s at hD_mem have hup_ord : ∀ s : List (Dicyclic n), s.length = D → HasOrdWeightedP1 qMul qOne qZPow A s := by intro s hs by_cases hnr : ∃ x ∈ s, x.2 = true · rcases hnr with ⟨⟨a, b⟩, hx, hb⟩; dsimp only at hb; subst hb exact hasOrd_single qMul_one hx hw₀A (qZPow_nonrot_mod4_0 a hw₀4) · push Not at hnr have hs_eq : s = (s.map Prod.fst).map (fun a => (a, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id s] apply List.map_congr_left intro x hx; rcases x with ⟨a, b⟩ exact Prod.ext rfl (Bool.eq_false_iff.mpr (hnr (a, b) hx)) obtain ⟨sub, ws, hsub, hne', hlen', hw, hprod⟩ := hD_mem.2 (s.map Prod.fst) (by rw [List.length_map, hs]) refine ⟨sub.map (fun a => (a, false)), ws, by rw [hs_eq]; exact hsub.map _, by simp [hne'], by simp [hlen'], hw, ?_⟩ have hzip : List.zipWith qZPow (sub.map (fun a => (a, false))) ws = (List.zipWith zSmul sub ws).map (fun a => (a, false)) := by clear hprod hw hne' hsub hs_eq hnr induction sub generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen' | cons w ws' => simp [qZPow_rot, zSmul, ih ws' (by simpa using hlen')] rw [hzip, listProd_qMul_rot]; rw [listProd_zAdd_eq_sum] at hprod; rw [hprod]; rfl have hrot_avoid : ∀ t : List (ZMod (2 * n)), ¬ HasOrdWeightedP1 zAdd zZero zSmul A t → ¬ HasUnordWeightedP1 qMul qOne qZPow A (t.map (fun a => (a, false))) := by intro t ht ⟨s', hp, sub, ws, hsub, hne', hlen', hw, hprod⟩ have hs'_rot : ∀ x ∈ s', x.2 = false := fun x hx => by rcases List.mem_map.mp (hp.mem_iff.mp hx) with ⟨a, _, rfl⟩; rfl have hsub_rot : ∀ x ∈ sub, x.2 = false := fun x hx => hs'_rot x (hsub.subset hx) have hsub_eq : sub = (sub.map Prod.fst).map (fun a => (a, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id sub] apply List.map_congr_left intro x hx; rcases x with ⟨a, b⟩; exact Prod.ext rfl (hsub_rot (a, b) hx) have hzip : List.zipWith qZPow sub ws = (List.zipWith zSmul (sub.map Prod.fst) ws).map (fun a => (a, false)) := by conv_lhs => rw [hsub_eq] have hlen'' : ws.length = (sub.map Prod.fst).length := by simp [hlen'] clear hprod hw hne' hsub hp hs'_rot hsub_rot hsub_eq hlen' generalize sub.map Prod.fst = u at hlen'' ⊢ induction u generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen'' | cons w ws' => simp [qZPow_rot, zSmul, ih ws' (by simpa using hlen'')] rw [hzip, listProd_qMul_rot] at hprod have hsum0 : (List.zipWith zSmul (sub.map Prod.fst) ws).sum = 0 := congrArg Prod.fst hprod have hp_fst : (s'.map Prod.fst).Perm t := by have := hp.map Prod.fst; rwa [List.map_map, Function.comp_def, List.map_id'] at this exact ht (hasUnord_iff_hasOrd_zMod.mp ⟨s'.map Prod.fst, hp_fst, sub.map Prod.fst, ws, hsub.map Prod.fst, by simp [hne'], by simp [hlen'], hw, by rw [listProd_zAdd_eq_sum]; exact hsum0⟩) have hle_ord := ordWeightedDavenport_le hD_mem.1 hup_ord have hle_un := unordWeightedDavenport_le_ord ⟨D, hD_mem.1, hup_ord⟩ have hge_un : D ≤ unordWeightedDavenport (α := Dicyclic n) qMul qOne qZPow A := by by_cases hD1 : D = 1 · rw [hD1] exact (Nat.sInf_mem (s := { d : ℕ | 0 < d ∧ ∀ s : List (Dicyclic n), s.length = d → HasUnordWeightedP1 qMul qOne qZPow A s }) ⟨D, hD_mem.1, fun s hs => hasUnord_of_hasOrd (hup_ord s hs)⟩).1 · have hDgt : 0 < D - 1 := by omega have hex : ∃ t : List (ZMod (2 * n)), t.length = D - 1 ∧ ¬ HasOrdWeightedP1 zAdd zZero zSmul A t := by by_contra hall; push Not at hall have := Nat.sInf_le (s := { d : ℕ | 0 < d ∧ ∀ s : List (ZMod (2 * n)), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul A s }) ⟨hDgt, hall⟩ change D ≤ D - 1 at this; omega rcases hex with ⟨t, htlen, htno⟩ have hlt := lt_unordWeightedDavenport ⟨D, hD_mem.1, fun s hs => hasUnord_of_hasOrd (hup_ord s hs)⟩ ⟨t.map (fun a => (a, false)), by rw [List.length_map, htlen], hrot_avoid t htno⟩ omega omega theorem dicyclic_weight_14_exact {m : ℕ} (hm : 1 ≤ m) : ordWeightedDavenport (α := Dicyclic (2 * m)) qMul qOne qZPow ({1, (4 : ℤ)} : Set ℤ) = m ∧ unordWeightedDavenport (α := Dicyclic (2 * m)) qMul qOne qZPow ({1, (4 : ℤ)} : Set ℤ) = m := by have heq : 2 * (2 * m) = 4 * m := by ring have hcyc : ordWeightedDavenport (α := ZMod (2 * (2 * m))) zAdd zZero zSmul ({1, (4 : ℤ)} : Set ℤ) = m := by rw [heq]; exact (cyclic_weighted_1c_exact (c := 4) (m := m) (by omega) hm).1 have hne : ∃ d, 0 < d ∧ ∀ s : List (ZMod (2 * (2 * m))), s.length = d → HasOrdWeightedP1 zAdd zZero zSmul ({1, (4 : ℤ)} : Set ℤ) s := by rw [heq] exact ⟨m, hm, fun s hs => hasOrd_mono_weights (fun w hw => Or.inr hw) (cyclic_weighted_c_upper (c := 4) (m := m) (by omega) hm s hs)⟩ have hdiv4 : ∃ w₀ ∈ ({1, (4 : ℤ)} : Set ℤ), w₀ % 4 = 0 := ⟨4, Or.inr rfl, rfl⟩ have hcoll := dicyclic_div4_collapse (n := 2 * m) hdiv4 hne exact ⟨hcoll.1.trans hcyc, hcoll.2.trans hcyc⟩ /-- **THEOREM 4b (Exact `{1, 2}`-Weighted Davenport Constant of ALL Dicyclic Groups `Dic_{4n}` — NEW!):** For EVERY `n ≥ 1`, BOTH ordered and unordered `{1, 2}`-weighted Davenport constants of `Dic_{4n}` satisfy: `D_ord({1, 2}, Dic_{4n}) = D_unord({1, 2}, Dic_{4n}) = max 2 n`! -/ theorem dicyclic_weight_12_exact {n : ℕ} (hn : 1 ≤ n) : ordWeightedDavenport (α := Dicyclic n) qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) = max 2 n ∧ unordWeightedDavenport (α := Dicyclic n) qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) = max 2 n := by -- Helper: ANY list in `Dic_{4n}` with ≥ 2 non-rotations has an ORDERED length-2 `{2}`-weighted product-one! have htwo_nonrot : ∀ s : List (Dicyclic n), 2 ≤ s.countP (fun x => x.2) → HasOrdWeightedP1 qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) s := by intro s hcnt -- Extract two non-rotations in order! have hex2 : ∀ l : List (Dicyclic n), 2 ≤ l.countP (fun x => x.2) → ∃ a b : ZMod (2 * n), ([(a, true), (b, true)] : List (Dicyclic n)).Sublist l := by intro l induction l with | nil => intro h; simp at h | cons x xs ih => intro h cases hx : x.2 with | false => rw [List.countP_cons, hx] at h; simp only [Bool.false_eq_true, ↓reduceIte, add_zero] at h obtain ⟨a, b, hsub⟩ := ih h exact ⟨a, b, hsub.trans (List.sublist_cons_self _ _)⟩ | true => rw [List.countP_cons, hx] at h; simp only [↓reduceIte] at h have hpos : 0 < xs.countP (fun y => y.2) := by omega obtain ⟨y, hy_mem, hy2⟩ := List.countP_pos_iff.mp hpos rcases x with ⟨a, _⟩; rcases y with ⟨b, _⟩; dsimp only at hx hy2; subst hx; subst hy2 exact ⟨a, b, List.Sublist.cons_cons _ (List.singleton_sublist.mpr hy_mem)⟩ obtain ⟨a, b, hsub⟩ := hex2 s hcnt refine ⟨[(a, true), (b, true)], [2, 2], hsub, List.cons_ne_nil _ _, rfl, by simp, ?_⟩ rw [List.zipWith_cons_cons, List.zipWith_cons_cons, List.zipWith_nil_left, qZPow_nonrot_mod4_2 a rfl, qZPow_nonrot_mod4_2 b rfl, listProd_cons, listProd_cons, listProd_nil, qMul_one, qMul_z_z] -- Case split `n = 1` vs `n ≥ 2`! by_cases hn1 : n = 1 · subst hn1 have hup : ∀ s : List (Dicyclic 1), s.length = 2 → HasOrdWeightedP1 qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) s := by intro s hs by_cases h2 : 2 ≤ s.countP (fun x => x.2) · exact htwo_nonrot s h2 · -- At least 1 rotation `x = (a, false)` in `ZMod 2`: `2 • a = 0`! have hex_rot : ∃ x ∈ s, x.2 = false := by by_contra hall; push Not at hall have hcnt : s.countP (fun x => x.2) = s.length := by rw [List.countP_eq_length]; intro x hx; exact Bool.eq_true_of_not_eq_false (hall x hx) omega rcases hex_rot with ⟨⟨a, b⟩, hx, hb⟩; dsimp only at hb; subst hb refine hasOrd_single qMul_one hx (Or.inr rfl) ?_ rw [qZPow_rot] have h0 : (2 : ℤ) • a = 0 := by rw [zsmul_eq_mul]; change ((2 * 1 : ℕ) : ZMod (2 * 1)) * a = 0 rw [ZMod.natCast_self, zero_mul] rw [h0]; rfl have hwit : ¬ HasUnordWeightedP1 qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) [((0 : ZMod (2 * 1)), true)] := by rintro ⟨s', hp, sub, ws, hsub, hne, hlen, hw, hprod⟩ have hs' : s' = [((0 : ZMod (2 * 1)), true)] := List.perm_singleton.mp hp subst hs' have hsub_eq : sub = [((0 : ZMod (2 * 1)), true)] := by cases hsub with | cons _ h0 => cases h0; exact absurd rfl hne | cons_cons _ h0 => cases h0; rfl subst hsub_eq rcases ws with _ | ⟨w, _ | _⟩ <;> try simp at hlen have hw' : w = 1 ∨ w = 2 := hw w (List.mem_cons_self ..) rcases hw' with rfl | rfl <;> simp [listProd, qZPow, qMul, qOne] at hprod have hmax : max 2 1 = 2 := rfl rw [hmax] exact ⟨ordWeightedDavenport_eq (by omega) hup (Or.inr ⟨[((0 : ZMod (2 * 1)), true)], rfl, fun h => hwit (hasUnord_of_hasOrd h)⟩), unordWeightedDavenport_eq (by omega) (fun s hs => hasUnord_of_hasOrd (hup s hs)) (Or.inr ⟨[((0 : ZMod (2 * 1)), true)], rfl, hwit⟩)⟩ · -- `n ≥ 2`: `max 2 n = n`! have hn2 : 2 ≤ n := by omega have hmax : max 2 n = n := Nat.max_eq_right hn2 rw [hmax] have hup : ∀ s : List (Dicyclic n), s.length = n → HasOrdWeightedP1 qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) s := by intro s hs by_cases h2 : 2 ≤ s.countP (fun x => x.2) · exact htwo_nonrot s h2 · by_cases h0 : s.countP (fun x => x.2) = 0 · -- Zero non-rotations: use `cyclic_weighted_c_upper` with `c = 2, m = n`! have hs_rot : ∀ x ∈ s, x.2 = false := fun x hx => by by_contra hne have hpos : 0 < s.countP (fun y => y.2) := List.countP_pos_iff.mpr ⟨x, hx, Bool.eq_true_of_not_eq_false hne⟩ omega have hs_eq : s = (s.map Prod.fst).map (fun a => (a, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id s] apply List.map_congr_left intro x hx; rcases x with ⟨a, b⟩; exact Prod.ext rfl (hs_rot (a, b) hx) obtain ⟨sub, ws, hsub, hne', hlen', hw, hprod⟩ := cyclic_weighted_c_upper (c := 2) (m := n) (by omega) hn (s.map Prod.fst) (by rw [List.length_map, hs]) refine ⟨sub.map (fun a => (a, false)), ws, by rw [hs_eq]; exact hsub.map _, by simp [hne'], by simp [hlen'], fun w hw' => Or.inr (hw w hw'), ?_⟩ have hzip : List.zipWith qZPow (sub.map (fun a => (a, false))) ws = (List.zipWith zSmul sub ws).map (fun a => (a, false)) := by clear hprod hw hne' hsub hs_eq hs_rot h0 h2 induction sub generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen' | cons w ws' => simp [qZPow_rot, zSmul, ih ws' (by simpa using hlen')] rw [hzip, listProd_qMul_rot]; rw [listProd_zAdd_eq_sum] at hprod; rw [hprod]; rfl · -- EXACTLY ONE non-rotation `g` in `s`: split `s = l₁ ++ [g] ++ l₂` where `l₁, l₂` are all rotations! have h1 : s.countP (fun x => x.2) = 1 := by omega have hsplit : ∃ (l₁ l₂ : List (ZMod (2 * n))) (a : ZMod (2 * n)), s = l₁.map (fun x => (x, false)) ++ [(a, true)] ++ l₂.map (fun x => (x, false)) := by clear h2 h0 hs induction s with | nil => simp at h1 | cons x xs ih => cases hx : x.2 with | false => rw [List.countP_cons, hx] at h1; simp only [Bool.false_eq_true, ↓reduceIte, add_zero] at h1 obtain ⟨l₁, l₂, a, heq⟩ := ih h1 rcases x with ⟨c, _⟩; dsimp only at hx; subst hx exact ⟨c :: l₁, l₂, a, by simp [heq]⟩ | true => rw [List.countP_cons, hx] at h1; simp only [↓reduceIte] at h1 have hxs0 : xs.countP (fun y => y.2) = 0 := by omega have hxs_eq : xs = (xs.map Prod.fst).map (fun y => (y, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id xs] apply List.map_congr_left intro y hy; rcases y with ⟨c, b⟩ have hb : b = false := by by_contra hb'; have : 0 < xs.countP (fun u => u.2) := List.countP_pos_iff.mpr ⟨(c, b), hy, Bool.eq_true_of_not_eq_false hb'⟩ omega exact Prod.ext rfl hb rcases x with ⟨a, _⟩; dsimp only at hx; subst hx exact ⟨[], xs.map Prod.fst, a, by simp [← hxs_eq]⟩ obtain ⟨l₁, l₂, a, hs_split⟩ := hsplit have hlen12 : (l₁ ++ l₂).length = n - 1 := by have := congrArg List.length hs_split simp only [hs, List.length_append, List.length_map, List.length_singleton] at this ⊢ omega -- Project `l₁ ++ l₂` from `ZMod (2 * n)` to `ZMod n` via `ZMod.castHom`! let φ : ZMod (2 * n) →+ ZMod n := ZMod.castHom (dvd_mul_left n 2) (ZMod n) have hφ_len : ((l₁ ++ l₂).map φ).length = n - 1 := by rw [List.length_map, hlen12] obtain ⟨sub_φ, ws, hsub_φ, hne_φ, hlen_φ, hw_φ, hprod_φ⟩ := cyclic_weighted_12_le_pred hn2 ((l₁ ++ l₂).map φ) hφ_len obtain ⟨sub, hsub_12, hsub_map⟩ := List.sublist_map_iff.mp hsub_φ have hlen_ws : ws.length = sub.length := by rw [hlen_φ, hsub_map, List.length_map] have hne_sub : sub ≠ [] := fun h => hne_φ (by rw [hsub_map, h]; rfl) -- Compute the sum `S := (List.zipWith zSmul sub ws).sum` in `ZMod (2 * n)`: `φ S = 0`, so `S = 0 ∨ S = n`! have hφ_sum : φ (List.zipWith zSmul sub ws).sum = 0 := by have h1 : φ (List.zipWith zSmul sub ws).sum = (List.zipWith zSmul sub_φ ws).sum := by rw [hsub_map] clear hprod_φ hsub_map hsub_12 hsub_φ hne_φ hne_sub hw_φ hlen_φ induction sub generalizing ws with | nil => cases ws <;> simp | cons x xs ih => cases ws with | nil => simp at hlen_ws | cons w ws' => simp only [List.map_cons, List.zipWith_cons_cons, List.sum_cons, map_add, zSmul, map_zsmul] congr 1; exact ih ws' (by simpa using hlen_ws) rw [h1]; rw [listProd_zAdd_eq_sum] at hprod_φ; exact hprod_φ have hS_cases : (List.zipWith zSmul sub ws).sum = 0 ∨ (List.zipWith zSmul sub ws).sum = (n : ZMod (2 * n)) := by set S := (List.zipWith zSmul sub ws).sum have : NeZero (2 * n) := ⟨by omega⟩ have : NeZero n := ⟨by omega⟩ have hval_lt : S.val < 2 * n := ZMod.val_lt S have hφ_val : (S.val : ZMod n) = 0 := by have hcast : φ ((S.val : ℕ) : ZMod (2 * n)) = (S.val : ZMod n) := by simp [φ] rw [ZMod.natCast_zmod_val] at hcast rw [← hcast, hφ_sum] have hdvd : n ∣ S.val := (ZMod.natCast_eq_zero_iff S.val n).mp hφ_val rcases hdvd with ⟨q, hq⟩ have hq01 : q = 0 ∨ q = 1 := by have : n * q < n * 2 := by rw [← hq]; omega have := Nat.lt_of_mul_lt_mul_left this; omega rcases hq01 with rfl | rfl · left; rw [← ZMod.natCast_zmod_val S, hq]; simp · right; rw [← ZMod.natCast_zmod_val S, hq]; simp -- Split `sub` and `ws` along `l₁ ++ l₂` into `sub₁, sub₂` and `ws₁, ws₂`! obtain ⟨sub₁, sub₂, hsub_eq, hsub₁, hsub₂⟩ := List.sublist_append_iff.mp hsub_12 let ws₁ := ws.take sub₁.length let ws₂ := ws.drop sub₁.length have hws_eq : ws = ws₁ ++ ws₂ := (List.take_append_drop _ _).symm have hlen_ws₁ : ws₁.length = sub₁.length := by rw [List.length_take, hlen_ws, hsub_eq, List.length_append]; omega have hlen_ws₂ : ws₂.length = sub₂.length := by rw [List.length_drop, hlen_ws, hsub_eq, List.length_append]; omega have hzip_rot : ∀ (u : List (ZMod (2 * n))) (v : List ℤ), v.length = u.length → List.zipWith qZPow (u.map (fun x => (x, false))) v = (List.zipWith zSmul u v).map (fun x => (x, false)) := by intro u; induction u with | nil => intro v hv; cases v <;> simp_all | cons x xs ih => intro v hv; cases v with | nil => simp at hv | cons w vs => simp [qZPow_rot, zSmul, ih vs (by simpa using hv)] rcases hS_cases with hS0 | hSn · -- `S = 0`: don't even need the non-rotation! have hsub_s : (sub.map (fun x => (x, false))).Sublist s := by rw [hs_split, hsub_eq, List.map_append] exact ((hsub₁.map _).trans (List.sublist_append_left _ _)).append (hsub₂.map _) refine ⟨sub.map (fun x => (x, false)), ws, hsub_s, by simp [hne_sub], by simp [hlen_ws], hw_φ, ?_⟩ rw [hzip_rot sub ws hlen_ws, listProd_qMul_rot, hS0]; rfl · -- `S = n`: insert `(a, true)` with weight `2` (giving the CENTRAL involution `qZ = (n, false)`) right between `sub₁` and `sub₂`! let fullSub := sub₁.map (fun x => (x, false)) ++ [(a, true)] ++ sub₂.map (fun x => (x, false)) let fullWs := ws₁ ++ [(2 : ℤ)] ++ ws₂ have hsub_s : fullSub.Sublist s := by rw [hs_split] exact ((hsub₁.map _).append (List.Sublist.refl _)).append (hsub₂.map _) have hlen_full : fullWs.length = fullSub.length := by simp [fullWs, fullSub, hlen_ws₁, hlen_ws₂] have hw_full : ∀ w ∈ fullWs, w ∈ ({1, (2 : ℤ)} : Set ℤ) := by intro w hw simp only [fullWs, List.mem_append, List.mem_singleton] at hw rcases hw with (h | rfl) | h · exact hw_φ w (List.mem_of_mem_take h) · right; rfl · exact hw_φ w (List.mem_of_mem_drop h) have hzip_full : List.zipWith qZPow fullSub fullWs = (List.zipWith zSmul sub₁ ws₁).map (fun x => (x, false)) ++ [qZ] ++ (List.zipWith zSmul sub₂ ws₂).map (fun x => (x, false)) := by dsimp only [fullSub, fullWs] rw [List.zipWith_append (by simp [hlen_ws₁]), List.zipWith_append (by simp [hlen_ws₁])] rw [hzip_rot sub₁ ws₁ hlen_ws₁, hzip_rot sub₂ ws₂ hlen_ws₂] simp [qZPow_nonrot_mod4_2] refine ⟨fullSub, fullWs, hsub_s, by simp [fullSub], hlen_full, hw_full, ?_⟩ rw [hzip_full, listProd_append qMul_assoc qOne_mul, listProd_append qMul_assoc qOne_mul, listProd_qMul_rot, listProd_qMul_rot] simp only [listProd_cons, listProd_nil, qMul_one] rw [qMul_assoc, qMul_z_left] simp only [qMul, Bool.false_eq_true, ↓reduceIte, Bool.xor_false, qOne, Prod.mk.injEq, and_true] have hS_split : (List.zipWith zSmul sub₁ ws₁).sum + (List.zipWith zSmul sub₂ ws₂).sum = (n : ZMod (2 * n)) := by rw [← List.sum_append, ← List.zipWith_append hlen_ws₁.symm, ← hsub_eq, ← hws_eq] exact hSn calc (List.zipWith zSmul sub₁ ws₁).sum + ((List.zipWith zSmul sub₂ ws₂).sum + (n : ZMod (2 * n))) = ((List.zipWith zSmul sub₁ ws₁).sum + (List.zipWith zSmul sub₂ ws₂).sum) + (n : ZMod (2 * n)) := by ring _ = (n : ZMod (2 * n)) + (n : ZMod (2 * n)) := by rw [hS_split] _ = 0 := qN_add_qN -- Lower bound: `n - 1` copies of rotation `(1, false)` in `Dic_{4n}`! have hwit : ¬ HasUnordWeightedP1 qMul qOne qZPow ({1, (2 : ℤ)} : Set ℤ) ((List.replicate (n - 1) (1 : ZMod (2 * n))).map (fun a => (a, false))) := by intro hun have hlow_cyc := cyclic_weighted_Icc_lower (c := 2) (m := n) (by omega) hn rcases hun with ⟨s', hp, sub, ws, hsub, hne', hlen', hw, hprod⟩ have hs'_rot : ∀ x ∈ s', x.2 = false := fun x hx => by rcases List.mem_map.mp (hp.mem_iff.mp hx) with ⟨a, _, rfl⟩; rfl have hsub_rot : ∀ x ∈ sub, x.2 = false := fun x hx => hs'_rot x (hsub.subset hx) have hsub_eq : sub = (sub.map Prod.fst).map (fun a => (a, false)) := by rw [List.map_map]; conv_lhs => rw [← List.map_id sub] apply List.map_congr_left intro x hx; rcases x with ⟨a, b⟩; exact Prod.ext rfl (hsub_rot (a, b) hx) have hzip : List.zipWith qZPow sub ws = (List.zipWith zSmul (sub.map Prod.fst) ws).map (fun a => (a, false)) := by conv_lhs => rw [hsub_eq] have hlen'' : ws.length = (sub.map Prod.fst).length := by simp [hlen'] clear hprod hw hne' hsub hp hs'_rot hsub_rot hsub_eq hlen' generalize sub.map Prod.fst = u at hlen'' ⊢ induction u generalizing ws with | nil => cases ws <;> rfl | cons a l ih => cases ws with | nil => simp at hlen'' | cons w ws' => simp [qZPow_rot, zSmul, ih ws' (by simpa using hlen'')] rw [hzip, listProd_qMul_rot] at hprod have hsum0 : (List.zipWith zSmul (sub.map Prod.fst) ws).sum = 0 := congrArg Prod.fst hprod have hp_fst : (s'.map Prod.fst).Perm (List.replicate (n - 1) (1 : ZMod (2 * n))) := by have := hp.map Prod.fst; rwa [List.map_map, Function.comp_def, List.map_id'] at this have hun_z : HasUnordWeightedP1 zAdd zZero zSmul (Set.Icc (1 : ℤ) 2) (List.replicate (n - 1) (1 : ZMod (2 * n))) := ⟨s'.map Prod.fst, hp_fst, sub.map Prod.fst, ws, hsub.map Prod.fst, by simp [hne'], by simp [hlen'], fun w hw' => by rcases hw w hw' with rfl | rfl <;> exact ⟨by omega, by omega⟩, by rw [listProd_zAdd_eq_sum]; exact hsum0⟩ exact hlow_cyc (hasUnord_iff_hasOrd_zMod.mp hun_z) exact ⟨ordWeightedDavenport_eq hn hup (Or.inr ⟨_, by simp, fun h => hwit (hasUnord_of_hasOrd h)⟩), unordWeightedDavenport_eq hn (fun s hs => hasUnord_of_hasOrd (hup s hs)) (Or.inr ⟨_, by simp, hwit⟩)⟩ /-! ### 8. Axiom Audit for All Headline Theorems -/ #print axioms cyclic_weighted_c_upper #print axioms cyclic_weighted_1c_exact #print axioms cyclic_weighted_12_le_pred #print axioms dihedral_ord_davenport_upper #print axioms dihedral_unweighted_exact #print axioms dihedral_ord_odd_weights_exact #print axioms dihedral_even_weight_collapse #print axioms dihedral_even_and_interval_exact #print axioms dihedral_unord_reflections_binom_bound #print axioms dihedral_unord_odd_c_upper #print axioms dihedral_binary_reflection_witness #print axioms dihedral_exponential_ord_unord_separation #print axioms dihedral_D8_strict_separation #print axioms dicyclic_div4_collapse #print axioms dicyclic_weight_14_exact #print axioms dicyclic_weight_12_exact end NonAbelianWeightedZeroSum