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
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 , there exists an algorithmic procedure to determine whether or .
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 is obtained by applying the standard rational number representation to its underlying rational value .
Equivalence `Exponent`
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 . The equivalence is formed by the mapping of an `Exponent` to its underlying rational value and the corresponding inverse mapping.
Conversion of to an `Exponent`
The function maps a rational number 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.
For any rational number , converting to a dimension exponent (using the function `ofRat`) and then extracting the underlying rational value (using the function `toRat`) returns the original value . That is, .
Fuel-bounded Euclidean algorithm for GCD
The function `gcdAux` takes three natural numbers as arguments: a "fuel" parameter , and two integers and . It implements a fuel-bounded version of the Euclidean algorithm to compute the greatest common divisor (GCD) of and . Specifically: - If the fuel is 0, it returns . - If the fuel is : - If , it returns . - Otherwise, it recursively calls itself with fuel , the new first integer as , and the new second integer as . This auxiliary function is used to ensure that the normalization of rational exponents in dimensional analysis is computationally reducible within Lean's kernel.
Greatest common divisor
The function computes the greatest common divisor of two natural numbers and . It is implemented using a fuel-bounded Euclidean algorithm (calling `gcdAux` with a fuel parameter of ) to ensure the calculation is computationally reducible within Lean's kernel, which facilitates the normalization of rational dimension exponents.
`Dimension.Exponent.gcd` equals `Nat.gcd`
For any natural numbers and , the greatest common divisor calculated using the specific implementation for dimension exponents (`Dimension.Exponent.gcd`) is equal to the standard greatest common divisor for natural numbers (`Nat.gcd`).
Normalization of and to a dimension exponent
The function `Dimension.Exponent.normalize` takes an integer numerator , a natural number denominator , and a proof that . It returns a dimension exponent (of type `Exponent`) representing the rational number in its reduced form. This is achieved by dividing both and by their greatest common divisor , utilizing a computationally reducible algorithm to facilitate definitional equality in dimensional analysis.
For any integer and any natural number such that , 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, .
Normalized numerator of a dimension exponent
The function maps a dimension exponent to the normalized numerator of its underlying rational value.
Denominator of a dimension exponent
For a dimension exponent , the function returns its normalized denominator such that represents a rational number in reduced form.
Addition of dimension exponents and
For two dimension exponents and , represented as rational numbers and respectively, their sum is defined as the normalized dimension exponent corresponding to the rational number . This addition is implemented using a reducible algorithm to ensure that concrete calculations can be evaluated by definitional equality.
Addition of dimension exponents
This definition provides the addition operation for the `Exponent` type, allowing the use of the symbol to represent the sum of two dimension exponents and . The operation is defined by the `Dimension.Exponent.add` function, which performs rational addition in a way that ensures concrete calculations are reducible to definitional equality.
For any dimension exponents and , let denote the canonical equivalence between the type of dimension exponents and the rational numbers . The rational number corresponding to the sum of and is equal to the sum of the rational numbers corresponding to and individually, satisfying the relation .
Subtraction for dimension exponents and
For two dimension exponents and , which are represented as rational numbers, their difference is defined as the sum of and the negation of . This subtraction is implemented using a reducible algorithm to ensure that concrete calculations can be evaluated by definitional equality.
Subtraction operator for dimension exponents
This definition provides the subtraction operator for the type `Exponent`, which represents dimension exponents. It allows for the notation for two dimension exponents and , utilizing the underlying reducible subtraction function `sub` specifically defined for this type.
For any dimension exponents and , the rational number associated with their difference is equal to the difference of the rational numbers associated with and . That is, , where is the canonical equivalence mapping between the type of dimension exponents and the rational numbers .
Multiplication of dimension exponents
The function computes the product of two dimension exponents and . Given with numerator and denominator , and with numerator and denominator , the function returns the normalized dimension exponent representing the rational number . This multiplication is implemented to be computationally reducible to support definitional equality in dimensional analysis.
Multiplication of dimension exponents
This instance defines the multiplication operation for dimension exponents. For any two exponents , their product is denoted by . This operation is implemented using a reducible form of rational multiplication to facilitate definitional equality in dimensional analysis calculations.
Let and be dimension exponents, and let be the canonical equivalence between the type of dimension exponents and the rational numbers. Then the rational value of the product of and is equal to the product of their individual rational values: 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 .
Multiplicative inverse of a dimension exponent
The function computes the multiplicative inverse of a dimension exponent . If represents a non-zero rational number , the function returns the exponent corresponding to . If , the inverse is defined to be .
Multiplicative inverse for dimension exponents
This definition provides the multiplicative inverse operation for dimension exponents. For any dimension exponent , its inverse is determined by the inverse of its underlying rational value, where the inverse of is defined to be .
for Dimension Exponents
For any dimension exponent , let be the equivalence mapping between dimension exponents and rational numbers. The rational number corresponding to the multiplicative inverse of is equal to the multiplicative inverse of the rational number corresponding to , i.e., where denotes the inverse operation on and denotes the standard inverse on .
Division of dimension exponents
The function computes the division of two dimension exponents and , defined as the product of and the multiplicative inverse of .
Division on `Exponent`
This instance provides the division operator for dimension exponents .
For any two dimension exponents , let denote the canonical equivalence between the type `Exponent` (a wrapper for rational numbers used in dimensional analysis) and the rational numbers . The division operation in `Exponent` is preserved under this equivalence, such that: where the division on the left is performed in `Exponent` and the division on the right is performed in .
`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 through the canonical equivalence . It ensures that the specific arithmetic operations—addition, subtraction, multiplication, inversion, and division—defined for `Exponent` satisfy the axioms of a field.
Ring isomorphism
This definition establishes a ring isomorphism between the type of dimension exponents, , and the rational numbers, . This isomorphism, denoted as , maps a dimension exponent to its underlying rational value while preserving the operations of addition and multiplication.
Coercion from `Exponent` to
This instance defines a canonical coercion from the type `Exponent` to the set of rational numbers , which allows a dimension exponent to be regarded as a rational number.
Equality of Dimension Exponents
Let be a type representing dimension exponents, which is a wrapper around the rational numbers . For any two exponents , their coerced rational values in are equal if and only if and are equal.
The coercion of to is
The zero element of the type , which represents dimension exponents, is equal to the rational number when coerced to .
Coercion from `Exponent` to preserves
The coercion of the dimension exponent to a rational number is equal to the rational number .
Coercion from `Exponent` to preserves natural numbers
For any natural number , the coercion of (when treated as a dimension exponent) to the rational numbers is equal to the natural number as a rational number.
Coercion from `Exponent` to preserves addition
For any two dimension exponents and , the coercion of their sum to a rational number is equal to the sum of their individual rational coercions.
for dimension exponents
For any two dimension exponents and , the coercion of their difference to a rational number is equal to the subtraction of their values as rational numbers in .
Coercion from `Exponent` to preserves negation
For any dimension exponent , the coercion of its negation to a rational number is equal to the negation of the rational number corresponding to , expressed as .
for dimension exponents
For any two dimension exponents and , the rational number obtained by coercing their product is equal to the product of their values when viewed as rational numbers in .
For any dimension exponent , the rational number corresponding to the inverse is equal to the multiplicative inverse of the rational number corresponding to , written as .
for dimension exponents
For any dimension exponents and , the rational number corresponding to their quotient is equal to the quotient of the rational numbers corresponding to and , written as .
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 via the canonical equivalence , meaning that for any , holds if and only if their corresponding rational values satisfy the relation in .
for dimension exponents
Let and be elements of the type `Exponent`, which represents rational exponents used in dimensional analysis. The inequality holds in the `Exponent` type if and only if their corresponding rational values in satisfy the inequality .
For any two dimension exponents , the strict inequality holds if and only if their corresponding rational values in satisfy .
`Exponent` is a strictly ordered ring
The type `Exponent`, which represents dimension exponents as a wrapper around the rational numbers , forms a strictly ordered ring. This means that the ring operations are compatible with the linear order; specifically, for any , if then , and if and then .
`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 to `Exponent` is injective; in other words, for any natural number , the sum of copies of the multiplicative identity in `Exponent` is zero if and only if .
`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`.
equals the field instance subtraction for
The custom subtraction operation defined for the type of dimension exponents is equal to the subtraction operation provided by the field instance structure of .
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.
for dimension exponents
On the type of dimension exponents , the custom multiplication operation is equal to the multiplication operation provided by the field structure instance on .
for dimension exponents
The custom division operation on the type (dimension exponents), denoted as , is equal to the division operation provided by the field structure () of the type.
for Tuples of Dimension Exponents
Let and be elements of the product space , where represents dimension exponents (rationals with reducible arithmetic). If we define , then the following equality holds: .
in `Exponent`
For the type `Exponent`, which represents dimension exponents as rational numbers, the following arithmetic equality holds:
in `Exponent`
In the type `Exponent`, which represents rational numbers used for physical dimension exponents, the following arithmetic identity holds: .
