Skip to content

Commit

Permalink
feat(measure_theory/measure/measure_space): Add parallel set of lemma…
Browse files Browse the repository at this point in the history
…s about count (#17245)

This PR adds a parallel set of basic lemmas about `measure_theory.measure.count`, which does not assume `[measurable_singleton_class _]` but instead assumes `(measurable set _)`.

The same lemmas are true without the `[measurable_singleton_class _]` assumption, so it often seems inappropriate to require this type class. However, the versions with `(measurable_set _)` assumption are also not strictly generalizations of the ones with the type class, so the PR adds a parallel set of lemmas (many but not all of the existing proofs reduce to the new lemmas at least partially). The new lemma names are a prime appended to the original lemma names; under the common `[measurable_singleton_class _]` assumption for counting measures, the original set of lemmas is more convenient.

One setup where it is, however, appropriate to relax the `[measurable_singleton_class _]` assumption is conditional expected values in finite probability spaces with uniform distribution 

Co-authored-by: kkytola <39528102+kkytola@users.noreply.github.com>
Co-authored-by: kkytola <“kalle.kytola@aalto.fi”>
  • Loading branch information
3 people committed Nov 3, 2022
1 parent b943047 commit a0381d5
Showing 1 changed file with 71 additions and 17 deletions.
88 changes: 71 additions & 17 deletions src/measure_theory/measure/measure_space.lean
Expand Up @@ -1841,12 +1841,21 @@ by simp only [count, sum_apply, hs, dirac_apply', ← tsum_subtype s 1, pi.one_a
@[simp] lemma count_empty : count (∅ : set α) = 0 :=
by rw [count_apply measurable_set.empty, tsum_empty]

@[simp] lemma count_apply_finset [measurable_singleton_class α] (s : finset α) :
@[simp] lemma count_apply_finset' {s : finset α} (s_mble : measurable_set (s : set α)) :
count (↑s : set α) = s.card :=
calc count (↑s : set α) = ∑' i : (↑s : set α), 1 : count_apply s.measurable_set
calc count (↑s : set α) = ∑' i : (↑s : set α), 1 : count_apply s_mble
... = ∑ i in s, 1 : s.tsum_subtype 1
... = s.card : by simp

@[simp] lemma count_apply_finset [measurable_singleton_class α] (s : finset α) :
count (↑s : set α) = s.card :=
count_apply_finset' s.measurable_set

lemma count_apply_finite' {s : set α} (s_fin : s.finite) (s_mble : measurable_set s) :
count s = s_fin.to_finset.card :=
by simp [← @count_apply_finset' _ _ s_fin.to_finset
(by simpa only [finite.coe_to_finset] using s_mble)]

lemma count_apply_finite [measurable_singleton_class α] (s : set α) (hs : s.finite) :
count s = hs.to_finset.card :=
by rw [← count_apply_finset, finite.coe_to_finset]
Expand All @@ -1862,52 +1871,97 @@ begin
... ≤ count s : measure_mono ht
end

variable [measurable_singleton_class α]

@[simp] lemma count_apply_eq_top : count s = ∞ ↔ s.infinite :=
@[simp] lemma count_apply_eq_top' (s_mble : measurable_set s) : count s = ∞ ↔ s.infinite :=
begin
by_cases hs : s.finite,
{ simp [set.infinite, hs, count_apply_finite] },
{ simp [set.infinite, hs, count_apply_finite' hs s_mble], },
{ change s.infinite at hs,
simp [hs, count_apply_infinite] }
simp [hs, count_apply_infinite], }
end

@[simp] lemma count_apply_lt_top : count s < ∞ ↔ s.finite :=
@[simp] lemma count_apply_eq_top [measurable_singleton_class α] : count s = ∞ ↔ s.infinite :=
begin
by_cases hs : s.finite,
{ exact count_apply_eq_top' hs.measurable_set, },
{ change s.infinite at hs,
simp [hs, count_apply_infinite], },
end

@[simp] lemma count_apply_lt_top' (s_mble : measurable_set s) : count s < ∞ ↔ s.finite :=
calc count s < ∞ ↔ count s ≠ ∞ : lt_top_iff_ne_top
... ↔ ¬s.infinite : not_congr (count_apply_eq_top' s_mble)
... ↔ s.finite : not_not

@[simp] lemma count_apply_lt_top [measurable_singleton_class α] : count s < ∞ ↔ s.finite :=
calc count s < ∞ ↔ count s ≠ ∞ : lt_top_iff_ne_top
... ↔ ¬s.infinite : not_congr count_apply_eq_top
... ↔ s.finite : not_not

lemma empty_of_count_eq_zero (hsc : count s = 0) : s = ∅ :=
lemma empty_of_count_eq_zero' (s_mble : measurable_set s) (hsc : count s = 0) : s = ∅ :=
begin
have hs : s.finite,
{ rw [← count_apply_lt_top' s_mble, hsc],
exact with_top.zero_lt_top },
simpa [count_apply_finite' hs s_mble] using hsc,
end

lemma empty_of_count_eq_zero [measurable_singleton_class α] (hsc : count s = 0) : s = ∅ :=
begin
have hs : s.finite,
{ rw [← count_apply_lt_top, hsc],
exact with_top.zero_lt_top },
rw count_apply_finite _ hs at hsc,
simpa using hsc,
simpa [count_apply_finite _ hs] using hsc,
end

@[simp] lemma count_eq_zero_iff : count s = 0 ↔ s = ∅ :=
@[simp] lemma count_eq_zero_iff' (s_mble : measurable_set s) : count s = 0 ↔ s = ∅ :=
⟨empty_of_count_eq_zero' s_mble, λ h, h.symm ▸ count_empty⟩

@[simp] lemma count_eq_zero_iff [measurable_singleton_class α] : count s = 0 ↔ s = ∅ :=
⟨empty_of_count_eq_zero, λ h, h.symm ▸ count_empty⟩

lemma count_ne_zero (hs' : s.nonempty) : count s ≠ 0 :=
lemma count_ne_zero' (hs' : s.nonempty) (s_mble : measurable_set s) : count s ≠ 0 :=
begin
rw [ne.def, count_eq_zero_iff' s_mble],
exact hs'.ne_empty,
end

lemma count_ne_zero [measurable_singleton_class α] (hs' : s.nonempty) : count s ≠ 0 :=
begin
rw [ne.def, count_eq_zero_iff],
exact hs'.ne_empty,
end

@[simp] lemma count_singleton (a : α) : count ({a} : set α) = 1 :=
@[simp] lemma count_singleton' {a : α} (ha : measurable_set ({a} : set α)) :
count ({a} : set α) = 1 :=
begin
rw [count_apply_finite ({a} : set α) (set.finite_singleton _), set.finite.to_finset],
rw [count_apply_finite' (set.finite_singleton a) ha, set.finite.to_finset],
simp,
end

lemma count_injective_image [measurable_singleton_class β]
{f : β → α} (hf : function.injective f) (s : set β) :
@[simp] lemma count_singleton [measurable_singleton_class α] (a : α) : count ({a} : set α) = 1 :=
count_singleton' (measurable_set_singleton a)

lemma count_injective_image' {f : β → α} (hf : function.injective f) {s : set β}
(s_mble : measurable_set s) (fs_mble : measurable_set (f '' s)):
count (f '' s) = count s :=
begin
by_cases hs : s.finite,
{ lift s to finset β using hs,
rw [← finset.coe_image, count_apply_finset, count_apply_finset, s.card_image_of_injective hf] },
rw [← finset.coe_image, count_apply_finset' _, count_apply_finset' s_mble,
s.card_image_of_injective hf],
simpa only [finset.coe_image] using fs_mble, },
rw count_apply_infinite hs,
rw ← (finite_image_iff $ hf.inj_on _) at hs,
rw count_apply_infinite hs,
end

lemma count_injective_image [measurable_singleton_class α] [measurable_singleton_class β]
{f : β → α} (hf : function.injective f) (s : set β) :
count (f '' s) = count s :=
begin
by_cases hs : s.finite,
{ exact count_injective_image' hf hs.measurable_set (finite.image f hs).measurable_set, },
rw count_apply_infinite hs,
rw ← (finite_image_iff $ hf.inj_on _) at hs,
rw count_apply_infinite hs,
Expand Down

0 comments on commit a0381d5

Please sign in to comment.