NLA-lib Explorer

NLAlib.Ops.evalCounted_loop_weight_of_writes

Library · theorem

The weighted invariant rule on an existing counted loop, starting from any prior count, live scratch and peak. Its frame and mathematical state use the ordinary word-level proof; only the weighted count increment is accumulated.

NLAlib.Ops.evalCounted_loop_weight_of_writes {Op Tst K : Type} {I : Ops.Interp Op Tst K}
  {τ : Ops.Tape K} {W : Op → List ℕ → ℕ} {ρ : Ops.Env} {a b : Ops.St Op Tst K} {n : Ops.IExp}
  {N : ℕ} {body : Ops.Stmt Op Tst} (hn : Ops.IExp.eval ρ.idx n = some N) (F : ℕ → Ops.Fp)
  (hF : ∀ i < N, F i ≤ F (i + 1)) (P : ℕ → Ops.Mem K → Prop) (h0 : P 0 a.mem)
  (hstep :
    ∀ i < N,
      ∀ (m' : Ops.Mem K),
        Ops.Store.EqOff (F i) a.mem.store m'.store →
          P i m' → Ops.Writes Ops.Mode.total I τ body (ρ.pushIdx i) (F (i + 1)) (P (i + 1)) m')
  (weight : Ops.Count Op Tst →+ ℕ) (w : ℕ → ℕ)
  (hweight :
    ∀ i < N,
      ∀ (x y : Ops.St Op Tst K),
        Ops.Store.EqOff (F i) a.mem.store x.mem.store →
          P i x.mem →
            Ops.evalCounted I W τ body (ρ.pushIdx i) x = some y →
              weight y.cost ≤ weight x.cost + w i)
  (hr : Ops.evalCounted I W τ (Ops.Stmt.loop n body) ρ a = some b) :
  weight b.cost ≤ weight a.cost + ∑ i ∈ Finset.range N, w i ∧
    Ops.Store.EqOff (F N) a.mem.store b.mem.store ∧ P N b.mem

Full source on GitHub

Import NLAlib.Ops.Logic.WeightedLoop.