Lean / Reader
Lean reader

DeskNarrowAudit.lean

383 lines27 declarationsno sorryimports Mathlib.Analysis.Asymptotics.AsymptoticEquivalent Mathlib.Analysis.SpecialFunctions.Log.Basic Mathlib.Data.Finset.Max Mathlib.Data.Finset.Sort Mathlib.Data.Nat.Factorial.BigOperators Mathlib.Data.Nat.Lattice +2
  1. import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent
  2. import Mathlib.Analysis.SpecialFunctions.Log.Basic
  3. import Mathlib.Data.Finset.Max
  4. import Mathlib.Data.Finset.Sort
  5. import Mathlib.Data.Nat.Factorial.BigOperators
  6. import Mathlib.Data.Nat.Lattice
  7. import Mathlib.Order.Interval.Finset.Nat
  8. import Mathlib.Tactic.NormNum
  9. /-!
  10. # Exact definitions for Erdős Problem 390
  11. This file fixes the literal finite combinatorial object and the exact
  12. asymptotic target used by the paper. A `Finset` represents the distinct
  13. factors: after sorting it, its elements are precisely a strictly increasing
  14. list `a₁ < ... < aₖ`.
  15. The quotient `M! / (n!)²` is deliberately valued in `ℚ`. It must not be
  16. defined with `Nat.div`: before admissibility has been proved, `(n!)²` need
  17. not divide `M!`.
  18. -/
  19. open Filter Topology
  20. open scoped BigOperators
  21. namespace Erdos390.WholePaper
  22. noncomputable section
  23. /-- The literal integer interval `(n, M]` from the paper. -/
  24. def factorInterval (n M : ℕ) : Finset ℕ :=
  25. Finset.Ioc n M
  26. /-- A factorization of `n!` into distinct integers in `(n, M]`. -/
  27. def IsAdmissibleEndpoint (n M : ℕ) : Prop :=
  28. ∃ factors : Finset ℕ,
  29. factors ⊆ factorInterval n M ∧ factors.prod id = n.factorial
  30. /-- For `n ≥ 3`, the singleton factorization `{n!}` supplies an endpoint. -/
  31. theorem exists_admissibleEndpoint {n : ℕ} (hn : 3 ≤ n) :
  32. ∃ M, IsAdmissibleEndpoint n M := by
  33. refine ⟨n.factorial, {n.factorial}, ?_, by simp⟩
  34. intro a ha
  35. have ha' : a = n.factorial := by simpa using ha
  36. subst a
  37. simp [factorInterval, Nat.lt_factorial_self hn]
  38. /-- The Erdős--Guy--Selfridge extremal function. For `n ≥ 3` this is the
  39. least possible upper endpoint, hence the least possible largest factor.
  40. The value outside the paper's domain is set to zero only to make the
  41. function total. -/
  42. def f (n : ℕ) : ℕ :=
  43. by
  44. classical
  45. exact if hn : 3 ≤ n then Nat.find (exists_admissibleEndpoint hn) else 0
  46. /-- The exact rational constant in the paper. -/
  47. def C0 : ℝ :=
  48. (4029639598 : ℝ) / 25970038185
  49. /-- The natural second-order scale `n / log n`. -/
  50. def secondOrderScale (n : ℕ) : ℝ :=
  51. (n : ℝ) / Real.log (n : ℝ)
  52. /-- The error in the paper's asserted expansion. -/
  53. def mainError (n : ℕ) : ℝ :=
  54. (f n : ℝ) -
  55. (2 * (n : ℝ) + C0 * secondOrderScale n)
  56. /-- Literal small-`o` formulation of the main asymptotic formula. -/
  57. def MainAsymptotic : Prop :=
  58. (mainError =o[atTop] secondOrderScale)
  59. /-- Equivalent normalized-limit expression displayed in the paper. -/
  60. def MainNormalizedLimit : Prop :=
  61. Tendsto
  62. (fun n : ℕ =>
  63. (((f n : ℝ) - 2 * (n : ℝ)) * Real.log (n : ℝ)) / (n : ℝ))
  64. atTop (nhds C0)
  65. theorem f_spec {n : ℕ} (hn : 3 ≤ n) :
  66. IsAdmissibleEndpoint n (f n) := by
  67. classical
  68. rw [f, dif_pos hn]
  69. exact Nat.find_spec (exists_admissibleEndpoint hn)
  70. theorem f_le_of_admissible {n M : ℕ} (hn : 3 ≤ n)
  71. (hM : IsAdmissibleEndpoint n M) :
  72. f n ≤ M := by
  73. classical
  74. rw [f, dif_pos hn]
  75. exact Nat.find_min' (exists_admissibleEndpoint hn) hM
  76. theorem admissible_mono {n M M' : ℕ} (hM : M ≤ M')
  77. (h : IsAdmissibleEndpoint n M) :
  78. IsAdmissibleEndpoint n M' := by
  79. obtain ⟨s, hs, hprod⟩ := h
  80. refine ⟨s, ?_, hprod⟩
  81. intro a ha
  82. have hai := Finset.mem_Ioc.mp (hs ha)
  83. exact Finset.mem_Ioc.mpr ⟨hai.1, hai.2.trans hM⟩
  84. /-- This characterizes `f` as the least legal endpoint, rather than merely
  85. as an implementation via `Nat.find`. -/
  86. theorem f_le_iff_admissible {n M : ℕ} (hn : 3 ≤ n) :
  87. f n ≤ M ↔ IsAdmissibleEndpoint n M := by
  88. constructor
  89. · intro h
  90. exact admissible_mono h (f_spec hn)
  91. · exact f_le_of_admissible hn
  92. end
  93. end Erdos390.WholePaper
  94. open Erdos390.WholePaper
  95. namespace DeskLargestFactor
  96. def PublishedEndpoint (n m : ℕ) : Prop :=
  97. ∃ factors : Finset ℕ, ∃ h : factors.Nonempty,
  98. factors.max' h = m ∧ (∀ a ∈ factors, n < a) ∧ factors.prod id = n.factorial
  99. theorem endpoint_is_admissible {n m : ℕ} (h : PublishedEndpoint n m) :
  100. IsAdmissibleEndpoint n m := by
  101. obtain ⟨factors, hne, hmax, hgt, hprod⟩ := h
  102. refine ⟨factors, ?_, hprod⟩
  103. intro a ha
  104. refine Finset.mem_Ioc.mpr ⟨hgt a ha, ?_⟩
  105. simpa only [hmax] using factors.le_max' a ha
  106. theorem f_is_least_published_endpoint {n : ℕ} (hn : 3 ≤ n) :
  107. IsLeast {m | PublishedEndpoint n m} (f n) := by
  108. obtain ⟨factors, hsubset, hprod⟩ := f_spec hn
  109. have hne : factors.Nonempty := by
  110. by_contra h
  111. rw [Finset.not_nonempty_iff_eq_empty.mp h, Finset.prod_empty] at hprod
  112. have hn' := Nat.factorial_eq_one.mp hprod.symm
  113. omega
  114. have hgt (a : ℕ) (ha : a ∈ factors) : n < a :=
  115. (Finset.mem_Ioc.mp (hsubset ha)).1
  116. have hmax_le : factors.max' hne ≤ f n :=
  117. (Finset.mem_Ioc.mp (hsubset (Finset.max'_mem factors hne))).2
  118. have hf_le : f n ≤ factors.max' hne :=
  119. f_le_of_admissible hn (endpoint_is_admissible ⟨factors, hne, rfl, hgt, hprod⟩)
  120. refine ⟨⟨factors, hne, le_antisymm hmax_le hf_le, hgt, hprod⟩, ?_⟩
  121. intro m hm
  122. exact f_le_of_admissible hn (endpoint_is_admissible hm)
  123. #print axioms f_is_least_published_endpoint
  124. end DeskLargestFactor
  125. /-!
  126. # Formal Conjectures bridge for Erdős 390
  127. This module deliberately has no dependency on the `formal-conjectures`
  128. repository. It gives a namespaced literal copy of that repository's
  129. extremal function, identifies it eventually with `Erdos390.WholePaper.f`,
  130. and exports the two conclusion shapes used upstream.
  131. The namespace is nested below `Erdos390.WholePaper`, so this module can be
  132. imported together with `FormalConjectures.ErdosProblems.390` without
  133. colliding with its declarations `Erdos390.f`, `Erdos390.erdos_390`, or
  134. `Erdos390.erdos_390.variants.theta`.
  135. -/
  136. open scoped Nat BigOperators
  137. open Filter Asymptotics Real
  138. namespace Erdos390.WholePaper.FormalConjecturesBridge
  139. noncomputable section
  140. /-! ## Literal Formal Conjectures endpoint model -/
  141. /-- The endpoint predicate used by the Formal Conjectures formulation. -/
  142. def FCAdmissible (n m : ℕ) : Prop :=
  143. ∃ k, ∃ g : ℕ → ℕ, StrictMono g ∧
  144. n < g 0 ∧ g (k - 1) = m ∧ ∏ i < k, g i = n.factorial
  145. /-- A literal, independently namespaced copy of the Formal Conjectures
  146. extremal function. -/
  147. noncomputable def formalF (n : ℕ) : ℕ :=
  148. sInf {m : ℕ | ∃ k, ∃ g : ℕ → ℕ, StrictMono g ∧
  149. n < g 0 ∧ g (k - 1) = m ∧ ∏ i < k, g i = n.factorial}
  150. theorem formalF_eq_sInf_FCAdmissible (n : ℕ) :
  151. formalF n = sInf {m : ℕ | FCAdmissible n m} := by
  152. rfl
  153. /-! ## Pointwise endpoint bridge -/
  154. /-- A Formal Conjectures strictly increasing prefix gives the corresponding
  155. finite set of distinct factors. -/
  156. theorem fcAdmissible_to_isAdmissibleEndpoint {n m : ℕ} (hn : 3 ≤ n)
  157. (h : FCAdmissible n m) :
  158. Erdos390.WholePaper.IsAdmissibleEndpoint n m := by
  159. rcases h with ⟨k, g, hg, hg0, hlast, hprod⟩
  160. rw [Nat.Iio_eq_range] at hprod
  161. have hk : 0 < k := by
  162. by_contra hnot
  163. have hk0 : k = 0 := Nat.eq_zero_of_not_pos hnot
  164. subst k
  165. simp only [Finset.range_zero, Finset.prod_empty] at hprod
  166. have hn_le_one : n ≤ 1 := Nat.factorial_eq_one.mp hprod.symm
  167. omega
  168. refine ⟨(Finset.range k).image g, ?_, ?_⟩
  169. · intro x hx
  170. rcases Finset.mem_image.mp hx with ⟨i, hi, rfl⟩
  171. have hi_lt : i < k := Finset.mem_range.mp hi
  172. rw [Erdos390.WholePaper.factorInterval, Finset.mem_Ioc]
  173. constructor
  174. · exact hg0.trans_le (hg.monotone (Nat.zero_le i))
  175. · rw [← hlast]
  176. exact hg.monotone (by omega)
  177. · calc
  178. ((Finset.range k).image g).prod id =
  179. (Finset.range k).prod (fun i ↦ id (g i)) :=
  180. Finset.prod_image hg.injective.injOn
  181. _ = n.factorial := by simpa using hprod
  182. /-- Every finite admissible set can be increasingly enumerated and extended
  183. to a globally strictly increasing sequence. -/
  184. theorem isAdmissibleEndpoint_to_exists_fcAdmissible {n M : ℕ} (hn : 3 ≤ n)
  185. (hM : Erdos390.WholePaper.IsAdmissibleEndpoint n M) :
  186. ∃ m ≤ M, FCAdmissible n m := by
  187. rcases hM with ⟨S, hS, hprod⟩
  188. have hS_nonempty : S.Nonempty := by
  189. by_contra hnot
  190. have hS0 : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hnot
  191. subst S
  192. simp only [Finset.prod_empty] at hprod
  193. have hn_le_one : n ≤ 1 := Nat.factorial_eq_one.mp hprod.symm
  194. omega
  195. let k : ℕ := S.card
  196. have hk : 0 < k := by
  197. simpa only [k] using Finset.card_pos.mpr hS_nonempty
  198. have hcard : S.card = k := rfl
  199. let e : Fin k ↪o ℕ := S.orderEmbOfFin hcard
  200. let g : ℕ → ℕ := fun i ↦
  201. if hi : i < k then e ⟨i, hi⟩ else M + i
  202. have hg : StrictMono g := by
  203. intro i j hij
  204. by_cases hi : i < k
  205. · by_cases hj : j < k
  206. · simp only [g, dif_pos hi, dif_pos hj]
  207. exact e.strictMono hij
  208. · have hei_mem : e ⟨i, hi⟩ ∈ S := by
  209. simpa only [e] using S.orderEmbOfFin_mem hcard ⟨i, hi⟩
  210. have hei_le : e ⟨i, hi⟩ ≤ M :=
  211. (Finset.mem_Ioc.mp (hS hei_mem)).2
  212. have hj_pos : 0 < j := by omega
  213. simp only [g, dif_pos hi, dif_neg hj]
  214. omega
  215. · have hj : ¬j < k := by omega
  216. simp only [g, dif_neg hi, dif_neg hj]
  217. omega
  218. have hlast_lt : k - 1 < k := by omega
  219. let m : ℕ := e ⟨k - 1, hlast_lt⟩
  220. have hm_mem : m ∈ S := by
  221. simpa only [m, e] using S.orderEmbOfFin_mem hcard ⟨k - 1, hlast_lt⟩
  222. have hm_le : m ≤ M := (Finset.mem_Ioc.mp (hS hm_mem)).2
  223. refine ⟨m, hm_le, k, g, hg, ?_, ?_, ?_⟩
  224. · have he0_mem : e ⟨0, hk⟩ ∈ S := by
  225. simpa only [e] using S.orderEmbOfFin_mem hcard ⟨0, hk⟩
  226. have hn_e0 : n < e ⟨0, hk⟩ :=
  227. (Finset.mem_Ioc.mp (hS he0_mem)).1
  228. simpa only [g, dif_pos hk] using hn_e0
  229. · simp only [g, m, dif_pos hlast_lt]
  230. · rw [Nat.Iio_eq_range]
  231. have himage : (Finset.range k).image g = S := by
  232. apply Finset.eq_of_subset_of_card_le
  233. · intro x hx
  234. rcases Finset.mem_image.mp hx with ⟨i, hi, rfl⟩
  235. have hi_lt : i < k := Finset.mem_range.mp hi
  236. simp only [g, dif_pos hi_lt]
  237. simpa only [e] using S.orderEmbOfFin_mem hcard ⟨i, hi_lt⟩
  238. · rw [Finset.card_image_of_injective _ hg.injective, Finset.card_range, hcard]
  239. calc
  240. (Finset.range k).prod g =
  241. ((Finset.range k).image g).prod id := by
  242. symm
  243. exact Finset.prod_image hg.injective.injOn
  244. _ = S.prod id := by rw [himage]
  245. _ = n.factorial := hprod
  246. /-- For `n ≥ 3`, the independently defined endpoint minima coincide. -/
  247. theorem formalF_eq_wholePaper_f {n : ℕ} (hn : 3 ≤ n) :
  248. formalF n = Erdos390.WholePaper.f n := by
  249. rw [formalF_eq_sInf_FCAdmissible]
  250. apply le_antisymm
  251. · obtain ⟨m, hm, hfc⟩ :=
  252. isAdmissibleEndpoint_to_exists_fcAdmissible hn
  253. (Erdos390.WholePaper.f_spec hn)
  254. exact (Nat.sInf_le hfc).trans hm
  255. · have hset_nonempty : Set.Nonempty {m : ℕ | FCAdmissible n m} := by
  256. obtain ⟨m, _hm, hfc⟩ :=
  257. isAdmissibleEndpoint_to_exists_fcAdmissible hn
  258. (Erdos390.WholePaper.f_spec hn)
  259. exact ⟨m, hfc⟩
  260. have hmin : FCAdmissible n (sInf {m : ℕ | FCAdmissible n m}) :=
  261. Nat.sInf_mem hset_nonempty
  262. exact Erdos390.WholePaper.f_le_of_admissible hn
  263. (fcAdmissible_to_isAdmissibleEndpoint hn hmin)
  264. /-- The two endpoint functions are eventually equal; the exceptional values
  265. `n < 3` are irrelevant to all `atTop` statements. -/
  266. theorem eventually_formalF_eq_wholePaper_f :
  267. formalF =ᶠ[atTop] Erdos390.WholePaper.f :=
  268. eventually_atTop.2 ⟨3, fun _n hn ↦ formalF_eq_wholePaper_f hn⟩
  269. /-! ## Small-o to asymptotic-equivalence wrapper -/
  270. private lemma C0_ne_zero : Erdos390.WholePaper.C0 ≠ 0 := by
  271. norm_num [Erdos390.WholePaper.C0]
  272. /-- The local literal small-o theorem implies equivalence with its fixed
  273. second-order coefficient. -/
  274. theorem wholePaper_isEquivalent_fixedC0_of_mainAsymptotic
  275. (h : Erdos390.WholePaper.MainAsymptotic) :
  276. (fun n : ℕ =>
  277. (Erdos390.WholePaper.f n : ℝ) - 2 * (n : ℝ)) ~[atTop]
  278. (fun n : ℕ =>
  279. Erdos390.WholePaper.C0 * (n : ℝ) / Real.log (n : ℝ)) := by
  280. have hsmall :
  281. Erdos390.WholePaper.mainError =o[atTop]
  282. Erdos390.WholePaper.secondOrderScale := by
  283. simpa only [Erdos390.WholePaper.MainAsymptotic] using h
  284. have hscaled :
  285. Erdos390.WholePaper.mainError =o[atTop]
  286. (fun n : ℕ =>
  287. Erdos390.WholePaper.C0 *
  288. Erdos390.WholePaper.secondOrderScale n) :=
  289. hsmall.const_mul_right C0_ne_zero
  290. rw [IsEquivalent]
  291. have hleft :
  292. (fun n : ℕ =>
  293. (Erdos390.WholePaper.f n : ℝ) - 2 * (n : ℝ)) -
  294. (fun n : ℕ =>
  295. Erdos390.WholePaper.C0 * (n : ℝ) /
  296. Real.log (n : ℝ)) =
  297. Erdos390.WholePaper.mainError := by
  298. funext n
  299. simp only [Pi.sub_apply, Erdos390.WholePaper.mainError,
  300. Erdos390.WholePaper.secondOrderScale, sub_add_eq_sub_sub,
  301. mul_div_assoc]
  302. rw [hleft]
  303. simpa only [Erdos390.WholePaper.secondOrderScale, mul_div_assoc] using hscaled
  304. /-- The local small-o theorem, together with the endpoint bridge, implies
  305. fixed-coefficient equivalence for the literal Formal Conjectures function. -/
  306. theorem formalF_isEquivalent_fixedC0_of_mainAsymptotic
  307. (h : Erdos390.WholePaper.MainAsymptotic) :
  308. (fun n : ℕ => (formalF n : ℝ) - 2 * (n : ℝ)) ~[atTop]
  309. (fun n : ℕ =>
  310. Erdos390.WholePaper.C0 * (n : ℝ) / Real.log (n : ℝ)) := by
  311. have hleft :
  312. (fun n : ℕ => (formalF n : ℝ) - 2 * (n : ℝ)) =ᶠ[atTop]
  313. (fun n : ℕ =>
  314. (Erdos390.WholePaper.f n : ℝ) - 2 * (n : ℝ)) :=
  315. eventually_formalF_eq_wholePaper_f.mono fun n hn ↦ by
  316. change
  317. (formalF n : ℝ) - 2 * (n : ℝ) =
  318. (Erdos390.WholePaper.f n : ℝ) - 2 * (n : ℝ)
  319. rw [hn]
  320. exact hleft.trans_isEquivalent
  321. (wholePaper_isEquivalent_fixedC0_of_mainAsymptotic h)
  322. /-- The problem's exact existential shape, conditional on the author's terminal. -/
  323. theorem problem_shape_of_terminal
  324. (h : Erdos390.WholePaper.MainAsymptotic) :
  325. ∃ c, (fun n => formalF n - 2 * n : ℕ → ℝ) ~[atTop]
  326. (fun n => c * n / log (n : ℝ)) :=
  327. ⟨Erdos390.WholePaper.C0, formalF_isEquivalent_fixedC0_of_mainAsymptotic h⟩
  328. #print axioms formalF_eq_wholePaper_f
  329. #print axioms problem_shape_of_terminal
  330. end
  331. end Erdos390.WholePaper.FormalConjecturesBridge