🏛️ Atlas✒️Formalizations.Combinatorics.Caballero.AngularPhaseLemma view on GitHub ↗8 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)-//-Modelo solicitado gpt-6.2-sol, esfuerzo medium. Valores efectivos no expuestos.Superficie: agente Codex. Tarea: formalizar el enunciado completo de `lem:phases`.Resultado: prueba del enunciado auditado, huella 18c2da924d73690e.Alcance: funciones de fase reales, puntos de quiebre y valores generadores.-/module public import Formalizations.Combinatorics.Caballero.AngularPhase2public import Formalizations.Combinatorics.Caballero.AngularPhaseTablepublic import Mathlib.Tactic.LinearCombination /-!# AngularPhaseLemma-/ /-!## 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 CaballeroPhaseLemma open CaballeroFase2 /-- A function is locally affine at `θ` if a single affine formula holds on an openinterval around `θ`. This uses both sides, including at the support endpoints. -/def AffineNear (f : ℝ → ℝ) (θ : ℝ) : Prop :=  ∃ (ε a c : ℝ), 0 < ε ∧ ∀ x ∈ Set.Ioo (θ - ε) (θ + ε), f x = a * x + c private theorem affineNear_of_row {f : ℝ → ℝ} {l θ r c a : ℝ}    (hl : l < θ) (hr : θ < r)    (hrow : ∀ x ∈ Set.Icc l r, f x = c + a * x) : AffineNear f θ := by  refine ⟨min (θ - l) (r - θ), a, c, lt_min (sub_pos.mpr hl) (sub_pos.mpr hr), ?_⟩  intro x hx  have hlo := min_le_left (θ - l) (r - θ)  have hhi := min_le_right (θ - l) (r - θ)  rw [hrow x ⟨by linarith [hx.1], by linarith [hx.2]⟩, add_comm] private theorem not_affineNear_of_slopes {f : ℝ → ℝ} {l θ r cl al cr ar : ℝ}    (hl : l < θ) (hr : θ < r)    (hleft : ∀ x ∈ Set.Icc l θ, f x = cl + al * x)    (hright : ∀ x ∈ Set.Icc θ r, f x = cr + ar * x)    (hne : al ≠ ar) : ¬ AffineNear f θ := by  rintro ⟨ε, a, c, hε, ha⟩  let d := min ε (min (θ - l) (r - θ)) / 2  have hd : 0 < d := half_pos (lt_min hε (lt_min (sub_pos.mpr hl) (sub_pos.mpr hr)))  have hdε : d < ε := by    have h := min_le_left ε (min (θ - l) (r - θ))    dsimp [d]    linarith  have hdl : d ≤ θ - l := by    have h := le_trans (min_le_right ε _) (min_le_left (θ - l) (r - θ))    dsimp [d]    linarith  have hdr : d ≤ r - θ := by    have h := le_trans (min_le_right ε _) (min_le_right (θ - l) (r - θ))    dsimp [d]    linarith  have ha0 := ha θ ⟨by linarith, by linarith⟩  have hal := ha (θ - d) ⟨by linarith, by linarith⟩  have har := ha (θ + d) ⟨by linarith, by linarith⟩  have hl0 := hleft θ ⟨hl.le, le_rfl⟩  have hll := hleft (θ - d) ⟨by linarith, by linarith⟩  have hr0 := hright θ ⟨le_rfl, hr.le⟩  have hrr := hright (θ + d) ⟨by linarith, by linarith⟩  have hal' : (a - al) * d = 0 := by    linear_combination hal - ha0 + hl0 - hll  have har' : (a - ar) * d = 0 := by    linear_combination ha0 - har + hrr - hr0  have hsl := sub_eq_zero.mp ((mul_eq_zero.mp hal').resolve_right hd.ne')  have hsr := sub_eq_zero.mp ((mul_eq_zero.mp har').resolve_right hd.ne')  exact hne (hsl.symm.trans hsr) private theorem phaseOne_eq (θ : ℝ) : Ufase 1 θ = CaballeroPhaseTable.Ufase1 θ :=  Ufase_1_eq θ private theorem phaseTwo_eq (θ : ℝ) : Ufase 2 θ = CaballeroPhaseTable.Ufase2 θ :=  Ufase_2_eq θ private theorem phase_zero_left (θ : ℝ) (h : θ ≤ 0) :    Ufase 1 θ = 0 + 0 * θ ∧ Ufase 2 θ = 0 + 0 * θ := by  rw [phaseOne_eq, phaseTwo_eq]  exact CaballeroPhaseTable.fases_tramo0 θ h private theorem phases_affineNear_of_row {l θ r c₁ a₁ c₂ a₂ : ℝ}    (h : ∀ t, l ≤ t → t ≤ r → Ufase 1 t = c₁ + a₁ * t ∧ Ufase 2 t = c₂ + a₂ * t)    (hl : l < θ) (hr : θ < r) : AffineNear (Ufase 1) θ ∧ AffineNear (Ufase 2) θ :=  ⟨affineNear_of_row hl hr (fun t ht => (h t ht.1 ht.2).1),   affineNear_of_row hl hr (fun t ht => (h t ht.1 ht.2).2)⟩ private theorem phase_breakpoints :    {θ : ℝ | θ ∈ Set.Icc 0 1 ∧      (¬ AffineNear (Ufase 1) θ ∨ ¬ AffineNear (Ufase 2) θ)} = Set.range farey4 := by  ext θ  change (θ ∈ Set.Icc 0 1 ∧    (¬ AffineNear (Ufase 1) θ ∨ ¬ AffineNear (Ufase 2) θ)) ↔ θ ∈ Set.range farey4  constructor  · rintro ⟨⟨h0, h1⟩, h⟩    have incompatible {l r c₁ a₁ c₂ a₂ : ℝ}        (row : ∀ t, l ≤ t → t ≤ r → Ufase 1 t = c₁ + a₁ * t ∧ Ufase 2 t = c₂ + a₂ * t)        (hl : l < θ) (hr : θ < r) : False := by      obtain ⟨ha, hb⟩ := phases_affineNear_of_row row hl hr      exact h.elim (fun h => h ha) (fun h => h hb)    rcases h0.eq_or_lt with h0 | h0    · exact ⟨0, h0⟩    rcases lt_trichotomy θ (1 / 4) with h14 | h14 | h14    · exact (incompatible Ufase_tramo1 h0 h14).elim    · exact ⟨1, h14.symm⟩    rcases lt_trichotomy θ (1 / 3) with h13 | h13 | h13    · exact (incompatible Ufase_tramo2 h14 h13).elim    · exact ⟨2, h13.symm⟩    rcases lt_trichotomy θ (1 / 2) with h12 | h12 | h12    · exact (incompatible Ufase_tramo3 h13 h12).elim    · exact ⟨3, h12.symm⟩    rcases lt_trichotomy θ (2 / 3) with h23 | h23 | h23    · exact (incompatible Ufase_tramo4 h12 h23).elim    · exact ⟨4, h23.symm⟩    rcases lt_trichotomy θ (3 / 4) with h34 | h34 | h34    · exact (incompatible Ufase_tramo5 h23 h34).elim    · exact ⟨5, h34.symm⟩    rcases h1.eq_or_lt with h1 | h1    · exact ⟨6, h1.symm⟩    · exact (incompatible Ufase_tramo6 h34 h1).elim  · rintro ⟨i, rfl⟩    have includePoint (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1)        (hb : ¬ AffineNear (Ufase 1) x ∨ ¬ AffineNear (Ufase 2) x) :        x ∈ Set.Icc 0 1 ∧ (¬ AffineNear (Ufase 1) x ∨ ¬ AffineNear (Ufase 2) x) :=      ⟨⟨h0, h1⟩, hb⟩    fin_cases i    · refine includePoint 0 (by norm_num) (by norm_num) (Or.inl ?_)      exact not_affineNear_of_slopes (l := -1) (r := 1 / 4)        (by norm_num) (by norm_num) (fun t ht => (phase_zero_left t ht.2).1)        (fun t ht => (Ufase_tramo1 t ht.1 ht.2).1) (by norm_num)    · refine includePoint (1 / 4) (by norm_num) (by norm_num) (Or.inl ?_)      exact not_affineNear_of_slopes (l := 0) (r := 1 / 3)        (by norm_num) (by norm_num) (fun t ht => (Ufase_tramo1 t ht.1 ht.2).1)        (fun t ht => (Ufase_tramo2 t ht.1 ht.2).1) (by norm_num)    · refine includePoint (1 / 3) (by norm_num) (by norm_num) (Or.inl ?_)      exact not_affineNear_of_slopes (l := 1 / 4) (r := 1 / 2)        (by norm_num) (by norm_num) (fun t ht => (Ufase_tramo2 t ht.1 ht.2).1)        (fun t ht => (Ufase_tramo3 t ht.1 ht.2).1) (by norm_num)    · refine includePoint (1 / 2) (by norm_num) (by norm_num) (Or.inl ?_)      exact not_affineNear_of_slopes (l := 1 / 3) (r := 2 / 3)        (by norm_num) (by norm_num) (fun t ht => (Ufase_tramo3 t ht.1 ht.2).1)        (fun t ht => (Ufase_tramo4 t ht.1 ht.2).1) (by norm_num)    · refine includePoint (2 / 3) (by norm_num) (by norm_num) (Or.inr ?_)      exact not_affineNear_of_slopes (l := 1 / 2) (r := 3 / 4)        (by norm_num) (by norm_num) (fun t ht => (Ufase_tramo4 t ht.1 ht.2).2)        (fun t ht => (Ufase_tramo5 t ht.1 ht.2).2) (by norm_num)    · refine includePoint (3 / 4) (by norm_num) (by norm_num) (Or.inr ?_)      exact not_affineNear_of_slopes (l := 2 / 3) (r := 1)        (by norm_num) (by norm_num) (fun t ht => (Ufase_tramo5 t ht.1 ht.2).2)        (fun t ht => (Ufase_tramo6 t ht.1 ht.2).2) (by norm_num)    · refine includePoint 1 (by norm_num) (by norm_num) (Or.inr ?_)      exact not_affineNear_of_slopes (l := 3 / 4) (r := 2)        (by norm_num) (by norm_num) (fun t ht => (Ufase_tramo6 t ht.1 ht.2).2)        (fun t ht => (Ufase_tramo7 t ht.1).2) (by norm_num) /-- Paper III, `lem:phases`, with `Ufase` and `farey4` as defined in `AngularPhase2`. -/theorem phases :    Continuous (Ufase 1) ∧ Continuous (Ufase 2) ∧    (∀ θ : ℝ, θ ∉ Set.Icc 0 1 → Ufase 1 θ = 0 ∧ Ufase 2 θ = 0) ∧    (∀ θ : ℝ, Ufase 2 θ = Ufase 1 (1 - θ)) ∧    (∀ θ ∈ Set.Icc (0 : ℝ) (1 / 4), Ufase 1 θ = 2 * θ) ∧    (∀ θ ∈ Set.Icc (1 / 4 : ℝ) (1 / 3), Ufase 1 θ = 6 * θ - 1) ∧    (∀ θ ∈ Set.Icc (1 / 3 : ℝ) (1 / 2), Ufase 1 θ = 3 - 6 * θ) ∧    (∀ θ ∈ Set.Icc (1 / 2 : ℝ) 1, Ufase 1 θ = 0) ∧    {θ : ℝ | θ ∈ Set.Icc 0 1 ∧      (¬ AffineNear (Ufase 1) θ ∨ ¬ AffineNear (Ufase 2) θ)} = Set.range farey4 ∧    Ufase 1 (1 / 3) = 1 ∧ Ufase 2 (2 / 3) = 1 ∧    Ufase 1 (2 / 3) = 0 ∧ Ufase 2 (1 / 3) = 0 := by  have he1 : Ufase 1 = CaballeroPhaseTable.Ufase1 := funext phaseOne_eq  have he2 : Ufase 2 = CaballeroPhaseTable.Ufase2 := funext phaseTwo_eq  refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, phase_breakpoints, ?_, ?_, ?_, ?_⟩  · rw [he1]; exact CaballeroPhaseTable.fases_continuas.1  · rw [he2]; exact CaballeroPhaseTable.fases_continuas.2  · intro θ h    by_cases h0 : θ ≤ 0    · simpa using phase_zero_left θ h0    · have h1 : 1 ≤ θ := by        by_contra ht        exact h ⟨(lt_of_not_ge h0).le, (lt_of_not_ge ht).le⟩      simpa using Ufase_tramo7 θ h1  · intro θ    rw [phaseTwo_eq, phaseOne_eq]    exact CaballeroPhaseTable.fases_reflejo θ  · intro θ h    simpa using (Ufase_tramo1 θ h.1 h.2).1  · intro θ h    rw [(Ufase_tramo2 θ h.1 h.2).1]; ring  · intro θ h    rw [(Ufase_tramo3 θ h.1 h.2).1]; ring  · intro θ h    rcases le_total θ (2 / 3) with h23 | h23    · simpa using (Ufase_tramo4 θ h.1 h23).1    rcases le_total θ (3 / 4) with h34 | h34    · simpa using (Ufase_tramo5 θ h23 h34).1    · simpa using (Ufase_tramo6 θ h34 h.2).1  · rw [(Ufase_tramo2 (1 / 3) (by norm_num) le_rfl).1]; norm_num  · rw [(Ufase_tramo4 (2 / 3) (by norm_num) le_rfl).2]; norm_num  · simpa using (Ufase_tramo4 (2 / 3) (by norm_num) le_rfl).1  · simpa using (Ufase_tramo2 (1 / 3) (by norm_num) le_rfl).2  end CaballeroPhaseLemma