NLAlib.Ops.writes_loop_weighted
Library · theorem
The same footprint and mathematical invariant as the ordinary total loop rule, augmented with bounds on actual per-round weighted counts. The result guarantees execution, its final word invariant/frame, and the sum of the per-round costs on that execution.
NLAlib.Ops.writes_loop_weighted {Op Tst K : Type} {I : Ops.Interp Op Tst K} {τ : Ops.Tape K}
{W : Op → List ℕ → ℕ} {ρ : Ops.Env} {m : Ops.Mem 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 m)
(hstep :
∀ i < N,
∀ (m' : Ops.Mem K),
Ops.Store.EqOff (F i) m.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,
∀ (a b : Ops.St Op Tst K),
Ops.Store.EqOff (F i) m.store a.mem.store →
P i a.mem →
Ops.evalCounted I W τ body (ρ.pushIdx i) a = some b →
weight b.cost ≤ weight a.cost + w i) :
Ops.ConditionalRunsW I W τ (Ops.Stmt.loop n body) ρ m
(Ops.stmtPeak W (Ops.Stmt.loop n body) ρ.idx) fun c m' ↦
weight c ≤ ∑ i ∈ Finset.range N, w i ∧ Ops.Store.EqOff (F N) m.store m'.store ∧ P N m'Import NLAlib.Ops.Logic.WeightedLoop.