Documentation

MIPRE.Foundations.Halting.Serial

Reading and writing descriptions, in the ambient model #

The two programs that move between a datum and its postorder serialization (Data.toBitsPost, Halting/Descriptions.lean):

Both run in time quadratic in the size of their input: each step copies the remainder of the work list and the accumulator.

A pending item of the serializer: a datum to write (some d, as cons nil d) or the closing 1 of a pair (none, as nil).

Equations
Instances For

    The measure of a list of pending items, decreasing along the serializer's loop.

    Equations
    Instances For

      The same measure, on the data of the pending list (for the loop invariant).

      Equations
      Instances For

        Close a cost bound after the run has been built, unfolding list encodings.

        Equations
        Instances For

          The parser #

          Body of parseProg, on the state cons bits stack: at the end, stop with the top of the stack (nil if empty); on a 0, push nil; on a 1, pop two entries and push their pair, leaving a stack with fewer than two entries alone.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            The stack size grows by at most two per step.

            theorem MIPRE.Cost.Prog.parseLoop_runs (x : BitStr) (s : List Data) (env : Env) (S : ℕ) (hS : (encode x).size + (Data.list s).size + 2 * List.length x ≤ S) :
            ∃ t ≤ (List.length x + 1) * (S + 21), Eval ((encode x).cons (Data.list s) :: env) parseBody.loop ((Data.stackRun x s).headD Data.nil) t

            The parsing loop computes the top of the final stack, in time (|x| + 1) · (S + 21) for S dominating the sizes along the run.

            theorem MIPRE.Cost.Prog.parseProg_runs (x : BitStr) :
            ∃ t ≤ (List.length x + 2) * ((encode x).size + 2 * List.length x + 25), parseProg.Runs (encode x) (Data.parse x) t

            parseProg reads a serialization back.

            The serializer #

            Body of serProg, on the state cons pending acc: at the end, stop with acc; a marker writes a 1; the datum nil writes a 0; a pair cons a b schedules a, b and a marker.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              serProg on d computes encode d.toBitsPost.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem MIPRE.Cost.Prog.serBody_marker (rest : List Data) (acc : BitStr) :
                ∃ t ≤ (Data.list rest).size + (encode acc).size + 20, Eval [(Data.list (Data.nil :: rest)).cons (encode acc)] serBody ((Data.nil.cons Data.nil).cons ((Data.list rest).cons (encode (true :: acc)))) t
                theorem MIPRE.Cost.Prog.serBody_datacons (a b : Data) (rest : List Data) (acc : BitStr) :
                ∃ t ≤ a.size + b.size + (Data.list rest).size + (encode acc).size + 30, Eval [(Data.list (Data.nil.cons (a.cons b) :: rest)).cons (encode acc)] serBody ((Data.nil.cons Data.nil).cons ((Data.list (Data.nil.cons a :: Data.nil.cons b :: Data.nil :: rest)).cons (encode acc))) t
                theorem MIPRE.Cost.Prog.serLoop_runs (d : Data) (env : Env) :
                ∃ t ≤ (3 * d.size + 2) * (16 * d.size + 42), Eval ((Data.list [Data.itemD (some d)]).cons (encode []) :: env) serBody.loop (encode (List.reverse d.toBitsPost)) t

                The serializer's loop, by the invariant "acc.reverse ++ serItems items is the target", with the measure serMeasure and the size bound S₀.

                theorem MIPRE.Cost.Prog.serProg_runs (d : Data) :
                ∃ t ≤ (3 * d.size + 2) * (16 * d.size + 42) + (d.size + 2) * (5 * d.size + 30), serProg.Runs d (encode d.toBitsPost) t

                serProg writes the postorder serialization.