Documentation

MIPRE.Foundations.Cost.Codable

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 as natural numbers through Cantor pairing: nil ↦ 0, cons a b ↦ pair a b + 1.

Equations
Instances For

    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
      Instances For

        The tail of a pair (nil on nil).

        Equations
        Instances For
          @[simp]
          theorem MIPRE.Cost.Data.left_cons (a b : Data) :
          (a.cons b).left = a
          @[simp]
          theorem MIPRE.Cost.Data.right_cons (a b : Data) :
          (a.cons b).right = b
          theorem MIPRE.Cost.Data.primrec_ite_nil {α : Type u_1} {σ : Type u_2} [Primcodable α] [Primcodable σ] {f : αData} {g : ασ} {h : αDataDataσ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec fun (p : α × Data × Data) => h p.1 p.2.1 p.2.2) :
          Primrec fun (a : α) => if f a = nil then g a else h a (f a).left (f a).right

          Case analysis on Data, primitive recursively.

          Tree recursion #

          def MIPRE.Cost.Data.recD {σ : Type u_1} (base : σ) (step : DataDataσσσ) :
          Dataσ

          Structural recursion on Data with a first-order result.

          Equations
          Instances For
            @[simp]
            theorem MIPRE.Cost.Data.recD_nil {σ : Type u_1} (base : σ) (step : DataDataσσσ) :
            recD base step nil = base
            @[simp]
            theorem MIPRE.Cost.Data.recD_cons {σ : Type u_1} (base : σ) (step : DataDataσσσ) (a b : Data) :
            recD base step (a.cons b) = step a b (recD base step a) (recD base step b)
            theorem MIPRE.Cost.Data.primrec_recD {σ : Type u_1} [Primcodable σ] [Inhabited σ] (base : σ) (step : DataDataσσσ) (hstep : Primrec fun (p : (Data × Data) × σ × σ) => step p.1.1 p.1.2 p.2.1 p.2.2) :
            Primrec (recD base step)

            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
            Instances For

              The n-th element of a cons-chain (nil beyond the end).

              Equations
              Instances For

                Decoding bit strings #

                theorem MIPRE.Cost.Data.toList?_eq_recD {α : Type u_1} (g : DataOption α) (d : Data) :
                toList? g d = recD (some []) (fun (a x : Data) (x_1 rb : Option (List α)) => (g a).bind fun (x : α) => Option.map (fun (x_2 : List α) => x :: x_2) rb) d
                theorem MIPRE.Cost.Data.primrec_toList? {α : Type u_1} [Primcodable α] {g : DataOption α} (hg : Primrec g) :

                Decoding bit strings from Data is primitive recursive.