Documentation

Complexitylib.Encoding.BinaryNat

Canonical variable-width binary natural-number codes #

This module packages Nat.bits as a canonical binary code for natural numbers. Bits are ordered least-significant first, and redundant high zeroes are rejected. In particular, zero has the unique empty code.

Unlike a prefix code, this representation relies on an enclosing framing layer to determine the field boundary. Complexitylib.Encoding.Pairing provides that framing for variable-length machine inputs.

Encode a natural by its minimal little-endian binary expansion.

Equations
Instances For

    Decode a natural only when the supplied bits are its minimal expansion.

    This rejects every redundant high-zero representation, making encode and decode? an exact codec rather than merely a value interpretation.

    Equations
    Instances For
      @[simp]

      Canonical binary codes have exactly the standard binary digit width.

      @[simp]

      Decoding a canonical binary code recovers its value.

      theorem Complexity.BinaryNatCode.decode?_eq_some_iff (bits : List Bool) (value : ) :
      decode? bits = some value bits = encode value

      Exact decoding succeeds precisely on the canonical code of the result.

      The canonical binary natural-number encoding is injective.