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.FDeriv.Extend |
| 2 | import Mathlib.Analysis.Calculus.FDeriv.Partial |
| 3 | import Mathlib.Analysis.Calculus.ContDiff.Comp |
| 4 | import Mathlib.Analysis.Calculus.ContDiff.Operations |
| 5 | |
| 6 | /-! |
| 7 | # Smooth evolution across finitely many exceptional times |
| 8 | |
| 9 | Continuous spatial jets and a smooth evolution operator depending on |
| 10 | finitely many jets recover joint smoothness across finitely many times. |
| 11 | This supplies the calculus for retained surgery gluing in Morgan--Tian, |
| 12 | Lemma 16.8 and Proposition 16.5, pp. 372-375; see M44 derivation 49. |
| 13 | -/ |
| 14 | |
| 15 | set_option autoImplicit false |
| 16 | |
| 17 | open Set Filter |
| 18 | open scoped ContDiff Topology |
| 19 | |
| 20 | namespace Poincare |
| 21 | |
| 22 | variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 23 | |
| 24 | /-- A continuous proposed derivative extends across one locally |
| 25 | exceptional time. Source: retained surgery gluing in Proposition |
| 26 | 16.5; M44 derivation 49, using Mathlib's derivative extension. -/ |
| 27 | theorem hasDerivAt_of_eventually_hasDerivAt_of_ne |
| 28 | {f g : ℝ → E} {t : ℝ} (hf : ContinuousAt f t) (hg : ContinuousAt g t) |
| 29 | (hderiv : ∀ᶠ s in 𝓝 t, s ≠ t → HasDerivAt f (g s) s) : |
| 30 | HasDerivAt f (g t) t := by |
| 31 | have hleft : ∀ᶠ s in 𝓝[<] t, HasDerivAt f (g s) s := by |
| 32 | filter_upwards [hderiv.filter_mono inf_le_left, self_mem_nhdsWithin] with s hs hst |
| 33 | exact hs (ne_of_lt hst) |
| 34 | have hright : ∀ᶠ s in 𝓝[>] t, HasDerivAt f (g s) s := by |
| 35 | filter_upwards [hderiv.filter_mono inf_le_left, self_mem_nhdsWithin] with s hs hst |
| 36 | exact hs (ne_of_gt hst) |
| 37 | have hL : HasDerivWithinAt f (g t) (Iic t) t := |
| 38 | hasDerivWithinAt_Iic_of_tendsto_deriv |
| 39 | (s := {s | HasDerivAt f (g s) s}) |
| 40 | (fun _ hs => hs.differentiableAt.differentiableWithinAt) hf.continuousWithinAt |
| 41 | hleft ((hg.mono_left inf_le_left).congr' (hleft.mono fun _ hs => hs.deriv.symm)) |
| 42 | have hR : HasDerivWithinAt f (g t) (Ici t) t := |
| 43 | hasDerivWithinAt_Ici_of_tendsto_deriv |
| 44 | (s := {s | HasDerivAt f (g s) s}) |
| 45 | (fun _ hs => hs.differentiableAt.differentiableWithinAt) hf.continuousWithinAt |
| 46 | hright ((hg.mono_left inf_le_left).congr' (hright.mono fun _ hs => hs.deriv.symm)) |
| 47 | simpa only [Iic_union_Ici, hasDerivWithinAt_univ] using hL.union hR |
| 48 | |
| 49 | /-- A continuous evolution equation holding off a finite set of |
| 50 | times holds also at those times. Source: retained surgery gluing in |
| 51 | Proposition 16.5, pp. 374-375; M44 derivation 49. -/ |
| 52 | theorem hasDerivAt_of_hasDerivAt_off_finite |
| 53 | {f g : ℝ → E} {J S : Set ℝ} (hJ : IsOpen J) (hS : S.Finite) |
| 54 | (hf : ContinuousOn f J) (hg : ContinuousOn g J) |
| 55 | (hderiv : ∀ t ∈ J, t ∉ S → HasDerivAt f (g t) t) |
| 56 | {t : ℝ} (ht : t ∈ J) : HasDerivAt f (g t) t := by |
| 57 | apply hasDerivAt_of_eventually_hasDerivAt_of_ne |
| 58 | (hf.continuousAt (hJ.mem_nhds ht)) (hg.continuousAt (hJ.mem_nhds ht)) |
| 59 | have hnear : (S \ {t})ᶜ ∈ 𝓝 t := |
| 60 | hS.sdiff.isClosed.isOpen_compl.mem_nhds (by simp) |
| 61 | filter_upwards [hJ.mem_nhds ht, hnear] with s hs houtside hne |
| 62 | exact hderiv s hs (fun hmem => houtside ⟨hmem, hne⟩) |
| 63 | |
| 64 | /-- Continuous spatial jets with a smooth finite-jet evolution |
| 65 | equation are jointly smooth, even when the original equation excludes |
| 66 | finitely many times. The coefficient spaces and number of required |
| 67 | jets may vary with order. Source: Lemma 16.8 and Proposition 16.5, |
| 68 | pp. 372-375; M44 derivation 49. -/ |
| 69 | theorem contDiffOn_of_finite_jet_evolution |
| 70 | {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] |
| 71 | {F : ℕ → Type*} [∀ i, NormedAddCommGroup (F i)] [∀ i, NormedSpace ℝ (F i)] |
| 72 | {J S : Set ℝ} {U : Set V} (hJ : IsOpen J) (hU : IsOpen U) (hS : S.Finite) |
| 73 | (f : ∀ i, ℝ × V → F i) |
| 74 | (spatial : ∀ i, F (i + 1) →L[ℝ] V →L[ℝ] F i) |
| 75 | (arity : ℕ → ℕ) |
| 76 | (rhs : ∀ i, (∀ j : Fin (arity i), F j.1) → F i) |
| 77 | (domain : ∀ i, Set (∀ j : Fin (arity i), F j.1)) |
| 78 | (hrhs : ∀ i, ContDiffOn ℝ ∞ (rhs i) (domain i)) |
| 79 | (hrange : ∀ i p, p ∈ J ×ˢ U → (fun j : Fin (arity i) => f j.1 p) ∈ domain i) |
| 80 | (hcont : ∀ i, ContinuousOn (f i) (J ×ˢ U)) |
| 81 | (hspatial : ∀ i t, t ∈ J → ∀ x ∈ U, |
| 82 | HasFDerivAt (fun y => f i (t, y)) (spatial i (f (i + 1) (t, x))) x) |
| 83 | (htime : ∀ i t, t ∈ J → t ∉ S → ∀ x ∈ U, |
| 84 | HasDerivAt (fun s => f i (s, x)) |
| 85 | (rhs i (fun j : Fin (arity i) => f j.1 (t, x))) t) : |
| 86 | ∀ i, ContDiffOn ℝ ∞ (f i) (J ×ˢ U) := by |
| 87 | let H (i : ℕ) (p : ℝ × V) := rhs i (fun j : Fin (arity i) => f j.1 p) |
| 88 | have hH : ∀ i, ContinuousOn (H i) (J ×ˢ U) := by |
| 89 | intro i |
| 90 | exact (hrhs i).continuousOn.comp (continuousOn_pi.mpr fun j => hcont j.1) (hrange i) |
| 91 | have htimeAll (i : ℕ) (t : ℝ) (ht : t ∈ J) (x : V) (hx : x ∈ U) : |
| 92 | HasDerivAt (fun s => f i (s, x)) (H i (t, x)) t := by |
| 93 | apply hasDerivAt_of_hasDerivAt_off_finite hJ hS |
| 94 | ((hcont i).comp (continuousOn_id.prodMk continuousOn_const) (fun _ hs => ⟨hs, hx⟩)) |
| 95 | ((hH i).comp (continuousOn_id.prodMk continuousOn_const) (fun _ hs => ⟨hs, hx⟩)) |
| 96 | (fun s hs hnot => htime i s hs hnot x hx) ht |
| 97 | let D (i : ℕ) (p : ℝ × V) : ℝ × V →L[ℝ] F i := |
| 98 | ((ContinuousLinearMap.id ℝ ℝ).smulRight (H i p)).coprod (spatial i (f (i + 1) p)) |
| 99 | have hD (i : ℕ) (p : ℝ × V) (hp : p ∈ J ×ˢ U) : HasFDerivAt (f i) (D i p) p := by |
| 100 | have hcH : ContinuousOn |
| 101 | (fun q => (ContinuousLinearMap.id ℝ ℝ).smulRight (H i q)) (J ×ˢ U) := |
| 102 | (ContinuousLinearMap.smulRightL ℝ ℝ (F i) |
| 103 | (ContinuousLinearMap.id ℝ ℝ)).continuous.comp_continuousOn |
| 104 | (hH i) |
| 105 | have hcX : ContinuousOn (fun q => spatial i (f (i + 1) q)) (J ×ˢ U) := |
| 106 | (spatial i).continuous.comp_continuousOn (hcont (i + 1)) |
| 107 | apply (hasStrictFDerivAt_uncurry_coprod (f := fun t x => f i (t, x)) |
| 108 | (f₁ := fun t x => (ContinuousLinearMap.id ℝ ℝ).smulRight (H i (t, x))) |
| 109 | (f₂ := fun t x => spatial i (f (i + 1) (t, x))) ?_ ?_ |
| 110 | (hcH.continuousAt ((hJ.prod hU).mem_nhds hp)) |
| 111 | (hcX.continuousAt ((hJ.prod hU).mem_nhds hp))).hasFDerivAt |
| 112 | · filter_upwards [(hJ.prod hU).mem_nhds hp] with q hq |
| 113 | exact (htimeAll i q.1 hq.1 q.2 hq.2).hasFDerivAt |
| 114 | · filter_upwards [(hJ.prod hU).mem_nhds hp] with q hq |
| 115 | exact hspatial i q.1 hq.1 q.2 hq.2 |
| 116 | have hfinite : ∀ n : ℕ, ∀ i, ContDiffOn ℝ n (f i) (J ×ˢ U) := by |
| 117 | intro n |
| 118 | induction n with |
| 119 | | zero => exact fun i => contDiffOn_zero.mpr (hcont i) |
| 120 | | succ n ih => |
| 121 | intro i |
| 122 | have hHn : ContDiffOn ℝ n (H i) (J ×ˢ U) := |
| 123 | ((hrhs i).of_le (by exact_mod_cast le_top)).comp |
| 124 | (contDiffOn_pi.mpr fun j => ih j.1) (hrange i) |
| 125 | have hTn := (contDiffOn_const (c := ContinuousLinearMap.id ℝ ℝ)).smulRight hHn |
| 126 | have hXn : ContDiffOn ℝ n (fun p => spatial i (f (i + 1) p)) (J ×ˢ U) := |
| 127 | (spatial i).contDiff.comp_contDiffOn (ih (i + 1)) |
| 128 | have hDn : ContDiffOn ℝ n (D i) (J ×ˢ U) := |
| 129 | (ContinuousLinearMap.coprodEquivL (𝕜 := ℝ) (E := ℝ) |
| 130 | (F := V) (G := F i) ℝ).contDiff.comp_contDiffOn |
| 131 | (hTn.prodMk hXn) |
| 132 | rw [Nat.cast_add, Nat.cast_one] |
| 133 | apply (contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn |
| 134 | (hJ.prod hU).uniqueDiffOn).mpr |
| 135 | exact ⟨by simp, D i, hDn, fun p hp => (hD i p hp).hasFDerivWithinAt⟩ |
| 136 | exact fun i => contDiffOn_infty.mpr (fun n => hfinite n i) |
| 137 | |
| 138 | end Poincare |