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.Convex.Deriv |
| 2 | import Mathlib.Analysis.Calculus.ContDiff.Deriv |
| 3 | import Mathlib.Analysis.Calculus.ContDiff.Operations |
| 4 | import Mathlib.Analysis.Calculus.Deriv.Pow |
| 5 | import Mathlib.Analysis.Calculus.LocalExtr.Basic |
| 6 | import Mathlib.Topology.Order.Compact |
| 7 | import Mathlib.Tactic.FunProp |
| 8 | import Mathlib.Tactic.Linarith |
| 9 | import Mathlib.Tactic.Ring |
| 10 | |
| 11 | /-! |
| 12 | # Scalar concavity and comparison assembly |
| 13 | |
| 14 | This module records the local second-derivative extremum lemma and the |
| 15 | two-parameter chord algebra used after one-variable concavity has been |
| 16 | established by the geometric comparison argument. |
| 17 | -/ |
| 18 | |
| 19 | set_option autoImplicit false |
| 20 | |
| 21 | open Set Filter |
| 22 | open scoped Topology |
| 23 | |
| 24 | namespace Poincare.Analysis |
| 25 | |
| 26 | /-- A twice differentiable function has nonnegative second derivative at an |
| 27 | interior local minimum. -/ |
| 28 | theorem nonneg_second_deriv_of_local_min {u : ℝ → ℝ} {x : ℝ} |
| 29 | (hu : ContDiffAt ℝ 2 u x) (hmin : IsLocalMin u x) : |
| 30 | 0 ≤ deriv (deriv u) x := by |
| 31 | by_contra hnonneg |
| 32 | have hneg : deriv (deriv u) x < 0 := lt_of_not_ge hnonneg |
| 33 | have hc : ContinuousAt (deriv (deriv u)) x := |
| 34 | ((hu.derivWithin (m := 1) (by norm_num)).derivWithin |
| 35 | (m := 0) (by norm_num)).continuousAt |
| 36 | have hev : ∀ᶠ y in 𝓝 x, |
| 37 | u x ≤ u y ∧ ContDiffAt ℝ 2 u y ∧ deriv (deriv u) y < 0 := by |
| 38 | filter_upwards [hmin, hu.eventually (by norm_num), |
| 39 | hc.eventually_lt continuousAt_const hneg] with y h₁ h₂ h₃ |
| 40 | exact ⟨h₁, h₂, h₃⟩ |
| 41 | obtain ⟨r, hr, hball⟩ := Metric.eventually_nhds_iff.mp hev |
| 42 | have hconc : StrictConcaveOn ℝ (Metric.ball x r) u := by |
| 43 | apply strictConcaveOn_of_deriv2_neg (convex_ball x r) |
| 44 | · exact fun y hy => (hball hy).2.1.continuousAt.continuousWithinAt |
| 45 | · intro y hy |
| 46 | have hball_eq : interior (Metric.ball x r) = Metric.ball x r := |
| 47 | Metric.isOpen_ball.interior_eq |
| 48 | exact (hball (Metric.mem_ball.mp (hball_eq ▸ hy))).2.2 |
| 49 | have hxy : x < x + r / 2 := by linarith |
| 50 | have hy : x + r / 2 ∈ Metric.ball x r := by |
| 51 | rw [Metric.mem_ball, Real.dist_eq] |
| 52 | rw [show x + r / 2 - x = r / 2 by ring, abs_of_pos (by positivity)] |
| 53 | linarith |
| 54 | have hslope := hconc.slope_lt_deriv (Metric.mem_ball_self hr) hy hxy |
| 55 | (hu.differentiableAt (by norm_num)) |
| 56 | rw [hmin.deriv_eq_zero, slope_def_field] at hslope |
| 57 | have hpos : 0 ≤ (u (x + r / 2) - u x) / (x + r / 2 - x) := |
| 58 | div_nonneg (sub_nonneg.mpr (hball hy).1) (sub_nonneg.mpr hxy.le) |
| 59 | exact (not_lt_of_ge hpos) hslope |
| 60 | |
| 61 | /-- A continuous function is concave if, at every interior point, it has |
| 62 | twice smooth local upper supports with arbitrarily small positive upper |
| 63 | bounds on their second derivatives. The function itself need not be |
| 64 | differentiable at the contact points. -/ |
| 65 | theorem concaveOn_of_approximate_upper_support {f : ℝ → ℝ} {a b : ℝ} |
| 66 | (hf : ContinuousOn f (Icc a b)) |
| 67 | (hsupport : ∀ x ∈ Ioo a b, ∀ ε : ℝ, 0 < ε → |
| 68 | ∃ u : ℝ → ℝ, ContDiffAt ℝ 2 u x ∧ u x = f x ∧ |
| 69 | (∀ᶠ y in 𝓝 x, f y ≤ u y) ∧ deriv (deriv u) x ≤ ε) : |
| 70 | ConcaveOn ℝ (Icc a b) f := by |
| 71 | apply concaveOn_of_slope_anti_adjacent (convex_Icc a b) |
| 72 | intro x y z hx hz hxy hyz |
| 73 | have hxz : x < z := hxy.trans hyz |
| 74 | let L : ℝ → ℝ := fun t => f x + (t - x) * ((f z - f x) / (z - x)) |
| 75 | have hLx : L x = f x := by simp [L] |
| 76 | have hLz : L z = f z := by |
| 77 | dsimp [L] |
| 78 | field_simp [sub_ne_zero.mpr hxz.ne'] |
| 79 | ring |
| 80 | have hchord : L y ≤ f y := by |
| 81 | by_contra hnot |
| 82 | have hgap : 0 < L y - f y := sub_pos.mpr (lt_of_not_ge hnot) |
| 83 | obtain ⟨ε, hε, hsmall⟩ := exists_pos_mul_lt hgap ((y - x) * (z - y)) |
| 84 | let P : ℝ → ℝ := fun t => -L t + ε * (t - x) * (z - t) |
| 85 | let F : ℝ → ℝ := fun t => f t + P t |
| 86 | have hPc : ContDiff ℝ 2 P := by dsimp [P, L]; fun_prop |
| 87 | have hFc : ContinuousOn F (Icc x z) := |
| 88 | (hf.mono (Icc_subset_Icc hx.1 hz.2)).add hPc.continuous.continuousOn |
| 89 | obtain ⟨t, ht, hmin⟩ := isCompact_Icc.exists_isMinOn |
| 90 | (nonempty_Icc.mpr hxz.le) hFc |
| 91 | have hFy : F y < 0 := by dsimp [F, P]; nlinarith [hsmall] |
| 92 | have hFt : F t < 0 := (hmin ⟨hxy.le, hyz.le⟩).trans_lt hFy |
| 93 | have hFx : F x = 0 := by simp [F, P, hLx] |
| 94 | have hFz : F z = 0 := by simp [F, P, hLz] |
| 95 | have hxt : x < t := lt_of_le_of_ne ht.1 (by |
| 96 | intro h; rw [← h, hFx] at hFt; exact lt_irrefl _ hFt) |
| 97 | have htz : t < z := lt_of_le_of_ne ht.2 (by |
| 98 | intro h; rw [h, hFz] at hFt; exact lt_irrefl _ hFt) |
| 99 | obtain ⟨u, hu, htouch, hupper, hsecond⟩ := |
| 100 | hsupport t ⟨hx.1.trans_lt hxt, htz.trans_le hz.2⟩ ε hε |
| 101 | have humin : IsLocalMin (fun s => u s + P s) t := by |
| 102 | filter_upwards [hmin.isLocalMin (Icc_mem_nhds hxt htz), hupper] with s hs hsu |
| 103 | change f t + P t ≤ f s + P s at hs |
| 104 | rw [htouch] |
| 105 | linarith |
| 106 | have hnonneg := nonneg_second_deriv_of_local_min (hu.add hPc.contDiffAt) humin |
| 107 | let P' : ℝ → ℝ := fun s => -((f z - f x) / (z - x)) + ε * (z + x - 2 * s) |
| 108 | have hPd (s : ℝ) : HasDerivAt P (P' s) s := by |
| 109 | dsimp [P, P', L] |
| 110 | convert (((hasDerivAt_const s (f x)).add |
| 111 | (((hasDerivAt_id s).sub_const x).mul_const ((f z - f x) / (z - x)))).neg).add |
| 112 | ((((hasDerivAt_id s).sub_const x).const_mul ε).mul |
| 113 | ((hasDerivAt_const s z).sub (hasDerivAt_id s))) using 1 <;> |
| 114 | first | rfl | (simp only [Pi.sub_apply, id_eq]; ring) |
| 115 | have hPdd : HasDerivAt P' (-2 * ε) t := by |
| 116 | dsimp [P'] |
| 117 | convert (hasDerivAt_const t (-((f z - f x) / (z - x)))).add |
| 118 | (((hasDerivAt_const t (z + x)).sub |
| 119 | ((hasDerivAt_id t).const_mul 2)).const_mul ε) using 1 <;> |
| 120 | first | rfl | ring |
| 121 | have hfirst : deriv (fun s => u s + P s) =ᶠ[𝓝 t] |
| 122 | (fun s => deriv u s + P' s) := by |
| 123 | filter_upwards [hu.eventually (by norm_num)] with s hs |
| 124 | rw [deriv_fun_add (hs.differentiableAt (by norm_num)) (hPd s).differentiableAt, |
| 125 | (hPd s).deriv] |
| 126 | have hud : DifferentiableAt ℝ (deriv u) t := |
| 127 | (hu.derivWithin (m := 1) (by norm_num)).differentiableAt (by norm_num) |
| 128 | rw [hfirst.deriv_eq, deriv_fun_add hud hPdd.differentiableAt, hPdd.deriv] at hnonneg |
| 129 | linarith |
| 130 | rw [div_le_div_iff₀ (sub_pos.mpr hyz) (sub_pos.mpr hxy)] |
| 131 | have hchord' : (f z - f x) * (y - x) ≤ (f y - f x) * (z - x) := by |
| 132 | have h : (y - x) * ((f z - f x) / (z - x)) ≤ f y - f x := by |
| 133 | dsimp [L] at hchord |
| 134 | linarith |
| 135 | have hh := (mul_le_mul_of_nonneg_right h (sub_nonneg.mpr hxz.le)) |
| 136 | field_simp at hh |
| 137 | nlinarith |
| 138 | nlinarith |
| 139 | |
| 140 | /-- Subtracting a quadratic removes its constant second derivative. -/ |
| 141 | theorem second_deriv_sub_quadratic {u : ℝ → ℝ} {x : ℝ} |
| 142 | (hu : ContDiffAt ℝ 2 u x) (C : ℝ) : |
| 143 | deriv (deriv (fun t => u t - C * t ^ 2)) x = deriv (deriv u) x - 2 * C := by |
| 144 | have hq (t : ℝ) : HasDerivAt (fun s : ℝ => C * s ^ 2) (2 * C * t) t := by |
| 145 | convert ((hasDerivAt_id t).pow 2).const_mul C using 1 <;> |
| 146 | first | rfl | (simp only [id_eq]; ring) |
| 147 | have hfirst : deriv (fun t => u t - C * t ^ 2) =ᶠ[𝓝 x] |
| 148 | (fun t => deriv u t - 2 * C * t) := by |
| 149 | filter_upwards [hu.eventually (by norm_num)] with t ht |
| 150 | rw [deriv_fun_sub (ht.differentiableAt (by norm_num)) (hq t).differentiableAt, |
| 151 | (hq t).deriv] |
| 152 | have hud : DifferentiableAt ℝ (deriv u) x := |
| 153 | (hu.derivWithin (m := 1) (by norm_num)).differentiableAt (by norm_num) |
| 154 | rw [hfirst.deriv_eq, deriv_fun_sub hud (by fun_prop)] |
| 155 | simp |
| 156 | |
| 157 | /-- An approximate upper bound on the second derivatives of touching |
| 158 | supports makes the corresponding quadratic defect concave. -/ |
| 159 | theorem concaveOn_sub_quadratic_of_approximate_upper_support |
| 160 | {f : ℝ → ℝ} {a b C : ℝ} (hf : ContinuousOn f (Icc a b)) |
| 161 | (hsupport : ∀ x ∈ Ioo a b, ∀ ε : ℝ, 0 < ε → |
| 162 | ∃ u : ℝ → ℝ, ContDiffAt ℝ 2 u x ∧ u x = f x ∧ |
| 163 | (∀ᶠ y in 𝓝 x, f y ≤ u y) ∧ deriv (deriv u) x ≤ 2 * C + ε) : |
| 164 | ConcaveOn ℝ (Icc a b) (fun t => f t - C * t ^ 2) := by |
| 165 | apply concaveOn_of_approximate_upper_support (hf.sub (by fun_prop)) |
| 166 | intro x hx ε hε |
| 167 | obtain ⟨u, hu, ht, hb, hd⟩ := hsupport x hx ε hε |
| 168 | refine ⟨fun t => u t - C * t ^ 2, hu.sub (by fun_prop), by simp only [Pi.sub_apply, ht], |
| 169 | ?_, ?_⟩ |
| 170 | · exact hb.mono fun y hy => sub_le_sub_right hy _ |
| 171 | · rw [second_deriv_sub_quadratic hu] |
| 172 | linarith |
| 173 | |
| 174 | /-- A touching differentiable upper support at the left endpoint bounds a |
| 175 | concave function by its tangent on the whole interval. This also applies |
| 176 | when the concave function is not differentiable at that endpoint. -/ |
| 177 | theorem le_affine_of_concaveOn_of_upper_support |
| 178 | {f u : ℝ → ℝ} {a b q : ℝ} (hab : a < b) |
| 179 | (hf : ConcaveOn ℝ (Icc a b) f) (htouch : u a = f a) |
| 180 | (hupper : ∀ᶠ y in 𝓝 a, f y ≤ u y) (hu : HasDerivAt u q a) : |
| 181 | f b ≤ f a + q * (b - a) := by |
| 182 | have hlimit := hu.tendsto_slope.mono_left (nhdsGT_le_nhdsNE a) |
| 183 | have hle : slope f a b ≤ q := by |
| 184 | apply ge_of_tendsto hlimit |
| 185 | filter_upwards [self_mem_nhdsWithin, |
| 186 | (eventually_lt_nhds hab).filter_mono nhdsWithin_le_nhds, |
| 187 | hupper.filter_mono nhdsWithin_le_nhds] with y hy hyb hyu |
| 188 | have hya : a < y := hy |
| 189 | have hsl := hf.slope_anti ⟨le_rfl, hab.le⟩ |
| 190 | (show y ∈ Icc a b \ {a} from ⟨⟨hya.le, hyb.le⟩, ne_of_gt hya⟩) |
| 191 | (show b ∈ Icc a b \ {a} from ⟨⟨hab.le, le_rfl⟩, ne_of_gt hab⟩) hyb.le |
| 192 | apply hsl.trans |
| 193 | simp only [slope_def_field, ← htouch] |
| 194 | exact div_le_div_of_nonneg_right (sub_le_sub_right hyu _) (sub_nonneg.mpr hya.le) |
| 195 | rw [slope_def_field, div_le_iff₀ (sub_pos.mpr hab)] at hle |
| 196 | linarith |
| 197 | |
| 198 | /-- The two one-variable concavity inequalities imply the corresponding |
| 199 | quadratic lower bound. This is the scalar assembly used after comparison of |
| 200 | the two sides of a hinge. -/ |
| 201 | theorem two_parameter_chord_lower_bound |
| 202 | {F : ℝ → ℝ → ℝ} {a b : ℝ} |
| 203 | (ha : 0 < a) (hb : 0 < b) |
| 204 | (haxis₁ : ∀ t ∈ Icc 0 b, |
| 205 | ConcaveOn ℝ (Icc 0 a) (fun s => F s t - s ^ 2)) |
| 206 | (haxis₂ : ∀ s ∈ Icc 0 a, |
| 207 | ConcaveOn ℝ (Icc 0 b) (fun t => F s t - t ^ 2)) |
| 208 | (hzero₁ : ∀ s ∈ Icc 0 a, F s 0 = s ^ 2) |
| 209 | (hzero₂ : ∀ t ∈ Icc 0 b, F 0 t = t ^ 2) : |
| 210 | ∀ s ∈ Icc 0 a, ∀ t ∈ Icc 0 b, |
| 211 | F s t ≥ s ^ 2 + t ^ 2 - |
| 212 | 2 * s * t * ((a ^ 2 + b ^ 2 - F a b) / (2 * a * b)) := by |
| 213 | intro s hs t ht |
| 214 | have hst : 0 ≤ s / a := div_nonneg hs.1 ha.le |
| 215 | have hsa_eq : s / a * a = s := by field_simp |
| 216 | have htb_eq : t / b * b = t := by field_simp |
| 217 | have htb : t / b ∈ Icc (0 : ℝ) 1 := by |
| 218 | constructor |
| 219 | · exact div_nonneg ht.1 hb.le |
| 220 | · simpa using (div_le_iff₀ hb).2 (by simpa using ht.2) |
| 221 | have hsa : s / a ∈ Icc (0 : ℝ) 1 := by |
| 222 | constructor |
| 223 | · exact div_nonneg hs.1 ha.le |
| 224 | · simpa using (div_le_iff₀ ha).2 (by simpa using hs.2) |
| 225 | have hconc_s := (haxis₁ t ht).2 |
| 226 | (show (0 : ℝ) ∈ Icc 0 a by exact ⟨le_rfl, ha.le⟩) |
| 227 | (show a ∈ Icc 0 a by exact ⟨ha.le, le_rfl⟩) |
| 228 | (show 0 ≤ 1 - s / a by linarith [hsa.2]) |
| 229 | (show 0 ≤ s / a by exact div_nonneg hs.1 ha.le) (by ring) |
| 230 | have hFa : F a t ≥ t ^ 2 + a ^ 2 + (t / b) * (F a b - a ^ 2 - b ^ 2) := by |
| 231 | have hconc_t := (haxis₂ a (show a ∈ Icc 0 a by exact ⟨ha.le, le_rfl⟩)).2 |
| 232 | (show (0 : ℝ) ∈ Icc 0 b by exact ⟨le_rfl, hb.le⟩) |
| 233 | (show b ∈ Icc 0 b by exact ⟨hb.le, le_rfl⟩) |
| 234 | (show 0 ≤ 1 - t / b by linarith [htb.2]) |
| 235 | (show 0 ≤ t / b by exact div_nonneg ht.1 hb.le) (by ring) |
| 236 | simp [smul_eq_mul, htb_eq, hzero₁ a ⟨ha.le, le_rfl⟩] at hconc_t |
| 237 | nlinarith [hconc_t] |
| 238 | simp [smul_eq_mul, hsa_eq, hzero₂ t ht] at hconc_s |
| 239 | have hsineq : s ^ 2 + t ^ 2 + (s / a) * (F a t - a ^ 2 - t ^ 2) ≤ F s t := by |
| 240 | nlinarith [hconc_s] |
| 241 | have hfa' : t ^ 2 + a ^ 2 + (t / b) * (F a b - a ^ 2 - b ^ 2) - a ^ 2 - t ^ 2 |
| 242 | ≤ F a t - a ^ 2 - t ^ 2 := by |
| 243 | nlinarith [hFa] |
| 244 | have hmul := mul_le_mul_of_nonneg_left hfa' hst |
| 245 | have hfinal : s ^ 2 + t ^ 2 + (s / a) * (t / b) * |
| 246 | (F a b - a ^ 2 - b ^ 2) ≤ F s t := by |
| 247 | nlinarith [hsineq, hmul] |
| 248 | have hid : s ^ 2 + t ^ 2 + (s / a) * (t / b) * |
| 249 | (F a b - a ^ 2 - b ^ 2) = |
| 250 | s ^ 2 + t ^ 2 - 2 * s * t * ((a ^ 2 + b ^ 2 - F a b) / (2 * a * b)) := by |
| 251 | field_simp [ha.ne', hb.ne'] |
| 252 | ring |
| 253 | rw [← hid] |
| 254 | exact hfinal |
| 255 | |
| 256 | end Poincare.Analysis |