@@ -4,7 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
4
4
Authors: Eric Rodriguez
5
5
-/
6
6
import data.fintype.card_embedding
7
- import tactic.norm_num
7
+ import probability.cond_count
8
+ import probability.notation
8
9
9
10
/-!
10
11
# Birthday Problem
@@ -16,12 +17,69 @@ in terms of injective functions. The general result about `fintype.card (α ↪
16
17
uses is `fintype.card_embedding_eq`.
17
18
-/
18
19
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
20
22
21
- /-- **Birthday Problem** -/
23
+ /-- **Birthday Problem** : set cardinality interpretation. -/
22
24
theorem birthday :
23
25
2 * ‖fin 23 ↪ fin 365 ‖ < ‖fin 23 → fin 365 ‖ ∧ 2 * ‖fin 22 ↪ fin 365 ‖ > ‖fin 22 → fin 365 ‖ :=
24
26
begin
25
27
simp only [nat.desc_factorial, fintype.card_fin, fintype.card_embedding_eq, fintype.card_fun],
26
28
norm_num
27
29
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
0 commit comments