Physlib

Physlib.Units.Exponent

Reducible rational arithmetic for dimension exponents

This module defines `Exponent`, a wrapper around the rational numbers whose arithmetic is reducible. This lets concrete arithmetic on dimension exponents hold by definitional equality.

The corresponding rational operations are irreducible in Lean. Locally unsealing them does not export their reducibility to downstream modules, while globally changing the reducibility of an imported declaration requires `allowUnsafeReducibility`. The wrapper instead owns transparent operations while remaining equivalent to `ℚ`.

The reducibility guarantee applies to the custom addition, subtraction, multiplication, inversion, and division below. Other operations supplied by the `Field` instance are transferred from `ℚ`. In particular, rational scalar multiplication and negative integer powers may require propositional reasoning rather than `rfl`.

A. Definition

B. Arithmetic

C. Field structure

D. Definitional equality tests

53 declarations

instance

Decidable equality for `Exponent`

The definition provides a `DecidableEq` instance for the `Exponent` type, which represents the rational exponents used in dimensional analysis. This signifies that for any two dimension exponents x,yExponentx, y \in \text{Exponent}, there exists an algorithmic procedure to determine whether x=yx = y or xyx \neq y.

instance

String representation of a dimension exponent

The definition provides a `Repr` instance for the `Exponent` type, which is used for displaying dimension exponents. It specifies that the string representation of an `Exponent` value xx is obtained by applying the standard rational number representation to its underlying rational value x.toRatQx.\text{toRat} \in \mathbb{Q}.

definition

Equivalence `Exponent` Q\simeq \mathbb{Q}

This definition establishes a canonical equivalence (bijection) between the type `Exponent`, which represents the rational exponents used in dimensional analysis, and the set of rational numbers Q\mathbb{Q}. The equivalence is formed by the mapping of an `Exponent` to its underlying rational value and the corresponding inverse mapping.

definition

Conversion of qQq \in \mathbb{Q} to an `Exponent`

The function maps a rational number qQq \in \mathbb{Q} to its representation as a dimension exponent of type `Exponent`. This type is a wrapper around the rational numbers used to ensure that arithmetic on physical dimensions is computationally reducible.

theorem

toRat(ofRat(q))=q\text{toRat}(\text{ofRat}(q)) = q

For any rational number qQq \in \mathbb{Q}, converting qq to a dimension exponent (using the function `ofRat`) and then extracting the underlying rational value (using the function `toRat`) returns the original value qq. That is, toRat(ofRat(q))=q\text{toRat}(\text{ofRat}(q)) = q.

definition

Fuel-bounded Euclidean algorithm for GCD

The function `gcdAux` takes three natural numbers as arguments: a "fuel" parameter ff, and two integers mm and nn. It implements a fuel-bounded version of the Euclidean algorithm to compute the greatest common divisor (GCD) of mm and nn. Specifically: - If the fuel ff is 0, it returns nn. - If the fuel is f+1f + 1: - If m=0m = 0, it returns nn. - Otherwise, it recursively calls itself with fuel ff, the new first integer as n(modm)n \pmod m, and the new second integer as mm. This auxiliary function is used to ensure that the normalization of rational exponents in dimensional analysis is computationally reducible within Lean's kernel.

definition

Greatest common divisor gcd(m,n)\text{gcd}(m, n)

The function gcd(m,n)\text{gcd}(m, n) computes the greatest common divisor of two natural numbers mm and nn. It is implemented using a fuel-bounded Euclidean algorithm (calling `gcdAux` with a fuel parameter of m+1m + 1) to ensure the calculation is computationally reducible within Lean's kernel, which facilitates the normalization of rational dimension exponents.

theorem

`Dimension.Exponent.gcd` equals `Nat.gcd`

For any natural numbers mm and nn, the greatest common divisor gcd(m,n)\gcd(m, n) calculated using the specific implementation for dimension exponents (`Dimension.Exponent.gcd`) is equal to the standard greatest common divisor for natural numbers (`Nat.gcd`).

definition

Normalization of nZn \in \mathbb{Z} and dNd \in \mathbb{N} to a dimension exponent

