🏛️ Atlas✒️Formalizations.Combinatorics.Caballero.AngularPrimaryPhase view on GitHub ↗7 theorems
/-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.AngularRigidpublic import Formalizations.Combinatorics.Caballero.AngularLowerBoundpublic import Mathlib.Analysis.SpecificLimits.Basicpublic import Mathlib.MeasureTheory.Group.Measure /-!# The primary phase of the ambiguity profile (Caballero, Part IV, Theorem 1) Theorem 1 of Part IV: for a >= 2, 0 < theta <= 1/a and every b >= 1, 0 <= L_b(theta) - b U_a(theta)<= 12a + 11, where L_b is the ambiguous length (CaballeroLowerBound.ambLength) and U_a the primaryphase function (CaballeroWidths.primaryPhase). The consequences are stated and proved in the sametheorem: the limit F_a(theta) = lim_b A_{a,b}(theta) exists on (0, 1/a] and equals U_a(theta); theconvergence is uniform there, |A_{a,b}(theta) - U_a(theta)| <= K/b for a constant K depending on aonly; and U_a is given by the three formulas 2 theta, a(a+1) theta - a + 1 and a + 1 - a(a+1) thetaon the three intervals with ends 1/(a+2), 1/(a+1), 1/a. The proof follows the paper. The lower boundis Theorem 5 (lower_bound). For the upper bound, the ambiguous points of the section are covered bytwo end intervals of total length 4a + 5 + C_a (the non-central units) and, in the central units, bythe translates j + (phase set of k^(r)), 0 <= j < b, 0 <= r <= a: by Proposition 14(central_rigidity) an ambiguous central cell is of the form O_1, so its fractional part lies in thephase set of a primary pattern; the measure of the union is at most b U_a(theta). The constant C_a =8a + 6 of the base module is the one of the paper, and the central cells are those with 4a + 5 <=floor(Lambda) <= b - C_a. ## Main results * `CaballeroPrimaryPhase.primary_phase`: Theorem 1: for a >= 2 and 0 < theta <= 1/a, 0 <= L_b - b U_a <= 12a+11 for b >= 1; A_{a,b}(theta) tends to U_a(theta), uniformly with rate K/b; and the three formulas for U_a* `CaballeroPrimaryPhase.ambLength_le_primaryPhase`: the upper bound L_b(theta) <= b U_a(theta) + 12a+11 for a >= 2 and 0 < theta <= 1/a* `CaballeroPrimaryPhase.phase_of_isO1`: a central cell of the form O_1 has the fractional part of Lambda in the phase set of some primary pattern k^(r)* `CaballeroPrimaryPhase.isO1_of_ambiguous_central`: an ambiguous central cell with 0 < theta <= 1/a is of the form O_1 (from Proposition 14) ## 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 CaballeroPrimaryPhase open Finset MeasureTheory Filter Topology CaballeroGeneralA CaballeroWidths CaballeroLowerBound  CaballeroMarker /-- The floor of `x / (a + 1)` for an integer `x`, as an integer division. -/theorem floor_div_succ (x : ℤ) (a : ℕ) : ⌊(x : ℝ) / ((a : ℝ) + 1)⌋ = x / ((a : ℤ) + 1) := by  have h := Rat.floor_intCast_div_natCast x (a + 1)  have h2 : ((x : ℝ) / ((a : ℝ) + 1)) = (((x : ℚ) / ((a + 1 : ℕ) : ℚ) : ℚ) : ℝ) := by    push_cast    rfl  rw [h2, Rat.floor_cast, h]  push_cast  rfl /-- A central cell of the form `O_1(s)`: the fractional part of `Λ` lies in the phase set of one ofthe primary patterns `k^(r)`, `0 ≤ r ≤ a`. -/theorem phase_of_isO1 (a b : ℕ) (Λ θ : ℝ) (hθ0 : 0 < θ) (haθ : (a : ℝ) * θ ≤ 1)    (hoff : OffLines a Λ θ) (hc : IsCentral a b Λ) (hO : IsO1 a (cellVec a b Λ θ)) :    ∃ n r : ℕ, ⌊Λ⌋ = n ∧ r ≤ a ∧ Λ - n ∈ phaseSet a (primaryPattern a r) θ := by  obtain ⟨s, hs⟩ := hO  have hJ0 : 0 ≤ ⌊Λ⌋ := by have := hc.1; omega  obtain ⟨n, hn⟩ := Int.eq_ofNat_of_zero_le hJ0  have hm : (0 : ℤ) < (a : ℤ) + 1 := by omega  obtain ⟨r, hr⟩ : ∃ r : ℕ, (r : ℤ) = s % ((a : ℤ) + 1) :=    (Int.eq_ofNat_of_zero_le (Int.emod_nonneg s hm.ne')).imp fun _ h => h.symm  have hrlt : (r : ℤ) < (a : ℤ) + 1 := by rw [hr]; exact Int.emod_lt_of_pos _ hm  have hsq : ((a : ℤ) + 1) * (s / ((a : ℤ) + 1)) + (r : ℤ) = s := by    rw [hr]; exact Int.mul_ediv_add_emod s _  -- the floors of the point, as `n + ⌊u + hθ⌋`  have hfl : ∀ h : ℤ, -(a : ℤ) ≤ h → h ≤ a →      (n : ℤ) + ⌊(Λ - n) + (h : ℝ) * θ⌋ = (s + h) / ((a : ℤ) + 1) := by    intro h h1 h2    have e1 := coord_eq_floor a b Λ θ hθ0 haθ hc h h1 h2    have e2 := hs h h1 h2    rw [e1] at e2    have e3 : Λ + (h : ℝ) * θ = ((Λ - n) + (h : ℝ) * θ) + (n : ℝ) := by ring    rw [e3, Int.floor_add_natCast] at e2    have e4 : ((((a + 1 : ℕ)) : ℝ)) = (a : ℝ) + 1 := by push_cast; ring    rw [show (((s + h : ℤ) : ℝ)) / ((a + 1 : ℕ) : ℝ) = ((s + h : ℤ) : ℝ) / ((a : ℝ) + 1) by rw [e4],      floor_div_succ] at e2    omega  -- the integer part of `s` is `n`  have hu0 : 0 < Λ - n ∧ Λ - n < 1 := by    have f1 := Int.floor_le Λ    have f2 := Int.lt_floor_add_one Λ    rw [hn] at f1 f2    simp only [Int.cast_natCast] at f1 f2    refine ⟨?_, by linarith⟩    rcases f1.lt_or_eq with h | h    · linarith    · exact absurd (by simpa using h.symm : Λ + ((0 : ℤ) : ℝ) * θ = (n : ℝ)) (by        have := hoff 0 (by omega) (by omega) (n : ℤ)        simpa using this)  have hfl0 : ⌊(Λ - n) + ((0 : ℤ) : ℝ) * θ⌋ = 0 := by    simp only [Int.cast_zero, zero_mul, add_zero]    exact Int.floor_eq_zero_iff.2 ⟨hu0.1.le, hu0.2⟩  have h0 := hfl 0 (by omega) (by omega)  rw [hfl0] at h0  have hr0 : (r : ℤ) / ((a : ℤ) + 1) = 0 := Int.ediv_eq_zero_of_lt (by omega) hrlt  have hsplit : ∀ h : ℤ, (s + h) / ((a : ℤ) + 1) = s / ((a : ℤ) + 1) + ((r : ℤ) + h) / ((a : ℤ) + 1) := by    intro h    have : s + h = ((r : ℤ) + h) + ((a : ℤ) + 1) * (s / ((a : ℤ) + 1)) := by linarith    rw [this, Int.add_mul_ediv_left _ _ hm.ne']    ring  have hq : s / ((a : ℤ) + 1) = n := by    have := hsplit 0    simp only [add_zero] at this h0    rw [hr0] at this    omega  refine ⟨n, r, hn, by omega, hu0.1, hu0.2, fun i => ?_⟩  have hi1 : -(a : ℤ) ≤ ((i : ℕ) : ℤ) - a := by omega  have hi2 : ((i : ℕ) : ℤ) - a ≤ a := by have := i.2; omega  have := hfl _ hi1 hi2  rw [hsplit, hq] at this  have hprim : primaryPattern a r i = ((r : ℤ) + (((i : ℕ) : ℤ) - a)) / ((a : ℤ) + 1) := by    unfold primaryPattern    exact floor_div_succ _ a  rw [hprim]  omega /-- The ambiguous cells of the central units are of the form `O_1` (Proposition 14). -/theorem isO1_of_ambiguous_central (a b : ℕ) (ha : 2 ≤ a) (Λ θ : ℝ) (hΛ : 0 < Λ) (hθ0 : 0 < θ)    (hθ : θ ≤ 1 / (a : ℝ)) (hoff : OffLines a Λ θ) (hc : IsCentral a b Λ)    (hamb : Ambiguous a b (cellVec a b Λ θ)) : IsO1 a (cellVec a b Λ θ) := by  by_contra hO  obtain ⟨_, d, hd, hne, hZ⟩ := hamb  exact hne (CaballeroRigid.central_rigidity a b ha Λ θ hΛ hθ0 hθ hoff hc hO d hd hZ) /-- `C_a = 8a + 6`, as a real number. -/theorem Ca_cast (a : ℕ) : ((Ca a : ℤ) : ℝ) = 8 * (a : ℝ) + 6 := by  unfold Ca  push_cast  ring /-- The upper bound `L_b(θ) ≤ b U_a(θ) + 12a + 11` of Theorem 1. -/theorem ambLength_le_primaryPhase (a b : ℕ) (ha : 2 ≤ a) (θ : ℝ) (hθ0 : 0 < θ)    (hθ : θ ≤ 1 / (a : ℝ)) :    ambLength a b θ ≤ (b : ℝ) * primaryPhase a θ + (12 * (a : ℝ) + 11) := by  have haθ : (a : ℝ) * θ ≤ 1 := CaballeroMarker.aθ_le (by omega) hθ  let T : Finset (ℕ × ℕ) := range b ×ˢ range (a + 1)  let blk : ℕ × ℕ → Set ℝ := fun p =>    (fun Λ : ℝ => Λ + (-(p.1 : ℝ))) ⁻¹' phaseSet a (primaryPattern a p.2) θ  have hCa : (0 : ℝ) < ((Ca a : ℤ) : ℝ) := by rw [Ca_cast]; positivity  have hsub : ambSet a b θ ⊆ (Set.Ico (0 : ℝ) (4 * (a : ℝ) + 5) ∪      Set.Ico ((b : ℝ) + 1 - ((Ca a : ℤ) : ℝ)) ((b : ℝ) + 1)) ∪ ⋃ p ∈ T, blk p := by    rintro Λ ⟨hΛ0, hΛb, hoff, hamb⟩    by_cases hc : IsCentral a b Λ    · right      have hO := isO1_of_ambiguous_central a b ha Λ θ hΛ0 hθ0 hθ hoff hc hamb      obtain ⟨n, r, hn, hr, hmem⟩ := phase_of_isO1 a b Λ θ hθ0 haθ hoff hc hO      have hnb : n < b := by        have := hc.2        have hCa' : (0 : ℤ) < Ca a := by unfold Ca; positivity        omega      refine Set.mem_iUnion₂.2 ⟨(n, r), ?_, ?_⟩      · simp only [T, mem_product, mem_range]        omega      · show Λ + (-((n : ℕ) : ℝ)) ∈ phaseSet a (primaryPattern a r) θ        rw [← sub_eq_add_neg]        exact hmem    · left      have f1 := Int.floor_le Λ      have f2 := Int.lt_floor_add_one Λ      unfold IsCentral at hc      rw [not_and_or] at hc      rcases hc with hc | hc      · left        refine ⟨hΛ0.le, ?_⟩        have : ⌊Λ⌋ + 1 ≤ 4 * (a : ℤ) + 5 := by omega        have h' : ((⌊Λ⌋ : ℤ) : ℝ) + 1 ≤ ((4 * (a : ℤ) + 5 : ℤ) : ℝ) := by exact_mod_cast this        push_cast at h'        linarith      · right        push Not at hc        have h' : ((b : ℤ) - Ca a + 1 : ℤ) ≤ ⌊Λ⌋ := by omega        have h'' : (((b : ℤ) - Ca a + 1 : ℤ) : ℝ) ≤ ((⌊Λ⌋ : ℤ) : ℝ) := by exact_mod_cast h'        push_cast at h''        constructor        · linarith        · have : (a : ℝ) * θ ≤ 1 := haθ          linarith  have hfin : ∀ p ∈ T, volume (blk p) ≠ ⊤ := by    intro p _    have e : volume (blk p) = volume (phaseSet a (primaryPattern a p.2) θ) :=      measure_preimage_add_right volume (-(p.1 : ℝ)) _    rw [e]    refine ne_top_of_le_ne_top (b := volume (Set.Ioo (0 : ℝ) 1)) (by simp)      (measure_mono fun u hu => ⟨hu.1, hu.2.1⟩)  have hvol : volume (ambSet a b θ) ≤ ENNReal.ofReal (4 * (a : ℝ) + 5) +      ENNReal.ofReal ((Ca a : ℤ) : ℝ) + ∑ p ∈ T, volume (blk p) := by    calc volume (ambSet a b θ)        ≤ volume ((Set.Ico (0 : ℝ) (4 * (a : ℝ) + 5) ∪            Set.Ico ((b : ℝ) + 1 - ((Ca a : ℤ) : ℝ)) ((b : ℝ) + 1)) ∪ ⋃ p ∈ T, blk p) :=          measure_mono hsub      _ ≤ volume (Set.Ico (0 : ℝ) (4 * (a : ℝ) + 5) ∪            Set.Ico ((b : ℝ) + 1 - ((Ca a : ℤ) : ℝ)) ((b : ℝ) + 1)) + volume (⋃ p ∈ T, blk p) :=          measure_union_le _ _      _ ≤ (volume (Set.Ico (0 : ℝ) (4 * (a : ℝ) + 5)) +            volume (Set.Ico ((b : ℝ) + 1 - ((Ca a : ℤ) : ℝ)) ((b : ℝ) + 1))) +            ∑ p ∈ T, volume (blk p) := by          gcongr          · exact measure_union_le _ _          · exact measure_biUnion_finset_le _ _      _ = _ := by          rw [Real.volume_Ico, Real.volume_Ico, sub_zero]          congr 3          ring  have hsumT : (∑ p ∈ T, volume (blk p)).toReal = (b : ℝ) * primaryPhase a θ := by    have e : ∀ p ∈ T, (volume (blk p)).toReal = phaseWidth a (primaryPattern a p.2) θ := by      intro p _      rw [measure_preimage_add_right volume (-(p.1 : ℝ)) _, volume_phaseSet]    rw [ENNReal.toReal_sum hfin, sum_congr rfl e, sum_product]    unfold primaryPhase    simp only [sum_const, card_range, nsmul_eq_mul]  have hR : (ENNReal.ofReal (4 * (a : ℝ) + 5) + ENNReal.ofReal ((Ca a : ℤ) : ℝ) +      ∑ p ∈ T, volume (blk p)) ≠ ⊤ :=    ENNReal.add_ne_top.2 ⟨ENNReal.add_ne_top.2 ⟨ENNReal.ofReal_ne_top, ENNReal.ofReal_ne_top⟩,      (ENNReal.sum_ne_top.2 hfin)⟩  rw [ambLength_eq]  have := ENNReal.toReal_mono hR hvol  rw [ENNReal.toReal_add (ENNReal.add_ne_top.2 ⟨ENNReal.ofReal_ne_top, ENNReal.ofReal_ne_top⟩)    (ENNReal.sum_ne_top.2 hfin), ENNReal.toReal_add ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top,    ENNReal.toReal_ofReal (by positivity), ENNReal.toReal_ofReal hCa.le, hsumT, Ca_cast] at this  linarith /-- The primary phase function is nonnegative. -/theorem primaryPhase_nonneg (a : ℕ) (θ : ℝ) : 0 ≤ primaryPhase a θ :=  sum_nonneg fun _ _ => le_max_right _ _ /-- Theorem 1 (primary phase). -/theorem primary_phase (a : ℕ) (ha : 2 ≤ a) :    (∀ θ : ℝ, 0 < θ → θ ≤ 1 / (a : ℝ) → ∀ b : ℕ, 1 ≤ b →      0 ≤ ambLength a b θ - (b : ℝ) * primaryPhase a θ ∧      ambLength a b θ - (b : ℝ) * primaryPhase a θ ≤ 12 * (a : ℝ) + 11) ∧    (∀ θ : ℝ, 0 < θ → θ ≤ 1 / (a : ℝ) →      Filter.Tendsto (fun b : ℕ => ambProportion a b θ) Filter.atTop (nhds (primaryPhase a θ))) ∧    (∃ K : ℝ, ∀ θ : ℝ, 0 < θ → θ ≤ 1 / (a : ℝ) → ∀ b : ℕ, 1 ≤ b →      |ambProportion a b θ - primaryPhase a θ| ≤ K / (b : ℝ)) ∧    (∀ θ : ℝ, 0 < θ → θ ≤ 1 / ((a : ℝ) + 2) → primaryPhase a θ = 2 * θ) ∧    (∀ θ : ℝ, 1 / ((a : ℝ) + 2) ≤ θ → θ ≤ 1 / ((a : ℝ) + 1) →      primaryPhase a θ = (a : ℝ) * ((a : ℝ) + 1) * θ - a + 1) ∧    (∀ θ : ℝ, 1 / ((a : ℝ) + 1) ≤ θ → θ ≤ 1 / (a : ℝ) →      primaryPhase a θ = (a : ℝ) + 1 - (a : ℝ) * ((a : ℝ) + 1) * θ) := by  have ha0 : (0 : ℝ) < a := by exact_mod_cast (by omega : 0 < a)  have hbound : ∀ θ : ℝ, 0 < θ → θ ≤ 1 / (a : ℝ) → ∀ b : ℕ, 1 ≤ b →      0 ≤ ambLength a b θ - (b : ℝ) * primaryPhase a θ ∧      ambLength a b θ - (b : ℝ) * primaryPhase a θ ≤ 12 * (a : ℝ) + 11 := by    intro θ hθ0 hθ b hb    exact ⟨sub_nonneg.2 (lower_bound a b ha hb θ hθ0),      sub_le_iff_le_add'.2 (ambLength_le_primaryPhase a b ha θ hθ0 hθ)⟩  have hunif : ∃ K : ℝ, ∀ θ : ℝ, 0 < θ → θ ≤ 1 / (a : ℝ) → ∀ b : ℕ, 1 ≤ b →      |ambProportion a b θ - primaryPhase a θ| ≤ K / (b : ℝ) := by    refine ⟨12 * (a : ℝ) + 11 + 2, fun θ hθ0 hθ b hb => ?_⟩    have haθ : (a : ℝ) * θ ≤ 1 := CaballeroMarker.aθ_le (by omega) hθ    have hb0 : (0 : ℝ) < b := by exact_mod_cast hb    have hD : (b : ℝ) ≤ (b : ℝ) + a * θ := by      have : 0 ≤ (a : ℝ) * θ := by positivity      linarith    have hD0 : 0 < (b : ℝ) + a * θ := lt_of_lt_of_le hb0 hD    have hU0 := primaryPhase_nonneg a θ    have hU2 : primaryPhase a θ ≤ 2 := by      have h1 := lower_bound a 1 ha le_rfl θ hθ0      have h2 := ambLength_le a 1 θ hθ0.le      push_cast at h1 h2      linarith    obtain ⟨hl, hu⟩ := hbound θ hθ0 hθ b hb    have haU : (a : ℝ) * θ * primaryPhase a θ ≤ 2 := by      have : (a : ℝ) * θ * primaryPhase a θ ≤ 1 * 2 :=        mul_le_mul haθ hU2 hU0 (by norm_num)      linarith    have haU0 : 0 ≤ (a : ℝ) * θ * primaryPhase a θ := by positivity    have key : ambProportion a b θ - primaryPhase a θ        = (ambLength a b θ - (b : ℝ) * primaryPhase a θ - (a : ℝ) * θ * primaryPhase a θ) /          ((b : ℝ) + a * θ) := by      unfold ambProportion      field_simp      ring    rw [key, abs_div, abs_of_pos hD0]    have hnum : |ambLength a b θ - (b : ℝ) * primaryPhase a θ - (a : ℝ) * θ * primaryPhase a θ|        ≤ 12 * (a : ℝ) + 11 + 2 := by      rw [abs_le]      constructor <;> nlinarith [sq_nonneg (a : ℝ)]    calc _ ≤ (12 * (a : ℝ) + 11 + 2) / ((b : ℝ) + a * θ) := by gcongr      _ ≤ _ := by gcongr  refine ⟨hbound, ?_, hunif, ?_, ?_, ?_⟩  · intro θ hθ0 hθ    obtain ⟨K, hK⟩ := hunif    have h0 : Tendsto (fun b : ℕ => ambProportion a b θ - primaryPhase a θ) atTop (𝓝 0) := by      refine squeeze_zero_norm' ?_ (tendsto_const_div_atTop_nhds_zero_nat K)      filter_upwards [eventually_ge_atTop 1] with b hb      exact hK θ hθ0 hθ b hb    exact tendsto_sub_nhds_zero_iff.1 h0  · intro θ hθ0 hθ    exact primaryPhase_first a ha θ hθ0 hθ  · intro θ h0 h1    exact primaryPhase_second a ha θ h0 h1  · intro θ h0 h1    exact primaryPhase_third a ha θ h0 h1 end CaballeroPrimaryPhase