NLA-lib Explorer

NLAlib.Ops.writes_whileFuel

Library · theorem

The loop with early exit, in the standard invariant form. At a round below the cap the test is evaluated (its Boolean is known from the access model: IsCmp, holds_testAt): 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 footprint is that of the rounds and of the continuation.

NLAlib.Ops.writes_whileFuel {Op Tst K : Type} {md : Ops.Mode} {I : Ops.Interp Op Tst K}
  {τ : Ops.Tape K} {ρ : Ops.Env} {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) (F : ℕ → Ops.Fp) (hF : ∀ i < N, F i ≤ F (i + 1))
  (G : Ops.Fp) (Inv : ℕ → Ops.Mem K → Prop) (P : Ops.Mem K → Prop) (h0 : Inv 0 m)
  (hstep :
    ∀ i < N,
      ∀ (m' : Ops.Mem K),
        Ops.Store.EqOff (F i) m.store m'.store →
          Inv i m' →
            md.Holds (I.testAt q ds ins (ρ.pushIdx i) m') fun c ↦
              if c = true then Ops.Writes md I τ body (ρ.pushIdx i) (F (i + 1)) (Inv (i + 1)) m'
              else Ops.Writes md I τ k (ρ.pushIdx i) G P m')
  (hcap :
    ∀ (m' : Ops.Mem K),
      Ops.Store.EqOff (F N) m.store m'.store →
        Inv N m' → Ops.Writes md I τ k (ρ.pushIdx N) G P m') :
  Ops.Writes md I τ (Ops.Stmt.whileFuel fuel q ds ins body k) ρ (F N ⊔ G) P m

Full source on GitHub

Import NLAlib.Ops.Logic.Loop.