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.ODE.ExistUnique |
| 2 | |
| 3 | /-! Adapted from Mapher `PoincareMT/Proofs/M08/LinearIntervalODE.lean` at |
| 4 | `f927d9e1f0810042766d3b5f64d3f4da02ee93cc`. -/ |
| 5 | |
| 6 | |
| 7 | set_option autoImplicit false |
| 8 | |
| 9 | noncomputable section |
| 10 | |
| 11 | open Set Filter Metric |
| 12 | open scoped Topology NNReal ContDiff |
| 13 | |
| 14 | universe uODE |
| 15 | |
| 16 | namespace PoincareMT.LGeometry |
| 17 | |
| 18 | variable {E : Type uODE} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 19 | |
| 20 | theorem linearODE_piecewise_Icc (L : ℝ → E →L[ℝ] E) {a c b : ℝ} |
| 21 | (hac : a ≤ c) (hcb : c ≤ b) {f g : ℝ → E} |
| 22 | (hf : ∀ s ∈ Icc a c, HasDerivWithinAt f (L s (f s)) (Icc a c) s) |
| 23 | (hg : ∀ s ∈ Icc c b, HasDerivWithinAt g (L s (g s)) (Icc c b) s) |
| 24 | (hfg : f c = g c) : |
| 25 | ∀ s ∈ Icc a b, HasDerivWithinAt ((Iic c).piecewise f g) |
| 26 | (L s ((Iic c).piecewise f g s)) (Icc a b) s := by |
| 27 | classical |
| 28 | let z := (Iic c).piecewise f g |
| 29 | have hleft (s : ℝ) (hs : s ≤ c) : z s = f s := |
| 30 | piecewise_eq_of_mem (Iic c) f g hs |
| 31 | have hright (s : ℝ) (hs : c ≤ s) : z s = g s := by |
| 32 | by_cases hsc : s ≤ c |
| 33 | · have hsc' : s = c := le_antisymm hsc hs |
| 34 | rw [hsc', hleft c le_rfl, hfg] |
| 35 | · exact piecewise_eq_of_notMem (Iic c) f g hsc |
| 36 | have hdleft (s : ℝ) (hs : s ∈ Icc a c) : |
| 37 | HasDerivWithinAt z (L s (z s)) (Icc a c) s := by |
| 38 | rw [hleft s hs.2] |
| 39 | exact (hf s hs).congr_of_mem (fun r hr ↦ hleft r hr.2) hs |
| 40 | have hdright (s : ℝ) (hs : s ∈ Icc c b) : |
| 41 | HasDerivWithinAt z (L s (z s)) (Icc c b) s := by |
| 42 | rw [hright s hs.1] |
| 43 | exact (hg s hs).congr_of_mem (fun r hr ↦ hright r hr.1) hs |
| 44 | intro s hs |
| 45 | change HasDerivWithinAt z (L s (z s)) (Icc a b) s |
| 46 | rcases lt_trichotomy s c with hsc | rfl | hcs |
| 47 | · apply (hdleft s ⟨hs.1, hsc.le⟩).mono_of_mem_nhdsWithin |
| 48 | filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds (Iio_mem_nhds hsc)] |
| 49 | with r hr hrc |
| 50 | exact ⟨hr.1, hrc.le⟩ |
| 51 | · simpa only [Icc_union_Icc_eq_Icc hac hcb] using |
| 52 | (hdleft s ⟨hac, le_rfl⟩).union (hdright s ⟨le_rfl, hcb⟩) |
| 53 | · apply (hdright s ⟨hcs.le, hs.2⟩).mono_of_mem_nhdsWithin |
| 54 | filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds (Ioi_mem_nhds hcs)] |
| 55 | with r hr hcr |
| 56 | exact ⟨hcr.le, hr.2⟩ |
| 57 | |
| 58 | theorem linear_interval_solution_unique (L : ℝ → E →L[ℝ] E) {a b t₀ : ℝ} |
| 59 | (hL : ContinuousOn L (Icc a b)) (ht₀ : t₀ ∈ Icc a b) {f g : ℝ → E} |
| 60 | (hf : ∀ s ∈ Icc a b, HasDerivWithinAt f (L s (f s)) (Icc a b) s) |
| 61 | (hg : ∀ s ∈ Icc a b, HasDerivWithinAt g (L s (g s)) (Icc a b) s) |
| 62 | (heq : f t₀ = g t₀) : EqOn f g (Icc a b) := by |
| 63 | obtain ⟨C, hC⟩ := isCompact_Icc.exists_bound_of_continuousOn hL |
| 64 | let K : ℝ≥0 := ⟨max C 0, le_max_right _ _⟩ |
| 65 | have hlip (s : ℝ) (hs : s ∈ Icc a b) : LipschitzOnWith K (L s) (univ : Set E) := |
| 66 | ((L s).lipschitzWith_of_opNorm_le ((hC s hs).trans (le_max_left _ _))).lipschitzOnWith |
| 67 | have hfc : ContinuousOn f (Icc a b) := HasDerivWithinAt.continuousOn hf |
| 68 | have hgc : ContinuousOn g (Icc a b) := HasDerivWithinAt.continuousOn hg |
| 69 | have hleft : EqOn f g (Icc a t₀) := by |
| 70 | apply ODE_solution_unique_of_mem_Icc_left (s := fun _ ↦ univ) (K := K) |
| 71 | (fun s hs ↦ hlip s ⟨hs.1.le, hs.2.trans ht₀.2⟩) |
| 72 | (hfc.mono (Icc_subset_Icc_right ht₀.2)) |
| 73 | (fun s hs ↦ (hf s ⟨hs.1.le, hs.2.trans ht₀.2⟩).mono_of_mem_nhdsWithin |
| 74 | (Icc_mem_nhdsLE_of_mem ⟨hs.1, hs.2.trans ht₀.2⟩)) |
| 75 | (fun _ _ ↦ mem_univ _) (hgc.mono (Icc_subset_Icc_right ht₀.2)) |
| 76 | (fun s hs ↦ (hg s ⟨hs.1.le, hs.2.trans ht₀.2⟩).mono_of_mem_nhdsWithin |
| 77 | (Icc_mem_nhdsLE_of_mem ⟨hs.1, hs.2.trans ht₀.2⟩)) |
| 78 | (fun _ _ ↦ mem_univ _) heq |
| 79 | have hright : EqOn f g (Icc t₀ b) := by |
| 80 | apply ODE_solution_unique_of_mem_Icc_right (s := fun _ ↦ univ) (K := K) |
| 81 | (fun s hs ↦ hlip s ⟨ht₀.1.trans hs.1, hs.2.le⟩) |
| 82 | (hfc.mono (Icc_subset_Icc_left ht₀.1)) |
| 83 | (fun s hs ↦ (hf s ⟨ht₀.1.trans hs.1, hs.2.le⟩).mono_of_mem_nhdsWithin |
| 84 | (Icc_mem_nhdsGE_of_mem ⟨ht₀.1.trans hs.1, hs.2⟩)) |
| 85 | (fun _ _ ↦ mem_univ _) (hgc.mono (Icc_subset_Icc_left ht₀.1)) |
| 86 | (fun s hs ↦ (hg s ⟨ht₀.1.trans hs.1, hs.2.le⟩).mono_of_mem_nhdsWithin |
| 87 | (Icc_mem_nhdsGE_of_mem ⟨ht₀.1.trans hs.1, hs.2⟩)) |
| 88 | (fun _ _ ↦ mem_univ _) heq |
| 89 | intro s hs |
| 90 | rcases le_total s t₀ with h | h |
| 91 | · exact hleft ⟨hs.1, h⟩ |
| 92 | · exact hright ⟨h, hs.2⟩ |
| 93 | |
| 94 | variable [CompleteSpace E] |
| 95 | |
| 96 | theorem exists_linear_interval_solution_short (L : ℝ → E →L[ℝ] E) |
| 97 | {a b t₀ K δ : ℝ} (hK : 0 ≤ K) (hδ : 0 ≤ δ) (hstep : 2 * K * δ ≤ 1) |
| 98 | (hL : ContinuousOn L (Icc a b)) (ht₀ : t₀ ∈ Icc a b) |
| 99 | (hbound : ∀ s ∈ Icc a b, ‖L s‖ ≤ K) |
| 100 | (hlen : max (b - t₀) (t₀ - a) ≤ δ) (z₀ : E) : |
| 101 | ∃ z : ℝ → E, z t₀ = z₀ ∧ |
| 102 | ∀ s ∈ Icc a b, HasDerivWithinAt z (L s (z s)) (Icc a b) s := by |
| 103 | let A := ‖z₀‖ + 1 |
| 104 | have hA : 0 ≤ A := by dsimp only [A]; positivity |
| 105 | let Ar : ℝ≥0 := ⟨A, hA⟩ |
| 106 | let B : ℝ≥0 := ⟨2 * K * A, by positivity⟩ |
| 107 | let Kr : ℝ≥0 := ⟨K, hK⟩ |
| 108 | have hpl : IsPicardLindelof (fun s z ↦ L s z) ⟨t₀, ht₀⟩ z₀ Ar 0 B Kr := by |
| 109 | refine ⟨?_, ?_, ?_, ?_⟩ |
| 110 | · intro s hs |
| 111 | exact ((L s).lipschitzWith_of_opNorm_le (K := Kr) (hbound s hs)).lipschitzOnWith |
| 112 | · intro z _ |
| 113 | exact hL.clm_apply continuousOn_const |
| 114 | · intro s hs z hz |
| 115 | have hdist : ‖z - z₀‖ ≤ A := by |
| 116 | change dist z z₀ ≤ A at hz |
| 117 | rwa [dist_eq_norm] at hz |
| 118 | have hzbound : ‖z‖ ≤ 2 * A := by |
| 119 | have := norm_le_norm_sub_add z z₀ |
| 120 | dsimp only [A] at * |
| 121 | linarith |
| 122 | change ‖L s z‖ ≤ 2 * K * A |
| 123 | calc |
| 124 | ‖L s z‖ ≤ ‖L s‖ * ‖z‖ := (L s).le_opNorm z |
| 125 | _ ≤ K * (2 * A) := mul_le_mul (hbound s hs) hzbound (norm_nonneg _) hK |
| 126 | _ = 2 * K * A := by ring |
| 127 | · change (2 * K * A) * max (b - t₀) (t₀ - a) ≤ A - 0 |
| 128 | rw [sub_zero] |
| 129 | calc |
| 130 | (2 * K * A) * max (b - t₀) (t₀ - a) ≤ (2 * K * A) * δ := |
| 131 | mul_le_mul_of_nonneg_left hlen (by positivity) |
| 132 | _ = A * (2 * K * δ) := by ring |
| 133 | _ ≤ A * 1 := mul_le_mul_of_nonneg_left hstep hA |
| 134 | _ = A := mul_one A |
| 135 | exact hpl.exists_eq_forall_mem_Icc_hasDerivWithinAt₀ |
| 136 | |
| 137 | theorem exists_linear_interval_solution_left_bounded (L : ℝ → E →L[ℝ] E) |
| 138 | (K δ : ℝ) (hK : 0 ≤ K) (hδ : 0 < δ) (hstep : 2 * K * δ ≤ 1) : |
| 139 | ∀ (N : ℕ) {a b : ℝ}, a ≤ b → b - a ≤ (N : ℝ) * δ → |
| 140 | ContinuousOn L (Icc a b) → (∀ s ∈ Icc a b, ‖L s‖ ≤ K) → |
| 141 | ∀ z₀ : E, ∃ z : ℝ → E, z a = z₀ ∧ |
| 142 | ∀ s ∈ Icc a b, HasDerivWithinAt z (L s (z s)) (Icc a b) s := by |
| 143 | intro N |
| 144 | induction N with |
| 145 | | zero => |
| 146 | intro a b hab hlen hL hbound z₀ |
| 147 | apply exists_linear_interval_solution_short L hK hδ.le hstep hL |
| 148 | ⟨le_rfl, hab⟩ hbound ?_ z₀ |
| 149 | rw [sub_self, max_eq_left (sub_nonneg.mpr hab)] |
| 150 | simp only [Nat.cast_zero, zero_mul] at hlen |
| 151 | exact hlen.trans hδ.le |
| 152 | | succ N ih => |
| 153 | intro a b hab hlen hL hbound z₀ |
| 154 | let c := min b (a + δ) |
| 155 | have hac : a ≤ c := le_min hab (le_add_of_nonneg_right hδ.le) |
| 156 | have hcb : c ≤ b := min_le_left _ _ |
| 157 | have hclen : c - a ≤ δ := by |
| 158 | have h := min_le_right b (a + δ) |
| 159 | change c ≤ a + δ at h |
| 160 | linarith |
| 161 | have hsubleft : Icc a c ⊆ Icc a b := Icc_subset_Icc_right hcb |
| 162 | obtain ⟨f, hfa, hfd⟩ := exists_linear_interval_solution_short L hK hδ.le hstep |
| 163 | (hL.mono hsubleft) ⟨le_rfl, hac⟩ (fun s hs ↦ hbound s (hsubleft hs)) |
| 164 | (by simpa only [sub_self, max_eq_left (sub_nonneg.mpr hac)] using hclen) z₀ |
| 165 | have hremain : b - c ≤ (N : ℝ) * δ := by |
| 166 | by_cases hb : b ≤ a + δ |
| 167 | · rw [show c = b from min_eq_left hb, sub_self] |
| 168 | exact mul_nonneg (Nat.cast_nonneg _) hδ.le |
| 169 | · rw [show c = a + δ from min_eq_right (le_of_not_ge hb)] |
| 170 | simp only [Nat.cast_succ, add_mul, one_mul] at hlen |
| 171 | linarith |
| 172 | have hsubright : Icc c b ⊆ Icc a b := Icc_subset_Icc_left hac |
| 173 | obtain ⟨g, hgc, hgd⟩ := ih hcb hremain (hL.mono hsubright) |
| 174 | (fun s hs ↦ hbound s (hsubright hs)) (f c) |
| 175 | refine ⟨(Iic c).piecewise f g, ?_, linearODE_piecewise_Icc L hac hcb hfd hgd hgc.symm⟩ |
| 176 | rw [piecewise_eq_of_mem (Iic c) f g hac] |
| 177 | exact hfa |
| 178 | |
| 179 | theorem exists_linear_interval_solution_left (L : ℝ → E →L[ℝ] E) |
| 180 | {a b : ℝ} (hab : a ≤ b) (hL : ContinuousOn L (Icc a b)) (z₀ : E) : |
| 181 | ∃ z : ℝ → E, z a = z₀ ∧ |
| 182 | ∀ s ∈ Icc a b, HasDerivWithinAt z (L s (z s)) (Icc a b) s := by |
| 183 | obtain ⟨C, hC⟩ := isCompact_Icc.exists_bound_of_continuousOn hL |
| 184 | let K := max C 0 |
| 185 | have hK : 0 ≤ K := le_max_right _ _ |
| 186 | let δ := 1 / (2 * (K + 1)) |
| 187 | have hden : 0 < 2 * (K + 1) := by positivity |
| 188 | have hδ : 0 < δ := one_div_pos.mpr hden |
| 189 | have hstep : 2 * K * δ ≤ 1 := by |
| 190 | dsimp only [δ] |
| 191 | rw [mul_one_div] |
| 192 | apply (div_le_iff₀ hden).mpr |
| 193 | linarith |
| 194 | obtain ⟨N, hN⟩ := exists_nat_ge ((b - a) / δ) |
| 195 | exact exists_linear_interval_solution_left_bounded L K δ hK hδ hstep N hab |
| 196 | ((div_le_iff₀ hδ).mp hN) hL (fun s hs ↦ (hC s hs).trans (le_max_left _ _)) z₀ |
| 197 | |
| 198 | theorem exists_linear_interval_solution (L : ℝ → E →L[ℝ] E) |
| 199 | {a b t₀ : ℝ} (hL : ContinuousOn L (Icc a b)) (ht₀ : t₀ ∈ Icc a b) (z₀ : E) : |
| 200 | ∃ z : ℝ → E, z t₀ = z₀ ∧ |
| 201 | ∀ s ∈ Icc a b, HasDerivWithinAt z (L s (z s)) (Icc a b) s := by |
| 202 | obtain ⟨f, hf₀, hfd⟩ := exists_linear_interval_solution_left L ht₀.2 |
| 203 | (hL.mono (Icc_subset_Icc_left ht₀.1)) z₀ |
| 204 | let Lrev : ℝ → E →L[ℝ] E := fun s ↦ -L (-s) |
| 205 | have hrevmap : MapsTo Neg.neg (Icc (-t₀) (-a)) (Icc a t₀) := by |
| 206 | intro s hs |
| 207 | constructor <;> linarith [hs.1, hs.2] |
| 208 | have hLrev : ContinuousOn Lrev (Icc (-t₀) (-a)) := |
| 209 | ((hL.mono (Icc_subset_Icc_right ht₀.2)).comp continuous_neg.continuousOn hrevmap).neg |
| 210 | obtain ⟨q, hq₀, hqd⟩ := exists_linear_interval_solution_left Lrev |
| 211 | (neg_le_neg ht₀.1) hLrev z₀ |
| 212 | let g := q ∘ Neg.neg |
| 213 | have hg₀ : g t₀ = z₀ := hq₀ |
| 214 | have hback : MapsTo Neg.neg (Icc a t₀) (Icc (-t₀) (-a)) := by |
| 215 | intro s hs |
| 216 | constructor <;> linarith [hs.1, hs.2] |
| 217 | have hgd (s : ℝ) (hs : s ∈ Icc a t₀) : |
| 218 | HasDerivWithinAt g (L s (g s)) (Icc a t₀) s := by |
| 219 | have h := (hqd (-s) (hback hs)).scomp s (hasDerivAt_neg s).hasDerivWithinAt hback |
| 220 | simpa [g, Lrev] using h |
| 221 | refine ⟨(Iic t₀).piecewise g f, ?_, |
| 222 | linearODE_piecewise_Icc L ht₀.1 ht₀.2 hgd hfd (hg₀.trans hf₀.symm)⟩ |
| 223 | rw [piecewise_eq_of_mem (Iic t₀) g f (show t₀ ∈ Iic t₀ from le_refl t₀)] |
| 224 | exact hg₀ |
| 225 | |
| 226 | theorem linear_interval_solution_contDiffOn (L : ℝ → E →L[ℝ] E) {a b : ℝ} |
| 227 | (hL : ContDiffOn ℝ ∞ L (Icc a b)) {z : ℝ → E} |
| 228 | (hz : ∀ s ∈ Icc a b, HasDerivWithinAt z (L s (z s)) (Icc a b) s) : |
| 229 | ContDiffOn ℝ ∞ z (Icc a b) := by |
| 230 | have hfield : ContDiffOn ℝ ∞ (fun p : ℝ × E ↦ L p.1 p.2) (Icc a b ×ˢ univ) := |
| 231 | (hL.comp contDiffOn_fst (fun p hp ↦ hp.1)).clm_apply contDiffOn_snd |
| 232 | exact ODE.contDiffOn_enat_Icc_of_hasDerivWithinAt (n := ⊤) |
| 233 | (f := fun s z ↦ L s z) (u := univ) hfield hz |
| 234 | (fun _ _ ↦ mem_univ _) |
| 235 | |
| 236 | end PoincareMT.LGeometry |