PhysLean Documentation

PhysLean.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:

(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 PhysLean are implemented with the following convention:

References #

Zulip chats discussing units:

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 PhysLean which is based exclusively on Reals.

Units #

structure UnitChoices :

The choice of units.

Instances For
    theorem UnitChoices.ext {x y : UnitChoices} (length : x.length = y.length) (time : x.time = y.time) (mass : x.mass = y.mass) (charge : x.charge = y.charge) (temperature : x.temperature = y.temperature) :
    x = y

    Given two choices of units u1 and u2 and a dimension d, the element of ℝ≥0 corresponding to the scaling (by definition) of a quantity of dimension d when changing from units u1 to u2.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem UnitChoices.dimScale_apply (u1 u2 : UnitChoices) (d : Dimension) :
      (u1.dimScale u2) d = (u1.length / u2.length) ^ d.length * (u1.time / u2.time) ^ d.time * (u1.mass / u2.mass) ^ d.mass * (u1.charge / u2.charge) ^ d.charge * (u1.temperature / u2.temperature) ^ d.temperature
      @[simp]
      @[simp]
      theorem UnitChoices.dimScale_one (u1 u2 : UnitChoices) :
      (u1.dimScale u2) 1 = 1
      theorem UnitChoices.dimScale_transitive (u1 u2 u3 : UnitChoices) (d : Dimension) :
      (u1.dimScale u2) d * (u2.dimScale u3) d = (u1.dimScale u3) d
      @[simp]
      theorem UnitChoices.dimScale_mul_symm (u1 u2 : UnitChoices) (d : Dimension) :
      (u1.dimScale u2) d * (u2.dimScale u1) d = 1
      @[simp]
      theorem UnitChoices.dimScale_coe_mul_symm (u1 u2 : UnitChoices) (d : Dimension) :
      ((u1.dimScale u2) d) * ((u2.dimScale u1) d) = 1
      @[simp]
      theorem UnitChoices.dimScale_neq_zero (u1 u2 : UnitChoices) (d : Dimension) :
      (u1.dimScale u2) d 0
      theorem UnitChoices.dimScale_symm (u1 u2 : UnitChoices) (d : Dimension) :
      (u1.dimScale u2) d = ((u2.dimScale u1) d)⁻¹
      @[simp]
      theorem UnitChoices.smul_dimScale_injective {M : Type} [MulAction NNReal M] (u1 u2 : UnitChoices) (d : Dimension) (m1 m2 : M) :
      (u1.dimScale u2) d m1 = (u1.dimScale u2) d m2 m1 = m2
      @[simp]
      theorem UnitChoices.dimScale_pos (u1 u2 : UnitChoices) (d : Dimension) :
      0 < (u1.dimScale u2) d
      noncomputable def UnitChoices.SI :

      The choice of units corresponding to SI units, that is

      • meters,
      • seconds,
      • kilograms,
      • columbs,
      • kelvin.
      Equations
      Instances For

        A UnitChoices which is related to SI by a prime scaling of each of the underlying units. This is useful in proving that a result is not dimensionally correct.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[simp]
          theorem UnitChoices.dimScale_SIPrimed_SI (d : Dimension) :
          (SIPrimed.dimScale SI) d = 2 ^ d.length * 3 ^ d.time * 5 ^ d.mass * 7 ^ d.charge * 11 ^ d.temperature

          Types carrying dimensions #

          Dimensions are assigned to types with the following type-classes

          The latter is need to prevent a typeclass dimond.

          class CarriesDimension (M : Type) extends MulAction NNReal M :

          A type M carries a dimension d if every element of M is supposed to have this dimension. For example, the type Time will carry a dimension T𝓭.

          Instances

            A module M carries a dimension d if every element of M is supposed to have this dimension. This is defined in additon to CarriesDimension to prevent a type-casting dimond.

            • The dimension carried by a module M.

            Instances

              Terms of the current dimension #

              Given a type M which carries a dimension d, we are intrested in elements of M which depend on a choice of units, i.e. functions UnitChoices → M.

              We define both a proposition

              A quantity of type M which depends on a choice of units UnitChoices is said to be of dimension d if it scales by UnitChoices.dimScale u1 u2 d under a change in units.

              Equations
              Instances For
                theorem hasDimension_iff {M : Type} [CarriesDimension M] (f : UnitChoicesM) :
                HasDimension f ∀ (u1 u2 : UnitChoices), f u2 = (u1.dimScale u2) (CarriesDimension.d M) f u1

                The subtype of functions UnitChoices → M, for which M carries a dimension, which HasDimension.

                Equations
                Instances For
                  theorem Dimensionful.ext {M : Type} [CarriesDimension M] (f1 f2 : Dimensionful M) (h : f1 = f2) :
                  f1 = f2
                  theorem Dimensionful.ext_iff {M : Type} [CarriesDimension M] {f1 f2 : Dimensionful M} :
                  f1 = f2 f1 = f2
                  Equations
                  @[simp]
                  theorem Dimensionful.smul_apply {M : Type} [CarriesDimension M] (a : NNReal) (f : Dimensionful M) (u : UnitChoices) :
                  ↑(a f) u = a f u

                  For M carying a dimension d, the equivalence between M and Dimension M, given a choice of units.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem CarriesDimension.toDimensionful_apply_apply {M : Type} [CarriesDimension M] (u1 u2 : UnitChoices) (m : M) :
                    ((toDimensionful u1) m) u2 = (u1.dimScale u2) (d M) m