Bit-strings as naturals, and their primitive recursiveness #
The bijection between bit-strings and natural numbers, and the computability of the layer built on it.
What this establishes #
bitsToNat,natToBits: a bit-string/natural bijection,[] ↦ 0.natToBits,bitsToNatarePrimrec: a fuel-bounded reformulation ofnatToBitsfittingPrimrec.nat_iterate, bridged to the well-founded definition bynatToBitsFuel_eq.- The prefix relation on bit-strings is a
PrimrecRel(primrec_isPrefix), and so is list membership (primrec_mem_list).
What this does NOT establish (flagged) #
- The bijection's two inverse laws and its length law live with the prefix machine in
AIT/PrefixMachine.lean, which imports this module.
A bit-string / natural bijection #
Bit-strings as naturals, most-significant-bit first: the number whose binary digits are
1 :: p, less one. [] ↦ 0.
Equations
- PrefixMachine.bitsToNat p = List.foldl (fun (acc : ℕ) (b : Bool) => 2 * acc + b.toNat) 1 p - 1
Instances For
@[irreducible]
The inverse of bitsToNat: the bits of n + 1, most-significant-bit first, with the leading
1 dropped. Well-founded recursion, peeling the low bit at each step.
Equations
Instances For
One step of peeling natToBits's low bit: idle once the state has bottomed out at 0,
otherwise move to the smaller state and cons the peeled bit onto the accumulator.
Equations
Instances For
Prefix of one bit-string by another: p <+: q ↔ List.take p.length q = p.
List membership is a PrimrecRel.