import Mathlib /-! # OEIS A248183: a proof of Ridouane Oudra's conjecture A248183 (Clark Kimberling, 2014) is the sequence a(n) = least k such that 1/4 - Sum_{h = 1..k} 1/(h*(h+1)*(h+2)) < 1/n^2. In 2023 Ridouane Oudra conjectured on the OEIS that, for n > 1, a(n) = floor(sqrt(n^2/2 + 1) - 1/2). The entry still lists this as a conjecture (revision 19, read 24 November 2026). This file proves it, with the statement written as it appears on the OEIS: the sum is taken in the rationals, the square root in the reals, and "least k" means the least element of the set of k >= 1 that satisfy the inequality. The idea. The sum telescopes: s(k) = 1/4 - 1/(2(k+1)(k+2)). So k works exactly when n^2 < 2(k+1)(k+2). The formula's value j satisfies (2j+1)^2 <= 2n^2 + 4 < (2j+3)^2. The upper bound shows j works. The lower bound gives n^2 >= 2j(j+1) - 1, and equality is impossible because a square is 0 or 1 mod 4 while 2j(j+1) - 1 is 3 mod 4. So no smaller k works. Check it: paste into https://live.lean-lang.org (it has Mathlib). No errors means the proof holds; the last line lists the axioms used, which are Lean's three standard ones. -/ namespace A248183 open Finset /-- The partial sum s(k) = Sum_{h = 1..k} 1/(h(h+1)(h+2)). -/ noncomputable def s (k : ℕ) : ℚ := ∑ h ∈ Icc 1 k, 1 / ((h : ℚ) * (h + 1) * (h + 2)) /-- The sum telescopes. -/ theorem s_eq (k : ℕ) : s k = 1 / 4 - 1 / (2 * ((k : ℚ) + 1) * (k + 2)) := by unfold s induction k with | zero => norm_num | succ k ih => rw [sum_Icc_succ_top (by omega), ih] push_cast field_simp ring /-- So k satisfies the defining inequality exactly when n^2 < 2(k+1)(k+2). -/ theorem cond_iff (n k : ℕ) (hn : 0 < n) : (1 / 4 - s k < 1 / (n : ℚ) ^ 2) ↔ n * n < 2 * ((k + 1) * (k + 2)) := by have hn' : (0 : ℚ) < n := by exact_mod_cast hn rw [s_eq] have h1 : (1 : ℚ) / 4 - (1 / 4 - 1 / (2 * ((k : ℚ) + 1) * (k + 2))) = 1 / (2 * ((k : ℚ) + 1) * (k + 2)) := by ring rw [h1, one_div_lt_one_div (by positivity) (by positivity)] rw [show (n : ℚ) ^ 2 = ((n * n : ℕ) : ℚ) by push_cast; ring, show 2 * ((k : ℚ) + 1) * (k + 2) = ((2 * ((k + 1) * (k + 2)) : ℕ) : ℚ) by push_cast; ring] exact Nat.cast_lt /-- A square plus one is never twice a product of consecutive numbers (look mod 4). -/ theorem sq_add_one_ne (n j : ℕ) : n * n + 1 ≠ 2 * (j * (j + 1)) := by intro h have hn : n * n % 4 = 0 ∨ n * n % 4 = 1 := by rcases Nat.mod_two_eq_zero_or_one n with h2 | h2 · obtain ⟨q, rfl⟩ : ∃ q, n = 2 * q := ⟨n / 2, by omega⟩ have e : 2 * q * (2 * q) = 4 * (q * q) := by ring omega · obtain ⟨q, rfl⟩ : ∃ q, n = 2 * q + 1 := ⟨n / 2, by omega⟩ have e : (2 * q + 1) * (2 * q + 1) = 4 * (q * q + q) + 1 := by ring omega have hj : j * (j + 1) % 2 = 0 := by rcases Nat.mod_two_eq_zero_or_one j with h2 | h2 · obtain ⟨r, rfl⟩ : ∃ r, j = 2 * r := ⟨j / 2, by omega⟩ have e : 2 * r * (2 * r + 1) = 2 * (r * (2 * r + 1)) := by ring omega · obtain ⟨r, rfl⟩ : ∃ r, j = 2 * r + 1 := ⟨j / 2, by omega⟩ have e : (2 * r + 1) * (2 * r + 1 + 1) = 2 * ((2 * r + 1) * (r + 1)) := by ring omega omega /-- The whole-number core: if (2j+1)^2 <= 2n^2 + 4 < (2j+3)^2 then j is the least k with n^2 < 2(k+1)(k+2). -/ theorem core (n j : ℕ) (hlo : (2 * j + 1) * (2 * j + 1) ≤ 2 * (n * n) + 4) (hhi : 2 * (n * n) + 4 < (2 * j + 3) * (2 * j + 3)) : n * n < 2 * ((j + 1) * (j + 2)) ∧ ∀ k, k < j → ¬ n * n < 2 * ((k + 1) * (k + 2)) := by have e1 : (2 * j + 1) * (2 * j + 1) = 4 * (j * j) + 4 * j + 1 := by ring have e2 : (2 * j + 3) * (2 * j + 3) = 4 * (j * j) + 12 * j + 9 := by ring have e3 : (j + 1) * (j + 2) = j * j + 3 * j + 2 := by ring have e4 : j * (j + 1) = j * j + j := by ring have hne := sq_add_one_ne n j constructor · omega · intro k hk hw have hm : (k + 1) * (k + 2) ≤ j * (j + 1) := Nat.mul_le_mul (by omega) (by omega) omega /-- **Oudra's conjecture for A248183.** For every n > 1, the least k >= 1 with 1/4 - Sum_{h = 1..k} 1/(h(h+1)(h+2)) < 1/n^2 is floor(sqrt(n^2/2 + 1) - 1/2). -/ theorem oudra_conjecture (n : ℕ) (hn : 2 ≤ n) : IsLeast {k : ℕ | 1 ≤ k ∧ 1 / 4 - s k < 1 / (n : ℚ) ^ 2} ⌊Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) - 1 / 2⌋₊ := by have hy : (0 : ℝ) ≤ (n : ℝ) ^ 2 / 2 + 1 := by positivity have hsq : Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) ^ 2 = (n : ℝ) ^ 2 / 2 + 1 := Real.sq_sqrt hy have hs0 : 0 ≤ Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) := Real.sqrt_nonneg _ have hs1 : 1 ≤ Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) := by by_contra hlt rw [not_le] at hlt nlinarith [mul_nonneg hs0 (sub_nonneg.mpr hlt.le), sq_nonneg (n : ℝ)] have hx : (0 : ℝ) ≤ Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) - 1 / 2 := by linarith have h1 := Nat.floor_le hx have h2 := Nat.lt_floor_add_one (Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) - 1 / 2) generalize ⌊Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) - 1 / 2⌋₊ = j at h1 h2 ⊢ have hj0 : (0 : ℝ) ≤ j := Nat.cast_nonneg j have hlo : ((j : ℝ) + 1 / 2) ^ 2 ≤ (n : ℝ) ^ 2 / 2 + 1 := by have a : 0 ≤ Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) - ((j : ℝ) + 1 / 2) := by linarith have b : 0 ≤ Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) + ((j : ℝ) + 1 / 2) := by linarith nlinarith [mul_nonneg a b] have hhi : (n : ℝ) ^ 2 / 2 + 1 < ((j : ℝ) + 3 / 2) ^ 2 := by have a : 0 < ((j : ℝ) + 3 / 2) - Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) := by linarith have b : 0 < ((j : ℝ) + 3 / 2) + Real.sqrt ((n : ℝ) ^ 2 / 2 + 1) := by linarith nlinarith [mul_pos a b] have hloN : (2 * j + 1) * (2 * j + 1) ≤ 2 * (n * n) + 4 := by have h : ((2 * j + 1) * (2 * j + 1) : ℝ) ≤ 2 * (n * n) + 4 := by nlinarith exact_mod_cast h have hhiN : 2 * (n * n) + 4 < (2 * j + 3) * (2 * j + 3) := by have h : (2 * (n * n) + 4 : ℝ) < (2 * j + 3) * (2 * j + 3) := by nlinarith exact_mod_cast h obtain ⟨hw, hmin⟩ := core n j hloN hhiN have hj1 : 1 ≤ j := by by_contra h0 have hz : j = 0 := by omega subst hz have := Nat.mul_le_mul hn hn omega constructor · exact ⟨hj1, (cond_iff n j (by omega)).mpr hw⟩ · intro k hk obtain ⟨_, hk2⟩ := hk by_contra hlt exact hmin k (by omega) ((cond_iff n k (by omega)).mp hk2) end A248183 #print axioms A248183.oudra_conjecture