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.SpecialFunctions.Sqrt |
| 2 | import Mathlib.Analysis.Calculus.Deriv.Mul |
| 3 | import Mathlib.Analysis.Calculus.Deriv.Pow |
| 4 | import Mathlib.Analysis.Calculus.Deriv.Inv |
| 5 | |
| 6 | /-! |
| 7 | # Derivatives of two normalized orthogonal coefficients |
| 8 | |
| 9 | The positive square root of A^2*f^2+B^2 normalizes a tangent with horizontal |
| 10 | coefficient f and constant vertical coefficient B. Both actual derivative |
| 11 | formulas allow A=0. This is the scalar differentiation in Claim 19.22, |
| 12 | MT2007 pp. 452-453; see `2026-09-21-parallel-frame-turning-density.md`. |
| 13 | -/ |
| 14 | |
| 15 | set_option autoImplicit false |
| 16 | |
| 17 | /-- Actual derivative of the normalized horizontal coefficient, for either |
| 18 | sign of A and nonzero B. Claim 19.22, MT2007 pp. 452-453. -/ |
| 19 | theorem HasDerivAt.div_sqrt_sq_mul_sq_add_sq {f : ℝ → ℝ} {f' x A B : ℝ} |
| 20 | (hf : HasDerivAt f f' x) (hB : B ≠ 0) : |
| 21 | HasDerivAt (fun s => f s / Real.sqrt (A ^ 2 * f s ^ 2 + B ^ 2)) |
| 22 | (B ^ 2 * f' / Real.sqrt (A ^ 2 * f x ^ 2 + B ^ 2) ^ 3) x := by |
| 23 | have hD : 0 < A ^ 2 * f x ^ 2 + B ^ 2 := |
| 24 | add_pos_of_nonneg_of_pos (mul_nonneg (sq_nonneg A) (sq_nonneg (f x))) |
| 25 | (sq_pos_of_ne_zero hB) |
| 26 | have hr := Real.sqrt_pos.mpr hD |
| 27 | have hs := Real.sq_sqrt hD.le |
| 28 | have hroot : HasDerivAt (fun s => Real.sqrt (A ^ 2 * f s ^ 2 + B ^ 2)) |
| 29 | (A ^ 2 * f x * f' / Real.sqrt (A ^ 2 * f x ^ 2 + B ^ 2)) x := by |
| 30 | convert HasDerivAt.sqrt (((hf.pow 2).const_mul (A ^ 2)).add_const (B ^ 2)) |
| 31 | hD.ne' using 1 |
| 32 | · ext s |
| 33 | simp only [Pi.pow_apply] |
| 34 | · simp only [Pi.pow_apply] |
| 35 | field_simp |
| 36 | ring |
| 37 | apply (hf.div hroot hr.ne').congr_deriv |
| 38 | field_simp |
| 39 | rw [hs] |
| 40 | ring |
| 41 | |
| 42 | /-- Actual derivative of the normalized constant vertical coefficient, for |
| 43 | either sign of A and nonzero B. Claim 19.22, MT2007 pp. 452-453. -/ |
| 44 | theorem HasDerivAt.const_div_sqrt_sq_mul_sq_add_sq {f : ℝ → ℝ} {f' x A B : ℝ} |
| 45 | (hf : HasDerivAt f f' x) (hB : B ≠ 0) : |
| 46 | HasDerivAt (fun s => B / Real.sqrt (A ^ 2 * f s ^ 2 + B ^ 2)) |
| 47 | (-(A ^ 2 * B * f x * f') / Real.sqrt (A ^ 2 * f x ^ 2 + B ^ 2) ^ 3) x := by |
| 48 | have hD : 0 < A ^ 2 * f x ^ 2 + B ^ 2 := |
| 49 | add_pos_of_nonneg_of_pos (mul_nonneg (sq_nonneg A) (sq_nonneg (f x))) |
| 50 | (sq_pos_of_ne_zero hB) |
| 51 | have hr := Real.sqrt_pos.mpr hD |
| 52 | have hroot : HasDerivAt (fun s => Real.sqrt (A ^ 2 * f s ^ 2 + B ^ 2)) |
| 53 | (A ^ 2 * f x * f' / Real.sqrt (A ^ 2 * f x ^ 2 + B ^ 2)) x := by |
| 54 | convert HasDerivAt.sqrt (((hf.pow 2).const_mul (A ^ 2)).add_const (B ^ 2)) |
| 55 | hD.ne' using 1 |
| 56 | · ext s |
| 57 | simp only [Pi.pow_apply] |
| 58 | · simp only [Pi.pow_apply] |
| 59 | field_simp |
| 60 | ring |
| 61 | apply ((hasDerivAt_const x B).div hroot hr.ne').congr_deriv |
| 62 | field_simp |
| 63 | ring |