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.Congr |
| 2 | import Mathlib.Analysis.Calculus.Deriv.Basic |
| 3 | |
| 4 | /-! |
| 5 | # Differentiability of piecewise maps with matching first jets |
| 6 | |
| 7 | Matching values and derivatives suffice at the join; no agreement of |
| 8 | higher derivatives is required. This is used for the straight boundary |
| 9 | contact in MT Claim 19.40; see the minimal-contact derivation, Section 9. |
| 10 | -/ |
| 11 | |
| 12 | set_option autoImplicit false |
| 13 | |
| 14 | open Set |
| 15 | |
| 16 | namespace PoincareMT |
| 17 | |
| 18 | /-- Choosing between maps with the same value and derivative preserves that derivative, |
| 19 | independently of the geometry of the selection set. Source: MT Claim 19.40, pp. 470-471; |
| 20 | derivations/2026-09-27-minimal-contact-regularity.md, Section 9. -/ |
| 21 | theorem m64HasFDerivAt_piecewise_of_same_jet |
| 22 | {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] |
| 23 | [NormedAddCommGroup E] [NormedSpace 𝕜 E] |
| 24 | [NormedAddCommGroup F] [NormedSpace 𝕜 F] |
| 25 | {f g : E → F} {D : E →L[𝕜] F} {x : E} |
| 26 | (hf : HasFDerivAt f D x) (hg : HasFDerivAt g D x) (hval : f x = g x) |
| 27 | (S : Set E) [DecidablePred (fun y => y ∈ S)] : |
| 28 | HasFDerivAt (S.piecewise f g) D x := by |
| 29 | have hleft : HasFDerivWithinAt (S.piecewise f g) D S x := |
| 30 | hf.hasFDerivWithinAt.congr (fun y hy => piecewise_eq_of_mem S f g hy) |
| 31 | (by by_cases hx : x ∈ S <;> simp [hx, hval]) |
| 32 | have hright : HasFDerivWithinAt (S.piecewise f g) D Sᶜ x := |
| 33 | hg.hasFDerivWithinAt.congr (fun y hy => piecewise_eq_of_notMem S f g hy) |
| 34 | (by by_cases hx : x ∈ S <;> simp [hx, hval]) |
| 35 | have h := hleft.union hright |
| 36 | rwa [union_compl_self, hasFDerivWithinAt_univ] at h |
| 37 | |
| 38 | /-- The one-variable version retains the literal derivative vector of either branch when |
| 39 | their values and first derivatives agree. Source: MT Claim 19.40, pp. 470-471; |
| 40 | derivations/2026-09-27-minimal-contact-regularity.md, Section 9. -/ |
| 41 | theorem m64HasDerivAt_piecewise_of_same_jet |
| 42 | {𝕜 F : Type*} [NontriviallyNormedField 𝕜] |
| 43 | [NormedAddCommGroup F] [NormedSpace 𝕜 F] |
| 44 | {f g : 𝕜 → F} {v : F} {x : 𝕜} |
| 45 | (hf : HasDerivAt f v x) (hg : HasDerivAt g v x) (hval : f x = g x) |
| 46 | (S : Set 𝕜) [DecidablePred (fun y => y ∈ S)] : |
| 47 | HasDerivAt (S.piecewise f g) v x := |
| 48 | m64HasFDerivAt_piecewise_of_same_jet hf.hasFDerivAt hg.hasFDerivAt hval S |
| 49 | |
| 50 | end PoincareMT |