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.CompCLM |
| 3 | |
| 4 | /-! |
| 5 | # Second derivatives of a fixed composition |
| 6 | |
| 7 | Differentiate the actual identity `r composed with f = f` twice on open |
| 8 | domains, retaining an arbitrary tangent correction. MT2007 Claim 19.1, |
| 9 | p. 437; `2026-09-21-fixed-composition-second-derivative.md`. |
| 10 | -/ |
| 11 | |
| 12 | set_option autoImplicit false |
| 13 | |
| 14 | open Set Filter |
| 15 | open scoped Topology |
| 16 | |
| 17 | universe u v |
| 18 | |
| 19 | namespace PoincareMT.M63 |
| 20 | |
| 21 | variable {E : Type u} {F : Type v} |
| 22 | [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 23 | [NormedAddCommGroup F] [NormedSpace ℝ F] |
| 24 | |
| 25 | /-- First and second actual derivatives of a fixed composition, including |
| 26 | an arbitrary tangent correction in the second identity. MT2007 Claim 19.1, |
| 27 | p. 437; fixed-composition second-derivative derivation. -/ |
| 28 | theorem fixedComposition_second_derivative {S : Set E} {U : Set F} |
| 29 | (hS : IsOpen S) (hU : IsOpen U) {f : E → F} {r : F → F} |
| 30 | (hf : ContDiffOn ℝ 2 f S) (hr : ContDiffOn ℝ 2 r U) |
| 31 | (hfU : MapsTo f S U) (hfix : ∀ y ∈ S, r (f y) = f y) |
| 32 | {y : E} (hy : y ∈ S) : |
| 33 | (∀ v : E, fderiv ℝ r (f y) (fderiv ℝ f y v) = fderiv ℝ f y v) ∧ |
| 34 | ∀ v w c : E, |
| 35 | fderiv ℝ (fderiv ℝ r) (f y) (fderiv ℝ f y v) (fderiv ℝ f y w) + |
| 36 | fderiv ℝ r (f y) |
| 37 | (fderiv ℝ (fderiv ℝ f) y v w - fderiv ℝ f y c) = |
| 38 | fderiv ℝ (fderiv ℝ f) y v w - fderiv ℝ f y c := by |
| 39 | have hfd (z : E) (hz : z ∈ S) : HasFDerivAt f (fderiv ℝ f z) z := |
| 40 | ((hf.contDiffAt (hS.mem_nhds hz)).differentiableAt (by norm_num)).hasFDerivAt |
| 41 | have hrd (z : E) (hz : z ∈ S) : HasFDerivAt r (fderiv ℝ r (f z)) (f z) := |
| 42 | ((hr.contDiffAt (hU.mem_nhds (hfU hz))).differentiableAt (by norm_num)).hasFDerivAt |
| 43 | have hfirst (z : E) (hz : z ∈ S) : |
| 44 | (fderiv ℝ r (f z)).comp (fderiv ℝ f z) = fderiv ℝ f z := by |
| 45 | have heq : f =ᶠ[𝓝 z] r ∘ f := by |
| 46 | filter_upwards [hS.mem_nhds hz] with x hx |
| 47 | exact (hfix x hx).symm |
| 48 | exact (((hrd z hz).comp z (hfd z hz)).congr_of_eventuallyEq heq).unique (hfd z hz) |
| 49 | have happ (z : E) (hz : z ∈ S) (v : E) : |
| 50 | fderiv ℝ r (f z) (fderiv ℝ f z v) = fderiv ℝ f z v := |
| 51 | congrArg (fun L : E →L[ℝ] F => L v) (hfirst z hz) |
| 52 | refine ⟨happ y hy, ?_⟩ |
| 53 | intro v w c |
| 54 | have hDDf : HasFDerivAt (fderiv ℝ f) (fderiv ℝ (fderiv ℝ f) y) y := |
| 55 | (((hf.contDiffAt (hS.mem_nhds hy)).fderiv_right (m := 1) (by norm_num)).differentiableAt |
| 56 | (by norm_num)).hasFDerivAt |
| 57 | have hDDr : HasFDerivAt (fderiv ℝ r) (fderiv ℝ (fderiv ℝ r) (f y)) (f y) := |
| 58 | (((hr.contDiffAt (hU.mem_nhds (hfU hy))).fderiv_right (m := 1) |
| 59 | (by norm_num)).differentiableAt (by norm_num)).hasFDerivAt |
| 60 | have hw : HasFDerivAt (fun z => fderiv ℝ f z w) |
| 61 | ((fderiv ℝ (fderiv ℝ f) y).flip w) y := by |
| 62 | simpa only [ContinuousLinearMap.comp_zero, zero_add] using |
| 63 | hDDf.clm_apply (hasFDerivAt_const w y) |
| 64 | have heq : (fun z => fderiv ℝ f z w) =ᶠ[𝓝 y] |
| 65 | (fun z => fderiv ℝ r (f z) (fderiv ℝ f z w)) := by |
| 66 | filter_upwards [hS.mem_nhds hy] with z hz |
| 67 | exact (happ z hz w).symm |
| 68 | have hsecond := congrArg (fun L : E →L[ℝ] F => L v) |
| 69 | ((((hDDr.comp y (hfd y hy)).clm_apply hw).congr_of_eventuallyEq heq).unique hw) |
| 70 | simp only [add_apply, ContinuousLinearMap.comp_apply, |
| 71 | ContinuousLinearMap.flip_apply, Function.comp_apply] at hsecond |
| 72 | rw [add_comm] at hsecond |
| 73 | rw [map_sub, happ y hy c, ← add_sub_assoc, hsecond] |
| 74 | |
| 75 | end PoincareMT.M63 |