Documentation

CslibFrontier.Computability.WordRAM.Realization.RandomLoop

Runtime-bounded loops with private coins #

RealizesRand.iterate realizes a runtime-bounded loop whose body is a memory client with private coins. The loop is any family loop d n a satisfying the iteration equations loop d 0 a = pure a and loop d (n + 1) a = body (d, a) >>= loop d n. The client need not be rewritten into a canonical form: a recursive client such as link methods (contractTimes n) satisfies these equations directly. The native code is the loop of Realizes.iterateRuntime (loopEmit) around the body's emitter.

Every body run must satisfy the body's domain, and the body's time and rand budgets must stay within the uniform per-iteration budgets T and R, at every state that the loop reaches with positive probability. With n iterations the loop then takes n * (T + 1) units of time and at most n * R rand calls on every path. Its law is the law of the loop's run.

Main results #

The rule is original infrastructure over the existing native loop and ExecRandLaw.

theorem Cslib.WordRAM.Realization.RealizesRand.iterate {δ σ : Type} {k l : ℕ} (input : δ ↪ Fin k → ℕ) (output : σ ↪ Fin l → ℕ) {body : δ × σ → ProbOracleComp DataStructure.Memory.Op.Result σ} {loop : δ → ℕ → σ → ProbOracleComp DataStructure.Memory.Op.Result σ} (hzero : ∀ (d : δ) (a : σ), loop d 0 a = pure a) (hsucc : ∀ (d : δ) (n : ℕ) (a : σ), loop d (n + 1) a = body (d, a) >>= loop d n) {safe : ℕ → δ × σ → DataStructure.Memory.State → Prop} {time calls : δ × σ → DataStructure.Memory.State → ℕ} (T R : (δ × σ) × ℕ → DataStructure.Memory.State → ℕ) (h : RealizesRand Basis.exact body (appendWords input output) output safe time calls) :
RealizesRand Basis.exact (fun (x : (δ × σ) × ℕ) => match x with | ((d, a), fuel) => loop d fuel a) (((appendWords input output).prodMap (Equiv.funUnique (Fin 1) ℕ).symm.toEmbedding).trans (Fin.appendEquiv (k + l) 1).toEmbedding) output (fun (w : ℕ) (x : (δ × σ) × ℕ) (s : DataStructure.Memory.State) => match x with | ((d, a), fuel) => ∀ j < fuel, ∀ (b : σ) (s' : (DataStructure.Memory.spec w).toRandomized.withCoins.State), (b, s') ∈ ((DataStructure.Memory.spec w).toRandomized.withCoins.run (loop d j a) s).support → safe w (d, b) s' ∧ time (d, b) s' ≤ T ((d, a), fuel) s ∧ calls (d, b) s' ≤ R ((d, a), fuel) s) (fun (x : (δ × σ) × ℕ) (s : DataStructure.Memory.State) => match x with | ((d, a), fuel) => fuel * (T ((d, a), fuel) s + 1)) fun (x : (δ × σ) × ℕ) (s : DataStructure.Memory.State) => match x with | ((d, a), fuel) => fuel * R ((d, a), fuel) s

Loops. One uniform body certificate realizes a runtime-bounded loop, given by its iteration equations. The visible domain asks for the body's domain and per-iteration budgets at every supported state reached after fewer than fuel iterations.