path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
MeasureTheory\MeasurableSpace\Embedding.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.MeasurableSpace.Basic
/-!
# Measurable embeddings and equivalences
A measurable equivalence between measurable spaces is an equivalence
which respects the σ-algebras, that is, for which both directions of
the equivalence are measurable functions.
## Main definitions
* `MeasurableEmbedding`: a map `f : α → β` is called a *measurable embedding* if it is injective,
measurable, and sends measurable sets to measurable sets.
* `MeasurableEquiv`: an equivalence `α ≃ β` is a *measurable equivalence* if its forward and inverse
functions are measurable.
We prove a multitude of elementary lemmas about these, and one more substantial theorem:
* `MeasurableEmbedding.schroederBernstein`: the **measurable Schröder-Bernstein Theorem**: given
measurable embeddings `α → β` and `β → α`, we can find a measurable equivalence `α ≃ᵐ β`.
## Notation
* We write `α ≃ᵐ β` for measurable equivalences between the measurable spaces `α` and `β`.
This should not be confused with `≃ₘ` which is used for diffeomorphisms between manifolds.
## Tags
measurable equivalence, measurable embedding
-/
open Set Function Equiv MeasureTheory
universe uι
variable {α β γ δ δ' : Type*} {ι : Sort uι} {s t u : Set α}
/-- A map `f : α → β` is called a *measurable embedding* if it is injective, measurable, and sends
measurable sets to measurable sets. The latter assumption can be replaced with “`f` has measurable
inverse `g : Set.range f → α`”, see `MeasurableEmbedding.measurable_rangeSplitting`,
`MeasurableEmbedding.of_measurable_inverse_range`, and
`MeasurableEmbedding.of_measurable_inverse`.
One more interpretation: `f` is a measurable embedding if it defines a measurable equivalence to its
range and the range is a measurable set. One implication is formalized as
`MeasurableEmbedding.equivRange`; the other one follows from
`MeasurableEquiv.measurableEmbedding`, `MeasurableEmbedding.subtype_coe`, and
`MeasurableEmbedding.comp`. -/
structure MeasurableEmbedding [MeasurableSpace α] [MeasurableSpace β] (f : α → β) : Prop where
/-- A measurable embedding is injective. -/
protected injective : Injective f
/-- A measurable embedding is a measurable function. -/
protected measurable : Measurable f
/-- The image of a measurable set under a measurable embedding is a measurable set. -/
protected measurableSet_image' : ∀ ⦃s⦄, MeasurableSet s → MeasurableSet (f '' s)
namespace MeasurableEmbedding
variable {mα : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] {f : α → β} {g : β → γ}
theorem measurableSet_image (hf : MeasurableEmbedding f) :
MeasurableSet (f '' s) ↔ MeasurableSet s :=
⟨fun h => by simpa only [hf.injective.preimage_image] using hf.measurable h, fun h =>
hf.measurableSet_image' h⟩
theorem id : MeasurableEmbedding (id : α → α) :=
⟨injective_id, measurable_id, fun s hs => by rwa [image_id]⟩
theorem comp (hg : MeasurableEmbedding g) (hf : MeasurableEmbedding f) :
MeasurableEmbedding (g ∘ f) :=
⟨hg.injective.comp hf.injective, hg.measurable.comp hf.measurable, fun s hs => by
rwa [image_comp, hg.measurableSet_image, hf.measurableSet_image]⟩
theorem subtype_coe (hs : MeasurableSet s) : MeasurableEmbedding ((↑) : s → α) where
injective := Subtype.coe_injective
measurable := measurable_subtype_coe
measurableSet_image' := fun _ => MeasurableSet.subtype_image hs
theorem measurableSet_range (hf : MeasurableEmbedding f) : MeasurableSet (range f) := by
rw [← image_univ]
exact hf.measurableSet_image' MeasurableSet.univ
theorem measurableSet_preimage (hf : MeasurableEmbedding f) {s : Set β} :
MeasurableSet (f ⁻¹' s) ↔ MeasurableSet (s ∩ range f) := by
rw [← image_preimage_eq_inter_range, hf.measurableSet_image]
theorem measurable_rangeSplitting (hf : MeasurableEmbedding f) :
Measurable (rangeSplitting f) := fun s hs => by
rwa [preimage_rangeSplitting hf.injective,
← (subtype_coe hf.measurableSet_range).measurableSet_image, ← image_comp,
coe_comp_rangeFactorization, hf.measurableSet_image]
theorem measurable_extend (hf : MeasurableEmbedding f) {g : α → γ} {g' : β → γ} (hg : Measurable g)
(hg' : Measurable g') : Measurable (extend f g g') := by
refine measurable_of_restrict_of_restrict_compl hf.measurableSet_range ?_ ?_
· rw [restrict_extend_range]
simpa only [rangeSplitting] using hg.comp hf.measurable_rangeSplitting
· rw [restrict_extend_compl_range]
exact hg'.comp measurable_subtype_coe
theorem exists_measurable_extend (hf : MeasurableEmbedding f) {g : α → γ} (hg : Measurable g)
(hne : β → Nonempty γ) : ∃ g' : β → γ, Measurable g' ∧ g' ∘ f = g :=
⟨extend f g fun x => Classical.choice (hne x),
hf.measurable_extend hg (measurable_const' fun _ _ => rfl),
funext fun _ => hf.injective.extend_apply _ _ _⟩
theorem measurable_comp_iff (hg : MeasurableEmbedding g) : Measurable (g ∘ f) ↔ Measurable f := by
refine ⟨fun H => ?_, hg.measurable.comp⟩
suffices Measurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) by
rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this
exact hg.measurable_rangeSplitting.comp H.subtype_mk
end MeasurableEmbedding
theorem MeasurableSet.exists_measurable_proj {_ : MeasurableSpace α}
(hs : MeasurableSet s) (hne : s.Nonempty) : ∃ f : α → s, Measurable f ∧ ∀ x : s, f x = x :=
let ⟨f, hfm, hf⟩ :=
(MeasurableEmbedding.subtype_coe hs).exists_measurable_extend measurable_id fun _ =>
hne.to_subtype
⟨f, hfm, congr_fun hf⟩
/-- Equivalences between measurable spaces. Main application is the simplification of measurability
statements along measurable equivalences. -/
structure MeasurableEquiv (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] extends α ≃ β where
/-- The forward function of a measurable equivalence is measurable. -/
measurable_toFun : Measurable toEquiv
/-- The inverse function of a measurable equivalence is measurable. -/
measurable_invFun : Measurable toEquiv.symm
@[inherit_doc]
infixl:25 " ≃ᵐ " => MeasurableEquiv
namespace MeasurableEquiv
variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
theorem toEquiv_injective : Injective (toEquiv : α ≃ᵐ β → α ≃ β) := by
rintro ⟨e₁, _, _⟩ ⟨e₂, _, _⟩ (rfl : e₁ = e₂)
rfl
instance instEquivLike : EquivLike (α ≃ᵐ β) α β where
coe e := e.toEquiv
inv e := e.toEquiv.symm
left_inv e := e.toEquiv.left_inv
right_inv e := e.toEquiv.right_inv
coe_injective' _ _ he _ := toEquiv_injective <| DFunLike.ext' he
@[simp]
theorem coe_toEquiv (e : α ≃ᵐ β) : (e.toEquiv : α → β) = e :=
rfl
@[measurability]
protected theorem measurable (e : α ≃ᵐ β) : Measurable (e : α → β) :=
e.measurable_toFun
@[simp]
theorem coe_mk (e : α ≃ β) (h1 : Measurable e) (h2 : Measurable e.symm) :
((⟨e, h1, h2⟩ : α ≃ᵐ β) : α → β) = e :=
rfl
/-- Any measurable space is equivalent to itself. -/
def refl (α : Type*) [MeasurableSpace α] : α ≃ᵐ α where
toEquiv := Equiv.refl α
measurable_toFun := measurable_id
measurable_invFun := measurable_id
instance instInhabited : Inhabited (α ≃ᵐ α) := ⟨refl α⟩
/-- The composition of equivalences between measurable spaces. -/
def trans (ab : α ≃ᵐ β) (bc : β ≃ᵐ γ) : α ≃ᵐ γ where
toEquiv := ab.toEquiv.trans bc.toEquiv
measurable_toFun := bc.measurable_toFun.comp ab.measurable_toFun
measurable_invFun := ab.measurable_invFun.comp bc.measurable_invFun
theorem coe_trans (ab : α ≃ᵐ β) (bc : β ≃ᵐ γ) : ⇑(ab.trans bc) = bc ∘ ab := rfl
/-- The inverse of an equivalence between measurable spaces. -/
def symm (ab : α ≃ᵐ β) : β ≃ᵐ α where
toEquiv := ab.toEquiv.symm
measurable_toFun := ab.measurable_invFun
measurable_invFun := ab.measurable_toFun
@[simp]
theorem coe_toEquiv_symm (e : α ≃ᵐ β) : (e.toEquiv.symm : β → α) = e.symm :=
rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def Simps.apply (h : α ≃ᵐ β) : α → β := h
/-- See Note [custom simps projection] -/
def Simps.symm_apply (h : α ≃ᵐ β) : β → α := h.symm
initialize_simps_projections MeasurableEquiv (toFun → apply, invFun → symm_apply)
@[ext] theorem ext {e₁ e₂ : α ≃ᵐ β} (h : (e₁ : α → β) = e₂) : e₁ = e₂ := DFunLike.ext' h
@[simp]
theorem symm_mk (e : α ≃ β) (h1 : Measurable e) (h2 : Measurable e.symm) :
(⟨e, h1, h2⟩ : α ≃ᵐ β).symm = ⟨e.symm, h2, h1⟩ :=
rfl
attribute [simps! apply toEquiv] trans refl
@[simp]
theorem symm_symm (e : α ≃ᵐ β) : e.symm.symm = e := rfl
theorem symm_bijective :
Function.Bijective (MeasurableEquiv.symm : (α ≃ᵐ β) → β ≃ᵐ α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp]
theorem symm_refl (α : Type*) [MeasurableSpace α] : (refl α).symm = refl α :=
rfl
@[simp]
theorem symm_comp_self (e : α ≃ᵐ β) : e.symm ∘ e = id :=
funext e.left_inv
@[simp]
theorem self_comp_symm (e : α ≃ᵐ β) : e ∘ e.symm = id :=
funext e.right_inv
@[simp]
theorem apply_symm_apply (e : α ≃ᵐ β) (y : β) : e (e.symm y) = y :=
e.right_inv y
@[simp]
theorem symm_apply_apply (e : α ≃ᵐ β) (x : α) : e.symm (e x) = x :=
e.left_inv x
@[simp]
theorem symm_trans_self (e : α ≃ᵐ β) : e.symm.trans e = refl β :=
ext e.self_comp_symm
@[simp]
theorem self_trans_symm (e : α ≃ᵐ β) : e.trans e.symm = refl α :=
ext e.symm_comp_self
protected theorem surjective (e : α ≃ᵐ β) : Surjective e :=
e.toEquiv.surjective
protected theorem bijective (e : α ≃ᵐ β) : Bijective e :=
e.toEquiv.bijective
protected theorem injective (e : α ≃ᵐ β) : Injective e :=
e.toEquiv.injective
@[simp]
theorem symm_preimage_preimage (e : α ≃ᵐ β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s :=
e.toEquiv.symm_preimage_preimage s
theorem image_eq_preimage (e : α ≃ᵐ β) (s : Set α) : e '' s = e.symm ⁻¹' s :=
e.toEquiv.image_eq_preimage s
lemma preimage_symm (e : α ≃ᵐ β) (s : Set α) : e.symm ⁻¹' s = e '' s := (image_eq_preimage _ _).symm
lemma image_symm (e : α ≃ᵐ β) (s : Set β) : e.symm '' s = e ⁻¹' s := by
rw [← symm_symm e, preimage_symm, symm_symm]
lemma eq_image_iff_symm_image_eq (e : α ≃ᵐ β) (s : Set β) (t : Set α) :
s = e '' t ↔ e.symm '' s = t := by
rw [← coe_toEquiv, Equiv.eq_image_iff_symm_image_eq, coe_toEquiv_symm]
@[simp]
lemma image_preimage (e : α ≃ᵐ β) (s : Set β) : e '' (e ⁻¹' s) = s := by
rw [← coe_toEquiv, Equiv.image_preimage]
@[simp]
lemma preimage_image (e : α ≃ᵐ β) (s : Set α) : e ⁻¹' (e '' s) = s := by
rw [← coe_toEquiv, Equiv.preimage_image]
@[simp]
theorem measurableSet_preimage (e : α ≃ᵐ β) {s : Set β} :
MeasurableSet (e ⁻¹' s) ↔ MeasurableSet s :=
⟨fun h => by simpa only [symm_preimage_preimage] using e.symm.measurable h, fun h =>
e.measurable h⟩
@[simp]
theorem measurableSet_image (e : α ≃ᵐ β) :
MeasurableSet (e '' s) ↔ MeasurableSet s := by rw [image_eq_preimage, measurableSet_preimage]
@[simp] theorem map_eq (e : α ≃ᵐ β) : MeasurableSpace.map e ‹_› = ‹_› :=
e.measurable.le_map.antisymm' fun _s ↦ e.measurableSet_preimage.1
/-- A measurable equivalence is a measurable embedding. -/
protected theorem measurableEmbedding (e : α ≃ᵐ β) : MeasurableEmbedding e where
injective := e.injective
measurable := e.measurable
measurableSet_image' := fun _ => e.measurableSet_image.2
/-- Equal measurable spaces are equivalent. -/
protected def cast {α β} [i₁ : MeasurableSpace α] [i₂ : MeasurableSpace β] (h : α = β)
(hi : HEq i₁ i₂) : α ≃ᵐ β where
toEquiv := Equiv.cast h
measurable_toFun := by
subst h
subst hi
exact measurable_id
measurable_invFun := by
subst h
subst hi
exact measurable_id
/-- Measurable equivalence between `ULift α` and `α`. -/
def ulift.{u, v} {α : Type u} [MeasurableSpace α] : ULift.{v, u} α ≃ᵐ α :=
⟨Equiv.ulift, measurable_down, measurable_up⟩
protected theorem measurable_comp_iff {f : β → γ} (e : α ≃ᵐ β) :
Measurable (f ∘ e) ↔ Measurable f :=
Iff.intro
(fun hfe => by
have : Measurable (f ∘ (e.symm.trans e).toEquiv) := hfe.comp e.symm.measurable
rwa [coe_toEquiv, symm_trans_self] at this)
fun h => h.comp e.measurable
/-- Any two types with unique elements are measurably equivalent. -/
def ofUniqueOfUnique (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] [Unique α] [Unique β] :
α ≃ᵐ β where
toEquiv := equivOfUnique α β
measurable_toFun := Subsingleton.measurable
measurable_invFun := Subsingleton.measurable
variable [MeasurableSpace δ] in
/-- Products of equivalent measurable spaces are equivalent. -/
def prodCongr (ab : α ≃ᵐ β) (cd : γ ≃ᵐ δ) : α × γ ≃ᵐ β × δ where
toEquiv := .prodCongr ab.toEquiv cd.toEquiv
measurable_toFun :=
(ab.measurable_toFun.comp measurable_id.fst).prod_mk
(cd.measurable_toFun.comp measurable_id.snd)
measurable_invFun :=
(ab.measurable_invFun.comp measurable_id.fst).prod_mk
(cd.measurable_invFun.comp measurable_id.snd)
/-- Products of measurable spaces are symmetric. -/
def prodComm : α × β ≃ᵐ β × α where
toEquiv := .prodComm α β
measurable_toFun := measurable_id.snd.prod_mk measurable_id.fst
measurable_invFun := measurable_id.snd.prod_mk measurable_id.fst
/-- Products of measurable spaces are associative. -/
def prodAssoc : (α × β) × γ ≃ᵐ α × β × γ where
toEquiv := .prodAssoc α β γ
measurable_toFun := measurable_fst.fst.prod_mk <| measurable_fst.snd.prod_mk measurable_snd
measurable_invFun := (measurable_fst.prod_mk measurable_snd.fst).prod_mk measurable_snd.snd
variable [MeasurableSpace δ] in
/-- Sums of measurable spaces are symmetric. -/
def sumCongr (ab : α ≃ᵐ β) (cd : γ ≃ᵐ δ) : α ⊕ γ ≃ᵐ β ⊕ δ where
toEquiv := .sumCongr ab.toEquiv cd.toEquiv
measurable_toFun := ab.measurable.sumMap cd.measurable
measurable_invFun := ab.symm.measurable.sumMap cd.symm.measurable
/-- `s ×ˢ t ≃ (s × t)` as measurable spaces. -/
def Set.prod (s : Set α) (t : Set β) : ↥(s ×ˢ t) ≃ᵐ s × t where
toEquiv := Equiv.Set.prod s t
measurable_toFun :=
measurable_id.subtype_val.fst.subtype_mk.prod_mk measurable_id.subtype_val.snd.subtype_mk
measurable_invFun :=
Measurable.subtype_mk <| measurable_id.fst.subtype_val.prod_mk measurable_id.snd.subtype_val
/-- `univ α ≃ α` as measurable spaces. -/
def Set.univ (α : Type*) [MeasurableSpace α] : (univ : Set α) ≃ᵐ α where
toEquiv := Equiv.Set.univ α
measurable_toFun := measurable_id.subtype_val
measurable_invFun := measurable_id.subtype_mk
/-- `{a} ≃ Unit` as measurable spaces. -/
def Set.singleton (a : α) : ({a} : Set α) ≃ᵐ Unit where
toEquiv := Equiv.Set.singleton a
measurable_toFun := measurable_const
measurable_invFun := measurable_const
/-- `α` is equivalent to its image in `α ⊕ β` as measurable spaces. -/
def Set.rangeInl : (range Sum.inl : Set (α ⊕ β)) ≃ᵐ α where
toEquiv := Equiv.Set.rangeInl α β
measurable_toFun s (hs : MeasurableSet s) := by
refine ⟨_, hs.inl_image, Set.ext ?_⟩
rintro ⟨ab, a, rfl⟩
simp [Set.range_inl]
measurable_invFun := Measurable.subtype_mk measurable_inl
/-- `β` is equivalent to its image in `α ⊕ β` as measurable spaces. -/
def Set.rangeInr : (range Sum.inr : Set (α ⊕ β)) ≃ᵐ β where
toEquiv := Equiv.Set.rangeInr α β
measurable_toFun s (hs : MeasurableSet s) := by
refine ⟨_, hs.inr_image, Set.ext ?_⟩
rintro ⟨ab, b, rfl⟩
simp [Set.range_inr]
measurable_invFun := Measurable.subtype_mk measurable_inr
/-- Products distribute over sums (on the right) as measurable spaces. -/
def sumProdDistrib (α β γ) [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] :
(α ⊕ β) × γ ≃ᵐ (α × γ) ⊕ (β × γ) where
toEquiv := .sumProdDistrib α β γ
measurable_toFun := by
refine
measurable_of_measurable_union_cover (range Sum.inl ×ˢ (univ : Set γ))
(range Sum.inr ×ˢ (univ : Set γ)) (measurableSet_range_inl.prod MeasurableSet.univ)
(measurableSet_range_inr.prod MeasurableSet.univ)
(by rintro ⟨a | b, c⟩ <;> simp [Set.prod_eq]) ?_ ?_
· refine (Set.prod (range Sum.inl) univ).symm.measurable_comp_iff.1 ?_
refine (prodCongr Set.rangeInl (Set.univ _)).symm.measurable_comp_iff.1 ?_
exact measurable_inl
· refine (Set.prod (range Sum.inr) univ).symm.measurable_comp_iff.1 ?_
refine (prodCongr Set.rangeInr (Set.univ _)).symm.measurable_comp_iff.1 ?_
exact measurable_inr
measurable_invFun :=
measurable_sum ((measurable_inl.comp measurable_fst).prod_mk measurable_snd)
((measurable_inr.comp measurable_fst).prod_mk measurable_snd)
/-- Products distribute over sums (on the left) as measurable spaces. -/
def prodSumDistrib (α β γ) [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] :
α × (β ⊕ γ) ≃ᵐ (α × β) ⊕ (α × γ) :=
prodComm.trans <| (sumProdDistrib _ _ _).trans <| sumCongr prodComm prodComm
/-- Products distribute over sums as measurable spaces. -/
def sumProdSum (α β γ δ) [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ] : (α ⊕ β) × (γ ⊕ δ) ≃ᵐ ((α × γ) ⊕ (α × δ)) ⊕ ((β × γ) ⊕ (β × δ)) :=
(sumProdDistrib _ _ _).trans <| sumCongr (prodSumDistrib _ _ _) (prodSumDistrib _ _ _)
variable {π π' : δ' → Type*} [∀ x, MeasurableSpace (π x)] [∀ x, MeasurableSpace (π' x)]
/-- A family of measurable equivalences `Π a, β₁ a ≃ᵐ β₂ a` generates a measurable equivalence
between `Π a, β₁ a` and `Π a, β₂ a`. -/
def piCongrRight (e : ∀ a, π a ≃ᵐ π' a) : (∀ a, π a) ≃ᵐ ∀ a, π' a where
toEquiv := .piCongrRight fun a => (e a).toEquiv
measurable_toFun :=
measurable_pi_lambda _ fun i => (e i).measurable_toFun.comp (measurable_pi_apply i)
measurable_invFun :=
measurable_pi_lambda _ fun i => (e i).measurable_invFun.comp (measurable_pi_apply i)
variable (π) in
/-- Moving a dependent type along an equivalence of coordinates, as a measurable equivalence. -/
def piCongrLeft (f : δ ≃ δ') : (∀ b, π (f b)) ≃ᵐ ∀ a, π a where
__ := Equiv.piCongrLeft π f
measurable_toFun := measurable_piCongrLeft f
measurable_invFun := by
simp only [invFun_as_coe, coe_fn_symm_mk]
rw [measurable_pi_iff]
exact fun i => measurable_pi_apply (f i)
theorem coe_piCongrLeft (f : δ ≃ δ') :
⇑(MeasurableEquiv.piCongrLeft π f) = f.piCongrLeft π := by rfl
lemma piCongrLeft_apply_apply {ι ι' : Type*} (e : ι ≃ ι') {β : ι' → Type*}
[∀ i', MeasurableSpace (β i')] (x : (i : ι) → β (e i)) (i : ι) :
piCongrLeft (fun i' ↦ β i') e x (e i) = x i := by
rw [piCongrLeft, coe_mk, Equiv.piCongrLeft_apply_apply]
/-- Pi-types are measurably equivalent to iterated products. -/
@[simps! (config := .asFn)]
def piMeasurableEquivTProd [DecidableEq δ'] {l : List δ'} (hnd : l.Nodup) (h : ∀ i, i ∈ l) :
(∀ i, π i) ≃ᵐ List.TProd π l where
toEquiv := List.TProd.piEquivTProd hnd h
measurable_toFun := measurable_tProd_mk l
measurable_invFun := measurable_tProd_elim' h
variable (π) in
/-- The measurable equivalence `(∀ i, π i) ≃ᵐ π ⋆` when the domain of `π` only contains `⋆` -/
@[simps! (config := .asFn)]
def piUnique [Unique δ'] : (∀ i, π i) ≃ᵐ π default where
toEquiv := Equiv.piUnique π
measurable_toFun := measurable_pi_apply _
measurable_invFun := measurable_uniqueElim
/-- If `α` has a unique term, then the type of function `α → β` is measurably equivalent to `β`. -/
@[simps! (config := .asFn)]
def funUnique (α β : Type*) [Unique α] [MeasurableSpace β] : (α → β) ≃ᵐ β :=
MeasurableEquiv.piUnique _
/-- The space `Π i : Fin 2, α i` is measurably equivalent to `α 0 × α 1`. -/
@[simps! (config := .asFn)]
def piFinTwo (α : Fin 2 → Type*) [∀ i, MeasurableSpace (α i)] : (∀ i, α i) ≃ᵐ α 0 × α 1 where
toEquiv := piFinTwoEquiv α
measurable_toFun := Measurable.prod (measurable_pi_apply _) (measurable_pi_apply _)
measurable_invFun := measurable_pi_iff.2 <| Fin.forall_fin_two.2 ⟨measurable_fst, measurable_snd⟩
/-- The space `Fin 2 → α` is measurably equivalent to `α × α`. -/
@[simps! (config := .asFn)]
def finTwoArrow : (Fin 2 → α) ≃ᵐ α × α :=
piFinTwo fun _ => α
/-- Measurable equivalence between `Π j : Fin (n + 1), α j` and
`α i × Π j : Fin n, α (Fin.succAbove i j)`. -/
@[simps! (config := .asFn)]
def piFinSuccAbove {n : ℕ} (α : Fin (n + 1) → Type*) [∀ i, MeasurableSpace (α i)]
(i : Fin (n + 1)) : (∀ j, α j) ≃ᵐ α i × ∀ j, α (i.succAbove j) where
toEquiv := .piFinSuccAbove α i
measurable_toFun := (measurable_pi_apply i).prod_mk <| measurable_pi_iff.2 fun j =>
measurable_pi_apply _
measurable_invFun := measurable_pi_iff.2 <| i.forall_iff_succAbove.2
⟨by simp only [piFinSuccAbove_symm_apply, Fin.insertNth_apply_same, measurable_fst],
fun j => by simpa only [piFinSuccAbove_symm_apply, Fin.insertNth_apply_succAbove]
using (measurable_pi_apply _).comp measurable_snd⟩
variable (π)
/-- Measurable equivalence between (dependent) functions on a type and pairs of functions on
`{i // p i}` and `{i // ¬p i}`. See also `Equiv.piEquivPiSubtypeProd`. -/
@[simps! (config := .asFn)]
def piEquivPiSubtypeProd (p : δ' → Prop) [DecidablePred p] :
(∀ i, π i) ≃ᵐ (∀ i : Subtype p, π i) × ∀ i : { i // ¬p i }, π i where
toEquiv := .piEquivPiSubtypeProd p π
measurable_toFun := measurable_piEquivPiSubtypeProd π p
measurable_invFun := measurable_piEquivPiSubtypeProd_symm π p
/-- The measurable equivalence between the pi type over a sum type and a product of pi-types.
This is similar to `MeasurableEquiv.piEquivPiSubtypeProd`. -/
def sumPiEquivProdPi (α : δ ⊕ δ' → Type*) [∀ i, MeasurableSpace (α i)] :
(∀ i, α i) ≃ᵐ (∀ i, α (.inl i)) × ∀ i', α (.inr i') where
__ := Equiv.sumPiEquivProdPi α
measurable_toFun := by
apply Measurable.prod <;> rw [measurable_pi_iff] <;> rintro i <;> apply measurable_pi_apply
measurable_invFun := by
rw [measurable_pi_iff]; rintro (i | i)
· exact measurable_pi_iff.1 measurable_fst _
· exact measurable_pi_iff.1 measurable_snd _
theorem coe_sumPiEquivProdPi (α : δ ⊕ δ' → Type*) [∀ i, MeasurableSpace (α i)] :
⇑(MeasurableEquiv.sumPiEquivProdPi α) = Equiv.sumPiEquivProdPi α := by rfl
theorem coe_sumPiEquivProdPi_symm (α : δ ⊕ δ' → Type*) [∀ i, MeasurableSpace (α i)] :
⇑(MeasurableEquiv.sumPiEquivProdPi α).symm = (Equiv.sumPiEquivProdPi α).symm := by rfl
/-- The measurable equivalence for (dependent) functions on an Option type
`(∀ i : Option δ, α i) ≃ᵐ (∀ (i : δ), α i) × α none`. -/
def piOptionEquivProd {δ : Type*} (α : Option δ → Type*) [∀ i, MeasurableSpace (α i)] :
(∀ i, α i) ≃ᵐ (∀ (i : δ), α i) × α none :=
let e : Option δ ≃ δ ⊕ Unit := Equiv.optionEquivSumPUnit δ
let em1 : ((i : δ ⊕ Unit) → α (e.symm i)) ≃ᵐ ((a : Option δ) → α a) :=
MeasurableEquiv.piCongrLeft α e.symm
let em2 : ((i : δ ⊕ Unit) → α (e.symm i)) ≃ᵐ ((i : δ) → α (e.symm (Sum.inl i)))
× ((i' : Unit) → α (e.symm (Sum.inr i'))) :=
MeasurableEquiv.sumPiEquivProdPi (fun i ↦ α (e.symm i))
let em3 : ((i : δ) → α (e.symm (Sum.inl i))) × ((i' : Unit) → α (e.symm (Sum.inr i')))
≃ᵐ ((i : δ) → α (some i)) × α none :=
MeasurableEquiv.prodCongr (MeasurableEquiv.refl ((i : δ) → α (e.symm (Sum.inl i))))
(MeasurableEquiv.piUnique fun i ↦ α (e.symm (Sum.inr i)))
em1.symm.trans <| em2.trans em3
/-- The measurable equivalence `(∀ i : s, π i) × (∀ i : t, π i) ≃ᵐ (∀ i : s ∪ t, π i)`
for disjoint finsets `s` and `t`. `Equiv.piFinsetUnion` as a measurable equivalence. -/
def piFinsetUnion [DecidableEq δ'] {s t : Finset δ'} (h : Disjoint s t) :
((∀ i : s, π i) × ∀ i : t, π i) ≃ᵐ ∀ i : (s ∪ t : Finset δ'), π i :=
letI e := Finset.union s t h
MeasurableEquiv.sumPiEquivProdPi (fun b ↦ π (e b)) |>.symm.trans <|
.piCongrLeft (fun i : ↥(s ∪ t) ↦ π i) e
/-- If `s` is a measurable set in a measurable space, that space is equivalent
to the sum of `s` and `sᶜ`. -/
def sumCompl {s : Set α} [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
s ⊕ (sᶜ : Set α) ≃ᵐ α where
toEquiv := .sumCompl (· ∈ s)
measurable_toFun := measurable_subtype_coe.sumElim measurable_subtype_coe
measurable_invFun := Measurable.dite measurable_inl measurable_inr hs
/-- Convert a measurable involutive function `f` to a measurable permutation with
`toFun = invFun = f`. See also `Function.Involutive.toPerm`. -/
@[simps toEquiv]
def ofInvolutive (f : α → α) (hf : Involutive f) (hf' : Measurable f) : α ≃ᵐ α where
toEquiv := hf.toPerm
measurable_toFun := hf'
measurable_invFun := hf'
@[simp] theorem ofInvolutive_apply (f : α → α) (hf : Involutive f) (hf' : Measurable f) (a : α) :
ofInvolutive f hf hf' a = f a := rfl
@[simp] theorem ofInvolutive_symm (f : α → α) (hf : Involutive f) (hf' : Measurable f) :
(ofInvolutive f hf hf').symm = ofInvolutive f hf hf' := rfl
end MeasurableEquiv
namespace MeasurableEmbedding
variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] {f : α → β} {g : β → α}
@[simp] theorem comap_eq (hf : MeasurableEmbedding f) : MeasurableSpace.comap f ‹_› = ‹_› :=
hf.measurable.comap_le.antisymm fun _s h ↦
⟨_, hf.measurableSet_image' h, hf.injective.preimage_image _⟩
theorem iff_comap_eq :
MeasurableEmbedding f ↔
Injective f ∧ MeasurableSpace.comap f ‹_› = ‹_› ∧ MeasurableSet (range f) :=
⟨fun hf ↦ ⟨hf.injective, hf.comap_eq, hf.measurableSet_range⟩, fun hf ↦
{ injective := hf.1
measurable := by rw [← hf.2.1]; exact comap_measurable f
measurableSet_image' := by
rw [← hf.2.1]
rintro _ ⟨s, hs, rfl⟩
simpa only [image_preimage_eq_inter_range] using hs.inter hf.2.2 }⟩
/-- A set is equivalent to its image under a function `f` as measurable spaces,
if `f` is a measurable embedding -/
noncomputable def equivImage (s : Set α) (hf : MeasurableEmbedding f) : s ≃ᵐ f '' s where
toEquiv := Equiv.Set.image f s hf.injective
measurable_toFun := (hf.measurable.comp measurable_id.subtype_val).subtype_mk
measurable_invFun := by
rintro t ⟨u, hu, rfl⟩; simp [preimage_preimage, Set.image_symm_preimage hf.injective]
exact measurable_subtype_coe (hf.measurableSet_image' hu)
/-- The domain of `f` is equivalent to its range as measurable spaces,
if `f` is a measurable embedding -/
noncomputable def equivRange (hf : MeasurableEmbedding f) : α ≃ᵐ range f :=
(MeasurableEquiv.Set.univ _).symm.trans <|
(hf.equivImage univ).trans <| MeasurableEquiv.cast (by rw [image_univ]) (by rw [image_univ])
theorem of_measurable_inverse_on_range {g : range f → α} (hf₁ : Measurable f)
(hf₂ : MeasurableSet (range f)) (hg : Measurable g) (H : LeftInverse g (rangeFactorization f)) :
MeasurableEmbedding f := by
set e : α ≃ᵐ range f :=
⟨⟨rangeFactorization f, g, H, H.rightInverse_of_surjective surjective_onto_range⟩,
hf₁.subtype_mk, hg⟩
exact (MeasurableEmbedding.subtype_coe hf₂).comp e.measurableEmbedding
theorem of_measurable_inverse (hf₁ : Measurable f) (hf₂ : MeasurableSet (range f))
(hg : Measurable g) (H : LeftInverse g f) : MeasurableEmbedding f :=
of_measurable_inverse_on_range hf₁ hf₂ (hg.comp measurable_subtype_coe) H
/-- The **measurable Schröder-Bernstein Theorem**: given measurable embeddings
`α → β` and `β → α`, we can find a measurable equivalence `α ≃ᵐ β`. -/
noncomputable def schroederBernstein {f : α → β} {g : β → α} (hf : MeasurableEmbedding f)
(hg : MeasurableEmbedding g) : α ≃ᵐ β := by
let F : Set α → Set α := fun A => (g '' (f '' A)ᶜ)ᶜ
-- We follow the proof of the usual SB theorem in mathlib,
-- the crux of which is finding a fixed point of this F.
-- However, we must find this fixed point manually instead of invoking Knaster-Tarski
-- in order to make sure it is measurable.
suffices Σ'A : Set α, MeasurableSet A ∧ F A = A by
classical
rcases this with ⟨A, Ameas, Afp⟩
let B := f '' A
have Bmeas : MeasurableSet B := hf.measurableSet_image' Ameas
refine (MeasurableEquiv.sumCompl Ameas).symm.trans
(MeasurableEquiv.trans ?_ (MeasurableEquiv.sumCompl Bmeas))
apply MeasurableEquiv.sumCongr (hf.equivImage _)
have : Aᶜ = g '' Bᶜ := by
apply compl_injective
rw [← Afp]
simp
rw [this]
exact (hg.equivImage _).symm
have Fmono : ∀ {A B}, A ⊆ B → F A ⊆ F B := fun h =>
compl_subset_compl.mpr <| Set.image_subset _ <| compl_subset_compl.mpr <| Set.image_subset _ h
let X : ℕ → Set α := fun n => F^[n] univ
refine ⟨iInter X, ?_, ?_⟩
· apply MeasurableSet.iInter
intro n
induction' n with n ih
· exact MeasurableSet.univ
rw [Function.iterate_succ', Function.comp_apply]
exact (hg.measurableSet_image' (hf.measurableSet_image' ih).compl).compl
apply subset_antisymm
· apply subset_iInter
intro n
cases n
· exact subset_univ _
rw [Function.iterate_succ', Function.comp_apply]
exact Fmono (iInter_subset _ _)
rintro x hx ⟨y, hy, rfl⟩
rw [mem_iInter] at hx
apply hy
rw [hf.injective.injOn.image_iInter_eq]
rw [mem_iInter]
intro n
specialize hx n.succ
rw [Function.iterate_succ', Function.comp_apply] at hx
by_contra h
apply hx
exact ⟨y, h, rfl⟩
end MeasurableEmbedding
theorem MeasurableSpace.comap_compl {m' : MeasurableSpace β} [BooleanAlgebra β]
(h : Measurable (compl : β → β)) (f : α → β) :
MeasurableSpace.comap (fun a => (f a)ᶜ) inferInstance =
MeasurableSpace.comap f inferInstance := by
rw [← Function.comp_def, ← MeasurableSpace.comap_comp]
congr
exact (MeasurableEquiv.ofInvolutive _ compl_involutive h).measurableEmbedding.comap_eq
@[simp] theorem MeasurableSpace.comap_not (p : α → Prop) :
MeasurableSpace.comap (fun a ↦ ¬p a) inferInstance = MeasurableSpace.comap p inferInstance :=
MeasurableSpace.comap_compl (fun _ _ ↦ measurableSet_top) _
|
MeasureTheory\MeasurableSpace\Instances.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.MeasurableSpace.Defs
import Mathlib.Data.Rat.Init
import Mathlib.Data.ZMod.Defs
/-!
# Measurable-space typeclass instances
This file provides measurable-space instances for a selection of standard countable types,
in each case defining the Σ-algebra to be `⊤` (the discrete measurable-space structure).
-/
instance Empty.instMeasurableSpace : MeasurableSpace Empty := ⊤
instance PUnit.instMeasurableSpace : MeasurableSpace PUnit := ⊤
instance Bool.instMeasurableSpace : MeasurableSpace Bool := ⊤
instance Prop.instMeasurableSpace : MeasurableSpace Prop := ⊤
instance Nat.instMeasurableSpace : MeasurableSpace ℕ := ⊤
instance Fin.instMeasurableSpace (n : ℕ) : MeasurableSpace (Fin n) := ⊤
instance ZMod.instMeasurableSpace (n : ℕ) : MeasurableSpace (ZMod n) := ⊤
instance Int.instMeasurableSpace : MeasurableSpace ℤ := ⊤
instance Rat.instMeasurableSpace : MeasurableSpace ℚ := ⊤
instance Subsingleton.measurableSingletonClass {α} [MeasurableSpace α] [Subsingleton α] :
MeasurableSingletonClass α := by
refine ⟨fun i => ?_⟩
convert MeasurableSet.univ
simp [Set.eq_univ_iff_forall, eq_iff_true_of_subsingleton]
instance Bool.instMeasurableSingletonClass : MeasurableSingletonClass Bool := ⟨fun _ => trivial⟩
instance Prop.instMeasurableSingletonClass : MeasurableSingletonClass Prop := ⟨fun _ => trivial⟩
instance Nat.instMeasurableSingletonClass : MeasurableSingletonClass ℕ := ⟨fun _ => trivial⟩
instance Fin.instMeasurableSingletonClass (n : ℕ) : MeasurableSingletonClass (Fin n) :=
⟨fun _ => trivial⟩
instance ZMod.instMeasurableSingletonClass (n : ℕ) : MeasurableSingletonClass (ZMod n) :=
⟨fun _ => trivial⟩
instance Int.instMeasurableSingletonClass : MeasurableSingletonClass ℤ := ⟨fun _ => trivial⟩
instance Rat.instMeasurableSingletonClass : MeasurableSingletonClass ℚ := ⟨fun _ => trivial⟩
|
MeasureTheory\MeasurableSpace\Invariants.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.MeasurableSpace.Defs
/-!
# σ-algebra of sets invariant under a self-map
In this file we define `MeasurableSpace.invariants (f : α → α)`
to be the σ-algebra of sets `s : Set α` such that
- `s` is measurable w.r.t. the canonical σ-algebra on `α`;
- and `f ⁻ˢ' s = s`.
-/
open Set Function
open scoped MeasureTheory
namespace MeasurableSpace
variable {α : Type*}
/-- Given a self-map `f : α → α`,
`invariants f` is the σ-algebra of measurable sets that are invariant under `f`.
A set `s` is `(invariants f)`-measurable
iff it is meaurable w.r.t. the canonical σ-algebra on `α` and `f ⁻¹' s = s`. -/
def invariants [m : MeasurableSpace α] (f : α → α) : MeasurableSpace α :=
{ m ⊓ ⟨fun s ↦ f ⁻¹' s = s, by simp, by simp, fun f hf ↦ by simp [hf]⟩ with
MeasurableSet' := fun s ↦ MeasurableSet[m] s ∧ f ⁻¹' s = s }
variable [MeasurableSpace α]
/-- A set `s` is `(invariants f)`-measurable
iff it is meaurable w.r.t. the canonical σ-algebra on `α` and `f ⁻¹' s = s`. -/
theorem measurableSet_invariants {f : α → α} {s : Set α} :
MeasurableSet[invariants f] s ↔ MeasurableSet s ∧ f ⁻¹' s = s :=
.rfl
@[simp]
theorem invariants_id : invariants (id : α → α) = ‹MeasurableSpace α› :=
ext fun _ ↦ ⟨And.left, fun h ↦ ⟨h, rfl⟩⟩
theorem invariants_le (f : α → α) : invariants f ≤ ‹MeasurableSpace α› := fun _ ↦ And.left
theorem inf_le_invariants_comp (f g : α → α) :
invariants f ⊓ invariants g ≤ invariants (f ∘ g) := fun s hs ↦
⟨hs.1.1, by rw [preimage_comp, hs.1.2, hs.2.2]⟩
theorem le_invariants_iterate (f : α → α) (n : ℕ) :
invariants f ≤ invariants (f^[n]) := by
induction n with
| zero => simp [invariants_le]
| succ n ihn => exact le_trans (le_inf ihn le_rfl) (inf_le_invariants_comp _ _)
variable {β : Type*} [MeasurableSpace β]
theorem measurable_invariants_dom {f : α → α} {g : α → β} :
Measurable[invariants f] g ↔ Measurable g ∧ ∀ s, MeasurableSet s → (g ∘ f) ⁻¹' s = g ⁻¹' s := by
simp only [Measurable, ← forall_and]; rfl
theorem measurable_invariants_of_semiconj {fa : α → α} {fb : β → β} {g : α → β} (hg : Measurable g)
(hfg : Semiconj g fa fb) : @Measurable _ _ (invariants fa) (invariants fb) g := fun s hs ↦
⟨hg hs.1, by rw [← preimage_comp, hfg.comp_eq, preimage_comp, hs.2]⟩
end MeasurableSpace
|
MeasureTheory\Measure\AddContent.lean | /-
Copyright (c) 2024 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Peter Pfaffelhuber
-/
import Mathlib.Data.ENNReal.Basic
import Mathlib.MeasureTheory.SetSemiring
/-!
# Additive Contents
An additive content `m` on a set of sets `C` is a set function with value 0 at the empty set which
is finitely additive on `C`. That means that for any finset `I` of pairwise disjoint sets in `C`
such that `⋃₀ I ∈ C`, `m (⋃₀ I) = ∑ s ∈ I, m s`.
Mathlib also has a definition of contents over compact sets: see `MeasureTheory.Content`.
A `Content` is in particular an `AddContent` on the set of compact sets.
## Main definitions
* `MeasureTheory.AddContent C`: additive contents over the set of sets `C`.
## Main statements
Let `m` be an `AddContent C`. If `C` is a set semi-ring (`IsSetSemiring C`) we have the properties
* `MeasureTheory.sum_addContent_le_of_subset`: if `I` is a finset of pairwise disjoint sets in `C`
and `⋃₀ I ⊆ t` for `t ∈ C`, then `∑ s ∈ I, m s ≤ m t`.
* `MeasureTheory.addContent_mono`: if `s ⊆ t` for two sets in `C`, then `m s ≤ m t`.
* `MeasureTheory.addContent_union'`: if `s, t ∈ C` are disjoint and `s ∪ t ∈ C`,
then `m (s ∪ t) = m s + m t`.
If `C` is a set ring (`IsSetRing`), then `addContent_union` gives the same conclusion without the
hypothesis `s ∪ t ∈ C` (since it is a consequence of `IsSetRing C`).
If `C` is a set ring (`MeasureTheory.IsSetRing C`), we have, for `s, t ∈ C`,
* `MeasureTheory.addContent_union_le`: `m (s ∪ t) ≤ m s + m t`
* `MeasureTheory.addContent_le_diff`: `m s - m t ≤ m (s \ t)`
-/
open Set Finset
open scoped ENNReal
namespace MeasureTheory
variable {α : Type*} {C : Set (Set α)} {s t : Set α} {I : Finset (Set α)}
/-- An additive content is a set function with value 0 at the empty set which is finitely additive
on a given set of sets. -/
structure AddContent (C : Set (Set α)) where
/-- The value of the content on a set. -/
toFun : Set α → ℝ≥0∞
empty' : toFun ∅ = 0
sUnion' (I : Finset (Set α)) (_h_ss : ↑I ⊆ C)
(_h_dis : PairwiseDisjoint (I : Set (Set α)) id) (_h_mem : ⋃₀ ↑I ∈ C) :
toFun (⋃₀ I) = ∑ u ∈ I, toFun u
instance : Inhabited (AddContent C) :=
⟨{toFun := fun _ => 0
empty' := by simp
sUnion' := by simp }⟩
instance : DFunLike (AddContent C) (Set α) (fun _ ↦ ℝ≥0∞) where
coe := fun m s ↦ m.toFun s
coe_injective' := by
intro m m' h
cases m
cases m'
congr
variable {m m' : AddContent C}
@[ext] protected lemma AddContent.ext (h : ∀ s, m s = m' s) : m = m' :=
DFunLike.ext _ _ h
@[simp] lemma addContent_empty : m ∅ = 0 := m.empty'
lemma addContent_sUnion (h_ss : ↑I ⊆ C)
(h_dis : PairwiseDisjoint (I : Set (Set α)) id) (h_mem : ⋃₀ ↑I ∈ C) :
m (⋃₀ I) = ∑ u ∈ I, m u :=
m.sUnion' I h_ss h_dis h_mem
lemma addContent_union' (hs : s ∈ C) (ht : t ∈ C) (hst : s ∪ t ∈ C) (h_dis : Disjoint s t) :
m (s ∪ t) = m s + m t := by
by_cases hs_empty : s = ∅
· simp only [hs_empty, Set.empty_union, addContent_empty, zero_add]
classical
have h := addContent_sUnion (m := m) (I := {s, t}) ?_ ?_ ?_
rotate_left
· simp only [coe_pair, Set.insert_subset_iff, hs, ht, Set.singleton_subset_iff, and_self_iff]
· simp only [coe_pair, Set.pairwiseDisjoint_insert, pairwiseDisjoint_singleton,
mem_singleton_iff, Ne, id, forall_eq, true_and_iff]
exact fun _ => h_dis
· simp only [coe_pair, sUnion_insert, sUnion_singleton]
exact hst
convert h
· simp only [coe_pair, sUnion_insert, sUnion_singleton]
· rw [sum_insert, sum_singleton]
simp only [Finset.mem_singleton]
refine fun hs_eq_t => hs_empty ?_
rw [← hs_eq_t] at h_dis
exact Disjoint.eq_bot_of_self h_dis
section IsSetSemiring
lemma addContent_eq_add_diffFinset₀_of_subset (hC : IsSetSemiring C)
(hs : s ∈ C) (hI : ↑I ⊆ C) (hI_ss : ∀ t ∈ I, t ⊆ s)
(h_dis : PairwiseDisjoint (I : Set (Set α)) id) :
m s = ∑ i ∈ I, m i + ∑ i ∈ hC.diffFinset₀ hs hI, m i := by
classical
conv_lhs => rw [← hC.sUnion_union_diffFinset₀_of_subset hs hI hI_ss]
rw [addContent_sUnion]
· rw [sum_union]
exact hC.disjoint_diffFinset₀ hs hI
· rw [coe_union]
exact Set.union_subset hI (hC.diffFinset₀_subset hs hI)
· rw [coe_union]
exact hC.pairwiseDisjoint_union_diffFinset₀ hs hI h_dis
· rwa [hC.sUnion_union_diffFinset₀_of_subset hs hI hI_ss]
lemma sum_addContent_le_of_subset (hC : IsSetSemiring C)
(h_ss : ↑I ⊆ C) (h_dis : PairwiseDisjoint (I : Set (Set α)) id)
(ht : t ∈ C) (hJt : ∀ s ∈ I, s ⊆ t) :
∑ u ∈ I, m u ≤ m t := by
classical
rw [addContent_eq_add_diffFinset₀_of_subset hC ht h_ss hJt h_dis]
exact le_add_right le_rfl
lemma addContent_mono (hC : IsSetSemiring C) (hs : s ∈ C) (ht : t ∈ C)
(hst : s ⊆ t) :
m s ≤ m t := by
have h := sum_addContent_le_of_subset (m := m) hC (I := {s}) ?_ ?_ ht ?_
· simpa only [sum_singleton] using h
· rwa [singleton_subset_set_iff]
· simp only [coe_singleton, pairwiseDisjoint_singleton]
· simp [hst]
end IsSetSemiring
section IsSetRing
lemma addContent_union (hC : IsSetRing C) (hs : s ∈ C) (ht : t ∈ C)
(h_dis : Disjoint s t) :
m (s ∪ t) = m s + m t :=
addContent_union' hs ht (hC.union_mem hs ht) h_dis
lemma addContent_union_le (hC : IsSetRing C) (hs : s ∈ C) (ht : t ∈ C) :
m (s ∪ t) ≤ m s + m t := by
rw [← union_diff_self, addContent_union hC hs (hC.diff_mem ht hs)]
· exact add_le_add le_rfl
(addContent_mono hC.isSetSemiring (hC.diff_mem ht hs) ht diff_subset)
· rw [Set.disjoint_iff_inter_eq_empty, inter_diff_self]
lemma addContent_biUnion_le {ι : Type*} (hC : IsSetRing C) {s : ι → Set α}
{S : Finset ι} (hs : ∀ n ∈ S, s n ∈ C) :
m (⋃ i ∈ S, s i) ≤ ∑ i ∈ S, m (s i) := by
classical
induction' S using Finset.induction with i S hiS h hs
· simp
· rw [Finset.sum_insert hiS]
simp_rw [← Finset.mem_coe, Finset.coe_insert, Set.biUnion_insert]
simp only [Finset.mem_insert, forall_eq_or_imp] at hs
refine (addContent_union_le hC hs.1 (hC.biUnion_mem S hs.2)).trans ?_
exact add_le_add le_rfl (h hs.2)
lemma le_addContent_diff (m : AddContent C) (hC : IsSetRing C) (hs : s ∈ C) (ht : t ∈ C) :
m s - m t ≤ m (s \ t) := by
conv_lhs => rw [← inter_union_diff s t]
rw [addContent_union hC (hC.inter_mem hs ht) (hC.diff_mem hs ht) disjoint_inf_sdiff, add_comm]
refine add_tsub_le_assoc.trans_eq ?_
rw [tsub_eq_zero_of_le
(addContent_mono hC.isSetSemiring (hC.inter_mem hs ht) ht inter_subset_right), add_zero]
end IsSetRing
end MeasureTheory
|
MeasureTheory\Measure\AEDisjoint.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.MeasureSpaceDef
/-!
# Almost everywhere disjoint sets
We say that sets `s` and `t` are `μ`-a.e. disjoint (see `MeasureTheory.AEDisjoint`) if their
intersection has measure zero. This assumption can be used instead of `Disjoint` in most theorems in
measure theory.
-/
open Set Function
namespace MeasureTheory
variable {ι α : Type*} {m : MeasurableSpace α} (μ : Measure α)
/-- Two sets are said to be `μ`-a.e. disjoint if their intersection has measure zero. -/
def AEDisjoint (s t : Set α) :=
μ (s ∩ t) = 0
variable {μ} {s t u v : Set α}
/-- If `s : ι → Set α` is a countable family of pairwise a.e. disjoint sets, then there exists a
family of measurable null sets `t i` such that `s i \ t i` are pairwise disjoint. -/
theorem exists_null_pairwise_disjoint_diff [Countable ι] {s : ι → Set α}
(hd : Pairwise (AEDisjoint μ on s)) : ∃ t : ι → Set α, (∀ i, MeasurableSet (t i)) ∧
(∀ i, μ (t i) = 0) ∧ Pairwise (Disjoint on fun i => s i \ t i) := by
refine ⟨fun i => toMeasurable μ (s i ∩ ⋃ j ∈ ({i}ᶜ : Set ι), s j), fun i =>
measurableSet_toMeasurable _ _, fun i => ?_, ?_⟩
· simp only [measure_toMeasurable, inter_iUnion]
exact (measure_biUnion_null_iff <| to_countable _).2 fun j hj => hd (Ne.symm hj)
· simp only [Pairwise, disjoint_left, onFun, mem_diff, not_and, and_imp, Classical.not_not]
intro i j hne x hi hU hj
replace hU : x ∉ s i ∩ iUnion fun j ↦ iUnion fun _ ↦ s j :=
fun h ↦ hU (subset_toMeasurable _ _ h)
simp only [mem_inter_iff, mem_iUnion, not_and, not_exists] at hU
exact (hU hi j hne.symm hj).elim
namespace AEDisjoint
protected theorem eq (h : AEDisjoint μ s t) : μ (s ∩ t) = 0 :=
h
@[symm]
protected theorem symm (h : AEDisjoint μ s t) : AEDisjoint μ t s := by rwa [AEDisjoint, inter_comm]
protected theorem symmetric : Symmetric (AEDisjoint μ) := fun _ _ => AEDisjoint.symm
protected theorem comm : AEDisjoint μ s t ↔ AEDisjoint μ t s :=
⟨AEDisjoint.symm, AEDisjoint.symm⟩
protected theorem _root_.Disjoint.aedisjoint (h : Disjoint s t) : AEDisjoint μ s t := by
rw [AEDisjoint, disjoint_iff_inter_eq_empty.1 h, measure_empty]
protected theorem _root_.Pairwise.aedisjoint {f : ι → Set α} (hf : Pairwise (Disjoint on f)) :
Pairwise (AEDisjoint μ on f) :=
hf.mono fun _i _j h => h.aedisjoint
protected theorem _root_.Set.PairwiseDisjoint.aedisjoint {f : ι → Set α} {s : Set ι}
(hf : s.PairwiseDisjoint f) : s.Pairwise (AEDisjoint μ on f) :=
hf.mono' fun _i _j h => h.aedisjoint
theorem mono_ae (h : AEDisjoint μ s t) (hu : u ≤ᵐ[μ] s) (hv : v ≤ᵐ[μ] t) : AEDisjoint μ u v :=
measure_mono_null_ae (hu.inter hv) h
protected theorem mono (h : AEDisjoint μ s t) (hu : u ⊆ s) (hv : v ⊆ t) : AEDisjoint μ u v :=
mono_ae h (HasSubset.Subset.eventuallyLE hu) (HasSubset.Subset.eventuallyLE hv)
protected theorem congr (h : AEDisjoint μ s t) (hu : u =ᵐ[μ] s) (hv : v =ᵐ[μ] t) :
AEDisjoint μ u v :=
mono_ae h (Filter.EventuallyEq.le hu) (Filter.EventuallyEq.le hv)
@[simp]
theorem iUnion_left_iff [Countable ι] {s : ι → Set α} :
AEDisjoint μ (⋃ i, s i) t ↔ ∀ i, AEDisjoint μ (s i) t := by
simp only [AEDisjoint, iUnion_inter, measure_iUnion_null_iff]
@[simp]
theorem iUnion_right_iff [Countable ι] {t : ι → Set α} :
AEDisjoint μ s (⋃ i, t i) ↔ ∀ i, AEDisjoint μ s (t i) := by
simp only [AEDisjoint, inter_iUnion, measure_iUnion_null_iff]
@[simp]
theorem union_left_iff : AEDisjoint μ (s ∪ t) u ↔ AEDisjoint μ s u ∧ AEDisjoint μ t u := by
simp [union_eq_iUnion, and_comm]
@[simp]
theorem union_right_iff : AEDisjoint μ s (t ∪ u) ↔ AEDisjoint μ s t ∧ AEDisjoint μ s u := by
simp [union_eq_iUnion, and_comm]
theorem union_left (hs : AEDisjoint μ s u) (ht : AEDisjoint μ t u) : AEDisjoint μ (s ∪ t) u :=
union_left_iff.mpr ⟨hs, ht⟩
theorem union_right (ht : AEDisjoint μ s t) (hu : AEDisjoint μ s u) : AEDisjoint μ s (t ∪ u) :=
union_right_iff.2 ⟨ht, hu⟩
theorem diff_ae_eq_left (h : AEDisjoint μ s t) : (s \ t : Set α) =ᵐ[μ] s :=
@diff_self_inter _ s t ▸ diff_null_ae_eq_self h
theorem diff_ae_eq_right (h : AEDisjoint μ s t) : (t \ s : Set α) =ᵐ[μ] t :=
diff_ae_eq_left <| AEDisjoint.symm h
theorem measure_diff_left (h : AEDisjoint μ s t) : μ (s \ t) = μ s :=
measure_congr <| AEDisjoint.diff_ae_eq_left h
theorem measure_diff_right (h : AEDisjoint μ s t) : μ (t \ s) = μ t :=
measure_congr <| AEDisjoint.diff_ae_eq_right h
/-- If `s` and `t` are `μ`-a.e. disjoint, then `s \ u` and `t` are disjoint for some measurable null
set `u`. -/
theorem exists_disjoint_diff (h : AEDisjoint μ s t) :
∃ u, MeasurableSet u ∧ μ u = 0 ∧ Disjoint (s \ u) t :=
⟨toMeasurable μ (s ∩ t), measurableSet_toMeasurable _ _, (measure_toMeasurable _).trans h,
disjoint_sdiff_self_left.mono_left fun x hx => by
simp; exact ⟨hx.1, fun hxt => hx.2 <| subset_toMeasurable _ _ ⟨hx.1, hxt⟩⟩⟩
theorem of_null_right (h : μ t = 0) : AEDisjoint μ s t :=
measure_mono_null inter_subset_right h
theorem of_null_left (h : μ s = 0) : AEDisjoint μ s t :=
AEDisjoint.symm (of_null_right h)
end AEDisjoint
theorem aedisjoint_compl_left : AEDisjoint μ sᶜ s :=
(@disjoint_compl_left _ _ s).aedisjoint
theorem aedisjoint_compl_right : AEDisjoint μ s sᶜ :=
(@disjoint_compl_right _ _ s).aedisjoint
end MeasureTheory
|
MeasureTheory\Measure\AEMeasurable.lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.Trim
import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. This property, called `AEMeasurable f μ`, is defined in the file `MeasureSpaceDef`.
We discuss several of its properties that are analogous to properties of measurable functions.
-/
open MeasureTheory MeasureTheory.Measure Filter Set Function ENNReal
variable {ι α β γ δ R : Type*} {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ] {f g : α → β} {μ ν : Measure α}
section
@[nontriviality, measurability]
theorem Subsingleton.aemeasurable [Subsingleton α] : AEMeasurable f μ :=
Subsingleton.measurable.aemeasurable
@[nontriviality, measurability]
theorem aemeasurable_of_subsingleton_codomain [Subsingleton β] : AEMeasurable f μ :=
(measurable_of_subsingleton_codomain f).aemeasurable
@[simp, measurability]
theorem aemeasurable_zero_measure : AEMeasurable f (0 : Measure α) := by
nontriviality α; inhabit α
exact ⟨fun _ => f default, measurable_const, rfl⟩
@[fun_prop]
theorem aemeasurable_id'' (μ : Measure α) {m : MeasurableSpace α} (hm : m ≤ m0) :
@AEMeasurable α α m m0 id μ :=
@Measurable.aemeasurable α α m0 m id μ (measurable_id'' hm)
lemma aemeasurable_of_map_neZero {mβ : MeasurableSpace β} {μ : Measure α}
{f : α → β} (h : NeZero (μ.map f)) :
AEMeasurable f μ := by
by_contra h'
simp [h'] at h
namespace AEMeasurable
lemma mono_ac (hf : AEMeasurable f ν) (hμν : μ ≪ ν) : AEMeasurable f μ :=
⟨hf.mk f, hf.measurable_mk, hμν.ae_le hf.ae_eq_mk⟩
theorem mono_measure (h : AEMeasurable f μ) (h' : ν ≤ μ) : AEMeasurable f ν :=
mono_ac h h'.absolutelyContinuous
theorem mono_set {s t} (h : s ⊆ t) (ht : AEMeasurable f (μ.restrict t)) :
AEMeasurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
@[fun_prop]
protected theorem mono' (h : AEMeasurable f μ) (h' : ν ≪ μ) : AEMeasurable f ν :=
⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩
theorem ae_mem_imp_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
theorem ae_inf_principal_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) : f =ᶠ[ae μ ⊓ 𝓟 s] h.mk f :=
le_ae_restrict h.ae_eq_mk
@[measurability]
theorem sum_measure [Countable ι] {μ : ι → Measure α} (h : ∀ i, AEMeasurable f (μ i)) :
AEMeasurable f (sum μ) := by
classical
nontriviality β
inhabit β
set s : ι → Set α := fun i => toMeasurable (μ i) { x | f x ≠ (h i).mk f x }
have hsμ : ∀ i, μ i (s i) = 0 := by
intro i
rw [measure_toMeasurable]
exact (h i).ae_eq_mk
have hsm : MeasurableSet (⋂ i, s i) :=
MeasurableSet.iInter fun i => measurableSet_toMeasurable _ _
have hs : ∀ i x, x ∉ s i → f x = (h i).mk f x := by
intro i x hx
contrapose! hx
exact subset_toMeasurable _ _ hx
set g : α → β := (⋂ i, s i).piecewise (const α default) f
refine ⟨g, measurable_of_restrict_of_restrict_compl hsm ?_ ?_, ae_sum_iff.mpr fun i => ?_⟩
· rw [restrict_piecewise]
simp only [s, Set.restrict, const]
exact measurable_const
· rw [restrict_piecewise_compl, compl_iInter]
intro t ht
refine ⟨⋃ i, (h i).mk f ⁻¹' t ∩ (s i)ᶜ, MeasurableSet.iUnion fun i ↦
(measurable_mk _ ht).inter (measurableSet_toMeasurable _ _).compl, ?_⟩
ext ⟨x, hx⟩
simp only [mem_preimage, mem_iUnion, Subtype.coe_mk, Set.restrict, mem_inter_iff,
mem_compl_iff] at hx ⊢
constructor
· rintro ⟨i, hxt, hxs⟩
rwa [hs _ _ hxs]
· rcases hx with ⟨i, hi⟩
rw [hs _ _ hi]
exact fun h => ⟨i, h, hi⟩
· refine measure_mono_null (fun x (hx : f x ≠ g x) => ?_) (hsμ i)
contrapose! hx
refine (piecewise_eq_of_not_mem _ _ _ ?_).symm
exact fun h => hx (mem_iInter.1 h i)
@[simp]
theorem _root_.aemeasurable_sum_measure_iff [Countable ι] {μ : ι → Measure α} :
AEMeasurable f (sum μ) ↔ ∀ i, AEMeasurable f (μ i) :=
⟨fun h _ => h.mono_measure (le_sum _ _), sum_measure⟩
@[simp]
theorem _root_.aemeasurable_add_measure_iff :
AEMeasurable f (μ + ν) ↔ AEMeasurable f μ ∧ AEMeasurable f ν := by
rw [← sum_cond, aemeasurable_sum_measure_iff, Bool.forall_bool, and_comm]
rfl
@[measurability]
theorem add_measure {f : α → β} (hμ : AEMeasurable f μ) (hν : AEMeasurable f ν) :
AEMeasurable f (μ + ν) :=
aemeasurable_add_measure_iff.2 ⟨hμ, hν⟩
@[measurability]
protected theorem iUnion [Countable ι] {s : ι → Set α}
(h : ∀ i, AEMeasurable f (μ.restrict (s i))) : AEMeasurable f (μ.restrict (⋃ i, s i)) :=
(sum_measure h).mono_measure <| restrict_iUnion_le
@[simp]
theorem _root_.aemeasurable_iUnion_iff [Countable ι] {s : ι → Set α} :
AEMeasurable f (μ.restrict (⋃ i, s i)) ↔ ∀ i, AEMeasurable f (μ.restrict (s i)) :=
⟨fun h _ => h.mono_measure <| restrict_mono (subset_iUnion _ _) le_rfl, AEMeasurable.iUnion⟩
@[simp]
theorem _root_.aemeasurable_union_iff {s t : Set α} :
AEMeasurable f (μ.restrict (s ∪ t)) ↔
AEMeasurable f (μ.restrict s) ∧ AEMeasurable f (μ.restrict t) := by
simp only [union_eq_iUnion, aemeasurable_iUnion_iff, Bool.forall_bool, cond, and_comm]
@[measurability]
theorem smul_measure [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : AEMeasurable f μ) (c : R) : AEMeasurable f (c • μ) :=
⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
theorem comp_aemeasurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (g ∘ f) μ :=
⟨hg.mk g ∘ hf.mk f, hg.measurable_mk.comp hf.measurable_mk,
(ae_eq_comp hf hg.ae_eq_mk).trans (hf.ae_eq_mk.fun_comp (mk g hg))⟩
@[fun_prop]
theorem comp_aemeasurable' {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (fun x ↦ g (f x)) μ := comp_aemeasurable hg hf
theorem comp_measurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : Measurable f) : AEMeasurable (g ∘ f) μ :=
hg.comp_aemeasurable hf.aemeasurable
theorem comp_quasiMeasurePreserving {ν : Measure δ} {f : α → δ} {g : δ → β} (hg : AEMeasurable g ν)
(hf : QuasiMeasurePreserving f μ ν) : AEMeasurable (g ∘ f) μ :=
(hg.mono' hf.absolutelyContinuous).comp_measurable hf.measurable
theorem map_map_of_aemeasurable {g : β → γ} {f : α → β} (hg : AEMeasurable g (Measure.map f μ))
(hf : AEMeasurable f μ) : (μ.map f).map g = μ.map (g ∘ f) := by
ext1 s hs
rw [map_apply_of_aemeasurable hg hs, map_apply₀ hf (hg.nullMeasurable hs),
map_apply_of_aemeasurable (hg.comp_aemeasurable hf) hs, preimage_comp]
@[fun_prop, measurability]
theorem prod_mk {f : α → β} {g : α → γ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (fun x => (f x, g x)) μ :=
⟨fun a => (hf.mk f a, hg.mk g a), hf.measurable_mk.prod_mk hg.measurable_mk,
EventuallyEq.prod_mk hf.ae_eq_mk hg.ae_eq_mk⟩
theorem exists_ae_eq_range_subset (H : AEMeasurable f μ) {t : Set β} (ht : ∀ᵐ x ∂μ, f x ∈ t)
(h₀ : t.Nonempty) : ∃ g, Measurable g ∧ range g ⊆ t ∧ f =ᵐ[μ] g := by
classical
let s : Set α := toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ
let g : α → β := piecewise s (fun _ => h₀.some) (H.mk f)
refine ⟨g, ?_, ?_, ?_⟩
· exact Measurable.piecewise (measurableSet_toMeasurable _ _) measurable_const H.measurable_mk
· rintro _ ⟨x, rfl⟩
by_cases hx : x ∈ s
· simpa [g, hx] using h₀.some_mem
· simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp (config := { contextual := true }) only [hx, mem_compl_iff, mem_setOf_eq, not_and,
not_false_iff, imp_true_iff]
· have A : μ (toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ) = 0 := by
rw [measure_toMeasurable, ← compl_mem_ae_iff, compl_compl]
exact H.ae_eq_mk.and ht
filter_upwards [compl_mem_ae_iff.2 A] with x hx
rw [mem_compl_iff] at hx
simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp only [hx, mem_compl_iff, mem_setOf_eq, false_and_iff, not_false_iff]
theorem exists_measurable_nonneg {β} [Preorder β] [Zero β] {mβ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (f_nn : ∀ᵐ t ∂μ, 0 ≤ f t) : ∃ g, Measurable g ∧ 0 ≤ g ∧ f =ᵐ[μ] g := by
obtain ⟨G, hG_meas, hG_mem, hG_ae_eq⟩ := hf.exists_ae_eq_range_subset f_nn ⟨0, le_rfl⟩
exact ⟨G, hG_meas, fun x => hG_mem (mem_range_self x), hG_ae_eq⟩
theorem subtype_mk (h : AEMeasurable f μ) {s : Set β} {hfs : ∀ x, f x ∈ s} :
AEMeasurable (codRestrict f s hfs) μ := by
nontriviality α; inhabit α
obtain ⟨g, g_meas, hg, fg⟩ : ∃ g : α → β, Measurable g ∧ range g ⊆ s ∧ f =ᵐ[μ] g :=
h.exists_ae_eq_range_subset (eventually_of_forall hfs) ⟨_, hfs default⟩
refine ⟨codRestrict g s fun x => hg (mem_range_self _), Measurable.subtype_mk g_meas, ?_⟩
filter_upwards [fg] with x hx
simpa [Subtype.ext_iff]
end AEMeasurable
theorem aemeasurable_const' (h : ∀ᵐ (x) (y) ∂μ, f x = f y) : AEMeasurable f μ := by
rcases eq_or_ne μ 0 with (rfl | hμ)
· exact aemeasurable_zero_measure
· haveI := ae_neBot.2 hμ
rcases h.exists with ⟨x, hx⟩
exact ⟨const α (f x), measurable_const, EventuallyEq.symm hx⟩
theorem aemeasurable_uIoc_iff [LinearOrder α] {f : α → β} {a b : α} :
(AEMeasurable f <| μ.restrict <| Ι a b) ↔
(AEMeasurable f <| μ.restrict <| Ioc a b) ∧ (AEMeasurable f <| μ.restrict <| Ioc b a) := by
rw [uIoc_eq_union, aemeasurable_union_iff]
theorem aemeasurable_iff_measurable [μ.IsComplete] : AEMeasurable f μ ↔ Measurable f :=
⟨fun h => h.nullMeasurable.measurable_of_complete, fun h => h.aemeasurable⟩
theorem MeasurableEmbedding.aemeasurable_map_iff {g : β → γ} (hf : MeasurableEmbedding f) :
AEMeasurable g (μ.map f) ↔ AEMeasurable (g ∘ f) μ := by
refine ⟨fun H => H.comp_measurable hf.measurable, ?_⟩
rintro ⟨g₁, hgm₁, heq⟩
rcases hf.exists_measurable_extend hgm₁ fun x => ⟨g x⟩ with ⟨g₂, hgm₂, rfl⟩
exact ⟨g₂, hgm₂, hf.ae_map_iff.2 heq⟩
theorem MeasurableEmbedding.aemeasurable_comp_iff {g : β → γ} (hg : MeasurableEmbedding g)
{μ : Measure α} : AEMeasurable (g ∘ f) μ ↔ AEMeasurable f μ := by
refine ⟨fun H => ?_, hg.measurable.comp_aemeasurable⟩
suffices AEMeasurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) μ by
rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this
exact hg.measurable_rangeSplitting.comp_aemeasurable H.subtype_mk
theorem aemeasurable_restrict_iff_comap_subtype {s : Set α} (hs : MeasurableSet s) {μ : Measure α}
{f : α → β} : AEMeasurable f (μ.restrict s) ↔ AEMeasurable (f ∘ (↑) : s → β) (comap (↑) μ) := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).aemeasurable_map_iff]
@[to_additive] -- @[to_additive (attr := simp)] -- Porting note (#10618): simp can prove this
theorem aemeasurable_one [One β] : AEMeasurable (fun _ : α => (1 : β)) μ :=
measurable_one.aemeasurable
@[simp]
theorem aemeasurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :
AEMeasurable f (c • μ) ↔ AEMeasurable f μ :=
⟨fun h => ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩, fun h =>
⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩
theorem aemeasurable_of_aemeasurable_trim {α} {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) {f : α → β} (hf : AEMeasurable f (μ.trim hm)) : AEMeasurable f μ :=
⟨hf.mk f, Measurable.mono hf.measurable_mk hm le_rfl, ae_eq_of_ae_eq_trim hf.ae_eq_mk⟩
theorem aemeasurable_restrict_of_measurable_subtype {s : Set α} (hs : MeasurableSet s)
(hf : Measurable fun x : s => f x) : AEMeasurable f (μ.restrict s) :=
(aemeasurable_restrict_iff_comap_subtype hs).2 hf.aemeasurable
theorem aemeasurable_map_equiv_iff (e : α ≃ᵐ β) {f : β → γ} :
AEMeasurable f (μ.map e) ↔ AEMeasurable (f ∘ e) μ :=
e.measurableEmbedding.aemeasurable_map_iff
end
theorem AEMeasurable.restrict (hfm : AEMeasurable f μ) {s} : AEMeasurable f (μ.restrict s) :=
⟨AEMeasurable.mk f hfm, hfm.measurable_mk, ae_restrict_of_ae hfm.ae_eq_mk⟩
theorem aemeasurable_Ioi_of_forall_Ioc {β} {mβ : MeasurableSpace β} [LinearOrder α]
[(atTop : Filter α).IsCountablyGenerated] {x : α} {g : α → β}
(g_meas : ∀ t > x, AEMeasurable g (μ.restrict (Ioc x t))) :
AEMeasurable g (μ.restrict (Ioi x)) := by
haveI : Nonempty α := ⟨x⟩
obtain ⟨u, hu_tendsto⟩ := exists_seq_tendsto (atTop : Filter α)
have Ioi_eq_iUnion : Ioi x = ⋃ n : ℕ, Ioc x (u n) := by
rw [iUnion_Ioc_eq_Ioi_self_iff.mpr _]
exact fun y _ => (hu_tendsto.eventually (eventually_ge_atTop y)).exists
rw [Ioi_eq_iUnion, aemeasurable_iUnion_iff]
intro n
cases' lt_or_le x (u n) with h h
· exact g_meas (u n) h
· rw [Ioc_eq_empty (not_lt.mpr h), Measure.restrict_empty]
exact aemeasurable_zero_measure
section Zero
variable [Zero β]
theorem aemeasurable_indicator_iff {s} (hs : MeasurableSet s) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
constructor
· intro h
exact (h.mono_measure Measure.restrict_le_self).congr (indicator_ae_eq_restrict hs)
· intro h
refine ⟨indicator s (h.mk f), h.measurable_mk.indicator hs, ?_⟩
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans <| (indicator_ae_eq_restrict hs).symm)
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm
exact ae_of_ae_restrict_of_ae_restrict_compl _ A B
theorem aemeasurable_indicator_iff₀ {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
rcases hs with ⟨t, ht, hst⟩
rw [← aemeasurable_congr (indicator_ae_eq_of_ae_eq_set hst.symm), aemeasurable_indicator_iff ht,
restrict_congr_set hst]
/-- A characterization of the a.e.-measurability of the indicator function which takes a constant
value `b` on a set `A` and `0` elsewhere. -/
lemma aemeasurable_indicator_const_iff {s} [MeasurableSingletonClass β] (b : β) [NeZero b] :
AEMeasurable (s.indicator (fun _ ↦ b)) μ ↔ NullMeasurableSet s μ := by
classical
constructor <;> intro h
· convert h.nullMeasurable (MeasurableSet.singleton (0 : β)).compl
rw [indicator_const_preimage_eq_union s {0}ᶜ b]
simp [NeZero.ne b]
· exact (aemeasurable_indicator_iff₀ h).mpr aemeasurable_const
@[measurability]
theorem AEMeasurable.indicator (hfm : AEMeasurable f μ) {s} (hs : MeasurableSet s) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff hs).mpr hfm.restrict
theorem AEMeasurable.indicator₀ (hfm : AEMeasurable f μ) {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff₀ hs).mpr hfm.restrict
end Zero
theorem MeasureTheory.Measure.restrict_map_of_aemeasurable {f : α → δ} (hf : AEMeasurable f μ)
{s : Set δ} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
calc
(μ.map f).restrict s = (μ.map (hf.mk f)).restrict s := by
congr 1
apply Measure.map_congr hf.ae_eq_mk
_ = (μ.restrict <| hf.mk f ⁻¹' s).map (hf.mk f) := Measure.restrict_map hf.measurable_mk hs
_ = (μ.restrict <| hf.mk f ⁻¹' s).map f :=
(Measure.map_congr (ae_restrict_of_ae hf.ae_eq_mk.symm))
_ = (μ.restrict <| f ⁻¹' s).map f := by
apply congr_arg
ext1 t ht
simp only [ht, Measure.restrict_apply]
apply measure_congr
apply (EventuallyEq.refl _ _).inter (hf.ae_eq_mk.symm.preimage s)
theorem MeasureTheory.Measure.map_mono_of_aemeasurable {f : α → δ} (h : μ ≤ ν)
(hf : AEMeasurable f ν) : μ.map f ≤ ν.map f :=
le_iff.2 fun s hs ↦ by simpa [hf, hs, hf.mono_measure h] using h (f ⁻¹' s)
/-- If the `σ`-algebra of the codomain of a null measurable function is countably generated,
then the function is a.e.-measurable. -/
lemma MeasureTheory.NullMeasurable.aemeasurable {f : α → β}
[hc : MeasurableSpace.CountablyGenerated β] (h : NullMeasurable f μ) : AEMeasurable f μ := by
classical
nontriviality β; inhabit β
rcases hc.1 with ⟨S, hSc, rfl⟩
choose! T hTf hTm hTeq using fun s hs ↦ (h <| .basic s hs).exists_measurable_subset_ae_eq
choose! U hUf hUm hUeq using fun s hs ↦ (h <| .basic s hs).exists_measurable_superset_ae_eq
set v := ⋃ s ∈ S, U s \ T s
have hvm : MeasurableSet v := .biUnion hSc fun s hs ↦ (hUm s hs).diff (hTm s hs)
have hvμ : μ v = 0 := (measure_biUnion_null_iff hSc).2 fun s hs ↦ ae_le_set.1 <|
((hUeq s hs).trans (hTeq s hs).symm).le
refine ⟨v.piecewise (fun _ ↦ default) f, ?_, measure_mono_null (fun x ↦
not_imp_comm.2 fun hxv ↦ (piecewise_eq_of_not_mem _ _ _ hxv).symm) hvμ⟩
refine measurable_of_restrict_of_restrict_compl hvm ?_ ?_
· rw [restrict_piecewise]
apply measurable_const
· rw [restrict_piecewise_compl, restrict_eq]
refine measurable_generateFrom fun s hs ↦ .of_subtype_image ?_
rw [preimage_comp, Subtype.image_preimage_coe]
convert (hTm s hs).diff hvm using 1
rw [inter_comm]
refine Set.ext fun x ↦ and_congr_left fun hxv ↦ ⟨fun hx ↦ ?_, fun hx ↦ hTf s hs hx⟩
exact by_contra fun hx' ↦ hxv <| mem_biUnion hs ⟨hUf s hs hx, hx'⟩
/-- Let `f : α → β` be a null measurable function
such that a.e. all values of `f` belong to a set `t`
such that the restriction of the `σ`-algebra in the codomain to `t` is countably generated,
then `f` is a.e.-measurable. -/
lemma MeasureTheory.NullMeasurable.aemeasurable_of_aerange {f : α → β} {t : Set β}
[MeasurableSpace.CountablyGenerated t] (h : NullMeasurable f μ) (hft : ∀ᵐ x ∂μ, f x ∈ t) :
AEMeasurable f μ := by
rcases eq_empty_or_nonempty t with rfl | hne
· obtain rfl : μ = 0 := by simpa using hft
apply aemeasurable_zero_measure
· rw [← μ.ae_completion] at hft
obtain ⟨f', hf'm, hf't, hff'⟩ :
∃ f' : α → β, NullMeasurable f' μ ∧ range f' ⊆ t ∧ f =ᵐ[μ] f' :=
h.measurable'.aemeasurable.exists_ae_eq_range_subset hft hne
rw [range_subset_iff] at hf't
lift f' to α → t using hf't
replace hf'm : NullMeasurable f' μ := hf'm.measurable'.subtype_mk
exact (measurable_subtype_coe.comp_aemeasurable hf'm.aemeasurable).congr hff'.symm
namespace MeasureTheory
namespace Measure
lemma map_sum {ι : Type*} {m : ι → Measure α} {f : α → β} (hf : AEMeasurable f (Measure.sum m)) :
Measure.map f (Measure.sum m) = Measure.sum (fun i ↦ Measure.map f (m i)) := by
ext s hs
rw [map_apply_of_aemeasurable hf hs, sum_apply₀ _ (hf.nullMeasurable hs), sum_apply _ hs]
have M i : AEMeasurable f (m i) := hf.mono_measure (le_sum m i)
simp_rw [map_apply_of_aemeasurable (M _) hs]
instance (μ : Measure α) (f : α → β) [SFinite μ] : SFinite (μ.map f) := by
by_cases H : AEMeasurable f μ
· rw [← sum_sFiniteSeq μ] at H ⊢
rw [map_sum H]
infer_instance
· rw [map_of_not_aemeasurable H]
infer_instance
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Complex.lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.VectorMeasure
/-!
# Complex measure
This file proves some elementary results about complex measures. In particular, we prove that
a complex measure is always in the form `s + it` where `s` and `t` are signed measures.
The complex measure is defined to be vector measure over `ℂ`, this definition can be found
in `Mathlib/MeasureTheory/Measure/VectorMeasure.lean` and is known as
`MeasureTheory.ComplexMeasure`.
## Main definitions
* `MeasureTheory.ComplexMeasure.re`: obtains a signed measure `s` from a complex measure `c`
such that `s i = (c i).re` for all measurable sets `i`.
* `MeasureTheory.ComplexMeasure.im`: obtains a signed measure `s` from a complex measure `c`
such that `s i = (c i).im` for all measurable sets `i`.
* `MeasureTheory.SignedMeasure.toComplexMeasure`: given two signed measures `s` and `t`,
`s.to_complex_measure t` provides a complex measure of the form `s + it`.
* `MeasureTheory.ComplexMeasure.equivSignedMeasure`: is the equivalence between the complex
measures and the type of the product of the signed measures with itself.
## Tags
Complex measure
-/
noncomputable section
open scoped MeasureTheory ENNReal NNReal
variable {α β : Type*} {m : MeasurableSpace α}
namespace MeasureTheory
open VectorMeasure
namespace ComplexMeasure
/-- The real part of a complex measure is a signed measure. -/
@[simps! apply]
def re : ComplexMeasure α →ₗ[ℝ] SignedMeasure α :=
mapRangeₗ Complex.reCLM Complex.continuous_re
/-- The imaginary part of a complex measure is a signed measure. -/
@[simps! apply]
def im : ComplexMeasure α →ₗ[ℝ] SignedMeasure α :=
mapRangeₗ Complex.imCLM Complex.continuous_im
/-- Given `s` and `t` signed measures, `s + it` is a complex measure-/
@[simps!]
def _root_.MeasureTheory.SignedMeasure.toComplexMeasure (s t : SignedMeasure α) :
ComplexMeasure α where
measureOf' i := ⟨s i, t i⟩
empty' := by dsimp only; rw [s.empty, t.empty]; rfl
not_measurable' i hi := by dsimp only; rw [s.not_measurable hi, t.not_measurable hi]; rfl
m_iUnion' f hf hfdisj := (Complex.hasSum_iff _ _).2 ⟨s.m_iUnion hf hfdisj, t.m_iUnion hf hfdisj⟩
theorem _root_.MeasureTheory.SignedMeasure.toComplexMeasure_apply
{s t : SignedMeasure α} {i : Set α} : s.toComplexMeasure t i = ⟨s i, t i⟩ := rfl
theorem toComplexMeasure_to_signedMeasure (c : ComplexMeasure α) :
SignedMeasure.toComplexMeasure (ComplexMeasure.re c) (ComplexMeasure.im c) = c := rfl
theorem _root_.MeasureTheory.SignedMeasure.re_toComplexMeasure (s t : SignedMeasure α) :
ComplexMeasure.re (SignedMeasure.toComplexMeasure s t) = s := rfl
theorem _root_.MeasureTheory.SignedMeasure.im_toComplexMeasure (s t : SignedMeasure α) :
ComplexMeasure.im (SignedMeasure.toComplexMeasure s t) = t := rfl
/-- The complex measures form an equivalence to the type of pairs of signed measures. -/
@[simps]
def equivSignedMeasure : ComplexMeasure α ≃ SignedMeasure α × SignedMeasure α where
toFun c := ⟨ComplexMeasure.re c, ComplexMeasure.im c⟩
invFun := fun ⟨s, t⟩ => s.toComplexMeasure t
left_inv c := c.toComplexMeasure_to_signedMeasure
right_inv := fun ⟨s, t⟩ => Prod.mk.inj_iff.2 ⟨s.re_toComplexMeasure t, s.im_toComplexMeasure t⟩
section
variable {R : Type*} [Semiring R] [Module R ℝ]
variable [ContinuousConstSMul R ℝ] [ContinuousConstSMul R ℂ]
/-- The complex measures form a linear isomorphism to the type of pairs of signed measures. -/
@[simps]
def equivSignedMeasureₗ : ComplexMeasure α ≃ₗ[R] SignedMeasure α × SignedMeasure α :=
{ equivSignedMeasure with
map_add' := fun c d => by rfl
map_smul' := by
intro r c
dsimp
ext
· simp [Complex.smul_re]
· simp [Complex.smul_im] }
end
theorem absolutelyContinuous_ennreal_iff (c : ComplexMeasure α) (μ : VectorMeasure α ℝ≥0∞) :
c ≪ᵥ μ ↔ ComplexMeasure.re c ≪ᵥ μ ∧ ComplexMeasure.im c ≪ᵥ μ := by
constructor <;> intro h
· constructor <;> · intro i hi; simp [h hi]
· intro i hi
rw [← Complex.re_add_im (c i), (_ : (c i).re = 0), (_ : (c i).im = 0)]
exacts [by simp, h.2 hi, h.1 hi]
end ComplexMeasure
end MeasureTheory
|
MeasureTheory\Measure\Content.lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.Topology.Sets.Compacts
/-!
# Contents
In this file we work with *contents*. A content `λ` is a function from a certain class of subsets
(such as the compact subsets) to `ℝ≥0` that is
* additive: If `K₁` and `K₂` are disjoint sets in the domain of `λ`,
then `λ(K₁ ∪ K₂) = λ(K₁) + λ(K₂)`;
* subadditive: If `K₁` and `K₂` are in the domain of `λ`, then `λ(K₁ ∪ K₂) ≤ λ(K₁) + λ(K₂)`;
* monotone: If `K₁ ⊆ K₂` are in the domain of `λ`, then `λ(K₁) ≤ λ(K₂)`.
We show that:
* Given a content `λ` on compact sets, let us define a function `λ*` on open sets, by letting
`λ* U` be the supremum of `λ K` for `K` included in `U`. This is a countably subadditive map that
vanishes at `∅`. In Halmos (1950) this is called the *inner content* `λ*` of `λ`, and formalized
as `innerContent`.
* Given an inner content, we define an outer measure `μ*`, by letting `μ* E` be the infimum of
`λ* U` over the open sets `U` containing `E`. This is indeed an outer measure. It is formalized
as `outerMeasure`.
* Restricting this outer measure to Borel sets gives a regular measure `μ`.
We define bundled contents as `Content`.
In this file we only work on contents on compact sets, and inner contents on open sets, and both
contents and inner contents map into the extended nonnegative reals. However, in other applications
other choices can be made, and it is not a priori clear what the best interface should be.
## Main definitions
For `μ : Content G`, we define
* `μ.innerContent` : the inner content associated to `μ`.
* `μ.outerMeasure` : the outer measure associated to `μ`.
* `μ.measure` : the Borel measure associated to `μ`.
These definitions are given for spaces which are R₁.
The resulting measure `μ.measure` is always outer regular by design.
When the space is locally compact, `μ.measure` is also regular.
## References
* Paul Halmos (1950), Measure Theory, §53
* <https://en.wikipedia.org/wiki/Content_(measure_theory)>
-/
universe u v w
noncomputable section
open Set TopologicalSpace
open NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {G : Type w} [TopologicalSpace G]
/-- A content is an additive function on compact sets taking values in `ℝ≥0`. It is a device
from which one can define a measure. -/
structure Content (G : Type w) [TopologicalSpace G] where
toFun : Compacts G → ℝ≥0
mono' : ∀ K₁ K₂ : Compacts G, (K₁ : Set G) ⊆ K₂ → toFun K₁ ≤ toFun K₂
sup_disjoint' :
∀ K₁ K₂ : Compacts G, Disjoint (K₁ : Set G) K₂ → IsClosed (K₁ : Set G) → IsClosed (K₂ : Set G)
→ toFun (K₁ ⊔ K₂) = toFun K₁ + toFun K₂
sup_le' : ∀ K₁ K₂ : Compacts G, toFun (K₁ ⊔ K₂) ≤ toFun K₁ + toFun K₂
instance : Inhabited (Content G) :=
⟨{ toFun := fun _ => 0
mono' := by simp
sup_disjoint' := by simp
sup_le' := by simp }⟩
/-- Although the `toFun` field of a content takes values in `ℝ≥0`, we register a coercion to
functions taking values in `ℝ≥0∞` as most constructions below rely on taking iSups and iInfs, which
is more convenient in a complete lattice, and aim at constructing a measure. -/
instance : CoeFun (Content G) fun _ => Compacts G → ℝ≥0∞ :=
⟨fun μ s => μ.toFun s⟩
namespace Content
variable (μ : Content G)
theorem apply_eq_coe_toFun (K : Compacts G) : μ K = μ.toFun K :=
rfl
theorem mono (K₁ K₂ : Compacts G) (h : (K₁ : Set G) ⊆ K₂) : μ K₁ ≤ μ K₂ := by
simp [apply_eq_coe_toFun, μ.mono' _ _ h]
theorem sup_disjoint (K₁ K₂ : Compacts G) (h : Disjoint (K₁ : Set G) K₂)
(h₁ : IsClosed (K₁ : Set G)) (h₂ : IsClosed (K₂ : Set G)) :
μ (K₁ ⊔ K₂) = μ K₁ + μ K₂ := by
simp [apply_eq_coe_toFun, μ.sup_disjoint' _ _ h]
theorem sup_le (K₁ K₂ : Compacts G) : μ (K₁ ⊔ K₂) ≤ μ K₁ + μ K₂ := by
simp only [apply_eq_coe_toFun]
norm_cast
exact μ.sup_le' _ _
theorem lt_top (K : Compacts G) : μ K < ∞ :=
ENNReal.coe_lt_top
theorem empty : μ ⊥ = 0 := by
have := μ.sup_disjoint' ⊥ ⊥
simpa [apply_eq_coe_toFun] using this
/-- Constructing the inner content of a content. From a content defined on the compact sets, we
obtain a function defined on all open sets, by taking the supremum of the content of all compact
subsets. -/
def innerContent (U : Opens G) : ℝ≥0∞ :=
⨆ (K : Compacts G) (_ : (K : Set G) ⊆ U), μ K
theorem le_innerContent (K : Compacts G) (U : Opens G) (h2 : (K : Set G) ⊆ U) :
μ K ≤ μ.innerContent U :=
le_iSup_of_le K <| le_iSup (fun _ ↦ (μ.toFun K : ℝ≥0∞)) h2
theorem innerContent_le (U : Opens G) (K : Compacts G) (h2 : (U : Set G) ⊆ K) :
μ.innerContent U ≤ μ K :=
iSup₂_le fun _ hK' => μ.mono _ _ (Subset.trans hK' h2)
theorem innerContent_of_isCompact {K : Set G} (h1K : IsCompact K) (h2K : IsOpen K) :
μ.innerContent ⟨K, h2K⟩ = μ ⟨K, h1K⟩ :=
le_antisymm (iSup₂_le fun _ hK' => μ.mono _ ⟨K, h1K⟩ hK') (μ.le_innerContent _ _ Subset.rfl)
theorem innerContent_bot : μ.innerContent ⊥ = 0 := by
refine le_antisymm ?_ (zero_le _)
rw [← μ.empty]
refine iSup₂_le fun K hK => ?_
have : K = ⊥ := by
ext1
rw [subset_empty_iff.mp hK, Compacts.coe_bot]
rw [this]
/-- This is "unbundled", because that is required for the API of `inducedOuterMeasure`. -/
theorem innerContent_mono ⦃U V : Set G⦄ (hU : IsOpen U) (hV : IsOpen V) (h2 : U ⊆ V) :
μ.innerContent ⟨U, hU⟩ ≤ μ.innerContent ⟨V, hV⟩ :=
biSup_mono fun _ hK => hK.trans h2
theorem innerContent_exists_compact {U : Opens G} (hU : μ.innerContent U ≠ ∞) {ε : ℝ≥0}
(hε : ε ≠ 0) : ∃ K : Compacts G, (K : Set G) ⊆ U ∧ μ.innerContent U ≤ μ K + ε := by
have h'ε := ENNReal.coe_ne_zero.2 hε
rcases le_or_lt (μ.innerContent U) ε with h | h
· exact ⟨⊥, empty_subset _, le_add_left h⟩
have h₂ := ENNReal.sub_lt_self hU h.ne_bot h'ε
conv at h₂ => rhs; rw [innerContent]
simp only [lt_iSup_iff] at h₂
rcases h₂ with ⟨U, h1U, h2U⟩; refine ⟨U, h1U, ?_⟩
rw [← tsub_le_iff_right]; exact le_of_lt h2U
/-- The inner content of a supremum of opens is at most the sum of the individual inner contents. -/
theorem innerContent_iSup_nat [R1Space G] (U : ℕ → Opens G) :
μ.innerContent (⨆ i : ℕ, U i) ≤ ∑' i : ℕ, μ.innerContent (U i) := by
have h3 : ∀ (t : Finset ℕ) (K : ℕ → Compacts G), μ (t.sup K) ≤ t.sum fun i => μ (K i) := by
intro t K
refine Finset.induction_on t ?_ ?_
· simp only [μ.empty, nonpos_iff_eq_zero, Finset.sum_empty, Finset.sup_empty]
· intro n s hn ih
rw [Finset.sup_insert, Finset.sum_insert hn]
exact le_trans (μ.sup_le _ _) (add_le_add_left ih _)
refine iSup₂_le fun K hK => ?_
obtain ⟨t, ht⟩ :=
K.isCompact.elim_finite_subcover _ (fun i => (U i).isOpen) (by rwa [← Opens.coe_iSup])
rcases K.isCompact.finite_compact_cover t (SetLike.coe ∘ U) (fun i _ => (U i).isOpen) ht with
⟨K', h1K', h2K', h3K'⟩
let L : ℕ → Compacts G := fun n => ⟨K' n, h1K' n⟩
convert le_trans (h3 t L) _
· ext1
rw [Compacts.coe_finset_sup, Finset.sup_eq_iSup]
exact h3K'
refine le_trans (Finset.sum_le_sum ?_) (ENNReal.sum_le_tsum t)
intro i _
refine le_trans ?_ (le_iSup _ (L i))
refine le_trans ?_ (le_iSup _ (h2K' i))
rfl
/-- The inner content of a union of sets is at most the sum of the individual inner contents.
This is the "unbundled" version of `innerContent_iSup_nat`.
It is required for the API of `inducedOuterMeasure`. -/
theorem innerContent_iUnion_nat [R1Space G] ⦃U : ℕ → Set G⦄
(hU : ∀ i : ℕ, IsOpen (U i)) :
μ.innerContent ⟨⋃ i : ℕ, U i, isOpen_iUnion hU⟩ ≤ ∑' i : ℕ, μ.innerContent ⟨U i, hU i⟩ := by
have := μ.innerContent_iSup_nat fun i => ⟨U i, hU i⟩
rwa [Opens.iSup_def] at this
theorem innerContent_comap (f : G ≃ₜ G) (h : ∀ ⦃K : Compacts G⦄, μ (K.map f f.continuous) = μ K)
(U : Opens G) : μ.innerContent (Opens.comap f.toContinuousMap U) = μ.innerContent U := by
refine (Compacts.equiv f).surjective.iSup_congr _ fun K => iSup_congr_Prop image_subset_iff ?_
intro hK
simp only [Equiv.coe_fn_mk, Subtype.mk_eq_mk, Compacts.equiv]
apply h
@[to_additive]
theorem is_mul_left_invariant_innerContent [Group G] [TopologicalGroup G]
(h : ∀ (g : G) {K : Compacts G}, μ (K.map _ <| continuous_mul_left g) = μ K) (g : G)
(U : Opens G) :
μ.innerContent (Opens.comap (Homeomorph.mulLeft g).toContinuousMap U) = μ.innerContent U := by
convert μ.innerContent_comap (Homeomorph.mulLeft g) (fun K => h g) U
@[to_additive]
theorem innerContent_pos_of_is_mul_left_invariant [Group G] [TopologicalGroup G]
(h3 : ∀ (g : G) {K : Compacts G}, μ (K.map _ <| continuous_mul_left g) = μ K) (K : Compacts G)
(hK : μ K ≠ 0) (U : Opens G) (hU : (U : Set G).Nonempty) : 0 < μ.innerContent U := by
have : (interior (U : Set G)).Nonempty := by rwa [U.isOpen.interior_eq]
rcases compact_covered_by_mul_left_translates K.2 this with ⟨s, hs⟩
suffices μ K ≤ s.card * μ.innerContent U by
exact (ENNReal.mul_pos_iff.mp <| hK.bot_lt.trans_le this).2
have : (K : Set G) ⊆ ↑(⨆ g ∈ s, Opens.comap (Homeomorph.mulLeft g).toContinuousMap U) := by
simpa only [Opens.iSup_def, Opens.coe_comap, Subtype.coe_mk]
refine (μ.le_innerContent _ _ this).trans ?_
refine
(rel_iSup_sum μ.innerContent μ.innerContent_bot (· ≤ ·) μ.innerContent_iSup_nat _ _).trans ?_
simp only [μ.is_mul_left_invariant_innerContent h3, Finset.sum_const, nsmul_eq_mul, le_refl]
theorem innerContent_mono' ⦃U V : Set G⦄ (hU : IsOpen U) (hV : IsOpen V) (h2 : U ⊆ V) :
μ.innerContent ⟨U, hU⟩ ≤ μ.innerContent ⟨V, hV⟩ :=
biSup_mono fun _ hK => hK.trans h2
section OuterMeasure
/-- Extending a content on compact sets to an outer measure on all sets. -/
protected def outerMeasure : OuterMeasure G :=
inducedOuterMeasure (fun U hU => μ.innerContent ⟨U, hU⟩) isOpen_empty μ.innerContent_bot
variable [R1Space G]
theorem outerMeasure_opens (U : Opens G) : μ.outerMeasure U = μ.innerContent U :=
inducedOuterMeasure_eq' (fun _ => isOpen_iUnion) μ.innerContent_iUnion_nat μ.innerContent_mono U.2
theorem outerMeasure_of_isOpen (U : Set G) (hU : IsOpen U) :
μ.outerMeasure U = μ.innerContent ⟨U, hU⟩ :=
μ.outerMeasure_opens ⟨U, hU⟩
theorem outerMeasure_le (U : Opens G) (K : Compacts G) (hUK : (U : Set G) ⊆ K) :
μ.outerMeasure U ≤ μ K :=
(μ.outerMeasure_opens U).le.trans <| μ.innerContent_le U K hUK
theorem le_outerMeasure_compacts (K : Compacts G) : μ K ≤ μ.outerMeasure K := by
rw [Content.outerMeasure, inducedOuterMeasure_eq_iInf]
· exact le_iInf fun U => le_iInf fun hU => le_iInf <| μ.le_innerContent K ⟨U, hU⟩
· exact fun U hU => isOpen_iUnion hU
· exact μ.innerContent_iUnion_nat
· exact μ.innerContent_mono
theorem outerMeasure_eq_iInf (A : Set G) :
μ.outerMeasure A = ⨅ (U : Set G) (hU : IsOpen U) (_ : A ⊆ U), μ.innerContent ⟨U, hU⟩ :=
inducedOuterMeasure_eq_iInf _ μ.innerContent_iUnion_nat μ.innerContent_mono A
theorem outerMeasure_interior_compacts (K : Compacts G) : μ.outerMeasure (interior K) ≤ μ K :=
(μ.outerMeasure_opens <| Opens.interior K).le.trans <| μ.innerContent_le _ _ interior_subset
theorem outerMeasure_exists_compact {U : Opens G} (hU : μ.outerMeasure U ≠ ∞) {ε : ℝ≥0}
(hε : ε ≠ 0) : ∃ K : Compacts G, (K : Set G) ⊆ U ∧ μ.outerMeasure U ≤ μ.outerMeasure K + ε := by
rw [μ.outerMeasure_opens] at hU ⊢
rcases μ.innerContent_exists_compact hU hε with ⟨K, h1K, h2K⟩
exact ⟨K, h1K, le_trans h2K <| add_le_add_right (μ.le_outerMeasure_compacts K) _⟩
theorem outerMeasure_exists_open {A : Set G} (hA : μ.outerMeasure A ≠ ∞) {ε : ℝ≥0} (hε : ε ≠ 0) :
∃ U : Opens G, A ⊆ U ∧ μ.outerMeasure U ≤ μ.outerMeasure A + ε := by
rcases inducedOuterMeasure_exists_set _ μ.innerContent_iUnion_nat μ.innerContent_mono hA
(ENNReal.coe_ne_zero.2 hε) with
⟨U, hU, h2U, h3U⟩
exact ⟨⟨U, hU⟩, h2U, h3U⟩
theorem outerMeasure_preimage (f : G ≃ₜ G) (h : ∀ ⦃K : Compacts G⦄, μ (K.map f f.continuous) = μ K)
(A : Set G) : μ.outerMeasure (f ⁻¹' A) = μ.outerMeasure A := by
refine inducedOuterMeasure_preimage _ μ.innerContent_iUnion_nat μ.innerContent_mono _
(fun _ => f.isOpen_preimage) ?_
intro s hs
convert μ.innerContent_comap f h ⟨s, hs⟩
theorem outerMeasure_lt_top_of_isCompact [WeaklyLocallyCompactSpace G]
{K : Set G} (hK : IsCompact K) :
μ.outerMeasure K < ∞ := by
rcases exists_compact_superset hK with ⟨F, h1F, h2F⟩
calc
μ.outerMeasure K ≤ μ.outerMeasure (interior F) := measure_mono h2F
_ ≤ μ ⟨F, h1F⟩ := by
apply μ.outerMeasure_le ⟨interior F, isOpen_interior⟩ ⟨F, h1F⟩ interior_subset
_ < ⊤ := μ.lt_top _
@[to_additive]
theorem is_mul_left_invariant_outerMeasure [Group G] [TopologicalGroup G]
(h : ∀ (g : G) {K : Compacts G}, μ (K.map _ <| continuous_mul_left g) = μ K) (g : G)
(A : Set G) : μ.outerMeasure ((g * ·) ⁻¹' A) = μ.outerMeasure A := by
convert μ.outerMeasure_preimage (Homeomorph.mulLeft g) (fun K => h g) A
theorem outerMeasure_caratheodory (A : Set G) :
MeasurableSet[μ.outerMeasure.caratheodory] A ↔
∀ U : Opens G, μ.outerMeasure (U ∩ A) + μ.outerMeasure (U \ A) ≤ μ.outerMeasure U := by
rw [Opens.forall]
apply inducedOuterMeasure_caratheodory
· apply innerContent_iUnion_nat
· apply innerContent_mono'
@[to_additive]
theorem outerMeasure_pos_of_is_mul_left_invariant [Group G] [TopologicalGroup G]
(h3 : ∀ (g : G) {K : Compacts G}, μ (K.map _ <| continuous_mul_left g) = μ K) (K : Compacts G)
(hK : μ K ≠ 0) {U : Set G} (h1U : IsOpen U) (h2U : U.Nonempty) : 0 < μ.outerMeasure U := by
convert μ.innerContent_pos_of_is_mul_left_invariant h3 K hK ⟨U, h1U⟩ h2U
exact μ.outerMeasure_opens ⟨U, h1U⟩
variable [S : MeasurableSpace G] [BorelSpace G]
/-- For the outer measure coming from a content, all Borel sets are measurable. -/
theorem borel_le_caratheodory : S ≤ μ.outerMeasure.caratheodory := by
rw [@BorelSpace.measurable_eq G _ _]
refine MeasurableSpace.generateFrom_le ?_
intro U hU
rw [μ.outerMeasure_caratheodory]
intro U'
rw [μ.outerMeasure_of_isOpen ((U' : Set G) ∩ U) (U'.isOpen.inter hU)]
simp only [innerContent, iSup_subtype']
rw [Opens.coe_mk]
haveI : Nonempty { L : Compacts G // (L : Set G) ⊆ U' ∩ U } := ⟨⟨⊥, empty_subset _⟩⟩
rw [ENNReal.iSup_add]
refine iSup_le ?_
rintro ⟨L, hL⟩
let L' : Compacts G := ⟨closure L, L.isCompact.closure⟩
suffices μ L' + μ.outerMeasure (↑U' \ U) ≤ μ.outerMeasure U' by
have A : μ L ≤ μ L' := μ.mono _ _ subset_closure
exact (add_le_add_right A _).trans this
simp only [subset_inter_iff] at hL
have hL'U : (L' : Set G) ⊆ U := IsCompact.closure_subset_of_isOpen L.2 hU hL.2
have hL'U' : (L' : Set G) ⊆ (U' : Set G) := IsCompact.closure_subset_of_isOpen L.2 U'.2 hL.1
have : ↑U' \ U ⊆ U' \ L' := diff_subset_diff_right hL'U
refine le_trans (add_le_add_left (measure_mono this) _) ?_
rw [μ.outerMeasure_of_isOpen (↑U' \ L') (IsOpen.sdiff U'.2 isClosed_closure)]
simp only [innerContent, iSup_subtype']
rw [Opens.coe_mk]
haveI : Nonempty { M : Compacts G // (M : Set G) ⊆ ↑U' \ closure L } := ⟨⟨⊥, empty_subset _⟩⟩
rw [ENNReal.add_iSup]
refine iSup_le ?_
rintro ⟨M, hM⟩
let M' : Compacts G := ⟨closure M, M.isCompact.closure⟩
suffices μ L' + μ M' ≤ μ.outerMeasure U' by
have A : μ M ≤ μ M' := μ.mono _ _ subset_closure
exact (add_le_add_left A _).trans this
have hM' : (M' : Set G) ⊆ U' \ L' :=
IsCompact.closure_subset_of_isOpen M.2 (IsOpen.sdiff U'.2 isClosed_closure) hM
have : (↑(L' ⊔ M') : Set G) ⊆ U' := by
simp only [Compacts.coe_sup, union_subset_iff, hL'U', true_and]
exact hM'.trans diff_subset
rw [μ.outerMeasure_of_isOpen (↑U') U'.2]
refine le_trans (ge_of_eq ?_) (μ.le_innerContent _ _ this)
exact μ.sup_disjoint L' M' (subset_diff.1 hM').2.symm isClosed_closure isClosed_closure
/-- The measure induced by the outer measure coming from a content, on the Borel sigma-algebra. -/
protected def measure : Measure G :=
μ.outerMeasure.toMeasure μ.borel_le_caratheodory
theorem measure_apply {s : Set G} (hs : MeasurableSet s) : μ.measure s = μ.outerMeasure s :=
toMeasure_apply _ _ hs
instance outerRegular : μ.measure.OuterRegular := by
refine ⟨fun A hA r (hr : _ < _) ↦ ?_⟩
rw [μ.measure_apply hA, outerMeasure_eq_iInf] at hr
simp only [iInf_lt_iff] at hr
rcases hr with ⟨U, hUo, hAU, hr⟩
rw [← μ.outerMeasure_of_isOpen U hUo, ← μ.measure_apply hUo.measurableSet] at hr
exact ⟨U, hAU, hUo, hr⟩
/-- In a locally compact space, any measure constructed from a content is regular. -/
instance regular [WeaklyLocallyCompactSpace G] : μ.measure.Regular := by
have : IsFiniteMeasureOnCompacts μ.measure := by
refine ⟨fun K hK => ?_⟩
apply (measure_mono subset_closure).trans_lt _
rw [measure_apply _ isClosed_closure.measurableSet]
exact μ.outerMeasure_lt_top_of_isCompact hK.closure
refine ⟨fun U hU r hr => ?_⟩
rw [measure_apply _ hU.measurableSet, μ.outerMeasure_of_isOpen U hU] at hr
simp only [innerContent, lt_iSup_iff] at hr
rcases hr with ⟨K, hKU, hr⟩
refine ⟨K, hKU, K.2, hr.trans_le ?_⟩
exact (μ.le_outerMeasure_compacts K).trans (le_toMeasure_apply _ _ _)
end OuterMeasure
section RegularContents
/-- A content `μ` is called regular if for every compact set `K`,
`μ(K) = inf {μ(K') : K ⊂ int K' ⊂ K'}`. See Paul Halmos (1950), Measure Theory, §54-/
def ContentRegular :=
∀ ⦃K : TopologicalSpace.Compacts G⦄,
μ K = ⨅ (K' : TopologicalSpace.Compacts G) (_ : (K : Set G) ⊆ interior (K' : Set G)), μ K'
theorem contentRegular_exists_compact (H : ContentRegular μ) (K : TopologicalSpace.Compacts G)
{ε : NNReal} (hε : ε ≠ 0) :
∃ K' : TopologicalSpace.Compacts G, K.carrier ⊆ interior K'.carrier ∧ μ K' ≤ μ K + ε := by
by_contra hc
simp only [not_exists, not_and, not_le] at hc
have lower_bound_iInf : μ K + ε ≤
⨅ (K' : TopologicalSpace.Compacts G) (_ : (K : Set G) ⊆ interior (K' : Set G)), μ K' :=
le_iInf fun K' => le_iInf fun K'_hyp => le_of_lt (hc K' K'_hyp)
rw [← H] at lower_bound_iInf
exact (lt_self_iff_false (μ K)).mp (lt_of_le_of_lt' lower_bound_iInf
(ENNReal.lt_add_right (ne_top_of_lt (μ.lt_top K)) (ENNReal.coe_ne_zero.mpr hε)))
variable [MeasurableSpace G] [R1Space G] [BorelSpace G]
/-- If `μ` is a regular content, then the measure induced by `μ` will agree with `μ`
on compact sets. -/
theorem measure_eq_content_of_regular (H : MeasureTheory.Content.ContentRegular μ)
(K : TopologicalSpace.Compacts G) : μ.measure ↑K = μ K := by
refine le_antisymm ?_ ?_
· apply ENNReal.le_of_forall_pos_le_add
intro ε εpos _
obtain ⟨K', K'_hyp⟩ := contentRegular_exists_compact μ H K (ne_bot_of_gt εpos)
calc
μ.measure ↑K ≤ μ.measure (interior ↑K') := measure_mono K'_hyp.1
_ ≤ μ K' := by
rw [μ.measure_apply (IsOpen.measurableSet isOpen_interior)]
exact μ.outerMeasure_interior_compacts K'
_ ≤ μ K + ε := K'_hyp.right
· calc
μ K ≤ μ ⟨closure K, K.2.closure⟩ := μ.mono _ _ subset_closure
_ ≤ μ.measure (closure K) := by
rw [μ.measure_apply (isClosed_closure.measurableSet)]
exact μ.le_outerMeasure_compacts _
_ = μ.measure K := K.2.measure_closure _
end RegularContents
end Content
end MeasureTheory
|
MeasureTheory\Measure\Count.lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.MeasureTheory.Measure.Dirac
/-!
# Counting measure
In this file we define the counting measure `MeasurTheory.Measure.count`
as `MeasureTheory.Measure.sum MeasureTheory.Measure.dirac`
and prove basic properties of this measure.
-/
open Set
open scoped ENNReal
variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] {s : Set α}
noncomputable section
namespace MeasureTheory.Measure
/-- Counting measure on any measurable space. -/
def count : Measure α :=
sum dirac
theorem le_count_apply : ∑' _ : s, (1 : ℝ≥0∞) ≤ count s :=
calc
(∑' _ : s, 1 : ℝ≥0∞) = ∑' i, indicator s 1 i := tsum_subtype s 1
_ ≤ ∑' i, dirac i s := ENNReal.tsum_le_tsum fun _ => le_dirac_apply
_ ≤ count s := le_sum_apply _ _
theorem count_apply (hs : MeasurableSet s) : count s = ∑' i : s, 1 := by
simp only [count, sum_apply, hs, dirac_apply', ← tsum_subtype s (1 : α → ℝ≥0∞), Pi.one_apply]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem count_empty : count (∅ : Set α) = 0 := by rw [count_apply MeasurableSet.empty, tsum_empty]
@[simp]
theorem count_apply_finset' {s : Finset α} (s_mble : MeasurableSet (s : Set α)) :
count (↑s : Set α) = s.card :=
calc
count (↑s : Set α) = ∑' i : (↑s : Set α), 1 := count_apply s_mble
_ = ∑ i ∈ s, 1 := s.tsum_subtype 1
_ = s.card := by simp
@[simp]
theorem count_apply_finset [MeasurableSingletonClass α] (s : Finset α) :
count (↑s : Set α) = s.card :=
count_apply_finset' s.measurableSet
theorem count_apply_finite' {s : Set α} (s_fin : s.Finite) (s_mble : MeasurableSet s) :
count s = s_fin.toFinset.card := by
simp [←
@count_apply_finset' _ _ s_fin.toFinset (by simpa only [Finite.coe_toFinset] using s_mble)]
theorem count_apply_finite [MeasurableSingletonClass α] (s : Set α) (hs : s.Finite) :
count s = hs.toFinset.card := by rw [← count_apply_finset, Finite.coe_toFinset]
/-- `count` measure evaluates to infinity at infinite sets. -/
theorem count_apply_infinite (hs : s.Infinite) : count s = ∞ := by
refine top_unique (le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n => ?_)
rcases hs.exists_subset_card_eq n with ⟨t, ht, rfl⟩
calc
(t.card : ℝ≥0∞) = ∑ i ∈ t, 1 := by simp
_ = ∑' i : (t : Set α), 1 := (t.tsum_subtype 1).symm
_ ≤ count (t : Set α) := le_count_apply
_ ≤ count s := measure_mono ht
@[simp]
theorem count_apply_eq_top' (s_mble : MeasurableSet s) : count s = ∞ ↔ s.Infinite := by
by_cases hs : s.Finite
· simp [Set.Infinite, hs, count_apply_finite' hs s_mble]
· change s.Infinite at hs
simp [hs, count_apply_infinite]
@[simp]
theorem count_apply_eq_top [MeasurableSingletonClass α] : count s = ∞ ↔ s.Infinite := by
by_cases hs : s.Finite
· exact count_apply_eq_top' hs.measurableSet
· change s.Infinite at hs
simp [hs, count_apply_infinite]
@[simp]
theorem count_apply_lt_top' (s_mble : MeasurableSet 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 := Classical.not_not
@[simp]
theorem count_apply_lt_top [MeasurableSingletonClass α] : count s < ∞ ↔ s.Finite :=
calc
count s < ∞ ↔ count s ≠ ∞ := lt_top_iff_ne_top
_ ↔ ¬s.Infinite := not_congr count_apply_eq_top
_ ↔ s.Finite := Classical.not_not
theorem empty_of_count_eq_zero' (s_mble : MeasurableSet s) (hsc : count s = 0) : s = ∅ := by
have hs : s.Finite := by
rw [← count_apply_lt_top' s_mble, hsc]
exact WithTop.zero_lt_top
simpa [count_apply_finite' hs s_mble] using hsc
theorem empty_of_count_eq_zero [MeasurableSingletonClass α] (hsc : count s = 0) : s = ∅ := by
have hs : s.Finite := by
rw [← count_apply_lt_top, hsc]
exact WithTop.zero_lt_top
simpa [count_apply_finite _ hs] using hsc
@[simp]
theorem count_eq_zero_iff' (s_mble : MeasurableSet s) : count s = 0 ↔ s = ∅ :=
⟨empty_of_count_eq_zero' s_mble, fun h => h.symm ▸ count_empty⟩
@[simp]
theorem count_eq_zero_iff [MeasurableSingletonClass α] : count s = 0 ↔ s = ∅ :=
⟨empty_of_count_eq_zero, fun h => h.symm ▸ count_empty⟩
theorem count_ne_zero' (hs' : s.Nonempty) (s_mble : MeasurableSet s) : count s ≠ 0 := by
rw [Ne, count_eq_zero_iff' s_mble]
exact hs'.ne_empty
theorem count_ne_zero [MeasurableSingletonClass α] (hs' : s.Nonempty) : count s ≠ 0 := by
rw [Ne, count_eq_zero_iff]
exact hs'.ne_empty
@[simp]
theorem count_singleton' {a : α} (ha : MeasurableSet ({a} : Set α)) : count ({a} : Set α) = 1 := by
rw [count_apply_finite' (Set.finite_singleton a) ha, Set.Finite.toFinset]
simp [@toFinset_card _ _ (Set.finite_singleton a).fintype,
@Fintype.card_unique _ _ (Set.finite_singleton a).fintype]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem count_singleton [MeasurableSingletonClass α] (a : α) : count ({a} : Set α) = 1 :=
count_singleton' (measurableSet_singleton a)
theorem count_injective_image' {f : β → α} (hf : Function.Injective f) {s : Set β}
(s_mble : MeasurableSet s) (fs_mble : MeasurableSet (f '' s)) : count (f '' s) = count s := by
classical
by_cases hs : s.Finite
· lift s to Finset β using hs
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.injOn] at hs
rw [count_apply_infinite hs]
theorem count_injective_image [MeasurableSingletonClass α] [MeasurableSingletonClass β] {f : β → α}
(hf : Function.Injective f) (s : Set β) : count (f '' s) = count s := by
by_cases hs : s.Finite
· exact count_injective_image' hf hs.measurableSet (Finite.image f hs).measurableSet
rw [count_apply_infinite hs]
rw [← finite_image_iff hf.injOn] at hs
rw [count_apply_infinite hs]
instance count.isFiniteMeasure [Finite α] :
IsFiniteMeasure (Measure.count : Measure α) :=
⟨by
cases nonempty_fintype α
simpa [Measure.count_apply, tsum_fintype] using (ENNReal.natCast_ne_top _).lt_top⟩
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Dirac.lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.MeasureTheory.Measure.Typeclasses
import Mathlib.MeasureTheory.Measure.MutuallySingular
import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
/-!
# Dirac measure
In this file we define the Dirac measure `MeasureTheory.Measure.dirac a`
and prove some basic facts about it.
-/
open Function Set
open scoped ENNReal
noncomputable section
variable {α β δ : Type*} [MeasurableSpace α] [MeasurableSpace β] {s : Set α} {a : α}
namespace MeasureTheory
namespace Measure
/-- The dirac measure. -/
def dirac (a : α) : Measure α := (OuterMeasure.dirac a).toMeasure (by simp)
instance : MeasureSpace PUnit :=
⟨dirac PUnit.unit⟩
theorem le_dirac_apply {a} : s.indicator 1 a ≤ dirac a s :=
OuterMeasure.dirac_apply a s ▸ le_toMeasure_apply _ _ _
@[simp]
theorem dirac_apply' (a : α) (hs : MeasurableSet s) : dirac a s = s.indicator 1 a :=
toMeasure_apply _ _ hs
@[simp]
theorem dirac_apply_of_mem {a : α} (h : a ∈ s) : dirac a s = 1 := by
have : ∀ t : Set α, a ∈ t → t.indicator (1 : α → ℝ≥0∞) a = 1 := fun t ht => indicator_of_mem ht 1
refine le_antisymm (this univ trivial ▸ ?_) (this s h ▸ le_dirac_apply)
rw [← dirac_apply' a MeasurableSet.univ]
exact measure_mono (subset_univ s)
@[simp]
theorem dirac_apply [MeasurableSingletonClass α] (a : α) (s : Set α) :
dirac a s = s.indicator 1 a := by
by_cases h : a ∈ s; · rw [dirac_apply_of_mem h, indicator_of_mem h, Pi.one_apply]
rw [indicator_of_not_mem h, ← nonpos_iff_eq_zero]
calc
dirac a s ≤ dirac a {a}ᶜ := measure_mono (subset_compl_comm.1 <| singleton_subset_iff.2 h)
_ = 0 := by simp [dirac_apply' _ (measurableSet_singleton _).compl]
theorem map_dirac {f : α → β} (hf : Measurable f) (a : α) : (dirac a).map f = dirac (f a) := by
classical
exact ext fun s hs => by simp [hs, map_apply hf hs, hf hs, indicator_apply]
lemma map_const (μ : Measure α) (c : β) : μ.map (fun _ ↦ c) = (μ Set.univ) • dirac c := by
ext s hs
simp only [aemeasurable_const, measurable_const, Measure.coe_smul, Pi.smul_apply,
dirac_apply' _ hs, smul_eq_mul]
classical
rw [Measure.map_apply measurable_const hs, Set.preimage_const]
by_cases hsc : c ∈ s
· rw [(Set.indicator_eq_one_iff_mem _).mpr hsc, mul_one, if_pos hsc]
· rw [if_neg hsc, (Set.indicator_eq_zero_iff_not_mem _).mpr hsc, measure_empty, mul_zero]
@[simp]
theorem restrict_singleton (μ : Measure α) (a : α) : μ.restrict {a} = μ {a} • dirac a := by
ext1 s hs
by_cases ha : a ∈ s
· have : s ∩ {a} = {a} := by simpa
simp [*]
· have : s ∩ {a} = ∅ := inter_singleton_eq_empty.2 ha
simp [*]
/-- If `f` is a map with countable codomain, then `μ.map f` is a sum of Dirac measures. -/
theorem map_eq_sum [Countable β] [MeasurableSingletonClass β] (μ : Measure α) (f : α → β)
(hf : Measurable f) : μ.map f = sum fun b : β => μ (f ⁻¹' {b}) • dirac b := by
ext s
have : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y}) := fun y _ => hf (measurableSet_singleton _)
simp [← tsum_measure_preimage_singleton (to_countable s) this, *,
tsum_subtype s fun b => μ (f ⁻¹' {b}), ← indicator_mul_right s fun b => μ (f ⁻¹' {b})]
/-- A measure on a countable type is a sum of Dirac measures. -/
@[simp]
theorem sum_smul_dirac [Countable α] [MeasurableSingletonClass α] (μ : Measure α) :
(sum fun a => μ {a} • dirac a) = μ := by simpa using (map_eq_sum μ id measurable_id).symm
/-- Given that `α` is a countable, measurable space with all singleton sets measurable,
write the measure of a set `s` as the sum of the measure of `{x}` for all `x ∈ s`. -/
theorem tsum_indicator_apply_singleton [Countable α] [MeasurableSingletonClass α] (μ : Measure α)
(s : Set α) (hs : MeasurableSet s) : (∑' x : α, s.indicator (fun x => μ {x}) x) = μ s := by
classical
calc
(∑' x : α, s.indicator (fun x => μ {x}) x) =
Measure.sum (fun a => μ {a} • Measure.dirac a) s := by
simp only [Measure.sum_apply _ hs, Measure.smul_apply, smul_eq_mul, Measure.dirac_apply,
Set.indicator_apply, mul_ite, Pi.one_apply, mul_one, mul_zero]
_ = μ s := by rw [μ.sum_smul_dirac]
end Measure
open Measure
theorem mem_ae_dirac_iff {a : α} (hs : MeasurableSet s) : s ∈ ae (dirac a) ↔ a ∈ s := by
by_cases a ∈ s <;> simp [mem_ae_iff, dirac_apply', hs.compl, indicator_apply, *]
theorem ae_dirac_iff {a : α} {p : α → Prop} (hp : MeasurableSet { x | p x }) :
(∀ᵐ x ∂dirac a, p x) ↔ p a :=
mem_ae_dirac_iff hp
@[simp]
theorem ae_dirac_eq [MeasurableSingletonClass α] (a : α) : ae (dirac a) = pure a := by
ext s
simp [mem_ae_iff, imp_false]
theorem ae_eq_dirac' [MeasurableSingletonClass β] {a : α} {f : α → β} (hf : Measurable f) :
f =ᵐ[dirac a] const α (f a) :=
(ae_dirac_iff <| show MeasurableSet (f ⁻¹' {f a}) from hf <| measurableSet_singleton _).2 rfl
theorem ae_eq_dirac [MeasurableSingletonClass α] {a : α} (f : α → δ) :
f =ᵐ[dirac a] const α (f a) := by simp [Filter.EventuallyEq]
instance Measure.dirac.isProbabilityMeasure {x : α} : IsProbabilityMeasure (dirac x) :=
⟨dirac_apply_of_mem <| mem_univ x⟩
/-! Extra instances to short-circuit type class resolution -/
instance Measure.dirac.instIsFiniteMeasure {a : α} : IsFiniteMeasure (dirac a) := inferInstance
instance Measure.dirac.instSigmaFinite {a : α} : SigmaFinite (dirac a) := inferInstance
theorem restrict_dirac' (hs : MeasurableSet s) [Decidable (a ∈ s)] :
(Measure.dirac a).restrict s = if a ∈ s then Measure.dirac a else 0 := by
split_ifs with has
· apply restrict_eq_self_of_ae_mem
rw [ae_dirac_iff] <;> assumption
· rw [restrict_eq_zero, dirac_apply' _ hs, indicator_of_not_mem has]
theorem restrict_dirac [MeasurableSingletonClass α] [Decidable (a ∈ s)] :
(Measure.dirac a).restrict s = if a ∈ s then Measure.dirac a else 0 := by
split_ifs with has
· apply restrict_eq_self_of_ae_mem
rwa [ae_dirac_eq]
· rw [restrict_eq_zero, dirac_apply, indicator_of_not_mem has]
lemma mutuallySingular_dirac [MeasurableSingletonClass α] (x : α) (μ : Measure α) [NoAtoms μ] :
Measure.dirac x ⟂ₘ μ :=
⟨{x}ᶜ, (MeasurableSet.singleton x).compl, by simp, by simp⟩
section dirac_injective
/-- Dirac delta measures at two points are equal if every measurable set contains either both or
neither of the points. -/
lemma dirac_eq_dirac_iff_forall_mem_iff_mem {x y : α} :
Measure.dirac x = Measure.dirac y ↔ ∀ A, MeasurableSet A → (x ∈ A ↔ y ∈ A) := by
constructor
· intro h A A_mble
have obs := congr_arg (fun μ ↦ μ A) h
simp only [Measure.dirac_apply' _ A_mble] at obs
by_cases x_in_A : x ∈ A
· simpa only [x_in_A, indicator_of_mem, Pi.one_apply, true_iff, Eq.comm (a := (1 : ℝ≥0∞)),
indicator_eq_one_iff_mem] using obs
· simpa only [x_in_A, indicator_of_not_mem, Eq.comm (a := (0 : ℝ≥0∞)), indicator_apply_eq_zero,
false_iff, not_false_eq_true, Pi.one_apply, one_ne_zero, imp_false] using obs
· intro h
ext A A_mble
by_cases x_in_A : x ∈ A
· simp only [Measure.dirac_apply' _ A_mble, x_in_A, indicator_of_mem, Pi.one_apply,
(h A A_mble).mp x_in_A]
· have y_notin_A : y ∉ A := by simp_all only [false_iff, not_false_eq_true]
simp only [Measure.dirac_apply' _ A_mble, x_in_A, y_notin_A,
not_false_eq_true, indicator_of_not_mem]
/-- Dirac delta measures at two points are different if and only if there is a measurable set
containing one of the points but not the other. -/
lemma dirac_ne_dirac_iff_exists_measurableSet {x y : α} :
Measure.dirac x ≠ Measure.dirac y ↔ ∃ A, MeasurableSet A ∧ x ∈ A ∧ y ∉ A := by
apply not_iff_not.mp
simp only [ne_eq, not_not, not_exists, not_and, dirac_eq_dirac_iff_forall_mem_iff_mem]
refine ⟨fun h A A_mble ↦ by simp only [h A A_mble, imp_self], fun h A A_mble ↦ ?_⟩
by_cases x_in_A : x ∈ A
· simp only [x_in_A, h A A_mble x_in_A]
· simpa only [x_in_A, false_iff] using h Aᶜ (MeasurableSet.compl_iff.mpr A_mble) x_in_A
open MeasurableSpace
/-- Dirac delta measures at two different points are different, assuming the measurable space
separates points. -/
lemma dirac_ne_dirac [SeparatesPoints α] {x y : α} (x_ne_y : x ≠ y) :
Measure.dirac x ≠ Measure.dirac y := by
obtain ⟨A, A_mble, x_in_A, y_notin_A⟩ := exists_measurableSet_of_ne x_ne_y
exact dirac_ne_dirac_iff_exists_measurableSet.mpr ⟨A, A_mble, x_in_A, y_notin_A⟩
/-- Dirac delta measures at two points are different if and only if the two points are different,
assuming the measurable space separates points. -/
lemma dirac_ne_dirac_iff [SeparatesPoints α] {x y : α} :
Measure.dirac x ≠ Measure.dirac y ↔ x ≠ y :=
⟨fun h x_eq_y ↦ h <| congrArg dirac x_eq_y, fun h ↦ dirac_ne_dirac h⟩
/-- Dirac delta measures at two points are equal if and only if the two points are equal,
assuming the measurable space separates points. -/
lemma dirac_eq_dirac_iff [SeparatesPoints α] {x y : α} :
Measure.dirac x = Measure.dirac y ↔ x = y := not_iff_not.mp dirac_ne_dirac_iff
/-- The assignment `x ↦ dirac x` is injective, assuming the measurable space separates points. -/
lemma injective_dirac [SeparatesPoints α] :
Function.Injective (fun (x : α) ↦ dirac x) := fun x y x_ne_y ↦ by rwa [← dirac_eq_dirac_iff]
end dirac_injective
end MeasureTheory
|
MeasureTheory\Measure\DiracProba.lean | /-
Copyright (c) 2024 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.Topology.CompletelyRegular
import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
/-!
# Dirac deltas as probability measures and embedding of a space into probability measures on it
## Main definitions
* `diracProba`: The Dirac delta mass at a point as a probability measure.
## Main results
* `embedding_diracProba`: If `X` is a completely regular T0 space with its Borel sigma algebra,
then the mapping that takes a point `x : X` to the delta-measure `diracProba x` is an embedding
`X ↪ ProbabilityMeasure X`.
## Tags
probability measure, Dirac delta, embedding
-/
open Topology Metric Filter Set ENNReal NNReal BoundedContinuousFunction
open scoped Topology ENNReal NNReal BoundedContinuousFunction
lemma CompletelyRegularSpace.exists_BCNN {X : Type*} [TopologicalSpace X] [CompletelyRegularSpace X]
{K : Set X} (K_closed : IsClosed K) {x : X} (x_notin_K : x ∉ K) :
∃ (f : X →ᵇ ℝ≥0), f x = 1 ∧ (∀ y ∈ K, f y = 0) := by
obtain ⟨g, g_cont, gx_zero, g_one_on_K⟩ :=
CompletelyRegularSpace.completely_regular x K K_closed x_notin_K
have g_bdd : ∀ x y, dist (Real.toNNReal (g x)) (Real.toNNReal (g y)) ≤ 1 := by
refine fun x y ↦ ((Real.lipschitzWith_toNNReal).dist_le_mul (g x) (g y)).trans ?_
simpa using Real.dist_le_of_mem_Icc_01 (g x).prop (g y).prop
set g' := BoundedContinuousFunction.mkOfBound
⟨fun x ↦ Real.toNNReal (g x), continuous_real_toNNReal.comp g_cont.subtype_val⟩ 1 g_bdd
set f := 1 - g'
refine ⟨f, by simp [f, g', gx_zero], fun y y_in_K ↦ by simp [f, g', g_one_on_K y_in_K]⟩
namespace MeasureTheory
section embed_to_probabilityMeasure
variable {X : Type*} [MeasurableSpace X]
/-- The Dirac delta mass at a point `x : X` as a `ProbabilityMeasure`. -/
noncomputable def diracProba (x : X) : ProbabilityMeasure X :=
⟨Measure.dirac x, Measure.dirac.isProbabilityMeasure⟩
/-- The assignment `x ↦ diracProba x` is injective if all singletons are measurable. -/
lemma injective_diracProba {X : Type*} [MeasurableSpace X] [MeasurableSpace.SeparatesPoints X] :
Function.Injective (fun (x : X) ↦ diracProba x) := by
intro x y x_eq_y
rw [← dirac_eq_dirac_iff]
rwa [Subtype.ext_iff] at x_eq_y
@[simp] lemma diracProba_toMeasure_apply' (x : X) {A : Set X} (A_mble : MeasurableSet A) :
(diracProba x).toMeasure A = A.indicator 1 x := Measure.dirac_apply' x A_mble
@[simp] lemma diracProba_toMeasure_apply_of_mem {x : X} {A : Set X} (x_in_A : x ∈ A) :
(diracProba x).toMeasure A = 1 := Measure.dirac_apply_of_mem x_in_A
@[simp] lemma diracProba_toMeasure_apply [MeasurableSingletonClass X] (x : X) (A : Set X) :
(diracProba x).toMeasure A = A.indicator 1 x := Measure.dirac_apply _ _
variable [TopologicalSpace X] [OpensMeasurableSpace X]
/-- The assignment `x ↦ diracProba x` is continuous `X → ProbabilityMeasure X`. -/
lemma continuous_diracProba : Continuous (fun (x : X) ↦ diracProba x) := by
rw [continuous_iff_continuousAt]
apply fun x ↦ ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto.mpr fun f ↦ ?_
have f_mble : Measurable (fun X ↦ (f X : ℝ≥0∞)) :=
measurable_coe_nnreal_ennreal_iff.mpr f.continuous.measurable
simp only [diracProba, ProbabilityMeasure.coe_mk, lintegral_dirac' _ f_mble]
exact (ENNReal.continuous_coe.comp f.continuous).continuousAt
/-- In a T0 topological space equipped with a sigma algebra which contains all open sets,
the assignment `x ↦ diracProba x` is injective. -/
lemma injective_diracProba_of_T0 [T0Space X] :
Function.Injective (fun (x : X) ↦ diracProba x) := by
intro x y δx_eq_δy
by_contra x_ne_y
exact dirac_ne_dirac x_ne_y <| congr_arg Subtype.val δx_eq_δy
lemma not_tendsto_diracProba_of_not_tendsto [CompletelyRegularSpace X] {x : X} (L : Filter X)
(h : ¬ Tendsto id L (𝓝 x)) :
¬ Tendsto diracProba L (𝓝 (diracProba x)) := by
obtain ⟨U, U_nhd, hU⟩ : ∃ U, U ∈ 𝓝 x ∧ ∃ᶠ x in L, x ∉ U := by
by_contra! con
apply h
intro U U_nhd
simpa only [not_frequently, not_not] using con U U_nhd
have Uint_nhd : interior U ∈ 𝓝 x := by simpa only [interior_mem_nhds] using U_nhd
obtain ⟨f, fx_eq_one, f_vanishes_outside⟩ :=
CompletelyRegularSpace.exists_BCNN isOpen_interior.isClosed_compl
(by simpa only [mem_compl_iff, not_not] using mem_of_mem_nhds Uint_nhd)
rw [ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto, not_forall]
use f
simp only [diracProba, ProbabilityMeasure.coe_mk, fx_eq_one,
lintegral_dirac' _ (measurable_coe_nnreal_ennreal_iff.mpr f.continuous.measurable)]
apply not_tendsto_iff_exists_frequently_nmem.mpr
refine ⟨Ioi 0, Ioi_mem_nhds (by simp only [ENNReal.coe_one, zero_lt_one]),
hU.mp (eventually_of_forall ?_)⟩
intro x x_notin_U
rw [f_vanishes_outside x
(compl_subset_compl.mpr (show interior U ⊆ U from interior_subset) x_notin_U)]
simp only [ENNReal.coe_zero, mem_Ioi, lt_self_iff_false, not_false_eq_true]
lemma tendsto_diracProba_iff_tendsto [CompletelyRegularSpace X] {x : X} (L : Filter X) :
Tendsto diracProba L (𝓝 (diracProba x)) ↔ Tendsto id L (𝓝 x) := by
constructor
· contrapose
exact not_tendsto_diracProba_of_not_tendsto L
· intro h
have aux := (@continuous_diracProba X _ _ _).continuousAt (x := x)
simp only [ContinuousAt] at aux
exact aux.comp h
/-- An inverse function to `diracProba` (only really an inverse under hypotheses that
guarantee injectivity of `diracProba`). -/
noncomputable def diracProbaInverse : range (diracProba (X := X)) → X :=
fun μ' ↦ (mem_range.mp μ'.prop).choose
@[simp] lemma diracProba_diracProbaInverse (μ : range (diracProba (X := X))) :
diracProba (diracProbaInverse μ) = μ := (mem_range.mp μ.prop).choose_spec
lemma diracProbaInverse_eq [T0Space X] {x : X} {μ : range (diracProba (X := X))}
(h : μ = diracProba x) :
diracProbaInverse μ = x := by
apply injective_diracProba_of_T0 (X := X)
simp only [← h]
exact (mem_range.mp μ.prop).choose_spec
/-- In a T0 topological space `X`, the assignment `x ↦ diracProba x` is a bijection to its
range in `ProbabilityMeasure X`. -/
noncomputable def diracProbaEquiv [T0Space X] : X ≃ range (diracProba (X := X)) where
toFun := fun x ↦ ⟨diracProba x, by exact mem_range_self x⟩
invFun := diracProbaInverse
left_inv x := by apply diracProbaInverse_eq; rfl
right_inv μ := Subtype.ext (by simp only [diracProba_diracProbaInverse])
/-- The composition of `diracProbaEquiv.symm` and `diracProba` is the subtype inclusion. -/
lemma diracProba_comp_diracProbaEquiv_symm_eq_val [T0Space X] :
diracProba ∘ (diracProbaEquiv (X := X)).symm = fun μ ↦ μ.val := by
funext μ; simp [diracProbaEquiv]
lemma tendsto_diracProbaEquivSymm_iff_tendsto [T0Space X] [CompletelyRegularSpace X]
{μ : range (diracProba (X := X))} (F : Filter (range (diracProba (X := X)))) :
Tendsto diracProbaEquiv.symm F (𝓝 (diracProbaEquiv.symm μ)) ↔ Tendsto id F (𝓝 μ) := by
have key :=
tendsto_diracProba_iff_tendsto (F.map diracProbaEquiv.symm) (x := diracProbaEquiv.symm μ)
rw [← (diracProbaEquiv (X := X)).symm_comp_self, ← tendsto_map'_iff] at key
simp only [tendsto_map'_iff, map_map, Equiv.self_comp_symm, map_id] at key
simp only [← key, diracProba_comp_diracProbaEquiv_symm_eq_val]
convert tendsto_subtype_rng.symm
exact apply_rangeSplitting (fun x ↦ diracProba x) μ
/-- In a T0 topological space, `diracProbaEquiv` is continuous. -/
lemma continuous_diracProbaEquiv [T0Space X] :
Continuous (diracProbaEquiv (X := X)) :=
Continuous.subtype_mk continuous_diracProba mem_range_self
/-- In a completely regular T0 topological space, the inverse of `diracProbaEquiv` is continuous. -/
lemma continuous_diracProbaEquivSymm [T0Space X] [CompletelyRegularSpace X] :
Continuous (diracProbaEquiv (X := X)).symm := by
apply continuous_iff_continuousAt.mpr
intro μ
apply continuousAt_of_tendsto_nhds (y := diracProbaInverse μ)
exact (tendsto_diracProbaEquivSymm_iff_tendsto _).mpr fun _ mem_nhd ↦ mem_nhd
/-- In a completely regular T0 topological space `X`, `diracProbaEquiv` is a homeomorphism to
its image in `ProbabilityMeasure X`. -/
noncomputable def diracProbaHomeomorph [T0Space X] [CompletelyRegularSpace X]
[MeasurableSpace X] [OpensMeasurableSpace X] : X ≃ₜ range (diracProba (X := X)) :=
@Homeomorph.mk X _ _ _ diracProbaEquiv continuous_diracProbaEquiv continuous_diracProbaEquivSymm
/-- If `X` is a completely regular T0 space with its Borel sigma algebra, then the mapping
that takes a point `x : X` to the delta-measure `diracProba x` is an embedding
`X → ProbabilityMeasure X`. -/
theorem embedding_diracProba [T0Space X] [CompletelyRegularSpace X]
[MeasurableSpace X] [OpensMeasurableSpace X] : Embedding (fun (x : X) ↦ diracProba x) :=
embedding_subtype_val.comp diracProbaHomeomorph.embedding
end embed_to_probabilityMeasure
end MeasureTheory
|
MeasureTheory\Measure\Doubling.lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Analysis.SpecialFunctions.Log.Base
import Mathlib.MeasureTheory.Measure.MeasureSpaceDef
/-!
# Uniformly locally doubling measures
A uniformly locally doubling measure `μ` on a metric space is a measure for which there exists a
constant `C` such that for all sufficiently small radii `ε`, and for any centre, the measure of a
ball of radius `2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`.
This file records basic facts about uniformly locally doubling measures.
## Main definitions
* `IsUnifLocDoublingMeasure`: the definition of a uniformly locally doubling measure (as a
typeclass).
* `IsUnifLocDoublingMeasure.doublingConstant`: a function yielding the doubling constant `C`
appearing in the definition of a uniformly locally doubling measure.
-/
noncomputable section
open Set Filter Metric MeasureTheory TopologicalSpace ENNReal NNReal Topology
/-- A measure `μ` is said to be a uniformly locally doubling measure if there exists a constant `C`
such that for all sufficiently small radii `ε`, and for any centre, the measure of a ball of radius
`2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`.
Note: it is important that this definition makes a demand only for sufficiently small `ε`. For
example we want hyperbolic space to carry the instance `IsUnifLocDoublingMeasure volume` but
volumes grow exponentially in hyperbolic space. To be really explicit, consider the hyperbolic plane
of curvature -1, the area of a disc of radius `ε` is `A(ε) = 2π(cosh(ε) - 1)` so
`A(2ε)/A(ε) ~ exp(ε)`. -/
class IsUnifLocDoublingMeasure {α : Type*} [MetricSpace α] [MeasurableSpace α]
(μ : Measure α) : Prop where
exists_measure_closedBall_le_mul'' :
∃ C : ℝ≥0, ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x (2 * ε)) ≤ C * μ (closedBall x ε)
namespace IsUnifLocDoublingMeasure
variable {α : Type*} [MetricSpace α] [MeasurableSpace α] (μ : Measure α)
[IsUnifLocDoublingMeasure μ]
-- Porting note: added for missing infer kinds
theorem exists_measure_closedBall_le_mul :
∃ C : ℝ≥0, ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x (2 * ε)) ≤ C * μ (closedBall x ε) :=
exists_measure_closedBall_le_mul''
/-- A doubling constant for a uniformly locally doubling measure.
See also `IsUnifLocDoublingMeasure.scalingConstantOf`. -/
def doublingConstant : ℝ≥0 :=
Classical.choose <| exists_measure_closedBall_le_mul μ
theorem exists_measure_closedBall_le_mul' :
∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closedBall x (2 * ε)) ≤ doublingConstant μ * μ (closedBall x ε) :=
Classical.choose_spec <| exists_measure_closedBall_le_mul μ
theorem exists_eventually_forall_measure_closedBall_le_mul (K : ℝ) :
∃ C : ℝ≥0, ∀ᶠ ε in 𝓝[>] 0, ∀ x, ∀ t ≤ K, μ (closedBall x (t * ε)) ≤ C * μ (closedBall x ε) := by
let C := doublingConstant μ
have hμ :
∀ n : ℕ, ∀ᶠ ε in 𝓝[>] 0, ∀ x,
μ (closedBall x ((2 : ℝ) ^ n * ε)) ≤ ↑(C ^ n) * μ (closedBall x ε) := by
intro n
induction' n with n ih
· simp
replace ih := eventually_nhdsWithin_pos_mul_left (two_pos : 0 < (2 : ℝ)) ih
refine (ih.and (exists_measure_closedBall_le_mul' μ)).mono fun ε hε x => ?_
calc
μ (closedBall x ((2 : ℝ) ^ (n + 1) * ε)) = μ (closedBall x ((2 : ℝ) ^ n * (2 * ε))) := by
rw [pow_succ, mul_assoc]
_ ≤ ↑(C ^ n) * μ (closedBall x (2 * ε)) := hε.1 x
_ ≤ ↑(C ^ n) * (C * μ (closedBall x ε)) := by gcongr; exact hε.2 x
_ = ↑(C ^ (n + 1)) * μ (closedBall x ε) := by rw [← mul_assoc, pow_succ, ENNReal.coe_mul]
rcases lt_or_le K 1 with (hK | hK)
· refine ⟨1, ?_⟩
simp only [ENNReal.coe_one, one_mul]
refine eventually_mem_nhdsWithin.mono fun ε hε x t ht ↦ ?_
gcongr
nlinarith [mem_Ioi.mp hε]
· use C ^ ⌈Real.logb 2 K⌉₊
filter_upwards [hμ ⌈Real.logb 2 K⌉₊, eventually_mem_nhdsWithin] with ε hε hε₀ x t ht
refine le_trans ?_ (hε x)
gcongr
· exact (mem_Ioi.mp hε₀).le
· refine ht.trans ?_
rw [← Real.rpow_natCast, ← Real.logb_le_iff_le_rpow]
exacts [Nat.le_ceil _, by norm_num, by linarith]
/-- A variant of `IsUnifLocDoublingMeasure.doublingConstant` which allows for scaling the
radius by values other than `2`. -/
def scalingConstantOf (K : ℝ) : ℝ≥0 :=
max (Classical.choose <| exists_eventually_forall_measure_closedBall_le_mul μ K) 1
@[simp]
theorem one_le_scalingConstantOf (K : ℝ) : 1 ≤ scalingConstantOf μ K :=
le_max_of_le_right <| le_refl 1
theorem eventually_measure_mul_le_scalingConstantOf_mul (K : ℝ) :
∃ R : ℝ,
0 < R ∧
∀ x t r, t ∈ Ioc 0 K → r ≤ R →
μ (closedBall x (t * r)) ≤ scalingConstantOf μ K * μ (closedBall x r) := by
have h := Classical.choose_spec (exists_eventually_forall_measure_closedBall_le_mul μ K)
rcases mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 h with ⟨R, Rpos, hR⟩
refine ⟨R, Rpos, fun x t r ht hr => ?_⟩
rcases lt_trichotomy r 0 with (rneg | rfl | rpos)
· have : t * r < 0 := mul_neg_of_pos_of_neg ht.1 rneg
simp only [closedBall_eq_empty.2 this, measure_empty, zero_le']
· simp only [mul_zero, closedBall_zero]
refine le_mul_of_one_le_of_le ?_ le_rfl
apply ENNReal.one_le_coe_iff.2 (le_max_right _ _)
· apply (hR ⟨rpos, hr⟩ x t ht.2).trans
gcongr
apply le_max_left
theorem eventually_measure_le_scaling_constant_mul (K : ℝ) :
∀ᶠ r in 𝓝[>] 0, ∀ x, μ (closedBall x (K * r)) ≤ scalingConstantOf μ K * μ (closedBall x r) := by
filter_upwards [Classical.choose_spec
(exists_eventually_forall_measure_closedBall_le_mul μ K)] with r hr x
exact (hr x K le_rfl).trans (mul_le_mul_right' (ENNReal.coe_le_coe.2 (le_max_left _ _)) _)
theorem eventually_measure_le_scaling_constant_mul' (K : ℝ) (hK : 0 < K) :
∀ᶠ r in 𝓝[>] 0, ∀ x,
μ (closedBall x r) ≤ scalingConstantOf μ K⁻¹ * μ (closedBall x (K * r)) := by
convert eventually_nhdsWithin_pos_mul_left hK (eventually_measure_le_scaling_constant_mul μ K⁻¹)
simp [inv_mul_cancel_left₀ hK.ne']
/-- A scale below which the doubling measure `μ` satisfies good rescaling properties when one
multiplies the radius of balls by at most `K`, as stated
in `IsUnifLocDoublingMeasure.measure_mul_le_scalingConstantOf_mul`. -/
def scalingScaleOf (K : ℝ) : ℝ :=
(eventually_measure_mul_le_scalingConstantOf_mul μ K).choose
theorem scalingScaleOf_pos (K : ℝ) : 0 < scalingScaleOf μ K :=
(eventually_measure_mul_le_scalingConstantOf_mul μ K).choose_spec.1
theorem measure_mul_le_scalingConstantOf_mul {K : ℝ} {x : α} {t r : ℝ} (ht : t ∈ Ioc 0 K)
(hr : r ≤ scalingScaleOf μ K) :
μ (closedBall x (t * r)) ≤ scalingConstantOf μ K * μ (closedBall x r) :=
(eventually_measure_mul_le_scalingConstantOf_mul μ K).choose_spec.2 x t r ht hr
end IsUnifLocDoublingMeasure
|
MeasureTheory\Measure\EverywherePos.lean | /-
Copyright (c) 2024 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Group.Measure
import Mathlib.Topology.UrysohnsLemma
/-!
# Everywhere positive sets in measure spaces
A set `s` in a topological space with a measure `μ` is *everywhere positive* (also called
*self-supporting*) if any neighborhood `n` of any point of `s` satisfies `μ (s ∩ n) > 0`.
## Main definitions and results
* `μ.IsEverywherePos s` registers that, for any point in `s`, all its neighborhoods have positive
measure inside `s`.
* `μ.everywherePosSubset s` is the subset of `s` made of those points all of whose neighborhoods
have positive measure inside `s`.
* `everywherePosSubset_ae_eq` shows that `s` and `μ.everywherePosSubset s` coincide almost
everywhere if `μ` is inner regular and `s` is measurable.
* `isEverywherePos_everywherePosSubset` shows that `μ.everywherePosSubset s` satisfies the property
`μ.IsEverywherePos` if `μ` is inner regular and `s` is measurable.
The latter two statements have also versions when `μ` is inner regular for finite measure sets,
assuming additionally that `s` has finite measure.
* `IsEverywherePos.IsGδ` proves that an everywhere positive compact closed set is a Gδ set,
in a topological group with a left-invariant measure. This is a nontrivial statement, used
crucially in the study of the uniqueness of Haar measures.
* `innerRegularWRT_preimage_one_hasCompactSupport_measure_ne_top`: for a Haar measure, any
finite measure set can be approximated from inside by level sets of continuous
compactly supported functions. This property is also known as completion-regularity of Haar
measures.
-/
open scoped Topology ENNReal NNReal
open Set Filter
namespace MeasureTheory.Measure
variable {α : Type*} [TopologicalSpace α] [MeasurableSpace α]
/-- A set `s` is *everywhere positive* (also called *self-supporting*) with respect to a
measure `μ` if it has positive measure around each of its points, i.e., if all neighborhoods `n`
of points of `s` satisfy `μ (s ∩ n) > 0`. -/
def IsEverywherePos (μ : Measure α) (s : Set α) : Prop :=
∀ x ∈ s, ∀ n ∈ 𝓝[s] x, 0 < μ n
/-- * The everywhere positive subset of a set is the subset made of those points all of whose
neighborhoods have positive measure inside the set. -/
def everywherePosSubset (μ : Measure α) (s : Set α) : Set α :=
{x | x ∈ s ∧ ∀ n ∈ 𝓝[s] x, 0 < μ n}
lemma everywherePosSubset_subset (μ : Measure α) (s : Set α) : μ.everywherePosSubset s ⊆ s :=
fun _x hx ↦ hx.1
/-- The everywhere positive subset of a set is obtained by removing an open set. -/
lemma exists_isOpen_everywherePosSubset_eq_diff (μ : Measure α) (s : Set α) :
∃ u, IsOpen u ∧ μ.everywherePosSubset s = s \ u := by
refine ⟨{x | ∃ n ∈ 𝓝[s] x, μ n = 0}, ?_, by ext x; simp [everywherePosSubset, zero_lt_iff]⟩
rw [isOpen_iff_mem_nhds]
intro x ⟨n, ns, hx⟩
rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.1 ns with ⟨v, vx, hv⟩
rcases mem_nhds_iff.1 vx with ⟨w, wv, w_open, xw⟩
have A : w ⊆ {x | ∃ n ∈ 𝓝[s] x, μ n = 0} := by
intro y yw
refine ⟨s ∩ w, inter_mem_nhdsWithin _ (w_open.mem_nhds yw), measure_mono_null ?_ hx⟩
rw [inter_comm]
exact (inter_subset_inter_left _ wv).trans hv
have B : w ∈ 𝓝 x := w_open.mem_nhds xw
exact mem_of_superset B A
variable {μ ν : Measure α} {s k : Set α}
protected lemma _root_.MeasurableSet.everywherePosSubset [OpensMeasurableSpace α]
(hs : MeasurableSet s) :
MeasurableSet (μ.everywherePosSubset s) := by
rcases exists_isOpen_everywherePosSubset_eq_diff μ s with ⟨u, u_open, hu⟩
rw [hu]
exact hs.diff u_open.measurableSet
protected lemma _root_.IsClosed.everywherePosSubset (hs : IsClosed s) :
IsClosed (μ.everywherePosSubset s) := by
rcases exists_isOpen_everywherePosSubset_eq_diff μ s with ⟨u, u_open, hu⟩
rw [hu]
exact hs.sdiff u_open
protected lemma _root_.IsCompact.everywherePosSubset (hs : IsCompact s) :
IsCompact (μ.everywherePosSubset s) := by
rcases exists_isOpen_everywherePosSubset_eq_diff μ s with ⟨u, u_open, hu⟩
rw [hu]
exact hs.diff u_open
/-- Any compact set contained in `s \ μ.everywherePosSubset s` has zero measure. -/
lemma measure_eq_zero_of_subset_diff_everywherePosSubset
(hk : IsCompact k) (h'k : k ⊆ s \ μ.everywherePosSubset s) : μ k = 0 := by
apply hk.induction_on (p := fun t ↦ μ t = 0)
· exact measure_empty
· exact fun s t hst ht ↦ measure_mono_null hst ht
· exact fun s t hs ht ↦ measure_union_null hs ht
· intro x hx
obtain ⟨u, ux, hu⟩ : ∃ u ∈ 𝓝[s] x, μ u = 0 := by
simpa [everywherePosSubset, (h'k hx).1] using (h'k hx).2
exact ⟨u, nhdsWithin_mono x (h'k.trans diff_subset) ux, hu⟩
/-- In a space with an inner regular measure, any measurable set coincides almost everywhere with
its everywhere positive subset. -/
lemma everywherePosSubset_ae_eq [OpensMeasurableSpace α] [InnerRegular μ] (hs : MeasurableSet s) :
μ.everywherePosSubset s =ᵐ[μ] s := by
simp only [ae_eq_set, diff_eq_empty.mpr (everywherePosSubset_subset μ s), measure_empty,
true_and, (hs.diff hs.everywherePosSubset).measure_eq_iSup_isCompact, ENNReal.iSup_eq_zero]
intro k hk h'k
exact measure_eq_zero_of_subset_diff_everywherePosSubset h'k hk
/-- In a space with an inner regular measure for finite measure sets, any measurable set of finite
measure coincides almost everywhere with its everywhere positive subset. -/
lemma everywherePosSubset_ae_eq_of_measure_ne_top
[OpensMeasurableSpace α] [InnerRegularCompactLTTop μ] (hs : MeasurableSet s) (h's : μ s ≠ ∞) :
μ.everywherePosSubset s =ᵐ[μ] s := by
have A : μ (s \ μ.everywherePosSubset s) ≠ ∞ :=
((measure_mono diff_subset).trans_lt h's.lt_top).ne
simp only [ae_eq_set, diff_eq_empty.mpr (everywherePosSubset_subset μ s), measure_empty,
true_and, (hs.diff hs.everywherePosSubset).measure_eq_iSup_isCompact_of_ne_top A,
ENNReal.iSup_eq_zero]
intro k hk h'k
exact measure_eq_zero_of_subset_diff_everywherePosSubset h'k hk
/-- In a space with an inner regular measure, the everywhere positive subset of a measurable set
is itself everywhere positive. This is not obvious as `μ.everywherePosSubset s` is defined as
the points whose neighborhoods intersect `s` along positive measure subsets, but this does not
say they also intersect `μ.everywherePosSubset s` along positive measure subsets. -/
lemma isEverywherePos_everywherePosSubset
[OpensMeasurableSpace α] [InnerRegular μ] (hs : MeasurableSet s) :
μ.IsEverywherePos (μ.everywherePosSubset s) := by
intro x hx n hn
rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.1 hn with ⟨u, u_mem, hu⟩
have A : 0 < μ (u ∩ s) := by
have : u ∩ s ∈ 𝓝[s] x := by rw [inter_comm]; exact inter_mem_nhdsWithin s u_mem
exact hx.2 _ this
have B : (u ∩ μ.everywherePosSubset s : Set α) =ᵐ[μ] (u ∩ s : Set α) :=
ae_eq_set_inter (ae_eq_refl _) (everywherePosSubset_ae_eq hs)
rw [← B.measure_eq] at A
exact A.trans_le (measure_mono hu)
/-- In a space with an inner regular measure for finite measure sets, the everywhere positive subset
of a measurable set of finite measure is itself everywhere positive. This is not obvious as
`μ.everywherePosSubset s` is defined as the points whose neighborhoods intersect `s` along positive
measure subsets, but this does not say they also intersect `μ.everywherePosSubset s` along positive
measure subsets. -/
lemma isEverywherePos_everywherePosSubset_of_measure_ne_top
[OpensMeasurableSpace α] [InnerRegularCompactLTTop μ] (hs : MeasurableSet s) (h's : μ s ≠ ∞) :
μ.IsEverywherePos (μ.everywherePosSubset s) := by
intro x hx n hn
rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.1 hn with ⟨u, u_mem, hu⟩
have A : 0 < μ (u ∩ s) := by
have : u ∩ s ∈ 𝓝[s] x := by rw [inter_comm]; exact inter_mem_nhdsWithin s u_mem
exact hx.2 _ this
have B : (u ∩ μ.everywherePosSubset s : Set α) =ᵐ[μ] (u ∩ s : Set α) :=
ae_eq_set_inter (ae_eq_refl _) (everywherePosSubset_ae_eq_of_measure_ne_top hs h's)
rw [← B.measure_eq] at A
exact A.trans_le (measure_mono hu)
lemma IsEverywherePos.smul_measure (hs : IsEverywherePos μ s) {c : ℝ≥0∞} (hc : c ≠ 0) :
IsEverywherePos (c • μ) s :=
fun x hx n hn ↦ by simpa [hc.bot_lt, hs x hx n hn] using hc.bot_lt
lemma IsEverywherePos.smul_measure_nnreal (hs : IsEverywherePos μ s) {c : ℝ≥0} (hc : c ≠ 0) :
IsEverywherePos (c • μ) s :=
hs.smul_measure (by simpa using hc)
/-- If two measures coincide locally, then a set which is everywhere positive for the former is
also everywhere positive for the latter. -/
lemma IsEverywherePos.of_forall_exists_nhds_eq (hs : IsEverywherePos μ s)
(h : ∀ x ∈ s, ∃ t ∈ 𝓝 x, ∀ u ⊆ t, ν u = μ u) : IsEverywherePos ν s := by
intro x hx n hn
rcases h x hx with ⟨t, t_mem, ht⟩
refine lt_of_lt_of_le ?_ (measure_mono (inter_subset_left (t := t)))
rw [ht (n ∩ t) inter_subset_right]
exact hs x hx _ (inter_mem hn (mem_nhdsWithin_of_mem_nhds t_mem))
/-- If two measures coincide locally, then a set is everywhere positive for the former iff it is
everywhere positive for the latter. -/
lemma isEverywherePos_iff_of_forall_exists_nhds_eq (h : ∀ x ∈ s, ∃ t ∈ 𝓝 x, ∀ u ⊆ t, ν u = μ u) :
IsEverywherePos ν s ↔ IsEverywherePos μ s := by
refine ⟨fun H ↦ H.of_forall_exists_nhds_eq ?_, fun H ↦ H.of_forall_exists_nhds_eq h⟩
intro x hx
rcases h x hx with ⟨t, ht, h't⟩
exact ⟨t, ht, fun u hu ↦ (h't u hu).symm⟩
/-- An open set is everywhere positive for a measure which is positive on open sets. -/
lemma _root_.IsOpen.isEverywherePos [IsOpenPosMeasure μ] (hs : IsOpen s) : IsEverywherePos μ s := by
intro x xs n hn
rcases mem_nhdsWithin.1 hn with ⟨u, u_open, xu, hu⟩
apply lt_of_lt_of_le _ (measure_mono hu)
exact (u_open.inter hs).measure_pos μ ⟨x, ⟨xu, xs⟩⟩
section TopologicalGroup
variable {G : Type*} [Group G] [TopologicalSpace G] [TopologicalGroup G]
[LocallyCompactSpace G] [MeasurableSpace G] [BorelSpace G] {μ : Measure G}
[IsMulLeftInvariant μ] [IsFiniteMeasureOnCompacts μ] [InnerRegularCompactLTTop μ]
open Pointwise
/-- If a compact closed set is everywhere positive with respect to a left-invariant measure on a
topological group, then it is a Gδ set. This is nontrivial, as there is no second-countability or
metrizability assumption in the statement, so a general compact closed set has no reason to be
a countable intersection of open sets. -/
@[to_additive]
lemma IsEverywherePos.IsGdelta_of_isMulLeftInvariant
{k : Set G} (h : μ.IsEverywherePos k) (hk : IsCompact k) (h'k : IsClosed k) :
IsGδ k := by
/- Consider a decreasing sequence of open neighborhoods `Vₙ` of the identity, such that `g k \ k`
has small measure for all `g ∈ Vₙ`. We claim that `k = ⋂ Vₙ k`, which proves
the lemma as the sets on the right are open. The inclusion `⊆` is trivial.
Let us show the converse. Take `x` in the intersection. For each `n`, write `x = vₙ yₙ` with
`vₙ ∈ Vₙ` and `yₙ ∈ k`. Let `z ∈ k` be a cluster value of `yₙ`, by compactness. As multiplication
by `vₙ = x yₙ⁻¹ ∈ Vₙ` changes the measure of `k` by very little, passing to the limit we get
`μ (x z⁻¹ k \ k) = 0`. By invariance of the measure under `z x ⁻¹`, we get `μ (k \ z x⁻¹ k) = 0`.
Assume `x ∉ k`. Then `z ∈ k \ z x⁻¹ k`. Even more, this set is a neighborhood of `z` within `k`
(as `z x⁻¹ k` is closed), and it has zero measure. This contradicts the fact that `k` has
positive measure around the point `z`. -/
obtain ⟨u, -, u_mem, u_lim⟩ : ∃ u, StrictAnti u ∧ (∀ (n : ℕ), u n ∈ Ioo 0 1)
∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto' (zero_lt_one : (0 : ℝ≥0∞) < 1)
have : ∀ n, ∃ (W : Set G), IsOpen W ∧ 1 ∈ W ∧ ∀ g ∈ W * W, μ ((g • k) \ k) < u n :=
fun n ↦ exists_open_nhds_one_mul_subset
(eventually_nhds_one_measure_smul_diff_lt hk h'k (u_mem n).1.ne')
choose W W_open mem_W hW using this
let V n := ⋂ i ∈ Finset.range n, W i
suffices ⋂ n, V n * k ⊆ k by
replace : k = ⋂ n, V n * k := by
apply Subset.antisymm (subset_iInter_iff.2 (fun n ↦ ?_)) this
exact subset_mul_right k (by simp [V, mem_W])
rw [this]
refine .iInter_of_isOpen fun n ↦ ?_
exact .mul_right (isOpen_biInter_finset (fun i _hi ↦ W_open i))
intro x hx
choose v hv y hy hvy using mem_iInter.1 hx
obtain ⟨z, zk, hz⟩ : ∃ z ∈ k, MapClusterPt z atTop y := hk.exists_mapClusterPt (by simp [hy])
have A n : μ (((x * z ⁻¹) • k) \ k) ≤ u n := by
apply le_of_lt (hW _ _ ?_)
have : W n * {z} ∈ 𝓝 z := (IsOpen.mul_right (W_open n)).mem_nhds (by simp [mem_W])
obtain ⟨i, hi, ni⟩ : ∃ i, y i ∈ W n * {z} ∧ n < i :=
(((mapClusterPt_iff _ _ _).1 hz _ this).and_eventually (eventually_gt_atTop n)).exists
refine ⟨x * (y i) ⁻¹, ?_, y i * z⁻¹, by simpa using hi, by group⟩
have I : V i ⊆ W n := iInter₂_subset n (by simp [ni])
have J : x * (y i) ⁻¹ ∈ V i := by simpa [← hvy i] using hv i
exact I J
have B : μ (((x * z ⁻¹) • k) \ k) = 0 :=
le_antisymm (ge_of_tendsto u_lim (eventually_of_forall A)) bot_le
have C : μ (k \ (z * x⁻¹) • k) = 0 := by
have : μ ((z * x⁻¹) • (((x * z ⁻¹) • k) \ k)) = 0 := by rwa [measure_smul]
rw [← this, smul_set_sdiff, smul_smul]
group
simp
by_contra H
have : k ∩ ((z * x⁻¹) • k)ᶜ ∈ 𝓝[k] z := by
apply inter_mem_nhdsWithin k
apply IsOpen.mem_nhds (by simpa using h'k.smul _)
simp only [mem_compl_iff]
contrapose! H
simpa [mem_smul_set_iff_inv_smul_mem] using H
have : 0 < μ (k \ ((z * x⁻¹) • k)) := h z zk _ this
exact lt_irrefl _ (C.le.trans_lt this)
/-- **Halmos' theorem: Haar measure is completion regular.** More precisely, any finite measure
set can be approximated from inside by a level set of a continuous function with compact support. -/
@[to_additive innerRegularWRT_preimage_one_hasCompactSupport_measure_ne_top_of_addGroup]
theorem innerRegularWRT_preimage_one_hasCompactSupport_measure_ne_top_of_group :
InnerRegularWRT μ (fun s ↦ ∃ (f : G → ℝ), Continuous f ∧ HasCompactSupport f ∧ s = f ⁻¹' {1})
(fun s ↦ MeasurableSet s ∧ μ s ≠ ∞) := by
/- First, approximate a measurable set from inside by a compact closed set `K`. Then notice that
the everywhere positive subset of `K` is a Gδ,
by Lemma `IsEverywherePos.IsGdelta_of_isMulLeftInvariant`, and therefore the level set of a
continuous compactly supported function. Moreover, it has the same measure as `K`. -/
apply InnerRegularWRT.trans _ innerRegularWRT_isCompact_isClosed_measure_ne_top_of_group
intro K ⟨K_comp, K_closed⟩ r hr
let L := μ.everywherePosSubset K
have L_comp : IsCompact L := K_comp.everywherePosSubset
have L_closed : IsClosed L := K_closed.everywherePosSubset
refine ⟨L, everywherePosSubset_subset μ K, ?_, ?_⟩
· have : μ.IsEverywherePos L :=
isEverywherePos_everywherePosSubset_of_measure_ne_top K_closed.measurableSet
K_comp.measure_lt_top.ne
have L_Gδ : IsGδ L := this.IsGdelta_of_isMulLeftInvariant L_comp L_closed
obtain ⟨⟨f, f_cont⟩, Lf, -, f_comp, -⟩ : ∃ f : C(G, ℝ), L = f ⁻¹' {1} ∧ EqOn f 0 ∅
∧ HasCompactSupport f ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 :=
exists_continuous_one_zero_of_isCompact_of_isGδ L_comp L_Gδ isClosed_empty
(disjoint_empty L)
exact ⟨f, f_cont, f_comp, Lf⟩
· convert hr using 1
apply measure_congr
exact everywherePosSubset_ae_eq_of_measure_ne_top K_closed.measurableSet
K_comp.measure_lt_top.ne
end TopologicalGroup
end Measure
end MeasureTheory
|
MeasureTheory\Measure\FiniteMeasure.lean | /-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.Topology.Algebra.Module.WeakDual
import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction
import Mathlib.MeasureTheory.Measure.HasOuterApproxClosed
/-!
# Finite measures
This file defines the type of finite measures on a given measurable space. When the underlying
space has a topology and the measurable space structure (sigma algebra) is finer than the Borel
sigma algebra, then the type of finite measures is equipped with the topology of weak convergence
of measures. The topology of weak convergence is the coarsest topology w.r.t. which
for every bounded continuous `ℝ≥0`-valued function `f`, the integration of `f` against the
measure is continuous.
## Main definitions
The main definitions are
* `MeasureTheory.FiniteMeasure Ω`: The type of finite measures on `Ω` with the topology of weak
convergence of measures.
* `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`:
Interpret a finite measure as a continuous linear functional on the space of
bounded continuous nonnegative functions on `Ω`. This is used for the definition of the
topology of weak convergence.
* `MeasureTheory.FiniteMeasure.map`: The push-forward `f* μ` of a finite measure `μ` on `Ω`
along a measurable function `f : Ω → Ω'`.
* `MeasureTheory.FiniteMeasure.mapCLM`: The push-forward along a given continuous `f : Ω → Ω'`
as a continuous linear map `f* : FiniteMeasure Ω →L[ℝ≥0] FiniteMeasure Ω'`.
## Main results
* Finite measures `μ` on `Ω` give rise to continuous linear functionals on the space of
bounded continuous nonnegative functions on `Ω` via integration:
`MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`
* `MeasureTheory.FiniteMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of finite
measures is characterized by the convergence of integrals of all bounded continuous functions.
This shows that the chosen definition of topology coincides with the common textbook definition
of weak convergence of measures. A similar characterization by the convergence of integrals (in
the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative functions is
`MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto`.
* `MeasureTheory.FiniteMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the
push-forward of finite measures `f* : FiniteMeasure Ω → FiniteMeasure Ω'` is continuous.
* `MeasureTheory.FiniteMeasure.t2Space`: The topology of weak convergence of finite Borel measures
is Hausdorff on spaces where indicators of closed sets have continuous decreasing approximating
sequences (in particular on any pseudo-metrizable spaces).
## Implementation notes
The topology of weak convergence of finite Borel measures is defined using a mapping from
`MeasureTheory.FiniteMeasure Ω` to `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)`, inheriting the topology from the
latter.
The implementation of `MeasureTheory.FiniteMeasure Ω` and is directly as a subtype of
`MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal`
and the coercion to function of `MeasureTheory.Measure Ω`. Another alternative would have been to
use a bijection with `MeasureTheory.VectorMeasure Ω ℝ≥0` as an intermediate step. Some
considerations:
* Potential advantages of using the `NNReal`-valued vector measure alternative:
* The coercion to function would avoid need to compose with `ENNReal.toNNReal`, the
`NNReal`-valued API could be more directly available.
* Potential drawbacks of the vector measure alternative:
* The coercion to function would lose monotonicity, as non-measurable sets would be defined to
have measure 0.
* No integration theory directly. E.g., the topology definition requires
`MeasureTheory.lintegral` w.r.t. a coercion to `MeasureTheory.Measure Ω` in any case.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
weak convergence of measures, finite measure
-/
noncomputable section
open MeasureTheory
open Set
open Filter
open BoundedContinuousFunction
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
namespace FiniteMeasure
section FiniteMeasure
/-! ### Finite measures
In this section we define the `Type` of `MeasureTheory.FiniteMeasure Ω`, when `Ω` is a measurable
space. Finite measures on `Ω` are a module over `ℝ≥0`.
If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma
algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.FiniteMeasure Ω` is equipped with
the topology of weak convergence of measures. This is implemented by defining a pairing of finite
measures `μ` on `Ω` with continuous bounded nonnegative functions `f : Ω →ᵇ ℝ≥0` via integration,
and using the associated weak topology (essentially the weak-star topology on the dual of
`Ω →ᵇ ℝ≥0`).
-/
variable {Ω : Type*} [MeasurableSpace Ω]
/-- Finite measures are defined as the subtype of measures that have the property of being finite
measures (i.e., their total mass is finite). -/
def _root_.MeasureTheory.FiniteMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ :=
{ μ : Measure Ω // IsFiniteMeasure μ }
-- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`, we need a new function for the
-- coercion instead of relying on `Subtype.val`.
/-- Coercion from `MeasureTheory.FiniteMeasure Ω` to `MeasureTheory.Measure Ω`. -/
@[coe]
def toMeasure : FiniteMeasure Ω → Measure Ω := Subtype.val
/-- A finite measure can be interpreted as a measure. -/
instance instCoe : Coe (FiniteMeasure Ω) (MeasureTheory.Measure Ω) where
coe := toMeasure
instance isFiniteMeasure (μ : FiniteMeasure Ω) : IsFiniteMeasure (μ : Measure Ω) :=
μ.prop
@[simp]
theorem val_eq_toMeasure (ν : FiniteMeasure Ω) : ν.val = (ν : Measure Ω) :=
rfl
theorem toMeasure_injective : Function.Injective ((↑) : FiniteMeasure Ω → Measure Ω) :=
Subtype.coe_injective
instance instFunLike : FunLike (FiniteMeasure Ω) (Set Ω) ℝ≥0 where
coe μ s := ((μ : Measure Ω) s).toNNReal
coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by
simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s
lemma coeFn_def (μ : FiniteMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl
lemma coeFn_mk (μ : Measure Ω) (hμ) :
DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl
@[simp, norm_cast]
lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) :
DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl
@[simp]
theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : FiniteMeasure Ω) (s : Set Ω) :
(ν s : ℝ≥0∞) = (ν : Measure Ω) s :=
ENNReal.coe_toNNReal (measure_lt_top (↑ν) s).ne
theorem apply_mono (μ : FiniteMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by
change ((μ : Measure Ω) s₁).toNNReal ≤ ((μ : Measure Ω) s₂).toNNReal
have key : (μ : Measure Ω) s₁ ≤ (μ : Measure Ω) s₂ := (μ : Measure Ω).mono h
apply (ENNReal.toNNReal_le_toNNReal (measure_ne_top _ s₁) (measure_ne_top _ s₂)).mpr key
/-- The (total) mass of a finite measure `μ` is `μ univ`, i.e., the cast to `NNReal` of
`(μ : measure Ω) univ`. -/
def mass (μ : FiniteMeasure Ω) : ℝ≥0 :=
μ univ
@[simp] theorem apply_le_mass (μ : FiniteMeasure Ω) (s : Set Ω) : μ s ≤ μ.mass := by
simpa using apply_mono μ (subset_univ s)
@[simp]
theorem ennreal_mass {μ : FiniteMeasure Ω} : (μ.mass : ℝ≥0∞) = (μ : Measure Ω) univ :=
ennreal_coeFn_eq_coeFn_toMeasure μ Set.univ
instance instZero : Zero (FiniteMeasure Ω) where zero := ⟨0, MeasureTheory.isFiniteMeasureZero⟩
@[simp, norm_cast] lemma coeFn_zero : ⇑(0 : FiniteMeasure Ω) = 0 := rfl
@[simp]
theorem zero_mass : (0 : FiniteMeasure Ω).mass = 0 :=
rfl
@[simp]
theorem mass_zero_iff (μ : FiniteMeasure Ω) : μ.mass = 0 ↔ μ = 0 := by
refine ⟨fun μ_mass => ?_, fun hμ => by simp only [hμ, zero_mass]⟩
apply toMeasure_injective
apply Measure.measure_univ_eq_zero.mp
rwa [← ennreal_mass, ENNReal.coe_eq_zero]
theorem mass_nonzero_iff (μ : FiniteMeasure Ω) : μ.mass ≠ 0 ↔ μ ≠ 0 := by
rw [not_iff_not]
exact FiniteMeasure.mass_zero_iff μ
@[ext]
theorem eq_of_forall_toMeasure_apply_eq (μ ν : FiniteMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by
apply Subtype.ext
ext1 s s_mble
exact h s s_mble
theorem eq_of_forall_apply_eq (μ ν : FiniteMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble
simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
instance instInhabited : Inhabited (FiniteMeasure Ω) :=
⟨0⟩
instance instAdd : Add (FiniteMeasure Ω) where add μ ν := ⟨μ + ν, MeasureTheory.isFiniteMeasureAdd⟩
variable {R : Type*} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞]
instance instSMul : SMul R (FiniteMeasure Ω) where
smul (c : R) μ := ⟨c • (μ : Measure Ω), MeasureTheory.isFiniteMeasureSMulOfNNRealTower⟩
@[simp, norm_cast]
theorem toMeasure_zero : ((↑) : FiniteMeasure Ω → Measure Ω) 0 = 0 :=
rfl
-- Porting note: with `simp` here the `coeFn` lemmas below fall prey to `simpNF`: the LHS simplifies
@[norm_cast]
theorem toMeasure_add (μ ν : FiniteMeasure Ω) : ↑(μ + ν) = (↑μ + ↑ν : Measure Ω) :=
rfl
@[simp, norm_cast]
theorem toMeasure_smul (c : R) (μ : FiniteMeasure Ω) : ↑(c • μ) = c • (μ : Measure Ω) :=
rfl
@[simp, norm_cast]
theorem coeFn_add (μ ν : FiniteMeasure Ω) : (⇑(μ + ν) : Set Ω → ℝ≥0) = (⇑μ + ⇑ν : Set Ω → ℝ≥0) := by
funext
simp only [Pi.add_apply, ← ENNReal.coe_inj, ne_eq, ennreal_coeFn_eq_coeFn_toMeasure,
ENNReal.coe_add]
norm_cast
@[simp, norm_cast]
theorem coeFn_smul [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) :
(⇑(c • μ) : Set Ω → ℝ≥0) = c • (⇑μ : Set Ω → ℝ≥0) := by
funext; simp [← ENNReal.coe_inj, ENNReal.coe_smul]
instance instAddCommMonoid : AddCommMonoid (FiniteMeasure Ω) :=
toMeasure_injective.addCommMonoid (↑) toMeasure_zero toMeasure_add fun _ _ => toMeasure_smul _ _
/-- Coercion is an `AddMonoidHom`. -/
@[simps]
def toMeasureAddMonoidHom : FiniteMeasure Ω →+ Measure Ω where
toFun := (↑)
map_zero' := toMeasure_zero
map_add' := toMeasure_add
instance {Ω : Type*} [MeasurableSpace Ω] : Module ℝ≥0 (FiniteMeasure Ω) :=
Function.Injective.module _ toMeasureAddMonoidHom toMeasure_injective toMeasure_smul
@[simp]
theorem smul_apply [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) (s : Set Ω) :
(c • μ) s = c • μ s := by
rw [coeFn_smul, Pi.smul_apply]
/-- Restrict a finite measure μ to a set A. -/
def restrict (μ : FiniteMeasure Ω) (A : Set Ω) : FiniteMeasure Ω where
val := (μ : Measure Ω).restrict A
property := MeasureTheory.isFiniteMeasureRestrict (μ : Measure Ω) A
theorem restrict_measure_eq (μ : FiniteMeasure Ω) (A : Set Ω) :
(μ.restrict A : Measure Ω) = (μ : Measure Ω).restrict A :=
rfl
theorem restrict_apply_measure (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω}
(s_mble : MeasurableSet s) : (μ.restrict A : Measure Ω) s = (μ : Measure Ω) (s ∩ A) :=
Measure.restrict_apply s_mble
theorem restrict_apply (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω} (s_mble : MeasurableSet s) :
(μ.restrict A) s = μ (s ∩ A) := by
apply congr_arg ENNReal.toNNReal
exact Measure.restrict_apply s_mble
theorem restrict_mass (μ : FiniteMeasure Ω) (A : Set Ω) : (μ.restrict A).mass = μ A := by
simp only [mass, restrict_apply μ A MeasurableSet.univ, univ_inter]
theorem restrict_eq_zero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A = 0 ↔ μ A = 0 := by
rw [← mass_zero_iff, restrict_mass]
theorem restrict_nonzero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A ≠ 0 ↔ μ A ≠ 0 := by
rw [← mass_nonzero_iff, restrict_mass]
variable [TopologicalSpace Ω]
/-- Two finite Borel measures are equal if the integrals of all bounded continuous functions with
respect to both agree. -/
theorem ext_of_forall_lintegral_eq [HasOuterApproxClosed Ω] [BorelSpace Ω]
{μ ν : FiniteMeasure Ω} (h : ∀ (f : Ω →ᵇ ℝ≥0), ∫⁻ x, f x ∂μ = ∫⁻ x, f x ∂ν) :
μ = ν := by
apply Subtype.ext
change (μ : Measure Ω) = (ν : Measure Ω)
exact ext_of_forall_lintegral_eq_of_IsFiniteMeasure h
/-- The pairing of a finite (Borel) measure `μ` with a nonnegative bounded continuous
function is obtained by (Lebesgue) integrating the (test) function against the measure.
This is `MeasureTheory.FiniteMeasure.testAgainstNN`. -/
def testAgainstNN (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : ℝ≥0 :=
(∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal
@[simp]
theorem testAgainstNN_coe_eq {μ : FiniteMeasure Ω} {f : Ω →ᵇ ℝ≥0} :
(μ.testAgainstNN f : ℝ≥0∞) = ∫⁻ ω, f ω ∂(μ : Measure Ω) :=
ENNReal.coe_toNNReal (f.lintegral_lt_top_of_nnreal _).ne
theorem testAgainstNN_const (μ : FiniteMeasure Ω) (c : ℝ≥0) :
μ.testAgainstNN (BoundedContinuousFunction.const Ω c) = c * μ.mass := by
simp [← ENNReal.coe_inj]
theorem testAgainstNN_mono (μ : FiniteMeasure Ω) {f g : Ω →ᵇ ℝ≥0} (f_le_g : (f : Ω → ℝ≥0) ≤ g) :
μ.testAgainstNN f ≤ μ.testAgainstNN g := by
simp only [← ENNReal.coe_le_coe, testAgainstNN_coe_eq]
gcongr
apply f_le_g
@[simp]
theorem testAgainstNN_zero (μ : FiniteMeasure Ω) : μ.testAgainstNN 0 = 0 := by
simpa only [zero_mul] using μ.testAgainstNN_const 0
@[simp]
theorem testAgainstNN_one (μ : FiniteMeasure Ω) : μ.testAgainstNN 1 = μ.mass := by
simp only [testAgainstNN, coe_one, Pi.one_apply, ENNReal.coe_one, lintegral_one]
rfl
@[simp]
theorem zero_testAgainstNN_apply (f : Ω →ᵇ ℝ≥0) : (0 : FiniteMeasure Ω).testAgainstNN f = 0 := by
simp only [testAgainstNN, toMeasure_zero, lintegral_zero_measure, ENNReal.zero_toNNReal]
theorem zero_testAgainstNN : (0 : FiniteMeasure Ω).testAgainstNN = 0 := by
funext
simp only [zero_testAgainstNN_apply, Pi.zero_apply]
@[simp]
theorem smul_testAgainstNN_apply (c : ℝ≥0) (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
(c • μ).testAgainstNN f = c • μ.testAgainstNN f := by
simp only [testAgainstNN, toMeasure_smul, smul_eq_mul, ← ENNReal.smul_toNNReal, ENNReal.smul_def,
lintegral_smul_measure]
section weak_convergence
variable [OpensMeasurableSpace Ω]
theorem testAgainstNN_add (μ : FiniteMeasure Ω) (f₁ f₂ : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN (f₁ + f₂) = μ.testAgainstNN f₁ + μ.testAgainstNN f₂ := by
simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_add, ENNReal.coe_add, Pi.add_apply,
testAgainstNN_coe_eq]
exact lintegral_add_left (BoundedContinuousFunction.measurable_coe_ennreal_comp _) _
theorem testAgainstNN_smul [IsScalarTower R ℝ≥0 ℝ≥0] [PseudoMetricSpace R] [Zero R]
[BoundedSMul R ℝ≥0] (μ : FiniteMeasure Ω) (c : R) (f : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN (c • f) = c • μ.testAgainstNN f := by
simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_smul, testAgainstNN_coe_eq,
ENNReal.coe_smul]
simp_rw [← smul_one_smul ℝ≥0∞ c (f _ : ℝ≥0∞), ← smul_one_smul ℝ≥0∞ c (lintegral _ _ : ℝ≥0∞),
smul_eq_mul]
exact
@lintegral_const_mul _ _ (μ : Measure Ω) (c • (1 : ℝ≥0∞)) _ f.measurable_coe_ennreal_comp
theorem testAgainstNN_lipschitz_estimate (μ : FiniteMeasure Ω) (f g : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN f ≤ μ.testAgainstNN g + nndist f g * μ.mass := by
simp only [← μ.testAgainstNN_const (nndist f g), ← testAgainstNN_add, ← ENNReal.coe_le_coe,
BoundedContinuousFunction.coe_add, const_apply, ENNReal.coe_add, Pi.add_apply,
coe_nnreal_ennreal_nndist, testAgainstNN_coe_eq]
apply lintegral_mono
have le_dist : ∀ ω, dist (f ω) (g ω) ≤ nndist f g := BoundedContinuousFunction.dist_coe_le_dist
intro ω
have le' : f ω ≤ g ω + nndist f g := by
apply (NNReal.le_add_nndist (f ω) (g ω)).trans
rw [add_le_add_iff_left]
exact dist_le_coe.mp (le_dist ω)
have le : (f ω : ℝ≥0∞) ≤ (g ω : ℝ≥0∞) + nndist f g := by
rw [← ENNReal.coe_add]
exact ENNReal.coe_mono le'
rwa [coe_nnreal_ennreal_nndist] at le
theorem testAgainstNN_lipschitz (μ : FiniteMeasure Ω) :
LipschitzWith μ.mass fun f : Ω →ᵇ ℝ≥0 => μ.testAgainstNN f := by
rw [lipschitzWith_iff_dist_le_mul]
intro f₁ f₂
suffices abs (μ.testAgainstNN f₁ - μ.testAgainstNN f₂ : ℝ) ≤ μ.mass * dist f₁ f₂ by
rwa [NNReal.dist_eq]
apply abs_le.mpr
constructor
· have key' := μ.testAgainstNN_lipschitz_estimate f₂ f₁
rw [mul_comm] at key'
suffices ↑(μ.testAgainstNN f₂) ≤ ↑(μ.testAgainstNN f₁) + ↑μ.mass * dist f₁ f₂ by linarith
have key := NNReal.coe_mono key'
rwa [NNReal.coe_add, NNReal.coe_mul, nndist_comm] at key
· have key' := μ.testAgainstNN_lipschitz_estimate f₁ f₂
rw [mul_comm] at key'
suffices ↑(μ.testAgainstNN f₁) ≤ ↑(μ.testAgainstNN f₂) + ↑μ.mass * dist f₁ f₂ by linarith
have key := NNReal.coe_mono key'
rwa [NNReal.coe_add, NNReal.coe_mul] at key
/-- Finite measures yield elements of the `WeakDual` of bounded continuous nonnegative
functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/
def toWeakDualBCNN (μ : FiniteMeasure Ω) : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) where
toFun f := μ.testAgainstNN f
map_add' := testAgainstNN_add μ
map_smul' := testAgainstNN_smul μ
cont := μ.testAgainstNN_lipschitz.continuous
@[simp]
theorem coe_toWeakDualBCNN (μ : FiniteMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.testAgainstNN :=
rfl
@[simp]
theorem toWeakDualBCNN_apply (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
μ.toWeakDualBCNN f = (∫⁻ x, f x ∂(μ : Measure Ω)).toNNReal :=
rfl
/-- The topology of weak convergence on `MeasureTheory.FiniteMeasure Ω` is inherited (induced)
from the weak-* topology on `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)` via the function
`MeasureTheory.FiniteMeasure.toWeakDualBCNN`. -/
instance instTopologicalSpace : TopologicalSpace (FiniteMeasure Ω) :=
TopologicalSpace.induced toWeakDualBCNN inferInstance
theorem toWeakDualBCNN_continuous : Continuous (@toWeakDualBCNN Ω _ _ _) :=
continuous_induced_dom
/-- Integration of (nonnegative bounded continuous) test functions against finite Borel measures
depends continuously on the measure. -/
theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) :
Continuous fun μ : FiniteMeasure Ω => μ.testAgainstNN f := by
show Continuous ((fun φ : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) => φ f) ∘ toWeakDualBCNN)
refine Continuous.comp ?_ (toWeakDualBCNN_continuous (Ω := Ω))
exact WeakBilin.eval_continuous (𝕜 := ℝ≥0) (E := (Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0) _ _
/- porting note: without explicitly providing `𝕜` and `E` TC synthesis times
out trying to find `Module ℝ≥0 ((Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0)`, but it can find it with enough time:
`set_option synthInstance.maxHeartbeats 47000` was sufficient. -/
/-- The total mass of a finite measure depends continuously on the measure. -/
theorem continuous_mass : Continuous fun μ : FiniteMeasure Ω => μ.mass := by
simp_rw [← testAgainstNN_one]; exact continuous_testAgainstNN_eval 1
/-- Convergence of finite measures implies the convergence of their total masses. -/
theorem _root_.Filter.Tendsto.mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} (h : Tendsto μs F (𝓝 μ)) : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass) :=
(continuous_mass.tendsto μ).comp h
theorem tendsto_iff_weak_star_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔ Tendsto (fun i => (μs i).toWeakDualBCNN) F (𝓝 μ.toWeakDualBCNN) :=
Inducing.tendsto_nhds_iff ⟨rfl⟩
theorem tendsto_iff_forall_toWeakDualBCNN_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).toWeakDualBCNN f) F (𝓝 (μ.toWeakDualBCNN f)) := by
rw [tendsto_iff_weak_star_tendsto, tendsto_iff_forall_eval_tendsto_topDualPairing]; rfl
theorem tendsto_iff_forall_testAgainstNN_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
rw [FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto]; rfl
/-- If the total masses of finite measures tend to zero, then the measures tend to
zero. This formulation concerns the associated functionals on bounded continuous
nonnegative test functions. See `MeasureTheory.FiniteMeasure.tendsto_zero_of_tendsto_zero_mass` for
a formulation stating the weak convergence of measures. -/
theorem tendsto_zero_testAgainstNN_of_tendsto_zero_mass {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 0) := by
apply tendsto_iff_dist_tendsto_zero.mpr
have obs := fun i => (μs i).testAgainstNN_lipschitz_estimate f 0
simp_rw [testAgainstNN_zero, zero_add] at obs
simp_rw [show ∀ i, dist ((μs i).testAgainstNN f) 0 = (μs i).testAgainstNN f by
simp only [dist_nndist, NNReal.nndist_zero_eq_val', eq_self_iff_true, imp_true_iff]]
refine squeeze_zero (fun i => NNReal.coe_nonneg _) obs ?_
have lim_pair : Tendsto (fun i => (⟨nndist f 0, (μs i).mass⟩ : ℝ × ℝ)) F (𝓝 ⟨nndist f 0, 0⟩) := by
refine (Prod.tendsto_iff _ _).mpr ⟨tendsto_const_nhds, ?_⟩
exact (NNReal.continuous_coe.tendsto 0).comp mass_lim
have key := tendsto_mul.comp lim_pair
rwa [mul_zero] at key
/-- If the total masses of finite measures tend to zero, then the measures tend to zero. -/
theorem tendsto_zero_of_tendsto_zero_mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
(mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) : Tendsto μs F (𝓝 0) := by
rw [tendsto_iff_forall_testAgainstNN_tendsto]
intro f
convert tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
rw [zero_testAgainstNN_apply]
/-- A characterization of weak convergence in terms of integrals of bounded continuous
nonnegative functions. -/
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0,
Tendsto (fun i => ∫⁻ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ x, f x ∂(μ : Measure Ω))) := by
rw [tendsto_iff_forall_toWeakDualBCNN_tendsto]
simp_rw [toWeakDualBCNN_apply _ _, ← testAgainstNN_coe_eq, ENNReal.tendsto_coe,
ENNReal.toNNReal_coe]
end weak_convergence -- section
section Hausdorff
variable [HasOuterApproxClosed Ω] [BorelSpace Ω]
open Function
/-- The mapping `toWeakDualBCNN` from finite Borel measures to the weak dual of `Ω →ᵇ ℝ≥0` is
injective, if in the underlying space `Ω`, indicator functions of closed sets have decreasing
approximations by sequences of continuous functions (in particular if `Ω` is pseudometrizable). -/
lemma injective_toWeakDualBCNN :
Injective (toWeakDualBCNN : FiniteMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)) := by
intro μ ν hμν
apply ext_of_forall_lintegral_eq
intro f
have key := congr_fun (congrArg DFunLike.coe hμν) f
apply (ENNReal.toNNReal_eq_toNNReal_iff' ?_ ?_).mp key
· exact (lintegral_lt_top_of_nnreal μ f).ne
· exact (lintegral_lt_top_of_nnreal ν f).ne
variable (Ω)
lemma embedding_toWeakDualBCNN :
Embedding (toWeakDualBCNN : FiniteMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)) where
induced := rfl
inj := injective_toWeakDualBCNN
/-- On topological spaces where indicators of closed sets have decreasing approximating sequences of
continuous functions (`HasOuterApproxClosed`), the topology of weak convergence of finite Borel
measures is Hausdorff (`T2Space`). -/
instance t2Space : T2Space (FiniteMeasure Ω) :=
Embedding.t2Space (embedding_toWeakDualBCNN Ω)
end Hausdorff -- section
end FiniteMeasure
-- section
section FiniteMeasureBoundedConvergence
/-! ### Bounded convergence results for finite measures
This section is about bounded convergence theorems for finite measures.
-/
variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
/-- A bounded convergence theorem for a finite measure:
If a sequence of bounded continuous non-negative functions are uniformly bounded by a constant
and tend pointwise to a limit, then their integrals (`MeasureTheory.lintegral`) against the finite
measure tend to the integral of the limit.
A related result with more general assumptions is
`MeasureTheory.tendsto_lintegral_nn_filter_of_le_const`.
-/
theorem tendsto_lintegral_nn_of_le_const (μ : FiniteMeasure Ω) {fs : ℕ → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ n ω, fs n ω ≤ c) {f : Ω → ℝ≥0}
(fs_lim : ∀ ω, Tendsto (fun n => fs n ω) atTop (𝓝 (f ω))) :
Tendsto (fun n => ∫⁻ ω, fs n ω ∂(μ : Measure Ω)) atTop (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) :=
tendsto_lintegral_nn_filter_of_le_const μ
(eventually_of_forall fun n => eventually_of_forall (fs_le_const n))
(eventually_of_forall fs_lim)
/-- A bounded convergence theorem for a finite measure:
If bounded continuous non-negative functions are uniformly bounded by a constant and tend to a
limit, then their integrals against the finite measure tend to the integral of the limit.
This formulation assumes:
* the functions tend to a limit along a countably generated filter;
* the limit is in the almost everywhere sense;
* boundedness holds almost everywhere;
* integration is the pairing against non-negative continuous test functions
(`MeasureTheory.FiniteMeasure.testAgainstNN`).
A related result using `MeasureTheory.lintegral` for integration is
`MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_filter_of_le_const`.
-/
theorem tendsto_testAgainstNN_filter_of_le_const {ι : Type*} {L : Filter ι}
[L.IsCountablyGenerated] {μ : FiniteMeasure Ω} {fs : ι → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂(μ : Measure Ω), fs i ω ≤ c) {f : Ω →ᵇ ℝ≥0}
(fs_lim : ∀ᵐ ω : Ω ∂(μ : Measure Ω), Tendsto (fun i => fs i ω) L (𝓝 (f ω))) :
Tendsto (fun i => μ.testAgainstNN (fs i)) L (𝓝 (μ.testAgainstNN f)) := by
apply (ENNReal.tendsto_toNNReal (f.lintegral_lt_top_of_nnreal (μ : Measure Ω)).ne).comp
exact tendsto_lintegral_nn_filter_of_le_const μ fs_le_const fs_lim
/-- A bounded convergence theorem for a finite measure:
If a sequence of bounded continuous non-negative functions are uniformly bounded by a constant and
tend pointwise to a limit, then their integrals (`MeasureTheory.FiniteMeasure.testAgainstNN`)
against the finite measure tend to the integral of the limit.
Related results:
* `MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_filter_of_le_const`:
more general assumptions
* `MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_of_le_const`:
using `MeasureTheory.lintegral` for integration.
-/
theorem tendsto_testAgainstNN_of_le_const {μ : FiniteMeasure Ω} {fs : ℕ → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ n ω, fs n ω ≤ c) {f : Ω →ᵇ ℝ≥0}
(fs_lim : ∀ ω, Tendsto (fun n => fs n ω) atTop (𝓝 (f ω))) :
Tendsto (fun n => μ.testAgainstNN (fs n)) atTop (𝓝 (μ.testAgainstNN f)) :=
tendsto_testAgainstNN_filter_of_le_const
(eventually_of_forall fun n => eventually_of_forall (fs_le_const n))
(eventually_of_forall fs_lim)
end FiniteMeasureBoundedConvergence
-- section
section FiniteMeasureConvergenceByBoundedContinuousFunctions
/-! ### Weak convergence of finite measures with bounded continuous real-valued functions
In this section we characterize the weak convergence of finite measures by the usual (defining)
condition that the integrals of all bounded continuous real-valued functions converge.
-/
variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
theorem tendsto_of_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω}
(h :
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i => ∫ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫ x, f x ∂(μ : Measure Ω)))) :
Tendsto μs F (𝓝 μ) := by
apply (@tendsto_iff_forall_lintegral_tendsto Ω _ _ _ γ F μs μ).mpr
intro f
have key :=
@ENNReal.tendsto_toReal_iff _ F _
(fun i => (f.lintegral_lt_top_of_nnreal (μs i)).ne) _ (f.lintegral_lt_top_of_nnreal μ).ne
simp only [ENNReal.ofReal_coe_nnreal] at key
apply key.mp
have lip : LipschitzWith 1 ((↑) : ℝ≥0 → ℝ) := isometry_subtype_coe.lipschitz
set f₀ := BoundedContinuousFunction.comp _ lip f with _def_f₀
have f₀_eq : ⇑f₀ = ((↑) : ℝ≥0 → ℝ) ∘ ⇑f := rfl
have f₀_nn : 0 ≤ ⇑f₀ := fun _ => by
simp only [f₀_eq, Pi.zero_apply, Function.comp_apply, NNReal.zero_le_coe]
have f₀_ae_nn : 0 ≤ᵐ[(μ : Measure Ω)] ⇑f₀ := eventually_of_forall f₀_nn
have f₀_ae_nns : ∀ i, 0 ≤ᵐ[(μs i : Measure Ω)] ⇑f₀ := fun i => eventually_of_forall f₀_nn
have aux :=
integral_eq_lintegral_of_nonneg_ae f₀_ae_nn f₀.continuous.measurable.aestronglyMeasurable
have auxs := fun i =>
integral_eq_lintegral_of_nonneg_ae (f₀_ae_nns i) f₀.continuous.measurable.aestronglyMeasurable
simp_rw [f₀_eq, Function.comp_apply, ENNReal.ofReal_coe_nnreal] at aux auxs
simpa only [← aux, ← auxs] using h f₀
/-- A characterization of weak convergence in terms of integrals of bounded continuous
real-valued functions. -/
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i => ∫ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫ x, f x ∂(μ : Measure Ω))) := by
refine ⟨?_, tendsto_of_forall_integral_tendsto⟩
rw [tendsto_iff_forall_lintegral_tendsto]
intro h f
simp_rw [BoundedContinuousFunction.integral_eq_integral_nnrealPart_sub]
set f_pos := f.nnrealPart with _def_f_pos
set f_neg := (-f).nnrealPart with _def_f_neg
have tends_pos := (ENNReal.tendsto_toReal (f_pos.lintegral_lt_top_of_nnreal μ).ne).comp (h f_pos)
have tends_neg := (ENNReal.tendsto_toReal (f_neg.lintegral_lt_top_of_nnreal μ).ne).comp (h f_neg)
have aux :
∀ g : Ω →ᵇ ℝ≥0,
(ENNReal.toReal ∘ fun i : γ => ∫⁻ x : Ω, ↑(g x) ∂(μs i : Measure Ω)) = fun i : γ =>
(∫⁻ x : Ω, ↑(g x) ∂(μs i : Measure Ω)).toReal :=
fun _ => rfl
simp_rw [aux, BoundedContinuousFunction.toReal_lintegral_coe_eq_integral] at tends_pos tends_neg
exact Tendsto.sub tends_pos tends_neg
end FiniteMeasureConvergenceByBoundedContinuousFunctions -- section
section map
variable {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω']
/-- The push-forward of a finite measure by a function between measurable spaces. -/
noncomputable def map (ν : FiniteMeasure Ω) (f : Ω → Ω') : FiniteMeasure Ω' :=
⟨(ν : Measure Ω).map f, by
constructor
by_cases f_aemble : AEMeasurable f ν
· rw [Measure.map_apply_of_aemeasurable f_aemble MeasurableSet.univ]
exact measure_lt_top (↑ν) (f ⁻¹' univ)
· simp [Measure.map, f_aemble]⟩
@[simp] lemma toMeasure_map (ν : FiniteMeasure Ω) (f : Ω → Ω') :
(ν.map f).toMeasure = ν.toMeasure.map f := rfl
/-- Note that this is an equality of elements of `ℝ≥0∞`. See also
`MeasureTheory.FiniteMeasure.map_apply` for the corresponding equality as elements of `ℝ≥0`. -/
lemma map_apply' (ν : FiniteMeasure Ω) {f : Ω → Ω'} (f_aemble : AEMeasurable f ν)
{A : Set Ω'} (A_mble : MeasurableSet A) :
(ν.map f : Measure Ω') A = (ν : Measure Ω) (f ⁻¹' A) :=
Measure.map_apply_of_aemeasurable f_aemble A_mble
lemma map_apply_of_aemeasurable (ν : FiniteMeasure Ω) {f : Ω → Ω'} (f_aemble : AEMeasurable f ν)
{A : Set Ω'} (A_mble : MeasurableSet A) :
ν.map f A = ν (f ⁻¹' A) := by
have := ν.map_apply' f_aemble A_mble
exact (ENNReal.toNNReal_eq_toNNReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mpr this
lemma map_apply (ν : FiniteMeasure Ω) {f : Ω → Ω'} (f_mble : Measurable f)
{A : Set Ω'} (A_mble : MeasurableSet A) :
ν.map f A = ν (f ⁻¹' A) :=
map_apply_of_aemeasurable ν f_mble.aemeasurable A_mble
@[simp] lemma map_add {f : Ω → Ω'} (f_mble : Measurable f) (ν₁ ν₂ : FiniteMeasure Ω) :
(ν₁ + ν₂).map f = ν₁.map f + ν₂.map f := by
ext s s_mble
simp only [map_apply' _ f_mble.aemeasurable s_mble, toMeasure_add, Measure.add_apply]
@[simp] lemma map_smul {f : Ω → Ω'} (c : ℝ≥0) (ν : FiniteMeasure Ω) :
(c • ν).map f = c • (ν.map f) := by
ext s _
simp [toMeasure_smul]
/-- The push-forward of a finite measure by a function between measurable spaces as a linear map. -/
noncomputable def mapHom {f : Ω → Ω'} (f_mble : Measurable f) :
FiniteMeasure Ω →ₗ[ℝ≥0] FiniteMeasure Ω' where
toFun := fun ν ↦ ν.map f
map_add' := map_add f_mble
map_smul' := map_smul
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
variable [TopologicalSpace Ω'] [BorelSpace Ω']
/-- If `f : X → Y` is continuous and `Y` is equipped with the Borel sigma algebra, then
(weak) convergence of `FiniteMeasure`s on `X` implies (weak) convergence of the push-forwards
of these measures by `f`. -/
lemma tendsto_map_of_tendsto_of_continuous {ι : Type*} {L : Filter ι}
(νs : ι → FiniteMeasure Ω) (ν : FiniteMeasure Ω) (lim : Tendsto νs L (𝓝 ν))
{f : Ω → Ω'} (f_cont : Continuous f) :
Tendsto (fun i ↦ (νs i).map f) L (𝓝 (ν.map f)) := by
rw [FiniteMeasure.tendsto_iff_forall_lintegral_tendsto] at lim ⊢
intro g
convert lim (g.compContinuous ⟨f, f_cont⟩) <;>
· simp only [map, compContinuous_apply, ContinuousMap.coe_mk]
refine lintegral_map ?_ f_cont.measurable
exact (ENNReal.continuous_coe.comp g.continuous).measurable
/-- If `f : X → Y` is continuous and `Y` is equipped with the Borel sigma algebra, then
the push-forward of finite measures `f* : FiniteMeasure X → FiniteMeasure Y` is continuous
(in the topologies of weak convergence of measures). -/
lemma continuous_map {f : Ω → Ω'} (f_cont : Continuous f) :
Continuous (fun ν ↦ FiniteMeasure.map ν f) := by
rw [continuous_iff_continuousAt]
exact fun _ ↦ tendsto_map_of_tendsto_of_continuous _ _ continuous_id.continuousAt f_cont
/-- The push-forward of a finite measure by a continuous function between Borel spaces as
a continuous linear map. -/
noncomputable def mapCLM {f : Ω → Ω'} (f_cont : Continuous f) :
FiniteMeasure Ω →L[ℝ≥0] FiniteMeasure Ω' where
toFun := fun ν ↦ ν.map f
map_add' := map_add f_cont.measurable
map_smul' := map_smul
cont := continuous_map f_cont
end map -- section
end FiniteMeasure -- namespace
end MeasureTheory -- namespace
|
MeasureTheory\Measure\FiniteMeasureProd.lean | /-
Copyright (c) 2023 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
import Mathlib.MeasureTheory.Constructions.Prod.Basic
/-!
# Products of finite measures and probability measures
This file introduces binary products of finite measures and probability measures. The constructions
are obtained from special cases of products of general measures. Taking products nevertheless has
specific properties in the cases of finite measures and probability measures, notably the fact that
the product measures depend continuously on their factors in the topology of weak convergence when
the underlying space is metrizable and separable.
## Main definitions
* `MeasureTheory.FiniteMeasure.prod`: The product of two finite measures.
* `MeasureTheory.ProbabilityMeasure.prod`: The product of two probability measures.
## TODO
* Add continuous dependence of the product measures on the factors.
-/
open MeasureTheory Topology Metric Filter Set ENNReal NNReal
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
section FiniteMeasure_product
namespace FiniteMeasure
variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β]
/-- The binary product of finite measures. -/
noncomputable def prod (μ : FiniteMeasure α) (ν : FiniteMeasure β) : FiniteMeasure (α × β) :=
⟨μ.toMeasure.prod ν.toMeasure, inferInstance⟩
variable (μ : FiniteMeasure α) (ν : FiniteMeasure β)
@[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl
lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by
simp [coeFn_def, Measure.prod_apply s_mble]
lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by
simp [coeFn_def, Measure.prod_apply_symm s_mble]
lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def]
@[simp] lemma mass_prod : (μ.prod ν).mass = μ.mass * ν.mass := by
simp only [coeFn_def, mass, univ_prod_univ.symm, toMeasure_prod]
rw [← ENNReal.toNNReal_mul]
exact congr_arg ENNReal.toNNReal (Measure.prod_prod univ univ)
@[simp] lemma zero_prod : (0 : FiniteMeasure α).prod ν = 0 := by
rw [← mass_zero_iff, mass_prod, zero_mass, zero_mul]
@[simp] lemma prod_zero : μ.prod (0 : FiniteMeasure β) = 0 := by
rw [← mass_zero_iff, mass_prod, zero_mass, mul_zero]
@[simp] lemma map_fst_prod : (μ.prod ν).map Prod.fst = ν univ • μ := by ext; simp
@[simp] lemma map_snd_prod : (μ.prod ν).map Prod.snd = μ univ • ν := by ext; simp
lemma map_prod_map {α' : Type*} [MeasurableSpace α'] {β' : Type*} [MeasurableSpace β']
{f : α → α'} {g : β → β'} (f_mble : Measurable f) (g_mble : Measurable g) :
(μ.map f).prod (ν.map g) = (μ.prod ν).map (Prod.map f g) := by
apply Subtype.ext
simp only [val_eq_toMeasure, toMeasure_prod, toMeasure_map]
rw [Measure.map_prod_map _ _ f_mble g_mble]
lemma prod_swap : (μ.prod ν).map Prod.swap = ν.prod μ := by
apply Subtype.ext
simp [Measure.prod_swap]
end FiniteMeasure -- namespace
end FiniteMeasure_product -- section
section ProbabilityMeasure_product
namespace ProbabilityMeasure
variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β]
/-- The binary product of probability measures. -/
noncomputable def prod (μ : ProbabilityMeasure α) (ν : ProbabilityMeasure β) :
ProbabilityMeasure (α × β) :=
⟨μ.toMeasure.prod ν.toMeasure, by infer_instance⟩
variable (μ : ProbabilityMeasure α) (ν : ProbabilityMeasure β)
@[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl
lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by
simp [coeFn_def, Measure.prod_apply s_mble]
lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by
simp [coeFn_def, Measure.prod_apply_symm s_mble]
lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def]
/-- The first marginal of a product probability measure is the first probability measure. -/
@[simp] lemma map_fst_prod : (μ.prod ν).map measurable_fst.aemeasurable = μ := by
apply Subtype.ext
simp only [val_eq_to_measure, toMeasure_map, toMeasure_prod, Measure.map_fst_prod,
measure_univ, one_smul]
/-- The second marginal of a product probability measure is the second probability measure. -/
@[simp] lemma map_snd_prod : (μ.prod ν).map measurable_snd.aemeasurable = ν := by
apply Subtype.ext
simp only [val_eq_to_measure, toMeasure_map, toMeasure_prod, Measure.map_snd_prod,
measure_univ, one_smul]
lemma map_prod_map {α' : Type*} [MeasurableSpace α'] {β' : Type*} [MeasurableSpace β']
{f : α → α'} {g : β → β'} (f_mble : Measurable f) (g_mble : Measurable g) :
(μ.map f_mble.aemeasurable).prod (ν.map g_mble.aemeasurable)
= (μ.prod ν).map (f_mble.prod_map g_mble).aemeasurable := by
apply Subtype.ext
simp only [val_eq_to_measure, toMeasure_prod, toMeasure_map]
rw [Measure.map_prod_map _ _ f_mble g_mble]
lemma prod_swap : (μ.prod ν).map measurable_swap.aemeasurable = ν.prod μ := by
apply Subtype.ext
simp [Measure.prod_swap]
end ProbabilityMeasure -- namespace
end ProbabilityMeasure_product -- section
end MeasureTheory -- namespace
|
MeasureTheory\Measure\GiryMonad.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.MeasureTheory.Integral.Lebesgue
/-!
# The Giry monad
Let X be a measurable space. The collection of all measures on X again
forms a measurable space. This construction forms a monad on
measurable spaces and measurable functions, called the Giry monad.
Note that most sources use the term "Giry monad" for the restriction
to *probability* measures. Here we include all measures on X.
See also `MeasureTheory/Category/MeasCat.lean`, containing an upgrade of the type-level
monad to an honest monad of the functor `measure : MeasCat ⥤ MeasCat`.
## References
* <https://ncatlab.org/nlab/show/Giry+monad>
## Tags
giry monad
-/
noncomputable section
open ENNReal Set Filter
variable {α β : Type*}
namespace MeasureTheory
namespace Measure
variable [MeasurableSpace α] [MeasurableSpace β]
/-- Measurability structure on `Measure`: Measures are measurable w.r.t. all projections -/
instance instMeasurableSpace : MeasurableSpace (Measure α) :=
⨆ (s : Set α) (_ : MeasurableSet s), (borel ℝ≥0∞).comap fun μ => μ s
theorem measurable_coe {s : Set α} (hs : MeasurableSet s) : Measurable fun μ : Measure α => μ s :=
Measurable.of_comap_le <| le_iSup_of_le s <| le_iSup_of_le hs <| le_rfl
theorem measurable_of_measurable_coe (f : β → Measure α)
(h : ∀ (s : Set α), MeasurableSet s → Measurable fun b => f b s) : Measurable f :=
Measurable.of_le_map <|
iSup₂_le fun s hs =>
MeasurableSpace.comap_le_iff_le_map.2 <| by rw [MeasurableSpace.map_comp]; exact h s hs
instance instMeasurableAdd₂ {α : Type*} {m : MeasurableSpace α} : MeasurableAdd₂ (Measure α) := by
refine ⟨Measure.measurable_of_measurable_coe _ fun s hs => ?_⟩
simp_rw [Measure.coe_add, Pi.add_apply]
refine Measurable.add ?_ ?_
· exact (Measure.measurable_coe hs).comp measurable_fst
· exact (Measure.measurable_coe hs).comp measurable_snd
theorem measurable_measure {μ : α → Measure β} :
Measurable μ ↔ ∀ (s : Set β), MeasurableSet s → Measurable fun b => μ b s :=
⟨fun hμ _s hs => (measurable_coe hs).comp hμ, measurable_of_measurable_coe μ⟩
theorem measurable_map (f : α → β) (hf : Measurable f) :
Measurable fun μ : Measure α => map f μ := by
refine measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [map_apply hf hs]
exact measurable_coe (hf hs)
theorem measurable_dirac : Measurable (Measure.dirac : α → Measure α) := by
refine measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [dirac_apply' _ hs]
exact measurable_one.indicator hs
theorem measurable_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) :
Measurable fun μ : Measure α => ∫⁻ x, f x ∂μ := by
simp only [lintegral_eq_iSup_eapprox_lintegral, hf, SimpleFunc.lintegral]
refine measurable_iSup fun n => Finset.measurable_sum _ fun i _ => ?_
refine Measurable.const_mul ?_ _
exact measurable_coe ((SimpleFunc.eapprox f n).measurableSet_preimage _)
/-- Monadic join on `Measure` in the category of measurable spaces and measurable
functions. -/
def join (m : Measure (Measure α)) : Measure α :=
Measure.ofMeasurable (fun s _ => ∫⁻ μ, μ s ∂m)
(by simp only [measure_empty, lintegral_const, zero_mul])
(by
intro f hf h
simp_rw [measure_iUnion h hf]
apply lintegral_tsum
intro i; exact (measurable_coe (hf i)).aemeasurable)
@[simp]
theorem join_apply {m : Measure (Measure α)} {s : Set α} (hs : MeasurableSet s) :
join m s = ∫⁻ μ, μ s ∂m :=
Measure.ofMeasurable_apply s hs
@[simp]
theorem join_zero : (0 : Measure (Measure α)).join = 0 := by
ext1 s hs
simp only [hs, join_apply, lintegral_zero_measure, coe_zero, Pi.zero_apply]
theorem measurable_join : Measurable (join : Measure (Measure α) → Measure α) :=
measurable_of_measurable_coe _ fun s hs => by
simp only [join_apply hs]; exact measurable_lintegral (measurable_coe hs)
theorem lintegral_join {m : Measure (Measure α)} {f : α → ℝ≥0∞} (hf : Measurable f) :
∫⁻ x, f x ∂join m = ∫⁻ μ, ∫⁻ x, f x ∂μ ∂m := by
simp_rw [lintegral_eq_iSup_eapprox_lintegral hf, SimpleFunc.lintegral,
join_apply (SimpleFunc.measurableSet_preimage _ _)]
suffices
∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞), (∀ n r, Measurable (f n r)) →
Monotone (fun n μ => ∑ r ∈ s n, r * f n r μ) →
⨆ n, ∑ r ∈ s n, r * ∫⁻ μ, f n r μ ∂m = ∫⁻ μ, ⨆ n, ∑ r ∈ s n, r * f n r μ ∂m by
refine
this (fun n => SimpleFunc.range (SimpleFunc.eapprox f n))
(fun n r μ => μ (SimpleFunc.eapprox f n ⁻¹' {r})) ?_ ?_
· exact fun n r => measurable_coe (SimpleFunc.measurableSet_preimage _ _)
· exact fun n m h μ => SimpleFunc.lintegral_mono (SimpleFunc.monotone_eapprox _ h) le_rfl
intro s f hf hm
rw [lintegral_iSup _ hm]
swap
· exact fun n => Finset.measurable_sum _ fun r _ => (hf _ _).const_mul _
congr
funext n
rw [lintegral_finset_sum (s n)]
· simp_rw [lintegral_const_mul _ (hf _ _)]
· exact fun r _ => (hf _ _).const_mul _
/-- Monadic bind on `Measure`, only works in the category of measurable spaces and measurable
functions. When the function `f` is not measurable the result is not well defined. -/
def bind (m : Measure α) (f : α → Measure β) : Measure β :=
join (map f m)
@[simp]
theorem bind_zero_left (f : α → Measure β) : bind 0 f = 0 := by simp [bind]
@[simp]
theorem bind_zero_right (m : Measure α) : bind m (0 : α → Measure β) = 0 := by
ext1 s hs
simp only [bind, hs, join_apply, coe_zero, Pi.zero_apply]
rw [lintegral_map (measurable_coe hs) measurable_zero]
simp only [Pi.zero_apply, coe_zero, lintegral_const, zero_mul]
@[simp]
theorem bind_zero_right' (m : Measure α) : bind m (fun _ => 0 : α → Measure β) = 0 :=
bind_zero_right m
@[simp]
theorem bind_apply {m : Measure α} {f : α → Measure β} {s : Set β} (hs : MeasurableSet s)
(hf : Measurable f) : bind m f s = ∫⁻ a, f a s ∂m := by
rw [bind, join_apply hs, lintegral_map (measurable_coe hs) hf]
theorem measurable_bind' {g : α → Measure β} (hg : Measurable g) : Measurable fun m => bind m g :=
measurable_join.comp (measurable_map _ hg)
theorem lintegral_bind {m : Measure α} {μ : α → Measure β} {f : β → ℝ≥0∞} (hμ : Measurable μ)
(hf : Measurable f) : ∫⁻ x, f x ∂bind m μ = ∫⁻ a, ∫⁻ x, f x ∂μ a ∂m :=
(lintegral_join hf).trans (lintegral_map (measurable_lintegral hf) hμ)
theorem bind_bind {γ} [MeasurableSpace γ] {m : Measure α} {f : α → Measure β} {g : β → Measure γ}
(hf : Measurable f) (hg : Measurable g) : bind (bind m f) g = bind m fun a => bind (f a) g := by
ext1 s hs
erw [bind_apply hs hg, bind_apply hs ((measurable_bind' hg).comp hf),
lintegral_bind hf ((measurable_coe hs).comp hg)]
conv_rhs => enter [2, a]; erw [bind_apply hs hg]
rfl
theorem bind_dirac {f : α → Measure β} (hf : Measurable f) (a : α) : bind (dirac a) f = f a := by
ext1 s hs
erw [bind_apply hs hf, lintegral_dirac' a ((measurable_coe hs).comp hf)]
rfl
theorem dirac_bind {m : Measure α} : bind m dirac = m := by
ext1 s hs
simp only [bind_apply hs measurable_dirac, dirac_apply' _ hs, lintegral_indicator 1 hs,
Pi.one_apply, lintegral_one, restrict_apply, MeasurableSet.univ, univ_inter]
theorem join_eq_bind (μ : Measure (Measure α)) : join μ = bind μ id := by rw [bind, map_id]
theorem join_map_map {f : α → β} (hf : Measurable f) (μ : Measure (Measure α)) :
join (map (map f) μ) = map f (join μ) := by
ext1 s hs
rw [join_apply hs, map_apply hf hs, join_apply (hf hs),
lintegral_map (measurable_coe hs) (measurable_map f hf)]
simp_rw [map_apply hf hs]
theorem join_map_join (μ : Measure (Measure (Measure α))) : join (map join μ) = join (join μ) := by
show bind μ join = join (join μ)
rw [join_eq_bind, join_eq_bind, bind_bind measurable_id measurable_id]
apply congr_arg (bind μ)
funext ν
exact join_eq_bind ν
theorem join_map_dirac (μ : Measure α) : join (map dirac μ) = μ :=
dirac_bind
theorem join_dirac (μ : Measure α) : join (dirac μ) = μ :=
(join_eq_bind (dirac μ)).trans (bind_dirac measurable_id _)
end Measure
end MeasureTheory
|
MeasureTheory\Measure\HasOuterApproxClosed.lean | /-
Copyright (c) 2022 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Integral.Lebesgue
import Mathlib.Topology.MetricSpace.ThickenedIndicator
/-!
# Spaces where indicators of closed sets have decreasing approximations by continuous functions
In this file we define a typeclass `HasOuterApproxClosed` for topological spaces in which indicator
functions of closed sets have sequences of bounded continuous functions approximating them from
above. All pseudo-emetrizable spaces have this property, see `instHasOuterApproxClosed`.
In spaces with the `HasOuterApproxClosed` property, finite Borel measures are uniquely characterized
by the integrals of bounded continuous functions. Also weak convergence of finite measures and
convergence in distribution for random variables behave somewhat well in spaces with this property.
## Main definitions
* `HasOuterApproxClosed`: the typeclass for topological spaces in which indicator functions of
closed sets have sequences of bounded continuous functions approximating them.
* `IsClosed.apprSeq`: a (non-constructive) choice of an approximating sequence to the indicator
function of a closed set.
## Main results
* `instHasOuterApproxClosed`: Any pseudo-emetrizable space has the property `HasOuterApproxClosed`.
* `tendsto_lintegral_apprSeq`: The integrals of the approximating functions to the indicator of a
closed set tend to the measure of the set.
* `ext_of_forall_lintegral_eq_of_IsFiniteMeasure`: Two finite measures are equal if the integrals
of all bounded continuous functions with respect to both agree.
-/
open MeasureTheory Topology Metric Filter Set ENNReal NNReal
open scoped Topology ENNReal NNReal BoundedContinuousFunction
section auxiliary
namespace MeasureTheory
variable {Ω : Type*} [TopologicalSpace Ω] [MeasurableSpace Ω] [OpensMeasurableSpace Ω]
/-- A bounded convergence theorem for a finite measure:
If bounded continuous non-negative functions are uniformly bounded by a constant and tend to a
limit, then their integrals against the finite measure tend to the integral of the limit.
This formulation assumes:
* the functions tend to a limit along a countably generated filter;
* the limit is in the almost everywhere sense;
* boundedness holds almost everywhere;
* integration is `MeasureTheory.lintegral`, i.e., the functions and their integrals are
`ℝ≥0∞`-valued.
-/
theorem tendsto_lintegral_nn_filter_of_le_const {ι : Type*} {L : Filter ι} [L.IsCountablyGenerated]
(μ : Measure Ω) [IsFiniteMeasure μ] {fs : ι → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂μ, fs i ω ≤ c) {f : Ω → ℝ≥0}
(fs_lim : ∀ᵐ ω : Ω ∂μ, Tendsto (fun i ↦ fs i ω) L (𝓝 (f ω))) :
Tendsto (fun i ↦ ∫⁻ ω, fs i ω ∂μ) L (𝓝 (∫⁻ ω, f ω ∂μ)) := by
refine tendsto_lintegral_filter_of_dominated_convergence (fun _ ↦ c)
(eventually_of_forall fun i ↦ (ENNReal.continuous_coe.comp (fs i).continuous).measurable) ?_
(@lintegral_const_lt_top _ _ μ _ _ (@ENNReal.coe_ne_top c)).ne ?_
· simpa only [Function.comp_apply, ENNReal.coe_le_coe] using fs_le_const
· simpa only [Function.comp_apply, ENNReal.tendsto_coe] using fs_lim
/-- If bounded continuous functions tend to the indicator of a measurable set and are
uniformly bounded, then their integrals against a finite measure tend to the measure of the set.
This formulation assumes:
* the functions tend to a limit along a countably generated filter;
* the limit is in the almost everywhere sense;
* boundedness holds almost everywhere.
-/
theorem measure_of_cont_bdd_of_tendsto_filter_indicator {ι : Type*} {L : Filter ι}
[L.IsCountablyGenerated] (μ : Measure Ω)
[IsFiniteMeasure μ] {c : ℝ≥0} {E : Set Ω} (E_mble : MeasurableSet E) (fs : ι → Ω →ᵇ ℝ≥0)
(fs_bdd : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂μ, fs i ω ≤ c)
(fs_lim : ∀ᵐ ω ∂μ, Tendsto (fun i ↦ fs i ω) L (𝓝 (indicator E (fun _ ↦ (1 : ℝ≥0)) ω))) :
Tendsto (fun n ↦ lintegral μ fun ω ↦ fs n ω) L (𝓝 (μ E)) := by
convert tendsto_lintegral_nn_filter_of_le_const μ fs_bdd fs_lim
have aux : ∀ ω, indicator E (fun _ ↦ (1 : ℝ≥0∞)) ω = ↑(indicator E (fun _ ↦ (1 : ℝ≥0)) ω) :=
fun ω ↦ by simp only [ENNReal.coe_indicator, ENNReal.coe_one]
simp_rw [← aux, lintegral_indicator _ E_mble]
simp only [lintegral_one, Measure.restrict_apply, MeasurableSet.univ, univ_inter]
/-- If a sequence of bounded continuous functions tends to the indicator of a measurable set and
the functions are uniformly bounded, then their integrals against a finite measure tend to the
measure of the set.
A similar result with more general assumptions is
`MeasureTheory.measure_of_cont_bdd_of_tendsto_filter_indicator`.
-/
theorem measure_of_cont_bdd_of_tendsto_indicator
(μ : Measure Ω) [IsFiniteMeasure μ] {c : ℝ≥0} {E : Set Ω} (E_mble : MeasurableSet E)
(fs : ℕ → Ω →ᵇ ℝ≥0) (fs_bdd : ∀ n ω, fs n ω ≤ c)
(fs_lim : Tendsto (fun n ω ↦ fs n ω) atTop (𝓝 (indicator E fun _ ↦ (1 : ℝ≥0)))) :
Tendsto (fun n ↦ lintegral μ fun ω ↦ fs n ω) atTop (𝓝 (μ E)) := by
have fs_lim' :
∀ ω, Tendsto (fun n : ℕ ↦ (fs n ω : ℝ≥0)) atTop (𝓝 (indicator E (fun _ ↦ (1 : ℝ≥0)) ω)) := by
rw [tendsto_pi_nhds] at fs_lim
exact fun ω ↦ fs_lim ω
apply measure_of_cont_bdd_of_tendsto_filter_indicator μ E_mble fs
(eventually_of_forall fun n ↦ eventually_of_forall (fs_bdd n)) (eventually_of_forall fs_lim')
/-- The integrals of thickened indicators of a closed set against a finite measure tend to the
measure of the closed set if the thickening radii tend to zero. -/
theorem tendsto_lintegral_thickenedIndicator_of_isClosed {Ω : Type*} [MeasurableSpace Ω]
[PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] {F : Set Ω}
(F_closed : IsClosed F) {δs : ℕ → ℝ} (δs_pos : ∀ n, 0 < δs n)
(δs_lim : Tendsto δs atTop (𝓝 0)) :
Tendsto (fun n ↦ lintegral μ fun ω ↦ (thickenedIndicator (δs_pos n) F ω : ℝ≥0∞)) atTop
(𝓝 (μ F)) := by
apply measure_of_cont_bdd_of_tendsto_indicator μ F_closed.measurableSet
(fun n ↦ thickenedIndicator (δs_pos n) F) fun n ω ↦ thickenedIndicator_le_one (δs_pos n) F ω
have key := thickenedIndicator_tendsto_indicator_closure δs_pos δs_lim F
rwa [F_closed.closure_eq] at key
end MeasureTheory -- namespace
end auxiliary -- section
section HasOuterApproxClosed
/-- A type class for topological spaces in which the indicator functions of closed sets can be
approximated pointwise from above by a sequence of bounded continuous functions. -/
class HasOuterApproxClosed (X : Type*) [TopologicalSpace X] : Prop where
exAppr : ∀ (F : Set X), IsClosed F → ∃ (fseq : ℕ → (X →ᵇ ℝ≥0)),
(∀ n x, fseq n x ≤ 1) ∧ (∀ n x, x ∈ F → 1 ≤ fseq n x) ∧
Tendsto (fun n : ℕ ↦ (fun x ↦ fseq n x)) atTop (𝓝 (indicator F fun _ ↦ (1 : ℝ≥0)))
namespace HasOuterApproxClosed
variable {X : Type*} [TopologicalSpace X] [HasOuterApproxClosed X]
variable {F : Set X} (hF : IsClosed F)
/-- A sequence of continuous functions `X → [0,1]` tending to the indicator of a closed set. -/
noncomputable def _root_.IsClosed.apprSeq : ℕ → (X →ᵇ ℝ≥0) :=
Exists.choose (HasOuterApproxClosed.exAppr F hF)
lemma apprSeq_apply_le_one (n : ℕ) (x : X) :
hF.apprSeq n x ≤ 1 :=
(Exists.choose_spec (HasOuterApproxClosed.exAppr F hF)).1 n x
lemma apprSeq_apply_eq_one (n : ℕ) {x : X} (hxF : x ∈ F) :
hF.apprSeq n x = 1 :=
le_antisymm (apprSeq_apply_le_one _ _ _)
((Exists.choose_spec (HasOuterApproxClosed.exAppr F hF)).2.1 n x hxF)
lemma tendsto_apprSeq :
Tendsto (fun n : ℕ ↦ (fun x ↦ hF.apprSeq n x)) atTop (𝓝 (indicator F fun _ ↦ (1 : ℝ≥0))) :=
(Exists.choose_spec (HasOuterApproxClosed.exAppr F hF)).2.2
lemma indicator_le_apprSeq (n : ℕ) :
indicator F (fun _ ↦ 1) ≤ hF.apprSeq n := by
intro x
by_cases hxF : x ∈ F
· simp only [hxF, indicator_of_mem, apprSeq_apply_eq_one hF n, le_refl]
· simp only [hxF, not_false_eq_true, indicator_of_not_mem, zero_le]
/-- The measure of a closed set is at most the integral of any function in a decreasing
approximating sequence to the indicator of the set. -/
theorem measure_le_lintegral [MeasurableSpace X] [OpensMeasurableSpace X] (μ : Measure X) (n : ℕ) :
μ F ≤ ∫⁻ x, (hF.apprSeq n x : ℝ≥0∞) ∂μ := by
convert_to ∫⁻ x, (F.indicator (fun _ ↦ (1 : ℝ≥0∞))) x ∂μ ≤ ∫⁻ x, hF.apprSeq n x ∂μ
· rw [lintegral_indicator _ hF.measurableSet]
simp only [lintegral_one, MeasurableSet.univ, Measure.restrict_apply, univ_inter]
· apply lintegral_mono
intro x
by_cases hxF : x ∈ F
· simp only [hxF, indicator_of_mem, apprSeq_apply_eq_one hF n hxF, ENNReal.coe_one, le_refl]
· simp only [hxF, not_false_eq_true, indicator_of_not_mem, zero_le]
/-- The integrals along a decreasing approximating sequence to the indicator of a closed set
tend to the measure of the closed set. -/
lemma tendsto_lintegral_apprSeq [MeasurableSpace X] [OpensMeasurableSpace X]
(μ : Measure X) [IsFiniteMeasure μ] :
Tendsto (fun n ↦ ∫⁻ x, hF.apprSeq n x ∂μ) atTop (𝓝 ((μ : Measure X) F)) :=
measure_of_cont_bdd_of_tendsto_indicator μ hF.measurableSet hF.apprSeq
(apprSeq_apply_le_one hF) (tendsto_apprSeq hF)
end HasOuterApproxClosed --namespace
noncomputable instance (X : Type*) [TopologicalSpace X]
[TopologicalSpace.PseudoMetrizableSpace X] : HasOuterApproxClosed X := by
letI : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X
refine ⟨fun F hF ↦ ?_⟩
use fun n ↦ thickenedIndicator (δ := (1 : ℝ) / (n + 1)) Nat.one_div_pos_of_nat F
refine ⟨?_, ⟨?_, ?_⟩⟩
· exact fun n x ↦ thickenedIndicator_le_one Nat.one_div_pos_of_nat F x
· exact fun n x hxF ↦ one_le_thickenedIndicator_apply X Nat.one_div_pos_of_nat hxF
· have key := thickenedIndicator_tendsto_indicator_closure
(δseq := fun (n : ℕ) ↦ (1 : ℝ) / (n + 1))
(fun _ ↦ Nat.one_div_pos_of_nat) tendsto_one_div_add_atTop_nhds_zero_nat F
rw [tendsto_pi_nhds] at *
intro x
nth_rw 2 [← IsClosed.closure_eq hF]
exact key x
namespace MeasureTheory
/-- Two finite measures give equal values to all closed sets if the integrals of all bounded
continuous functions with respect to the two measures agree. -/
theorem measure_isClosed_eq_of_forall_lintegral_eq_of_isFiniteMeasure {Ω : Type*}
[MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω]
[OpensMeasurableSpace Ω] {μ ν : Measure Ω} [IsFiniteMeasure μ]
(h : ∀ (f : Ω →ᵇ ℝ≥0), ∫⁻ x, f x ∂μ = ∫⁻ x, f x ∂ν) {F : Set Ω} (F_closed : IsClosed F) :
μ F = ν F := by
have ν_finite : IsFiniteMeasure ν := by
constructor
have whole := h 1
simp only [BoundedContinuousFunction.coe_one, Pi.one_apply, ENNReal.coe_one, lintegral_const,
one_mul] at whole
simpa [← whole] using IsFiniteMeasure.measure_univ_lt_top
have obs_μ := HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed μ
have obs_ν := HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed ν
simp_rw [h] at obs_μ
exact tendsto_nhds_unique obs_μ obs_ν
/-- Two finite Borel measures are equal if the integrals of all bounded continuous functions with
respect to both agree. -/
theorem ext_of_forall_lintegral_eq_of_IsFiniteMeasure {Ω : Type*}
[MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω]
[BorelSpace Ω] {μ ν : Measure Ω} [IsFiniteMeasure μ]
(h : ∀ (f : Ω →ᵇ ℝ≥0), ∫⁻ x, f x ∂μ = ∫⁻ x, f x ∂ν) :
μ = ν := by
have key := @measure_isClosed_eq_of_forall_lintegral_eq_of_isFiniteMeasure Ω _ _ _ _ μ ν _ h
apply ext_of_generate_finite _ ?_ isPiSystem_isClosed
· exact fun F F_closed ↦ key F_closed
· exact key isClosed_univ
· rw [BorelSpace.measurable_eq (α := Ω), borel_eq_generateFrom_isClosed]
end MeasureTheory -- namespace
end HasOuterApproxClosed -- section
|
MeasureTheory\Measure\Hausdorff.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Convex.Between
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.Topology.MetricSpace.Holder
import Mathlib.Topology.MetricSpace.MetricSeparated
/-!
# Hausdorff measure and metric (outer) measures
In this file we define the `d`-dimensional Hausdorff measure on an (extended) metric space `X` and
the Hausdorff dimension of a set in an (extended) metric space. Let `μ d δ` be the maximal outer
measure such that `μ d δ s ≤ (EMetric.diam s) ^ d` for every set of diameter less than `δ`. Then
the Hausdorff measure `μH[d] s` of `s` is defined as `⨆ δ > 0, μ d δ s`. By Caratheodory theorem
`MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, this is a Borel measure on `X`.
The value of `μH[d]`, `d > 0`, on a set `s` (measurable or not) is given by
```
μH[d] s = ⨆ (r : ℝ≥0∞) (hr : 0 < r), ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n)
(ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, EMetric.diam (t n) ^ d
```
For every set `s` for any `d < d'` we have either `μH[d] s = ∞` or `μH[d'] s = 0`, see
`MeasureTheory.Measure.hausdorffMeasure_zero_or_top`. In
`Mathlib.Topology.MetricSpace.HausdorffDimension` we use this fact to define the Hausdorff dimension
`dimH` of a set in an (extended) metric space.
We also define two generalizations of the Hausdorff measure. In one generalization (see
`MeasureTheory.Measure.mkMetric`) we take any function `m (diam s)` instead of `(diam s) ^ d`. In
an even more general definition (see `MeasureTheory.Measure.mkMetric'`) we use any function
of `m : Set X → ℝ≥0∞`. Some authors start with a partial function `m` defined only on some sets
`s : Set X` (e.g., only on balls or only on measurable sets). This is equivalent to our definition
applied to `MeasureTheory.extend m`.
We also define a predicate `MeasureTheory.OuterMeasure.IsMetric` which says that an outer measure
is additive on metric separated pairs of sets: `μ (s ∪ t) = μ s + μ t` provided that
`⨅ (x ∈ s) (y ∈ t), edist x y ≠ 0`. This is the property required for the Caratheodory theorem
`MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, so we prove this theorem for any
metric outer measure, then prove that outer measures constructed using `mkMetric'` are metric outer
measures.
## Main definitions
* `MeasureTheory.OuterMeasure.IsMetric`: an outer measure `μ` is called *metric* if
`μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s` and `t`. A metric outer measure in a
Borel extended metric space is guaranteed to satisfy the Caratheodory condition, see
`MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`.
* `MeasureTheory.OuterMeasure.mkMetric'` and its particular case
`MeasureTheory.OuterMeasure.mkMetric`: a construction of an outer measure that is guaranteed to
be metric. Both constructions are generalizations of the Hausdorff measure. The same measures
interpreted as Borel measures are called `MeasureTheory.Measure.mkMetric'` and
`MeasureTheory.Measure.mkMetric`.
* `MeasureTheory.Measure.hausdorffMeasure` a.k.a. `μH[d]`: the `d`-dimensional Hausdorff measure.
There are many definitions of the Hausdorff measure that differ from each other by a
multiplicative constant. We put
`μH[d] s = ⨆ r > 0, ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r),
∑' n, ⨆ (ht : ¬Set.Subsingleton (t n)), (EMetric.diam (t n)) ^ d`,
see `MeasureTheory.Measure.hausdorffMeasure_apply`. In the most interesting case `0 < d` one
can omit the `⨆ (ht : ¬Set.Subsingleton (t n))` part.
## Main statements
### Basic properties
* `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`: if `μ` is a metric outer measure
on an extended metric space `X` (that is, it is additive on pairs of metric separated sets), then
every Borel set is Caratheodory measurable (hence, `μ` defines an actual
`MeasureTheory.Measure`). See also `MeasureTheory.Measure.mkMetric`.
* `MeasureTheory.Measure.hausdorffMeasure_mono`: `μH[d] s` is an antitone function
of `d`.
* `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`: if `d₁ < d₂`, then for any `s`, either
`μH[d₂] s = 0` or `μH[d₁] s = ∞`. Together with the previous lemma, this means that `μH[d] s` is
equal to infinity on some ray `(-∞, D)` and is equal to zero on `(D, +∞)`, where `D` is a possibly
infinite number called the *Hausdorff dimension* of `s`; `μH[D] s` can be zero, infinity, or
anything in between.
* `MeasureTheory.Measure.noAtoms_hausdorff`: Hausdorff measure has no atoms.
### Hausdorff measure in `ℝⁿ`
* `MeasureTheory.hausdorffMeasure_pi_real`: for a nonempty `ι`, `μH[card ι]` on `ι → ℝ` equals
Lebesgue measure.
## Notations
We use the following notation localized in `MeasureTheory`.
- `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d`
## Implementation notes
There are a few similar constructions called the `d`-dimensional Hausdorff measure. E.g., some
sources only allow coverings by balls and use `r ^ d` instead of `(diam s) ^ d`. While these
construction lead to different Hausdorff measures, they lead to the same notion of the Hausdorff
dimension.
## References
* [Herbert Federer, Geometric Measure Theory, Chapter 2.10][Federer1996]
## Tags
Hausdorff measure, measure, metric measure
-/
open scoped NNReal ENNReal Topology
open EMetric Set Function Filter Encodable FiniteDimensional TopologicalSpace
noncomputable section
variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y]
namespace MeasureTheory
namespace OuterMeasure
/-!
### Metric outer measures
In this section we define metric outer measures and prove Caratheodory theorem: a metric outer
measure has the Caratheodory property.
-/
/-- We say that an outer measure `μ` in an (e)metric space is *metric* if `μ (s ∪ t) = μ s + μ t`
for any two metric separated sets `s`, `t`. -/
def IsMetric (μ : OuterMeasure X) : Prop :=
∀ s t : Set X, IsMetricSeparated s t → μ (s ∪ t) = μ s + μ t
namespace IsMetric
variable {μ : OuterMeasure X}
/-- A metric outer measure is additive on a finite set of pairwise metric separated sets. -/
theorem finset_iUnion_of_pairwise_separated (hm : IsMetric μ) {I : Finset ι} {s : ι → Set X}
(hI : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → IsMetricSeparated (s i) (s j)) :
μ (⋃ i ∈ I, s i) = ∑ i ∈ I, μ (s i) := by
classical
induction' I using Finset.induction_on with i I hiI ihI hI
· simp
simp only [Finset.mem_insert] at hI
rw [Finset.set_biUnion_insert, hm, ihI, Finset.sum_insert hiI]
exacts [fun i hi j hj hij => hI i (Or.inr hi) j (Or.inr hj) hij,
IsMetricSeparated.finset_iUnion_right fun j hj =>
hI i (Or.inl rfl) j (Or.inr hj) (ne_of_mem_of_not_mem hj hiI).symm]
/-- Caratheodory theorem. If `m` is a metric outer measure, then every Borel measurable set `t` is
Caratheodory measurable: for any (not necessarily measurable) set `s` we have
`μ (s ∩ t) + μ (s \ t) = μ s`. -/
theorem borel_le_caratheodory (hm : IsMetric μ) : borel X ≤ μ.caratheodory := by
rw [borel_eq_generateFrom_isClosed]
refine MeasurableSpace.generateFrom_le fun t ht => μ.isCaratheodory_iff_le.2 fun s => ?_
set S : ℕ → Set X := fun n => {x ∈ s | (↑n)⁻¹ ≤ infEdist x t}
have Ssep (n) : IsMetricSeparated (S n) t :=
⟨n⁻¹, ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _),
fun x hx y hy ↦ hx.2.trans <| infEdist_le_edist_of_mem hy⟩
have Ssep' : ∀ n, IsMetricSeparated (S n) (s ∩ t) := fun n =>
(Ssep n).mono Subset.rfl inter_subset_right
have S_sub : ∀ n, S n ⊆ s \ t := fun n =>
subset_inter inter_subset_left (Ssep n).subset_compl_right
have hSs : ∀ n, μ (s ∩ t) + μ (S n) ≤ μ s := fun n =>
calc
μ (s ∩ t) + μ (S n) = μ (s ∩ t ∪ S n) := Eq.symm <| hm _ _ <| (Ssep' n).symm
_ ≤ μ (s ∩ t ∪ s \ t) := μ.mono <| union_subset_union_right _ <| S_sub n
_ = μ s := by rw [inter_union_diff]
have iUnion_S : ⋃ n, S n = s \ t := by
refine Subset.antisymm (iUnion_subset S_sub) ?_
rintro x ⟨hxs, hxt⟩
rw [mem_iff_infEdist_zero_of_closed ht] at hxt
rcases ENNReal.exists_inv_nat_lt hxt with ⟨n, hn⟩
exact mem_iUnion.2 ⟨n, hxs, hn.le⟩
/- Now we have `∀ n, μ (s ∩ t) + μ (S n) ≤ μ s` and we need to prove
`μ (s ∩ t) + μ (⋃ n, S n) ≤ μ s`. We can't pass to the limit because
`μ` is only an outer measure. -/
by_cases htop : μ (s \ t) = ∞
· rw [htop, add_top, ← htop]
exact μ.mono diff_subset
suffices μ (⋃ n, S n) ≤ ⨆ n, μ (S n) by calc
μ (s ∩ t) + μ (s \ t) = μ (s ∩ t) + μ (⋃ n, S n) := by rw [iUnion_S]
_ ≤ μ (s ∩ t) + ⨆ n, μ (S n) := by gcongr
_ = ⨆ n, μ (s ∩ t) + μ (S n) := ENNReal.add_iSup
_ ≤ μ s := iSup_le hSs
/- It suffices to show that `∑' k, μ (S (k + 1) \ S k) ≠ ∞`. Indeed, if we have this,
then for all `N` we have `μ (⋃ n, S n) ≤ μ (S N) + ∑' k, m (S (N + k + 1) \ S (N + k))`
and the second term tends to zero, see `OuterMeasure.iUnion_nat_of_monotone_of_tsum_ne_top`
for details. -/
have : ∀ n, S n ⊆ S (n + 1) := fun n x hx =>
⟨hx.1, le_trans (ENNReal.inv_le_inv.2 <| Nat.cast_le.2 n.le_succ) hx.2⟩
classical -- Porting note: Added this to get the next tactic to work
refine (μ.iUnion_nat_of_monotone_of_tsum_ne_top this ?_).le; clear this
/- While the sets `S (k + 1) \ S k` are not pairwise metric separated, the sets in each
subsequence `S (2 * k + 1) \ S (2 * k)` and `S (2 * k + 2) \ S (2 * k)` are metric separated,
so `m` is additive on each of those sequences. -/
rw [← tsum_even_add_odd ENNReal.summable ENNReal.summable, ENNReal.add_ne_top]
suffices ∀ a, (∑' k : ℕ, μ (S (2 * k + 1 + a) \ S (2 * k + a))) ≠ ∞ from
⟨by simpa using this 0, by simpa using this 1⟩
refine fun r => ne_top_of_le_ne_top htop ?_
rw [← iUnion_S, ENNReal.tsum_eq_iSup_nat, iSup_le_iff]
intro n
rw [← hm.finset_iUnion_of_pairwise_separated]
· exact μ.mono (iUnion_subset fun i => iUnion_subset fun _ x hx => mem_iUnion.2 ⟨_, hx.1⟩)
suffices ∀ i j, i < j → IsMetricSeparated (S (2 * i + 1 + r)) (s \ S (2 * j + r)) from
fun i _ j _ hij => hij.lt_or_lt.elim
(fun h => (this i j h).mono inter_subset_left fun x hx => by exact ⟨hx.1.1, hx.2⟩)
fun h => (this j i h).symm.mono (fun x hx => by exact ⟨hx.1.1, hx.2⟩) inter_subset_left
intro i j hj
have A : ((↑(2 * j + r))⁻¹ : ℝ≥0∞) < (↑(2 * i + 1 + r))⁻¹ := by
rw [ENNReal.inv_lt_inv, Nat.cast_lt]; omega
refine ⟨(↑(2 * i + 1 + r))⁻¹ - (↑(2 * j + r))⁻¹, by simpa [tsub_eq_zero_iff_le] using A,
fun x hx y hy => ?_⟩
have : infEdist y t < (↑(2 * j + r))⁻¹ := not_le.1 fun hle => hy.2 ⟨hy.1, hle⟩
rcases infEdist_lt_iff.mp this with ⟨z, hzt, hyz⟩
have hxz : (↑(2 * i + 1 + r))⁻¹ ≤ edist x z := le_infEdist.1 hx.2 _ hzt
apply ENNReal.le_of_add_le_add_right hyz.ne_top
refine le_trans ?_ (edist_triangle _ _ _)
refine (add_le_add le_rfl hyz.le).trans (Eq.trans_le ?_ hxz)
rw [tsub_add_cancel_of_le A.le]
theorem le_caratheodory [MeasurableSpace X] [BorelSpace X] (hm : IsMetric μ) :
‹MeasurableSpace X› ≤ μ.caratheodory := by
rw [BorelSpace.measurable_eq (α := X)]
exact hm.borel_le_caratheodory
end IsMetric
/-!
### Constructors of metric outer measures
In this section we provide constructors `MeasureTheory.OuterMeasure.mkMetric'` and
`MeasureTheory.OuterMeasure.mkMetric` and prove that these outer measures are metric outer
measures. We also prove basic lemmas about `map`/`comap` of these measures.
-/
/-- Auxiliary definition for `OuterMeasure.mkMetric'`: given a function on sets
`m : Set X → ℝ≥0∞`, returns the maximal outer measure `μ` such that `μ s ≤ m s`
for any set `s` of diameter at most `r`. -/
def mkMetric'.pre (m : Set X → ℝ≥0∞) (r : ℝ≥0∞) : OuterMeasure X :=
boundedBy <| extend fun s (_ : diam s ≤ r) => m s
/-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `mkMetric'.pre m r`
over `r > 0`. Equivalently, it is the limit of `mkMetric'.pre m r` as `r` tends to zero from
the right. -/
def mkMetric' (m : Set X → ℝ≥0∞) : OuterMeasure X :=
⨆ r > 0, mkMetric'.pre m r
/-- Given a function `m : ℝ≥0∞ → ℝ≥0∞` and `r > 0`, let `μ r` be the maximal outer measure such that
`μ s ≤ m (EMetric.diam s)` whenever `EMetric.diam s < r`. Then `mkMetric m = ⨆ r > 0, μ r`. -/
def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X :=
mkMetric' fun s => m (diam s)
namespace mkMetric'
variable {m : Set X → ℝ≥0∞} {r : ℝ≥0∞} {μ : OuterMeasure X} {s : Set X}
theorem le_pre : μ ≤ pre m r ↔ ∀ s : Set X, diam s ≤ r → μ s ≤ m s := by
simp only [pre, le_boundedBy, extend, le_iInf_iff]
theorem pre_le (hs : diam s ≤ r) : pre m r s ≤ m s :=
(boundedBy_le _).trans <| iInf_le _ hs
theorem mono_pre (m : Set X → ℝ≥0∞) {r r' : ℝ≥0∞} (h : r ≤ r') : pre m r' ≤ pre m r :=
le_pre.2 fun _ hs => pre_le (hs.trans h)
theorem mono_pre_nat (m : Set X → ℝ≥0∞) : Monotone fun k : ℕ => pre m k⁻¹ :=
fun k l h => le_pre.2 fun s hs => pre_le (hs.trans <| by simpa)
theorem tendsto_pre (m : Set X → ℝ≥0∞) (s : Set X) :
Tendsto (fun r => pre m r s) (𝓝[>] 0) (𝓝 <| mkMetric' m s) := by
rw [← map_coe_Ioi_atBot, tendsto_map'_iff]
simp only [mkMetric', OuterMeasure.iSup_apply, iSup_subtype']
exact tendsto_atBot_iSup fun r r' hr => mono_pre _ hr _
theorem tendsto_pre_nat (m : Set X → ℝ≥0∞) (s : Set X) :
Tendsto (fun n : ℕ => pre m n⁻¹ s) atTop (𝓝 <| mkMetric' m s) := by
refine (tendsto_pre m s).comp (tendsto_inf.2 ⟨ENNReal.tendsto_inv_nat_nhds_zero, ?_⟩)
refine tendsto_principal.2 (eventually_of_forall fun n => ?_)
simp
theorem eq_iSup_nat (m : Set X → ℝ≥0∞) : mkMetric' m = ⨆ n : ℕ, mkMetric'.pre m n⁻¹ := by
ext1 s
rw [iSup_apply]
refine tendsto_nhds_unique (mkMetric'.tendsto_pre_nat m s)
(tendsto_atTop_iSup fun k l hkl => mkMetric'.mono_pre_nat m hkl s)
/-- `MeasureTheory.OuterMeasure.mkMetric'.pre m r` is a trimmed measure provided that
`m (closure s) = m s` for any set `s`. -/
theorem trim_pre [MeasurableSpace X] [OpensMeasurableSpace X] (m : Set X → ℝ≥0∞)
(hcl : ∀ s, m (closure s) = m s) (r : ℝ≥0∞) : (pre m r).trim = pre m r := by
refine le_antisymm (le_pre.2 fun s hs => ?_) (le_trim _)
rw [trim_eq_iInf]
refine iInf_le_of_le (closure s) <| iInf_le_of_le subset_closure <|
iInf_le_of_le measurableSet_closure ((pre_le ?_).trans_eq (hcl _))
rwa [diam_closure]
end mkMetric'
/-- An outer measure constructed using `OuterMeasure.mkMetric'` is a metric outer measure. -/
theorem mkMetric'_isMetric (m : Set X → ℝ≥0∞) : (mkMetric' m).IsMetric := by
rintro s t ⟨r, r0, hr⟩
refine tendsto_nhds_unique_of_eventuallyEq
(mkMetric'.tendsto_pre _ _) ((mkMetric'.tendsto_pre _ _).add (mkMetric'.tendsto_pre _ _)) ?_
rw [← pos_iff_ne_zero] at r0
filter_upwards [Ioo_mem_nhdsWithin_Ioi ⟨le_rfl, r0⟩]
rintro ε ⟨_, εr⟩
refine boundedBy_union_of_top_of_nonempty_inter ?_
rintro u ⟨x, hxs, hxu⟩ ⟨y, hyt, hyu⟩
have : ε < diam u := εr.trans_le ((hr x hxs y hyt).trans <| edist_le_diam_of_mem hxu hyu)
exact iInf_eq_top.2 fun h => (this.not_le h).elim
/-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0`
(we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/
theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0)
(hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : OuterMeasure X) ≤ c • mkMetric m₂ := by
classical
rcases (mem_nhdsWithin_Ici_iff_exists_Ico_subset' zero_lt_one).1 hle with ⟨r, hr0, hr⟩
refine fun s =>
le_of_tendsto_of_tendsto (mkMetric'.tendsto_pre _ s)
(ENNReal.Tendsto.const_mul (mkMetric'.tendsto_pre _ s) (Or.inr hc))
(mem_of_superset (Ioo_mem_nhdsWithin_Ioi ⟨le_rfl, hr0⟩) fun r' hr' => ?_)
simp only [mem_setOf_eq, mkMetric'.pre, RingHom.id_apply]
rw [← smul_eq_mul, ← smul_apply, smul_boundedBy hc]
refine le_boundedBy.2 (fun t => (boundedBy_le _).trans ?_) _
simp only [smul_eq_mul, Pi.smul_apply, extend, iInf_eq_if]
split_ifs with ht
· apply hr
exact ⟨zero_le _, ht.trans_lt hr'.2⟩
· simp [h0]
@[simp]
theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X) = ⊤ := by
simp_rw [mkMetric, mkMetric', mkMetric'.pre, extend_top, boundedBy_top, eq_top_iff]
rw [le_iSup_iff]
intro b hb
simpa using hb ⊤
/-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then
`mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/
theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) :
(mkMetric m₁ : OuterMeasure X) ≤ mkMetric m₂ := by
convert @mkMetric_mono_smul X _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*]
theorem isometry_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f)
(H : Monotone m ∨ Surjective f) : comap f (mkMetric m) = mkMetric m := by
simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, comap_iSup]
refine surjective_id.iSup_congr id fun ε => surjective_id.iSup_congr id fun hε => ?_
rw [comap_boundedBy _ (H.imp _ id)]
· congr with s : 1
apply extend_congr
· simp [hf.ediam_image]
· intros; simp [hf.injective.subsingleton_image_iff, hf.ediam_image]
· intro h_mono s t hst
simp only [extend, le_iInf_iff]
intro ht
apply le_trans _ (h_mono (diam_mono hst))
simp only [(diam_mono hst).trans ht, le_refl, ciInf_pos]
theorem mkMetric_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0∞} (hc : c ≠ ∞) (hc' : c ≠ 0) :
(mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by
simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, ENNReal.smul_iSup]
simp_rw [smul_iSup, smul_boundedBy hc, smul_extend _ hc', Pi.smul_apply]
theorem mkMetric_nnreal_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0} (hc : c ≠ 0) :
(mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by
rw [ENNReal.smul_def, ENNReal.smul_def,
mkMetric_smul m ENNReal.coe_ne_top (ENNReal.coe_ne_zero.mpr hc)]
theorem isometry_map_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f)
(H : Monotone m ∨ Surjective f) : map f (mkMetric m) = restrict (range f) (mkMetric m) := by
rw [← isometry_comap_mkMetric _ hf H, map_comap]
theorem isometryEquiv_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (f : X ≃ᵢ Y) :
comap f (mkMetric m) = mkMetric m :=
isometry_comap_mkMetric _ f.isometry (Or.inr f.surjective)
theorem isometryEquiv_map_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (f : X ≃ᵢ Y) :
map f (mkMetric m) = mkMetric m := by
rw [← isometryEquiv_comap_mkMetric _ f, map_comap_of_surjective f.surjective]
theorem trim_mkMetric [MeasurableSpace X] [BorelSpace X] (m : ℝ≥0∞ → ℝ≥0∞) :
(mkMetric m : OuterMeasure X).trim = mkMetric m := by
simp only [mkMetric, mkMetric'.eq_iSup_nat, trim_iSup]
congr 1 with n : 1
refine mkMetric'.trim_pre _ (fun s => ?_) _
simp
theorem le_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (μ : OuterMeasure X) (r : ℝ≥0∞) (h0 : 0 < r)
(hr : ∀ s, diam s ≤ r → μ s ≤ m (diam s)) : μ ≤ mkMetric m :=
le_iSup₂_of_le r h0 <| mkMetric'.le_pre.2 fun _ hs => hr _ hs
end OuterMeasure
/-!
### Metric measures
In this section we use `MeasureTheory.OuterMeasure.toMeasure` and theorems about
`MeasureTheory.OuterMeasure.mkMetric'`/`MeasureTheory.OuterMeasure.mkMetric` to define
`MeasureTheory.Measure.mkMetric'`/`MeasureTheory.Measure.mkMetric`. We also restate some lemmas
about metric outer measures for metric measures.
-/
namespace Measure
variable [MeasurableSpace X] [BorelSpace X]
/-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `μ r`
over `r > 0`, where `μ r` is the maximal outer measure `μ` such that `μ s ≤ m s`
for all `s`. While each `μ r` is an *outer* measure, the supremum is a measure. -/
def mkMetric' (m : Set X → ℝ≥0∞) : Measure X :=
(OuterMeasure.mkMetric' m).toMeasure (OuterMeasure.mkMetric'_isMetric _).le_caratheodory
/-- Given a function `m : ℝ≥0∞ → ℝ≥0∞`, `mkMetric m` is the supremum of `μ r` over `r > 0`, where
`μ r` is the maximal outer measure `μ` such that `μ s ≤ m s` for all sets `s` that contain at least
two points. While each `mkMetric'.pre` is an *outer* measure, the supremum is a measure. -/
def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : Measure X :=
(OuterMeasure.mkMetric m).toMeasure (OuterMeasure.mkMetric'_isMetric _).le_caratheodory
@[simp]
theorem mkMetric'_toOuterMeasure (m : Set X → ℝ≥0∞) :
(mkMetric' m).toOuterMeasure = (OuterMeasure.mkMetric' m).trim :=
rfl
@[simp]
theorem mkMetric_toOuterMeasure (m : ℝ≥0∞ → ℝ≥0∞) :
(mkMetric m : Measure X).toOuterMeasure = OuterMeasure.mkMetric m :=
OuterMeasure.trim_mkMetric m
end Measure
theorem OuterMeasure.coe_mkMetric [MeasurableSpace X] [BorelSpace X] (m : ℝ≥0∞ → ℝ≥0∞) :
⇑(OuterMeasure.mkMetric m : OuterMeasure X) = Measure.mkMetric m := by
rw [← Measure.mkMetric_toOuterMeasure, Measure.coe_toOuterMeasure]
namespace Measure
variable [MeasurableSpace X] [BorelSpace X]
/-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0`
(we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/
theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0)
(hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : Measure X) ≤ c • mkMetric m₂ := fun s ↦ by
rw [← OuterMeasure.coe_mkMetric, coe_smul, ← OuterMeasure.coe_mkMetric]
exact OuterMeasure.mkMetric_mono_smul hc h0 hle s
@[simp]
theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : Measure X) = ⊤ := by
apply toOuterMeasure_injective
rw [mkMetric_toOuterMeasure, OuterMeasure.mkMetric_top, toOuterMeasure_top]
/-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then
`mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/
theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) :
(mkMetric m₁ : Measure X) ≤ mkMetric m₂ := by
convert @mkMetric_mono_smul X _ _ _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*]
/-- A formula for `MeasureTheory.Measure.mkMetric`. -/
theorem mkMetric_apply (m : ℝ≥0∞ → ℝ≥0∞) (s : Set X) :
mkMetric m s =
⨆ (r : ℝ≥0∞) (_ : 0 < r),
⨅ (t : ℕ → Set X) (_ : s ⊆ iUnion t) (_ : ∀ n, diam (t n) ≤ r),
∑' n, ⨆ _ : (t n).Nonempty, m (diam (t n)) := by
classical
-- We mostly unfold the definitions but we need to switch the order of `∑'` and `⨅`
simp only [← OuterMeasure.coe_mkMetric, OuterMeasure.mkMetric, OuterMeasure.mkMetric',
OuterMeasure.iSup_apply, OuterMeasure.mkMetric'.pre, OuterMeasure.boundedBy_apply, extend]
refine
surjective_id.iSup_congr (fun r => r) fun r =>
iSup_congr_Prop Iff.rfl fun _ =>
surjective_id.iInf_congr _ fun t => iInf_congr_Prop Iff.rfl fun ht => ?_
dsimp
by_cases htr : ∀ n, diam (t n) ≤ r
· rw [iInf_eq_if, if_pos htr]
congr 1 with n : 1
simp only [iInf_eq_if, htr n, id, if_true, iSup_and']
· rw [iInf_eq_if, if_neg htr]
push_neg at htr; rcases htr with ⟨n, hn⟩
refine ENNReal.tsum_eq_top_of_eq_top ⟨n, ?_⟩
rw [iSup_eq_if, if_pos, iInf_eq_if, if_neg]
· exact hn.not_le
rcases diam_pos_iff.1 ((zero_le r).trans_lt hn) with ⟨x, hx, -⟩
exact ⟨x, hx⟩
theorem le_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (μ : Measure X) (ε : ℝ≥0∞) (h₀ : 0 < ε)
(h : ∀ s : Set X, diam s ≤ ε → μ s ≤ m (diam s)) : μ ≤ mkMetric m := by
rw [← toOuterMeasure_le, mkMetric_toOuterMeasure]
exact OuterMeasure.le_mkMetric m μ.toOuterMeasure ε h₀ h
/-- To bound the Hausdorff measure (or, more generally, for a measure defined using
`MeasureTheory.Measure.mkMetric`) of a set, one may use coverings with maximum diameter tending to
`0`, indexed by any sequence of countable types. -/
theorem mkMetric_le_liminf_tsum {β : Type*} {ι : β → Type*} [∀ n, Countable (ι n)] (s : Set X)
{l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X)
(ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) (m : ℝ≥0∞ → ℝ≥0∞) :
mkMetric m s ≤ liminf (fun n => ∑' i, m (diam (t n i))) l := by
haveI : ∀ n, Encodable (ι n) := fun n => Encodable.ofCountable _
simp only [mkMetric_apply]
refine iSup₂_le fun ε hε => ?_
refine le_of_forall_le_of_dense fun c hc => ?_
rcases ((frequently_lt_of_liminf_lt (by isBoundedDefault) hc).and_eventually
((hr.eventually (gt_mem_nhds hε)).and (ht.and hst))).exists with
⟨n, hn, hrn, htn, hstn⟩
set u : ℕ → Set X := fun j => ⋃ b ∈ decode₂ (ι n) j, t n b
refine iInf₂_le_of_le u (by rwa [iUnion_decode₂]) ?_
refine iInf_le_of_le (fun j => ?_) ?_
· rw [EMetric.diam_iUnion_mem_option]
exact iSup₂_le fun _ _ => (htn _).trans hrn.le
· calc
(∑' j : ℕ, ⨆ _ : (u j).Nonempty, m (diam (u j))) = _ :=
tsum_iUnion_decode₂ (fun t : Set X => ⨆ _ : t.Nonempty, m (diam t)) (by simp) _
_ ≤ ∑' i : ι n, m (diam (t n i)) := ENNReal.tsum_le_tsum fun b => iSup_le fun _ => le_rfl
_ ≤ c := hn.le
/-- To bound the Hausdorff measure (or, more generally, for a measure defined using
`MeasureTheory.Measure.mkMetric`) of a set, one may use coverings with maximum diameter tending to
`0`, indexed by any sequence of finite types. -/
theorem mkMetric_le_liminf_sum {β : Type*} {ι : β → Type*} [hι : ∀ n, Fintype (ι n)] (s : Set X)
{l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X)
(ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) (m : ℝ≥0∞ → ℝ≥0∞) :
mkMetric m s ≤ liminf (fun n => ∑ i, m (diam (t n i))) l := by
simpa only [tsum_fintype] using mkMetric_le_liminf_tsum s r hr t ht hst m
/-!
### Hausdorff measure and Hausdorff dimension
-/
/-- Hausdorff measure on an (e)metric space. -/
def hausdorffMeasure (d : ℝ) : Measure X :=
mkMetric fun r => r ^ d
scoped[MeasureTheory] notation "μH[" d "]" => MeasureTheory.Measure.hausdorffMeasure d
theorem le_hausdorffMeasure (d : ℝ) (μ : Measure X) (ε : ℝ≥0∞) (h₀ : 0 < ε)
(h : ∀ s : Set X, diam s ≤ ε → μ s ≤ diam s ^ d) : μ ≤ μH[d] :=
le_mkMetric _ μ ε h₀ h
/-- A formula for `μH[d] s`. -/
theorem hausdorffMeasure_apply (d : ℝ) (s : Set X) :
μH[d] s =
⨆ (r : ℝ≥0∞) (_ : 0 < r),
⨅ (t : ℕ → Set X) (_ : s ⊆ ⋃ n, t n) (_ : ∀ n, diam (t n) ≤ r),
∑' n, ⨆ _ : (t n).Nonempty, diam (t n) ^ d :=
mkMetric_apply _ _
/-- To bound the Hausdorff measure of a set, one may use coverings with maximum diameter tending
to `0`, indexed by any sequence of countable types. -/
theorem hausdorffMeasure_le_liminf_tsum {β : Type*} {ι : β → Type*} [∀ n, Countable (ι n)]
(d : ℝ) (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0))
(t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n)
(hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) : μH[d] s ≤ liminf (fun n => ∑' i, diam (t n i) ^ d) l :=
mkMetric_le_liminf_tsum s r hr t ht hst _
/-- To bound the Hausdorff measure of a set, one may use coverings with maximum diameter tending
to `0`, indexed by any sequence of finite types. -/
theorem hausdorffMeasure_le_liminf_sum {β : Type*} {ι : β → Type*} [∀ n, Fintype (ι n)]
(d : ℝ) (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0))
(t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n)
(hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) : μH[d] s ≤ liminf (fun n => ∑ i, diam (t n i) ^ d) l :=
mkMetric_le_liminf_sum s r hr t ht hst _
/-- If `d₁ < d₂`, then for any set `s` we have either `μH[d₂] s = 0`, or `μH[d₁] s = ∞`. -/
theorem hausdorffMeasure_zero_or_top {d₁ d₂ : ℝ} (h : d₁ < d₂) (s : Set X) :
μH[d₂] s = 0 ∨ μH[d₁] s = ∞ := by
by_contra! H
suffices ∀ c : ℝ≥0, c ≠ 0 → μH[d₂] s ≤ c * μH[d₁] s by
rcases ENNReal.exists_nnreal_pos_mul_lt H.2 H.1 with ⟨c, hc0, hc⟩
exact hc.not_le (this c (pos_iff_ne_zero.1 hc0))
intro c hc
refine le_iff'.1 (mkMetric_mono_smul ENNReal.coe_ne_top (mod_cast hc) ?_) s
have : 0 < ((c : ℝ≥0∞) ^ (d₂ - d₁)⁻¹) := by
rw [ENNReal.coe_rpow_of_ne_zero hc, pos_iff_ne_zero, Ne, ENNReal.coe_eq_zero,
NNReal.rpow_eq_zero_iff]
exact mt And.left hc
filter_upwards [Ico_mem_nhdsWithin_Ici ⟨le_rfl, this⟩]
rintro r ⟨hr₀, hrc⟩
lift r to ℝ≥0 using ne_top_of_lt hrc
rw [Pi.smul_apply, smul_eq_mul,
← ENNReal.div_le_iff_le_mul (Or.inr ENNReal.coe_ne_top) (Or.inr <| mt ENNReal.coe_eq_zero.1 hc)]
rcases eq_or_ne r 0 with (rfl | hr₀)
· rcases lt_or_le 0 d₂ with (h₂ | h₂)
· simp only [h₂, ENNReal.zero_rpow_of_pos, zero_le, ENNReal.zero_div, ENNReal.coe_zero]
· simp only [h.trans_le h₂, ENNReal.div_top, zero_le, ENNReal.zero_rpow_of_neg,
ENNReal.coe_zero]
· have : (r : ℝ≥0∞) ≠ 0 := by simpa only [ENNReal.coe_eq_zero, Ne] using hr₀
rw [← ENNReal.rpow_sub _ _ this ENNReal.coe_ne_top]
refine (ENNReal.rpow_lt_rpow hrc (sub_pos.2 h)).le.trans ?_
rw [← ENNReal.rpow_mul, inv_mul_cancel (sub_pos.2 h).ne', ENNReal.rpow_one]
/-- Hausdorff measure `μH[d] s` is monotone in `d`. -/
theorem hausdorffMeasure_mono {d₁ d₂ : ℝ} (h : d₁ ≤ d₂) (s : Set X) : μH[d₂] s ≤ μH[d₁] s := by
rcases h.eq_or_lt with (rfl | h); · exact le_rfl
cases' hausdorffMeasure_zero_or_top h s with hs hs
· rw [hs]; exact zero_le _
· rw [hs]; exact le_top
variable (X)
theorem noAtoms_hausdorff {d : ℝ} (hd : 0 < d) : NoAtoms (hausdorffMeasure d : Measure X) := by
refine ⟨fun x => ?_⟩
rw [← nonpos_iff_eq_zero, hausdorffMeasure_apply]
refine iSup₂_le fun ε _ => iInf₂_le_of_le (fun _ => {x}) ?_ <| iInf_le_of_le (fun _ => ?_) ?_
· exact subset_iUnion (fun _ => {x} : ℕ → Set X) 0
· simp only [EMetric.diam_singleton, zero_le]
· simp [hd]
variable {X}
@[simp]
theorem hausdorffMeasure_zero_singleton (x : X) : μH[0] ({x} : Set X) = 1 := by
apply le_antisymm
· let r : ℕ → ℝ≥0∞ := fun _ => 0
let t : ℕ → Unit → Set X := fun _ _ => {x}
have ht : ∀ᶠ n in atTop, ∀ i, diam (t n i) ≤ r n := by
simp only [t, r, imp_true_iff, eq_self_iff_true, diam_singleton, eventually_atTop,
nonpos_iff_eq_zero, exists_const]
simpa [t, liminf_const] using hausdorffMeasure_le_liminf_sum 0 {x} r tendsto_const_nhds t ht
· rw [hausdorffMeasure_apply]
suffices
(1 : ℝ≥0∞) ≤
⨅ (t : ℕ → Set X) (_ : {x} ⊆ ⋃ n, t n) (_ : ∀ n, diam (t n) ≤ 1),
∑' n, ⨆ _ : (t n).Nonempty, diam (t n) ^ (0 : ℝ) by
apply le_trans this _
convert le_iSup₂ (α := ℝ≥0∞) (1 : ℝ≥0∞) zero_lt_one
rfl
simp only [ENNReal.rpow_zero, le_iInf_iff]
intro t hst _
rcases mem_iUnion.1 (hst (mem_singleton x)) with ⟨m, hm⟩
have A : (t m).Nonempty := ⟨x, hm⟩
calc
(1 : ℝ≥0∞) = ⨆ h : (t m).Nonempty, 1 := by simp only [A, ciSup_pos]
_ ≤ ∑' n, ⨆ h : (t n).Nonempty, 1 := ENNReal.le_tsum _
theorem one_le_hausdorffMeasure_zero_of_nonempty {s : Set X} (h : s.Nonempty) : 1 ≤ μH[0] s := by
rcases h with ⟨x, hx⟩
calc
(1 : ℝ≥0∞) = μH[0] ({x} : Set X) := (hausdorffMeasure_zero_singleton x).symm
_ ≤ μH[0] s := measure_mono (singleton_subset_iff.2 hx)
theorem hausdorffMeasure_le_one_of_subsingleton {s : Set X} (hs : s.Subsingleton) {d : ℝ}
(hd : 0 ≤ d) : μH[d] s ≤ 1 := by
rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩)
· simp only [measure_empty, zero_le]
· rw [(subsingleton_iff_singleton hx).1 hs]
rcases eq_or_lt_of_le hd with (rfl | dpos)
· simp only [le_refl, hausdorffMeasure_zero_singleton]
· haveI := noAtoms_hausdorff X dpos
simp only [zero_le, measure_singleton]
end Measure
end MeasureTheory
/-!
### Hausdorff measure, Hausdorff dimension, and Hölder or Lipschitz continuous maps
-/
open scoped MeasureTheory
open MeasureTheory MeasureTheory.Measure
variable [MeasurableSpace X] [BorelSpace X] [MeasurableSpace Y] [BorelSpace Y]
namespace HolderOnWith
variable {C r : ℝ≥0} {f : X → Y} {s t : Set X}
/-- If `f : X → Y` is Hölder continuous on `s` with a positive exponent `r`, then
`μH[d] (f '' s) ≤ C ^ d * μH[r * d] s`. -/
theorem hausdorffMeasure_image_le (h : HolderOnWith C r f s) (hr : 0 < r) {d : ℝ} (hd : 0 ≤ d) :
μH[d] (f '' s) ≤ (C : ℝ≥0∞) ^ d * μH[r * d] s := by
-- We start with the trivial case `C = 0`
rcases (zero_le C).eq_or_lt with (rfl | hC0)
· rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩)
· simp only [measure_empty, nonpos_iff_eq_zero, mul_zero, image_empty]
have : f '' s = {f x} :=
have : (f '' s).Subsingleton := by simpa [diam_eq_zero_iff] using h.ediam_image_le
(subsingleton_iff_singleton (mem_image_of_mem f hx)).1 this
rw [this]
rcases eq_or_lt_of_le hd with (rfl | h'd)
· simp only [ENNReal.rpow_zero, one_mul, mul_zero]
rw [hausdorffMeasure_zero_singleton]
exact one_le_hausdorffMeasure_zero_of_nonempty ⟨x, hx⟩
· haveI := noAtoms_hausdorff Y h'd
simp only [zero_le, measure_singleton]
-- Now assume `C ≠ 0`
· have hCd0 : (C : ℝ≥0∞) ^ d ≠ 0 := by simp [hC0.ne']
have hCd : (C : ℝ≥0∞) ^ d ≠ ∞ := by simp [hd]
simp only [hausdorffMeasure_apply, ENNReal.mul_iSup, ENNReal.mul_iInf_of_ne hCd0 hCd,
← ENNReal.tsum_mul_left]
refine iSup_le fun R => iSup_le fun hR => ?_
have : Tendsto (fun d : ℝ≥0∞ => (C : ℝ≥0∞) * d ^ (r : ℝ)) (𝓝 0) (𝓝 0) :=
ENNReal.tendsto_const_mul_rpow_nhds_zero_of_pos ENNReal.coe_ne_top hr
rcases ENNReal.nhds_zero_basis_Iic.eventually_iff.1 (this.eventually (gt_mem_nhds hR)) with
⟨δ, δ0, H⟩
refine le_iSup₂_of_le δ δ0 <| iInf₂_mono' fun t hst ↦
⟨fun n => f '' (t n ∩ s), ?_, iInf_mono' fun htδ ↦
⟨fun n => (h.ediam_image_inter_le (t n)).trans (H (htδ n)).le, ?_⟩⟩
· rw [← image_iUnion, ← iUnion_inter]
exact image_subset _ (subset_inter hst Subset.rfl)
· refine ENNReal.tsum_le_tsum fun n => ?_
simp only [iSup_le_iff, image_nonempty]
intro hft
simp only [Nonempty.mono ((t n).inter_subset_left) hft, ciSup_pos]
rw [ENNReal.rpow_mul, ← ENNReal.mul_rpow_of_nonneg _ _ hd]
exact ENNReal.rpow_le_rpow (h.ediam_image_inter_le _) hd
end HolderOnWith
namespace LipschitzOnWith
variable {K : ℝ≥0} {f : X → Y} {s t : Set X}
/-- If `f : X → Y` is `K`-Lipschitz on `s`, then `μH[d] (f '' s) ≤ K ^ d * μH[d] s`. -/
theorem hausdorffMeasure_image_le (h : LipschitzOnWith K f s) {d : ℝ} (hd : 0 ≤ d) :
μH[d] (f '' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := by
simpa only [NNReal.coe_one, one_mul] using h.holderOnWith.hausdorffMeasure_image_le zero_lt_one hd
end LipschitzOnWith
namespace LipschitzWith
variable {K : ℝ≥0} {f : X → Y}
/-- If `f` is a `K`-Lipschitz map, then it increases the Hausdorff `d`-measures of sets at most
by the factor of `K ^ d`. -/
theorem hausdorffMeasure_image_le (h : LipschitzWith K f) {d : ℝ} (hd : 0 ≤ d) (s : Set X) :
μH[d] (f '' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s :=
(h.lipschitzOnWith s).hausdorffMeasure_image_le hd
end LipschitzWith
open scoped Pointwise
theorem MeasureTheory.Measure.hausdorffMeasure_smul₀ {𝕜 E : Type*} [NormedAddCommGroup E]
[NormedField 𝕜] [NormedSpace 𝕜 E] [MeasurableSpace E] [BorelSpace E] {d : ℝ} (hd : 0 ≤ d)
{r : 𝕜} (hr : r ≠ 0) (s : Set E) : μH[d] (r • s) = ‖r‖₊ ^ d • μH[d] s := by
suffices ∀ {r : 𝕜}, r ≠ 0 → ∀ s : Set E, μH[d] (r • s) ≤ ‖r‖₊ ^ d • μH[d] s by
refine le_antisymm (this hr s) ?_
rw [← le_inv_smul_iff_of_pos]
· dsimp
rw [← NNReal.inv_rpow, ← nnnorm_inv]
· refine Eq.trans_le ?_ (this (inv_ne_zero hr) (r • s))
rw [inv_smul_smul₀ hr]
· simp [pos_iff_ne_zero, hr]
intro r _ s
simp only [NNReal.rpow_eq_pow, ENNReal.smul_def, ← ENNReal.coe_rpow_of_nonneg _ hd, smul_eq_mul]
exact (lipschitzWith_smul (β := E) r).hausdorffMeasure_image_le hd s
/-!
### Antilipschitz maps do not decrease Hausdorff measures and dimension
-/
namespace AntilipschitzWith
variable {f : X → Y} {K : ℝ≥0} {d : ℝ}
theorem hausdorffMeasure_preimage_le (hf : AntilipschitzWith K f) (hd : 0 ≤ d) (s : Set Y) :
μH[d] (f ⁻¹' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := by
rcases eq_or_ne K 0 with (rfl | h0)
· rcases eq_empty_or_nonempty (f ⁻¹' s) with (hs | ⟨x, hx⟩)
· simp only [hs, measure_empty, zero_le]
have : f ⁻¹' s = {x} := by
haveI : Subsingleton X := hf.subsingleton
have : (f ⁻¹' s).Subsingleton := subsingleton_univ.anti (subset_univ _)
exact (subsingleton_iff_singleton hx).1 this
rw [this]
rcases eq_or_lt_of_le hd with (rfl | h'd)
· simp only [ENNReal.rpow_zero, one_mul, mul_zero]
rw [hausdorffMeasure_zero_singleton]
exact one_le_hausdorffMeasure_zero_of_nonempty ⟨f x, hx⟩
· haveI := noAtoms_hausdorff X h'd
simp only [zero_le, measure_singleton]
have hKd0 : (K : ℝ≥0∞) ^ d ≠ 0 := by simp [h0]
have hKd : (K : ℝ≥0∞) ^ d ≠ ∞ := by simp [hd]
simp only [hausdorffMeasure_apply, ENNReal.mul_iSup, ENNReal.mul_iInf_of_ne hKd0 hKd,
← ENNReal.tsum_mul_left]
refine iSup₂_le fun ε ε0 => ?_
refine le_iSup₂_of_le (ε / K) (by simp [ε0.ne']) ?_
refine le_iInf₂ fun t hst => le_iInf fun htε => ?_
replace hst : f ⁻¹' s ⊆ _ := preimage_mono hst; rw [preimage_iUnion] at hst
refine iInf₂_le_of_le _ hst (iInf_le_of_le (fun n => ?_) ?_)
· exact (hf.ediam_preimage_le _).trans (ENNReal.mul_le_of_le_div' <| htε n)
· refine ENNReal.tsum_le_tsum fun n => iSup_le_iff.2 fun hft => ?_
simp only [nonempty_of_nonempty_preimage hft, ciSup_pos]
rw [← ENNReal.mul_rpow_of_nonneg _ _ hd]
exact ENNReal.rpow_le_rpow (hf.ediam_preimage_le _) hd
theorem le_hausdorffMeasure_image (hf : AntilipschitzWith K f) (hd : 0 ≤ d) (s : Set X) :
μH[d] s ≤ (K : ℝ≥0∞) ^ d * μH[d] (f '' s) :=
calc
μH[d] s ≤ μH[d] (f ⁻¹' (f '' s)) := measure_mono (subset_preimage_image _ _)
_ ≤ (K : ℝ≥0∞) ^ d * μH[d] (f '' s) := hf.hausdorffMeasure_preimage_le hd (f '' s)
end AntilipschitzWith
/-!
### Isometries preserve the Hausdorff measure and Hausdorff dimension
-/
namespace Isometry
variable {f : X → Y} {d : ℝ}
theorem hausdorffMeasure_image (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) (s : Set X) :
μH[d] (f '' s) = μH[d] s := by
simp only [hausdorffMeasure, ← OuterMeasure.coe_mkMetric, ← OuterMeasure.comap_apply]
rw [OuterMeasure.isometry_comap_mkMetric _ hf (hd.imp_left _)]
exact ENNReal.monotone_rpow_of_nonneg
theorem hausdorffMeasure_preimage (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) (s : Set Y) :
μH[d] (f ⁻¹' s) = μH[d] (s ∩ range f) := by
rw [← hf.hausdorffMeasure_image hd, image_preimage_eq_inter_range]
theorem map_hausdorffMeasure (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) :
Measure.map f μH[d] = μH[d].restrict (range f) := by
ext1 s hs
rw [map_apply hf.continuous.measurable hs, Measure.restrict_apply hs,
hf.hausdorffMeasure_preimage hd]
end Isometry
namespace IsometryEquiv
@[simp]
theorem hausdorffMeasure_image (e : X ≃ᵢ Y) (d : ℝ) (s : Set X) : μH[d] (e '' s) = μH[d] s :=
e.isometry.hausdorffMeasure_image (Or.inr e.surjective) s
@[simp]
theorem hausdorffMeasure_preimage (e : X ≃ᵢ Y) (d : ℝ) (s : Set Y) : μH[d] (e ⁻¹' s) = μH[d] s := by
rw [← e.image_symm, e.symm.hausdorffMeasure_image]
@[simp]
theorem map_hausdorffMeasure (e : X ≃ᵢ Y) (d : ℝ) : Measure.map e μH[d] = μH[d] := by
rw [e.isometry.map_hausdorffMeasure (Or.inr e.surjective), e.surjective.range_eq, restrict_univ]
theorem measurePreserving_hausdorffMeasure (e : X ≃ᵢ Y) (d : ℝ) : MeasurePreserving e μH[d] μH[d] :=
⟨e.continuous.measurable, map_hausdorffMeasure _ _⟩
end IsometryEquiv
namespace MeasureTheory
@[to_additive]
theorem hausdorffMeasure_smul {α : Type*} [SMul α X] [IsometricSMul α X] {d : ℝ} (c : α)
(h : 0 ≤ d ∨ Surjective (c • · : X → X)) (s : Set X) : μH[d] (c • s) = μH[d] s :=
(isometry_smul X c).hausdorffMeasure_image h _
@[to_additive]
instance {d : ℝ} [Group X] [IsometricSMul X X] : IsMulLeftInvariant (μH[d] : Measure X) where
map_mul_left_eq_self x := (IsometryEquiv.constSMul x).map_hausdorffMeasure _
@[to_additive]
instance {d : ℝ} [Group X] [IsometricSMul Xᵐᵒᵖ X] : IsMulRightInvariant (μH[d] : Measure X) where
map_mul_right_eq_self x := (IsometryEquiv.constSMul (MulOpposite.op x)).map_hausdorffMeasure _
/-!
### Hausdorff measure and Lebesgue measure
-/
/-- In the space `ι → ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/
@[simp]
theorem hausdorffMeasure_pi_real {ι : Type*} [Fintype ι] :
(μH[Fintype.card ι] : Measure (ι → ℝ)) = volume := by
classical
-- it suffices to check that the two measures coincide on products of rational intervals
refine (pi_eq_generateFrom (fun _ => Real.borel_eq_generateFrom_Ioo_rat.symm)
(fun _ => Real.isPiSystem_Ioo_rat) (fun _ => Real.finiteSpanningSetsInIooRat _) ?_).symm
simp only [mem_iUnion, mem_singleton_iff]
-- fix such a product `s` of rational intervals, of the form `Π (a i, b i)`.
intro s hs
choose a b H using hs
obtain rfl : s = fun i => Ioo (α := ℝ) (a i) (b i) := funext fun i => (H i).2
replace H := fun i => (H i).1
apply le_antisymm _
-- first check that `volume s ≤ μH s`
· have Hle : volume ≤ (μH[Fintype.card ι] : Measure (ι → ℝ)) := by
refine le_hausdorffMeasure _ _ ∞ ENNReal.coe_lt_top fun s _ => ?_
rw [ENNReal.rpow_natCast]
exact Real.volume_pi_le_diam_pow s
rw [← volume_pi_pi fun i => Ioo (a i : ℝ) (b i)]
exact Measure.le_iff'.1 Hle _
/- For the other inequality `μH s ≤ volume s`, we use a covering of `s` by sets of small diameter
`1/n`, namely cubes with left-most point of the form `a i + f i / n` with `f i` ranging between
`0` and `⌈(b i - a i) * n⌉`. Their number is asymptotic to `n^d * Π (b i - a i)`. -/
have I : ∀ i, 0 ≤ (b i : ℝ) - a i := fun i => by
simpa only [sub_nonneg, Rat.cast_le] using (H i).le
let γ := fun n : ℕ => ∀ i : ι, Fin ⌈((b i : ℝ) - a i) * n⌉₊
let t : ∀ n : ℕ, γ n → Set (ι → ℝ) := fun n f =>
Set.pi univ fun i => Icc (a i + f i / n) (a i + (f i + 1) / n)
have A : Tendsto (fun n : ℕ => 1 / (n : ℝ≥0∞)) atTop (𝓝 0) := by
simp only [one_div, ENNReal.tendsto_inv_nat_nhds_zero]
have B : ∀ᶠ n in atTop, ∀ i : γ n, diam (t n i) ≤ 1 / n := by
refine eventually_atTop.2 ⟨1, fun n hn => ?_⟩
intro f
refine diam_pi_le_of_le fun b => ?_
simp only [Real.ediam_Icc, add_div, ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr hn), le_refl,
add_sub_add_left_eq_sub, add_sub_cancel_left, ENNReal.ofReal_one, ENNReal.ofReal_natCast]
have C : ∀ᶠ n in atTop, (Set.pi univ fun i : ι => Ioo (a i : ℝ) (b i)) ⊆ ⋃ i : γ n, t n i := by
refine eventually_atTop.2 ⟨1, fun n hn => ?_⟩
have npos : (0 : ℝ) < n := Nat.cast_pos.2 hn
intro x hx
simp only [mem_Ioo, mem_univ_pi] at hx
simp only [t, mem_iUnion, mem_Ioo, mem_univ_pi]
let f : γ n := fun i =>
⟨⌊(x i - a i) * n⌋₊, by
apply Nat.floor_lt_ceil_of_lt_of_pos
· refine (mul_lt_mul_right npos).2 ?_
simp only [(hx i).right, sub_lt_sub_iff_right]
· refine mul_pos ?_ npos
simpa only [Rat.cast_lt, sub_pos] using H i⟩
refine ⟨f, fun i => ⟨?_, ?_⟩⟩
· calc
(a i : ℝ) + ⌊(x i - a i) * n⌋₊ / n ≤ (a i : ℝ) + (x i - a i) * n / n := by
gcongr
exact Nat.floor_le (mul_nonneg (sub_nonneg.2 (hx i).1.le) npos.le)
_ = x i := by field_simp [npos.ne']
· calc
x i = (a i : ℝ) + (x i - a i) * n / n := by field_simp [npos.ne']
_ ≤ (a i : ℝ) + (⌊(x i - a i) * n⌋₊ + 1) / n := by
gcongr
exact (Nat.lt_floor_add_one _).le
calc
μH[Fintype.card ι] (Set.pi univ fun i : ι => Ioo (a i : ℝ) (b i)) ≤
liminf (fun n : ℕ => ∑ i : γ n, diam (t n i) ^ ((Fintype.card ι) : ℝ)) atTop :=
hausdorffMeasure_le_liminf_sum _ (Set.pi univ fun i => Ioo (a i : ℝ) (b i))
(fun n : ℕ => 1 / (n : ℝ≥0∞)) A t B C
_ ≤ liminf (fun n : ℕ => ∑ i : γ n, (1 / (n : ℝ≥0∞)) ^ Fintype.card ι) atTop := by
refine liminf_le_liminf ?_ ?_
· filter_upwards [B] with _ hn
apply Finset.sum_le_sum fun i _ => _
simp only [ENNReal.rpow_natCast]
intros i _
exact pow_le_pow_left' (hn i) _
· isBoundedDefault
_ = liminf (fun n : ℕ => ∏ i : ι, (⌈((b i : ℝ) - a i) * n⌉₊ : ℝ≥0∞) / n) atTop := by
simp only [γ, Finset.card_univ, Nat.cast_prod, one_mul, Fintype.card_fin, Finset.sum_const,
nsmul_eq_mul, Fintype.card_pi, div_eq_mul_inv, Finset.prod_mul_distrib, Finset.prod_const]
_ = ∏ i : ι, volume (Ioo (a i : ℝ) (b i)) := by
simp only [Real.volume_Ioo]
apply Tendsto.liminf_eq
refine ENNReal.tendsto_finset_prod_of_ne_top _ (fun i _ => ?_) fun i _ => ?_
· apply
Tendsto.congr' _
((ENNReal.continuous_ofReal.tendsto _).comp
((tendsto_nat_ceil_mul_div_atTop (I i)).comp tendsto_natCast_atTop_atTop))
apply eventually_atTop.2 ⟨1, fun n hn => _⟩
intros n hn
simp only [ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr hn), comp_apply,
ENNReal.ofReal_natCast]
· simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff]
variable (ι X)
theorem hausdorffMeasure_measurePreserving_funUnique [Unique ι]
[SecondCountableTopology X] (d : ℝ) :
MeasurePreserving (MeasurableEquiv.funUnique ι X) μH[d] μH[d] :=
(IsometryEquiv.funUnique ι X).measurePreserving_hausdorffMeasure _
theorem hausdorffMeasure_measurePreserving_piFinTwo (α : Fin 2 → Type*)
[∀ i, MeasurableSpace (α i)] [∀ i, EMetricSpace (α i)] [∀ i, BorelSpace (α i)]
[∀ i, SecondCountableTopology (α i)] (d : ℝ) :
MeasurePreserving (MeasurableEquiv.piFinTwo α) μH[d] μH[d] :=
(IsometryEquiv.piFinTwo α).measurePreserving_hausdorffMeasure _
/-- In the space `ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/
@[simp]
theorem hausdorffMeasure_real : (μH[1] : Measure ℝ) = volume := by
rw [← (volume_preserving_funUnique Unit ℝ).map_eq,
← (hausdorffMeasure_measurePreserving_funUnique Unit ℝ 1).map_eq,
← hausdorffMeasure_pi_real, Fintype.card_unit, Nat.cast_one]
/-- In the space `ℝ × ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/
@[simp]
theorem hausdorffMeasure_prod_real : (μH[2] : Measure (ℝ × ℝ)) = volume := by
rw [← (volume_preserving_piFinTwo fun _ => ℝ).map_eq,
← (hausdorffMeasure_measurePreserving_piFinTwo (fun _ => ℝ) _).map_eq,
← hausdorffMeasure_pi_real, Fintype.card_fin, Nat.cast_two]
/-! ### Geometric results in affine spaces -/
section Geometric
variable {𝕜 E P : Type*}
theorem hausdorffMeasure_smul_right_image [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] (v : E) (s : Set ℝ) :
μH[1] ((fun r => r • v) '' s) = ‖v‖₊ • μH[1] s := by
obtain rfl | hv := eq_or_ne v 0
· haveI := noAtoms_hausdorff E one_pos
obtain rfl | hs := s.eq_empty_or_nonempty
· simp
simp [hs]
have hn : ‖v‖ ≠ 0 := norm_ne_zero_iff.mpr hv
-- break lineMap into pieces
suffices
μH[1] ((‖v‖ • ·) '' (LinearMap.toSpanSingleton ℝ E (‖v‖⁻¹ • v) '' s)) = ‖v‖₊ • μH[1] s by
-- Porting note: proof was shorter, could need some golf
simp only [hausdorffMeasure_real, nnreal_smul_coe_apply]
convert this
· simp only [image_smul, LinearMap.toSpanSingleton_apply, Set.image_image]
ext e
simp only [mem_image]
refine ⟨fun ⟨x, h⟩ => ⟨x, ?_⟩, fun ⟨x, h⟩ => ⟨x, ?_⟩⟩
· rw [smul_comm (norm _), smul_comm (norm _), inv_smul_smul₀ hn]
exact h
· rw [smul_comm (norm _), smul_comm (norm _), inv_smul_smul₀ hn] at h
exact h
· exact hausdorffMeasure_real.symm
have iso_smul : Isometry (LinearMap.toSpanSingleton ℝ E (‖v‖⁻¹ • v)) := by
refine AddMonoidHomClass.isometry_of_norm _ fun x => (norm_smul _ _).trans ?_
rw [norm_smul, norm_inv, norm_norm, inv_mul_cancel hn, mul_one, LinearMap.id_apply]
rw [Set.image_smul, Measure.hausdorffMeasure_smul₀ zero_le_one hn, nnnorm_norm,
NNReal.rpow_one, iso_smul.hausdorffMeasure_image (Or.inl <| zero_le_one' ℝ)]
section NormedFieldAffine
variable [NormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [MeasurableSpace P]
variable [MetricSpace P] [NormedAddTorsor E P] [BorelSpace P]
/-- Scaling by `c` around `x` scales the measure by `‖c‖₊ ^ d`. -/
theorem hausdorffMeasure_homothety_image {d : ℝ} (hd : 0 ≤ d) (x : P) {c : 𝕜} (hc : c ≠ 0)
(s : Set P) : μH[d] (AffineMap.homothety x c '' s) = ‖c‖₊ ^ d • μH[d] s := by
suffices
μH[d] (IsometryEquiv.vaddConst x '' ((c • ·) '' ((IsometryEquiv.vaddConst x).symm '' s))) =
‖c‖₊ ^ d • μH[d] s by
simpa only [Set.image_image]
borelize E
rw [IsometryEquiv.hausdorffMeasure_image, Set.image_smul, Measure.hausdorffMeasure_smul₀ hd hc,
IsometryEquiv.hausdorffMeasure_image]
theorem hausdorffMeasure_homothety_preimage {d : ℝ} (hd : 0 ≤ d) (x : P) {c : 𝕜} (hc : c ≠ 0)
(s : Set P) : μH[d] (AffineMap.homothety x c ⁻¹' s) = ‖c‖₊⁻¹ ^ d • μH[d] s := by
change μH[d] (AffineEquiv.homothetyUnitsMulHom x (Units.mk0 c hc) ⁻¹' s) = _
rw [← AffineEquiv.image_symm, AffineEquiv.coe_homothetyUnitsMulHom_apply_symm,
hausdorffMeasure_homothety_image hd x (_ : 𝕜ˣ).isUnit.ne_zero, Units.val_inv_eq_inv_val,
Units.val_mk0, nnnorm_inv]
/-! TODO: prove `Measure.map (AffineMap.homothety x c) μH[d] = ‖c‖₊⁻¹ ^ d • μH[d]`, which needs a
more general version of `AffineMap.homothety_continuous`. -/
end NormedFieldAffine
section RealAffine
variable [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace P]
variable [MetricSpace P] [NormedAddTorsor E P] [BorelSpace P]
/-- Mapping a set of reals along a line segment scales the measure by the length of a segment.
This is an auxiliary result used to prove `hausdorffMeasure_affineSegment`. -/
theorem hausdorffMeasure_lineMap_image (x y : P) (s : Set ℝ) :
μH[1] (AffineMap.lineMap x y '' s) = nndist x y • μH[1] s := by
suffices μH[1] (IsometryEquiv.vaddConst x '' ((· • (y -ᵥ x)) '' s)) = nndist x y • μH[1] s by
simpa only [Set.image_image]
borelize E
rw [IsometryEquiv.hausdorffMeasure_image, hausdorffMeasure_smul_right_image,
nndist_eq_nnnorm_vsub' E]
/-- The measure of a segment is the distance between its endpoints. -/
@[simp]
theorem hausdorffMeasure_affineSegment (x y : P) : μH[1] (affineSegment ℝ x y) = edist x y := by
rw [affineSegment, hausdorffMeasure_lineMap_image, hausdorffMeasure_real, Real.volume_Icc,
sub_zero, ENNReal.ofReal_one, ← Algebra.algebraMap_eq_smul_one]
exact (edist_nndist _ _).symm
end RealAffine
/-- The measure of a segment is the distance between its endpoints. -/
@[simp]
theorem hausdorffMeasure_segment {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] (x y : E) : μH[1] (segment ℝ x y) = edist x y := by
rw [← affineSegment_eq_segment, hausdorffMeasure_affineSegment]
end Geometric
end MeasureTheory
|
MeasureTheory\Measure\LevyProkhorovMetric.lean | /-
Copyright (c) 2023 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.Portmanteau
import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.MeasureTheory.Integral.Layercake
import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction
/-!
# The Lévy-Prokhorov distance on spaces of finite measures and probability measures
## Main definitions
* `MeasureTheory.levyProkhorovEDist`: The Lévy-Prokhorov edistance between two measures.
* `MeasureTheory.levyProkhorovDist`: The Lévy-Prokhorov distance between two finite measures.
## Main results
* `levyProkhorovDist_pseudoMetricSpace_finiteMeasure`: The Lévy-Prokhorov distance is a
pseudoemetric on the space of finite measures.
* `levyProkhorovDist_pseudoMetricSpace_probabilityMeasure`: The Lévy-Prokhorov distance is a
pseudoemetric on the space of probability measures.
* `levyProkhorov_le_convergenceInDistribution`: The topology of the Lévy-Prokhorov metric on
probability measures is always at least as fine as the topology of convergence in distribution.
* `levyProkhorov_eq_convergenceInDistribution`: The topology of the Lévy-Prokhorov metric on
probability measures on a separable space coincides with the topology of convergence in
distribution, and in particular convergence in distribution is then pseudometrizable.
## TODO
* Show that in Borel spaces, the Lévy-Prokhorov distance is a metric; not just a pseudometric.
## Tags
finite measure, probability measure, weak convergence, convergence in distribution, metrizability
-/
open Topology Metric Filter Set ENNReal NNReal
namespace MeasureTheory
open scoped Topology ENNReal NNReal BoundedContinuousFunction
section Levy_Prokhorov
/-! ### Lévy-Prokhorov metric -/
variable {ι : Type*} {Ω : Type*} [MeasurableSpace Ω] [PseudoEMetricSpace Ω]
/-- The Lévy-Prokhorov edistance between measures:
`d(μ,ν) = inf {r ≥ 0 | ∀ B, μ B ≤ ν Bᵣ + r ∧ ν B ≤ μ Bᵣ + r}`. -/
noncomputable def levyProkhorovEDist (μ ν : Measure Ω) : ℝ≥0∞ :=
sInf {ε | ∀ B, MeasurableSet B →
μ B ≤ ν (thickening ε.toReal B) + ε ∧ ν B ≤ μ (thickening ε.toReal B) + ε}
/- This result is not placed in earlier more generic files, since it is rather specialized;
it mixes measure and metric in a very particular way. -/
lemma meas_le_of_le_of_forall_le_meas_thickening_add {ε₁ ε₂ : ℝ≥0∞} (μ ν : Measure Ω)
(h_le : ε₁ ≤ ε₂) {B : Set Ω} (hε₁ : μ B ≤ ν (thickening ε₁.toReal B) + ε₁) :
μ B ≤ ν (thickening ε₂.toReal B) + ε₂ := by
by_cases ε_top : ε₂ = ∞
· simp only [ne_eq, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure, ε_top, top_toReal,
add_top, le_top]
apply hε₁.trans (add_le_add ?_ h_le)
exact measure_mono (μ := ν) (thickening_mono (toReal_mono ε_top h_le) B)
lemma left_measure_le_of_levyProkhorovEDist_lt {μ ν : Measure Ω} {c : ℝ≥0∞}
(h : levyProkhorovEDist μ ν < c) {B : Set Ω} (B_mble : MeasurableSet B) :
μ B ≤ ν (thickening c.toReal B) + c := by
obtain ⟨c', ⟨hc', lt_c⟩⟩ := sInf_lt_iff.mp h
exact meas_le_of_le_of_forall_le_meas_thickening_add μ ν lt_c.le (hc' B B_mble).1
lemma right_measure_le_of_levyProkhorovEDist_lt {μ ν : Measure Ω} {c : ℝ≥0∞}
(h : levyProkhorovEDist μ ν < c) {B : Set Ω} (B_mble : MeasurableSet B) :
ν B ≤ μ (thickening c.toReal B) + c := by
obtain ⟨c', ⟨hc', lt_c⟩⟩ := sInf_lt_iff.mp h
exact meas_le_of_le_of_forall_le_meas_thickening_add ν μ lt_c.le (hc' B B_mble).2
/-- A general sufficient condition for bounding `levyProkhorovEDist` from above. -/
lemma levyProkhorovEDist_le_of_forall_add_pos_le (μ ν : Measure Ω) (δ : ℝ≥0∞)
(h : ∀ ε B, 0 < ε → ε < ∞ → MeasurableSet B →
μ B ≤ ν (thickening (δ + ε).toReal B) + δ + ε ∧
ν B ≤ μ (thickening (δ + ε).toReal B) + δ + ε) :
levyProkhorovEDist μ ν ≤ δ := by
apply ENNReal.le_of_forall_pos_le_add
intro ε hε _
by_cases ε_top : ε = ∞
· simp only [ε_top, add_top, le_top]
apply sInf_le
intro B B_mble
simpa only [add_assoc] using h ε B (coe_pos.mpr hε) coe_lt_top B_mble
/-- A simple general sufficient condition for bounding `levyProkhorovEDist` from above. -/
lemma levyProkhorovEDist_le_of_forall (μ ν : Measure Ω) (δ : ℝ≥0∞)
(h : ∀ ε B, δ < ε → ε < ∞ → MeasurableSet B →
μ B ≤ ν (thickening ε.toReal B) + ε ∧ ν B ≤ μ (thickening ε.toReal B) + ε) :
levyProkhorovEDist μ ν ≤ δ := by
by_cases δ_top : δ = ∞
· simp only [δ_top, add_top, le_top]
apply levyProkhorovEDist_le_of_forall_add_pos_le
intro x B x_pos x_lt_top B_mble
simpa only [← add_assoc] using h (δ + x) B (ENNReal.lt_add_right δ_top x_pos.ne.symm)
(by simp only [add_lt_top, Ne.lt_top δ_top, x_lt_top, and_self]) B_mble
lemma levyProkhorovEDist_le_max_measure_univ (μ ν : Measure Ω) :
levyProkhorovEDist μ ν ≤ max (μ univ) (ν univ) := by
refine sInf_le fun B _ ↦ ⟨?_, ?_⟩ <;> apply le_add_left <;> simp [measure_mono]
lemma levyProkhorovEDist_lt_top (μ ν : Measure Ω) [IsFiniteMeasure μ] [IsFiniteMeasure ν] :
levyProkhorovEDist μ ν < ∞ :=
(levyProkhorovEDist_le_max_measure_univ μ ν).trans_lt <| by simp [measure_lt_top]
lemma levyProkhorovEDist_ne_top (μ ν : Measure Ω) [IsFiniteMeasure μ] [IsFiniteMeasure ν] :
levyProkhorovEDist μ ν ≠ ∞ := (levyProkhorovEDist_lt_top μ ν).ne
lemma levyProkhorovEDist_self (μ : Measure Ω) :
levyProkhorovEDist μ μ = 0 := by
rw [← nonpos_iff_eq_zero, ← csInf_Ioo zero_lt_top]
refine sInf_le_sInf fun ε ⟨hε₀, hε_top⟩ B _ ↦ and_self_iff.2 ?_
refine le_add_right <| measure_mono <| self_subset_thickening ?_ _
exact ENNReal.toReal_pos hε₀.ne' hε_top.ne
lemma levyProkhorovEDist_comm (μ ν : Measure Ω) :
levyProkhorovEDist μ ν = levyProkhorovEDist ν μ := by
simp only [levyProkhorovEDist, and_comm]
lemma levyProkhorovEDist_triangle [OpensMeasurableSpace Ω] (μ ν κ : Measure Ω) :
levyProkhorovEDist μ κ ≤ levyProkhorovEDist μ ν + levyProkhorovEDist ν κ := by
by_cases LPμν_finite : levyProkhorovEDist μ ν = ∞
· simp [LPμν_finite]
by_cases LPνκ_finite : levyProkhorovEDist ν κ = ∞
· simp [LPνκ_finite]
apply levyProkhorovEDist_le_of_forall_add_pos_le
intro ε B ε_pos ε_lt_top B_mble
have half_ε_pos : 0 < ε / 2 := ENNReal.div_pos ε_pos.ne' two_ne_top
have half_ε_lt_top : ε / 2 < ∞ := ENNReal.div_lt_top ε_lt_top.ne two_ne_zero
let r := levyProkhorovEDist μ ν + ε / 2
let s := levyProkhorovEDist ν κ + ε / 2
have lt_r : levyProkhorovEDist μ ν < r := lt_add_right LPμν_finite half_ε_pos.ne'
have lt_s : levyProkhorovEDist ν κ < s := lt_add_right LPνκ_finite half_ε_pos.ne'
have hs_add_r : s + r = levyProkhorovEDist μ ν + levyProkhorovEDist ν κ + ε := by
simp_rw [s, r, add_assoc, add_comm (ε / 2), add_assoc, ENNReal.add_halves, ← add_assoc,
add_comm (levyProkhorovEDist μ ν)]
have hs_add_r' : s.toReal + r.toReal
= (levyProkhorovEDist μ ν + levyProkhorovEDist ν κ + ε).toReal := by
rw [← hs_add_r, ← ENNReal.toReal_add]
· exact ENNReal.add_ne_top.mpr ⟨LPνκ_finite, half_ε_lt_top.ne⟩
· exact ENNReal.add_ne_top.mpr ⟨LPμν_finite, half_ε_lt_top.ne⟩
rw [← hs_add_r', add_assoc, ← hs_add_r, add_assoc _ _ ε, ← hs_add_r]
refine ⟨?_, ?_⟩
· calc μ B ≤ ν (thickening r.toReal B) + r :=
left_measure_le_of_levyProkhorovEDist_lt lt_r B_mble
_ ≤ κ (thickening s.toReal (thickening r.toReal B)) + s + r :=
add_le_add_right
(left_measure_le_of_levyProkhorovEDist_lt lt_s isOpen_thickening.measurableSet) _
_ = κ (thickening s.toReal (thickening r.toReal B)) + (s + r) := add_assoc _ _ _
_ ≤ κ (thickening (s.toReal + r.toReal) B) + (s + r) :=
add_le_add_right (measure_mono (thickening_thickening_subset _ _ _)) _
· calc κ B ≤ ν (thickening s.toReal B) + s :=
right_measure_le_of_levyProkhorovEDist_lt lt_s B_mble
_ ≤ μ (thickening r.toReal (thickening s.toReal B)) + r + s :=
add_le_add_right
(right_measure_le_of_levyProkhorovEDist_lt lt_r isOpen_thickening.measurableSet) s
_ = μ (thickening r.toReal (thickening s.toReal B)) + (s + r) := by rw [add_assoc, add_comm r]
_ ≤ μ (thickening (r.toReal + s.toReal) B) + (s + r) :=
add_le_add_right (measure_mono (thickening_thickening_subset _ _ _)) _
_ = μ (thickening (s.toReal + r.toReal) B) + (s + r) := by rw [add_comm r.toReal]
/-- The Lévy-Prokhorov distance between finite measures:
`d(μ,ν) = inf {r ≥ 0 | ∀ B, μ B ≤ ν Bᵣ + r ∧ ν B ≤ μ Bᵣ + r}`. -/
noncomputable def levyProkhorovDist (μ ν : Measure Ω) : ℝ :=
(levyProkhorovEDist μ ν).toReal
lemma levyProkhorovDist_self (μ : Measure Ω) :
levyProkhorovDist μ μ = 0 := by
simp only [levyProkhorovDist, levyProkhorovEDist_self, zero_toReal]
lemma levyProkhorovDist_comm (μ ν : Measure Ω) :
levyProkhorovDist μ ν = levyProkhorovDist ν μ := by
simp only [levyProkhorovDist, levyProkhorovEDist_comm]
lemma levyProkhorovDist_triangle [OpensMeasurableSpace Ω] (μ ν κ : Measure Ω)
[IsFiniteMeasure μ] [IsFiniteMeasure ν] [IsFiniteMeasure κ] :
levyProkhorovDist μ κ ≤ levyProkhorovDist μ ν + levyProkhorovDist ν κ := by
have dμκ_finite := (levyProkhorovEDist_lt_top μ κ).ne
have dμν_finite := (levyProkhorovEDist_lt_top μ ν).ne
have dνκ_finite := (levyProkhorovEDist_lt_top ν κ).ne
convert (ENNReal.toReal_le_toReal (a := levyProkhorovEDist μ κ)
(b := levyProkhorovEDist μ ν + levyProkhorovEDist ν κ)
_ _).mpr <| levyProkhorovEDist_triangle μ ν κ
· simp only [levyProkhorovDist, ENNReal.toReal_add dμν_finite dνκ_finite]
· exact dμκ_finite
· exact ENNReal.add_ne_top.mpr ⟨dμν_finite, dνκ_finite⟩
/-- A type synonym, to be used for `Measure α`, `FiniteMeasure α`, or `ProbabilityMeasure α`,
when they are to be equipped with the Lévy-Prokhorov distance. -/
def LevyProkhorov (α : Type*) := α
variable [OpensMeasurableSpace Ω]
/-- The Lévy-Prokhorov distance `levyProkhorovEDist` makes `Measure Ω` a pseudoemetric
space. The instance is recorded on the type synonym `LevyProkhorov (Measure Ω) := Measure Ω`. -/
noncomputable instance : PseudoEMetricSpace (LevyProkhorov (Measure Ω)) where
edist := levyProkhorovEDist
edist_self := levyProkhorovEDist_self
edist_comm := levyProkhorovEDist_comm
edist_triangle := levyProkhorovEDist_triangle
/-- The Lévy-Prokhorov distance `levyProkhorovDist` makes `FiniteMeasure Ω` a pseudometric
space. The instance is recorded on the type synonym
`LevyProkhorov (FiniteMeasure Ω) := FiniteMeasure Ω`. -/
noncomputable instance levyProkhorovDist_pseudoMetricSpace_finiteMeasure :
PseudoMetricSpace (LevyProkhorov (FiniteMeasure Ω)) where
dist μ ν := levyProkhorovDist μ.toMeasure ν.toMeasure
dist_self μ := levyProkhorovDist_self _
dist_comm μ ν := levyProkhorovDist_comm _ _
dist_triangle μ ν κ := levyProkhorovDist_triangle _ _ _
edist_dist μ ν := by simp [← ENNReal.ofReal_coe_nnreal]
/-- The Lévy-Prokhorov distance `levyProkhorovDist` makes `ProbabilityMeasure Ω` a pseudoemetric
space. The instance is recorded on the type synonym
`LevyProkhorov (ProbabilityMeasure Ω) := ProbabilityMeasure Ω`. -/
noncomputable instance levyProkhorovDist_pseudoMetricSpace_probabilityMeasure :
PseudoMetricSpace (LevyProkhorov (ProbabilityMeasure Ω)) where
dist μ ν := levyProkhorovDist μ.toMeasure ν.toMeasure
dist_self μ := levyProkhorovDist_self _
dist_comm μ ν := levyProkhorovDist_comm _ _
dist_triangle μ ν κ := levyProkhorovDist_triangle _ _ _
edist_dist μ ν := by simp [← ENNReal.ofReal_coe_nnreal]
lemma LevyProkhorov.dist_def (μ ν : LevyProkhorov (ProbabilityMeasure Ω)) :
dist μ ν = levyProkhorovDist μ.toMeasure ν.toMeasure := rfl
/-- A simple sufficient condition for bounding `levyProkhorovEDist` between probability measures
from above. The condition involves only one of two natural bounds, the other bound is for free. -/
lemma levyProkhorovEDist_le_of_forall_le
(μ ν : Measure Ω) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (δ : ℝ≥0∞)
(h : ∀ ε B, δ < ε → ε < ∞ → MeasurableSet B → μ B ≤ ν (thickening ε.toReal B) + ε) :
levyProkhorovEDist μ ν ≤ δ := by
apply levyProkhorovEDist_le_of_forall μ ν δ
intro ε B ε_gt ε_lt_top B_mble
refine ⟨h ε B ε_gt ε_lt_top B_mble, ?_⟩
have B_subset := subset_compl_thickening_compl_thickening_self ε.toReal B
apply (measure_mono (μ := ν) B_subset).trans
rw [prob_compl_eq_one_sub isOpen_thickening.measurableSet]
have Tc_mble := (isOpen_thickening (δ := ε.toReal) (E := B)).isClosed_compl.measurableSet
specialize h ε (thickening ε.toReal B)ᶜ ε_gt ε_lt_top Tc_mble
rw [prob_compl_eq_one_sub isOpen_thickening.measurableSet] at h
have almost := add_le_add (c := μ (thickening ε.toReal B)) h rfl.le
rw [tsub_add_cancel_of_le prob_le_one, add_assoc] at almost
apply (tsub_le_tsub_right almost _).trans
rw [ENNReal.add_sub_cancel_left (measure_ne_top ν _), add_comm ε]
/-- A simple sufficient condition for bounding `levyProkhorovDist` between probability measures
from above. The condition involves only one of two natural bounds, the other bound is for free. -/
lemma levyProkhorovDist_le_of_forall_le
(μ ν : Measure Ω) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] {δ : ℝ} (δ_nn : 0 ≤ δ)
(h : ∀ ε B, δ < ε → MeasurableSet B → μ B ≤ ν (thickening ε B) + ENNReal.ofReal ε) :
levyProkhorovDist μ ν ≤ δ := by
apply toReal_le_of_le_ofReal δ_nn
apply levyProkhorovEDist_le_of_forall_le
intro ε B ε_gt ε_lt_top B_mble
have ε_gt' : δ < ε.toReal := by
refine (ofReal_lt_ofReal_iff ?_).mp ?_
· exact ENNReal.toReal_pos (ne_zero_of_lt ε_gt) ε_lt_top.ne
· simpa [ofReal_toReal_eq_iff.mpr ε_lt_top.ne] using ε_gt
convert h ε.toReal B ε_gt' B_mble
exact (ENNReal.ofReal_toReal ε_lt_top.ne).symm
end Levy_Prokhorov --section
section Levy_Prokhorov_is_finer
/-! ### The Lévy-Prokhorov topology is at least as fine as convergence in distribution -/
open BoundedContinuousFunction
variable {ι : Type*} {Ω : Type*} [MeasurableSpace Ω]
/-- Coercion from the type synonym `LevyProkhorov (ProbabilityMeasure Ω)`
to `ProbabilityMeasure Ω`. -/
def LevyProkhorov.toProbabilityMeasure (μ : LevyProkhorov (ProbabilityMeasure Ω)) :
ProbabilityMeasure Ω := μ
/-- Coercion to the type synonym `LevyProkhorov (ProbabilityMeasure Ω)`
from `ProbabilityMeasure Ω`. -/
def ProbabilityMeasure.toLevyProkhorov (μ : ProbabilityMeasure Ω) :
LevyProkhorov (ProbabilityMeasure Ω) := μ
/-- Coercion from the type synonym `LevyProkhorov (FiniteMeasure Ω)` to `FiniteMeasure Ω`. -/
def LevyProkhorov.finiteMeasure (μ : LevyProkhorov (FiniteMeasure Ω)) :
FiniteMeasure Ω := μ
variable [PseudoMetricSpace Ω] [OpensMeasurableSpace Ω]
/-- A version of the layer cake formula for bounded continuous functions which have finite integral:
∫ f dμ = ∫ t in (0, ‖f‖], μ {x | f(x) ≥ t} dt. -/
lemma BoundedContinuousFunction.integral_eq_integral_meas_le_of_hasFiniteIntegral
{α : Type*} [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α]
(f : α →ᵇ ℝ) (μ : Measure α) (f_nn : 0 ≤ᵐ[μ] f) (hf : HasFiniteIntegral f μ) :
∫ ω, f ω ∂μ = ∫ t in Ioc 0 ‖f‖, ENNReal.toReal (μ {a : α | t ≤ f a}) := by
rw [Integrable.integral_eq_integral_Ioc_meas_le (M := ‖f‖) ?_ f_nn ?_]
· refine ⟨f.continuous.measurable.aestronglyMeasurable, hf⟩
· exact eventually_of_forall (fun x ↦ BoundedContinuousFunction.apply_le_norm f x)
/-- A version of the layer cake formula for bounded continuous functions and finite measures:
∫ f dμ = ∫ t in (0, ‖f‖], μ {x | f(x) ≥ t} dt. -/
lemma BoundedContinuousFunction.integral_eq_integral_meas_le
{α : Type*} [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α]
(f : α →ᵇ ℝ) (μ : Measure α) [IsFiniteMeasure μ] (f_nn : 0 ≤ᵐ[μ] f) :
∫ ω, f ω ∂μ = ∫ t in Ioc 0 ‖f‖, ENNReal.toReal (μ {a : α | t ≤ f a}) :=
integral_eq_integral_meas_le_of_hasFiniteIntegral _ _ f_nn (f.integrable μ).2
/-- Assuming `levyProkhorovEDist μ ν < ε`, we can bound `∫ f ∂μ` in terms of
`∫ t in (0, ‖f‖], ν (thickening ε {x | f(x) ≥ t}) dt` and `‖f‖`. -/
lemma BoundedContinuousFunction.integral_le_of_levyProkhorovEDist_lt (μ ν : Measure Ω)
[IsFiniteMeasure μ] [IsFiniteMeasure ν] {ε : ℝ} (ε_pos : 0 < ε)
(hμν : levyProkhorovEDist μ ν < ENNReal.ofReal ε) (f : Ω →ᵇ ℝ) (f_nn : 0 ≤ᵐ[μ] f) :
∫ ω, f ω ∂μ
≤ (∫ t in Ioc 0 ‖f‖, ENNReal.toReal (ν (thickening ε {a | t ≤ f a}))) + ε * ‖f‖ := by
rw [BoundedContinuousFunction.integral_eq_integral_meas_le f μ f_nn]
have key : (fun (t : ℝ) ↦ ENNReal.toReal (μ {a | t ≤ f a}))
≤ (fun (t : ℝ) ↦ ENNReal.toReal (ν (thickening ε {a | t ≤ f a})) + ε) := by
intro t
convert (ENNReal.toReal_le_toReal (measure_ne_top _ _) ?_).mpr
<| left_measure_le_of_levyProkhorovEDist_lt hμν (B := {a | t ≤ f a})
(f.continuous.measurable measurableSet_Ici)
· rw [ENNReal.toReal_add (measure_ne_top ν _) ofReal_ne_top, ENNReal.toReal_ofReal ε_pos.le]
· exact ENNReal.add_ne_top.mpr ⟨measure_ne_top ν _, ofReal_ne_top⟩
have intble₁ : IntegrableOn (fun t ↦ ENNReal.toReal (μ {a | t ≤ f a})) (Ioc 0 ‖f‖) := by
apply Measure.integrableOn_of_bounded (M := ENNReal.toReal (μ univ)) measure_Ioc_lt_top.ne
· apply (Measurable.ennreal_toReal (Antitone.measurable ?_)).aestronglyMeasurable
exact fun _ _ hst ↦ measure_mono (fun _ h ↦ hst.trans h)
· apply eventually_of_forall <| fun t ↦ ?_
simp only [Real.norm_eq_abs, abs_toReal]
exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) (measure_ne_top _ _)).mpr
<| measure_mono (subset_univ _)
have intble₂ : IntegrableOn
(fun t ↦ ENNReal.toReal (ν (thickening ε {a | t ≤ f a}))) (Ioc 0 ‖f‖) := by
apply Measure.integrableOn_of_bounded (M := ENNReal.toReal (ν univ)) measure_Ioc_lt_top.ne
· apply (Measurable.ennreal_toReal (Antitone.measurable ?_)).aestronglyMeasurable
exact fun _ _ hst ↦ measure_mono <| thickening_subset_of_subset ε (fun _ h ↦ hst.trans h)
· apply eventually_of_forall <| fun t ↦ ?_
simp only [Real.norm_eq_abs, abs_toReal]
exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) (measure_ne_top _ _)).mpr
<| measure_mono (subset_univ _)
apply le_trans (setIntegral_mono (s := Ioc 0 ‖f‖) ?_ ?_ key)
· rw [integral_add]
· apply add_le_add_left
simp only [integral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter,
Real.volume_Ioc, sub_zero, norm_nonneg, toReal_ofReal, smul_eq_mul,
(mul_comm _ ε).le]
· exact intble₂
· exact integrable_const ε
· exact intble₁
· exact intble₂.add <| integrable_const ε
/-- A monotone decreasing convergence lemma for integrals of measures of thickenings:
`∫ t in (0, ‖f‖], μ (thickening ε {x | f(x) ≥ t}) dt` tends to
`∫ t in (0, ‖f‖], μ {x | f(x) ≥ t} dt` as `ε → 0`. -/
lemma tendsto_integral_meas_thickening_le (f : Ω →ᵇ ℝ)
{A : Set ℝ} (A_finmeas : volume A ≠ ∞) (μ : ProbabilityMeasure Ω) :
Tendsto (fun ε ↦ ∫ t in A, ENNReal.toReal (μ (thickening ε {a | t ≤ f a}))) (𝓝[>] (0 : ℝ))
(𝓝 (∫ t in A, ENNReal.toReal (μ {a | t ≤ f a}))) := by
apply tendsto_integral_filter_of_dominated_convergence (G := ℝ) (μ := volume.restrict A)
(F := fun ε t ↦ (μ (thickening ε {a | t ≤ f a}))) (f := fun t ↦ (μ {a | t ≤ f a})) 1
· apply eventually_of_forall fun n ↦ Measurable.aestronglyMeasurable ?_
simp only [measurable_coe_nnreal_real_iff]
apply measurable_toNNReal.comp <| Antitone.measurable (fun s t hst ↦ ?_)
exact measure_mono <| thickening_subset_of_subset _ <| fun ω h ↦ hst.trans h
· apply eventually_of_forall (fun i ↦ ?_)
apply eventually_of_forall (fun t ↦ ?_)
simp only [Real.norm_eq_abs, NNReal.abs_eq, Pi.one_apply]
exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) one_ne_top).mpr prob_le_one
· have aux : IsFiniteMeasure (volume.restrict A) := ⟨by simp [lt_top_iff_ne_top, A_finmeas]⟩
apply integrable_const
· apply eventually_of_forall (fun t ↦ ?_)
simp only [NNReal.tendsto_coe]
apply (ENNReal.tendsto_toNNReal _).comp
· apply tendsto_measure_thickening_of_isClosed ?_ ?_
· exact ⟨1, ⟨Real.zero_lt_one, measure_ne_top _ _⟩⟩
· exact isClosed_le continuous_const f.continuous
· exact measure_ne_top _ _
/-- The coercion `LevyProkhorov (ProbabilityMeasure Ω) → ProbabilityMeasure Ω` is continuous. -/
lemma LevyProkhorov.continuous_toProbabilityMeasure :
Continuous (LevyProkhorov.toProbabilityMeasure (Ω := Ω)) := by
refine SeqContinuous.continuous ?_
intro μs ν hμs
set P := ν.toProbabilityMeasure -- more palatable notation
set Ps := fun n ↦ (μs n).toProbabilityMeasure -- more palatable notation
rw [ProbabilityMeasure.tendsto_iff_forall_integral_tendsto]
refine fun f ↦ tendsto_integral_of_forall_limsup_integral_le_integral ?_ f
intro f f_nn
by_cases f_zero : ‖f‖ = 0
· simp only [norm_eq_zero] at f_zero
simp [f_zero, limsup_const]
have norm_f_pos : 0 < ‖f‖ := lt_of_le_of_ne (norm_nonneg _) (fun a => f_zero a.symm)
apply _root_.le_of_forall_pos_le_add
intro δ δ_pos
apply limsup_le_of_le ?_
· obtain ⟨εs, ⟨_, ⟨εs_pos, εs_lim⟩⟩⟩ := exists_seq_strictAnti_tendsto (0 : ℝ)
have ε_of_room := Tendsto.add (tendsto_iff_dist_tendsto_zero.mp hμs) εs_lim
have ε_of_room' : Tendsto (fun n ↦ dist (μs n) ν + εs n) atTop (𝓝[>] 0) := by
rw [tendsto_nhdsWithin_iff]
refine ⟨by simpa using ε_of_room, eventually_of_forall fun n ↦ ?_⟩
· rw [mem_Ioi]
linarith [εs_pos n, dist_nonneg (x := μs n) (y := ν)]
rw [add_zero] at ε_of_room
have key := (tendsto_integral_meas_thickening_le f (A := Ioc 0 ‖f‖) (by simp) P).comp ε_of_room'
have aux : ∀ (z : ℝ), Iio (z + δ/2) ∈ 𝓝 z := fun z ↦ Iio_mem_nhds (by linarith)
filter_upwards [key (aux _), ε_of_room <| Iio_mem_nhds <| half_pos <|
Real.mul_pos (inv_pos.mpr norm_f_pos) δ_pos]
with n hn hn'
simp only [mem_preimage, mem_Iio] at *
specialize εs_pos n
have bound := BoundedContinuousFunction.integral_le_of_levyProkhorovEDist_lt
(Ps n) P (ε := dist (μs n) ν + εs n) ?_ ?_ f ?_
· refine bound.trans ?_
apply (add_le_add_right hn.le _).trans
rw [BoundedContinuousFunction.integral_eq_integral_meas_le]
· simp only [ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure]
rw [add_assoc, mul_comm]
gcongr
calc
δ / 2 + ‖f‖ * (dist (μs n) ν + εs n)
_ ≤ δ / 2 + ‖f‖ * (‖f‖⁻¹ * δ / 2) := by gcongr
_ = δ := by field_simp; ring
· exact eventually_of_forall f_nn
· positivity
· rw [ENNReal.ofReal_add (by positivity) (by positivity), ← add_zero (levyProkhorovEDist _ _)]
apply ENNReal.add_lt_add_of_le_of_lt (levyProkhorovEDist_ne_top _ _)
(le_of_eq ?_) (ofReal_pos.mpr εs_pos)
rw [LevyProkhorov.dist_def, levyProkhorovDist,
ofReal_toReal (levyProkhorovEDist_ne_top _ _)]
simp only [Ps, P, LevyProkhorov.toProbabilityMeasure]
· exact eventually_of_forall f_nn
· simp only [IsCoboundedUnder, IsCobounded, eventually_map, eventually_atTop,
forall_exists_index]
refine ⟨0, fun a i hia ↦ le_trans (integral_nonneg f_nn) (hia i le_rfl)⟩
/-- The topology of the Lévy-Prokhorov metric is at least as fine as the topology of convergence in
distribution. -/
theorem levyProkhorov_le_convergenceInDistribution :
TopologicalSpace.coinduced (LevyProkhorov.toProbabilityMeasure (Ω := Ω)) inferInstance
≤ (inferInstance : TopologicalSpace (ProbabilityMeasure Ω)) :=
(LevyProkhorov.continuous_toProbabilityMeasure).coinduced_le
end Levy_Prokhorov_is_finer
section Levy_Prokhorov_metrizes_convergence_in_distribution
/-! ### On separable spaces the Lévy-Prokhorov distance metrizes convergence in distribution -/
open BoundedContinuousFunction TopologicalSpace
variable {ι : Type*} (Ω : Type*) [PseudoMetricSpace Ω] [SeparableSpace Ω]
variable [MeasurableSpace Ω] [OpensMeasurableSpace Ω]
/-- In a separable pseudometric space, for any ε > 0 there exists a countable collection of
disjoint Borel measurable subsets of diameter at most ε that cover the whole space. -/
lemma SeparableSpace.exists_measurable_partition_diam_le {ε : ℝ} (ε_pos : 0 < ε) :
∃ (As : ℕ → Set Ω), (∀ n, MeasurableSet (As n)) ∧ (∀ n, Bornology.IsBounded (As n)) ∧
(∀ n, diam (As n) ≤ ε) ∧ (⋃ n, As n = univ) ∧
(Pairwise (fun (n m : ℕ) ↦ Disjoint (As n) (As m))) := by
by_cases X_emp : IsEmpty Ω
· refine ⟨fun _ ↦ ∅, fun _ ↦ MeasurableSet.empty, fun _ ↦ Bornology.isBounded_empty, ?_, ?_,
fun _ _ _ ↦ disjoint_of_subsingleton⟩
· intro n
simpa only [diam_empty] using LT.lt.le ε_pos
· simp only [iUnion_empty]
apply Eq.symm
simp only [univ_eq_empty_iff, X_emp]
rw [not_isEmpty_iff] at X_emp
obtain ⟨xs, xs_dense⟩ := exists_dense_seq Ω
have half_ε_pos : 0 < ε / 2 := half_pos ε_pos
set Bs := fun n ↦ Metric.ball (xs n) (ε/2)
set As := disjointed Bs
refine ⟨As, ?_, ?_, ?_, ?_, ?_⟩
· exact MeasurableSet.disjointed (fun n ↦ measurableSet_ball)
· exact fun n ↦ Bornology.IsBounded.subset isBounded_ball <| disjointed_subset Bs n
· intro n
apply (diam_mono (disjointed_subset Bs n) isBounded_ball).trans
convert diam_ball half_ε_pos.le
ring
· have aux : ⋃ n, Bs n = univ := by
convert DenseRange.iUnion_uniformity_ball xs_dense <| Metric.dist_mem_uniformity half_ε_pos
exact (ball_eq_ball' _ _).symm
simpa only [← aux] using iUnion_disjointed
· exact disjoint_disjointed Bs
variable {Ω}
lemma ProbabilityMeasure.toMeasure_add_pos_gt_mem_nhds (P : ProbabilityMeasure Ω)
{G : Set Ω} (G_open : IsOpen G) {ε : ℝ≥0∞} (ε_pos : 0 < ε) :
{Q | P.toMeasure G < Q.toMeasure G + ε} ∈ 𝓝 P := by
by_cases easy : P.toMeasure G < ε
· exact eventually_of_forall (fun _ ↦ lt_of_lt_of_le easy le_add_self)
by_cases ε_top : ε = ∞
· simp [ε_top, measure_lt_top]
simp only [not_lt] at easy
have aux : P.toMeasure G - ε < liminf (fun Q ↦ Q.toMeasure G) (𝓝 P) := by
apply lt_of_lt_of_le (ENNReal.sub_lt_self (measure_lt_top _ _).ne _ _)
<| ProbabilityMeasure.le_liminf_measure_open_of_tendsto tendsto_id G_open
· exact (lt_of_lt_of_le ε_pos easy).ne.symm
· exact ε_pos.ne.symm
filter_upwards [gt_mem_sets_of_limsInf_gt (α := ℝ≥0∞) isBounded_ge_of_bot
(show P.toMeasure G - ε < limsInf ((𝓝 P).map (fun Q ↦ Q.toMeasure G)) from aux)] with Q hQ
simp only [preimage_setOf_eq, mem_setOf_eq] at hQ
convert ENNReal.add_lt_add_right ε_top hQ
exact (tsub_add_cancel_of_le easy).symm
lemma ProbabilityMeasure.continuous_toLevyProkhorov :
Continuous (ProbabilityMeasure.toLevyProkhorov (Ω := Ω)) := by
-- We check continuity of `id : ProbabilityMeasure Ω → LevyProkhorov (ProbabilityMeasure Ω)` at
-- each point `P : ProbabilityMeasure Ω`.
rw [continuous_iff_continuousAt]
intro P
-- To check continuity, fix `ε > 0`. To leave some wiggle room, be ready to use `ε/3 > 0` instead.
rw [continuousAt_iff']
intro ε ε_pos
have third_ε_pos : 0 < ε / 3 := by linarith
have third_ε_pos' : 0 < ENNReal.ofReal (ε / 3) := ofReal_pos.mpr third_ε_pos
-- First use separability to choose a countable partition of `Ω` into measurable
-- subsets `Es n ⊆ Ω` of small diamater, `diam (Es n) < ε/3`.
obtain ⟨Es, Es_mble, Es_bdd, Es_diam, Es_cover, Es_disjoint⟩ :=
SeparableSpace.exists_measurable_partition_diam_le Ω third_ε_pos
-- Instead of the whole space `Ω = ⋃ n ∈ ℕ, Es n`, focus on a large but finite
-- union `⋃ n < N, Es n`, chosen in such a way that the complement has small `P`-mass,
-- `P (⋃ n < N, Es n)ᶜ < ε/3`.
obtain ⟨N, hN⟩ : ∃ N, P.toMeasure (⋃ j ∈ Iio N, Es j)ᶜ < ENNReal.ofReal (ε/3) := by
have exhaust := @tendsto_measure_biUnion_Ici_zero_of_pairwise_disjoint Ω _ P.toMeasure _
Es Es_mble Es_disjoint
simp only [tendsto_atTop_nhds, Function.comp_apply] at exhaust
obtain ⟨N, hN⟩ := exhaust (Iio (ENNReal.ofReal (ε / 3))) third_ε_pos' isOpen_Iio
refine ⟨N, ?_⟩
have rewr : ⋃ i, ⋃ (_ : N ≤ i), Es i = (⋃ i, ⋃ (_ : i < N), Es i)ᶜ := by
simpa only [mem_Iio, compl_Iio, mem_Ici] using
(biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ Es_cover Es_disjoint (Iio N)).symm
simpa only [mem_Iio, ← rewr, gt_iff_lt] using hN N le_rfl
-- With the finite `N` fixed above, consider the finite collection of open sets of the form
-- `Gs J = thickening (ε/3) (⋃ j ∈ J, Es j)`, where `J ⊆ {0, 1, ..., N-1}`.
have Js_finite : Set.Finite {J | J ⊆ Iio N} := Finite.finite_subsets <| finite_Iio N
set Gs := (fun (J : Set ℕ) ↦ thickening (ε/3) (⋃ j ∈ J, Es j)) '' {J | J ⊆ Iio N}
have Gs_open : ∀ (J : Set ℕ), IsOpen (thickening (ε/3) (⋃ j ∈ J, Es j)) :=
fun J ↦ isOpen_thickening
-- Any open set `G ⊆ Ω` determines a neighborhood of `P` consisting of those `Q` that
-- satisfy `P G < Q G + ε/3`.
have mem_nhds_P (G : Set Ω) (G_open : IsOpen G) :
{Q | P.toMeasure G < Q.toMeasure G + ENNReal.ofReal (ε/3)} ∈ 𝓝 P :=
P.toMeasure_add_pos_gt_mem_nhds G_open third_ε_pos'
-- Assume that `Q` is in the neighborhood of `P` such that for each `J ⊆ {0, 1, ..., N-1}`
-- we have `P (Gs J) < Q (Gs J) + ε/3`.
filter_upwards [(Finset.iInter_mem_sets Js_finite.toFinset).mpr <|
fun J _ ↦ mem_nhds_P _ (Gs_open J)] with Q hQ
simp only [Finite.mem_toFinset, mem_setOf_eq, thickening_iUnion, mem_iInter] at hQ
-- Note that in order to show that the Lévy-Prokhorov distance `LPdist P Q` is small (`≤ 2*ε/3`),
-- it suffices to show that for arbitrary subsets `B ⊆ Ω`, the measure `P B` is bounded above up
-- to a small error by the `Q`-measure of a small thickening of `B`.
apply lt_of_le_of_lt ?_ (show 2*(ε/3) < ε by linarith)
rw [dist_comm]
-- Fix an arbitrary set `B ⊆ Ω`, and an arbitrary `δ > 2*ε/3` to gain some room for error
-- and for thickening.
apply levyProkhorovDist_le_of_forall_le _ _ (by linarith) (fun δ B δ_gt _ ↦ ?_)
-- Let `JB ⊆ {0, 1, ..., N-1}` consist of those indices `j` such that `B` intersects `Es j`.
-- Then the open set `Gs JB` approximates `B` rather well:
-- except for what happens in the small complement `(⋃ n < N, Es n)ᶜ`, the set `B` is
-- contained in `Gs JB`, and conversely `Gs JB` only contains points within `δ` from `B`.
set JB := {i | B ∩ Es i ≠ ∅ ∧ i ∈ Iio N}
have B_subset : B ⊆ (⋃ i ∈ JB, thickening (ε/3) (Es i)) ∪ (⋃ j ∈ Iio N, Es j)ᶜ := by
suffices B ⊆ (⋃ i ∈ JB, thickening (ε/3) (Es i)) ∪ (⋃ j ∈ Ici N, Es j) by
refine this.trans <| union_subset_union le_rfl ?_
intro ω hω
simp only [mem_Ici, mem_iUnion, exists_prop] at hω
obtain ⟨i, i_large, ω_in_Esi⟩ := hω
by_contra con
simp only [mem_Iio, compl_iUnion, mem_iInter, mem_compl_iff, not_forall, not_not,
exists_prop] at con
obtain ⟨j, j_small, ω_in_Esj⟩ := con
exact disjoint_left.mp (Es_disjoint (show j ≠ i by linarith)) ω_in_Esj ω_in_Esi
intro ω ω_in_B
obtain ⟨i, hi⟩ := show ∃ n, ω ∈ Es n by simp only [← mem_iUnion, Es_cover, mem_univ]
simp only [mem_Ici, mem_union, mem_iUnion, exists_prop]
by_cases i_small : i ∈ Iio N
· refine Or.inl ⟨i, ?_, self_subset_thickening third_ε_pos _ hi⟩
simp only [mem_Iio, mem_setOf_eq, JB]
refine ⟨nonempty_iff_ne_empty.mp <| Set.nonempty_of_mem <| mem_inter ω_in_B hi, i_small⟩
· exact Or.inr ⟨i, by simpa only [mem_Iio, not_lt] using i_small, hi⟩
have subset_thickB : ⋃ i ∈ JB, thickening (ε / 3) (Es i) ⊆ thickening δ B := by
intro ω ω_in_U
simp only [mem_setOf_eq, mem_iUnion, exists_prop] at ω_in_U
obtain ⟨k, ⟨B_intersects, _⟩, ω_in_thEk⟩ := ω_in_U
rw [mem_thickening_iff] at ω_in_thEk ⊢
obtain ⟨w, w_in_Ek, w_near⟩ := ω_in_thEk
obtain ⟨z, ⟨z_in_B, z_in_Ek⟩⟩ := nonempty_iff_ne_empty.mpr B_intersects
refine ⟨z, z_in_B, lt_of_le_of_lt (dist_triangle ω w z) ?_⟩
apply lt_of_le_of_lt (add_le_add w_near.le <|
(dist_le_diam_of_mem (Es_bdd k) w_in_Ek z_in_Ek).trans <| Es_diam k)
linarith
-- We use the resulting upper bound `P B ≤ P (Gs JB) + P (small complement)`.
apply (measure_mono B_subset).trans ((measure_union_le _ _).trans ?_)
-- From the choice of `Q` in a suitable neighborhood, we have `P (Gs JB) < Q (Gs JB) + ε/3`.
specialize hQ _ (show JB ⊆ Iio N from fun _ h ↦ h.2)
-- Now it remains to add the pieces and use the above estimates.
apply (add_le_add hQ.le hN.le).trans
rw [add_assoc, ← ENNReal.ofReal_add third_ε_pos.le third_ε_pos.le, ← two_mul]
apply add_le_add (measure_mono subset_thickB) (ofReal_le_ofReal _)
exact δ_gt.le
/-- The topology of the Lévy-Prokhorov metric on probability measures on a separable space
coincides with the topology of convergence in distribution. -/
theorem levyProkhorov_eq_convergenceInDistribution :
(inferInstance : TopologicalSpace (ProbabilityMeasure Ω))
= TopologicalSpace.coinduced (LevyProkhorov.toProbabilityMeasure (Ω := Ω)) inferInstance :=
le_antisymm (ProbabilityMeasure.continuous_toLevyProkhorov (Ω := Ω)).coinduced_le
levyProkhorov_le_convergenceInDistribution
/-- The identity map is a homeomorphism from `ProbabilityMeasure Ω` with the topology of
convergence in distribution to `ProbabilityMeasure Ω` with the Lévy-Prokhorov (pseudo)metric. -/
def homeomorph_probabilityMeasure_levyProkhorov :
ProbabilityMeasure Ω ≃ₜ LevyProkhorov (ProbabilityMeasure Ω) where
toFun := ProbabilityMeasure.toLevyProkhorov (Ω := Ω)
invFun := LevyProkhorov.toProbabilityMeasure (Ω := Ω)
left_inv := congrFun rfl
right_inv := congrFun rfl
continuous_toFun := ProbabilityMeasure.continuous_toLevyProkhorov
continuous_invFun := LevyProkhorov.continuous_toProbabilityMeasure
/-- The topology of convergence in distribution on a separable space is pseudo-metrizable. -/
instance (X : Type*) [TopologicalSpace X] [PseudoMetrizableSpace X] [SeparableSpace X]
[MeasurableSpace X] [OpensMeasurableSpace X] :
PseudoMetrizableSpace (ProbabilityMeasure X) :=
letI : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X
(homeomorph_probabilityMeasure_levyProkhorov (Ω := X)).inducing.pseudoMetrizableSpace
end Levy_Prokhorov_metrizes_convergence_in_distribution
end MeasureTheory -- namespace
|
MeasureTheory\Measure\LogLikelihoodRatio.lean | /-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Measure.Tilted
/-!
# Log-likelihood Ratio
The likelihood ratio between two measures `μ` and `ν` is their Radon-Nikodym derivative
`μ.rnDeriv ν`. The logarithm of that function is often used instead: this is the log-likelihood
ratio.
This file contains a definition of the log-likelihood ratio (llr) and its properties.
## Main definitions
* `llr μ ν`: Log-Likelihood Ratio between `μ` and `ν`, defined as the function
`x ↦ log (μ.rnDeriv ν x).toReal`.
-/
open Real
open scoped ENNReal NNReal Topology
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ ν : Measure α} {f : α → ℝ}
/-- Log-Likelihood Ratio between two measures. -/
noncomputable def llr (μ ν : Measure α) (x : α) : ℝ := log (μ.rnDeriv ν x).toReal
lemma llr_def (μ ν : Measure α) : llr μ ν = fun x ↦ log (μ.rnDeriv ν x).toReal := rfl
lemma exp_llr (μ ν : Measure α) [SigmaFinite μ] :
(fun x ↦ exp (llr μ ν x))
=ᵐ[ν] fun x ↦ if μ.rnDeriv ν x = 0 then 1 else (μ.rnDeriv ν x).toReal := by
filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx
by_cases h_zero : μ.rnDeriv ν x = 0
· simp only [llr, h_zero, ENNReal.zero_toReal, log_zero, exp_zero, ite_true]
· rw [llr, exp_log, if_neg h_zero]
exact ENNReal.toReal_pos h_zero hx.ne
lemma exp_llr_of_ac (μ ν : Measure α) [SigmaFinite μ] [Measure.HaveLebesgueDecomposition μ ν]
(hμν : μ ≪ ν) :
(fun x ↦ exp (llr μ ν x)) =ᵐ[μ] fun x ↦ (μ.rnDeriv ν x).toReal := by
filter_upwards [hμν.ae_le (exp_llr μ ν), Measure.rnDeriv_pos hμν] with x hx_eq hx_pos
rw [hx_eq, if_neg hx_pos.ne']
lemma exp_llr_of_ac' (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] (hμν : ν ≪ μ) :
(fun x ↦ exp (llr μ ν x)) =ᵐ[ν] fun x ↦ (μ.rnDeriv ν x).toReal := by
filter_upwards [exp_llr μ ν, Measure.rnDeriv_pos' hμν] with x hx hx_pos
rwa [if_neg hx_pos.ne'] at hx
lemma neg_llr [SigmaFinite μ] [SigmaFinite ν] (hμν : μ ≪ ν) :
- llr μ ν =ᵐ[μ] llr ν μ := by
filter_upwards [Measure.inv_rnDeriv hμν] with x hx
rw [Pi.neg_apply, llr, llr, ← log_inv, ← ENNReal.toReal_inv]
congr
lemma exp_neg_llr [SigmaFinite μ] [SigmaFinite ν] (hμν : μ ≪ ν) :
(fun x ↦ exp (- llr μ ν x)) =ᵐ[μ] fun x ↦ (ν.rnDeriv μ x).toReal := by
filter_upwards [neg_llr hμν, exp_llr_of_ac' ν μ hμν] with x hx hx_exp_log
rw [Pi.neg_apply] at hx
rw [hx, hx_exp_log]
lemma exp_neg_llr' [SigmaFinite μ] [SigmaFinite ν] (hμν : ν ≪ μ) :
(fun x ↦ exp (- llr μ ν x)) =ᵐ[ν] fun x ↦ (ν.rnDeriv μ x).toReal := by
filter_upwards [neg_llr hμν, exp_llr_of_ac ν μ hμν] with x hx hx_exp_log
rw [Pi.neg_apply, neg_eq_iff_eq_neg] at hx
rw [← hx, hx_exp_log]
@[measurability]
lemma measurable_llr (μ ν : Measure α) : Measurable (llr μ ν) :=
(Measure.measurable_rnDeriv μ ν).ennreal_toReal.log
@[measurability]
lemma stronglyMeasurable_llr (μ ν : Measure α) : StronglyMeasurable (llr μ ν) :=
(measurable_llr μ ν).stronglyMeasurable
lemma llr_smul_left [IsFiniteMeasure μ] [Measure.HaveLebesgueDecomposition μ ν]
(hμν : μ ≪ ν) (c : ℝ≥0∞) (hc : c ≠ 0) (hc_ne_top : c ≠ ∞) :
llr (c • μ) ν =ᵐ[μ] fun x ↦ llr μ ν x + log c.toReal := by
simp only [llr, llr_def]
have h := Measure.rnDeriv_smul_left_of_ne_top μ ν hc_ne_top
filter_upwards [hμν.ae_le h, Measure.rnDeriv_pos hμν, hμν.ae_le (Measure.rnDeriv_lt_top μ ν)]
with x hx_eq hx_pos hx_ne_top
rw [hx_eq]
simp only [Pi.smul_apply, smul_eq_mul, ENNReal.toReal_mul]
rw [log_mul]
rotate_left
· rw [ENNReal.toReal_ne_zero]
simp [hc, hc_ne_top]
· rw [ENNReal.toReal_ne_zero]
simp [hx_pos.ne', hx_ne_top.ne]
ring
lemma llr_smul_right [IsFiniteMeasure μ] [Measure.HaveLebesgueDecomposition μ ν]
(hμν : μ ≪ ν) (c : ℝ≥0∞) (hc : c ≠ 0) (hc_ne_top : c ≠ ∞) :
llr μ (c • ν) =ᵐ[μ] fun x ↦ llr μ ν x - log c.toReal := by
simp only [llr, llr_def]
have h := Measure.rnDeriv_smul_right_of_ne_top μ ν hc hc_ne_top
filter_upwards [hμν.ae_le h, Measure.rnDeriv_pos hμν, hμν.ae_le (Measure.rnDeriv_lt_top μ ν)]
with x hx_eq hx_pos hx_ne_top
rw [hx_eq]
simp only [Pi.smul_apply, smul_eq_mul, ENNReal.toReal_mul]
rw [log_mul]
rotate_left
· rw [ENNReal.toReal_ne_zero]
simp [hc, hc_ne_top]
· rw [ENNReal.toReal_ne_zero]
simp [hx_pos.ne', hx_ne_top.ne]
rw [ENNReal.toReal_inv, log_inv]
ring
section llr_tilted
lemma llr_tilted_left [SigmaFinite μ] [SigmaFinite ν] (hμν : μ ≪ ν)
(hf : Integrable (fun x ↦ exp (f x)) μ) (hfν : AEMeasurable f ν) :
(llr (μ.tilted f) ν) =ᵐ[μ] fun x ↦ f x - log (∫ z, exp (f z) ∂μ) + llr μ ν x := by
cases eq_zero_or_neZero μ with
| inl hμ =>
simp only [hμ, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
| inr h0 =>
filter_upwards [hμν.ae_le (toReal_rnDeriv_tilted_left μ hfν), Measure.rnDeriv_pos hμν,
hμν.ae_le (Measure.rnDeriv_lt_top μ ν)] with x hx hx_pos hx_lt_top
rw [llr, hx, log_mul, div_eq_mul_inv, log_mul (exp_pos _).ne', log_exp, log_inv, llr,
← sub_eq_add_neg]
· simp only [ne_eq, inv_eq_zero]
exact (integral_exp_pos hf).ne'
· simp only [ne_eq, div_eq_zero_iff]
push_neg
exact ⟨(exp_pos _).ne', (integral_exp_pos hf).ne'⟩
· simp [ENNReal.toReal_eq_zero_iff, hx_lt_top.ne, hx_pos.ne']
lemma integrable_llr_tilted_left [IsFiniteMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hf : Integrable f μ) (h_int : Integrable (llr μ ν) μ)
(hfμ : Integrable (fun x ↦ exp (f x)) μ) (hfν : AEMeasurable f ν) :
Integrable (llr (μ.tilted f) ν) μ := by
rw [integrable_congr (llr_tilted_left hμν hfμ hfν)]
exact Integrable.add (hf.sub (integrable_const _)) h_int
lemma integral_llr_tilted_left [IsProbabilityMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hf : Integrable f μ) (h_int : Integrable (llr μ ν) μ)
(hfμ : Integrable (fun x ↦ exp (f x)) μ) (hfν : AEMeasurable f ν) :
∫ x, llr (μ.tilted f) ν x ∂μ = ∫ x, llr μ ν x ∂μ + ∫ x, f x ∂μ - log (∫ x, exp (f x) ∂μ) := by
calc ∫ x, llr (μ.tilted f) ν x ∂μ
= ∫ x, f x - log (∫ x, exp (f x) ∂μ) + llr μ ν x ∂μ :=
integral_congr_ae (llr_tilted_left hμν hfμ hfν)
_ = ∫ x, f x ∂μ - log (∫ x, exp (f x) ∂μ) + ∫ x, llr μ ν x ∂μ := by
rw [integral_add ?_ h_int]
swap; · exact hf.sub (integrable_const _)
rw [integral_sub hf (integrable_const _)]
simp only [integral_const, measure_univ, ENNReal.one_toReal, smul_eq_mul, one_mul]
_ = ∫ x, llr μ ν x ∂μ + ∫ x, f x ∂μ - log (∫ x, exp (f x) ∂μ) := by abel
lemma llr_tilted_right [SigmaFinite μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hf : Integrable (fun x ↦ exp (f x)) ν) :
(llr μ (ν.tilted f)) =ᵐ[μ] fun x ↦ - f x + log (∫ z, exp (f z) ∂ν) + llr μ ν x := by
cases eq_zero_or_neZero ν with
| inl h =>
have hμ : μ = 0 := by ext s _; exact hμν (by simp [h])
simp only [hμ, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
| inr h0 =>
filter_upwards [hμν.ae_le (toReal_rnDeriv_tilted_right μ ν hf), Measure.rnDeriv_pos hμν,
hμν.ae_le (Measure.rnDeriv_lt_top μ ν)] with x hx hx_pos hx_lt_top
rw [llr, hx, log_mul, log_mul (exp_pos _).ne', log_exp, llr]
· exact (integral_exp_pos hf).ne'
· refine (mul_pos (exp_pos _) (integral_exp_pos hf)).ne'
· simp [ENNReal.toReal_eq_zero_iff, hx_lt_top.ne, hx_pos.ne']
lemma integrable_llr_tilted_right [IsFiniteMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hfμ : Integrable f μ)
(h_int : Integrable (llr μ ν) μ) (hfν : Integrable (fun x ↦ exp (f x)) ν) :
Integrable (llr μ (ν.tilted f)) μ := by
rw [integrable_congr (llr_tilted_right hμν hfν)]
exact Integrable.add (hfμ.neg.add (integrable_const _)) h_int
lemma integral_llr_tilted_right [IsProbabilityMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hfμ : Integrable f μ) (hfν : Integrable (fun x ↦ exp (f x)) ν)
(h_int : Integrable (llr μ ν) μ) :
∫ x, llr μ (ν.tilted f) x ∂μ = ∫ x, llr μ ν x ∂μ - ∫ x, f x ∂μ + log (∫ x, exp (f x) ∂ν) := by
calc ∫ x, llr μ (ν.tilted f) x ∂μ
= ∫ x, - f x + log (∫ x, exp (f x) ∂ν) + llr μ ν x ∂μ :=
integral_congr_ae (llr_tilted_right hμν hfν)
_ = - ∫ x, f x ∂μ + log (∫ x, exp (f x) ∂ν) + ∫ x, llr μ ν x ∂μ := by
rw [← integral_neg, integral_add ?_ h_int]
swap; · exact hfμ.neg.add (integrable_const _)
rw [integral_add ?_ (integrable_const _)]
swap; · exact hfμ.neg
simp only [integral_const, measure_univ, ENNReal.one_toReal, smul_eq_mul, one_mul]
_ = ∫ x, llr μ ν x ∂μ - ∫ x, f x ∂μ + log (∫ x, exp (f x) ∂ν) := by abel
end llr_tilted
end MeasureTheory
|
MeasureTheory\Measure\MeasureSpace.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.NullMeasurable
import Mathlib.MeasureTheory.MeasurableSpace.Embedding
import Mathlib.Topology.Algebra.Order.LiminfLimsup
/-!
# Measure spaces
The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to
be available in `MeasureSpace` (through `MeasurableSpace`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure.
## Implementation notes
Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generateFrom_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using
`C ∪ {univ}`, but is easier to work with.
A `MeasureSpace` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable section
open Set
open Filter hiding map
open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory
open scoped symmDiff
variable {α β γ δ ι R R' : Type*}
namespace MeasureTheory
section
variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α}
instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) :=
⟨fun _s hs =>
let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
/-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/
theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by
simp only [uIoc_eq_union, mem_union, or_imp, eventually_and]
theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀ h.nullMeasurableSet hd.aedisjoint
theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀' h.nullMeasurableSet hd.aedisjoint
theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s :=
measure_inter_add_diff₀ _ ht.nullMeasurableSet
theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s :=
(add_comm _ _).trans (measure_inter_add_diff s ht)
theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ←
measure_inter_add_diff s ht]
ac_rfl
theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm]
lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) :
μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by
simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs)
lemma measure_symmDiff_le (s t u : Set α) :
μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) :=
le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u))
theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ :=
measure_add_measure_compl₀ h.nullMeasurableSet
theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable)
(hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by
haveI := hs.toEncodable
rw [biUnion_eq_iUnion]
exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2
theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f)
(h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=
measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet
theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ))
(h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h]
theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint)
(h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion hs hd h]
theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α}
(hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by
rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype]
exact measure_biUnion₀ s.countable_toSet hd hm
theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f)
(hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) :=
measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet
/-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least
the sum of the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by
rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff]
intro s
simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i]
gcongr
exact iUnion_subset fun _ ↦ Subset.rfl
/-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of
the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) :=
tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet)
(fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by
rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf]
lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) :
μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by
rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs]
/-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by
simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf,
Finset.set_biUnion_preimage_singleton]
theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_congr <| diff_ae_eq_self.2 h
theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by
rw [← measure_union' disjoint_sdiff_right hs, union_diff_self]
theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) :
μ (s \ t) = μ (s ∪ t) - μ t :=
Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm]
theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) :
μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h]
theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) :=
tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by
gcongr; apply inter_subset_right
/-- If the measure of the symmetric difference of two sets is finite,
then one has infinite measure if and only if the other one does. -/
theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by
suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞
from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩
intro u v hμuv hμu
by_contra! hμv
apply hμuv
rw [Set.symmDiff_def, eq_top_iff]
calc
∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm
_ ≤ μ (u \ v) := le_measure_diff
_ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left
/-- If the measure of the symmetric difference of two sets is finite,
then one has finite measure if and only if the other one does. -/
theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ :=
(measure_eq_top_iff_of_symmDiff hμst).ne
theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞}
(h : μ t < μ s + ε) : μ (t \ s) < ε := by
rw [measure_diff hst hs hs']; rw [add_comm] at h
exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h
theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} :
μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left]
theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) :
μ s = μ t := measure_congr <|
EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff)
theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃)
(h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by
have le12 : μ s₁ ≤ μ s₂ := measure_mono h12
have le23 : μ s₂ ≤ μ s₃ := measure_mono h23
have key : μ s₃ ≤ μ s₁ :=
calc
μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)]
_ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _
_ = μ s₁ := by simp only [h_nulldiff, zero_add]
exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩
theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1
theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2
lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) :
μ sᶜ = μ Set.univ - μ s := by
rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs]
theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s :=
measure_compl₀ h₁.nullMeasurableSet h_fin
lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null']; rwa [← diff_eq]
lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null ht]
@[simp]
theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by
rw [ae_le_set]
refine
⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h =>
eventuallyLE_antisymm_iff.mpr
⟨by rwa [ae_le_set, union_diff_left],
HasSubset.Subset.eventuallyLE subset_union_left⟩⟩
@[simp]
theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by
rw [union_comm, union_ae_eq_left_iff_ae_subset]
theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s)
(ht : μ t ≠ ∞) : s =ᵐ[μ] t := by
refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩
replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁)
replace ht : μ s ≠ ∞ := h₂ ▸ ht
rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self]
/-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/
theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s)
(ht : μ t ≠ ∞) : s =ᵐ[μ] t :=
ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht
theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α}
(hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by
rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop)
· calc
μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _)
_ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _)
push_neg at htop
refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_
set M := toMeasurable μ
have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by
refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_
· calc
μ (M (t b)) = μ (t b) := measure_toMeasurable _
_ ≤ μ (s b) := h_le b
_ ≤ μ (M (t b) ∩ M (⋃ b, s b)) :=
measure_mono <|
subset_inter ((hsub b).trans <| subset_toMeasurable _ _)
((subset_iUnion _ _).trans <| subset_toMeasurable _ _)
· exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _)
· rw [measure_toMeasurable]
exact htop b
calc
μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _)
_ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm
_ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right)
_ = μ (⋃ b, s b) := measure_toMeasurable _
theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁)
(ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by
rw [union_eq_iUnion, union_eq_iUnion]
exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩)
@[simp]
theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) :
μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) :=
Eq.symm <|
measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b =>
(measure_toMeasurable _).le
theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) :
μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable]
@[simp]
theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl
le_rfl
@[simp]
theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _)
(measure_toMeasurable _).le
theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α}
(h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) :
(∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by
rw [← measure_biUnion_finset₀ H h]
exact measure_mono (subset_univ _)
theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : Pairwise (AEDisjoint μ on s)) : ∑' i, μ (s i) ≤ μ (univ : Set α) := by
rw [ENNReal.tsum_eq_iSup_sum]
exact iSup_le fun s =>
sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α}
(μ : Measure α) {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by
contrapose! H
apply tsum_measure_le_measure_univ hs
intro i j hij
exact (disjoint_iff_inter_eq_empty.mpr (H i j hij)).aedisjoint
/-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and
`∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α)
{s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ)
(H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) :
∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by
contrapose! H
apply sum_measure_le_measure_univ h
intro i hi j hj hij
exact (disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)).aedisjoint
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `t` is measurable. -/
theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [← Set.not_disjoint_iff_nonempty_inter]
contrapose! h
calc
μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm
_ ≤ μ u := measure_mono (union_subset h's h't)
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `s` is measurable. -/
theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [add_comm] at h
rw [inter_comm]
exact nonempty_inter_of_measure_lt_add μ hs h't h's h
/-- Continuity from below: the measure of the union of a directed sequence of (not necessarily
-measurable) sets is the supremum of the measures. -/
theorem measure_iUnion_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
cases nonempty_encodable ι
-- WLOG, `ι = ℕ`
generalize ht : Function.extend Encodable.encode s ⊥ = t
replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot Encodable.encode_injective
suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by
simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion,
iSup_extend_bot Encodable.encode_injective, (· ∘ ·), Pi.bot_apply, bot_eq_empty,
measure_empty] at this
exact this.trans (iSup_extend_bot Encodable.encode_injective _)
clear! ι
-- The `≥` inequality is trivial
refine le_antisymm ?_ (iSup_le fun i => measure_mono <| subset_iUnion _ _)
-- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T`
set T : ℕ → Set α := fun n => toMeasurable μ (t n)
set Td : ℕ → Set α := disjointed T
have hm : ∀ n, MeasurableSet (Td n) :=
MeasurableSet.disjointed fun n => measurableSet_toMeasurable _ _
calc
μ (⋃ n, t n) ≤ μ (⋃ n, T n) := measure_mono (iUnion_mono fun i => subset_toMeasurable _ _)
_ = μ (⋃ n, Td n) := by rw [iUnion_disjointed]
_ ≤ ∑' n, μ (Td n) := measure_iUnion_le _
_ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum
_ ≤ ⨆ n, μ (t n) := iSup_le fun I => by
rcases hd.finset_le I with ⟨N, hN⟩
calc
(∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) :=
(measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm
_ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _)
_ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _
_ ≤ μ (t N) := measure_mono (iUnion₂_subset hN)
_ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N
/-- Continuity from below: the measure of the union of a sequence of
(not necessarily measurable) sets is the supremum of the measures of the partial unions. -/
theorem measure_iUnion_eq_iSup' {α ι : Type*} [MeasurableSpace α] {μ : Measure α}
[Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)]
{f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by
have hd : Directed (· ⊆ ·) (Accumulate f) := by
intro i j
rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩
exact ⟨k, biUnion_subset_biUnion_left fun l rli ↦ le_trans rli rik,
biUnion_subset_biUnion_left fun l rlj ↦ le_trans rlj rjk⟩
rw [← iUnion_accumulate]
exact measure_iUnion_eq_iSup hd
theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable)
(hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by
haveI := ht.toEncodable
rw [biUnion_eq_iUnion, measure_iUnion_eq_iSup hd.directed_val, ← iSup_subtype'']
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the infimum of the measures. -/
theorem measure_iInter_eq_iInf [Countable ι] {s : ι → Set α} (h : ∀ i, MeasurableSet (s i))
(hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by
rcases hfin with ⟨k, hk⟩
have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht)
rw [← ENNReal.sub_sub_cancel hk (iInf_le _ k), ENNReal.sub_iInf, ←
ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ←
measure_diff (iInter_subset _ k) (MeasurableSet.iInter h) (this _ (iInter_subset _ k)),
diff_iInter, measure_iUnion_eq_iSup]
· congr 1
refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => ?_)
· rcases hd i k with ⟨j, hji, hjk⟩
use j
rw [← measure_diff hjk (h _) (this _ hjk)]
gcongr
· rw [tsub_le_iff_right, ← measure_union, Set.union_comm]
· exact measure_mono (diff_subset_iff.1 Subset.rfl)
· apply disjoint_sdiff_left
· apply h i
· exact hd.mono_comp _ fun _ _ => diff_subset_diff_right
/-- Continuity from above: the measure of the intersection of a sequence of
measurable sets is the infimum of the measures of the partial intersections. -/
theorem measure_iInter_eq_iInf' {α ι : Type*} [MeasurableSpace α] {μ : Measure α}
[Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)]
{f : ι → Set α} (h : ∀ i, MeasurableSet (f i)) (hfin : ∃ i, μ (f i) ≠ ∞) :
μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by
let s := fun i ↦ ⋂ j ≤ i, f j
have iInter_eq : ⋂ i, f i = ⋂ i, s i := by
ext x; simp [s]; constructor
· exact fun h _ j _ ↦ h j
· intro h i
rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩
exact h j i rij
have ms : ∀ i, MeasurableSet (s i) :=
fun i ↦ MeasurableSet.biInter (countable_univ.mono <| subset_univ _) fun i _ ↦ h i
have hd : Directed (· ⊇ ·) s := by
intro i j
rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩
exact ⟨k, biInter_subset_biInter_left fun j rji ↦ le_trans rji rik,
biInter_subset_biInter_left fun i rij ↦ le_trans rij rjk⟩
have hfin' : ∃ i, μ (s i) ≠ ∞ := by
rcases hfin with ⟨i, hi⟩
rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩
exact ⟨j, ne_top_of_le_ne_top hi <| measure_mono <| biInter_subset_of_mem rij⟩
exact iInter_eq ▸ measure_iInter_eq_iInf ms hd hfin'
/-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily
measurable) sets is the limit of the measures. -/
theorem tendsto_measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [Countable ι]
{s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by
rw [measure_iUnion_eq_iSup hm.directed_le]
exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm
/-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable)
sets is the limit of the measures of the partial unions. -/
theorem tendsto_measure_iUnion' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι]
[Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} :
Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by
rw [measure_iUnion_eq_iSup']
exact tendsto_atTop_iSup fun i j hij ↦ by gcongr
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the limit of the measures. -/
theorem tendsto_measure_iInter [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {s : ι → Set α}
(hs : ∀ n, MeasurableSet (s n)) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) :
Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by
rw [measure_iInter_eq_iInf hs hm.directed_ge hf]
exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm
/-- Continuity from above: the measure of the intersection of a sequence of measurable
sets such that one has finite measure is the limit of the measures of the partial intersections. -/
theorem tendsto_measure_iInter' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι]
[Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (hm : ∀ i, MeasurableSet (f i))
(hf : ∃ i, μ (f i) ≠ ∞) :
Tendsto (fun i ↦ μ (⋂ j ∈ {j | j ≤ i}, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by
rw [measure_iInter_eq_iInf' hm hf]
exact tendsto_atTop_iInf
fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij
/-- The measure of the intersection of a decreasing sequence of measurable
sets indexed by a linear order with first countable topology is the limit of the measures. -/
theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι]
[OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α}
{a : ι} (hs : ∀ r > a, MeasurableSet (s r)) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j)
(hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by
refine tendsto_order.2 ⟨fun l hl => ?_, fun L hL => ?_⟩
· filter_upwards [self_mem_nhdsWithin (s := Ioi a)] with r hr using hl.trans_le
(measure_mono (biInter_subset_of_mem hr))
obtain ⟨u, u_anti, u_pos, u_lim⟩ :
∃ u : ℕ → ι, StrictAnti u ∧ (∀ n : ℕ, a < u n) ∧ Tendsto u atTop (𝓝 a) := by
rcases hf with ⟨r, ar, _⟩
rcases exists_seq_strictAnti_tendsto' ar with ⟨w, w_anti, w_mem, w_lim⟩
exact ⟨w, w_anti, fun n => (w_mem n).1, w_lim⟩
have A : Tendsto (μ ∘ s ∘ u) atTop (𝓝 (μ (⋂ n, s (u n)))) := by
refine tendsto_measure_iInter (fun n => hs _ (u_pos n)) ?_ ?_
· intro m n hmn
exact hm _ _ (u_pos n) (u_anti.antitone hmn)
· rcases hf with ⟨r, rpos, hr⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, u n < r := ((tendsto_order.1 u_lim).2 r rpos).exists
refine ⟨n, ne_of_lt (lt_of_le_of_lt ?_ hr.lt_top)⟩
exact measure_mono (hm _ _ (u_pos n) hn.le)
have B : ⋂ n, s (u n) = ⋂ r > a, s r := by
apply Subset.antisymm
· simp only [subset_iInter_iff, gt_iff_lt]
intro r rpos
obtain ⟨n, hn⟩ : ∃ n, u n < r := ((tendsto_order.1 u_lim).2 _ rpos).exists
exact Subset.trans (iInter_subset _ n) (hm (u n) r (u_pos n) hn.le)
· simp only [subset_iInter_iff, gt_iff_lt]
intro n
apply biInter_subset_of_mem
exact u_pos n
rw [B] at A
obtain ⟨n, hn⟩ : ∃ n, μ (s (u n)) < L := ((tendsto_order.1 A).2 _ hL).exists
have : Ioc a (u n) ∈ 𝓝[>] a := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, u_pos n⟩
filter_upwards [this] with r hr using lt_of_le_of_lt (measure_mono (hm _ _ hr.1 hr.2)) hn
/-- One direction of the **Borel-Cantelli lemma** (sometimes called the "*first* Borel-Cantelli
lemma"): if (sᵢ) is a sequence of sets such that `∑ μ sᵢ` is finite, then the limit superior of the
`sᵢ` is a null set.
Note: for the *second* Borel-Cantelli lemma (applying to independent sets in a probability space),
see `ProbabilityTheory.measure_limsup_eq_one`. -/
theorem measure_limsup_eq_zero {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) :
μ (limsup s atTop) = 0 := by
-- First we replace the sequence `sₙ` with a sequence of measurable sets `tₙ ⊇ sₙ` of the same
-- measure.
set t : ℕ → Set α := fun n => toMeasurable μ (s n)
have ht : (∑' i, μ (t i)) ≠ ∞ := by simpa only [t, measure_toMeasurable] using hs
suffices μ (limsup t atTop) = 0 by
have A : s ≤ t := fun n => subset_toMeasurable μ (s n)
-- TODO default args fail
exact measure_mono_null (limsup_le_limsup (eventually_of_forall (Pi.le_def.mp A))) this
-- Next we unfold `limsup` for sets and replace equality with an inequality
simp only [limsup_eq_iInf_iSup_of_nat', Set.iInf_eq_iInter, Set.iSup_eq_iUnion, ←
nonpos_iff_eq_zero]
-- Finally, we estimate `μ (⋃ i, t (i + n))` by `∑ i', μ (t (i + n))`
refine
le_of_tendsto_of_tendsto'
(tendsto_measure_iInter
(fun i => MeasurableSet.iUnion fun b => measurableSet_toMeasurable _ _) ?_
⟨0, ne_top_of_le_ne_top ht (measure_iUnion_le t)⟩)
(ENNReal.tendsto_sum_nat_add (μ ∘ t) ht) fun n => measure_iUnion_le _
intro n m hnm x
simp only [Set.mem_iUnion]
exact fun ⟨i, hi⟩ => ⟨i + (m - n), by simpa only [add_assoc, tsub_add_cancel_of_le hnm] using hi⟩
theorem measure_liminf_eq_zero {s : ℕ → Set α} (h : (∑' i, μ (s i)) ≠ ∞) :
μ (liminf s atTop) = 0 := by
rw [← le_zero_iff]
have : liminf s atTop ≤ limsup s atTop := liminf_le_limsup
exact (μ.mono this).trans (by simp [measure_limsup_eq_zero h])
-- Need to specify `α := Set α` below because of diamond; see #19041
theorem limsup_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α}
(h : ∀ n, s n =ᵐ[μ] t) : limsup (α := Set α) s atTop =ᵐ[μ] t := by
simp_rw [ae_eq_set] at h ⊢
constructor
· rw [atTop.limsup_sdiff s t]
apply measure_limsup_eq_zero
simp [h]
· rw [atTop.sdiff_limsup s t]
apply measure_liminf_eq_zero
simp [h]
-- Need to specify `α := Set α` above because of diamond; see #19041
theorem liminf_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α}
(h : ∀ n, s n =ᵐ[μ] t) : liminf (α := Set α) s atTop =ᵐ[μ] t := by
simp_rw [ae_eq_set] at h ⊢
constructor
· rw [atTop.liminf_sdiff s t]
apply measure_liminf_eq_zero
simp [h]
· rw [atTop.sdiff_liminf s t]
apply measure_limsup_eq_zero
simp [h]
theorem measure_if {x : β} {t : Set β} {s : Set α} [Decidable (x ∈ t)] :
μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h]
end
section OuterMeasure
variable [ms : MeasurableSpace α] {s t : Set α}
/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are
Carathéodory measurable. -/
def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α :=
Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd =>
m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd
theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory :=
fun _s hs _t => (measure_inter_add_diff _ hs).symm
@[simp]
theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) :
(m.toMeasure h).toOuterMeasure = m.trim :=
rfl
@[simp]
theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α}
(hs : MeasurableSet s) : m.toMeasure h s = m s :=
m.trim_eq hs
theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) :
m s ≤ m.toMeasure h s :=
m.le_trim s
theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α}
(hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by
refine le_antisymm ?_ (le_toMeasure_apply _ _ _)
rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩
calc
m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm
_ = m t := toMeasure_apply m h htm
_ ≤ m s := m.mono hts
@[simp]
theorem toOuterMeasure_toMeasure {μ : Measure α} :
μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ :=
Measure.ext fun _s => μ.toOuterMeasure.trim_eq
@[simp]
theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure :=
μ.toOuterMeasure.boundedBy_eq_self
end OuterMeasure
section
/- Porting note: These variables are wrapped by an anonymous section because they interrupt
synthesizing instances in `MeasureSpace` section. -/
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable),
then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/
theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u)
(htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by
rw [h] at ht_ne_top
refine le_antisymm (by gcongr) ?_
have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) :=
calc
μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs
_ = μ t := h.symm
_ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm
_ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr
have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne
exact ENNReal.le_of_add_le_add_right B A
/-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`)
satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`.
Here, we require that the measure of `t` is finite. The conclusion holds without this assumption
when the measure is s-finite (for example when it is σ-finite),
see `measure_toMeasurable_inter_of_sFinite`. -/
theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) :=
(measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t)
ht).symm
/-! ### The `ℝ≥0∞`-module of measures -/
instance instZero [MeasurableSpace α] : Zero (Measure α) :=
⟨{ toOuterMeasure := 0
m_iUnion := fun _f _hf _hd => tsum_zero.symm
trim_le := OuterMeasure.trim_zero.le }⟩
@[simp]
theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 :=
rfl
@[simp, norm_cast]
theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 :=
rfl
@[nontriviality]
lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) :
μ s = 0 := by
rw [eq_empty_of_isEmpty s, measure_empty]
instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) :=
⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩
theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 :=
Subsingleton.elim μ 0
instance instInhabited [MeasurableSpace α] : Inhabited (Measure α) :=
⟨0⟩
instance instAdd [MeasurableSpace α] : Add (Measure α) :=
⟨fun μ₁ μ₂ =>
{ toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure
m_iUnion := fun s hs hd =>
show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by
rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs]
trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩
@[simp]
theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) :
(μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure :=
rfl
@[simp, norm_cast]
theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ :=
rfl
theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) :
(μ₁ + μ₂) s = μ₁ s + μ₂ s :=
rfl
section SMul
variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞]
instance instSMul [MeasurableSpace α] : SMul R (Measure α) :=
⟨fun c μ =>
{ toOuterMeasure := c • μ.toOuterMeasure
m_iUnion := fun s hs hd => by
simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul,
measure_iUnion hd hs]
trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩
@[simp]
theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) :
(c • μ).toOuterMeasure = c • μ.toOuterMeasure :=
rfl
@[simp, norm_cast]
theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ :=
rfl
@[simp]
theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) :
(c • μ) s = c • μ s :=
rfl
instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] [MeasurableSpace α] :
SMulCommClass R R' (Measure α) :=
⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩
instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] [MeasurableSpace α] :
IsScalarTower R R' (Measure α) :=
⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩
instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] [MeasurableSpace α] :
IsCentralScalar R (Measure α) :=
⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩
end SMul
instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where
eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h
instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[MeasurableSpace α] : MulAction R (Measure α) :=
Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure
instance instAddCommMonoid [MeasurableSpace α] : AddCommMonoid (Measure α) :=
toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure
fun _ _ => smul_toOuterMeasure _ _
/-- Coercion to function as an additive monoid homomorphism. -/
def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
@[simp]
theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) :
⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I
theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) :
(∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply]
instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[MeasurableSpace α] : DistribMulAction R (Measure α) :=
Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩
toOuterMeasure_injective smul_toOuterMeasure
instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] :
Module R (Measure α) :=
Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩
toOuterMeasure_injective smul_toOuterMeasure
@[simp]
theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) :
(c • μ) s = c * μ s :=
rfl
@[simp]
theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) :
c • μ s = c * μ s := by
rfl
theorem ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) :
(∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by
simp [ae_iff, hc]
@[simp]
theorem ae_smul_measure_eq {c : ℝ≥0∞} (hc : c ≠ 0) : ae (c • μ) = ae μ := by
ext
exact ae_smul_measure_iff hc
theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t)
(h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by
refine le_antisymm (measure_mono h') ?_
have : μ t + ν t ≤ μ s + ν t :=
calc
μ t + ν t = μ s + ν s := h''.symm
_ ≤ μ s + ν t := by gcongr
apply ENNReal.le_of_add_le_add_right _ this
exact ne_top_of_le_ne_top h (le_add_left le_rfl)
theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t)
(h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by
rw [add_comm] at h'' h
exact measure_eq_left_of_subset_of_measure_add_eq h h' h''
theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s)
(ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by
refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm
· refine
measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _)
(measure_toMeasurable t).symm
rwa [measure_toMeasurable t]
· simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht
exact ht.1
theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s)
(ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by
rw [add_comm] at ht ⊢
exact measure_toMeasurable_add_inter_left hs ht
/-! ### The complete lattice of measures -/
/-- Measures are partially ordered. -/
instance instPartialOrder [MeasurableSpace α] : PartialOrder (Measure α) where
le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s
le_refl m s := le_rfl
le_trans m₁ m₂ m₃ h₁ h₂ s := le_trans (h₁ s) (h₂ s)
le_antisymm m₁ m₂ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s)
theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl
theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff
theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ :=
le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs)
theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl
theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s :=
lt_iff_le_not_le.trans <|
and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop]
theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=
lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le]
instance covariantAddLE [MeasurableSpace α] :
CovariantClass (Measure α) (Measure α) (· + ·) (· ≤ ·) :=
⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩
protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s)
protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s)
section sInf
variable {m : Set (Measure α)}
theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) :
MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by
rw [OuterMeasure.sInf_eq_boundedBy_sInfGen]
refine OuterMeasure.boundedBy_caratheodory fun t => ?_
simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t,
coe_toOuterMeasure]
intro μ hμ u htu _hu
have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by
intro s t hst
rw [OuterMeasure.sInfGen_def, iInf_image]
exact iInf₂_le_of_le μ hμ <| measure_mono hst
rw [← measure_inter_add_diff u hs]
exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu)
instance [MeasurableSpace α] : InfSet (Measure α) :=
⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩
theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s :=
toMeasure_apply _ _ hs
private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ :=
have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h)
le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s
private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m :=
have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) :=
le_sInf <| forall_mem_image.2 fun μ hμ ↦ toOuterMeasure_le.2 <| h _ hμ
le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s
instance instCompleteSemilatticeInf [MeasurableSpace α] : CompleteSemilatticeInf (Measure α) :=
{ (by infer_instance : PartialOrder (Measure α)),
(by infer_instance : InfSet (Measure α)) with
sInf_le := fun _s _a => measure_sInf_le
le_sInf := fun _s _a => measure_le_sInf }
instance instCompleteLattice [MeasurableSpace α] : CompleteLattice (Measure α) :=
{ completeLatticeOfCompleteSemilatticeInf (Measure α) with
top :=
{ toOuterMeasure := ⊤,
m_iUnion := by
intro f _ _
refine (measure_iUnion_le _).antisymm ?_
if hne : (⋃ i, f i).Nonempty then
rw [OuterMeasure.top_apply hne]
exact le_top
else
simp_all [Set.not_nonempty_iff_eq_empty]
trim_le := le_top },
le_top := fun μ => toOuterMeasure_le.mp le_top
bot := 0
bot_le := fun _a _s => bot_le }
end sInf
@[simp]
theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top :
(⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) =
(⊤ : Measure α) :=
toOuterMeasure_toMeasure (μ := ⊤)
@[simp]
theorem toOuterMeasure_top [MeasurableSpace α] :
(⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) :=
rfl
@[simp]
theorem top_add : ⊤ + μ = ⊤ :=
top_unique <| Measure.le_add_right le_rfl
@[simp]
theorem add_top : μ + ⊤ = ⊤ :=
top_unique <| Measure.le_add_left le_rfl
protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ :=
bot_le
theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 :=
μ.zero_le.le_iff_eq
@[simp]
theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 :=
⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h =>
h.symm ▸ rfl⟩
theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 :=
measure_univ_eq_zero.not
instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩
@[simp]
theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 :=
pos_iff_ne_zero.trans measure_univ_ne_zero
/-! ### Pushforward and pullback -/
/-- Lift a linear map between `OuterMeasure` spaces such that for each measure `μ` every measurable
set is caratheodory-measurable w.r.t. `f μ` to a linear map between `Measure` spaces. -/
def liftLinear {m0 : MeasurableSpace α} (f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β)
(hf : ∀ μ : Measure α, ‹_› ≤ (f μ.toOuterMeasure).caratheodory) :
Measure α →ₗ[ℝ≥0∞] Measure β where
toFun μ := (f μ.toOuterMeasure).toMeasure (hf μ)
map_add' μ₁ μ₂ := ext fun s hs => by
simp only [map_add, coe_add, Pi.add_apply, toMeasure_apply, add_toOuterMeasure,
OuterMeasure.coe_add, hs]
map_smul' c μ := ext fun s hs => by
simp only [LinearMap.map_smulₛₗ, coe_smul, Pi.smul_apply,
toMeasure_apply, smul_toOuterMeasure (R := ℝ≥0∞), OuterMeasure.coe_smul (R := ℝ≥0∞),
smul_apply, hs]
lemma liftLinear_apply₀ {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β}
(hs : NullMeasurableSet s (liftLinear f hf μ)) : liftLinear f hf μ s = f μ.toOuterMeasure s :=
toMeasure_apply₀ _ (hf μ) hs
@[simp]
theorem liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β}
(hs : MeasurableSet s) : liftLinear f hf μ s = f μ.toOuterMeasure s :=
toMeasure_apply _ (hf μ) hs
theorem le_liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) (s : Set β) :
f μ.toOuterMeasure s ≤ liftLinear f hf μ s :=
le_toMeasure_apply _ (hf μ) s
open Classical in
/-- The pushforward of a measure as a linear map. It is defined to be `0` if `f` is not
a measurable function. -/
def mapₗ [MeasurableSpace α] (f : α → β) : Measure α →ₗ[ℝ≥0∞] Measure β :=
if hf : Measurable f then
liftLinear (OuterMeasure.map f) fun μ _s hs t =>
le_toOuterMeasure_caratheodory μ _ (hf hs) (f ⁻¹' t)
else 0
theorem mapₗ_congr {f g : α → β} (hf : Measurable f) (hg : Measurable g) (h : f =ᵐ[μ] g) :
mapₗ f μ = mapₗ g μ := by
ext1 s hs
simpa only [mapₗ, hf, hg, hs, dif_pos, liftLinear_apply, OuterMeasure.map_apply]
using measure_congr (h.preimage s)
open Classical in
/-- The pushforward of a measure. It is defined to be `0` if `f` is not an almost everywhere
measurable function. -/
irreducible_def map [MeasurableSpace α] (f : α → β) (μ : Measure α) : Measure β :=
if hf : AEMeasurable f μ then mapₗ (hf.mk f) μ else 0
theorem mapₗ_mk_apply_of_aemeasurable {f : α → β} (hf : AEMeasurable f μ) :
mapₗ (hf.mk f) μ = map f μ := by simp [map, hf]
theorem mapₗ_apply_of_measurable {f : α → β} (hf : Measurable f) (μ : Measure α) :
mapₗ f μ = map f μ := by
simp only [← mapₗ_mk_apply_of_aemeasurable hf.aemeasurable]
exact mapₗ_congr hf hf.aemeasurable.measurable_mk hf.aemeasurable.ae_eq_mk
@[simp]
theorem map_add (μ ν : Measure α) {f : α → β} (hf : Measurable f) :
(μ + ν).map f = μ.map f + ν.map f := by simp [← mapₗ_apply_of_measurable hf]
@[simp]
theorem map_zero (f : α → β) : (0 : Measure α).map f = 0 := by
by_cases hf : AEMeasurable f (0 : Measure α) <;> simp [map, hf]
@[simp]
theorem map_of_not_aemeasurable {f : α → β} {μ : Measure α} (hf : ¬AEMeasurable f μ) :
μ.map f = 0 := by simp [map, hf]
theorem map_congr {f g : α → β} (h : f =ᵐ[μ] g) : Measure.map f μ = Measure.map g μ := by
by_cases hf : AEMeasurable f μ
· have hg : AEMeasurable g μ := hf.congr h
simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hg]
exact
mapₗ_congr hf.measurable_mk hg.measurable_mk (hf.ae_eq_mk.symm.trans (h.trans hg.ae_eq_mk))
· have hg : ¬AEMeasurable g μ := by simpa [← aemeasurable_congr h] using hf
simp [map_of_not_aemeasurable, hf, hg]
@[simp]
protected theorem map_smul (c : ℝ≥0∞) (μ : Measure α) (f : α → β) :
(c • μ).map f = c • μ.map f := by
rcases eq_or_ne c 0 with (rfl | hc); · simp
by_cases hf : AEMeasurable f μ
· have hfc : AEMeasurable f (c • μ) :=
⟨hf.mk f, hf.measurable_mk, (ae_smul_measure_iff hc).2 hf.ae_eq_mk⟩
simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hfc,
LinearMap.map_smulₛₗ, RingHom.id_apply]
congr 1
apply mapₗ_congr hfc.measurable_mk hf.measurable_mk
exact EventuallyEq.trans ((ae_smul_measure_iff hc).1 hfc.ae_eq_mk.symm) hf.ae_eq_mk
· have hfc : ¬AEMeasurable f (c • μ) := by
intro hfc
exact hf ⟨hfc.mk f, hfc.measurable_mk, (ae_smul_measure_iff hc).1 hfc.ae_eq_mk⟩
simp [map_of_not_aemeasurable hf, map_of_not_aemeasurable hfc]
@[simp]
protected theorem map_smul_nnreal (c : ℝ≥0) (μ : Measure α) (f : α → β) :
(c • μ).map f = c • μ.map f :=
μ.map_smul (c : ℝ≥0∞) f
variable {f : α → β}
lemma map_apply₀ {f : α → β} (hf : AEMeasurable f μ) {s : Set β}
(hs : NullMeasurableSet s (map f μ)) : μ.map f s = μ (f ⁻¹' s) := by
rw [map, dif_pos hf, mapₗ, dif_pos hf.measurable_mk] at hs ⊢
rw [liftLinear_apply₀ _ hs, measure_congr (hf.ae_eq_mk.preimage s)]
rfl
/-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see
`MeasureTheory.Measure.le_map_apply` and `MeasurableEquiv.map_apply`. -/
@[simp]
theorem map_apply_of_aemeasurable (hf : AEMeasurable f μ) {s : Set β} (hs : MeasurableSet s) :
μ.map f s = μ (f ⁻¹' s) := map_apply₀ hf hs.nullMeasurableSet
@[simp]
theorem map_apply (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
μ.map f s = μ (f ⁻¹' s) :=
map_apply_of_aemeasurable hf.aemeasurable hs
theorem map_toOuterMeasure (hf : AEMeasurable f μ) :
(μ.map f).toOuterMeasure = (OuterMeasure.map f μ.toOuterMeasure).trim := by
rw [← trimmed, OuterMeasure.trim_eq_trim_iff]
intro s hs
simp [hf, hs]
@[simp] lemma map_eq_zero_iff (hf : AEMeasurable f μ) : μ.map f = 0 ↔ μ = 0 := by
simp_rw [← measure_univ_eq_zero, map_apply_of_aemeasurable hf .univ, preimage_univ]
@[simp] lemma mapₗ_eq_zero_iff (hf : Measurable f) : Measure.mapₗ f μ = 0 ↔ μ = 0 := by
rw [mapₗ_apply_of_measurable hf, map_eq_zero_iff hf.aemeasurable]
/-- If `map f μ = μ`, then the measure of the preimage of any null measurable set `s`
is equal to the measure of `s`.
Note that this lemma does not assume (a.e.) measurability of `f`. -/
lemma measure_preimage_of_map_eq_self {f : α → α} (hf : map f μ = μ)
{s : Set α} (hs : NullMeasurableSet s μ) : μ (f ⁻¹' s) = μ s := by
if hfm : AEMeasurable f μ then
rw [← map_apply₀ hfm, hf]
rwa [hf]
else
rw [map_of_not_aemeasurable hfm] at hf
simp [← hf]
lemma map_ne_zero_iff (hf : AEMeasurable f μ) : μ.map f ≠ 0 ↔ μ ≠ 0 := (map_eq_zero_iff hf).not
lemma mapₗ_ne_zero_iff (hf : Measurable f) : Measure.mapₗ f μ ≠ 0 ↔ μ ≠ 0 :=
(mapₗ_eq_zero_iff hf).not
@[simp]
theorem map_id : map id μ = μ :=
ext fun _ => map_apply measurable_id
@[simp]
theorem map_id' : map (fun x => x) μ = μ :=
map_id
theorem map_map {g : β → γ} {f : α → β} (hg : Measurable g) (hf : Measurable f) :
(μ.map f).map g = μ.map (g ∘ f) :=
ext fun s hs => by simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp]
@[mono]
theorem map_mono {f : α → β} (h : μ ≤ ν) (hf : Measurable f) : μ.map f ≤ ν.map f :=
le_iff.2 fun s hs ↦ by simp [hf.aemeasurable, hs, h _]
/-- Even if `s` is not measurable, we can bound `map f μ s` from below.
See also `MeasurableEquiv.map_apply`. -/
theorem le_map_apply {f : α → β} (hf : AEMeasurable f μ) (s : Set β) : μ (f ⁻¹' s) ≤ μ.map f s :=
calc
μ (f ⁻¹' s) ≤ μ (f ⁻¹' toMeasurable (μ.map f) s) := by gcongr; apply subset_toMeasurable
_ = μ.map f (toMeasurable (μ.map f) s) :=
(map_apply_of_aemeasurable hf <| measurableSet_toMeasurable _ _).symm
_ = μ.map f s := measure_toMeasurable _
theorem le_map_apply_image {f : α → β} (hf : AEMeasurable f μ) (s : Set α) :
μ s ≤ μ.map f (f '' s) :=
(measure_mono (subset_preimage_image f s)).trans (le_map_apply hf _)
/-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/
theorem preimage_null_of_map_null {f : α → β} (hf : AEMeasurable f μ) {s : Set β}
(hs : μ.map f s = 0) : μ (f ⁻¹' s) = 0 :=
nonpos_iff_eq_zero.mp <| (le_map_apply hf s).trans_eq hs
theorem tendsto_ae_map {f : α → β} (hf : AEMeasurable f μ) : Tendsto f (ae μ) (ae (μ.map f)) :=
fun _ hs => preimage_null_of_map_null hf hs
open Classical in
/-- Pullback of a `Measure` as a linear map. If `f` sends each measurable set to a measurable
set, then for each measurable set `s` we have `comapₗ f μ s = μ (f '' s)`.
Note that if `f` is not injective, this definition assigns `Set.univ` measure zero.
If the linearity is not needed, please use `comap` instead, which works for a larger class of
functions. `comapₗ` is an auxiliary definition and most lemmas deal with comap. -/
def comapₗ [MeasurableSpace α] (f : α → β) : Measure β →ₗ[ℝ≥0∞] Measure α :=
if hf : Injective f ∧ ∀ s, MeasurableSet s → MeasurableSet (f '' s) then
liftLinear (OuterMeasure.comap f) fun μ s hs t => by
simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1]
apply le_toOuterMeasure_caratheodory
exact hf.2 s hs
else 0
theorem comapₗ_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β)
(hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β)
(hs : MeasurableSet s) : comapₗ f μ s = μ (f '' s) := by
rw [comapₗ, dif_pos, liftLinear_apply _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure]
exact ⟨hfi, hf⟩
open Classical in
/-- Pullback of a `Measure`. If `f` sends each measurable set to a null-measurable set,
then for each measurable set `s` we have `comap f μ s = μ (f '' s)`.
Note that if `f` is not injective, this definition assigns `Set.univ` measure zero. -/
def comap [MeasurableSpace α] (f : α → β) (μ : Measure β) : Measure α :=
if hf : Injective f ∧ ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ then
(OuterMeasure.comap f μ.toOuterMeasure).toMeasure fun s hs t => by
simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1]
exact (measure_inter_add_diff₀ _ (hf.2 s hs)).symm
else 0
theorem comap_apply₀ [MeasurableSpace α] (f : α → β) (μ : Measure β) (hfi : Injective f)
(hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ)
(hs : NullMeasurableSet s (comap f μ)) : comap f μ s = μ (f '' s) := by
rw [comap, dif_pos (And.intro hfi hf)] at hs ⊢
rw [toMeasure_apply₀ _ _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure]
theorem le_comap_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β)
(hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (s : Set α) :
μ (f '' s) ≤ comap f μ s := by
rw [comap, dif_pos (And.intro hfi hf)]
exact le_toMeasure_apply _ _ _
theorem comap_apply {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β)
(hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β)
(hs : MeasurableSet s) : comap f μ s = μ (f '' s) :=
comap_apply₀ f μ hfi (fun s hs => (hf s hs).nullMeasurableSet) hs.nullMeasurableSet
theorem comapₗ_eq_comap {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β)
(hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β)
(hs : MeasurableSet s) : comapₗ f μ s = comap f μ s :=
(comapₗ_apply f hfi hf μ hs).trans (comap_apply f hfi hf μ hs).symm
theorem measure_image_eq_zero_of_comap_eq_zero {β} [MeasurableSpace α] {_mβ : MeasurableSpace β}
(f : α → β) (μ : Measure β) (hfi : Injective f)
(hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : comap f μ s = 0) :
μ (f '' s) = 0 :=
le_antisymm ((le_comap_apply f μ hfi hf s).trans hs.le) (zero_le _)
theorem ae_eq_image_of_ae_eq_comap {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β)
(μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ)
{s t : Set α} (hst : s =ᵐ[comap f μ] t) : f '' s =ᵐ[μ] f '' t := by
rw [EventuallyEq, ae_iff] at hst ⊢
have h_eq_α : { a : α | ¬s a = t a } = s \ t ∪ t \ s := by
ext1 x
simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff]
tauto
have h_eq_β : { a : β | ¬(f '' s) a = (f '' t) a } = f '' s \ f '' t ∪ f '' t \ f '' s := by
ext1 x
simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff]
tauto
rw [← Set.image_diff hfi, ← Set.image_diff hfi, ← Set.image_union] at h_eq_β
rw [h_eq_β]
rw [h_eq_α] at hst
exact measure_image_eq_zero_of_comap_eq_zero f μ hfi hf hst
theorem NullMeasurableSet.image {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β)
(μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ)
{s : Set α} (hs : NullMeasurableSet s (μ.comap f)) : NullMeasurableSet (f '' s) μ := by
refine ⟨toMeasurable μ (f '' toMeasurable (μ.comap f) s), measurableSet_toMeasurable _ _, ?_⟩
refine EventuallyEq.trans ?_ (NullMeasurableSet.toMeasurable_ae_eq ?_).symm
swap
· exact hf _ (measurableSet_toMeasurable _ _)
have h : toMeasurable (comap f μ) s =ᵐ[comap f μ] s :=
NullMeasurableSet.toMeasurable_ae_eq hs
exact ae_eq_image_of_ae_eq_comap f μ hfi hf h.symm
theorem comap_preimage {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β)
{s : Set β} (hf : Injective f) (hf' : Measurable f)
(h : ∀ t, MeasurableSet t → NullMeasurableSet (f '' t) μ) (hs : MeasurableSet s) :
μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by
rw [comap_apply₀ _ _ hf h (hf' hs).nullMeasurableSet, image_preimage_eq_inter_range]
section Sum
/-- Sum of an indexed family of measures. -/
noncomputable def sum (f : ι → Measure α) : Measure α :=
(OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <|
le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _)
(OuterMeasure.le_sum_caratheodory _)
theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s :=
le_toMeasure_apply _ _ _
@[simp]
theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
sum f s = ∑' i, f i s :=
toMeasure_apply _ _ hs
theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) :
sum f s = ∑' i, f i s := by
apply le_antisymm ?_ (le_sum_apply _ _)
rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩
calc
sum f s = sum f t := measure_congr ht.symm
_ = ∑' i, f i t := sum_apply _ t_meas
_ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts
/-! For the next theorem, the countability assumption is necessary. For a counterexample, consider
an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets
not containing `x₀`, and their complements. All points but `x₀` are measurable.
Consider the sum of the Dirac masses at points different from `x₀`, and `s = x₀`. For any Dirac mass
`δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure `sum δ_x`
gives mass one to each point different from `x₀`, so it gives infinite mass to any measurable set
containing `x₀` (as such a set is uncountable), and by outer regularity one get `sum δ_x {x₀} = ∞`.
-/
theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) :
sum f s = ∑' i, f i s := by
apply le_antisymm ?_ (le_sum_apply _ _)
rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩
calc
sum f s ≤ sum f t := measure_mono hst
_ = ∑' i, f i t := sum_apply _ htm
_ = ∑' i, f i s := by simp [ht]
theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ :=
le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i
@[simp]
theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} :
sum μ s = 0 ↔ ∀ i, μ i s = 0 := by
simp [sum_apply_of_countable]
theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) :
sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs]
@[simp]
lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by
ext s hs
simp [Measure.sum_apply _ hs]
theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) :
(sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by
ext1 s hs
simp [sum_apply _ hs, ENNReal.tsum_prod']
theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) :
(sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by
ext1 s hs
simp_rw [sum_apply _ hs]
rw [ENNReal.tsum_comm]
theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} :
(∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x :=
sum_apply_eq_zero
theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) :
(∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x :=
sum_apply_eq_zero' h.compl
@[simp]
theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by
ext1 s hs
simp only [sum_apply, finset_sum_apply, hs, tsum_fintype]
theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) :
(sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ]
@[simp]
theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) :=
Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm
theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by
rw [sum_fintype, Fintype.sum_bool]
theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν :=
sum_bool _
@[simp]
theorem sum_of_isEmpty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by
rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty]
@[deprecated (since := "2024-06-11")] alias sum_of_empty := sum_of_isEmpty
theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) :
((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by
ext1 t ht
simp only [add_apply, sum_apply _ ht]
exact tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable ENNReal.summable
theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν :=
congr_arg sum (funext h)
theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by
ext1 s hs
simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add,
tsum_add ENNReal.summable ENNReal.summable]
@[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) :
sum (m ∘ e) = sum m := by
ext s hs
simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s)
@[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) :
sum (Function.extend f m 0) = sum m := by
ext s hs
simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)]
end Sum
/-! ### Absolute continuity -/
/-- We say that `μ` is absolutely continuous with respect to `ν`, or that `μ` is dominated by `ν`,
if `ν(A) = 0` implies that `μ(A) = 0`. -/
def AbsolutelyContinuous {_m0 : MeasurableSpace α} (μ ν : Measure α) : Prop :=
∀ ⦃s : Set α⦄, ν s = 0 → μ s = 0
@[inherit_doc MeasureTheory.Measure.AbsolutelyContinuous]
scoped[MeasureTheory] infixl:50 " ≪ " => MeasureTheory.Measure.AbsolutelyContinuous
theorem absolutelyContinuous_of_le (h : μ ≤ ν) : μ ≪ ν := fun s hs =>
nonpos_iff_eq_zero.1 <| hs ▸ le_iff'.1 h s
alias _root_.LE.le.absolutelyContinuous := absolutelyContinuous_of_le
theorem absolutelyContinuous_of_eq (h : μ = ν) : μ ≪ ν :=
h.le.absolutelyContinuous
alias _root_.Eq.absolutelyContinuous := absolutelyContinuous_of_eq
namespace AbsolutelyContinuous
theorem mk (h : ∀ ⦃s : Set α⦄, MeasurableSet s → ν s = 0 → μ s = 0) : μ ≪ ν := by
intro s hs
rcases exists_measurable_superset_of_null hs with ⟨t, h1t, h2t, h3t⟩
exact measure_mono_null h1t (h h2t h3t)
@[refl]
protected theorem refl {_m0 : MeasurableSpace α} (μ : Measure α) : μ ≪ μ :=
rfl.absolutelyContinuous
protected theorem rfl : μ ≪ μ := fun _s hs => hs
instance instIsRefl [MeasurableSpace α] : IsRefl (Measure α) (· ≪ ·) :=
⟨fun _ => AbsolutelyContinuous.rfl⟩
@[simp]
protected lemma zero (μ : Measure α) : 0 ≪ μ := fun s _ ↦ by simp
@[trans]
protected theorem trans (h1 : μ₁ ≪ μ₂) (h2 : μ₂ ≪ μ₃) : μ₁ ≪ μ₃ := fun _s hs => h1 <| h2 hs
@[mono]
protected theorem map (h : μ ≪ ν) {f : α → β} (hf : Measurable f) : μ.map f ≪ ν.map f :=
AbsolutelyContinuous.mk fun s hs => by simpa [hf, hs] using @h _
protected theorem smul [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : μ ≪ ν) (c : R) : c • μ ≪ ν := fun s hνs => by
simp only [h hνs, smul_eq_mul, smul_apply, smul_zero]
protected lemma add (h1 : μ₁ ≪ ν) (h2 : μ₂ ≪ ν') : μ₁ + μ₂ ≪ ν + ν' := by
intro s hs
simp only [coe_add, Pi.add_apply, add_eq_zero] at hs ⊢
exact ⟨h1 hs.1, h2 hs.2⟩
lemma add_left_iff {μ₁ μ₂ ν : Measure α} :
μ₁ + μ₂ ≪ ν ↔ μ₁ ≪ ν ∧ μ₂ ≪ ν := by
refine ⟨fun h ↦ ?_, fun h ↦ (h.1.add h.2).trans ?_⟩
· have : ∀ s, ν s = 0 → μ₁ s = 0 ∧ μ₂ s = 0 := by intro s hs0; simpa using h hs0
exact ⟨fun s hs0 ↦ (this s hs0).1, fun s hs0 ↦ (this s hs0).2⟩
· have : ν + ν = 2 • ν := by ext; simp [two_mul]
rw [this]
exact AbsolutelyContinuous.rfl.smul 2
lemma add_left {μ₁ μ₂ ν : Measure α} (h₁ : μ₁ ≪ ν) (h₂ : μ₂ ≪ ν) : μ₁ + μ₂ ≪ ν :=
Measure.AbsolutelyContinuous.add_left_iff.mpr ⟨h₁, h₂⟩
lemma add_right (h1 : μ ≪ ν) (ν' : Measure α) : μ ≪ ν + ν' := by
intro s hs
simp only [coe_add, Pi.add_apply, add_eq_zero] at hs ⊢
exact h1 hs.1
end AbsolutelyContinuous
@[simp]
lemma absolutelyContinuous_zero_iff : μ ≪ 0 ↔ μ = 0 :=
⟨fun h ↦ measure_univ_eq_zero.mp (h rfl), fun h ↦ h.symm ▸ AbsolutelyContinuous.zero _⟩
alias absolutelyContinuous_refl := AbsolutelyContinuous.refl
alias absolutelyContinuous_rfl := AbsolutelyContinuous.rfl
lemma absolutelyContinuous_sum_left {μs : ι → Measure α} (hμs : ∀ i, μs i ≪ ν) :
Measure.sum μs ≪ ν :=
AbsolutelyContinuous.mk fun s hs hs0 ↦ by simp [sum_apply _ hs, fun i ↦ hμs i hs0]
lemma absolutelyContinuous_sum_right {μs : ι → Measure α} (i : ι) (hνμ : ν ≪ μs i) :
ν ≪ Measure.sum μs := by
refine AbsolutelyContinuous.mk fun s hs hs0 ↦ ?_
simp only [sum_apply _ hs, ENNReal.tsum_eq_zero] at hs0
exact hνμ (hs0 i)
theorem absolutelyContinuous_of_le_smul {μ' : Measure α} {c : ℝ≥0∞} (hμ'_le : μ' ≤ c • μ) :
μ' ≪ μ :=
(Measure.absolutelyContinuous_of_le hμ'_le).trans (Measure.AbsolutelyContinuous.rfl.smul c)
lemma smul_absolutelyContinuous {c : ℝ≥0∞} : c • μ ≪ μ := absolutelyContinuous_of_le_smul le_rfl
lemma absolutelyContinuous_smul {c : ℝ≥0∞} (hc : c ≠ 0) : μ ≪ c • μ := by
simp [AbsolutelyContinuous, hc]
theorem ae_le_iff_absolutelyContinuous : ae μ ≤ ae ν ↔ μ ≪ ν :=
⟨fun h s => by
rw [measure_zero_iff_ae_nmem, measure_zero_iff_ae_nmem]
exact fun hs => h hs, fun h s hs => h hs⟩
alias ⟨_root_.LE.le.absolutelyContinuous_of_ae, AbsolutelyContinuous.ae_le⟩ :=
ae_le_iff_absolutelyContinuous
alias ae_mono' := AbsolutelyContinuous.ae_le
theorem AbsolutelyContinuous.ae_eq (h : μ ≪ ν) {f g : α → δ} (h' : f =ᵐ[ν] g) : f =ᵐ[μ] g :=
h.ae_le h'
protected theorem _root_.MeasureTheory.AEDisjoint.of_absolutelyContinuous
(h : AEDisjoint μ s t) {ν : Measure α} (h' : ν ≪ μ) :
AEDisjoint ν s t := h' h
protected theorem _root_.MeasureTheory.AEDisjoint.of_le
(h : AEDisjoint μ s t) {ν : Measure α} (h' : ν ≤ μ) :
AEDisjoint ν s t :=
h.of_absolutelyContinuous (Measure.absolutelyContinuous_of_le h')
/-! ### Quasi measure preserving maps (a.k.a. non-singular maps) -/
/-- A map `f : α → β` is said to be *quasi measure preserving* (a.k.a. non-singular) w.r.t. measures
`μa` and `μb` if it is measurable and `μb s = 0` implies `μa (f ⁻¹' s) = 0`. -/
structure QuasiMeasurePreserving {m0 : MeasurableSpace α} (f : α → β)
(μa : Measure α := by volume_tac)
(μb : Measure β := by volume_tac) : Prop where
protected measurable : Measurable f
protected absolutelyContinuous : μa.map f ≪ μb
namespace QuasiMeasurePreserving
protected theorem id {_m0 : MeasurableSpace α} (μ : Measure α) : QuasiMeasurePreserving id μ μ :=
⟨measurable_id, map_id.absolutelyContinuous⟩
variable {μa μa' : Measure α} {μb μb' : Measure β} {μc : Measure γ} {f : α → β}
protected theorem _root_.Measurable.quasiMeasurePreserving
{_m0 : MeasurableSpace α} (hf : Measurable f) (μ : Measure α) :
QuasiMeasurePreserving f μ (μ.map f) :=
⟨hf, AbsolutelyContinuous.rfl⟩
theorem mono_left (h : QuasiMeasurePreserving f μa μb) (ha : μa' ≪ μa) :
QuasiMeasurePreserving f μa' μb :=
⟨h.1, (ha.map h.1).trans h.2⟩
theorem mono_right (h : QuasiMeasurePreserving f μa μb) (ha : μb ≪ μb') :
QuasiMeasurePreserving f μa μb' :=
⟨h.1, h.2.trans ha⟩
@[mono]
theorem mono (ha : μa' ≪ μa) (hb : μb ≪ μb') (h : QuasiMeasurePreserving f μa μb) :
QuasiMeasurePreserving f μa' μb' :=
(h.mono_left ha).mono_right hb
protected theorem comp {g : β → γ} {f : α → β} (hg : QuasiMeasurePreserving g μb μc)
(hf : QuasiMeasurePreserving f μa μb) : QuasiMeasurePreserving (g ∘ f) μa μc :=
⟨hg.measurable.comp hf.measurable, by
rw [← map_map hg.1 hf.1]
exact (hf.2.map hg.1).trans hg.2⟩
protected theorem iterate {f : α → α} (hf : QuasiMeasurePreserving f μa μa) :
∀ n, QuasiMeasurePreserving f^[n] μa μa
| 0 => QuasiMeasurePreserving.id μa
| n + 1 => (hf.iterate n).comp hf
protected theorem aemeasurable (hf : QuasiMeasurePreserving f μa μb) : AEMeasurable f μa :=
hf.1.aemeasurable
theorem ae_map_le (h : QuasiMeasurePreserving f μa μb) : ae (μa.map f) ≤ ae μb :=
h.2.ae_le
theorem tendsto_ae (h : QuasiMeasurePreserving f μa μb) : Tendsto f (ae μa) (ae μb) :=
(tendsto_ae_map h.aemeasurable).mono_right h.ae_map_le
theorem ae (h : QuasiMeasurePreserving f μa μb) {p : β → Prop} (hg : ∀ᵐ x ∂μb, p x) :
∀ᵐ x ∂μa, p (f x) :=
h.tendsto_ae hg
theorem ae_eq (h : QuasiMeasurePreserving f μa μb) {g₁ g₂ : β → δ} (hg : g₁ =ᵐ[μb] g₂) :
g₁ ∘ f =ᵐ[μa] g₂ ∘ f :=
h.ae hg
theorem preimage_null (h : QuasiMeasurePreserving f μa μb) {s : Set β} (hs : μb s = 0) :
μa (f ⁻¹' s) = 0 :=
preimage_null_of_map_null h.aemeasurable (h.2 hs)
theorem preimage_mono_ae {s t : Set β} (hf : QuasiMeasurePreserving f μa μb) (h : s ≤ᵐ[μb] t) :
f ⁻¹' s ≤ᵐ[μa] f ⁻¹' t :=
eventually_map.mp <|
Eventually.filter_mono (tendsto_ae_map hf.aemeasurable) (Eventually.filter_mono hf.ae_map_le h)
theorem preimage_ae_eq {s t : Set β} (hf : QuasiMeasurePreserving f μa μb) (h : s =ᵐ[μb] t) :
f ⁻¹' s =ᵐ[μa] f ⁻¹' t :=
EventuallyLE.antisymm (hf.preimage_mono_ae h.le) (hf.preimage_mono_ae h.symm.le)
theorem preimage_iterate_ae_eq {s : Set α} {f : α → α} (hf : QuasiMeasurePreserving f μ μ) (k : ℕ)
(hs : f ⁻¹' s =ᵐ[μ] s) : f^[k] ⁻¹' s =ᵐ[μ] s := by
induction' k with k ih; · rfl
rw [iterate_succ, preimage_comp]
exact EventuallyEq.trans (hf.preimage_ae_eq ih) hs
theorem image_zpow_ae_eq {s : Set α} {e : α ≃ α} (he : QuasiMeasurePreserving e μ μ)
(he' : QuasiMeasurePreserving e.symm μ μ) (k : ℤ) (hs : e '' s =ᵐ[μ] s) :
(⇑(e ^ k)) '' s =ᵐ[μ] s := by
rw [Equiv.image_eq_preimage]
obtain ⟨k, rfl | rfl⟩ := k.eq_nat_or_neg
· replace hs : (⇑e⁻¹) ⁻¹' s =ᵐ[μ] s := by rwa [Equiv.image_eq_preimage] at hs
replace he' : (⇑e⁻¹)^[k] ⁻¹' s =ᵐ[μ] s := he'.preimage_iterate_ae_eq k hs
rwa [Equiv.Perm.iterate_eq_pow e⁻¹ k, inv_pow e k] at he'
· rw [zpow_neg, zpow_natCast]
replace hs : e ⁻¹' s =ᵐ[μ] s := by
convert he.preimage_ae_eq hs.symm
rw [Equiv.preimage_image]
replace he : (⇑e)^[k] ⁻¹' s =ᵐ[μ] s := he.preimage_iterate_ae_eq k hs
rwa [Equiv.Perm.iterate_eq_pow e k] at he
-- Need to specify `α := Set α` below because of diamond; see #19041
theorem limsup_preimage_iterate_ae_eq {f : α → α} (hf : QuasiMeasurePreserving f μ μ)
(hs : f ⁻¹' s =ᵐ[μ] s) : limsup (α := Set α) (fun n => (preimage f)^[n] s) atTop =ᵐ[μ] s :=
haveI : ∀ n, (preimage f)^[n] s =ᵐ[μ] s := by
intro n
induction' n with n ih
· rfl
simpa only [iterate_succ', comp_apply] using ae_eq_trans (hf.ae_eq ih) hs
(limsup_ae_eq_of_forall_ae_eq (fun n => (preimage f)^[n] s) this).trans (ae_eq_refl _)
-- Need to specify `α := Set α` below because of diamond; see #19041
theorem liminf_preimage_iterate_ae_eq {f : α → α} (hf : QuasiMeasurePreserving f μ μ)
(hs : f ⁻¹' s =ᵐ[μ] s) : liminf (α := Set α) (fun n => (preimage f)^[n] s) atTop =ᵐ[μ] s := by
rw [← ae_eq_set_compl_compl, @Filter.liminf_compl (Set α)]
rw [← ae_eq_set_compl_compl, ← preimage_compl] at hs
convert hf.limsup_preimage_iterate_ae_eq hs
ext1 n
simp only [← Set.preimage_iterate_eq, comp_apply, preimage_compl]
/-- By replacing a measurable set that is almost invariant with the `limsup` of its preimages, we
obtain a measurable set that is almost equal and strictly invariant.
(The `liminf` would work just as well.) -/
theorem exists_preimage_eq_of_preimage_ae {f : α → α} (h : QuasiMeasurePreserving f μ μ)
(hs : MeasurableSet s) (hs' : f ⁻¹' s =ᵐ[μ] s) :
∃ t : Set α, MeasurableSet t ∧ t =ᵐ[μ] s ∧ f ⁻¹' t = t :=
⟨limsup (fun n => (preimage f)^[n] s) atTop,
MeasurableSet.measurableSet_limsup fun n =>
preimage_iterate_eq ▸ h.measurable.iterate n hs,
h.limsup_preimage_iterate_ae_eq hs',
(CompleteLatticeHom.setPreimage f).apply_limsup_iterate s⟩
open Pointwise
@[to_additive]
theorem smul_ae_eq_of_ae_eq {G α : Type*} [Group G] [MulAction G α] [MeasurableSpace α]
{s t : Set α} {μ : Measure α} (g : G)
(h_qmp : QuasiMeasurePreserving (g⁻¹ • · : α → α) μ μ)
(h_ae_eq : s =ᵐ[μ] t) : (g • s : Set α) =ᵐ[μ] (g • t : Set α) := by
simpa only [← preimage_smul_inv] using h_qmp.ae_eq h_ae_eq
end QuasiMeasurePreserving
section Pointwise
open Pointwise
@[to_additive]
theorem pairwise_aedisjoint_of_aedisjoint_forall_ne_one {G α : Type*} [Group G] [MulAction G α]
[MeasurableSpace α] {μ : Measure α} {s : Set α}
(h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s)
(h_qmp : ∀ g : G, QuasiMeasurePreserving (g • ·) μ μ) :
Pairwise (AEDisjoint μ on fun g : G => g • s) := by
intro g₁ g₂ hg
let g := g₂⁻¹ * g₁
replace hg : g ≠ 1 := by
rw [Ne, inv_mul_eq_one]
exact hg.symm
have : (g₂⁻¹ • ·) ⁻¹' (g • s ∩ s) = g₁ • s ∩ g₂ • s := by
rw [preimage_eq_iff_eq_image (MulAction.bijective g₂⁻¹), image_smul, smul_set_inter, smul_smul,
smul_smul, inv_mul_self, one_smul]
change μ (g₁ • s ∩ g₂ • s) = 0
exact this ▸ (h_qmp g₂⁻¹).preimage_null (h_ae_disjoint g hg)
end Pointwise
/-! ### The `cofinite` filter -/
/-- The filter of sets `s` such that `sᶜ` has finite measure. -/
def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α :=
comk (μ · < ∞) (by simp) (fun t ht s hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦
(measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩
theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ :=
Iff.rfl
theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ :=
Iff.rfl
instance cofinite.instIsMeasurablyGenerated : IsMeasurablyGenerated μ.cofinite where
exists_measurable_subset s hs := by
refine ⟨(toMeasurable μ sᶜ)ᶜ, ?_, (measurableSet_toMeasurable _ _).compl, ?_⟩
· rwa [compl_mem_cofinite, measure_toMeasurable]
· rw [compl_subset_comm]
apply subset_toMeasurable
end Measure
open Measure
open MeasureTheory
protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) :
NullMeasurable f μ :=
let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm
lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β}
(hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ :=
hf.nullMeasurable hs
/-- The preimage of a null measurable set under a (quasi) measure preserving map is a null
measurable set. -/
theorem NullMeasurableSet.preimage {ν : Measure β} {f : α → β} {t : Set β}
(ht : NullMeasurableSet t ν) (hf : QuasiMeasurePreserving f μ ν) :
NullMeasurableSet (f ⁻¹' t) μ :=
⟨f ⁻¹' toMeasurable ν t, hf.measurable (measurableSet_toMeasurable _ _),
hf.ae_eq ht.toMeasurable_ae_eq.symm⟩
theorem NullMeasurableSet.mono_ac (h : NullMeasurableSet s μ) (hle : ν ≪ μ) :
NullMeasurableSet s ν :=
h.preimage <| (QuasiMeasurePreserving.id μ).mono_left hle
theorem NullMeasurableSet.mono (h : NullMeasurableSet s μ) (hle : ν ≤ μ) : NullMeasurableSet s ν :=
h.mono_ac hle.absolutelyContinuous
theorem AEDisjoint.preimage {ν : Measure β} {f : α → β} {s t : Set β} (ht : AEDisjoint ν s t)
(hf : QuasiMeasurePreserving f μ ν) : AEDisjoint μ (f ⁻¹' s) (f ⁻¹' t) :=
hf.preimage_null ht
@[simp]
theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by
rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]
@[simp]
theorem ae_neBot : (ae μ).NeBot ↔ μ ≠ 0 :=
neBot_iff.trans (not_congr ae_eq_bot)
instance Measure.ae.neBot [NeZero μ] : (ae μ).NeBot := ae_neBot.2 <| NeZero.ne μ
@[simp]
theorem ae_zero {_m0 : MeasurableSpace α} : ae (0 : Measure α) = ⊥ :=
ae_eq_bot.2 rfl
@[mono]
theorem ae_mono (h : μ ≤ ν) : ae μ ≤ ae ν :=
h.absolutelyContinuous.ae_le
theorem mem_ae_map_iff {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : MeasurableSet s) :
s ∈ ae (μ.map f) ↔ f ⁻¹' s ∈ ae μ := by
simp only [mem_ae_iff, map_apply_of_aemeasurable hf hs.compl, preimage_compl]
theorem mem_ae_of_mem_ae_map {f : α → β} (hf : AEMeasurable f μ) {s : Set β}
(hs : s ∈ ae (μ.map f)) : f ⁻¹' s ∈ ae μ :=
(tendsto_ae_map hf).eventually hs
theorem ae_map_iff {f : α → β} (hf : AEMeasurable f μ) {p : β → Prop}
(hp : MeasurableSet { x | p x }) : (∀ᵐ y ∂μ.map f, p y) ↔ ∀ᵐ x ∂μ, p (f x) :=
mem_ae_map_iff hf hp
theorem ae_of_ae_map {f : α → β} (hf : AEMeasurable f μ) {p : β → Prop} (h : ∀ᵐ y ∂μ.map f, p y) :
∀ᵐ x ∂μ, p (f x) :=
mem_ae_of_mem_ae_map hf h
theorem ae_map_mem_range {m0 : MeasurableSpace α} (f : α → β) (hf : MeasurableSet (range f))
(μ : Measure α) : ∀ᵐ x ∂μ.map f, x ∈ range f := by
by_cases h : AEMeasurable f μ
· change range f ∈ ae (μ.map f)
rw [mem_ae_map_iff h hf]
filter_upwards using mem_range_self
· simp [map_of_not_aemeasurable h]
section Intervals
theorem biSup_measure_Iic [Preorder α] {s : Set α} (hsc : s.Countable)
(hst : ∀ x : α, ∃ y ∈ s, x ≤ y) (hdir : DirectedOn (· ≤ ·) s) :
⨆ x ∈ s, μ (Iic x) = μ univ := by
rw [← measure_biUnion_eq_iSup hsc]
· congr
simp only [← bex_def] at hst
exact iUnion₂_eq_univ_iff.2 hst
· exact directedOn_iff_directed.2 (hdir.directed_val.mono_comp _ fun x y => Iic_subset_Iic.2)
theorem tendsto_measure_Ico_atTop [SemilatticeSup α] [NoMaxOrder α]
[(atTop : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) :
Tendsto (fun x => μ (Ico a x)) atTop (𝓝 (μ (Ici a))) := by
haveI : Nonempty α := ⟨a⟩
have h_mono : Monotone fun x => μ (Ico a x) := fun i j hij => by simp only; gcongr
convert tendsto_atTop_iSup h_mono
obtain ⟨xs, hxs_mono, hxs_tendsto⟩ := exists_seq_monotone_tendsto_atTop_atTop α
have h_Ici : Ici a = ⋃ n, Ico a (xs n) := by
ext1 x
simp only [mem_Ici, mem_iUnion, mem_Ico, exists_and_left, iff_self_and]
intro
obtain ⟨y, hxy⟩ := NoMaxOrder.exists_gt x
obtain ⟨n, hn⟩ := tendsto_atTop_atTop.mp hxs_tendsto y
exact ⟨n, hxy.trans_le (hn n le_rfl)⟩
rw [h_Ici, measure_iUnion_eq_iSup, iSup_eq_iSup_subseq_of_monotone h_mono hxs_tendsto]
exact Monotone.directed_le fun i j hij => Ico_subset_Ico_right (hxs_mono hij)
theorem tendsto_measure_Ioc_atBot [SemilatticeInf α] [NoMinOrder α]
[(atBot : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) :
Tendsto (fun x => μ (Ioc x a)) atBot (𝓝 (μ (Iic a))) := by
haveI : Nonempty α := ⟨a⟩
have h_mono : Antitone fun x => μ (Ioc x a) := fun i j hij => by simp only; gcongr
convert tendsto_atBot_iSup h_mono
obtain ⟨xs, hxs_mono, hxs_tendsto⟩ := exists_seq_antitone_tendsto_atTop_atBot α
have h_Iic : Iic a = ⋃ n, Ioc (xs n) a := by
ext1 x
simp only [mem_Iic, mem_iUnion, mem_Ioc, exists_and_right, iff_and_self]
intro
obtain ⟨y, hxy⟩ := NoMinOrder.exists_lt x
obtain ⟨n, hn⟩ := tendsto_atTop_atBot.mp hxs_tendsto y
exact ⟨n, (hn n le_rfl).trans_lt hxy⟩
rw [h_Iic, measure_iUnion_eq_iSup, iSup_eq_iSup_subseq_of_antitone h_mono hxs_tendsto]
exact Monotone.directed_le fun i j hij => Ioc_subset_Ioc_left (hxs_mono hij)
theorem tendsto_measure_Iic_atTop [SemilatticeSup α] [(atTop : Filter α).IsCountablyGenerated]
(μ : Measure α) : Tendsto (fun x => μ (Iic x)) atTop (𝓝 (μ univ)) := by
cases isEmpty_or_nonempty α
· have h1 : ∀ x : α, Iic x = ∅ := fun x => Subsingleton.elim _ _
have h2 : (univ : Set α) = ∅ := Subsingleton.elim _ _
simp_rw [h1, h2]
exact tendsto_const_nhds
have h_mono : Monotone fun x => μ (Iic x) := fun i j hij => by simp only; gcongr
convert tendsto_atTop_iSup h_mono
obtain ⟨xs, hxs_mono, hxs_tendsto⟩ := exists_seq_monotone_tendsto_atTop_atTop α
have h_univ : (univ : Set α) = ⋃ n, Iic (xs n) := by
ext1 x
simp only [mem_univ, mem_iUnion, mem_Iic, true_iff_iff]
obtain ⟨n, hn⟩ := tendsto_atTop_atTop.mp hxs_tendsto x
exact ⟨n, hn n le_rfl⟩
rw [h_univ, measure_iUnion_eq_iSup, iSup_eq_iSup_subseq_of_monotone h_mono hxs_tendsto]
exact Monotone.directed_le fun i j hij => Iic_subset_Iic.mpr (hxs_mono hij)
theorem tendsto_measure_Ici_atBot [SemilatticeInf α] [h : (atBot : Filter α).IsCountablyGenerated]
(μ : Measure α) : Tendsto (fun x => μ (Ici x)) atBot (𝓝 (μ univ)) :=
@tendsto_measure_Iic_atTop αᵒᵈ _ _ h μ
variable [PartialOrder α] {a b : α}
theorem Iio_ae_eq_Iic' (ha : μ {a} = 0) : Iio a =ᵐ[μ] Iic a := by
rw [← Iic_diff_right, diff_ae_eq_self, measure_mono_null Set.inter_subset_right ha]
theorem Ioi_ae_eq_Ici' (ha : μ {a} = 0) : Ioi a =ᵐ[μ] Ici a :=
Iio_ae_eq_Iic' (α := αᵒᵈ) ha
theorem Ioo_ae_eq_Ioc' (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Ioc a b :=
(ae_eq_refl _).inter (Iio_ae_eq_Iic' hb)
theorem Ioc_ae_eq_Icc' (ha : μ {a} = 0) : Ioc a b =ᵐ[μ] Icc a b :=
(Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _)
theorem Ioo_ae_eq_Ico' (ha : μ {a} = 0) : Ioo a b =ᵐ[μ] Ico a b :=
(Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _)
theorem Ioo_ae_eq_Icc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Icc a b :=
(Ioi_ae_eq_Ici' ha).inter (Iio_ae_eq_Iic' hb)
theorem Ico_ae_eq_Icc' (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Icc a b :=
(ae_eq_refl _).inter (Iio_ae_eq_Iic' hb)
theorem Ico_ae_eq_Ioc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Ioc a b :=
(Ioo_ae_eq_Ico' ha).symm.trans (Ioo_ae_eq_Ioc' hb)
end Intervals
end
end MeasureTheory
namespace MeasurableEmbedding
open MeasureTheory Measure
variable {m0 : MeasurableSpace α} {m1 : MeasurableSpace β} {f : α → β} {μ ν : Measure α}
nonrec theorem map_apply (hf : MeasurableEmbedding f) (μ : Measure α) (s : Set β) :
μ.map f s = μ (f ⁻¹' s) := by
refine le_antisymm ?_ (le_map_apply hf.measurable.aemeasurable s)
set t := f '' toMeasurable μ (f ⁻¹' s) ∪ (range f)ᶜ
have htm : MeasurableSet t :=
(hf.measurableSet_image.2 <| measurableSet_toMeasurable _ _).union
hf.measurableSet_range.compl
have hst : s ⊆ t := by
rw [subset_union_compl_iff_inter_subset, ← image_preimage_eq_inter_range]
exact image_subset _ (subset_toMeasurable _ _)
have hft : f ⁻¹' t = toMeasurable μ (f ⁻¹' s) := by
rw [preimage_union, preimage_compl, preimage_range, compl_univ, union_empty,
hf.injective.preimage_image]
calc
μ.map f s ≤ μ.map f t := by gcongr
_ = μ (f ⁻¹' s) := by rw [map_apply hf.measurable htm, hft, measure_toMeasurable]
lemma comap_add (hf : MeasurableEmbedding f) (μ ν : Measure β) :
(μ + ν).comap f = μ.comap f + ν.comap f := by
ext s hs
simp only [← comapₗ_eq_comap _ hf.injective (fun _ ↦ hf.measurableSet_image.mpr) _ hs,
_root_.map_add, add_apply]
lemma absolutelyContinuous_map (hf : MeasurableEmbedding f) (hμν : μ ≪ ν) :
μ.map f ≪ ν.map f := by
intro t ht
rw [hf.map_apply] at ht ⊢
exact hμν ht
end MeasurableEmbedding
namespace MeasurableEquiv
/-! Interactions of measurable equivalences and measures -/
open Equiv MeasureTheory.Measure
variable [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α} {ν : Measure β}
/-- If we map a measure along a measurable equivalence, we can compute the measure on all sets
(not just the measurable ones). -/
protected theorem map_apply (f : α ≃ᵐ β) (s : Set β) : μ.map f s = μ (f ⁻¹' s) :=
f.measurableEmbedding.map_apply _ _
lemma comap_symm (e : α ≃ᵐ β) : μ.comap e.symm = μ.map e := by
ext s hs
rw [e.map_apply, Measure.comap_apply _ e.symm.injective _ _ hs, image_symm]
exact fun t ht ↦ e.symm.measurableSet_image.mpr ht
lemma map_symm (e : β ≃ᵐ α) : μ.map e.symm = μ.comap e := by
rw [← comap_symm, symm_symm]
@[simp]
theorem map_symm_map (e : α ≃ᵐ β) : (μ.map e).map e.symm = μ := by
simp [map_map e.symm.measurable e.measurable]
@[simp]
theorem map_map_symm (e : α ≃ᵐ β) : (ν.map e.symm).map e = ν := by
simp [map_map e.measurable e.symm.measurable]
theorem map_measurableEquiv_injective (e : α ≃ᵐ β) : Injective (Measure.map e) := by
intro μ₁ μ₂ hμ
apply_fun Measure.map e.symm at hμ
simpa [map_symm_map e] using hμ
theorem map_apply_eq_iff_map_symm_apply_eq (e : α ≃ᵐ β) : μ.map e = ν ↔ ν.map e.symm = μ := by
rw [← (map_measurableEquiv_injective e).eq_iff, map_map_symm, eq_comm]
theorem map_ae (f : α ≃ᵐ β) (μ : Measure α) : Filter.map f (ae μ) = ae (map f μ) := by
ext s
simp_rw [mem_map, mem_ae_iff, ← preimage_compl, f.map_apply]
theorem quasiMeasurePreserving_symm (μ : Measure α) (e : α ≃ᵐ β) :
QuasiMeasurePreserving e.symm (map e μ) μ :=
⟨e.symm.measurable, by rw [Measure.map_map, e.symm_comp_self, Measure.map_id] <;> measurability⟩
end MeasurableEquiv
namespace MeasureTheory
theorem OuterMeasure.toMeasure_zero [MeasurableSpace α] :
(0 : OuterMeasure α).toMeasure (le_top.trans OuterMeasure.zero_caratheodory.symm.le) = 0 := by
rw [← Measure.measure_univ_eq_zero, toMeasure_apply _ _ MeasurableSet.univ,
OuterMeasure.coe_zero, Pi.zero_apply]
end MeasureTheory
end
|
MeasureTheory\Measure\MeasureSpaceDef.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Induced
import Mathlib.MeasureTheory.OuterMeasure.AE
import Mathlib.Order.Filter.CountableInter
/-!
# Measure spaces
This file defines measure spaces, the almost-everywhere filter and ae_measurable functions.
See `MeasureTheory.MeasureSpace` for their properties and for extended documentation.
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the sum of the measures of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, an outer measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
## Implementation notes
Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
See the documentation of `MeasureTheory.MeasureSpace` for ways to construct measures and proving
that two measure are equal.
A `MeasureSpace` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
This file does not import `MeasureTheory.MeasurableSpace.Basic`, but only `MeasurableSpace.Defs`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space
-/
noncomputable section
open Set Function MeasurableSpace Topology Filter ENNReal NNReal
open Filter hiding map
variable {α β γ δ : Type*} {ι : Sort*}
namespace MeasureTheory
/-- A measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure. -/
structure Measure (α : Type*) [MeasurableSpace α] extends OuterMeasure α where
m_iUnion ⦃f : ℕ → Set α⦄ : (∀ i, MeasurableSet (f i)) → Pairwise (Disjoint on f) →
toOuterMeasure (⋃ i, f i) = ∑' i, toOuterMeasure (f i)
trim_le : toOuterMeasure.trim ≤ toOuterMeasure
/-- Notation for `Measure` with respect to a non-standard σ-algebra in the domain. -/
scoped notation "Measure[" mα "]" α:arg => @Measure α mα
theorem Measure.toOuterMeasure_injective [MeasurableSpace α] :
Injective (toOuterMeasure : Measure α → OuterMeasure α)
| ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl
instance Measure.instFunLike [MeasurableSpace α] : FunLike (Measure α) (Set α) ℝ≥0∞ where
coe μ := μ.toOuterMeasure
coe_injective' | ⟨_, _, _⟩, ⟨_, _, _⟩, h => toOuterMeasure_injective <| DFunLike.coe_injective h
set_option linter.deprecated false in -- Not immediately obvious how to use `measure_empty` here.
instance Measure.instOuterMeasureClass [MeasurableSpace α] : OuterMeasureClass (Measure α) α where
measure_empty m := m.empty'
measure_iUnion_nat_le m := m.iUnion_nat
measure_mono m := m.mono
section
variable [MeasurableSpace α] {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α}
namespace Measure
theorem trimmed (μ : Measure α) : μ.toOuterMeasure.trim = μ.toOuterMeasure :=
le_antisymm μ.trim_le μ.1.le_trim
/-! ### General facts about measures -/
/-- Obtain a measure by giving a countably additive function that sends `∅` to `0`. -/
def ofMeasurable (m : ∀ s : Set α, MeasurableSet s → ℝ≥0∞) (m0 : m ∅ MeasurableSet.empty = 0)
(mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ i, MeasurableSet (f i)),
Pairwise (Disjoint on f) → m (⋃ i, f i) (MeasurableSet.iUnion h) = ∑' i, m (f i) (h i)) :
Measure α :=
{ toOuterMeasure := inducedOuterMeasure m _ m0
m_iUnion := fun f hf hd =>
show inducedOuterMeasure m _ m0 (iUnion f) = ∑' i, inducedOuterMeasure m _ m0 (f i) by
rw [inducedOuterMeasure_eq m0 mU, mU hf hd]
congr; funext n; rw [inducedOuterMeasure_eq m0 mU]
trim_le := le_inducedOuterMeasure.2 fun s hs ↦ by
rw [OuterMeasure.trim_eq _ hs, inducedOuterMeasure_eq m0 mU hs] }
theorem ofMeasurable_apply {m : ∀ s : Set α, MeasurableSet s → ℝ≥0∞}
{m0 : m ∅ MeasurableSet.empty = 0}
{mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ i, MeasurableSet (f i)),
Pairwise (Disjoint on f) → m (⋃ i, f i) (MeasurableSet.iUnion h) = ∑' i, m (f i) (h i)}
(s : Set α) (hs : MeasurableSet s) : ofMeasurable m m0 mU s = m s hs :=
inducedOuterMeasure_eq m0 mU hs
@[ext]
theorem ext (h : ∀ s, MeasurableSet s → μ₁ s = μ₂ s) : μ₁ = μ₂ :=
toOuterMeasure_injective <| by
rw [← trimmed, OuterMeasure.trim_congr (h _), trimmed]
theorem ext_iff' : μ₁ = μ₂ ↔ ∀ s, μ₁ s = μ₂ s :=
⟨by rintro rfl s; rfl, fun h ↦ Measure.ext (fun s _ ↦ h s)⟩
theorem outerMeasure_le_iff {m : OuterMeasure α} : m ≤ μ.1 ↔ ∀ s, MeasurableSet s → m s ≤ μ s := by
simpa only [μ.trimmed] using OuterMeasure.le_trim_iff (m₂ := μ.1)
end Measure
@[simp] theorem Measure.coe_toOuterMeasure (μ : Measure α) : ⇑μ.toOuterMeasure = μ := rfl
theorem Measure.toOuterMeasure_apply (μ : Measure α) (s : Set α) :
μ.toOuterMeasure s = μ s :=
rfl
theorem measure_eq_trim (s : Set α) : μ s = μ.toOuterMeasure.trim s := by
rw [μ.trimmed, μ.coe_toOuterMeasure]
theorem measure_eq_iInf (s : Set α) : μ s = ⨅ (t) (_ : s ⊆ t) (_ : MeasurableSet t), μ t := by
rw [measure_eq_trim, OuterMeasure.trim_eq_iInf, μ.coe_toOuterMeasure]
/-- A variant of `measure_eq_iInf` which has a single `iInf`. This is useful when applying a
lemma next that only works for non-empty infima, in which case you can use
`nonempty_measurable_superset`. -/
theorem measure_eq_iInf' (μ : Measure α) (s : Set α) :
μ s = ⨅ t : { t // s ⊆ t ∧ MeasurableSet t }, μ t := by
simp_rw [iInf_subtype, iInf_and, ← measure_eq_iInf]
theorem measure_eq_inducedOuterMeasure :
μ s = inducedOuterMeasure (fun s _ => μ s) MeasurableSet.empty μ.empty s :=
measure_eq_trim _
theorem toOuterMeasure_eq_inducedOuterMeasure :
μ.toOuterMeasure = inducedOuterMeasure (fun s _ => μ s) MeasurableSet.empty μ.empty :=
μ.trimmed.symm
theorem measure_eq_extend (hs : MeasurableSet s) :
μ s = extend (fun t (_ht : MeasurableSet t) => μ t) s := by
rw [extend_eq]
exact hs
theorem nonempty_of_measure_ne_zero (h : μ s ≠ 0) : s.Nonempty :=
nonempty_iff_ne_empty.2 fun h' => h <| h'.symm ▸ measure_empty
theorem measure_mono_top (h : s₁ ⊆ s₂) (h₁ : μ s₁ = ∞) : μ s₂ = ∞ :=
top_unique <| h₁ ▸ measure_mono h
@[simp, mono]
theorem measure_le_measure_union_left : μ s ≤ μ (s ∪ t) := μ.mono subset_union_left
@[simp, mono]
theorem measure_le_measure_union_right : μ t ≤ μ (s ∪ t) := μ.mono subset_union_right
/-- For every set there exists a measurable superset of the same measure. -/
theorem exists_measurable_superset (μ : Measure α) (s : Set α) :
∃ t, s ⊆ t ∧ MeasurableSet t ∧ μ t = μ s := by
simpa only [← measure_eq_trim] using μ.toOuterMeasure.exists_measurable_superset_eq_trim s
/-- For every set `s` and a countable collection of measures `μ i` there exists a measurable
superset `t ⊇ s` such that each measure `μ i` takes the same value on `s` and `t`. -/
theorem exists_measurable_superset_forall_eq [Countable ι] (μ : ι → Measure α) (s : Set α) :
∃ t, s ⊆ t ∧ MeasurableSet t ∧ ∀ i, μ i t = μ i s := by
simpa only [← measure_eq_trim] using
OuterMeasure.exists_measurable_superset_forall_eq_trim (fun i => (μ i).toOuterMeasure) s
theorem exists_measurable_superset₂ (μ ν : Measure α) (s : Set α) :
∃ t, s ⊆ t ∧ MeasurableSet t ∧ μ t = μ s ∧ ν t = ν s := by
simpa only [Bool.forall_bool.trans and_comm] using
exists_measurable_superset_forall_eq (fun b => cond b μ ν) s
theorem exists_measurable_superset_of_null (h : μ s = 0) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ μ t = 0 :=
h ▸ exists_measurable_superset μ s
theorem exists_measurable_superset_iff_measure_eq_zero :
(∃ t, s ⊆ t ∧ MeasurableSet t ∧ μ t = 0) ↔ μ s = 0 :=
⟨fun ⟨_t, hst, _, ht⟩ => measure_mono_null hst ht, exists_measurable_superset_of_null⟩
theorem measure_biUnion_lt_top {s : Set β} {f : β → Set α} (hs : s.Finite)
(hfin : ∀ i ∈ s, μ (f i) ≠ ∞) : μ (⋃ i ∈ s, f i) < ∞ := by
convert (measure_biUnion_finset_le (μ := μ) hs.toFinset f).trans_lt _ using 3
· ext
rw [Finite.mem_toFinset]
· apply ENNReal.sum_lt_top; simpa only [Finite.mem_toFinset]
@[deprecated measure_iUnion_null_iff (since := "2024-01-14")]
theorem measure_iUnion_null_iff' {ι : Prop} {s : ι → Set α} : μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 :=
measure_iUnion_null_iff
theorem measure_union_lt_top (hs : μ s < ∞) (ht : μ t < ∞) : μ (s ∪ t) < ∞ :=
(measure_union_le s t).trans_lt (ENNReal.add_lt_top.mpr ⟨hs, ht⟩)
@[simp]
theorem measure_union_lt_top_iff : μ (s ∪ t) < ∞ ↔ μ s < ∞ ∧ μ t < ∞ := by
refine ⟨fun h => ⟨?_, ?_⟩, fun h => measure_union_lt_top h.1 h.2⟩
· exact (measure_mono Set.subset_union_left).trans_lt h
· exact (measure_mono Set.subset_union_right).trans_lt h
theorem measure_union_ne_top (hs : μ s ≠ ∞) (ht : μ t ≠ ∞) : μ (s ∪ t) ≠ ∞ :=
(measure_union_lt_top hs.lt_top ht.lt_top).ne
open scoped symmDiff in
theorem measure_symmDiff_ne_top (hs : μ s ≠ ∞) (ht : μ t ≠ ∞) : μ (s ∆ t) ≠ ∞ :=
ne_top_of_le_ne_top (measure_union_ne_top hs ht) <| measure_mono symmDiff_subset_union
@[simp]
theorem measure_union_eq_top_iff : μ (s ∪ t) = ∞ ↔ μ s = ∞ ∨ μ t = ∞ :=
not_iff_not.1 <| by simp only [← lt_top_iff_ne_top, ← Ne.eq_def, not_or, measure_union_lt_top_iff]
theorem exists_measure_pos_of_not_measure_iUnion_null [Countable ι] {s : ι → Set α}
(hs : μ (⋃ n, s n) ≠ 0) : ∃ n, 0 < μ (s n) := by
contrapose! hs
exact measure_iUnion_null fun n => nonpos_iff_eq_zero.1 (hs n)
theorem measure_lt_top_of_subset (hst : t ⊆ s) (hs : μ s ≠ ∞) : μ t < ∞ :=
lt_of_le_of_lt (μ.mono hst) hs.lt_top
theorem measure_inter_lt_top_of_left_ne_top (hs_finite : μ s ≠ ∞) : μ (s ∩ t) < ∞ :=
measure_lt_top_of_subset inter_subset_left hs_finite
theorem measure_inter_lt_top_of_right_ne_top (ht_finite : μ t ≠ ∞) : μ (s ∩ t) < ∞ :=
measure_lt_top_of_subset inter_subset_right ht_finite
theorem measure_inter_null_of_null_right (S : Set α) {T : Set α} (h : μ T = 0) : μ (S ∩ T) = 0 :=
measure_mono_null inter_subset_right h
theorem measure_inter_null_of_null_left {S : Set α} (T : Set α) (h : μ S = 0) : μ (S ∩ T) = 0 :=
measure_mono_null inter_subset_left h
/-! ### The almost everywhere filter -/
section ae
/-- Given a predicate on `β` and `Set α` where both `α` and `β` are measurable spaces, if the
predicate holds for almost every `x : β` and
- `∅ : Set α`
- a family of sets generating the σ-algebra of `α`
Moreover, if for almost every `x : β`, the predicate is closed under complements and countable
disjoint unions, then the predicate holds for almost every `x : β` and all measurable sets of `α`.
This is an AE version of `MeasurableSpace.induction_on_inter` where the condition is dependent
on a measurable space `β`. -/
theorem _root_.MeasurableSpace.ae_induction_on_inter {β} [MeasurableSpace β] {μ : Measure β}
{C : β → Set α → Prop} {s : Set (Set α)} [m : MeasurableSpace α]
(h_eq : m = MeasurableSpace.generateFrom s)
(h_inter : IsPiSystem s) (h_empty : ∀ᵐ x ∂μ, C x ∅) (h_basic : ∀ᵐ x ∂μ, ∀ t ∈ s, C x t)
(h_compl : ∀ᵐ x ∂μ, ∀ t, MeasurableSet t → C x t → C x tᶜ)
(h_union : ∀ᵐ x ∂μ, ∀ f : ℕ → Set α,
Pairwise (Disjoint on f) → (∀ i, MeasurableSet (f i)) → (∀ i, C x (f i)) → C x (⋃ i, f i)) :
∀ᵐ x ∂μ, ∀ ⦃t⦄, MeasurableSet t → C x t := by
filter_upwards [h_empty, h_basic, h_compl, h_union] with x hx_empty hx_basic hx_compl hx_union
using MeasurableSpace.induction_on_inter h_eq h_inter hx_empty hx_basic hx_compl hx_union
end ae
open Classical in
/-- A measurable set `t ⊇ s` such that `μ t = μ s`. It even satisfies `μ (t ∩ u) = μ (s ∩ u)` for
any measurable set `u` if `μ s ≠ ∞`, see `measure_toMeasurable_inter`.
(This property holds without the assumption `μ s ≠ ∞` when the space is s-finite -- for example
σ-finite), see `measure_toMeasurable_inter_of_sFinite`).
If `s` is a null measurable set, then
we also have `t =ᵐ[μ] s`, see `NullMeasurableSet.toMeasurable_ae_eq`.
This notion is sometimes called a "measurable hull" in the literature. -/
irreducible_def toMeasurable (μ : Measure α) (s : Set α) : Set α :=
if h : ∃ t, t ⊇ s ∧ MeasurableSet t ∧ t =ᵐ[μ] s then h.choose else
if h' : ∃ t, t ⊇ s ∧ MeasurableSet t ∧
∀ u, MeasurableSet u → μ (t ∩ u) = μ (s ∩ u) then h'.choose
else (exists_measurable_superset μ s).choose
theorem subset_toMeasurable (μ : Measure α) (s : Set α) : s ⊆ toMeasurable μ s := by
rw [toMeasurable_def]; split_ifs with hs h's
exacts [hs.choose_spec.1, h's.choose_spec.1, (exists_measurable_superset μ s).choose_spec.1]
theorem ae_le_toMeasurable : s ≤ᵐ[μ] toMeasurable μ s :=
HasSubset.Subset.eventuallyLE (subset_toMeasurable _ _)
--(subset_toMeasurable _ _).EventuallyLE
@[simp]
theorem measurableSet_toMeasurable (μ : Measure α) (s : Set α) :
MeasurableSet (toMeasurable μ s) := by
rw [toMeasurable_def]; split_ifs with hs h's
exacts [hs.choose_spec.2.1, h's.choose_spec.2.1,
(exists_measurable_superset μ s).choose_spec.2.1]
@[simp]
theorem measure_toMeasurable (s : Set α) : μ (toMeasurable μ s) = μ s := by
rw [toMeasurable_def]; split_ifs with hs h's
· exact measure_congr hs.choose_spec.2.2
· simpa only [inter_univ] using h's.choose_spec.2.2 univ MeasurableSet.univ
· exact (exists_measurable_superset μ s).choose_spec.2.2
/-- A measure space is a measurable space equipped with a
measure, referred to as `volume`. -/
class MeasureSpace (α : Type*) extends MeasurableSpace α where
volume : Measure α
export MeasureSpace (volume)
/-- `volume` is the canonical measure on `α`. -/
add_decl_doc volume
section MeasureSpace
/-- `∀ᵐ a, p a` means that `p a` for a.e. `a`, i.e. `p` holds true away from a null set.
This is notation for `Filter.Eventually P (MeasureTheory.ae MeasureSpace.volume)`. -/
notation3 "∀ᵐ "(...)", "r:(scoped P =>
Filter.Eventually P <| MeasureTheory.ae MeasureTheory.MeasureSpace.volume) => r
/-- `∃ᵐ a, p a` means that `p` holds frequently, i.e. on a set of positive measure,
w.r.t. the volume measure.
This is notation for `Filter.Frequently P (MeasureTheory.ae MeasureSpace.volume)`. -/
notation3 "∃ᵐ "(...)", "r:(scoped P =>
Filter.Frequently P <| MeasureTheory.ae MeasureTheory.MeasureSpace.volume) => r
/-- The tactic `exact volume`, to be used in optional (`autoParam`) arguments. -/
macro "volume_tac" : tactic =>
`(tactic| (first | exact MeasureTheory.MeasureSpace.volume))
end MeasureSpace
end
end MeasureTheory
section
open MeasureTheory
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. We define this property, called `AEMeasurable f μ`. It's properties are discussed in
`MeasureTheory.MeasureSpace`.
-/
variable {m : MeasurableSpace α} [MeasurableSpace β] {f g : α → β} {μ ν : Measure α}
/-- A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. -/
@[fun_prop]
def AEMeasurable {_m : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop :=
∃ g : α → β, Measurable g ∧ f =ᵐ[μ] g
@[fun_prop, aesop unsafe 30% apply (rule_sets := [Measurable])]
theorem Measurable.aemeasurable (h : Measurable f) : AEMeasurable f μ :=
⟨f, h, ae_eq_refl f⟩
namespace AEMeasurable
/-- Given an almost everywhere measurable function `f`, associate to it a measurable function
that coincides with it almost everywhere. `f` is explicit in the definition to make sure that
it shows in pretty-printing. -/
def mk (f : α → β) (h : AEMeasurable f μ) : α → β :=
Classical.choose h
@[measurability]
theorem measurable_mk (h : AEMeasurable f μ) : Measurable (h.mk f) :=
(Classical.choose_spec h).1
theorem ae_eq_mk (h : AEMeasurable f μ) : f =ᵐ[μ] h.mk f :=
(Classical.choose_spec h).2
theorem congr (hf : AEMeasurable f μ) (h : f =ᵐ[μ] g) : AEMeasurable g μ :=
⟨hf.mk f, hf.measurable_mk, h.symm.trans hf.ae_eq_mk⟩
end AEMeasurable
theorem aemeasurable_congr (h : f =ᵐ[μ] g) : AEMeasurable f μ ↔ AEMeasurable g μ :=
⟨fun hf => AEMeasurable.congr hf h, fun hg => AEMeasurable.congr hg h.symm⟩
@[simp, fun_prop, measurability]
theorem aemeasurable_const {b : β} : AEMeasurable (fun _a : α => b) μ :=
measurable_const.aemeasurable
@[measurability]
theorem aemeasurable_id : AEMeasurable id μ :=
measurable_id.aemeasurable
@[measurability]
theorem aemeasurable_id' : AEMeasurable (fun x => x) μ :=
measurable_id.aemeasurable
theorem Measurable.comp_aemeasurable [MeasurableSpace δ] {f : α → δ} {g : δ → β} (hg : Measurable g)
(hf : AEMeasurable f μ) : AEMeasurable (g ∘ f) μ :=
⟨g ∘ hf.mk f, hg.comp hf.measurable_mk, EventuallyEq.fun_comp hf.ae_eq_mk _⟩
@[fun_prop, measurability]
theorem Measurable.comp_aemeasurable' [MeasurableSpace δ] {f : α → δ} {g : δ → β}
(hg : Measurable g) (hf : AEMeasurable f μ) : AEMeasurable (fun x ↦ g (f x)) μ :=
Measurable.comp_aemeasurable hg hf
end
|
MeasureTheory\Measure\MutuallySingular.lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.Restrict
/-! # Mutually singular measures
Two measures `μ`, `ν` are said to be mutually singular (`MeasureTheory.Measure.MutuallySingular`,
localized notation `μ ⟂ₘ ν`) if there exists a measurable set `s` such that `μ s = 0` and
`ν sᶜ = 0`. The measurability of `s` is an unnecessary assumption (see
`MeasureTheory.Measure.MutuallySingular.mk`) but we keep it because this way `rcases (h : μ ⟂ₘ ν)`
gives us a measurable set and usually it is easy to prove measurability.
In this file we define the predicate `MeasureTheory.Measure.MutuallySingular` and prove basic
facts about it.
## Tags
measure, mutually singular
-/
open Set
open MeasureTheory NNReal ENNReal
namespace MeasureTheory
namespace Measure
variable {α : Type*} {m0 : MeasurableSpace α} {μ μ₁ μ₂ ν ν₁ ν₂ : Measure α}
/-- Two measures `μ`, `ν` are said to be mutually singular if there exists a measurable set `s`
such that `μ s = 0` and `ν sᶜ = 0`. -/
def MutuallySingular {_ : MeasurableSpace α} (μ ν : Measure α) : Prop :=
∃ s : Set α, MeasurableSet s ∧ μ s = 0 ∧ ν sᶜ = 0
@[inherit_doc MeasureTheory.Measure.MutuallySingular]
scoped[MeasureTheory] infixl:60 " ⟂ₘ " => MeasureTheory.Measure.MutuallySingular
namespace MutuallySingular
theorem mk {s t : Set α} (hs : μ s = 0) (ht : ν t = 0) (hst : univ ⊆ s ∪ t) :
MutuallySingular μ ν := by
use toMeasurable μ s, measurableSet_toMeasurable _ _, (measure_toMeasurable _).trans hs
refine measure_mono_null (fun x hx => (hst trivial).resolve_left fun hxs => hx ?_) ht
exact subset_toMeasurable _ _ hxs
/-- A set such that `μ h.nullSet = 0` and `ν h.nullSetᶜ = 0`. -/
def nullSet (h : μ ⟂ₘ ν) : Set α := h.choose
lemma measurableSet_nullSet (h : μ ⟂ₘ ν) : MeasurableSet h.nullSet := h.choose_spec.1
@[simp]
lemma measure_nullSet (h : μ ⟂ₘ ν) : μ h.nullSet = 0 := h.choose_spec.2.1
@[simp]
lemma measure_compl_nullSet (h : μ ⟂ₘ ν) : ν h.nullSetᶜ = 0 := h.choose_spec.2.2
-- TODO: this is proved by simp, but is not simplified in other contexts without the @[simp]
-- attribute. Also, the linter does not complain about that attribute.
@[simp]
lemma restrict_nullSet (h : μ ⟂ₘ ν) : μ.restrict h.nullSet = 0 := by simp
-- TODO: this is proved by simp, but is not simplified in other contexts without the @[simp]
-- attribute. Also, the linter does not complain about that attribute.
@[simp]
lemma restrict_compl_nullSet (h : μ ⟂ₘ ν) : ν.restrict h.nullSetᶜ = 0 := by simp
@[simp]
theorem zero_right : μ ⟂ₘ 0 :=
⟨∅, MeasurableSet.empty, measure_empty, rfl⟩
@[symm]
theorem symm (h : ν ⟂ₘ μ) : μ ⟂ₘ ν :=
let ⟨i, hi, his, hit⟩ := h
⟨iᶜ, hi.compl, hit, (compl_compl i).symm ▸ his⟩
theorem comm : μ ⟂ₘ ν ↔ ν ⟂ₘ μ :=
⟨fun h => h.symm, fun h => h.symm⟩
@[simp]
theorem zero_left : 0 ⟂ₘ μ :=
zero_right.symm
theorem mono_ac (h : μ₁ ⟂ₘ ν₁) (hμ : μ₂ ≪ μ₁) (hν : ν₂ ≪ ν₁) : μ₂ ⟂ₘ ν₂ :=
let ⟨s, hs, h₁, h₂⟩ := h
⟨s, hs, hμ h₁, hν h₂⟩
theorem mono (h : μ₁ ⟂ₘ ν₁) (hμ : μ₂ ≤ μ₁) (hν : ν₂ ≤ ν₁) : μ₂ ⟂ₘ ν₂ :=
h.mono_ac hμ.absolutelyContinuous hν.absolutelyContinuous
@[simp]
lemma self_iff (μ : Measure α) : μ ⟂ₘ μ ↔ μ = 0 := by
refine ⟨?_, fun h ↦ by (rw [h]; exact zero_left)⟩
rintro ⟨s, hs, hμs, hμs_compl⟩
suffices μ Set.univ = 0 by rwa [measure_univ_eq_zero] at this
rw [← Set.union_compl_self s, measure_union disjoint_compl_right hs.compl, hμs, hμs_compl,
add_zero]
@[simp]
theorem sum_left {ι : Type*} [Countable ι] {μ : ι → Measure α} : sum μ ⟂ₘ ν ↔ ∀ i, μ i ⟂ₘ ν := by
refine ⟨fun h i => h.mono (le_sum _ _) le_rfl, fun H => ?_⟩
choose s hsm hsμ hsν using H
refine ⟨⋂ i, s i, MeasurableSet.iInter hsm, ?_, ?_⟩
· rw [sum_apply _ (MeasurableSet.iInter hsm), ENNReal.tsum_eq_zero]
exact fun i => measure_mono_null (iInter_subset _ _) (hsμ i)
· rwa [compl_iInter, measure_iUnion_null_iff]
@[simp]
theorem sum_right {ι : Type*} [Countable ι] {ν : ι → Measure α} : μ ⟂ₘ sum ν ↔ ∀ i, μ ⟂ₘ ν i :=
comm.trans <| sum_left.trans <| forall_congr' fun _ => comm
@[simp]
theorem add_left_iff : μ₁ + μ₂ ⟂ₘ ν ↔ μ₁ ⟂ₘ ν ∧ μ₂ ⟂ₘ ν := by
rw [← sum_cond, sum_left, Bool.forall_bool, cond, cond, and_comm]
@[simp]
theorem add_right_iff : μ ⟂ₘ ν₁ + ν₂ ↔ μ ⟂ₘ ν₁ ∧ μ ⟂ₘ ν₂ :=
comm.trans <| add_left_iff.trans <| and_congr comm comm
theorem add_left (h₁ : ν₁ ⟂ₘ μ) (h₂ : ν₂ ⟂ₘ μ) : ν₁ + ν₂ ⟂ₘ μ :=
add_left_iff.2 ⟨h₁, h₂⟩
theorem add_right (h₁ : μ ⟂ₘ ν₁) (h₂ : μ ⟂ₘ ν₂) : μ ⟂ₘ ν₁ + ν₂ :=
add_right_iff.2 ⟨h₁, h₂⟩
theorem smul (r : ℝ≥0∞) (h : ν ⟂ₘ μ) : r • ν ⟂ₘ μ :=
h.mono_ac (AbsolutelyContinuous.rfl.smul r) AbsolutelyContinuous.rfl
theorem smul_nnreal (r : ℝ≥0) (h : ν ⟂ₘ μ) : r • ν ⟂ₘ μ :=
h.smul r
lemma restrict (h : μ ⟂ₘ ν) (s : Set α) : μ.restrict s ⟂ₘ ν := by
refine ⟨h.nullSet, h.measurableSet_nullSet, ?_, h.measure_compl_nullSet⟩
rw [Measure.restrict_apply h.measurableSet_nullSet]
exact measure_mono_null Set.inter_subset_left h.measure_nullSet
end MutuallySingular
lemma eq_zero_of_absolutelyContinuous_of_mutuallySingular {μ ν : Measure α}
(h_ac : μ ≪ ν) (h_ms : μ ⟂ₘ ν) :
μ = 0 := by
rw [← Measure.MutuallySingular.self_iff]
exact h_ms.mono_ac Measure.AbsolutelyContinuous.rfl h_ac
lemma _root_.MeasurableEmbedding.mutuallySingular_map {β : Type*} {_ : MeasurableSpace β}
{f : α → β} (hf : MeasurableEmbedding f) (hμν : μ ⟂ₘ ν) :
μ.map f ⟂ₘ ν.map f := by
refine ⟨f '' hμν.nullSet, hf.measurableSet_image' hμν.measurableSet_nullSet, ?_, ?_⟩
· rw [hf.map_apply, hf.injective.preimage_image, hμν.measure_nullSet]
· rw [hf.map_apply, Set.preimage_compl, hf.injective.preimage_image, hμν.measure_compl_nullSet]
end Measure
end MeasureTheory
|
MeasureTheory\Measure\NullMeasurable.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.AEDisjoint
import Mathlib.MeasureTheory.Constructions.EventuallyMeasurable
/-!
# Null measurable sets and complete measures
## Main definitions
### Null measurable sets and functions
A set `s : Set α` is called *null measurable* (`MeasureTheory.NullMeasurableSet`) if it satisfies
any of the following equivalent conditions:
* there exists a measurable set `t` such that `s =ᵐ[μ] t` (this is used as a definition);
* `MeasureTheory.toMeasurable μ s =ᵐ[μ] s`;
* there exists a measurable subset `t ⊆ s` such that `t =ᵐ[μ] s` (in this case the latter equality
means that `μ (s \ t) = 0`);
* `s` can be represented as a union of a measurable set and a set of measure zero;
* `s` can be represented as a difference of a measurable set and a set of measure zero.
Null measurable sets form a σ-algebra that is registered as a `MeasurableSpace` instance on
`MeasureTheory.NullMeasurableSpace α μ`. We also say that `f : α → β` is
`MeasureTheory.NullMeasurable` if the preimage of a measurable set is a null measurable set.
In other words, `f : α → β` is null measurable if it is measurable as a function
`MeasureTheory.NullMeasurableSpace α μ → β`.
### Complete measures
We say that a measure `μ` is complete w.r.t. the `MeasurableSpace α` σ-algebra (or the σ-algebra is
complete w.r.t measure `μ`) if every set of measure zero is measurable. In this case all null
measurable sets and functions are measurable.
For each measure `μ`, we define `MeasureTheory.Measure.completion μ` to be the same measure
interpreted as a measure on `MeasureTheory.NullMeasurableSpace α μ` and prove that this is a
complete measure.
## Implementation notes
We define `MeasureTheory.NullMeasurableSet` as `@MeasurableSet (NullMeasurableSpace α μ) _` so
that theorems about `MeasurableSet`s like `MeasurableSet.union` can be applied to
`NullMeasurableSet`s. However, these lemmas output terms of the same form
`@MeasurableSet (NullMeasurableSpace α μ) _ _`. While this is definitionally equal to the
expected output `NullMeasurableSet s μ`, it looks different and may be misleading. So we copy all
standard lemmas about measurable sets to the `MeasureTheory.NullMeasurableSet` namespace and fix
the output type.
## Tags
measurable, measure, null measurable, completion
-/
open Filter Set Encodable
variable {ι α β γ : Type*}
namespace MeasureTheory
/-- A type tag for `α` with `MeasurableSet` given by `NullMeasurableSet`. -/
@[nolint unusedArguments]
def NullMeasurableSpace (α : Type*) [MeasurableSpace α]
(_μ : Measure α := by volume_tac) : Type _ :=
α
section
variable {m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α}
instance NullMeasurableSpace.instInhabited [h : Inhabited α] :
Inhabited (NullMeasurableSpace α μ) :=
h
instance NullMeasurableSpace.instSubsingleton [h : Subsingleton α] :
Subsingleton (NullMeasurableSpace α μ) :=
h
instance NullMeasurableSpace.instMeasurableSpace : MeasurableSpace (NullMeasurableSpace α μ) :=
@EventuallyMeasurableSpace α inferInstance (ae μ) _
/-- A set is called `NullMeasurableSet` if it can be approximated by a measurable set up to
a set of null measure. -/
def NullMeasurableSet [MeasurableSpace α] (s : Set α)
(μ : Measure α := by volume_tac) : Prop :=
@MeasurableSet (NullMeasurableSpace α μ) _ s
@[simp]
theorem _root_.MeasurableSet.nullMeasurableSet (h : MeasurableSet s) : NullMeasurableSet s μ :=
h.eventuallyMeasurableSet
-- @[simp] -- Porting note (#10618): simp can prove this
theorem nullMeasurableSet_empty : NullMeasurableSet ∅ μ :=
MeasurableSet.empty
-- @[simp] -- Porting note (#10618): simp can prove this
theorem nullMeasurableSet_univ : NullMeasurableSet univ μ :=
MeasurableSet.univ
namespace NullMeasurableSet
theorem of_null (h : μ s = 0) : NullMeasurableSet s μ :=
⟨∅, MeasurableSet.empty, ae_eq_empty.2 h⟩
theorem compl (h : NullMeasurableSet s μ) : NullMeasurableSet sᶜ μ :=
MeasurableSet.compl h
theorem of_compl (h : NullMeasurableSet sᶜ μ) : NullMeasurableSet s μ :=
MeasurableSet.of_compl h
@[simp]
theorem compl_iff : NullMeasurableSet sᶜ μ ↔ NullMeasurableSet s μ :=
MeasurableSet.compl_iff
@[nontriviality]
theorem of_subsingleton [Subsingleton α] : NullMeasurableSet s μ :=
Subsingleton.measurableSet
protected theorem congr (hs : NullMeasurableSet s μ) (h : s =ᵐ[μ] t) : NullMeasurableSet t μ :=
EventuallyMeasurableSet.congr hs h.symm
protected theorem iUnion {ι : Sort*} [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) : NullMeasurableSet (⋃ i, s i) μ :=
MeasurableSet.iUnion h
protected theorem biUnion {f : ι → Set α} {s : Set ι} (hs : s.Countable)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋃ b ∈ s, f b) μ :=
MeasurableSet.biUnion hs h
protected theorem sUnion {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, NullMeasurableSet t μ) :
NullMeasurableSet (⋃₀ s) μ := by
rw [sUnion_eq_biUnion]
exact MeasurableSet.biUnion hs h
protected theorem iInter {ι : Sort*} [Countable ι] {f : ι → Set α}
(h : ∀ i, NullMeasurableSet (f i) μ) : NullMeasurableSet (⋂ i, f i) μ :=
MeasurableSet.iInter h
protected theorem biInter {f : β → Set α} {s : Set β} (hs : s.Countable)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋂ b ∈ s, f b) μ :=
MeasurableSet.biInter hs h
protected theorem sInter {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, NullMeasurableSet t μ) :
NullMeasurableSet (⋂₀ s) μ :=
MeasurableSet.sInter hs h
@[simp]
protected theorem union (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
NullMeasurableSet (s ∪ t) μ :=
MeasurableSet.union hs ht
protected theorem union_null (hs : NullMeasurableSet s μ) (ht : μ t = 0) :
NullMeasurableSet (s ∪ t) μ :=
hs.union (of_null ht)
@[simp]
protected theorem inter (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
NullMeasurableSet (s ∩ t) μ :=
MeasurableSet.inter hs ht
@[simp]
protected theorem diff (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
NullMeasurableSet (s \ t) μ :=
MeasurableSet.diff hs ht
@[simp]
protected theorem disjointed {f : ℕ → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (n) :
NullMeasurableSet (disjointed f n) μ :=
MeasurableSet.disjointed h n
-- @[simp] -- Porting note (#10618): simp can prove thisrove this
protected theorem const (p : Prop) : NullMeasurableSet { _a : α | p } μ :=
MeasurableSet.const p
instance instMeasurableSingletonClass [MeasurableSingletonClass α] :
MeasurableSingletonClass (NullMeasurableSpace α μ) :=
EventuallyMeasurableSpace.measurableSingleton (m := m0)
protected theorem insert [MeasurableSingletonClass (NullMeasurableSpace α μ)]
(hs : NullMeasurableSet s μ) (a : α) : NullMeasurableSet (insert a s) μ :=
MeasurableSet.insert hs a
theorem exists_measurable_superset_ae_eq (h : NullMeasurableSet s μ) :
∃ t ⊇ s, MeasurableSet t ∧ t =ᵐ[μ] s := by
rcases h with ⟨t, htm, hst⟩
refine ⟨t ∪ toMeasurable μ (s \ t), ?_, htm.union (measurableSet_toMeasurable _ _), ?_⟩
· exact diff_subset_iff.1 (subset_toMeasurable _ _)
· have : toMeasurable μ (s \ t) =ᵐ[μ] (∅ : Set α) := by simp [ae_le_set.1 hst.le]
simpa only [union_empty] using hst.symm.union this
theorem toMeasurable_ae_eq (h : NullMeasurableSet s μ) : toMeasurable μ s =ᵐ[μ] s := by
rw [toMeasurable_def, dif_pos]
exact (exists_measurable_superset_ae_eq h).choose_spec.2.2
theorem compl_toMeasurable_compl_ae_eq (h : NullMeasurableSet s μ) : (toMeasurable μ sᶜ)ᶜ =ᵐ[μ] s :=
Iff.mpr ae_eq_set_compl <| toMeasurable_ae_eq h.compl
theorem exists_measurable_subset_ae_eq (h : NullMeasurableSet s μ) :
∃ t ⊆ s, MeasurableSet t ∧ t =ᵐ[μ] s :=
⟨(toMeasurable μ sᶜ)ᶜ, compl_subset_comm.2 <| subset_toMeasurable _ _,
(measurableSet_toMeasurable _ _).compl, compl_toMeasurable_compl_ae_eq h⟩
end NullMeasurableSet
open NullMeasurableSet
/-- If `sᵢ` is a countable family of (null) measurable pairwise `μ`-a.e. disjoint sets, then there
exists a subordinate family `tᵢ ⊆ sᵢ` of measurable pairwise disjoint sets such that
`tᵢ =ᵐ[μ] sᵢ`. -/
theorem exists_subordinate_pairwise_disjoint [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) :
∃ t : ι → Set α,
(∀ i, t i ⊆ s i) ∧
(∀ i, s i =ᵐ[μ] t i) ∧ (∀ i, MeasurableSet (t i)) ∧ Pairwise (Disjoint on t) := by
choose t ht_sub htm ht_eq using fun i => exists_measurable_subset_ae_eq (h i)
rcases exists_null_pairwise_disjoint_diff hd with ⟨u, hum, hu₀, hud⟩
exact
⟨fun i => t i \ u i, fun i => diff_subset.trans (ht_sub _), fun i =>
(ht_eq _).symm.trans (diff_null_ae_eq_self (hu₀ i)).symm, fun i => (htm i).diff (hum i),
hud.mono fun i j h =>
h.mono (diff_subset_diff_left (ht_sub i)) (diff_subset_diff_left (ht_sub j))⟩
theorem measure_iUnion {m0 : MeasurableSpace α} {μ : Measure α} [Countable ι] {f : ι → Set α}
(hn : Pairwise (Disjoint on f)) (h : ∀ i, MeasurableSet (f i)) :
μ (⋃ i, f i) = ∑' i, μ (f i) := by
rw [measure_eq_extend (MeasurableSet.iUnion h),
extend_iUnion MeasurableSet.empty _ MeasurableSet.iUnion _ hn h]
· simp [measure_eq_extend, h]
· exact μ.empty
· exact μ.m_iUnion
theorem measure_iUnion₀ [Countable ι] {f : ι → Set α} (hd : Pairwise (AEDisjoint μ on f))
(h : ∀ i, NullMeasurableSet (f i) μ) : μ (⋃ i, f i) = ∑' i, μ (f i) := by
rcases exists_subordinate_pairwise_disjoint h hd with ⟨t, _ht_sub, ht_eq, htm, htd⟩
calc
μ (⋃ i, f i) = μ (⋃ i, t i) := measure_congr (EventuallyEq.countable_iUnion ht_eq)
_ = ∑' i, μ (t i) := measure_iUnion htd htm
_ = ∑' i, μ (f i) := tsum_congr fun i => measure_congr (ht_eq _).symm
theorem measure_union₀_aux (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ)
(hd : AEDisjoint μ s t) : μ (s ∪ t) = μ s + μ t := by
rw [union_eq_iUnion, measure_iUnion₀, tsum_fintype, Fintype.sum_bool, cond, cond]
exacts [(pairwise_on_bool AEDisjoint.symmetric).2 hd, fun b => Bool.casesOn b ht hs]
/-- A null measurable set `t` is Carathéodory measurable: for any `s`, we have
`μ (s ∩ t) + μ (s \ t) = μ s`. -/
theorem measure_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ (s ∩ t) + μ (s \ t) = μ s := by
refine le_antisymm ?_ (measure_le_inter_add_diff _ _ _)
rcases exists_measurable_superset μ s with ⟨s', hsub, hs'm, hs'⟩
replace hs'm : NullMeasurableSet s' μ := hs'm.nullMeasurableSet
calc
μ (s ∩ t) + μ (s \ t) ≤ μ (s' ∩ t) + μ (s' \ t) := by gcongr
_ = μ (s' ∩ t ∪ s' \ t) :=
(measure_union₀_aux (hs'm.inter ht) (hs'm.diff ht) <|
(@disjoint_inf_sdiff _ s' t _).aedisjoint).symm
_ = μ s' := congr_arg μ (inter_union_diff _ _)
_ = μ s := hs'
theorem measure_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [← measure_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
measure_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
theorem measure_union_add_inter₀' (hs : NullMeasurableSet s μ) (t : Set α) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [union_comm, inter_comm, measure_union_add_inter₀ t hs, add_comm]
theorem measure_union₀ (ht : NullMeasurableSet t μ) (hd : AEDisjoint μ s t) :
μ (s ∪ t) = μ s + μ t := by rw [← measure_union_add_inter₀ s ht, hd, add_zero]
theorem measure_union₀' (hs : NullMeasurableSet s μ) (hd : AEDisjoint μ s t) :
μ (s ∪ t) = μ s + μ t := by rw [union_comm, measure_union₀ hs (AEDisjoint.symm hd), add_comm]
theorem measure_add_measure_compl₀ {s : Set α} (hs : NullMeasurableSet s μ) :
μ s + μ sᶜ = μ univ := by rw [← measure_union₀' hs aedisjoint_compl_right, union_compl_self]
section MeasurableSingletonClass
variable [MeasurableSingletonClass (NullMeasurableSpace α μ)]
theorem nullMeasurableSet_singleton (x : α) : NullMeasurableSet {x} μ :=
@measurableSet_singleton _ _ _ _
@[simp]
theorem nullMeasurableSet_insert {a : α} {s : Set α} :
NullMeasurableSet (insert a s) μ ↔ NullMeasurableSet s μ :=
measurableSet_insert
theorem nullMeasurableSet_eq {a : α} : NullMeasurableSet { x | x = a } μ :=
nullMeasurableSet_singleton a
protected theorem _root_.Set.Finite.nullMeasurableSet (hs : s.Finite) : NullMeasurableSet s μ :=
Finite.measurableSet hs
protected theorem _root_.Finset.nullMeasurableSet (s : Finset α) : NullMeasurableSet (↑s) μ := by
apply Finset.measurableSet
end MeasurableSingletonClass
theorem _root_.Set.Finite.nullMeasurableSet_biUnion {f : ι → Set α} {s : Set ι} (hs : s.Finite)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋃ b ∈ s, f b) μ :=
Finite.measurableSet_biUnion hs h
theorem _root_.Finset.nullMeasurableSet_biUnion {f : ι → Set α} (s : Finset ι)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋃ b ∈ s, f b) μ :=
Finset.measurableSet_biUnion s h
theorem _root_.Set.Finite.nullMeasurableSet_sUnion {s : Set (Set α)} (hs : s.Finite)
(h : ∀ t ∈ s, NullMeasurableSet t μ) : NullMeasurableSet (⋃₀ s) μ :=
Finite.measurableSet_sUnion hs h
theorem _root_.Set.Finite.nullMeasurableSet_biInter {f : ι → Set α} {s : Set ι} (hs : s.Finite)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋂ b ∈ s, f b) μ :=
Finite.measurableSet_biInter hs h
theorem _root_.Finset.nullMeasurableSet_biInter {f : ι → Set α} (s : Finset ι)
(h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : NullMeasurableSet (⋂ b ∈ s, f b) μ :=
s.finite_toSet.nullMeasurableSet_biInter h
theorem _root_.Set.Finite.nullMeasurableSet_sInter {s : Set (Set α)} (hs : s.Finite)
(h : ∀ t ∈ s, NullMeasurableSet t μ) : NullMeasurableSet (⋂₀ s) μ :=
NullMeasurableSet.sInter (Finite.countable hs) h
theorem nullMeasurableSet_toMeasurable : NullMeasurableSet (toMeasurable μ s) μ :=
(measurableSet_toMeasurable _ _).nullMeasurableSet
end
section NullMeasurable
variable [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] {f : α → β} {μ : Measure α}
/-- A function `f : α → β` is null measurable if the preimage of a measurable set is a null
measurable set. -/
def NullMeasurable (f : α → β) (μ : Measure α := by volume_tac) : Prop :=
∀ ⦃s : Set β⦄, MeasurableSet s → NullMeasurableSet (f ⁻¹' s) μ
protected theorem _root_.Measurable.nullMeasurable (h : Measurable f) : NullMeasurable f μ :=
h.eventuallyMeasurable
protected theorem NullMeasurable.measurable' (h : NullMeasurable f μ) :
@Measurable (NullMeasurableSpace α μ) β _ _ f :=
h
theorem Measurable.comp_nullMeasurable {g : β → γ} (hg : Measurable g) (hf : NullMeasurable f μ) :
NullMeasurable (g ∘ f) μ :=
hg.comp_eventuallyMeasurable hf
theorem NullMeasurable.congr {g : α → β} (hf : NullMeasurable f μ) (hg : f =ᵐ[μ] g) :
NullMeasurable g μ :=
EventuallyMeasurable.congr hf hg.symm
end NullMeasurable
section IsComplete
/-- A measure is complete if every null set is also measurable.
A null set is a subset of a measurable set with measure `0`.
Since every measure is defined as a special case of an outer measure, we can more simply state
that a set `s` is null if `μ s = 0`. -/
class Measure.IsComplete {_ : MeasurableSpace α} (μ : Measure α) : Prop where
out' : ∀ s, μ s = 0 → MeasurableSet s
variable {m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α}
theorem Measure.isComplete_iff : μ.IsComplete ↔ ∀ s, μ s = 0 → MeasurableSet s :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
theorem Measure.IsComplete.out (h : μ.IsComplete) : ∀ s, μ s = 0 → MeasurableSet s :=
h.1
theorem measurableSet_of_null [μ.IsComplete] (hs : μ s = 0) : MeasurableSet s :=
MeasureTheory.Measure.IsComplete.out' s hs
theorem NullMeasurableSet.measurable_of_complete (hs : NullMeasurableSet s μ) [μ.IsComplete] :
MeasurableSet s :=
diff_diff_cancel_left (subset_toMeasurable μ s) ▸
(measurableSet_toMeasurable _ _).diff
(measurableSet_of_null (ae_le_set.1 <|
EventuallyEq.le (NullMeasurableSet.toMeasurable_ae_eq hs)))
theorem NullMeasurable.measurable_of_complete [μ.IsComplete] {_m1 : MeasurableSpace β} {f : α → β}
(hf : NullMeasurable f μ) : Measurable f := fun _s hs => (hf hs).measurable_of_complete
theorem _root_.Measurable.congr_ae {α β} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α}
[_hμ : μ.IsComplete] {f g : α → β} (hf : Measurable f) (hfg : f =ᵐ[μ] g) : Measurable g :=
NullMeasurable.measurable_of_complete (NullMeasurable.congr hf.nullMeasurable hfg)
namespace Measure
/-- Given a measure we can complete it to a (complete) measure on all null measurable sets. -/
def completion {_ : MeasurableSpace α} (μ : Measure α) :
MeasureTheory.Measure (NullMeasurableSpace α μ) where
toOuterMeasure := μ.toOuterMeasure
m_iUnion s hs hd := measure_iUnion₀ (hd.mono fun i j h => h.aedisjoint) hs
trim_le := by
nth_rewrite 2 [← μ.trimmed]
exact OuterMeasure.trim_anti_measurableSpace _ fun _ ↦ MeasurableSet.nullMeasurableSet
instance completion.isComplete {_m : MeasurableSpace α} (μ : Measure α) : μ.completion.IsComplete :=
⟨fun _z hz => NullMeasurableSet.of_null hz⟩
@[simp]
theorem coe_completion {_ : MeasurableSpace α} (μ : Measure α) : ⇑μ.completion = μ :=
rfl
theorem completion_apply {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) :
μ.completion s = μ s :=
rfl
@[simp]
theorem ae_completion {_ : MeasurableSpace α} (μ : Measure α) : ae μ.completion = ae μ := rfl
end Measure
end IsComplete
end MeasureTheory
|
MeasureTheory\Measure\OpenPos.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
/-!
# Measures positive on nonempty opens
In this file we define a typeclass for measures that are positive on nonempty opens, see
`MeasureTheory.Measure.IsOpenPosMeasure`. Examples include (additive) Haar measures, as well as
measures that have positive density with respect to a Haar measure. We also prove some basic facts
about these measures.
-/
open Topology ENNReal MeasureTheory
open Set Function Filter
namespace MeasureTheory
namespace Measure
section Basic
variable {X Y : Type*} [TopologicalSpace X] {m : MeasurableSpace X} [TopologicalSpace Y]
[T2Space Y] (μ ν : Measure X)
/-- A measure is said to be `IsOpenPosMeasure` if it is positive on nonempty open sets. -/
class IsOpenPosMeasure : Prop where
open_pos : ∀ U : Set X, IsOpen U → U.Nonempty → μ U ≠ 0
variable [IsOpenPosMeasure μ] {s U F : Set X} {x : X}
theorem _root_.IsOpen.measure_ne_zero (hU : IsOpen U) (hne : U.Nonempty) : μ U ≠ 0 :=
IsOpenPosMeasure.open_pos U hU hne
theorem _root_.IsOpen.measure_pos (hU : IsOpen U) (hne : U.Nonempty) : 0 < μ U :=
(hU.measure_ne_zero μ hne).bot_lt
instance (priority := 100) [Nonempty X] : NeZero μ :=
⟨measure_univ_pos.mp <| isOpen_univ.measure_pos μ univ_nonempty⟩
theorem _root_.IsOpen.measure_pos_iff (hU : IsOpen U) : 0 < μ U ↔ U.Nonempty :=
⟨fun h => nonempty_iff_ne_empty.2 fun he => h.ne' <| he.symm ▸ measure_empty, hU.measure_pos μ⟩
theorem _root_.IsOpen.measure_eq_zero_iff (hU : IsOpen U) : μ U = 0 ↔ U = ∅ := by
simpa only [not_lt, nonpos_iff_eq_zero, not_nonempty_iff_eq_empty] using
not_congr (hU.measure_pos_iff μ)
theorem measure_pos_of_nonempty_interior (h : (interior s).Nonempty) : 0 < μ s :=
(isOpen_interior.measure_pos μ h).trans_le (measure_mono interior_subset)
theorem measure_pos_of_mem_nhds (h : s ∈ 𝓝 x) : 0 < μ s :=
measure_pos_of_nonempty_interior _ ⟨x, mem_interior_iff_mem_nhds.2 h⟩
theorem isOpenPosMeasure_smul {c : ℝ≥0∞} (h : c ≠ 0) : IsOpenPosMeasure (c • μ) :=
⟨fun _U Uo Une => mul_ne_zero h (Uo.measure_ne_zero μ Une)⟩
variable {μ ν}
protected theorem AbsolutelyContinuous.isOpenPosMeasure (h : μ ≪ ν) : IsOpenPosMeasure ν :=
⟨fun _U ho hne h₀ => ho.measure_ne_zero μ hne (h h₀)⟩
theorem _root_.LE.le.isOpenPosMeasure (h : μ ≤ ν) : IsOpenPosMeasure ν :=
h.absolutelyContinuous.isOpenPosMeasure
theorem _root_.IsOpen.measure_zero_iff_eq_empty (hU : IsOpen U) :
μ U = 0 ↔ U = ∅ :=
⟨fun h ↦ (hU.measure_eq_zero_iff μ).mp h, fun h ↦ by simp [h]⟩
theorem _root_.IsOpen.ae_eq_empty_iff_eq (hU : IsOpen U) :
U =ᵐ[μ] (∅ : Set X) ↔ U = ∅ := by
rw [ae_eq_empty, hU.measure_zero_iff_eq_empty]
/-- An open null set w.r.t. an `IsOpenPosMeasure` is empty. -/
theorem _root_.IsOpen.eq_empty_of_measure_zero (hU : IsOpen U) (h₀ : μ U = 0) : U = ∅ :=
(hU.measure_eq_zero_iff μ).mp h₀
theorem _root_.IsClosed.ae_eq_univ_iff_eq (hF : IsClosed F) :
F =ᵐ[μ] univ ↔ F = univ := by
refine ⟨fun h ↦ ?_, fun h ↦ by rw [h]⟩
rwa [ae_eq_univ, hF.isOpen_compl.measure_eq_zero_iff μ, compl_empty_iff] at h
theorem _root_.IsClosed.measure_eq_univ_iff_eq [OpensMeasurableSpace X] [IsFiniteMeasure μ]
(hF : IsClosed F) :
μ F = μ univ ↔ F = univ := by
rw [← ae_eq_univ_iff_measure_eq hF.measurableSet.nullMeasurableSet, hF.ae_eq_univ_iff_eq]
theorem _root_.IsClosed.measure_eq_one_iff_eq_univ [OpensMeasurableSpace X] [IsProbabilityMeasure μ]
(hF : IsClosed F) :
μ F = 1 ↔ F = univ := by
rw [← measure_univ (μ := μ), hF.measure_eq_univ_iff_eq]
/-- A null set has empty interior. -/
theorem interior_eq_empty_of_null (hs : μ s = 0) : interior s = ∅ :=
isOpen_interior.eq_empty_of_measure_zero <| measure_mono_null interior_subset hs
/-- If two functions are a.e. equal on an open set and are continuous on this set, then they are
equal on this set. -/
theorem eqOn_open_of_ae_eq {f g : X → Y} (h : f =ᵐ[μ.restrict U] g) (hU : IsOpen U)
(hf : ContinuousOn f U) (hg : ContinuousOn g U) : EqOn f g U := by
replace h := ae_imp_of_ae_restrict h
simp only [EventuallyEq, ae_iff, Classical.not_imp] at h
have : IsOpen (U ∩ { a | f a ≠ g a }) := by
refine isOpen_iff_mem_nhds.mpr fun a ha => inter_mem (hU.mem_nhds ha.1) ?_
rcases ha with ⟨ha : a ∈ U, ha' : (f a, g a) ∈ (diagonal Y)ᶜ⟩
exact
(hf.continuousAt (hU.mem_nhds ha)).prod_mk_nhds (hg.continuousAt (hU.mem_nhds ha))
(isClosed_diagonal.isOpen_compl.mem_nhds ha')
replace := (this.eq_empty_of_measure_zero h).le
exact fun x hx => Classical.not_not.1 fun h => this ⟨hx, h⟩
/-- If two continuous functions are a.e. equal, then they are equal. -/
theorem eq_of_ae_eq {f g : X → Y} (h : f =ᵐ[μ] g) (hf : Continuous f) (hg : Continuous g) : f = g :=
suffices EqOn f g univ from funext fun _ => this trivial
eqOn_open_of_ae_eq (ae_restrict_of_ae h) isOpen_univ hf.continuousOn hg.continuousOn
theorem eqOn_of_ae_eq {f g : X → Y} (h : f =ᵐ[μ.restrict s] g) (hf : ContinuousOn f s)
(hg : ContinuousOn g s) (hU : s ⊆ closure (interior s)) : EqOn f g s :=
have : interior s ⊆ s := interior_subset
(eqOn_open_of_ae_eq (ae_restrict_of_ae_restrict_of_subset this h) isOpen_interior (hf.mono this)
(hg.mono this)).of_subset_closure
hf hg this hU
variable (μ)
theorem _root_.Continuous.ae_eq_iff_eq {f g : X → Y} (hf : Continuous f) (hg : Continuous g) :
f =ᵐ[μ] g ↔ f = g :=
⟨fun h => eq_of_ae_eq h hf hg, fun h => h ▸ EventuallyEq.rfl⟩
variable {μ}
theorem _root_.Continuous.isOpenPosMeasure_map [OpensMeasurableSpace X]
{Z : Type*} [TopologicalSpace Z] [MeasurableSpace Z] [BorelSpace Z]
{f : X → Z} (hf : Continuous f) (hf_surj : Function.Surjective f) :
(Measure.map f μ).IsOpenPosMeasure := by
refine ⟨fun U hUo hUne => ?_⟩
rw [Measure.map_apply hf.measurable hUo.measurableSet]
exact (hUo.preimage hf).measure_ne_zero μ (hf_surj.nonempty_preimage.mpr hUne)
end Basic
section LinearOrder
variable {X Y : Type*} [TopologicalSpace X] [LinearOrder X] [OrderTopology X]
{m : MeasurableSpace X} [TopologicalSpace Y] [T2Space Y] (μ : Measure X) [IsOpenPosMeasure μ]
theorem measure_Ioi_pos [NoMaxOrder X] (a : X) : 0 < μ (Ioi a) :=
isOpen_Ioi.measure_pos μ nonempty_Ioi
theorem measure_Iio_pos [NoMinOrder X] (a : X) : 0 < μ (Iio a) :=
isOpen_Iio.measure_pos μ nonempty_Iio
theorem measure_Ioo_pos [DenselyOrdered X] {a b : X} : 0 < μ (Ioo a b) ↔ a < b :=
(isOpen_Ioo.measure_pos_iff μ).trans nonempty_Ioo
theorem measure_Ioo_eq_zero [DenselyOrdered X] {a b : X} : μ (Ioo a b) = 0 ↔ b ≤ a :=
(isOpen_Ioo.measure_eq_zero_iff μ).trans (Ioo_eq_empty_iff.trans not_lt)
theorem eqOn_Ioo_of_ae_eq {a b : X} {f g : X → Y} (hfg : f =ᵐ[μ.restrict (Ioo a b)] g)
(hf : ContinuousOn f (Ioo a b)) (hg : ContinuousOn g (Ioo a b)) : EqOn f g (Ioo a b) :=
eqOn_of_ae_eq hfg hf hg Ioo_subset_closure_interior
theorem eqOn_Ioc_of_ae_eq [DenselyOrdered X] {a b : X} {f g : X → Y}
(hfg : f =ᵐ[μ.restrict (Ioc a b)] g) (hf : ContinuousOn f (Ioc a b))
(hg : ContinuousOn g (Ioc a b)) : EqOn f g (Ioc a b) :=
eqOn_of_ae_eq hfg hf hg (Ioc_subset_closure_interior _ _)
theorem eqOn_Ico_of_ae_eq [DenselyOrdered X] {a b : X} {f g : X → Y}
(hfg : f =ᵐ[μ.restrict (Ico a b)] g) (hf : ContinuousOn f (Ico a b))
(hg : ContinuousOn g (Ico a b)) : EqOn f g (Ico a b) :=
eqOn_of_ae_eq hfg hf hg (Ico_subset_closure_interior _ _)
theorem eqOn_Icc_of_ae_eq [DenselyOrdered X] {a b : X} (hne : a ≠ b) {f g : X → Y}
(hfg : f =ᵐ[μ.restrict (Icc a b)] g) (hf : ContinuousOn f (Icc a b))
(hg : ContinuousOn g (Icc a b)) : EqOn f g (Icc a b) :=
eqOn_of_ae_eq hfg hf hg (closure_interior_Icc hne).symm.subset
end LinearOrder
end Measure
end MeasureTheory
open MeasureTheory MeasureTheory.Measure
namespace Metric
variable {X : Type*} [PseudoMetricSpace X] {m : MeasurableSpace X} (μ : Measure X)
[IsOpenPosMeasure μ]
theorem measure_ball_pos (x : X) {r : ℝ} (hr : 0 < r) : 0 < μ (ball x r) :=
isOpen_ball.measure_pos μ (nonempty_ball.2 hr)
/-- See also `Metric.measure_closedBall_pos_iff`. -/
theorem measure_closedBall_pos (x : X) {r : ℝ} (hr : 0 < r) : 0 < μ (closedBall x r) :=
(measure_ball_pos μ x hr).trans_le (measure_mono ball_subset_closedBall)
@[simp] lemma measure_closedBall_pos_iff {X : Type*} [MetricSpace X] {m : MeasurableSpace X}
(μ : Measure X) [IsOpenPosMeasure μ] [NoAtoms μ] {x : X} {r : ℝ} :
0 < μ (closedBall x r) ↔ 0 < r := by
refine ⟨fun h ↦ ?_, measure_closedBall_pos μ x⟩
contrapose! h
rw [(subsingleton_closedBall x h).measure_zero μ]
end Metric
namespace EMetric
variable {X : Type*} [PseudoEMetricSpace X] {m : MeasurableSpace X} (μ : Measure X)
[IsOpenPosMeasure μ]
theorem measure_ball_pos (x : X) {r : ℝ≥0∞} (hr : r ≠ 0) : 0 < μ (ball x r) :=
isOpen_ball.measure_pos μ ⟨x, mem_ball_self hr.bot_lt⟩
theorem measure_closedBall_pos (x : X) {r : ℝ≥0∞} (hr : r ≠ 0) : 0 < μ (closedBall x r) :=
(measure_ball_pos μ x hr).trans_le (measure_mono ball_subset_closedBall)
end EMetric
section MeasureZero
/-! ## Meagre sets and measure zero
In general, neither of meagre and measure zero implies the other.
- The set of Liouville numbers is a Lebesgue measure zero subset of ℝ, but is not meagre.
(In fact, its complement is meagre. See `Real.disjoint_residual_ae`.)
- The complement of the set of Liouville numbers in $[0,1]$ is meagre and has measure 1.
For another counterexample, for all $α ∈ (0,1)$, there is a generalised Cantor set $C ⊆ [0,1]$
of measure `α`. Cantor sets are nowhere dense (hence meagre). Taking a countable union of
fat Cantor sets whose measure approaches 1 even yields a meagre set of measure 1.
However, with respect to a measure which is positive on non-empty open sets, *closed* measure
zero sets are nowhere dense and σ-compact measure zero sets in a Hausdorff space are meagre.
-/
variable {X : Type*} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] {s : Set X}
{μ : Measure X} [IsOpenPosMeasure μ]
/-- A *closed* measure zero subset is nowhere dense. (Closedness is required: for instance, the
rational numbers are countable (thus have measure zero), but are dense (hence not nowhere dense). -/
lemma IsNowhereDense.of_isClosed_null (h₁s : IsClosed s) (h₂s : μ s = 0) :
IsNowhereDense s := h₁s.isNowhereDense_iff.mpr (interior_eq_empty_of_null h₂s)
/-- A σ-compact measure zero subset is meagre.
(More generally, every Fσ set of measure zero is meagre.) -/
lemma IsMeagre.of_isSigmaCompact_null [T2Space X] (h₁s : IsSigmaCompact s) (h₂s : μ s = 0) :
IsMeagre s := by
rcases h₁s with ⟨K, hcompact, hcover⟩
have h (n : ℕ) : IsNowhereDense (K n) := by
have : μ (K n) = 0 := measure_mono_null (hcover ▸ subset_iUnion K n) h₂s
exact .of_isClosed_null (hcompact n).isClosed this
rw [isMeagre_iff_countable_union_isNowhereDense]
exact ⟨range K, fun t ⟨n, hn⟩ ↦ hn ▸ h n, countable_range K, hcover.symm.subset⟩
end MeasureZero
|
MeasureTheory\Measure\Portmanteau.lean | /-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.MeasureTheory.Integral.Layercake
import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction
/-!
# Characterizations of weak convergence of finite measures and probability measures
This file will provide portmanteau characterizations of the weak convergence of finite measures
and of probability measures, i.e., the standard characterizations of convergence in distribution.
## Main definitions
The topologies of weak convergence on the types of finite measures and probability measures are
already defined in their corresponding files; no substantial new definitions are introduced here.
## Main results
The main result will be the portmanteau theorem providing various characterizations of the
weak convergence of measures (probability measures or finite measures). Given measures μs
and μ on a topological space Ω, the conditions that will be proven equivalent (under quite
general hypotheses) are:
(T) The measures μs tend to the measure μ weakly.
(C) For any closed set F, the limsup of the measures of F under μs is at most
the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F).
(O) For any open set G, the liminf of the measures of G under μs is at least
the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G).
(B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0,
the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B).
The separate implications are:
* `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` is the implication (T) → (C).
* `MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge` is the equivalence (C) ↔ (O).
* `MeasureTheory.tendsto_measure_of_null_frontier` is the implication (O) → (B).
* `MeasureTheory.limsup_measure_closed_le_of_forall_tendsto_measure` is the implication (B) → (C).
* `MeasureTheory.tendsto_of_forall_isOpen_le_liminf` gives the implication (O) → (T) for
any sequence of Borel probability measures.
## Implementation notes
Many of the characterizations of weak convergence hold for finite measures and are proven in that
generality and then specialized to probability measures. Some implications hold with slightly
more general assumptions than in the usual statement of portmanteau theorem. The full portmanteau
theorem, however, is most convenient for probability measures on pseudo-emetrizable spaces with
their Borel sigma algebras.
Some specific considerations on the assumptions in the different implications:
* `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` assumes
`PseudoEMetricSpace`. The only reason is to have bounded continuous pointwise approximations
to the indicator function of a closed set. Clearly for example metrizability or
pseudo-emetrizability would be sufficient assumptions. The typeclass assumptions should be later
adjusted in a way that takes into account use cases, but the proof will presumably remain
essentially the same.
* Where formulations are currently only provided for probability measures, one can obtain the
finite measure formulations using the characterization of convergence of finite measures by
their total masses and their probability-normalized versions, i.e., by
`MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
weak convergence of measures, convergence in distribution, convergence in law, finite measure,
probability measure
-/
noncomputable section
open MeasureTheory Set Filter BoundedContinuousFunction
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
section LimsupClosedLEAndLELiminfOpen
/-! ### Portmanteau: limsup condition for closed sets iff liminf condition for open sets
In this section we prove that for a sequence of Borel probability measures on a topological space
and its candidate limit measure, the following two conditions are equivalent:
(C) For any closed set F, the limsup of the measures of F under μs is at most
the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F);
(O) For any open set G, the liminf of the measures of G under μs is at least
the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G).
Either of these will later be shown to be equivalent to the weak convergence of the sequence
of measures.
-/
variable {Ω : Type*} [MeasurableSpace Ω]
/-- **Portmanteau theorem** -/
theorem le_measure_compl_liminf_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω}
{μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω}
(E_mble : MeasurableSet E) (h : (L.limsup fun i => μs i E) ≤ μ E) :
μ Eᶜ ≤ L.liminf fun i => μs i Eᶜ := by
rcases L.eq_or_neBot with rfl | hne
· simp only [liminf_bot, le_top]
have meas_Ec : μ Eᶜ = 1 - μ E := by
simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne
have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by
intro i
simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne
simp_rw [meas_Ec, meas_i_Ec]
have obs :
(L.liminf fun i : ι => 1 - μs i E) = L.liminf ((fun x => 1 - x) ∘ fun i : ι => μs i E) := rfl
rw [obs]
have := antitone_const_tsub.map_limsup_of_continuousAt (F := L)
(fun i => μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt
simp_rw [← this]
exact antitone_const_tsub h
theorem le_measure_liminf_of_limsup_measure_compl_le {ι : Type*} {L : Filter ι} {μ : Measure Ω}
{μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω}
(E_mble : MeasurableSet E) (h : (L.limsup fun i => μs i Eᶜ) ≤ μ Eᶜ) :
μ E ≤ L.liminf fun i => μs i E :=
compl_compl E ▸ le_measure_compl_liminf_of_limsup_measure_le (MeasurableSet.compl E_mble) h
theorem limsup_measure_compl_le_of_le_liminf_measure {ι : Type*} {L : Filter ι} {μ : Measure Ω}
{μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω}
(E_mble : MeasurableSet E) (h : μ E ≤ L.liminf fun i => μs i E) :
(L.limsup fun i => μs i Eᶜ) ≤ μ Eᶜ := by
rcases L.eq_or_neBot with rfl | hne
· simp only [limsup_bot, bot_le]
have meas_Ec : μ Eᶜ = 1 - μ E := by
simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne
have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by
intro i
simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne
simp_rw [meas_Ec, meas_i_Ec]
have obs :
(L.limsup fun i : ι => 1 - μs i E) = L.limsup ((fun x => 1 - x) ∘ fun i : ι => μs i E) := rfl
rw [obs]
have := antitone_const_tsub.map_liminf_of_continuousAt (F := L)
(fun i => μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt
simp_rw [← this]
exact antitone_const_tsub h
theorem limsup_measure_le_of_le_liminf_measure_compl {ι : Type*} {L : Filter ι} {μ : Measure Ω}
{μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω}
(E_mble : MeasurableSet E) (h : μ Eᶜ ≤ L.liminf fun i => μs i Eᶜ) :
(L.limsup fun i => μs i E) ≤ μ E :=
compl_compl E ▸ limsup_measure_compl_le_of_le_liminf_measure (MeasurableSet.compl E_mble) h
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
/-- One pair of implications of the portmanteau theorem:
For a sequence of Borel probability measures, the following two are equivalent:
(C) The limsup of the measures of any closed set is at most the measure of the closed set
under a candidate limit measure.
(O) The liminf of the measures of any open set is at least the measure of the open set
under a candidate limit measure.
-/
theorem limsup_measure_closed_le_iff_liminf_measure_open_ge {ι : Type*} {L : Filter ι}
{μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ]
[∀ i, IsProbabilityMeasure (μs i)] :
(∀ F, IsClosed F → (L.limsup fun i => μs i F) ≤ μ F) ↔
∀ G, IsOpen G → μ G ≤ L.liminf fun i => μs i G := by
constructor
· intro h G G_open
exact le_measure_liminf_of_limsup_measure_compl_le
G_open.measurableSet (h Gᶜ (isClosed_compl_iff.mpr G_open))
· intro h F F_closed
exact limsup_measure_le_of_le_liminf_measure_compl
F_closed.measurableSet (h Fᶜ (isOpen_compl_iff.mpr F_closed))
end LimsupClosedLEAndLELiminfOpen -- section
section TendstoOfNullFrontier
/-! ### Portmanteau: limit of measures of Borel sets whose boundary carries no mass in the limit
In this section we prove that for a sequence of Borel probability measures on a topological space
and its candidate limit measure, either of the following equivalent conditions:
(C) For any closed set F, the limsup of the measures of F under μs is at most
the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F);
(O) For any open set G, the liminf of the measures of G under μs is at least
the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G).
implies that
(B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0,
the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B).
-/
variable {Ω : Type*} [MeasurableSpace Ω]
theorem tendsto_measure_of_le_liminf_measure_of_limsup_measure_le {ι : Type*} {L : Filter ι}
{μ : Measure Ω} {μs : ι → Measure Ω} {E₀ E E₁ : Set Ω} (E₀_subset : E₀ ⊆ E) (subset_E₁ : E ⊆ E₁)
(nulldiff : μ (E₁ \ E₀) = 0) (h_E₀ : μ E₀ ≤ L.liminf fun i => μs i E₀)
(h_E₁ : (L.limsup fun i => μs i E₁) ≤ μ E₁) : L.Tendsto (fun i => μs i E) (𝓝 (μ E)) := by
apply tendsto_of_le_liminf_of_limsup_le
· have E₀_ae_eq_E : E₀ =ᵐ[μ] E :=
EventuallyLE.antisymm E₀_subset.eventuallyLE
(subset_E₁.eventuallyLE.trans (ae_le_set.mpr nulldiff))
calc
μ E = μ E₀ := measure_congr E₀_ae_eq_E.symm
_ ≤ L.liminf fun i => μs i E₀ := h_E₀
_ ≤ L.liminf fun i => μs i E :=
liminf_le_liminf (eventually_of_forall fun _ => measure_mono E₀_subset)
· have E_ae_eq_E₁ : E =ᵐ[μ] E₁ :=
EventuallyLE.antisymm subset_E₁.eventuallyLE
((ae_le_set.mpr nulldiff).trans E₀_subset.eventuallyLE)
calc
(L.limsup fun i => μs i E) ≤ L.limsup fun i => μs i E₁ :=
limsup_le_limsup (eventually_of_forall fun _ => measure_mono subset_E₁)
_ ≤ μ E₁ := h_E₁
_ = μ E := measure_congr E_ae_eq_E₁.symm
· infer_param
· infer_param
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
/-- One implication of the portmanteau theorem:
For a sequence of Borel probability measures, if the liminf of the measures of any open set is at
least the measure of the open set under a candidate limit measure, then for any set whose
boundary carries no probability mass under the candidate limit measure, then its measures under the
sequence converge to its measure under the candidate limit measure.
-/
theorem tendsto_measure_of_null_frontier {ι : Type*} {L : Filter ι} {μ : Measure Ω}
{μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)]
(h_opens : ∀ G, IsOpen G → μ G ≤ L.liminf fun i => μs i G) {E : Set Ω}
(E_nullbdry : μ (frontier E) = 0) : L.Tendsto (fun i => μs i E) (𝓝 (μ E)) :=
haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i => μs i F) ≤ μ F :=
limsup_measure_closed_le_iff_liminf_measure_open_ge.mpr h_opens
tendsto_measure_of_le_liminf_measure_of_limsup_measure_le interior_subset subset_closure
E_nullbdry (h_opens _ isOpen_interior) (h_closeds _ isClosed_closure)
end TendstoOfNullFrontier --section
section ConvergenceImpliesLimsupClosedLE
/-! ### Portmanteau implication: weak convergence implies a limsup condition for closed sets
In this section we prove, under the assumption that the underlying topological space `Ω` is
pseudo-emetrizable, that
(T) The measures μs tend to the measure μ weakly
implies
(C) For any closed set F, the limsup of the measures of F under μs is at most
the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F).
Combining with a earlier proven implications, we get that (T) implies also both
(O) For any open set G, the liminf of the measures of G under μs is at least
the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G);
(B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0,
the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B).
-/
/-- One implication of the portmanteau theorem:
Weak convergence of finite measures implies that the limsup of the measures of any closed set is
at most the measure of the closed set under the limit measure.
-/
theorem FiniteMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι}
[MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω]
[OpensMeasurableSpace Ω] {μ : FiniteMeasure Ω}
{μs : ι → FiniteMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) :
(L.limsup fun i => (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by
rcases L.eq_or_neBot with rfl | hne
· simp only [limsup_bot, bot_le]
apply ENNReal.le_of_forall_pos_le_add
intro ε ε_pos _
let fs := F_closed.apprSeq
have key₁ : Tendsto (fun n ↦ ∫⁻ ω, (fs n ω : ℝ≥0∞) ∂μ) atTop (𝓝 ((μ : Measure Ω) F)) :=
HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed (μ : Measure Ω)
have room₁ : (μ : Measure Ω) F < (μ : Measure Ω) F + ε / 2 := by
apply
ENNReal.lt_add_right (measure_lt_top (μ : Measure Ω) F).ne
(ENNReal.div_pos_iff.mpr ⟨(ENNReal.coe_pos.mpr ε_pos).ne.symm, ENNReal.two_ne_top⟩).ne.symm
rcases eventually_atTop.mp (eventually_lt_of_tendsto_lt room₁ key₁) with ⟨M, hM⟩
have key₂ := FiniteMeasure.tendsto_iff_forall_lintegral_tendsto.mp μs_lim (fs M)
have room₂ :
(lintegral (μ : Measure Ω) fun a => fs M a) <
(lintegral (μ : Measure Ω) fun a => fs M a) + ε / 2 := by
apply ENNReal.lt_add_right (ne_of_lt ?_)
(ENNReal.div_pos_iff.mpr ⟨(ENNReal.coe_pos.mpr ε_pos).ne.symm, ENNReal.two_ne_top⟩).ne.symm
apply BoundedContinuousFunction.lintegral_lt_top_of_nnreal
have ev_near := Eventually.mono (eventually_lt_of_tendsto_lt room₂ key₂) fun n => le_of_lt
have ev_near' := Eventually.mono ev_near
(fun n ↦ le_trans (HasOuterApproxClosed.measure_le_lintegral F_closed (μs n) M))
apply (Filter.limsup_le_limsup ev_near').trans
rw [limsup_const]
apply le_trans (add_le_add (hM M rfl.le).le (le_refl (ε / 2 : ℝ≥0∞)))
simp only [add_assoc, ENNReal.add_halves, le_refl]
/-- One implication of the portmanteau theorem:
Weak convergence of probability measures implies that the limsup of the measures of any closed
set is at most the measure of the closed set under the limit probability measure.
-/
theorem ProbabilityMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι}
[MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω]
{μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ))
{F : Set Ω} (F_closed : IsClosed F) :
(L.limsup fun i => (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by
apply FiniteMeasure.limsup_measure_closed_le_of_tendsto
((ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds L).mp μs_lim) F_closed
/-- One implication of the portmanteau theorem:
Weak convergence of probability measures implies that the liminf of the measures of any open set
is at least the measure of the open set under the limit probability measure.
-/
theorem ProbabilityMeasure.le_liminf_measure_open_of_tendsto {Ω ι : Type*} {L : Filter ι}
[MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω]
{μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ))
{G : Set Ω} (G_open : IsOpen G) :
(μ : Measure Ω) G ≤ L.liminf fun i => (μs i : Measure Ω) G :=
haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F :=
fun _ F_closed => ProbabilityMeasure.limsup_measure_closed_le_of_tendsto μs_lim F_closed
le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet
(h_closeds _ (isClosed_compl_iff.mpr G_open))
theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' {Ω ι : Type*}
{L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω]
[HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω}
(μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : (μ : Measure Ω) (frontier E) = 0) :
Tendsto (fun i => (μs i : Measure Ω) E) L (𝓝 ((μ : Measure Ω) E)) :=
haveI h_opens : ∀ G, IsOpen G → (μ : Measure Ω) G ≤ L.liminf fun i => (μs i : Measure Ω) G :=
fun _ G_open => ProbabilityMeasure.le_liminf_measure_open_of_tendsto μs_lim G_open
tendsto_measure_of_null_frontier h_opens E_nullbdry
/-- One implication of the portmanteau theorem:
Weak convergence of probability measures implies that if the boundary of a Borel set
carries no probability mass under the limit measure, then the limit of the measures of the set
equals the measure of the set under the limit probability measure.
A version with coercions to ordinary `ℝ≥0∞`-valued measures is
`MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto'`.
-/
theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto {Ω ι : Type*} {L : Filter ι}
[MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω]
{μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ))
{E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : Tendsto (fun i => μs i E) L (𝓝 (μ E)) := by
have E_nullbdry' : (μ : Measure Ω) (frontier E) = 0 := by
rw [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure, E_nullbdry, ENNReal.coe_zero]
have key := ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' μs_lim E_nullbdry'
exact (ENNReal.tendsto_toNNReal (measure_ne_top (↑μ) E)).comp key
end ConvergenceImpliesLimsupClosedLE --section
section LimitBorelImpliesLimsupClosedLE
/-! ### Portmanteau implication: limit condition for Borel sets implies limsup for closed sets
In this section we prove, under the assumption that the underlying topological space `Ω` is
pseudo-emetrizable, that
(B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0,
the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B)
implies
(C) For any closed set F, the limsup of the measures of F under μs is at most
the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F).
Combining with a earlier proven implications, we get that (B) implies also
(O) For any open set G, the liminf of the measures of G under μs is at least
the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G).
-/
open ENNReal
variable {Ω : Type*} [PseudoEMetricSpace Ω] [MeasurableSpace Ω] [OpensMeasurableSpace Ω]
theorem exists_null_frontier_thickening (μ : Measure Ω) [SFinite μ] (s : Set Ω) {a b : ℝ}
(hab : a < b) : ∃ r ∈ Ioo a b, μ (frontier (Metric.thickening r s)) = 0 := by
have mbles : ∀ r : ℝ, MeasurableSet (frontier (Metric.thickening r s)) :=
fun r => isClosed_frontier.measurableSet
have disjs := Metric.frontier_thickening_disjoint s
have key := Measure.countable_meas_pos_of_disjoint_iUnion (μ := μ) mbles disjs
have aux := measure_diff_null (s := Ioo a b) (Set.Countable.measure_zero key volume)
have len_pos : 0 < ENNReal.ofReal (b - a) := by simp only [hab, ENNReal.ofReal_pos, sub_pos]
rw [← Real.volume_Ioo, ← aux] at len_pos
rcases nonempty_of_measure_ne_zero len_pos.ne.symm with ⟨r, ⟨r_in_Ioo, hr⟩⟩
refine ⟨r, r_in_Ioo, ?_⟩
simpa only [mem_setOf_eq, not_lt, le_zero_iff] using hr
theorem exists_null_frontiers_thickening (μ : Measure Ω) [SFinite μ] (s : Set Ω) :
∃ rs : ℕ → ℝ,
Tendsto rs atTop (𝓝 0) ∧ ∀ n, 0 < rs n ∧ μ (frontier (Metric.thickening (rs n) s)) = 0 := by
rcases exists_seq_strictAnti_tendsto (0 : ℝ) with ⟨Rs, ⟨_, ⟨Rs_pos, Rs_lim⟩⟩⟩
have obs := fun n : ℕ => exists_null_frontier_thickening μ s (Rs_pos n)
refine ⟨fun n : ℕ => (obs n).choose, ⟨?_, ?_⟩⟩
· exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds Rs_lim
(fun n => (obs n).choose_spec.1.1.le) fun n => (obs n).choose_spec.1.2.le
· exact fun n => ⟨(obs n).choose_spec.1.1, (obs n).choose_spec.2⟩
/-- One implication of the portmanteau theorem:
Assuming that for all Borel sets E whose boundary ∂E carries no probability mass under a
candidate limit probability measure μ we have convergence of the measures μsᵢ(E) to μ(E),
then for all closed sets F we have the limsup condition limsup μsᵢ(F) ≤ μ(F). -/
lemma limsup_measure_closed_le_of_forall_tendsto_measure
{Ω ι : Type*} {L : Filter ι} [NeBot L]
[MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω]
{μ : Measure Ω} [IsFiniteMeasure μ] {μs : ι → Measure Ω}
(h : ∀ {E : Set Ω}, MeasurableSet E → μ (frontier E) = 0 →
Tendsto (fun i ↦ μs i E) L (𝓝 (μ E)))
(F : Set Ω) (F_closed : IsClosed F) :
L.limsup (fun i ↦ μs i F) ≤ μ F := by
have ex := exists_null_frontiers_thickening μ F
let rs := Classical.choose ex
have rs_lim : Tendsto rs atTop (𝓝 0) := (Classical.choose_spec ex).1
have rs_pos : ∀ n, 0 < rs n := fun n ↦ ((Classical.choose_spec ex).2 n).1
have rs_null : ∀ n, μ (frontier (Metric.thickening (rs n) F)) = 0 :=
fun n ↦ ((Classical.choose_spec ex).2 n).2
have Fthicks_open : ∀ n, IsOpen (Metric.thickening (rs n) F) :=
fun n ↦ Metric.isOpen_thickening
have key := fun (n : ℕ) ↦ h (Fthicks_open n).measurableSet (rs_null n)
apply ENNReal.le_of_forall_pos_le_add
intros ε ε_pos μF_finite
have keyB := tendsto_measure_cthickening_of_isClosed (μ := μ) (s := F)
⟨1, ⟨by simp only [gt_iff_lt, zero_lt_one], measure_ne_top _ _⟩⟩ F_closed
have nhd : Iio (μ F + ε) ∈ 𝓝 (μ F) := by
apply Iio_mem_nhds
exact ENNReal.lt_add_right μF_finite.ne (ENNReal.coe_pos.mpr ε_pos).ne'
specialize rs_lim (keyB nhd)
simp only [mem_map, mem_atTop_sets, mem_preimage, mem_Iio] at rs_lim
obtain ⟨m, hm⟩ := rs_lim
have aux' := fun i ↦ measure_mono (μ := μs i) (Metric.self_subset_thickening (rs_pos m) F)
have aux : (fun i ↦ (μs i F)) ≤ᶠ[L] (fun i ↦ μs i (Metric.thickening (rs m) F)) :=
eventually_of_forall aux'
refine (limsup_le_limsup aux).trans ?_
rw [Tendsto.limsup_eq (key m)]
apply (measure_mono (Metric.thickening_subset_cthickening (rs m) F)).trans (hm m rfl.le).le
/-- One implication of the portmanteau theorem:
Assuming that for all Borel sets E whose boundary ∂E carries no probability mass under a
candidate limit probability measure μ we have convergence of the measures μsᵢ(E) to μ(E),
then for all open sets G we have the limsup condition μ(G) ≤ liminf μsᵢ(G). -/
lemma le_liminf_measure_open_of_forall_tendsto_measure
{Ω ι : Type*} {L : Filter ι} [NeBot L]
[MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω]
{μ : Measure Ω} [IsProbabilityMeasure μ] {μs : ι → Measure Ω} [∀ i, IsProbabilityMeasure (μs i)]
(h : ∀ {E}, MeasurableSet E → μ (frontier E) = 0 → Tendsto (fun i ↦ μs i E) L (𝓝 (μ E)))
(G : Set Ω) (G_open : IsOpen G) :
μ G ≤ L.liminf (fun i ↦ μs i G) := by
apply le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet
exact limsup_measure_closed_le_of_forall_tendsto_measure h _ (isClosed_compl_iff.mpr G_open)
end LimitBorelImpliesLimsupClosedLE --section
section le_liminf_open_implies_convergence
/-! ### Portmanteau implication: liminf condition for open sets implies weak convergence
In this section we prove for a sequence (μsₙ)ₙ Borel probability measures that
(O) For any open set G, the liminf of the measures of G under μsₙ is at least
the measure of G under μ, i.e., μ(G) ≤ liminfₙ μsₙ(G).
implies
(T) The measures μsₙ converge weakly to the measure μ.
-/
variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
lemma lintegral_le_liminf_lintegral_of_forall_isOpen_measure_le_liminf_measure
{μ : Measure Ω} {μs : ℕ → Measure Ω} {f : Ω → ℝ} (f_cont : Continuous f) (f_nn : 0 ≤ f)
(h_opens : ∀ G, IsOpen G → μ G ≤ atTop.liminf (fun i ↦ μs i G)) :
∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ atTop.liminf (fun i ↦ ∫⁻ x, ENNReal.ofReal (f x) ∂ (μs i)) := by
simp_rw [lintegral_eq_lintegral_meas_lt _ (eventually_of_forall f_nn) f_cont.aemeasurable]
calc ∫⁻ (t : ℝ) in Set.Ioi 0, μ {a | t < f a}
≤ ∫⁻ (t : ℝ) in Set.Ioi 0, atTop.liminf (fun i ↦ (μs i) {a | t < f a}) := ?_ -- (i)
_ ≤ atTop.liminf (fun i ↦ ∫⁻ (t : ℝ) in Set.Ioi 0, (μs i) {a | t < f a}) := ?_ -- (ii)
· -- (i)
exact (lintegral_mono (fun t ↦ h_opens _ (continuous_def.mp f_cont _ isOpen_Ioi))).trans
(le_refl _)
· -- (ii)
exact lintegral_liminf_le (fun n ↦ Antitone.measurable (fun s t hst ↦
measure_mono (fun ω hω ↦ lt_of_le_of_lt hst hω)))
lemma integral_le_liminf_integral_of_forall_isOpen_measure_le_liminf_measure
{μ : Measure Ω} [IsProbabilityMeasure μ] {μs : ℕ → Measure Ω} [∀ i, IsProbabilityMeasure (μs i)]
{f : Ω →ᵇ ℝ} (f_nn : 0 ≤ f)
(h_opens : ∀ G, IsOpen G → μ G ≤ atTop.liminf (fun i ↦ μs i G)) :
∫ x, (f x) ∂μ ≤ atTop.liminf (fun i ↦ ∫ x, (f x) ∂ (μs i)) := by
have same := lintegral_le_liminf_lintegral_of_forall_isOpen_measure_le_liminf_measure
f.continuous f_nn h_opens
rw [@integral_eq_lintegral_of_nonneg_ae Ω _ μ f (eventually_of_forall f_nn)
f.continuous.measurable.aestronglyMeasurable]
convert (ENNReal.toReal_le_toReal ?_ ?_).mpr same
· simp only [fun i ↦ @integral_eq_lintegral_of_nonneg_ae Ω _ (μs i) f (eventually_of_forall f_nn)
f.continuous.measurable.aestronglyMeasurable]
let g := BoundedContinuousFunction.comp _ Real.lipschitzWith_toNNReal f
have bound : ∀ i, ∫⁻ x, ENNReal.ofReal (f x) ∂(μs i) ≤ nndist 0 g := fun i ↦ by
simpa only [coe_nnreal_ennreal_nndist, measure_univ, mul_one] using
BoundedContinuousFunction.lintegral_le_edist_mul (μ := μs i) g
apply ENNReal.liminf_toReal_eq ENNReal.coe_ne_top (eventually_of_forall bound)
· exact (f.lintegral_of_real_lt_top μ).ne
· apply ne_of_lt
have obs := fun (i : ℕ) ↦ @BoundedContinuousFunction.lintegral_nnnorm_le Ω _ _ (μs i) ℝ _ f
simp only [measure_univ, mul_one] at obs
apply lt_of_le_of_lt _ (show (‖f‖₊ : ℝ≥0∞) < ∞ from ENNReal.coe_lt_top)
apply liminf_le_of_le
· refine ⟨0, eventually_of_forall (by simp only [zero_le, forall_const])⟩
· intro x hx
obtain ⟨i, hi⟩ := hx.exists
apply le_trans hi
convert obs i with x
have aux := ENNReal.ofReal_eq_coe_nnreal (f_nn x)
simp only [ContinuousMap.toFun_eq_coe, BoundedContinuousFunction.coe_to_continuous_fun] at aux
rw [aux]
congr
exact (Real.norm_of_nonneg (f_nn x)).symm
/-- One implication of the portmanteau theorem:
If for all open sets G we have the liminf condition `μ(G) ≤ liminf μsₙ(G)`, then the measures
μsₙ converge weakly to the measure μ. -/
theorem tendsto_of_forall_isOpen_le_liminf {μ : ProbabilityMeasure Ω}
{μs : ℕ → ProbabilityMeasure Ω}
(h_opens : ∀ G, IsOpen G → μ G ≤ atTop.liminf (fun i ↦ μs i G)) :
atTop.Tendsto (fun i ↦ μs i) (𝓝 μ) := by
refine ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr ?_
apply tendsto_integral_of_forall_integral_le_liminf_integral
intro f f_nn
apply integral_le_liminf_integral_of_forall_isOpen_measure_le_liminf_measure (f := f) f_nn
intro G G_open
specialize h_opens G G_open
have aux : ENNReal.ofNNReal (liminf (fun i ↦ μs i G) atTop) =
liminf (ENNReal.ofNNReal ∘ fun i ↦ μs i G) atTop := by
refine Monotone.map_liminf_of_continuousAt (F := atTop) ENNReal.coe_mono (μs · G) ?_ ?_ ?_
· apply ENNReal.continuous_coe.continuousAt
· apply IsBoundedUnder.isCoboundedUnder_ge ⟨1, ?_⟩
simp only [eventually_map, ProbabilityMeasure.apply_le_one, eventually_atTop, ge_iff_le,
implies_true, forall_const, exists_const]
· use 0
simp only [zero_le, eventually_map, eventually_atTop, implies_true, forall_const,
exists_const]
have obs := ENNReal.coe_mono h_opens
simp only [ne_eq, ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure, aux] at obs
convert obs
simp only [Function.comp_apply, ne_eq, ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure]
end le_liminf_open_implies_convergence
end MeasureTheory --namespace
|
MeasureTheory\Measure\ProbabilityMeasure.lean | /-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.FiniteMeasure
import Mathlib.MeasureTheory.Integral.Average
/-!
# Probability measures
This file defines the type of probability measures on a given measurable space. When the underlying
space has a topology and the measurable space structure (sigma algebra) is finer than the Borel
sigma algebra, then the type of probability measures is equipped with the topology of convergence
in distribution (weak convergence of measures). The topology of convergence in distribution is the
coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the
expected value of `X` depends continuously on the choice of probability measure. This is a special
case of the topology of weak convergence of finite measures.
## Main definitions
The main definitions are
* the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in
distribution (a.k.a. convergence in law, weak convergence of measures);
* `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as
a finite measure;
* `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure
(returns junk for the zero measure).
* `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure
`μ` on `Ω` along a measurable function `f : Ω → Ω'`.
## Main results
* `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of
probability measures is characterized by the convergence of expected values of all bounded
continuous random variables. This shows that the chosen definition of topology coincides with
the common textbook definition of convergence in distribution, i.e., weak convergence of
measures. A similar characterization by the convergence of expected values (in the
`MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is
`MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`.
* `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite
measures to a nonzero limit is characterized by the convergence of the probability-normalized
versions and of the total masses.
* `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the
push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is
continuous.
* `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is
Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing
approximating sequences (in particular on any pseudo-metrizable spaces).
TODO:
* Probability measures form a convex space.
## Implementation notes
The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited
weak convergence of finite measures via the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω`
is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the
composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
convergence in distribution, convergence in law, weak convergence of measures, probability measure
-/
noncomputable section
open MeasureTheory
open Set
open Filter
open BoundedContinuousFunction
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
section ProbabilityMeasure
/-! ### Probability measures
In this section we define the type of probability measures on a measurable space `Ω`, denoted by
`MeasureTheory.ProbabilityMeasure Ω`.
If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma
algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is
equipped with the topology of weak convergence of measures. Since every probability measure is a
finite measure, this is implemented as the induced topology from the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
-/
/-- Probability measures are defined as the subtype of measures that have the property of being
probability measures (i.e., their total mass is one). -/
def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ :=
{ μ : Measure Ω // IsProbabilityMeasure μ }
namespace ProbabilityMeasure
variable {Ω : Type*} [MeasurableSpace Ω]
instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) :=
⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩
-- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`), we need a new function for the
-- coercion instead of relying on `Subtype.val`.
/-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/
@[coe]
def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val
/-- A probability measure can be interpreted as a measure. -/
instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) where
coe := toMeasure
instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) :=
μ.prop
@[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl
@[simp]
theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) :=
rfl
theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) :=
Subtype.coe_injective
instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where
coe μ s := ((μ : Measure Ω) s).toNNReal
coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by
simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s
lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl
lemma coeFn_mk (μ : Measure Ω) (hμ) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl
@[simp, norm_cast]
lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl
@[simp, norm_cast]
theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 :=
congr_arg ENNReal.toNNReal ν.prop.measure_univ
theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by
simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff]
/-- A probability measure can be interpreted as a finite measure. -/
def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω :=
⟨μ, inferInstance⟩
@[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl
lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) :
μ.toFiniteMeasure s = μ s := rfl
@[simp]
theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) :=
rfl
@[simp]
theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) :=
rfl
@[simp]
theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) :
ν.toFiniteMeasure s = ν s := rfl
@[simp]
theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) :
(ν s : ℝ≥0∞) = (ν : Measure Ω) s := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure,
toMeasure_comp_toFiniteMeasure_eq_toMeasure]
theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn]
exact MeasureTheory.FiniteMeasure.apply_mono _ h
@[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by
simpa using apply_mono μ (subset_univ s)
theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by
by_contra maybe_empty
have zero : (μ : Measure Ω) univ = 0 := by
rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty]
rw [measure_univ] at zero
exact zero_ne_one zero.symm
@[ext]
theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by
apply toMeasure_injective
ext1 s s_mble
exact h s s_mble
theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble
simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
@[simp]
theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 :=
μ.coeFn_univ
theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by
rw [← FiniteMeasure.mass_nonzero_iff, μ.mass_toFiniteMeasure]
exact one_ne_zero
section convergence_in_distribution
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) :
LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 => μ.toFiniteMeasure.testAgainstNN f :=
μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz
/-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited
(induced) from the topology of weak convergence of finite measures via the inclusion
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/
instance : TopologicalSpace (ProbabilityMeasure Ω) :=
TopologicalSpace.induced toFiniteMeasure inferInstance
theorem toFiniteMeasure_continuous :
Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) :=
continuous_induced_dom
/-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative
functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/
def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) :=
FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure
@[simp]
theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) :
⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN :=
rfl
@[simp]
theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal :=
rfl
theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω => μ.toWeakDualBCNN :=
FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous
/- Integration of (nonnegative bounded continuous) test functions against Borel probability
measures depends continuously on the measure. -/
theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) :
Continuous fun μ : ProbabilityMeasure Ω => μ.toFiniteMeasure.testAgainstNN f :=
(FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous
-- The canonical mapping from probability measures to finite measures is an embedding.
theorem toFiniteMeasure_embedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω]
[OpensMeasurableSpace Ω] :
Embedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) :=
{ induced := rfl
inj := fun _μ _ν h => Subtype.eq <| congr_arg FiniteMeasure.toMeasure h }
theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ)
{μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) :=
Embedding.tendsto_nhds_iff (toFiniteMeasure_embedding Ω)
/-- A characterization of weak convergence of probability measures by the condition that the
integrals of every continuous bounded nonnegative function converge to the integral of the function
against the limit measure. -/
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0,
Tendsto (fun i => ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds]
exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto
/-- The characterization of weak convergence of probability measures by the usual (defining)
condition that the integrals of every continuous bounded function converge to the integral of the
function against the limit measure. -/
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i => ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds]
rw [FiniteMeasure.tendsto_iff_forall_integral_tendsto]
rfl
end convergence_in_distribution -- section
section Hausdorff
variable [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [BorelSpace Ω]
variable (Ω)
/-- On topological spaces where indicators of closed sets have decreasing approximating sequences of
continuous functions (`HasOuterApproxClosed`), the topology of convergence in distribution of Borel
probability measures is Hausdorff (`T2Space`). -/
instance t2Space : T2Space (ProbabilityMeasure Ω) :=
Embedding.t2Space (toFiniteMeasure_embedding Ω)
end Hausdorff -- section
end ProbabilityMeasure
-- namespace
end ProbabilityMeasure
-- section
section NormalizeFiniteMeasure
/-! ### Normalization of finite measures to probability measures
This section is about normalizing finite measures to probability measures.
The weak convergence of finite measures to nonzero limit measures is characterized by
the convergence of the total mass and the convergence of the normalized probability
measures.
-/
namespace FiniteMeasure
variable {Ω : Type*} [Nonempty Ω] {m0 : MeasurableSpace Ω} (μ : FiniteMeasure Ω)
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
else
{ val := ↑(μ.mass⁻¹ • μ)
property := by
refine ⟨?_⟩
-- Porting note: paying the price that this isn't `simp` lemma now.
rw [FiniteMeasure.toMeasure_smul]
simp only [Measure.coe_smul, Pi.smul_apply, Measure.nnreal_smul_coe_apply, ne_eq,
mass_zero_iff, ENNReal.coe_inv zero, ennreal_mass]
rw [← Ne, ← ENNReal.coe_ne_zero, ennreal_mass] at zero
exact ENNReal.inv_mul_cancel zero μ.prop.measure_univ_lt_top.ne }
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
obtain rfl | h := eq_or_ne μ 0
· simp
have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
simp only [normalize, dif_neg mass_nonzero]
simp [ProbabilityMeasure.coe_mk, toMeasure_smul, mul_inv_cancel_left₀ mass_nonzero, coeFn_def]
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
apply eq_of_forall_apply_eq
intro s _s_mble
rw [μ.self_eq_mass_mul_normalize s, smul_apply, smul_eq_mul,
ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn]
theorem normalize_eq_of_nonzero (nonzero : μ ≠ 0) (s : Set Ω) : μ.normalize s = μ.mass⁻¹ * μ s := by
simp only [μ.self_eq_mass_mul_normalize, μ.mass_nonzero_iff.mpr nonzero, inv_mul_cancel_left₀,
Ne, not_false_iff]
theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) :
μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by
nth_rw 3 [μ.self_eq_mass_smul_normalize]
rw [← smul_assoc]
simp only [μ.mass_nonzero_iff.mpr nonzero, Algebra.id.smul_eq_mul, inv_mul_cancel, Ne,
not_false_iff, one_smul]
theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) :
(μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by
ext1 s _s_mble
rw [← μ.normalize.ennreal_coeFn_eq_coeFn_toMeasure s, μ.normalize_eq_of_nonzero nonzero s,
ENNReal.coe_mul, ennreal_coeFn_eq_coeFn_toMeasure]
exact Measure.coe_nnreal_smul_apply _ _ _
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
(μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
apply ProbabilityMeasure.eq_of_forall_apply_eq
intro s _s_mble
rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s]
simp only [ProbabilityMeasure.mass_toFiniteMeasure, inv_one, one_mul, μ.coeFn_toFiniteMeasure]
/-- Averaging with respect to a finite measure is the same as integrating against
`MeasureTheory.FiniteMeasure.normalize`. -/
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(nonzero : μ ≠ 0) (f : Ω → E) :
average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average]
congr
simp [ENNReal.coe_inv (μ.mass_nonzero_iff.mpr nonzero), ennreal_mass]
variable [TopologicalSpace Ω]
theorem testAgainstNN_eq_mass_mul (f : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN f = μ.mass * μ.normalize.toFiniteMeasure.testAgainstNN f := by
nth_rw 1 [μ.self_eq_mass_smul_normalize]
rw [μ.normalize.toFiniteMeasure.smul_testAgainstNN_apply μ.mass f, smul_eq_mul]
theorem normalize_testAgainstNN (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
μ.normalize.toFiniteMeasure.testAgainstNN f = μ.mass⁻¹ * μ.testAgainstNN f := by
simp [μ.testAgainstNN_eq_mass_mul, inv_mul_cancel_left₀ <| μ.mass_nonzero_iff.mpr nonzero]
variable [OpensMeasurableSpace Ω]
variable {μ}
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
{F : Filter γ} {μs : γ → FiniteMeasure Ω}
(μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
(mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
by_cases h_mass : μ.mass = 0
· simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
eq_self_iff_true] at *
exact tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
simp_rw [fun i => (μs i).testAgainstNN_eq_mass_mul f, μ.testAgainstNN_eq_mass_mul f]
rw [ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] at μs_lim
rw [tendsto_iff_forall_testAgainstNN_tendsto] at μs_lim
have lim_pair :
Tendsto (fun i => (⟨(μs i).mass, (μs i).normalize.toFiniteMeasure.testAgainstNN f⟩ : ℝ≥0 × ℝ≥0))
F (𝓝 ⟨μ.mass, μ.normalize.toFiniteMeasure.testAgainstNN f⟩) :=
(Prod.tendsto_iff _ _).mpr ⟨mass_lim, μs_lim f⟩
exact tendsto_mul.comp lim_pair
theorem tendsto_normalize_testAgainstNN_of_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (μs_lim : Tendsto μs F (𝓝 μ)) (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i => (μs i).normalize.toFiniteMeasure.testAgainstNN f) F
(𝓝 (μ.normalize.toFiniteMeasure.testAgainstNN f)) := by
have lim_mass := μs_lim.mass
have aux : {(0 : ℝ≥0)}ᶜ ∈ 𝓝 μ.mass :=
isOpen_compl_singleton.mem_nhds (μ.mass_nonzero_iff.mpr nonzero)
have eventually_nonzero : ∀ᶠ i in F, μs i ≠ 0 := by
simp_rw [← mass_nonzero_iff]
exact lim_mass aux
have eve : ∀ᶠ i in F,
(μs i).normalize.toFiniteMeasure.testAgainstNN f =
(μs i).mass⁻¹ * (μs i).testAgainstNN f := by
filter_upwards [eventually_iff.mp eventually_nonzero]
intro i hi
apply normalize_testAgainstNN _ hi
simp_rw [tendsto_congr' eve, μ.normalize_testAgainstNN nonzero]
have lim_pair :
Tendsto (fun i => (⟨(μs i).mass⁻¹, (μs i).testAgainstNN f⟩ : ℝ≥0 × ℝ≥0)) F
(𝓝 ⟨μ.mass⁻¹, μ.testAgainstNN f⟩) := by
refine (Prod.tendsto_iff _ _).mpr ⟨?_, ?_⟩
· exact (continuousOn_inv₀.continuousAt aux).tendsto.comp lim_mass
· exact tendsto_iff_forall_testAgainstNN_tendsto.mp μs_lim f
exact tendsto_mul.comp lim_pair
/-- If the normalized versions of finite measures converge weakly and their total masses
also converge, then the finite measures themselves converge weakly. -/
theorem tendsto_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
(mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) : Tendsto μs F (𝓝 μ) := by
rw [tendsto_iff_forall_testAgainstNN_tendsto]
exact fun f =>
tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass μs_lim mass_lim f
/-- If finite measures themselves converge weakly to a nonzero limit measure, then their
normalized versions also converge weakly. -/
theorem tendsto_normalize_of_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
(μs_lim : Tendsto μs F (𝓝 μ)) (nonzero : μ ≠ 0) :
Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize) := by
rw [ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds,
tendsto_iff_forall_testAgainstNN_tendsto]
exact fun f => tendsto_normalize_testAgainstNN_of_tendsto μs_lim nonzero f
/-- The weak convergence of finite measures to a nonzero limit can be characterized by the weak
convergence of both their normalized versions (probability measures) and their total masses. -/
theorem tendsto_normalize_iff_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
(nonzero : μ ≠ 0) :
Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize) ∧
Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass) ↔
Tendsto μs F (𝓝 μ) := by
constructor
· rintro ⟨normalized_lim, mass_lim⟩
exact tendsto_of_tendsto_normalize_testAgainstNN_of_tendsto_mass normalized_lim mass_lim
· intro μs_lim
exact ⟨tendsto_normalize_of_tendsto μs_lim nonzero, μs_lim.mass⟩
end FiniteMeasure --namespace
end NormalizeFiniteMeasure -- section
section map
variable {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω']
namespace ProbabilityMeasure
/-- The push-forward of a probability measure by a measurable function. -/
noncomputable def map (ν : ProbabilityMeasure Ω) {f : Ω → Ω'} (f_aemble : AEMeasurable f ν) :
ProbabilityMeasure Ω' :=
⟨(ν : Measure Ω).map f,
⟨by simp only [Measure.map_apply_of_aemeasurable f_aemble MeasurableSet.univ,
preimage_univ, measure_univ]⟩⟩
@[simp] lemma toMeasure_map (ν : ProbabilityMeasure Ω) {f : Ω → Ω'} (hf : AEMeasurable f ν) :
(ν.map hf).toMeasure = ν.toMeasure.map f := rfl
/-- Note that this is an equality of elements of `ℝ≥0∞`. See also
`MeasureTheory.ProbabilityMeasure.map_apply` for the corresponding equality as elements of `ℝ≥0`. -/
lemma map_apply' (ν : ProbabilityMeasure Ω) {f : Ω → Ω'} (f_aemble : AEMeasurable f ν)
{A : Set Ω'} (A_mble : MeasurableSet A) :
(ν.map f_aemble : Measure Ω') A = (ν : Measure Ω) (f ⁻¹' A) :=
Measure.map_apply_of_aemeasurable f_aemble A_mble
lemma map_apply_of_aemeasurable (ν : ProbabilityMeasure Ω) {f : Ω → Ω'}
(f_aemble : AEMeasurable f ν) {A : Set Ω'} (A_mble : MeasurableSet A) :
(ν.map f_aemble) A = ν (f ⁻¹' A) := by
have := ν.map_apply' f_aemble A_mble
exact (ENNReal.toNNReal_eq_toNNReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mpr this
lemma map_apply (ν : ProbabilityMeasure Ω) {f : Ω → Ω'} (f_aemble : AEMeasurable f ν)
{A : Set Ω'} (A_mble : MeasurableSet A) :
(ν.map f_aemble) A = ν (f ⁻¹' A) :=
map_apply_of_aemeasurable ν f_aemble A_mble
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
variable [TopologicalSpace Ω'] [BorelSpace Ω']
/-- If `f : X → Y` is continuous and `Y` is equipped with the Borel sigma algebra, then
convergence (in distribution) of `ProbabilityMeasure`s on `X` implies convergence (in
distribution) of the push-forwards of these measures by `f`. -/
lemma tendsto_map_of_tendsto_of_continuous {ι : Type*} {L : Filter ι}
(νs : ι → ProbabilityMeasure Ω) (ν : ProbabilityMeasure Ω) (lim : Tendsto νs L (𝓝 ν))
{f : Ω → Ω'} (f_cont : Continuous f) :
Tendsto (fun i ↦ (νs i).map f_cont.measurable.aemeasurable) L
(𝓝 (ν.map f_cont.measurable.aemeasurable)) := by
rw [ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto] at lim ⊢
intro g
convert lim (g.compContinuous ⟨f, f_cont⟩) <;>
· simp only [map, compContinuous_apply, ContinuousMap.coe_mk]
refine lintegral_map ?_ f_cont.measurable
exact (ENNReal.continuous_coe.comp g.continuous).measurable
/-- If `f : X → Y` is continuous and `Y` is equipped with the Borel sigma algebra, then
the push-forward of probability measures `f* : ProbabilityMeasure X → ProbabilityMeasure Y`
is continuous (in the topologies of convergence in distribution). -/
lemma continuous_map {f : Ω → Ω'} (f_cont : Continuous f) :
Continuous (fun ν ↦ ProbabilityMeasure.map ν f_cont.measurable.aemeasurable) := by
rw [continuous_iff_continuousAt]
exact fun _ ↦ tendsto_map_of_tendsto_of_continuous _ _ continuous_id.continuousAt f_cont
end ProbabilityMeasure -- namespace
end map -- section
end MeasureTheory -- namespace
|
MeasureTheory\Measure\Regular.lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris Van Doorn, Yury Kudryashov
-/
import Mathlib.Topology.MetricSpace.HausdorffDistance
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
/-!
# Regular measures
A measure is `OuterRegular` if the measure of any measurable set `A` is the infimum of `μ U` over
all open sets `U` containing `A`.
A measure is `WeaklyRegular` if it satisfies the following properties:
* it is outer regular;
* it is inner regular for open sets with respect to closed sets: the measure of any open set `U`
is the supremum of `μ F` over all closed sets `F` contained in `U`.
A measure is `Regular` if it satisfies the following properties:
* it is finite on compact sets;
* it is outer regular;
* it is inner regular for open sets with respect to compacts closed sets: the measure of any open
set `U` is the supremum of `μ K` over all compact sets `K` contained in `U`.
A measure is `InnerRegular` if it is inner regular for measurable sets with respect to compact
sets: the measure of any measurable set `s` is the supremum of `μ K` over all compact
sets contained in `s`.
A measure is `InnerRegularCompactLTTop` if it is inner regular for measurable sets of finite
measure with respect to compact sets: the measure of any measurable set `s` is the supremum
of `μ K` over all compact sets contained in `s`.
There is a reason for this zoo of regularity classes:
* A finite measure on a metric space is always weakly regular. Therefore, in probability theory,
weakly regular measures play a prominent role.
* In locally compact topological spaces, there are two competing notions of Radon measures: the
ones that are regular, and the ones that are inner regular. For any of these two notions, there is
a Riesz representation theorem, and an existence and uniqueness statement for the Haar measure in
locally compact topological groups. The two notions coincide in sigma-compact spaces, but they
differ in general, so it is worth having the two of them.
* Both notions of Haar measure satisfy the weaker notion `InnerRegularCompactLTTop`, so it is worth
trying to express theorems using this weaker notion whenever possible, to make sure that it
applies to both Haar measures simultaneously.
While traditional textbooks on measure theory on locally compact spaces emphasize regular measures,
more recent textbooks emphasize that inner regular Haar measures are better behaved than regular
Haar measures, so we will develop both notions.
The five conditions above are registered as typeclasses for a measure `μ`, and implications between
them are recorded as instances. For example, in a Hausdorff topological space, regularity implies
weak regularity. Also, regularity or inner regularity both imply `InnerRegularCompactLTTop`.
In a regular locally compact finite measure space, then regularity, inner regularity
and `InnerRegularCompactLTTop` are all equivalent.
In order to avoid code duplication, we also define a measure `μ` to be `InnerRegularWRT` for sets
satisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set
`U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ F`.
There are two main nontrivial results in the development below:
* `InnerRegularWRT.measurableSet_of_isOpen` shows that, for an outer regular measure, inner
regularity for open sets with respect to compact sets or closed sets implies inner regularity for
all measurable sets of finite measure (with respect to compact sets or closed sets respectively).
* `InnerRegularWRT.weaklyRegular_of_finite` shows that a finite measure which is inner regular for
open sets with respect to closed sets (for instance a finite measure on a metric space) is weakly
regular.
All other results are deduced from these ones.
Here is an example showing how regularity and inner regularity may differ even on locally compact
spaces. Consider the group `ℝ × ℝ` where the first factor has the discrete topology and the second
one the usual topology. It is a locally compact Hausdorff topological group, with Haar measure equal
to Lebesgue measure on each vertical fiber. Let us consider the regular version of Haar measure.
Then the set `ℝ × {0}` has infinite measure (by outer regularity), but any compact set it contains
has zero measure (as it is finite). In fact, this set only contains subset with measure zero or
infinity. The inner regular version of Haar measure, on the other hand, gives zero mass to the
set `ℝ × {0}`.
Another interesting example is the sum of the Dirac masses at rational points in the real line.
It is a σ-finite measure on a locally compact metric space, but it is not outer regular: for
outer regularity, one needs additional locally finite assumptions. On the other hand, it is
inner regular.
Several authors require both regularity and inner regularity for their measures. We have opted
for the more fine grained definitions above as they apply more generally.
## Main definitions
* `MeasureTheory.Measure.OuterRegular μ`: a typeclass registering that a measure `μ` on a
topological space is outer regular.
* `MeasureTheory.Measure.Regular μ`: a typeclass registering that a measure `μ` on a topological
space is regular.
* `MeasureTheory.Measure.WeaklyRegular μ`: a typeclass registering that a measure `μ` on a
topological space is weakly regular.
* `MeasureTheory.Measure.InnerRegularWRT μ p q`: a non-typeclass predicate saying that a measure `μ`
is inner regular for sets satisfying `q` with respect to sets satisfying `p`.
* `MeasureTheory.Measure.InnerRegular μ`: a typeclass registering that a measure `μ` on a
topological space is inner regular for measurable sets with respect to compact sets.
* `MeasureTheory.Measure.InnerRegularCompactLTTop μ`: a typeclass registering that a measure `μ`
on a topological space is inner regular for measurable sets of finite measure with respect to
compact sets.
## Main results
### Outer regular measures
* `Set.measure_eq_iInf_isOpen` asserts that, when `μ` is outer regular, the measure of a
set is the infimum of the measure of open sets containing it.
* `Set.exists_isOpen_lt_of_lt` asserts that, when `μ` is outer regular, for every set `s`
and `r > μ s` there exists an open superset `U ⊇ s` of measure less than `r`.
* push forward of an outer regular measure is outer regular, and scalar multiplication of a regular
measure by a finite number is outer regular.
### Weakly regular measures
* `IsOpen.measure_eq_iSup_isClosed` asserts that the measure of an open set is the supremum of
the measure of closed sets it contains.
* `IsOpen.exists_lt_isClosed`: for an open set `U` and `r < μ U`, there exists a closed `F ⊆ U`
of measure greater than `r`;
* `MeasurableSet.measure_eq_iSup_isClosed_of_ne_top` asserts that the measure of a measurable set
of finite measure is the supremum of the measure of closed sets it contains.
* `MeasurableSet.exists_lt_isClosed_of_ne_top` and `MeasurableSet.exists_isClosed_lt_add`:
a measurable set of finite measure can be approximated by a closed subset (stated as
`r < μ F` and `μ s < μ F + ε`, respectively).
* `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_of_isFiniteMeasure` is an
instance registering that a finite measure on a metric space is weakly regular (in fact, a pseudo
metrizable space is enough);
* `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_secondCountable_of_locallyFinite`
is an instance registering that a locally finite measure on a second countable metric space (or
even a pseudo metrizable space) is weakly regular.
### Regular measures
* `IsOpen.measure_eq_iSup_isCompact` asserts that the measure of an open set is the supremum of
the measure of compact sets it contains.
* `IsOpen.exists_lt_isCompact`: for an open set `U` and `r < μ U`, there exists a compact `K ⊆ U`
of measure greater than `r`;
* `MeasureTheory.Measure.Regular.of_sigmaCompactSpace_of_isLocallyFiniteMeasure` is an
instance registering that a locally finite measure on a `σ`-compact metric space is regular (in
fact, an emetric space is enough).
### Inner regular measures
* `MeasurableSet.measure_eq_iSup_isCompact` asserts that the measure of a measurable set is the
supremum of the measure of compact sets it contains.
* `MeasurableSet.exists_lt_isCompact`: for a measurable set `s` and `r < μ s`, there exists a
compact `K ⊆ s` of measure greater than `r`;
### Inner regular measures for finite measure sets with respect to compact sets
* `MeasurableSet.measure_eq_iSup_isCompact_of_ne_top` asserts that the measure of a measurable set
of finite measure is the supremum of the measure of compact sets it contains.
* `MeasurableSet.exists_lt_isCompact_of_ne_top` and `MeasurableSet.exists_isCompact_lt_add`:
a measurable set of finite measure can be approximated by a compact subset (stated as
`r < μ K` and `μ s < μ K + ε`, respectively).
## Implementation notes
The main nontrivial statement is `MeasureTheory.Measure.InnerRegular.weaklyRegular_of_finite`,
expressing that in a finite measure space, if every open set can be approximated from inside by
closed sets, then the measure is in fact weakly regular. To prove that we show that any measurable
set can be approximated from inside by closed sets and from outside by open sets. This statement is
proved by measurable induction, starting from open sets and checking that it is stable by taking
complements (this is the point of this condition, being symmetrical between inside and outside) and
countable disjoint unions.
Once this statement is proved, one deduces results for `σ`-finite measures from this statement, by
restricting them to finite measure sets (and proving that this restriction is weakly regular, using
again the same statement).
For non-Hausdorff spaces, one may argue whether the right condition for inner regularity is with
respect to compact sets, or to compact closed sets. For instance,
[Fremlin, *Measure Theory* (volume 4, 411J)][fremlin_vol4] considers measures which are inner
regular with respect to compact closed sets (and calls them *tight*). However, since most of the
literature uses mere compact sets, we have chosen to follow this convention. It doesn't make a
difference in Hausdorff spaces, of course. In locally compact topological groups, the two
conditions coincide, since if a compact set `k` is contained in a measurable set `u`, then the
closure of `k` is a compact closed set still contained in `u`, see
`IsCompact.closure_subset_of_measurableSet_of_group`.
## References
[Halmos, Measure Theory, §52][halmos1950measure]. Note that Halmos uses an unusual definition of
Borel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his
proofs or statements do not apply directly.
[Billingsley, Convergence of Probability Measures][billingsley1999]
[Bogachev, Measure Theory, volume 2, Theorem 7.11.1][bogachev2007]
-/
open Set Filter ENNReal NNReal TopologicalSpace
open scoped symmDiff Topology
namespace MeasureTheory
namespace Measure
/-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : Set α → Prop`,
if for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ U` satisfying `p K`
of measure greater than `r`.
This definition is used to prove some facts about regular and weakly regular measures without
repeating the proofs. -/
def InnerRegularWRT {α} {_ : MeasurableSpace α} (μ : Measure α) (p q : Set α → Prop) :=
∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K, K ⊆ U ∧ p K ∧ r < μ K
namespace InnerRegularWRT
variable {α : Type*} {m : MeasurableSpace α} {μ : Measure α} {p q : Set α → Prop} {U : Set α}
{ε : ℝ≥0∞}
theorem measure_eq_iSup (H : InnerRegularWRT μ p q) (hU : q U) :
μ U = ⨆ (K) (_ : K ⊆ U) (_ : p K), μ K := by
refine
le_antisymm (le_of_forall_lt fun r hr => ?_) (iSup₂_le fun K hK => iSup_le fun _ => μ.mono hK)
simpa only [lt_iSup_iff, exists_prop] using H hU r hr
theorem exists_subset_lt_add (H : InnerRegularWRT μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞)
(hε : ε ≠ 0) : ∃ K, K ⊆ U ∧ p K ∧ μ U < μ K + ε := by
rcases eq_or_ne (μ U) 0 with h₀ | h₀
· refine ⟨∅, empty_subset _, h0, ?_⟩
rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero]
· rcases H hU _ (ENNReal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩
exact ⟨K, hKU, hKc, ENNReal.lt_add_of_sub_lt_right (Or.inl hμU) hrK⟩
protected theorem map {α β} [MeasurableSpace α] [MeasurableSpace β]
{μ : Measure α} {pa qa : Set α → Prop}
(H : InnerRegularWRT μ pa qa) {f : α → β} (hf : AEMeasurable f μ) {pb qb : Set β → Prop}
(hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K))
(hB₂ : ∀ U, qb U → MeasurableSet U) :
InnerRegularWRT (map f μ) pb qb := by
intro U hU r hr
rw [map_apply_of_aemeasurable hf (hB₂ _ hU)] at hr
rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩
refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩
exact hK.trans_le (le_map_apply_image hf _)
theorem map' {α β} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α} {pa qa : Set α → Prop}
(H : InnerRegularWRT μ pa qa) (f : α ≃ᵐ β) {pb qb : Set β → Prop}
(hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K)) :
InnerRegularWRT (map f μ) pb qb := by
intro U hU r hr
rw [f.map_apply U] at hr
rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩
refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩
rwa [f.map_apply, f.preimage_image]
theorem smul (H : InnerRegularWRT μ p q) (c : ℝ≥0∞) : InnerRegularWRT (c • μ) p q := by
intro U hU r hr
rw [smul_apply, H.measure_eq_iSup hU, smul_eq_mul] at hr
simpa only [ENNReal.mul_iSup, lt_iSup_iff, exists_prop] using hr
theorem trans {q' : Set α → Prop} (H : InnerRegularWRT μ p q) (H' : InnerRegularWRT μ q q') :
InnerRegularWRT μ p q' := by
intro U hU r hr
rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩; rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩
exact ⟨K, hKF.trans hFU, hpK, hrK⟩
theorem rfl {p : Set α → Prop} : InnerRegularWRT μ p p :=
fun U hU _r hr ↦ ⟨U, Subset.rfl, hU, hr⟩
theorem of_imp (h : ∀ s, q s → p s) : InnerRegularWRT μ p q :=
fun U hU _ hr ↦ ⟨U, Subset.rfl, h U hU, hr⟩
theorem mono {p' q' : Set α → Prop} (H : InnerRegularWRT μ p q)
(h : ∀ s, q' s → q s) (h' : ∀ s, p s → p' s) : InnerRegularWRT μ p' q' :=
of_imp h' |>.trans H |>.trans (of_imp h)
end InnerRegularWRT
variable {α β : Type*} [MeasurableSpace α] {μ : Measure α}
section Classes
variable [TopologicalSpace α]
/-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ U open}` for a measurable set `A`.
This definition implies the same equality for any (not necessarily measurable) set, see
`Set.measure_eq_iInf_isOpen`. -/
class OuterRegular (μ : Measure α) : Prop where
protected outerRegular :
∀ ⦃A : Set α⦄, MeasurableSet A → ∀ r > μ A, ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r
/-- A measure `μ` is regular if
- it is finite on all compact sets;
- it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;
- it is inner regular for open sets, using compact sets:
`μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/
class Regular (μ : Measure α) extends IsFiniteMeasureOnCompacts μ, OuterRegular μ : Prop where
innerRegular : InnerRegularWRT μ IsCompact IsOpen
/-- A measure `μ` is weakly regular if
- it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;
- it is inner regular for open sets, using closed sets:
`μ(U) = sup {μ(F) | F ⊆ U closed}` for `U` open. -/
class WeaklyRegular (μ : Measure α) extends OuterRegular μ : Prop where
protected innerRegular : InnerRegularWRT μ IsClosed IsOpen
/-- A measure `μ` is inner regular if, for any measurable set `s`, then
`μ(s) = sup {μ(K) | K ⊆ s compact}`. -/
class InnerRegular (μ : Measure α) : Prop where
protected innerRegular : InnerRegularWRT μ IsCompact (fun s ↦ MeasurableSet s)
/-- A measure `μ` is inner regular for finite measure sets with respect to compact sets:
for any measurable set `s` with finite measure, then `μ(s) = sup {μ(K) | K ⊆ s compact}`.
The main interest of this class is that it is satisfied for both natural Haar measures (the
regular one and the inner regular one). -/
class InnerRegularCompactLTTop (μ : Measure α) : Prop where
protected innerRegular : InnerRegularWRT μ IsCompact (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)
-- see Note [lower instance priority]
/-- A regular measure is weakly regular in an R₁ space. -/
instance (priority := 100) Regular.weaklyRegular [R1Space α] [Regular μ] :
WeaklyRegular μ where
innerRegular := fun _U hU r hr ↦
let ⟨K, KU, K_comp, hK⟩ := Regular.innerRegular hU r hr
⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure,
hK.trans_le (measure_mono subset_closure)⟩
end Classes
namespace OuterRegular
variable [TopologicalSpace α]
instance zero : OuterRegular (0 : Measure α) :=
⟨fun A _ _r hr => ⟨univ, subset_univ A, isOpen_univ, hr⟩⟩
/-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with
measure less than `r`. -/
theorem _root_.Set.exists_isOpen_lt_of_lt [OuterRegular μ] (A : Set α) (r : ℝ≥0∞) (hr : μ A < r) :
∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r := by
rcases OuterRegular.outerRegular (measurableSet_toMeasurable μ A) r
(by rwa [measure_toMeasurable]) with
⟨U, hAU, hUo, hU⟩
exact ⟨U, (subset_toMeasurable _ _).trans hAU, hUo, hU⟩
/-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets
containing it. -/
theorem _root_.Set.measure_eq_iInf_isOpen (A : Set α) (μ : Measure α) [OuterRegular μ] :
μ A = ⨅ (U : Set α) (_ : A ⊆ U) (_ : IsOpen U), μ U := by
refine le_antisymm (le_iInf₂ fun s hs => le_iInf fun _ => μ.mono hs) ?_
refine le_of_forall_lt' fun r hr => ?_
simpa only [iInf_lt_iff, exists_prop] using A.exists_isOpen_lt_of_lt r hr
theorem _root_.Set.exists_isOpen_lt_add [OuterRegular μ] (A : Set α) (hA : μ A ≠ ∞) {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < μ A + ε :=
A.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hA hε)
theorem _root_.Set.exists_isOpen_le_add (A : Set α) (μ : Measure α) [OuterRegular μ] {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U ≤ μ A + ε := by
rcases eq_or_ne (μ A) ∞ with (H | H)
· exact ⟨univ, subset_univ _, isOpen_univ, by simp only [H, _root_.top_add, le_top]⟩
· rcases A.exists_isOpen_lt_add H hε with ⟨U, AU, U_open, hU⟩
exact ⟨U, AU, U_open, hU.le⟩
theorem _root_.MeasurableSet.exists_isOpen_diff_lt [OuterRegular μ] {A : Set α}
(hA : MeasurableSet A) (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < ∞ ∧ μ (U \ A) < ε := by
rcases A.exists_isOpen_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩
use U, hAU, hUo, hU.trans_le le_top
exact measure_diff_lt_of_lt_add hA hAU hA' hU
protected theorem map [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] (f : α ≃ₜ β) (μ : Measure α) [OuterRegular μ] :
(Measure.map f μ).OuterRegular := by
refine ⟨fun A hA r hr => ?_⟩
rw [map_apply f.measurable hA, ← f.image_symm] at hr
rcases Set.exists_isOpen_lt_of_lt _ r hr with ⟨U, hAU, hUo, hU⟩
have : IsOpen (f.symm ⁻¹' U) := hUo.preimage f.symm.continuous
refine ⟨f.symm ⁻¹' U, image_subset_iff.1 hAU, this, ?_⟩
rwa [map_apply f.measurable this.measurableSet, f.preimage_symm, f.preimage_image]
protected theorem smul (μ : Measure α) [OuterRegular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) :
(x • μ).OuterRegular := by
rcases eq_or_ne x 0 with (rfl | h0)
· rw [zero_smul]
exact OuterRegular.zero
· refine ⟨fun A _ r hr => ?_⟩
rw [smul_apply, A.measure_eq_iInf_isOpen, smul_eq_mul] at hr
simpa only [ENNReal.mul_iInf_of_ne h0 hx, gt_iff_lt, iInf_lt_iff, exists_prop] using hr
instance smul_nnreal (μ : Measure α) [OuterRegular μ] (c : ℝ≥0) :
OuterRegular (c • μ) :=
OuterRegular.smul μ coe_ne_top
/-- If the restrictions of a measure to countably many open sets covering the space are
outer regular, then the measure itself is outer regular. -/
lemma of_restrict [OpensMeasurableSpace α] {μ : Measure α} {s : ℕ → Set α}
(h : ∀ n, OuterRegular (μ.restrict (s n))) (h' : ∀ n, IsOpen (s n)) (h'' : univ ⊆ ⋃ n, s n) :
OuterRegular μ := by
refine ⟨fun A hA r hr => ?_⟩
have HA : μ A < ∞ := lt_of_lt_of_le hr le_top
have hm : ∀ n, MeasurableSet (s n) := fun n => (h' n).measurableSet
-- Note that `A = ⋃ n, A ∩ disjointed s n`. We replace `A` with this sequence.
obtain ⟨A, hAm, hAs, hAd, rfl⟩ :
∃ A' : ℕ → Set α,
(∀ n, MeasurableSet (A' n)) ∧
(∀ n, A' n ⊆ s n) ∧ Pairwise (Disjoint on A') ∧ A = ⋃ n, A' n := by
refine
⟨fun n => A ∩ disjointed s n, fun n => hA.inter (MeasurableSet.disjointed hm _), fun n =>
inter_subset_right.trans (disjointed_subset _ _),
(disjoint_disjointed s).mono fun k l hkl => hkl.mono inf_le_right inf_le_right, ?_⟩
rw [← inter_iUnion, iUnion_disjointed, univ_subset_iff.mp h'', inter_univ]
rcases ENNReal.exists_pos_sum_of_countable' (tsub_pos_iff_lt.2 hr).ne' ℕ with ⟨δ, δ0, hδε⟩
rw [lt_tsub_iff_right, add_comm] at hδε
have : ∀ n, ∃ U ⊇ A n, IsOpen U ∧ μ U < μ (A n) + δ n := by
intro n
have H₁ : ∀ t, μ.restrict (s n) t = μ (t ∩ s n) := fun t => restrict_apply' (hm n)
have Ht : μ.restrict (s n) (A n) ≠ ∞ := by
rw [H₁]
exact ((measure_mono (inter_subset_left.trans (subset_iUnion A n))).trans_lt HA).ne
rcases (A n).exists_isOpen_lt_add Ht (δ0 n).ne' with ⟨U, hAU, hUo, hU⟩
rw [H₁, H₁, inter_eq_self_of_subset_left (hAs _)] at hU
exact ⟨U ∩ s n, subset_inter hAU (hAs _), hUo.inter (h' n), hU⟩
choose U hAU hUo hU using this
refine ⟨⋃ n, U n, iUnion_mono hAU, isOpen_iUnion hUo, ?_⟩
calc
μ (⋃ n, U n) ≤ ∑' n, μ (U n) := measure_iUnion_le _
_ ≤ ∑' n, (μ (A n) + δ n) := ENNReal.tsum_le_tsum fun n => (hU n).le
_ = ∑' n, μ (A n) + ∑' n, δ n := ENNReal.tsum_add
_ = μ (⋃ n, A n) + ∑' n, δ n := (congr_arg₂ (· + ·) (measure_iUnion hAd hAm).symm rfl)
_ < r := hδε
/-- See also `IsCompact.measure_closure` for a version
that assumes the `σ`-algebra to be the Borel `σ`-algebra but makes no assumptions on `μ`. -/
lemma measure_closure_eq_of_isCompact [R1Space α] [OuterRegular μ]
{k : Set α} (hk : IsCompact k) : μ (closure k) = μ k := by
apply le_antisymm ?_ (measure_mono subset_closure)
simp only [measure_eq_iInf_isOpen k, le_iInf_iff]
intro u ku u_open
exact measure_mono (hk.closure_subset_of_isOpen u_open ku)
end OuterRegular
/-- If a measure `μ` admits finite spanning open sets such that the restriction of `μ` to each set
is outer regular, then the original measure is outer regular as well. -/
protected theorem FiniteSpanningSetsIn.outerRegular
[TopologicalSpace α] [OpensMeasurableSpace α] {μ : Measure α}
(s : μ.FiniteSpanningSetsIn { U | IsOpen U ∧ OuterRegular (μ.restrict U) }) :
OuterRegular μ :=
OuterRegular.of_restrict (s := fun n ↦ s.set n) (fun n ↦ (s.set_mem n).2)
(fun n ↦ (s.set_mem n).1) s.spanning.symm.subset
namespace InnerRegularWRT
variable {p q : Set α → Prop} {U s : Set α} {ε r : ℝ≥0∞}
/-- If the restrictions of a measure to a monotone sequence of sets covering the space are
inner regular for some property `p` and all measurable sets, then the measure itself is
inner regular. -/
lemma of_restrict {μ : Measure α} {s : ℕ → Set α}
(h : ∀ n, InnerRegularWRT (μ.restrict (s n)) p MeasurableSet)
(hs : univ ⊆ ⋃ n, s n) (hmono : Monotone s) : InnerRegularWRT μ p MeasurableSet := by
intro F hF r hr
have hBU : ⋃ n, F ∩ s n = F := by rw [← inter_iUnion, univ_subset_iff.mp hs, inter_univ]
have : μ F = ⨆ n, μ (F ∩ s n) := by
rw [← measure_iUnion_eq_iSup, hBU]
exact Monotone.directed_le fun m n h ↦ inter_subset_inter_right _ (hmono h)
rw [this] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
rw [← restrict_apply hF] at hn
rcases h n hF _ hn with ⟨K, KF, hKp, hK⟩
exact ⟨K, KF, hKp, hK.trans_le (restrict_apply_le _ _)⟩
/-- If `μ` is inner regular for measurable finite measure sets with respect to some class of sets,
then its restriction to any set is also inner regular for measurable finite measure sets, with
respect to the same class of sets. -/
lemma restrict (h : InnerRegularWRT μ p (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)) (A : Set α) :
InnerRegularWRT (μ.restrict A) p (fun s ↦ MeasurableSet s ∧ μ.restrict A s ≠ ∞) := by
rintro s ⟨s_meas, hs⟩ r hr
rw [restrict_apply s_meas] at hs
obtain ⟨K, K_subs, pK, rK⟩ : ∃ K, K ⊆ (toMeasurable μ (s ∩ A)) ∩ s ∧ p K ∧ r < μ K := by
have : r < μ ((toMeasurable μ (s ∩ A)) ∩ s) := by
apply hr.trans_le
rw [restrict_apply s_meas]
exact measure_mono <| subset_inter (subset_toMeasurable μ (s ∩ A)) inter_subset_left
refine h ⟨(measurableSet_toMeasurable _ _).inter s_meas, ?_⟩ _ this
apply (lt_of_le_of_lt _ hs.lt_top).ne
rw [← measure_toMeasurable (s ∩ A)]
exact measure_mono inter_subset_left
refine ⟨K, K_subs.trans inter_subset_right, pK, ?_⟩
calc
r < μ K := rK
_ = μ.restrict (toMeasurable μ (s ∩ A)) K := by
rw [restrict_apply' (measurableSet_toMeasurable μ (s ∩ A))]
congr
apply (inter_eq_left.2 ?_).symm
exact K_subs.trans inter_subset_left
_ = μ.restrict (s ∩ A) K := by rwa [restrict_toMeasurable]
_ ≤ μ.restrict A K := Measure.le_iff'.1 (restrict_mono inter_subset_right le_rfl) K
/-- If `μ` is inner regular for measurable finite measure sets with respect to some class of sets,
then its restriction to any finite measure set is also inner regular for measurable sets with
respect to the same class of sets. -/
lemma restrict_of_measure_ne_top (h : InnerRegularWRT μ p (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞))
{A : Set α} (hA : μ A ≠ ∞) :
InnerRegularWRT (μ.restrict A) p (fun s ↦ MeasurableSet s) := by
have : Fact (μ A < ∞) := ⟨hA.lt_top⟩
exact (restrict h A).trans (of_imp (fun s hs ↦ ⟨hs, measure_ne_top _ _⟩))
/-- Given a σ-finite measure, any measurable set can be approximated from inside by a measurable
set of finite measure. -/
lemma of_sigmaFinite [SigmaFinite μ] :
InnerRegularWRT μ (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞) (fun s ↦ MeasurableSet s) := by
intro s hs r hr
set B : ℕ → Set α := spanningSets μ
have hBU : ⋃ n, s ∩ B n = s := by rw [← inter_iUnion, iUnion_spanningSets, inter_univ]
have : μ s = ⨆ n, μ (s ∩ B n) := by
rw [← measure_iUnion_eq_iSup, hBU]
exact Monotone.directed_le fun m n h => inter_subset_inter_right _ (monotone_spanningSets μ h)
rw [this] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
refine ⟨s ∩ B n, inter_subset_left, ⟨hs.inter (measurable_spanningSets μ n), ?_⟩, hn⟩
exact ((measure_mono inter_subset_right).trans_lt (measure_spanningSets_lt_top μ n)).ne
variable [TopologicalSpace α]
/-- If a measure is inner regular (using closed or compact sets) for open sets, then every
measurable set of finite measure can be approximated by a (closed or compact) subset. -/
theorem measurableSet_of_isOpen [OuterRegular μ] (H : InnerRegularWRT μ p IsOpen)
(hd : ∀ ⦃s U⦄, p s → IsOpen U → p (s \ U)) :
InnerRegularWRT μ p fun s => MeasurableSet s ∧ μ s ≠ ∞ := by
rintro s ⟨hs, hμs⟩ r hr
have h0 : p ∅ := by
have : 0 < μ univ := (bot_le.trans_lt hr).trans_le (measure_mono (subset_univ _))
obtain ⟨K, -, hK, -⟩ : ∃ K, K ⊆ univ ∧ p K ∧ 0 < μ K := H isOpen_univ _ this
simpa using hd hK isOpen_univ
obtain ⟨ε, hε, hεs, rfl⟩ : ∃ ε ≠ 0, ε + ε ≤ μ s ∧ r = μ s - (ε + ε) := by
use (μ s - r) / 2
simp [*, hr.le, ENNReal.add_halves, ENNReal.sub_sub_cancel, le_add_right, tsub_eq_zero_iff_le]
rcases hs.exists_isOpen_diff_lt hμs hε with ⟨U, hsU, hUo, hUt, hμU⟩
rcases (U \ s).exists_isOpen_lt_of_lt _ hμU with ⟨U', hsU', hU'o, hμU'⟩
replace hsU' := diff_subset_comm.1 hsU'
rcases H.exists_subset_lt_add h0 hUo hUt.ne hε with ⟨K, hKU, hKc, hKr⟩
refine ⟨K \ U', fun x hx => hsU' ⟨hKU hx.1, hx.2⟩, hd hKc hU'o, ENNReal.sub_lt_of_lt_add hεs ?_⟩
calc
μ s ≤ μ U := μ.mono hsU
_ < μ K + ε := hKr
_ ≤ μ (K \ U') + μ U' + ε := add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _
_ ≤ μ (K \ U') + ε + ε := by gcongr
_ = μ (K \ U') + (ε + ε) := add_assoc _ _ _
open Finset in
/-- In a finite measure space, assume that any open set can be approximated from inside by closed
sets. Then the measure is weakly regular. -/
theorem weaklyRegular_of_finite [BorelSpace α] (μ : Measure α) [IsFiniteMeasure μ]
(H : InnerRegularWRT μ IsClosed IsOpen) : WeaklyRegular μ := by
have hfin : ∀ {s}, μ s ≠ ∞ := @(measure_ne_top μ)
suffices ∀ s, MeasurableSet s → ∀ ε, ε ≠ 0 → ∃ F, F ⊆ s ∧ ∃ U, U ⊇ s ∧
IsClosed F ∧ IsOpen U ∧ μ s ≤ μ F + ε ∧ μ U ≤ μ s + ε by
refine
{ outerRegular := fun s hs r hr => ?_
innerRegular := H }
rcases exists_between hr with ⟨r', hsr', hr'r⟩
rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with ⟨-, -, U, hsU, -, hUo, -, H⟩
refine ⟨U, hsU, hUo, ?_⟩
rw [add_tsub_cancel_of_le hsr'.le] at H
exact H.trans_lt hr'r
apply MeasurableSet.induction_on_open
/- The proof is by measurable induction: we should check that the property is true for the empty
set, for open sets, and is stable by taking the complement and by taking countable disjoint
unions. The point of the property we are proving is that it is stable by taking complements
(exchanging the roles of closed and open sets and thanks to the finiteness of the measure). -/
-- check for open set
· intro U hU ε hε
rcases H.exists_subset_lt_add isClosed_empty hU hfin hε with ⟨F, hsF, hFc, hF⟩
exact ⟨F, hsF, U, Subset.rfl, hFc, hU, hF.le, le_self_add⟩
-- check for complements
· rintro s hs H ε hε
rcases H ε hε with ⟨F, hFs, U, hsU, hFc, hUo, hF, hU⟩
refine
⟨Uᶜ, compl_subset_compl.2 hsU, Fᶜ, compl_subset_compl.2 hFs, hUo.isClosed_compl,
hFc.isOpen_compl, ?_⟩
simp only [measure_compl_le_add_iff, *, hUo.measurableSet, hFc.measurableSet, true_and_iff]
-- check for disjoint unions
· intro s hsd hsm H ε ε0
have ε0' : ε / 2 ≠ 0 := (ENNReal.half_pos ε0).ne'
rcases ENNReal.exists_pos_sum_of_countable' ε0' ℕ with ⟨δ, δ0, hδε⟩
choose F hFs U hsU hFc hUo hF hU using fun n => H n (δ n) (δ0 n).ne'
-- the approximating closed set is constructed by considering finitely many sets `s i`, which
-- cover all the measure up to `ε/2`, approximating each of these by a closed set `F i`, and
-- taking the union of these (finitely many) `F i`.
have : Tendsto (fun t => (∑ k ∈ t, μ (s k)) + ε / 2) atTop (𝓝 <| μ (⋃ n, s n) + ε / 2) := by
rw [measure_iUnion hsd hsm]
exact Tendsto.add ENNReal.summable.hasSum tendsto_const_nhds
rcases (this.eventually <| lt_mem_nhds <| ENNReal.lt_add_right hfin ε0').exists with ⟨t, ht⟩
-- the approximating open set is constructed by taking for each `s n` an approximating open set
-- `U n` with measure at most `μ (s n) + δ n` for a summable `δ`, and taking the union of these.
refine
⟨⋃ k ∈ t, F k, iUnion_mono fun k => iUnion_subset fun _ => hFs _, ⋃ n, U n, iUnion_mono hsU,
isClosed_biUnion_finset fun k _ => hFc k, isOpen_iUnion hUo, ht.le.trans ?_, ?_⟩
· calc
(∑ k ∈ t, μ (s k)) + ε / 2 ≤ ((∑ k ∈ t, μ (F k)) + ∑ k ∈ t, δ k) + ε / 2 := by
rw [← sum_add_distrib]
gcongr
apply hF
_ ≤ (∑ k ∈ t, μ (F k)) + ε / 2 + ε / 2 := by
gcongr
exact (ENNReal.sum_le_tsum _).trans hδε.le
_ = μ (⋃ k ∈ t, F k) + ε := by
rw [measure_biUnion_finset, add_assoc, ENNReal.add_halves]
exacts [fun k _ n _ hkn => (hsd hkn).mono (hFs k) (hFs n),
fun k _ => (hFc k).measurableSet]
· calc
μ (⋃ n, U n) ≤ ∑' n, μ (U n) := measure_iUnion_le _
_ ≤ ∑' n, (μ (s n) + δ n) := ENNReal.tsum_le_tsum hU
_ = μ (⋃ n, s n) + ∑' n, δ n := by rw [measure_iUnion hsd hsm, ENNReal.tsum_add]
_ ≤ μ (⋃ n, s n) + ε := add_le_add_left (hδε.le.trans ENNReal.half_le_self) _
/-- In a metrizable space (or even a pseudo metrizable space), an open set can be approximated from
inside by closed sets. -/
theorem of_pseudoMetrizableSpace {X : Type*} [TopologicalSpace X] [PseudoMetrizableSpace X]
[MeasurableSpace X] (μ : Measure X) : InnerRegularWRT μ IsClosed IsOpen := by
let A : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X
intro U hU r hr
rcases hU.exists_iUnion_isClosed with ⟨F, F_closed, -, rfl, F_mono⟩
rw [measure_iUnion_eq_iSup F_mono.directed_le] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
exact ⟨F n, subset_iUnion _ _, F_closed n, hn⟩
/-- In a `σ`-compact space, any closed set can be approximated by a compact subset. -/
theorem isCompact_isClosed {X : Type*} [TopologicalSpace X] [SigmaCompactSpace X]
[MeasurableSpace X] (μ : Measure X) : InnerRegularWRT μ IsCompact IsClosed := by
intro F hF r hr
set B : ℕ → Set X := compactCovering X
have hBc : ∀ n, IsCompact (F ∩ B n) := fun n => (isCompact_compactCovering X n).inter_left hF
have hBU : ⋃ n, F ∩ B n = F := by rw [← inter_iUnion, iUnion_compactCovering, Set.inter_univ]
have : μ F = ⨆ n, μ (F ∩ B n) := by
rw [← measure_iUnion_eq_iSup, hBU]
exact Monotone.directed_le fun m n h => inter_subset_inter_right _ (compactCovering_subset _ h)
rw [this] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
exact ⟨_, inter_subset_left, hBc n, hn⟩
end InnerRegularWRT
namespace InnerRegular
variable {U : Set α} {ε : ℝ≥0∞} [TopologicalSpace α]
/-- The measure of a measurable set is the supremum of the measures of compact sets it contains. -/
theorem _root_.MeasurableSet.measure_eq_iSup_isCompact ⦃U : Set α⦄ (hU : MeasurableSet U)
(μ : Measure α) [InnerRegular μ] :
μ U = ⨆ (K : Set α) (_ : K ⊆ U) (_ : IsCompact K), μ K :=
InnerRegular.innerRegular.measure_eq_iSup hU
instance zero : InnerRegular (0 : Measure α) :=
⟨fun _ _ _r hr => ⟨∅, empty_subset _, isCompact_empty, hr⟩⟩
instance smul [h : InnerRegular μ] (c : ℝ≥0∞) : InnerRegular (c • μ) :=
⟨InnerRegularWRT.smul h.innerRegular c⟩
instance smul_nnreal [InnerRegular μ] (c : ℝ≥0) : InnerRegular (c • μ) := smul (c : ℝ≥0∞)
instance (priority := 100) [InnerRegular μ] : InnerRegularCompactLTTop μ :=
⟨fun _s hs r hr ↦ InnerRegular.innerRegular hs.1 r hr⟩
lemma innerRegularWRT_isClosed_isOpen [R1Space α] [OpensMeasurableSpace α] [h : InnerRegular μ] :
InnerRegularWRT μ IsClosed IsOpen := by
intro U hU r hr
rcases h.innerRegular hU.measurableSet r hr with ⟨K, KU, K_comp, hK⟩
exact ⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure,
hK.trans_le (measure_mono subset_closure)⟩
theorem exists_compact_not_null [InnerRegular μ] : (∃ K, IsCompact K ∧ μ K ≠ 0) ↔ μ ≠ 0 := by
simp_rw [Ne, ← measure_univ_eq_zero, MeasurableSet.univ.measure_eq_iSup_isCompact,
ENNReal.iSup_eq_zero, not_forall, exists_prop, subset_univ, true_and_iff]
/-- If `μ` is inner regular, then any measurable set can be approximated by a compact subset.
See also `MeasurableSet.exists_isCompact_lt_add_of_ne_top`. -/
theorem _root_.MeasurableSet.exists_lt_isCompact [InnerRegular μ] ⦃A : Set α⦄
(hA : MeasurableSet A) {r : ℝ≥0∞} (hr : r < μ A) :
∃ K, K ⊆ A ∧ IsCompact K ∧ r < μ K :=
InnerRegular.innerRegular hA _ hr
protected theorem map_of_continuous [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [h : InnerRegular μ] {f : α → β} (hf : Continuous f) :
InnerRegular (Measure.map f μ) :=
⟨InnerRegularWRT.map h.innerRegular hf.aemeasurable (fun _s hs ↦ hf.measurable hs)
(fun _K hK ↦ hK.image hf) (fun _s hs ↦ hs)⟩
protected theorem map [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [InnerRegular μ] (f : α ≃ₜ β) : (Measure.map f μ).InnerRegular :=
InnerRegular.map_of_continuous f.continuous
protected theorem map_iff [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] (f : α ≃ₜ β) :
InnerRegular (Measure.map f μ) ↔ InnerRegular μ := by
refine ⟨fun h ↦ ?_, fun h ↦ h.map f⟩
convert h.map f.symm
rw [map_map f.symm.continuous.measurable f.continuous.measurable]
simp
end InnerRegular
namespace InnerRegularCompactLTTop
variable [TopologicalSpace α]
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_lt_isCompact_of_ne_top`. -/
theorem _root_.MeasurableSet.exists_isCompact_lt_add [InnerRegularCompactLTTop μ]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ μ A < μ K + ε :=
InnerRegularCompactLTTop.innerRegular.exists_subset_lt_add isCompact_empty ⟨hA, h'A⟩ h'A hε
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a compact closed subset.
Compared to `MeasurableSet.exists_isCompact_lt_add`,
this version additionally assumes that `α` is an R₁ space with Borel σ-algebra.
-/
theorem _root_.MeasurableSet.exists_isCompact_isClosed_lt_add
[InnerRegularCompactLTTop μ] [R1Space α] [BorelSpace α]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ IsClosed K ∧ μ A < μ K + ε :=
let ⟨K, hKA, hK, hμK⟩ := hA.exists_isCompact_lt_add h'A hε
⟨closure K, hK.closure_subset_measurableSet hA hKA, hK.closure, isClosed_closure,
by rwa [hK.measure_closure]⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_isCompact_lt_add` and
`MeasurableSet.exists_lt_isCompact_of_ne_top`. -/
theorem _root_.MeasurableSet.exists_isCompact_diff_lt [OpensMeasurableSpace α] [T2Space α]
[InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ μ (A \ K) < ε := by
rcases hA.exists_isCompact_lt_add h'A hε with ⟨K, hKA, hKc, hK⟩
exact ⟨K, hKA, hKc, measure_diff_lt_of_lt_add hKc.measurableSet hKA
(ne_top_of_le_ne_top h'A <| measure_mono hKA) hK⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a compact closed subset.
Compared to `MeasurableSet.exists_isCompact_diff_lt`,
this lemma additionally assumes that `α` is an R₁ space with Borel σ-algebra. -/
theorem _root_.MeasurableSet.exists_isCompact_isClosed_diff_lt [BorelSpace α] [R1Space α]
[InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ IsClosed K ∧ μ (A \ K) < ε := by
rcases hA.exists_isCompact_isClosed_lt_add h'A hε with ⟨K, hKA, hKco, hKcl, hK⟩
exact ⟨K, hKA, hKco, hKcl, measure_diff_lt_of_lt_add hKcl.measurableSet hKA
(ne_top_of_le_ne_top h'A <| measure_mono hKA) hK⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_isCompact_lt_add`. -/
theorem _root_.MeasurableSet.exists_lt_isCompact_of_ne_top [InnerRegularCompactLTTop μ] ⦃A : Set α⦄
(hA : MeasurableSet A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) :
∃ K, K ⊆ A ∧ IsCompact K ∧ r < μ K :=
InnerRegularCompactLTTop.innerRegular ⟨hA, h'A⟩ _ hr
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
any measurable set of finite mass can be approximated from inside by compact sets. -/
theorem _root_.MeasurableSet.measure_eq_iSup_isCompact_of_ne_top [InnerRegularCompactLTTop μ]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) :
μ A = ⨆ (K) (_ : K ⊆ A) (_ : IsCompact K), μ K :=
InnerRegularCompactLTTop.innerRegular.measure_eq_iSup ⟨hA, h'A⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets, then its
restriction to any set also is. -/
instance restrict [h : InnerRegularCompactLTTop μ] (A : Set α) :
InnerRegularCompactLTTop (μ.restrict A) :=
⟨InnerRegularWRT.restrict h.innerRegular A⟩
instance (priority := 50) [h : InnerRegularCompactLTTop μ] [IsFiniteMeasure μ] :
InnerRegular μ := by
constructor
convert h.innerRegular with s
simp [measure_ne_top μ s]
instance (priority := 50) [BorelSpace α] [R1Space α] [InnerRegularCompactLTTop μ]
[IsFiniteMeasure μ] : WeaklyRegular μ :=
InnerRegular.innerRegularWRT_isClosed_isOpen.weaklyRegular_of_finite _
instance (priority := 50) [BorelSpace α] [R1Space α] [h : InnerRegularCompactLTTop μ]
[IsFiniteMeasure μ] : Regular μ where
innerRegular := InnerRegularWRT.trans h.innerRegular <|
InnerRegularWRT.of_imp (fun U hU ↦ ⟨hU.measurableSet, measure_ne_top μ U⟩)
protected lemma _root_.IsCompact.exists_isOpen_lt_of_lt [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α}
(hK : IsCompact K) (r : ℝ≥0∞) (hr : μ K < r) :
∃ U, K ⊆ U ∧ IsOpen U ∧ μ U < r := by
rcases hK.exists_open_superset_measure_lt_top μ with ⟨V, hKV, hVo, hμV⟩
have := Fact.mk hμV
obtain ⟨U, hKU, hUo, hμU⟩ : ∃ U, K ⊆ U ∧ IsOpen U ∧ μ.restrict V U < r :=
exists_isOpen_lt_of_lt K r <| (restrict_apply_le _ _).trans_lt hr
refine ⟨U ∩ V, subset_inter hKU hKV, hUo.inter hVo, ?_⟩
rwa [restrict_apply hUo.measurableSet] at hμU
/-- If `μ` is inner regular for finite measure sets with respect to compact sets
and is locally finite in an R₁ space,
then any compact set can be approximated from outside by open sets. -/
protected lemma _root_.IsCompact.measure_eq_iInf_isOpen [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α} (hK : IsCompact K) :
μ K = ⨅ (U : Set α) (_ : K ⊆ U) (_ : IsOpen U), μ U := by
apply le_antisymm
· simp only [le_iInf_iff]
exact fun U KU _ ↦ measure_mono KU
· apply le_of_forall_lt'
simpa only [iInf_lt_iff, exists_prop, exists_and_left] using hK.exists_isOpen_lt_of_lt
@[deprecated (since := "2024-01-28")]
alias _root_.IsCompact.measure_eq_infi_isOpen := IsCompact.measure_eq_iInf_isOpen
protected theorem _root_.IsCompact.exists_isOpen_lt_add [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α]
{K : Set α} (hK : IsCompact K) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, K ⊆ U ∧ IsOpen U ∧ μ U < μ K + ε :=
hK.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hK.measure_lt_top.ne hε)
/-- Let `μ` be a locally finite measure on an R₁ topological space with Borel σ-algebra.
If `μ` is inner regular for finite measure sets with respect to compact sets,
then any finite measurable set can be approximated in measure by an open set.
See also `Set.exists_isOpen_lt_of_lt` and `MeasurableSet.exists_isOpen_diff_lt`
for the case of an outer regular measure. -/
protected theorem _root_.MeasurableSet.exists_isOpen_symmDiff_lt [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α]
{s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, IsOpen U ∧ μ U < ∞ ∧ μ (U ∆ s) < ε := by
have : ε / 2 ≠ 0 := (ENNReal.half_pos hε).ne'
rcases hs.exists_isCompact_isClosed_diff_lt hμs this with ⟨K, hKs, hKco, hKcl, hμK⟩
rcases hKco.exists_isOpen_lt_add (μ := μ) this with ⟨U, hKU, hUo, hμU⟩
refine ⟨U, hUo, hμU.trans_le le_top, ?_⟩
rw [← ENNReal.add_halves ε, measure_symmDiff_eq hUo.measurableSet hs]
gcongr
· calc
μ (U \ s) ≤ μ (U \ K) := by gcongr
_ < ε / 2 := by
apply measure_diff_lt_of_lt_add hKcl.measurableSet hKU _ hμU
exact ne_top_of_le_ne_top hμs (by gcongr)
· exact lt_of_le_of_lt (by gcongr) hμK
instance smul [h : InnerRegularCompactLTTop μ] (c : ℝ≥0∞) : InnerRegularCompactLTTop (c • μ) := by
by_cases hc : c = 0
· simp only [hc, zero_smul]
infer_instance
by_cases h'c : c = ∞
· constructor
intro s hs r hr
simp only [h'c, smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply, smul_eq_mul] at hr
by_cases h's : μ s = 0
· simp [h's] at hr
· simp [h'c, ENNReal.mul_eq_top, h's] at hs
· constructor
convert InnerRegularWRT.smul h.innerRegular c using 2 with s
have : (c • μ) s ≠ ∞ ↔ μ s ≠ ∞ := by simp [not_iff_not, ENNReal.mul_eq_top, hc, h'c]
simp only [this]
instance smul_nnreal [InnerRegularCompactLTTop μ] (c : ℝ≥0) :
InnerRegularCompactLTTop (c • μ) :=
inferInstanceAs (InnerRegularCompactLTTop ((c : ℝ≥0∞) • μ))
instance (priority := 80) [InnerRegularCompactLTTop μ] [SigmaFinite μ] : InnerRegular μ :=
⟨InnerRegularCompactLTTop.innerRegular.trans InnerRegularWRT.of_sigmaFinite⟩
protected theorem map_of_continuous [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [h : InnerRegularCompactLTTop μ] {f : α → β} (hf : Continuous f) :
InnerRegularCompactLTTop (Measure.map f μ) := by
constructor
refine InnerRegularWRT.map h.innerRegular hf.aemeasurable ?_ (fun K hK ↦ hK.image hf) ?_
· rintro s ⟨hs, h's⟩
exact ⟨hf.measurable hs, by rwa [map_apply hf.measurable hs] at h's⟩
· rintro s ⟨hs, -⟩
exact hs
end InnerRegularCompactLTTop
-- Generalized and moved to another file
namespace WeaklyRegular
variable [TopologicalSpace α]
instance zero : WeaklyRegular (0 : Measure α) :=
⟨fun _ _ _r hr => ⟨∅, empty_subset _, isClosed_empty, hr⟩⟩
/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/
theorem _root_.IsOpen.exists_lt_isClosed [WeaklyRegular μ] ⦃U : Set α⦄ (hU : IsOpen U) {r : ℝ≥0∞}
(hr : r < μ U) : ∃ F, F ⊆ U ∧ IsClosed F ∧ r < μ F :=
WeaklyRegular.innerRegular hU r hr
/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/
theorem _root_.IsOpen.measure_eq_iSup_isClosed ⦃U : Set α⦄ (hU : IsOpen U) (μ : Measure α)
[WeaklyRegular μ] : μ U = ⨆ (F) (_ : F ⊆ U) (_ : IsClosed F), μ F :=
WeaklyRegular.innerRegular.measure_eq_iSup hU
theorem innerRegular_measurable [WeaklyRegular μ] :
InnerRegularWRT μ IsClosed fun s => MeasurableSet s ∧ μ s ≠ ∞ :=
WeaklyRegular.innerRegular.measurableSet_of_isOpen (fun _ _ h₁ h₂ ↦ h₁.inter h₂.isClosed_compl)
/-- If `s` is a measurable set, a weakly regular measure `μ` is finite on `s`, and `ε` is a positive
number, then there exist a closed set `K ⊆ s` such that `μ s < μ K + ε`. -/
theorem _root_.MeasurableSet.exists_isClosed_lt_add [WeaklyRegular μ] {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ s ∧ IsClosed K ∧ μ s < μ K + ε :=
innerRegular_measurable.exists_subset_lt_add isClosed_empty ⟨hs, hμs⟩ hμs hε
theorem _root_.MeasurableSet.exists_isClosed_diff_lt [OpensMeasurableSpace α] [WeaklyRegular μ]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ F, F ⊆ A ∧ IsClosed F ∧ μ (A \ F) < ε := by
rcases hA.exists_isClosed_lt_add h'A hε with ⟨F, hFA, hFc, hF⟩
exact ⟨F, hFA, hFc, measure_diff_lt_of_lt_add hFc.measurableSet hFA
(ne_top_of_le_ne_top h'A <| measure_mono hFA) hF⟩
/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from
inside by closed sets. -/
theorem _root_.MeasurableSet.exists_lt_isClosed_of_ne_top [WeaklyRegular μ] ⦃A : Set α⦄
(hA : MeasurableSet A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) :
∃ K, K ⊆ A ∧ IsClosed K ∧ r < μ K :=
innerRegular_measurable ⟨hA, h'A⟩ _ hr
/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from
inside by closed sets. -/
theorem _root_.MeasurableSet.measure_eq_iSup_isClosed_of_ne_top [WeaklyRegular μ] ⦃A : Set α⦄
(hA : MeasurableSet A) (h'A : μ A ≠ ∞) : μ A = ⨆ (K) (_ : K ⊆ A) (_ : IsClosed K), μ K :=
innerRegular_measurable.measure_eq_iSup ⟨hA, h'A⟩
/-- The restriction of a weakly regular measure to a measurable set of finite measure is
weakly regular. -/
theorem restrict_of_measure_ne_top [BorelSpace α] [WeaklyRegular μ] {A : Set α}
(h'A : μ A ≠ ∞) : WeaklyRegular (μ.restrict A) := by
haveI : Fact (μ A < ∞) := ⟨h'A.lt_top⟩
refine InnerRegularWRT.weaklyRegular_of_finite (μ.restrict A) (fun V V_open r hr ↦ ?_)
have : InnerRegularWRT (μ.restrict A) IsClosed (fun s ↦ MeasurableSet s) :=
InnerRegularWRT.restrict_of_measure_ne_top innerRegular_measurable h'A
exact this V_open.measurableSet r hr
-- see Note [lower instance priority]
/-- Any finite measure on a metrizable space (or even a pseudo metrizable space)
is weakly regular. -/
instance (priority := 100) of_pseudoMetrizableSpace_of_isFiniteMeasure {X : Type*}
[TopologicalSpace X] [PseudoMetrizableSpace X] [MeasurableSpace X] [BorelSpace X]
(μ : Measure X) [IsFiniteMeasure μ] :
WeaklyRegular μ :=
(InnerRegularWRT.of_pseudoMetrizableSpace μ).weaklyRegular_of_finite μ
-- see Note [lower instance priority]
/-- Any locally finite measure on a second countable metrizable space
(or even a pseudo metrizable space) is weakly regular. -/
instance (priority := 100) of_pseudoMetrizableSpace_secondCountable_of_locallyFinite {X : Type*}
[TopologicalSpace X] [PseudoMetrizableSpace X] [SecondCountableTopology X] [MeasurableSpace X]
[BorelSpace X] (μ : Measure X) [IsLocallyFiniteMeasure μ] : WeaklyRegular μ :=
have : OuterRegular μ := by
refine (μ.finiteSpanningSetsInOpen'.mono' fun U hU => ?_).outerRegular
have : Fact (μ U < ∞) := ⟨hU.2⟩
exact ⟨hU.1, inferInstance⟩
⟨InnerRegularWRT.of_pseudoMetrizableSpace μ⟩
protected theorem smul [WeaklyRegular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) : (x • μ).WeaklyRegular := by
haveI := OuterRegular.smul μ hx
exact ⟨WeaklyRegular.innerRegular.smul x⟩
instance smul_nnreal [WeaklyRegular μ] (c : ℝ≥0) : WeaklyRegular (c • μ) :=
WeaklyRegular.smul coe_ne_top
end WeaklyRegular
namespace Regular
variable [TopologicalSpace α]
instance zero : Regular (0 : Measure α) :=
⟨fun _ _ _r hr => ⟨∅, empty_subset _, isCompact_empty, hr⟩⟩
/-- If `μ` is a regular measure, then any open set can be approximated by a compact subset. -/
theorem _root_.IsOpen.exists_lt_isCompact [Regular μ] ⦃U : Set α⦄ (hU : IsOpen U) {r : ℝ≥0∞}
(hr : r < μ U) : ∃ K, K ⊆ U ∧ IsCompact K ∧ r < μ K :=
Regular.innerRegular hU r hr
/-- The measure of an open set is the supremum of the measures of compact sets it contains. -/
theorem _root_.IsOpen.measure_eq_iSup_isCompact ⦃U : Set α⦄ (hU : IsOpen U) (μ : Measure α)
[Regular μ] : μ U = ⨆ (K : Set α) (_ : K ⊆ U) (_ : IsCompact K), μ K :=
Regular.innerRegular.measure_eq_iSup hU
theorem exists_compact_not_null [Regular μ] : (∃ K, IsCompact K ∧ μ K ≠ 0) ↔ μ ≠ 0 := by
simp_rw [Ne, ← measure_univ_eq_zero, isOpen_univ.measure_eq_iSup_isCompact,
ENNReal.iSup_eq_zero, not_forall, exists_prop, subset_univ, true_and_iff]
/-- If `μ` is a regular measure, then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_isCompact_lt_add` and
`MeasurableSet.exists_lt_isCompact_of_ne_top`. -/
instance (priority := 100) [Regular μ] : InnerRegularCompactLTTop μ :=
⟨Regular.innerRegular.measurableSet_of_isOpen (fun _ _ hs hU ↦ hs.diff hU)⟩
protected theorem map [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [Regular μ] (f : α ≃ₜ β) : (Measure.map f μ).Regular := by
haveI := OuterRegular.map f μ
haveI := IsFiniteMeasureOnCompacts.map μ f
exact
⟨Regular.innerRegular.map' f.toMeasurableEquiv
(fun U hU => hU.preimage f.continuous)
(fun K hK => hK.image f.continuous)⟩
protected theorem map_iff [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] (f : α ≃ₜ β) :
Regular (Measure.map f μ) ↔ Regular μ := by
refine ⟨fun h ↦ ?_, fun h ↦ h.map f⟩
convert h.map f.symm
rw [map_map f.symm.continuous.measurable f.continuous.measurable]
simp
protected theorem smul [Regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) : (x • μ).Regular := by
haveI := OuterRegular.smul μ hx
haveI := IsFiniteMeasureOnCompacts.smul μ hx
exact ⟨Regular.innerRegular.smul x⟩
instance smul_nnreal [Regular μ] (c : ℝ≥0) : Regular (c • μ) := Regular.smul coe_ne_top
/-- The restriction of a regular measure to a set of finite measure is regular. -/
theorem restrict_of_measure_ne_top [R1Space α] [BorelSpace α] [Regular μ]
{A : Set α} (h'A : μ A ≠ ∞) : Regular (μ.restrict A) := by
have : WeaklyRegular (μ.restrict A) := WeaklyRegular.restrict_of_measure_ne_top h'A
constructor
intro V hV r hr
have R : restrict μ A V ≠ ∞ := by
rw [restrict_apply hV.measurableSet]
exact ((measure_mono inter_subset_right).trans_lt h'A.lt_top).ne
exact MeasurableSet.exists_lt_isCompact_of_ne_top hV.measurableSet R hr
end Regular
-- see Note [lower instance priority]
/-- Any locally finite measure on a `σ`-compact pseudometrizable space is regular. -/
instance (priority := 100) Regular.of_sigmaCompactSpace_of_isLocallyFiniteMeasure {X : Type*}
[TopologicalSpace X] [PseudoMetrizableSpace X] [SigmaCompactSpace X] [MeasurableSpace X]
[BorelSpace X] (μ : Measure X) [IsLocallyFiniteMeasure μ] : Regular μ := by
let A : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X
exact ⟨(InnerRegularWRT.isCompact_isClosed μ).trans (InnerRegularWRT.of_pseudoMetrizableSpace μ)⟩
/-- Any sigma finite measure on a `σ`-compact pseudometrizable space is inner regular. -/
instance (priority := 100) {X : Type*}
[TopologicalSpace X] [PseudoMetrizableSpace X] [SigmaCompactSpace X] [MeasurableSpace X]
[BorelSpace X] (μ : Measure X) [SigmaFinite μ] : InnerRegular μ := by
refine ⟨(InnerRegularWRT.isCompact_isClosed μ).trans ?_⟩
refine InnerRegularWRT.of_restrict (fun n ↦ ?_)
(univ_subset_iff.2 (iUnion_spanningSets μ)) (monotone_spanningSets μ)
have : Fact (μ (spanningSets μ n) < ∞) := ⟨measure_spanningSets_lt_top μ n⟩
exact WeaklyRegular.innerRegular_measurable.trans InnerRegularWRT.of_sigmaFinite
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Restrict.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s :=
(restrictₗ s).map_smul c μ
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
@[simp]
theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by
rw [← measure_univ_eq_zero, restrict_apply_univ]
/-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) :=
⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩
theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 :=
restrict_eq_zero.2 h
@[simp]
theorem restrict_empty : μ.restrict ∅ = 0 :=
restrict_zero_set measure_empty
@[simp]
theorem restrict_univ : μ.restrict univ = μ :=
ext fun s hs => by simp [hs]
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq]
exact measure_inter_add_diff₀ (u ∩ s) ht
theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s :=
restrict_inter_add_diff₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
restrict_union_add_inter₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h]
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
restrict_union₀ h.aedisjoint ht.nullMeasurableSet
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
μ.restrict s + μ.restrict sᶜ = μ := by
rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self,
restrict_univ]
@[simp]
theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by
rw [add_comm, restrict_add_restrict_compl hs]
theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
le_iff.2 fun t ht ↦ by
simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s')
theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by
simp only [restrict_apply, ht, inter_iUnion]
exact
measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right)
fun i => ht.nullMeasurableSet.inter (hm i)
theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht
theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s)
{t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion]
rw [measure_iUnion_eq_iSup]
exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _]
/-- The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/
theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
ext fun t ht => by simp [*, hf ht]
theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h,
inter_comm]
theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄
(hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ :=
calc
μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs)
_ = μ := restrict_univ
theorem restrict_congr_meas (hs : MeasurableSet s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t :=
⟨fun H t hts ht => by
rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H =>
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩
theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s := by
rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
theorem restrict_union_congr :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by
refine
⟨fun h =>
⟨restrict_congr_mono subset_union_left h,
restrict_congr_mono subset_union_right h⟩,
?_⟩
rintro ⟨hs, ht⟩
ext1 u hu
simp only [restrict_apply hu, inter_union_distrib_left]
rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩
calc
μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) :=
measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl
_ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm _).symm
_ = restrict μ s u + restrict μ t (u \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc]
_ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht]
_ = ν US + ν ((u ∩ t) \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc]
_ = ν (US ∪ u ∩ t) := measure_add_diff hm _
_ = ν (u ∩ s ∪ u ∩ t) := Eq.symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl
theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
classical
induction' s using Finset.induction_on with i s _ hs; · simp
simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert]
rw [restrict_union_congr, ← hs]
theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩
ext1 t ht
have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i :=
Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht
rw [iUnion_eq_iUnion_finset]
simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i]
theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr]
theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by
rw [sUnion_eq_biUnion, restrict_biUnion_congr hc]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)}
(hm : m.Nonempty) (ht : MeasurableSet t) :
(sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by
ext1 s hs
simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht),
Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ←
Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _),
OuterMeasure.restrict_apply]
theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop}
(hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by
rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs
exact (hs.and_eventually hp).exists
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `biUnion`). -/
theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable)
(hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion]
alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ
theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞)
(ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by
refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_
ext1 u hu
simp only [restrict_apply hu]
refine induction_on_inter h_gen h_inter ?_ (ST_eq t ht) ?_ ?_ hu
· simp only [Set.empty_inter, measure_empty]
· intro v hv hvt
have := T_eq t ht
rw [Set.inter_comm] at hvt ⊢
rwa [← measure_inter_add_diff t hv, ← measure_inter_add_diff t hv, ← hvt,
ENNReal.add_right_inj] at this
exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left)
· intro f hfd hfm h_eq
simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at h_eq ⊢
simp only [measure_iUnion hfd hfm, h_eq]
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ)
(htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht)
intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H
· simp only [H, measure_empty]
· exact h_eq _ (h_inter _ hs _ (h_sub ht) H)
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `iUnion`.
`FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/
theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞)
(h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq
· rintro _ ⟨i, rfl⟩
apply h2B
· rintro _ ⟨i, rfl⟩
apply hμB
@[simp]
theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
(sum μ).restrict s = sum fun i => (μ i).restrict s :=
ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
@[simp]
theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) :
(sum μ).restrict s = sum fun i => (μ i).restrict s := by
ext t ht
simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable]
lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by
refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_)
rw [restrict_apply ht] at htν ⊢
exact h htν
theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht]
theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet
theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) :=
le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·)
end Measure
@[simp]
theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) :
ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) :=
le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <|
iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl
@[simp]
theorem ae_restrict_union_eq (s t : Set α) :
ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by
simp [union_eq_iUnion, iSup_bool_eq]
theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype'']
theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) :=
ae_restrict_biUnion_eq s t.countable_toSet
theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp
theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp
theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup]
@[simp]
theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup]
theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup]
theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup]
theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g :=
ae_eq_restrict_biUnion_iff s t.countable_toSet f g
theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) :
ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by
simp only [uIoc_eq_union, ae_restrict_union_eq]
/-- See also `MeasureTheory.ae_uIoc_iff`. -/
theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔
(∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by
rw [ae_restrict_uIoc_eq, eventually_sup]
theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff₀ hp.nullMeasurableSet
theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) :
∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff] at h ⊢
simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h
theorem ae_restrict_iff'₀ {p : α → Prop} (hs : NullMeasurableSet s μ) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, restrict_apply₀' hs]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff' {p : α → Prop} (hs : MeasurableSet s) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff'₀ hs.nullMeasurableSet
theorem _root_.Filter.EventuallyEq.restrict {f g : α → δ} {s : Set α} (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.restrict s] g := by
-- note that we cannot use `ae_restrict_iff` since we do not require measurability
refine hfg.filter_mono ?_
rw [Measure.ae_le_iff_absolutelyContinuous]
exact Measure.absolutelyContinuous_of_le Measure.restrict_le_self
theorem ae_restrict_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
(ae_restrict_iff'₀ hs).2 (Filter.eventually_of_forall fun _ => id)
theorem ae_restrict_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
ae_restrict_mem₀ hs.nullMeasurableSet
theorem ae_restrict_of_ae {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono Measure.restrict_le_self)
theorem ae_restrict_of_ae_restrict_of_subset {s t : Set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂μ.restrict t, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono <| Measure.restrict_mono hst (le_refl μ))
theorem ae_of_ae_restrict_of_ae_restrict_compl (t : Set α) {p : α → Prop}
(ht : ∀ᵐ x ∂μ.restrict t, p x) (htc : ∀ᵐ x ∂μ.restrict tᶜ, p x) : ∀ᵐ x ∂μ, p x :=
nonpos_iff_eq_zero.1 <|
calc
μ { x | ¬p x } ≤ μ ({ x | ¬p x } ∩ t) + μ ({ x | ¬p x } ∩ tᶜ) :=
measure_le_inter_add_diff _ _ _
_ ≤ μ.restrict t { x | ¬p x } + μ.restrict tᶜ { x | ¬p x } :=
add_le_add (le_restrict_apply _ _) (le_restrict_apply _ _)
_ = 0 := by rw [ae_iff.1 ht, ae_iff.1 htc, zero_add]
theorem mem_map_restrict_ae_iff {β} {s : Set α} {t : Set β} {f : α → β} (hs : MeasurableSet s) :
t ∈ Filter.map f (ae (μ.restrict s)) ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0 := by
rw [mem_map, mem_ae_iff, Measure.restrict_apply' hs]
theorem ae_smul_measure {p : α → Prop} [Monoid R] [DistribMulAction R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : ∀ᵐ x ∂μ, p x) (c : R) : ∀ᵐ x ∂c • μ, p x :=
ae_iff.2 <| by rw [smul_apply, ae_iff.1 h, smul_zero]
theorem ae_add_measure_iff {p : α → Prop} {ν} :
(∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero_iff
theorem ae_eq_comp' {ν : Measure β} {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ)
(h : g =ᵐ[ν] g') (h2 : μ.map f ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=
(tendsto_ae_map hf).mono_right h2.ae_le h
theorem Measure.QuasiMeasurePreserving.ae_eq_comp {ν : Measure β} {f : α → β} {g g' : β → δ}
(hf : QuasiMeasurePreserving f μ ν) (h : g =ᵐ[ν] g') : g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf.aemeasurable h hf.absolutelyContinuous
theorem ae_eq_comp {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ) (h : g =ᵐ[μ.map f] g') :
g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf h AbsolutelyContinuous.rfl
@[to_additive]
theorem div_ae_eq_one {β} [Group β] (f g : α → β) : f / g =ᵐ[μ] 1 ↔ f =ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun x hx ↦ ?_, fun h ↦ h.mono fun x hx ↦ ?_⟩
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one] at hx
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one]
@[to_additive sub_nonneg_ae]
lemma one_le_div_ae {β : Type*} [Group β] [LE β]
[CovariantClass β β (Function.swap (· * ·)) (· ≤ ·)] (f g : α → β) :
1 ≤ᵐ[μ] g / f ↔ f ≤ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun a ha ↦ ?_, fun h ↦ h.mono fun a ha ↦ ?_⟩
· rwa [Pi.one_apply, Pi.div_apply, one_le_div'] at ha
· rwa [Pi.one_apply, Pi.div_apply, one_le_div']
theorem le_ae_restrict : ae μ ⊓ 𝓟 s ≤ ae (μ.restrict s) := fun _s hs =>
eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)
@[simp]
theorem ae_restrict_eq (hs : MeasurableSet s) : ae (μ.restrict s) = ae μ ⊓ 𝓟 s := by
ext t
simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_setOf,
Classical.not_imp, fun a => and_comm (a := a ∈ s) (b := ¬a ∈ t)]
rfl
-- @[simp] -- Porting note (#10618): simp can prove this
theorem ae_restrict_eq_bot {s} : ae (μ.restrict s) = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans restrict_eq_zero
theorem ae_restrict_neBot {s} : (ae <| μ.restrict s).NeBot ↔ μ s ≠ 0 :=
neBot_iff.trans ae_restrict_eq_bot.not
theorem self_mem_ae_restrict {s} (hs : MeasurableSet s) : s ∈ ae (μ.restrict s) := by
simp only [ae_restrict_eq hs, exists_prop, mem_principal, mem_inf_iff]
exact ⟨_, univ_mem, s, Subset.rfl, (univ_inter s).symm⟩
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_of_ae_eq_of_ae_restrict {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) → ∀ᵐ x ∂μ.restrict t, p x := by simp [Measure.restrict_congr_set hst]
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_congr_set {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ.restrict t, p x :=
⟨ae_restrict_of_ae_eq_of_ae_restrict hst, ae_restrict_of_ae_eq_of_ae_restrict hst.symm⟩
/-- A version of the **Borel-Cantelli lemma**: if `pᵢ` is a sequence of predicates such that
`∑ μ {x | pᵢ x}` is finite, then the measure of `x` such that `pᵢ x` holds frequently as `i → ∞` (or
equivalently, `pᵢ x` holds for infinitely many `i`) is equal to zero. -/
theorem measure_setOf_frequently_eq_zero {p : ℕ → α → Prop} (hp : ∑' i, μ { x | p i x } ≠ ∞) :
μ { x | ∃ᶠ n in atTop, p n x } = 0 := by
simpa only [limsup_eq_iInf_iSup_of_nat, frequently_atTop, ← bex_def, setOf_forall,
setOf_exists] using measure_limsup_eq_zero hp
/-- A version of the **Borel-Cantelli lemma**: if `sᵢ` is a sequence of sets such that
`∑ μ sᵢ` exists, then for almost all `x`, `x` does not belong to almost all `sᵢ`. -/
theorem ae_eventually_not_mem {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) :
∀ᵐ x ∂μ, ∀ᶠ n in atTop, x ∉ s n :=
measure_setOf_frequently_eq_zero hs
lemma NullMeasurable.measure_preimage_eq_measure_restrict_preimage_of_ae_compl_eq_const
{β : Type*} [MeasurableSpace β] {b : β} {f : α → β} {s : Set α}
(f_mble : NullMeasurable f (μ.restrict s)) (hs : f =ᵐ[Measure.restrict μ sᶜ] (fun _ ↦ b))
{t : Set β} (t_mble : MeasurableSet t) (ht : b ∉ t) :
μ (f ⁻¹' t) = μ.restrict s (f ⁻¹' t) := by
rw [Measure.restrict_apply₀ (f_mble t_mble)]
rw [EventuallyEq, ae_iff, Measure.restrict_apply₀] at hs
· apply le_antisymm _ (measure_mono inter_subset_left)
apply (measure_mono (Eq.symm (inter_union_compl (f ⁻¹' t) s)).le).trans
apply (measure_union_le _ _).trans
have obs : μ ((f ⁻¹' t) ∩ sᶜ) = 0 := by
apply le_antisymm _ (zero_le _)
rw [← hs]
apply measure_mono (inter_subset_inter_left _ _)
intro x hx hfx
simp only [mem_preimage, mem_setOf_eq] at hx hfx
exact ht (hfx ▸ hx)
simp only [obs, add_zero, le_refl]
· exact NullMeasurableSet.of_null hs
namespace Measure
section Subtype
/-! ### Subtype of a measure space -/
section ComapAnyMeasure
theorem MeasurableSet.nullMeasurableSet_subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : MeasurableSet t) : NullMeasurableSet ((↑) '' t) μ := by
rw [Subtype.instMeasurableSpace, comap_eq_generateFrom] at ht
refine
generateFrom_induction (p := fun t : Set s => NullMeasurableSet ((↑) '' t) μ)
{ t : Set s | ∃ s' : Set α, MeasurableSet s' ∧ (↑) ⁻¹' s' = t } ?_ ?_ ?_ ?_ ht
· rintro t' ⟨s', hs', rfl⟩
rw [Subtype.image_preimage_coe]
exact hs.inter (hs'.nullMeasurableSet)
· simp only [image_empty, nullMeasurableSet_empty]
· intro t'
simp only [← range_diff_image Subtype.coe_injective, Subtype.range_coe_subtype, setOf_mem_eq]
exact hs.diff
· intro f
dsimp only []
rw [image_iUnion]
exact NullMeasurableSet.iUnion
theorem NullMeasurableSet.subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : NullMeasurableSet t (μ.comap Subtype.val)) : NullMeasurableSet (((↑) : s → α) '' t) μ :=
NullMeasurableSet.image (↑) μ Subtype.coe_injective
(fun _ => MeasurableSet.nullMeasurableSet_subtype_coe hs) ht
theorem measure_subtype_coe_le_comap (hs : NullMeasurableSet s μ) (t : Set s) :
μ (((↑) : s → α) '' t) ≤ μ.comap Subtype.val t :=
le_comap_apply _ _ Subtype.coe_injective (fun _ =>
MeasurableSet.nullMeasurableSet_subtype_coe hs) _
theorem measure_subtype_coe_eq_zero_of_comap_eq_zero (hs : NullMeasurableSet s μ) {t : Set s}
(ht : μ.comap Subtype.val t = 0) : μ (((↑) : s → α) '' t) = 0 :=
eq_bot_iff.mpr <| (measure_subtype_coe_le_comap hs t).trans ht.le
end ComapAnyMeasure
section MeasureSpace
variable {u : Set δ} [MeasureSpace δ] {p : δ → Prop}
/-- In a measure space, one can restrict the measure to a subtype to get a new measure space.
Not registered as an instance, as there are other natural choices such as the normalized restriction
for a probability measure, or the subspace measure when restricting to a vector subspace. Enable
locally if needed with `attribute [local instance] Measure.Subtype.measureSpace`. -/
noncomputable def Subtype.measureSpace : MeasureSpace (Subtype p) where
volume := Measure.comap Subtype.val volume
attribute [local instance] Subtype.measureSpace
theorem Subtype.volume_def : (volume : Measure u) = volume.comap Subtype.val :=
rfl
theorem Subtype.volume_univ (hu : NullMeasurableSet u) : volume (univ : Set u) = volume u := by
rw [Subtype.volume_def, comap_apply₀ _ _ _ _ MeasurableSet.univ.nullMeasurableSet]
· congr
simp only [image_univ, Subtype.range_coe_subtype, setOf_mem_eq]
· exact Subtype.coe_injective
· exact fun t => MeasurableSet.nullMeasurableSet_subtype_coe hu
theorem volume_subtype_coe_le_volume (hu : NullMeasurableSet u) (t : Set u) :
volume (((↑) : u → δ) '' t) ≤ volume t :=
measure_subtype_coe_le_comap hu t
theorem volume_subtype_coe_eq_zero_of_volume_eq_zero (hu : NullMeasurableSet u) {t : Set u}
(ht : volume t = 0) : volume (((↑) : u → δ) '' t) = 0 :=
measure_subtype_coe_eq_zero_of_comap_eq_zero hu ht
end MeasureSpace
end Subtype
end Measure
end MeasureTheory
open MeasureTheory Measure
namespace MeasurableEmbedding
variable {m0 : MeasurableSpace α} {m1 : MeasurableSpace β} {f : α → β} (hf : MeasurableEmbedding f)
theorem map_comap (μ : Measure β) : (comap f μ).map f = μ.restrict (range f) := by
ext1 t ht
rw [hf.map_apply, comap_apply f hf.injective hf.measurableSet_image' _ (hf.measurable ht),
image_preimage_eq_inter_range, Measure.restrict_apply ht]
theorem comap_apply (μ : Measure β) (s : Set α) : comap f μ s = μ (f '' s) :=
calc
comap f μ s = comap f μ (f ⁻¹' (f '' s)) := by rw [hf.injective.preimage_image]
_ = (comap f μ).map f (f '' s) := (hf.map_apply _ _).symm
_ = μ (f '' s) := by
rw [hf.map_comap, restrict_apply' hf.measurableSet_range,
inter_eq_self_of_subset_left (image_subset_range _ _)]
theorem comap_map (μ : Measure α) : (map f μ).comap f = μ := by
ext t _
rw [hf.comap_apply, hf.map_apply, preimage_image_eq _ hf.injective]
theorem ae_map_iff {p : β → Prop} {μ : Measure α} : (∀ᵐ x ∂μ.map f, p x) ↔ ∀ᵐ x ∂μ, p (f x) := by
simp only [ae_iff, hf.map_apply, preimage_setOf_eq]
theorem restrict_map (μ : Measure α) (s : Set β) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
Measure.ext fun t ht => by simp [hf.map_apply, ht, hf.measurable ht]
protected theorem comap_preimage (μ : Measure β) (s : Set β) :
μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by
rw [← hf.map_apply, hf.map_comap, restrict_apply' hf.measurableSet_range]
lemma comap_restrict (μ : Measure β) (s : Set β) :
(μ.restrict s).comap f = (μ.comap f).restrict (f ⁻¹' s) := by
ext t ht
rw [Measure.restrict_apply ht, comap_apply hf, comap_apply hf,
Measure.restrict_apply (hf.measurableSet_image.2 ht), image_inter_preimage]
lemma restrict_comap (μ : Measure β) (s : Set α) :
(μ.comap f).restrict s = (μ.restrict (f '' s)).comap f := by
rw [comap_restrict hf, preimage_image_eq _ hf.injective]
theorem _root_.MeasurableEquiv.restrict_map (e : α ≃ᵐ β) (μ : Measure α) (s : Set β) :
(μ.map e).restrict s = (μ.restrict <| e ⁻¹' s).map e :=
e.measurableEmbedding.restrict_map _ _
end MeasurableEmbedding
section Subtype
theorem comap_subtype_coe_apply {_m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s)
(μ : Measure α) (t : Set s) : comap (↑) μ t = μ ((↑) '' t) :=
(MeasurableEmbedding.subtype_coe hs).comap_apply _ _
theorem map_comap_subtype_coe {m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s)
(μ : Measure α) : (comap (↑) μ).map ((↑) : s → α) = μ.restrict s := by
rw [(MeasurableEmbedding.subtype_coe hs).map_comap, Subtype.range_coe]
theorem ae_restrict_iff_subtype {m0 : MeasurableSpace α} {μ : Measure α} {s : Set α}
(hs : MeasurableSet s) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ (x : s) ∂comap ((↑) : s → α) μ, p x := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).ae_map_iff]
variable [MeasureSpace α] {s t : Set α}
/-!
### Volume on `s : Set α`
Note the instance is provided earlier as `Subtype.measureSpace`.
-/
attribute [local instance] Subtype.measureSpace
theorem volume_set_coe_def (s : Set α) : (volume : Measure s) = comap ((↑) : s → α) volume :=
rfl
theorem MeasurableSet.map_coe_volume {s : Set α} (hs : MeasurableSet s) :
volume.map ((↑) : s → α) = restrict volume s := by
rw [volume_set_coe_def, (MeasurableEmbedding.subtype_coe hs).map_comap volume, Subtype.range_coe]
theorem volume_image_subtype_coe {s : Set α} (hs : MeasurableSet s) (t : Set s) :
volume ((↑) '' t : Set α) = volume t :=
(comap_subtype_coe_apply hs volume t).symm
@[simp]
theorem volume_preimage_coe (hs : NullMeasurableSet s) (ht : MeasurableSet t) :
volume (((↑) : s → α) ⁻¹' t) = volume (t ∩ s) := by
rw [volume_set_coe_def,
comap_apply₀ _ _ Subtype.coe_injective
(fun h => MeasurableSet.nullMeasurableSet_subtype_coe hs)
(measurable_subtype_coe ht).nullMeasurableSet,
image_preimage_eq_inter_range, Subtype.range_coe]
end Subtype
section Piecewise
variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f g : α → β}
theorem piecewise_ae_eq_restrict [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
piecewise s f g =ᵐ[μ.restrict s] f := by
rw [ae_restrict_eq hs]
exact (piecewise_eqOn s f g).eventuallyEq.filter_mono inf_le_right
theorem piecewise_ae_eq_restrict_compl [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
piecewise s f g =ᵐ[μ.restrict sᶜ] g := by
rw [ae_restrict_eq hs.compl]
exact (piecewise_eqOn_compl s f g).eventuallyEq.filter_mono inf_le_right
theorem piecewise_ae_eq_of_ae_eq_set [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)]
(hst : s =ᵐ[μ] t) : s.piecewise f g =ᵐ[μ] t.piecewise f g :=
hst.mem_iff.mono fun x hx => by simp [piecewise, hx]
end Piecewise
section IndicatorFunction
variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f : α → β}
theorem mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem [Zero β] {t : Set β}
(ht : (0 : β) ∈ t) (hs : MeasurableSet s) :
t ∈ Filter.map (s.indicator f) (ae μ) ↔ t ∈ Filter.map f (ae <| μ.restrict s) := by
classical
simp_rw [mem_map, mem_ae_iff]
rw [Measure.restrict_apply' hs, Set.indicator_preimage, Set.ite]
simp_rw [Set.compl_union, Set.compl_inter]
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((fun _ => (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0
simp only [ht, ← Set.compl_eq_univ_diff, compl_compl, Set.compl_union, if_true,
Set.preimage_const]
simp_rw [Set.union_inter_distrib_right, Set.compl_inter_self s, Set.union_empty]
theorem mem_map_indicator_ae_iff_of_zero_nmem [Zero β] {t : Set β} (ht : (0 : β) ∉ t) :
t ∈ Filter.map (s.indicator f) (ae μ) ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0 := by
classical
rw [mem_map, mem_ae_iff, Set.indicator_preimage, Set.ite, Set.compl_union, Set.compl_inter]
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((fun _ => (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0
simp only [ht, if_false, Set.compl_empty, Set.empty_diff, Set.inter_univ, Set.preimage_const]
theorem map_restrict_ae_le_map_indicator_ae [Zero β] (hs : MeasurableSet s) :
Filter.map f (ae <| μ.restrict s) ≤ Filter.map (s.indicator f) (ae μ) := by
intro t
by_cases ht : (0 : β) ∈ t
· rw [mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem ht hs]
exact id
rw [mem_map_indicator_ae_iff_of_zero_nmem ht, mem_map_restrict_ae_iff hs]
exact fun h => measure_mono_null (Set.inter_subset_left.trans Set.subset_union_left) h
variable [Zero β]
theorem indicator_ae_eq_restrict (hs : MeasurableSet s) : indicator s f =ᵐ[μ.restrict s] f := by
classical exact piecewise_ae_eq_restrict hs
theorem indicator_ae_eq_restrict_compl (hs : MeasurableSet s) :
indicator s f =ᵐ[μ.restrict sᶜ] 0 := by
classical exact piecewise_ae_eq_restrict_compl hs
theorem indicator_ae_eq_of_restrict_compl_ae_eq_zero (hs : MeasurableSet s)
(hf : f =ᵐ[μ.restrict sᶜ] 0) : s.indicator f =ᵐ[μ] f := by
rw [Filter.EventuallyEq, ae_restrict_iff' hs.compl] at hf
filter_upwards [hf] with x hx
by_cases hxs : x ∈ s
· simp only [hxs, Set.indicator_of_mem]
· simp only [hx hxs, Pi.zero_apply, Set.indicator_apply_eq_zero, eq_self_iff_true, imp_true_iff]
theorem indicator_ae_eq_zero_of_restrict_ae_eq_zero (hs : MeasurableSet s)
(hf : f =ᵐ[μ.restrict s] 0) : s.indicator f =ᵐ[μ] 0 := by
rw [Filter.EventuallyEq, ae_restrict_iff' hs] at hf
filter_upwards [hf] with x hx
by_cases hxs : x ∈ s
· simp only [hxs, hx hxs, Set.indicator_of_mem]
· simp [hx, hxs]
theorem indicator_ae_eq_of_ae_eq_set (hst : s =ᵐ[μ] t) : s.indicator f =ᵐ[μ] t.indicator f := by
classical exact piecewise_ae_eq_of_ae_eq_set hst
theorem indicator_meas_zero (hs : μ s = 0) : indicator s f =ᵐ[μ] 0 :=
indicator_empty' f ▸ indicator_ae_eq_of_ae_eq_set (ae_eq_empty.2 hs)
theorem ae_eq_restrict_iff_indicator_ae_eq {g : α → β} (hs : MeasurableSet s) :
f =ᵐ[μ.restrict s] g ↔ s.indicator f =ᵐ[μ] s.indicator g := by
rw [Filter.EventuallyEq, ae_restrict_iff' hs]
refine ⟨fun h => ?_, fun h => ?_⟩ <;> filter_upwards [h] with x hx
· by_cases hxs : x ∈ s
· simp [hxs, hx hxs]
· simp [hxs]
· intro hxs
simpa [hxs] using hx
end IndicatorFunction
|
MeasureTheory\Measure\Stieltjes.lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
import Mathlib.Topology.Order.LeftRightLim
/-!
# Stieltjes measures on the real line
Consider a function `f : ℝ → ℝ` which is monotone and right-continuous. Then one can define a
corresponding measure, giving mass `f b - f a` to the interval `(a, b]`.
## Main definitions
* `StieltjesFunction` is a structure containing a function from `ℝ → ℝ`, together with the
assertions that it is monotone and right-continuous. To `f : StieltjesFunction`, one associates
a Borel measure `f.measure`.
* `f.measure_Ioc` asserts that `f.measure (Ioc a b) = ofReal (f b - f a)`
* `f.measure_Ioo` asserts that `f.measure (Ioo a b) = ofReal (leftLim f b - f a)`.
* `f.measure_Icc` and `f.measure_Ico` are analogous.
-/
noncomputable section
open Set Filter Function ENNReal NNReal Topology MeasureTheory
open ENNReal (ofReal)
/-! ### Basic properties of Stieltjes functions -/
/-- Bundled monotone right-continuous real functions, used to construct Stieltjes measures. -/
structure StieltjesFunction where
toFun : ℝ → ℝ
mono' : Monotone toFun
right_continuous' : ∀ x, ContinuousWithinAt toFun (Ici x) x
namespace StieltjesFunction
attribute [coe] toFun
instance instCoeFun : CoeFun StieltjesFunction fun _ => ℝ → ℝ :=
⟨toFun⟩
initialize_simps_projections StieltjesFunction (toFun → apply)
@[ext] lemma ext {f g : StieltjesFunction} (h : ∀ x, f x = g x) : f = g := by
exact (StieltjesFunction.mk.injEq ..).mpr (funext h)
variable (f : StieltjesFunction)
theorem mono : Monotone f :=
f.mono'
theorem right_continuous (x : ℝ) : ContinuousWithinAt f (Ici x) x :=
f.right_continuous' x
theorem rightLim_eq (f : StieltjesFunction) (x : ℝ) : Function.rightLim f x = f x := by
rw [← f.mono.continuousWithinAt_Ioi_iff_rightLim_eq, continuousWithinAt_Ioi_iff_Ici]
exact f.right_continuous' x
theorem iInf_Ioi_eq (f : StieltjesFunction) (x : ℝ) : ⨅ r : Ioi x, f r = f x := by
suffices Function.rightLim f x = ⨅ r : Ioi x, f r by rw [← this, f.rightLim_eq]
rw [f.mono.rightLim_eq_sInf, sInf_image']
rw [← neBot_iff]
infer_instance
theorem iInf_rat_gt_eq (f : StieltjesFunction) (x : ℝ) :
⨅ r : { r' : ℚ // x < r' }, f r = f x := by
rw [← iInf_Ioi_eq f x]
refine (Real.iInf_Ioi_eq_iInf_rat_gt _ ?_ f.mono).symm
refine ⟨f x, fun y => ?_⟩
rintro ⟨y, hy_mem, rfl⟩
exact f.mono (le_of_lt hy_mem)
/-- The identity of `ℝ` as a Stieltjes function, used to construct Lebesgue measure. -/
@[simps]
protected def id : StieltjesFunction where
toFun := id
mono' _ _ := id
right_continuous' _ := continuousWithinAt_id
@[simp]
theorem id_leftLim (x : ℝ) : leftLim StieltjesFunction.id x = x :=
tendsto_nhds_unique (StieltjesFunction.id.mono.tendsto_leftLim x) <|
continuousAt_id.tendsto.mono_left nhdsWithin_le_nhds
instance instInhabited : Inhabited StieltjesFunction :=
⟨StieltjesFunction.id⟩
/-- Constant functions are Stieltjes function. -/
protected def const (c : ℝ) : StieltjesFunction where
toFun := fun _ ↦ c
mono' _ _ := by simp
right_continuous' _ := continuousWithinAt_const
@[simp] lemma const_apply (c x : ℝ) : (StieltjesFunction.const c) x = c := rfl
/-- The sum of two Stieltjes functions is a Stieltjes function. -/
protected def add (f g : StieltjesFunction) : StieltjesFunction where
toFun := fun x => f x + g x
mono' := f.mono.add g.mono
right_continuous' := fun x => (f.right_continuous x).add (g.right_continuous x)
instance : AddZeroClass StieltjesFunction where
add := StieltjesFunction.add
zero := StieltjesFunction.const 0
zero_add _ := ext fun _ ↦ zero_add _
add_zero _ := ext fun _ ↦ add_zero _
instance : AddCommMonoid StieltjesFunction where
nsmul n f := nsmulRec n f
add_assoc _ _ _ := ext fun _ ↦ add_assoc _ _ _
add_comm _ _ := ext fun _ ↦ add_comm _ _
__ := StieltjesFunction.instAddZeroClass
instance : Module ℝ≥0 StieltjesFunction where
smul c f := {
toFun := fun x ↦ c * f x
mono' := f.mono.const_mul c.2
right_continuous' := fun x ↦ (f.right_continuous x).const_smul c.1}
one_smul _ := ext fun _ ↦ one_mul _
mul_smul _ _ _ := ext fun _ ↦ mul_assoc _ _ _
smul_zero _ := ext fun _ ↦ mul_zero _
smul_add _ _ _ := ext fun _ ↦ mul_add _ _ _
add_smul _ _ _ := ext fun _ ↦ add_mul _ _ _
zero_smul _ := ext fun _ ↦ zero_mul _
@[simp] lemma add_apply (f g : StieltjesFunction) (x : ℝ) : (f + g) x = f x + g x := rfl
/-- If a function `f : ℝ → ℝ` is monotone, then the function mapping `x` to the right limit of `f`
at `x` is a Stieltjes function, i.e., it is monotone and right-continuous. -/
noncomputable def _root_.Monotone.stieltjesFunction {f : ℝ → ℝ} (hf : Monotone f) :
StieltjesFunction where
toFun := rightLim f
mono' x y hxy := hf.rightLim hxy
right_continuous' := by
intro x s hs
obtain ⟨l, u, hlu, lus⟩ : ∃ l u : ℝ, rightLim f x ∈ Ioo l u ∧ Ioo l u ⊆ s :=
mem_nhds_iff_exists_Ioo_subset.1 hs
obtain ⟨y, xy, h'y⟩ : ∃ (y : ℝ), x < y ∧ Ioc x y ⊆ f ⁻¹' Ioo l u :=
mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 (hf.tendsto_rightLim x (Ioo_mem_nhds hlu.1 hlu.2))
change ∀ᶠ y in 𝓝[≥] x, rightLim f y ∈ s
filter_upwards [Ico_mem_nhdsWithin_Ici ⟨le_refl x, xy⟩] with z hz
apply lus
refine ⟨hlu.1.trans_le (hf.rightLim hz.1), ?_⟩
obtain ⟨a, za, ay⟩ : ∃ a : ℝ, z < a ∧ a < y := exists_between hz.2
calc
rightLim f z ≤ f a := hf.rightLim_le za
_ < u := (h'y ⟨hz.1.trans_lt za, ay.le⟩).2
theorem _root_.Monotone.stieltjesFunction_eq {f : ℝ → ℝ} (hf : Monotone f) (x : ℝ) :
hf.stieltjesFunction x = rightLim f x :=
rfl
theorem countable_leftLim_ne (f : StieltjesFunction) : Set.Countable { x | leftLim f x ≠ f x } := by
refine Countable.mono ?_ f.mono.countable_not_continuousAt
intro x hx h'x
apply hx
exact tendsto_nhds_unique (f.mono.tendsto_leftLim x) (h'x.tendsto.mono_left nhdsWithin_le_nhds)
/-! ### The outer measure associated to a Stieltjes function -/
/-- Length of an interval. This is the largest monotone function which correctly measures all
intervals. -/
def length (s : Set ℝ) : ℝ≥0∞ :=
⨅ (a) (b) (_ : s ⊆ Ioc a b), ofReal (f b - f a)
@[simp]
theorem length_empty : f.length ∅ = 0 :=
nonpos_iff_eq_zero.1 <| iInf_le_of_le 0 <| iInf_le_of_le 0 <| by simp
@[simp]
theorem length_Ioc (a b : ℝ) : f.length (Ioc a b) = ofReal (f b - f a) := by
refine
le_antisymm (iInf_le_of_le a <| iInf₂_le b Subset.rfl)
(le_iInf fun a' => le_iInf fun b' => le_iInf fun h => ENNReal.coe_le_coe.2 ?_)
rcases le_or_lt b a with ab | ab
· rw [Real.toNNReal_of_nonpos (sub_nonpos.2 (f.mono ab))]
apply zero_le
cases' (Ioc_subset_Ioc_iff ab).1 h with h₁ h₂
exact Real.toNNReal_le_toNNReal (sub_le_sub (f.mono h₁) (f.mono h₂))
theorem length_mono {s₁ s₂ : Set ℝ} (h : s₁ ⊆ s₂) : f.length s₁ ≤ f.length s₂ :=
iInf_mono fun _ => biInf_mono fun _ => h.trans
open MeasureTheory
/-- The Stieltjes outer measure associated to a Stieltjes function. -/
protected def outer : OuterMeasure ℝ :=
OuterMeasure.ofFunction f.length f.length_empty
theorem outer_le_length (s : Set ℝ) : f.outer s ≤ f.length s :=
OuterMeasure.ofFunction_le _
/-- If a compact interval `[a, b]` is covered by a union of open interval `(c i, d i)`, then
`f b - f a ≤ ∑ f (d i) - f (c i)`. This is an auxiliary technical statement to prove the same
statement for half-open intervals, the point of the current statement being that one can use
compactness to reduce it to a finite sum, and argue by induction on the size of the covering set. -/
theorem length_subadditive_Icc_Ioo {a b : ℝ} {c d : ℕ → ℝ} (ss : Icc a b ⊆ ⋃ i, Ioo (c i) (d i)) :
ofReal (f b - f a) ≤ ∑' i, ofReal (f (d i) - f (c i)) := by
suffices
∀ (s : Finset ℕ) (b), Icc a b ⊆ (⋃ i ∈ (s : Set ℕ), Ioo (c i) (d i)) →
(ofReal (f b - f a) : ℝ≥0∞) ≤ ∑ i ∈ s, ofReal (f (d i) - f (c i)) by
rcases isCompact_Icc.elim_finite_subcover_image
(fun (i : ℕ) (_ : i ∈ univ) => @isOpen_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with
⟨s, _, hf, hs⟩
have e : ⋃ i ∈ (hf.toFinset : Set ℕ), Ioo (c i) (d i) = ⋃ i ∈ s, Ioo (c i) (d i) := by
simp only [Set.ext_iff, exists_prop, Finset.set_biUnion_coe, mem_iUnion, forall_const,
iff_self_iff, Finite.mem_toFinset]
rw [ENNReal.tsum_eq_iSup_sum]
refine le_trans ?_ (le_iSup _ hf.toFinset)
exact this hf.toFinset _ (by simpa only [e] )
clear ss b
refine fun s => Finset.strongInductionOn s fun s IH b cv => ?_
rcases le_total b a with ab | ab
· rw [ENNReal.ofReal_eq_zero.2 (sub_nonpos.2 (f.mono ab))]
exact zero_le _
have := cv ⟨ab, le_rfl⟩
simp only [Finset.mem_coe, gt_iff_lt, not_lt, mem_iUnion, mem_Ioo, exists_and_left,
exists_prop] at this
rcases this with ⟨i, cb, is, bd⟩
rw [← Finset.insert_erase is] at cv ⊢
rw [Finset.coe_insert, biUnion_insert] at cv
rw [Finset.sum_insert (Finset.not_mem_erase _ _)]
refine le_trans ?_ (add_le_add_left (IH _ (Finset.erase_ssubset is) (c i) ?_) _)
· refine le_trans (ENNReal.ofReal_le_ofReal ?_) ENNReal.ofReal_add_le
rw [sub_add_sub_cancel]
exact sub_le_sub_right (f.mono bd.le) _
· rintro x ⟨h₁, h₂⟩
exact (cv ⟨h₁, le_trans h₂ (le_of_lt cb)⟩).resolve_left (mt And.left (not_lt_of_le h₂))
@[simp]
theorem outer_Ioc (a b : ℝ) : f.outer (Ioc a b) = ofReal (f b - f a) := by
/- It suffices to show that, if `(a, b]` is covered by sets `s i`, then `f b - f a` is bounded
by `∑ f.length (s i) + ε`. The difficulty is that `f.length` is expressed in terms of half-open
intervals, while we would like to have a compact interval covered by open intervals to use
compactness and finite sums, as provided by `length_subadditive_Icc_Ioo`. The trick is to use
the right-continuity of `f`. If `a'` is close enough to `a` on its right, then `[a', b]` is
still covered by the sets `s i` and moreover `f b - f a'` is very close to `f b - f a`
(up to `ε/2`).
Also, by definition one can cover `s i` by a half-closed interval `(p i, q i]` with `f`-length
very close to that of `s i` (within a suitably small `ε' i`, say). If one moves `q i` very
slightly to the right, then the `f`-length will change very little by right continuity, and we
will get an open interval `(p i, q' i)` covering `s i` with `f (q' i) - f (p i)` within `ε' i`
of the `f`-length of `s i`. -/
refine
le_antisymm
(by
rw [← f.length_Ioc]
apply outer_le_length)
(le_iInf₂ fun s hs => ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_)
let δ := ε / 2
have δpos : 0 < (δ : ℝ≥0∞) := by simpa [δ] using εpos.ne'
rcases ENNReal.exists_pos_sum_of_countable δpos.ne' ℕ with ⟨ε', ε'0, hε⟩
obtain ⟨a', ha', aa'⟩ : ∃ a', f a' - f a < δ ∧ a < a' := by
have A : ContinuousWithinAt (fun r => f r - f a) (Ioi a) a := by
refine ContinuousWithinAt.sub ?_ continuousWithinAt_const
exact (f.right_continuous a).mono Ioi_subset_Ici_self
have B : f a - f a < δ := by rwa [sub_self, NNReal.coe_pos, ← ENNReal.coe_pos]
exact (((tendsto_order.1 A).2 _ B).and self_mem_nhdsWithin).exists
have : ∀ i, ∃ p : ℝ × ℝ, s i ⊆ Ioo p.1 p.2 ∧
(ofReal (f p.2 - f p.1) : ℝ≥0∞) < f.length (s i) + ε' i := by
intro i
have hl :=
ENNReal.lt_add_right ((ENNReal.le_tsum i).trans_lt h).ne (ENNReal.coe_ne_zero.2 (ε'0 i).ne')
conv at hl =>
lhs
rw [length]
simp only [iInf_lt_iff, exists_prop] at hl
rcases hl with ⟨p, q', spq, hq'⟩
have : ContinuousWithinAt (fun r => ofReal (f r - f p)) (Ioi q') q' := by
apply ENNReal.continuous_ofReal.continuousAt.comp_continuousWithinAt
refine ContinuousWithinAt.sub ?_ continuousWithinAt_const
exact (f.right_continuous q').mono Ioi_subset_Ici_self
rcases (((tendsto_order.1 this).2 _ hq').and self_mem_nhdsWithin).exists with ⟨q, hq, q'q⟩
exact ⟨⟨p, q⟩, spq.trans (Ioc_subset_Ioo_right q'q), hq⟩
choose g hg using this
have I_subset : Icc a' b ⊆ ⋃ i, Ioo (g i).1 (g i).2 :=
calc
Icc a' b ⊆ Ioc a b := fun x hx => ⟨aa'.trans_le hx.1, hx.2⟩
_ ⊆ ⋃ i, s i := hs
_ ⊆ ⋃ i, Ioo (g i).1 (g i).2 := iUnion_mono fun i => (hg i).1
calc
ofReal (f b - f a) = ofReal (f b - f a' + (f a' - f a)) := by rw [sub_add_sub_cancel]
_ ≤ ofReal (f b - f a') + ofReal (f a' - f a) := ENNReal.ofReal_add_le
_ ≤ ∑' i, ofReal (f (g i).2 - f (g i).1) + ofReal δ :=
(add_le_add (f.length_subadditive_Icc_Ioo I_subset) (ENNReal.ofReal_le_ofReal ha'.le))
_ ≤ ∑' i, (f.length (s i) + ε' i) + δ :=
(add_le_add (ENNReal.tsum_le_tsum fun i => (hg i).2.le)
(by simp only [ENNReal.ofReal_coe_nnreal, le_rfl]))
_ = ∑' i, f.length (s i) + ∑' i, (ε' i : ℝ≥0∞) + δ := by rw [ENNReal.tsum_add]
_ ≤ ∑' i, f.length (s i) + δ + δ := add_le_add (add_le_add le_rfl hε.le) le_rfl
_ = ∑' i : ℕ, f.length (s i) + ε := by simp [δ, add_assoc, ENNReal.add_halves]
theorem measurableSet_Ioi {c : ℝ} : MeasurableSet[f.outer.caratheodory] (Ioi c) := by
refine OuterMeasure.ofFunction_caratheodory fun t => ?_
refine le_iInf fun a => le_iInf fun b => le_iInf fun h => ?_
refine
le_trans
(add_le_add (f.length_mono <| inter_subset_inter_left _ h)
(f.length_mono <| diff_subset_diff_left h)) ?_
rcases le_total a c with hac | hac <;> rcases le_total b c with hbc | hbc
· simp only [Ioc_inter_Ioi, f.length_Ioc, hac, _root_.sup_eq_max, hbc, le_refl, Ioc_eq_empty,
max_eq_right, min_eq_left, Ioc_diff_Ioi, f.length_empty, zero_add, not_lt]
· simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right,
_root_.sup_eq_max, ← ENNReal.ofReal_add, f.mono hac, f.mono hbc, sub_nonneg,
sub_add_sub_cancel, le_refl,
max_eq_right]
· simp only [hbc, le_refl, Ioc_eq_empty, Ioc_inter_Ioi, min_eq_left, Ioc_diff_Ioi, f.length_empty,
zero_add, or_true_iff, le_sup_iff, f.length_Ioc, not_lt]
· simp only [hac, hbc, Ioc_inter_Ioi, Ioc_diff_Ioi, f.length_Ioc, min_eq_right, _root_.sup_eq_max,
le_refl, Ioc_eq_empty, add_zero, max_eq_left, f.length_empty, not_lt]
theorem outer_trim : f.outer.trim = f.outer := by
refine le_antisymm (fun s => ?_) (OuterMeasure.le_trim _)
rw [OuterMeasure.trim_eq_iInf]
refine le_iInf fun t => le_iInf fun ht => ENNReal.le_of_forall_pos_le_add fun ε ε0 h => ?_
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 ε0).ne' ℕ with ⟨ε', ε'0, hε⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hε) _)
rw [← ENNReal.tsum_add]
choose g hg using
show ∀ i, ∃ s, t i ⊆ s ∧ MeasurableSet s ∧ f.outer s ≤ f.length (t i) + ofReal (ε' i) by
intro i
have hl :=
ENNReal.lt_add_right ((ENNReal.le_tsum i).trans_lt h).ne (ENNReal.coe_pos.2 (ε'0 i)).ne'
conv at hl =>
lhs
rw [length]
simp only [iInf_lt_iff] at hl
rcases hl with ⟨a, b, h₁, h₂⟩
rw [← f.outer_Ioc] at h₂
exact ⟨_, h₁, measurableSet_Ioc, le_of_lt <| by simpa using h₂⟩
simp only [ofReal_coe_nnreal] at hg
apply iInf_le_of_le (iUnion g) _
apply iInf_le_of_le (ht.trans <| iUnion_mono fun i => (hg i).1) _
apply iInf_le_of_le (MeasurableSet.iUnion fun i => (hg i).2.1) _
exact le_trans (measure_iUnion_le _) (ENNReal.tsum_le_tsum fun i => (hg i).2.2)
theorem borel_le_measurable : borel ℝ ≤ f.outer.caratheodory := by
rw [borel_eq_generateFrom_Ioi]
refine MeasurableSpace.generateFrom_le ?_
simp (config := { contextual := true }) [f.measurableSet_Ioi]
/-! ### The measure associated to a Stieltjes function -/
/-- The measure associated to a Stieltjes function, giving mass `f b - f a` to the
interval `(a, b]`. -/
protected irreducible_def measure : Measure ℝ where
toOuterMeasure := f.outer
m_iUnion _s hs := f.outer.iUnion_eq_of_caratheodory fun i => f.borel_le_measurable _ (hs i)
trim_le := f.outer_trim.le
@[simp]
theorem measure_Ioc (a b : ℝ) : f.measure (Ioc a b) = ofReal (f b - f a) := by
rw [StieltjesFunction.measure]
exact f.outer_Ioc a b
@[simp]
theorem measure_singleton (a : ℝ) : f.measure {a} = ofReal (f a - leftLim f a) := by
obtain ⟨u, u_mono, u_lt_a, u_lim⟩ :
∃ u : ℕ → ℝ, StrictMono u ∧ (∀ n : ℕ, u n < a) ∧ Tendsto u atTop (𝓝 a) :=
exists_seq_strictMono_tendsto a
have A : {a} = ⋂ n, Ioc (u n) a := by
refine Subset.antisymm (fun x hx => by simp [mem_singleton_iff.1 hx, u_lt_a]) fun x hx => ?_
simp? at hx says simp only [mem_iInter, mem_Ioc] at hx
have : a ≤ x := le_of_tendsto' u_lim fun n => (hx n).1.le
simp [le_antisymm this (hx 0).2]
have L1 : Tendsto (fun n => f.measure (Ioc (u n) a)) atTop (𝓝 (f.measure {a})) := by
rw [A]
refine tendsto_measure_iInter (fun n => measurableSet_Ioc) (fun m n hmn => ?_) ?_
· exact Ioc_subset_Ioc (u_mono.monotone hmn) le_rfl
· exact ⟨0, by simpa only [measure_Ioc] using ENNReal.ofReal_ne_top⟩
have L2 :
Tendsto (fun n => f.measure (Ioc (u n) a)) atTop (𝓝 (ofReal (f a - leftLim f a))) := by
simp only [measure_Ioc]
have : Tendsto (fun n => f (u n)) atTop (𝓝 (leftLim f a)) := by
apply (f.mono.tendsto_leftLim a).comp
exact
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ u_lim
(eventually_of_forall fun n => u_lt_a n)
exact ENNReal.continuous_ofReal.continuousAt.tendsto.comp (tendsto_const_nhds.sub this)
exact tendsto_nhds_unique L1 L2
@[simp]
theorem measure_Icc (a b : ℝ) : f.measure (Icc a b) = ofReal (f b - leftLim f a) := by
rcases le_or_lt a b with (hab | hab)
· have A : Disjoint {a} (Ioc a b) := by simp
simp [← Icc_union_Ioc_eq_Icc le_rfl hab, -singleton_union, ← ENNReal.ofReal_add,
f.mono.leftLim_le, measure_union A measurableSet_Ioc, f.mono hab]
· simp only [hab, measure_empty, Icc_eq_empty, not_le]
symm
simp [ENNReal.ofReal_eq_zero, f.mono.le_leftLim hab]
@[simp]
theorem measure_Ioo {a b : ℝ} : f.measure (Ioo a b) = ofReal (leftLim f b - f a) := by
rcases le_or_lt b a with (hab | hab)
· simp only [hab, measure_empty, Ioo_eq_empty, not_lt]
symm
simp [ENNReal.ofReal_eq_zero, f.mono.leftLim_le hab]
· have A : Disjoint (Ioo a b) {b} := by simp
have D : f b - f a = f b - leftLim f b + (leftLim f b - f a) := by abel
have := f.measure_Ioc a b
simp only [← Ioo_union_Icc_eq_Ioc hab le_rfl, measure_singleton,
measure_union A (measurableSet_singleton b), Icc_self] at this
rw [D, ENNReal.ofReal_add, add_comm] at this
· simpa only [ENNReal.add_right_inj ENNReal.ofReal_ne_top]
· simp only [f.mono.leftLim_le le_rfl, sub_nonneg]
· simp only [f.mono.le_leftLim hab, sub_nonneg]
@[simp]
theorem measure_Ico (a b : ℝ) : f.measure (Ico a b) = ofReal (leftLim f b - leftLim f a) := by
rcases le_or_lt b a with (hab | hab)
· simp only [hab, measure_empty, Ico_eq_empty, not_lt]
symm
simp [ENNReal.ofReal_eq_zero, f.mono.leftLim hab]
· have A : Disjoint {a} (Ioo a b) := by simp
simp [← Icc_union_Ioo_eq_Ico le_rfl hab, -singleton_union, hab.ne, f.mono.leftLim_le,
measure_union A measurableSet_Ioo, f.mono.le_leftLim hab, ← ENNReal.ofReal_add]
theorem measure_Iic {l : ℝ} (hf : Tendsto f atBot (𝓝 l)) (x : ℝ) :
f.measure (Iic x) = ofReal (f x - l) := by
refine tendsto_nhds_unique (tendsto_measure_Ioc_atBot _ _) ?_
simp_rw [measure_Ioc]
exact ENNReal.tendsto_ofReal (Tendsto.const_sub _ hf)
theorem measure_Ici {l : ℝ} (hf : Tendsto f atTop (𝓝 l)) (x : ℝ) :
f.measure (Ici x) = ofReal (l - leftLim f x) := by
refine tendsto_nhds_unique (tendsto_measure_Ico_atTop _ _) ?_
simp_rw [measure_Ico]
refine ENNReal.tendsto_ofReal (Tendsto.sub_const ?_ _)
have h_le1 : ∀ x, f (x - 1) ≤ leftLim f x := fun x => Monotone.le_leftLim f.mono (sub_one_lt x)
have h_le2 : ∀ x, leftLim f x ≤ f x := fun x => Monotone.leftLim_le f.mono le_rfl
refine tendsto_of_tendsto_of_tendsto_of_le_of_le (hf.comp ?_) hf h_le1 h_le2
rw [tendsto_atTop_atTop]
exact fun y => ⟨y + 1, fun z hyz => by rwa [le_sub_iff_add_le]⟩
theorem measure_univ {l u : ℝ} (hfl : Tendsto f atBot (𝓝 l)) (hfu : Tendsto f atTop (𝓝 u)) :
f.measure univ = ofReal (u - l) := by
refine tendsto_nhds_unique (tendsto_measure_Iic_atTop _) ?_
simp_rw [measure_Iic f hfl]
exact ENNReal.tendsto_ofReal (Tendsto.sub_const hfu _)
lemma isFiniteMeasure {l u : ℝ} (hfl : Tendsto f atBot (𝓝 l)) (hfu : Tendsto f atTop (𝓝 u)) :
IsFiniteMeasure f.measure := ⟨by simp [f.measure_univ hfl hfu]⟩
lemma isProbabilityMeasure (hf_bot : Tendsto f atBot (𝓝 0)) (hf_top : Tendsto f atTop (𝓝 1)) :
IsProbabilityMeasure f.measure := ⟨by simp [f.measure_univ hf_bot hf_top]⟩
instance instIsLocallyFiniteMeasure : IsLocallyFiniteMeasure f.measure :=
⟨fun x => ⟨Ioo (x - 1) (x + 1), Ioo_mem_nhds (by linarith) (by linarith), by simp⟩⟩
lemma eq_of_measure_of_tendsto_atBot (g : StieltjesFunction) {l : ℝ}
(hfg : f.measure = g.measure) (hfl : Tendsto f atBot (𝓝 l)) (hgl : Tendsto g atBot (𝓝 l)) :
f = g := by
ext x
have hf := measure_Iic f hfl x
rw [hfg, measure_Iic g hgl x, ENNReal.ofReal_eq_ofReal_iff, eq_comm] at hf
· simpa using hf
· rw [sub_nonneg]
exact Monotone.le_of_tendsto g.mono hgl x
· rw [sub_nonneg]
exact Monotone.le_of_tendsto f.mono hfl x
lemma eq_of_measure_of_eq (g : StieltjesFunction) {y : ℝ}
(hfg : f.measure = g.measure) (hy : f y = g y) :
f = g := by
ext x
cases le_total x y with
| inl hxy =>
have hf := measure_Ioc f x y
rw [hfg, measure_Ioc g x y, ENNReal.ofReal_eq_ofReal_iff, eq_comm, hy] at hf
· simpa using hf
· rw [sub_nonneg]
exact g.mono hxy
· rw [sub_nonneg]
exact f.mono hxy
| inr hxy =>
have hf := measure_Ioc f y x
rw [hfg, measure_Ioc g y x, ENNReal.ofReal_eq_ofReal_iff, eq_comm, hy] at hf
· simpa using hf
· rw [sub_nonneg]
exact g.mono hxy
· rw [sub_nonneg]
exact f.mono hxy
@[simp]
lemma measure_const (c : ℝ) : (StieltjesFunction.const c).measure = 0 :=
Measure.ext_of_Ioc _ _ (fun _ _ _ ↦ by simp)
@[simp]
lemma measure_add (f g : StieltjesFunction) : (f + g).measure = f.measure + g.measure := by
refine Measure.ext_of_Ioc _ _ (fun a b h ↦ ?_)
simp only [measure_Ioc, add_apply, Measure.coe_add, Pi.add_apply]
rw [← ENNReal.ofReal_add (sub_nonneg_of_le (f.mono h.le)) (sub_nonneg_of_le (g.mono h.le))]
ring_nf
@[simp]
lemma measure_smul (c : ℝ≥0) (f : StieltjesFunction) : (c • f).measure = c • f.measure := by
refine Measure.ext_of_Ioc _ _ (fun a b _ ↦ ?_)
simp only [measure_Ioc, Measure.smul_apply]
change ofReal (c * f b - c * f a) = c • ofReal (f b - f a)
rw [← _root_.mul_sub, ENNReal.ofReal_mul zero_le_coe, ofReal_coe_nnreal, ← smul_eq_mul]
rfl
end StieltjesFunction
|
MeasureTheory\Measure\Sub.lean | /-
Copyright (c) 2022 Martin Zinkevich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Zinkevich
-/
import Mathlib.MeasureTheory.Measure.Typeclasses
/-!
# Subtraction of measures
In this file we define `μ - ν` to be the least measure `τ` such that `μ ≤ τ + ν`.
It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures.
Compare with `ENNReal.instSub`.
Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and
`ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and
`ν univ ≠ ∞`, then `(μ - ν) + ν = μ`.
-/
open Set
namespace MeasureTheory
namespace Measure
/-- The measure `μ - ν` is defined to be the least measure `τ` such that `μ ≤ τ + ν`.
It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures.
Compare with `ENNReal.instSub`.
Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and
`ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and
`ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/
noncomputable instance instSub {α : Type*} [MeasurableSpace α] : Sub (Measure α) :=
⟨fun μ ν => sInf { τ | μ ≤ τ + ν }⟩
variable {α : Type*} {m : MeasurableSpace α} {μ ν : Measure α} {s : Set α}
theorem sub_def : μ - ν = sInf { d | μ ≤ d + ν } := rfl
theorem sub_le_of_le_add {d} (h : μ ≤ d + ν) : μ - ν ≤ d :=
sInf_le h
theorem sub_eq_zero_of_le (h : μ ≤ ν) : μ - ν = 0 :=
nonpos_iff_eq_zero'.1 <| sub_le_of_le_add <| by rwa [zero_add]
theorem sub_le : μ - ν ≤ μ :=
sub_le_of_le_add <| Measure.le_add_right le_rfl
@[simp]
theorem sub_top : μ - ⊤ = 0 :=
sub_eq_zero_of_le le_top
@[simp]
theorem zero_sub : 0 - μ = 0 :=
sub_eq_zero_of_le μ.zero_le
@[simp]
theorem sub_self : μ - μ = 0 :=
sub_eq_zero_of_le le_rfl
/-- This application lemma only works in special circumstances. Given knowledge of
when `μ ≤ ν` and `ν ≤ μ`, a more general application lemma can be written. -/
theorem sub_apply [IsFiniteMeasure ν] (h₁ : MeasurableSet s) (h₂ : ν ≤ μ) :
(μ - ν) s = μ s - ν s := by
-- We begin by defining `measure_sub`, which will be equal to `(μ - ν)`.
let measure_sub : Measure α := MeasureTheory.Measure.ofMeasurable
(fun (t : Set α) (_ : MeasurableSet t) => μ t - ν t) (by simp)
(fun g h_meas h_disj ↦ by
simp only [measure_iUnion h_disj h_meas]
rw [ENNReal.tsum_sub _ (h₂ <| g ·)]
rw [← measure_iUnion h_disj h_meas]
apply measure_ne_top)
-- Now, we demonstrate `μ - ν = measure_sub`, and apply it.
have h_measure_sub_add : ν + measure_sub = μ := by
ext1 t h_t_measurable_set
simp only [Pi.add_apply, coe_add]
rw [MeasureTheory.Measure.ofMeasurable_apply _ h_t_measurable_set, add_comm,
tsub_add_cancel_of_le (h₂ t)]
have h_measure_sub_eq : μ - ν = measure_sub := by
rw [MeasureTheory.Measure.sub_def]
apply le_antisymm
· apply sInf_le
simp [le_refl, add_comm, h_measure_sub_add]
apply le_sInf
intro d h_d
rw [← h_measure_sub_add, mem_setOf_eq, add_comm d] at h_d
apply Measure.le_of_add_le_add_left h_d
rw [h_measure_sub_eq]
apply Measure.ofMeasurable_apply _ h₁
theorem sub_add_cancel_of_le [IsFiniteMeasure ν] (h₁ : ν ≤ μ) : μ - ν + ν = μ := by
ext1 s h_s_meas
rw [add_apply, sub_apply h_s_meas h₁, tsub_add_cancel_of_le (h₁ s)]
@[simp]
lemma add_sub_cancel [IsFiniteMeasure ν] : μ + ν - ν = μ := by
ext1 s hs
rw [sub_apply hs (Measure.le_add_left (le_refl _)), add_apply,
ENNReal.add_sub_cancel_right (measure_ne_top ν s)]
theorem restrict_sub_eq_restrict_sub_restrict (h_meas_s : MeasurableSet s) :
(μ - ν).restrict s = μ.restrict s - ν.restrict s := by
repeat rw [sub_def]
have h_nonempty : { d | μ ≤ d + ν }.Nonempty := ⟨μ, Measure.le_add_right le_rfl⟩
rw [restrict_sInf_eq_sInf_restrict h_nonempty h_meas_s]
apply le_antisymm
· refine sInf_le_sInf_of_forall_exists_le ?_
intro ν' h_ν'_in
rw [mem_setOf_eq] at h_ν'_in
refine ⟨ν'.restrict s, ?_, restrict_le_self⟩
refine ⟨ν' + (⊤ : Measure α).restrict sᶜ, ?_, ?_⟩
· rw [mem_setOf_eq, add_right_comm, Measure.le_iff]
intro t h_meas_t
repeat rw [← measure_inter_add_diff t h_meas_s]
refine add_le_add ?_ ?_
· rw [add_apply, add_apply]
apply le_add_right _
rw [← restrict_eq_self μ inter_subset_right,
← restrict_eq_self ν inter_subset_right]
apply h_ν'_in
· rw [add_apply, restrict_apply (h_meas_t.diff h_meas_s), diff_eq, inter_assoc, inter_self,
← add_apply]
have h_mu_le_add_top : μ ≤ ν' + ν + ⊤ := by simp only [add_top, le_top]
exact Measure.le_iff'.1 h_mu_le_add_top _
· ext1 t h_meas_t
simp [restrict_apply h_meas_t, restrict_apply (h_meas_t.inter h_meas_s), inter_assoc]
· refine sInf_le_sInf_of_forall_exists_le ?_
refine forall_mem_image.2 fun t h_t_in => ⟨t.restrict s, ?_, le_rfl⟩
rw [Set.mem_setOf_eq, ← restrict_add]
exact restrict_mono Subset.rfl h_t_in
theorem sub_apply_eq_zero_of_restrict_le_restrict (h_le : μ.restrict s ≤ ν.restrict s)
(h_meas_s : MeasurableSet s) : (μ - ν) s = 0 := by
rw [← restrict_apply_self, restrict_sub_eq_restrict_sub_restrict, sub_eq_zero_of_le] <;> simp [*]
instance isFiniteMeasure_sub [IsFiniteMeasure μ] : IsFiniteMeasure (μ - ν) :=
isFiniteMeasure_of_le μ sub_le
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Tilted.lean | /-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Decomposition.RadonNikodym
/-!
# Exponentially tilted measures
The exponential tilting of a measure `μ` on `α` by a function `f : α → ℝ` is the measure with
density `x ↦ exp (f x) / ∫ y, exp (f y) ∂μ` with respect to `μ`. This is sometimes also called
the Esscher transform.
The definition is mostly used for `f` linear, in which case the exponentially tilted measure belongs
to the natural exponential family of the base measure. Exponentially tilted measures for general `f`
can be used for example to establish variational expressions for the Kullback-Leibler divergence.
## Main definitions
* `Measure.tilted μ f`: exponential tilting of `μ` by `f`, equal to
`μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))`.
-/
open Real
open scoped ENNReal NNReal
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} {f : α → ℝ}
/-- Exponentially tilted measure. When `x ↦ exp (f x)` is integrable, `μ.tilted f` is the
probability measure with density with respect to `μ` proportional to `exp (f x)`. Otherwise it is 0.
-/
noncomputable
def Measure.tilted (μ : Measure α) (f : α → ℝ) : Measure α :=
μ.withDensity (fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ))
@[simp]
lemma tilted_of_not_integrable (hf : ¬ Integrable (fun x ↦ exp (f x)) μ) : μ.tilted f = 0 := by
rw [Measure.tilted, integral_undef hf]
simp
@[simp]
lemma tilted_of_not_aemeasurable (hf : ¬ AEMeasurable f μ) : μ.tilted f = 0 := by
refine tilted_of_not_integrable ?_
suffices ¬ AEMeasurable (fun x ↦ exp (f x)) μ by exact fun h ↦ this h.1.aemeasurable
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h)
@[simp]
lemma tilted_zero_measure (f : α → ℝ) : (0 : Measure α).tilted f = 0 := by simp [Measure.tilted]
@[simp]
lemma tilted_const' (μ : Measure α) (c : ℝ) :
μ.tilted (fun _ ↦ c) = (μ Set.univ)⁻¹ • μ := by
cases eq_zero_or_neZero μ with
| inl h => rw [h]; simp
| inr h0 =>
simp only [Measure.tilted, withDensity_const, integral_const, smul_eq_mul]
by_cases h_univ : μ Set.univ = ∞
· simp only [h_univ, ENNReal.top_toReal, zero_mul, log_zero, div_zero, ENNReal.ofReal_zero,
zero_smul, ENNReal.inv_top]
congr
rw [div_eq_mul_inv, mul_inv, mul_comm, mul_assoc, inv_mul_cancel (exp_pos _).ne', mul_one,
← ENNReal.toReal_inv, ENNReal.ofReal_toReal]
simp [h0.out]
lemma tilted_const (μ : Measure α) [IsProbabilityMeasure μ] (c : ℝ) :
μ.tilted (fun _ ↦ c) = μ := by simp
@[simp]
lemma tilted_zero' (μ : Measure α) : μ.tilted 0 = (μ Set.univ)⁻¹ • μ := by
change μ.tilted (fun _ ↦ 0) = (μ Set.univ)⁻¹ • μ
simp
lemma tilted_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ.tilted 0 = μ := by simp
lemma tilted_congr {g : α → ℝ} (hfg : f =ᵐ[μ] g) :
μ.tilted f = μ.tilted g := by
have h_int_eq : ∫ x, exp (f x) ∂μ = ∫ x, exp (g x) ∂μ := by
refine integral_congr_ae ?_
filter_upwards [hfg] with x hx
rw [hx]
refine withDensity_congr_ae ?_
filter_upwards [hfg] with x hx
rw [h_int_eq, hx]
lemma tilted_eq_withDensity_nnreal (μ : Measure α) (f : α → ℝ) :
μ.tilted f = μ.withDensity (fun x ↦ ((↑) : ℝ≥0 → ℝ≥0∞)
(⟨exp (f x) / ∫ x, exp (f x) ∂μ, by positivity⟩ : ℝ≥0)) := by
rw [Measure.tilted]
congr with x
rw [ENNReal.ofReal_eq_coe_nnreal]
lemma tilted_apply' (μ : Measure α) (f : α → ℝ) {s : Set α} (hs : MeasurableSet s) :
μ.tilted f s = ∫⁻ a in s, ENNReal.ofReal (exp (f a) / ∫ x, exp (f x) ∂μ) ∂μ := by
rw [Measure.tilted, withDensity_apply _ hs]
lemma tilted_apply (μ : Measure α) [SFinite μ] (f : α → ℝ) (s : Set α) :
μ.tilted f s = ∫⁻ a in s, ENNReal.ofReal (exp (f a) / ∫ x, exp (f x) ∂μ) ∂μ := by
rw [Measure.tilted, withDensity_apply' _ s]
lemma tilted_apply_eq_ofReal_integral' {s : Set α} (f : α → ℝ) (hs : MeasurableSet s) :
μ.tilted f s = ENNReal.ofReal (∫ a in s, exp (f a) / ∫ x, exp (f x) ∂μ ∂μ) := by
by_cases hf : Integrable (fun x ↦ exp (f x)) μ
· rw [tilted_apply' _ _ hs, ← ofReal_integral_eq_lintegral_ofReal]
· exact hf.integrableOn.div_const _
· exact ae_of_all _ (fun _ ↦ by positivity)
· simp only [hf, not_false_eq_true, tilted_of_not_integrable, Measure.coe_zero,
Pi.zero_apply, integral_undef hf, div_zero, integral_zero, ENNReal.ofReal_zero]
lemma tilted_apply_eq_ofReal_integral [SFinite μ] (f : α → ℝ) (s : Set α) :
μ.tilted f s = ENNReal.ofReal (∫ a in s, exp (f a) / ∫ x, exp (f x) ∂μ ∂μ) := by
by_cases hf : Integrable (fun x ↦ exp (f x)) μ
· rw [tilted_apply _ _, ← ofReal_integral_eq_lintegral_ofReal]
· exact hf.integrableOn.div_const _
· exact ae_of_all _ (fun _ ↦ by positivity)
· simp [tilted_of_not_integrable hf, integral_undef hf]
instance isFiniteMeasure_tilted : IsFiniteMeasure (μ.tilted f) := by
by_cases hf : Integrable (fun x ↦ exp (f x)) μ
· refine isFiniteMeasure_withDensity_ofReal ?_
suffices Integrable (fun x ↦ exp (f x) / ∫ x, exp (f x) ∂μ) μ by exact this.2
exact hf.div_const _
· simp only [hf, not_false_eq_true, tilted_of_not_integrable]
infer_instance
lemma isProbabilityMeasure_tilted [NeZero μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
IsProbabilityMeasure (μ.tilted f) := by
constructor
simp_rw [tilted_apply' _ _ MeasurableSet.univ, setLIntegral_univ,
ENNReal.ofReal_div_of_pos (integral_exp_pos hf), div_eq_mul_inv]
rw [lintegral_mul_const'' _ hf.1.aemeasurable.ennreal_ofReal,
← ofReal_integral_eq_lintegral_ofReal hf (ae_of_all _ fun _ ↦ (exp_pos _).le),
ENNReal.mul_inv_cancel]
· simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]
exact integral_exp_pos hf
· simp
section lintegral
lemma setLIntegral_tilted' (f : α → ℝ) (g : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) :
∫⁻ x in s, g x ∂(μ.tilted f)
= ∫⁻ x in s, ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) * g x ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [Measure.tilted, setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀]
· simp only [Pi.mul_apply]
· refine AEMeasurable.restrict ?_
exact ((measurable_exp.comp_aemeasurable hf).div_const _).ennreal_ofReal
· exact hs
· filter_upwards
simp only [ENNReal.ofReal_lt_top, implies_true]
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
lintegral_zero_measure]
rw [integral_undef hf']
simp
@[deprecated (since := "2024-06-29")]
alias set_lintegral_tilted' := setLIntegral_tilted'
lemma setLIntegral_tilted [SFinite μ] (f : α → ℝ) (g : α → ℝ≥0∞) (s : Set α) :
∫⁻ x in s, g x ∂(μ.tilted f)
= ∫⁻ x in s, ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) * g x ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [Measure.tilted, setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀']
· simp only [Pi.mul_apply]
· refine AEMeasurable.restrict ?_
exact ((measurable_exp.comp_aemeasurable hf).div_const _).ennreal_ofReal
· filter_upwards
simp only [ENNReal.ofReal_lt_top, implies_true]
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
lintegral_zero_measure]
rw [integral_undef hf']
simp
@[deprecated (since := "2024-06-29")]
alias set_lintegral_tilted := setLIntegral_tilted
lemma lintegral_tilted (f : α → ℝ) (g : α → ℝ≥0∞) :
∫⁻ x, g x ∂(μ.tilted f)
= ∫⁻ x, ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) * (g x) ∂μ := by
rw [← setLIntegral_univ, setLIntegral_tilted' f g MeasurableSet.univ, setLIntegral_univ]
end lintegral
section integral
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
lemma setIntegral_tilted' (f : α → ℝ) (g : α → E) {s : Set α} (hs : MeasurableSet s) :
∫ x in s, g x ∂(μ.tilted f) = ∫ x in s, (exp (f x) / ∫ x, exp (f x) ∂μ) • (g x) ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [tilted_eq_withDensity_nnreal, setIntegral_withDensity_eq_setIntegral_smul₀ _ _ hs]
· congr
· suffices AEMeasurable (fun x ↦ exp (f x) / ∫ x, exp (f x) ∂μ) μ by
rw [← aemeasurable_coe_nnreal_real_iff]
refine AEMeasurable.restrict ?_
simpa only [NNReal.coe_mk]
exact (measurable_exp.comp_aemeasurable hf).div_const _
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
integral_zero_measure]
rw [integral_undef hf']
simp
@[deprecated (since := "2024-04-17")]
alias set_integral_tilted' := setIntegral_tilted'
lemma setIntegral_tilted [SFinite μ] (f : α → ℝ) (g : α → E) (s : Set α) :
∫ x in s, g x ∂(μ.tilted f) = ∫ x in s, (exp (f x) / ∫ x, exp (f x) ∂μ) • (g x) ∂μ := by
by_cases hf : AEMeasurable f μ
· rw [tilted_eq_withDensity_nnreal, setIntegral_withDensity_eq_setIntegral_smul₀']
· congr
· suffices AEMeasurable (fun x ↦ exp (f x) / ∫ x, exp (f x) ∂μ) μ by
rw [← aemeasurable_coe_nnreal_real_iff]
refine AEMeasurable.restrict ?_
simpa only [NNReal.coe_mk]
exact (measurable_exp.comp_aemeasurable hf).div_const _
· have hf' : ¬ Integrable (fun x ↦ exp (f x)) μ := by
exact fun h ↦ hf (aemeasurable_of_aemeasurable_exp h.1.aemeasurable)
simp only [hf, not_false_eq_true, tilted_of_not_aemeasurable, Measure.restrict_zero,
integral_zero_measure]
rw [integral_undef hf']
simp
@[deprecated (since := "2024-04-17")]
alias set_integral_tilted := setIntegral_tilted
lemma integral_tilted (f : α → ℝ) (g : α → E) :
∫ x, g x ∂(μ.tilted f) = ∫ x, (exp (f x) / ∫ x, exp (f x) ∂μ) • (g x) ∂μ := by
rw [← integral_univ, setIntegral_tilted' f g MeasurableSet.univ, integral_univ]
end integral
lemma integral_exp_tilted (f g : α → ℝ) :
∫ x, exp (g x) ∂(μ.tilted f) = (∫ x, exp ((f + g) x) ∂μ) / ∫ x, exp (f x) ∂μ := by
cases eq_zero_or_neZero μ with
| inl h => rw [h]; simp
| inr h0 =>
rw [integral_tilted f]
simp_rw [smul_eq_mul]
have : ∀ x, (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * rexp (g x)
= (rexp ((f + g) x) / ∫ (x : α), rexp (f x) ∂μ) := by
intro x
rw [Pi.add_apply, exp_add]
ring
simp_rw [this, div_eq_mul_inv]
rw [integral_mul_right]
lemma tilted_tilted (hf : Integrable (fun x ↦ exp (f x)) μ) (g : α → ℝ) :
(μ.tilted f).tilted g = μ.tilted (f + g) := by
cases eq_zero_or_neZero μ with
| inl h => simp [h]
| inr h0 =>
ext1 s hs
rw [tilted_apply' _ _ hs, tilted_apply' _ _ hs, setLIntegral_tilted' f _ hs]
congr with x
rw [← ENNReal.ofReal_mul (by positivity),
integral_exp_tilted f, Pi.add_apply, exp_add]
congr 1
simp only [Pi.add_apply]
field_simp
ring_nf
congr 1
rw [mul_assoc, mul_inv_cancel, mul_one]
exact (integral_exp_pos hf).ne'
lemma tilted_comm (hf : Integrable (fun x ↦ exp (f x)) μ) {g : α → ℝ}
(hg : Integrable (fun x ↦ exp (g x)) μ) :
(μ.tilted f).tilted g = (μ.tilted g).tilted f := by
rw [tilted_tilted hf, add_comm, tilted_tilted hg]
@[simp]
lemma tilted_neg_same' (hf : Integrable (fun x ↦ exp (f x)) μ) :
(μ.tilted f).tilted (-f) = (μ Set.univ)⁻¹ • μ := by
rw [tilted_tilted hf]; simp
@[simp]
lemma tilted_neg_same [IsProbabilityMeasure μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
(μ.tilted f).tilted (-f) = μ := by
simp [hf]
lemma tilted_absolutelyContinuous (μ : Measure α) (f : α → ℝ) : μ.tilted f ≪ μ :=
withDensity_absolutelyContinuous _ _
lemma absolutelyContinuous_tilted (hf : Integrable (fun x ↦ exp (f x)) μ) : μ ≪ μ.tilted f := by
cases eq_zero_or_neZero μ with
| inl h => simp only [h, tilted_zero_measure]; exact fun _ _ ↦ by simp
| inr h0 =>
refine withDensity_absolutelyContinuous' ?_ ?_
· exact (hf.1.aemeasurable.div_const _).ennreal_ofReal
· filter_upwards
simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]
exact fun _ ↦ div_pos (exp_pos _) (integral_exp_pos hf)
lemma rnDeriv_tilted_right (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν]
(hf : Integrable (fun x ↦ exp (f x)) ν) :
μ.rnDeriv (ν.tilted f)
=ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (- f x) * ∫ x, exp (f x) ∂ν) * μ.rnDeriv ν x := by
cases eq_zero_or_neZero ν with
| inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
| inr h0 =>
refine (Measure.rnDeriv_withDensity_right μ ν ?_ ?_ ?_).trans ?_
· exact (hf.1.aemeasurable.div_const _).ennreal_ofReal
· filter_upwards
simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]
exact fun _ ↦ div_pos (exp_pos _) (integral_exp_pos hf)
· refine ae_of_all _ (by simp)
· filter_upwards with x
congr
rw [← ENNReal.ofReal_inv_of_pos, inv_div', ← exp_neg, div_eq_mul_inv, inv_inv]
exact div_pos (exp_pos _) (integral_exp_pos hf)
lemma toReal_rnDeriv_tilted_right (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν]
(hf : Integrable (fun x ↦ exp (f x)) ν) :
(fun x ↦ (μ.rnDeriv (ν.tilted f) x).toReal)
=ᵐ[ν] fun x ↦ exp (- f x) * (∫ x, exp (f x) ∂ν) * (μ.rnDeriv ν x).toReal := by
filter_upwards [rnDeriv_tilted_right μ ν hf] with x hx
rw [hx]
simp only [ENNReal.toReal_mul, gt_iff_lt, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
exact Or.inl (by positivity)
variable (μ) in
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν] (hfν : AEMeasurable f ν) :
(μ.tilted f).rnDeriv ν
=ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_
· exact ((measurable_exp.comp_aemeasurable hfν).div_const _).ennreal_ofReal
· exact ae_of_all _ (fun x ↦ by simp [g])
variable (μ) in
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
(hfν : AEMeasurable f ν) :
(fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
=ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
filter_upwards [rnDeriv_tilted_left μ hfν] with x hx
rw [hx]
simp only [ENNReal.toReal_mul, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
exact Or.inl (by positivity)
lemma rnDeriv_tilted_left_self [SigmaFinite μ] (hf : AEMeasurable f μ) :
(μ.tilted f).rnDeriv μ =ᵐ[μ] fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) := by
refine (rnDeriv_tilted_left μ hf).trans ?_
filter_upwards [Measure.rnDeriv_self μ] with x hx
rw [hx, mul_one]
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
(fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
=ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
cases eq_zero_or_neZero μ with
| inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
| inr h0 =>
have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
rw [hx, ENNReal.toReal_ofReal (by positivity), log_div (exp_pos _).ne', log_exp]
exact (integral_exp_pos hf).ne'
end MeasureTheory
|
MeasureTheory\Measure\Trim.lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Measure.Typeclasses
/-!
# Restriction of a measure to a sub-σ-algebra
## Main definitions
* `MeasureTheory.Measure.trim`: restriction of a measure to a sub-sigma algebra.
-/
open scoped ENNReal
namespace MeasureTheory
variable {α : Type*}
/-- Restriction of a measure to a sub-σ-algebra.
It is common to see a measure `μ` on a measurable space structure `m0` as being also a measure on
any `m ≤ m0`. Since measures in mathlib have to be trimmed to the measurable space, `μ` itself
cannot be a measure on `m`, hence the definition of `μ.trim hm`.
This notion is related to `OuterMeasure.trim`, see the lemma
`toOuterMeasure_trim_eq_trim_toOuterMeasure`. -/
noncomputable
def Measure.trim {m m0 : MeasurableSpace α} (μ : @Measure α m0) (hm : m ≤ m0) : @Measure α m :=
@OuterMeasure.toMeasure α m μ.toOuterMeasure (hm.trans (le_toOuterMeasure_caratheodory μ))
@[simp]
theorem trim_eq_self [MeasurableSpace α] {μ : Measure α} : μ.trim le_rfl = μ := by
simp [Measure.trim]
variable {m m0 : MeasurableSpace α} {μ : Measure α} {s : Set α}
theorem toOuterMeasure_trim_eq_trim_toOuterMeasure (μ : Measure α) (hm : m ≤ m0) :
@Measure.toOuterMeasure _ m (μ.trim hm) = @OuterMeasure.trim _ m μ.toOuterMeasure := by
rw [Measure.trim, toMeasure_toOuterMeasure (ms := m)]
@[simp]
theorem zero_trim (hm : m ≤ m0) : (0 : Measure α).trim hm = (0 : @Measure α m) := by
simp [Measure.trim, @OuterMeasure.toMeasure_zero _ m]
theorem trim_measurableSet_eq (hm : m ≤ m0) (hs : @MeasurableSet α m s) : μ.trim hm s = μ s := by
rw [Measure.trim, toMeasure_apply (ms := m) _ _ hs, Measure.coe_toOuterMeasure]
theorem le_trim (hm : m ≤ m0) : μ s ≤ μ.trim hm s := by
simp_rw [Measure.trim]
exact @le_toMeasure_apply _ m _ _ _
lemma trim_add {ν : Measure α} (hm : m ≤ m0) : (μ + ν).trim hm = μ.trim hm + ν.trim hm :=
@Measure.ext _ m _ _ (fun s hs ↦ by simp [trim_measurableSet_eq hm hs])
theorem measure_eq_zero_of_trim_eq_zero (hm : m ≤ m0) (h : μ.trim hm s = 0) : μ s = 0 :=
le_antisymm ((le_trim hm).trans (le_of_eq h)) (zero_le _)
theorem measure_trim_toMeasurable_eq_zero {hm : m ≤ m0} (hs : μ.trim hm s = 0) :
μ (@toMeasurable α m (μ.trim hm) s) = 0 :=
measure_eq_zero_of_trim_eq_zero hm (by rwa [@measure_toMeasurable _ m])
theorem ae_of_ae_trim (hm : m ≤ m0) {μ : Measure α} {P : α → Prop} (h : ∀ᵐ x ∂μ.trim hm, P x) :
∀ᵐ x ∂μ, P x :=
measure_eq_zero_of_trim_eq_zero hm h
theorem ae_eq_of_ae_eq_trim {E} {hm : m ≤ m0} {f₁ f₂ : α → E}
(h12 : f₁ =ᵐ[μ.trim hm] f₂) : f₁ =ᵐ[μ] f₂ :=
measure_eq_zero_of_trim_eq_zero hm h12
theorem ae_le_of_ae_le_trim {E} [LE E] {hm : m ≤ m0} {f₁ f₂ : α → E}
(h12 : f₁ ≤ᵐ[μ.trim hm] f₂) : f₁ ≤ᵐ[μ] f₂ :=
measure_eq_zero_of_trim_eq_zero hm h12
theorem trim_trim {m₁ m₂ : MeasurableSpace α} {hm₁₂ : m₁ ≤ m₂} {hm₂ : m₂ ≤ m0} :
(μ.trim hm₂).trim hm₁₂ = μ.trim (hm₁₂.trans hm₂) := by
refine @Measure.ext _ m₁ _ _ (fun t ht => ?_)
rw [trim_measurableSet_eq hm₁₂ ht, trim_measurableSet_eq (hm₁₂.trans hm₂) ht,
trim_measurableSet_eq hm₂ (hm₁₂ t ht)]
theorem restrict_trim (hm : m ≤ m0) (μ : Measure α) (hs : @MeasurableSet α m s) :
@Measure.restrict α m (μ.trim hm) s = (μ.restrict s).trim hm := by
refine @Measure.ext _ m _ _ (fun t ht => ?_)
rw [@Measure.restrict_apply α m _ _ _ ht, trim_measurableSet_eq hm ht,
Measure.restrict_apply (hm t ht),
trim_measurableSet_eq hm (@MeasurableSet.inter α m t s ht hs)]
instance isFiniteMeasure_trim (hm : m ≤ m0) [IsFiniteMeasure μ] : IsFiniteMeasure (μ.trim hm) where
measure_univ_lt_top := by
rw [trim_measurableSet_eq hm (@MeasurableSet.univ _ m)]
exact measure_lt_top _ _
theorem sigmaFiniteTrim_mono {m m₂ m0 : MeasurableSpace α} {μ : Measure α} (hm : m ≤ m0)
(hm₂ : m₂ ≤ m) [SigmaFinite (μ.trim (hm₂.trans hm))] : SigmaFinite (μ.trim hm) := by
refine ⟨⟨?_⟩⟩
refine
{ set := spanningSets (μ.trim (hm₂.trans hm))
set_mem := fun _ => Set.mem_univ _
finite := fun i => ?_
spanning := iUnion_spanningSets _ }
calc
(μ.trim hm) (spanningSets (μ.trim (hm₂.trans hm)) i) =
((μ.trim hm).trim hm₂) (spanningSets (μ.trim (hm₂.trans hm)) i) := by
rw [@trim_measurableSet_eq α m₂ m (μ.trim hm) _ hm₂ (measurable_spanningSets _ _)]
_ = (μ.trim (hm₂.trans hm)) (spanningSets (μ.trim (hm₂.trans hm)) i) := by
rw [@trim_trim _ _ μ _ _ hm₂ hm]
_ < ∞ := measure_spanningSets_lt_top _ _
theorem sigmaFinite_trim_bot_iff : SigmaFinite (μ.trim bot_le) ↔ IsFiniteMeasure μ := by
rw [sigmaFinite_bot_iff]
refine ⟨fun h => ⟨?_⟩, fun h => ⟨?_⟩⟩ <;> have h_univ := h.measure_univ_lt_top
· rwa [trim_measurableSet_eq bot_le MeasurableSet.univ] at h_univ
· rwa [trim_measurableSet_eq bot_le MeasurableSet.univ]
lemma Measure.AbsolutelyContinuous.trim {ν : Measure α} (hμν : μ ≪ ν) (hm : m ≤ m0) :
μ.trim hm ≪ ν.trim hm := by
refine Measure.AbsolutelyContinuous.mk (fun s hs hsν ↦ ?_)
rw [trim_measurableSet_eq hm hs] at hsν ⊢
exact hμν hsν
end MeasureTheory
|
MeasureTheory\Measure\Typeclasses.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Restrict
/-!
# Classes of measures
We introduce the following typeclasses for measures:
* `IsProbabilityMeasure μ`: `μ univ = 1`;
* `IsFiniteMeasure μ`: `μ univ < ∞`;
* `SigmaFinite μ`: there exists a countable collection of sets that cover `univ`
where `μ` is finite;
* `SFinite μ`: the measure `μ` can be written as a countable sum of finite measures;
* `IsLocallyFiniteMeasure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`;
* `NoAtoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as
`∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter Function MeasurableSpace ENNReal
variable {α β δ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] {μ ν ν₁ ν₂ : Measure α}
{s t : Set α}
section IsFiniteMeasure
/-- A measure `μ` is called finite if `μ univ < ∞`. -/
class IsFiniteMeasure (μ : Measure α) : Prop where
measure_univ_lt_top : μ univ < ∞
theorem not_isFiniteMeasure_iff : ¬IsFiniteMeasure μ ↔ μ Set.univ = ∞ := by
refine ⟨fun h => ?_, fun h => fun h' => h'.measure_univ_lt_top.ne h⟩
by_contra h'
exact h ⟨lt_top_iff_ne_top.mpr h'⟩
instance Restrict.isFiniteMeasure (μ : Measure α) [hs : Fact (μ s < ∞)] :
IsFiniteMeasure (μ.restrict s) :=
⟨by simpa using hs.elim⟩
theorem measure_lt_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s < ∞ :=
(measure_mono (subset_univ s)).trans_lt IsFiniteMeasure.measure_univ_lt_top
instance isFiniteMeasureRestrict (μ : Measure α) (s : Set α) [h : IsFiniteMeasure μ] :
IsFiniteMeasure (μ.restrict s) :=
⟨by simpa using measure_lt_top μ s⟩
theorem measure_ne_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s ≠ ∞ :=
ne_of_lt (measure_lt_top μ s)
theorem measure_compl_le_add_of_le_add [IsFiniteMeasure μ] (hs : MeasurableSet s)
(ht : MeasurableSet t) {ε : ℝ≥0∞} (h : μ s ≤ μ t + ε) : μ tᶜ ≤ μ sᶜ + ε := by
rw [measure_compl ht (measure_ne_top μ _), measure_compl hs (measure_ne_top μ _),
tsub_le_iff_right]
calc
μ univ = μ univ - μ s + μ s := (tsub_add_cancel_of_le <| measure_mono s.subset_univ).symm
_ ≤ μ univ - μ s + (μ t + ε) := add_le_add_left h _
_ = _ := by rw [add_right_comm, add_assoc]
theorem measure_compl_le_add_iff [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t)
{ε : ℝ≥0∞} : μ sᶜ ≤ μ tᶜ + ε ↔ μ t ≤ μ s + ε :=
⟨fun h => compl_compl s ▸ compl_compl t ▸ measure_compl_le_add_of_le_add hs.compl ht.compl h,
measure_compl_le_add_of_le_add ht hs⟩
/-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/
def measureUnivNNReal (μ : Measure α) : ℝ≥0 :=
(μ univ).toNNReal
@[simp]
theorem coe_measureUnivNNReal (μ : Measure α) [IsFiniteMeasure μ] :
↑(measureUnivNNReal μ) = μ univ :=
ENNReal.coe_toNNReal (measure_ne_top μ univ)
instance isFiniteMeasureZero : IsFiniteMeasure (0 : Measure α) :=
⟨by simp⟩
instance (priority := 50) isFiniteMeasureOfIsEmpty [IsEmpty α] : IsFiniteMeasure μ := by
rw [eq_zero_of_isEmpty μ]
infer_instance
@[simp]
theorem measureUnivNNReal_zero : measureUnivNNReal (0 : Measure α) = 0 :=
rfl
instance isFiniteMeasureAdd [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteMeasure (μ + ν) where
measure_univ_lt_top := by
rw [Measure.coe_add, Pi.add_apply, ENNReal.add_lt_top]
exact ⟨measure_lt_top _ _, measure_lt_top _ _⟩
instance isFiniteMeasureSMulNNReal [IsFiniteMeasure μ] {r : ℝ≥0} : IsFiniteMeasure (r • μ) where
measure_univ_lt_top := ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_ne_top _ _)
instance IsFiniteMeasure.average : IsFiniteMeasure ((μ univ)⁻¹ • μ) where
measure_univ_lt_top := by
rw [smul_apply, smul_eq_mul, ← ENNReal.div_eq_inv_mul]
exact ENNReal.div_self_le_one.trans_lt ENNReal.one_lt_top
instance isFiniteMeasureSMulOfNNRealTower {R} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] [IsFiniteMeasure μ] {r : R} : IsFiniteMeasure (r • μ) := by
rw [← smul_one_smul ℝ≥0 r μ]
infer_instance
theorem isFiniteMeasure_of_le (μ : Measure α) [IsFiniteMeasure μ] (h : ν ≤ μ) : IsFiniteMeasure ν :=
{ measure_univ_lt_top := (h Set.univ).trans_lt (measure_lt_top _ _) }
@[instance]
theorem Measure.isFiniteMeasure_map {m : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ]
(f : α → β) : IsFiniteMeasure (μ.map f) := by
by_cases hf : AEMeasurable f μ
· constructor
rw [map_apply_of_aemeasurable hf MeasurableSet.univ]
exact measure_lt_top μ _
· rw [map_of_not_aemeasurable hf]
exact MeasureTheory.isFiniteMeasureZero
@[simp]
theorem measureUnivNNReal_eq_zero [IsFiniteMeasure μ] : measureUnivNNReal μ = 0 ↔ μ = 0 := by
rw [← MeasureTheory.Measure.measure_univ_eq_zero, ← coe_measureUnivNNReal]
norm_cast
theorem measureUnivNNReal_pos [IsFiniteMeasure μ] (hμ : μ ≠ 0) : 0 < measureUnivNNReal μ := by
contrapose! hμ
simpa [measureUnivNNReal_eq_zero, Nat.le_zero] using hμ
/-- `le_of_add_le_add_left` is normally applicable to `OrderedCancelAddCommMonoid`,
but it holds for measures with the additional assumption that μ is finite. -/
theorem Measure.le_of_add_le_add_left [IsFiniteMeasure μ] (A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ :=
fun S => ENNReal.le_of_add_le_add_left (MeasureTheory.measure_ne_top μ S) (A2 S)
theorem summable_measure_toReal [hμ : IsFiniteMeasure μ] {f : ℕ → Set α}
(hf₁ : ∀ i : ℕ, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) :
Summable fun x => (μ (f x)).toReal := by
apply ENNReal.summable_toReal
rw [← MeasureTheory.measure_iUnion hf₂ hf₁]
exact ne_of_lt (measure_lt_top _ _)
theorem ae_eq_univ_iff_measure_eq [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ) :
s =ᵐ[μ] univ ↔ μ s = μ univ := by
refine ⟨measure_congr, fun h => ?_⟩
obtain ⟨t, -, ht₁, ht₂⟩ := hs.exists_measurable_subset_ae_eq
exact
ht₂.symm.trans
(ae_eq_of_subset_of_measure_ge (subset_univ t) (Eq.le ((measure_congr ht₂).trans h).symm) ht₁
(measure_ne_top μ univ))
theorem ae_iff_measure_eq [IsFiniteMeasure μ] {p : α → Prop}
(hp : NullMeasurableSet { a | p a } μ) : (∀ᵐ a ∂μ, p a) ↔ μ { a | p a } = μ univ := by
rw [← ae_eq_univ_iff_measure_eq hp, eventuallyEq_univ, eventually_iff]
theorem ae_mem_iff_measure_eq [IsFiniteMeasure μ] {s : Set α} (hs : NullMeasurableSet s μ) :
(∀ᵐ a ∂μ, a ∈ s) ↔ μ s = μ univ :=
ae_iff_measure_eq hs
lemma tendsto_measure_biUnion_Ici_zero_of_pairwise_disjoint
{X : Type*} [MeasurableSpace X] {μ : Measure X} [IsFiniteMeasure μ]
{Es : ℕ → Set X} (Es_mble : ∀ i, MeasurableSet (Es i))
(Es_disj : Pairwise fun n m ↦ Disjoint (Es n) (Es m)) :
Tendsto (μ ∘ fun n ↦ ⋃ i ≥ n, Es i) atTop (𝓝 0) := by
have decr : Antitone fun n ↦ ⋃ i ≥ n, Es i :=
fun n m hnm ↦ biUnion_mono (fun _ hi ↦ le_trans hnm hi) (fun _ _ ↦ subset_rfl)
have nothing : ⋂ n, ⋃ i ≥ n, Es i = ∅ := by
apply subset_antisymm _ (empty_subset _)
intro x hx
simp only [mem_iInter, mem_iUnion, exists_prop] at hx
obtain ⟨j, _, x_in_Es_j⟩ := hx 0
obtain ⟨k, k_gt_j, x_in_Es_k⟩ := hx (j+1)
have oops := (Es_disj (Nat.ne_of_lt k_gt_j)).ne_of_mem x_in_Es_j x_in_Es_k
contradiction
have key :=
tendsto_measure_iInter (μ := μ) (fun n ↦ by measurability) decr ⟨0, measure_ne_top _ _⟩
simp only [nothing, measure_empty] at key
convert key
open scoped symmDiff
theorem abs_toReal_measure_sub_le_measure_symmDiff'
(hs : MeasurableSet s) (ht : MeasurableSet t) (hs' : μ s ≠ ∞) (ht' : μ t ≠ ∞) :
|(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal := by
have hst : μ (s \ t) ≠ ∞ := (measure_lt_top_of_subset diff_subset hs').ne
have hts : μ (t \ s) ≠ ∞ := (measure_lt_top_of_subset diff_subset ht').ne
suffices (μ s).toReal - (μ t).toReal = (μ (s \ t)).toReal - (μ (t \ s)).toReal by
rw [this, measure_symmDiff_eq hs ht, ENNReal.toReal_add hst hts]
convert abs_sub (μ (s \ t)).toReal (μ (t \ s)).toReal <;> simp
rw [measure_diff' s ht ht', measure_diff' t hs hs',
ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top hs' ht'),
ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top ht' hs'),
union_comm t s]
abel
theorem abs_toReal_measure_sub_le_measure_symmDiff [IsFiniteMeasure μ]
(hs : MeasurableSet s) (ht : MeasurableSet t) :
|(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal :=
abs_toReal_measure_sub_le_measure_symmDiff' hs ht (measure_ne_top μ s) (measure_ne_top μ t)
end IsFiniteMeasure
section IsProbabilityMeasure
/-- A measure `μ` is called a probability measure if `μ univ = 1`. -/
class IsProbabilityMeasure (μ : Measure α) : Prop where
measure_univ : μ univ = 1
export MeasureTheory.IsProbabilityMeasure (measure_univ)
attribute [simp] IsProbabilityMeasure.measure_univ
lemma isProbabilityMeasure_iff : IsProbabilityMeasure μ ↔ μ univ = 1 :=
⟨fun _ ↦ measure_univ, IsProbabilityMeasure.mk⟩
instance (priority := 100) IsProbabilityMeasure.toIsFiniteMeasure (μ : Measure α)
[IsProbabilityMeasure μ] : IsFiniteMeasure μ :=
⟨by simp only [measure_univ, ENNReal.one_lt_top]⟩
theorem IsProbabilityMeasure.ne_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ ≠ 0 :=
mt measure_univ_eq_zero.2 <| by simp [measure_univ]
instance (priority := 100) IsProbabilityMeasure.neZero (μ : Measure α) [IsProbabilityMeasure μ] :
NeZero μ := ⟨IsProbabilityMeasure.ne_zero μ⟩
-- Porting note: no longer an `instance` because `inferInstance` can find it now
theorem IsProbabilityMeasure.ae_neBot [IsProbabilityMeasure μ] : NeBot (ae μ) := inferInstance
theorem prob_add_prob_compl [IsProbabilityMeasure μ] (h : MeasurableSet s) : μ s + μ sᶜ = 1 :=
(measure_add_measure_compl h).trans measure_univ
theorem prob_le_one [IsProbabilityMeasure μ] : μ s ≤ 1 :=
(measure_mono <| Set.subset_univ _).trans_eq measure_univ
-- Porting note: made an `instance`, using `NeZero`
instance isProbabilityMeasureSMul [IsFiniteMeasure μ] [NeZero μ] :
IsProbabilityMeasure ((μ univ)⁻¹ • μ) :=
⟨ENNReal.inv_mul_cancel (NeZero.ne (μ univ)) (measure_ne_top _ _)⟩
variable [IsProbabilityMeasure μ] {p : α → Prop} {f : β → α}
theorem isProbabilityMeasure_map {f : α → β} (hf : AEMeasurable f μ) :
IsProbabilityMeasure (map f μ) :=
⟨by simp [map_apply_of_aemeasurable, hf]⟩
@[simp]
theorem one_le_prob_iff : 1 ≤ μ s ↔ μ s = 1 :=
⟨fun h => le_antisymm prob_le_one h, fun h => h ▸ le_refl _⟩
/-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`.
Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the
better-behaved subtraction of `ℝ`. -/
lemma prob_compl_eq_one_sub₀ (h : NullMeasurableSet s μ) : μ sᶜ = 1 - μ s := by
rw [measure_compl₀ h (measure_ne_top _ _), measure_univ]
/-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`.
Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the
better-behaved subtraction of `ℝ`. -/
theorem prob_compl_eq_one_sub (hs : MeasurableSet s) : μ sᶜ = 1 - μ s :=
prob_compl_eq_one_sub₀ hs.nullMeasurableSet
lemma prob_compl_lt_one_sub_of_lt_prob {p : ℝ≥0∞} (hμs : p < μ s) (s_mble : MeasurableSet s) :
μ sᶜ < 1 - p := by
rw [prob_compl_eq_one_sub s_mble]
apply ENNReal.sub_lt_of_sub_lt prob_le_one (Or.inl one_ne_top)
convert hμs
exact ENNReal.sub_sub_cancel one_ne_top (lt_of_lt_of_le hμs prob_le_one).le
lemma prob_compl_le_one_sub_of_le_prob {p : ℝ≥0∞} (hμs : p ≤ μ s) (s_mble : MeasurableSet s) :
μ sᶜ ≤ 1 - p := by
simpa [prob_compl_eq_one_sub s_mble] using tsub_le_tsub_left hμs 1
@[simp] lemma prob_compl_eq_zero_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 0 ↔ μ s = 1 := by
rw [prob_compl_eq_one_sub₀ hs, tsub_eq_zero_iff_le, one_le_prob_iff]
@[simp] lemma prob_compl_eq_zero_iff (hs : MeasurableSet s) : μ sᶜ = 0 ↔ μ s = 1 :=
prob_compl_eq_zero_iff₀ hs.nullMeasurableSet
@[simp] lemma prob_compl_eq_one_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 1 ↔ μ s = 0 := by
rw [← prob_compl_eq_zero_iff₀ hs.compl, compl_compl]
@[simp] lemma prob_compl_eq_one_iff (hs : MeasurableSet s) : μ sᶜ = 1 ↔ μ s = 0 :=
prob_compl_eq_one_iff₀ hs.nullMeasurableSet
lemma mem_ae_iff_prob_eq_one₀ (hs : NullMeasurableSet s μ) : s ∈ ae μ ↔ μ s = 1 :=
mem_ae_iff.trans <| prob_compl_eq_zero_iff₀ hs
lemma mem_ae_iff_prob_eq_one (hs : MeasurableSet s) : s ∈ ae μ ↔ μ s = 1 :=
mem_ae_iff.trans <| prob_compl_eq_zero_iff hs
lemma ae_iff_prob_eq_one (hp : Measurable p) : (∀ᵐ a ∂μ, p a) ↔ μ {a | p a} = 1 :=
mem_ae_iff_prob_eq_one hp.setOf
lemma isProbabilityMeasure_comap (hf : Injective f) (hf' : ∀ᵐ a ∂μ, a ∈ range f)
(hf'' : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) :
IsProbabilityMeasure (μ.comap f) where
measure_univ := by
rw [comap_apply _ hf hf'' _ MeasurableSet.univ,
← mem_ae_iff_prob_eq_one (hf'' _ MeasurableSet.univ)]
simpa
protected lemma _root_.MeasurableEmbedding.isProbabilityMeasure_comap (hf : MeasurableEmbedding f)
(hf' : ∀ᵐ a ∂μ, a ∈ range f) : IsProbabilityMeasure (μ.comap f) :=
isProbabilityMeasure_comap hf.injective hf' hf.measurableSet_image'
instance isProbabilityMeasure_map_up :
IsProbabilityMeasure (μ.map ULift.up) := isProbabilityMeasure_map measurable_up.aemeasurable
instance isProbabilityMeasure_comap_down : IsProbabilityMeasure (μ.comap ULift.down) :=
MeasurableEquiv.ulift.measurableEmbedding.isProbabilityMeasure_comap <| ae_of_all _ <| by
simp [Function.Surjective.range_eq <| EquivLike.surjective _]
end IsProbabilityMeasure
section NoAtoms
/-- Measure `μ` *has no atoms* if the measure of each singleton is zero.
NB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure,
there exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`,
the converse is not true. -/
class NoAtoms {m0 : MeasurableSpace α} (μ : Measure α) : Prop where
measure_singleton : ∀ x, μ {x} = 0
export MeasureTheory.NoAtoms (measure_singleton)
attribute [simp] measure_singleton
variable [NoAtoms μ]
theorem _root_.Set.Subsingleton.measure_zero (hs : s.Subsingleton) (μ : Measure α) [NoAtoms μ] :
μ s = 0 :=
hs.induction_on (p := fun s => μ s = 0) measure_empty measure_singleton
theorem Measure.restrict_singleton' {a : α} : μ.restrict {a} = 0 := by
simp only [measure_singleton, Measure.restrict_eq_zero]
instance Measure.restrict.instNoAtoms (s : Set α) : NoAtoms (μ.restrict s) := by
refine ⟨fun x => ?_⟩
obtain ⟨t, hxt, ht1, ht2⟩ := exists_measurable_superset_of_null (measure_singleton x : μ {x} = 0)
apply measure_mono_null hxt
rw [Measure.restrict_apply ht1]
apply measure_mono_null inter_subset_left ht2
theorem _root_.Set.Countable.measure_zero (h : s.Countable) (μ : Measure α) [NoAtoms μ] :
μ s = 0 := by
rw [← biUnion_of_singleton s, measure_biUnion_null_iff h]
simp
theorem _root_.Set.Countable.ae_not_mem (h : s.Countable) (μ : Measure α) [NoAtoms μ] :
∀ᵐ x ∂μ, x ∉ s := by
simpa only [ae_iff, Classical.not_not] using h.measure_zero μ
lemma _root_.Set.Countable.measure_restrict_compl (h : s.Countable) (μ : Measure α) [NoAtoms μ] :
μ.restrict sᶜ = μ :=
restrict_eq_self_of_ae_mem <| h.ae_not_mem μ
@[simp]
lemma restrict_compl_singleton (a : α) : μ.restrict ({a}ᶜ) = μ :=
(countable_singleton _).measure_restrict_compl μ
theorem _root_.Set.Finite.measure_zero (h : s.Finite) (μ : Measure α) [NoAtoms μ] : μ s = 0 :=
h.countable.measure_zero μ
theorem _root_.Finset.measure_zero (s : Finset α) (μ : Measure α) [NoAtoms μ] : μ s = 0 :=
s.finite_toSet.measure_zero μ
theorem insert_ae_eq_self (a : α) (s : Set α) : (insert a s : Set α) =ᵐ[μ] s :=
union_ae_eq_right.2 <| measure_mono_null diff_subset (measure_singleton _)
section
variable [PartialOrder α] {a b : α}
theorem Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a :=
Iio_ae_eq_Iic' (measure_singleton a)
theorem Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a :=
Ioi_ae_eq_Ici' (measure_singleton a)
theorem Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b :=
Ioo_ae_eq_Ioc' (measure_singleton b)
theorem Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b :=
Ioc_ae_eq_Icc' (measure_singleton a)
theorem Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b :=
Ioo_ae_eq_Ico' (measure_singleton a)
theorem Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b :=
Ioo_ae_eq_Icc' (measure_singleton a) (measure_singleton b)
theorem Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b :=
Ico_ae_eq_Icc' (measure_singleton b)
theorem Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b :=
Ico_ae_eq_Ioc' (measure_singleton a) (measure_singleton b)
theorem restrict_Iio_eq_restrict_Iic : μ.restrict (Iio a) = μ.restrict (Iic a) :=
restrict_congr_set Iio_ae_eq_Iic
theorem restrict_Ioi_eq_restrict_Ici : μ.restrict (Ioi a) = μ.restrict (Ici a) :=
restrict_congr_set Ioi_ae_eq_Ici
theorem restrict_Ioo_eq_restrict_Ioc : μ.restrict (Ioo a b) = μ.restrict (Ioc a b) :=
restrict_congr_set Ioo_ae_eq_Ioc
theorem restrict_Ioc_eq_restrict_Icc : μ.restrict (Ioc a b) = μ.restrict (Icc a b) :=
restrict_congr_set Ioc_ae_eq_Icc
theorem restrict_Ioo_eq_restrict_Ico : μ.restrict (Ioo a b) = μ.restrict (Ico a b) :=
restrict_congr_set Ioo_ae_eq_Ico
theorem restrict_Ioo_eq_restrict_Icc : μ.restrict (Ioo a b) = μ.restrict (Icc a b) :=
restrict_congr_set Ioo_ae_eq_Icc
theorem restrict_Ico_eq_restrict_Icc : μ.restrict (Ico a b) = μ.restrict (Icc a b) :=
restrict_congr_set Ico_ae_eq_Icc
theorem restrict_Ico_eq_restrict_Ioc : μ.restrict (Ico a b) = μ.restrict (Ioc a b) :=
restrict_congr_set Ico_ae_eq_Ioc
end
open Interval
theorem uIoc_ae_eq_interval [LinearOrder α] {a b : α} : Ι a b =ᵐ[μ] [[a, b]] :=
Ioc_ae_eq_Icc
end NoAtoms
theorem ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : Set α) [DecidablePred (· ∈ s)]
(hs_zero : μ s = 0) :
(fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g := by
have h_ss : sᶜ ⊆ { a : α | ite (a ∈ s) (f a) (g a) = g a } := fun x hx => by
simp [(Set.mem_compl_iff _ _).mp hx]
refine measure_mono_null ?_ hs_zero
conv_rhs => rw [← compl_compl s]
rwa [Set.compl_subset_compl]
theorem ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ)
(s : Set α) [DecidablePred (· ∈ s)] (hs_zero : μ sᶜ = 0) :
(fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f := by
rw [← mem_ae_iff] at hs_zero
filter_upwards [hs_zero]
intros
split_ifs
rfl
namespace Measure
/-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`.
Equivalently, it is eventually finite at `s` in `f.small_sets`. -/
def FiniteAtFilter {_m0 : MeasurableSpace α} (μ : Measure α) (f : Filter α) : Prop :=
∃ s ∈ f, μ s < ∞
theorem finiteAtFilter_of_finite {_m0 : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ]
(f : Filter α) : μ.FiniteAtFilter f :=
⟨univ, univ_mem, measure_lt_top μ univ⟩
theorem FiniteAtFilter.exists_mem_basis {f : Filter α} (hμ : FiniteAtFilter μ f) {p : ι → Prop}
{s : ι → Set α} (hf : f.HasBasis p s) : ∃ i, p i ∧ μ (s i) < ∞ :=
(hf.exists_iff fun {_s _t} hst ht => (measure_mono hst).trans_lt ht).1 hμ
theorem finiteAtBot {m0 : MeasurableSpace α} (μ : Measure α) : μ.FiniteAtFilter ⊥ :=
⟨∅, mem_bot, by simp only [measure_empty, zero_lt_top]⟩
/-- `μ` has finite spanning sets in `C` if there is a countable sequence of sets in `C` that have
finite measures. This structure is a type, which is useful if we want to record extra properties
about the sets, such as that they are monotone.
`SigmaFinite` is defined in terms of this: `μ` is σ-finite if there exists a sequence of
finite spanning sets in the collection of all measurable sets. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
structure FiniteSpanningSetsIn {m0 : MeasurableSpace α} (μ : Measure α) (C : Set (Set α)) where
protected set : ℕ → Set α
protected set_mem : ∀ i, set i ∈ C
protected finite : ∀ i, μ (set i) < ∞
protected spanning : ⋃ i, set i = univ
end Measure
open Measure
section SFinite
/-- A measure is called s-finite if it is a countable sum of finite measures. -/
class SFinite (μ : Measure α) : Prop where
out' : ∃ m : ℕ → Measure α, (∀ n, IsFiniteMeasure (m n)) ∧ μ = Measure.sum m
/-- A sequence of finite measures such that `μ = sum (sFiniteSeq μ)` (see `sum_sFiniteSeq`). -/
noncomputable
def sFiniteSeq (μ : Measure α) [h : SFinite μ] : ℕ → Measure α := h.1.choose
instance isFiniteMeasure_sFiniteSeq [h : SFinite μ] (n : ℕ) : IsFiniteMeasure (sFiniteSeq μ n) :=
h.1.choose_spec.1 n
lemma sum_sFiniteSeq (μ : Measure α) [h : SFinite μ] : sum (sFiniteSeq μ) = μ :=
h.1.choose_spec.2.symm
instance : SFinite (0 : Measure α) := ⟨fun _ ↦ 0, inferInstance, by rw [Measure.sum_zero]⟩
@[simp]
lemma sFiniteSeq_zero (n : ℕ) : sFiniteSeq (0 : Measure α) n = 0 := by
ext s hs
have h : ∑' n, sFiniteSeq (0 : Measure α) n s = 0 := by
simp [← Measure.sum_apply _ hs, sum_sFiniteSeq]
simp only [ENNReal.tsum_eq_zero] at h
exact h n
/-- A countable sum of finite measures is s-finite.
This lemma is superseeded by the instance below. -/
lemma sfinite_sum_of_countable [Countable ι]
(m : ι → Measure α) [∀ n, IsFiniteMeasure (m n)] : SFinite (Measure.sum m) := by
classical
obtain ⟨f, hf⟩ : ∃ f : ι → ℕ, Function.Injective f := Countable.exists_injective_nat ι
refine ⟨_, fun n ↦ ?_, (sum_extend_zero hf m).symm⟩
rcases em (n ∈ range f) with ⟨i, rfl⟩ | hn
· rw [hf.extend_apply]
infer_instance
· rw [Function.extend_apply' _ _ _ hn, Pi.zero_apply]
infer_instance
instance [Countable ι] (m : ι → Measure α) [∀ n, SFinite (m n)] : SFinite (Measure.sum m) := by
change SFinite (Measure.sum (fun i ↦ m i))
simp_rw [← sum_sFiniteSeq (m _), Measure.sum_sum]
apply sfinite_sum_of_countable
instance [SFinite μ] [SFinite ν] : SFinite (μ + ν) := by
have : ∀ b : Bool, SFinite (cond b μ ν) := by simp [*]
simpa using inferInstanceAs (SFinite (.sum (cond · μ ν)))
instance [SFinite μ] (s : Set α) : SFinite (μ.restrict s) :=
⟨fun n ↦ (sFiniteSeq μ n).restrict s, fun n ↦ inferInstance,
by rw [← restrict_sum_of_countable, sum_sFiniteSeq]⟩
variable (μ) in
/-- An s-finite measure is absolutely continuous with respect to some finite measure. -/
theorem exists_absolutelyContinuous_isFiniteMeasure [SFinite μ] :
∃ ν : Measure α, IsFiniteMeasure ν ∧ μ ≪ ν := by
rcases ENNReal.exists_pos_tsum_mul_lt_of_countable top_ne_zero (sFiniteSeq μ · univ)
fun _ ↦ measure_ne_top _ _ with ⟨c, hc₀, hc⟩
refine ⟨.sum fun n ↦ c n • sFiniteSeq μ n, ⟨?_⟩, ?_⟩
· simpa [mul_comm] using hc
· refine AbsolutelyContinuous.mk fun s hsm hs ↦ ?_
have : ∀ n, (sFiniteSeq μ n) s = 0 := by simpa [hsm, (hc₀ _).ne'] using hs
rw [← sum_sFiniteSeq μ, sum_apply _ hsm]
simp [this]
end SFinite
/-- A measure `μ` is called σ-finite if there is a countable collection of sets
`{ A i | i ∈ ℕ }` such that `μ (A i) < ∞` and `⋃ i, A i = s`. -/
class SigmaFinite {m0 : MeasurableSpace α} (μ : Measure α) : Prop where
out' : Nonempty (μ.FiniteSpanningSetsIn univ)
theorem sigmaFinite_iff : SigmaFinite μ ↔ Nonempty (μ.FiniteSpanningSetsIn univ) :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
theorem SigmaFinite.out (h : SigmaFinite μ) : Nonempty (μ.FiniteSpanningSetsIn univ) :=
h.1
/-- If `μ` is σ-finite it has finite spanning sets in the collection of all measurable sets. -/
def Measure.toFiniteSpanningSetsIn (μ : Measure α) [h : SigmaFinite μ] :
μ.FiniteSpanningSetsIn { s | MeasurableSet s } where
set n := toMeasurable μ (h.out.some.set n)
set_mem n := measurableSet_toMeasurable _ _
finite n := by
rw [measure_toMeasurable]
exact h.out.some.finite n
spanning := eq_univ_of_subset (iUnion_mono fun n => subset_toMeasurable _ _) h.out.some.spanning
/-- A noncomputable way to get a monotone collection of sets that span `univ` and have finite
measure using `Classical.choose`. This definition satisfies monotonicity in addition to all other
properties in `SigmaFinite`. -/
def spanningSets (μ : Measure α) [SigmaFinite μ] (i : ℕ) : Set α :=
Accumulate μ.toFiniteSpanningSetsIn.set i
theorem monotone_spanningSets (μ : Measure α) [SigmaFinite μ] : Monotone (spanningSets μ) :=
monotone_accumulate
theorem measurable_spanningSets (μ : Measure α) [SigmaFinite μ] (i : ℕ) :
MeasurableSet (spanningSets μ i) :=
MeasurableSet.iUnion fun j => MeasurableSet.iUnion fun _ => μ.toFiniteSpanningSetsIn.set_mem j
theorem measure_spanningSets_lt_top (μ : Measure α) [SigmaFinite μ] (i : ℕ) :
μ (spanningSets μ i) < ∞ :=
measure_biUnion_lt_top (finite_le_nat i) fun j _ => (μ.toFiniteSpanningSetsIn.finite j).ne
theorem iUnion_spanningSets (μ : Measure α) [SigmaFinite μ] : ⋃ i : ℕ, spanningSets μ i = univ := by
simp_rw [spanningSets, iUnion_accumulate, μ.toFiniteSpanningSetsIn.spanning]
theorem isCountablySpanning_spanningSets (μ : Measure α) [SigmaFinite μ] :
IsCountablySpanning (range (spanningSets μ)) :=
⟨spanningSets μ, mem_range_self, iUnion_spanningSets μ⟩
open scoped Classical in
/-- `spanningSetsIndex μ x` is the least `n : ℕ` such that `x ∈ spanningSets μ n`. -/
noncomputable def spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) : ℕ :=
Nat.find <| iUnion_eq_univ_iff.1 (iUnion_spanningSets μ) x
open scoped Classical in
theorem measurable_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] :
Measurable (spanningSetsIndex μ) :=
measurable_find _ <| measurable_spanningSets μ
open scoped Classical in
theorem preimage_spanningSetsIndex_singleton (μ : Measure α) [SigmaFinite μ] (n : ℕ) :
spanningSetsIndex μ ⁻¹' {n} = disjointed (spanningSets μ) n :=
preimage_find_eq_disjointed _ _ _
theorem spanningSetsIndex_eq_iff (μ : Measure α) [SigmaFinite μ] {x : α} {n : ℕ} :
spanningSetsIndex μ x = n ↔ x ∈ disjointed (spanningSets μ) n := by
convert Set.ext_iff.1 (preimage_spanningSetsIndex_singleton μ n) x
theorem mem_disjointed_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) :
x ∈ disjointed (spanningSets μ) (spanningSetsIndex μ x) :=
(spanningSetsIndex_eq_iff μ).1 rfl
theorem mem_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) :
x ∈ spanningSets μ (spanningSetsIndex μ x) :=
disjointed_subset _ _ (mem_disjointed_spanningSetsIndex μ x)
theorem mem_spanningSets_of_index_le (μ : Measure α) [SigmaFinite μ] (x : α) {n : ℕ}
(hn : spanningSetsIndex μ x ≤ n) : x ∈ spanningSets μ n :=
monotone_spanningSets μ hn (mem_spanningSetsIndex μ x)
theorem eventually_mem_spanningSets (μ : Measure α) [SigmaFinite μ] (x : α) :
∀ᶠ n in atTop, x ∈ spanningSets μ n :=
eventually_atTop.2 ⟨spanningSetsIndex μ x, fun _ => mem_spanningSets_of_index_le μ x⟩
theorem sum_restrict_disjointed_spanningSets (μ ν : Measure α) [SigmaFinite ν] :
sum (fun n ↦ μ.restrict (disjointed (spanningSets ν) n)) = μ := by
rw [← restrict_iUnion (disjoint_disjointed _)
(MeasurableSet.disjointed (measurable_spanningSets _)),
iUnion_disjointed, iUnion_spanningSets, restrict_univ]
instance (priority := 100) [SigmaFinite μ] : SFinite μ := by
have : ∀ n, Fact (μ (disjointed (spanningSets μ) n) < ∞) :=
fun n ↦ ⟨(measure_mono (disjointed_subset _ _)).trans_lt (measure_spanningSets_lt_top μ n)⟩
exact ⟨⟨fun n ↦ μ.restrict (disjointed (spanningSets μ) n), fun n ↦ by infer_instance,
(sum_restrict_disjointed_spanningSets μ μ).symm⟩⟩
namespace Measure
/-- A set in a σ-finite space has zero measure if and only if its intersection with
all members of the countable family of finite measure spanning sets has zero measure. -/
theorem forall_measure_inter_spanningSets_eq_zero [MeasurableSpace α] {μ : Measure α}
[SigmaFinite μ] (s : Set α) : (∀ n, μ (s ∩ spanningSets μ n) = 0) ↔ μ s = 0 := by
nth_rw 2 [show s = ⋃ n, s ∩ spanningSets μ n by
rw [← inter_iUnion, iUnion_spanningSets, inter_univ] ]
rw [measure_iUnion_null_iff]
/-- A set in a σ-finite space has positive measure if and only if its intersection with
some member of the countable family of finite measure spanning sets has positive measure. -/
theorem exists_measure_inter_spanningSets_pos [MeasurableSpace α] {μ : Measure α} [SigmaFinite μ]
(s : Set α) : (∃ n, 0 < μ (s ∩ spanningSets μ n)) ↔ 0 < μ s := by
rw [← not_iff_not]
simp only [not_exists, not_lt, nonpos_iff_eq_zero]
exact forall_measure_inter_spanningSets_eq_zero s
/-- If the union of a.e.-disjoint null-measurable sets has finite measure, then there are only
finitely many members of the union whose measure exceeds any given positive number. -/
theorem finite_const_le_meas_of_disjoint_iUnion₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α)
{ε : ℝ≥0∞} (ε_pos : 0 < ε) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Finite { i : ι | ε ≤ μ (As i) } :=
ENNReal.finite_const_le_of_tsum_ne_top
(ne_top_of_le_ne_top Union_As_finite (tsum_meas_le_meas_iUnion_of_disjoint₀ μ As_mble As_disj))
ε_pos.ne'
/-- If the union of disjoint measurable sets has finite measure, then there are only
finitely many members of the union whose measure exceeds any given positive number. -/
theorem finite_const_le_meas_of_disjoint_iUnion {ι : Type*} [MeasurableSpace α] (μ : Measure α)
{ε : ℝ≥0∞} (ε_pos : 0 < ε) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Finite { i : ι | ε ≤ μ (As i) } :=
finite_const_le_meas_of_disjoint_iUnion₀ μ ε_pos (fun i ↦ (As_mble i).nullMeasurableSet)
(fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) Union_As_finite
/-- If all elements of an infinite set have measure uniformly separated from zero,
then the set has infinite measure. -/
theorem _root_.Set.Infinite.meas_eq_top [MeasurableSingletonClass α]
{s : Set α} (hs : s.Infinite) (h' : ∃ ε, ε ≠ 0 ∧ ∀ x ∈ s, ε ≤ μ {x}) : μ s = ∞ := top_unique <|
let ⟨ε, hne, hε⟩ := h'; have := hs.to_subtype
calc
∞ = ∑' _ : s, ε := (ENNReal.tsum_const_eq_top_of_ne_zero hne).symm
_ ≤ ∑' x : s, μ {x.1} := ENNReal.tsum_le_tsum fun x ↦ hε x x.2
_ ≤ μ (⋃ x : s, {x.1}) := tsum_meas_le_meas_iUnion_of_disjoint _
(fun _ ↦ MeasurableSet.singleton _) fun x y hne ↦ by simpa [Subtype.val_inj]
_ = μ s := by simp
/-- If the union of a.e.-disjoint null-measurable sets has finite measure, then there are only
countably many members of the union whose measure is positive. -/
theorem countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ {ι : Type*} {_ : MeasurableSpace α}
(μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Countable { i : ι | 0 < μ (As i) } := by
set posmeas := { i : ι | 0 < μ (As i) } with posmeas_def
rcases exists_seq_strictAnti_tendsto' (zero_lt_one : (0 : ℝ≥0∞) < 1) with
⟨as, _, as_mem, as_lim⟩
set fairmeas := fun n : ℕ => { i : ι | as n ≤ μ (As i) }
have countable_union : posmeas = ⋃ n, fairmeas n := by
have fairmeas_eq : ∀ n, fairmeas n = (fun i => μ (As i)) ⁻¹' Ici (as n) := fun n => by
simp only [fairmeas]
rfl
simpa only [fairmeas_eq, posmeas_def, ← preimage_iUnion,
iUnion_Ici_eq_Ioi_of_lt_of_tendsto (0 : ℝ≥0∞) (fun n => (as_mem n).1) as_lim]
rw [countable_union]
refine countable_iUnion fun n => Finite.countable ?_
exact finite_const_le_meas_of_disjoint_iUnion₀ μ (as_mem n).1 As_mble As_disj Union_As_finite
/-- If the union of disjoint measurable sets has finite measure, then there are only
countably many members of the union whose measure is positive. -/
theorem countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top {ι : Type*} {_ : MeasurableSpace α}
(μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) :
Set.Countable { i : ι | 0 < μ (As i) } :=
countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ μ (fun i ↦ (As_mble i).nullMeasurableSet)
((fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))) Union_As_finite
/-- In an s-finite space, among disjoint null-measurable sets, only countably many can have positive
measure. -/
theorem countable_meas_pos_of_disjoint_iUnion₀ {ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) :
Set.Countable { i : ι | 0 < μ (As i) } := by
rw [← sum_sFiniteSeq μ] at As_disj As_mble ⊢
have obs : { i : ι | 0 < sum (sFiniteSeq μ) (As i) }
⊆ ⋃ n, { i : ι | 0 < sFiniteSeq μ n (As i) } := by
intro i hi
by_contra con
simp only [mem_iUnion, mem_setOf_eq, not_exists, not_lt, nonpos_iff_eq_zero] at *
rw [sum_apply₀] at hi
· simp_rw [con] at hi
simp at hi
· exact As_mble i
apply Countable.mono obs
refine countable_iUnion fun n ↦ ?_
apply countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀
· exact fun i ↦ (As_mble i).mono (le_sum _ _)
· exact fun i j hij ↦ AEDisjoint.of_le (As_disj hij) (le_sum _ _)
· exact measure_ne_top _ (⋃ i, As i)
/-- In an s-finite space, among disjoint measurable sets, only countably many can have positive
measure. -/
theorem countable_meas_pos_of_disjoint_iUnion {ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) : Set.Countable { i : ι | 0 < μ (As i) } :=
countable_meas_pos_of_disjoint_iUnion₀ (fun i ↦ (As_mble i).nullMeasurableSet)
((fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)))
theorem countable_meas_level_set_pos₀ {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] [MeasurableSpace β] [MeasurableSingletonClass β] {g : α → β}
(g_mble : NullMeasurable g μ) : Set.Countable { t : β | 0 < μ { a : α | g a = t } } := by
have level_sets_disjoint : Pairwise (Disjoint on fun t : β => { a : α | g a = t }) :=
fun s t hst => Disjoint.preimage g (disjoint_singleton.mpr hst)
exact Measure.countable_meas_pos_of_disjoint_iUnion₀
(fun b => g_mble (‹MeasurableSingletonClass β›.measurableSet_singleton b))
((fun _ _ h ↦ Disjoint.aedisjoint (level_sets_disjoint h)))
theorem countable_meas_level_set_pos {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SFinite μ] [MeasurableSpace β] [MeasurableSingletonClass β] {g : α → β}
(g_mble : Measurable g) : Set.Countable { t : β | 0 < μ { a : α | g a = t } } :=
countable_meas_level_set_pos₀ g_mble.nullMeasurable
/-- If a measure `μ` is the sum of a countable family `mₙ`, and a set `t` has finite measure for
each `mₙ`, then its measurable superset `toMeasurable μ t` (which has the same measure as `t`)
satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. -/
theorem measure_toMeasurable_inter_of_sum {s : Set α} (hs : MeasurableSet s) {t : Set α}
{m : ℕ → Measure α} (hv : ∀ n, m n t ≠ ∞) (hμ : μ = sum m) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := by
-- we show that there is a measurable superset of `t` satisfying the conclusion for any
-- measurable set `s`. It is built for each measure `mₙ` using `toMeasurable`
-- (which is well behaved for finite measure sets thanks to `measure_toMeasurable_inter`), and
-- then taking the intersection over `n`.
have A : ∃ t', t' ⊇ t ∧ MeasurableSet t' ∧ ∀ u, MeasurableSet u → μ (t' ∩ u) = μ (t ∩ u) := by
let w n := toMeasurable (m n) t
have T : t ⊆ ⋂ n, w n := subset_iInter (fun i ↦ subset_toMeasurable (m i) t)
have M : MeasurableSet (⋂ n, w n) :=
MeasurableSet.iInter (fun i ↦ measurableSet_toMeasurable (m i) t)
refine ⟨⋂ n, w n, T, M, fun u hu ↦ ?_⟩
refine le_antisymm ?_ (by gcongr)
rw [hμ, sum_apply _ (M.inter hu)]
apply le_trans _ (le_sum_apply _ _)
apply ENNReal.tsum_le_tsum (fun i ↦ ?_)
calc
m i ((⋂ n, w n) ∩ u) ≤ m i (w i ∩ u) := by gcongr; apply iInter_subset
_ = m i (t ∩ u) := measure_toMeasurable_inter hu (hv i)
-- thanks to the definition of `toMeasurable`, the previous property will also be shared
-- by `toMeasurable μ t`, which is enough to conclude the proof.
rw [toMeasurable]
split_ifs with ht
· apply measure_congr
exact ae_eq_set_inter ht.choose_spec.2.2 (ae_eq_refl _)
· exact A.choose_spec.2.2 s hs
/-- If a set `t` is covered by a countable family of finite measure sets, then its measurable
superset `toMeasurable μ t` (which has the same measure as `t`) satisfies,
for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. -/
theorem measure_toMeasurable_inter_of_cover {s : Set α} (hs : MeasurableSet s) {t : Set α}
{v : ℕ → Set α} (hv : t ⊆ ⋃ n, v n) (h'v : ∀ n, μ (t ∩ v n) ≠ ∞) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := by
-- we show that there is a measurable superset of `t` satisfying the conclusion for any
-- measurable set `s`. It is built on each member of a spanning family using `toMeasurable`
-- (which is well behaved for finite measure sets thanks to `measure_toMeasurable_inter`), and
-- the desired property passes to the union.
have A : ∃ t', t' ⊇ t ∧ MeasurableSet t' ∧ ∀ u, MeasurableSet u → μ (t' ∩ u) = μ (t ∩ u) := by
let w n := toMeasurable μ (t ∩ v n)
have hw : ∀ n, μ (w n) < ∞ := by
intro n
simp_rw [w, measure_toMeasurable]
exact (h'v n).lt_top
set t' := ⋃ n, toMeasurable μ (t ∩ disjointed w n) with ht'
have tt' : t ⊆ t' :=
calc
t ⊆ ⋃ n, t ∩ disjointed w n := by
rw [← inter_iUnion, iUnion_disjointed, inter_iUnion]
intro x hx
rcases mem_iUnion.1 (hv hx) with ⟨n, hn⟩
refine mem_iUnion.2 ⟨n, ?_⟩
have : x ∈ t ∩ v n := ⟨hx, hn⟩
exact ⟨hx, subset_toMeasurable μ _ this⟩
_ ⊆ ⋃ n, toMeasurable μ (t ∩ disjointed w n) :=
iUnion_mono fun n => subset_toMeasurable _ _
refine ⟨t', tt', MeasurableSet.iUnion fun n => measurableSet_toMeasurable μ _, fun u hu => ?_⟩
apply le_antisymm _ (by gcongr)
calc
μ (t' ∩ u) ≤ ∑' n, μ (toMeasurable μ (t ∩ disjointed w n) ∩ u) := by
rw [ht', iUnion_inter]
exact measure_iUnion_le _
_ = ∑' n, μ (t ∩ disjointed w n ∩ u) := by
congr 1
ext1 n
apply measure_toMeasurable_inter hu
apply ne_of_lt
calc
μ (t ∩ disjointed w n) ≤ μ (t ∩ w n) := by
gcongr
exact disjointed_le w n
_ ≤ μ (w n) := measure_mono inter_subset_right
_ < ∞ := hw n
_ = ∑' n, μ.restrict (t ∩ u) (disjointed w n) := by
congr 1
ext1 n
rw [restrict_apply, inter_comm t _, inter_assoc]
refine MeasurableSet.disjointed (fun n => ?_) n
exact measurableSet_toMeasurable _ _
_ = μ.restrict (t ∩ u) (⋃ n, disjointed w n) := by
rw [measure_iUnion]
· exact disjoint_disjointed _
· intro i
refine MeasurableSet.disjointed (fun n => ?_) i
exact measurableSet_toMeasurable _ _
_ ≤ μ.restrict (t ∩ u) univ := measure_mono (subset_univ _)
_ = μ (t ∩ u) := by rw [restrict_apply MeasurableSet.univ, univ_inter]
-- thanks to the definition of `toMeasurable`, the previous property will also be shared
-- by `toMeasurable μ t`, which is enough to conclude the proof.
rw [toMeasurable]
split_ifs with ht
· apply measure_congr
exact ae_eq_set_inter ht.choose_spec.2.2 (ae_eq_refl _)
· exact A.choose_spec.2.2 s hs
theorem restrict_toMeasurable_of_cover {s : Set α} {v : ℕ → Set α} (hv : s ⊆ ⋃ n, v n)
(h'v : ∀ n, μ (s ∩ v n) ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
simp only [restrict_apply ht, inter_comm t, measure_toMeasurable_inter_of_cover ht hv h'v]
/-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`)
satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`.
This only holds when `μ` is s-finite -- for example for σ-finite measures. For a version without
this assumption (but requiring that `t` has finite measure), see `measure_toMeasurable_inter`. -/
theorem measure_toMeasurable_inter_of_sFinite [SFinite μ] {s : Set α} (hs : MeasurableSet s)
(t : Set α) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) :=
measure_toMeasurable_inter_of_sum hs (fun _ ↦ measure_ne_top _ t) (sum_sFiniteSeq μ).symm
@[simp]
theorem restrict_toMeasurable_of_sFinite [SFinite μ] (s : Set α) :
μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, inter_comm t, measure_toMeasurable_inter_of_sFinite ht,
restrict_apply ht, inter_comm t]
/-- Auxiliary lemma for `iSup_restrict_spanningSets`. -/
theorem iSup_restrict_spanningSets_of_measurableSet [SigmaFinite μ] (hs : MeasurableSet s) :
⨆ i, μ.restrict (spanningSets μ i) s = μ s :=
calc
⨆ i, μ.restrict (spanningSets μ i) s = μ.restrict (⋃ i, spanningSets μ i) s :=
(restrict_iUnion_apply_eq_iSup (monotone_spanningSets μ).directed_le hs).symm
_ = μ s := by rw [iUnion_spanningSets, restrict_univ]
theorem iSup_restrict_spanningSets [SigmaFinite μ] (s : Set α) :
⨆ i, μ.restrict (spanningSets μ i) s = μ s := by
rw [← measure_toMeasurable s,
← iSup_restrict_spanningSets_of_measurableSet (measurableSet_toMeasurable _ _)]
simp_rw [restrict_apply' (measurable_spanningSets μ _), Set.inter_comm s,
← restrict_apply (measurable_spanningSets μ _), ← restrict_toMeasurable_of_sFinite s,
restrict_apply (measurable_spanningSets μ _), Set.inter_comm _ (toMeasurable μ s)]
/-- In a σ-finite space, any measurable set of measure `> r` contains a measurable subset of
finite measure `> r`. -/
theorem exists_subset_measure_lt_top [SigmaFinite μ] {r : ℝ≥0∞} (hs : MeasurableSet s)
(h's : r < μ s) : ∃ t, MeasurableSet t ∧ t ⊆ s ∧ r < μ t ∧ μ t < ∞ := by
rw [← iSup_restrict_spanningSets,
@lt_iSup_iff _ _ _ r fun i : ℕ => μ.restrict (spanningSets μ i) s] at h's
rcases h's with ⟨n, hn⟩
simp only [restrict_apply hs] at hn
refine
⟨s ∩ spanningSets μ n, hs.inter (measurable_spanningSets _ _), inter_subset_left, hn, ?_⟩
exact (measure_mono inter_subset_right).trans_lt (measure_spanningSets_lt_top _ _)
namespace FiniteSpanningSetsIn
variable {C D : Set (Set α)}
/-- If `μ` has finite spanning sets in `C` and `C ∩ {s | μ s < ∞} ⊆ D` then `μ` has finite spanning
sets in `D`. -/
protected def mono' (h : μ.FiniteSpanningSetsIn C) (hC : C ∩ { s | μ s < ∞ } ⊆ D) :
μ.FiniteSpanningSetsIn D :=
⟨h.set, fun i => hC ⟨h.set_mem i, h.finite i⟩, h.finite, h.spanning⟩
/-- If `μ` has finite spanning sets in `C` and `C ⊆ D` then `μ` has finite spanning sets in `D`. -/
protected def mono (h : μ.FiniteSpanningSetsIn C) (hC : C ⊆ D) : μ.FiniteSpanningSetsIn D :=
h.mono' fun _s hs => hC hs.1
/-- If `μ` has finite spanning sets in the collection of measurable sets `C`, then `μ` is σ-finite.
-/
protected theorem sigmaFinite (h : μ.FiniteSpanningSetsIn C) : SigmaFinite μ :=
⟨⟨h.mono <| subset_univ C⟩⟩
/-- An extensionality for measures. It is `ext_of_generateFrom_of_iUnion` formulated in terms of
`FiniteSpanningSetsIn`. -/
protected theorem ext {ν : Measure α} {C : Set (Set α)} (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h : μ.FiniteSpanningSetsIn C) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=
ext_of_generateFrom_of_iUnion C _ hA hC h.spanning h.set_mem (fun i => (h.finite i).ne) h_eq
protected theorem isCountablySpanning (h : μ.FiniteSpanningSetsIn C) : IsCountablySpanning C :=
⟨h.set, h.set_mem, h.spanning⟩
end FiniteSpanningSetsIn
theorem sigmaFinite_of_countable {S : Set (Set α)} (hc : S.Countable) (hμ : ∀ s ∈ S, μ s < ∞)
(hU : ⋃₀ S = univ) : SigmaFinite μ := by
obtain ⟨s, hμ, hs⟩ : ∃ s : ℕ → Set α, (∀ n, μ (s n) < ∞) ∧ ⋃ n, s n = univ :=
(@exists_seq_cover_iff_countable _ (fun x => μ x < ∞) ⟨∅, by simp⟩).2 ⟨S, hc, hμ, hU⟩
exact ⟨⟨⟨fun n => s n, fun _ => trivial, hμ, hs⟩⟩⟩
/-- Given measures `μ`, `ν` where `ν ≤ μ`, `FiniteSpanningSetsIn.ofLe` provides the induced
`FiniteSpanningSet` with respect to `ν` from a `FiniteSpanningSet` with respect to `μ`. -/
def FiniteSpanningSetsIn.ofLE (h : ν ≤ μ) {C : Set (Set α)} (S : μ.FiniteSpanningSetsIn C) :
ν.FiniteSpanningSetsIn C where
set := S.set
set_mem := S.set_mem
finite n := lt_of_le_of_lt (le_iff'.1 h _) (S.finite n)
spanning := S.spanning
theorem sigmaFinite_of_le (μ : Measure α) [hs : SigmaFinite μ] (h : ν ≤ μ) : SigmaFinite ν :=
⟨hs.out.map <| FiniteSpanningSetsIn.ofLE h⟩
@[simp] lemma add_right_inj (μ ν₁ ν₂ : Measure α) [SigmaFinite μ] :
μ + ν₁ = μ + ν₂ ↔ ν₁ = ν₂ := by
refine ⟨fun h ↦ ?_, fun h ↦ by rw [h]⟩
rw [ext_iff_of_iUnion_eq_univ (iUnion_spanningSets μ)]
intro i
ext s hs
rw [← ENNReal.add_right_inj (measure_mono s.inter_subset_right |>.trans_lt <|
measure_spanningSets_lt_top μ i).ne]
simp only [ext_iff', coe_add, Pi.add_apply] at h
simp [hs, h]
@[simp] lemma add_left_inj (μ ν₁ ν₂ : Measure α) [SigmaFinite μ] :
ν₁ + μ = ν₂ + μ ↔ ν₁ = ν₂ := by rw [add_comm _ μ, add_comm _ μ, μ.add_right_inj]
end Measure
/-- Every finite measure is σ-finite. -/
instance (priority := 100) IsFiniteMeasure.toSigmaFinite {_m0 : MeasurableSpace α} (μ : Measure α)
[IsFiniteMeasure μ] : SigmaFinite μ :=
⟨⟨⟨fun _ => univ, fun _ => trivial, fun _ => measure_lt_top μ _, iUnion_const _⟩⟩⟩
theorem sigmaFinite_bot_iff (μ : @Measure α ⊥) : SigmaFinite μ ↔ IsFiniteMeasure μ := by
refine
⟨fun h => ⟨?_⟩, fun h => by
haveI := h
infer_instance⟩
haveI : SigmaFinite μ := h
let s := spanningSets μ
have hs_univ : ⋃ i, s i = Set.univ := iUnion_spanningSets μ
have hs_meas : ∀ i, MeasurableSet[⊥] (s i) := measurable_spanningSets μ
simp_rw [MeasurableSpace.measurableSet_bot_iff] at hs_meas
by_cases h_univ_empty : (Set.univ : Set α) = ∅
· rw [h_univ_empty, measure_empty]
exact ENNReal.zero_ne_top.lt_top
obtain ⟨i, hsi⟩ : ∃ i, s i = Set.univ := by
by_contra! h_not_univ
have h_empty : ∀ i, s i = ∅ := by simpa [h_not_univ] using hs_meas
simp only [h_empty, iUnion_empty] at hs_univ
exact h_univ_empty hs_univ.symm
rw [← hsi]
exact measure_spanningSets_lt_top μ i
instance Restrict.sigmaFinite (μ : Measure α) [SigmaFinite μ] (s : Set α) :
SigmaFinite (μ.restrict s) := by
refine ⟨⟨⟨spanningSets μ, fun _ => trivial, fun i => ?_, iUnion_spanningSets μ⟩⟩⟩
rw [Measure.restrict_apply (measurable_spanningSets μ i)]
exact (measure_mono inter_subset_left).trans_lt (measure_spanningSets_lt_top μ i)
instance sum.sigmaFinite {ι} [Finite ι] (μ : ι → Measure α) [∀ i, SigmaFinite (μ i)] :
SigmaFinite (sum μ) := by
cases nonempty_fintype ι
have : ∀ n, MeasurableSet (⋂ i : ι, spanningSets (μ i) n) := fun n =>
MeasurableSet.iInter fun i => measurable_spanningSets (μ i) n
refine ⟨⟨⟨fun n => ⋂ i, spanningSets (μ i) n, fun _ => trivial, fun n => ?_, ?_⟩⟩⟩
· rw [sum_apply _ (this n), tsum_fintype, ENNReal.sum_lt_top_iff]
rintro i -
exact (measure_mono <| iInter_subset _ i).trans_lt (measure_spanningSets_lt_top (μ i) n)
· rw [iUnion_iInter_of_monotone]
· simp_rw [iUnion_spanningSets, iInter_univ]
exact fun i => monotone_spanningSets (μ i)
instance Add.sigmaFinite (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] :
SigmaFinite (μ + ν) := by
rw [← sum_cond]
refine @sum.sigmaFinite _ _ _ _ _ (Bool.rec ?_ ?_) <;> simpa
instance SMul.sigmaFinite {μ : Measure α} [SigmaFinite μ] (c : ℝ≥0) :
MeasureTheory.SigmaFinite (c • μ) where
out' :=
⟨{ set := spanningSets μ
set_mem := fun _ ↦ trivial
finite := by
intro i
simp only [Measure.coe_smul, Pi.smul_apply, nnreal_smul_coe_apply]
exact ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_spanningSets_lt_top μ i).ne
spanning := iUnion_spanningSets μ }⟩
theorem SigmaFinite.of_map (μ : Measure α) {f : α → β} (hf : AEMeasurable f μ)
(h : SigmaFinite (μ.map f)) : SigmaFinite μ :=
⟨⟨⟨fun n => f ⁻¹' spanningSets (μ.map f) n, fun _ => trivial, fun n => by
simp only [← map_apply_of_aemeasurable hf, measurable_spanningSets,
measure_spanningSets_lt_top],
by rw [← preimage_iUnion, iUnion_spanningSets, preimage_univ]⟩⟩⟩
lemma _root_.MeasurableEmbedding.sigmaFinite_map {f : α → β} (hf : MeasurableEmbedding f)
[SigmaFinite μ] :
SigmaFinite (μ.map f) := by
refine ⟨fun n ↦ f '' (spanningSets μ n) ∪ (Set.range f)ᶜ, by simp, fun n ↦ ?_, ?_⟩
· rw [hf.map_apply, Set.preimage_union]
simp only [Set.preimage_compl, Set.preimage_range, Set.compl_univ, Set.union_empty,
Set.preimage_image_eq _ hf.injective]
exact measure_spanningSets_lt_top μ n
· rw [← Set.iUnion_union, ← Set.image_iUnion, iUnion_spanningSets,
Set.image_univ, Set.union_compl_self]
theorem _root_.MeasurableEquiv.sigmaFinite_map (f : α ≃ᵐ β) [SigmaFinite μ] :
SigmaFinite (μ.map f) := f.measurableEmbedding.sigmaFinite_map
/-- Similar to `ae_of_forall_measure_lt_top_ae_restrict`, but where you additionally get the
hypothesis that another σ-finite measure has finite values on `s`. -/
theorem ae_of_forall_measure_lt_top_ae_restrict' {μ : Measure α} (ν : Measure α) [SigmaFinite μ]
[SigmaFinite ν] (P : α → Prop)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ν s < ∞ → ∀ᵐ x ∂μ.restrict s, P x) : ∀ᵐ x ∂μ, P x := by
have : ∀ n, ∀ᵐ x ∂μ, x ∈ spanningSets (μ + ν) n → P x := by
intro n
have := h
(spanningSets (μ + ν) n) (measurable_spanningSets _ _)
((self_le_add_right _ _).trans_lt (measure_spanningSets_lt_top (μ + ν) _))
((self_le_add_left _ _).trans_lt (measure_spanningSets_lt_top (μ + ν) _))
exact (ae_restrict_iff' (measurable_spanningSets _ _)).mp this
filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _)
/-- To prove something for almost all `x` w.r.t. a σ-finite measure, it is sufficient to show that
this holds almost everywhere in sets where the measure has finite value. -/
theorem ae_of_forall_measure_lt_top_ae_restrict {μ : Measure α} [SigmaFinite μ] (P : α → Prop)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ∀ᵐ x ∂μ.restrict s, P x) : ∀ᵐ x ∂μ, P x :=
ae_of_forall_measure_lt_top_ae_restrict' μ P fun s hs h2s _ => h s hs h2s
/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/
class IsLocallyFiniteMeasure [TopologicalSpace α] (μ : Measure α) : Prop where
finiteAtNhds : ∀ x, μ.FiniteAtFilter (𝓝 x)
-- see Note [lower instance priority]
instance (priority := 100) IsFiniteMeasure.toIsLocallyFiniteMeasure [TopologicalSpace α]
(μ : Measure α) [IsFiniteMeasure μ] : IsLocallyFiniteMeasure μ :=
⟨fun _ => finiteAtFilter_of_finite _ _⟩
theorem Measure.finiteAt_nhds [TopologicalSpace α] (μ : Measure α) [IsLocallyFiniteMeasure μ]
(x : α) : μ.FiniteAtFilter (𝓝 x) :=
IsLocallyFiniteMeasure.finiteAtNhds x
theorem Measure.smul_finite (μ : Measure α) [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) :
IsFiniteMeasure (c • μ) := by
lift c to ℝ≥0 using hc
exact MeasureTheory.isFiniteMeasureSMulNNReal
theorem Measure.exists_isOpen_measure_lt_top [TopologicalSpace α] (μ : Measure α)
[IsLocallyFiniteMeasure μ] (x : α) : ∃ s : Set α, x ∈ s ∧ IsOpen s ∧ μ s < ∞ := by
simpa only [and_assoc] using (μ.finiteAt_nhds x).exists_mem_basis (nhds_basis_opens x)
instance isLocallyFiniteMeasureSMulNNReal [TopologicalSpace α] (μ : Measure α)
[IsLocallyFiniteMeasure μ] (c : ℝ≥0) : IsLocallyFiniteMeasure (c • μ) := by
refine ⟨fun x => ?_⟩
rcases μ.exists_isOpen_measure_lt_top x with ⟨o, xo, o_open, μo⟩
refine ⟨o, o_open.mem_nhds xo, ?_⟩
apply ENNReal.mul_lt_top _ μo.ne
simp
protected theorem Measure.isTopologicalBasis_isOpen_lt_top [TopologicalSpace α]
(μ : Measure α) [IsLocallyFiniteMeasure μ] :
TopologicalSpace.IsTopologicalBasis { s | IsOpen s ∧ μ s < ∞ } := by
refine TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds (fun s hs => hs.1) ?_
intro x s xs hs
rcases μ.exists_isOpen_measure_lt_top x with ⟨v, xv, hv, μv⟩
refine ⟨v ∩ s, ⟨hv.inter hs, lt_of_le_of_lt ?_ μv⟩, ⟨xv, xs⟩, inter_subset_right⟩
exact measure_mono inter_subset_left
/-- A measure `μ` is finite on compacts if any compact set `K` satisfies `μ K < ∞`. -/
class IsFiniteMeasureOnCompacts [TopologicalSpace α] (μ : Measure α) : Prop where
protected lt_top_of_isCompact : ∀ ⦃K : Set α⦄, IsCompact K → μ K < ∞
/-- A compact subset has finite measure for a measure which is finite on compacts. -/
theorem _root_.IsCompact.measure_lt_top [TopologicalSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] ⦃K : Set α⦄ (hK : IsCompact K) : μ K < ∞ :=
IsFiniteMeasureOnCompacts.lt_top_of_isCompact hK
/-- A compact subset has finite measure for a measure which is finite on compacts. -/
theorem _root_.IsCompact.measure_ne_top [TopologicalSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] ⦃K : Set α⦄ (hK : IsCompact K) : μ K ≠ ∞ :=
hK.measure_lt_top.ne
/-- A bounded subset has finite measure for a measure which is finite on compact sets, in a
proper space. -/
theorem _root_.Bornology.IsBounded.measure_lt_top [PseudoMetricSpace α] [ProperSpace α]
{μ : Measure α} [IsFiniteMeasureOnCompacts μ] ⦃s : Set α⦄ (hs : Bornology.IsBounded s) :
μ s < ∞ :=
calc
μ s ≤ μ (closure s) := measure_mono subset_closure
_ < ∞ := (Metric.isCompact_of_isClosed_isBounded isClosed_closure hs.closure).measure_lt_top
theorem measure_closedBall_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] {x : α} {r : ℝ} : μ (Metric.closedBall x r) < ∞ :=
Metric.isBounded_closedBall.measure_lt_top
theorem measure_ball_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] {x : α} {r : ℝ} : μ (Metric.ball x r) < ∞ :=
Metric.isBounded_ball.measure_lt_top
protected theorem IsFiniteMeasureOnCompacts.smul [TopologicalSpace α] (μ : Measure α)
[IsFiniteMeasureOnCompacts μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : IsFiniteMeasureOnCompacts (c • μ) :=
⟨fun _K hK => ENNReal.mul_lt_top hc hK.measure_lt_top.ne⟩
instance IsFiniteMeasureOnCompacts.smul_nnreal [TopologicalSpace α] (μ : Measure α)
[IsFiniteMeasureOnCompacts μ] (c : ℝ≥0) : IsFiniteMeasureOnCompacts (c • μ) :=
IsFiniteMeasureOnCompacts.smul μ coe_ne_top
instance instIsFiniteMeasureOnCompactsRestrict [TopologicalSpace α] {μ : Measure α}
[IsFiniteMeasureOnCompacts μ] {s : Set α} : IsFiniteMeasureOnCompacts (μ.restrict s) :=
⟨fun _k hk ↦ (restrict_apply_le _ _).trans_lt hk.measure_lt_top⟩
instance (priority := 100) CompactSpace.isFiniteMeasure [TopologicalSpace α] [CompactSpace α]
[IsFiniteMeasureOnCompacts μ] : IsFiniteMeasure μ :=
⟨IsFiniteMeasureOnCompacts.lt_top_of_isCompact isCompact_univ⟩
instance (priority := 100) SigmaFinite.of_isFiniteMeasureOnCompacts [TopologicalSpace α]
[SigmaCompactSpace α] (μ : Measure α) [IsFiniteMeasureOnCompacts μ] : SigmaFinite μ :=
⟨⟨{ set := compactCovering α
set_mem := fun _ => trivial
finite := fun n => (isCompact_compactCovering α n).measure_lt_top
spanning := iUnion_compactCovering α }⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) sigmaFinite_of_locallyFinite [TopologicalSpace α]
[SecondCountableTopology α] [IsLocallyFiniteMeasure μ] : SigmaFinite μ := by
choose s hsx hsμ using μ.finiteAt_nhds
rcases TopologicalSpace.countable_cover_nhds hsx with ⟨t, htc, htU⟩
refine Measure.sigmaFinite_of_countable (htc.image s) (forall_mem_image.2 fun x _ => hsμ x) ?_
rwa [sUnion_image]
/-- A measure which is finite on compact sets in a locally compact space is locally finite. -/
instance (priority := 100) isLocallyFiniteMeasure_of_isFiniteMeasureOnCompacts [TopologicalSpace α]
[WeaklyLocallyCompactSpace α] [IsFiniteMeasureOnCompacts μ] : IsLocallyFiniteMeasure μ :=
⟨fun x ↦
let ⟨K, K_compact, K_mem⟩ := exists_compact_mem_nhds x
⟨K, K_mem, K_compact.measure_lt_top⟩⟩
theorem exists_pos_measure_of_cover [Countable ι] {U : ι → Set α} (hU : ⋃ i, U i = univ)
(hμ : μ ≠ 0) : ∃ i, 0 < μ (U i) := by
contrapose! hμ with H
rw [← measure_univ_eq_zero, ← hU]
exact measure_iUnion_null fun i => nonpos_iff_eq_zero.1 (H i)
theorem exists_pos_preimage_ball [PseudoMetricSpace δ] (f : α → δ) (x : δ) (hμ : μ ≠ 0) :
∃ n : ℕ, 0 < μ (f ⁻¹' Metric.ball x n) :=
exists_pos_measure_of_cover (by rw [← preimage_iUnion, Metric.iUnion_ball_nat, preimage_univ]) hμ
theorem exists_pos_ball [PseudoMetricSpace α] (x : α) (hμ : μ ≠ 0) :
∃ n : ℕ, 0 < μ (Metric.ball x n) :=
exists_pos_preimage_ball id x hμ
/-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure
in a second-countable space. -/
@[deprecated (since := "2024-05-14")]
alias null_of_locally_null := measure_null_of_locally_null
theorem exists_ne_forall_mem_nhds_pos_measure_preimage {β} [TopologicalSpace β] [T1Space β]
[SecondCountableTopology β] [Nonempty β] {f : α → β} (h : ∀ b, ∃ᵐ x ∂μ, f x ≠ b) :
∃ a b : β, a ≠ b ∧ (∀ s ∈ 𝓝 a, 0 < μ (f ⁻¹' s)) ∧ ∀ t ∈ 𝓝 b, 0 < μ (f ⁻¹' t) := by
-- We use an `OuterMeasure` so that the proof works without `Measurable f`
set m : OuterMeasure β := OuterMeasure.map f μ.toOuterMeasure
replace h : ∀ b : β, m {b}ᶜ ≠ 0 := fun b => not_eventually.mpr (h b)
inhabit β
have : m univ ≠ 0 := ne_bot_of_le_ne_bot (h default) (measure_mono <| subset_univ _)
rcases exists_mem_forall_mem_nhdsWithin_pos_measure this with ⟨b, -, hb⟩
simp only [nhdsWithin_univ] at hb
rcases exists_mem_forall_mem_nhdsWithin_pos_measure (h b) with ⟨a, hab : a ≠ b, ha⟩
simp only [isOpen_compl_singleton.nhdsWithin_eq hab] at ha
exact ⟨a, b, hab, ha, hb⟩
/-- If two finite measures give the same mass to the whole space and coincide on a π-system made
of measurable sets, then they coincide on all sets in the σ-algebra generated by the π-system. -/
theorem ext_on_measurableSpace_of_generate_finite {α} (m₀ : MeasurableSpace α) {μ ν : Measure α}
[IsFiniteMeasure μ] (C : Set (Set α)) (hμν : ∀ s ∈ C, μ s = ν s) {m : MeasurableSpace α}
(h : m ≤ m₀) (hA : m = MeasurableSpace.generateFrom C) (hC : IsPiSystem C)
(h_univ : μ Set.univ = ν Set.univ) {s : Set α} (hs : MeasurableSet[m] s) : μ s = ν s := by
haveI : IsFiniteMeasure ν := by
constructor
rw [← h_univ]
apply IsFiniteMeasure.measure_univ_lt_top
refine induction_on_inter hA hC (by simp) hμν ?_ ?_ hs
· intro t h1t h2t
have h1t_ : @MeasurableSet α m₀ t := h _ h1t
rw [@measure_compl α m₀ μ t h1t_ (@measure_ne_top α m₀ μ _ t),
@measure_compl α m₀ ν t h1t_ (@measure_ne_top α m₀ ν _ t), h_univ, h2t]
· intro f h1f h2f h3f
have h2f_ : ∀ i : ℕ, @MeasurableSet α m₀ (f i) := fun i => h _ (h2f i)
simp [measure_iUnion, h1f, h3f, h2f_]
/-- Two finite measures are equal if they are equal on the π-system generating the σ-algebra
(and `univ`). -/
theorem ext_of_generate_finite (C : Set (Set α)) (hA : m0 = generateFrom C) (hC : IsPiSystem C)
[IsFiniteMeasure μ] (hμν : ∀ s ∈ C, μ s = ν s) (h_univ : μ univ = ν univ) : μ = ν :=
Measure.ext fun _s hs =>
ext_on_measurableSpace_of_generate_finite m0 C hμν le_rfl hA hC h_univ hs
namespace Measure
section disjointed
/-- Given `S : μ.FiniteSpanningSetsIn {s | MeasurableSet s}`,
`FiniteSpanningSetsIn.disjointed` provides a `FiniteSpanningSetsIn {s | MeasurableSet s}`
such that its underlying sets are pairwise disjoint. -/
protected def FiniteSpanningSetsIn.disjointed {μ : Measure α}
(S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) :
μ.FiniteSpanningSetsIn { s | MeasurableSet s } :=
⟨disjointed S.set, MeasurableSet.disjointed S.set_mem, fun n =>
lt_of_le_of_lt (measure_mono (disjointed_subset S.set n)) (S.finite _),
S.spanning ▸ iUnion_disjointed⟩
theorem FiniteSpanningSetsIn.disjointed_set_eq {μ : Measure α}
(S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) : S.disjointed.set = disjointed S.set :=
rfl
theorem exists_eq_disjoint_finiteSpanningSetsIn (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] :
∃ (S : μ.FiniteSpanningSetsIn { s | MeasurableSet s })
(T : ν.FiniteSpanningSetsIn { s | MeasurableSet s }),
S.set = T.set ∧ Pairwise (Disjoint on S.set) :=
let S := (μ + ν).toFiniteSpanningSetsIn.disjointed
⟨S.ofLE (Measure.le_add_right le_rfl), S.ofLE (Measure.le_add_left le_rfl), rfl,
disjoint_disjointed _⟩
end disjointed
namespace FiniteAtFilter
variable {f g : Filter α}
theorem filter_mono (h : f ≤ g) : μ.FiniteAtFilter g → μ.FiniteAtFilter f := fun ⟨s, hs, hμ⟩ =>
⟨s, h hs, hμ⟩
theorem inf_of_left (h : μ.FiniteAtFilter f) : μ.FiniteAtFilter (f ⊓ g) :=
h.filter_mono inf_le_left
theorem inf_of_right (h : μ.FiniteAtFilter g) : μ.FiniteAtFilter (f ⊓ g) :=
h.filter_mono inf_le_right
@[simp]
theorem inf_ae_iff : μ.FiniteAtFilter (f ⊓ ae μ) ↔ μ.FiniteAtFilter f := by
refine ⟨?_, fun h => h.filter_mono inf_le_left⟩
rintro ⟨s, ⟨t, ht, u, hu, rfl⟩, hμ⟩
suffices μ t ≤ μ (t ∩ u) from ⟨t, ht, this.trans_lt hμ⟩
exact measure_mono_ae (mem_of_superset hu fun x hu ht => ⟨ht, hu⟩)
alias ⟨of_inf_ae, _⟩ := inf_ae_iff
theorem filter_mono_ae (h : f ⊓ (ae μ) ≤ g) (hg : μ.FiniteAtFilter g) : μ.FiniteAtFilter f :=
inf_ae_iff.1 (hg.filter_mono h)
protected theorem measure_mono (h : μ ≤ ν) : ν.FiniteAtFilter f → μ.FiniteAtFilter f :=
fun ⟨s, hs, hν⟩ => ⟨s, hs, (Measure.le_iff'.1 h s).trans_lt hν⟩
@[mono]
protected theorem mono (hf : f ≤ g) (hμ : μ ≤ ν) : ν.FiniteAtFilter g → μ.FiniteAtFilter f :=
fun h => (h.filter_mono hf).measure_mono hμ
protected theorem eventually (h : μ.FiniteAtFilter f) : ∀ᶠ s in f.smallSets, μ s < ∞ :=
(eventually_smallSets' fun _s _t hst ht => (measure_mono hst).trans_lt ht).2 h
theorem filterSup : μ.FiniteAtFilter f → μ.FiniteAtFilter g → μ.FiniteAtFilter (f ⊔ g) :=
fun ⟨s, hsf, hsμ⟩ ⟨t, htg, htμ⟩ =>
⟨s ∪ t, union_mem_sup hsf htg, (measure_union_le s t).trans_lt (ENNReal.add_lt_top.2 ⟨hsμ, htμ⟩)⟩
end FiniteAtFilter
theorem finiteAt_nhdsWithin [TopologicalSpace α] {_m0 : MeasurableSpace α} (μ : Measure α)
[IsLocallyFiniteMeasure μ] (x : α) (s : Set α) : μ.FiniteAtFilter (𝓝[s] x) :=
(finiteAt_nhds μ x).inf_of_left
@[simp]
theorem finiteAt_principal : μ.FiniteAtFilter (𝓟 s) ↔ μ s < ∞ :=
⟨fun ⟨_t, ht, hμ⟩ => (measure_mono ht).trans_lt hμ, fun h => ⟨s, mem_principal_self s, h⟩⟩
theorem isLocallyFiniteMeasure_of_le [TopologicalSpace α] {_m : MeasurableSpace α} {μ ν : Measure α}
[H : IsLocallyFiniteMeasure μ] (h : ν ≤ μ) : IsLocallyFiniteMeasure ν :=
let F := H.finiteAtNhds
⟨fun x => (F x).measure_mono h⟩
end Measure
end MeasureTheory
namespace IsCompact
variable [TopologicalSpace α] [MeasurableSpace α] {μ : Measure α} {s : Set α}
/-- If `s` is a compact set and `μ` is finite at `𝓝 x` for every `x ∈ s`, then `s` admits an open
superset of finite measure. -/
theorem exists_open_superset_measure_lt_top' (h : IsCompact s)
(hμ : ∀ x ∈ s, μ.FiniteAtFilter (𝓝 x)) : ∃ U ⊇ s, IsOpen U ∧ μ U < ∞ := by
refine IsCompact.induction_on h ?_ ?_ ?_ ?_
· use ∅
simp [Superset]
· rintro s t hst ⟨U, htU, hUo, hU⟩
exact ⟨U, hst.trans htU, hUo, hU⟩
· rintro s t ⟨U, hsU, hUo, hU⟩ ⟨V, htV, hVo, hV⟩
refine
⟨U ∪ V, union_subset_union hsU htV, hUo.union hVo,
(measure_union_le _ _).trans_lt <| ENNReal.add_lt_top.2 ⟨hU, hV⟩⟩
· intro x hx
rcases (hμ x hx).exists_mem_basis (nhds_basis_opens _) with ⟨U, ⟨hx, hUo⟩, hU⟩
exact ⟨U, nhdsWithin_le_nhds (hUo.mem_nhds hx), U, Subset.rfl, hUo, hU⟩
/-- If `s` is a compact set and `μ` is a locally finite measure, then `s` admits an open superset of
finite measure. -/
theorem exists_open_superset_measure_lt_top (h : IsCompact s) (μ : Measure α)
[IsLocallyFiniteMeasure μ] : ∃ U ⊇ s, IsOpen U ∧ μ U < ∞ :=
h.exists_open_superset_measure_lt_top' fun x _ => μ.finiteAt_nhds x
theorem measure_lt_top_of_nhdsWithin (h : IsCompact s) (hμ : ∀ x ∈ s, μ.FiniteAtFilter (𝓝[s] x)) :
μ s < ∞ :=
IsCompact.induction_on h (by simp) (fun s t hst ht => (measure_mono hst).trans_lt ht)
(fun s t hs ht => (measure_union_le s t).trans_lt (ENNReal.add_lt_top.2 ⟨hs, ht⟩)) hμ
theorem measure_zero_of_nhdsWithin (hs : IsCompact s) :
(∀ a ∈ s, ∃ t ∈ 𝓝[s] a, μ t = 0) → μ s = 0 := by
simpa only [← compl_mem_ae_iff] using hs.compl_mem_sets_of_nhdsWithin
end IsCompact
-- see Note [lower instance priority]
instance (priority := 100) isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure [TopologicalSpace α]
{_ : MeasurableSpace α} {μ : Measure α} [IsLocallyFiniteMeasure μ] :
IsFiniteMeasureOnCompacts μ :=
⟨fun _s hs => hs.measure_lt_top_of_nhdsWithin fun _ _ => μ.finiteAt_nhdsWithin _ _⟩
theorem isFiniteMeasure_iff_isFiniteMeasureOnCompacts_of_compactSpace [TopologicalSpace α]
[MeasurableSpace α] {μ : Measure α} [CompactSpace α] :
IsFiniteMeasure μ ↔ IsFiniteMeasureOnCompacts μ := by
constructor <;> intros
· infer_instance
· exact CompactSpace.isFiniteMeasure
/-- Compact covering of a `σ`-compact topological space as
`MeasureTheory.Measure.FiniteSpanningSetsIn`. -/
def MeasureTheory.Measure.finiteSpanningSetsInCompact [TopologicalSpace α] [SigmaCompactSpace α]
{_ : MeasurableSpace α} (μ : Measure α) [IsLocallyFiniteMeasure μ] :
μ.FiniteSpanningSetsIn { K | IsCompact K } where
set := compactCovering α
set_mem := isCompact_compactCovering α
finite n := (isCompact_compactCovering α n).measure_lt_top
spanning := iUnion_compactCovering α
/-- A locally finite measure on a `σ`-compact topological space admits a finite spanning sequence
of open sets. -/
def MeasureTheory.Measure.finiteSpanningSetsInOpen [TopologicalSpace α] [SigmaCompactSpace α]
{_ : MeasurableSpace α} (μ : Measure α) [IsLocallyFiniteMeasure μ] :
μ.FiniteSpanningSetsIn { K | IsOpen K } where
set n := ((isCompact_compactCovering α n).exists_open_superset_measure_lt_top μ).choose
set_mem n :=
((isCompact_compactCovering α n).exists_open_superset_measure_lt_top μ).choose_spec.2.1
finite n :=
((isCompact_compactCovering α n).exists_open_superset_measure_lt_top μ).choose_spec.2.2
spanning :=
eq_univ_of_subset
(iUnion_mono fun n =>
((isCompact_compactCovering α n).exists_open_superset_measure_lt_top μ).choose_spec.1)
(iUnion_compactCovering α)
open TopologicalSpace
/-- A locally finite measure on a second countable topological space admits a finite spanning
sequence of open sets. -/
noncomputable irreducible_def MeasureTheory.Measure.finiteSpanningSetsInOpen' [TopologicalSpace α]
[SecondCountableTopology α] {m : MeasurableSpace α} (μ : Measure α) [IsLocallyFiniteMeasure μ] :
μ.FiniteSpanningSetsIn { K | IsOpen K } := by
suffices H : Nonempty (μ.FiniteSpanningSetsIn { K | IsOpen K }) from H.some
cases isEmpty_or_nonempty α
· exact
⟨{ set := fun _ => ∅
set_mem := fun _ => by simp
finite := fun _ => by simp
spanning := by simp [eq_iff_true_of_subsingleton] }⟩
inhabit α
let S : Set (Set α) := { s | IsOpen s ∧ μ s < ∞ }
obtain ⟨T, T_count, TS, hT⟩ : ∃ T : Set (Set α), T.Countable ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S :=
isOpen_sUnion_countable S fun s hs => hs.1
rw [μ.isTopologicalBasis_isOpen_lt_top.sUnion_eq] at hT
have T_ne : T.Nonempty := by
by_contra h'T
rw [not_nonempty_iff_eq_empty.1 h'T, sUnion_empty] at hT
simpa only [← hT] using mem_univ (default : α)
obtain ⟨f, hf⟩ : ∃ f : ℕ → Set α, T = range f := T_count.exists_eq_range T_ne
have fS : ∀ n, f n ∈ S := by
intro n
apply TS
rw [hf]
exact mem_range_self n
refine
⟨{ set := f
set_mem := fun n => (fS n).1
finite := fun n => (fS n).2
spanning := ?_ }⟩
refine eq_univ_of_forall fun x => ?_
obtain ⟨t, tT, xt⟩ : ∃ t : Set α, t ∈ range f ∧ x ∈ t := by
have : x ∈ ⋃₀ T := by simp only [hT, mem_univ]
simpa only [mem_sUnion, exists_prop, ← hf]
obtain ⟨n, rfl⟩ : ∃ n : ℕ, f n = t := by simpa only using tT
exact mem_iUnion_of_mem _ xt
section MeasureIxx
variable [Preorder α] [TopologicalSpace α] [CompactIccSpace α] {m : MeasurableSpace α}
{μ : Measure α} [IsLocallyFiniteMeasure μ] {a b : α}
theorem measure_Icc_lt_top : μ (Icc a b) < ∞ :=
isCompact_Icc.measure_lt_top
theorem measure_Ico_lt_top : μ (Ico a b) < ∞ :=
(measure_mono Ico_subset_Icc_self).trans_lt measure_Icc_lt_top
theorem measure_Ioc_lt_top : μ (Ioc a b) < ∞ :=
(measure_mono Ioc_subset_Icc_self).trans_lt measure_Icc_lt_top
theorem measure_Ioo_lt_top : μ (Ioo a b) < ∞ :=
(measure_mono Ioo_subset_Icc_self).trans_lt measure_Icc_lt_top
end MeasureIxx
|
MeasureTheory\Measure\VectorMeasure.lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.Typeclasses
import Mathlib.Analysis.Complex.Basic
/-!
# Vector valued measures
This file defines vector valued measures, which are σ-additive functions from a set to an add monoid
`M` such that it maps the empty set and non-measurable sets to zero. In the case
that `M = ℝ`, we called the vector measure a signed measure and write `SignedMeasure α`.
Similarly, when `M = ℂ`, we call the measure a complex measure and write `ComplexMeasure α`.
## Main definitions
* `MeasureTheory.VectorMeasure` is a vector valued, σ-additive function that maps the empty
and non-measurable set to zero.
* `MeasureTheory.VectorMeasure.map` is the pushforward of a vector measure along a function.
* `MeasureTheory.VectorMeasure.restrict` is the restriction of a vector measure on some set.
## Notation
* `v ≤[i] w` means that the vector measure `v` restricted on the set `i` is less than or equal
to the vector measure `w` restricted on `i`, i.e. `v.restrict i ≤ w.restrict i`.
## Implementation notes
We require all non-measurable sets to be mapped to zero in order for the extensionality lemma
to only compare the underlying functions for measurable sets.
We use `HasSum` instead of `tsum` in the definition of vector measures in comparison to `Measure`
since this provides summability.
## Tags
vector measure, signed measure, complex measure
-/
noncomputable section
open NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {α β : Type*} {m : MeasurableSpace α}
/-- A vector measure on a measurable space `α` is a σ-additive `M`-valued function (for some `M`
an add monoid) such that the empty set and non-measurable sets are mapped to zero. -/
structure VectorMeasure (α : Type*) [MeasurableSpace α] (M : Type*) [AddCommMonoid M]
[TopologicalSpace M] where
measureOf' : Set α → M
empty' : measureOf' ∅ = 0
not_measurable' ⦃i : Set α⦄ : ¬MeasurableSet i → measureOf' i = 0
m_iUnion' ⦃f : ℕ → Set α⦄ : (∀ i, MeasurableSet (f i)) → Pairwise (Disjoint on f) →
HasSum (fun i => measureOf' (f i)) (measureOf' (⋃ i, f i))
/-- A `SignedMeasure` is an `ℝ`-vector measure. -/
abbrev SignedMeasure (α : Type*) [MeasurableSpace α] :=
VectorMeasure α ℝ
/-- A `ComplexMeasure` is a `ℂ`-vector measure. -/
abbrev ComplexMeasure (α : Type*) [MeasurableSpace α] :=
VectorMeasure α ℂ
open Set MeasureTheory
namespace VectorMeasure
section
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
attribute [coe] VectorMeasure.measureOf'
instance instCoeFun : CoeFun (VectorMeasure α M) fun _ => Set α → M :=
⟨VectorMeasure.measureOf'⟩
initialize_simps_projections VectorMeasure (measureOf' → apply)
@[simp]
theorem empty (v : VectorMeasure α M) : v ∅ = 0 :=
v.empty'
theorem not_measurable (v : VectorMeasure α M) {i : Set α} (hi : ¬MeasurableSet i) : v i = 0 :=
v.not_measurable' hi
theorem m_iUnion (v : VectorMeasure α M) {f : ℕ → Set α} (hf₁ : ∀ i, MeasurableSet (f i))
(hf₂ : Pairwise (Disjoint on f)) : HasSum (fun i => v (f i)) (v (⋃ i, f i)) :=
v.m_iUnion' hf₁ hf₂
theorem of_disjoint_iUnion_nat [T2Space M] (v : VectorMeasure α M) {f : ℕ → Set α}
(hf₁ : ∀ i, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) :
v (⋃ i, f i) = ∑' i, v (f i) :=
(v.m_iUnion hf₁ hf₂).tsum_eq.symm
theorem coe_injective : @Function.Injective (VectorMeasure α M) (Set α → M) (⇑) := fun v w h => by
cases v
cases w
congr
theorem ext_iff' (v w : VectorMeasure α M) : v = w ↔ ∀ i : Set α, v i = w i := by
rw [← coe_injective.eq_iff, Function.funext_iff]
theorem ext_iff (v w : VectorMeasure α M) : v = w ↔ ∀ i : Set α, MeasurableSet i → v i = w i := by
constructor
· rintro rfl _ _
rfl
· rw [ext_iff']
intro h i
by_cases hi : MeasurableSet i
· exact h i hi
· simp_rw [not_measurable _ hi]
@[ext]
theorem ext {s t : VectorMeasure α M} (h : ∀ i : Set α, MeasurableSet i → s i = t i) : s = t :=
(ext_iff s t).2 h
variable [T2Space M] {v : VectorMeasure α M} {f : ℕ → Set α}
theorem hasSum_of_disjoint_iUnion [Countable β] {f : β → Set α} (hf₁ : ∀ i, MeasurableSet (f i))
(hf₂ : Pairwise (Disjoint on f)) : HasSum (fun i => v (f i)) (v (⋃ i, f i)) := by
cases nonempty_encodable β
set g := fun i : ℕ => ⋃ (b : β) (_ : b ∈ Encodable.decode₂ β i), f b with hg
have hg₁ : ∀ i, MeasurableSet (g i) :=
fun _ => MeasurableSet.iUnion fun b => MeasurableSet.iUnion fun _ => hf₁ b
have hg₂ : Pairwise (Disjoint on g) := Encodable.iUnion_decode₂_disjoint_on hf₂
have := v.of_disjoint_iUnion_nat hg₁ hg₂
rw [hg, Encodable.iUnion_decode₂] at this
have hg₃ : (fun i : β => v (f i)) = fun i => v (g (Encodable.encode i)) := by
ext x
rw [hg]
simp only
congr
ext y
simp only [exists_prop, Set.mem_iUnion, Option.mem_def]
constructor
· intro hy
exact ⟨x, (Encodable.decode₂_is_partial_inv _ _).2 rfl, hy⟩
· rintro ⟨b, hb₁, hb₂⟩
rw [Encodable.decode₂_is_partial_inv _ _] at hb₁
rwa [← Encodable.encode_injective hb₁]
rw [Summable.hasSum_iff, this, ← tsum_iUnion_decode₂]
· exact v.empty
· rw [hg₃]
change Summable ((fun i => v (g i)) ∘ Encodable.encode)
rw [Function.Injective.summable_iff Encodable.encode_injective]
· exact (v.m_iUnion hg₁ hg₂).summable
· intro x hx
convert v.empty
simp only [g, Set.iUnion_eq_empty, Option.mem_def, not_exists, Set.mem_range] at hx ⊢
intro i hi
exact False.elim ((hx i) ((Encodable.decode₂_is_partial_inv _ _).1 hi))
theorem of_disjoint_iUnion [Countable β] {f : β → Set α} (hf₁ : ∀ i, MeasurableSet (f i))
(hf₂ : Pairwise (Disjoint on f)) : v (⋃ i, f i) = ∑' i, v (f i) :=
(hasSum_of_disjoint_iUnion hf₁ hf₂).tsum_eq.symm
theorem of_union {A B : Set α} (h : Disjoint A B) (hA : MeasurableSet A) (hB : MeasurableSet B) :
v (A ∪ B) = v A + v B := by
rw [Set.union_eq_iUnion, of_disjoint_iUnion, tsum_fintype, Fintype.sum_bool, cond, cond]
exacts [fun b => Bool.casesOn b hB hA, pairwise_disjoint_on_bool.2 h]
theorem of_add_of_diff {A B : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B) (h : A ⊆ B) :
v A + v (B \ A) = v B := by
rw [← of_union (@Set.disjoint_sdiff_right _ A B) hA (hB.diff hA), Set.union_diff_cancel h]
theorem of_diff {M : Type*} [AddCommGroup M] [TopologicalSpace M] [T2Space M]
{v : VectorMeasure α M} {A B : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B)
(h : A ⊆ B) : v (B \ A) = v B - v A := by
rw [← of_add_of_diff hA hB h, add_sub_cancel_left]
theorem of_diff_of_diff_eq_zero {A B : Set α} (hA : MeasurableSet A) (hB : MeasurableSet B)
(h' : v (B \ A) = 0) : v (A \ B) + v B = v A := by
symm
calc
v A = v (A \ B ∪ A ∩ B) := by simp only [Set.diff_union_inter]
_ = v (A \ B) + v (A ∩ B) := by
rw [of_union]
· rw [disjoint_comm]
exact Set.disjoint_of_subset_left A.inter_subset_right disjoint_sdiff_self_right
· exact hA.diff hB
· exact hA.inter hB
_ = v (A \ B) + v (A ∩ B ∪ B \ A) := by
rw [of_union, h', add_zero]
· exact Set.disjoint_of_subset_left A.inter_subset_left disjoint_sdiff_self_right
· exact hA.inter hB
· exact hB.diff hA
_ = v (A \ B) + v B := by rw [Set.union_comm, Set.inter_comm, Set.diff_union_inter]
theorem of_iUnion_nonneg {M : Type*} [TopologicalSpace M] [OrderedAddCommMonoid M]
[OrderClosedTopology M] {v : VectorMeasure α M} (hf₁ : ∀ i, MeasurableSet (f i))
(hf₂ : Pairwise (Disjoint on f)) (hf₃ : ∀ i, 0 ≤ v (f i)) : 0 ≤ v (⋃ i, f i) :=
(v.of_disjoint_iUnion_nat hf₁ hf₂).symm ▸ tsum_nonneg hf₃
theorem of_iUnion_nonpos {M : Type*} [TopologicalSpace M] [OrderedAddCommMonoid M]
[OrderClosedTopology M] {v : VectorMeasure α M} (hf₁ : ∀ i, MeasurableSet (f i))
(hf₂ : Pairwise (Disjoint on f)) (hf₃ : ∀ i, v (f i) ≤ 0) : v (⋃ i, f i) ≤ 0 :=
(v.of_disjoint_iUnion_nat hf₁ hf₂).symm ▸ tsum_nonpos hf₃
theorem of_nonneg_disjoint_union_eq_zero {s : SignedMeasure α} {A B : Set α} (h : Disjoint A B)
(hA₁ : MeasurableSet A) (hB₁ : MeasurableSet B) (hA₂ : 0 ≤ s A) (hB₂ : 0 ≤ s B)
(hAB : s (A ∪ B) = 0) : s A = 0 := by
rw [of_union h hA₁ hB₁] at hAB
linarith
theorem of_nonpos_disjoint_union_eq_zero {s : SignedMeasure α} {A B : Set α} (h : Disjoint A B)
(hA₁ : MeasurableSet A) (hB₁ : MeasurableSet B) (hA₂ : s A ≤ 0) (hB₂ : s B ≤ 0)
(hAB : s (A ∪ B) = 0) : s A = 0 := by
rw [of_union h hA₁ hB₁] at hAB
linarith
end
section SMul
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
variable {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M]
/-- Given a real number `r` and a signed measure `s`, `smul r s` is the signed
measure corresponding to the function `r • s`. -/
def smul (r : R) (v : VectorMeasure α M) : VectorMeasure α M where
measureOf' := r • ⇑v
empty' := by rw [Pi.smul_apply, empty, smul_zero]
not_measurable' _ hi := by rw [Pi.smul_apply, v.not_measurable hi, smul_zero]
m_iUnion' _ hf₁ hf₂ := by exact HasSum.const_smul _ (v.m_iUnion hf₁ hf₂)
instance instSMul : SMul R (VectorMeasure α M) :=
⟨smul⟩
@[simp]
theorem coe_smul (r : R) (v : VectorMeasure α M) : ⇑(r • v) = r • ⇑v := rfl
theorem smul_apply (r : R) (v : VectorMeasure α M) (i : Set α) : (r • v) i = r • v i := rfl
end SMul
section AddCommMonoid
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
instance instZero : Zero (VectorMeasure α M) :=
⟨⟨0, rfl, fun _ _ => rfl, fun _ _ _ => hasSum_zero⟩⟩
instance instInhabited : Inhabited (VectorMeasure α M) :=
⟨0⟩
@[simp]
theorem coe_zero : ⇑(0 : VectorMeasure α M) = 0 := rfl
theorem zero_apply (i : Set α) : (0 : VectorMeasure α M) i = 0 := rfl
variable [ContinuousAdd M]
/-- The sum of two vector measure is a vector measure. -/
def add (v w : VectorMeasure α M) : VectorMeasure α M where
measureOf' := v + w
empty' := by simp
not_measurable' _ hi := by rw [Pi.add_apply, v.not_measurable hi, w.not_measurable hi, add_zero]
m_iUnion' f hf₁ hf₂ := HasSum.add (v.m_iUnion hf₁ hf₂) (w.m_iUnion hf₁ hf₂)
instance instAdd : Add (VectorMeasure α M) :=
⟨add⟩
@[simp]
theorem coe_add (v w : VectorMeasure α M) : ⇑(v + w) = v + w := rfl
theorem add_apply (v w : VectorMeasure α M) (i : Set α) : (v + w) i = v i + w i := rfl
instance instAddCommMonoid : AddCommMonoid (VectorMeasure α M) :=
Function.Injective.addCommMonoid _ coe_injective coe_zero coe_add fun _ _ => coe_smul _ _
/-- `(⇑)` is an `AddMonoidHom`. -/
@[simps]
def coeFnAddMonoidHom : VectorMeasure α M →+ Set α → M where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
end AddCommMonoid
section AddCommGroup
variable {M : Type*} [AddCommGroup M] [TopologicalSpace M] [TopologicalAddGroup M]
/-- The negative of a vector measure is a vector measure. -/
def neg (v : VectorMeasure α M) : VectorMeasure α M where
measureOf' := -v
empty' := by simp
not_measurable' _ hi := by rw [Pi.neg_apply, neg_eq_zero, v.not_measurable hi]
m_iUnion' f hf₁ hf₂ := HasSum.neg <| v.m_iUnion hf₁ hf₂
instance instNeg : Neg (VectorMeasure α M) :=
⟨neg⟩
@[simp]
theorem coe_neg (v : VectorMeasure α M) : ⇑(-v) = -v := rfl
theorem neg_apply (v : VectorMeasure α M) (i : Set α) : (-v) i = -v i := rfl
/-- The difference of two vector measure is a vector measure. -/
def sub (v w : VectorMeasure α M) : VectorMeasure α M where
measureOf' := v - w
empty' := by simp
not_measurable' _ hi := by rw [Pi.sub_apply, v.not_measurable hi, w.not_measurable hi, sub_zero]
m_iUnion' f hf₁ hf₂ := HasSum.sub (v.m_iUnion hf₁ hf₂) (w.m_iUnion hf₁ hf₂)
instance instSub : Sub (VectorMeasure α M) :=
⟨sub⟩
@[simp]
theorem coe_sub (v w : VectorMeasure α M) : ⇑(v - w) = v - w := rfl
theorem sub_apply (v w : VectorMeasure α M) (i : Set α) : (v - w) i = v i - w i := rfl
instance instAddCommGroup : AddCommGroup (VectorMeasure α M) :=
Function.Injective.addCommGroup _ coe_injective coe_zero coe_add coe_neg coe_sub
(fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
end AddCommGroup
section DistribMulAction
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
variable {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M]
instance instDistribMulAction [ContinuousAdd M] : DistribMulAction R (VectorMeasure α M) :=
Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective coe_smul
end DistribMulAction
section Module
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
variable {R : Type*} [Semiring R] [Module R M] [ContinuousConstSMul R M]
instance instModule [ContinuousAdd M] : Module R (VectorMeasure α M) :=
Function.Injective.module R coeFnAddMonoidHom coe_injective coe_smul
end Module
end VectorMeasure
namespace Measure
open Classical in
/-- A finite measure coerced into a real function is a signed measure. -/
@[simps]
def toSignedMeasure (μ : Measure α) [hμ : IsFiniteMeasure μ] : SignedMeasure α where
measureOf' := fun s : Set α => if MeasurableSet s then (μ s).toReal else 0
empty' := by simp [μ.empty]
not_measurable' _ hi := if_neg hi
m_iUnion' f hf₁ hf₂ := by
simp only [*, MeasurableSet.iUnion hf₁, if_true, measure_iUnion hf₂ hf₁]
rw [ENNReal.tsum_toReal_eq]
exacts [(summable_measure_toReal hf₁ hf₂).hasSum, fun _ ↦ measure_ne_top _ _]
theorem toSignedMeasure_apply_measurable {μ : Measure α} [IsFiniteMeasure μ] {i : Set α}
(hi : MeasurableSet i) : μ.toSignedMeasure i = (μ i).toReal :=
if_pos hi
-- Without this lemma, `singularPart_neg` in `MeasureTheory.Decomposition.Lebesgue` is
-- extremely slow
theorem toSignedMeasure_congr {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν]
(h : μ = ν) : μ.toSignedMeasure = ν.toSignedMeasure := by
congr
theorem toSignedMeasure_eq_toSignedMeasure_iff {μ ν : Measure α} [IsFiniteMeasure μ]
[IsFiniteMeasure ν] : μ.toSignedMeasure = ν.toSignedMeasure ↔ μ = ν := by
refine ⟨fun h => ?_, fun h => ?_⟩
· ext1 i hi
have : μ.toSignedMeasure i = ν.toSignedMeasure i := by rw [h]
rwa [toSignedMeasure_apply_measurable hi, toSignedMeasure_apply_measurable hi,
ENNReal.toReal_eq_toReal] at this
<;> exact measure_ne_top _ _
· congr
@[simp]
theorem toSignedMeasure_zero : (0 : Measure α).toSignedMeasure = 0 := by
ext i
simp
@[simp]
theorem toSignedMeasure_add (μ ν : Measure α) [IsFiniteMeasure μ] [IsFiniteMeasure ν] :
(μ + ν).toSignedMeasure = μ.toSignedMeasure + ν.toSignedMeasure := by
ext i hi
rw [toSignedMeasure_apply_measurable hi, add_apply,
ENNReal.toReal_add (ne_of_lt (measure_lt_top _ _)) (ne_of_lt (measure_lt_top _ _)),
VectorMeasure.add_apply, toSignedMeasure_apply_measurable hi,
toSignedMeasure_apply_measurable hi]
@[simp]
theorem toSignedMeasure_smul (μ : Measure α) [IsFiniteMeasure μ] (r : ℝ≥0) :
(r • μ).toSignedMeasure = r • μ.toSignedMeasure := by
ext i hi
rw [toSignedMeasure_apply_measurable hi, VectorMeasure.smul_apply,
toSignedMeasure_apply_measurable hi, coe_smul, Pi.smul_apply, ENNReal.toReal_smul]
open Classical in
/-- A measure is a vector measure over `ℝ≥0∞`. -/
@[simps]
def toENNRealVectorMeasure (μ : Measure α) : VectorMeasure α ℝ≥0∞ where
measureOf' := fun i : Set α => if MeasurableSet i then μ i else 0
empty' := by simp [μ.empty]
not_measurable' _ hi := if_neg hi
m_iUnion' _ hf₁ hf₂ := by
simp only
rw [Summable.hasSum_iff ENNReal.summable, if_pos (MeasurableSet.iUnion hf₁),
MeasureTheory.measure_iUnion hf₂ hf₁]
exact tsum_congr fun n => if_pos (hf₁ n)
theorem toENNRealVectorMeasure_apply_measurable {μ : Measure α} {i : Set α} (hi : MeasurableSet i) :
μ.toENNRealVectorMeasure i = μ i :=
if_pos hi
@[simp]
theorem toENNRealVectorMeasure_zero : (0 : Measure α).toENNRealVectorMeasure = 0 := by
ext i
simp
@[simp]
theorem toENNRealVectorMeasure_add (μ ν : Measure α) :
(μ + ν).toENNRealVectorMeasure = μ.toENNRealVectorMeasure + ν.toENNRealVectorMeasure := by
refine MeasureTheory.VectorMeasure.ext fun i hi => ?_
rw [toENNRealVectorMeasure_apply_measurable hi, add_apply, VectorMeasure.add_apply,
toENNRealVectorMeasure_apply_measurable hi, toENNRealVectorMeasure_apply_measurable hi]
theorem toSignedMeasure_sub_apply {μ ν : Measure α} [IsFiniteMeasure μ] [IsFiniteMeasure ν]
{i : Set α} (hi : MeasurableSet i) :
(μ.toSignedMeasure - ν.toSignedMeasure) i = (μ i).toReal - (ν i).toReal := by
rw [VectorMeasure.sub_apply, toSignedMeasure_apply_measurable hi,
Measure.toSignedMeasure_apply_measurable hi]
end Measure
namespace VectorMeasure
open Measure
section
/-- A vector measure over `ℝ≥0∞` is a measure. -/
def ennrealToMeasure {_ : MeasurableSpace α} (v : VectorMeasure α ℝ≥0∞) : Measure α :=
ofMeasurable (fun s _ => v s) v.empty fun _ hf₁ hf₂ => v.of_disjoint_iUnion_nat hf₁ hf₂
theorem ennrealToMeasure_apply {m : MeasurableSpace α} {v : VectorMeasure α ℝ≥0∞} {s : Set α}
(hs : MeasurableSet s) : ennrealToMeasure v s = v s := by
rw [ennrealToMeasure, ofMeasurable_apply _ hs]
@[simp]
theorem _root_.MeasureTheory.Measure.toENNRealVectorMeasure_ennrealToMeasure
(μ : VectorMeasure α ℝ≥0∞) :
toENNRealVectorMeasure (ennrealToMeasure μ) = μ := ext fun s hs => by
rw [toENNRealVectorMeasure_apply_measurable hs, ennrealToMeasure_apply hs]
@[simp]
theorem ennrealToMeasure_toENNRealVectorMeasure (μ : Measure α) :
ennrealToMeasure (toENNRealVectorMeasure μ) = μ := Measure.ext fun s hs => by
rw [ennrealToMeasure_apply hs, toENNRealVectorMeasure_apply_measurable hs]
/-- The equiv between `VectorMeasure α ℝ≥0∞` and `Measure α` formed by
`MeasureTheory.VectorMeasure.ennrealToMeasure` and
`MeasureTheory.Measure.toENNRealVectorMeasure`. -/
@[simps]
def equivMeasure [MeasurableSpace α] : VectorMeasure α ℝ≥0∞ ≃ Measure α where
toFun := ennrealToMeasure
invFun := toENNRealVectorMeasure
left_inv := toENNRealVectorMeasure_ennrealToMeasure
right_inv := ennrealToMeasure_toENNRealVectorMeasure
end
section
variable [MeasurableSpace α] [MeasurableSpace β]
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
variable (v : VectorMeasure α M)
open Classical in
/-- The pushforward of a vector measure along a function. -/
def map (v : VectorMeasure α M) (f : α → β) : VectorMeasure β M :=
if hf : Measurable f then
{ measureOf' := fun s => if MeasurableSet s then v (f ⁻¹' s) else 0
empty' := by simp
not_measurable' := fun i hi => if_neg hi
m_iUnion' := by
intro g hg₁ hg₂
simp only
convert v.m_iUnion (fun i => hf (hg₁ i)) fun i j hij => (hg₂ hij).preimage _
· rw [if_pos (hg₁ _)]
· rw [Set.preimage_iUnion, if_pos (MeasurableSet.iUnion hg₁)] }
else 0
theorem map_not_measurable {f : α → β} (hf : ¬Measurable f) : v.map f = 0 :=
dif_neg hf
theorem map_apply {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
v.map f s = v (f ⁻¹' s) := by
rw [map, dif_pos hf]
exact if_pos hs
@[simp]
theorem map_id : v.map id = v :=
ext fun i hi => by rw [map_apply v measurable_id hi, Set.preimage_id]
@[simp]
theorem map_zero (f : α → β) : (0 : VectorMeasure α M).map f = 0 := by
by_cases hf : Measurable f
· ext i hi
rw [map_apply _ hf hi, zero_apply, zero_apply]
· exact dif_neg hf
section
variable {N : Type*} [AddCommMonoid N] [TopologicalSpace N]
/-- Given a vector measure `v` on `M` and a continuous `AddMonoidHom` `f : M → N`, `f ∘ v` is a
vector measure on `N`. -/
def mapRange (v : VectorMeasure α M) (f : M →+ N) (hf : Continuous f) : VectorMeasure α N where
measureOf' s := f (v s)
empty' := by simp only; rw [empty, AddMonoidHom.map_zero]
not_measurable' i hi := by simp only; rw [not_measurable v hi, AddMonoidHom.map_zero]
m_iUnion' g hg₁ hg₂ := HasSum.map (v.m_iUnion hg₁ hg₂) f hf
@[simp]
theorem mapRange_apply {f : M →+ N} (hf : Continuous f) {s : Set α} : v.mapRange f hf s = f (v s) :=
rfl
@[simp]
theorem mapRange_id : v.mapRange (AddMonoidHom.id M) continuous_id = v := by
ext
rfl
@[simp]
theorem mapRange_zero {f : M →+ N} (hf : Continuous f) :
mapRange (0 : VectorMeasure α M) f hf = 0 := by
ext
simp
section ContinuousAdd
variable [ContinuousAdd M] [ContinuousAdd N]
@[simp]
theorem mapRange_add {v w : VectorMeasure α M} {f : M →+ N} (hf : Continuous f) :
(v + w).mapRange f hf = v.mapRange f hf + w.mapRange f hf := by
ext
simp
/-- Given a continuous `AddMonoidHom` `f : M → N`, `mapRangeHom` is the `AddMonoidHom` mapping the
vector measure `v` on `M` to the vector measure `f ∘ v` on `N`. -/
def mapRangeHom (f : M →+ N) (hf : Continuous f) : VectorMeasure α M →+ VectorMeasure α N where
toFun v := v.mapRange f hf
map_zero' := mapRange_zero hf
map_add' _ _ := mapRange_add hf
end ContinuousAdd
section Module
variable {R : Type*} [Semiring R] [Module R M] [Module R N]
variable [ContinuousAdd M] [ContinuousAdd N] [ContinuousConstSMul R M] [ContinuousConstSMul R N]
/-- Given a continuous linear map `f : M → N`, `mapRangeₗ` is the linear map mapping the
vector measure `v` on `M` to the vector measure `f ∘ v` on `N`. -/
def mapRangeₗ (f : M →ₗ[R] N) (hf : Continuous f) : VectorMeasure α M →ₗ[R] VectorMeasure α N where
toFun v := v.mapRange f.toAddMonoidHom hf
map_add' _ _ := mapRange_add hf
map_smul' := by
intros
ext
simp
end Module
end
open Classical in
/-- The restriction of a vector measure on some set. -/
def restrict (v : VectorMeasure α M) (i : Set α) : VectorMeasure α M :=
if hi : MeasurableSet i then
{ measureOf' := fun s => if MeasurableSet s then v (s ∩ i) else 0
empty' := by simp
not_measurable' := fun i hi => if_neg hi
m_iUnion' := by
intro f hf₁ hf₂
simp only
convert v.m_iUnion (fun n => (hf₁ n).inter hi)
(hf₂.mono fun i j => Disjoint.mono inf_le_left inf_le_left)
· rw [if_pos (hf₁ _)]
· rw [Set.iUnion_inter, if_pos (MeasurableSet.iUnion hf₁)] }
else 0
theorem restrict_not_measurable {i : Set α} (hi : ¬MeasurableSet i) : v.restrict i = 0 :=
dif_neg hi
theorem restrict_apply {i : Set α} (hi : MeasurableSet i) {j : Set α} (hj : MeasurableSet j) :
v.restrict i j = v (j ∩ i) := by
rw [restrict, dif_pos hi]
exact if_pos hj
theorem restrict_eq_self {i : Set α} (hi : MeasurableSet i) {j : Set α} (hj : MeasurableSet j)
(hij : j ⊆ i) : v.restrict i j = v j := by
rw [restrict_apply v hi hj, Set.inter_eq_left.2 hij]
@[simp]
theorem restrict_empty : v.restrict ∅ = 0 :=
ext fun i hi => by
rw [restrict_apply v MeasurableSet.empty hi, Set.inter_empty, v.empty, zero_apply]
@[simp]
theorem restrict_univ : v.restrict Set.univ = v :=
ext fun i hi => by rw [restrict_apply v MeasurableSet.univ hi, Set.inter_univ]
@[simp]
theorem restrict_zero {i : Set α} : (0 : VectorMeasure α M).restrict i = 0 := by
by_cases hi : MeasurableSet i
· ext j hj
rw [restrict_apply 0 hi hj, zero_apply, zero_apply]
· exact dif_neg hi
section ContinuousAdd
variable [ContinuousAdd M]
theorem map_add (v w : VectorMeasure α M) (f : α → β) : (v + w).map f = v.map f + w.map f := by
by_cases hf : Measurable f
· ext i hi
simp [map_apply _ hf hi]
· simp [map, dif_neg hf]
/-- `VectorMeasure.map` as an additive monoid homomorphism. -/
@[simps]
def mapGm (f : α → β) : VectorMeasure α M →+ VectorMeasure β M where
toFun v := v.map f
map_zero' := map_zero f
map_add' _ _ := map_add _ _ f
theorem restrict_add (v w : VectorMeasure α M) (i : Set α) :
(v + w).restrict i = v.restrict i + w.restrict i := by
by_cases hi : MeasurableSet i
· ext j hj
simp [restrict_apply _ hi hj]
· simp [restrict_not_measurable _ hi]
/-- `VectorMeasure.restrict` as an additive monoid homomorphism. -/
@[simps]
def restrictGm (i : Set α) : VectorMeasure α M →+ VectorMeasure α M where
toFun v := v.restrict i
map_zero' := restrict_zero
map_add' _ _ := restrict_add _ _ i
end ContinuousAdd
end
section
variable [MeasurableSpace β]
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
variable {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M]
@[simp]
theorem map_smul {v : VectorMeasure α M} {f : α → β} (c : R) : (c • v).map f = c • v.map f := by
by_cases hf : Measurable f
· ext i hi
simp [map_apply _ hf hi]
· simp only [map, dif_neg hf]
-- `smul_zero` does not work since we do not require `ContinuousAdd`
ext i
simp
@[simp]
theorem restrict_smul {v : VectorMeasure α M} {i : Set α} (c : R) :
(c • v).restrict i = c • v.restrict i := by
by_cases hi : MeasurableSet i
· ext j hj
simp [restrict_apply _ hi hj]
· simp only [restrict_not_measurable _ hi]
-- `smul_zero` does not work since we do not require `ContinuousAdd`
ext j
simp
end
section
variable [MeasurableSpace β]
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M]
variable {R : Type*} [Semiring R] [Module R M] [ContinuousConstSMul R M] [ContinuousAdd M]
/-- `VectorMeasure.map` as a linear map. -/
@[simps]
def mapₗ (f : α → β) : VectorMeasure α M →ₗ[R] VectorMeasure β M where
toFun v := v.map f
map_add' _ _ := map_add _ _ f
map_smul' _ _ := map_smul _
/-- `VectorMeasure.restrict` as an additive monoid homomorphism. -/
@[simps]
def restrictₗ (i : Set α) : VectorMeasure α M →ₗ[R] VectorMeasure α M where
toFun v := v.restrict i
map_add' _ _ := restrict_add _ _ i
map_smul' _ _ := restrict_smul _
end
section
variable {M : Type*} [TopologicalSpace M] [AddCommMonoid M] [PartialOrder M]
/-- Vector measures over a partially ordered monoid is partially ordered.
This definition is consistent with `Measure.instPartialOrder`. -/
instance instPartialOrder : PartialOrder (VectorMeasure α M) where
le v w := ∀ i, MeasurableSet i → v i ≤ w i
le_refl v i _ := le_rfl
le_trans u v w h₁ h₂ i hi := le_trans (h₁ i hi) (h₂ i hi)
le_antisymm v w h₁ h₂ := ext fun i hi => le_antisymm (h₁ i hi) (h₂ i hi)
variable {u v w : VectorMeasure α M}
theorem le_iff : v ≤ w ↔ ∀ i, MeasurableSet i → v i ≤ w i := Iff.rfl
theorem le_iff' : v ≤ w ↔ ∀ i, v i ≤ w i := by
refine ⟨fun h i => ?_, fun h i _ => h i⟩
by_cases hi : MeasurableSet i
· exact h i hi
· rw [v.not_measurable hi, w.not_measurable hi]
end
set_option quotPrecheck false in -- Porting note: error message suggested to do this
scoped[MeasureTheory]
notation:50 v " ≤[" i:50 "] " w:50 =>
MeasureTheory.VectorMeasure.restrict v i ≤ MeasureTheory.VectorMeasure.restrict w i
section
variable {M : Type*} [TopologicalSpace M] [AddCommMonoid M] [PartialOrder M]
variable (v w : VectorMeasure α M)
theorem restrict_le_restrict_iff {i : Set α} (hi : MeasurableSet i) :
v ≤[i] w ↔ ∀ ⦃j⦄, MeasurableSet j → j ⊆ i → v j ≤ w j :=
⟨fun h j hj₁ hj₂ => restrict_eq_self v hi hj₁ hj₂ ▸ restrict_eq_self w hi hj₁ hj₂ ▸ h j hj₁,
fun h => le_iff.1 fun _ hj =>
(restrict_apply v hi hj).symm ▸ (restrict_apply w hi hj).symm ▸
h (hj.inter hi) Set.inter_subset_right⟩
theorem subset_le_of_restrict_le_restrict {i : Set α} (hi : MeasurableSet i) (hi₂ : v ≤[i] w)
{j : Set α} (hj : j ⊆ i) : v j ≤ w j := by
by_cases hj₁ : MeasurableSet j
· exact (restrict_le_restrict_iff _ _ hi).1 hi₂ hj₁ hj
· rw [v.not_measurable hj₁, w.not_measurable hj₁]
theorem restrict_le_restrict_of_subset_le {i : Set α}
(h : ∀ ⦃j⦄, MeasurableSet j → j ⊆ i → v j ≤ w j) : v ≤[i] w := by
by_cases hi : MeasurableSet i
· exact (restrict_le_restrict_iff _ _ hi).2 h
· rw [restrict_not_measurable v hi, restrict_not_measurable w hi]
theorem restrict_le_restrict_subset {i j : Set α} (hi₁ : MeasurableSet i) (hi₂ : v ≤[i] w)
(hij : j ⊆ i) : v ≤[j] w :=
restrict_le_restrict_of_subset_le v w fun _ _ hk₂ =>
subset_le_of_restrict_le_restrict v w hi₁ hi₂ (Set.Subset.trans hk₂ hij)
theorem le_restrict_empty : v ≤[∅] w := by
intro j _
rw [restrict_empty, restrict_empty]
theorem le_restrict_univ_iff_le : v ≤[Set.univ] w ↔ v ≤ w := by
constructor
· intro h s hs
have := h s hs
rwa [restrict_apply _ MeasurableSet.univ hs, Set.inter_univ,
restrict_apply _ MeasurableSet.univ hs, Set.inter_univ] at this
· intro h s hs
rw [restrict_apply _ MeasurableSet.univ hs, Set.inter_univ,
restrict_apply _ MeasurableSet.univ hs, Set.inter_univ]
exact h s hs
end
section
variable {M : Type*} [TopologicalSpace M] [OrderedAddCommGroup M] [TopologicalAddGroup M]
variable (v w : VectorMeasure α M)
nonrec theorem neg_le_neg {i : Set α} (hi : MeasurableSet i) (h : v ≤[i] w) : -w ≤[i] -v := by
intro j hj₁
rw [restrict_apply _ hi hj₁, restrict_apply _ hi hj₁, neg_apply, neg_apply]
refine neg_le_neg ?_
rw [← restrict_apply _ hi hj₁, ← restrict_apply _ hi hj₁]
exact h j hj₁
@[simp]
theorem neg_le_neg_iff {i : Set α} (hi : MeasurableSet i) : -w ≤[i] -v ↔ v ≤[i] w :=
⟨fun h => neg_neg v ▸ neg_neg w ▸ neg_le_neg _ _ hi h, fun h => neg_le_neg _ _ hi h⟩
end
section
variable {M : Type*} [TopologicalSpace M] [OrderedAddCommMonoid M] [OrderClosedTopology M]
variable (v w : VectorMeasure α M) {i j : Set α}
theorem restrict_le_restrict_iUnion {f : ℕ → Set α} (hf₁ : ∀ n, MeasurableSet (f n))
(hf₂ : ∀ n, v ≤[f n] w) : v ≤[⋃ n, f n] w := by
refine restrict_le_restrict_of_subset_le v w fun a ha₁ ha₂ => ?_
have ha₃ : ⋃ n, a ∩ disjointed f n = a := by
rwa [← Set.inter_iUnion, iUnion_disjointed, Set.inter_eq_left]
have ha₄ : Pairwise (Disjoint on fun n => a ∩ disjointed f n) :=
(disjoint_disjointed _).mono fun i j => Disjoint.mono inf_le_right inf_le_right
rw [← ha₃, v.of_disjoint_iUnion_nat _ ha₄, w.of_disjoint_iUnion_nat _ ha₄]
· refine tsum_le_tsum (fun n => (restrict_le_restrict_iff v w (hf₁ n)).1 (hf₂ n) ?_ ?_) ?_ ?_
· exact ha₁.inter (MeasurableSet.disjointed hf₁ n)
· exact Set.Subset.trans Set.inter_subset_right (disjointed_subset _ _)
· refine (v.m_iUnion (fun n => ?_) ?_).summable
· exact ha₁.inter (MeasurableSet.disjointed hf₁ n)
· exact (disjoint_disjointed _).mono fun i j => Disjoint.mono inf_le_right inf_le_right
· refine (w.m_iUnion (fun n => ?_) ?_).summable
· exact ha₁.inter (MeasurableSet.disjointed hf₁ n)
· exact (disjoint_disjointed _).mono fun i j => Disjoint.mono inf_le_right inf_le_right
· intro n
exact ha₁.inter (MeasurableSet.disjointed hf₁ n)
· exact fun n => ha₁.inter (MeasurableSet.disjointed hf₁ n)
theorem restrict_le_restrict_countable_iUnion [Countable β] {f : β → Set α}
(hf₁ : ∀ b, MeasurableSet (f b)) (hf₂ : ∀ b, v ≤[f b] w) : v ≤[⋃ b, f b] w := by
cases nonempty_encodable β
rw [← Encodable.iUnion_decode₂]
refine restrict_le_restrict_iUnion v w ?_ ?_
· intro n
measurability
· intro n
cases' Encodable.decode₂ β n with b
· simp
· simp [hf₂ b]
theorem restrict_le_restrict_union (hi₁ : MeasurableSet i) (hi₂ : v ≤[i] w) (hj₁ : MeasurableSet j)
(hj₂ : v ≤[j] w) : v ≤[i ∪ j] w := by
rw [Set.union_eq_iUnion]
refine restrict_le_restrict_countable_iUnion v w ?_ ?_
· measurability
· rintro (_ | _) <;> simpa
end
section
variable {M : Type*} [TopologicalSpace M] [OrderedAddCommMonoid M]
variable (v w : VectorMeasure α M) {i j : Set α}
theorem nonneg_of_zero_le_restrict (hi₂ : 0 ≤[i] v) : 0 ≤ v i := by
by_cases hi₁ : MeasurableSet i
· exact (restrict_le_restrict_iff _ _ hi₁).1 hi₂ hi₁ Set.Subset.rfl
· rw [v.not_measurable hi₁]
theorem nonpos_of_restrict_le_zero (hi₂ : v ≤[i] 0) : v i ≤ 0 := by
by_cases hi₁ : MeasurableSet i
· exact (restrict_le_restrict_iff _ _ hi₁).1 hi₂ hi₁ Set.Subset.rfl
· rw [v.not_measurable hi₁]
theorem zero_le_restrict_not_measurable (hi : ¬MeasurableSet i) : 0 ≤[i] v := by
rw [restrict_zero, restrict_not_measurable _ hi]
theorem restrict_le_zero_of_not_measurable (hi : ¬MeasurableSet i) : v ≤[i] 0 := by
rw [restrict_zero, restrict_not_measurable _ hi]
theorem measurable_of_not_zero_le_restrict (hi : ¬0 ≤[i] v) : MeasurableSet i :=
Not.imp_symm (zero_le_restrict_not_measurable _) hi
theorem measurable_of_not_restrict_le_zero (hi : ¬v ≤[i] 0) : MeasurableSet i :=
Not.imp_symm (restrict_le_zero_of_not_measurable _) hi
theorem zero_le_restrict_subset (hi₁ : MeasurableSet i) (hij : j ⊆ i) (hi₂ : 0 ≤[i] v) : 0 ≤[j] v :=
restrict_le_restrict_of_subset_le _ _ fun _ hk₁ hk₂ =>
(restrict_le_restrict_iff _ _ hi₁).1 hi₂ hk₁ (Set.Subset.trans hk₂ hij)
theorem restrict_le_zero_subset (hi₁ : MeasurableSet i) (hij : j ⊆ i) (hi₂ : v ≤[i] 0) : v ≤[j] 0 :=
restrict_le_restrict_of_subset_le _ _ fun _ hk₁ hk₂ =>
(restrict_le_restrict_iff _ _ hi₁).1 hi₂ hk₁ (Set.Subset.trans hk₂ hij)
end
section
variable {M : Type*} [TopologicalSpace M] [LinearOrderedAddCommMonoid M]
variable (v w : VectorMeasure α M) {i j : Set α}
theorem exists_pos_measure_of_not_restrict_le_zero (hi : ¬v ≤[i] 0) :
∃ j : Set α, MeasurableSet j ∧ j ⊆ i ∧ 0 < v j := by
have hi₁ : MeasurableSet i := measurable_of_not_restrict_le_zero _ hi
rw [restrict_le_restrict_iff _ _ hi₁] at hi
push_neg at hi
exact hi
end
section
variable {M : Type*} [TopologicalSpace M] [AddCommMonoid M] [PartialOrder M]
[CovariantClass M M (· + ·) (· ≤ ·)] [ContinuousAdd M]
instance covariant_add_le :
CovariantClass (VectorMeasure α M) (VectorMeasure α M) (· + ·) (· ≤ ·) :=
⟨fun _ _ _ h i hi => add_le_add_left (h i hi) _⟩
end
section
variable {L M N : Type*}
variable [AddCommMonoid L] [TopologicalSpace L] [AddCommMonoid M] [TopologicalSpace M]
[AddCommMonoid N] [TopologicalSpace N]
/-- A vector measure `v` is absolutely continuous with respect to a measure `μ` if for all sets
`s`, `μ s = 0`, we have `v s = 0`. -/
def AbsolutelyContinuous (v : VectorMeasure α M) (w : VectorMeasure α N) :=
∀ ⦃s : Set α⦄, w s = 0 → v s = 0
@[inherit_doc VectorMeasure.AbsolutelyContinuous]
scoped[MeasureTheory] infixl:50 " ≪ᵥ " => MeasureTheory.VectorMeasure.AbsolutelyContinuous
open MeasureTheory
namespace AbsolutelyContinuous
variable {v : VectorMeasure α M} {w : VectorMeasure α N}
theorem mk (h : ∀ ⦃s : Set α⦄, MeasurableSet s → w s = 0 → v s = 0) : v ≪ᵥ w := by
intro s hs
by_cases hmeas : MeasurableSet s
· exact h hmeas hs
· exact not_measurable v hmeas
theorem eq {w : VectorMeasure α M} (h : v = w) : v ≪ᵥ w :=
fun _ hs => h.symm ▸ hs
@[refl]
theorem refl (v : VectorMeasure α M) : v ≪ᵥ v :=
eq rfl
@[trans]
theorem trans {u : VectorMeasure α L} {v : VectorMeasure α M} {w : VectorMeasure α N} (huv : u ≪ᵥ v)
(hvw : v ≪ᵥ w) : u ≪ᵥ w :=
fun _ hs => huv <| hvw hs
theorem zero (v : VectorMeasure α N) : (0 : VectorMeasure α M) ≪ᵥ v :=
fun s _ => VectorMeasure.zero_apply s
theorem neg_left {M : Type*} [AddCommGroup M] [TopologicalSpace M] [TopologicalAddGroup M]
{v : VectorMeasure α M} {w : VectorMeasure α N} (h : v ≪ᵥ w) : -v ≪ᵥ w := by
intro s hs
rw [neg_apply, h hs, neg_zero]
theorem neg_right {N : Type*} [AddCommGroup N] [TopologicalSpace N] [TopologicalAddGroup N]
{v : VectorMeasure α M} {w : VectorMeasure α N} (h : v ≪ᵥ w) : v ≪ᵥ -w := by
intro s hs
rw [neg_apply, neg_eq_zero] at hs
exact h hs
theorem add [ContinuousAdd M] {v₁ v₂ : VectorMeasure α M} {w : VectorMeasure α N} (hv₁ : v₁ ≪ᵥ w)
(hv₂ : v₂ ≪ᵥ w) : v₁ + v₂ ≪ᵥ w := by
intro s hs
rw [add_apply, hv₁ hs, hv₂ hs, zero_add]
theorem sub {M : Type*} [AddCommGroup M] [TopologicalSpace M] [TopologicalAddGroup M]
{v₁ v₂ : VectorMeasure α M} {w : VectorMeasure α N} (hv₁ : v₁ ≪ᵥ w) (hv₂ : v₂ ≪ᵥ w) :
v₁ - v₂ ≪ᵥ w := by
intro s hs
rw [sub_apply, hv₁ hs, hv₂ hs, zero_sub, neg_zero]
theorem smul {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M] {r : R}
{v : VectorMeasure α M} {w : VectorMeasure α N} (h : v ≪ᵥ w) : r • v ≪ᵥ w := by
intro s hs
rw [smul_apply, h hs, smul_zero]
theorem map [MeasureSpace β] (h : v ≪ᵥ w) (f : α → β) : v.map f ≪ᵥ w.map f := by
by_cases hf : Measurable f
· refine mk fun s hs hws => ?_
rw [map_apply _ hf hs] at hws ⊢
exact h hws
· intro s _
rw [map_not_measurable v hf, zero_apply]
theorem ennrealToMeasure {μ : VectorMeasure α ℝ≥0∞} :
(∀ ⦃s : Set α⦄, μ.ennrealToMeasure s = 0 → v s = 0) ↔ v ≪ᵥ μ := by
constructor <;> intro h
· refine mk fun s hmeas hs => h ?_
rw [← hs, ennrealToMeasure_apply hmeas]
· intro s hs
by_cases hmeas : MeasurableSet s
· rw [ennrealToMeasure_apply hmeas] at hs
exact h hs
· exact not_measurable v hmeas
end AbsolutelyContinuous
/-- Two vector measures `v` and `w` are said to be mutually singular if there exists a measurable
set `s`, such that for all `t ⊆ s`, `v t = 0` and for all `t ⊆ sᶜ`, `w t = 0`.
We note that we do not require the measurability of `t` in the definition since this makes it easier
to use. This is equivalent to the definition which requires measurability. To prove
`MutuallySingular` with the measurability condition, use
`MeasureTheory.VectorMeasure.MutuallySingular.mk`. -/
def MutuallySingular (v : VectorMeasure α M) (w : VectorMeasure α N) : Prop :=
∃ s : Set α, MeasurableSet s ∧ (∀ t ⊆ s, v t = 0) ∧ ∀ t ⊆ sᶜ, w t = 0
@[inherit_doc VectorMeasure.MutuallySingular]
scoped[MeasureTheory] infixl:60 " ⟂ᵥ " => MeasureTheory.VectorMeasure.MutuallySingular
namespace MutuallySingular
variable {v v₁ v₂ : VectorMeasure α M} {w w₁ w₂ : VectorMeasure α N}
theorem mk (s : Set α) (hs : MeasurableSet s) (h₁ : ∀ t ⊆ s, MeasurableSet t → v t = 0)
(h₂ : ∀ t ⊆ sᶜ, MeasurableSet t → w t = 0) : v ⟂ᵥ w := by
refine ⟨s, hs, fun t hst => ?_, fun t hst => ?_⟩ <;> by_cases ht : MeasurableSet t
· exact h₁ t hst ht
· exact not_measurable v ht
· exact h₂ t hst ht
· exact not_measurable w ht
theorem symm (h : v ⟂ᵥ w) : w ⟂ᵥ v :=
let ⟨s, hmeas, hs₁, hs₂⟩ := h
⟨sᶜ, hmeas.compl, hs₂, fun t ht => hs₁ _ (compl_compl s ▸ ht : t ⊆ s)⟩
theorem zero_right : v ⟂ᵥ (0 : VectorMeasure α N) :=
⟨∅, MeasurableSet.empty, fun _ ht => (Set.subset_empty_iff.1 ht).symm ▸ v.empty,
fun _ _ => zero_apply _⟩
theorem zero_left : (0 : VectorMeasure α M) ⟂ᵥ w :=
zero_right.symm
theorem add_left [T2Space N] [ContinuousAdd M] (h₁ : v₁ ⟂ᵥ w) (h₂ : v₂ ⟂ᵥ w) : v₁ + v₂ ⟂ᵥ w := by
obtain ⟨u, hmu, hu₁, hu₂⟩ := h₁
obtain ⟨v, hmv, hv₁, hv₂⟩ := h₂
refine mk (u ∩ v) (hmu.inter hmv) (fun t ht _ => ?_) fun t ht hmt => ?_
· rw [add_apply, hu₁ _ (Set.subset_inter_iff.1 ht).1, hv₁ _ (Set.subset_inter_iff.1 ht).2,
zero_add]
· rw [Set.compl_inter] at ht
rw [(_ : t = uᶜ ∩ t ∪ vᶜ \ uᶜ ∩ t),
of_union _ (hmu.compl.inter hmt) ((hmv.compl.diff hmu.compl).inter hmt), hu₂, hv₂, add_zero]
· exact Set.Subset.trans Set.inter_subset_left diff_subset
· exact Set.inter_subset_left
· exact disjoint_sdiff_self_right.mono Set.inter_subset_left Set.inter_subset_left
· apply Set.Subset.antisymm <;> intro x hx
· by_cases hxu' : x ∈ uᶜ
· exact Or.inl ⟨hxu', hx⟩
rcases ht hx with (hxu | hxv)
exacts [False.elim (hxu' hxu), Or.inr ⟨⟨hxv, hxu'⟩, hx⟩]
· cases' hx with hx hx <;> exact hx.2
theorem add_right [T2Space M] [ContinuousAdd N] (h₁ : v ⟂ᵥ w₁) (h₂ : v ⟂ᵥ w₂) : v ⟂ᵥ w₁ + w₂ :=
(add_left h₁.symm h₂.symm).symm
theorem smul_right {R : Type*} [Semiring R] [DistribMulAction R N] [ContinuousConstSMul R N]
(r : R) (h : v ⟂ᵥ w) : v ⟂ᵥ r • w :=
let ⟨s, hmeas, hs₁, hs₂⟩ := h
⟨s, hmeas, hs₁, fun t ht => by simp only [coe_smul, Pi.smul_apply, hs₂ t ht, smul_zero]⟩
theorem smul_left {R : Type*} [Semiring R] [DistribMulAction R M] [ContinuousConstSMul R M] (r : R)
(h : v ⟂ᵥ w) : r • v ⟂ᵥ w :=
(smul_right r h.symm).symm
theorem neg_left {M : Type*} [AddCommGroup M] [TopologicalSpace M] [TopologicalAddGroup M]
{v : VectorMeasure α M} {w : VectorMeasure α N} (h : v ⟂ᵥ w) : -v ⟂ᵥ w := by
obtain ⟨u, hmu, hu₁, hu₂⟩ := h
refine ⟨u, hmu, fun s hs => ?_, hu₂⟩
rw [neg_apply v s, neg_eq_zero]
exact hu₁ s hs
theorem neg_right {N : Type*} [AddCommGroup N] [TopologicalSpace N] [TopologicalAddGroup N]
{v : VectorMeasure α M} {w : VectorMeasure α N} (h : v ⟂ᵥ w) : v ⟂ᵥ -w :=
h.symm.neg_left.symm
@[simp]
theorem neg_left_iff {M : Type*} [AddCommGroup M] [TopologicalSpace M] [TopologicalAddGroup M]
{v : VectorMeasure α M} {w : VectorMeasure α N} : -v ⟂ᵥ w ↔ v ⟂ᵥ w :=
⟨fun h => neg_neg v ▸ h.neg_left, neg_left⟩
@[simp]
theorem neg_right_iff {N : Type*} [AddCommGroup N] [TopologicalSpace N] [TopologicalAddGroup N]
{v : VectorMeasure α M} {w : VectorMeasure α N} : v ⟂ᵥ -w ↔ v ⟂ᵥ w :=
⟨fun h => neg_neg w ▸ h.neg_right, neg_right⟩
end MutuallySingular
section Trim
open Classical in
/-- Restriction of a vector measure onto a sub-σ-algebra. -/
@[simps]
def trim {m n : MeasurableSpace α} (v : VectorMeasure α M) (hle : m ≤ n) :
@VectorMeasure α m M _ _ :=
@VectorMeasure.mk α m M _ _
(fun i => if MeasurableSet[m] i then v i else 0)
(by dsimp only; rw [if_pos (@MeasurableSet.empty _ m), v.empty])
(fun i hi => by dsimp only; rw [if_neg hi])
(fun f hf₁ hf₂ => by
dsimp only
have hf₁' : ∀ k, MeasurableSet[n] (f k) := fun k => hle _ (hf₁ k)
convert v.m_iUnion hf₁' hf₂ using 1
· ext n
rw [if_pos (hf₁ n)]
· rw [if_pos (@MeasurableSet.iUnion _ _ m _ _ hf₁)])
variable {n : MeasurableSpace α} {v : VectorMeasure α M}
theorem trim_eq_self : v.trim le_rfl = v := by
ext i hi
exact if_pos hi
@[simp]
theorem zero_trim (hle : m ≤ n) : (0 : VectorMeasure α M).trim hle = 0 := by
ext i hi
exact if_pos hi
theorem trim_measurableSet_eq (hle : m ≤ n) {i : Set α} (hi : MeasurableSet[m] i) :
v.trim hle i = v i :=
if_pos hi
theorem restrict_trim (hle : m ≤ n) {i : Set α} (hi : MeasurableSet[m] i) :
@VectorMeasure.restrict α m M _ _ (v.trim hle) i = (v.restrict i).trim hle := by
ext j hj
rw [@restrict_apply _ m, trim_measurableSet_eq hle hj, restrict_apply, trim_measurableSet_eq]
all_goals measurability
end Trim
end
end VectorMeasure
namespace SignedMeasure
open VectorMeasure
open MeasureTheory
/-- The underlying function for `SignedMeasure.toMeasureOfZeroLE`. -/
def toMeasureOfZeroLE' (s : SignedMeasure α) (i : Set α) (hi : 0 ≤[i] s) (j : Set α)
(hj : MeasurableSet j) : ℝ≥0∞ :=
((↑) : ℝ≥0 → ℝ≥0∞) ⟨s.restrict i j, le_trans (by simp) (hi j hj)⟩
/-- Given a signed measure `s` and a positive measurable set `i`, `toMeasureOfZeroLE`
provides the measure, mapping measurable sets `j` to `s (i ∩ j)`. -/
def toMeasureOfZeroLE (s : SignedMeasure α) (i : Set α) (hi₁ : MeasurableSet i) (hi₂ : 0 ≤[i] s) :
Measure α := by
refine Measure.ofMeasurable (s.toMeasureOfZeroLE' i hi₂) ?_ ?_
· simp_rw [toMeasureOfZeroLE', s.restrict_apply hi₁ MeasurableSet.empty, Set.empty_inter i,
s.empty]
rfl
· intro f hf₁ hf₂
have h₁ : ∀ n, MeasurableSet (i ∩ f n) := fun n => hi₁.inter (hf₁ n)
have h₂ : Pairwise (Disjoint on fun n : ℕ => i ∩ f n) := by
intro n m hnm
exact ((hf₂ hnm).inf_left' i).inf_right' i
simp only [toMeasureOfZeroLE', s.restrict_apply hi₁ (MeasurableSet.iUnion hf₁), Set.inter_comm,
Set.inter_iUnion, s.of_disjoint_iUnion_nat h₁ h₂, ENNReal.some_eq_coe, id]
have h : ∀ n, 0 ≤ s (i ∩ f n) := fun n =>
s.nonneg_of_zero_le_restrict (s.zero_le_restrict_subset hi₁ Set.inter_subset_left hi₂)
rw [NNReal.coe_tsum_of_nonneg h, ENNReal.coe_tsum]
· refine tsum_congr fun n => ?_
simp_rw [s.restrict_apply hi₁ (hf₁ n), Set.inter_comm]
· exact (NNReal.summable_mk h).2 (s.m_iUnion h₁ h₂).summable
variable (s : SignedMeasure α) {i j : Set α}
theorem toMeasureOfZeroLE_apply (hi : 0 ≤[i] s) (hi₁ : MeasurableSet i) (hj₁ : MeasurableSet j) :
s.toMeasureOfZeroLE i hi₁ hi j = ((↑) : ℝ≥0 → ℝ≥0∞) ⟨s (i ∩ j), nonneg_of_zero_le_restrict
s (zero_le_restrict_subset s hi₁ Set.inter_subset_left hi)⟩ := by
simp_rw [toMeasureOfZeroLE, Measure.ofMeasurable_apply _ hj₁, toMeasureOfZeroLE',
s.restrict_apply hi₁ hj₁, Set.inter_comm]
/-- Given a signed measure `s` and a negative measurable set `i`, `toMeasureOfLEZero`
provides the measure, mapping measurable sets `j` to `-s (i ∩ j)`. -/
def toMeasureOfLEZero (s : SignedMeasure α) (i : Set α) (hi₁ : MeasurableSet i) (hi₂ : s ≤[i] 0) :
Measure α :=
toMeasureOfZeroLE (-s) i hi₁ <| @neg_zero (VectorMeasure α ℝ) _ ▸ neg_le_neg _ _ hi₁ hi₂
theorem toMeasureOfLEZero_apply (hi : s ≤[i] 0) (hi₁ : MeasurableSet i) (hj₁ : MeasurableSet j) :
s.toMeasureOfLEZero i hi₁ hi j = ((↑) : ℝ≥0 → ℝ≥0∞) ⟨-s (i ∩ j), neg_apply s (i ∩ j) ▸
nonneg_of_zero_le_restrict _ (zero_le_restrict_subset _ hi₁ Set.inter_subset_left
(@neg_zero (VectorMeasure α ℝ) _ ▸ neg_le_neg _ _ hi₁ hi))⟩ := by
erw [toMeasureOfZeroLE_apply]
· simp
· assumption
/-- `SignedMeasure.toMeasureOfZeroLE` is a finite measure. -/
instance toMeasureOfZeroLE_finite (hi : 0 ≤[i] s) (hi₁ : MeasurableSet i) :
IsFiniteMeasure (s.toMeasureOfZeroLE i hi₁ hi) where
measure_univ_lt_top := by
rw [toMeasureOfZeroLE_apply s hi hi₁ MeasurableSet.univ]
exact ENNReal.coe_lt_top
/-- `SignedMeasure.toMeasureOfLEZero` is a finite measure. -/
instance toMeasureOfLEZero_finite (hi : s ≤[i] 0) (hi₁ : MeasurableSet i) :
IsFiniteMeasure (s.toMeasureOfLEZero i hi₁ hi) where
measure_univ_lt_top := by
rw [toMeasureOfLEZero_apply s hi hi₁ MeasurableSet.univ]
exact ENNReal.coe_lt_top
theorem toMeasureOfZeroLE_toSignedMeasure (hs : 0 ≤[Set.univ] s) :
(s.toMeasureOfZeroLE Set.univ MeasurableSet.univ hs).toSignedMeasure = s := by
ext i hi
simp [hi, toMeasureOfZeroLE_apply _ _ _ hi]
theorem toMeasureOfLEZero_toSignedMeasure (hs : s ≤[Set.univ] 0) :
(s.toMeasureOfLEZero Set.univ MeasurableSet.univ hs).toSignedMeasure = -s := by
ext i hi
simp [hi, toMeasureOfLEZero_apply _ _ _ hi]
end SignedMeasure
namespace Measure
open VectorMeasure
variable (μ : Measure α) [IsFiniteMeasure μ]
theorem zero_le_toSignedMeasure : 0 ≤ μ.toSignedMeasure := by
rw [← le_restrict_univ_iff_le]
refine restrict_le_restrict_of_subset_le _ _ fun j hj₁ _ => ?_
simp only [Measure.toSignedMeasure_apply_measurable hj₁, coe_zero, Pi.zero_apply,
ENNReal.toReal_nonneg, VectorMeasure.coe_zero]
theorem toSignedMeasure_toMeasureOfZeroLE :
μ.toSignedMeasure.toMeasureOfZeroLE Set.univ MeasurableSet.univ
((le_restrict_univ_iff_le _ _).2 (zero_le_toSignedMeasure μ)) = μ := by
refine Measure.ext fun i hi => ?_
lift μ i to ℝ≥0 using (measure_lt_top _ _).ne with m hm
rw [SignedMeasure.toMeasureOfZeroLE_apply _ _ _ hi, ENNReal.coe_inj]
congr
simp [hi, ← hm]
end Measure
end MeasureTheory
|
MeasureTheory\Measure\WithDensity.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.MeasureTheory.Integral.Lebesgue
/-!
# Measure with a given density with respect to another measure
For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`.
On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`.
An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures
`μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to
`ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that
`μ = ν.withDensity f`.
See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`.
-/
open Set hiding restrict restrict_apply
open Filter ENNReal NNReal MeasureTheory.Measure
namespace MeasureTheory
variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α}
/-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the
measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/
noncomputable
def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α :=
Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun s hs hd =>
lintegral_iUnion hs hd _
@[simp]
theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) :
μ.withDensity f s = ∫⁻ a in s, f a ∂μ :=
Measure.ofMeasurable_apply s hs
theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) :
∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by
let t := toMeasurable (μ.withDensity f) s
calc
∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ :=
lintegral_mono_set (subset_toMeasurable (withDensity μ f) s)
_ = μ.withDensity f t :=
(withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm
_ = μ.withDensity f s := measure_toMeasurable s
/-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample
without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider
the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their
complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal
to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then
* `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then
`∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim.
* `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets
`t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then
`μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`.
One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not
containing `x₀`, and infinite mass to those that contain it. -/
theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) :
μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by
apply le_antisymm ?_ (withDensity_apply_le f s)
let t := toMeasurable μ s
calc
μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s)
_ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s)
_ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s
@[simp]
lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by
ext s hs
rw [withDensity_apply _ hs]
simp
theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) :
μ.withDensity f = μ.withDensity g := by
refine Measure.ext fun s hs => ?_
rw [withDensity_apply _ hs, withDensity_apply _ hs]
exact lintegral_congr_ae (ae_restrict_of_ae h)
lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) :
μ.withDensity f ≤ μ.withDensity g := by
refine le_iff.2 fun s hs ↦ ?_
rw [withDensity_apply _ hs, withDensity_apply _ hs]
refine setLIntegral_mono_ae' hs ?_
filter_upwards [hfg] with x h_le using fun _ ↦ h_le
theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) :
μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by
refine Measure.ext fun s hs => ?_
rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs,
← lintegral_add_left hf]
simp only [Pi.add_apply]
theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) :
μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by
simpa only [add_comm] using withDensity_add_left hg f
theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) :
(μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by
ext1 s hs
simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply]
theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) :
(sum μ).withDensity f = sum fun n => (μ n).withDensity f := by
ext1 s hs
simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure]
theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) :
μ.withDensity (r • f) = r • μ.withDensity f := by
refine Measure.ext fun s hs => ?_
rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs,
smul_eq_mul, ← lintegral_const_mul r hf]
simp only [Pi.smul_apply, smul_eq_mul]
theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) :
μ.withDensity (r • f) = r • μ.withDensity f := by
refine Measure.ext fun s hs => ?_
rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs,
smul_eq_mul, ← lintegral_const_mul' r f hr]
simp only [Pi.smul_apply, smul_eq_mul]
theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) :
(r • μ).withDensity f = r • μ.withDensity f := by
ext s hs
rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs,
smul_eq_mul, setLIntegral_smul_measure]
theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) :
IsFiniteMeasure (μ.withDensity f) :=
{ measure_univ_lt_top := by
rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] }
theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) :
μ.withDensity f ≪ μ := by
refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_
rw [withDensity_apply _ hs₁]
exact setLIntegral_measure_zero _ _ hs₂
@[simp]
theorem withDensity_zero : μ.withDensity 0 = 0 := by
ext1 s hs
simp [withDensity_apply _ hs]
@[simp]
theorem withDensity_one : μ.withDensity 1 = μ := by
ext1 s hs
simp [withDensity_apply _ hs]
@[simp]
theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by
ext1 s hs
simp [withDensity_apply _ hs]
theorem withDensity_tsum {ι : Type*} [Countable ι] {f : ι → α → ℝ≥0∞} (h : ∀ i, Measurable (f i)) :
μ.withDensity (∑' n, f n) = sum fun n => μ.withDensity (f n) := by
ext1 s hs
simp_rw [sum_apply _ hs, withDensity_apply _ hs]
change ∫⁻ x in s, (∑' n, f n) x ∂μ = ∑' i, ∫⁻ x, f i x ∂μ.restrict s
rw [← lintegral_tsum fun i => (h i).aemeasurable]
exact lintegral_congr fun x => tsum_apply (Pi.summable.2 fun _ => ENNReal.summable)
theorem withDensity_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) :
μ.withDensity (s.indicator f) = (μ.restrict s).withDensity f := by
ext1 t ht
rw [withDensity_apply _ ht, lintegral_indicator _ hs, restrict_comm hs, ←
withDensity_apply _ ht]
theorem withDensity_indicator_one {s : Set α} (hs : MeasurableSet s) :
μ.withDensity (s.indicator 1) = μ.restrict s := by
rw [withDensity_indicator hs, withDensity_one]
theorem withDensity_ofReal_mutuallySingular {f : α → ℝ} (hf : Measurable f) :
(μ.withDensity fun x => ENNReal.ofReal <| f x) ⟂ₘ
μ.withDensity fun x => ENNReal.ofReal <| -f x := by
set S : Set α := { x | f x < 0 }
have hS : MeasurableSet S := measurableSet_lt hf measurable_const
refine ⟨S, hS, ?_, ?_⟩
· rw [withDensity_apply _ hS, lintegral_eq_zero_iff hf.ennreal_ofReal, EventuallyEq]
exact (ae_restrict_mem hS).mono fun x hx => ENNReal.ofReal_eq_zero.2 (le_of_lt hx)
· rw [withDensity_apply _ hS.compl, lintegral_eq_zero_iff hf.neg.ennreal_ofReal, EventuallyEq]
exact
(ae_restrict_mem hS.compl).mono fun x hx =>
ENNReal.ofReal_eq_zero.2 (not_lt.1 <| mt neg_pos.1 hx)
theorem restrict_withDensity {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) :
(μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by
ext1 t ht
rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply _ (ht.inter hs),
restrict_restrict ht]
theorem restrict_withDensity' [SFinite μ] (s : Set α) (f : α → ℝ≥0∞) :
(μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by
ext1 t ht
rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply' _ (t ∩ s),
restrict_restrict ht]
lemma trim_withDensity {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : Measurable[m] f) :
(μ.withDensity f).trim hm = (μ.trim hm).withDensity f := by
refine @Measure.ext _ m _ _ (fun s hs ↦ ?_)
rw [withDensity_apply _ hs, restrict_trim _ _ hs, lintegral_trim _ hf, trim_measurableSet_eq _ hs,
withDensity_apply _ (hm s hs)]
lemma Measure.MutuallySingular.withDensity {ν : Measure α} {f : α → ℝ≥0∞} (h : μ ⟂ₘ ν) :
μ.withDensity f ⟂ₘ ν :=
MutuallySingular.mono_ac h (withDensity_absolutelyContinuous _ _) AbsolutelyContinuous.rfl
@[simp]
theorem withDensity_eq_zero_iff {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) :
μ.withDensity f = 0 ↔ f =ᵐ[μ] 0 := by
rw [← measure_univ_eq_zero, withDensity_apply _ .univ, restrict_univ, lintegral_eq_zero_iff' hf]
alias ⟨withDensity_eq_zero, _⟩ := withDensity_eq_zero_iff
theorem withDensity_apply_eq_zero' {f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f μ) :
μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := by
constructor
· intro hs
let t := toMeasurable (μ.withDensity f) s
apply measure_mono_null (inter_subset_inter_right _ (subset_toMeasurable (μ.withDensity f) s))
have A : μ.withDensity f t = 0 := by rw [measure_toMeasurable, hs]
rw [withDensity_apply f (measurableSet_toMeasurable _ s),
lintegral_eq_zero_iff' (AEMeasurable.restrict hf),
EventuallyEq, ae_restrict_iff'₀, ae_iff] at A
swap
· simp only [measurableSet_toMeasurable, MeasurableSet.nullMeasurableSet]
simp only [Pi.zero_apply, mem_setOf_eq, Filter.mem_mk] at A
convert A using 2
ext x
simp only [and_comm, exists_prop, mem_inter_iff, iff_self_iff, mem_setOf_eq,
mem_compl_iff, not_forall]
· intro hs
let t := toMeasurable μ ({ x | f x ≠ 0 } ∩ s)
have A : s ⊆ t ∪ { x | f x = 0 } := by
intro x hx
rcases eq_or_ne (f x) 0 with (fx | fx)
· simp only [fx, mem_union, mem_setOf_eq, eq_self_iff_true, or_true_iff]
· left
apply subset_toMeasurable _ _
exact ⟨fx, hx⟩
apply measure_mono_null A (measure_union_null _ _)
· apply withDensity_absolutelyContinuous
rwa [measure_toMeasurable]
rcases hf with ⟨g, hg, hfg⟩
have t : {x | f x = 0} =ᵐ[μ.withDensity f] {x | g x = 0} := by
apply withDensity_absolutelyContinuous
filter_upwards [hfg] with a ha
rw [eq_iff_iff]
exact ⟨fun h ↦ by rw [h] at ha; exact ha.symm,
fun h ↦ by rw [h] at ha; exact ha⟩
rw [measure_congr t, withDensity_congr_ae hfg]
have M : MeasurableSet { x : α | g x = 0 } := hg (measurableSet_singleton _)
rw [withDensity_apply _ M, lintegral_eq_zero_iff hg]
filter_upwards [ae_restrict_mem M]
simp only [imp_self, Pi.zero_apply, imp_true_iff]
theorem withDensity_apply_eq_zero {f : α → ℝ≥0∞} {s : Set α} (hf : Measurable f) :
μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 :=
withDensity_apply_eq_zero' <| hf.aemeasurable
theorem ae_withDensity_iff' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) :
(∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := by
rw [ae_iff, ae_iff, withDensity_apply_eq_zero' hf, iff_iff_eq]
congr
ext x
simp only [exists_prop, mem_inter_iff, iff_self_iff, mem_setOf_eq, not_forall]
theorem ae_withDensity_iff {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) :
(∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x :=
ae_withDensity_iff' <| hf.aemeasurable
theorem ae_withDensity_iff_ae_restrict' {p : α → Prop} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) :
(∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := by
rw [ae_withDensity_iff' hf, ae_restrict_iff'₀]
· simp only [mem_setOf]
· rcases hf with ⟨g, hg, hfg⟩
have nonneg_eq_ae : {x | g x ≠ 0} =ᵐ[μ] {x | f x ≠ 0} := by
filter_upwards [hfg] with a ha
simp only [eq_iff_iff]
exact ⟨fun (h : g a ≠ 0) ↦ by rwa [← ha] at h,
fun (h : f a ≠ 0) ↦ by rwa [ha] at h⟩
exact NullMeasurableSet.congr
(MeasurableSet.nullMeasurableSet
<| hg (measurableSet_singleton _)).compl
nonneg_eq_ae
theorem ae_withDensity_iff_ae_restrict {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) :
(∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x :=
ae_withDensity_iff_ae_restrict' <| hf.aemeasurable
theorem aemeasurable_withDensity_ennreal_iff' {f : α → ℝ≥0}
(hf : AEMeasurable f μ) {g : α → ℝ≥0∞} :
AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔
AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := by
have t : ∃ f', Measurable f' ∧ f =ᵐ[μ] f' := hf
rcases t with ⟨f', hf'_m, hf'_ae⟩
constructor
· rintro ⟨g', g'meas, hg'⟩
have A : MeasurableSet {x | f' x ≠ 0} := hf'_m (measurableSet_singleton _).compl
refine ⟨fun x => f' x * g' x, hf'_m.coe_nnreal_ennreal.smul g'meas, ?_⟩
apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 }
· rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] at hg'
rw [ae_restrict_iff' A]
filter_upwards [hg', hf'_ae] with a ha h'a h_a_nonneg
have : (f' a : ℝ≥0∞) ≠ 0 := by simpa only [Ne, ENNReal.coe_eq_zero] using h_a_nonneg
rw [← h'a] at this ⊢
rw [ha this]
· rw [ae_restrict_iff' A.compl]
filter_upwards [hf'_ae] with a ha ha_null
have ha_null : f' a = 0 := Function.nmem_support.mp ha_null
rw [ha_null] at ha ⊢
rw [ha]
simp only [ENNReal.coe_zero, zero_mul]
· rintro ⟨g', g'meas, hg'⟩
refine ⟨fun x => ((f' x)⁻¹ : ℝ≥0∞) * g' x, hf'_m.coe_nnreal_ennreal.inv.smul g'meas, ?_⟩
rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal]
filter_upwards [hg', hf'_ae] with a hfga hff'a h'a
rw [hff'a] at hfga h'a
rw [← hfga, ← mul_assoc, ENNReal.inv_mul_cancel h'a ENNReal.coe_ne_top, one_mul]
theorem aemeasurable_withDensity_ennreal_iff {f : α → ℝ≥0} (hf : Measurable f) {g : α → ℝ≥0∞} :
AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔
AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ :=
aemeasurable_withDensity_ennreal_iff' <| hf.aemeasurable
open MeasureTheory.SimpleFunc
/-- This is Exercise 1.2.1 from [tao2010]. It allows you to express integration of a measurable
function with respect to `(μ.withDensity f)` as an integral with respect to `μ`, called the base
measure. `μ` is often the Lebesgue measure, and in this circumstance `f` is the probability density
function, and `(μ.withDensity f)` represents any continuous random variable as a
probability measure, such as the uniform distribution between 0 and 1, the Gaussian distribution,
the exponential distribution, the Beta distribution, or the Cauchy distribution (see Section 2.4
of [wasserman2004]). Thus, this method shows how to one can calculate expectations, variances,
and other moments as a function of the probability density function.
-/
theorem lintegral_withDensity_eq_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞}
(h_mf : Measurable f) :
∀ {g : α → ℝ≥0∞}, Measurable g → ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by
apply Measurable.ennreal_induction
· intro c s h_ms
simp [*, mul_comm _ c, ← indicator_mul_right]
· intro g h _ h_mea_g _ h_ind_g h_ind_h
simp [mul_add, *, Measurable.mul]
· intro g h_mea_g h_mono_g h_ind
have : Monotone fun n a => f a * g n a := fun m n hmn x => mul_le_mul_left' (h_mono_g hmn x) _
simp [lintegral_iSup, ENNReal.mul_iSup, h_mf.mul (h_mea_g _), *]
theorem setLIntegral_withDensity_eq_setLIntegral_mul (μ : Measure α) {f g : α → ℝ≥0∞}
(hf : Measurable f) (hg : Measurable g) {s : Set α} (hs : MeasurableSet s) :
∫⁻ x in s, g x ∂μ.withDensity f = ∫⁻ x in s, (f * g) x ∂μ := by
rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul _ hf hg]
@[deprecated (since := "2024-06-29")]
alias set_lintegral_withDensity_eq_set_lintegral_mul := setLIntegral_withDensity_eq_setLIntegral_mul
/-- The Lebesgue integral of `g` with respect to the measure `μ.withDensity f` coincides with
the integral of `f * g`. This version assumes that `g` is almost everywhere measurable. For a
version without conditions on `g` but requiring that `f` is almost everywhere finite, see
`lintegral_withDensity_eq_lintegral_mul_non_measurable` -/
theorem lintegral_withDensity_eq_lintegral_mul₀' {μ : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.withDensity f)) :
∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by
let f' := hf.mk f
have : μ.withDensity f = μ.withDensity f' := withDensity_congr_ae hf.ae_eq_mk
rw [this] at hg ⊢
let g' := hg.mk g
calc
∫⁻ a, g a ∂μ.withDensity f' = ∫⁻ a, g' a ∂μ.withDensity f' := lintegral_congr_ae hg.ae_eq_mk
_ = ∫⁻ a, (f' * g') a ∂μ :=
(lintegral_withDensity_eq_lintegral_mul _ hf.measurable_mk hg.measurable_mk)
_ = ∫⁻ a, (f' * g) a ∂μ := by
apply lintegral_congr_ae
apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 }
· have Z := hg.ae_eq_mk
rw [EventuallyEq, ae_withDensity_iff_ae_restrict hf.measurable_mk] at Z
filter_upwards [Z]
intro x hx
simp only [hx, Pi.mul_apply]
· have M : MeasurableSet { x : α | f' x ≠ 0 }ᶜ :=
(hf.measurable_mk (measurableSet_singleton 0).compl).compl
filter_upwards [ae_restrict_mem M]
intro x hx
simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx
simp only [hx, zero_mul, Pi.mul_apply]
_ = ∫⁻ a : α, (f * g) a ∂μ := by
apply lintegral_congr_ae
filter_upwards [hf.ae_eq_mk]
intro x hx
simp only [hx, Pi.mul_apply]
lemma setLIntegral_withDensity_eq_lintegral_mul₀' {μ : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.withDensity f))
{s : Set α} (hs : MeasurableSet s) :
∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by
rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul₀' hf.restrict]
rw [← restrict_withDensity hs]
exact hg.restrict
@[deprecated (since := "2024-06-29")]
alias set_lintegral_withDensity_eq_lintegral_mul₀' := setLIntegral_withDensity_eq_lintegral_mul₀'
theorem lintegral_withDensity_eq_lintegral_mul₀ {μ : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) :
∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ :=
lintegral_withDensity_eq_lintegral_mul₀' hf (hg.mono' (withDensity_absolutelyContinuous μ f))
lemma setLIntegral_withDensity_eq_lintegral_mul₀ {μ : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ)
{s : Set α} (hs : MeasurableSet s) :
∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ :=
setLIntegral_withDensity_eq_lintegral_mul₀' hf
(hg.mono' (MeasureTheory.withDensity_absolutelyContinuous μ f)) hs
@[deprecated (since := "2024-06-29")]
alias set_lintegral_withDensity_eq_lintegral_mul₀ := setLIntegral_withDensity_eq_lintegral_mul₀
theorem lintegral_withDensity_le_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞}
(f_meas : Measurable f) (g : α → ℝ≥0∞) : (∫⁻ a, g a ∂μ.withDensity f) ≤ ∫⁻ a, (f * g) a ∂μ := by
rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral]
refine iSup₂_le fun i i_meas => iSup_le fun hi => ?_
have A : f * i ≤ f * g := fun x => mul_le_mul_left' (hi x) _
refine le_iSup₂_of_le (f * i) (f_meas.mul i_meas) ?_
exact le_iSup_of_le A (le_of_eq (lintegral_withDensity_eq_lintegral_mul _ f_meas i_meas))
theorem lintegral_withDensity_eq_lintegral_mul_non_measurable (μ : Measure α) {f : α → ℝ≥0∞}
(f_meas : Measurable f) (hf : ∀ᵐ x ∂μ, f x < ∞) (g : α → ℝ≥0∞) :
∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by
refine le_antisymm (lintegral_withDensity_le_lintegral_mul μ f_meas g) ?_
rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral]
refine iSup₂_le fun i i_meas => iSup_le fun hi => ?_
have A : (fun x => (f x)⁻¹ * i x) ≤ g := by
intro x
dsimp
rw [mul_comm, ← div_eq_mul_inv]
exact div_le_of_le_mul' (hi x)
refine le_iSup_of_le (fun x => (f x)⁻¹ * i x) (le_iSup_of_le (f_meas.inv.mul i_meas) ?_)
refine le_iSup_of_le A ?_
rw [lintegral_withDensity_eq_lintegral_mul _ f_meas (f_meas.inv.mul i_meas)]
apply lintegral_mono_ae
filter_upwards [hf]
intro x h'x
rcases eq_or_ne (f x) 0 with (hx | hx)
· have := hi x
simp only [hx, zero_mul, Pi.mul_apply, nonpos_iff_eq_zero] at this
simp [this]
· apply le_of_eq _
dsimp
rw [← mul_assoc, ENNReal.mul_inv_cancel hx h'x.ne, one_mul]
theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable (μ : Measure α) {f : α → ℝ≥0∞}
(f_meas : Measurable f) (g : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s)
(hf : ∀ᵐ x ∂μ.restrict s, f x < ∞) :
∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by
rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul_non_measurable _ f_meas hf]
@[deprecated (since := "2024-06-29")]
alias set_lintegral_withDensity_eq_set_lintegral_mul_non_measurable :=
setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable
theorem lintegral_withDensity_eq_lintegral_mul_non_measurable₀ (μ : Measure α) {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (h'f : ∀ᵐ x ∂μ, f x < ∞) (g : α → ℝ≥0∞) :
∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by
let f' := hf.mk f
calc
∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, g a ∂μ.withDensity f' := by
rw [withDensity_congr_ae hf.ae_eq_mk]
_ = ∫⁻ a, (f' * g) a ∂μ := by
apply lintegral_withDensity_eq_lintegral_mul_non_measurable _ hf.measurable_mk
filter_upwards [h'f, hf.ae_eq_mk]
intro x hx h'x
rwa [← h'x]
_ = ∫⁻ a, (f * g) a ∂μ := by
apply lintegral_congr_ae
filter_upwards [hf.ae_eq_mk]
intro x hx
simp only [hx, Pi.mul_apply]
theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀ (μ : Measure α)
{f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f (μ.restrict s)) (g : α → ℝ≥0∞)
(hs : MeasurableSet s) (h'f : ∀ᵐ x ∂μ.restrict s, f x < ∞) :
∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by
rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul_non_measurable₀ _ hf h'f]
@[deprecated (since := "2024-06-29")]
alias set_lintegral_withDensity_eq_set_lintegral_mul_non_measurable₀ :=
setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀
theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀' (μ : Measure α) [SFinite μ]
{f : α → ℝ≥0∞} (s : Set α) (hf : AEMeasurable f (μ.restrict s)) (g : α → ℝ≥0∞)
(h'f : ∀ᵐ x ∂μ.restrict s, f x < ∞) :
∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by
rw [restrict_withDensity' s, lintegral_withDensity_eq_lintegral_mul_non_measurable₀ _ hf h'f]
@[deprecated (since := "2024-06-29")]
alias set_lintegral_withDensity_eq_set_lintegral_mul_non_measurable₀' :=
setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀'
theorem withDensity_mul₀ {μ : Measure α} {f g : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
μ.withDensity (f * g) = (μ.withDensity f).withDensity g := by
ext1 s hs
rw [withDensity_apply _ hs, withDensity_apply _ hs, restrict_withDensity hs,
lintegral_withDensity_eq_lintegral_mul₀ hf.restrict hg.restrict]
theorem withDensity_mul (μ : Measure α) {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) :
μ.withDensity (f * g) = (μ.withDensity f).withDensity g :=
withDensity_mul₀ hf.aemeasurable hg.aemeasurable
lemma withDensity_inv_same_le {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) :
(μ.withDensity f).withDensity f⁻¹ ≤ μ := by
change (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) ≤ μ
rw [← withDensity_mul₀ hf hf.inv]
suffices (f * fun x ↦ (f x)⁻¹) ≤ᵐ[μ] 1 by
refine (withDensity_mono this).trans ?_
rw [withDensity_one]
filter_upwards with x
simp only [Pi.mul_apply, Pi.one_apply]
by_cases hx_top : f x = ∞
· simp only [hx_top, ENNReal.inv_top, mul_zero, zero_le]
by_cases hx_zero : f x = 0
· simp only [hx_zero, ENNReal.inv_zero, zero_mul, zero_le]
rw [ENNReal.mul_inv_cancel hx_zero hx_top]
lemma withDensity_inv_same₀ {μ : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
(μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) = μ := by
rw [← withDensity_mul₀ hf hf.inv]
suffices (f * fun x ↦ (f x)⁻¹) =ᵐ[μ] 1 by
rw [withDensity_congr_ae this, withDensity_one]
filter_upwards [hf_ne_zero, hf_ne_top] with x hf_ne_zero hf_ne_top
simp only [Pi.mul_apply]
rw [ENNReal.mul_inv_cancel hf_ne_zero hf_ne_top, Pi.one_apply]
lemma withDensity_inv_same {μ : Measure α} {f : α → ℝ≥0∞}
(hf : Measurable f) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
(μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) = μ :=
withDensity_inv_same₀ hf.aemeasurable hf_ne_zero hf_ne_top
/-- If `f` is almost everywhere positive, then `μ ≪ μ.withDensity f`. See also
`withDensity_absolutelyContinuous` for the reverse direction, which always holds. -/
lemma withDensity_absolutelyContinuous' {μ : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) :
μ ≪ μ.withDensity f := by
refine Measure.AbsolutelyContinuous.mk (fun s hs hμs ↦ ?_)
rw [withDensity_apply _ hs, lintegral_eq_zero_iff' hf.restrict,
ae_eq_restrict_iff_indicator_ae_eq hs, Set.indicator_zero', Filter.EventuallyEq, ae_iff] at hμs
simp only [ae_iff, ne_eq, not_not] at hf_ne_zero
simp only [Pi.zero_apply, Set.indicator_apply_eq_zero, not_forall, exists_prop] at hμs
have hle : s ⊆ {a | a ∈ s ∧ ¬f a = 0} ∪ {a | f a = 0} :=
fun x hx ↦ or_iff_not_imp_right.mpr <| fun hnx ↦ ⟨hx, hnx⟩
exact measure_mono_null hle <| nonpos_iff_eq_zero.1 <| le_trans (measure_union_le _ _)
<| hμs.symm ▸ zero_add _ |>.symm ▸ hf_ne_zero.le
theorem withDensity_ae_eq {β : Type} {f g : α → β} {d : α → ℝ≥0∞}
(hd : AEMeasurable d μ) (h_ae_nonneg : ∀ᵐ x ∂μ, d x ≠ 0) :
f =ᵐ[μ.withDensity d] g ↔ f =ᵐ[μ] g :=
Iff.intro
(fun h ↦ Measure.AbsolutelyContinuous.ae_eq
(withDensity_absolutelyContinuous' hd h_ae_nonneg) h)
(fun h ↦ Measure.AbsolutelyContinuous.ae_eq
(withDensity_absolutelyContinuous μ d) h)
/-- If `μ` is a σ-finite measure, then so is `μ.withDensity fun x ↦ f x`
for any `ℝ≥0`-valued function `f`. -/
protected instance SigmaFinite.withDensity [SigmaFinite μ] (f : α → ℝ≥0) :
SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
refine ⟨⟨⟨fun n ↦ spanningSets μ n ∩ f ⁻¹' (Iic n), fun _ ↦ trivial, fun n ↦ ?_, ?_⟩⟩⟩
· rw [withDensity_apply']
apply setLIntegral_lt_top_of_bddAbove
· exact ((measure_mono inter_subset_left).trans_lt (measure_spanningSets_lt_top μ n)).ne
· exact ⟨n, forall_mem_image.2 fun x hx ↦ hx.2⟩
· rw [iUnion_eq_univ_iff]
refine fun x ↦ ⟨max (spanningSetsIndex μ x) ⌈f x⌉₊, ?_, ?_⟩
· exact mem_spanningSets_of_index_le _ _ (le_max_left ..)
· simp [Nat.le_ceil]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
(hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) : SigmaFinite (μ.withDensity f) := by
have : f =ᵐ[μ] fun x ↦ (f x).toNNReal := hf_ne_top.mono fun x hx ↦ (ENNReal.coe_toNNReal hx).symm
rw [withDensity_congr_ae this]
infer_instance
lemma SigmaFinite.withDensity_of_ne_top' [SigmaFinite μ] {f : α → ℝ≥0∞} (hf_ne_top : ∀ x, f x ≠ ∞) :
SigmaFinite (μ.withDensity f) :=
SigmaFinite.withDensity_of_ne_top <| ae_of_all _ hf_ne_top
instance SigmaFinite.withDensity_ofReal [SigmaFinite μ] (f : α → ℝ) :
SigmaFinite (μ.withDensity (fun x ↦ ENNReal.ofReal (f x))) :=
.withDensity _
section SFinite
variable (μ) in
theorem exists_measurable_le_withDensity_eq [SFinite μ] (f : α → ℝ≥0∞) :
∃ g, Measurable g ∧ g ≤ f ∧ μ.withDensity g = μ.withDensity f := by
obtain ⟨g, hgm, hgf, hint⟩ := exists_measurable_le_forall_setLIntegral_eq μ f
use g, hgm, hgf
ext s hs
simp only [hint, withDensity_apply _ hs]
/-- If `μ` is an `s`-finite measure, then so is `μ.withDensity f`. -/
instance Measure.withDensity.instSFinite [SFinite μ] {f : α → ℝ≥0∞} :
SFinite (μ.withDensity f) := by
wlog hfm : Measurable f generalizing f
· rcases exists_measurable_le_withDensity_eq μ f with ⟨g, hgm, -, h⟩
exact h ▸ this hgm
wlog hμ : IsFiniteMeasure μ generalizing μ
· rw [← sum_sFiniteSeq μ, withDensity_sum]
have (n : ℕ) : SFinite ((sFiniteSeq μ n).withDensity f) := this inferInstance
infer_instance
set s := {x | f x = ∞}
have hs : MeasurableSet s := hfm (measurableSet_singleton _)
have key := calc
μ.withDensity f = μ.withDensity (sᶜ.indicator f) + μ.withDensity (s.indicator f) := by
simp (disch := measurability) [withDensity_indicator, ← restrict_withDensity]
_ = μ.withDensity (sᶜ.indicator f) + .sum fun _ : ℕ ↦ μ.withDensity (s.indicator 1) := by
rw [← withDensity_tsum (by measurability)]
congr 2 with x
rw [ENNReal.tsum_apply]
if hx : x ∈ s then simpa [hx, ENNReal.tsum_const_eq_top_of_ne_zero]
else simp [hx]
have : SigmaFinite (μ.withDensity (sᶜ.indicator f)) := by
refine SigmaFinite.withDensity_of_ne_top <| ae_of_all _ fun x hx ↦ ?_
simp [indicator_apply, ite_eq_iff, s] at hx
have : SigmaFinite (μ.withDensity (s.indicator 1)) := by
rw [withDensity_indicator hs]
exact SigmaFinite.withDensity 1
rw [key]
infer_instance
@[deprecated Measure.withDensity.instSFinite (since := "2024-07-14"), nolint unusedArguments]
lemma sFinite_withDensity_of_sigmaFinite_of_measurable (μ : Measure α) [SigmaFinite μ]
{f : α → ℝ≥0∞} (_hf : Measurable f) :
SFinite (μ.withDensity f) :=
inferInstance
@[deprecated Measure.withDensity.instSFinite (since := "2024-07-14"), nolint unusedArguments]
lemma sFinite_withDensity_of_measurable (μ : Measure α) [SFinite μ]
{f : α → ℝ≥0∞} (_hf : Measurable f) :
SFinite (μ.withDensity f) :=
inferInstance
end SFinite
variable [TopologicalSpace α] [OpensMeasurableSpace α] [IsLocallyFiniteMeasure μ]
lemma IsLocallyFiniteMeasure.withDensity_coe {f : α → ℝ≥0} (hf : Continuous f) :
IsLocallyFiniteMeasure (μ.withDensity fun x ↦ f x) := by
refine ⟨fun x ↦ ?_⟩
rcases (μ.finiteAt_nhds x).exists_mem_basis ((nhds_basis_opens' x).restrict_subset
(eventually_le_of_tendsto_lt (lt_add_one _) (hf.tendsto x))) with ⟨U, ⟨⟨hUx, hUo⟩, hUf⟩, hμU⟩
refine ⟨U, hUx, ?_⟩
rw [withDensity_apply _ hUo.measurableSet]
exact setLIntegral_lt_top_of_bddAbove hμU.ne ⟨f x + 1, forall_mem_image.2 hUf⟩
lemma IsLocallyFiniteMeasure.withDensity_ofReal {f : α → ℝ} (hf : Continuous f) :
IsLocallyFiniteMeasure (μ.withDensity fun x ↦ .ofReal (f x)) :=
.withDensity_coe <| continuous_real_toNNReal.comp hf
end MeasureTheory
|
MeasureTheory\Measure\WithDensityFinite.lean | /-
Copyright (c) 2024 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Decomposition.RadonNikodym
import Mathlib.Probability.ConditionalProbability
/-!
# s-finite measures can be written as `withDensity` of a finite measure
If `μ` is an s-finite measure, then there exists a finite measure `μ.toFinite` and a measurable
function `densityToFinite μ` such that `μ = μ.toFinite.withDensity μ.densityToFinite`. If `μ` is
zero this is the zero measure, and otherwise we can choose a probability measure for `μ.toFinite`.
That measure is not unique, and in particular our implementation leads to `μ.toFinite ≠ μ` even if
`μ` is a probability measure.
We use this construction to define a set `μ.sigmaFiniteSet`, such that `μ.restrict μ.sigmaFiniteSet`
is sigma-finite, and for all measurable sets `s ⊆ μ.sigmaFiniteSetᶜ`, either `μ s = 0`
or `μ s = ∞`.
## Main definitions
In these definitions and the results below, `μ` is an s-finite measure (`SFinite μ`).
* `MeasureTheory.Measure.toFinite`: a finite measure with `μ ≪ μ.toFinite` and `μ.toFinite ≪ μ`.
If `μ ≠ 0`, this is a probability measure.
* `MeasureTheory.Measure.densityToFinite`: a measurable function such that
`μ = μ.toFinite.withDensity μ.densityToFinite`.
* `MeasureTheory.Measure.sigmaFiniteSet`: a measurable set such that `μ.restrict μ.sigmaFiniteSet`
is sigma-finite, and for all sets `s ⊆ μ.sigmaFiniteSetᶜ`, either `μ s = 0` or `μ s = ∞`.
## Main statements
* `absolutelyContinuous_toFinite`: `μ ≪ μ.toFinite`.
* `toFinite_absolutelyContinuous`: `μ.toFinite ≪ μ`.
* `withDensity_densitytoFinite`: `μ.toFinite.withDensity μ.densityToFinite = μ`.
* An instance showing that `μ.restrict μ.sigmaFiniteSet` is sigma-finite.
* `restrict_compl_sigmaFiniteSet_eq_zero_or_top`: the measure `μ.restrict μ.sigmaFiniteSetᶜ` takes
only two values: 0 and ∞ .
* `measure_compl_sigmaFiniteSet_eq_zero_iff_sigmaFinite`: an s-finite measure `μ` is sigma-finite
iff `μ μ.sigmaFiniteSetᶜ = 0`.
-/
open scoped ENNReal
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α}
/-- Auxiliary definition for `MeasureTheory.Measure.toFinite`. -/
noncomputable def Measure.toFiniteAux (μ : Measure α) [SFinite μ] : Measure α :=
Measure.sum (fun n ↦ (2 ^ (n + 1) * sFiniteSeq μ n Set.univ)⁻¹ • sFiniteSeq μ n)
/-- A finite measure obtained from an s-finite measure `μ`, such that
`μ = μ.toFinite.withDensity μ.densityToFinite` (see `withDensity_densitytoFinite`).
If `μ` is non-zero, this is a probability measure. -/
noncomputable def Measure.toFinite (μ : Measure α) [SFinite μ] : Measure α :=
ProbabilityTheory.cond μ.toFiniteAux Set.univ
lemma toFiniteAux_apply (μ : Measure α) [SFinite μ] (s : Set α) :
μ.toFiniteAux s = ∑' n, (2 ^ (n + 1) * sFiniteSeq μ n Set.univ)⁻¹ * sFiniteSeq μ n s := by
rw [Measure.toFiniteAux, Measure.sum_apply_of_countable]; rfl
lemma toFinite_apply (μ : Measure α) [SFinite μ] (s : Set α) :
μ.toFinite s = (μ.toFiniteAux Set.univ)⁻¹ * μ.toFiniteAux s := by
rw [Measure.toFinite, ProbabilityTheory.cond_apply _ MeasurableSet.univ, Set.univ_inter]
lemma toFiniteAux_zero : Measure.toFiniteAux (0 : Measure α) = 0 := by
ext s
simp [toFiniteAux_apply]
@[simp]
lemma toFinite_zero : Measure.toFinite (0 : Measure α) = 0 := by
simp [Measure.toFinite, toFiniteAux_zero]
lemma toFiniteAux_eq_zero_iff [SFinite μ] : μ.toFiniteAux = 0 ↔ μ = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ by simp [h, toFiniteAux_zero]⟩
ext s hs
rw [Measure.ext_iff] at h
specialize h s hs
simp only [toFiniteAux_apply, Measure.coe_zero, Pi.zero_apply,
ENNReal.tsum_eq_zero, mul_eq_zero, ENNReal.inv_eq_zero] at h
rw [← sum_sFiniteSeq μ, Measure.sum_apply _ hs]
simp only [Measure.coe_zero, Pi.zero_apply, ENNReal.tsum_eq_zero]
intro n
specialize h n
simpa [ENNReal.mul_eq_top, measure_ne_top] using h
lemma toFiniteAux_univ_le_one (μ : Measure α) [SFinite μ] : μ.toFiniteAux Set.univ ≤ 1 := by
rw [toFiniteAux_apply]
have h_le_pow : ∀ n, (2 ^ (n + 1) * sFiniteSeq μ n Set.univ)⁻¹ * sFiniteSeq μ n Set.univ
≤ (2 ^ (n + 1))⁻¹ := by
intro n
by_cases h_zero : sFiniteSeq μ n = 0
· simp [h_zero]
· rw [ENNReal.le_inv_iff_mul_le, mul_assoc, mul_comm (sFiniteSeq μ n Set.univ),
ENNReal.inv_mul_cancel]
· simp [h_zero]
· exact ENNReal.mul_ne_top (by simp) (measure_ne_top _ _)
refine (tsum_le_tsum h_le_pow ENNReal.summable ENNReal.summable).trans ?_
simp [ENNReal.inv_pow, ENNReal.tsum_geometric_add_one, ENNReal.inv_mul_cancel]
instance [SFinite μ] : IsFiniteMeasure μ.toFiniteAux :=
⟨(toFiniteAux_univ_le_one μ).trans_lt ENNReal.one_lt_top⟩
@[simp]
lemma toFinite_eq_zero_iff [SFinite μ] : μ.toFinite = 0 ↔ μ = 0 := by
simp [Measure.toFinite, measure_ne_top μ.toFiniteAux Set.univ, toFiniteAux_eq_zero_iff]
instance [SFinite μ] : IsFiniteMeasure μ.toFinite := by
rw [Measure.toFinite]
infer_instance
instance [SFinite μ] [h_zero : NeZero μ] : IsProbabilityMeasure μ.toFinite := by
refine ProbabilityTheory.cond_isProbabilityMeasure μ.toFiniteAux ?_
simp [toFiniteAux_eq_zero_iff, h_zero.out]
lemma sFiniteSeq_absolutelyContinuous_toFiniteAux (μ : Measure α) [SFinite μ] (n : ℕ) :
sFiniteSeq μ n ≪ μ.toFiniteAux := by
refine Measure.absolutelyContinuous_sum_right n (Measure.absolutelyContinuous_smul ?_)
simp only [ne_eq, ENNReal.inv_eq_zero]
exact ENNReal.mul_ne_top (by simp) (measure_ne_top _ _)
lemma toFiniteAux_absolutelyContinuous_toFinite (μ : Measure α) [SFinite μ] :
μ.toFiniteAux ≪ μ.toFinite := ProbabilityTheory.absolutelyContinuous_cond_univ
lemma sFiniteSeq_absolutelyContinuous_toFinite (μ : Measure α) [SFinite μ] (n : ℕ) :
sFiniteSeq μ n ≪ μ.toFinite :=
(sFiniteSeq_absolutelyContinuous_toFiniteAux μ n).trans
(toFiniteAux_absolutelyContinuous_toFinite μ)
lemma absolutelyContinuous_toFinite (μ : Measure α) [SFinite μ] : μ ≪ μ.toFinite := by
conv_lhs => rw [← sum_sFiniteSeq μ]
exact Measure.absolutelyContinuous_sum_left (sFiniteSeq_absolutelyContinuous_toFinite μ)
lemma toFinite_absolutelyContinuous (μ : Measure α) [SFinite μ] : μ.toFinite ≪ μ := by
conv_rhs => rw [← sum_sFiniteSeq μ]
refine Measure.AbsolutelyContinuous.mk (fun s hs hs0 ↦ ?_)
simp only [Measure.sum_apply _ hs, ENNReal.tsum_eq_zero] at hs0
simp [toFinite_apply, toFiniteAux_apply, hs0]
/-- A measurable function such that `μ.toFinite.withDensity μ.densityToFinite = μ`.
See `withDensity_densitytoFinite`. -/
noncomputable
def Measure.densityToFinite (μ : Measure α) [SFinite μ] (a : α) : ℝ≥0∞ :=
∑' n, (sFiniteSeq μ n).rnDeriv μ.toFinite a
lemma densityToFinite_def (μ : Measure α) [SFinite μ] :
μ.densityToFinite = fun a ↦ ∑' n, (sFiniteSeq μ n).rnDeriv μ.toFinite a := rfl
lemma measurable_densityToFinite (μ : Measure α) [SFinite μ] : Measurable μ.densityToFinite :=
Measurable.ennreal_tsum fun _ ↦ Measure.measurable_rnDeriv _ _
theorem withDensity_densitytoFinite (μ : Measure α) [SFinite μ] :
μ.toFinite.withDensity μ.densityToFinite = μ := by
have : (μ.toFinite.withDensity fun a ↦ ∑' n, (sFiniteSeq μ n).rnDeriv μ.toFinite a)
= μ.toFinite.withDensity (∑' n, (sFiniteSeq μ n).rnDeriv μ.toFinite) := by
congr with a
rw [ENNReal.tsum_apply]
rw [densityToFinite_def, this, withDensity_tsum (fun i ↦ Measure.measurable_rnDeriv _ _)]
conv_rhs => rw [← sum_sFiniteSeq μ]
congr with n
rw [Measure.withDensity_rnDeriv_eq]
exact sFiniteSeq_absolutelyContinuous_toFinite μ n
lemma densityToFinite_ae_lt_top (μ : Measure α) [SigmaFinite μ] :
∀ᵐ x ∂μ, μ.densityToFinite x < ∞ := by
refine ae_of_forall_measure_lt_top_ae_restrict _ (fun s _ hμs ↦ ?_)
suffices ∀ᵐ x ∂μ.toFinite.restrict s, μ.densityToFinite x < ∞ from
(absolutelyContinuous_toFinite μ).restrict _ this
refine ae_lt_top (measurable_densityToFinite μ) ?_
rw [← withDensity_apply', withDensity_densitytoFinite]
exact hμs.ne
lemma densityToFinite_ae_ne_top (μ : Measure α) [SigmaFinite μ] :
∀ᵐ x ∂μ, μ.densityToFinite x ≠ ∞ :=
(densityToFinite_ae_lt_top μ).mono (fun _ hx ↦ hx.ne)
section SigmaFiniteSet
variable {s t : Set α}
/-- A measurable set such that `μ.restrict μ.sigmaFiniteSet` is sigma-finite,
and for all measurable sets `s ⊆ μ.sigmaFiniteSetᶜ`, either `μ s = 0` or `μ s = ∞`. -/
def Measure.sigmaFiniteSet (μ : Measure α) [SFinite μ] : Set α := {x | μ.densityToFinite x ≠ ∞}
lemma measurableSet_sigmaFiniteSet (μ : Measure α) [SFinite μ] :
MeasurableSet μ.sigmaFiniteSet :=
(measurable_densityToFinite μ (measurableSet_singleton ∞)).compl
lemma restrict_compl_sigmaFiniteSet [SFinite μ] :
μ.restrict μ.sigmaFiniteSetᶜ = ∞ • μ.toFinite.restrict μ.sigmaFiniteSetᶜ := by
ext t ht
have : μ.restrict μ.sigmaFiniteSetᶜ
= (μ.toFinite.withDensity μ.densityToFinite).restrict μ.sigmaFiniteSetᶜ := by
rw [withDensity_densitytoFinite μ]
simp only [Measure.coe_smul, Pi.smul_apply, smul_eq_mul]
rw [this, Measure.restrict_apply ht,
withDensity_apply _ (ht.inter (measurableSet_sigmaFiniteSet μ).compl),
Measure.restrict_apply ht]
calc ∫⁻ a in t ∩ μ.sigmaFiniteSetᶜ, μ.densityToFinite a ∂μ.toFinite
_ = ∫⁻ _ in t ∩ μ.sigmaFiniteSetᶜ, ∞ ∂μ.toFinite := by
refine setLIntegral_congr_fun (ht.inter (measurableSet_sigmaFiniteSet μ).compl)
(ae_of_all _ (fun x hx ↦ ?_))
simpa [Measure.sigmaFiniteSet] using ((Set.inter_subset_right) hx)
_ = ∞ * μ.toFinite (t ∩ μ.sigmaFiniteSetᶜ) := by simp
/-- The measure `μ.restrict μ.sigmaFiniteSetᶜ` takes only two values: 0 and ∞ . -/
lemma restrict_compl_sigmaFiniteSet_eq_zero_or_top (μ : Measure α) [SFinite μ] (s : Set α) :
μ.restrict μ.sigmaFiniteSetᶜ s = 0 ∨ μ.restrict μ.sigmaFiniteSetᶜ s = ∞ := by
rw [restrict_compl_sigmaFiniteSet]
simp only [Measure.coe_smul, Pi.smul_apply, smul_eq_mul, mul_eq_zero, ENNReal.top_ne_zero,
false_or]
rw [Measure.restrict_apply' (measurableSet_sigmaFiniteSet μ).compl]
by_cases h_zero : μ.toFinite (s ∩ μ.sigmaFiniteSetᶜ) = 0
· exact Or.inl h_zero
· exact Or.inr (ENNReal.top_mul h_zero)
lemma measure_eq_zero_or_top_of_subset_compl_sigmaFiniteSet [SFinite μ]
(ht_subset : t ⊆ μ.sigmaFiniteSetᶜ) :
μ t = 0 ∨ μ t = ∞ := by
have : μ t = μ.restrict μ.sigmaFiniteSetᶜ t := by
rw [Measure.restrict_apply' (measurableSet_sigmaFiniteSet μ).compl,
Set.inter_eq_left.mpr ht_subset]
rw [this]
exact restrict_compl_sigmaFiniteSet_eq_zero_or_top μ t
lemma toFinite_withDensity_restrict_sigmaFiniteSet (μ : Measure α) [SFinite μ] :
(μ.toFinite.withDensity
(fun x ↦ if μ.densityToFinite x ≠ ∞ then μ.densityToFinite x else 1)).restrict
μ.sigmaFiniteSet
= μ.restrict μ.sigmaFiniteSet := by
have : μ.restrict μ.sigmaFiniteSet
= (μ.toFinite.withDensity μ.densityToFinite).restrict μ.sigmaFiniteSet := by
rw [withDensity_densitytoFinite μ]
rw [this]
ext s hs
rw [Measure.restrict_apply hs, Measure.restrict_apply hs,
withDensity_apply _ (hs.inter (measurableSet_sigmaFiniteSet μ)),
withDensity_apply _ (hs.inter (measurableSet_sigmaFiniteSet μ))]
refine setLIntegral_congr_fun (hs.inter (measurableSet_sigmaFiniteSet μ))
(ae_of_all _ (fun x hx ↦ Eq.symm ?_))
simp only [Measure.sigmaFiniteSet, Set.mem_inter_iff, Set.mem_compl_iff, Set.mem_setOf_eq,
ne_eq] at hx
rw [if_pos hx.2]
/-- The restriction of an s-finite measure `μ` to `μ.sigmaFiniteSet` is sigma-finite. -/
instance (μ : Measure α) [SFinite μ] : SigmaFinite (μ.restrict μ.sigmaFiniteSet) := by
rw [← toFinite_withDensity_restrict_sigmaFiniteSet]
have : SigmaFinite (μ.toFinite.withDensity
(fun x ↦ if μ.densityToFinite x ≠ ∞ then μ.densityToFinite x else 1)) := by
refine SigmaFinite.withDensity_of_ne_top ?_
· refine ae_of_all _ (fun x ↦ ?_)
split_ifs with h <;> simp [h]
exact Restrict.sigmaFinite _ _
lemma sigmaFinite_of_measure_compl_sigmaFiniteSet_eq_zero [SFinite μ]
(h : μ μ.sigmaFiniteSetᶜ = 0) :
SigmaFinite μ := by
rw [← Measure.restrict_add_restrict_compl (μ := μ) (measurableSet_sigmaFiniteSet μ),
Measure.restrict_eq_zero.mpr h, add_zero]
infer_instance
@[simp]
lemma measure_compl_sigmaFiniteSet (μ : Measure α) [SigmaFinite μ] : μ μ.sigmaFiniteSetᶜ = 0 :=
densityToFinite_ae_ne_top μ
/-- An s-finite measure `μ` is sigma-finite iff `μ μ.sigmaFiniteSetᶜ = 0`. -/
lemma measure_compl_sigmaFiniteSet_eq_zero_iff_sigmaFinite (μ : Measure α) [SFinite μ] :
μ μ.sigmaFiniteSetᶜ = 0 ↔ SigmaFinite μ :=
⟨sigmaFinite_of_measure_compl_sigmaFiniteSet_eq_zero, fun _ ↦ measure_compl_sigmaFiniteSet μ⟩
end SigmaFiniteSet
end MeasureTheory
|
MeasureTheory\Measure\WithDensityVectorMeasure.lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.VectorMeasure
import Mathlib.MeasureTheory.Function.AEEqOfIntegral
/-!
# Vector measure defined by an integral
Given a measure `μ` and an integrable function `f : α → E`, we can define a vector measure `v` such
that for all measurable set `s`, `v i = ∫ x in s, f x ∂μ`. This definition is useful for
the Radon-Nikodym theorem for signed measures.
## Main definitions
* `MeasureTheory.Measure.withDensityᵥ`: the vector measure formed by integrating a function `f`
with respect to a measure `μ` on some set if `f` is integrable, and `0` otherwise.
-/
noncomputable section
open scoped MeasureTheory NNReal ENNReal
variable {α β : Type*} {m : MeasurableSpace α}
namespace MeasureTheory
open TopologicalSpace
variable {μ ν : Measure α}
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
open Classical in
/-- Given a measure `μ` and an integrable function `f`, `μ.withDensityᵥ f` is
the vector measure which maps the set `s` to `∫ₛ f ∂μ`. -/
def Measure.withDensityᵥ {m : MeasurableSpace α} (μ : Measure α) (f : α → E) : VectorMeasure α E :=
if hf : Integrable f μ then
{ measureOf' := fun s => if MeasurableSet s then ∫ x in s, f x ∂μ else 0
empty' := by simp
not_measurable' := fun s hs => if_neg hs
m_iUnion' := fun s hs₁ hs₂ => by
dsimp only
convert hasSum_integral_iUnion hs₁ hs₂ hf.integrableOn with n
· rw [if_pos (hs₁ n)]
· rw [if_pos (MeasurableSet.iUnion hs₁)] }
else 0
open Measure
variable {f g : α → E}
theorem withDensityᵥ_apply (hf : Integrable f μ) {s : Set α} (hs : MeasurableSet s) :
μ.withDensityᵥ f s = ∫ x in s, f x ∂μ := by rw [withDensityᵥ, dif_pos hf]; exact dif_pos hs
@[simp]
theorem withDensityᵥ_zero : μ.withDensityᵥ (0 : α → E) = 0 := by
ext1 s hs; erw [withDensityᵥ_apply (integrable_zero α E μ) hs]; simp
@[simp]
theorem withDensityᵥ_neg : μ.withDensityᵥ (-f) = -μ.withDensityᵥ f := by
by_cases hf : Integrable f μ
· ext1 i hi
rw [VectorMeasure.neg_apply, withDensityᵥ_apply hf hi, ← integral_neg,
withDensityᵥ_apply hf.neg hi]
rfl
· rw [withDensityᵥ, withDensityᵥ, dif_neg hf, dif_neg, neg_zero]
rwa [integrable_neg_iff]
theorem withDensityᵥ_neg' : (μ.withDensityᵥ fun x => -f x) = -μ.withDensityᵥ f :=
withDensityᵥ_neg
@[simp]
theorem withDensityᵥ_add (hf : Integrable f μ) (hg : Integrable g μ) :
μ.withDensityᵥ (f + g) = μ.withDensityᵥ f + μ.withDensityᵥ g := by
ext1 i hi
rw [withDensityᵥ_apply (hf.add hg) hi, VectorMeasure.add_apply, withDensityᵥ_apply hf hi,
withDensityᵥ_apply hg hi]
simp_rw [Pi.add_apply]
rw [integral_add] <;> rw [← integrableOn_univ]
· exact hf.integrableOn.restrict MeasurableSet.univ
· exact hg.integrableOn.restrict MeasurableSet.univ
theorem withDensityᵥ_add' (hf : Integrable f μ) (hg : Integrable g μ) :
(μ.withDensityᵥ fun x => f x + g x) = μ.withDensityᵥ f + μ.withDensityᵥ g :=
withDensityᵥ_add hf hg
@[simp]
theorem withDensityᵥ_sub (hf : Integrable f μ) (hg : Integrable g μ) :
μ.withDensityᵥ (f - g) = μ.withDensityᵥ f - μ.withDensityᵥ g := by
rw [sub_eq_add_neg, sub_eq_add_neg, withDensityᵥ_add hf hg.neg, withDensityᵥ_neg]
theorem withDensityᵥ_sub' (hf : Integrable f μ) (hg : Integrable g μ) :
(μ.withDensityᵥ fun x => f x - g x) = μ.withDensityᵥ f - μ.withDensityᵥ g :=
withDensityᵥ_sub hf hg
@[simp]
theorem withDensityᵥ_smul {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E]
[SMulCommClass ℝ 𝕜 E] (f : α → E) (r : 𝕜) : μ.withDensityᵥ (r • f) = r • μ.withDensityᵥ f := by
by_cases hf : Integrable f μ
· ext1 i hi
rw [withDensityᵥ_apply (hf.smul r) hi, VectorMeasure.smul_apply, withDensityᵥ_apply hf hi, ←
integral_smul r f]
rfl
· by_cases hr : r = 0
· rw [hr, zero_smul, zero_smul, withDensityᵥ_zero]
· rw [withDensityᵥ, withDensityᵥ, dif_neg hf, dif_neg, smul_zero]
rwa [integrable_smul_iff hr f]
theorem withDensityᵥ_smul' {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E]
[SMulCommClass ℝ 𝕜 E] (f : α → E) (r : 𝕜) :
(μ.withDensityᵥ fun x => r • f x) = r • μ.withDensityᵥ f :=
withDensityᵥ_smul f r
theorem withDensityᵥ_smul_eq_withDensityᵥ_withDensity {f : α → ℝ≥0} {g : α → E}
(hf : AEMeasurable f μ) (hfg : Integrable (f • g) μ) :
μ.withDensityᵥ (f • g) = (μ.withDensity (fun x ↦ f x)).withDensityᵥ g := by
ext s hs
rw [withDensityᵥ_apply hfg hs,
withDensityᵥ_apply ((integrable_withDensity_iff_integrable_smul₀ hf).mpr hfg) hs,
setIntegral_withDensity_eq_setIntegral_smul₀ hf.restrict _ hs]
rfl
theorem withDensityᵥ_smul_eq_withDensityᵥ_withDensity' {f : α → ℝ≥0∞} {g : α → E}
(hf : AEMeasurable f μ) (hflt : ∀ᵐ x ∂μ, f x < ∞)
(hfg : Integrable (fun x ↦ (f x).toReal • g x) μ) :
μ.withDensityᵥ (fun x ↦ (f x).toReal • g x) = (μ.withDensity f).withDensityᵥ g := by
rw [← withDensity_congr_ae (coe_toNNReal_ae_eq hflt),
← withDensityᵥ_smul_eq_withDensityᵥ_withDensity hf.ennreal_toNNReal hfg]
rfl
theorem Measure.withDensityᵥ_absolutelyContinuous (μ : Measure α) (f : α → ℝ) :
μ.withDensityᵥ f ≪ᵥ μ.toENNRealVectorMeasure := by
by_cases hf : Integrable f μ
· refine VectorMeasure.AbsolutelyContinuous.mk fun i hi₁ hi₂ => ?_
rw [toENNRealVectorMeasure_apply_measurable hi₁] at hi₂
rw [withDensityᵥ_apply hf hi₁, Measure.restrict_zero_set hi₂, integral_zero_measure]
· rw [withDensityᵥ, dif_neg hf]
exact VectorMeasure.AbsolutelyContinuous.zero _
/-- Having the same density implies the underlying functions are equal almost everywhere. -/
theorem Integrable.ae_eq_of_withDensityᵥ_eq {f g : α → E} (hf : Integrable f μ)
(hg : Integrable g μ) (hfg : μ.withDensityᵥ f = μ.withDensityᵥ g) : f =ᵐ[μ] g := by
refine hf.ae_eq_of_forall_setIntegral_eq f g hg fun i hi _ => ?_
rw [← withDensityᵥ_apply hf hi, hfg, withDensityᵥ_apply hg hi]
theorem WithDensityᵥEq.congr_ae {f g : α → E} (h : f =ᵐ[μ] g) :
μ.withDensityᵥ f = μ.withDensityᵥ g := by
by_cases hf : Integrable f μ
· ext i hi
rw [withDensityᵥ_apply hf hi, withDensityᵥ_apply (hf.congr h) hi]
exact integral_congr_ae (ae_restrict_of_ae h)
· have hg : ¬Integrable g μ := by intro hg; exact hf (hg.congr h.symm)
rw [withDensityᵥ, withDensityᵥ, dif_neg hf, dif_neg hg]
theorem Integrable.withDensityᵥ_eq_iff {f g : α → E} (hf : Integrable f μ) (hg : Integrable g μ) :
μ.withDensityᵥ f = μ.withDensityᵥ g ↔ f =ᵐ[μ] g :=
⟨fun hfg => hf.ae_eq_of_withDensityᵥ_eq hg hfg, fun h => WithDensityᵥEq.congr_ae h⟩
section SignedMeasure
theorem withDensityᵥ_toReal {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) (hf : (∫⁻ x, f x ∂μ) ≠ ∞) :
(μ.withDensityᵥ fun x => (f x).toReal) =
@toSignedMeasure α _ (μ.withDensity f) (isFiniteMeasure_withDensity hf) := by
have hfi := integrable_toReal_of_lintegral_ne_top hfm hf
haveI := isFiniteMeasure_withDensity hf
ext i hi
rw [withDensityᵥ_apply hfi hi, toSignedMeasure_apply_measurable hi, withDensity_apply _ hi,
integral_toReal hfm.restrict]
refine ae_lt_top' hfm.restrict (ne_top_of_le_ne_top hf ?_)
conv_rhs => rw [← setLIntegral_univ]
exact lintegral_mono_set (Set.subset_univ _)
theorem withDensityᵥ_eq_withDensity_pos_part_sub_withDensity_neg_part {f : α → ℝ}
(hfi : Integrable f μ) :
μ.withDensityᵥ f =
@toSignedMeasure α _ (μ.withDensity fun x => ENNReal.ofReal <| f x)
(isFiniteMeasure_withDensity_ofReal hfi.2) -
@toSignedMeasure α _ (μ.withDensity fun x => ENNReal.ofReal <| -f x)
(isFiniteMeasure_withDensity_ofReal hfi.neg.2) := by
haveI := isFiniteMeasure_withDensity_ofReal hfi.2
haveI := isFiniteMeasure_withDensity_ofReal hfi.neg.2
ext i hi
rw [withDensityᵥ_apply hfi hi,
integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi.integrableOn,
VectorMeasure.sub_apply, toSignedMeasure_apply_measurable hi,
toSignedMeasure_apply_measurable hi, withDensity_apply _ hi, withDensity_apply _ hi]
theorem Integrable.withDensityᵥ_trim_eq_integral {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) {f : α → ℝ} (hf : Integrable f μ) {i : Set α} (hi : MeasurableSet[m] i) :
(μ.withDensityᵥ f).trim hm i = ∫ x in i, f x ∂μ := by
rw [VectorMeasure.trim_measurableSet_eq hm hi, withDensityᵥ_apply hf (hm _ hi)]
theorem Integrable.withDensityᵥ_trim_absolutelyContinuous {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) (hfi : Integrable f μ) :
(μ.withDensityᵥ f).trim hm ≪ᵥ (μ.trim hm).toENNRealVectorMeasure := by
refine VectorMeasure.AbsolutelyContinuous.mk fun j hj₁ hj₂ => ?_
rw [Measure.toENNRealVectorMeasure_apply_measurable hj₁, trim_measurableSet_eq hm hj₁] at hj₂
rw [VectorMeasure.trim_measurableSet_eq hm hj₁, withDensityᵥ_apply hfi (hm _ hj₁)]
simp only [Measure.restrict_eq_zero.mpr hj₂, integral_zero_measure]
end SignedMeasure
end MeasureTheory
|
MeasureTheory\Measure\Haar\Basic.lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Measure.Content
import Mathlib.MeasureTheory.Group.Prod
import Mathlib.Topology.Algebra.Group.Compact
/-!
# Haar measure
In this file we prove the existence of Haar measure for a locally compact Hausdorff topological
group.
We follow the write-up by Jonathan Gleason, *Existence and Uniqueness of Haar Measure*.
This is essentially the same argument as in
https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets.
We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest)
number of left-translates of `U` that are needed to cover `K` (`index` in the formalization).
Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`,
where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set
with nonempty interior. This function is `chaar` in the formalization, and we define the limit
formally using Tychonoff's theorem.
This function `h` forms a content, which we can extend to an outer measure and then a measure
(`haarMeasure`).
We normalize the Haar measure so that the measure of `K₀` is `1`.
Note that `μ` need not coincide with `h` on compact sets, according to
[halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`,
where `ᵒ` denotes the interior.
We also give a form of uniqueness of Haar measure, for σ-finite measures on second-countable
locally compact groups. For more involved statements not assuming second-countability, see
the file `MeasureTheory.Measure.Haar.Unique`.
## Main Declarations
* `haarMeasure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant
regular measure. It takes as argument a compact set of the group (with non-empty interior),
and is normalized so that the measure of the given set is 1.
* `haarMeasure_self`: the Haar measure is normalized.
* `isMulLeftInvariant_haarMeasure`: the Haar measure is left invariant.
* `regular_haarMeasure`: the Haar measure is a regular measure.
* `isHaarMeasure_haarMeasure`: the Haar measure satisfies the `IsHaarMeasure` typeclass, i.e.,
it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets.
* `haar` : some choice of a Haar measure, on a locally compact Hausdorff group, constructed as
`haarMeasure K` where `K` is some arbitrary choice of a compact set with nonempty interior.
* `haarMeasure_unique`: Every σ-finite left invariant measure on a second-countable locally compact
Hausdorff group is a scalar multiple of the Haar measure.
## References
* Paul Halmos (1950), Measure Theory, §53
* Jonathan Gleason, Existence and Uniqueness of Haar Measure
- Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact
sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11)
invalid.
* https://en.wikipedia.org/wiki/Haar_measure
-/
noncomputable section
open Set Inv Function TopologicalSpace MeasurableSpace
open scoped NNReal ENNReal Pointwise Topology
namespace MeasureTheory
namespace Measure
section Group
variable {G : Type*} [Group G]
/-! We put the internal functions in the construction of the Haar measure in a namespace,
so that the chosen names don't clash with other declarations.
We first define a couple of the functions before proving the properties (that require that `G`
is a topological group). -/
namespace haar
/-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`:
it is the smallest number of (left) translates of `V` that is necessary to cover `K`.
It is defined to be 0 if no finite number of translates cover `K`. -/
@[to_additive addIndex "additive version of `MeasureTheory.Measure.haar.index`"]
noncomputable def index (K V : Set G) : ℕ :=
sInf <| Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V }
@[to_additive addIndex_empty]
theorem index_empty {V : Set G} : index ∅ V = 0 := by
simp only [index, Nat.sInf_eq_zero]; left; use ∅
simp only [Finset.card_empty, empty_subset, mem_setOf_eq, eq_self_iff_true, and_self_iff]
variable [TopologicalSpace G]
/-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`.
In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`,
and `K` is any compact set.
The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an
element of `haarProduct` (below). -/
@[to_additive "additive version of `MeasureTheory.Measure.haar.prehaar`"]
noncomputable def prehaar (K₀ U : Set G) (K : Compacts G) : ℝ :=
(index (K : Set G) U : ℝ) / index K₀ U
@[to_additive]
theorem prehaar_empty (K₀ : PositiveCompacts G) {U : Set G} : prehaar (K₀ : Set G) U ⊥ = 0 := by
rw [prehaar, Compacts.coe_bot, index_empty, Nat.cast_zero, zero_div]
@[to_additive]
theorem prehaar_nonneg (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G) :
0 ≤ prehaar (K₀ : Set G) U K := by apply div_nonneg <;> norm_cast <;> apply zero_le
/-- `haarProduct K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`.
For all `U`, we can show that `prehaar K₀ U ∈ haarProduct K₀`. -/
@[to_additive "additive version of `MeasureTheory.Measure.haar.haarProduct`"]
def haarProduct (K₀ : Set G) : Set (Compacts G → ℝ) :=
pi univ fun K => Icc 0 <| index (K : Set G) K₀
@[to_additive (attr := simp)]
theorem mem_prehaar_empty {K₀ : Set G} {f : Compacts G → ℝ} :
f ∈ haarProduct K₀ ↔ ∀ K : Compacts G, f K ∈ Icc (0 : ℝ) (index (K : Set G) K₀) := by
simp only [haarProduct, Set.pi, forall_prop_of_true, mem_univ, mem_setOf_eq]
/-- The closure of the collection of elements of the form `prehaar K₀ U`,
for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space
`compacts G → ℝ`, with the topology of pointwise convergence.
We show that the intersection of all these sets is nonempty, and the Haar measure
on compact sets is defined to be an element in the closure of this intersection. -/
@[to_additive "additive version of `MeasureTheory.Measure.haar.clPrehaar`"]
def clPrehaar (K₀ : Set G) (V : OpenNhdsOf (1 : G)) : Set (Compacts G → ℝ) :=
closure <| prehaar K₀ '' { U : Set G | U ⊆ V.1 ∧ IsOpen U ∧ (1 : G) ∈ U }
variable [TopologicalGroup G]
/-!
### Lemmas about `index`
-/
/-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined,
there is a finite set `t` satisfying the desired properties. -/
@[to_additive addIndex_defined
"If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is
a finite set `t` satisfying the desired properties."]
theorem index_defined {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) :
∃ n : ℕ, n ∈ Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } := by
rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩; exact ⟨t.card, t, ht, rfl⟩
@[to_additive addIndex_elim]
theorem index_elim {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) :
∃ t : Finset G, (K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V) ∧ Finset.card t = index K V := by
have := Nat.sInf_mem (index_defined hK hV); rwa [mem_image] at this
@[to_additive le_addIndex_mul]
theorem le_index_mul (K₀ : PositiveCompacts G) (K : Compacts G) {V : Set G}
(hV : (interior V).Nonempty) :
index (K : Set G) V ≤ index (K : Set G) K₀ * index (K₀ : Set G) V := by
classical
obtain ⟨s, h1s, h2s⟩ := index_elim K.isCompact K₀.interior_nonempty
obtain ⟨t, h1t, h2t⟩ := index_elim K₀.isCompact hV
rw [← h2s, ← h2t, mul_comm]
refine le_trans ?_ Finset.card_mul_le
apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq]; refine Subset.trans h1s ?_
apply iUnion₂_subset; intro g₁ hg₁; rw [preimage_subset_iff]; intro g₂ hg₂
have := h1t hg₂
rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩; rw [mem_preimage, ← mul_assoc] at h2V
exact mem_biUnion (Finset.mul_mem_mul hg₃ hg₁) h2V
@[to_additive addIndex_pos]
theorem index_pos (K : PositiveCompacts G) {V : Set G} (hV : (interior V).Nonempty) :
0 < index (K : Set G) V := by
classical
rw [index, Nat.sInf_def, Nat.find_pos, mem_image]
· rintro ⟨t, h1t, h2t⟩; rw [Finset.card_eq_zero] at h2t; subst h2t
obtain ⟨g, hg⟩ := K.interior_nonempty
show g ∈ (∅ : Set G)
convert h1t (interior_subset hg); symm
simp only [Finset.not_mem_empty, iUnion_of_empty, iUnion_empty]
· exact index_defined K.isCompact hV
@[to_additive addIndex_mono]
theorem index_mono {K K' V : Set G} (hK' : IsCompact K') (h : K ⊆ K') (hV : (interior V).Nonempty) :
index K V ≤ index K' V := by
rcases index_elim hK' hV with ⟨s, h1s, h2s⟩
apply Nat.sInf_le; rw [mem_image]; exact ⟨s, Subset.trans h h1s, h2s⟩
@[to_additive addIndex_union_le]
theorem index_union_le (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) :
index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V := by
classical
rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩
rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩
rw [← h2s, ← h2t]
refine le_trans ?_ (Finset.card_union_le _ _)
apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq]
apply union_subset <;> refine Subset.trans (by assumption) ?_ <;>
apply biUnion_subset_biUnion_left <;> intro g hg <;> simp only [mem_def] at hg <;>
simp only [mem_def, Multiset.mem_union, Finset.union_val, hg, or_true_iff, true_or_iff]
@[to_additive addIndex_union_eq]
theorem index_union_eq (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty)
(h : Disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) :
index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V := by
classical
apply le_antisymm (index_union_le K₁ K₂ hV)
rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩; rw [← h2s]
have :
∀ K : Set G,
(K ⊆ ⋃ g ∈ s, (fun h => g * h) ⁻¹' V) →
index K V ≤ (s.filter fun g => ((fun h : G => g * h) ⁻¹' V ∩ K).Nonempty).card := by
intro K hK; apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq]
intro g hg; rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩
simp only [mem_preimage] at h2g₀
simp only [mem_iUnion]; use g₀; constructor; swap
· simp only [Finset.mem_filter, h1g₀, true_and_iff]; use g
simp only [hg, h2g₀, mem_inter_iff, mem_preimage, and_self_iff]
exact h2g₀
refine
le_trans
(add_le_add (this K₁.1 <| Subset.trans subset_union_left h1s)
(this K₂.1 <| Subset.trans subset_union_right h1s)) ?_
rw [← Finset.card_union_of_disjoint, Finset.filter_union_right]
· exact s.card_filter_le _
apply Finset.disjoint_filter.mpr
rintro g₁ _ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩
simp only [mem_preimage] at h1g₃ h1g₂
refine h.le_bot (?_ : g₁⁻¹ ∈ _)
constructor <;> simp only [Set.mem_inv, Set.mem_mul, exists_exists_and_eq_and, exists_and_left]
· refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, ?_, ?_⟩
· simp only [inv_inv, h1g₂]
· simp only [mul_inv_rev, mul_inv_cancel_left]
· refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, ?_, ?_⟩
· simp only [inv_inv, h1g₃]
· simp only [mul_inv_rev, mul_inv_cancel_left]
@[to_additive add_left_addIndex_le]
theorem mul_left_index_le {K : Set G} (hK : IsCompact K) {V : Set G} (hV : (interior V).Nonempty)
(g : G) : index ((fun h => g * h) '' K) V ≤ index K V := by
rcases index_elim hK hV with ⟨s, h1s, h2s⟩; rw [← h2s]
apply Nat.sInf_le; rw [mem_image]
refine ⟨s.map (Equiv.mulRight g⁻¹).toEmbedding, ?_, Finset.card_map _⟩
simp only [mem_setOf_eq]; refine Subset.trans (image_subset _ h1s) ?_
rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩
simp only [mem_preimage] at hg₁
simp only [exists_prop, mem_iUnion, Finset.mem_map, Equiv.coe_mulRight,
exists_exists_and_eq_and, mem_preimage, Equiv.toEmbedding_apply]
refine ⟨_, hg₂, ?_⟩; simp only [mul_assoc, hg₁, inv_mul_cancel_left]
@[to_additive is_left_invariant_addIndex]
theorem is_left_invariant_index {K : Set G} (hK : IsCompact K) (g : G) {V : Set G}
(hV : (interior V).Nonempty) : index ((fun h => g * h) '' K) V = index K V := by
refine le_antisymm (mul_left_index_le hK hV g) ?_
convert mul_left_index_le (hK.image <| continuous_mul_left g) hV g⁻¹
rw [image_image]; symm; convert image_id' _ with h; apply inv_mul_cancel_left
/-!
### Lemmas about `prehaar`
-/
@[to_additive add_prehaar_le_addIndex]
theorem prehaar_le_index (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G)
(hU : (interior U).Nonempty) : prehaar (K₀ : Set G) U K ≤ index (K : Set G) K₀ := by
unfold prehaar; rw [div_le_iff] <;> norm_cast
· apply le_index_mul K₀ K hU
· exact index_pos K₀ hU
@[to_additive]
theorem prehaar_pos (K₀ : PositiveCompacts G) {U : Set G} (hU : (interior U).Nonempty) {K : Set G}
(h1K : IsCompact K) (h2K : (interior K).Nonempty) : 0 < prehaar (K₀ : Set G) U ⟨K, h1K⟩ := by
apply div_pos <;> norm_cast
· apply index_pos ⟨⟨K, h1K⟩, h2K⟩ hU
· exact index_pos K₀ hU
@[to_additive]
theorem prehaar_mono {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty)
{K₁ K₂ : Compacts G} (h : (K₁ : Set G) ⊆ K₂.1) :
prehaar (K₀ : Set G) U K₁ ≤ prehaar (K₀ : Set G) U K₂ := by
simp only [prehaar]; rw [div_le_div_right]
· exact mod_cast index_mono K₂.2 h hU
· exact mod_cast index_pos K₀ hU
@[to_additive]
theorem prehaar_self {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty) :
prehaar (K₀ : Set G) U K₀.toCompacts = 1 :=
div_self <| ne_of_gt <| mod_cast index_pos K₀ hU
@[to_additive]
theorem prehaar_sup_le {K₀ : PositiveCompacts G} {U : Set G} (K₁ K₂ : Compacts G)
(hU : (interior U).Nonempty) :
prehaar (K₀ : Set G) U (K₁ ⊔ K₂) ≤ prehaar (K₀ : Set G) U K₁ + prehaar (K₀ : Set G) U K₂ := by
simp only [prehaar]; rw [div_add_div_same, div_le_div_right]
· exact mod_cast index_union_le K₁ K₂ hU
· exact mod_cast index_pos K₀ hU
@[to_additive]
theorem prehaar_sup_eq {K₀ : PositiveCompacts G} {U : Set G} {K₁ K₂ : Compacts G}
(hU : (interior U).Nonempty) (h : Disjoint (K₁.1 * U⁻¹) (K₂.1 * U⁻¹)) :
prehaar (K₀ : Set G) U (K₁ ⊔ K₂) = prehaar (K₀ : Set G) U K₁ + prehaar (K₀ : Set G) U K₂ := by
simp only [prehaar]; rw [div_add_div_same]
-- Porting note: Here was `congr`, but `to_additive` failed to generate a theorem.
refine congr_arg (fun x : ℝ => x / index K₀ U) ?_
exact mod_cast index_union_eq K₁ K₂ hU h
@[to_additive]
theorem is_left_invariant_prehaar {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty)
(g : G) (K : Compacts G) :
prehaar (K₀ : Set G) U (K.map _ <| continuous_mul_left g) = prehaar (K₀ : Set G) U K := by
simp only [prehaar, Compacts.coe_map, is_left_invariant_index K.isCompact _ hU]
/-!
### Lemmas about `haarProduct`
-/
@[to_additive]
theorem prehaar_mem_haarProduct (K₀ : PositiveCompacts G) {U : Set G} (hU : (interior U).Nonempty) :
prehaar (K₀ : Set G) U ∈ haarProduct (K₀ : Set G) := by
rintro ⟨K, hK⟩ _; rw [mem_Icc]; exact ⟨prehaar_nonneg K₀ _, prehaar_le_index K₀ _ hU⟩
@[to_additive]
theorem nonempty_iInter_clPrehaar (K₀ : PositiveCompacts G) :
(haarProduct (K₀ : Set G) ∩ ⋂ V : OpenNhdsOf (1 : G), clPrehaar K₀ V).Nonempty := by
have : IsCompact (haarProduct (K₀ : Set G)) := by
apply isCompact_univ_pi; intro K; apply isCompact_Icc
refine this.inter_iInter_nonempty (clPrehaar K₀) (fun s => isClosed_closure) fun t => ?_
let V₀ := ⋂ V ∈ t, (V : OpenNhdsOf (1 : G)).carrier
have h1V₀ : IsOpen V₀ := isOpen_biInter_finset <| by rintro ⟨⟨V, hV₁⟩, hV₂⟩ _; exact hV₁
have h2V₀ : (1 : G) ∈ V₀ := by simp only [V₀, mem_iInter]; rintro ⟨⟨V, hV₁⟩, hV₂⟩ _; exact hV₂
refine ⟨prehaar K₀ V₀, ?_⟩
constructor
· apply prehaar_mem_haarProduct K₀; use 1; rwa [h1V₀.interior_eq]
· simp only [mem_iInter]; rintro ⟨V, hV⟩ h2V; apply subset_closure
apply mem_image_of_mem; rw [mem_setOf_eq]
exact ⟨Subset.trans (iInter_subset _ ⟨V, hV⟩) (iInter_subset _ h2V), h1V₀, h2V₀⟩
/-!
### Lemmas about `chaar`
-/
/-- This is the "limit" of `prehaar K₀ U K` as `U` becomes a smaller and smaller open
neighborhood of `(1 : G)`. More precisely, it is defined to be an arbitrary element
in the intersection of all the sets `clPrehaar K₀ V` in `haarProduct K₀`.
This is roughly equal to the Haar measure on compact sets,
but it can differ slightly. We do know that
`haarMeasure K₀ (interior K) ≤ chaar K₀ K ≤ haarMeasure K₀ K`. -/
@[to_additive addCHaar "additive version of `MeasureTheory.Measure.haar.chaar`"]
noncomputable def chaar (K₀ : PositiveCompacts G) (K : Compacts G) : ℝ :=
Classical.choose (nonempty_iInter_clPrehaar K₀) K
@[to_additive addCHaar_mem_addHaarProduct]
theorem chaar_mem_haarProduct (K₀ : PositiveCompacts G) : chaar K₀ ∈ haarProduct (K₀ : Set G) :=
(Classical.choose_spec (nonempty_iInter_clPrehaar K₀)).1
@[to_additive addCHaar_mem_clAddPrehaar]
theorem chaar_mem_clPrehaar (K₀ : PositiveCompacts G) (V : OpenNhdsOf (1 : G)) :
chaar K₀ ∈ clPrehaar (K₀ : Set G) V := by
have := (Classical.choose_spec (nonempty_iInter_clPrehaar K₀)).2; rw [mem_iInter] at this
exact this V
@[to_additive addCHaar_nonneg]
theorem chaar_nonneg (K₀ : PositiveCompacts G) (K : Compacts G) : 0 ≤ chaar K₀ K := by
have := chaar_mem_haarProduct K₀ K (mem_univ _); rw [mem_Icc] at this; exact this.1
@[to_additive addCHaar_empty]
theorem chaar_empty (K₀ : PositiveCompacts G) : chaar K₀ ⊥ = 0 := by
let eval : (Compacts G → ℝ) → ℝ := fun f => f ⊥
have : Continuous eval := continuous_apply ⊥
show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
unfold clPrehaar; rw [IsClosed.closure_subset_iff]
· rintro _ ⟨U, _, rfl⟩; apply prehaar_empty
· apply continuous_iff_isClosed.mp this; exact isClosed_singleton
@[to_additive addCHaar_self]
theorem chaar_self (K₀ : PositiveCompacts G) : chaar K₀ K₀.toCompacts = 1 := by
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₀.toCompacts
have : Continuous eval := continuous_apply _
show chaar K₀ ∈ eval ⁻¹' {(1 : ℝ)}
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
unfold clPrehaar; rw [IsClosed.closure_subset_iff]
· rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩; apply prehaar_self
rw [h2U.interior_eq]; exact ⟨1, h3U⟩
· apply continuous_iff_isClosed.mp this; exact isClosed_singleton
@[to_additive addCHaar_mono]
theorem chaar_mono {K₀ : PositiveCompacts G} {K₁ K₂ : Compacts G} (h : (K₁ : Set G) ⊆ K₂) :
chaar K₀ K₁ ≤ chaar K₀ K₂ := by
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₂ - f K₁
have : Continuous eval := (continuous_apply K₂).sub (continuous_apply K₁)
rw [← sub_nonneg]; show chaar K₀ ∈ eval ⁻¹' Ici (0 : ℝ)
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
unfold clPrehaar; rw [IsClosed.closure_subset_iff]
· rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩; simp only [eval, mem_preimage, mem_Ici, sub_nonneg]
apply prehaar_mono _ h; rw [h2U.interior_eq]; exact ⟨1, h3U⟩
· apply continuous_iff_isClosed.mp this; exact isClosed_Ici
@[to_additive addCHaar_sup_le]
theorem chaar_sup_le {K₀ : PositiveCompacts G} (K₁ K₂ : Compacts G) :
chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂ := by
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
have : Continuous eval := by
exact ((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂))
rw [← sub_nonneg]; show chaar K₀ ∈ eval ⁻¹' Ici (0 : ℝ)
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
unfold clPrehaar; rw [IsClosed.closure_subset_iff]
· rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩; simp only [eval, mem_preimage, mem_Ici, sub_nonneg]
apply prehaar_sup_le; rw [h2U.interior_eq]; exact ⟨1, h3U⟩
· apply continuous_iff_isClosed.mp this; exact isClosed_Ici
@[to_additive addCHaar_sup_eq]
theorem chaar_sup_eq {K₀ : PositiveCompacts G}
{K₁ K₂ : Compacts G} (h : Disjoint K₁.1 K₂.1) (h₂ : IsClosed K₂.1) :
chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂ := by
rcases SeparatedNhds.of_isCompact_isCompact_isClosed K₁.2 K₂.2 h₂ h
with ⟨U₁, U₂, h1U₁, h1U₂, h2U₁, h2U₂, hU⟩
rcases compact_open_separated_mul_right K₁.2 h1U₁ h2U₁ with ⟨L₁, h1L₁, h2L₁⟩
rcases mem_nhds_iff.mp h1L₁ with ⟨V₁, h1V₁, h2V₁, h3V₁⟩
replace h2L₁ := Subset.trans (mul_subset_mul_left h1V₁) h2L₁
rcases compact_open_separated_mul_right K₂.2 h1U₂ h2U₂ with ⟨L₂, h1L₂, h2L₂⟩
rcases mem_nhds_iff.mp h1L₂ with ⟨V₂, h1V₂, h2V₂, h3V₂⟩
replace h2L₂ := Subset.trans (mul_subset_mul_left h1V₂) h2L₂
let eval : (Compacts G → ℝ) → ℝ := fun f => f K₁ + f K₂ - f (K₁ ⊔ K₂)
have : Continuous eval :=
((continuous_apply K₁).add (continuous_apply K₂)).sub (continuous_apply (K₁ ⊔ K₂))
rw [eq_comm, ← sub_eq_zero]; show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}
let V := V₁ ∩ V₂
apply
mem_of_subset_of_mem _
(chaar_mem_clPrehaar K₀
⟨⟨V⁻¹, (h2V₁.inter h2V₂).preimage continuous_inv⟩, by
simp only [V, mem_inv, inv_one, h3V₁, h3V₂, mem_inter_iff, true_and_iff]⟩)
unfold clPrehaar; rw [IsClosed.closure_subset_iff]
· rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩
simp only [eval, mem_preimage, sub_eq_zero, mem_singleton_iff]; rw [eq_comm]
apply prehaar_sup_eq
· rw [h2U.interior_eq]; exact ⟨1, h3U⟩
· refine disjoint_of_subset ?_ ?_ hU
· refine Subset.trans (mul_subset_mul Subset.rfl ?_) h2L₁
exact Subset.trans (inv_subset.mpr h1U) inter_subset_left
· refine Subset.trans (mul_subset_mul Subset.rfl ?_) h2L₂
exact Subset.trans (inv_subset.mpr h1U) inter_subset_right
· apply continuous_iff_isClosed.mp this; exact isClosed_singleton
@[to_additive is_left_invariant_addCHaar]
theorem is_left_invariant_chaar {K₀ : PositiveCompacts G} (g : G) (K : Compacts G) :
chaar K₀ (K.map _ <| continuous_mul_left g) = chaar K₀ K := by
let eval : (Compacts G → ℝ) → ℝ := fun f => f (K.map _ <| continuous_mul_left g) - f K
have : Continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K)
rw [← sub_eq_zero]; show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)}
apply mem_of_subset_of_mem _ (chaar_mem_clPrehaar K₀ ⊤)
unfold clPrehaar; rw [IsClosed.closure_subset_iff]
· rintro _ ⟨U, ⟨_, h2U, h3U⟩, rfl⟩
simp only [eval, mem_singleton_iff, mem_preimage, sub_eq_zero]
apply is_left_invariant_prehaar; rw [h2U.interior_eq]; exact ⟨1, h3U⟩
· apply continuous_iff_isClosed.mp this; exact isClosed_singleton
/-- The function `chaar` interpreted in `ℝ≥0`, as a content -/
@[to_additive "additive version of `MeasureTheory.Measure.haar.haarContent`"]
noncomputable def haarContent (K₀ : PositiveCompacts G) : Content G where
toFun K := ⟨chaar K₀ K, chaar_nonneg _ _⟩
mono' K₁ K₂ h := by simp only [← NNReal.coe_le_coe, NNReal.toReal, chaar_mono, h]
sup_disjoint' K₁ K₂ h _h₁ h₂ := by simp only [chaar_sup_eq h]; rfl
sup_le' K₁ K₂ := by
simp only [← NNReal.coe_le_coe, NNReal.coe_add]
simp only [NNReal.toReal, chaar_sup_le]
/-! We only prove the properties for `haarContent` that we use at least twice below. -/
@[to_additive]
theorem haarContent_apply (K₀ : PositiveCompacts G) (K : Compacts G) :
haarContent K₀ K = show NNReal from ⟨chaar K₀ K, chaar_nonneg _ _⟩ :=
rfl
/-- The variant of `chaar_self` for `haarContent` -/
@[to_additive "The variant of `addCHaar_self` for `addHaarContent`."]
theorem haarContent_self {K₀ : PositiveCompacts G} : haarContent K₀ K₀.toCompacts = 1 := by
simp_rw [← ENNReal.coe_one, haarContent_apply, ENNReal.coe_inj, chaar_self]; rfl
/-- The variant of `is_left_invariant_chaar` for `haarContent` -/
@[to_additive "The variant of `is_left_invariant_addCHaar` for `addHaarContent`"]
theorem is_left_invariant_haarContent {K₀ : PositiveCompacts G} (g : G) (K : Compacts G) :
haarContent K₀ (K.map _ <| continuous_mul_left g) = haarContent K₀ K := by
simpa only [ENNReal.coe_inj, ← NNReal.coe_inj, haarContent_apply] using
is_left_invariant_chaar g K
@[to_additive]
theorem haarContent_outerMeasure_self_pos (K₀ : PositiveCompacts G) :
0 < (haarContent K₀).outerMeasure K₀ := by
refine zero_lt_one.trans_le ?_
rw [Content.outerMeasure_eq_iInf]
refine le_iInf₂ fun U hU => le_iInf fun hK₀ => le_trans ?_ <| le_iSup₂ K₀.toCompacts hK₀
exact haarContent_self.ge
@[to_additive]
theorem haarContent_outerMeasure_closure_pos (K₀ : PositiveCompacts G) :
0 < (haarContent K₀).outerMeasure (closure K₀) :=
(haarContent_outerMeasure_self_pos K₀).trans_le (OuterMeasure.mono _ subset_closure)
end haar
open haar
/-!
### The Haar measure
-/
variable [TopologicalSpace G] [TopologicalGroup G] [MeasurableSpace G] [BorelSpace G]
/-- The Haar measure on the locally compact group `G`, scaled so that `haarMeasure K₀ K₀ = 1`. -/
@[to_additive
"The Haar measure on the locally compact additive group `G`, scaled so that
`addHaarMeasure K₀ K₀ = 1`."]
noncomputable def haarMeasure (K₀ : PositiveCompacts G) : Measure G :=
((haarContent K₀).measure K₀)⁻¹ • (haarContent K₀).measure
@[to_additive]
theorem haarMeasure_apply {K₀ : PositiveCompacts G} {s : Set G} (hs : MeasurableSet s) :
haarMeasure K₀ s = (haarContent K₀).outerMeasure s / (haarContent K₀).measure K₀ := by
change ((haarContent K₀).measure K₀)⁻¹ * (haarContent K₀).measure s = _
simp only [hs, div_eq_mul_inv, mul_comm, Content.measure_apply]
@[to_additive]
instance isMulLeftInvariant_haarMeasure (K₀ : PositiveCompacts G) :
IsMulLeftInvariant (haarMeasure K₀) := by
rw [← forall_measure_preimage_mul_iff]
intro g A hA
rw [haarMeasure_apply hA, haarMeasure_apply (measurable_const_mul g hA)]
-- Porting note: Here was `congr 1`, but `to_additive` failed to generate a theorem.
refine congr_arg (fun x : ℝ≥0∞ => x / (haarContent K₀).measure K₀) ?_
apply Content.is_mul_left_invariant_outerMeasure
apply is_left_invariant_haarContent
@[to_additive]
theorem haarMeasure_self {K₀ : PositiveCompacts G} : haarMeasure K₀ K₀ = 1 := by
haveI : LocallyCompactSpace G := K₀.locallyCompactSpace_of_group
simp only [haarMeasure, coe_smul, Pi.smul_apply, smul_eq_mul]
rw [← K₀.isCompact.measure_closure,
Content.measure_apply _ isClosed_closure.measurableSet, ENNReal.inv_mul_cancel]
· exact (haarContent_outerMeasure_closure_pos K₀).ne'
· exact (Content.outerMeasure_lt_top_of_isCompact _ K₀.isCompact.closure).ne
/-- The Haar measure is regular. -/
@[to_additive "The additive Haar measure is regular."]
instance regular_haarMeasure {K₀ : PositiveCompacts G} : (haarMeasure K₀).Regular := by
haveI : LocallyCompactSpace G := K₀.locallyCompactSpace_of_group
apply Regular.smul
rw [← K₀.isCompact.measure_closure,
Content.measure_apply _ isClosed_closure.measurableSet, ENNReal.inv_ne_top]
exact (haarContent_outerMeasure_closure_pos K₀).ne'
@[to_additive]
theorem haarMeasure_closure_self {K₀ : PositiveCompacts G} : haarMeasure K₀ (closure K₀) = 1 := by
rw [K₀.isCompact.measure_closure, haarMeasure_self]
/-- The Haar measure is sigma-finite in a second countable group. -/
@[to_additive "The additive Haar measure is sigma-finite in a second countable group."]
instance sigmaFinite_haarMeasure [SecondCountableTopology G] {K₀ : PositiveCompacts G} :
SigmaFinite (haarMeasure K₀) := by
haveI : LocallyCompactSpace G := K₀.locallyCompactSpace_of_group; infer_instance
/-- The Haar measure is a Haar measure, i.e., it is invariant and gives finite mass to compact
sets and positive mass to nonempty open sets. -/
@[to_additive
"The additive Haar measure is an additive Haar measure, i.e., it is invariant and gives finite mass
to compact sets and positive mass to nonempty open sets."]
instance isHaarMeasure_haarMeasure (K₀ : PositiveCompacts G) : IsHaarMeasure (haarMeasure K₀) := by
apply
isHaarMeasure_of_isCompact_nonempty_interior (haarMeasure K₀) K₀ K₀.isCompact
K₀.interior_nonempty
· simp only [haarMeasure_self]; exact one_ne_zero
· simp only [haarMeasure_self, ne_eq, ENNReal.one_ne_top, not_false_eq_true]
/-- `haar` is some choice of a Haar measure, on a locally compact group. -/
@[to_additive (attr := reducible)
"`addHaar` is some choice of a Haar measure, on a locally compact additive group."]
noncomputable def haar [LocallyCompactSpace G] : Measure G :=
haarMeasure <| Classical.arbitrary _
/-! Steinhaus theorem: if `E` has positive measure, then `E / E` contains a neighborhood of zero.
Note that this is not true for general regular Haar measures: in `ℝ × ℝ` where the first factor
has the discrete topology, then `E = ℝ × {0}` has infinite measure for the regular Haar measure,
but `E / E` does not contain a neighborhood of zero. On the other hand, it is always true for
inner regular Haar measures (and in particular for any Haar measure on a second countable group).
-/
open Pointwise
/-- **Steinhaus Theorem** In any locally compact group `G` with an inner regular Haar measure `μ`,
for any measurable set `E` of positive measure, the set `E / E` is a neighbourhood of `1`. -/
@[to_additive
"**Steinhaus Theorem** In any locally compact group `G` with an inner regular Haar measure `μ`,
for any measurable set `E` of positive measure, the set `E - E` is a neighbourhood of `0`."]
theorem div_mem_nhds_one_of_haar_pos (μ : Measure G) [IsHaarMeasure μ] [LocallyCompactSpace G]
[InnerRegular μ] (E : Set G) (hE : MeasurableSet E) (hEpos : 0 < μ E) :
E / E ∈ 𝓝 (1 : G) := by
/- For any inner regular measure `μ` and set `E` of positive measure, we can find a compact
set `K` of positive measure inside `E`. Further, there exists a neighborhood `V` of the
identity such that `v • K \ K` has small measure for all `v ∈ V`, say `< μ K`.
Then `v • K` and `K` can not be disjoint, as otherwise `μ (v • K \ K) = μ (v • K) = μ K`.
This show that `K / K` contains the neighborhood `V` of `1`, and therefore that it is
itself such a neighborhood. -/
obtain ⟨K, hKE, hK, K_closed, hKpos⟩ :
∃ (K : Set G), K ⊆ E ∧ IsCompact K ∧ IsClosed K ∧ 0 < μ K := by
rcases MeasurableSet.exists_lt_isCompact hE hEpos with ⟨K, KE, K_comp, K_meas⟩
refine ⟨closure K, ?_, K_comp.closure, isClosed_closure, ?_⟩
· exact K_comp.closure_subset_measurableSet hE KE
· rwa [K_comp.measure_closure]
filter_upwards [eventually_nhds_one_measure_smul_diff_lt hK K_closed hKpos.ne' (μ := μ)] with g hg
have : ¬Disjoint (g • K) K := fun hd ↦ by
rw [hd.symm.sdiff_eq_right, measure_smul] at hg
exact hg.false
rcases Set.not_disjoint_iff.1 this with ⟨_, ⟨x, hxK, rfl⟩, hgxK⟩
simpa using div_mem_div (hKE hgxK) (hKE hxK)
section SecondCountable_SigmaFinite
/-! In this section, we investigate uniqueness of left-invariant measures without assuming that
the measure is finite on compact sets, but assuming σ-finiteness instead. We also rely on
second-countability, to ensure that the group operations are measurable: in this case, one can
bypass all topological arguments, and conclude using uniqueness of σ-finite left-invariant measures
in measurable groups.
For more general uniqueness statements without second-countability assumptions,
see the file `MeasureTheory.Measure.Haar.Unique`.
-/
variable [SecondCountableTopology G]
/-- **Uniqueness of left-invariant measures**: In a second-countable locally compact group, any
σ-finite left-invariant measure is a scalar multiple of the Haar measure.
This is slightly weaker than assuming that `μ` is a Haar measure (in particular we don't require
`μ ≠ 0`).
See also `isMulLeftInvariant_eq_smul_of_regular`
for a statement not assuming second-countability. -/
@[to_additive
"**Uniqueness of left-invariant measures**: In a second-countable locally compact additive group,
any σ-finite left-invariant measure is a scalar multiple of the additive Haar measure.
This is slightly weaker than assuming that `μ` is a additive Haar measure (in particular we don't
require `μ ≠ 0`).
See also `isAddLeftInvariant_eq_smul_of_regular`
for a statement not assuming second-countability."]
theorem haarMeasure_unique (μ : Measure G) [SigmaFinite μ] [IsMulLeftInvariant μ]
(K₀ : PositiveCompacts G) : μ = μ K₀ • haarMeasure K₀ := by
have A : Set.Nonempty (interior (closure (K₀ : Set G))) :=
K₀.interior_nonempty.mono (interior_mono subset_closure)
have := measure_eq_div_smul μ (haarMeasure K₀)
(measure_pos_of_nonempty_interior _ A).ne' K₀.isCompact.closure.measure_ne_top
rwa [haarMeasure_closure_self, div_one, K₀.isCompact.measure_closure] at this
/-- Let `μ` be a σ-finite left invariant measure on `G`. Then `μ` is equal to the Haar measure
defined by `K₀` iff `μ K₀ = 1`. -/
@[to_additive]
theorem haarMeasure_eq_iff (K₀ : PositiveCompacts G) (μ : Measure G) [SigmaFinite μ]
[IsMulLeftInvariant μ] :
haarMeasure K₀ = μ ↔ μ K₀ = 1 :=
⟨fun h => h.symm ▸ haarMeasure_self, fun h => by rw [haarMeasure_unique μ K₀, h, one_smul]⟩
example [LocallyCompactSpace G] (μ : Measure G) [IsHaarMeasure μ] (K₀ : PositiveCompacts G) :
μ = μ K₀.1 • haarMeasure K₀ :=
haarMeasure_unique μ K₀
/-- To show that an invariant σ-finite measure is regular it is sufficient to show that it is finite
on some compact set with non-empty interior. -/
@[to_additive
"To show that an invariant σ-finite measure is regular it is sufficient to show that it is finite on
some compact set with non-empty interior."]
theorem regular_of_isMulLeftInvariant {μ : Measure G} [SigmaFinite μ] [IsMulLeftInvariant μ]
{K : Set G} (hK : IsCompact K) (h2K : (interior K).Nonempty) (hμK : μ K ≠ ∞) : Regular μ := by
rw [haarMeasure_unique μ ⟨⟨K, hK⟩, h2K⟩]; exact Regular.smul hμK
end SecondCountable_SigmaFinite
end Group
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Haar\Disintegration.lean | /-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Pushing a Haar measure by a linear map
We show that the push-forward of an additive Haar measure in a vector space under a surjective
linear map is proportional to the Haar measure on the target space,
in `LinearMap.exists_map_addHaar_eq_smul_addHaar`.
We deduce disintegration properties of the Haar measure: to check that a property is true ae,
it suffices to check that it is true ae along all translates of a given vector subspace.
See `MeasureTheory.ae_mem_of_ae_add_linearMap_mem`.
TODO: this holds more generally in any locally compact group, see
[Fremlin, *Measure Theory* (volume 4, 443Q)][fremlin_vol4]
-/
open MeasureTheory Measure Set
open scoped ENNReal
variable {𝕜 E F : Type*}
[NontriviallyNormedField 𝕜] [CompleteSpace 𝕜]
[NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] [NormedSpace 𝕜 E]
[NormedAddCommGroup F] [MeasurableSpace F] [BorelSpace F] [NormedSpace 𝕜 F] {L : E →ₗ[𝕜] F}
{μ : Measure E} {ν : Measure F}
[IsAddHaarMeasure μ] [IsAddHaarMeasure ν]
variable [LocallyCompactSpace E]
variable (L μ ν)
/-- The image of an additive Haar measure under a surjective linear map is proportional to a given
additive Haar measure. The proportionality factor will be infinite if the linear map has a
nontrivial kernel. -/
theorem LinearMap.exists_map_addHaar_eq_smul_addHaar' (h : Function.Surjective L) :
∃ (c : ℝ≥0∞), 0 < c ∧ c < ∞ ∧ μ.map L = (c * addHaar (univ : Set (LinearMap.ker L))) • ν := by
/- This is true for the second projection in product spaces, as the projection of the Haar
measure `μS.prod μT` is equal to the Haar measure `μT` multiplied by the total mass of `μS`. This
is also true for linear equivalences, as they map Haar measure to Haar measure. The general case
follows from these two and linear algebra, as `L` can be interpreted as the composition of the
projection `P` on a complement `T` to its kernel `S`, together with a linear equivalence. -/
have : ProperSpace E := .of_locallyCompactSpace 𝕜
have : FiniteDimensional 𝕜 E := .of_locallyCompactSpace 𝕜
have : ProperSpace F := by
rcases subsingleton_or_nontrivial E with hE|hE
· have : Subsingleton F := Function.Surjective.subsingleton h
infer_instance
· have : ProperSpace 𝕜 := .of_locallyCompact_module 𝕜 E
have : FiniteDimensional 𝕜 F := Module.Finite.of_surjective L h
exact FiniteDimensional.proper 𝕜 F
let S : Submodule 𝕜 E := LinearMap.ker L
obtain ⟨T, hT⟩ : ∃ T : Submodule 𝕜 E, IsCompl S T := Submodule.exists_isCompl S
let M : (S × T) ≃ₗ[𝕜] E := Submodule.prodEquivOfIsCompl S T hT
have M_cont : Continuous M.symm := LinearMap.continuous_of_finiteDimensional _
let P : S × T →ₗ[𝕜] T := LinearMap.snd 𝕜 S T
have P_cont : Continuous P := LinearMap.continuous_of_finiteDimensional _
have I : Function.Bijective (LinearMap.domRestrict L T) :=
⟨LinearMap.injective_domRestrict_iff.2 (IsCompl.inf_eq_bot hT.symm),
(LinearMap.surjective_domRestrict_iff h).2 hT.symm.sup_eq_top⟩
let L' : T ≃ₗ[𝕜] F := LinearEquiv.ofBijective (LinearMap.domRestrict L T) I
have L'_cont : Continuous L' := LinearMap.continuous_of_finiteDimensional _
have A : L = (L' : T →ₗ[𝕜] F).comp (P.comp (M.symm : E →ₗ[𝕜] (S × T))) := by
ext x
obtain ⟨y, z, hyz⟩ : ∃ (y : S) (z : T), M.symm x = (y, z) := ⟨_, _, rfl⟩
have : x = M (y, z) := by
rw [← hyz]; simp only [LinearEquiv.apply_symm_apply]
simp [L', P, M, this]
have I : μ.map L = ((μ.map M.symm).map P).map L' := by
rw [Measure.map_map, Measure.map_map, A]
· rfl
· exact L'_cont.measurable.comp P_cont.measurable
· exact M_cont.measurable
· exact L'_cont.measurable
· exact P_cont.measurable
let μS : Measure S := addHaar
let μT : Measure T := addHaar
obtain ⟨c₀, c₀_pos, c₀_fin, h₀⟩ :
∃ c₀ : ℝ≥0∞, c₀ ≠ 0 ∧ c₀ ≠ ∞ ∧ μ.map M.symm = c₀ • μS.prod μT := by
have : IsAddHaarMeasure (μ.map M.symm) :=
M.toContinuousLinearEquiv.symm.isAddHaarMeasure_map μ
refine ⟨addHaarScalarFactor (μ.map M.symm) (μS.prod μT), ?_, ENNReal.coe_ne_top,
isAddLeftInvariant_eq_smul _ _⟩
simpa only [ne_eq, ENNReal.coe_eq_zero] using
(addHaarScalarFactor_pos_of_isAddHaarMeasure (μ.map M.symm) (μS.prod μT)).ne'
have J : (μS.prod μT).map P = (μS univ) • μT := map_snd_prod
obtain ⟨c₁, c₁_pos, c₁_fin, h₁⟩ : ∃ c₁ : ℝ≥0∞, c₁ ≠ 0 ∧ c₁ ≠ ∞ ∧ μT.map L' = c₁ • ν := by
have : IsAddHaarMeasure (μT.map L') :=
L'.toContinuousLinearEquiv.isAddHaarMeasure_map μT
refine ⟨addHaarScalarFactor (μT.map L') ν, ?_, ENNReal.coe_ne_top,
isAddLeftInvariant_eq_smul _ _⟩
simpa only [ne_eq, ENNReal.coe_eq_zero] using
(addHaarScalarFactor_pos_of_isAddHaarMeasure (μT.map L') ν).ne'
refine ⟨c₀ * c₁, by simp [pos_iff_ne_zero, c₀_pos, c₁_pos], ENNReal.mul_lt_top c₀_fin c₁_fin, ?_⟩
simp only [I, h₀, Measure.map_smul, J, smul_smul, h₁]
rw [mul_assoc, mul_comm _ c₁, ← mul_assoc]
/-- The image of an additive Haar measure under a surjective linear map is proportional to a given
additive Haar measure, with a positive (but maybe infinite) factor. -/
theorem LinearMap.exists_map_addHaar_eq_smul_addHaar (h : Function.Surjective L) :
∃ (c : ℝ≥0∞), 0 < c ∧ μ.map L = c • ν := by
rcases L.exists_map_addHaar_eq_smul_addHaar' μ ν h with ⟨c, c_pos, -, hc⟩
exact ⟨_, by simp [c_pos, NeZero.ne addHaar], hc⟩
namespace MeasureTheory
/-- Given a surjective linear map `L`, it is equivalent to require a property almost everywhere
in the source or the target spaces of `L`, with respect to additive Haar measures there. -/
lemma ae_comp_linearMap_mem_iff (h : Function.Surjective L) {s : Set F} (hs : MeasurableSet s) :
(∀ᵐ x ∂μ, L x ∈ s) ↔ ∀ᵐ y ∂ν, y ∈ s := by
have : FiniteDimensional 𝕜 E := .of_locallyCompactSpace 𝕜
have : AEMeasurable L μ := L.continuous_of_finiteDimensional.aemeasurable
apply (ae_map_iff this hs).symm.trans
rcases L.exists_map_addHaar_eq_smul_addHaar μ ν h with ⟨c, c_pos, hc⟩
rw [hc]
exact ae_smul_measure_iff c_pos.ne'
/-- Given a linear map `L : E → F`, a property holds almost everywhere in `F` if and only if,
almost everywhere in `F`, it holds almost everywhere along the subspace spanned by the
image of `L`. This is an instance of a disintegration argument for additive Haar measures. -/
lemma ae_ae_add_linearMap_mem_iff [LocallyCompactSpace F] {s : Set F} (hs : MeasurableSet s) :
(∀ᵐ y ∂ν, ∀ᵐ x ∂μ, y + L x ∈ s) ↔ ∀ᵐ y ∂ν, y ∈ s := by
have : FiniteDimensional 𝕜 E := .of_locallyCompactSpace 𝕜
have : FiniteDimensional 𝕜 F := .of_locallyCompactSpace 𝕜
have : ProperSpace E := .of_locallyCompactSpace 𝕜
have : ProperSpace F := .of_locallyCompactSpace 𝕜
let M : F × E →ₗ[𝕜] F := LinearMap.id.coprod L
have M_cont : Continuous M := M.continuous_of_finiteDimensional
-- Note: #8386 had to change `range_eq_top` into `range_eq_top (f := _)`
have hM : Function.Surjective M := by
simp [M, ← LinearMap.range_eq_top (f := _), LinearMap.range_coprod]
have A : ∀ x, M x ∈ s ↔ x ∈ M ⁻¹' s := fun x ↦ Iff.rfl
simp_rw [← ae_comp_linearMap_mem_iff M (ν.prod μ) ν hM hs, A]
rw [Measure.ae_prod_mem_iff_ae_ae_mem]
· simp only [M, mem_preimage, LinearMap.coprod_apply, LinearMap.id_coe, id_eq]
· exact M_cont.measurable hs
/-- To check that a property holds almost everywhere with respect to an additive Haar measure, it
suffices to check it almost everywhere along all translates of a given vector subspace. This is an
instance of a disintegration argument for additive Haar measures. -/
lemma ae_mem_of_ae_add_linearMap_mem [LocallyCompactSpace F] {s : Set F} (hs : MeasurableSet s)
(h : ∀ y, ∀ᵐ x ∂μ, y + L x ∈ s) : ∀ᵐ y ∂ν, y ∈ s :=
(ae_ae_add_linearMap_mem_iff L μ ν hs).1 (Filter.eventually_of_forall h)
end MeasureTheory
|
MeasureTheory\Measure\Haar\InnerProductSpace.lean | /-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.InnerProductSpace.Orientation
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
/-!
# Volume forms and measures on inner product spaces
A volume form induces a Lebesgue measure on general finite-dimensional real vector spaces. In this
file, we discuss the specific situation of inner product spaces, where an orientation gives
rise to a canonical volume form. We show that the measure coming from this volume form gives
measure `1` to the parallelepiped spanned by any orthonormal basis, and that it coincides with
the canonical `volume` from the `MeasureSpace` instance.
-/
open FiniteDimensional MeasureTheory MeasureTheory.Measure Set
variable {ι E F : Type*}
variable [Fintype ι] [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F]
[MeasurableSpace F] [BorelSpace F]
section
variable {m n : ℕ} [_i : Fact (finrank ℝ F = n)]
/-- The volume form coming from an orientation in an inner product space gives measure `1` to the
parallelepiped associated to any orthonormal basis. This is a rephrasing of
`abs_volumeForm_apply_of_orthonormal` in terms of measures. -/
theorem Orientation.measure_orthonormalBasis (o : Orientation ℝ F (Fin n))
(b : OrthonormalBasis ι ℝ F) : o.volumeForm.measure (parallelepiped b) = 1 := by
have e : ι ≃ Fin n := by
refine Fintype.equivFinOfCardEq ?_
rw [← _i.out, finrank_eq_card_basis b.toBasis]
have A : ⇑b = b.reindex e ∘ e := by
ext x
simp only [OrthonormalBasis.coe_reindex, Function.comp_apply, Equiv.symm_apply_apply]
rw [A, parallelepiped_comp_equiv, AlternatingMap.measure_parallelepiped,
o.abs_volumeForm_apply_of_orthonormal, ENNReal.ofReal_one]
/-- In an oriented inner product space, the measure coming from the canonical volume form
associated to an orientation coincides with the volume. -/
theorem Orientation.measure_eq_volume (o : Orientation ℝ F (Fin n)) :
o.volumeForm.measure = volume := by
have A : o.volumeForm.measure (stdOrthonormalBasis ℝ F).toBasis.parallelepiped = 1 :=
Orientation.measure_orthonormalBasis o (stdOrthonormalBasis ℝ F)
rw [addHaarMeasure_unique o.volumeForm.measure
(stdOrthonormalBasis ℝ F).toBasis.parallelepiped, A, one_smul]
simp only [volume, Basis.addHaar]
end
/-- The volume measure in a finite-dimensional inner product space gives measure `1` to the
parallelepiped spanned by any orthonormal basis. -/
theorem OrthonormalBasis.volume_parallelepiped (b : OrthonormalBasis ι ℝ F) :
volume (parallelepiped b) = 1 := by
haveI : Fact (finrank ℝ F = finrank ℝ F) := ⟨rfl⟩
let o := (stdOrthonormalBasis ℝ F).toBasis.orientation
rw [← o.measure_eq_volume]
exact o.measure_orthonormalBasis b
/-- The Haar measure defined by any orthonormal basis of a finite-dimensional inner product space
is equal to its volume measure. -/
theorem OrthonormalBasis.addHaar_eq_volume {ι F : Type*} [Fintype ι] [NormedAddCommGroup F]
[InnerProductSpace ℝ F] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F]
(b : OrthonormalBasis ι ℝ F) :
b.toBasis.addHaar = volume := by
rw [Basis.addHaar_eq_iff]
exact b.volume_parallelepiped
/-- An orthonormal basis of a finite-dimensional inner product space defines a measurable
equivalence between the space and the Euclidean space of the same dimension. -/
noncomputable def OrthonormalBasis.measurableEquiv (b : OrthonormalBasis ι ℝ F) :
F ≃ᵐ EuclideanSpace ℝ ι := b.repr.toHomeomorph.toMeasurableEquiv
/-- The measurable equivalence defined by an orthonormal basis is volume preserving. -/
theorem OrthonormalBasis.measurePreserving_measurableEquiv (b : OrthonormalBasis ι ℝ F) :
MeasurePreserving b.measurableEquiv volume volume := by
convert (b.measurableEquiv.symm.measurable.measurePreserving _).symm
rw [← (EuclideanSpace.basisFun ι ℝ).addHaar_eq_volume]
erw [MeasurableEquiv.coe_toEquiv_symm, Basis.map_addHaar _ b.repr.symm.toContinuousLinearEquiv]
exact b.addHaar_eq_volume.symm
theorem OrthonormalBasis.measurePreserving_repr (b : OrthonormalBasis ι ℝ F) :
MeasurePreserving b.repr volume volume := b.measurePreserving_measurableEquiv
theorem OrthonormalBasis.measurePreserving_repr_symm (b : OrthonormalBasis ι ℝ F) :
MeasurePreserving b.repr.symm volume volume := b.measurePreserving_measurableEquiv.symm
section PiLp
variable (ι : Type*) [Fintype ι]
/-- The measure equivalence between `EuclideanSpace ℝ ι` and `ι → ℝ` is volume preserving. -/
theorem EuclideanSpace.volume_preserving_measurableEquiv :
MeasurePreserving (EuclideanSpace.measurableEquiv ι) := by
suffices volume = map (EuclideanSpace.measurableEquiv ι).symm volume by
convert ((EuclideanSpace.measurableEquiv ι).symm.measurable.measurePreserving _).symm
rw [← addHaarMeasure_eq_volume_pi, ← Basis.parallelepiped_basisFun, ← Basis.addHaar_def,
coe_measurableEquiv_symm, ← PiLp.continuousLinearEquiv_symm_apply 2 ℝ, Basis.map_addHaar]
exact (EuclideanSpace.basisFun _ _).addHaar_eq_volume.symm
/-- A copy of `EuclideanSpace.volume_preserving_measurableEquiv` for the canonical spelling of the
equivalence. -/
theorem PiLp.volume_preserving_equiv : MeasurePreserving (WithLp.equiv 2 (ι → ℝ)) :=
EuclideanSpace.volume_preserving_measurableEquiv ι
/-- The reverse direction of `PiLp.volume_preserving_measurableEquiv`, since
`MeasurePreserving.symm` only works for `MeasurableEquiv`s. -/
theorem PiLp.volume_preserving_equiv_symm : MeasurePreserving (WithLp.equiv 2 (ι → ℝ)).symm :=
(EuclideanSpace.volume_preserving_measurableEquiv ι).symm
lemma volume_euclideanSpace_eq_dirac [IsEmpty ι] :
(volume : Measure (EuclideanSpace ℝ ι)) = Measure.dirac 0 := by
rw [← ((EuclideanSpace.volume_preserving_measurableEquiv ι).symm).map_eq,
volume_pi_eq_dirac 0, map_dirac (MeasurableEquiv.measurable _),
EuclideanSpace.coe_measurableEquiv_symm, WithLp.equiv_symm_zero]
end PiLp
namespace LinearIsometryEquiv
variable [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
[MeasurableSpace E] [BorelSpace E]
variable (f : E ≃ₗᵢ[ℝ] F)
/-- Every linear isometry on a real finite dimensional Hilbert space is measure-preserving. -/
theorem measurePreserving : MeasurePreserving f := by
refine ⟨f.continuous.measurable, ?_⟩
rcases exists_orthonormalBasis ℝ E with ⟨w, b, _hw⟩
erw [← OrthonormalBasis.addHaar_eq_volume b, ← OrthonormalBasis.addHaar_eq_volume (b.map f),
Basis.map_addHaar _ f.toContinuousLinearEquiv]
congr
/-- Every linear isometry equivalence is a measurable equivalence. -/
def toMeasureEquiv : E ≃ᵐ F where
toEquiv := f
measurable_toFun := f.continuous.measurable
measurable_invFun := f.symm.continuous.measurable
@[simp] theorem coe_toMeasureEquiv : (f.toMeasureEquiv : E → F) = f := rfl
theorem toMeasureEquiv_symm : f.toMeasureEquiv.symm = f.symm.toMeasureEquiv := rfl
end LinearIsometryEquiv
|
MeasureTheory\Measure\Haar\NormedSpace.lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
import Mathlib.MeasureTheory.Integral.SetIntegral
/-!
# Basic properties of Haar measures on real vector spaces
-/
noncomputable section
open scoped NNReal ENNReal Pointwise Topology
open Inv Set Function MeasureTheory.Measure Filter
open FiniteDimensional
namespace MeasureTheory
namespace Measure
/- The instance `MeasureTheory.Measure.IsAddHaarMeasure.noAtoms` applies in particular to show that
an additive Haar measure on a nontrivial finite-dimensional real vector space has no atom. -/
example {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Nontrivial E] [FiniteDimensional ℝ E]
[MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] : NoAtoms μ := by
infer_instance
section ContinuousLinearEquiv
variable {𝕜 G H : Type*} [MeasurableSpace G] [MeasurableSpace H] [NontriviallyNormedField 𝕜]
[TopologicalSpace G] [TopologicalSpace H] [AddCommGroup G] [AddCommGroup H]
[TopologicalAddGroup G] [TopologicalAddGroup H] [Module 𝕜 G] [Module 𝕜 H] (μ : Measure G)
[IsAddHaarMeasure μ] [BorelSpace G] [BorelSpace H] [T2Space H]
instance MapContinuousLinearEquiv.isAddHaarMeasure (e : G ≃L[𝕜] H) : IsAddHaarMeasure (μ.map e) :=
e.toAddEquiv.isAddHaarMeasure_map _ e.continuous e.symm.continuous
variable [CompleteSpace 𝕜] [T2Space G] [FiniteDimensional 𝕜 G] [ContinuousSMul 𝕜 G]
[ContinuousSMul 𝕜 H]
instance MapLinearEquiv.isAddHaarMeasure (e : G ≃ₗ[𝕜] H) : IsAddHaarMeasure (μ.map e) :=
MapContinuousLinearEquiv.isAddHaarMeasure _ e.toContinuousLinearEquiv
end ContinuousLinearEquiv
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {F : Type*} [NormedAddCommGroup F]
[NormedSpace ℝ F]
variable {s : Set E}
/-- The integral of `f (R • x)` with respect to an additive Haar measure is a multiple of the
integral of `f`. The formula we give works even when `f` is not integrable or `R = 0`
thanks to the convention that a non-integrable function has integral zero. -/
theorem integral_comp_smul (f : E → F) (R : ℝ) :
∫ x, f (R • x) ∂μ = |(R ^ finrank ℝ E)⁻¹| • ∫ x, f x ∂μ := by
by_cases hF : CompleteSpace F; swap
· simp [integral, hF]
rcases eq_or_ne R 0 with (rfl | hR)
· simp only [zero_smul, integral_const]
rcases Nat.eq_zero_or_pos (finrank ℝ E) with (hE | hE)
· have : Subsingleton E := finrank_zero_iff.1 hE
have : f = fun _ => f 0 := by ext x; rw [Subsingleton.elim x 0]
conv_rhs => rw [this]
simp only [hE, pow_zero, inv_one, abs_one, one_smul, integral_const]
· have : Nontrivial E := finrank_pos_iff.1 hE
simp only [zero_pow hE.ne', measure_univ_of_isAddLeftInvariant, ENNReal.top_toReal, zero_smul,
inv_zero, abs_zero]
· calc
(∫ x, f (R • x) ∂μ) = ∫ y, f y ∂Measure.map (fun x => R • x) μ :=
(integral_map_equiv (Homeomorph.smul (isUnit_iff_ne_zero.2 hR).unit).toMeasurableEquiv
f).symm
_ = |(R ^ finrank ℝ E)⁻¹| • ∫ x, f x ∂μ := by
simp only [map_addHaar_smul μ hR, integral_smul_measure, ENNReal.toReal_ofReal, abs_nonneg]
/-- The integral of `f (R • x)` with respect to an additive Haar measure is a multiple of the
integral of `f`. The formula we give works even when `f` is not integrable or `R = 0`
thanks to the convention that a non-integrable function has integral zero. -/
theorem integral_comp_smul_of_nonneg (f : E → F) (R : ℝ) {hR : 0 ≤ R} :
∫ x, f (R • x) ∂μ = (R ^ finrank ℝ E)⁻¹ • ∫ x, f x ∂μ := by
rw [integral_comp_smul μ f R, abs_of_nonneg (inv_nonneg.2 (pow_nonneg hR _))]
/-- The integral of `f (R⁻¹ • x)` with respect to an additive Haar measure is a multiple of the
integral of `f`. The formula we give works even when `f` is not integrable or `R = 0`
thanks to the convention that a non-integrable function has integral zero. -/
theorem integral_comp_inv_smul (f : E → F) (R : ℝ) :
∫ x, f (R⁻¹ • x) ∂μ = |R ^ finrank ℝ E| • ∫ x, f x ∂μ := by
rw [integral_comp_smul μ f R⁻¹, inv_pow, inv_inv]
/-- The integral of `f (R⁻¹ • x)` with respect to an additive Haar measure is a multiple of the
integral of `f`. The formula we give works even when `f` is not integrable or `R = 0`
thanks to the convention that a non-integrable function has integral zero. -/
theorem integral_comp_inv_smul_of_nonneg (f : E → F) {R : ℝ} (hR : 0 ≤ R) :
∫ x, f (R⁻¹ • x) ∂μ = R ^ finrank ℝ E • ∫ x, f x ∂μ := by
rw [integral_comp_inv_smul μ f R, abs_of_nonneg (pow_nonneg hR _)]
theorem setIntegral_comp_smul (f : E → F) {R : ℝ} (s : Set E) (hR : R ≠ 0) :
∫ x in s, f (R • x) ∂μ = |(R ^ finrank ℝ E)⁻¹| • ∫ x in R • s, f x ∂μ := by
let e : E ≃ᵐ E := (Homeomorph.smul (Units.mk0 R hR)).toMeasurableEquiv
calc
∫ x in s, f (R • x) ∂μ
= ∫ x in e ⁻¹' (e.symm ⁻¹' s), f (e x) ∂μ := by simp [← preimage_comp]; rfl
_ = ∫ y in e.symm ⁻¹' s, f y ∂map (fun x ↦ R • x) μ := (setIntegral_map_equiv _ _ _).symm
_ = |(R ^ finrank ℝ E)⁻¹| • ∫ y in e.symm ⁻¹' s, f y ∂μ := by
simp [map_addHaar_smul μ hR, integral_smul_measure, ENNReal.toReal_ofReal, abs_nonneg]
_ = |(R ^ finrank ℝ E)⁻¹| • ∫ x in R • s, f x ∂μ := by
congr
ext y
rw [mem_smul_set_iff_inv_smul_mem₀ hR]
rfl
@[deprecated (since := "2024-04-17")]
alias set_integral_comp_smul := setIntegral_comp_smul
theorem setIntegral_comp_smul_of_pos (f : E → F) {R : ℝ} (s : Set E) (hR : 0 < R) :
∫ x in s, f (R • x) ∂μ = (R ^ finrank ℝ E)⁻¹ • ∫ x in R • s, f x ∂μ := by
rw [setIntegral_comp_smul μ f s hR.ne', abs_of_nonneg (inv_nonneg.2 (pow_nonneg hR.le _))]
@[deprecated (since := "2024-04-17")]
alias set_integral_comp_smul_of_pos := setIntegral_comp_smul_of_pos
theorem integral_comp_mul_left (g : ℝ → F) (a : ℝ) :
(∫ x : ℝ, g (a * x)) = |a⁻¹| • ∫ y : ℝ, g y := by
simp_rw [← smul_eq_mul, Measure.integral_comp_smul, FiniteDimensional.finrank_self, pow_one]
theorem integral_comp_inv_mul_left (g : ℝ → F) (a : ℝ) :
(∫ x : ℝ, g (a⁻¹ * x)) = |a| • ∫ y : ℝ, g y := by
simp_rw [← smul_eq_mul, Measure.integral_comp_inv_smul, FiniteDimensional.finrank_self, pow_one]
theorem integral_comp_mul_right (g : ℝ → F) (a : ℝ) :
(∫ x : ℝ, g (x * a)) = |a⁻¹| • ∫ y : ℝ, g y := by
simpa only [mul_comm] using integral_comp_mul_left g a
theorem integral_comp_inv_mul_right (g : ℝ → F) (a : ℝ) :
(∫ x : ℝ, g (x * a⁻¹)) = |a| • ∫ y : ℝ, g y := by
simpa only [mul_comm] using integral_comp_inv_mul_left g a
theorem integral_comp_div (g : ℝ → F) (a : ℝ) : (∫ x : ℝ, g (x / a)) = |a| • ∫ y : ℝ, g y :=
integral_comp_inv_mul_right g a
end Measure
variable {F : Type*} [NormedAddCommGroup F]
theorem integrable_comp_smul_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
(f : E → F) {R : ℝ} (hR : R ≠ 0) : Integrable (fun x => f (R • x)) μ ↔ Integrable f μ := by
-- reduce to one-way implication
suffices
∀ {g : E → F} (_ : Integrable g μ) {S : ℝ} (_ : S ≠ 0), Integrable (fun x => g (S • x)) μ by
refine ⟨fun hf => ?_, fun hf => this hf hR⟩
convert this hf (inv_ne_zero hR)
rw [← mul_smul, mul_inv_cancel hR, one_smul]
-- now prove
intro g hg S hS
let t := ((Homeomorph.smul (isUnit_iff_ne_zero.2 hS).unit).toMeasurableEquiv : E ≃ᵐ E)
refine (integrable_map_equiv t g).mp (?_ : Integrable g (map (S • ·) μ))
rwa [map_addHaar_smul μ hS, integrable_smul_measure _ ENNReal.ofReal_ne_top]
simpa only [Ne, ENNReal.ofReal_eq_zero, not_le, abs_pos] using inv_ne_zero (pow_ne_zero _ hS)
theorem Integrable.comp_smul {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] {μ : Measure E} [IsAddHaarMeasure μ]
{f : E → F} (hf : Integrable f μ) {R : ℝ} (hR : R ≠ 0) : Integrable (fun x => f (R • x)) μ :=
(integrable_comp_smul_iff μ f hR).2 hf
theorem integrable_comp_mul_left_iff (g : ℝ → F) {R : ℝ} (hR : R ≠ 0) :
(Integrable fun x => g (R * x)) ↔ Integrable g := by
simpa only [smul_eq_mul] using integrable_comp_smul_iff volume g hR
theorem Integrable.comp_mul_left' {g : ℝ → F} (hg : Integrable g) {R : ℝ} (hR : R ≠ 0) :
Integrable fun x => g (R * x) :=
(integrable_comp_mul_left_iff g hR).2 hg
theorem integrable_comp_mul_right_iff (g : ℝ → F) {R : ℝ} (hR : R ≠ 0) :
(Integrable fun x => g (x * R)) ↔ Integrable g := by
simpa only [mul_comm] using integrable_comp_mul_left_iff g hR
theorem Integrable.comp_mul_right' {g : ℝ → F} (hg : Integrable g) {R : ℝ} (hR : R ≠ 0) :
Integrable fun x => g (x * R) :=
(integrable_comp_mul_right_iff g hR).2 hg
theorem integrable_comp_div_iff (g : ℝ → F) {R : ℝ} (hR : R ≠ 0) :
(Integrable fun x => g (x / R)) ↔ Integrable g :=
integrable_comp_mul_right_iff g (inv_ne_zero hR)
theorem Integrable.comp_div {g : ℝ → F} (hg : Integrable g) {R : ℝ} (hR : R ≠ 0) :
Integrable fun x => g (x / R) :=
(integrable_comp_div_iff g hR).2 hg
section InnerProductSpace
variable {E' F' A : Type*}
variable [NormedAddCommGroup E'] [InnerProductSpace ℝ E'] [FiniteDimensional ℝ E']
[MeasurableSpace E'] [BorelSpace E']
variable [NormedAddCommGroup F'] [InnerProductSpace ℝ F'] [FiniteDimensional ℝ F']
[MeasurableSpace F'] [BorelSpace F']
variable (f : E' ≃ₗᵢ[ℝ] F')
variable [NormedAddCommGroup A] [NormedSpace ℝ A]
theorem integrable_comp (g : F' → A) : Integrable (g ∘ f) ↔ Integrable g :=
f.measurePreserving.integrable_comp_emb f.toMeasureEquiv.measurableEmbedding
theorem integral_comp (g : F' → A) : ∫ (x : E'), g (f x) = ∫ (y : F'), g y :=
f.measurePreserving.integral_comp' (f := f.toMeasureEquiv) g
end InnerProductSpace
end MeasureTheory
|
MeasureTheory\Measure\Haar\OfBasis.lean | /-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.Analysis.InnerProductSpace.PiL2
/-!
# Additive Haar measure constructed from a basis
Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue
measure, which gives measure `1` to the parallelepiped spanned by the basis.
## Main definitions
* `parallelepiped v` is the parallelepiped spanned by a finite family of vectors.
* `Basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with
nonempty interior.
* `Basis.addHaar` is the Lebesgue measure associated to a basis, giving measure `1` to the
corresponding parallelepiped.
In particular, we declare a `MeasureSpace` instance on any finite-dimensional inner product space,
by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent
of the basis).
-/
open Set TopologicalSpace MeasureTheory MeasureTheory.Measure FiniteDimensional
open scoped Pointwise
noncomputable section
variable {ι ι' E F : Type*}
section Fintype
variable [Fintype ι] [Fintype ι']
section AddCommGroup
variable [AddCommGroup E] [Module ℝ E] [AddCommGroup F] [Module ℝ F]
/-- The closed parallelepiped spanned by a finite family of vectors. -/
def parallelepiped (v : ι → E) : Set E :=
(fun t : ι → ℝ => ∑ i, t i • v i) '' Icc 0 1
theorem mem_parallelepiped_iff (v : ι → E) (x : E) :
x ∈ parallelepiped v ↔ ∃ t ∈ Icc (0 : ι → ℝ) 1, x = ∑ i, t i • v i := by
simp [parallelepiped, eq_comm]
theorem parallelepiped_basis_eq (b : Basis ι ℝ E) :
parallelepiped b = {x | ∀ i, b.repr x i ∈ Set.Icc 0 1} := by
classical
ext x
simp_rw [mem_parallelepiped_iff, mem_setOf_eq, b.ext_elem_iff, _root_.map_sum,
_root_.map_smul, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single, smul_eq_mul,
mul_one, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ite_true, mem_Icc,
Pi.le_def, Pi.zero_apply, Pi.one_apply, ← forall_and]
aesop
theorem image_parallelepiped (f : E →ₗ[ℝ] F) (v : ι → E) :
f '' parallelepiped v = parallelepiped (f ∘ v) := by
simp only [parallelepiped, ← image_comp]
congr 1 with t
simp only [Function.comp_apply, _root_.map_sum, LinearMap.map_smulₛₗ, RingHom.id_apply]
/-- Reindexing a family of vectors does not change their parallelepiped. -/
@[simp]
theorem parallelepiped_comp_equiv (v : ι → E) (e : ι' ≃ ι) :
parallelepiped (v ∘ e) = parallelepiped v := by
simp only [parallelepiped]
let K : (ι' → ℝ) ≃ (ι → ℝ) := Equiv.piCongrLeft' (fun _a : ι' => ℝ) e
have : Icc (0 : ι → ℝ) 1 = K '' Icc (0 : ι' → ℝ) 1 := by
rw [← Equiv.preimage_eq_iff_eq_image]
ext x
simp only [K, mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Equiv.piCongrLeft'_apply,
Pi.one_apply]
refine
⟨fun h => ⟨fun i => ?_, fun i => ?_⟩, fun h =>
⟨fun i => h.1 (e.symm i), fun i => h.2 (e.symm i)⟩⟩
· simpa only [Equiv.symm_apply_apply] using h.1 (e i)
· simpa only [Equiv.symm_apply_apply] using h.2 (e i)
rw [this, ← image_comp]
congr 1 with x
have := fun z : ι' → ℝ => e.symm.sum_comp fun i => z i • v (e i)
simp_rw [Equiv.apply_symm_apply] at this
simp_rw [Function.comp_apply, mem_image, mem_Icc, K, Equiv.piCongrLeft'_apply, this]
-- The parallelepiped associated to an orthonormal basis of `ℝ` is either `[0, 1]` or `[-1, 0]`.
theorem parallelepiped_orthonormalBasis_one_dim (b : OrthonormalBasis ι ℝ ℝ) :
parallelepiped b = Icc 0 1 ∨ parallelepiped b = Icc (-1) 0 := by
have e : ι ≃ Fin 1 := by
apply Fintype.equivFinOfCardEq
simp only [← finrank_eq_card_basis b.toBasis, finrank_self]
have B : parallelepiped (b.reindex e) = parallelepiped b := by
convert parallelepiped_comp_equiv b e.symm
ext i
simp only [OrthonormalBasis.coe_reindex]
rw [← B]
let F : ℝ → Fin 1 → ℝ := fun t => fun _i => t
have A : Icc (0 : Fin 1 → ℝ) 1 = F '' Icc (0 : ℝ) 1 := by
apply Subset.antisymm
· intro x hx
refine ⟨x 0, ⟨hx.1 0, hx.2 0⟩, ?_⟩
ext j
simp only [Subsingleton.elim j 0]
· rintro x ⟨y, hy, rfl⟩
exact ⟨fun _j => hy.1, fun _j => hy.2⟩
rcases orthonormalBasis_one_dim (b.reindex e) with (H | H)
· left
simp_rw [parallelepiped, H, A, Algebra.id.smul_eq_mul, mul_one]
simp only [Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, ← image_comp,
Function.comp_apply, image_id']
· right
simp_rw [H, parallelepiped, Algebra.id.smul_eq_mul, A]
simp only [F, Finset.univ_unique, Fin.default_eq_zero, mul_neg, mul_one, Finset.sum_neg_distrib,
Finset.sum_singleton, ← image_comp, Function.comp, image_neg, preimage_neg_Icc, neg_zero]
theorem parallelepiped_eq_sum_segment (v : ι → E) : parallelepiped v = ∑ i, segment ℝ 0 (v i) := by
ext
simp only [mem_parallelepiped_iff, Set.mem_finset_sum, Finset.mem_univ, forall_true_left,
segment_eq_image, smul_zero, zero_add, ← Set.pi_univ_Icc, Set.mem_univ_pi]
constructor
· rintro ⟨t, ht, rfl⟩
exact ⟨t • v, fun {i} => ⟨t i, ht _, by simp⟩, rfl⟩
rintro ⟨g, hg, rfl⟩
choose t ht hg using @hg
refine ⟨@t, @ht, ?_⟩
simp_rw [hg]
theorem convex_parallelepiped (v : ι → E) : Convex ℝ (parallelepiped v) := by
rw [parallelepiped_eq_sum_segment]
exact convex_sum _ fun _i _hi => convex_segment _ _
/-- A `parallelepiped` is the convex hull of its vertices -/
theorem parallelepiped_eq_convexHull (v : ι → E) :
parallelepiped v = convexHull ℝ (∑ i, {(0 : E), v i}) := by
simp_rw [convexHull_sum, convexHull_pair, parallelepiped_eq_sum_segment]
/-- The axis aligned parallelepiped over `ι → ℝ` is a cuboid. -/
theorem parallelepiped_single [DecidableEq ι] (a : ι → ℝ) :
(parallelepiped fun i => Pi.single i (a i)) = Set.uIcc 0 a := by
ext x
simp_rw [Set.uIcc, mem_parallelepiped_iff, Set.mem_Icc, Pi.le_def, ← forall_and, Pi.inf_apply,
Pi.sup_apply, ← Pi.single_smul', Pi.one_apply, Pi.zero_apply, ← Pi.smul_apply',
Finset.univ_sum_single (_ : ι → ℝ)]
constructor
· rintro ⟨t, ht, rfl⟩ i
specialize ht i
simp_rw [smul_eq_mul, Pi.mul_apply]
rcases le_total (a i) 0 with hai | hai
· rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai]
exact ⟨le_mul_of_le_one_left hai ht.2, mul_nonpos_of_nonneg_of_nonpos ht.1 hai⟩
· rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai]
exact ⟨mul_nonneg ht.1 hai, mul_le_of_le_one_left hai ht.2⟩
· intro h
refine ⟨fun i => x i / a i, fun i => ?_, funext fun i => ?_⟩
· specialize h i
rcases le_total (a i) 0 with hai | hai
· rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] at h
exact ⟨div_nonneg_of_nonpos h.2 hai, div_le_one_of_ge h.1 hai⟩
· rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] at h
exact ⟨div_nonneg h.1 hai, div_le_one_of_le h.2 hai⟩
· specialize h i
simp only [smul_eq_mul, Pi.mul_apply]
rcases eq_or_ne (a i) 0 with hai | hai
· rw [hai, inf_idem, sup_idem, ← le_antisymm_iff] at h
rw [hai, ← h, zero_div, zero_mul]
· rw [div_mul_cancel₀ _ hai]
end AddCommGroup
section NormedSpace
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F]
/-- The parallelepiped spanned by a basis, as a compact set with nonempty interior. -/
def Basis.parallelepiped (b : Basis ι ℝ E) : PositiveCompacts E where
carrier := _root_.parallelepiped b
isCompact' := IsCompact.image isCompact_Icc
(continuous_finset_sum Finset.univ fun (i : ι) (_H : i ∈ Finset.univ) =>
(continuous_apply i).smul continuous_const)
interior_nonempty' := by
suffices H : Set.Nonempty (interior (b.equivFunL.symm.toHomeomorph '' Icc 0 1)) by
dsimp only [_root_.parallelepiped]
convert H
exact (b.equivFun_symm_apply _).symm
have A : Set.Nonempty (interior (Icc (0 : ι → ℝ) 1)) := by
rw [← pi_univ_Icc, interior_pi_set (@finite_univ ι _)]
simp only [univ_pi_nonempty_iff, Pi.zero_apply, Pi.one_apply, interior_Icc, nonempty_Ioo,
zero_lt_one, imp_true_iff]
rwa [← Homeomorph.image_interior, image_nonempty]
@[simp]
theorem Basis.coe_parallelepiped (b : Basis ι ℝ E) :
(b.parallelepiped : Set E) = _root_.parallelepiped b := rfl
@[simp]
theorem Basis.parallelepiped_reindex (b : Basis ι ℝ E) (e : ι ≃ ι') :
(b.reindex e).parallelepiped = b.parallelepiped :=
PositiveCompacts.ext <|
(congr_arg _root_.parallelepiped (b.coe_reindex e)).trans (parallelepiped_comp_equiv b e.symm)
theorem Basis.parallelepiped_map (b : Basis ι ℝ E) (e : E ≃ₗ[ℝ] F) :
(b.map e).parallelepiped = b.parallelepiped.map e
(have := FiniteDimensional.of_fintype_basis b
-- Porting note: Lean cannot infer the instance above
LinearMap.continuous_of_finiteDimensional e.toLinearMap)
(have := FiniteDimensional.of_fintype_basis (b.map e)
-- Porting note: Lean cannot infer the instance above
LinearMap.isOpenMap_of_finiteDimensional _ e.surjective) :=
PositiveCompacts.ext (image_parallelepiped e.toLinearMap _).symm
set_option tactic.skipAssignedInstances false in
theorem Basis.prod_parallelepiped (v : Basis ι ℝ E) (w : Basis ι' ℝ F) :
(v.prod w).parallelepiped = v.parallelepiped.prod w.parallelepiped := by
ext x
simp only [Basis.coe_parallelepiped, TopologicalSpace.PositiveCompacts.coe_prod, Set.mem_prod,
mem_parallelepiped_iff]
constructor
· intro h
rcases h with ⟨t, ht1, ht2⟩
constructor
· use t ∘ Sum.inl
constructor
· exact ⟨(ht1.1 <| Sum.inl ·), (ht1.2 <| Sum.inl ·)⟩
simp [ht2, Prod.fst_sum, Prod.snd_sum]
· use t ∘ Sum.inr
constructor
· exact ⟨(ht1.1 <| Sum.inr ·), (ht1.2 <| Sum.inr ·)⟩
simp [ht2, Prod.fst_sum, Prod.snd_sum]
intro h
rcases h with ⟨⟨t, ht1, ht2⟩, ⟨s, hs1, hs2⟩⟩
use Sum.elim t s
constructor
· constructor
· change ∀ x : ι ⊕ ι', 0 ≤ Sum.elim t s x
aesop
· change ∀ x : ι ⊕ ι', Sum.elim t s x ≤ 1
aesop
ext
· simp [ht2, Prod.fst_sum]
· simp [hs2, Prod.snd_sum]
variable [MeasurableSpace E] [BorelSpace E]
/-- The Lebesgue measure associated to a basis, giving measure `1` to the parallelepiped spanned
by the basis. -/
irreducible_def Basis.addHaar (b : Basis ι ℝ E) : Measure E :=
Measure.addHaarMeasure b.parallelepiped
instance IsAddHaarMeasure_basis_addHaar (b : Basis ι ℝ E) : IsAddHaarMeasure b.addHaar := by
rw [Basis.addHaar]; exact Measure.isAddHaarMeasure_addHaarMeasure _
instance (b : Basis ι ℝ E) : SigmaFinite b.addHaar := by
have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis b
rw [Basis.addHaar_def]; exact sigmaFinite_addHaarMeasure
/-- Let `μ` be a σ-finite left invariant measure on `E`. Then `μ` is equal to the Haar measure
defined by `b` iff the parallelepiped defined by `b` has measure `1` for `μ`. -/
theorem Basis.addHaar_eq_iff [SecondCountableTopology E] (b : Basis ι ℝ E) (μ : Measure E)
[SigmaFinite μ] [IsAddLeftInvariant μ] :
b.addHaar = μ ↔ μ b.parallelepiped = 1 := by
rw [Basis.addHaar_def]
exact addHaarMeasure_eq_iff b.parallelepiped μ
@[simp]
theorem Basis.addHaar_reindex (b : Basis ι ℝ E) (e : ι ≃ ι') :
(b.reindex e).addHaar = b.addHaar := by
rw [Basis.addHaar, b.parallelepiped_reindex e, ← Basis.addHaar]
theorem Basis.addHaar_self (b : Basis ι ℝ E) : b.addHaar (_root_.parallelepiped b) = 1 := by
rw [Basis.addHaar]; exact addHaarMeasure_self
variable [MeasurableSpace F] [BorelSpace F] [SecondCountableTopologyEither E F]
theorem Basis.prod_addHaar (v : Basis ι ℝ E) (w : Basis ι' ℝ F) :
(v.prod w).addHaar = v.addHaar.prod w.addHaar := by
have : FiniteDimensional ℝ E := FiniteDimensional.of_fintype_basis v
have : FiniteDimensional ℝ F := FiniteDimensional.of_fintype_basis w
simp [(v.prod w).addHaar_eq_iff, Basis.prod_parallelepiped, Basis.addHaar_self]
end NormedSpace
end Fintype
/-- A finite dimensional inner product space has a canonical measure, the Lebesgue measure giving
volume `1` to the parallelepiped spanned by any orthonormal basis. We define the measure using
some arbitrary choice of orthonormal basis. The fact that it works with any orthonormal basis
is proved in `orthonormalBasis.volume_parallelepiped`. -/
instance (priority := 100) measureSpaceOfInnerProductSpace [NormedAddCommGroup E]
[InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] :
MeasureSpace E where volume := (stdOrthonormalBasis ℝ E).toBasis.addHaar
instance [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
[MeasurableSpace E] [BorelSpace E] : IsAddHaarMeasure (volume : Measure E) :=
IsAddHaarMeasure_basis_addHaar _
/- This instance should not be necessary, but Lean has difficulties to find it in product
situations if we do not declare it explicitly. -/
instance Real.measureSpace : MeasureSpace ℝ := by infer_instance
/-! # Miscellaneous instances for `EuclideanSpace`
In combination with `measureSpaceOfInnerProductSpace`, these put a `MeasureSpace` structure
on `EuclideanSpace`. -/
namespace EuclideanSpace
variable (ι)
-- TODO: do we want these instances for `PiLp` too?
instance : MeasurableSpace (EuclideanSpace ℝ ι) := MeasurableSpace.pi
instance [Finite ι] : BorelSpace (EuclideanSpace ℝ ι) := Pi.borelSpace
/-- `WithLp.equiv` as a `MeasurableEquiv`. -/
@[simps toEquiv]
protected def measurableEquiv : EuclideanSpace ℝ ι ≃ᵐ (ι → ℝ) where
toEquiv := WithLp.equiv _ _
measurable_toFun := measurable_id
measurable_invFun := measurable_id
theorem coe_measurableEquiv : ⇑(EuclideanSpace.measurableEquiv ι) = WithLp.equiv 2 _ := rfl
theorem coe_measurableEquiv_symm :
⇑(EuclideanSpace.measurableEquiv ι).symm = (WithLp.equiv 2 _).symm := rfl
end EuclideanSpace
|
MeasureTheory\Measure\Haar\Quotient.lean | /-
Copyright (c) 2022 Alex Kontorovich and Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth
-/
import Mathlib.Algebra.Group.Opposite
import Mathlib.MeasureTheory.Constructions.Polish.Basic
import Mathlib.MeasureTheory.Group.FundamentalDomain
import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.MeasureTheory.Measure.Haar.Basic
/-!
# Haar quotient measure
In this file, we consider properties of fundamental domains and measures for the action of a
subgroup `Γ` of a topological group `G` on `G` itself. Let `μ` be a measure on `G ⧸ Γ`.
## Main results
* `MeasureTheory.QuotientMeasureEqMeasurePreimage.smulInvariantMeasure_quotient`: If `μ` satisfies
`QuotientMeasureEqMeasurePreimage` relative to a both left- and right-invariant measure on `G`,
then it is a `G` invariant measure on `G ⧸ Γ`.
The next two results assume that `Γ` is normal, and that `G` is equipped with a left- and
right-invariant measure.
* `MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient`: If `μ` satisfies
`QuotientMeasureEqMeasurePreimage`, then `μ` is a left-invariant measure.
* `MeasureTheory.leftInvariantIsQuotientMeasureEqMeasurePreimage`: If `μ` is left-invariant, and
the action of `Γ` on `G` has finite covolume, and `μ` satisfies the right scaling condition, then
it satisfies `QuotientMeasureEqMeasurePreimage`. This is a converse to
`MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient`.
The last result assumes that `G` is locally compact, that `Γ` is countable and normal, that its
action on `G` has a fundamental domain, and that `μ` is a finite measure. We also assume that `G`
is equipped with a sigma-finite Haar measure.
* `MeasureTheory.QuotientMeasureEqMeasurePreimage.haarMeasure_quotient`: If `μ` satisfies
`QuotientMeasureEqMeasurePreimage`, then it is itself Haar. This is a variant of
`MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient`.
Note that a group `G` with Haar measure that is both left and right invariant is called
**unimodular**.
-/
open Set MeasureTheory TopologicalSpace MeasureTheory.Measure
open scoped Pointwise NNReal ENNReal
section
/-- Measurability of the action of the topological group `G` on the left-coset space `G / Γ`. -/
@[to_additive "Measurability of the action of the additive topological group `G` on the left-coset
space `G / Γ`."]
instance QuotientGroup.measurableSMul {G : Type*} [Group G] {Γ : Subgroup G} [MeasurableSpace G]
[TopologicalSpace G] [TopologicalGroup G] [BorelSpace G] [BorelSpace (G ⧸ Γ)] :
MeasurableSMul G (G ⧸ Γ) where
measurable_const_smul g := (continuous_const_smul g).measurable
measurable_smul_const x := (QuotientGroup.continuous_smul₁ x).measurable
end
section smulInvariantMeasure
variable {G : Type*} [Group G] [MeasurableSpace G] [TopologicalSpace G] [TopologicalGroup G]
[BorelSpace G] [PolishSpace G] (ν : Measure G) {Γ : Subgroup G} [Countable Γ]
[T2Space (G ⧸ Γ)] [SecondCountableTopology (G ⧸ Γ)] {μ : Measure (G ⧸ Γ)}
[QuotientMeasureEqMeasurePreimage ν μ]
local notation "π" => @QuotientGroup.mk G _ Γ
/-- If `μ` satisfies `QuotientMeasureEqMeasurePreimage` relative to a both left- and right-
invariant measure `ν` on `G`, then it is a `G` invariant measure on `G ⧸ Γ`. -/
@[to_additive]
lemma MeasureTheory.QuotientMeasureEqMeasurePreimage.smulInvariantMeasure_quotient
[IsMulLeftInvariant ν] [hasFun : HasFundamentalDomain Γ.op G ν] :
SMulInvariantMeasure G (G ⧸ Γ) μ where
measure_preimage_smul g A hA := by
have meas_π : Measurable π := continuous_quotient_mk'.measurable
obtain ⟨𝓕, h𝓕⟩ := hasFun.ExistsIsFundamentalDomain
have h𝓕_translate_fundom : IsFundamentalDomain Γ.op (g • 𝓕) ν := h𝓕.smul_of_comm g
-- TODO: why `rw` fails with both of these rewrites?
erw [h𝓕.projection_respects_measure_apply (μ := μ)
(meas_π (measurableSet_preimage (measurable_const_smul g) hA)),
h𝓕_translate_fundom.projection_respects_measure_apply (μ := μ) hA]
change ν ((π ⁻¹' _) ∩ _) = ν ((π ⁻¹' _) ∩ _)
set π_preA := π ⁻¹' A
have : π ⁻¹' ((fun x : G ⧸ Γ => g • x) ⁻¹' A) = (g * ·) ⁻¹' π_preA := by ext1; simp [π_preA]
rw [this]
have : ν ((g * ·) ⁻¹' π_preA ∩ 𝓕) = ν (π_preA ∩ (g⁻¹ * ·) ⁻¹' 𝓕) := by
trans ν ((g * ·) ⁻¹' (π_preA ∩ (g⁻¹ * ·) ⁻¹' 𝓕))
· rw [preimage_inter]
congr 2
simp [Set.preimage]
rw [measure_preimage_mul]
rw [this, ← preimage_smul_inv]; rfl
/-- Given a subgroup `Γ` of a topological group `G` with measure `ν`, and a measure 'μ' on the
quotient `G ⧸ Γ` satisfying `QuotientMeasureEqMeasurePreimage`, the restriction
of `ν` to a fundamental domain is measure-preserving with respect to `μ`. -/
@[to_additive]
theorem measurePreserving_quotientGroup_mk_of_QuotientMeasureEqMeasurePreimage
{𝓕 : Set G} (h𝓕 : IsFundamentalDomain Γ.op 𝓕 ν) (μ : Measure (G ⧸ Γ))
[QuotientMeasureEqMeasurePreimage ν μ] :
MeasurePreserving (@QuotientGroup.mk G _ Γ) (ν.restrict 𝓕) μ :=
h𝓕.measurePreserving_quotient_mk μ
end smulInvariantMeasure
section normal
variable {G : Type*} [Group G] [MeasurableSpace G] [TopologicalSpace G] [TopologicalGroup G]
[BorelSpace G] [PolishSpace G] {Γ : Subgroup G} [Countable Γ] [Subgroup.Normal Γ]
[T2Space (G ⧸ Γ)] [SecondCountableTopology (G ⧸ Γ)] {μ : Measure (G ⧸ Γ)}
section mulInvariantMeasure
variable (ν : Measure G) [IsMulLeftInvariant ν] [IsMulRightInvariant ν]
[SigmaFinite ν]
/-- If `μ` on `G ⧸ Γ` satisfies `QuotientMeasureEqMeasurePreimage` relative to a both left- and
right-invariant measure on `G` and `Γ` is a normal subgroup, then `μ` is a left-invariant
measure. -/
@[to_additive "If `μ` on `G ⧸ Γ` satisfies `AddQuotientMeasureEqMeasurePreimage` relative to a both
left- and right-invariant measure on `G` and `Γ` is a normal subgroup, then `μ` is a
left-invariant measure."]
lemma MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient
[hasFun : HasFundamentalDomain Γ.op G ν] [QuotientMeasureEqMeasurePreimage ν μ] :
μ.IsMulLeftInvariant where
map_mul_left_eq_self x := by
ext A hA
obtain ⟨x₁, h⟩ := @Quotient.exists_rep _ (QuotientGroup.leftRel Γ) x
convert measure_preimage_smul μ x₁ A using 1
· rw [← h, Measure.map_apply (measurable_const_mul _) hA]
simp [← MulAction.Quotient.coe_smul_out', ← Quotient.mk''_eq_mk]
exact smulInvariantMeasure_quotient ν
variable [IsMulLeftInvariant μ] [SigmaFinite μ]
local notation "π" => @QuotientGroup.mk G _ Γ
/-- Assume that a measure `μ` is `IsMulLeftInvariant`, that the action of `Γ` on `G` has a
measurable fundamental domain `s` with positive finite volume, and that there is a single measurable
set `V ⊆ G ⧸ Γ` along which the pullback of `μ` and `ν` agree (so the scaling is right). Then
`μ` satisfies `QuotientMeasureEqMeasurePreimage`. The main tool of the proof is the uniqueness of
left invariant measures, if normalized by a single positive finite-measured set. -/
@[to_additive
"Assume that a measure `μ` is `IsAddLeftInvariant`, that the action of `Γ` on `G` has a
measurable fundamental domain `s` with positive finite volume, and that there is a single measurable
set `V ⊆ G ⧸ Γ` along which the pullback of `μ` and `ν` agree (so the scaling is right). Then
`μ` satisfies `AddQuotientMeasureEqMeasurePreimage`. The main tool of the proof is the uniqueness of
left invariant measures, if normalized by a single positive finite-measured set."]
theorem MeasureTheory.Measure.IsMulLeftInvariant.quotientMeasureEqMeasurePreimage_of_set {s : Set G}
(fund_dom_s : IsFundamentalDomain Γ.op s ν) {V : Set (G ⧸ Γ)}
(meas_V : MeasurableSet V) (neZeroV : μ V ≠ 0) (hV : μ V = ν (π ⁻¹' V ∩ s))
(neTopV : μ V ≠ ⊤) : QuotientMeasureEqMeasurePreimage ν μ := by
apply fund_dom_s.quotientMeasureEqMeasurePreimage
ext U _
have meas_π : Measurable (QuotientGroup.mk : G → G ⧸ Γ) := continuous_quotient_mk'.measurable
let μ' : Measure (G ⧸ Γ) := (ν.restrict s).map π
haveI has_fund : HasFundamentalDomain Γ.op G ν := ⟨⟨s, fund_dom_s⟩⟩
have i : QuotientMeasureEqMeasurePreimage ν μ' :=
fund_dom_s.quotientMeasureEqMeasurePreimage_quotientMeasure
have : μ'.IsMulLeftInvariant :=
MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient ν
suffices μ = μ' by
rw [this]
rfl
have : SigmaFinite μ' := i.sigmaFiniteQuotient
rw [measure_eq_div_smul μ' μ neZeroV neTopV, hV]
symm
suffices (μ' V / ν (QuotientGroup.mk ⁻¹' V ∩ s)) = 1 by rw [this, one_smul]
rw [Measure.map_apply meas_π meas_V, Measure.restrict_apply]
· convert ENNReal.div_self ..
· exact trans hV.symm neZeroV
· exact trans hV.symm neTopV
exact measurableSet_quotient.mp meas_V
/-- If a measure `μ` is left-invariant and satisfies the right scaling condition, then it
satisfies `QuotientMeasureEqMeasurePreimage`. -/
@[to_additive "If a measure `μ` is
left-invariant and satisfies the right scaling condition, then it satisfies
`AddQuotientMeasureEqMeasurePreimage`."]
theorem MeasureTheory.leftInvariantIsQuotientMeasureEqMeasurePreimage [IsFiniteMeasure μ]
[hasFun : HasFundamentalDomain Γ.op G ν]
(h : covolume Γ.op G ν = μ univ) : QuotientMeasureEqMeasurePreimage ν μ := by
obtain ⟨s, fund_dom_s⟩ := hasFun.ExistsIsFundamentalDomain
have finiteCovol : μ univ < ⊤ := measure_lt_top μ univ
rw [fund_dom_s.covolume_eq_volume] at h
by_cases meas_s_ne_zero : ν s = 0
· convert fund_dom_s.quotientMeasureEqMeasurePreimage_of_zero meas_s_ne_zero
rw [← @measure_univ_eq_zero, ← h, meas_s_ne_zero]
apply IsMulLeftInvariant.quotientMeasureEqMeasurePreimage_of_set (fund_dom_s := fund_dom_s)
(meas_V := MeasurableSet.univ)
· rw [← h]
exact meas_s_ne_zero
· rw [← h]
simp
· rw [← h]
convert finiteCovol.ne
end mulInvariantMeasure
section haarMeasure
variable (ν : Measure G) [SigmaFinite ν] [IsHaarMeasure ν] [IsMulRightInvariant ν]
local notation "π" => @QuotientGroup.mk G _ Γ
/-- If a measure `μ` on the quotient `G ⧸ Γ` of a group `G` by a discrete normal subgroup `Γ` having
fundamental domain, satisfies `QuotientMeasureEqMeasurePreimage` relative to a standardized choice
of Haar measure on `G`, and assuming `μ` is finite, then `μ` is itself Haar.
TODO: Is it possible to drop the assumption that `μ` is finite? -/
@[to_additive "If a measure `μ` on the quotient `G ⧸ Γ` of an additive group `G` by a discrete
normal subgroup `Γ` having fundamental domain, satisfies `AddQuotientMeasureEqMeasurePreimage`
relative to a standardized choice of Haar measure on `G`, and assuming `μ` is finite, then `μ` is
itself Haar."]
theorem MeasureTheory.QuotientMeasureEqMeasurePreimage.haarMeasure_quotient [LocallyCompactSpace G]
[QuotientMeasureEqMeasurePreimage ν μ] [i : HasFundamentalDomain Γ.op G ν]
[IsFiniteMeasure μ] : IsHaarMeasure μ := by
obtain ⟨K⟩ := PositiveCompacts.nonempty' (α := G)
let K' : PositiveCompacts (G ⧸ Γ) :=
K.map π continuous_coinduced_rng (QuotientGroup.isOpenMap_coe Γ)
haveI : IsMulLeftInvariant μ :=
MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient ν
rw [haarMeasure_unique μ K']
have finiteCovol : covolume Γ.op G ν ≠ ⊤ :=
ne_top_of_lt $ QuotientMeasureEqMeasurePreimage.covolume_ne_top μ (ν := ν)
obtain ⟨s, fund_dom_s⟩ := i
rw [fund_dom_s.covolume_eq_volume] at finiteCovol
-- TODO: why `rw` fails?
erw [fund_dom_s.projection_respects_measure_apply μ K'.isCompact.measurableSet]
apply IsHaarMeasure.smul
· intro h
haveI i' : IsOpenPosMeasure (ν : Measure G) := inferInstance
apply IsOpenPosMeasure.open_pos (interior K) (μ := ν) (self := i')
· exact isOpen_interior
· exact K.interior_nonempty
rw [← le_zero_iff,
← fund_dom_s.measure_zero_of_invariant _ (fun g ↦ QuotientGroup.sound _ _ g) h]
apply measure_mono
refine interior_subset.trans ?_
rw [QuotientGroup.coe_mk']
show (K : Set G) ⊆ π ⁻¹' (π '' K)
exact subset_preimage_image π K
· show ν (π ⁻¹' (π '' K) ∩ s) ≠ ⊤
apply ne_of_lt
refine lt_of_le_of_lt ?_ finiteCovol.lt_top
apply measure_mono
exact inter_subset_right
/-- Given a normal subgroup `Γ` of a topological group `G` with Haar measure `μ`, which is also
right-invariant, and a finite volume fundamental domain `𝓕`, the quotient map to `G ⧸ Γ`,
properly normalized, satisfies `QuotientMeasureEqMeasurePreimage`. -/
@[to_additive "Given a normal
subgroup `Γ` of an additive topological group `G` with Haar measure `μ`, which is also
right-invariant, and a finite volume fundamental domain `𝓕`, the quotient map to `G ⧸ Γ`,
properly normalized, satisfies `AddQuotientMeasureEqMeasurePreimage`."]
theorem IsFundamentalDomain.QuotientMeasureEqMeasurePreimage_HaarMeasure {𝓕 : Set G}
(h𝓕 : IsFundamentalDomain Γ.op 𝓕 ν) [IsMulLeftInvariant μ] [SigmaFinite μ]
{V : Set (G ⧸ Γ)} (hV : (interior V).Nonempty) (meas_V : MeasurableSet V)
(hμK : μ V = ν ((π ⁻¹' V) ∩ 𝓕)) (neTopV : μ V ≠ ⊤) :
QuotientMeasureEqMeasurePreimage ν μ := by
apply IsMulLeftInvariant.quotientMeasureEqMeasurePreimage_of_set (fund_dom_s := h𝓕)
(meas_V := meas_V)
· rw [hμK]
intro c_eq_zero
apply IsOpenPosMeasure.open_pos (interior (π ⁻¹' V)) (μ := ν)
· simp
· apply Set.Nonempty.mono (preimage_interior_subset_interior_preimage continuous_coinduced_rng)
apply hV.preimage'
simp
· apply measure_mono_null (h := interior_subset)
apply h𝓕.measure_zero_of_invariant (ht := fun g ↦ QuotientGroup.sound _ _ g)
exact c_eq_zero
· exact hμK
· exact neTopV
variable (K : PositiveCompacts (G ⧸ Γ))
/-- Given a normal subgroup `Γ` of a topological group `G` with Haar measure `μ`, which is also
right-invariant, and a finite volume fundamental domain `𝓕`, the quotient map to `G ⧸ Γ`,
properly normalized, satisfies `QuotientMeasureEqMeasurePreimage`. -/
@[to_additive "Given a
normal subgroup `Γ` of an additive topological group `G` with Haar measure `μ`, which is also
right-invariant, and a finite volume fundamental domain `𝓕`, the quotient map to `G ⧸ Γ`,
properly normalized, satisfies `AddQuotientMeasureEqMeasurePreimage`."]
theorem IsFundamentalDomain.QuotientMeasureEqMeasurePreimage_smulHaarMeasure {𝓕 : Set G}
(h𝓕 : IsFundamentalDomain Γ.op 𝓕 ν) (h𝓕_finite : ν 𝓕 ≠ ⊤) :
QuotientMeasureEqMeasurePreimage ν
((ν ((π ⁻¹' (K : Set (G ⧸ Γ))) ∩ 𝓕)) • haarMeasure K) := by
set c := ν ((π ⁻¹' (K : Set (G ⧸ Γ))) ∩ 𝓕)
have c_ne_top : c ≠ ∞ := by
contrapose! h𝓕_finite
have : c ≤ ν 𝓕 := measure_mono (Set.inter_subset_right)
rw [h𝓕_finite] at this
exact top_unique this
set μ := c • haarMeasure K
have hμK : μ K = c := by simp [μ, haarMeasure_self]
haveI : SigmaFinite μ := by
clear_value c
lift c to NNReal using c_ne_top
exact SMul.sigmaFinite c
apply IsFundamentalDomain.QuotientMeasureEqMeasurePreimage_HaarMeasure (h𝓕 := h𝓕)
(meas_V := K.isCompact.measurableSet) (μ := μ)
· exact K.interior_nonempty
· exact hμK
· rw [hμK]
exact c_ne_top
end haarMeasure
end normal
section UnfoldingTrick
variable {G : Type*} [Group G] [MeasurableSpace G] [TopologicalSpace G] [TopologicalGroup G]
[BorelSpace G] {μ : Measure G} {Γ : Subgroup G}
variable {𝓕 : Set G} (h𝓕 : IsFundamentalDomain Γ.op 𝓕 μ)
variable [Countable Γ] [MeasurableSpace (G ⧸ Γ)] [BorelSpace (G ⧸ Γ)]
local notation "μ_𝓕" => Measure.map (@QuotientGroup.mk G _ Γ) (μ.restrict 𝓕)
/-- The `essSup` of a function `g` on the quotient space `G ⧸ Γ` with respect to the pushforward
of the restriction, `μ_𝓕`, of a right-invariant measure `μ` to a fundamental domain `𝓕`, is the
same as the `essSup` of `g`'s lift to the universal cover `G` with respect to `μ`. -/
@[to_additive "The `essSup` of a function `g` on the additive quotient space `G ⧸ Γ` with respect
to the pushforward of the restriction, `μ_𝓕`, of a right-invariant measure `μ` to a fundamental
domain `𝓕`, is the same as the `essSup` of `g`'s lift to the universal cover `G` with respect
to `μ`."]
lemma essSup_comp_quotientGroup_mk [μ.IsMulRightInvariant] {g : G ⧸ Γ → ℝ≥0∞}
(g_ae_measurable : AEMeasurable g μ_𝓕) : essSup g μ_𝓕 = essSup (fun (x : G) ↦ g x) μ := by
have hπ : Measurable (QuotientGroup.mk : G → G ⧸ Γ) := continuous_quotient_mk'.measurable
rw [essSup_map_measure g_ae_measurable hπ.aemeasurable]
refine h𝓕.essSup_measure_restrict ?_
intro ⟨γ, hγ⟩ x
dsimp
congr 1
exact QuotientGroup.mk_mul_of_mem x hγ
/-- Given a quotient space `G ⧸ Γ` where `Γ` is `Countable`, and the restriction,
`μ_𝓕`, of a right-invariant measure `μ` on `G` to a fundamental domain `𝓕`, a set
in the quotient which has `μ_𝓕`-measure zero, also has measure zero under the
folding of `μ` under the quotient. Note that, if `Γ` is infinite, then the folded map
will take the value `∞` on any open set in the quotient! -/
@[to_additive "Given an additive quotient space `G ⧸ Γ` where `Γ` is `Countable`, and the
restriction, `μ_𝓕`, of a right-invariant measure `μ` on `G` to a fundamental domain `𝓕`, a set
in the quotient which has `μ_𝓕`-measure zero, also has measure zero under the
folding of `μ` under the quotient. Note that, if `Γ` is infinite, then the folded map
will take the value `∞` on any open set in the quotient!"]
lemma _root_.MeasureTheory.IsFundamentalDomain.absolutelyContinuous_map
[μ.IsMulRightInvariant] :
map (QuotientGroup.mk : G → G ⧸ Γ) μ ≪ map (QuotientGroup.mk : G → G ⧸ Γ) (μ.restrict 𝓕) := by
set π : G → G ⧸ Γ := QuotientGroup.mk
have meas_π : Measurable π := continuous_quotient_mk'.measurable
apply AbsolutelyContinuous.mk
intro s s_meas hs
rw [map_apply meas_π s_meas] at hs ⊢
rw [Measure.restrict_apply] at hs
· apply h𝓕.measure_zero_of_invariant _ _ hs
intro γ
ext g
rw [Set.mem_smul_set_iff_inv_smul_mem, mem_preimage, mem_preimage]
congr! 1
convert QuotientGroup.mk_mul_of_mem g (γ⁻¹).2 using 1
exact MeasurableSet.preimage s_meas meas_π
attribute [-instance] Quotient.instMeasurableSpace
/-- This is a simple version of the **Unfolding Trick**: Given a subgroup `Γ` of a group `G`, the
integral of a function `f` on `G` with respect to a right-invariant measure `μ` is equal to the
integral over the quotient `G ⧸ Γ` of the automorphization of `f`. -/
@[to_additive "This is a simple version of the **Unfolding Trick**: Given a subgroup `Γ` of an
additive group `G`, the integral of a function `f` on `G` with respect to a right-invariant
measure `μ` is equal to the integral over the quotient `G ⧸ Γ` of the automorphization of `f`."]
lemma QuotientGroup.integral_eq_integral_automorphize {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [μ.IsMulRightInvariant] {f : G → E}
(hf₁ : Integrable f μ) (hf₂ : AEStronglyMeasurable (automorphize f) μ_𝓕) :
∫ x : G, f x ∂μ = ∫ x : G ⧸ Γ, automorphize f x ∂μ_𝓕 := by
calc ∫ x : G, f x ∂μ = ∑' γ : Γ.op, ∫ x in 𝓕, f (γ • x) ∂μ :=
h𝓕.integral_eq_tsum'' f hf₁
_ = ∫ x in 𝓕, ∑' γ : Γ.op, f (γ • x) ∂μ := ?_
_ = ∫ x : G ⧸ Γ, automorphize f x ∂μ_𝓕 :=
(integral_map continuous_quotient_mk'.aemeasurable hf₂).symm
rw [integral_tsum]
· exact fun i ↦ (hf₁.1.comp_quasiMeasurePreserving
(measurePreserving_smul i μ).quasiMeasurePreserving).restrict
· rw [← h𝓕.lintegral_eq_tsum'' (fun x ↦ ‖f x‖₊)]
exact ne_of_lt hf₁.2
/-- This is the **Unfolding Trick**: Given a subgroup `Γ` of a group `G`, the integral of a
function `f` on `G` times the lift to `G` of a function `g` on the quotient `G ⧸ Γ` with respect
to a right-invariant measure `μ` on `G`, is equal to the integral over the quotient of the
automorphization of `f` times `g`. -/
lemma QuotientGroup.integral_mul_eq_integral_automorphize_mul {K : Type*} [NormedField K]
[NormedSpace ℝ K] [μ.IsMulRightInvariant] {f : G → K}
(f_ℒ_1 : Integrable f μ) {g : G ⧸ Γ → K} (hg : AEStronglyMeasurable g μ_𝓕)
(g_ℒ_infinity : essSup (fun x ↦ ↑‖g x‖₊) μ_𝓕 ≠ ∞)
(F_ae_measurable : AEStronglyMeasurable (QuotientGroup.automorphize f) μ_𝓕) :
∫ x : G, g (x : G ⧸ Γ) * (f x) ∂μ
= ∫ x : G ⧸ Γ, g x * (QuotientGroup.automorphize f x) ∂μ_𝓕 := by
let π : G → G ⧸ Γ := QuotientGroup.mk
have meas_π : Measurable π := continuous_quotient_mk'.measurable
have H₀ : QuotientGroup.automorphize ((g ∘ π) * f) = g * (QuotientGroup.automorphize f) := by
exact QuotientGroup.automorphize_smul_left f g
calc ∫ (x : G), g (π x) * (f x) ∂μ =
∫ (x : G ⧸ Γ), QuotientGroup.automorphize ((g ∘ π) * f) x ∂μ_𝓕 := ?_
_ = ∫ (x : G ⧸ Γ), g x * (QuotientGroup.automorphize f x) ∂μ_𝓕 := by simp [H₀]
have H₁ : Integrable ((g ∘ π) * f) μ := by
have : AEStronglyMeasurable (fun (x : G) ↦ g (x : (G ⧸ Γ))) μ :=
(hg.mono_ac h𝓕.absolutelyContinuous_map).comp_measurable meas_π
refine Integrable.essSup_smul f_ℒ_1 this ?_
have hg' : AEStronglyMeasurable (fun x ↦ (‖g x‖₊ : ℝ≥0∞)) μ_𝓕 :=
(ENNReal.continuous_coe.comp continuous_nnnorm).comp_aestronglyMeasurable hg
rw [← essSup_comp_quotientGroup_mk h𝓕 hg'.aemeasurable]
exact g_ℒ_infinity
have H₂ : AEStronglyMeasurable (QuotientGroup.automorphize ((g ∘ π) * f)) μ_𝓕 := by
simp_rw [H₀]
exact hg.mul F_ae_measurable
apply QuotientGroup.integral_eq_integral_automorphize h𝓕 H₁ H₂
end UnfoldingTrick
section
variable {G' : Type*} [AddGroup G'] [MeasurableSpace G'] [TopologicalSpace G']
[TopologicalAddGroup G'] [BorelSpace G']
{μ' : Measure G'}
{Γ' : AddSubgroup G'}
[Countable Γ'] [MeasurableSpace (G' ⧸ Γ')] [BorelSpace (G' ⧸ Γ')]
{𝓕' : Set G'}
local notation "μ_𝓕" => Measure.map (@QuotientAddGroup.mk G' _ Γ') (μ'.restrict 𝓕')
/-- This is the **Unfolding Trick**: Given an additive subgroup `Γ'` of an additive group `G'`, the
integral of a function `f` on `G'` times the lift to `G'` of a function `g` on the quotient
`G' ⧸ Γ'` with respect to a right-invariant measure `μ` on `G'`, is equal to the integral over
the quotient of the automorphization of `f` times `g`. -/
lemma QuotientAddGroup.integral_mul_eq_integral_automorphize_mul {K : Type*} [NormedField K]
[NormedSpace ℝ K] [μ'.IsAddRightInvariant] {f : G' → K}
(f_ℒ_1 : Integrable f μ') {g : G' ⧸ Γ' → K} (hg : AEStronglyMeasurable g μ_𝓕)
(g_ℒ_infinity : essSup (fun x ↦ (‖g x‖₊ : ℝ≥0∞)) μ_𝓕 ≠ ∞)
(F_ae_measurable : AEStronglyMeasurable (QuotientAddGroup.automorphize f) μ_𝓕)
(h𝓕 : IsAddFundamentalDomain Γ'.op 𝓕' μ') :
∫ x : G', g (x : G' ⧸ Γ') * (f x) ∂μ'
= ∫ x : G' ⧸ Γ', g x * (QuotientAddGroup.automorphize f x) ∂μ_𝓕 := by
let π : G' → G' ⧸ Γ' := QuotientAddGroup.mk
have meas_π : Measurable π := continuous_quotient_mk'.measurable
have H₀ : QuotientAddGroup.automorphize ((g ∘ π) * f) = g * (QuotientAddGroup.automorphize f) :=
by exact QuotientAddGroup.automorphize_smul_left f g
calc ∫ (x : G'), g (π x) * f x ∂μ' =
∫ (x : G' ⧸ Γ'), QuotientAddGroup.automorphize ((g ∘ π) * f) x ∂μ_𝓕 := ?_
_ = ∫ (x : G' ⧸ Γ'), g x * (QuotientAddGroup.automorphize f x) ∂μ_𝓕 := by simp [H₀]
have H₁ : Integrable ((g ∘ π) * f) μ' := by
have : AEStronglyMeasurable (fun (x : G') ↦ g (x : (G' ⧸ Γ'))) μ' :=
(hg.mono_ac h𝓕.absolutelyContinuous_map).comp_measurable meas_π
refine Integrable.essSup_smul f_ℒ_1 this ?_
have hg' : AEStronglyMeasurable (fun x ↦ (‖g x‖₊ : ℝ≥0∞)) μ_𝓕 :=
(ENNReal.continuous_coe.comp continuous_nnnorm).comp_aestronglyMeasurable hg
rw [← essSup_comp_quotientAddGroup_mk h𝓕 hg'.aemeasurable]
exact g_ℒ_infinity
have H₂ : AEStronglyMeasurable (QuotientAddGroup.automorphize ((g ∘ π) * f)) μ_𝓕 := by
simp_rw [H₀]
exact hg.mul F_ae_measurable
apply QuotientAddGroup.integral_eq_integral_automorphize h𝓕 H₁ H₂
end
attribute [to_additive existing QuotientGroup.integral_mul_eq_integral_automorphize_mul]
QuotientAddGroup.integral_mul_eq_integral_automorphize_mul
|
MeasureTheory\Measure\Haar\Unique.lean | /-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Constructions.Prod.Integral
import Mathlib.MeasureTheory.Function.LocallyIntegrable
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.Topology.Metrizable.Urysohn
import Mathlib.Topology.UrysohnsLemma
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.MeasureTheory.Measure.EverywherePos
import Mathlib.MeasureTheory.Integral.SetIntegral
/-!
# Uniqueness of Haar measure in locally compact groups
## Main results
In a locally compact group, we prove that two left-invariant measures `μ'` and `μ` which are finite
on compact sets coincide, up to a normalizing scalar that we denote with `haarScalarFactor μ' μ`,
in the following sense:
* `integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport`: they give the same value to the
integral of continuous compactly supported functions, up to a scalar.
* `measure_isMulInvariant_eq_smul_of_isCompact_closure`: they give the same value to sets with
compact closure, up to a scalar.
* `measure_isHaarMeasure_eq_smul_of_isOpen`: they give the same value to open sets, up to a scalar.
To get genuine equality of measures, we typically need additional regularity assumptions:
* `isMulLeftInvariant_eq_smul_of_innerRegular`: two left invariant measures which are
inner regular coincide up to a scalar.
* `isMulLeftInvariant_eq_smul_of_regular`: two left invariant measure which are
regular coincide up to a scalar.
* `isHaarMeasure_eq_smul`: in a second countable space, two Haar measures coincide up to a
scalar.
* `isMulInvariant_eq_smul_of_compactSpace`: two left-invariant measures on a compact group coincide
up to a scalar.
* `isHaarMeasure_eq_of_isProbabilityMeasure`: two Haar measures which are probability measures
coincide exactly.
In general, uniqueness statements for Haar measures in the literature make some assumption of
regularity, either regularity or inner regularity. We have tried to minimize the assumptions in the
theorems above, and cover the different results that exist in the literature.
## Implementation
The first result `integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport` is classical. To prove
it, we use a change of variables to express integrals with respect to a left-invariant measure as
integrals with respect to a given right-invariant measure (with a suitable density function).
The uniqueness readily follows.
Uniqueness results for the measure of compact sets and open sets, without any regularity assumption,
are significantly harder. They rely on the completion-regularity of the standard regular Haar
measure. We follow McQuillan's answer at https://mathoverflow.net/questions/456670/.
On second-countable groups, one can arrive to slightly different uniqueness results by using that
the operations are measurable. In particular, one can get uniqueness assuming σ-finiteness of
the measures but discarding the assumption that they are finite on compact sets. See
`haarMeasure_unique` in the file `MeasureTheory.Measure.Haar.Basic`.
## References
[Halmos, Measure Theory][halmos1950measure]
[Fremlin, *Measure Theory* (volume 4)][fremlin_vol4]
-/
open Filter Set TopologicalSpace Function MeasureTheory Measure
open scoped Uniformity Topology ENNReal Pointwise NNReal
/-- In a locally compact regular space with an inner regular measure, the measure of a compact
set `k` is the infimum of the integrals of compactly supported functions equal to `1` on `k`. -/
lemma IsCompact.measure_eq_biInf_integral_hasCompactSupport
{X : Type*} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X]
{k : Set X} (hk : IsCompact k)
(μ : Measure X) [IsFiniteMeasureOnCompacts μ] [InnerRegularCompactLTTop μ]
[LocallyCompactSpace X] [RegularSpace X] :
μ k = ⨅ (f : X → ℝ) (_ : Continuous f) (_ : HasCompactSupport f) (_ : EqOn f 1 k)
(_ : 0 ≤ f), ENNReal.ofReal (∫ x, f x ∂μ) := by
apply le_antisymm
· simp only [le_iInf_iff]
intro f f_cont f_comp fk f_nonneg
apply (f_cont.integrable_of_hasCompactSupport f_comp).measure_le_integral
· exact eventually_of_forall f_nonneg
· exact fun x hx ↦ by simp [fk hx]
· apply le_of_forall_lt' (fun r hr ↦ ?_)
simp only [iInf_lt_iff, exists_prop, exists_and_left]
obtain ⟨U, kU, U_open, mu_U⟩ : ∃ U, k ⊆ U ∧ IsOpen U ∧ μ U < r :=
hk.exists_isOpen_lt_of_lt r hr
obtain ⟨⟨f, f_cont⟩, fk, fU, f_comp, f_range⟩ : ∃ (f : C(X, ℝ)), EqOn f 1 k ∧ EqOn f 0 Uᶜ
∧ HasCompactSupport f ∧ ∀ (x : X), f x ∈ Icc 0 1 := exists_continuous_one_zero_of_isCompact
hk U_open.isClosed_compl (disjoint_compl_right_iff_subset.mpr kU)
refine ⟨f, f_cont, f_comp, fk, fun x ↦ (f_range x).1, ?_⟩
exact (integral_le_measure (fun x _hx ↦ (f_range x).2) (fun x hx ↦ (fU hx).le)).trans_lt mu_U
namespace MeasureTheory
/-- The parameterized integral `x ↦ ∫ y, g (y⁻¹ * x) ∂μ` depends continuously on `y` when `g` is a
compactly supported continuous function on a topological group `G`, and `μ` is finite on compact
sets. -/
@[to_additive]
lemma continuous_integral_apply_inv_mul
{G : Type*} [TopologicalSpace G] [LocallyCompactSpace G] [Group G] [TopologicalGroup G]
[MeasurableSpace G] [BorelSpace G]
{μ : Measure G} [IsFiniteMeasureOnCompacts μ] {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] {g : G → E}
(hg : Continuous g) (h'g : HasCompactSupport g) :
Continuous (fun (x : G) ↦ ∫ y, g (y⁻¹ * x) ∂μ) := by
let k := tsupport g
have k_comp : IsCompact k := h'g
apply continuous_iff_continuousAt.2 (fun x₀ ↦ ?_)
obtain ⟨t, t_comp, ht⟩ : ∃ t, IsCompact t ∧ t ∈ 𝓝 x₀ := exists_compact_mem_nhds x₀
let k' : Set G := t • k⁻¹
have k'_comp : IsCompact k' := t_comp.smul_set k_comp.inv
have A : ContinuousOn (fun (x : G) ↦ ∫ y, g (y⁻¹ * x) ∂μ) t := by
apply continuousOn_integral_of_compact_support k'_comp
· exact (hg.comp (continuous_snd.inv.mul continuous_fst)).continuousOn
· intro p x hp hx
contrapose! hx
refine ⟨p, hp, p⁻¹ * x, ?_, by simp⟩
simpa only [Set.mem_inv, mul_inv_rev, inv_inv] using subset_tsupport _ hx
exact A.continuousAt ht
namespace Measure
section Group
variable {G : Type*} [TopologicalSpace G] [Group G] [TopologicalGroup G]
[MeasurableSpace G] [BorelSpace G]
/-!
### Uniqueness of integrals of compactly supported functions
Two left invariant measures coincide when integrating continuous compactly supported functions,
up to a scalar that we denote with `haarScalarFactor μ' μ `.
This is proved by relating the integral for arbitrary left invariant and right invariant measures,
applying a version of Fubini.
As one may use the same right invariant measure, this shows that two different left invariant
measures will give the same integral, up to some fixed scalar.
-/
/-- In a group with a left invariant measure `μ` and a right invariant measure `ν`, one can express
integrals with respect to `μ` as integrals with respect to `ν` up to a constant scaling factor
(given in the statement as `∫ x, g x ∂μ` where `g` is a fixed reference function) and an
explicit density `y ↦ 1/∫ z, g (z⁻¹ * y) ∂ν`. -/
@[to_additive]
lemma integral_isMulLeftInvariant_isMulRightInvariant_combo
{μ ν : Measure G} [IsFiniteMeasureOnCompacts μ] [IsFiniteMeasureOnCompacts ν]
[IsMulLeftInvariant μ] [IsMulRightInvariant ν] [IsOpenPosMeasure ν]
{f g : G → ℝ} (hf : Continuous f) (h'f : HasCompactSupport f)
(hg : Continuous g) (h'g : HasCompactSupport g) (g_nonneg : 0 ≤ g) {x₀ : G} (g_pos : g x₀ ≠ 0) :
∫ x, f x ∂μ = (∫ y, f y * (∫ z, g (z⁻¹ * y) ∂ν)⁻¹ ∂ν) * ∫ x, g x ∂μ := by
-- The group has to be locally compact, otherwise all integrals vanish and the result is trivial.
rcases h'f.eq_zero_or_locallyCompactSpace_of_group hf with Hf|Hf
· simp [Hf]
let D : G → ℝ := fun (x : G) ↦ ∫ y, g (y⁻¹ * x) ∂ν
have D_cont : Continuous D := continuous_integral_apply_inv_mul hg h'g
have D_pos : ∀ x, 0 < D x := by
intro x
have C : Continuous (fun y ↦ g (y⁻¹ * x)) := hg.comp (continuous_inv.mul continuous_const)
apply (integral_pos_iff_support_of_nonneg _ _).2
· apply C.isOpen_support.measure_pos ν
exact ⟨x * x₀⁻¹, by simpa using g_pos⟩
· exact fun y ↦ g_nonneg (y⁻¹ * x)
· apply C.integrable_of_hasCompactSupport
exact h'g.comp_homeomorph ((Homeomorph.inv G).trans (Homeomorph.mulRight x))
calc
∫ x, f x ∂μ = ∫ x, f x * (D x)⁻¹ * D x ∂μ := by
congr with x; rw [mul_assoc, inv_mul_cancel (D_pos x).ne', mul_one]
_ = ∫ x, (∫ y, f x * (D x)⁻¹ * g (y⁻¹ * x) ∂ν) ∂μ := by simp_rw [integral_mul_left]
_ = ∫ y, (∫ x, f x * (D x)⁻¹ * g (y⁻¹ * x) ∂μ) ∂ν := by
apply integral_integral_swap_of_hasCompactSupport
· apply Continuous.mul
· exact (hf.comp continuous_fst).mul
((D_cont.comp continuous_fst).inv₀ (fun x ↦ (D_pos _).ne'))
· exact hg.comp (continuous_snd.inv.mul continuous_fst)
· let K := tsupport f
have K_comp : IsCompact K := h'f
let L := tsupport g
have L_comp : IsCompact L := h'g
let M := (fun (p : G × G) ↦ p.1 * p.2⁻¹) '' (K ×ˢ L)
have M_comp : IsCompact M :=
(K_comp.prod L_comp).image (continuous_fst.mul continuous_snd.inv)
have M'_comp : IsCompact (closure M) := M_comp.closure
have : ∀ (p : G × G), p ∉ K ×ˢ closure M → f p.1 * (D p.1)⁻¹ * g (p.2⁻¹ * p.1) = 0 := by
rintro ⟨x, y⟩ hxy
by_cases H : x ∈ K; swap
· simp [image_eq_zero_of_nmem_tsupport H]
have : g (y⁻¹ * x) = 0 := by
apply image_eq_zero_of_nmem_tsupport
contrapose! hxy
simp only [mem_prod, H, true_and]
apply subset_closure
simp only [M, mem_image, mem_prod, Prod.exists]
exact ⟨x, y⁻¹ * x, ⟨H, hxy⟩, by group⟩
simp [this]
apply HasCompactSupport.intro' (K_comp.prod M'_comp) ?_ this
exact (isClosed_tsupport f).prod isClosed_closure
_ = ∫ y, (∫ x, f (y * x) * (D (y * x))⁻¹ * g x ∂μ) ∂ν := by
congr with y
rw [← integral_mul_left_eq_self _ y]
simp
_ = ∫ x, (∫ y, f (y * x) * (D (y * x))⁻¹ * g x ∂ν) ∂μ := by
apply (integral_integral_swap_of_hasCompactSupport _ _).symm
· apply Continuous.mul ?_ (hg.comp continuous_fst)
exact (hf.comp (continuous_snd.mul continuous_fst)).mul
((D_cont.comp (continuous_snd.mul continuous_fst)).inv₀ (fun x ↦ (D_pos _).ne'))
· let K := tsupport f
have K_comp : IsCompact K := h'f
let L := tsupport g
have L_comp : IsCompact L := h'g
let M := (fun (p : G × G) ↦ p.1 * p.2⁻¹) '' (K ×ˢ L)
have M_comp : IsCompact M :=
(K_comp.prod L_comp).image (continuous_fst.mul continuous_snd.inv)
have M'_comp : IsCompact (closure M) := M_comp.closure
have : ∀ (p : G × G), p ∉ L ×ˢ closure M →
f (p.2 * p.1) * (D (p.2 * p.1))⁻¹ * g p.1 = 0 := by
rintro ⟨x, y⟩ hxy
by_cases H : x ∈ L; swap
· simp [image_eq_zero_of_nmem_tsupport H]
have : f (y * x) = 0 := by
apply image_eq_zero_of_nmem_tsupport
contrapose! hxy
simp only [mem_prod, H, true_and]
apply subset_closure
simp only [M, mem_image, mem_prod, Prod.exists]
exact ⟨y * x, x, ⟨hxy, H⟩, by group⟩
simp [this]
apply HasCompactSupport.intro' (L_comp.prod M'_comp) ?_ this
exact (isClosed_tsupport g).prod isClosed_closure
_ = ∫ x, (∫ y, f y * (D y)⁻¹ ∂ν) * g x ∂μ := by
simp_rw [integral_mul_right]
congr with x
conv_rhs => rw [← integral_mul_right_eq_self _ x]
_ = (∫ y, f y * (D y)⁻¹ ∂ν) * ∫ x, g x ∂μ := integral_mul_left _ _
/-- Given two left-invariant measures which are finite on
compacts, they coincide in the following sense: they give the same value to the integral of
continuous compactly supported functions, up to a multiplicative constant. -/
@[to_additive exists_integral_isAddLeftInvariant_eq_smul_of_hasCompactSupport]
lemma exists_integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport (μ' μ : Measure G)
[IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ'] :
∃ (c : ℝ≥0), ∀ (f : G → ℝ), Continuous f → HasCompactSupport f →
∫ x, f x ∂μ' = ∫ x, f x ∂(c • μ) := by
-- The group has to be locally compact, otherwise all integrals vanish and the result is trivial.
by_cases H : LocallyCompactSpace G; swap
· refine ⟨0, fun f f_cont f_comp ↦ ?_⟩
rcases f_comp.eq_zero_or_locallyCompactSpace_of_group f_cont with hf|hf
· simp [hf]
· exact (H hf).elim
-- Fix some nonzero continuous function with compact support `g`.
obtain ⟨⟨g, g_cont⟩, g_comp, g_nonneg, g_one⟩ :
∃ (g : C(G, ℝ)), HasCompactSupport g ∧ 0 ≤ g ∧ g 1 ≠ 0 := exists_continuous_nonneg_pos 1
have int_g_pos : 0 < ∫ x, g x ∂μ :=
g_cont.integral_pos_of_hasCompactSupport_nonneg_nonzero g_comp g_nonneg g_one
-- The proportionality constant we are looking for will be the ratio of the integrals of `g`
-- with respect to `μ'` and `μ`.
let c : ℝ := (∫ x, g x ∂μ) ⁻¹ * (∫ x, g x ∂μ')
have c_nonneg : 0 ≤ c :=
mul_nonneg (inv_nonneg.2 (integral_nonneg g_nonneg)) (integral_nonneg g_nonneg)
refine ⟨⟨c, c_nonneg⟩, fun f f_cont f_comp ↦ ?_⟩
/- use the lemma `integral_mulLeftInvariant_mulRightInvariant_combo` for `μ` and then `μ'`
to reexpress the integral of `f` as the integral of `g` times a factor which only depends
on a right-invariant measure `ν`. We use `ν = μ.inv` for convenience. -/
let ν := μ.inv
have A : ∫ x, f x ∂μ = (∫ y, f y * (∫ z, g (z⁻¹ * y) ∂ν)⁻¹ ∂ν) * ∫ x, g x ∂μ :=
integral_isMulLeftInvariant_isMulRightInvariant_combo f_cont f_comp g_cont g_comp g_nonneg g_one
rw [← mul_inv_eq_iff_eq_mul₀ int_g_pos.ne'] at A
have B : ∫ x, f x ∂μ' = (∫ y, f y * (∫ z, g (z⁻¹ * y) ∂ν)⁻¹ ∂ν) * ∫ x, g x ∂μ' :=
integral_isMulLeftInvariant_isMulRightInvariant_combo f_cont f_comp g_cont g_comp g_nonneg g_one
/- Since the `ν`-factor is the same for `μ` and `μ'`, this gives the result. -/
rw [← A, mul_assoc, mul_comm] at B
simp only [B, integral_smul_nnreal_measure]
rfl
open scoped Classical in
/-- Given two left-invariant measures which are finite on compacts, `haarScalarFactor μ' μ` is a
scalar such that `∫ f dμ' = (haarScalarFactor μ' μ) ∫ f dμ` for any compactly supported continuous
function `f`.
Note that there is a dissymmetry in the assumptions between `μ'` and `μ`: the measure `μ'` needs
only be finite on compact sets, while `μ` has to be finite on compact sets and positive on open
sets, i.e., a Haar measure, to exclude for instance the case where `μ = 0`, where the definition
doesn't make sense. -/
@[to_additive "Given two left-invariant measures which are finite on compacts,
`addHaarScalarFactor μ' μ` is a scalar such that `∫ f dμ' = (addHaarScalarFactor μ' μ) ∫ f dμ` for
any compactly supported continuous function `f`.
Note that there is a dissymmetry in the assumptions between `μ'` and `μ`: the measure `μ'` needs
only be finite on compact sets, while `μ` has to be finite on compact sets and positive on open
sets, i.e., an additive Haar measure, to exclude for instance the case where `μ = 0`, where the
definition doesn't make sense."]
noncomputable def haarScalarFactor
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ'] :
ℝ≥0 :=
if ¬ LocallyCompactSpace G then 1
else (exists_integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ' μ).choose
/-- Two left invariant measures integrate in the same way continuous compactly supported functions,
up to the scalar `haarScalarFactor μ' μ`. See also
`measure_isMulInvariant_eq_smul_of_isCompact_closure`, which gives the same result for compact
sets, and `measure_isHaarMeasure_eq_smul_of_isOpen` for open sets. -/
@[to_additive integral_isAddLeftInvariant_eq_smul_of_hasCompactSupport
"Two left invariant measures integrate in the same way continuous compactly supported functions,
up to the scalar `addHaarScalarFactor μ' μ`. See also
`measure_isAddInvariant_eq_smul_of_isCompact_closure`, which gives the same result for compact
sets, and `measure_isAddHaarMeasure_eq_smul_of_isOpen` for open sets."]
theorem integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
{f : G → ℝ} (hf : Continuous f) (h'f : HasCompactSupport f) :
∫ x, f x ∂μ' = ∫ x, f x ∂(haarScalarFactor μ' μ • μ) := by
classical
rcases h'f.eq_zero_or_locallyCompactSpace_of_group hf with Hf|Hf
· simp [Hf]
· simp only [haarScalarFactor, Hf, not_true_eq_false, ite_false]
exact (exists_integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ' μ).choose_spec
f hf h'f
@[to_additive addHaarScalarFactor_eq_integral_div]
lemma haarScalarFactor_eq_integral_div (μ' μ : Measure G) [IsHaarMeasure μ]
[IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ'] {f : G → ℝ} (hf : Continuous f)
(h'f : HasCompactSupport f) (int_nonzero : ∫ x, f x ∂μ ≠ 0) :
haarScalarFactor μ' μ = (∫ x, f x ∂μ') / ∫ x, f x ∂μ := by
have := integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ' μ hf h'f
rw [integral_smul_nnreal_measure] at this
exact EuclideanDomain.eq_div_of_mul_eq_left int_nonzero this.symm
@[to_additive (attr := simp) addHaarScalarFactor_smul]
lemma haarScalarFactor_smul [LocallyCompactSpace G] (μ' μ : Measure G) [IsHaarMeasure μ]
[IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ'] {c : ℝ≥0} :
haarScalarFactor (c • μ') μ = c • haarScalarFactor μ' μ := by
obtain ⟨⟨g, g_cont⟩, g_comp, g_nonneg, g_one⟩ :
∃ g : C(G, ℝ), HasCompactSupport g ∧ 0 ≤ g ∧ g 1 ≠ 0 := exists_continuous_nonneg_pos 1
have int_g_ne_zero : ∫ x, g x ∂μ ≠ 0 :=
ne_of_gt (g_cont.integral_pos_of_hasCompactSupport_nonneg_nonzero g_comp g_nonneg g_one)
apply NNReal.coe_injective
calc
haarScalarFactor (c • μ') μ = (∫ x, g x ∂(c • μ')) / ∫ x, g x ∂μ :=
haarScalarFactor_eq_integral_div _ _ g_cont g_comp int_g_ne_zero
_ = (c • (∫ x, g x ∂μ')) / ∫ x, g x ∂μ := by simp
_ = c • ((∫ x, g x ∂μ') / ∫ x, g x ∂μ) := smul_div_assoc c _ _
_ = c • haarScalarFactor μ' μ := by
rw [← haarScalarFactor_eq_integral_div _ _ g_cont g_comp int_g_ne_zero]
@[to_additive (attr := simp)]
lemma haarScalarFactor_self (μ : Measure G) [IsHaarMeasure μ] :
haarScalarFactor μ μ = 1 := by
by_cases hG : LocallyCompactSpace G; swap
· simp [haarScalarFactor, hG]
obtain ⟨⟨g, g_cont⟩, g_comp, g_nonneg, g_one⟩ :
∃ g : C(G, ℝ), HasCompactSupport g ∧ 0 ≤ g ∧ g 1 ≠ 0 := exists_continuous_nonneg_pos 1
have int_g_ne_zero : ∫ x, g x ∂μ ≠ 0 :=
ne_of_gt (g_cont.integral_pos_of_hasCompactSupport_nonneg_nonzero g_comp g_nonneg g_one)
apply NNReal.coe_injective
calc
haarScalarFactor μ μ = (∫ x, g x ∂μ) / ∫ x, g x ∂μ :=
haarScalarFactor_eq_integral_div _ _ g_cont g_comp int_g_ne_zero
_ = 1 := div_self int_g_ne_zero
@[to_additive]
lemma haarScalarFactor_eq_mul (μ' μ ν : Measure G)
[IsHaarMeasure μ] [IsHaarMeasure ν] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ'] :
haarScalarFactor μ' ν = haarScalarFactor μ' μ * haarScalarFactor μ ν := by
-- The group has to be locally compact, otherwise the scalar factor is 1 by definition.
by_cases hG : LocallyCompactSpace G; swap
· simp [haarScalarFactor, hG]
-- Fix some nonzero continuous function with compact support `g`.
obtain ⟨⟨g, g_cont⟩, g_comp, g_nonneg, g_one⟩ :
∃ (g : C(G, ℝ)), HasCompactSupport g ∧ 0 ≤ g ∧ g 1 ≠ 0 := exists_continuous_nonneg_pos 1
have Z := integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ' μ g_cont g_comp
simp only [integral_smul_nnreal_measure, smul_smul,
integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ' ν g_cont g_comp,
integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ ν g_cont g_comp] at Z
have int_g_pos : 0 < ∫ x, g x ∂ν := by
apply (integral_pos_iff_support_of_nonneg g_nonneg _).2
· exact IsOpen.measure_pos ν g_cont.isOpen_support ⟨1, g_one⟩
· exact g_cont.integrable_of_hasCompactSupport g_comp
change (haarScalarFactor μ' ν : ℝ) * ∫ (x : G), g x ∂ν =
(haarScalarFactor μ' μ * haarScalarFactor μ ν : ℝ≥0) * ∫ (x : G), g x ∂ν at Z
simpa only [mul_eq_mul_right_iff (M₀ := ℝ), int_g_pos.ne', or_false, NNReal.eq_iff] using Z
/-- The scalar factor between two left-invariant measures is non-zero when both measures are
positive on open sets. -/
@[to_additive]
lemma haarScalarFactor_pos_of_isHaarMeasure (μ' μ : Measure G) [IsHaarMeasure μ]
[IsHaarMeasure μ'] : 0 < haarScalarFactor μ' μ :=
pos_iff_ne_zero.2 (fun H ↦ by simpa [H] using haarScalarFactor_eq_mul μ' μ μ')
@[deprecated (since := "2024-02-12")]
alias haarScalarFactor_pos_of_isOpenPosMeasure := haarScalarFactor_pos_of_isHaarMeasure
@[deprecated (since := "2024-02-12")]
alias addHaarScalarFactor_pos_of_isOpenPosMeasure := addHaarScalarFactor_pos_of_isAddHaarMeasure
/-!
### Uniqueness of measure of sets with compact closure
Two left invariant measures give the same measure to sets with compact closure, up to the
scalar `haarScalarFactor μ' μ`.
This is a tricky argument, typically not done in textbooks (the textbooks version all require one
version of regularity or another). Here is a sketch, based on
McQuillan's answer at https://mathoverflow.net/questions/456670/.
Assume for simplicity that all measures are normalized, so that the scalar factors are all `1`.
First, from the fact that `μ` and `μ'` integrate in the same way compactly supported functions,
they give the same measure to compact "zero sets", i.e., sets of the form `f⁻¹ {1}`
for `f` continuous and compactly supported.
See `measure_preimage_isMulLeftInvariant_eq_smul_of_hasCompactSupport`.
If `μ` is inner regular, a theorem of Halmos shows that any measurable set `s` of finite measure can
be approximated from inside by a compact zero set `k`. Then `μ s ≤ μ k + ε = μ' k + ε ≤ μ' s + ε`.
Letting `ε` tend to zero, one gets `μ s ≤ μ' s`.
See `smul_measure_isMulInvariant_le_of_isCompact_closure`.
Assume now that `s` is a measurable set of compact closure. It is contained in a compact
zero set `t`. The same argument applied to `t - s` gives `μ (t \ s) ≤ μ' (t \ s)`, i.e.,
`μ t - μ s ≤ μ' t - μ' s`. As `μ t = μ' t` (since these are zero sets), we get the inequality
`μ' s ≤ μ s`. Together with the previous one, this gives `μ' s = μ s`.
See `measure_isMulInvariant_eq_smul_of_isCompact_closure_of_innerRegularCompactLTTop`.
If neither `μ` nor `μ'` is inner regular, we can use the existence of another inner regular
left-invariant measure `ν`, so get `μ s = ν s = μ' s`, by applying twice the previous argument.
Here, the uniqueness argument uses the existence of a Haar measure with a nice behavior!
See `measure_isMulInvariant_eq_smul_of_isCompact_closure_of_measurableSet`.
Finally, if `s` has compact closure but is not measurable, its measure is the infimum of the
measures of its measurable supersets, and even of those contained in `closure s`. As `μ`
and `μ'` coincide on these supersets, this yields `μ s = μ' s`.
See `measure_isMulInvariant_eq_smul_of_isCompact_closure`.
-/
/-- Two left invariant measures give the same mass to level sets of continuous compactly supported
functions, up to the scalar `haarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isMulInvariant_eq_smul_of_isCompact_closure`, which works for any set with
compact closure. -/
@[to_additive measure_preimage_isAddLeftInvariant_eq_smul_of_hasCompactSupport
"Two left invariant measures give the same mass to level sets of continuous compactly supported
functions, up to the scalar `addHaarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isAddInvariant_eq_smul_of_isCompact_closure`, which works for any set with
compact closure."]
lemma measure_preimage_isMulLeftInvariant_eq_smul_of_hasCompactSupport
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
{f : G → ℝ} (hf : Continuous f) (h'f : HasCompactSupport f) :
μ' (f ⁻¹' {1}) = haarScalarFactor μ' μ • μ (f ⁻¹' {1}) := by
/- This follows from the fact that the two measures integrate in the same way continuous
functions, by approximating the indicator function of `f ⁻¹' {1}` by continuous functions
(namely `vₙ ∘ f` where `vₙ` is equal to `1` at `1`, and `0` outside of a small neighborhood
`(1 - uₙ, 1 + uₙ)` where `uₙ` is a sequence tending to `0`).
We use `vₙ = thickenedIndicator uₙ {1}` to take advantage of existing lemmas. -/
obtain ⟨u, -, u_mem, u_lim⟩ : ∃ u, StrictAnti u ∧ (∀ (n : ℕ), u n ∈ Ioo 0 1)
∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto' (zero_lt_one : (0 : ℝ) < 1)
let v : ℕ → ℝ → ℝ := fun n x ↦ thickenedIndicator (u_mem n).1 ({1} : Set ℝ) x
have vf_cont n : Continuous ((v n) ∘ f) := by
apply Continuous.comp (continuous_induced_dom.comp ?_) hf
exact BoundedContinuousFunction.continuous (thickenedIndicator (u_mem n).left {1})
have I : ∀ (ν : Measure G), IsFiniteMeasureOnCompacts ν →
Tendsto (fun n ↦ ∫ x, v n (f x) ∂ν) atTop
(𝓝 (∫ x, Set.indicator ({1} : Set ℝ) (fun _ ↦ 1) (f x) ∂ν)) := by
intro ν hν
apply tendsto_integral_of_dominated_convergence
(bound := (tsupport f).indicator (fun (_ : G) ↦ (1 : ℝ)) )
· exact fun n ↦ (vf_cont n).aestronglyMeasurable
· apply IntegrableOn.integrable_indicator _ (isClosed_tsupport f).measurableSet
simpa using IsCompact.measure_lt_top h'f
· refine fun n ↦ eventually_of_forall (fun x ↦ ?_)
by_cases hx : x ∈ tsupport f
· simp only [v, Real.norm_eq_abs, NNReal.abs_eq, hx, indicator_of_mem]
norm_cast
exact thickenedIndicator_le_one _ _ _
· simp only [v, Real.norm_eq_abs, NNReal.abs_eq, hx, not_false_eq_true, indicator_of_not_mem]
rw [thickenedIndicator_zero]
· simp
· simpa [image_eq_zero_of_nmem_tsupport hx] using (u_mem n).2.le
· filter_upwards with x
have T := tendsto_pi_nhds.1 (thickenedIndicator_tendsto_indicator_closure
(fun n ↦ (u_mem n).1) u_lim ({1} : Set ℝ)) (f x)
simp only [thickenedIndicator_toFun, closure_singleton] at T
convert NNReal.tendsto_coe.2 T
simp
have M n : ∫ (x : G), v n (f x) ∂μ' = ∫ (x : G), v n (f x) ∂(haarScalarFactor μ' μ • μ) := by
apply integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport μ' μ (vf_cont n)
apply h'f.comp_left
simp only [v, thickenedIndicator_toFun, NNReal.coe_eq_zero]
rw [thickenedIndicatorAux_zero (u_mem n).1]
· simp only [ENNReal.zero_toNNReal]
· simpa using (u_mem n).2.le
have I1 := I μ' (by infer_instance)
simp_rw [M] at I1
have J1 : ∫ (x : G), indicator {1} (fun _ ↦ (1 : ℝ)) (f x) ∂μ'
= ∫ (x : G), indicator {1} (fun _ ↦ 1) (f x) ∂(haarScalarFactor μ' μ • μ) :=
tendsto_nhds_unique I1 (I (haarScalarFactor μ' μ • μ) (by infer_instance))
have J2 : ENNReal.toReal (μ' (f ⁻¹' {1}))
= ENNReal.toReal ((haarScalarFactor μ' μ • μ) (f ⁻¹' {1})) := by
have : (fun x ↦ indicator {1} (fun _ ↦ (1 : ℝ)) (f x)) =
(fun x ↦ indicator (f ⁻¹' {1}) (fun _ ↦ (1 : ℝ)) x) := by
ext x
exact (indicator_comp_right f (s := ({1} : Set ℝ)) (g := (fun _ ↦ (1 : ℝ))) (x := x)).symm
have mf : MeasurableSet (f ⁻¹' {1}) := (isClosed_singleton.preimage hf).measurableSet
simpa only [this, mf, integral_indicator_const, smul_eq_mul, mul_one, Pi.smul_apply,
nnreal_smul_coe_apply, ENNReal.toReal_mul, ENNReal.coe_toReal] using J1
have C : IsCompact (f ⁻¹' {1}) := h'f.isCompact_preimage hf isClosed_singleton (by simp)
rw [ENNReal.toReal_eq_toReal C.measure_lt_top.ne C.measure_lt_top.ne] at J2
simpa using J2
/-- If an invariant measure is inner regular, then it gives less mass to sets with compact closure
than any other invariant measure, up to the scalar `haarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isMulInvariant_eq_smul_of_isCompact_closure`, which gives equality for any
set with compact closure. -/
@[to_additive smul_measure_isAddInvariant_le_of_isCompact_closure
"If an invariant measure is inner regular, then it gives less mass to sets with compact closure
than any other invariant measure, up to the scalar `addHaarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isAddInvariant_eq_smul_of_isCompact_closure`, which gives equality for any
set with compact closure."]
lemma smul_measure_isMulInvariant_le_of_isCompact_closure [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
[InnerRegularCompactLTTop μ]
{s : Set G} (hs : MeasurableSet s) (h's : IsCompact (closure s)) :
haarScalarFactor μ' μ • μ s ≤ μ' s := by
apply le_of_forall_lt (fun r hr ↦ ?_)
let ν := haarScalarFactor μ' μ • μ
have : ν s ≠ ∞ := ((measure_mono subset_closure).trans_lt h's.measure_lt_top).ne
obtain ⟨-, hf, ⟨f, f_cont, f_comp, rfl⟩, νf⟩ :
∃ K ⊆ s, (∃ f, Continuous f ∧ HasCompactSupport f ∧ K = f ⁻¹' {1}) ∧ r < ν K :=
innerRegularWRT_preimage_one_hasCompactSupport_measure_ne_top_of_group ⟨hs, this⟩ r
(by convert hr)
calc
r < ν (f ⁻¹' {1}) := νf
_ = μ' (f ⁻¹' {1}) :=
(measure_preimage_isMulLeftInvariant_eq_smul_of_hasCompactSupport _ _ f_cont f_comp).symm
_ ≤ μ' s := measure_mono hf
/-- If an invariant measure is inner regular, then it gives the same mass to measurable sets with
compact closure as any other invariant measure, up to the scalar `haarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isMulInvariant_eq_smul_of_isCompact_closure`, which works for any set with
compact closure, and removes the inner regularity assumption. -/
@[to_additive measure_isAddInvariant_eq_smul_of_isCompact_closure_of_innerRegularCompactLTTop
" If an invariant measure is inner regular, then it gives the same mass to measurable sets with
compact closure as any other invariant measure, up to the scalar `addHaarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isAddInvariant_eq_smul_of_isCompact_closure`, which works for any set with
compact closure, and removes the inner regularity assumption."]
lemma measure_isMulInvariant_eq_smul_of_isCompact_closure_of_innerRegularCompactLTTop
[LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
[InnerRegularCompactLTTop μ]
{s : Set G} (hs : MeasurableSet s) (h's : IsCompact (closure s)) :
μ' s = haarScalarFactor μ' μ • μ s := by
apply le_antisymm ?_ (smul_measure_isMulInvariant_le_of_isCompact_closure μ' μ hs h's)
let ν := haarScalarFactor μ' μ • μ
change μ' s ≤ ν s
obtain ⟨⟨f, f_cont⟩, hf, -, f_comp, -⟩ : ∃ f : C(G, ℝ), EqOn f 1 (closure s) ∧ EqOn f 0 ∅
∧ HasCompactSupport f ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 :=
exists_continuous_one_zero_of_isCompact h's isClosed_empty (disjoint_empty _)
let t := f ⁻¹' {1}
have t_closed : IsClosed t := isClosed_singleton.preimage f_cont
have t_comp : IsCompact t := f_comp.isCompact_preimage f_cont isClosed_singleton (by simp)
have st : s ⊆ t := (IsClosed.closure_subset_iff t_closed).mp hf
have A : ν (t \ s) ≤ μ' (t \ s) := by
apply smul_measure_isMulInvariant_le_of_isCompact_closure _ _ (t_closed.measurableSet.diff hs)
exact t_comp.closure_of_subset diff_subset
have B : μ' t = ν t :=
measure_preimage_isMulLeftInvariant_eq_smul_of_hasCompactSupport _ _ f_cont f_comp
rwa [measure_diff st hs, measure_diff st hs, ← B, ENNReal.sub_le_sub_iff_left] at A
· exact measure_mono st
· exact t_comp.measure_lt_top.ne
· exact ((measure_mono st).trans_lt t_comp.measure_lt_top).ne
· exact ((measure_mono st).trans_lt t_comp.measure_lt_top).ne
/-- Given an invariant measure then it gives the same mass to measurable sets with
compact closure as any other invariant measure, up to the scalar `haarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isMulInvariant_eq_smul_of_isCompact_closure`, which removes the
measurability assumption. -/
@[to_additive measure_isAddInvariant_eq_smul_of_isCompact_closure_of_measurableSet
"Given an invariant measure then it gives the same mass to measurable sets with
compact closure as any other invariant measure, up to the scalar `addHaarScalarFactor μ' μ`.
Auxiliary lemma in the proof of the more general
`measure_isAddInvariant_eq_smul_of_isCompact_closure`, which removes the
measurability assumption."]
lemma measure_isMulInvariant_eq_smul_of_isCompact_closure_of_measurableSet [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
{s : Set G} (hs : MeasurableSet s) (h's : IsCompact (closure s)) :
μ' s = haarScalarFactor μ' μ • μ s := by
let ν : Measure G := haar
have A : μ' s = haarScalarFactor μ' ν • ν s :=
measure_isMulInvariant_eq_smul_of_isCompact_closure_of_innerRegularCompactLTTop μ' ν hs h's
have B : μ s = haarScalarFactor μ ν • ν s :=
measure_isMulInvariant_eq_smul_of_isCompact_closure_of_innerRegularCompactLTTop μ ν hs h's
rw [A, B, smul_smul, haarScalarFactor_eq_mul μ' μ ν]
/-- **Uniqueness of left-invariant measures**:
Given two left-invariant measures which are finite on compacts, they coincide in the following
sense: they give the same value to sets with compact closure, up to the multiplicative
constant `haarScalarFactor μ' μ`. -/
@[to_additive measure_isAddInvariant_eq_smul_of_isCompact_closure
"**Uniqueness of left-invariant measures**:
Given two left-invariant measures which are finite on compacts, they coincide in the following
sense: they give the same value to sets with compact closure, up to the multiplicative
constant `addHaarScalarFactor μ' μ`. "]
theorem measure_isMulInvariant_eq_smul_of_isCompact_closure [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
{s : Set G} (h's : IsCompact (closure s)) :
μ' s = haarScalarFactor μ' μ • μ s := by
let ν := haarScalarFactor μ' μ • μ
apply le_antisymm
· calc
μ' s ≤ μ' ((toMeasurable ν s) ∩ (closure s)) :=
measure_mono <| subset_inter (subset_toMeasurable ν s) subset_closure
_ = ν ((toMeasurable ν s) ∩ (closure s)) := by
apply measure_isMulInvariant_eq_smul_of_isCompact_closure_of_measurableSet _ _ _ _
· exact (measurableSet_toMeasurable ν s).inter isClosed_closure.measurableSet
· exact h's.closure_of_subset inter_subset_right
_ ≤ ν (toMeasurable ν s) := measure_mono inter_subset_left
_ = ν s := measure_toMeasurable s
· calc
ν s ≤ ν ((toMeasurable μ' s) ∩ (closure s)) :=
measure_mono <| subset_inter (subset_toMeasurable μ' s) subset_closure
_ = μ' ((toMeasurable μ' s) ∩ (closure s)) := by
apply (measure_isMulInvariant_eq_smul_of_isCompact_closure_of_measurableSet _ _ _ _).symm
· exact (measurableSet_toMeasurable μ' s).inter isClosed_closure.measurableSet
· exact h's.closure_of_subset inter_subset_right
_ ≤ μ' (toMeasurable μ' s) := measure_mono inter_subset_left
_ = μ' s := measure_toMeasurable s
/-- **Uniqueness of Haar measures**:
Two Haar measures on a compact group coincide up to a multiplicative factor. -/
@[to_additive isAddInvariant_eq_smul_of_compactSpace]
lemma isMulInvariant_eq_smul_of_compactSpace [CompactSpace G] (μ' μ : Measure G)
[IsHaarMeasure μ] [IsMulLeftInvariant μ'] [IsFiniteMeasureOnCompacts μ'] :
μ' = haarScalarFactor μ' μ • μ := by
ext s _hs
exact measure_isMulInvariant_eq_smul_of_isCompact_closure _ _ isClosed_closure.isCompact
@[to_additive]
instance (priority := 100) instInnerRegularOfIsHaarMeasureOfCompactSpace
[CompactSpace G] (μ : Measure G) [IsMulLeftInvariant μ] [IsFiniteMeasureOnCompacts μ] :
InnerRegular μ := by
rw [isMulInvariant_eq_smul_of_compactSpace μ haar]
infer_instance
@[to_additive]
instance (priority := 100) instRegularOfIsHaarMeasureOfCompactSpace
[CompactSpace G] (μ : Measure G) [IsMulLeftInvariant μ] [IsFiniteMeasureOnCompacts μ] :
Regular μ := by
rw [isMulInvariant_eq_smul_of_compactSpace μ haar]
infer_instance
/-- **Uniqueness of Haar measures**:
Two Haar measures which are probability measures coincide. -/
@[to_additive]
lemma isHaarMeasure_eq_of_isProbabilityMeasure [LocallyCompactSpace G] (μ' μ : Measure G)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ'] [IsHaarMeasure μ] [IsHaarMeasure μ'] :
μ' = μ := by
have : CompactSpace G := by
by_contra H
rw [not_compactSpace_iff] at H
simpa using measure_univ_of_isMulLeftInvariant μ
have A s : μ' s = haarScalarFactor μ' μ • μ s :=
measure_isMulInvariant_eq_smul_of_isCompact_closure _ _ isClosed_closure.isCompact
have Z := A univ
simp only [measure_univ, ENNReal.smul_def, smul_eq_mul, mul_one, ENNReal.one_eq_coe] at Z
ext s _hs
simp [A s, ← Z]
@[deprecated (since := "2024-02-12")]
alias haarScalarFactor_eq_one_of_isProbabilityMeasure := isHaarMeasure_eq_of_isProbabilityMeasure
@[deprecated (since := "2024-02-12")]
alias addHaarScalarFactor_eq_one_of_isProbabilityMeasure :=
isAddHaarMeasure_eq_of_isProbabilityMeasure
/-!
### Uniqueness of measure of open sets
Two Haar measures give the same measure to open sets (or more generally to sets which are everywhere
positive), up to the scalar `haarScalarFactor μ' μ `.
-/
@[to_additive measure_isAddHaarMeasure_eq_smul_of_isEverywherePos]
theorem measure_isHaarMeasure_eq_smul_of_isEverywherePos [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsHaarMeasure μ']
{s : Set G} (hs : MeasurableSet s) (h's : IsEverywherePos μ s) :
μ' s = haarScalarFactor μ' μ • μ s := by
let ν := haarScalarFactor μ' μ • μ
change μ' s = ν s
/- Fix a compact neighborhood `k` of the identity, and consider a maximal disjoint family `m` of
sets `x • k` centered at points in `s`. Then `s` is covered by the sets `x • (k * k⁻¹)` by
maximality. If the family is countable, then since `μ'` and `ν` coincide in compact sets, and
the measure of a countable disjoint union is the sum of the measures, we get `μ' s = ν s`.
Otherwise, the family is uncountable, and each intersection with `s` has positive measure by
the everywhere positivity assumption, so `ν s = ∞`, and `μ' s = ∞` in the same way. -/
obtain ⟨k, k_comp, k_closed, k_mem⟩ : ∃ k, IsCompact k ∧ IsClosed k ∧ k ∈ 𝓝 (1 : G) := by
rcases exists_compact_mem_nhds (1 : G) with ⟨k, hk, hmem⟩
exact ⟨closure k, hk.closure, isClosed_closure, mem_of_superset hmem subset_closure⟩
have one_k : 1 ∈ k := mem_of_mem_nhds k_mem
let A : Set (Set G) := {t | t ⊆ s ∧ PairwiseDisjoint t (fun x ↦ x • k)}
obtain ⟨m, mA, m_max⟩ : ∃ m ∈ A, ∀ a ∈ A, m ⊆ a → a = m := by
apply zorn_subset
intro c cA hc
refine ⟨⋃ a ∈ c, a, ⟨?_, ?_⟩, ?_⟩
· simp only [iUnion_subset_iff]
intro a ac x hx
simp only [A, subset_def, mem_setOf_eq] at cA
exact (cA _ ac).1 x hx
· rintro x hx y hy hxy
simp only [mem_iUnion, exists_prop] at hx hy
rcases hx with ⟨a, ac, xa⟩
rcases hy with ⟨b, bc, yb⟩
obtain ⟨m, mc, am, bm⟩ : ∃ m ∈ c, a ⊆ m ∧ b ⊆ m := hc.directedOn _ ac _ bc
exact (cA mc).2 (am xa) (bm yb) hxy
· intro a ac
exact subset_biUnion_of_mem (u := id) ac
change m ⊆ s ∧ PairwiseDisjoint m (fun x ↦ x • k) at mA
have sm : s ⊆ ⋃ x ∈ m, x • (k * k⁻¹) := by
intro y hy
by_cases h'y : m ∪ {y} ∈ A
· have : m ∪ {y} = m := m_max _ h'y subset_union_left
have ym : y ∈ m := by simpa using subset_union_right.trans this.subset
have : y ∈ y • (k * k⁻¹) := by
simpa using mem_leftCoset y (Set.mul_mem_mul one_k (Set.inv_mem_inv.mpr one_k))
exact mem_biUnion ym this
· obtain ⟨x, xm, -, z, zy, zx⟩ : ∃ x ∈ m, y ≠ x ∧ ∃ z, z ∈ y • k ∧ z ∈ x • k := by
simpa [A, mA.1, hy, insert_subset_iff, pairwiseDisjoint_insert, mA.2, not_disjoint_iff]
using h'y
have : y ∈ x • (k * k⁻¹) := by
rw [show y = x * ((x⁻¹ * z) * (y⁻¹ * z)⁻¹) by group]
have : (x⁻¹ * z) * (y⁻¹ * z)⁻¹ ∈ k * k⁻¹ := Set.mul_mem_mul ((mem_leftCoset_iff x).mp zx)
(Set.inv_mem_inv.mpr ((mem_leftCoset_iff y).mp zy))
exact mem_leftCoset x this
exact mem_biUnion xm this
rcases eq_empty_or_nonempty m with rfl|hm
· simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty, subset_empty_iff] at sm
simp [sm]
by_cases h'm : Set.Countable m
· rcases h'm.exists_eq_range hm with ⟨f, rfl⟩
have M i : MeasurableSet (disjointed (fun n ↦ s ∩ f n • (k * k⁻¹)) i) := by
apply MeasurableSet.disjointed (fun j ↦ hs.inter ?_)
have : IsClosed (k • k⁻¹) := IsClosed.smul_left_of_isCompact k_closed.inv k_comp
exact (IsClosed.smul this (f j)).measurableSet
simp only [mem_range, iUnion_exists, iUnion_iUnion_eq'] at sm
have s_eq : s = ⋃ n, s ∩ (f n • (k * k⁻¹)) := by rwa [← inter_iUnion, eq_comm, inter_eq_left]
have I : μ' s = ∑' n, μ' (disjointed (fun n ↦ s ∩ f n • (k * k⁻¹)) n) := by
rw [← measure_iUnion (disjoint_disjointed _) M, iUnion_disjointed, ← s_eq]
have J : ν s = ∑' n, ν (disjointed (fun n ↦ s ∩ f n • (k * k⁻¹)) n) := by
rw [← measure_iUnion (disjoint_disjointed _) M, iUnion_disjointed, ← s_eq]
rw [I, J]
congr with n
apply measure_isMulInvariant_eq_smul_of_isCompact_closure
have : IsCompact (f n • (k * k⁻¹)) := IsCompact.smul (f n) (k_comp.mul k_comp.inv)
exact this.closure_of_subset <| (disjointed_subset _ _).trans inter_subset_right
· have H : ∀ (ρ : Measure G), IsEverywherePos ρ s → ρ s = ∞ := by
intro ρ hρ
have M : ∀ (i : ↑m), MeasurableSet (s ∩ (i : G) • k) :=
fun i ↦ hs.inter (IsClosed.smul k_closed _).measurableSet
contrapose! h'm
have : ∑' (x : m), ρ (s ∩ ((x : G) • k)) < ∞ := by
apply lt_of_le_of_lt (MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint _ M _) _
· have I : PairwiseDisjoint m fun x ↦ s ∩ x • k :=
mA.2.mono (fun x ↦ inter_subset_right)
exact I.on_injective Subtype.val_injective (fun x ↦ x.2)
· exact lt_of_le_of_lt (measure_mono (by simp [inter_subset_left])) h'm.lt_top
have C : Set.Countable (support fun (i : m) ↦ ρ (s ∩ (i : G) • k)) :=
Summable.countable_support_ennreal this.ne
have : support (fun (i : m) ↦ ρ (s ∩ (i : G) • k)) = univ := by
apply eq_univ_iff_forall.2 (fun i ↦ ?_)
apply ne_of_gt (hρ (i : G) (mA.1 i.2) _ _)
exact inter_mem_nhdsWithin s (by simpa using smul_mem_nhds (i : G) k_mem)
rw [this] at C
have : Countable m := countable_univ_iff.mp C
exact to_countable m
have Hν : IsEverywherePos ν s :=
h's.smul_measure_nnreal (haarScalarFactor_pos_of_isHaarMeasure _ _).ne'
have Hμ' : IsEverywherePos μ' s := by
apply Hν.of_forall_exists_nhds_eq (fun x _hx ↦ ?_)
obtain ⟨t, t_comp, t_mem⟩ : ∃ t, IsCompact t ∧ t ∈ 𝓝 x := exists_compact_mem_nhds x
refine ⟨t, t_mem, fun u hu ↦ ?_⟩
apply measure_isMulInvariant_eq_smul_of_isCompact_closure
exact t_comp.closure_of_subset hu
rw [H ν Hν, H μ' Hμ']
/-- **Uniqueness of Haar measures**:
Given two Haar measures, they coincide in the following sense: they give the same value to open
sets, up to the multiplicative constant `haarScalarFactor μ' μ`. -/
@[to_additive measure_isAddHaarMeasure_eq_smul_of_isOpen
"**Uniqueness of Haar measures**:
Given two additive Haar measures, they coincide in the following sense: they give the same value to
open sets, up to the multiplicative constant `addHaarScalarFactor μ' μ`."]
theorem measure_isHaarMeasure_eq_smul_of_isOpen [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsHaarMeasure μ'] {s : Set G} (hs : IsOpen s) :
μ' s = haarScalarFactor μ' μ • μ s :=
measure_isHaarMeasure_eq_smul_of_isEverywherePos μ' μ hs.measurableSet hs.isEverywherePos
/-!
### Uniqueness of Haar measure under regularity assumptions.
-/
/-- **Uniqueness of left-invariant measures**:
Given two left-invariant measures which are finite on
compacts and inner regular for finite measure sets with respect to compact sets,
they coincide in the following sense: they give the same value to finite measure sets,
up to a multiplicative constant. -/
@[to_additive]
lemma measure_isMulLeftInvariant_eq_smul_of_ne_top [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
[InnerRegularCompactLTTop μ] [InnerRegularCompactLTTop μ'] {s : Set G}
(hs : μ s ≠ ∞) (h's : μ' s ≠ ∞) : μ' s = haarScalarFactor μ' μ • μ s := by
/- We know that the measures integrate in the same way continuous compactly supported functions,
up to the factor `c = haarScalarFactor μ' μ`. -/
let c := haarScalarFactor μ' μ
/- By regularity, every measurable set of finite measure may be approximated by compact sets.
Therefore, the measures coincide on measurable sets of finite measure. -/
have B : ∀ s, MeasurableSet s → μ s < ∞ → μ' s < ∞ → μ' s = (c • μ) s := by
intro s s_meas hs h's
have : (c • μ) s ≠ ∞ := by simp [ENNReal.mul_eq_top, hs.ne]
rw [s_meas.measure_eq_iSup_isCompact_of_ne_top h's.ne,
s_meas.measure_eq_iSup_isCompact_of_ne_top this]
congr! 4 with K _Ks K_comp
exact measure_isMulInvariant_eq_smul_of_isCompact_closure μ' μ K_comp.closure
/- Finally, replace an arbitrary finite measure set with a measurable version, and use the
version for measurable sets. -/
let t := toMeasurable μ' s ∩ toMeasurable μ s
have st : s ⊆ t := subset_inter (subset_toMeasurable μ' s) (subset_toMeasurable μ s)
have mu'_t : μ' t = μ' s := by
apply le_antisymm
· exact (measure_mono inter_subset_left).trans (measure_toMeasurable s).le
· exact measure_mono st
have mu_t : μ t = μ s := by
apply le_antisymm
· exact (measure_mono inter_subset_right).trans (measure_toMeasurable s).le
· exact measure_mono st
simp only [← mu'_t, smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply, ← mu_t,
nnreal_smul_coe_apply]
apply B
· exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _)
· exact mu_t.le.trans_lt hs.lt_top
· exact mu'_t.le.trans_lt h's.lt_top
/-- **Uniqueness of left-invariant measures**:
Given two left-invariant measures which are finite
on compacts and inner regular, they coincide up to a multiplicative constant. -/
@[to_additive isAddLeftInvariant_eq_smul_of_innerRegular]
lemma isMulLeftInvariant_eq_smul_of_innerRegular [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
[InnerRegular μ] [InnerRegular μ'] :
μ' = haarScalarFactor μ' μ • μ := by
ext s hs
rw [hs.measure_eq_iSup_isCompact, hs.measure_eq_iSup_isCompact]
congr! 4 with K _Ks K_comp
exact measure_isMulLeftInvariant_eq_smul_of_ne_top μ' μ K_comp.measure_lt_top.ne
K_comp.measure_lt_top.ne
/-- **Uniqueness of left-invariant measures**:
Given two left-invariant measures which are finite
on compacts and regular, they coincide up to a multiplicative constant. -/
@[to_additive isAddLeftInvariant_eq_smul_of_regular]
lemma isMulLeftInvariant_eq_smul_of_regular [LocallyCompactSpace G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ']
[Regular μ] [Regular μ'] :
μ' = haarScalarFactor μ' μ • μ := by
have A : ∀ U, IsOpen U → μ' U = (haarScalarFactor μ' μ • μ) U := by
intro U hU
rw [hU.measure_eq_iSup_isCompact, hU.measure_eq_iSup_isCompact]
congr! 4 with K _KU K_comp
exact measure_isMulLeftInvariant_eq_smul_of_ne_top μ' μ K_comp.measure_lt_top.ne
K_comp.measure_lt_top.ne
ext s _hs
rw [s.measure_eq_iInf_isOpen, s.measure_eq_iInf_isOpen]
congr! 4 with U _sU U_open
exact A U U_open
/-- **Uniqueness of left-invariant measures**:
Two Haar measures coincide up to a multiplicative constant in a second countable group. -/
@[to_additive isAddLeftInvariant_eq_smul]
lemma isMulLeftInvariant_eq_smul [LocallyCompactSpace G] [SecondCountableTopology G]
(μ' μ : Measure G) [IsHaarMeasure μ] [IsFiniteMeasureOnCompacts μ'] [IsMulLeftInvariant μ'] :
μ' = haarScalarFactor μ' μ • μ :=
isMulLeftInvariant_eq_smul_of_regular μ' μ
-- one could use as well `isMulLeftInvariant_eq_smul_of_innerRegular`, as in a
-- second countable topological space all Haar measures are regular and inner regular
@[deprecated (since := "2024-02-12")] alias isHaarMeasure_eq_smul := isMulLeftInvariant_eq_smul
@[deprecated (since := "2024-02-12")] alias isAddHaarMeasure_eq_smul := isAddLeftInvariant_eq_smul
/-- An invariant σ-finite measure is absolutely continuous with respect to a Haar measure in a
second countable group. -/
@[to_additive
"An invariant measure is absolutely continuous with respect to an additive Haar measure. "]
theorem absolutelyContinuous_isHaarMeasure [LocallyCompactSpace G]
[SecondCountableTopology G] (μ ν : Measure G)
[SigmaFinite μ] [IsMulLeftInvariant μ] [IsHaarMeasure ν] : μ ≪ ν := by
have K : PositiveCompacts G := Classical.arbitrary _
have h : haarMeasure K = (haarScalarFactor (haarMeasure K) ν : ℝ≥0∞) • ν :=
isMulLeftInvariant_eq_smul (haarMeasure K) ν
rw [haarMeasure_unique μ K, h, smul_smul]
exact AbsolutelyContinuous.smul (Eq.absolutelyContinuous rfl) _
end Group
section CommGroup
variable {G : Type*} [CommGroup G] [TopologicalSpace G] [TopologicalGroup G]
[MeasurableSpace G] [BorelSpace G] (μ : Measure G) [IsHaarMeasure μ]
/-- Any regular Haar measure is invariant under inversion in an abelian group. -/
@[to_additive "Any regular additive Haar measure is invariant under negation in an abelian group."]
instance (priority := 100) IsHaarMeasure.isInvInvariant_of_regular
[LocallyCompactSpace G] [Regular μ] : IsInvInvariant μ := by
-- the image measure is a Haar measure. By uniqueness up to multiplication, it is of the form
-- `c μ`. Applying again inversion, one gets the measure `c^2 μ`. But since inversion is an
-- involution, this is also `μ`. Hence, `c^2 = 1`, which implies `c = 1`.
constructor
let c : ℝ≥0∞ := haarScalarFactor μ.inv μ
have hc : μ.inv = c • μ := isMulLeftInvariant_eq_smul_of_regular μ.inv μ
have : map Inv.inv (map Inv.inv μ) = c ^ 2 • μ := by
rw [← inv_def μ, hc, Measure.map_smul, ← inv_def μ, hc, smul_smul, pow_two]
have μeq : μ = c ^ 2 • μ := by
rw [map_map continuous_inv.measurable continuous_inv.measurable] at this
simpa only [inv_involutive, Involutive.comp_self, Measure.map_id]
have K : PositiveCompacts G := Classical.arbitrary _
have : c ^ 2 * μ K = 1 ^ 2 * μ K := by
conv_rhs => rw [μeq]
simp
have : c ^ 2 = 1 ^ 2 :=
(ENNReal.mul_eq_mul_right (measure_pos_of_nonempty_interior _ K.interior_nonempty).ne'
K.isCompact.measure_lt_top.ne).1 this
have : c = 1 := (ENNReal.pow_strictMono two_ne_zero).injective this
rw [hc, this, one_smul]
/-- Any inner regular Haar measure is invariant under inversion in an abelian group. -/
@[to_additive "Any regular additive Haar measure is invariant under negation in an abelian group."]
instance (priority := 100) IsHaarMeasure.isInvInvariant_of_innerRegular
[LocallyCompactSpace G] [InnerRegular μ] : IsInvInvariant μ := by
-- the image measure is a Haar measure. By uniqueness up to multiplication, it is of the form
-- `c μ`. Applying again inversion, one gets the measure `c^2 μ`. But since inversion is an
-- involution, this is also `μ`. Hence, `c^2 = 1`, which implies `c = 1`.
constructor
let c : ℝ≥0∞ := haarScalarFactor μ.inv μ
have hc : μ.inv = c • μ := isMulLeftInvariant_eq_smul_of_innerRegular μ.inv μ
have : map Inv.inv (map Inv.inv μ) = c ^ 2 • μ := by
rw [← inv_def μ, hc, Measure.map_smul, ← inv_def μ, hc, smul_smul, pow_two]
have μeq : μ = c ^ 2 • μ := by
rw [map_map continuous_inv.measurable continuous_inv.measurable] at this
simpa only [inv_involutive, Involutive.comp_self, Measure.map_id]
have K : PositiveCompacts G := Classical.arbitrary _
have : c ^ 2 * μ K = 1 ^ 2 * μ K := by
conv_rhs => rw [μeq]
simp
have : c ^ 2 = 1 ^ 2 :=
(ENNReal.mul_eq_mul_right (measure_pos_of_nonempty_interior _ K.interior_nonempty).ne'
K.isCompact.measure_lt_top.ne).1 this
have : c = 1 := (ENNReal.pow_strictMono two_ne_zero).injective this
rw [hc, this, one_smul]
@[to_additive]
theorem measurePreserving_zpow [CompactSpace G] [RootableBy G ℤ] {n : ℤ} (hn : n ≠ 0) :
MeasurePreserving (fun g : G => g ^ n) μ μ :=
{ measurable := (continuous_zpow n).measurable
map_eq := by
let f := @zpowGroupHom G _ n
have hf : Continuous f := continuous_zpow n
have : (μ.map f).IsHaarMeasure :=
isHaarMeasure_map_of_isFiniteMeasure μ f hf (RootableBy.surjective_pow G ℤ hn)
let C : ℝ≥0∞ := haarScalarFactor (μ.map f) μ
have hC : μ.map f = C • μ := isMulLeftInvariant_eq_smul_of_innerRegular _ _
suffices C = 1 by rwa [this, one_smul] at hC
have h_univ : (μ.map f) univ = μ univ := by
rw [map_apply_of_aemeasurable hf.measurable.aemeasurable MeasurableSet.univ,
preimage_univ]
have hμ₀ : μ univ ≠ 0 := IsOpenPosMeasure.open_pos univ isOpen_univ univ_nonempty
have hμ₁ : μ univ ≠ ∞ := CompactSpace.isFiniteMeasure.measure_univ_lt_top.ne
rwa [hC, smul_apply, Algebra.id.smul_eq_mul, mul_comm, ← ENNReal.eq_div_iff hμ₀ hμ₁,
ENNReal.div_self hμ₀ hμ₁] at h_univ }
@[to_additive]
theorem MeasurePreserving.zpow [CompactSpace G] [RootableBy G ℤ]
{n : ℤ} (hn : n ≠ 0) {X : Type*}
[MeasurableSpace X] {μ' : Measure X} {f : X → G} (hf : MeasurePreserving f μ' μ) :
MeasurePreserving (fun x => f x ^ n) μ' μ :=
(measurePreserving_zpow μ hn).comp hf
end CommGroup
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Lebesgue\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Matrix.Diagonal
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.MeasureTheory.Group.LIntegral
import Mathlib.MeasureTheory.Integral.Marginal
import Mathlib.MeasureTheory.Measure.Stieltjes
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
/-!
# Lebesgue measure on the real line and on `ℝⁿ`
We show that the Lebesgue measure on the real line (constructed as a particular case of additive
Haar measure on inner product spaces) coincides with the Stieltjes measure associated
to the function `x ↦ x`. We deduce properties of this measure on `ℝ`, and then of the product
Lebesgue measure on `ℝⁿ`. In particular, we prove that they are translation invariant.
We show that, on `ℝⁿ`, a linear map acts on Lebesgue measure by rescaling it through the absolute
value of its determinant, in `Real.map_linearMap_volume_pi_eq_smul_volume_pi`.
More properties of the Lebesgue measure are deduced from this in
`Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean`, where they are proved more generally for any
additive Haar measure on a finite-dimensional real vector space.
-/
assert_not_exists MeasureTheory.integral
noncomputable section
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
open ENNReal (ofReal)
open scoped ENNReal NNReal Topology
/-!
### Definition of the Lebesgue measure and lengths of intervals
-/
namespace Real
variable {ι : Type*} [Fintype ι]
/-- The volume on the real line (as a particular case of the volume on a finite-dimensional
inner product space) coincides with the Stieltjes measure coming from the identity function. -/
theorem volume_eq_stieltjes_id : (volume : Measure ℝ) = StieltjesFunction.id.measure := by
haveI : IsAddLeftInvariant StieltjesFunction.id.measure :=
⟨fun a =>
Eq.symm <|
Real.measure_ext_Ioo_rat fun p q => by
simp only [Measure.map_apply (measurable_const_add a) measurableSet_Ioo,
sub_sub_sub_cancel_right, StieltjesFunction.measure_Ioo, StieltjesFunction.id_leftLim,
StieltjesFunction.id_apply, id, preimage_const_add_Ioo]⟩
have A : StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped = 1 := by
change StieltjesFunction.id.measure (parallelepiped (stdOrthonormalBasis ℝ ℝ)) = 1
rcases parallelepiped_orthonormalBasis_one_dim (stdOrthonormalBasis ℝ ℝ) with (H | H) <;>
simp only [H, StieltjesFunction.measure_Icc, StieltjesFunction.id_apply, id, tsub_zero,
StieltjesFunction.id_leftLim, sub_neg_eq_add, zero_add, ENNReal.ofReal_one]
conv_rhs =>
rw [addHaarMeasure_unique StieltjesFunction.id.measure
(stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped, A]
simp only [volume, Basis.addHaar, one_smul]
theorem volume_val (s) : volume s = StieltjesFunction.id.measure s := by
simp [volume_eq_stieltjes_id]
@[simp]
theorem volume_Ico {a b : ℝ} : volume (Ico a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
theorem volume_Icc {a b : ℝ} : volume (Icc a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
theorem volume_Ioo {a b : ℝ} : volume (Ioo a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
theorem volume_Ioc {a b : ℝ} : volume (Ioc a b) = ofReal (b - a) := by simp [volume_val]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem volume_singleton {a : ℝ} : volume ({a} : Set ℝ) = 0 := by simp [volume_val]
-- @[simp] -- Porting note (#10618): simp can prove this, after mathlib4#4628
theorem volume_univ : volume (univ : Set ℝ) = ∞ :=
ENNReal.eq_top_of_forall_nnreal_le fun r =>
calc
(r : ℝ≥0∞) = volume (Icc (0 : ℝ) r) := by simp
_ ≤ volume univ := measure_mono (subset_univ _)
@[simp]
theorem volume_ball (a r : ℝ) : volume (Metric.ball a r) = ofReal (2 * r) := by
rw [ball_eq_Ioo, volume_Ioo, ← sub_add, add_sub_cancel_left, two_mul]
@[simp]
theorem volume_closedBall (a r : ℝ) : volume (Metric.closedBall a r) = ofReal (2 * r) := by
rw [closedBall_eq_Icc, volume_Icc, ← sub_add, add_sub_cancel_left, two_mul]
@[simp]
theorem volume_emetric_ball (a : ℝ) (r : ℝ≥0∞) : volume (EMetric.ball a r) = 2 * r := by
rcases eq_or_ne r ∞ with (rfl | hr)
· rw [Metric.emetric_ball_top, volume_univ, two_mul, _root_.top_add]
· lift r to ℝ≥0 using hr
rw [Metric.emetric_ball_nnreal, volume_ball, two_mul, ← NNReal.coe_add,
ENNReal.ofReal_coe_nnreal, ENNReal.coe_add, two_mul]
@[simp]
theorem volume_emetric_closedBall (a : ℝ) (r : ℝ≥0∞) : volume (EMetric.closedBall a r) = 2 * r := by
rcases eq_or_ne r ∞ with (rfl | hr)
· rw [EMetric.closedBall_top, volume_univ, two_mul, _root_.top_add]
· lift r to ℝ≥0 using hr
rw [Metric.emetric_closedBall_nnreal, volume_closedBall, two_mul, ← NNReal.coe_add,
ENNReal.ofReal_coe_nnreal, ENNReal.coe_add, two_mul]
instance noAtoms_volume : NoAtoms (volume : Measure ℝ) :=
⟨fun _ => volume_singleton⟩
@[simp]
theorem volume_interval {a b : ℝ} : volume (uIcc a b) = ofReal |b - a| := by
rw [← Icc_min_max, volume_Icc, max_sub_min_eq_abs]
@[simp]
theorem volume_Ioi {a : ℝ} : volume (Ioi a) = ∞ :=
top_unique <|
le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n =>
calc
(n : ℝ≥0∞) = volume (Ioo a (a + n)) := by simp
_ ≤ volume (Ioi a) := measure_mono Ioo_subset_Ioi_self
@[simp]
theorem volume_Ici {a : ℝ} : volume (Ici a) = ∞ := by rw [← measure_congr Ioi_ae_eq_Ici]; simp
@[simp]
theorem volume_Iio {a : ℝ} : volume (Iio a) = ∞ :=
top_unique <|
le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n =>
calc
(n : ℝ≥0∞) = volume (Ioo (a - n) a) := by simp
_ ≤ volume (Iio a) := measure_mono Ioo_subset_Iio_self
@[simp]
theorem volume_Iic {a : ℝ} : volume (Iic a) = ∞ := by rw [← measure_congr Iio_ae_eq_Iic]; simp
instance locallyFinite_volume : IsLocallyFiniteMeasure (volume : Measure ℝ) :=
⟨fun x =>
⟨Ioo (x - 1) (x + 1),
IsOpen.mem_nhds isOpen_Ioo ⟨sub_lt_self _ zero_lt_one, lt_add_of_pos_right _ zero_lt_one⟩, by
simp only [Real.volume_Ioo, ENNReal.ofReal_lt_top]⟩⟩
instance isFiniteMeasure_restrict_Icc (x y : ℝ) : IsFiniteMeasure (volume.restrict (Icc x y)) :=
⟨by simp⟩
instance isFiniteMeasure_restrict_Ico (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ico x y)) :=
⟨by simp⟩
instance isFiniteMeasure_restrict_Ioc (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ioc x y)) :=
⟨by simp⟩
instance isFiniteMeasure_restrict_Ioo (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ioo x y)) :=
⟨by simp⟩
theorem volume_le_diam (s : Set ℝ) : volume s ≤ EMetric.diam s := by
by_cases hs : Bornology.IsBounded s
· rw [Real.ediam_eq hs, ← volume_Icc]
exact volume.mono hs.subset_Icc_sInf_sSup
· rw [Metric.ediam_of_unbounded hs]; exact le_top
theorem _root_.Filter.Eventually.volume_pos_of_nhds_real {p : ℝ → Prop} {a : ℝ}
(h : ∀ᶠ x in 𝓝 a, p x) : (0 : ℝ≥0∞) < volume { x | p x } := by
rcases h.exists_Ioo_subset with ⟨l, u, hx, hs⟩
refine lt_of_lt_of_le ?_ (measure_mono hs)
simpa [-mem_Ioo] using hx.1.trans hx.2
/-!
### Volume of a box in `ℝⁿ`
-/
theorem volume_Icc_pi {a b : ι → ℝ} : volume (Icc a b) = ∏ i, ENNReal.ofReal (b i - a i) := by
rw [← pi_univ_Icc, volume_pi_pi]
simp only [Real.volume_Icc]
@[simp]
theorem volume_Icc_pi_toReal {a b : ι → ℝ} (h : a ≤ b) :
(volume (Icc a b)).toReal = ∏ i, (b i - a i) := by
simp only [volume_Icc_pi, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))]
theorem volume_pi_Ioo {a b : ι → ℝ} :
volume (pi univ fun i => Ioo (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) :=
(measure_congr Measure.univ_pi_Ioo_ae_eq_Icc).trans volume_Icc_pi
@[simp]
theorem volume_pi_Ioo_toReal {a b : ι → ℝ} (h : a ≤ b) :
(volume (pi univ fun i => Ioo (a i) (b i))).toReal = ∏ i, (b i - a i) := by
simp only [volume_pi_Ioo, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))]
theorem volume_pi_Ioc {a b : ι → ℝ} :
volume (pi univ fun i => Ioc (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) :=
(measure_congr Measure.univ_pi_Ioc_ae_eq_Icc).trans volume_Icc_pi
@[simp]
theorem volume_pi_Ioc_toReal {a b : ι → ℝ} (h : a ≤ b) :
(volume (pi univ fun i => Ioc (a i) (b i))).toReal = ∏ i, (b i - a i) := by
simp only [volume_pi_Ioc, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))]
theorem volume_pi_Ico {a b : ι → ℝ} :
volume (pi univ fun i => Ico (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) :=
(measure_congr Measure.univ_pi_Ico_ae_eq_Icc).trans volume_Icc_pi
@[simp]
theorem volume_pi_Ico_toReal {a b : ι → ℝ} (h : a ≤ b) :
(volume (pi univ fun i => Ico (a i) (b i))).toReal = ∏ i, (b i - a i) := by
simp only [volume_pi_Ico, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))]
@[simp]
nonrec theorem volume_pi_ball (a : ι → ℝ) {r : ℝ} (hr : 0 < r) :
volume (Metric.ball a r) = ENNReal.ofReal ((2 * r) ^ Fintype.card ι) := by
simp only [MeasureTheory.volume_pi_ball a hr, volume_ball, Finset.prod_const]
exact (ENNReal.ofReal_pow (mul_nonneg zero_le_two hr.le) _).symm
@[simp]
nonrec theorem volume_pi_closedBall (a : ι → ℝ) {r : ℝ} (hr : 0 ≤ r) :
volume (Metric.closedBall a r) = ENNReal.ofReal ((2 * r) ^ Fintype.card ι) := by
simp only [MeasureTheory.volume_pi_closedBall a hr, volume_closedBall, Finset.prod_const]
exact (ENNReal.ofReal_pow (mul_nonneg zero_le_two hr) _).symm
theorem volume_pi_le_prod_diam (s : Set (ι → ℝ)) :
volume s ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) :=
calc
volume s ≤ volume (pi univ fun i => closure (Function.eval i '' s)) :=
volume.mono <|
Subset.trans (subset_pi_eval_image univ s) <| pi_mono fun _ _ => subset_closure
_ = ∏ i, volume (closure <| Function.eval i '' s) := volume_pi_pi _
_ ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) :=
Finset.prod_le_prod' fun _ _ => (volume_le_diam _).trans_eq (EMetric.diam_closure _)
theorem volume_pi_le_diam_pow (s : Set (ι → ℝ)) : volume s ≤ EMetric.diam s ^ Fintype.card ι :=
calc
volume s ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := volume_pi_le_prod_diam s
_ ≤ ∏ _i : ι, (1 : ℝ≥0) * EMetric.diam s :=
(Finset.prod_le_prod' fun i _ => (LipschitzWith.eval i).ediam_image_le s)
_ = EMetric.diam s ^ Fintype.card ι := by
simp only [ENNReal.coe_one, one_mul, Finset.prod_const, Fintype.card]
/-!
### Images of the Lebesgue measure under multiplication in ℝ
-/
theorem smul_map_volume_mul_left {a : ℝ} (h : a ≠ 0) :
ENNReal.ofReal |a| • Measure.map (a * ·) volume = volume := by
refine (Real.measure_ext_Ioo_rat fun p q => ?_).symm
cases' lt_or_gt_of_ne h with h h
· simp only [Real.volume_Ioo, Measure.smul_apply, ← ENNReal.ofReal_mul (le_of_lt <| neg_pos.2 h),
Measure.map_apply (measurable_const_mul a) measurableSet_Ioo, neg_sub_neg, neg_mul,
preimage_const_mul_Ioo_of_neg _ _ h, abs_of_neg h, mul_sub, smul_eq_mul,
mul_div_cancel₀ _ (ne_of_lt h)]
· simp only [Real.volume_Ioo, Measure.smul_apply, ← ENNReal.ofReal_mul (le_of_lt h),
Measure.map_apply (measurable_const_mul a) measurableSet_Ioo, preimage_const_mul_Ioo _ _ h,
abs_of_pos h, mul_sub, mul_div_cancel₀ _ (ne_of_gt h), smul_eq_mul]
theorem map_volume_mul_left {a : ℝ} (h : a ≠ 0) :
Measure.map (a * ·) volume = ENNReal.ofReal |a⁻¹| • volume := by
conv_rhs =>
rw [← Real.smul_map_volume_mul_left h, smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ←
abs_mul, inv_mul_cancel h, abs_one, ENNReal.ofReal_one, one_smul]
@[simp]
theorem volume_preimage_mul_left {a : ℝ} (h : a ≠ 0) (s : Set ℝ) :
volume ((a * ·) ⁻¹' s) = ENNReal.ofReal (abs a⁻¹) * volume s :=
calc
volume ((a * ·) ⁻¹' s) = Measure.map (a * ·) volume s :=
((Homeomorph.mulLeft₀ a h).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs a⁻¹) * volume s := by rw [map_volume_mul_left h]; rfl
theorem smul_map_volume_mul_right {a : ℝ} (h : a ≠ 0) :
ENNReal.ofReal |a| • Measure.map (· * a) volume = volume := by
simpa only [mul_comm] using Real.smul_map_volume_mul_left h
theorem map_volume_mul_right {a : ℝ} (h : a ≠ 0) :
Measure.map (· * a) volume = ENNReal.ofReal |a⁻¹| • volume := by
simpa only [mul_comm] using Real.map_volume_mul_left h
@[simp]
theorem volume_preimage_mul_right {a : ℝ} (h : a ≠ 0) (s : Set ℝ) :
volume ((· * a) ⁻¹' s) = ENNReal.ofReal (abs a⁻¹) * volume s :=
calc
volume ((· * a) ⁻¹' s) = Measure.map (· * a) volume s :=
((Homeomorph.mulRight₀ a h).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs a⁻¹) * volume s := by rw [map_volume_mul_right h]; rfl
/-!
### Images of the Lebesgue measure under translation/linear maps in ℝⁿ
-/
open Matrix
/-- A diagonal matrix rescales Lebesgue according to its determinant. This is a special case of
`Real.map_matrix_volume_pi_eq_smul_volume_pi`, that one should use instead (and whose proof
uses this particular case). -/
theorem smul_map_diagonal_volume_pi [DecidableEq ι] {D : ι → ℝ} (h : det (diagonal D) ≠ 0) :
ENNReal.ofReal (abs (det (diagonal D))) • Measure.map (toLin' (diagonal D)) volume =
volume := by
refine (Measure.pi_eq fun s hs => ?_).symm
simp only [det_diagonal, Measure.coe_smul, Algebra.id.smul_eq_mul, Pi.smul_apply]
rw [Measure.map_apply _ (MeasurableSet.univ_pi hs)]
swap; · exact Continuous.measurable (LinearMap.continuous_on_pi _)
have :
(Matrix.toLin' (diagonal D) ⁻¹' Set.pi Set.univ fun i : ι => s i) =
Set.pi Set.univ fun i : ι => (D i * ·) ⁻¹' s i := by
ext f
simp only [LinearMap.coe_proj, Algebra.id.smul_eq_mul, LinearMap.smul_apply, mem_univ_pi,
mem_preimage, LinearMap.pi_apply, diagonal_toLin']
have B : ∀ i, ofReal (abs (D i)) * volume ((D i * ·) ⁻¹' s i) = volume (s i) := by
intro i
have A : D i ≠ 0 := by
simp only [det_diagonal, Ne] at h
exact Finset.prod_ne_zero_iff.1 h i (Finset.mem_univ i)
rw [volume_preimage_mul_left A, ← mul_assoc, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul,
mul_inv_cancel A, abs_one, ENNReal.ofReal_one, one_mul]
rw [this, volume_pi_pi, Finset.abs_prod,
ENNReal.ofReal_prod_of_nonneg fun i _ => abs_nonneg (D i), ← Finset.prod_mul_distrib]
simp only [B]
/-- A transvection preserves Lebesgue measure. -/
theorem volume_preserving_transvectionStruct [DecidableEq ι] (t : TransvectionStruct ι ℝ) :
MeasurePreserving (toLin' t.toMatrix) := by
/- We use `lmarginal` to conveniently use Fubini's theorem.
Along the coordinate where there is a shearing, it acts like a
translation, and therefore preserves Lebesgue. -/
have ht : Measurable (toLin' t.toMatrix) :=
(toLin' t.toMatrix).continuous_of_finiteDimensional.measurable
refine ⟨ht, ?_⟩
refine (pi_eq fun s hs ↦ ?_).symm
have h2s : MeasurableSet (univ.pi s) := .pi countable_univ fun i _ ↦ hs i
simp_rw [← pi_pi, ← lintegral_indicator_one h2s]
rw [lintegral_map (measurable_one.indicator h2s) ht, volume_pi]
refine lintegral_eq_of_lmarginal_eq {t.i} ((measurable_one.indicator h2s).comp ht)
(measurable_one.indicator h2s) ?_
simp_rw [lmarginal_singleton]
ext x
cases t with | mk t_i t_j t_hij t_c =>
simp [transvection, mulVec_stdBasisMatrix, t_hij.symm, ← Function.update_add,
lintegral_add_right_eq_self fun xᵢ ↦ indicator (univ.pi s) 1 (Function.update x t_i xᵢ)]
/-- Any invertible matrix rescales Lebesgue measure through the absolute value of its
determinant. -/
theorem map_matrix_volume_pi_eq_smul_volume_pi [DecidableEq ι] {M : Matrix ι ι ℝ} (hM : det M ≠ 0) :
Measure.map (toLin' M) volume = ENNReal.ofReal (abs (det M)⁻¹) • volume := by
-- This follows from the cases we have already proved, of diagonal matrices and transvections,
-- as these matrices generate all invertible matrices.
apply diagonal_transvection_induction_of_det_ne_zero _ M hM
· intro D hD
conv_rhs => rw [← smul_map_diagonal_volume_pi hD]
rw [smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel hD, abs_one,
ENNReal.ofReal_one, one_smul]
· intro t
simp_rw [Matrix.TransvectionStruct.det, _root_.inv_one, abs_one, ENNReal.ofReal_one, one_smul,
(volume_preserving_transvectionStruct _).map_eq]
· intro A B _ _ IHA IHB
rw [toLin'_mul, det_mul, LinearMap.coe_comp, ← Measure.map_map, IHB, Measure.map_smul, IHA,
smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, mul_comm, mul_inv]
· apply Continuous.measurable
apply LinearMap.continuous_on_pi
· apply Continuous.measurable
apply LinearMap.continuous_on_pi
/-- Any invertible linear map rescales Lebesgue measure through the absolute value of its
determinant. -/
theorem map_linearMap_volume_pi_eq_smul_volume_pi {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ}
(hf : LinearMap.det f ≠ 0) : Measure.map f volume =
ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • volume := by
classical
-- this is deduced from the matrix case
let M := LinearMap.toMatrix' f
have A : LinearMap.det f = det M := by simp only [M, LinearMap.det_toMatrix']
have B : f = toLin' M := by simp only [M, toLin'_toMatrix']
rw [A, B]
apply map_matrix_volume_pi_eq_smul_volume_pi
rwa [A] at hf
end Real
section regionBetween
variable {α : Type*}
/-- The region between two real-valued functions on an arbitrary set. -/
def regionBetween (f g : α → ℝ) (s : Set α) : Set (α × ℝ) :=
{ p : α × ℝ | p.1 ∈ s ∧ p.2 ∈ Ioo (f p.1) (g p.1) }
theorem regionBetween_subset (f g : α → ℝ) (s : Set α) : regionBetween f g s ⊆ s ×ˢ univ := by
simpa only [prod_univ, regionBetween, Set.preimage, setOf_subset_setOf] using fun a => And.left
variable [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ} {s : Set α}
/-- The region between two measurable functions on a measurable set is measurable. -/
theorem measurableSet_regionBetween (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) :
MeasurableSet (regionBetween f g s) := by
dsimp only [regionBetween, Ioo, mem_setOf_eq, setOf_and]
refine
MeasurableSet.inter ?_
((measurableSet_lt (hf.comp measurable_fst) measurable_snd).inter
(measurableSet_lt measurable_snd (hg.comp measurable_fst)))
exact measurable_fst hs
/-- The region between two measurable functions on a measurable set is measurable;
a version for the region together with the graph of the upper function. -/
theorem measurableSet_region_between_oc (hf : Measurable f) (hg : Measurable g)
(hs : MeasurableSet s) :
MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Ioc (f p.fst) (g p.fst) } := by
dsimp only [regionBetween, Ioc, mem_setOf_eq, setOf_and]
refine
MeasurableSet.inter ?_
((measurableSet_lt (hf.comp measurable_fst) measurable_snd).inter
(measurableSet_le measurable_snd (hg.comp measurable_fst)))
exact measurable_fst hs
/-- The region between two measurable functions on a measurable set is measurable;
a version for the region together with the graph of the lower function. -/
theorem measurableSet_region_between_co (hf : Measurable f) (hg : Measurable g)
(hs : MeasurableSet s) :
MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Ico (f p.fst) (g p.fst) } := by
dsimp only [regionBetween, Ico, mem_setOf_eq, setOf_and]
refine
MeasurableSet.inter ?_
((measurableSet_le (hf.comp measurable_fst) measurable_snd).inter
(measurableSet_lt measurable_snd (hg.comp measurable_fst)))
exact measurable_fst hs
/-- The region between two measurable functions on a measurable set is measurable;
a version for the region together with the graphs of both functions. -/
theorem measurableSet_region_between_cc (hf : Measurable f) (hg : Measurable g)
(hs : MeasurableSet s) :
MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Icc (f p.fst) (g p.fst) } := by
dsimp only [regionBetween, Icc, mem_setOf_eq, setOf_and]
refine
MeasurableSet.inter ?_
((measurableSet_le (hf.comp measurable_fst) measurable_snd).inter
(measurableSet_le measurable_snd (hg.comp measurable_fst)))
exact measurable_fst hs
/-- The graph of a measurable function is a measurable set. -/
theorem measurableSet_graph (hf : Measurable f) :
MeasurableSet { p : α × ℝ | p.snd = f p.fst } := by
simpa using measurableSet_region_between_cc hf hf MeasurableSet.univ
theorem volume_regionBetween_eq_lintegral' (hf : Measurable f) (hg : Measurable g)
(hs : MeasurableSet s) :
μ.prod volume (regionBetween f g s) = ∫⁻ y in s, ENNReal.ofReal ((g - f) y) ∂μ := by
classical
rw [Measure.prod_apply]
· have h :
(fun x => volume { a | x ∈ s ∧ a ∈ Ioo (f x) (g x) }) =
s.indicator fun x => ENNReal.ofReal (g x - f x) := by
funext x
rw [indicator_apply]
split_ifs with h
· have hx : { a | x ∈ s ∧ a ∈ Ioo (f x) (g x) } = Ioo (f x) (g x) := by simp [h, Ioo]
simp only [hx, Real.volume_Ioo, sub_zero]
· have hx : { a | x ∈ s ∧ a ∈ Ioo (f x) (g x) } = ∅ := by simp [h]
simp only [hx, measure_empty]
dsimp only [regionBetween, preimage_setOf_eq]
rw [h, lintegral_indicator] <;> simp only [hs, Pi.sub_apply]
· exact measurableSet_regionBetween hf hg hs
/-- The volume of the region between two almost everywhere measurable functions on a measurable set
can be represented as a Lebesgue integral. -/
theorem volume_regionBetween_eq_lintegral [SFinite μ] (hf : AEMeasurable f (μ.restrict s))
(hg : AEMeasurable g (μ.restrict s)) (hs : MeasurableSet s) :
μ.prod volume (regionBetween f g s) = ∫⁻ y in s, ENNReal.ofReal ((g - f) y) ∂μ := by
have h₁ :
(fun y => ENNReal.ofReal ((g - f) y)) =ᵐ[μ.restrict s] fun y =>
ENNReal.ofReal ((AEMeasurable.mk g hg - AEMeasurable.mk f hf) y) :=
(hg.ae_eq_mk.sub hf.ae_eq_mk).fun_comp ENNReal.ofReal
have h₂ :
(μ.restrict s).prod volume (regionBetween f g s) =
(μ.restrict s).prod volume
(regionBetween (AEMeasurable.mk f hf) (AEMeasurable.mk g hg) s) := by
apply measure_congr
apply EventuallyEq.rfl.inter
exact
((quasiMeasurePreserving_fst.ae_eq_comp hf.ae_eq_mk).comp₂ _ EventuallyEq.rfl).inter
(EventuallyEq.rfl.comp₂ _ <| quasiMeasurePreserving_fst.ae_eq_comp hg.ae_eq_mk)
rw [lintegral_congr_ae h₁, ←
volume_regionBetween_eq_lintegral' hf.measurable_mk hg.measurable_mk hs]
convert h₂ using 1
· rw [Measure.restrict_prod_eq_prod_univ]
exact (Measure.restrict_eq_self _ (regionBetween_subset f g s)).symm
· rw [Measure.restrict_prod_eq_prod_univ]
exact
(Measure.restrict_eq_self _
(regionBetween_subset (AEMeasurable.mk f hf) (AEMeasurable.mk g hg) s)).symm
/-- The region between two a.e.-measurable functions on a null-measurable set is null-measurable. -/
lemma nullMeasurableSet_regionBetween (μ : Measure α)
{f g : α → ℝ} (f_mble : AEMeasurable f μ) (g_mble : AEMeasurable g μ)
{s : Set α} (s_mble : NullMeasurableSet s μ) :
NullMeasurableSet {p : α × ℝ | p.1 ∈ s ∧ p.snd ∈ Ioo (f p.fst) (g p.fst)} (μ.prod volume) := by
refine NullMeasurableSet.inter
(s_mble.preimage quasiMeasurePreserving_fst) (NullMeasurableSet.inter ?_ ?_)
· exact nullMeasurableSet_lt (AEMeasurable.fst f_mble) measurable_snd.aemeasurable
· exact nullMeasurableSet_lt measurable_snd.aemeasurable (AEMeasurable.fst g_mble)
/-- The region between two a.e.-measurable functions on a null-measurable set is null-measurable;
a version for the region together with the graph of the upper function. -/
lemma nullMeasurableSet_region_between_oc (μ : Measure α)
{f g : α → ℝ} (f_mble : AEMeasurable f μ) (g_mble : AEMeasurable g μ)
{s : Set α} (s_mble : NullMeasurableSet s μ) :
NullMeasurableSet {p : α × ℝ | p.1 ∈ s ∧ p.snd ∈ Ioc (f p.fst) (g p.fst)} (μ.prod volume) := by
refine NullMeasurableSet.inter
(s_mble.preimage quasiMeasurePreserving_fst) (NullMeasurableSet.inter ?_ ?_)
· exact nullMeasurableSet_lt (AEMeasurable.fst f_mble) measurable_snd.aemeasurable
· change NullMeasurableSet {p : α × ℝ | p.snd ≤ g p.fst} (μ.prod volume)
rw [show {p : α × ℝ | p.snd ≤ g p.fst} = {p : α × ℝ | g p.fst < p.snd}ᶜ by
ext p
simp only [mem_setOf_eq, mem_compl_iff, not_lt]]
exact (nullMeasurableSet_lt (AEMeasurable.fst g_mble) measurable_snd.aemeasurable).compl
/-- The region between two a.e.-measurable functions on a null-measurable set is null-measurable;
a version for the region together with the graph of the lower function. -/
lemma nullMeasurableSet_region_between_co (μ : Measure α)
{f g : α → ℝ} (f_mble : AEMeasurable f μ) (g_mble : AEMeasurable g μ)
{s : Set α} (s_mble : NullMeasurableSet s μ) :
NullMeasurableSet {p : α × ℝ | p.1 ∈ s ∧ p.snd ∈ Ico (f p.fst) (g p.fst)} (μ.prod volume) := by
refine NullMeasurableSet.inter
(s_mble.preimage quasiMeasurePreserving_fst) (NullMeasurableSet.inter ?_ ?_)
· change NullMeasurableSet {p : α × ℝ | f p.fst ≤ p.snd} (μ.prod volume)
rw [show {p : α × ℝ | f p.fst ≤ p.snd} = {p : α × ℝ | p.snd < f p.fst}ᶜ by
ext p
simp only [mem_setOf_eq, mem_compl_iff, not_lt]]
exact (nullMeasurableSet_lt measurable_snd.aemeasurable (AEMeasurable.fst f_mble)).compl
· exact nullMeasurableSet_lt measurable_snd.aemeasurable (AEMeasurable.fst g_mble)
/-- The region between two a.e.-measurable functions on a null-measurable set is null-measurable;
a version for the region together with the graphs of both functions. -/
lemma nullMeasurableSet_region_between_cc (μ : Measure α)
{f g : α → ℝ} (f_mble : AEMeasurable f μ) (g_mble : AEMeasurable g μ)
{s : Set α} (s_mble : NullMeasurableSet s μ) :
NullMeasurableSet {p : α × ℝ | p.1 ∈ s ∧ p.snd ∈ Icc (f p.fst) (g p.fst)} (μ.prod volume) := by
refine NullMeasurableSet.inter
(s_mble.preimage quasiMeasurePreserving_fst) (NullMeasurableSet.inter ?_ ?_)
· change NullMeasurableSet {p : α × ℝ | f p.fst ≤ p.snd} (μ.prod volume)
rw [show {p : α × ℝ | f p.fst ≤ p.snd} = {p : α × ℝ | p.snd < f p.fst}ᶜ by
ext p
simp only [mem_setOf_eq, mem_compl_iff, not_lt]]
exact (nullMeasurableSet_lt measurable_snd.aemeasurable (AEMeasurable.fst f_mble)).compl
· change NullMeasurableSet {p : α × ℝ | p.snd ≤ g p.fst} (μ.prod volume)
rw [show {p : α × ℝ | p.snd ≤ g p.fst} = {p : α × ℝ | g p.fst < p.snd}ᶜ by
ext p
simp only [mem_setOf_eq, mem_compl_iff, not_lt]]
exact (nullMeasurableSet_lt (AEMeasurable.fst g_mble) measurable_snd.aemeasurable).compl
end regionBetween
/-- Consider a real set `s`. If a property is true almost everywhere in `s ∩ (a, b)` for
all `a, b ∈ s`, then it is true almost everywhere in `s`. Formulated with `μ.restrict`.
See also `ae_of_mem_of_ae_of_mem_inter_Ioo`. -/
theorem ae_restrict_of_ae_restrict_inter_Ioo {μ : Measure ℝ} [NoAtoms μ] {s : Set ℝ} {p : ℝ → Prop}
(h : ∀ a b, a ∈ s → b ∈ s → a < b → ∀ᵐ x ∂μ.restrict (s ∩ Ioo a b), p x) :
∀ᵐ x ∂μ.restrict s, p x := by
/- By second-countability, we cover `s` by countably many intervals `(a, b)` (except maybe for
two endpoints, which don't matter since `μ` does not have any atom). -/
let T : s × s → Set ℝ := fun p => Ioo p.1 p.2
let u := ⋃ i : ↥s × ↥s, T i
have hfinite : (s \ u).Finite := s.finite_diff_iUnion_Ioo'
obtain ⟨A, A_count, hA⟩ :
∃ A : Set (↥s × ↥s), A.Countable ∧ ⋃ i ∈ A, T i = ⋃ i : ↥s × ↥s, T i :=
isOpen_iUnion_countable _ fun p => isOpen_Ioo
have : s ⊆ s \ u ∪ ⋃ p ∈ A, s ∩ T p := by
intro x hx
by_cases h'x : x ∈ ⋃ i : ↥s × ↥s, T i
· rw [← hA] at h'x
obtain ⟨p, pA, xp⟩ : ∃ p : ↥s × ↥s, p ∈ A ∧ x ∈ T p := by
simpa only [mem_iUnion, exists_prop, SetCoe.exists, exists_and_right] using h'x
right
exact mem_biUnion pA ⟨hx, xp⟩
· exact Or.inl ⟨hx, h'x⟩
apply ae_restrict_of_ae_restrict_of_subset this
rw [ae_restrict_union_iff, ae_restrict_biUnion_iff _ A_count]
constructor
· have : μ.restrict (s \ u) = 0 := by simp only [restrict_eq_zero, hfinite.measure_zero]
simp only [this, ae_zero, eventually_bot]
· rintro ⟨⟨a, as⟩, ⟨b, bs⟩⟩ -
dsimp [T]
rcases le_or_lt b a with (hba | hab)
· simp only [Ioo_eq_empty_of_le hba, inter_empty, restrict_empty, ae_zero, eventually_bot]
· exact h a b as bs hab
/-- Consider a real set `s`. If a property is true almost everywhere in `s ∩ (a, b)` for
all `a, b ∈ s`, then it is true almost everywhere in `s`. Formulated with bare membership.
See also `ae_restrict_of_ae_restrict_inter_Ioo`. -/
theorem ae_of_mem_of_ae_of_mem_inter_Ioo {μ : Measure ℝ} [NoAtoms μ] {s : Set ℝ} {p : ℝ → Prop}
(h : ∀ a b, a ∈ s → b ∈ s → a < b → ∀ᵐ x ∂μ, x ∈ s ∩ Ioo a b → p x) :
∀ᵐ x ∂μ, x ∈ s → p x := by
/- By second-countability, we cover `s` by countably many intervals `(a, b)` (except maybe for
two endpoints, which don't matter since `μ` does not have any atom). -/
let T : s × s → Set ℝ := fun p => Ioo p.1 p.2
let u := ⋃ i : ↥s × ↥s, T i
have hfinite : (s \ u).Finite := s.finite_diff_iUnion_Ioo'
obtain ⟨A, A_count, hA⟩ :
∃ A : Set (↥s × ↥s), A.Countable ∧ ⋃ i ∈ A, T i = ⋃ i : ↥s × ↥s, T i :=
isOpen_iUnion_countable _ fun p => isOpen_Ioo
have M : ∀ᵐ x ∂μ, x ∉ s \ u := hfinite.countable.ae_not_mem _
have M' : ∀ᵐ x ∂μ, ∀ (i : ↥s × ↥s), i ∈ A → x ∈ s ∩ T i → p x := by
rw [ae_ball_iff A_count]
rintro ⟨⟨a, as⟩, ⟨b, bs⟩⟩ -
change ∀ᵐ x : ℝ ∂μ, x ∈ s ∩ Ioo a b → p x
rcases le_or_lt b a with (hba | hab)
· simp only [Ioo_eq_empty_of_le hba, inter_empty, IsEmpty.forall_iff, eventually_true,
mem_empty_iff_false]
· exact h a b as bs hab
filter_upwards [M, M'] with x hx h'x
intro xs
by_cases Hx : x ∈ ⋃ i : ↥s × ↥s, T i
· rw [← hA] at Hx
obtain ⟨p, pA, xp⟩ : ∃ p : ↥s × ↥s, p ∈ A ∧ x ∈ T p := by
simpa only [mem_iUnion, exists_prop, SetCoe.exists, exists_and_right] using Hx
apply h'x p pA ⟨xs, xp⟩
· exact False.elim (hx ⟨xs, Hx⟩)
|
MeasureTheory\Measure\Lebesgue\Complex.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace
import Mathlib.MeasureTheory.Constructions.BorelSpace.Complex
/-!
# Lebesgue measure on `ℂ`
In this file, we consider the Lebesgue measure on `ℂ` defined as the push-forward of the volume
on `ℝ²` under the natural isomorphism and prove that it is equal to the measure `volume` of `ℂ`
coming from its `InnerProductSpace` structure over `ℝ`. For that, we consider the two frequently
used ways to represent `ℝ²` in `mathlib`: `ℝ × ℝ` and `Fin 2 → ℝ`, define measurable equivalences
(`MeasurableEquiv`) to both types and prove that both of them are volume preserving (in the sense
of `MeasureTheory.measurePreserving`).
-/
open MeasureTheory
noncomputable section
namespace Complex
/-- Measurable equivalence between `ℂ` and `ℝ² = Fin 2 → ℝ`. -/
def measurableEquivPi : ℂ ≃ᵐ (Fin 2 → ℝ) :=
basisOneI.equivFun.toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv
@[simp]
theorem measurableEquivPi_apply (a : ℂ) :
measurableEquivPi a = ![a.re, a.im] := rfl
@[simp]
theorem measurableEquivPi_symm_apply (p : (Fin 2) → ℝ) :
measurableEquivPi.symm p = (p 0) + (p 1) * I := rfl
/-- Measurable equivalence between `ℂ` and `ℝ × ℝ`. -/
def measurableEquivRealProd : ℂ ≃ᵐ ℝ × ℝ :=
equivRealProdCLM.toHomeomorph.toMeasurableEquiv
@[simp]
theorem measurableEquivRealProd_apply (a : ℂ) : measurableEquivRealProd a = (a.re, a.im) := rfl
@[simp]
theorem measurableEquivRealProd_symm_apply (p : ℝ × ℝ) :
measurableEquivRealProd.symm p = {re := p.1, im := p.2} := rfl
theorem volume_preserving_equiv_pi : MeasurePreserving measurableEquivPi := by
convert (measurableEquivPi.symm.measurable.measurePreserving volume).symm
rw [← addHaarMeasure_eq_volume_pi, ← Basis.parallelepiped_basisFun, ← Basis.addHaar,
measurableEquivPi, Homeomorph.toMeasurableEquiv_symm_coe,
ContinuousLinearEquiv.symm_toHomeomorph, ContinuousLinearEquiv.coe_toHomeomorph,
Basis.map_addHaar, eq_comm]
exact (Basis.addHaar_eq_iff _ _).mpr Complex.orthonormalBasisOneI.volume_parallelepiped
theorem volume_preserving_equiv_real_prod : MeasurePreserving measurableEquivRealProd :=
(volume_preserving_finTwoArrow ℝ).comp volume_preserving_equiv_pi
end Complex
|
MeasureTheory\Measure\Lebesgue\EqHaar.lean | /-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Sébastien Gouëzel
-/
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.MeasureTheory.Measure.Doubling
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric
/-!
# Relationship between the Haar and Lebesgue measures
We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in
`MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`.
We deduce basic properties of any Haar measure on a finite dimensional real vector space:
* `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the
absolute value of its determinant.
* `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure
of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the
determinant of `f`.
* `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the
measure of `s` multiplied by the absolute value of the determinant of `f`.
* `addHaar_submodule` : a strict submodule has measure `0`.
* `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`.
* `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_sphere`: spheres have zero measure.
This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`.
This measure is called `AlternatingMap.measure`. Its main property is
`ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned
by vectors `v₁, ..., vₙ` is given by `|ω v|`.
We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has
density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in
`tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for
small `r`, see `eventually_nonempty_inter_smul_of_density_one`.
Statements on integrals of functions with respect to an additive Haar measure can be found in
`MeasureTheory.Measure.Haar.NormedSpace`.
-/
assert_not_exists MeasureTheory.integral
open TopologicalSpace Set Filter Metric Bornology
open scoped ENNReal Pointwise Topology NNReal
/-- The interval `[0,1]` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where
carrier := Icc 0 1
isCompact' := isCompact_Icc
interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]
universe u
/-- The set `[0,1]^ι` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] :
PositiveCompacts (ι → ℝ) where
carrier := pi univ fun _ => Icc 0 1
isCompact' := isCompact_univ_pi fun _ => isCompact_Icc
interior_nonempty' := by
simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,
imp_true_iff, zero_lt_one]
/-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/
theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] :
(Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι :=
SetLike.coe_injective <| by
refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm)
· classical convert parallelepiped_single (ι := ι) 1
· exact zero_le_one
/-- A parallelepiped can be expressed on the standard basis. -/
theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E]
[NormedSpace ℝ E] (b : Basis ι ℝ E) :
b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm
b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by
classical
rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map]
congr with x
simp
open MeasureTheory MeasureTheory.Measure
theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F]
[NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E]
[BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F]
(b : Basis ι ℝ E) (f : E ≃L[ℝ] F) :
map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by
have : IsAddHaarMeasure (map f b.addHaar) :=
AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous
rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable
(PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map]
erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self]
namespace MeasureTheory
open Measure TopologicalSpace.PositiveCompacts FiniteDimensional
/-!
### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`.
-/
/-- The Haar measure equals the Lebesgue measure on `ℝ`. -/
theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by
convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01]
/-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/
theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] :
addHaarMeasure (piIcc01 ι) = volume := by
convert (addHaarMeasure_unique volume (piIcc01 ι)).symm
simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk,
Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero]
-- Porting note (#11215): TODO: remove this instance?
instance isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] :
IsAddHaarMeasure (volume : Measure (ι → ℝ)) :=
inferInstance
namespace Measure
/-!
### Strict subspaces have zero measure
-/
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/
theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
by_contra h
apply lt_irrefl ∞
calc
∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm
_ = ∑' n : ℕ, μ ({u n} + s) := by
congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add]
_ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by
simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's
_ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range]
_ < ∞ := (hu.add sb).measure_lt_top
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. -/
theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by
apply le_antisymm _ (zero_le _)
calc
μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by
conv_lhs => rw [← iUnion_inter_closedBall_nat s 0]
exact measure_iUnion_le _
_ = 0 := by simp only [H, tsum_zero]
intro R
apply addHaar_eq_zero_of_disjoint_translates_aux μ u
(isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall)
refine pairwise_disjoint_mono hs fun n => ?_
exact add_subset_add Subset.rfl inter_subset_left
/-- A strict vector subspace has measure zero. -/
theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E]
[BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E)
(hs : s ≠ ⊤) : μ s = 0 := by
obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by
simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs
obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩
have A : IsBounded (range fun n : ℕ => c ^ n • x) :=
have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) :=
(tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x
isBounded_range_of_tendsto _ this
apply addHaar_eq_zero_of_disjoint_translates μ _ A _
(Submodule.closed_of_finiteDimensional s).measurableSet
intro m n hmn
simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage,
SetLike.mem_coe]
intro y hym hyn
have A : (c ^ n - c ^ m) • x ∈ s := by
convert s.sub_mem hym hyn using 1
simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub]
have H : c ^ n - c ^ m ≠ 0 := by
simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti cpos cone).injective.ne hmn.symm
have : x ∈ s := by
convert s.smul_mem (c ^ n - c ^ m)⁻¹ A
rw [smul_smul, inv_mul_cancel H, one_smul]
exact hx this
/-- A strict affine subspace has measure zero. -/
theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
(s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by
rcases s.eq_bot_or_nonempty with (rfl | hne)
· rw [AffineSubspace.bot_coe, measure_empty]
rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs
rcases hne with ⟨x, hx : x ∈ s⟩
simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg,
image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs
/-!
### Applying a linear map rescales Haar measure by the determinant
We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue
measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real
vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a
linear equiv maps Haar measure to Haar measure.
-/
theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ}
(hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] :
Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by
cases nonempty_fintype ι
/- We have already proved the result for the Lebesgue product measure, using matrices.
We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/
have := addHaarMeasure_unique μ (piIcc01 ι)
rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul,
Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {F : Type*} [NormedAddCommGroup F]
[NormedSpace ℝ F] [CompleteSpace F]
theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) :
Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by
-- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using
-- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`.
let ι := Fin (finrank ℝ E)
haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance
have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι]
have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this
-- next line is to avoid `g` getting reduced by `simp`.
obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩
have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e
rw [← gdet] at hf ⊢
have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by
ext x
simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp,
LinearEquiv.symm_apply_apply, hg]
simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp]
have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional
have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g
have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional
rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable]
haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm
have ecomp : e.symm ∘ e = id := by
ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply]
rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul,
map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id]
/-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s :=
calc
μ (f ⁻¹' s) = Measure.map f μ s :=
((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply
s).symm
_ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl
/-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E}
(hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s :=
addHaar_preimage_linearMap μ hf s
/-- The preimage of a set `s` under a linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by
have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero
convert addHaar_preimage_linearMap μ A s
simp only [LinearEquiv.det_coe_symm]
/-- The preimage of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s :=
addHaar_preimage_linearEquiv μ _ s
/-- The image of a set `s` under a linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by
rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf)
· let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv
change μ (g '' s) = _
rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv]
congr
· simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero]
have : μ (LinearMap.range f) = 0 :=
addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne
exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _)
/-- The image of a set `s` under a continuous linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
addHaar_image_linearMap μ _ s
/-- The image of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s
theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) :
QuasiMeasurePreserving f μ μ := by
refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]
exact smul_absolutelyContinuous
theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) :
QuasiMeasurePreserving f μ μ :=
LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf
/-!
### Basic properties of Haar measures on real vector spaces
-/
theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) :
Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by
let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E)
change Measure.map f μ = _
have hf : LinearMap.det f ≠ 0 := by
simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one]
intro h
exact hr (pow_eq_zero h)
simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one]
theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) :
QuasiMeasurePreserving (r • ·) μ μ := by
refine ⟨measurable_const_smul r, ?_⟩
rw [map_addHaar_smul μ hr]
exact smul_absolutelyContinuous
@[simp]
theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) :
μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s :=
calc
μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s :=
((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by
rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul]
/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/
@[simp]
theorem addHaar_smul (r : ℝ) (s : Set E) :
μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
rcases ne_or_eq r 0 with (h | rfl)
· rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv]
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp only [measure_empty, mul_zero, smul_set_empty]
rw [zero_smul_set hs, ← singleton_zero]
by_cases h : finrank ℝ E = 0
· haveI : Subsingleton E := finrank_zero_iff.1 h
simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs,
pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))]
· haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h)
simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff,
zero_pow, measure_singleton]
theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) :
μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by
rw [addHaar_smul, abs_pow, abs_of_nonneg hr]
variable {μ} {s : Set E}
-- Note: We might want to rename this once we acquire the lemma corresponding to
-- `MeasurableSet.const_smul`
theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) :
NullMeasurableSet (r • s) μ := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simp
obtain rfl | hr := eq_or_ne r 0
· simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _
obtain ⟨t, ht, hst⟩ := hs
refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩
rw [← measure_symmDiff_eq_zero_iff] at hst ⊢
rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero]
variable (μ)
@[simp]
theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) :
μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s :=
calc
μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by
simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
simp only [image_add_right, measure_preimage_add_right, addHaar_smul]
/-! We don't need to state `map_addHaar_neg` here, because it has already been proved for
general Haar measures on general commutative groups. -/
/-! ### Measure of balls -/
theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E]
(μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by
have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball]
rw [this, measure_preimage_add]
theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (closedBall (0 : E) r) := by
have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall]
rw [this, measure_preimage_add]
theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
have : ball (0 : E) (r * s) = r • ball (0 : E) s := by
simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow]
theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul_of_pos μ x hr, mul_one]
theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
rcases hr.eq_or_lt with (rfl | h)
· simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul,
ENNReal.ofReal_zero, ball_zero]
· exact addHaar_ball_mul_of_pos μ x h s
theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul μ x hr, mul_one]
theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow]
theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr]
simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow]
/-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball.
Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard
form. -/
theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by
rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one]
theorem addHaar_closed_unit_ball_eq_addHaar_unit_ball :
μ (closedBall (0 : E) 1) = μ (ball 0 1) := by
apply le_antisymm _ (measure_mono ball_subset_closedBall)
have A : Tendsto
(fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall (0 : E) 1)) (𝓝[<] 1)
(𝓝 (ENNReal.ofReal ((1 : ℝ) ^ finrank ℝ E) * μ (closedBall (0 : E) 1))) := by
refine ENNReal.Tendsto.mul ?_ (by simp) tendsto_const_nhds (by simp)
exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _)
simp only [one_pow, one_mul, ENNReal.ofReal_one] at A
refine le_of_tendsto A ?_
refine mem_nhdsWithin_Iio_iff_exists_Ioo_subset.2 ⟨(0 : ℝ), by simp, fun r hr => ?_⟩
dsimp
rw [← addHaar_closedBall' μ (0 : E) hr.1.le]
exact measure_mono (closedBall_subset_ball hr.2)
theorem addHaar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [addHaar_closedBall' μ x hr, addHaar_closed_unit_ball_eq_addHaar_unit_ball]
theorem addHaar_closedBall_eq_addHaar_ball [Nontrivial E] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (ball x r) := by
by_cases h : r < 0
· rw [Metric.closedBall_eq_empty.mpr h, Metric.ball_eq_empty.mpr h.le]
push_neg at h
rw [addHaar_closedBall μ x h, addHaar_ball μ x h]
theorem addHaar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 := by
rcases hr.lt_or_lt with (h | h)
· simp only [empty_diff, measure_empty, ← closedBall_diff_ball, closedBall_eq_empty.2 h]
· rw [← closedBall_diff_ball,
measure_diff ball_subset_closedBall measurableSet_ball measure_ball_lt_top.ne,
addHaar_ball_of_pos μ _ h, addHaar_closedBall μ _ h.le, tsub_self]
theorem addHaar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 := by
rcases eq_or_ne r 0 with (rfl | h)
· rw [sphere_zero, measure_singleton]
· exact addHaar_sphere_of_ne_zero μ x h
theorem addHaar_singleton_add_smul_div_singleton_add_smul {r : ℝ} (hr : r ≠ 0) (x y : E)
(s t : Set E) : μ ({x} + r • s) / μ ({y} + r • t) = μ s / μ t :=
calc
μ ({x} + r • s) / μ ({y} + r • t) = ENNReal.ofReal (|r| ^ finrank ℝ E) * μ s *
(ENNReal.ofReal (|r| ^ finrank ℝ E) * μ t)⁻¹ := by
simp only [div_eq_mul_inv, addHaar_smul, image_add_left, measure_preimage_add, abs_pow,
singleton_add]
_ = ENNReal.ofReal (|r| ^ finrank ℝ E) * (ENNReal.ofReal (|r| ^ finrank ℝ E))⁻¹ *
(μ s * (μ t)⁻¹) := by
rw [ENNReal.mul_inv]
· ring
· simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne, true_or_iff]
· simp only [ENNReal.ofReal_ne_top, true_or_iff, Ne, not_false_iff]
_ = μ s / μ t := by
rw [ENNReal.mul_inv_cancel, one_mul, div_eq_mul_inv]
· simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne]
· simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff]
instance (priority := 100) isUnifLocDoublingMeasureOfIsAddHaarMeasure :
IsUnifLocDoublingMeasure μ := by
refine ⟨⟨(2 : ℝ≥0) ^ finrank ℝ E, ?_⟩⟩
filter_upwards [self_mem_nhdsWithin] with r hr x
rw [addHaar_closedBall_mul μ x zero_le_two (le_of_lt hr), addHaar_closedBall_center μ x,
ENNReal.ofReal, Real.toNNReal_pow zero_le_two]
simp only [Real.toNNReal_ofNat, le_refl]
section
/-!
### The Lebesgue measure associated to an alternating map
-/
variable {ι G : Type*} [Fintype ι] [DecidableEq ι] [NormedAddCommGroup G] [NormedSpace ℝ G]
[MeasurableSpace G] [BorelSpace G]
theorem addHaar_parallelepiped (b : Basis ι ℝ G) (v : ι → G) :
b.addHaar (parallelepiped v) = ENNReal.ofReal |b.det v| := by
have : FiniteDimensional ℝ G := FiniteDimensional.of_fintype_basis b
have A : parallelepiped v = b.constr ℕ v '' parallelepiped b := by
rw [image_parallelepiped]
-- Porting note: was `congr 1 with i` but Lean 4 `congr` applies `ext` first
refine congr_arg _ <| funext fun i ↦ ?_
exact (b.constr_basis ℕ v i).symm
rw [A, addHaar_image_linearMap, b.addHaar_self, mul_one, ← LinearMap.det_toMatrix b,
← Basis.toMatrix_eq_toMatrix_constr, Basis.det_apply]
variable [FiniteDimensional ℝ G] {n : ℕ} [_i : Fact (finrank ℝ G = n)]
/-- The Lebesgue measure associated to an alternating map. It gives measure `|ω v|` to the
parallelepiped spanned by the vectors `v₁, ..., vₙ`. Note that it is not always a Haar measure,
as it can be zero, but it is always locally finite and translation invariant. -/
noncomputable irreducible_def _root_.AlternatingMap.measure (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) :
Measure G :=
‖ω (finBasisOfFinrankEq ℝ G _i.out)‖₊ • (finBasisOfFinrankEq ℝ G _i.out).addHaar
theorem _root_.AlternatingMap.measure_parallelepiped (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ)
(v : Fin n → G) : ω.measure (parallelepiped v) = ENNReal.ofReal |ω v| := by
conv_rhs => rw [ω.eq_smul_basis_det (finBasisOfFinrankEq ℝ G _i.out)]
simp only [addHaar_parallelepiped, AlternatingMap.measure, coe_nnreal_smul_apply,
AlternatingMap.smul_apply, Algebra.id.smul_eq_mul, abs_mul, ENNReal.ofReal_mul (abs_nonneg _),
Real.ennnorm_eq_ofReal_abs]
instance (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) : IsAddLeftInvariant ω.measure := by
rw [AlternatingMap.measure]; infer_instance
instance (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) : IsLocallyFiniteMeasure ω.measure := by
rw [AlternatingMap.measure]; infer_instance
end
/-!
### Density points
Besicovitch covering theorem ensures that, for any locally finite measure on a finite-dimensional
real vector space, almost every point of a set `s` is a density point, i.e.,
`μ (s ∩ closedBall x r) / μ (closedBall x r)` tends to `1` as `r` tends to `0`
(see `Besicovitch.ae_tendsto_measure_inter_div`).
When `μ` is a Haar measure, one can deduce the same property for any rescaling sequence of sets,
of the form `{x} + r • t` where `t` is a set with positive finite measure, instead of the sequence
of closed balls.
We argue first for the dual property, i.e., if `s` has density `0` at `x`, then
`μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)` tends to `0`. First when `t` is contained in the ball
of radius `1`, in `tendsto_addHaar_inter_smul_zero_of_density_zero_aux1`,
(by arguing by inclusion). Then when `t` is bounded, reducing to the previous one by rescaling, in
`tendsto_addHaar_inter_smul_zero_of_density_zero_aux2`.
Then for a general set `t`, by cutting it into a bounded part and a part with small measure, in
`tendsto_addHaar_inter_smul_zero_of_density_zero`.
Going to the complement, one obtains the desired property at points of density `1`, first when
`s` is measurable in `tendsto_addHaar_inter_smul_one_of_density_one_aux`, and then without this
assumption in `tendsto_addHaar_inter_smul_one_of_density_one` by applying the previous lemma to
the measurable hull `toMeasurable μ s`
-/
theorem tendsto_addHaar_inter_smul_zero_of_density_zero_aux1 (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)
(u : Set E) (h'u : μ u ≠ 0) (t_bound : t ⊆ closedBall 0 1) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) (𝓝[>] 0) (𝓝 0) := by
have A : Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0) := by
apply
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds h
(eventually_of_forall fun b => zero_le _)
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
rw [← affinity_unitClosedBall rpos.le, singleton_add, ← image_vadd]
gcongr
exact smul_set_mono t_bound
have B :
Tendsto (fun r : ℝ => μ (closedBall x r) / μ ({x} + r • u)) (𝓝[>] 0)
(𝓝 (μ (closedBall x 1) / μ ({x} + u))) := by
apply tendsto_const_nhds.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
have : closedBall x r = {x} + r • closedBall (0 : E) 1 := by
simp only [_root_.smul_closedBall, Real.norm_of_nonneg rpos.le, zero_le_one, add_zero,
mul_one, singleton_add_closedBall, smul_zero]
simp only [this, addHaar_singleton_add_smul_div_singleton_add_smul μ rpos.ne']
simp only [addHaar_closedBall_center, image_add_left, measure_preimage_add, singleton_add]
have C : Tendsto (fun r : ℝ =>
μ (s ∩ ({x} + r • t)) / μ (closedBall x r) * (μ (closedBall x r) / μ ({x} + r • u)))
(𝓝[>] 0) (𝓝 (0 * (μ (closedBall x 1) / μ ({x} + u)))) := by
apply ENNReal.Tendsto.mul A _ B (Or.inr ENNReal.zero_ne_top)
simp only [ne_eq, not_true, singleton_add, image_add_left, measure_preimage_add, false_or,
ENNReal.div_eq_top, h'u, false_or_iff, not_and, and_false_iff]
intro aux
exact (measure_closedBall_lt_top.ne aux).elim
-- Porting note: it used to be enough to pass `measure_closedBall_lt_top.ne` to `simp`
-- and avoid the `intro; exact` dance.
simp only [zero_mul] at C
apply C.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
calc
μ (s ∩ ({x} + r • t)) / μ (closedBall x r) * (μ (closedBall x r) / μ ({x} + r • u)) =
μ (closedBall x r) * (μ (closedBall x r))⁻¹ * (μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) :=
by simp only [div_eq_mul_inv]; ring
_ = μ (s ∩ ({x} + r • t)) / μ ({x} + r • u) := by
rw [ENNReal.mul_inv_cancel (measure_closedBall_pos μ x rpos).ne'
measure_closedBall_lt_top.ne,
one_mul]
theorem tendsto_addHaar_inter_smul_zero_of_density_zero_aux2 (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)
(u : Set E) (h'u : μ u ≠ 0) (R : ℝ) (Rpos : 0 < R) (t_bound : t ⊆ closedBall 0 R) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) (𝓝[>] 0) (𝓝 0) := by
set t' := R⁻¹ • t with ht'
set u' := R⁻¹ • u with hu'
have A : Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t')) / μ ({x} + r • u')) (𝓝[>] 0) (𝓝 0) := by
apply tendsto_addHaar_inter_smul_zero_of_density_zero_aux1 μ s x h t' u'
· simp only [u', h'u, (pow_pos Rpos _).ne', abs_nonpos_iff, addHaar_smul, not_false_iff,
ENNReal.ofReal_eq_zero, inv_eq_zero, inv_pow, Ne, or_self_iff, mul_eq_zero]
· refine (smul_set_mono t_bound).trans_eq ?_
rw [smul_closedBall _ _ Rpos.le, smul_zero, Real.norm_of_nonneg (inv_nonneg.2 Rpos.le),
inv_mul_cancel Rpos.ne']
have B : Tendsto (fun r : ℝ => R * r) (𝓝[>] 0) (𝓝[>] (R * 0)) := by
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
· exact (tendsto_const_nhds.mul tendsto_id).mono_left nhdsWithin_le_nhds
· filter_upwards [self_mem_nhdsWithin]
intro r rpos
rw [mul_zero]
exact mul_pos Rpos rpos
rw [mul_zero] at B
apply (A.comp B).congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r -
have T : (R * r) • t' = r • t := by
rw [mul_comm, ht', smul_smul, mul_assoc, mul_inv_cancel Rpos.ne', mul_one]
have U : (R * r) • u' = r • u := by
rw [mul_comm, hu', smul_smul, mul_assoc, mul_inv_cancel Rpos.ne', mul_one]
dsimp
rw [T, U]
/-- Consider a point `x` at which a set `s` has density zero, with respect to closed balls. Then it
also has density zero with respect to any measurable set `t`: the proportion of points in `s`
belonging to a rescaled copy `{x} + r • t` of `t` tends to zero as `r` tends to zero. -/
theorem tendsto_addHaar_inter_smul_zero_of_density_zero (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)
(ht : MeasurableSet t) (h''t : μ t ≠ ∞) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 0) := by
refine tendsto_order.2 ⟨fun a' ha' => (ENNReal.not_lt_zero ha').elim, fun ε (εpos : 0 < ε) => ?_⟩
rcases eq_or_ne (μ t) 0 with (h't | h't)
· filter_upwards with r
suffices H : μ (s ∩ ({x} + r • t)) = 0 by
rw [H]; simpa only [ENNReal.zero_div] using εpos
apply le_antisymm _ (zero_le _)
calc
μ (s ∩ ({x} + r • t)) ≤ μ ({x} + r • t) := measure_mono inter_subset_right
_ = 0 := by
simp only [h't, addHaar_smul, image_add_left, measure_preimage_add, singleton_add,
mul_zero]
obtain ⟨n, npos, hn⟩ : ∃ n : ℕ, 0 < n ∧ μ (t \ closedBall 0 n) < ε / 2 * μ t := by
have A :
Tendsto (fun n : ℕ => μ (t \ closedBall 0 n)) atTop
(𝓝 (μ (⋂ n : ℕ, t \ closedBall 0 n))) := by
have N : ∃ n : ℕ, μ (t \ closedBall 0 n) ≠ ∞ :=
⟨0, ((measure_mono diff_subset).trans_lt h''t.lt_top).ne⟩
refine tendsto_measure_iInter (fun n ↦ ht.diff measurableSet_closedBall) (fun m n hmn ↦ ?_) N
exact diff_subset_diff Subset.rfl (closedBall_subset_closedBall (Nat.cast_le.2 hmn))
have : ⋂ n : ℕ, t \ closedBall 0 n = ∅ := by
simp_rw [diff_eq, ← inter_iInter, iInter_eq_compl_iUnion_compl, compl_compl,
iUnion_closedBall_nat, compl_univ, inter_empty]
simp only [this, measure_empty] at A
have I : 0 < ε / 2 * μ t := ENNReal.mul_pos (ENNReal.half_pos εpos.ne').ne' h't
exact (Eventually.and (Ioi_mem_atTop 0) ((tendsto_order.1 A).2 _ I)).exists
have L :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) / μ ({x} + r • t)) (𝓝[>] 0)
(𝓝 0) :=
tendsto_addHaar_inter_smul_zero_of_density_zero_aux2 μ s x h _ t h't n (Nat.cast_pos.2 npos)
inter_subset_right
filter_upwards [(tendsto_order.1 L).2 _ (ENNReal.half_pos εpos.ne'), self_mem_nhdsWithin]
rintro r hr (rpos : 0 < r)
have I :
μ (s ∩ ({x} + r • t)) ≤
μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ ({x} + r • (t \ closedBall 0 n)) :=
calc
μ (s ∩ ({x} + r • t)) =
μ (s ∩ ({x} + r • (t ∩ closedBall 0 n)) ∪ s ∩ ({x} + r • (t \ closedBall 0 n))) := by
rw [← inter_union_distrib_left, ← add_union, ← smul_set_union, inter_union_diff]
_ ≤ μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ (s ∩ ({x} + r • (t \ closedBall 0 n))) :=
measure_union_le _ _
_ ≤ μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ ({x} + r • (t \ closedBall 0 n)) := by
gcongr; apply inter_subset_right
calc
μ (s ∩ ({x} + r • t)) / μ ({x} + r • t) ≤
(μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ ({x} + r • (t \ closedBall 0 n))) /
μ ({x} + r • t) := by gcongr
_ < ε / 2 + ε / 2 := by
rw [ENNReal.add_div]
apply ENNReal.add_lt_add hr _
rwa [addHaar_singleton_add_smul_div_singleton_add_smul μ rpos.ne',
ENNReal.div_lt_iff (Or.inl h't) (Or.inl h''t)]
_ = ε := ENNReal.add_halves _
theorem tendsto_addHaar_inter_smul_one_of_density_one_aux (s : Set E) (hs : MeasurableSet s)
(x : E) (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1))
(t : Set E) (ht : MeasurableSet t) (h't : μ t ≠ 0) (h''t : μ t ≠ ∞) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) := by
have I : ∀ u v, μ u ≠ 0 → μ u ≠ ∞ → MeasurableSet v →
μ u / μ u - μ (vᶜ ∩ u) / μ u = μ (v ∩ u) / μ u := by
intro u v uzero utop vmeas
simp_rw [div_eq_mul_inv]
rw [← ENNReal.sub_mul]; swap
· simp only [uzero, ENNReal.inv_eq_top, imp_true_iff, Ne, not_false_iff]
congr 1
apply
ENNReal.sub_eq_of_add_eq (ne_top_of_le_ne_top utop (measure_mono inter_subset_right))
rw [inter_comm _ u, inter_comm _ u]
exact measure_inter_add_diff u vmeas
have L : Tendsto (fun r => μ (sᶜ ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0) := by
have A : Tendsto (fun r => μ (closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1) := by
apply tendsto_const_nhds.congr' _
filter_upwards [self_mem_nhdsWithin]
intro r hr
rw [div_eq_mul_inv, ENNReal.mul_inv_cancel]
· exact (measure_closedBall_pos μ _ hr).ne'
· exact measure_closedBall_lt_top.ne
have B := ENNReal.Tendsto.sub A h (Or.inl ENNReal.one_ne_top)
simp only [tsub_self] at B
apply B.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
convert I (closedBall x r) sᶜ (measure_closedBall_pos μ _ rpos).ne'
measure_closedBall_lt_top.ne hs.compl
rw [compl_compl]
have L' : Tendsto (fun r : ℝ => μ (sᶜ ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 0) :=
tendsto_addHaar_inter_smul_zero_of_density_zero μ sᶜ x L t ht h''t
have L'' : Tendsto (fun r : ℝ => μ ({x} + r • t) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) := by
apply tendsto_const_nhds.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
rw [addHaar_singleton_add_smul_div_singleton_add_smul μ rpos.ne', ENNReal.div_self h't h''t]
have := ENNReal.Tendsto.sub L'' L' (Or.inl ENNReal.one_ne_top)
simp only [tsub_zero] at this
apply this.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
refine I ({x} + r • t) s ?_ ?_ hs
· simp only [h't, abs_of_nonneg rpos.le, pow_pos rpos, addHaar_smul, image_add_left,
ENNReal.ofReal_eq_zero, not_le, or_false_iff, Ne, measure_preimage_add, abs_pow,
singleton_add, mul_eq_zero]
· simp [h''t, ENNReal.ofReal_ne_top, addHaar_smul, image_add_left, ENNReal.mul_eq_top,
Ne, not_false_iff, measure_preimage_add, singleton_add, and_false_iff, false_and_iff,
or_self_iff]
/-- Consider a point `x` at which a set `s` has density one, with respect to closed balls (i.e.,
a Lebesgue density point of `s`). Then `s` has also density one at `x` with respect to any
measurable set `t`: the proportion of points in `s` belonging to a rescaled copy `{x} + r • t`
of `t` tends to one as `r` tends to zero. -/
theorem tendsto_addHaar_inter_smul_one_of_density_one (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1)) (t : Set E)
(ht : MeasurableSet t) (h't : μ t ≠ 0) (h''t : μ t ≠ ∞) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) := by
have : Tendsto (fun r : ℝ => μ (toMeasurable μ s ∩ ({x} + r • t)) / μ ({x} + r • t))
(𝓝[>] 0) (𝓝 1) := by
apply
tendsto_addHaar_inter_smul_one_of_density_one_aux μ _ (measurableSet_toMeasurable _ _) _ _
t ht h't h''t
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' h tendsto_const_nhds
· refine eventually_of_forall fun r ↦ ?_
gcongr
apply subset_toMeasurable
· filter_upwards [self_mem_nhdsWithin]
rintro r -
apply ENNReal.div_le_of_le_mul
rw [one_mul]
exact measure_mono inter_subset_right
refine this.congr fun r => ?_
congr 1
apply measure_toMeasurable_inter_of_sFinite
simp only [image_add_left, singleton_add]
apply (continuous_add_left (-x)).measurable (ht.const_smul₀ r)
/-- Consider a point `x` at which a set `s` has density one, with respect to closed balls (i.e.,
a Lebesgue density point of `s`). Then `s` intersects the rescaled copies `{x} + r • t` of a given
set `t` with positive measure, for any small enough `r`. -/
theorem eventually_nonempty_inter_smul_of_density_one (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1)) (t : Set E)
(ht : MeasurableSet t) (h't : μ t ≠ 0) :
∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • t)).Nonempty := by
obtain ⟨t', t'_meas, t't, t'pos, t'top⟩ : ∃ t', MeasurableSet t' ∧ t' ⊆ t ∧ 0 < μ t' ∧ μ t' < ⊤ :=
exists_subset_measure_lt_top ht h't.bot_lt
filter_upwards [(tendsto_order.1
(tendsto_addHaar_inter_smul_one_of_density_one μ s x h t' t'_meas t'pos.ne' t'top.ne)).1
0 zero_lt_one]
intro r hr
have : μ (s ∩ ({x} + r • t')) ≠ 0 := fun h' => by
simp only [ENNReal.not_lt_zero, ENNReal.zero_div, h'] at hr
have : (s ∩ ({x} + r • t')).Nonempty := nonempty_of_measure_ne_zero this
apply this.mono (inter_subset_inter Subset.rfl _)
exact add_subset_add Subset.rfl (smul_set_mono t't)
end Measure
end MeasureTheory
|
MeasureTheory\Measure\Lebesgue\Integral.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Integral.SetIntegral
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-! # Properties of integration with respect to the Lebesgue measure -/
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
section regionBetween
variable {α : Type*}
variable [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ} {s : Set α}
theorem volume_regionBetween_eq_integral' [SigmaFinite μ] (f_int : IntegrableOn f s μ)
(g_int : IntegrableOn g s μ) (hs : MeasurableSet s) (hfg : f ≤ᵐ[μ.restrict s] g) :
μ.prod volume (regionBetween f g s) = ENNReal.ofReal (∫ y in s, (g - f) y ∂μ) := by
have h : g - f =ᵐ[μ.restrict s] fun x => Real.toNNReal (g x - f x) :=
hfg.mono fun x hx => (Real.coe_toNNReal _ <| sub_nonneg.2 hx).symm
rw [volume_regionBetween_eq_lintegral f_int.aemeasurable g_int.aemeasurable hs,
integral_congr_ae h, lintegral_congr_ae,
lintegral_coe_eq_integral _ ((integrable_congr h).mp (g_int.sub f_int))]
dsimp only
rfl
/-- If two functions are integrable on a measurable set, and one function is less than
or equal to the other on that set, then the volume of the region
between the two functions can be represented as an integral. -/
theorem volume_regionBetween_eq_integral [SigmaFinite μ] (f_int : IntegrableOn f s μ)
(g_int : IntegrableOn g s μ) (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) :
μ.prod volume (regionBetween f g s) = ENNReal.ofReal (∫ y in s, (g - f) y ∂μ) :=
volume_regionBetween_eq_integral' f_int g_int hs
((ae_restrict_iff' hs).mpr (eventually_of_forall hfg))
end regionBetween
section SummableNormIcc
open ContinuousMap
/- The following lemma is a minor variation on `integrable_of_summable_norm_restrict` in
`Mathlib/MeasureTheory/Integral/SetIntegral.lean`, but it is placed here because it needs to know
that `Icc a b` has volume `b - a`. -/
/-- If the sequence with `n`-th term the sup norm of `fun x ↦ f (x + n)` on the interval `Icc 0 1`,
for `n ∈ ℤ`, is summable, then `f` is integrable on `ℝ`. -/
theorem Real.integrable_of_summable_norm_Icc {E : Type*} [NormedAddCommGroup E] {f : C(ℝ, E)}
(hf : Summable fun n : ℤ => ‖(f.comp <| ContinuousMap.addRight n).restrict (Icc 0 1)‖) :
Integrable f := by
refine integrable_of_summable_norm_restrict (.of_nonneg_of_le
(fun n : ℤ => mul_nonneg (norm_nonneg
(f.restrict (⟨Icc (n : ℝ) ((n : ℝ) + 1), isCompact_Icc⟩ : Compacts ℝ)))
ENNReal.toReal_nonneg) (fun n => ?_) hf) ?_
· simp only [Compacts.coe_mk, Real.volume_Icc, add_sub_cancel_left,
ENNReal.toReal_ofReal zero_le_one, mul_one, norm_le _ (norm_nonneg _)]
intro x
have := ((f.comp <| ContinuousMap.addRight n).restrict (Icc 0 1)).norm_coe_le_norm
⟨x - n, ⟨sub_nonneg.mpr x.2.1, sub_le_iff_le_add'.mpr x.2.2⟩⟩
simpa only [ContinuousMap.restrict_apply, comp_apply, coe_addRight, Subtype.coe_mk,
sub_add_cancel] using this
· exact iUnion_Icc_intCast ℝ
end SummableNormIcc
/-!
### Substituting `-x` for `x`
These lemmas are stated in terms of either `Iic` or `Ioi` (neglecting `Iio` and `Ici`) to match
mathlib's conventions for integrals over finite intervals (see `intervalIntegral`). For the case
of finite integrals, see `intervalIntegral.integral_comp_neg`.
-/
/- @[simp] Porting note: Linter complains it does not apply to itself. Although it does apply to
itself, it does not apply when `f` is more complicated -/
theorem integral_comp_neg_Iic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(c : ℝ) (f : ℝ → E) : (∫ x in Iic c, f (-x)) = ∫ x in Ioi (-c), f x := by
have A : MeasurableEmbedding fun x : ℝ => -x :=
(Homeomorph.neg ℝ).closedEmbedding.measurableEmbedding
have := MeasurableEmbedding.setIntegral_map (μ := volume) A f (Ici (-c))
rw [Measure.map_neg_eq_self (volume : Measure ℝ)] at this
simp_rw [← integral_Ici_eq_integral_Ioi, this, neg_preimage, preimage_neg_Ici, neg_neg]
/- @[simp] Porting note: Linter complains it does not apply to itself. Although it does apply to
itself, it does not apply when `f` is more complicated -/
theorem integral_comp_neg_Ioi {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(c : ℝ) (f : ℝ → E) : (∫ x in Ioi c, f (-x)) = ∫ x in Iic (-c), f x := by
rw [← neg_neg c, ← integral_comp_neg_Iic]
simp only [neg_neg]
theorem integral_comp_abs {f : ℝ → ℝ} :
∫ x, f |x| = 2 * ∫ x in Ioi (0 : ℝ), f x := by
have eq : ∫ (x : ℝ) in Ioi 0, f |x| = ∫ (x : ℝ) in Ioi 0, f x := by
refine setIntegral_congr measurableSet_Ioi (fun _ hx => ?_)
rw [abs_eq_self.mpr (le_of_lt (by exact hx))]
by_cases hf : IntegrableOn (fun x => f |x|) (Ioi 0)
· have int_Iic : IntegrableOn (fun x ↦ f |x|) (Iic 0) := by
rw [← Measure.map_neg_eq_self (volume : Measure ℝ)]
let m : MeasurableEmbedding fun x : ℝ => -x := (Homeomorph.neg ℝ).measurableEmbedding
rw [m.integrableOn_map_iff]
simp_rw [Function.comp, abs_neg, neg_preimage, preimage_neg_Iic, neg_zero]
exact integrableOn_Ici_iff_integrableOn_Ioi.mpr hf
calc
_ = (∫ x in Iic 0, f |x|) + ∫ x in Ioi 0, f |x| := by
rw [← integral_union (Iic_disjoint_Ioi le_rfl) measurableSet_Ioi int_Iic hf,
Iic_union_Ioi, restrict_univ]
_ = 2 * ∫ x in Ioi 0, f x := by
rw [two_mul, eq]
congr! 1
rw [← neg_zero, ← integral_comp_neg_Iic, neg_zero]
refine setIntegral_congr measurableSet_Iic (fun _ hx => ?_)
rw [abs_eq_neg_self.mpr (by exact hx)]
· have : ¬ Integrable (fun x => f |x|) := by
contrapose! hf
exact hf.integrableOn
rw [← eq, integral_undef hf, integral_undef this, mul_zero]
|
MeasureTheory\Measure\Lebesgue\VolumeOfBalls.lean | /-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Constructions.HaarToSphere
import Mathlib.MeasureTheory.Integral.Gamma
import Mathlib.MeasureTheory.Integral.Pi
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
/-!
# Volume of balls
Let `E` be a finite dimensional normed `ℝ`-vector space equipped with a Haar measure `μ`. We
prove that
`μ (Metric.ball 0 1) = (∫ (x : E), Real.exp (- ‖x‖ ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)`
for any real number `p` with `0 < p`, see `MeasureTheorymeasure_unitBall_eq_integral_div_gamma`. We
also prove the corresponding result to compute `μ {x : E | g x < 1}` where `g : E → ℝ` is a function
defining a norm on `E`, see `MeasureTheory.measure_lt_one_eq_integral_div_gamma`.
Using these formulas, we compute the volume of the unit balls in several cases.
* `MeasureTheory.volume_sum_rpow_lt` / `MeasureTheory.volume_sum_rpow_le`: volume of the open and
closed balls for the norm `Lp` over a real finite dimensional vector space with `1 ≤ p`. These
are computed as `volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r}` and
`volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) ≤ r}` since the spaces `PiLp` do not have a
`MeasureSpace` instance.
* `Complex.volume_sum_rpow_lt_one` / `Complex.volume_sum_rpow_lt`: same as above but for complex
finite dimensional vector space.
* `EuclideanSpace.volume_ball` / `EuclideanSpace.volume_closedBall` : volume of open and closed
balls in a finite dimensional Euclidean space.
* `InnerProductSpace.volume_ball` / `InnerProductSpace.volume_closedBall`: volume of open and closed
balls in a finite dimensional real inner product space.
* `Complex.volume_ball` / `Complex.volume_closedBall`: volume of open and closed balls in `ℂ`.
-/
section general_case
open MeasureTheory MeasureTheory.Measure FiniteDimensional ENNReal
theorem MeasureTheory.measure_unitBall_eq_integral_div_gamma {E : Type*} {p : ℝ}
[NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (hp : 0 < p) :
μ (Metric.ball 0 1) =
.ofReal ((∫ (x : E), Real.exp (- ‖x‖ ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)) := by
obtain hE | hE := subsingleton_or_nontrivial E
· rw [(Metric.nonempty_ball.mpr zero_lt_one).eq_zero, ← integral_univ, Set.univ_nonempty.eq_zero,
integral_singleton, finrank_zero_of_subsingleton, Nat.cast_zero, zero_div, zero_add,
Real.Gamma_one, div_one, norm_zero, Real.zero_rpow (ne_of_gt hp), neg_zero, Real.exp_zero,
smul_eq_mul, mul_one, ofReal_toReal (measure_ne_top μ {0})]
· have : (0 : ℝ) < finrank ℝ E := Nat.cast_pos.mpr finrank_pos
have : ((∫ y in Set.Ioi (0 : ℝ), y ^ (finrank ℝ E - 1) • Real.exp (-y ^ p)) /
Real.Gamma ((finrank ℝ E) / p + 1)) * (finrank ℝ E) = 1 := by
simp_rw [← Real.rpow_natCast _ (finrank ℝ E - 1), smul_eq_mul, Nat.cast_sub finrank_pos,
Nat.cast_one]
rw [integral_rpow_mul_exp_neg_rpow hp (by linarith), sub_add_cancel,
Real.Gamma_add_one (ne_of_gt (by positivity))]
field_simp; ring
rw [integral_fun_norm_addHaar μ (fun x => Real.exp (- x ^ p)), nsmul_eq_mul, smul_eq_mul,
mul_div_assoc, mul_div_assoc, mul_comm, mul_assoc, this, mul_one, ofReal_toReal]
exact ne_of_lt measure_ball_lt_top
variable {E : Type*} [AddCommGroup E] [Module ℝ E] [FiniteDimensional ℝ E] [mE : MeasurableSpace E]
[tE : TopologicalSpace E] [TopologicalAddGroup E] [BorelSpace E] [T2Space E] [ContinuousSMul ℝ E]
(μ : Measure E) [IsAddHaarMeasure μ] {g : E → ℝ} (h1 : g 0 = 0) (h2 : ∀ x, g (- x) = g x)
(h3 : ∀ x y, g (x + y) ≤ g x + g y) (h4 : ∀ {x}, g x = 0 → x = 0)
(h5 : ∀ r x, g (r • x) ≤ |r| * (g x))
theorem MeasureTheory.measure_lt_one_eq_integral_div_gamma {p : ℝ} (hp : 0 < p) :
μ {x : E | g x < 1} =
.ofReal ((∫ (x : E), Real.exp (- (g x) ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)) := by
-- We copy `E` to a new type `F` on which we will put the norm defined by `g`
letI F : Type _ := E
letI : NormedAddCommGroup F :=
{ norm := g
dist := fun x y => g (x - y)
dist_self := by simp only [_root_.sub_self, h1, forall_const]
dist_comm := fun _ _ => by dsimp [dist]; rw [← h2, neg_sub]
dist_triangle := fun x y z => by convert h3 (x - y) (y - z) using 1; abel_nf
edist := fun x y => .ofReal (g (x - y))
edist_dist := fun _ _ => rfl
eq_of_dist_eq_zero := by convert fun _ _ h => eq_of_sub_eq_zero (h4 h) }
letI : NormedSpace ℝ F :=
{ norm_smul_le := fun _ _ ↦ h5 _ _ }
-- We put the new topology on F
letI : TopologicalSpace F := UniformSpace.toTopologicalSpace
letI : MeasurableSpace F := borel F
have : BorelSpace F := { measurable_eq := rfl }
-- The map between `E` and `F` as a continuous linear equivalence
let φ := @LinearEquiv.toContinuousLinearEquiv ℝ _ E _ _ tE _ _ F _ _ _ _ _ _ _ _ _
(LinearEquiv.refl ℝ E : E ≃ₗ[ℝ] F)
-- The measure `ν` is the measure on `F` defined by `μ`
-- Since we have two different topologies, it is necessary to specify the topology of E
let ν : Measure F := @Measure.map E F _ mE φ μ
have : IsAddHaarMeasure ν :=
@ContinuousLinearEquiv.isAddHaarMeasure_map E F ℝ ℝ _ _ _ _ _ _ tE _ _ _ _ _ _ _ mE _ _ _ φ μ _
convert (measure_unitBall_eq_integral_div_gamma ν hp) using 1
· rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_ball]
· congr!
simp_rw [Metric.ball, dist_zero_right]
rfl
· refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_
exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ
· -- The map between `E` and `F` as a measurable equivalence
let ψ := @Homeomorph.toMeasurableEquiv E F tE mE _ _ _ _
(@ContinuousLinearEquiv.toHomeomorph ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ)
-- The map `ψ` is measure preserving by construction
have : @MeasurePreserving E F mE _ ψ μ ν :=
@Measurable.measurePreserving E F mE _ ψ (@MeasurableEquiv.measurable E F mE _ ψ) _
erw [← this.integral_comp']
rfl
theorem MeasureTheory.measure_le_eq_lt [Nontrivial E] (r : ℝ) :
μ {x : E | g x ≤ r} = μ {x : E | g x < r} := by
-- We copy `E` to a new type `F` on which we will put the norm defined by `g`
letI F : Type _ := E
letI : NormedAddCommGroup F :=
{ norm := g
dist := fun x y => g (x - y)
dist_self := by simp only [_root_.sub_self, h1, forall_const]
dist_comm := fun _ _ => by dsimp [dist]; rw [← h2, neg_sub]
dist_triangle := fun x y z => by convert h3 (x - y) (y - z) using 1; abel_nf
edist := fun x y => .ofReal (g (x - y))
edist_dist := fun _ _ => rfl
eq_of_dist_eq_zero := by convert fun _ _ h => eq_of_sub_eq_zero (h4 h) }
letI : NormedSpace ℝ F :=
{ norm_smul_le := fun _ _ ↦ h5 _ _ }
-- We put the new topology on F
letI : TopologicalSpace F := UniformSpace.toTopologicalSpace
letI : MeasurableSpace F := borel F
have : BorelSpace F := { measurable_eq := rfl }
-- The map between `E` and `F` as a continuous linear equivalence
let φ := @LinearEquiv.toContinuousLinearEquiv ℝ _ E _ _ tE _ _ F _ _ _ _ _ _ _ _ _
(LinearEquiv.refl ℝ E : E ≃ₗ[ℝ] F)
-- The measure `ν` is the measure on `F` defined by `μ`
-- Since we have two different topologies, it is necessary to specify the topology of E
let ν : Measure F := @Measure.map E F _ mE φ μ
have : IsAddHaarMeasure ν :=
@ContinuousLinearEquiv.isAddHaarMeasure_map E F ℝ ℝ _ _ _ _ _ _ tE _ _ _ _ _ _ _ mE _ _ _ φ μ _
convert addHaar_closedBall_eq_addHaar_ball ν 0 r using 1
· rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_closedBall]
· congr!
simp_rw [Metric.closedBall, dist_zero_right]
rfl
· refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_
exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ
· rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_ball]
· congr!
simp_rw [Metric.ball, dist_zero_right]
rfl
· refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_
exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ
end general_case
section LpSpace
open Real Fintype ENNReal FiniteDimensional MeasureTheory MeasureTheory.Measure
variable (ι : Type*) [Fintype ι] {p : ℝ} (hp : 1 ≤ p)
theorem MeasureTheory.volume_sum_rpow_lt_one :
volume {x : ι → ℝ | ∑ i, |x i| ^ p < 1} =
.ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by
have h₁ : 0 < p := by linarith
have h₂ : ∀ x : ι → ℝ, 0 ≤ ∑ i, |x i| ^ p := by
refine fun _ => Finset.sum_nonneg' ?_
exact fun i => (fun _ => rpow_nonneg (abs_nonneg _) _) _
-- We collect facts about `Lp` norms that will be used in `measure_lt_one_eq_integral_div_gamma`
have eq_norm := fun x : ι → ℝ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x)
((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁))
simp_rw [toReal_ofReal (le_of_lt h₁), Real.norm_eq_abs] at eq_norm
have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ofReal_one ▸ (ofReal_le_ofReal hp))
have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ))
have eq_zero := fun x : ι → ℝ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) (a := x)
have nm_neg := fun x : ι → ℝ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x
have nm_add := fun x y : ι → ℝ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x y
simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add
have nm_smul := fun (r : ℝ) (x : ι → ℝ) =>
norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℝ)) r x
simp_rw [eq_norm, norm_eq_abs] at nm_smul
-- We use `measure_lt_one_eq_integral_div_gamma` with `g` equals to the norm `L_p`
convert (measure_lt_one_eq_integral_div_gamma (volume : Measure (ι → ℝ))
(g := fun x => (∑ i, |x i| ^ p) ^ (1 / p)) nm_zero nm_neg nm_add (eq_zero _).mp
(fun r x => nm_smul r x) (by linarith : 0 < p)) using 4
· rw [rpow_lt_one_iff' _ (one_div_pos.mpr h₁)]
exact Finset.sum_nonneg' (fun _ => rpow_nonneg (abs_nonneg _) _)
· simp_rw [← rpow_mul (h₂ _), div_mul_cancel₀ _ (ne_of_gt h₁), Real.rpow_one,
← Finset.sum_neg_distrib, exp_sum]
rw [integral_fintype_prod_eq_pow ι fun x : ℝ => exp (- |x| ^ p), integral_comp_abs
(f := fun x => exp (- x ^ p)), integral_exp_neg_rpow h₁]
· rw [finrank_fintype_fun_eq_card]
theorem MeasureTheory.volume_sum_rpow_lt [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) :
volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r} = (.ofReal r) ^ card ι *
.ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by
have h₁ (x : ι → ℝ) : 0 ≤ ∑ i, |x i| ^ p := by positivity
have h₂ : ∀ x : ι → ℝ, 0 ≤ (∑ i, |x i| ^ p) ^ (1 / p) := fun x => rpow_nonneg (h₁ x) _
obtain hr | hr := le_or_lt r 0
· have : {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r} = ∅ := by
ext x
refine ⟨fun hx => ?_, fun hx => hx.elim⟩
exact not_le.mpr (lt_of_lt_of_le (Set.mem_setOf.mp hx) hr) (h₂ x)
rw [this, measure_empty, ← zero_eq_ofReal.mpr hr, zero_pow Fin.size_pos'.ne', zero_mul]
· rw [← volume_sum_rpow_lt_one _ hp, ← ofReal_pow (le_of_lt hr), ← finrank_pi ℝ]
convert addHaar_smul_of_nonneg volume (le_of_lt hr) {x : ι → ℝ | ∑ i, |x i| ^ p < 1} using 2
simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hr), Set.preimage_setOf_eq, Pi.smul_apply,
smul_eq_mul, abs_mul, mul_rpow (abs_nonneg _) (abs_nonneg _), abs_inv,
inv_rpow (abs_nonneg _), ← Finset.mul_sum, abs_eq_self.mpr (le_of_lt hr),
inv_mul_lt_iff (rpow_pos_of_pos hr _), mul_one, ← rpow_lt_rpow_iff
(rpow_nonneg (h₁ _) _) (le_of_lt hr) (by linarith : 0 < p), ← rpow_mul
(h₁ _), div_mul_cancel₀ _ (ne_of_gt (by linarith) : p ≠ 0), Real.rpow_one]
theorem MeasureTheory.volume_sum_rpow_le [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) :
volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) ≤ r} = (.ofReal r) ^ card ι *
.ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by
have h₁ : 0 < p := by linarith
-- We collect facts about `Lp` norms that will be used in `measure_le_one_eq_lt_one`
have eq_norm := fun x : ι → ℝ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x)
((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁))
simp_rw [toReal_ofReal (le_of_lt h₁), Real.norm_eq_abs] at eq_norm
have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ofReal_one ▸ (ofReal_le_ofReal hp))
have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ))
have eq_zero := fun x : ι → ℝ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) (a := x)
have nm_neg := fun x : ι → ℝ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x
have nm_add := fun x y : ι → ℝ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x y
simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add
have nm_smul := fun (r : ℝ) (x : ι → ℝ) =>
norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℝ)) r x
simp_rw [eq_norm, norm_eq_abs] at nm_smul
rw [measure_le_eq_lt _ nm_zero (fun x ↦ nm_neg x) (fun x y ↦ nm_add x y) (eq_zero _).mp
(fun r x => nm_smul r x), volume_sum_rpow_lt _ hp]
theorem Complex.volume_sum_rpow_lt_one {p : ℝ} (hp : 1 ≤ p) :
volume {x : ι → ℂ | ∑ i, ‖x i‖ ^ p < 1} =
.ofReal ((π * Real.Gamma (2 / p + 1)) ^ card ι / Real.Gamma (2 * card ι / p + 1)) := by
have h₁ : 0 < p := by linarith
have h₂ : ∀ x : ι → ℂ, 0 ≤ ∑ i, ‖x i‖ ^ p := by
refine fun _ => Finset.sum_nonneg' ?_
exact fun i => (fun _ => rpow_nonneg (norm_nonneg _) _) _
-- We collect facts about `Lp` norms that will be used in `measure_lt_one_eq_integral_div_gamma`
have eq_norm := fun x : ι → ℂ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x)
((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁))
simp_rw [toReal_ofReal (le_of_lt h₁)] at eq_norm
have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ENNReal.ofReal_one ▸ (ofReal_le_ofReal hp))
have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℂ))
have eq_zero := fun x : ι → ℂ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) (a := x)
have nm_neg := fun x : ι → ℂ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) x
have nm_add := fun x y : ι → ℂ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) x y
simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add
have nm_smul := fun (r : ℝ) (x : ι → ℂ) =>
norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℂ)) r x
simp_rw [eq_norm, norm_eq_abs] at nm_smul
-- We use `measure_lt_one_eq_integral_div_gamma` with `g` equals to the norm `L_p`
convert measure_lt_one_eq_integral_div_gamma (volume : Measure (ι → ℂ))
(g := fun x => (∑ i, ‖x i‖ ^ p) ^ (1 / p)) nm_zero nm_neg nm_add (eq_zero _).mp
(fun r x => nm_smul r x) (by linarith : 0 < p) using 4
· rw [rpow_lt_one_iff' _ (one_div_pos.mpr h₁)]
exact Finset.sum_nonneg' (fun _ => rpow_nonneg (norm_nonneg _) _)
· simp_rw [← rpow_mul (h₂ _), div_mul_cancel₀ _ (ne_of_gt h₁), Real.rpow_one,
← Finset.sum_neg_distrib, Real.exp_sum]
rw [integral_fintype_prod_eq_pow ι fun x : ℂ => Real.exp (- ‖x‖ ^ p),
Complex.integral_exp_neg_rpow hp]
· rw [finrank_pi_fintype, Complex.finrank_real_complex, Finset.sum_const, smul_eq_mul,
Nat.cast_mul, Nat.cast_ofNat, Fintype.card, mul_comm]
theorem Complex.volume_sum_rpow_lt [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) :
volume {x : ι → ℂ | (∑ i, ‖x i‖ ^ p) ^ (1 / p) < r} = (.ofReal r) ^ (2 * card ι) *
.ofReal ((π * Real.Gamma (2 / p + 1)) ^ card ι / Real.Gamma (2 * card ι / p + 1)) := by
have h₁ (x : ι → ℂ) : 0 ≤ ∑ i, ‖x i‖ ^ p := by positivity
have h₂ : ∀ x : ι → ℂ, 0 ≤ (∑ i, ‖x i‖ ^ p) ^ (1 / p) := fun x => rpow_nonneg (h₁ x) _
obtain hr | hr := le_or_lt r 0
· have : {x : ι → ℂ | (∑ i, ‖x i‖ ^ p) ^ (1 / p) < r} = ∅ := by
ext x
refine ⟨fun hx => ?_, fun hx => hx.elim⟩
exact not_le.mpr (lt_of_lt_of_le (Set.mem_setOf.mp hx) hr) (h₂ x)
rw [this, measure_empty, ← zero_eq_ofReal.mpr hr, zero_pow Fin.size_pos'.ne', zero_mul]
· rw [← Complex.volume_sum_rpow_lt_one _ hp, ← ENNReal.ofReal_pow (le_of_lt hr)]
convert addHaar_smul_of_nonneg volume (le_of_lt hr) {x : ι → ℂ | ∑ i, ‖x i‖ ^ p < 1} using 2
· simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hr), Set.preimage_setOf_eq, Pi.smul_apply,
norm_smul, mul_rpow (norm_nonneg _) (norm_nonneg _), Real.norm_eq_abs, abs_inv, inv_rpow
(abs_nonneg _), ← Finset.mul_sum, abs_eq_self.mpr (le_of_lt hr), inv_mul_lt_iff
(rpow_pos_of_pos hr _), mul_one, ← rpow_lt_rpow_iff (rpow_nonneg (h₁ _) _)
(le_of_lt hr) (by linarith : 0 < p), ← rpow_mul (h₁ _), div_mul_cancel₀ _
(ne_of_gt (by linarith) : p ≠ 0), Real.rpow_one]
· simp_rw [finrank_pi_fintype ℝ, Complex.finrank_real_complex, Finset.sum_const, smul_eq_mul,
mul_comm, Fintype.card]
theorem Complex.volume_sum_rpow_le [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) :
volume {x : ι → ℂ | (∑ i, ‖x i‖ ^ p) ^ (1 / p) ≤ r} = (.ofReal r) ^ (2 * card ι) *
.ofReal ((π * Real.Gamma (2 / p + 1)) ^ card ι / Real.Gamma (2 * card ι / p + 1)) := by
have h₁ : 0 < p := by linarith
-- We collect facts about `Lp` norms that will be used in `measure_lt_one_eq_integral_div_gamma`
have eq_norm := fun x : ι → ℂ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x)
((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁))
simp_rw [toReal_ofReal (le_of_lt h₁)] at eq_norm
have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ENNReal.ofReal_one ▸ (ofReal_le_ofReal hp))
have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℂ))
have eq_zero := fun x : ι → ℂ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) (a := x)
have nm_neg := fun x : ι → ℂ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) x
have nm_add := fun x y : ι → ℂ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) x y
simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add
have nm_smul := fun (r : ℝ) (x : ι → ℂ) =>
norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℂ)) r x
simp_rw [eq_norm, norm_eq_abs] at nm_smul
rw [measure_le_eq_lt _ nm_zero (fun x ↦ nm_neg x) (fun x y ↦ nm_add x y) (eq_zero _).mp
(fun r x => nm_smul r x), Complex.volume_sum_rpow_lt _ hp]
end LpSpace
section EuclideanSpace
variable (ι : Type*) [Nonempty ι] [Fintype ι]
open Fintype Real MeasureTheory MeasureTheory.Measure ENNReal
theorem EuclideanSpace.volume_ball (x : EuclideanSpace ℝ ι) (r : ℝ) :
volume (Metric.ball x r) = (.ofReal r) ^ card ι *
.ofReal (Real.sqrt π ^ card ι / Gamma (card ι / 2 + 1)) := by
obtain hr | hr := le_total r 0
· rw [Metric.ball_eq_empty.mpr hr, measure_empty, ← zero_eq_ofReal.mpr hr, zero_pow card_ne_zero,
zero_mul]
· suffices volume (Metric.ball (0 : EuclideanSpace ℝ ι) 1) =
.ofReal (Real.sqrt π ^ card ι / Gamma (card ι / 2 + 1)) by
rw [Measure.addHaar_ball _ _ hr, this, ofReal_pow hr, finrank_euclideanSpace]
rw [← ((EuclideanSpace.volume_preserving_measurableEquiv _).symm).measure_preimage
measurableSet_ball.nullMeasurableSet]
convert (volume_sum_rpow_lt_one ι one_le_two) using 4
· simp_rw [EuclideanSpace.ball_zero_eq _ zero_le_one, one_pow, Real.rpow_two, sq_abs,
Set.setOf_app_iff]
· rw [Gamma_add_one (by norm_num), Gamma_one_half_eq, ← mul_assoc, mul_div_cancel₀ _
two_ne_zero, one_mul]
theorem EuclideanSpace.volume_closedBall (x : EuclideanSpace ℝ ι) (r : ℝ) :
volume (Metric.closedBall x r) = (.ofReal r) ^ card ι *
.ofReal (sqrt π ^ card ι / Gamma (card ι / 2 + 1)) := by
rw [addHaar_closedBall_eq_addHaar_ball, EuclideanSpace.volume_ball]
@[deprecated (since := "2024-04-06")]
alias Euclidean_space.volume_ball := EuclideanSpace.volume_ball
@[deprecated (since := "2024-04-06")]
alias Euclidean_space.volume_closedBall := EuclideanSpace.volume_closedBall
end EuclideanSpace
section InnerProductSpace
open MeasureTheory MeasureTheory.Measure ENNReal Real FiniteDimensional
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
[MeasurableSpace E] [BorelSpace E] [Nontrivial E]
theorem InnerProductSpace.volume_ball (x : E) (r : ℝ) :
volume (Metric.ball x r) = (.ofReal r) ^ finrank ℝ E *
.ofReal (sqrt π ^ finrank ℝ E / Gamma (finrank ℝ E / 2 + 1)) := by
rw [← ((stdOrthonormalBasis ℝ E).measurePreserving_repr_symm).measure_preimage
measurableSet_ball.nullMeasurableSet]
have : Nonempty (Fin (finrank ℝ E)) := Fin.pos_iff_nonempty.mp finrank_pos
have := EuclideanSpace.volume_ball (Fin (finrank ℝ E)) ((stdOrthonormalBasis ℝ E).repr x) r
simp_rw [Fintype.card_fin] at this
convert this
simp only [LinearIsometryEquiv.preimage_ball, LinearIsometryEquiv.symm_symm, _root_.map_zero]
theorem InnerProductSpace.volume_closedBall (x : E) (r : ℝ) :
volume (Metric.closedBall x r) = (.ofReal r) ^ finrank ℝ E *
.ofReal (sqrt π ^ finrank ℝ E / Gamma (finrank ℝ E / 2 + 1)) := by
rw [addHaar_closedBall_eq_addHaar_ball, InnerProductSpace.volume_ball _]
end InnerProductSpace
section Complex
open MeasureTheory MeasureTheory.Measure ENNReal
@[simp]
theorem Complex.volume_ball (a : ℂ) (r : ℝ) :
volume (Metric.ball a r) = .ofReal r ^ 2 * NNReal.pi := by
rw [InnerProductSpace.volume_ball a r, finrank_real_complex, Nat.cast_ofNat, div_self two_ne_zero,
one_add_one_eq_two, Real.Gamma_two, div_one, Real.sq_sqrt (by positivity),
← NNReal.coe_real_pi, ofReal_coe_nnreal]
@[simp]
theorem Complex.volume_closedBall (a : ℂ) (r : ℝ) :
volume (Metric.closedBall a r) = .ofReal r ^ 2 * NNReal.pi := by
rw [addHaar_closedBall_eq_addHaar_ball, Complex.volume_ball]
end Complex
|
MeasureTheory\Order\Lattice.lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Measure.AEMeasurable
/-!
# Typeclasses for measurability of lattice operations
In this file we define classes `MeasurableSup` and `MeasurableInf` and prove dot-style
lemmas (`Measurable.sup`, `AEMeasurable.sup` etc). For binary operations we define two typeclasses:
- `MeasurableSup` says that both left and right sup are measurable;
- `MeasurableSup₂` says that `fun p : α × α => p.1 ⊔ p.2` is measurable,
and similarly for other binary operations. The reason for introducing these classes is that in case
of topological space `α` equipped with the Borel `σ`-algebra, instances for `MeasurableSup₂`
etc require `α` to have a second countable topology.
For instances relating, e.g., `ContinuousSup` to `MeasurableSup` see file
`MeasureTheory.BorelSpace`.
## Tags
measurable function, lattice operation
-/
open MeasureTheory
/-- We say that a type has `MeasurableSup` if `(c ⊔ ·)` and `(· ⊔ c)` are measurable functions.
For a typeclass assuming measurability of `uncurry (· ⊔ ·)` see `MeasurableSup₂`. -/
class MeasurableSup (M : Type*) [MeasurableSpace M] [Sup M] : Prop where
measurable_const_sup : ∀ c : M, Measurable (c ⊔ ·)
measurable_sup_const : ∀ c : M, Measurable (· ⊔ c)
/-- We say that a type has `MeasurableSup₂` if `uncurry (· ⊔ ·)` is a measurable functions.
For a typeclass assuming measurability of `(c ⊔ ·)` and `(· ⊔ c)` see `MeasurableSup`. -/
class MeasurableSup₂ (M : Type*) [MeasurableSpace M] [Sup M] : Prop where
measurable_sup : Measurable fun p : M × M => p.1 ⊔ p.2
export MeasurableSup₂ (measurable_sup)
export MeasurableSup (measurable_const_sup measurable_sup_const)
/-- We say that a type has `MeasurableInf` if `(c ⊓ ·)` and `(· ⊓ c)` are measurable functions.
For a typeclass assuming measurability of `uncurry (· ⊓ ·)` see `MeasurableInf₂`. -/
class MeasurableInf (M : Type*) [MeasurableSpace M] [Inf M] : Prop where
measurable_const_inf : ∀ c : M, Measurable (c ⊓ ·)
measurable_inf_const : ∀ c : M, Measurable (· ⊓ c)
/-- We say that a type has `MeasurableInf₂` if `uncurry (· ⊓ ·)` is a measurable functions.
For a typeclass assuming measurability of `(c ⊓ ·)` and `(· ⊓ c)` see `MeasurableInf`. -/
class MeasurableInf₂ (M : Type*) [MeasurableSpace M] [Inf M] : Prop where
measurable_inf : Measurable fun p : M × M => p.1 ⊓ p.2
export MeasurableInf₂ (measurable_inf)
export MeasurableInf (measurable_const_inf measurable_inf_const)
variable {M : Type*} [MeasurableSpace M]
section OrderDual
instance (priority := 100) OrderDual.instMeasurableSup [Inf M] [MeasurableInf M] :
MeasurableSup Mᵒᵈ :=
⟨@measurable_const_inf M _ _ _, @measurable_inf_const M _ _ _⟩
instance (priority := 100) OrderDual.instMeasurableInf [Sup M] [MeasurableSup M] :
MeasurableInf Mᵒᵈ :=
⟨@measurable_const_sup M _ _ _, @measurable_sup_const M _ _ _⟩
instance (priority := 100) OrderDual.instMeasurableSup₂ [Inf M] [MeasurableInf₂ M] :
MeasurableSup₂ Mᵒᵈ :=
⟨@measurable_inf M _ _ _⟩
instance (priority := 100) OrderDual.instMeasurableInf₂ [Sup M] [MeasurableSup₂ M] :
MeasurableInf₂ Mᵒᵈ :=
⟨@measurable_sup M _ _ _⟩
end OrderDual
variable {α : Type*} {m : MeasurableSpace α} {μ : Measure α} {f g : α → M}
section Sup
variable [Sup M]
section MeasurableSup
variable [MeasurableSup M]
@[measurability]
theorem Measurable.const_sup (hf : Measurable f) (c : M) : Measurable fun x => c ⊔ f x :=
(measurable_const_sup c).comp hf
@[measurability]
theorem AEMeasurable.const_sup (hf : AEMeasurable f μ) (c : M) :
AEMeasurable (fun x => c ⊔ f x) μ :=
(MeasurableSup.measurable_const_sup c).comp_aemeasurable hf
@[measurability]
theorem Measurable.sup_const (hf : Measurable f) (c : M) : Measurable fun x => f x ⊔ c :=
(measurable_sup_const c).comp hf
@[measurability]
theorem AEMeasurable.sup_const (hf : AEMeasurable f μ) (c : M) :
AEMeasurable (fun x => f x ⊔ c) μ :=
(measurable_sup_const c).comp_aemeasurable hf
end MeasurableSup
section MeasurableSup₂
variable [MeasurableSup₂ M]
@[measurability]
theorem Measurable.sup' (hf : Measurable f) (hg : Measurable g) : Measurable (f ⊔ g) :=
measurable_sup.comp (hf.prod_mk hg)
@[measurability]
theorem Measurable.sup (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a ⊔ g a :=
measurable_sup.comp (hf.prod_mk hg)
@[measurability]
theorem AEMeasurable.sup' (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (f ⊔ g) μ :=
measurable_sup.comp_aemeasurable (hf.prod_mk hg)
@[measurability]
theorem AEMeasurable.sup (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (fun a => f a ⊔ g a) μ :=
measurable_sup.comp_aemeasurable (hf.prod_mk hg)
instance (priority := 100) MeasurableSup₂.toMeasurableSup : MeasurableSup M :=
⟨fun _ => measurable_const.sup measurable_id, fun _ => measurable_id.sup measurable_const⟩
end MeasurableSup₂
end Sup
section Inf
variable [Inf M]
section MeasurableInf
variable [MeasurableInf M]
@[measurability]
theorem Measurable.const_inf (hf : Measurable f) (c : M) : Measurable fun x => c ⊓ f x :=
(measurable_const_inf c).comp hf
@[measurability]
theorem AEMeasurable.const_inf (hf : AEMeasurable f μ) (c : M) :
AEMeasurable (fun x => c ⊓ f x) μ :=
(MeasurableInf.measurable_const_inf c).comp_aemeasurable hf
@[measurability]
theorem Measurable.inf_const (hf : Measurable f) (c : M) : Measurable fun x => f x ⊓ c :=
(measurable_inf_const c).comp hf
@[measurability]
theorem AEMeasurable.inf_const (hf : AEMeasurable f μ) (c : M) :
AEMeasurable (fun x => f x ⊓ c) μ :=
(measurable_inf_const c).comp_aemeasurable hf
end MeasurableInf
section MeasurableInf₂
variable [MeasurableInf₂ M]
@[measurability]
theorem Measurable.inf' (hf : Measurable f) (hg : Measurable g) : Measurable (f ⊓ g) :=
measurable_inf.comp (hf.prod_mk hg)
@[measurability]
theorem Measurable.inf (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a ⊓ g a :=
measurable_inf.comp (hf.prod_mk hg)
@[measurability]
theorem AEMeasurable.inf' (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (f ⊓ g) μ :=
measurable_inf.comp_aemeasurable (hf.prod_mk hg)
@[measurability]
theorem AEMeasurable.inf (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (fun a => f a ⊓ g a) μ :=
measurable_inf.comp_aemeasurable (hf.prod_mk hg)
instance (priority := 100) MeasurableInf₂.to_hasMeasurableInf : MeasurableInf M :=
⟨fun _ => measurable_const.inf measurable_id, fun _ => measurable_id.inf measurable_const⟩
end MeasurableInf₂
end Inf
section SemilatticeSup
open Finset
variable {δ : Type*} [MeasurableSpace δ] [SemilatticeSup α] [MeasurableSup₂ α]
@[measurability]
theorem Finset.measurable_sup' {ι : Type*} {s : Finset ι} (hs : s.Nonempty) {f : ι → δ → α}
(hf : ∀ n ∈ s, Measurable (f n)) : Measurable (s.sup' hs f) :=
Finset.sup'_induction hs _ (fun _f hf _g hg => hf.sup hg) fun n hn => hf n hn
@[measurability]
theorem Finset.measurable_range_sup' {f : ℕ → δ → α} {n : ℕ} (hf : ∀ k ≤ n, Measurable (f k)) :
Measurable ((range (n + 1)).sup' nonempty_range_succ f) := by
simp_rw [← Nat.lt_succ_iff] at hf
refine Finset.measurable_sup' _ ?_
simpa [Finset.mem_range]
@[measurability]
theorem Finset.measurable_range_sup'' {f : ℕ → δ → α} {n : ℕ} (hf : ∀ k ≤ n, Measurable (f k)) :
Measurable fun x => (range (n + 1)).sup' nonempty_range_succ fun k => f k x := by
convert Finset.measurable_range_sup' hf using 1
ext x
simp
end SemilatticeSup
|
MeasureTheory\Order\UpperLower.lean | /-
Copyright (c) 2022 Yaël Dillies, Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Kexing Ying
-/
import Mathlib.Analysis.Normed.Order.UpperLower
import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace
import Mathlib.Topology.Order.DenselyOrdered
/-!
# Order-connected sets are null-measurable
This file proves that order-connected sets in `ℝⁿ` under the pointwise order are null-measurable.
Recall that `x ≤ y` iff `∀ i, x i ≤ y i`, and `s` is order-connected iff
`∀ x y ∈ s, ∀ z, x ≤ z → z ≤ y → z ∈ s`.
## Main declarations
* `Set.OrdConnected.null_frontier`: The frontier of an order-connected set in `ℝⁿ` has measure `0`.
## Notes
We prove null-measurability in `ℝⁿ` with the `∞`-metric, but this transfers directly to `ℝⁿ` with
the Euclidean metric because they have the same measurable sets.
Null-measurability can't be strengthened to measurability because any antichain (and in particular
any subset of the antidiagonal `{(x, y) | x + y = 0}`) is order-connected.
## Sketch proof
1. To show an order-connected set is null-measurable, it is enough to show it has null frontier.
2. Since an order-connected set is the intersection of its upper and lower closure, it's enough to
show that upper and lower sets have null frontier.
3. WLOG let's prove it for an upper set `s`.
4. By the Lebesgue density theorem, it is enough to show that any frontier point `x` of `s` is not a
Lebesgue point, namely we want the density of `s` over small balls centered at `x` to not tend to
either `0` or `1`.
5. This is true, since by the upper setness of `s` we can intercalate a ball of radius `δ / 4` in
`s` intersected with the upper quadrant of the ball of radius `δ` centered at `x` (recall that the
balls are taken in the ∞-norm, so they are cubes), and another ball of radius `δ / 4` in `sᶜ` and
the lower quadrant of the ball of radius `δ` centered at `x`.
## TODO
Generalize so that it also applies to `ℝ × ℝ`, for example.
-/
open Filter MeasureTheory Metric Set
open scoped Topology
variable {ι : Type*} [Fintype ι] {s : Set (ι → ℝ)} {x y : ι → ℝ} {δ : ℝ}
/-- If we can fit a small ball inside a set `s` intersected with any neighborhood of `x`, then the
density of `s` near `x` is not `0`.
Along with `aux₁`, this proves that `x` is a Lebesgue point of `s`. This will be used to prove that
the frontier of an order-connected set is null. -/
private lemma aux₀
(h : ∀ δ, 0 < δ →
∃ y, closedBall y (δ / 4) ⊆ closedBall x δ ∧ closedBall y (δ / 4) ⊆ interior s) :
¬Tendsto (fun r ↦ volume (closure s ∩ closedBall x r) / volume (closedBall x r)) (𝓝[>] 0)
(𝓝 0) := by
choose f hf₀ hf₁ using h
intro H
obtain ⟨ε, -, hε', hε₀⟩ := exists_seq_strictAnti_tendsto_nhdsWithin (0 : ℝ)
refine not_eventually.2
(frequently_of_forall fun _ ↦ lt_irrefl $ ENNReal.ofReal $ 4⁻¹ ^ Fintype.card ι)
((Filter.Tendsto.eventually_lt (H.comp hε₀) tendsto_const_nhds ?_).mono fun n ↦
lt_of_le_of_lt ?_)
on_goal 2 =>
calc
ENNReal.ofReal (4⁻¹ ^ Fintype.card ι)
= volume (closedBall (f (ε n) (hε' n)) (ε n / 4)) / volume (closedBall x (ε n)) := ?_
_ ≤ volume (closure s ∩ closedBall x (ε n)) / volume (closedBall x (ε n)) := by
gcongr; exact subset_inter ((hf₁ _ $ hε' n).trans interior_subset_closure) $ hf₀ _ $ hε' n
have := hε' n
rw [Real.volume_pi_closedBall, Real.volume_pi_closedBall, ← ENNReal.ofReal_div_of_pos,
← div_pow, mul_div_mul_left _ _ (two_ne_zero' ℝ), div_right_comm, div_self, one_div]
all_goals positivity
/-- If we can fit a small ball inside a set `sᶜ` intersected with any neighborhood of `x`, then the
density of `s` near `x` is not `1`.
Along with `aux₀`, this proves that `x` is a Lebesgue point of `s`. This will be used to prove that
the frontier of an order-connected set is null. -/
private lemma aux₁
(h : ∀ δ, 0 < δ →
∃ y, closedBall y (δ / 4) ⊆ closedBall x δ ∧ closedBall y (δ / 4) ⊆ interior sᶜ) :
¬Tendsto (fun r ↦ volume (closure s ∩ closedBall x r) / volume (closedBall x r)) (𝓝[>] 0)
(𝓝 1) := by
choose f hf₀ hf₁ using h
intro H
obtain ⟨ε, -, hε', hε₀⟩ := exists_seq_strictAnti_tendsto_nhdsWithin (0 : ℝ)
refine not_eventually.2
(frequently_of_forall fun _ ↦ lt_irrefl $ 1 - ENNReal.ofReal (4⁻¹ ^ Fintype.card ι))
((Filter.Tendsto.eventually_lt tendsto_const_nhds (H.comp hε₀) $
ENNReal.sub_lt_self ENNReal.one_ne_top one_ne_zero ?_).mono
fun n ↦ lt_of_le_of_lt' ?_)
on_goal 2 =>
calc
volume (closure s ∩ closedBall x (ε n)) / volume (closedBall x (ε n))
≤ volume (closedBall x (ε n) \ closedBall (f (ε n) $ hε' n) (ε n / 4)) /
volume (closedBall x (ε n)) := by
gcongr
rw [diff_eq_compl_inter]
refine inter_subset_inter_left _ ?_
rw [subset_compl_comm, ← interior_compl]
exact hf₁ _ _
_ = 1 - ENNReal.ofReal (4⁻¹ ^ Fintype.card ι) := ?_
dsimp only
have := hε' n
rw [measure_diff (hf₀ _ _) _ ((Real.volume_pi_closedBall _ _).trans_ne ENNReal.ofReal_ne_top),
Real.volume_pi_closedBall, Real.volume_pi_closedBall, ENNReal.sub_div fun _ _ ↦ _,
ENNReal.div_self _ ENNReal.ofReal_ne_top, ← ENNReal.ofReal_div_of_pos, ← div_pow,
mul_div_mul_left _ _ (two_ne_zero' ℝ), div_right_comm, div_self, one_div]
all_goals try positivity
· simp_all
· measurability
theorem IsUpperSet.null_frontier (hs : IsUpperSet s) : volume (frontier s) = 0 := by
refine measure_mono_null (fun x hx ↦ ?_)
(Besicovitch.ae_tendsto_measure_inter_div_of_measurableSet _
(isClosed_closure (s := s)).measurableSet)
by_cases h : x ∈ closure s <;>
simp only [mem_compl_iff, mem_setOf, h, not_false_eq_true, indicator_of_not_mem,
indicator_of_mem, Pi.one_apply]
· refine aux₁ fun _ ↦ hs.compl.exists_subset_ball $ frontier_subset_closure ?_
rwa [frontier_compl]
· exact aux₀ fun _ ↦ hs.exists_subset_ball $ frontier_subset_closure hx
theorem IsLowerSet.null_frontier (hs : IsLowerSet s) : volume (frontier s) = 0 := by
refine measure_mono_null (fun x hx ↦ ?_)
(Besicovitch.ae_tendsto_measure_inter_div_of_measurableSet _
(isClosed_closure (s := s)).measurableSet)
by_cases h : x ∈ closure s <;>
simp only [mem_compl_iff, mem_setOf, h, not_false_eq_true, indicator_of_not_mem,
indicator_of_mem, Pi.one_apply]
· refine aux₁ fun _ ↦ hs.compl.exists_subset_ball $ frontier_subset_closure ?_
rwa [frontier_compl]
· exact aux₀ fun _ ↦ hs.exists_subset_ball $ frontier_subset_closure hx
theorem Set.OrdConnected.null_frontier (hs : s.OrdConnected) : volume (frontier s) = 0 := by
rw [← hs.upperClosure_inter_lowerClosure]
exact measure_mono_null (frontier_inter_subset _ _) $ measure_union_null
(measure_inter_null_of_null_left _ (UpperSet.upper _).null_frontier)
(measure_inter_null_of_null_right _ (LowerSet.lower _).null_frontier)
protected theorem Set.OrdConnected.nullMeasurableSet (hs : s.OrdConnected) : NullMeasurableSet s :=
nullMeasurableSet_of_null_frontier hs.null_frontier
theorem IsAntichain.volume_eq_zero [Nonempty ι] (hs : IsAntichain (· ≤ ·) s) : volume s = 0 := by
refine measure_mono_null ?_ hs.ordConnected.null_frontier
rw [← closure_diff_interior, hs.interior_eq_empty, diff_empty]
exact subset_closure
|
MeasureTheory\Order\Group\Lattice.lean | /-
Copyright (c) 2024 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Order.Group.PosPart
import Mathlib.MeasureTheory.Group.Arithmetic
import Mathlib.MeasureTheory.Order.Lattice
/-!
# Measurability results on groups with a lattice structure.
## Tags
measurable function, group, lattice operation
-/
variable {α β : Type*} [Lattice α] [Group α] [MeasurableSpace α]
[MeasurableSpace β] {f : β → α} (hf : Measurable f)
variable [MeasurableSup α]
@[to_additive (attr := measurability)]
theorem measurable_oneLePart : Measurable (oneLePart : α → α) :=
measurable_sup_const _
@[to_additive (attr := measurability)]
protected theorem Measurable.oneLePart : Measurable fun x ↦ oneLePart (f x) :=
measurable_oneLePart.comp hf
variable [MeasurableInv α]
@[to_additive (attr := measurability)]
theorem measurable_leOnePart : Measurable (leOnePart : α → α) :=
(measurable_sup_const _).comp measurable_inv
@[to_additive (attr := measurability)]
protected theorem Measurable.leOnePart : Measurable fun x ↦ leOnePart (f x) :=
measurable_leOnePart.comp hf
variable [MeasurableSup₂ α]
@[to_additive (attr := measurability)]
theorem measurable_mabs : Measurable (mabs : α → α) :=
measurable_id'.sup measurable_inv
@[to_additive (attr := measurability)]
protected theorem Measurable.mabs : Measurable fun x ↦ mabs (f x) :=
measurable_mabs.comp hf
|
MeasureTheory\OuterMeasure\AE.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury Kudryashov
-/
import Mathlib.MeasureTheory.OuterMeasure.Basic
/-!
# The “almost everywhere” filter of co-null sets.
If `μ` is an outer measure or a measure on `α`,
then `MeasureTheory.ae μ` is the filter of co-null sets: `s ∈ ae μ ↔ μ sᶜ = 0`.
In this file we define the filter and prove some basic theorems about it.
## Notation
- `∀ᵐ x ∂μ, p x`: the predicate `p` holds for `μ`-a.e. all `x`;
- `∃ᶠ x ∂μ, p x`: the predicate `p` holds on a set of nonzero measure;
- `f =ᵐ[μ] g`: `f x = g x` for `μ`-a.e. all `x`;
- `f ≤ᵐ[μ] g`: `f x ≤ g x` for `μ`-a.e. all `x`.
## Implementation details
All notation introduced in this file
reducibly unfolds to the corresponding definitions about filters,
so generic lemmas about `Filter.Eventually`, `Filter.EventuallyEq` etc apply.
However, we restate some lemmas specifically for `ae`.
## Tags
outer measure, measure, almost everywhere
-/
open Filter Set
open scoped ENNReal
namespace MeasureTheory
variable {α β F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α] {μ : F} {s t : Set α}
/-- The “almost everywhere” filter of co-null sets. -/
def ae (μ : F) : Filter α :=
.ofCountableUnion (μ · = 0) (fun _S hSc ↦ (measure_sUnion_null_iff hSc).2) fun _t ht _s hs ↦
measure_mono_null hs ht
/-- `∀ᵐ a ∂μ, p a` means that `p a` for a.e. `a`, i.e. `p` holds true away from a null set.
This is notation for `Filter.Eventually p (MeasureTheory.ae μ)`. -/
notation3 "∀ᵐ "(...)" ∂"μ", "r:(scoped p => Filter.Eventually p <| MeasureTheory.ae μ) => r
/-- `∃ᵐ a ∂μ, p a` means that `p` holds `∂μ`-frequently,
i.e. `p` holds on a set of positive measure.
This is notation for `Filter.Frequently p (MeasureTheory.ae μ)`. -/
notation3 "∃ᵐ "(...)" ∂"μ", "r:(scoped P => Filter.Frequently P <| MeasureTheory.ae μ) => r
/-- `f =ᵐ[μ] g` means `f` and `g` are eventually equal along the a.e. filter,
i.e. `f=g` away from a null set.
This is notation for `Filter.EventuallyEq (MeasureTheory.ae μ) f g`. -/
notation:50 f " =ᵐ[" μ:50 "] " g:50 => Filter.EventuallyEq (MeasureTheory.ae μ) f g
/-- `f ≤ᵐ[μ] g` means `f` is eventually less than `g` along the a.e. filter,
i.e. `f ≤ g` away from a null set.
This is notation for `Filter.EventuallyLE (MeasureTheory.ae μ) f g`. -/
notation:50 f " ≤ᵐ[" μ:50 "] " g:50 => Filter.EventuallyLE (MeasureTheory.ae μ) f g
theorem mem_ae_iff {s : Set α} : s ∈ ae μ ↔ μ sᶜ = 0 :=
Iff.rfl
theorem ae_iff {p : α → Prop} : (∀ᵐ a ∂μ, p a) ↔ μ { a | ¬p a } = 0 :=
Iff.rfl
theorem compl_mem_ae_iff {s : Set α} : sᶜ ∈ ae μ ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl]
theorem frequently_ae_iff {p : α → Prop} : (∃ᵐ a ∂μ, p a) ↔ μ { a | p a } ≠ 0 :=
not_congr compl_mem_ae_iff
theorem frequently_ae_mem_iff {s : Set α} : (∃ᵐ a ∂μ, a ∈ s) ↔ μ s ≠ 0 :=
not_congr compl_mem_ae_iff
theorem measure_zero_iff_ae_nmem {s : Set α} : μ s = 0 ↔ ∀ᵐ a ∂μ, a ∉ s :=
compl_mem_ae_iff.symm
theorem ae_of_all {p : α → Prop} (μ : F) : (∀ a, p a) → ∀ᵐ a ∂μ, p a :=
eventually_of_forall
instance instCountableInterFilter : CountableInterFilter (ae μ) := by
unfold ae; infer_instance
theorem ae_all_iff {ι : Sort*} [Countable ι] {p : α → ι → Prop} :
(∀ᵐ a ∂μ, ∀ i, p a i) ↔ ∀ i, ∀ᵐ a ∂μ, p a i :=
eventually_countable_forall
theorem all_ae_of {ι : Sort*} {p : α → ι → Prop} (hp : ∀ᵐ a ∂μ, ∀ i, p a i) (i : ι) :
∀ᵐ a ∂μ, p a i := by
filter_upwards [hp] with a ha using ha i
lemma ae_iff_of_countable [Countable α] {p : α → Prop} : (∀ᵐ x ∂μ, p x) ↔ ∀ x, μ {x} ≠ 0 → p x := by
rw [ae_iff, measure_null_iff_singleton]
exacts [forall_congr' fun _ ↦ not_imp_comm, Set.to_countable _]
theorem ae_ball_iff {ι : Type*} {S : Set ι} (hS : S.Countable) {p : α → ∀ i ∈ S, Prop} :
(∀ᵐ x ∂μ, ∀ i (hi : i ∈ S), p x i hi) ↔ ∀ i (hi : i ∈ S), ∀ᵐ x ∂μ, p x i hi :=
eventually_countable_ball hS
theorem ae_eq_refl (f : α → β) : f =ᵐ[μ] f :=
EventuallyEq.rfl
theorem ae_eq_symm {f g : α → β} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f :=
h.symm
theorem ae_eq_trans {f g h : α → β} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) : f =ᵐ[μ] h :=
h₁.trans h₂
theorem ae_le_of_ae_lt {β : Type*} [Preorder β] {f g : α → β} (h : ∀ᵐ x ∂μ, f x < g x) :
f ≤ᵐ[μ] g :=
h.mono fun _ ↦ le_of_lt
@[simp]
theorem ae_eq_empty : s =ᵐ[μ] (∅ : Set α) ↔ μ s = 0 :=
eventuallyEq_empty.trans <| by simp only [ae_iff, Classical.not_not, setOf_mem_eq]
-- Porting note: The priority should be higher than `eventuallyEq_univ`.
@[simp high]
theorem ae_eq_univ : s =ᵐ[μ] (univ : Set α) ↔ μ sᶜ = 0 :=
eventuallyEq_univ
theorem ae_le_set : s ≤ᵐ[μ] t ↔ μ (s \ t) = 0 :=
calc
s ≤ᵐ[μ] t ↔ ∀ᵐ x ∂μ, x ∈ s → x ∈ t := Iff.rfl
_ ↔ μ (s \ t) = 0 := by simp [ae_iff]; rfl
theorem ae_le_set_inter {s' t' : Set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∩ s' : Set α) ≤ᵐ[μ] (t ∩ t' : Set α) :=
h.inter h'
theorem ae_le_set_union {s' t' : Set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∪ s' : Set α) ≤ᵐ[μ] (t ∪ t' : Set α) :=
h.union h'
theorem union_ae_eq_right : (s ∪ t : Set α) =ᵐ[μ] t ↔ μ (s \ t) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set, union_diff_right,
diff_eq_empty.2 Set.subset_union_right]
theorem diff_ae_eq_self : (s \ t : Set α) =ᵐ[μ] s ↔ μ (s ∩ t) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set, diff_diff_right, diff_diff,
diff_eq_empty.2 Set.subset_union_right]
theorem diff_null_ae_eq_self (ht : μ t = 0) : (s \ t : Set α) =ᵐ[μ] s :=
diff_ae_eq_self.mpr (measure_mono_null inter_subset_right ht)
theorem ae_eq_set {s t : Set α} : s =ᵐ[μ] t ↔ μ (s \ t) = 0 ∧ μ (t \ s) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set]
open scoped symmDiff in
@[simp]
theorem measure_symmDiff_eq_zero_iff {s t : Set α} : μ (s ∆ t) = 0 ↔ s =ᵐ[μ] t := by
simp [ae_eq_set, symmDiff_def]
@[simp]
theorem ae_eq_set_compl_compl {s t : Set α} : sᶜ =ᵐ[μ] tᶜ ↔ s =ᵐ[μ] t := by
simp only [← measure_symmDiff_eq_zero_iff, compl_symmDiff_compl]
theorem ae_eq_set_compl {s t : Set α} : sᶜ =ᵐ[μ] t ↔ s =ᵐ[μ] tᶜ := by
rw [← ae_eq_set_compl_compl, compl_compl]
theorem ae_eq_set_inter {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∩ s' : Set α) =ᵐ[μ] (t ∩ t' : Set α) :=
h.inter h'
theorem ae_eq_set_union {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∪ s' : Set α) =ᵐ[μ] (t ∪ t' : Set α) :=
h.union h'
theorem union_ae_eq_univ_of_ae_eq_univ_left (h : s =ᵐ[μ] univ) : (s ∪ t : Set α) =ᵐ[μ] univ :=
(ae_eq_set_union h (ae_eq_refl t)).trans <| by rw [univ_union]
theorem union_ae_eq_univ_of_ae_eq_univ_right (h : t =ᵐ[μ] univ) : (s ∪ t : Set α) =ᵐ[μ] univ := by
convert ae_eq_set_union (ae_eq_refl s) h
rw [union_univ]
theorem union_ae_eq_right_of_ae_eq_empty (h : s =ᵐ[μ] (∅ : Set α)) : (s ∪ t : Set α) =ᵐ[μ] t := by
convert ae_eq_set_union h (ae_eq_refl t)
rw [empty_union]
theorem union_ae_eq_left_of_ae_eq_empty (h : t =ᵐ[μ] (∅ : Set α)) : (s ∪ t : Set α) =ᵐ[μ] s := by
convert ae_eq_set_union (ae_eq_refl s) h
rw [union_empty]
theorem inter_ae_eq_right_of_ae_eq_univ (h : s =ᵐ[μ] univ) : (s ∩ t : Set α) =ᵐ[μ] t := by
convert ae_eq_set_inter h (ae_eq_refl t)
rw [univ_inter]
theorem inter_ae_eq_left_of_ae_eq_univ (h : t =ᵐ[μ] univ) : (s ∩ t : Set α) =ᵐ[μ] s := by
convert ae_eq_set_inter (ae_eq_refl s) h
rw [inter_univ]
theorem inter_ae_eq_empty_of_ae_eq_empty_left (h : s =ᵐ[μ] (∅ : Set α)) :
(s ∩ t : Set α) =ᵐ[μ] (∅ : Set α) := by
convert ae_eq_set_inter h (ae_eq_refl t)
rw [empty_inter]
theorem inter_ae_eq_empty_of_ae_eq_empty_right (h : t =ᵐ[μ] (∅ : Set α)) :
(s ∩ t : Set α) =ᵐ[μ] (∅ : Set α) := by
convert ae_eq_set_inter (ae_eq_refl s) h
rw [inter_empty]
@[to_additive]
theorem _root_.Set.mulIndicator_ae_eq_one {M : Type*} [One M] {f : α → M} {s : Set α} :
s.mulIndicator f =ᵐ[μ] 1 ↔ μ (s ∩ f.mulSupport) = 0 := by
simp [EventuallyEq, eventually_iff, ae, compl_setOf]; rfl
/-- If `s ⊆ t` modulo a set of measure `0`, then `μ s ≤ μ t`. -/
@[mono]
theorem measure_mono_ae (H : s ≤ᵐ[μ] t) : μ s ≤ μ t :=
calc
μ s ≤ μ (s ∪ t) := measure_mono subset_union_left
_ = μ (t ∪ s \ t) := by rw [union_diff_self, Set.union_comm]
_ ≤ μ t + μ (s \ t) := measure_union_le _ _
_ = μ t := by rw [ae_le_set.1 H, add_zero]
alias _root_.Filter.EventuallyLE.measure_le := measure_mono_ae
/-- If two sets are equal modulo a set of measure zero, then `μ s = μ t`. -/
theorem measure_congr (H : s =ᵐ[μ] t) : μ s = μ t :=
le_antisymm H.le.measure_le H.symm.le.measure_le
alias _root_.Filter.EventuallyEq.measure_eq := measure_congr
theorem measure_mono_null_ae (H : s ≤ᵐ[μ] t) (ht : μ t = 0) : μ s = 0 :=
nonpos_iff_eq_zero.1 <| ht ▸ H.measure_le
end MeasureTheory
|
MeasureTheory\OuterMeasure\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Countable.Basic
import Mathlib.Data.Fin.VecNotation
import Mathlib.Order.Disjointed
import Mathlib.MeasureTheory.OuterMeasure.Defs
/-!
# Outer Measures
An outer measure is a function `μ : Set α → ℝ≥0∞`, from the powerset of a type to the extended
nonnegative real numbers that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is monotone;
3. `μ` is countably subadditive. This means that the outer measure of a countable union is at most
the sum of the outer measure on the individual sets.
Note that we do not need `α` to be measurable to define an outer measure.
## References
<https://en.wikipedia.org/wiki/Outer_measure>
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
section OuterMeasureClass
variable {α ι F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α]
{μ : F} {s t : Set α}
@[simp]
theorem measure_empty : μ ∅ = 0 := OuterMeasureClass.measure_empty μ
@[mono, gcongr]
theorem measure_mono (h : s ⊆ t) : μ s ≤ μ t :=
OuterMeasureClass.measure_mono μ h
theorem measure_mono_null (h : s ⊆ t) (ht : μ t = 0) : μ s = 0 :=
eq_bot_mono (measure_mono h) ht
theorem measure_pos_of_superset (h : s ⊆ t) (hs : μ s ≠ 0) : 0 < μ t :=
hs.bot_lt.trans_le (measure_mono h)
theorem measure_iUnion_le [Countable ι] (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) := by
refine rel_iSup_tsum μ measure_empty (· ≤ ·) (fun t ↦ ?_) _
calc
μ (⋃ i, t i) = μ (⋃ i, disjointed t i) := by rw [iUnion_disjointed]
_ ≤ ∑' i, μ (disjointed t i) :=
OuterMeasureClass.measure_iUnion_nat_le _ _ (disjoint_disjointed _)
_ ≤ ∑' i, μ (t i) := by gcongr; apply disjointed_subset
theorem measure_biUnion_le {I : Set ι} (μ : F) (hI : I.Countable) (s : ι → Set α) :
μ (⋃ i ∈ I, s i) ≤ ∑' i : I, μ (s i) := by
have := hI.to_subtype
rw [biUnion_eq_iUnion]
apply measure_iUnion_le
theorem measure_biUnion_finset_le (I : Finset ι) (s : ι → Set α) :
μ (⋃ i ∈ I, s i) ≤ ∑ i ∈ I, μ (s i) :=
(measure_biUnion_le μ I.countable_toSet s).trans_eq <| I.tsum_subtype (μ <| s ·)
theorem measure_iUnion_fintype_le [Fintype ι] (μ : F) (s : ι → Set α) :
μ (⋃ i, s i) ≤ ∑ i, μ (s i) := by
simpa using measure_biUnion_finset_le Finset.univ s
theorem measure_union_le (s t : Set α) : μ (s ∪ t) ≤ μ s + μ t := by
simpa [union_eq_iUnion] using measure_iUnion_fintype_le μ (cond · s t)
lemma measure_univ_le_add_compl (s : Set α) : μ univ ≤ μ s + μ sᶜ :=
s.union_compl_self ▸ measure_union_le s sᶜ
theorem measure_le_inter_add_diff (μ : F) (s t : Set α) : μ s ≤ μ (s ∩ t) + μ (s \ t) := by
simpa using measure_union_le (s ∩ t) (s \ t)
theorem measure_diff_null (ht : μ t = 0) : μ (s \ t) = μ s :=
(measure_mono diff_subset).antisymm <| calc
μ s ≤ μ (s ∩ t) + μ (s \ t) := measure_le_inter_add_diff _ _ _
_ ≤ μ t + μ (s \ t) := by gcongr; apply inter_subset_right
_ = μ (s \ t) := by simp [ht]
theorem measure_biUnion_null_iff {I : Set ι} (hI : I.Countable) {s : ι → Set α} :
μ (⋃ i ∈ I, s i) = 0 ↔ ∀ i ∈ I, μ (s i) = 0 := by
refine ⟨fun h i hi ↦ measure_mono_null (subset_biUnion_of_mem hi) h, fun h ↦ ?_⟩
have _ := hI.to_subtype
simpa [h] using measure_iUnion_le (μ := μ) fun x : I ↦ s x
theorem measure_sUnion_null_iff {S : Set (Set α)} (hS : S.Countable) :
μ (⋃₀ S) = 0 ↔ ∀ s ∈ S, μ s = 0 := by
rw [sUnion_eq_biUnion, measure_biUnion_null_iff hS]
@[simp]
theorem measure_iUnion_null_iff {ι : Sort*} [Countable ι] {s : ι → Set α} :
μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 := by
rw [← sUnion_range, measure_sUnion_null_iff (countable_range s), forall_mem_range]
alias ⟨_, measure_iUnion_null⟩ := measure_iUnion_null_iff
@[simp]
theorem measure_union_null_iff : μ (s ∪ t) = 0 ↔ μ s = 0 ∧ μ t = 0 := by
simp [union_eq_iUnion, and_comm]
theorem measure_union_null (hs : μ s = 0) (ht : μ t = 0) : μ (s ∪ t) = 0 := by simp [*]
lemma measure_null_iff_singleton (hs : s.Countable) : μ s = 0 ↔ ∀ x ∈ s, μ {x} = 0 := by
rw [← measure_biUnion_null_iff hs, biUnion_of_singleton]
/-- Let `μ` be an (outer) measure; let `s : ι → Set α` be a sequence of sets, `S = ⋃ n, s n`.
If `μ (S \ s n)` tends to zero along some nontrivial filter (usually `Filter.atTop` on `ι = ℕ`),
then `μ S = ⨆ n, μ (s n)`. -/
theorem measure_iUnion_of_tendsto_zero {ι} (μ : F) {s : ι → Set α} (l : Filter ι) [NeBot l]
(h0 : Tendsto (fun k => μ ((⋃ n, s n) \ s k)) l (𝓝 0)) : μ (⋃ n, s n) = ⨆ n, μ (s n) := by
refine le_antisymm ?_ <| iSup_le fun n ↦ measure_mono <| subset_iUnion _ _
set S := ⋃ n, s n
set M := ⨆ n, μ (s n)
have A : ∀ k, μ S ≤ M + μ (S \ s k) := fun k ↦ calc
μ S ≤ μ (S ∩ s k) + μ (S \ s k) := measure_le_inter_add_diff _ _ _
_ ≤ μ (s k) + μ (S \ s k) := by gcongr; apply inter_subset_right
_ ≤ M + μ (S \ s k) := by gcongr; exact le_iSup (μ ∘ s) k
have B : Tendsto (fun k ↦ M + μ (S \ s k)) l (𝓝 M) := by simpa using tendsto_const_nhds.add h0
exact ge_of_tendsto' B A
/-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure
in a second-countable space. -/
theorem measure_null_of_locally_null [TopologicalSpace α] [SecondCountableTopology α]
(s : Set α) (hs : ∀ x ∈ s, ∃ u ∈ 𝓝[s] x, μ u = 0) : μ s = 0 := by
choose! u hxu hu₀ using hs
choose t ht using TopologicalSpace.countable_cover_nhdsWithin hxu
rcases ht with ⟨ts, t_count, ht⟩
apply measure_mono_null ht
exact (measure_biUnion_null_iff t_count).2 fun x hx => hu₀ x (ts hx)
/-- If `m s ≠ 0`, then for some point `x ∈ s` and any `t ∈ 𝓝[s] x` we have `0 < m t`. -/
theorem exists_mem_forall_mem_nhdsWithin_pos_measure [TopologicalSpace α]
[SecondCountableTopology α] {s : Set α} (hs : μ s ≠ 0) :
∃ x ∈ s, ∀ t ∈ 𝓝[s] x, 0 < μ t := by
contrapose! hs
simp only [nonpos_iff_eq_zero] at hs
exact measure_null_of_locally_null s hs
end OuterMeasureClass
namespace OuterMeasure
variable {α β : Type*} {m : OuterMeasure α}
@[deprecated measure_empty (since := "2024-05-14")]
theorem empty' (m : OuterMeasure α) : m ∅ = 0 := measure_empty
@[deprecated measure_mono (since := "2024-05-14")]
theorem mono' (m : OuterMeasure α) {s₁ s₂} (h : s₁ ⊆ s₂) : m s₁ ≤ m s₂ := by gcongr
@[deprecated measure_mono_null (since := "2024-05-14")]
theorem mono_null (m : OuterMeasure α) {s t} (h : s ⊆ t) (ht : m t = 0) : m s = 0 :=
measure_mono_null h ht
@[deprecated measure_pos_of_superset (since := "2024-05-14")]
theorem pos_of_subset_ne_zero (m : OuterMeasure α) {a b : Set α} (hs : a ⊆ b) (hnz : m a ≠ 0) :
0 < m b :=
measure_pos_of_superset hs hnz
@[deprecated measure_iUnion_le (since := "2024-05-14")]
protected theorem iUnion (m : OuterMeasure α) {β} [Countable β] (s : β → Set α) :
m (⋃ i, s i) ≤ ∑' i, m (s i) :=
measure_iUnion_le s
@[deprecated measure_biUnion_null_iff (since := "2024-05-14")]
theorem biUnion_null_iff (m : OuterMeasure α) {s : Set β} (hs : s.Countable) {t : β → Set α} :
m (⋃ i ∈ s, t i) = 0 ↔ ∀ i ∈ s, m (t i) = 0 :=
measure_biUnion_null_iff hs
@[deprecated measure_sUnion_null_iff (since := "2024-05-14")]
theorem sUnion_null_iff (m : OuterMeasure α) {S : Set (Set α)} (hS : S.Countable) :
m (⋃₀ S) = 0 ↔ ∀ s ∈ S, m s = 0 := measure_sUnion_null_iff hS
@[deprecated measure_iUnion_null_iff (since := "2024-05-14")]
theorem iUnion_null_iff {ι : Sort*} [Countable ι] (m : OuterMeasure α) {s : ι → Set α} :
m (⋃ i, s i) = 0 ↔ ∀ i, m (s i) = 0 :=
measure_iUnion_null_iff
@[deprecated measure_iUnion_null (since := "2024-05-14")]
alias ⟨_, iUnion_null⟩ := iUnion_null_iff
@[deprecated (since := "2024-01-14")]
theorem iUnion_null_iff' (m : OuterMeasure α) {ι : Prop} {s : ι → Set α} :
m (⋃ i, s i) = 0 ↔ ∀ i, m (s i) = 0 :=
measure_iUnion_null_iff
@[deprecated measure_biUnion_finset_le (since := "2024-05-14")]
protected theorem iUnion_finset (m : OuterMeasure α) (s : β → Set α) (t : Finset β) :
m (⋃ i ∈ t, s i) ≤ ∑ i ∈ t, m (s i) :=
measure_biUnion_finset_le t s
@[deprecated measure_union_le (since := "2024-05-14")]
protected theorem union (m : OuterMeasure α) (s₁ s₂ : Set α) : m (s₁ ∪ s₂) ≤ m s₁ + m s₂ :=
measure_union_le s₁ s₂
/-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure
in a second-countable space. -/
@[deprecated measure_null_of_locally_null (since := "2024-05-14")]
theorem null_of_locally_null [TopologicalSpace α] [SecondCountableTopology α] (m : OuterMeasure α)
(s : Set α) (hs : ∀ x ∈ s, ∃ u ∈ 𝓝[s] x, m u = 0) : m s = 0 :=
measure_null_of_locally_null s hs
/-- If `m s ≠ 0`, then for some point `x ∈ s` and any `t ∈ 𝓝[s] x` we have `0 < m t`. -/
@[deprecated exists_mem_forall_mem_nhdsWithin_pos_measure (since := "2024-05-14")]
theorem exists_mem_forall_mem_nhds_within_pos [TopologicalSpace α] [SecondCountableTopology α]
(m : OuterMeasure α) {s : Set α} (hs : m s ≠ 0) : ∃ x ∈ s, ∀ t ∈ 𝓝[s] x, 0 < m t :=
exists_mem_forall_mem_nhdsWithin_pos_measure hs
/-- If `s : ι → Set α` is a sequence of sets, `S = ⋃ n, s n`, and `m (S \ s n)` tends to zero along
some nontrivial filter (usually `atTop` on `ι = ℕ`), then `m S = ⨆ n, m (s n)`. -/
theorem iUnion_of_tendsto_zero {ι} (m : OuterMeasure α) {s : ι → Set α} (l : Filter ι) [NeBot l]
(h0 : Tendsto (fun k => m ((⋃ n, s n) \ s k)) l (𝓝 0)) : m (⋃ n, s n) = ⨆ n, m (s n) :=
measure_iUnion_of_tendsto_zero m l h0
/-- If `s : ℕ → Set α` is a monotone sequence of sets such that `∑' k, m (s (k + 1) \ s k) ≠ ∞`,
then `m (⋃ n, s n) = ⨆ n, m (s n)`. -/
theorem iUnion_nat_of_monotone_of_tsum_ne_top (m : OuterMeasure α) {s : ℕ → Set α}
(h_mono : ∀ n, s n ⊆ s (n + 1)) (h0 : (∑' k, m (s (k + 1) \ s k)) ≠ ∞) :
m (⋃ n, s n) = ⨆ n, m (s n) := by
classical
refine measure_iUnion_of_tendsto_zero m atTop ?_
refine tendsto_nhds_bot_mono' (ENNReal.tendsto_sum_nat_add _ h0) fun n => ?_
refine (m.mono ?_).trans (measure_iUnion_le _)
-- Current goal: `(⋃ k, s k) \ s n ⊆ ⋃ k, s (k + n + 1) \ s (k + n)`
have h' : Monotone s := @monotone_nat_of_le_succ (Set α) _ _ h_mono
simp only [diff_subset_iff, iUnion_subset_iff]
intro i x hx
have : ∃i, x ∈ s i := by exists i
rcases Nat.findX this with ⟨j, hj, hlt⟩
clear hx i
rcases le_or_lt j n with hjn | hnj
· exact Or.inl (h' hjn hj)
have : j - (n + 1) + n + 1 = j := by omega
refine Or.inr (mem_iUnion.2 ⟨j - (n + 1), ?_, hlt _ ?_⟩)
· rwa [this]
· rw [← Nat.succ_le_iff, Nat.succ_eq_add_one, this]
@[deprecated measure_le_inter_add_diff (since := "2024-05-14")]
theorem le_inter_add_diff {m : OuterMeasure α} {t : Set α} (s : Set α) :
m t ≤ m (t ∩ s) + m (t \ s) :=
measure_le_inter_add_diff m t s
@[deprecated measure_diff_null (since := "2024-05-14")]
theorem diff_null (m : OuterMeasure α) (s : Set α) {t : Set α} (ht : m t = 0) : m (s \ t) = m s :=
measure_diff_null ht
@[deprecated measure_union_null (since := "2024-05-14")]
theorem union_null (m : OuterMeasure α) {s₁ s₂ : Set α} (h₁ : m s₁ = 0) (h₂ : m s₂ = 0) :
m (s₁ ∪ s₂) = 0 :=
measure_union_null h₁ h₂
theorem coe_fn_injective : Injective fun (μ : OuterMeasure α) (s : Set α) => μ s :=
DFunLike.coe_injective
@[ext]
theorem ext {μ₁ μ₂ : OuterMeasure α} (h : ∀ s, μ₁ s = μ₂ s) : μ₁ = μ₂ :=
DFunLike.ext _ _ h
/-- A version of `MeasureTheory.OuterMeasure.ext` that assumes `μ₁ s = μ₂ s` on all *nonempty*
sets `s`, and gets `μ₁ ∅ = μ₂ ∅` from `MeasureTheory.OuterMeasure.empty'`. -/
theorem ext_nonempty {μ₁ μ₂ : OuterMeasure α} (h : ∀ s : Set α, s.Nonempty → μ₁ s = μ₂ s) :
μ₁ = μ₂ :=
ext fun s => s.eq_empty_or_nonempty.elim (fun he => by simp [he]) (h s)
end OuterMeasure
end MeasureTheory
|
MeasureTheory\OuterMeasure\Caratheodory.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.OfFunction
import Mathlib.MeasureTheory.PiSystem
/-!
# The Caratheodory σ-algebra of an outer measure
Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `caratheodory` is the Carathéodory-measurable space of an outer measure.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
Carathéodory-measurable, Carathéodory's criterion
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section CaratheodoryMeasurable
universe u
variable {α : Type u} (m : OuterMeasure α)
attribute [local simp] Set.inter_comm Set.inter_left_comm Set.inter_assoc
variable {s s₁ s₂ : Set α}
/-- A set `s` is Carathéodory-measurable for an outer measure `m` if for all sets `t` we have
`m t = m (t ∩ s) + m (t \ s)`. -/
def IsCaratheodory (s : Set α) : Prop :=
∀ t, m t = m (t ∩ s) + m (t \ s)
theorem isCaratheodory_iff_le' {s : Set α} :
IsCaratheodory m s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t :=
forall_congr' fun _ => le_antisymm_iff.trans <| and_iff_right <| measure_le_inter_add_diff _ _ _
@[simp]
theorem isCaratheodory_empty : IsCaratheodory m ∅ := by simp [IsCaratheodory, m.empty, diff_empty]
theorem isCaratheodory_compl : IsCaratheodory m s₁ → IsCaratheodory m s₁ᶜ := by
simp [IsCaratheodory, diff_eq, add_comm]
@[simp]
theorem isCaratheodory_compl_iff : IsCaratheodory m sᶜ ↔ IsCaratheodory m s :=
⟨fun h => by simpa using isCaratheodory_compl m h, isCaratheodory_compl m⟩
theorem isCaratheodory_union (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) :
IsCaratheodory m (s₁ ∪ s₂) := fun t => by
rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)), inter_diff_assoc _ _ s₁,
Set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right Set.subset_union_left,
union_diff_left, h₂ (t ∩ s₁)]
simp [diff_eq, add_assoc]
theorem measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : IsCaratheodory m s₁) {t : Set α} :
m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) := by
rw [h₁, Set.inter_assoc, Set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h]
theorem isCaratheodory_iUnion_lt {s : ℕ → Set α} :
∀ {n : ℕ}, (∀ i < n, IsCaratheodory m (s i)) → IsCaratheodory m (⋃ i < n, s i)
| 0, _ => by simp [Nat.not_lt_zero]
| n + 1, h => by
rw [biUnion_lt_succ]
exact isCaratheodory_union m
(isCaratheodory_iUnion_lt fun i hi => h i <| lt_of_lt_of_le hi <| Nat.le_succ _)
(h n (le_refl (n + 1)))
theorem isCaratheodory_inter (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) :
IsCaratheodory m (s₁ ∩ s₂) := by
rw [← isCaratheodory_compl_iff, Set.compl_inter]
exact isCaratheodory_union _ (isCaratheodory_compl _ h₁) (isCaratheodory_compl _ h₂)
theorem isCaratheodory_sum {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i))
(hd : Pairwise (Disjoint on s)) {t : Set α} :
∀ {n}, (∑ i ∈ Finset.range n, m (t ∩ s i)) = m (t ∩ ⋃ i < n, s i)
| 0 => by simp [Nat.not_lt_zero, m.empty]
| Nat.succ n => by
rw [biUnion_lt_succ, Finset.sum_range_succ, Set.union_comm, isCaratheodory_sum h hd,
m.measure_inter_union _ (h n), add_comm]
intro a
simpa using fun (h₁ : a ∈ s n) i (hi : i < n) h₂ => (hd (ne_of_gt hi)).le_bot ⟨h₁, h₂⟩
set_option linter.deprecated false in -- not immediately obvious how to replace `iUnion` here.
theorem isCaratheodory_iUnion_nat {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i))
(hd : Pairwise (Disjoint on s)) : IsCaratheodory m (⋃ i, s i) := by
apply (isCaratheodory_iff_le' m).mpr
intro t
have hp : m (t ∩ ⋃ i, s i) ≤ ⨆ n, m (t ∩ ⋃ i < n, s i) := by
convert m.iUnion fun i => t ∩ s i using 1
· simp [inter_iUnion]
· simp [ENNReal.tsum_eq_iSup_nat, isCaratheodory_sum m h hd]
refine le_trans (add_le_add_right hp _) ?_
rw [ENNReal.iSup_add]
refine iSup_le fun n => le_trans (add_le_add_left ?_ _)
(ge_of_eq (isCaratheodory_iUnion_lt m (fun i _ => h i) _))
refine m.mono (diff_subset_diff_right ?_)
exact iUnion₂_subset fun i _ => subset_iUnion _ i
theorem f_iUnion {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) :
m (⋃ i, s i) = ∑' i, m (s i) := by
refine le_antisymm (measure_iUnion_le s) ?_
rw [ENNReal.tsum_eq_iSup_nat]
refine iSup_le fun n => ?_
have := @isCaratheodory_sum _ m _ h hd univ n
simp only [inter_comm, inter_univ, univ_inter] at this; simp only [this]
exact m.mono (iUnion₂_subset fun i _ => subset_iUnion _ i)
/-- The Carathéodory-measurable sets for an outer measure `m` form a Dynkin system. -/
def caratheodoryDynkin : MeasurableSpace.DynkinSystem α where
Has := IsCaratheodory m
has_empty := isCaratheodory_empty m
has_compl s := isCaratheodory_compl m s
has_iUnion_nat f hf hn := by apply isCaratheodory_iUnion_nat m hf f
/-- Given an outer measure `μ`, the Carathéodory-measurable space is
defined such that `s` is measurable if `∀t, μ t = μ (t ∩ s) + μ (t \ s)`. -/
protected def caratheodory : MeasurableSpace α := by
apply MeasurableSpace.DynkinSystem.toMeasurableSpace (caratheodoryDynkin m)
intro s₁ s₂
apply isCaratheodory_inter
theorem isCaratheodory_iff {s : Set α} :
MeasurableSet[OuterMeasure.caratheodory m] s ↔ ∀ t, m t = m (t ∩ s) + m (t \ s) :=
Iff.rfl
theorem isCaratheodory_iff_le {s : Set α} :
MeasurableSet[OuterMeasure.caratheodory m] s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t :=
isCaratheodory_iff_le' m
protected theorem iUnion_eq_of_caratheodory {s : ℕ → Set α}
(h : ∀ i, MeasurableSet[OuterMeasure.caratheodory m] (s i)) (hd : Pairwise (Disjoint on s)) :
m (⋃ i, s i) = ∑' i, m (s i) :=
f_iUnion m h hd
end CaratheodoryMeasurable
variable {α : Type*}
theorem ofFunction_caratheodory {m : Set α → ℝ≥0∞} {s : Set α} {h₀ : m ∅ = 0}
(hs : ∀ t, m (t ∩ s) + m (t \ s) ≤ m t) :
MeasurableSet[(OuterMeasure.ofFunction m h₀).caratheodory] s := by
apply (isCaratheodory_iff_le _).mpr
refine fun t => le_iInf fun f => le_iInf fun hf => ?_
refine
le_trans
(add_le_add ((iInf_le_of_le fun i => f i ∩ s) <| iInf_le _ ?_)
((iInf_le_of_le fun i => f i \ s) <| iInf_le _ ?_))
?_
· rw [← iUnion_inter]
exact inter_subset_inter_left _ hf
· rw [← iUnion_diff]
exact diff_subset_diff_left hf
· rw [← ENNReal.tsum_add]
exact ENNReal.tsum_le_tsum fun i => hs _
theorem boundedBy_caratheodory {m : Set α → ℝ≥0∞} {s : Set α}
(hs : ∀ t, m (t ∩ s) + m (t \ s) ≤ m t) : MeasurableSet[(boundedBy m).caratheodory] s := by
apply ofFunction_caratheodory; intro t
rcases t.eq_empty_or_nonempty with h | h
· simp [h, Set.not_nonempty_empty]
· convert le_trans _ (hs t)
· simp [h]
exact add_le_add iSup_const_le iSup_const_le
@[simp]
theorem zero_caratheodory : (0 : OuterMeasure α).caratheodory = ⊤ :=
top_unique fun _ _ _ => (add_zero _).symm
theorem top_caratheodory : (⊤ : OuterMeasure α).caratheodory = ⊤ :=
top_unique fun s _ =>
(isCaratheodory_iff_le _).2 fun t =>
t.eq_empty_or_nonempty.elim (fun ht => by simp [ht]) fun ht => by
simp only [ht, top_apply, le_top]
theorem le_add_caratheodory (m₁ m₂ : OuterMeasure α) :
m₁.caratheodory ⊓ m₂.caratheodory ≤ (m₁ + m₂ : OuterMeasure α).caratheodory :=
fun s ⟨hs₁, hs₂⟩ t => by simp [hs₁ t, hs₂ t, add_left_comm, add_assoc]
theorem le_sum_caratheodory {ι} (m : ι → OuterMeasure α) :
⨅ i, (m i).caratheodory ≤ (sum m).caratheodory := fun s h t => by
simp [fun i => MeasurableSpace.measurableSet_iInf.1 h i t, ENNReal.tsum_add]
theorem le_smul_caratheodory (a : ℝ≥0∞) (m : OuterMeasure α) :
m.caratheodory ≤ (a • m).caratheodory := fun s h t => by
simp only [smul_apply, smul_eq_mul]
rw [(isCaratheodory_iff m).mp h t]
simp [mul_add]
@[simp]
theorem dirac_caratheodory (a : α) : (dirac a).caratheodory = ⊤ :=
top_unique fun s _ t => by
by_cases ht : a ∈ t; swap; · simp [ht]
by_cases hs : a ∈ s <;> simp [*]
end OuterMeasure
end MeasureTheory
|
MeasureTheory\OuterMeasure\Defs.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.Instances.ENNReal
/-!
# Definitions of an outer measure and the corresponding `FunLike` class
In this file we define `MeasureTheory.OuterMeasure α`
to be the type of outer measures on `α`.
An outer measure is a function `μ : Set α → ℝ≥0∞`,
from the powerset of a type to the extended nonnegative real numbers
that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is monotone;
3. `μ` is countably subadditive. This means that the outer measure of a countable union
is at most the sum of the outer measure on the individual sets.
Note that we do not need `α` to be measurable to define an outer measure.
We also define a typeclass `MeasureTheory.OuterMeasureClass`.
## References
<https://en.wikipedia.org/wiki/Outer_measure>
## Tags
outer measure
-/
open scoped ENNReal
variable {α : Type*}
namespace MeasureTheory
/-- An outer measure is a countably subadditive monotone function that sends `∅` to `0`. -/
structure OuterMeasure (α : Type*) where
/-- Outer measure function. Use automatic coercion instead. -/
protected measureOf : Set α → ℝ≥0∞
protected empty : measureOf ∅ = 0
protected mono : ∀ {s₁ s₂}, s₁ ⊆ s₂ → measureOf s₁ ≤ measureOf s₂
protected iUnion_nat : ∀ s : ℕ → Set α, Pairwise (Disjoint on s) →
measureOf (⋃ i, s i) ≤ ∑' i, measureOf (s i)
/-- A mixin class saying that elements `μ : F` are outer measures on `α`.
This typeclass is used to unify some API for outer measures and measures. -/
class OuterMeasureClass (F : Type*) (α : outParam Type*) [FunLike F (Set α) ℝ≥0∞] : Prop where
protected measure_empty (f : F) : f ∅ = 0
protected measure_mono (f : F) {s t} : s ⊆ t → f s ≤ f t
protected measure_iUnion_nat_le (f : F) (s : ℕ → Set α) : Pairwise (Disjoint on s) →
f (⋃ i, s i) ≤ ∑' i, f (s i)
namespace OuterMeasure
instance : FunLike (OuterMeasure α) (Set α) ℝ≥0∞ where
coe m := m.measureOf
coe_injective' | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
instance instCoeFun : CoeFun (OuterMeasure α) (fun _ => Set α → ℝ≥0∞) :=
inferInstance
@[simp] theorem measureOf_eq_coe (m : OuterMeasure α) : m.measureOf = m := rfl
instance : OuterMeasureClass (OuterMeasure α) α where
measure_empty f := f.empty
measure_mono f := f.mono
measure_iUnion_nat_le f := f.iUnion_nat
end OuterMeasure
end MeasureTheory
|
MeasureTheory\OuterMeasure\Induced.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Caratheodory
/-!
# Induced Outer Measure
We can extend a function defined on a subset of `Set α` to an outer measure.
The underlying function is called `extend`, and the measure it induces is called
`inducedOuterMeasure`.
Some lemmas below are proven twice, once in the general case, and one where the function `m`
is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can
remove some hypotheses in the statement. The general version has the same name, but with a prime
at the end.
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
open OuterMeasure
section Extend
variable {α : Type*} {P : α → Prop}
variable (m : ∀ s : α, P s → ℝ≥0∞)
/-- We can trivially extend a function defined on a subclass of objects (with codomain `ℝ≥0∞`)
to all objects by defining it to be `∞` on the objects not in the class. -/
def extend (s : α) : ℝ≥0∞ :=
⨅ h : P s, m s h
theorem extend_eq {s : α} (h : P s) : extend m s = m s h := by simp [extend, h]
theorem extend_eq_top {s : α} (h : ¬P s) : extend m s = ∞ := by simp [extend, h]
theorem smul_extend {R} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] {c : R} (hc : c ≠ 0) :
c • extend m = extend fun s h => c • m s h := by
classical
ext1 s
dsimp [extend]
by_cases h : P s
· simp [h]
· simp [h, ENNReal.smul_top, hc]
theorem le_extend {s : α} (h : P s) : m s h ≤ extend m s := by
simp only [extend, le_iInf_iff]
intro
rfl
-- TODO: why this is a bad `congr` lemma?
theorem extend_congr {β : Type*} {Pb : β → Prop} {mb : ∀ s : β, Pb s → ℝ≥0∞} {sa : α} {sb : β}
(hP : P sa ↔ Pb sb) (hm : ∀ (ha : P sa) (hb : Pb sb), m sa ha = mb sb hb) :
extend m sa = extend mb sb :=
iInf_congr_Prop hP fun _h => hm _ _
@[simp]
theorem extend_top {α : Type*} {P : α → Prop} : extend (fun _ _ => ∞ : ∀ s : α, P s → ℝ≥0∞) = ⊤ :=
funext fun _ => iInf_eq_top.mpr fun _ => rfl
end Extend
section ExtendSet
variable {α : Type*} {P : Set α → Prop}
variable {m : ∀ s : Set α, P s → ℝ≥0∞}
variable (P0 : P ∅) (m0 : m ∅ P0 = 0)
variable (PU : ∀ ⦃f : ℕ → Set α⦄ (_hm : ∀ i, P (f i)), P (⋃ i, f i))
variable
(mU :
∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)),
Pairwise (Disjoint on f) → m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i))
variable (msU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)), m (⋃ i, f i) (PU hm) ≤ ∑' i, m (f i) (hm i))
variable (m_mono : ∀ ⦃s₁ s₂ : Set α⦄ (hs₁ : P s₁) (hs₂ : P s₂), s₁ ⊆ s₂ → m s₁ hs₁ ≤ m s₂ hs₂)
theorem extend_empty : extend m ∅ = 0 :=
(extend_eq _ P0).trans m0
theorem extend_iUnion_nat {f : ℕ → Set α} (hm : ∀ i, P (f i))
(mU : m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i)) :
extend m (⋃ i, f i) = ∑' i, extend m (f i) :=
(extend_eq _ _).trans <|
mU.trans <| by
congr with i
rw [extend_eq]
section Subadditive
theorem extend_iUnion_le_tsum_nat' (s : ℕ → Set α) :
extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by
by_cases h : ∀ i, P (s i)
· rw [extend_eq _ (PU h), congr_arg tsum _]
· apply msU h
funext i
apply extend_eq _ (h i)
· cases' not_forall.1 h with i hi
exact le_trans (le_iInf fun h => hi.elim h) (ENNReal.le_tsum i)
end Subadditive
section Mono
theorem extend_mono' ⦃s₁ s₂ : Set α⦄ (h₁ : P s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by
refine le_iInf ?_
intro h₂
rw [extend_eq m h₁]
exact m_mono h₁ h₂ hs
end Mono
section Unions
theorem extend_iUnion {β} [Countable β] {f : β → Set α} (hd : Pairwise (Disjoint on f))
(hm : ∀ i, P (f i)) : extend m (⋃ i, f i) = ∑' i, extend m (f i) := by
cases nonempty_encodable β
rw [← Encodable.iUnion_decode₂, ← tsum_iUnion_decode₂]
· exact
extend_iUnion_nat PU (fun n => Encodable.iUnion_decode₂_cases P0 hm)
(mU _ (Encodable.iUnion_decode₂_disjoint_on hd))
· exact extend_empty P0 m0
theorem extend_union {s₁ s₂ : Set α} (hd : Disjoint s₁ s₂) (h₁ : P s₁) (h₂ : P s₂) :
extend m (s₁ ∪ s₂) = extend m s₁ + extend m s₂ := by
rw [union_eq_iUnion,
extend_iUnion P0 m0 PU mU (pairwise_disjoint_on_bool.2 hd) (Bool.forall_bool.2 ⟨h₂, h₁⟩),
tsum_fintype]
simp
end Unions
variable (m)
/-- Given an arbitrary function on a subset of sets, we can define the outer measure corresponding
to it (this is the unique maximal outer measure that is at most `m` on the domain of `m`). -/
def inducedOuterMeasure : OuterMeasure α :=
OuterMeasure.ofFunction (extend m) (extend_empty P0 m0)
variable {m P0 m0}
theorem le_inducedOuterMeasure {μ : OuterMeasure α} :
μ ≤ inducedOuterMeasure m P0 m0 ↔ ∀ (s) (hs : P s), μ s ≤ m s hs :=
le_ofFunction.trans <| forall_congr' fun _s => le_iInf_iff
/-- If `P u` is `False` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = inducedOuterMeasure m P0 m0`.
E.g., if `α` is an (e)metric space and `P u = diam u < r`, then this lemma implies that
`μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s` and `y ∈ t`. -/
theorem inducedOuterMeasure_union_of_false_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → ¬P u) :
inducedOuterMeasure m P0 m0 (s ∪ t) =
inducedOuterMeasure m P0 m0 s + inducedOuterMeasure m P0 m0 t :=
ofFunction_union_of_top_of_nonempty_inter fun u hsu htu => @iInf_of_empty _ _ _ ⟨h u hsu htu⟩ _
theorem inducedOuterMeasure_eq_extend' {s : Set α} (hs : P s) :
inducedOuterMeasure m P0 m0 s = extend m s :=
ofFunction_eq s (fun _t => extend_mono' m_mono hs) (extend_iUnion_le_tsum_nat' PU msU)
theorem inducedOuterMeasure_eq' {s : Set α} (hs : P s) : inducedOuterMeasure m P0 m0 s = m s hs :=
(inducedOuterMeasure_eq_extend' PU msU m_mono hs).trans <| extend_eq _ _
theorem inducedOuterMeasure_eq_iInf (s : Set α) :
inducedOuterMeasure m P0 m0 s = ⨅ (t : Set α) (ht : P t) (_ : s ⊆ t), m t ht := by
apply le_antisymm
· simp only [le_iInf_iff]
intro t ht hs
refine le_trans (measure_mono hs) ?_
exact le_of_eq (inducedOuterMeasure_eq' _ msU m_mono _)
· refine le_iInf ?_
intro f
refine le_iInf ?_
intro hf
refine le_trans ?_ (extend_iUnion_le_tsum_nat' _ msU _)
refine le_iInf ?_
intro h2f
exact iInf_le_of_le _ (iInf_le_of_le h2f <| iInf_le _ hf)
theorem inducedOuterMeasure_preimage (f : α ≃ α) (Pm : ∀ s : Set α, P (f ⁻¹' s) ↔ P s)
(mm : ∀ (s : Set α) (hs : P s), m (f ⁻¹' s) ((Pm _).mpr hs) = m s hs) {A : Set α} :
inducedOuterMeasure m P0 m0 (f ⁻¹' A) = inducedOuterMeasure m P0 m0 A := by
rw [inducedOuterMeasure_eq_iInf _ msU m_mono, inducedOuterMeasure_eq_iInf _ msU m_mono]; symm
refine f.injective.preimage_surjective.iInf_congr (preimage f) fun s => ?_
refine iInf_congr_Prop (Pm s) ?_; intro hs
refine iInf_congr_Prop f.surjective.preimage_subset_preimage_iff ?_
intro _; exact mm s hs
theorem inducedOuterMeasure_exists_set {s : Set α} (hs : inducedOuterMeasure m P0 m0 s ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ t : Set α,
P t ∧ s ⊆ t ∧ inducedOuterMeasure m P0 m0 t ≤ inducedOuterMeasure m P0 m0 s + ε := by
have h := ENNReal.lt_add_right hs hε
conv at h =>
lhs
rw [inducedOuterMeasure_eq_iInf _ msU m_mono]
simp only [iInf_lt_iff] at h
rcases h with ⟨t, h1t, h2t, h3t⟩
exact
⟨t, h1t, h2t, le_trans (le_of_eq <| inducedOuterMeasure_eq' _ msU m_mono h1t) (le_of_lt h3t)⟩
/-- To test whether `s` is Carathéodory-measurable we only need to check the sets `t` for which
`P t` holds. See `ofFunction_caratheodory` for another way to show the Carathéodory-measurability
of `s`.
-/
theorem inducedOuterMeasure_caratheodory (s : Set α) :
MeasurableSet[(inducedOuterMeasure m P0 m0).caratheodory] s ↔
∀ t : Set α,
P t →
inducedOuterMeasure m P0 m0 (t ∩ s) + inducedOuterMeasure m P0 m0 (t \ s) ≤
inducedOuterMeasure m P0 m0 t := by
rw [isCaratheodory_iff_le]
constructor
· intro h t _ht
exact h t
· intro h u
conv_rhs => rw [inducedOuterMeasure_eq_iInf _ msU m_mono]
refine le_iInf ?_
intro t
refine le_iInf ?_
intro ht
refine le_iInf ?_
intro h2t
refine le_trans ?_ ((h t ht).trans_eq <| inducedOuterMeasure_eq' _ msU m_mono ht)
gcongr
end ExtendSet
/-! If `P` is `MeasurableSet` for some measurable space, then we can remove some hypotheses of the
above lemmas. -/
section MeasurableSpace
variable {α : Type*} [MeasurableSpace α]
variable {m : ∀ s : Set α, MeasurableSet s → ℝ≥0∞}
variable (m0 : m ∅ MeasurableSet.empty = 0)
variable
(mU :
∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, MeasurableSet (f i)),
Pairwise (Disjoint on f) → m (⋃ i, f i) (MeasurableSet.iUnion hm) = ∑' i, m (f i) (hm i))
theorem extend_mono {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (hs : s₁ ⊆ s₂) :
extend m s₁ ≤ extend m s₂ := by
refine le_iInf ?_; intro h₂
have :=
extend_union MeasurableSet.empty m0 MeasurableSet.iUnion mU disjoint_sdiff_self_right h₁
(h₂.diff h₁)
rw [union_diff_cancel hs] at this
rw [← extend_eq m]
exact le_iff_exists_add.2 ⟨_, this⟩
theorem extend_iUnion_le_tsum_nat : ∀ s : ℕ → Set α,
extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by
refine extend_iUnion_le_tsum_nat' MeasurableSet.iUnion ?_; intro f h
simp (config := { singlePass := true }) only [iUnion_disjointed.symm]
rw [mU (MeasurableSet.disjointed h) (disjoint_disjointed _)]
refine ENNReal.tsum_le_tsum fun i => ?_
rw [← extend_eq m, ← extend_eq m]
exact extend_mono m0 mU (MeasurableSet.disjointed h _) (disjointed_le f _)
theorem inducedOuterMeasure_eq_extend {s : Set α} (hs : MeasurableSet s) :
inducedOuterMeasure m MeasurableSet.empty m0 s = extend m s :=
ofFunction_eq s (fun _t => extend_mono m0 mU hs) (extend_iUnion_le_tsum_nat m0 mU)
theorem inducedOuterMeasure_eq {s : Set α} (hs : MeasurableSet s) :
inducedOuterMeasure m MeasurableSet.empty m0 s = m s hs :=
(inducedOuterMeasure_eq_extend m0 mU hs).trans <| extend_eq _ _
end MeasurableSpace
namespace OuterMeasure
variable {α : Type*} [MeasurableSpace α] (m : OuterMeasure α)
/-- Given an outer measure `m` we can forget its value on non-measurable sets, and then consider
`m.trim`, the unique maximal outer measure less than that function. -/
def trim : OuterMeasure α :=
inducedOuterMeasure (fun s _ => m s) MeasurableSet.empty m.empty
theorem le_trim_iff {m₁ m₂ : OuterMeasure α} :
m₁ ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s :=
le_inducedOuterMeasure
theorem le_trim : m ≤ m.trim := le_trim_iff.2 fun _ _ ↦ le_rfl
@[simp] -- Porting note: added `simp`
theorem trim_eq {s : Set α} (hs : MeasurableSet s) : m.trim s = m s :=
inducedOuterMeasure_eq' MeasurableSet.iUnion (fun f _hf => measure_iUnion_le f)
(fun _ _ _ _ h => measure_mono h) hs
theorem trim_congr {m₁ m₂ : OuterMeasure α} (H : ∀ {s : Set α}, MeasurableSet s → m₁ s = m₂ s) :
m₁.trim = m₂.trim := by
simp (config := { contextual := true }) only [trim, H]
@[mono]
theorem trim_mono : Monotone (trim : OuterMeasure α → OuterMeasure α) := fun _m₁ _m₂ H _s =>
iInf₂_mono fun _f _hs => ENNReal.tsum_le_tsum fun _b => iInf_mono fun _hf => H _
/-- `OuterMeasure.trim` is antitone in the σ-algebra. -/
theorem trim_anti_measurableSpace (m : OuterMeasure α) {m0 m1 : MeasurableSpace α}
(h : m0 ≤ m1) : @trim _ m1 m ≤ @trim _ m0 m := by
simp only [le_trim_iff]
intro s hs
rw [trim_eq _ (h s hs)]
theorem trim_le_trim_iff {m₁ m₂ : OuterMeasure α} :
m₁.trim ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s :=
le_trim_iff.trans <| forall₂_congr fun s hs => by rw [trim_eq _ hs]
theorem trim_eq_trim_iff {m₁ m₂ : OuterMeasure α} :
m₁.trim = m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s = m₂ s := by
simp only [le_antisymm_iff, trim_le_trim_iff, forall_and]
theorem trim_eq_iInf (s : Set α) : m.trim s = ⨅ (t) (_ : s ⊆ t) (_ : MeasurableSet t), m t := by
simp (config := { singlePass := true }) only [iInf_comm]
exact
inducedOuterMeasure_eq_iInf MeasurableSet.iUnion (fun f _ => measure_iUnion_le f)
(fun _ _ _ _ h => measure_mono h) s
theorem trim_eq_iInf' (s : Set α) : m.trim s = ⨅ t : { t // s ⊆ t ∧ MeasurableSet t }, m t := by
simp [iInf_subtype, iInf_and, trim_eq_iInf]
theorem trim_trim (m : OuterMeasure α) : m.trim.trim = m.trim :=
trim_eq_trim_iff.2 fun _s => m.trim_eq
@[simp]
theorem trim_top : (⊤ : OuterMeasure α).trim = ⊤ :=
top_unique <| le_trim _
@[simp]
theorem trim_zero : (0 : OuterMeasure α).trim = 0 :=
ext fun s =>
le_antisymm
((measure_mono (subset_univ s)).trans_eq <| trim_eq _ MeasurableSet.univ)
(zero_le _)
theorem trim_sum_ge {ι} (m : ι → OuterMeasure α) : (sum fun i => (m i).trim) ≤ (sum m).trim :=
fun s => by
simp only [sum_apply, trim_eq_iInf, le_iInf_iff]
exact fun t st ht =>
ENNReal.tsum_le_tsum fun i => iInf_le_of_le t <| iInf_le_of_le st <| iInf_le _ ht
theorem exists_measurable_superset_eq_trim (m : OuterMeasure α) (s : Set α) :
∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t = m.trim s := by
simp only [trim_eq_iInf]; set ms := ⨅ (t : Set α) (_ : s ⊆ t) (_ : MeasurableSet t), m t
by_cases hs : ms = ∞
· simp only [hs]
simp only [iInf_eq_top, ms] at hs
exact ⟨univ, subset_univ s, MeasurableSet.univ, hs _ (subset_univ s) MeasurableSet.univ⟩
· have : ∀ r > ms, ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t < r := by
intro r hs
have : ∃t, MeasurableSet t ∧ s ⊆ t ∧ m t < r := by simpa [ms, iInf_lt_iff] using hs
rcases this with ⟨t, hmt, hin, hlt⟩
exists t
have : ∀ n : ℕ, ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t < ms + (n : ℝ≥0∞)⁻¹ := by
intro n
refine this _ (ENNReal.lt_add_right hs ?_)
simp
choose t hsub hm hm' using this
refine ⟨⋂ n, t n, subset_iInter hsub, MeasurableSet.iInter hm, ?_⟩
have : Tendsto (fun n : ℕ => ms + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (ms + 0)) :=
tendsto_const_nhds.add ENNReal.tendsto_inv_nat_nhds_zero
rw [add_zero] at this
refine le_antisymm (ge_of_tendsto' this fun n => ?_) ?_
· exact le_trans (measure_mono <| iInter_subset t n) (hm' n).le
· refine iInf_le_of_le (⋂ n, t n) ?_
refine iInf_le_of_le (subset_iInter hsub) ?_
exact iInf_le _ (MeasurableSet.iInter hm)
theorem exists_measurable_superset_of_trim_eq_zero {m : OuterMeasure α} {s : Set α}
(h : m.trim s = 0) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t = 0 := by
rcases exists_measurable_superset_eq_trim m s with ⟨t, hst, ht, hm⟩
exact ⟨t, hst, ht, h ▸ hm⟩
/-- If `μ i` is a countable family of outer measures, then for every set `s` there exists
a measurable set `t ⊇ s` such that `μ i t = (μ i).trim s` for all `i`. -/
theorem exists_measurable_superset_forall_eq_trim {ι} [Countable ι] (μ : ι → OuterMeasure α)
(s : Set α) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ∀ i, μ i t = (μ i).trim s := by
choose t hst ht hμt using fun i => (μ i).exists_measurable_superset_eq_trim s
replace hst := subset_iInter hst
replace ht := MeasurableSet.iInter ht
refine ⟨⋂ i, t i, hst, ht, fun i => le_antisymm ?_ ?_⟩
exacts [hμt i ▸ (μ i).mono (iInter_subset _ _), (measure_mono hst).trans_eq ((μ i).trim_eq ht)]
/-- If `m₁ s = op (m₂ s) (m₃ s)` for all `s`, then the same is true for `m₁.trim`, `m₂.trim`,
and `m₃ s`. -/
theorem trim_binop {m₁ m₂ m₃ : OuterMeasure α} {op : ℝ≥0∞ → ℝ≥0∞ → ℝ≥0∞}
(h : ∀ s, m₁ s = op (m₂ s) (m₃ s)) (s : Set α) : m₁.trim s = op (m₂.trim s) (m₃.trim s) := by
rcases exists_measurable_superset_forall_eq_trim ![m₁, m₂, m₃] s with ⟨t, _hst, _ht, htm⟩
simp only [Fin.forall_fin_succ, Matrix.cons_val_zero, Matrix.cons_val_succ] at htm
rw [← htm.1, ← htm.2.1, ← htm.2.2.1, h]
/-- If `m₁ s = op (m₂ s)` for all `s`, then the same is true for `m₁.trim` and `m₂.trim`. -/
theorem trim_op {m₁ m₂ : OuterMeasure α} {op : ℝ≥0∞ → ℝ≥0∞} (h : ∀ s, m₁ s = op (m₂ s))
(s : Set α) : m₁.trim s = op (m₂.trim s) :=
@trim_binop α _ m₁ m₂ 0 (fun a _b => op a) h s
/-- `trim` is additive. -/
theorem trim_add (m₁ m₂ : OuterMeasure α) : (m₁ + m₂).trim = m₁.trim + m₂.trim :=
ext <| trim_binop (add_apply m₁ m₂)
/-- `trim` respects scalar multiplication. -/
theorem trim_smul {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R)
(m : OuterMeasure α) : (c • m).trim = c • m.trim :=
ext <| trim_op (smul_apply c m)
/-- `trim` sends the supremum of two outer measures to the supremum of the trimmed measures. -/
theorem trim_sup (m₁ m₂ : OuterMeasure α) : (m₁ ⊔ m₂).trim = m₁.trim ⊔ m₂.trim :=
ext fun s => (trim_binop (sup_apply m₁ m₂) s).trans (sup_apply _ _ _).symm
/-- `trim` sends the supremum of a countable family of outer measures to the supremum
of the trimmed measures. -/
theorem trim_iSup {ι} [Countable ι] (μ : ι → OuterMeasure α) :
trim (⨆ i, μ i) = ⨆ i, trim (μ i) := by
simp_rw [← @iSup_plift_down _ ι]
ext1 s
obtain ⟨t, _, _, hμt⟩ :=
exists_measurable_superset_forall_eq_trim
(Option.elim' (⨆ i, μ (PLift.down i)) (μ ∘ PLift.down)) s
simp only [Option.forall, Option.elim'] at hμt
simp only [iSup_apply, ← hμt.1]
exact iSup_congr hμt.2
/-- The trimmed property of a measure μ states that `μ.toOuterMeasure.trim = μ.toOuterMeasure`.
This theorem shows that a restricted trimmed outer measure is a trimmed outer measure. -/
theorem restrict_trim {μ : OuterMeasure α} {s : Set α} (hs : MeasurableSet s) :
(restrict s μ).trim = restrict s μ.trim := by
refine le_antisymm (fun t => ?_) (le_trim_iff.2 fun t ht => ?_)
· rw [restrict_apply]
rcases μ.exists_measurable_superset_eq_trim (t ∩ s) with ⟨t', htt', ht', hμt'⟩
rw [← hμt']
rw [inter_subset] at htt'
refine (measure_mono htt').trans ?_
rw [trim_eq _ (hs.compl.union ht'), restrict_apply, union_inter_distrib_right, compl_inter_self,
Set.empty_union]
exact measure_mono inter_subset_left
· rw [restrict_apply, trim_eq _ (ht.inter hs), restrict_apply]
end OuterMeasure
end MeasureTheory
|
MeasureTheory\OuterMeasure\OfFunction.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Operations
import Mathlib.Analysis.SpecificLimits.Basic
/-!
# Outer measures from functions
Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer
measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets
`sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function.
Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function.
If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a
special case.
* `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
outer measure, Carathéodory-measurable, Carathéodory's criterion
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section OfFunction
-- Porting note: "set_option eqn_compiler.zeta true" removed
variable {α : Type*} (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0)
/-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/
protected def ofFunction : OuterMeasure α :=
let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i)
{ measureOf := μ
empty :=
le_antisymm
((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty])
(zero_le _)
mono := fun {s₁ s₂} hs => iInf_mono fun f => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩
iUnion_nat := fun s _ =>
ENNReal.le_of_forall_pos_le_add <| by
intro ε hε (hb : (∑' i, μ (s i)) < ∞)
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hl) _)
rw [← ENNReal.tsum_add]
choose f hf using
show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by
intro i
have : μ (s i) < μ (s i) + ε' i :=
ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _)
(by simpa using (hε' i).ne')
rcases iInf_lt_iff.mp this with ⟨t, ht⟩
exists t
contrapose! ht
exact le_iInf ht
refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2)
rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq]
refine iInf_le_of_le _ (iInf_le _ ?_)
apply iUnion_subset
intro i
apply Subset.trans (hf i).1
apply iUnion_subset
simp only [Nat.pairEquiv_symm_apply]
rw [iUnion_unpair]
intro j
apply subset_iUnion₂ i }
theorem ofFunction_apply (s : Set α) :
OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) :=
rfl
variable {m m_empty}
theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s :=
let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅
iInf_le_of_le f <|
iInf_le_of_le (subset_iUnion f 0) <|
le_of_eq <| tsum_eq_single 0 <| by
rintro (_ | i)
· simp
· simp [m_empty]
theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) :
OuterMeasure.ofFunction m m_empty s = m s :=
le_antisymm (ofFunction_le s) <|
le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f)
theorem le_ofFunction {μ : OuterMeasure α} :
μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ =>
le_iInf fun f =>
le_iInf fun hs =>
le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩
theorem isGreatest_ofFunction :
IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) :=
⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩
theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } :=
(@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
OuterMeasure.ofFunction m m_empty (s ∪ t) =
OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by
refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_)
set μ := OuterMeasure.ofFunction m m_empty
rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he)
· calc
μ s + μ t ≤ ∞ := le_top
_ = m (f i) := (h (f i) hs ht).symm
_ ≤ ∑' i, m (f i) := ENNReal.le_tsum i
set I := fun s => { i : ℕ | (s ∩ f i).Nonempty }
have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩
have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu =>
calc
μ u ≤ μ (⋃ i : I u, f i) :=
μ.mono fun x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx))
mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩
_ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _
calc
μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) :=
add_le_add (hI _ subset_union_left) (hI _ subset_union_right)
_ = ∑' i : ↑(I s ∪ I t), μ (f i) :=
(tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable ENNReal.summable).symm
_ ≤ ∑' i, μ (f i) :=
(tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _) (fun _ => le_rfl)
ENNReal.summable ENNReal.summable)
_ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _
theorem comap_ofFunction {β} (f : β → α) (h : Monotone m ∨ Surjective f) :
comap f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f '' s)) (by simp; simp [m_empty]) := by
refine le_antisymm (le_ofFunction.2 fun s => ?_) fun s => ?_
· rw [comap_apply]
apply ofFunction_le
· rw [comap_apply, ofFunction_apply, ofFunction_apply]
refine iInf_mono' fun t => ⟨fun k => f ⁻¹' t k, ?_⟩
refine iInf_mono' fun ht => ?_
rw [Set.image_subset_iff, preimage_iUnion] at ht
refine ⟨ht, ENNReal.tsum_le_tsum fun n => ?_⟩
cases' h with hl hr
exacts [hl (image_preimage_subset _ _), (congr_arg m (hr.image_preimage (t n))).le]
theorem map_ofFunction_le {β} (f : α → β) :
map f (OuterMeasure.ofFunction m m_empty) ≤
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty :=
le_ofFunction.2 fun s => by
rw [map_apply]
apply ofFunction_le
theorem map_ofFunction {β} {f : α → β} (hf : Injective f) :
map f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := by
refine (map_ofFunction_le _).antisymm fun s => ?_
simp only [ofFunction_apply, map_apply, le_iInf_iff]
intro t ht
refine iInf_le_of_le (fun n => (range f)ᶜ ∪ f '' t n) (iInf_le_of_le ?_ ?_)
· rw [← union_iUnion, ← inter_subset, ← image_preimage_eq_inter_range, ← image_iUnion]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => le_of_eq ?_
simp [hf.preimage_image]
-- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)`
theorem restrict_ofFunction (s : Set α) (hm : Monotone m) :
restrict s (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun t => m (t ∩ s)) (by simp; simp [m_empty]) := by
rw [restrict]
simp only [inter_comm _ s, LinearMap.comp_apply]
rw [comap_ofFunction _ (Or.inl hm)]
simp only [map_ofFunction Subtype.coe_injective, Subtype.image_preimage_coe]
theorem smul_ofFunction {c : ℝ≥0∞} (hc : c ≠ ∞) : c • OuterMeasure.ofFunction m m_empty =
OuterMeasure.ofFunction (c • m) (by simp [m_empty]) := by
ext1 s
haveI : Nonempty { t : ℕ → Set α // s ⊆ ⋃ i, t i } := ⟨⟨fun _ => s, subset_iUnion (fun _ => s) 0⟩⟩
simp only [smul_apply, ofFunction_apply, ENNReal.tsum_mul_left, Pi.smul_apply, smul_eq_mul,
iInf_subtype']
rw [ENNReal.iInf_mul_left fun h => (hc h).elim]
end OfFunction
section BoundedBy
variable {α : Type*} (m : Set α → ℝ≥0∞)
/-- Given any function `m` assigning measures to sets, there is a unique maximal outer measure `μ`
satisfying `μ s ≤ m s` for all `s : Set α`. This is the same as `OuterMeasure.ofFunction`,
except that it doesn't require `m ∅ = 0`. -/
def boundedBy : OuterMeasure α :=
OuterMeasure.ofFunction (fun s => ⨆ _ : s.Nonempty, m s) (by simp [Set.not_nonempty_empty])
variable {m}
theorem boundedBy_le (s : Set α) : boundedBy m s ≤ m s :=
(ofFunction_le _).trans iSup_const_le
theorem boundedBy_eq_ofFunction (m_empty : m ∅ = 0) (s : Set α) :
boundedBy m s = OuterMeasure.ofFunction m m_empty s := by
have : (fun s : Set α => ⨆ _ : s.Nonempty, m s) = m := by
ext1 t
rcases t.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty, m_empty]
simp [boundedBy, this]
theorem boundedBy_apply (s : Set α) :
boundedBy m s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t),
∑' n, ⨆ _ : (t n).Nonempty, m (t n) := by
simp [boundedBy, ofFunction_apply]
theorem boundedBy_eq (s : Set α) (m_empty : m ∅ = 0) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) : boundedBy m s = m s := by
rw [boundedBy_eq_ofFunction m_empty, ofFunction_eq s m_mono m_subadd]
@[simp]
theorem boundedBy_eq_self (m : OuterMeasure α) : boundedBy m = m :=
ext fun _ => boundedBy_eq _ measure_empty (fun _ ht => measure_mono ht) measure_iUnion_le
theorem le_boundedBy {μ : OuterMeasure α} : μ ≤ boundedBy m ↔ ∀ s, μ s ≤ m s := by
rw [boundedBy , le_ofFunction, forall_congr']; intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty]
theorem le_boundedBy' {μ : OuterMeasure α} :
μ ≤ boundedBy m ↔ ∀ s : Set α, s.Nonempty → μ s ≤ m s := by
rw [le_boundedBy, forall_congr']
intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h]
@[simp]
theorem boundedBy_top : boundedBy (⊤ : Set α → ℝ≥0∞) = ⊤ := by
rw [eq_top_iff, le_boundedBy']
intro s hs
rw [top_apply hs]
exact le_rfl
@[simp]
theorem boundedBy_zero : boundedBy (0 : Set α → ℝ≥0∞) = 0 := by
rw [← coe_bot, eq_bot_iff]
apply boundedBy_le
theorem smul_boundedBy {c : ℝ≥0∞} (hc : c ≠ ∞) : c • boundedBy m = boundedBy (c • m) := by
simp only [boundedBy , smul_ofFunction hc]
congr 1 with s : 1
rcases s.eq_empty_or_nonempty with (rfl | hs) <;> simp [*]
theorem comap_boundedBy {β} (f : β → α)
(h : (Monotone fun s : { s : Set α // s.Nonempty } => m s) ∨ Surjective f) :
comap f (boundedBy m) = boundedBy fun s => m (f '' s) := by
refine (comap_ofFunction _ ?_).trans ?_
· refine h.imp (fun H s t hst => iSup_le fun hs => ?_) id
have ht : t.Nonempty := hs.mono hst
exact (@H ⟨s, hs⟩ ⟨t, ht⟩ hst).trans (le_iSup (fun _ : t.Nonempty => m t) ht)
· dsimp only [boundedBy]
congr with s : 1
rw [image_nonempty]
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.boundedBy m`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem boundedBy_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
boundedBy m (s ∪ t) = boundedBy m s + boundedBy m t :=
ofFunction_union_of_top_of_nonempty_inter fun u hs ht =>
top_unique <| (h u hs ht).ge.trans <| le_iSup (fun _ => m u) (hs.mono inter_subset_right)
end BoundedBy
section sInfGen
variable {α : Type*}
/-- Given a set of outer measures, we define a new function that on a set `s` is defined to be the
infimum of `μ(s)` for the outer measures `μ` in the collection. We ensure that this
function is defined to be `0` on `∅`, even if the collection of outer measures is empty.
The outer measure generated by this function is the infimum of the given outer measures. -/
def sInfGen (m : Set (OuterMeasure α)) (s : Set α) : ℝ≥0∞ :=
⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ s
theorem sInfGen_def (m : Set (OuterMeasure α)) (t : Set α) :
sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t :=
rfl
theorem sInf_eq_boundedBy_sInfGen (m : Set (OuterMeasure α)) :
sInf m = OuterMeasure.boundedBy (sInfGen m) := by
refine le_antisymm ?_ ?_
· refine le_boundedBy.2 fun s => le_iInf₂ fun μ hμ => ?_
apply sInf_le hμ
· refine le_sInf ?_
intro μ hμ t
exact le_trans (boundedBy_le t) (iInf₂_le μ hμ)
theorem iSup_sInfGen_nonempty {m : Set (OuterMeasure α)} (h : m.Nonempty) (t : Set α) :
⨆ _ : t.Nonempty, sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t := by
rcases t.eq_empty_or_nonempty with (rfl | ht)
· simp [biInf_const h]
· simp [ht, sInfGen_def]
/-- The value of the Infimum of a nonempty set of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply {m : Set (OuterMeasure α)} {s : Set α} (h : m.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) := by
simp_rw [sInf_eq_boundedBy_sInfGen, boundedBy_apply, iSup_sInfGen_nonempty h]
/-- The value of the Infimum of a set of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply' {m : Set (OuterMeasure α)} {s : Set α} (h : s.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) :=
m.eq_empty_or_nonempty.elim (fun hm => by simp [hm, h]) sInf_apply
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply {ι} [Nonempty ι] (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply (range_nonempty m)]
simp only [iInf_range]
/-- The value of the Infimum of a family of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply' {ι} (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply' hs]
simp only [iInf_range]
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply {ι} {I : Set ι} (hI : I.Nonempty) (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
haveI := hI.to_subtype
simp only [← iInf_subtype'', iInf_apply]
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply' {ι} (I : Set ι) (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
simp only [← iInf_subtype'', iInf_apply' _ hs]
theorem map_iInf_le {ι β} (f : α → β) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) ≤ ⨅ i, map f (m i) :=
(map_mono f).map_iInf_le
theorem comap_iInf {ι β} (f : α → β) (m : ι → OuterMeasure β) :
comap f (⨅ i, m i) = ⨅ i, comap f (m i) := by
refine ext_nonempty fun s hs => ?_
refine ((comap_mono f).map_iInf_le s).antisymm ?_
simp only [comap_apply, iInf_apply' _ hs, iInf_apply' _ (hs.image _), le_iInf_iff,
Set.image_subset_iff, preimage_iUnion]
refine fun t ht => iInf_le_of_le _ (iInf_le_of_le ht <| ENNReal.tsum_le_tsum fun k => ?_)
exact iInf_mono fun i => (m i).mono (image_preimage_subset _ _)
theorem map_iInf {ι β} {f : α → β} (hf : Injective f) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) = restrict (range f) (⨅ i, map f (m i)) := by
refine Eq.trans ?_ (map_comap _ _)
simp only [comap_iInf, comap_map hf]
theorem map_iInf_comap {ι β} [Nonempty ι] {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i, comap f (m i)) = ⨅ i, map f (comap f (m i)) := by
refine (map_iInf_le _ _).antisymm fun s => ?_
simp only [map_apply, comap_apply, iInf_apply, le_iInf_iff]
refine fun t ht => iInf_le_of_le (fun n => f '' t n ∪ (range f)ᶜ) (iInf_le_of_le ?_ ?_)
· rw [← iUnion_union, Set.union_comm, ← inter_subset, ← image_iUnion, ←
image_preimage_eq_inter_range]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => iInf_mono fun i => (m i).mono ?_
simp only [preimage_union, preimage_compl, preimage_range, compl_univ, union_empty,
image_subset_iff]
exact subset_refl _
theorem map_biInf_comap {ι β} {I : Set ι} (hI : I.Nonempty) {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i ∈ I, comap f (m i)) = ⨅ i ∈ I, map f (comap f (m i)) := by
haveI := hI.to_subtype
rw [← iInf_subtype'', ← iInf_subtype'']
exact map_iInf_comap _
theorem restrict_iInf_restrict {ι} (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨅ i, restrict s (m i)) = restrict s (⨅ i, m i) :=
calc restrict s (⨅ i, restrict s (m i))
_ = restrict (range ((↑) : s → α)) (⨅ i, restrict s (m i)) := by rw [Subtype.range_coe]
_ = map ((↑) : s → α) (⨅ i, comap (↑) (m i)) := (map_iInf Subtype.coe_injective _).symm
_ = restrict s (⨅ i, m i) := congr_arg (map ((↑) : s → α)) (comap_iInf _ _).symm
theorem restrict_iInf {ι} [Nonempty ι] (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨅ i, m i) = ⨅ i, restrict s (m i) :=
(congr_arg (map ((↑) : s → α)) (comap_iInf _ _)).trans (map_iInf_comap _)
theorem restrict_biInf {ι} {I : Set ι} (hI : I.Nonempty) (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨅ i ∈ I, m i) = ⨅ i ∈ I, restrict s (m i) := by
haveI := hI.to_subtype
rw [← iInf_subtype'', ← iInf_subtype'']
exact restrict_iInf _ _
/-- This proves that Inf and restrict commute for outer measures, so long as the set of
outer measures is nonempty. -/
theorem restrict_sInf_eq_sInf_restrict (m : Set (OuterMeasure α)) {s : Set α} (hm : m.Nonempty) :
restrict s (sInf m) = sInf (restrict s '' m) := by
simp only [sInf_eq_iInf, restrict_biInf, hm, iInf_image]
end sInfGen
end OuterMeasure
end MeasureTheory
|
MeasureTheory\OuterMeasure\Operations.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Basic
/-!
# Operations on outer measures
In this file we define algebraic operations (addition, scalar multiplication)
on the type of outer measures on a type.
We also show that outer measures on a type `α` form a complete lattice.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section Basic
variable {α β : Type*} {m : OuterMeasure α}
instance instZero : Zero (OuterMeasure α) :=
⟨{ measureOf := fun _ => 0
empty := rfl
mono := by intro _ _ _; exact le_refl 0
iUnion_nat := fun s _ => zero_le _ }⟩
@[simp]
theorem coe_zero : ⇑(0 : OuterMeasure α) = 0 :=
rfl
instance instInhabited : Inhabited (OuterMeasure α) :=
⟨0⟩
instance instAdd : Add (OuterMeasure α) :=
⟨fun m₁ m₂ =>
{ measureOf := fun s => m₁ s + m₂ s
empty := show m₁ ∅ + m₂ ∅ = 0 by simp [OuterMeasure.empty]
mono := fun {s₁ s₂} h => add_le_add (m₁.mono h) (m₂.mono h)
iUnion_nat := fun s _ =>
calc
m₁ (⋃ i, s i) + m₂ (⋃ i, s i) ≤ (∑' i, m₁ (s i)) + ∑' i, m₂ (s i) :=
add_le_add (measure_iUnion_le s) (measure_iUnion_le s)
_ = _ := ENNReal.tsum_add.symm }⟩
@[simp]
theorem coe_add (m₁ m₂ : OuterMeasure α) : ⇑(m₁ + m₂) = m₁ + m₂ :=
rfl
theorem add_apply (m₁ m₂ : OuterMeasure α) (s : Set α) : (m₁ + m₂) s = m₁ s + m₂ s :=
rfl
section SMul
variable {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
variable {R' : Type*} [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞]
instance instSMul : SMul R (OuterMeasure α) :=
⟨fun c m =>
{ measureOf := fun s => c • m s
empty := by simp only [measure_empty]; rw [← smul_one_mul c]; simp
mono := fun {s t} h => by
simp only
rw [← smul_one_mul c, ← smul_one_mul c (m t)]
exact ENNReal.mul_left_mono (m.mono h)
iUnion_nat := fun s _ => by
simp_rw [← smul_one_mul c (m _), ENNReal.tsum_mul_left]
exact ENNReal.mul_left_mono (measure_iUnion_le _) }⟩
@[simp]
theorem coe_smul (c : R) (m : OuterMeasure α) : ⇑(c • m) = c • ⇑m :=
rfl
theorem smul_apply (c : R) (m : OuterMeasure α) (s : Set α) : (c • m) s = c • m s :=
rfl
instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] : SMulCommClass R R' (OuterMeasure α) :=
⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩
instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] :
IsScalarTower R R' (OuterMeasure α) :=
⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩
instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] :
IsCentralScalar R (OuterMeasure α) :=
⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩
end SMul
instance instMulAction {R : Type*} [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] :
MulAction R (OuterMeasure α) :=
Injective.mulAction _ coe_fn_injective coe_smul
instance addCommMonoid : AddCommMonoid (OuterMeasure α) :=
Injective.addCommMonoid (show OuterMeasure α → Set α → ℝ≥0∞ from _) coe_fn_injective rfl
(fun _ _ => rfl) fun _ _ => rfl
/-- `(⇑)` as an `AddMonoidHom`. -/
@[simps]
def coeFnAddMonoidHom : OuterMeasure α →+ Set α → ℝ≥0∞ where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
instance instDistribMulAction {R : Type*} [Monoid R] [DistribMulAction R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] :
DistribMulAction R (OuterMeasure α) :=
Injective.distribMulAction coeFnAddMonoidHom coe_fn_injective coe_smul
instance instModule {R : Type*} [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] :
Module R (OuterMeasure α) :=
Injective.module R coeFnAddMonoidHom coe_fn_injective coe_smul
instance instBot : Bot (OuterMeasure α) :=
⟨0⟩
@[simp]
theorem coe_bot : (⊥ : OuterMeasure α) = 0 :=
rfl
instance instPartialOrder : PartialOrder (OuterMeasure α) where
le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s
le_refl a s := le_rfl
le_trans a b c hab hbc s := le_trans (hab s) (hbc s)
le_antisymm a b hab hba := ext fun s => le_antisymm (hab s) (hba s)
instance orderBot : OrderBot (OuterMeasure α) :=
{ bot := 0,
bot_le := fun a s => by simp only [coe_zero, Pi.zero_apply, coe_bot, zero_le] }
theorem univ_eq_zero_iff (m : OuterMeasure α) : m univ = 0 ↔ m = 0 :=
⟨fun h => bot_unique fun s => (measure_mono <| subset_univ s).trans_eq h, fun h => h.symm ▸ rfl⟩
section Supremum
instance instSupSet : SupSet (OuterMeasure α) :=
⟨fun ms =>
{ measureOf := fun s => ⨆ m ∈ ms, (m : OuterMeasure α) s
empty := nonpos_iff_eq_zero.1 <| iSup₂_le fun m _ => le_of_eq m.empty
mono := fun {s₁ s₂} hs => iSup₂_mono fun m _ => m.mono hs
iUnion_nat := fun f _ =>
iSup₂_le fun m hm =>
calc
m (⋃ i, f i) ≤ ∑' i : ℕ, m (f i) := measure_iUnion_le _
_ ≤ ∑' i, ⨆ m ∈ ms, (m : OuterMeasure α) (f i) :=
ENNReal.tsum_le_tsum fun i => by apply le_iSup₂ m hm
}⟩
instance instCompleteLattice : CompleteLattice (OuterMeasure α) :=
{ OuterMeasure.orderBot,
completeLatticeOfSup (OuterMeasure α) fun ms =>
⟨fun m hm s => by apply le_iSup₂ m hm, fun m hm s => iSup₂_le fun m' hm' => hm hm' s⟩ with }
@[simp]
theorem sSup_apply (ms : Set (OuterMeasure α)) (s : Set α) :
(sSup ms) s = ⨆ m ∈ ms, (m : OuterMeasure α) s :=
rfl
@[simp]
theorem iSup_apply {ι} (f : ι → OuterMeasure α) (s : Set α) : (⨆ i : ι, f i) s = ⨆ i, f i s := by
rw [iSup, sSup_apply, iSup_range]
@[norm_cast]
theorem coe_iSup {ι} (f : ι → OuterMeasure α) : ⇑(⨆ i, f i) = ⨆ i, ⇑(f i) :=
funext fun s => by simp
@[simp]
theorem sup_apply (m₁ m₂ : OuterMeasure α) (s : Set α) : (m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s := by
have := iSup_apply (fun b => cond b m₁ m₂) s; rwa [iSup_bool_eq, iSup_bool_eq] at this
theorem smul_iSup {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{ι : Sort*} (f : ι → OuterMeasure α) (c : R) :
(c • ⨆ i, f i) = ⨆ i, c • f i :=
ext fun s => by simp only [smul_apply, iSup_apply, ENNReal.smul_iSup]
end Supremum
@[mono, gcongr]
theorem mono'' {m₁ m₂ : OuterMeasure α} {s₁ s₂ : Set α} (hm : m₁ ≤ m₂) (hs : s₁ ⊆ s₂) :
m₁ s₁ ≤ m₂ s₂ :=
(hm s₁).trans (m₂.mono hs)
/-- The pushforward of `m` along `f`. The outer measure on `s` is defined to be `m (f ⁻¹' s)`. -/
def map {β} (f : α → β) : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β where
toFun m :=
{ measureOf := fun s => m (f ⁻¹' s)
empty := m.empty
mono := fun {s t} h => m.mono (preimage_mono h)
iUnion_nat := fun s _ => by simpa using measure_iUnion_le fun i => f ⁻¹' s i }
map_add' m₁ m₂ := coe_fn_injective rfl
map_smul' c m := coe_fn_injective rfl
@[simp]
theorem map_apply {β} (f : α → β) (m : OuterMeasure α) (s : Set β) : map f m s = m (f ⁻¹' s) :=
rfl
@[simp]
theorem map_id (m : OuterMeasure α) : map id m = m :=
ext fun _ => rfl
@[simp]
theorem map_map {β γ} (f : α → β) (g : β → γ) (m : OuterMeasure α) :
map g (map f m) = map (g ∘ f) m :=
ext fun _ => rfl
@[mono]
theorem map_mono {β} (f : α → β) : Monotone (map f) := fun _ _ h _ => h _
@[simp]
theorem map_sup {β} (f : α → β) (m m' : OuterMeasure α) : map f (m ⊔ m') = map f m ⊔ map f m' :=
ext fun s => by simp only [map_apply, sup_apply]
@[simp]
theorem map_iSup {β ι} (f : α → β) (m : ι → OuterMeasure α) : map f (⨆ i, m i) = ⨆ i, map f (m i) :=
ext fun s => by simp only [map_apply, iSup_apply]
instance instFunctor : Functor OuterMeasure where map {_ _} f := map f
instance instLawfulFunctor : LawfulFunctor OuterMeasure := by constructor <;> intros <;> rfl
/-- The dirac outer measure. -/
def dirac (a : α) : OuterMeasure α where
measureOf s := indicator s (fun _ => 1) a
empty := by simp
mono {s t} h := indicator_le_indicator_of_subset h (fun _ => zero_le _) a
iUnion_nat s _ := calc
indicator (⋃ n, s n) 1 a = ⨆ n, indicator (s n) 1 a :=
indicator_iUnion_apply (M := ℝ≥0∞) rfl _ _ _
_ ≤ ∑' n, indicator (s n) 1 a := iSup_le fun _ ↦ ENNReal.le_tsum _
@[simp]
theorem dirac_apply (a : α) (s : Set α) : dirac a s = indicator s (fun _ => 1) a :=
rfl
/-- The sum of an (arbitrary) collection of outer measures. -/
def sum {ι} (f : ι → OuterMeasure α) : OuterMeasure α where
measureOf s := ∑' i, f i s
empty := by simp
mono {s t} h := ENNReal.tsum_le_tsum fun i => measure_mono h
iUnion_nat s _ := by
rw [ENNReal.tsum_comm]; exact ENNReal.tsum_le_tsum fun i => measure_iUnion_le _
@[simp]
theorem sum_apply {ι} (f : ι → OuterMeasure α) (s : Set α) : sum f s = ∑' i, f i s :=
rfl
theorem smul_dirac_apply (a : ℝ≥0∞) (b : α) (s : Set α) :
(a • dirac b) s = indicator s (fun _ => a) b := by
simp only [smul_apply, smul_eq_mul, dirac_apply, ← indicator_mul_right _ fun _ => a, mul_one]
/-- Pullback of an `OuterMeasure`: `comap f μ s = μ (f '' s)`. -/
def comap {β} (f : α → β) : OuterMeasure β →ₗ[ℝ≥0∞] OuterMeasure α where
toFun m :=
{ measureOf := fun s => m (f '' s)
empty := by simp
mono := fun {s t} h => m.mono <| image_subset f h
iUnion_nat := fun s _ => by simpa only [image_iUnion] using measure_iUnion_le _ }
map_add' m₁ m₂ := rfl
map_smul' c m := rfl
@[simp]
theorem comap_apply {β} (f : α → β) (m : OuterMeasure β) (s : Set α) : comap f m s = m (f '' s) :=
rfl
@[mono]
theorem comap_mono {β} (f : α → β) : Monotone (comap f) := fun _ _ h _ => h _
@[simp]
theorem comap_iSup {β ι} (f : α → β) (m : ι → OuterMeasure β) :
comap f (⨆ i, m i) = ⨆ i, comap f (m i) :=
ext fun s => by simp only [comap_apply, iSup_apply]
/-- Restrict an `OuterMeasure` to a set. -/
def restrict (s : Set α) : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure α :=
(map (↑)).comp (comap ((↑) : s → α))
-- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)`
@[simp]
theorem restrict_apply (s t : Set α) (m : OuterMeasure α) : restrict s m t = m (t ∩ s) := by
simp [restrict, inter_comm t]
@[mono]
theorem restrict_mono {s t : Set α} (h : s ⊆ t) {m m' : OuterMeasure α} (hm : m ≤ m') :
restrict s m ≤ restrict t m' := fun u => by
simp only [restrict_apply]
exact (hm _).trans (m'.mono <| inter_subset_inter_right _ h)
@[simp]
theorem restrict_univ (m : OuterMeasure α) : restrict univ m = m :=
ext fun s => by simp
@[simp]
theorem restrict_empty (m : OuterMeasure α) : restrict ∅ m = 0 :=
ext fun s => by simp
@[simp]
theorem restrict_iSup {ι} (s : Set α) (m : ι → OuterMeasure α) :
restrict s (⨆ i, m i) = ⨆ i, restrict s (m i) := by simp [restrict]
theorem map_comap {β} (f : α → β) (m : OuterMeasure β) : map f (comap f m) = restrict (range f) m :=
ext fun s => congr_arg m <| by simp only [image_preimage_eq_inter_range, Subtype.range_coe]
theorem map_comap_le {β} (f : α → β) (m : OuterMeasure β) : map f (comap f m) ≤ m := fun _ =>
m.mono <| image_preimage_subset _ _
theorem restrict_le_self (m : OuterMeasure α) (s : Set α) : restrict s m ≤ m :=
map_comap_le _ _
@[simp]
theorem map_le_restrict_range {β} {ma : OuterMeasure α} {mb : OuterMeasure β} {f : α → β} :
map f ma ≤ restrict (range f) mb ↔ map f ma ≤ mb :=
⟨fun h => h.trans (restrict_le_self _ _), fun h s => by simpa using h (s ∩ range f)⟩
theorem map_comap_of_surjective {β} {f : α → β} (hf : Surjective f) (m : OuterMeasure β) :
map f (comap f m) = m :=
ext fun s => by rw [map_apply, comap_apply, hf.image_preimage]
theorem le_comap_map {β} (f : α → β) (m : OuterMeasure α) : m ≤ comap f (map f m) := fun _ =>
m.mono <| subset_preimage_image _ _
theorem comap_map {β} {f : α → β} (hf : Injective f) (m : OuterMeasure α) : comap f (map f m) = m :=
ext fun s => by rw [comap_apply, map_apply, hf.preimage_image]
@[simp]
theorem top_apply {s : Set α} (h : s.Nonempty) : (⊤ : OuterMeasure α) s = ∞ :=
let ⟨a, as⟩ := h
top_unique <| le_trans (by simp [smul_dirac_apply, as]) (le_iSup₂ (∞ • dirac a) trivial)
theorem top_apply' (s : Set α) : (⊤ : OuterMeasure α) s = ⨅ h : s = ∅, 0 :=
s.eq_empty_or_nonempty.elim (fun h => by simp [h]) fun h => by simp [h, h.ne_empty]
@[simp]
theorem comap_top (f : α → β) : comap f ⊤ = ⊤ :=
ext_nonempty fun s hs => by rw [comap_apply, top_apply hs, top_apply (hs.image _)]
theorem map_top (f : α → β) : map f ⊤ = restrict (range f) ⊤ :=
ext fun s => by
rw [map_apply, restrict_apply, ← image_preimage_eq_inter_range, top_apply', top_apply',
Set.image_eq_empty]
@[simp]
theorem map_top_of_surjective (f : α → β) (hf : Surjective f) : map f ⊤ = ⊤ := by
rw [map_top, hf.range_eq, restrict_univ]
end Basic
end OuterMeasure
end MeasureTheory
|
ModelTheory\Basic.lean | /-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Fin.VecNotation
import Mathlib.SetTheory.Cardinal.Basic
/-!
# Basics on First-Order Structures
This file defines first-order languages and structures in the style of the
[Flypitch project](https://flypitch.github.io/), as well as several important maps between
structures.
## Main Definitions
- A `FirstOrder.Language` defines a language as a pair of functions from the natural numbers to
`Type l`. One sends `n` to the type of `n`-ary functions, and the other sends `n` to the type of
`n`-ary relations.
- A `FirstOrder.Language.Structure` interprets the symbols of a given `FirstOrder.Language` in the
context of a given type.
- A `FirstOrder.Language.Hom`, denoted `M →[L] N`, is a map from the `L`-structure `M` to the
`L`-structure `N` that commutes with the interpretations of functions, and which preserves the
interpretations of relations (although only in the forward direction).
- A `FirstOrder.Language.Embedding`, denoted `M ↪[L] N`, is an embedding from the `L`-structure `M`
to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves
the interpretations of relations in both directions.
- A `FirstOrder.Language.Equiv`, denoted `M ≃[L] N`, is an equivalence from the `L`-structure `M`
to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves
the interpretations of relations in both directions.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v u' v' w w'
open Cardinal
namespace FirstOrder
/-! ### Languages and Structures -/
-- intended to be used with explicit universe parameters
/-- A first-order language consists of a type of functions of every natural-number arity and a
type of relations of every natural-number arity. -/
@[nolint checkUnivs]
structure Language where
/-- For every arity, a `Type*` of functions of that arity -/
Functions : ℕ → Type u
/-- For every arity, a `Type*` of relations of that arity -/
Relations : ℕ → Type v
/-- Used to define `FirstOrder.Language₂`. -/
--@[simp]
def Sequence₂ (a₀ a₁ a₂ : Type u) : ℕ → Type u
| 0 => a₀
| 1 => a₁
| 2 => a₂
| _ => PEmpty
namespace Sequence₂
variable (a₀ a₁ a₂ : Type u)
instance inhabited₀ [h : Inhabited a₀] : Inhabited (Sequence₂ a₀ a₁ a₂ 0) :=
h
instance inhabited₁ [h : Inhabited a₁] : Inhabited (Sequence₂ a₀ a₁ a₂ 1) :=
h
instance inhabited₂ [h : Inhabited a₂] : Inhabited (Sequence₂ a₀ a₁ a₂ 2) :=
h
instance {n : ℕ} : IsEmpty (Sequence₂ a₀ a₁ a₂ (n + 3)) := inferInstanceAs (IsEmpty PEmpty)
@[simp]
theorem lift_mk {i : ℕ} :
Cardinal.lift.{v,u} #(Sequence₂ a₀ a₁ a₂ i)
= #(Sequence₂ (ULift.{v,u} a₀) (ULift.{v,u} a₁) (ULift.{v,u} a₂) i) := by
rcases i with (_ | _ | _ | i) <;>
simp only [Sequence₂, mk_uLift, Nat.succ_ne_zero, IsEmpty.forall_iff, Nat.succ.injEq,
add_eq_zero, OfNat.ofNat_ne_zero, and_false, one_ne_zero, mk_eq_zero, lift_zero]
@[simp]
theorem sum_card : Cardinal.sum (fun i => #(Sequence₂ a₀ a₁ a₂ i)) = #a₀ + #a₁ + #a₂ := by
rw [sum_nat_eq_add_sum_succ, sum_nat_eq_add_sum_succ, sum_nat_eq_add_sum_succ]
simp [add_assoc, Sequence₂]
end Sequence₂
namespace Language
/-- A constructor for languages with only constants, unary and binary functions, and
unary and binary relations. -/
@[simps]
protected def mk₂ (c f₁ f₂ : Type u) (r₁ r₂ : Type v) : Language :=
⟨Sequence₂ c f₁ f₂, Sequence₂ PEmpty r₁ r₂⟩
/-- The empty language has no symbols. -/
protected def empty : Language :=
⟨fun _ => Empty, fun _ => Empty⟩
instance : Inhabited Language :=
⟨Language.empty⟩
/-- The sum of two languages consists of the disjoint union of their symbols. -/
protected def sum (L : Language.{u, v}) (L' : Language.{u', v'}) : Language :=
⟨fun n => L.Functions n ⊕ L'.Functions n, fun n => L.Relations n ⊕ L'.Relations n⟩
variable (L : Language.{u, v})
/-- The type of constants in a given language. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
protected def Constants :=
L.Functions 0
@[simp]
theorem constants_mk₂ (c f₁ f₂ : Type u) (r₁ r₂ : Type v) :
(Language.mk₂ c f₁ f₂ r₁ r₂).Constants = c :=
rfl
/-- The type of symbols in a given language. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
def Symbols :=
(Σ l, L.Functions l) ⊕ (Σ l, L.Relations l)
/-- The cardinality of a language is the cardinality of its type of symbols. -/
def card : Cardinal :=
#L.Symbols
/-- A language is relational when it has no function symbols. -/
class IsRelational : Prop where
/-- There are no function symbols in the language. -/
empty_functions : ∀ n, IsEmpty (L.Functions n)
/-- A language is algebraic when it has no relation symbols. -/
class IsAlgebraic : Prop where
/-- There are no relation symbols in the language. -/
empty_relations : ∀ n, IsEmpty (L.Relations n)
variable {L} {L' : Language.{u', v'}}
theorem card_eq_card_functions_add_card_relations :
L.card =
(Cardinal.sum fun l => Cardinal.lift.{v} #(L.Functions l)) +
Cardinal.sum fun l => Cardinal.lift.{u} #(L.Relations l) := by
simp [card, Symbols]
instance [L.IsRelational] {n : ℕ} : IsEmpty (L.Functions n) :=
IsRelational.empty_functions n
instance [L.IsAlgebraic] {n : ℕ} : IsEmpty (L.Relations n) :=
IsAlgebraic.empty_relations n
instance isRelational_of_empty_functions {symb : ℕ → Type*} :
IsRelational ⟨fun _ => Empty, symb⟩ :=
⟨fun _ => instIsEmptyEmpty⟩
instance isAlgebraic_of_empty_relations {symb : ℕ → Type*} : IsAlgebraic ⟨symb, fun _ => Empty⟩ :=
⟨fun _ => instIsEmptyEmpty⟩
instance isRelational_empty : IsRelational Language.empty :=
Language.isRelational_of_empty_functions
instance isAlgebraic_empty : IsAlgebraic Language.empty :=
Language.isAlgebraic_of_empty_relations
instance isRelational_sum [L.IsRelational] [L'.IsRelational] : IsRelational (L.sum L') :=
⟨fun _ => instIsEmptySum⟩
instance isAlgebraic_sum [L.IsAlgebraic] [L'.IsAlgebraic] : IsAlgebraic (L.sum L') :=
⟨fun _ => instIsEmptySum⟩
instance isRelational_mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h0 : IsEmpty c] [h1 : IsEmpty f₁]
[h2 : IsEmpty f₂] : IsRelational (Language.mk₂ c f₁ f₂ r₁ r₂) :=
⟨fun n =>
Nat.casesOn n h0 fun n => Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ =>
inferInstanceAs (IsEmpty PEmpty)⟩
instance isAlgebraic_mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h1 : IsEmpty r₁] [h2 : IsEmpty r₂] :
IsAlgebraic (Language.mk₂ c f₁ f₂ r₁ r₂) :=
⟨fun n =>
Nat.casesOn n (inferInstanceAs (IsEmpty PEmpty)) fun n =>
Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => inferInstanceAs (IsEmpty PEmpty)⟩
instance subsingleton_mk₂_functions {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h0 : Subsingleton c]
[h1 : Subsingleton f₁] [h2 : Subsingleton f₂] {n : ℕ} :
Subsingleton ((Language.mk₂ c f₁ f₂ r₁ r₂).Functions n) :=
Nat.casesOn n h0 fun n =>
Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => ⟨fun x => PEmpty.elim x⟩
instance subsingleton_mk₂_relations {c f₁ f₂ : Type u} {r₁ r₂ : Type v} [h1 : Subsingleton r₁]
[h2 : Subsingleton r₂] {n : ℕ} : Subsingleton ((Language.mk₂ c f₁ f₂ r₁ r₂).Relations n) :=
Nat.casesOn n ⟨fun x => PEmpty.elim x⟩ fun n =>
Nat.casesOn n h1 fun n => Nat.casesOn n h2 fun _ => ⟨fun x => PEmpty.elim x⟩
@[simp]
theorem empty_card : Language.empty.card = 0 := by simp [card_eq_card_functions_add_card_relations]
instance isEmpty_empty : IsEmpty Language.empty.Symbols := by
simp only [Language.Symbols, isEmpty_sum, isEmpty_sigma]
exact ⟨fun _ => inferInstance, fun _ => inferInstance⟩
instance Countable.countable_functions [h : Countable L.Symbols] : Countable (Σl, L.Functions l) :=
@Function.Injective.countable _ _ h _ Sum.inl_injective
@[simp]
theorem card_functions_sum (i : ℕ) :
#((L.sum L').Functions i)
= (Cardinal.lift.{u'} #(L.Functions i) + Cardinal.lift.{u} #(L'.Functions i) : Cardinal) := by
simp [Language.sum]
@[simp]
theorem card_relations_sum (i : ℕ) :
#((L.sum L').Relations i) =
Cardinal.lift.{v'} #(L.Relations i) + Cardinal.lift.{v} #(L'.Relations i) := by
simp [Language.sum]
@[simp]
theorem card_sum :
(L.sum L').card = Cardinal.lift.{max u' v'} L.card + Cardinal.lift.{max u v} L'.card := by
simp only [card_eq_card_functions_add_card_relations, card_functions_sum, card_relations_sum,
sum_add_distrib', lift_add, lift_sum, lift_lift]
simp only [add_assoc, add_comm (Cardinal.sum fun i => (#(L'.Functions i)).lift)]
@[simp]
theorem card_mk₂ (c f₁ f₂ : Type u) (r₁ r₂ : Type v) :
(Language.mk₂ c f₁ f₂ r₁ r₂).card =
Cardinal.lift.{v} #c + Cardinal.lift.{v} #f₁ + Cardinal.lift.{v} #f₂ +
Cardinal.lift.{u} #r₁ + Cardinal.lift.{u} #r₂ := by
simp [card_eq_card_functions_add_card_relations, add_assoc]
variable (L) (M : Type w)
/-- A first-order structure on a type `M` consists of interpretations of all the symbols in a given
language. Each function of arity `n` is interpreted as a function sending tuples of length `n`
(modeled as `(Fin n → M)`) to `M`, and a relation of arity `n` is a function from tuples of length
`n` to `Prop`. -/
@[ext]
class Structure where
/-- Interpretation of the function symbols -/
funMap : ∀ {n}, L.Functions n → (Fin n → M) → M
/-- Interpretation of the relation symbols -/
RelMap : ∀ {n}, L.Relations n → (Fin n → M) → Prop
variable (N : Type w') [L.Structure M] [L.Structure N]
open Structure
/-- Used for defining `FirstOrder.Language.Theory.ModelType.instInhabited`. -/
def Inhabited.trivialStructure {α : Type*} [Inhabited α] : L.Structure α :=
⟨default, default⟩
/-! ### Maps -/
/-- A homomorphism between first-order structures is a function that commutes with the
interpretations of functions and maps tuples in one structure where a given relation is true to
tuples in the second structure where that relation is still true. -/
structure Hom where
/-- The underlying function of a homomorphism of structures -/
toFun : M → N
/-- The homomorphism commutes with the interpretations of the function symbols -/
-- Porting note:
-- The autoparam here used to be `obviously`. We would like to replace it with `aesop`
-- but that isn't currently sufficient.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases
-- If that can be improved, we should change this to `by aesop` and remove the proofs below.
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
intros; trivial
/-- The homomorphism sends related elements to related elements -/
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r x → RelMap r (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " →[" L "] " B => FirstOrder.Language.Hom L A B
/-- An embedding of first-order structures is an embedding that commutes with the
interpretations of functions and relations. -/
structure Embedding extends M ↪ N where
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " ↪[" L "] " B => FirstOrder.Language.Embedding L A B
/-- An equivalence of first-order structures is an equivalence that commutes with the
interpretations of functions and relations. -/
structure Equiv extends M ≃ N where
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " ≃[" L "] " B => FirstOrder.Language.Equiv L A B
-- Porting note: was [L.Structure P] and [L.Structure Q]
-- The former reported an error.
variable {L M N} {P : Type*} [Structure L P] {Q : Type*} [Structure L Q]
-- Porting note (#11445): new definition
/-- Interpretation of a constant symbol -/
@[coe]
def constantMap (c : L.Constants) : M := funMap c default
instance : CoeTC L.Constants M :=
⟨constantMap⟩
theorem funMap_eq_coe_constants {c : L.Constants} {x : Fin 0 → M} : funMap c x = c :=
congr rfl (funext finZeroElim)
/-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot
be a global instance, because `L` becomes a metavariable. -/
theorem nonempty_of_nonempty_constants [h : Nonempty L.Constants] : Nonempty M :=
h.map (↑)
/-- The function map for `FirstOrder.Language.Structure₂`. -/
def funMap₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (c' : c → M) (f₁' : f₁ → M → M)
(f₂' : f₂ → M → M → M) : ∀ {n}, (Language.mk₂ c f₁ f₂ r₁ r₂).Functions n → (Fin n → M) → M
| 0, f, _ => c' f
| 1, f, x => f₁' f (x 0)
| 2, f, x => f₂' f (x 0) (x 1)
| _ + 3, f, _ => PEmpty.elim f
/-- The relation map for `FirstOrder.Language.Structure₂`. -/
def RelMap₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (r₁' : r₁ → Set M) (r₂' : r₂ → M → M → Prop) :
∀ {n}, (Language.mk₂ c f₁ f₂ r₁ r₂).Relations n → (Fin n → M) → Prop
| 0, r, _ => PEmpty.elim r
| 1, r, x => x 0 ∈ r₁' r
| 2, r, x => r₂' r (x 0) (x 1)
| _ + 3, r, _ => PEmpty.elim r
/-- A structure constructor to match `FirstOrder.Language₂`. -/
protected def Structure.mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (c' : c → M) (f₁' : f₁ → M → M)
(f₂' : f₂ → M → M → M) (r₁' : r₁ → Set M) (r₂' : r₂ → M → M → Prop) :
(Language.mk₂ c f₁ f₂ r₁ r₂).Structure M :=
⟨funMap₂ c' f₁' f₂', RelMap₂ r₁' r₂'⟩
namespace Structure
variable {c f₁ f₂ : Type u} {r₁ r₂ : Type v}
variable {c' : c → M} {f₁' : f₁ → M → M} {f₂' : f₂ → M → M → M}
variable {r₁' : r₁ → Set M} {r₂' : r₂ → M → M → Prop}
@[simp]
theorem funMap_apply₀ (c₀ : c) {x : Fin 0 → M} :
@Structure.funMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 0 c₀ x = c' c₀ :=
rfl
@[simp]
theorem funMap_apply₁ (f : f₁) (x : M) :
@Structure.funMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 1 f ![x] = f₁' f x :=
rfl
@[simp]
theorem funMap_apply₂ (f : f₂) (x y : M) :
@Structure.funMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 2 f ![x, y] = f₂' f x y :=
rfl
@[simp]
theorem relMap_apply₁ (r : r₁) (x : M) :
@Structure.RelMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 1 r ![x] = (x ∈ r₁' r) :=
rfl
@[simp]
theorem relMap_apply₂ (r : r₂) (x y : M) :
@Structure.RelMap _ M (Structure.mk₂ c' f₁' f₂' r₁' r₂') 2 r ![x, y] = r₂' r x y :=
rfl
end Structure
/-- `HomClass L F M N` states that `F` is a type of `L`-homomorphisms. You should extend this
typeclass when you extend `FirstOrder.Language.Hom`. -/
class HomClass (L : outParam Language) (F M N : Type*)
[FunLike F M N] [L.Structure M] [L.Structure N] : Prop where
map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x)
map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r x → RelMap r (φ ∘ x)
/-- `StrongHomClass L F M N` states that `F` is a type of `L`-homomorphisms which preserve
relations in both directions. -/
class StrongHomClass (L : outParam Language) (F M N : Type*)
[FunLike F M N] [L.Structure M] [L.Structure N] : Prop where
map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x)
map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r (φ ∘ x) ↔ RelMap r x
-- Porting note: using implicit brackets for `Structure` arguments
instance (priority := 100) StrongHomClass.homClass {F : Type*} [L.Structure M]
[L.Structure N] [FunLike F M N] [StrongHomClass L F M N] : HomClass L F M N where
map_fun := StrongHomClass.map_fun
map_rel φ _ R x := (StrongHomClass.map_rel φ R x).2
/-- Not an instance to avoid a loop. -/
theorem HomClass.strongHomClassOfIsAlgebraic [L.IsAlgebraic] {F M N} [L.Structure M] [L.Structure N]
[FunLike F M N] [HomClass L F M N] : StrongHomClass L F M N where
map_fun := HomClass.map_fun
map_rel _ n R _ := (IsAlgebraic.empty_relations n).elim R
theorem HomClass.map_constants {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[HomClass L F M N] (φ : F) (c : L.Constants) : φ c = c :=
(HomClass.map_fun φ c default).trans (congr rfl (funext default))
attribute [inherit_doc FirstOrder.Language.Hom.map_fun'] FirstOrder.Language.Embedding.map_fun'
FirstOrder.Language.HomClass.map_fun FirstOrder.Language.StrongHomClass.map_fun
FirstOrder.Language.Equiv.map_fun'
attribute [inherit_doc FirstOrder.Language.Hom.map_rel'] FirstOrder.Language.Embedding.map_rel'
FirstOrder.Language.HomClass.map_rel FirstOrder.Language.StrongHomClass.map_rel
FirstOrder.Language.Equiv.map_rel'
namespace Hom
instance instFunLike : FunLike (M →[L] N) M N where
coe := Hom.toFun
coe_injective' f g h := by cases f; cases g; cases h; rfl
instance homClass : HomClass L (M →[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
instance [L.IsAlgebraic] : StrongHomClass L (M →[L] N) M N :=
HomClass.strongHomClassOfIsAlgebraic
instance hasCoeToFun : CoeFun (M →[L] N) fun _ => M → N :=
DFunLike.hasCoeToFun
@[simp]
theorem toFun_eq_coe {f : M →[L] N} : f.toFun = (f : M → N) :=
rfl
@[ext]
theorem ext ⦃f g : M →[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp]
theorem map_fun (φ : M →[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M →[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M →[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r x → RelMap r (φ ∘ x) :=
HomClass.map_rel φ r x
variable (L) (M)
/-- The identity map from a structure to itself. -/
@[refl]
def id : M →[L] M where
toFun m := m
variable {L} {M}
instance : Inhabited (M →[L] M) :=
⟨id L M⟩
@[simp]
theorem id_apply (x : M) : id L M x = x :=
rfl
/-- Composition of first-order homomorphisms. -/
@[trans]
def comp (hnp : N →[L] P) (hmn : M →[L] N) : M →[L] P where
toFun := hnp ∘ hmn
-- Porting note: should be done by autoparam?
map_fun' _ _ := by simp; rfl
-- Porting note: should be done by autoparam?
map_rel' _ _ h := map_rel _ _ _ (map_rel _ _ _ h)
@[simp]
theorem comp_apply (g : N →[L] P) (f : M →[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of first-order homomorphisms is associative. -/
theorem comp_assoc (f : M →[L] N) (g : N →[L] P) (h : P →[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
@[simp]
theorem comp_id (f : M →[L] N) : f.comp (id L M) = f :=
rfl
@[simp]
theorem id_comp (f : M →[L] N) : (id L N).comp f = f :=
rfl
end Hom
/-- Any element of a `HomClass` can be realized as a first_order homomorphism. -/
def HomClass.toHom {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[HomClass L F M N] : F → M →[L] N := fun φ =>
⟨φ, HomClass.map_fun φ, HomClass.map_rel φ⟩
namespace Embedding
instance funLike : FunLike (M ↪[L] N) M N where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
ext x
exact Function.funext_iff.1 h x
instance embeddingLike : EmbeddingLike (M ↪[L] N) M N where
injective' f := f.toEmbedding.injective
instance strongHomClass : StrongHomClass L (M ↪[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
@[simp]
theorem map_fun (φ : M ↪[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M ↪[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
StrongHomClass.map_rel φ r x
/-- A first-order embedding is also a first-order homomorphism. -/
def toHom : (M ↪[L] N) → M →[L] N :=
HomClass.toHom
@[simp]
theorem coe_toHom {f : M ↪[L] N} : (f.toHom : M → N) = f :=
rfl
theorem coe_injective : @Function.Injective (M ↪[L] N) (M → N) (↑)
| f, g, h => by
cases f
cases g
congr
ext x
exact Function.funext_iff.1 h x
@[ext]
theorem ext ⦃f g : M ↪[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_injective (funext h)
theorem toHom_injective : @Function.Injective (M ↪[L] N) (M →[L] N) (·.toHom) := by
intro f f' h
ext
exact congr_fun (congr_arg (↑) h) _
@[simp]
theorem toHom_inj {f g : M ↪[L] N} : f.toHom = g.toHom ↔ f = g :=
⟨fun h ↦ toHom_injective h, fun h ↦ congr_arg (·.toHom) h⟩
theorem injective (f : M ↪[L] N) : Function.Injective f :=
f.toEmbedding.injective
/-- In an algebraic language, any injective homomorphism is an embedding. -/
@[simps!]
def ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : M ↪[L] N :=
{ f with
inj' := hf
map_rel' := fun {_} r x => StrongHomClass.map_rel f r x }
@[simp]
theorem coeFn_ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) :
(ofInjective hf : M → N) = f :=
rfl
@[simp]
theorem ofInjective_toHom [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) :
(ofInjective hf).toHom = f := by
ext; simp
variable (L) (M)
/-- The identity embedding from a structure to itself. -/
@[refl]
def refl : M ↪[L] M where toEmbedding := Function.Embedding.refl M
variable {L} {M}
instance : Inhabited (M ↪[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x :=
rfl
/-- Composition of first-order embeddings. -/
@[trans]
def comp (hnp : N ↪[L] P) (hmn : M ↪[L] N) : M ↪[L] P where
toFun := hnp ∘ hmn
inj' := hnp.injective.comp hmn.injective
-- Porting note: should be done by autoparam?
map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial
-- Porting note: should be done by autoparam?
map_rel' := by intros; rw [Function.comp.assoc, map_rel, map_rel]
@[simp]
theorem comp_apply (g : N ↪[L] P) (f : M ↪[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of first-order embeddings is associative. -/
theorem comp_assoc (f : M ↪[L] N) (g : N ↪[L] P) (h : P ↪[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
theorem comp_injective (h : N ↪[L] P) :
Function.Injective (h.comp : (M ↪[L] N) → (M ↪[L] P)) := by
intro f g hfg
ext x; exact h.injective (DFunLike.congr_fun hfg x)
@[simp]
theorem comp_inj (h : N ↪[L] P) (f g : M ↪[L] N) : h.comp f = h.comp g ↔ f = g :=
⟨fun eq ↦ h.comp_injective eq, congr_arg h.comp⟩
theorem toHom_comp_injective (h : N ↪[L] P) :
Function.Injective (h.toHom.comp : (M →[L] N) → (M →[L] P)) := by
intro f g hfg
ext x; exact h.injective (DFunLike.congr_fun hfg x)
@[simp]
theorem toHom_comp_inj (h : N ↪[L] P) (f g : M →[L] N) : h.toHom.comp f = h.toHom.comp g ↔ f = g :=
⟨fun eq ↦ h.toHom_comp_injective eq, congr_arg h.toHom.comp⟩
@[simp]
theorem comp_toHom (hnp : N ↪[L] P) (hmn : M ↪[L] N) :
(hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom :=
rfl
@[simp]
theorem comp_refl (f : M ↪[L] N) : f.comp (refl L M) = f := DFunLike.coe_injective rfl
@[simp]
theorem refl_comp (f : M ↪[L] N) : (refl L N).comp f = f := DFunLike.coe_injective rfl
@[simp]
theorem refl_toHom : (refl L M).toHom = Hom.id L M :=
rfl
end Embedding
/-- Any element of an injective `StrongHomClass` can be realized as a first_order embedding. -/
def StrongHomClass.toEmbedding {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[EmbeddingLike F M N] [StrongHomClass L F M N] : F → M ↪[L] N := fun φ =>
⟨⟨φ, EmbeddingLike.injective φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩
namespace Equiv
instance : EquivLike (M ≃[L] N) M N where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by
cases f
cases g
simp only [mk.injEq]
ext x
exact Function.funext_iff.1 h₁ x
instance : StrongHomClass L (M ≃[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
/-- The inverse of a first-order equivalence is a first-order equivalence. -/
@[symm]
def symm (f : M ≃[L] N) : N ≃[L] M :=
{ f.toEquiv.symm with
map_fun' := fun n f' {x} => by
simp only [Equiv.toFun_as_coe]
rw [Equiv.symm_apply_eq]
refine Eq.trans ?_ (f.map_fun' f' (f.toEquiv.symm ∘ x)).symm
rw [← Function.comp.assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp]
map_rel' := fun n r {x} => by
simp only [Equiv.toFun_as_coe]
refine (f.map_rel' r (f.toEquiv.symm ∘ x)).symm.trans ?_
rw [← Function.comp.assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] }
instance hasCoeToFun : CoeFun (M ≃[L] N) fun _ => M → N :=
DFunLike.hasCoeToFun
@[simp]
theorem symm_symm (f : M ≃[L] N) :
f.symm.symm = f :=
rfl
@[simp]
theorem apply_symm_apply (f : M ≃[L] N) (a : N) : f (f.symm a) = a :=
f.toEquiv.apply_symm_apply a
@[simp]
theorem symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a :=
f.toEquiv.symm_apply_apply a
@[simp]
theorem map_fun (φ : M ≃[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M ≃[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
StrongHomClass.map_rel φ r x
/-- A first-order equivalence is also a first-order embedding. -/
def toEmbedding : (M ≃[L] N) → M ↪[L] N :=
StrongHomClass.toEmbedding
/-- A first-order equivalence is also a first-order homomorphism. -/
def toHom : (M ≃[L] N) → M →[L] N :=
HomClass.toHom
@[simp]
theorem toEmbedding_toHom (f : M ≃[L] N) : f.toEmbedding.toHom = f.toHom :=
rfl
@[simp]
theorem coe_toHom {f : M ≃[L] N} : (f.toHom : M → N) = (f : M → N) :=
rfl
@[simp]
theorem coe_toEmbedding (f : M ≃[L] N) : (f.toEmbedding : M → N) = (f : M → N) :=
rfl
theorem injective_toEmbedding : Function.Injective (toEmbedding : (M ≃[L] N) → M ↪[L] N) := by
intro _ _ h; apply DFunLike.coe_injective; exact congr_arg (DFunLike.coe ∘ Embedding.toHom) h
theorem coe_injective : @Function.Injective (M ≃[L] N) (M → N) (↑) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : M ≃[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_injective (funext h)
theorem bijective (f : M ≃[L] N) : Function.Bijective f :=
EquivLike.bijective f
theorem injective (f : M ≃[L] N) : Function.Injective f :=
EquivLike.injective f
theorem surjective (f : M ≃[L] N) : Function.Surjective f :=
EquivLike.surjective f
variable (L) (M)
/-- The identity equivalence from a structure to itself. -/
@[refl]
def refl : M ≃[L] M where toEquiv := _root_.Equiv.refl M
variable {L} {M}
instance : Inhabited (M ≃[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x := by simp [refl]; rfl
/-- Composition of first-order equivalences. -/
@[trans]
def comp (hnp : N ≃[L] P) (hmn : M ≃[L] N) : M ≃[L] P :=
{ hmn.toEquiv.trans hnp.toEquiv with
toFun := hnp ∘ hmn
-- Porting note: should be done by autoparam?
map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial
-- Porting note: should be done by autoparam?
map_rel' := by intros; rw [Function.comp.assoc, map_rel, map_rel] }
@[simp]
theorem comp_apply (g : N ≃[L] P) (f : M ≃[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
@[simp]
theorem comp_refl (g : M ≃[L] N) : g.comp (refl L M) = g :=
rfl
@[simp]
theorem refl_comp (g : M ≃[L] N) : (refl L N).comp g = g :=
rfl
@[simp]
theorem refl_toEmbedding : (refl L M).toEmbedding = Embedding.refl L M :=
rfl
@[simp]
theorem refl_toHom : (refl L M).toHom = Hom.id L M :=
rfl
/-- Composition of first-order homomorphisms is associative. -/
theorem comp_assoc (f : M ≃[L] N) (g : N ≃[L] P) (h : P ≃[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
theorem injective_comp (h : N ≃[L] P) :
Function.Injective (h.comp : (M ≃[L] N) → (M ≃[L] P)) := by
intro f g hfg
ext x; exact h.injective (congr_fun (congr_arg DFunLike.coe hfg) x)
@[simp]
theorem comp_toHom (hnp : N ≃[L] P) (hmn : M ≃[L] N) :
(hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom :=
rfl
@[simp]
theorem comp_toEmbedding (hnp : N ≃[L] P) (hmn : M ≃[L] N) :
(hnp.comp hmn).toEmbedding = hnp.toEmbedding.comp hmn.toEmbedding :=
rfl
@[simp]
theorem self_comp_symm (f : M ≃[L] N) : f.comp f.symm = refl L N := by
ext; rw [comp_apply, apply_symm_apply, refl_apply]
@[simp]
theorem symm_comp_self (f : M ≃[L] N) : f.symm.comp f = refl L M := by
ext; rw [comp_apply, symm_apply_apply, refl_apply]
@[simp]
theorem symm_comp_self_toEmbedding (f : M ≃[L] N) :
f.symm.toEmbedding.comp f.toEmbedding = Embedding.refl L M := by
rw [← comp_toEmbedding, symm_comp_self, refl_toEmbedding]
@[simp]
theorem self_comp_symm_toEmbedding (f : M ≃[L] N) :
f.toEmbedding.comp f.symm.toEmbedding = Embedding.refl L N := by
rw [← comp_toEmbedding, self_comp_symm, refl_toEmbedding]
@[simp]
theorem symm_comp_self_toHom (f : M ≃[L] N) :
f.symm.toHom.comp f.toHom = Hom.id L M := by
rw [← comp_toHom, symm_comp_self, refl_toHom]
@[simp]
theorem self_comp_symm_toHom (f : M ≃[L] N) :
f.toHom.comp f.symm.toHom = Hom.id L N := by
rw [← comp_toHom, self_comp_symm, refl_toHom]
@[simp]
theorem comp_symm (f : M ≃[L] N) (g : N ≃[L] P) : (g.comp f).symm = f.symm.comp g.symm :=
rfl
theorem comp_right_injective (h : M ≃[L] N) :
Function.Injective (fun f ↦ f.comp h : (N ≃[L] P) → (M ≃[L] P)) := by
intro f g hfg
convert (congr_arg (fun r : (M ≃[L] P) ↦ r.comp h.symm) hfg) <;>
rw [comp_assoc, self_comp_symm, comp_refl]
@[simp]
theorem comp_right_inj (h : M ≃[L] N) (f g : N ≃[L] P) : f.comp h = g.comp h ↔ f = g :=
⟨fun eq ↦ h.comp_right_injective eq, congr_arg (fun (r : N ≃[L] P) ↦ r.comp h)⟩
end Equiv
/-- Any element of a bijective `StrongHomClass` can be realized as a first_order isomorphism. -/
def StrongHomClass.toEquiv {F M N} [L.Structure M] [L.Structure N] [EquivLike F M N]
[StrongHomClass L F M N] : F → M ≃[L] N := fun φ =>
⟨⟨φ, EquivLike.inv φ, EquivLike.left_inv φ, EquivLike.right_inv φ⟩, StrongHomClass.map_fun φ,
StrongHomClass.map_rel φ⟩
section SumStructure
variable (L₁ L₂ : Language) (S : Type*) [L₁.Structure S] [L₂.Structure S]
instance sumStructure : (L₁.sum L₂).Structure S where
funMap := Sum.elim funMap funMap
RelMap := Sum.elim RelMap RelMap
variable {L₁ L₂ S}
@[simp]
theorem funMap_sum_inl {n : ℕ} (f : L₁.Functions n) :
@funMap (L₁.sum L₂) S _ n (Sum.inl f) = funMap f :=
rfl
@[simp]
theorem funMap_sum_inr {n : ℕ} (f : L₂.Functions n) :
@funMap (L₁.sum L₂) S _ n (Sum.inr f) = funMap f :=
rfl
@[simp]
theorem relMap_sum_inl {n : ℕ} (R : L₁.Relations n) :
@RelMap (L₁.sum L₂) S _ n (Sum.inl R) = RelMap R :=
rfl
@[simp]
theorem relMap_sum_inr {n : ℕ} (R : L₂.Relations n) :
@RelMap (L₁.sum L₂) S _ n (Sum.inr R) = RelMap R :=
rfl
end SumStructure
section Empty
section
variable [Language.empty.Structure M] [Language.empty.Structure N]
@[simp]
theorem empty.nonempty_embedding_iff :
Nonempty (M ↪[Language.empty] N) ↔ Cardinal.lift.{w'} #M ≤ Cardinal.lift.{w} #N :=
_root_.trans ⟨Nonempty.map fun f => f.toEmbedding, Nonempty.map fun f => { toEmbedding := f }⟩
Cardinal.lift_mk_le'.symm
@[simp]
theorem empty.nonempty_equiv_iff :
Nonempty (M ≃[Language.empty] N) ↔ Cardinal.lift.{w'} #M = Cardinal.lift.{w} #N :=
_root_.trans ⟨Nonempty.map fun f => f.toEquiv, Nonempty.map fun f => { toEquiv := f }⟩
Cardinal.lift_mk_eq'.symm
end
instance emptyStructure : Language.empty.Structure M :=
⟨Empty.elim, Empty.elim⟩
instance : Unique (Language.empty.Structure M) :=
⟨⟨Language.emptyStructure⟩, fun a => by
ext _ f <;> exact Empty.elim f⟩
instance (priority := 100) strongHomClassEmpty {F M N} [FunLike F M N] :
StrongHomClass Language.empty F M N :=
⟨fun _ _ f => Empty.elim f, fun _ _ r => Empty.elim r⟩
/-- Makes a `Language.empty.Hom` out of any function. -/
@[simps]
def _root_.Function.emptyHom (f : M → N) : M →[Language.empty] N where toFun := f
/-- Makes a `Language.empty.Embedding` out of any function. -/
--@[simps] Porting note: commented out and lemmas added manually
def _root_.Embedding.empty (f : M ↪ N) : M ↪[Language.empty] N where toEmbedding := f
@[simp]
theorem toFun_embedding_empty (f : M ↪ N) : (Embedding.empty f : M → N) = f :=
rfl
@[simp]
theorem toEmbedding_embedding_empty (f : M ↪ N) : (Embedding.empty f).toEmbedding = f :=
rfl
/-- Makes a `Language.empty.Equiv` out of any function. -/
--@[simps] Porting note: commented out and lemmas added manually
def _root_.Equiv.empty (f : M ≃ N) : M ≃[Language.empty] N where toEquiv := f
@[simp]
theorem toFun_equiv_empty (f : M ≃ N) : (Equiv.empty f : M → N) = f :=
rfl
@[simp]
theorem toEquiv_equiv_empty (f : M ≃ N) : (Equiv.empty f).toEquiv = f :=
rfl
end Empty
end Language
end FirstOrder
namespace Equiv
open FirstOrder FirstOrder.Language FirstOrder.Language.Structure
open FirstOrder
variable {L : Language} {M : Type*} {N : Type*} [L.Structure M]
/-- A structure induced by a bijection. -/
@[simps!]
def inducedStructure (e : M ≃ N) : L.Structure N :=
⟨fun f x => e (funMap f (e.symm ∘ x)), fun r x => RelMap r (e.symm ∘ x)⟩
/-- A bijection as a first-order isomorphism with the induced structure on the codomain. -/
--@[simps!] Porting note: commented out and lemmas added manually
def inducedStructureEquiv (e : M ≃ N) : @Language.Equiv L M N _ (inducedStructure e) := by
letI : L.Structure N := inducedStructure e
exact
{ e with
map_fun' := @fun n f x => by simp [← Function.comp.assoc e.symm e x]
map_rel' := @fun n r x => by simp [← Function.comp.assoc e.symm e x] }
@[simp]
theorem toEquiv_inducedStructureEquiv (e : M ≃ N) :
@Language.Equiv.toEquiv L M N _ (inducedStructure e) (inducedStructureEquiv e) = e :=
rfl
@[simp]
theorem toFun_inducedStructureEquiv (e : M ≃ N) :
DFunLike.coe (@inducedStructureEquiv L M N _ e) = e :=
rfl
@[simp]
theorem toFun_inducedStructureEquiv_Symm (e : M ≃ N) :
(by
letI : L.Structure N := inducedStructure e
exact DFunLike.coe (@inducedStructureEquiv L M N _ e).symm) = (e.symm : N → M) :=
rfl
end Equiv
|
ModelTheory\Bundled.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.ElementarySubstructures
import Mathlib.CategoryTheory.ConcreteCategory.Bundled
/-!
# Bundled First-Order Structures
This file bundles types together with their first-order structure.
## Main Definitions
- `FirstOrder.Language.Theory.ModelType` is the type of nonempty models of a particular theory.
- `FirstOrder.Language.equivSetoid` is the isomorphism equivalence relation on bundled structures.
## TODO
- Define category structures on bundled structures and models.
-/
universe u v w w' x
variable {L : FirstOrder.Language.{u, v}}
protected instance CategoryTheory.Bundled.structure {L : FirstOrder.Language.{u, v}}
(M : CategoryTheory.Bundled.{w} L.Structure) : L.Structure M :=
M.str
open FirstOrder Cardinal
namespace Equiv
variable (L) {M : Type w}
variable [L.Structure M] {N : Type w'} (g : M ≃ N)
/-- A type bundled with the structure induced by an equivalence. -/
@[simps]
def bundledInduced : CategoryTheory.Bundled.{w'} L.Structure :=
⟨N, g.inducedStructure⟩
/-- An equivalence of types as a first-order equivalence to the bundled structure on the codomain.
-/
@[simp]
def bundledInducedEquiv : M ≃[L] g.bundledInduced L :=
g.inducedStructureEquiv
end Equiv
namespace FirstOrder
namespace Language
/-- The equivalence relation on bundled `L.Structure`s indicating that they are isomorphic. -/
instance equivSetoid : Setoid (CategoryTheory.Bundled L.Structure) where
r M N := Nonempty (M ≃[L] N)
iseqv :=
⟨fun M => ⟨Equiv.refl L M⟩, fun {_ _} => Nonempty.map Equiv.symm, fun {_ _} _ =>
Nonempty.map2 fun MN NP => NP.comp MN⟩
variable (T : L.Theory)
namespace Theory
/-- The type of nonempty models of a first-order theory. -/
structure ModelType where
Carrier : Type w
[struc : L.Structure Carrier]
[is_model : T.Model Carrier]
[nonempty' : Nonempty Carrier]
-- Porting note: In Lean4, other instances precedes `FirstOrder.Language.Theory.ModelType.struc`,
-- it's issues in `ModelTheory.Satisfiability`. So, we increase these priorities.
attribute [instance 2000] ModelType.struc ModelType.is_model ModelType.nonempty'
namespace ModelType
attribute [coe] ModelType.Carrier
instance instCoeSort : CoeSort T.ModelType (Type w) :=
⟨ModelType.Carrier⟩
/-- The object in the category of R-algebras associated to a type equipped with the appropriate
typeclasses. -/
def of (M : Type w) [L.Structure M] [M ⊨ T] [Nonempty M] : T.ModelType :=
⟨M⟩
@[simp]
theorem coe_of (M : Type w) [L.Structure M] [M ⊨ T] [Nonempty M] : (of T M : Type w) = M :=
rfl
instance instNonempty (M : T.ModelType) : Nonempty M :=
inferInstance
section Inhabited
attribute [local instance] Inhabited.trivialStructure
instance instInhabited : Inhabited (ModelType.{u, v, w} (∅ : L.Theory)) :=
⟨ModelType.of _ PUnit⟩
end Inhabited
variable {T}
/-- Maps a bundled model along a bijection. -/
def equivInduced {M : ModelType.{u, v, w} T} {N : Type w'} (e : M ≃ N) :
ModelType.{u, v, w'} T where
Carrier := N
struc := e.inducedStructure
is_model := @Equiv.theory_model L M N _ e.inducedStructure T e.inducedStructureEquiv _
nonempty' := e.symm.nonempty
instance of_small (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] [h : Small.{w'} M] :
Small.{w'} (ModelType.of T M) :=
h
/-- Shrinks a small model to a particular universe. -/
noncomputable def shrink (M : ModelType.{u, v, w} T) [Small.{w'} M] : ModelType.{u, v, w'} T :=
equivInduced (equivShrink M)
/-- Lifts a model to a particular universe. -/
def ulift (M : ModelType.{u, v, w} T) : ModelType.{u, v, max w w'} T :=
equivInduced (Equiv.ulift.{w', w}.symm : M ≃ _)
/-- The reduct of any model of `φ.onTheory T` is a model of `T`. -/
@[simps]
def reduct {L' : Language} (φ : L →ᴸ L') (M : (φ.onTheory T).ModelType) : T.ModelType where
Carrier := M
struc := φ.reduct M
nonempty' := M.nonempty'
is_model := (@LHom.onTheory_model L L' M (φ.reduct M) _ φ _ T).1 M.is_model
/-- When `φ` is injective, `defaultExpansion` expands a model of `T` to a model of `φ.onTheory T`
arbitrarily. -/
@[simps]
noncomputable def defaultExpansion {L' : Language} {φ : L →ᴸ L'} (h : φ.Injective)
[∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => φ.onFunction f)]
[∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => φ.onRelation r)]
(M : T.ModelType) [Inhabited M] : (φ.onTheory T).ModelType where
Carrier := M
struc := φ.defaultExpansion M
nonempty' := M.nonempty'
is_model :=
(@LHom.onTheory_model L L' M _ (φ.defaultExpansion M) φ (h.isExpansionOn_default M) T).2
M.is_model
instance leftStructure {L' : Language} {T : (L.sum L').Theory} (M : T.ModelType) : L.Structure M :=
(LHom.sumInl : L →ᴸ L.sum L').reduct M
instance rightStructure {L' : Language} {T : (L.sum L').Theory} (M : T.ModelType) :
L'.Structure M :=
(LHom.sumInr : L' →ᴸ L.sum L').reduct M
/-- A model of a theory is also a model of any subtheory. -/
@[simps]
def subtheoryModel (M : T.ModelType) {T' : L.Theory} (h : T' ⊆ T) : T'.ModelType where
Carrier := M
is_model := ⟨fun _φ hφ => realize_sentence_of_mem T (h hφ)⟩
instance subtheoryModel_models (M : T.ModelType) {T' : L.Theory} (h : T' ⊆ T) :
M.subtheoryModel h ⊨ T :=
M.is_model
end ModelType
variable {T}
/-- Bundles `M ⊨ T` as a `T.ModelType`. -/
def Model.bundled {M : Type w} [LM : L.Structure M] [ne : Nonempty M] (h : M ⊨ T) : T.ModelType :=
@ModelType.of L T M LM h ne
@[simp]
theorem coe_of {M : Type w} [L.Structure M] [Nonempty M] (h : M ⊨ T) : (h.bundled : Type w) = M :=
rfl
end Theory
/-- A structure that is elementarily equivalent to a model, bundled as a model. -/
def ElementarilyEquivalent.toModel {M : T.ModelType} {N : Type*} [LN : L.Structure N]
(h : M ≅[L] N) : T.ModelType where
Carrier := N
struc := LN
nonempty' := h.nonempty
is_model := h.theory_model
/-- An elementary substructure of a bundled model as a bundled model. -/
def ElementarySubstructure.toModel {M : T.ModelType} (S : L.ElementarySubstructure M) :
T.ModelType :=
S.elementarilyEquivalent.symm.toModel T
instance ElementarySubstructure.toModel.instSmall {M : T.ModelType}
(S : L.ElementarySubstructure M) [h : Small.{w, x} S] : Small.{w, x} (S.toModel T) :=
h
end Language
end FirstOrder
|
ModelTheory\Complexity.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Satisfiability
/-!
# Quantifier Complexity
This file defines quantifier complexity of first-order formulas, and constructs prenex normal forms.
## Main Definitions
- `FirstOrder.Language.BoundedFormula.IsAtomic` defines atomic formulas - those which are
constructed only from terms and relations.
- `FirstOrder.Language.BoundedFormula.IsQF` defines quantifier-free formulas - those which are
constructed only from atomic formulas and boolean operations.
- `FirstOrder.Language.BoundedFormula.IsPrenex` defines when a formula is in prenex normal form -
when it consists of a series of quantifiers applied to a quantifier-free formula.
- `FirstOrder.Language.BoundedFormula.toPrenex` constructs a prenex normal form of a given formula.
## Main Results
- `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a
formula has the same realization as the original formula.
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
variable {n l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ}
variable {v : α → M} {xs : Fin l → M}
open FirstOrder Structure Fin
namespace BoundedFormula
/-- An atomic formula is either equality or a relation symbol applied to terms.
Note that `⊥` and `⊤` are not considered atomic in this convention. -/
inductive IsAtomic : L.BoundedFormula α n → Prop
| equal (t₁ t₂ : L.Term (α ⊕ (Fin n))) : IsAtomic (t₁.bdEqual t₂)
| rel {l : ℕ} (R : L.Relations l) (ts : Fin l → L.Term (α ⊕ (Fin n))) :
IsAtomic (R.boundedFormula ts)
theorem not_all_isAtomic (φ : L.BoundedFormula α (n + 1)) : ¬φ.all.IsAtomic := fun con => by
cases con
theorem not_ex_isAtomic (φ : L.BoundedFormula α (n + 1)) : ¬φ.ex.IsAtomic := fun con => by cases con
theorem IsAtomic.relabel {m : ℕ} {φ : L.BoundedFormula α m} (h : φ.IsAtomic)
(f : α → β ⊕ (Fin n)) : (φ.relabel f).IsAtomic :=
IsAtomic.recOn h (fun _ _ => IsAtomic.equal _ _) fun _ _ => IsAtomic.rel _ _
theorem IsAtomic.liftAt {k m : ℕ} (h : IsAtomic φ) : (φ.liftAt k m).IsAtomic :=
IsAtomic.recOn h (fun _ _ => IsAtomic.equal _ _) fun _ _ => IsAtomic.rel _ _
theorem IsAtomic.castLE {h : l ≤ n} (hφ : IsAtomic φ) : (φ.castLE h).IsAtomic :=
IsAtomic.recOn hφ (fun _ _ => IsAtomic.equal _ _) fun _ _ => IsAtomic.rel _ _
/-- A quantifier-free formula is a formula defined without quantifiers. These are all equivalent
to boolean combinations of atomic formulas. -/
inductive IsQF : L.BoundedFormula α n → Prop
| falsum : IsQF falsum
| of_isAtomic {φ} (h : IsAtomic φ) : IsQF φ
| imp {φ₁ φ₂} (h₁ : IsQF φ₁) (h₂ : IsQF φ₂) : IsQF (φ₁.imp φ₂)
theorem IsAtomic.isQF {φ : L.BoundedFormula α n} : IsAtomic φ → IsQF φ :=
IsQF.of_isAtomic
theorem isQF_bot : IsQF (⊥ : L.BoundedFormula α n) :=
IsQF.falsum
theorem IsQF.not {φ : L.BoundedFormula α n} (h : IsQF φ) : IsQF φ.not :=
h.imp isQF_bot
theorem IsQF.relabel {m : ℕ} {φ : L.BoundedFormula α m} (h : φ.IsQF) (f : α → β ⊕ (Fin n)) :
(φ.relabel f).IsQF :=
IsQF.recOn h isQF_bot (fun h => (h.relabel f).isQF) fun _ _ h1 h2 => h1.imp h2
theorem IsQF.liftAt {k m : ℕ} (h : IsQF φ) : (φ.liftAt k m).IsQF :=
IsQF.recOn h isQF_bot (fun ih => ih.liftAt.isQF) fun _ _ ih1 ih2 => ih1.imp ih2
theorem IsQF.castLE {h : l ≤ n} (hφ : IsQF φ) : (φ.castLE h).IsQF :=
IsQF.recOn hφ isQF_bot (fun ih => ih.castLE.isQF) fun _ _ ih1 ih2 => ih1.imp ih2
theorem not_all_isQF (φ : L.BoundedFormula α (n + 1)) : ¬φ.all.IsQF := fun con => by
cases' con with _ con
exact φ.not_all_isAtomic con
theorem not_ex_isQF (φ : L.BoundedFormula α (n + 1)) : ¬φ.ex.IsQF := fun con => by
cases' con with _ con _ _ con
· exact φ.not_ex_isAtomic con
· exact not_all_isQF _ con
/-- Indicates that a bounded formula is in prenex normal form - that is, it consists of quantifiers
applied to a quantifier-free formula. -/
inductive IsPrenex : ∀ {n}, L.BoundedFormula α n → Prop
| of_isQF {n} {φ : L.BoundedFormula α n} (h : IsQF φ) : IsPrenex φ
| all {n} {φ : L.BoundedFormula α (n + 1)} (h : IsPrenex φ) : IsPrenex φ.all
| ex {n} {φ : L.BoundedFormula α (n + 1)} (h : IsPrenex φ) : IsPrenex φ.ex
theorem IsQF.isPrenex {φ : L.BoundedFormula α n} : IsQF φ → IsPrenex φ :=
IsPrenex.of_isQF
theorem IsAtomic.isPrenex {φ : L.BoundedFormula α n} (h : IsAtomic φ) : IsPrenex φ :=
h.isQF.isPrenex
theorem IsPrenex.induction_on_all_not {P : ∀ {n}, L.BoundedFormula α n → Prop}
{φ : L.BoundedFormula α n} (h : IsPrenex φ)
(hq : ∀ {m} {ψ : L.BoundedFormula α m}, ψ.IsQF → P ψ)
(ha : ∀ {m} {ψ : L.BoundedFormula α (m + 1)}, P ψ → P ψ.all)
(hn : ∀ {m} {ψ : L.BoundedFormula α m}, P ψ → P ψ.not) : P φ :=
IsPrenex.recOn h hq (fun _ => ha) fun _ ih => hn (ha (hn ih))
theorem IsPrenex.relabel {m : ℕ} {φ : L.BoundedFormula α m} (h : φ.IsPrenex)
(f : α → β ⊕ (Fin n)) : (φ.relabel f).IsPrenex :=
IsPrenex.recOn h (fun h => (h.relabel f).isPrenex) (fun _ h => by simp [h.all])
fun _ h => by simp [h.ex]
theorem IsPrenex.castLE (hφ : IsPrenex φ) : ∀ {n} {h : l ≤ n}, (φ.castLE h).IsPrenex :=
IsPrenex.recOn (motive := @fun l φ _ => ∀ (n : ℕ) (h : l ≤ n), (φ.castLE h).IsPrenex) hφ
(@fun _ _ ih _ _ => ih.castLE.isPrenex)
(@fun _ _ _ ih _ _ => (ih _ _).all)
(@fun _ _ _ ih _ _ => (ih _ _).ex) _ _
theorem IsPrenex.liftAt {k m : ℕ} (h : IsPrenex φ) : (φ.liftAt k m).IsPrenex :=
IsPrenex.recOn h (fun ih => ih.liftAt.isPrenex) (fun _ ih => ih.castLE.all)
fun _ ih => ih.castLE.ex
-- Porting note: universes in different order
/-- An auxiliary operation to `FirstOrder.Language.BoundedFormula.toPrenex`.
If `φ` is quantifier-free and `ψ` is in prenex normal form, then `φ.toPrenexImpRight ψ`
is a prenex normal form for `φ.imp ψ`. -/
def toPrenexImpRight : ∀ {n}, L.BoundedFormula α n → L.BoundedFormula α n → L.BoundedFormula α n
| n, φ, BoundedFormula.ex ψ => ((φ.liftAt 1 n).toPrenexImpRight ψ).ex
| n, φ, all ψ => ((φ.liftAt 1 n).toPrenexImpRight ψ).all
| _n, φ, ψ => φ.imp ψ
theorem IsQF.toPrenexImpRight {φ : L.BoundedFormula α n} :
∀ {ψ : L.BoundedFormula α n}, IsQF ψ → φ.toPrenexImpRight ψ = φ.imp ψ
| _, IsQF.falsum => rfl
| _, IsQF.of_isAtomic (IsAtomic.equal _ _) => rfl
| _, IsQF.of_isAtomic (IsAtomic.rel _ _) => rfl
| _, IsQF.imp IsQF.falsum _ => rfl
| _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.equal _ _)) _ => rfl
| _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.rel _ _)) _ => rfl
| _, IsQF.imp (IsQF.imp _ _) _ => rfl
theorem isPrenex_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ) :
IsPrenex (φ.toPrenexImpRight ψ) := by
induction' hψ with _ _ hψ _ _ _ ih1 _ _ _ ih2
· rw [hψ.toPrenexImpRight]
exact (hφ.imp hψ).isPrenex
· exact (ih1 hφ.liftAt).all
· exact (ih2 hφ.liftAt).ex
-- Porting note: universes in different order
/-- An auxiliary operation to `FirstOrder.Language.BoundedFormula.toPrenex`.
If `φ` and `ψ` are in prenex normal form, then `φ.toPrenexImp ψ`
is a prenex normal form for `φ.imp ψ`. -/
def toPrenexImp : ∀ {n}, L.BoundedFormula α n → L.BoundedFormula α n → L.BoundedFormula α n
| n, BoundedFormula.ex φ, ψ => (φ.toPrenexImp (ψ.liftAt 1 n)).all
| n, all φ, ψ => (φ.toPrenexImp (ψ.liftAt 1 n)).ex
| _, φ, ψ => φ.toPrenexImpRight ψ
theorem IsQF.toPrenexImp :
∀ {φ ψ : L.BoundedFormula α n}, φ.IsQF → φ.toPrenexImp ψ = φ.toPrenexImpRight ψ
| _, _, IsQF.falsum => rfl
| _, _, IsQF.of_isAtomic (IsAtomic.equal _ _) => rfl
| _, _, IsQF.of_isAtomic (IsAtomic.rel _ _) => rfl
| _, _, IsQF.imp IsQF.falsum _ => rfl
| _, _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.equal _ _)) _ => rfl
| _, _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.rel _ _)) _ => rfl
| _, _, IsQF.imp (IsQF.imp _ _) _ => rfl
theorem isPrenex_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ) :
IsPrenex (φ.toPrenexImp ψ) := by
induction' hφ with _ _ hφ _ _ _ ih1 _ _ _ ih2
· rw [hφ.toPrenexImp]
exact isPrenex_toPrenexImpRight hφ hψ
· exact (ih1 hψ.liftAt).ex
· exact (ih2 hψ.liftAt).all
-- Porting note: universes in different order
/-- For any bounded formula `φ`, `φ.toPrenex` is a semantically-equivalent formula in prenex normal
form. -/
def toPrenex : ∀ {n}, L.BoundedFormula α n → L.BoundedFormula α n
| _, falsum => ⊥
| _, equal t₁ t₂ => t₁.bdEqual t₂
| _, rel R ts => rel R ts
| _, imp f₁ f₂ => f₁.toPrenex.toPrenexImp f₂.toPrenex
| _, all f => f.toPrenex.all
theorem toPrenex_isPrenex (φ : L.BoundedFormula α n) : φ.toPrenex.IsPrenex :=
BoundedFormula.recOn φ isQF_bot.isPrenex (fun _ _ => (IsAtomic.equal _ _).isPrenex)
(fun _ _ => (IsAtomic.rel _ _).isPrenex) (fun _ _ h1 h2 => isPrenex_toPrenexImp h1 h2)
fun _ => IsPrenex.all
variable [Nonempty M]
theorem realize_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ)
{v : α → M} {xs : Fin n → M} :
(φ.toPrenexImpRight ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by
induction' hψ with _ _ hψ _ _ _hψ ih _ _ _hψ ih
· rw [hψ.toPrenexImpRight]
· refine _root_.trans (forall_congr' fun _ => ih hφ.liftAt) ?_
simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all]
exact ⟨fun h1 a h2 => h1 h2 a, fun h1 h2 a => h1 a h2⟩
· unfold toPrenexImpRight
rw [realize_ex]
refine _root_.trans (exists_congr fun _ => ih hφ.liftAt) ?_
simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_ex]
refine ⟨?_, fun h' => ?_⟩
· rintro ⟨a, ha⟩ h
exact ⟨a, ha h⟩
· by_cases h : φ.Realize v xs
· obtain ⟨a, ha⟩ := h' h
exact ⟨a, fun _ => ha⟩
· inhabit M
exact ⟨default, fun h'' => (h h'').elim⟩
theorem realize_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ)
{v : α → M} {xs : Fin n → M} : (φ.toPrenexImp ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by
revert ψ
induction' hφ with _ _ hφ _ _ _hφ ih _ _ _hφ ih <;> intro ψ hψ
· rw [hφ.toPrenexImp]
exact realize_toPrenexImpRight hφ hψ
· unfold toPrenexImp
rw [realize_ex]
refine _root_.trans (exists_congr fun _ => ih hψ.liftAt) ?_
simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all]
refine ⟨?_, fun h' => ?_⟩
· rintro ⟨a, ha⟩ h
exact ha (h a)
· by_cases h : ψ.Realize v xs
· inhabit M
exact ⟨default, fun _h'' => h⟩
· obtain ⟨a, ha⟩ := not_forall.1 (h ∘ h')
exact ⟨a, fun h => (ha h).elim⟩
· refine _root_.trans (forall_congr' fun _ => ih hψ.liftAt) ?_
simp
@[simp]
theorem realize_toPrenex (φ : L.BoundedFormula α n) {v : α → M} :
∀ {xs : Fin n → M}, φ.toPrenex.Realize v xs ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ f1 f2 h1 h2 _ _ h
· exact Iff.rfl
· exact Iff.rfl
· exact Iff.rfl
· intros
rw [toPrenex, realize_toPrenexImp f1.toPrenex_isPrenex f2.toPrenex_isPrenex, realize_imp,
realize_imp, h1, h2]
· intros
rw [realize_all, toPrenex, realize_all]
exact forall_congr' fun a => h
theorem IsQF.induction_on_sup_not {P : L.BoundedFormula α n → Prop} {φ : L.BoundedFormula α n}
(h : IsQF φ) (hf : P (⊥ : L.BoundedFormula α n))
(ha : ∀ ψ : L.BoundedFormula α n, IsAtomic ψ → P ψ)
(hsup : ∀ {φ₁ φ₂}, P φ₁ → P φ₂ → P (φ₁ ⊔ φ₂)) (hnot : ∀ {φ}, P φ → P φ.not)
(hse :
∀ {φ₁ φ₂ : L.BoundedFormula α n}, Theory.SemanticallyEquivalent ∅ φ₁ φ₂ → (P φ₁ ↔ P φ₂)) :
P φ :=
IsQF.recOn h hf @(ha) fun {φ₁ φ₂} _ _ h1 h2 =>
(hse (φ₁.imp_semanticallyEquivalent_not_sup φ₂)).2 (hsup (hnot h1) h2)
theorem IsQF.induction_on_inf_not {P : L.BoundedFormula α n → Prop} {φ : L.BoundedFormula α n}
(h : IsQF φ) (hf : P (⊥ : L.BoundedFormula α n))
(ha : ∀ ψ : L.BoundedFormula α n, IsAtomic ψ → P ψ)
(hinf : ∀ {φ₁ φ₂}, P φ₁ → P φ₂ → P (φ₁ ⊓ φ₂)) (hnot : ∀ {φ}, P φ → P φ.not)
(hse :
∀ {φ₁ φ₂ : L.BoundedFormula α n}, Theory.SemanticallyEquivalent ∅ φ₁ φ₂ → (P φ₁ ↔ P φ₂)) :
P φ :=
h.induction_on_sup_not hf ha
(fun {φ₁ φ₂} h1 h2 =>
(hse (φ₁.sup_semanticallyEquivalent_not_inf_not φ₂)).2 (hnot (hinf (hnot h1) (hnot h2))))
(fun {_} => hnot) fun {_ _} => hse
theorem semanticallyEquivalent_toPrenex (φ : L.BoundedFormula α n) :
(∅ : L.Theory).SemanticallyEquivalent φ φ.toPrenex := fun M v xs => by
rw [realize_iff, realize_toPrenex]
theorem induction_on_all_ex {P : ∀ {m}, L.BoundedFormula α m → Prop} (φ : L.BoundedFormula α n)
(hqf : ∀ {m} {ψ : L.BoundedFormula α m}, IsQF ψ → P ψ)
(hall : ∀ {m} {ψ : L.BoundedFormula α (m + 1)}, P ψ → P ψ.all)
(hex : ∀ {m} {φ : L.BoundedFormula α (m + 1)}, P φ → P φ.ex)
(hse : ∀ {m} {φ₁ φ₂ : L.BoundedFormula α m},
Theory.SemanticallyEquivalent ∅ φ₁ φ₂ → (P φ₁ ↔ P φ₂)) :
P φ := by
suffices h' : ∀ {m} {φ : L.BoundedFormula α m}, φ.IsPrenex → P φ from
(hse φ.semanticallyEquivalent_toPrenex).2 (h' φ.toPrenex_isPrenex)
intro m φ hφ
induction' hφ with _ _ hφ _ _ _ hφ _ _ _ hφ
· exact hqf hφ
· exact hall hφ
· exact hex hφ
theorem induction_on_exists_not {P : ∀ {m}, L.BoundedFormula α m → Prop} (φ : L.BoundedFormula α n)
(hqf : ∀ {m} {ψ : L.BoundedFormula α m}, IsQF ψ → P ψ)
(hnot : ∀ {m} {φ : L.BoundedFormula α m}, P φ → P φ.not)
(hex : ∀ {m} {φ : L.BoundedFormula α (m + 1)}, P φ → P φ.ex)
(hse : ∀ {m} {φ₁ φ₂ : L.BoundedFormula α m},
Theory.SemanticallyEquivalent ∅ φ₁ φ₂ → (P φ₁ ↔ P φ₂)) :
P φ :=
φ.induction_on_all_ex (fun {_ _} => hqf)
(fun {_ φ} hφ => (hse φ.all_semanticallyEquivalent_not_ex_not).2 (hnot (hex (hnot hφ))))
(fun {_ _} => hex) fun {_ _ _} => hse
end BoundedFormula
theorem Formula.isAtomic_graph (f : L.Functions n) : (Formula.graph f).IsAtomic :=
BoundedFormula.IsAtomic.equal _ _
end Language
end FirstOrder
|
ModelTheory\Definability.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.SetLike.Basic
import Mathlib.Data.Finset.Preimage
import Mathlib.ModelTheory.Semantics
/-!
# Definable Sets
This file defines what it means for a set over a first-order structure to be definable.
## Main Definitions
- `Set.Definable` is defined so that `A.Definable L s` indicates that the
set `s` of a finite cartesian power of `M` is definable with parameters in `A`.
- `Set.Definable₁` is defined so that `A.Definable₁ L s` indicates that
`(s : Set M)` is definable with parameters in `A`.
- `Set.Definable₂` is defined so that `A.Definable₂ L s` indicates that
`(s : Set (M × M))` is definable with parameters in `A`.
- A `FirstOrder.Language.DefinableSet` is defined so that `L.DefinableSet A α` is the boolean
algebra of subsets of `α → M` defined by formulas with parameters in `A`.
## Main Results
- `L.DefinableSet A α` forms a `BooleanAlgebra`
- `Set.Definable.image_comp` shows that definability is closed under projections in finite
dimensions.
-/
universe u v w u₁
namespace Set
variable {M : Type w} (A : Set M) (L : FirstOrder.Language.{u, v}) [L.Structure M]
open FirstOrder FirstOrder.Language FirstOrder.Language.Structure
variable {α : Type u₁} {β : Type*}
/-- A subset of a finite Cartesian product of a structure is definable over a set `A` when
membership in the set is given by a first-order formula with parameters from `A`. -/
def Definable (s : Set (α → M)) : Prop :=
∃ φ : L[[A]].Formula α, s = setOf φ.Realize
variable {L} {A} {B : Set M} {s : Set (α → M)}
theorem Definable.map_expansion {L' : FirstOrder.Language} [L'.Structure M] (h : A.Definable L s)
(φ : L →ᴸ L') [φ.IsExpansionOn M] : A.Definable L' s := by
obtain ⟨ψ, rfl⟩ := h
refine ⟨(φ.addConstants A).onFormula ψ, ?_⟩
ext x
simp only [mem_setOf_eq, LHom.realize_onFormula]
theorem definable_iff_exists_formula_sum :
A.Definable L s ↔ ∃ φ : L.Formula (A ⊕ α), s = {v | φ.Realize (Sum.elim (↑) v)} := by
rw [Definable, Equiv.exists_congr_left (BoundedFormula.constantsVarsEquiv)]
refine exists_congr (fun φ => iff_iff_eq.2 (congr_arg (s = ·) ?_))
ext
simp only [Formula.Realize, BoundedFormula.constantsVarsEquiv, constantsOn, mk₂_Relations,
BoundedFormula.mapTermRelEquiv_symm_apply, mem_setOf_eq]
refine BoundedFormula.realize_mapTermRel_id ?_ (fun _ _ _ => rfl)
intros
simp only [Term.constantsVarsEquivLeft_symm_apply, Term.realize_varsToConstants,
coe_con, Term.realize_relabel]
congr
ext a
rcases a with (_ | _) | _ <;> rfl
theorem empty_definable_iff :
(∅ : Set M).Definable L s ↔ ∃ φ : L.Formula α, s = setOf φ.Realize := by
rw [Definable, Equiv.exists_congr_left (LEquiv.addEmptyConstants L (∅ : Set M)).onFormula]
simp [-constantsOn]
theorem definable_iff_empty_definable_with_params :
A.Definable L s ↔ (∅ : Set M).Definable (L[[A]]) s :=
empty_definable_iff.symm
theorem Definable.mono (hAs : A.Definable L s) (hAB : A ⊆ B) : B.Definable L s := by
rw [definable_iff_empty_definable_with_params] at *
exact hAs.map_expansion (L.lhomWithConstantsMap (Set.inclusion hAB))
@[simp]
theorem definable_empty : A.Definable L (∅ : Set (α → M)) :=
⟨⊥, by
ext
simp⟩
@[simp]
theorem definable_univ : A.Definable L (univ : Set (α → M)) :=
⟨⊤, by
ext
simp⟩
@[simp]
theorem Definable.inter {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) :
A.Definable L (f ∩ g) := by
rcases hf with ⟨φ, rfl⟩
rcases hg with ⟨θ, rfl⟩
refine ⟨φ ⊓ θ, ?_⟩
ext
simp
@[simp]
theorem Definable.union {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) :
A.Definable L (f ∪ g) := by
rcases hf with ⟨φ, hφ⟩
rcases hg with ⟨θ, hθ⟩
refine ⟨φ ⊔ θ, ?_⟩
ext
rw [hφ, hθ, mem_setOf_eq, Formula.realize_sup, mem_union, mem_setOf_eq, mem_setOf_eq]
theorem definable_finset_inf {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i))
(s : Finset ι) : A.Definable L (s.inf f) := by
classical
refine Finset.induction definable_univ (fun i s _ h => ?_) s
rw [Finset.inf_insert]
exact (hf i).inter h
theorem definable_finset_sup {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i))
(s : Finset ι) : A.Definable L (s.sup f) := by
classical
refine Finset.induction definable_empty (fun i s _ h => ?_) s
rw [Finset.sup_insert]
exact (hf i).union h
theorem definable_finset_biInter {ι : Type*} {f : ι → Set (α → M)}
(hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋂ i ∈ s, f i) := by
rw [← Finset.inf_set_eq_iInter]
exact definable_finset_inf hf s
theorem definable_finset_biUnion {ι : Type*} {f : ι → Set (α → M)}
(hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋃ i ∈ s, f i) := by
rw [← Finset.sup_set_eq_biUnion]
exact definable_finset_sup hf s
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
rcases hf with ⟨φ, hφ⟩
refine ⟨φ.not, ?_⟩
ext v
rw [hφ, compl_setOf, mem_setOf, mem_setOf, Formula.realize_not]
@[simp]
theorem Definable.sdiff {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) :
A.Definable L (s \ t) :=
hs.inter ht.compl
@[simp] lemma Definable.himp {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) :
A.Definable L (s ⇨ t) := by rw [himp_eq]; exact ht.union hs.compl
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
obtain ⟨φ, rfl⟩ := h
refine ⟨φ.relabel f, ?_⟩
ext
simp only [Set.preimage_setOf_eq, mem_setOf_eq, Formula.realize_relabel]
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
refine (congr rfl ?_).mp (h.preimage_comp f.symm)
rw [image_eq_preimage_of_inverse]
· intro i
ext b
simp only [Function.comp_apply, Equiv.apply_symm_apply]
· intro i
ext a
simp
theorem definable_iff_finitely_definable :
A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
(A0 : Set M).Definable L s := by
letI := Classical.decEq M
letI := Classical.decEq α
constructor
· simp only [definable_iff_exists_formula_sum]
rintro ⟨φ, rfl⟩
let A0 := (φ.freeVarFinset.preimage Sum.inl
(Function.Injective.injOn Sum.inl_injective)).image Subtype.val
have hA0 : (A0 : Set M) ⊆ A := by simp [A0]
refine ⟨A0, hA0, (φ.restrictFreeVar
(Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
· rintro ⟨a | a, ha⟩
· exact Sum.inl (Sum.inl ⟨a, by simpa [A0] using ha⟩)
· exact Sum.inl (Sum.inr a)
· ext v
simp only [Formula.Realize, BoundedFormula.realize_relabel,
Set.mem_setOf_eq]
apply Iff.symm
convert BoundedFormula.realize_restrictFreeVar _
ext a
rcases a with ⟨_ | _, _⟩ <;> simp
· rintro ⟨A0, hA0, hd⟩
exact Definable.mono hd hA0
/-- This lemma is only intended as a helper for `Definable.image_comp`. -/
theorem Definable.image_comp_sum_inl_fin (m : ℕ) {s : Set (Sum α (Fin m) → M)}
(h : A.Definable L s) : A.Definable L ((fun g : Sum α (Fin m) → M => g ∘ Sum.inl) '' s) := by
obtain ⟨φ, rfl⟩ := h
refine ⟨(BoundedFormula.relabel id φ).exs, ?_⟩
ext x
simp only [Set.mem_image, mem_setOf_eq, BoundedFormula.realize_exs,
BoundedFormula.realize_relabel, Function.comp_id, Fin.castAdd_zero, Fin.cast_refl]
constructor
· rintro ⟨y, hy, rfl⟩
exact
⟨y ∘ Sum.inr, (congr (congr rfl (Sum.elim_comp_inl_inr y).symm) (funext finZeroElim)).mp hy⟩
· rintro ⟨y, hy⟩
exact ⟨Sum.elim x y, (congr rfl (funext finZeroElim)).mp hy, Sum.elim_comp_inl _ _⟩
/-- Shows that definability is closed under finite projections. -/
theorem Definable.image_comp_embedding {s : Set (β → M)} (h : A.Definable L s) (f : α ↪ β)
[Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
classical
cases nonempty_fintype β
refine
(congr rfl (ext fun x => ?_)).mp
(((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv
(Equiv.sumCongr (Equiv.ofInjective f f.injective)
(Fintype.equivFin (↥(range f)ᶜ)).symm)).image_comp_sum_inl_fin
_)
simp only [mem_preimage, mem_image, exists_exists_and_eq_and]
refine exists_congr fun y => and_congr_right fun _ => Eq.congr_left (funext fun a => ?_)
simp
/-- Shows that definability is closed under finite projections. -/
theorem Definable.image_comp {s : Set (β → M)} (h : A.Definable L s) (f : α → β) [Finite α]
[Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
classical
cases nonempty_fintype α
cases nonempty_fintype β
have h :=
(((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv
(Equiv.sumCongr (_root_.Equiv.refl _)
(Fintype.equivFin _).symm)).image_comp_sum_inl_fin
_).preimage_comp
(rangeSplitting f)
have h' :
A.Definable L { x : α → M | ∀ a, x a = x (rangeSplitting f (rangeFactorization f a)) } := by
have h' : ∀ a,
A.Definable L { x : α → M | x a = x (rangeSplitting f (rangeFactorization f a)) } := by
refine fun a => ⟨(var a).equal (var (rangeSplitting f (rangeFactorization f a))), ext ?_⟩
simp
refine (congr rfl (ext ?_)).mp (definable_finset_biInter h' Finset.univ)
simp
refine (congr rfl (ext fun x => ?_)).mp (h.inter h')
simp only [Equiv.coe_trans, mem_inter_iff, mem_preimage, mem_image, exists_exists_and_eq_and,
mem_setOf_eq]
constructor
· rintro ⟨⟨y, ys, hy⟩, hx⟩
refine ⟨y, ys, ?_⟩
ext a
rw [hx a, ← Function.comp_apply (f := x), ← hy]
simp
· rintro ⟨y, ys, rfl⟩
refine ⟨⟨y, ys, ?_⟩, fun a => ?_⟩
· ext
simp [Set.apply_rangeSplitting f]
· rw [Function.comp_apply, Function.comp_apply, apply_rangeSplitting f,
rangeFactorization_coe]
variable (L A)
/-- A 1-dimensional version of `Definable`, for `Set M`. -/
def Definable₁ (s : Set M) : Prop :=
A.Definable L { x : Fin 1 → M | x 0 ∈ s }
/-- A 2-dimensional version of `Definable`, for `Set (M × M)`. -/
def Definable₂ (s : Set (M × M)) : Prop :=
A.Definable L { x : Fin 2 → M | (x 0, x 1) ∈ s }
end Set
namespace FirstOrder
namespace Language
open Set
variable (L : FirstOrder.Language.{u, v}) {M : Type w} [L.Structure M] (A : Set M) (α : Type u₁)
/-- Definable sets are subsets of finite Cartesian products of a structure such that membership is
given by a first-order formula. -/
def DefinableSet :=
{ s : Set (α → M) // A.Definable L s }
namespace DefinableSet
variable {L A α}
variable {s t : L.DefinableSet A α} {x : α → M}
instance instSetLike : SetLike (L.DefinableSet A α) (α → M) where
coe := Subtype.val
coe_injective' := Subtype.val_injective
instance instTop : Top (L.DefinableSet A α) :=
⟨⟨⊤, definable_univ⟩⟩
instance instBot : Bot (L.DefinableSet A α) :=
⟨⟨⊥, definable_empty⟩⟩
instance instSup : Sup (L.DefinableSet A α) :=
⟨fun s t => ⟨s ∪ t, s.2.union t.2⟩⟩
instance instInf : Inf (L.DefinableSet A α) :=
⟨fun s t => ⟨s ∩ t, s.2.inter t.2⟩⟩
instance instHasCompl : HasCompl (L.DefinableSet A α) :=
⟨fun s => ⟨sᶜ, s.2.compl⟩⟩
instance instSDiff : SDiff (L.DefinableSet A α) :=
⟨fun s t => ⟨s \ t, s.2.sdiff t.2⟩⟩
-- Why does it complain that `s ⇨ t` is noncomputable?
noncomputable instance instHImp : HImp (L.DefinableSet A α) where
himp s t := ⟨s ⇨ t, s.2.himp t.2⟩
instance instInhabited : Inhabited (L.DefinableSet A α) :=
⟨⊥⟩
theorem le_iff : s ≤ t ↔ (s : Set (α → M)) ≤ (t : Set (α → M)) :=
Iff.rfl
@[simp]
theorem mem_top : x ∈ (⊤ : L.DefinableSet A α) :=
mem_univ x
@[simp]
theorem not_mem_bot {x : α → M} : ¬x ∈ (⊥ : L.DefinableSet A α) :=
not_mem_empty x
@[simp]
theorem mem_sup : x ∈ s ⊔ t ↔ x ∈ s ∨ x ∈ t :=
Iff.rfl
@[simp]
theorem mem_inf : x ∈ s ⊓ t ↔ x ∈ s ∧ x ∈ t :=
Iff.rfl
@[simp]
theorem mem_compl : x ∈ sᶜ ↔ ¬x ∈ s :=
Iff.rfl
@[simp]
theorem mem_sdiff : x ∈ s \ t ↔ x ∈ s ∧ ¬x ∈ t :=
Iff.rfl
@[simp, norm_cast]
theorem coe_top : ((⊤ : L.DefinableSet A α) : Set (α → M)) = univ :=
rfl
@[simp, norm_cast]
theorem coe_bot : ((⊥ : L.DefinableSet A α) : Set (α → M)) = ∅ :=
rfl
@[simp, norm_cast]
theorem coe_sup (s t : L.DefinableSet A α) :
((s ⊔ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) ∪ (t : Set (α → M)) :=
rfl
@[simp, norm_cast]
theorem coe_inf (s t : L.DefinableSet A α) :
((s ⊓ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) ∩ (t : Set (α → M)) :=
rfl
@[simp, norm_cast]
theorem coe_compl (s : L.DefinableSet A α) :
((sᶜ : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M))ᶜ :=
rfl
@[simp, norm_cast]
theorem coe_sdiff (s t : L.DefinableSet A α) :
((s \ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) \ (t : Set (α → M)) :=
rfl
@[simp, norm_cast]
lemma coe_himp (s t : L.DefinableSet A α) : ↑(s ⇨ t) = (s ⇨ t : Set (α → M)) := rfl
noncomputable instance instBooleanAlgebra : BooleanAlgebra (L.DefinableSet A α) :=
Function.Injective.booleanAlgebra (α := L.DefinableSet A α) _ Subtype.coe_injective
coe_sup coe_inf coe_top coe_bot coe_compl coe_sdiff coe_himp
end DefinableSet
end Language
end FirstOrder
|
ModelTheory\DirectLimit.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Gabin Kolly
-/
import Mathlib.Data.Fintype.Order
import Mathlib.Algebra.DirectLimit
import Mathlib.ModelTheory.Quotients
import Mathlib.ModelTheory.FinitelyGenerated
/-!
# Direct Limits of First-Order Structures
This file constructs the direct limit of a directed system of first-order embeddings.
## Main Definitions
- `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of
first-order embeddings between the structures indexed by `G`.
- `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps
from the components to another module that respect the directed system structure give rise to
a unique map out of the direct limit.
- `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of
isomorphic direct systems.
-/
universe v w w' u₁ u₂
open FirstOrder
namespace FirstOrder
namespace Language
open Structure Set
variable {L : Language} {ι : Type v} [Preorder ι]
variable {G : ι → Type w} [∀ i, L.Structure (G i)]
variable (f : ∀ i j, i ≤ j → G i ↪[L] G j)
namespace DirectedSystem
/-- A copy of `DirectedSystem.map_self` specialized to `L`-embeddings, as otherwise the
`fun i j h ↦ f i j h` can confuse the simplifier. -/
nonrec theorem map_self [DirectedSystem G fun i j h => f i j h] (i x h) : f i i h x = x :=
DirectedSystem.map_self (fun i j h => f i j h) i x h
/-- A copy of `DirectedSystem.map_map` specialized to `L`-embeddings, as otherwise the
`fun i j h ↦ f i j h` can confuse the simplifier. -/
nonrec theorem map_map [DirectedSystem G fun i j h => f i j h] {i j k} (hij hjk x) :
f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x :=
DirectedSystem.map_map (fun i j h => f i j h) hij hjk x
variable {G' : ℕ → Type w} [∀ i, L.Structure (G' i)] (f' : ∀ n : ℕ, G' n ↪[L] G' (n + 1))
/-- Given a chain of embeddings of structures indexed by `ℕ`, defines a `DirectedSystem` by
composing them. -/
def natLERec (m n : ℕ) (h : m ≤ n) : G' m ↪[L] G' n :=
Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _)
@[simp]
theorem coe_natLERec (m n : ℕ) (h : m ≤ n) :
(natLERec f' m n h : G' m → G' n) = Nat.leRecOn h (@fun k => f' k) := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h
ext x
induction' k with k ih
· -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [natLERec, Nat.leRecOn_self, Embedding.refl_apply, Nat.leRecOn_self]
· -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, ← natLERec,
Embedding.comp_apply, ih]
instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h :=
⟨fun i x _ => congr (congr rfl (Nat.leRecOn_self _)) rfl,
fun hij hjk => by simp [Nat.leRecOn_trans hij hjk]⟩
end DirectedSystem
-- Porting note: Instead of `Σ i, G i`, we use the alias `Language.Structure.Sigma`
-- which depends on `f`. This way, Lean can infer what `L` and `f` are in the `Setoid` instance.
-- Otherwise we have a "cannot find synthesization order" error. See the discussion at
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting
set_option linter.unusedVariables false in
/-- Alias for `Σ i, G i`. -/
@[nolint unusedArguments]
protected abbrev Structure.Sigma (f : ∀ i j, i ≤ j → G i ↪[L] G j) := Σ i, G i
-- Porting note: Setting up notation for `Language.Structure.Sigma`: add a little asterisk to `Σ`
local notation "Σˣ" => Structure.Sigma
/-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/
abbrev Structure.Sigma.mk (i : ι) (x : G i) : Σˣ f := ⟨i, x⟩
namespace DirectLimit
/-- Raises a family of elements in the `Σ`-type to the same level along the embeddings. -/
def unify {α : Type*} (x : α → Σˣ f) (i : ι) (h : i ∈ upperBounds (range (Sigma.fst ∘ x)))
(a : α) : G i :=
f (x a).1 i (h (mem_range_self a)) (x a).2
variable [DirectedSystem G fun i j h => f i j h]
@[simp]
theorem unify_sigma_mk_self {α : Type*} {i : ι} {x : α → G i} :
(unify f (fun a => .mk f i (x a)) i fun j ⟨a, hj⟩ =>
_root_.trans (le_of_eq hj.symm) (refl _)) = x := by
ext a
rw [unify]
apply DirectedSystem.map_self
theorem comp_unify {α : Type*} {x : α → Σˣ f} {i j : ι} (ij : i ≤ j)
(h : i ∈ upperBounds (range (Sigma.fst ∘ x))) :
f i j ij ∘ unify f x i h = unify f x j
fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by
ext a
simp [unify, DirectedSystem.map_map]
end DirectLimit
variable (G)
namespace DirectLimit
/-- The directed limit glues together the structures along the embeddings. -/
def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] : Setoid (Σˣ f) where
r := fun ⟨i, x⟩ ⟨j, y⟩ => ∃ (k : ι) (ik : i ≤ k) (jk : j ≤ k), f i k ik x = f j k jk y
iseqv :=
⟨fun ⟨i, x⟩ => ⟨i, refl i, refl i, rfl⟩, @fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, ik, jk, h⟩ =>
⟨k, jk, ik, h.symm⟩,
@fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, z⟩ ⟨ij, hiij, hjij, hij⟩ ⟨jk, hjjk, hkjk, hjk⟩ => by
obtain ⟨ijk, hijijk, hjkijk⟩ := directed_of (· ≤ ·) ij jk
refine ⟨ijk, le_trans hiij hijijk, le_trans hkjk hjkijk, ?_⟩
rw [← DirectedSystem.map_map, hij, DirectedSystem.map_map]
· symm
rw [← DirectedSystem.map_map, ← hjk, DirectedSystem.map_map]
assumption
assumption⟩
/-- The structure on the `Σ`-type which becomes the structure on the direct limit after quotienting.
-/
noncomputable def sigmaStructure [IsDirected ι (· ≤ ·)] [Nonempty ι] : L.Structure (Σˣ f) where
funMap F x :=
⟨_,
funMap F
(unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1))
(Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))⟩
RelMap R x :=
RelMap R
(unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1))
(Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))
end DirectLimit
/-- The direct limit of a directed system is the structures glued together along the embeddings. -/
def DirectLimit [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] :=
Quotient (DirectLimit.setoid G f)
attribute [local instance] DirectLimit.setoid
-- Porting note (#10754): Added local instance
attribute [local instance] DirectLimit.sigmaStructure
instance [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] [Inhabited ι]
[Inhabited (G default)] : Inhabited (DirectLimit G f) :=
⟨⟦⟨default, default⟩⟧⟩
namespace DirectLimit
variable [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h => f i j h]
theorem equiv_iff {x y : Σˣ f} {i : ι} (hx : x.1 ≤ i) (hy : y.1 ≤ i) :
x ≈ y ↔ (f x.1 i hx) x.2 = (f y.1 i hy) y.2 := by
cases x
cases y
refine ⟨fun xy => ?_, fun xy => ⟨i, hx, hy, xy⟩⟩
obtain ⟨j, _, _, h⟩ := xy
obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j
have h := congr_arg (f j k jk) h
apply (f i k ik).injective
rw [DirectedSystem.map_map, DirectedSystem.map_map] at *
exact h
theorem funMap_unify_equiv {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i j : ι)
(hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) :
Structure.Sigma.mk f i (funMap F (unify f x i hi)) ≈ .mk f j (funMap F (unify f x j hj)) := by
obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j
refine ⟨k, ik, jk, ?_⟩
rw [(f i k ik).map_fun, (f j k jk).map_fun, comp_unify, comp_unify]
theorem relMap_unify_equiv {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i j : ι)
(hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) :
RelMap R (unify f x i hi) = RelMap R (unify f x j hj) := by
obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j
rw [← (f i k ik).map_rel, comp_unify, ← (f j k jk).map_rel, comp_unify]
variable [Nonempty ι]
theorem exists_unify_eq {α : Type*} [Finite α] {x y : α → Σˣ f} (xy : x ≈ y) :
∃ (i : ι) (hx : i ∈ upperBounds (range (Sigma.fst ∘ x)))
(hy : i ∈ upperBounds (range (Sigma.fst ∘ y))), unify f x i hx = unify f y i hy := by
obtain ⟨i, hi⟩ := Finite.bddAbove_range (Sum.elim (fun a => (x a).1) fun a => (y a).1)
rw [Sum.elim_range, upperBounds_union] at hi
simp_rw [← Function.comp_apply (f := Sigma.fst)] at hi
exact ⟨i, hi.1, hi.2, funext fun a => (equiv_iff G f _ _).1 (xy a)⟩
theorem funMap_equiv_unify {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i : ι)
(hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) :
funMap F x ≈ .mk f _ (funMap F (unify f x i hi)) :=
funMap_unify_equiv G f F x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi
theorem relMap_equiv_unify {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i : ι)
(hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) :
RelMap R x = RelMap R (unify f x i hi) :=
relMap_unify_equiv G f R x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi
/-- The direct limit `setoid` respects the structure `sigmaStructure`, so quotienting by it
gives rise to a valid structure. -/
noncomputable instance prestructure : L.Prestructure (DirectLimit.setoid G f) where
toStructure := sigmaStructure G f
fun_equiv {n} {F} x y xy := by
obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy
refine
Setoid.trans (funMap_equiv_unify G f F x i hx)
(Setoid.trans ?_ (Setoid.symm (funMap_equiv_unify G f F y i hy)))
rw [h]
rel_equiv {n} {R} x y xy := by
obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy
refine _root_.trans (relMap_equiv_unify G f R x i hx)
(_root_.trans ?_ (symm (relMap_equiv_unify G f R y i hy)))
rw [h]
/-- The `L.Structure` on a direct limit of `L.Structure`s. -/
noncomputable instance instStructureDirectLimit : L.Structure (DirectLimit G f) :=
Language.quotientStructure
@[simp]
theorem funMap_quotient_mk'_sigma_mk' {n : ℕ} {F : L.Functions n} {i : ι} {x : Fin n → G i} :
funMap F (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = ⟦.mk f i (funMap F x)⟧ := by
simp only [funMap_quotient_mk', Quotient.eq]
obtain ⟨k, ik, jk⟩ :=
directed_of (· ≤ ·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i))
refine ⟨k, jk, ik, ?_⟩
simp only [Embedding.map_fun, comp_unify]
rfl
@[simp]
theorem relMap_quotient_mk'_sigma_mk' {n : ℕ} {R : L.Relations n} {i : ι} {x : Fin n → G i} :
RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = RelMap R x := by
rw [relMap_quotient_mk']
obtain ⟨k, _, _⟩ :=
directed_of (· ≤ ·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i))
rw [relMap_equiv_unify G f R (fun a => .mk f i (x a)) i]
rw [unify_sigma_mk_self]
theorem exists_quotient_mk'_sigma_mk'_eq {α : Type*} [Finite α] (x : α → DirectLimit G f) :
∃ (i : ι) (y : α → G i), x = fun a => ⟦.mk f i (y a)⟧ := by
obtain ⟨i, hi⟩ := Finite.bddAbove_range fun a => (x a).out.1
refine ⟨i, unify f (Quotient.out ∘ x) i hi, ?_⟩
ext a
rw [Quotient.eq_mk_iff_out, unify]
generalize_proofs r
change _ ≈ .mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd)
have : (.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) : Σˣ f).fst ≤ i :=
le_rfl
rw [equiv_iff G f (i := i) (hi _) this]
· simp only [DirectedSystem.map_self]
exact ⟨a, rfl⟩
variable (L ι)
/-- The canonical map from a component to the direct limit. -/
def of (i : ι) : G i ↪[L] DirectLimit G f where
toFun := fun a => ⟦.mk f i a⟧
inj' x y h := by
rw [Quotient.eq] at h
obtain ⟨j, h1, _, h3⟩ := h
exact (f i j h1).injective h3
map_fun' F x := by
simp only
rw [← funMap_quotient_mk'_sigma_mk']
rfl
map_rel' := by
intro n R x
change RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) ↔ _
simp only [relMap_quotient_mk'_sigma_mk']
variable {L ι G f}
@[simp]
theorem of_apply {i : ι} {x : G i} : of L ι G f i x = ⟦.mk f i x⟧ :=
rfl
-- Porting note: removed the `@[simp]`, it is not in simp-normal form, but the simp-normal version
-- of this theorem would not be useful.
theorem of_f {i j : ι} {hij : i ≤ j} {x : G i} : of L ι G f j (f i j hij x) = of L ι G f i x := by
rw [of_apply, of_apply, Quotient.eq]
refine Setoid.symm ⟨j, hij, refl j, ?_⟩
simp only [DirectedSystem.map_self]
/-- Every element of the direct limit corresponds to some element in
some component of the directed system. -/
theorem exists_of (z : DirectLimit G f) : ∃ i x, of L ι G f i x = z :=
⟨z.out.1, z.out.2, by simp⟩
@[elab_as_elim]
protected theorem inductionOn {C : DirectLimit G f → Prop} (z : DirectLimit G f)
(ih : ∀ i x, C (of L ι G f i x)) : C z :=
let ⟨i, x, h⟩ := exists_of z
h ▸ ih i x
theorem iSup_range_of_eq_top : ⨆ i, (of L ι G f i).toHom.range = ⊤ :=
eq_top_iff.2 (fun x _ ↦ DirectLimit.inductionOn x
(fun i _ ↦ le_iSup (fun i ↦ Hom.range (Embedding.toHom (of L ι G f i))) i (mem_range_self _)))
/-- Every finitely generated substructure of the direct limit corresponds to some
substructure in some component of the directed system. -/
theorem exists_fg_substructure_in_Sigma (S : L.Substructure (DirectLimit G f)) (S_fg : S.FG) :
∃ i, ∃ T : L.Substructure (G i), T.map (of L ι G f i).toHom = S := by
let ⟨A, A_closure⟩ := S_fg
let ⟨i, y, eq_y⟩ := exists_quotient_mk'_sigma_mk'_eq G _ (fun a : A ↦ a.1)
use i
use Substructure.closure L (range y)
rw [Substructure.map_closure]
simp only [Embedding.coe_toHom, of_apply]
rw [← image_univ, image_image, image_univ, ← eq_y,
Subtype.range_coe_subtype, Finset.setOf_mem, A_closure]
variable {P : Type u₁} [L.Structure P] (g : ∀ i, G i ↪[L] P)
variable (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
variable (L ι G f)
/-- The universal property of the direct limit: maps from the components to another module
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit. -/
def lift : DirectLimit G f ↪[L] P where
toFun :=
Quotient.lift (fun x : Σˣ f => (g x.1) x.2) fun x y xy => by
simp only
obtain ⟨i, hx, hy⟩ := directed_of (· ≤ ·) x.1 y.1
rw [← Hg x.1 i hx, ← Hg y.1 i hy]
exact congr_arg _ ((equiv_iff ..).1 xy)
inj' x y xy := by
rw [← Quotient.out_eq x, ← Quotient.out_eq y, Quotient.lift_mk, Quotient.lift_mk] at xy
obtain ⟨i, hx, hy⟩ := directed_of (· ≤ ·) x.out.1 y.out.1
rw [← Hg x.out.1 i hx, ← Hg y.out.1 i hy] at xy
rw [← Quotient.out_eq x, ← Quotient.out_eq y, Quotient.eq, equiv_iff G f hx hy]
exact (g i).injective xy
map_fun' F x := by
obtain ⟨i, y, rfl⟩ := exists_quotient_mk'_sigma_mk'_eq G f x
change _ = funMap F (Quotient.lift _ _ ∘ Quotient.mk _ ∘ Structure.Sigma.mk f i ∘ y)
rw [funMap_quotient_mk'_sigma_mk', ← Function.comp.assoc, Quotient.lift_comp_mk]
simp only [Quotient.lift_mk, Embedding.map_fun]
rfl
map_rel' R x := by
obtain ⟨i, y, rfl⟩ := exists_quotient_mk'_sigma_mk'_eq G f x
change RelMap R (Quotient.lift _ _ ∘ Quotient.mk _ ∘ Structure.Sigma.mk f i ∘ y) ↔ _
rw [relMap_quotient_mk'_sigma_mk' G f, ← (g i).map_rel R y, ← Function.comp.assoc,
Quotient.lift_comp_mk]
rfl
variable {L ι G f}
@[simp]
theorem lift_quotient_mk'_sigma_mk' {i} (x : G i) : lift L ι G f g Hg ⟦.mk f i x⟧ = (g i) x := by
change (lift L ι G f g Hg).toFun ⟦.mk f i x⟧ = _
simp only [lift, Quotient.lift_mk]
theorem lift_of {i} (x : G i) : lift L ι G f g Hg (of L ι G f i x) = g i x := by simp
theorem lift_unique (F : DirectLimit G f ↪[L] P) (x) :
F x =
lift L ι G f (fun i => F.comp <| of L ι G f i)
(fun i j hij x => by rw [F.comp_apply, F.comp_apply, of_f]) x :=
DirectLimit.inductionOn x fun i x => by rw [lift_of]; rfl
lemma range_lift : (lift L ι G f g Hg).toHom.range = ⨆ i, (g i).toHom.range := by
simp_rw [Hom.range_eq_map]
rw [← iSup_range_of_eq_top, Substructure.map_iSup]
simp_rw [Hom.range_eq_map, Substructure.map_map]
rfl
variable (L ι G f)
variable (G' : ι → Type w') [∀ i, L.Structure (G' i)]
variable (f' : ∀ i j, i ≤ j → G' i ↪[L] G' j)
variable (g : ∀ i, G i ≃[L] G' i)
variable (H_commuting : ∀ i j hij x, g j (f i j hij x) = f' i j hij (g i x))
variable [DirectedSystem G' fun i j h => f' i j h]
/-- The isomorphism between limits of isomorphic systems. -/
noncomputable def equiv_lift : DirectLimit G f ≃[L] DirectLimit G' f' := by
let U i : G i ↪[L] DirectLimit G' f' := (of L _ G' f' i).comp (g i).toEmbedding
let F : DirectLimit G f ↪[L] DirectLimit G' f' := lift L _ G f U <| by
intro _ _ _ _
simp only [U, Embedding.comp_apply, Equiv.coe_toEmbedding, H_commuting, of_f]
have surj_f : Function.Surjective F := by
intro x
rcases x with ⟨i, pre_x⟩
use of L _ G f i ((g i).symm pre_x)
simp only [F, U, lift_of, Embedding.comp_apply, Equiv.coe_toEmbedding, Equiv.apply_symm_apply]
rfl
exact ⟨Equiv.ofBijective F ⟨F.injective, surj_f⟩, F.map_fun', F.map_rel'⟩
theorem equiv_lift_of {i : ι} (x : G i) :
equiv_lift L ι G f G' f' g H_commuting (of L ι G f i x) = of L ι G' f' i (g i x) := rfl
variable {L ι G f}
/-- The direct limit of countably many countably generated structures is countably generated. -/
theorem cg {ι : Type*} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι]
{G : ι → Type w} [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j)
(h : ∀ i, Structure.CG L (G i)) [DirectedSystem G fun i j h => f i j h] :
Structure.CG L (DirectLimit G f) := by
refine ⟨⟨⋃ i, DirectLimit.of L ι G f i '' Classical.choose (h i).out, ?_, ?_⟩⟩
· exact Set.countable_iUnion fun i => Set.Countable.image (Classical.choose_spec (h i).out).1 _
· rw [eq_top_iff, Substructure.closure_unionᵢ]
simp_rw [← Embedding.coe_toHom, Substructure.closure_image]
rw [le_iSup_iff]
intro S hS x _
let out := Quotient.out (s := DirectLimit.setoid G f)
refine hS (out x).1 ⟨(out x).2, ?_, ?_⟩
· rw [(Classical.choose_spec (h (out x).1).out).2]
trivial
· simp only [out, Embedding.coe_toHom, DirectLimit.of_apply, Sigma.eta, Quotient.out_eq]
instance cg' {ι : Type*} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι]
{G : ι → Type w} [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j)
[h : ∀ i, Structure.CG L (G i)] [DirectedSystem G fun i j h => f i j h] :
Structure.CG L (DirectLimit G f) :=
cg f h
end DirectLimit
section Substructure
variable [Nonempty ι] [IsDirected ι (· ≤ ·)]
variable {M N : Type*} [L.Structure M] [L.Structure N] (S : ι →o L.Substructure M)
instance : DirectedSystem (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) where
map_self' := fun _ _ _ ↦ rfl
map_map' := fun _ _ _ ↦ rfl
namespace DirectLimit
/-- The map from a direct limit of a system of substructures of `M` into `M`. -/
def liftInclusion :
DirectLimit (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) ↪[L] M :=
DirectLimit.lift L ι (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h))
(fun _ ↦ Substructure.subtype _) (fun _ _ _ _ ↦ rfl)
theorem liftInclusion_of {i : ι} (x : S i) :
(liftInclusion S) (of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i x)
= Substructure.subtype (S i) x := rfl
lemma rangeLiftInclusion : (liftInclusion S).toHom.range = ⨆ i, S i := by
simp_rw [liftInclusion, range_lift, Substructure.range_subtype]
/-- The isomorphism between a direct limit of a system of substructures and their union. -/
noncomputable def Equiv_iSup :
DirectLimit (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) ≃[L]
(iSup S : L.Substructure M) := by
have liftInclusion_in_sup : ∀ x, liftInclusion S x ∈ (⨆ i, S i) := by
simp only [← rangeLiftInclusion, Hom.mem_range, Embedding.coe_toHom]
intro x; use x
let F := Embedding.codRestrict (⨆ i, S i) _ liftInclusion_in_sup
have F_surj : Function.Surjective F := by
rintro ⟨m, hm⟩
rw [← rangeLiftInclusion, Hom.mem_range] at hm
rcases hm with ⟨a, _⟩; use a
simpa only [F, Embedding.codRestrict_apply', Subtype.mk.injEq]
exact ⟨Equiv.ofBijective F ⟨F.injective, F_surj⟩, F.map_fun', F.map_rel'⟩
theorem Equiv_isup_of_apply {i : ι} (x : S i) :
Equiv_iSup S (of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i x)
= Substructure.inclusion (le_iSup _ _) x := rfl
theorem Equiv_isup_symm_inclusion_apply {i : ι} (x : S i) :
(Equiv_iSup S).symm (Substructure.inclusion (le_iSup _ _) x)
= of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i x := by
apply (Equiv_iSup S).injective
simp only [Equiv.apply_symm_apply]
rfl
@[simp]
theorem Equiv_isup_symm_inclusion (i : ι) :
(Equiv_iSup S).symm.toEmbedding.comp (Substructure.inclusion (le_iSup _ _))
= of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i := by
ext x; exact Equiv_isup_symm_inclusion_apply _ x
end DirectLimit
end Substructure
end Language
end FirstOrder
|
ModelTheory\ElementaryMaps.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.Fintype.Basic
import Mathlib.ModelTheory.Substructures
/-!
# Elementary Maps Between First-Order Structures
## Main Definitions
- A `FirstOrder.Language.ElementaryEmbedding` is an embedding that commutes with the
realizations of formulas.
- The `FirstOrder.Language.elementaryDiagram` of a structure is the set of all sentences with
parameters that the structure satisfies.
- `FirstOrder.Language.ElementaryEmbedding.ofModelsElementaryDiagram` is the canonical
elementary embedding of any structure into a model of its elementary diagram.
## Main Results
- The Tarski-Vaught Test for embeddings: `FirstOrder.Language.Embedding.isElementary_of_exists`
gives a simple criterion for an embedding to be elementary.
-/
open FirstOrder
namespace FirstOrder
namespace Language
open Structure
variable (L : Language) (M : Type*) (N : Type*) {P : Type*} {Q : Type*}
variable [L.Structure M] [L.Structure N] [L.Structure P] [L.Structure Q]
/-- An elementary embedding of first-order structures is an embedding that commutes with the
realizations of formulas. -/
structure ElementaryEmbedding where
toFun : M → N
-- Porting note:
-- The autoparam here used to be `obviously`. We would like to replace it with `aesop`
-- but that isn't currently sufficient.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases
-- If that can be improved, we should change this to `by aesop` and remove the proofs below.
map_formula' :
∀ ⦃n⦄ (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (toFun ∘ x) ↔ φ.Realize x := by
intros; trivial
@[inherit_doc FirstOrder.Language.ElementaryEmbedding]
scoped[FirstOrder] notation:25 A " ↪ₑ[" L "] " B => FirstOrder.Language.ElementaryEmbedding L A B
variable {L} {M} {N}
namespace ElementaryEmbedding
attribute [coe] toFun
instance instFunLike : FunLike (M ↪ₑ[L] N) M N where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
simp only [ElementaryEmbedding.mk.injEq]
ext x
exact Function.funext_iff.1 h x
instance : CoeFun (M ↪ₑ[L] N) fun _ => M → N :=
DFunLike.hasCoeToFun
@[simp]
theorem map_boundedFormula (f : M ↪ₑ[L] N) {α : Type*} {n : ℕ} (φ : L.BoundedFormula α n)
(v : α → M) (xs : Fin n → M) : φ.Realize (f ∘ v) (f ∘ xs) ↔ φ.Realize v xs := by
classical
rw [← BoundedFormula.realize_restrictFreeVar Set.Subset.rfl, Set.inclusion_eq_id, iff_eq_eq]
have h :=
f.map_formula' ((φ.restrictFreeVar id).toFormula.relabel (Fintype.equivFin _))
(Sum.elim (v ∘ (↑)) xs ∘ (Fintype.equivFin _).symm)
simp only [Formula.realize_relabel, BoundedFormula.realize_toFormula, iff_eq_eq] at h
rw [← Function.comp.assoc _ _ (Fintype.equivFin _).symm,
Function.comp.assoc _ (Fintype.equivFin _).symm (Fintype.equivFin _),
_root_.Equiv.symm_comp_self, Function.comp_id, Function.comp.assoc, Sum.elim_comp_inl,
Function.comp.assoc _ _ Sum.inr, Sum.elim_comp_inr, ← Function.comp.assoc] at h
refine h.trans ?_
erw [Function.comp.assoc _ _ (Fintype.equivFin _), _root_.Equiv.symm_comp_self,
Function.comp_id, Sum.elim_comp_inl, Sum.elim_comp_inr (v ∘ Subtype.val) xs,
← Set.inclusion_eq_id (s := (BoundedFormula.freeVarFinset φ : Set α)) Set.Subset.rfl,
BoundedFormula.realize_restrictFreeVar Set.Subset.rfl]
@[simp]
theorem map_formula (f : M ↪ₑ[L] N) {α : Type*} (φ : L.Formula α) (x : α → M) :
φ.Realize (f ∘ x) ↔ φ.Realize x := by
rw [Formula.Realize, Formula.Realize, ← f.map_boundedFormula, Unique.eq_default (f ∘ default)]
theorem map_sentence (f : M ↪ₑ[L] N) (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ := by
rw [Sentence.Realize, Sentence.Realize, ← f.map_formula, Unique.eq_default (f ∘ default)]
theorem theory_model_iff (f : M ↪ₑ[L] N) (T : L.Theory) : M ⊨ T ↔ N ⊨ T := by
simp only [Theory.model_iff, f.map_sentence]
theorem elementarilyEquivalent (f : M ↪ₑ[L] N) : M ≅[L] N :=
elementarilyEquivalent_iff.2 f.map_sentence
@[simp]
theorem injective (φ : M ↪ₑ[L] N) : Function.Injective φ := by
intro x y
have h :=
φ.map_formula ((var 0).equal (var 1) : L.Formula (Fin 2)) fun i => if i = 0 then x else y
rw [Formula.realize_equal, Formula.realize_equal] at h
simp only [Nat.one_ne_zero, Term.realize, Fin.one_eq_zero_iff, if_true, eq_self_iff_true,
Function.comp_apply, if_false] at h
exact h.1
instance embeddingLike : EmbeddingLike (M ↪ₑ[L] N) M N :=
{ show FunLike (M ↪ₑ[L] N) M N from inferInstance with injective' := injective }
@[simp]
theorem map_fun (φ : M ↪ₑ[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) := by
have h := φ.map_formula (Formula.graph f) (Fin.cons (funMap f x) x)
rw [Formula.realize_graph, Fin.comp_cons, Formula.realize_graph] at h
rw [eq_comm, h]
@[simp]
theorem map_rel (φ : M ↪ₑ[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
haveI h := φ.map_formula (r.formula var) x
h
instance strongHomClass : StrongHomClass L (M ↪ₑ[L] N) M N where
map_fun := map_fun
map_rel := map_rel
@[simp]
theorem map_constants (φ : M ↪ₑ[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
/-- An elementary embedding is also a first-order embedding. -/
def toEmbedding (f : M ↪ₑ[L] N) : M ↪[L] N where
toFun := f
inj' := f.injective
map_fun' {_} f x := by aesop
map_rel' {_} R x := by aesop
/-- An elementary embedding is also a first-order homomorphism. -/
def toHom (f : M ↪ₑ[L] N) : M →[L] N where
toFun := f
map_fun' {_} f x := by aesop
map_rel' {_} R x := by aesop
@[simp]
theorem toEmbedding_toHom (f : M ↪ₑ[L] N) : f.toEmbedding.toHom = f.toHom :=
rfl
@[simp]
theorem coe_toHom {f : M ↪ₑ[L] N} : (f.toHom : M → N) = (f : M → N) :=
rfl
@[simp]
theorem coe_toEmbedding (f : M ↪ₑ[L] N) : (f.toEmbedding : M → N) = (f : M → N) :=
rfl
theorem coe_injective : @Function.Injective (M ↪ₑ[L] N) (M → N) (↑) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : M ↪ₑ[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
variable (L) (M)
/-- The identity elementary embedding from a structure to itself -/
@[refl]
def refl : M ↪ₑ[L] M where toFun := id
variable {L} {M}
instance : Inhabited (M ↪ₑ[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x :=
rfl
/-- Composition of elementary embeddings -/
@[trans]
def comp (hnp : N ↪ₑ[L] P) (hmn : M ↪ₑ[L] N) : M ↪ₑ[L] P where
toFun := hnp ∘ hmn
map_formula' n φ x := by
cases' hnp with _ hhnp
cases' hmn with _ hhmn
erw [hhnp, hhmn]
@[simp]
theorem comp_apply (g : N ↪ₑ[L] P) (f : M ↪ₑ[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of elementary embeddings is associative. -/
theorem comp_assoc (f : M ↪ₑ[L] N) (g : N ↪ₑ[L] P) (h : P ↪ₑ[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
end ElementaryEmbedding
variable (L) (M)
/-- The elementary diagram of an `L`-structure is the set of all sentences with parameters it
satisfies. -/
abbrev elementaryDiagram : L[[M]].Theory :=
L[[M]].completeTheory M
/-- The canonical elementary embedding of an `L`-structure into any model of its elementary diagram
-/
@[simps]
def ElementaryEmbedding.ofModelsElementaryDiagram (N : Type*) [L.Structure N] [L[[M]].Structure N]
[(lhomWithConstants L M).IsExpansionOn N] [N ⊨ L.elementaryDiagram M] : M ↪ₑ[L] N :=
⟨((↑) : L[[M]].Constants → N) ∘ Sum.inr, fun n φ x => by
refine
_root_.trans ?_
((realize_iff_of_model_completeTheory M N
(((L.lhomWithConstants M).onBoundedFormula φ).subst
(Constants.term ∘ Sum.inr ∘ x)).alls).trans
?_)
· simp_rw [Sentence.Realize, BoundedFormula.realize_alls, BoundedFormula.realize_subst,
LHom.realize_onBoundedFormula, Formula.Realize, Unique.forall_iff, Function.comp,
Term.realize_constants]
· simp_rw [Sentence.Realize, BoundedFormula.realize_alls, BoundedFormula.realize_subst,
LHom.realize_onBoundedFormula, Formula.Realize, Unique.forall_iff]
rfl⟩
variable {L M}
namespace Embedding
/-- The **Tarski-Vaught test** for elementarity of an embedding. -/
theorem isElementary_of_exists (f : M ↪[L] N)
(htv :
∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by
suffices h : ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M),
φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs by
intro n φ x
exact φ.realize_relabel_sum_inr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sum_inr)
refine fun n φ => φ.recOn ?_ ?_ ?_ ?_ ?_
· exact fun {_} _ => Iff.rfl
· intros
simp [BoundedFormula.Realize, ← Sum.comp_elim, Embedding.realize_term]
· intros
simp only [BoundedFormula.Realize, ← Sum.comp_elim, realize_term]
erw [map_rel f]
· intro _ _ _ ih1 ih2 _
simp [ih1, ih2]
· intro n φ ih xs
simp only [BoundedFormula.realize_all]
refine ⟨fun h a => ?_, ?_⟩
· rw [← ih, Fin.comp_snoc]
exact h (f a)
· contrapose!
rintro ⟨a, ha⟩
obtain ⟨b, hb⟩ := htv n φ.not xs a (by
rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)]
exact ha)
refine ⟨b, fun h => hb (Eq.mp ?_ ((ih _).2 h))⟩
rw [Unique.eq_default (f ∘ default), Fin.comp_snoc]
/-- Bundles an embedding satisfying the Tarski-Vaught test as an elementary embedding. -/
@[simps]
def toElementaryEmbedding (f : M ↪[L] N)
(htv :
∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N),
φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) →
∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) :
M ↪ₑ[L] N :=
⟨f, fun _ => f.isElementary_of_exists htv⟩
end Embedding
namespace Equiv
/-- A first-order equivalence is also an elementary embedding. -/
def toElementaryEmbedding (f : M ≃[L] N) : M ↪ₑ[L] N where
toFun := f
map_formula' n φ x := by aesop
@[simp]
theorem toElementaryEmbedding_toEmbedding (f : M ≃[L] N) :
f.toElementaryEmbedding.toEmbedding = f.toEmbedding :=
rfl
@[simp]
theorem coe_toElementaryEmbedding (f : M ≃[L] N) :
(f.toElementaryEmbedding : M → N) = (f : M → N) :=
rfl
end Equiv
@[simp]
theorem realize_term_substructure {α : Type*} {S : L.Substructure M} (v : α → S) (t : L.Term α) :
t.realize ((↑) ∘ v) = (↑(t.realize v) : M) :=
S.subtype.realize_term t
end Language
end FirstOrder
|
ModelTheory\ElementarySubstructures.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.ElementaryMaps
/-!
# Elementary Substructures
## Main Definitions
- A `FirstOrder.Language.ElementarySubstructure` is a substructure where the realization of each
formula agrees with the realization in the larger model.
## Main Results
- The Tarski-Vaught Test for substructures:
`FirstOrder.Language.Substructure.isElementary_of_exists` gives a simple criterion for a
substructure to be elementary.
-/
open FirstOrder
namespace FirstOrder
namespace Language
open Structure
variable {L : Language} {M : Type*} {N : Type*} {P : Type*} {Q : Type*}
variable [L.Structure M] [L.Structure N] [L.Structure P] [L.Structure Q]
/-- A substructure is elementary when every formula applied to a tuple in the substructure
agrees with its value in the overall structure. -/
def Substructure.IsElementary (S : L.Substructure M) : Prop :=
∀ ⦃n⦄ (φ : L.Formula (Fin n)) (x : Fin n → S), φ.Realize (((↑) : _ → M) ∘ x) ↔ φ.Realize x
variable (L M)
/-- An elementary substructure is one in which every formula applied to a tuple in the substructure
agrees with its value in the overall structure. -/
structure ElementarySubstructure where
toSubstructure : L.Substructure M
isElementary' : toSubstructure.IsElementary
variable {L M}
namespace ElementarySubstructure
attribute [coe] toSubstructure
instance instCoe : Coe (L.ElementarySubstructure M) (L.Substructure M) :=
⟨ElementarySubstructure.toSubstructure⟩
instance instSetLike : SetLike (L.ElementarySubstructure M) M :=
⟨fun x => x.toSubstructure.carrier, fun ⟨⟨s, hs1⟩, hs2⟩ ⟨⟨t, ht1⟩, _⟩ _ => by
congr⟩
instance inducedStructure (S : L.ElementarySubstructure M) : L.Structure S :=
Substructure.inducedStructure
@[simp]
theorem isElementary (S : L.ElementarySubstructure M) : (S : L.Substructure M).IsElementary :=
S.isElementary'
/-- The natural embedding of an `L.Substructure` of `M` into `M`. -/
def subtype (S : L.ElementarySubstructure M) : S ↪ₑ[L] M where
toFun := (↑)
map_formula' := S.isElementary
@[simp]
theorem coeSubtype {S : L.ElementarySubstructure M} : ⇑S.subtype = ((↑) : S → M) :=
rfl
/-- The substructure `M` of the structure `M` is elementary. -/
instance instTop : Top (L.ElementarySubstructure M) :=
⟨⟨⊤, fun _ _ _ => Substructure.realize_formula_top.symm⟩⟩
instance instInhabited : Inhabited (L.ElementarySubstructure M) :=
⟨⊤⟩
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : L.ElementarySubstructure M) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : L.ElementarySubstructure M) : Set M) = Set.univ :=
rfl
@[simp]
theorem realize_sentence (S : L.ElementarySubstructure M) (φ : L.Sentence) : S ⊨ φ ↔ M ⊨ φ :=
S.subtype.map_sentence φ
@[simp]
theorem theory_model_iff (S : L.ElementarySubstructure M) (T : L.Theory) : S ⊨ T ↔ M ⊨ T := by
simp only [Theory.model_iff, realize_sentence]
instance theory_model {T : L.Theory} [h : M ⊨ T] {S : L.ElementarySubstructure M} : S ⊨ T :=
(theory_model_iff S T).2 h
instance instNonempty [Nonempty M] {S : L.ElementarySubstructure M} : Nonempty S :=
(model_nonemptyTheory_iff L).1 inferInstance
theorem elementarilyEquivalent (S : L.ElementarySubstructure M) : S ≅[L] M :=
S.subtype.elementarilyEquivalent
end ElementarySubstructure
namespace Substructure
/-- The Tarski-Vaught test for elementarity of a substructure. -/
theorem isElementary_of_exists (S : L.Substructure M)
(htv :
∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → S) (a : M),
φ.Realize default (Fin.snoc ((↑) ∘ x) a : _ → M) →
∃ b : S, φ.Realize default (Fin.snoc ((↑) ∘ x) b : _ → M)) :
S.IsElementary := fun _ => S.subtype.isElementary_of_exists htv
/-- Bundles a substructure satisfying the Tarski-Vaught test as an elementary substructure. -/
@[simps]
def toElementarySubstructure (S : L.Substructure M)
(htv :
∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → S) (a : M),
φ.Realize default (Fin.snoc ((↑) ∘ x) a : _ → M) →
∃ b : S, φ.Realize default (Fin.snoc ((↑) ∘ x) b : _ → M)) :
L.ElementarySubstructure M :=
⟨S, S.isElementary_of_exists htv⟩
end Substructure
end Language
end FirstOrder
|
ModelTheory\Encoding.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Computability.Encoding
import Mathlib.Logic.Small.List
import Mathlib.ModelTheory.Syntax
import Mathlib.SetTheory.Cardinal.Ordinal
/-!
# Encodings and Cardinality of First-Order Syntax
## Main Definitions
- `FirstOrder.Language.Term.encoding` encodes terms as lists.
- `FirstOrder.Language.BoundedFormula.encoding` encodes bounded formulas as lists.
## Main Results
- `FirstOrder.Language.Term.card_le` shows that the number of terms in `L.Term α` is at most
`max ℵ₀ # (α ⊕ Σ i, L.Functions i)`.
- `FirstOrder.Language.BoundedFormula.card_le` shows that the number of bounded formulas in
`Σ n, L.BoundedFormula α n` is at most
`max ℵ₀ (Cardinal.lift.{max u v} #α + Cardinal.lift.{u'} L.card)`.
## TODO
- `Primcodable` instances for terms and formulas, based on the `encoding`s
- Computability facts about term and formula operations, to set up a computability approach to
incompleteness
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'}
open FirstOrder Cardinal
open Computability List Structure Cardinal Fin
namespace Term
/-- Encodes a term as a list of variables and function symbols. -/
def listEncode : L.Term α → List (α ⊕ (Σi, L.Functions i))
| var i => [Sum.inl i]
| func f ts =>
Sum.inr (⟨_, f⟩ : Σi, L.Functions i)::(List.finRange _).bind fun i => (ts i).listEncode
/-- Decodes a list of variables and function symbols as a list of terms. -/
def listDecode : List (α ⊕ (Σi, L.Functions i)) → List (L.Term α)
| [] => []
| Sum.inl a::l => (var a)::listDecode l
| Sum.inr ⟨n, f⟩::l =>
if h : n ≤ (listDecode l).length then
(func f (fun i => (listDecode l)[i])) :: (listDecode l).drop n
else []
theorem listDecode_encode_list (l : List (L.Term α)) :
listDecode (l.bind listEncode) = l := by
suffices h : ∀ (t : L.Term α) (l : List (α ⊕ (Σi, L.Functions i))),
listDecode (t.listEncode ++ l) = t::listDecode l by
induction' l with t l lih
· rfl
· rw [bind_cons, h t (l.bind listEncode), lih]
intro t
induction' t with a n f ts ih <;> intro l
· rw [listEncode, singleton_append, listDecode]
· rw [listEncode, cons_append, listDecode]
have h : listDecode (((finRange n).bind fun i : Fin n => (ts i).listEncode) ++ l) =
(finRange n).map ts ++ listDecode l := by
induction' finRange n with i l' l'ih
· rfl
· rw [bind_cons, List.append_assoc, ih, map_cons, l'ih, cons_append]
simp only [h, length_append, length_map, length_finRange, le_add_iff_nonneg_right,
_root_.zero_le, ↓reduceDIte, getElem_fin, cons.injEq, func.injEq, heq_eq_eq, true_and]
refine ⟨funext (fun i => ?_), ?_⟩
· rw [List.getElem_append, List.getElem_map, List.getElem_finRange]
simp only [length_map, length_finRange, i.2]
· simp only [length_map, length_finRange, drop_left']
/-- An encoding of terms as lists. -/
@[simps]
protected def encoding : Encoding (L.Term α) where
Γ := α ⊕ (Σi, L.Functions i)
encode := listEncode
decode l := (listDecode l).head?.join
decode_encode t := by
have h := listDecode_encode_list [t]
rw [bind_singleton] at h
simp only [Option.join, h, head?_cons, Option.pure_def, Option.bind_eq_bind, Option.some_bind,
id_eq]
theorem listEncode_injective :
Function.Injective (listEncode : L.Term α → List (α ⊕ (Σi, L.Functions i))) :=
Term.encoding.encode_injective
theorem card_le : #(L.Term α) ≤ max ℵ₀ #(α ⊕ (Σi, L.Functions i)) :=
lift_le.1 (_root_.trans Term.encoding.card_le_card_list (lift_le.2 (mk_list_le_max _)))
theorem card_sigma : #(Σn, L.Term (α ⊕ (Fin n))) = max ℵ₀ #(α ⊕ (Σi, L.Functions i)) := by
refine le_antisymm ?_ ?_
· rw [mk_sigma]
refine (sum_le_iSup_lift _).trans ?_
rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff,
ciSup_le_iff' (bddAbove_range _)]
· refine ⟨le_max_left _ _, fun i => card_le.trans ?_⟩
refine max_le (le_max_left _ _) ?_
rw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add,
add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast]
exact add_le_add_right (nat_lt_aleph0 _).le _
· rw [← one_le_iff_ne_zero]
refine _root_.trans ?_ (le_ciSup (bddAbove_range _) 1)
rw [one_le_iff_ne_zero, mk_ne_zero_iff]
exact ⟨var (Sum.inr 0)⟩
· rw [max_le_iff, ← infinite_iff]
refine ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr i)⟩) fun i j ij => ?_, ?_⟩
· cases ij
rfl
· rw [Cardinal.le_def]
refine ⟨⟨Sum.elim (fun i => ⟨0, var (Sum.inl i)⟩)
fun F => ⟨1, func F.2 fun _ => var (Sum.inr 0)⟩, ?_⟩⟩
rintro (a | a) (b | b) h
· simp only [Sum.elim_inl, Sigma.mk.inj_iff, heq_eq_eq, var.injEq, Sum.inl.injEq, true_and]
at h
rw [h]
· simp only [Sum.elim_inl, Sum.elim_inr, Sigma.mk.inj_iff, false_and] at h
· simp only [Sum.elim_inr, Sum.elim_inl, Sigma.mk.inj_iff, false_and] at h
· simp only [Sum.elim_inr, Sigma.mk.inj_iff, heq_eq_eq, func.injEq, true_and] at h
rw [Sigma.ext_iff.2 ⟨h.1, h.2.1⟩]
instance [Encodable α] [Encodable (Σi, L.Functions i)] : Encodable (L.Term α) :=
Encodable.ofLeftInjection listEncode (fun l => (listDecode l).head?.join) fun t => by
simp only
rw [← bind_singleton listEncode, listDecode_encode_list]
simp only [Option.join, head?_cons, Option.pure_def, Option.bind_eq_bind, Option.some_bind,
id_eq]
instance [h1 : Countable α] [h2 : Countable (Σl, L.Functions l)] : Countable (L.Term α) := by
refine mk_le_aleph0_iff.1 (card_le.trans (max_le_iff.2 ?_))
simp only [le_refl, mk_sum, add_le_aleph0, lift_le_aleph0, true_and_iff]
exact ⟨Cardinal.mk_le_aleph0, Cardinal.mk_le_aleph0⟩
instance small [Small.{u} α] : Small.{u} (L.Term α) :=
small_of_injective listEncode_injective
end Term
namespace BoundedFormula
/-- Encodes a bounded formula as a list of symbols. -/
def listEncode : ∀ {n : ℕ},
L.BoundedFormula α n → List ((Σk, L.Term (α ⊕ Fin k)) ⊕ ((Σn, L.Relations n) ⊕ ℕ))
| n, falsum => [Sum.inr (Sum.inr (n + 2))]
| _, equal t₁ t₂ => [Sum.inl ⟨_, t₁⟩, Sum.inl ⟨_, t₂⟩]
| n, rel R ts => [Sum.inr (Sum.inl ⟨_, R⟩), Sum.inr (Sum.inr n)] ++
(List.finRange _).map fun i => Sum.inl ⟨n, ts i⟩
| _, imp φ₁ φ₂ => (Sum.inr (Sum.inr 0)::φ₁.listEncode) ++ φ₂.listEncode
| _, all φ => Sum.inr (Sum.inr 1)::φ.listEncode
/-- Applies the `forall` quantifier to an element of `(Σ n, L.BoundedFormula α n)`,
or returns `default` if not possible. -/
def sigmaAll : (Σn, L.BoundedFormula α n) → Σn, L.BoundedFormula α n
| ⟨n + 1, φ⟩ => ⟨n, φ.all⟩
| _ => default
@[simp]
lemma sigmaAll_apply {n} {φ : L.BoundedFormula α (n + 1)} :
sigmaAll ⟨n + 1, φ⟩ = ⟨n, φ.all⟩ := rfl
/-- Applies `imp` to two elements of `(Σ n, L.BoundedFormula α n)`,
or returns `default` if not possible. -/
def sigmaImp : (Σn, L.BoundedFormula α n) → (Σn, L.BoundedFormula α n) → Σn, L.BoundedFormula α n
| ⟨m, φ⟩, ⟨n, ψ⟩ => if h : m = n then ⟨m, φ.imp (Eq.mp (by rw [h]) ψ)⟩ else default
#adaptation_note
/--
`List.drop_sizeOf_le` is deprecated.
See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Why.20is.20.60Mathlib.2EModelTheory.2EEncoding.60.20using.20.60SizeOf.2EsizeOf.60.3F
for discussion about adapting this code.
-/
set_option linter.deprecated false in
/-- Decodes a list of symbols as a list of formulas. -/
@[simp]
lemma sigmaImp_apply {n} {φ ψ : L.BoundedFormula α n} :
sigmaImp ⟨n, φ⟩ ⟨n, ψ⟩ = ⟨n, φ.imp ψ⟩ := by
simp only [sigmaImp, ↓reduceDIte, eq_mp_eq_cast, cast_eq]
/-- Decodes a list of symbols as a list of formulas. -/
def listDecode :
List ((Σk, L.Term (α ⊕ Fin k)) ⊕ ((Σn, L.Relations n) ⊕ ℕ)) → List (Σn, L.BoundedFormula α n)
| Sum.inr (Sum.inr (n + 2))::l => ⟨n, falsum⟩::(listDecode l)
| Sum.inl ⟨n₁, t₁⟩::Sum.inl ⟨n₂, t₂⟩::l =>
(if h : n₁ = n₂ then ⟨n₁, equal t₁ (Eq.mp (by rw [h]) t₂)⟩ else default)::(listDecode l)
| Sum.inr (Sum.inl ⟨n, R⟩)::Sum.inr (Sum.inr k)::l => (
if h : ∀ i : Fin n, ((l.map Sum.getLeft?).get? i).join.isSome then
if h' : ∀ i, (Option.get _ (h i)).1 = k then
⟨k, BoundedFormula.rel R fun i => Eq.mp (by rw [h' i]) (Option.get _ (h i)).2⟩
else default
else default)::(listDecode (l.drop n))
| Sum.inr (Sum.inr 0)::l => if h : 2 ≤ (listDecode l).length
then (sigmaImp (listDecode l)[0] (listDecode l)[1])::(drop 2 (listDecode l))
else []
| Sum.inr (Sum.inr 1)::l => if h : 1 ≤ (listDecode l).length
then (sigmaAll (listDecode l)[0])::(drop 1 (listDecode l))
else []
| _ => []
termination_by l => l.length
@[simp]
theorem listDecode_encode_list (l : List (Σn, L.BoundedFormula α n)) :
listDecode (l.bind (fun φ => φ.2.listEncode)) = l := by
suffices h : ∀ (φ : Σn, L.BoundedFormula α n)
(l' : List ((Σk, L.Term (α ⊕ Fin k)) ⊕ ((Σn, L.Relations n) ⊕ ℕ))),
(listDecode (listEncode φ.2 ++ l')) = φ::(listDecode l') by
induction' l with φ l ih
· rw [List.bind_nil]
simp [listDecode]
· rw [bind_cons, h φ _, ih]
rintro ⟨n, φ⟩
induction' φ with _ _ _ _ φ_n φ_l φ_R ts _ _ _ ih1 ih2 _ _ ih <;> intro l
· rw [listEncode, singleton_append, listDecode]
· rw [listEncode, cons_append, cons_append, listDecode, dif_pos]
· simp only [eq_mp_eq_cast, cast_eq, eq_self_iff_true, heq_iff_eq, and_self_iff, nil_append]
· simp only [eq_self_iff_true, heq_iff_eq, and_self_iff]
· rw [listEncode, cons_append, cons_append, singleton_append, cons_append, listDecode]
have h : ∀ i : Fin φ_l, ((List.map Sum.getLeft? (List.map (fun i : Fin φ_l =>
Sum.inl (⟨(⟨φ_n, rel φ_R ts⟩ : Σn, L.BoundedFormula α n).fst, ts i⟩ :
Σn, L.Term (α ⊕ (Fin n)))) (finRange φ_l) ++ l)).get? ↑i).join = some ⟨_, ts i⟩ := by
intro i
simp only [Option.join, map_append, map_map, Option.bind_eq_some, id, exists_eq_right,
get?_eq_some, length_append, length_map, length_finRange]
refine ⟨lt_of_lt_of_le i.2 le_self_add, ?_⟩
rw [get_eq_getElem, getElem_append, getElem_map]
· simp only [getElem_finRange, Fin.eta, Function.comp_apply, Sum.getLeft?]
· simp only [length_map, length_finRange, is_lt]
rw [dif_pos]
swap
· exact fun i => Option.isSome_iff_exists.2 ⟨⟨_, ts i⟩, h i⟩
rw [dif_pos]
swap
· intro i
obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i)
rw [h2]
simp only [Option.join, eq_mp_eq_cast, cons.injEq, Sigma.mk.inj_iff, heq_eq_eq, rel.injEq,
true_and]
refine ⟨funext fun i => ?_, ?_⟩
· obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i)
rw [cast_eq_iff_heq]
exact (Sigma.ext_iff.1 ((Sigma.eta (Option.get _ h1)).trans h2)).2
rw [List.drop_append_eq_append_drop, length_map, length_finRange, Nat.sub_self, drop,
drop_eq_nil_of_le, nil_append]
rw [length_map, length_finRange]
· simp only [] at *
rw [listEncode, List.append_assoc, cons_append, listDecode]
simp only [ih1, ih2, length_cons, le_add_iff_nonneg_left, _root_.zero_le, ↓reduceDIte,
getElem_cons_zero, getElem_cons_succ, sigmaImp_apply, drop_succ_cons, drop_zero]
· simp only [] at *
rw [listEncode, cons_append, listDecode]
simp only [ih, length_cons, le_add_iff_nonneg_left, _root_.zero_le, ↓reduceDIte,
getElem_cons_zero, sigmaAll_apply, drop_succ_cons, drop_zero]
/-- An encoding of bounded formulas as lists. -/
@[simps]
protected def encoding : Encoding (Σn, L.BoundedFormula α n) where
Γ := (Σk, L.Term (α ⊕ Fin k)) ⊕ ((Σn, L.Relations n) ⊕ ℕ)
encode φ := φ.2.listEncode
decode l := (listDecode l)[0]?
decode_encode φ := by
have h := listDecode_encode_list [φ]
rw [bind_singleton] at h
simp only
rw [h]
rfl
theorem listEncode_sigma_injective :
Function.Injective fun φ : Σn, L.BoundedFormula α n => φ.2.listEncode :=
BoundedFormula.encoding.encode_injective
theorem card_le : #(Σn, L.BoundedFormula α n) ≤
max ℵ₀ (Cardinal.lift.{max u v} #α + Cardinal.lift.{u'} L.card) := by
refine lift_le.1 (BoundedFormula.encoding.card_le_card_list.trans ?_)
rw [encoding_Γ, mk_list_eq_max_mk_aleph0, lift_max, lift_aleph0, lift_max, lift_aleph0,
max_le_iff]
refine ⟨?_, le_max_left _ _⟩
rw [mk_sum, Term.card_sigma, mk_sum, ← add_eq_max le_rfl, mk_sum, mk_nat]
simp only [lift_add, lift_lift, lift_aleph0]
rw [← add_assoc, add_comm, ← add_assoc, ← add_assoc, aleph0_add_aleph0, add_assoc,
add_eq_max le_rfl, add_assoc, card, Symbols, mk_sum, lift_add, lift_lift, lift_lift]
end BoundedFormula
end Language
end FirstOrder
|
ModelTheory\FinitelyGenerated.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Substructures
/-!
# Finitely Generated First-Order Structures
This file defines what it means for a first-order (sub)structure to be finitely or countably
generated, similarly to other finitely-generated objects in the algebra library.
## Main Definitions
- `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated.
- `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated.
- `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated.
- `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated.
## TODO
Develop a more unified definition of finite generation using the theory of closure operators, or use
this definition of finite generation to define the others.
-/
open FirstOrder Set
namespace FirstOrder
namespace Language
open Structure
variable {L : Language} {M : Type*} [L.Structure M]
namespace Substructure
/-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/
def FG (N : L.Substructure M) : Prop :=
∃ S : Finset M, closure L S = N
theorem fg_def {N : L.Substructure M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ closure L S = N :=
⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by
rintro ⟨t', h, rfl⟩
rcases Finite.exists_finset_coe h with ⟨t, rfl⟩
exact ⟨t, rfl⟩⟩
theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} :
N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), closure L (range s) = N := by
rw [fg_def]
constructor
· rintro ⟨S, Sfin, hS⟩
obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding
exact ⟨n, f, hS⟩
· rintro ⟨n, s, hs⟩
exact ⟨range s, finite_range s, hs⟩
theorem fg_bot : (⊥ : L.Substructure M).FG :=
⟨∅, by rw [Finset.coe_empty, closure_empty]⟩
theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) :=
⟨hs.toFinset, by rw [hs.coe_toFinset]⟩
theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) :=
fg_closure (finite_singleton x)
theorem FG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG :=
let ⟨t₁, ht₁⟩ := fg_def.1 hN₁
let ⟨t₂, ht₂⟩ := fg_def.1 hN₂
fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩
theorem FG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.FG) :
(s.map f).FG :=
let ⟨t, ht⟩ := fg_def.1 hs
fg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩
theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M}
(hs : (s.map f.toHom).FG) : s.FG := by
rcases hs with ⟨t, h⟩
rw [fg_def]
refine ⟨f ⁻¹' t, t.finite_toSet.preimage f.injective.injOn, ?_⟩
have hf : Function.Injective f.toHom := f.injective
refine map_injective_of_injective hf ?_
rw [← h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset]
intro x hx
have h' := subset_closure (L := L) hx
rw [h] at h'
exact Hom.map_le_range h'
/-- A substructure of `M` is countably generated if it is the closure of a countable subset of `M`.
-/
def CG (N : L.Substructure M) : Prop :=
∃ S : Set M, S.Countable ∧ closure L S = N
theorem cg_def {N : L.Substructure M} : N.CG ↔ ∃ S : Set M, S.Countable ∧ closure L S = N :=
Iff.refl _
theorem FG.cg {N : L.Substructure M} (h : N.FG) : N.CG := by
obtain ⟨s, hf, rfl⟩ := fg_def.1 h
exact ⟨s, hf.countable, rfl⟩
theorem cg_iff_empty_or_exists_nat_generating_family {N : L.Substructure M} :
N.CG ↔ N = (∅ : Set M) ∨ ∃ s : ℕ → M, closure L (range s) = N := by
rw [cg_def]
constructor
· rintro ⟨S, Scount, hS⟩
rcases eq_empty_or_nonempty (N : Set M) with h | h
· exact Or.intro_left _ h
obtain ⟨f, h'⟩ :=
(Scount.union (Set.countable_singleton h.some)).exists_eq_range
(singleton_nonempty h.some).inr
refine Or.intro_right _ ⟨f, ?_⟩
rw [← h', closure_union, hS, sup_eq_left, closure_le]
exact singleton_subset_iff.2 h.some_mem
· intro h
cases' h with h h
· refine ⟨∅, countable_empty, closure_eq_of_le (empty_subset _) ?_⟩
rw [← SetLike.coe_subset_coe, h]
exact empty_subset _
· obtain ⟨f, rfl⟩ := h
exact ⟨range f, countable_range _, rfl⟩
theorem cg_bot : (⊥ : L.Substructure M).CG :=
fg_bot.cg
theorem cg_closure {s : Set M} (hs : s.Countable) : CG (closure L s) :=
⟨s, hs, rfl⟩
theorem cg_closure_singleton (x : M) : CG (closure L ({x} : Set M)) :=
(fg_closure_singleton x).cg
theorem CG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.CG) (hN₂ : N₂.CG) : (N₁ ⊔ N₂).CG :=
let ⟨t₁, ht₁⟩ := cg_def.1 hN₁
let ⟨t₂, ht₂⟩ := cg_def.1 hN₂
cg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩
theorem CG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.CG) :
(s.map f).CG :=
let ⟨t, ht⟩ := cg_def.1 hs
cg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩
theorem CG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M}
(hs : (s.map f.toHom).CG) : s.CG := by
rcases hs with ⟨t, h1, h2⟩
rw [cg_def]
refine ⟨f ⁻¹' t, h1.preimage f.injective, ?_⟩
have hf : Function.Injective f.toHom := f.injective
refine map_injective_of_injective hf ?_
rw [← h2, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset]
intro x hx
have h' := subset_closure (L := L) hx
rw [h2] at h'
exact Hom.map_le_range h'
theorem cg_iff_countable [Countable (Σl, L.Functions l)] {s : L.Substructure M} :
s.CG ↔ Countable s := by
refine ⟨?_, fun h => ⟨s, h.to_set, s.closure_eq⟩⟩
rintro ⟨s, h, rfl⟩
exact h.substructure_closure L
end Substructure
open Substructure
namespace Structure
variable (L) (M)
/-- A structure is finitely generated if it is the closure of a finite subset. -/
class FG : Prop where
out : (⊤ : L.Substructure M).FG
/-- A structure is countably generated if it is the closure of a countable subset. -/
class CG : Prop where
out : (⊤ : L.Substructure M).CG
variable {L M}
theorem fg_def : FG L M ↔ (⊤ : L.Substructure M).FG :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
/-- An equivalent expression of `Structure.FG` in terms of `Set.Finite` instead of `Finset`. -/
theorem fg_iff : FG L M ↔ ∃ S : Set M, S.Finite ∧ closure L S = (⊤ : L.Substructure M) := by
rw [fg_def, Substructure.fg_def]
theorem FG.range {N : Type*} [L.Structure N] (h : FG L M) (f : M →[L] N) : f.range.FG := by
rw [Hom.range_eq_map]
exact (fg_def.1 h).map f
theorem FG.map_of_surjective {N : Type*} [L.Structure N] (h : FG L M) (f : M →[L] N)
(hs : Function.Surjective f) : FG L N := by
rw [← Hom.range_eq_top] at hs
rw [fg_def, ← hs]
exact h.range f
theorem cg_def : CG L M ↔ (⊤ : L.Substructure M).CG :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
/-- An equivalent expression of `Structure.cg`. -/
theorem cg_iff : CG L M ↔ ∃ S : Set M, S.Countable ∧ closure L S = (⊤ : L.Substructure M) := by
rw [cg_def, Substructure.cg_def]
theorem CG.range {N : Type*} [L.Structure N] (h : CG L M) (f : M →[L] N) : f.range.CG := by
rw [Hom.range_eq_map]
exact (cg_def.1 h).map f
theorem CG.map_of_surjective {N : Type*} [L.Structure N] (h : CG L M) (f : M →[L] N)
(hs : Function.Surjective f) : CG L N := by
rw [← Hom.range_eq_top] at hs
rw [cg_def, ← hs]
exact h.range f
theorem cg_iff_countable [Countable (Σl, L.Functions l)] : CG L M ↔ Countable M := by
rw [cg_def, Substructure.cg_iff_countable, topEquiv.toEquiv.countable_iff]
theorem FG.cg (h : FG L M) : CG L M :=
cg_def.2 (fg_def.1 h).cg
instance (priority := 100) cg_of_fg [h : FG L M] : CG L M :=
h.cg
end Structure
theorem Equiv.fg_iff {N : Type*} [L.Structure N] (f : M ≃[L] N) :
Structure.FG L M ↔ Structure.FG L N :=
⟨fun h => h.map_of_surjective f.toHom f.toEquiv.surjective, fun h =>
h.map_of_surjective f.symm.toHom f.toEquiv.symm.surjective⟩
theorem Substructure.fg_iff_structure_fg (S : L.Substructure M) : S.FG ↔ Structure.FG L S := by
rw [Structure.fg_def]
refine ⟨fun h => FG.of_map_embedding S.subtype ?_, fun h => ?_⟩
· rw [← Hom.range_eq_map, range_subtype]
exact h
· have h := h.map S.subtype.toHom
rw [← Hom.range_eq_map, range_subtype] at h
exact h
theorem Equiv.cg_iff {N : Type*} [L.Structure N] (f : M ≃[L] N) :
Structure.CG L M ↔ Structure.CG L N :=
⟨fun h => h.map_of_surjective f.toHom f.toEquiv.surjective, fun h =>
h.map_of_surjective f.symm.toHom f.toEquiv.symm.surjective⟩
theorem Substructure.cg_iff_structure_cg (S : L.Substructure M) : S.CG ↔ Structure.CG L S := by
rw [Structure.cg_def]
refine ⟨fun h => CG.of_map_embedding S.subtype ?_, fun h => ?_⟩
· rw [← Hom.range_eq_map, range_subtype]
exact h
· have h := h.map S.subtype.toHom
rw [← Hom.range_eq_map, range_subtype] at h
exact h
end Language
end FirstOrder
|
ModelTheory\Fraisse.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.FinitelyGenerated
import Mathlib.ModelTheory.DirectLimit
import Mathlib.ModelTheory.Bundled
import Mathlib.Algebra.Order.Archimedean.Basic
/-!
# Fraïssé Classes and Fraïssé Limits
This file pertains to the ages of countable first-order structures. The age of a structure is the
class of all finitely-generated structures that embed into it.
Of particular interest are Fraïssé classes, which are exactly the ages of countable
ultrahomogeneous structures. To each is associated a unique (up to nonunique isomorphism)
Fraïssé limit - the countable ultrahomogeneous structure with that age.
## Main Definitions
- `FirstOrder.Language.age` is the class of finitely-generated structures that embed into a
particular structure.
- A class `K` is `FirstOrder.Language.Hereditary` when all finitely-generated
structures that embed into structures in `K` are also in `K`.
- A class `K` has `FirstOrder.Language.JointEmbedding` when for every `M`, `N` in
`K`, there is another structure in `K` into which both `M` and `N` embed.
- A class `K` has `FirstOrder.Language.Amalgamation` when for any pair of embeddings
of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into
a fourth structure in `K` such that the resulting square of embeddings commutes.
- `FirstOrder.Language.IsFraisse` indicates that a class is nonempty, isomorphism-invariant,
essentially countable, and satisfies the hereditary, joint embedding, and amalgamation properties.
- `FirstOrder.Language.IsFraisseLimit` indicates that a structure is a Fraïssé limit for a given
class.
## Main Results
- We show that the age of any structure is isomorphism-invariant and satisfies the hereditary and
joint-embedding properties.
- `FirstOrder.Language.age.countable_quotient` shows that the age of any countable structure is
essentially countable.
- `FirstOrder.Language.exists_countable_is_age_of_iff` gives necessary and sufficient conditions
for a class to be the age of a countable structure in a language with countably many functions.
## Implementation Notes
- Classes of structures are formalized with `Set (Bundled L.Structure)`.
- Some results pertain to countable limit structures, others to countably-generated limit
structures. In the case of a language with countably many function symbols, these are equivalent.
## References
- [W. Hodges, *A Shorter Model Theory*][Hodges97]
- [K. Tent, M. Ziegler, *A Course in Model Theory*][Tent_Ziegler]
## TODO
- Show existence and uniqueness of Fraïssé limits
-/
universe u v w w'
open scoped FirstOrder
open Set CategoryTheory
namespace FirstOrder
namespace Language
open Structure Substructure
variable (L : Language.{u, v})
/-! ### The Age of a Structure and Fraïssé Classes-/
/-- The age of a structure `M` is the class of finitely-generated structures that embed into it. -/
def age (M : Type w) [L.Structure M] : Set (Bundled.{w} L.Structure) :=
{N | Structure.FG L N ∧ Nonempty (N ↪[L] M)}
variable {L}
variable (K : Set (Bundled.{w} L.Structure))
/-- A class `K` has the hereditary property when all finitely-generated structures that embed into
structures in `K` are also in `K`. -/
def Hereditary : Prop :=
∀ M : Bundled.{w} L.Structure, M ∈ K → L.age M ⊆ K
/-- A class `K` has the joint embedding property when for every `M`, `N` in `K`, there is another
structure in `K` into which both `M` and `N` embed. -/
def JointEmbedding : Prop :=
DirectedOn (fun M N : Bundled.{w} L.Structure => Nonempty (M ↪[L] N)) K
/-- A class `K` has the amalgamation property when for any pair of embeddings of a structure `M` in
`K` into other structures in `K`, those two structures can be embedded into a fourth structure in
`K` such that the resulting square of embeddings commutes. -/
def Amalgamation : Prop :=
∀ (M N P : Bundled.{w} L.Structure) (MN : M ↪[L] N) (MP : M ↪[L] P),
M ∈ K → N ∈ K → P ∈ K → ∃ (Q : Bundled.{w} L.Structure) (NQ : N ↪[L] Q) (PQ : P ↪[L] Q),
Q ∈ K ∧ NQ.comp MN = PQ.comp MP
/-- A Fraïssé class is a nonempty, isomorphism-invariant, essentially countable class of structures
satisfying the hereditary, joint embedding, and amalgamation properties. -/
class IsFraisse : Prop where
is_nonempty : K.Nonempty
FG : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M
is_equiv_invariant : ∀ M N : Bundled.{w} L.Structure, Nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)
is_essentially_countable : (Quotient.mk' '' K).Countable
hereditary : Hereditary K
jointEmbedding : JointEmbedding K
amalgamation : Amalgamation K
variable {K} (L) (M : Type w) [Structure L M]
theorem age.is_equiv_invariant (N P : Bundled.{w} L.Structure) (h : Nonempty (N ≃[L] P)) :
N ∈ L.age M ↔ P ∈ L.age M :=
and_congr h.some.fg_iff
⟨Nonempty.map fun x => Embedding.comp x h.some.symm.toEmbedding,
Nonempty.map fun x => Embedding.comp x h.some.toEmbedding⟩
variable {L} {M} {N : Type w} [Structure L N]
theorem Embedding.age_subset_age (MN : M ↪[L] N) : L.age M ⊆ L.age N := fun _ =>
And.imp_right (Nonempty.map MN.comp)
theorem Equiv.age_eq_age (MN : M ≃[L] N) : L.age M = L.age N :=
le_antisymm MN.toEmbedding.age_subset_age MN.symm.toEmbedding.age_subset_age
theorem Structure.FG.mem_age_of_equiv {M N : Bundled L.Structure} (h : Structure.FG L M)
(MN : Nonempty (M ≃[L] N)) : N ∈ L.age M :=
⟨MN.some.fg_iff.1 h, ⟨MN.some.symm.toEmbedding⟩⟩
theorem Hereditary.is_equiv_invariant_of_fg (h : Hereditary K)
(fg : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) (M N : Bundled.{w} L.Structure)
(hn : Nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K :=
⟨fun MK => h M MK ((fg M MK).mem_age_of_equiv hn),
fun NK => h N NK ((fg N NK).mem_age_of_equiv ⟨hn.some.symm⟩)⟩
variable (M)
theorem age.nonempty : (L.age M).Nonempty :=
⟨Bundled.of (Substructure.closure L (∅ : Set M)),
(fg_iff_structure_fg _).1 (fg_closure Set.finite_empty), ⟨Substructure.subtype _⟩⟩
theorem age.hereditary : Hereditary (L.age M) := fun _ hN _ hP => hN.2.some.age_subset_age hP
theorem age.jointEmbedding : JointEmbedding (L.age M) := fun _ hN _ hP =>
⟨Bundled.of (↥(hN.2.some.toHom.range ⊔ hP.2.some.toHom.range)),
⟨(fg_iff_structure_fg _).1 ((hN.1.range hN.2.some.toHom).sup (hP.1.range hP.2.some.toHom)),
⟨Substructure.subtype _⟩⟩,
⟨Embedding.comp (inclusion le_sup_left) hN.2.some.equivRange.toEmbedding⟩,
⟨Embedding.comp (inclusion le_sup_right) hP.2.some.equivRange.toEmbedding⟩⟩
/-- The age of a countable structure is essentially countable (has countably many isomorphism
classes). -/
theorem age.countable_quotient [h : Countable M] : (Quotient.mk' '' L.age M).Countable := by
classical
refine (congr_arg _ (Set.ext <| Quotient.forall.2 fun N => ?_)).mp
(countable_range fun s : Finset M => ⟦⟨closure L (s : Set M), inferInstance⟩⟧)
constructor
· rintro ⟨s, hs⟩
use Bundled.of (closure L (s : Set M))
exact ⟨⟨(fg_iff_structure_fg _).1 (fg_closure s.finite_toSet), ⟨Substructure.subtype _⟩⟩, hs⟩
· simp only [mem_range, Quotient.eq]
rintro ⟨P, ⟨⟨s, hs⟩, ⟨PM⟩⟩, hP2⟩
have : P ≈ N := by apply Quotient.eq'.mp; rw [hP2]; rfl -- Porting note: added
refine ⟨s.image PM, Setoid.trans (b := P) ?_ this⟩
rw [← Embedding.coe_toHom, Finset.coe_image, closure_image PM.toHom, hs, ← Hom.range_eq_map]
exact ⟨PM.equivRange.symm⟩
/-- The age of a direct limit of structures is the union of the ages of the structures. -/
-- @[simp] -- Porting note: cannot simplify itself
theorem age_directLimit {ι : Type w} [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι]
(G : ι → Type max w w') [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j)
[DirectedSystem G fun i j h => f i j h] : L.age (DirectLimit G f) = ⋃ i : ι, L.age (G i) := by
classical
ext M
simp only [mem_iUnion]
constructor
· rintro ⟨Mfg, ⟨e⟩⟩
obtain ⟨s, hs⟩ := Mfg.range e.toHom
let out := @Quotient.out _ (DirectLimit.setoid G f)
obtain ⟨i, hi⟩ := Finset.exists_le (s.image (Sigma.fst ∘ out))
have e' := (DirectLimit.of L ι G f i).equivRange.symm.toEmbedding
refine ⟨i, Mfg, ⟨e'.comp ((Substructure.inclusion ?_).comp e.equivRange.toEmbedding)⟩⟩
rw [← hs, closure_le]
intro x hx
refine ⟨f (out x).1 i (hi (out x).1 (Finset.mem_image_of_mem _ hx)) (out x).2, ?_⟩
rw [Embedding.coe_toHom, DirectLimit.of_apply, @Quotient.mk_eq_iff_out _ (_),
DirectLimit.equiv_iff G f _ (hi (out x).1 (Finset.mem_image_of_mem _ hx)),
DirectedSystem.map_self]
rfl
· rintro ⟨i, Mfg, ⟨e⟩⟩
exact ⟨Mfg, ⟨Embedding.comp (DirectLimit.of L ι G f i) e⟩⟩
/-- Sufficient conditions for a class to be the age of a countably-generated structure. -/
theorem exists_cg_is_age_of (hn : K.Nonempty)
(h : ∀ M N : Bundled.{w} L.Structure, Nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K))
(hc : (Quotient.mk' '' K).Countable)
(fg : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) (hp : Hereditary K)
(jep : JointEmbedding K) : ∃ M : Bundled.{w} L.Structure, Structure.CG L M ∧ L.age M = K := by
obtain ⟨F, hF⟩ := hc.exists_eq_range (hn.image _)
simp only [Set.ext_iff, Quotient.forall, mem_image, mem_range, Quotient.eq'] at hF
simp_rw [Quotient.eq_mk_iff_out] at hF
have hF' : ∀ n : ℕ, (F n).out ∈ K := by
intro n
obtain ⟨P, hP1, hP2⟩ := (hF (F n).out).2 ⟨n, Setoid.refl _⟩
-- Porting note: fix hP2 because `Quotient.out (Quotient.mk' x) ≈ a` was not simplified
-- to `x ≈ a` in hF
replace hP2 := Setoid.trans (Setoid.symm (Quotient.mk_out P)) hP2
exact (h _ _ hP2).1 hP1
choose P hPK hP hFP using fun (N : K) (n : ℕ) => jep N N.2 (F (n + 1)).out (hF' _)
let G : ℕ → K := @Nat.rec (fun _ => K) ⟨(F 0).out, hF' 0⟩ fun n N => ⟨P N n, hPK N n⟩
-- Poting note: was
-- let f : ∀ i j, i ≤ j → G i ↪[L] G j := DirectedSystem.natLeRec fun n => (hP _ n).some
let f : ∀ (i j : ℕ), i ≤ j → (G i).val ↪[L] (G j).val := by
refine DirectedSystem.natLERec (G' := fun i => (G i).val) (L := L) ?_
dsimp only [G]
exact fun n => (hP _ n).some
have : DirectedSystem (fun n ↦ (G n).val) fun i j h ↦ ↑(f i j h) := by
dsimp [f, G]; infer_instance
refine ⟨Bundled.of (@DirectLimit L _ _ (fun n ↦ (G n).val) _ f _ _), ?_, ?_⟩
· exact DirectLimit.cg _ (fun n => (fg _ (G n).2).cg)
· refine (age_directLimit (fun n ↦ (G n).val) f).trans
(subset_antisymm (iUnion_subset fun n N hN => hp (G n).val (G n).2 hN) fun N KN => ?_)
have : Quotient.out (Quotient.mk' N) ≈ N := Quotient.eq_mk_iff_out.mp rfl
obtain ⟨n, ⟨e⟩⟩ := (hF N).1 ⟨N, KN, this⟩
refine mem_iUnion_of_mem n ⟨fg _ KN, ⟨Embedding.comp ?_ e.symm.toEmbedding⟩⟩
cases' n with n
· dsimp [G]; exact Embedding.refl _ _
· dsimp [G]; exact (hFP _ n).some
theorem exists_countable_is_age_of_iff [Countable (Σ l, L.Functions l)] :
(∃ M : Bundled.{w} L.Structure, Countable M ∧ L.age M = K) ↔
K.Nonempty ∧ (∀ M N : Bundled.{w} L.Structure, Nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) ∧
(Quotient.mk' '' K).Countable ∧ (∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) ∧
Hereditary K ∧ JointEmbedding K := by
constructor
· rintro ⟨M, h1, h2, rfl⟩
refine ⟨age.nonempty M, age.is_equiv_invariant L M, age.countable_quotient M, fun N hN => hN.1,
age.hereditary M, age.jointEmbedding M⟩
· rintro ⟨Kn, eqinv, cq, hfg, hp, jep⟩
obtain ⟨M, hM, rfl⟩ := exists_cg_is_age_of Kn eqinv cq hfg hp jep
exact ⟨M, Structure.cg_iff_countable.1 hM, rfl⟩
variable (L)
/-- A structure `M` is ultrahomogeneous if every embedding of a finitely generated substructure
into `M` extends to an automorphism of `M`. -/
def IsUltrahomogeneous : Prop :=
∀ (S : L.Substructure M) (_ : S.FG) (f : S ↪[L] M),
∃ g : M ≃[L] M, f = g.toEmbedding.comp S.subtype
variable {L} (K)
/-- A structure `M` is a Fraïssé limit for a class `K` if it is countably generated,
ultrahomogeneous, and has age `K`. -/
structure IsFraisseLimit [Countable (Σ l, L.Functions l)] [Countable M] : Prop where
protected ultrahomogeneous : IsUltrahomogeneous L M
protected age : L.age M = K
variable {M}
theorem IsUltrahomogeneous.amalgamation_age (h : L.IsUltrahomogeneous M) :
Amalgamation (L.age M) := by
rintro N P Q NP NQ ⟨Nfg, ⟨-⟩⟩ ⟨Pfg, ⟨PM⟩⟩ ⟨Qfg, ⟨QM⟩⟩
obtain ⟨g, hg⟩ := h (PM.comp NP).toHom.range (Nfg.range _)
((QM.comp NQ).comp (PM.comp NP).equivRange.symm.toEmbedding)
let s := (g.toHom.comp PM.toHom).range ⊔ QM.toHom.range
refine ⟨Bundled.of s,
Embedding.comp (Substructure.inclusion le_sup_left)
(g.toEmbedding.comp PM).equivRange.toEmbedding,
Embedding.comp (Substructure.inclusion le_sup_right) QM.equivRange.toEmbedding,
⟨(fg_iff_structure_fg _).1 (FG.sup (Pfg.range _) (Qfg.range _)), ⟨Substructure.subtype _⟩⟩, ?_⟩
ext n
apply Subtype.ext
have hgn := (Embedding.ext_iff.1 hg) ((PM.comp NP).equivRange n)
simp only [Embedding.comp_apply, Equiv.coe_toEmbedding, Equiv.symm_apply_apply,
Substructure.coeSubtype, Embedding.equivRange_apply] at hgn
simp only [Embedding.comp_apply, Equiv.coe_toEmbedding]
erw [Substructure.coe_inclusion, Substructure.coe_inclusion]
simp only [Embedding.comp_apply, Equiv.coe_toEmbedding, Set.coe_inclusion,
Embedding.equivRange_apply, hgn]
-- This used to be `simp only [...]` before leanprover/lean4#2644
erw [Embedding.comp_apply, Equiv.coe_toEmbedding,
Embedding.equivRange_apply]
simp
theorem IsUltrahomogeneous.age_isFraisse [Countable M] (h : L.IsUltrahomogeneous M) :
IsFraisse (L.age M) :=
⟨age.nonempty M, fun _ hN => hN.1, age.is_equiv_invariant L M, age.countable_quotient M,
age.hereditary M, age.jointEmbedding M, h.amalgamation_age⟩
namespace IsFraisseLimit
/-- If a class has a Fraïssé limit, it must be Fraïssé. -/
theorem isFraisse [Countable (Σ l, L.Functions l)] [Countable M] (h : IsFraisseLimit K M) :
IsFraisse K :=
(congr rfl h.age).mp h.ultrahomogeneous.age_isFraisse
end IsFraisseLimit
end Language
end FirstOrder
|
ModelTheory\Graph.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Satisfiability
import Mathlib.Combinatorics.SimpleGraph.Basic
/-!
# First-Order Structures in Graph Theory
This file defines first-order languages, structures, and theories in graph theory.
## Main Definitions
- `FirstOrder.Language.graph` is the language consisting of a single relation representing
adjacency.
- `SimpleGraph.structure` is the first-order structure corresponding to a given simple graph.
- `FirstOrder.Language.Theory.simpleGraph` is the theory of simple graphs.
- `FirstOrder.Language.simpleGraphOfStructure` gives the simple graph corresponding to a model
of the theory of simple graphs.
-/
universe u v w w'
namespace FirstOrder
namespace Language
open FirstOrder
open Structure
variable {L : Language.{u, v}} {α : Type w} {V : Type w'} {n : ℕ}
/-! ### Simple Graphs -/
/-- The language consisting of a single relation representing adjacency. -/
protected def graph : Language :=
Language.mk₂ Empty Empty Empty Empty Unit
/-- The symbol representing the adjacency relation. -/
def adj : Language.graph.Relations 2 :=
Unit.unit
/-- Any simple graph can be thought of as a structure in the language of graphs. -/
def _root_.SimpleGraph.structure (G : SimpleGraph V) : Language.graph.Structure V :=
Structure.mk₂ Empty.elim Empty.elim Empty.elim Empty.elim fun _ => G.Adj
namespace graph
instance instIsRelational : IsRelational Language.graph :=
Language.isRelational_mk₂
instance instSubsingleton : Subsingleton (Language.graph.Relations n) :=
Language.subsingleton_mk₂_relations
end graph
/-- The theory of simple graphs. -/
protected def Theory.simpleGraph : Language.graph.Theory :=
{adj.irreflexive, adj.symmetric}
@[simp]
theorem Theory.simpleGraph_model_iff [Language.graph.Structure V] :
V ⊨ Theory.simpleGraph ↔
(Irreflexive fun x y : V => RelMap adj ![x, y]) ∧
Symmetric fun x y : V => RelMap adj ![x, y] := by
simp [Theory.simpleGraph]
instance simpleGraph_model (G : SimpleGraph V) :
@Theory.Model _ V G.structure Theory.simpleGraph := by
simp only [@Theory.simpleGraph_model_iff _ G.structure, relMap_apply₂]
exact ⟨G.loopless, G.symm⟩
variable (V)
/-- Any model of the theory of simple graphs represents a simple graph. -/
@[simps]
def simpleGraphOfStructure [Language.graph.Structure V] [V ⊨ Theory.simpleGraph] :
SimpleGraph V where
Adj x y := RelMap adj ![x, y]
symm :=
Relations.realize_symmetric.1
(Theory.realize_sentence_of_mem Theory.simpleGraph
(Set.mem_insert_of_mem _ (Set.mem_singleton _)))
loopless :=
Relations.realize_irreflexive.1
(Theory.realize_sentence_of_mem Theory.simpleGraph (Set.mem_insert _ _))
variable {V}
@[simp]
theorem _root_.SimpleGraph.simpleGraphOfStructure (G : SimpleGraph V) :
@simpleGraphOfStructure V G.structure _ = G := by
ext
rfl
@[simp]
theorem structure_simpleGraphOfStructure [S : Language.graph.Structure V] [V ⊨ Theory.simpleGraph] :
(simpleGraphOfStructure V).structure = S := by
ext
case funMap n f xs =>
exact (IsRelational.empty_functions n).elim f
case RelMap n r xs =>
rw [iff_eq_eq]
cases' n with n
· exact r.elim
· cases' n with n
· exact r.elim
· cases' n with n
· cases r
change RelMap adj ![xs 0, xs 1] = _
refine congr rfl (funext ?_)
simp [Fin.forall_fin_two]
· exact r.elim
theorem Theory.simpleGraph_isSatisfiable : Theory.IsSatisfiable Theory.simpleGraph :=
⟨@Theory.ModelType.of _ _ Unit (SimpleGraph.structure ⊥) _ _⟩
end Language
end FirstOrder
|
ModelTheory\LanguageMap.lean | /-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.ModelTheory.Basic
/-!
# Language Maps
Maps between first-order languages in the style of the
[Flypitch project](https://flypitch.github.io/), as well as several important maps between
structures.
## Main Definitions
- A `FirstOrder.Language.LHom`, denoted `L →ᴸ L'`, is a map between languages, sending the symbols
of one to symbols of the same kind and arity in the other.
- A `FirstOrder.Language.LEquiv`, denoted `L ≃ᴸ L'`, is an invertible language homomorphism.
- `FirstOrder.Language.withConstants` is defined so that if `M` is an `L.Structure` and
`A : Set M`, `L.withConstants A`, denoted `L[[A]]`, is a language which adds constant symbols for
elements of `A` to `L`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v u' v' w w'
namespace FirstOrder
namespace Language
open Structure Cardinal
open Cardinal
variable (L : Language.{u, v}) (L' : Language.{u', v'}) {M : Type w} [L.Structure M]
/-- A language homomorphism maps the symbols of one language to symbols of another. -/
structure LHom where
onFunction : ∀ ⦃n⦄, L.Functions n → L'.Functions n
onRelation : ∀ ⦃n⦄, L.Relations n → L'.Relations n
@[inherit_doc FirstOrder.Language.LHom]
infixl:10 " →ᴸ " => LHom
-- \^L
variable {L L'}
namespace LHom
/-- Defines a map between languages defined with `Language.mk₂`. -/
protected def mk₂ {c f₁ f₂ : Type u} {r₁ r₂ : Type v} (φ₀ : c → L'.Constants)
(φ₁ : f₁ → L'.Functions 1) (φ₂ : f₂ → L'.Functions 2) (φ₁' : r₁ → L'.Relations 1)
(φ₂' : r₂ → L'.Relations 2) : Language.mk₂ c f₁ f₂ r₁ r₂ →ᴸ L' :=
⟨fun n =>
Nat.casesOn n φ₀ fun n => Nat.casesOn n φ₁ fun n => Nat.casesOn n φ₂ fun _ => PEmpty.elim,
fun n =>
Nat.casesOn n PEmpty.elim fun n =>
Nat.casesOn n φ₁' fun n => Nat.casesOn n φ₂' fun _ => PEmpty.elim⟩
variable (ϕ : L →ᴸ L')
/-- Pulls a structure back along a language map. -/
def reduct (M : Type*) [L'.Structure M] : L.Structure M where
funMap f xs := funMap (ϕ.onFunction f) xs
RelMap r xs := RelMap (ϕ.onRelation r) xs
/-- The identity language homomorphism. -/
@[simps]
protected def id (L : Language) : L →ᴸ L :=
⟨fun _n => id, fun _n => id⟩
instance : Inhabited (L →ᴸ L) :=
⟨LHom.id L⟩
/-- The inclusion of the left factor into the sum of two languages. -/
@[simps]
protected def sumInl : L →ᴸ L.sum L' :=
⟨fun _n => Sum.inl, fun _n => Sum.inl⟩
/-- The inclusion of the right factor into the sum of two languages. -/
@[simps]
protected def sumInr : L' →ᴸ L.sum L' :=
⟨fun _n => Sum.inr, fun _n => Sum.inr⟩
variable (L L')
/-- The inclusion of an empty language into any other language. -/
@[simps]
protected def ofIsEmpty [L.IsAlgebraic] [L.IsRelational] : L →ᴸ L' :=
⟨fun n => (IsRelational.empty_functions n).elim, fun n => (IsAlgebraic.empty_relations n).elim⟩
variable {L L'} {L'' : Language}
@[ext]
protected theorem funext {F G : L →ᴸ L'} (h_fun : F.onFunction = G.onFunction)
(h_rel : F.onRelation = G.onRelation) : F = G := by
cases' F with Ff Fr
cases' G with Gf Gr
simp only [mk.injEq]
exact And.intro h_fun h_rel
instance [L.IsAlgebraic] [L.IsRelational] : Unique (L →ᴸ L') :=
⟨⟨LHom.ofIsEmpty L L'⟩, fun _ => LHom.funext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩
theorem mk₂_funext {c f₁ f₂ : Type u} {r₁ r₂ : Type v} {F G : Language.mk₂ c f₁ f₂ r₁ r₂ →ᴸ L'}
(h0 : ∀ c : (Language.mk₂ c f₁ f₂ r₁ r₂).Constants, F.onFunction c = G.onFunction c)
(h1 : ∀ f : (Language.mk₂ c f₁ f₂ r₁ r₂).Functions 1, F.onFunction f = G.onFunction f)
(h2 : ∀ f : (Language.mk₂ c f₁ f₂ r₁ r₂).Functions 2, F.onFunction f = G.onFunction f)
(h1' : ∀ r : (Language.mk₂ c f₁ f₂ r₁ r₂).Relations 1, F.onRelation r = G.onRelation r)
(h2' : ∀ r : (Language.mk₂ c f₁ f₂ r₁ r₂).Relations 2, F.onRelation r = G.onRelation r) :
F = G :=
LHom.funext
(funext fun n =>
Nat.casesOn n (funext h0) fun n =>
Nat.casesOn n (funext h1) fun n =>
Nat.casesOn n (funext h2) fun _n => funext fun f => PEmpty.elim f)
(funext fun n =>
Nat.casesOn n (funext fun r => PEmpty.elim r) fun n =>
Nat.casesOn n (funext h1') fun n =>
Nat.casesOn n (funext h2') fun _n => funext fun r => PEmpty.elim r)
/-- The composition of two language homomorphisms. -/
@[simps]
def comp (g : L' →ᴸ L'') (f : L →ᴸ L') : L →ᴸ L'' :=
⟨fun _n F => g.1 (f.1 F), fun _ R => g.2 (f.2 R)⟩
-- Porting note: added ᴸ to avoid clash with function composition
@[inherit_doc]
local infixl:60 " ∘ᴸ " => LHom.comp
@[simp]
theorem id_comp (F : L →ᴸ L') : LHom.id L' ∘ᴸ F = F := by
cases F
rfl
@[simp]
theorem comp_id (F : L →ᴸ L') : F ∘ᴸ LHom.id L = F := by
cases F
rfl
theorem comp_assoc {L3 : Language} (F : L'' →ᴸ L3) (G : L' →ᴸ L'') (H : L →ᴸ L') :
F ∘ᴸ G ∘ᴸ H = F ∘ᴸ (G ∘ᴸ H) :=
rfl
section SumElim
variable (ψ : L'' →ᴸ L')
/-- A language map defined on two factors of a sum. -/
@[simps]
protected def sumElim : L.sum L'' →ᴸ L' where
onFunction _n := Sum.elim (fun f => ϕ.onFunction f) fun f => ψ.onFunction f
onRelation _n := Sum.elim (fun f => ϕ.onRelation f) fun f => ψ.onRelation f
theorem sumElim_comp_inl (ψ : L'' →ᴸ L') : ϕ.sumElim ψ ∘ᴸ LHom.sumInl = ϕ :=
LHom.funext (funext fun _ => rfl) (funext fun _ => rfl)
theorem sumElim_comp_inr (ψ : L'' →ᴸ L') : ϕ.sumElim ψ ∘ᴸ LHom.sumInr = ψ :=
LHom.funext (funext fun _ => rfl) (funext fun _ => rfl)
theorem sumElim_inl_inr : LHom.sumInl.sumElim LHom.sumInr = LHom.id (L.sum L') :=
LHom.funext (funext fun _ => Sum.elim_inl_inr) (funext fun _ => Sum.elim_inl_inr)
theorem comp_sumElim {L3 : Language} (θ : L' →ᴸ L3) :
θ ∘ᴸ ϕ.sumElim ψ = (θ ∘ᴸ ϕ).sumElim (θ ∘ᴸ ψ) :=
LHom.funext (funext fun _n => Sum.comp_elim _ _ _) (funext fun _n => Sum.comp_elim _ _ _)
end SumElim
section SumMap
variable {L₁ L₂ : Language} (ψ : L₁ →ᴸ L₂)
/-- The map between two sum-languages induced by maps on the two factors. -/
@[simps]
def sumMap : L.sum L₁ →ᴸ L'.sum L₂ where
onFunction _n := Sum.map (fun f => ϕ.onFunction f) fun f => ψ.onFunction f
onRelation _n := Sum.map (fun f => ϕ.onRelation f) fun f => ψ.onRelation f
@[simp]
theorem sumMap_comp_inl : ϕ.sumMap ψ ∘ᴸ LHom.sumInl = LHom.sumInl ∘ᴸ ϕ :=
LHom.funext (funext fun _ => rfl) (funext fun _ => rfl)
@[simp]
theorem sumMap_comp_inr : ϕ.sumMap ψ ∘ᴸ LHom.sumInr = LHom.sumInr ∘ᴸ ψ :=
LHom.funext (funext fun _ => rfl) (funext fun _ => rfl)
end SumMap
/-- A language homomorphism is injective when all the maps between symbol types are. -/
protected structure Injective : Prop where
onFunction {n} : Function.Injective fun f : L.Functions n => onFunction ϕ f
onRelation {n} : Function.Injective fun R : L.Relations n => onRelation ϕ R
/-- Pulls an `L`-structure along a language map `ϕ : L →ᴸ L'`, and then expands it
to an `L'`-structure arbitrarily. -/
noncomputable def defaultExpansion (ϕ : L →ᴸ L')
[∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => onFunction ϕ f)]
[∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => onRelation ϕ r)]
(M : Type*) [Inhabited M] [L.Structure M] : L'.Structure M where
funMap {n} f xs :=
if h' : f ∈ Set.range fun f : L.Functions n => onFunction ϕ f then funMap h'.choose xs
else default
RelMap {n} r xs :=
if h' : r ∈ Set.range fun r : L.Relations n => onRelation ϕ r then RelMap h'.choose xs
else default
/-- A language homomorphism is an expansion on a structure if it commutes with the interpretation of
all symbols on that structure. -/
class IsExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] : Prop where
map_onFunction : ∀ {n} (f : L.Functions n) (x : Fin n → M), funMap (ϕ.onFunction f) x = funMap f x
map_onRelation : ∀ {n} (R : L.Relations n) (x : Fin n → M),
RelMap (ϕ.onRelation R) x = RelMap R x
@[simp]
theorem map_onFunction {M : Type*} [L.Structure M] [L'.Structure M] [ϕ.IsExpansionOn M] {n}
(f : L.Functions n) (x : Fin n → M) : funMap (ϕ.onFunction f) x = funMap f x :=
IsExpansionOn.map_onFunction f x
@[simp]
theorem map_onRelation {M : Type*} [L.Structure M] [L'.Structure M] [ϕ.IsExpansionOn M] {n}
(R : L.Relations n) (x : Fin n → M) : RelMap (ϕ.onRelation R) x = RelMap R x :=
IsExpansionOn.map_onRelation R x
instance id_isExpansionOn (M : Type*) [L.Structure M] : IsExpansionOn (LHom.id L) M :=
⟨fun _ _ => rfl, fun _ _ => rfl⟩
instance ofIsEmpty_isExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] [L.IsAlgebraic]
[L.IsRelational] : IsExpansionOn (LHom.ofIsEmpty L L') M :=
⟨fun {n} => (IsRelational.empty_functions n).elim,
fun {n} => (IsAlgebraic.empty_relations n).elim⟩
instance sumElim_isExpansionOn {L'' : Language} (ψ : L'' →ᴸ L') (M : Type*) [L.Structure M]
[L'.Structure M] [L''.Structure M] [ϕ.IsExpansionOn M] [ψ.IsExpansionOn M] :
(ϕ.sumElim ψ).IsExpansionOn M :=
⟨fun f _ => Sum.casesOn f (by simp) (by simp), fun R _ => Sum.casesOn R (by simp) (by simp)⟩
instance sumMap_isExpansionOn {L₁ L₂ : Language} (ψ : L₁ →ᴸ L₂) (M : Type*) [L.Structure M]
[L'.Structure M] [L₁.Structure M] [L₂.Structure M] [ϕ.IsExpansionOn M] [ψ.IsExpansionOn M] :
(ϕ.sumMap ψ).IsExpansionOn M :=
⟨fun f _ => Sum.casesOn f (by simp) (by simp), fun R _ => Sum.casesOn R (by simp) (by simp)⟩
instance sumInl_isExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] :
(LHom.sumInl : L →ᴸ L.sum L').IsExpansionOn M :=
⟨fun _f _ => rfl, fun _R _ => rfl⟩
instance sumInr_isExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] :
(LHom.sumInr : L' →ᴸ L.sum L').IsExpansionOn M :=
⟨fun _f _ => rfl, fun _R _ => rfl⟩
@[simp]
theorem funMap_sumInl [(L.sum L').Structure M] [(LHom.sumInl : L →ᴸ L.sum L').IsExpansionOn M] {n}
{f : L.Functions n} {x : Fin n → M} : @funMap (L.sum L') M _ n (Sum.inl f) x = funMap f x :=
(LHom.sumInl : L →ᴸ L.sum L').map_onFunction f x
@[simp]
theorem funMap_sumInr [(L'.sum L).Structure M] [(LHom.sumInr : L →ᴸ L'.sum L).IsExpansionOn M] {n}
{f : L.Functions n} {x : Fin n → M} : @funMap (L'.sum L) M _ n (Sum.inr f) x = funMap f x :=
(LHom.sumInr : L →ᴸ L'.sum L).map_onFunction f x
theorem sumInl_injective : (LHom.sumInl : L →ᴸ L.sum L').Injective :=
⟨fun h => Sum.inl_injective h, fun h => Sum.inl_injective h⟩
theorem sumInr_injective : (LHom.sumInr : L' →ᴸ L.sum L').Injective :=
⟨fun h => Sum.inr_injective h, fun h => Sum.inr_injective h⟩
instance (priority := 100) isExpansionOn_reduct (ϕ : L →ᴸ L') (M : Type*) [L'.Structure M] :
@IsExpansionOn L L' ϕ M (ϕ.reduct M) _ :=
letI := ϕ.reduct M
⟨fun _f _ => rfl, fun _R _ => rfl⟩
theorem Injective.isExpansionOn_default {ϕ : L →ᴸ L'}
[∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => ϕ.onFunction f)]
[∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => ϕ.onRelation r)]
(h : ϕ.Injective) (M : Type*) [Inhabited M] [L.Structure M] :
@IsExpansionOn L L' ϕ M _ (ϕ.defaultExpansion M) := by
letI := ϕ.defaultExpansion M
refine ⟨fun {n} f xs => ?_, fun {n} r xs => ?_⟩
· have hf : ϕ.onFunction f ∈ Set.range fun f : L.Functions n => ϕ.onFunction f := ⟨f, rfl⟩
refine (dif_pos hf).trans ?_
rw [h.onFunction hf.choose_spec]
· have hr : ϕ.onRelation r ∈ Set.range fun r : L.Relations n => ϕ.onRelation r := ⟨r, rfl⟩
refine (dif_pos hr).trans ?_
rw [h.onRelation hr.choose_spec]
end LHom
/-- A language equivalence maps the symbols of one language to symbols of another bijectively. -/
structure LEquiv (L L' : Language) where
toLHom : L →ᴸ L'
invLHom : L' →ᴸ L
left_inv : invLHom.comp toLHom = LHom.id L
right_inv : toLHom.comp invLHom = LHom.id L'
infixl:10 " ≃ᴸ " => LEquiv
-- \^L
namespace LEquiv
variable (L)
/-- The identity equivalence from a first-order language to itself. -/
@[simps]
protected def refl : L ≃ᴸ L :=
⟨LHom.id L, LHom.id L, LHom.comp_id _, LHom.comp_id _⟩
variable {L}
instance : Inhabited (L ≃ᴸ L) :=
⟨LEquiv.refl L⟩
variable {L'' : Language} (e' : L' ≃ᴸ L'') (e : L ≃ᴸ L')
/-- The inverse of an equivalence of first-order languages. -/
@[simps]
protected def symm : L' ≃ᴸ L :=
⟨e.invLHom, e.toLHom, e.right_inv, e.left_inv⟩
/-- The composition of equivalences of first-order languages. -/
@[simps, trans]
protected def trans (e : L ≃ᴸ L') (e' : L' ≃ᴸ L'') : L ≃ᴸ L'' :=
⟨e'.toLHom.comp e.toLHom, e.invLHom.comp e'.invLHom, by
rw [LHom.comp_assoc, ← LHom.comp_assoc e'.invLHom, e'.left_inv, LHom.id_comp, e.left_inv], by
rw [LHom.comp_assoc, ← LHom.comp_assoc e.toLHom, e.right_inv, LHom.id_comp, e'.right_inv]⟩
end LEquiv
section ConstantsOn
variable (α : Type u')
/-- A language with constants indexed by a type. -/
@[simp]
def constantsOn : Language.{u', 0} :=
Language.mk₂ α PEmpty PEmpty PEmpty PEmpty
variable {α}
theorem constantsOn_constants : (constantsOn α).Constants = α :=
rfl
instance isAlgebraic_constantsOn : IsAlgebraic (constantsOn α) :=
Language.isAlgebraic_mk₂
instance isRelational_constantsOn [_ie : IsEmpty α] : IsRelational (constantsOn α) :=
Language.isRelational_mk₂
instance isEmpty_functions_constantsOn_succ {n : ℕ} : IsEmpty ((constantsOn α).Functions (n + 1)) :=
Nat.casesOn n (inferInstanceAs (IsEmpty PEmpty))
fun n => Nat.casesOn n (inferInstanceAs (IsEmpty PEmpty))
fun _ => (inferInstanceAs (IsEmpty PEmpty))
theorem card_constantsOn : (constantsOn α).card = #α := by simp
/-- Gives a `constantsOn α` structure to a type by assigning each constant a value. -/
def constantsOn.structure (f : α → M) : (constantsOn α).Structure M :=
Structure.mk₂ f PEmpty.elim PEmpty.elim PEmpty.elim PEmpty.elim
variable {β : Type v'}
/-- A map between index types induces a map between constant languages. -/
def LHom.constantsOnMap (f : α → β) : constantsOn α →ᴸ constantsOn β :=
LHom.mk₂ f PEmpty.elim PEmpty.elim PEmpty.elim PEmpty.elim
theorem constantsOnMap_isExpansionOn {f : α → β} {fα : α → M} {fβ : β → M} (h : fβ ∘ f = fα) :
@LHom.IsExpansionOn _ _ (LHom.constantsOnMap f) M (constantsOn.structure fα)
(constantsOn.structure fβ) := by
letI := constantsOn.structure fα
letI := constantsOn.structure fβ
exact
⟨fun {n} => Nat.casesOn n (fun F _x => (congr_fun h F : _)) fun n F => isEmptyElim F, fun R =>
isEmptyElim R⟩
end ConstantsOn
section WithConstants
variable (L)
section
variable (α : Type w')
/-- Extends a language with a constant for each element of a parameter set in `M`. -/
def withConstants : Language.{max u w', v} :=
L.sum (constantsOn α)
@[inherit_doc FirstOrder.Language.withConstants]
scoped[FirstOrder] notation:95 L "[[" α "]]" => Language.withConstants L α
@[simp]
theorem card_withConstants :
L[[α]].card = Cardinal.lift.{w'} L.card + Cardinal.lift.{max u v} #α := by
rw [withConstants, card_sum, card_constantsOn]
/-- The language map adding constants. -/
@[simps!] -- Porting note: add `!` to `simps`
def lhomWithConstants : L →ᴸ L[[α]] :=
LHom.sumInl
theorem lhomWithConstants_injective : (L.lhomWithConstants α).Injective :=
LHom.sumInl_injective
variable {α}
/-- The constant symbol indexed by a particular element. -/
protected def con (a : α) : L[[α]].Constants :=
Sum.inr a
variable {L} (α)
/-- Adds constants to a language map. -/
def LHom.addConstants {L' : Language} (φ : L →ᴸ L') : L[[α]] →ᴸ L'[[α]] :=
φ.sumMap (LHom.id _)
instance paramsStructure (A : Set α) : (constantsOn A).Structure α :=
constantsOn.structure (↑)
variable (L)
/-- The language map removing an empty constant set. -/
@[simps]
def LEquiv.addEmptyConstants [ie : IsEmpty α] : L ≃ᴸ L[[α]] where
toLHom := lhomWithConstants L α
invLHom := LHom.sumElim (LHom.id L) (LHom.ofIsEmpty (constantsOn α) L)
left_inv := by rw [lhomWithConstants, LHom.sumElim_comp_inl]
right_inv := by
simp only [LHom.comp_sumElim, lhomWithConstants, LHom.comp_id]
exact _root_.trans (congr rfl (Subsingleton.elim _ _)) LHom.sumElim_inl_inr
variable {α} {β : Type*}
@[simp]
theorem withConstants_funMap_sum_inl [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{n} {f : L.Functions n} {x : Fin n → M} : @funMap (L[[α]]) M _ n (Sum.inl f) x = funMap f x :=
(lhomWithConstants L α).map_onFunction f x
@[simp]
theorem withConstants_relMap_sum_inl [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{n} {R : L.Relations n} {x : Fin n → M} : @RelMap (L[[α]]) M _ n (Sum.inl R) x = RelMap R x :=
(lhomWithConstants L α).map_onRelation R x
/-- The language map extending the constant set. -/
def lhomWithConstantsMap (f : α → β) : L[[α]] →ᴸ L[[β]] :=
LHom.sumMap (LHom.id L) (LHom.constantsOnMap f)
@[simp]
theorem LHom.map_constants_comp_sumInl {f : α → β} :
(L.lhomWithConstantsMap f).comp LHom.sumInl = L.lhomWithConstants β := by ext <;> rfl
end
open FirstOrder
instance constantsOnSelfStructure : (constantsOn M).Structure M :=
constantsOn.structure id
instance withConstantsSelfStructure : L[[M]].Structure M :=
Language.sumStructure _ _ M
instance withConstants_self_expansion : (lhomWithConstants L M).IsExpansionOn M :=
⟨fun _ _ => rfl, fun _ _ => rfl⟩
variable (α : Type*) [(constantsOn α).Structure M]
instance withConstantsStructure : L[[α]].Structure M :=
Language.sumStructure _ _ _
instance withConstants_expansion : (L.lhomWithConstants α).IsExpansionOn M :=
⟨fun _ _ => rfl, fun _ _ => rfl⟩
instance addEmptyConstants_is_expansion_on' :
(LEquiv.addEmptyConstants L (∅ : Set M)).toLHom.IsExpansionOn M :=
L.withConstants_expansion _
instance addEmptyConstants_symm_isExpansionOn :
(LEquiv.addEmptyConstants L (∅ : Set M)).symm.toLHom.IsExpansionOn M :=
LHom.sumElim_isExpansionOn _ _ _
instance addConstants_expansion {L' : Language} [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] :
(φ.addConstants α).IsExpansionOn M :=
LHom.sumMap_isExpansionOn _ _ M
@[simp]
theorem withConstants_funMap_sum_inr {a : α} {x : Fin 0 → M} :
@funMap (L[[α]]) M _ 0 (Sum.inr a : L[[α]].Functions 0) x = L.con a := by
rw [Unique.eq_default x]
exact (LHom.sumInr : constantsOn α →ᴸ L.sum _).map_onFunction _ _
variable {α} (A : Set M)
@[simp]
theorem coe_con {a : A} : (L.con a : M) = a :=
rfl
variable {A} {B : Set M} (h : A ⊆ B)
instance constantsOnMap_inclusion_isExpansionOn :
(LHom.constantsOnMap (Set.inclusion h)).IsExpansionOn M :=
constantsOnMap_isExpansionOn rfl
instance map_constants_inclusion_isExpansionOn :
(L.lhomWithConstantsMap (Set.inclusion h)).IsExpansionOn M :=
LHom.sumMap_isExpansionOn _ _ _
end WithConstants
end Language
end FirstOrder
|
ModelTheory\Order.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Semantics
/-!
# Ordered First-Ordered Structures
This file defines ordered first-order languages and structures, as well as their theories.
## Main Definitions
- `FirstOrder.Language.order` is the language consisting of a single relation representing `≤`.
- `FirstOrder.Language.orderStructure` is the structure on an ordered type, assigning the symbol
representing `≤` to the actual relation `≤`.
- `FirstOrder.Language.IsOrdered` points out a specific symbol in a language as representing `≤`.
- `FirstOrder.Language.OrderedStructure` indicates that the `≤` symbol in an ordered language
is interpreted as the actual relation `≤` in a particular structure.
- `FirstOrder.Language.linearOrderTheory` and similar define the theories of preorders,
partial orders, and linear orders.
- `FirstOrder.Language.dlo` defines the theory of dense linear orders without endpoints, a
particularly useful example in model theory.
## Main Results
- `PartialOrder`s model the theory of partial orders, `LinearOrder`s model the theory of
linear orders, and dense linear orders without endpoints model `Language.dlo`.
-/
universe u v w w'
namespace FirstOrder
namespace Language
open FirstOrder Structure
variable {L : Language.{u, v}} {α : Type w} {M : Type w'} {n : ℕ}
/-- The language consisting of a single relation representing `≤`. -/
protected def order : Language :=
Language.mk₂ Empty Empty Empty Empty Unit
instance orderStructure [LE M] : Language.order.Structure M :=
Structure.mk₂ Empty.elim Empty.elim Empty.elim Empty.elim fun _ => (· ≤ ·)
namespace Order
instance Language.instIsRelational : IsRelational Language.order :=
Language.isRelational_mk₂
instance Language.instSubsingleton : Subsingleton (Language.order.Relations n) :=
Language.subsingleton_mk₂_relations
end Order
/-- A language is ordered if it has a symbol representing `≤`. -/
class IsOrdered (L : Language.{u, v}) where
leSymb : L.Relations 2
export IsOrdered (leSymb)
section IsOrdered
variable [IsOrdered L]
/-- Joins two terms `t₁, t₂` in a formula representing `t₁ ≤ t₂`. -/
def Term.le (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n :=
leSymb.boundedFormula₂ t₁ t₂
/-- Joins two terms `t₁, t₂` in a formula representing `t₁ < t₂`. -/
def Term.lt (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n :=
t₁.le t₂ ⊓ ∼(t₂.le t₁)
variable (L)
/-- The language homomorphism sending the unique symbol `≤` of `Language.order` to `≤` in an ordered
language. -/
def orderLHom : Language.order →ᴸ L :=
LHom.mk₂ Empty.elim Empty.elim Empty.elim Empty.elim fun _ => leSymb
end IsOrdered
instance : IsOrdered Language.order :=
⟨Unit.unit⟩
@[simp]
theorem orderLHom_leSymb [L.IsOrdered] :
(orderLHom L).onRelation leSymb = (leSymb : L.Relations 2) :=
rfl
@[simp]
theorem orderLHom_order : orderLHom Language.order = LHom.id Language.order :=
LHom.funext (Subsingleton.elim _ _) (Subsingleton.elim _ _)
instance sum.instIsOrdered : IsOrdered (L.sum Language.order) :=
⟨Sum.inr IsOrdered.leSymb⟩
section
variable (L) [IsOrdered L]
/-- The theory of preorders. -/
def preorderTheory : L.Theory :=
{leSymb.reflexive, leSymb.transitive}
/-- The theory of partial orders. -/
def partialOrderTheory : L.Theory :=
{leSymb.reflexive, leSymb.antisymmetric, leSymb.transitive}
/-- The theory of linear orders. -/
def linearOrderTheory : L.Theory :=
{leSymb.reflexive, leSymb.antisymmetric, leSymb.transitive, leSymb.total}
/-- A sentence indicating that an order has no top element:
$\forall x, \exists y, \neg y \le x$. -/
def noTopOrderSentence : L.Sentence :=
∀'∃'∼((&1).le &0)
/-- A sentence indicating that an order has no bottom element:
$\forall x, \exists y, \neg x \le y$. -/
def noBotOrderSentence : L.Sentence :=
∀'∃'∼((&0).le &1)
/-- A sentence indicating that an order is dense:
$\forall x, \forall y, x < y \to \exists z, x < z \wedge z < y$. -/
def denselyOrderedSentence : L.Sentence :=
∀'∀'((&0).lt &1 ⟹ ∃'((&0).lt &2 ⊓ (&2).lt &1))
/-- The theory of dense linear orders without endpoints. -/
def dlo : L.Theory :=
L.linearOrderTheory ∪ {L.noTopOrderSentence, L.noBotOrderSentence, L.denselyOrderedSentence}
end
variable (L M)
/-- A structure is ordered if its language has a `≤` symbol whose interpretation is -/
abbrev OrderedStructure [IsOrdered L] [LE M] [L.Structure M] : Prop :=
LHom.IsExpansionOn (orderLHom L) M
variable {L M}
@[simp]
theorem orderedStructure_iff [IsOrdered L] [LE M] [L.Structure M] :
L.OrderedStructure M ↔ LHom.IsExpansionOn (orderLHom L) M :=
Iff.rfl
instance orderedStructure_LE [LE M] : OrderedStructure Language.order M := by
rw [orderedStructure_iff, orderLHom_order]
exact LHom.id_isExpansionOn M
instance model_preorder [Preorder M] : M ⊨ Language.order.preorderTheory := by
simp only [preorderTheory, Theory.model_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
forall_eq_or_imp, Relations.realize_reflexive, relMap_apply₂, forall_eq,
Relations.realize_transitive]
exact ⟨le_refl, fun _ _ _ => le_trans⟩
instance model_partialOrder [PartialOrder M] : M ⊨ Language.order.partialOrderTheory := by
simp only [partialOrderTheory, Theory.model_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
forall_eq_or_imp, Relations.realize_reflexive, relMap_apply₂, Relations.realize_antisymmetric,
forall_eq, Relations.realize_transitive]
exact ⟨le_refl, fun _ _ => le_antisymm, fun _ _ _ => le_trans⟩
instance model_linearOrder [LinearOrder M] : M ⊨ Language.order.linearOrderTheory := by
simp only [linearOrderTheory, Theory.model_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
forall_eq_or_imp, Relations.realize_reflexive, relMap_apply₂, Relations.realize_antisymmetric,
Relations.realize_transitive, forall_eq, Relations.realize_total]
exact ⟨le_refl, fun _ _ => le_antisymm, fun _ _ _ => le_trans, le_total⟩
section OrderedStructure
variable [IsOrdered L] [L.Structure M]
@[simp]
theorem relMap_leSymb [LE M] [L.OrderedStructure M] {a b : M} :
RelMap (leSymb : L.Relations 2) ![a, b] ↔ a ≤ b := by
rw [← orderLHom_leSymb, LHom.map_onRelation]
rfl
@[simp]
theorem Term.realize_le [LE M] [L.OrderedStructure M] {t₁ t₂ : L.Term (α ⊕ (Fin n))} {v : α → M}
{xs : Fin n → M} :
(t₁.le t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) ≤ t₂.realize (Sum.elim v xs) := by
simp [Term.le]
@[simp]
theorem Term.realize_lt [Preorder M] [L.OrderedStructure M] {t₁ t₂ : L.Term (α ⊕ (Fin n))}
{v : α → M} {xs : Fin n → M} :
(t₁.lt t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) < t₂.realize (Sum.elim v xs) := by
simp [Term.lt, lt_iff_le_not_le]
end OrderedStructure
section LE
variable [LE M]
theorem realize_noTopOrder_iff : M ⊨ Language.order.noTopOrderSentence ↔ NoTopOrder M := by
simp only [noTopOrderSentence, Sentence.Realize, Formula.Realize, BoundedFormula.realize_all,
BoundedFormula.realize_ex, BoundedFormula.realize_not, Term.realize, Term.realize_le,
Sum.elim_inr]
refine ⟨fun h => ⟨fun a => h a⟩, ?_⟩
intro h a
exact exists_not_le a
@[simp]
theorem realize_noTopOrder [h : NoTopOrder M] : M ⊨ Language.order.noTopOrderSentence :=
realize_noTopOrder_iff.2 h
theorem realize_noBotOrder_iff : M ⊨ Language.order.noBotOrderSentence ↔ NoBotOrder M := by
simp only [noBotOrderSentence, Sentence.Realize, Formula.Realize, BoundedFormula.realize_all,
BoundedFormula.realize_ex, BoundedFormula.realize_not, Term.realize, Term.realize_le,
Sum.elim_inr]
refine ⟨fun h => ⟨fun a => h a⟩, ?_⟩
intro h a
exact exists_not_ge a
@[simp]
theorem realize_noBotOrder [h : NoBotOrder M] : M ⊨ Language.order.noBotOrderSentence :=
realize_noBotOrder_iff.2 h
end LE
theorem realize_denselyOrdered_iff [Preorder M] :
M ⊨ Language.order.denselyOrderedSentence ↔ DenselyOrdered M := by
simp only [denselyOrderedSentence, Sentence.Realize, Formula.Realize,
BoundedFormula.realize_imp, BoundedFormula.realize_all, Term.realize, Term.realize_lt,
Sum.elim_inr, BoundedFormula.realize_ex, BoundedFormula.realize_inf]
refine ⟨fun h => ⟨fun a b ab => h a b ab⟩, ?_⟩
intro h a b ab
exact exists_between ab
@[simp]
theorem realize_denselyOrdered [Preorder M] [h : DenselyOrdered M] :
M ⊨ Language.order.denselyOrderedSentence :=
realize_denselyOrdered_iff.2 h
instance model_dlo [LinearOrder M] [DenselyOrdered M] [NoTopOrder M] [NoBotOrder M] :
M ⊨ Language.order.dlo := by
simp only [dlo, Set.union_insert, Set.union_singleton, Theory.model_iff, Set.mem_insert_iff,
forall_eq_or_imp, realize_noTopOrder, realize_noBotOrder, realize_denselyOrdered,
true_and_iff]
rw [← Theory.model_iff]
infer_instance
end Language
end FirstOrder
|
ModelTheory\PartialEquiv.lean | /-
Copyright (c) 2024 Gabin Kolly. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Gabin Kolly
-/
import Mathlib.ModelTheory.Substructures
/-!
# Partial Isomorphisms
This file defines partial isomorphisms between first-order structures.
## Main Definitions
- `FirstOrder.Language.Substructure.PartialEquiv` is defined so that `L.PartialEquiv M N`, annotated
`M ≃ₚ[L] N`, is the type of equivalences between substructures of `M` and `N`.
-/
universe u v w w'
namespace FirstOrder
namespace Language
variable (L : Language.{u, v}) (M : Type w) (N : Type w') {P : Type*}
variable [L.Structure M] [L.Structure N] [L.Structure P]
open FirstOrder Structure Substructure
/-- A partial `L`-equivalence, implemented as an equivalence between substructures. -/
structure PartialEquiv where
/-- The substructure which is the domain of the equivalence. -/
dom : L.Substructure M
/-- The substructure which is the codomain of the equivalence. -/
cod : L.Substructure N
/-- The equivalence between the two subdomains. -/
toEquiv : dom ≃[L] cod
@[inherit_doc]
scoped[FirstOrder] notation:25 M " ≃ₚ[" L "] " N =>
FirstOrder.Language.PartialEquiv L M N
variable {L M N}
namespace PartialEquiv
noncomputable instance instInhabited_self : Inhabited (M ≃ₚ[L] M) :=
⟨⊤, ⊤, Equiv.refl L (⊤ : L.Substructure M)⟩
/-- Maps to the symmetric partial equivalence. -/
def symm (f : M ≃ₚ[L] N) : N ≃ₚ[L] M where
dom := f.cod
cod := f.dom
toEquiv := f.toEquiv.symm
@[simp]
theorem symm_symm (f : M ≃ₚ[L] N) : f.symm.symm = f :=
rfl
@[simp]
theorem symm_apply (f : M ≃ₚ[L] N) (x : f.cod) : f.symm.toEquiv x = f.toEquiv.symm x :=
rfl
instance : LE (M ≃ₚ[L] N) :=
⟨fun f g ↦ ∃h : f.dom ≤ g.dom,
(subtype _).comp (g.toEquiv.toEmbedding.comp (Substructure.inclusion h)) =
(subtype _).comp f.toEquiv.toEmbedding⟩
theorem le_def (f g : M ≃ₚ[L] N) : f ≤ g ↔ ∃ h : f.dom ≤ g.dom,
(subtype _).comp (g.toEquiv.toEmbedding.comp (Substructure.inclusion h)) =
(subtype _).comp f.toEquiv.toEmbedding :=
Iff.rfl
@[gcongr] theorem dom_le_dom {f g : M ≃ₚ[L] N} : f ≤ g → f.dom ≤ g.dom := fun ⟨le, _⟩ ↦ le
@[gcongr] theorem cod_le_cod {f g : M ≃ₚ[L] N} : f ≤ g → f.cod ≤ g.cod := by
rintro ⟨_, eq_fun⟩ n hn
let m := f.toEquiv.symm ⟨n, hn⟩
have : ((subtype _).comp f.toEquiv.toEmbedding) m = n := by simp only [m, Embedding.comp_apply,
Equiv.coe_toEmbedding, Equiv.apply_symm_apply, coeSubtype]
rw [← this, ← eq_fun]
simp only [Embedding.comp_apply, coe_inclusion, Equiv.coe_toEmbedding, coeSubtype,
SetLike.coe_mem]
theorem subtype_toEquiv_inclusion {f g : M ≃ₚ[L] N} (h : f ≤ g) :
(subtype _).comp (g.toEquiv.toEmbedding.comp (Substructure.inclusion (dom_le_dom h))) =
(subtype _).comp f.toEquiv.toEmbedding := by
let ⟨_, eq⟩ := h; exact eq
theorem toEquiv_inclusion {f g : M ≃ₚ[L] N} (h : f ≤ g) :
g.toEquiv.toEmbedding.comp (Substructure.inclusion (dom_le_dom h)) =
(Substructure.inclusion (cod_le_cod h)).comp f.toEquiv.toEmbedding := by
rw [← (subtype _).comp_inj, subtype_toEquiv_inclusion h]
rfl
theorem toEquiv_inclusion_apply {f g : M ≃ₚ[L] N} (h : f ≤ g) (x : f.dom) :
g.toEquiv (Substructure.inclusion (dom_le_dom h) x) =
Substructure.inclusion (cod_le_cod h) (f.toEquiv x) := by
apply (subtype _).injective
change (subtype _).comp (g.toEquiv.toEmbedding.comp (inclusion _)) x = _
rw [subtype_toEquiv_inclusion h]
rfl
theorem le_iff {f g : M ≃ₚ[L] N} : f ≤ g ↔
∃ dom_le_dom : f.dom ≤ g.dom,
∃ cod_le_cod : f.cod ≤ g.cod,
∀ x, inclusion cod_le_cod (f.toEquiv x) = g.toEquiv (inclusion dom_le_dom x) := by
constructor
· exact fun h ↦ ⟨dom_le_dom h, cod_le_cod h,
by intro x; apply (subtype _).inj'; rwa [toEquiv_inclusion_apply]⟩
· rintro ⟨dom_le_dom, le_cod, h_eq⟩
rw [le_def]
exact ⟨dom_le_dom, by ext; change subtype _ (g.toEquiv _) = _; rw [← h_eq]; rfl⟩
theorem le_trans (f g h : M ≃ₚ[L] N) : f ≤ g → g ≤ h → f ≤ h := by
rintro ⟨le_fg, eq_fg⟩ ⟨le_gh, eq_gh⟩
refine ⟨le_fg.trans le_gh, ?_⟩
rw [← eq_fg, ← Embedding.comp_assoc (g := g.toEquiv.toEmbedding), ← eq_gh]
rfl
private theorem le_refl (f : M ≃ₚ[L] N) : f ≤ f := ⟨le_rfl, rfl⟩
private theorem le_antisymm (f g : M ≃ₚ[L] N) (le_fg : f ≤ g) (le_gf : g ≤ f) : f = g := by
let ⟨dom_f, cod_f, equiv_f⟩ := f
cases _root_.le_antisymm (dom_le_dom le_fg) (dom_le_dom le_gf)
cases _root_.le_antisymm (cod_le_cod le_fg) (cod_le_cod le_gf)
convert rfl
exact Equiv.injective_toEmbedding ((subtype _).comp_injective (subtype_toEquiv_inclusion le_fg))
instance : PartialOrder (M ≃ₚ[L] N) where
le_refl := le_refl
le_trans := le_trans
le_antisymm := le_antisymm
@[gcongr] lemma symm_le_symm {f g : M ≃ₚ[L] N} (hfg : f ≤ g) : f.symm ≤ g.symm := by
rw [le_iff]
refine ⟨cod_le_cod hfg, dom_le_dom hfg, ?_⟩
intro x
apply g.toEquiv.injective
change g.toEquiv (inclusion _ (f.toEquiv.symm x)) = g.toEquiv (g.toEquiv.symm _)
rw [g.toEquiv.apply_symm_apply, (Equiv.apply_symm_apply f.toEquiv x).symm,
f.toEquiv.symm_apply_apply]
exact toEquiv_inclusion_apply hfg _
theorem monotone_symm : Monotone (fun (f : M ≃ₚ[L] N) ↦ f.symm) := fun _ _ => symm_le_symm
theorem symm_le_iff {f : M ≃ₚ[L] N} {g : N ≃ₚ[L] M} : f.symm ≤ g ↔ f ≤ g.symm :=
⟨by intro h; rw [← f.symm_symm]; exact monotone_symm h,
by intro h; rw [← g.symm_symm]; exact monotone_symm h⟩
theorem ext {f g : M ≃ₚ[L] N} (h_dom : f.dom = g.dom) : (∀ x : M, ∀ h : x ∈ f.dom,
subtype _ (f.toEquiv ⟨x, h⟩) = subtype _ (g.toEquiv ⟨x, (h_dom ▸ h)⟩)) → f = g := by
intro h
rcases f with ⟨dom_f, cod_f, equiv_f⟩
cases h_dom
apply le_antisymm <;> (rw [le_def]; use (by rfl); ext ⟨x, hx⟩)
· exact (h x hx).symm
· exact h x hx
theorem ext_iff {f g : M ≃ₚ[L] N} : f = g ↔ ∃ h_dom : f.dom = g.dom,
∀ x : M, ∀ h : x ∈ f.dom,
subtype _ (f.toEquiv ⟨x, h⟩) = subtype _ (g.toEquiv ⟨x, (h_dom ▸ h)⟩) := by
constructor
· intro h_eq
rcases f with ⟨dom_f, cod_f, equiv_f⟩
cases h_eq
exact ⟨rfl, fun _ _ ↦ rfl⟩
· rintro ⟨h, H⟩; exact ext h H
theorem monotone_dom : Monotone (fun f : M ≃ₚ[L] N ↦ f.dom) := fun _ _ ↦ dom_le_dom
theorem monotone_cod : Monotone (fun f : M ≃ₚ[L] N ↦ f.cod) := fun _ _ ↦ cod_le_cod
/-- Restriction of a partial equivalence to a substructure of the domain. -/
noncomputable def domRestrict (f : M ≃ₚ[L] N) {A : L.Substructure M} (h : A ≤ f.dom) :
M ≃ₚ[L] N := by
let g := (subtype _).comp (f.toEquiv.toEmbedding.comp (A.inclusion h))
exact {
dom := A
cod := g.toHom.range
toEquiv := g.equivRange
}
theorem domRestrict_le (f : M ≃ₚ[L] N) {A : L.Substructure M} (h : A ≤ f.dom) :
f.domRestrict h ≤ f := ⟨h, rfl⟩
theorem le_domRestrict (f g : M ≃ₚ[L] N) {A : L.Substructure M} (hf : f.dom ≤ A)
(hg : A ≤ g.dom) (hfg : f ≤ g) : f ≤ g.domRestrict hg :=
⟨hf, by rw [← (subtype_toEquiv_inclusion hfg)]; rfl⟩
/-- Restriction of a partial equivalence to a substructure of the codomain. -/
noncomputable def codRestrict (f : M ≃ₚ[L] N) {A : L.Substructure N} (h : A ≤ f.cod) :
M ≃ₚ[L] N :=
(f.symm.domRestrict h).symm
theorem codRestrict_le (f : M ≃ₚ[L] N) {A : L.Substructure N} (h : A ≤ f.cod) :
codRestrict f h ≤ f :=
symm_le_iff.2 (f.symm.domRestrict_le h)
theorem le_codRestrict (f g : M ≃ₚ[L] N) {A : L.Substructure N} (hf : f.cod ≤ A)
(hg : A ≤ g.cod) (hfg : f ≤ g) : f ≤ g.codRestrict hg :=
symm_le_iff.1 (le_domRestrict f.symm g.symm hf hg (monotone_symm hfg))
/-- A partial equivalence as an embedding from its domain. -/
def toEmbedding (f : M ≃ₚ[L] N) : f.dom ↪[L] N :=
(subtype _).comp f.toEquiv.toEmbedding
@[simp]
theorem toEmbedding_apply {f : M ≃ₚ[L] N} (m : f.dom) :
f.toEmbedding m = f.toEquiv m := by
rcases f with ⟨dom, cod, g⟩
rfl
/-- Given a partial equivalence which has the whole structure as domain,
returns the corresponding embedding. -/
def toEmbeddingOfEqTop {f : M ≃ₚ[L] N} (h : f.dom = ⊤) : M ↪[L] N :=
(h ▸ f.toEmbedding).comp topEquiv.symm.toEmbedding
@[simp]
theorem toEmbeddingOfEqTop__apply {f : M ≃ₚ[L] N} (h : f.dom = ⊤) (m : M) :
toEmbeddingOfEqTop h m = f.toEquiv ⟨m, h.symm ▸ mem_top m⟩ := by
rcases f with ⟨dom, cod, g⟩
cases h
rfl
/-- Given a partial equivalence which has the whole structure as domain and
as codomain, returns the corresponding equivalence. -/
def toEquivOfEqTop {f : M ≃ₚ[L] N} (h_dom : f.dom = ⊤)
(h_cod : f.cod = ⊤) : M ≃[L] N :=
(topEquiv (M := N)).comp ((h_dom ▸ h_cod ▸ f.toEquiv).comp (topEquiv (M := M)).symm)
@[simp]
theorem toEquivOfEqTop_toEmbedding {f : M ≃ₚ[L] N} (h_dom : f.dom = ⊤)
(h_cod : f.cod = ⊤) :
(toEquivOfEqTop h_dom h_cod).toEmbedding = toEmbeddingOfEqTop h_dom := by
rcases f with ⟨dom, cod, g⟩
cases h_dom
cases h_cod
rfl
end PartialEquiv
namespace Embedding
/-- Given an embedding, returns the corresponding partial equivalence with `⊤` as domain. -/
noncomputable def toPartialEquiv (f : M ↪[L] N) : M ≃ₚ[L] N :=
⟨⊤, f.toHom.range, f.equivRange.comp (Substructure.topEquiv)⟩
theorem toPartialEquiv_injective :
Function.Injective (fun f : M ↪[L] N ↦ f.toPartialEquiv) := by
intro _ _ h
ext
rw [PartialEquiv.ext_iff] at h
rcases h with ⟨_, H⟩
exact H _ (Substructure.mem_top _)
@[simp]
theorem toEmbedding_toPartialEquiv (f : M ↪[L] N) :
PartialEquiv.toEmbeddingOfEqTop (f := f.toPartialEquiv) rfl = f :=
rfl
@[simp]
theorem toPartialEquiv_toEmbedding {f : M ≃ₚ[L] N} (h : f.dom = ⊤) :
(PartialEquiv.toEmbeddingOfEqTop h).toPartialEquiv = f := by
rcases f with ⟨_, _, _⟩
cases h
apply PartialEquiv.ext
intro _ _
rfl; rfl
end Embedding
end Language
end FirstOrder
|
ModelTheory\Quotients.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.Fintype.Quotient
import Mathlib.ModelTheory.Semantics
/-!
# Quotients of First-Order Structures
This file defines prestructures and quotients of first-order structures.
## Main Definitions
- If `s` is a setoid (equivalence relation) on `M`, a `FirstOrder.Language.Prestructure s` is the
data for a first-order structure on `M` that will still be a structure when modded out by `s`.
- The structure `FirstOrder.Language.quotientStructure s` is the resulting structure on
`Quotient s`.
-/
namespace FirstOrder
namespace Language
variable (L : Language) {M : Type*}
open FirstOrder
open Structure
/-- A prestructure is a first-order structure with a `Setoid` equivalence relation on it,
such that quotienting by that equivalence relation is still a structure. -/
class Prestructure (s : Setoid M) where
toStructure : L.Structure M
fun_equiv : ∀ {n} {f : L.Functions n} (x y : Fin n → M), x ≈ y → funMap f x ≈ funMap f y
rel_equiv : ∀ {n} {r : L.Relations n} (x y : Fin n → M) (_ : x ≈ y), RelMap r x = RelMap r y
variable {L} {s : Setoid M}
variable [ps : L.Prestructure s]
instance quotientStructure : L.Structure (Quotient s) where
funMap {n} f x :=
Quotient.map (@funMap L M ps.toStructure n f) Prestructure.fun_equiv (Quotient.finChoice x)
RelMap {n} r x :=
Quotient.lift (@RelMap L M ps.toStructure n r) Prestructure.rel_equiv (Quotient.finChoice x)
variable (s)
theorem funMap_quotient_mk' {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
(funMap f fun i => (⟦x i⟧ : Quotient s)) = ⟦@funMap _ _ ps.toStructure _ f x⟧ := by
change
Quotient.map (@funMap L M ps.toStructure n f) Prestructure.fun_equiv (Quotient.finChoice _) =
_
rw [Quotient.finChoice_eq, Quotient.map_mk]
theorem relMap_quotient_mk' {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
(RelMap r fun i => (⟦x i⟧ : Quotient s)) ↔ @RelMap _ _ ps.toStructure _ r x := by
change
Quotient.lift (@RelMap L M ps.toStructure n r) Prestructure.rel_equiv (Quotient.finChoice _) ↔
_
rw [Quotient.finChoice_eq, Quotient.lift_mk]
theorem Term.realize_quotient_mk' {β : Type*} (t : L.Term β) (x : β → M) :
(t.realize fun i => (⟦x i⟧ : Quotient s)) = ⟦@Term.realize _ _ ps.toStructure _ x t⟧ := by
induction' t with _ _ _ _ ih
· rfl
· simp only [ih, funMap_quotient_mk', Term.realize]
end Language
end FirstOrder
|
ModelTheory\Satisfiability.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Ultraproducts
import Mathlib.ModelTheory.Bundled
import Mathlib.ModelTheory.Skolem
/-!
# First-Order Satisfiability
This file deals with the satisfiability of first-order theories, as well as equivalence over them.
## Main Definitions
- `FirstOrder.Language.Theory.IsSatisfiable`: `T.IsSatisfiable` indicates that `T` has a nonempty
model.
- `FirstOrder.Language.Theory.IsFinitelySatisfiable`: `T.IsFinitelySatisfiable` indicates that
every finite subset of `T` is satisfiable.
- `FirstOrder.Language.Theory.IsComplete`: `T.IsComplete` indicates that `T` is satisfiable and
models each sentence or its negation.
- `FirstOrder.Language.Theory.SemanticallyEquivalent`: `T.SemanticallyEquivalent φ ψ` indicates
that `φ` and `ψ` are equivalent formulas or sentences in models of `T`.
- `Cardinal.Categorical`: A theory is `κ`-categorical if all models of size `κ` are isomorphic.
## Main Results
- The Compactness Theorem, `FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable`,
shows that a theory is satisfiable iff it is finitely satisfiable.
- `FirstOrder.Language.completeTheory.isComplete`: The complete theory of a structure is
complete.
- `FirstOrder.Language.Theory.exists_large_model_of_infinite_model` shows that any theory with an
infinite model has arbitrarily large models.
- `FirstOrder.Language.Theory.exists_elementaryEmbedding_card_eq`: The Upward Löwenheim–Skolem
Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure
`M`, then `M` has an elementary extension of cardinality `κ`.
## Implementation Details
- Satisfiability of an `L.Theory` `T` is defined in the minimal universe containing all the symbols
of `L`. By Löwenheim-Skolem, this is equivalent to satisfiability in any universe.
-/
universe u v w w'
open Cardinal CategoryTheory
open Cardinal FirstOrder
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ}
namespace Theory
variable (T)
/-- A theory is satisfiable if a structure models it. -/
def IsSatisfiable : Prop :=
Nonempty (ModelType.{u, v, max u v} T)
/-- A theory is finitely satisfiable if all of its finite subtheories are satisfiable. -/
def IsFinitelySatisfiable : Prop :=
∀ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T → IsSatisfiable (T0 : L.Theory)
variable {T} {T' : L.Theory}
theorem Model.isSatisfiable (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] :
T.IsSatisfiable :=
⟨((⊥ : Substructure _ (ModelType.of T M)).elementarySkolem₁Reduct.toModel T).shrink⟩
theorem IsSatisfiable.mono (h : T'.IsSatisfiable) (hs : T ⊆ T') : T.IsSatisfiable :=
⟨(Theory.Model.mono (ModelType.is_model h.some) hs).bundled⟩
theorem isSatisfiable_empty (L : Language.{u, v}) : IsSatisfiable (∅ : L.Theory) :=
⟨default⟩
theorem isSatisfiable_of_isSatisfiable_onTheory {L' : Language.{w, w'}} (φ : L →ᴸ L')
(h : (φ.onTheory T).IsSatisfiable) : T.IsSatisfiable :=
Model.isSatisfiable (h.some.reduct φ)
theorem isSatisfiable_onTheory_iff {L' : Language.{w, w'}} {φ : L →ᴸ L'} (h : φ.Injective) :
(φ.onTheory T).IsSatisfiable ↔ T.IsSatisfiable := by
classical
refine ⟨isSatisfiable_of_isSatisfiable_onTheory φ, fun h' => ?_⟩
haveI : Inhabited h'.some := Classical.inhabited_of_nonempty'
exact Model.isSatisfiable (h'.some.defaultExpansion h)
theorem IsSatisfiable.isFinitelySatisfiable (h : T.IsSatisfiable) : T.IsFinitelySatisfiable :=
fun _ => h.mono
/-- The **Compactness Theorem of first-order logic**: A theory is satisfiable if and only if it is
finitely satisfiable. -/
theorem isSatisfiable_iff_isFinitelySatisfiable {T : L.Theory} :
T.IsSatisfiable ↔ T.IsFinitelySatisfiable :=
⟨Theory.IsSatisfiable.isFinitelySatisfiable, fun h => by
classical
set M : Finset T → Type max u v := fun T0 : Finset T =>
(h (T0.map (Function.Embedding.subtype fun x => x ∈ T)) T0.map_subtype_subset).some.Carrier
let M' := Filter.Product (Ultrafilter.of (Filter.atTop : Filter (Finset T))) M
have h' : M' ⊨ T := by
refine ⟨fun φ hφ => ?_⟩
rw [Ultraproduct.sentence_realize]
refine
Filter.Eventually.filter_mono (Ultrafilter.of_le _)
(Filter.eventually_atTop.2
⟨{⟨φ, hφ⟩}, fun s h' =>
Theory.realize_sentence_of_mem (s.map (Function.Embedding.subtype fun x => x ∈ T))
?_⟩)
simp only [Finset.coe_map, Function.Embedding.coe_subtype, Set.mem_image, Finset.mem_coe,
Subtype.exists, Subtype.coe_mk, exists_and_right, exists_eq_right]
exact ⟨hφ, h' (Finset.mem_singleton_self _)⟩
exact ⟨ModelType.of T M'⟩⟩
theorem isSatisfiable_directed_union_iff {ι : Type*} [Nonempty ι] {T : ι → L.Theory}
(h : Directed (· ⊆ ·) T) : Theory.IsSatisfiable (⋃ i, T i) ↔ ∀ i, (T i).IsSatisfiable := by
refine ⟨fun h' i => h'.mono (Set.subset_iUnion _ _), fun h' => ?_⟩
rw [isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable]
intro T0 hT0
obtain ⟨i, hi⟩ := h.exists_mem_subset_of_finset_subset_biUnion hT0
exact (h' i).mono hi
theorem isSatisfiable_union_distinctConstantsTheory_of_card_le (T : L.Theory) (s : Set α)
(M : Type w') [Nonempty M] [L.Structure M] [M ⊨ T]
(h : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} #M) :
((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by
haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance
rw [Cardinal.lift_mk_le'] at h
letI : (constantsOn α).Structure M := constantsOn.structure (Function.extend (↑) h.some default)
have : M ⊨ (L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s := by
refine ((LHom.onTheory_model _ _).2 inferInstance).union ?_
rw [model_distinctConstantsTheory]
refine fun a as b bs ab => ?_
rw [← Subtype.coe_mk a as, ← Subtype.coe_mk b bs, ← Subtype.ext_iff]
exact
h.some.injective
((Subtype.coe_injective.extend_apply h.some default ⟨a, as⟩).symm.trans
(ab.trans (Subtype.coe_injective.extend_apply h.some default ⟨b, bs⟩)))
exact Model.isSatisfiable M
theorem isSatisfiable_union_distinctConstantsTheory_of_infinite (T : L.Theory) (s : Set α)
(M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] :
((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by
classical
rw [distinctConstantsTheory_eq_iUnion, Set.union_iUnion, isSatisfiable_directed_union_iff]
· exact fun t =>
isSatisfiable_union_distinctConstantsTheory_of_card_le T _ M
((lift_le_aleph0.2 (finset_card_lt_aleph0 _).le).trans
(aleph0_le_lift.2 (aleph0_le_mk M)))
· apply Monotone.directed_le
refine monotone_const.union (monotone_distinctConstantsTheory.comp ?_)
simp only [Finset.coe_map, Function.Embedding.coe_subtype]
exact Monotone.comp (g := Set.image ((↑) : s → α)) (f := ((↑) : Finset s → Set s))
Set.monotone_image fun _ _ => Finset.coe_subset.2
/-- Any theory with an infinite model has arbitrarily large models. -/
theorem exists_large_model_of_infinite_model (T : L.Theory) (κ : Cardinal.{w}) (M : Type w')
[L.Structure M] [M ⊨ T] [Infinite M] :
∃ N : ModelType.{_, _, max u v w} T, Cardinal.lift.{max u v w} κ ≤ #N := by
obtain ⟨N⟩ :=
isSatisfiable_union_distinctConstantsTheory_of_infinite T (Set.univ : Set κ.out) M
refine ⟨(N.is_model.mono Set.subset_union_left).bundled.reduct _, ?_⟩
haveI : N ⊨ distinctConstantsTheory _ _ := N.is_model.mono Set.subset_union_right
rw [ModelType.reduct_Carrier, coe_of]
refine _root_.trans (lift_le.2 (le_of_eq (Cardinal.mk_out κ).symm)) ?_
rw [← mk_univ]
refine
(card_le_of_model_distinctConstantsTheory L Set.univ N).trans (lift_le.{max u v w}.1 ?_)
rw [lift_lift]
theorem isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset {ι : Type*} (T : ι → L.Theory) :
IsSatisfiable (⋃ i, T i) ↔ ∀ s : Finset ι, IsSatisfiable (⋃ i ∈ s, T i) := by
classical
refine
⟨fun h s => h.mono (Set.iUnion_mono fun _ => Set.iUnion_subset_iff.2 fun _ => refl _),
fun h => ?_⟩
rw [isSatisfiable_iff_isFinitelySatisfiable]
intro s hs
rw [Set.iUnion_eq_iUnion_finset] at hs
obtain ⟨t, ht⟩ := Directed.exists_mem_subset_of_finset_subset_biUnion (by
exact Monotone.directed_le fun t1 t2 (h : ∀ ⦃x⦄, x ∈ t1 → x ∈ t2) =>
Set.iUnion_mono fun _ => Set.iUnion_mono' fun h1 => ⟨h h1, refl _⟩) hs
exact (h t).mono ht
end Theory
variable (L)
/-- A version of The Downward Löwenheim–Skolem theorem where the structure `N` elementarily embeds
into `M`, but is not by type a substructure of `M`, and thus can be chosen to belong to the universe
of the cardinal `κ`.
-/
theorem exists_elementaryEmbedding_card_eq_of_le (M : Type w') [L.Structure M] [Nonempty M]
(κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ)
(h3 : lift.{w'} κ ≤ Cardinal.lift.{w} #M) :
∃ N : Bundled L.Structure, Nonempty (N ↪ₑ[L] M) ∧ #N = κ := by
obtain ⟨S, _, hS⟩ := exists_elementarySubstructure_card_eq L ∅ κ h1 (by simp) h2 h3
have : Small.{w} S := by
rw [← lift_inj.{_, w + 1}, lift_lift, lift_lift] at hS
exact small_iff_lift_mk_lt_univ.2 (lt_of_eq_of_lt hS κ.lift_lt_univ')
refine
⟨(equivShrink S).bundledInduced L,
⟨S.subtype.comp (Equiv.bundledInducedEquiv L _).symm.toElementaryEmbedding⟩,
lift_inj.1 (_root_.trans ?_ hS)⟩
simp only [Equiv.bundledInduced_α, lift_mk_shrink']
section
-- Porting note: This instance interrupts synthesizing instances.
attribute [-instance] FirstOrder.Language.withConstants_expansion
/-- The **Upward Löwenheim–Skolem Theorem**: If `κ` is a cardinal greater than the cardinalities of
`L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. -/
theorem exists_elementaryEmbedding_card_eq_of_ge (M : Type w') [L.Structure M] [iM : Infinite M]
(κ : Cardinal.{w}) (h1 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ)
(h2 : Cardinal.lift.{w} #M ≤ Cardinal.lift.{w'} κ) :
∃ N : Bundled L.Structure, Nonempty (M ↪ₑ[L] N) ∧ #N = κ := by
obtain ⟨N0, hN0⟩ := (L.elementaryDiagram M).exists_large_model_of_infinite_model κ M
rw [← lift_le.{max u v}, lift_lift, lift_lift] at h2
obtain ⟨N, ⟨NN0⟩, hN⟩ :=
exists_elementaryEmbedding_card_eq_of_le (L[[M]]) N0 κ
(aleph0_le_lift.1 ((aleph0_le_lift.2 (aleph0_le_mk M)).trans h2))
(by
simp only [card_withConstants, lift_add, lift_lift]
rw [add_comm, add_eq_max (aleph0_le_lift.2 (infinite_iff.1 iM)), max_le_iff]
rw [← lift_le.{w'}, lift_lift, lift_lift] at h1
exact ⟨h2, h1⟩)
(hN0.trans (by rw [← lift_umax', lift_id]))
letI := (lhomWithConstants L M).reduct N
haveI h : N ⊨ L.elementaryDiagram M :=
(NN0.theory_model_iff (L.elementaryDiagram M)).2 inferInstance
refine ⟨Bundled.of N, ⟨?_⟩, hN⟩
apply ElementaryEmbedding.ofModelsElementaryDiagram L M N
end
/-- The Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L`
and an infinite `L`-structure `M`, then there is an elementary embedding in the appropriate
direction between then `M` and a structure of cardinality `κ`. -/
theorem exists_elementaryEmbedding_card_eq (M : Type w') [L.Structure M] [iM : Infinite M]
(κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : Bundled L.Structure, (Nonempty (N ↪ₑ[L] M) ∨ Nonempty (M ↪ₑ[L] N)) ∧ #N = κ := by
cases le_or_gt (lift.{w'} κ) (Cardinal.lift.{w} #M) with
| inl h =>
obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_le L M κ h1 h2 h
exact ⟨N, Or.inl hN1, hN2⟩
| inr h =>
obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_ge L M κ h2 (le_of_lt h)
exact ⟨N, Or.inr hN1, hN2⟩
/-- A consequence of the Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the
cardinalities of `L` and an infinite `L`-structure `M`, then there is a structure of cardinality `κ`
elementarily equivalent to `M`. -/
theorem exists_elementarilyEquivalent_card_eq (M : Type w') [L.Structure M] [Infinite M]
(κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : CategoryTheory.Bundled L.Structure, (M ≅[L] N) ∧ #N = κ := by
obtain ⟨N, NM | MN, hNκ⟩ := exists_elementaryEmbedding_card_eq L M κ h1 h2
· exact ⟨N, NM.some.elementarilyEquivalent.symm, hNκ⟩
· exact ⟨N, MN.some.elementarilyEquivalent, hNκ⟩
variable {L}
namespace Theory
theorem exists_model_card_eq (h : ∃ M : ModelType.{u, v, max u v} T, Infinite M) (κ : Cardinal.{w})
(h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : ModelType.{u, v, w} T, #N = κ := by
cases h with
| intro M MI =>
haveI := MI
obtain ⟨N, hN, rfl⟩ := exists_elementarilyEquivalent_card_eq L M κ h1 h2
haveI : Nonempty N := hN.nonempty
exact ⟨hN.theory_model.bundled, rfl⟩
variable (T)
/-- A theory models a (bounded) formula when any of its nonempty models realizes that formula on all
inputs. -/
def ModelsBoundedFormula (φ : L.BoundedFormula α n) : Prop :=
∀ (M : ModelType.{u, v, max u v} T) (v : α → M) (xs : Fin n → M), φ.Realize v xs
-- Porting note: In Lean3 it was `⊨` but ambiguous.
@[inherit_doc FirstOrder.Language.Theory.ModelsBoundedFormula]
infixl:51 " ⊨ᵇ " => ModelsBoundedFormula -- input using \|= or \vDash, but not using \models
variable {T}
theorem models_formula_iff {φ : L.Formula α} :
T ⊨ᵇ φ ↔ ∀ (M : ModelType.{u, v, max u v} T) (v : α → M), φ.Realize v :=
forall_congr' fun _ => forall_congr' fun _ => Unique.forall_iff
theorem models_sentence_iff {φ : L.Sentence} : T ⊨ᵇ φ ↔ ∀ M : ModelType.{u, v, max u v} T, M ⊨ φ :=
models_formula_iff.trans (forall_congr' fun _ => Unique.forall_iff)
theorem models_sentence_of_mem {φ : L.Sentence} (h : φ ∈ T) : T ⊨ᵇ φ :=
models_sentence_iff.2 fun _ => realize_sentence_of_mem T h
theorem models_iff_not_satisfiable (φ : L.Sentence) : T ⊨ᵇ φ ↔ ¬IsSatisfiable (T ∪ {φ.not}) := by
rw [models_sentence_iff, IsSatisfiable]
refine
⟨fun h1 h2 =>
(Sentence.realize_not _).1
(realize_sentence_of_mem (T ∪ {Formula.not φ})
(Set.subset_union_right (Set.mem_singleton _)))
(h1 (h2.some.subtheoryModel Set.subset_union_left)),
fun h M => ?_⟩
contrapose! h
rw [← Sentence.realize_not] at h
refine
⟨{ Carrier := M
is_model := ⟨fun ψ hψ => hψ.elim (realize_sentence_of_mem _) fun h' => ?_⟩ }⟩
rw [Set.mem_singleton_iff.1 h']
exact h
theorem ModelsBoundedFormula.realize_sentence {φ : L.Sentence} (h : T ⊨ᵇ φ) (M : Type*)
[L.Structure M] [M ⊨ T] [Nonempty M] : M ⊨ φ := by
rw [models_iff_not_satisfiable] at h
contrapose! h
have : M ⊨ T ∪ {Formula.not φ} := by
simp only [Set.union_singleton, model_iff, Set.mem_insert_iff, forall_eq_or_imp,
Sentence.realize_not]
rw [← model_iff]
exact ⟨h, inferInstance⟩
exact Model.isSatisfiable M
theorem models_of_models_theory {T' : L.Theory}
(h : ∀ φ : L.Sentence, φ ∈ T' → T ⊨ᵇ φ)
{φ : L.Formula α} (hφ : T' ⊨ᵇ φ) : T ⊨ᵇ φ := by
simp only [models_sentence_iff] at h
intro M
have hM : M ⊨ T' := T'.model_iff.2 (fun ψ hψ => h ψ hψ M)
let M' : ModelType T' := ⟨M⟩
exact hφ M'
/-- An alternative statement of the Compactness Theorem. A formula `φ` is modeled by a
theory iff there is a finite subset `T0` of the theory such that `φ` is modeled by `T0` -/
theorem models_iff_finset_models {φ : L.Sentence} :
T ⊨ᵇ φ ↔ ∃ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T ∧ (T0 : L.Theory) ⊨ᵇ φ := by
simp only [models_iff_not_satisfiable]
rw [← not_iff_not, not_not, isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable]
push_neg
letI := Classical.decEq (Sentence L)
constructor
· intro h T0 hT0
simpa using h (T0 ∪ {Formula.not φ})
(by
simp only [Finset.coe_union, Finset.coe_singleton]
exact Set.union_subset_union hT0 (Set.Subset.refl _))
· intro h T0 hT0
exact IsSatisfiable.mono (h (T0.erase (Formula.not φ))
(by simpa using hT0)) (by simp)
/-- A theory is complete when it is satisfiable and models each sentence or its negation. -/
def IsComplete (T : L.Theory) : Prop :=
T.IsSatisfiable ∧ ∀ φ : L.Sentence, T ⊨ᵇ φ ∨ T ⊨ᵇ φ.not
namespace IsComplete
theorem models_not_iff (h : T.IsComplete) (φ : L.Sentence) : T ⊨ᵇ φ.not ↔ ¬T ⊨ᵇ φ := by
cases' h.2 φ with hφ hφn
· simp only [hφ, not_true, iff_false_iff]
rw [models_sentence_iff, not_forall]
refine ⟨h.1.some, ?_⟩
simp only [Sentence.realize_not, Classical.not_not]
exact models_sentence_iff.1 hφ _
· simp only [hφn, true_iff_iff]
intro hφ
rw [models_sentence_iff] at *
exact hφn h.1.some (hφ _)
theorem realize_sentence_iff (h : T.IsComplete) (φ : L.Sentence) (M : Type*) [L.Structure M]
[M ⊨ T] [Nonempty M] : M ⊨ φ ↔ T ⊨ᵇ φ := by
cases' h.2 φ with hφ hφn
· exact iff_of_true (hφ.realize_sentence M) hφ
· exact
iff_of_false ((Sentence.realize_not M).1 (hφn.realize_sentence M))
((h.models_not_iff φ).1 hφn)
end IsComplete
/-- A theory is maximal when it is satisfiable and contains each sentence or its negation.
Maximal theories are complete. -/
def IsMaximal (T : L.Theory) : Prop :=
T.IsSatisfiable ∧ ∀ φ : L.Sentence, φ ∈ T ∨ φ.not ∈ T
theorem IsMaximal.isComplete (h : T.IsMaximal) : T.IsComplete :=
h.imp_right (forall_imp fun _ => Or.imp models_sentence_of_mem models_sentence_of_mem)
theorem IsMaximal.mem_or_not_mem (h : T.IsMaximal) (φ : L.Sentence) : φ ∈ T ∨ φ.not ∈ T :=
h.2 φ
theorem IsMaximal.mem_of_models (h : T.IsMaximal) {φ : L.Sentence} (hφ : T ⊨ᵇ φ) : φ ∈ T := by
refine (h.mem_or_not_mem φ).resolve_right fun con => ?_
rw [models_iff_not_satisfiable, Set.union_singleton, Set.insert_eq_of_mem con] at hφ
exact hφ h.1
theorem IsMaximal.mem_iff_models (h : T.IsMaximal) (φ : L.Sentence) : φ ∈ T ↔ T ⊨ᵇ φ :=
⟨models_sentence_of_mem, h.mem_of_models⟩
/-- Two (bounded) formulas are semantically equivalent over a theory `T` when they have the same
interpretation in every model of `T`. (This is also known as logical equivalence, which also has a
proof-theoretic definition.) -/
def SemanticallyEquivalent (T : L.Theory) (φ ψ : L.BoundedFormula α n) : Prop :=
T ⊨ᵇ φ.iff ψ
@[refl]
theorem SemanticallyEquivalent.refl (φ : L.BoundedFormula α n) : T.SemanticallyEquivalent φ φ :=
fun M v xs => by rw [BoundedFormula.realize_iff]
instance : IsRefl (L.BoundedFormula α n) T.SemanticallyEquivalent :=
⟨SemanticallyEquivalent.refl⟩
@[symm]
theorem SemanticallyEquivalent.symm {φ ψ : L.BoundedFormula α n}
(h : T.SemanticallyEquivalent φ ψ) : T.SemanticallyEquivalent ψ φ := fun M v xs => by
rw [BoundedFormula.realize_iff, Iff.comm, ← BoundedFormula.realize_iff]
exact h M v xs
@[trans]
theorem SemanticallyEquivalent.trans {φ ψ θ : L.BoundedFormula α n}
(h1 : T.SemanticallyEquivalent φ ψ) (h2 : T.SemanticallyEquivalent ψ θ) :
T.SemanticallyEquivalent φ θ := fun M v xs => by
have h1' := h1 M v xs
have h2' := h2 M v xs
rw [BoundedFormula.realize_iff] at *
exact ⟨h2'.1 ∘ h1'.1, h1'.2 ∘ h2'.2⟩
theorem SemanticallyEquivalent.realize_bd_iff {φ ψ : L.BoundedFormula α n} {M : Type max u v}
[Nonempty M] [L.Structure M] [T.Model M] (h : T.SemanticallyEquivalent φ ψ)
{v : α → M} {xs : Fin n → M} : φ.Realize v xs ↔ ψ.Realize v xs :=
BoundedFormula.realize_iff.1 (h (ModelType.of T M) v xs)
theorem SemanticallyEquivalent.realize_iff {φ ψ : L.Formula α} {M : Type max u v} [Nonempty M]
[L.Structure M] (_hM : T.Model M) (h : T.SemanticallyEquivalent φ ψ) {v : α → M} :
φ.Realize v ↔ ψ.Realize v :=
h.realize_bd_iff
/-- Semantic equivalence forms an equivalence relation on formulas. -/
def semanticallyEquivalentSetoid (T : L.Theory) : Setoid (L.BoundedFormula α n) where
r := SemanticallyEquivalent T
iseqv := ⟨fun _ => refl _, fun {_ _} h => h.symm, fun {_ _ _} h1 h2 => h1.trans h2⟩
protected theorem SemanticallyEquivalent.all {φ ψ : L.BoundedFormula α (n + 1)}
(h : T.SemanticallyEquivalent φ ψ) : T.SemanticallyEquivalent φ.all ψ.all := by
simp_rw [SemanticallyEquivalent, ModelsBoundedFormula, BoundedFormula.realize_iff,
BoundedFormula.realize_all]
exact fun M v xs => forall_congr' fun a => h.realize_bd_iff
protected theorem SemanticallyEquivalent.ex {φ ψ : L.BoundedFormula α (n + 1)}
(h : T.SemanticallyEquivalent φ ψ) : T.SemanticallyEquivalent φ.ex ψ.ex := by
simp_rw [SemanticallyEquivalent, ModelsBoundedFormula, BoundedFormula.realize_iff,
BoundedFormula.realize_ex]
exact fun M v xs => exists_congr fun a => h.realize_bd_iff
protected theorem SemanticallyEquivalent.not {φ ψ : L.BoundedFormula α n}
(h : T.SemanticallyEquivalent φ ψ) : T.SemanticallyEquivalent φ.not ψ.not := by
simp_rw [SemanticallyEquivalent, ModelsBoundedFormula, BoundedFormula.realize_iff,
BoundedFormula.realize_not]
exact fun M v xs => not_congr h.realize_bd_iff
protected theorem SemanticallyEquivalent.imp {φ ψ φ' ψ' : L.BoundedFormula α n}
(h : T.SemanticallyEquivalent φ ψ) (h' : T.SemanticallyEquivalent φ' ψ') :
T.SemanticallyEquivalent (φ.imp φ') (ψ.imp ψ') := by
simp_rw [SemanticallyEquivalent, ModelsBoundedFormula, BoundedFormula.realize_iff,
BoundedFormula.realize_imp]
exact fun M v xs => imp_congr h.realize_bd_iff h'.realize_bd_iff
end Theory
namespace completeTheory
variable (L) (M : Type w)
variable [L.Structure M]
theorem isSatisfiable [Nonempty M] : (L.completeTheory M).IsSatisfiable :=
Theory.Model.isSatisfiable M
theorem mem_or_not_mem (φ : L.Sentence) : φ ∈ L.completeTheory M ∨ φ.not ∈ L.completeTheory M := by
simp_rw [completeTheory, Set.mem_setOf_eq, Sentence.Realize, Formula.realize_not, or_not]
theorem isMaximal [Nonempty M] : (L.completeTheory M).IsMaximal :=
⟨isSatisfiable L M, mem_or_not_mem L M⟩
theorem isComplete [Nonempty M] : (L.completeTheory M).IsComplete :=
(completeTheory.isMaximal L M).isComplete
end completeTheory
namespace BoundedFormula
variable (φ ψ : L.BoundedFormula α n)
theorem semanticallyEquivalent_not_not : T.SemanticallyEquivalent φ φ.not.not := fun M v xs => by
simp
theorem imp_semanticallyEquivalent_not_sup : T.SemanticallyEquivalent (φ.imp ψ) (φ.not ⊔ ψ) :=
fun M v xs => by simp [imp_iff_not_or]
theorem sup_semanticallyEquivalent_not_inf_not :
T.SemanticallyEquivalent (φ ⊔ ψ) (φ.not ⊓ ψ.not).not := fun M v xs => by simp [imp_iff_not_or]
theorem inf_semanticallyEquivalent_not_sup_not :
T.SemanticallyEquivalent (φ ⊓ ψ) (φ.not ⊔ ψ.not).not := fun M v xs => by
simp
theorem all_semanticallyEquivalent_not_ex_not (φ : L.BoundedFormula α (n + 1)) :
T.SemanticallyEquivalent φ.all φ.not.ex.not := fun M v xs => by simp
theorem ex_semanticallyEquivalent_not_all_not (φ : L.BoundedFormula α (n + 1)) :
T.SemanticallyEquivalent φ.ex φ.not.all.not := fun M v xs => by simp
theorem semanticallyEquivalent_all_liftAt : T.SemanticallyEquivalent φ (φ.liftAt 1 n).all :=
fun M v xs => by
rw [realize_iff, realize_all_liftAt_one_self]
end BoundedFormula
namespace Formula
variable (φ ψ : L.Formula α)
theorem semanticallyEquivalent_not_not : T.SemanticallyEquivalent φ φ.not.not :=
BoundedFormula.semanticallyEquivalent_not_not φ
theorem imp_semanticallyEquivalent_not_sup : T.SemanticallyEquivalent (φ.imp ψ) (φ.not ⊔ ψ) :=
BoundedFormula.imp_semanticallyEquivalent_not_sup φ ψ
theorem sup_semanticallyEquivalent_not_inf_not :
T.SemanticallyEquivalent (φ ⊔ ψ) (φ.not ⊓ ψ.not).not :=
BoundedFormula.sup_semanticallyEquivalent_not_inf_not φ ψ
theorem inf_semanticallyEquivalent_not_sup_not :
T.SemanticallyEquivalent (φ ⊓ ψ) (φ.not ⊔ ψ.not).not :=
BoundedFormula.inf_semanticallyEquivalent_not_sup_not φ ψ
end Formula
end Language
end FirstOrder
namespace Cardinal
open FirstOrder FirstOrder.Language
variable {L : Language.{u, v}} (κ : Cardinal.{w}) (T : L.Theory)
/-- A theory is `κ`-categorical if all models of size `κ` are isomorphic. -/
def Categorical : Prop :=
∀ M N : T.ModelType, #M = κ → #N = κ → Nonempty (M ≃[L] N)
/-- The Łoś–Vaught Test : a criterion for categorical theories to be complete. -/
theorem Categorical.isComplete (h : κ.Categorical T) (h1 : ℵ₀ ≤ κ)
(h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (hS : T.IsSatisfiable)
(hT : ∀ M : Theory.ModelType.{u, v, max u v} T, Infinite M) : T.IsComplete :=
⟨hS, fun φ => by
obtain ⟨_, _⟩ := Theory.exists_model_card_eq ⟨hS.some, hT hS.some⟩ κ h1 h2
rw [Theory.models_sentence_iff, Theory.models_sentence_iff]
by_contra! con
obtain ⟨⟨MF, hMF⟩, MT, hMT⟩ := con
rw [Sentence.realize_not, Classical.not_not] at hMT
refine hMF ?_
haveI := hT MT
haveI := hT MF
obtain ⟨NT, MNT, hNT⟩ := exists_elementarilyEquivalent_card_eq L MT κ h1 h2
obtain ⟨NF, MNF, hNF⟩ := exists_elementarilyEquivalent_card_eq L MF κ h1 h2
obtain ⟨TF⟩ := h (MNT.toModel T) (MNF.toModel T) hNT hNF
exact
((MNT.realize_sentence φ).trans
((TF.realize_sentence φ).trans (MNF.realize_sentence φ).symm)).1 hMT⟩
theorem empty_theory_categorical (T : Language.empty.Theory) : κ.Categorical T := fun M N hM hN =>
by rw [empty.nonempty_equiv_iff, hM, hN]
theorem empty_infinite_Theory_isComplete : Language.empty.infiniteTheory.IsComplete :=
(empty_theory_categorical.{0} ℵ₀ _).isComplete ℵ₀ _ le_rfl (by simp)
⟨Theory.Model.bundled ((model_infiniteTheory_iff Language.empty).2
(inferInstanceAs (Infinite ℕ)))⟩ fun M =>
(model_infiniteTheory_iff Language.empty).1 M.is_model
end Cardinal
|
ModelTheory\Semantics.lean | /-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Finset.Basic
import Mathlib.ModelTheory.Syntax
import Mathlib.Data.List.ProdSigma
/-!
# Basics on First-Order Semantics
This file defines the interpretations of first-order terms, formulas, sentences, and theories
in a style inspired by the [Flypitch project](https://flypitch.github.io/).
## Main Definitions
- `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at
variables `v`.
- `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded
formula `φ` evaluated at tuples of variables `v` and `xs`.
- `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ`
evaluated at variables `v`.
- `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ`
evaluated in the structure `M`. Also denoted `M ⊨ φ`.
- `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every
sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`.
## Main Results
- Several results in this file show that syntactic constructions such as `relabel`, `castLE`,
`liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas,
sentences, and theories.
## Implementation Notes
- Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder Cardinal
open Structure Cardinal Fin
namespace Term
-- Porting note: universes in different order
/-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/
def realize (v : α → M) : ∀ _t : L.Term α, M
| var k => v k
| func f ts => funMap f fun i => (ts i).realize v
/- Porting note: The equation lemma of `realize` is too strong; it simplifies terms like the LHS of
`realize_functions_apply₁`. Even `eqns` can't fix this. We removed `simp` attr from `realize` and
prepare new simp lemmas for `realize`. -/
@[simp]
theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl
@[simp]
theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) :
realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl
@[simp]
theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} :
(t.relabel g).realize v = t.realize (v ∘ g) := by
induction' t with _ n f ts ih
· rfl
· simp [ih]
@[simp]
theorem realize_liftAt {n n' m : ℕ} {t : L.Term (α ⊕ (Fin n))} {v : α ⊕ (Fin (n + n')) → M} :
(t.liftAt n' m).realize v =
t.realize (v ∘ Sum.map id fun i : Fin _ =>
if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') :=
realize_relabel
@[simp]
theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c :=
funMap_eq_coe_constants
@[simp]
theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} :
(f.apply₁ t).realize v = funMap f ![t.realize v] := by
rw [Functions.apply₁, Term.realize]
refine congr rfl (funext fun i => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} :
(f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by
rw [Functions.apply₂, Term.realize]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a :=
rfl
@[simp]
theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} :
(t.subst tf).realize v = t.realize fun a => (tf a).realize v := by
induction' t with _ _ _ _ ih
· rfl
· simp [ih]
@[simp]
theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s)
{v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := by
induction' t with _ _ _ _ ih
· rfl
· simp_rw [varFinset, Finset.coe_biUnion, Set.iUnion_subset_iff] at h
exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i)))
@[simp]
theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {s : Set α}
(h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} :
(t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) =
t.realize (Sum.elim v xs) := by
induction' t with a _ _ _ ih
· cases a <;> rfl
· simp_rw [varFinsetLeft, Finset.coe_biUnion, Set.iUnion_subset_iff] at h
exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i)))
@[simp]
theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L[[α]].Term β} {v : β → M} :
t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by
induction' t with _ n f ts ih
· simp
· cases n
· cases f
· simp only [realize, ih, Nat.zero_eq, constantsOn, mk₂_Functions]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sum_inl]
· simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants]
rfl
· cases' f with _ f
· simp only [realize, ih, constantsOn, mk₂_Functions]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sum_inl]
· exact isEmptyElim f
@[simp]
theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L.Term (α ⊕ β)} {v : β → M} :
t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by
induction' t with ab n f ts ih
· cases' ab with a b
-- Porting note: both cases were `simp [Language.con]`
· simp [Language.con, realize, funMap_eq_coe_constants]
· simp [realize, constantMap]
· simp only [realize, constantsOn, mk₂_Functions, ih]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sum_inl]
theorem realize_constantsVarsEquivLeft [L[[α]].Structure M]
[(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (β ⊕ (Fin n))} {v : β → M}
{xs : Fin n → M} :
(constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) =
t.realize (Sum.elim v xs) := by
simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply,
constantsVarsEquiv_apply, relabelEquiv_symm_apply]
refine _root_.trans ?_ realize_constantsToVars
rcongr x
rcases x with (a | (b | i)) <;> simp
end Term
namespace LHom
@[simp]
theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α)
(v : α → M) : (φ.onTerm t).realize v = t.realize v := by
induction' t with _ n f ts ih
· rfl
· simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih]
end LHom
@[simp]
theorem Hom.realize_term (g : M →[L] N) {t : L.Term α} {v : α → M} :
t.realize (g ∘ v) = g (t.realize v) := by
induction t
· rfl
· rw [Term.realize, Term.realize, g.map_fun]
refine congr rfl ?_
ext x
simp [*]
@[simp]
theorem Embedding.realize_term {v : α → M} (t : L.Term α) (g : M ↪[L] N) :
t.realize (g ∘ v) = g (t.realize v) :=
g.toHom.realize_term
@[simp]
theorem Equiv.realize_term {v : α → M} (t : L.Term α) (g : M ≃[L] N) :
t.realize (g ∘ v) = g (t.realize v) :=
g.toHom.realize_term
variable {n : ℕ}
namespace BoundedFormula
open Term
-- Porting note: universes in different order
/-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/
def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop
| _, falsum, _v, _xs => False
| _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs)
| _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs)
| _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs
| _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x)
variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ}
variable {v : α → M} {xs : Fin l → M}
@[simp]
theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False :=
Iff.rfl
@[simp]
theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs :=
Iff.rfl
@[simp]
theorem realize_bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin l))) :
(t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) :=
Iff.rfl
@[simp]
theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top]
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by
simp [Inf.inf, Realize]
@[simp]
theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp [ih]
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by
simp only [Realize]
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} :
(R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) :=
Iff.rfl
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.boundedFormula₂ t₁ t₂).Realize v xs ↔
RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by
simp only [realize, Sup.sup, realize_not, eq_iff_iff]
tauto
@[simp]
theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or,
exists_eq_left]
@[simp]
theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) :=
Iff.rfl
@[simp]
theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by
rw [BoundedFormula.ex, realize_not, realize_all, not_forall]
simp_rw [realize_not, Classical.not_not]
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by
simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def]
theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m}
{v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ cast h) := by
subst h
simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id]
theorem realize_mapTermRel_id [L'.Structure M]
{ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M}
{v' : β → M} {xs : Fin n → M}
(h1 :
∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs : Fin n → M),
(ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) :
(φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih
· rfl
· simp [mapTermRel, Realize, h1]
· simp [mapTermRel, Realize, h1, h2]
· simp [mapTermRel, Realize, ih1, ih2]
· simp only [mapTermRel, Realize, ih, id]
theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ}
{ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (k + n)))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n}
(v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M)
(h1 :
∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs' : Fin (k + n) → M),
(ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _)))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x)
(hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) :
(φ.mapTermRel ft fr fun n => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔
φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih
· rfl
· simp [mapTermRel, Realize, h1]
· simp [mapTermRel, Realize, h1, h2]
· simp [mapTermRel, Realize, ih1, ih2]
· simp [mapTermRel, Realize, ih, hv]
@[simp]
theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → β ⊕ (Fin m)} {v : β → M}
{xs : Fin (m + n) → M} :
(φ.relabel g).Realize v xs ↔
φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by
rw [relabel, realize_mapTermRel_add_castLe] <;> intros <;> simp
theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M}
(hmn : m + n' ≤ n + 1) :
(φ.liftAt n' m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by
rw [liftAt]
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 k _ ih3
· simp [mapTermRel, Realize]
· simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
· simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
· simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn]
· have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc]
simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)]
refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_)))
· simp only [Function.comp_apply, val_last, snoc_last]
by_cases h : k < m
· rw [if_pos h]
refine (congr rfl (Fin.ext ?_)).trans (snoc_last _ _)
simp only [coe_cast, coe_castAdd, val_last, self_eq_add_right]
refine le_antisymm
(le_of_add_le_add_left ((hmn.trans (Nat.succ_le_of_lt h)).trans ?_)) n'.zero_le
rw [add_zero]
· rw [if_neg h]
refine (congr rfl (Fin.ext ?_)).trans (snoc_last _ _)
simp
· simp only [Function.comp_apply, Fin.snoc_castSucc]
refine (congr rfl (Fin.ext ?_)).trans (snoc_castSucc _ _ _)
simp only [coe_castSucc, coe_cast]
split_ifs <;> simp
theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M}
(hmn : m ≤ n) :
(φ.liftAt 1 m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by
simp [realize_liftAt (add_le_add_right hmn 1), castSucc]
@[simp]
theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by
rw [realize_liftAt_one (refl n), iff_eq_eq]
refine congr rfl (congr rfl (funext fun i => ?_))
rw [if_pos i.is_lt]
@[simp]
theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} :
(φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs :=
realize_mapTermRel_id
(fun n t x => by
rw [Term.realize_subst]
rcongr a
cases a
· simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl]
· rfl)
(by simp)
@[simp]
theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α}
(h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} :
(φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp [restrictFreeVar, Realize]
· simp [restrictFreeVar, Realize]
· simp [restrictFreeVar, Realize, ih1, ih2]
· simp [restrictFreeVar, Realize, ih3]
theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} :
(constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by
refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← (lhomWithConstants L α).map_onRelation
(Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs]
rcongr
cases' R with R R
· simp
· exact isEmptyElim R
@[simp]
theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M}
{xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by
simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl]
refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl
simp only [relabelEquiv_apply, Term.realize_relabel]
refine congr (congr rfl ?_) rfl
ext (i | i) <;> rfl
variable [Nonempty M]
theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by
inhabit M
simp only [realize_all, realize_liftAt_one_self]
refine ⟨fun h => ?_, fun h a => ?_⟩
· refine (congr rfl (funext fun i => ?_)).mp (h default)
simp
· refine (congr rfl (funext fun i => ?_)).mp h
simp
end BoundedFormula
-- Porting note: no `protected` attribute in Lean4
-- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel
-- attribute [protected] bounded_formula.imp bounded_formula.all
namespace LHom
open BoundedFormula
@[simp]
theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ}
(ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} :
(φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by
induction' ψ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp only [onBoundedFormula, realize_bdEqual, realize_onTerm]
rfl
· simp only [onBoundedFormula, realize_rel, LHom.map_onRelation,
Function.comp_apply, realize_onTerm]
rfl
· simp only [onBoundedFormula, ih1, ih2, realize_imp]
· simp only [onBoundedFormula, ih3, realize_all]
end LHom
-- Porting note: no `protected` attribute in Lean4
-- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel
-- attribute [protected] bounded_formula.imp bounded_formula.all
namespace Formula
/-- A formula can be evaluated as true or false by giving values to each free variable. -/
nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop :=
φ.Realize v default
variable {φ ψ : L.Formula α} {v : α → M}
@[simp]
theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v :=
Iff.rfl
@[simp]
theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False :=
Iff.rfl
@[simp]
theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True :=
BoundedFormula.realize_top
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v :=
BoundedFormula.realize_inf
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v :=
BoundedFormula.realize_imp
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} :
(R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v :=
BoundedFormula.realize_rel.trans (by simp)
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by
rw [Relations.formula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by
rw [Relations.formula₂, realize_rel, iff_eq_eq]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v :=
BoundedFormula.realize_sup
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) :=
BoundedFormula.realize_iff
@[simp]
theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} :
(φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by
rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero]
exact congr rfl (funext finZeroElim)
theorem realize_relabel_sum_inr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} :
(BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by
rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero,
cast_refl, Function.comp_id,
Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default]
@[simp]
theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} :
(t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize]
@[simp]
theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} :
(Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by
simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ]
rw [eq_comm]
end Formula
@[simp]
theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α)
{v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v :=
φ.realize_onBoundedFormula ψ
@[simp]
theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M]
(ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by
ext
simp
variable (M)
/-- A sentence can be evaluated as true or false in a structure. -/
nonrec def Sentence.Realize (φ : L.Sentence) : Prop :=
φ.Realize (default : _ → M)
-- input using \|= or \vDash, but not using \models
@[inherit_doc Sentence.Realize]
infixl:51 " ⊨ " => Sentence.Realize
@[simp]
theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ :=
Iff.rfl
namespace Formula
@[simp]
theorem realize_equivSentence_symm_con [L[[α]].Structure M]
[(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) :
((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by
simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize,
BoundedFormula.realize_relabelEquiv, Function.comp]
refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv
rw [iff_iff_eq]
congr with (_ | a)
· simp
· cases a
@[simp]
theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M]
(φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by
rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply]
theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) :
(equivSentence.symm φ).Realize v ↔
@Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v))
φ :=
letI := constantsOn.structure v
realize_equivSentence_symm_con M φ
end Formula
@[simp]
theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M]
(ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ :=
φ.realize_onFormula ψ
variable (L)
/-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/
def completeTheory : L.Theory :=
{ φ | M ⊨ φ }
variable (N)
/-- Two structures are elementarily equivalent when they satisfy the same sentences. -/
def ElementarilyEquivalent : Prop :=
L.completeTheory M = L.completeTheory N
@[inherit_doc FirstOrder.Language.ElementarilyEquivalent]
scoped[FirstOrder]
notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B
variable {L} {M} {N}
@[simp]
theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ :=
Iff.rfl
theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by
simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq]
variable (M)
/-- A model of a theory is a structure in which every sentence is realized as true. -/
class Theory.Model (T : L.Theory) : Prop where
realize_of_mem : ∀ φ ∈ T, M ⊨ φ
-- input using \|= or \vDash, but not using \models
@[inherit_doc Theory.Model]
infixl:51 " ⊨ " => Theory.Model
variable {M} (T : L.Theory)
@[simp default-10]
theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ :=
⟨fun h => h.realize_of_mem, fun h => ⟨h⟩⟩
theorem Theory.realize_sentence_of_mem [M ⊨ T] {φ : L.Sentence} (h : φ ∈ T) : M ⊨ φ :=
Theory.Model.realize_of_mem φ h
@[simp]
theorem LHom.onTheory_model [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (T : L.Theory) :
M ⊨ φ.onTheory T ↔ M ⊨ T := by simp [Theory.model_iff, LHom.onTheory]
variable {T}
instance model_empty : M ⊨ (∅ : L.Theory) :=
⟨fun φ hφ => (Set.not_mem_empty φ hφ).elim⟩
namespace Theory
theorem Model.mono {T' : L.Theory} (_h : M ⊨ T') (hs : T ⊆ T') : M ⊨ T :=
⟨fun _φ hφ => T'.realize_sentence_of_mem (hs hφ)⟩
theorem Model.union {T' : L.Theory} (h : M ⊨ T) (h' : M ⊨ T') : M ⊨ T ∪ T' := by
simp only [model_iff, Set.mem_union] at *
exact fun φ hφ => hφ.elim (h _) (h' _)
@[simp]
theorem model_union_iff {T' : L.Theory} : M ⊨ T ∪ T' ↔ M ⊨ T ∧ M ⊨ T' :=
⟨fun h => ⟨h.mono Set.subset_union_left, h.mono Set.subset_union_right⟩, fun h =>
h.1.union h.2⟩
theorem model_singleton_iff {φ : L.Sentence} : M ⊨ ({φ} : L.Theory) ↔ M ⊨ φ := by simp
theorem model_iff_subset_completeTheory : M ⊨ T ↔ T ⊆ L.completeTheory M :=
T.model_iff
theorem completeTheory.subset [MT : M ⊨ T] : T ⊆ L.completeTheory M :=
model_iff_subset_completeTheory.1 MT
end Theory
instance model_completeTheory : M ⊨ L.completeTheory M :=
Theory.model_iff_subset_completeTheory.2 (subset_refl _)
variable (M N)
theorem realize_iff_of_model_completeTheory [N ⊨ L.completeTheory M] (φ : L.Sentence) :
N ⊨ φ ↔ M ⊨ φ := by
refine ⟨fun h => ?_, (L.completeTheory M).realize_sentence_of_mem⟩
contrapose! h
rw [← Sentence.realize_not] at *
exact (L.completeTheory M).realize_sentence_of_mem (mem_completeTheory.2 h)
variable {M N}
namespace BoundedFormula
@[simp]
theorem realize_alls {φ : L.BoundedFormula α n} {v : α → M} :
φ.alls.Realize v ↔ ∀ xs : Fin n → M, φ.Realize v xs := by
induction' n with n ih
· exact Unique.forall_iff.symm
· simp only [alls, ih, Realize]
exact ⟨fun h xs => Fin.snoc_init_self xs ▸ h _ _, fun h xs x => h (Fin.snoc xs x)⟩
@[simp]
theorem realize_exs {φ : L.BoundedFormula α n} {v : α → M} :
φ.exs.Realize v ↔ ∃ xs : Fin n → M, φ.Realize v xs := by
induction' n with n ih
· exact Unique.exists_iff.symm
· simp only [BoundedFormula.exs, ih, realize_ex]
constructor
· rintro ⟨xs, x, h⟩
exact ⟨_, h⟩
· rintro ⟨xs, h⟩
rw [← Fin.snoc_init_self xs] at h
exact ⟨_, _, h⟩
@[simp]
theorem _root_.FirstOrder.Language.Formula.realize_iAlls
[Finite γ] {f : α → β ⊕ γ}
{φ : L.Formula α} {v : β → M} : (φ.iAlls f).Realize v ↔
∀ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by
let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ))
rw [Formula.iAlls]
simp only [Nat.add_zero, realize_alls, realize_relabel, Function.comp,
castAdd_zero, finCongr_refl, OrderIso.refl_apply, Sum.elim_map, id_eq]
refine Equiv.forall_congr ?_ ?_
· exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm,
fun _ => by simp [Function.comp],
fun _ => by simp [Function.comp]⟩
· intro x
rw [Formula.Realize, iff_iff_eq]
congr
funext i
exact i.elim0
@[simp]
theorem realize_iAlls [Finite γ] {f : α → β ⊕ γ}
{φ : L.Formula α} {v : β → M} {v' : Fin 0 → M} :
BoundedFormula.Realize (φ.iAlls f) v v' ↔
∀ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by
rw [← Formula.realize_iAlls, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton]
@[simp]
theorem _root_.FirstOrder.Language.Formula.realize_iExs
[Finite γ] {f : α → β ⊕ γ}
{φ : L.Formula α} {v : β → M} : (φ.iExs f).Realize v ↔
∃ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by
let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ))
rw [Formula.iExs]
simp only [Nat.add_zero, realize_exs, realize_relabel, Function.comp,
castAdd_zero, finCongr_refl, OrderIso.refl_apply, Sum.elim_map, id_eq]
rw [← not_iff_not, not_exists, not_exists]
refine Equiv.forall_congr ?_ ?_
· exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm,
fun _ => by simp [Function.comp],
fun _ => by simp [Function.comp]⟩
· intro x
rw [Formula.Realize, iff_iff_eq]
congr
funext i
exact i.elim0
@[simp]
theorem realize_iExs [Finite γ] {f : α → β ⊕ γ}
{φ : L.Formula α} {v : β → M} {v' : Fin 0 → M} :
BoundedFormula.Realize (φ.iExs f) v v' ↔
∃ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by
rw [← Formula.realize_iExs, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton]
@[simp]
theorem realize_toFormula (φ : L.BoundedFormula α n) (v : α ⊕ (Fin n) → M) :
φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 a8 a9 a0
· rfl
· simp [BoundedFormula.Realize]
· simp [BoundedFormula.Realize]
· rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2,
realize_imp]
· rw [toFormula, Formula.Realize, realize_all, realize_all]
refine forall_congr' fun a => ?_
have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a))
simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h
rw [← h, realize_relabel, Formula.Realize, iff_iff_eq]
simp only [Function.comp]
congr with x
· cases' x with _ x
· simp
· refine Fin.lastCases ?_ ?_ x
· rw [Sum.elim_inr, Sum.elim_inr,
finSumFinEquiv_symm_last, Sum.map_inr, Sum.elim_inr]
simp [Fin.snoc]
· simp only [castSucc, Function.comp_apply, Sum.elim_inr,
finSumFinEquiv_symm_apply_castAdd, Sum.map_inl, Sum.elim_inl]
rw [← castSucc]
simp
· exact Fin.elim0 x
@[simp]
theorem realize_iSup (s : Finset β) (f : β → L.BoundedFormula α n)
(v : α → M) (v' : Fin n → M) :
(iSup s f).Realize v v' ↔ ∃ b ∈ s, (f b).Realize v v' := by
simp only [iSup, realize_foldr_sup, List.mem_map, Finset.mem_toList,
exists_exists_and_eq_and]
@[simp]
theorem realize_iInf (s : Finset β) (f : β → L.BoundedFormula α n)
(v : α → M) (v' : Fin n → M) :
(iInf s f).Realize v v' ↔ ∀ b ∈ s, (f b).Realize v v' := by
simp only [iInf, realize_foldr_inf, List.mem_map, Finset.mem_toList,
forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
end BoundedFormula
namespace Equiv
@[simp]
theorem realize_boundedFormula (g : M ≃[L] N) (φ : L.BoundedFormula α n) {v : α → M}
{xs : Fin n → M} : φ.Realize (g ∘ v) (g ∘ xs) ↔ φ.Realize v xs := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp only [BoundedFormula.Realize, ← Sum.comp_elim, Equiv.realize_term, g.injective.eq_iff]
· simp only [BoundedFormula.Realize, ← Sum.comp_elim, Equiv.realize_term]
exact g.map_rel _ _
· rw [BoundedFormula.Realize, ih1, ih2, BoundedFormula.Realize]
· rw [BoundedFormula.Realize, BoundedFormula.Realize]
constructor
· intro h a
have h' := h (g a)
rw [← Fin.comp_snoc, ih3] at h'
exact h'
· intro h a
have h' := h (g.symm a)
rw [← ih3, Fin.comp_snoc, g.apply_symm_apply] at h'
exact h'
@[simp]
theorem realize_formula (g : M ≃[L] N) (φ : L.Formula α) {v : α → M} :
φ.Realize (g ∘ v) ↔ φ.Realize v := by
rw [Formula.Realize, Formula.Realize, ← g.realize_boundedFormula φ, iff_eq_eq,
Unique.eq_default (g ∘ default)]
theorem realize_sentence (g : M ≃[L] N) (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ := by
rw [Sentence.Realize, Sentence.Realize, ← g.realize_formula, Unique.eq_default (g ∘ default)]
theorem theory_model (g : M ≃[L] N) [M ⊨ T] : N ⊨ T :=
⟨fun φ hφ => (g.realize_sentence φ).1 (Theory.realize_sentence_of_mem T hφ)⟩
theorem elementarilyEquivalent (g : M ≃[L] N) : M ≅[L] N :=
elementarilyEquivalent_iff.2 g.realize_sentence
end Equiv
namespace Relations
open BoundedFormula
variable {r : L.Relations 2}
@[simp]
theorem realize_reflexive : M ⊨ r.reflexive ↔ Reflexive fun x y : M => RelMap r ![x, y] :=
forall_congr' fun _ => realize_rel₂
@[simp]
theorem realize_irreflexive : M ⊨ r.irreflexive ↔ Irreflexive fun x y : M => RelMap r ![x, y] :=
forall_congr' fun _ => not_congr realize_rel₂
@[simp]
theorem realize_symmetric : M ⊨ r.symmetric ↔ Symmetric fun x y : M => RelMap r ![x, y] :=
forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ realize_rel₂
@[simp]
theorem realize_antisymmetric :
M ⊨ r.antisymmetric ↔ AntiSymmetric fun x y : M => RelMap r ![x, y] :=
forall_congr' fun _ =>
forall_congr' fun _ => imp_congr realize_rel₂ (imp_congr realize_rel₂ Iff.rfl)
@[simp]
theorem realize_transitive : M ⊨ r.transitive ↔ Transitive fun x y : M => RelMap r ![x, y] :=
forall_congr' fun _ =>
forall_congr' fun _ =>
forall_congr' fun _ => imp_congr realize_rel₂ (imp_congr realize_rel₂ realize_rel₂)
@[simp]
theorem realize_total : M ⊨ r.total ↔ Total fun x y : M => RelMap r ![x, y] :=
forall_congr' fun _ =>
forall_congr' fun _ => realize_sup.trans (or_congr realize_rel₂ realize_rel₂)
end Relations
section Cardinality
variable (L)
@[simp]
theorem Sentence.realize_cardGe (n) : M ⊨ Sentence.cardGe L n ↔ ↑n ≤ #M := by
rw [← lift_mk_fin, ← lift_le.{0}, lift_lift, lift_mk_le, Sentence.cardGe, Sentence.Realize,
BoundedFormula.realize_exs]
simp_rw [BoundedFormula.realize_foldr_inf]
simp only [Function.comp_apply, List.mem_map, Prod.exists, Ne, List.mem_product,
List.mem_finRange, forall_exists_index, and_imp, List.mem_filter, true_and_iff]
refine ⟨?_, fun xs => ⟨xs.some, ?_⟩⟩
· rintro ⟨xs, h⟩
refine ⟨⟨xs, fun i j ij => ?_⟩⟩
contrapose! ij
have hij := h _ i j (by simpa using ij) rfl
simp only [BoundedFormula.realize_not, Term.realize, BoundedFormula.realize_bdEqual,
Sum.elim_inr] at hij
exact hij
· rintro _ i j ij rfl
simpa using ij
@[simp]
theorem model_infiniteTheory_iff : M ⊨ L.infiniteTheory ↔ Infinite M := by
simp [infiniteTheory, infinite_iff, aleph0_le]
instance model_infiniteTheory [h : Infinite M] : M ⊨ L.infiniteTheory :=
L.model_infiniteTheory_iff.2 h
@[simp]
theorem model_nonemptyTheory_iff : M ⊨ L.nonemptyTheory ↔ Nonempty M := by
simp only [nonemptyTheory, Theory.model_iff, Set.mem_singleton_iff, forall_eq,
Sentence.realize_cardGe, Nat.cast_one, one_le_iff_ne_zero, mk_ne_zero_iff]
instance model_nonempty [h : Nonempty M] : M ⊨ L.nonemptyTheory :=
L.model_nonemptyTheory_iff.2 h
theorem model_distinctConstantsTheory {M : Type w} [L[[α]].Structure M] (s : Set α) :
M ⊨ L.distinctConstantsTheory s ↔ Set.InjOn (fun i : α => (L.con i : M)) s := by
simp only [distinctConstantsTheory, Theory.model_iff, Set.mem_image, Set.mem_inter,
Set.mem_prod, Set.mem_compl, Prod.exists, forall_exists_index, and_imp]
refine ⟨fun h a as b bs ab => ?_, ?_⟩
· contrapose! ab
have h' := h _ a b ⟨⟨as, bs⟩, ab⟩ rfl
simp only [Sentence.Realize, Formula.realize_not, Formula.realize_equal,
Term.realize_constants] at h'
exact h'
· rintro h φ a b ⟨⟨as, bs⟩, ab⟩ rfl
simp only [Sentence.Realize, Formula.realize_not, Formula.realize_equal, Term.realize_constants]
exact fun contra => ab (h as bs contra)
theorem card_le_of_model_distinctConstantsTheory (s : Set α) (M : Type w) [L[[α]].Structure M]
[h : M ⊨ L.distinctConstantsTheory s] : Cardinal.lift.{w} #s ≤ Cardinal.lift.{u'} #M :=
lift_mk_le'.2 ⟨⟨_, Set.injOn_iff_injective.1 ((L.model_distinctConstantsTheory s).1 h)⟩⟩
end Cardinality
namespace ElementarilyEquivalent
@[symm]
nonrec theorem symm (h : M ≅[L] N) : N ≅[L] M :=
h.symm
@[trans]
nonrec theorem trans (MN : M ≅[L] N) (NP : N ≅[L] P) : M ≅[L] P :=
MN.trans NP
theorem completeTheory_eq (h : M ≅[L] N) : L.completeTheory M = L.completeTheory N :=
h
theorem realize_sentence (h : M ≅[L] N) (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ :=
(elementarilyEquivalent_iff.1 h) φ
theorem theory_model_iff (h : M ≅[L] N) : M ⊨ T ↔ N ⊨ T := by
rw [Theory.model_iff_subset_completeTheory, Theory.model_iff_subset_completeTheory,
h.completeTheory_eq]
theorem theory_model [MT : M ⊨ T] (h : M ≅[L] N) : N ⊨ T :=
h.theory_model_iff.1 MT
theorem nonempty_iff (h : M ≅[L] N) : Nonempty M ↔ Nonempty N :=
(model_nonemptyTheory_iff L).symm.trans (h.theory_model_iff.trans (model_nonemptyTheory_iff L))
theorem nonempty [Mn : Nonempty M] (h : M ≅[L] N) : Nonempty N :=
h.nonempty_iff.1 Mn
theorem infinite_iff (h : M ≅[L] N) : Infinite M ↔ Infinite N :=
(model_infiniteTheory_iff L).symm.trans (h.theory_model_iff.trans (model_infiniteTheory_iff L))
theorem infinite [Mi : Infinite M] (h : M ≅[L] N) : Infinite N :=
h.infinite_iff.1 Mi
end ElementarilyEquivalent
end Language
end FirstOrder
|
ModelTheory\Skolem.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.ElementarySubstructures
/-!
# Skolem Functions and Downward Löwenheim–Skolem
## Main Definitions
- `FirstOrder.Language.skolem₁` is a language consisting of Skolem functions for another language.
## Main Results
- `FirstOrder.Language.exists_elementarySubstructure_card_eq` is the Downward Löwenheim–Skolem
theorem: If `s` is a set in an `L`-structure `M` and `κ` an infinite cardinal such that
`max (#s, L.card) ≤ κ` and `κ ≤ # M`, then `M` has an elementary substructure containing `s` of
cardinality `κ`.
## TODO
- Use `skolem₁` recursively to construct an actual Skolemization of a language.
-/
universe u v w w'
namespace FirstOrder
namespace Language
open Structure Cardinal
open Cardinal
variable (L : Language.{u, v}) {M : Type w} [Nonempty M] [L.Structure M]
/-- A language consisting of Skolem functions for another language.
Called `skolem₁` because it is the first step in building a Skolemization of a language. -/
@[simps]
def skolem₁ : Language :=
⟨fun n => L.BoundedFormula Empty (n + 1), fun _ => Empty⟩
variable {L}
theorem card_functions_sum_skolem₁ :
#(Σ n, (L.sum L.skolem₁).Functions n) = #(Σ n, L.BoundedFormula Empty (n + 1)) := by
simp only [card_functions_sum, skolem₁_Functions, mk_sigma, sum_add_distrib']
conv_lhs => enter [2, 1, i]; rw [lift_id'.{u, v}]
rw [add_comm, add_eq_max, max_eq_left]
· refine sum_le_sum _ _ fun n => ?_
rw [← lift_le.{_, max u v}, lift_lift, lift_mk_le.{v}]
refine ⟨⟨fun f => (func f default).bdEqual (func f default), fun f g h => ?_⟩⟩
rcases h with ⟨rfl, ⟨rfl⟩⟩
rfl
· rw [← mk_sigma]
exact infinite_iff.1 (Infinite.of_injective (fun n => ⟨n, ⊥⟩) fun x y xy =>
(Sigma.mk.inj_iff.1 xy).1)
theorem card_functions_sum_skolem₁_le : #(Σ n, (L.sum L.skolem₁).Functions n) ≤ max ℵ₀ L.card := by
rw [card_functions_sum_skolem₁]
trans #(Σ n, L.BoundedFormula Empty n)
· exact
⟨⟨Sigma.map Nat.succ fun _ => id,
Nat.succ_injective.sigma_map fun _ => Function.injective_id⟩⟩
· refine _root_.trans BoundedFormula.card_le (lift_le.{max u v}.1 ?_)
simp only [mk_empty, lift_zero, lift_uzero, zero_add]
rfl
/-- The structure assigning each function symbol of `L.skolem₁` to a skolem function generated with
choice. -/
noncomputable instance skolem₁Structure : L.skolem₁.Structure M :=
⟨fun {_} φ x => Classical.epsilon fun a => φ.Realize default (Fin.snoc x a : _ → M), fun {_} r =>
Empty.elim r⟩
namespace Substructure
theorem skolem₁_reduct_isElementary (S : (L.sum L.skolem₁).Substructure M) :
(LHom.sumInl.substructureReduct S).IsElementary := by
apply (LHom.sumInl.substructureReduct S).isElementary_of_exists
intro n φ x a h
let φ' : (L.sum L.skolem₁).Functions n := LHom.sumInr.onFunction φ
exact
⟨⟨funMap φ' ((↑) ∘ x), S.fun_mem (LHom.sumInr.onFunction φ) ((↑) ∘ x) (by
exact fun i => (x i).2)⟩,
by exact Classical.epsilon_spec (p := fun a => BoundedFormula.Realize φ default
(Fin.snoc (Subtype.val ∘ x) a)) ⟨a, h⟩⟩
/-- Any `L.sum L.skolem₁`-substructure is an elementary `L`-substructure. -/
noncomputable def elementarySkolem₁Reduct (S : (L.sum L.skolem₁).Substructure M) :
L.ElementarySubstructure M :=
⟨LHom.sumInl.substructureReduct S, S.skolem₁_reduct_isElementary⟩
theorem coeSort_elementarySkolem₁Reduct (S : (L.sum L.skolem₁).Substructure M) :
(S.elementarySkolem₁Reduct : Type w) = S :=
rfl
end Substructure
open Substructure
variable (L) (M)
instance Substructure.elementarySkolem₁Reduct.instSmall :
Small.{max u v} (⊥ : (L.sum L.skolem₁).Substructure M).elementarySkolem₁Reduct := by
rw [coeSort_elementarySkolem₁Reduct]
infer_instance
theorem exists_small_elementarySubstructure : ∃ S : L.ElementarySubstructure M, Small.{max u v} S :=
⟨Substructure.elementarySkolem₁Reduct ⊥, inferInstance⟩
variable {M}
/-- The **Downward Löwenheim–Skolem theorem** :
If `s` is a set in an `L`-structure `M` and `κ` an infinite cardinal such that
`max (#s, L.card) ≤ κ` and `κ ≤ # M`, then `M` has an elementary substructure containing `s` of
cardinality `κ`. -/
theorem exists_elementarySubstructure_card_eq (s : Set M) (κ : Cardinal.{w'}) (h1 : ℵ₀ ≤ κ)
(h2 : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} κ)
(h3 : Cardinal.lift.{w'} L.card ≤ Cardinal.lift.{max u v} κ)
(h4 : Cardinal.lift.{w} κ ≤ Cardinal.lift.{w'} #M) :
∃ S : L.ElementarySubstructure M, s ⊆ S ∧ Cardinal.lift.{w'} #S = Cardinal.lift.{w} κ := by
obtain ⟨s', hs'⟩ := Cardinal.le_mk_iff_exists_set.1 h4
rw [← aleph0_le_lift.{_, w}] at h1
rw [← hs'] at h1 h2 ⊢
refine
⟨elementarySkolem₁Reduct (closure (L.sum L.skolem₁) (s ∪ Equiv.ulift '' s')),
(s.subset_union_left).trans subset_closure, ?_⟩
have h := mk_image_eq_lift _ s' Equiv.ulift.injective
rw [lift_umax.{w, w'}, lift_id'.{w, w'}] at h
rw [coeSort_elementarySkolem₁Reduct, ← h, lift_inj]
refine
le_antisymm (lift_le.1 (lift_card_closure_le.trans ?_))
(mk_le_mk_of_subset ((s.subset_union_right).trans subset_closure))
rw [max_le_iff, aleph0_le_lift, ← aleph0_le_lift.{_, w'}, h, add_eq_max, max_le_iff, lift_le]
· refine ⟨h1, (mk_union_le _ _).trans ?_, (lift_le.2 card_functions_sum_skolem₁_le).trans ?_⟩
· rw [← lift_le, lift_add, h, add_comm, add_eq_max h1]
exact max_le le_rfl h2
· rw [lift_max, lift_aleph0, max_le_iff, aleph0_le_lift, and_comm, ← lift_le.{w'},
lift_lift, lift_lift, ← aleph0_le_lift, h]
refine ⟨?_, h1⟩
rw [← lift_lift.{w', w}]
refine _root_.trans (lift_le.{w}.2 h3) ?_
rw [lift_lift, ← lift_lift.{w, max u v}, ← hs', ← h, lift_lift]
· refine _root_.trans ?_ (lift_le.2 (mk_le_mk_of_subset Set.subset_union_right))
rw [aleph0_le_lift, ← aleph0_le_lift, h]
exact h1
end Language
end FirstOrder
|
ModelTheory\Substructures.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Gabin Kolly
-/
import Mathlib.Order.Closure
import Mathlib.ModelTheory.Semantics
import Mathlib.ModelTheory.Encoding
/-!
# First-Order Substructures
This file defines substructures of first-order structures in a similar manner to the various
substructures appearing in the algebra library.
## Main Definitions
- A `FirstOrder.Language.Substructure` is defined so that `L.Substructure M` is the type of all
substructures of the `L`-structure `M`.
- `FirstOrder.Language.Substructure.closure` is defined so that if `s : Set M`, `closure L s` is
the least substructure of `M` containing `s`.
- `FirstOrder.Language.Substructure.comap` is defined so that `s.comap f` is the preimage of the
substructure `s` under the homomorphism `f`, as a substructure.
- `FirstOrder.Language.Substructure.map` is defined so that `s.map f` is the image of the
substructure `s` under the homomorphism `f`, as a substructure.
- `FirstOrder.Language.Hom.range` is defined so that `f.range` is the range of the
homomorphism `f`, as a substructure.
- `FirstOrder.Language.Hom.domRestrict` and `FirstOrder.Language.Hom.codRestrict` restrict
the domain and codomain respectively of first-order homomorphisms to substructures.
- `FirstOrder.Language.Embedding.domRestrict` and `FirstOrder.Language.Embedding.codRestrict`
restrict the domain and codomain respectively of first-order embeddings to substructures.
- `FirstOrder.Language.Substructure.inclusion` is the inclusion embedding between substructures.
- `FirstOrder.Language.Substructure.PartialEquiv` is defined so that `PartialEquiv L M N` is
the type of equivalences between substructures of `M` and `N`.
## Main Results
- `L.Substructure M` forms a `CompleteLattice`.
-/
universe u v w
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {M : Type w} {N P : Type*}
variable [L.Structure M] [L.Structure N] [L.Structure P]
open FirstOrder Cardinal
open Structure Cardinal
section ClosedUnder
open Set
variable {n : ℕ} (f : L.Functions n) (s : Set M)
/-- Indicates that a set in a given structure is a closed under a function symbol. -/
def ClosedUnder : Prop :=
∀ x : Fin n → M, (∀ i : Fin n, x i ∈ s) → funMap f x ∈ s
variable (L)
@[simp]
theorem closedUnder_univ : ClosedUnder f (univ : Set M) := fun _ _ => mem_univ _
variable {L f s} {t : Set M}
namespace ClosedUnder
theorem inter (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ∩ t) := fun x h =>
mem_inter (hs x fun i => mem_of_mem_inter_left (h i)) (ht x fun i => mem_of_mem_inter_right (h i))
theorem inf (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ⊓ t) :=
hs.inter ht
variable {S : Set (Set M)}
theorem sInf (hS : ∀ s, s ∈ S → ClosedUnder f s) : ClosedUnder f (sInf S) := fun x h s hs =>
hS s hs x fun i => h i s hs
end ClosedUnder
end ClosedUnder
variable (L) (M)
/-- A substructure of a structure `M` is a set closed under application of function symbols. -/
structure Substructure where
carrier : Set M
fun_mem : ∀ {n}, ∀ f : L.Functions n, ClosedUnder f carrier
variable {L} {M}
namespace Substructure
attribute [coe] Substructure.carrier
instance instSetLike : SetLike (L.Substructure M) M :=
⟨Substructure.carrier, fun p q h => by cases p; cases q; congr⟩
/-- See Note [custom simps projection] -/
def Simps.coe (S : L.Substructure M) : Set M :=
S
initialize_simps_projections Substructure (carrier → coe)
@[simp]
theorem mem_carrier {s : L.Substructure M} {x : M} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
/-- Two substructures are equal if they have the same elements. -/
@[ext]
theorem ext {S T : L.Substructure M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
/-- Copy a substructure replacing `carrier` with a set that is equal to it. -/
protected def copy (S : L.Substructure M) (s : Set M) (hs : s = S) : L.Substructure M where
carrier := s
fun_mem _ f := hs.symm ▸ S.fun_mem _ f
end Substructure
variable {S : L.Substructure M}
theorem Term.realize_mem {α : Type*} (t : L.Term α) (xs : α → M) (h : ∀ a, xs a ∈ S) :
t.realize xs ∈ S := by
induction' t with a n f ts ih
· exact h a
· exact Substructure.fun_mem _ _ _ ih
namespace Substructure
@[simp]
theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s :=
rfl
theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S :=
SetLike.coe_injective hs
theorem constants_mem (c : L.Constants) : (c : M) ∈ S :=
mem_carrier.2 (S.fun_mem c _ finZeroElim)
/-- The substructure `M` of the structure `M`. -/
instance instTop : Top (L.Substructure M) :=
⟨{ carrier := Set.univ
fun_mem := fun {_} _ _ _ => Set.mem_univ _ }⟩
instance instInhabited : Inhabited (L.Substructure M) :=
⟨⊤⟩
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : L.Substructure M) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : L.Substructure M) : Set M) = Set.univ :=
rfl
/-- The inf of two substructures is their intersection. -/
instance instInf : Inf (L.Substructure M) :=
⟨fun S₁ S₂ =>
{ carrier := (S₁ : Set M) ∩ (S₂ : Set M)
fun_mem := fun {_} f => (S₁.fun_mem f).inf (S₂.fun_mem f) }⟩
@[simp]
theorem coe_inf (p p' : L.Substructure M) :
((p ⊓ p' : L.Substructure M) : Set M) = (p : Set M) ∩ (p' : Set M) :=
rfl
@[simp]
theorem mem_inf {p p' : L.Substructure M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
instance instInfSet : InfSet (L.Substructure M) :=
⟨fun s =>
{ carrier := ⋂ t ∈ s, (t : Set M)
fun_mem := fun {n} f =>
ClosedUnder.sInf
(by
rintro _ ⟨t, rfl⟩
by_cases h : t ∈ s
· simpa [h] using t.fun_mem f
· simp [h]) }⟩
@[simp, norm_cast]
theorem coe_sInf (S : Set (L.Substructure M)) :
((sInf S : L.Substructure M) : Set M) = ⋂ s ∈ S, (s : Set M) :=
rfl
theorem mem_sInf {S : Set (L.Substructure M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
theorem mem_iInf {ι : Sort*} {S : ι → L.Substructure M} {x : M} :
(x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range]
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → L.Substructure M} :
((⨅ i, S i : L.Substructure M) : Set M) = ⋂ i, (S i : Set M) := by
simp only [iInf, coe_sInf, Set.biInter_range]
/-- Substructures of a structure form a complete lattice. -/
instance instCompleteLattice : CompleteLattice (L.Substructure M) :=
{ completeLatticeOfInf (L.Substructure M) fun _ =>
IsGLB.of_image
(fun {S T : L.Substructure M} => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe)
isGLB_biInf with
le := (· ≤ ·)
lt := (· < ·)
top := ⊤
le_top := fun _ x _ => mem_top x
inf := (· ⊓ ·)
sInf := InfSet.sInf
le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right }
variable (L)
/-- The `L.Substructure` generated by a set. -/
def closure : LowerAdjoint ((↑) : L.Substructure M → Set M) :=
⟨fun s => sInf { S | s ⊆ S }, fun _ _ =>
⟨Set.Subset.trans fun _x hx => mem_sInf.2 fun _S hS => hS hx, fun h => sInf_le h⟩⟩
variable {L} {s : Set M}
theorem mem_closure {x : M} : x ∈ closure L s ↔ ∀ S : L.Substructure M, s ⊆ S → x ∈ S :=
mem_sInf
/-- The substructure generated by a set includes the set. -/
@[simp]
theorem subset_closure : s ⊆ closure L s :=
(closure L).le_closure s
theorem not_mem_of_not_mem_closure {P : M} (hP : P ∉ closure L s) : P ∉ s := fun h =>
hP (subset_closure h)
@[simp]
theorem closed (S : L.Substructure M) : (closure L).closed (S : Set M) :=
congr rfl ((closure L).eq_of_le Set.Subset.rfl fun _x xS => mem_closure.2 fun _T hT => hT xS)
open Set
/-- A substructure `S` includes `closure L s` if and only if it includes `s`. -/
@[simp]
theorem closure_le : closure L s ≤ S ↔ s ⊆ S :=
(closure L).closure_le_closed_iff_le s S.closed
/-- Substructure closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure L s ≤ closure L t`. -/
theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure L s ≤ closure L t :=
(closure L).monotone h
theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure L s) : closure L s = S :=
(closure L).eq_of_le h₁ h₂
theorem coe_closure_eq_range_term_realize :
(closure L s : Set M) = range (@Term.realize L _ _ _ ((↑) : s → M)) := by
let S : L.Substructure M := ⟨range (Term.realize (L := L) ((↑) : s → M)), fun {n} f x hx => by
simp only [mem_range] at *
refine ⟨func f fun i => Classical.choose (hx i), ?_⟩
simp only [Term.realize, fun i => Classical.choose_spec (hx i)]⟩
change _ = (S : Set M)
rw [← SetLike.ext'_iff]
refine closure_eq_of_le (fun x hx => ⟨var ⟨x, hx⟩, rfl⟩) (le_sInf fun S' hS' => ?_)
rintro _ ⟨t, rfl⟩
exact t.realize_mem _ fun i => hS' i.2
instance small_closure [Small.{u} s] : Small.{u} (closure L s) := by
rw [← SetLike.coe_sort_coe, Substructure.coe_closure_eq_range_term_realize]
exact small_range _
theorem mem_closure_iff_exists_term {x : M} :
x ∈ closure L s ↔ ∃ t : L.Term s, t.realize ((↑) : s → M) = x := by
rw [← SetLike.mem_coe, coe_closure_eq_range_term_realize, mem_range]
theorem lift_card_closure_le_card_term : Cardinal.lift.{max u w} #(closure L s) ≤ #(L.Term s) := by
rw [← SetLike.coe_sort_coe, coe_closure_eq_range_term_realize]
rw [← Cardinal.lift_id'.{w, max u w} #(L.Term s)]
exact Cardinal.mk_range_le_lift
theorem lift_card_closure_le :
Cardinal.lift.{u, w} #(closure L s) ≤
max ℵ₀ (Cardinal.lift.{u, w} #s + Cardinal.lift.{w, u} #(Σi, L.Functions i)) := by
rw [← lift_umax]
refine lift_card_closure_le_card_term.trans (Term.card_le.trans ?_)
rw [mk_sum, lift_umax.{w, u}]
variable (L)
theorem _root_.Set.Countable.substructure_closure
[Countable (Σl, L.Functions l)] (h : s.Countable) : Countable.{w + 1} (closure L s) := by
haveI : Countable s := h.to_subtype
rw [← mk_le_aleph0_iff, ← lift_le_aleph0]
exact lift_card_closure_le_card_term.trans mk_le_aleph0
variable {L} (S)
/-- An induction principle for closure membership. If `p` holds for all elements of `s`, and
is preserved under function symbols, then `p` holds for all elements of the closure of `s`. -/
@[elab_as_elim]
theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure L s) (Hs : ∀ x ∈ s, p x)
(Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x :=
(@closure_le L M _ ⟨setOf p, fun {_} => Hfun⟩ _).2 Hs h
/-- If `s` is a dense set in a structure `M`, `Substructure.closure L s = ⊤`, then in order to prove
that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify
that `p` is preserved under function symbols. -/
@[elab_as_elim]
theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure L s = ⊤)
(Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := by
have : ∀ x ∈ closure L s, p x := fun x hx => closure_induction hx Hs fun {n} => Hfun
simpa [hs] using this x
variable (L) (M)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : GaloisInsertion (@closure L M _) (↑) where
choice s _ := closure L s
gc := (closure L).gc
le_l_u _ := subset_closure
choice_eq _ _ := rfl
variable {L} {M}
/-- Closure of a substructure `S` equals `S`. -/
@[simp]
theorem closure_eq : closure L (S : Set M) = S :=
(Substructure.gi L M).l_u_eq S
@[simp]
theorem closure_empty : closure L (∅ : Set M) = ⊥ :=
(Substructure.gi L M).gc.l_bot
@[simp]
theorem closure_univ : closure L (univ : Set M) = ⊤ :=
@coe_top L M _ ▸ closure_eq ⊤
theorem closure_union (s t : Set M) : closure L (s ∪ t) = closure L s ⊔ closure L t :=
(Substructure.gi L M).gc.l_sup
theorem closure_unionᵢ {ι} (s : ι → Set M) : closure L (⋃ i, s i) = ⨆ i, closure L (s i) :=
(Substructure.gi L M).gc.l_iSup
instance small_bot : Small.{u} (⊥ : L.Substructure M) := by
rw [← closure_empty]
haveI : Small.{u} (∅ : Set M) := small_subsingleton _
exact Substructure.small_closure
/-!
### `comap` and `map`
-/
/-- The preimage of a substructure along a homomorphism is a substructure. -/
@[simps]
def comap (φ : M →[L] N) (S : L.Substructure N) : L.Substructure M where
carrier := φ ⁻¹' S
fun_mem {n} f x hx := by
rw [mem_preimage, φ.map_fun]
exact S.fun_mem f (φ ∘ x) hx
@[simp]
theorem mem_comap {S : L.Substructure N} {f : M →[L] N} {x : M} : x ∈ S.comap f ↔ f x ∈ S :=
Iff.rfl
theorem comap_comap (S : L.Substructure P) (g : N →[L] P) (f : M →[L] N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[simp]
theorem comap_id (S : L.Substructure P) : S.comap (Hom.id _ _) = S :=
ext (by simp)
/-- The image of a substructure along a homomorphism is a substructure. -/
@[simps]
def map (φ : M →[L] N) (S : L.Substructure M) : L.Substructure N where
carrier := φ '' S
fun_mem {n} f x hx :=
(mem_image _ _ _).1
⟨funMap f fun i => Classical.choose (hx i),
S.fun_mem f _ fun i => (Classical.choose_spec (hx i)).1, by
simp only [Hom.map_fun, SetLike.mem_coe]
exact congr rfl (funext fun i => (Classical.choose_spec (hx i)).2)⟩
@[simp]
theorem mem_map {f : M →[L] N} {S : L.Substructure M} {y : N} :
y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
Iff.rfl
theorem mem_map_of_mem (f : M →[L] N) {S : L.Substructure M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
theorem apply_coe_mem_map (f : M →[L] N) (S : L.Substructure M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.prop
theorem map_map (g : N →[L] P) (f : M →[L] N) : (S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| image_image _ _ _
theorem map_le_iff_le_comap {f : M →[L] N} {S : L.Substructure M} {T : L.Substructure N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
theorem gc_map_comap (f : M →[L] N) : GaloisConnection (map f) (comap f) := fun _ _ =>
map_le_iff_le_comap
theorem map_le_of_le_comap {T : L.Substructure N} {f : M →[L] N} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
theorem le_comap_of_map_le {T : L.Substructure N} {f : M →[L] N} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
theorem le_comap_map {f : M →[L] N} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
theorem map_comap_le {S : L.Substructure N} {f : M →[L] N} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
theorem monotone_map {f : M →[L] N} : Monotone (map f) :=
(gc_map_comap f).monotone_l
theorem monotone_comap {f : M →[L] N} : Monotone (comap f) :=
(gc_map_comap f).monotone_u
@[simp]
theorem map_comap_map {f : M →[L] N} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[simp]
theorem comap_map_comap {S : L.Substructure N} {f : M →[L] N} :
((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
theorem map_sup (S T : L.Substructure M) (f : M →[L] N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure M) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem comap_inf (S T : L.Substructure N) (f : M →[L] N) :
(S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f).u_inf
theorem comap_iInf {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure N) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[simp]
theorem map_bot (f : M →[L] N) : (⊥ : L.Substructure M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp]
theorem comap_top (f : M →[L] N) : (⊤ : L.Substructure N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp]
theorem map_id (S : L.Substructure M) : S.map (Hom.id L M) = S :=
ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩
theorem map_closure (f : M →[L] N) (s : Set M) : (closure L s).map f = closure L (f '' s) :=
Eq.symm <|
closure_eq_of_le (Set.image_subset f subset_closure) <|
map_le_iff_le_comap.2 <| closure_le.2 fun x hx => subset_closure ⟨x, hx, rfl⟩
@[simp]
theorem closure_image (f : M →[L] N) : closure L (f '' s) = map f (closure L s) :=
(map_closure f s).symm
section GaloisCoinsertion
variable {ι : Type*} {f : M →[L] N}
/-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/
def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff]
variable (hf : Function.Injective f)
theorem comap_map_eq_of_injective (S : L.Substructure M) : (S.map f).comap f = S :=
(gciMapComap hf).u_l_eq _
theorem comap_surjective_of_injective : Function.Surjective (comap f) :=
(gciMapComap hf).u_surjective
theorem map_injective_of_injective : Function.Injective (map f) :=
(gciMapComap hf).l_injective
theorem comap_inf_map_of_injective (S T : L.Substructure M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gciMapComap hf).u_inf_l _ _
theorem comap_iInf_map_of_injective (S : ι → L.Substructure M) :
(⨅ i, (S i).map f).comap f = iInf S :=
(gciMapComap hf).u_iInf_l _
theorem comap_sup_map_of_injective (S T : L.Substructure M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gciMapComap hf).u_sup_l _ _
theorem comap_iSup_map_of_injective (S : ι → L.Substructure M) :
(⨆ i, (S i).map f).comap f = iSup S :=
(gciMapComap hf).u_iSup_l _
theorem map_le_map_iff_of_injective {S T : L.Substructure M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gciMapComap hf).l_le_l_iff
theorem map_strictMono_of_injective : StrictMono (map f) :=
(gciMapComap hf).strictMono_l
end GaloisCoinsertion
section GaloisInsertion
variable {ι : Type*} {f : M →[L] N} (hf : Function.Surjective f)
/-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisInsertion fun S x h =>
let ⟨y, hy⟩ := hf x
mem_map.2 ⟨y, by simp [hy, h]⟩
theorem map_comap_eq_of_surjective (S : L.Substructure N) : (S.comap f).map f = S :=
(giMapComap hf).l_u_eq _
theorem map_surjective_of_surjective : Function.Surjective (map f) :=
(giMapComap hf).l_surjective
theorem comap_injective_of_surjective : Function.Injective (comap f) :=
(giMapComap hf).u_injective
theorem map_inf_comap_of_surjective (S T : L.Substructure N) :
(S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(giMapComap hf).l_inf_u _ _
theorem map_iInf_comap_of_surjective (S : ι → L.Substructure N) :
(⨅ i, (S i).comap f).map f = iInf S :=
(giMapComap hf).l_iInf_u _
theorem map_sup_comap_of_surjective (S T : L.Substructure N) :
(S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(giMapComap hf).l_sup_u _ _
theorem map_iSup_comap_of_surjective (S : ι → L.Substructure N) :
(⨆ i, (S i).comap f).map f = iSup S :=
(giMapComap hf).l_iSup_u _
theorem comap_le_comap_iff_of_surjective {S T : L.Substructure N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(giMapComap hf).u_le_u_iff
theorem comap_strictMono_of_surjective : StrictMono (comap f) :=
(giMapComap hf).strictMono_u
end GaloisInsertion
instance inducedStructure {S : L.Substructure M} : L.Structure S where
funMap {_} f x := ⟨funMap f fun i => x i, S.fun_mem f (fun i => x i) fun i => (x i).2⟩
RelMap {_} r x := RelMap r fun i => (x i : M)
/-- The natural embedding of an `L.Substructure` of `M` into `M`. -/
def subtype (S : L.Substructure M) : S ↪[L] M where
toFun := (↑)
inj' := Subtype.coe_injective
@[simp]
theorem coeSubtype : ⇑S.subtype = ((↑) : S → M) :=
rfl
/-- The equivalence between the maximal substructure of a structure and the structure itself. -/
def topEquiv : (⊤ : L.Substructure M) ≃[L] M where
toFun := subtype ⊤
invFun m := ⟨m, mem_top m⟩
left_inv m := by simp
right_inv m := rfl
@[simp]
theorem coe_topEquiv :
⇑(topEquiv : (⊤ : L.Substructure M) ≃[L] M) = ((↑) : (⊤ : L.Substructure M) → M) :=
rfl
@[simp]
theorem realize_boundedFormula_top {α : Type*} {n : ℕ} {φ : L.BoundedFormula α n}
{v : α → (⊤ : L.Substructure M)} {xs : Fin n → (⊤ : L.Substructure M)} :
φ.Realize v xs ↔ φ.Realize (((↑) : _ → M) ∘ v) ((↑) ∘ xs) := by
rw [← Substructure.topEquiv.realize_boundedFormula φ]
simp
@[simp]
theorem realize_formula_top {α : Type*} {φ : L.Formula α} {v : α → (⊤ : L.Substructure M)} :
φ.Realize v ↔ φ.Realize (((↑) : (⊤ : L.Substructure M) → M) ∘ v) := by
rw [← Substructure.topEquiv.realize_formula φ]
simp
/-- A dependent version of `Substructure.closure_induction`. -/
@[elab_as_elim]
theorem closure_induction' (s : Set M) {p : ∀ x, x ∈ closure L s → Prop}
(Hs : ∀ (x) (h : x ∈ s), p x (subset_closure h))
(Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f { x | ∃ hx, p x hx }) {x}
(hx : x ∈ closure L s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ closure L s) (hc : p x hx) => hc
exact closure_induction hx (fun x hx => ⟨subset_closure hx, Hs x hx⟩) @Hfun
end Substructure
open Substructure
namespace LHom
variable {L' : Language} [L'.Structure M]
/-- Reduces the language of a substructure along a language hom. -/
def substructureReduct (φ : L →ᴸ L') [φ.IsExpansionOn M] :
L'.Substructure M ↪o L.Substructure M where
toFun S :=
{ carrier := S
fun_mem := fun {n} f x hx => by
have h := S.fun_mem (φ.onFunction f) x hx
simp only [LHom.map_onFunction, Substructure.mem_carrier] at h
exact h }
inj' S T h := by
simp only [SetLike.coe_set_eq, Substructure.mk.injEq] at h
exact h
map_rel_iff' {S T} := Iff.rfl
variable (φ : L →ᴸ L') [φ.IsExpansionOn M]
@[simp]
theorem mem_substructureReduct {x : M} {S : L'.Substructure M} :
x ∈ φ.substructureReduct S ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_substructureReduct {S : L'.Substructure M} : (φ.substructureReduct S : Set M) = ↑S :=
rfl
end LHom
namespace Substructure
/-- Turns any substructure containing a constant set `A` into a `L[[A]]`-substructure. -/
def withConstants (S : L.Substructure M) {A : Set M} (h : A ⊆ S) : L[[A]].Substructure M where
carrier := S
fun_mem {n} f := by
cases' f with f f
· exact S.fun_mem f
· cases n
· exact fun _ _ => h f.2
· exact isEmptyElim f
variable {A : Set M} {s : Set M} (h : A ⊆ S)
@[simp]
theorem mem_withConstants {x : M} : x ∈ S.withConstants h ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_withConstants : (S.withConstants h : Set M) = ↑S :=
rfl
@[simp]
theorem reduct_withConstants :
(L.lhomWithConstants A).substructureReduct (S.withConstants h) = S := by
ext
simp
theorem subset_closure_withConstants : A ⊆ closure (L[[A]]) s := by
intro a ha
simp only [SetLike.mem_coe]
let a' : L[[A]].Constants := Sum.inr ⟨a, ha⟩
exact constants_mem a'
theorem closure_withConstants_eq :
closure (L[[A]]) s =
(closure L (A ∪ s)).withConstants ((A.subset_union_left).trans subset_closure) := by
refine closure_eq_of_le ((A.subset_union_right).trans subset_closure) ?_
rw [← (L.lhomWithConstants A).substructureReduct.le_iff_le]
simp only [subset_closure, reduct_withConstants, closure_le, LHom.coe_substructureReduct,
Set.union_subset_iff, and_true_iff]
exact subset_closure_withConstants
end Substructure
namespace Hom
/-- The restriction of a first-order hom to a substructure `s ⊆ M` gives a hom `s → N`. -/
@[simps!]
def domRestrict (f : M →[L] N) (p : L.Substructure M) : p →[L] N :=
f.comp p.subtype.toHom
/-- A first-order hom `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to a
hom `M → p`. -/
@[simps]
def codRestrict (p : L.Substructure N) (f : M →[L] N) (h : ∀ c, f c ∈ p) : M →[L] p where
toFun c := ⟨f c, h c⟩
map_fun' {n} f x := by aesop
map_rel' {n} R x h := f.map_rel R x h
@[simp]
theorem comp_codRestrict (f : M →[L] N) (g : N →[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) :
((codRestrict p g h).comp f : M →[L] p) = codRestrict p (g.comp f) fun _ => h _ :=
ext fun _ => rfl
@[simp]
theorem subtype_comp_codRestrict (f : M →[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) :
p.subtype.toHom.comp (codRestrict p f h) = f :=
ext fun _ => rfl
/-- The range of a first-order hom `f : M → N` is a submodule of `N`.
See Note [range copy pattern]. -/
def range (f : M →[L] N) : L.Substructure N :=
(map f ⊤).copy (Set.range f) Set.image_univ.symm
theorem range_coe (f : M →[L] N) : (range f : Set N) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : M →[L] N} {x} : x ∈ range f ↔ ∃ y, f y = x :=
Iff.rfl
theorem range_eq_map (f : M →[L] N) : f.range = map f ⊤ := by
ext
simp
theorem mem_range_self (f : M →[L] N) (x : M) : f x ∈ f.range :=
⟨x, rfl⟩
@[simp]
theorem range_id : range (id L M) = ⊤ :=
SetLike.coe_injective Set.range_id
theorem range_comp (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) = map g (range f) :=
SetLike.coe_injective (Set.range_comp g f)
theorem range_comp_le_range (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) ≤ range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
theorem range_eq_top {f : M →[L] N} : range f = ⊤ ↔ Function.Surjective f := by
rw [SetLike.ext'_iff, range_coe, coe_top, Set.range_iff_surjective]
theorem range_le_iff_comap {f : M →[L] N} {p : L.Substructure N} : range f ≤ p ↔ comap f p = ⊤ := by
rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
theorem map_le_range {f : M →[L] N} {p : L.Substructure M} : map f p ≤ range f :=
SetLike.coe_mono (Set.image_subset_range f p)
/-- The substructure of elements `x : M` such that `f x = g x` -/
def eqLocus (f g : M →[L] N) : Substructure L M where
carrier := { x : M | f x = g x }
fun_mem {n} fn x hx := by
have h : f ∘ x = g ∘ x := by
ext
repeat' rw [Function.comp_apply]
apply hx
simp [h]
/-- If two `L.Hom`s are equal on a set, then they are equal on its substructure closure. -/
theorem eqOn_closure {f g : M →[L] N} {s : Set M} (h : Set.EqOn f g s) :
Set.EqOn f g (closure L s) :=
show closure L s ≤ f.eqLocus g from closure_le.2 h
theorem eq_of_eqOn_top {f g : M →[L] N} (h : Set.EqOn f g (⊤ : Substructure L M)) : f = g :=
ext fun _ => h trivial
variable {s : Set M}
theorem eq_of_eqOn_dense (hs : closure L s = ⊤) {f g : M →[L] N} (h : s.EqOn f g) : f = g :=
eq_of_eqOn_top <| hs ▸ eqOn_closure h
end Hom
namespace Embedding
/-- The restriction of a first-order embedding to a substructure `s ⊆ M` gives an embedding `s → N`.
-/
def domRestrict (f : M ↪[L] N) (p : L.Substructure M) : p ↪[L] N :=
f.comp p.subtype
@[simp]
theorem domRestrict_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) : f.domRestrict p x = f x :=
rfl
/-- A first-order embedding `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted
to an embedding `M → p`. -/
def codRestrict (p : L.Substructure N) (f : M ↪[L] N) (h : ∀ c, f c ∈ p) : M ↪[L] p where
toFun := f.toHom.codRestrict p h
inj' a b ab := f.injective (Subtype.mk_eq_mk.1 ab)
map_fun' {n} F x := (f.toHom.codRestrict p h).map_fun' F x
map_rel' {n} r x := by
simp only
rw [← p.subtype.map_rel]
change RelMap r (Hom.comp p.subtype.toHom (f.toHom.codRestrict p h) ∘ x) ↔ _
rw [Hom.subtype_comp_codRestrict, ← f.map_rel]
rfl
@[simp]
theorem codRestrict_apply (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) :
(codRestrict p f h x : N) = f x :=
rfl
@[simp]
theorem codRestrict_apply' (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) :
codRestrict p f h x = ⟨f x, h x⟩ :=
rfl
@[simp]
theorem comp_codRestrict (f : M ↪[L] N) (g : N ↪[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) :
((codRestrict p g h).comp f : M ↪[L] p) = codRestrict p (g.comp f) fun _ => h _ :=
ext fun _ => rfl
@[simp]
theorem subtype_comp_codRestrict (f : M ↪[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) :
p.subtype.comp (codRestrict p f h) = f :=
ext fun _ => rfl
/-- The equivalence between a substructure `s` and its image `s.map f.toHom`, where `f` is an
embedding. -/
noncomputable def substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) :
s ≃[L] s.map f.toHom where
toFun := codRestrict (s.map f.toHom) (f.domRestrict s) fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩
invFun n := ⟨Classical.choose n.2, (Classical.choose_spec n.2).1⟩
left_inv := fun ⟨m, hm⟩ =>
Subtype.mk_eq_mk.2
(f.injective
(Classical.choose_spec
(codRestrict (s.map f.toHom) (f.domRestrict s) (fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩)
⟨m, hm⟩).2).2)
right_inv := fun ⟨n, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn).2
map_fun' {n} f x := by aesop
map_rel' {n} R x := by aesop
@[simp]
theorem substructureEquivMap_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) :
(f.substructureEquivMap p x : N) = f x :=
rfl
@[simp]
theorem subtype_substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) :
(subtype _).comp (f.substructureEquivMap s).toEmbedding = f.comp (subtype _) := by
ext; rfl
/-- The equivalence between the domain and the range of an embedding `f`. -/
noncomputable def equivRange (f : M ↪[L] N) : M ≃[L] f.toHom.range where
toFun := codRestrict f.toHom.range f f.toHom.mem_range_self
invFun n := Classical.choose n.2
left_inv m :=
f.injective (Classical.choose_spec (codRestrict f.toHom.range f f.toHom.mem_range_self m).2)
right_inv := fun ⟨n, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn)
map_fun' {n} f x := by aesop
map_rel' {n} R x := by aesop
@[simp]
theorem equivRange_apply (f : M ↪[L] N) (x : M) : (f.equivRange x : N) = f x :=
rfl
@[simp]
theorem subtype_equivRange (f : M ↪[L] N) : (subtype _).comp f.equivRange.toEmbedding = f := by
ext; rfl
end Embedding
namespace Equiv
theorem toHom_range (f : M ≃[L] N) : f.toHom.range = ⊤ := by
ext n
simp only [Hom.mem_range, coe_toHom, Substructure.mem_top, iff_true_iff]
exact ⟨f.symm n, apply_symm_apply _ _⟩
end Equiv
namespace Substructure
/-- The embedding associated to an inclusion of substructures. -/
def inclusion {S T : L.Substructure M} (h : S ≤ T) : S ↪[L] T :=
S.subtype.codRestrict _ fun x => h x.2
@[simp]
theorem inclusion_self (S : L.Substructure M) : inclusion (le_refl S) = Embedding.refl L S := rfl
@[simp]
theorem coe_inclusion {S T : L.Substructure M} (h : S ≤ T) :
(inclusion h : S → T) = Set.inclusion h :=
rfl
theorem range_subtype (S : L.Substructure M) : S.subtype.toHom.range = S := by
ext x
simp only [Hom.mem_range, Embedding.coe_toHom, coeSubtype]
refine ⟨?_, fun h => ⟨⟨x, h⟩, rfl⟩⟩
rintro ⟨⟨y, hy⟩, rfl⟩
exact hy
end Substructure
end Language
end FirstOrder
|
ModelTheory\Syntax.lean | /-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Set.Prod
import Mathlib.Logic.Equiv.Fin
import Mathlib.ModelTheory.LanguageMap
/-!
# Basics on First-Order Syntax
This file defines first-order terms, formulas, sentences, and theories in a style inspired by the
[Flypitch project](https://flypitch.github.io/).
## Main Definitions
- A `FirstOrder.Language.Term` is defined so that `L.Term α` is the type of `L`-terms with free
variables indexed by `α`.
- A `FirstOrder.Language.Formula` is defined so that `L.Formula α` is the type of `L`-formulas with
free variables indexed by `α`.
- A `FirstOrder.Language.Sentence` is a formula with no free variables.
- A `FirstOrder.Language.Theory` is a set of sentences.
- The variables of terms and formulas can be relabelled with `FirstOrder.Language.Term.relabel`,
`FirstOrder.Language.BoundedFormula.relabel`, and `FirstOrder.Language.Formula.relabel`.
- Given an operation on terms and an operation on relations,
`FirstOrder.Language.BoundedFormula.mapTermRel` gives an operation on formulas.
- `FirstOrder.Language.BoundedFormula.castLE` adds more `Fin`-indexed variables.
- `FirstOrder.Language.BoundedFormula.liftAt` raises the indexes of the `Fin`-indexed variables
above a particular index.
- `FirstOrder.Language.Term.subst` and `FirstOrder.Language.BoundedFormula.subst` substitute
variables with given terms.
- Language maps can act on syntactic objects with functions such as
`FirstOrder.Language.LHom.onFormula`.
- `FirstOrder.Language.Term.constantsVarsEquiv` and
`FirstOrder.Language.BoundedFormula.constantsVarsEquiv` switch terms and formulas between having
constants in the language and having extra variables indexed by the same type.
## Implementation Notes
- Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable (L : Language.{u, v}) {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder
open Structure Fin
/-- A term on `α` is either a variable indexed by an element of `α`
or a function symbol applied to simpler terms. -/
inductive Term (α : Type u') : Type max u u'
| var : α → Term α
| func : ∀ {l : ℕ} (_f : L.Functions l) (_ts : Fin l → Term α), Term α
export Term (var func)
variable {L}
namespace Term
open Finset
/-- The `Finset` of variables used in a given term. -/
@[simp]
def varFinset [DecidableEq α] : L.Term α → Finset α
| var i => {i}
| func _f ts => univ.biUnion fun i => (ts i).varFinset
-- Porting note: universes in different order
/-- The `Finset` of variables from the left side of a sum used in a given term. -/
@[simp]
def varFinsetLeft [DecidableEq α] : L.Term (α ⊕ β) → Finset α
| var (Sum.inl i) => {i}
| var (Sum.inr _i) => ∅
| func _f ts => univ.biUnion fun i => (ts i).varFinsetLeft
-- Porting note: universes in different order
@[simp]
def relabel (g : α → β) : L.Term α → L.Term β
| var i => var (g i)
| func f ts => func f fun {i} => (ts i).relabel g
theorem relabel_id (t : L.Term α) : t.relabel id = t := by
induction' t with _ _ _ _ ih
· rfl
· simp [ih]
@[simp]
theorem relabel_id_eq_id : (Term.relabel id : L.Term α → L.Term α) = id :=
funext relabel_id
@[simp]
theorem relabel_relabel (f : α → β) (g : β → γ) (t : L.Term α) :
(t.relabel f).relabel g = t.relabel (g ∘ f) := by
induction' t with _ _ _ _ ih
· rfl
· simp [ih]
@[simp]
theorem relabel_comp_relabel (f : α → β) (g : β → γ) :
(Term.relabel g ∘ Term.relabel f : L.Term α → L.Term γ) = Term.relabel (g ∘ f) :=
funext (relabel_relabel f g)
/-- Relabels a term's variables along a bijection. -/
@[simps]
def relabelEquiv (g : α ≃ β) : L.Term α ≃ L.Term β :=
⟨relabel g, relabel g.symm, fun t => by simp, fun t => by simp⟩
-- Porting note: universes in different order
/-- Restricts a term to use only a set of the given variables. -/
def restrictVar [DecidableEq α] : ∀ (t : L.Term α) (_f : t.varFinset → β), L.Term β
| var a, f => var (f ⟨a, mem_singleton_self a⟩)
| func F ts, f =>
func F fun i => (ts i).restrictVar (f ∘ Set.inclusion
(subset_biUnion_of_mem (fun i => varFinset (ts i)) (mem_univ i)))
-- Porting note: universes in different order
/-- Restricts a term to use only a set of the given variables on the left side of a sum. -/
def restrictVarLeft [DecidableEq α] {γ : Type*} :
∀ (t : L.Term (α ⊕ γ)) (_f : t.varFinsetLeft → β), L.Term (β ⊕ γ)
| var (Sum.inl a), f => var (Sum.inl (f ⟨a, mem_singleton_self a⟩))
| var (Sum.inr a), _f => var (Sum.inr a)
| func F ts, f =>
func F fun i =>
(ts i).restrictVarLeft (f ∘ Set.inclusion (subset_biUnion_of_mem
(fun i => varFinsetLeft (ts i)) (mem_univ i)))
end Term
/-- The representation of a constant symbol as a term. -/
def Constants.term (c : L.Constants) : L.Term α :=
func c default
/-- Applies a unary function to a term. -/
def Functions.apply₁ (f : L.Functions 1) (t : L.Term α) : L.Term α :=
func f ![t]
/-- Applies a binary function to two terms. -/
def Functions.apply₂ (f : L.Functions 2) (t₁ t₂ : L.Term α) : L.Term α :=
func f ![t₁, t₂]
namespace Term
-- Porting note: universes in different order
/-- Sends a term with constants to a term with extra variables. -/
@[simp]
def constantsToVars : L[[γ]].Term α → L.Term (γ ⊕ α)
| var a => var (Sum.inr a)
| @func _ _ 0 f ts =>
Sum.casesOn f (fun f => func f fun i => (ts i).constantsToVars) fun c => var (Sum.inl c)
| @func _ _ (_n + 1) f ts =>
Sum.casesOn f (fun f => func f fun i => (ts i).constantsToVars) fun c => isEmptyElim c
-- Porting note: universes in different order
/-- Sends a term with extra variables to a term with constants. -/
@[simp]
def varsToConstants : L.Term (γ ⊕ α) → L[[γ]].Term α
| var (Sum.inr a) => var a
| var (Sum.inl c) => Constants.term (Sum.inr c)
| func f ts => func (Sum.inl f) fun i => (ts i).varsToConstants
/-- A bijection between terms with constants and terms with extra variables. -/
@[simps]
def constantsVarsEquiv : L[[γ]].Term α ≃ L.Term (γ ⊕ α) :=
⟨constantsToVars, varsToConstants, by
intro t
induction' t with _ n f _ ih
· rfl
· cases n
· cases f
· simp [constantsToVars, varsToConstants, ih]
· simp [constantsToVars, varsToConstants, Constants.term, eq_iff_true_of_subsingleton]
· cases' f with f f
· simp [constantsToVars, varsToConstants, ih]
· exact isEmptyElim f, by
intro t
induction' t with x n f _ ih
· cases x <;> rfl
· cases n <;> · simp [varsToConstants, constantsToVars, ih]⟩
/-- A bijection between terms with constants and terms with extra variables. -/
def constantsVarsEquivLeft : L[[γ]].Term (α ⊕ β) ≃ L.Term ((γ ⊕ α) ⊕ β) :=
constantsVarsEquiv.trans (relabelEquiv (Equiv.sumAssoc _ _ _)).symm
@[simp]
theorem constantsVarsEquivLeft_apply (t : L[[γ]].Term (α ⊕ β)) :
constantsVarsEquivLeft t = (constantsToVars t).relabel (Equiv.sumAssoc _ _ _).symm :=
rfl
@[simp]
theorem constantsVarsEquivLeft_symm_apply (t : L.Term ((γ ⊕ α) ⊕ β)) :
constantsVarsEquivLeft.symm t = varsToConstants (t.relabel (Equiv.sumAssoc _ _ _)) :=
rfl
instance inhabitedOfVar [Inhabited α] : Inhabited (L.Term α) :=
⟨var default⟩
instance inhabitedOfConstant [Inhabited L.Constants] : Inhabited (L.Term α) :=
⟨(default : L.Constants).term⟩
/-- Raises all of the `Fin`-indexed variables of a term greater than or equal to `m` by `n'`. -/
def liftAt {n : ℕ} (n' m : ℕ) : L.Term (α ⊕ (Fin n)) → L.Term (α ⊕ (Fin (n + n'))) :=
relabel (Sum.map id fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n')
-- Porting note: universes in different order
/-- Substitutes the variables in a given term with terms. -/
@[simp]
def subst : L.Term α → (α → L.Term β) → L.Term β
| var a, tf => tf a
| func f ts, tf => func f fun i => (ts i).subst tf
end Term
scoped[FirstOrder] prefix:arg "&" => FirstOrder.Language.Term.var ∘ Sum.inr
namespace LHom
open Term
-- Porting note: universes in different order
/-- Maps a term's symbols along a language map. -/
@[simp]
def onTerm (φ : L →ᴸ L') : L.Term α → L'.Term α
| var i => var i
| func f ts => func (φ.onFunction f) fun i => onTerm φ (ts i)
@[simp]
theorem id_onTerm : ((LHom.id L).onTerm : L.Term α → L.Term α) = id := by
ext t
induction' t with _ _ _ _ ih
· rfl
· simp_rw [onTerm, ih]
rfl
@[simp]
theorem comp_onTerm {L'' : Language} (φ : L' →ᴸ L'') (ψ : L →ᴸ L') :
((φ.comp ψ).onTerm : L.Term α → L''.Term α) = φ.onTerm ∘ ψ.onTerm := by
ext t
induction' t with _ _ _ _ ih
· rfl
· simp_rw [onTerm, ih]
rfl
end LHom
/-- Maps a term's symbols along a language equivalence. -/
@[simps]
def Lequiv.onTerm (φ : L ≃ᴸ L') : L.Term α ≃ L'.Term α where
toFun := φ.toLHom.onTerm
invFun := φ.invLHom.onTerm
left_inv := by
rw [Function.leftInverse_iff_comp, ← LHom.comp_onTerm, φ.left_inv, LHom.id_onTerm]
right_inv := by
rw [Function.rightInverse_iff_comp, ← LHom.comp_onTerm, φ.right_inv, LHom.id_onTerm]
variable (L) (α)
/-- `BoundedFormula α n` is the type of formulas with free variables indexed by `α` and up to `n`
additional free variables. -/
inductive BoundedFormula : ℕ → Type max u v u'
| falsum {n} : BoundedFormula n
| equal {n} (t₁ t₂ : L.Term (α ⊕ (Fin n))) : BoundedFormula n
| rel {n l : ℕ} (R : L.Relations l) (ts : Fin l → L.Term (α ⊕ (Fin n))) : BoundedFormula n
| imp {n} (f₁ f₂ : BoundedFormula n) : BoundedFormula n
| all {n} (f : BoundedFormula (n + 1)) : BoundedFormula n
/-- `Formula α` is the type of formulas with all free variables indexed by `α`. -/
abbrev Formula :=
L.BoundedFormula α 0
/-- A sentence is a formula with no free variables. -/
abbrev Sentence :=
L.Formula Empty
/-- A theory is a set of sentences. -/
abbrev Theory :=
Set L.Sentence
variable {L} {α} {n : ℕ}
/-- Applies a relation to terms as a bounded formula. -/
def Relations.boundedFormula {l : ℕ} (R : L.Relations n) (ts : Fin n → L.Term (α ⊕ (Fin l))) :
L.BoundedFormula α l :=
BoundedFormula.rel R ts
/-- Applies a unary relation to a term as a bounded formula. -/
def Relations.boundedFormula₁ (r : L.Relations 1) (t : L.Term (α ⊕ (Fin n))) :
L.BoundedFormula α n :=
r.boundedFormula ![t]
/-- Applies a binary relation to two terms as a bounded formula. -/
def Relations.boundedFormula₂ (r : L.Relations 2) (t₁ t₂ : L.Term (α ⊕ (Fin n))) :
L.BoundedFormula α n :=
r.boundedFormula ![t₁, t₂]
/-- The equality of two terms as a bounded formula. -/
def Term.bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n :=
BoundedFormula.equal t₁ t₂
/-- Applies a relation to terms as a bounded formula. -/
def Relations.formula (R : L.Relations n) (ts : Fin n → L.Term α) : L.Formula α :=
R.boundedFormula fun i => (ts i).relabel Sum.inl
/-- Applies a unary relation to a term as a formula. -/
def Relations.formula₁ (r : L.Relations 1) (t : L.Term α) : L.Formula α :=
r.formula ![t]
/-- Applies a binary relation to two terms as a formula. -/
def Relations.formula₂ (r : L.Relations 2) (t₁ t₂ : L.Term α) : L.Formula α :=
r.formula ![t₁, t₂]
/-- The equality of two terms as a first-order formula. -/
def Term.equal (t₁ t₂ : L.Term α) : L.Formula α :=
(t₁.relabel Sum.inl).bdEqual (t₂.relabel Sum.inl)
namespace BoundedFormula
instance : Inhabited (L.BoundedFormula α n) :=
⟨falsum⟩
instance : Bot (L.BoundedFormula α n) :=
⟨falsum⟩
/-- The negation of a bounded formula is also a bounded formula. -/
@[match_pattern]
protected def not (φ : L.BoundedFormula α n) : L.BoundedFormula α n :=
φ.imp ⊥
/-- Puts an `∃` quantifier on a bounded formula. -/
@[match_pattern]
protected def ex (φ : L.BoundedFormula α (n + 1)) : L.BoundedFormula α n :=
φ.not.all.not
instance : Top (L.BoundedFormula α n) :=
⟨BoundedFormula.not ⊥⟩
instance : Inf (L.BoundedFormula α n) :=
⟨fun f g => (f.imp g.not).not⟩
instance : Sup (L.BoundedFormula α n) :=
⟨fun f g => f.not.imp g⟩
/-- The biimplication between two bounded formulas. -/
protected def iff (φ ψ : L.BoundedFormula α n) :=
φ.imp ψ ⊓ ψ.imp φ
open Finset
-- Porting note: universes in different order
/-- The `Finset` of variables used in a given formula. -/
@[simp]
def freeVarFinset [DecidableEq α] : ∀ {n}, L.BoundedFormula α n → Finset α
| _n, falsum => ∅
| _n, equal t₁ t₂ => t₁.varFinsetLeft ∪ t₂.varFinsetLeft
| _n, rel _R ts => univ.biUnion fun i => (ts i).varFinsetLeft
| _n, imp f₁ f₂ => f₁.freeVarFinset ∪ f₂.freeVarFinset
| _n, all f => f.freeVarFinset
-- Porting note: universes in different order
/-- Casts `L.BoundedFormula α m` as `L.BoundedFormula α n`, where `m ≤ n`. -/
@[simp]
def castLE : ∀ {m n : ℕ} (_h : m ≤ n), L.BoundedFormula α m → L.BoundedFormula α n
| _m, _n, _h, falsum => falsum
| _m, _n, h, equal t₁ t₂ =>
equal (t₁.relabel (Sum.map id (Fin.castLE h))) (t₂.relabel (Sum.map id (Fin.castLE h)))
| _m, _n, h, rel R ts => rel R (Term.relabel (Sum.map id (Fin.castLE h)) ∘ ts)
| _m, _n, h, imp f₁ f₂ => (f₁.castLE h).imp (f₂.castLE h)
| _m, _n, h, all f => (f.castLE (add_le_add_right h 1)).all
@[simp]
theorem castLE_rfl {n} (h : n ≤ n) (φ : L.BoundedFormula α n) : φ.castLE h = φ := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp [Fin.castLE_of_eq]
· simp [Fin.castLE_of_eq]
· simp [Fin.castLE_of_eq, ih1, ih2]
· simp [Fin.castLE_of_eq, ih3]
@[simp]
theorem castLE_castLE {k m n} (km : k ≤ m) (mn : m ≤ n) (φ : L.BoundedFormula α k) :
(φ.castLE km).castLE mn = φ.castLE (km.trans mn) := by
revert m n
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 <;> intro m n km mn
· rfl
· simp
· simp only [castLE, eq_self_iff_true, heq_iff_eq, true_and_iff]
rw [← Function.comp.assoc, Term.relabel_comp_relabel]
simp
· simp [ih1, ih2]
· simp only [castLE, ih3]
@[simp]
theorem castLE_comp_castLE {k m n} (km : k ≤ m) (mn : m ≤ n) :
(BoundedFormula.castLE mn ∘ BoundedFormula.castLE km :
L.BoundedFormula α k → L.BoundedFormula α n) =
BoundedFormula.castLE (km.trans mn) :=
funext (castLE_castLE km mn)
-- Porting note: universes in different order
/-- Restricts a bounded formula to only use a particular set of free variables. -/
def restrictFreeVar [DecidableEq α] :
∀ {n : ℕ} (φ : L.BoundedFormula α n) (_f : φ.freeVarFinset → β), L.BoundedFormula β n
| _n, falsum, _f => falsum
| _n, equal t₁ t₂, f =>
equal (t₁.restrictVarLeft (f ∘ Set.inclusion subset_union_left))
(t₂.restrictVarLeft (f ∘ Set.inclusion subset_union_right))
| _n, rel R ts, f =>
rel R fun i => (ts i).restrictVarLeft (f ∘ Set.inclusion
(subset_biUnion_of_mem (fun i => Term.varFinsetLeft (ts i)) (mem_univ i)))
| _n, imp φ₁ φ₂, f =>
(φ₁.restrictFreeVar (f ∘ Set.inclusion subset_union_left)).imp
(φ₂.restrictFreeVar (f ∘ Set.inclusion subset_union_right))
| _n, all φ, f => (φ.restrictFreeVar f).all
-- Porting note: universes in different order
/-- Places universal quantifiers on all extra variables of a bounded formula. -/
def alls : ∀ {n}, L.BoundedFormula α n → L.Formula α
| 0, φ => φ
| _n + 1, φ => φ.all.alls
-- Porting note: universes in different order
/-- Places existential quantifiers on all extra variables of a bounded formula. -/
def exs : ∀ {n}, L.BoundedFormula α n → L.Formula α
| 0, φ => φ
| _n + 1, φ => φ.ex.exs
-- Porting note: universes in different order
/-- Maps bounded formulas along a map of terms and a map of relations. -/
def mapTermRel {g : ℕ → ℕ} (ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (g n))))
(fr : ∀ n, L.Relations n → L'.Relations n)
(h : ∀ n, L'.BoundedFormula β (g (n + 1)) → L'.BoundedFormula β (g n + 1)) :
∀ {n}, L.BoundedFormula α n → L'.BoundedFormula β (g n)
| _n, falsum => falsum
| _n, equal t₁ t₂ => equal (ft _ t₁) (ft _ t₂)
| _n, rel R ts => rel (fr _ R) fun i => ft _ (ts i)
| _n, imp φ₁ φ₂ => (φ₁.mapTermRel ft fr h).imp (φ₂.mapTermRel ft fr h)
| n, all φ => (h n (φ.mapTermRel ft fr h)).all
/-- Raises all of the `Fin`-indexed variables of a formula greater than or equal to `m` by `n'`. -/
def liftAt : ∀ {n : ℕ} (n' _m : ℕ), L.BoundedFormula α n → L.BoundedFormula α (n + n') :=
fun {n} n' m φ =>
φ.mapTermRel (fun k t => t.liftAt n' m) (fun _ => id) fun _ =>
castLE (by rw [add_assoc, add_comm 1, add_assoc])
@[simp]
theorem mapTermRel_mapTermRel {L'' : Language}
(ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n)))
(fr : ∀ n, L.Relations n → L'.Relations n)
(ft' : ∀ n, L'.Term (β ⊕ Fin n) → L''.Term (γ ⊕ (Fin n)))
(fr' : ∀ n, L'.Relations n → L''.Relations n) {n} (φ : L.BoundedFormula α n) :
((φ.mapTermRel ft fr fun _ => id).mapTermRel ft' fr' fun _ => id) =
φ.mapTermRel (fun _ => ft' _ ∘ ft _) (fun _ => fr' _ ∘ fr _) fun _ => id := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp [mapTermRel]
· simp [mapTermRel]
· simp [mapTermRel, ih1, ih2]
· simp [mapTermRel, ih3]
@[simp]
theorem mapTermRel_id_id_id {n} (φ : L.BoundedFormula α n) :
(φ.mapTermRel (fun _ => id) (fun _ => id) fun _ => id) = φ := by
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp [mapTermRel]
· simp [mapTermRel]
· simp [mapTermRel, ih1, ih2]
· simp [mapTermRel, ih3]
/-- An equivalence of bounded formulas given by an equivalence of terms and an equivalence of
relations. -/
@[simps]
def mapTermRelEquiv (ft : ∀ n, L.Term (α ⊕ (Fin n)) ≃ L'.Term (β ⊕ (Fin n)))
(fr : ∀ n, L.Relations n ≃ L'.Relations n) {n} : L.BoundedFormula α n ≃ L'.BoundedFormula β n :=
⟨mapTermRel (fun n => ft n) (fun n => fr n) fun _ => id,
mapTermRel (fun n => (ft n).symm) (fun n => (fr n).symm) fun _ => id, fun φ => by simp, fun φ =>
by simp⟩
/-- A function to help relabel the variables in bounded formulas. -/
def relabelAux (g : α → β ⊕ (Fin n)) (k : ℕ) : α ⊕ (Fin k) → β ⊕ (Fin (n + k)) :=
Sum.map id finSumFinEquiv ∘ Equiv.sumAssoc _ _ _ ∘ Sum.map g id
@[simp]
theorem sum_elim_comp_relabelAux {m : ℕ} {g : α → β ⊕ (Fin n)} {v : β → M}
{xs : Fin (n + m) → M} : Sum.elim v xs ∘ relabelAux g m =
Sum.elim (Sum.elim v (xs ∘ castAdd m) ∘ g) (xs ∘ natAdd n) := by
ext x
cases' x with x x
· simp only [BoundedFormula.relabelAux, Function.comp_apply, Sum.map_inl, Sum.elim_inl]
cases' g x with l r <;> simp
· simp [BoundedFormula.relabelAux]
@[simp]
theorem relabelAux_sum_inl (k : ℕ) :
relabelAux (Sum.inl : α → α ⊕ (Fin n)) k = Sum.map id (natAdd n) := by
ext x
cases x <;> · simp [relabelAux]
/-- Relabels a bounded formula's variables along a particular function. -/
def relabel (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α k) : L.BoundedFormula β (n + k) :=
φ.mapTermRel (fun _ t => t.relabel (relabelAux g _)) (fun _ => id) fun _ =>
castLE (ge_of_eq (add_assoc _ _ _))
/-- Relabels a bounded formula's free variables along a bijection. -/
def relabelEquiv (g : α ≃ β) {k} : L.BoundedFormula α k ≃ L.BoundedFormula β k :=
mapTermRelEquiv (fun _n => Term.relabelEquiv (g.sumCongr (_root_.Equiv.refl _)))
fun _n => _root_.Equiv.refl _
@[simp]
theorem relabel_falsum (g : α → β ⊕ (Fin n)) {k} :
(falsum : L.BoundedFormula α k).relabel g = falsum :=
rfl
@[simp]
theorem relabel_bot (g : α → β ⊕ (Fin n)) {k} : (⊥ : L.BoundedFormula α k).relabel g = ⊥ :=
rfl
@[simp]
theorem relabel_imp (g : α → β ⊕ (Fin n)) {k} (φ ψ : L.BoundedFormula α k) :
(φ.imp ψ).relabel g = (φ.relabel g).imp (ψ.relabel g) :=
rfl
@[simp]
theorem relabel_not (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α k) :
φ.not.relabel g = (φ.relabel g).not := by simp [BoundedFormula.not]
@[simp]
theorem relabel_all (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α (k + 1)) :
φ.all.relabel g = (φ.relabel g).all := by
rw [relabel, mapTermRel, relabel]
simp
@[simp]
theorem relabel_ex (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α (k + 1)) :
φ.ex.relabel g = (φ.relabel g).ex := by simp [BoundedFormula.ex]
@[simp]
theorem relabel_sum_inl (φ : L.BoundedFormula α n) :
(φ.relabel Sum.inl : L.BoundedFormula α (0 + n)) = φ.castLE (ge_of_eq (zero_add n)) := by
simp only [relabel, relabelAux_sum_inl]
induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp [Fin.natAdd_zero, castLE_of_eq, mapTermRel]
· simp [Fin.natAdd_zero, castLE_of_eq, mapTermRel]; rfl
· simp [mapTermRel, ih1, ih2]
· simp [mapTermRel, ih3, castLE]
/-- Substitutes the variables in a given formula with terms. -/
def subst {n : ℕ} (φ : L.BoundedFormula α n) (f : α → L.Term β) : L.BoundedFormula β n :=
φ.mapTermRel (fun _ t => t.subst (Sum.elim (Term.relabel Sum.inl ∘ f) (var ∘ Sum.inr)))
(fun _ => id) fun _ => id
/-- A bijection sending formulas with constants to formulas with extra variables. -/
def constantsVarsEquiv : L[[γ]].BoundedFormula α n ≃ L.BoundedFormula (γ ⊕ α) n :=
mapTermRelEquiv (fun _ => Term.constantsVarsEquivLeft) fun _ => Equiv.sumEmpty _ _
-- Porting note: universes in different order
/-- Turns the extra variables of a bounded formula into free variables. -/
@[simp]
def toFormula : ∀ {n : ℕ}, L.BoundedFormula α n → L.Formula (α ⊕ (Fin n))
| _n, falsum => falsum
| _n, equal t₁ t₂ => t₁.equal t₂
| _n, rel R ts => R.formula ts
| _n, imp φ₁ φ₂ => φ₁.toFormula.imp φ₂.toFormula
| _n, all φ =>
(φ.toFormula.relabel
(Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ finSumFinEquiv.symm))).all
/-- take the disjunction of a finite set of formulas -/
noncomputable def iSup (s : Finset β) (f : β → L.BoundedFormula α n) : L.BoundedFormula α n :=
(s.toList.map f).foldr (· ⊔ ·) ⊥
/-- take the conjunction of a finite set of formulas -/
noncomputable def iInf (s : Finset β) (f : β → L.BoundedFormula α n) : L.BoundedFormula α n :=
(s.toList.map f).foldr (· ⊓ ·) ⊤
end BoundedFormula
namespace LHom
open BoundedFormula
-- Porting note: universes in different order
/-- Maps a bounded formula's symbols along a language map. -/
@[simp]
def onBoundedFormula (g : L →ᴸ L') : ∀ {k : ℕ}, L.BoundedFormula α k → L'.BoundedFormula α k
| _k, falsum => falsum
| _k, equal t₁ t₂ => (g.onTerm t₁).bdEqual (g.onTerm t₂)
| _k, rel R ts => (g.onRelation R).boundedFormula (g.onTerm ∘ ts)
| _k, imp f₁ f₂ => (onBoundedFormula g f₁).imp (onBoundedFormula g f₂)
| _k, all f => (onBoundedFormula g f).all
@[simp]
theorem id_onBoundedFormula :
((LHom.id L).onBoundedFormula : L.BoundedFormula α n → L.BoundedFormula α n) = id := by
ext f
induction' f with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· rw [onBoundedFormula, LHom.id_onTerm, id, id, id, Term.bdEqual]
· rw [onBoundedFormula, LHom.id_onTerm]
rfl
· rw [onBoundedFormula, ih1, ih2, id, id, id]
· rw [onBoundedFormula, ih3, id, id]
@[simp]
theorem comp_onBoundedFormula {L'' : Language} (φ : L' →ᴸ L'') (ψ : L →ᴸ L') :
((φ.comp ψ).onBoundedFormula : L.BoundedFormula α n → L''.BoundedFormula α n) =
φ.onBoundedFormula ∘ ψ.onBoundedFormula := by
ext f
induction' f with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3
· rfl
· simp only [onBoundedFormula, comp_onTerm, Function.comp_apply]
· simp only [onBoundedFormula, comp_onRelation, comp_onTerm, Function.comp_apply]
rfl
· simp only [onBoundedFormula, Function.comp_apply, ih1, ih2, eq_self_iff_true, and_self_iff]
· simp only [ih3, onBoundedFormula, Function.comp_apply]
/-- Maps a formula's symbols along a language map. -/
def onFormula (g : L →ᴸ L') : L.Formula α → L'.Formula α :=
g.onBoundedFormula
/-- Maps a sentence's symbols along a language map. -/
def onSentence (g : L →ᴸ L') : L.Sentence → L'.Sentence :=
g.onFormula
/-- Maps a theory's symbols along a language map. -/
def onTheory (g : L →ᴸ L') (T : L.Theory) : L'.Theory :=
g.onSentence '' T
@[simp]
theorem mem_onTheory {g : L →ᴸ L'} {T : L.Theory} {φ : L'.Sentence} :
φ ∈ g.onTheory T ↔ ∃ φ₀, φ₀ ∈ T ∧ g.onSentence φ₀ = φ :=
Set.mem_image _ _ _
end LHom
namespace LEquiv
/-- Maps a bounded formula's symbols along a language equivalence. -/
@[simps]
def onBoundedFormula (φ : L ≃ᴸ L') : L.BoundedFormula α n ≃ L'.BoundedFormula α n where
toFun := φ.toLHom.onBoundedFormula
invFun := φ.invLHom.onBoundedFormula
left_inv := by
rw [Function.leftInverse_iff_comp, ← LHom.comp_onBoundedFormula, φ.left_inv,
LHom.id_onBoundedFormula]
right_inv := by
rw [Function.rightInverse_iff_comp, ← LHom.comp_onBoundedFormula, φ.right_inv,
LHom.id_onBoundedFormula]
theorem onBoundedFormula_symm (φ : L ≃ᴸ L') :
(φ.onBoundedFormula.symm : L'.BoundedFormula α n ≃ L.BoundedFormula α n) =
φ.symm.onBoundedFormula :=
rfl
/-- Maps a formula's symbols along a language equivalence. -/
def onFormula (φ : L ≃ᴸ L') : L.Formula α ≃ L'.Formula α :=
φ.onBoundedFormula
@[simp]
theorem onFormula_apply (φ : L ≃ᴸ L') :
(φ.onFormula : L.Formula α → L'.Formula α) = φ.toLHom.onFormula :=
rfl
@[simp]
theorem onFormula_symm (φ : L ≃ᴸ L') :
(φ.onFormula.symm : L'.Formula α ≃ L.Formula α) = φ.symm.onFormula :=
rfl
/-- Maps a sentence's symbols along a language equivalence. -/
@[simps!] -- Porting note: add `!` to `simps`
def onSentence (φ : L ≃ᴸ L') : L.Sentence ≃ L'.Sentence :=
φ.onFormula
end LEquiv
scoped[FirstOrder] infixl:88 " =' " => FirstOrder.Language.Term.bdEqual
-- input \~- or \simeq
scoped[FirstOrder] infixr:62 " ⟹ " => FirstOrder.Language.BoundedFormula.imp
-- input \==>
scoped[FirstOrder] prefix:110 "∀'" => FirstOrder.Language.BoundedFormula.all
scoped[FirstOrder] prefix:arg "∼" => FirstOrder.Language.BoundedFormula.not
-- input \~, the ASCII character ~ has too low precedence
scoped[FirstOrder] infixl:61 " ⇔ " => FirstOrder.Language.BoundedFormula.iff
-- input \<=>
scoped[FirstOrder] prefix:110 "∃'" => FirstOrder.Language.BoundedFormula.ex
-- input \ex
namespace Formula
/-- Relabels a formula's variables along a particular function. -/
def relabel (g : α → β) : L.Formula α → L.Formula β :=
@BoundedFormula.relabel _ _ _ 0 (Sum.inl ∘ g) 0
/-- The graph of a function as a first-order formula. -/
def graph (f : L.Functions n) : L.Formula (Fin (n + 1)) :=
Term.equal (var 0) (func f fun i => var i.succ)
/-- The negation of a formula. -/
protected nonrec abbrev not (φ : L.Formula α) : L.Formula α :=
φ.not
/-- The implication between formulas, as a formula. -/
protected abbrev imp : L.Formula α → L.Formula α → L.Formula α :=
BoundedFormula.imp
/-- Given a map `f : α → β ⊕ γ`, `iAlls f φ` transforms a `L.Formula α`
into a `L.Formula β` by renaming variables with the map `f` and then universally
quantifying over all variables `Sum.inr _`. -/
noncomputable def iAlls [Finite γ] (f : α → β ⊕ γ)
(φ : L.Formula α) : L.Formula β :=
let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ))
(BoundedFormula.relabel (fun a => Sum.map id e (f a)) φ).alls
/-- Given a map `f : α → β ⊕ γ`, `iExs f φ` transforms a `L.Formula α`
into a `L.Formula β` by renaming variables with the map `f` and then universally
quantifying over all variables `Sum.inr _`. -/
noncomputable def iExs [Finite γ] (f : α → β ⊕ γ)
(φ : L.Formula α) : L.Formula β :=
let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ))
(BoundedFormula.relabel (fun a => Sum.map id e (f a)) φ).exs
/-- The biimplication between formulas, as a formula. -/
protected nonrec abbrev iff (φ ψ : L.Formula α) : L.Formula α :=
φ.iff ψ
/-- A bijection sending formulas to sentences with constants. -/
def equivSentence : L.Formula α ≃ L[[α]].Sentence :=
(BoundedFormula.constantsVarsEquiv.trans (BoundedFormula.relabelEquiv (Equiv.sumEmpty _ _))).symm
theorem equivSentence_not (φ : L.Formula α) : equivSentence φ.not = (equivSentence φ).not :=
rfl
theorem equivSentence_inf (φ ψ : L.Formula α) :
equivSentence (φ ⊓ ψ) = equivSentence φ ⊓ equivSentence ψ :=
rfl
end Formula
namespace Relations
variable (r : L.Relations 2)
/-- The sentence indicating that a basic relation symbol is reflexive. -/
protected def reflexive : L.Sentence :=
∀'r.boundedFormula₂ (&0) &0
/-- The sentence indicating that a basic relation symbol is irreflexive. -/
protected def irreflexive : L.Sentence :=
∀'∼(r.boundedFormula₂ (&0) &0)
/-- The sentence indicating that a basic relation symbol is symmetric. -/
protected def symmetric : L.Sentence :=
∀'∀'(r.boundedFormula₂ (&0) &1 ⟹ r.boundedFormula₂ (&1) &0)
/-- The sentence indicating that a basic relation symbol is antisymmetric. -/
protected def antisymmetric : L.Sentence :=
∀'∀'(r.boundedFormula₂ (&0) &1 ⟹ r.boundedFormula₂ (&1) &0 ⟹ Term.bdEqual (&0) &1)
/-- The sentence indicating that a basic relation symbol is transitive. -/
protected def transitive : L.Sentence :=
∀'∀'∀'(r.boundedFormula₂ (&0) &1 ⟹ r.boundedFormula₂ (&1) &2 ⟹ r.boundedFormula₂ (&0) &2)
/-- The sentence indicating that a basic relation symbol is total. -/
protected def total : L.Sentence :=
∀'∀'(r.boundedFormula₂ (&0) &1 ⊔ r.boundedFormula₂ (&1) &0)
end Relations
section Cardinality
variable (L)
/-- A sentence indicating that a structure has `n` distinct elements. -/
protected def Sentence.cardGe (n : ℕ) : L.Sentence :=
((((List.finRange n ×ˢ List.finRange n).filter fun ij : _ × _ => ij.1 ≠ ij.2).map
fun ij : _ × _ => ∼((&ij.1).bdEqual &ij.2)).foldr
(· ⊓ ·) ⊤).exs
/-- A theory indicating that a structure is infinite. -/
def infiniteTheory : L.Theory :=
Set.range (Sentence.cardGe L)
/-- A theory that indicates a structure is nonempty. -/
def nonemptyTheory : L.Theory :=
{Sentence.cardGe L 1}
/-- A theory indicating that each of a set of constants is distinct. -/
def distinctConstantsTheory (s : Set α) : L[[α]].Theory :=
(fun ab : α × α => ((L.con ab.1).term.equal (L.con ab.2).term).not) ''
(s ×ˢ s ∩ (Set.diagonal α)ᶜ)
variable {L}
open Set
theorem distinctConstantsTheory_mono {s t : Set α} (h : s ⊆ t) :
L.distinctConstantsTheory s ⊆ L.distinctConstantsTheory t := by
unfold distinctConstantsTheory; gcongr
theorem monotone_distinctConstantsTheory :
Monotone (L.distinctConstantsTheory : Set α → L[[α]].Theory) := fun _s _t st =>
L.distinctConstantsTheory_mono st
theorem directed_distinctConstantsTheory :
Directed (· ⊆ ·) (L.distinctConstantsTheory : Set α → L[[α]].Theory) :=
Monotone.directed_le monotone_distinctConstantsTheory
theorem distinctConstantsTheory_eq_iUnion (s : Set α) :
L.distinctConstantsTheory s =
⋃ t : Finset s,
L.distinctConstantsTheory (t.map (Function.Embedding.subtype fun x => x ∈ s)) := by
classical
simp only [distinctConstantsTheory]
rw [← image_iUnion, ← iUnion_inter]
refine congr(_ '' ($(?_) ∩ _))
ext ⟨i, j⟩
simp only [prod_mk_mem_set_prod_eq, Finset.coe_map, Function.Embedding.coe_subtype, mem_iUnion,
mem_image, Finset.mem_coe, Subtype.exists, Subtype.coe_mk, exists_and_right, exists_eq_right]
refine ⟨fun h => ⟨{⟨i, h.1⟩, ⟨j, h.2⟩}, ⟨h.1, ?_⟩, ⟨h.2, ?_⟩⟩, ?_⟩
· simp
· simp
· rintro ⟨t, ⟨is, _⟩, ⟨js, _⟩⟩
exact ⟨is, js⟩
end Cardinality
end Language
end FirstOrder
|
ModelTheory\Types.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Satisfiability
/-!
# Type Spaces
This file defines the space of complete types over a first-order theory.
(Note that types in model theory are different from types in type theory.)
## Main Definitions
- `FirstOrder.Language.Theory.CompleteType`:
`T.CompleteType α` consists of complete types over the theory `T` with variables `α`.
- `FirstOrder.Language.Theory.typeOf` is the type of a given tuple.
- `FirstOrder.Language.Theory.realizedTypes`: `T.realizedTypes M α` is the set of
types in `T.CompleteType α` that are realized in `M` - that is, the type of some tuple in `M`.
## Main Results
- `FirstOrder.Language.Theory.CompleteType.nonempty_iff`:
The space `T.CompleteType α` is nonempty exactly when `T` is satisfiable.
- `FirstOrder.Language.Theory.CompleteType.exists_modelType_is_realized_in`: Every type is realized
in some model.
## Implementation Notes
- Complete types are implemented as maximal consistent theories in an expanded language.
More frequently they are described as maximal consistent sets of formulas, but this is equivalent.
## TODO
- Connect `T.CompleteType α` to sets of formulas `L.Formula α`.
-/
universe u v w w'
open Cardinal Set FirstOrder
namespace FirstOrder
namespace Language
namespace Theory
variable {L : Language.{u, v}} (T : L.Theory) (α : Type w)
/-- A complete type over a given theory in a certain type of variables is a maximally
consistent (with the theory) set of formulas in that type. -/
structure CompleteType where
toTheory : L[[α]].Theory
subset' : (L.lhomWithConstants α).onTheory T ⊆ toTheory
isMaximal' : toTheory.IsMaximal
variable {T α}
namespace CompleteType
attribute [coe] CompleteType.toTheory
instance Sentence.instSetLike : SetLike (T.CompleteType α) (L[[α]].Sentence) :=
⟨fun p => p.toTheory, fun p q h => by
cases p
cases q
congr ⟩
theorem isMaximal (p : T.CompleteType α) : IsMaximal (p : L[[α]].Theory) :=
p.isMaximal'
theorem subset (p : T.CompleteType α) : (L.lhomWithConstants α).onTheory T ⊆ (p : L[[α]].Theory) :=
p.subset'
theorem mem_or_not_mem (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ ∈ p ∨ φ.not ∈ p :=
p.isMaximal.mem_or_not_mem φ
theorem mem_of_models (p : T.CompleteType α) {φ : L[[α]].Sentence}
(h : (L.lhomWithConstants α).onTheory T ⊨ᵇ φ) : φ ∈ p :=
(p.mem_or_not_mem φ).resolve_right fun con =>
((models_iff_not_satisfiable _).1 h)
(p.isMaximal.1.mono (union_subset p.subset (singleton_subset_iff.2 con)))
theorem not_mem_iff (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ.not ∈ p ↔ ¬φ ∈ p :=
⟨fun hf ht => by
have h : ¬IsSatisfiable ({φ, φ.not} : L[[α]].Theory) := by
rintro ⟨@⟨_, _, h, _⟩⟩
simp only [model_iff, mem_insert_iff, mem_singleton_iff, forall_eq_or_imp, forall_eq] at h
exact h.2 h.1
refine h (p.isMaximal.1.mono ?_)
rw [insert_subset_iff, singleton_subset_iff]
exact ⟨ht, hf⟩, (p.mem_or_not_mem φ).resolve_left⟩
@[simp]
theorem compl_setOf_mem {φ : L[[α]].Sentence} :
{ p : T.CompleteType α | φ ∈ p }ᶜ = { p : T.CompleteType α | φ.not ∈ p } :=
ext fun _ => (not_mem_iff _ _).symm
theorem setOf_subset_eq_empty_iff (S : L[[α]].Theory) :
{ p : T.CompleteType α | S ⊆ ↑p } = ∅ ↔
¬((L.lhomWithConstants α).onTheory T ∪ S).IsSatisfiable := by
rw [iff_not_comm, ← not_nonempty_iff_eq_empty, Classical.not_not, Set.Nonempty]
refine
⟨fun h =>
⟨⟨L[[α]].completeTheory h.some, (subset_union_left (t := S)).trans completeTheory.subset,
completeTheory.isMaximal (L[[α]]) h.some⟩,
(((L.lhomWithConstants α).onTheory T).subset_union_right).trans completeTheory.subset⟩,
?_⟩
rintro ⟨p, hp⟩
exact p.isMaximal.1.mono (union_subset p.subset hp)
theorem setOf_mem_eq_univ_iff (φ : L[[α]].Sentence) :
{ p : T.CompleteType α | φ ∈ p } = Set.univ ↔ (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by
rw [models_iff_not_satisfiable, ← compl_empty_iff, compl_setOf_mem, ← setOf_subset_eq_empty_iff]
simp
theorem setOf_subset_eq_univ_iff (S : L[[α]].Theory) :
{ p : T.CompleteType α | S ⊆ ↑p } = Set.univ ↔
∀ φ, φ ∈ S → (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by
have h : { p : T.CompleteType α | S ⊆ ↑p } = ⋂₀ ((fun φ => { p | φ ∈ p }) '' S) := by
ext
simp [subset_def]
simp_rw [h, sInter_eq_univ, ← setOf_mem_eq_univ_iff]
refine ⟨fun h φ φS => h _ ⟨_, φS, rfl⟩, ?_⟩
rintro h _ ⟨φ, h1, rfl⟩
exact h _ h1
theorem nonempty_iff : Nonempty (T.CompleteType α) ↔ T.IsSatisfiable := by
rw [← isSatisfiable_onTheory_iff (lhomWithConstants_injective L α)]
rw [nonempty_iff_univ_nonempty, nonempty_iff_ne_empty, Ne, not_iff_comm,
← union_empty ((L.lhomWithConstants α).onTheory T), ← setOf_subset_eq_empty_iff]
simp
instance instNonempty : Nonempty (CompleteType (∅ : L.Theory) α) :=
nonempty_iff.2 (isSatisfiable_empty L)
theorem iInter_setOf_subset {ι : Type*} (S : ι → L[[α]].Theory) :
⋂ i : ι, { p : T.CompleteType α | S i ⊆ p } =
{ p : T.CompleteType α | ⋃ i : ι, S i ⊆ p } := by
ext
simp only [mem_iInter, mem_setOf_eq, iUnion_subset_iff]
theorem toList_foldr_inf_mem {p : T.CompleteType α} {t : Finset (L[[α]]).Sentence} :
t.toList.foldr (· ⊓ ·) ⊤ ∈ p ↔ (t : L[[α]].Theory) ⊆ ↑p := by
simp_rw [subset_def, ← SetLike.mem_coe, p.isMaximal.mem_iff_models, models_sentence_iff,
Sentence.Realize, Formula.Realize, BoundedFormula.realize_foldr_inf, Finset.mem_toList]
exact ⟨fun h φ hφ M => h _ _ hφ, fun h M φ hφ => h _ hφ _⟩
end CompleteType
variable {M : Type w'} [L.Structure M] [Nonempty M] [M ⊨ T] (T)
/-- The set of all formulas true at a tuple in a structure forms a complete type. -/
def typeOf (v : α → M) : T.CompleteType α :=
haveI : (constantsOn α).Structure M := constantsOn.structure v
{ toTheory := L[[α]].completeTheory M
subset' := model_iff_subset_completeTheory.1 ((LHom.onTheory_model _ T).2 inferInstance)
isMaximal' := completeTheory.isMaximal _ _ }
namespace CompleteType
variable {T} {v : α → M}
@[simp]
theorem mem_typeOf {φ : L[[α]].Sentence} :
φ ∈ T.typeOf v ↔ (Formula.equivSentence.symm φ).Realize v :=
letI : (constantsOn α).Structure M := constantsOn.structure v
mem_completeTheory.trans (Formula.realize_equivSentence_symm _ _ _).symm
theorem formula_mem_typeOf {φ : L.Formula α} :
Formula.equivSentence φ ∈ T.typeOf v ↔ φ.Realize v := by simp
end CompleteType
variable (M)
/-- A complete type `p` is realized in a particular structure when there is some
tuple `v` whose type is `p`. -/
@[simp]
def realizedTypes (α : Type w) : Set (T.CompleteType α) :=
Set.range (T.typeOf : (α → M) → T.CompleteType α)
section
-- Porting note: This instance interrupts synthesizing instances.
attribute [-instance] FirstOrder.Language.withConstants_expansion
theorem exists_modelType_is_realized_in (p : T.CompleteType α) :
∃ M : Theory.ModelType.{u, v, max u v w} T, p ∈ T.realizedTypes M α := by
obtain ⟨M⟩ := p.isMaximal.1
refine ⟨(M.subtheoryModel p.subset).reduct (L.lhomWithConstants α), fun a => (L.con a : M), ?_⟩
refine SetLike.ext fun φ => ?_
simp only [CompleteType.mem_typeOf]
refine
(@Formula.realize_equivSentence_symm_con _
((M.subtheoryModel p.subset).reduct (L.lhomWithConstants α)) _ _ M.struc _ φ).trans
(_root_.trans (_root_.trans ?_ (p.isMaximal.isComplete.realize_sentence_iff φ M))
(p.isMaximal.mem_iff_models φ).symm)
rfl
end
end Theory
end Language
end FirstOrder
|
ModelTheory\Ultraproducts.lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Quotients
import Mathlib.Order.Filter.Germ.Basic
import Mathlib.Order.Filter.Ultrafilter
/-!
# Ultraproducts and Łoś's Theorem
## Main Definitions
- `FirstOrder.Language.Ultraproduct.Structure` is the ultraproduct structure on `Filter.Product`.
## Main Results
- Łoś's Theorem: `FirstOrder.Language.Ultraproduct.sentence_realize`. An ultraproduct models a
sentence `φ` if and only if the set of structures in the product that model `φ` is in the
ultrafilter.
## Tags
ultraproduct, Los's theorem
-/
universe u v
variable {α : Type*} (M : α → Type*) (u : Ultrafilter α)
open FirstOrder Filter
open Filter
namespace FirstOrder
namespace Language
open Structure
variable {L : Language.{u, v}} [∀ a, L.Structure (M a)]
namespace Ultraproduct
instance setoidPrestructure : L.Prestructure ((u : Filter α).productSetoid M) :=
{ (u : Filter α).productSetoid M with
toStructure :=
{ funMap := fun {n} f x a => funMap f fun i => x i a
RelMap := fun {n} r x => ∀ᶠ a : α in u, RelMap r fun i => x i a }
fun_equiv := fun {n} f x y xy => by
refine mem_of_superset (iInter_mem.2 xy) fun a ha => ?_
simp only [Set.mem_iInter, Set.mem_setOf_eq] at ha
simp only [Set.mem_setOf_eq, ha]
rel_equiv := fun {n} r x y xy => by
rw [← iff_eq_eq]
refine ⟨fun hx => ?_, fun hy => ?_⟩
· refine mem_of_superset (inter_mem hx (iInter_mem.2 xy)) ?_
rintro a ⟨ha1, ha2⟩
simp only [Set.mem_iInter, Set.mem_setOf_eq] at *
rw [← funext ha2]
exact ha1
· refine mem_of_superset (inter_mem hy (iInter_mem.2 xy)) ?_
rintro a ⟨ha1, ha2⟩
simp only [Set.mem_iInter, Set.mem_setOf_eq] at *
rw [funext ha2]
exact ha1 }
variable {M} {u}
instance «structure» : L.Structure ((u : Filter α).Product M) :=
Language.quotientStructure
theorem funMap_cast {n : ℕ} (f : L.Functions n) (x : Fin n → ∀ a, M a) :
(funMap f fun i => (x i : (u : Filter α).Product M)) =
(fun a => funMap f fun i => x i a : (u : Filter α).Product M) := by
apply funMap_quotient_mk'
theorem term_realize_cast {β : Type*} (x : β → ∀ a, M a) (t : L.Term β) :
(t.realize fun i => (x i : (u : Filter α).Product M)) =
(fun a => t.realize fun i => x i a : (u : Filter α).Product M) := by
convert @Term.realize_quotient_mk' L _ ((u : Filter α).productSetoid M)
(Ultraproduct.setoidPrestructure M u) _ t x using 2
ext a
induction t with
| var => rfl
| func _ _ t_ih => simp only [Term.realize, t_ih]; rfl
variable [∀ a : α, Nonempty (M a)]
theorem boundedFormula_realize_cast {β : Type*} {n : ℕ} (φ : L.BoundedFormula β n)
(x : β → ∀ a, M a) (v : Fin n → ∀ a, M a) :
(φ.Realize (fun i : β => (x i : (u : Filter α).Product M))
(fun i => (v i : (u : Filter α).Product M))) ↔
∀ᶠ a : α in u, φ.Realize (fun i : β => x i a) fun i => v i a := by
letI := (u : Filter α).productSetoid M
induction' φ with _ _ _ _ _ _ _ _ m _ _ ih ih' k φ ih
· simp only [BoundedFormula.Realize, eventually_const]
· have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a :=
fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl
simp only [BoundedFormula.Realize, h2, term_realize_cast]
erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm,
term_realize_cast, term_realize_cast]
exact Quotient.eq''
· have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a :=
fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl
simp only [BoundedFormula.Realize, h2]
erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm]
conv_lhs => enter [2, i]; erw [term_realize_cast]
apply relMap_quotient_mk'
· simp only [BoundedFormula.Realize, ih v, ih' v]
rw [Ultrafilter.eventually_imp]
· simp only [BoundedFormula.Realize]
apply Iff.trans (b := ∀ m : ∀ a : α, M a,
φ.Realize (fun i : β => (x i : (u : Filter α).Product M))
(Fin.snoc (((↑) : (∀ a, M a) → (u : Filter α).Product M) ∘ v)
(m : (u : Filter α).Product M)))
· exact Quotient.forall
have h' :
∀ (m : ∀ a, M a) (a : α),
(fun i : Fin (k + 1) => (Fin.snoc v m : _ → ∀ a, M a) i a) =
Fin.snoc (fun i : Fin k => v i a) (m a) := by
refine fun m a => funext (Fin.reverseInduction ?_ fun i _ => ?_)
· simp only [Fin.snoc_last]
· simp only [Fin.snoc_castSucc]
simp only [← Fin.comp_snoc]
simp only [Function.comp, ih, h']
refine ⟨fun h => ?_, fun h m => ?_⟩
· contrapose! h
simp_rw [← Ultrafilter.eventually_not, not_forall] at h
refine
⟨fun a : α =>
Classical.epsilon fun m : M a =>
¬φ.Realize (fun i => x i a) (Fin.snoc (fun i => v i a) m),
?_⟩
rw [← Ultrafilter.eventually_not]
exact Filter.mem_of_superset h fun a ha => Classical.epsilon_spec ha
· rw [Filter.eventually_iff] at *
exact Filter.mem_of_superset h fun a ha => ha (m a)
theorem realize_formula_cast {β : Type*} (φ : L.Formula β) (x : β → ∀ a, M a) :
(φ.Realize fun i => (x i : (u : Filter α).Product M)) ↔
∀ᶠ a : α in u, φ.Realize fun i => x i a := by
simp_rw [Formula.Realize, ← boundedFormula_realize_cast φ x, iff_eq_eq]
exact congr rfl (Subsingleton.elim _ _)
/-- **Łoś's Theorem**: A sentence is true in an ultraproduct if and only if the set of structures
it is true in is in the ultrafilter. -/
theorem sentence_realize (φ : L.Sentence) :
(u : Filter α).Product M ⊨ φ ↔ ∀ᶠ a : α in u, M a ⊨ φ := by
simp_rw [Sentence.Realize]
erw [← realize_formula_cast φ, iff_eq_eq]
exact congr rfl (Subsingleton.elim _ _)
nonrec instance Product.instNonempty : Nonempty ((u : Filter α).Product M) :=
letI : ∀ a, Inhabited (M a) := fun _ => Classical.inhabited_of_nonempty'
inferInstance
end Ultraproduct
end Language
end FirstOrder
|
ModelTheory\Algebra\Field\Basic.lean | /-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.ModelTheory.Syntax
import Mathlib.ModelTheory.Semantics
import Mathlib.ModelTheory.Algebra.Ring.Basic
import Mathlib.Algebra.Field.MinimalAxioms
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# The First Order Theory of Fields
This file defines the first order theory of fields as a theory over the language of rings.
## Main definitions
- `FirstOrder.Language.Theory.field` : the theory of fields
- `FirstOrder.Model.fieldOfModelField` : a model of the theory of fields on a type `K` that
already has ring operations.
- `FirstOrder.Model.compatibleRingOfModelField` : shows that the ring operations on `K` given
by `fieldOfModelField` are compatible with the ring operations on `K` given by the
`Language.ring.Structure` instance.
-/
variable {K : Type*}
namespace FirstOrder
namespace Field
open Language Ring Structure BoundedFormula
/-- An indexing type to name each of the field axioms. The theory
of fields is defined as the range of a function `FieldAxiom ->
Language.ring.Sentence` -/
inductive FieldAxiom : Type
| addAssoc : FieldAxiom
| zeroAdd : FieldAxiom
| addLeftNeg : FieldAxiom
| mulAssoc : FieldAxiom
| mulComm : FieldAxiom
| oneMul : FieldAxiom
| existsInv : FieldAxiom
| leftDistrib : FieldAxiom
| existsPairNE : FieldAxiom
/-- The first order sentence corresponding to each field axiom -/
@[simp]
def FieldAxiom.toSentence : FieldAxiom → Language.ring.Sentence
| .addAssoc => ∀' ∀' ∀' (((&0 + &1) + &2) =' (&0 + (&1 + &2)))
| .zeroAdd => ∀' (((0 : Language.ring.Term _) + &0) =' &0)
| .addLeftNeg => ∀' ∀' ((-&0 + &0) =' 0)
| .mulAssoc => ∀' ∀' ∀' (((&0 * &1) * &2) =' (&0 * (&1 * &2)))
| .mulComm => ∀' ∀' ((&0 * &1) =' (&1 * &0))
| .oneMul => ∀' (((1 : Language.ring.Term _) * &0) =' &0)
| .existsInv => ∀' (∼(&0 =' 0) ⟹ ∃' ((&0 * &1) =' 1))
| .leftDistrib => ∀' ∀' ∀' ((&0 * (&1 + &2)) =' ((&0 * &1) + (&0 * &2)))
| .existsPairNE => ∃' ∃' (∼(&0 =' &1))
/-- The Proposition corresponding to each field axiom -/
@[simp]
def FieldAxiom.toProp (K : Type*) [Add K] [Mul K] [Neg K] [Zero K] [One K] :
FieldAxiom → Prop
| .addAssoc => ∀ x y z : K, (x + y) + z = x + (y + z)
| .zeroAdd => ∀ x : K, 0 + x = x
| .addLeftNeg => ∀ x : K, -x + x = 0
| .mulAssoc => ∀ x y z : K, (x * y) * z = x * (y * z)
| .mulComm => ∀ x y : K, x * y = y * x
| .oneMul => ∀ x : K, 1 * x = x
| .existsInv => ∀ x : K, x ≠ 0 → ∃ y, x * y = 1
| .leftDistrib => ∀ x y z : K, x * (y + z) = x * y + x * z
| .existsPairNE => ∃ x y : K, x ≠ y
/-- The first order theory of fields, as a theory over the language of rings -/
def _root_.FirstOrder.Language.Theory.field : Language.ring.Theory :=
Set.range FieldAxiom.toSentence
theorem FieldAxiom.realize_toSentence_iff_toProp {K : Type*}
[Add K] [Mul K] [Neg K] [Zero K] [One K] [CompatibleRing K]
(ax : FieldAxiom) :
(K ⊨ (ax.toSentence : Sentence Language.ring)) ↔ ax.toProp K := by
cases ax <;>
simp [Sentence.Realize, Formula.Realize, Fin.snoc]
theorem FieldAxiom.toProp_of_model {K : Type*}
[Add K] [Mul K] [Neg K] [Zero K] [One K] [CompatibleRing K]
[Theory.field.Model K] (ax : FieldAxiom) : ax.toProp K :=
(FieldAxiom.realize_toSentence_iff_toProp ax).1
(Theory.realize_sentence_of_mem Theory.field
(Set.mem_range_self ax))
open FieldAxiom
/-- A model for the theory of fields is a field. To introduced locally on Types that don't
already have instances for ring operations.
When this is used, it is almost always useful to also add locally the instance
`compatibleFieldOfModelField` afterwards. -/
noncomputable abbrev fieldOfModelField (K : Type*) [Language.ring.Structure K]
[Theory.field.Model K] : Field K :=
letI : DecidableEq K := Classical.decEq K
letI := addOfRingStructure K
letI := mulOfRingStructure K
letI := negOfRingStructure K
letI := zeroOfRingStructure K
letI := oneOfRingStructure K
letI := compatibleRingOfRingStructure K
have exists_inv : ∀ x : K, x ≠ 0 → ∃ y : K, x * y = 1 :=
existsInv.toProp_of_model
letI : Inv K := ⟨fun x => if hx0 : x = 0 then 0 else Classical.choose (exists_inv x hx0)⟩
Field.ofMinimalAxioms K
addAssoc.toProp_of_model
zeroAdd.toProp_of_model
addLeftNeg.toProp_of_model
mulAssoc.toProp_of_model
mulComm.toProp_of_model
oneMul.toProp_of_model
(fun x hx0 => show x * (dite _ _ _) = _ from
(dif_neg hx0).symm ▸ Classical.choose_spec (existsInv.toProp_of_model x hx0))
(dif_pos rfl)
leftDistrib.toProp_of_model
existsPairNE.toProp_of_model
section
attribute [local instance] fieldOfModelField
/-- The instances given by `fieldOfModelField` are compatible with the `Language.ring.Structure`
instance on `K`. This instance is to be used on models for the language of fields that do
not already have the ring operations on the Type.
Always add `fieldOfModelField` as a local instance first before using this instance.
-/
noncomputable abbrev compatibleRingOfModelField (K : Type*) [Language.ring.Structure K]
[Theory.field.Model K] : CompatibleRing K :=
compatibleRingOfRingStructure K
end
instance [Field K] [CompatibleRing K] : Theory.field.Model K :=
{ realize_of_mem := by
simp only [Theory.field, Set.mem_range, exists_imp]
rintro φ a rfl
rw [a.realize_toSentence_iff_toProp (K := K)]
cases a with
| existsPairNE => exact exists_pair_ne K
| existsInv => exact fun x hx0 => ⟨x⁻¹, mul_inv_cancel hx0⟩
| addAssoc => exact add_assoc
| zeroAdd => exact zero_add
| addLeftNeg => exact add_left_neg
| mulAssoc => exact mul_assoc
| mulComm => exact mul_comm
| oneMul => exact one_mul
| leftDistrib => exact mul_add }
end Field
end FirstOrder
|
ModelTheory\Algebra\Field\CharP.lean | /-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.ModelTheory.Algebra.Ring.FreeCommRing
import Mathlib.ModelTheory.Algebra.Field.Basic
/-!
# First order theory of fields
This file defines the first order theory of fields of characteristic `p` as a theory over the
language of rings
## Main definitions
- `FirstOrder.Language.Theory.fieldOfChar` : the first order theory of fields of characteristic `p`
as a theory over the language of rings
-/
variable {p : ℕ} {K : Type*}
namespace FirstOrder
namespace Field
open Language Ring
/-- For a given natural number `n`, `eqZero n` is the sentence in the language of rings
saying that `n` is zero. -/
noncomputable def eqZero (n : ℕ) : Language.ring.Sentence :=
Term.equal (termOfFreeCommRing n) 0
@[simp] theorem realize_eqZero [CommRing K] [CompatibleRing K] (n : ℕ)
(v : Empty → K) : (Formula.Realize (eqZero n) v) ↔ ((n : K) = 0) := by
simp [eqZero, Term.realize]
/-- The first order theory of fields of characteristic `p` as a theory over the language of rings -/
def _root_.FirstOrder.Language.Theory.fieldOfChar (p : ℕ) : Language.ring.Theory :=
Theory.field ∪
if p = 0
then (fun q => ∼(eqZero q)) '' {q : ℕ | q.Prime}
else if p.Prime then {eqZero p}
else {⊥}
instance model_hasChar_of_charP [Field K] [CompatibleRing K] [CharP K p] :
(Theory.fieldOfChar p).Model K := by
refine Language.Theory.model_union_iff.2 ⟨inferInstance, ?_⟩
cases CharP.char_is_prime_or_zero K p with
| inl hp =>
simp [hp.ne_zero, hp, Sentence.Realize]
| inr hp =>
subst hp
simp only [ite_false, ite_true, Theory.model_iff, Set.mem_image, Set.mem_setOf_eq,
Sentence.Realize, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂,
Formula.realize_not, realize_eqZero, ← CharZero.charZero_iff_forall_prime_ne_zero]
exact CharP.charP_to_charZero K
theorem charP_iff_model_fieldOfChar [Field K] [CompatibleRing K] :
(Theory.fieldOfChar p).Model K ↔ CharP K p := by
simp only [Theory.fieldOfChar, Theory.model_union_iff,
(show (Theory.field.Model K) by infer_instance), true_and]
split_ifs with hp0 hp
· subst hp0
simp only [Theory.model_iff, Set.mem_image, Set.mem_setOf_eq, Sentence.Realize,
forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Formula.realize_not,
realize_eqZero, ← CharZero.charZero_iff_forall_prime_ne_zero]
exact ⟨fun _ => CharP.ofCharZero _, fun _ => CharP.charP_to_charZero K⟩
· simp only [Theory.model_iff, Set.mem_singleton_iff, Sentence.Realize, forall_eq,
realize_eqZero, ← CharP.charP_iff_prime_eq_zero hp]
· simp only [Theory.model_iff, Set.mem_singleton_iff, Sentence.Realize,
forall_eq, Formula.realize_bot, false_iff]
intro H
cases (CharP.char_is_prime_or_zero K p) <;> simp_all
instance model_fieldOfChar_of_charP [Field K] [CompatibleRing K]
[CharP K p] : (Theory.fieldOfChar p).Model K :=
charP_iff_model_fieldOfChar.2 inferInstance
variable (p) (K)
/- Not an instance because it caused performance problems in a different file. -/
theorem charP_of_model_fieldOfChar [Field K] [CompatibleRing K]
[h : (Theory.fieldOfChar p).Model K] : CharP K p :=
charP_iff_model_fieldOfChar.1 h
end Field
end FirstOrder
|
ModelTheory\Algebra\Ring\Basic.lean | /-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.ModelTheory.Syntax
import Mathlib.ModelTheory.Semantics
import Mathlib.Algebra.Ring.Equiv
/-!
# First Order Language of Rings
This file defines the first order language of rings, as well as defining instance of `Add`, `Mul`,
etc. on terms in the language.
## Main Definitions
- `FirstOrder.Language.ring` : the language of rings, with function symbols `+`, `*`, `-`, `0`, `1`
- `FirstOrder.Ring.CompatibleRing` : A class stating that a type is a `Language.ring.Structure`, and
that this structure is the same as the structure given by the classes `Add`, `Mul`, etc. already
on `R`.
- `FirstOrder.Ring.compatibleRingOfRing` : Given a type `R` with instances for each of the `Ring`
operations, make a `compatibleRing` instance.
## Implementation Notes
There are implementation difficulties with the model theory of rings caused by the fact that there
are two different ways to say that `R` is a `Ring`. We can say `Ring R` or
`Language.ring.Structure R` and `Theory.ring.Model R` (The theory of rings is not implemented yet).
The recommended way to use this library is to use the hypotheses `CompatibleRing R` and `Ring R`
on any theorem that requires both a `Ring` instance and a `Language.ring.Structure` instance
in order to state the theorem. To apply such a theorem to a ring `R` with a `Ring` instance,
use the tactic `let _ := compatibleRingOfRing R`. To apply the theorem to `K`
a `Language.ring.Structure K` instance and for example an instance of `Theory.field.Model K`,
you must add local instances with definitions like `ModelTheory.Field.fieldOfModelField K` and
`FirstOrder.Ring.compatibleRingOfModelField K`.
(in `Mathlib/ModelTheory/Algebra/Field/Basic.lean`), depending on the Theory.
-/
variable {α : Type*}
namespace FirstOrder
open FirstOrder
/-- The type of Ring functions, to be used in the definition of the language of rings.
It contains the operations (+,*,-,0,1) -/
inductive ringFunc : ℕ → Type
| add : ringFunc 2
| mul : ringFunc 2
| neg : ringFunc 1
| zero : ringFunc 0
| one : ringFunc 0
deriving DecidableEq
/-- The language of rings contains the operations (+,*,-,0,1) -/
def Language.ring : Language :=
{ Functions := ringFunc
Relations := fun _ => Empty }
namespace Ring
open ringFunc Language
instance (n : ℕ) : DecidableEq (Language.ring.Functions n) := by
dsimp [Language.ring]; infer_instance
instance (n : ℕ) : DecidableEq (Language.ring.Relations n) := by
dsimp [Language.ring]; infer_instance
/-- `RingFunc.add`, but with the defeq type `Language.ring.Functions 2` instead
of `RingFunc 2` -/
abbrev addFunc : Language.ring.Functions 2 := add
/-- `RingFunc.mul`, but with the defeq type `Language.ring.Functions 2` instead
of `RingFunc 2` -/
abbrev mulFunc : Language.ring.Functions 2 := mul
/-- `RingFunc.neg`, but with the defeq type `Language.ring.Functions 1` instead
of `RingFunc 1` -/
abbrev negFunc : Language.ring.Functions 1 := neg
/-- `RingFunc.zero`, but with the defeq type `Language.ring.Functions 0` instead
of `RingFunc 0` -/
abbrev zeroFunc : Language.ring.Functions 0 := zero
/-- `RingFunc.one`, but with the defeq type `Language.ring.Functions 0` instead
of `RingFunc 0` -/
abbrev oneFunc : Language.ring.Functions 0 := one
instance (α : Type*) : Zero (Language.ring.Term α) :=
{ zero := Constants.term zeroFunc }
theorem zero_def (α : Type*) : (0 : Language.ring.Term α) = Constants.term zeroFunc := rfl
instance (α : Type*) : One (Language.ring.Term α) :=
{ one := Constants.term oneFunc }
theorem one_def (α : Type*) : (1 : Language.ring.Term α) = Constants.term oneFunc := rfl
instance (α : Type*) : Add (Language.ring.Term α) :=
{ add := addFunc.apply₂ }
theorem add_def (α : Type*) (t₁ t₂ : Language.ring.Term α) :
t₁ + t₂ = addFunc.apply₂ t₁ t₂ := rfl
instance (α : Type*) : Mul (Language.ring.Term α) :=
{ mul := mulFunc.apply₂ }
theorem mul_def (α : Type*) (t₁ t₂ : Language.ring.Term α) :
t₁ * t₂ = mulFunc.apply₂ t₁ t₂ := rfl
instance (α : Type*) : Neg (Language.ring.Term α) :=
{ neg := negFunc.apply₁ }
theorem neg_def (α : Type*) (t : Language.ring.Term α) :
-t = negFunc.apply₁ t := rfl
instance : Fintype Language.ring.Symbols :=
⟨⟨Multiset.ofList
[Sum.inl ⟨2, .add⟩,
Sum.inl ⟨2, .mul⟩,
Sum.inl ⟨1, .neg⟩,
Sum.inl ⟨0, .zero⟩,
Sum.inl ⟨0, .one⟩], by
dsimp [Language.Symbols]; decide⟩, by
intro x
dsimp [Language.Symbols]
rcases x with ⟨_, f⟩ | ⟨_, f⟩
· cases f <;> decide
· cases f ⟩
@[simp]
theorem card_ring : card Language.ring = 5 := by
have : Fintype.card Language.ring.Symbols = 5 := rfl
simp [Language.card, this]
open Language ring Structure
/-- A Type `R` is a `CompatibleRing` if it is a structure for the language of rings and this
structure is the same as the structure already given on `R` by the classes `Add`, `Mul` etc.
It is recommended to use this type class as a hypothesis to any theorem whose statement
requires a type to have be both a `Ring` (or `Field` etc.) and a
`Language.ring.Structure` -/
/- This class does not extend `Add` etc, because this way it can be used in
combination with a `Ring`, or `Field` instance without having multiple different
`Add` structures on the Type. -/
class CompatibleRing (R : Type*) [Add R] [Mul R] [Neg R] [One R] [Zero R]
extends Language.ring.Structure R where
/-- Addition in the `Language.ring.Structure` is the same as the addition given by the
`Add` instance -/
funMap_add : ∀ x, funMap addFunc x = x 0 + x 1
/-- Multiplication in the `Language.ring.Structure` is the same as the multiplication given by the
`Mul` instance -/
funMap_mul : ∀ x, funMap mulFunc x = x 0 * x 1
/-- Negation in the `Language.ring.Structure` is the same as the negation given by the
`Neg` instance -/
funMap_neg : ∀ x, funMap negFunc x = -x 0
/-- The constant `0` in the `Language.ring.Structure` is the same as the constant given by the
`Zero` instance -/
funMap_zero : ∀ x, funMap (zeroFunc : Language.ring.Constants) x = 0
/-- The constant `1` in the `Language.ring.Structure` is the same as the constant given by the
`One` instance -/
funMap_one : ∀ x, funMap (oneFunc : Language.ring.Constants) x = 1
open CompatibleRing
attribute [simp] funMap_add funMap_mul funMap_neg funMap_zero funMap_one
section
variable {R : Type*} [Add R] [Mul R] [Neg R] [One R] [Zero R] [CompatibleRing R]
@[simp]
theorem realize_add (x y : ring.Term α) (v : α → R) :
Term.realize v (x + y) = Term.realize v x + Term.realize v y := by
simp [add_def, funMap_add]
@[simp]
theorem realize_mul (x y : ring.Term α) (v : α → R) :
Term.realize v (x * y) = Term.realize v x * Term.realize v y := by
simp [mul_def, funMap_mul]
@[simp]
theorem realize_neg (x : ring.Term α) (v : α → R) :
Term.realize v (-x) = -Term.realize v x := by
simp [neg_def, funMap_neg]
@[simp]
theorem realize_zero (v : α → R) : Term.realize v (0 : ring.Term α) = 0 := by
simp [zero_def, funMap_zero, constantMap]
@[simp]
theorem realize_one (v : α → R) : Term.realize v (1 : ring.Term α) = 1 := by
simp [one_def, funMap_one, constantMap]
end
/-- Given a Type `R` with instances for each of the `Ring` operations, make a
`Language.ring.Structure R` instance, along with a proof that the operations given
by the `Language.ring.Structure` are the same as those given by the `Add` or `Mul` etc.
instances.
This definition can be used when applying a theorem about the model theory of rings
to a literal ring `R`, by writing `let _ := compatibleRingOfRing R`. After this, if,
for example, `R` is a field, then Lean will be able to find the instance for
`Theory.field.Model R`, and it will be possible to apply theorems about the model theory
of fields.
This is a `def` and not an `instance`, because the path
`Ring` => `Language.ring.Structure` => `Ring` cannot be made to
commute by definition
-/
def compatibleRingOfRing (R : Type*) [Add R] [Mul R] [Neg R] [One R] [Zero R] :
CompatibleRing R :=
{ funMap := fun {n} f =>
match n, f with
| _, .add => fun x => x 0 + x 1
| _, .mul => fun x => x 0 * x 1
| _, .neg => fun x => -x 0
| _, .zero => fun _ => 0
| _, .one => fun _ => 1
RelMap := Empty.elim,
funMap_add := fun _ => rfl,
funMap_mul := fun _ => rfl,
funMap_neg := fun _ => rfl,
funMap_zero := fun _ => rfl,
funMap_one := fun _ => rfl }
/-- An isomorphism in the language of rings is a ring isomorphism -/
def languageEquivEquivRingEquiv {R S : Type*}
[NonAssocRing R] [NonAssocRing S]
[CompatibleRing R] [CompatibleRing S] :
(Language.ring.Equiv R S) ≃ (R ≃+* S) :=
{ toFun := fun f =>
{ f with
map_add' := by
intro x y
simpa using f.map_fun addFunc ![x, y]
map_mul' := by
intro x y
simpa using f.map_fun mulFunc ![x, y] }
invFun := fun f =>
{ f with
map_fun' := fun {n} f => by
cases f <;> simp
map_rel' := fun {n} f => by cases f },
left_inv := fun f => by ext; rfl
right_inv := fun f => by ext; rfl }
variable (R : Type*) [Language.ring.Structure R]
/-- A def to put an `Add` instance on a type with a `Language.ring.Structure` instance.
To be used sparingly, usually only when defining a more useful definition like,
`[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/
abbrev addOfRingStructure : Add R :=
{ add := fun x y => funMap addFunc ![x, y] }
/-- A def to put an `Mul` instance on a type with a `Language.ring.Structure` instance.
To be used sparingly, usually only when defining a more useful definition like,
`[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/
abbrev mulOfRingStructure : Mul R :=
{ mul := fun x y => funMap mulFunc ![x, y] }
/-- A def to put an `Neg` instance on a type with a `Language.ring.Structure` instance.
To be used sparingly, usually only when defining a more useful definition like,
`[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/
abbrev negOfRingStructure : Neg R :=
{ neg := fun x => funMap negFunc ![x] }
/-- A def to put an `Zero` instance on a type with a `Language.ring.Structure` instance.
To be used sparingly, usually only when defining a more useful definition like,
`[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/
abbrev zeroOfRingStructure : Zero R :=
{ zero := funMap zeroFunc ![] }
/-- A def to put an `One` instance on a type with a `Language.ring.Structure` instance.
To be used sparingly, usually only when defining a more useful definition like,
`[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/
abbrev oneOfRingStructure : One R :=
{ one := funMap oneFunc ![] }
attribute [local instance] addOfRingStructure mulOfRingStructure negOfRingStructure
zeroOfRingStructure oneOfRingStructure
/--
Given a Type `R` with a `Language.ring.Structure R`, the instance given by
`addOfRingStructure` etc are compatible with the `Language.ring.Structure` instance on `R`.
This definition is only to be used when `addOfRingStructure`, `mulOfRingStructure` etc
are local instances.
-/
abbrev compatibleRingOfRingStructure : CompatibleRing R :=
{ funMap_add := by
simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi]
intros; rfl
funMap_mul := by
simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi]
intros; rfl
funMap_neg := by
simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi]
intros; rfl
funMap_zero := by
simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi]
rfl
funMap_one := by
simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi]
rfl }
end Ring
end FirstOrder
|
ModelTheory\Algebra\Ring\FreeCommRing.lean | /-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.ModelTheory.Algebra.Ring.Basic
import Mathlib.RingTheory.FreeCommRing
/-!
# Making a term in the language of rings from an element of the FreeCommRing
This file defines the function `FirstOrder.Ring.termOfFreeCommRing` which constructs a
`Language.ring.Term α` from an element of `FreeCommRing α`.
The theorem `FirstOrder.Ring.realize_termOfFreeCommRing` shows that the term constructed when
realized in a ring `R` is equal to the lift of the element of `FreeCommRing α` to `R`.
-/
namespace FirstOrder
namespace Ring
open Language
variable {α : Type*}
section
attribute [local instance] compatibleRingOfRing
private theorem exists_term_realize_eq_freeCommRing (p : FreeCommRing α) :
∃ t : Language.ring.Term α,
(t.realize FreeCommRing.of : FreeCommRing α) = p :=
FreeCommRing.induction_on p
⟨-1, by simp [Term.realize]⟩
(fun a => ⟨Term.var a, by simp [Term.realize]⟩)
(fun x y ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ =>
⟨t₁ + t₂, by simp_all [Term.realize]⟩)
(fun x y ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ =>
⟨t₁ * t₂, by simp_all [Term.realize]⟩)
end
/-- Make a `Language.ring.Term α` from an element of `FreeCommRing α` -/
noncomputable def termOfFreeCommRing (p : FreeCommRing α) : Language.ring.Term α :=
Classical.choose (exists_term_realize_eq_freeCommRing p)
variable {R : Type*} [CommRing R] [CompatibleRing R]
@[simp]
theorem realize_termOfFreeCommRing (p : FreeCommRing α) (v : α → R) :
(termOfFreeCommRing p).realize v = FreeCommRing.lift v p := by
let _ := compatibleRingOfRing (FreeCommRing α)
rw [termOfFreeCommRing]
conv_rhs => rw [← Classical.choose_spec (exists_term_realize_eq_freeCommRing p)]
induction Classical.choose (exists_term_realize_eq_freeCommRing p) with
| var _ => simp
| func f a ih =>
cases f <;>
simp [ih]
end Ring
end FirstOrder
|
NumberTheory\ADEInequality.lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Ring.Rat
import Mathlib.Data.Multiset.Sort
import Mathlib.Data.PNat.Basic
import Mathlib.Data.PNat.Interval
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.IntervalCases
/-!
# The inequality `p⁻¹ + q⁻¹ + r⁻¹ > 1`
In this file we classify solutions to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`, for positive natural numbers `p`, `q`, and `r`.
The solutions are exactly of the form.
* `A' q r := {1,q,r}`
* `D' r := {2,2,r}`
* `E6 := {2,3,3}`, or `E7 := {2,3,4}`, or `E8 := {2,3,5}`
This inequality shows up in Lie theory,
in the classification of Dynkin diagrams, root systems, and semisimple Lie algebras.
## Main declarations
* `pqr.A' q r`, the multiset `{1,q,r}`
* `pqr.D' r`, the multiset `{2,2,r}`
* `pqr.E6`, the multiset `{2,3,3}`
* `pqr.E7`, the multiset `{2,3,4}`
* `pqr.E8`, the multiset `{2,3,5}`
* `pqr.classification`, the classification of solutions to `p⁻¹ + q⁻¹ + r⁻¹ > 1`
-/
namespace ADEInequality
open Multiset
/-- `A' q r := {1,q,r}` is a `Multiset ℕ+`
that is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. -/
def A' (q r : ℕ+) : Multiset ℕ+ :=
{1, q, r}
/-- `A r := {1,1,r}` is a `Multiset ℕ+`
that is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`.
These solutions are related to the Dynkin diagrams $A_r$. -/
def A (r : ℕ+) : Multiset ℕ+ :=
A' 1 r
/-- `D' r := {2,2,r}` is a `Multiset ℕ+`
that is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`.
These solutions are related to the Dynkin diagrams $D_{r+2}$. -/
def D' (r : ℕ+) : Multiset ℕ+ :=
{2, 2, r}
/-- `E' r := {2,3,r}` is a `Multiset ℕ+`.
For `r ∈ {3,4,5}` is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`.
These solutions are related to the Dynkin diagrams $E_{r+3}$. -/
def E' (r : ℕ+) : Multiset ℕ+ :=
{2, 3, r}
/-- `E6 := {2,3,3}` is a `Multiset ℕ+`
that is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`.
This solution is related to the Dynkin diagrams $E_6$. -/
def E6 : Multiset ℕ+ :=
E' 3
/-- `E7 := {2,3,4}` is a `Multiset ℕ+`
that is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`.
This solution is related to the Dynkin diagrams $E_7$. -/
def E7 : Multiset ℕ+ :=
E' 4
/-- `E8 := {2,3,5}` is a `Multiset ℕ+`
that is a solution to the inequality
`(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`.
This solution is related to the Dynkin diagrams $E_8$. -/
def E8 : Multiset ℕ+ :=
E' 5
/-- `sum_inv pqr` for a `pqr : Multiset ℕ+` is the sum of the inverses
of the elements of `pqr`, as rational number.
The intended argument is a multiset `{p,q,r}` of cardinality `3`. -/
def sumInv (pqr : Multiset ℕ+) : ℚ :=
Multiset.sum (pqr.map fun (x : ℕ+) => x⁻¹)
theorem sumInv_pqr (p q r : ℕ+) : sumInv {p, q, r} = (p : ℚ)⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹ := by
simp only [sumInv, add_zero, insert_eq_cons, add_assoc, map_cons, sum_cons,
map_singleton, sum_singleton]
/-- A multiset `pqr` of positive natural numbers is `admissible`
if it is equal to `A' q r`, or `D' r`, or one of `E6`, `E7`, or `E8`. -/
def Admissible (pqr : Multiset ℕ+) : Prop :=
(∃ q r, A' q r = pqr) ∨ (∃ r, D' r = pqr) ∨ E' 3 = pqr ∨ E' 4 = pqr ∨ E' 5 = pqr
theorem admissible_A' (q r : ℕ+) : Admissible (A' q r) :=
Or.inl ⟨q, r, rfl⟩
theorem admissible_D' (n : ℕ+) : Admissible (D' n) :=
Or.inr <| Or.inl ⟨n, rfl⟩
theorem admissible_E'3 : Admissible (E' 3) :=
Or.inr <| Or.inr <| Or.inl rfl
theorem admissible_E'4 : Admissible (E' 4) :=
Or.inr <| Or.inr <| Or.inr <| Or.inl rfl
theorem admissible_E'5 : Admissible (E' 5) :=
Or.inr <| Or.inr <| Or.inr <| Or.inr rfl
theorem admissible_E6 : Admissible E6 :=
admissible_E'3
theorem admissible_E7 : Admissible E7 :=
admissible_E'4
theorem admissible_E8 : Admissible E8 :=
admissible_E'5
theorem Admissible.one_lt_sumInv {pqr : Multiset ℕ+} : Admissible pqr → 1 < sumInv pqr := by
rw [Admissible]
rintro (⟨p', q', H⟩ | ⟨n, H⟩ | H | H | H)
· rw [← H, A', sumInv_pqr, add_assoc]
simp only [lt_add_iff_pos_right, PNat.one_coe, inv_one, Nat.cast_one]
apply add_pos <;> simp only [PNat.pos, Nat.cast_pos, inv_pos]
· rw [← H, D', sumInv_pqr]
conv_rhs => simp only [OfNat.ofNat, PNat.mk_coe]
norm_num
all_goals
rw [← H, E', sumInv_pqr]
conv_rhs => simp only [OfNat.ofNat, PNat.mk_coe]
rfl
theorem lt_three {p q r : ℕ+} (hpq : p ≤ q) (hqr : q ≤ r) (H : 1 < sumInv {p, q, r}) : p < 3 := by
have h3 : (0 : ℚ) < 3 := by norm_num
contrapose! H
rw [sumInv_pqr]
have h3q := H.trans hpq
have h3r := h3q.trans hqr
have hp : (p : ℚ)⁻¹ ≤ 3⁻¹ := by
rw [inv_le_inv _ h3]
· assumption_mod_cast
· norm_num
have hq : (q : ℚ)⁻¹ ≤ 3⁻¹ := by
rw [inv_le_inv _ h3]
· assumption_mod_cast
· norm_num
have hr : (r : ℚ)⁻¹ ≤ 3⁻¹ := by
rw [inv_le_inv _ h3]
· assumption_mod_cast
· norm_num
calc
(p : ℚ)⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹ ≤ 3⁻¹ + 3⁻¹ + 3⁻¹ := add_le_add (add_le_add hp hq) hr
_ = 1 := by norm_num
theorem lt_four {q r : ℕ+} (hqr : q ≤ r) (H : 1 < sumInv {2, q, r}) : q < 4 := by
have h4 : (0 : ℚ) < 4 := by norm_num
contrapose! H
rw [sumInv_pqr]
have h4r := H.trans hqr
have hq : (q : ℚ)⁻¹ ≤ 4⁻¹ := by
rw [inv_le_inv _ h4]
· assumption_mod_cast
· norm_num
have hr : (r : ℚ)⁻¹ ≤ 4⁻¹ := by
rw [inv_le_inv _ h4]
· assumption_mod_cast
· norm_num
calc
(2⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹) ≤ 2⁻¹ + 4⁻¹ + 4⁻¹ := add_le_add (add_le_add le_rfl hq) hr
_ = 1 := by norm_num
theorem lt_six {r : ℕ+} (H : 1 < sumInv {2, 3, r}) : r < 6 := by
have h6 : (0 : ℚ) < 6 := by norm_num
contrapose! H
rw [sumInv_pqr]
have hr : (r : ℚ)⁻¹ ≤ 6⁻¹ := by
rw [inv_le_inv _ h6]
· assumption_mod_cast
· norm_num
calc
(2⁻¹ + 3⁻¹ + (r : ℚ)⁻¹ : ℚ) ≤ 2⁻¹ + 3⁻¹ + 6⁻¹ := add_le_add (add_le_add le_rfl le_rfl) hr
_ = 1 := by norm_num
theorem admissible_of_one_lt_sumInv_aux' {p q r : ℕ+} (hpq : p ≤ q) (hqr : q ≤ r)
(H : 1 < sumInv {p, q, r}) : Admissible {p, q, r} := by
have hp3 : p < 3 := lt_three hpq hqr H
-- Porting note: `interval_cases` doesn't support `ℕ+` yet.
replace hp3 := Finset.mem_Iio.mpr hp3
conv at hp3 => change p ∈ ({1, 2} : Multiset ℕ+)
fin_cases hp3
· exact admissible_A' q r
have hq4 : q < 4 := lt_four hqr H
replace hq4 := Finset.mem_Ico.mpr ⟨hpq, hq4⟩; clear hpq
conv at hq4 => change q ∈ ({2, 3} : Multiset ℕ+)
fin_cases hq4
· exact admissible_D' r
have hr6 : r < 6 := lt_six H
replace hr6 := Finset.mem_Ico.mpr ⟨hqr, hr6⟩; clear hqr
conv at hr6 => change r ∈ ({3, 4, 5} : Multiset ℕ+)
fin_cases hr6
· exact admissible_E6
· exact admissible_E7
· exact admissible_E8
theorem admissible_of_one_lt_sumInv_aux :
∀ {pqr : List ℕ+} (_ : pqr.Sorted (· ≤ ·)) (_ : pqr.length = 3) (_ : 1 < sumInv pqr),
Admissible pqr
| [p, q, r], hs, _, H => by
obtain ⟨⟨hpq, -⟩, hqr⟩ : (p ≤ q ∧ p ≤ r) ∧ q ≤ r := by simpa using hs
exact admissible_of_one_lt_sumInv_aux' hpq hqr H
theorem admissible_of_one_lt_sumInv {p q r : ℕ+} (H : 1 < sumInv {p, q, r}) :
Admissible {p, q, r} := by
simp only [Admissible]
let S := sort ((· ≤ ·) : ℕ+ → ℕ+ → Prop) {p, q, r}
have hS : S.Sorted (· ≤ ·) := sort_sorted _ _
have hpqr : ({p, q, r} : Multiset ℕ+) = S := (sort_eq LE.le {p, q, r}).symm
rw [hpqr]
rw [hpqr] at H
apply admissible_of_one_lt_sumInv_aux hS _ H
simp only [S, insert_eq_cons, length_sort, card_cons, card_singleton]
/-- A multiset `{p,q,r}` of positive natural numbers
is a solution to `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1` if and only if
it is `admissible` which means it is one of:
* `A' q r := {1,q,r}`
* `D' r := {2,2,r}`
* `E6 := {2,3,3}`, or `E7 := {2,3,4}`, or `E8 := {2,3,5}`
-/
theorem classification (p q r : ℕ+) : 1 < sumInv {p, q, r} ↔ Admissible {p, q, r} :=
⟨admissible_of_one_lt_sumInv, Admissible.one_lt_sumInv⟩
end ADEInequality
|
NumberTheory\ArithmeticFunction.lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.Module.BigOperators
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Squarefree
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Tactic.ArithMult
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `IsMultiplicative` when `x.coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function (spelled `moebius` in code).
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero`
* And variants that apply when the equalities only hold on a set `S : Set ℕ` such that
`m ∣ n → n ∈ S → m ∈ S`:
* `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero`
## Notation
All notation is localized in the namespace `ArithmeticFunction`.
The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names.
In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`,
`ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`,
`ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`,
to allow for selective access to these notations.
The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation
`∏ᵖ p ∣ n, f p` when applied to `n`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open Finset
open Nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by
Dirichlet convolution. -/
def ArithmeticFunction [Zero R] :=
ZeroHom ℕ R
instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) :=
inferInstanceAs (Zero (ZeroHom ℕ R))
instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R))
variable {R}
namespace ArithmeticFunction
section Zero
variable [Zero R]
-- porting note: used to be `CoeFun`
instance : FunLike (ArithmeticFunction R) ℕ R :=
inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R)
@[simp]
theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl
@[simp]
theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _
(ZeroHom.mk f hf) = f := rfl
@[simp]
theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 :=
ZeroHom.map_zero' f
theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[simp]
theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 :=
ZeroHom.zero_apply x
@[ext]
theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g :=
ZeroHom.ext h
section One
variable [One R]
instance one : One (ArithmeticFunction R) :=
⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩
theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 :=
rfl
@[simp]
theorem one_one : (1 : ArithmeticFunction R) 1 = 1 :=
rfl
@[simp]
theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 :=
if_neg h
end One
end Zero
/-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline
this in `natCoe` because it gets unfolded too much. -/
@[coe] -- Porting note: added `coe` tag.
def natToArithmeticFunction [AddMonoidWithOne R] :
(ArithmeticFunction ℕ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) :=
⟨natToArithmeticFunction⟩
@[simp]
theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f :=
ext fun _ => cast_id _
@[simp]
theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x :=
rfl
/-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline
this in `intCoe` because it gets unfolded too much. -/
@[coe]
def ofInt [AddGroupWithOne R] :
(ArithmeticFunction ℤ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) :=
⟨ofInt⟩
@[simp]
theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f :=
ext fun _ => Int.cast_id
@[simp]
theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x := rfl
@[simp]
theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} :
((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by
ext
simp
@[simp]
theorem natCoe_one [AddMonoidWithOne R] :
((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
@[simp]
theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) :
ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
section AddMonoid
variable [AddMonoid R]
instance add : Add (ArithmeticFunction R) :=
⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩
@[simp]
theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n :=
rfl
instance instAddMonoid : AddMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.zero R,
ArithmeticFunction.add with
add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _
zero_add := fun _ => ext fun _ => zero_add _
add_zero := fun _ => ext fun _ => add_zero _
nsmul := nsmulRec }
end AddMonoid
instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid,
ArithmeticFunction.one with
natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩
natCast_zero := by ext; simp
natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] }
instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ }
instance [NegZeroClass R] : Neg (ArithmeticFunction R) where
neg f := ⟨fun n => -f n, by simp⟩
instance [AddGroup R] : AddGroup (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with
add_left_neg := fun _ => ext fun _ => add_left_neg _
zsmul := zsmulRec }
instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) :=
{ show AddGroup (ArithmeticFunction R) by infer_instance with
add_comm := fun _ _ ↦ add_comm _ _ }
section SMul
variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) :=
⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} :
(f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd :=
rfl
end SMul
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [Semiring R] : Mul (ArithmeticFunction R) :=
⟨(· • ·)⟩
@[simp]
theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} :
(f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd :=
rfl
theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp
@[simp, norm_cast]
theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} :
(↑(f * g) : ArithmeticFunction R) = f * g := by
ext n
simp
@[simp, norm_cast]
theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} :
(↑(f * g) : ArithmeticFunction R) = ↑f * g := by
ext n
simp
section Module
variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :
(f * g) • h = f • g • h := by
ext n
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc)
theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y1ne : y.fst ≠ 1 := by
intro con
simp only [Con, mem_divisorsAntidiagonal, one_mul, Ne] at ymem
simp only [mem_singleton, Prod.ext_iff] at ynmem
-- Porting note: `tauto` worked from here.
cases y
subst con
simp only [true_and, one_mul, x0, not_false_eq_true, and_true] at ynmem ymem
tauto
simp [y1ne]
end Module
section Semiring
variable [Semiring R]
instance instMonoid : Monoid (ArithmeticFunction R) :=
{ one := One.one
mul := Mul.mul
one_mul := one_smul'
mul_one := fun f => by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y2ne : y.snd ≠ 1 := by
intro con
cases y; subst con -- Porting note: added
simp only [Con, mem_divisorsAntidiagonal, mul_one, Ne] at ymem
simp only [mem_singleton, Prod.ext_iff] at ynmem
tauto
simp [y2ne]
mul_assoc := mul_smul' }
instance instSemiring : Semiring (ArithmeticFunction R) :=
-- Porting note: I reorganized this instance
{ ArithmeticFunction.instAddMonoidWithOne,
ArithmeticFunction.instMonoid,
ArithmeticFunction.instAddCommMonoid with
zero_mul := fun f => by
ext
simp only [mul_apply, zero_mul, sum_const_zero, zero_apply]
mul_zero := fun f => by
ext
simp only [mul_apply, sum_const_zero, mul_zero, zero_apply]
left_distrib := fun a b c => by
ext
simp only [← sum_add_distrib, mul_add, mul_apply, add_apply]
right_distrib := fun a b c => by
ext
simp only [← sum_add_distrib, add_mul, mul_apply, add_apply] }
end Semiring
instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
mul_comm := fun f g => by
ext
rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map]
simp [mul_comm] }
instance [CommRing R] : CommRing (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
add_left_neg := add_left_neg
mul_comm := mul_comm
zsmul := (· • ·) }
instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] :
Module (ArithmeticFunction R) (ArithmeticFunction M) where
one_smul := one_smul'
mul_smul := mul_smul'
smul_add r x y := by
ext
simp only [sum_add_distrib, smul_add, smul_apply, add_apply]
smul_zero r := by
ext
simp only [smul_apply, sum_const_zero, smul_zero, zero_apply]
add_smul r s x := by
ext
simp only [add_smul, sum_add_distrib, smul_apply, add_apply]
zero_smul r := by
ext
simp only [smul_apply, sum_const_zero, zero_smul, zero_apply]
section Zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/
def zeta : ArithmeticFunction ℕ :=
⟨fun x => ite (x = 0) 0 1, rfl⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta
@[simp]
theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 :=
rfl
theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 :=
if_neg h
-- Porting note: removed `@[simp]`, LHS not in normal form
theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [Module R M]
{f : ArithmeticFunction M} {x : ℕ} :
((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by
rw [smul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.snd
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul]
· rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk]
-- Porting note: removed `@[simp]` to make the linter happy.
theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(↑ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply
-- Porting note: removed `@[simp]` to make the linter happy.
theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_mul_apply
-- Porting note: was `by rw [← nat_coe_nat ζ, coe_zeta_mul_apply]`. Is this `theorem` obsolete?
theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i :=
coe_mul_zeta_apply
-- Porting note: was `by rw [← natCoe_nat ζ, coe_mul_zeta_apply]`. Is this `theorem` obsolete=
end Zeta
open ArithmeticFunction
section Pmul
/-- This is the pointwise product of `ArithmeticFunction`s. -/
def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun x => f x * g x, by simp⟩
@[simp]
theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x :=
rfl
theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by
ext
simp [mul_comm]
lemma pmul_assoc [CommMonoidWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) :
pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by
ext
simp only [pmul_apply, mul_assoc]
section NonAssocSemiring
variable [NonAssocSemiring R]
@[simp]
theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
@[simp]
theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
end NonAssocSemiring
variable [Semiring R]
/-- This is the pointwise power of `ArithmeticFunction`s. -/
def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R :=
if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩
@[simp]
theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl]
@[simp]
theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by
rw [ppow, dif_neg (Nat.ne_of_gt kpos)]
rfl
theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ']
induction k <;> simp
theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ]
induction k <;> simp
end Pmul
section Pdiv
/-- This is the pointwise division of `ArithmeticFunction`s. -/
def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩
@[simp]
theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) :
pdiv f g n = f n / g n := rfl
/-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes
values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/
@[simp]
theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) :
pdiv f zeta = f := by
ext n
cases n <;> simp [succ_ne_zero]
end Pdiv
section ProdPrimeFactors
/-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/
def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where
toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p
map_zero' := if_pos rfl
open Batteries.ExtendedBinder
/-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/
scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term
scoped macro_rules (kind := bigproddvd)
| `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n)
@[simp]
theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) :
∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p :=
if_neg hn
end ProdPrimeFactors
/-- Multiplicative functions -/
def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop :=
f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n
namespace IsMultiplicative
section MonoidWithZero
variable [MonoidWithZero R]
@[simp, arith_mult]
theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 :=
h.1
@[simp]
theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ}
(h : m.Coprime n) : f (m * n) = f m * f n :=
hf.2 h
end MonoidWithZero
theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) :
f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by
classical
induction' s using Finset.induction_on with a s has ih hs
· simp [hf]
rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs
rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1]
exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm
theorem map_prod_of_prime [CommSemiring R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f)
(t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy
theorem map_prod_of_subset_primeFactors [CommSemiring R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ)
(t : Finset ℕ) (ht : t ⊆ l.primeFactors) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a)
@[arith_mult]
theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
-- Porting note: was `by simp [cop, h]`
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[deprecated (since := "2024-04-17")]
alias nat_cast := natCast
@[arith_mult]
theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
-- Porting note: was `by simp [cop, h]`
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[deprecated (since := "2024-04-17")]
alias int_cast := intCast
@[arith_mult]
theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by
refine ⟨by simp [hf.1, hg.1], ?_⟩
simp only [mul_apply]
intro m n cop
rw [sum_mul_sum, ← sum_product']
symm
apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l)
· rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h
simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne]
constructor
· ring
rw [Nat.mul_eq_zero] at *
apply not_or_of_not ha hb
· simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk.inj_iff]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h
simp only [Prod.mk.inj_iff] at h
ext <;> dsimp only
· trans Nat.gcd (a1 * a2) (a1 * b1)
· rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.1, Nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· trans Nat.gcd (a1 * a2) (a2 * b2)
· rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a1 * b1)
· rw [mul_comm, Nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a2 * b2)
· rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one,
one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.2, Nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul]
· simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product,
Set.mem_image, exists_prop, Prod.mk.inj_iff]
rintro ⟨b1, b2⟩ h
dsimp at h
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n))
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _]
· rw [Nat.mul_eq_zero, not_or] at h
simp [h.2.1, h.2.2]
rw [mul_comm n m, h.1]
· simp only [mem_divisorsAntidiagonal, Ne, mem_product]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
dsimp only
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right]
ring
@[arith_mult]
theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop]
ring⟩
@[arith_mult]
theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f)
(hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) :=
⟨ by simp [hf, hg], fun {m n} cop => by
simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop,
div_eq_mul_inv, mul_inv]
apply mul_mul_mul_comm ⟩
/-- For any multiplicative function `f` and any `n > 0`,
we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/
nonrec -- Porting note: added
theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) :
f n = n.factorization.prod fun p k => f (p ^ k) :=
multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn
/-- A recapitulation of the definition of multiplicative that is simpler for proofs -/
theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} :
IsMultiplicative f ↔
f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by
refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩)
rcases eq_or_ne m 0 with (rfl | hm)
· simp
rcases eq_or_ne n 0 with (rfl | hn)
· simp
exact h hm hn hmn
/-- Two multiplicative functions `f` and `g` are equal if and only if
they agree on prime powers -/
theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) :
f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by
constructor
· intro h p i _
rw [h]
intro h
ext n
by_cases hn : n = 0
· rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero]
rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn]
exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp)
@[arith_mult]
theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) :
IsMultiplicative (prodPrimeFactors f) := by
rw [iff_ne_zero]
simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one,
prod_empty, true_and]
intro x y hx hy hxy
have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy
rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy,
Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors]
theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R}
(hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) :
∏ᵖ p ∣ n, (f + g) p = (f * g) n := by
rw [prodPrimeFactors_apply hn.ne_zero]
simp_rw [add_apply (f := f) (g := g)]
rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·),
← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero,
factors_eq]
apply Finset.sum_congr rfl
intro t ht
rw [t.prod_val, Function.id_def,
← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht),
hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht),
← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset]
theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} :
f (x.lcm y) * f (x.gcd y) = f x * f y := by
by_cases hx : x = 0
· simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left]
by_cases hy : y = 0
· simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul]
have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx
have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy
have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by
intro i; rw [Nat.pow_zero, hf.1]
iterate 4 rw [hf.multiplicative_factorization f (by assumption),
Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero)
(s := (x.primeFactors ⊔ y.primeFactors))]
· rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro p _
rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;>
simp only [factorization_lcm hx hy, Finsupp.sup_apply, h, sup_of_le_right,
sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply,
inf_of_le_left, mul_comm]
· apply Finset.subset_union_right
· apply Finset.subset_union_left
· rw [factorization_gcd hx hy, Finsupp.support_inf, Finset.sup_eq_union]
apply Finset.inter_subset_union
· simp [factorization_lcm hx hy]
end IsMultiplicative
section SpecialFunctions
/-- The identity on `ℕ` as an `ArithmeticFunction`. -/
nonrec -- Porting note (#11445): added
def id : ArithmeticFunction ℕ :=
⟨id, rfl⟩
@[simp]
theorem id_apply {x : ℕ} : id x = x :=
rfl
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : ArithmeticFunction ℕ :=
id.ppow k
@[simp]
theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by
cases k
· simp [pow]
rename_i k -- Porting note: added
simp [pow, k.succ_pos.ne']
theorem pow_zero_eq_zeta : pow 0 = ζ := by
ext n
simp
/-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/
def sigma (k : ℕ) : ArithmeticFunction ℕ :=
⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma
@[inherit_doc]
scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma
theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k :=
rfl
theorem sigma_apply_prime_pow {k p i : ℕ} (hp : p.Prime) :
σ k (p ^ i) = ∑ j in .range (i + 1), p ^ (j * k) := by
simp [sigma_apply, divisors_prime_pow hp, Nat.pow_mul]
theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply]
theorem sigma_one_apply_prime_pow {p i : ℕ} (hp : p.Prime) :
σ 1 (p ^ i) = ∑ k in .range (i + 1), p ^ k := by
simp [sigma_apply_prime_pow hp]
theorem sigma_zero_apply (n : ℕ) : σ 0 n = (divisors n).card := by simp [sigma_apply]
theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by
simp [sigma_apply_prime_pow hp]
theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by
ext
rw [sigma, zeta_mul_apply]
apply sum_congr rfl
intro x hx
rw [pow_apply, if_neg (not_and_of_not_right _ _)]
contrapose! hx
simp [hx]
@[arith_mult]
theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) :=
IsMultiplicative.iff_ne_zero.2
⟨by simp, by
intro m n hm _hn hmn
rcases eq_or_ne m 1 with (rfl | hm')
· simp
rw [one_apply_ne, one_apply_ne hm', zero_mul]
rw [Ne, mul_eq_one, not_and_or]
exact Or.inl hm'⟩
@[arith_mult]
theorem isMultiplicative_zeta : IsMultiplicative ζ :=
IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp (config := { contextual := true })⟩
@[arith_mult]
theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id :=
⟨rfl, fun {_ _} _ => rfl⟩
@[arith_mult]
theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative)
{k : ℕ} : IsMultiplicative (f.ppow k) := by
induction' k with k hi
· exact isMultiplicative_zeta.natCast
· rw [ppow_succ']
apply hf.pmul hi
@[arith_mult]
theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) :=
isMultiplicative_id.ppow
@[arith_mult]
theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by
rw [← zeta_mul_pow_eq_sigma]
apply isMultiplicative_zeta.mul isMultiplicative_pow
/-- `Ω n` is the number of prime factors of `n`. -/
def cardFactors : ArithmeticFunction ℕ :=
⟨fun n => n.primeFactorsList.length, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors
@[inherit_doc]
scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors
theorem cardFactors_apply {n : ℕ} : Ω n = n.primeFactorsList.length :=
rfl
lemma cardFactors_zero : Ω 0 = 0 := by simp
@[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply]
@[simp]
theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by
refine ⟨fun h => ?_, fun h => List.length_eq_one.2 ⟨n, primeFactorsList_prime h⟩⟩
cases' n with n
· simp at h
rcases List.length_eq_one.1 h with ⟨x, hx⟩
rw [← prod_primeFactorsList n.add_one_ne_zero, hx, List.prod_singleton]
apply prime_of_mem_primeFactorsList
rw [hx, List.mem_singleton]
theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by
rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq,
UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq,
Multiset.card_add, Multiset.coe_card, Multiset.coe_card]
theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) :
Ω s.prod = (Multiset.map Ω s).sum := by
induction s using Multiset.induction_on with
| empty => simp
| cons ih => simp_all [cardFactors_mul, not_or]
@[simp]
theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 :=
cardFactors_eq_one_iff_prime.2 hp
@[simp]
theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by
rw [cardFactors_apply, hp.primeFactorsList_pow, List.length_replicate]
/-- `ω n` is the number of distinct prime factors of `n`. -/
def cardDistinctFactors : ArithmeticFunction ℕ :=
⟨fun n => n.primeFactorsList.dedup.length, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors
@[inherit_doc]
scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors
theorem cardDistinctFactors_zero : ω 0 = 0 := by simp
@[simp]
theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors]
theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.primeFactorsList.dedup.length :=
rfl
theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) :
ω n = Ω n ↔ Squarefree n := by
rw [squarefree_iff_nodup_primeFactorsList h0, cardDistinctFactors_apply]
constructor <;> intro h
· rw [← n.primeFactorsList.dedup_sublist.eq_of_length h]
apply List.nodup_dedup
· rw [h.dedup]
rfl
@[simp]
theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
ω (p ^ k) = 1 := by
rw [cardDistinctFactors_apply, hp.primeFactorsList_pow, List.replicate_dedup hk,
List.length_singleton]
@[simp]
theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by
rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero]
/-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors,
`μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`.
If `n` is not squarefree, `μ n = 0`. -/
def moebius : ArithmeticFunction ℤ :=
⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius
@[inherit_doc]
scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius
@[simp]
theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n :=
if_pos h
@[simp]
theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 :=
if_neg h
theorem moebius_apply_one : μ 1 = 1 := by simp
theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by
constructor <;> intro h
· contrapose! h
simp [h]
· simp [h, pow_ne_zero]
theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by
simp only [moebius, coe_mk]
split_ifs
· right
exact neg_one_pow_eq_or ..
· left
rfl
theorem moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 := by
have := moebius_eq_or n
aesop
theorem moebius_sq_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : μ l ^ 2 = 1 := by
rw [moebius_apply_of_squarefree hl, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]
theorem abs_moebius_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : |μ l| = 1 := by
simp only [moebius_apply_of_squarefree hl, abs_pow, abs_neg, abs_one, one_pow]
theorem moebius_sq {n : ℕ} :
μ n ^ 2 = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact moebius_sq_eq_one_of_squarefree h
· simp only [pow_eq_zero_iff, moebius_eq_zero_of_not_squarefree h,
zero_pow (show 2 ≠ 0 by norm_num)]
theorem abs_moebius {n : ℕ} :
|μ n| = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact abs_moebius_eq_one_of_squarefree h
· simp only [moebius_eq_zero_of_not_squarefree h, abs_zero]
theorem abs_moebius_le_one {n : ℕ} : |μ n| ≤ 1 := by
rw [abs_moebius, apply_ite (· ≤ 1)]
simp
theorem moebius_apply_prime {p : ℕ} (hp : p.Prime) : μ p = -1 := by
rw [moebius_apply_of_squarefree hp.squarefree, cardFactors_apply_prime hp, pow_one]
theorem moebius_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
μ (p ^ k) = if k = 1 then -1 else 0 := by
split_ifs with h
· rw [h, pow_one, moebius_apply_prime hp]
rw [moebius_eq_zero_of_not_squarefree]
rw [squarefree_pow_iff hp.ne_one hk, not_and_or]
exact Or.inr h
theorem moebius_apply_isPrimePow_not_prime {n : ℕ} (hn : IsPrimePow n) (hn' : ¬n.Prime) :
μ n = 0 := by
obtain ⟨p, k, hp, hk, rfl⟩ := (isPrimePow_nat_iff _).1 hn
rw [moebius_apply_prime_pow hp hk.ne', if_neg]
rintro rfl
exact hn' (by simpa)
@[arith_mult]
theorem isMultiplicative_moebius : IsMultiplicative μ := by
rw [IsMultiplicative.iff_ne_zero]
refine ⟨by simp, fun {n m} hn hm hnm => ?_⟩
simp only [moebius, ZeroHom.coe_mk, coe_mk, ZeroHom.toFun_eq_coe, Eq.ndrec, ZeroHom.coe_mk,
IsUnit.mul_iff, Nat.isUnit_iff, squarefree_mul hnm, ite_zero_mul_ite_zero,
cardFactors_mul hn hm, pow_add]
theorem IsMultiplicative.prodPrimeFactors_one_add_of_squarefree [CommSemiring R]
{f : ArithmeticFunction R} (h_mult : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 + f p) = ∑ d ∈ n.divisors, f d := by
trans (∏ᵖ p ∣ n, ((ζ : ArithmeticFunction R) + f) p)
· simp_rw [prodPrimeFactors_apply hn.ne_zero, add_apply, natCoe_apply]
apply Finset.prod_congr rfl; intro p hp
rw [zeta_apply_ne (prime_of_mem_primeFactorsList <| List.mem_toFinset.mp hp).ne_zero, cast_one]
rw [isMultiplicative_zeta.natCast.prodPrimeFactors_add_of_squarefree h_mult hn,
coe_zeta_mul_apply]
theorem IsMultiplicative.prodPrimeFactors_one_sub_of_squarefree [CommRing R]
(f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 - f p) = ∑ d ∈ n.divisors, μ d * f d := by
trans (∏ p ∈ n.primeFactors, (1 + (ArithmeticFunction.pmul (μ : ArithmeticFunction R) f) p))
· apply Finset.prod_congr rfl; intro p hp
rw [pmul_apply, intCoe_apply, ArithmeticFunction.moebius_apply_prime
(prime_of_mem_primeFactorsList (List.mem_toFinset.mp hp))]
ring
· rw [(isMultiplicative_moebius.intCast.pmul hf).prodPrimeFactors_one_add_of_squarefree hn]
simp_rw [pmul_apply, intCoe_apply]
open UniqueFactorizationMonoid
@[simp]
theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
ext n
refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n
· intro p n hp hn
rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ']
simp_rw [Nat.pow_zero, moebius_apply_one,
moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj', sum_ite_eq', mem_range,
if_pos hn, add_left_neg]
rw [one_apply_ne]
rw [Ne, pow_eq_one_iff]
· exact hp.ne_one
· exact hn.ne'
· rw [ZeroHom.map_zero, ZeroHom.map_zero]
· simp
· intro a b _ha _hb hab ha' hb'
rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb',
IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab]
exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast
@[simp]
theorem coe_zeta_mul_moebius : (ζ * μ : ArithmeticFunction ℤ) = 1 := by
rw [mul_comm, moebius_mul_coe_zeta]
@[simp]
theorem coe_moebius_mul_coe_zeta [Ring R] : (μ * ζ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, moebius_mul_coe_zeta, intCoe_one]
@[simp]
theorem coe_zeta_mul_coe_moebius [Ring R] : (ζ * μ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, coe_zeta_mul_moebius, intCoe_one]
section CommRing
variable [CommRing R]
instance : Invertible (ζ : ArithmeticFunction R) where
invOf := μ
invOf_mul_self := coe_moebius_mul_coe_zeta
mul_invOf_self := coe_zeta_mul_coe_moebius
/-- A unit in `ArithmeticFunction R` that evaluates to `ζ`, with inverse `μ`. -/
def zetaUnit : (ArithmeticFunction R)ˣ :=
⟨ζ, μ, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta⟩
@[simp]
theorem coe_zetaUnit : ((zetaUnit : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = ζ :=
rfl
@[simp]
theorem inv_zetaUnit : ((zetaUnit⁻¹ : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = μ :=
rfl
end CommRing
/-- Möbius inversion for functions to an `AddCommGroup`. -/
theorem sum_eq_iff_sum_smul_moebius_eq [AddCommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd = f n := by
let f' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else f x, if_pos rfl⟩
let g' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else g x, if_pos rfl⟩
trans (ζ : ArithmeticFunction ℤ) • f' = g'
· rw [ArithmeticFunction.ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
rw [coe_zeta_smul_apply]
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, ZeroHom.coe_mk]
simp only [f', g', coe_mk, succ_ne_zero, ite_false]
rw [sum_congr rfl fun x hx => ?_]
rw [if_neg (Nat.pos_of_mem_divisors hx).ne']
trans μ • g' = f'
· constructor <;> intro h
· rw [← h, ← mul_smul, moebius_mul_coe_zeta, one_smul]
· rw [← h, ← mul_smul, coe_zeta_mul_moebius, one_smul]
· rw [ArithmeticFunction.ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', smul_apply, if_false,
ZeroHom.coe_mk]
-- Porting note: added following `simp only`
simp only [f', g', Nat.isUnit_iff, coe_mk, ZeroHom.toFun_eq_coe, succ_ne_zero, ite_false]
rw [sum_congr rfl fun x hx => ?_]
rw [if_neg (Nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)).ne']
/-- Möbius inversion for functions to a `Ring`. -/
theorem sum_eq_iff_sum_mul_moebius_eq [Ring R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd = f n := by
rw [sum_eq_iff_sum_smul_moebius_eq]
apply forall_congr'
refine fun a => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
/-- Möbius inversion for functions to a `CommGroup`. -/
theorem prod_eq_iff_prod_pow_moebius_eq [CommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n :=
@sum_eq_iff_sum_smul_moebius_eq (Additive R) _ _ _
/-- Möbius inversion for functions to a `CommGroupWithZero`. -/
theorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [CommGroupWithZero R] {f g : ℕ → R}
(hf : ∀ n : ℕ, 0 < n → f n ≠ 0) (hg : ∀ n : ℕ, 0 < n → g n ≠ 0) :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n := by
refine
Iff.trans
(Iff.trans (forall_congr' fun n => ?_)
(@prod_eq_iff_prod_pow_moebius_eq Rˣ _
(fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1) fun n =>
if h : 0 < n then Units.mk0 (g n) (hg n h) else 1))
(forall_congr' fun n => ?_) <;>
refine imp_congr_right fun hn => ?_
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0]
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)),
Units.coeHom_apply, Units.val_zpow_eq_zpow_val, Units.val_mk0]
/-- Möbius inversion for functions to an `AddCommGroup`, where the equalities only hold on a
well-behaved set. -/
theorem sum_eq_iff_sum_smul_moebius_eq_on [AddCommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd) = f n := by
constructor
· intro h
let G := fun (n : ℕ) => (∑ i ∈ n.divisors, f i)
intro n hn hnP
suffices ∑ d ∈ n.divisors, μ (n/d) • G d = f n from by
rw [Nat.sum_divisorsAntidiagonal' (f := fun x y => μ x • g y), ← this, sum_congr rfl]
intro d hd
rw [← h d (Nat.pos_of_mem_divisors hd) <| hs d n (Nat.dvd_of_mem_divisors hd) hnP]
rw [← Nat.sum_divisorsAntidiagonal' (f := fun x y => μ x • G y)]
apply sum_eq_iff_sum_smul_moebius_eq.mp _ n hn
intro _ _; rfl
· intro h
let F := fun (n : ℕ) => ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd
intro n hn hnP
suffices ∑ d ∈ n.divisors, F d = g n from by
rw [← this, sum_congr rfl]
intro d hd
rw [← h d (Nat.pos_of_mem_divisors hd) <| hs d n (Nat.dvd_of_mem_divisors hd) hnP]
apply sum_eq_iff_sum_smul_moebius_eq.mpr _ n hn
intro _ _; rfl
theorem sum_eq_iff_sum_smul_moebius_eq_on' [AddCommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) (hs₀ : 0 ∉ s) :
(∀ n ∈ s, (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n ∈ s, (∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd) = f n := by
have : ∀ P : ℕ → Prop, ((∀ n ∈ s, P n) ↔ (∀ n > 0, n ∈ s → P n)) := fun P ↦ by
refine forall_congr' (fun n ↦ ⟨fun h _ ↦ h, fun h hn ↦ h ?_ hn⟩)
contrapose! hs₀
simpa [nonpos_iff_eq_zero.mp hs₀] using hn
simpa only [this] using sum_eq_iff_sum_smul_moebius_eq_on s hs
/-- Möbius inversion for functions to a `Ring`, where the equalities only hold on a well-behaved
set. -/
theorem sum_eq_iff_sum_mul_moebius_eq_on [Ring R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s →
(∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd) = f n := by
rw [sum_eq_iff_sum_smul_moebius_eq_on s hs]
apply forall_congr'
intro a; refine imp_congr_right ?_
refine fun _ => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
/-- Möbius inversion for functions to a `CommGroup`, where the equalities only hold on a
well-behaved set. -/
theorem prod_eq_iff_prod_pow_moebius_eq_on [CommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∏ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst) = f n :=
@sum_eq_iff_sum_smul_moebius_eq_on (Additive R) _ _ _ s hs
/-- Möbius inversion for functions to a `CommGroupWithZero`, where the equalities only hold on
a well-behaved set. -/
theorem prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero [CommGroupWithZero R]
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) {f g : ℕ → R}
(hf : ∀ n > 0, f n ≠ 0) (hg : ∀ n > 0, g n ≠ 0) :
(∀ n > 0, n ∈ s → (∏ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst) = f n := by
refine
Iff.trans
(Iff.trans (forall_congr' fun n => ?_)
(@prod_eq_iff_prod_pow_moebius_eq_on Rˣ _
(fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1)
(fun n => if h : 0 < n then Units.mk0 (g n) (hg n h) else 1)
s hs) )
(forall_congr' fun n => ?_) <;>
refine imp_congr_right fun hn => ?_
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0]
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)),
Units.coeHom_apply, Units.val_zpow_eq_zpow_val, Units.val_mk0]
end SpecialFunctions
theorem _root_.Nat.card_divisors {n : ℕ} (hn : n ≠ 0) :
n.divisors.card = n.primeFactors.prod (n.factorization · + 1) := by
rw [← sigma_zero_apply, isMultiplicative_sigma.multiplicative_factorization _ hn]
exact Finset.prod_congr n.support_factorization fun _ h =>
sigma_zero_apply_prime_pow <| Nat.prime_of_mem_primeFactors h
@[deprecated (since := "2024-06-09")] theorem card_divisors (n : ℕ) (hn : n ≠ 0) :
n.divisors.card = n.primeFactors.prod (n.factorization · + 1) := Nat.card_divisors hn
theorem _root_.Nat.sum_divisors {n : ℕ} (hn : n ≠ 0) :
∑ d ∈ n.divisors, d = ∏ p ∈ n.primeFactors, ∑ k ∈ .range (n.factorization p + 1), p ^ k := by
rw [← sigma_one_apply, isMultiplicative_sigma.multiplicative_factorization _ hn]
exact Finset.prod_congr n.support_factorization fun _ h =>
sigma_one_apply_prime_pow <| Nat.prime_of_mem_primeFactors h
end ArithmeticFunction
namespace Nat.Coprime
open ArithmeticFunction
theorem card_divisors_mul {m n : ℕ} (hmn : m.Coprime n) :
(m * n).divisors.card = m.divisors.card * n.divisors.card := by
simp only [← sigma_zero_apply, isMultiplicative_sigma.map_mul_of_coprime hmn]
theorem sum_divisors_mul {m n : ℕ} (hmn : m.Coprime n) :
∑ d ∈ (m * n).divisors, d = (∑ d ∈ m.divisors, d) * ∑ d ∈ n.divisors, d := by
simp only [← sigma_one_apply, isMultiplicative_sigma.map_mul_of_coprime hmn]
end Nat.Coprime
|
NumberTheory\Basic.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.GeomSum
import Mathlib.RingTheory.Ideal.Quotient
/-!
# Basic results in number theory
This file should contain basic results in number theory. So far, it only contains the essential
lemma in the construction of the ring of Witt vectors.
## Main statement
`dvd_sub_pow_of_dvd_sub` proves that for elements `a` and `b` in a commutative ring `R` and for
all natural numbers `p` and `k` if `p` divides `a-b` in `R`, then `p ^ (k + 1)` divides
`a ^ (p ^ k) - b ^ (p ^ k)`.
-/
section
open Ideal Ideal.Quotient
theorem dvd_sub_pow_of_dvd_sub {R : Type*} [CommRing R] {p : ℕ} {a b : R} (h : (p : R) ∣ a - b)
(k : ℕ) : (p ^ (k + 1) : R) ∣ a ^ p ^ k - b ^ p ^ k := by
induction' k with k ih
· rwa [pow_one, pow_zero, pow_one, pow_one]
rw [pow_succ p k, pow_mul, pow_mul, ← geom_sum₂_mul, pow_succ']
refine mul_dvd_mul ?_ ih
let f : R →+* R ⧸ span {(p : R)} := mk (span {(p : R)})
have hf : ∀ r : R, (p : R) ∣ r ↔ f r = 0 := fun r ↦ by rw [eq_zero_iff_mem, mem_span_singleton]
rw [hf, map_sub, sub_eq_zero] at h
rw [hf, RingHom.map_geom_sum₂, map_pow, map_pow, h, geom_sum₂_self, mul_eq_zero_of_left]
rw [← map_natCast f, eq_zero_iff_mem, mem_span_singleton]
end
|
NumberTheory\Bernoulli.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kevin Buzzard
-/
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Algebra.GeomSum
import Mathlib.Data.Fintype.BigOperators
import Mathlib.RingTheory.PowerSeries.Inverse
import Mathlib.RingTheory.PowerSeries.WellKnown
import Mathlib.Tactic.FieldSimp
/-!
# Bernoulli numbers
The Bernoulli numbers are a sequence of rational numbers that frequently show up in
number theory.
## Mathematical overview
The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are
a sequence of rational numbers. They show up in the formula for the sums of $k$th
powers. They are related to the Taylor series expansions of $x/\tan(x)$ and
of $\coth(x)$, and also show up in the values that the Riemann Zeta function
takes both at both negative and positive integers (and hence in the
theory of modular forms). For example, if $1 \leq n$ is even then
$$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$
Note however that this result is not yet formalised in Lean.
The Bernoulli numbers can be formally defined using the power series
$$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$
although that happens to not be the definition in mathlib (this is an *implementation
detail* and need not concern the mathematician).
Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of
[from Wikipedia](https://en.wikipedia.org/wiki/Bernoulli_number).
## Implementation detail
The Bernoulli numbers are defined using well-founded induction, by the formula
$$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$
This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition
for positive Bernoulli numbers, which we call `bernoulli'`. The negative Bernoulli numbers are
then defined as `bernoulli := (-1)^n * bernoulli'`.
## Main theorems
`sum_bernoulli : ∑ k ∈ Finset.range n, (n.choose k : ℚ) * bernoulli k = if n = 1 then 1 else 0`
-/
open Nat Finset Finset.Nat PowerSeries
variable (A : Type*) [CommRing A] [Algebra ℚ A]
/-! ### Definitions -/
/-- The Bernoulli numbers:
the $n$-th Bernoulli number $B_n$ is defined recursively via
$$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$ -/
def bernoulli' : ℕ → ℚ :=
WellFounded.fix Nat.lt_wfRel.wf fun n bernoulli' =>
1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k k.2
theorem bernoulli'_def' (n : ℕ) :
bernoulli' n = 1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k :=
WellFounded.fix_eq _ _ _
theorem bernoulli'_def (n : ℕ) :
bernoulli' n = 1 - ∑ k ∈ range n, n.choose k / (n - k + 1) * bernoulli' k := by
rw [bernoulli'_def', ← Fin.sum_univ_eq_sum_range]
theorem bernoulli'_spec (n : ℕ) :
(∑ k ∈ range n.succ, (n.choose (n - k) : ℚ) / (n - k + 1) * bernoulli' k) = 1 := by
rw [sum_range_succ_comm, bernoulli'_def n, tsub_self, choose_zero_right, sub_self, zero_add,
div_one, cast_one, one_mul, sub_add, ← sum_sub_distrib, ← sub_eq_zero, sub_sub_cancel_left,
neg_eq_zero]
exact Finset.sum_eq_zero (fun x hx => by rw [choose_symm (le_of_lt (mem_range.1 hx)), sub_self])
theorem bernoulli'_spec' (n : ℕ) :
(∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli' k.1) = 1 := by
refine ((sum_antidiagonal_eq_sum_range_succ_mk _ n).trans ?_).trans (bernoulli'_spec n)
refine sum_congr rfl fun x hx => ?_
simp only [add_tsub_cancel_of_le, mem_range_succ_iff.mp hx, cast_sub]
/-! ### Examples -/
section Examples
@[simp]
theorem bernoulli'_zero : bernoulli' 0 = 1 := by
rw [bernoulli'_def]
norm_num
@[simp]
theorem bernoulli'_one : bernoulli' 1 = 1 / 2 := by
rw [bernoulli'_def]
norm_num
@[simp]
theorem bernoulli'_two : bernoulli' 2 = 1 / 6 := by
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero]
@[simp]
theorem bernoulli'_three : bernoulli' 3 = 0 := by
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero]
@[simp]
theorem bernoulli'_four : bernoulli' 4 = -1 / 30 := by
have : Nat.choose 4 2 = 6 := by decide -- shrug
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero, this]
end Examples
@[simp]
theorem sum_bernoulli' (n : ℕ) : (∑ k ∈ range n, (n.choose k : ℚ) * bernoulli' k) = n := by
cases' n with n
· simp
suffices
((n + 1 : ℚ) * ∑ k ∈ range n, ↑(n.choose k) / (n - k + 1) * bernoulli' k) =
∑ x ∈ range n, ↑(n.succ.choose x) * bernoulli' x by
rw_mod_cast [sum_range_succ, bernoulli'_def, ← this, choose_succ_self_right]
ring
simp_rw [mul_sum, ← mul_assoc]
refine sum_congr rfl fun k hk => ?_
congr
have : ((n - k : ℕ) : ℚ) + 1 ≠ 0 := by norm_cast
field_simp [← cast_sub (mem_range.1 hk).le, mul_comm]
rw_mod_cast [tsub_add_eq_add_tsub (mem_range.1 hk).le, choose_mul_succ_eq]
/-- The exponential generating function for the Bernoulli numbers `bernoulli' n`. -/
def bernoulli'PowerSeries :=
mk fun n => algebraMap ℚ A (bernoulli' n / n !)
theorem bernoulli'PowerSeries_mul_exp_sub_one :
bernoulli'PowerSeries A * (exp A - 1) = X * exp A := by
ext n
-- constant coefficient is a special case
cases' n with n
· simp
rw [bernoulli'PowerSeries, coeff_mul, mul_comm X, sum_antidiagonal_succ']
suffices (∑ p ∈ antidiagonal n,
bernoulli' p.1 / p.1! * ((p.2 + 1) * p.2! : ℚ)⁻¹) = (n ! : ℚ)⁻¹ by
simpa [map_sum, Nat.factorial] using congr_arg (algebraMap ℚ A) this
apply eq_inv_of_mul_eq_one_left
rw [sum_mul]
convert bernoulli'_spec' n using 1
apply sum_congr rfl
simp_rw [mem_antidiagonal]
rintro ⟨i, j⟩ rfl
have := factorial_mul_factorial_dvd_factorial_add i j
field_simp [mul_comm _ (bernoulli' i), mul_assoc, add_choose]
norm_cast
simp [mul_comm (j + 1)]
/-- Odd Bernoulli numbers (greater than 1) are zero. -/
theorem bernoulli'_odd_eq_zero {n : ℕ} (h_odd : Odd n) (hlt : 1 < n) : bernoulli' n = 0 := by
let B := mk fun n => bernoulli' n / (n ! : ℚ)
suffices (B - evalNegHom B) * (exp ℚ - 1) = X * (exp ℚ - 1) by
cases' mul_eq_mul_right_iff.mp this with h h <;>
simp only [PowerSeries.ext_iff, evalNegHom, coeff_X] at h
· apply eq_zero_of_neg_eq
specialize h n
split_ifs at h <;> simp_all [B, h_odd.neg_one_pow, factorial_ne_zero]
· simpa (config := {decide := true}) [Nat.factorial] using h 1
have h : B * (exp ℚ - 1) = X * exp ℚ := by
simpa [bernoulli'PowerSeries] using bernoulli'PowerSeries_mul_exp_sub_one ℚ
rw [sub_mul, h, mul_sub X, sub_right_inj, ← neg_sub, mul_neg, neg_eq_iff_eq_neg]
suffices evalNegHom (B * (exp ℚ - 1)) * exp ℚ = evalNegHom (X * exp ℚ) * exp ℚ by
rw [map_mul, map_mul] at this -- Porting note: Why doesn't simp do this?
simpa [mul_assoc, sub_mul, mul_comm (evalNegHom (exp ℚ)), exp_mul_exp_neg_eq_one]
congr
/-- The Bernoulli numbers are defined to be `bernoulli'` with a parity sign. -/
def bernoulli (n : ℕ) : ℚ :=
(-1) ^ n * bernoulli' n
theorem bernoulli'_eq_bernoulli (n : ℕ) : bernoulli' n = (-1) ^ n * bernoulli n := by
simp [bernoulli, ← mul_assoc, ← sq, ← pow_mul, mul_comm n 2, pow_mul]
@[simp]
theorem bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli]
@[simp]
theorem bernoulli_one : bernoulli 1 = -1 / 2 := by norm_num [bernoulli]
theorem bernoulli_eq_bernoulli'_of_ne_one {n : ℕ} (hn : n ≠ 1) : bernoulli n = bernoulli' n := by
by_cases h0 : n = 0; · simp [h0]
rw [bernoulli, neg_one_pow_eq_pow_mod_two]
cases' mod_two_eq_zero_or_one n with h h
· simp [h]
· simp [bernoulli'_odd_eq_zero (odd_iff.mpr h) (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, hn⟩)]
@[simp]
theorem sum_bernoulli (n : ℕ) :
(∑ k ∈ range n, (n.choose k : ℚ) * bernoulli k) = if n = 1 then 1 else 0 := by
cases' n with n
· simp
cases' n with n
· rw [sum_range_one]
simp
suffices (∑ i ∈ range n, ↑((n + 2).choose (i + 2)) * bernoulli (i + 2)) = n / 2 by
simp only [this, sum_range_succ', cast_succ, bernoulli_one, bernoulli_zero, choose_one_right,
mul_one, choose_zero_right, cast_zero, if_false, zero_add, succ_succ_ne_one]
ring
have f := sum_bernoulli' n.succ.succ
simp_rw [sum_range_succ', cast_succ, ← eq_sub_iff_add_eq] at f
-- Porting note: was `convert f`
refine Eq.trans ?_ (Eq.trans f ?_)
· congr
funext x
rw [bernoulli_eq_bernoulli'_of_ne_one (succ_ne_zero x ∘ succ.inj)]
· simp only [one_div, mul_one, bernoulli'_zero, cast_one, choose_zero_right, add_sub_cancel_right,
zero_add, choose_one_right, cast_succ, cast_add, cast_one, bernoulli'_one, one_div]
ring
theorem bernoulli_spec' (n : ℕ) :
(∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli k.1) =
if n = 0 then 1 else 0 := by
cases' n with n
· simp
rw [if_neg (succ_ne_zero _)]
-- algebra facts
have h₁ : (1, n) ∈ antidiagonal n.succ := by simp [mem_antidiagonal, add_comm]
have h₂ : (n : ℚ) + 1 ≠ 0 := by norm_cast
have h₃ : (1 + n).choose n = n + 1 := by simp [add_comm]
-- key equation: the corresponding fact for `bernoulli'`
have H := bernoulli'_spec' n.succ
-- massage it to match the structure of the goal, then convert piece by piece
rw [sum_eq_add_sum_diff_singleton h₁] at H ⊢
apply add_eq_of_eq_sub'
convert eq_sub_of_add_eq' H using 1
· refine sum_congr rfl fun p h => ?_
obtain ⟨h', h''⟩ : p ∈ _ ∧ p ≠ _ := by rwa [mem_sdiff, mem_singleton] at h
simp [bernoulli_eq_bernoulli'_of_ne_one ((not_congr (antidiagonal_congr h' h₁)).mp h'')]
· field_simp [h₃]
norm_num
/-- The exponential generating function for the Bernoulli numbers `bernoulli n`. -/
def bernoulliPowerSeries :=
mk fun n => algebraMap ℚ A (bernoulli n / n !)
theorem bernoulliPowerSeries_mul_exp_sub_one : bernoulliPowerSeries A * (exp A - 1) = X := by
ext n
-- constant coefficient is a special case
cases' n with n
· simp
simp only [bernoulliPowerSeries, coeff_mul, coeff_X, sum_antidiagonal_succ', one_div, coeff_mk,
coeff_one, coeff_exp, LinearMap.map_sub, factorial, if_pos, cast_succ, cast_one, cast_mul,
sub_zero, RingHom.map_one, add_eq_zero_iff, if_false, _root_.inv_one, zero_add, one_ne_zero,
mul_zero, and_false_iff, sub_self, ← RingHom.map_mul, ← map_sum]
cases' n with n
· simp
rw [if_neg n.succ_succ_ne_one]
have hfact : ∀ m, (m ! : ℚ) ≠ 0 := fun m => mod_cast factorial_ne_zero m
have hite2 : ite (n.succ = 0) 1 0 = (0 : ℚ) := if_neg n.succ_ne_zero
simp only [CharP.cast_eq_zero, zero_add, inv_one, map_one, sub_self, mul_zero, add_eq]
rw [← map_zero (algebraMap ℚ A), ← zero_div (n.succ ! : ℚ), ← hite2, ← bernoulli_spec', sum_div]
refine congr_arg (algebraMap ℚ A) (sum_congr rfl fun x h => eq_div_of_mul_eq (hfact n.succ) ?_)
rw [mem_antidiagonal] at h
rw [← h, add_choose, cast_div_charZero (factorial_mul_factorial_dvd_factorial_add _ _)]
field_simp [hfact x.1, mul_comm _ (bernoulli x.1), mul_assoc]
left; left; ring
section Faulhaber
/-- **Faulhaber's theorem** relating the **sum of p-th powers** to the Bernoulli numbers:
$$\sum_{k=0}^{n-1} k^p = \sum_{i=0}^p B_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$
See https://proofwiki.org/wiki/Faulhaber%27s_Formula and [orosi2018faulhaber] for
the proof provided here. -/
theorem sum_range_pow (n p : ℕ) :
(∑ k ∈ range n, (k : ℚ) ^ p) =
∑ i ∈ range (p + 1), bernoulli i * ((p + 1).choose i) * (n : ℚ) ^ (p + 1 - i) / (p + 1) := by
have hne : ∀ m : ℕ, (m ! : ℚ) ≠ 0 := fun m => mod_cast factorial_ne_zero m
-- compute the Cauchy product of two power series
have h_cauchy :
((mk fun p => bernoulli p / p !) * mk fun q => coeff ℚ (q + 1) (exp ℚ ^ n)) =
mk fun p => ∑ i ∈ range (p + 1),
bernoulli i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1)! := by
ext q : 1
let f a b := bernoulli a / a ! * coeff ℚ (b + 1) (exp ℚ ^ n)
-- key step: use `PowerSeries.coeff_mul` and then rewrite sums
simp only [coeff_mul, coeff_mk, cast_mul, sum_antidiagonal_eq_sum_range_succ f]
apply sum_congr rfl
intros m h
simp only [f, exp_pow_eq_rescale_exp, rescale, one_div, coeff_mk, RingHom.coe_mk, coeff_exp,
RingHom.id_apply, cast_mul, algebraMap_rat_rat]
-- manipulate factorials and binomial coefficients
simp? at h says simp only [succ_eq_add_one, mem_range] at h
rw [choose_eq_factorial_div_factorial h.le, eq_comm, div_eq_iff (hne q.succ), succ_eq_add_one,
mul_assoc _ _ (q.succ ! : ℚ), mul_comm _ (q.succ ! : ℚ), ← mul_assoc, div_mul_eq_mul_div]
simp only [add_eq, add_zero, IsUnit.mul_iff, Nat.isUnit_iff, succ.injEq, cast_mul,
cast_succ, MonoidHom.coe_mk, OneHom.coe_mk, coeff_exp, Algebra.id.map_eq_id, one_div,
map_inv₀, map_natCast, coeff_mk, mul_inv_rev]
rw [mul_comm ((n : ℚ) ^ (q - m + 1)), ← mul_assoc _ _ ((n : ℚ) ^ (q - m + 1)), ← one_div,
mul_one_div, div_div, tsub_add_eq_add_tsub (le_of_lt_succ h), cast_div, cast_mul]
· ring
· exact factorial_mul_factorial_dvd_factorial h.le
· simp [hne, factorial_ne_zero]
-- same as our goal except we pull out `p!` for convenience
have hps :
(∑ k ∈ range n, (k : ℚ) ^ p) =
(∑ i ∈ range (p + 1),
bernoulli i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1)!) * p ! := by
suffices
(mk fun p => ∑ k ∈ range n, (k : ℚ) ^ p * algebraMap ℚ ℚ p !⁻¹) =
mk fun p =>
∑ i ∈ range (p + 1), bernoulli i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1)! by
rw [← div_eq_iff (hne p), div_eq_mul_inv, sum_mul]
rw [PowerSeries.ext_iff] at this
simpa using this p
-- the power series `exp ℚ - 1` is non-zero, a fact we need in order to use `mul_right_inj'`
have hexp : exp ℚ - 1 ≠ 0 := by
simp only [exp, PowerSeries.ext_iff, Ne, not_forall]
use 1
simp [factorial_ne_zero]
have h_r : exp ℚ ^ n - 1 = X * mk fun p => coeff ℚ (p + 1) (exp ℚ ^ n) := by
have h_const : C ℚ (constantCoeff ℚ (exp ℚ ^ n)) = 1 := by simp
rw [← h_const, sub_const_eq_X_mul_shift]
-- key step: a chain of equalities of power series
-- Porting note: altered proof slightly
rw [← mul_right_inj' hexp, mul_comm]
rw [← exp_pow_sum, geom_sum_mul, h_r, ← bernoulliPowerSeries_mul_exp_sub_one,
bernoulliPowerSeries, mul_right_comm]
simp only [mul_comm, mul_eq_mul_left_iff, hexp, or_false]
refine Eq.trans (mul_eq_mul_right_iff.mpr ?_) (Eq.trans h_cauchy ?_)
· left
congr
· simp only [mul_comm, factorial, cast_succ, cast_pow]
-- massage `hps` into our goal
rw [hps, sum_mul]
refine sum_congr rfl fun x _ => ?_
field_simp [mul_right_comm _ ↑p !, ← mul_assoc _ _ ↑p !, factorial]
ring
/-- Alternate form of **Faulhaber's theorem**, relating the sum of p-th powers to the Bernoulli
numbers: $$\sum_{k=1}^{n} k^p = \sum_{i=0}^p (-1)^iB_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$
Deduced from `sum_range_pow`. -/
theorem sum_Ico_pow (n p : ℕ) :
(∑ k ∈ Ico 1 (n + 1), (k : ℚ) ^ p) =
∑ i ∈ range (p + 1), bernoulli' i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1) := by
rw [← Nat.cast_succ]
-- dispose of the trivial case
cases' p with p
· simp
let f i := bernoulli i * p.succ.succ.choose i * (n : ℚ) ^ (p.succ.succ - i) / p.succ.succ
let f' i := bernoulli' i * p.succ.succ.choose i * (n : ℚ) ^ (p.succ.succ - i) / p.succ.succ
suffices (∑ k ∈ Ico 1 n.succ, (k : ℚ) ^ p.succ) = ∑ i ∈ range p.succ.succ, f' i by convert this
-- prove some algebraic facts that will make things easier for us later on
have hle := Nat.le_add_left 1 n
have hne : (p + 1 + 1 : ℚ) ≠ 0 := by norm_cast
have h1 : ∀ r : ℚ, r * (p + 1 + 1) * (n : ℚ) ^ p.succ / (p + 1 + 1 : ℚ) = r * (n : ℚ) ^ p.succ :=
fun r => by rw [mul_div_right_comm, mul_div_cancel_right₀ _ hne]
have h2 : f 1 + (n : ℚ) ^ p.succ = 1 / 2 * (n : ℚ) ^ p.succ := by
simp_rw [f, bernoulli_one, choose_one_right, succ_sub_succ_eq_sub, cast_succ, tsub_zero, h1]
ring
have :
(∑ i ∈ range p, bernoulli (i + 2) * (p + 2).choose (i + 2) * (n : ℚ) ^ (p - i) / ↑(p + 2)) =
∑ i ∈ range p, bernoulli' (i + 2) * (p + 2).choose (i + 2) * (n : ℚ) ^ (p - i) / ↑(p + 2) :=
sum_congr rfl fun i _ => by rw [bernoulli_eq_bernoulli'_of_ne_one (succ_succ_ne_one i)]
calc
(-- replace sum over `Ico` with sum over `range` and simplify
∑ k ∈ Ico 1 n.succ, (k : ℚ) ^ p.succ)
_ = ∑ k ∈ range n.succ, (k : ℚ) ^ p.succ := by simp [sum_Ico_eq_sub _ hle, succ_ne_zero]
-- extract the last term of the sum
_ = (∑ k ∈ range n, (k : ℚ) ^ p.succ) + (n : ℚ) ^ p.succ := by rw [sum_range_succ]
-- apply the key lemma, `sum_range_pow`
_ = (∑ i ∈ range p.succ.succ, f i) + (n : ℚ) ^ p.succ := by simp [f, sum_range_pow]
-- extract the first two terms of the sum
_ = (∑ i ∈ range p, f i.succ.succ) + f 1 + f 0 + (n : ℚ) ^ p.succ := by
simp_rw [sum_range_succ']
_ = (∑ i ∈ range p, f i.succ.succ) + (f 1 + (n : ℚ) ^ p.succ) + f 0 := by ring
_ = (∑ i ∈ range p, f i.succ.succ) + 1 / 2 * (n : ℚ) ^ p.succ + f 0 := by rw [h2]
-- convert from `bernoulli` to `bernoulli'`
_ = (∑ i ∈ range p, f' i.succ.succ) + f' 1 + f' 0 := by
simpa [f, f', h1, fun i => show i + 2 = i + 1 + 1 from rfl]
-- rejoin the first two terms of the sum
_ = ∑ i ∈ range p.succ.succ, f' i := by simp_rw [sum_range_succ']
end Faulhaber
|
NumberTheory\BernoulliPolynomials.lean | /-
Copyright (c) 2021 Ashvni Narayanan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ashvni Narayanan, David Loeffler
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Data.Nat.Choose.Cast
import Mathlib.NumberTheory.Bernoulli
/-!
# Bernoulli polynomials
The [Bernoulli polynomials](https://en.wikipedia.org/wiki/Bernoulli_polynomials)
are an important tool obtained from Bernoulli numbers.
## Mathematical overview
The $n$-th Bernoulli polynomial is defined as
$$ B_n(X) = ∑_{k = 0}^n {n \choose k} (-1)^k B_k X^{n - k} $$
where $B_k$ is the $k$-th Bernoulli number. The Bernoulli polynomials are generating functions,
$$ \frac{t e^{tX} }{ e^t - 1} = ∑_{n = 0}^{\infty} B_n(X) \frac{t^n}{n!} $$
## Implementation detail
Bernoulli polynomials are defined using `bernoulli`, the Bernoulli numbers.
## Main theorems
- `sum_bernoulli`: The sum of the $k^\mathrm{th}$ Bernoulli polynomial with binomial
coefficients up to `n` is `(n + 1) * X^n`.
- `Polynomial.bernoulli_generating_function`: The Bernoulli polynomials act as generating functions
for the exponential.
## TODO
- `bernoulli_eval_one_neg` : $$ B_n(1 - x) = (-1)^n B_n(x) $$
-/
noncomputable section
open Nat Polynomial
open Nat Finset
namespace Polynomial
/-- The Bernoulli polynomials are defined in terms of the negative Bernoulli numbers. -/
def bernoulli (n : ℕ) : ℚ[X] :=
∑ i ∈ range (n + 1), Polynomial.monomial (n - i) (_root_.bernoulli i * choose n i)
theorem bernoulli_def (n : ℕ) : bernoulli n =
∑ i ∈ range (n + 1), Polynomial.monomial i (_root_.bernoulli (n - i) * choose n i) := by
rw [← sum_range_reflect, add_succ_sub_one, add_zero, bernoulli]
apply sum_congr rfl
rintro x hx
rw [mem_range_succ_iff] at hx
rw [choose_symm hx, tsub_tsub_cancel_of_le hx]
/-
### examples
-/
section Examples
@[simp]
theorem bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli]
@[simp]
theorem bernoulli_eval_zero (n : ℕ) : (bernoulli n).eval 0 = _root_.bernoulli n := by
rw [bernoulli, eval_finset_sum, sum_range_succ]
have : ∑ x ∈ range n, _root_.bernoulli x * n.choose x * 0 ^ (n - x) = 0 := by
apply sum_eq_zero fun x hx => _
intros x hx
simp [tsub_eq_zero_iff_le, mem_range.1 hx]
simp [this]
@[simp]
theorem bernoulli_eval_one (n : ℕ) : (bernoulli n).eval 1 = bernoulli' n := by
simp only [bernoulli, eval_finset_sum]
simp only [← succ_eq_add_one, sum_range_succ, mul_one, cast_one, choose_self,
(_root_.bernoulli _).mul_comm, sum_bernoulli, one_pow, mul_one, eval_C, eval_monomial, one_mul]
by_cases h : n = 1
· norm_num [h]
· simp [h, bernoulli_eq_bernoulli'_of_ne_one h]
end Examples
theorem derivative_bernoulli_add_one (k : ℕ) :
Polynomial.derivative (bernoulli (k + 1)) = (k + 1) * bernoulli k := by
simp_rw [bernoulli, derivative_sum, derivative_monomial, Nat.sub_sub, Nat.add_sub_add_right]
-- LHS sum has an extra term, but the coefficient is zero:
rw [range_add_one, sum_insert not_mem_range_self, tsub_self, cast_zero, mul_zero,
map_zero, zero_add, mul_sum]
-- the rest of the sum is termwise equal:
refine sum_congr (by rfl) fun m _ => ?_
conv_rhs => rw [← Nat.cast_one, ← Nat.cast_add, ← C_eq_natCast, C_mul_monomial, mul_comm]
rw [mul_assoc, mul_assoc, ← Nat.cast_mul, ← Nat.cast_mul]
congr 3
rw [(choose_mul_succ_eq k m).symm]
theorem derivative_bernoulli (k : ℕ) :
Polynomial.derivative (bernoulli k) = k * bernoulli (k - 1) := by
cases k with
| zero => rw [Nat.cast_zero, zero_mul, bernoulli_zero, derivative_one]
| succ k => exact mod_cast derivative_bernoulli_add_one k
@[simp]
nonrec theorem sum_bernoulli (n : ℕ) :
(∑ k ∈ range (n + 1), ((n + 1).choose k : ℚ) • bernoulli k) = monomial n (n + 1 : ℚ) := by
simp_rw [bernoulli_def, Finset.smul_sum, Finset.range_eq_Ico, ← Finset.sum_Ico_Ico_comm,
Finset.sum_Ico_eq_sum_range]
simp only [add_tsub_cancel_left, tsub_zero, zero_add, map_add]
simp_rw [smul_monomial, mul_comm (_root_.bernoulli _) _, smul_eq_mul, ← mul_assoc]
conv_lhs =>
apply_congr
· skip
· conv =>
apply_congr
· skip
· rw [← Nat.cast_mul, choose_mul ((le_tsub_iff_left <| mem_range_le (by assumption)).1 <|
mem_range_le (by assumption)) (le.intro rfl),
Nat.cast_mul, add_tsub_cancel_left, mul_assoc, mul_comm, ← smul_eq_mul, ←
smul_monomial]
simp_rw [← sum_smul]
rw [sum_range_succ_comm]
simp only [add_right_eq_self, mul_one, cast_one, cast_add, add_tsub_cancel_left,
choose_succ_self_right, one_smul, _root_.bernoulli_zero, sum_singleton, zero_add,
map_add, range_one, bernoulli_zero, mul_one, one_mul, add_zero, choose_self]
apply sum_eq_zero fun x hx => _
have f : ∀ x ∈ range n, ¬n + 1 - x = 1 := by
rintro x H
rw [mem_range] at H
rw [eq_comm]
exact _root_.ne_of_lt (Nat.lt_of_lt_of_le one_lt_two (le_tsub_of_add_le_left (succ_le_succ H)))
intro x hx
rw [sum_bernoulli]
have g : ite (n + 1 - x = 1) (1 : ℚ) 0 = 0 := by
simp only [ite_eq_right_iff, one_ne_zero]
intro h₁
exact (f x hx) h₁
rw [g, zero_smul]
/-- Another version of `Polynomial.sum_bernoulli`. -/
theorem bernoulli_eq_sub_sum (n : ℕ) :
(n.succ : ℚ) • bernoulli n =
monomial n (n.succ : ℚ) - ∑ k ∈ Finset.range n, ((n + 1).choose k : ℚ) • bernoulli k := by
rw [Nat.cast_succ, ← sum_bernoulli n, sum_range_succ, add_sub_cancel_left, choose_succ_self_right,
Nat.cast_succ]
/-- Another version of `sum_range_pow`. -/
theorem sum_range_pow_eq_bernoulli_sub (n p : ℕ) :
((p + 1 : ℚ) * ∑ k ∈ range n, (k : ℚ) ^ p) = (bernoulli p.succ).eval (n : ℚ) -
_root_.bernoulli p.succ := by
rw [sum_range_pow, bernoulli_def, eval_finset_sum, ← sum_div, mul_div_cancel₀ _ _]
· simp_rw [eval_monomial]
symm
rw [← sum_flip _, sum_range_succ]
simp only [tsub_self, tsub_zero, choose_zero_right, cast_one, mul_one, _root_.pow_zero,
add_tsub_cancel_right]
apply sum_congr rfl fun x hx => _
intro x hx
apply congr_arg₂ _ (congr_arg₂ _ _ _) rfl
· rw [Nat.sub_sub_self (mem_range_le hx)]
· rw [← choose_symm (mem_range_le hx)]
· norm_cast
/-- Rearrangement of `Polynomial.sum_range_pow_eq_bernoulli_sub`. -/
theorem bernoulli_succ_eval (n p : ℕ) : (bernoulli p.succ).eval (n : ℚ) =
_root_.bernoulli p.succ + (p + 1 : ℚ) * ∑ k ∈ range n, (k : ℚ) ^ p := by
apply eq_add_of_sub_eq'
rw [sum_range_pow_eq_bernoulli_sub]
theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) :
(bernoulli n).eval (1 + x) = (bernoulli n).eval x + n * x ^ (n - 1) := by
refine Nat.strong_induction_on n fun d hd => ?_
have nz : ((d.succ : ℕ) : ℚ) ≠ 0 := by
norm_cast
apply (mul_right_inj' nz).1
rw [← smul_eq_mul, ← eval_smul, bernoulli_eq_sub_sum, mul_add, ← smul_eq_mul, ← eval_smul,
bernoulli_eq_sub_sum, eval_sub, eval_finset_sum]
conv_lhs =>
congr
· skip
· apply_congr
· skip
· rw [eval_smul, hd _ (mem_range.1 (by assumption))]
rw [eval_sub, eval_finset_sum]
simp_rw [eval_smul, smul_add]
rw [sum_add_distrib, sub_add, sub_eq_sub_iff_sub_eq_sub, _root_.add_sub_sub_cancel]
conv_rhs =>
congr
· skip
· congr
rw [succ_eq_add_one, ← choose_succ_self_right d]
rw [Nat.cast_succ, ← smul_eq_mul, ← sum_range_succ _ d, eval_monomial_one_add_sub]
simp_rw [smul_eq_mul]
open PowerSeries
variable {A : Type*} [CommRing A] [Algebra ℚ A]
-- TODO: define exponential generating functions, and use them here
-- This name should probably be updated afterwards
/-- The theorem that $(e^X - 1) * ∑ Bₙ(t)* X^n/n! = Xe^{tX}$ -/
theorem bernoulli_generating_function (t : A) :
(mk fun n => aeval t ((1 / n ! : ℚ) • bernoulli n)) * (exp A - 1) =
PowerSeries.X * rescale t (exp A) := by
-- check equality of power series by checking coefficients of X^n
ext n
-- n = 0 case solved by `simp`
cases' n with n
· simp
-- n ≥ 1, the coefficients is a sum to n+2, so use `sum_range_succ` to write as
-- last term plus sum to n+1
rw [coeff_succ_X_mul, coeff_rescale, coeff_exp, PowerSeries.coeff_mul,
Nat.sum_antidiagonal_eq_sum_range_succ_mk, sum_range_succ]
-- last term is zero so kill with `add_zero`
simp only [RingHom.map_sub, tsub_self, constantCoeff_one, constantCoeff_exp,
coeff_zero_eq_constantCoeff, mul_zero, sub_self, add_zero]
-- Let's multiply both sides by (n+1)! (OK because it's a unit)
have hnp1 : IsUnit ((n + 1)! : ℚ) := IsUnit.mk0 _ (mod_cast factorial_ne_zero (n + 1))
rw [← (hnp1.map (algebraMap ℚ A)).mul_right_inj]
-- do trivial rearrangements to make RHS (n+1)*t^n
rw [mul_left_comm, ← RingHom.map_mul]
change _ = t ^ n * algebraMap ℚ A (((n + 1) * n ! : ℕ) * (1 / n !))
rw [cast_mul, mul_assoc,
mul_one_div_cancel (show (n ! : ℚ) ≠ 0 from cast_ne_zero.2 (factorial_ne_zero n)), mul_one,
mul_comm (t ^ n), ← aeval_monomial, cast_add, cast_one]
-- But this is the RHS of `Polynomial.sum_bernoulli`
rw [← sum_bernoulli, Finset.mul_sum, map_sum]
-- and now we have to prove a sum is a sum, but all the terms are equal.
apply Finset.sum_congr rfl
-- The rest is just trivialities, hampered by the fact that we're coercing
-- factorials and binomial coefficients between ℕ and ℚ and A.
intro i hi
-- deal with coefficients of e^X-1
simp only [Nat.cast_choose ℚ (mem_range_le hi), coeff_mk, if_neg (mem_range_sub_ne_zero hi),
one_div, map_smul, PowerSeries.coeff_one, coeff_exp, sub_zero, LinearMap.map_sub,
Algebra.smul_mul_assoc, Algebra.smul_def, mul_right_comm _ ((aeval t) _), ← mul_assoc, ←
RingHom.map_mul, succ_eq_add_one, ← Polynomial.C_eq_algebraMap, Polynomial.aeval_mul,
Polynomial.aeval_C]
-- finally cancel the Bernoulli polynomial and the algebra_map
field_simp
end Polynomial
|
NumberTheory\Bertrand.lean | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
import Mathlib.Tactic.NormNum.Prime
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the Erdős proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of “There is a Prime between n and 2n”_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 ≤ x.
-/
theorem real_main_inequality {x : ℝ} (x_large : (512 : ℝ) ≤ x) :
x * (2 * x) ^ √(2 * x) * 4 ^ (2 * x / 3) ≤ 4 ^ x := by
let f : ℝ → ℝ := fun x => log x + √(2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : ∀ x, 0 < x → 0 < x * (2 * x) ^ √(2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : ∀ x, 0 < x → f x = log (x * (2 * x) ^ √(2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' ℝ) h5
have h7 := rpow_pos_of_pos h6 (√(2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, ← mul_div_right_comm, ← mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) x_large
rw [← div_le_one (rpow_pos_of_pos four_pos x), ← div_div_eq_mul_div, ← rpow_sub four_pos, ←
mul_div 2 x, mul_div_left_comm, ← mul_one_sub, (by norm_num1 : (1 : ℝ) - 2 / 3 = 1 / 3),
mul_one_div, ← log_nonpos_iff (hf' x h5), ← hf x h5]
-- porting note (#11083): the proof was rewritten, because it was too slow
have h : ConcaveOn ℝ (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
· apply ConcaveOn.add
· exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : ℝ) • LinearMap.id))) using 1
ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [← mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
· refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
· exact convexOn_id (convex_Ioi (0.5 : ℝ))
suffices ∃ x1 x2, 0.5 < x1 ∧ x1 < x2 ∧ x2 ≤ x ∧ 0 ≤ f x1 ∧ f x2 ≤ 0 by
obtain ⟨x1, x2, h1, h2, h0, h3, h4⟩ := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine ⟨18, 512, by norm_num1, by norm_num1, x_large, ?_, ?_⟩
· have : √(2 * 18 : ℝ) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf _ (by norm_num1), log_nonneg_iff (by positivity), this, one_le_div (by norm_num1)]
norm_num1
· have : √(2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf _ (by norm_num1), log_nonpos_iff (hf' _ (by norm_num1)), this,
div_le_one (by positivity)]
conv in 512 => equals 2 ^ 9 => norm_num1
conv in 2 * 512 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [← Nat.cast_ofNat]
rw [rpow_natCast, ← pow_mul, ← pow_add]
conv in 4 => equals 2 ^ (2 : ℝ) => rw [rpow_two]; norm_num1
rw [← rpow_mul, ← rpow_natCast]
on_goal 1 => apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : ℕ} (n_large : 512 ≤ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) ≤ 4 ^ n := by
rw [← @cast_le ℝ]
simp only [cast_add, cast_one, cast_mul, cast_pow, ← Real.rpow_natCast]
refine _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
· exact_mod_cast Real.nat_sqrt_le_real_sqrt
· norm_num1
· exact cast_div_le.trans (by norm_cast)
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : ℕ) (n_large : 2 < n)
(no_prime : ¬∃ p : ℕ, p.Prime ∧ n < p ∧ p ≤ 2 * n) :
centralBinom n = ∏ p ∈ Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine (Eq.trans ?_ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, Nat.lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [← and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : ℕ) (n_large : 2 < n)
(no_prime : ¬∃ p : ℕ, Nat.Prime p ∧ n < p ∧ p ≤ 2 * n) :
centralBinom n ≤ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_large
have n2_pos : 1 ≤ 2 * n := mul_pos (zero_lt_two' ℕ) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : ∏ x ∈ S, f x = ∏ x ∈ Finset.range (2 * n / 3 + 1), f x := by
refine Finset.prod_filter_of_ne fun p _ h => ?_
contrapose! h; dsimp only [f]
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
rw [centralBinom_factorization_small n n_large no_prime, ← this, ←
Finset.prod_filter_mul_prod_filter_not S (· ≤ sqrt (2 * n))]
apply mul_le_mul'
· refine (Finset.prod_le_prod' fun p _ => (?_ : f p ≤ 2 * n)).trans ?_
· exact pow_factorization_choose_le (mul_pos two_pos n_pos)
have : (Finset.Icc 1 (sqrt (2 * n))).card = sqrt (2 * n) := by rw [card_Icc, Nat.add_sub_cancel]
rw [Finset.prod_const]
refine pow_le_pow_right n2_pos ((Finset.card_le_card fun x hx => ?_).trans this.le)
obtain ⟨h1, h2⟩ := Finset.mem_filter.1 hx
exact Finset.mem_Icc.mpr ⟨(Finset.mem_filter.1 h1).2.one_lt.le, h2⟩
· refine le_trans ?_ (primorial_le_4_pow (2 * n / 3))
refine (Finset.prod_le_prod' fun p hp => (?_ : f p ≤ p)).trans ?_
· obtain ⟨h1, h2⟩ := Finset.mem_filter.1 hp
refine (pow_le_pow_right (Finset.mem_filter.1 h1).2.one_lt.le ?_).trans (pow_one p).le
exact Nat.factorization_choose_le_one (sqrt_lt'.mp <| not_le.1 h2)
refine Finset.prod_le_prod_of_subset_of_one_le' (Finset.filter_subset _ _) ?_
exact fun p hp _ => (Finset.mem_filter.1 hp).2.one_lt.le
namespace Nat
/-- Proves that **Bertrand's postulate** holds for all sufficiently large `n`.
-/
theorem exists_prime_lt_and_le_two_mul_eventually (n : ℕ) (n_large : 512 ≤ n) :
∃ p : ℕ, p.Prime ∧ n < p ∧ p ≤ 2 * n := by
-- Assume there is no prime in the range.
by_contra no_prime
-- Then we have the above sub-exponential bound on the size of this central binomial coefficient.
-- We now couple this bound with an exponential lower bound on the central binomial coefficient,
-- yielding an inequality which we have seen is false for large enough n.
have H1 : n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) ≤ 4 ^ n := bertrand_main_inequality n_large
have H2 : 4 ^ n < n * n.centralBinom :=
Nat.four_pow_lt_mul_centralBinom n (le_trans (by norm_num1) n_large)
have H3 : n.centralBinom ≤ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) :=
centralBinom_le_of_no_bertrand_prime n (lt_of_lt_of_le (by norm_num1) n_large) no_prime
rw [mul_assoc] at H1; exact not_le.2 H2 ((mul_le_mul_left' H3 n).trans H1)
/-- Proves that Bertrand's postulate holds over all positive naturals less than n by identifying a
descending list of primes, each no more than twice the next, such that the list contains a witness
for each number ≤ n.
-/
theorem exists_prime_lt_and_le_two_mul_succ {n} (q) {p : ℕ} (prime_p : Nat.Prime p)
(covering : p ≤ 2 * q) (H : n < q → ∃ p : ℕ, p.Prime ∧ n < p ∧ p ≤ 2 * n) (hn : n < p) :
∃ p : ℕ, p.Prime ∧ n < p ∧ p ≤ 2 * n := by
by_cases h : p ≤ 2 * n; · exact ⟨p, prime_p, hn, h⟩
exact H (lt_of_mul_lt_mul_left' (lt_of_lt_of_le (not_le.1 h) covering))
/--
**Bertrand's Postulate**: For any positive natural number, there is a prime which is greater than
it, but no more than twice as large.
-/
theorem exists_prime_lt_and_le_two_mul (n : ℕ) (hn0 : n ≠ 0) :
∃ p, Nat.Prime p ∧ n < p ∧ p ≤ 2 * n := by
-- Split into cases whether `n` is large or small
cases' lt_or_le 511 n with h h
-- If `n` is large, apply the lemma derived from the inequalities on the central binomial
-- coefficient.
· exact exists_prime_lt_and_le_two_mul_eventually n h
replace h : n < 521 := h.trans_lt (by norm_num1)
revert h
-- For small `n`, supply a list of primes to cover the initial cases.
open Lean Elab Tactic in
run_tac do
for i in [317, 163, 83, 43, 23, 13, 7, 5, 3, 2] do
let i : Term := quote i
evalTactic <| ←
`(tactic| refine exists_prime_lt_and_le_two_mul_succ $i (by norm_num1) (by norm_num1) ?_)
exact fun h2 => ⟨2, prime_two, h2, Nat.mul_le_mul_left 2 (Nat.pos_of_ne_zero hn0)⟩
alias bertrand := Nat.exists_prime_lt_and_le_two_mul
end Nat
end Nat
|
NumberTheory\Dioph.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Fin.Fin2
import Mathlib.Data.PFun
import Mathlib.Data.Vector3
import Mathlib.NumberTheory.PellMatiyasevic
/-!
# Diophantine functions and Matiyasevic's theorem
Hilbert's tenth problem asked whether there exists an algorithm which for a given integer polynomial
determines whether this polynomial has integer solutions. It was answered in the negative in 1970,
the final step being completed by Matiyasevic who showed that the power function is Diophantine.
Here a function is called Diophantine if its graph is Diophantine as a set. A subset `S ⊆ ℕ ^ α` in
turn is called Diophantine if there exists an integer polynomial on `α ⊕ β` such that `v ∈ S` iff
there exists `t : ℕ^β` with `p (v, t) = 0`.
## Main definitions
* `IsPoly`: a predicate stating that a function is a multivariate integer polynomial.
* `Poly`: the type of multivariate integer polynomial functions.
* `Dioph`: a predicate stating that a set is Diophantine, i.e. a set `S ⊆ ℕ^α` is
Diophantine if there exists a polynomial on `α ⊕ β` such that `v ∈ S` iff there
exists `t : ℕ^β` with `p (v, t) = 0`.
* `dioph_fn`: a predicate on a function stating that it is Diophantine in the sense that its graph
is Diophantine as a set.
## Main statements
* `pell_dioph` states that solutions to Pell's equation form a Diophantine set.
* `pow_dioph` states that the power function is Diophantine, a version of Matiyasevic's theorem.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevic's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Matiyasevic's theorem, Hilbert's tenth problem
## TODO
* Finish the solution of Hilbert's tenth problem.
* Connect `Poly` to `MvPolynomial`
-/
open Fin2 Function Nat Sum
local infixr:67 " ::ₒ " => Option.elim'
local infixr:65 " ⊗ " => Sum.elim
universe u
/-!
### Multivariate integer polynomials
Note that this duplicates `MvPolynomial`.
-/
section Polynomials
variable {α β γ : Type*}
/-- A predicate asserting that a function is a multivariate integer polynomial.
(We are being a bit lazy here by allowing many representations for multiplication,
rather than only allowing monomials and addition, but the definition is equivalent
and this is easier to use.) -/
inductive IsPoly : ((α → ℕ) → ℤ) → Prop
| proj : ∀ i, IsPoly fun x : α → ℕ => x i
| const : ∀ n : ℤ, IsPoly fun _ : α → ℕ => n
| sub : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x - g x
| mul : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x * g x
theorem IsPoly.neg {f : (α → ℕ) → ℤ} : IsPoly f → IsPoly (-f) := by
rw [← zero_sub]; exact (IsPoly.const 0).sub
theorem IsPoly.add {f g : (α → ℕ) → ℤ} (hf : IsPoly f) (hg : IsPoly g) : IsPoly (f + g) := by
rw [← sub_neg_eq_add]; exact hf.sub hg.neg
/-- The type of multivariate integer polynomials -/
def Poly (α : Type u) := { f : (α → ℕ) → ℤ // IsPoly f }
namespace Poly
section
instance instFunLike : FunLike (Poly α) (α → ℕ) ℤ :=
⟨Subtype.val, Subtype.val_injective⟩
/-- The underlying function of a `Poly` is a polynomial -/
protected theorem isPoly (f : Poly α) : IsPoly f := f.2
/-- Extensionality for `Poly α` -/
@[ext]
theorem ext {f g : Poly α} : (∀ x, f x = g x) → f = g := DFunLike.ext _ _
/-- The `i`th projection function, `x_i`. -/
def proj (i : α) : Poly α := ⟨_, IsPoly.proj i⟩
@[simp]
theorem proj_apply (i : α) (x) : proj i x = x i := rfl
/-- The constant function with value `n : ℤ`. -/
def const (n : ℤ) : Poly α := ⟨_, IsPoly.const n⟩
@[simp]
theorem const_apply (n) (x : α → ℕ) : const n x = n := rfl
instance : Zero (Poly α) := ⟨const 0⟩
instance : One (Poly α) := ⟨const 1⟩
instance : Neg (Poly α) := ⟨fun f => ⟨-f, f.2.neg⟩⟩
instance : Add (Poly α) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩
instance : Sub (Poly α) := ⟨fun f g => ⟨f - g, f.2.sub g.2⟩⟩
instance : Mul (Poly α) := ⟨fun f g => ⟨f * g, f.2.mul g.2⟩⟩
@[simp]
theorem coe_zero : ⇑(0 : Poly α) = const 0 := rfl
@[simp]
theorem coe_one : ⇑(1 : Poly α) = const 1 := rfl
@[simp]
theorem coe_neg (f : Poly α) : ⇑(-f) = -f := rfl
@[simp]
theorem coe_add (f g : Poly α) : ⇑(f + g) = f + g := rfl
@[simp]
theorem coe_sub (f g : Poly α) : ⇑(f - g) = f - g := rfl
@[simp]
theorem coe_mul (f g : Poly α) : ⇑(f * g) = f * g := rfl
@[simp]
theorem zero_apply (x) : (0 : Poly α) x = 0 := rfl
@[simp]
theorem one_apply (x) : (1 : Poly α) x = 1 := rfl
@[simp]
theorem neg_apply (f : Poly α) (x) : (-f) x = -f x := rfl
@[simp]
theorem add_apply (f g : Poly α) (x : α → ℕ) : (f + g) x = f x + g x := rfl
@[simp]
theorem sub_apply (f g : Poly α) (x : α → ℕ) : (f - g) x = f x - g x := rfl
@[simp]
theorem mul_apply (f g : Poly α) (x : α → ℕ) : (f * g) x = f x * g x := rfl
instance (α : Type*) : Inhabited (Poly α) := ⟨0⟩
instance : AddCommGroup (Poly α) where
add := ((· + ·) : Poly α → Poly α → Poly α)
neg := (Neg.neg : Poly α → Poly α)
sub := Sub.sub
zero := 0
nsmul := @nsmulRec _ ⟨(0 : Poly α)⟩ ⟨(· + ·)⟩
zsmul := @zsmulRec _ ⟨(0 : Poly α)⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec _ ⟨(0 : Poly α)⟩ ⟨(· + ·)⟩)
add_zero _ := by ext; simp_rw [add_apply, zero_apply, add_zero]
zero_add _ := by ext; simp_rw [add_apply, zero_apply, zero_add]
add_comm _ _ := by ext; simp_rw [add_apply, add_comm]
add_assoc _ _ _ := by ext; simp_rw [add_apply, ← add_assoc]
add_left_neg _ := by ext; simp_rw [add_apply, neg_apply, add_left_neg, zero_apply]
instance : AddGroupWithOne (Poly α) :=
{ (inferInstance : AddCommGroup (Poly α)) with
one := 1
natCast := fun n => Poly.const n
intCast := Poly.const }
instance : CommRing (Poly α) where
__ := (inferInstance : AddCommGroup (Poly α))
__ := (inferInstance : AddGroupWithOne (Poly α))
mul := (· * ·)
npow := @npowRec _ ⟨(1 : Poly α)⟩ ⟨(· * ·)⟩
mul_zero _ := by ext; rw [mul_apply, zero_apply, mul_zero]
zero_mul _ := by ext; rw [mul_apply, zero_apply, zero_mul]
mul_one _ := by ext; rw [mul_apply, one_apply, mul_one]
one_mul _ := by ext; rw [mul_apply, one_apply, one_mul]
mul_comm _ _ := by ext; simp_rw [mul_apply, mul_comm]
mul_assoc _ _ _ := by ext; simp_rw [mul_apply, mul_assoc]
left_distrib _ _ _ := by ext; simp_rw [add_apply, mul_apply]; apply mul_add
right_distrib _ _ _ := by ext; simp only [add_apply, mul_apply]; apply add_mul
theorem induction {C : Poly α → Prop} (H1 : ∀ i, C (proj i)) (H2 : ∀ n, C (const n))
(H3 : ∀ f g, C f → C g → C (f - g)) (H4 : ∀ f g, C f → C g → C (f * g)) (f : Poly α) : C f := by
cases' f with f pf
induction' pf with i n f g pf pg ihf ihg f g pf pg ihf ihg
· apply H1
· apply H2
· apply H3 _ _ ihf ihg
· apply H4 _ _ ihf ihg
/-- The sum of squares of a list of polynomials. This is relevant for
Diophantine equations, because it means that a list of equations
can be encoded as a single equation: `x = 0 ∧ y = 0 ∧ z = 0` is
equivalent to `x^2 + y^2 + z^2 = 0`. -/
def sumsq : List (Poly α) → Poly α
| [] => 0
| p::ps => p * p + sumsq ps
theorem sumsq_nonneg (x : α → ℕ) : ∀ l, 0 ≤ sumsq l x
| [] => le_refl 0
| p::ps => by
rw [sumsq]
exact add_nonneg (mul_self_nonneg _) (sumsq_nonneg _ ps)
theorem sumsq_eq_zero (x) : ∀ l, sumsq l x = 0 ↔ l.Forall fun a : Poly α => a x = 0
| [] => eq_self_iff_true _
| p::ps => by
rw [List.forall_cons, ← sumsq_eq_zero _ ps]; rw [sumsq]
exact
⟨fun h : p x * p x + sumsq ps x = 0 =>
have : p x = 0 :=
eq_zero_of_mul_self_eq_zero <|
le_antisymm
(by
rw [← h]
have t := add_le_add_left (sumsq_nonneg x ps) (p x * p x)
rwa [add_zero] at t)
(mul_self_nonneg _)
⟨this, by simpa [this] using h⟩,
fun ⟨h1, h2⟩ => by rw [add_apply, mul_apply, h1, h2]; rfl⟩
end
/-- Map the index set of variables, replacing `x_i` with `x_(f i)`. -/
def map {α β} (f : α → β) (g : Poly α) : Poly β :=
⟨fun v => g <| v ∘ f, Poly.induction (C := fun g => IsPoly (fun v => g (v ∘ f)))
(fun i => by simpa using IsPoly.proj _) (fun n => by simpa using IsPoly.const _)
(fun f g pf pg => by simpa using IsPoly.sub pf pg)
(fun f g pf pg => by simpa using IsPoly.mul pf pg) _⟩
@[simp]
theorem map_apply {α β} (f : α → β) (g : Poly α) (v) : map f g v = g (v ∘ f) := rfl
end Poly
end Polynomials
/-! ### Diophantine sets -/
/-- A set `S ⊆ ℕ^α` is Diophantine if there exists a polynomial on
`α ⊕ β` such that `v ∈ S` iff there exists `t : ℕ^β` with `p (v, t) = 0`. -/
def Dioph {α : Type u} (S : Set (α → ℕ)) : Prop :=
∃ (β : Type u) (p : Poly (α ⊕ β)), ∀ v, S v ↔ ∃ t, p (v ⊗ t) = 0
namespace Dioph
section
variable {α β γ : Type u} {S S' : Set (α → ℕ)}
theorem ext (d : Dioph S) (H : ∀ v, v ∈ S ↔ v ∈ S') : Dioph S' := by rwa [← Set.ext H]
theorem of_no_dummies (S : Set (α → ℕ)) (p : Poly α) (h : ∀ v, S v ↔ p v = 0) : Dioph S :=
⟨PEmpty, ⟨p.map inl, fun v => (h v).trans ⟨fun h => ⟨PEmpty.elim, h⟩, fun ⟨_, ht⟩ => ht⟩⟩⟩
theorem inject_dummies_lem (f : β → γ) (g : γ → Option β) (inv : ∀ x, g (f x) = some x)
(p : Poly (α ⊕ β)) (v : α → ℕ) :
(∃ t, p (v ⊗ t) = 0) ↔ ∃ t, p.map (inl ⊗ inr ∘ f) (v ⊗ t) = 0 := by
dsimp; refine ⟨fun t => ?_, fun t => ?_⟩ <;> cases' t with t ht
· have : (v ⊗ (0 ::ₒ t) ∘ g) ∘ (inl ⊗ inr ∘ f) = v ⊗ t :=
funext fun s => by cases' s with a b <;> dsimp [(· ∘ ·)]; try rw [inv]; rfl
exact ⟨(0 ::ₒ t) ∘ g, by rwa [this]⟩
· have : v ⊗ t ∘ f = (v ⊗ t) ∘ (inl ⊗ inr ∘ f) := funext fun s => by cases' s with a b <;> rfl
exact ⟨t ∘ f, by rwa [this]⟩
theorem inject_dummies (f : β → γ) (g : γ → Option β) (inv : ∀ x, g (f x) = some x)
(p : Poly (α ⊕ β)) (h : ∀ v, S v ↔ ∃ t, p (v ⊗ t) = 0) :
∃ q : Poly (α ⊕ γ), ∀ v, S v ↔ ∃ t, q (v ⊗ t) = 0 :=
⟨p.map (inl ⊗ inr ∘ f), fun v => (h v).trans <| inject_dummies_lem f g inv _ _⟩
variable (β)
theorem reindex_dioph (f : α → β) : Dioph S → Dioph {v | v ∘ f ∈ S}
| ⟨γ, p, pe⟩ => ⟨γ, p.map (inl ∘ f ⊗ inr), fun v =>
(pe _).trans <|
exists_congr fun t =>
suffices v ∘ f ⊗ t = (v ⊗ t) ∘ (inl ∘ f ⊗ inr) by simp [this]
funext fun s => by cases' s with a b <;> rfl⟩
variable {β}
theorem DiophList.forall (l : List (Set <| α → ℕ)) (d : l.Forall Dioph) :
Dioph {v | l.Forall fun S : Set (α → ℕ) => v ∈ S} := by
suffices ∃ (β : _) (pl : List (Poly (α ⊕ β))), ∀ v, List.Forall (fun S : Set _ => S v) l ↔
∃ t, List.Forall (fun p : Poly (α ⊕ β) => p (v ⊗ t) = 0) pl
from
let ⟨β, pl, h⟩ := this
⟨β, Poly.sumsq pl, fun v => (h v).trans <| exists_congr fun t => (Poly.sumsq_eq_zero _ _).symm⟩
induction' l with S l IH
· exact ⟨ULift Empty, [], fun _ => by simp⟩
simp? at d says simp only [List.forall_cons] at d
exact
let ⟨⟨β, p, pe⟩, dl⟩ := d
let ⟨γ, pl, ple⟩ := IH dl
⟨β ⊕ γ, p.map (inl ⊗ inr ∘ inl)::pl.map fun q => q.map (inl ⊗ inr ∘ inr),
fun v => by
simp; exact
Iff.trans (and_congr (pe v) (ple v))
⟨fun ⟨⟨m, hm⟩, ⟨n, hn⟩⟩ =>
⟨m ⊗ n, by
rw [show (v ⊗ m ⊗ n) ∘ (inl ⊗ inr ∘ inl) = v ⊗ m from
funext fun s => by cases' s with a b <;> rfl]; exact hm, by
refine List.Forall.imp (fun q hq => ?_) hn; dsimp [Function.comp_def]
rw [show
(fun x : α ⊕ γ => (v ⊗ m ⊗ n) ((inl ⊗ fun x : γ => inr (inr x)) x)) = v ⊗ n
from funext fun s => by cases' s with a b <;> rfl]; exact hq⟩,
fun ⟨t, hl, hr⟩ =>
⟨⟨t ∘ inl, by
rwa [show (v ⊗ t) ∘ (inl ⊗ inr ∘ inl) = v ⊗ t ∘ inl from
funext fun s => by cases' s with a b <;> rfl] at hl⟩,
⟨t ∘ inr, by
refine List.Forall.imp (fun q hq => ?_) hr; dsimp [Function.comp_def] at hq
rwa [show
(fun x : α ⊕ γ => (v ⊗ t) ((inl ⊗ fun x : γ => inr (inr x)) x)) =
v ⊗ t ∘ inr
from funext fun s => by cases' s with a b <;> rfl] at hq ⟩⟩⟩⟩
theorem inter (d : Dioph S) (d' : Dioph S') : Dioph (S ∩ S') := DiophList.forall [S, S'] ⟨d, d'⟩
theorem union : ∀ (_ : Dioph S) (_ : Dioph S'), Dioph (S ∪ S')
| ⟨β, p, pe⟩, ⟨γ, q, qe⟩ =>
⟨β ⊕ γ, p.map (inl ⊗ inr ∘ inl) * q.map (inl ⊗ inr ∘ inr), fun v => by
refine
Iff.trans (or_congr ((pe v).trans ?_) ((qe v).trans ?_))
(exists_or.symm.trans
(exists_congr fun t =>
(@mul_eq_zero _ _ _ (p ((v ⊗ t) ∘ (inl ⊗ inr ∘ inl)))
(q ((v ⊗ t) ∘ (inl ⊗ inr ∘ inr)))).symm))
-- Porting note: putting everything on the same line fails
· refine inject_dummies_lem _ ?_ ?_ _ _
· exact some ⊗ fun _ => none
· exact fun _ => by simp only [elim_inl]
-- Porting note: putting everything on the same line fails
· refine inject_dummies_lem _ ?_ ?_ _ _
· exact (fun _ => none) ⊗ some
· exact fun _ => by simp only [elim_inr]⟩
/-- A partial function is Diophantine if its graph is Diophantine. -/
def DiophPFun (f : (α → ℕ) →. ℕ) : Prop :=
Dioph {v : Option α → ℕ | f.graph (v ∘ some, v none)}
/-- A function is Diophantine if its graph is Diophantine. -/
def DiophFn (f : (α → ℕ) → ℕ) : Prop :=
Dioph {v : Option α → ℕ | f (v ∘ some) = v none}
theorem reindex_diophFn {f : (α → ℕ) → ℕ} (g : α → β) (d : DiophFn f) :
DiophFn fun v => f (v ∘ g) := by convert reindex_dioph (Option β) (Option.map g) d
theorem ex_dioph {S : Set (α ⊕ β → ℕ)} : Dioph S → Dioph {v | ∃ x, v ⊗ x ∈ S}
| ⟨γ, p, pe⟩ =>
⟨β ⊕ γ, p.map ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr), fun v =>
⟨fun ⟨x, hx⟩ =>
let ⟨t, ht⟩ := (pe _).1 hx
⟨x ⊗ t, by
simp; rw [show (v ⊗ x ⊗ t) ∘ ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr) = (v ⊗ x) ⊗ t from
funext fun s => by cases' s with a b <;> try { cases a <;> rfl }; rfl]
exact ht⟩,
fun ⟨t, ht⟩ =>
⟨t ∘ inl,
(pe _).2
⟨t ∘ inr, by
simp only [Poly.map_apply] at ht
rwa [show (v ⊗ t) ∘ ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr) = (v ⊗ t ∘ inl) ⊗ t ∘ inr from
funext fun s => by cases' s with a b <;> try { cases a <;> rfl }; rfl] at ht⟩⟩⟩⟩
theorem ex1_dioph {S : Set (Option α → ℕ)} : Dioph S → Dioph {v | ∃ x, x ::ₒ v ∈ S}
| ⟨β, p, pe⟩ =>
⟨Option β, p.map (inr none ::ₒ inl ⊗ inr ∘ some), fun v =>
⟨fun ⟨x, hx⟩ =>
let ⟨t, ht⟩ := (pe _).1 hx
⟨x ::ₒ t, by
simp only [Poly.map_apply]
rw [show (v ⊗ x ::ₒ t) ∘ (inr none ::ₒ inl ⊗ inr ∘ some) = x ::ₒ v ⊗ t from
funext fun s => by cases' s with a b <;> try { cases a <;> rfl}; rfl]
exact ht⟩,
fun ⟨t, ht⟩ =>
⟨t none,
(pe _).2
⟨t ∘ some, by
simp only [Poly.map_apply] at ht
rwa [show (v ⊗ t) ∘ (inr none ::ₒ inl ⊗ inr ∘ some) = t none ::ₒ v ⊗ t ∘ some from
funext fun s => by cases' s with a b <;> try { cases a <;> rfl }; rfl] at ht ⟩⟩⟩⟩
theorem dom_dioph {f : (α → ℕ) →. ℕ} (d : DiophPFun f) : Dioph f.Dom :=
cast (congr_arg Dioph <| Set.ext fun _ => (PFun.dom_iff_graph _ _).symm) (ex1_dioph d)
theorem diophFn_iff_pFun (f : (α → ℕ) → ℕ) : DiophFn f = @DiophPFun α f := by
refine congr_arg Dioph (Set.ext fun v => ?_); exact PFun.lift_graph.symm
theorem abs_poly_dioph (p : Poly α) : DiophFn fun v => (p v).natAbs :=
of_no_dummies _ ((p.map some - Poly.proj none) * (p.map some + Poly.proj none))
fun v => (by dsimp; exact Int.eq_natAbs_iff_mul_eq_zero)
theorem proj_dioph (i : α) : DiophFn fun v => v i :=
abs_poly_dioph (Poly.proj i)
theorem diophPFun_comp1 {S : Set (Option α → ℕ)} (d : Dioph S) {f} (df : DiophPFun f) :
Dioph {v : α → ℕ | ∃ h : f.Dom v, f.fn v h ::ₒ v ∈ S} :=
ext (ex1_dioph (d.inter df)) fun v =>
⟨fun ⟨x, hS, (h : Exists _)⟩ => by
rw [show (x ::ₒ v) ∘ some = v from funext fun s => rfl] at h
cases' h with hf h; refine ⟨hf, ?_⟩; rw [PFun.fn, h]; exact hS,
fun ⟨x, hS⟩ =>
⟨f.fn v x, hS, show Exists _ by
rw [show (f.fn v x ::ₒ v) ∘ some = v from funext fun s => rfl]; exact ⟨x, rfl⟩⟩⟩
theorem diophFn_comp1 {S : Set (Option α → ℕ)} (d : Dioph S) {f : (α → ℕ) → ℕ} (df : DiophFn f) :
Dioph {v | f v ::ₒ v ∈ S} :=
ext (diophPFun_comp1 d <| cast (diophFn_iff_pFun f) df)
fun _ => ⟨fun ⟨_, h⟩ => h, fun h => ⟨trivial, h⟩⟩
end
section
variable {α β : Type} {n : ℕ}
open Vector3
open scoped Vector3
-- Porting note: Fails because declaration is in an imported module
-- attribute [local reducible] Vector3
theorem diophFn_vec_comp1 {S : Set (Vector3 ℕ (succ n))} (d : Dioph S) {f : Vector3 ℕ n → ℕ}
(df : DiophFn f) : Dioph {v : Vector3 ℕ n | (f v::v) ∈ S} :=
Dioph.ext (diophFn_comp1 (reindex_dioph _ (none::some) d) df) (fun v => by
dsimp
-- Porting note: `congr` use to be enough here
refine iff_of_eq (congrFun (congrArg Membership.mem ?_) S)
ext x; cases x <;> rfl)
theorem vec_ex1_dioph (n) {S : Set (Vector3 ℕ (succ n))} (d : Dioph S) :
Dioph {v : Fin2 n → ℕ | ∃ x, (x::v) ∈ S} :=
ext (ex1_dioph <| reindex_dioph _ (none::some) d) fun v =>
exists_congr fun x => by
dsimp
rw [show Option.elim' x v ∘ cons none some = x::v from
funext fun s => by cases' s with a b <;> rfl]
theorem diophFn_vec (f : Vector3 ℕ n → ℕ) : DiophFn f ↔ Dioph {v | f (v ∘ fs) = v fz} :=
⟨reindex_dioph _ (fz ::ₒ fs), reindex_dioph _ (none::some)⟩
theorem diophPFun_vec (f : Vector3 ℕ n →. ℕ) : DiophPFun f ↔ Dioph {v | f.graph (v ∘ fs, v fz)} :=
⟨reindex_dioph _ (fz ::ₒ fs), reindex_dioph _ (none::some)⟩
theorem diophFn_compn :
∀ {n} {S : Set (α ⊕ (Fin2 n) → ℕ)} (_ : Dioph S) {f : Vector3 ((α → ℕ) → ℕ) n}
(_ : VectorAllP DiophFn f), Dioph {v : α → ℕ | (v ⊗ fun i => f i v) ∈ S}
| 0, S, d, f => fun _ =>
ext (reindex_dioph _ (id ⊗ Fin2.elim0) d) fun v => by
dsimp
-- Porting note: `congr` use to be enough here
refine iff_of_eq (congrFun (congrArg Membership.mem ?_) S)
ext x; obtain _ | _ | _ := x; rfl
| succ n, S, d, f =>
f.consElim fun f fl => by
simp only [vectorAllP_cons, and_imp]
exact fun df dfl =>
have : Dioph {v | (v ∘ inl ⊗ f (v ∘ inl)::v ∘ inr) ∈ S} :=
ext (diophFn_comp1 (reindex_dioph _ (some ∘ inl ⊗ none::some ∘ inr) d) <|
reindex_diophFn inl df)
fun v => by
dsimp
-- Porting note: `congr` use to be enough here
refine iff_of_eq (congrFun (congrArg Membership.mem ?_) S)
ext x; obtain _ | _ | _ := x <;> rfl
have : Dioph {v | (v ⊗ f v::fun i : Fin2 n => fl i v) ∈ S} :=
@diophFn_compn n (fun v => S (v ∘ inl ⊗ f (v ∘ inl)::v ∘ inr)) this _ dfl
ext this fun v => by
dsimp
-- Porting note: `congr` use to be enough here
refine iff_of_eq (congrFun (congrArg Membership.mem ?_) S)
ext x; obtain _ | _ | _ := x <;> rfl
theorem dioph_comp {S : Set (Vector3 ℕ n)} (d : Dioph S) (f : Vector3 ((α → ℕ) → ℕ) n)
(df : VectorAllP DiophFn f) : Dioph {v | (fun i => f i v) ∈ S} :=
diophFn_compn (reindex_dioph _ inr d) df
theorem diophFn_comp {f : Vector3 ℕ n → ℕ} (df : DiophFn f) (g : Vector3 ((α → ℕ) → ℕ) n)
(dg : VectorAllP DiophFn g) : DiophFn fun v => f fun i => g i v :=
dioph_comp ((diophFn_vec _).1 df) ((fun v => v none)::fun i v => g i (v ∘ some)) <| by
simp only [vectorAllP_cons]
exact ⟨proj_dioph none, (vectorAllP_iff_forall _ _).2 fun i =>
reindex_diophFn _ <| (vectorAllP_iff_forall _ _).1 dg _⟩
scoped notation:35 x " D∧ " y => Dioph.inter x y
scoped notation:35 x " D∨ " y => Dioph.union x y
scoped notation:30 "D∃" => Dioph.vec_ex1_dioph
scoped prefix:arg "&" => Fin2.ofNat'
theorem proj_dioph_of_nat {n : ℕ} (m : ℕ) [IsLT m n] : DiophFn fun v : Vector3 ℕ n => v &m :=
proj_dioph &m
scoped prefix:100 "D&" => Dioph.proj_dioph_of_nat
theorem const_dioph (n : ℕ) : DiophFn (const (α → ℕ) n) :=
abs_poly_dioph (Poly.const n)
scoped prefix:100 "D." => Dioph.const_dioph
variable {f g : (α → ℕ) → ℕ} (df : DiophFn f) (dg : DiophFn g)
theorem dioph_comp2 {S : ℕ → ℕ → Prop} (d : Dioph fun v : Vector3 ℕ 2 => S (v &0) (v &1)) :
Dioph fun v => S (f v) (g v) := dioph_comp d [f, g] ⟨df, dg⟩
theorem diophFn_comp2 {h : ℕ → ℕ → ℕ} (d : DiophFn fun v : Vector3 ℕ 2 => h (v &0) (v &1)) :
DiophFn fun v => h (f v) (g v) := diophFn_comp d [f, g] ⟨df, dg⟩
theorem eq_dioph : Dioph fun v => f v = g v :=
dioph_comp2 df dg <|
of_no_dummies _ (Poly.proj &0 - Poly.proj &1) fun v => by
exact Int.ofNat_inj.symm.trans ⟨@sub_eq_zero_of_eq ℤ _ (v &0) (v &1), eq_of_sub_eq_zero⟩
scoped infixl:50 " D= " => Dioph.eq_dioph
theorem add_dioph : DiophFn fun v => f v + g v :=
diophFn_comp2 df dg <| abs_poly_dioph (@Poly.proj (Fin2 2) &0 + @Poly.proj (Fin2 2) &1)
scoped infixl:80 " D+ " => Dioph.add_dioph
theorem mul_dioph : DiophFn fun v => f v * g v :=
diophFn_comp2 df dg <| abs_poly_dioph (@Poly.proj (Fin2 2) &0 * @Poly.proj (Fin2 2) &1)
scoped infixl:90 " D* " => Dioph.mul_dioph
theorem le_dioph : Dioph {v | f v ≤ g v} :=
dioph_comp2 df dg <|
ext ((D∃) 2 <| D&1 D+ D&0 D= D&2) fun _ => ⟨fun ⟨_, hx⟩ => le.intro hx, le.dest⟩
scoped infixl:50 " D≤ " => Dioph.le_dioph
theorem lt_dioph : Dioph {v | f v < g v} := df D+ D.1 D≤ dg
scoped infixl:50 " D< " => Dioph.lt_dioph
theorem ne_dioph : Dioph {v | f v ≠ g v} :=
ext (df D< dg D∨ dg D< df) fun v => by dsimp; exact lt_or_lt_iff_ne (α := ℕ)
scoped infixl:50 " D≠ " => Dioph.ne_dioph
theorem sub_dioph : DiophFn fun v => f v - g v :=
diophFn_comp2 df dg <|
(diophFn_vec _).2 <|
ext (D&1 D= D&0 D+ D&2 D∨ D&1 D≤ D&2 D∧ D&0 D= D.0) <|
(vectorAll_iff_forall _).1 fun x y z =>
show y = x + z ∨ y ≤ z ∧ x = 0 ↔ y - z = x from
⟨fun o => by
rcases o with (ae | ⟨yz, x0⟩)
· rw [ae, add_tsub_cancel_right]
· rw [x0, tsub_eq_zero_iff_le.mpr yz], by
rintro rfl
rcases le_total y z with yz | zy
· exact Or.inr ⟨yz, tsub_eq_zero_iff_le.mpr yz⟩
· exact Or.inl (tsub_add_cancel_of_le zy).symm⟩
scoped infixl:80 " D- " => Dioph.sub_dioph
theorem dvd_dioph : Dioph fun v => f v ∣ g v :=
dioph_comp ((D∃) 2 <| D&2 D= D&1 D* D&0) [f, g] ⟨df, dg⟩
scoped infixl:50 " D∣ " => Dioph.dvd_dioph
theorem mod_dioph : DiophFn fun v => f v % g v :=
have : Dioph fun v : Vector3 ℕ 3 => (v &2 = 0 ∨ v &0 < v &2) ∧ ∃ x : ℕ, v &0 + v &2 * x = v &1 :=
(D&2 D= D.0 D∨ D&0 D< D&2) D∧ (D∃) 3 <| D&1 D+ D&3 D* D&0 D= D&2
diophFn_comp2 df dg <|
(diophFn_vec _).2 <|
ext this <|
(vectorAll_iff_forall _).1 fun z x y =>
show ((y = 0 ∨ z < y) ∧ ∃ c, z + y * c = x) ↔ x % y = z from
⟨fun ⟨h, c, hc⟩ => by
rw [← hc]; simp; cases' h with x0 hl
· rw [x0, mod_zero]
exact mod_eq_of_lt hl, fun e => by
rw [← e]
exact ⟨or_iff_not_imp_left.2 fun h => mod_lt _ (Nat.pos_of_ne_zero h), x / y,
mod_add_div _ _⟩⟩
scoped infixl:80 " D% " => Dioph.mod_dioph
theorem modEq_dioph {h : (α → ℕ) → ℕ} (dh : DiophFn h) : Dioph fun v => f v ≡ g v [MOD h v] :=
df D% dh D= dg D% dh
scoped notation " D≡ " => Dioph.modEq_dioph
theorem div_dioph : DiophFn fun v => f v / g v :=
have :
Dioph fun v : Vector3 ℕ 3 =>
v &2 = 0 ∧ v &0 = 0 ∨ v &0 * v &2 ≤ v &1 ∧ v &1 < (v &0 + 1) * v &2 :=
(D&2 D= D.0 D∧ D&0 D= D.0) D∨ D&0 D* D&2 D≤ D&1 D∧ D&1 D< (D&0 D+ D.1) D* D&2
diophFn_comp2 df dg <|
(diophFn_vec _).2 <|
ext this <|
(vectorAll_iff_forall _).1 fun z x y =>
show y = 0 ∧ z = 0 ∨ z * y ≤ x ∧ x < (z + 1) * y ↔ x / y = z by
refine Iff.trans ?_ eq_comm
exact y.eq_zero_or_pos.elim
(fun y0 => by
rw [y0, Nat.div_zero]
exact ⟨fun o => (o.resolve_right fun ⟨_, h2⟩ => Nat.not_lt_zero _ h2).right,
fun z0 => Or.inl ⟨rfl, z0⟩⟩)
fun ypos =>
Iff.trans ⟨fun o => o.resolve_left fun ⟨h1, _⟩ => Nat.ne_of_gt ypos h1, Or.inr⟩
(le_antisymm_iff.trans <| and_congr (Nat.le_div_iff_mul_le ypos) <|
Iff.trans ⟨lt_succ_of_le, le_of_lt_succ⟩ (div_lt_iff_lt_mul ypos)).symm
scoped infixl:80 " D/ " => Dioph.div_dioph
open Pell
theorem pell_dioph :
Dioph fun v : Vector3 ℕ 4 => ∃ h : 1 < v &0, xn h (v &1) = v &2 ∧ yn h (v &1) = v &3 := by
have proof := D.1 D< D&0 D∧ D&1 D≤ D&3 D∧
((D&2 D= D.1 D∧ D&3 D= D.0) D∨
((D∃) 4 <| (D∃) 5 <| (D∃) 6 <| (D∃) 7 <| (D∃) 8 <|
D&7 D* D&7 D- (D&5 D* D&5 D- D.1) D* D&8 D* D&8 D= D.1 D∧
D&4 D* D&4 D- (D&5 D* D&5 D- D.1) D* D&3 D* D&3 D= D.1 D∧
D&2 D* D&2 D- (D&0 D* D&0 D- D.1) D* D&1 D* D&1 D= D.1 D∧
D.1 D< D&0 D∧ (D≡ (D&0) (D.1) (D.4 D* D&8)) D∧ (D≡ (D&0) (D&5) (D&4)) D∧
D.0 D< D&3 D∧ D&8 D* D&8 D∣ D&3 D∧
(D≡ (D&2) (D&7) (D&4)) D∧
(D≡ (D&1) (D&6) (D.4 D* (D&8)))))
-- Porting note: copying directly `proof` in the proof of the following have fails
have : Dioph {v : Vector3 ℕ 4 |
1 < v &0 ∧ v &1 ≤ v &3 ∧
(v &2 = 1 ∧ v &3 = 0 ∨
∃ u w s t b : ℕ,
v &2 * v &2 - (v &0 * v &0 - 1) * v &3 * v &3 = 1 ∧
u * u - (v &0 * v &0 - 1) * w * w = 1 ∧
s * s - (b * b - 1) * t * t = 1 ∧
1 < b ∧ b ≡ 1 [MOD 4 * v &3] ∧ b ≡ v &0 [MOD u] ∧
0 < w ∧ v &3 * v &3 ∣ w ∧
s ≡ v &2 [MOD u] ∧
t ≡ v &1 [MOD 4 * v &3])} := by
exact proof
exact Dioph.ext this fun v => matiyasevic.symm
theorem xn_dioph : DiophPFun fun v : Vector3 ℕ 2 => ⟨1 < v &0, fun h => xn h (v &1)⟩ :=
have : Dioph fun v : Vector3 ℕ 3 => ∃ y, ∃ h : 1 < v &1, xn h (v &2) = v &0 ∧ yn h (v &2) = y :=
let D_pell := pell_dioph.reindex_dioph (Fin2 4) [&2, &3, &1, &0]
(D∃) 3 D_pell
(diophPFun_vec _).2 <|
Dioph.ext this fun _ => ⟨fun ⟨_, h, xe, _⟩ => ⟨h, xe⟩, fun ⟨h, xe⟩ => ⟨_, h, xe, rfl⟩⟩
/-- A version of **Matiyasevic's theorem** -/
theorem pow_dioph : DiophFn fun v => f v ^ g v := by
have proof :=
let D_pell := pell_dioph.reindex_dioph (Fin2 9) [&4, &8, &1, &0]
(D&2 D= D.0 D∧ D&0 D= D.1) D∨ (D.0 D< D&2 D∧
((D&1 D= D.0 D∧ D&0 D= D.0) D∨ (D.0 D< D&1 D∧
((D∃) 3 <| (D∃) 4 <| (D∃) 5 <| (D∃) 6 <| (D∃) 7 <| (D∃) 8 <| D_pell D∧
(D≡ (D&1) (D&0 D* (D&4 D- D&7) D+ D&6) (D&3)) D∧
D.2 D* D&4 D* D&7 D= D&3 D+ (D&7 D* D&7 D+ D.1) D∧
D&6 D< D&3 D∧ D&7 D≤ D&5 D∧ D&8 D≤ D&5 D∧
D&4 D* D&4 D- ((D&5 D+ D.1) D* (D&5 D+ D.1) D- D.1) D* (D&5 D* D&2) D* (D&5 D* D&2) D= D.1))))
-- Porting note: copying directly `proof` in the proof of the following have fails
have : Dioph {v : Vector3 ℕ 3 |
v &2 = 0 ∧ v &0 = 1 ∨ 0 < v &2 ∧
(v &1 = 0 ∧ v &0 = 0 ∨ 0 < v &1 ∧
∃ w a t z x y : ℕ,
(∃ a1 : 1 < a, xn a1 (v &2) = x ∧ yn a1 (v &2) = y) ∧
x ≡ y * (a - v &1) + v &0 [MOD t] ∧
2 * a * v &1 = t + (v &1 * v &1 + 1) ∧
v &0 < t ∧ v &1 ≤ w ∧ v &2 ≤ w ∧
a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)} := by
exact proof
exact diophFn_comp2 df dg <| (diophFn_vec _).2 <| Dioph.ext this fun v => Iff.symm <|
eq_pow_of_pell.trans <| or_congr Iff.rfl <| and_congr Iff.rfl <| or_congr Iff.rfl <|
and_congr Iff.rfl <|
⟨fun ⟨w, a, t, z, a1, h⟩ => ⟨w, a, t, z, _, _, ⟨a1, rfl, rfl⟩, h⟩,
fun ⟨w, a, t, z, _, _, ⟨a1, rfl, rfl⟩, h⟩ => ⟨w, a, t, z, a1, h⟩⟩
end
end Dioph
|
NumberTheory\DiophantineApproximation.lean | /-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Geißer, Michael Stoll
-/
import Mathlib.Algebra.ContinuedFractions.Computation.ApproximationCorollaries
import Mathlib.Algebra.ContinuedFractions.Computation.Translations
import Mathlib.Data.Real.Irrational
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.Tactic.Basic
/-!
# Diophantine Approximation
The first part of this file gives proofs of various versions of
**Dirichlet's approximation theorem** and its important consequence that when $\xi$ is an
irrational real number, then there are infinitely many rationals $x/y$ (in lowest terms)
such that
$$\left|\xi - \frac{x}{y}\right| < \frac{1}{y^2} \,.$$
The proof is based on the pigeonhole principle.
The second part of the file gives a proof of **Legendre's Theorem** on rational approximation,
which states that if $\xi$ is a real number and $x/y$ is a rational number such that
$$\left|\xi - \frac{x}{y}\right| < \frac{1}{2y^2} \,,$$
then $x/y$ must be a convergent of the continued fraction expansion of $\xi$.
## Main statements
The main results are three variants of Dirichlet's approximation theorem:
* `Real.exists_int_int_abs_mul_sub_le`, which states that for all real `ξ` and natural `0 < n`,
there are integers `j` and `k` with `0 < k ≤ n` and `|k*ξ - j| ≤ 1/(n+1)`,
* `Real.exists_nat_abs_mul_sub_round_le`, which replaces `j` by `round(k*ξ)` and uses
a natural number `k`,
* `Real.exists_rat_abs_sub_le_and_den_le`, which says that there is a rational number `q`
satisfying `|ξ - q| ≤ 1/((n+1)*q.den)` and `q.den ≤ n`,
and
* `Real.infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational`, which states that
for irrational `ξ`, the set `{q : ℚ | |ξ - q| < 1/q.den^2}` is infinite.
We also show a converse,
* `Rat.finite_rat_abs_sub_lt_one_div_den_sq`, which states that the set above is finite
when `ξ` is a rational number.
Both statements are combined to give an equivalence,
`Real.infinite_rat_abs_sub_lt_one_div_den_sq_iff_irrational`.
There are two versions of Legendre's Theorem. One, `Real.exists_rat_eq_convergent`, uses
`Real.convergent`, a simple recursive definition of the convergents that is also defined
in this file, whereas the other, `Real.exists_convs_eq_rat`, uses
`GenContFract.convs` of `GenContFract.of ξ`.
## Implementation notes
We use the namespace `Real` for the results on real numbers and `Rat` for the results
on rational numbers. We introduce a secondary namespace `real.contfrac_legendre`
to separate off a definition and some technical auxiliary lemmas used in the proof
of Legendre's Theorem. For remarks on the proof of Legendre's Theorem, see below.
## References
<https://en.wikipedia.org/wiki/Dirichlet%27s_approximation_theorem>
<https://de.wikipedia.org/wiki/Kettenbruch> (The German Wikipedia page on continued
fractions is much more extensive than the English one.)
## Tags
Diophantine approximation, Dirichlet's approximation theorem, continued fraction
-/
namespace Real
section Dirichlet
/-!
### Dirichlet's approximation theorem
We show that for any real number `ξ` and positive natural `n`, there is a fraction `q`
such that `q.den ≤ n` and `|ξ - q| ≤ 1/((n+1)*q.den)`.
-/
open Finset Int
/-- *Dirichlet's approximation theorem:*
For any real number `ξ` and positive natural `n`, there are integers `j` and `k`,
with `0 < k ≤ n` and `|k*ξ - j| ≤ 1/(n+1)`.
See also `Real.exists_nat_abs_mul_sub_round_le`. -/
theorem exists_int_int_abs_mul_sub_le (ξ : ℝ) {n : ℕ} (n_pos : 0 < n) :
∃ j k : ℤ, 0 < k ∧ k ≤ n ∧ |↑k * ξ - j| ≤ 1 / (n + 1) := by
let f : ℤ → ℤ := fun m => ⌊fract (ξ * m) * (n + 1)⌋
have hn : 0 < (n : ℝ) + 1 := mod_cast Nat.succ_pos _
have hfu := fun m : ℤ => mul_lt_of_lt_one_left hn <| fract_lt_one (ξ * ↑m)
conv in |_| ≤ _ => rw [mul_comm, le_div_iff hn, ← abs_of_pos hn, ← abs_mul]
let D := Icc (0 : ℤ) n
by_cases H : ∃ m ∈ D, f m = n
· obtain ⟨m, hm, hf⟩ := H
have hf' : ((n : ℤ) : ℝ) ≤ fract (ξ * m) * (n + 1) := hf ▸ floor_le (fract (ξ * m) * (n + 1))
have hm₀ : 0 < m := by
have hf₀ : f 0 = 0 := by
-- Porting note: was
-- simp only [floor_eq_zero_iff, algebraMap.coe_zero, mul_zero, fract_zero,
-- zero_mul, Set.left_mem_Ico, zero_lt_one]
simp only [f, cast_zero, mul_zero, fract_zero, zero_mul, floor_zero]
refine Ne.lt_of_le (fun h => n_pos.ne ?_) (mem_Icc.mp hm).1
exact mod_cast hf₀.symm.trans (h.symm ▸ hf : f 0 = n)
refine ⟨⌊ξ * m⌋ + 1, m, hm₀, (mem_Icc.mp hm).2, ?_⟩
rw [cast_add, ← sub_sub, sub_mul, cast_one, one_mul, abs_le]
refine
⟨le_sub_iff_add_le.mpr ?_, sub_le_iff_le_add.mpr <| le_of_lt <| (hfu m).trans <| lt_one_add _⟩
simpa only [neg_add_cancel_comm_assoc] using hf'
· -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5127): added `not_and`
simp_rw [not_exists, not_and] at H
have hD : (Ico (0 : ℤ) n).card < D.card := by rw [card_Icc, card_Ico]; exact lt_add_one n
have hfu' : ∀ m, f m ≤ n := fun m => lt_add_one_iff.mp (floor_lt.mpr (mod_cast hfu m))
have hwd : ∀ m : ℤ, m ∈ D → f m ∈ Ico (0 : ℤ) n := fun x hx =>
mem_Ico.mpr
⟨floor_nonneg.mpr (mul_nonneg (fract_nonneg (ξ * x)) hn.le), Ne.lt_of_le (H x hx) (hfu' x)⟩
obtain ⟨x, hx, y, hy, x_lt_y, hxy⟩ : ∃ x ∈ D, ∃ y ∈ D, x < y ∧ f x = f y := by
obtain ⟨x, hx, y, hy, x_ne_y, hxy⟩ := exists_ne_map_eq_of_card_lt_of_maps_to hD hwd
rcases lt_trichotomy x y with (h | h | h)
exacts [⟨x, hx, y, hy, h, hxy⟩, False.elim (x_ne_y h), ⟨y, hy, x, hx, h, hxy.symm⟩]
refine
⟨⌊ξ * y⌋ - ⌊ξ * x⌋, y - x, sub_pos_of_lt x_lt_y,
sub_le_iff_le_add.mpr <| le_add_of_le_of_nonneg (mem_Icc.mp hy).2 (mem_Icc.mp hx).1, ?_⟩
convert_to |fract (ξ * y) * (n + 1) - fract (ξ * x) * (n + 1)| ≤ 1
· congr; push_cast; simp only [fract]; ring
exact (abs_sub_lt_one_of_floor_eq_floor hxy.symm).le
/-- *Dirichlet's approximation theorem:*
For any real number `ξ` and positive natural `n`, there is a natural number `k`,
with `0 < k ≤ n` such that `|k*ξ - round(k*ξ)| ≤ 1/(n+1)`.
-/
theorem exists_nat_abs_mul_sub_round_le (ξ : ℝ) {n : ℕ} (n_pos : 0 < n) :
∃ k : ℕ, 0 < k ∧ k ≤ n ∧ |↑k * ξ - round (↑k * ξ)| ≤ 1 / (n + 1) := by
obtain ⟨j, k, hk₀, hk₁, h⟩ := exists_int_int_abs_mul_sub_le ξ n_pos
have hk := toNat_of_nonneg hk₀.le
rw [← hk] at hk₀ hk₁ h
exact ⟨k.toNat, natCast_pos.mp hk₀, Nat.cast_le.mp hk₁, (round_le (↑k.toNat * ξ) j).trans h⟩
/-- *Dirichlet's approximation theorem:*
For any real number `ξ` and positive natural `n`, there is a fraction `q`
such that `q.den ≤ n` and `|ξ - q| ≤ 1/((n+1)*q.den)`.
See also `AddCircle.exists_norm_nsmul_le`. -/
theorem exists_rat_abs_sub_le_and_den_le (ξ : ℝ) {n : ℕ} (n_pos : 0 < n) :
∃ q : ℚ, |ξ - q| ≤ 1 / ((n + 1) * q.den) ∧ q.den ≤ n := by
obtain ⟨j, k, hk₀, hk₁, h⟩ := exists_int_int_abs_mul_sub_le ξ n_pos
have hk₀' : (0 : ℝ) < k := Int.cast_pos.mpr hk₀
have hden : ((j / k : ℚ).den : ℤ) ≤ k := by
convert le_of_dvd hk₀ (Rat.den_dvd j k)
exact Rat.intCast_div_eq_divInt _ _
refine ⟨j / k, ?_, Nat.cast_le.mp (hden.trans hk₁)⟩
rw [← div_div, le_div_iff (Nat.cast_pos.mpr <| Rat.pos _ : (0 : ℝ) < _)]
refine (mul_le_mul_of_nonneg_left (Int.cast_le.mpr hden : _ ≤ (k : ℝ)) (abs_nonneg _)).trans ?_
rwa [← abs_of_pos hk₀', Rat.cast_div, Rat.cast_intCast, Rat.cast_intCast, ← abs_mul, sub_mul,
div_mul_cancel₀ _ hk₀'.ne', mul_comm]
end Dirichlet
section RatApprox
/-!
### Infinitely many good approximations to irrational numbers
We show that an irrational real number `ξ` has infinitely many "good rational approximations",
i.e., fractions `x/y` in lowest terms such that `|ξ - x/y| < 1/y^2`.
-/
open Set
/-- Given any rational approximation `q` to the irrational real number `ξ`, there is
a good rational approximation `q'` such that `|ξ - q'| < |ξ - q|`. -/
theorem exists_rat_abs_sub_lt_and_lt_of_irrational {ξ : ℝ} (hξ : Irrational ξ) (q : ℚ) :
∃ q' : ℚ, |ξ - q'| < 1 / (q'.den : ℝ) ^ 2 ∧ |ξ - q'| < |ξ - q| := by
have h := abs_pos.mpr (sub_ne_zero.mpr <| Irrational.ne_rat hξ q)
obtain ⟨m, hm⟩ := exists_nat_gt (1 / |ξ - q|)
have m_pos : (0 : ℝ) < m := (one_div_pos.mpr h).trans hm
obtain ⟨q', hbd, hden⟩ := exists_rat_abs_sub_le_and_den_le ξ (Nat.cast_pos.mp m_pos)
have den_pos : (0 : ℝ) < q'.den := Nat.cast_pos.mpr q'.pos
have md_pos := mul_pos (add_pos m_pos zero_lt_one) den_pos
refine
⟨q', lt_of_le_of_lt hbd ?_,
lt_of_le_of_lt hbd <|
(one_div_lt md_pos h).mpr <|
hm.trans <|
lt_of_lt_of_le (lt_add_one _) <|
(le_mul_iff_one_le_right <| add_pos m_pos zero_lt_one).mpr <|
mod_cast (q'.pos : 1 ≤ q'.den)⟩
rw [sq, one_div_lt_one_div md_pos (mul_pos den_pos den_pos), mul_lt_mul_right den_pos]
exact lt_add_of_le_of_pos (Nat.cast_le.mpr hden) zero_lt_one
/-- If `ξ` is an irrational real number, then there are infinitely many good
rational approximations to `ξ`. -/
theorem infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational {ξ : ℝ} (hξ : Irrational ξ) :
{q : ℚ | |ξ - q| < 1 / (q.den : ℝ) ^ 2}.Infinite := by
refine Or.resolve_left (Set.finite_or_infinite _) fun h => ?_
obtain ⟨q, _, hq⟩ :=
exists_min_image {q : ℚ | |ξ - q| < 1 / (q.den : ℝ) ^ 2} (fun q => |ξ - q|) h
⟨⌊ξ⌋, by simp [abs_of_nonneg, Int.fract_lt_one]⟩
obtain ⟨q', hmem, hbetter⟩ := exists_rat_abs_sub_lt_and_lt_of_irrational hξ q
exact lt_irrefl _ (lt_of_le_of_lt (hq q' hmem) hbetter)
end RatApprox
end Real
namespace Rat
/-!
### Finitely many good approximations to rational numbers
We now show that a rational number `ξ` has only finitely many good rational
approximations.
-/
open Set
/-- If `ξ` is rational, then the good rational approximations to `ξ` have bounded
numerator and denominator. -/
theorem den_le_and_le_num_le_of_sub_lt_one_div_den_sq {ξ q : ℚ}
(h : |ξ - q| < 1 / (q.den : ℚ) ^ 2) :
q.den ≤ ξ.den ∧ ⌈ξ * q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * q.den⌋ + 1 := by
have hq₀ : (0 : ℚ) < q.den := Nat.cast_pos.mpr q.pos
replace h : |ξ * q.den - q.num| < 1 / q.den := by
rw [← mul_lt_mul_right hq₀] at h
conv_lhs at h => rw [← abs_of_pos hq₀, ← abs_mul, sub_mul, mul_den_eq_num]
rwa [sq, div_mul, mul_div_cancel_left₀ _ hq₀.ne'] at h
constructor
· rcases eq_or_ne ξ q with (rfl | H)
· exact le_rfl
· have hξ₀ : (0 : ℚ) < ξ.den := Nat.cast_pos.mpr ξ.pos
rw [← Rat.num_div_den ξ, div_mul_eq_mul_div, div_sub' _ _ _ hξ₀.ne', abs_div, abs_of_pos hξ₀,
div_lt_iff hξ₀, div_mul_comm, mul_one] at h
refine Nat.cast_le.mp ((one_lt_div hq₀).mp <| lt_of_le_of_lt ?_ h).le
norm_cast
rw [mul_comm _ q.num]
exact Int.one_le_abs (sub_ne_zero_of_ne <| mt Rat.eq_iff_mul_eq_mul.mpr H)
· obtain ⟨h₁, h₂⟩ :=
abs_sub_lt_iff.mp
(h.trans_le <|
(one_div_le zero_lt_one hq₀).mp <| (@one_div_one ℚ _).symm ▸ Nat.cast_le.mpr q.pos)
rw [sub_lt_iff_lt_add, add_comm] at h₁ h₂
rw [← sub_lt_iff_lt_add] at h₂
norm_cast at h₁ h₂
exact
⟨sub_le_iff_le_add.mpr (Int.ceil_le.mpr h₁.le), sub_le_iff_le_add.mp (Int.le_floor.mpr h₂.le)⟩
/-- A rational number has only finitely many good rational approximations. -/
theorem finite_rat_abs_sub_lt_one_div_den_sq (ξ : ℚ) :
{q : ℚ | |ξ - q| < 1 / (q.den : ℚ) ^ 2}.Finite := by
let f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
set s := {q : ℚ | |ξ - q| < 1 / (q.den : ℚ) ^ 2}
have hinj : Function.Injective f := by
intro a b hab
simp only [f, Prod.mk.inj_iff] at hab
rw [← Rat.num_div_den a, ← Rat.num_div_den b, hab.1, hab.2]
have H : f '' s ⊆ ⋃ (y : ℕ) (_ : y ∈ Ioc 0 ξ.den), Icc (⌈ξ * y⌉ - 1) (⌊ξ * y⌋ + 1) ×ˢ {y} := by
intro xy hxy
simp only [mem_image, mem_setOf] at hxy
obtain ⟨q, hq₁, hq₂⟩ := hxy
obtain ⟨hd, hn⟩ := den_le_and_le_num_le_of_sub_lt_one_div_den_sq hq₁
simp_rw [mem_iUnion]
refine ⟨q.den, Set.mem_Ioc.mpr ⟨q.pos, hd⟩, ?_⟩
simp only [prod_singleton, mem_image, mem_Icc, (congr_arg Prod.snd (Eq.symm hq₂)).trans rfl]
exact ⟨q.num, hn, hq₂⟩
refine (Finite.subset ?_ H).of_finite_image hinj.injOn
exact Finite.biUnion (finite_Ioc _ _) fun x _ => Finite.prod (finite_Icc _ _) (finite_singleton _)
end Rat
/-- The set of good rational approximations to a real number `ξ` is infinite if and only if
`ξ` is irrational. -/
theorem Real.infinite_rat_abs_sub_lt_one_div_den_sq_iff_irrational (ξ : ℝ) :
{q : ℚ | |ξ - q| < 1 / (q.den : ℝ) ^ 2}.Infinite ↔ Irrational ξ := by
refine
⟨fun h => (irrational_iff_ne_rational ξ).mpr fun a b H => Set.not_infinite.mpr ?_ h,
Real.infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational⟩
convert Rat.finite_rat_abs_sub_lt_one_div_den_sq ((a : ℚ) / b) with q
rw [H, (by (push_cast; rfl) : (1 : ℝ) / (q.den : ℝ) ^ 2 = (1 / (q.den : ℚ) ^ 2 : ℚ))]
norm_cast
/-!
### Legendre's Theorem on Rational Approximation
We prove **Legendre's Theorem** on rational approximation: If $\xi$ is a real number and
$x/y$ is a rational number such that $|\xi - x/y| < 1/(2y^2)$,
then $x/y$ is a convergent of the continued fraction expansion of $\xi$.
The proof is by induction. However, the induction proof does not work with the
statement as given, since the assumption is too weak to imply the corresponding
statement for the application of the induction hypothesis. This can be remedied
by making the statement slightly stronger. Namely, we assume that $|\xi - x/y| < 1/(y(2y-1))$
when $y \ge 2$ and $-\frac{1}{2} < \xi - x < 1$ when $y = 1$.
-/
section Convergent
namespace Real
open Int
/-!
### Convergents: definition and API lemmas
-/
/-- We give a direct recursive definition of the convergents of the continued fraction
expansion of a real number `ξ`. The main reason for that is that we want to have the
convergents as rational numbers; the versions `(GenContFract.of ξ).convs` and
`(GenContFract.of ξ).convs'` always give something of the same type as `ξ`.
We can then also use dot notation `ξ.convergent n`.
Another minor reason is that this demonstrates that the proof
of Legendre's theorem does not need anything beyond this definition.
We provide a proof that this definition agrees with the other one;
see `Real.convs_eq_convergent`.
(Note that we use the fact that `1/0 = 0` here to make it work for rational `ξ`.) -/
noncomputable def convergent : ℝ → ℕ → ℚ
| ξ, 0 => ⌊ξ⌋
| ξ, n + 1 => ⌊ξ⌋ + (convergent (fract ξ)⁻¹ n)⁻¹
/-- The zeroth convergent of `ξ` is `⌊ξ⌋`. -/
@[simp]
theorem convergent_zero (ξ : ℝ) : ξ.convergent 0 = ⌊ξ⌋ :=
rfl
/-- The `(n+1)`th convergent of `ξ` is the `n`th convergent of `1/(fract ξ)`. -/
@[simp]
theorem convergent_succ (ξ : ℝ) (n : ℕ) :
ξ.convergent (n + 1) = ⌊ξ⌋ + ((fract ξ)⁻¹.convergent n)⁻¹ :=
-- Porting note(https://github.com/leanprover-community/mathlib4/issues/5026): was
-- by simp only [convergent]
rfl
/-- All convergents of `0` are zero. -/
@[simp]
theorem convergent_of_zero (n : ℕ) : convergent 0 n = 0 := by
induction' n with n ih
· simp only [Nat.zero_eq, convergent_zero, floor_zero, cast_zero]
· simp only [ih, convergent_succ, floor_zero, cast_zero, fract_zero, add_zero, inv_zero]
/-- If `ξ` is an integer, all its convergents equal `ξ`. -/
@[simp]
theorem convergent_of_int {ξ : ℤ} (n : ℕ) : convergent ξ n = ξ := by
cases n
· simp only [Nat.zero_eq, convergent_zero, floor_intCast]
· simp only [convergent_succ, floor_intCast, fract_intCast, convergent_of_zero, add_zero,
inv_zero]
/-!
Our `convergent`s agree with `GenContFract.convs`.
-/
open GenContFract
/-- The `n`th convergent of the `GenContFract.of ξ` agrees with `ξ.convergent n`. -/
theorem convs_eq_convergent (ξ : ℝ) (n : ℕ) :
(GenContFract.of ξ).convs n = ξ.convergent n := by
induction' n with n ih generalizing ξ
· simp only [Nat.zero_eq, zeroth_conv_eq_h, of_h_eq_floor, convergent_zero, Rat.cast_intCast]
· rw [convs_succ, ih (fract ξ)⁻¹, convergent_succ, one_div]
norm_cast
end Real
end Convergent
/-!
### The key technical condition for the induction proof
-/
namespace Real
open Int
-- this is not `private`, as it is used in the public `exists_rat_eq_convergent'` below.
/-- Define the technical condition to be used as assumption in the inductive proof. -/
def ContfracLegendre.Ass (ξ : ℝ) (u v : ℤ) : Prop :=
IsCoprime u v ∧ (v = 1 → (-(1 / 2) : ℝ) < ξ - u) ∧
|ξ - u / v| < ((v : ℝ) * (2 * v - 1))⁻¹
-- ### Auxiliary lemmas
-- This saves a few lines below, as it is frequently needed.
private theorem aux₀ {v : ℤ} (hv : 0 < v) : (0 : ℝ) < v ∧ (0 : ℝ) < 2 * v - 1 :=
⟨cast_pos.mpr hv, by norm_cast; omega⟩
-- In the following, we assume that `ass ξ u v` holds and `v ≥ 2`.
variable {ξ : ℝ} {u v : ℤ} (hv : 2 ≤ v) (h : ContfracLegendre.Ass ξ u v)
-- The fractional part of `ξ` is positive.
private theorem aux₁ : 0 < fract ξ := by
have hv₀ : (0 : ℝ) < v := cast_pos.mpr (zero_lt_two.trans_le hv)
obtain ⟨hv₁, hv₂⟩ := aux₀ (zero_lt_two.trans_le hv)
obtain ⟨hcop, _, h⟩ := h
refine fract_pos.mpr fun hf => ?_
rw [hf] at h
have H : (2 * v - 1 : ℝ) < 1 := by
refine
(mul_lt_iff_lt_one_right hv₀).mp ((inv_lt_inv hv₀ (mul_pos hv₁ hv₂)).mp (lt_of_le_of_lt ?_ h))
have h' : (⌊ξ⌋ : ℝ) - u / v = (⌊ξ⌋ * v - u) / v := by field_simp
rw [h', abs_div, abs_of_pos hv₀, ← one_div, div_le_div_right hv₀]
norm_cast
rw [← zero_add (1 : ℤ), add_one_le_iff, abs_pos, sub_ne_zero]
rintro rfl
cases isUnit_iff.mp (isCoprime_self.mp (IsCoprime.mul_left_iff.mp hcop).2) <;> omega
norm_cast at H
linarith only [hv, H]
-- An auxiliary lemma for the inductive step.
private theorem aux₂ : 0 < u - ⌊ξ⌋ * v ∧ u - ⌊ξ⌋ * v < v := by
obtain ⟨hcop, _, h⟩ := h
obtain ⟨hv₀, hv₀'⟩ := aux₀ (zero_lt_two.trans_le hv)
have hv₁ : 0 < 2 * v - 1 := by linarith only [hv]
rw [← one_div, lt_div_iff (mul_pos hv₀ hv₀'), ← abs_of_pos (mul_pos hv₀ hv₀'), ← abs_mul, sub_mul,
← mul_assoc, ← mul_assoc, div_mul_cancel₀ _ hv₀.ne', abs_sub_comm, abs_lt, lt_sub_iff_add_lt,
sub_lt_iff_lt_add, mul_assoc] at h
have hu₀ : 0 ≤ u - ⌊ξ⌋ * v := by
-- Porting note: this abused the definitional equality `-1 + 1 = 0`
-- refine' (mul_nonneg_iff_of_pos_right hv₁).mp ((lt_iff_add_one_le (-1 : ℤ) _).mp _)
refine (mul_nonneg_iff_of_pos_right hv₁).mp ?_
rw [← sub_one_lt_iff, zero_sub]
replace h := h.1
rw [← lt_sub_iff_add_lt, ← mul_assoc, ← sub_mul] at h
exact mod_cast
h.trans_le
((mul_le_mul_right <| hv₀').mpr <|
(sub_le_sub_iff_left (u : ℝ)).mpr ((mul_le_mul_right hv₀).mpr (floor_le ξ)))
have hu₁ : u - ⌊ξ⌋ * v ≤ v := by
refine _root_.le_of_mul_le_mul_right (le_of_lt_add_one ?_) hv₁
replace h := h.2
rw [← sub_lt_iff_lt_add, ← mul_assoc, ← sub_mul, ← add_lt_add_iff_right (v * (2 * v - 1) : ℝ),
add_comm (1 : ℝ)] at h
have :=
(mul_lt_mul_right <| hv₀').mpr
((sub_lt_sub_iff_left (u : ℝ)).mpr <|
(mul_lt_mul_right hv₀).mpr <| sub_right_lt_of_lt_add <| lt_floor_add_one ξ)
rw [sub_mul ξ, one_mul, ← sub_add, add_mul] at this
exact mod_cast this.trans h
have huv_cop : IsCoprime (u - ⌊ξ⌋ * v) v := by
rwa [sub_eq_add_neg, ← neg_mul, IsCoprime.add_mul_right_left_iff]
refine ⟨lt_of_le_of_ne' hu₀ fun hf => ?_, lt_of_le_of_ne hu₁ fun hf => ?_⟩ <;>
· rw [hf] at huv_cop
simp only [isCoprime_zero_left, isCoprime_self, isUnit_iff] at huv_cop
cases' huv_cop with huv_cop huv_cop <;> linarith only [hv, huv_cop]
-- The key step: the relevant inequality persists in the inductive step.
private theorem aux₃ :
|(fract ξ)⁻¹ - v / (u - ⌊ξ⌋ * v)| < (((u : ℝ) - ⌊ξ⌋ * v) * (2 * (u - ⌊ξ⌋ * v) - 1))⁻¹ := by
obtain ⟨hu₀, huv⟩ := aux₂ hv h
have hξ₀ := aux₁ hv h
set u' := u - ⌊ξ⌋ * v with hu'
have hu'ℝ : (u' : ℝ) = u - ⌊ξ⌋ * v := mod_cast hu'
rw [← hu'ℝ]
replace hu'ℝ := (eq_sub_iff_add_eq.mp hu'ℝ).symm
obtain ⟨Hu, Hu'⟩ := aux₀ hu₀
obtain ⟨Hv, Hv'⟩ := aux₀ (zero_lt_two.trans_le hv)
have H₁ := div_pos (div_pos Hv Hu) hξ₀
replace h := h.2.2
have h' : |fract ξ - u' / v| < ((v : ℝ) * (2 * v - 1))⁻¹ := by
rwa [hu'ℝ, add_div, mul_div_cancel_right₀ _ Hv.ne', ← sub_sub, sub_right_comm] at h
have H : (2 * u' - 1 : ℝ) ≤ (2 * v - 1) * fract ξ := by
replace h := (abs_lt.mp h).1
have : (2 * (v : ℝ) - 1) * (-((v : ℝ) * (2 * v - 1))⁻¹ + u' / v) = 2 * u' - (1 + u') / v := by
field_simp; ring
rw [hu'ℝ, add_div, mul_div_cancel_right₀ _ Hv.ne', ← sub_sub, sub_right_comm, self_sub_floor,
lt_sub_iff_add_lt, ← mul_lt_mul_left Hv', this] at h
refine LE.le.trans ?_ h.le
rw [sub_le_sub_iff_left, div_le_one Hv, add_comm]
exact mod_cast huv
have help₁ {a b c : ℝ} : a ≠ 0 → b ≠ 0 → c ≠ 0 → |a⁻¹ - b / c| = |(a - c / b) * (b / c / a)| := by
intros; rw [abs_sub_comm]; congr 1; field_simp; ring
have help₂ :
∀ {a b c d : ℝ}, a ≠ 0 → b ≠ 0 → c ≠ 0 → d ≠ 0 → (b * c)⁻¹ * (b / d / a) = (d * c * a)⁻¹ := by
intros; field_simp; ring
calc
|(fract ξ)⁻¹ - v / u'| = |(fract ξ - u' / v) * (v / u' / fract ξ)| :=
help₁ hξ₀.ne' Hv.ne' Hu.ne'
_ = |fract ξ - u' / v| * (v / u' / fract ξ) := by rw [abs_mul, abs_of_pos H₁]
_ < ((v : ℝ) * (2 * v - 1))⁻¹ * (v / u' / fract ξ) := (mul_lt_mul_right H₁).mpr h'
_ = (u' * (2 * v - 1) * fract ξ)⁻¹ := help₂ hξ₀.ne' Hv.ne' Hv'.ne' Hu.ne'
_ ≤ ((u' : ℝ) * (2 * u' - 1))⁻¹ := by
rwa [inv_le_inv (mul_pos (mul_pos Hu Hv') hξ₀) <| mul_pos Hu Hu', mul_assoc,
mul_le_mul_left Hu]
-- The conditions `ass ξ u v` persist in the inductive step.
private theorem invariant : ContfracLegendre.Ass (fract ξ)⁻¹ v (u - ⌊ξ⌋ * v) := by
refine ⟨?_, fun huv => ?_, mod_cast aux₃ hv h⟩
· rw [sub_eq_add_neg, ← neg_mul, isCoprime_comm, IsCoprime.add_mul_right_left_iff]
exact h.1
· obtain hv₀' := (aux₀ (zero_lt_two.trans_le hv)).2
have Hv : (v * (2 * v - 1) : ℝ)⁻¹ + (v : ℝ)⁻¹ = 2 / (2 * v - 1) := by
field_simp; ring
have Huv : (u / v : ℝ) = ⌊ξ⌋ + (v : ℝ)⁻¹ := by
rw [sub_eq_iff_eq_add'.mp huv]; field_simp
have h' := (abs_sub_lt_iff.mp h.2.2).1
rw [Huv, ← sub_sub, sub_lt_iff_lt_add, self_sub_floor, Hv] at h'
rwa [lt_sub_iff_add_lt', (by ring : (v : ℝ) + -(1 / 2) = (2 * v - 1) / 2),
lt_inv (div_pos hv₀' zero_lt_two) (aux₁ hv h), inv_div]
/-!
### The main result
-/
/-- The technical version of *Legendre's Theorem*. -/
theorem exists_rat_eq_convergent' {v : ℕ} (h' : ContfracLegendre.Ass ξ u v) :
∃ n, (u / v : ℚ) = ξ.convergent n := by
-- Porting note: `induction` got in trouble because of the irrelevant hypothesis `h`
clear h; have h := h'; clear h'
induction v using Nat.strong_induction_on generalizing ξ u with | h v ih => ?_
rcases lt_trichotomy v 1 with (ht | rfl | ht)
· replace h := h.2.2
simp only [Nat.lt_one_iff.mp ht, Nat.cast_zero, div_zero, tsub_zero, zero_mul,
cast_zero, inv_zero] at h
exact False.elim (lt_irrefl _ <| (abs_nonneg ξ).trans_lt h)
· rw [Nat.cast_one, div_one]
obtain ⟨_, h₁, h₂⟩ := h
rcases le_or_lt (u : ℝ) ξ with ht | ht
· use 0
rw [convergent_zero, Rat.coe_int_inj, eq_comm, floor_eq_iff]
convert And.intro ht (sub_lt_iff_lt_add'.mp (abs_lt.mp h₂).2) <;> norm_num
· replace h₁ := lt_sub_iff_add_lt'.mp (h₁ rfl)
have hξ₁ : ⌊ξ⌋ = u - 1 := by
rw [floor_eq_iff, cast_sub, cast_one, sub_add_cancel]
exact ⟨(((sub_lt_sub_iff_left _).mpr one_half_lt_one).trans h₁).le, ht⟩
rcases eq_or_ne ξ ⌊ξ⌋ with Hξ | Hξ
· rw [Hξ, hξ₁, cast_sub, cast_one, ← sub_eq_add_neg, sub_lt_sub_iff_left] at h₁
exact False.elim (lt_irrefl _ <| h₁.trans one_half_lt_one)
· have hξ₂ : ⌊(fract ξ)⁻¹⌋ = 1 := by
rw [floor_eq_iff, cast_one, le_inv zero_lt_one (fract_pos.mpr Hξ), inv_one,
one_add_one_eq_two, inv_lt (fract_pos.mpr Hξ) zero_lt_two]
refine ⟨(fract_lt_one ξ).le, ?_⟩
rw [fract, hξ₁, cast_sub, cast_one, lt_sub_iff_add_lt', sub_add]
convert h₁ using 1
-- Porting note: added (`convert` handled this in lean 3)
rw [sub_eq_add_neg]
norm_num
use 1
simp [convergent, hξ₁, hξ₂, cast_sub, cast_one]
· obtain ⟨huv₀, huv₁⟩ := aux₂ (Nat.cast_le.mpr ht) h
have Hv : (v : ℚ) ≠ 0 := (Nat.cast_pos.mpr (zero_lt_one.trans ht)).ne'
have huv₁' : (u - ⌊ξ⌋ * v).toNat < v := by zify; rwa [toNat_of_nonneg huv₀.le]
have inv : ContfracLegendre.Ass (fract ξ)⁻¹ v (u - ⌊ξ⌋ * ↑v).toNat :=
(toNat_of_nonneg huv₀.le).symm ▸ invariant (Nat.cast_le.mpr ht) h
obtain ⟨n, hn⟩ := ih (u - ⌊ξ⌋ * v).toNat huv₁' inv
use n + 1
rw [convergent_succ, ← hn,
(mod_cast toNat_of_nonneg huv₀.le : ((u - ⌊ξ⌋ * v).toNat : ℚ) = u - ⌊ξ⌋ * v),
cast_natCast, inv_div, sub_div, mul_div_cancel_right₀ _ Hv, add_sub_cancel]
/-- The main result, *Legendre's Theorem* on rational approximation:
if `ξ` is a real number and `q` is a rational number such that `|ξ - q| < 1/(2*q.den^2)`,
then `q` is a convergent of the continued fraction expansion of `ξ`.
This version uses `Real.convergent`. -/
theorem exists_rat_eq_convergent {q : ℚ} (h : |ξ - q| < 1 / (2 * (q.den : ℝ) ^ 2)) :
∃ n, q = ξ.convergent n := by
refine q.num_div_den ▸ exists_rat_eq_convergent' ⟨?_, fun hd => ?_, ?_⟩
· exact coprime_iff_nat_coprime.mpr (natAbs_ofNat q.den ▸ q.reduced)
· rw [← q.den_eq_one_iff.mp (Nat.cast_eq_one.mp hd)] at h
simpa only [Rat.den_intCast, Nat.cast_one, one_pow, mul_one] using (abs_lt.mp h).1
· obtain ⟨hq₀, hq₁⟩ := aux₀ (Nat.cast_pos.mpr q.pos)
replace hq₁ := mul_pos hq₀ hq₁
have hq₂ : (0 : ℝ) < 2 * (q.den * q.den) := mul_pos zero_lt_two (mul_pos hq₀ hq₀)
rw [cast_natCast] at *
rw [(by norm_cast : (q.num / q.den : ℝ) = (q.num / q.den : ℚ)), Rat.num_div_den]
exact h.trans (by rw [← one_div, sq, one_div_lt_one_div hq₂ hq₁, ← sub_pos]; ring_nf; exact hq₀)
/-- The main result, *Legendre's Theorem* on rational approximation:
if `ξ` is a real number and `q` is a rational number such that `|ξ - q| < 1/(2*q.den^2)`,
then `q` is a convergent of the continued fraction expansion of `ξ`.
This is the version using `GenContFract.convs`. -/
theorem exists_convs_eq_rat {q : ℚ}
(h : |ξ - q| < 1 / (2 * (q.den : ℝ) ^ 2)) : ∃ n, (GenContFract.of ξ).convs n = q := by
obtain ⟨n, hn⟩ := exists_rat_eq_convergent h
exact ⟨n, hn.symm ▸ convs_eq_convergent ξ n⟩
end Real
|
NumberTheory\Divisors.lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.Nat.PrimeFin
import Mathlib.Order.Interval.Finset.Nat
/-!
# Divisor Finsets
This file defines sets of divisors of a natural number. This is particularly useful as background
for defining Dirichlet convolution.
## Main Definitions
Let `n : ℕ`. All of the following definitions are in the `Nat` namespace:
* `divisors n` is the `Finset` of natural numbers that divide `n`.
* `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`.
* `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`.
* `Perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`.
## Implementation details
* `divisors 0`, `properDivisors 0`, and `divisorsAntidiagonal 0` are defined to be `∅`.
## Tags
divisors, perfect numbers
-/
open Finset
namespace Nat
variable (n : ℕ)
/-- `divisors n` is the `Finset` of divisors of `n`. As a special case, `divisors 0 = ∅`. -/
def divisors : Finset ℕ :=
Finset.filter (fun x : ℕ => x ∣ n) (Finset.Ico 1 (n + 1))
/-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`.
As a special case, `properDivisors 0 = ∅`. -/
def properDivisors : Finset ℕ :=
Finset.filter (fun x : ℕ => x ∣ n) (Finset.Ico 1 n)
/-- `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`.
As a special case, `divisorsAntidiagonal 0 = ∅`. -/
def divisorsAntidiagonal : Finset (ℕ × ℕ) :=
Finset.filter (fun x => x.fst * x.snd = n) (Ico 1 (n + 1) ×ˢ Ico 1 (n + 1))
variable {n}
@[simp]
theorem filter_dvd_eq_divisors (h : n ≠ 0) : (Finset.range n.succ).filter (· ∣ n) = n.divisors := by
ext
simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]
exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)
@[simp]
theorem filter_dvd_eq_properDivisors (h : n ≠ 0) :
(Finset.range n).filter (· ∣ n) = n.properDivisors := by
ext
simp only [properDivisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]
exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)
theorem properDivisors.not_self_mem : ¬n ∈ properDivisors n := by simp [properDivisors]
@[simp]
theorem mem_properDivisors {m : ℕ} : n ∈ properDivisors m ↔ n ∣ m ∧ n < m := by
rcases eq_or_ne m 0 with (rfl | hm); · simp [properDivisors]
simp only [and_comm, ← filter_dvd_eq_properDivisors hm, mem_filter, mem_range]
theorem insert_self_properDivisors (h : n ≠ 0) : insert n (properDivisors n) = divisors n := by
rw [divisors, properDivisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h),
Finset.filter_insert, if_pos (dvd_refl n)]
theorem cons_self_properDivisors (h : n ≠ 0) :
cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by
rw [cons_eq_insert, insert_self_properDivisors h]
@[simp]
theorem mem_divisors {m : ℕ} : n ∈ divisors m ↔ n ∣ m ∧ m ≠ 0 := by
rcases eq_or_ne m 0 with (rfl | hm); · simp [divisors]
simp only [hm, Ne, not_false_iff, and_true_iff, ← filter_dvd_eq_divisors hm, mem_filter,
mem_range, and_iff_right_iff_imp, Nat.lt_succ_iff]
exact le_of_dvd hm.bot_lt
theorem one_mem_divisors : 1 ∈ divisors n ↔ n ≠ 0 := by simp
theorem mem_divisors_self (n : ℕ) (h : n ≠ 0) : n ∈ n.divisors :=
mem_divisors.2 ⟨dvd_rfl, h⟩
theorem dvd_of_mem_divisors {m : ℕ} (h : n ∈ divisors m) : n ∣ m := by
cases m
· apply dvd_zero
· simp [mem_divisors.1 h]
@[simp]
theorem mem_divisorsAntidiagonal {x : ℕ × ℕ} :
x ∈ divisorsAntidiagonal n ↔ x.fst * x.snd = n ∧ n ≠ 0 := by
simp only [divisorsAntidiagonal, Finset.mem_Ico, Ne, Finset.mem_filter, Finset.mem_product]
rw [and_comm]
apply and_congr_right
rintro rfl
constructor <;> intro h
· contrapose! h
simp [h]
· rw [Nat.lt_add_one_iff, Nat.lt_add_one_iff]
rw [mul_eq_zero, not_or] at h
simp only [succ_le_of_lt (Nat.pos_of_ne_zero h.1), succ_le_of_lt (Nat.pos_of_ne_zero h.2),
true_and_iff]
exact
⟨Nat.le_mul_of_pos_right _ (Nat.pos_of_ne_zero h.2),
Nat.le_mul_of_pos_left _ (Nat.pos_of_ne_zero h.1)⟩
lemma ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) :
p.1 ≠ 0 ∧ p.2 ≠ 0 := by
obtain ⟨hp₁, hp₂⟩ := Nat.mem_divisorsAntidiagonal.mp hp
exact mul_ne_zero_iff.mp (hp₁.symm ▸ hp₂)
lemma left_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) :
p.1 ≠ 0 :=
(ne_zero_of_mem_divisorsAntidiagonal hp).1
lemma right_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) :
p.2 ≠ 0 :=
(ne_zero_of_mem_divisorsAntidiagonal hp).2
theorem divisor_le {m : ℕ} : n ∈ divisors m → n ≤ m := by
cases' m with m
· simp
· simp only [mem_divisors, Nat.succ_ne_zero m, and_true_iff, Ne, not_false_iff]
exact Nat.le_of_dvd (Nat.succ_pos m)
theorem divisors_subset_of_dvd {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) : divisors m ⊆ divisors n :=
Finset.subset_iff.2 fun _x hx => Nat.mem_divisors.mpr ⟨(Nat.mem_divisors.mp hx).1.trans h, hzero⟩
theorem divisors_subset_properDivisors {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) (hdiff : m ≠ n) :
divisors m ⊆ properDivisors n := by
apply Finset.subset_iff.2
intro x hx
exact
Nat.mem_properDivisors.2
⟨(Nat.mem_divisors.1 hx).1.trans h,
lt_of_le_of_lt (divisor_le hx)
(lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 ⟨h, hzero⟩)) hdiff)⟩
lemma divisors_filter_dvd_of_dvd {n m : ℕ} (hn : n ≠ 0) (hm : m ∣ n) :
(n.divisors.filter (· ∣ m)) = m.divisors := by
ext k
simp_rw [mem_filter, mem_divisors]
exact ⟨fun ⟨_, hkm⟩ ↦ ⟨hkm, ne_zero_of_dvd_ne_zero hn hm⟩, fun ⟨hk, _⟩ ↦ ⟨⟨hk.trans hm, hn⟩, hk⟩⟩
@[simp]
theorem divisors_zero : divisors 0 = ∅ := by
ext
simp
@[simp]
theorem properDivisors_zero : properDivisors 0 = ∅ := by
ext
simp
@[simp]
lemma nonempty_divisors : (divisors n).Nonempty ↔ n ≠ 0 :=
⟨fun ⟨m, hm⟩ hn ↦ by simp [hn] at hm, fun hn ↦ ⟨1, one_mem_divisors.2 hn⟩⟩
@[simp]
lemma divisors_eq_empty : divisors n = ∅ ↔ n = 0 :=
not_nonempty_iff_eq_empty.symm.trans nonempty_divisors.not_left
theorem properDivisors_subset_divisors : properDivisors n ⊆ divisors n :=
filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ
@[simp]
theorem divisors_one : divisors 1 = {1} := by
ext
simp
@[simp]
theorem properDivisors_one : properDivisors 1 = ∅ := by rw [properDivisors, Ico_self, filter_empty]
theorem pos_of_mem_divisors {m : ℕ} (h : m ∈ n.divisors) : 0 < m := by
cases m
· rw [mem_divisors, zero_dvd_iff (a := n)] at h
cases h.2 h.1
apply Nat.succ_pos
theorem pos_of_mem_properDivisors {m : ℕ} (h : m ∈ n.properDivisors) : 0 < m :=
pos_of_mem_divisors (properDivisors_subset_divisors h)
theorem one_mem_properDivisors_iff_one_lt : 1 ∈ n.properDivisors ↔ 1 < n := by
rw [mem_properDivisors, and_iff_right (one_dvd _)]
@[simp]
lemma sup_divisors_id (n : ℕ) : n.divisors.sup id = n := by
refine le_antisymm (Finset.sup_le fun _ ↦ divisor_le) ?_
rcases Decidable.eq_or_ne n 0 with rfl | hn
· apply zero_le
· exact Finset.le_sup (f := id) <| mem_divisors_self n hn
lemma one_lt_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) : 1 < n :=
lt_of_le_of_lt (pos_of_mem_properDivisors h) (mem_properDivisors.1 h).2
lemma one_lt_div_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) :
1 < n / m := by
obtain ⟨h_dvd, h_lt⟩ := mem_properDivisors.mp h
rwa [Nat.lt_div_iff_mul_lt h_dvd, mul_one]
/-- See also `Nat.mem_properDivisors`. -/
lemma mem_properDivisors_iff_exists {m n : ℕ} (hn : n ≠ 0) :
m ∈ n.properDivisors ↔ ∃ k > 1, n = m * k := by
refine ⟨fun h ↦ ⟨n / m, one_lt_div_of_mem_properDivisors h, ?_⟩, ?_⟩
· exact (Nat.mul_div_cancel' (mem_properDivisors.mp h).1).symm
· rintro ⟨k, hk, rfl⟩
rw [mul_ne_zero_iff] at hn
exact mem_properDivisors.mpr ⟨⟨k, rfl⟩, lt_mul_of_one_lt_right (Nat.pos_of_ne_zero hn.1) hk⟩
@[simp]
lemma nonempty_properDivisors : n.properDivisors.Nonempty ↔ 1 < n :=
⟨fun ⟨_m, hm⟩ ↦ one_lt_of_mem_properDivisors hm, fun hn ↦
⟨1, one_mem_properDivisors_iff_one_lt.2 hn⟩⟩
@[simp]
lemma properDivisors_eq_empty : n.properDivisors = ∅ ↔ n ≤ 1 := by
rw [← not_nonempty_iff_eq_empty, nonempty_properDivisors, not_lt]
@[simp]
theorem divisorsAntidiagonal_zero : divisorsAntidiagonal 0 = ∅ := by
ext
simp
@[simp]
theorem divisorsAntidiagonal_one : divisorsAntidiagonal 1 = {(1, 1)} := by
ext
simp [mul_eq_one, Prod.ext_iff]
/- Porting note: simpnf linter; added aux lemma below
Left-hand side simplifies from
Prod.swap x ∈ Nat.divisorsAntidiagonal n
to
x.snd * x.fst = n ∧ ¬n = 0-/
-- @[simp]
theorem swap_mem_divisorsAntidiagonal {x : ℕ × ℕ} :
x.swap ∈ divisorsAntidiagonal n ↔ x ∈ divisorsAntidiagonal n := by
rw [mem_divisorsAntidiagonal, mem_divisorsAntidiagonal, mul_comm, Prod.swap]
-- Porting note: added below thm to replace the simp from the previous thm
@[simp]
theorem swap_mem_divisorsAntidiagonal_aux {x : ℕ × ℕ} :
x.snd * x.fst = n ∧ ¬n = 0 ↔ x ∈ divisorsAntidiagonal n := by
rw [mem_divisorsAntidiagonal, mul_comm]
theorem fst_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) :
x.fst ∈ divisors n := by
rw [mem_divisorsAntidiagonal] at h
simp [Dvd.intro _ h.1, h.2]
theorem snd_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) :
x.snd ∈ divisors n := by
rw [mem_divisorsAntidiagonal] at h
simp [Dvd.intro_left _ h.1, h.2]
@[simp]
theorem map_swap_divisorsAntidiagonal :
(divisorsAntidiagonal n).map (Equiv.prodComm _ _).toEmbedding = divisorsAntidiagonal n := by
rw [← coe_inj, coe_map, Equiv.coe_toEmbedding, Equiv.coe_prodComm,
Set.image_swap_eq_preimage_swap]
ext
exact swap_mem_divisorsAntidiagonal
@[simp]
theorem image_fst_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.fst = divisors n := by
ext
simp [Dvd.dvd, @eq_comm _ n (_ * _)]
@[simp]
theorem image_snd_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.snd = divisors n := by
rw [← map_swap_divisorsAntidiagonal, map_eq_image, image_image]
exact image_fst_divisorsAntidiagonal
theorem map_div_right_divisors :
n.divisors.map ⟨fun d => (d, n / d), fun p₁ p₂ => congr_arg Prod.fst⟩ =
n.divisorsAntidiagonal := by
ext ⟨d, nd⟩
simp only [mem_map, mem_divisorsAntidiagonal, Function.Embedding.coeFn_mk, mem_divisors,
Prod.ext_iff, exists_prop, and_left_comm, exists_eq_left]
constructor
· rintro ⟨⟨⟨k, rfl⟩, hn⟩, rfl⟩
rw [Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt]
exact ⟨rfl, hn⟩
· rintro ⟨rfl, hn⟩
exact ⟨⟨dvd_mul_right _ _, hn⟩, Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt⟩
theorem map_div_left_divisors :
n.divisors.map ⟨fun d => (n / d, d), fun p₁ p₂ => congr_arg Prod.snd⟩ =
n.divisorsAntidiagonal := by
apply Finset.map_injective (Equiv.prodComm _ _).toEmbedding
ext
rw [map_swap_divisorsAntidiagonal, ← map_div_right_divisors, Finset.map_map]
simp
theorem sum_divisors_eq_sum_properDivisors_add_self :
∑ i ∈ divisors n, i = (∑ i ∈ properDivisors n, i) + n := by
rcases Decidable.eq_or_ne n 0 with (rfl | hn)
· simp
· rw [← cons_self_properDivisors hn, Finset.sum_cons, add_comm]
/-- `n : ℕ` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`
is positive. -/
def Perfect (n : ℕ) : Prop :=
∑ i ∈ properDivisors n, i = n ∧ 0 < n
theorem perfect_iff_sum_properDivisors (h : 0 < n) : Perfect n ↔ ∑ i ∈ properDivisors n, i = n :=
and_iff_left h
theorem perfect_iff_sum_divisors_eq_two_mul (h : 0 < n) :
Perfect n ↔ ∑ i ∈ divisors n, i = 2 * n := by
rw [perfect_iff_sum_properDivisors h, sum_divisors_eq_sum_properDivisors_add_self, two_mul]
constructor <;> intro h
· rw [h]
· apply add_right_cancel h
theorem mem_divisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) {x : ℕ} :
x ∈ divisors (p ^ k) ↔ ∃ j ≤ k, x = p ^ j := by
rw [mem_divisors, Nat.dvd_prime_pow pp, and_iff_left (ne_of_gt (pow_pos pp.pos k))]
theorem Prime.divisors {p : ℕ} (pp : p.Prime) : divisors p = {1, p} := by
ext
rw [mem_divisors, dvd_prime pp, and_iff_left pp.ne_zero, Finset.mem_insert, Finset.mem_singleton]
theorem Prime.properDivisors {p : ℕ} (pp : p.Prime) : properDivisors p = {1} := by
rw [← erase_insert properDivisors.not_self_mem, insert_self_properDivisors pp.ne_zero,
pp.divisors, pair_comm, erase_insert fun con => pp.ne_one (mem_singleton.1 con)]
theorem divisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) :
divisors (p ^ k) = (Finset.range (k + 1)).map ⟨(p ^ ·), Nat.pow_right_injective pp.two_le⟩ := by
ext a
rw [mem_divisors_prime_pow pp]
simp [Nat.lt_succ, eq_comm]
theorem divisors_injective : Function.Injective divisors :=
Function.LeftInverse.injective sup_divisors_id
@[simp]
theorem divisors_inj {a b : ℕ} : a.divisors = b.divisors ↔ a = b :=
divisors_injective.eq_iff
theorem eq_properDivisors_of_subset_of_sum_eq_sum {s : Finset ℕ} (hsub : s ⊆ n.properDivisors) :
((∑ x ∈ s, x) = ∑ x ∈ n.properDivisors, x) → s = n.properDivisors := by
cases n
· rw [properDivisors_zero, subset_empty] at hsub
simp [hsub]
classical
rw [← sum_sdiff hsub]
intro h
apply Subset.antisymm hsub
rw [← sdiff_eq_empty_iff_subset]
contrapose h
rw [← Ne, ← nonempty_iff_ne_empty] at h
apply ne_of_lt
rw [← zero_add (∑ x ∈ s, x), ← add_assoc, add_zero]
apply add_lt_add_right
have hlt :=
sum_lt_sum_of_nonempty h fun x hx => pos_of_mem_properDivisors (sdiff_subset hx)
simp only [sum_const_zero] at hlt
apply hlt
theorem sum_properDivisors_dvd (h : (∑ x ∈ n.properDivisors, x) ∣ n) :
∑ x ∈ n.properDivisors, x = 1 ∨ ∑ x ∈ n.properDivisors, x = n := by
cases' n with n
· simp
· cases' n with n
· simp at h
· rw [or_iff_not_imp_right]
intro ne_n
have hlt : ∑ x ∈ n.succ.succ.properDivisors, x < n.succ.succ :=
lt_of_le_of_ne (Nat.le_of_dvd (Nat.succ_pos _) h) ne_n
symm
rw [← mem_singleton, eq_properDivisors_of_subset_of_sum_eq_sum (singleton_subset_iff.2
(mem_properDivisors.2 ⟨h, hlt⟩)) (sum_singleton _ _), mem_properDivisors]
exact ⟨one_dvd _, Nat.succ_lt_succ (Nat.succ_pos _)⟩
@[to_additive (attr := simp)]
theorem Prime.prod_properDivisors {α : Type*} [CommMonoid α] {p : ℕ} {f : ℕ → α} (h : p.Prime) :
∏ x ∈ p.properDivisors, f x = f 1 := by simp [h.properDivisors]
@[to_additive (attr := simp)]
theorem Prime.prod_divisors {α : Type*} [CommMonoid α] {p : ℕ} {f : ℕ → α} (h : p.Prime) :
∏ x ∈ p.divisors, f x = f p * f 1 := by
rw [← cons_self_properDivisors h.ne_zero, prod_cons, h.prod_properDivisors]
theorem properDivisors_eq_singleton_one_iff_prime : n.properDivisors = {1} ↔ n.Prime := by
refine ⟨?_, ?_⟩
· intro h
refine Nat.prime_def_lt''.mpr ⟨?_, fun m hdvd => ?_⟩
· match n with
| 0 => contradiction
| 1 => contradiction
| Nat.succ (Nat.succ n) => simp [succ_le_succ]
· rw [← mem_singleton, ← h, mem_properDivisors]
have := Nat.le_of_dvd ?_ hdvd
· simp [hdvd, this]
exact (le_iff_eq_or_lt.mp this).symm
· by_contra!
simp only [nonpos_iff_eq_zero.mp this, this] at h
contradiction
· exact fun h => Prime.properDivisors h
theorem sum_properDivisors_eq_one_iff_prime : ∑ x ∈ n.properDivisors, x = 1 ↔ n.Prime := by
cases' n with n
· simp [Nat.not_prime_zero]
· cases n
· simp [Nat.not_prime_one]
· rw [← properDivisors_eq_singleton_one_iff_prime]
refine ⟨fun h => ?_, fun h => h.symm ▸ sum_singleton _ _⟩
rw [@eq_comm (Finset ℕ) _ _]
apply
eq_properDivisors_of_subset_of_sum_eq_sum
(singleton_subset_iff.2
(one_mem_properDivisors_iff_one_lt.2 (succ_lt_succ (Nat.succ_pos _))))
((sum_singleton _ _).trans h.symm)
theorem mem_properDivisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) {x : ℕ} :
x ∈ properDivisors (p ^ k) ↔ ∃ (j : ℕ) (_ : j < k), x = p ^ j := by
rw [mem_properDivisors, Nat.dvd_prime_pow pp, ← exists_and_right]
simp only [exists_prop, and_assoc]
apply exists_congr
intro a
constructor <;> intro h
· rcases h with ⟨_h_left, rfl, h_right⟩
rw [Nat.pow_lt_pow_iff_right pp.one_lt] at h_right
exact ⟨h_right, rfl⟩
· rcases h with ⟨h_left, rfl⟩
rw [Nat.pow_lt_pow_iff_right pp.one_lt]
simp [h_left, le_of_lt]
theorem properDivisors_prime_pow {p : ℕ} (pp : p.Prime) (k : ℕ) :
properDivisors (p ^ k) = (Finset.range k).map ⟨(p ^ ·), Nat.pow_right_injective pp.two_le⟩ := by
ext a
simp only [mem_properDivisors, Nat.isUnit_iff, mem_map, mem_range, Function.Embedding.coeFn_mk,
pow_eq]
have := mem_properDivisors_prime_pow pp k (x := a)
rw [mem_properDivisors] at this
rw [this]
refine ⟨?_, ?_⟩
· intro h; rcases h with ⟨j, hj, hap⟩; use j; tauto
· tauto
@[to_additive (attr := simp)]
theorem prod_properDivisors_prime_pow {α : Type*} [CommMonoid α] {k p : ℕ} {f : ℕ → α}
(h : p.Prime) : (∏ x ∈ (p ^ k).properDivisors, f x) = ∏ x ∈ range k, f (p ^ x) := by
simp [h, properDivisors_prime_pow]
@[to_additive (attr := simp) sum_divisors_prime_pow]
theorem prod_divisors_prime_pow {α : Type*} [CommMonoid α] {k p : ℕ} {f : ℕ → α} (h : p.Prime) :
(∏ x ∈ (p ^ k).divisors, f x) = ∏ x ∈ range (k + 1), f (p ^ x) := by
simp [h, divisors_prime_pow]
@[to_additive]
theorem prod_divisorsAntidiagonal {M : Type*} [CommMonoid M] (f : ℕ → ℕ → M) {n : ℕ} :
∏ i ∈ n.divisorsAntidiagonal, f i.1 i.2 = ∏ i ∈ n.divisors, f i (n / i) := by
rw [← map_div_right_divisors, Finset.prod_map]
rfl
@[to_additive]
theorem prod_divisorsAntidiagonal' {M : Type*} [CommMonoid M] (f : ℕ → ℕ → M) {n : ℕ} :
∏ i ∈ n.divisorsAntidiagonal, f i.1 i.2 = ∏ i ∈ n.divisors, f (n / i) i := by
rw [← map_swap_divisorsAntidiagonal, Finset.prod_map]
exact prod_divisorsAntidiagonal fun i j => f j i
/-- The factors of `n` are the prime divisors -/
theorem primeFactors_eq_to_filter_divisors_prime (n : ℕ) :
n.primeFactors = (divisors n).filter Prime := by
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
· ext q
simpa [hn, hn.ne', mem_primeFactorsList] using and_comm
@[deprecated (since := "2024-07-17")]
alias prime_divisors_eq_to_filter_divisors_prime := primeFactors_eq_to_filter_divisors_prime
lemma primeFactors_filter_dvd_of_dvd {m n : ℕ} (hn : n ≠ 0) (hmn : m ∣ n) :
n.primeFactors.filter (· ∣ m) = m.primeFactors := by
simp_rw [primeFactors_eq_to_filter_divisors_prime, filter_comm,
divisors_filter_dvd_of_dvd hn hmn]
@[deprecated (since := "2024-07-17")]
alias prime_divisors_filter_dvd_of_dvd := primeFactors_filter_dvd_of_dvd
@[simp]
theorem image_div_divisors_eq_divisors (n : ℕ) :
image (fun x : ℕ => n / x) n.divisors = n.divisors := by
by_cases hn : n = 0
· simp [hn]
ext a
constructor
· rw [mem_image]
rintro ⟨x, hx1, hx2⟩
rw [mem_divisors] at *
refine ⟨?_, hn⟩
rw [← hx2]
exact div_dvd_of_dvd hx1.1
· rw [mem_divisors, mem_image]
rintro ⟨h1, -⟩
exact ⟨n / a, mem_divisors.mpr ⟨div_dvd_of_dvd h1, hn⟩, Nat.div_div_self h1 hn⟩
/- Porting note: Removed simp; simp_nf linter:
Left-hand side does not simplify, when using the simp lemma on itself.
This usually means that it will never apply. -/
@[to_additive sum_div_divisors]
theorem prod_div_divisors {α : Type*} [CommMonoid α] (n : ℕ) (f : ℕ → α) :
(∏ d ∈ n.divisors, f (n / d)) = n.divisors.prod f := by
by_cases hn : n = 0; · simp [hn]
rw [← prod_image]
· exact prod_congr (image_div_divisors_eq_divisors n) (by simp)
· intro x hx y hy h
rw [mem_divisors] at hx hy
exact (div_eq_iff_eq_of_dvd_dvd hn hx.1 hy.1).mp h
end Nat
|
NumberTheory\EllipticDivisibilitySequence.lean | /-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Data.Nat.EvenOddRec
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.LinearCombination
/-!
# Elliptic divisibility sequences
This file defines the type of an elliptic divisibility sequence (EDS) and a few examples.
## Mathematical background
Let $R$ be a commutative ring. An elliptic sequence is a sequence $W : \mathbb{Z} \to R$ satisfying
$$ W(m + n)W(m - n)W(r)^2 = W(m + r)W(m - r)W(n)^2 - W(n + r)W(n - r)W(m)^2, $$
for any $m, n, r \in \mathbb{Z}$. A divisibility sequence is a sequence $W : \mathbb{Z} \to R$
satisfying $W(m) \mid W(n)$ for any $m, n \in \mathbb{Z}$ such that $m \mid n$.
Some examples of EDSs include
* the identity sequence,
* certain terms of Lucas sequences, and
* division polynomials of elliptic curves.
## Main definitions
* `IsEllSequence`: a sequence indexed by integers is an elliptic sequence.
* `IsDivSequence`: a sequence indexed by integers is a divisibility sequence.
* `IsEllDivSequence`: a sequence indexed by integers is an EDS.
* `preNormEDS'`: the auxiliary sequence for a normalised EDS indexed by `ℕ`.
* `preNormEDS`: the auxiliary sequence for a normalised EDS indexed by `ℤ`.
* `normEDS`: the canonical example of a normalised EDS indexed by `ℤ`.
## Main statements
* TODO: prove that `normEDS` satisfies `IsEllDivSequence`.
* TODO: prove that a normalised sequence satisfying `IsEllDivSequence` can be given by `normEDS`.
## Implementation notes
The normalised EDS `normEDS b c d n` is defined in terms of the auxiliary sequence
`preNormEDS (b ^ 4) c d n`, which are equal when `n` is odd, and which differ by a factor of `b`
when `n` is even. This coincides with the definition in the references since both agree for
`normEDS b c d 2` and for `normEDS b c d 4`, and the correct factors of `b` are removed in
`normEDS b c d (2 * (m + 2) + 1)` and in `normEDS b c d (2 * (m + 3))`.
One reason is to avoid the necessity for ring division by `b` in the inductive definition of
`normEDS b c d (2 * (m + 3))`. The idea is that, it can be shown that `normEDS b c d (2 * (m + 3))`
always contains a factor of `b`, so it is possible to remove a factor of `b` *a posteriori*, but
stating this lemma requires first defining `normEDS b c d (2 * (m + 3))`, which requires having this
factor of `b` *a priori*. Another reason is to allow the definition of univariate $n$-division
polynomials of elliptic curves, omitting a factor of the bivariate $2$-division polynomial.
## References
M Ward, *Memoir on Elliptic Divisibility Sequences*
## Tags
elliptic, divisibility, sequence
-/
universe u v w
variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] (W : ℤ → R) (f : R →+* S)
/-- The proposition that a sequence indexed by integers is an elliptic sequence. -/
def IsEllSequence : Prop :=
∀ m n r : ℤ, W (m + n) * W (m - n) * W r ^ 2 =
W (m + r) * W (m - r) * W n ^ 2 - W (n + r) * W (n - r) * W m ^ 2
/-- The proposition that a sequence indexed by integers is a divisibility sequence. -/
def IsDivSequence : Prop :=
∀ m n : ℕ, m ∣ n → W m ∣ W n
/-- The proposition that a sequence indexed by integers is an EDS. -/
def IsEllDivSequence : Prop :=
IsEllSequence W ∧ IsDivSequence W
lemma isEllSequence_id : IsEllSequence id :=
fun _ _ _ => by simp only [id_eq]; ring1
lemma isDivSequence_id : IsDivSequence id :=
fun _ _ => Int.ofNat_dvd.mpr
/-- The identity sequence is an EDS. -/
theorem isEllDivSequence_id : IsEllDivSequence id :=
⟨isEllSequence_id, isDivSequence_id⟩
variable {W}
lemma IsEllSequence.smul (h : IsEllSequence W) (x : R) : IsEllSequence (x • W) :=
fun m n r => by
linear_combination (norm := (simp only [Pi.smul_apply, smul_eq_mul]; ring1)) x ^ 4 * h m n r
lemma IsDivSequence.smul (h : IsDivSequence W) (x : R) : IsDivSequence (x • W) :=
fun m n r => mul_dvd_mul_left x <| h m n r
lemma IsEllDivSequence.smul (h : IsEllDivSequence W) (x : R) : IsEllDivSequence (x • W) :=
⟨h.left.smul x, h.right.smul x⟩
/-- The auxiliary sequence for a normalised EDS `W : ℕ → R`, with initial values
`W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`. -/
def preNormEDS' (b c d : R) : ℕ → R
| 0 => 0
| 1 => 1
| 2 => 1
| 3 => c
| 4 => d
| (n + 5) => let m := n / 2
have h4 : m + 4 < n + 5 := Nat.lt_succ.mpr <| add_le_add_right (n.div_le_self 2) 4
have h3 : m + 3 < n + 5 := (lt_add_one _).trans h4
have h2 : m + 2 < n + 5 := (lt_add_one _).trans h3
have h1 : m + 1 < n + 5 := (lt_add_one _).trans h2
if hn : Even n then
preNormEDS' b c d (m + 4) * preNormEDS' b c d (m + 2) ^ 3 * (if Even m then b else 1) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) ^ 3 * (if Even m then 1 else b)
else
have h5 : m + 5 < n + 5 := add_lt_add_right
(Nat.div_lt_self (Nat.odd_iff_not_even.mpr hn).pos <| Nat.lt_succ_self 1) 5
preNormEDS' b c d (m + 2) ^ 2 * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 5) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 4) ^ 2
variable (b c d : R)
@[simp]
lemma preNormEDS'_zero : preNormEDS' b c d 0 = 0 := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_one : preNormEDS' b c d 1 = 1 := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_two : preNormEDS' b c d 2 = 1 := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_three : preNormEDS' b c d 3 = c := by
rw [preNormEDS']
@[simp]
lemma preNormEDS'_four : preNormEDS' b c d 4 = d := by
rw [preNormEDS']
lemma preNormEDS'_odd (m : ℕ) : preNormEDS' b c d (2 * (m + 2) + 1) =
preNormEDS' b c d (m + 4) * preNormEDS' b c d (m + 2) ^ 3 * (if Even m then b else 1) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) ^ 3 * (if Even m then 1 else b) := by
rw [show 2 * (m + 2) + 1 = 2 * m + 5 by rfl, preNormEDS', dif_pos <| even_two_mul _]
simp only [m.mul_div_cancel_left two_pos]
lemma preNormEDS'_even (m : ℕ) : preNormEDS' b c d (2 * (m + 3)) =
preNormEDS' b c d (m + 2) ^ 2 * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 5) -
preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 4) ^ 2 := by
rw [show 2 * (m + 3) = 2 * m + 1 + 5 by rfl, preNormEDS', dif_neg m.not_even_two_mul_add_one]
simp only [Nat.mul_add_div two_pos]
rfl
/-- The auxiliary sequence for a normalised EDS `W : ℤ → R`, with initial values
`W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`.
This extends `preNormEDS'` by defining its values at negative integers. -/
def preNormEDS (n : ℤ) : R :=
n.sign * preNormEDS' b c d n.natAbs
@[simp]
lemma preNormEDS_ofNat (n : ℕ) : preNormEDS b c d n = preNormEDS' b c d n := by
by_cases hn : n = 0
· rw [hn, preNormEDS, Nat.cast_zero, Int.sign_zero, Int.cast_zero, zero_mul, preNormEDS'_zero]
· rw [preNormEDS, Int.sign_natCast_of_ne_zero hn, Int.cast_one, one_mul, Int.natAbs_cast]
@[simp]
lemma preNormEDS_zero : preNormEDS b c d 0 = 0 := by
erw [preNormEDS_ofNat, preNormEDS'_zero]
@[simp]
lemma preNormEDS_one : preNormEDS b c d 1 = 1 := by
erw [preNormEDS_ofNat, preNormEDS'_one]
@[simp]
lemma preNormEDS_two : preNormEDS b c d 2 = 1 := by
erw [preNormEDS_ofNat, preNormEDS'_two]
@[simp]
lemma preNormEDS_three : preNormEDS b c d 3 = c := by
erw [preNormEDS_ofNat, preNormEDS'_three]
@[simp]
lemma preNormEDS_four : preNormEDS b c d 4 = d := by
erw [preNormEDS_ofNat, preNormEDS'_four]
lemma preNormEDS_odd (m : ℕ) : preNormEDS b c d (2 * (m + 2) + 1) =
preNormEDS b c d (m + 4) * preNormEDS b c d (m + 2) ^ 3 * (if Even m then b else 1) -
preNormEDS b c d (m + 1) * preNormEDS b c d (m + 3) ^ 3 * (if Even m then 1 else b) := by
repeat erw [preNormEDS_ofNat]
exact preNormEDS'_odd ..
lemma preNormEDS_even (m : ℕ) : preNormEDS b c d (2 * (m + 3)) =
preNormEDS b c d (m + 2) ^ 2 * preNormEDS b c d (m + 3) * preNormEDS b c d (m + 5) -
preNormEDS b c d (m + 1) * preNormEDS b c d (m + 3) * preNormEDS b c d (m + 4) ^ 2 := by
repeat erw [preNormEDS_ofNat]
exact preNormEDS'_even ..
@[simp]
lemma preNormEDS_neg (n : ℤ) : preNormEDS b c d (-n) = -preNormEDS b c d n := by
rw [preNormEDS, Int.sign_neg, Int.cast_neg, neg_mul, Int.natAbs_neg, preNormEDS]
/-- The canonical example of a normalised EDS `W : ℤ → R`, with initial values
`W(0) = 0`, `W(1) = 1`, `W(2) = b`, `W(3) = c`, and `W(4) = d * b`.
This is defined in terms of `preNormEDS` whose even terms differ by a factor of `b`. -/
def normEDS (n : ℤ) : R :=
preNormEDS (b ^ 4) c d n * if Even n then b else 1
@[simp]
lemma normEDS_ofNat (n : ℕ) :
normEDS b c d n = preNormEDS' (b ^ 4) c d n * if Even n then b else 1 := by
simp only [normEDS, preNormEDS_ofNat, Int.even_coe_nat]
@[simp]
lemma normEDS_zero : normEDS b c d 0 = 0 := by
erw [normEDS_ofNat, preNormEDS'_zero, zero_mul]
@[simp]
lemma normEDS_one : normEDS b c d 1 = 1 := by
erw [normEDS_ofNat, preNormEDS'_one, one_mul, if_neg Nat.not_even_one]
@[simp]
lemma normEDS_two : normEDS b c d 2 = b := by
erw [normEDS_ofNat, preNormEDS'_two, one_mul, if_pos even_two]
@[simp]
lemma normEDS_three : normEDS b c d 3 = c := by
erw [normEDS_ofNat, preNormEDS'_three, if_neg <| by decide, mul_one]
@[simp]
lemma normEDS_four : normEDS b c d 4 = d * b := by
erw [normEDS_ofNat, preNormEDS'_four, if_pos <| by decide]
lemma normEDS_odd (m : ℕ) : normEDS b c d (2 * (m + 2) + 1) =
normEDS b c d (m + 4) * normEDS b c d (m + 2) ^ 3 -
normEDS b c d (m + 1) * normEDS b c d (m + 3) ^ 3 := by
repeat erw [normEDS_ofNat]
simp_rw [preNormEDS'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not]
split_ifs <;> ring1
lemma normEDS_even (m : ℕ) : normEDS b c d (2 * (m + 3)) * b =
normEDS b c d (m + 2) ^ 2 * normEDS b c d (m + 3) * normEDS b c d (m + 5) -
normEDS b c d (m + 1) * normEDS b c d (m + 3) * normEDS b c d (m + 4) ^ 2 := by
repeat erw [normEDS_ofNat]
simp only [preNormEDS'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not]
split_ifs <;> ring1
@[simp]
lemma normEDS_neg (n : ℤ) : normEDS b c d (-n) = -normEDS b c d n := by
simp only [normEDS, preNormEDS_neg, neg_mul, even_neg]
/-- Strong recursion principle for a normalised EDS: if we have
* `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`,
* for all `m : ℕ` we can prove `P (2 * (m + 3))` from `P k` for all `k < 2 * (m + 3)`, and
* for all `m : ℕ` we can prove `P (2 * (m + 2) + 1)` from `P k` for all `k < 2 * (m + 2) + 1`,
then we have `P n` for all `n : ℕ`. -/
@[elab_as_elim]
noncomputable def normEDSRec' {P : ℕ → Sort u}
(zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4)
(even : ∀ m : ℕ, (∀ k < 2 * (m + 3), P k) → P (2 * (m + 3)))
(odd : ∀ m : ℕ, (∀ k < 2 * (m + 2) + 1, P k) → P (2 * (m + 2) + 1)) (n : ℕ) : P n :=
n.evenOddStrongRec (by rintro (_ | _ | _ | _) h; exacts [zero, two, four, even _ h])
(by rintro (_ | _ | _) h; exacts [one, three, odd _ h])
/-- Recursion principle for a normalised EDS: if we have
* `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`,
* for all `m : ℕ` we can prove `P (2 * (m + 3))` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`,
`P (m + 4)`, and `P (m + 5)`, and
* for all `m : ℕ` we can prove `P (2 * (m + 2) + 1)` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`,
and `P (m + 4)`,
then we have `P n` for all `n : ℕ`. -/
@[elab_as_elim]
noncomputable def normEDSRec {P : ℕ → Sort u}
(zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4)
(even : ∀ m : ℕ, P (m + 1) → P (m + 2) → P (m + 3) → P (m + 4) → P (m + 5) → P (2 * (m + 3)))
(odd : ∀ m : ℕ, P (m + 1) → P (m + 2) → P (m + 3) → P (m + 4) → P (2 * (m + 2) + 1)) (n : ℕ) :
P n :=
normEDSRec' zero one two three four
(fun _ ih => by apply even <;> exact ih _ <| by linarith only)
(fun _ ih => by apply odd <;> exact ih _ <| by linarith only) n
lemma map_preNormEDS' (n : ℕ) : f (preNormEDS' b c d n) = preNormEDS' (f b) (f c) (f d) n := by
induction n using normEDSRec' with
| zero => rw [preNormEDS'_zero, map_zero, preNormEDS'_zero]
| one => rw [preNormEDS'_one, map_one, preNormEDS'_one]
| two => rw [preNormEDS'_two, map_one, preNormEDS'_two]
| three => rw [preNormEDS'_three, preNormEDS'_three]
| four => rw [preNormEDS'_four, preNormEDS'_four]
| _ _ ih =>
simp only [preNormEDS'_odd, preNormEDS'_even, map_one, map_sub, map_mul, map_pow, apply_ite f]
repeat rw [ih _ <| by linarith only]
lemma map_preNormEDS (n : ℤ) : f (preNormEDS b c d n) = preNormEDS (f b) (f c) (f d) n := by
rw [preNormEDS, map_mul, map_intCast, map_preNormEDS', preNormEDS]
lemma map_normEDS (n : ℤ) : f (normEDS b c d n) = normEDS (f b) (f c) (f d) n := by
rw [normEDS, map_mul, map_preNormEDS, map_pow, apply_ite f, map_one, normEDS]
|
NumberTheory\FermatPsp.lean | /-
Copyright (c) 2022 Niels Voss. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Niels Voss
-/
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.Order.Filter.Cofinite
/-!
# Fermat Pseudoprimes
In this file we define Fermat pseudoprimes: composite numbers that pass the Fermat primality test.
A natural number `n` passes the Fermat primality test to base `b` (and is therefore deemed a
"probable prime") if `n` divides `b ^ (n - 1) - 1`. `n` is a Fermat pseudoprime to base `b` if `n`
is a composite number that passes the Fermat primality test to base `b` and is coprime with `b`.
Fermat pseudoprimes can also be seen as composite numbers for which Fermat's little theorem holds
true.
Numbers which are Fermat pseudoprimes to all bases are known as Carmichael numbers (not yet defined
in this file).
## Main Results
The main definitions for this file are
- `Nat.ProbablePrime`: A number `n` is a probable prime to base `b` if it passes the Fermat
primality test; that is, if `n` divides `b ^ (n - 1) - 1`
- `Nat.FermatPsp`: A number `n` is a pseudoprime to base `b` if it is a probable prime to base `b`,
is composite, and is coprime with `b` (this last condition is automatically true if `n` divides
`b ^ (n - 1) - 1`, but some sources include it in the definition).
Note that all composite numbers are pseudoprimes to base 0 and 1, and that the definition of
`Nat.ProbablePrime` in this file implies that all numbers are probable primes to bases 0 and 1, and
that 0 and 1 are probable primes to any base.
The main theorems are
- `Nat.exists_infinite_pseudoprimes`: there are infinite pseudoprimes to any base `b ≥ 1`
-/
namespace Nat
/--
`n` is a probable prime to base `b` if `n` passes the Fermat primality test; that is, `n` divides
`b ^ (n - 1) - 1`.
This definition implies that all numbers are probable primes to base 0 or 1, and that 0 and 1 are
probable primes to any base.
-/
def ProbablePrime (n b : ℕ) : Prop :=
n ∣ b ^ (n - 1) - 1
/--
`n` is a Fermat pseudoprime to base `b` if `n` is a probable prime to base `b` and is composite. By
this definition, all composite natural numbers are pseudoprimes to base 0 and 1. This definition
also permits `n` to be less than `b`, so that 4 is a pseudoprime to base 5, for example.
-/
def FermatPsp (n b : ℕ) : Prop :=
ProbablePrime n b ∧ ¬n.Prime ∧ 1 < n
instance decidableProbablePrime (n b : ℕ) : Decidable (ProbablePrime n b) :=
Nat.decidable_dvd _ _
instance decidablePsp (n b : ℕ) : Decidable (FermatPsp n b) :=
And.decidable
/-- If `n` passes the Fermat primality test to base `b`, then `n` is coprime with `b`, assuming that
`n` and `b` are both positive.
-/
theorem coprime_of_probablePrime {n b : ℕ} (h : ProbablePrime n b) (h₁ : 1 ≤ n) (h₂ : 1 ≤ b) :
Nat.Coprime n b := by
by_cases h₃ : 2 ≤ n
· -- To prove that `n` is coprime with `b`, we need to show that for all prime factors of `n`,
-- we can derive a contradiction if `n` divides `b`.
apply Nat.coprime_of_dvd
-- If `k` is a prime number that divides both `n` and `b`, then we know that `n = m * k` and
-- `b = j * k` for some natural numbers `m` and `j`. We substitute these into the hypothesis.
rintro k hk ⟨m, rfl⟩ ⟨j, rfl⟩
-- Because prime numbers do not divide 1, it suffices to show that `k ∣ 1` to prove a
-- contradiction
apply Nat.Prime.not_dvd_one hk
-- Since `n` divides `b ^ (n - 1) - 1`, `k` also divides `b ^ (n - 1) - 1`
replace h := dvd_of_mul_right_dvd h
-- Because `k` divides `b ^ (n - 1) - 1`, if we can show that `k` also divides `b ^ (n - 1)`,
-- then we know `k` divides 1.
rw [Nat.dvd_add_iff_right h, Nat.sub_add_cancel (Nat.one_le_pow _ _ h₂)]
-- Since `k` divides `b`, `k` also divides any power of `b` except `b ^ 0`. Therefore, it
-- suffices to show that `n - 1` isn't zero. However, we know that `n - 1` isn't zero because we
-- assumed `2 ≤ n` when doing `by_cases`.
refine dvd_of_mul_right_dvd (dvd_pow_self (k * j) ?_)
omega
-- If `n = 1`, then it follows trivially that `n` is coprime with `b`.
· rw [show n = 1 by omega]
norm_num
theorem probablePrime_iff_modEq (n : ℕ) {b : ℕ} (h : 1 ≤ b) :
ProbablePrime n b ↔ b ^ (n - 1) ≡ 1 [MOD n] := by
have : 1 ≤ b ^ (n - 1) := one_le_pow_of_one_le h (n - 1)
-- For exact mod_cast
rw [Nat.ModEq.comm]
constructor
· intro h₁
apply Nat.modEq_of_dvd
exact mod_cast h₁
· intro h₁
exact mod_cast Nat.ModEq.dvd h₁
/-- If `n` is a Fermat pseudoprime to base `b`, then `n` is coprime with `b`, assuming that `b` is
positive.
This lemma is a small wrapper based on `coprime_of_probablePrime`
-/
theorem coprime_of_fermatPsp {n b : ℕ} (h : FermatPsp n b) (h₁ : 1 ≤ b) : Nat.Coprime n b := by
rcases h with ⟨hp, _, hn₂⟩
exact coprime_of_probablePrime hp (by omega) h₁
/-- All composite numbers are Fermat pseudoprimes to base 1.
-/
theorem fermatPsp_base_one {n : ℕ} (h₁ : 1 < n) (h₂ : ¬n.Prime) : FermatPsp n 1 := by
refine ⟨show n ∣ 1 ^ (n - 1) - 1 from ?_, h₂, h₁⟩
exact show 0 = 1 ^ (n - 1) - 1 by norm_num ▸ dvd_zero n
-- Lemmas that are needed to prove statements in this file, but aren't directly related to Fermat
-- pseudoprimes
section HelperLemmas
private theorem a_id_helper {a b : ℕ} (ha : 2 ≤ a) (hb : 2 ≤ b) : 2 ≤ (a ^ b - 1) / (a - 1) := by
change 1 < _
have h₁ : a - 1 ∣ a ^ b - 1 := by simpa only [one_pow] using nat_sub_dvd_pow_sub_pow a 1 b
rw [Nat.lt_div_iff_mul_lt h₁, mul_one, tsub_lt_tsub_iff_right (Nat.le_of_succ_le ha)]
exact lt_self_pow (Nat.lt_of_succ_le ha) hb
private theorem b_id_helper {a b : ℕ} (ha : 2 ≤ a) (hb : 2 < b) : 2 ≤ (a ^ b + 1) / (a + 1) := by
rw [Nat.le_div_iff_mul_le (Nat.zero_lt_succ _)]
apply Nat.succ_le_succ
calc
2 * a + 1 ≤ a ^ 2 * a := by nlinarith
_ = a ^ 3 := by rw [Nat.pow_succ a 2]
_ ≤ a ^ b := pow_le_pow_right (Nat.le_of_succ_le ha) hb
private theorem AB_id_helper (b p : ℕ) (_ : 2 ≤ b) (hp : Odd p) :
(b ^ p - 1) / (b - 1) * ((b ^ p + 1) / (b + 1)) = (b ^ (2 * p) - 1) / (b ^ 2 - 1) := by
have q₁ : b - 1 ∣ b ^ p - 1 := by simpa only [one_pow] using nat_sub_dvd_pow_sub_pow b 1 p
have q₂ : b + 1 ∣ b ^ p + 1 := by simpa only [one_pow] using hp.nat_add_dvd_pow_add_pow b 1
convert Nat.div_mul_div_comm q₁ q₂ using 2 <;> rw [mul_comm (_ - 1), ← Nat.sq_sub_sq]
ring_nf
/-- Used in the proof of `psp_from_prime_psp`
-/
private theorem bp_helper {b p : ℕ} (hb : 0 < b) (hp : 1 ≤ p) :
b ^ (2 * p) - 1 - (b ^ 2 - 1) = b * (b ^ (p - 1) - 1) * (b ^ p + b) :=
have hi_bsquared : 1 ≤ b ^ 2 := Nat.one_le_pow _ _ hb
calc
b ^ (2 * p) - 1 - (b ^ 2 - 1) = b ^ (2 * p) - (1 + (b ^ 2 - 1)) := by rw [Nat.sub_sub]
_ = b ^ (2 * p) - (1 + b ^ 2 - 1) := by rw [Nat.add_sub_assoc hi_bsquared]
_ = b ^ (2 * p) - b ^ 2 := by rw [Nat.add_sub_cancel_left]
_ = b ^ (p * 2) - b ^ 2 := by rw [mul_comm]
_ = (b ^ p) ^ 2 - b ^ 2 := by rw [pow_mul]
_ = (b ^ p + b) * (b ^ p - b) := by rw [Nat.sq_sub_sq]
_ = (b ^ p - b) * (b ^ p + b) := by rw [mul_comm]
_ = (b ^ (p - 1 + 1) - b) * (b ^ p + b) := by rw [Nat.sub_add_cancel hp]
_ = (b * b ^ (p - 1) - b) * (b ^ p + b) := by rw [pow_succ']
_ = (b * b ^ (p - 1) - b * 1) * (b ^ p + b) := by rw [mul_one]
_ = b * (b ^ (p - 1) - 1) * (b ^ p + b) := by rw [Nat.mul_sub_left_distrib]
end HelperLemmas
/-- Given a prime `p` which does not divide `b * (b ^ 2 - 1)`, we can produce a number `n` which is
larger than `p` and pseudoprime to base `b`. We do this by defining
`n = ((b ^ p - 1) / (b - 1)) * ((b ^ p + 1) / (b + 1))`
The primary purpose of this definition is to help prove `exists_infinite_pseudoprimes`. For a proof
that `n` is actually pseudoprime to base `b`, see `psp_from_prime_psp`, and for a proof that `n` is
greater than `p`, see `psp_from_prime_gt_p`.
This lemma is intended to be used when `2 ≤ b`, `2 < p`, `p` is prime, and `¬p ∣ b * (b ^ 2 - 1)`,
because those are the hypotheses for `psp_from_prime_psp`.
-/
private def psp_from_prime (b : ℕ) (p : ℕ) : ℕ :=
(b ^ p - 1) / (b - 1) * ((b ^ p + 1) / (b + 1))
/--
This is a proof that the number produced using `psp_from_prime` is actually pseudoprime to base `b`.
The primary purpose of this lemma is to help prove `exists_infinite_pseudoprimes`.
We use <https://primes.utm.edu/notes/proofs/a_pseudoprimes.html> as a rough outline of the proof.
-/
private theorem psp_from_prime_psp {b : ℕ} (b_ge_two : 2 ≤ b) {p : ℕ} (p_prime : p.Prime)
(p_gt_two : 2 < p) (not_dvd : ¬p ∣ b * (b ^ 2 - 1)) : FermatPsp (psp_from_prime b p) b := by
unfold psp_from_prime
set A := (b ^ p - 1) / (b - 1)
set B := (b ^ p + 1) / (b + 1)
-- Inequalities
have hi_A : 1 < A := a_id_helper (Nat.succ_le_iff.mp b_ge_two) (Nat.Prime.one_lt p_prime)
have hi_B : 1 < B := b_id_helper (Nat.succ_le_iff.mp b_ge_two) p_gt_two
have hi_AB : 1 < A * B := one_lt_mul'' hi_A hi_B
have hi_b : 0 < b := by omega
have hi_p : 1 ≤ p := Nat.one_le_of_lt p_gt_two
have hi_bsquared : 0 < b ^ 2 - 1 := by
-- Porting note: was `by nlinarith [Nat.one_le_pow 2 b hi_b]`
have h0 := mul_le_mul b_ge_two b_ge_two zero_le_two hi_b.le
have h1 : 1 < 2 * 2 := by omega
have := tsub_pos_of_lt (h1.trans_le h0)
rwa [pow_two]
have hi_bpowtwop : 1 ≤ b ^ (2 * p) := Nat.one_le_pow (2 * p) b hi_b
have hi_bpowpsubone : 1 ≤ b ^ (p - 1) := Nat.one_le_pow (p - 1) b hi_b
-- Other useful facts
have p_odd : Odd p := p_prime.odd_of_ne_two p_gt_two.ne.symm
have AB_not_prime : ¬Nat.Prime (A * B) := Nat.not_prime_mul hi_A.ne' hi_B.ne'
have AB_id : A * B = (b ^ (2 * p) - 1) / (b ^ 2 - 1) := AB_id_helper _ _ b_ge_two p_odd
have hd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1 := by
simpa only [one_pow, pow_mul] using nat_sub_dvd_pow_sub_pow _ 1 p
-- We know that `A * B` is not prime, and that `1 < A * B`. Since two conditions of being
-- pseudoprime are satisfied, we only need to show that `A * B` is probable prime to base `b`
refine ⟨?_, AB_not_prime, hi_AB⟩
-- Used to prove that `2 * p * (b ^ 2 - 1) ∣ (b ^ 2 - 1) * (A * B - 1)`.
have ha₁ : (b ^ 2 - 1) * (A * B - 1) = b * (b ^ (p - 1) - 1) * (b ^ p + b) := by
apply_fun fun x => x * (b ^ 2 - 1) at AB_id
rw [Nat.div_mul_cancel hd] at AB_id
apply_fun fun x => x - (b ^ 2 - 1) at AB_id
nth_rw 2 [← one_mul (b ^ 2 - 1)] at AB_id
rw [← Nat.mul_sub_right_distrib, mul_comm] at AB_id
rw [AB_id]
exact bp_helper hi_b hi_p
-- If `b` is even, then `b^p` is also even, so `2 ∣ b^p + b`
-- If `b` is odd, then `b^p` is also odd, so `2 ∣ b^p + b`
have ha₂ : 2 ∣ b ^ p + b := by
-- Porting note: golfed
rw [← even_iff_two_dvd, Nat.even_add, Nat.even_pow' p_prime.ne_zero]
-- Since `b` isn't divisible by `p`, `b` is coprime with `p`. we can use Fermat's Little Theorem
-- to prove this.
have ha₃ : p ∣ b ^ (p - 1) - 1 := by
have : ¬p ∣ b := mt (fun h : p ∣ b => dvd_mul_of_dvd_left h _) not_dvd
have : p.Coprime b := Or.resolve_right (Nat.coprime_or_dvd_of_prime p_prime b) this
have : IsCoprime (b : ℤ) ↑p := this.symm.isCoprime
have : ↑b ^ (p - 1) ≡ 1 [ZMOD ↑p] := Int.ModEq.pow_card_sub_one_eq_one p_prime this
have : ↑p ∣ ↑b ^ (p - 1) - ↑1 := mod_cast Int.ModEq.dvd (Int.ModEq.symm this)
exact mod_cast this
-- Because `p - 1` is even, there is a `c` such that `2 * c = p - 1`. `nat_sub_dvd_pow_sub_pow`
-- implies that `b ^ c - 1 ∣ (b ^ c) ^ 2 - 1`, and `(b ^ c) ^ 2 = b ^ (p - 1)`.
have ha₄ : b ^ 2 - 1 ∣ b ^ (p - 1) - 1 := by
cases' p_odd with k hk
have : 2 ∣ p - 1 := ⟨k, by simp [hk]⟩
cases' this with c hc
have : b ^ 2 - 1 ∣ (b ^ 2) ^ c - 1 := by
simpa only [one_pow] using nat_sub_dvd_pow_sub_pow _ 1 c
have : b ^ 2 - 1 ∣ b ^ (2 * c) - 1 := by rwa [← pow_mul] at this
rwa [← hc] at this
-- Used to prove that `2 * p` divides `A * B - 1`
have ha₅ : 2 * p * (b ^ 2 - 1) ∣ (b ^ 2 - 1) * (A * B - 1) := by
suffices q : 2 * p * (b ^ 2 - 1) ∣ b * (b ^ (p - 1) - 1) * (b ^ p + b) by rwa [ha₁]
-- We already proved that `b ^ 2 - 1 ∣ b ^ (p - 1) - 1`.
-- Since `2 ∣ b ^ p + b` and `p ∣ b ^ p + b`, if we show that 2 and p are coprime, then we
-- know that `2 * p ∣ b ^ p + b`
have q₁ : Nat.Coprime p (b ^ 2 - 1) :=
haveI q₂ : ¬p ∣ b ^ 2 - 1 := by
rw [mul_comm] at not_dvd
exact mt (fun h : p ∣ b ^ 2 - 1 => dvd_mul_of_dvd_left h _) not_dvd
(Nat.Prime.coprime_iff_not_dvd p_prime).mpr q₂
have q₂ : p * (b ^ 2 - 1) ∣ b ^ (p - 1) - 1 := Nat.Coprime.mul_dvd_of_dvd_of_dvd q₁ ha₃ ha₄
have q₃ : p * (b ^ 2 - 1) * 2 ∣ (b ^ (p - 1) - 1) * (b ^ p + b) := mul_dvd_mul q₂ ha₂
have q₄ : p * (b ^ 2 - 1) * 2 ∣ b * ((b ^ (p - 1) - 1) * (b ^ p + b)) :=
dvd_mul_of_dvd_right q₃ _
rwa [mul_assoc, mul_comm, mul_assoc b]
have ha₆ : 2 * p ∣ A * B - 1 := by
rw [mul_comm] at ha₅
exact Nat.dvd_of_mul_dvd_mul_left hi_bsquared ha₅
-- `A * B` divides `b ^ (2 * p) - 1` because `A * B * (b ^ 2 - 1) = b ^ (2 * p) - 1`.
-- This can be proven by multiplying both sides of `AB_id` by `b ^ 2 - 1`.
have ha₇ : A * B ∣ b ^ (2 * p) - 1 := by
use b ^ 2 - 1
have : A * B * (b ^ 2 - 1) = (b ^ (2 * p) - 1) / (b ^ 2 - 1) * (b ^ 2 - 1) :=
congr_arg (fun x : ℕ => x * (b ^ 2 - 1)) AB_id
simpa only [add_comm, Nat.div_mul_cancel hd, Nat.sub_add_cancel hi_bpowtwop] using this.symm
-- Since `2 * p ∣ A * B - 1`, there is a number `q` such that `2 * p * q = A * B - 1`.
-- By `nat_sub_dvd_pow_sub_pow`, we know that `b ^ (2 * p) - 1 ∣ b ^ (2 * p * q) - 1`.
-- This means that `b ^ (2 * p) - 1 ∣ b ^ (A * B - 1) - 1`.
cases' ha₆ with q hq
have ha₈ : b ^ (2 * p) - 1 ∣ b ^ (A * B - 1) - 1 := by
simpa only [one_pow, pow_mul, hq] using nat_sub_dvd_pow_sub_pow _ 1 q
-- We have proved that `A * B ∣ b ^ (2 * p) - 1` and `b ^ (2 * p) - 1 ∣ b ^ (A * B - 1) - 1`.
-- Therefore, `A * B ∣ b ^ (A * B - 1) - 1`.
exact dvd_trans ha₇ ha₈
/--
This is a proof that the number produced using `psp_from_prime` is greater than the prime `p` used
to create it. The primary purpose of this lemma is to help prove `exists_infinite_pseudoprimes`.
-/
private theorem psp_from_prime_gt_p {b : ℕ} (b_ge_two : 2 ≤ b) {p : ℕ} (p_prime : p.Prime)
(p_gt_two : 2 < p) : p < psp_from_prime b p := by
unfold psp_from_prime
set A := (b ^ p - 1) / (b - 1)
set B := (b ^ p + 1) / (b + 1)
rw [show A * B = (b ^ (2 * p) - 1) / (b ^ 2 - 1) from
AB_id_helper _ _ b_ge_two (p_prime.odd_of_ne_two p_gt_two.ne.symm)]
have AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1 := by
simpa only [one_pow, pow_mul] using nat_sub_dvd_pow_sub_pow _ 1 p
suffices h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1 by
have h₁ : p * (b ^ 2 - 1) / (b ^ 2 - 1) < (b ^ (2 * p) - 1) / (b ^ 2 - 1) :=
Nat.div_lt_div_of_lt_of_dvd AB_dvd h
have h₂ : 0 < b ^ 2 - 1 := by
linarith [show 3 ≤ b ^ 2 - 1 from le_tsub_of_add_le_left (show 4 ≤ b ^ 2 by nlinarith)]
rwa [Nat.mul_div_cancel _ h₂] at h₁
rw [Nat.mul_sub_left_distrib, mul_one, pow_mul]
conv_rhs => rw [← Nat.sub_add_cancel (show 1 ≤ p by omega)]
rw [Nat.pow_succ (b ^ 2)]
suffices h : p * b ^ 2 < (b ^ 2) ^ (p - 1) * b ^ 2 by
apply gt_of_ge_of_gt
· exact tsub_le_tsub_left (one_le_of_lt p_gt_two) ((b ^ 2) ^ (p - 1) * b ^ 2)
· have : p ≤ p * b ^ 2 := Nat.le_mul_of_pos_right _ (show 0 < b ^ 2 by nlinarith)
exact tsub_lt_tsub_right_of_le this h
suffices h : p < (b ^ 2) ^ (p - 1) by
have : 4 ≤ b ^ 2 := by nlinarith
have : 0 < b ^ 2 := by omega
exact mul_lt_mul_of_pos_right h this
rw [← pow_mul, Nat.mul_sub_left_distrib, mul_one]
have : 2 ≤ 2 * p - 2 := le_tsub_of_add_le_left (show 4 ≤ 2 * p by omega)
have : 2 + p ≤ 2 * p := by omega
have : p ≤ 2 * p - 2 := le_tsub_of_add_le_left this
exact this.trans_lt (lt_pow_self b_ge_two _)
/-- For all positive bases, there exist infinite **Fermat pseudoprimes** to that base.
Given in this form: for all numbers `b ≥ 1` and `m`, there exists a pseudoprime `n` to base `b` such
that `m ≤ n`. This form is similar to `Nat.exists_infinite_primes`.
-/
theorem exists_infinite_pseudoprimes {b : ℕ} (h : 1 ≤ b) (m : ℕ) :
∃ n : ℕ, FermatPsp n b ∧ m ≤ n := by
by_cases b_ge_two : 2 ≤ b
-- If `2 ≤ b`, then because there exist infinite prime numbers, there is a prime number p with
-- `m ≤ p` and `¬p ∣ b*(b^2 - 1)`. We pick a prime number `b*(b^2 - 1) + 1 + m ≤ p` because we
-- automatically know that `p` is greater than m and that it does not divide `b*(b^2 - 1)`
-- (because `p` can't divide a number less than `p`).
-- From `p`, we can use the lemmas we proved earlier to show that
-- `((b^p - 1)/(b - 1)) * ((b^p + 1)/(b + 1))` is a pseudoprime to base `b`.
· have h := Nat.exists_infinite_primes (b * (b ^ 2 - 1) + 1 + m)
cases' h with p hp
cases' hp with hp₁ hp₂
have h₁ : 0 < b := pos_of_gt (Nat.succ_le_iff.mp b_ge_two)
have h₂ : 4 ≤ b ^ 2 := pow_le_pow_left' b_ge_two 2
have h₃ : 0 < b ^ 2 - 1 := tsub_pos_of_lt (gt_of_ge_of_gt h₂ (by norm_num))
have h₄ : 0 < b * (b ^ 2 - 1) := mul_pos h₁ h₃
have h₅ : b * (b ^ 2 - 1) < p := by omega
have h₆ : ¬p ∣ b * (b ^ 2 - 1) := Nat.not_dvd_of_pos_of_lt h₄ h₅
have h₇ : b ≤ b * (b ^ 2 - 1) := Nat.le_mul_of_pos_right _ h₃
have h₈ : 2 ≤ b * (b ^ 2 - 1) := le_trans b_ge_two h₇
have h₉ : 2 < p := gt_of_gt_of_ge h₅ h₈
have h₁₀ := psp_from_prime_gt_p b_ge_two hp₂ h₉
use psp_from_prime b p
constructor
· exact psp_from_prime_psp b_ge_two hp₂ h₉ h₆
· exact le_trans (show m ≤ p by omega) (le_of_lt h₁₀)
-- If `¬2 ≤ b`, then `b = 1`. Since all composite numbers are pseudoprimes to base 1, we can pick
-- any composite number greater than m. We choose `2 * (m + 2)` because it is greater than `m` and
-- is composite for all natural numbers `m`.
· have h₁ : b = 1 := by omega
rw [h₁]
use 2 * (m + 2)
have : ¬Nat.Prime (2 * (m + 2)) := Nat.not_prime_mul (by omega) (by omega)
exact ⟨fermatPsp_base_one (by omega) this, by omega⟩
theorem frequently_atTop_fermatPsp {b : ℕ} (h : 1 ≤ b) : ∃ᶠ n in Filter.atTop, FermatPsp n b := by
-- Based on the proof of `Nat.frequently_atTop_modEq_one`
refine Filter.frequently_atTop.2 fun n => ?_
obtain ⟨p, hp⟩ := exists_infinite_pseudoprimes h n
exact ⟨p, hp.2, hp.1⟩
/-- Infinite set variant of `Nat.exists_infinite_pseudoprimes`
-/
theorem infinite_setOf_pseudoprimes {b : ℕ} (h : 1 ≤ b) :
Set.Infinite { n : ℕ | FermatPsp n b } :=
Nat.frequently_atTop_iff_infinite.mp (frequently_atTop_fermatPsp h)
end Nat
|
NumberTheory\FrobeniusNumber.lean | /-
Copyright (c) 2021 Alex Zhao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Zhao
-/
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.Data.Nat.ModEq
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Zify
/-!
# Frobenius Number in Two Variables
In this file we first define a predicate for Frobenius numbers, then solve the 2-variable variant
of this problem.
## Theorem Statement
Given a finite set of relatively prime integers all greater than 1, their Frobenius number is the
largest positive integer that cannot be expressed as a sum of nonnegative multiples of these
integers. Here we show the Frobenius number of two relatively prime integers `m` and `n` greater
than 1 is `m * n - m - n`. This result is also known as the Chicken McNugget Theorem.
## Implementation Notes
First we define Frobenius numbers in general using `IsGreatest` and `AddSubmonoid.closure`. Then
we proceed to compute the Frobenius number of `m` and `n`.
For the upper bound, we begin with an auxiliary lemma showing `m * n` is not attainable, then show
`m * n - m - n` is not attainable. Then for the construction, we create a `k_1` which is `k mod n`
and `0 mod m`, then show it is at most `k`. Then `k_1` is a multiple of `m`, so `(k-k_1)`
is a multiple of n, and we're done.
## Tags
frobenius number, chicken mcnugget, chinese remainder theorem, add_submonoid.closure
-/
open Nat
/-- A natural number `n` is the **Frobenius number** of a set of natural numbers `s` if it is an
upper bound on the complement of the additive submonoid generated by `s`.
In other words, it is the largest number that can not be expressed as a sum of numbers in `s`. -/
def FrobeniusNumber (n : ℕ) (s : Set ℕ) : Prop :=
IsGreatest { k | k ∉ AddSubmonoid.closure s } n
variable {m n : ℕ}
/-- The **Chicken McNugget theorem** stating that the Frobenius number
of positive numbers `m` and `n` is `m * n - m - n`. -/
theorem frobeniusNumber_pair (cop : Coprime m n) (hm : 1 < m) (hn : 1 < n) :
FrobeniusNumber (m * n - m - n) {m, n} := by
simp_rw [FrobeniusNumber, AddSubmonoid.mem_closure_pair]
have hmn : m + n ≤ m * n := add_le_mul hm hn
constructor
· push_neg
intro a b h
apply cop.mul_add_mul_ne_mul (add_one_ne_zero a) (add_one_ne_zero b)
simp only [Nat.sub_sub, smul_eq_mul] at h
zify [hmn] at h ⊢
rw [← sub_eq_zero] at h ⊢
rw [← h]
ring
· intro k hk
dsimp at hk
contrapose! hk
let x := chineseRemainder cop 0 k
have hx : x.val < m * n := chineseRemainder_lt_mul cop 0 k (ne_bot_of_gt hm) (ne_bot_of_gt hn)
suffices key : x.1 ≤ k by
obtain ⟨a, ha⟩ := modEq_zero_iff_dvd.mp x.2.1
obtain ⟨b, hb⟩ := (modEq_iff_dvd' key).mp x.2.2
exact ⟨a, b, by rw [mul_comm, ← ha, mul_comm, ← hb, Nat.add_sub_of_le key]⟩
refine ModEq.le_of_lt_add x.2.2 (lt_of_le_of_lt ?_ (add_lt_add_right hk n))
rw [Nat.sub_add_cancel (le_tsub_of_add_le_left hmn)]
exact
ModEq.le_of_lt_add
(x.2.1.trans (modEq_zero_iff_dvd.mpr (Nat.dvd_sub' (dvd_mul_right m n) dvd_rfl)).symm)
(lt_of_lt_of_le hx le_tsub_add)
|
NumberTheory\FunctionField.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Ashvni Narayanan
-/
import Mathlib.Algebra.Order.Group.TypeTags
import Mathlib.FieldTheory.RatFunc.Degree
import Mathlib.RingTheory.DedekindDomain.IntegralClosure
import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed
import Mathlib.Topology.Algebra.Valued.ValuedField
/-!
# Function fields
This file defines a function field and the ring of integers corresponding to it.
## Main definitions
- `FunctionField Fq F` states that `F` is a function field over the (finite) field `Fq`,
i.e. it is a finite extension of the field of rational functions in one variable over `Fq`.
- `FunctionField.ringOfIntegers` defines the ring of integers corresponding to a function field
as the integral closure of `Fq[X]` in the function field.
- `FunctionField.inftyValuation` : The place at infinity on `Fq(t)` is the nonarchimedean
valuation on `Fq(t)` with uniformizer `1/t`.
- `FunctionField.FqtInfty` : The completion `Fq((t⁻¹))` of `Fq(t)` with respect to the
valuation at infinity.
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice. We also omit assumptions like `Finite Fq` or
`IsScalarTower Fq[X] (FractionRing Fq[X]) F` in definitions,
adding them back in lemmas when they are needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic]
* [P. Samuel, *Algebraic Theory of Numbers*][samuel1970algebraic]
## Tags
function field, ring of integers
-/
noncomputable section
open scoped nonZeroDivisors Polynomial DiscreteValuation
variable (Fq F : Type) [Field Fq] [Field F]
/-- `F` is a function field over the finite field `Fq` if it is a finite
extension of the field of rational functions in one variable over `Fq`.
Note that `F` can be a function field over multiple, non-isomorphic, `Fq`.
-/
abbrev FunctionField [Algebra (RatFunc Fq) F] : Prop :=
FiniteDimensional (RatFunc Fq) F
-- Porting note: Removed `protected`
/-- `F` is a function field over `Fq` iff it is a finite extension of `Fq(t)`. -/
theorem functionField_iff (Fqt : Type*) [Field Fqt] [Algebra Fq[X] Fqt]
[IsFractionRing Fq[X] Fqt] [Algebra (RatFunc Fq) F] [Algebra Fqt F] [Algebra Fq[X] F]
[IsScalarTower Fq[X] Fqt F] [IsScalarTower Fq[X] (RatFunc Fq) F] :
FunctionField Fq F ↔ FiniteDimensional Fqt F := by
let e := IsLocalization.algEquiv Fq[X]⁰ (RatFunc Fq) Fqt
have : ∀ (c) (x : F), e c • x = c • x := by
intro c x
rw [Algebra.smul_def, Algebra.smul_def]
congr
refine congr_fun (f := fun c => algebraMap Fqt F (e c)) ?_ c -- Porting note: Added `(f := _)`
refine IsLocalization.ext (nonZeroDivisors Fq[X]) _ _ ?_ ?_ ?_ ?_ ?_ <;> intros <;>
simp only [map_one, map_mul, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply]
constructor <;> intro h
· let b := FiniteDimensional.finBasis (RatFunc Fq) F
exact FiniteDimensional.of_fintype_basis (b.mapCoeffs e this)
· let b := FiniteDimensional.finBasis Fqt F
refine FiniteDimensional.of_fintype_basis (b.mapCoeffs e.symm ?_)
intro c x; convert (this (e.symm c) x).symm; simp only [e.apply_symm_apply]
theorem algebraMap_injective [Algebra Fq[X] F] [Algebra (RatFunc Fq) F]
[IsScalarTower Fq[X] (RatFunc Fq) F] : Function.Injective (⇑(algebraMap Fq[X] F)) := by
rw [IsScalarTower.algebraMap_eq Fq[X] (RatFunc Fq) F]
exact (algebraMap (RatFunc Fq) F).injective.comp (IsFractionRing.injective Fq[X] (RatFunc Fq))
namespace FunctionField
/-- The function field analogue of `NumberField.ringOfIntegers`:
`FunctionField.ringOfIntegers Fq Fqt F` is the integral closure of `Fq[t]` in `F`.
We don't actually assume `F` is a function field over `Fq` in the definition,
only when proving its properties.
-/
def ringOfIntegers [Algebra Fq[X] F] :=
integralClosure Fq[X] F
namespace ringOfIntegers
variable [Algebra Fq[X] F]
instance : IsDomain (ringOfIntegers Fq F) :=
(ringOfIntegers Fq F).isDomain
instance : IsIntegralClosure (ringOfIntegers Fq F) Fq[X] F :=
integralClosure.isIntegralClosure _ _
variable [Algebra (RatFunc Fq) F] [IsScalarTower Fq[X] (RatFunc Fq) F]
theorem algebraMap_injective : Function.Injective (⇑(algebraMap Fq[X] (ringOfIntegers Fq F))) := by
have hinj : Function.Injective (⇑(algebraMap Fq[X] F)) := by
rw [IsScalarTower.algebraMap_eq Fq[X] (RatFunc Fq) F]
exact (algebraMap (RatFunc Fq) F).injective.comp (IsFractionRing.injective Fq[X] (RatFunc Fq))
rw [injective_iff_map_eq_zero (algebraMap Fq[X] (↥(ringOfIntegers Fq F)))]
intro p hp
rw [← Subtype.coe_inj, Subalgebra.coe_zero] at hp
rw [injective_iff_map_eq_zero (algebraMap Fq[X] F)] at hinj
exact hinj p hp
theorem not_isField : ¬IsField (ringOfIntegers Fq F) := by
simpa [← (IsIntegralClosure.isIntegral_algebra Fq[X] F).isField_iff_isField
(algebraMap_injective Fq F)] using
Polynomial.not_isField Fq
variable [FunctionField Fq F]
instance : IsFractionRing (ringOfIntegers Fq F) F :=
integralClosure.isFractionRing_of_finite_extension (RatFunc Fq) F
instance : IsIntegrallyClosed (ringOfIntegers Fq F) :=
integralClosure.isIntegrallyClosedOfFiniteExtension (RatFunc Fq)
instance [Algebra.IsSeparable (RatFunc Fq) F] : IsNoetherian Fq[X] (ringOfIntegers Fq F) :=
IsIntegralClosure.isNoetherian _ (RatFunc Fq) F _
instance [Algebra.IsSeparable (RatFunc Fq) F] : IsDedekindDomain (ringOfIntegers Fq F) :=
IsIntegralClosure.isDedekindDomain Fq[X] (RatFunc Fq) F _
end ringOfIntegers
/-! ### The place at infinity on Fq(t) -/
section InftyValuation
variable [DecidableEq (RatFunc Fq)]
/-- The valuation at infinity is the nonarchimedean valuation on `Fq(t)` with uniformizer `1/t`.
Explicitly, if `f/g ∈ Fq(t)` is a nonzero quotient of polynomials, its valuation at infinity is
`Multiplicative.ofAdd(degree(f) - degree(g))`. -/
def inftyValuationDef (r : RatFunc Fq) : ℤₘ₀ :=
if r = 0 then 0 else ↑(Multiplicative.ofAdd r.intDegree)
theorem InftyValuation.map_zero' : inftyValuationDef Fq 0 = 0 :=
if_pos rfl
theorem InftyValuation.map_one' : inftyValuationDef Fq 1 = 1 :=
(if_neg one_ne_zero).trans <| by rw [RatFunc.intDegree_one, ofAdd_zero, WithZero.coe_one]
theorem InftyValuation.map_mul' (x y : RatFunc Fq) :
inftyValuationDef Fq (x * y) = inftyValuationDef Fq x * inftyValuationDef Fq y := by
rw [inftyValuationDef, inftyValuationDef, inftyValuationDef]
by_cases hx : x = 0
· rw [hx, zero_mul, if_pos (Eq.refl _), zero_mul]
· by_cases hy : y = 0
· rw [hy, mul_zero, if_pos (Eq.refl _), mul_zero]
· rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithZero.coe_mul, WithZero.coe_inj,
← ofAdd_add, RatFunc.intDegree_mul hx hy]
theorem InftyValuation.map_add_le_max' (x y : RatFunc Fq) :
inftyValuationDef Fq (x + y) ≤ max (inftyValuationDef Fq x) (inftyValuationDef Fq y) := by
by_cases hx : x = 0
· rw [hx, zero_add]
conv_rhs => rw [inftyValuationDef, if_pos (Eq.refl _)]
rw [max_eq_right (WithZero.zero_le (inftyValuationDef Fq y))]
· by_cases hy : y = 0
· rw [hy, add_zero]
conv_rhs => rw [max_comm, inftyValuationDef, if_pos (Eq.refl _)]
rw [max_eq_right (WithZero.zero_le (inftyValuationDef Fq x))]
· by_cases hxy : x + y = 0
· rw [inftyValuationDef, if_pos hxy]; exact zero_le'
· rw [inftyValuationDef, inftyValuationDef, inftyValuationDef, if_neg hx, if_neg hy,
if_neg hxy]
rw [le_max_iff, WithZero.coe_le_coe, Multiplicative.ofAdd_le, WithZero.coe_le_coe,
Multiplicative.ofAdd_le, ← le_max_iff]
exact RatFunc.intDegree_add_le hy hxy
@[simp]
theorem inftyValuation_of_nonzero {x : RatFunc Fq} (hx : x ≠ 0) :
inftyValuationDef Fq x = Multiplicative.ofAdd x.intDegree := by
rw [inftyValuationDef, if_neg hx]
/-- The valuation at infinity on `Fq(t)`. -/
def inftyValuation : Valuation (RatFunc Fq) ℤₘ₀ where
toFun := inftyValuationDef Fq
map_zero' := InftyValuation.map_zero' Fq
map_one' := InftyValuation.map_one' Fq
map_mul' := InftyValuation.map_mul' Fq
map_add_le_max' := InftyValuation.map_add_le_max' Fq
@[simp]
theorem inftyValuation_apply {x : RatFunc Fq} : inftyValuation Fq x = inftyValuationDef Fq x :=
rfl
@[simp]
theorem inftyValuation.C {k : Fq} (hk : k ≠ 0) :
inftyValuationDef Fq (RatFunc.C k) = Multiplicative.ofAdd (0 : ℤ) := by
have hCk : RatFunc.C k ≠ 0 := (map_ne_zero _).mpr hk
rw [inftyValuationDef, if_neg hCk, RatFunc.intDegree_C]
@[simp]
theorem inftyValuation.X : inftyValuationDef Fq RatFunc.X = Multiplicative.ofAdd (1 : ℤ) := by
rw [inftyValuationDef, if_neg RatFunc.X_ne_zero, RatFunc.intDegree_X]
@[simp]
theorem inftyValuation.polynomial {p : Fq[X]} (hp : p ≠ 0) :
inftyValuationDef Fq (algebraMap Fq[X] (RatFunc Fq) p) =
Multiplicative.ofAdd (p.natDegree : ℤ) := by
have hp' : algebraMap Fq[X] (RatFunc Fq) p ≠ 0 := by
rw [Ne, RatFunc.algebraMap_eq_zero_iff]; exact hp
rw [inftyValuationDef, if_neg hp', RatFunc.intDegree_polynomial]
/-- The valued field `Fq(t)` with the valuation at infinity. -/
def inftyValuedFqt : Valued (RatFunc Fq) ℤₘ₀ :=
Valued.mk' <| inftyValuation Fq
theorem inftyValuedFqt.def {x : RatFunc Fq} :
@Valued.v (RatFunc Fq) _ _ _ (inftyValuedFqt Fq) x = inftyValuationDef Fq x :=
rfl
/-- The completion `Fq((t⁻¹))` of `Fq(t)` with respect to the valuation at infinity. -/
def FqtInfty :=
@UniformSpace.Completion (RatFunc Fq) <| (inftyValuedFqt Fq).toUniformSpace
instance : Field (FqtInfty Fq) :=
letI := inftyValuedFqt Fq
UniformSpace.Completion.instField
instance : Inhabited (FqtInfty Fq) :=
⟨(0 : FqtInfty Fq)⟩
/-- The valuation at infinity on `k(t)` extends to a valuation on `FqtInfty`. -/
instance valuedFqtInfty : Valued (FqtInfty Fq) ℤₘ₀ :=
@Valued.valuedCompletion _ _ _ _ (inftyValuedFqt Fq)
theorem valuedFqtInfty.def {x : FqtInfty Fq} :
Valued.v x = @Valued.extension (RatFunc Fq) _ _ _ (inftyValuedFqt Fq) x :=
rfl
end InftyValuation
end FunctionField
|
NumberTheory\GaussSum.lean | /-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.NumberTheory.LegendreSymbol.AddCharacter
import Mathlib.NumberTheory.LegendreSymbol.ZModChar
import Mathlib.Algebra.CharP.CharAndCard
/-!
# Gauss sums
We define the Gauss sum associated to a multiplicative and an additive
character of a finite field and prove some results about them.
## Main definition
Let `R` be a finite commutative ring and let `R'` be another commutative ring.
If `χ` is a multiplicative character `R → R'` (type `MulChar R R'`) and `ψ`
is an additive character `R → R'` (type `AddChar R R'`, which abbreviates
`(Multiplicative R) →* R'`), then the *Gauss sum* of `χ` and `ψ` is `∑ a, χ a * ψ a`.
## Main results
Some important results are as follows.
* `gaussSum_mul_gaussSum_eq_card`: The product of the Gauss
sums of `χ` and `ψ` and that of `χ⁻¹` and `ψ⁻¹` is the cardinality
of the source ring `R` (if `χ` is nontrivial, `ψ` is primitive and `R` is a field).
* `gaussSum_sq`: The square of the Gauss sum is `χ(-1)` times
the cardinality of `R` if in addition `χ` is a quadratic character.
* `MulChar.IsQuadratic.gaussSum_frob`: For a quadratic character `χ`, raising
the Gauss sum to the `p`th power (where `p` is the characteristic of
the target ring `R'`) multiplies it by `χ p`.
* `Char.card_pow_card`: When `F` and `F'` are finite fields and `χ : F → F'`
is a nontrivial quadratic character, then `(χ (-1) * #F)^(#F'/2) = χ #F'`.
* `FiniteField.two_pow_card`: For every finite field `F` of odd characteristic,
we have `2^(#F/2) = χ₈ #F` in `F`.
This machinery can be used to derive (a generalization of) the Law of
Quadratic Reciprocity.
## Tags
additive character, multiplicative character, Gauss sum
-/
universe u v
open AddChar MulChar
section GaussSumDef
-- `R` is the domain of the characters
variable {R : Type u} [CommRing R] [Fintype R]
-- `R'` is the target of the characters
variable {R' : Type v} [CommRing R']
/-!
### Definition and first properties
-/
/-- Definition of the Gauss sum associated to a multiplicative and an additive character. -/
def gaussSum (χ : MulChar R R') (ψ : AddChar R R') : R' :=
∑ a, χ a * ψ a
/-- Replacing `ψ` by `mulShift ψ a` and multiplying the Gauss sum by `χ a` does not change it. -/
theorem gaussSum_mulShift (χ : MulChar R R') (ψ : AddChar R R') (a : Rˣ) :
χ a * gaussSum χ (mulShift ψ a) = gaussSum χ ψ := by
simp only [gaussSum, mulShift_apply, Finset.mul_sum]
simp_rw [← mul_assoc, ← map_mul]
exact Fintype.sum_bijective _ a.mulLeft_bijective _ _ fun x ↦ rfl
end GaussSumDef
/-!
### The product of two Gauss sums
-/
section GaussSumProd
-- In the following, we need `R` to be a finite field and `R'` to be a domain.
variable {R : Type u} [Field R] [Fintype R] {R' : Type v} [CommRing R'] [IsDomain R']
-- A helper lemma for `gaussSum_mul_gaussSum_eq_card` below
-- Is this useful enough in other contexts to be public?
private theorem gaussSum_mul_aux {χ : MulChar R R'} (hχ : χ ≠ 1) (ψ : AddChar R R')
(b : R) :
∑ a, χ (a * b⁻¹) * ψ (a - b) = ∑ c, χ c * ψ (b * (c - 1)) := by
rcases eq_or_ne b 0 with hb | hb
· -- case `b = 0`
simp only [hb, inv_zero, mul_zero, MulChar.map_zero, zero_mul,
Finset.sum_const_zero, map_zero_eq_one, mul_one, χ.sum_eq_zero_of_ne_one hχ]
· -- case `b ≠ 0`
refine (Fintype.sum_bijective _ (mulLeft_bijective₀ b hb) _ _ fun x ↦ ?_).symm
rw [mul_assoc, mul_comm x, ← mul_assoc, mul_inv_cancel hb, one_mul, mul_sub, mul_one]
/-- We have `gaussSum χ ψ * gaussSum χ⁻¹ ψ⁻¹ = Fintype.card R`
when `χ` is nontrivial and `ψ` is primitive (and `R` is a field). -/
theorem gaussSum_mul_gaussSum_eq_card {χ : MulChar R R'} (hχ : χ ≠ 1) {ψ : AddChar R R'}
(hψ : IsPrimitive ψ) :
gaussSum χ ψ * gaussSum χ⁻¹ ψ⁻¹ = Fintype.card R := by
simp only [gaussSum, AddChar.inv_apply, Finset.sum_mul, Finset.mul_sum, MulChar.inv_apply']
conv =>
enter [1, 2, x, 2, y]
rw [mul_mul_mul_comm, ← map_mul, ← map_add_eq_mul, ← sub_eq_add_neg]
-- conv in _ * _ * (_ * _) => rw [mul_mul_mul_comm, ← map_mul, ← map_add_eq_mul, ← sub_eq_add_neg]
simp_rw [gaussSum_mul_aux hχ ψ]
rw [Finset.sum_comm]
classical -- to get `[DecidableEq R]` for `sum_mulShift`
simp_rw [← Finset.mul_sum, sum_mulShift _ hψ, sub_eq_zero, apply_ite, Nat.cast_zero, mul_zero]
rw [Finset.sum_ite_eq' Finset.univ (1 : R)]
simp only [Finset.mem_univ, map_one, one_mul, if_true]
/-- When `χ` is a nontrivial quadratic character, then the square of `gaussSum χ ψ`
is `χ(-1)` times the cardinality of `R`. -/
theorem gaussSum_sq {χ : MulChar R R'} (hχ₁ : χ ≠ 1) (hχ₂ : IsQuadratic χ)
{ψ : AddChar R R'} (hψ : IsPrimitive ψ) :
gaussSum χ ψ ^ 2 = χ (-1) * Fintype.card R := by
rw [pow_two, ← gaussSum_mul_gaussSum_eq_card hχ₁ hψ, hχ₂.inv, mul_rotate']
congr
rw [mul_comm, ← gaussSum_mulShift _ _ (-1 : Rˣ), inv_mulShift]
rfl
end GaussSumProd
/-!
### Gauss sums and Frobenius
-/
section gaussSum_frob
variable {R : Type u} [CommRing R] [Fintype R] {R' : Type v} [CommRing R']
-- We assume that the target ring `R'` has prime characteristic `p`.
variable (p : ℕ) [fp : Fact p.Prime] [hch : CharP R' p]
/-- When `R'` has prime characteristic `p`, then the `p`th power of the Gauss sum
of `χ` and `ψ` is the Gauss sum of `χ^p` and `ψ^p`. -/
theorem gaussSum_frob (χ : MulChar R R') (ψ : AddChar R R') :
gaussSum χ ψ ^ p = gaussSum (χ ^ p) (ψ ^ p) := by
rw [← frobenius_def, gaussSum, gaussSum, map_sum]
simp_rw [pow_apply' χ fp.1.ne_zero, map_mul, frobenius_def]
rfl
/-- For a quadratic character `χ` and when the characteristic `p` of the target ring
is a unit in the source ring, the `p`th power of the Gauss sum of`χ` and `ψ` is
`χ p` times the original Gauss sum. -/
theorem MulChar.IsQuadratic.gaussSum_frob (hp : IsUnit (p : R)) {χ : MulChar R R'}
(hχ : IsQuadratic χ) (ψ : AddChar R R') :
gaussSum χ ψ ^ p = χ p * gaussSum χ ψ := by
rw [_root_.gaussSum_frob, pow_mulShift, hχ.pow_char p, ← gaussSum_mulShift χ ψ hp.unit,
← mul_assoc, hp.unit_spec, ← pow_two, ← pow_apply' _ two_ne_zero, hχ.sq_eq_one, ← hp.unit_spec,
one_apply_coe, one_mul]
/-- For a quadratic character `χ` and when the characteristic `p` of the target ring
is a unit in the source ring and `n` is a natural number, the `p^n`th power of the Gauss
sum of`χ` and `ψ` is `χ (p^n)` times the original Gauss sum. -/
theorem MulChar.IsQuadratic.gaussSum_frob_iter (n : ℕ) (hp : IsUnit (p : R)) {χ : MulChar R R'}
(hχ : IsQuadratic χ) (ψ : AddChar R R') :
gaussSum χ ψ ^ p ^ n = χ ((p : R) ^ n) * gaussSum χ ψ := by
induction' n with n ih
· rw [pow_zero, pow_one, pow_zero, MulChar.map_one, one_mul]
· rw [pow_succ, pow_mul, ih, mul_pow, hχ.gaussSum_frob _ hp, ← mul_assoc, pow_succ, map_mul,
← pow_apply' χ fp.1.ne_zero ((p : R) ^ n), hχ.pow_char p]
end gaussSum_frob
/-!
### Values of quadratic characters
-/
section GaussSumValues
variable {R : Type u} [CommRing R] [Fintype R] {R' : Type v} [CommRing R'] [IsDomain R']
/-- If the square of the Gauss sum of a quadratic character is `χ(-1) * #R`,
then we get, for all `n : ℕ`, the relation `(χ(-1) * #R) ^ (p^n/2) = χ(p^n)`,
where `p` is the (odd) characteristic of the target ring `R'`.
This version can be used when `R` is not a field, e.g., `ℤ/8ℤ`. -/
theorem Char.card_pow_char_pow {χ : MulChar R R'} (hχ : IsQuadratic χ) (ψ : AddChar R R') (p n : ℕ)
[fp : Fact p.Prime] [hch : CharP R' p] (hp : IsUnit (p : R)) (hp' : p ≠ 2)
(hg : gaussSum χ ψ ^ 2 = χ (-1) * Fintype.card R) :
(χ (-1) * Fintype.card R) ^ (p ^ n / 2) = χ ((p : R) ^ n) := by
have : gaussSum χ ψ ≠ 0 := by
intro hf
rw [hf, zero_pow two_ne_zero, eq_comm, mul_eq_zero] at hg
exact not_isUnit_prime_of_dvd_card p
((CharP.cast_eq_zero_iff R' p _).mp <| hg.resolve_left (isUnit_one.neg.map χ).ne_zero) hp
rw [← hg]
apply mul_right_cancel₀ this
rw [← hχ.gaussSum_frob_iter p n hp ψ, ← pow_mul, ← pow_succ,
Nat.two_mul_div_two_add_one_of_odd (fp.1.eq_two_or_odd'.resolve_left hp').pow]
/-- When `F` and `F'` are finite fields and `χ : F → F'` is a nontrivial quadratic character,
then `(χ(-1) * #F)^(#F'/2) = χ #F'`. -/
theorem Char.card_pow_card {F : Type*} [Field F] [Fintype F] {F' : Type*} [Field F'] [Fintype F']
{χ : MulChar F F'} (hχ₁ : χ ≠ 1) (hχ₂ : IsQuadratic χ)
(hch₁ : ringChar F' ≠ ringChar F) (hch₂ : ringChar F' ≠ 2) :
(χ (-1) * Fintype.card F) ^ (Fintype.card F' / 2) = χ (Fintype.card F') := by
obtain ⟨n, hp, hc⟩ := FiniteField.card F (ringChar F)
obtain ⟨n', hp', hc'⟩ := FiniteField.card F' (ringChar F')
let ψ := FiniteField.primitiveChar F F' hch₁
let FF' := CyclotomicField ψ.n F'
have hchar := Algebra.ringChar_eq F' FF'
apply (algebraMap F' FF').injective
rw [map_pow, map_mul, map_natCast, hc', hchar, Nat.cast_pow]
simp only [← MulChar.ringHomComp_apply]
have := Fact.mk hp'
have := Fact.mk (hchar.subst hp')
rw [Ne, ← Nat.prime_dvd_prime_iff_eq hp' hp, ← isUnit_iff_not_dvd_char, hchar] at hch₁
exact Char.card_pow_char_pow (hχ₂.comp _) ψ.char (ringChar FF') n' hch₁ (hchar ▸ hch₂)
(gaussSum_sq ((ringHomComp_ne_one_iff (RingHom.injective _)).mpr hχ₁) (hχ₂.comp _) ψ.prim)
end GaussSumValues
section GaussSumTwo
/-!
### The quadratic character of 2
This section proves the following result.
For every finite field `F` of odd characteristic, we have `2^(#F/2) = χ₈#F` in `F`.
This can be used to show that the quadratic character of `F` takes the value
`χ₈#F` at `2`.
The proof uses the Gauss sum of `χ₈` and a primitive additive character on `ℤ/8ℤ`;
in this way, the result is reduced to `card_pow_char_pow`.
-/
open ZMod
/-- For every finite field `F` of odd characteristic, we have `2^(#F/2) = χ₈ #F` in `F`. -/
theorem FiniteField.two_pow_card {F : Type*} [Fintype F] [Field F] (hF : ringChar F ≠ 2) :
(2 : F) ^ (Fintype.card F / 2) = χ₈ (Fintype.card F) := by
have hp2 (n : ℕ) : (2 ^ n : F) ≠ 0 := pow_ne_zero n (Ring.two_ne_zero hF)
obtain ⟨n, hp, hc⟩ := FiniteField.card F (ringChar F)
-- we work in `FF`, the eighth cyclotomic field extension of `F`
let FF := CyclotomicField 8 F
have hchar := Algebra.ringChar_eq F FF
have FFp := hchar.subst hp
have := Fact.mk FFp
have hFF := hchar ▸ hF -- `ringChar FF ≠ 2`
have hu : IsUnit (ringChar FF : ZMod 8) := by
rw [isUnit_iff_not_dvd_char, ringChar_zmod_n]
rw [Ne, ← Nat.prime_dvd_prime_iff_eq FFp Nat.prime_two] at hFF
change ¬_ ∣ 2 ^ 3
exact mt FFp.dvd_of_dvd_pow hFF
-- there is a primitive additive character `ℤ/8ℤ → FF`, sending `a + 8ℤ ↦ τ^a`
-- with a primitive eighth root of unity `τ`
let ψ₈ := primitiveZModChar 8 F (by convert hp2 3 using 1; norm_cast)
-- We cast from `AddChar (ZMod (8 : ℕ+)) FF` to `AddChar (ZMod 8) FF`
-- This is needed to make `simp_rw [← h₁]` below work.
let ψ₈char : AddChar (ZMod 8) FF := ψ₈.char
let τ : FF := ψ₈char 1
have τ_spec : τ ^ 4 = -1 := by
rw [show τ = ψ₈.char 1 from rfl] -- to make `rw [ψ₈.prim.zmod_char_eq_one_iff]` work
refine (sq_eq_one_iff.1 ?_).resolve_left ?_
· rw [← pow_mul, ← map_nsmul_eq_pow ψ₈.char, ψ₈.prim.zmod_char_eq_one_iff]
decide
· rw [← map_nsmul_eq_pow ψ₈.char, ψ₈.prim.zmod_char_eq_one_iff]
decide
-- we consider `χ₈` as a multiplicative character `ℤ/8ℤ → FF`
let χ := χ₈.ringHomComp (Int.castRingHom FF)
have hχ : χ (-1) = 1 := Int.cast_one
have hq : IsQuadratic χ := isQuadratic_χ₈.comp _
-- we now show that the Gauss sum of `χ` and `ψ₈` has the relevant property
have h₁ : (fun (a : Fin 8) ↦ ↑(χ₈ a) * τ ^ (a : ℕ)) = fun a ↦ χ a * ↑(ψ₈char a) := by
ext1; congr; apply pow_one
have hg₁ : gaussSum χ ψ₈char = 2 * (τ - τ ^ 3) := by
rw [gaussSum, ← h₁, Fin.sum_univ_eight,
-- evaluate `χ₈`
show χ₈ 0 = 0 from rfl, show χ₈ 1 = 1 from rfl, show χ₈ 2 = 0 from rfl,
show χ₈ 3 = -1 from rfl, show χ₈ 4 = 0 from rfl, show χ₈ 5 = -1 from rfl,
show χ₈ 6 = 0 from rfl, show χ₈ 7 = 1 from rfl,
-- normalize exponents
show ((3 : Fin 8) : ℕ) = 3 from rfl, show ((5 : Fin 8) : ℕ) = 5 from rfl,
show ((7 : Fin 8) : ℕ) = 7 from rfl]
simp only [Int.cast_zero, zero_mul, Int.cast_one, Fin.val_one, pow_one, one_mul, zero_add,
Fin.val_two, add_zero, Int.reduceNeg, Int.cast_neg, neg_mul]
linear_combination (τ ^ 3 - τ) * τ_spec
have hg : gaussSum χ ψ₈char ^ 2 = χ (-1) * Fintype.card (ZMod 8) := by
rw [hχ, one_mul, ZMod.card, Nat.cast_ofNat, hg₁]
linear_combination (4 * τ ^ 2 - 8) * τ_spec
-- this allows us to apply `card_pow_char_pow` to our situation
have h := Char.card_pow_char_pow (R := ZMod 8) hq ψ₈char (ringChar FF) n hu hFF hg
rw [ZMod.card, ← hchar, hχ, one_mul, ← hc, ← Nat.cast_pow (ringChar F), ← hc] at h
-- finally, we change `2` to `8` on the left hand side
convert_to (8 : F) ^ (Fintype.card F / 2) = _
· rw [(by norm_num : (8 : F) = 2 ^ 2 * 2), mul_pow,
(FiniteField.isSquare_iff hF <| hp2 2).mp ⟨2, pow_two 2⟩, one_mul]
apply (algebraMap F FF).injective
simpa only [map_pow, map_ofNat, map_intCast, Nat.cast_ofNat] using h
end GaussSumTwo
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.