/-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)-//-# encaje: geometría del paso tres del Paper III, obligación 4 deGEOMETRIA_TEOR_A_CONTRATO.md. Reutiliza CaballeroPeaks.Palabra y la medida de Mathlib.Modelo y esfuerzo efectivos: no expuestos por la interfaz. Superficie: agente Codex.Tarea: identificar el intervalo de fases de una quinteta y su medida de Lebesgue.Resultado: igualdad exacta de conjuntos y longitud igual a la anchura del manuscrito.Alcance: una quinteta arbitraria de suelos, para toda pendiente real.-/module public import Formalizations.Combinatorics.Caballero.AngularPeaks /-!# AngularPhaseFiber-/ /-!## References * C. Marín, Exact angular ambiguity profile for Dyck words of divisors (Part III), Zenodo (2026), doi:10.5281/zenodo.24699411.* 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 CaballeroPhaseFiber open CaballeroPeaks MeasureTheory Set /-- The five floors on the unit of phase at slope `θ`, in order `h = -2, …, 2`. -/noncomputable def rawWord (θ u : ℝ) : Palabra := (⌊u - 2 * θ⌋, ⌊u - θ⌋, ⌊u⌋, ⌊u + θ⌋, ⌊u + 2 * θ⌋) /-- The phases in `[0,1)` producing the prescribed word. -/noncomputable def phaseFiber (θ : ℝ) (k : Palabra) : Set ℝ := {u | u ∈ Ico 0 1 ∧ rawWord θ u = k} /-- Greatest lower bound imposed by the five floors and the left endpoint of the unit. -/noncomputable def phaseLower (k : Palabra) (θ : ℝ) : ℝ := let (a, b, c, d, e) := k max 0 (max ((a : ℝ) + 2 * θ) (max ((b : ℝ) + θ) (max (c : ℝ) (max ((d : ℝ) - θ) ((e : ℝ) - 2 * θ))))) /-- Least of the six strict upper bounds for the phases. -/noncomputable def phaseUpper (k : Palabra) (θ : ℝ) : ℝ := let (a, b, c, d, e) := k min 1 (min ((a : ℝ) + 1 + 2 * θ) (min ((b : ℝ) + 1 + θ) (min ((c : ℝ) + 1) (min ((d : ℝ) + 1 - θ) ((e : ℝ) + 1 - 2 * θ))))) /-- The manuscript's phase width `w_k(θ)`, including the empty-fibre case. -/noncomputable def phaseWidth (k : Palabra) (θ : ℝ) : ℝ := max 0 (phaseUpper k θ - phaseLower k θ) /-- The left endpoint belongs to the fibre whenever the interval has positive length. -/theorem phaseFiber_eq_Ico (θ : ℝ) (k : Palabra) : phaseFiber θ k = Ico (phaseLower k θ) (phaseUpper k θ) := by rcases k with ⟨a, b, c, d, e⟩ ext u simp only [phaseFiber, Set.mem_ofPred_eq, Set.mem_Ico, rawWord, Prod.mk.injEq, Int.floor_eq_iff, phaseLower, phaseUpper, max_le_iff, lt_min_iff] constructor · rintro ⟨⟨hu₀, hu₁⟩, ⟨ha₀, ha₁⟩, ⟨hb₀, hb₁⟩, ⟨hc₀, hc₁⟩, ⟨hd₀, hd₁⟩, he₀, he₁⟩ repeat' apply And.intro all_goals linarith · rintro ⟨⟨hu₀, ha₀, hb₀, hc₀, hd₀, he₀⟩, hu₁, ha₁, hb₁, hc₁, hd₁, he₁⟩ repeat' apply And.intro all_goals linarith /-- Equation for `w_k` immediately before the definition of `U_m` in Part III. -/theorem volume_phase_fiber (θ : ℝ) (k : Palabra) : volume.real (phaseFiber θ k) = phaseWidth k θ := by rw [phaseFiber_eq_Ico, Real.volume_real_Ico, phaseWidth] exact max_comm _ _ -- At slope zero the zero word fills the entire half-open unit.example : volume.real (phaseFiber 0 (0, 0, 0, 0, 0)) = 1 := by rw [volume_phase_fiber] norm_num [phaseWidth, phaseLower, phaseUpper] -- Replacing the right-open interval by its closure changes the fibre as a set.example : phaseFiber 0 (0, 0, 0, 0, 0) ≠ Icc (0 : ℝ) 1 := by intro h have hu : (1 : ℝ) ∈ phaseFiber 0 (0, 0, 0, 0, 0) := by rw [h] exact ⟨zero_le_one, le_rfl⟩ exact (lt_irrefl (1 : ℝ)) hu.1.2 -- Incompatible floors have length zero although the signed difference is negative.example : let k : Palabra := (1, -1, 0, 0, 0) volume.real (phaseFiber 0 k) = 0 ∧ volume.real (phaseFiber 0 k) ≠ phaseUpper k 0 - phaseLower k 0 := by dsimp only rw [volume_phase_fiber] norm_num [phaseWidth, phaseLower, phaseUpper] end CaballeroPhaseFiber