Expand description
§Diffable
A differential geometry framework for Rust. Each trait represents a mathematical structure—group, vector space, smooth atlas, metric, and so on. Implementing a trait certifies that a type carries that structure, while blanket implementations derive the structures that follow from it. In practice, implementing a single high-level trait often gives you the surrounding geometry for free.
§Structure
The library is organised around a hierarchy of traits that mirror the mathematical structure of differential geometry.
§Foundation — points, scalars, separation
traits::Point— The underlying set: an element of a manifold, group, or metric space. Anything can be a Point, in fact; anything that isCloneis aPoint.traits::Field— A (possibly non-commutative) scalar field of vector space equipped with a possibly trivial involution. Follows the field axioms.traits::CField— The commutative refinement of a field.traits::Real— An ordered real-number field, used as a coordinate scalar and as the target of intervals and metrics. Seetraits::ExactCmpfor the strict order that convergence tests need when an implementor’s equality is tolerance-based.traits::Interval— A signed squared intervals²: M × M → R(negative timelike, zero null, positive spacelike); the pseudo-metric base, claiming no metric-space axioms.interval_squaredis the primitive,intervalits signed square root, returningComplex<R: Real>traits::Metric— the definite refinement: a genuine non-negative distanced = √(interval_squared). Independent of any coordinate structure
§Vector spaces and forms
traits::Vector— A finite-dimensional coordinate vector space over aField. It is the local model atraits::Chartmaps into and the tangent space of every manifold, and is its own additivetraits::LieGroup.traits::Dualis the dual spaceV*.- A bare
Vectorcarries no metric. Scalar products are induced by progressively stronger traits:traits::Formgives a lowering map♭: V → V*and the induced pairingdot.traits::Nondegeneratemakes♭invertible by adding♯.traits::Sesquilinearspecialises to Hermitian forms.traits::Bilinearspecialises further to symmetric bilinear forms.traits::InnerProductadds positive definiteness.
traits::Euclidean— The canonical flatRⁿthat is simultaneously an inner-product space, its own tangent bundle, and an additive Lie group.
§Charts — local coordinate structure
traits::Chart— A coordinate chart mapping points of a manifold to a flat coordinate space and back.traits::ExpMap— A chart whose coordinate lines are geodesics and whose coordinate distances are (signed) arc lengths.traits::TangentBundle— The tangent bundleTM: anExpMapchart centred at every point. This is the working surface of a smooth manifold —expandlog, geodesics, geodesic distance, and sectional curvature are all read off it, so most geometric computation is written against this trait.traits::PseudoRiemannian— Certifies that the exponential map and the tangent-space form agree: the geodesic interval equals⟨v,v⟩. Signature-agnostic; reduces to the usuald(p, exp_p v) = ‖v‖in the definite case.traits::Smooth— A helper trait for manifolds that charts themselves, providingexpandlogat every point. Implement this one trait and the full chart bundleChart,ExpMap,TangentBundlefor free.
§Algebra — groups and Lie groups
-
traits::Group— an operator-agnostic group interface, using named methods rather than+or*.traits::CMonoid/traits::CGroupandtraits::Monoid/traits::MulGroupare the additive and multiplicative presentations used by concrete types. The helper macrosimpl_group_via_add!andimpl_group_via_mul!connect them toGroup.traits::Rig,traits::Ring,traits::DivRing, andtraits::Fieldcombine both operations. -
traits::LieGroup— a group with a smooth exponential map at the identity; automatically derivesSmooth(and therefore the whole chart bundle) via left translation -
traits::Quotient— a quotientG/Hof a Lie group by a subgroup, inheriting Lie group structure from the parent
§Global topology — covers, nerve complexes, fundamental groups and global geodesic minimisation
traits::Bounded— aTangentBundlechart with a bounded, open domain, expressed via a signed distance field.traits::NerveComplex— a finite cover of a manifold byBoundedcharts whose overlap pattern forms a simplicial complex; computes global geodesic distance by graph search and recovers the fundamental groupπ₁(M)from the nerve. Since the cover finite and open, NerveComplex serves as a proof that the implemented manifold is compact.traits::GroupPresentation— a group described by generators and relations; the output ofNerveComplex::fundamental_group. Group presentation does not implementGroupbecause the word problem is uncomputable in general.
§Blanket chains
Implement one trait; receive the these for free:
| Trait | Blaket impls |
|---|---|
Smooth<V> | Chart, ExpMap, TangentBundle |
LieGroup<V> | Smooth<V> → … |
Vector | Group, LieGroup<Self> → … |
Quotient<G, H, V> (via macro) | Group, LieGroup<V> → … |
Sesquilinear<F: Field<Fixed = F>> | Bilinear |
Group itself is reached via a one-line macro rather than a blanket impl
(CMonoid/Monoid can’t both blanket-impl the same trait without
overlapping), so every LieGroup implementor pairs its +/* structure
with impl_group_via_add!/impl_group_via_mul! before joining the chain.
§Implementations
coords::Coords— the canonical flat spaceR^(N−M, M), a fixed-size array parameterised by a signatureM(the count of timelike directions).M = 0is ordinary EuclideanRⁿ(with a norm and metric);M > 0is indefinite (Coords<R, 4, 1>is Minkowski spacetime), carrying only aBilinearformcomplex::Complex— the complex numbers as aField, withconjthe Hermitian involution.traits::Symmetrizedwraps a field to select its bilinear rather than Hermitian formmatrix::Matrix— anN×Nmatrix, interpreted as the tensorV ⊗ V*, with variance encoded in the type so only variance-correct contractions typecheck.matrix::MatrixExponentialprovidesexp/log.hypersphere::Sphere— the unit hypersphereSⁿas a smooth manifold with geodesic structure for any dimensionhypersphere::S0,hypersphere::UnitComplex,hypersphere::S3— the Lie group structures on the three parallelizable spheres (signs, the unit complex numbersU(1), the unit quaternionsSU(2)), as newtypes ofSpherethat add the group operationhypersphere::So3— the rotation groupSO(3)as the quotientS³/{±1}, a newtype ofS3hypersphere::Stereographic— stereographic projection charts, an external atlas independent of the geodesic self-chartsspacetime::Minkowski—Coords<R, 4, 1>, spacetime with signature(−,+,+,+);spacetime::Sl/spacetime::Sl2cthe special linear group (SL(2,ℂ)double-covering the Lorentz group);spacetime::SlAlgebraits traceless Lie algebra with the Killing form; andspacetime::Lorentzthe restricted Lorentz groupSO⁺(1,3)asSL(2,ℂ)/{±1}discrete::Z— the integers, as the Grothendieck completion of the naturalsdiscrete::N; also the covering lattice forflat::S1flat::S1— the circle as the flat quotientR/Z, a more performant model ofS¹thanhypersphere::UnitComplex;flat::Torus/flat::KleinBottleglue two circles straight (a group) or with a fibre-flipping twist (the library’s only non-orientable manifold)
The newtype layering reflects the mathematical structure: Sphere is the
bare manifold (geometry only), S3 adds the quaternion group operation,
and So3 adds the antipodal identification. Each wrapper is zero-cost and
peelable — .0 is the forgetful functor dropping one layer of structure.
§Testing
Diffable takes the philosophy that any axiom which is assumed true of a type
but not directly enforcable by the compiler should be emperically verified
via property testing. Enable the testing feature to access the test_*
macros, which verify that your implementations satisfy the mathematical
invariants certified by each trait. The Real types R64 and R32 provide
tolerance-based equality suitable for property testing with floating point,
since the library assumes that its real numbers are perfect.
[dev-dependencies]
diffable = { version = "...", features = ["testing"] }§Optional features
testing— property-testing macros and tolerance-based scalar typesall— enables all features
Re-exports§
Modules§
Macros§
- group_
presentation - impl_
abelian_ group_ via_ grothendieck - Implements
Zero,Add, andNegfor$targetvia Grothendieck group completion of the commutative monoid$monoid. - impl_
group_ via_ add - Bridges a
+/--flavoured type into the spelling-agnosticGroupby delegatingidentity/compose/inverseto itsZero/Add/Neg. - impl_
group_ via_ mul - Bridges a
*/Inv-flavoured type into the spelling-agnosticGroupby delegatingidentity/compose/inverseto itsOne/Mul/Inv. - impl_
lie_ group_ via_ quotient - Implements
GroupandLieGroupfor$typeby routing every operation through itsQuotient<$g, $h, V>implementation. - impl_
ring_ via_ grothendieck - Implements
Zero,Add,Neg,One, andMulfor$targetvia Grothendieck completion of the commutative semiring (“rig”)$rig. - impl_
tangent_ bundle_ via_ bounded - Implements
Chart,ExpMap, andTangentBundlefor$targetby delegating to$target’sAsRef::as_refchart, restrictingto_localto the region whereBounded::sdfis negative. - test_
cfield - Tests the
CFieldaxioms: that we have a commutative field. - test_
cgroup - Tests the
CGroupaxioms: everythingtest_cmonoid!checks, plus additive inverses. - test_
chart - Tests the chart roundtrip invariant: to_global(to_local(p)) == p for any chart type and point generator.
- test_
cmonoid - Tests the
CMonoidaxioms: identity, associativity, commutativity. - test_
div_ ring - Tests the
DivRingaxioms: that the Inverse is properly implemented. - test_
euclidean - Tests that a space claiming to be a euclidean space is a euclidean space
- test_
exp_ map - Tests the ExpMap invariants: preservation of origin, geodesic symmetry, geodesic scaling, and first-order isometry. The chart is constructed via chart_at on a generated base point.
- test_
field - Tests the
Fieldaxioms: that we have a division ring with proper involution. - test_
form - test_
group - Tests the
Groupaxioms: identity, associativity, inverses. - test_
inner_ product - Tests the InnerProduct axioms: symmetry, bilinearity, positive-definiteness.
- test_
interval - Tests the Interval axioms: Symmetry and self-interval is zero.
- test_
metric - Tests the Metric axioms: non-negativity, symmetry, self-distance is zero.
- test_
monoid - Tests the
Monoidaxioms: identity, associativity (no commutativity). - test_
mul_ group - Tests the
MulGroupaxioms: everythingtest_monoid!checks, plus multiplicative inverses. - test_
nondegenerate - test_
pseudo_ euclidean - Tests that a space claiming to be a pseudo-Euclidean space is a pseudo-Euclidean space
- test_
pseudo_ riemannian - Tests that
MetricandExpMapagree:d(p, exp_p(v)) == |log_p(exp_p(v))|. - test_
quotient - Tests the Quotient axioms: that canonical respects cosets, and the inherited LieGroup axioms which follow from the quotient structure.
- test_
rig - Tests the
Rigaxioms: everythingtest_cmonoid!andtest_monoid!check, plus distributivity and multiplicative annihilation by zero. - test_
ring - Tests the
Ringaxioms: everythingtest_cgroup!andtest_rig!check. - test_
sesquilinear - Tests the
Sesquilinearaxioms: Hermitian symmetry, additivity, and scalar linearity in the first argument. - test_
tangent_ bundle - Tests the TangentBundle invariant on top of all ExpMap invariants.
- test_
vector - Tests that a vector space is a vector space