/-Copyright (c) 2026 Carles Marín. All rights reserved.Released under Apache 2.0 license as described in the file LICENSE.Authors: Carles Marín-/module public import Formalizations.NumberTheory.NumericalSemigroup.GenusBound /-!# The `i`-th gap is at most `2i − 1`, and the tail `δ ≥ 2` For a submonoid `S = ⟨A⟩ ⊆ ℕ` and a gap `g ∉ S`, the map `s ↦ g − s` injects the elements of `S`in `[0, g]` into the gaps in `[0, g]`. Hence if `g` is the `i`-th gap (`i` gaps in `[0, g]`), then`g + 1 ≤ 2i`, i.e. `g_i ≤ 2i − 1`; in particular every gap is at most `2δ − 1`, `δ` the genus. The second part is Corollary `cor:delta2` of the paper, from the generating rule alone: if`S_T = ⟨e, {j < e | M_j ≠ 0}⟩` with `M_1 = 0` (the spectrum is centred) and `e ≥ 4`, then`δ ≥ 2 ↔ M_2 M_3 = 0`. The moments are abstracted to a predicate `V j` ("`M_j` vanishes");the generating rule itself (Part I of the paper) enters as the definition of `genSet`. ## Main results * `P3b.two_mul_card_gaps_ge`: `g ∉ ⟨A⟩ → g + 1 ≤ 2 · #{x ≤ g | x ∉ ⟨A⟩}`.* `P3b.gap_le_two_mul_index_sub_one`: `g_i ≤ 2i − 1` with `i = #{x ≤ g | x ∉ ⟨A⟩}`.* `P3b.gap_le_two_mul_genus_sub_one`: every gap is `≤ 2δ − 1` when the gaps are finite.* `P3b.two_le_genus_iff`: `cor:delta2`, `2 ≤ δ ↔ V 2 ∨ V 3`. ## References * C. Marín, *The order generated by a column of the SU(n)_k S-matrix is locally a numerical semigroup ring (Part II)*, Zenodo (2026), doi:10.5281/zenodo.22864267, §6 (the bound on `g_i`) and Corollary `cor:delta2`.-/ @[expose] public section open Finset P3a namespace P3b /-! ## The bound `g_i ≤ 2i − 1` -/ open Classical in/-- `s ↦ g − s` injects the semigroup elements of `[0, g]` into the gaps of `[0, g]`. -/theorem card_mem_le_card_gaps (A : Set ℕ) {g : ℕ} (hg : g ∉ AddSubmonoid.closure A) : #{x ∈ range (g + 1) | x ∈ AddSubmonoid.closure A} ≤ #{x ∈ range (g + 1) | x ∉ AddSubmonoid.closure A} := by refine card_le_card_of_injOn (fun s => g - s) ?_ ?_ · intro s hs obtain ⟨hs1, hs2⟩ := mem_filter.mp hs rw [mem_range] at hs1 refine mem_filter.mpr ⟨mem_range.mpr (show g - s < g + 1 by omega), fun h => hg ?_⟩ have := add_mem hs2 h rwa [show s + (g - s) = g by omega] at this · intro s hs t ht h have hs1 := mem_range.mp (mem_filter.mp hs).1 have ht1 := mem_range.mp (mem_filter.mp ht).1 simp only at h omega open Classical in/-- If `g` is a gap, then `g + 1 ≤ 2 · #{x ≤ g | x is a gap}`. -/theorem two_mul_card_gaps_ge (A : Set ℕ) {g : ℕ} (hg : g ∉ AddSubmonoid.closure A) : g + 1 ≤ 2 * #{x ∈ range (g + 1) | x ∉ AddSubmonoid.closure A} := by have h1 := card_mem_le_card_gaps A hg have h2 := card_filter_add_card_filter_not (s := range (g + 1)) (fun x => x ∈ AddSubmonoid.closure A) rw [card_range] at h2 omega open Classical in/-- **`g_i ≤ 2i − 1`**: if `g` is the `i`-th gap, i.e. there are exactly `i` gaps in `[0, g]`,then `g ≤ 2i − 1`. -/theorem gap_le_two_mul_index_sub_one (A : Set ℕ) {g i : ℕ} (hg : g ∉ AddSubmonoid.closure A) (hi : #{x ∈ range (g + 1) | x ∉ AddSubmonoid.closure A} = i) : g ≤ 2 * i - 1 := by have := two_mul_card_gaps_ge A hg omega /-- With finitely many gaps, every gap is at most `2δ − 1`, `δ` the genus. -/theorem gap_le_two_mul_genus_sub_one (A : Set ℕ) (hfin : (gaps A).Finite) {g : ℕ} (hg : g ∉ AddSubmonoid.closure A) : g ≤ 2 * genus A - 1 := by classical have h := two_mul_card_gaps_ge A hg have hsub : (({x ∈ range (g + 1) | x ∉ AddSubmonoid.closure A} : Finset ℕ) : Set ℕ) ⊆ gaps A := by intro x hx exact (mem_filter.mp hx).2 have hle := Set.ncard_le_ncard hsub hfin rw [Set.ncard_coe_finset] at hle unfold genus omega /-! ## Corollary `cor:delta2` -/ /-- The generating rule of Part I at `h = 1`: `S_T` is generated by `e` and the `0 < j < e` with`M_j ≠ 0`; here `V j` stands for "`M_j = 0`". -/def genSet (e : ℕ) (V : ℕ → Prop) : Set ℕ := insert e {j | 0 < j ∧ j < e ∧ ¬ V j} /-- A closure is contained in any additively closed predicate holding at `0` and on `A`. -/theorem closure_sub_of {A : Set ℕ} (P : ℕ → Prop) (h0 : P 0) (hadd : ∀ x y, P x → P y → P (x + y)) (hA : ∀ a ∈ A, P a) {x : ℕ} (hx : x ∈ AddSubmonoid.closure A) : P x := by induction hx using AddSubmonoid.closure_induction with | mem a ha => exact hA a ha | zero => exact h0 | add x y _ _ hx hy => exact hadd x y hx hy /-- If `2, 3 ∈ ⟨A⟩` then every `x ≠ 1` lies in `⟨A⟩`. -/theorem mem_of_two_three {A : Set ℕ} (h2 : 2 ∈ AddSubmonoid.closure A) (h3 : 3 ∈ AddSubmonoid.closure A) : ∀ x, x ≠ 1 → x ∈ AddSubmonoid.closure A := by intro x induction x using Nat.strong_induction_on with | _ x ih => intro hx rcases (by omega : x = 0 ∨ x = 2 ∨ x = 3 ∨ 4 ≤ x) with h | h | h | h · exact h ▸ zero_mem _ · exact h ▸ h2 · exact h ▸ h3 · have := add_mem (ih (x - 2) (by omega) (by omega)) h2 rwa [show x - 2 + 2 = x by omega] at this /-- **Corollary `cor:delta2`**: for `h = 1` (generating rule `genSet e V`), a centred spectrum(`V 1`, i.e. `M_1 = 0`) and `e ≥ 4`, with finitely many gaps, `δ ≥ 2 ↔ M_2 M_3 = 0`. -/theorem two_le_genus_iff {e : ℕ} {V : ℕ → Prop} (he : 4 ≤ e) (hV1 : V 1) (hfin : (gaps (genSet e V)).Finite) : 2 ≤ genus (genSet e V) ↔ V 2 ∨ V 3 := by have h1 : (1 : ℕ) ∉ AddSubmonoid.closure (genSet e V) := fun h => closure_sub_of (fun x => x ≠ 1) (by omega) (fun x y hx hy => by omega) (fun a ha => by rcases ha with rfl | ⟨_, _, ha⟩ · omega · rintro rfl; exact ha hV1) h rfl constructor · intro hg by_contra hV push Not at hV have hmem : ∀ x, x ≠ 1 → x ∈ AddSubmonoid.closure (genSet e V) := mem_of_two_three (AddSubmonoid.subset_closure (Or.inr ⟨by omega, by omega, hV.1⟩)) (AddSubmonoid.subset_closure (Or.inr ⟨by omega, by omega, hV.2⟩)) have hgaps : gaps (genSet e V) = {1} := by ext x simp only [gaps, Set.mem_ofPred_eq, Set.mem_singleton_iff] exact ⟨fun hx => by by_contra h; exact hx (hmem x h), fun hx => hx ▸ h1⟩ rw [genus, hgaps, Set.ncard_singleton] at hg omega · intro hV have hk : ∃ k, (k = 2 ∨ k = 3) ∧ k ∉ AddSubmonoid.closure (genSet e V) := by rcases hV with hV | hV · refine ⟨2, Or.inl rfl, fun h => ?_⟩ exact closure_sub_of (fun x => x = 0 ∨ 3 ≤ x) (Or.inl rfl) (fun x y hx hy => by omega) (fun a ha => by rcases ha with rfl | ⟨ha0, _, ha⟩ · omega · rcases (by omega : a = 1 ∨ a = 2 ∨ 3 ≤ a) with rfl | rfl | h · exact absurd hV1 ha · exact absurd hV ha · exact Or.inr h) h |>.elim (by omega) (by omega) · refine ⟨3, Or.inr rfl, fun h => ?_⟩ exact closure_sub_of (fun x => x ≠ 1 ∧ x ≠ 3) ⟨by omega, by omega⟩ (fun x y hx hy => by omega) (fun a ha => by rcases ha with rfl | ⟨ha0, _, ha⟩ · omega · refine ⟨fun h => ?_, fun h => ?_⟩ · exact ha (h ▸ hV1) · exact ha (h ▸ hV)) h |>.2 rfl obtain ⟨k, hk, hk'⟩ := hk have hsub : ({1, k} : Set ℕ) ⊆ gaps (genSet e V) := by intro x hx rcases hx with rfl | rfl · exact h1 · exact hk' have := Set.ncard_le_ncard hsub hfin rw [Set.ncard_pair (by omega)] at this exact this end P3b