Compositional while-loop segments for structured randomized word-RAM programs #
Cslib.WordRAM.LoopSegment w cond body x m represents executing zero or more active iterations of
Code.loop cond body starting at machine state x : Data r and producing the randomized
state-time distribution m : ProbComp (Data r × ℕ), without yet performing the final loop-exit
condition check.
Whereas ExecRand.loop_iter and ExecRand.loop_exit require each iteration to continue all the
way to termination of the enclosing loop (¬cond.Holds), LoopSegment packages multi-iteration
sub-runs that may finish in states where cond.Holds still holds. This allows explicit call-stack
algorithms (such as Karger and Stein's recursive FastCut simulated inside a single while sp > 0
loop) to prove frame execution by structural induction on stack depth sp = b + 1 → b, compose
sibling recursive subtrees via LoopSegment.trans, and discharge the outer while sp > 0 loop at
depth b = 0 via LoopSegment.finish.
Main definitions #
Cslib.WordRAM.LoopSegment: multi-iteration execution segments ofCode.loop cond bodybefore loop exit.
Main results #
Cslib.WordRAM.LoopSegment.single,Cslib.WordRAM.LoopSegment.detSingle: single randomized or deterministic loop iteration (+ 2loop-header instructions).Cslib.WordRAM.LoopSegment.trans,Cslib.WordRAM.LoopSegment.trans_exists,Cslib.WordRAM.LoopSegment.stepDet: transitive and deterministic-prefix sequential composition of loop segments.Cslib.WordRAM.LoopSegment.finish: closes aLoopSegmentintoExecRand w (.loop cond body)once every supported output violatescond(+ 2instructions for the final exit check).Cslib.WordRAM.LoopSegment.regs_eq,Cslib.WordRAM.LoopSegment.bounded: register preservation and word-bound invariance across aLoopSegment.Cslib.WordRAM.execRand_seq_det: appends a deterministicExecWithincontinuation onto a randomizedExecRandcomputation as a pureFunctor.map.
References #
LoopSegment w cond body x m: starting at data x, executing zero or more iterations of
Code.loop cond body (each verifying cond.Holds, running body, and charging + 2 for the loop
header test and back-jump) without yet taking the loop-exit check produces m.
Enables structural induction on explicit call-stack depth inside a single outer while sp > 0
loop, where popping a recursive frame lowers sp from b + 1 to b without exiting the loop when
b > 0.
- nil {B : Basis} {r w : ℕ} {cond : Cond r} {body : Code B r} (x : Data r) : LoopSegment w cond body x (pure (x, 0))
Zero iterations, charging
0instructions. - step {B : Basis} {r w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {mb : ProbComp (Data r × ℕ)} {mr : Data r → ProbComp (Data r × ℕ)} (hc : cond.Holds x) (hb : ExecRand w body x mb) (hr : ∀ z ∈ OracleComp.support mb, LoopSegment w cond body z.1 (mr z.1)) : LoopSegment w cond body x do
let z₁ ← mb
let z₂ ← mr z₁.1
pure (z₂.1, z₁.2 + z₂.2 + 2)
One active loop iteration followed by a continuation segment.
Instances For
Sequential composition of two loop segments.
Existential sequential composition of two loop segments using Classical.choose.
Prepending a deterministic single iteration onto a continuation LoopSegment.
Closing a LoopSegment into ExecRand w (.loop cond body) once every supported state
violates cond (+ 2 instructions for the final loop-exit check).
Any register preserved by body is preserved along every LoopSegment.
LoopSegment preserves Data.Bounded w on every supported path.
Append a deterministic ExecWithin continuation onto a randomized ExecRand computation as a
pure Functor.map.