NLAlib.Ops.PWrites.whileFuel
Library · theorem
The loop with early exit: with the fuel N, a round from the invariant Inv i with a true test fails with probability at most \varphi_i, and the exit block from Inv i with a false test, or at the cap, fails with probability at most \psi; then the loop fails with probability at most \sum_{i < N}\varphi_i + \psi. This is the union bound over the rounds, whose start positions are random.
NLAlib.Ops.PWrites.whileFuel {Op Tst K : Type} [Inhabited K] [MeasurableSpace K]
{law : ℕ → Measure K} {I : Ops.Interp Op Tst K} {ρ : Ops.Env} {F : Ops.Fp}
{Pre Post : Ops.Mem K → Prop} (hI : I.IsMeasurable) {win : Op → List ℕ → ℕ}
(hloc : ∀ (o : Op), I.TapeLocal o (win o)) {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) {G : Ops.Fp} (Inv : ℕ → Ops.Mem K → Prop) (φ : ℕ → ℝ)
{ψ : ℝ} (hφ : ∀ i < N, 0 ≤ φ i) (hψ : 0 ≤ ψ) (h0 : ∀ (m : Ops.Mem K), Pre m → Inv 0 m)
(htest : ∀ i < N, ∀ (m : Ops.Mem K), Inv i m → ∃ b, I.testAt q ds ins (ρ.pushIdx i) m = some b)
(hbody :
∀ i < N,
Ops.PWrites law I body (ρ.pushIdx i) F
(fun m ↦ Inv i m ∧ I.testAt q ds ins (ρ.pushIdx i) m = some true) (Inv (i + 1)) (φ i))
(hexit :
∀ i ≤ N,
Ops.PWrites law I k (ρ.pushIdx i) G
(fun m ↦ Inv i m ∧ (i = N ∨ I.testAt q ds ins (ρ.pushIdx i) m = some false)) Post ψ) :
Ops.PWrites law I (Ops.Stmt.whileFuel fuel q ds ins body k) ρ (F ⊔ G) Pre Post
(∑ i ∈ Finset.range N, φ i + ψ)Import NLAlib.Ops.Logic.Probabilistic.