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.FDeriv.Analytic |
| 2 | import Mathlib.Analysis.Calculus.Deriv.Comp |
| 3 | import Mathlib.Analysis.Matrix.Normed |
| 4 | import Mathlib.Analysis.SpecialFunctions.Sqrt |
| 5 | import Mathlib.LinearAlgebra.Matrix.NonsingularInverse |
| 6 | import Mathlib.LinearAlgebra.Matrix.Trace |
| 7 | import Mathlib.Topology.Instances.Matrix |
| 8 | |
| 9 | /-! |
| 10 | # Jacobi's determinant differentiation formula |
| 11 | |
| 12 | These identities supply the volume-density derivative in the coordinate Green |
| 13 | formula for the retained Riemannian Laplacian. The statements follow the pinned |
| 14 | Chow--Liao--Qin source, `Analysis/Integration/Measure/JacobiFormula.lean`, |
| 15 | commit `1b535dd102b94cc42b107cca27059687888f08b3`. The proof uses Mathlib's |
| 16 | continuous multilinear derivative and Cramer's rule in place of a permutation |
| 17 | expansion. |
| 18 | -/ |
| 19 | |
| 20 | noncomputable section |
| 21 | |
| 22 | namespace Poincare.Matrix |
| 23 | |
| 24 | open scoped BigOperators Matrix.Norms.Elementwise |
| 25 | |
| 26 | variable {n : Type*} [Fintype n] [DecidableEq n] |
| 27 | |
| 28 | private def detMultilinear : ContinuousMultilinearMap ℝ (fun _ : n => n → ℝ) ℝ where |
| 29 | toMultilinearMap := Matrix.detRowAlternating.toMultilinearMap |
| 30 | cont := continuous_id.matrix_det |
| 31 | |
| 32 | private theorem detMultilinear_linearDeriv (A B : Matrix n n ℝ) : |
| 33 | (detMultilinear.linearDeriv A) B = Matrix.trace (Matrix.adjugate A * B) := by |
| 34 | change (detMultilinear.linearDeriv (fun i j => A i j)) (fun i j => B i j) = _ |
| 35 | rw [ContinuousMultilinearMap.linearDeriv_apply] |
| 36 | change (∑ i, (A.updateRow i (B i)).det) = _ |
| 37 | trans ∑ i, ∑ j, A.adjugate j i * B i j |
| 38 | · apply Finset.sum_congr rfl |
| 39 | intro i _ |
| 40 | rw [← Matrix.cramer_transpose_apply, Matrix.cramer_eq_adjugate_mulVec, |
| 41 | ← Matrix.adjugate_transpose] |
| 42 | rfl |
| 43 | · rw [Finset.sum_comm] |
| 44 | rfl |
| 45 | |
| 46 | /-- Jacobi's formula in adjugate form, with no nonsingularity assumption. -/ |
| 47 | theorem fderiv_det_eq_trace_adjugate_mul (A B : Matrix n n ℝ) : |
| 48 | fderiv ℝ Matrix.det A B = Matrix.trace (Matrix.adjugate A * B) := by |
| 49 | change fderiv ℝ (fun a : n → n → ℝ => (Matrix.of a).det) |
| 50 | (fun i j => A i j) (fun i j => B i j) = _ |
| 51 | have h := detMultilinear.hasFDerivAt (fun i j => A i j) |
| 52 | change HasFDerivAt (fun a : n → n → ℝ => (Matrix.of a).det) |
| 53 | (detMultilinear.linearDeriv (fun i j => A i j)) (fun i j => A i j) at h |
| 54 | rw [h.fderiv] |
| 55 | exact detMultilinear_linearDeriv A B |
| 56 | |
| 57 | /-- Jacobi's formula at an invertible real matrix. -/ |
| 58 | theorem fderiv_det_eq_det_mul_trace_inv_mul (A B : Matrix n n ℝ) |
| 59 | (hA : IsUnit A.det) : |
| 60 | fderiv ℝ Matrix.det A B = A.det * Matrix.trace (A⁻¹ * B) := by |
| 61 | rw [fderiv_det_eq_trace_adjugate_mul] |
| 62 | have hadj : Matrix.adjugate A = A.det • A⁻¹ := by |
| 63 | rw [Matrix.inv_def, smul_smul, Ring.mul_inverse_cancel _ hA, one_smul] |
| 64 | rw [hadj, Matrix.smul_mul, Matrix.trace_smul, smul_eq_mul] |
| 65 | |
| 66 | variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] |
| 67 | |
| 68 | /-- The determinant of an entrywise differentiable matrix field is differentiable. -/ |
| 69 | theorem differentiableAt_det {G : E → Matrix n n ℝ} {x : E} |
| 70 | (hG : ∀ i j, DifferentiableAt ℝ (fun y => G y i j) x) : |
| 71 | DifferentiableAt ℝ (fun y => (G y).det) x := by |
| 72 | exact (detMultilinear.hasFDerivAt (fun i j => G x i j)).differentiableAt.comp x |
| 73 | (differentiableAt_pi.mpr fun i => differentiableAt_pi.mpr (hG i)) |
| 74 | |
| 75 | /-- Jacobi's formula for an entrywise differentiable matrix field. -/ |
| 76 | theorem fderiv_det {G : E → Matrix n n ℝ} {x : E} |
| 77 | (hG : ∀ i j, DifferentiableAt ℝ (fun y => G y i j) x) |
| 78 | (hunit : IsUnit (G x).det) (v : E) : |
| 79 | fderiv ℝ (fun y => (G y).det) x v = |
| 80 | (G x).det * Matrix.trace ((G x)⁻¹ * |
| 81 | Matrix.of (fun i j => fderiv ℝ (fun y => G y i j) x v)) := by |
| 82 | have h := (detMultilinear.hasFDerivAt (fun i j => G x i j)).comp x |
| 83 | (hasFDerivAt_pi.mpr fun i => hasFDerivAt_pi.mpr fun j => (hG i j).hasFDerivAt) |
| 84 | change HasFDerivAt (fun y => (G y).det) |
| 85 | ((detMultilinear.linearDeriv (fun i j => G x i j)).comp |
| 86 | (ContinuousLinearMap.pi fun i => ContinuousLinearMap.pi fun j => |
| 87 | fderiv ℝ (fun y => G y i j) x)) x at h |
| 88 | rw [h.fderiv] |
| 89 | change (detMultilinear.linearDeriv (fun i j => G x i j)) |
| 90 | (fun i j => fderiv ℝ (fun y => G y i j) x v) = _ |
| 91 | exact (detMultilinear_linearDeriv (G x) |
| 92 | (Matrix.of (fun i j => fderiv ℝ (fun y => G y i j) x v))).trans |
| 93 | ((fderiv_det_eq_trace_adjugate_mul _ _).symm.trans |
| 94 | (fderiv_det_eq_det_mul_trace_inv_mul _ _ hunit)) |
| 95 | |
| 96 | private theorem sqrt_det_factor {d : ℝ} (hd : 0 < d) (a : ℝ) : |
| 97 | (1 / (2 * Real.sqrt d)) * (d * a) = |
| 98 | (1 / 2) * a * Real.sqrt d := by |
| 99 | have hs : Real.sqrt d ≠ 0 := Real.sqrt_ne_zero'.mpr hd |
| 100 | have hdiv : d / Real.sqrt d = Real.sqrt d := by |
| 101 | rw [eq_comm, eq_div_iff hs] |
| 102 | exact Real.mul_self_sqrt hd.le |
| 103 | calc |
| 104 | (1 / (2 * Real.sqrt d)) * (d * a) = (d / Real.sqrt d) * ((1 / 2) * a) := by ring |
| 105 | _ = (1 / 2) * a * Real.sqrt d := by rw [hdiv]; ring |
| 106 | |
| 107 | /-- The derivative of a positive square-root determinant, in density form. -/ |
| 108 | theorem fderiv_sqrt_det {G : E → Matrix n n ℝ} {x : E} |
| 109 | (hG : ∀ i j, DifferentiableAt ℝ (fun y => G y i j) x) |
| 110 | (hpos : 0 < (G x).det) (v : E) : |
| 111 | fderiv ℝ (fun y => Real.sqrt (G y).det) x v = |
| 112 | (1 / 2) * Matrix.trace ((G x)⁻¹ * |
| 113 | Matrix.of (fun i j => fderiv ℝ (fun y => G y i j) x v)) * |
| 114 | Real.sqrt (G x).det := by |
| 115 | rw [_root_.fderiv_sqrt (differentiableAt_det hG) (ne_of_gt hpos), |
| 116 | smul_apply, smul_eq_mul, fderiv_det hG (ne_of_gt hpos).isUnit] |
| 117 | exact sqrt_det_factor hpos _ |
| 118 | |
| 119 | /-- Entrywise Jacobi formula for a matrix curve. -/ |
| 120 | theorem hasDerivAt_det_eq_det_mul_trace_inv_mul |
| 121 | (G : ℝ → Matrix n n ℝ) (G' : Matrix n n ℝ) (t : ℝ) |
| 122 | (hG : ∀ i j, HasDerivAt (fun s => G s i j) (G' i j) t) |
| 123 | (hunit : IsUnit (G t).det) : |
| 124 | HasDerivAt (fun s => (G s).det) |
| 125 | ((G t).det * Matrix.trace ((G t)⁻¹ * G')) t := by |
| 126 | have hdiff : ∀ i j, DifferentiableAt ℝ (fun s => G s i j) t := |
| 127 | fun i j => (hG i j).differentiableAt |
| 128 | have h := (differentiableAt_det hdiff).hasDerivAt |
| 129 | rw [deriv, fderiv_det hdiff hunit] at h |
| 130 | have hentries : Matrix.of (fun i j => fderiv ℝ (fun s => G s i j) t 1) = G' := by |
| 131 | ext i j |
| 132 | exact (hG i j).deriv |
| 133 | rwa [hentries] at h |
| 134 | |
| 135 | /-- The square-root determinant derivative of a positive-determinant matrix curve. -/ |
| 136 | theorem hasDerivAt_sqrt_det_eq_half_trace_inv_mul |
| 137 | (G : ℝ → Matrix n n ℝ) (G' : Matrix n n ℝ) (t : ℝ) |
| 138 | (hG : ∀ i j, HasDerivAt (fun s => G s i j) (G' i j) t) |
| 139 | (hpos : 0 < (G t).det) : |
| 140 | HasDerivAt (fun s => Real.sqrt (G s).det) |
| 141 | ((1 / 2) * Matrix.trace ((G t)⁻¹ * G') * Real.sqrt (G t).det) t := by |
| 142 | have hdet := hasDerivAt_det_eq_det_mul_trace_inv_mul G G' t hG (ne_of_gt hpos).isUnit |
| 143 | have h := (Real.hasDerivAt_sqrt (ne_of_gt hpos)).comp t hdet |
| 144 | rw [sqrt_det_factor hpos] at h |
| 145 | simpa only [Function.comp_def] using! h |
| 146 | |
| 147 | end Poincare.Matrix |