The function `Dimension.Exponent.normalize` takes an integer numerator nZn \in \mathbb{Z}, a natural number denominator dNd \in \mathbb{N}, and a proof that d0d \neq 0. It returns a dimension exponent (of type `Exponent`) representing the rational number n/dn/d in its reduced form. This is achieved by dividing both nn and dd by their greatest common divisor gcd(n,d)\text{gcd}(|n|, d), utilizing a computationally reducible algorithm to facilitate definitional equality in dimensional analysis.

theorem

(normalize n d).toRat=Rat.normalize n d(\text{normalize } n \ d).\text{toRat} = \text{Rat.normalize } n \ d

For any integer nZn \in \mathbb{Z} and any natural number dNd \in \mathbb{N} such that d0d \neq 0, the rational value of the dimension exponent obtained via `Dimension.Exponent.normalize` is equal to the standard rational number obtained via `Rat.normalize`. That is, (normalize(n,d)).toRat=Rat.normalize(n,d)(\text{normalize}(n, d)).\text{toRat} = \text{Rat.normalize}(n, d).

definition

Normalized numerator of a dimension exponent xx

The function maps a dimension exponent xx to the normalized numerator nZn \in \mathbb{Z} of its underlying rational value.

definition

Denominator of a dimension exponent xx

For a dimension exponent xx, the function returns its normalized denominator dNd \in \mathbb{N} such that xx represents a rational number q=ndq = \frac{n}{d} in reduced form.

definition

Addition of dimension exponents aa and bb

For two dimension exponents aa and bb, represented as rational numbers nada\frac{n_a}{d_a} and nbdb\frac{n_b}{d_b} respectively, their sum is defined as the normalized dimension exponent corresponding to the rational number nadb+nbdadadb\frac{n_a d_b + n_b d_a}{d_a d_b}. This addition is implemented using a reducible algorithm to ensure that concrete calculations can be evaluated by definitional equality.

instance

Addition of dimension exponents a+ba + b

This definition provides the addition operation for the `Exponent` type, allowing the use of the symbol ++ to represent the sum of two dimension exponents aa and bb. The operation a+ba + b is defined by the `Dimension.Exponent.add` function, which performs rational addition in a way that ensures concrete calculations are reducible to definitional equality.

theorem

equivRat(a+b)=equivRat(a)+equivRat(b)\text{equivRat}(a + b) = \text{equivRat}(a) + \text{equivRat}(b)

For any dimension exponents aa and bb, let equivRat\text{equivRat} denote the canonical equivalence between the type of dimension exponents and the rational numbers Q\mathbb{Q}. The rational number corresponding to the sum of aa and bb is equal to the sum of the rational numbers corresponding to aa and bb individually, satisfying the relation equivRat(a+b)=equivRat(a)+equivRat(b)\text{equivRat}(a + b) = \text{equivRat}(a) + \text{equivRat}(b).

definition

Subtraction aba - b for dimension exponents aa and bb

For two dimension exponents aa and bb, which are represented as rational numbers, their difference aba - b is defined as the sum of aa and the negation of bb. This subtraction is implemented using a reducible algorithm to ensure that concrete calculations can be evaluated by definitional equality.

instance

Subtraction operator - for dimension exponents

This definition provides the subtraction operator - for the type `Exponent`, which represents dimension exponents. It allows for the notation aba - b for two dimension exponents aa and bb, utilizing the underlying reducible subtraction function `sub` specifically defined for this type.

theorem

equivRat(ab)=equivRat(a)equivRat(b)\text{equivRat}(a - b) = \text{equivRat}(a) - \text{equivRat}(b)

For any dimension exponents aa and bb, the rational number associated with their difference aba - b is equal to the difference of the rational numbers associated with aa and bb. That is, equivRat(ab)=equivRat(a)equivRat(b)\text{equivRat}(a - b) = \text{equivRat}(a) - \text{equivRat}(b), where equivRat\text{equivRat} is the canonical equivalence mapping between the type of dimension exponents and the rational numbers Q\mathbb{Q}.

definition

Multiplication of dimension exponents aba \cdot b

The function computes the product of two dimension exponents aa and bb. Given aa with numerator naZn_a \in \mathbb{Z} and denominator daNd_a \in \mathbb{N}, and bb with numerator nbZn_b \in \mathbb{Z} and denominator dbNd_b \in \mathbb{N}, the function returns the normalized dimension exponent representing the rational number nanbdadb\frac{n_a \cdot n_b}{d_a \cdot d_b}. This multiplication is implemented to be computationally reducible to support definitional equality in dimensional analysis.

