Documentation

MIPRE.Foundations.Cost.Encoding

Size-aware encodings #

Interface between ordinary types and the ambient model: a SizedEncoding α renders a : α as a value encode a : Data, and esize a is its size (the length of its preorder serialization Data.toBits), an honest bit-length up to a constant factor. All polynomial-time statements (Cost.PolyTime) are relative to these encodings.

Conventions:

This deliberately does not reuse Mathlib's Encodable/Primcodable: those encode into ℕ via the quadratic pairing Nat.pair, whose iterated use distorts lengths exponentially.

class MIPRE.Cost.SizedEncoding (α : Type u_1) :
Type u_1

A size-faithful encoding of α as data, with decode inverting encode.

Instances
    def MIPRE.Cost.esize {α : Type u_1} [SizedEncoding α] (a : α) :

    The size of a value: the number of nodes of its encoding.

    Equations
    Instances For
      theorem MIPRE.Cost.esize_pos {α : Type u_1} [SizedEncoding α] (a : α) :
      0 < esize a
      @[reducible, inline]

      Binary strings, the {0,1}* of the paper.

      Equations
      Instances For
        def MIPRE.Cost.Data.ofList {α : Type u_1} (f : α → Data) :
        List α → Data

        Lists: cons-chains ending in nil.

        Equations
        Instances For
          def MIPRE.Cost.Data.toList? {α : Type u_1} (g : Data → Option α) :
          Data → Option (List α)

          Reading a list back, elementwise.

          Equations
          Instances For
            theorem MIPRE.Cost.Data.toList?_ofList {α : Type u_1} {f : α → Data} {g : Data → Option α} (hfg : ∀ (a : α), g (f a) = some a) (l : List α) :
            toList? g (ofList f l) = some l
            theorem MIPRE.Cost.Data.size_ofList_le {α : Type u_1} {f : α → Data} {B : ℕ} (hf : ∀ (a : α), (f a).size ≤ B) (l : List α) :
            (ofList f l).size ≤ (B + 1) * l.length + 1
            theorem MIPRE.Cost.Data.length_le_size_ofList {α : Type u_1} (f : α → Data) (l : List α) :
            @[instance_reducible]

            Bit strings encode as lists of bits.

            Equations

            Folding Nat.bit over the binary digits of n recovers n.

            @[instance_reducible]

            Natural numbers encode in binary (LSB first): the bit string n.bits. This is the encoding under which indices "n in binary" enter succinct descriptions (blueprint def:succinct).

            Equations
            • One or more equations did not get rendered due to their size.
            @[instance_reducible]
            instance MIPRE.Cost.instSizedEncodingProd {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] :

            Length-additive pairing: encode (a, b) = cons (encode a) (encode b).

            Equations
            • One or more equations did not get rendered due to their size.
            @[simp]
            theorem MIPRE.Cost.esize_prod {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (a : α) (b : β) :
            esize (a, b) = esize a + esize b + 1
            theorem MIPRE.Cost.encode_prod {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (a : α) (b : β) :

            Programs as data #

            Every program has size at least two. Prog.toData is a Data.cons whatever the constructor, so no program encodes to nil. Small, and load-bearing: it is what forces 2 ≤ λ in Verifier.IsBounded (Verifier.IsBounded.two_le), and so what puts the index of the halting reduction inside the range where IsBounded's time clauses say anything.