Lean 4 Mathlib: Dimension-Polymorphic Affine Torsors¶
Repository:
_refs/mathlib4(https://github.com/leanprover-community/mathlib4, Apache-2.0, Mathlib2020)Scale Audited: 46 files (16,844 LOC) in
Mathlib/Geometry/Euclidean/+ 24 files (11,708 LOC) inMathlib/LinearAlgebra/AffineSpace/Mathematical Foundation: Dependent type-theoretic affine torsor
NormedAddTorsor V Pover a realInnerProductSpace ℝ V
1. Why Points and Vectors Are Separate Types¶
In Cartesian software (sympy.geometry), a point \((x, y)\) and a displacement vector \(\langle dx, dy \rangle\) share coordinates relative to a privileged origin \((0, 0)\). mathlib4 enforces coordinate-free discipline through the typeclass stack:
variable {V : Type*} {P : Type*}
[NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P]
Here p₁ + p₂ is a compile-time type error! You may only subtract two points to obtain a vector (p₁ -ᵥ p₂ : V), translate a point by a vector (v +ᵥ p : P), or form weighted affine combinations (Finset.centroid, midpoint, AffineMap.lineMap) whose weights sum to 1.
2. Where Affine Torsors Shine: Arbitrary Dimension \(n\)¶
Because V need not have dimension 2, Mathlib/Geometry/Euclidean/ achieves breathtaking generality across dimensions:
Monge Point & :math:`3(n+1)`-Point Sphere (`MongePoint.lean`, `NinePointCircle.lean`): Instead of proving altitude concurrency only for planar triangles,
Simplex.mongePointgeneralizes the orthocenter to an arbitrary \(n\)-simplex in \(\mathbb{R}^n\), andNinePointCircle.leanproves Feuerbach’s nine-point circle as the \(n\)-dimensional :math:`3(n+1)`-point sphere!Directed Twice-Angles Modulo :math:`2pi` (`Angle/Oriented/Basic.lean`): When [Module.Oriented ℝ V (Fin 2)] and [Fact (Module.finrank ℝ V = 2)] are added for 2D plane geometry,
oangle x y z(∡ x y z : Real.Angle) lives in \(\mathbb{R} / 2\pi\mathbb{Z}\). Multiplying by (2 : ℤ) • ∡ p₁ p₂ p₃ kills ray-reversal (π becomes 2π = 0), encoding directed line angles cleanly and proving inscribed-angle concyclicity (Sphere/Basic.lean) without case splits!1-Line La Hire Pole–Polar Reciprocity (`Sphere/PolePolar.lean`): Defines
Sphere.power s p := dist p s.center ^ 2 - s.radius ^ 2andSphere.polar s p := mk' (inversion s.center s.radius p) (ℝ ∙ (p -ᵥ s.center))ᗮ, proving Philippe de La Hire’s reciprocityq ∈ s.polar p ↔ p ∈ s.polar qin a handful of inner-product rewrite steps across all dimensions!Compositional Naming Grammar: Theorems read like self-documenting sentences (conclusion_of_hypothesis, e.g.,
mul_dist_add_mul_dist_eq_mul_dist_of_cosphericalinSphere/Ptolemy.lean).
3. Forensic Blind Spots: Noncomputability, Cyclic Order & Projective Gaps¶
Pervasive ``noncomputable`` Definitions:
Simplex.circumsphereusesClassical.chooseon an existence proof, andEuclideanGeometry.angleinvokes noncomputableReal.arccos. You cannot execute amathlib4Euclidean construction to inspect exact symbolic coordinates!No Constructive ``Euclid I.1`` & Awkward Cyclic Order: Because two spheres in \(\mathbb{R}^3\) meet in a circle rather than two points,
mathlib4has no planar compass-and-straightedgeEuclid I.1theorem. Moreover,Sphere/Ptolemy.lean:22-41contains a candid 20-line ``TODO`` block lamenting the lack of a clean cyclic-order predicate on circles in vector-torsor geometry.Wide-Open Projective & Coaxial Omissions: Despite defining
Projectivization K VinLinearAlgebra/Projective/Basic.lean,mathlib4currently has zeroradicalAxis, zerocrossRatio, zeroMenelaus(despite havingCeva.lean!), zeroPappus, zeroDesargues, zero general conics inGeometry/Euclidean/, and zero geometric theorems onReal.goldenRatioor Platonic solids.
4. Takeaway for GEOMETOR¶
Adopt mathlib4’s conclusion_of_hypothesis naming discipline and its crystal-clear power / inversion / polar conceptual factoring in geometor.elements 2.0 and geometor.model.inversion, while retaining 100% computable ANP coordinates and full projective/golden coverage.