NLA-lib Explorer

NLAlib.Ops.wp_whileFuel

Library · theorem

The loop with early exit. Inv i is an invariant of the memory after i rounds. At a round below the cap the test is evaluated: 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.

NLAlib.Ops.wp_whileFuel {Op Tst K : Type} {md : Ops.Mode} {I : Ops.Interp Op Tst K} {τ : Ops.Tape K}
  {ρ : Ops.Env} {Q : Ops.Mem K → Prop} {m : Ops.Mem K} {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.Mem K → Prop) (h0 : Inv 0 m)
  (hstep :
    ∀ i < n,
      ∀ (m : Ops.Mem K),
        Inv i m →
          md.Holds (I.testAt q ds ins (ρ.pushIdx i) m) fun c ↦
            if c = true then Ops.Wp md I τ body (ρ.pushIdx i) (Inv (i + 1)) m
            else Ops.Wp md I τ k (ρ.pushIdx i) Q m)
  (hcap : ∀ (m : Ops.Mem K), Inv n m → Ops.Wp md I τ k (ρ.pushIdx n) Q m) :
  Ops.Wp md I τ (Ops.Stmt.whileFuel fuel q ds ins body k) ρ Q m

Full source on GitHub

Import NLAlib.Ops.Logic.