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.Elliptic.Regularity.WeakInequalityLipschitz |
| 2 | import PoincareLib.Analysis.Elliptic.Regularity.Sobolev.Weak.LipschitzDerivatives |
| 3 | |
| 4 | /-! |
| 5 | # Nonnegative difference tests in weak inequalities |
| 6 | |
| 7 | A uniform bound on the difference of two locally Lipschitz functions makes |
| 8 | the literal test `phi * (v - u + epsilon)` admissible. Its actual derivative |
| 9 | then gives the tested comparison inequality used in Morgan--Tian, |
| 10 | Claim 9.22, pp. 190-191. |
| 11 | -/ |
| 12 | |
| 13 | noncomputable section |
| 14 | |
| 15 | open Set MeasureTheory Filter |
| 16 | open scoped Topology ENNReal NNReal |
| 17 | |
| 18 | namespace Poincare.Analysis.Elliptic |
| 19 | |
| 20 | variable {d : ℕ} |
| 21 | local notation "E" => EuclideanSpace ℝ (Fin d) |
| 22 | |
| 23 | /-- Local Lipschitz control and a uniform difference bound make the literal |
| 24 | cutoff comparison a nonnegative globally Lipschitz function. -/ |
| 25 | theorem compact_lipschitz_comparison_test |
| 26 | {O : Set E} {u v φ : E → ℝ} {A B ε : ℝ≥0} |
| 27 | (hu : LipschitzOnWith A u O) (hv : LipschitzOnWith B v O) |
| 28 | (herr : ∀ x ∈ O, |u x - v x| ≤ ε) |
| 29 | (hφ : ContDiff ℝ (⊤ : ℕ∞) φ) (hφc : HasCompactSupport φ) |
| 30 | (hφO : tsupport φ ⊆ O) (hφ0 : ∀ x, 0 ≤ φ x) (hφ1 : ∀ x, φ x ≤ 1) : |
| 31 | (∀ x, 0 ≤ φ x * (v x - u x + ε)) ∧ |
| 32 | ∃ D : ℝ≥0, LipschitzWith D (fun x => φ x * (v x - u x + ε)) := by |
| 33 | have hdiff : LipschitzOnWith (B + A) (fun x => v x - u x + (ε : ℝ)) O := by |
| 34 | simpa using (hv.sub hu).add (LipschitzWith.const (ε : ℝ)).lipschitzOnWith |
| 35 | obtain ⟨w, hw, heq⟩ := hdiff.extend_real |
| 36 | let z : E → ℝ := fun x => max 0 (min (2 * (ε : ℝ)) (w x)) |
| 37 | have hz : LipschitzWith (B + A) z := (hw.const_min _).const_max _ |
| 38 | have hz0 (x) : 0 ≤ z x := le_max_left _ _ |
| 39 | have hzB (x) : z x ≤ 2 * (ε : ℝ) := |
| 40 | max_le (by positivity) (min_le_left _ _) |
| 41 | have hprod : (fun x => φ x * z x) = (fun x => φ x * (v x - u x + ε)) := by |
| 42 | funext x |
| 43 | by_cases hx : φ x = 0 |
| 44 | · simp only [hx, zero_mul] |
| 45 | · have hxO := hφO (subset_tsupport _ hx) |
| 46 | have hb := abs_le.mp (herr x hxO) |
| 47 | have hlo : 0 ≤ v x - u x + (ε : ℝ) := by linarith |
| 48 | have hhi : v x - u x + (ε : ℝ) ≤ 2 * (ε : ℝ) := by linarith |
| 49 | simp only [z, ← heq hxO, min_eq_right hhi, max_eq_right hlo] |
| 50 | constructor |
| 51 | · intro x |
| 52 | rw [← congrFun hprod x] |
| 53 | exact mul_nonneg (hφ0 x) (hz0 x) |
| 54 | rw [← hprod] |
| 55 | obtain ⟨C, hC⟩ := ContDiff.lipschitzWith_of_hasCompactSupport hφc hφ (by simp) |
| 56 | refine ⟨B + A + 2 * ε * C, LipschitzWith.of_dist_le_mul fun x y => ?_⟩ |
| 57 | have hp := hC.dist_le_mul x y |
| 58 | have hq := hz.dist_le_mul x y |
| 59 | simp only [Real.dist_eq] at hp hq ⊢ |
| 60 | calc |
| 61 | |φ x * z x - φ y * z y| = |φ x * (z x - z y) + z y * (φ x - φ y)| := by ring_nf |
| 62 | _ ≤ |φ x * (z x - z y)| + |z y * (φ x - φ y)| := abs_add_le _ _ |
| 63 | _ = φ x * |z x - z y| + z y * |φ x - φ y| := by |
| 64 | rw [abs_mul, abs_mul, abs_of_nonneg (hφ0 x), abs_of_nonneg (hz0 y)] |
| 65 | _ ≤ 1 * ((B + A : ℝ≥0) * dist x y) + (2 * (ε : ℝ)) * (C * dist x y) := |
| 66 | add_le_add (mul_le_mul (hφ1 x) hq (abs_nonneg _) (by norm_num)) |
| 67 | (mul_le_mul (hzB y) hp (abs_nonneg _) (by positivity)) |
| 68 | _ = ((B + A + 2 * ε * C : ℝ≥0) : ℝ) * dist x y := by push_cast; ring |
| 69 | |
| 70 | /-- The smooth-test divergence inequality admits the explicit comparison |
| 71 | test, with its product derivative expanded almost everywhere. -/ |
| 72 | theorem weakInequality_comparison_test |
| 73 | {O : Set E} (hO : IsOpen O) {F : Fin d → E → ℝ} {f u v φ : E → ℝ} |
| 74 | (hF : ∀ i, MemLp (F i) 2 (volume.restrict O)) |
| 75 | (hf : MemLp f 2 (volume.restrict O)) |
| 76 | (hle : ∀ ψ : E → ℝ, ContDiff ℝ (⊤ : ℕ∞) ψ → HasCompactSupport ψ → |
| 77 | tsupport ψ ⊆ O → (∀ x, 0 ≤ ψ x) → |
| 78 | (∫ x in O, ∑ i, F i x * fderiv ℝ ψ x (EuclideanSpace.single i 1)) ≤ |
| 79 | ∫ x in O, f x * ψ x) |
| 80 | {A B ε : ℝ≥0} (hu : LipschitzOnWith A u O) (hv : LipschitzOnWith B v O) |
| 81 | (herr : ∀ x ∈ O, |u x - v x| ≤ ε) |
| 82 | (hφ : ContDiff ℝ (⊤ : ℕ∞) φ) (hφc : HasCompactSupport φ) |
| 83 | (hφO : tsupport φ ⊆ O) (hφ0 : ∀ x, 0 ≤ φ x) (hφ1 : ∀ x, φ x ≤ 1) : |
| 84 | (∫ x in O, ∑ i, F i x * |
| 85 | (φ x * (fderiv ℝ v x (EuclideanSpace.single i 1) - |
| 86 | fderiv ℝ u x (EuclideanSpace.single i 1)) + |
| 87 | (v x - u x + ε) * fderiv ℝ φ x (EuclideanSpace.single i 1))) ≤ |
| 88 | ∫ x in O, f x * (φ x * (v x - u x + ε)) := by |
| 89 | obtain ⟨hψ0, C, hψ⟩ := compact_lipschitz_comparison_test hu hv herr hφ hφc hφO hφ0 hφ1 |
| 90 | have h := weakInequality_of_nonneg_compact_lipschitz hO hF hf hle hψ hψ0 |
| 91 | hφc.mul_right ((tsupport_mul_subset_left (f := φ)).trans hφO) |
| 92 | convert h using 1 |
| 93 | apply integral_congr_ae |
| 94 | filter_upwards [ae_restrict_mem hO.measurableSet, |
| 95 | ae_restrict_of_ae (hu.ae_differentiableWithinAt_of_mem (μ := volume)), |
| 96 | ae_restrict_of_ae (hv.ae_differentiableWithinAt_of_mem (μ := volume))] with x hx hux hvx |
| 97 | have du := (hux hx).differentiableAt (hO.mem_nhds hx) |
| 98 | have dv := (hvx hx).differentiableAt (hO.mem_nhds hx) |
| 99 | rw [fderiv_fun_mul (d := fun x => v x - u x + (ε : ℝ)) |
| 100 | (hφ.differentiable (by simp) x) ((dv.sub du).add_const _), |
| 101 | fderiv_add_const, fderiv_fun_sub dv du] |
| 102 | simp only [add_apply, smul_apply, sub_apply, smul_eq_mul] |
| 103 | |
| 104 | end Poincare.Analysis.Elliptic |