instance

Multiplication of dimension exponents aba \cdot b

This instance defines the multiplication operation for dimension exponents. For any two exponents a,bExponenta, b \in \text{Exponent}, their product is denoted by aba \cdot b. This operation is implemented using a reducible form of rational multiplication to facilitate definitional equality in dimensional analysis calculations.

theorem

equivRat(ab)=equivRat(a)equivRat(b)\text{equivRat}(a \cdot b) = \text{equivRat}(a) \cdot \text{equivRat}(b)

Let aa and bb be dimension exponents, and let equivRat:ExponentQ\text{equivRat} : \text{Exponent} \simeq \mathbb{Q} be the canonical equivalence between the type of dimension exponents and the rational numbers. Then the rational value of the product of aa and bb is equal to the product of their individual rational values: equivRat(ab)=equivRat(a)equivRat(b)\text{equivRat}(a \cdot b) = \text{equivRat}(a) \cdot \text{equivRat}(b) where the multiplication on the left is the specific multiplication defined for dimension exponents and the multiplication on the right is the standard multiplication in Q\mathbb{Q}.

definition

Multiplicative inverse a1a^{-1} of a dimension exponent

The function computes the multiplicative inverse a1a^{-1} of a dimension exponent aa. If aa represents a non-zero rational number qq, the function returns the exponent corresponding to 1/q1/q. If a=0a = 0, the inverse is defined to be 00.

instance

Multiplicative inverse a1a^{-1} for dimension exponents

This definition provides the multiplicative inverse operation for dimension exponents. For any dimension exponent aa, its inverse a1a^{-1} is determined by the inverse of its underlying rational value, where the inverse of 00 is defined to be 00.

theorem

equivRat(inv a)=(equivRat a)1\text{equivRat}(\text{inv } a) = (\text{equivRat } a)^{-1} for Dimension Exponents

For any dimension exponent aa, let equivRat:ExponentQ\text{equivRat} : \text{Exponent} \to \mathbb{Q} be the equivalence mapping between dimension exponents and rational numbers. The rational number corresponding to the multiplicative inverse of aa is equal to the multiplicative inverse of the rational number corresponding to aa, i.e., equivRat(inv a)=(equivRat a)1\text{equivRat}(\text{inv } a) = (\text{equivRat } a)^{-1} where inv\text{inv} denotes the inverse operation on Exponent\text{Exponent} and 1^{-1} denotes the standard inverse on Q\mathbb{Q}.

definition

Division a/ba / b of dimension exponents

The function computes the division of two dimension exponents aa and bb, defined as the product ab1a \cdot b^{-1} of aa and the multiplicative inverse of bb.

instance

Division on `Exponent`

This instance provides the division operator a/ba / b for dimension exponents a,bExponenta, b \in \text{Exponent}.

theorem

equivRat(a/b)=equivRat(a)/equivRat(b)\text{equivRat}(a / b) = \text{equivRat}(a) / \text{equivRat}(b)

For any two dimension exponents a,bExponenta, b \in \text{Exponent}, let equivRat\text{equivRat} denote the canonical equivalence between the type `Exponent` (a wrapper for rational numbers used in dimensional analysis) and the rational numbers Q\mathbb{Q}. The division operation in `Exponent` is preserved under this equivalence, such that: equivRat(a/b)=equivRat(a)/equivRat(b)\text{equivRat}(a / b) = \text{equivRat}(a) / \text{equivRat}(b) where the division on the left is performed in `Exponent` and the division on the right is performed in Q\mathbb{Q}.

instance

`Exponent` forms a field

This definition establishes that the type `Exponent`, which represents dimension exponents, forms a field. The field structure is inherited from the rational numbers Q\mathbb{Q} through the canonical equivalence equivRat:ExponentQ\text{equivRat} : \text{Exponent} \simeq \mathbb{Q}. It ensures that the specific arithmetic operations—addition, subtraction, multiplication, inversion, and division—defined for `Exponent` satisfy the axioms of a field.

definition

Ring isomorphism Exponent+Q\text{Exponent} \simeq+* \mathbb{Q}

