@@ -157,10 +157,9 @@ variable {k : ℕ} {L : FinRV n (Fin k)}
157157theorem indi_eq_indr : ∀i : Fin k, (𝕀 ∘ (L =ᵣ i)) = (L =ᵢ i) := by
158158 intro i; unfold FinRV.eq FinRV.eqi 𝕀 indicator; ext ω; by_cases h: L ω = i; repeat simp [h]
159159
160-
161160variable {B : FinRV n Bool}
162161/-- Indicator is 0 or 1 -/
163- theorem ind_zero_one : ∀ ω, (𝕀∘B) ω = 1 ∨ (𝕀∘B) ω = 0 := by
162+ theorem ind_zero_one : ∀ ω, (𝕀∘B) ω = 1 ∨ (𝕀∘B) ω = 0 := by
164163 intro ω
165164 by_cases h : B ω
166165 · left; simp only [Function.comp_apply, h, indicator]
@@ -190,14 +189,12 @@ theorem one_of_ind_bool_or_not : (𝕀∘B) + (𝕀∘(¬ᵣ B)) = (1 : FinRV n
190189 · simp [h]
191190 · simp [h]
192191
193- variable {X Y: FinRV n ℚ}
192+ variable {X Y: FinRV n ℚ} {Xs : Fin k → FinRV n ℚ}
194193
195194theorem rv_le_abs : X ≤ abs ∘ X := by intro i; simp [le_abs_self (X i)]
196195
197- theorem rv_prod_sum_additive {Xs : Fin k → FinRV n ℚ} : ∑ i, Y * (Xs i) = Y * (∑ i, Xs i) :=
198- by ext ω
199- simp
200- rw [Finset.mul_sum]
196+ theorem rv_prod_sum_additive : ∑ i, Y * (Xs i) = Y * (∑ i, Xs i) :=
197+ by ext ω; simp [Finset.mul_sum]
201198
202199variable {g : Fin k → ℚ}
203200
@@ -221,9 +218,6 @@ notation "ℙ[" B "//" P "]" => probability P B
221218-- helps to refold is when needed
222219lemma probability_def : P.p ⬝ᵥ (𝕀 ∘ B) = ℙ[B // P] := rfl
223220
224- -- TODO: the sorry in the definition has to do with the decidability of the membership
225- --theorem prob_iprod_eq_def : ℙ[B // P] = P.measure (B.preimage true) sorry := sorry
226-
227221/-- Conditional probability of B -/
228222def probability_cnd : ℚ := ℙ[B * C // P] / ℙ[ C // P ]
229223
@@ -234,8 +228,7 @@ notation "ℙ[" B "|" C "//" P "]" => probability_cnd P B C
234228
235229theorem prob_one_of_true : ℙ[1 // P] = 1 :=
236230 by unfold probability
237- rw[one_of_true]
238- rw [dotProduct_comm]
231+ rewrite [one_of_true, dotProduct_comm]
239232 exact P.prob
240233
241234example {a b : ℚ} (h : 0 ≤ a) (h2 : 0 ≤ b) : 0 ≤ a * b := Rat.mul_nonneg h h2
@@ -245,7 +238,6 @@ variable {P : Findist n} {B : FinRV n Bool}
245238theorem prod_zero_of_prob_zero : ℙ[B // P] = 0 → (P.p * (𝕀∘B) = 0 ) := by
246239 intro h; exact prod_eq_zero_of_nneg_dp_zero P.nneg ind_nneg h
247240
248-
249241------------------------------ PMF ---------------------------
250242
251243/-- Proof that p is a the PMF of X on probability space P -/
@@ -254,6 +246,15 @@ def PMF {K : ℕ} (pmf : Fin K → ℚ) (P : Findist n) (L : FinRV n (Fin K)) :=
254246
255247namespace PMF
256248
249+ variable {n : ℕ} {k : ℕ} {L : FinRV n (Fin k)}
250+ variable {pmf : Fin k → ℚ} {P : Findist n}
251+
252+ theorem pmf_rv_k_ge_1 (h : PMF pmf P L) : 0 < k :=
253+ match k with
254+ | Nat.zero => Fin.pos <| L ⟨0 ,P.nonempty⟩
255+ | Nat.succ k₂ => Nat.zero_lt_succ k₂
256+
257+
257258
258259end PMF
259260
@@ -270,7 +271,6 @@ Main results
270271 -/
271272
272273
273- namespace Ex
274274
275275
276276variable {n : ℕ} (P : Findist n) (X Y Z: FinRV n ℚ) (B : FinRV n Bool)
@@ -302,15 +302,15 @@ def expect_cnd_rv : Fin n → ℚ := fun i ↦ 𝔼[ X | L =ᵣ (L i) // P ]
302302
303303notation "𝔼[" X "|ᵣ" L "//" P "]" => expect_cnd_rv P X L
304304
305- end Ex
305+
306306--- some basic properties
307307
308308section Expectation_properties
309309variable {P : Findist n} {X Y Z: FinRV n ℚ} {B : FinRV n Bool}
310310
311311theorem exp_congr : (X = Y) → 𝔼[X // P] = 𝔼[Y // P] :=
312312 by intro h
313- unfold Ex. expect dotProduct
313+ unfold expect dotProduct
314314 apply Fintype.sum_congr
315315 simp_all
316316
@@ -320,40 +320,40 @@ theorem exp_mul_comm : 𝔼[X * Y // P] = 𝔼[Y * X // P] := exp_congr (CommMon
320320variable {c : ℚ} {p : Fin n → ℚ}
321321
322322theorem exp_const : 𝔼[(fun _ ↦ c) // P] = c :=
323- by unfold Ex. expect
324- rw [rv_const_fun_to_one]
325- simp only [dotProduct_smul, smul_eq_mul]
326- rw [dotProduct_comm, P.prob]
327- simp
323+ by unfold expect
324+ rw [rv_const_fun_to_one]
325+ simp only [dotProduct_smul, smul_eq_mul]
326+ rw [dotProduct_comm, P.prob]
327+ simp
328328
329329theorem exp_one : 𝔼[ 1 // P] = 1 := exp_const
330330
331331theorem exp_cond_eq_def : 𝔼[X | B // P] * ℙ[B // P] = 𝔼[X * (𝕀 ∘ B) // P] :=
332- by unfold Ex. expect_cnd
333- by_cases h: ℙ[B//P] = 0
334- · rw [h, Rat.mul_zero]
335- unfold Ex. expect
336- rw [dotProd_hadProd_comm, dotProd_hadProd_rotate, prod_zero_of_prob_zero h]
337- exact (dotProduct_zero X).symm
338- · simp_all
332+ by unfold expect_cnd
333+ by_cases h: ℙ[B//P] = 0
334+ · rw [h, Rat.mul_zero]
335+ unfold expect
336+ rw [dotProd_hadProd_comm, dotProd_hadProd_rotate, prod_zero_of_prob_zero h]
337+ exact (dotProduct_zero X).symm
338+ · simp_all
339339
340340
341341lemma constant_mul_eq_smul : (fun ω ↦ c * X ω) = c • X := rfl
342342
343343theorem exp_prod_const_fun : 𝔼[(λ _ ↦ c) * X // P] = c * 𝔼[X // P] :=
344- by simp only [Ex. expect, Pi.mul_def, constant_mul_eq_smul, dotProduct_smul, smul_eq_mul]
344+ by simp only [expect, Pi.mul_def, constant_mul_eq_smul, dotProduct_smul, smul_eq_mul]
345345
346346theorem exp_indi_eq_exp_indr : ∀i : Fin k, 𝔼[L =ᵢ i // P] = 𝔼[𝕀 ∘ (L =ᵣ i) // P] := by
347347 intro i; rw [indi_eq_indr]
348348
349349/-- Expectation is homogeneous under product -/
350- theorem exp_homogenous : 𝔼[c • X // P] = c * 𝔼[X // P] := by simp only [Ex. expect, dotProduct_smul, smul_eq_mul]
350+ theorem exp_homogenous : 𝔼[c • X // P] = c * 𝔼[X // P] := by simp only [expect, dotProduct_smul, smul_eq_mul]
351351
352- theorem exp_dists_add : 𝔼[X + Y // P] = 𝔼[X // P] + 𝔼[Y // P] := by simp [Ex. expect]
352+ theorem exp_dists_add : 𝔼[X + Y // P] = 𝔼[X // P] + 𝔼[Y // P] := by simp [expect]
353353
354354/-- Additivity of expectation --/
355355theorem exp_additive {m : ℕ} (Xs : Fin m → FinRV n ℚ) : 𝔼[∑ i : Fin m, Xs i // P] = ∑ i : Fin m, 𝔼[Xs i // P] :=
356- by unfold Ex. expect; exact dotProduct_sum P.p Finset.univ Xs
356+ by unfold expect; exact dotProduct_sum P.p Finset.univ Xs
357357
358358/-- Expectation is monotone -/
359359theorem exp_monotone (h: X ≤ Y) : 𝔼[X // P] ≤ 𝔼[Y // P] := dotProduct_le_dotProduct_of_nonneg_left h P.nneg
@@ -371,9 +371,9 @@ theorem exp_decompose : 𝔼[X // P] = ∑ i, 𝔼[X * (L =ᵢ i) // P] :=
371371/-- Expectation of a conditional constant. Only when probability is positive. -/
372372theorem exp_cond_const : ∀ i, ℙ[L =ᵣ i // P] ≠ 0 → 𝔼[g ∘ L | L =ᵣ i // P] = g i :=
373373 by intro i h
374- unfold Ex. expect_cnd
374+ unfold expect_cnd
375375 rw [indi_eq_indr, rv_prod_const i, exp_homogenous]
376- rw [←indi_eq_indr, ←Ex. prob_eq_exp_ind]
376+ rw [←indi_eq_indr, ←prob_eq_exp_ind]
377377 simp only [h, ne_eq, isUnit_iff_ne_zero, not_false_eq_true, IsUnit.mul_div_cancel_right]
378378
379379end Expectation_properties
0 commit comments