Documentation

VCVio.EvalDist.Monad.Branch

Conditional branches under measure semantics #

A proposition-valued observation selects between two computations. The resulting measure is the sum of the branch measures weighted by the selector's successful outcome masses. Discarded source values need no measurable space, and failure is kept separate from either branch.

@[simp]
theorem prEvent_false {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {α : Type} (mx : m α) :
𝒟[do let _ ← mx pure False] {True} = 0

An impossible final observation has zero mass, including after a failed computation.

theorem evalDist_bind_prop {m : TypeType v} [Monad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {β : Type} [MeasurableSpace β] (selector : m Prop) (yes no : m β) :
𝒟[do let pselector if p then yes else no] = 𝒟[selector] {True} 𝒟[yes] + 𝒟[selector] {False} 𝒟[no]

Binding a propositional selector gives the two branch measures with their actual masses.

theorem prEvent_not_eq_apply_false {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {α : Type} (mx : m α) (p : αProp) :
𝒟[do let xmx pure ¬p x] {True} = 𝒟[p <$> mx] {False}

An observation's negation is the false mass of the same propositional selector.

theorem prEvent_add_prEvent_not {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {α : Type} (mx : m α) (p : αProp) :
𝒟[do let xmx pure (p x)] {True} + 𝒟[do let xmx pure ¬p x] {True} = 𝒟[p <$> mx] Set.univ

An event and its negation partition the selector's successful mass, including lossy draws.

theorem evalDist_bind_ite {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {α β : Type} [MeasurableSpace β] (mx : m α) (p : αProp) [DecidablePred p] (yes no : m β) :
𝒟[do let xmx if p x then yes else no] = 𝒟[do let xmx pure (p x)] {True} 𝒟[yes] + 𝒟[do let xmx pure ¬p x] {True} 𝒟[no]

A conditional continuation is a mixture weighted by the observed predicate, without a measurable space on discarded source values.

theorem measurable_evalDist_bind_ite {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {ρ : Type u_1} {α β : Type} [MeasurableSpace ρ] [MeasurableSpace β] (mx : ρm α) (p : ραProp) [(r : ρ) → DecidablePred (p r)] (yes no : ρm β) (hobs : Measurable fun (r : ρ) => 𝒟[p r <$> mx r]) (hyes : Measurable fun (r : ρ) => 𝒟[yes r]) (hno : Measurable fun (r : ρ) => 𝒟[no r]) :
Measurable fun (r : ρ) => 𝒟[do let xmx r if p r x then yes r else no r]

Measurable selector measures and branch measures give a measurable conditional family. The family can be bundled by evalDistKernel; discarded source values need no measurable space.

Lossless branches selected by a lossless observation give a lossless computation. The selected output space may be continuous, and the discarded source needs no measurable space.

theorem prEvent_bind_ite {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {α β : Type} (mx : m α) (p : αProp) [DecidablePred p] (yes no : m β) (q : βProp) :
𝒟[do let ydo let xmx if p x then yes else no pure (q y)] {True} = 𝒟[do let xmx pure (p x)] {True} * 𝒟[do let yyes pure (q y)] {True} + 𝒟[do let xmx pure ¬p x] {True} * 𝒟[do let yno pure (q y)] {True}

The event probability of a conditional continuation is the weighted sum of its two branch event probabilities. Each weight retains successful mass.

theorem prEvent_bind_eq_mul_of_ite {m : TypeType v} [Monad m] [LawfulMonad m] [EvalDistSemantics m] [LawfulEvalDistSemantics m] {α β γ : Type} (mx : m α) (f : αm β) (p : αProp) [DecidablePred p] (q : βProp) (my : m γ) (r : γProp) (h : ∀ (x : α), 𝒟[do let yf x pure (q y)] {True} = if p x then 𝒟[do let zmy pure (r z)] {True} else 0) :
𝒟[do let ymx >>= f pure (q y)] {True} = 𝒟[do let xmx pure (p x)] {True} * 𝒟[do let zmy pure (r z)] {True}

A continuation event that is constant on an observed condition and zero otherwise factors through that condition's probability. The reference event may have a different output type.