/-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.AngularK6Evenpublic import Formalizations.Combinatorics.Caballero.AngularSecondPeakOdd /-!# The remark on the second-peak families (Caballero, Part IV) Remark after Theorem 3 of Part IV. Item (3): the two-step vector c = (x, y, b, ..., b) always has acoordinate equal to b (twoStep_last_eq_b); for the slope-2/(a+1) vector g of Theorem 17 (k = ab + a+ x, Delta = b - x), g_a = b if and only if Delta <= 3a (even_last_eq_b_iff); for the slope-2/(a+2)vector of Theorem 18 (k = qb + 2a - T - 1, q = a+2), g_a = b if and only if T <= 4a - 1(odd_last_eq_b_iff). Item (1), a = 2: for x = b-2 and x = b-1 the two vectors coincide, c = g(a_two_eq). Item (4), a = 2r even: Sigma = <2, q>, q = 2r+1, is a numerical semigroup with Frobeniusnumber F = q - 2 and is symmetric (sigma_symmetric); T = Delta + F, and the removed indices T - v, va gap of Sigma, are exactly Delta + s with s in Sigma, s <= F (removed_indices). The paper's check'for even a <= 20 and Delta < 60' is replaced by a proof for all r >= 1 and Delta >= 0. ## Main results * `CaballeroK6Remark.removed_indices`: item (4): T = Delta + F, and {T - v : v gap} = {Delta + s : s in Sigma, s <= F}* `CaballeroK6Remark.sigma_symmetric`: item (4): <2, 2r+1> is closed under addition, has Frobenius number 2r-1 and is symmetric* `CaballeroK6Remark.even_last_eq_b_iff`: item (3), a even: g_a = b iff Delta <= 3a* `CaballeroK6Remark.odd_last_eq_b_iff`: item (3), a odd: g_a = b iff T <= 4a - 1* `CaballeroK6Remark.twoStep_last_eq_b`: item (3): the two-step vector has c_a = b* `CaballeroK6Remark.a_two_eq`: item (1), a = 2: for x = b-2, b-1 the vectors c and g coincide ## 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.* J. C. Rosales, P. A. García-Sánchez, Numerical Semigroups, Springer (2009).-/ @[expose] public section namespace CaballeroK6Remark open CaballeroGeneralA Finset /-! ### Item (3): where the partner `g` reaches `b` -/ /-- Item (3): the two-step vector `c = (x, y, b, …, b)` always has a coordinate equal to `b`(its last one, `c_a`). -/theorem twoStep_last_eq_b (a b ρ : ℕ) (x : ℤ) (ha : 2 ≤ a) : CaballeroTwoStep.twoStep a b ρ x ⟨2 * a, by omega⟩ = b := by unfold CaballeroTwoStep.twoStep split_ifs with h0 h1 · simp only at h0; omega · simp only at h1; omega · rfl /-- Item (3), `a` even (Theorem 17): with `k = ab + a + x` and `Δ = b - x`, the last coordinate`g_a = clip ⌊(k + 2a)/(a+1)⌋` equals `b` if and only if `Δ ≤ 3a`. (The formula holds for every`a`; the remark uses it for even `a`.) -/theorem even_last_eq_b_iff (a b : ℕ) (x : ℤ) : CaballeroK6Even.slopeVec a b (a + 1) ((a : ℤ) * b + a + x) ⟨2 * a, by omega⟩ = b ↔ (b : ℤ) - x ≤ 3 * a := by unfold CaballeroK6Even.slopeVec rw [CaballeroSlopeTwo.slope2_g_eq] unfold CaballeroSlopeTwo.slope2_clip have e : (a : ℤ) * b + a + x + 2 * (((2 * a : ℕ) : ℤ) - a) = ((a : ℤ) + 1) * b + (3 * a + x - b) := by push_cast; ring push_cast at e ⊢ rw [e] have hq : (0 : ℤ) < (a : ℤ) + 1 := by positivity have hdiv : (((a : ℤ) + 1) * b + (3 * a + x - b)) / ((a : ℤ) + 1) = b + (3 * a + x - b) / ((a : ℤ) + 1) := by rw [show ((a : ℤ) + 1) * b + (3 * a + x - b) = (3 * a + x - b) + (b : ℤ) * ((a : ℤ) + 1) by ring, Int.add_mul_ediv_right _ _ hq.ne'] ring rw [hdiv] constructor · intro h by_contra hc have : (3 * a + x - b) / ((a : ℤ) + 1) < 0 := Int.ediv_neg_of_neg_of_pos (by omega) hq omega · intro h have : 0 ≤ (3 * a + x - b) / ((a : ℤ) + 1) := Int.ediv_nonneg (by omega) hq.le omega /-- Item (3), `a` odd (Theorem 18): with `q = a + 2` and `k = qb + 2a - T - 1`, the lastcoordinate `g_a = clip ⌊(k + 2a)/q⌋` equals `b` if and only if `T ≤ 4a - 1`. -/theorem odd_last_eq_b_iff (a b : ℕ) (T : ℤ) : CaballeroK6Odd.slopeVec a b (a + 2) (((a : ℤ) + 2) * b + 2 * a - T - 1) ⟨2 * a, by omega⟩ = b ↔ T ≤ 4 * a - 1 := by unfold CaballeroK6Odd.slopeVec rw [Rat.floor_intCast_div_natCast] unfold CaballeroPeaks.clip have hq : (0 : ℤ) < (a : ℤ) + 2 := by positivity have e : ((a : ℤ) + 2) * b + 2 * a - T - 1 + 2 * (((2 * a : ℕ) : ℤ) - a) = ((a : ℤ) + 2) * b + (4 * a - T - 1) := by push_cast; ring simp only at e ⊢ push_cast at e ⊢ rw [e] have hdiv : (((a : ℤ) + 2) * b + (4 * a - T - 1)) / ((a : ℤ) + 2) = b + (4 * a - T - 1) / ((a : ℤ) + 2) := by rw [show ((a : ℤ) + 2) * b + (4 * a - T - 1) = (4 * a - T - 1) + (b : ℤ) * ((a : ℤ) + 2) by ring, Int.add_mul_ediv_right _ _ hq.ne'] ring rw [hdiv] constructor · intro h by_contra hc have : (4 * a - T - 1) / ((a : ℤ) + 2) < 0 := Int.ediv_neg_of_neg_of_pos (by omega) hq omega · intro h have : 0 ≤ (4 * a - T - 1) / ((a : ℤ) + 2) := Int.ediv_nonneg (by omega) hq.le omega /-! ### Item (1) for `a = 2`: the two vectors coincide -/ /-- Item (1), `a = 2`: for `x = b - 2` and `x = b - 1` the vectors `c = (x, b-1, b, b, b)` and`g_h = clip ⌊(k+2h)/3⌋`, `k = 2b + 2 + x`, are equal (so the multisets agree but there is nosecond vector). -/theorem a_two_eq (b : ℕ) (hb : 1 ≤ b) (x : ℤ) (hx : x = (b : ℤ) - 2 ∨ x = (b : ℤ) - 1) : CaballeroK6Even.slopeVec 2 b 3 (2 * (b : ℤ) + 2 + x) = CaballeroTwoStep.twoStep 2 b 1 x := by funext i unfold CaballeroK6Even.slopeVec CaballeroTwoStep.twoStep rw [CaballeroSlopeTwo.slope2_g_eq] unfold CaballeroSlopeTwo.slope2_clip fin_cases i <;> simp <;> rcases hx with rfl | rfl <;> omega /-! ### Item (4): the symmetric semigroup `⟨2, q⟩` -/ /-- Membership in `Σ = ⟨2, 2r+1⟩` (Part IV, Section 5, `a = 2r`), as a decidable predicate. -/def InSigma (r v : ℕ) : Prop := v % 2 = 0 ∨ 2 * r + 1 ≤ v instance (r v : ℕ) : Decidable (InSigma r v) := by unfold InSigma; infer_instance theorem inSigma_iff (r v : ℕ) : v ∈ CaballeroSlopeTwo.slope2_Sigma (2 * r) (2 * r + 1) ↔ InSigma r v := CaballeroK6Even.mem_Sigma_iff r v /-- Item (4): `Σ = ⟨2, q⟩`, `q = 2r + 1`, is a numerical semigroup (closed under addition, withfinite complement) whose Frobenius number is `F = q - 2 = 2r - 1`, and it is symmetric:for `0 ≤ v ≤ F`, `v ∈ Σ` if and only if `F - v ∉ Σ`. -/theorem sigma_symmetric (r : ℕ) (hr : 1 ≤ r) : (∀ v w : ℕ, InSigma r v → InSigma r w → InSigma r (v + w)) ∧ ¬ InSigma r (2 * r - 1) ∧ (∀ v : ℕ, 2 * r - 1 < v → InSigma r v) ∧ (∀ v : ℕ, v ≤ 2 * r - 1 → (InSigma r v ↔ ¬ InSigma r (2 * r - 1 - v))) := by unfold InSigma refine ⟨fun v w hv hw => ?_, by omega, fun v hv => by omega, fun v hv => by omega⟩ omega /-- Item (4): in the setting of Theorem 17 (`a = 2r`, `q = a + 1`, `k = ab + a + x`,`Δ = b - x ≥ 0`) one has `T = Δ + F` with `F = q - 2`, and the removed indices `T - v`,`v` a gap of `Σ`, are exactly the `Δ + s` with `s ∈ Σ`, `s ≤ F`. -/theorem removed_indices (r b : ℕ) (hr : 1 ≤ r) (x : ℤ) (Δ : ℕ) (hΔ : (Δ : ℤ) = b - x) : CaballeroSlopeTwo.slope2_T (2 * r) b (2 * r + 1) (((2 * r : ℕ) : ℤ) * b + (2 * r : ℕ) + x) = ((Δ + (2 * r - 1) : ℕ) : ℤ) ∧ ((range (2 * r)).filter (fun v => ¬ InSigma r v)).image (fun v => Δ + (2 * r - 1) - v) = ((range (2 * r)).filter (fun s => InSigma r s)).image (fun s => Δ + s) := by constructor · unfold CaballeroSlopeTwo.slope2_T push_cast [Nat.cast_sub (show 1 ≤ 2 * r by omega)] linear_combination (-1 : ℤ) * hΔ · ext n simp only [Finset.mem_image, Finset.mem_filter, Finset.mem_range] constructor · rintro ⟨v, ⟨hv, hgap⟩, rfl⟩ unfold InSigma at hgap exact ⟨2 * r - 1 - v, ⟨by omega, by unfold InSigma; omega⟩, by omega⟩ · rintro ⟨s, ⟨hs, hin⟩, rfl⟩ unfold InSigma at hin exact ⟨2 * r - 1 - s, ⟨by omega, by unfold InSigma; omega⟩, by omega⟩ end CaballeroK6Remark