Documentation

CslibFrontier.Computability.WordRAM.Resizable.Randomized

Compositional distributional execution (ExecRCodeDist) on the Resizable Word RAM #

Structured distributional execution (ExecRCodeDist) and its compilation (toExecRProgramDist) to flat clocked adaptive-adversary execution (ExecRProgramDist) for the word-granular Resizable Word RAM (Cslib.WordRAM.Resizable).

ExecRCodeDist w c x μ T L_peak couples an adversary-independent fallthrough distribution μ : PMF (RData r) with an expected instruction bound T : ℝ≥0∞ and an every-step peak hardware frontier bound L_peak : ℕ. Deterministic big-step RDemonicExec certificates (including single-word .shrink, the derived Θ(k + 1) subroutines growDirtyCode, growZeroCode, and shrinkCode, and by realize segments lifted via RDemonicExec.of_execBounded) lift via ExecRCodeDist.of_demonicExec, compose with .rand, .seq, .branch, .loop_bounded, and .loop_geometric, transfer along basis simulations (mapSimulates), and compile via ExecRCodeDist.toExecRProgramDist to ExecRProgramDist w (c.program out) out x μ (T + 1) L_peak.

Main definitions #

Main results #

References #

Compositional distributional execution (ExecRCodeDist) #

inductive Cslib.WordRAM.Resizable.ExecRCodeDist {B : Basis} {r : ℕ} (w : ℕ) :
RCode B r → RData r → PMF (RData r) → ENNReal → ℕ → Prop

Compositional Distributional Execution on the Resizable Word RAM (ExecRCodeDist). ExecRCodeDist w c x μ T L_peak: at word width w starting from x : RData r, running structured program c : RCode B r executes without faulting across all adaptive adversaries adv : RAdv r, keeps the hardware frontier ≤ L_peak at every intermediate step, realizes adversary-independent fallthrough distribution μ : PMF (RData r) at pc + c.size, and uses at most T : ℝ≥0∞ expected instructions.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.congr_dist {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ μ' : PMF (RData r)} {T T' : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) (hμ : μ = μ') (hT : T ≤ T') :
ExecRCodeDist w c x μ' T' L_peak
theorem Cslib.WordRAM.Resizable.ExecRCodeDist.frontier_le {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) :
x.frontier ≤ L_peak

Entry hardware frontier is bounded by L_peak.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.post_frontier_le {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) (y : RData r) :
y ∈ μ.support → y.frontier ≤ L_peak

