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.CurveShortening.Comparison.Approximation |
| 2 | |
| 3 | /-! |
| 4 | # Length of the unsmoothed sampled polygon |
| 5 | |
| 6 | The actual concatenated polygon is smooth on the interior of each closed |
| 7 | cell. Its corner values form a finite null set, so its derivative integral |
| 8 | is the sum of the constant side speeds. This is the raw length clause in |
| 9 | M64 Definition 19.18 and Claim 19.19, MT2007 p. 450. |
| 10 | |
| 11 | Morgan--Tian context: Section 19.4, Definition 19.18 and Claims 19.19-19.22, printed pp. |
| 12 | 450-453. |
| 13 | -/ |
| 14 | |
| 15 | set_option autoImplicit false |
| 16 | set_option backward.isDefEq.respectTransparency false |
| 17 | |
| 18 | open Bundle Set Filter MeasureTheory |
| 19 | open scoped Manifold ContDiff Bundle BigOperators intervalIntegral Topology |
| 20 | |
| 21 | universe u |
| 22 | |
| 23 | namespace PoincareMT |
| 24 | |
| 25 | variable {n : ℕ} {M : Type u} [TopologicalSpace M] |
| 26 | [ChartedSpace (EuclideanSpace ℝ (Fin n)) M] |
| 27 | [IsManifold (𝓡 n) ∞ M] |
| 28 | {g : RiemannianMetric n M} {D : LeviCivitaData g} {N : ℕ} |
| 29 | |
| 30 | private theorem cellLength_pos {N : ℕ} (hN : 0 < N) : 0 < m63CellLength N := by |
| 31 | dsimp only [m63CellLength] |
| 32 | exact div_pos Real.two_pi_pos (by exact_mod_cast hN) |
| 33 | |
| 34 | private theorem count_mul_cellLength {N : ℕ} (hN : 0 < N) : |
| 35 | (N : ℝ) * m63CellLength N = curvePeriod := by |
| 36 | dsimp only [m63CellLength, curvePeriod] |
| 37 | field_simp |
| 38 | |
| 39 | omit [IsManifold (𝓡 n) ∞ M] in |
| 40 | private theorem curveVelocity_comp_local {gamma : ℝ → M} {phi : ℝ → ℝ} {x v : ℝ} |
| 41 | (hgamma : MDifferentiableAt 𝓘(ℝ, ℝ) (𝓡 n) gamma (phi x)) |
| 42 | (hphi : HasDerivAt phi v x) : |
| 43 | curveVelocity (n := n) (fun y => gamma (phi y)) x = |
| 44 | v • curveVelocity (n := n) gamma (phi x) := by |
| 45 | have hvalue : mfderiv 𝓘(ℝ, ℝ) 𝓘(ℝ, ℝ) phi x 1 = v := by |
| 46 | rw [mfderiv_eq_fderiv, hphi.hasFDerivAt.fderiv] |
| 47 | exact ContinuousLinearMap.toSpanSingleton_apply_one ℝ v |
| 48 | have hcomp := mfderiv_comp_apply (f := phi) (g := gamma) x hgamma |
| 49 | hphi.hasFDerivAt.hasMFDerivAt.mdifferentiableAt (1 : ℝ) |
| 50 | exact hcomp.trans ((congrArg (mfderiv 𝓘(ℝ, ℝ) (𝓡 n) gamma (phi x)) hvalue).trans (by |
| 51 | simpa only [curveVelocity, smul_eq_mul, mul_one] using |
| 52 | (mfderiv 𝓘(ℝ, ℝ) (𝓡 n) gamma (phi x)).map_smul v (1 : ℝ))) |
| 53 | |
| 54 | private theorem polygon_cell_speed_ae |
| 55 | (polygon : M63GeodesicPolygon g D N) (hN : 0 < N) |
| 56 | (j : Fin N) : |
| 57 | ∀ᵐ x : ℝ ∂volume, |
| 58 | x ∈ Set.uIoc (m63CellLeft N j) |
| 59 | (m63CellLeft N j + m63CellLength N) → |
| 60 | g.tangentNorm (polygon.map x) |
| 61 | (curveVelocity (n := n) polygon.map x) = |
| 62 | (polygon.side j).speed := by |
| 63 | let ell := m63CellLength N |
| 64 | let left := m63CellLeft N j |
| 65 | let right := left + ell |
| 66 | have hell : 0 < ell := cellLength_pos hN |
| 67 | have hleft : left < right := by dsimp [right]; linarith |
| 68 | have hne : ∀ᵐ x : ℝ ∂volume, x ≠ right := by |
| 69 | simp [ae_iff, measure_singleton] |
| 70 | filter_upwards [hne] with x hx hxu |
| 71 | have hxu' : x ∈ Ioc left right := by |
| 72 | simpa only [uIoc_of_le hleft.le, left, right, ell] using hxu |
| 73 | have hxint : x ∈ Ioo left right := ⟨hxu'.1, lt_of_le_of_ne hxu'.2 hx⟩ |
| 74 | let S : Set ℝ := Icc left right |
| 75 | have hxS : x ∈ S := ⟨hxint.1.le, hxint.2.le⟩ |
| 76 | have hmap : EqOn polygon.map ((polygon.side j).map ∘ (fun y => y - left)) S := by |
| 77 | intro y hy |
| 78 | have hys : y - left ∈ Icc 0 ell := by |
| 79 | dsimp [S, left, right, ell] at hy ⊢ |
| 80 | constructor <;> linarith [hy.1, hy.2] |
| 81 | simpa [left, Function.comp_apply, sub_add_cancel] using polygon.cell_agreement j (y - left) hys |
| 82 | have hysx : x - left ∈ Icc 0 ell := by |
| 83 | dsimp [left, right, ell] at hxint ⊢ |
| 84 | constructor <;> linarith [hxint.1, hxint.2] |
| 85 | have hsideAt : MDifferentiableAt 𝓘(ℝ, ℝ) (𝓡 n) |
| 86 | (polygon.side j).map (x - left) := |
| 87 | ((polygon.side j).smooth.contMDiffAt |
| 88 | ((polygon.side j).domain_open.mem_nhds |
| 89 | ((polygon.side j).interval_subset hysx))).mdifferentiableAt (by simp) |
| 90 | have hside : MDifferentiableAt 𝓘(ℝ, ℝ) (𝓡 n) |
| 91 | ((polygon.side j).map ∘ (fun y : ℝ => y - left)) x := |
| 92 | hsideAt.comp x ((hasDerivAt_id x).sub_const left).differentiableAt.mdifferentiableAt |
| 93 | have hflat : MDifferentiableAt 𝓘(ℝ, ℝ) (𝓡 n) polygon.map x := by |
| 94 | have hEqAt : polygon.map =ᶠ[𝓝 x] (polygon.side j).map ∘ (fun y : ℝ => y - left) := |
| 95 | by |
| 96 | filter_upwards [isOpen_Ioo.mem_nhds hxint] with y hy |
| 97 | exact hmap ⟨hy.1.le, hy.2.le⟩ |
| 98 | exact hside.congr_of_eventuallyEq hEqAt |
| 99 | have hunique : UniqueMDiffWithinAt 𝓘(ℝ, ℝ) S x := |
| 100 | ((uniqueDiffOn_Icc hleft) x hxS).uniqueMDiffWithinAt |
| 101 | have hderiv := mfderivWithin_congr_of_mem (I := 𝓘(ℝ, ℝ)) |
| 102 | (I' := 𝓡 n) hmap hxS |
| 103 | rw [mfderivWithin_eq_mfderiv hunique hflat, |
| 104 | mfderivWithin_eq_mfderiv hunique hside] at hderiv |
| 105 | have hvelocity : curveVelocity (n := n) polygon.map x = |
| 106 | curveVelocity (n := n) ((polygon.side j).map ∘ (fun y : ℝ => y - left)) x := by |
| 107 | change mfderiv 𝓘(ℝ, ℝ) (𝓡 n) polygon.map x 1 = _ |
| 108 | exact congrArg (fun L => L 1) hderiv |
| 109 | have hpoint : polygon.map x = (polygon.side j).map (x - left) := hmap hxS |
| 110 | rw [hpoint, hvelocity] |
| 111 | have hphi : HasDerivAt (fun y : ℝ => y - left) 1 x := |
| 112 | (hasDerivAt_id x).sub_const left |
| 113 | change g.tangentNorm ((polygon.side j).map (x - left)) |
| 114 | (curveVelocity (n := n) (fun y : ℝ => (polygon.side j).map (y - left)) x) = _ |
| 115 | rw [curveVelocity_comp_local (gamma := (polygon.side j).map) |
| 116 | (phi := fun y : ℝ => y - left) (x := x) (v := 1) hsideAt hphi] |
| 117 | simpa only [Function.comp_apply, curveVelocity, one_smul] using |
| 118 | ((polygon.side j).constant_speed (x - left) (by |
| 119 | dsimp [left, right, ell] at hxint ⊢ |
| 120 | constructor <;> linarith [hxint.1, hxint.2])) |
| 121 | |
| 122 | /-- The actual derivative-integral length equals the sum of side lengths. Source: Auxiliary |
| 123 | step for MT Definition 19.18 and Claims 19.19/19.22, pp. 450-453; project construction in |
| 124 | `proof-work/tasks/M64/reports/2026-09-23-static-polygon.md`. -/ |
| 125 | theorem m64PolygonLength_eq_sum |
| 126 | (polygon : M63GeodesicPolygon g D N) (hN : 0 < N) : |
| 127 | m64PolygonLength polygon = |
| 128 | ∑ j : Fin N, m63CellLength N * (polygon.side j).speed := by |
| 129 | let ell := m63CellLength N |
| 130 | have hell : 0 < ell := cellLength_pos hN |
| 131 | have hcell (j : Fin N) : |
| 132 | (∫ x in m63CellLeft N j..(m63CellLeft N j + ell), |
| 133 | g.tangentNorm (polygon.map x) (curveVelocity (n := n) polygon.map x)) = |
| 134 | ell * (polygon.side j).speed := by |
| 135 | have hEq : (fun x => g.tangentNorm (polygon.map x) |
| 136 | (curveVelocity (n := n) polygon.map x)) =ᵐ[volume.restrict |
| 137 | (Set.uIoc (m63CellLeft N j) (m63CellLeft N j + ell))] |
| 138 | (fun _ => (polygon.side j).speed) := by |
| 139 | apply (ae_restrict_iff' measurableSet_uIoc).2 |
| 140 | simpa only [ell] using polygon_cell_speed_ae polygon hN j |
| 141 | rw [intervalIntegral.integral_congr_ae_restrict hEq] |
| 142 | simp only [intervalIntegral.integral_const, smul_eq_mul] |
| 143 | dsimp [ell] |
| 144 | ring |
| 145 | have hsum : |
| 146 | (∑ j : Fin N, ∫ x in m63CellLeft N j..(m63CellLeft N j + ell), |
| 147 | g.tangentNorm (polygon.map x) (curveVelocity (n := n) polygon.map x)) = |
| 148 | ∫ x in (0 : ℝ)..curvePeriod, |
| 149 | g.tangentNorm (polygon.map x) (curveVelocity (n := n) polygon.map x) := by |
| 150 | have htel := intervalIntegral.sum_integral_adjacent_intervals |
| 151 | (a := fun k : ℕ => (k : ℝ) * ell) (n := N) (μ := volume) |
| 152 | (fun j hj => by |
| 153 | let jj : Fin N := ⟨j, hj⟩ |
| 154 | have hEq : (fun x => g.tangentNorm (polygon.map x) |
| 155 | (curveVelocity (n := n) polygon.map x)) =ᵐ[volume.restrict |
| 156 | (Set.uIoc (m63CellLeft N jj) |
| 157 | (m63CellLeft N jj + ell))] |
| 158 | (fun _ => (polygon.side jj).speed) := by |
| 159 | apply (ae_restrict_iff' measurableSet_uIoc).2 |
| 160 | simpa only [ell, jj] using polygon_cell_speed_ae polygon hN jj |
| 161 | have hint := (intervalIntegrable_congr_ae hEq).mpr intervalIntegrable_const |
| 162 | simpa only [m63CellLeft, ell, Nat.cast_add, Nat.cast_one, add_mul, |
| 163 | one_mul] using hint) |
| 164 | rw [← Fin.sum_univ_eq_sum_range] at htel |
| 165 | simpa only [m63CellLeft, ell, Nat.cast_add, Nat.cast_one, add_mul, one_mul, |
| 166 | Nat.cast_zero, zero_mul, count_mul_cellLength hN, curvePeriod] using htel |
| 167 | change (∫ x in (0 : ℝ)..curvePeriod, |
| 168 | g.tangentNorm (polygon.map x) (curveVelocity (n := n) polygon.map x)) = _ |
| 169 | rw [← hsum] |
| 170 | exact Finset.sum_congr rfl (fun j _ => hcell j) |
| 171 | |
| 172 | end PoincareMT |