Documentation

CslibFrontier.Computability.WordRAM.Randomized.SampleBits

Acceptance observation and uniform bit-slice sampling on the randomized word RAM #

Shared acceptance and bit-sampling primitives for randomized word-RAM algorithms:

Main definitions #

Main results #

Acceptance observation on RandCfg #

Whether a randomized machine configuration halted with output 1.

@[simp]
theorem Cslib.WordRAM.RandCfg.accepts_halted {r : ℕ} (v : ℕ) (d : Data r) :
(halted v d).accepts = decide (v = 1)

Reading and sampling Boolean vectors #

def Cslib.WordRAM.bitsAt (mem : ℕ → ℕ) (base n : ℕ) :
Fin n → Bool

Read n words starting at base as a Boolean vector (true when the word equals 1).

theorem Cslib.WordRAM.bitsAt_update_self {n : ℕ} (mem : ℕ → ℕ) (base : ℕ) (i : Fin n) (v : ℕ) :
bitsAt (Function.update mem (base + ↑i) v) base n = Function.update (bitsAt mem base n) i (decide (v = 1))

Writing v at base + i updates coordinate i of bitsAt mem base n.

def Cslib.WordRAM.sampleBits {r : ℕ} (zero one baseReg nReg cnt val addr : Fin r) :

Sample n = regs nReg independent uniform bits via rand one into [regs baseReg, regs baseReg + n), using cnt, val and addr as scratch registers.

@[simp]
theorem Cslib.WordRAM.preserves_sampleBits {r : ℕ} {zero one baseReg nReg cnt val addr i : Fin r} :
Code.Preserves i (sampleBits zero one baseReg nReg cnt val addr) ↔ i ≠ cnt ∧ i ≠ val ∧ i ≠ addr
theorem Cslib.WordRAM.sampleBits_law {r w base n : ℕ} {zero one baseReg nReg cnt val addr : Fin r} (hdistinct : [one, baseReg, nReg, cnt, val, addr].Nodup) (hw1 : Fits w 1) (hw_end : Fits w (base + n)) {x : Data r} (hz : x.regs zero = 0) (ho : x.regs one = 1) (hbReg : x.regs baseReg = base) (hn : x.regs nReg = n) :
ExecRandLaw w (sampleBits zero one baseReg nReg cnt val addr) x (fun (y : Data r) => (∀ i < n, y.mem (base + i) ≤ 1) ∧ (∀ (a : ℕ), ¬(base ≤ a ∧ a < base + n) → y.mem a = x.mem a) ∧ ∀ (i : Fin r), i ≠ cnt → i ≠ val → i ≠ addr → y.regs i = x.regs i) (6 * n + 3) n (fun (y : Data r) => bitsAt y.mem base n) (Probability.PMF.uniformOfFintype (Fin n → Bool))

Uniform bit-slice sampling. When [one, baseReg, nReg, cnt, val, addr] are distinct registers with regs zero = 0, regs one = 1, regs baseReg = base and regs nReg = n, sampleBits halts within 6 * n + 3 instructions and n rand calls, writes 0/1 words across [base, base + n) whose bitsAt view is distributed uniformly on Fin n → Bool, leaves memory outside [base, base + n) unchanged, and preserves all registers outside {cnt, val, addr}.

Query-bound transfer for fixed-register rand calls #

def Cslib.WordRAM.Code.usesRandSrc {B : Basis} {r : ℕ} (s : Fin r) :
Code B r → Bool

Syntactic check that every rand instruction in c reads register s.

@[simp]
theorem Cslib.WordRAM.usesRandSrc_sampleBits {r : ℕ} {zero one baseReg nReg cnt val addr s : Fin r} :
Code.usesRandSrc s (sampleBits zero one baseReg nReg cnt val addr) = (one == s)
theorem Cslib.WordRAM.ExecRand.queriesSatisfy_eq_of_usesRandSrc {B : Basis} {r w u : ℕ} {s : Fin r} {c : Code B r} {x : Data r} {m : ProbComp (Data r × ℕ)} (h : ExecRand w c x m) (hs : x.regs s = u) (hp : Code.Preserves s c) (hu : Code.usesRandSrc s c = true) :
OracleComp.QueriesSatisfy (fun (x : ℕ) => x = u) m

When c preserves register s holding u and every rand in c reads s, every oracle query issued along ExecRand w c x m equals u.