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.IntermediateValue |
| 2 | import Mathlib.Topology.Order.Compact |
| 3 | |
| 4 | /-! |
| 5 | # First passage of a continuous ordered path through a level |
| 6 | |
| 7 | The compact level fiber has a least point. The intermediate value theorem |
| 8 | excludes a larger value at any earlier point. This permits extended-real |
| 9 | distance levels in the reverse-ball argument of Morgan-Tian Theorem 12.29 |
| 10 | and Claim 12.30, pp. 324-325; reverse-ball-localization.md. |
| 11 | -/ |
| 12 | |
| 13 | set_option autoImplicit false |
| 14 | |
| 15 | open Set |
| 16 | |
| 17 | /-- A continuous ordered path attains each level between its endpoints |
| 18 | for the first time, allowing endpoint equality and a degenerate interval. |
| 19 | The target may be the extended nonnegative reals (Theorem 12.29). -/ |
| 20 | theorem ContinuousOn.exists_first_eq_of_le |
| 21 | {α β : Type*} [ConditionallyCompleteLinearOrder α] [DenselyOrdered α] |
| 22 | [TopologicalSpace α] [OrderTopology α] |
| 23 | [LinearOrder β] [TopologicalSpace β] [OrderClosedTopology β] |
| 24 | {f : α → β} {a b : α} (hf : ContinuousOn f (Icc a b)) |
| 25 | (hab : a ≤ b) {c : β} (ha : f a ≤ c) (hb : c ≤ f b) : |
| 26 | ∃ t ∈ Icc a b, f t = c ∧ ∀ s ∈ Ico a t, f s < c := by |
| 27 | have hne : (Icc a b ∩ f ⁻¹' {c}).Nonempty := by |
| 28 | obtain ⟨t, ht, hft⟩ := intermediate_value_Icc hab hf ⟨ha, hb⟩ |
| 29 | exact ⟨t, ht, hft⟩ |
| 30 | have hcompact : IsCompact (Icc a b ∩ f ⁻¹' {c}) := |
| 31 | isCompact_Icc.of_isClosed_subset |
| 32 | (hf.preimage_isClosed_of_isClosed isClosed_Icc isClosed_singleton) inter_subset_left |
| 33 | obtain ⟨t, ht⟩ := hcompact.exists_isLeast hne |
| 34 | refine ⟨t, ht.1.1, ht.1.2, ?_⟩ |
| 35 | intro s hs |
| 36 | by_contra hsc |
| 37 | obtain ⟨r, hr, hfr⟩ := intermediate_value_Icc hs.1 |
| 38 | (hf.mono (Icc_subset_Icc_right (hs.2.le.trans ht.1.1.2))) ⟨ha, le_of_not_gt hsc⟩ |
| 39 | have htr := ht.2 ⟨⟨hr.1, hr.2.trans (hs.2.le.trans ht.1.1.2)⟩, hfr⟩ |
| 40 | exact (not_lt_of_ge htr) (hr.2.trans_lt hs.2) |