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.LinearAlgebra.CrossProduct.Orthonormal |
| 2 | import Mathlib.LinearAlgebra.Matrix.Adjugate |
| 3 | import Mathlib.LinearAlgebra.Matrix.DotProduct |
| 4 | import Mathlib.LinearAlgebra.Matrix.ToLin |
| 5 | |
| 6 | /-! |
| 7 | # Cofactor normals to embedded tangent planes |
| 8 | |
| 9 | The transpose adjugate maps the normal of a plane to a normal of its image. |
| 10 | When a linear map is injective on the plane, this new normal is nonzero. |
| 11 | -/ |
| 12 | |
| 13 | open Matrix |
| 14 | |
| 15 | namespace Poincare.LinearAlgebra |
| 16 | |
| 17 | /-- Cofactors transport oriented area vectors without requiring an invertible map. -/ |
| 18 | theorem adjugate_transpose_mulVec_crossProduct |
| 19 | (A : Matrix (Fin 3) (Fin 3) ℝ) (u v : Fin 3 → ℝ) : |
| 20 | A.adjugate.transpose *ᵥ (u ⨯₃ v) = (A *ᵥ u) ⨯₃ (A *ᵥ v) := by |
| 21 | rw [adjugate_fin_three] |
| 22 | ext i |
| 23 | fin_cases i <;> |
| 24 | simp [cross_apply, mulVec, vec3_dotProduct, transpose_apply] <;> ring |
| 25 | |
| 26 | /-- The polynomial normal determined by a linear map and a domain normal. -/ |
| 27 | noncomputable def cofactorNormal |
| 28 | (A : (Fin 3 → ℝ) →ₗ[ℝ] (Fin 3 → ℝ)) (p : Fin 3 → ℝ) : Fin 3 → ℝ := |
| 29 | (LinearMap.toMatrix' A).adjugate.transpose *ᵥ p |
| 30 | |
| 31 | /-- A cofactor normal is orthogonal to the image of every tangent vector. -/ |
| 32 | theorem cofactorNormal_dot_apply_eq_zero |
| 33 | (A : (Fin 3 → ℝ) →ₗ[ℝ] (Fin 3 → ℝ)) (p v : Fin 3 → ℝ) |
| 34 | (hv : p ⬝ᵥ v = 0) : cofactorNormal A p ⬝ᵥ A v = 0 := by |
| 35 | rw [cofactorNormal, dotProduct_comm, dotProduct_transpose_mulVec, |
| 36 | ← LinearMap.toMatrix'_mulVec A v, mulVec_mulVec, adjugate_mul, |
| 37 | smul_mulVec, one_mulVec, dotProduct_smul, hv, smul_zero] |
| 38 | |
| 39 | /-- Injectivity on a unit normal's orthogonal plane makes the cofactor normal nonzero. -/ |
| 40 | theorem cofactorNormal_ne_zero |
| 41 | (A : (Fin 3 → ℝ) →ₗ[ℝ] (Fin 3 → ℝ)) (p : Fin 3 → ℝ) |
| 42 | (hp : p ⬝ᵥ p = 1) |
| 43 | (hA : Set.InjOn A {v | p ⬝ᵥ v = 0}) : cofactorNormal A p ≠ 0 := by |
| 44 | obtain ⟨u, v, hu, hv, huv, huv_eq⟩ := exists_orthonormal_crossProduct_coordinates p hp |
| 45 | have hpu : p ⬝ᵥ u = 0 := by rw [← huv_eq, dotProduct_comm, dot_self_cross] |
| 46 | have hpv : p ⬝ᵥ v = 0 := by rw [← huv_eq, dotProduct_comm, dot_cross_self] |
| 47 | have hcross : cofactorNormal A p = A u ⨯₃ A v := by |
| 48 | rw [cofactorNormal, ← huv_eq, adjugate_transpose_mulVec_crossProduct] |
| 49 | simp only [LinearMap.toMatrix'_mulVec] |
| 50 | rw [hcross, crossProduct_ne_zero_iff_linearIndependent, LinearIndependent.pair_iff] |
| 51 | intro a b hab |
| 52 | have hpre : a • u + b • v = 0 := by |
| 53 | apply hA |
| 54 | · simp only [Set.mem_ofPred_eq, dotProduct_add, dotProduct_smul, hpu, hpv, |
| 55 | smul_zero, add_zero] |
| 56 | · simp |
| 57 | · simpa using hab |
| 58 | have ha := congrArg (fun w => u ⬝ᵥ w) hpre |
| 59 | have hb := congrArg (fun w => v ⬝ᵥ w) hpre |
| 60 | have hvu : v ⬝ᵥ u = 0 := by rwa [dotProduct_comm] |
| 61 | simpa [dotProduct_add, dotProduct_smul, hu, hv, huv, hvu] using And.intro ha hb |
| 62 | |
| 63 | /-- Completing an injective tangent map by its cofactor normal is injective. -/ |
| 64 | theorem injective_tangent_add_cofactorNormal |
| 65 | (A : (Fin 3 → ℝ) →ₗ[ℝ] (Fin 3 → ℝ)) (p : Fin 3 → ℝ) |
| 66 | (hp : p ⬝ᵥ p = 1) |
| 67 | (hA : Set.InjOn A {v | p ⬝ᵥ v = 0}) : |
| 68 | Function.Injective fun v => |
| 69 | A (v - (p ⬝ᵥ v) • p) + (p ⬝ᵥ v) • cofactorNormal A p := by |
| 70 | have hproj (v : Fin 3 → ℝ) : p ⬝ᵥ (v - (p ⬝ᵥ v) • p) = 0 := by |
| 71 | simp [dotProduct_sub, dotProduct_smul, hp] |
| 72 | have hnormal (v : Fin 3 → ℝ) : |
| 73 | cofactorNormal A p ⬝ᵥ A (v - (p ⬝ᵥ v) • p) = 0 := |
| 74 | cofactorNormal_dot_apply_eq_zero A p _ (hproj v) |
| 75 | have hnn : cofactorNormal A p ⬝ᵥ cofactorNormal A p ≠ 0 := by |
| 76 | simpa only [ne_eq, dotProduct_self_eq_zero] using cofactorNormal_ne_zero A p hp hA |
| 77 | intro u v huv |
| 78 | dsimp only at huv |
| 79 | have hdot := congrArg (fun w => cofactorNormal A p ⬝ᵥ w) huv |
| 80 | simp only [dotProduct_add, dotProduct_smul, hnormal, zero_add, smul_eq_mul] at hdot |
| 81 | have huv' : p ⬝ᵥ u = p ⬝ᵥ v := mul_right_cancel₀ hnn hdot |
| 82 | have hproj_eq : u - (p ⬝ᵥ u) • p = v - (p ⬝ᵥ v) • p := by |
| 83 | apply hA (hproj u) (hproj v) |
| 84 | exact add_right_cancel (huv.trans (by rw [huv'])) |
| 85 | rwa [huv', sub_left_inj] at hproj_eq |
| 86 | |
| 87 | /-- The coordinate representation of a Euclidean endomorphism. -/ |
| 88 | noncomputable def euclideanCoordinateLinearMap |
| 89 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) : |
| 90 | (Fin 3 → ℝ) →ₗ[ℝ] (Fin 3 → ℝ) := |
| 91 | (WithLp.linearEquiv 2 ℝ (Fin 3 → ℝ)).toLinearMap.comp |
| 92 | (A.toLinearMap.comp (WithLp.linearEquiv 2 ℝ (Fin 3 → ℝ)).symm.toLinearMap) |
| 93 | |
| 94 | @[simp] |
| 95 | theorem euclideanCoordinateLinearMap_apply |
| 96 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) (v : Fin 3 → ℝ) : |
| 97 | euclideanCoordinateLinearMap A v = (A (WithLp.toLp 2 v)).ofLp := rfl |
| 98 | |
| 99 | /-- The polynomial cofactor normal in Euclidean three-space. -/ |
| 100 | noncomputable def euclideanCofactorNormal |
| 101 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) |
| 102 | (p : EuclideanSpace ℝ (Fin 3)) : EuclideanSpace ℝ (Fin 3) := |
| 103 | WithLp.toLp 2 (cofactorNormal (euclideanCoordinateLinearMap A) p) |
| 104 | |
| 105 | private theorem inner_eq_dotProduct (p v : EuclideanSpace ℝ (Fin 3)) : |
| 106 | inner ℝ p v = p ⬝ᵥ v := by |
| 107 | rw [EuclideanSpace.inner_eq_star_dotProduct, star_trivial, dotProduct_comm] |
| 108 | |
| 109 | /-- The Euclidean cofactor normal is orthogonal to the image tangent plane. -/ |
| 110 | theorem inner_euclideanCofactorNormal_apply_eq_zero |
| 111 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) |
| 112 | (p v : EuclideanSpace ℝ (Fin 3)) (hv : inner ℝ p v = 0) : |
| 113 | inner ℝ (euclideanCofactorNormal A p) (A v) = 0 := by |
| 114 | simp only [inner_eq_dotProduct] at hv ⊢ |
| 115 | exact cofactorNormal_dot_apply_eq_zero (euclideanCoordinateLinearMap A) p v hv |
| 116 | |
| 117 | /-- A cofactor normal to an injectively mapped Euclidean tangent plane is nonzero. -/ |
| 118 | theorem euclideanCofactorNormal_ne_zero |
| 119 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) |
| 120 | (p : EuclideanSpace ℝ (Fin 3)) (hp : inner ℝ p p = 1) |
| 121 | (hA : Set.InjOn A {v | inner ℝ p v = 0}) : euclideanCofactorNormal A p ≠ 0 := by |
| 122 | have hAc : Set.InjOn (euclideanCoordinateLinearMap A) {v | p ⬝ᵥ v = 0} := by |
| 123 | intro u hu v hv huv |
| 124 | have h := hA (x₁ := WithLp.toLp 2 u) (x₂ := WithLp.toLp 2 v) |
| 125 | (by simpa only [Set.mem_ofPred_eq, inner_eq_dotProduct, WithLp.ofLp_toLp] using hu) |
| 126 | (by simpa only [Set.mem_ofPred_eq, inner_eq_dotProduct, WithLp.ofLp_toLp] using hv) |
| 127 | (WithLp.ofLp_injective 2 huv) |
| 128 | exact congrArg WithLp.ofLp h |
| 129 | have hpc : p ⬝ᵥ p = 1 := by |
| 130 | simpa only [inner_eq_dotProduct] using hp |
| 131 | intro h |
| 132 | exact cofactorNormal_ne_zero _ _ hpc hAc (congrArg WithLp.ofLp h) |
| 133 | |
| 134 | /-- Euclidean tangent completion by the cofactor normal is injective. -/ |
| 135 | theorem injective_tangent_add_euclideanCofactorNormal |
| 136 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) |
| 137 | (p : EuclideanSpace ℝ (Fin 3)) (hp : inner ℝ p p = 1) |
| 138 | (hA : Set.InjOn A {v | inner ℝ p v = 0}) : |
| 139 | Function.Injective fun v => |
| 140 | A (v - (inner ℝ p v) • p) + (inner ℝ p v) • euclideanCofactorNormal A p := by |
| 141 | have hAc : Set.InjOn (euclideanCoordinateLinearMap A) {v | p ⬝ᵥ v = 0} := by |
| 142 | intro u hu v hv huv |
| 143 | have h := hA (x₁ := WithLp.toLp 2 u) (x₂ := WithLp.toLp 2 v) |
| 144 | (by simpa only [Set.mem_ofPred_eq, inner_eq_dotProduct, WithLp.ofLp_toLp] using hu) |
| 145 | (by simpa only [Set.mem_ofPred_eq, inner_eq_dotProduct, WithLp.ofLp_toLp] using hv) |
| 146 | (WithLp.ofLp_injective 2 huv) |
| 147 | exact congrArg WithLp.ofLp h |
| 148 | have hpc : p ⬝ᵥ p = 1 := by |
| 149 | simpa only [inner_eq_dotProduct] using hp |
| 150 | intro u v huv |
| 151 | apply WithLp.ofLp_injective |
| 152 | apply injective_tangent_add_cofactorNormal _ _ hpc hAc |
| 153 | simpa only [inner_eq_dotProduct, euclideanCoordinateLinearMap_apply, euclideanCofactorNormal, |
| 154 | WithLp.ofLp_add, WithLp.ofLp_smul, |
| 155 | WithLp.toLp_sub, WithLp.toLp_smul, WithLp.toLp_ofLp, WithLp.ofLp_toLp] using |
| 156 | congrArg WithLp.ofLp huv |
| 157 | |
| 158 | /-- The annihilator of an injectively mapped tangent plane is the line |
| 159 | spanned by its cofactor normal. -/ |
| 160 | theorem orthogonal_tangent_iff_smul_euclideanCofactorNormal |
| 161 | (A : EuclideanSpace ℝ (Fin 3) →L[ℝ] EuclideanSpace ℝ (Fin 3)) |
| 162 | (p w : EuclideanSpace ℝ (Fin 3)) (hp : inner ℝ p p = 1) |
| 163 | (hA : Set.InjOn A {v | inner ℝ p v = 0}) : |
| 164 | (∀ v, inner ℝ p v = 0 → inner ℝ w (A v) = 0) ↔ |
| 165 | ∃ c : ℝ, w = c • euclideanCofactorNormal A p := by |
| 166 | let N := euclideanCofactorNormal A p |
| 167 | let B : EuclideanSpace ℝ (Fin 3) →ₗ[ℝ] EuclideanSpace ℝ (Fin 3) := |
| 168 | A.toLinearMap.comp (LinearMap.id - (innerSL ℝ p).toLinearMap.smulRight p) + |
| 169 | (innerSL ℝ p).toLinearMap.smulRight N |
| 170 | have hB (v) : B v = A (v - inner ℝ p v • p) + inner ℝ p v • N := rfl |
| 171 | constructor |
| 172 | · intro hw |
| 173 | have hi : Function.Injective B := injective_tangent_add_euclideanCofactorNormal A p hp hA |
| 174 | obtain ⟨v, hv⟩ := (LinearMap.injective_iff_surjective.mp hi) w |
| 175 | have ht : inner ℝ p (v - inner ℝ p v • p) = 0 := by |
| 176 | simp only [inner_sub_right, inner_smul_right, hp, mul_one, sub_self] |
| 177 | have hz := hw (v - inner ℝ p v • p) ht |
| 178 | rw [← hv, hB, inner_add_left, inner_smul_left, |
| 179 | inner_euclideanCofactorNormal_apply_eq_zero A p _ ht, mul_zero, add_zero] at hz |
| 180 | have hzero := inner_self_eq_zero.mp hz |
| 181 | refine ⟨inner ℝ p v, ?_⟩ |
| 182 | rw [← hv, hB, hzero, zero_add] |
| 183 | · rintro ⟨c, rfl⟩ v hv |
| 184 | rw [inner_smul_left, inner_euclideanCofactorNormal_apply_eq_zero A p v hv, mul_zero] |
| 185 | |
| 186 | end Poincare.LinearAlgebra |