Physlib.Units.Basic
Dimensions and unit
A unit in physics arises from choice of something in physics which is non-canonical. An example is the choice of translationally-invariant metric on the time manifold `TimeMan`.
A dimension is a property of a quantity related to how it changes with respect to a change in the unit.
The fundamental choices one has in physics are related to: - Time - Length - Mass - Charge - Temperature
(In fact temperature is not really a fundamental choice, however we leave this as a `TODO`.)
From these fundamental choices one can construct all other units and dimensions.
Implementation details
Units within Physlib are implemented with the following convention: - The fundamental units, and the choices they correspond to, are defined within the appropriate physics directory, in particular: - `Physlib/SpaceAndTime/Time/TimeUnit.lean` - `Physlib/SpaceAndTime/Space/LengthUnit.lean` - `Physlib/ClassicalMechanics/Mass/MassUnit.lean` - `Physlib/Electromagnetism/Charge/ChargeUnit.lean` - `Physlib/Thermodynamics/Temperature/TemperatureUnit.lean` - In this `Units` directory, we define the necessary structures and properties to work derived units and dimensions.
References
Zulip chats discussing units: - https://leanprover.zulipchat.com/#narrow/channel/479953-Physlib/topic/physical.20units - https://leanprover.zulipchat.com/#narrow/channel/116395-maths/topic/Dimensional.20Analysis.20Revisited/with/530238303
Note
A lot of the results around units is still experimental and should be adapted based on needs.
Other implementations of units
There are other implementations of units in Lean, in particular: 1. https://github.com/ATOMSLab/LeanDimensionalAnalysis/tree/main 2. https://github.com/teorth/analysis/blob/main/analysis/Analysis/Misc/SI.lean 3. https://github.com/ecyrbe/lean-units Each of these have their own advantages and specific use-cases. For example both (1) and (3) allow for or work in Floats, allowing computability and the use of `#eval`. This is currently not possible with the more theoretical implementation here in Physlib which is based exclusively on Reals.
Units
Types carrying dimensions
Dimensions are assigned to types with the following type-classes
- `HasDim` for any type `M` with an associated dimension
- `CarriesDimension` for a type that also has an instance of `MulAction ℝ≥0 M`
Terms of the current dimension
Given a type `M` which carries a dimension `d`, we are interested in elements of `M` which depend on a choice of units, i.e. functions `UnitChoices → M`.
We define both a proposition - `HasDimension f` which says that `f` scales correctly with units, and a type - `Dimensionful M` which is the subtype of functions which `HasDimension`.
30 declarations
Scaling factor for a dimension between unit choices and
Given two sets of unit choices and , this function defines a monoid homomorphism from physical dimensions to the non-negative real numbers . For a dimension , it computes the scaling factor used to convert a quantity of dimension from unit system to . This factor is calculated as the product of the ratios of the fundamental units (length, time, mass, charge, and temperature) in and , each raised to the power of the corresponding component in the dimension : where the exponents are the rational powers associated with each fundamental dimension.
Formula for the Scaling Factor of a Physical Dimension between Unit Systems and
Given two sets of unit choices and and a physical dimension , the scaling factor is calculated as the product of the ratios of the fundamental units in and , each raised to the power of the corresponding component in the dimension : where represents the fundamental unit of a specific type (length, time, mass, charge, or temperature) in unit system , and represents the rational exponent of that fundamental dimension in .
for identical unit systems
For any set of unit choices and any physical dimension , the scaling factor used to convert a quantity of dimension from unit system to itself is equal to .
The scaling factor for the dimensionless dimension is
For any two systems of unit choices and , the scaling factor associated with the identity dimension (dimensionless quantity) is equal to .
For any three sets of unit choices and any physical dimension , the scaling factor used to convert a quantity of dimension from unit system to satisfies the transitivity property:
For any two systems of unit choices and and any physical dimension , the product of the scaling factor (used to convert a quantity of dimension from unit system to ) and the scaling factor (used for the reverse conversion) is equal to :
For any two systems of unit choices and any physical dimension , let be the factor used to convert a quantity of dimension from unit system to . The product of this scaling factor and its reverse counterpart , when converted to real numbers, is equal to :
The dimension scaling factor is non-zero
For any two systems of unit choices and any physical dimension , the scaling factor is non-zero. This scaling factor represents the product of the ratios of fundamental units in and raised to the powers specified by the dimension , used to convert physical quantities between the two unit systems.
For any two systems of unit choices and any physical dimension , the scaling factor used to convert quantities of dimension from unit system to is the multiplicative inverse of the scaling factor for the reverse conversion. That is,
For any two systems of unit choices and any physical dimension , the scaling factor for the inverse dimension from unit system to is equal to the scaling factor for the original dimension when converting from unit system to . That is,
Scaling by `dimScale` is injective in
Let be a type equipped with a scalar action of the non-negative real numbers . For any two systems of unit choices and any physical dimension , let be the scaling factor associated with converting quantities of dimension from unit system to . For any two elements , the result of scaling by is equal if and only if the original elements are equal:
For any two systems of unit choices and any physical dimension , the scaling factor used to convert physical quantities of dimension from unit system to is strictly positive:
The International System of Units (SI) choices
The definition `UnitChoices.SI` represents the choice of base physical units corresponding to the International System of Units (SI). It is a structure of type `UnitChoices` where the fundamental units are assigned as follows: - The unit of length is meters. - The unit of time is seconds. - The unit of mass is kilograms. - The unit of charge is coulombs. - The unit of temperature is kelvin.
In the International System of Units (), the base unit assigned to the length dimension is the meter:
In the International System of Units (), the fundamental unit chosen for the dimension of time is the second ().
The SI unit of mass is the kilogram
In the International System of Units (SI), the designated fundamental unit for the mass dimension is the kilogram.
The SI unit of charge is the coulomb
In the International System of Units (SI), the assigned base unit for physical charge is the coulomb.
The SI unit of temperature is Kelvin
In the International System of Units (SI), the base unit for temperature is defined as Kelvin.
Prime-scaled SI unit system
`UnitChoices.SIPrimed` is a specific set of unit choices derived from the International System of Units (SI) where each base unit is scaled by a distinct prime number. It is defined as follows: - Length: - Time: - Mass: - Charge: - Temperature: This configuration is primarily used to verify the dimensional correctness of physical expressions, as the prime scaling ensures that different combinations of base dimensions result in unique scaling factors.
Scaling factor for dimension from to units
For any physical dimension , the scaling factor required to convert a quantity from the International System of Units () to the prime-scaled system () is given by the product: where , and are the rational components of the dimension . This factor arises because the base units in (meters, seconds, kilograms, coulombs, and kelvin) are scaled by the factors 2, 3, 5, 7, and 11, respectively, relative to .
Scaling factor for dimension from to units
For any physical dimension , the scaling factor required to convert a quantity from the prime-scaled system () to the International System of Units () is given by the product: where , and are the rational components (exponents) of the dimension . This factor corresponds to the ratios of the base units in relative to , which are scaled by factors of 2 (length), 3 (time), 5 (mass), 7 (charge), and 11 (temperature).
is consistent with dimension
Let be a type that carries a physical dimension, denoted as . A function , representing a quantity whose value depends on the chosen system of units, satisfies the property **HasDimension** if it scales correctly under a change of units. Specifically, for any two unit choices , the value of the function at must relate to the value at by: where is the scaling factor associated with dimension for the transition from unit system to , and the multiplication represents the action of non-negative reals on .
`HasDimension f` iff scales by `dimScale` for the dimension of
Let be a type that carries a physical dimension, denoted as . For any function , the property **HasDimension** holds if and only if for all unit choices , the value of the function at is related to the value at by the scaling factor associated with the dimension of : where is the scaling factor for the transition from unit system to , and the multiplication represents the action of non-negative reals on .
The type of dimensionful quantities of type
Let be a type that carries a physical dimension, denoted as . The type **Dimensionful ** is defined as the set of functions that are consistent with the dimension of . Specifically, a function belongs to this type if, for all pairs of unit choices , it satisfies the scaling relation: where is the scaling factor associated with the dimension of for the transition from the unit system to , and the multiplication denotes the action of non-negative reals on .
Coercion from **Dimensionful ** to functions
For any type that carries a physical dimension, an element of the type **Dimensionful ** can be treated as a function from the set of unit choices to . This coercion allows a dimensionful quantity to be evaluated at a specific system of units to return its value in .
for Dimensionful Quantities
Let be a type that carries a physical dimension. For any two dimensionful quantities , if their underlying functions are equal, then the dimensionful quantities themselves are equal ().
-action on
Let be a type that carries a physical dimension. The space of dimensionful quantities of type , denoted as , is equipped with a scalar action by the non-negative real numbers . For any scalar and any dimensionful quantity , the action is defined pointwise for each choice of units as: where the right-hand side is the action of on . This operation satisfies the axioms of a multiplicative action: and .
for dimensionful quantities
Let be a type that carries a physical dimension. For any non-negative real number , any dimensionful quantity (represented as a function from unit choices to ), and any specific choice of units , the value of the scaled dimensionful quantity at is equal to the scalar acting on the value of at : where the multiplication on the right-hand side is the action of on the type .
Equivalence relative to unit choice
Let be a type that carries a physical dimension . Given a specific system of units , there exists an equivalence (bijection) between the type and the type of functions that scale correctly under a change of units. An element corresponds to the dimensionful quantity defined by: where is the scaling factor for dimension when transitioning from unit system to . Conversely, a dimensionful quantity is mapped to the value it takes in the unit system , given by .
Evaluating a dimensionful quantity from in equals
Let be a type that carries a physical dimension . For any two systems of unit choices and any value , let be the dimensionful quantity (an element of the type **Dimensionful **) that corresponds to in the unit system . The value of when evaluated at the unit system is given by: where is the scaling factor associated with dimension for the transition from unit system to , and the multiplication denotes the action of non-negative reals on .
