/-
Copyright (c) 2025 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Tooby-Smith
-/modulepublicimportMathlib.Analysis.Normed.Field.LemmaspublicimportMathlib.Tactic.DeriveFintype
Dimension
In this module we define the type Dimension which carries the dimension
of a physical quantity.
A Dimension B is parameterised by a basisB of base dimensions: it assigns a
rational exponent to each base dimension b : B. The parameterisation is purely in
the dimensional algebra: Dimension B is a CommGroup for every B
(multiplication adds exponents, inversion negates them), so quantities can be typed by
dimensions over any basis. The commutative-group and ℚ-power structure, decidable
equality (DecidableEq), the base vectors single b, and the change-of-basis map
extend are all generic in B.
PhysLib's default basis is LTMCTDimensionBase — length, time, mass, charge,
temperature — whose projections and named generators (L𝓭, T𝓭, …) live in
Physlib.Units.LTMCTDimensionBase. It is charge-based with five generators, so it
is not the SI/ISQ base-quantity set; the ISQ set is ISQDimensionBase, and other
systems (Gaussian–CGS, natural units, …) are equally expressible as Dimension B for
a suitable basis B.
@[expose]publicsection
Defining dimensions
A dimension over a basis B of base dimensions: a rational exponent for each
base dimension b : B. PhysLib's default basis is LTMCTDimensionBase.
Change of basis along a map f : B → B' of base dimensions: reindex a dimension
over B into one over B' by placing each exponent at its image. For an embedding
f (injective) this preserves every exponent (extend_exponent_apply), so a
dimension in one system re-expresses faithfully in an extending one.
A cross-basis map of dimensions is only admissible if it preserves the dimensional
algebra. We record the two truth-preserving directions as bundled data:
an Embedding B B' is an injectiveMonoidHom (Dimension B) (Dimension B') — a
faithful, dimension-preserving inclusion of one basis into another; and
a Projection B' B is a surjectiveMonoidHom (Dimension B') (Dimension B) — a
truth-preserving reduction of a richer basis onto a coarser one.
Being a MonoidHom is what makes either map dimension-preserving (it respects
products, inverses and rational powers); the injectivity / surjectivity side condition
distinguishes the two directions. Cross-basis dimension maps should be produced as one
of these, so that dimension-preservation holds by construction — a bare relabelling
that sends a base dimension to an inequivalent one is not expressible as either.
extend f packaged as a monoid homomorphism of dimensions.
A dimension embeddingB ↪ B': an injective monoid homomorphism of
dimensions. As a MonoidHom it is dimension-preserving (it respects products,
inverses and rational powers); injectivity makes it a faithful inclusion of the basis
B into B'. Cross-basis dimension injections are produced as Embeddings so that
dimension-preservation holds by construction.
The underlying dimension-preserving homomorphism.
The homomorphism is injective (a faithful embedding).
A dimension projectionB' ↠ B: a surjective monoid homomorphism of
dimensions. As a MonoidHom it is truth-preserving, but it is lossy — it reduces a
richer basis B' onto a coarser basis B, collapsing the base dimensions that B
does not track.
The underlying dimension-preserving homomorphism.
The homomorphism is surjective (the reduction hits every dimension of B).
An injective basis map f : B → B' induces a dimension embedding, via extend.
This is the label-level case: it sends each base dimension of B to a base dimension
of B', so it is automatically dimension-preserving and faithful.