/-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.AngularLowerBoundpublic import Formalizations.Combinatorics.Caballero.AngularK6Evenpublic import Formalizations.Combinatorics.Caballero.AngularSecondPeakOddpublic import Mathlib.Analysis.SpecificLimits.Basic /-!# The second peak of the ambiguity profile: lower bounds on the liminf (Caballero, Part IV, Theorem 3) Theorem 3 of Part IV, for a >= 2: if a is even, liminf_b A_{a,b}(2/(a+1)) >= 1/(a+1); if a is odd,liminf_b A_{a,b}(2/(a+2)) >= 2/((a+1)(a+2)), where A_{a,b}(theta) = L_b(theta)/(b + a theta) is theambiguous proportion of the vertical section (CaballeroLowerBound.ambProportion). On the sectiontheta = 2/q every Lambda with k < q Lambda < k+1 has the clipped floor vector g_h = clipfloor((k+2h)/q); Theorems 17 and 18 of Part IV (k6_even, thm_K6odd) make that vector ambiguous forthe admissible k, and these k give disjoint intervals of length 1/q inside (0, b + a theta). Theirnumber gives a linear lower bound m b - e on L_b, hence the liminf. The proof counts fewer k thanthe paper (b - a + 1 for a even instead of b - a + 3, 2 floor((b+1)/(a+1)) for a odd instead offloor((b+2)/(a+1)) + floor((b+1)/(a+1))); this suffices for the liminf and the constants m = 1/(a+1)and 2/((a+1)(a+2)) are the paper's. The finer bounds L_b >= max(0, b-a+3)/(a+1) are not stated. Theimported modules are used, not copied. ## Main results * `CaballeroSecondPeak.thm_K6`: Theorem 3: for a >= 2, a even gives liminf_b A_{a,b}(2/(a+1)) >= 1/(a+1) and a odd gives liminf_b A_{a,b}(2/(a+2)) >= 2/((a+1)(a+2))* `CaballeroSecondPeak.le_ambLength`: disjoint intervals of length 1/q of ambiguous slope-2/q vectors inside (0, b + 2a/q) give L_b(2/q) >= (their number)/q* `CaballeroSecondPeak.cellVec_of_mem`: for k < q Lambda < k+1 the cell vector of (Lambda, 2/q) is g_h = clip floor((k+2h)/q)* `CaballeroSecondPeak.le_liminf_of_linear`: if L_b(theta) >= m b - e for large b then liminf_b A_{a,b}(theta) >= m ## 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 CaballeroSecondPeak open Finset MeasureTheory Filter Topology CaballeroGeneralA CaballeroLowerBound /-! ### The vector of a point of the section `θ = 2/q` -/ /-- If `k < qΛ < k+1` then `Λ + 2h/q` lies strictly between `⌊(k+2h)/q⌋` and its successor. -/theorem between_floor (q : ℕ) (hq : 0 < q) (k h : ℤ) (Λ : ℝ) (h1 : (k : ℝ) < q * Λ) (h2 : (q : ℝ) * Λ < k + 1) : (((k + 2 * h) / (q : ℤ) : ℤ) : ℝ) < Λ + (h : ℝ) * (2 / q) ∧ Λ + (h : ℝ) * (2 / q) < (((k + 2 * h) / (q : ℤ) : ℤ) : ℝ) + 1 := by have hq' : (0 : ℝ) < q := by exact_mod_cast hq have hq'' : (0 : ℤ) < q := by exact_mod_cast hq have hde := Int.mul_ediv_add_emod (k + 2 * h) q have h0 := Int.emod_nonneg (k + 2 * h) hq''.ne' have hlt := Int.emod_lt_of_pos (k + 2 * h) hq'' generalize (k + 2 * h) / (q : ℤ) = d at hde ⊢ generalize (k + 2 * h) % (q : ℤ) = e at hde h0 hlt have hN : (q : ℝ) * d + e = k + 2 * h := by exact_mod_cast hde have h0' : (0 : ℝ) ≤ e := by exact_mod_cast h0 have h1' : (e : ℝ) + 1 ≤ q := by exact_mod_cast hlt have eq : Λ + (h : ℝ) * (2 / q) = ((q : ℝ) * Λ + 2 * h) / q := by field_simp rw [eq, lt_div_iff₀ hq', div_lt_iff₀ hq'] constructor <;> nlinarith /-- For `k < qΛ < k+1` the point `(Λ, 2/q)` is off the lines. -/theorem offLines_of_mem (a q : ℕ) (hq : 0 < q) (k : ℤ) (Λ : ℝ) (h1 : (k : ℝ) < q * Λ) (h2 : (q : ℝ) * Λ < k + 1) : OffLines a Λ (2 / q) := by intro h _ _ z hz obtain ⟨b1, b2⟩ := between_floor q hq k h Λ h1 h2 rw [hz] at b1 b2 have c1 : (k + 2 * h) / (q : ℤ) < z := by exact_mod_cast b1 have c2 : z < (k + 2 * h) / (q : ℤ) + 1 := by exact_mod_cast b2 omega /-- For `k < qΛ < k+1` the clipped floor vector of `(Λ, 2/q)` is `g_h = clip ⌊(k+2h)/q⌋`. -/theorem cellVec_of_mem (a b q : ℕ) (hq : 0 < q) (k : ℤ) (Λ : ℝ) (h1 : (k : ℝ) < q * Λ) (h2 : (q : ℝ) * Λ < k + 1) : cellVec a b Λ (2 / q) = CaballeroK6Odd.slopeVec a b q k := by funext i unfold cellVec CaballeroK6Odd.slopeVec obtain ⟨b1, b2⟩ := between_floor q hq k ((((i : ℕ) : ℤ) - a : ℤ)) Λ h1 h2 have hf : ⌊Λ + ((((i : ℕ) : ℤ) - a : ℤ) : ℝ) * (2 / q)⌋ = (k + 2 * (((i : ℕ) : ℤ) - a)) / (q : ℤ) := by rw [Int.floor_eq_iff] exact ⟨b1.le, b2⟩ rw [hf, Rat.floor_intCast_div_natCast] /-! ### Measure of the union of the intervals -/ /-- Disjoint intervals `(k/q, (k+1)/q)` of ambiguous slope-2/q vectors inside `(0, b + 2a/q)`give ambiguous length at least `(number of k)/q`. -/theorem le_ambLength (a b q : ℕ) (hq : 0 < q) (S : Finset ℤ) (h0 : ∀ k ∈ S, 0 ≤ k) (h1 : ∀ k ∈ S, k + 1 ≤ (q : ℤ) * b + 2 * a) (hamb : ∀ k ∈ S, Ambiguous a b (CaballeroK6Odd.slopeVec a b q k)) : (S.card : ℝ) / q ≤ ambLength a b (2 / q) := by have hq' : (0 : ℝ) < q := by exact_mod_cast hq let I : ℤ → Set ℝ := fun k => Set.Ioo ((k : ℝ) / q) (((k : ℝ) + 1) / q) have hmem : ∀ k Λ, Λ ∈ I k → (k : ℝ) < q * Λ ∧ (q : ℝ) * Λ < k + 1 := by intro k Λ ⟨l1, l2⟩ rw [div_lt_iff₀ hq'] at l1 rw [lt_div_iff₀ hq'] at l2 constructor <;> linarith have hdisj : (S : Set ℤ).PairwiseDisjoint I := by intro k hk k' hk' hne rw [Function.onFun, Set.disjoint_left] intro Λ ⟨a1, a2⟩ ⟨b1, b2⟩ have c1 : (k : ℝ) < k' + 1 := by have := a1.trans b2 rwa [div_lt_div_iff_of_pos_right hq'] at this have c2 : (k' : ℝ) < k + 1 := by have := b1.trans a2 rwa [div_lt_div_iff_of_pos_right hq'] at this have d1 : k < k' + 1 := by exact_mod_cast c1 have d2 : k' < k + 1 := by exact_mod_cast c2 omega have hsub : (⋃ k ∈ S, I k) ⊆ ambSet a b (2 / q) := by intro Λ hΛ obtain ⟨k, hk, hI⟩ := Set.mem_iUnion₂.mp hΛ obtain ⟨m1, m2⟩ := hmem k Λ hI have hk0 : (0 : ℝ) ≤ k := by exact_mod_cast h0 k hk have hk1 : (k : ℝ) + 1 ≤ q * b + 2 * a := by exact_mod_cast h1 k hk have hpos : 0 < Λ := by by_contra hn push Not at hn nlinarith refine ⟨hpos, ?_, offLines_of_mem a q hq k Λ m1 m2, ?_⟩ · have e : (b : ℝ) + (a : ℝ) * (2 / q) = ((q : ℝ) * b + 2 * a) / q := by field_simp rw [e, lt_div_iff₀ hq'] linarith · rw [cellVec_of_mem a b q hq k Λ m1 m2] exact hamb k hk have hfin : volume (ambSet a b (2 / q)) ≠ ⊤ := ne_top_of_le_ne_top ENNReal.ofReal_ne_top (volume_ambSet_le a b (2 / q)) have hU : volume (⋃ k ∈ S, I k) = ∑ k ∈ S, ENNReal.ofReal (1 / q) := by rw [measure_biUnion_finset hdisj (fun k _ => measurableSet_Ioo)] apply sum_congr rfl intro k _ rw [Real.volume_Ioo] congr 1 field_simp ring have hle := ENNReal.toReal_mono hfin (measure_mono hsub) rw [hU, ENNReal.toReal_sum (fun k _ => ENNReal.ofReal_ne_top)] at hle rw [ambLength_eq] refine le_trans (le_of_eq ?_) hle simp only [ENNReal.toReal_ofReal (by positivity : (0 : ℝ) ≤ 1 / q), sum_const, nsmul_eq_mul] ring /-! ### From a linear lower bound to the liminf -/ /-- If `L_b(θ) ≥ m b - e` for all large `b`, then `liminf_b A_{a,b}(θ) ≥ m`. -/theorem le_liminf_of_linear (a : ℕ) (ha : 1 ≤ a) (θ : ℝ) (hθ : 0 < θ) (m e : ℝ) (h : ∀ᶠ b : ℕ in atTop, m * b - e ≤ ambLength a b θ) : m ≤ Filter.liminf (fun b : ℕ => ambProportion a b θ) atTop := by have hden : ∀ b : ℕ, 0 < (b : ℝ) + (a : ℝ) * θ := fun b => by have : (0 : ℝ) < a := by exact_mod_cast (show 0 < a by omega) positivity let g : ℕ → ℝ := fun b => (m * b - e) / ((b : ℝ) + (a : ℝ) * θ) have hg : Tendsto g atTop (𝓝 m) := by have h1 : Tendsto (fun b : ℕ => (b : ℝ) + (a : ℝ) * θ) atTop atTop := tendsto_natCast_atTop_atTop.atTop_add tendsto_const_nhds have h2 := (tendsto_const_nhds (x := m)).sub ((tendsto_const_nhds (x := e + m * ((a : ℝ) * θ))).div_atTop h1) rw [sub_zero] at h2 refine h2.congr fun b => ?_ have := (hden b).ne' simp only [g] field_simp ring have hle : ∀ᶠ b in atTop, g b ≤ ambProportion a b θ := by filter_upwards [h] with b hb unfold ambProportion simp only [g] exact div_le_div_of_nonneg_right hb (hden b).le have hco : IsCoboundedUnder (· ≥ ·) atTop (fun b : ℕ => ambProportion a b θ) := isCoboundedUnder_ge_of_le atTop (x := 1) fun b => div_le_one_of_le₀ (ambLength_le a b θ hθ.le) (hden b).le calc m = Filter.liminf g atTop := hg.liminf_eq.symm _ ≤ Filter.liminf (fun b : ℕ => ambProportion a b θ) atTop := Filter.liminf_le_liminf hle (hv := hg.isBoundedUnder_ge) (hu := hco) /-! ### The even case -/ /-- The two slope-vector definitions of Part IV agree. -/theorem slopeVec_even_eq (a b q : ℕ) (k : ℤ) : CaballeroK6Even.slopeVec a b q k = CaballeroK6Odd.slopeVec a b q k := by funext i simp only [CaballeroK6Even.slopeVec, CaballeroK6Odd.slopeVec, CaballeroSlopeTwo.slope2_g, CaballeroSlopeTwo.slope2_clip, CaballeroPeaks.clip] /-- Theorem 3, `a` even. -/theorem thm_K6_even (a : ℕ) (ha : 2 ≤ a) (hev : Even a) : (1 : ℝ) / ((a : ℝ) + 1) ≤ Filter.liminf (fun b : ℕ => ambProportion a b (2 / ((a : ℝ) + 1))) Filter.atTop := by obtain ⟨r, hr⟩ := hev have hq : 0 < a + 1 := by omega have hθ : (2 : ℝ) / ((a : ℝ) + 1) = 2 / ((a + 1 : ℕ) : ℝ) := by push_cast; rfl rw [hθ] refine le_liminf_of_linear a (by omega) _ (by positivity) _ (((a : ℝ) - 1) / ((a : ℝ) + 1)) ?_ filter_upwards [eventually_ge_atTop a] with b hb let S : Finset ℤ := Icc ((a : ℤ) * b + a - 1) ((a : ℤ) * b + b - 1) have hcard : (S.card : ℤ) = (b : ℤ) - a + 1 := by simp only [S, Int.card_Icc] omega have hcardR : (S.card : ℝ) = (b : ℝ) - a + 1 := by exact_mod_cast hcard have key := le_ambLength a b (a + 1) hq S (fun k hk => by have := (mem_Icc.mp hk).1 have : (0 : ℤ) ≤ (a : ℤ) * b := by positivity omega) (fun k hk => by have := (mem_Icc.mp hk).2 push_cast nlinarith) (fun k hk => by obtain ⟨hk1, hk2⟩ := mem_Icc.mp hk have hx := CaballeroK6Even.k6_even a r b (k - ((a : ℤ) * b + a)) (by omega) ha (by omega) (by omega) (by omega) obtain ⟨hc, hg, hne, hZ⟩ := hx have ek : (a : ℤ) * b + a + (k - ((a : ℤ) * b + a)) = k := by ring rw [ek, slopeVec_even_eq] at hg hne hZ exact ⟨hg, _, hc, hne.symm, hZ⟩) rw [hcardR] at key refine le_trans (le_of_eq ?_) key push_cast field_simp ring /-! ### The odd case -/ /-- The integer `k = qb + 2a - T - 1`, `T = (ℓ+1)q - 5 + ε`, of Theorem 18 (`q = a+2`). -/def kOdd (a b ℓ ε : ℕ) : ℤ := ((a : ℤ) + 2) * b + 2 * a - (((ℓ : ℤ) + 1) * ((a : ℤ) + 2) - 5 + ε) - 1 theorem kOdd_bounds (a b ℓ ε : ℕ) (ha : 3 ≤ a) (hℓ : 1 ≤ ℓ) (hε : ε ≤ 1) (hΔ : (ℓ : ℤ) * (a + 1) - 1 + ε ≤ (b : ℤ) + 1) : 0 ≤ kOdd a b ℓ ε ∧ kOdd a b ℓ ε + 1 ≤ ((a + 2 : ℕ) : ℤ) * b + 2 * a := by unfold kOdd push_cast have hℓ' : (1 : ℤ) ≤ ℓ := by exact_mod_cast hℓ have ha' : (3 : ℤ) ≤ a := by exact_mod_cast ha have hε' : (ε : ℤ) ≤ 1 := by exact_mod_cast hε have hε0 : (0 : ℤ) ≤ ε := by positivity have hb : (ℓ : ℤ) + 1 ≤ b := by nlinarith have hq : (0 : ℤ) ≤ (a : ℤ) + 2 := by omega have := mul_le_mul_of_nonneg_left hb hq constructor <;> nlinarith theorem kOdd_inj (a b ℓ ε ℓ' ε' : ℕ) (ha : 3 ≤ a) (hε : ε ≤ 1) (hε' : ε' ≤ 1) (h : kOdd a b ℓ ε = kOdd a b ℓ' ε') : ℓ = ℓ' ∧ ε = ε' := by unfold kOdd at h have ha' : (3 : ℤ) ≤ a := by exact_mod_cast ha have hq : (5 : ℤ) ≤ (a : ℤ) + 2 := by omega have e : ((ℓ : ℤ) - ℓ') * ((a : ℤ) + 2) = (ε' : ℤ) - ε := by linarith have hε1 : (ε : ℤ) ≤ 1 := by exact_mod_cast hε have hε1' : (ε' : ℤ) ≤ 1 := by exact_mod_cast hε' have hε0 : (0 : ℤ) ≤ ε := by positivity have hε0' : (0 : ℤ) ≤ ε' := by positivity have hl : (ℓ : ℤ) = ℓ' := by by_contra hne rcases lt_or_gt_of_ne hne with hlt | hlt · have : (ℓ : ℤ) - ℓ' ≤ -1 := by omega nlinarith · have : 1 ≤ (ℓ : ℤ) - ℓ' := by omega nlinarith have hl' : ℓ = ℓ' := by exact_mod_cast hl refine ⟨hl', ?_⟩ rw [hl] at e have : (ε : ℤ) = ε' := by linarith exact_mod_cast this /-- Theorem 18 gives an ambiguous slope vector for every admissible pair `(ℓ, ε)`. -/theorem ambiguous_kOdd (a b ℓ ε : ℕ) (ha : Odd a) (ha3 : 3 ≤ a) (hℓ : 1 ≤ ℓ) (hε : ε ≤ 1) (hΔ : (ℓ : ℤ) * (a + 1) - 1 + ε ≤ (b : ℤ) + 1) : Ambiguous a b (CaballeroK6Odd.slopeVec a b (a + 2) (kOdd a b ℓ ε)) := by obtain ⟨r, hr⟩ := ha obtain ⟨hc, hg, hne, hZ⟩ := CaballeroK6Odd.thm_K6odd a b r ℓ ε hr ha3 hℓ hε ((ℓ : ℤ) * (a + 1) - 1 + ε) rfl hΔ ((b : ℤ) - ((ℓ : ℤ) * (a + 1) - 1 + ε)) ((b : ℤ) - r) rfl rfl (((ℓ : ℤ) + 1) * ((a : ℤ) + 2) - 5 + ε) (kOdd a b ℓ ε) rfl rfl exact ⟨hg, _, hc, hne, hZ⟩ /-- Theorem 3, `a` odd. -/theorem thm_K6_odd (a : ℕ) (ha : 2 ≤ a) (hodd : Odd a) : 2 / (((a : ℝ) + 1) * ((a : ℝ) + 2)) ≤ Filter.liminf (fun b : ℕ => ambProportion a b (2 / ((a : ℝ) + 2))) Filter.atTop := by have ha3 : 3 ≤ a := by obtain ⟨r, hr⟩ := hodd omega have hq : 0 < a + 2 := by omega have hθ : (2 : ℝ) / ((a : ℝ) + 2) = 2 / ((a + 2 : ℕ) : ℝ) := by push_cast; rfl rw [hθ] refine le_liminf_of_linear a (by omega) _ (by positivity) _ (2 * ((a : ℝ) - 1) / (((a : ℝ) + 1) * ((a : ℝ) + 2))) ?_ filter_upwards [eventually_ge_atTop a] with b hb let N : ℕ := (b + 1) / (a + 1) let P : Finset (ℕ × ℕ) := Icc 1 N ×ˢ range 2 let S : Finset ℤ := P.image fun p => kOdd a b p.1 p.2 have hP : ∀ p ∈ P, 1 ≤ p.1 ∧ p.1 ≤ N ∧ p.2 ≤ 1 := by intro p hp simp only [P, mem_product, mem_Icc, mem_range] at hp omega have hΔ : ∀ p ∈ P, (p.1 : ℤ) * (a + 1) - 1 + p.2 ≤ (b : ℤ) + 1 := by intro p hp obtain ⟨h1, h2, h3⟩ := hP p hp have : p.1 * (a + 1) ≤ b + 1 := by calc p.1 * (a + 1) ≤ N * (a + 1) := Nat.mul_le_mul_right _ h2 _ ≤ b + 1 := Nat.div_mul_le_self _ _ have h4 : (p.1 : ℤ) * (a + 1) ≤ b + 1 := by exact_mod_cast this have h5 : (p.2 : ℤ) ≤ 1 := by exact_mod_cast h3 omega have hinj : Set.InjOn (fun p : ℕ × ℕ => kOdd a b p.1 p.2) P := by intro p hp p' hp' e obtain ⟨h1, h2, h3⟩ := hP p hp obtain ⟨h1', h2', h3'⟩ := hP p' hp' obtain ⟨e1, e2⟩ := kOdd_inj a b p.1 p.2 p'.1 p'.2 ha3 h3 h3' e exact Prod.ext e1 e2 have hcard : S.card = N * 2 := by simp only [S] rw [card_image_of_injOn hinj] simp [P] have key := le_ambLength a b (a + 2) hq S (fun k hk => by obtain ⟨p, hp, rfl⟩ := mem_image.mp hk obtain ⟨h1, h2, h3⟩ := hP p hp exact (kOdd_bounds a b p.1 p.2 ha3 h1 h3 (hΔ p hp)).1) (fun k hk => by obtain ⟨p, hp, rfl⟩ := mem_image.mp hk obtain ⟨h1, h2, h3⟩ := hP p hp exact (kOdd_bounds a b p.1 p.2 ha3 h1 h3 (hΔ p hp)).2) (fun k hk => by obtain ⟨p, hp, rfl⟩ := mem_image.mp hk obtain ⟨h1, h2, h3⟩ := hP p hp exact ambiguous_kOdd a b p.1 p.2 hodd ha3 h1 h3 (hΔ p hp)) rw [hcard] at key have hN : (b : ℝ) + 1 - a ≤ (N : ℝ) * ((a : ℝ) + 1) := by have h1 : b + 1 < (N + 1) * (a + 1) := by have := Nat.lt_mul_div_succ (b + 1) (show 0 < a + 1 by omega) simpa [N, Nat.mul_comm] using this have h1' : b + 1 ≤ N * (a + 1) + a := by have : (N + 1) * (a + 1) = N * (a + 1) + a + 1 := by ring omega have h2 : (b : ℝ) + 1 ≤ (N : ℝ) * ((a : ℝ) + 1) + a := by exact_mod_cast h1' linarith have hqpos : (0 : ℝ) < (a : ℝ) + 2 := by positivity have hapos : (0 : ℝ) < (a : ℝ) + 1 := by positivity refine le_trans ?_ key have e : 2 / (((a : ℝ) + 1) * ((a : ℝ) + 2)) * b - 2 * ((a : ℝ) - 1) / (((a : ℝ) + 1) * ((a : ℝ) + 2)) = 2 * ((b : ℝ) + 1 - a) / (((a : ℝ) + 1) * ((a : ℝ) + 2)) := by field_simp ring rw [e] push_cast rw [div_le_div_iff₀ (by positivity) hqpos] nlinarith /-- **Theorem 3** (second peak, lower bounds), for `a ≥ 2`: if `a` is even,`liminf_b A_{a,b}(2/(a+1)) ≥ 1/(a+1)`; if `a` is odd, `liminf_b A_{a,b}(2/(a+2)) ≥ 2/((a+1)(a+2))`. -/theorem thm_K6 (a : ℕ) (ha : 2 ≤ a) : (Even a → (1 : ℝ) / ((a : ℝ) + 1) ≤ Filter.liminf (fun b : ℕ => ambProportion a b (2 / ((a : ℝ) + 1))) Filter.atTop) ∧ (Odd a → 2 / (((a : ℝ) + 1) * ((a : ℝ) + 2)) ≤ Filter.liminf (fun b : ℕ => ambProportion a b (2 / ((a : ℝ) + 2))) Filter.atTop) := ⟨thm_K6_even a ha, thm_K6_odd a ha⟩ end CaballeroSecondPeak