Synchronous finite-row numerals #
This file supplies small, reusable finite-state verifiers for counters stored across a row.
Digits are written least significant first, so carry propagation is checked in one
left-to-right sweep, exactly the direction used by CertifiedRowSystem.
The digit order is made explicit by a DigitCodec. This keeps the scanners independent of a
particular order instance; orderedCodec supplies the canonical increasing codec for every
finite linear order.
A numbering of a finite digit type by 0, ..., card D - 1.
Instances For
The canonical increasing numbering of a finite linearly ordered digit type.
Equations
- RowNumeral.orderedCodec D = { toFin := (monoEquivOfFin D ⋯).symm.toEquiv }
Instances For
The next digit, or none at the greatest digit.
Equations
Instances For
The all-zero row of a given width.
Equations
- E.zeroRow width = List.replicate width E.zero
Instances For
Cellwise zero and copy checks #
One cell of an all-zero check. false is an absorbing failure state.
Instances For
One cell of a synchronous equality/copy check.
Instances For
Equations
- RowNumeral.instFintypeOneState = { elems := { val := ↑RowNumeral.OneState.enumList, nodup := RowNumeral.OneState.enumList_nodup }, complete := RowNumeral.instFintypeOneState._proof_1 }
Equations
- RowNumeral.instReprOneState = { reprPrec := RowNumeral.instReprOneState.repr }
Equations
- RowNumeral.instReprOneState.repr RowNumeral.OneState.first prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RowNumeral.OneState.first")).group prec✝
- RowNumeral.instReprOneState.repr RowNumeral.OneState.rest prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RowNumeral.OneState.rest")).group prec✝
- RowNumeral.instReprOneState.repr RowNumeral.OneState.bad prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RowNumeral.OneState.bad")).group prec✝
Instances For
Check one digit of the canonical positive-width numeral one.
Equations
Instances For
Run a copy/equality checker over two rows; a length mismatch rejects.
Equations
Instances For
Run the canonical-one checker. The empty row rejects.
Instances For
Synchronous successor #
State of the one-pass successor verifier.
- carry : CarryState
- done : CarryState
- bad : CarryState
Instances For
Equations
- RowNumeral.instFintypeCarryState = { elems := { val := ↑RowNumeral.CarryState.enumList, nodup := RowNumeral.CarryState.enumList_nodup }, complete := RowNumeral.instFintypeCarryState._proof_1 }
Equations
- One or more equations did not get rendered due to their size.
- RowNumeral.instReprCarryState.repr RowNumeral.CarryState.bad prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "RowNumeral.CarryState.bad")).group prec✝
Instances For
Equations
Check one aligned pair of digits while propagating a carry from left to right.
Equations
- One or more equations did not get rendered due to their size.
- E.succStep RowNumeral.CarryState.bad x✝¹ x✝ = RowNumeral.CarryState.bad
- E.succStep RowNumeral.CarryState.done x✝¹ x✝ = if x✝ = x✝¹ then RowNumeral.CarryState.done else RowNumeral.CarryState.bad
Instances For
Run the synchronous successor verifier; a length mismatch rejects.
Equations
Instances For
Increment an LSD-first row, returning an overflow bit.
Equations
Instances For
Overflow occurs exactly at the all-greatest digit row.
A successful non-overflowing scan is exactly canonical row successor.
A carry remaining after the last cell is exactly canonical overflow.
Synchronous comparison #
The scan still runs from least to most significant digit. A newly read unequal digit is more significant than everything seen before, so it replaces the accumulated ordering.
Compare one aligned pair during an LSD-first scan.
Equations
- E.compareStep q x y = match compare (E.digitValue x) (E.digitValue y) with | Ordering.eq => q | q' => q'
Instances For
Run the synchronous comparison scan; a length mismatch rejects.
Equations
- E.evalCompare x✝ [] [] = some x✝
- E.evalCompare x✝ (x_3 :: xs) (y :: ys) = E.evalCompare (E.compareStep x✝ x_3 y) xs ys
- E.evalCompare x✝² x✝¹ x✝ = none
Instances For
Canonical LSD-first comparison of two rows.
Equations
- E.compareRows xs ys = E.evalCompare Ordering.eq xs ys
Instances For
Equality result of the synchronous comparison.
Equations
- E.rowsEqual xs ys = (E.compareRows xs ys = some Ordering.eq)
Instances For
Strict less-than result of the synchronous comparison.
Equations
- E.rowsLess xs ys = (E.compareRows xs ys = some Ordering.lt)