@@ -11,32 +11,36 @@ section Findist
1111
1212variable {n : β}
1313
14+ /-- Finite probability distribution -/
1415structure Findist (n : β) : Type where
15- p : Fin n β β
16+ /-- Probaiblity measure -/
17+ p : Fin n β β
1618 prob : 1 β¬α΅₯ p = 1
1719 nneg : 0 β€ p
1820
21+
1922namespace Findist
2023
24+ /-- Finite probability distribution -/
2125abbrev Delta : β β Type := Findist
26+
27+ /-- Finite probability distribution -/
2228abbrev Ξ : β β Type := Delta
2329
2430
31+ /-- Single probability distribution -/
2532def singleton : Findist 1 :=
2633 {p := ![1 ],
2734 prob := by simp [Matrix.vecHead],
2835 nneg := by simp [Pi.zero_def, Pi.le_def] }
2936
3037
31- @[simp]
32- def length (_ : Findist n) := n
33-
3438variable {n : β}
3539
36- theorem nonempty (P : Findist n) : P.length > 0 :=
40+ theorem nonempty (P : Findist n) : n > 0 :=
3741 by cases n
3842 Β· have := P.prob; simp_all only [Matrix.dotProduct_of_isEmpty, zero_ne_one]
39- Β· simp only [length, gt_iff_lt, lt_add_iff_pos_left, add_pos_iff, zero_lt_one, or_true]
43+ Β· simp only [gt_iff_lt, lt_add_iff_pos_left, add_pos_iff, zero_lt_one, or_true]
4044
4145
4246end Findist
@@ -87,52 +91,50 @@ instance instBoolAdd: Add Bool where add a b := Bool.or a b
8791instance instBoolZero : Zero Bool where zero := false
8892instance instBoolOne : One Bool where one := true
8993
90- @[simp] lemma bool_mul_tt : (true * true : Bool) = true := rfl
91- @[simp] lemma bool_mul_tf : (true * false : Bool) = false := rfl
92- @[simp] lemma bool_mul_ft : (false * true : Bool) = false := rfl
93- @[simp] lemma bool_mul_ff : (false * false : Bool) = false := rfl
94-
9594variable {A B : Bool}
9695
9796@[simp] theorem one_eq_true : (1 :Bool) = true := rfl
9897@[simp] theorem zero_eq_false : (0 :Bool) = false := rfl
9998@[simp] theorem bool_sum_or : A + B = Bool.or A B := rfl
10099@[simp] theorem bool_prod_and : A * B = Bool.and A B := rfl
101100
102- @[simp]
103- def not (B : FinRV n Bool) : FinRV n Bool :=
101+
102+ /-- Negates a random variable -/
103+ @[simp] def not (B : FinRV n Bool) : FinRV n Bool :=
104104 fun Ο β¦ (B Ο).not
105105
106+ /-- Negates a random variable -/
106107prefix :40 "Β¬α΅£" => FinRV.not
107108
108- @[simp]
109- def eq [DecidableEq Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n Bool :=
109+ /-- Boolean random variable representing an quality condition -/
110+ @[simp] def eq [DecidableEq Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n Bool :=
110111 (fun Ο β¦ decide (Y Ο = y) )
111112
113+ /-- Boolean random variable representing an quality condition -/
112114infix :50 "=α΅£" => FinRV.eq
113115
114- /-- indicator version of equality -/
115- @[simp]
116- def eqi [DecidableEq Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n β :=
116+ /-- 0/1 random variable representing an quality condition -/
117+ @[simp] def eqi [DecidableEq Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n β :=
117118 (fun Ο β¦ if Y Ο = y then 1 else 0 )
118119
120+ /-- 0/1 random variable representing an quality condition -/
119121infix :50 "=α΅’" => FinRV.eqi
120122
121- @[simp]
122- def leq [LE Ο] [DecidableLE Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n Bool :=
123+ /-- Boolean random variable represening Y β€ y inequality -/
124+ @[simp] def leq [LE Ο] [DecidableLE Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n Bool :=
123125 (fun Ο β¦ Y Ο β€ y)
124126
127+ /-- Boolean random variable represening Y β€ y inequality -/
125128infix :50 "β€α΅£" => FinRV.leq
126129
127- @[simp]
128- def gt [LT Ο] [DecidableLT Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n Bool :=
130+ /-- Boolean random variable represening Y > y inequality -/
131+ @[simp] def gt [LT Ο] [DecidableLT Ο] (Y : FinRV n Ο) (y : Ο) : FinRV n Bool :=
129132 fun Ο β¦ Y Ο > y
130133
134+ /-- Boolean random variable represening Y > y inequality -/
131135infix :50 ">α΅£" => FinRV.gt
132136
133- example (m n : β) : (m < n) β¨ (m = n) β¨ (m > n) := Nat.lt_trichotomy m n
134-
135- /-- Shows equivalence when extending the random variable to another element. -/
137+ /-- Equivalence when extending the random variable to another element. -/
136138theorem le_of_le_eq (D : FinRV n β) (m : β) : ((D β€α΅£ m) + (D =α΅£ m.succ)) = (D β€α΅£ m.succ) := by
137139 funext x --extensionality principle for functions
138140 unfold FinRV.leq FinRV.eq instHAdd Add.add Pi.instAdd
@@ -149,6 +151,7 @@ end FinRV
149151/-- Boolean indicator function -/
150152def indicator [OfNat Ο 0 ] [OfNat Ο 1 ] (cond : Bool) : Ο := cond.rec 0 1
151153
154+ /-- Boolean indicator function -/
152155abbrev π [OfNat Ο 0 ] [OfNat Ο 1 ] : Bool β Ο := indicator
153156
154157
@@ -213,16 +216,16 @@ variable {n : β} (P : Findist n) (B C : FinRV n Bool)
213216/-- Probability of B -/
214217def probability : β := P.p β¬α΅₯ (π β B)
215218
219+ /-- Probability of B -/
216220notation "β[" B "//" P "]" => probability P B
217221
218222-- helps to refold is when needed
219223lemma probability_def : P.p β¬α΅₯ (π β B) = β[B // P] := rfl
220224
221- /-- Conditional probability of B -/
225+ /-- Conditional probability of B on C -/
222226def probability_cnd : β := β[B * C // P] / β[ C // P ]
223227
224-
225- ---- conditional probability
228+ /-- Conditional probability of B on C -/
226229notation "β[" B "|" C "//" P "]" => probability_cnd P B C
227230
228231
@@ -275,34 +278,31 @@ Main results
275278
276279variable {n : β} (P : Findist n) (X Y Z: FinRV n β) (B : FinRV n Bool)
277280
281+ /-- Standard expectation operator -/
278282def expect : β := P.p β¬α΅₯ X
279283
284+ /-- Standard expectation operator -/
280285notation "πΌ[" X "//" P "]" => expect P X
281286
282- -- expectation for a joint probability space and random variable
283- notation "πΌ[" PX "]" => expect PX.1 PX.2
284-
285287--theorem exp_eq_correct : πΌ[X // P] = β v β ((List.finRange P.length).map X).toFinset, v * β[ X =α΅£ v // P]
286288
287289@[simp]
288290theorem prob_eq_exp_ind : β[B // P] = πΌ[π β B // P] := by simp only [expect, probability]
289291
290- /-- Conditional expectation -/
292+ /-- Conditional expectation operator -/
291293def expect_cnd : β := πΌ[ X * (π β B) // P] / β[ B // P]
292294
295+ /-- Conditional expectation operator -/
293296notation "πΌ[" X "|" B "//" P "]" => expect_cnd P X B
294297
295- -- expectation for a joint probability space and random variable
296- notation "πΌ[" PX "|" B "]" => expect_cnd PX.1 PX.2 B
297-
298298variable {k : β} (L : FinRV n (Fin k))
299299
300- -- creates a random variable
300+ / -- Expectation conditioned on a random variable. It creates a random variable -/
301301def expect_cnd_rv : Fin n β β := fun i β¦ πΌ[ X | L =α΅£ (L i) // P ]
302302
303+ /-- Expectation conditioned on a random variable. It creates a random variable -/
303304notation "πΌ[" X "|α΅£" L "//" P "]" => expect_cnd_rv P X L
304305
305-
306306--- some basic properties
307307
308308section Expectation_properties
@@ -377,3 +377,5 @@ theorem exp_cond_const : β i, β[L =α΅£ i // P] β 0 β πΌ[g β L | L
377377 simp only [h, ne_eq, isUnit_iff_ne_zero, not_false_eq_true, IsUnit.mul_div_cancel_right]
378378
379379end Expectation_properties
380+
381+ #lint
0 commit comments