🏛️ Atlas✒️Formalizations.Combinatorics.Caballero.AngularStepPartition view on GitHub ↗5 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)-//-# encaje: geometría del paso tres del Paper III, obligación 1 deGEOMETRIA_TEOR_A_CONTRATO.md. Reutiliza los intervalos y las traslaciones de Mathlib.Modelo solicitado gpt-6.2-astra, esfuerzo max. Valores efectivos no expuestos. Superficie: agente Codex.Tarea: partición de las dos secciones y traslación con inversa de las cuatro regiones.Resultado: las particiones son exactas como conjuntos y las cuatro imágenes tienen inversa por resta.Alcance: todos los enteros naturales b y todas las pendientes no negativas para la partición.-/module public import Mathlib.Algebra.Order.Archimedean.Real.Basicpublic import Mathlib.Algebra.Order.Interval.Set.Monoidpublic import Mathlib.Data.Fintype.Basicpublic import Mathlib.Order.Fin.Basicpublic import Mathlib.Order.Interval.Set.Unionpublic import Mathlib.Tactic.FinCasespublic import Mathlib.Tactic.Linarithpublic import Mathlib.Tactic.NormNum /-!# AngularStepPartition-/ /-!## 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 CaballeroStepPartition open Set /-- Integer cuts in the old section, using natural division before coercion to the reals. -/def j1 (b : ℕ) : ℕ := b / 6def j2 (b : ℕ) : ℕ := b / 2def j3 (b : ℕ) : ℕ := (5 * b) / 6 /-- The right endpoint of the old section. -/noncomputable def sectionEnd (b : ℕ) (θ : ℝ) : ℝ := (b : ℝ) + 2 * θ /-- Boundaries of the four original intervals, with the last boundary repeated beyond index 4. -/noncomputable def oldCut (b : ℕ) (θ : ℝ) : ℕ → ℝ  | 0 => 0  | 1 => j1 b  | 2 => j2 b  | 3 => j3 b  | _ => sectionEnd b θ /-- Boundaries in the new section. The three gaps alternate with the four translated intervals. -/noncomputable def newCut (b : ℕ) (θ : ℝ) : ℕ → ℝ  | 0 => 0  | 1 => j1 b  | 2 => (j1 b : ℝ) + 1  | 3 => (j2 b : ℝ) + 1  | 4 => (j2 b : ℝ) + 2  | 5 => (j3 b : ℝ) + 2  | 6 => (j3 b : ℝ) + 3  | _ => sectionEnd b θ + 3 /-- Region `i` of the original section. -/noncomputable def oldRegion (b : ℕ) (θ : ℝ) (i : Fin 4) : Set ℝ :=  Ico (oldCut b θ i.val) (oldCut b θ (i.val + 1)) /-- Piece `i` of the new section, ordered from left to right. -/noncomputable def piece (b : ℕ) (θ : ℝ) (i : Fin 7) : Set ℝ :=  Ico (newCut b θ i.val) (newCut b θ (i.val + 1)) /-- The new index of an old region: `0, 2, 4, 6`. -/def imageIndex (i : Fin 4) : Fin 7 := ⟨2 * i.val, by omega⟩ private theorem consecutive_partition (f : ℕ → ℝ) (n : ℕ) (hf : Monotone f) :    Ico (f 0) (f n) = (⋃ i : Fin n, Ico (f i.val) (f (i.val + 1))) ∧    Pairwise (fun i j : Fin n => Disjoint (Ico (f i.val) (f (i.val + 1)))      (Ico (f j.val) (f (j.val + 1)))) := by  constructor  · apply Set.Subset.antisymm    · intro x hx      obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (Ico_subset_biUnion_Ico n f hx)      obtain ⟨hin, hcell⟩ := Set.mem_iUnion.mp hi      exact Set.mem_iUnion.mpr ⟨⟨i, Finset.mem_range.mp hin⟩, hcell⟩    · intro x hx      obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx      exact ⟨(hf (Nat.zero_le i.val)).trans hi.1,        hi.2.trans_le (hf (Nat.succ_le_of_lt i.isLt))⟩  · intro i j hne    apply Set.disjoint_left.mpr    intro x hi hj    rcases lt_or_gt_of_ne hne with hij | hji    · have hcut : f (i.val + 1) ≤ f j.val := hf (Nat.succ_le_of_lt hij)      exact (not_lt_of_ge (hcut.trans hj.1)) hi.2    · have hcut : f (j.val + 1) ≤ f i.val := hf (Nat.succ_le_of_lt hji)      exact (not_lt_of_ge (hcut.trans hi.1)) hj.2 private theorem cuts_monotone (b : ℕ) (θ : ℝ) (hθ : 0 ≤ θ) :    Monotone (oldCut b θ) ∧ Monotone (newCut b θ) := by  have h01 : (0 : ℝ) ≤ j1 b := Nat.cast_nonneg _  have h12n : j1 b ≤ j2 b := by unfold j1 j2; omega  have h23n : j2 b ≤ j3 b := by unfold j2 j3; omega  have h3n : j3 b ≤ b := by unfold j3; omega  have h12 : (j1 b : ℝ) ≤ j2 b := by exact_mod_cast h12n  have h23 : (j2 b : ℝ) ≤ j3 b := by exact_mod_cast h23n  have h3 : (j3 b : ℝ) ≤ b := by exact_mod_cast h3n  have h3end : (j3 b : ℝ) ≤ sectionEnd b θ := by unfold sectionEnd; linarith  constructor  · apply monotone_nat_of_le_succ    intro i    match i with    | 0 => exact h01    | 1 => exact h12    | 2 => exact h23    | 3 => exact h3end    | _ + 4 => exact le_rfl  · apply monotone_nat_of_le_succ    intro i    match i with    | 0 => exact h01    | 1 => change (j1 b : ℝ) ≤ j1 b + 1; linarith    | 2 => change (j1 b : ℝ) + 1 ≤ (j2 b : ℝ) + 1; linarith    | 3 => change (j2 b : ℝ) + 1 ≤ j2 b + 2; linarith    | 4 => change (j2 b : ℝ) + 2 ≤ (j3 b : ℝ) + 2; linarith    | 5 => change (j3 b : ℝ) + 2 ≤ j3 b + 3; linarith    | 6 => change (j3 b : ℝ) + 3 ≤ sectionEnd b θ + 3; linarith    | _ + 7 => exact le_rfl /-- The four old regions cover the section and are pairwise disjoint. -/theorem old_partition (b : ℕ) (θ : ℝ) (hθ : 0 ≤ θ) :    Ico 0 (sectionEnd b θ) = (⋃ i : Fin 4, oldRegion b θ i) ∧    Pairwise (fun i j : Fin 4 => Disjoint (oldRegion b θ i) (oldRegion b θ j)) :=  consecutive_partition (oldCut b θ) 4 (cuts_monotone b θ hθ).1 /-- The enlarged section is the disjoint union of the seven displayed half-open pieces. -/theorem new_partition (b : ℕ) (θ : ℝ) (hθ : 0 ≤ θ) :    Ico 0 (sectionEnd (b + 3) θ) = (⋃ i : Fin 7, piece b θ i) ∧    Pairwise (fun i j : Fin 7 => Disjoint (piece b θ i) (piece b θ j)) := by  have end_eq : sectionEnd (b + 3) θ = sectionEnd b θ + 3 := by    unfold sectionEnd    push_cast    ring  rw [end_eq]  exact consecutive_partition (newCut b θ) 7 (cuts_monotone b θ hθ).2 /-- Translation by `i` carries the old region onto its new piece, with inverse subtraction by `i`. -/theorem region_translation (b : ℕ) (θ : ℝ) (i : Fin 4) :    (fun x : ℝ => x + (i.val : ℝ)) '' oldRegion b θ i = piece b θ (imageIndex i) ∧    (fun y : ℝ => y - (i.val : ℝ)) '' piece b θ (imageIndex i) = oldRegion b θ i := by  have he : piece b θ (imageIndex i) =      Ico (oldCut b θ i.val + i.val) (oldCut b θ (i.val + 1) + i.val) := by    fin_cases i <;> norm_num [piece, imageIndex, oldCut, newCut]  rw [he]  constructor  · exact Set.image_add_const_Ico _ _ _  · simp only [oldRegion, sub_eq_add_neg, Set.image_add_const_Ico]    congr 1 <;> ring -- At b = 66 the first cut is 11. Closing the first piece on its right would count 11 twice.example : (11 : ℝ) ∉ piece 66 1 0 ∧ (11 : ℝ) ∈ piece 66 1 1 := by  norm_num [piece, newCut, j1, Set.mem_Ico] -- Shifting region 1 by zero misses its target. The correct shift sends 11 to 12.example : (11 : ℝ) ∈ oldRegion 66 1 1 ∧ (11 : ℝ) ∉ piece 66 1 2 ∧    (12 : ℝ) ∈ piece 66 1 2 := by  norm_num [oldRegion, oldCut, piece, newCut, j1, j2, Set.mem_Ico]  end CaballeroStepPartition