M6: reasoning about loops of the core language #
evalF_loop: a loop runs to completion when each iteration succeeds and keeps an invariant,
with cost at most 1 + cost(bound) + N · (1 + body).
theorem
OrderMaintenance.Impl.runForF_inv
{κ : Caps}
(b : Stm)
(x : Machine.Reg)
(N : ℕ)
(I : ℕ → Model.Core → Loc → Prop)
(cb : ℕ)
(hb :
∀ k < N,
∀ (s : Model.Core) (L : Loc),
I k s L →
∃ (s' : Model.Core) (L' : Loc) (c : ℕ),
evalF κ b s (Machine.State.upd L x k) = Res.ok s' L' c ∧ c ≤ cb ∧ I (k + 1) s' L')
(n k : ℕ)
(s : Model.Core)
(L : Loc)
:
theorem
OrderMaintenance.Impl.evalF_assign_ok
{κ : Caps}
{x : Machine.Reg}
{e : Exp}
{s : Model.Core}
{L : Loc}
{v : ℕ}
(h : Exp.ev κ s L e = some v)
:
theorem
OrderMaintenance.Impl.evalF_loop
{κ : Caps}
{x : Machine.Reg}
{n : Exp}
{b : Stm}
{s : Model.Core}
{L : Loc}
{N : ℕ}
(hn : Exp.ev κ s L n = some N)
(I : ℕ → Model.Core → Loc → Prop)
(cb : ℕ)
(h0 : I 0 s L)
(hb :
∀ k < N,
∀ (s : Model.Core) (L : Loc),
I k s L →
∃ (s' : Model.Core) (L' : Loc) (c : ℕ),
evalF κ b s (Machine.State.upd L x k) = Res.ok s' L' c ∧ c ≤ cb ∧ I (k + 1) s' L')
:
The loop rule.
theorem
OrderMaintenance.Impl.evalF_loop_pure
{κ : Caps}
{x : Machine.Reg}
{n : Exp}
{b : Stm}
{s : Model.Core}
{L : Loc}
{N : ℕ}
(hn : Exp.ev κ s L n = some N)
{α : Type}
(F : Loc → Prop)
(abs : Loc → α)
(f : α → ℕ → α)
(cb : ℕ)
(h0 : F L)
(hb :
∀ k < N,
∀ (L' : Loc),
F L' →
∃ (L'' : Loc) (c : ℕ),
evalF κ b s (Machine.State.upd L' x k) = Res.ok s L'' c ∧ c ≤ cb ∧ F L'' ∧ abs L'' = f (abs L') k)
:
The loop rule for loops that only change locals: an abstraction abs of the locals follows
the fold of f over the iterations, and a frame condition F is kept.