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.Calculus.DerivativeTest |
| 2 | import Mathlib.Analysis.Calculus.FDeriv.Symmetric |
| 3 | import Mathlib.Analysis.Calculus.LocalExtr.Basic |
| 4 | import Mathlib.Analysis.Calculus.Deriv.Mul |
| 5 | |
| 6 | /-! |
| 7 | # The kernel of the actual Hessian at a local minimum |
| 8 | |
| 9 | Line restrictions give nonnegative diagonal values. A second line argument |
| 10 | shows that every zero diagonal vector annihilates a symmetric positive form. |
| 11 | -/ |
| 12 | |
| 13 | set_option autoImplicit false |
| 14 | set_option backward.isDefEq.respectTransparency false |
| 15 | |
| 16 | open scoped ContDiff Topology |
| 17 | open Filter |
| 18 | |
| 19 | namespace PoincareMT.ReducedLength |
| 20 | |
| 21 | variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 22 | |
| 23 | theorem localMin_secondDeriv_nonneg (f : ℝ → ℝ) (x : ℝ) |
| 24 | (hf : ContinuousAt f x) (hmin : IsLocalMin f x) : 0 ≤ deriv (deriv f) x := by |
| 25 | by_contra h |
| 26 | have hneg : deriv (deriv f) x < 0 := lt_of_not_ge h |
| 27 | have hmax := isLocalMax_of_deriv_deriv_neg hneg hmin.deriv_eq_zero hf |
| 28 | have heq : f =ᶠ[𝓝 x] fun _ ↦ f x := by |
| 29 | filter_upwards [hmin, hmax] with y hlow hupp |
| 30 | exact le_antisymm hupp hlow |
| 31 | have hdeq : deriv f =ᶠ[𝓝 x] fun _ ↦ (0 : ℝ) := by |
| 32 | filter_upwards [heq.deriv] with y hy |
| 33 | simpa only [deriv_const] using hy |
| 34 | have hzero : deriv (deriv f) x = 0 := by |
| 35 | simpa only [deriv_const] using hdeq.deriv_eq |
| 36 | exact hneg.ne hzero |
| 37 | |
| 38 | theorem localMin_secondFDeriv_nonneg (f : E → ℝ) (x : E) |
| 39 | (hf : ContDiffAt ℝ ∞ f x) (hmin : IsLocalMin f x) (v : E) : |
| 40 | 0 ≤ fderiv ℝ (fderiv ℝ f) x v v := by |
| 41 | let a : ℝ → E := fun t ↦ x + t • v |
| 42 | have ha (t : ℝ) : HasDerivAt a v t := by |
| 43 | simpa only [a, id_eq, one_smul] using ((hasDerivAt_id t).smul_const v).const_add x |
| 44 | have ha0 : a 0 = x := by simp only [a, zero_smul, add_zero] |
| 45 | have hnear : ∀ᶠ y in 𝓝 x, DifferentiableAt ℝ f y := |
| 46 | ((hf.of_le (show (1 : ℕ∞ω) ≤ ∞ by simp)).eventually (by simp)).mono |
| 47 | (fun y hy ↦ hy.differentiableAt (by simp)) |
| 48 | have hfirst : deriv (f ∘ a) =ᶠ[𝓝 (0 : ℝ)] fun t ↦ fderiv ℝ f (a t) v := by |
| 49 | have hnear' : ∀ᶠ t in 𝓝 (0 : ℝ), DifferentiableAt ℝ f (a t) := |
| 50 | ((ha 0).continuousAt.tendsto.mono_right (by rw [ha0])).eventually hnear |
| 51 | filter_upwards [hnear'] with t ht |
| 52 | exact (ht.hasFDerivAt.comp_hasDerivAt t (ha t)).deriv |
| 53 | have hD : DifferentiableAt ℝ (fderiv ℝ f) (a 0) := by |
| 54 | rw [ha0] |
| 55 | exact (hf.fderiv_right (m := ∞) (by simp)).differentiableAt (by simp) |
| 56 | have hsecond : HasDerivAt (fun t ↦ fderiv ℝ f (a t) v) |
| 57 | (fderiv ℝ (fderiv ℝ f) x v v) 0 := by |
| 58 | simpa only [Function.comp_apply, ha0, map_zero, add_zero] using |
| 59 | (hD.hasFDerivAt.comp_hasDerivAt 0 (ha 0)).clm_apply (hasDerivAt_const 0 v) |
| 60 | have hmin' : IsLocalMin (f ∘ a) 0 := by |
| 61 | have h := (ha 0).continuousAt.preimage_mem_nhds (show {y | f x ≤ f y} ∈ 𝓝 (a 0) from |
| 62 | ha0.symm ▸ hmin) |
| 63 | change ∀ᶠ t in 𝓝 (0 : ℝ), f (a 0) ≤ f (a t) |
| 64 | rw [ha0] |
| 65 | exact h |
| 66 | have hf' : ContinuousAt (f ∘ a) 0 := by |
| 67 | apply ContinuousAt.comp _ (ha 0).continuousAt |
| 68 | simpa only [ha0] using hf.continuousAt |
| 69 | have hpos := localMin_secondDeriv_nonneg (f ∘ a) 0 hf' hmin' |
| 70 | rwa [hfirst.deriv_eq, hsecond.deriv] at hpos |
| 71 | |
| 72 | theorem positiveSymmetricForm_zero_diagonal |
| 73 | (B : E →L[ℝ] E →L[ℝ] ℝ) (hsymm : ∀ v w, B v w = B w v) |
| 74 | (hpos : ∀ v, 0 ≤ B v v) (v : E) (hzero : B v v = 0) (w : E) : B v w = 0 := by |
| 75 | let a : ℝ → E := fun t ↦ v + t • w |
| 76 | have ha : HasDerivAt a w 0 := by |
| 77 | simpa only [a, id_eq, one_smul] using ((hasDerivAt_id (0 : ℝ)).smul_const w).const_add v |
| 78 | have hd : HasDerivAt (fun t ↦ B (a t) (a t)) (B w v + B v w) 0 := by |
| 79 | simpa only [Function.comp_apply, a, zero_smul, add_zero] using |
| 80 | (B.hasFDerivAt.comp_hasDerivAt 0 ha).clm_apply ha |
| 81 | have hmin : IsLocalMin (fun t ↦ B (a t) (a t)) 0 := by |
| 82 | apply Filter.Eventually.of_forall |
| 83 | intro t |
| 84 | simpa only [a, zero_smul, add_zero, hzero] using hpos (a t) |
| 85 | have hstat := hmin.hasDerivAt_eq_zero hd |
| 86 | rw [hsymm w v] at hstat |
| 87 | linarith |
| 88 | |
| 89 | theorem localMin_secondFDeriv_zero_diagonal (f : E → ℝ) (x : E) |
| 90 | (hf : ContDiffAt ℝ ∞ f x) (hmin : IsLocalMin f x) |
| 91 | (v : E) (hv : fderiv ℝ (fderiv ℝ f) x v v = 0) (w : E) : |
| 92 | fderiv ℝ (fderiv ℝ f) x v w = 0 := by |
| 93 | have htwo : (2 : ℕ∞ω) ≤ ∞ := ENat.natCast_le_of_coe_top_le_withTop le_rfl 2 |
| 94 | apply positiveSymmetricForm_zero_diagonal (fderiv ℝ (fderiv ℝ f) x) |
| 95 | (fun v w ↦ hf.isSymmSndFDerivAt (by simpa using htwo) v w) |
| 96 | (localMin_secondFDeriv_nonneg f x hf hmin) v hv w |
| 97 | |
| 98 | end PoincareMT.ReducedLength |