/-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.AngularGeneralApublic import Formalizations.Combinatorics.Caballero.AngularSlopeTwopublic import Formalizations.Combinatorics.Caballero.AngularTwoSteppublic import Mathlib.Algebra.BigOperators.Ring.Finsetpublic import Mathlib.Order.Interval.Finset.Natpublic import Mathlib.Order.Interval.Multisetpublic import Mathlib.Data.Rat.Floor /-!# The second peak of the ambiguity profile for a even: a realisable pair on the slope-2/q section (Caballero, Part IV) Part IV, Theorem 17 (a = 2r even): for q = a + 1 and -1 <= x <= min(b-3, b-a+1), the two-step vectorc = (x, b-r, b, ..., b) and the slope-2/q vector g_h = clip floor((k+2h)/q), k = ab + a + x, aredistinct realisable cell vectors with the same multiset Z. The proof follows the paper: the rows ofg are the counting function Phi of the numerical semigroup generated by 2 and q = 2r+1 (importedLemma 15, rows_slopeTwo), the closed form of Phi (Phi_closed, via the description of the semigroup,mem_Sigma_iff) and a multiset identity that removes the reflected gap indices from {{Phi(u)}}(key_multiset) give the multiset of the two-step vector (imported Lemma 16, lem_twostep), and Lemma7 (rows_iff) turns equality of the row multisets into equality of Z. Realisability of g is shown atthe explicit point Lambda = (k + 1/2)/q, theta = 2/q. The vector g is the type CaballeroGeneralA.Vecbuilt by slopeVec from CaballeroSlopeTwo.slope2_g (the coordinates are shared by definitionalunfolding of the copies in CaballeroTwoStep). Hypotheses: the paper fixes a >= 2, b >= 1; here a =2r with 2 <= a, b a natural number (the hypotheses on x force b >= 2). What is NOT formalised: thecounting of intervals and the liminf of the profile that use this theorem later in the paper(Theorem 3 for a even). ## Main results * `CaballeroK6Even.k6_even`: Theorem 17 (a even): c and g are distinct realisable vectors with Z(c) = Z(g)* `CaballeroK6Even.k6_even_ambiguous`: c is ambiguous (its fibre has at least two elements)* `CaballeroK6Even.key_multiset`: over u = 0..T the values Phi(T-v), v in Sigma, v <= T, form {{1..r}} + {{1..Delta-r}} + {{Delta-r+2t : 1 <= t <= r}} (Delta = s + r, T = s + 3r - 1)* `CaballeroK6Even.Phi_closed`: Phi(u) = floor(u/2) + 1 for u < 2r and u - r + 1 afterwards, for Sigma generated by 2 and 2r+1* `CaballeroK6Even.mem_Sigma_iff`: v is in Sigma = {2t + qs : t <= 2r} iff v is even or v >= q = 2r+1 ## 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 CaballeroK6Even open CaballeroGeneralA Finset /-- The vector `g = (g_h)_{h=-a}^{a}`, `g_h = clip ⌊(k+2h)/q⌋`, as a cell vector (index `h + a`). -/def slopeVec (a b q : ℕ) (k : ℤ) : Vec a := fun i => CaballeroSlopeTwo.slope2_g b q k (((i : ℕ) : ℤ) - a) /-! ### The semigroup `Σ = ⟨2, q⟩` and its counting function `Φ` -/ theorem mem_Sigma_iff (r v : ℕ) : v ∈ CaballeroSlopeTwo.slope2_Sigma (2 * r) (2 * r + 1) ↔ v % 2 = 0 ∨ 2 * r + 1 ≤ v := by simp only [CaballeroSlopeTwo.slope2_Sigma, Set.mem_ofPred_eq] constructor · rintro ⟨t, s, ht, rfl⟩ by_cases hs : s = 0 · subst hs left omega · right have : 2 * r + 1 ≤ (2 * r + 1) * s := Nat.le_mul_of_pos_right _ (by omega) omega · rintro (h | h) · obtain ⟨m, hm⟩ : ∃ m, v = 2 * m := ⟨v / 2, by omega⟩ have e := Nat.mod_add_div m (2 * r + 1) have hlt := Nat.mod_lt m (show 2 * r + 1 > 0 by omega) refine ⟨m % (2 * r + 1), 2 * (m / (2 * r + 1)), by omega, ?_⟩ generalize m / (2 * r + 1) = n at * generalize m % (2 * r + 1) = t at * have : (2 * r + 1) * (2 * n) = 2 * ((2 * r + 1) * n) := by ring omega · by_cases hv : v % 2 = 0 · obtain ⟨m, hm⟩ : ∃ m, v = 2 * m := ⟨v / 2, by omega⟩ have e := Nat.mod_add_div m (2 * r + 1) have hlt := Nat.mod_lt m (show 2 * r + 1 > 0 by omega) refine ⟨m % (2 * r + 1), 2 * (m / (2 * r + 1)), by omega, ?_⟩ generalize m / (2 * r + 1) = n at * generalize m % (2 * r + 1) = t at * have : (2 * r + 1) * (2 * n) = 2 * ((2 * r + 1) * n) := by ring omega · obtain ⟨m, hm⟩ : ∃ m, v = 2 * r + 1 + 2 * m := ⟨(v - (2 * r + 1)) / 2, by omega⟩ have e := Nat.mod_add_div m (2 * r + 1) have hlt := Nat.mod_lt m (show 2 * r + 1 > 0 by omega) refine ⟨m % (2 * r + 1), 2 * (m / (2 * r + 1)) + 1, by omega, ?_⟩ generalize m / (2 * r + 1) = n at * generalize m % (2 * r + 1) = t at * have : (2 * r + 1) * (2 * n + 1) = 2 * ((2 * r + 1) * n) + (2 * r + 1) := by ring omega /-- The closed form of `Φ` for `Σ = ⟨2, 2r+1⟩`: `Φ(u) = ⌊u/2⌋ + 1` for `u < 2r`, `u + 1 - r`afterwards. -/def Fval (r u : ℕ) : ℕ := if u < 2 * r then u / 2 + 1 else u + 1 - r theorem Fval_ge (r u : ℕ) (h : 2 * r ≤ u + 1) : Fval r u = u + 1 - r := by unfold Fval split_ifs <;> omega theorem card_closed (r u : ℕ) : ((range (u + 1)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v)).card = Fval r u := by induction u with | zero => unfold Fval simp only [zero_add, range_one] rw [filter_singleton] split_ifs <;> simp_all | succ n ih => rw [range_add_one, filter_insert] by_cases hP : (n + 1) % 2 = 0 ∨ 2 * r + 1 ≤ n + 1 · simp only [hP, ↓reduceIte] rw [card_insert_of_notMem (by simp), ih] unfold Fval split_ifs <;> omega · simp only [hP, ↓reduceIte] rw [ih] unfold Fval split_ifs <;> omega theorem Phi_closed (r u : ℕ) : CaballeroSlopeTwo.slope2_Phi (2 * r) (2 * r + 1) (u : ℤ) = Fval r u := by have hset : {v : ℕ | v ∈ CaballeroSlopeTwo.slope2_Sigma (2 * r) (2 * r + 1) ∧ (v : ℤ) ≤ (u : ℤ)} = ↑((range (u + 1)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v)) := by ext v simp only [Set.mem_ofPred_eq, coe_filter, mem_range, mem_Sigma_iff] omega unfold CaballeroSlopeTwo.slope2_Phi simp only [Int.natCast_nonneg, ↓reduceIte] rw [hset, Set.ncard_coe_finset, card_closed] /-! ### Multiset bookkeeping -/ /-- The block `{c, c+1, …, c+n-1}` as a multiset of integers. -/def ssum (c n : ℕ) : Multiset ℤ := ∑ j ∈ range n, ({((c + j : ℕ) : ℤ)} : Multiset ℤ) /-- The block `{c, c+2, …, c+2(n-1)}`. -/def ssum2 (c n : ℕ) : Multiset ℤ := ∑ j ∈ range n, ({((c + 2 * j : ℕ) : ℤ)} : Multiset ℤ) theorem ssum_add (c m n : ℕ) : ssum c (m + n) = ssum c m + ssum (c + m) n := by unfold ssum rw [sum_range_add] congr 1 apply sum_congr rfl intro j _ rw [show c + (m + j) = c + m + j from by omega] theorem pair_ssum2 (c n : ℕ) : ssum2 (c + 1) n + ssum2 (c + 2) n = ssum (c + 1) (2 * n) := by induction n with | zero => simp [ssum, ssum2] | succ n ih => have e : 2 * (n + 1) = 2 * n + 1 + 1 := by ring unfold ssum2 ssum at * rw [e, sum_range_succ, sum_range_succ, sum_range_succ, sum_range_succ, ← ih] have h1 : ((c + 1 + 2 * n : ℕ) : ℤ) = ((c + 1 + 2 * n : ℕ) : ℤ) := rfl have h2 : c + 2 + 2 * n = c + 1 + (2 * n + 1) := by omega have h3 : c + 1 + 2 * n = c + 1 + 2 * n := rfl rw [h2] abel theorem icc_eq (n : ℕ) : Multiset.Icc (1 : ℤ) n = ssum 1 n := by have hF : Finset.Icc (1 : ℤ) n = (range n).map ⟨fun j : ℕ => ((1 + j : ℕ) : ℤ), by intro i j h; simpa using h⟩ := by ext z simp only [mem_Icc, mem_map, mem_range] constructor · rintro ⟨h1, h2⟩ exact ⟨(z - 1).toNat, by omega, by show ((1 + (z - 1).toNat : ℕ) : ℤ) = z; omega⟩ · rintro ⟨j, hj, rfl⟩ show 1 ≤ ((1 + j : ℕ) : ℤ) ∧ ((1 + j : ℕ) : ℤ) ≤ n omega have : Multiset.Icc (1 : ℤ) n = (Finset.Icc (1 : ℤ) n).val := rfl rw [this, hF, Finset.map_val] unfold ssum exact CaballeroTwoStep.map_eq_sum (range n) (fun j : ℕ => ((1 + j : ℕ) : ℤ)) theorem icc_map_eq (s r : ℕ) : (Multiset.Icc (1 : ℤ) r).map (fun t => (s : ℤ) + 2 * t) = ssum2 (s + 2) r := by rw [icc_eq] unfold ssum ssum2 have : ∀ (S : Finset ℕ) (f : ℕ → ℤ), (∑ j ∈ S, ({f j} : Multiset ℤ)).map (fun t => (s : ℤ) + 2 * t) = ∑ j ∈ S, ({(s : ℤ) + 2 * f j} : Multiset ℤ) := by intro S f induction S using Finset.induction_on with | empty => simp | insert a S ha ih => rw [sum_insert ha, sum_insert ha, Multiset.map_add, ih]; simp rw [this] apply sum_congr rfl intro j _ congr 2 push_cast ring theorem double_sum (r : ℕ) : ∑ u ∈ range (2 * r), ({((Fval r u : ℕ) : ℤ)} : Multiset ℤ) = ssum 1 r + ssum 1 r := by have : ∀ r' : ℕ, r' ≤ r → ∑ u ∈ range (2 * r'), ({((Fval r u : ℕ) : ℤ)} : Multiset ℤ) = ssum 1 r' + ssum 1 r' := by intro r' hr' induction r' with | zero => simp [ssum] | succ n ih => have e : 2 * (n + 1) = 2 * n + 1 + 1 := by ring rw [e, sum_range_succ, sum_range_succ, ih (by omega)] unfold ssum rw [sum_range_succ] have h1 : Fval r (2 * n) = 1 + n := by unfold Fval; split_ifs <;> omega have h2 : Fval r (2 * n + 1) = 1 + n := by unfold Fval; split_ifs <;> omega rw [h1, h2] abel exact this r le_rfl /-- The key multiset identity of the proof of Theorem 17: over `u = 0..T`, the values `Φ(T - v)`for `v ∈ Σ`, `v ≤ T`, `T = s + 3r - 1`. -/theorem key_multiset (r s : ℕ) (hr : 1 ≤ r) (hs : r ≤ s + 1) : ((range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v)).val.map (fun v => ((Fval r (s + 3 * r - 1 - v) : ℕ) : ℤ)) = Multiset.Icc (1 : ℤ) r + Multiset.Icc (1 : ℤ) s + (Multiset.Icc (1 : ℤ) r).map (fun t => (s : ℤ) + 2 * t) := by rw [icc_map_eq, icc_eq, icc_eq] set f : ℕ → Multiset ℤ := fun v => ({((Fval r (s + 3 * r - 1 - v) : ℕ) : ℤ)} : Multiset ℤ) with hf have hL : ((range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v)).val.map (fun v => ((Fval r (s + 3 * r - 1 - v) : ℕ) : ℤ)) = ∑ v ∈ (range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v), f v := CaballeroTwoStep.map_eq_sum _ _ rw [hL] -- the gaps have h3 : ∑ v ∈ (range (s + 3 * r)).filter (fun v => ¬ (v % 2 = 0 ∨ 2 * r + 1 ≤ v)), f v = ssum2 (s + 1) r := by unfold ssum2 apply sum_nbij' (fun v => r - 1 - v / 2) (fun i => 2 * (r - 1 - i) + 1) · intro v hv simp only [mem_filter, mem_range] at hv ⊢ omega · intro i hi simp only [mem_filter, mem_range] at hi ⊢ omega · intro v hv simp only [mem_filter, mem_range] at hv omega · intro i hi simp only [mem_range] at hi omega · intro v hv simp only [mem_filter, mem_range] at hv simp only [hf] have : Fval r (s + 3 * r - 1 - v) = s + 1 + 2 * (r - 1 - v / 2) := by rw [Fval_ge r _ (by omega)] omega rw [this] have h1 := sum_filter_add_sum_filter_not (range (s + 3 * r)) (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v) f have h2 : ∑ v ∈ range (s + 3 * r), f v = ∑ u ∈ range (s + 3 * r), ({((Fval r u : ℕ) : ℤ)} : Multiset ℤ) := by have := sum_range_reflect (fun u => ({((Fval r u : ℕ) : ℤ)} : Multiset ℤ)) (s + 3 * r) exact this have h4 : ∑ u ∈ range (s + 3 * r), ({((Fval r u : ℕ) : ℤ)} : Multiset ℤ) = ssum 1 r + ssum 1 (s + 2 * r) := by have e : s + 3 * r = 2 * r + (s + r) := by ring rw [e, sum_range_add, double_sum] have : ∑ x ∈ range (s + r), ({((Fval r (2 * r + x) : ℕ) : ℤ)} : Multiset ℤ) = ssum (r + 1) (s + r) := by unfold ssum apply sum_congr rfl intro x _ rw [Fval_ge r _ (by omega)] congr 2 omega rw [this] have e2 : s + 2 * r = r + (s + r) := by ring rw [e2, ssum_add 1 r (s + r)] have e3 : 1 + r = r + 1 := by ring rw [e3] abel have h5 : ssum2 (s + 1) r + ssum2 (s + 2) r = ssum (s + 1) (2 * r) := pair_ssum2 s r have h6 : ssum 1 (s + 2 * r) = ssum 1 s + ssum (s + 1) (2 * r) := by rw [ssum_add 1 s (2 * r), show 1 + s = s + 1 from by omega] have h7 : ∑ v ∈ (range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v), f v + ssum2 (s + 1) r = ssum 1 r + ssum 1 s + ssum2 (s + 2) r + ssum2 (s + 1) r := by have hh : ∑ v ∈ (range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v), f v + ssum2 (s + 1) r = ∑ v ∈ range (s + 3 * r), f v := by rw [← h3] exact h1 rw [hh, h2, h4, h6, ← h5] abel exact add_right_cancel h7 /-! ### Rows of vectors of non-negative rows -/ theorem R_nonneg (a b : ℕ) (c : Vec a) (i j : ℕ) : 0 ≤ R a b c i j := by unfold R apply sum_nonneg intro h _ exact le_min (by positivity) (le_max_left _ _) theorem Zr_eq_of_pos (a b : ℕ) (c d : Vec a) (h : (Zr a b c).filter (fun v => 0 < v) = (Zr a b d).filter (fun v => 0 < v)) : Zr a b c = Zr a b d := by have key : ∀ e : Vec a, Zr a b e = (Zr a b e).filter (fun v => 0 < v) + Multiset.replicate ((a + 1) * (b + 1) - ((Zr a b e).filter (fun v => 0 < v)).card) 0 := by intro e have hc : Multiset.card (Zr a b e) = (a + 1) * (b + 1) := by simp [Zr] ring have hnn : Multiset.filter (fun v => ¬ 0 < v) (Zr a b e) = Multiset.replicate (Multiset.card (Multiset.filter (fun v => ¬ 0 < v) (Zr a b e))) 0 := by rw [Multiset.eq_replicate_card] intro v hv have hv' := Multiset.mem_filter.mp hv have : 0 ≤ v := by obtain ⟨hmem, -⟩ := hv' simp only [Zr, Multiset.mem_map] at hmem obtain ⟨p, -, rfl⟩ := hmem exact R_nonneg _ _ _ _ _ omega have hsplit := Multiset.filter_add_not (fun v => 0 < v) (Zr a b e) have hcc := congrArg Multiset.card hsplit rw [Multiset.card_add, hc] at hcc conv_lhs => rw [← hsplit] congr 1 rw [hnn] congr 1 omega rw [key c, key d, h] /-! ### Bridges to the base modules -/ theorem coord_slopeVec (a b q : ℕ) (k : ℤ) (h : ℤ) (h1 : -(a : ℤ) ≤ h) (h2 : h ≤ a) : coord (slopeVec a b q k) h = CaballeroSlopeTwo.slope2_g b q k h := by unfold coord slopeVec simp only [h1, h2, and_self, ↓reduceDIte] rw [show (((h + a).toNat : ℕ) : ℤ) - a = h by omega] theorem Zr_slopeVec (a b q : ℕ) (k : ℤ) : Zr a b (slopeVec a b q k) = CaballeroSlopeTwo.slope2_Zr a b (CaballeroSlopeTwo.slope2_g b q k) := by unfold Zr CaballeroSlopeTwo.slope2_Zr apply Multiset.map_congr rfl intro p hp simp only [Finset.mem_val, mem_product, mem_range] at hp unfold R CaballeroSlopeTwo.slope2_row apply sum_congr rfl intro h hh rw [mem_Icc] at hh rw [coord_slopeVec a b q k h (by omega) (by omega)] theorem Zr_twoStep_bridge (a b : ℕ) (c : Vec a) : CaballeroTwoStep.Zr a b c = Zr a b c := rfl theorem floor_slope (n : ℤ) (q : ℕ) (hq : 0 < q) : ⌊((n : ℝ) + 1 / 2) / (q : ℝ)⌋ = n / (q : ℤ) := by have hq' : (0 : ℝ) < q := by exact_mod_cast hq have hqz : (0 : ℤ) < q := by exact_mod_cast hq rw [Int.floor_eq_iff] have e0 := Int.emod_add_mul_ediv n (q : ℤ) have hm0 := Int.emod_nonneg n hqz.ne' have hm1 := Int.emod_lt_of_pos n hqz set z := n / (q : ℤ) set m := n % (q : ℤ) have e : (n : ℝ) = (m : ℝ) + (q : ℝ) * (z : ℝ) := by exact_mod_cast e0.symm have hm0' : (0 : ℝ) ≤ m := by exact_mod_cast hm0 have hm1' : (m : ℝ) + 1 ≤ q := by exact_mod_cast hm1 constructor · rw [le_div_iff₀ hq'] nlinarith · rw [div_lt_iff₀ hq'] nlinarith theorem slopeVec_realisable (a b : ℕ) (k : ℤ) (hk : 0 ≤ k) : Realisable a b (slopeVec a b (a + 1) k) := by have hq' : (0 : ℝ) < (a : ℝ) + 1 := by positivity refine ⟨((k : ℝ) + 1 / 2) / ((a : ℝ) + 1), 2 / ((a : ℝ) + 1), ?_, by positivity, ?_, ?_⟩ · have : (0 : ℝ) ≤ k := by exact_mod_cast hk exact div_pos (by linarith) hq' · intro h _ _ z hz have h1 : (((k : ℝ) + 1 / 2) + 2 * h) / ((a : ℝ) + 1) = z := by rw [← hz]; ring rw [div_eq_iff hq'.ne'] at h1 have h2 : ((2 * k + 1 + 4 * h : ℤ) : ℝ) = ((2 * (z * ((a : ℤ) + 1)) : ℤ) : ℝ) := by push_cast linarith have h3 : 2 * k + 1 + 4 * h = 2 * (z * ((a : ℤ) + 1)) := by exact_mod_cast h2 omega · funext i unfold cellVec slopeVec rw [CaballeroSlopeTwo.slope2_g_eq] have : ⌊((k : ℝ) + 1 / 2) / ((a : ℝ) + 1) + ((((i : ℕ) : ℤ) - a : ℤ) : ℝ) * (2 / ((a : ℝ) + 1))⌋ = (k + 2 * (((i : ℕ) : ℤ) - a)) / ((a + 1 : ℕ) : ℤ) := by rw [← floor_slope (k + 2 * (((i : ℕ) : ℤ) - a)) (a + 1) (by omega)] congr 1 push_cast ring rw [this] rfl /-! ### Theorem 17 -/ open Classical in/-- Part IV, Theorem 17 (`a` even). Let `a = 2r ≥ 2`, `q = a + 1`, and`-1 ≤ x ≤ min(b-3, b-a+1)`. Put `y = b - r`, `c = (x, y, b, …, b)` (`twoStep a b r x`),`k = ab + a + x` and `g_h = clip ⌊(k+2h)/q⌋` (`slopeVec a b (a+1) k`). Then `c` and `g` aredistinct realisable vectors with `Z(c) = Z(g)`. -/theorem k6_even (a r b : ℕ) (x : ℤ) (hr : a = 2 * r) (ha : 2 ≤ a) (hx : -1 ≤ x) (hxb : x ≤ (b : ℤ) - 3) (hxa : x ≤ (b : ℤ) - a + 1) : Realisable a b (CaballeroTwoStep.twoStep a b r x) ∧ Realisable a b (slopeVec a b (a + 1) ((a : ℤ) * b + a + x)) ∧ slopeVec a b (a + 1) ((a : ℤ) * b + a + x) ≠ CaballeroTwoStep.twoStep a b r x ∧ Z a b (CaballeroTwoStep.twoStep a b r x) = Z a b (slopeVec a b (a + 1) ((a : ℤ) * b + a + x)) := by subst hr have hr1 : 1 ≤ r := by omega obtain ⟨s, hs⟩ : ∃ s : ℕ, (s : ℤ) = b - x - r := ⟨(b - x - r).toNat, by push_cast at hxa; omega⟩ have hsr : r ≤ s + 1 := by push_cast at hxa; omega have hxy : x ≤ (b : ℤ) - r := by push_cast at hxa; omega have hb2 : (2 : ℤ) ≤ b := by omega have hc : Realisable (2 * r) b (CaballeroTwoStep.twoStep (2 * r) b r x) := CaballeroTwoStep.twoStep_realisable (2 * r) b r x ha hr1 hx hxy (by push_cast at hxa; omega) have hk : 2 * ((2 * r : ℕ) : ℤ) ≤ ((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x := by push_cast have : (2 * (r : ℤ)) * 1 ≤ (2 * (r : ℤ)) * (b - 1) := mul_le_mul_of_nonneg_left (by omega) (by positivity) nlinarith have hg : Realisable (2 * r) b (slopeVec (2 * r) b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x)) := slopeVec_realisable _ _ _ (by push_cast at hk ⊢; linarith) have hTeq : CaballeroSlopeTwo.slope2_T (2 * r) b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x) = ((s + 3 * r - 1 : ℕ) : ℤ) := by unfold CaballeroSlopeTwo.slope2_T push_cast [Nat.cast_sub (show 1 ≤ s + 3 * r by omega)] linear_combination (-1 : ℤ) * hs have hT : CaballeroSlopeTwo.slope2_T (2 * r) b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x) < ((2 * r + 1 : ℕ) : ℤ) * (b + 1) := by rw [hTeq] push_cast [Nat.cast_sub (show 1 ≤ s + 3 * r by omega)] have : (0 : ℤ) ≤ 2 * r * b := by positivity nlinarith have h1 : (Zr (2 * r) b (CaballeroTwoStep.twoStep (2 * r) b r x)).filter (fun v => 0 < v) = Multiset.Icc (1 : ℤ) r + Multiset.Icc (1 : ℤ) s + (Multiset.Icc (1 : ℤ) r).map (fun t => (s : ℤ) + 2 * t) := by have := (CaballeroTwoStep.lem_twostep (2 * r) b r x ha hr1 hx hxy).1 rw [← hs] at this exact this have h2 : (Zr (2 * r) b (slopeVec (2 * r) b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x))).filter (fun v => 0 < v) = Multiset.Icc (1 : ℤ) r + Multiset.Icc (1 : ℤ) s + (Multiset.Icc (1 : ℤ) r).map (fun t => (s : ℤ) + 2 * t) := by rw [Zr_slopeVec, CaballeroSlopeTwo.rows_slopeTwo (2 * r) b (2 * r + 1) _ ⟨r, rfl⟩ le_rfl hk hT, hTeq, ← key_multiset r s hr1 hsr] have hfil : ((range ((((s + 3 * r - 1 : ℕ) : ℤ)).toNat + 1)).filter (fun v : ℕ => v ∈ CaballeroSlopeTwo.slope2_Sigma (2 * r) (2 * r + 1) ∧ (v : ℤ) ≤ ((s + 3 * r - 1 : ℕ) : ℤ))) = (range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v) := by ext v simp only [mem_filter, mem_range, mem_Sigma_iff] omega rw [hfil] apply Multiset.map_congr rfl intro v hv have hv' : v < s + 3 * r := by have := (mem_filter.mp (show v ∈ (range (s + 3 * r)).filter (fun v => v % 2 = 0 ∨ 2 * r + 1 ≤ v) from hv)).1 exact mem_range.mp this have e : ((s + 3 * r - 1 : ℕ) : ℤ) - (v : ℤ) = ((s + 3 * r - 1 - v : ℕ) : ℤ) := by omega rw [e, Phi_closed] have hZr := Zr_eq_of_pos _ _ _ _ (h1.trans h2.symm) have hne : slopeVec (2 * r) b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x) ≠ CaballeroTwoStep.twoStep (2 * r) b r x := by intro heq have h0 := congrFun heq ⟨0, by omega⟩ have h0' : CaballeroSlopeTwo.slope2_g b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x) (0 - ((2 * r : ℕ) : ℤ)) = x := by simpa [slopeVec, CaballeroTwoStep.twoStep] using h0 rw [CaballeroSlopeTwo.slope2_g_eq] at h0' unfold CaballeroSlopeTwo.slope2_clip at h0' have hv : (x + 1) ≤ ((((2 * r : ℕ) : ℤ) * b + ((2 * r : ℕ) : ℤ) + x) + 2 * (0 - ((2 * r : ℕ) : ℤ))) / ((2 * r + 1 : ℕ) : ℤ) := by rw [Int.le_ediv_iff_mul_le (by positivity)] push_cast have h12 : (r : ℤ) * 1 ≤ r * ((b : ℤ) - 2 - x) := mul_le_mul_of_nonneg_left (by omega) (by positivity) nlinarith omega exact ⟨hc, hg, hne, (rows_iff _ _ _ _ hc hg).mp hZr⟩ /-- The fibre of `c` has at least two elements: `c` is ambiguous (Part IV, Theorem 17). -/theorem k6_even_ambiguous (a r b : ℕ) (x : ℤ) (hr : a = 2 * r) (ha : 2 ≤ a) (hx : -1 ≤ x) (hxb : x ≤ (b : ℤ) - 3) (hxa : x ≤ (b : ℤ) - a + 1) : Ambiguous a b (CaballeroTwoStep.twoStep a b r x) := by obtain ⟨hc, hg, hne, hZ⟩ := k6_even a r b x hr ha hx hxb hxa exact ⟨hc, _, hg, hne, hZ.symm⟩ end CaballeroK6Even