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.RicciFlow.Curvature.Calculus.Tensors.RiemannRegularity |
| 2 | import PoincareLib.Geometry.RicciFlow.Curvature.Calculus.Identities.CurvatureSymmetries |
| 3 | import PoincareLib.Geometry.RicciFlow.Basic |
| 4 | import Mathlib.LinearAlgebra.Trace |
| 5 | import Mathlib.Analysis.Calculus.Deriv.Mul |
| 6 | |
| 7 | /-! Adapted from Mapher06/Poincare-MorganTian, `PoincareMT/Proofs/M04/RicciTraceVariation.lean`, |
| 8 | revision `f927d9e1f0810042766d3b5f64d3f4da02ee93cc`. See the curvature import record under |
| 9 | `references/ricci-flow/mapher/curvature/`. -/ |
| 10 | |
| 11 | /-! |
| 12 | # Differentiating the actual Ricci contraction |
| 13 | |
| 14 | Topping Proposition 2.3.6, printed pp.30 and 34, applied to a curvature |
| 15 | slice with fixed first and third inputs. This slice need not be symmetric. |
| 16 | -/ |
| 17 | |
| 18 | set_option autoImplicit false |
| 19 | |
| 20 | open scoped Manifold ContDiff Bundle |
| 21 | open Set Topology Filter |
| 22 | |
| 23 | universe u |
| 24 | |
| 25 | namespace PoincareMT.RicciFlowAnalysis |
| 26 | |
| 27 | variable {n : ℕ} {M : Type u} [TopologicalSpace M] |
| 28 | [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] [IsManifold (𝓡 n) ∞ M] |
| 29 | {J : Set ℝ} |
| 30 | |
| 31 | set_option maxHeartbeats 2000000 in |
| 32 | -- Differentiating the inverse-metric curvature trace needs extra elaboration. |
| 33 | set_option backward.isDefEq.respectTransparency false in |
| 34 | theorem hasDerivAt_ricci_of_curvature_derivative (F : RicciFlow n M J) |
| 35 | {t : ℝ} (x : M) (u v : TangentSpace (𝓡 n) x) |
| 36 | (r : TangentSpace (𝓡 n) x → TangentSpace (𝓡 n) x → ℝ) |
| 37 | (ht : t ∈ interior J) |
| 38 | (hRtime : ∀ a b, |
| 39 | HasDerivAt (fun s ↦ (F.connection s).curvatureTensor x u a v b) (r a b) t) : |
| 40 | HasDerivAt (fun s ↦ (F.connection s).ricci x u v) |
| 41 | ((∑ i, r ((F.metric t).orthonormalBasis x i) ((F.metric t).orthonormalBasis x i)) + |
| 42 | 2 * (∑ i, ∑ j, (F.connection t).ricci x |
| 43 | ((F.metric t).orthonormalBasis x i) ((F.metric t).orthonormalBasis x j) * |
| 44 | (F.connection t).curvatureTensor x u ((F.metric t).orthonormalBasis x i) |
| 45 | v ((F.metric t).orthonormalBasis x j))) t := by |
| 46 | classical |
| 47 | let : Bundle.RiemannianBundle (TangentSpace (𝓡 n) : M → Type _) := |
| 48 | ⟨(F.metric t).toRiemannianMetric⟩ |
| 49 | let E := TangentSpace (𝓡 n) x |
| 50 | let : FiniteDimensional ℝ E := VectorBundle.finiteDimensional ℝ |
| 51 | (EuclideanSpace ℝ (Fin n)) (TangentSpace (𝓡 n) : M → Type _) x |
| 52 | let : CompleteSpace E := FiniteDimensional.complete ℝ E |
| 53 | let : NormedAddCommGroup (E →L[ℝ] ℝ) := inferInstance |
| 54 | let : NormedSpace ℝ (E →L[ℝ] ℝ) := inferInstance |
| 55 | let : NormedAddCommGroup (E →L[ℝ] E →L[ℝ] ℝ) := inferInstance |
| 56 | let : NormedSpace ℝ (E →L[ℝ] E →L[ℝ] ℝ) := inferInstance |
| 57 | let : NormedAddCommGroup (E →L[ℝ] E) := inferInstance |
| 58 | let : NormedSpace ℝ (E →L[ℝ] E) := inferInstance |
| 59 | have hclm {V W : Type} [NormedAddCommGroup V] [NormedSpace ℝ V] |
| 60 | [FiniteDimensional ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] |
| 61 | {L : ℝ → V →L[ℝ] W} |
| 62 | (hL : ∀ a, DifferentiableAt ℝ (fun s ↦ L s a) t) : |
| 63 | DifferentiableAt ℝ L t := by |
| 64 | let d := Module.finrank ℝ V |
| 65 | have hd : d = Module.finrank ℝ (Fin d → ℝ) := (Module.finrank_fin_fun ℝ).symm |
| 66 | let e1 := ContinuousLinearEquiv.ofFinrankEq hd |
| 67 | let e2 := (e1.arrowCongr (1 : W ≃L[ℝ] W)).trans (ContinuousLinearEquiv.piRing (Fin d)) |
| 68 | have hc : DifferentiableAt ℝ (fun s ↦ e2 (L s)) t := |
| 69 | differentiableAt_pi.mpr fun _ ↦ hL _ |
| 70 | have he := e2.symm.toContinuousLinearMap.differentiableAt.comp t hc |
| 71 | have heq : (fun s ↦ e2.symm (e2 (L s))) = L := by |
| 72 | funext s |
| 73 | exact e2.symm_apply_apply (L s) |
| 74 | have he' : DifferentiableAt ℝ (fun s ↦ e2.symm (e2 (L s))) t := by |
| 75 | simpa only [Function.comp_apply, ContinuousLinearEquiv.coe_coe] using! he |
| 76 | rwa [heq] at he' |
| 77 | choose T hT using fun s : ℝ ↦ |
| 78 | (isSmoothCovariantTensor_riemannEvaluation (F.connection s)).1 x |
| 79 | have hEval (s : ℝ) (a b : E) : |
| 80 | (F.connection s).curvatureTensor x u a v b = T s ![u, a, v, b] := |
| 81 | hT s ![u, a, v, b] |
| 82 | have hu1 (a b z : E) : Function.update ![u, a, v, b] 1 z = ![u, z, v, b] := by |
| 83 | ext i |
| 84 | fin_cases i <;> simp [Function.update] |
| 85 | have hu3 (a b z : E) : Function.update ![u, a, v, b] 3 z = ![u, a, v, z] := by |
| 86 | ext i |
| 87 | fin_cases i <;> simp [Function.update] |
| 88 | have ha1 (s : ℝ) (a b z : E) : (F.connection s).curvatureTensor x u (a + b) v z = |
| 89 | (F.connection s).curvatureTensor x u a v z + |
| 90 | (F.connection s).curvatureTensor x u b v z := by |
| 91 | simp only [hEval] |
| 92 | simpa only [hu1] using (T s).map_update_add ![u, a, v, z] 1 a b |
| 93 | have ha2 (s : ℝ) (a b z : E) : (F.connection s).curvatureTensor x u z v (a + b) = |
| 94 | (F.connection s).curvatureTensor x u z v a + |
| 95 | (F.connection s).curvatureTensor x u z v b := by |
| 96 | simp only [hEval] |
| 97 | simpa only [hu3] using (T s).map_update_add ![u, z, v, a] 3 a b |
| 98 | have hs1 (s c : ℝ) (a b : E) : (F.connection s).curvatureTensor x u (c • a) v b = |
| 99 | c • (F.connection s).curvatureTensor x u a v b := by |
| 100 | simp only [hEval] |
| 101 | simpa only [hu1] using (T s).map_update_smul ![u, a, v, b] 1 c a |
| 102 | have hs2 (s c : ℝ) (a b : E) : (F.connection s).curvatureTensor x u a v (c • b) = |
| 103 | c • (F.connection s).curvatureTensor x u a v b := by |
| 104 | simp only [hEval] |
| 105 | simpa only [hu3] using (T s).map_update_smul ![u, a, v, b] 3 c b |
| 106 | let R : ℝ → E →L[ℝ] E →L[ℝ] ℝ := fun s ↦ LinearMap.toContinuousLinearMap |
| 107 | { toFun := fun a ↦ LinearMap.toContinuousLinearMap |
| 108 | { toFun := fun b ↦ (F.connection s).curvatureTensor x u a v b |
| 109 | map_add' := fun b c ↦ ha2 s b c a |
| 110 | map_smul' := fun c b ↦ hs2 s c a b } |
| 111 | map_add' := by intro a b; ext z; exact ha1 s a b z |
| 112 | map_smul' := by intro c a; ext b; exact hs1 s c a b } |
| 113 | let G : ℝ → E →L[ℝ] E →L[ℝ] ℝ := fun s ↦ (F.metric s).inner x |
| 114 | have hRd : DifferentiableAt ℝ R t := by |
| 115 | apply hclm (V := E) (W := E →L[ℝ] ℝ) (L := R) |
| 116 | intro a |
| 117 | apply hclm (V := E) (W := ℝ) (L := fun s ↦ R s a) |
| 118 | intro b |
| 119 | exact (hRtime a b).differentiableAt |
| 120 | have hg (a b : E) : HasDerivAt (fun s ↦ G s a b) |
| 121 | (-2 * (F.connection t).ricci x a b) t := |
| 122 | (F.equation t (interior_subset ht) x a b).hasDerivAt (mem_interior_iff_mem_nhds.mp ht) |
| 123 | have hGd : DifferentiableAt ℝ G t := by |
| 124 | apply hclm (V := E) (W := E →L[ℝ] ℝ) (L := G) |
| 125 | intro a |
| 126 | apply hclm (V := E) (W := ℝ) (L := fun s ↦ G s a) |
| 127 | intro b |
| 128 | exact (hg a b).differentiableAt |
| 129 | have hRtime' : HasDerivAt R (deriv R t) t := hRd.hasDerivAt |
| 130 | have hGtime : HasDerivAt G (deriv G t) t := hGd.hasDerivAt |
| 131 | have hR' (a b : E) : deriv R t a b = r a b := by |
| 132 | have he : HasDerivAt (fun s ↦ R s a b) (deriv R t a b) t := by |
| 133 | simpa only [map_zero, zero_apply, zero_add, add_zero] using! |
| 134 | (hRtime'.clm_apply (F := E) (G := E →L[ℝ] ℝ) |
| 135 | (hasDerivAt_const t a)).clm_apply (F := E) (G := ℝ) (hasDerivAt_const t b) |
| 136 | exact he.unique (hRtime a b) |
| 137 | have hG' (a b : E) : deriv G t a b = -2 * (F.connection t).ricci x a b := by |
| 138 | have he : HasDerivAt (fun s ↦ G s a b) (deriv G t a b) t := by |
| 139 | simpa only [map_zero, zero_apply, zero_add, add_zero] using! |
| 140 | (hGtime.clm_apply (F := E) (G := E →L[ℝ] ℝ) |
| 141 | (hasDerivAt_const t a)).clm_apply (F := E) (G := ℝ) (hasDerivAt_const t b) |
| 142 | exact he.unique (hg a b) |
| 143 | let Q := (InnerProductSpace.toDual ℝ E).symm.toContinuousLinearEquiv |
| 144 | let B : ℝ → E →L[ℝ] E := fun s ↦ Q.toContinuousLinearMap.comp (G s) |
| 145 | let C : ℝ → E →L[ℝ] E := fun s ↦ Q.toContinuousLinearMap.comp (R s) |
| 146 | let V : E →L[ℝ] E := Q.toContinuousLinearMap.comp (deriv G t) |
| 147 | have hBd : HasDerivAt B V t := by |
| 148 | simpa only [ContinuousLinearMap.zero_comp, zero_add, V, B] using! |
| 149 | (hasDerivAt_const t Q.toContinuousLinearMap).clm_comp hGtime |
| 150 | have hCd : HasDerivAt C (Q.toContinuousLinearMap.comp (deriv R t)) t := by |
| 151 | simpa only [ContinuousLinearMap.zero_comp, zero_add, C] using! |
| 152 | (hasDerivAt_const t Q.toContinuousLinearMap).clm_comp hRtime' |
| 153 | have hCderiv : deriv C t = Q.toContinuousLinearMap.comp (deriv R t) := |
| 154 | HasDerivAt.deriv (𝕜 := ℝ) (F := E →L[ℝ] E) hCd |
| 155 | have hBt : B t = ContinuousLinearMap.id ℝ E := by |
| 156 | ext a |
| 157 | exact (InnerProductSpace.toDual ℝ E).symm_apply_apply a |
| 158 | have hInv (s : ℝ) : (B s).IsInvertible := by |
| 159 | have hz (a : E) (ha : B s a = 0) : a = 0 := by |
| 160 | have hg0 : G s a = 0 := Q.injective (by simpa [B] using ha) |
| 161 | have hi : (F.metric s).inner x a a = 0 := by |
| 162 | simpa [G] using congrArg (fun L : E →L[ℝ] ℝ ↦ L a) hg0 |
| 163 | by_contra hne |
| 164 | exact (ne_of_gt ((F.metric s).pos x a hne)) hi |
| 165 | have hinj : Function.Injective (B s) := by |
| 166 | intro a b h |
| 167 | apply sub_eq_zero.mp |
| 168 | apply hz |
| 169 | rw [map_sub, h, sub_self] |
| 170 | have hsurj : Function.Surjective (B s) := LinearMap.injective_iff_surjective.mp hinj |
| 171 | exact ⟨(LinearEquiv.ofBijective (B s).toLinearMap ⟨hinj, hsurj⟩).toContinuousLinearEquiv, |
| 172 | by ext a; rfl⟩ |
| 173 | let L : ℝ → E →L[ℝ] E := fun s ↦ (B s).inverse.comp (C s) |
| 174 | have hLd : DifferentiableAt ℝ L t := |
| 175 | (((hInv t).contDiffAt_map_inverse (n := 1)).differentiableAt (by norm_num) |
| 176 | |>.comp t hBd.differentiableAt).clm_comp hCd.differentiableAt |
| 177 | have hLtime : HasDerivAt L (deriv L t) t := hLd.hasDerivAt |
| 178 | have hBL (s : ℝ) (a : E) : B s (L s a) = C s a := (hInv s).self_apply_inverse _ |
| 179 | have hpair (s : ℝ) (a b : E) : (F.metric s).inner x (L s a) b = |
| 180 | (F.connection s).curvatureTensor x u a v b := by |
| 181 | have he := Q.injective (hBL s a) |
| 182 | exact congrArg (fun f : E →L[ℝ] ℝ ↦ f b) he |
| 183 | have hprod : HasDerivAt C (V.comp (L t) + (B t).comp (deriv L t)) t := by |
| 184 | have heq : (fun s ↦ (B s).comp (L s)) = C := by |
| 185 | funext s |
| 186 | ext a |
| 187 | exact hBL s a |
| 188 | simpa only [heq] using hBd.clm_comp (E := E) (F := E) (G := E) hLtime |
| 189 | have hL' : deriv L t = deriv C t - V.comp (L t) := by |
| 190 | have he := hprod.unique hCd |
| 191 | rw [hBt, ContinuousLinearMap.id_comp] at he |
| 192 | apply eq_sub_iff_add_eq.mpr |
| 193 | simpa only [hCderiv, add_comm] using he |
| 194 | have hC'pair (a b : E) : (F.metric t).inner x (deriv C t a) b = r a b := by |
| 195 | rw [hCderiv] |
| 196 | change inner ℝ ((InnerProductSpace.toDual ℝ E).symm (deriv R t a)) b = r a b |
| 197 | rw [InnerProductSpace.toDual_symm_apply, hR'] |
| 198 | have hVpair (a b : E) : (F.metric t).inner x (V a) b = |
| 199 | -2 * (F.connection t).ricci x a b := by |
| 200 | change inner ℝ ((InnerProductSpace.toDual ℝ E).symm (deriv G t a)) b = _ |
| 201 | rw [InnerProductSpace.toDual_symm_apply, hG'] |
| 202 | let b := (F.metric t).orthonormalBasis x |
| 203 | have hTrace (s : ℝ) : (∑ i, inner ℝ (b i) (L s (b i))) = |
| 204 | (F.connection s).ricci x u v := by |
| 205 | calc |
| 206 | _ = LinearMap.trace ℝ E (L s).toLinearMap := by |
| 207 | symm |
| 208 | rw [LinearMap.trace_eq_matrix_trace ℝ b.toBasis] |
| 209 | simp only [Matrix.trace, Matrix.diag, LinearMap.toMatrix_apply, |
| 210 | OrthonormalBasis.coe_toBasis, OrthonormalBasis.coe_toBasis_repr_apply, |
| 211 | OrthonormalBasis.repr_apply_apply] |
| 212 | rfl |
| 213 | _ = ∑ i, (F.metric s).inner x ((F.metric s).orthonormalBasis x i) |
| 214 | (L s ((F.metric s).orthonormalBasis x i)) := by |
| 215 | let : Bundle.RiemannianBundle (TangentSpace (𝓡 n) : M → Type _) := |
| 216 | ⟨(F.metric s).toRiemannianMetric⟩ |
| 217 | rw [LinearMap.trace_eq_matrix_trace ℝ ((F.metric s).orthonormalBasis x).toBasis] |
| 218 | simp only [Matrix.trace, Matrix.diag, LinearMap.toMatrix_apply, |
| 219 | OrthonormalBasis.coe_toBasis, OrthonormalBasis.coe_toBasis_repr_apply, |
| 220 | OrthonormalBasis.repr_apply_apply] |
| 221 | rfl |
| 222 | _ = _ := by |
| 223 | apply Finset.sum_congr rfl |
| 224 | intro i _ |
| 225 | rw [(F.metric s).symm, hpair] |
| 226 | have hExpand (a : E) : L t a = |
| 227 | ∑ j, (F.connection t).curvatureTensor x u a v (b j) • b j := by |
| 228 | calc |
| 229 | _ = ∑ j, inner ℝ (b j) (L t a) • b j := (b.sum_repr' (L t a)).symm |
| 230 | _ = _ := by |
| 231 | apply Finset.sum_congr rfl |
| 232 | intro j _ |
| 233 | change (F.metric t).inner x (b j) (L t a) • b j = _ |
| 234 | rw [(F.metric t).symm, hpair] |
| 235 | have hTerm : (∑ i, inner ℝ (b i) (V.comp (L t) (b i))) = |
| 236 | -2 * (∑ i, ∑ j, (F.connection t).ricci x (b i) (b j) * |
| 237 | (F.connection t).curvatureTensor x u (b i) v (b j)) := by |
| 238 | rw [Finset.mul_sum] |
| 239 | apply Finset.sum_congr rfl |
| 240 | intro i _ |
| 241 | simp only [ContinuousLinearMap.comp_apply, hExpand (b i), map_sum, map_smul, |
| 242 | inner_sum, inner_smul_right, Finset.mul_sum] |
| 243 | apply Finset.sum_congr rfl |
| 244 | intro j _ |
| 245 | change (F.connection t).curvatureTensor x u (b i) v (b j) * |
| 246 | (F.metric t).inner x (b i) (V (b j)) = _ |
| 247 | rw [(F.metric t).symm, hVpair, ricci_symm (F.connection t) x (b j) (b i)] |
| 248 | ring |
| 249 | have hTraceC : (∑ i, inner ℝ (b i) (deriv C t (b i))) = ∑ i, r (b i) (b i) := by |
| 250 | apply Finset.sum_congr rfl |
| 251 | intro i _ |
| 252 | change (F.metric t).inner x (b i) (deriv C t (b i)) = _ |
| 253 | rw [(F.metric t).symm, hC'pair] |
| 254 | have hd : HasDerivAt (fun s ↦ ∑ i, inner ℝ (b i) (L s (b i))) |
| 255 | (∑ i, inner ℝ (b i) (deriv L t (b i))) t := by |
| 256 | apply HasDerivAt.fun_sum |
| 257 | intro i _ |
| 258 | simpa only [map_zero, zero_apply, zero_add, add_zero] using! |
| 259 | (hasDerivAt_const t (innerSL ℝ (b i))).clm_apply (F := E) (G := ℝ) |
| 260 | (hLtime.clm_apply (F := E) (G := E) (hasDerivAt_const t (b i))) |
| 261 | have hdRic : HasDerivAt (fun s ↦ (F.connection s).ricci x u v) |
| 262 | (∑ i, inner ℝ (b i) (deriv L t (b i))) t := |
| 263 | hd.congr_of_eventuallyEq (Eventually.of_forall fun s ↦ (hTrace s).symm) |
| 264 | apply hdRic.congr_deriv |
| 265 | rw [hL'] |
| 266 | simp only [sub_apply, inner_sub_right, Finset.sum_sub_distrib, hTraceC, hTerm] |
| 267 | ring |
| 268 | |
| 269 | end PoincareMT.RicciFlowAnalysis |
| 270 |