/-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, Claude (AI assistant)-/module public import Formalizations.Combinatorics.Caballero.AngularGeneralApublic import Mathlib.Algebra.Order.Floor.Ringpublic import Mathlib.Algebra.BigOperators.Ring.Finsetpublic import Mathlib.Order.Interval.Finset.Nat /-!# One marker in the local block of the divisor Dyck word (Caballero, Part IV) Lemma 12 of Part IV. For a central point (Lambda, theta) off the lines (4a+5 <= J <= b - C_a, J =floor Lambda) with 0 < theta <= 1/a and cell vector c, put delta_i = c_{a-i} - c_{-i-1} for i < aand delta_a = m - sum_{i<a} delta_i, m = a+1 (the numbers of Lemma 11). If c is not of the formO_1(s), that is c_h = floor((s+h)/m) for no integer s, then exactly one of delta_0, ..., delta_a isat least 2. The proof is direct and does not go through the arcs of R/Z, the three distance theoremor the perturbation of theta at theta = 1/a: for i < a, delta_i >= 2 forces c_{a-i} = J+1 andc_{-i-1} = J-1, which is equivalent to Lambda - J < (i+1) theta and Lambda - J + (a-i) theta >= 1;two such indices are incompatible with a theta <= 1, and the pair (i, a) is excluded because delta_l>= 1 for every l < a as soon as one delta_i >= 2 (the window has length (a+1) theta > 1), whichforces delta_a <= 0. If no delta_i is at least 2, all delta_i equal 1, and a floor form is builtfrom c (monotone, with c_{h+m} = c_h + 1 for -a <= h <= -1) by taking s = max_h (m c_h - h). Thestatement is for a >= 2 and any b (the paper fixes a >= 2, b >= 1; centrality forces b to be large);Lemma 11 is not used, the case delta_i = 1 for all i implies the floor form is reproved here. ## Main results * `CaballeroMarker.exactly_one_marker`: Lemma 12: at a central point with 0 < theta <= 1/a, if c is not of the form O_1(s) then exactly one delta_i (0 <= i <= a) is at least 2* `CaballeroMarker.isO1_of_periodic`: if c is monotone, c_{h+m} = c_h + 1 for -a <= h <= -1, then c = O_1(s) for some integer s ## References * C. Marín, How Many Dyck Words Do the Divisors of an Integer Make? IV. The Primary Phase of the Ambiguity Profile for General a, draft (2 December 2026), unpublished.* C. Marín, How Many Dyck Words Do the Divisors of an Integer Make? Exact Counts and Quasipolynomial Growth (Part I), Zenodo (2026), doi:10.5281/zenodo.24536372 (concept DOI).-/ @[expose] public section namespace CaballeroMarker open Finset CaballeroGeneralA /-- `δ_i = c_{a-i} - c_{-i-1}` for `0 ≤ i < a` and `δ_a = m - Σ_{i<a} δ_i`, `m = a + 1`. -/def markerDelta (a : ℕ) (c : Vec a) (i : ℕ) : ℤ := if i < a then coord c ((a : ℤ) - i) - coord c (-(i : ℤ) - 1) else ((a : ℤ) + 1) - ∑ l ∈ range a, (coord c ((a : ℤ) - l) - coord c (-(l : ℤ) - 1)) /-- `c` is of the form `O₁(s)`: `c_h = ⌊(s+h)/m⌋` for `-a ≤ h ≤ a` and some integer `s`,`m = a + 1`. -/def IsO1 (a : ℕ) (c : Vec a) : Prop := ∃ s : ℤ, ∀ h : ℤ, -(a : ℤ) ≤ h → h ≤ a → coord c h = ⌊((s + h : ℤ) : ℝ) / ((a + 1 : ℕ) : ℝ)⌋ theorem markerDelta_of_lt {a : ℕ} (c : Vec a) {i : ℕ} (hi : i < a) : markerDelta a c i = coord c ((a : ℤ) - i) - coord c (-(i : ℤ) - 1) := by simp [markerDelta, hi] theorem markerDelta_self {a : ℕ} (c : Vec a) : markerDelta a c a = ((a : ℤ) + 1) - ∑ l ∈ range a, markerDelta a c l := by conv_lhs => rw [markerDelta]; simp only [lt_self_iff_false, ↓reduceIte] congr 1 refine sum_congr rfl fun l hl => ?_ rw [markerDelta_of_lt c (mem_range.1 hl)] /-! ### A monotone vector with `g(h + m) = g(h) + 1` is of the form `O₁(s)` -/ /-- The cross inequality `m g(h') - h' < m g(h) - h + m` for a monotone `g` on `[-a, a]` with`g(h + m) = g(h) + 1` for `-a ≤ h ≤ -1`. -/theorem cross_ineq (a : ℕ) (ha : 1 ≤ a) (g : ℤ → ℤ) (hmono : ∀ h h' : ℤ, -(a : ℤ) ≤ h → h ≤ h' → h' ≤ a → g h ≤ g h') (hper : ∀ h : ℤ, -(a : ℤ) ≤ h → h ≤ -1 → g (h + ((a : ℤ) + 1)) = g h + 1) (h h' : ℤ) (h1 : -(a : ℤ) ≤ h) (h2 : h ≤ a) (h3 : -(a : ℤ) ≤ h') (h4 : h' ≤ a) : ((a : ℤ) + 1) * g h' - h' < ((a : ℤ) + 1) * g h - h + ((a : ℤ) + 1) := by have hm : (0 : ℤ) ≤ (a : ℤ) + 1 := by omega have ha1 : (1 : ℤ) ≤ a := by exact_mod_cast ha have e1 : g 1 = g (-(a : ℤ)) + 1 := by have := hper (-(a : ℤ)) (by omega) (by omega) rwa [show -(a : ℤ) + ((a : ℤ) + 1) = 1 by ring] at this have e2 : g (a : ℤ) = g (-1) + 1 := by have := hper (-1) (by omega) (by omega) rwa [show (-1 : ℤ) + ((a : ℤ) + 1) = a by ring] at this have hA : ∀ x y : ℤ, -(a : ℤ) ≤ x → x ≤ a → -(a : ℤ) ≤ y → y ≤ a → g y ≤ g x + 2 := by intro x y hx1 hx2 hy1 hy2 have m1 := hmono y a hy1 hy2 (le_refl _) have m2 := hmono (-1) 0 (by omega) (by omega) (by omega) have m3 := hmono 0 1 (by omega) (by omega) (by omega) have m4 := hmono (-(a : ℤ)) x (le_refl _) hx1 hx2 omega have hB : ∀ x y : ℤ, -(a : ℤ) ≤ x → x ≤ a → -(a : ℤ) ≤ y → y ≤ a → y + ((a : ℤ) + 1) ≤ x → g y + 1 ≤ g x := by intro x y hx1 hx2 hy1 hy2 hxy have p := hper (x - ((a : ℤ) + 1)) (by omega) (by omega) rw [show x - ((a : ℤ) + 1) + ((a : ℤ) + 1) = x by ring] at p have q := hmono y (x - ((a : ℤ) + 1)) hy1 (by omega) (by omega) omega have hC : ∀ x y : ℤ, -(a : ℤ) ≤ x → x ≤ a → -(a : ℤ) ≤ y → y ≤ a → y ≤ x + ((a : ℤ) + 1) → g y ≤ g x + 1 := by intro x y hx1 hx2 hy1 hy2 hxy by_cases hyx : y ≤ x · have q := hmono y x hy1 hyx hx2 omega · push Not at hyx by_cases hx : x ≤ -1 · have p := hper x hx1 hx have q := hmono y (x + ((a : ℤ) + 1)) hy1 (by omega) (by omega) omega · have p := hper (y - ((a : ℤ) + 1)) (by omega) (by omega) rw [show y - ((a : ℤ) + 1) + ((a : ℤ) + 1) = y by ring] at p have q := hmono (y - ((a : ℤ) + 1)) x (by omega) (by omega) hx2 omega by_cases hn0 : g h' ≤ g h · by_cases hd : h' - h ≤ -((a : ℤ) + 1) · have hb := hB h h' h1 h2 h3 h4 (by omega) have : ((a : ℤ) + 1) * g h' ≤ ((a : ℤ) + 1) * (g h - 1) := mul_le_mul_of_nonneg_left (by omega) hm nlinarith · have : ((a : ℤ) + 1) * g h' ≤ ((a : ℤ) + 1) * g h := mul_le_mul_of_nonneg_left hn0 hm nlinarith · push Not at hn0 have hup := hA h h' h1 h2 h3 h4 have hlt : h < h' := by by_contra hcon push Not at hcon have := hmono h' h h3 hcon h2 omega rcases (by omega : g h' = g h + 1 ∨ g h' = g h + 2) with e | e · rw [e] nlinarith · have hd : (a : ℤ) + 1 < h' - h := by by_contra hcon push Not at hcon have := hC h h' h1 h2 h3 h4 (by omega) omega rw [e] nlinarith /-- A monotone vector with `c_{h+m} = c_h + 1` for `-a ≤ h ≤ -1` is of the form `O₁(s)`. -/theorem isO1_of_periodic (a : ℕ) (ha : 1 ≤ a) (c : Vec a) (hmono : ∀ h h' : ℤ, -(a : ℤ) ≤ h → h ≤ h' → h' ≤ a → coord c h ≤ coord c h') (hper : ∀ h : ℤ, -(a : ℤ) ≤ h → h ≤ -1 → coord c (h + ((a : ℤ) + 1)) = coord c h + 1) : IsO1 a c := by obtain ⟨h0, hh0, hmax⟩ := Finset.exists_max_image (Icc (-(a : ℤ)) a) (fun h => ((a : ℤ) + 1) * coord c h - h) ⟨0, Finset.mem_Icc.2 ⟨by omega, by omega⟩⟩ rw [Finset.mem_Icc] at hh0 refine ⟨((a : ℤ) + 1) * coord c h0 - h0, fun h h1 h2 => ?_⟩ have k1 := hmax h (Finset.mem_Icc.2 ⟨h1, h2⟩) have k2 := cross_ineq a ha (coord c) hmono hper h h0 h1 h2 hh0.1 hh0.2 have hmz : (((a + 1 : ℕ) : ℤ)) = (a : ℤ) + 1 := by push_cast; ring have i1 : coord c h * ((a + 1 : ℕ) : ℤ) ≤ ((a : ℤ) + 1) * coord c h0 - h0 + h := by rw [hmz]; nlinarith have i2 : ((a : ℤ) + 1) * coord c h0 - h0 + h < (coord c h + 1) * ((a + 1 : ℕ) : ℤ) := by rw [hmz]; nlinarith have hpos : (0 : ℝ) < ((a + 1 : ℕ) : ℝ) := by positivity symm rw [Int.floor_eq_iff] constructor · rw [le_div_iff₀ hpos] exact_mod_cast i1 · rw [div_lt_iff₀ hpos] exact_mod_cast i2 /-! ### Floors at a central point -/ theorem aθ_le {a : ℕ} {θ : ℝ} (ha : 1 ≤ a) (hθ : θ ≤ 1 / (a : ℝ)) : (a : ℝ) * θ ≤ 1 := by have hapos : (0 : ℝ) < a := by exact_mod_cast ha calc (a : ℝ) * θ ≤ a * (1 / a) := mul_le_mul_of_nonneg_left hθ hapos.le _ = 1 := mul_one_div_cancel hapos.ne' theorem floor_add_mul_bounds (Λ θ : ℝ) (a : ℕ) (hθ0 : 0 < θ) (haθ : (a : ℝ) * θ ≤ 1) (h : ℤ) (h1 : -(a : ℤ) ≤ h) (h2 : h ≤ a) : ⌊Λ⌋ - 1 ≤ ⌊Λ + (h : ℝ) * θ⌋ ∧ ⌊Λ + (h : ℝ) * θ⌋ ≤ ⌊Λ⌋ + 1 := by have hh1 : (-(a : ℝ)) ≤ h := by exact_mod_cast h1 have hh2 : (h : ℝ) ≤ a := by exact_mod_cast h2 have p1 : (h : ℝ) * θ ≤ a * θ := mul_le_mul_of_nonneg_right hh2 hθ0.le have p2 : (-(a : ℝ)) * θ ≤ h * θ := mul_le_mul_of_nonneg_right hh1 hθ0.le have f1 := Int.floor_le Λ have f2 := Int.lt_floor_add_one Λ constructor · rw [Int.le_floor] push_cast linarith · have : ⌊Λ + (h : ℝ) * θ⌋ < ⌊Λ⌋ + 2 := by rw [Int.floor_lt] push_cast linarith omega theorem coord_eq_floor (a b : ℕ) (Λ θ : ℝ) (hθ0 : 0 < θ) (haθ : (a : ℝ) * θ ≤ 1) (hc : IsCentral a b Λ) (h : ℤ) (h1 : -(a : ℤ) ≤ h) (h2 : h ≤ a) : coord (cellVec a b Λ θ) h = ⌊Λ + (h : ℝ) * θ⌋ := by rw [coord_cellVec a b Λ θ h h1 h2] obtain ⟨hJ1, hJ2⟩ := hc obtain ⟨hb1, hb2⟩ := floor_add_mul_bounds Λ θ a hθ0 haθ h h1 h2 have hCa : 0 < Ca a := by unfold Ca; positivity unfold CaballeroPeaks.clip omega theorem marker_conditions (a b : ℕ) (Λ θ : ℝ) (hθ0 : 0 < θ) (haθ : (a : ℝ) * θ ≤ 1) (hc : IsCentral a b Λ) (i : ℕ) (hi : i < a) (hd : 2 ≤ coord (cellVec a b Λ θ) ((a : ℤ) - i) - coord (cellVec a b Λ θ) (-(i : ℤ) - 1)) : (⌊Λ⌋ : ℝ) + 1 ≤ Λ + ((a : ℝ) - i) * θ ∧ Λ - ((i : ℝ) + 1) * θ < ⌊Λ⌋ := by rw [coord_eq_floor a b Λ θ hθ0 haθ hc _ (by omega) (by omega), coord_eq_floor a b Λ θ hθ0 haθ hc _ (by omega) (by omega)] at hd have b1 := (floor_add_mul_bounds Λ θ a hθ0 haθ ((a : ℤ) - i) (by omega) (by omega)).2 have b2 := (floor_add_mul_bounds Λ θ a hθ0 haθ (-(i : ℤ) - 1) (by omega) (by omega)).1 constructor · have := Int.le_floor.mp (show ⌊Λ⌋ + 1 ≤ ⌊Λ + (((a : ℤ) - i : ℤ) : ℝ) * θ⌋ by omega) push_cast at this linarith · have := Int.floor_lt.mp (show ⌊Λ + ((-(i : ℤ) - 1 : ℤ) : ℝ) * θ⌋ < ⌊Λ⌋ by omega) push_cast at this linarith theorem delta_pos_of_long (a b : ℕ) (Λ θ : ℝ) (hθ0 : 0 < θ) (haθ : (a : ℝ) * θ ≤ 1) (hc : IsCentral a b Λ) (hlen : 1 ≤ ((a : ℝ) + 1) * θ) (l : ℕ) (hl : l < a) : 1 ≤ coord (cellVec a b Λ θ) ((a : ℤ) - l) - coord (cellVec a b Λ θ) (-(l : ℤ) - 1) := by rw [coord_eq_floor a b Λ θ hθ0 haθ hc _ (by omega) (by omega), coord_eq_floor a b Λ θ hθ0 haθ hc _ (by omega) (by omega)] have f := Int.floor_le (Λ + ((-(l : ℤ) - 1 : ℤ) : ℝ) * θ) have : ⌊Λ + ((-(l : ℤ) - 1 : ℤ) : ℝ) * θ⌋ + 1 ≤ ⌊Λ + (((a : ℤ) - l : ℤ) : ℝ) * θ⌋ := by rw [Int.le_floor] push_cast at f ⊢ linarith omega theorem no_two (a b : ℕ) (Λ θ : ℝ) (ha : 1 ≤ a) (hθ0 : 0 < θ) (haθ : (a : ℝ) * θ ≤ 1) (hc : IsCentral a b Λ) (i j : ℕ) (hij : i < j) (hj : j ≤ a) (hdi : 2 ≤ markerDelta a (cellVec a b Λ θ) i) (hdj : 2 ≤ markerDelta a (cellVec a b Λ θ) j) : False := by have hia : i < a := lt_of_lt_of_le hij hj have hdi' := hdi rw [markerDelta_of_lt _ hia] at hdi' obtain ⟨hi1, hi2⟩ := marker_conditions a b Λ θ hθ0 haθ hc i hia hdi' have hij' : (i : ℝ) + 1 ≤ j := by exact_mod_cast hij have hlen : 1 < ((a : ℝ) + 1) * θ := by nlinarith rcases Nat.lt_or_ge j a with hja | hja · rw [markerDelta_of_lt _ hja] at hdj obtain ⟨hj1, hj2⟩ := marker_conditions a b Λ θ hθ0 haθ hc j hja hdj have : 0 ≤ ((j : ℝ) - i - 1) * θ := mul_nonneg (by linarith) hθ0.le nlinarith · have hja' : j = a := le_antisymm hj hja subst hja' have hpos : ∀ l ∈ range j, 1 ≤ markerDelta j (cellVec j b Λ θ) l := fun l hl => by rw [markerDelta_of_lt _ (mem_range.1 hl)] exact delta_pos_of_long j b Λ θ hθ0 haθ hc hlen.le l (mem_range.1 hl) have hsingle : markerDelta j (cellVec j b Λ θ) i - 1 ≤ ∑ l ∈ range j, (markerDelta j (cellVec j b Λ θ) l - 1) := Finset.single_le_sum (f := fun l => markerDelta j (cellVec j b Λ θ) l - 1) (fun l hl => by have := hpos l hl; omega) (mem_range.2 hia) have hsum : ∑ l ∈ range j, (markerDelta j (cellVec j b Λ θ) l - 1) = (∑ l ∈ range j, markerDelta j (cellVec j b Λ θ) l) - j := by rw [Finset.sum_sub_distrib] simp have hself := markerDelta_self (cellVec j b Λ θ) omega /-- Lemma 12 (one marker): for `0 < θ ≤ 1/a` and a central point `(Λ, θ)` off the lines(`c` is its vector `cellVec a b Λ θ`, `J = ⌊Λ⌋`) such that `c` is not of the form `O₁(s)`, exactlyone of `δ_0, …, δ_a` is at least `2`. -/theorem exactly_one_marker (a b : ℕ) (ha : 2 ≤ a) (Λ θ : ℝ) (hθ0 : 0 < θ) (hθ : θ ≤ 1 / (a : ℝ)) (_hoff : OffLines a Λ θ) (hc : IsCentral a b Λ) (hO1 : ¬ IsO1 a (cellVec a b Λ θ)) : ∃! i : ℕ, i ≤ a ∧ 2 ≤ markerDelta a (cellVec a b Λ θ) i := by have ha1 : 1 ≤ a := by omega have haθ := aθ_le ha1 hθ have hex : ∃ i : ℕ, i ≤ a ∧ 2 ≤ markerDelta a (cellVec a b Λ θ) i := by by_contra hcon push Not at hcon apply hO1 have hsum : ∑ i ∈ range (a + 1), markerDelta a (cellVec a b Λ θ) i = (a : ℤ) + 1 := by rw [Finset.sum_range_succ, markerDelta_self] ring have hall : ∀ i ∈ range (a + 1), markerDelta a (cellVec a b Λ θ) i = 1 := by refine (Finset.sum_eq_sum_iff_of_le (f := markerDelta a (cellVec a b Λ θ)) (g := fun _ => (1 : ℤ)) (fun i hi => ?_)).1 ?_ · have := hcon i (by simpa [Nat.lt_succ_iff] using hi) omega · rw [hsum] simp apply isO1_of_periodic a ha1 · intro h h' h1 h2 h3 rw [coord_eq_floor a b Λ θ hθ0 haθ hc h h1 (by omega), coord_eq_floor a b Λ θ hθ0 haθ hc h' (by omega) h3] apply Int.floor_mono have : (h : ℝ) ≤ h' := by exact_mod_cast h2 nlinarith · intro h h1 h2 have hi : (-h - 1).toNat < a := by omega have := hall (-h - 1).toNat (by rw [mem_range]; omega) rw [markerDelta_of_lt _ hi] at this rw [show (a : ℤ) - ((-h - 1).toNat : ℤ) = h + ((a : ℤ) + 1) by omega, show -(((-h - 1).toNat : ℕ) : ℤ) - 1 = h by omega] at this omega obtain ⟨i0, hi0, hd0⟩ := hex refine ⟨i0, ⟨hi0, hd0⟩, fun j hj => ?_⟩ obtain ⟨hj, hdj⟩ := hj by_contra hne rcases lt_or_gt_of_ne hne with h | h · exact no_two a b Λ θ ha1 hθ0 haθ hc j i0 h hi0 hdj hd0 · exact no_two a b Λ θ ha1 hθ0 haθ hc i0 j h hj hd0 hdj end CaballeroMarker