NLAlib.Ops.RunsFromW.whileFuel
Library · theorem
The loop with early exit, with an invariant on the counts added so far and the memory. At a round below the cap the test is used once: if it holds the body keeps the invariant, otherwise the continuation runs with the round index. At the cap the continuation runs without a test. The counts are those of the rounds that were done.
NLAlib.Ops.RunsFromW.whileFuel {Op Tst K : Type} {I : Ops.Interp Op Tst K} {W : Op → List ℕ → ℕ}
{τ : Ops.Tape K} {ρ : Ops.Env} {st : Ops.St Op Tst K} {p : ℕ}
{Q : Ops.Count Op Tst → Ops.Mem K → Prop} {fuel : Ops.IExp} {q : Tst} {ds : List Ops.IExp}
{ins : List Ops.Operand} {body k : Ops.Stmt Op Tst} {n : ℕ}
(hn : Ops.IExp.eval ρ.idx fuel = some n) (Inv : ℕ → Ops.Count Op Tst → Ops.Mem K → Prop)
(h0 : Inv 0 0 st.mem)
(hstep :
∀ i < n,
∀ (st' : Ops.St Op Tst K) (c : Ops.Count Op Tst),
Inv i c st'.mem →
∃ d a b,
Ops.IExp.evalList (ρ.pushIdx i).idx ds = some d ∧
Ops.Operand.evalList (ρ.pushIdx i) ins = some a ∧
I.test q d a st'.mem = some b ∧
if b = true then
Ops.RunsFromW I W τ body (ρ.pushIdx i) (st'.tick q d) p fun c' m ↦
Inv (i + 1) (c + (Ops.Count.test q d + c')) m
else
Ops.RunsFromW I W τ k (ρ.pushIdx i) (st'.tick q d) p fun c' m ↦
Q (c + (Ops.Count.test q d + c')) m)
(hcap :
∀ (st' : Ops.St Op Tst K) (c : Ops.Count Op Tst),
Inv n c st'.mem → Ops.RunsFromW I W τ k (ρ.pushIdx n) st' p fun c' m ↦ Q (c + c') m) :
Ops.RunsFromW I W τ (Ops.Stmt.whileFuel fuel q ds ins body k) ρ st p QImport NLAlib.Ops.Counted.