This definition establishes a ring isomorphism between the type of dimension exponents, Exponent\text{Exponent}, and the rational numbers, Q\mathbb{Q}. This isomorphism, denoted as Exponent+Q\text{Exponent} \simeq+* \mathbb{Q}, maps a dimension exponent to its underlying rational value while preserving the operations of addition and multiplication.

instance

Coercion from `Exponent` to Q\mathbb{Q}

This instance defines a canonical coercion from the type `Exponent` to the set of rational numbers Q\mathbb{Q}, which allows a dimension exponent to be regarded as a rational number.

theorem

Equality of Dimension Exponents a=b    (a:Q)=(b:Q)a = b \iff (a : \mathbb{Q}) = (b : \mathbb{Q})

Let Exponent\text{Exponent} be a type representing dimension exponents, which is a wrapper around the rational numbers Q\mathbb{Q}. For any two exponents a,bExponenta, b \in \text{Exponent}, their coerced rational values in Q\mathbb{Q} are equal if and only if aa and bb are equal.

theorem

The coercion of 0Exponent0 \in \text{Exponent} to Q\mathbb{Q} is 00

The zero element of the type Exponent\text{Exponent}, which represents dimension exponents, is equal to the rational number 00 when coerced to Q\mathbb{Q}.

theorem

Coercion from `Exponent` to Q\mathbb{Q} preserves 11

The coercion of the dimension exponent 11 to a rational number is equal to the rational number 11.

theorem

Coercion from `Exponent` to Q\mathbb{Q} preserves natural numbers n2n \ge 2

For any natural number n2n \ge 2, the coercion of nn (when treated as a dimension exponent) to the rational numbers Q\mathbb{Q} is equal to the natural number nn as a rational number.

theorem

Coercion from `Exponent` to Q\mathbb{Q} preserves addition

For any two dimension exponents aa and bb, the coercion of their sum a+ba + b to a rational number is equal to the sum of their individual rational coercions.

theorem

(ab:Q)=ab(a - b : \mathbb{Q}) = a - b for dimension exponents

For any two dimension exponents aa and bb, the coercion of their difference aba - b to a rational number is equal to the subtraction of their values as rational numbers in Q\mathbb{Q}.

theorem

Coercion from `Exponent` to Q\mathbb{Q} preserves negation

For any dimension exponent aa, the coercion of its negation a-a to a rational number is equal to the negation of the rational number corresponding to aa, expressed as (a:Q)=(a:Q)(-a : \mathbb{Q}) = -(a : \mathbb{Q}).

theorem

(ab:Q)=ab(a \cdot b : \mathbb{Q}) = a \cdot b for dimension exponents

For any two dimension exponents aa and bb, the rational number obtained by coercing their product aba \cdot b is equal to the product of their values when viewed as rational numbers in Q\mathbb{Q}.

theorem

(a1:Q)=(a:Q)1(a^{-1} : \mathbb{Q}) = (a : \mathbb{Q})^{-1}

For any dimension exponent aa, the rational number corresponding to the inverse a1a^{-1} is equal to the multiplicative inverse of the rational number corresponding to aa, written as (a1:Q)=(a:Q)1(a^{-1} : \mathbb{Q}) = (a : \mathbb{Q})^{-1}.

theorem

(a/b:Q)=(a:Q)/(b:Q)(a / b : \mathbb{Q}) = (a : \mathbb{Q}) / (b : \mathbb{Q}) for dimension exponents

For any dimension exponents aa and bb, the rational number corresponding to their quotient a/ba / b is equal to the quotient of the rational numbers corresponding to aa and bb, written as (a/b:Q)=(a:Q)/(b:Q)(a / b : \mathbb{Q}) = (a : \mathbb{Q}) / (b : \mathbb{Q}).

instance

Linear order on `Exponent`

This definition equips the type `Exponent`, which represents the rational exponents used in dimensional analysis, with a linear order structure. This order is induced by the standard linear order on the rational numbers Q\mathbb{Q} via the canonical equivalence ExponentQ\text{Exponent} \simeq \mathbb{Q}, meaning that for any a,bExponenta, b \in \text{Exponent}, aba \leq b holds if and only if their corresponding rational values satisfy the relation in Q\mathbb{Q}.

theorem

ab    (a:Q)(b:Q)a \le b \iff (a : \mathbb{Q}) \le (b : \mathbb{Q}) for dimension exponents

