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.ContDiff.Operations |
| 2 | import Mathlib.Analysis.Calculus.FDeriv.OfCompLeft |
| 3 | |
| 4 | /-! |
| 5 | # Smooth inverses on subsets |
| 6 | |
| 7 | An already continuous inverse is smooth up to the boundary when the forward |
| 8 | map has an invertible derivative with smooth dependence on the point. |
| 9 | -/ |
| 10 | |
| 11 | set_option autoImplicit false |
| 12 | |
| 13 | open Set Filter |
| 14 | open scoped Topology ContDiff |
| 15 | |
| 16 | namespace PoincareMT |
| 17 | |
| 18 | theorem contDiffOn_inverse_of_derivative |
| 19 | {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] |
| 20 | [NormedAddCommGroup F] [NormedSpace ℝ F] |
| 21 | {f : E → F} {g : F → E} {s : Set E} {t : Set F} |
| 22 | (f' : E → E →L[ℝ] F) |
| 23 | (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) |
| 24 | (hinv : ∀ x ∈ s, (f' x).IsInvertible) |
| 25 | (hf' : ContDiffOn ℝ ∞ f' s) |
| 26 | (hg : ContinuousOn g t) (hgs : MapsTo g t s) |
| 27 | (hfg : ∀ y ∈ t, f (g y) = y) : ContDiffOn ℝ ∞ g t := by |
| 28 | have hderiv (y : F) (hy : y ∈ t) : |
| 29 | HasFDerivWithinAt g (f' (g y)).inverse t y := by |
| 30 | obtain ⟨e, he⟩ := hinv (g y) (hgs hy) |
| 31 | rw [← he, ContinuousLinearMap.inverse_equiv] |
| 32 | apply HasFDerivWithinAt.of_local_left_inverse ((hg y hy).tendsto_nhdsWithin hgs) |
| 33 | (he ▸ hf (g y) (hgs hy)) hy (eventually_nhdsWithin_of_forall hfg) |
| 34 | apply contDiffOn_infty.mpr |
| 35 | intro k |
| 36 | induction k with |
| 37 | | zero => exact contDiffOn_zero.mpr hg |
| 38 | | succ k ih => |
| 39 | rw [Nat.cast_add, Nat.cast_one] |
| 40 | apply (contDiffOn_succ_iff_hasFDerivWithinAt (by simp)).mpr |
| 41 | intro y hy |
| 42 | refine ⟨t, by simpa [insert_eq_of_mem hy] using self_mem_nhdsWithin, |
| 43 | by simp, fun z => (f' (g z)).inverse, hderiv, ?_⟩ |
| 44 | have hi : ContDiffOn ℝ k |
| 45 | (fun x => ContinuousLinearMap.inverse (f' x)) s := by |
| 46 | intro x hx |
| 47 | obtain ⟨e, he⟩ := hinv x hx |
| 48 | exact (he ▸ contDiffAt_map_inverse e).comp_contDiffWithinAt x |
| 49 | (contDiffOn_infty.mp hf' k x hx) |
| 50 | exact hi.comp ih hgs |
| 51 | |
| 52 | theorem contDiffOn_inverse_of_invertible_fderivWithin |
| 53 | {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] |
| 54 | [NormedAddCommGroup F] [NormedSpace ℝ F] |
| 55 | {f : E → F} {g : F → E} {s : Set E} {t : Set F} |
| 56 | (hf : ContDiffOn ℝ ∞ f s) (hs : UniqueDiffOn ℝ s) |
| 57 | (hinv : ∀ x ∈ s, (fderivWithin ℝ f s x).IsInvertible) |
| 58 | (hg : ContinuousOn g t) (hgs : MapsTo g t s) |
| 59 | (hfg : ∀ y ∈ t, f (g y) = y) : ContDiffOn ℝ ∞ g t := by |
| 60 | exact contDiffOn_inverse_of_derivative (fderivWithin ℝ f s) |
| 61 | (fun x hx => (hf.differentiableOn (by simp) x hx).hasFDerivWithinAt) |
| 62 | hinv (hf.fderivWithin hs (by simp)) hg hgs hfg |
| 63 | |
| 64 | end PoincareMT |