Documentation

MIPRE.Foundations.Cost.Closure

The closure library, part I: calls, projections, pairing, branching #

Program-layer combinators on Prog with their Eval lemmas, and the corresponding PolyTimeFun combinators (const, pair, fst, snd, ite). Two conventions keep composition free of de Bruijn bookkeeping:

Costs are exact at the program layer and packaged as polynomials at the function layer (planning/compression-track.md, K2).

Program layer #

theorem MIPRE.Cost.Eval.cast_cost {env : Env} {p : Prog} {r : Data} {t t' : } (h : Eval env p r t) (e : t = t') :
Eval env p r t'

Transport a run along an equation between costs.

theorem MIPRE.Cost.Eval.var_of_get {env : Env} {i : } {v : Data} (h : env.get i = v) :
Eval env (Prog.var i) v (v.size + 1)

Reading a variable whose value is known.

Call the closed program q on the value of variable i.

Equations
Instances For

    First component of the input (variable 0).

    Equations
    Instances For

      Second component of the input (variable 0).

      Equations
      Instances For
        theorem MIPRE.Cost.Prog.callVar_wellScoped {n i : } (hi : i < n) {q : Prog} (hq : WellScoped 1 q) :
        theorem MIPRE.Cost.Prog.callVar_eval {env : Env} {i : } {q : Prog} (hq : WellScoped 1 q) {v r : Data} {t : } (hv : env.get i = v) (h : Eval [v] q r t) :
        Eval env (callVar i q) r (v.size + 1 + t + 1)

        Calling q on variable i: copy the value, then run q (its input is variable 0; the rest of the environment is inert).

        theorem MIPRE.Cost.Prog.fstProg_runs (a b : Data) :
        fstProg.Runs (a.cons b) a (a.size + 1 + 1)
        theorem MIPRE.Cost.Prog.sndProg_runs (a b : Data) :
        sndProg.Runs (a.cons b) b (b.size + 1 + 1)

        Function layer #

        noncomputable def MIPRE.Cost.PolyTimeFun.const {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (b : β) :

        The constant function, in constant time.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[simp]
          theorem MIPRE.Cost.PolyTimeFun.const_apply {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (b : β) (a : α) :
          (const b).toFun a = b
          noncomputable def MIPRE.Cost.PolyTimeFun.pair {α : Type u_1} {β : Type u_2} {γ : Type u_3} [SizedEncoding α] [SizedEncoding β] [SizedEncoding γ] (F : PolyTimeFun α β) (G : PolyTimeFun α γ) :
          PolyTimeFun α (β × γ)

          Pairing.

          Equations
          Instances For
            @[simp]
            theorem MIPRE.Cost.PolyTimeFun.pair_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} [SizedEncoding α] [SizedEncoding β] [SizedEncoding γ] (F : PolyTimeFun α β) (G : PolyTimeFun α γ) (a : α) :
            (F.pair G).toFun a = (F.toFun a, G.toFun a)
            noncomputable def MIPRE.Cost.PolyTimeFun.fst {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] :
            PolyTimeFun (α × β) α

            First projection.

            Equations
            Instances For
              noncomputable def MIPRE.Cost.PolyTimeFun.snd {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] :
              PolyTimeFun (α × β) β

              Second projection.

              Equations
              Instances For
                @[simp]
                theorem MIPRE.Cost.PolyTimeFun.fst_apply {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (p : α × β) :
                fst.toFun p = p.1
                @[simp]
                theorem MIPRE.Cost.PolyTimeFun.snd_apply {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (p : α × β) :
                snd.toFun p = p.2
                noncomputable def MIPRE.Cost.PolyTimeFun.ite {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (c : PolyTimeFun α Bool) (F G : PolyTimeFun α β) :

                Branching on a boolean: ite c F G a = if c a then F a else G a. The condition is bound as variable 0; the nil (false) branch calls G on the original input (variable 1), the cons (true) branch calls F on it (variable 3, after elim bound the two nil components of encode true).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[simp]
                  theorem MIPRE.Cost.PolyTimeFun.ite_apply {α : Type u_1} {β : Type u_2} [SizedEncoding α] [SizedEncoding β] (c : PolyTimeFun α Bool) (F G : PolyTimeFun α β) (a : α) :
                  (c.ite F G).toFun a = if c.toFun a = true then F.toFun a else G.toFun a