@@ -3,7 +3,7 @@ import Probability.Probability.Prelude
33import Mathlib.Data.Matrix.Mul -- dot product definitions and results
44import Mathlib.Algebra.Notation.Pi.Defs -- operations on functions
55import Mathlib.Algebra.Module.PointwisePi -- for smul_pi
6- import Mathlib.LinearAlgebra.Matrix.DotProduct -- for monotonicity
6+ import Mathlib.LinearAlgebra.Matrix.DotProduct -- for monotonicity
77
88--------------------------- Findist ---------------------------------------------------------------
99
@@ -14,7 +14,7 @@ variable {n : ℕ}
1414structure Findist (n : ℕ) : Type where
1515 p : Fin n → ℚ
1616 prob : 1 ⬝ᵥ p = 1
17- nneg : 0 ≤ p
17+ nneg : 0 ≤ p
1818
1919namespace Findist
2020
@@ -29,12 +29,12 @@ def singleton : Findist 1 :=
2929
3030
3131@[simp]
32- def length (_ : Findist n) := n
32+ def length (_ : Findist n) := n
3333
34- variable {n : ℕ}
34+ variable {n : ℕ}
3535
36- theorem nonempty (P : Findist n) : P.length > 0 :=
37- by cases n
36+ theorem nonempty (P : Findist n) : P.length > 0 :=
37+ by cases n
3838 · have := P.prob; simp_all only [Matrix.dotProduct_of_isEmpty, zero_ne_one]
3939 · simp only [length, gt_iff_lt, lt_add_iff_pos_left, add_pos_iff, zero_lt_one, or_true]
4040
@@ -50,7 +50,7 @@ end Findist
5050--------------------------- Random Variable -------------------------------------------------------------------
5151
5252/-!
53- Random variables are defined as function. The operations on random variables can be performed
53+ Random variables are defined as function. The operations on random variables can be performed
5454using the standard notation:
5555
5656- X + Y is elementwise addition
@@ -60,12 +60,12 @@ using the standard notation:
6060
6161
6262- L =ᵣ i is a boolean indicator random variable
63- - L =ᵢ i is a ℚ indicator random variable
64- - L ≤ᵣ i is a bool indicator random variable
63+ - L =ᵢ i is a ℚ indicator random variable
64+ - L ≤ᵣ i is a bool indicator random variable
6565
66- Main results
66+ Main results
6767
68- - Hadamard product is linear: Y * (∑ i, Xs i) = ∑ i, Y * (Xs i)
68+ - Hadamard product is linear: Y * (∑ i, Xs i) = ∑ i, Y * (Xs i)
6969 -/
7070
7171
@@ -133,6 +133,12 @@ def leq [LE ρ] [DecidableLE ρ] (Y : FinRV n ρ) (y : ρ) : FinRV n Bool :=
133133
134134infix :50 "≤ᵣ" => FinRV.leq
135135
136+ @[simp]
137+ def gt [LT ρ] [DecidableLT ρ] (Y : FinRV n ρ) (y : ρ) : FinRV n Bool :=
138+ fun ω ↦ Y ω > y
139+
140+ infix :50 ">ᵣ" => FinRV.gt
141+
136142example (m n : ℕ) : (m < n) ∨ (m = n) ∨ (m > n) := Nat.lt_trichotomy m n
137143
138144/-- Shows equivalence when extending the random variable to another element. -/
@@ -158,16 +164,16 @@ abbrev 𝕀 [OfNat ρ 0] [OfNat ρ 1] : Bool → ρ := indicator
158164
159165variable {k : ℕ} {L : FinRV n (Fin k)}
160166
161- theorem indi_eq_indr : ∀i : Fin k, (𝕀 ∘ (L =ᵣ i)) = (L =ᵢ i) := by
162- intro i
163- unfold FinRV.eq FinRV.eqi 𝕀 indicator
164- ext ω
165- by_cases h: L ω = i
167+ theorem indi_eq_indr : ∀i : Fin k, (𝕀 ∘ (L =ᵣ i)) = (L =ᵢ i) := by
168+ intro i
169+ unfold FinRV.eq FinRV.eqi 𝕀 indicator
170+ ext ω
171+ by_cases h: L ω = i
166172 · simp [h]
167173 · simp [h]
168174
169175
170- variable {B : FinRV n Bool}
176+ variable {B : FinRV n Bool}
171177/-- Indicator is 0 or 1 -/
172178theorem ind_zero_one : ∀ ω, (𝕀∘B) ω = 1 ∨ (𝕀∘B) ω = 0 := by
173179 intro ω
@@ -176,40 +182,40 @@ theorem ind_zero_one : ∀ ω, (𝕀∘B) ω = 1 ∨ (𝕀∘B) ω = 0 := by
176182 · right; simp only [Function.comp_apply, h, indicator]
177183
178184/-- Indicator is 0 or 1 -/
179- theorem ind_nneg : (0 : FinRV n ℚ) ≤ 𝕀∘B := by
185+ theorem ind_nneg : (0 : FinRV n ℚ) ≤ 𝕀∘B := by
180186 intro ω
181187 simp [𝕀, indicator]
182188 by_cases h : B ω
183- · simp [h]
184- · simp [h]
189+ · simp [h]
190+ · simp [h]
185191
186- theorem ind_le_one : 𝕀∘B ≤ (1 : FinRV n ℚ) :=
192+ theorem ind_le_one : 𝕀∘B ≤ (1 : FinRV n ℚ) :=
187193 by unfold 𝕀 indicator
188194 intro ω
189195 by_cases h : B ω
190196 · simp [h]
191- · simp [h]
197+ · simp [h]
192198
193199theorem one_of_true : 𝕀 ∘ (1 : Fin n → Bool) = (1 : Fin n → ℚ) := by ext; simp [𝕀, indicator]
194200
195- theorem one_of_bool_or_not : B + (¬ᵣ B) = (1 : FinRV n Bool) := by ext ω; unfold FinRV.not; simp
201+ theorem one_of_bool_or_not : B + (¬ᵣ B) = (1 : FinRV n Bool) := by ext ω; unfold FinRV.not; simp
196202
197- theorem one_of_ind_bool_or_not : (𝕀∘B) + (𝕀∘(¬ᵣ B)) = (1 : FinRV n ℚ) :=
203+ theorem one_of_ind_bool_or_not : (𝕀∘B) + (𝕀∘(¬ᵣ B)) = (1 : FinRV n ℚ) :=
198204 by ext ω
199- unfold FinRV.not 𝕀 indicator not
205+ unfold FinRV.not 𝕀 indicator not
200206 by_cases h : B ω
201207 · simp [h]
202- · simp [h]
208+ · simp [h]
203209
204- variable {X Y: FinRV n ℚ}
210+ variable {X Y: FinRV n ℚ}
205211
206212theorem rv_le_abs : X ≤ abs ∘ X := by intro i; simp [le_abs_self (X i)]
207213
208- theorem rv_prod_sum_linear {Xs : Fin k → FinRV n ℚ} : ∑ i, Y * (Xs i) = Y * (∑ i, Xs i) :=
209- by ext ω
210- simp
211- rw [Finset.mul_sum]
212-
214+ theorem rv_prod_sum_linear {Xs : Fin k → FinRV n ℚ} : ∑ i, Y * (Xs i) = Y * (∑ i, Xs i) :=
215+ by ext ω
216+ simp
217+ rw [Finset.mul_sum]
218+
213219end RandomVariable
214220
215221------------------------------ Probability ---------------------------
@@ -222,7 +228,7 @@ def probability : ℚ := P.p ⬝ᵥ (𝕀 ∘ B)
222228
223229notation "ℙ[" B "//" P "]" => probability P B
224230
225- -- helps to refold is when needed
231+ -- helps to refold is when needed
226232lemma probability_def : P.p ⬝ᵥ (𝕀 ∘ B) = ℙ[B // P] := rfl
227233
228234-- TODO: the sorry in the definition has to do with the decidability of the membership
@@ -244,11 +250,11 @@ theorem prob_one_of_true : ℙ[1 // P] = 1 :=
244250
245251example {a b : ℚ} (h : 0 ≤ a) (h2 : 0 ≤ b) : 0 ≤ a * b := Rat.mul_nonneg h h2
246252
247- variable {P : Findist n} {B : FinRV n Bool}
253+ variable {P : Findist n} {B : FinRV n Bool}
254+
255+ theorem prod_zero_of_prob_zero : ℙ[B // P] = 0 → (P.p * (𝕀∘B) = 0 ) := by
256+ intro h; exact prod_eq_zero_of_nneg_dp_zero P.nneg ind_nneg h
248257
249- theorem prod_zero_of_prob_zero : ℙ[B // P] = 0 → (P.p * (𝕀∘B) = 0 ) := by
250- intro h; exact prod_eq_zero_of_nneg_dp_zero P.nneg ind_nneg h
251-
252258
253259------------------------------ PMF ---------------------------
254260
@@ -278,7 +284,7 @@ notation "𝔼[" PX "]" => expect PX.1 PX.2
278284--theorem exp_eq_correct : 𝔼[X // P] = ∑ v ∈ ((List.finRange P.length).map X).toFinset, v * ℙ[ X =ᵣ v // P]
279285
280286@[simp]
281- theorem prob_eq_exp_ind : ℙ[B // P] = 𝔼[𝕀 ∘ B // P] :=
287+ theorem prob_eq_exp_ind : ℙ[B // P] = 𝔼[𝕀 ∘ B // P] :=
282288 by simp only [expect, probability]
283289
284290
@@ -298,47 +304,47 @@ def expect_cnd_rv : Fin n → ℚ := fun i ↦ 𝔼[ X | L =ᵣ (L i) // P ]
298304notation "𝔼[" X "|ᵣ" L "//" P "]" => expect_cnd_rv P X L
299305
300306end Ex
301- --- some basic properties
307+ --- some basic properties
302308
303- section Expectation_properties
309+ section Expectation_properties
304310variable {P : Findist n} {X Y Z: FinRV n ℚ} {B : FinRV n Bool}
305311
306- theorem exp_congr : (X = Y) → 𝔼[X // P] = 𝔼[Y // P] :=
307- by intro h
308- unfold Ex.expect dotProduct
312+ theorem exp_congr : (X = Y) → 𝔼[X // P] = 𝔼[Y // P] :=
313+ by intro h
314+ unfold Ex.expect dotProduct
309315 apply Fintype.sum_congr
310- simp_all
316+ simp_all
311317
312- theorem exp_dists_add : 𝔼[X + Y // P] = 𝔼[X // P] + 𝔼[Y // P] := by simp [Ex.expect]
318+ theorem exp_dists_add : 𝔼[X + Y // P] = 𝔼[X // P] + 𝔼[Y // P] := by simp [Ex.expect]
313319
314320theorem exp_mul_comm : 𝔼[X * Y // P] = 𝔼[Y * X // P] := by unfold Ex.expect; exact dotProd_hadProd_comm
315321
316322variable {c : ℚ} {p : Fin n → ℚ}
317323
318- theorem const_fun_to_one : (fun _ ↦ c : FinRV n ℚ) = c • 1 := by ext; simp;
324+ theorem const_fun_to_one : (fun _ ↦ c : FinRV n ℚ) = c • 1 := by ext; simp;
319325
320- theorem exp_const : 𝔼[(fun _ ↦ c) // P] = c :=
326+ theorem exp_const : 𝔼[(fun _ ↦ c) // P] = c :=
321327 by unfold Ex.expect
322- rw [const_fun_to_one]
328+ rw [const_fun_to_one]
323329 simp only [dotProduct_smul, smul_eq_mul]
324330 rw [dotProduct_comm, P.prob]
325- simp
331+ simp
326332
327- theorem exp_one : 𝔼[ 1 // P] = 1 :=
328- by calc 𝔼[ 1 // P] = 𝔼[ (fun _ ↦ 1 ) // P] := rfl
329- _ = 1 := exp_const
333+ theorem exp_one : 𝔼[ 1 // P] = 1 :=
334+ by calc 𝔼[ 1 // P] = 𝔼[ (fun _ ↦ 1 ) // P] := rfl
335+ _ = 1 := exp_const
330336
331337theorem exp_prod_const : 𝔼[c • X // P] = c * 𝔼[X // P] := by simp only [Ex.expect, dotProduct_smul, smul_eq_mul]
332338
333- lemma constant_mul_eq_smul : (fun ω ↦ c * X ω) = c • X := rfl
339+ lemma constant_mul_eq_smul : (fun ω ↦ c * X ω) = c • X := rfl
334340
335- theorem exp_prod_const_fun : 𝔼[(λ _ ↦ c) * X // P] = c * 𝔼[X // P] :=
341+ theorem exp_prod_const_fun : 𝔼[(λ _ ↦ c) * X // P] = c * 𝔼[X // P] :=
336342 by simp only [Ex.expect, Pi.mul_def, constant_mul_eq_smul, dotProduct_smul, smul_eq_mul]
337343
338- theorem exp_indi_eq_exp_indr : ∀i : Fin k, 𝔼[L =ᵢ i // P] = 𝔼[𝕀 ∘ (L =ᵣ i) // P] := by
339- intro i
344+ theorem exp_indi_eq_exp_indr : ∀i : Fin k, 𝔼[L =ᵢ i // P] = 𝔼[𝕀 ∘ (L =ᵣ i) // P] := by
345+ intro i
340346 rw [indi_eq_indr]
341347
342348theorem exp_monotone (h: X ≤ Y) : 𝔼[X // P] ≤ 𝔼[Y // P] := dotProduct_le_dotProduct_of_nonneg_left h P.nneg
343349
344- end Expectation_properties
350+ end Expectation_properties
0 commit comments