Poincaré conjecture: the Lean proof, cleaned up together
The 2026 Lean proof of the Poincaré conjecture after Morgan and Tian, 3 million lines, cleaned up together: smaller, faster to build, more readable, the theorems unchanged

| 1 | import Mathlib.Analysis.ODE.Gronwall |
| 2 | import Mathlib.Analysis.Calculus.Deriv.MeanValue |
| 3 | |
| 4 | /-! |
| 5 | # Scalar Gronwall comparison with interior derivatives |
| 6 | |
| 7 | An integrating factor compares a real function to the exact affine |
| 8 | Gronwall solution on a closed interval. Differentiability is needed only |
| 9 | in the interior, and no sign conditions on the coefficients or the |
| 10 | function are required. This is used in Morgan-Tian Section 12.5, |
| 11 | pp. 309-319; see finite-neighbor-energy-closure.md. |
| 12 | -/ |
| 13 | |
| 14 | set_option autoImplicit false |
| 15 | |
| 16 | open Set |
| 17 | |
| 18 | /-- An affine scalar differential inequality with only interior |
| 19 | derivatives gives the exact Gronwall bound on the closed interval |
| 20 | (Section 12.5, pp. 309-319). -/ |
| 21 | theorem le_gronwallBound_of_interior_deriv_le |
| 22 | {f : ℝ → ℝ} {a b C ε δ : ℝ} (hf : ContinuousOn f (Icc a b)) |
| 23 | (hd : ∀ t ∈ Ioo a b, DifferentiableAt ℝ f t) |
| 24 | (hfa : f a ≤ δ) |
| 25 | (hr : ∀ t ∈ Ioo a b, deriv f t ≤ C * f t + ε) : |
| 26 | ∀ t ∈ Icc a b, f t ≤ gronwallBound δ C ε (t - a) := by |
| 27 | let g : ℝ → ℝ := fun t => gronwallBound δ C ε (t - a) |
| 28 | have hgd (t : ℝ) : HasDerivAt g (C * g t + ε) t := |
| 29 | hasDerivAt_gronwallBound_shift δ C ε t a |
| 30 | have hg : Continuous g := continuous_iff_continuousAt.mpr (fun t => (hgd t).continuousAt) |
| 31 | let H : ℝ → ℝ := fun t => Real.exp (-C * (t - a)) * (f t - g t) |
| 32 | have hH : ContinuousOn H (Icc a b) := |
| 33 | (Real.continuous_exp.comp |
| 34 | (continuous_const.mul (continuous_id.sub continuous_const))).continuousOn.mul |
| 35 | (hf.sub hg.continuousOn) |
| 36 | have hHd (t : ℝ) (ht : t ∈ Ioo a b) : |
| 37 | HasDerivAt H (Real.exp (-C * (t - a)) * (deriv f t - C * f t - ε)) t := by |
| 38 | convert! (((hasDerivAt_id t).sub_const a).const_mul (-C)).exp.mul |
| 39 | ((hd t ht).hasDerivAt.sub (hgd t)) using 1 |
| 40 | simp only [id_eq, Pi.sub_apply] |
| 41 | ring |
| 42 | have hanti : AntitoneOn H (Icc a b) := by |
| 43 | apply antitoneOn_of_deriv_nonpos (convex_Icc a b) hH |
| 44 | · intro t ht |
| 45 | rw [interior_Icc] at ht |
| 46 | exact (hHd t ht).differentiableAt.differentiableWithinAt |
| 47 | · intro t ht |
| 48 | rw [interior_Icc] at ht |
| 49 | rw [(hHd t ht).deriv] |
| 50 | exact mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos _).le (by linarith [hr t ht]) |
| 51 | intro t ht |
| 52 | have hle := hanti (show a ∈ Icc a b from ⟨le_rfl, ht.1.trans ht.2⟩) ht ht.1 |
| 53 | have hHa : H a ≤ 0 := by |
| 54 | simpa only [H, g, sub_self, gronwallBound_x0, mul_zero, Real.exp_zero, one_mul] |
| 55 | using sub_nonpos.mpr hfa |
| 56 | exact sub_nonpos.mp (nonpos_of_mul_nonpos_right (hle.trans hHa) (Real.exp_pos _)) |