Fixed-length radix arithmetic #
These lemmas use Mathlib's Nat.ofDigits and finFunctionFinEquiv to relate fixed tuples
of digits, exact carry equations, and ordinary natural-number values. No modular overflow is
implicit in a carry equation.
Main definitions #
Cslib.Radix.digit: recursive fixed-position digit extraction.Cslib.Radix.pack: little-endian finite-tuple packing with a fixed enumeration.Cslib.Radix.component: extraction using the same finite-tuple enumeration.
Main results #
Nat.ofDigits_ofFn_eq_sum: fixed tuples have the usual weighted value.Nat.exists_ofDigits_ofFn: every value below the fixed capacity has bounded digits.Nat.radix_carry_split: one exact low-digit equation and its remaining carry.Cslib.Radix.component_pack,Cslib.Radix.pack_lt: recovery and capacity for tuples indexed by any fixed finite type, independently of a machine or resource model.finFunctionFinEquiv_snoc,finFunctionFinEquiv_eq_of_high_zero,finFunctionFinEquiv_lt_pow_iff,finFunctionFinEquiv_lt_iff: highest-digit splitting, zero high digits, power bounds, and colexicographic order forfinFunctionFinEquiv.
References #
The application to full-tuple numeric predicates follows [Imm99], Exercise 1.33(3).
All suffix quotients of a word are bounded by its whole value.
Read a digit by repeatedly dividing by the radix. This is total even at radix zero.
Instances For
Pack a finite tuple in little-endian order using the fixed Fintype.equivFin enumeration.
The enumeration is independent of the radix and tuple values.
Instances For
finFunctionFinEquiv order and prefix lemmas #
Separate the highest-weight digit (x (Fin.last k) : ℕ) * n ^ k of finFunctionFinEquiv x.
When all coordinates of x : Fin k → Fin n at indices ≥ a are zero, finFunctionFinEquiv x
has the same value as its prefix of length a.
For a ≤ k, a k-tuple has finFunctionFinEquiv value < n ^ a iff all coordinates at
indices ≥ a are zero.
The numerical order on finFunctionFinEquiv is the colexicographic order on Fin k → Fin n
(comparing at the most significant coordinate where the tuples differ).