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.

Defining dimensions #

structure Dimension :

The foundational dimensions. Defined in the order ⟨length, time, mass, charge, temperature⟩

  • length : β„š

    The length dimension.

  • time : β„š

    The time dimension.

  • mass : β„š

    The mass dimension.

  • charge : β„š

    The charge dimension.

  • temperature : β„š

    The temperature dimension.

Instances For
    Equations
    theorem Dimension.zero_eq :
    0 = { length := 0, time := 0, mass := 0, charge := 0, temperature := 0 }
    Equations
    • One or more equations did not get rendered due to their size.
    @[simp]
    theorem Dimension.time_mul (d1 d2 : Dimension) :
    (d1 * d2).time = d1.time + d2.time
    @[simp]
    theorem Dimension.length_mul (d1 d2 : Dimension) :
    (d1 * d2).length = d1.length + d2.length
    @[simp]
    theorem Dimension.mass_mul (d1 d2 : Dimension) :
    (d1 * d2).mass = d1.mass + d2.mass
    @[simp]
    theorem Dimension.charge_mul (d1 d2 : Dimension) :
    (d1 * d2).charge = d1.charge + d2.charge
    Equations
    Equations
    • One or more equations did not get rendered due to their size.

    The dimension corresponding to length.

    Equations
    Instances For

      The dimension corresponding to time.

      Equations
      Instances For

        The dimension corresponding to mass.

        Equations
        Instances For

          The dimension corresponding to charge.

          Equations
          Instances For

            The dimension corresponding to temperature.

            Equations
            Instances For

              Units #

              structure UnitChoices :

              The choice of units.

              Instances For
                noncomputable def UnitChoices.dimScale (u1 u2 : UnitChoices) (d : Dimension) :

                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
                  @[simp]
                  @[simp]
                  theorem UnitChoices.dimScale_zero (u1 u2 : UnitChoices) :
                  u1.dimScale u2 0 = 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 (u1 u2 : UnitChoices) (d1 d2 : Dimension) :
                  u1.dimScale u2 (d1 * d2) = u1.dimScale u2 d1 * u1.dimScale u2 d2
                  @[simp]
                  noncomputable def UnitChoices.SI :

                  The choice of units corresponding to SI units, that is

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

                    Dimensionful #

                    Given a type M with a dimension d, a dimensionful quantity is a map from UnitChoices to M, which scales with the choice of unit according to d.

                    See: https://leanprover.zulipchat.com/#narrow/channel/479953-PhysLean/topic/physical.20units/near/530520545

                    def HasDimension (d : Dimension) {M : Type} [SMul NNReal M] (f : UnitChoices β†’ M) :

                    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 {d : Dimension} {M : Type} [SMul NNReal M] (f : UnitChoices β†’ M) :
                      HasDimension d f ↔ βˆ€ (u1 u2 : UnitChoices), f u2 = u1.dimScale u2 d β€’ f u1
                      def Dimensionful (d : Dimension) (M : Type) [SMul NNReal M] :

                      The type of maps from UnitChoices to M which have dimension d.

                      Equations
                      Instances For

                        Applying an element of Dimensionful d M to a unit choice gives an element of M.

                        Equations

                        Equality lemmas #

                        theorem Dimensionful.eq_of_val {d : Dimension} {M : Type} [SMul NNReal M] {f1 f2 : Dimensionful d M} (h : ↑f1 = ↑f2) :
                        f1 = f2
                        theorem Dimensionful.eq_of_apply {d : Dimension} {M : Type} [SMul NNReal M] {f1 f2 : Dimensionful d M} (h : βˆ€ (u : UnitChoices), ↑f1 u = ↑f2 u) :
                        f1 = f2
                        theorem Dimensionful.eq_of_unitChoices {d : Dimension} {M : Type} [SMul NNReal M] {f1 f2 : Dimensionful d M} (u : UnitChoices) (h : ↑f1 u = ↑f2 u) :
                        f1 = f2
                        theorem Dimensionful.eq_of_SI {d : Dimension} {M : Type} [SMul NNReal M] {f1 f2 : Dimensionful d M} (h : ↑f1 UnitChoices.SI = ↑f2 UnitChoices.SI) :
                        f1 = f2

                        MulAction #

                        Equations
                        Equations
                        @[simp]
                        theorem Dimensionful.smul_apply {d : Dimension} {M : Type} [MulAction NNReal M] (f : Dimensionful d M) (u : UnitChoices) (a : NNReal) :
                        ↑(a β€’ f) u = a β€’ ↑f u
                        @[simp]
                        theorem Dimensionful.smul_real_apply {d : Dimension} {M : Type} [MulAction ℝ M] (f : Dimensionful d M) (u : UnitChoices) (a : ℝ) :
                        ↑(a β€’ f) u = a β€’ ↑f u

                        ofUnit #

                        noncomputable def Dimensionful.ofUnit (d : Dimension) {M : Type} [MulAction NNReal M] (m : M) (u : UnitChoices) :

                        The creation of an element f : Dimensionful d M given a m : M and a choice of units u : UnitChoices, defined such that f u = m.

                        Equations
                        Instances For
                          theorem Dimensionful.ofUnit_eq_mul_dimScale {d : Dimension} {M : Type} [MulAction NNReal M] (m : M) (u1 u2 : UnitChoices) :
                          ofUnit d m u1 = u1.dimScale u2 d β€’ ofUnit d m u2
                          @[simp]
                          theorem Dimensionful.ofUnit_apply_self {d : Dimension} {M : Type} [MulAction NNReal M] (m : M) (u : UnitChoices) :
                          ↑(ofUnit d m u) u = m
                          theorem Dimensionful.ofUnit_apply {d : Dimension} {M : Type} [MulAction NNReal M] (m : M) (u1 u2 : UnitChoices) :
                          ↑(ofUnit d m u1) u2 = u1.dimScale u2 d β€’ m

                          LE #

                          Equations
                          theorem Dimensionful.le_nnReals_of_unitChoice {d : Dimension} {f1 f2 : Dimensionful d NNReal} (u : UnitChoices) (h : ↑f1 u ≀ ↑f2 u) :
                          f1 ≀ f2

                          Addition and module structure #

                          Equations
                          @[simp]
                          theorem Dimensionful.add_apply {d : Dimension} {M : Type} [AddZeroClass M] [DistribSMul NNReal M] (f1 f2 : Dimensionful d M) (u : UnitChoices) :
                          ↑(f1 + f2) u = ↑f1 u + ↑f2 u
                          Equations
                          • One or more equations did not get rendered due to their size.
                          @[simp]
                          theorem Dimensionful.neg_apply {d : Dimension} {M : Type} [AddCommGroup M] [DistribSMul NNReal M] (f : Dimensionful d M) (u : UnitChoices) :
                          ↑(-f) u = -↑f u
                          @[simp]
                          theorem Dimensionful.zero_apply {d : Dimension} {M : Type} [AddZeroClass M] [DistribSMul NNReal M] (u : UnitChoices) :
                          ↑0 u = 0
                          Equations
                          @[simp]
                          theorem Dimensionful.sub_apply {d : Dimension} {M : Type} [AddCommGroup M] [DistribSMul NNReal M] (f1 f2 : Dimensionful d M) (u : UnitChoices) :
                          ↑(f1 - f2) u = ↑f1 u - ↑f2 u

                          ###Β Multiplication

                          Equations
                          @[simp]
                          theorem Dimensionful.mul_real_apply {d1 d2 : Dimension} (x : Dimensionful d1 ℝ) (y : Dimensionful d2 ℝ) (u : UnitChoices) :
                          ↑(x * y) u = ↑x u * ↑y u

                          Division #

                          Equations
                          @[simp]
                          theorem Dimensionful.hdiv_apply {d1 d2 : Dimension} (x : Dimensionful d1 ℝ) (y : Dimensionful d2 ℝ) (u : UnitChoices) :
                          ↑(x / y) u = ↑x u / ↑y u

                          SMul #

                          noncomputable instance Dimensionful.instHSMulRealHMulDimension {d1 d2 : Dimension} {M : Type} [AddCommGroup M] [Module ℝ M] :
                          Equations
                          @[simp]
                          theorem Dimensionful.hsmul_apply {d1 d2 : Dimension} {M : Type} [AddCommGroup M] [Module ℝ M] (x : Dimensionful d1 ℝ) (y : Dimensionful d2 M) (u : UnitChoices) :
                          ↑(x β€’ y) u = ↑x u β€’ ↑y u

                          Inner product #

                          We define the inner product in SI units.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Equations
                          • One or more equations did not get rendered due to their size.

                          Derivatives #

                          noncomputable def Dimensionful.deriv {d1 d2 : Dimension} (f : Dimensionful d1 ℝ β†’ Dimensionful d2 ℝ) (atLocation : Dimensionful d1 ℝ) :

                          The derivative using dimensionalful quantities.

                          Equations
                          Instances For

                            valCast #

                            noncomputable def Dimensionful.valCast {d : Dimension} {M : Type} [SMul NNReal M] (f : Dimensionful d M) (hd : d = 0 := by rfl) :
                            M

                            The casting of a quantity in Dimensionful 0 M to its underlying element in M.

                            Equations
                            Instances For
                              theorem Dimensionful.valCast_eq_unitChoices {d : Dimension} {M : Type} [MulAction NNReal M] {f : Dimensionful d M} {hd : d = 0} (u : UnitChoices) :
                              f.valCast hd = ↑f u

                              Measured quantities #

                              We defined Measured d M to be a type of measured quantity of type M and of dimension d, the terms of Measured d M are corresponds to values of the quantity in a given but arbitary set of units.

                              If M has the type of a vector space, then the type Measured d M inherits this structure.

                              Likewise if M has the type of an inner product space, then the type Measured d M inherits this structure. However, note that the inner product space does not explicit track the dimension, mapping down to ℝ. This is in theory fine, as it is still dimensionful, in the sense that it scales with the choice of unit.

                              The type Measured d M can be seen as a convienent way to work with and keep track of dimensions. However, working with Measured d M does not formally prove anything about dimensions, which can only be done with Dimensionful d M, or other manifest considerations of UnitChoices.

                              structure Measured (d : Dimension) (M : Type) [SMul NNReal M] :

                              A measured quantity is a quantity which carries a dimension d, but which lives in a given (but arbitary) set of units.

                              • val : M

                                The value of the measured quantity.

                              Instances For
                                theorem Measured.eq_of_val {d : Dimension} {M : Type} [SMul NNReal M] {m1 m2 : Measured d M} (h : m1.val = m2.val) :
                                m1 = m2
                                theorem Measured.eq_of_val_iff {d : Dimension} {M : Type} [SMul NNReal M] {m1 m2 : Measured d M} :
                                m1 = m2 ↔ m1.val = m2.val

                                Basic instances carried from underlying type. #

                                instance Measured.instSMul {d : Dimension} {Ξ± M : Type} [SMul NNReal M] [SMul Ξ± M] :
                                SMul Ξ± (Measured d M)
                                Equations
                                @[simp]
                                theorem Measured.smul_val {d : Dimension} {Ξ± M : Type} [SMul NNReal M] [SMul Ξ± M] (r : Ξ±) (m : Measured d M) :
                                (r β€’ m).val = r β€’ m.val
                                instance Measured.instHMulHMulDimension {d1 d2 : Dimension} {M1 M2 M : Type} [SMul NNReal M1] [SMul NNReal M2] [SMul NNReal M] [HMul M1 M2 M] :
                                HMul (Measured d1 M1) (Measured d2 M2) (Measured (d1 * d2) M)
                                Equations
                                instance Measured.instHSMulHMulDimension {d1 d2 : Dimension} {M1 M2 M : Type} [SMul NNReal M1] [SMul NNReal M2] [SMul NNReal M] [HSMul M1 M2 M] :
                                HSMul (Measured d1 M1) (Measured d2 M2) (Measured (d1 * d2) M)
                                Equations
                                instance Measured.instLE {d : Dimension} {M : Type} [SMul NNReal M] [LE M] :
                                LE (Measured d M)
                                Equations
                                theorem Measured.le_eq_le_val {d : Dimension} {M : Type} [SMul NNReal M] [LE M] (x y : Measured d M) :
                                @[simp]
                                theorem Measured.smul_unitChoices_apply {d : Dimension} {M : Type} [MulAction NNReal M] (m : Measured d M) (u u1 : UnitChoices) :
                                ↑(m β€’ u) u1 = u.dimScale u1 d β€’ m.val