Clock bounds for stateful computations #
Cslib.bind_stateM_clock adds the bounds for two consecutive stateful computations.
Cslib.bind_optionT_clock handles the rejecting bind.
Cslib.foldlM_optionT_clock applies this to each iteration of a finite fold in
OptionT (StateM σ). Rejection stops the fold but preserves the final state, so the bound
also charges the iteration that rejects. This is a bound on a caller-selected state clock,
not on the physical evaluation time of a callback.
theorem Cslib.bind_optionT_clock {σ α β : Type} (clock : σ → ℕ) (A B : ℕ) (x : OptionT (StateM σ) α) (f : α → OptionT (StateM σ) β) (hx : ∀ (s : σ), clock (x.run s).2 ≤ clock s + A) (hf : ∀ (a : α) (s : σ), clock ((f a).run s).2 ≤ clock s + B) (s : σ) :
Bound the clock of a rejecting bind by the sum of the component bounds. If the first computation rejects, its final state supplies the clock.
theorem Cslib.foldlM_optionT_clock {σ R : Type} {n : ℕ} (clock : σ → ℕ) (cost : ℕ) (f : R → Fin n → OptionT (StateM σ) R) (h : ∀ (a : R) (v : Fin n) (s : σ), clock ((f a v).run s).2 ≤ clock s + cost) (a : R) (s : σ) :
A finite fold spends at most its number of indices times the per-iteration budget, including the last, possibly rejecting, iteration.