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.Geometry.Riemannian.ScalarOperators.Gradient.Flow.Expansion |
| 2 | |
| 3 | /-! |
| 4 | # Nondecreasing tangent lengths under normalized gradient transport |
| 5 | |
| 6 | The normalization derivative vanishes when paired with a level tangent. |
| 7 | The actual smooth-flow variation equation thus differentiates its squared |
| 8 | length into twice the tangential Hessian divided by the gradient norm square. |
| 9 | -/ |
| 10 | |
| 11 | noncomputable section |
| 12 | set_option autoImplicit false |
| 13 | set_option backward.isDefEq.respectTransparency false |
| 14 | |
| 15 | open Set Filter |
| 16 | open Poincare.Geometry.Riemannian.Convexity |
| 17 | open scoped Manifold ContDiff Bundle Topology |
| 18 | |
| 19 | namespace PoincareMT.LeviCivitaData |
| 20 | |
| 21 | variable {n : ℕ} {M : Type*} [TopologicalSpace M] |
| 22 | [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓡 n) ∞ M] |
| 23 | {g : RiemannianMetric n M} |
| 24 | |
| 25 | /-- The exact tangential metric pairing for the positive normalized |
| 26 | gradient field on a smooth manifold. -/ |
| 27 | theorem inner_connection_normalizedGradient_of_tangent |
| 28 | (D : LeviCivitaData g) {f : M → ℝ} {x : M} |
| 29 | (hf : ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f x) |
| 30 | (hregular : g.inner x (D.gradient f x) (D.gradient f x) ≠ 0) |
| 31 | (v : TangentSpace (𝓡 n) x) (hv : mvfderiv (𝓡 n) f x v = 0) : |
| 32 | g.inner x (D.connection (D.normalizedGradient f) x v) v = |
| 33 | D.hessian f x v v / g.inner x (D.gradient f x) (D.gradient f x) := by |
| 34 | let : Bundle.RiemannianBundle (TangentSpace (𝓡 n) : M → Type _) := |
| 35 | ⟨g.toRiemannianMetric⟩ |
| 36 | have hgrad := (D.contMDiffAt_gradient hf).mdifferentiableAt (by simp) |
| 37 | have hpair : MDifferentiableAt (𝓡 n) 𝓘(ℝ, ℝ) |
| 38 | (fun y ↦ g.inner y (D.gradient f y) (D.gradient f y)) x := |
| 39 | hgrad.inner_bundle hgrad |
| 40 | have hinv : MDifferentiableAt (𝓡 n) 𝓘(ℝ, ℝ) |
| 41 | (fun y ↦ (g.inner y (D.gradient f y) (D.gradient f y))⁻¹) x := |
| 42 | (differentiableAt_inv hregular).mdifferentiableAt.comp x hpair |
| 43 | unfold normalizedGradient |
| 44 | rw [inner_connection_smul_gradient_of_tangent D hf hinv v hv] |
| 45 | ring |
| 46 | |
| 47 | /-- Convexity makes the actual tangential normalized-gradient metric |
| 48 | variation nonnegative. -/ |
| 49 | theorem inner_connection_normalizedGradient_nonneg |
| 50 | (D : LeviCivitaData g) {f : M → ℝ} {x : M} |
| 51 | (hf : ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f x) |
| 52 | (hregular : 0 < g.inner x (D.gradient f x) (D.gradient f x)) |
| 53 | (v : TangentSpace (𝓡 n) x) (hv : mvfderiv (𝓡 n) f x v = 0) |
| 54 | (hhess : 0 ≤ D.hessian f x v v) : |
| 55 | 0 ≤ g.inner x (D.connection (D.normalizedGradient f) x v) v := by |
| 56 | rw [D.inner_connection_normalizedGradient_of_tangent hf hregular.ne' v hv] |
| 57 | exact div_nonneg hhess hregular.le |
| 58 | |
| 59 | end PoincareMT.LeviCivitaData |
| 60 | |
| 61 | namespace PoincareMT.LeviCivitaData |
| 62 | |
| 63 | variable {n : ℕ} {g : RiemannianMetric n (EuclideanSpace ℝ (Fin n))} |
| 64 | |
| 65 | /-- Exact squared-length variation of an actual normalized-gradient flow |
| 66 | at a transported level tangent in model coordinates. -/ |
| 67 | theorem hasDerivAt_normalizedGradient_flow_squared_length |
| 68 | (D : LeviCivitaData g) {f : EuclideanSpace ℝ (Fin n) → ℝ} |
| 69 | {q : ℝ × EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)} |
| 70 | {t : ℝ} {x : EuclideanSpace ℝ (Fin n)} |
| 71 | (hq : ContDiffAt ℝ ∞ q (t, x)) |
| 72 | (hf : ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f (q (t, x))) |
| 73 | (hregular : g.inner (q (t, x)) (D.gradient f (q (t, x))) |
| 74 | (D.gradient f (q (t, x))) ≠ 0) |
| 75 | (htime : ∀ᶠ y in 𝓝 x, HasDerivAt (fun s ↦ q (s, y)) |
| 76 | (D.normalizedGradient f (q (t, y))) t) |
| 77 | (v : EuclideanSpace ℝ (Fin n)) |
| 78 | (htangent : mvfderiv (𝓡 n) f (q (t, x)) |
| 79 | (fderiv ℝ (fun y ↦ q (t, y)) x v) = 0) : |
| 80 | let w := fderiv ℝ (fun y ↦ q (t, y)) x v |
| 81 | HasDerivAt (fun s ↦ g.inner (q (s, x)) |
| 82 | (fderiv ℝ (fun y ↦ q (s, y)) x v) |
| 83 | (fderiv ℝ (fun y ↦ q (s, y)) x v)) |
| 84 | (2 * D.hessian f (q (t, x)) w w / |
| 85 | g.inner (q (t, x)) (D.gradient f (q (t, x))) (D.gradient f (q (t, x)))) t := by |
| 86 | have hfield : DifferentiableAt ℝ (D.normalizedGradient f) (q (t, x)) := by |
| 87 | have heq : D.normalizedGradient f = fun z ↦ -normalizedNegGradient D f z := by |
| 88 | funext z |
| 89 | simp only [normalizedGradient, normalizedNegGradient, neg_smul, neg_neg] |
| 90 | rw [heq] |
| 91 | exact (differentiableAt_normalizedNegGradient D hf hregular).neg |
| 92 | have h := hasDerivAt_flow_squared_length D hq hfield htime v |
| 93 | dsimp only at h ⊢ |
| 94 | rw [D.inner_connection_normalizedGradient_of_tangent hf hregular _ htangent] at h |
| 95 | convert! h using 1 |
| 96 | ring |
| 97 | |
| 98 | private theorem comp_normalizedGradient_eq_add |
| 99 | (D : LeviCivitaData g) {f : EuclideanSpace ℝ (Fin n) → ℝ} |
| 100 | {γ : ℝ → EuclideanSpace ℝ (Fin n)} {a b : ℝ} |
| 101 | (hf : ∀ t ∈ Icc a b, ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f (γ t)) |
| 102 | (hregular : ∀ t ∈ Icc a b, |
| 103 | g.inner (γ t) (D.gradient f (γ t)) (D.gradient f (γ t)) ≠ 0) |
| 104 | (hγ : ∀ t ∈ Icc a b, HasDerivAt γ (D.normalizedGradient f (γ t)) t) : |
| 105 | ∀ t ∈ Icc a b, f (γ t) = f (γ a) + (t - a) := by |
| 106 | have hd (t : ℝ) (ht : t ∈ Icc a b) : HasDerivAt (f ∘ γ) 1 t := by |
| 107 | have hcomp := ((contMDiffAt_iff_contDiffAt.mp (hf t ht)).differentiableAt |
| 108 | (by simp)).hasFDerivAt.comp_hasDerivAt t (hγ t ht) |
| 109 | have he : mvfderiv (𝓡 n) f (γ t) (D.normalizedGradient f (γ t)) = 1 := by |
| 110 | simp only [normalizedGradient, map_smul, smul_eq_mul, ← D.inner_gradient] |
| 111 | exact inv_mul_cancel₀ (hregular t ht) |
| 112 | have he' : fderiv ℝ f (γ t) (D.normalizedGradient f (γ t)) = 1 := by |
| 113 | simp [mvfderiv, mfderiv_eq_fderiv, NormedSpace.fromTangentSpace] at he |
| 114 | convert! he using 1 |
| 115 | exact hcomp.congr_deriv he' |
| 116 | have hl (t : ℝ) : HasDerivAt (fun s ↦ f (γ a) + (s - a)) 1 t := by |
| 117 | simpa using ((hasDerivAt_id t).sub_const a).const_add (f (γ a)) |
| 118 | exact eq_of_has_deriv_right_eq |
| 119 | (fun t ht ↦ (hd t ⟨ht.1, ht.2.le⟩).hasDerivWithinAt) |
| 120 | (fun t _ ↦ (hl t).hasDerivWithinAt) |
| 121 | (fun t ht ↦ (hd t ht).continuousAt.continuousWithinAt) |
| 122 | (fun t _ ↦ (hl t).continuousAt.continuousWithinAt) (by simp) |
| 123 | |
| 124 | /-- A genuine positive normalized-gradient flow preserves the differential |
| 125 | of its defining function. -/ |
| 126 | theorem normalizedGradient_flow_preserves_level_differential |
| 127 | (D : LeviCivitaData g) {f : EuclideanSpace ℝ (Fin n) → ℝ} |
| 128 | {q : ℝ × EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)} |
| 129 | {a b : ℝ} {x : EuclideanSpace ℝ (Fin n)} |
| 130 | (hq : ∀ t ∈ Icc a b, ContDiffAt ℝ ∞ q (t, x)) |
| 131 | (hf : ∀ᶠ y in 𝓝 x, ∀ t ∈ Icc a b, |
| 132 | ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f (q (t, y))) |
| 133 | (hregular : ∀ᶠ y in 𝓝 x, ∀ t ∈ Icc a b, |
| 134 | g.inner (q (t, y)) (D.gradient f (q (t, y))) (D.gradient f (q (t, y))) ≠ 0) |
| 135 | (htime : ∀ᶠ y in 𝓝 x, ∀ t ∈ Icc a b, HasDerivAt (fun s ↦ q (s, y)) |
| 136 | (D.normalizedGradient f (q (t, y))) t) |
| 137 | (v : EuclideanSpace ℝ (Fin n)) (t : ℝ) (ht : t ∈ Icc a b) : |
| 138 | mvfderiv (𝓡 n) f (q (t, x)) (fderiv ℝ (fun y ↦ q (t, y)) x v) = |
| 139 | mvfderiv (𝓡 n) f (q (a, x)) (fderiv ℝ (fun y ↦ q (a, y)) x v) := by |
| 140 | have ha : a ∈ Icc a b := ⟨le_rfl, ht.1.trans ht.2⟩ |
| 141 | have he : (fun y ↦ f (q (t, y))) =ᶠ[𝓝 x] |
| 142 | fun y ↦ f (q (a, y)) + (t - a) := by |
| 143 | filter_upwards [hf, hregular, htime] with y hy hr hytime |
| 144 | exact comp_normalizedGradient_eq_add D hy hr hytime t ht |
| 145 | have hqd (s : ℝ) (hs : s ∈ Icc a b) : |
| 146 | DifferentiableAt ℝ (fun y ↦ q (s, y)) x := |
| 147 | ((hq s hs).differentiableAt (by simp)).comp x |
| 148 | (differentiableAt_const s |>.prodMk differentiableAt_id) |
| 149 | have hfd (s : ℝ) (hs : s ∈ Icc a b) : DifferentiableAt ℝ f (q (s, x)) := |
| 150 | (contMDiffAt_iff_contDiffAt.mp (hf.self_of_nhds s hs)).differentiableAt (by simp) |
| 151 | have hleft := (hfd t ht).hasFDerivAt.comp x (hqd t ht).hasFDerivAt |
| 152 | have hright := ((hfd a ha).hasFDerivAt.comp x (hqd a ha).hasFDerivAt).add_const (t - a) |
| 153 | have hd := congrArg (fun A ↦ A v) (hleft.unique (hright.congr_of_eventuallyEq he)) |
| 154 | simp [mvfderiv, mfderiv_eq_fderiv, NormedSpace.fromTangentSpace] |
| 155 | convert! hd using 1 |
| 156 | |
| 157 | /-- The actual induced quadratic metric on level tangents is nondecreasing |
| 158 | along any smooth normalized-gradient flow with nonnegative tangential Hessian. -/ |
| 159 | theorem normalizedGradient_flow_squared_length_monotone |
| 160 | (D : LeviCivitaData g) {f : EuclideanSpace ℝ (Fin n) → ℝ} |
| 161 | {q : ℝ × EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)} |
| 162 | {a b : ℝ} {x : EuclideanSpace ℝ (Fin n)} |
| 163 | (hq : ∀ t ∈ Icc a b, ContDiffAt ℝ ∞ q (t, x)) |
| 164 | (hf : ∀ᶠ y in 𝓝 x, ∀ t ∈ Icc a b, |
| 165 | ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f (q (t, y))) |
| 166 | (hregular : ∀ᶠ y in 𝓝 x, ∀ t ∈ Icc a b, |
| 167 | 0 < g.inner (q (t, y)) (D.gradient f (q (t, y))) (D.gradient f (q (t, y)))) |
| 168 | (htime : ∀ᶠ y in 𝓝 x, ∀ t ∈ Icc a b, HasDerivAt (fun s ↦ q (s, y)) |
| 169 | (D.normalizedGradient f (q (t, y))) t) |
| 170 | (v : EuclideanSpace ℝ (Fin n)) |
| 171 | (hinitial : mvfderiv (𝓡 n) f (q (a, x)) |
| 172 | (fderiv ℝ (fun y ↦ q (a, y)) x v) = 0) |
| 173 | (hhess : ∀ t ∈ Icc a b, ∀ w, mvfderiv (𝓡 n) f (q (t, x)) w = 0 → |
| 174 | 0 ≤ D.hessian f (q (t, x)) w w) : |
| 175 | MonotoneOn (fun t ↦ g.inner (q (t, x)) |
| 176 | (fderiv ℝ (fun y ↦ q (t, y)) x v) |
| 177 | (fderiv ℝ (fun y ↦ q (t, y)) x v)) (Icc a b) := by |
| 178 | have htan (t : ℝ) (ht : t ∈ Icc a b) : mvfderiv (𝓡 n) f (q (t, x)) |
| 179 | (fderiv ℝ (fun y ↦ q (t, y)) x v) = 0 := |
| 180 | (D.normalizedGradient_flow_preserves_level_differential hq hf |
| 181 | (hregular.mono fun y hy s hs ↦ (hy s hs).ne') htime v t ht).trans hinitial |
| 182 | have hd (t : ℝ) (ht : t ∈ Icc a b) := |
| 183 | D.hasDerivAt_normalizedGradient_flow_squared_length (hq t ht) |
| 184 | (hf.self_of_nhds t ht) (hregular.self_of_nhds t ht).ne' |
| 185 | (htime.mono fun y hy ↦ hy t ht) v (htan t ht) |
| 186 | apply monotoneOn_of_deriv_nonneg (convex_Icc _ _) |
| 187 | (fun t ht ↦ (hd t ht).continuousAt.continuousWithinAt) |
| 188 | (fun t ht ↦ (hd t (interior_subset ht)).differentiableAt.differentiableWithinAt) |
| 189 | intro t ht |
| 190 | rw [(hd t (interior_subset ht)).deriv] |
| 191 | exact div_nonneg (mul_nonneg (by norm_num) |
| 192 | (hhess t (interior_subset ht) _ (htan t (interior_subset ht)))) |
| 193 | (hregular.self_of_nhds t (interior_subset ht)).le |
| 194 | |
| 195 | /-- A local normalized-gradient flow exists on a regular region with |
| 196 | nonnegative tangential Hessian and expands the induced level metric. -/ |
| 197 | theorem exists_local_normalizedGradient_flow_with_nondecreasing_metric |
| 198 | (D : LeviCivitaData g) {f : EuclideanSpace ℝ (Fin n) → ℝ} |
| 199 | {U : Set (EuclideanSpace ℝ (Fin n))} |
| 200 | (hU : IsOpen U) (hf : ContDiffOn ℝ ∞ f U) |
| 201 | (hregular : ∀ y ∈ U, 0 < g.inner y (D.gradient f y) (D.gradient f y)) |
| 202 | (hhess : ∀ y ∈ U, ∀ v : EuclideanSpace ℝ (Fin n), |
| 203 | mvfderiv (𝓡 n) f y v = 0 → 0 ≤ D.hessian f y v v) |
| 204 | {x : EuclideanSpace ℝ (Fin n)} (hx : x ∈ U) : |
| 205 | ∃ (V : Set (EuclideanSpace ℝ (Fin n))) (δ : ℝ) |
| 206 | (Φ : ℝ × EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)), |
| 207 | IsOpen V ∧ x ∈ V ∧ V ⊆ U ∧ 0 < δ ∧ |
| 208 | ContDiffOn ℝ ∞ Φ (Ioo (-δ) δ ×ˢ V) ∧ |
| 209 | (∀ y ∈ V, Φ (0, y) = y) ∧ |
| 210 | (∀ y ∈ V, ∀ t ∈ Ioo (-δ) δ, Φ (t, y) ∈ U ∧ |
| 211 | HasDerivAt (fun s => Φ (s, y)) (D.normalizedGradient f (Φ (t, y))) t) ∧ |
| 212 | ∀ y ∈ V, ∀ t ∈ Ico 0 δ, |
| 213 | f (Φ (t, y)) = f y + t ∧ |
| 214 | ∀ v : EuclideanSpace ℝ (Fin n), mvfderiv (𝓡 n) f y v = 0 → |
| 215 | g.inner y v v ≤ g.inner (Φ (t, y)) |
| 216 | (fderiv ℝ (fun z => Φ (t, z)) y v) |
| 217 | (fderiv ℝ (fun z => Φ (t, z)) y v) := by |
| 218 | obtain ⟨V, δ, q, hV, hxV, hVU, hδ, hq, hinit, hflow⟩ := |
| 219 | exists_smooth_normalizedNegGradient_flow D hU hf |
| 220 | (fun y hy => (hregular y hy).ne') hx |
| 221 | let Φ : ℝ × EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n) := |
| 222 | fun p => q (-p.1, p.2) |
| 223 | have hneg (t : ℝ) (ht : t ∈ Ioo (-δ) δ) : -t ∈ Ioo (-δ) δ := by |
| 224 | constructor <;> linarith [ht.1, ht.2] |
| 225 | have hΦ : ContDiffOn ℝ ∞ Φ (Ioo (-δ) δ ×ˢ V) := |
| 226 | hq.comp (contDiff_fst.neg.prodMk contDiff_snd).contDiffOn |
| 227 | (fun p hp => ⟨hneg p.1 hp.1, hp.2⟩) |
| 228 | have hΦ0 (y : EuclideanSpace ℝ (Fin n)) (hy : y ∈ V) : Φ (0, y) = y := by |
| 229 | simpa only [Φ, neg_zero] using hinit y hy |
| 230 | have hΦflow (y : EuclideanSpace ℝ (Fin n)) (hy : y ∈ V) |
| 231 | (t : ℝ) (ht : t ∈ Ioo (-δ) δ) : |
| 232 | Φ (t, y) ∈ U ∧ HasDerivAt (fun s => Φ (s, y)) |
| 233 | (D.normalizedGradient f (Φ (t, y))) t := by |
| 234 | refine ⟨(hflow y hy (-t) (hneg t ht)).1, ?_⟩ |
| 235 | have hd := (hflow y hy (-t) (hneg t ht)).2.scomp t ((hasDerivAt_id t).neg) |
| 236 | simpa only [Φ, Function.comp_def, normalizedGradient, normalizedNegGradient, |
| 237 | neg_smul, one_smul, neg_neg] using hd |
| 238 | refine ⟨V, δ, Φ, hV, hxV, hVU, hδ, hΦ, hΦ0, hΦflow, ?_⟩ |
| 239 | intro y hy t ht |
| 240 | have hsub : Icc (0 : ℝ) t ⊆ Ioo (-δ) δ := fun s hs => |
| 241 | ⟨by linarith [hs.1], hs.2.trans_lt ht.2⟩ |
| 242 | have hqs (s : ℝ) (hs : s ∈ Icc (0 : ℝ) t) : ContDiffAt ℝ ∞ Φ (s, y) := |
| 243 | hΦ.contDiffAt ((isOpen_Ioo.prod hV).mem_nhds ⟨hsub hs, hy⟩) |
| 244 | have hfs : ∀ᶠ z in 𝓝 y, ∀ s ∈ Icc (0 : ℝ) t, |
| 245 | ContMDiffAt (𝓡 n) 𝓘(ℝ, ℝ) ∞ f (Φ (s, z)) := by |
| 246 | filter_upwards [hV.mem_nhds hy] with z hz s hs |
| 247 | exact contMDiffAt_iff_contDiffAt.mpr |
| 248 | (hf.contDiffAt (hU.mem_nhds (hΦflow z hz s (hsub hs)).1)) |
| 249 | have hrs : ∀ᶠ z in 𝓝 y, ∀ s ∈ Icc (0 : ℝ) t, |
| 250 | 0 < g.inner (Φ (s, z)) (D.gradient f (Φ (s, z))) |
| 251 | (D.gradient f (Φ (s, z))) := by |
| 252 | filter_upwards [hV.mem_nhds hy] with z hz s hs |
| 253 | exact hregular _ (hΦflow z hz s (hsub hs)).1 |
| 254 | have hts : ∀ᶠ z in 𝓝 y, ∀ s ∈ Icc (0 : ℝ) t, |
| 255 | HasDerivAt (fun r => Φ (r, z)) (D.normalizedGradient f (Φ (s, z))) s := by |
| 256 | filter_upwards [hV.mem_nhds hy] with z hz s hs |
| 257 | exact (hΦflow z hz s (hsub hs)).2 |
| 258 | constructor |
| 259 | · have he := comp_normalizedGradient_eq_add D hfs.self_of_nhds |
| 260 | (fun s hs => (hrs.self_of_nhds s hs).ne') hts.self_of_nhds t ⟨ht.1, le_rfl⟩ |
| 261 | simpa only [hΦ0 y hy, sub_zero] using he |
| 262 | · intro v hv |
| 263 | have he : (fun z => Φ (0, z)) =ᶠ[𝓝 y] id := by |
| 264 | filter_upwards [hV.mem_nhds hy] with z hz |
| 265 | exact hΦ0 z hz |
| 266 | have hzero : fderiv ℝ (fun z => Φ (0, z)) y v = v := by |
| 267 | rw [he.fderiv_eq, fderiv_id, ContinuousLinearMap.id_apply] |
| 268 | have hm := D.normalizedGradient_flow_squared_length_monotone hqs hfs hrs hts v |
| 269 | (by rw [hzero, hΦ0 y hy]; exact hv) |
| 270 | (fun s hs w hw => hhess _ (hΦflow y hy s (hsub hs)).1 w hw) |
| 271 | have hb := hm ⟨le_rfl, ht.1⟩ ⟨ht.1, le_rfl⟩ ht.1 |
| 272 | dsimp only at hb |
| 273 | rw [hzero, hΦ0 y hy] at hb |
| 274 | exact hb |
| 275 | |
| 276 | end PoincareMT.LeviCivitaData |