Canonical enumeration of fixed-width finite rows #
RowNumeral implements least-significant-digit-first counters and their synchronous
finite-state verifiers. This file supplies their arithmetic semantics. A row of
length n over a finite alphabet A has a unique rank below |A| ^ n; starting at
the zero row and repeatedly applying fixed-width increment visits every such row
exactly once before overflowing.
The final section chooses a codec for Option A. Its radix is |A| + 1, so on every
positive-width input it has room for the endpoint |A| ^ n as well as all smaller
row ranks. These are the fuel and depth counters used by the linear-space
inductive-counting verifier.
A choice-free-at-use-site digit codec for any finite type. Unlike
orderedCodec, this does not require the caller to install a LinearOrder; the
noncomputable choice is made once when the verifier is constructed.
Equations
- RowNumeral.fintypeCodec D = { toFin := Fintype.equivFin D }
Instances For
Rank bounds and uniqueness #
Greatest row and increment arithmetic #
The all-greatest-digit row of a fixed width.
Equations
- E.lastRow width = List.replicate width E.last
Instances For
The rank of fixed-width increment: on overflow it wraps to zero, otherwise it is the old rank plus one.
Canonical fixed-width enumeration #
Every value below radix ^ width is represented by the corresponding iterate
of fixed-width successor from zero.
Equality of two in-range enumeration positions forces equality of their ranks.
A fixed-width row occurs at a unique in-range enumeration position.
At an in-range enumeration position, the following increment overflows exactly when that position is the final rank.
Equivalently, another nonoverflowing enumeration step exists exactly before the last rank.
The canonical list of every row of one width, in increasing numeric rank.
Equations
Instances For
The canonical enumeration has no duplicate rows.
Membership in the canonical enumeration is exactly having the specified length.
Correctness of synchronous row comparison #
General comparison invariant: the already-scanned ordering matters exactly when the remaining (more-significant) suffixes have equal value.
Equality variant of the general comparison invariant.
The synchronous comparison reports strict inequality exactly when the numeric ranks are strictly ordered.
The synchronous comparison reports equality exactly when the numeric ranks are equal (for equal-length rows).
Boolean scanner acceptance predicates #
Boolean acceptance predicate for a nonoverflowing synchronous successor scan.
Equations
- E.checkSucc old new = decide (E.evalSucc RowNumeral.CarryState.carry old new = some RowNumeral.CarryState.done)
Instances For
Boolean acceptance predicate for value xs ≤ value ys. A length mismatch is
rejected because neither comparison result can be produced.
Equations
- E.checkLE xs ys = decide (E.compareRows xs ys = some Ordering.lt ∨ E.compareRows xs ys = some Ordering.eq)
Instances For
The canonical fuel codec. The extra none digit raises its radix from |A|
to |A| + 1, independently of how the Fintype instance orders the digits.
Equations
Instances For
Pure cardinal-arithmetic form of the fuel-capacity bound.
Every number up to and including the number of width-n rows over A fits in
the width-n base-Option A fuel counter.
Concrete count-row form of exists_fuelRow_of_le_rowCapacity.