Documentation

MIPRE.Foundations.Cost.Interpreter

The self-interpreter, I: the step function as a program #

Programs of the ambient model implementing the step function of the evaluation machine on data (Machine.stepData, Cost/MachineData.lean): stepEvProg for "evaluate" controls, stepRetProg for "return" controls, and stepProg combining them. Each is proved to compute stepData on encoded configurations, at a cost quadratic in the size of the configuration (the only non-constant work is the walk getListProg along the environment, which copies the remaining environment at each of its steps).

Conventions: every sub-program is closed and receives its input, a tuple built with cons, at variable 0; tuples are taken apart with elim (free), and the pieces are read back with var (paid by size). Tag dispatch on a unary numeral is a chain of elims; the case programs are called through callVar on a packaged tuple whose index grows by two per level of the chain.

Discharge a linear inequality between costs and sizes, after expanding the sizes of constructors and of encoded configurations.

Equations
Instances For

    Projections at an arbitrary index #

    theorem MIPRE.Cost.Machine.projLeft_runs {E : Env} {i : } {d : Data} (h : E.get i = d) :
    sd.size + 2, Eval E (projLeft i) d.left s
    theorem MIPRE.Cost.Machine.projRight_runs {E : Env} {i : } {d : Data} (h : E.get i = d) :
    sd.size + 2, Eval E (projRight i) d.right s

    The environment walk #

    Body of getListProg: on the state cons env idx, stop with left env if idx is exhausted, else continue with cons (right env) idx'.

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

      getListProg on cons env idx computes getList env (unaryToNat idx).

      Equations
      Instances For
        theorem MIPRE.Cost.Machine.getListProg_runs (idx env : Data) (rest : Env) :
        t ≤ (idx.size + 1) * (env.size + idx.size + 12), Eval (env.cons idx :: rest) getListProg (env.getList idx.unaryToNat) t

        The "evaluate" cases #

        Cases of stepEvProg; input cons body (cons env kont). After the two elims the environment is [env, kont, body, cons env kont, input].

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem MIPRE.Cost.Machine.evVar_runs (body env kont : Data) :
                      s ≤ (body.size + 1) * (env.size + body.size + 12) + 4 * env.size + 3 * body.size + 2 * kont.size + 20, Eval [body.cons (env.cons kont)] evVar ((retD (env.getList body.unaryToNat)).cons (env.cons kont)) s
                      theorem MIPRE.Cost.Machine.evNil_runs (body env kont : Data) :
                      senv.size + kont.size + 12, Eval [body.cons (env.cons kont)] evNil ((retD Data.nil).cons (env.cons kont)) s
                      theorem MIPRE.Cost.Machine.evCons_runs (h t env kont : Data) :
                      sh.size + t.size + 2 * env.size + kont.size + 20, Eval [(h.cons t).cons (env.cons kont)] evCons ((evD h).cons (env.cons (((Data.ofNat 0).cons (t.cons env)).cons kont))) s
                      theorem MIPRE.Cost.Machine.evLet_runs (e b env kont : Data) :
                      se.size + b.size + 2 * env.size + kont.size + 24, Eval [(e.cons b).cons (env.cons kont)] evLet ((evD e).cons (env.cons (((Data.ofNat 2).cons (b.cons env)).cons kont))) s
                      theorem MIPRE.Cost.Machine.evLoop_runs (b env kont : Data) :
                      s2 * b.size + 2 * env.size + kont.size + 26, Eval [b.cons (env.cons kont)] evLoop ((evD b).cons (env.cons (((Data.ofNat 3).cons (b.cons env)).cons kont))) s
                      theorem MIPRE.Cost.Machine.evConst_runs (d env kont : Data) :
                      sd.size + env.size + kont.size + 12, Eval [d.cons (env.cons kont)] evConst ((retD d).cons (env.cons kont)) s
                      theorem MIPRE.Cost.Machine.evElim_runs (i n c env kont : Data) :
                      s ≤ (i.size + 1) * (env.size + i.size + 12) + 5 * env.size + 3 * i.size + n.size + c.size + 2 * kont.size + 40, Eval [(i.cons (n.cons c)).cons (env.cons kont)] evElim (if env.getList i.unaryToNat = Data.nil then (evD n).cons (env.cons kont) else (evD c).cons (((env.getList i.unaryToNat).left.cons ((env.getList i.unaryToNat).right.cons env)).cons kont)) s

                      Tag dispatch #

                      dispatch cs i idx: case analysis on the unary numeral at variable i, calling the k-th program of cs on the tuple at variable idx + 2 k (each level of the chain binds two more variables).

                      Equations
                      Instances For
                        theorem MIPRE.Cost.Machine.dispatch_wellScoped (cs : List Prog) (i idx n : ) :
                        i < nidx < n(∀ ccs, Prog.WellScoped 1 c)Prog.WellScoped n (dispatch cs i idx)
                        theorem MIPRE.Cost.Machine.dispatch_runs (cs : List Prog) (k i idx : ) (E : Env) (pk r : Data) (t : ) :
                        k < cs.length(∀ ccs, Prog.WellScoped 1 c)E.get i = Data.ofNat kE.get idx = pkEval [pk] (cs.getD k Prog.nil) r tst + pk.size + k + 3, Eval E (dispatch cs i idx) r s

                        The "evaluate" step #

                        The case programs of stepEvProg, indexed by the tag of the program.

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

                          The step on "evaluate p"; input cons (toData p) (cons env kont).

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def MIPRE.Cost.Machine.dispEnv (k : ) (body env kont : Data) :

                            The environment in which the dispatch of stepEvProg runs, for a program with tag k and body body.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              theorem MIPRE.Cost.Machine.stepEvProg_prefix (k : ) (body env kont r : Data) {s : } (hd : Eval (dispEnv k body env kont) (dispatch evCases 0 1) r s) :
                              cs + body.size + env.size + kont.size + (Data.ofNat k).size + 12, Eval [((Data.ofNat k).cons body).cons (env.cons kont)] stepEvProg r c

                              The prefix of stepEvProg up to the dispatch.

                              Bound of one "evaluate" step in terms of S = esize p + env.size + kont.size.

                              Equations
                              Instances For
                                theorem MIPRE.Cost.Machine.stepEvProg_runs (p : Prog) (env kont : Data) :
                                sstepEvBound (esize p + env.size + kont.size), stepEvProg.Runs (p.toData.cons (env.cons kont)) (stepEv p.toData env kont) s

                                The "return" cases #

                                Cases of stepRetProg; input cons v (cons env (cons fb k)) with fb the payload of the top frame. After the three elims the environment is [fb, k, env, cons fb k, v, cons env (cons fb k), input].

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem MIPRE.Cost.Machine.retCons1_runs (t' env' v env k : Data) :
                                        st'.size + env'.size + v.size + k.size + 20, Eval [v.cons (env.cons ((t'.cons env').cons k))] retCons1 ((evD t').cons (env'.cons (((Data.ofNat 1).cons v).cons k))) s
                                        theorem MIPRE.Cost.Machine.retCons2_runs (a v env k : Data) :
                                        sa.size + v.size + env.size + k.size + 16, Eval [v.cons (env.cons (a.cons k))] retCons2 ((retD (a.cons v)).cons (env.cons k)) s
                                        theorem MIPRE.Cost.Machine.retLet1_runs (b env' v env k : Data) :
                                        sb.size + v.size + env'.size + k.size + 16, Eval [v.cons (env.cons ((b.cons env').cons k))] retLet1 ((evD b).cons ((v.cons env').cons k)) s
                                        theorem MIPRE.Cost.Machine.retLoop1_runs_nil (b env' env k : Data) :
                                        senv'.size + k.size + 16, Eval [Data.nil.cons (env.cons ((b.cons env').cons k))] retLoop1 ((retD Data.nil).cons (env'.cons k)) s
                                        theorem MIPRE.Cost.Machine.retLoop1_runs_stop (b env' c env k : Data) :
                                        sc.size + env'.size + k.size + 18, Eval [(Data.nil.cons c).cons (env.cons ((b.cons env').cons k))] retLoop1 ((retD c).cons (env'.cons k)) s
                                        theorem MIPRE.Cost.Machine.retLoop1_runs_step (b env' a₁ a₂ c env k : Data) :
                                        s2 * b.size + 2 * c.size + 2 * env'.size + k.size + 40, Eval [((a₁.cons a₂).cons c).cons (env.cons ((b.cons env').cons k))] retLoop1 ((evD b).cons ((c.cons env'.right).cons (((Data.ofNat 3).cons (b.cons (c.cons env'.right))).cons k))) s

                                        The "return" step #

                                        The step on "return v"; input cons v (cons env kont).

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          theorem MIPRE.Cost.Machine.stepRetProg_runs_nil (v env : Data) :
                                          sv.size + env.size + 12, stepRetProg.Runs (v.cons (env.cons Data.nil)) (stepRet v env Data.nil) s
                                          def MIPRE.Cost.Machine.retDispEnv (ftag : ) (fb v env k : Data) :

                                          The environment in which the dispatch of stepRetProg runs, for a top frame with tag ftag and payload fb.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            theorem MIPRE.Cost.Machine.stepRetProg_prefix (ftag : ) (fb v env k r : Data) {s : } (hd : Eval (retDispEnv ftag fb v env k) (dispatch retCases 0 1) r s) :
                                            cs + v.size + env.size + fb.size + k.size + (Data.ofNat ftag).size + 16, Eval [v.cons (env.cons (((Data.ofNat ftag).cons fb).cons k))] stepRetProg r c

                                            Bound of one "return" step in terms of S = v.size + env.size + kont.size.

                                            Equations
                                            Instances For
                                              theorem MIPRE.Cost.Machine.stepRetProg_runs_cons (v env : Data) (f : Frame) (k : Data) :
                                              sstepRetBound (v.size + env.size + f.toData.size + k.size), stepRetProg.Runs (v.cons (env.cons (f.toData.cons k))) (stepRet v env (f.toData.cons k)) s

                                              The step #

                                              The step function as a program: on the encoding of a configuration, the encoding of the next configuration.

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

                                                Bound of one step of the interpreter in terms of the size of the configuration.

                                                Equations
                                                Instances For
                                                  theorem MIPRE.Cost.Machine.le_stepBound_of_le {c S T : } (hc : c 41 * S + 240) (hS : S T) :
                                                  theorem MIPRE.Cost.Machine.le_stepBound_of_quad {c S T : } (hc : c (S + 1) * (S + 30) + 100 + 3 * S + 60) (hS : S + 4 T) :

                                                  stepProg computes the step of the machine on encoded configurations, at a cost quadratic in the size of the configuration.