Documentation

CslibFrontier.Computability.WordRAM.Randomized.LoopSegmentLaw

Observation laws for randomized loop segments #

LoopSegmentLaw packages the existing LoopSegment execution relation with an exact observation law, a supported-path instruction bound and a pathwise random-query bound. The witness still contains the complete joint distribution of native data and instruction count. No additional execution semantics or expected-time relaxation is introduced.

Segments may stop while the loop condition still holds. Closing a segment into a complete loop requires the explicit exit postcondition and charges the final two instructions.

Main definitions #

Main results #

References #

Original packaging of the existing LoopSegment and ExecRandLaw interfaces.

def Cslib.WordRAM.LoopSegmentLaw {B : Basis} {r : ℕ} {α : Type} (w : ℕ) (cond : Cond r) (body : Code B r) (x : Data r) (P : Data r → Prop) (T R : ℕ) (f : Data r → α) (μ : PMF α) :

A finite loop segment using at most T instructions on every supported path, with a pathwise random-call bound and the exact law of an observation of its final data.

theorem Cslib.WordRAM.LoopSegmentLaw.nil {B : Basis} {r : ℕ} {α : Type} {w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {P : Data r → Prop} {f : Data r → α} (hx : P x) :
LoopSegmentLaw w cond body x P 0 0 f (PMF.pure (f x))

Zero iterations observe the starting data and use no instructions or random calls.

theorem Cslib.WordRAM.LoopSegmentLaw.mono {B : Basis} {r : ℕ} {α : Type} {w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {P Q : Data r → Prop} {T T' R R' : ℕ} {f : Data r → α} {μ : PMF α} (h : LoopSegmentLaw w cond body x P T R f μ) (hPQ : ∀ (y : Data r), P y → Q y) (hT : T ≤ T') (hR : R ≤ R') :
LoopSegmentLaw w cond body x Q T' R' f μ

Enlarge budgets and weaken the supported-path postcondition.

theorem Cslib.WordRAM.LoopSegmentLaw.congr_law {B : Basis} {r : ℕ} {α : Type} {w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {P : Data r → Prop} {T R : ℕ} {f : Data r → α} {μ μ' : PMF α} (h : LoopSegmentLaw w cond body x P T R f μ) (hμ : μ = μ') :
LoopSegmentLaw w cond body x P T R f μ'

Rewrite only the exact observation law.

theorem Cslib.WordRAM.LoopSegmentLaw.single {B : Basis} {r : ℕ} {α : Type} {w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {P : Data r → Prop} {T R : ℕ} {f : Data r → α} {μ : PMF α} (hc : cond.Holds x) (h : ExecRandLaw w body x P T R f μ) :
LoopSegmentLaw w cond body x P (T + 2) R f μ

A single active body execution pays the existing two-instruction loop-header allowance.

theorem Cslib.WordRAM.LoopSegmentLaw.trans {B : Basis} {r : ℕ} {α β : Type} {w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {P Q : Data r → Prop} {T₁ T₂ R₁ R₂ : ℕ} {f : Data r → α} {g : Data r → β} {ν : PMF β} {κ : β → PMF α} (h₁ : LoopSegmentLaw w cond body x P T₁ R₁ g ν) (h₂ : ∀ (y : Data r), P y → LoopSegmentLaw w cond body y Q T₂ R₂ f (κ (g y))) :
LoopSegmentLaw w cond body x Q (T₁ + T₂) (R₁ + R₂) f (ν.bind κ)

Segment laws compose through the observed intermediate state. The continuation witness is chosen per state; no uniqueness of partial loop segments is assumed.

theorem Cslib.WordRAM.LoopSegmentLaw.finish {B : Basis} {r : ℕ} {α : Type} {w : ℕ} {cond : Cond r} {body : Code B r} {x : Data r} {P : Data r → Prop} {T R : ℕ} {f : Data r → α} {μ : PMF α} (h : LoopSegmentLaw w cond body x P T R f μ) (hexit : ∀ (y : Data r), P y → ¬cond.Holds y) :
ExecRandLaw w (Code.loop cond body) x P (T + 2) R f μ

An explicit supported exit condition closes the loop and pays its final exit check.