/-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.AngularExactpublic import Mathlib.Algebra.Order.Floor.Ringpublic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic /-!# The unambiguous diagonal section theta = 1 (Caballero, a = 2) For every b >= 3, conditional on the classification of Part I at b: on the line theta = 1 the cellword of every Lambda >= 0 is Dg b (floor Lambda), which is never in the list of Lemma 9.3 of Part I;hence no cell of the section is ambiguous and the ambiguous section length is exactly 0. The cases b= 1, 2 are proved unconditionally by a finite kernel check over nondecreasing vectors in [-b-1,b]^5, with ambiguity defined from the Dyck-word key of the supplement; the final theorem diagonalcovers every b >= 1. ## Main results * `CaballeroDiagonal.diagonal`: for every b >= 1 (Part I classification assumed only for b >= 3), with Ambig defined from the Dyck word Zw of the supplement: no cell of the section theta = 1 is ambiguous and secLen Ambig b 1 = 0* `CaballeroDiagonal.diagonal_pequena`: for b = 1, 2, unconditionally: no cell word of the section theta = 1 is Ambig (finite kernel check, decide +kernel)* `CaballeroDiagonal.diagonal_completa`: for b >= 3 under the classification of Part I, no cell of the section theta = 1 is ambiguous and secLen Amb b 1 = 0* `CaballeroDiagonal.cellWord_diag`: on theta = 1 the cell word of Lambda is Dg b (floor Lambda)* `CaballeroDiagonal.ambig_realisable`: control, Ambig b w implies Realisable b w (Ambig is literally A_{2,b} of the paper)* `CaballeroDiagonal.oldAmbig_insatisfacible`: control, with the earlier Ambig (w not required realizable) the classification hypothesis is false at b = 3 ## 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 CaballeroDiagonal open CaballeroPeaks CaballeroExact MeasureTheory /-- On the diagonal `θ = 1` the cell word of `Λ` is the word of the integer cell `⌊Λ⌋`. -/theorem cellWord_diag (b : ℤ) (Λ : ℝ) : cellWord b Λ 1 = Dg b ⌊Λ⌋ := by have e : ∀ h : ℤ, ⌊Λ + ((h : ℤ) : ℝ) * 1⌋ = ⌊Λ⌋ + h := fun h => by rw [mul_one, Int.floor_add_intCast] unfold cellWord rw [e (-2), e (-1), e 0, e 1, e 2] simp [Dg, sub_eq_add_neg] /-- Beyond the last diagonal cell the clipped word is constant. -/theorem Dg_top (b j : ℤ) (hb : 0 ≤ b) (hj : b + 2 ≤ j) : Dg b j = (b, b, b, b, b) := by simp only [Dg, clip, Prod.mk.injEq] omega /-- Part III, Theorem `thm:diagonal` (`b ≥ 3`, conditional on the classification ofPart I at `b`): no cell of the section `θ = 1` is ambiguous, and the ambiguous sectionlength vanishes exactly. -/theorem diagonal_completa (Amb : ℤ → Palabra → Prop) (b : ℕ) (hb : 3 ≤ b) (hcl : ∀ w, Amb (b : ℤ) w ↔ enLista (b : ℤ) w) : (∀ Λ : ℝ, 0 ≤ Λ → ¬ Amb (b : ℤ) (cellWord (b : ℤ) Λ 1)) ∧ secLen Amb b 1 = 0 := by have h1 : ∀ Λ : ℝ, 0 ≤ Λ → ¬ Amb (b : ℤ) (cellWord (b : ℤ) Λ 1) := by intro Λ hΛ hA rw [cellWord_diag, hcl] at hA have hj : 0 ≤ ⌊Λ⌋ := Int.floor_nonneg.mpr hΛ by_cases hj1 : ⌊Λ⌋ ≤ (b : ℤ) + 1 · exact diagonal_fuera b ⌊Λ⌋ (by omega) hj hj1 hA · rw [Dg_top _ _ (by omega) (by omega)] at hA exact diagonal_superior_fuera b (by omega) hA refine ⟨h1, ?_⟩ have hvac : {Λ : ℝ | 0 ≤ Λ ∧ Λ ≤ (b : ℝ) + 2 * 1 ∧ Amb (b : ℤ) (cellWord (b : ℤ) Λ 1)} = ∅ := by ext Λ simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false] rintro ⟨h0, -, hA⟩ exact h1 Λ h0 hA unfold secLen rw [hvac, measure_empty, ENNReal.toReal_zero] /-! ### The Dyck word of a cell vector and ambiguity, for every `b ≥ 1` -/ /-- Clipping to `[0, b+1]` (the `np.clip(·, 0, b+1)` of `clave`). -/def clip0 (b v : ℤ) : ℤ := min (b + 1) (max 0 v) /-- Coordinate `c_h` of `c = (c₋₂, c₋₁, c₀, c₁, c₂)`, `h ∈ {-2, …, 2}`. -/def coord (c : Palabra) (h : ℤ) : ℤ := if h = -2 then c.1 else if h = -1 then c.2.1 else if h = 0 then c.2.2.1 else if h = 1 then c.2.2.2.1 else c.2.2.2.2 /-- `H_i(j) = Σ_{l=0}^{2} clip₀(j + c_{i-l} + 1)`. -/def Hv (b : ℤ) (c : Palabra) (i j : ℤ) : ℤ := clip0 b (j + coord c (i - 0) + 1) + clip0 b (j + coord c (i - 1) + 1) + clip0 b (j + coord c (i - 2) + 1) /-- The Dyck-word key of the cell vector `c` (`a = 2`): the multiset of the values `H_i(j)`,`i = 0, 1, 2`, `j = 0, …, b`. Literal transcription of `clave(a, b, c)` in the supplement(`research/caballero-parentesis/fila_a_c.py:36`, Part I): `clave` sorts the concatenation, i.e.it encodes exactly this multiset. -/def Zw (b : ℤ) (c : Palabra) : Multiset ℤ := (((List.range 3).flatMap fun i : ℕ => (List.range (b.toNat + 1)).map fun j : ℕ => Hv b c (i : ℤ) (j : ℤ)) : List ℤ) /-- Realisability: `w` is the cell word of some cell of the open quadrant `Λ > 0`, `θ > 0`(the set `C_{2,b}` of the paper). -/def Realisable (b : ℤ) (w : Palabra) : Prop := ∃ Λ θ : ℝ, 0 < Λ ∧ 0 < θ ∧ cellWord b Λ θ = w /-- Ambiguity, literally `A_{2,b} = {c ∈ C_{2,b} : ∃ d ∈ C_{2,b}, d ≠ c, Z(d) = Z(c)}` of thepaper: `w` itself is realizable (`Λ > 0`, `θ > 0`, the open quadrant of Part I) and some otherrealizable cell vector has the same Dyck word. -/def Ambig (b : ℤ) (w : Palabra) : Prop := Realisable b w ∧ ∃ Λ' θ' : ℝ, 0 < Λ' ∧ 0 < θ' ∧ cellWord b Λ' θ' ≠ w ∧ Zw b (cellWord b Λ' θ') = Zw b w /-- Integer interval `[lo, hi]` as a list. -/def rng (lo hi : ℤ) : List ℤ := (List.range (hi - lo + 1).toNat).map fun k : ℕ => lo + (k : ℤ) theorem mem_rng {lo hi x : ℤ} (h0 : lo ≤ x) (h1 : x ≤ hi) : x ∈ rng lo hi := by simp only [rng, List.mem_map, List.mem_range] exact ⟨(x - lo).toNat, by omega, by omega⟩ /-- Finite check: among nondecreasing vectors in `[-b-1, b]^5`, the diagonal words aredetermined by their Dyck word. -/def Chk (b : ℤ) : Prop := ∀ x0 ∈ rng (-b - 1) b, ∀ x1 ∈ rng x0 b, ∀ x2 ∈ rng x1 b, ∀ x3 ∈ rng x2 b, ∀ x4 ∈ rng x3 b, ∀ j ∈ rng 0 (b + 2), Zw b (x0, x1, x2, x3, x4) = Zw b (Dg b j) → (x0, x1, x2, x3, x4) = Dg b j theorem chk1 : Chk 1 := by unfold Chk; decide +kernel theorem chk2 : Chk 2 := by unfold Chk; decide +kernel theorem clip_mono (b v w : ℤ) (h : v ≤ w) : clip b v ≤ clip b w := by unfold clip; omega /-- For `θ > 0` the cell word is nondecreasing and lies in `[-b-1, b]^5`. -/theorem cellWord_mono (b : ℤ) (hb : 0 ≤ b) (Λ θ : ℝ) (hθ : 0 < θ) : -b - 1 ≤ (cellWord b Λ θ).1 ∧ (cellWord b Λ θ).1 ≤ (cellWord b Λ θ).2.1 ∧ (cellWord b Λ θ).2.1 ≤ (cellWord b Λ θ).2.2.1 ∧ (cellWord b Λ θ).2.2.1 ≤ (cellWord b Λ θ).2.2.2.1 ∧ (cellWord b Λ θ).2.2.2.1 ≤ (cellWord b Λ θ).2.2.2.2 ∧ (cellWord b Λ θ).2.2.2.2 ≤ b := by have m : ∀ h : ℤ, clip b ⌊Λ + ((h : ℤ) : ℝ) * θ⌋ ≤ clip b ⌊Λ + ((h + 1 : ℤ) : ℝ) * θ⌋ := fun h => clip_mono _ _ _ (Int.floor_le_floor (by push_cast; nlinarith)) refine ⟨?_, m (-2), m (-1), m 0, m 1, ?_⟩ <;> simp only [cellWord, clip] <;> omega /-- Part III, Theorem `thm:diagonal` for `b = 1, 2`, with no classification hypothesis:no cell word of the section `θ = 1` is ambiguous. -/theorem diagonal_pequena (b : ℕ) (hb : 1 ≤ b) (hb2 : b ≤ 2) : ∀ Λ : ℝ, 0 ≤ Λ → ¬ Ambig (b : ℤ) (cellWord (b : ℤ) Λ 1) := by intro Λ hΛ ⟨_, Λ', θ', _, hθ, hne, hZ⟩ rw [cellWord_diag] at hne hZ have hj : 0 ≤ ⌊Λ⌋ := Int.floor_nonneg.mpr hΛ obtain ⟨j, hj0, hj1, hD⟩ : ∃ j : ℤ, 0 ≤ j ∧ j ≤ (b : ℤ) + 2 ∧ Dg (b : ℤ) ⌊Λ⌋ = Dg (b : ℤ) j := by by_cases h : ⌊Λ⌋ ≤ (b : ℤ) + 2 · exact ⟨⌊Λ⌋, hj, h, rfl⟩ · exact ⟨(b : ℤ) + 2, by omega, le_rfl, by rw [Dg_top _ _ (by omega) (by omega), Dg_top _ _ (by omega) le_rfl]⟩ rw [hD] at hne hZ obtain ⟨m0, m1, m2, m3, m4, m5⟩ := cellWord_mono (b : ℤ) (by omega) Λ' θ' hθ set d := cellWord (b : ℤ) Λ' θ' have key : ∀ B : ℤ, Chk B → B = (b : ℤ) → d = Dg (b : ℤ) j := by rintro B hc rfl exact hc _ (mem_rng m0 (by omega)) _ (mem_rng m1 (by omega)) _ (mem_rng m2 (by omega)) _ (mem_rng m3 (by omega)) _ (mem_rng m4 m5) j (mem_rng hj0 hj1) hZ apply hne rcases (show b = 1 ∨ b = 2 by omega) with rfl | rfl · exact key 1 chk1 rfl · exact key 2 chk2 rfl /-- Part III, Theorem `thm:diagonal`, full range `b ≥ 1`: under the classification of Part I(assumed only for `b ≥ 3`), no cell of the section `θ = 1` is ambiguous and the ambiguoussection length vanishes exactly. -/theorem diagonal (b : ℕ) (hb : 1 ≤ b) (hcl : 3 ≤ b → ∀ w, Ambig (b : ℤ) w ↔ enLista (b : ℤ) w) : (∀ Λ : ℝ, 0 ≤ Λ → ¬ Ambig (b : ℤ) (cellWord (b : ℤ) Λ 1)) ∧ secLen Ambig b 1 = 0 := by by_cases h3 : 3 ≤ b · exact diagonal_completa Ambig b h3 (hcl h3) · have h1 := diagonal_pequena b hb (by omega) refine ⟨h1, ?_⟩ have hvac : {Λ : ℝ | 0 ≤ Λ ∧ Λ ≤ (b : ℝ) + 2 * 1 ∧ Ambig (b : ℤ) (cellWord (b : ℤ) Λ 1)} = ∅ := by ext Λ simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false] rintro ⟨h0, -, hA⟩ exact h1 Λ h0 hA unfold secLen rw [hvac, measure_empty, ENNReal.toReal_zero] /-! ### Non-vacuity controls -/ /-- Control: ambiguous words are realizable. -/theorem ambig_realisable (b : ℤ) (w : Palabra) (h : Ambig b w) : Realisable b w := h.1 /-- The previous (defective) definition of ambiguity, which did not require `w` realizable. -/def OldAmbig (b : ℤ) (w : Palabra) : Prop := ∃ Λ' θ' : ℝ, 0 < Λ' ∧ 0 < θ' ∧ cellWord b Λ' θ' ≠ w ∧ Zw b (cellWord b Λ' θ') = Zw b w /-- Control: the previous hypothesis `∀ w, OldAmbig b w ↔ enLista b w` is unsatisfiable at`b = 3` (witness `w = (3,3,3,3,2)`, the reversal of `(2,3,3,3,3)`, realizable at `Λ = 9/2`,`θ = 1`, but not in the list). -/theorem oldAmbig_insatisfacible : ¬ (∀ w, OldAmbig 3 w ↔ enLista 3 w) := by intro h have hf : ⌊(9/2 : ℝ)⌋ = 4 := by rw [Int.floor_eq_iff]; norm_num have hc : cellWord 3 (9/2) 1 = ((2, 3, 3, 3, 3) : Palabra) := by rw [cellWord_diag, hf]; simp [Dg, clip] have hw : OldAmbig 3 ((3, 3, 3, 3, 2) : Palabra) := by refine ⟨9/2, 1, by norm_num, by norm_num, ?_, ?_⟩ · rw [hc]; simp · rw [hc]; decide +kernel have := (h _).1 hw simp only [enLista, G, O1, O2, Prod.mk.injEq, ne_eq] at this rcases this with ⟨m1, m2, h⟩ | ⟨s, h⟩ | ⟨k', h⟩ | ⟨v, h⟩ | h | ⟨i, e, h⟩ | ⟨i, h⟩ | ⟨x, h⟩ all_goals ((try simp only [clip] at h) ; omega) end CaballeroDiagonal