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.Topology.ContinuousOn |
| 2 | import Mathlib.Topology.Order.Compact |
| 3 | import Mathlib.Topology.Instances.Real.Lemmas |
| 4 | |
| 5 | /-! |
| 6 | # First exit from an open set |
| 7 | |
| 8 | The first exit of a continuous path on a compact real interval belongs |
| 9 | to the frontier, with the preceding path confined to the closure. |
| 10 | Used for the initial-chart length barrier in Morgan--Tian, |
| 11 | Claim 16.6 and Corollary 16.7, pp. 371-372. |
| 12 | -/ |
| 13 | |
| 14 | set_option autoImplicit false |
| 15 | |
| 16 | open Set |
| 17 | |
| 18 | /-- A path starting inside an open set and ending outside has a first |
| 19 | frontier time, with the entire preceding closed interval in the closure. -/ |
| 20 | theorem ContinuousOn.exists_first_frontier_time |
| 21 | {X : Type*} [TopologicalSpace X] {γ : ℝ → X} {a b : ℝ} |
| 22 | (hab : a ≤ b) (hγ : ContinuousOn γ (Icc a b)) |
| 23 | {U : Set X} (hU : IsOpen U) (ha : γ a ∈ U) (hb : γ b ∉ U) : |
| 24 | ∃ c ∈ Ioc a b, γ c ∈ frontier U ∧ |
| 25 | MapsTo γ (Ico a c) U ∧ MapsTo γ (Icc a c) (closure U) := by |
| 26 | let S : Set ℝ := Icc a b ∩ γ ⁻¹' Uᶜ |
| 27 | have hS : IsClosed S := |
| 28 | hγ.preimage_isClosed_of_isClosed isClosed_Icc hU.isClosed_compl |
| 29 | have hSne : S.Nonempty := ⟨b, ⟨⟨hab, le_rfl⟩, hb⟩⟩ |
| 30 | have hSb : BddBelow S := ⟨a, fun _ hs => hs.1.1⟩ |
| 31 | let c := sInf S |
| 32 | have hc : c ∈ S := hS.csInf_mem hSne hSb |
| 33 | have hac : a < c := lt_of_le_of_ne hc.1.1 (by |
| 34 | intro heq |
| 35 | exact hc.2 (heq ▸ ha)) |
| 36 | have hprior : MapsTo γ (Ico a c) U := by |
| 37 | intro s hs |
| 38 | by_contra hnot |
| 39 | have hsS : s ∈ S := ⟨⟨hs.1, hs.2.le.trans hc.1.2⟩, hnot⟩ |
| 40 | exact (not_le_of_gt hs.2) (csInf_le hSb hsS) |
| 41 | have hccl : c ∈ closure (Ico a c) := by |
| 42 | rw [closure_Ico hac.ne] |
| 43 | exact ⟨hac.le, le_rfl⟩ |
| 44 | have hcl : γ c ∈ closure U := |
| 45 | ((hγ c hc.1).mono (Ico_subset_Icc_self.trans |
| 46 | (Icc_subset_Icc le_rfl hc.1.2))).mem_closure hccl hprior |
| 47 | refine ⟨c, ⟨hac, hc.1.2⟩, ?_, hprior, ?_⟩ |
| 48 | · rw [frontier, hU.interior_eq] |
| 49 | exact ⟨hcl, hc.2⟩ |
| 50 | · intro s hs |
| 51 | rcases lt_or_eq_of_le hs.2 with hsc | rfl |
| 52 | · exact subset_closure (hprior ⟨hs.1, hsc⟩) |
| 53 | · exact hcl |
| 54 | |
| 55 | /-- An open condition persists when its validity on each preceding |
| 56 | half-open interval implies validity at the terminal time. Source: |
| 57 | the stopped collar in Morgan--Tian, Lemma 16.8; M44 derivation 43. -/ |
| 58 | theorem ContinuousOn.mapsTo_of_open_prefix |
| 59 | {X : Type*} [TopologicalSpace X] {f : ℝ → X} {a b : ℝ} |
| 60 | (hf : ContinuousOn f (Icc a b)) {U : Set X} (hU : IsOpen U) (ha : f a ∈ U) |
| 61 | (hstep : ∀ c ∈ Ioc a b, MapsTo f (Ico a c) U → f c ∈ U) : |
| 62 | MapsTo f (Icc a b) U := by |
| 63 | intro t ht |
| 64 | by_contra hnot |
| 65 | obtain ⟨c, hc, hfront, hprior, _hclosed⟩ := |
| 66 | (hf.mono (Icc_subset_Icc le_rfl ht.2)).exists_first_frontier_time ht.1 hU ha hnot |
| 67 | rw [frontier, hU.interior_eq] at hfront |
| 68 | exact hfront.2 (hstep c ⟨hc.1, hc.2.trans ht.2⟩ hprior) |