NLA-lib Explorer

NLAlib.Ops.Reference.instrumented_whileFuel

Library · theorem

Fuelled loops enter the counted query/body iteration after the fuel and entry charges.

NLAlib.Ops.Reference.instrumented_whileFuel {Op Tst K : Type} (I : Ops.Interp Op Tst K)
  (R : Ops.ResourceModel Op Tst) (τ : Ops.Tape K) (fuel : Ops.IExp) (q : Tst) (ds : List Ops.IExp)
  (ins : List Ops.Operand) (body next : Ops.Stmt Op Tst) (ρ : Ops.Env)
  (a : Ops.Reference.State Op Tst K) (ha : a.cur ≤ a.peak) {n : ℕ}
  (hn : Ops.IExp.eval ρ.idx fuel = some n) :
  Ops.Reference.instrumented I R τ (Ops.Stmt.whileFuel fuel q ds ins body next) ρ a =
    (Ops.whileIter (fun i ↦ I.instrument.testSt q ds ins (ρ.pushIdx i))
          (fun i ↦
            Ops.evalCounted I.instrument (Ops.instrumentWorkspace R.workspace) τ
              ((Ops.tally
                    (Ops.indexBookkeeping ds ++ Ops.operandBookkeeping ins ++
                      [Ops.Bookkeeping.round])).seq
                body.instrument)
              (ρ.pushIdx i))
          n 0
          (Ops.Reference.charge (Ops.Reference.index fuel + Ops.Reference.core Ops.Bookkeeping.loop)
            a)).bind
      fun jb ↦
      Ops.evalCounted I.instrument (Ops.instrumentWorkspace R.workspace) τ
        ((Ops.tally
              (Ops.indexBookkeeping ds ++ Ops.operandBookkeeping ins ++ [Ops.Bookkeeping.exit])).seq
          next.instrument)
        (ρ.pushIdx jb.1) jb.2

Full source on GitHub

Import NLAlib.Ops.Reference.Accounting.