@@ -12,6 +12,7 @@ public import RandomDo.Tactic.IsMarkov.ForInStep
1212public import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
1313public import Mathlib.Data.List.OfFn
1414public import Mathlib.Probability.Distributions.Gaussian.Real
15+ public import Mathlib.Probability.Distributions.Bernoulli
1516
1617/-!
1718# Markov property of `rdo` programs
@@ -31,6 +32,8 @@ complex program to the Markov property/measurability of its underlying mathemati
3132 the bound variable is Markovian in the parameter.
3233* `gaussianReal`: A Gaussian distribution whose mean and variance depend measurably on the parameter
3334 is Markovian in the parameter.
35+ * `bernoulliMeasure`: A Bernoulli distribution whose two outcomes and probability depend measurably
36+ on the parameter is Markovian in the parameter.
3437* `comp`: Composing a Markov kernel `κ` with a measurable function `g` is Markovian in the
3538 parameter.
3639* `ite`: A conditional `rdo` program that chooses between two Markov kernels `κ` and `η` based on a
@@ -43,6 +46,7 @@ complex program to the Markov property/measurability of its underlying mathemati
4346* `forInList_comp`, `forInArray_comp`, `forInVector_comp`: The same three, for a loop over a
4447 collection the program takes as an argument. The body is then asked to be Markovian jointly in the
4548 parameter and in the element, which the fixed collections do not need.
49+ * `forIn_nil`, `forIn_cons`: A `for` loop over a list, unrolled one element at a time.
4650* `breakRunK`: The case analysis a program performs after a loop that returns early, on the `Option`
4751 slot holding the returned value, is Markovian as soon as both of its branches are.
4852 -/
@@ -51,6 +55,7 @@ complex program to the Markov property/measurability of its underlying mathemati
5155
5256open MeasureTheory ProbabilityTheory Function
5357open MeasurableSpacePure
58+ open scoped ENNReal
5459
5560namespace IsMarkov
5661
@@ -91,6 +96,18 @@ lemma gaussianReal {m : γ → ℝ} {v : γ → NNReal} (hm : Measurable m) (hv
9196 IsMarkov fun c ↦ ProbabilityTheory.gaussianReal (m c) (v c) :=
9297 ⟨ProbabilityTheory.measurable_gaussianReal.comp (hm.prodMk hv), fun _ ↦ inferInstance⟩
9398
99+ lemma bernoulliMeasure {x y : γ → α} {p : γ → unitInterval} (hx : Measurable x)
100+ (hy : Measurable y) (hp : Measurable p) :
101+ IsMarkov fun c ↦ ProbabilityTheory.bernoulliMeasure (x c) (y c) (p c) := by
102+ refine ⟨Measure.measurable_of_measurable_coe _ fun s hs ↦ ?_, fun _ ↦ inferInstance⟩
103+ simp only [bernoulliMeasure_def, Measure.add_apply, Measure.smul_apply,
104+ Measure.dirac_apply' _ hs, ENNReal.smul_def, smul_eq_mul]
105+ have hp' : Measurable fun c ↦ ((unitInterval.toNNReal (p c) : ℝ≥0 ∞)) := by fun_prop
106+ have hq' : Measurable fun c ↦ ((unitInterval.toNNReal (unitInterval.symm (p c)) : ℝ≥0 ∞)) := by
107+ fun_prop
108+ exact (hp'.mul ((measurable_one.indicator hs).comp hx)).add
109+ (hq'.mul ((measurable_one.indicator hs).comp hy))
110+
94111lemma comp {κ : γ → Measure α} (hκ : IsMarkov κ) {g : σ → γ} (hg : Measurable g) :
95112 IsMarkov fun c ↦ κ (g c) := ⟨hκ.measurable.comp hg, fun _ ↦ hκ.isProbabilityMeasure _⟩
96113
@@ -228,11 +245,14 @@ private lemma forIn_eq_listLoop (l : List ι) (b : σ) (g : ι → σ → Measur
228245 MeasurableSpaceForIn.forIn (m := Measure) l b g = listLoop g l b :=
229246 loop_eq_listLoop g l b l _ (fun _ _ _ ↦ rfl) ⟨[], rfl⟩
230247
231- private lemma forIn_nil (b : σ) (g : ι → σ → Measure (ForInStep σ)) :
248+ /-- A `for` loop over the empty list returns its initial state. -/
249+ lemma forIn_nil (b : σ) (g : ι → σ → Measure (ForInStep σ)) :
232250 MeasurableSpaceForIn.forIn (m := Measure) ([] : List ι) b g = mPure b :=
233251 forIn_eq_listLoop _ _ _
234252
235- private lemma forIn_cons (a : ι) (l : List ι) (b : σ) (g : ι → σ → Measure (ForInStep σ)) :
253+ /-- A `for` loop over `a :: l` runs its body on `a`, then stops or carries on with the loop over
254+ `l`. -/
255+ lemma forIn_cons (a : ι) (l : List ι) (b : σ) (g : ι → σ → Measure (ForInStep σ)) :
236256 MeasurableSpaceForIn.forIn (m := Measure) (a :: l) b g
237257 = g a b >>=ₘ fun step ↦ ForInStep.casesOn (motive := fun _ ↦ Measure σ) step mPure
238258 fun b' ↦ MeasurableSpaceForIn.forIn (m := Measure) l b' g := by
0 commit comments