Let aa and bb be elements of the type `Exponent`, which represents rational exponents used in dimensional analysis. The inequality aba \leq b holds in the `Exponent` type if and only if their corresponding rational values in Q\mathbb{Q} satisfy the inequality (a:Q)(b:Q)(a : \mathbb{Q}) \leq (b : \mathbb{Q}).

theorem

a<b    (a:Q)<(b:Q)a < b \iff (a : \mathbb{Q}) < (b : \mathbb{Q})

For any two dimension exponents a,bExponenta, b \in \text{Exponent}, the strict inequality a<ba < b holds if and only if their corresponding rational values in Q\mathbb{Q} satisfy (a:Q)<(b:Q)(a : \mathbb{Q}) < (b : \mathbb{Q}).

instance

`Exponent` is a strictly ordered ring

The type `Exponent`, which represents dimension exponents as a wrapper around the rational numbers Q\mathbb{Q}, forms a strictly ordered ring. This means that the ring operations are compatible with the linear order; specifically, for any a,b,cExponenta, b, c \in \text{Exponent}, if a<ba < b then a+c<b+ca + c < b + c, and if 0<a0 < a and 0<b0 < b then 0<ab0 < a \cdot b.

instance

`Exponent` has characteristic zero

The type `Exponent`, which represents dimension exponents, has characteristic zero. This means that the canonical ring homomorphism from the natural numbers N\mathbb{N} to `Exponent` is injective; in other words, for any natural number nn, the sum of nn copies of the multiplicative identity 11 in `Exponent` is zero if and only if n=0n = 0.

theorem

`add` equals field addition for `Exponent`

The custom addition operation `add` defined for the `Exponent` type is equal to the addition operation provided by the field instance on `Exponent`.

theorem

sub\text{sub} equals the field instance subtraction for Exponent\text{Exponent}

The custom subtraction operation sub\text{sub} defined for the type of dimension exponents Exponent\text{Exponent} is equal to the subtraction operation provided by the field instance structure instField\text{instField} of Exponent\text{Exponent}.

theorem

The multiplicative inverse of `Exponent` coincides with its field inverse

For the type `Exponent` representing dimension exponents, the specifically defined multiplicative inverse function `inv` is equal to the inverse operation provided by its `Field` instance.

theorem

mul=instField.mul\text{mul} = \text{instField.mul} for dimension exponents

On the type of dimension exponents Exponent\text{Exponent}, the custom multiplication operation mul\text{mul} is equal to the multiplication operation provided by the field structure instance instField\text{instField} on Exponent\text{Exponent}.

theorem

div=instField.div\text{div} = \text{instField.div} for dimension exponents

The custom division operation on the type Exponent\text{Exponent} (dimension exponents), denoted as div\text{div}, is equal to the division operation provided by the field structure (instField\text{instField}) of the Exponent\text{Exponent} type.

theorem

Length=Time+Speed\text{Length} = \text{Time} + \text{Speed} for Tuples of Dimension Exponents

Let Length=(1,0)\text{Length} = (1, 0) and Time=(0,1)\text{Time} = (0, 1) be elements of the product space Exponent×Exponent\text{Exponent} \times \text{Exponent}, where Exponent\text{Exponent} represents dimension exponents (rationals with reducible arithmetic). If we define Speed=LengthTime\text{Speed} = \text{Length} - \text{Time}, then the following equality holds: Length=Time+Speed\text{Length} = \text{Time} + \text{Speed}.

theorem

(23+57)(111312)=87182\left( \frac{2}{3} + \frac{5}{7} \right) \cdot \left( \frac{11}{13} - \frac{1}{2} \right) = \frac{87}{182} in `Exponent`

For the type `Exponent`, which represents dimension exponents as rational numbers, the following arithmetic equality holds: (23+57)(111312)=87182 \left( \frac{2}{3} + \frac{5}{7} \right) \cdot \left( \frac{11}{13} - \frac{1}{2} \right) = \frac{87}{182}

theorem

(3/4)1+5/6=1/2(-3/4)^{-1} + 5/6 = -1/2 in `Exponent`

In the type `Exponent`, which represents rational numbers used for physical dimension exponents, the following arithmetic identity holds: (3/4)1+5/6=1/2(-3/4)^{-1} + 5/6 = -1/2.