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 PoincareLib.Analysis.Convex.UpperSupport |
| 2 | import Mathlib.Analysis.Calculus.Deriv.AffineMap |
| 3 | import Mathlib.Analysis.InnerProductSpace.Calculus |
| 4 | |
| 5 | /-! |
| 6 | # Concavity from upper supports in a real inner product space |
| 7 | |
| 8 | Restriction to affine lines turns the second Frechet derivative bound into |
| 9 | the scalar upper-support criterion. No differentiability of the supported |
| 10 | function is required. |
| 11 | -/ |
| 12 | |
| 13 | noncomputable section |
| 14 | set_option autoImplicit false |
| 15 | set_option backward.isDefEq.respectTransparency false |
| 16 | |
| 17 | open Set Filter |
| 18 | open scoped Topology |
| 19 | |
| 20 | namespace Poincare.Analysis |
| 21 | |
| 22 | section Normed |
| 23 | |
| 24 | variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 25 | |
| 26 | /-- Along an affine line the second derivative is the second Frechet |
| 27 | derivative evaluated twice on its constant velocity. -/ |
| 28 | theorem second_deriv_comp_lineMap {u : E → ℝ} {x y : E} {t : ℝ} |
| 29 | (hu : ContDiffAt ℝ 2 u (AffineMap.lineMap x y t)) : |
| 30 | deriv (deriv (u ∘ AffineMap.lineMap x y)) t = |
| 31 | fderiv ℝ (fderiv ℝ u) (AffineMap.lineMap x y t) (y - x) (y - x) := by |
| 32 | let L : ℝ → E := AffineMap.lineMap x y |
| 33 | have hL (s : ℝ) : HasDerivAt L (y - x) s := AffineMap.hasDerivAt_lineMap |
| 34 | have hfirst : deriv (u ∘ L) =ᶠ[𝓝 t] fun s => fderiv ℝ u (L s) (y - x) := by |
| 35 | filter_upwards [(hL t).continuousAt.eventually (hu.eventually (by norm_num))] with s hs |
| 36 | exact (hs.differentiableAt (by norm_num)).hasFDerivAt.comp_hasDerivAt s (hL s) |>.deriv |
| 37 | have hdu : DifferentiableAt ℝ (fderiv ℝ u) (L t) := |
| 38 | (hu.fderiv_right (m := 1) (by norm_num)).differentiableAt (by norm_num) |
| 39 | have hsecond := (hdu.hasFDerivAt.comp_hasDerivAt t (hL t)).clm_apply |
| 40 | (hasDerivAt_const t (y - x)) |
| 41 | rw [hfirst.deriv_eq] |
| 42 | simpa using hsecond.deriv |
| 43 | |
| 44 | /-- Nonpositive second derivatives of smooth touching upper supports imply |
| 45 | concavity on any convex set. -/ |
| 46 | theorem concaveOn_of_hessian_upper_support {s : Set E} {f : E → ℝ} |
| 47 | (hs : Convex ℝ s) (hf : ContinuousOn f s) |
| 48 | (hsupport : ∀ x ∈ s, ∃ u : E → ℝ, ContDiffAt ℝ 2 u x ∧ u x = f x ∧ |
| 49 | (∀ᶠ y in 𝓝 x, f y ≤ u y) ∧ |
| 50 | ∀ v : E, fderiv ℝ (fderiv ℝ u) x v v ≤ 0) : |
| 51 | ConcaveOn ℝ s f := by |
| 52 | refine ⟨hs, ?_⟩ |
| 53 | intro x hx y hy a b ha hb hab |
| 54 | let L : ℝ → E := AffineMap.lineMap x y |
| 55 | have hL : Continuous L := by dsimp [L]; fun_prop |
| 56 | have hmem : MapsTo L (Icc 0 1) s := fun t ht => hs.lineMap_mem hx hy ht |
| 57 | have hc : ConcaveOn ℝ (Icc (0 : ℝ) 1) (f ∘ L) := by |
| 58 | apply concaveOn_of_approximate_upper_support |
| 59 | (hf.comp hL.continuousOn hmem) |
| 60 | intro t ht ε hε |
| 61 | obtain ⟨u, hu, htouch, hupper, hsecond⟩ := |
| 62 | hsupport (L t) (hmem ⟨ht.1.le, ht.2.le⟩) |
| 63 | refine ⟨u ∘ L, hu.comp t (by |
| 64 | change ContDiffAt ℝ 2 (fun z : ℝ => z • (y - x) + x) t |
| 65 | fun_prop), htouch, |
| 66 | (hL.continuousAt.eventually hupper), ?_⟩ |
| 67 | rw [second_deriv_comp_lineMap hu] |
| 68 | exact (hsecond (y - x)).trans hε.le |
| 69 | have h := hc.2 (show (0 : ℝ) ∈ Icc 0 1 by constructor <;> norm_num) |
| 70 | (show (1 : ℝ) ∈ Icc 0 1 by constructor <;> norm_num) ha hb hab |
| 71 | have haeq : 1 - b = a := by linarith |
| 72 | have heq : b • (y - x) + x = a • x + b • y := by |
| 73 | rw [← haeq, sub_smul, one_smul, smul_sub] |
| 74 | abel |
| 75 | simpa [L, Function.comp_def, AffineMap.lineMap_apply, heq] using h |
| 76 | |
| 77 | end Normed |
| 78 | |
| 79 | variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] |
| 80 | |
| 81 | /-- A uniform upper Hessian bound on touching supports gives concavity |
| 82 | after subtraction of the corresponding norm-square quadratic. -/ |
| 83 | theorem concaveOn_sub_norm_sq_of_hessian_upper_support |
| 84 | {s : Set E} {f : E → ℝ} {C : ℝ} |
| 85 | (hs : Convex ℝ s) (hf : ContinuousOn f s) |
| 86 | (hsupport : ∀ x ∈ s, ∃ u : E → ℝ, ContDiffAt ℝ 2 u x ∧ u x = f x ∧ |
| 87 | (∀ᶠ y in 𝓝 x, f y ≤ u y) ∧ |
| 88 | ∀ v : E, fderiv ℝ (fderiv ℝ u) x v v ≤ C * ‖v‖ ^ 2) : |
| 89 | ConcaveOn ℝ s (fun x => f x - C * ‖x‖ ^ 2 / 2) := by |
| 90 | let q : E → ℝ := fun x => C * ‖x‖ ^ 2 / 2 |
| 91 | have hqc : ContDiff ℝ 2 q := by |
| 92 | exact (contDiff_const.mul (contDiff_norm_sq ℝ)).div_const 2 |
| 93 | have hqd (x : E) : HasFDerivAt q (C • innerSL ℝ x) x := by |
| 94 | have h := (hasStrictFDerivAt_norm_sq x).hasFDerivAt.fun_const_smul (C / 2) |
| 95 | have hcoef : (C / 2) • (2 • innerSL ℝ x) = C • innerSL ℝ x := by |
| 96 | ext v |
| 97 | simp |
| 98 | ring |
| 99 | rw [hcoef] at h |
| 100 | simpa only [q, smul_eq_mul, div_mul_eq_mul_div] using h |
| 101 | have hqfirst : fderiv ℝ q = fun x => C • innerSL ℝ x := |
| 102 | funext fun x => (hqd x).fderiv |
| 103 | have hqsecond (x v : E) : fderiv ℝ (fderiv ℝ q) x v v = C * ‖v‖ ^ 2 := by |
| 104 | rw [hqfirst, ((innerSL ℝ).hasFDerivAt.fun_const_smul C).fderiv] |
| 105 | change C * inner ℝ v v = C * ‖v‖ ^ 2 |
| 106 | rw [real_inner_self_eq_norm_sq] |
| 107 | apply concaveOn_of_hessian_upper_support hs (hf.sub hqc.continuous.continuousOn) |
| 108 | intro x hx |
| 109 | obtain ⟨u, hu, htouch, hupper, hbound⟩ := hsupport x hx |
| 110 | refine ⟨fun y => u y - q y, hu.sub hqc.contDiffAt, by simp [htouch], |
| 111 | hupper.mono (fun y hy => sub_le_sub_right hy (q y)), ?_⟩ |
| 112 | intro v |
| 113 | have hfirst : fderiv ℝ (fun y => u y - q y) =ᶠ[𝓝 x] |
| 114 | fun y => fderiv ℝ u y - fderiv ℝ q y := by |
| 115 | filter_upwards [hu.eventually (by norm_num)] with y hy |
| 116 | exact fderiv_sub (hy.differentiableAt (by norm_num)) |
| 117 | (hqc.differentiable (by norm_num) y) |
| 118 | rw [hfirst.fderiv_eq, fderiv_fun_sub |
| 119 | ((hu.fderiv_right (m := 1) (by norm_num)).differentiableAt (by norm_num)) |
| 120 | (((hqc.contDiffAt).fderiv_right (m := 1) (by norm_num)).differentiableAt (by norm_num))] |
| 121 | simp only [sub_apply, hqsecond] |
| 122 | exact sub_nonpos.mpr (hbound v) |
| 123 | |
| 124 | end Poincare.Analysis |