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.Calculus.ContDiff.Deriv |
| 2 | import Mathlib.Analysis.Calculus.ContDiff.Operations |
| 3 | import Mathlib.Analysis.Calculus.Deriv.MeanValue |
| 4 | import Mathlib.Analysis.SpecialFunctions.SmoothTransition |
| 5 | import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus |
| 6 | import Mathlib.Order.Hom.Set |
| 7 | import Mathlib.Topology.Order.MonotoneContinuity |
| 8 | |
| 9 | /-! |
| 10 | # Smooth compression fixing a lower ray |
| 11 | |
| 12 | Integrating a positive smooth speed gives a global order isomorphism |
| 13 | which shortens an interval and fixes a neighborhood of its lower end. |
| 14 | This supplies the smooth model transport in Morgan--Tian Proposition |
| 15 | 9.79(3), p. 234; cap-persistence-implementation.md, section 2. |
| 16 | -/ |
| 17 | |
| 18 | set_option autoImplicit false |
| 19 | |
| 20 | open Set Filter |
| 21 | open scoped Topology ContDiff Interval |
| 22 | |
| 23 | namespace Real |
| 24 | |
| 25 | private theorem surjective_of_deriv_lower_bound {f : ℝ → ℝ} {C : ℝ} |
| 26 | (hf : Differentiable ℝ f) (hC : 0 < C) (hd : ∀ x, C ≤ deriv f x) : |
| 27 | Function.Surjective f := by |
| 28 | apply hf.continuous.surjective |
| 29 | · refine tendsto_atTop.2 fun b => ?_ |
| 30 | filter_upwards [eventually_ge_atTop (max 0 ((b - f 0) / C))] with x hx |
| 31 | have hx0 : 0 ≤ x := (le_max_left _ _).trans hx |
| 32 | have hb : b - f 0 ≤ x * C := (div_le_iff₀ hC).mp ((le_max_right _ _).trans hx) |
| 33 | have hg := mul_sub_le_image_sub_of_le_deriv hf hd hx0 |
| 34 | nlinarith |
| 35 | · refine tendsto_atBot.2 fun b => ?_ |
| 36 | filter_upwards [eventually_le_atBot (min 0 ((b - f 0) / C))] with x hx |
| 37 | have hx0 : x ≤ 0 := hx.trans (min_le_left _ _) |
| 38 | have hb : x * C ≤ b - f 0 := (le_div_iff₀ hC).mp (hx.trans (min_le_right _ _)) |
| 39 | have hg := mul_sub_le_image_sub_of_le_deriv hf hd hx0 |
| 40 | nlinarith |
| 41 | |
| 42 | /-- A smooth increasing compression with smooth inverse fixes an entire |
| 43 | lower ray. Its actual derivative is positive and at most one; no |
| 44 | analyticity at the join is asserted (Proposition 9.79(3), p. 234). -/ |
| 45 | theorem exists_smooth_orderIso_compression {c b A : ℝ} (hcb : c < b) (hbA : b < A) : |
| 46 | ∃ e : ℝ ≃o ℝ, ContDiff ℝ ∞ (e : ℝ → ℝ) ∧ |
| 47 | ContDiff ℝ ∞ (e.symm : ℝ → ℝ) ∧ e A = b ∧ |
| 48 | (∀ x ≤ c, e x = x) ∧ ∀ x, 0 < deriv (e : ℝ → ℝ) x ∧ |
| 49 | deriv (e : ℝ → ℝ) x ≤ 1 := by |
| 50 | let d := (c + b) / 2 |
| 51 | have hcd : c < d := by dsimp [d]; linarith |
| 52 | have hdb : d < b := by dsimp [d]; linarith |
| 53 | have hdA : d < A := hdb.trans hbA |
| 54 | have hcA : c < A := hcb.trans hbA |
| 55 | let χ : ℝ → ℝ := fun x => 1 - smoothTransition ((x - c) / (d - c)) |
| 56 | have hχ : ContDiff ℝ ∞ χ := |
| 57 | contDiff_const.sub ((smoothTransition.contDiff (n := (⊤ : ℕ∞))).comp |
| 58 | ((contDiff_id.sub contDiff_const).div_const (d - c))) |
| 59 | have hχ0 (x : ℝ) : 0 ≤ χ x := sub_nonneg.mpr (smoothTransition.le_one _) |
| 60 | have hχ1 (x : ℝ) : χ x ≤ 1 := sub_le_self _ (smoothTransition.nonneg _) |
| 61 | have hχleft {x : ℝ} (hx : x ≤ c) : χ x = 1 := by |
| 62 | dsimp [χ] |
| 63 | rw [smoothTransition.zero_of_nonpos |
| 64 | (div_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr hx) (sub_pos.mpr hcd).le)] |
| 65 | ring |
| 66 | have hχright {x : ℝ} (hx : d ≤ x) : χ x = 0 := by |
| 67 | dsimp [χ] |
| 68 | rw [smoothTransition.one_of_one_le ((le_div_iff₀ (sub_pos.mpr hcd)).mpr (by linarith))] |
| 69 | ring |
| 70 | let I : ℝ := ∫ x in c..A, χ x |
| 71 | have hI0 : 0 ≤ I := intervalIntegral.integral_nonneg_of_forall hcA.le hχ0 |
| 72 | have hId : I ≤ d - c := by |
| 73 | have hz : (∫ x in d..A, χ x) = 0 := by |
| 74 | calc |
| 75 | (∫ x in d..A, χ x) = ∫ _ in d..A, (0 : ℝ) := |
| 76 | intervalIntegral.integral_congr fun x hx => |
| 77 | hχright ((uIcc_of_le hdA.le ▸ hx).1) |
| 78 | _ = 0 := by simp |
| 79 | have hm := intervalIntegral.integral_mono_on (μ := MeasureTheory.volume) hcd.le |
| 80 | (hχ.continuous.intervalIntegrable c d) (continuous_const.intervalIntegrable c d) |
| 81 | (fun x _ => hχ1 x) |
| 82 | have hs := intervalIntegral.integral_add_adjacent_intervals (μ := MeasureTheory.volume) |
| 83 | (hχ.continuous.intervalIntegrable c d) (hχ.continuous.intervalIntegrable d A) |
| 84 | dsimp [I] |
| 85 | rw [← hs, hz, add_zero] |
| 86 | simpa using hm |
| 87 | have hIb : I < b - c := by linarith |
| 88 | have hden : 0 < A - c - I := by linarith |
| 89 | let l := (b - c - I) / (A - c - I) |
| 90 | have hl : 0 < l := div_pos (by linarith) hden |
| 91 | have hl1 : l < 1 := (div_lt_one hden).mpr (by linarith) |
| 92 | have hleq : l * (A - c - I) = b - c - I := div_mul_cancel₀ _ hden.ne' |
| 93 | let P : ℝ → ℝ := fun x => ∫ y in c..x, χ y |
| 94 | have hPderiv (x : ℝ) : HasDerivAt P (χ x) x := |
| 95 | intervalIntegral.integral_hasDerivAt_right (hχ.continuous.intervalIntegrable c x) |
| 96 | hχ.continuous.aestronglyMeasurable.stronglyMeasurableAtFilter hχ.continuous.continuousAt |
| 97 | have hP : ContDiff ℝ ∞ P := by |
| 98 | apply contDiff_infty_iff_deriv.mpr |
| 99 | refine ⟨fun x => (hPderiv x).differentiableAt, ?_⟩ |
| 100 | have heq : deriv P = χ := funext fun x => (hPderiv x).deriv |
| 101 | rw [heq] |
| 102 | exact hχ |
| 103 | let f : ℝ → ℝ := fun x => c + (l * (x - c) + (1 - l) * P x) |
| 104 | have hf : ContDiff ℝ ∞ f := |
| 105 | contDiff_const.add ((contDiff_const.mul (contDiff_id.sub contDiff_const)).add |
| 106 | (contDiff_const.mul hP)) |
| 107 | have hfderiv (x : ℝ) : HasDerivAt f (l + (1 - l) * χ x) x := by |
| 108 | convert! ((((hasDerivAt_id x).sub_const c).const_mul l).add |
| 109 | ((hPderiv x).const_mul (1 - l))).const_add c using 1 |
| 110 | simp only [mul_one] |
| 111 | have hd0 (x : ℝ) : l ≤ deriv f x := by |
| 112 | rw [(hfderiv x).deriv] |
| 113 | exact le_add_of_nonneg_right (mul_nonneg (sub_pos.mpr hl1).le (hχ0 x)) |
| 114 | have hd1 (x : ℝ) : deriv f x ≤ 1 := by |
| 115 | rw [(hfderiv x).deriv] |
| 116 | nlinarith [mul_le_mul_of_nonneg_left (hχ1 x) (sub_pos.mpr hl1).le] |
| 117 | have hm : StrictMono f := strictMono_of_deriv_pos fun x => hl.trans_le (hd0 x) |
| 118 | have hs : Function.Surjective f := surjective_of_deriv_lower_bound |
| 119 | (fun x => (hfderiv x).differentiableAt) hl hd0 |
| 120 | let e : ℝ ≃o ℝ := hm.orderIsoOfSurjective f hs |
| 121 | have he : (e : ℝ → ℝ) = f := rfl |
| 122 | refine ⟨e, he ▸ hf, ?_, ?_, ?_, ?_⟩ |
| 123 | · exact e.toHomeomorph.contDiff_symm_deriv (fun x => (hl.trans_le (hd0 x)).ne') |
| 124 | (fun x => (hfderiv x).congr_deriv (hfderiv x).deriv.symm) (he ▸ hf) |
| 125 | · change f A = b |
| 126 | change c + (l * (A - c) + (1 - l) * I) = b |
| 127 | nlinarith [hleq] |
| 128 | · intro x hx |
| 129 | have hPx : P x = x - c := by |
| 130 | calc |
| 131 | P x = ∫ _ in c..x, (1 : ℝ) := intervalIntegral.integral_congr fun y hy => |
| 132 | hχleft ((uIcc_of_ge hx ▸ hy).2) |
| 133 | _ = x - c := by simp |
| 134 | change f x = x |
| 135 | dsimp [f] |
| 136 | rw [hPx] |
| 137 | ring |
| 138 | · intro x |
| 139 | rw [he] |
| 140 | exact ⟨hl.trans_le (hd0 x), hd1 x⟩ |
| 141 | |
| 142 | end Real |