Fixed-width binary encodings of natural numbers #
Big-endian, fixed-width binary encoding Nat.toBits with its exact decoder
Nat.fromBits, plus the little-endian views Nat.toBitsLE and
Nat.fromBitsLE used by local Turing-machine arithmetic. Both conventions
have exact length, truncation, round-trip, and fixed-width injectivity lemmas.
Values wider than the target width are truncated modulo 2 ^ w.
This file lives in Complexitylib/Mathlib/ because it extends a Mathlib
type in its home (root) namespace — the sanctioned exception to the
Complexity root-namespace rule. Its contents are candidates for
upstreaming to Mathlib.
Nat.fromBits is a left inverse of Nat.toBits on values below 2 ^ w.
Decode a little-endian bit list.
Equations
- Nat.fromBitsLE bits = Nat.fromBits bits.reverse
Instances For
Little-endian decoding of a fixed-width encoding truncates modulo 2^width.
Little-endian encoding exactly round-trips values that fit the width.
Every little-endian list is recovered at its own fixed width.
A little-endian list decodes below 2 raised to its width.
Little-endian decoding is injective at a fixed width.
Decoding the canonical variable-width little-endian bits recovers the original natural number.