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 | /- |
| 2 | Copyright (c) 2026 The PoincareLib contributors. |
| 3 | -/ |
| 4 | import Mathlib.Analysis.Calculus.ContDiff.Comp |
| 5 | import Mathlib.Analysis.Calculus.Deriv.MeanValue |
| 6 | import Mathlib.Analysis.Calculus.Deriv.Prod |
| 7 | |
| 8 | /-! |
| 9 | # Local preservation of coordinate quadrants |
| 10 | |
| 11 | A continuously differentiable family tangent to the identity in its two |
| 12 | spatial variables preserves their signs near the origin if it preserves the |
| 13 | two coordinate axes there. The neighborhood is uniform in the parameter. |
| 14 | -/ |
| 15 | |
| 16 | set_option autoImplicit false |
| 17 | |
| 18 | open Set Filter Metric |
| 19 | open scoped Topology ContDiff |
| 20 | |
| 21 | namespace Poincare.Analysis |
| 22 | |
| 23 | private theorem signs_of_strictMonoOn {δ x : ℝ} {f : ℝ → ℝ} |
| 24 | (hδ : 0 < δ) (hf : StrictMonoOn f (Ioo (-δ) δ)) (hf0 : f 0 = 0) |
| 25 | (hx : x ∈ Ioo (-δ) δ) : |
| 26 | (0 < f x ↔ 0 < x) ∧ (f x = 0 ↔ x = 0) ∧ (0 ≤ f x ↔ 0 ≤ x) := by |
| 27 | have h0 : (0 : ℝ) ∈ Ioo (-δ) δ := ⟨neg_lt_zero.mpr hδ, hδ⟩ |
| 28 | exact ⟨by simpa [hf0] using hf.lt_iff_lt h0 hx, |
| 29 | by simpa [hf0] using hf.eq_iff_eq hx h0, |
| 30 | by simpa [hf0] using hf.le_iff_le h0 hx⟩ |
| 31 | |
| 32 | /-- A positive first partial derivative and vanishing on the vertical axis |
| 33 | give the sign of the first coordinate on one whole neighborhood. -/ |
| 34 | theorem exists_first_coordinate_sign_radius {f : ℝ × ℝ → ℝ} |
| 35 | (hf : ContDiffAt ℝ 1 f 0) |
| 36 | (hpositive : 0 < fderiv ℝ f 0 (1, 0)) |
| 37 | (hzero : ∀ᶠ q in 𝓝 (0 : ℝ × ℝ), q.1 = 0 → f q = 0) : |
| 38 | ∃ δ > 0, ∀ r t : ℝ, |r| < δ → |t| < δ → |
| 39 | (0 < f (r, t) ↔ 0 < r) ∧ (f (r, t) = 0 ↔ r = 0) ∧ |
| 40 | (0 ≤ f (r, t) ↔ 0 ≤ r) := by |
| 41 | let d (q : ℝ × ℝ) := fderiv ℝ f q (1, 0) |
| 42 | have hd : ContinuousAt d 0 := |
| 43 | (hf.continuousAt_fderiv (by simp)).clm_apply continuousAt_const |
| 44 | have hpos : ∀ᶠ q in 𝓝 (0 : ℝ × ℝ), 0 < d q := |
| 45 | hd.eventually (eventually_gt_nhds hpositive) |
| 46 | have hgood : ∀ᶠ q in 𝓝 (0 : ℝ × ℝ), |
| 47 | DifferentiableAt ℝ f q ∧ 0 < d q ∧ (q.1 = 0 → f q = 0) := by |
| 48 | filter_upwards [hf.eventually (by simp), hpos, hzero] with q hq hp hz |
| 49 | exact ⟨hq.differentiableAt_one, hp, hz⟩ |
| 50 | obtain ⟨δ, hδ, hball⟩ := Metric.mem_nhds_iff.mp hgood |
| 51 | have hlocal {r t : ℝ} (hr : |r| < δ) (ht : |t| < δ) := |
| 52 | hball (show (r, t) ∈ ball (0 : ℝ × ℝ) δ by |
| 53 | simpa only [mem_ball, dist_zero_right, Prod.norm_def, Real.norm_eq_abs, |
| 54 | max_lt_iff] using And.intro hr ht) |
| 55 | refine ⟨δ, hδ, ?_⟩ |
| 56 | intro r t hr ht |
| 57 | have hderiv : ∀ u ∈ Ioo (-δ) δ, |
| 58 | HasDerivAt (fun u => f (u, t)) (d (u, t)) u := by |
| 59 | intro u hu |
| 60 | exact (hlocal (abs_lt.mpr hu) ht).1.hasFDerivAt.comp_hasDerivAt u |
| 61 | ((hasDerivAt_id u).prodMk (hasDerivAt_const u t)) |
| 62 | have hmono : StrictMonoOn (fun u => f (u, t)) (Ioo (-δ) δ) := by |
| 63 | apply strictMonoOn_of_deriv_pos (convex_Ioo (-δ) δ) |
| 64 | · exact fun u hu => (hderiv u hu).continuousAt.continuousWithinAt |
| 65 | · intro u hu |
| 66 | have hu' : u ∈ Ioo (-δ) δ := interior_subset hu |
| 67 | rw [(hderiv u hu').deriv] |
| 68 | exact (hlocal (abs_lt.mpr hu') ht).2.1 |
| 69 | exact signs_of_strictMonoOn hδ hmono |
| 70 | ((hlocal (r := 0) (by simpa using hδ) ht).2.2 rfl) (abs_lt.mp hr) |
| 71 | |
| 72 | /-- A `C¹` parameterized map tangent to the identity in the spatial variables |
| 73 | and locally preserving both coordinate axes preserves all coordinate signs |
| 74 | on one uniform neighborhood of the parameter and spatial origin. -/ |
| 75 | theorem exists_quadrant_preserving_radius {K : ℝ × (ℝ × ℝ) → ℝ × ℝ} |
| 76 | (hK : ContDiffAt ℝ 1 K (0, (0, 0))) |
| 77 | (hdK : HasFDerivAt K (ContinuousLinearMap.snd ℝ ℝ (ℝ × ℝ)) (0, (0, 0))) |
| 78 | (haxes : ∀ᶠ p in 𝓝 (0, (0, 0)), |
| 79 | (p.2.1 = 0 → (K p).1 = 0) ∧ (p.2.2 = 0 → (K p).2 = 0)) : |
| 80 | ∃ δ > 0, ∀ ε s t : ℝ, |ε| < δ → |s| < δ → |t| < δ → |
| 81 | ((0 < (K (ε, (s, t))).1 ↔ 0 < s) ∧ |
| 82 | ((K (ε, (s, t))).1 = 0 ↔ s = 0) ∧ |
| 83 | (0 ≤ (K (ε, (s, t))).1 ↔ 0 ≤ s)) ∧ |
| 84 | ((0 < (K (ε, (s, t))).2 ↔ 0 < t) ∧ |
| 85 | ((K (ε, (s, t))).2 = 0 ↔ t = 0) ∧ |
| 86 | (0 ≤ (K (ε, (s, t))).2 ↔ 0 ≤ t)) := by |
| 87 | let d₁ (p : ℝ × (ℝ × ℝ)) : ℝ := (fderiv ℝ K p (0, (1, 0))).1 |
| 88 | let d₂ (p : ℝ × (ℝ × ℝ)) : ℝ := (fderiv ℝ K p (0, (0, 1))).2 |
| 89 | have hc₁ : ContinuousAt d₁ (0, (0, 0)) := |
| 90 | ((hK.continuousAt_fderiv (by simp)).clm_apply continuousAt_const).fst |
| 91 | have hc₂ : ContinuousAt d₂ (0, (0, 0)) := |
| 92 | ((hK.continuousAt_fderiv (by simp)).clm_apply continuousAt_const).snd |
| 93 | have hp₁ : ∀ᶠ p in 𝓝 (0, (0, 0)), 0 < d₁ p := |
| 94 | hc₁.eventually (eventually_gt_nhds (by simp [d₁, hdK.fderiv])) |
| 95 | have hp₂ : ∀ᶠ p in 𝓝 (0, (0, 0)), 0 < d₂ p := |
| 96 | hc₂.eventually (eventually_gt_nhds (by simp [d₂, hdK.fderiv])) |
| 97 | have hgood : ∀ᶠ p in 𝓝 (0, (0, 0)), |
| 98 | DifferentiableAt ℝ K p ∧ 0 < d₁ p ∧ 0 < d₂ p ∧ |
| 99 | (p.2.1 = 0 → (K p).1 = 0) ∧ (p.2.2 = 0 → (K p).2 = 0) := by |
| 100 | filter_upwards [hK.eventually (by simp), hp₁, hp₂, haxes] with p hp h₁ h₂ ha |
| 101 | exact ⟨hp.differentiableAt_one, h₁, h₂, ha⟩ |
| 102 | obtain ⟨δ, hδ, hball⟩ := Metric.mem_nhds_iff.mp hgood |
| 103 | have hlocal {ε s t : ℝ} (hε : |ε| < δ) (hs : |s| < δ) (ht : |t| < δ) := |
| 104 | hball (show (ε, (s, t)) ∈ ball (0, (0, 0)) δ by |
| 105 | change dist (ε, (s, t)) 0 < δ |
| 106 | simpa only [dist_zero_right, Prod.norm_def, Real.norm_eq_abs, |
| 107 | max_lt_iff] using And.intro hε (And.intro hs ht)) |
| 108 | refine ⟨δ, hδ, ?_⟩ |
| 109 | intro ε s t hε hs ht |
| 110 | have hzero : |(0 : ℝ)| < δ := by simpa using hδ |
| 111 | have hd₁ : ∀ u ∈ Ioo (-δ) δ, |
| 112 | HasDerivAt (fun u => (K (ε, (u, t))).1) (d₁ (ε, (u, t))) u := by |
| 113 | intro u hu |
| 114 | have hpath : HasDerivAt (fun u : ℝ => (ε, (u, t))) (0, (1, 0)) u := |
| 115 | (hasDerivAt_const u ε).prodMk ((hasDerivAt_id u).prodMk (hasDerivAt_const u t)) |
| 116 | simpa only [Function.comp_def, ContinuousLinearMap.comp_apply, |
| 117 | ContinuousLinearMap.coe_fst', d₁] using |
| 118 | (hlocal hε (abs_lt.mpr hu) ht).1.hasFDerivAt.fst.comp_hasDerivAt u hpath |
| 119 | have hm₁ : StrictMonoOn (fun u => (K (ε, (u, t))).1) (Ioo (-δ) δ) := by |
| 120 | apply strictMonoOn_of_deriv_pos (convex_Ioo (-δ) δ) |
| 121 | · exact fun u hu => (hd₁ u hu).continuousAt.continuousWithinAt |
| 122 | · intro u hu |
| 123 | have hu' : u ∈ Ioo (-δ) δ := interior_subset hu |
| 124 | rw [(hd₁ u hu').deriv] |
| 125 | exact (hlocal hε (abs_lt.mpr hu') ht).2.1 |
| 126 | have hz₁ : (K (ε, (0, t))).1 = 0 := (hlocal hε hzero ht).2.2.2.1 rfl |
| 127 | have hd₂ : ∀ u ∈ Ioo (-δ) δ, |
| 128 | HasDerivAt (fun u => (K (ε, (s, u))).2) (d₂ (ε, (s, u))) u := by |
| 129 | intro u hu |
| 130 | have hpath : HasDerivAt (fun u : ℝ => (ε, (s, u))) (0, (0, 1)) u := |
| 131 | (hasDerivAt_const u ε).prodMk ((hasDerivAt_const u s).prodMk (hasDerivAt_id u)) |
| 132 | simpa only [Function.comp_def, ContinuousLinearMap.comp_apply, |
| 133 | ContinuousLinearMap.coe_snd', d₂] using |
| 134 | (hlocal hε hs (abs_lt.mpr hu)).1.hasFDerivAt.snd.comp_hasDerivAt u hpath |
| 135 | have hm₂ : StrictMonoOn (fun u => (K (ε, (s, u))).2) (Ioo (-δ) δ) := by |
| 136 | apply strictMonoOn_of_deriv_pos (convex_Ioo (-δ) δ) |
| 137 | · exact fun u hu => (hd₂ u hu).continuousAt.continuousWithinAt |
| 138 | · intro u hu |
| 139 | have hu' : u ∈ Ioo (-δ) δ := interior_subset hu |
| 140 | rw [(hd₂ u hu').deriv] |
| 141 | exact (hlocal hε hs (abs_lt.mpr hu')).2.2.1 |
| 142 | have hz₂ : (K (ε, (s, 0))).2 = 0 := (hlocal hε hs hzero).2.2.2.2 rfl |
| 143 | exact ⟨signs_of_strictMonoOn hδ hm₁ hz₁ (abs_lt.mp hs), |
| 144 | signs_of_strictMonoOn hδ hm₂ hz₂ (abs_lt.mp ht)⟩ |
| 145 | |
| 146 | end Poincare.Analysis |