Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 827a83e

Browse files
committed
feat(archive/birthday): improve birthday problem (#16528)
This adds a measure-theoretic interpretation of the birthday problem; not yet the one with independent uniform random variables, but some form of a step in that direction. It also removes a misleading statement from the YAML to make it clearer that `card_embedding_eq` is not all the work done on the Birthday problem on mathlib. cc @digama0 Co-authored-by: Eric Rodriguez <37984851+ericrbg@users.noreply.github.com>
1 parent 7e74869 commit 827a83e

File tree

5 files changed

+80
-5
lines changed

5 files changed

+80
-5
lines changed

archive/100-theorems-list/93_birthday_problem.lean

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Eric Rodriguez
55
-/
66
import data.fintype.card_embedding
7-
import tactic.norm_num
7+
import probability.cond_count
8+
import probability.notation
89

910
/-!
1011
# Birthday Problem
@@ -16,12 +17,69 @@ in terms of injective functions. The general result about `fintype.card (α ↪
1617
uses is `fintype.card_embedding_eq`.
1718
-/
1819

19-
local notation `‖` x `‖` := fintype.card x
20+
local notation (name := finset.card) `|` x `|` := finset.card x
21+
local notation (name := fintype.card) `‖` x `‖` := fintype.card x
2022

21-
/-- **Birthday Problem** -/
23+
/-- **Birthday Problem**: set cardinality interpretation. -/
2224
theorem birthday :
2325
2 * ‖fin 23 ↪ fin 365‖ < ‖fin 23 → fin 365‖ ∧ 2 * ‖fin 22 ↪ fin 365‖ > ‖fin 22 → fin 365‖ :=
2426
begin
2527
simp only [nat.desc_factorial, fintype.card_fin, fintype.card_embedding_eq, fintype.card_fun],
2628
norm_num
2729
end
30+
31+
section measure_theory
32+
33+
open measure_theory probability_theory
34+
open_locale probability_theory ennreal
35+
36+
variables {n m : ℕ}
37+
38+
/- In order for Lean to understand that we can take probabilities in `fin 23 → fin 365`, we must
39+
tell Lean that there is a `measurable_space` structure on the space. Note that this instance
40+
is only for `fin m` - Lean automatically figures out that the function space `fin n → fin m`
41+
is _also_ measurable, by using `measurable_space.pi` -/
42+
43+
instance : measurable_space (fin m) := ⊤
44+
45+
/- We then endow the space with a canonical measure, which is called ℙ.
46+
We define this to be the conditional counting measure. -/
47+
noncomputable instance : measure_space (fin n → fin m) := ⟨cond_count set.univ⟩
48+
49+
-- Singletons are measurable; therefore, as `fin n → fin m` is finite, all sets are measurable.
50+
instance : measurable_singleton_class (fin n → fin m) :=
51+
⟨λ f, begin
52+
convert measurable_set.pi set.finite_univ.countable
53+
(show ∀ i, i ∈ set.univ → measurable_set ({f i} : set (fin m)), from λ _ _, trivial),
54+
ext g,
55+
simp only [function.funext_iff, set.mem_singleton_iff, set.mem_univ_pi],
56+
end
57+
58+
/- The canonical measure on `fin n → fin m` is a probability measure (except on an empty space). -/
59+
example : is_probability_measure (ℙ : measure (fin n → fin (m + 1))) :=
60+
cond_count_is_probability_measure set.finite_univ set.univ_nonempty
61+
62+
lemma fin_fin.measure_apply {s : set $ fin n → fin m} :
63+
ℙ s = (|s.to_finite.to_finset|) / ‖fin n → fin m‖ :=
64+
by erw [cond_count_univ, measure.count_apply_finite]
65+
66+
/-- **Birthday Problem**: first probabilistic interpretation. -/
67+
theorem birthday_measure : ℙ {f : fin 23 → fin 365 | function.injective f} < 1 / 2 :=
68+
begin
69+
-- most of this proof is essentially converting it to the same form as `birthday`.
70+
rw [fin_fin.measure_apply],
71+
generalize_proofs hfin,
72+
have : |hfin.to_finset| = 42200819302092359872395663074908957253749760700776448000000,
73+
{ transitivity ‖fin 23 ↪ fin 365‖,
74+
{ simp_rw [←fintype.card_coe, set.finite.coe_sort_to_finset, set.coe_set_of],
75+
exact fintype.card_congr (equiv.subtype_injective_equiv_embedding _ _) },
76+
{ simp only [fintype.card_embedding_eq, fintype.card_fin, nat.desc_factorial],
77+
norm_num } },
78+
rw [this, ennreal.lt_div_iff_mul_lt, mul_comm, mul_div, ennreal.div_lt_iff],
79+
rotate, iterate 2 { right, norm_num }, iterate 2 { left, norm_num },
80+
norm_cast,
81+
simp only [fintype.card_pi, fintype.card_fin],
82+
norm_num
83+
end
84+
85+
end measure_theory

docs/100.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@
379379
title : Pick’s Theorem
380380
93:
381381
title : The Birthday Problem
382-
decl : fintype.card_embedding_eq
383382
links :
384383
mathlib archive: https://github.com/leanprover-community/mathlib/blob/master/archive/100-theorems-list/93_birthday_problem.lean
385384
author : Eric Rodriguez

src/data/set/finite.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ by rw [← finset.coe_sort_coe _, h.coe_to_finset]
141141
@[simp] lemma finite_empty_to_finset (h : (∅ : set α).finite) : h.to_finset = ∅ :=
142142
by rw [← finset.coe_inj, h.coe_to_finset, finset.coe_empty]
143143

144+
@[simp] lemma finite_univ_to_finset [fintype α] (h : (set.univ : set α).finite) :
145+
h.to_finset = finset.univ :=
146+
finset.ext $ by simp
147+
144148
@[simp] lemma finite.to_finset_inj {s t : set α} {hs : s.finite} {ht : t.finite} :
145149
hs.to_finset = ht.to_finset ↔ s = t :=
146150
by simp only [←finset.coe_inj, finite.coe_to_finset]

src/measure_theory/measure/measure_space.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,10 @@ begin
23372337
exact ne_of_lt (measure_lt_top _ _)
23382338
end
23392339

2340+
instance [finite α] [measurable_space α] : is_finite_measure (measure.count : measure α) :=
2341+
by { casesI nonempty_fintype α,
2342+
simpa [measure.count_apply, tsum_fintype] using (ennreal.nat_ne_top _).lt_top }⟩
2343+
23402344
end is_finite_measure
23412345

23422346
section is_probability_measure

src/probability/cond_count.lean

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ begin
6262
simpa [cond_count, cond, measure.count_apply_infinite hs'] using h,
6363
end
6464

65+
lemma cond_count_univ [fintype Ω] {s : set Ω} :
66+
cond_count set.univ s = measure.count s / fintype.card Ω :=
67+
begin
68+
rw [cond_count, cond_apply _ measurable_set.univ, ←ennreal.div_eq_inv_mul, set.univ_inter],
69+
congr',
70+
rw [←finset.coe_univ, measure.count_apply, finset.univ.tsum_subtype' (λ _, (1 : ennreal))],
71+
{ simp [finset.card_univ] },
72+
{ exact (@finset.coe_univ Ω _).symm ▸ measurable_set.univ }
73+
end
74+
6575
variables [measurable_singleton_class Ω]
6676

6777
lemma cond_count_is_probability_measure {s : set Ω} (hs : s.finite) (hs' : s.nonempty) :
@@ -126,7 +136,7 @@ lemma cond_count_eq_zero_iff (hs : s.finite) :
126136
by simp [cond_count, cond_apply _ hs.measurable_set, measure.count_apply_eq_top,
127137
set.not_infinite.2 hs, measure.count_apply_finite _ (hs.inter_of_left _)]
128138

129-
lemma cond_count_univ (hs : s.finite) (hs' : s.nonempty) :
139+
lemma cond_count_of_univ (hs : s.finite) (hs' : s.nonempty) :
130140
cond_count s set.univ = 1 :=
131141
cond_count_eq_one_of hs hs' s.subset_univ
132142

0 commit comments

Comments
 (0)