@@ -16,34 +16,50 @@ import Mathlib.Data.Fintype.BigOperators
1616
1717namespace Findist
1818
19- variable {n : ℕ} ( P : Findist n) ( B : FinRV n Bool)
19+ variable {n : ℕ} { P : Findist n} { B : FinRV n Bool}
2020
21- -- TODO: is there a way to simplify this result to not use induction?
22- theorem in_prob (P : Findist n) : Prob ℙ[B // P] := sorry
2321
24- theorem ge_zero : ℙ[ B // P ] ≥ 0 := (P.in_prob B).left
22+ theorem ge_zero : 0 ≤ ℙ[ B // P ] :=
23+ by rw [Ex.prob_eq_exp_ind]
24+ have h : (0 : FinRV n ℚ) ≤ 𝕀∘B := ind_nneg
25+ calc 0 = 𝔼[0 // P] := exp_const.symm
26+ _ ≤ 𝔼[𝕀 ∘ B//P] := exp_monotone h
27+
2528
26- theorem le_one : ℙ[B // P] ≤ 1 := (P.in_prob B).right
29+ theorem le_one : ℙ[B // P] ≤ 1 :=
30+ by rw [Ex.prob_eq_exp_ind]
31+ have h : 𝕀∘B ≤ (1 : FinRV n ℚ) := ind_le_one
32+ calc 𝔼[𝕀 ∘ B//P] ≤ 𝔼[1 // P] := exp_monotone h
33+ _ = 1 := exp_const
34+
35+ theorem in_prob (P : Findist n) : Prob ℙ[B // P] := ⟨ge_zero, le_one⟩
2736
2837end Findist
2938
30- ------------------------------ Probablity ---------------------------
39+ ------------------------------ Probability ---------------------------
3140
3241namespace Pr
3342
34- variable {n : ℕ} (P : Findist n) (B C : FinRV n Bool)
43+ variable {n : ℕ} {P : Findist n} {B C : FinRV n Bool}
44+
45+
46+ theorem prob_compl_sums_to_one : ℙ[B // P] + ℙ[¬ᵣB // P] = 1 :=
47+ by rw [Ex.prob_eq_exp_ind, Ex.prob_eq_exp_ind]
48+ rw [←exp_dists_add]
49+ rw [one_of_ind_bool_or_not]
50+ exact exp_one
3551
36- theorem prob_compl_sums_to_one : ℙ[B // P] + ℙ[¬ᵣB // P] = 1 := sorry
52+
3753
3854theorem prob_compl_one_minus : ℙ[¬ᵣB // P] = 1 - ℙ[B // P] :=
39- by have := prob_compl_sums_to_one P B
55+ by have := prob_compl_sums_to_one (P:=P) (B:=B)
4056 linarith
4157
42- @[simp]
43- lemma refold_probability : P.p ⬝ᵥ (𝕀 ∘ B) = ℙ[B // P] := rfl
4458
45- theorem law_of_total_probs_bool : ℙ[B // P] = ℙ[B * C // P] + ℙ[B * (¬ᵣC) // P] :=
46- by
59+ -- TODO: I think that we can show the following results from the law of total expectations
60+
61+ --TODO: theorem law_of_total_probs_bool : ℙ[B // P] = ℙ[B * C // P] + ℙ[B * (¬ᵣC) // P] :=
62+ /- by
4763 unfold probability
4864 have h : ∀ i : Fin n, (𝕀 (B i)) = (𝕀 (B i * C i)) + (𝕀 (B i * (¬ᵣ C) i)) :=
4965 by
@@ -56,10 +72,9 @@ theorem law_of_total_probs_bool : ℙ[B // P] = ℙ[B * C // P] + ℙ[B * (¬ᵣ
5672 · simp [hB, hC, FinRV.not, indicator]
5773 · simp [hB, hC, FinRV.not, indicator]
5874 sorry ---I tried to do this proof but got stuck, feel free to delete my work
75+ -/
5976
60-
61- theorem conditional_total (h : 0 < ℙ[C // P]) : ℙ[B * C // P] = ℙ[B | C // P] * ℙ[C // P] :=
62- sorry
77+ --TODO: theorem conditional_total (h : 0 < ℙ[C // P]) : ℙ[B * C // P] = ℙ[B | C // P] * ℙ[C // P] :=
6378 -- by simp [ probability_cnd ] at ⊢ h
6479 -- have : P.ℙ.iprodb C * (P.ℙ.iprodb C)⁻¹ = 1 :=
6580 -- Rat.mul_inv_cancel (P.ℙ.iprodb C) (Ne.symm (ne_of_lt h))
@@ -69,17 +84,17 @@ theorem conditional_total (h : 0 < ℙ[C // P]) : ℙ[B * C // P] = ℙ[B | C /
6984 -- _ = P.ℙ.iprodb (B ∧ᵣ C) / P.ℙ.iprodb C * P.ℙ.iprodb C := by ring
7085
7186
72- theorem law_total_prbs_cnd (h1 : 0 < ℙ[C // P]) (h2 : ℙ[C // P] < 1 )
73- : ℙ[B // P] = ℙ[B | C // P] * ℙ[ C // P] + ℙ[B | ¬ᵣC // P] * ℙ[¬ᵣC // P] :=
74- by have h2' : 0 < ℙ[¬ᵣC // P] := by rw [prob_compl_one_minus]; linarith
75- rw [←conditional_total P B C h1]
76- rw [←conditional_total P B (¬ᵣC) h2']
77- exact law_of_total_probs_bool P B C
87+ --TODO: theorem law_total_prbs_cnd (h1 : 0 < ℙ[C // P]) (h2 : ℙ[C // P] < 1)
88+ -- : ℙ[B // P] = ℙ[B | C // P] * ℙ[ C // P] + ℙ[B | ¬ᵣC // P] * ℙ[¬ᵣC // P] :=
89+ -- by have h2' : 0 < ℙ[¬ᵣC // P] := by rw [ prob_compl_one_minus ] ; linarith
90+ -- rw [←conditional_total P B C h1]
91+ -- rw [←conditional_total P B (¬ᵣC) h2']
92+ -- exact law_of_total_probs_bool P B C
7893
7994variable {k : ℕ} {L : FinRV n (Fin k)}
8095
81- -- TODO: we will prove this from the law for expectations
82- theorem law_of_total_probs : ∑ i : Fin k, ℙ[B * (L =ᵣ i) // P] = ℙ[B // P] := sorry
96+ -- TODO: we can prove this from the law for expectations
97+ -- TODO: theorem law_of_total_probs : ∑ i : Fin k, ℙ[B * (L =ᵣ i) // P] = ℙ[B // P] := sorry
8398
8499end Pr
85100
@@ -148,7 +163,7 @@ theorem fin_sum_g: ∀ ω, ∑ i, (g i) * (𝕀 ∘ (L =ᵣ i)) ω = g (L ω) :=
148163variable {ρ : Type } [AddCommMonoid ρ]
149164
150165/-- Linearity of expectation --/
151- theorem expect_linear {m : ℕ} (Xs : Fin m → FinRV n ℚ) : 𝔼[∑ i : Fin m, Xs i // P] = ∑ i : Fin m, 𝔼[Xs i // P] :=
166+ theorem exp_linear {m : ℕ} (Xs : Fin m → FinRV n ℚ) : 𝔼[∑ i : Fin m, Xs i // P] = ∑ i : Fin m, 𝔼[Xs i // P] :=
152167 by unfold expect
153168 exact dotProduct_sum P.p Finset.univ Xs
154169
@@ -160,7 +175,7 @@ theorem fin_sum_simple : (g ∘ L) = ∑ i, (fun _ ↦ g i) * (L =ᵢ i) :=
160175theorem idktheorem (P : Findist n) (L : FinRV n (Fin k)) (g : Fin k → ℚ) :
161176 𝔼[g ∘ L // P] = ∑ i : Fin k, g i * ℙ[L =ᵣ i // P] := by
162177 rw [fin_sum_simple]
163- rw [expect_linear ]
178+ rw [exp_linear ]
164179 apply Fintype.sum_congr
165180 intro a
166181 rw [exp_prod_const_fun]
@@ -182,7 +197,9 @@ theorem LOTUS {g : Fin k → ℚ} (h : PMF pmf P L):
182197-- this proof will rely on the extensional property of function (functions are the same if they
183198-- return the same value for the same inputs; for all inputs)
184199theorem condexp_pmf : 𝔼[ X |ᵣ L // P] = (fun i ↦ 𝔼[ X | (L =ᵣ i) // P]) ∘ L :=
185- by sorry
200+ by unfold expect_cnd_rv
201+ ext ω; simp
202+
186203
187204
188205theorem expexp : 𝔼[ 𝔼[ X |ᵣ L // P] // P ] = ∑ i : Fin k, 𝔼[ X | L =ᵣ i // P] * ℙ[ L =ᵣ i // P] := by
@@ -195,32 +212,34 @@ theorem expexp : 𝔼[ 𝔼[ X |ᵣ L // P] // P ] = ∑ i : Fin k, 𝔼[ X | L
195212
196213-- STEP 2:
197214
198- theorem μ_eq_zero_of_cond_empty (h : ℙ[B // P] = 0 ) : ∀ X, 𝔼[X * (𝕀 ∘ B) // P] = 0 := sorry
199-
200215example (a : ℚ) : a * 0 = 0 := Rat.mul_zero a
201216
202217theorem exp_prod_μ : 𝔼[X | B // P] * ℙ[B // P] = 𝔼[X * (𝕀 ∘ B) // P] :=
203- by unfold expect_cnd
218+ by unfold expect_cnd
204219 by_cases h: ℙ[B//P] = 0
205220 · rw [h, Rat.mul_zero]
206- sorry
207- · sorry
208- --simp_all only [isUnit_iff_ne_zero, ne_eq, not_false_eq_true,
209- -- IsUnit.div_mul_cancel]
221+ unfold expect
222+ rw [dotProd_hadProd_comm, dotProd_hadProd_rotate, prod_zero_of_prob_zero h]
223+ exact (dotProduct_zero X).symm
224+ · simp_all
210225
211226-- STEP 3:
212- -- proves that μ distributes over the random variables
213- theorem μ_dist (h : Fin k → FinRV n ℚ) : ∑ i : Fin k, 𝔼[X * (h i) // P] = 𝔼[X * (fun ω ↦ ∑ i : Fin k, (h i) ω) // P] := sorry
214227
228+ example (Xs : Fin k → FinRV n ℚ) : (fun ω ↦ ∑ i, Xs i ω) = ∑ i, Xs i := by exact Eq.symm (Finset.sum_fn Finset.univ Xs)
229+
230+ -- proves that μ distributes over the random variables
231+ theorem μ_dist (Xs : Fin k → FinRV n ℚ) : ∑ i : Fin k, 𝔼[X * (Xs i) // P] = 𝔼[X * (fun ω ↦ ∑ i : Fin k, Xs i ω) // P] := by
232+ rw [←Finset.sum_fn Finset.univ Xs]
233+ rw [←rv_prod_sum_linear]
234+ rw [exp_linear]
215235
216- -- TODO: need to sum all probabilities
217236
218237
219238theorem fin_sum : ∀ ω : Fin n, ∑ i : Fin k, (𝕀 ∘ (L =ᵣ i)) ω = (1 :ℚ) :=
220239 by have := fin_sum_g 1 (L := L)
221240 simp_all only [Pi.one_apply, Function.comp_apply, FinRV.eq, one_mul, implies_true]
222241
223- theorem exp_eq_exp_cond_true : 𝔼[X // P] = 𝔼[X * (fun ω ↦ 1 ) // P] := sorry
242+ theorem exp_eq_exp_cond_true : 𝔼[X // P] = 𝔼[X * (fun _ ↦ 1 ) // P] := by simp [expect, Pi.mul_def]
224243
225244
226245example {f g : ℕ → ℚ} {m : ℕ} (h : ∀ n : ℕ, f n = g n) :
@@ -237,9 +256,10 @@ theorem law_total_exp : 𝔼[𝔼[X |ᵣ L // P] // P] = 𝔼[X // P] :=
237256 apply Finset.sum_congr
238257 · rfl
239258 · exact fun a _ ↦ exp_prod_μ
240- _ = 𝔼[X * (fun ω ↦ ∑ i : Fin k, (𝕀 ∘ (L =ᵣ i)) ω) // P] := μ_dist fun i => 𝕀 ∘ (L=ᵣi)
259+ _ = 𝔼[X * (fun ω ↦ ∑ i : Fin k, (𝕀 ∘ (L =ᵣ i)) ω) // P] := μ_dist ( fun i ↦ 𝕀 ∘ (L=ᵣi) )
241260 _ = 𝔼[X * (fun ω ↦ 1 ) // P] := by
242261 unfold expect; conv => lhs; congr; rfl; congr; rfl; intro ω; exact fin_sum ω
243262 _ = 𝔼[X // P] := exp_eq_exp_cond_true.symm
244263
264+
245265end Ex
0 commit comments