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.Analysis.Calculus.Morse.SquareCompletion |
| 2 | import Mathlib.Analysis.InnerProductSpace.PiL2 |
| 3 | import Mathlib.Analysis.Normed.Module.FiniteDimension |
| 4 | import Mathlib.LinearAlgebra.QuadraticForm.Basic |
| 5 | import Mathlib.Topology.OpenPartialHomeomorph.Composition |
| 6 | |
| 7 | /-! |
| 8 | # The two-dimensional smooth Morse lemma |
| 9 | |
| 10 | An orthogonal basis for the Hessian, the smooth quadratic-factor formula, and |
| 11 | smooth square completion give the signed-square normal form at a nondegenerate |
| 12 | critical point. |
| 13 | -/ |
| 14 | |
| 15 | noncomputable section |
| 16 | |
| 17 | open Set Module |
| 18 | open scoped ContDiff Topology |
| 19 | |
| 20 | namespace Poincare.Analysis.Calculus.Morse |
| 21 | |
| 22 | private theorem bilinear_apply_planar_expansion |
| 23 | {E : Type} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 24 | (B : E →L[ℝ] E →L[ℝ] ℝ) (u v : E) |
| 25 | (hsymm : B u v = B v u) (x y : ℝ) : |
| 26 | B (x • u + y • v) (x • u + y • v) = |
| 27 | B u u * x ^ 2 + 2 * B u v * x * y + B v v * y ^ 2 := by |
| 28 | simp only [map_add, map_smul, add_apply, smul_apply, smul_eq_mul] |
| 29 | rw [← hsymm] |
| 30 | ring |
| 31 | |
| 32 | theorem exists_smooth_morse_coordinates_two |
| 33 | {f : EuclideanSpace ℝ (Fin 2) → ℝ} (hf : ContDiff ℝ ∞ f) |
| 34 | (hcrit : fderiv ℝ f 0 = 0) |
| 35 | (hH : Function.Bijective (fderiv ℝ (fderiv ℝ f) 0)) : |
| 36 | ∃ (e : OpenPartialHomeomorph (EuclideanSpace ℝ (Fin 2)) |
| 37 | (EuclideanSpace ℝ (Fin 2))) (σ : Fin 2 → ℝ), |
| 38 | (∀ i, σ i = -1 ∨ σ i = 1) ∧ |
| 39 | (0 : EuclideanSpace ℝ (Fin 2)) ∈ e.source ∧ e 0 = 0 ∧ |
| 40 | ContDiffOn ℝ ∞ e e.source ∧ ContDiffOn ℝ ∞ e.symm e.target ∧ |
| 41 | ∀ x ∈ e.source, f (e x) = f 0 + ∑ i : Fin 2, σ i * x i ^ 2 := by |
| 42 | let B := quadraticFactor f |
| 43 | let L := (B 0).toBilinForm |
| 44 | have hsymm : L.IsSymm := ⟨fun v w => quadraticFactor_symmetric hf 0 v w⟩ |
| 45 | have hsep : L.SeparatingLeft := by |
| 46 | intro x hx |
| 47 | apply hH.1 |
| 48 | ext y |
| 49 | have hxy := hx y |
| 50 | change quadraticFactor f 0 x y = 0 at hxy |
| 51 | rw [quadraticFactor_zero] at hxy |
| 52 | simp only [smul_apply, smul_eq_mul] at hxy |
| 53 | simp only [map_zero, zero_apply] |
| 54 | linarith |
| 55 | obtain ⟨v, hv⟩ : ∃ v : Basis (Fin 2) ℝ (EuclideanSpace ℝ (Fin 2)), |
| 56 | L.IsOrthoᵢ v := by |
| 57 | have h := LinearMap.BilinForm.exists_orthogonal_basis hsymm |
| 58 | have hfin : finrank ℝ (EuclideanSpace ℝ (Fin 2)) = 2 := by |
| 59 | simp |
| 60 | rw [hfin] at h |
| 61 | exact h |
| 62 | have hvnonzero := hv.not_isOrtho_basis_self_of_separatingLeft hsep |
| 63 | let A : (ℝ × ℝ) ≃L[ℝ] EuclideanSpace ℝ (Fin 2) := |
| 64 | ((LinearEquiv.finTwoArrow ℝ ℝ).symm.trans v.equivFun.symm).toContinuousLinearEquiv |
| 65 | have hA (x : ℝ × ℝ) : A x = x.1 • v 0 + x.2 • v 1 := by |
| 66 | simp [A, Basis.equivFun_symm_apply, Fin.sum_univ_two, LinearEquiv.finTwoArrow, |
| 67 | finTwoArrowEquiv] |
| 68 | let a : ℝ × ℝ → ℝ := fun x => B (A x) (v 0) (v 0) |
| 69 | let b : ℝ × ℝ → ℝ := fun x => B (A x) (v 0) (v 1) |
| 70 | let c : ℝ × ℝ → ℝ := fun x => B (A x) (v 1) (v 1) |
| 71 | have hB : ContDiff ℝ ∞ (fun x => B (A x)) := |
| 72 | (contDiff_quadraticFactor hf).comp A.contDiff |
| 73 | have ha : ContDiff ℝ ∞ a := (hB.clm_apply contDiff_const).clm_apply contDiff_const |
| 74 | have hb : ContDiff ℝ ∞ b := (hB.clm_apply contDiff_const).clm_apply contDiff_const |
| 75 | have hc : ContDiff ℝ ∞ c := (hB.clm_apply contDiff_const).clm_apply contDiff_const |
| 76 | have ha0 : a 0 ≠ 0 := by simpa [a, L] using hvnonzero 0 |
| 77 | have hb0 : b 0 = 0 := by simpa [b, L] using hv (by decide : (0 : Fin 2) ≠ 1) |
| 78 | have hc0 : c 0 ≠ 0 := by simpa [c, L] using hvnonzero 1 |
| 79 | have hd0 : c 0 - b 0 ^ 2 / a 0 ≠ 0 := by simpa [hb0] using hc0 |
| 80 | have hfA (x : ℝ × ℝ) : f (A x) = f 0 + |
| 81 | (a x * x.1 ^ 2 + 2 * b x * x.1 * x.2 + c x * x.2 ^ 2) := by |
| 82 | rw [eq_add_quadraticFactor_of_fderiv_eq_zero hf hcrit (A x)] |
| 83 | congr 1 |
| 84 | change B (A x) (A x) (A x) = _ |
| 85 | conv_lhs => arg 2; rw [hA] |
| 86 | conv_lhs => arg 1; arg 2; rw [hA] |
| 87 | exact bilinear_apply_planar_expansion (B (A x)) (v 0) (v 1) |
| 88 | (quadraticFactor_symmetric hf (A x) (v 0) (v 1)) x.1 x.2 |
| 89 | obtain ⟨e, s, t, hs, ht, he0, hezero, he, hei, hform⟩ := |
| 90 | exists_binary_quadratic_normalForm ha hb hc ha0 hd0 |
| 91 | let C : EuclideanSpace ℝ (Fin 2) ≃L[ℝ] ℝ × ℝ := |
| 92 | (EuclideanSpace.equiv (Fin 2) ℝ).trans |
| 93 | (LinearEquiv.finTwoArrow ℝ ℝ).toContinuousLinearEquiv |
| 94 | have hC (x : EuclideanSpace ℝ (Fin 2)) : C x = (x 0, x 1) := rfl |
| 95 | let q := (C.toHomeomorph.toOpenPartialHomeomorph.trans e).trans |
| 96 | A.toHomeomorph.toOpenPartialHomeomorph |
| 97 | have hq (x : EuclideanSpace ℝ (Fin 2)) : q x = A (e (C x)) := rfl |
| 98 | have hqs : ∀ x ∈ q.source, C x ∈ e.source := fun x hx => hx.1.2 |
| 99 | refine ⟨q, ![s, t], ?_, ?_, ?_, ?_, ?_, ?_⟩ |
| 100 | · intro i |
| 101 | fin_cases i <;> simp [hs, ht] |
| 102 | · exact ⟨⟨mem_univ _, by simpa using he0⟩, mem_univ _⟩ |
| 103 | · simp [hq, hezero] |
| 104 | · exact A.contDiff.contDiffOn.comp |
| 105 | (he.comp C.contDiff.contDiffOn (fun x hx => hqs x hx)) (fun _ _ => mem_univ _) |
| 106 | · exact C.symm.contDiff.contDiffOn.comp |
| 107 | (hei.comp A.symm.contDiff.contDiffOn (fun x hx => hx.2.1)) (fun _ _ => mem_univ _) |
| 108 | · intro x hx |
| 109 | rw [hq, hfA, hform (C x) (hqs x hx)] |
| 110 | simp [Fin.sum_univ_two, hC] |
| 111 | |
| 112 | end Poincare.Analysis.Calculus.Morse |