Skip to content

Commit a1de52a

Browse files
committed
progress on proving the correctness of E definition
1 parent fb91536 commit a1de52a

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

MDPLib/Probability/Basic.lean

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,29 @@ theorem law_total_exp : 𝔼[𝔼[X |ᵣ L // P] // P] = 𝔼[X // P] :=
502502
_ = 𝔼[X // P] := by rw [←exp_decompose]
503503

504504
--- shows that using a set and list is the same
505-
lemma finset_image_eq_list_map_dedup : ∀x, x ∈ Finset.univ.image X ↔ x ∈ (List.ofFn X |> List.dedup) :=
506-
by intro x; constructor <;> simp [Fin.univ_image_def,List.mem_toFinset]
505+
lemma finset_image_eq_list_map_dedup : ∀x, x ∈ Finset.univ.image X ↔ x ∈ (List.ofFn X |> List.dedup) := by
506+
intro x; constructor <;> simp [Fin.univ_image_def,List.mem_toFinset]
507507

508508

509-
#check Finset.sum
509+
lemma finset_list_eq_list_dedup (l : List ℚ) : l.toFinset = l.dedup.toFinset :=
510+
List.toFinset.ext (fun _ => List.mem_dedup.symm)
510511

511512

512-
example (f : ℚ → ℚ) : (∑ y ∈ (Finset.univ.image X), f y) = ((List.ofFn X |> List.dedup).map f).sum := sorry
513+
example (f : ℚ → ℚ) (l : List ℚ) (h : l.Nodup) : ∑ y ∈ l.toFinset, f y = (l.map f).sum :=
514+
List.sum_toFinset (fun y => f y) h
513515

514-
515516

517+
example (f : ℚ → ℚ) : (∑ y ∈ (Finset.univ.image X), f y) = ((List.ofFn X |> List.dedup).map f).sum := by
518+
rw [Fin.univ_image_def]
519+
rw [Finset.sum_list_map_count]
520+
rw [finset_list_eq_list_dedup]
521+
have h : ∀m ∈ (List.ofFn X).dedup.toFinset, List.count m (List.ofFn X).dedup = 1 :=
522+
fun m hm => List.count_eq_one_of_mem (List.nodup_dedup (List.ofFn X)) (List.mem_dedup.mp hm)
523+
apply Finset.sum_congr
524+
· simp
525+
· intro x hx
526+
simp [h x hx]
527+
516528

517529
/-- Shows that our definition of expectation is correct -/
518530
theorem expect_def_correct : 𝔼[ X // P] = ∑ y ∈ (Finset.univ.image X), (ℙ[ X =ᵣ y // P] * y) := by
@@ -527,15 +539,15 @@ section Probability
527539
variable {k : ℕ} {L : FinRV n (Fin k)}
528540

529541
/-- The law of total probabilities -/
530-
theorem law_of_total_probs : ℙ[B // P] = ∑ i, ℙ[B * (L =ᵣ i) // P] :=
531-
by rewrite [prob_eq_exp_ind, rv_decompose (𝕀∘B) L, exp_additive]
532-
apply Fintype.sum_congr
533-
intro i
534-
rewrite [prob_eq_exp_ind]
535-
apply exp_congr
536-
ext ω
537-
by_cases h1 : L ω = i
538-
repeat by_cases h2 : B ω; repeat simp [h1, h2, 𝕀, indicator ]
542+
theorem law_of_total_probs : ℙ[B // P] = ∑ i, ℙ[B * (L =ᵣ i) // P] := by
543+
rewrite [prob_eq_exp_ind, rv_decompose (𝕀∘B) L, exp_additive]
544+
apply Fintype.sum_congr
545+
intro i
546+
rewrite [prob_eq_exp_ind]
547+
apply exp_congr
548+
ext ω
549+
by_cases h1 : L ω = i
550+
repeat by_cases h2 : B ω; repeat simp [h1, h2, 𝕀, indicator ]
539551

540552
end Probability
541553

0 commit comments

Comments
 (0)