@@ -3,7 +3,7 @@ Copyright (c) 2022 Bhavik Mehta, Kexing Ying. All rights reserved.
33Released under Apache 2.0 license as described in the file LICENSE.
44Authors: Bhavik Mehta, Kexing Ying
55-/
6- import Mathlib.Probability.CondCount
6+ import Mathlib.Probability.UniformOn
77
88/-!
99# Ballot problem
@@ -188,21 +188,21 @@ theorem count_countedSequence : ∀ p q : ℕ, count (countedSequence p q) = (p
188188
189189theorem first_vote_pos :
190190 ∀ p q,
191- 0 < p + q → condCount (countedSequence p q : Set (List ℤ)) {l | l.headI = 1 } = p / (p + q)
191+ 0 < p + q → uniformOn (countedSequence p q : Set (List ℤ)) {l | l.headI = 1 } = p / (p + q)
192192 | p + 1 , 0 , _ => by
193- rw [counted_right_zero, condCount_singleton ]
193+ rw [counted_right_zero, uniformOn_singleton ]
194194 simp [ENNReal.div_self _ _, List.replicate_succ]
195195 | 0 , q + 1 , _ => by
196- rw [counted_left_zero, condCount_singleton ]
196+ rw [counted_left_zero, uniformOn_singleton ]
197197 simp only [List.replicate, Nat.add_eq, add_zero, mem_setOf_eq, List.headI_cons, Nat.cast_zero,
198198 ENNReal.zero_div, ite_eq_right_iff]
199199 decide
200200 | p + 1 , q + 1 , _ => by
201201 simp_rw [counted_succ_succ]
202- rw [← condCount_disjoint_union ((countedSequence_finite _ _).image _)
202+ rw [← uniformOn_disjoint_union ((countedSequence_finite _ _).image _)
203203 ((countedSequence_finite _ _).image _) (disjoint_bits _ _),
204204 ← counted_succ_succ,
205- condCount_eq_one_of ((countedSequence_finite p (q + 1 )).image _)
205+ uniformOn_eq_one_of ((countedSequence_finite p (q + 1 )).image _)
206206 ((countedSequence_nonempty _ _).image _)]
207207 · have : List.cons (-1 ) '' countedSequence (p + 1 ) q ∩ {l : List ℤ | l.headI = 1 } = ∅ := by
208208 ext
@@ -215,7 +215,7 @@ theorem first_vote_pos :
215215 List.cons 1 '' countedSequence p (q + 1 ) := by
216216 rw [inter_eq_right, counted_succ_succ]
217217 exact subset_union_left
218- rw [(condCount_eq_zero_iff <| (countedSequence_finite _ _).image _).2 this, condCount ,
218+ rw [(uniformOn_eq_zero_iff <| (countedSequence_finite _ _).image _).2 this, uniformOn ,
219219 cond_apply _ list_int_measurableSet, hint, count_injective_image List.cons_injective,
220220 count_countedSequence, count_countedSequence, one_mul, zero_mul, add_zero,
221221 Nat.cast_add, Nat.cast_one, mul_comm, ← div_eq_mul_inv, ENNReal.div_eq_div_iff]
@@ -230,27 +230,27 @@ theorem headI_mem_of_nonempty {α : Type*} [Inhabited α] : ∀ {l : List α} (_
230230 | x::l, _ => List.mem_cons_self x l
231231
232232theorem first_vote_neg (p q : ℕ) (h : 0 < p + q) :
233- condCount (countedSequence p q) {l | l.headI = 1 }ᶜ = q / (p + q) := by
233+ uniformOn (countedSequence p q) {l | l.headI = 1 }ᶜ = q / (p + q) := by
234234 have h' : (p + q : ℝ≥0 ∞) ≠ 0 := mod_cast h.ne'
235- have := condCount_compl
235+ have := uniformOn_compl
236236 {l : List ℤ | l.headI = 1 }ᶜ (countedSequence_finite p q) (countedSequence_nonempty p q)
237237 rw [compl_compl, first_vote_pos _ _ h] at this
238238 rw [ENNReal.eq_sub_of_add_eq _ this, ENNReal.eq_div_iff, ENNReal.mul_sub, mul_one,
239239 ENNReal.mul_div_cancel', ENNReal.add_sub_cancel_left]
240240 all_goals simp_all [ENNReal.div_eq_top]
241241
242- theorem ballot_same (p : ℕ) : condCount (countedSequence (p + 1 ) (p + 1 )) staysPositive = 0 := by
243- rw [condCount_eq_zero_iff (countedSequence_finite _ _), eq_empty_iff_forall_not_mem]
242+ theorem ballot_same (p : ℕ) : uniformOn (countedSequence (p + 1 ) (p + 1 )) staysPositive = 0 := by
243+ rw [uniformOn_eq_zero_iff (countedSequence_finite _ _), eq_empty_iff_forall_not_mem]
244244 rintro x ⟨hx, t⟩
245245 apply ne_of_gt (t x _ x.suffix_refl)
246246 · simpa using sum_of_mem_countedSequence hx
247247 · refine List.ne_nil_of_length_pos ?_
248248 rw [length_of_mem_countedSequence hx]
249249 exact Nat.add_pos_left (Nat.succ_pos _) _
250250
251- theorem ballot_edge (p : ℕ) : condCount (countedSequence (p + 1 ) 0 ) staysPositive = 1 := by
251+ theorem ballot_edge (p : ℕ) : uniformOn (countedSequence (p + 1 ) 0 ) staysPositive = 1 := by
252252 rw [counted_right_zero]
253- refine condCount_eq_one_of (finite_singleton _) (singleton_nonempty _) ?_
253+ refine uniformOn_eq_one_of (finite_singleton _) (singleton_nonempty _) ?_
254254 refine singleton_subset_iff.2 fun l hl₁ hl₂ => List.sum_pos _ (fun x hx => ?_) hl₁
255255 rw [List.eq_of_mem_replicate (hl₂.mem hx)]
256256 norm_num
@@ -267,9 +267,9 @@ theorem countedSequence_int_pos_counted_succ_succ (p q : ℕ) :
267267 norm_num
268268
269269theorem ballot_pos (p q : ℕ) :
270- condCount (countedSequence (p + 1 ) (q + 1 ) ∩ {l | l.headI = 1 }) staysPositive =
271- condCount (countedSequence p (q + 1 )) staysPositive := by
272- rw [countedSequence_int_pos_counted_succ_succ, condCount, condCount ,
270+ uniformOn (countedSequence (p + 1 ) (q + 1 ) ∩ {l | l.headI = 1 }) staysPositive =
271+ uniformOn (countedSequence p (q + 1 )) staysPositive := by
272+ rw [countedSequence_int_pos_counted_succ_succ, uniformOn, uniformOn ,
273273 cond_apply _ list_int_measurableSet, cond_apply _ list_int_measurableSet,
274274 count_injective_image List.cons_injective]
275275 congr 1
@@ -294,9 +294,9 @@ theorem countedSequence_int_neg_counted_succ_succ (p q : ℕ) :
294294 norm_num
295295
296296theorem ballot_neg (p q : ℕ) (qp : q < p) :
297- condCount (countedSequence (p + 1 ) (q + 1 ) ∩ {l | l.headI = 1 }ᶜ) staysPositive =
298- condCount (countedSequence (p + 1 ) q) staysPositive := by
299- rw [countedSequence_int_neg_counted_succ_succ, condCount, condCount ,
297+ uniformOn (countedSequence (p + 1 ) (q + 1 ) ∩ {l | l.headI = 1 }ᶜ) staysPositive =
298+ uniformOn (countedSequence (p + 1 ) q) staysPositive := by
299+ rw [countedSequence_int_neg_counted_succ_succ, uniformOn, uniformOn ,
300300 cond_apply _ list_int_measurableSet, cond_apply _ list_int_measurableSet,
301301 count_injective_image List.cons_injective]
302302 congr 1
@@ -310,7 +310,7 @@ theorem ballot_neg (p q : ℕ) (qp : q < p) :
310310 exact List.cons_injective
311311
312312theorem ballot_problem' :
313- ∀ q p, q < p → (condCount (countedSequence p q) staysPositive).toReal = (p - q) / (p + q) := by
313+ ∀ q p, q < p → (uniformOn (countedSequence p q) staysPositive).toReal = (p - q) / (p + q) := by
314314 classical
315315 apply Nat.diag_induction
316316 · intro p
@@ -322,12 +322,12 @@ theorem ballot_problem' :
322322 rw [div_self]
323323 exact Nat.cast_add_one_ne_zero p
324324 · intro q p qp h₁ h₂
325- haveI := condCount_isProbabilityMeasure
325+ haveI := uniformOn_isProbabilityMeasure
326326 (countedSequence_finite p (q + 1 )) (countedSequence_nonempty _ _)
327- haveI := condCount_isProbabilityMeasure
327+ haveI := uniformOn_isProbabilityMeasure
328328 (countedSequence_finite (p + 1 ) q) (countedSequence_nonempty _ _)
329329 have h₃ : p + 1 + (q + 1 ) > 0 := Nat.add_pos_left (Nat.succ_pos _) _
330- rw [← condCount_add_compl_eq {l : List ℤ | l.headI = 1 } _ (countedSequence_finite _ _),
330+ rw [← uniformOn_add_compl_eq {l : List ℤ | l.headI = 1 } _ (countedSequence_finite _ _),
331331 first_vote_pos _ _ h₃, first_vote_neg _ _ h₃, ballot_pos, ballot_neg _ _ qp]
332332 rw [ENNReal.toReal_add, ENNReal.toReal_mul, ENNReal.toReal_mul, ← Nat.cast_add,
333333 ENNReal.toReal_div, ENNReal.toReal_div, ENNReal.toReal_nat, ENNReal.toReal_nat,
@@ -349,12 +349,12 @@ theorem ballot_problem' :
349349
350350/-- The ballot problem. -/
351351theorem ballot_problem :
352- ∀ q p, q < p → condCount (countedSequence p q) staysPositive = (p - q) / (p + q) := by
352+ ∀ q p, q < p → uniformOn (countedSequence p q) staysPositive = (p - q) / (p + q) := by
353353 intro q p qp
354354 haveI :=
355- condCount_isProbabilityMeasure (countedSequence_finite p q) (countedSequence_nonempty _ _)
355+ uniformOn_isProbabilityMeasure (countedSequence_finite p q) (countedSequence_nonempty _ _)
356356 have :
357- (condCount (countedSequence p q) staysPositive).toReal =
357+ (uniformOn (countedSequence p q) staysPositive).toReal =
358358 ((p - q) / (p + q) : ℝ≥0 ∞).toReal := by
359359 rw [ballot_problem' q p qp]
360360 rw [ENNReal.toReal_div, ← Nat.cast_add, ← Nat.cast_add, ENNReal.toReal_nat,
0 commit comments