Every state in the support of μ satisfies y.frontier ≤ L_peak.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.loop_exit {B : Basis} {r w L_peak : ℕ} {body : RCode B r} {cond : Cond r} {x : RData r} (hL : x.frontier ≤ L_peak) (hc : ¬cond.Holds x.toData) :
ExecRCodeDist w (RCode.loop cond body) x (PMF.pure x) 2 L_peak
theorem Cslib.WordRAM.Resizable.ExecRCodeDist.branch {B : Basis} {r w L_peak : ℕ} {pos neg : RCode B r} {cond : Cond r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (hpos : cond.Holds x.toData → ExecRCodeDist w pos x μ T L_peak) (hneg : ¬cond.Holds x.toData → ExecRCodeDist w neg x μ T L_peak) :
ExecRCodeDist w (RCode.branch cond pos neg) x μ (T + 2) L_peak
theorem Cslib.WordRAM.Resizable.ExecRCodeDist.seq_const {B : Basis} {r w L_peak : ℕ} {c₁ c₂ : RCode B r} {x : RData r} {μ₁ : PMF (RData r)} {T₁ : ENNReal} {μ₂ : RData r → PMF (RData r)} {T₂ : RData r → ENNReal} {B₂ : ENNReal} (h₁ : ExecRCodeDist w c₁ x μ₁ T₁ L_peak) (h₂ : ∀ y ∈ μ₁.support, ExecRCodeDist w c₂ y (μ₂ y) (T₂ y) L_peak) (hB₂ : ∀ y ∈ μ₁.support, T₂ y ≤ B₂) :
ExecRCodeDist w (c₁.seq c₂) x (μ₁.bind μ₂) (T₁ + B₂) L_peak
theorem Cslib.WordRAM.Resizable.ExecRCodeDist.seq_pure {B : Basis} {r w L_peak : ℕ} {c₁ c₂ : RCode B r} {x y : RData r} {μ : PMF (RData r)} {T₁ T₂ : ENNReal} (h₁ : ExecRCodeDist w c₁ x (PMF.pure y) T₁ L_peak) (h₂ : ExecRCodeDist w c₂ y μ T₂ L_peak) :
ExecRCodeDist w (c₁.seq c₂) x μ (T₁ + T₂) L_peak
theorem Cslib.WordRAM.Resizable.ExecRCodeDist.loop_bounded {B : Basis} {r w L_peak : ℕ} {body : RCode B r} {cond : Cond r} {x : RData r} (I Q : RData r → Prop) {μ_body : RData r → PMF (RData r)} {T_body : RData r → ENNReal} {B_body : ENNReal} (rank : RData r → ℕ) (K : ℕ) (hbody : ∀ (z : RData r), I z → cond.Holds z.toData → ExecRCodeDist w body z (μ_body z) (T_body z) L_peak) (hB : ∀ (z : RData r), I z → cond.Holds z.toData → T_body z ≤ B_body) (hinv : ∀ (z : RData r), I z → cond.Holds z.toData → ∀ y ∈ (μ_body z).support, RLoopStateInv cond I Q y ∧ (cond.Holds y.toData → rank y < rank z)) (hfr : ∀ (z : RData r), ¬cond.Holds z.toData → Q z → z.frontier ≤ L_peak) (hx_inv : RLoopStateInv cond I Q x) (hrank : cond.Holds x.toData → rank x < K) :
ExecRCodeDist w (RCode.loop cond body) x (loopIterRPMF cond μ_body K x) (↑K * (B_body + 2) + 2) L_peak

Ranked worst-case K-iteration while loop rule for ExecRCodeDist.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.mapSimulates {B B' : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (φ : B.Simulates B') (h : ExecRCodeDist w c x μ T L_peak) :
ExecRCodeDist w (RCode.mapSimulates φ c) x μ T L_peak

Transport ExecRCodeDist along any defined-evaluation basis simulation φ : B.Simulates B'.

theorem Cslib.WordRAM.Resizable.RDemonicExec.le_haltedReach_assemble {B : Basis} {r w L_peak n pc v : ℕ} {c : RCode B r} {x d : RData r} {P : RData r → Prop} (h : RDemonicExec w L_peak c x n P) {p : RProgram B r} (hp : p.Contains pc (c.assemble pc)) :
⨅ (y : RData r), ⨅ (_ : P y), haltedReach w p v d (pc + c.size) y ≤ haltedReach w p v d pc x
theorem Cslib.WordRAM.Resizable.ExecRCodeDist.supExpectedStepsWithin_assemble {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) {p : RProgram B r} {pc : ℕ} (hp : p.Contains pc (c.assemble pc)) (N : ℕ) :
supExpectedStepsWithin w p N (RCfg.running { pc := pc, data := x }) ≤ T + ∑' (y : RData r), μ y * supExpectedStepsWithin w p N (RCfg.running { pc := pc + c.size, data := y })

Finite-horizon Bellman inequality for ExecRCodeDist inside any containing p : RProgram B r.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.expectedStepsFromDemonic_assemble {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) {p : RProgram B r} {pc : ℕ} (hp : p.Contains pc (c.assemble pc)) :
expectedStepsFromDemonic w p (RCfg.running { pc := pc, data := x }) ≤ T + ∑' (y : RData r), μ y * expectedStepsFromDemonic w p (RCfg.running { pc := pc + c.size, data := y })

Full-horizon Bellman inequality for ExecRCodeDist.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.demonicSafeWithin_assemble {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) {L_bound : ℕ} (hL_bound : L_peak ≤ L_bound) {p : RProgram B r} {pc T_hor : ℕ} (hp : p.Contains pc (c.assemble pc)) (hcont : ∀ y ∈ μ.support, DemonicSafeWithin w L_bound T_hor p { pc := pc + c.size, data := y }) :
DemonicSafeWithin w L_bound T_hor p { pc := pc, data := x }

Horizon-bounded safety and peak-frontier propagation for ExecRCodeDist.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.le_haltedReach_assemble {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) {p : RProgram B r} {pc v : ℕ} {d : RData r} (hp : p.Contains pc (c.assemble pc)) :
∑' (y : RData r), μ y * haltedReach w p v d (pc + c.size) y ≤ haltedReach w p v d pc x

Halting-reachability propagation for ExecRCodeDist.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.toExecRProgramDist {B : Basis} {r w L_peak : ℕ} {c : RCode B r} {x : RData r} {μ : PMF (RData r)} {T : ENNReal} (h : ExecRCodeDist w c x μ T L_peak) (out : Fin r) :
ExecRProgramDist w (c.program out) out x μ (T + 1) L_peak

Main Structured-to-Flat Resizable Word RAM Compilation (toExecRProgramDist). Every ExecRCodeDist w c x μ T L_peak certificate compiles via c.program out to ExecRProgramDist w (c.program out) out x μ (T + 1) L_peak.

Lifting frontier-bounded randomized WordRAM.Code executions (ExecRandBounded) #

inductive Cslib.WordRAM.Resizable.ExecRandBounded {B : Basis} {r : ℕ} (w L : ℕ) :
Code B r → Data r → ProbComp (Data r × ℕ) → Prop

Frontier-bounded randomized big-step execution of a structured Code B r. Mirrors Cslib.WordRAM.ExecRand while recording Op.BoundedAccess L o x on every data instruction, allowing any non-allocating randomized subroutine to lift directly to ExecRCodeDist on RCode.ofCode c (and across injective register renamings c.rename f).

theorem Cslib.WordRAM.Resizable.ExecRandBounded.toExecRand {B : Basis} {r w L : ℕ} {c : Code B r} {x : Data r} {m : ProbComp (Data r × ℕ)} (h : ExecRandBounded w L c x m) :
ExecRand w c x m

Forget the address bound L to obtain an ExecRand execution.

theorem Cslib.WordRAM.Resizable.ExecRandBounded.of_execBoundedExact {B : Basis} {r w L n : ℕ} {c : Code B r} {x y : Data r} (h : ExecBoundedExact w L c x y n) :
ExecRandBounded w L c x (pure (y, n))

Embed a deterministic frontier-bounded execution ExecBoundedExact as a point-mass ExecRandBounded.

theorem Cslib.WordRAM.Resizable.ExecRandBounded.seq_of_exec_regOnly {B : Basis} {r w L n₁ : ℕ} {c₁ c₂ : Code B r} {x y : Data r} {m₂ : ProbComp (Data r × ℕ)} (hc₁ : IsRegOnlyCode c₁) (h₁ : Exec w c₁ x y n₁) (h₂ : ExecRandBounded w L c₂ y m₂) :
ExecRandBounded w L (c₁.seq c₂) x ((fun (z : Data r × ℕ) => (z.1, n₁ + z.2)) <$> m₂)

Prepend a register-only deterministic Exec onto an ExecRandBounded.

theorem Cslib.WordRAM.Resizable.ExecRandBounded.rand_seq_det {B : Basis} {r w L : ℕ} {dst src : Fin r} {a : ℕ} {c₂ : Code B r} {x : Data r} {f : Fin (a + 1) → Data r} {n : ℕ} (hs : x.regs src = a) (hfit : Fits w a) (h₂ : ∀ (k : Fin (a + 1)), ExecBoundedExact w L c₂ (x.set dst ↑k) (f k) n) :
ExecRandBounded w L ((Code.rand dst src).seq c₂) x do let k ← ProbComp.unifFin a pure (f k, 1 + n)

A rand instruction followed by a frontier-bounded deterministic ExecBoundedExact suffix.

theorem Cslib.WordRAM.Resizable.ExecRandBounded.rename {B : Basis} {r r' w L : ℕ} {f : Fin r → Fin r'} (hf : Function.Injective f) {c : Code B r} {x : Data r'} {m : ProbComp (Data r × ℕ)} (h : ExecRandBounded w L c (Data.comap f x) m) :
ExecRandBounded w L (Code.rename f c) x ((fun (z : Data r × ℕ) => (Data.extend f z.1 x, z.2)) <$> m)

Rename registers in an ExecRandBounded execution along an injective map f.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.of_execRandBounded {B : Basis} {r w L_peak L : ℕ} {c : Code B r} {x : RData r} {m : ProbComp (Data r × ℕ)} (hL_peak : x.frontier ≤ L_peak) (hL : L ≤ x.frontier) (h : ExecRandBounded w L c x.toData m) :
ExecRCodeDist w (RCode.ofCode c) x (PMF.map (fun (z : Data r × ℕ) => { regs := z.1.regs, mem := z.1.mem, frontier := x.frontier }) m.eval) (m.expect fun (z : Data r × ℕ) => ↑z.2) L_peak

Lift a frontier-bounded randomized execution ExecRandBounded w L c x.toData m directly into ExecRCodeDist on RCode.ofCode c with unchanged hardware frontier x.frontier.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.of_execRandBounded_rename {B : Basis} {r r' w L_peak L : ℕ} {f : Fin r → Fin r'} (hf : Function.Injective f) {c : Code B r} {x : RData r'} {m : ProbComp (Data r × ℕ)} (hL_peak : x.frontier ≤ L_peak) (hL : L ≤ x.frontier) (h : ExecRandBounded w L c (Data.comap f x.toData) m) :
ExecRCodeDist w (RCode.ofCode (Code.rename f c)) x (PMF.map (fun (z : Data r × ℕ) => { regs := (Data.extend f z.1 x.toData).regs, mem := z.1.mem, frontier := x.frontier }) m.eval) (m.expect fun (z : Data r × ℕ) => ↑z.2) L_peak

Lift a frontier-bounded randomized execution ExecRandBounded w L c (x.toData.comap f) m along any injective register renaming f : Fin r → Fin r' directly into ExecRCodeDist on RCode.ofCode (c.rename f), preserving x.frontier.

theorem Cslib.WordRAM.Resizable.ExecRCodeDist.of_execRandBounded_rename_le {B : Basis} {r r' w L_peak L T : ℕ} {f : Fin r → Fin r'} (hf : Function.Injective f) {c : Code B r} {x : RData r'} {m : ProbComp (Data r × ℕ)} (hL_peak : x.frontier ≤ L_peak) (hL : L ≤ x.frontier) (h : ExecRandBounded w L c (Data.comap f x.toData) m) (hT : ∀ z ∈ OracleComp.support m, z.2 ≤ T) :
ExecRCodeDist w (RCode.ofCode (Code.rename f c)) x (PMF.map (fun (z : Data r × ℕ) => { regs := (Data.extend f z.1 x.toData).regs, mem := z.1.mem, frontier := x.frontier }) m.eval) (↑T) L_peak

Worst-case step-bound specialization of ExecRCodeDist.of_execRandBounded_rename.