The canonical bits of a number #
DataEncode writes a natural number as Nat.bits, its little-endian bits with
no trailing zero. A fixed-width counter, which is what a polynomial-time machine
can produce, carries trailing zeros; dropping them is the missing step between
the two.
Dropping trailing zeros is a right fold — what to do with a bit depends on
whether everything after it vanished — so recFoldClamp expresses it directly,
with no reversal.
Main definitions #
Complexity.stripTrailing— drop trailing zeros
Main results #
Complexity.stripTrailing_eq_bits— the result isNat.bitsof the valueComplexity.stripTrailing_mem_FP— it is polynomial time
Drop trailing zeros from a little-endian bit string.
Equations
Instances For
Dropping trailing zeros gives the canonical bits.
Polynomial time #
The fold step on a zero.
Equations
Instances For
The fold step on a one.
Equations
Instances For
theorem
Complexity.recFoldClamp_stripTrailing
(bound : ℕ)
(W l : List Bool)
:
l.length ≤ bound → Cobham.recFoldClamp stripZero stripOne bound [] W l = stripTrailing l
The fold computes stripTrailing, as long as the clamp allows the answer.
Dropping trailing zeros, on pair anything bits.