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.Order.Compact |
| 2 | import Mathlib.Topology.Connected.Clopen |
| 3 | |
| 4 | /-! |
| 5 | # Actual first exit from an open set |
| 6 | |
| 7 | Compact parameter intervals provide a least exit time. Connected sets |
| 8 | cross the frontier of a closed set. Source: Morgan-Tian Proposition 9.79, |
| 9 | p. 234; cap-ball-confinement.md. |
| 10 | -/ |
| 11 | |
| 12 | set_option autoImplicit false |
| 13 | |
| 14 | open Set |
| 15 | |
| 16 | /-- A path first exits an open set at its actual frontier, while every |
| 17 | earlier parameter stays inside (cap confinement, Proposition 9.79). -/ |
| 18 | theorem ContinuousOn.exists_first_exit_open |
| 19 | {A X : Type*} [ConditionallyCompleteLinearOrder A] [DenselyOrdered A] |
| 20 | [TopologicalSpace A] [OrderTopology A] [TopologicalSpace X] |
| 21 | {γ : A → X} {a b : A} {U : Set X} |
| 22 | (hγ : ContinuousOn γ (Icc a b)) (hab : a ≤ b) (hU : IsOpen U) |
| 23 | (ha : γ a ∈ U) (hb : γ b ∉ U) : |
| 24 | ∃ t ∈ Ioc a b, γ t ∈ frontier U ∧ ∀ s ∈ Ico a t, γ s ∈ U := by |
| 25 | let S := Icc a b ∩ γ ⁻¹' Uᶜ |
| 26 | have hS : IsCompact S := isCompact_Icc.of_isClosed_subset |
| 27 | (hγ.preimage_isClosed_of_isClosed isClosed_Icc hU.isClosed_compl) inter_subset_left |
| 28 | have hSne : S.Nonempty := ⟨b, ⟨hab, le_rfl⟩, hb⟩ |
| 29 | obtain ⟨t, ht⟩ := hS.exists_isLeast hSne |
| 30 | have hat : a < t := by |
| 31 | have hne : a ≠ t := by |
| 32 | intro h |
| 33 | exact ht.1.2 (h ▸ ha) |
| 34 | exact lt_of_le_of_ne ht.1.1.1 hne |
| 35 | have hbefore : ∀ s ∈ Ico a t, γ s ∈ U := by |
| 36 | intro s hs |
| 37 | by_contra hnot |
| 38 | have hts := ht.2 ⟨⟨hs.1, hs.2.le.trans ht.1.1.2⟩, hnot⟩ |
| 39 | exact (not_lt_of_ge hts) hs.2 |
| 40 | have hcont : ContinuousWithinAt γ (Ico a t) t := |
| 41 | (hγ t ht.1.1).mono (fun s hs => ⟨hs.1, hs.2.le.trans ht.1.1.2⟩) |
| 42 | have htcl : t ∈ closure (Ico a t) := by |
| 43 | rw [closure_Ico hat.ne] |
| 44 | exact ⟨hat.le, le_rfl⟩ |
| 45 | have hcl : γ t ∈ closure U := |
| 46 | closure_mono (image_subset_iff.mpr hbefore) (hcont.mem_closure_image htcl) |
| 47 | exact ⟨t, ⟨hat, ht.1.1.2⟩, ⟨hcl, fun h => ht.1.2 (interior_subset h)⟩, hbefore⟩ |
| 48 | |
| 49 | /-- A connected set meeting a closed set and its complement meets the |
| 50 | actual frontier, without local connectedness assumptions |
| 51 | (cap confinement, Proposition 9.79). -/ |
| 52 | theorem IsPreconnected.exists_mem_frontier_of_mem_not_mem |
| 53 | {X : Type*} [TopologicalSpace X] {S Y : Set X} |
| 54 | (hS : IsPreconnected S) (hY : IsClosed Y) |
| 55 | {x y : X} (hxS : x ∈ S) (hxY : x ∈ Y) (hyS : y ∈ S) (hyY : y ∉ Y) : |
| 56 | ∃ z ∈ S, z ∈ frontier Y := by |
| 57 | by_contra hnot |
| 58 | have havoid : ∀ z ∈ S, z ∉ frontier Y := by simpa only [not_exists, not_and] using hnot |
| 59 | have hout : S ⊆ Yᶜ := hS.subset_of_closure_inter_subset hY.isOpen_compl |
| 60 | ⟨y, hyS, hyY⟩ (by |
| 61 | intro z hz |
| 62 | by_contra hzY |
| 63 | have hf : z ∈ frontier Yᶜ := |
| 64 | ⟨hz.1, by simpa only [hY.isOpen_compl.interior_eq] using hzY⟩ |
| 65 | rw [frontier_compl] at hf |
| 66 | exact havoid z hz.2 hf) |
| 67 | exact hout hxS hxY |