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 PoincareLib.Geometry.RicciFlow.Surgery.StandardCap.Existence.Analysis.Basic.FirstExitLevel |
| 2 | |
| 3 | /-! |
| 4 | # Last crossing of a continuous ordered level |
| 5 | |
| 6 | The compact level fiber has a greatest element. This isolates an actual |
| 7 | path segment in the neck for the cap collar length barrier. |
| 8 | Source: Morgan-Tian Proposition 9.79, p. 234; cap-ball-confinement.md. |
| 9 | -/ |
| 10 | |
| 11 | set_option autoImplicit false |
| 12 | |
| 13 | open Set |
| 14 | |
| 15 | /-- Between the last crossing and a strictly larger endpoint every |
| 16 | value is strictly above the level (cap confinement, Proposition 9.79). -/ |
| 17 | theorem ContinuousOn.exists_last_eq_of_lt |
| 18 | {A B : Type*} [ConditionallyCompleteLinearOrder A] [DenselyOrdered A] |
| 19 | [TopologicalSpace A] [OrderTopology A] |
| 20 | [LinearOrder B] [TopologicalSpace B] [OrderClosedTopology B] |
| 21 | {f : A → B} {a b : A} (hf : ContinuousOn f (Icc a b)) |
| 22 | (hab : a ≤ b) {c : B} (ha : f a ≤ c) (hb : c < f b) : |
| 23 | ∃ t ∈ Ico a b, f t = c ∧ ∀ s ∈ Ioc t b, c < f s := by |
| 24 | have hne : (Icc a b ∩ f ⁻¹' {c}).Nonempty := by |
| 25 | obtain ⟨t, ht, hft⟩ := intermediate_value_Icc hab hf ⟨ha, hb.le⟩ |
| 26 | exact ⟨t, ht, hft⟩ |
| 27 | have hcompact : IsCompact (Icc a b ∩ f ⁻¹' {c}) := |
| 28 | isCompact_Icc.of_isClosed_subset |
| 29 | (hf.preimage_isClosed_of_isClosed isClosed_Icc isClosed_singleton) inter_subset_left |
| 30 | obtain ⟨t, ht⟩ := hcompact.exists_isGreatest hne |
| 31 | have htb : t < b := by |
| 32 | have hne : t ≠ b := by |
| 33 | intro h |
| 34 | have he : f b = c := h ▸ ht.1.2 |
| 35 | exact (ne_of_gt hb) he |
| 36 | exact lt_of_le_of_ne ht.1.1.2 hne |
| 37 | refine ⟨t, ⟨ht.1.1.1, htb⟩, ht.1.2, ?_⟩ |
| 38 | intro s hs |
| 39 | by_contra hsc |
| 40 | obtain ⟨r, hr, hfr⟩ := intermediate_value_Icc hs.2 |
| 41 | (hf.mono (Icc_subset_Icc_left (ht.1.1.1.trans hs.1.le))) |
| 42 | ⟨le_of_not_gt hsc, hb.le⟩ |
| 43 | have hrt := ht.2 ⟨⟨(ht.1.1.1.trans hs.1.le).trans hr.1, hr.2⟩, hfr⟩ |
| 44 | exact (not_lt_of_ge hrt) (hs.1.trans_le hr.1) |