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 Mathlib.Analysis.Calculus.Rademacher |
| 2 | import Mathlib.MeasureTheory.Integral.IntervalIntegral.AbsolutelyContinuousFun |
| 3 | import Mathlib.Topology.MetricSpace.Thickening |
| 4 | import Mathlib.Tactic |
| 5 | |
| 6 | /-! |
| 7 | # Distance bounds from almost-everywhere derivative bounds |
| 8 | |
| 9 | Translated segments avoid a null exceptional set for almost every translation. |
| 10 | Absolute continuity permits integration along those segments, and continuity |
| 11 | removes the translation. This also covers exceptional sets containing a whole |
| 12 | segment. |
| 13 | -/ |
| 14 | |
| 15 | open Set Filter MeasureTheory |
| 16 | open scoped Topology NNReal |
| 17 | |
| 18 | namespace Poincare.Analysis.WeakDerivative |
| 19 | |
| 20 | variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 21 | [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] |
| 22 | |
| 23 | omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in |
| 24 | private theorem segment_bound {f : E → ℝ} {K : ℝ≥0} |
| 25 | (hf : LipschitzWith K f) (z v : E) {C : ℝ} |
| 26 | (hderiv : ∀ᵐ t ∂volume.restrict (Icc (0 : ℝ) 1), |
| 27 | DifferentiableAt ℝ f (z + t • v) ∧ ‖fderiv ℝ f (z + t • v)‖ ≤ C) : |
| 28 | |f (z + v) - f z| ≤ C * ‖v‖ := by |
| 29 | let L : ℝ →L[ℝ] E := ContinuousLinearMap.smulRight (1 : ℝ →L[ℝ] ℝ) v |
| 30 | let F : ℝ → ℝ := fun t => f (z + t • v) |
| 31 | have hF : LipschitzWith (K * (0 + ‖L‖₊)) F := |
| 32 | hf.comp ((LipschitzWith.const z).add L.lipschitz) |
| 33 | have hAC := hF.lipschitzOnWith.absolutelyContinuousOnInterval (a := 0) (b := 1) |
| 34 | have hbound : ∀ᵐ t ∂volume.restrict (Icc (0 : ℝ) 1), |
| 35 | |deriv F t| ≤ C * ‖v‖ := by |
| 36 | filter_upwards [hderiv] with t ht |
| 37 | have hpath : HasDerivAt (fun t : ℝ => z + t • v) v t := by |
| 38 | simpa [L] using L.hasDerivAt.const_add z |
| 39 | have hd := ht.1.hasFDerivAt.comp_hasDerivAt t hpath |
| 40 | rw [show deriv F t = fderiv ℝ f (z + t • v) v from hd.deriv] |
| 41 | exact (fderiv ℝ f (z + t • v)).le_opNorm v |>.trans |
| 42 | (mul_le_mul_of_nonneg_right ht.2 (norm_nonneg v)) |
| 43 | calc |
| 44 | |f (z + v) - f z| = |∫ t in (0 : ℝ)..1, deriv F t| := by |
| 45 | rw [hAC.integral_deriv_eq_sub] |
| 46 | simp [F] |
| 47 | _ ≤ ∫ t in (0 : ℝ)..1, |deriv F t| := |
| 48 | intervalIntegral.abs_integral_le_integral_abs (by norm_num) |
| 49 | _ ≤ ∫ _t in (0 : ℝ)..1, C * ‖v‖ := |
| 50 | intervalIntegral.integral_mono_ae_restrict (by norm_num) |
| 51 | hAC.intervalIntegrable_deriv.abs intervalIntegrable_const hbound |
| 52 | _ = C * ‖v‖ := by simp |
| 53 | |
| 54 | /-- A full-measure derivative bound improves the Lipschitz constant on an |
| 55 | open convex domain. The ambient Lipschitz constant is only used for absolute |
| 56 | continuity, so no regularity is required on the null exceptional set. -/ |
| 57 | theorem lipschitzOnWith_of_ae_fderiv_bound |
| 58 | (μ : Measure E) [μ.IsAddHaarMeasure] {U G : Set E} |
| 59 | (hU : IsOpen U) (hconv : Convex ℝ U) (hG : MeasurableSet G) |
| 60 | (hfull : ∀ᵐ x ∂μ, x ∈ U → x ∈ G) |
| 61 | {f : E → ℝ} {K C : ℝ≥0} (hf : LipschitzWith K f) |
| 62 | (hderiv : ∀ x ∈ U ∩ G, DifferentiableAt ℝ f x ∧ ‖fderiv ℝ f x‖ ≤ C) : |
| 63 | LipschitzOnWith C f U := by |
| 64 | apply LipschitzOnWith.of_dist_le_mul |
| 65 | intro x hx y hy |
| 66 | let v := y - x |
| 67 | let L : ℝ →L[ℝ] E := ContinuousLinearMap.smulRight (1 : ℝ →L[ℝ] ℝ) v |
| 68 | have hfull' : ∀ᵐ z ∂μ, z ∈ Uᶜ ∪ G := by |
| 69 | filter_upwards [hfull] with z hz |
| 70 | by_cases hzU : z ∈ U |
| 71 | · exact Or.inr (hz hzU) |
| 72 | · exact Or.inl hzU |
| 73 | have hline : ∀ᵐ z ∂μ, ∀ᵐ t ∂volume, z + t • v ∈ Uᶜ ∪ G := |
| 74 | (ae_ae_add_linearMap_mem_iff L.toLinearMap volume μ |
| 75 | (hU.measurableSet.compl.union hG)).mpr hfull' |
| 76 | have hseg : (fun t : ℝ => x + t • v) '' Icc 0 1 ⊆ U := by |
| 77 | rintro _ ⟨t, ht, rfl⟩ |
| 78 | exact hconv.add_smul_sub_mem hx hy ht |
| 79 | obtain ⟨δ, hδ, hδU⟩ := |
| 80 | (isCompact_Icc.image (by fun_prop : Continuous (fun t : ℝ => x + t • v))).exists_thickening_subset_open hU hseg |
| 81 | have hnear : ∀ z, dist z x < δ → (∀ᵐ (t : ℝ) ∂volume, z + t • v ∈ Uᶜ ∪ G) → |
| 82 | |f (z + v) - f z| ≤ (C : ℝ) * ‖v‖ := by |
| 83 | intro z hz hgood |
| 84 | apply segment_bound hf z v |
| 85 | filter_upwards [ae_restrict_of_ae hgood, ae_restrict_mem measurableSet_Icc] with t ht htI |
| 86 | have htU : z + t • v ∈ U := by |
| 87 | apply hδU |
| 88 | apply Metric.mem_thickening_iff.mpr |
| 89 | refine ⟨x + t • v, ⟨t, htI, rfl⟩, ?_⟩ |
| 90 | simpa only [dist_add_right] using hz |
| 91 | exact hderiv _ ⟨htU, ht.resolve_left (not_not.mpr htU)⟩ |
| 92 | have hclosed : IsClosed {z : E | |f (z + v) - f z| ≤ (C : ℝ) * ‖v‖} := |
| 93 | isClosed_le ((hf.continuous.comp (continuous_id.add continuous_const)).sub |
| 94 | hf.continuous).abs continuous_const |
| 95 | have hxclosed : x ∈ {z : E | |f (z + v) - f z| ≤ (C : ℝ) * ‖v‖} := by |
| 96 | apply hclosed.closure_subset |
| 97 | apply Metric.mem_closure_iff.mpr |
| 98 | intro ε hε |
| 99 | obtain ⟨z, hz, hzx⟩ := (μ.dense_of_ae hline).exists_dist_lt x (lt_min hδ hε) |
| 100 | refine ⟨z, hnear z ?_ hz, hzx.trans_le (min_le_right _ _)⟩ |
| 101 | exact (dist_comm z x).trans_lt (hzx.trans_le (min_le_left _ _)) |
| 102 | simpa [v, Real.dist_eq, dist_eq_norm, abs_sub_comm, norm_sub_rev] using hxclosed |
| 103 | |
| 104 | /-- Domain-local version, using a Lipschitz extension only to integrate the |
| 105 | translated segments. -/ |
| 106 | theorem lipschitzOnWith_of_ae_fderiv_bound_on |
| 107 | (μ : Measure E) [μ.IsAddHaarMeasure] {U G : Set E} |
| 108 | (hU : IsOpen U) (hconv : Convex ℝ U) (hG : MeasurableSet G) |
| 109 | (hfull : ∀ᵐ x ∂μ, x ∈ U → x ∈ G) |
| 110 | {f : E → ℝ} {K C : ℝ≥0} (hf : LipschitzOnWith K f U) |
| 111 | (hderiv : ∀ x ∈ U ∩ G, DifferentiableAt ℝ f x ∧ ‖fderiv ℝ f x‖ ≤ C) : |
| 112 | LipschitzOnWith C f U := by |
| 113 | obtain ⟨F, hF, heq⟩ := hf.extend_real |
| 114 | have hbound : LipschitzOnWith C F U := |
| 115 | lipschitzOnWith_of_ae_fderiv_bound μ hU hconv hG hfull hF (by |
| 116 | intro x hx |
| 117 | have hlocal : f =ᶠ[𝓝 x] F := |
| 118 | heq.eventuallyEq_of_mem (hU.mem_nhds hx.1) |
| 119 | obtain ⟨hd, hb⟩ := hderiv x hx |
| 120 | exact ⟨hd.congr_of_eventuallyEq hlocal.symm, hlocal.fderiv_eq (𝕜 := ℝ) ▸ hb⟩) |
| 121 | intro x hx y hy |
| 122 | rw [heq hx, heq hy] |
| 123 | exact hbound hx hy |
| 124 | |
| 125 | end Poincare.Analysis.WeakDerivative |