Data as a primcodable type #
Data is denumerable through Cantor pairing (Data.encodeNat/Data.decodeNat), hence
Primcodable, with primitive recursive constructor, projections, a tree-recursion
principle (Data.primrec_recD), unary numerals, list indexing and the decoders of bit
strings. This is the interface between the ambient model and Mathlib's computability
(Cost/Partrec.lean): everything the model manipulates is Data — programs included,
through Prog.toData — so no separate encoding of Prog is needed.
Data ≃ ℕ #
Data ≃ ℕ.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Primitive recursive constructor and projections #
The head of a pair (nil on nil).
Equations
- MIPRE.Cost.Data.nil.left = MIPRE.Cost.Data.nil
- (a.cons b).left = a
Instances For
The tail of a pair (nil on nil).
Equations
Instances For
Case analysis on Data, primitive recursively.
Tree recursion #
Structural recursion on Data with a first-order result.
Equations
- MIPRE.Cost.Data.recD base step MIPRE.Cost.Data.nil = base
- MIPRE.Cost.Data.recD base step (a.cons b) = step a b (MIPRE.Cost.Data.recD base step a) (MIPRE.Cost.Data.recD base step b)
Instances For
Tree recursion is primitive recursive (through the pairing encoding, structural
recursion on Data is strong recursion on ℕ).
Unary numerals and list indexing #
The length of the right spine: reads a unary numeral (unaryToNat (ofNat n) = n).
Equations
- MIPRE.Cost.Data.unaryToNat = MIPRE.Cost.Data.recD 0 fun (x x_1 : MIPRE.Cost.Data) (x_2 rb : ℕ) => rb + 1
Instances For
Decoding bit strings #
Decoding bit strings from Data is primitive recursive.
Encoding naturals #
The companion of primrec_decode_bitStr in the other direction. A natural is encoded as the
bit string of Nat.bits, so its encoding satisfies the halving recursion below, and strong
recursion on ℕ turns that into a primitive recursive definition. Every budgeted run of the
tabulation feeds the machine an encode (n, …), so this is on the critical path of
MIPRE.Halting.tab_computable.
Encoding a natural as data is primitive recursive.
Two small gaps in the ambient library #
Exponentiation is primitive recursive. Mathlib has Nat.Primrec.pow on the unpaired
form but no Primrec₂ spelling.
Two LawfulBEq instances give the same List.idxOf. List Bool has its own BEq, while
Mathlib's Primrec.list_idxOf is stated at the one derived from DecidableEq; the two are
propositionally equal, but reducing them to a common normal form sends whnf a very long way
indeed, so the bridge is proved once, here, rather than left to unification.
The index of a bit string in a list of bit strings, at the instance the enumerations of
Halting/Enumerate.lean actually elaborate to.