path
stringlengths
11
71
content
stringlengths
75
124k
Order\SuccPred\IntervalSucc.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.Data.Set.Pairwise.Basic import Mathlib.Data.Set.Lattice import Mathlib.Order.SuccPred.Basic /-! # Intervals `Ixx (f x) (f (Order.succ x))` In this file we prove * `Monotone.biUnion_Ico_Ioc_map_succ`: if `α` is a linear archimedean succ order and `β` is a linear order, then for any monotone function `f` and `m n : α`, the union of intervals `Set.Ioc (f i) (f (Order.succ i))`, `m ≤ i < n`, is equal to `Set.Ioc (f m) (f n)`; * `Monotone.pairwise_disjoint_on_Ioc_succ`: if `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioc (f n) (f (Order.succ n))` are pairwise disjoint. For the latter lemma, we also prove various order dual versions. -/ open Set Order variable {α β : Type*} [LinearOrder α] namespace Monotone /-- If `α` is a linear archimedean succ order and `β` is a linear order, then for any monotone function `f` and `m n : α`, the union of intervals `Set.Ioc (f i) (f (Order.succ i))`, `m ≤ i < n`, is equal to `Set.Ioc (f m) (f n)` -/ theorem biUnion_Ico_Ioc_map_succ [SuccOrder α] [IsSuccArchimedean α] [LinearOrder β] {f : α → β} (hf : Monotone f) (m n : α) : ⋃ i ∈ Ico m n, Ioc (f i) (f (succ i)) = Ioc (f m) (f n) := by rcases le_total n m with hnm | hmn · rw [Ico_eq_empty_of_le hnm, Ioc_eq_empty_of_le (hf hnm), biUnion_empty] · refine Succ.rec ?_ ?_ hmn · simp only [Ioc_self, Ico_self, biUnion_empty] · intro k hmk ihk rw [← Ioc_union_Ioc_eq_Ioc (hf hmk) (hf <| le_succ _), union_comm, ← ihk] by_cases hk : IsMax k · rw [hk.succ_eq, Ioc_self, empty_union] · rw [Ico_succ_right_eq_insert_of_not_isMax hmk hk, biUnion_insert] /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioc (f n) (f (Order.succ n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioc (f n) (f (succ n))) := (pairwise_disjoint_on _).2 fun _ _ hmn => disjoint_iff_inf_le.mpr fun _ ⟨⟨_, h₁⟩, ⟨h₂, _⟩⟩ => h₂.not_le <| h₁.trans <| hf <| succ_le_of_lt hmn /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ico (f n) (f (Order.succ n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ico (f n) (f (succ n))) := (pairwise_disjoint_on _).2 fun _ _ hmn => disjoint_iff_inf_le.mpr fun _ ⟨⟨_, h₁⟩, ⟨h₂, _⟩⟩ => h₁.not_le <| (hf <| succ_le_of_lt hmn).trans h₂ /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioo (f n) (f (Order.succ n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioo (f n) (f (succ n))) := hf.pairwise_disjoint_on_Ico_succ.mono fun _ _ h => h.mono Ioo_subset_Ico_self Ioo_subset_Ico_self /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioc (f Order.pred n) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioc (f (pred n)) (f n)) := by simpa only [(· ∘ ·), dual_Ico] using hf.dual.pairwise_disjoint_on_Ico_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ico (f Order.pred n) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ico (f (pred n)) (f n)) := by simpa only [(· ∘ ·), dual_Ioc] using hf.dual.pairwise_disjoint_on_Ioc_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is a monotone function, then the intervals `Set.Ioo (f Order.pred n) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Monotone f) : Pairwise (Disjoint on fun n => Ioo (f (pred n)) (f n)) := by simpa only [(· ∘ ·), dual_Ioo] using hf.dual.pairwise_disjoint_on_Ioo_succ end Monotone namespace Antitone /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioc (f (Order.succ n)) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioc (f (succ n)) (f n)) := hf.dual_left.pairwise_disjoint_on_Ioc_pred /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ico (f (Order.succ n)) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ico (f (succ n)) (f n)) := hf.dual_left.pairwise_disjoint_on_Ico_pred /-- If `α` is a linear succ order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioo (f (Order.succ n)) (f n)` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_succ [SuccOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioo (f (succ n)) (f n)) := hf.dual_left.pairwise_disjoint_on_Ioo_pred /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioc (f n) (f (Order.pred n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioc_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioc (f n) (f (pred n))) := hf.dual_left.pairwise_disjoint_on_Ioc_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ico (f n) (f (Order.pred n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ico_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ico (f n) (f (pred n))) := hf.dual_left.pairwise_disjoint_on_Ico_succ /-- If `α` is a linear pred order, `β` is a preorder, and `f : α → β` is an antitone function, then the intervals `Set.Ioo (f n) (f (Order.pred n))` are pairwise disjoint. -/ theorem pairwise_disjoint_on_Ioo_pred [PredOrder α] [Preorder β] {f : α → β} (hf : Antitone f) : Pairwise (Disjoint on fun n => Ioo (f n) (f (pred n))) := hf.dual_left.pairwise_disjoint_on_Ioo_succ end Antitone
Order\SuccPred\Limit.lean
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.Order.SuccPred.Basic import Mathlib.Order.BoundedOrder /-! # Successor and predecessor limits We define the predicate `Order.IsSuccLimit` for "successor limits", values that don't cover any others. They are so named since they can't be the successors of anything smaller. We define `Order.IsPredLimit` analogously, and prove basic results. ## TODO The plan is to eventually replace `Ordinal.IsLimit` and `Cardinal.IsLimit` with the common predicate `Order.IsSuccLimit`. -/ variable {α : Type*} namespace Order open Function Set OrderDual /-! ### Successor limits -/ section LT variable [LT α] /-- A successor limit is a value that doesn't cover any other. It's so named because in a successor order, a successor limit can't be the successor of anything smaller. -/ def IsSuccLimit (a : α) : Prop := ∀ b, ¬b ⋖ a theorem not_isSuccLimit_iff_exists_covBy (a : α) : ¬IsSuccLimit a ↔ ∃ b, b ⋖ a := by simp [IsSuccLimit] @[simp] theorem isSuccLimit_of_dense [DenselyOrdered α] (a : α) : IsSuccLimit a := fun _ => not_covBy end LT section Preorder variable [Preorder α] {a : α} protected theorem _root_.IsMin.isSuccLimit : IsMin a → IsSuccLimit a := fun h _ hab => not_isMin_of_lt hab.lt h theorem isSuccLimit_bot [OrderBot α] : IsSuccLimit (⊥ : α) := IsMin.isSuccLimit isMin_bot variable [SuccOrder α] protected theorem IsSuccLimit.isMax (h : IsSuccLimit (succ a)) : IsMax a := by by_contra H exact h a (covBy_succ_of_not_isMax H) theorem not_isSuccLimit_succ_of_not_isMax (ha : ¬IsMax a) : ¬IsSuccLimit (succ a) := by contrapose! ha exact ha.isMax section NoMaxOrder variable [NoMaxOrder α] theorem IsSuccLimit.succ_ne (h : IsSuccLimit a) (b : α) : succ b ≠ a := by rintro rfl exact not_isMax _ h.isMax @[simp] theorem not_isSuccLimit_succ (a : α) : ¬IsSuccLimit (succ a) := fun h => h.succ_ne _ rfl end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] theorem IsSuccLimit.isMin_of_noMax [NoMaxOrder α] (h : IsSuccLimit a) : IsMin a := fun b hb => by rcases hb.exists_succ_iterate with ⟨_ | n, rfl⟩ · exact le_rfl · rw [iterate_succ_apply'] at h exact (not_isSuccLimit_succ _ h).elim @[simp] theorem isSuccLimit_iff_of_noMax [NoMaxOrder α] : IsSuccLimit a ↔ IsMin a := ⟨IsSuccLimit.isMin_of_noMax, IsMin.isSuccLimit⟩ theorem not_isSuccLimit_of_noMax [NoMinOrder α] [NoMaxOrder α] : ¬IsSuccLimit a := by simp end IsSuccArchimedean end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} {C : α → Sort*} theorem isSuccLimit_of_succ_ne (h : ∀ b, succ b ≠ a) : IsSuccLimit a := fun b hba => h b (CovBy.succ_eq hba) theorem not_isSuccLimit_iff : ¬IsSuccLimit a ↔ ∃ b, ¬IsMax b ∧ succ b = a := by rw [not_isSuccLimit_iff_exists_covBy] refine exists_congr fun b => ⟨fun hba => ⟨hba.lt.not_isMax, (CovBy.succ_eq hba)⟩, ?_⟩ rintro ⟨h, rfl⟩ exact covBy_succ_of_not_isMax h /-- See `not_isSuccLimit_iff` for a version that states that `a` is a successor of a value other than itself. -/ theorem mem_range_succ_of_not_isSuccLimit (h : ¬IsSuccLimit a) : a ∈ range (@succ α _ _) := by cases' not_isSuccLimit_iff.1 h with b hb exact ⟨b, hb.2⟩ theorem isSuccLimit_of_succ_lt (H : ∀ a < b, succ a < b) : IsSuccLimit b := fun a hab => (H a hab.lt).ne (CovBy.succ_eq hab) theorem IsSuccLimit.succ_lt (hb : IsSuccLimit b) (ha : a < b) : succ a < b := by by_cases h : IsMax a · rwa [h.succ_eq] · rw [lt_iff_le_and_ne, succ_le_iff_of_not_isMax h] refine ⟨ha, fun hab => ?_⟩ subst hab exact (h hb.isMax).elim theorem IsSuccLimit.succ_lt_iff (hb : IsSuccLimit b) : succ a < b ↔ a < b := ⟨fun h => (le_succ a).trans_lt h, hb.succ_lt⟩ theorem isSuccLimit_iff_succ_lt : IsSuccLimit b ↔ ∀ a < b, succ a < b := ⟨fun hb _ => hb.succ_lt, isSuccLimit_of_succ_lt⟩ /-- A value can be built by building it on successors and successor limits. -/ @[elab_as_elim] noncomputable def isSuccLimitRecOn (b : α) (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) : C b := by by_cases hb : IsSuccLimit b · exact hl b hb · have H := Classical.choose_spec (not_isSuccLimit_iff.1 hb) rw [← H.2] exact hs _ H.1 theorem isSuccLimitRecOn_limit (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) (hb : IsSuccLimit b) : @isSuccLimitRecOn α _ _ C b hs hl = hl b hb := by classical exact dif_pos hb theorem isSuccLimitRecOn_succ' (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) {b : α} (hb : ¬IsMax b) : @isSuccLimitRecOn α _ _ C (succ b) hs hl = hs b hb := by have hb' := not_isSuccLimit_succ_of_not_isMax hb have H := Classical.choose_spec (not_isSuccLimit_iff.1 hb') rw [isSuccLimitRecOn] simp only [cast_eq_iff_heq, hb', not_false_iff, eq_mpr_eq_cast, dif_neg] congr 1 <;> first | exact (succ_eq_succ_iff_of_not_isMax H.left hb).mp H.right | exact proof_irrel_heq H.left hb section limitRecOn variable [WellFoundedLT α] (H_succ : ∀ a, ¬IsMax a → C a → C (succ a)) (H_lim : ∀ a, IsSuccLimit a → (∀ b < a, C b) → C a) open scoped Classical in variable (a) in /-- Recursion principle on a well-founded partial `SuccOrder`. -/ @[elab_as_elim] noncomputable def _root_.SuccOrder.limitRecOn : C a := wellFounded_lt.fix (fun a IH ↦ if h : IsSuccLimit a then H_lim a h IH else let x := Classical.indefiniteDescription _ (not_isSuccLimit_iff.mp h) x.2.2 ▸ H_succ x x.2.1 (IH x <| x.2.2.subst <| lt_succ_of_not_isMax x.2.1)) a @[simp] theorem _root_.SuccOrder.limitRecOn_succ (ha : ¬ IsMax a) : SuccOrder.limitRecOn (succ a) H_succ H_lim = H_succ a ha (SuccOrder.limitRecOn a H_succ H_lim) := by have h := not_isSuccLimit_succ_of_not_isMax ha rw [SuccOrder.limitRecOn, WellFounded.fix_eq, dif_neg h] have {b c hb hc} {x : ∀ a, C a} (h : b = c) : congr_arg succ h ▸ H_succ b hb (x b) = H_succ c hc (x c) := by subst h; rfl let x := Classical.indefiniteDescription _ (not_isSuccLimit_iff.mp h) exact this ((succ_eq_succ_iff_of_not_isMax x.2.1 ha).mp x.2.2) @[simp] theorem _root_.SuccOrder.limitRecOn_limit (ha : IsSuccLimit a) : SuccOrder.limitRecOn a H_succ H_lim = H_lim a ha fun x _ ↦ SuccOrder.limitRecOn x H_succ H_lim := by rw [SuccOrder.limitRecOn, WellFounded.fix_eq, dif_pos ha]; rfl end limitRecOn section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem isSuccLimitRecOn_succ (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) (b : α) : @isSuccLimitRecOn α _ _ C (succ b) hs hl = hs b (not_isMax b) := isSuccLimitRecOn_succ' _ _ _ theorem isSuccLimit_iff_succ_ne : IsSuccLimit a ↔ ∀ b, succ b ≠ a := ⟨IsSuccLimit.succ_ne, isSuccLimit_of_succ_ne⟩ theorem not_isSuccLimit_iff' : ¬IsSuccLimit a ↔ a ∈ range (@succ α _ _) := by simp_rw [isSuccLimit_iff_succ_ne, not_forall, not_ne_iff] rfl end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] protected theorem IsSuccLimit.isMin (h : IsSuccLimit a) : IsMin a := fun b hb => by revert h refine Succ.rec (fun _ => le_rfl) (fun c _ H hc => ?_) hb have := hc.isMax.succ_eq rw [this] at hc ⊢ exact H hc @[simp] theorem isSuccLimit_iff : IsSuccLimit a ↔ IsMin a := ⟨IsSuccLimit.isMin, IsMin.isSuccLimit⟩ theorem not_isSuccLimit [NoMinOrder α] : ¬IsSuccLimit a := by simp end IsSuccArchimedean end PartialOrder /-! ### Predecessor limits -/ section LT variable [LT α] {a : α} /-- A predecessor limit is a value that isn't covered by any other. It's so named because in a predecessor order, a predecessor limit can't be the predecessor of anything greater. -/ def IsPredLimit (a : α) : Prop := ∀ b, ¬a ⋖ b theorem not_isPredLimit_iff_exists_covBy (a : α) : ¬IsPredLimit a ↔ ∃ b, a ⋖ b := by simp [IsPredLimit] theorem isPredLimit_of_dense [DenselyOrdered α] (a : α) : IsPredLimit a := fun _ => not_covBy @[simp] theorem isSuccLimit_toDual_iff : IsSuccLimit (toDual a) ↔ IsPredLimit a := by simp [IsSuccLimit, IsPredLimit] @[simp] theorem isPredLimit_toDual_iff : IsPredLimit (toDual a) ↔ IsSuccLimit a := by simp [IsSuccLimit, IsPredLimit] alias ⟨_, isPredLimit.dual⟩ := isSuccLimit_toDual_iff alias ⟨_, isSuccLimit.dual⟩ := isPredLimit_toDual_iff end LT section Preorder variable [Preorder α] {a : α} protected theorem _root_.IsMax.isPredLimit : IsMax a → IsPredLimit a := fun h _ hab => not_isMax_of_lt hab.lt h theorem isPredLimit_top [OrderTop α] : IsPredLimit (⊤ : α) := IsMax.isPredLimit isMax_top variable [PredOrder α] protected theorem IsPredLimit.isMin (h : IsPredLimit (pred a)) : IsMin a := by by_contra H exact h a (pred_covBy_of_not_isMin H) theorem not_isPredLimit_pred_of_not_isMin (ha : ¬IsMin a) : ¬IsPredLimit (pred a) := by contrapose! ha exact ha.isMin section NoMinOrder variable [NoMinOrder α] theorem IsPredLimit.pred_ne (h : IsPredLimit a) (b : α) : pred b ≠ a := by rintro rfl exact not_isMin _ h.isMin @[simp] theorem not_isPredLimit_pred (a : α) : ¬IsPredLimit (pred a) := fun h => h.pred_ne _ rfl end NoMinOrder section IsPredArchimedean variable [IsPredArchimedean α] protected theorem IsPredLimit.isMax_of_noMin [NoMinOrder α] (h : IsPredLimit a) : IsMax a := (isPredLimit.dual h).isMin_of_noMax @[simp] theorem isPredLimit_iff_of_noMin [NoMinOrder α] : IsPredLimit a ↔ IsMax a := isSuccLimit_toDual_iff.symm.trans isSuccLimit_iff_of_noMax theorem not_isPredLimit_of_noMin [NoMinOrder α] [NoMaxOrder α] : ¬IsPredLimit a := by simp end IsPredArchimedean end Preorder section PartialOrder variable [PartialOrder α] [PredOrder α] {a b : α} {C : α → Sort*} theorem isPredLimit_of_pred_ne (h : ∀ b, pred b ≠ a) : IsPredLimit a := fun b hba => h b (CovBy.pred_eq hba) theorem not_isPredLimit_iff : ¬IsPredLimit a ↔ ∃ b, ¬IsMin b ∧ pred b = a := by rw [← isSuccLimit_toDual_iff] exact not_isSuccLimit_iff /-- See `not_isPredLimit_iff` for a version that states that `a` is a successor of a value other than itself. -/ theorem mem_range_pred_of_not_isPredLimit (h : ¬IsPredLimit a) : a ∈ range (@pred α _ _) := by cases' not_isPredLimit_iff.1 h with b hb exact ⟨b, hb.2⟩ theorem isPredLimit_of_pred_lt (H : ∀ a > b, pred a < b) : IsPredLimit b := fun a hab => (H a hab.lt).ne (CovBy.pred_eq hab) theorem IsPredLimit.lt_pred (h : IsPredLimit a) : a < b → a < pred b := (isPredLimit.dual h).succ_lt theorem IsPredLimit.lt_pred_iff (h : IsPredLimit a) : a < pred b ↔ a < b := (isPredLimit.dual h).succ_lt_iff theorem isPredLimit_iff_lt_pred : IsPredLimit a ↔ ∀ ⦃b⦄, a < b → a < pred b := isSuccLimit_toDual_iff.symm.trans isSuccLimit_iff_succ_lt /-- A value can be built by building it on predecessors and predecessor limits. -/ @[elab_as_elim] noncomputable def isPredLimitRecOn (b : α) (hs : ∀ a, ¬IsMin a → C (pred a)) (hl : ∀ a, IsPredLimit a → C a) : C b := @isSuccLimitRecOn αᵒᵈ _ _ _ _ hs fun _ ha => hl _ (isSuccLimit.dual ha) theorem isPredLimitRecOn_limit (hs : ∀ a, ¬IsMin a → C (pred a)) (hl : ∀ a, IsPredLimit a → C a) (hb : IsPredLimit b) : @isPredLimitRecOn α _ _ C b hs hl = hl b hb := isSuccLimitRecOn_limit _ _ (isPredLimit.dual hb) theorem isPredLimitRecOn_pred' (hs : ∀ a, ¬IsMin a → C (pred a)) (hl : ∀ a, IsPredLimit a → C a) {b : α} (hb : ¬IsMin b) : @isPredLimitRecOn α _ _ C (pred b) hs hl = hs b hb := isSuccLimitRecOn_succ' _ _ _ section limitRecOn variable [WellFoundedGT α] (H_pred : ∀ a, ¬IsMin a → C a → C (pred a)) (H_lim : ∀ a, IsPredLimit a → (∀ b > a, C b) → C a) open scoped Classical in variable (a) in /-- Recursion principle on a well-founded partial `PredOrder`. -/ @[elab_as_elim] noncomputable def _root_.PredOrder.limitRecOn : C a := wellFounded_gt.fix (fun a IH ↦ if h : IsPredLimit a then H_lim a h IH else let x := Classical.indefiniteDescription _ (not_isPredLimit_iff.mp h) x.2.2 ▸ H_pred x x.2.1 (IH x <| x.2.2.subst <| pred_lt_of_not_isMin x.2.1)) a @[simp] theorem _root_.PredOrder.limitRecOn_pred (ha : ¬ IsMin a) : PredOrder.limitRecOn (pred a) H_pred H_lim = H_pred a ha (PredOrder.limitRecOn a H_pred H_lim) := by have h := not_isPredLimit_pred_of_not_isMin ha rw [PredOrder.limitRecOn, WellFounded.fix_eq, dif_neg h] have {b c hb hc} {x : ∀ a, C a} (h : b = c) : congr_arg pred h ▸ H_pred b hb (x b) = H_pred c hc (x c) := by subst h; rfl let x := Classical.indefiniteDescription _ (not_isPredLimit_iff.mp h) exact this ((pred_eq_pred_iff_of_not_isMin x.2.1 ha).mp x.2.2) @[simp] theorem _root_.PredOrder.limitRecOn_limit (ha : IsPredLimit a) : PredOrder.limitRecOn a H_pred H_lim = H_lim a ha fun x _ ↦ PredOrder.limitRecOn x H_pred H_lim := by rw [PredOrder.limitRecOn, WellFounded.fix_eq, dif_pos ha]; rfl end limitRecOn section NoMinOrder variable [NoMinOrder α] @[simp] theorem isPredLimitRecOn_pred (hs : ∀ a, ¬IsMin a → C (pred a)) (hl : ∀ a, IsPredLimit a → C a) (b : α) : @isPredLimitRecOn α _ _ C (pred b) hs hl = hs b (not_isMin b) := isSuccLimitRecOn_succ _ _ _ end NoMinOrder section IsPredArchimedean variable [IsPredArchimedean α] protected theorem IsPredLimit.isMax (h : IsPredLimit a) : IsMax a := (isPredLimit.dual h).isMin @[simp] theorem isPredLimit_iff : IsPredLimit a ↔ IsMax a := isSuccLimit_toDual_iff.symm.trans isSuccLimit_iff theorem not_isPredLimit [NoMaxOrder α] : ¬IsPredLimit a := by simp end IsPredArchimedean end PartialOrder end Order
Order\SuccPred\LinearLocallyFinite.lean
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Data.Countable.Basic import Mathlib.Logic.Encodable.Basic import Mathlib.Order.SuccPred.Basic import Mathlib.Order.Interval.Finset.Defs import Mathlib.Algebra.Order.Ring.Nat /-! # Linear locally finite orders We prove that a `LinearOrder` which is a `LocallyFiniteOrder` also verifies * `SuccOrder` * `PredOrder` * `IsSuccArchimedean` * `IsPredArchimedean` * `Countable` Furthermore, we show that there is an `OrderIso` between such an order and a subset of `ℤ`. ## Main definitions * `toZ i0 i`: in a linear order on which we can define predecessors and successors and which is succ-archimedean, we can assign a unique integer `toZ i0 i` to each element `i : ι` while respecting the order, starting from `toZ i0 i0 = 0`. ## Main results Instances about linear locally finite orders: * `LinearLocallyFiniteOrder.SuccOrder`: a linear locally finite order has a successor function. * `LinearLocallyFiniteOrder.PredOrder`: a linear locally finite order has a predecessor function. * `LinearLocallyFiniteOrder.isSuccArchimedean`: a linear locally finite order is succ-archimedean. * `LinearOrder.pred_archimedean_of_succ_archimedean`: a succ-archimedean linear order is also pred-archimedean. * `countable_of_linear_succ_pred_arch` : a succ-archimedean linear order is countable. About `toZ`: * `orderIsoRangeToZOfLinearSuccPredArch`: `toZ` defines an `OrderIso` between `ι` and its range. * `orderIsoNatOfLinearSuccPredArch`: if the order has a bot but no top, `toZ` defines an `OrderIso` between `ι` and `ℕ`. * `orderIsoIntOfLinearSuccPredArch`: if the order has neither bot nor top, `toZ` defines an `OrderIso` between `ι` and `ℤ`. * `orderIsoRangeOfLinearSuccPredArch`: if the order has both a bot and a top, `toZ` gives an `OrderIso` between `ι` and `Finset.range ((toZ ⊥ ⊤).toNat + 1)`. -/ open Order variable {ι : Type*} [LinearOrder ι] namespace LinearLocallyFiniteOrder /-- Successor in a linear order. This defines a true successor only when `i` is isolated from above, i.e. when `i` is not the greatest lower bound of `(i, ∞)`. -/ noncomputable def succFn (i : ι) : ι := (exists_glb_Ioi i).choose theorem succFn_spec (i : ι) : IsGLB (Set.Ioi i) (succFn i) := (exists_glb_Ioi i).choose_spec theorem le_succFn (i : ι) : i ≤ succFn i := by rw [le_isGLB_iff (succFn_spec i), mem_lowerBounds] exact fun x hx ↦ le_of_lt hx theorem isGLB_Ioc_of_isGLB_Ioi {i j k : ι} (hij_lt : i < j) (h : IsGLB (Set.Ioi i) k) : IsGLB (Set.Ioc i j) k := by simp_rw [IsGLB, IsGreatest, mem_upperBounds, mem_lowerBounds] at h ⊢ refine ⟨fun x hx ↦ h.1 x hx.1, fun x hx ↦ h.2 x ?_⟩ intro y hy rcases le_or_lt y j with h_le | h_lt · exact hx y ⟨hy, h_le⟩ · exact le_trans (hx j ⟨hij_lt, le_rfl⟩) h_lt.le theorem isMax_of_succFn_le [LocallyFiniteOrder ι] (i : ι) (hi : succFn i ≤ i) : IsMax i := by refine fun j _ ↦ not_lt.mp fun hij_lt ↦ ?_ have h_succFn_eq : succFn i = i := le_antisymm hi (le_succFn i) have h_glb : IsGLB (Finset.Ioc i j : Set ι) i := by rw [Finset.coe_Ioc] have h := succFn_spec i rw [h_succFn_eq] at h exact isGLB_Ioc_of_isGLB_Ioi hij_lt h have hi_mem : i ∈ Finset.Ioc i j := by refine Finset.isGLB_mem _ h_glb ?_ exact ⟨_, Finset.mem_Ioc.mpr ⟨hij_lt, le_rfl⟩⟩ rw [Finset.mem_Ioc] at hi_mem exact lt_irrefl i hi_mem.1 theorem succFn_le_of_lt (i j : ι) (hij : i < j) : succFn i ≤ j := by have h := succFn_spec i rw [IsGLB, IsGreatest, mem_lowerBounds] at h exact h.1 j hij theorem le_of_lt_succFn (j i : ι) (hij : j < succFn i) : j ≤ i := by rw [lt_isGLB_iff (succFn_spec i)] at hij obtain ⟨k, hk_lb, hk⟩ := hij rw [mem_lowerBounds] at hk_lb exact not_lt.mp fun hi_lt_j ↦ not_le.mpr hk (hk_lb j hi_lt_j) noncomputable instance (priority := 100) [LocallyFiniteOrder ι] : SuccOrder ι where succ := succFn le_succ := le_succFn max_of_succ_le h := isMax_of_succFn_le _ h succ_le_of_lt h := succFn_le_of_lt _ _ h le_of_lt_succ h := le_of_lt_succFn _ _ h noncomputable instance (priority := 100) [LocallyFiniteOrder ι] : PredOrder ι := (inferInstance : PredOrder (OrderDual ιᵒᵈ)) end LinearLocallyFiniteOrder instance (priority := 100) LinearLocallyFiniteOrder.isSuccArchimedean [LocallyFiniteOrder ι] : IsSuccArchimedean ι where exists_succ_iterate_of_le := by intro i j hij rw [le_iff_lt_or_eq] at hij cases' hij with hij hij swap · refine ⟨0, ?_⟩ simpa only [Function.iterate_zero, id] using hij by_contra! h have h_lt : ∀ n, succ^[n] i < j := by intro n induction' n with n hn · simpa only [Function.iterate_zero, id] using hij · refine lt_of_le_of_ne ?_ (h _) rw [Function.iterate_succ', Function.comp_apply] exact succ_le_of_lt hn have h_mem : ∀ n, succ^[n] i ∈ Finset.Icc i j := fun n ↦ Finset.mem_Icc.mpr ⟨le_succ_iterate n i, (h_lt n).le⟩ obtain ⟨n, m, hnm, h_eq⟩ : ∃ n m, n < m ∧ succ^[n] i = succ^[m] i := by let f : ℕ → Finset.Icc i j := fun n ↦ ⟨succ^[n] i, h_mem n⟩ obtain ⟨n, m, hnm_ne, hfnm⟩ : ∃ n m, n ≠ m ∧ f n = f m := Finite.exists_ne_map_eq_of_infinite f have hnm_eq : succ^[n] i = succ^[m] i := by simpa only [f, Subtype.mk_eq_mk] using hfnm rcases le_total n m with h_le | h_le · exact ⟨n, m, lt_of_le_of_ne h_le hnm_ne, hnm_eq⟩ · exact ⟨m, n, lt_of_le_of_ne h_le hnm_ne.symm, hnm_eq.symm⟩ have h_max : IsMax (succ^[n] i) := isMax_iterate_succ_of_eq_of_ne h_eq hnm.ne exact not_le.mpr (h_lt n) (h_max (h_lt n).le) instance (priority := 100) LinearOrder.isPredArchimedean_of_isSuccArchimedean [SuccOrder ι] [PredOrder ι] [IsSuccArchimedean ι] : IsPredArchimedean ι where exists_pred_iterate_of_le := by intro i j hij have h_exists := exists_succ_iterate_of_le hij obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j := ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩ refine ⟨n, ?_⟩ rw [← hn_eq] induction' n with n · simp only [Nat.zero_eq, Function.iterate_zero, id] · rw [pred_succ_iterate_of_not_isMax] rw [Nat.succ_sub_succ_eq_sub, tsub_zero] suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this refine lt_of_le_of_ne ?_ ?_ · rw [Function.iterate_succ'] exact le_succ _ · rw [hn_eq] exact hn_lt_ne _ (Nat.lt_succ_self n) section toZ variable [SuccOrder ι] [IsSuccArchimedean ι] [PredOrder ι] {i0 i : ι} -- For "to_Z" /-- `toZ` numbers elements of `ι` according to their order, starting from `i0`. We prove in `orderIsoRangeToZOfLinearSuccPredArch` that this defines an `OrderIso` between `ι` and the range of `toZ`. -/ def toZ (i0 i : ι) : ℤ := dite (i0 ≤ i) (fun hi ↦ Nat.find (exists_succ_iterate_of_le hi)) fun hi ↦ -Nat.find (exists_pred_iterate_of_le (not_le.mp hi).le) theorem toZ_of_ge (hi : i0 ≤ i) : toZ i0 i = Nat.find (exists_succ_iterate_of_le hi) := dif_pos hi theorem toZ_of_lt (hi : i < i0) : toZ i0 i = -Nat.find (exists_pred_iterate_of_le hi.le) := dif_neg (not_le.mpr hi) @[simp] theorem toZ_of_eq : toZ i0 i0 = 0 := by rw [toZ_of_ge le_rfl] norm_cast refine le_antisymm (Nat.find_le ?_) (zero_le _) rw [Function.iterate_zero, id] theorem iterate_succ_toZ (i : ι) (hi : i0 ≤ i) : succ^[(toZ i0 i).toNat] i0 = i := by rw [toZ_of_ge hi, Int.toNat_natCast] exact Nat.find_spec (exists_succ_iterate_of_le hi) theorem iterate_pred_toZ (i : ι) (hi : i < i0) : pred^[(-toZ i0 i).toNat] i0 = i := by rw [toZ_of_lt hi, neg_neg, Int.toNat_natCast] exact Nat.find_spec (exists_pred_iterate_of_le hi.le) lemma toZ_nonneg (hi : i0 ≤ i) : 0 ≤ toZ i0 i := by rw [toZ_of_ge hi]; exact Int.natCast_nonneg _ theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by refine lt_of_le_of_ne ?_ ?_ · rw [toZ_of_lt hi] omega · by_contra h have h_eq := iterate_pred_toZ i hi rw [← h_eq, h] at hi simp only [neg_zero, Int.toNat_zero, Function.iterate_zero, id, lt_self_iff_false] at hi theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by rw [toZ_of_ge (le_succ_iterate _ _)] norm_cast exact Nat.find_min' _ rfl theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by rcases le_or_lt i0 (pred^[n] i0) with h | h · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h rw [h_eq, toZ_of_eq] omega · rw [toZ_of_lt h] refine Int.neg_le_neg ?_ norm_cast exact Nat.find_min' _ rfl theorem toZ_iterate_succ_of_not_isMax (n : ℕ) (hn : ¬IsMax (succ^[n] i0)) : toZ i0 (succ^[n] i0) = n := by let m := (toZ i0 (succ^[n] i0)).toNat have h_eq : succ^[m] i0 = succ^[n] i0 := iterate_succ_toZ _ (le_succ_iterate _ _) by_cases hmn : m = n · nth_rw 2 [← hmn] rw [Int.toNat_eq_max, toZ_of_ge (le_succ_iterate _ _), max_eq_left] exact Int.natCast_nonneg _ suffices IsMax (succ^[n] i0) from absurd this hn exact isMax_iterate_succ_of_eq_of_ne h_eq.symm (Ne.symm hmn) theorem toZ_iterate_pred_of_not_isMin (n : ℕ) (hn : ¬IsMin (pred^[n] i0)) : toZ i0 (pred^[n] i0) = -n := by cases' n with n n · simp only [Nat.zero_eq, Function.iterate_zero, id, toZ_of_eq, Nat.cast_zero, neg_zero]; rfl have : pred^[n.succ] i0 < i0 := by refine lt_of_le_of_ne (pred_iterate_le _ _) fun h_pred_iterate_eq ↦ hn ?_ have h_pred_eq_pred : pred^[n.succ] i0 = pred^[0] i0 := by rwa [Function.iterate_zero, id] exact isMin_iterate_pred_of_eq_of_ne h_pred_eq_pred (Nat.succ_ne_zero n) let m := (-toZ i0 (pred^[n.succ] i0)).toNat have h_eq : pred^[m] i0 = pred^[n.succ] i0 := iterate_pred_toZ _ this by_cases hmn : m = n + 1 · nth_rw 2 [← hmn] rw [Int.toNat_eq_max, toZ_of_lt this, max_eq_left, neg_neg] rw [neg_neg] exact Int.natCast_nonneg _ · suffices IsMin (pred^[n.succ] i0) from absurd this hn exact isMin_iterate_pred_of_eq_of_ne h_eq.symm (Ne.symm hmn) theorem le_of_toZ_le {j : ι} (h_le : toZ i0 i ≤ toZ i0 j) : i ≤ j := by rcases le_or_lt i0 i with hi | hi <;> rcases le_or_lt i0 j with hj | hj · rw [← iterate_succ_toZ i hi, ← iterate_succ_toZ j hj] exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ _) (Int.toNat_le_toNat h_le) · exact absurd ((toZ_neg hj).trans_le (toZ_nonneg hi)) (not_lt.mpr h_le) · exact hi.le.trans hj · rw [← iterate_pred_toZ i hi, ← iterate_pred_toZ j hj] refine Monotone.antitone_iterate_of_map_le pred_mono (pred_le _) (Int.toNat_le_toNat ?_) exact Int.neg_le_neg h_le theorem toZ_mono {i j : ι} (h_le : i ≤ j) : toZ i0 i ≤ toZ i0 j := by by_cases hi_max : IsMax i · rw [le_antisymm h_le (hi_max h_le)] by_cases hj_min : IsMin j · rw [le_antisymm h_le (hj_min h_le)] rcases le_or_lt i0 i with hi | hi <;> rcases le_or_lt i0 j with hj | hj · let m := Nat.find (exists_succ_iterate_of_le h_le) have hm : succ^[m] i = j := Nat.find_spec (exists_succ_iterate_of_le h_le) have hj_eq : j = succ^[(toZ i0 i).toNat + m] i0 := by rw [← hm, add_comm] nth_rw 1 [← iterate_succ_toZ i hi] rw [Function.iterate_add] rfl by_contra h by_cases hm0 : m = 0 · rw [hm0, Function.iterate_zero, id] at hm rw [hm] at h exact h (le_of_eq rfl) refine hi_max (max_of_succ_le (le_trans ?_ (@le_of_toZ_le _ _ _ _ _ i0 j i ?_))) · have h_succ_le : succ^[(toZ i0 i).toNat + 1] i0 ≤ j := by rw [hj_eq] refine Monotone.monotone_iterate_of_le_map succ_mono (le_succ i0) (add_le_add_left ?_ _) exact Nat.one_le_iff_ne_zero.mpr hm0 rwa [Function.iterate_succ', Function.comp_apply, iterate_succ_toZ i hi] at h_succ_le · exact le_of_not_le h · exact absurd h_le (not_le.mpr (hj.trans_le hi)) · exact (toZ_neg hi).le.trans (toZ_nonneg hj) · let m := Nat.find (exists_pred_iterate_of_le h_le) have hm : pred^[m] j = i := Nat.find_spec (exists_pred_iterate_of_le h_le) have hj_eq : i = pred^[(-toZ i0 j).toNat + m] i0 := by rw [← hm, add_comm] nth_rw 1 [← iterate_pred_toZ j hj] rw [Function.iterate_add] rfl by_contra h by_cases hm0 : m = 0 · rw [hm0, Function.iterate_zero, id] at hm rw [hm] at h exact h (le_of_eq rfl) refine hj_min (min_of_le_pred ?_) refine (@le_of_toZ_le _ _ _ _ _ i0 j i ?_).trans ?_ · exact le_of_not_le h · have h_le_pred : i ≤ pred^[(-toZ i0 j).toNat + 1] i0 := by rw [hj_eq] refine Monotone.antitone_iterate_of_map_le pred_mono (pred_le i0) (add_le_add_left ?_ _) exact Nat.one_le_iff_ne_zero.mpr hm0 rwa [Function.iterate_succ', Function.comp_apply, iterate_pred_toZ j hj] at h_le_pred theorem toZ_le_iff (i j : ι) : toZ i0 i ≤ toZ i0 j ↔ i ≤ j := ⟨le_of_toZ_le, toZ_mono⟩ theorem toZ_iterate_succ [NoMaxOrder ι] (n : ℕ) : toZ i0 (succ^[n] i0) = n := toZ_iterate_succ_of_not_isMax n (not_isMax _) theorem toZ_iterate_pred [NoMinOrder ι] (n : ℕ) : toZ i0 (pred^[n] i0) = -n := toZ_iterate_pred_of_not_isMin n (not_isMin _) theorem injective_toZ : Function.Injective (toZ i0) := fun _ _ h ↦ le_antisymm (le_of_toZ_le h.le) (le_of_toZ_le h.symm.le) end toZ section OrderIso variable [SuccOrder ι] [PredOrder ι] [IsSuccArchimedean ι] /-- `toZ` defines an `OrderIso` between `ι` and its range. -/ noncomputable def orderIsoRangeToZOfLinearSuccPredArch [hι : Nonempty ι] : ι ≃o Set.range (toZ hι.some) where toEquiv := Equiv.ofInjective _ injective_toZ map_rel_iff' := by intro i j; exact toZ_le_iff i j instance (priority := 100) countable_of_linear_succ_pred_arch : Countable ι := by cases' isEmpty_or_nonempty ι with _ hι · infer_instance · exact Countable.of_equiv _ orderIsoRangeToZOfLinearSuccPredArch.symm.toEquiv /-- If the order has neither bot nor top, `toZ` defines an `OrderIso` between `ι` and `ℤ`. -/ noncomputable def orderIsoIntOfLinearSuccPredArch [NoMaxOrder ι] [NoMinOrder ι] [hι : Nonempty ι] : ι ≃o ℤ where toFun := toZ hι.some invFun n := if 0 ≤ n then succ^[n.toNat] hι.some else pred^[(-n).toNat] hι.some left_inv i := by rcases le_or_lt hι.some i with hi | hi · have h_nonneg : 0 ≤ toZ hι.some i := toZ_nonneg hi simp_rw [if_pos h_nonneg] exact iterate_succ_toZ i hi · have h_neg : toZ hι.some i < 0 := toZ_neg hi simp_rw [if_neg (not_le.mpr h_neg)] exact iterate_pred_toZ i hi right_inv n := by rcases le_or_lt 0 n with hn | hn · simp_rw [if_pos hn] rw [toZ_iterate_succ] exact Int.toNat_of_nonneg hn · simp_rw [if_neg (not_le.mpr hn)] rw [toZ_iterate_pred] simp only [hn.le, Int.toNat_of_nonneg, Int.neg_nonneg_of_nonpos, Int.neg_neg] map_rel_iff' := by intro i j; exact toZ_le_iff i j /-- If the order has a bot but no top, `toZ` defines an `OrderIso` between `ι` and `ℕ`. -/ def orderIsoNatOfLinearSuccPredArch [NoMaxOrder ι] [OrderBot ι] : ι ≃o ℕ where toFun i := (toZ ⊥ i).toNat invFun n := succ^[n] ⊥ left_inv i := by dsimp only exact iterate_succ_toZ i bot_le right_inv n := by dsimp only rw [toZ_iterate_succ] exact Int.toNat_natCast n map_rel_iff' := by intro i j simp only [Equiv.coe_fn_mk, Int.toNat_le] rw [← @toZ_le_iff ι _ _ _ _ ⊥, Int.toNat_of_nonneg (toZ_nonneg bot_le)] /-- If the order has both a bot and a top, `toZ` gives an `OrderIso` between `ι` and `Finset.range n` for some `n`. -/ def orderIsoRangeOfLinearSuccPredArch [OrderBot ι] [OrderTop ι] : ι ≃o Finset.range ((toZ ⊥ (⊤ : ι)).toNat + 1) where toFun i := ⟨(toZ ⊥ i).toNat, Finset.mem_range_succ_iff.mpr (Int.toNat_le_toNat ((toZ_le_iff _ _).mpr le_top))⟩ invFun n := succ^[n] ⊥ left_inv i := iterate_succ_toZ i bot_le right_inv n := by ext1 simp only [Subtype.coe_mk] refine le_antisymm ?_ ?_ · rw [Int.toNat_le] exact toZ_iterate_succ_le _ by_cases hn_max : IsMax (succ^[↑n] (⊥ : ι)) · rw [← isTop_iff_isMax, isTop_iff_eq_top] at hn_max rw [hn_max] exact Nat.lt_succ_iff.mp (Finset.mem_range.mp n.prop) · rw [toZ_iterate_succ_of_not_isMax _ hn_max] simp only [Int.toNat_natCast, le_refl] map_rel_iff' := by intro i j simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Int.toNat_le] rw [← @toZ_le_iff ι _ _ _ _ ⊥, Int.toNat_of_nonneg (toZ_nonneg bot_le)] end OrderIso
Order\SuccPred\Relation.lean
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Order.SuccPred.Basic /-! # Relations on types with a `SuccOrder` This file contains properties about relations on types with a `SuccOrder` and their closure operations (like the transitive closure). -/ open Function Order Relation Set section PartialSucc variable {α : Type*} [PartialOrder α] [SuccOrder α] [IsSuccArchimedean α] /-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_succ_of_le (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n ≤ m) : ReflTransGen r n m := by revert h; refine Succ.rec ?_ ?_ hnm · intro _ exact ReflTransGen.refl · intro m hnm ih h have : ReflTransGen r n m := ih fun i hi => h i ⟨hi.1, hi.2.trans_le <| le_succ m⟩ rcases (le_succ m).eq_or_lt with hm | hm · rwa [← hm] exact this.tail (h m ⟨hnm, hm⟩) /-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `succ i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_succ_of_ge (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m ≤ n) : ReflTransGen r n m := by rw [← reflTransGen_swap] exact reflTransGen_of_succ_of_le (swap r) h hmn /-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_lt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n < m) : TransGen r n m := (reflTransGen_iff_eq_or_transGen.mp <| reflTransGen_of_succ_of_le r h hnm.le).resolve_left hnm.ne' /-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` if `succ i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_gt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m < n) : TransGen r n m := (reflTransGen_iff_eq_or_transGen.mp <| reflTransGen_of_succ_of_ge r h hmn.le).resolve_left hmn.ne end PartialSucc section LinearSucc variable {α : Type*} [LinearOrder α] [SuccOrder α] [IsSuccArchimedean α] /-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i` and `succ i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_succ (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : ReflTransGen r n m := (le_total n m).elim (reflTransGen_of_succ_of_le r h1) <| reflTransGen_of_succ_of_ge r h2 /-- For `n ≠ m`,`(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i` and `succ i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_ne (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) (hnm : n ≠ m) : TransGen r n m := (reflTransGen_iff_eq_or_transGen.mp (reflTransGen_of_succ r h1 h2)).resolve_left hnm.symm /-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ succ i` and `succ i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_succ_of_reflexive (r : α → α → Prop) {n m : α} (hr : Reflexive r) (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : TransGen r n m := by rcases eq_or_ne m n with (rfl | hmn); · exact TransGen.single (hr m) exact transGen_of_succ_of_ne r h1 h2 hmn.symm end LinearSucc section PartialPred variable {α : Type*} [PartialOrder α] [PredOrder α] [IsPredArchimedean α] /-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_pred_of_ge (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m ≤ n) : ReflTransGen r n m := reflTransGen_of_succ_of_le (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hnm /-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `pred i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_pred_of_le (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n ≤ m) : ReflTransGen r n m := reflTransGen_of_succ_of_ge (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hmn /-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `i ~ pred i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_gt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m < n) : TransGen r n m := transGen_of_succ_of_lt (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hnm /-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `pred i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_lt (r : α → α → Prop) {n m : α} (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n < m) : TransGen r n m := transGen_of_succ_of_gt (α := αᵒᵈ) r (fun x hx => h x ⟨hx.2, hx.1⟩) hmn end PartialPred section LinearPred variable {α : Type*} [LinearOrder α] [PredOrder α] [IsPredArchimedean α] /-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i` and `pred i ~ i` for all `i` between `n` and `m`. -/ theorem reflTransGen_of_pred (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : ReflTransGen r n m := reflTransGen_of_succ (α := αᵒᵈ) r (fun x hx => h1 x ⟨hx.2, hx.1⟩) fun x hx => h2 x ⟨hx.2, hx.1⟩ /-- For `n ≠ m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ pred i` and `pred i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_ne (r : α → α → Prop) {n m : α} (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) (hnm : n ≠ m) : TransGen r n m := transGen_of_succ_of_ne (α := αᵒᵈ) r (fun x hx => h1 x ⟨hx.2, hx.1⟩) (fun x hx => h2 x ⟨hx.2, hx.1⟩) hnm /-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ pred i` and `pred i ~ i` for all `i` between `n` and `m`. -/ theorem transGen_of_pred_of_reflexive (r : α → α → Prop) {n m : α} (hr : Reflexive r) (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : TransGen r n m := transGen_of_succ_of_reflexive (α := αᵒᵈ) r hr (fun x hx => h1 x ⟨hx.2, hx.1⟩) fun x hx => h2 x ⟨hx.2, hx.1⟩ end LinearPred
Order\UpperLower\Basic.lean
/- Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Sara Rousta -/ import Mathlib.Data.SetLike.Basic import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Data.Set.Lattice /-! # Up-sets and down-sets This file defines upper and lower sets in an order. ## Main declarations * `IsUpperSet`: Predicate for a set to be an upper set. This means every element greater than a member of the set is in the set itself. * `IsLowerSet`: Predicate for a set to be a lower set. This means every element less than a member of the set is in the set itself. * `UpperSet`: The type of upper sets. * `LowerSet`: The type of lower sets. * `upperClosure`: The greatest upper set containing a set. * `lowerClosure`: The least lower set containing a set. * `UpperSet.Ici`: Principal upper set. `Set.Ici` as an upper set. * `UpperSet.Ioi`: Strict principal upper set. `Set.Ioi` as an upper set. * `LowerSet.Iic`: Principal lower set. `Set.Iic` as a lower set. * `LowerSet.Iio`: Strict principal lower set. `Set.Iio` as a lower set. ## Notation * `×ˢ` is notation for `UpperSet.prod` / `LowerSet.prod`. ## Notes Upper sets are ordered by **reverse** inclusion. This convention is motivated by the fact that this makes them order-isomorphic to lower sets and antichains, and matches the convention on `Filter`. ## TODO Lattice structure on antichains. Order equivalence between upper/lower sets and antichains. -/ open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} {κ : ι → Sort*} /-! ### Unbundled upper/lower sets -/ section LE variable [LE α] [LE β] {s t : Set α} {a : α} /-- An upper set in an order `α` is a set such that any element greater than one of its members is also a member. Also called up-set, upward-closed set. -/ @[aesop norm unfold] def IsUpperSet (s : Set α) : Prop := ∀ ⦃a b : α⦄, a ≤ b → a ∈ s → b ∈ s /-- A lower set in an order `α` is a set such that any element less than one of its members is also a member. Also called down-set, downward-closed set. -/ @[aesop norm unfold] def IsLowerSet (s : Set α) : Prop := ∀ ⦃a b : α⦄, b ≤ a → a ∈ s → b ∈ s theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha @[simp] theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsLowerSet.compl⟩ @[simp] theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsUpperSet.compl⟩ theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) := isUpperSet_sUnion <| forall_mem_range.2 hf theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) := isLowerSet_sUnion <| forall_mem_range.2 hf theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋃ (i) (j), f i j) := isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋃ (i) (j), f i j) := isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) := isUpperSet_sInter <| forall_mem_range.2 hf theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) := isLowerSet_sInter <| forall_mem_range.2 hf theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋂ (i) (j), f i j) := isUpperSet_iInter fun i => isUpperSet_iInter <| hf i theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋂ (i) (j), f i j) := isLowerSet_iInter fun i => isLowerSet_iInter <| hf i @[simp] theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl @[simp] theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) : IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) : IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : IsUpperSet (s \ t) := fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩ lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : IsLowerSet (s \ t) := fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩ lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) := hs.sdiff <| by aesop lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) := hs.sdiff <| by aesop lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) := hs.sdiff <| by simpa using has lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) := hs.sdiff <| by simpa using has end LE section Preorder variable [Preorder α] [Preorder β] {s : Set α} {p : α → Prop} (a : α) theorem isUpperSet_Ici : IsUpperSet (Ici a) := fun _ _ => ge_trans theorem isLowerSet_Iic : IsLowerSet (Iic a) := fun _ _ => le_trans theorem isUpperSet_Ioi : IsUpperSet (Ioi a) := fun _ _ => flip lt_of_lt_of_le theorem isLowerSet_Iio : IsLowerSet (Iio a) := fun _ _ => lt_of_le_of_lt theorem isUpperSet_iff_Ici_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ici a ⊆ s := by simp [IsUpperSet, subset_def, @forall_swap (_ ∈ s)] theorem isLowerSet_iff_Iic_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iic a ⊆ s := by simp [IsLowerSet, subset_def, @forall_swap (_ ∈ s)] alias ⟨IsUpperSet.Ici_subset, _⟩ := isUpperSet_iff_Ici_subset alias ⟨IsLowerSet.Iic_subset, _⟩ := isLowerSet_iff_Iic_subset theorem IsUpperSet.Ioi_subset (h : IsUpperSet s) ⦃a⦄ (ha : a ∈ s) : Ioi a ⊆ s := Ioi_subset_Ici_self.trans <| h.Ici_subset ha theorem IsLowerSet.Iio_subset (h : IsLowerSet s) ⦃a⦄ (ha : a ∈ s) : Iio a ⊆ s := h.toDual.Ioi_subset ha theorem IsUpperSet.ordConnected (h : IsUpperSet s) : s.OrdConnected := ⟨fun _ ha _ _ => Icc_subset_Ici_self.trans <| h.Ici_subset ha⟩ theorem IsLowerSet.ordConnected (h : IsLowerSet s) : s.OrdConnected := ⟨fun _ _ _ hb => Icc_subset_Iic_self.trans <| h.Iic_subset hb⟩ theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f) : IsUpperSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) : IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by change IsUpperSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by change IsLowerSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ici a = Ici (e a) := by rw [← e.preimage_Ici, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ici_subset (mem_range_self _)] theorem OrderEmbedding.image_Iic (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iic a = Iic (e a) := e.dual.image_Ici he a theorem OrderEmbedding.image_Ioi (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ioi a = Ioi (e a) := by rw [← e.preimage_Ioi, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ioi_subset (mem_range_self _)] theorem OrderEmbedding.image_Iio (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iio a = Iio (e a) := e.dual.image_Ioi he a @[simp] theorem Set.monotone_mem : Monotone (· ∈ s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem Set.antitone_mem : Antitone (· ∈ s) ↔ IsLowerSet s := forall_swap @[simp] theorem isUpperSet_setOf : IsUpperSet { a | p a } ↔ Monotone p := Iff.rfl @[simp] theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p := forall_swap lemma IsUpperSet.upperBounds_subset (hs : IsUpperSet s) : s.Nonempty → upperBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha lemma IsLowerSet.lowerBounds_subset (hs : IsLowerSet s) : s.Nonempty → lowerBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha section OrderTop variable [OrderTop α] theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩ theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩ theorem IsUpperSet.not_top_mem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ := hs.top_mem.not.trans not_nonempty_iff_eq_empty end OrderTop section OrderBot variable [OrderBot α] theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩ theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩ theorem IsLowerSet.not_bot_mem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ := hs.bot_mem.not.trans not_nonempty_iff_eq_empty end OrderBot section NoMaxOrder variable [NoMaxOrder α] theorem IsUpperSet.not_bddAbove (hs : IsUpperSet s) : s.Nonempty → ¬BddAbove s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_gt b exact hc.not_le (hb <| hs ((hb ha).trans hc.le) ha) theorem not_bddAbove_Ici : ¬BddAbove (Ici a) := (isUpperSet_Ici _).not_bddAbove nonempty_Ici theorem not_bddAbove_Ioi : ¬BddAbove (Ioi a) := (isUpperSet_Ioi _).not_bddAbove nonempty_Ioi end NoMaxOrder section NoMinOrder variable [NoMinOrder α] theorem IsLowerSet.not_bddBelow (hs : IsLowerSet s) : s.Nonempty → ¬BddBelow s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_lt b exact hc.not_le (hb <| hs (hc.le.trans <| hb ha) ha) theorem not_bddBelow_Iic : ¬BddBelow (Iic a) := (isLowerSet_Iic _).not_bddBelow nonempty_Iic theorem not_bddBelow_Iio : ¬BddBelow (Iio a) := (isLowerSet_Iio _).not_bddBelow nonempty_Iio end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] theorem isLowerSet_iff_Iio_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iio a ⊆ s := by simp [isLowerSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] end PartialOrder /-! ### Upper/lower sets and Fibrations -/ namespace Relation variable {f : α → β} {s : Set α} lemma Fibration.isLowerSet_image [LE α] [LE β] (hf : Fibration (· ≤ ·) (· ≤ ·) f) {s : Set α} (hs : IsLowerSet s) : IsLowerSet (f '' s) := by rintro _ y' e ⟨x, hx, rfl⟩; obtain ⟨y, e', rfl⟩ := hf e; exact ⟨_, hs e' hx, rfl⟩ alias _root_.IsLowerSet.image_fibration := Fibration.isLowerSet_image lemma fibration_iff_isLowerSet_image_Iic [Preorder α] [LE β] : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ x, IsLowerSet (f '' Iic x) := ⟨fun h x ↦ (isLowerSet_Iic x).image_fibration h, fun H x _ e ↦ H x e ⟨x, le_rfl, rfl⟩⟩ lemma fibration_iff_isLowerSet_image [Preorder α] [LE β] : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ s, IsLowerSet s → IsLowerSet (f '' s) := ⟨Fibration.isLowerSet_image, fun H ↦ fibration_iff_isLowerSet_image_Iic.mpr (H _ <| isLowerSet_Iic ·)⟩ lemma fibration_iff_image_Iic [Preorder α] [Preorder β] (hf : Monotone f) : Fibration (· ≤ ·) (· ≤ ·) f ↔ ∀ x, f '' Iic x = Iic (f x) := ⟨fun H x ↦ le_antisymm (fun _ ⟨_, hy, e⟩ ↦ e ▸ hf hy) ((H.isLowerSet_image (isLowerSet_Iic x)).Iic_subset ⟨x, le_rfl, rfl⟩), fun H ↦ fibration_iff_isLowerSet_image_Iic.mpr (fun x ↦ (H x).symm ▸ isLowerSet_Iic (f x))⟩ lemma Fibration.isUpperSet_image [LE α] [LE β] (hf : Fibration (· ≥ ·) (· ≥ ·) f) {s : Set α} (hs : IsUpperSet s) : IsUpperSet (f '' s) := @Fibration.isLowerSet_image αᵒᵈ βᵒᵈ _ _ _ hf s hs alias _root_.IsUpperSet.image_fibration := Fibration.isUpperSet_image lemma fibration_iff_isUpperSet_image_Ici [Preorder α] [LE β] : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ x, IsUpperSet (f '' Ici x) := @fibration_iff_isLowerSet_image_Iic αᵒᵈ βᵒᵈ _ _ _ lemma fibration_iff_isUpperSet_image [Preorder α] [LE β] : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ s, IsUpperSet s → IsUpperSet (f '' s) := @fibration_iff_isLowerSet_image αᵒᵈ βᵒᵈ _ _ _ lemma fibration_iff_image_Ici [Preorder α] [Preorder β] (hf : Monotone f) : Fibration (· ≥ ·) (· ≥ ·) f ↔ ∀ x, f '' Ici x = Ici (f x) := fibration_iff_image_Iic hf.dual end Relation section LinearOrder variable [LinearOrder α] {s t : Set α} theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by by_contra! h simp_rw [Set.not_subset] at h obtain ⟨⟨a, has, hat⟩, b, hbt, hbs⟩ := h obtain hab | hba := le_total a b · exact hbs (hs hab has) · exact hat (ht hba hbt) theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s := hs.toDual.total ht.toDual end LinearOrder /-! ### Bundled upper/lower sets -/ section LE variable [LE α] @[inherit_doc IsUpperSet] structure UpperSet (α : Type*) [LE α] where /-- The carrier of an `UpperSet`. -/ carrier : Set α /-- The carrier of an `UpperSet` is an upper set. -/ upper' : IsUpperSet carrier extend_docs UpperSet before "The type of upper sets of an order." @[inherit_doc IsLowerSet] structure LowerSet (α : Type*) [LE α] where /-- The carrier of a `LowerSet`. -/ carrier : Set α /-- The carrier of a `LowerSet` is a lower set. -/ lower' : IsLowerSet carrier extend_docs LowerSet before "The type of lower sets of an order." namespace UpperSet instance : SetLike (UpperSet α) α where coe := UpperSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : UpperSet α) : Set α := s initialize_simps_projections UpperSet (carrier → coe) @[ext] theorem ext {s t : UpperSet α} : (s : Set α) = t → s = t := SetLike.ext' @[simp] theorem carrier_eq_coe (s : UpperSet α) : s.carrier = s := rfl @[simp] protected lemma upper (s : UpperSet α) : IsUpperSet (s : Set α) := s.upper' @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl end UpperSet namespace LowerSet instance : SetLike (LowerSet α) α where coe := LowerSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : LowerSet α) : Set α := s initialize_simps_projections LowerSet (carrier → coe) @[ext] theorem ext {s t : LowerSet α} : (s : Set α) = t → s = t := SetLike.ext' @[simp] theorem carrier_eq_coe (s : LowerSet α) : s.carrier = s := rfl @[simp] protected lemma lower (s : LowerSet α) : IsLowerSet (s : Set α) := s.lower' @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl end LowerSet /-! #### Order -/ namespace UpperSet variable {S : Set (UpperSet α)} {s t : UpperSet α} {a : α} instance : Sup (UpperSet α) := ⟨fun s t => ⟨s ∩ t, s.upper.inter t.upper⟩⟩ instance : Inf (UpperSet α) := ⟨fun s t => ⟨s ∪ t, s.upper.union t.upper⟩⟩ instance : Top (UpperSet α) := ⟨⟨∅, isUpperSet_empty⟩⟩ instance : Bot (UpperSet α) := ⟨⟨univ, isUpperSet_univ⟩⟩ instance : SupSet (UpperSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isUpperSet_iInter₂ fun s _ => s.upper⟩⟩ instance : InfSet (UpperSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isUpperSet_iUnion₂ fun s _ => s.upper⟩⟩ instance completeLattice : CompleteLattice (UpperSet α) := (toDual.injective.comp SetLike.coe_injective).completeLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance completelyDistribLattice : CompletelyDistribLattice (UpperSet α) := .ofMinimalAxioms $ (toDual.injective.comp SetLike.coe_injective).completelyDistribLatticeMinimalAxioms .of _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (UpperSet α) := ⟨⊥⟩ @[simp 1100, norm_cast] theorem coe_subset_coe : (s : Set α) ⊆ t ↔ t ≤ s := Iff.rfl @[simp 1100, norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ t < s := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : UpperSet α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : UpperSet α) : Set α) = univ := rfl @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊥ := by simp [SetLike.ext'_iff] @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊤ := by simp [SetLike.ext'_iff] @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊤ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : UpperSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∩ t := rfl @[simp, norm_cast] theorem coe_inf (s t : UpperSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∪ t := rfl @[simp, norm_cast] theorem coe_sSup (S : Set (UpperSet α)) : (↑(sSup S) : Set α) = ⋂ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_sInf (S : Set (UpperSet α)) : (↑(sInf S) : Set α) = ⋃ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_iSup (f : ι → UpperSet α) : (↑(⨆ i, f i) : Set α) = ⋂ i, f i := by simp [iSup] @[simp, norm_cast] theorem coe_iInf (f : ι → UpperSet α) : (↑(⨅ i, f i) : Set α) = ⋃ i, f i := by simp [iInf] @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iSup₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iSup] @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iInf₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iInf] @[simp] theorem not_mem_top : a ∉ (⊤ : UpperSet α) := id @[simp] theorem mem_bot : a ∈ (⊥ : UpperSet α) := trivial @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] @[simp] theorem mem_iSup_iff {f : ι → UpperSet α} : (a ∈ ⨆ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iInter @[simp] theorem mem_iInf_iff {f : ι → UpperSet α} : (a ∈ ⨅ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iUnion -- Porting note: no longer a @[simp] theorem mem_iSup₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp_rw [mem_iSup_iff] -- Porting note: no longer a @[simp] theorem mem_iInf₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp_rw [mem_iInf_iff] @[simp, norm_cast] theorem codisjoint_coe : Codisjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, codisjoint_iff, SetLike.ext'_iff] end UpperSet namespace LowerSet variable {S : Set (LowerSet α)} {s t : LowerSet α} {a : α} instance : Sup (LowerSet α) := ⟨fun s t => ⟨s ∪ t, fun _ _ h => Or.imp (s.lower h) (t.lower h)⟩⟩ instance : Inf (LowerSet α) := ⟨fun s t => ⟨s ∩ t, fun _ _ h => And.imp (s.lower h) (t.lower h)⟩⟩ instance : Top (LowerSet α) := ⟨⟨univ, fun _ _ _ => id⟩⟩ instance : Bot (LowerSet α) := ⟨⟨∅, fun _ _ _ => id⟩⟩ instance : SupSet (LowerSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isLowerSet_iUnion₂ fun s _ => s.lower⟩⟩ instance : InfSet (LowerSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isLowerSet_iInter₂ fun s _ => s.lower⟩⟩ instance completeLattice : CompleteLattice (LowerSet α) := SetLike.coe_injective.completeLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance completelyDistribLattice : CompletelyDistribLattice (LowerSet α) := .ofMinimalAxioms $ SetLike.coe_injective.completelyDistribLatticeMinimalAxioms .of _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (LowerSet α) := ⟨⊥⟩ @[norm_cast] lemma coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := Iff.rfl @[norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : LowerSet α) : Set α) = univ := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : LowerSet α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊤ := by simp [SetLike.ext'_iff] @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊥ := by simp [SetLike.ext'_iff] @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊥ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : LowerSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∪ t := rfl @[simp, norm_cast] theorem coe_inf (s t : LowerSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∩ t := rfl @[simp, norm_cast] theorem coe_sSup (S : Set (LowerSet α)) : (↑(sSup S) : Set α) = ⋃ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_sInf (S : Set (LowerSet α)) : (↑(sInf S) : Set α) = ⋂ s ∈ S, ↑s := rfl @[simp, norm_cast] theorem coe_iSup (f : ι → LowerSet α) : (↑(⨆ i, f i) : Set α) = ⋃ i, f i := by simp_rw [iSup, coe_sSup, mem_range, iUnion_exists, iUnion_iUnion_eq'] @[simp, norm_cast] theorem coe_iInf (f : ι → LowerSet α) : (↑(⨅ i, f i) : Set α) = ⋂ i, f i := by simp_rw [iInf, coe_sInf, mem_range, iInter_exists, iInter_iInter_eq'] @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iSup₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iSup] @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iInf₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iInf] @[simp] theorem mem_top : a ∈ (⊤ : LowerSet α) := trivial @[simp] theorem not_mem_bot : a ∉ (⊥ : LowerSet α) := id @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ @[simp] theorem mem_iSup_iff {f : ι → LowerSet α} : (a ∈ ⨆ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iUnion @[simp] theorem mem_iInf_iff {f : ι → LowerSet α} : (a ∈ ⨅ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iInter -- Porting note: no longer a @[simp] theorem mem_iSup₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp_rw [mem_iSup_iff] -- Porting note: no longer a @[simp] theorem mem_iInf₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp_rw [mem_iInf_iff] @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, SetLike.ext'_iff] end LowerSet /-! #### Complement -/ /-- The complement of a lower set as an upper set. -/ def UpperSet.compl (s : UpperSet α) : LowerSet α := ⟨sᶜ, s.upper.compl⟩ /-- The complement of a lower set as an upper set. -/ def LowerSet.compl (s : LowerSet α) : UpperSet α := ⟨sᶜ, s.lower.compl⟩ namespace UpperSet variable {s t : UpperSet α} {a : α} @[simp] theorem coe_compl (s : UpperSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl @[simp] nonrec theorem compl_compl (s : UpperSet α) : s.compl.compl = s := UpperSet.ext <| compl_compl _ @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl @[simp] protected theorem compl_sup (s t : UpperSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := LowerSet.ext compl_inf @[simp] protected theorem compl_inf (s t : UpperSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := LowerSet.ext compl_sup @[simp] protected theorem compl_top : (⊤ : UpperSet α).compl = ⊤ := LowerSet.ext compl_empty @[simp] protected theorem compl_bot : (⊥ : UpperSet α).compl = ⊥ := LowerSet.ext compl_univ @[simp] protected theorem compl_sSup (S : Set (UpperSet α)) : (sSup S).compl = ⨆ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sSup, compl_iInter₂, LowerSet.coe_iSup₂] @[simp] protected theorem compl_sInf (S : Set (UpperSet α)) : (sInf S).compl = ⨅ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sInf, compl_iUnion₂, LowerSet.coe_iInf₂] @[simp] protected theorem compl_iSup (f : ι → UpperSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iSup, compl_iInter, LowerSet.coe_iSup] @[simp] protected theorem compl_iInf (f : ι → UpperSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iInf, compl_iUnion, LowerSet.coe_iInf] -- Porting note: no longer a @[simp] theorem compl_iSup₂ (f : ∀ i, κ i → UpperSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp_rw [UpperSet.compl_iSup] -- Porting note: no longer a @[simp] theorem compl_iInf₂ (f : ∀ i, κ i → UpperSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp_rw [UpperSet.compl_iInf] end UpperSet namespace LowerSet variable {s t : LowerSet α} {a : α} @[simp] theorem coe_compl (s : LowerSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl @[simp] nonrec theorem compl_compl (s : LowerSet α) : s.compl.compl = s := LowerSet.ext <| compl_compl _ @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl protected theorem compl_sup (s t : LowerSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := UpperSet.ext compl_sup protected theorem compl_inf (s t : LowerSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := UpperSet.ext compl_inf protected theorem compl_top : (⊤ : LowerSet α).compl = ⊤ := UpperSet.ext compl_univ protected theorem compl_bot : (⊥ : LowerSet α).compl = ⊥ := UpperSet.ext compl_empty protected theorem compl_sSup (S : Set (LowerSet α)) : (sSup S).compl = ⨆ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sSup, compl_iUnion₂, UpperSet.coe_iSup₂] protected theorem compl_sInf (S : Set (LowerSet α)) : (sInf S).compl = ⨅ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sInf, compl_iInter₂, UpperSet.coe_iInf₂] protected theorem compl_iSup (f : ι → LowerSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iSup, compl_iUnion, UpperSet.coe_iSup] protected theorem compl_iInf (f : ι → LowerSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iInf, compl_iInter, UpperSet.coe_iInf] @[simp] theorem compl_iSup₂ (f : ∀ i, κ i → LowerSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp_rw [LowerSet.compl_iSup] @[simp] theorem compl_iInf₂ (f : ∀ i, κ i → LowerSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp_rw [LowerSet.compl_iInf] end LowerSet /-- Upper sets are order-isomorphic to lower sets under complementation. -/ @[simps] def upperSetIsoLowerSet : UpperSet α ≃o LowerSet α where toFun := UpperSet.compl invFun := LowerSet.compl left_inv := UpperSet.compl_compl right_inv := LowerSet.compl_compl map_rel_iff' := UpperSet.compl_le_compl end LE section LinearOrder variable [LinearOrder α] instance UpperSet.isTotal_le : IsTotal (UpperSet α) (· ≤ ·) := ⟨fun s t => t.upper.total s.upper⟩ instance LowerSet.isTotal_le : IsTotal (LowerSet α) (· ≤ ·) := ⟨fun s t => s.lower.total t.lower⟩ noncomputable instance UpperSet.instLinearOrder : LinearOrder (UpperSet α) := by classical exact Lattice.toLinearOrder _ noncomputable instance LowerSet.instLinearOrder : LinearOrder (LowerSet α) := by classical exact Lattice.toLinearOrder _ noncomputable instance UpperSet.instCompleteLinearOrder : CompleteLinearOrder (UpperSet α) := { completelyDistribLattice, instLinearOrder with } noncomputable instance LowerSet.instCompleteLinearOrder : CompleteLinearOrder (LowerSet α) := { completelyDistribLattice, instLinearOrder with } end LinearOrder /-! #### Map -/ section variable [Preorder α] [Preorder β] [Preorder γ] namespace UpperSet variable {f : α ≃o β} {s t : UpperSet α} {a : α} {b : β} /-- An order isomorphism of Preorders induces an order isomorphism of their upper sets. -/ def map (f : α ≃o β) : UpperSet α ≃o UpperSet β where toFun s := ⟨f '' s, s.upper.image f⟩ invFun t := ⟨f ⁻¹' t, t.upper.preimage f.monotone⟩ left_inv _ := ext <| f.preimage_image _ right_inv _ := ext <| f.image_preimage _ map_rel_iff' := image_subset_image_iff f.injective @[simp] theorem symm_map (f : α ≃o β) : (map f).symm = map f.symm := DFunLike.ext _ _ fun s => ext <| by convert Set.preimage_equiv_eq_image_symm s f.toEquiv @[simp] theorem mem_map : b ∈ map f s ↔ f.symm b ∈ s := by rw [← f.symm_symm, ← symm_map, f.symm_symm] rfl @[simp] theorem map_refl : map (OrderIso.refl α) = OrderIso.refl _ := by ext simp @[simp] theorem map_map (g : β ≃o γ) (f : α ≃o β) : map g (map f s) = map (f.trans g) s := by ext simp variable (f s t) @[simp, norm_cast] theorem coe_map : (map f s : Set β) = f '' s := rfl end UpperSet namespace LowerSet variable {f : α ≃o β} {s t : LowerSet α} {a : α} {b : β} /-- An order isomorphism of Preorders induces an order isomorphism of their lower sets. -/ def map (f : α ≃o β) : LowerSet α ≃o LowerSet β where toFun s := ⟨f '' s, s.lower.image f⟩ invFun t := ⟨f ⁻¹' t, t.lower.preimage f.monotone⟩ left_inv _ := SetLike.coe_injective <| f.preimage_image _ right_inv _ := SetLike.coe_injective <| f.image_preimage _ map_rel_iff' := image_subset_image_iff f.injective @[simp] theorem symm_map (f : α ≃o β) : (map f).symm = map f.symm := DFunLike.ext _ _ fun s => ext <| by convert Set.preimage_equiv_eq_image_symm s f.toEquiv @[simp] theorem mem_map {f : α ≃o β} {b : β} : b ∈ map f s ↔ f.symm b ∈ s := by rw [← f.symm_symm, ← symm_map, f.symm_symm] rfl @[simp] theorem map_refl : map (OrderIso.refl α) = OrderIso.refl _ := by ext simp @[simp] theorem map_map (g : β ≃o γ) (f : α ≃o β) : map g (map f s) = map (f.trans g) s := by ext simp variable (f s t) @[simp, norm_cast] theorem coe_map : (map f s : Set β) = f '' s := rfl end LowerSet namespace UpperSet @[simp] theorem compl_map (f : α ≃o β) (s : UpperSet α) : (map f s).compl = LowerSet.map f s.compl := SetLike.coe_injective (Set.image_compl_eq f.bijective).symm end UpperSet namespace LowerSet @[simp] theorem compl_map (f : α ≃o β) (s : LowerSet α) : (map f s).compl = UpperSet.map f s.compl := SetLike.coe_injective (Set.image_compl_eq f.bijective).symm end LowerSet end /-! #### Principal sets -/ namespace UpperSet section Preorder variable [Preorder α] [Preorder β] {s : UpperSet α} {a b : α} /-- The smallest upper set containing a given element. -/ nonrec def Ici (a : α) : UpperSet α := ⟨Ici a, isUpperSet_Ici a⟩ /-- The smallest upper set containing a given element. -/ nonrec def Ioi (a : α) : UpperSet α := ⟨Ioi a, isUpperSet_Ioi a⟩ @[simp] theorem coe_Ici (a : α) : ↑(Ici a) = Set.Ici a := rfl @[simp] theorem coe_Ioi (a : α) : ↑(Ioi a) = Set.Ioi a := rfl @[simp] theorem mem_Ici_iff : b ∈ Ici a ↔ a ≤ b := Iff.rfl @[simp] theorem mem_Ioi_iff : b ∈ Ioi a ↔ a < b := Iff.rfl @[simp] theorem map_Ici (f : α ≃o β) (a : α) : map f (Ici a) = Ici (f a) := by ext simp @[simp] theorem map_Ioi (f : α ≃o β) (a : α) : map f (Ioi a) = Ioi (f a) := by ext simp theorem Ici_le_Ioi (a : α) : Ici a ≤ Ioi a := Ioi_subset_Ici_self @[simp] nonrec theorem Ici_bot [OrderBot α] : Ici (⊥ : α) = ⊥ := SetLike.coe_injective Ici_bot @[simp] nonrec theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ⊤ := SetLike.coe_injective Ioi_top @[simp] lemma Ici_ne_top : Ici a ≠ ⊤ := SetLike.coe_ne_coe.1 nonempty_Ici.ne_empty @[simp] lemma Ici_lt_top : Ici a < ⊤ := lt_top_iff_ne_top.2 Ici_ne_top @[simp] lemma le_Ici : s ≤ Ici a ↔ a ∈ s := ⟨fun h ↦ h le_rfl, fun ha ↦ s.upper.Ici_subset ha⟩ end Preorder section PartialOrder variable [PartialOrder α] {a b : α} nonrec lemma Ici_injective : Injective (Ici : α → UpperSet α) := fun _a _b hab ↦ Ici_injective <| congr_arg ((↑) : _ → Set α) hab @[simp] lemma Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff lemma Ici_ne_Ici : Ici a ≠ Ici b ↔ a ≠ b := Ici_inj.not end PartialOrder @[simp] theorem Ici_sup [SemilatticeSup α] (a b : α) : Ici (a ⊔ b) = Ici a ⊔ Ici b := ext Ici_inter_Ici.symm section CompleteLattice variable [CompleteLattice α] @[simp] theorem Ici_sSup (S : Set α) : Ici (sSup S) = ⨆ a ∈ S, Ici a := SetLike.ext fun c => by simp only [mem_Ici_iff, mem_iSup_iff, sSup_le_iff] @[simp] theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⨆ i, Ici (f i) := SetLike.ext fun c => by simp only [mem_Ici_iff, mem_iSup_iff, iSup_le_iff] -- Porting note: no longer a @[simp] theorem Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⨆ (i) (j), Ici (f i j) := by simp_rw [Ici_iSup] end CompleteLattice end UpperSet namespace LowerSet section Preorder variable [Preorder α] [Preorder β] {s : LowerSet α} {a b : α} /-- Principal lower set. `Set.Iic` as a lower set. The smallest lower set containing a given element. -/ nonrec def Iic (a : α) : LowerSet α := ⟨Iic a, isLowerSet_Iic a⟩ /-- Strict principal lower set. `Set.Iio` as a lower set. -/ nonrec def Iio (a : α) : LowerSet α := ⟨Iio a, isLowerSet_Iio a⟩ @[simp] theorem coe_Iic (a : α) : ↑(Iic a) = Set.Iic a := rfl @[simp] theorem coe_Iio (a : α) : ↑(Iio a) = Set.Iio a := rfl @[simp] theorem mem_Iic_iff : b ∈ Iic a ↔ b ≤ a := Iff.rfl @[simp] theorem mem_Iio_iff : b ∈ Iio a ↔ b < a := Iff.rfl @[simp] theorem map_Iic (f : α ≃o β) (a : α) : map f (Iic a) = Iic (f a) := by ext simp @[simp] theorem map_Iio (f : α ≃o β) (a : α) : map f (Iio a) = Iio (f a) := by ext simp theorem Ioi_le_Ici (a : α) : Ioi a ≤ Ici a := Ioi_subset_Ici_self @[simp] nonrec theorem Iic_top [OrderTop α] : Iic (⊤ : α) = ⊤ := SetLike.coe_injective Iic_top @[simp] nonrec theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ⊥ := SetLike.coe_injective Iio_bot @[simp] lemma Iic_ne_bot : Iic a ≠ ⊥ := SetLike.coe_ne_coe.1 nonempty_Iic.ne_empty @[simp] lemma bot_lt_Iic : ⊥ < Iic a := bot_lt_iff_ne_bot.2 Iic_ne_bot @[simp] lemma Iic_le : Iic a ≤ s ↔ a ∈ s := ⟨fun h ↦ h le_rfl, fun ha ↦ s.lower.Iic_subset ha⟩ end Preorder section PartialOrder variable [PartialOrder α] {a b : α} nonrec lemma Iic_injective : Injective (Iic : α → LowerSet α) := fun _a _b hab ↦ Iic_injective <| congr_arg ((↑) : _ → Set α) hab @[simp] lemma Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff lemma Iic_ne_Iic : Iic a ≠ Iic b ↔ a ≠ b := Iic_inj.not end PartialOrder @[simp] theorem Iic_inf [SemilatticeInf α] (a b : α) : Iic (a ⊓ b) = Iic a ⊓ Iic b := SetLike.coe_injective Iic_inter_Iic.symm section CompleteLattice variable [CompleteLattice α] @[simp] theorem Iic_sInf (S : Set α) : Iic (sInf S) = ⨅ a ∈ S, Iic a := SetLike.ext fun c => by simp only [mem_Iic_iff, mem_iInf₂_iff, le_sInf_iff] @[simp] theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⨅ i, Iic (f i) := SetLike.ext fun c => by simp only [mem_Iic_iff, mem_iInf_iff, le_iInf_iff] -- Porting note: no longer a @[simp] theorem Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⨅ (i) (j), Iic (f i j) := by simp_rw [Iic_iInf] end CompleteLattice end LowerSet section closure variable [Preorder α] [Preorder β] {s t : Set α} {x : α} /-- The greatest upper set containing a given set. -/ def upperClosure (s : Set α) : UpperSet α := ⟨{ x | ∃ a ∈ s, a ≤ x }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hx.2.trans hle⟩⟩ /-- The least lower set containing a given set. -/ def lowerClosure (s : Set α) : LowerSet α := ⟨{ x | ∃ a ∈ s, x ≤ a }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hle.trans hx.2⟩⟩ -- Porting note (#11215): TODO: move `GaloisInsertion`s up, use them to prove lemmas @[simp] theorem mem_upperClosure : x ∈ upperClosure s ↔ ∃ a ∈ s, a ≤ x := Iff.rfl @[simp] theorem mem_lowerClosure : x ∈ lowerClosure s ↔ ∃ a ∈ s, x ≤ a := Iff.rfl -- We do not tag those two as `simp` to respect the abstraction. @[norm_cast] theorem coe_upperClosure (s : Set α) : ↑(upperClosure s) = ⋃ a ∈ s, Ici a := by ext simp @[norm_cast] theorem coe_lowerClosure (s : Set α) : ↑(lowerClosure s) = ⋃ a ∈ s, Iic a := by ext simp instance instDecidablePredMemUpperClosure [DecidablePred (∃ a ∈ s, a ≤ ·)] : DecidablePred (· ∈ upperClosure s) := ‹DecidablePred _› instance instDecidablePredMemLowerClosure [DecidablePred (∃ a ∈ s, · ≤ a)] : DecidablePred (· ∈ lowerClosure s) := ‹DecidablePred _› theorem subset_upperClosure : s ⊆ upperClosure s := fun x hx => ⟨x, hx, le_rfl⟩ theorem subset_lowerClosure : s ⊆ lowerClosure s := fun x hx => ⟨x, hx, le_rfl⟩ theorem upperClosure_min (h : s ⊆ t) (ht : IsUpperSet t) : ↑(upperClosure s) ⊆ t := fun _a ⟨_b, hb, hba⟩ => ht hba <| h hb theorem lowerClosure_min (h : s ⊆ t) (ht : IsLowerSet t) : ↑(lowerClosure s) ⊆ t := fun _a ⟨_b, hb, hab⟩ => ht hab <| h hb protected theorem IsUpperSet.upperClosure (hs : IsUpperSet s) : ↑(upperClosure s) = s := (upperClosure_min Subset.rfl hs).antisymm subset_upperClosure protected theorem IsLowerSet.lowerClosure (hs : IsLowerSet s) : ↑(lowerClosure s) = s := (lowerClosure_min Subset.rfl hs).antisymm subset_lowerClosure @[simp] protected theorem UpperSet.upperClosure (s : UpperSet α) : upperClosure (s : Set α) = s := SetLike.coe_injective s.2.upperClosure @[simp] protected theorem LowerSet.lowerClosure (s : LowerSet α) : lowerClosure (s : Set α) = s := SetLike.coe_injective s.2.lowerClosure @[simp] theorem upperClosure_image (f : α ≃o β) : upperClosure (f '' s) = UpperSet.map f (upperClosure s) := by rw [← f.symm_symm, ← UpperSet.symm_map, f.symm_symm] ext simp [-UpperSet.symm_map, UpperSet.map, OrderIso.symm, ← f.le_symm_apply] @[simp] theorem lowerClosure_image (f : α ≃o β) : lowerClosure (f '' s) = LowerSet.map f (lowerClosure s) := by rw [← f.symm_symm, ← LowerSet.symm_map, f.symm_symm] ext simp [-LowerSet.symm_map, LowerSet.map, OrderIso.symm, ← f.symm_apply_le] @[simp] theorem UpperSet.iInf_Ici (s : Set α) : ⨅ a ∈ s, UpperSet.Ici a = upperClosure s := by ext simp @[simp] theorem LowerSet.iSup_Iic (s : Set α) : ⨆ a ∈ s, LowerSet.Iic a = lowerClosure s := by ext simp @[simp] lemma lowerClosure_le {t : LowerSet α} : lowerClosure s ≤ t ↔ s ⊆ t := ⟨fun h ↦ subset_lowerClosure.trans <| LowerSet.coe_subset_coe.2 h, fun h ↦ lowerClosure_min h t.lower⟩ @[simp] lemma le_upperClosure {s : UpperSet α} : s ≤ upperClosure t ↔ t ⊆ s := ⟨fun h ↦ subset_upperClosure.trans <| UpperSet.coe_subset_coe.2 h, fun h ↦ upperClosure_min h s.upper⟩ theorem gc_upperClosure_coe : GaloisConnection (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) := fun _s _t ↦ le_upperClosure theorem gc_lowerClosure_coe : GaloisConnection (lowerClosure : Set α → LowerSet α) (↑) := fun _s _t ↦ lowerClosure_le /-- `upperClosure` forms a reversed Galois insertion with the coercion from upper sets to sets. -/ def giUpperClosureCoe : GaloisInsertion (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) where choice s hs := toDual (⟨s, fun a _b hab ha => hs ⟨a, ha, hab⟩⟩ : UpperSet α) gc := gc_upperClosure_coe le_l_u _ := subset_upperClosure choice_eq _s hs := ofDual.injective <| SetLike.coe_injective <| subset_upperClosure.antisymm hs /-- `lowerClosure` forms a Galois insertion with the coercion from lower sets to sets. -/ def giLowerClosureCoe : GaloisInsertion (lowerClosure : Set α → LowerSet α) (↑) where choice s hs := ⟨s, fun a _b hba ha => hs ⟨a, ha, hba⟩⟩ gc := gc_lowerClosure_coe le_l_u _ := subset_lowerClosure choice_eq _s hs := SetLike.coe_injective <| subset_lowerClosure.antisymm hs theorem upperClosure_anti : Antitone (upperClosure : Set α → UpperSet α) := gc_upperClosure_coe.monotone_l theorem lowerClosure_mono : Monotone (lowerClosure : Set α → LowerSet α) := gc_lowerClosure_coe.monotone_l @[simp] theorem upperClosure_empty : upperClosure (∅ : Set α) = ⊤ := (@gc_upperClosure_coe α).l_bot @[simp] theorem lowerClosure_empty : lowerClosure (∅ : Set α) = ⊥ := (@gc_lowerClosure_coe α).l_bot @[simp] theorem upperClosure_singleton (a : α) : upperClosure ({a} : Set α) = UpperSet.Ici a := by ext simp @[simp] theorem lowerClosure_singleton (a : α) : lowerClosure ({a} : Set α) = LowerSet.Iic a := by ext simp @[simp] theorem upperClosure_univ : upperClosure (univ : Set α) = ⊥ := bot_unique subset_upperClosure @[simp] theorem lowerClosure_univ : lowerClosure (univ : Set α) = ⊤ := top_unique subset_lowerClosure @[simp] theorem upperClosure_eq_top_iff : upperClosure s = ⊤ ↔ s = ∅ := (@gc_upperClosure_coe α _).l_eq_bot.trans subset_empty_iff @[simp] theorem lowerClosure_eq_bot_iff : lowerClosure s = ⊥ ↔ s = ∅ := (@gc_lowerClosure_coe α _).l_eq_bot.trans subset_empty_iff @[simp] theorem upperClosure_union (s t : Set α) : upperClosure (s ∪ t) = upperClosure s ⊓ upperClosure t := (@gc_upperClosure_coe α _).l_sup @[simp] theorem lowerClosure_union (s t : Set α) : lowerClosure (s ∪ t) = lowerClosure s ⊔ lowerClosure t := (@gc_lowerClosure_coe α _).l_sup @[simp] theorem upperClosure_iUnion (f : ι → Set α) : upperClosure (⋃ i, f i) = ⨅ i, upperClosure (f i) := (@gc_upperClosure_coe α _).l_iSup @[simp] theorem lowerClosure_iUnion (f : ι → Set α) : lowerClosure (⋃ i, f i) = ⨆ i, lowerClosure (f i) := (@gc_lowerClosure_coe α _).l_iSup @[simp] theorem upperClosure_sUnion (S : Set (Set α)) : upperClosure (⋃₀ S) = ⨅ s ∈ S, upperClosure s := by simp_rw [sUnion_eq_biUnion, upperClosure_iUnion] @[simp] theorem lowerClosure_sUnion (S : Set (Set α)) : lowerClosure (⋃₀ S) = ⨆ s ∈ S, lowerClosure s := by simp_rw [sUnion_eq_biUnion, lowerClosure_iUnion] theorem Set.OrdConnected.upperClosure_inter_lowerClosure (h : s.OrdConnected) : ↑(upperClosure s) ∩ ↑(lowerClosure s) = s := (subset_inter subset_upperClosure subset_lowerClosure).antisymm' fun _a ⟨⟨_b, hb, hba⟩, _c, hc, hac⟩ => h.out hb hc ⟨hba, hac⟩ theorem ordConnected_iff_upperClosure_inter_lowerClosure : s.OrdConnected ↔ ↑(upperClosure s) ∩ ↑(lowerClosure s) = s := by refine ⟨Set.OrdConnected.upperClosure_inter_lowerClosure, fun h => ?_⟩ rw [← h] exact (UpperSet.upper _).ordConnected.inter (LowerSet.lower _).ordConnected @[simp] theorem upperBounds_lowerClosure : upperBounds (lowerClosure s : Set α) = upperBounds s := (upperBounds_mono_set subset_lowerClosure).antisymm fun _a ha _b ⟨_c, hc, hcb⟩ ↦ hcb.trans <| ha hc @[simp] theorem lowerBounds_upperClosure : lowerBounds (upperClosure s : Set α) = lowerBounds s := (lowerBounds_mono_set subset_upperClosure).antisymm fun _a ha _b ⟨_c, hc, hcb⟩ ↦ (ha hc).trans hcb @[simp] theorem bddAbove_lowerClosure : BddAbove (lowerClosure s : Set α) ↔ BddAbove s := by simp_rw [BddAbove, upperBounds_lowerClosure] @[simp] theorem bddBelow_upperClosure : BddBelow (upperClosure s : Set α) ↔ BddBelow s := by simp_rw [BddBelow, lowerBounds_upperClosure] protected alias ⟨BddAbove.of_lowerClosure, BddAbove.lowerClosure⟩ := bddAbove_lowerClosure protected alias ⟨BddBelow.of_upperClosure, BddBelow.upperClosure⟩ := bddBelow_upperClosure @[simp] lemma IsLowerSet.disjoint_upperClosure_left (ht : IsLowerSet t) : Disjoint ↑(upperClosure s) t ↔ Disjoint s t := by refine ⟨Disjoint.mono_left subset_upperClosure, ?_⟩ simp only [disjoint_left, SetLike.mem_coe, mem_upperClosure, forall_exists_index, and_imp] exact fun h a b hb hba ha ↦ h hb <| ht hba ha @[simp] lemma IsLowerSet.disjoint_upperClosure_right (hs : IsLowerSet s) : Disjoint s (upperClosure t) ↔ Disjoint s t := by simpa only [disjoint_comm] using hs.disjoint_upperClosure_left @[simp] lemma IsUpperSet.disjoint_lowerClosure_left (ht : IsUpperSet t) : Disjoint ↑(lowerClosure s) t ↔ Disjoint s t := ht.toDual.disjoint_upperClosure_left @[simp] lemma IsUpperSet.disjoint_lowerClosure_right (hs : IsUpperSet s) : Disjoint s (lowerClosure t) ↔ Disjoint s t := hs.toDual.disjoint_upperClosure_right @[simp] lemma upperClosure_eq : ↑(upperClosure s) = s ↔ IsUpperSet s := ⟨(· ▸ UpperSet.upper _), IsUpperSet.upperClosure⟩ @[simp] lemma lowerClosure_eq : ↑(lowerClosure s) = s ↔ IsLowerSet s := @upperClosure_eq αᵒᵈ _ _ end closure /-! ### Set Difference -/ namespace LowerSet variable [Preorder α] {s : LowerSet α} {t : Set α} {a : α} /-- The biggest lower subset of a lower set `s` disjoint from a set `t`. -/ def sdiff (s : LowerSet α) (t : Set α) : LowerSet α where carrier := s \ upperClosure t lower' := s.lower.sdiff_of_isUpperSet (upperClosure t).upper /-- The biggest lower subset of a lower set `s` not containing an element `a`. -/ def erase (s : LowerSet α) (a : α) : LowerSet α where carrier := s \ UpperSet.Ici a lower' := s.lower.sdiff_of_isUpperSet (UpperSet.Ici a).upper @[simp, norm_cast] lemma coe_sdiff (s : LowerSet α) (t : Set α) : s.sdiff t = (s : Set α) \ upperClosure t := rfl @[simp, norm_cast] lemma coe_erase (s : LowerSet α) (a : α) : s.erase a = (s : Set α) \ UpperSet.Ici a := rfl @[simp] lemma sdiff_singleton (s : LowerSet α) (a : α) : s.sdiff {a} = s.erase a := by simp [sdiff, erase] lemma sdiff_le_left : s.sdiff t ≤ s := diff_subset lemma erase_le : s.erase a ≤ s := diff_subset @[simp] protected lemma sdiff_eq_left : s.sdiff t = s ↔ Disjoint ↑s t := by simp [← SetLike.coe_set_eq] @[simp] lemma erase_eq : s.erase a = s ↔ a ∉ s := by rw [← sdiff_singleton]; simp [-sdiff_singleton] @[simp] lemma sdiff_lt_left : s.sdiff t < s ↔ ¬ Disjoint ↑s t := sdiff_le_left.lt_iff_ne.trans LowerSet.sdiff_eq_left.not @[simp] lemma erase_lt : s.erase a < s ↔ a ∈ s := erase_le.lt_iff_ne.trans erase_eq.not_left @[simp] protected lemma sdiff_idem (s : LowerSet α) (t : Set α) : (s.sdiff t).sdiff t = s.sdiff t := SetLike.coe_injective sdiff_idem @[simp] lemma erase_idem (s : LowerSet α) (a : α) : (s.erase a).erase a = s.erase a := SetLike.coe_injective sdiff_idem lemma sdiff_sup_lowerClosure (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : s.sdiff t ⊔ lowerClosure t = s := by refine le_antisymm (sup_le sdiff_le_left <| lowerClosure_le.2 hts) fun a ha ↦ ?_ obtain hat | hat := em (a ∈ t) · exact subset_union_right (subset_lowerClosure hat) · refine subset_union_left ⟨ha, ?_⟩ rintro ⟨b, hb, hba⟩ exact hat <| hst _ ha _ hb hba lemma lowerClosure_sup_sdiff (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : lowerClosure t ⊔ s.sdiff t = s := by rw [sup_comm, sdiff_sup_lowerClosure hts hst] lemma erase_sup_Iic (ha : a ∈ s) (has : ∀ b ∈ s, a ≤ b → b = a) : s.erase a ⊔ Iic a = s := by rw [← lowerClosure_singleton, ← sdiff_singleton, sdiff_sup_lowerClosure] <;> simpa lemma Iic_sup_erase (ha : a ∈ s) (has : ∀ b ∈ s, a ≤ b → b = a) : Iic a ⊔ s.erase a = s := by rw [sup_comm, erase_sup_Iic ha has] end LowerSet namespace UpperSet variable [Preorder α] {s : UpperSet α} {t : Set α} {a : α} /-- The biggest upper subset of a upper set `s` disjoint from a set `t`. -/ def sdiff (s : UpperSet α) (t : Set α) : UpperSet α where carrier := s \ lowerClosure t upper' := s.upper.sdiff_of_isLowerSet (lowerClosure t).lower /-- The biggest upper subset of a upper set `s` not containing an element `a`. -/ def erase (s : UpperSet α) (a : α) : UpperSet α where carrier := s \ LowerSet.Iic a upper' := s.upper.sdiff_of_isLowerSet (LowerSet.Iic a).lower @[simp, norm_cast] lemma coe_sdiff (s : UpperSet α) (t : Set α) : s.sdiff t = (s : Set α) \ lowerClosure t := rfl @[simp, norm_cast] lemma coe_erase (s : UpperSet α) (a : α) : s.erase a = (s : Set α) \ LowerSet.Iic a := rfl @[simp] lemma sdiff_singleton (s : UpperSet α) (a : α) : s.sdiff {a} = s.erase a := by simp [sdiff, erase] lemma le_sdiff_left : s ≤ s.sdiff t := diff_subset lemma le_erase : s ≤ s.erase a := diff_subset @[simp] protected lemma sdiff_eq_left : s.sdiff t = s ↔ Disjoint ↑s t := by simp [← SetLike.coe_set_eq] @[simp] lemma erase_eq : s.erase a = s ↔ a ∉ s := by rw [← sdiff_singleton]; simp [-sdiff_singleton] @[simp] lemma lt_sdiff_left : s < s.sdiff t ↔ ¬ Disjoint ↑s t := le_sdiff_left.gt_iff_ne.trans UpperSet.sdiff_eq_left.not @[simp] lemma lt_erase : s < s.erase a ↔ a ∈ s := le_erase.gt_iff_ne.trans erase_eq.not_left @[simp] protected lemma sdiff_idem (s : UpperSet α) (t : Set α) : (s.sdiff t).sdiff t = s.sdiff t := SetLike.coe_injective sdiff_idem @[simp] lemma erase_idem (s : UpperSet α) (a : α) : (s.erase a).erase a = s.erase a := SetLike.coe_injective sdiff_idem lemma sdiff_inf_upperClosure (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : s.sdiff t ⊓ upperClosure t = s := by refine ge_antisymm (le_inf le_sdiff_left <| le_upperClosure.2 hts) fun a ha ↦ ?_ obtain hat | hat := em (a ∈ t) · exact subset_union_right (subset_upperClosure hat) · refine subset_union_left ⟨ha, ?_⟩ rintro ⟨b, hb, hab⟩ exact hat <| hst _ ha _ hb hab lemma upperClosure_inf_sdiff (hts : t ⊆ s) (hst : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : upperClosure t ⊓ s.sdiff t = s := by rw [inf_comm, sdiff_inf_upperClosure hts hst] lemma erase_inf_Ici (ha : a ∈ s) (has : ∀ b ∈ s, b ≤ a → b = a) : s.erase a ⊓ Ici a = s := by rw [← upperClosure_singleton, ← sdiff_singleton, sdiff_inf_upperClosure] <;> simpa lemma Ici_inf_erase (ha : a ∈ s) (has : ∀ b ∈ s, b ≤ a → b = a) : Ici a ⊓ s.erase a = s := by rw [inf_comm, erase_inf_Ici ha has] end UpperSet /-! ### Product -/ section Preorder variable [Preorder α] [Preorder β] section variable {s : Set α} {t : Set β} {x : α × β} theorem IsUpperSet.prod (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ×ˢ t) := fun _ _ h ha => ⟨hs h.1 ha.1, ht h.2 ha.2⟩ theorem IsLowerSet.prod (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ×ˢ t) := fun _ _ h ha => ⟨hs h.1 ha.1, ht h.2 ha.2⟩ end namespace UpperSet variable (s s₁ s₂ : UpperSet α) (t t₁ t₂ : UpperSet β) {x : α × β} /-- The product of two upper sets as an upper set. -/ def prod : UpperSet (α × β) := ⟨s ×ˢ t, s.2.prod t.2⟩ instance instSProd : SProd (UpperSet α) (UpperSet β) (UpperSet (α × β)) where sprod := UpperSet.prod @[simp, norm_cast] theorem coe_prod : ((s ×ˢ t : UpperSet (α × β)) : Set (α × β)) = (s : Set α) ×ˢ t := rfl @[simp] theorem mem_prod {s : UpperSet α} {t : UpperSet β} : x ∈ s ×ˢ t ↔ x.1 ∈ s ∧ x.2 ∈ t := Iff.rfl theorem Ici_prod (x : α × β) : Ici x = Ici x.1 ×ˢ Ici x.2 := rfl @[simp] theorem Ici_prod_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) := rfl @[simp] theorem prod_top : s ×ˢ (⊤ : UpperSet β) = ⊤ := ext prod_empty @[simp] theorem top_prod : (⊤ : UpperSet α) ×ˢ t = ⊤ := ext empty_prod @[simp] theorem bot_prod_bot : (⊥ : UpperSet α) ×ˢ (⊥ : UpperSet β) = ⊥ := ext univ_prod_univ @[simp] theorem sup_prod : (s₁ ⊔ s₂) ×ˢ t = s₁ ×ˢ t ⊔ s₂ ×ˢ t := ext inter_prod @[simp] theorem prod_sup : s ×ˢ (t₁ ⊔ t₂) = s ×ˢ t₁ ⊔ s ×ˢ t₂ := ext prod_inter @[simp] theorem inf_prod : (s₁ ⊓ s₂) ×ˢ t = s₁ ×ˢ t ⊓ s₂ ×ˢ t := ext union_prod @[simp] theorem prod_inf : s ×ˢ (t₁ ⊓ t₂) = s ×ˢ t₁ ⊓ s ×ˢ t₂ := ext prod_union theorem prod_sup_prod : s₁ ×ˢ t₁ ⊔ s₂ ×ˢ t₂ = (s₁ ⊔ s₂) ×ˢ (t₁ ⊔ t₂) := ext prod_inter_prod variable {s s₁ s₂ t t₁ t₂} @[mono] theorem prod_mono : s₁ ≤ s₂ → t₁ ≤ t₂ → s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ := Set.prod_mono theorem prod_mono_left : s₁ ≤ s₂ → s₁ ×ˢ t ≤ s₂ ×ˢ t := Set.prod_mono_left theorem prod_mono_right : t₁ ≤ t₂ → s ×ˢ t₁ ≤ s ×ˢ t₂ := Set.prod_mono_right @[simp] theorem prod_self_le_prod_self : s₁ ×ˢ s₁ ≤ s₂ ×ˢ s₂ ↔ s₁ ≤ s₂ := prod_self_subset_prod_self @[simp] theorem prod_self_lt_prod_self : s₁ ×ˢ s₁ < s₂ ×ˢ s₂ ↔ s₁ < s₂ := prod_self_ssubset_prod_self theorem prod_le_prod_iff : s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ ↔ s₁ ≤ s₂ ∧ t₁ ≤ t₂ ∨ s₂ = ⊤ ∨ t₂ = ⊤ := prod_subset_prod_iff.trans <| by simp @[simp] theorem prod_eq_top : s ×ˢ t = ⊤ ↔ s = ⊤ ∨ t = ⊤ := by simp_rw [SetLike.ext'_iff] exact prod_eq_empty_iff @[simp] theorem codisjoint_prod : Codisjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Codisjoint s₁ s₂ ∨ Codisjoint t₁ t₂ := by simp_rw [codisjoint_iff, prod_sup_prod, prod_eq_top] end UpperSet namespace LowerSet variable (s s₁ s₂ : LowerSet α) (t t₁ t₂ : LowerSet β) {x : α × β} /-- The product of two lower sets as a lower set. -/ def prod : LowerSet (α × β) := ⟨s ×ˢ t, s.2.prod t.2⟩ instance instSProd : SProd (LowerSet α) (LowerSet β) (LowerSet (α × β)) where sprod := LowerSet.prod @[simp, norm_cast] theorem coe_prod : ((s ×ˢ t : LowerSet (α × β)) : Set (α × β)) = (s : Set α) ×ˢ t := rfl @[simp] theorem mem_prod {s : LowerSet α} {t : LowerSet β} : x ∈ s ×ˢ t ↔ x.1 ∈ s ∧ x.2 ∈ t := Iff.rfl theorem Iic_prod (x : α × β) : Iic x = Iic x.1 ×ˢ Iic x.2 := rfl @[simp] theorem Ici_prod_Ici (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) := rfl @[simp] theorem prod_bot : s ×ˢ (⊥ : LowerSet β) = ⊥ := ext prod_empty @[simp] theorem bot_prod : (⊥ : LowerSet α) ×ˢ t = ⊥ := ext empty_prod @[simp] theorem top_prod_top : (⊤ : LowerSet α) ×ˢ (⊤ : LowerSet β) = ⊤ := ext univ_prod_univ @[simp] theorem inf_prod : (s₁ ⊓ s₂) ×ˢ t = s₁ ×ˢ t ⊓ s₂ ×ˢ t := ext inter_prod @[simp] theorem prod_inf : s ×ˢ (t₁ ⊓ t₂) = s ×ˢ t₁ ⊓ s ×ˢ t₂ := ext prod_inter @[simp] theorem sup_prod : (s₁ ⊔ s₂) ×ˢ t = s₁ ×ˢ t ⊔ s₂ ×ˢ t := ext union_prod @[simp] theorem prod_sup : s ×ˢ (t₁ ⊔ t₂) = s ×ˢ t₁ ⊔ s ×ˢ t₂ := ext prod_union theorem prod_inf_prod : s₁ ×ˢ t₁ ⊓ s₂ ×ˢ t₂ = (s₁ ⊓ s₂) ×ˢ (t₁ ⊓ t₂) := ext prod_inter_prod variable {s s₁ s₂ t t₁ t₂} theorem prod_mono : s₁ ≤ s₂ → t₁ ≤ t₂ → s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ := Set.prod_mono theorem prod_mono_left : s₁ ≤ s₂ → s₁ ×ˢ t ≤ s₂ ×ˢ t := Set.prod_mono_left theorem prod_mono_right : t₁ ≤ t₂ → s ×ˢ t₁ ≤ s ×ˢ t₂ := Set.prod_mono_right @[simp] theorem prod_self_le_prod_self : s₁ ×ˢ s₁ ≤ s₂ ×ˢ s₂ ↔ s₁ ≤ s₂ := prod_self_subset_prod_self @[simp] theorem prod_self_lt_prod_self : s₁ ×ˢ s₁ < s₂ ×ˢ s₂ ↔ s₁ < s₂ := prod_self_ssubset_prod_self theorem prod_le_prod_iff : s₁ ×ˢ t₁ ≤ s₂ ×ˢ t₂ ↔ s₁ ≤ s₂ ∧ t₁ ≤ t₂ ∨ s₁ = ⊥ ∨ t₁ = ⊥ := prod_subset_prod_iff.trans <| by simp @[simp] theorem prod_eq_bot : s ×ˢ t = ⊥ ↔ s = ⊥ ∨ t = ⊥ := by simp_rw [SetLike.ext'_iff] exact prod_eq_empty_iff @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_iff, prod_inf_prod, prod_eq_bot] end LowerSet @[simp] theorem upperClosure_prod (s : Set α) (t : Set β) : upperClosure (s ×ˢ t) = upperClosure s ×ˢ upperClosure t := by ext simp [Prod.le_def, @and_and_and_comm _ (_ ∈ t)] @[simp] theorem lowerClosure_prod (s : Set α) (t : Set β) : lowerClosure (s ×ˢ t) = lowerClosure s ×ˢ lowerClosure t := by ext simp [Prod.le_def, @and_and_and_comm _ (_ ∈ t)] end Preorder
Order\UpperLower\Hom.lean
/- Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.UpperLower.Basic import Mathlib.Order.Hom.CompleteLattice /-! # `UpperSet.Ici` etc as `Sup`/`sSup`/`Inf`/`sInf`-homomorphisms In this file we define `UpperSet.iciSupHom` etc. These functions are `UpperSet.Ici` and `LowerSet.Iic` bundled as `SupHom`s, `InfHom`s, `sSupHom`s, or `sInfHom`s. -/ variable {α : Type*} open OrderDual namespace UpperSet section SemilatticeSup variable [SemilatticeSup α] /-- `UpperSet.Ici` as a `SupHom`. -/ def iciSupHom : SupHom α (UpperSet α) := ⟨Ici, Ici_sup⟩ @[simp] theorem coe_iciSupHom : (iciSupHom : α → UpperSet α) = Ici := rfl @[simp] theorem iciSupHom_apply (a : α) : iciSupHom a = Ici a := rfl end SemilatticeSup variable [CompleteLattice α] /-- `UpperSet.Ici` as a `sSupHom`. -/ def icisSupHom : sSupHom α (UpperSet α) := ⟨Ici, fun s => (Ici_sSup s).trans sSup_image.symm⟩ -- Porting note: `ₓ` because typeclass assumption changed @[simp] theorem coe_icisSupHom : (icisSupHom : α → UpperSet α) = Ici := rfl -- Porting note: `ₓ` because typeclass assumption changed @[simp] theorem icisSupHom_apply (a : α) : icisSupHom a = Ici a := rfl -- Porting note: `ₓ` because typeclass assumption changed end UpperSet namespace LowerSet section SemilatticeInf variable [SemilatticeInf α] /-- `LowerSet.Iic` as an `InfHom`. -/ def iicInfHom : InfHom α (LowerSet α) := ⟨Iic, Iic_inf⟩ @[simp] theorem coe_iicInfHom : (iicInfHom : α → LowerSet α) = Iic := rfl @[simp] theorem iicInfHom_apply (a : α) : iicInfHom a = Iic a := rfl end SemilatticeInf variable [CompleteLattice α] /-- `LowerSet.Iic` as an `sInfHom`. -/ def iicsInfHom : sInfHom α (LowerSet α) := ⟨Iic, fun s => (Iic_sInf s).trans sInf_image.symm⟩ -- Porting note: `ₓ` because typeclass assumption changed @[simp] theorem coe_iicsInfHom : (iicsInfHom : α → LowerSet α) = Iic := rfl -- Porting note: `ₓ` because typeclass assumption changed @[simp] theorem iicsInfHom_apply (a : α) : iicsInfHom a = Iic a := rfl -- Porting note: `ₓ` because typeclass assumption changed end LowerSet
Order\UpperLower\LocallyFinite.lean
/- Copyright (c) 2023 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.UpperLower.Basic /-! # Upper and lower sets in a locally finite order In this file we characterise the interaction of `UpperSet`/`LowerSet` and `LocallyFiniteOrder`. -/ namespace Set variable {α : Type*} [Preorder α] {s : Set α} protected theorem Finite.upperClosure [LocallyFiniteOrderTop α] (hs : s.Finite) : (upperClosure s : Set α).Finite := by rw [coe_upperClosure] exact hs.biUnion fun _ _ => finite_Ici _ protected theorem Finite.lowerClosure [LocallyFiniteOrderBot α] (hs : s.Finite) : (lowerClosure s : Set α).Finite := by rw [coe_lowerClosure] exact hs.biUnion fun _ _ => finite_Iic _ end Set
Probability\BorelCantelli.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Martingale.BorelCantelli import Mathlib.Probability.ConditionalExpectation import Mathlib.Probability.Independence.Basic /-! # The second Borel-Cantelli lemma This file contains the *second Borel-Cantelli lemma* which states that, given a sequence of independent sets `(sₙ)` in a probability space, if `∑ n, μ sₙ = ∞`, then the limsup of `sₙ` has measure 1. We employ a proof using Lévy's generalized Borel-Cantelli by choosing an appropriate filtration. ## Main result - `ProbabilityTheory.measure_limsup_eq_one`: the second Borel-Cantelli lemma. **Note**: for the *first Borel-Cantelli lemma*, which holds in general measure spaces (not only in probability spaces), see `MeasureTheory.measure_limsup_eq_zero`. -/ open scoped ENNReal Topology open MeasureTheory namespace ProbabilityTheory variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [IsProbabilityMeasure μ] section BorelCantelli variable {ι β : Type*} [LinearOrder ι] [mβ : MeasurableSpace β] [NormedAddCommGroup β] [BorelSpace β] {f : ι → Ω → β} {i j : ι} {s : ι → Set Ω} theorem iIndepFun.indep_comap_natural_of_lt (hf : ∀ i, StronglyMeasurable (f i)) (hfi : iIndepFun (fun _ => mβ) f μ) (hij : i < j) : Indep (MeasurableSpace.comap (f j) mβ) (Filtration.natural f hf i) μ := by suffices Indep (⨆ k ∈ ({j} : Set ι), MeasurableSpace.comap (f k) mβ) (⨆ k ∈ {k | k ≤ i}, MeasurableSpace.comap (f k) mβ) μ by rwa [iSup_singleton] at this exact indep_iSup_of_disjoint (fun k => (hf k).measurable.comap_le) hfi (by simpa) theorem iIndepFun.condexp_natural_ae_eq_of_lt [SecondCountableTopology β] [CompleteSpace β] [NormedSpace ℝ β] (hf : ∀ i, StronglyMeasurable (f i)) (hfi : iIndepFun (fun _ => mβ) f μ) (hij : i < j) : μ[f j|Filtration.natural f hf i] =ᵐ[μ] fun _ => μ[f j] := condexp_indep_eq (hf j).measurable.comap_le (Filtration.le _ _) (comap_measurable <| f j).stronglyMeasurable (hfi.indep_comap_natural_of_lt hf hij) theorem iIndepSet.condexp_indicator_filtrationOfSet_ae_eq (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (hij : i < j) : μ[(s j).indicator (fun _ => 1 : Ω → ℝ)|filtrationOfSet hsm i] =ᵐ[μ] fun _ => (μ (s j)).toReal := by rw [Filtration.filtrationOfSet_eq_natural (β := ℝ) hsm] refine (iIndepFun.condexp_natural_ae_eq_of_lt _ hs.iIndepFun_indicator hij).trans ?_ simp only [integral_indicator_const _ (hsm _), Algebra.id.smul_eq_mul, mul_one]; rfl open Filter /-- **The second Borel-Cantelli lemma**: Given a sequence of independent sets `(sₙ)` such that `∑ n, μ sₙ = ∞`, `limsup sₙ` has measure 1. -/ theorem measure_limsup_eq_one {s : ℕ → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (hs' : (∑' n, μ (s n)) = ∞) : μ (limsup s atTop) = 1 := by rw [measure_congr (eventuallyEq_set.2 (ae_mem_limsup_atTop_iff μ <| measurableSet_filtrationOfSet' hsm) : (limsup s atTop : Set Ω) =ᵐ[μ] {ω | Tendsto (fun n => ∑ k ∈ Finset.range n, (μ[(s (k + 1)).indicator (1 : Ω → ℝ)|filtrationOfSet hsm k]) ω) atTop atTop})] suffices {ω | Tendsto (fun n => ∑ k ∈ Finset.range n, (μ[(s (k + 1)).indicator (1 : Ω → ℝ)|filtrationOfSet hsm k]) ω) atTop atTop} =ᵐ[μ] Set.univ by rw [measure_congr this, measure_univ] have : ∀ᵐ ω ∂μ, ∀ n, (μ[(s (n + 1)).indicator (1 : Ω → ℝ)|filtrationOfSet hsm n]) ω = _ := ae_all_iff.2 fun n => hs.condexp_indicator_filtrationOfSet_ae_eq hsm n.lt_succ_self filter_upwards [this] with ω hω refine eq_true (?_ : Tendsto _ _ _) simp_rw [hω] have htends : Tendsto (fun n => ∑ k ∈ Finset.range n, μ (s (k + 1))) atTop (𝓝 ∞) := by rw [← ENNReal.tsum_add_one_eq_top hs' (measure_ne_top _ _)] exact ENNReal.tendsto_nat_tsum _ rw [ENNReal.tendsto_nhds_top_iff_nnreal] at htends refine tendsto_atTop_atTop_of_monotone' ?_ ?_ · refine monotone_nat_of_le_succ fun n => ?_ rw [← sub_nonneg, Finset.sum_range_succ_sub_sum] exact ENNReal.toReal_nonneg · rintro ⟨B, hB⟩ refine not_eventually.2 (frequently_of_forall fun n => ?_) (htends B.toNNReal) rw [mem_upperBounds] at hB specialize hB (∑ k ∈ Finset.range n, μ (s (k + 1))).toReal _ · refine ⟨n, ?_⟩ rw [ENNReal.toReal_sum] exact fun _ _ => measure_ne_top _ _ · rw [not_lt, ← ENNReal.toReal_le_toReal (ENNReal.sum_lt_top _).ne ENNReal.coe_ne_top] · exact hB.trans (by simp) · exact fun _ _ => measure_ne_top _ _ end BorelCantelli end ProbabilityTheory
Probability\CDF.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.Probability.Kernel.Disintegration.CondCDF /-! # Cumulative distribution function of a real probability measure The cumulative distribution function (cdf) of a probability measure over `ℝ` is a monotone, right continuous function with limit 0 at -∞ and 1 at +∞, such that `cdf μ x = μ (Iic x)` for all `x : ℝ`. Two probability measures are equal if and only if they have the same cdf. ## Main definitions * `ProbabilityTheory.cdf μ`: cumulative distribution function of `μ : Measure ℝ`, defined as the conditional cdf (`ProbabilityTheory.condCDF`) of the product measure `(Measure.dirac Unit.unit).prod μ` evaluated at `Unit.unit`. The definition could be replaced by the more elementary `cdf μ x = (μ (Iic x)).toReal`, but using `condCDF` gives us access to its API, from which most properties of the cdf follow directly. ## Main statements * `ProbabilityTheory.ofReal_cdf`: for a probability measure `μ` and `x : ℝ`, `ENNReal.ofReal (cdf μ x) = μ (Iic x)`. * `MeasureTheory.Measure.ext_of_cdf`: two probability measures are equal if and only if they have the same cdf. ## TODO The definition could be extended to a finite measure by rescaling `condCDF`, but it would be nice to have more structure on Stieltjes functions first. Right now, if `f` is a Stieltjes function, `2 • f` makes no sense. We could define Stieltjes functions as a submodule. The definition could be extended to `ℝⁿ`, either by extending the definition of `condCDF`, or by using another construction here. -/ open MeasureTheory Set Filter open scoped Topology namespace ProbabilityTheory /-- Cumulative distribution function of a real measure. The definition currently makes sense only for probability measures. In that case, it satisfies `cdf μ x = (μ (Iic x)).toReal` (see `ProbabilityTheory.cdf_eq_toReal`). -/ noncomputable def cdf (μ : Measure ℝ) : StieltjesFunction := condCDF ((Measure.dirac Unit.unit).prod μ) Unit.unit section ExplicitMeasureArg variable (μ : Measure ℝ) /-- The cdf is non-negative. -/ lemma cdf_nonneg (x : ℝ) : 0 ≤ cdf μ x := condCDF_nonneg _ _ _ /-- The cdf is lower or equal to 1. -/ lemma cdf_le_one (x : ℝ) : cdf μ x ≤ 1 := condCDF_le_one _ _ _ /-- The cdf is monotone. -/ lemma monotone_cdf : Monotone (cdf μ) := (condCDF _ _).mono /-- The cdf tends to 0 at -∞. -/ lemma tendsto_cdf_atBot : Tendsto (cdf μ) atBot (𝓝 0) := tendsto_condCDF_atBot _ _ /-- The cdf tends to 1 at +∞. -/ lemma tendsto_cdf_atTop : Tendsto (cdf μ) atTop (𝓝 1) := tendsto_condCDF_atTop _ _ lemma ofReal_cdf [IsProbabilityMeasure μ] (x : ℝ) : ENNReal.ofReal (cdf μ x) = μ (Iic x) := by have := IsProbabilityMeasure.toIsFiniteMeasure (Measure.prod (Measure.dirac ()) μ) have h := lintegral_condCDF ((Measure.dirac Unit.unit).prod μ) x simpa only [MeasureTheory.Measure.fst_prod, Measure.prod_prod, measure_univ, one_mul, lintegral_dirac] using h lemma cdf_eq_toReal [IsProbabilityMeasure μ] (x : ℝ) : cdf μ x = (μ (Iic x)).toReal := by rw [← ofReal_cdf μ x, ENNReal.toReal_ofReal (cdf_nonneg μ x)] instance instIsProbabilityMeasurecdf : IsProbabilityMeasure (cdf μ).measure := by constructor simp only [StieltjesFunction.measure_univ _ (tendsto_cdf_atBot μ) (tendsto_cdf_atTop μ), sub_zero, ENNReal.ofReal_one] /-- The measure associated to the cdf of a probability measure is the same probability measure. -/ lemma measure_cdf [IsProbabilityMeasure μ] : (cdf μ).measure = μ := by refine Measure.ext_of_Iic (cdf μ).measure μ (fun a ↦ ?_) rw [StieltjesFunction.measure_Iic _ (tendsto_cdf_atBot μ), sub_zero, ofReal_cdf] end ExplicitMeasureArg lemma cdf_measure_stieltjesFunction (f : StieltjesFunction) (hf0 : Tendsto f atBot (𝓝 0)) (hf1 : Tendsto f atTop (𝓝 1)) : cdf f.measure = f := by refine (cdf f.measure).eq_of_measure_of_tendsto_atBot f ?_ (tendsto_cdf_atBot _) hf0 have h_prob : IsProbabilityMeasure f.measure := ⟨by rw [f.measure_univ hf0 hf1, sub_zero, ENNReal.ofReal_one]⟩ exact measure_cdf f.measure end ProbabilityTheory open ProbabilityTheory /-- If two real probability distributions have the same cdf, they are equal. -/ lemma MeasureTheory.Measure.eq_of_cdf (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (h : cdf μ = cdf ν) : μ = ν := by rw [← measure_cdf μ, ← measure_cdf ν, h] @[simp] lemma MeasureTheory.Measure.cdf_eq_iff (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] : cdf μ = cdf ν ↔ μ = ν := ⟨MeasureTheory.Measure.eq_of_cdf μ ν, fun h ↦ by rw [h]⟩
Probability\CondCount.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Bhavik Mehta -/ import Mathlib.Probability.ConditionalProbability import Mathlib.MeasureTheory.Measure.Count /-! # Classical probability The classical formulation of probability states that the probability of an event occurring in a finite probability space is the ratio of that event to all possible events. This notion can be expressed with measure theory using the counting measure. In particular, given the sets `s` and `t`, we define the probability of `t` occurring in `s` to be `|s|⁻¹ * |s ∩ t|`. With this definition, we recover the probability over the entire sample space when `s = Set.univ`. Classical probability is often used in combinatorics and we prove some useful lemmas in this file for that purpose. ## Main definition * `ProbabilityTheory.condCount`: given a set `s`, `condCount s` is the counting measure conditioned on `s`. This is a probability measure when `s` is finite and nonempty. ## Notes The original aim of this file is to provide a measure theoretic method of describing the probability an element of a set `s` satisfies some predicate `P`. Our current formulation still allow us to describe this by abusing the definitional equality of sets and predicates by simply writing `condCount s P`. We should avoid this however as none of the lemmas are written for predicates. -/ noncomputable section open ProbabilityTheory open MeasureTheory MeasurableSpace namespace ProbabilityTheory variable {Ω : Type*} [MeasurableSpace Ω] /-- Given a set `s`, `condCount s` is the counting measure conditioned on `s`. In particular, `condCount s t` is the proportion of `s` that is contained in `t`. This is a probability measure when `s` is finite and nonempty and is given by `ProbabilityTheory.condCount_isProbabilityMeasure`. -/ def condCount (s : Set Ω) : Measure Ω := Measure.count[|s] @[simp] theorem condCount_empty_meas : (condCount ∅ : Measure Ω) = 0 := by simp [condCount] theorem condCount_empty {s : Set Ω} : condCount s ∅ = 0 := by simp theorem finite_of_condCount_ne_zero {s t : Set Ω} (h : condCount s t ≠ 0) : s.Finite := by by_contra hs' simp [condCount, cond, Measure.count_apply_infinite hs'] at h theorem condCount_univ [Fintype Ω] {s : Set Ω} : condCount Set.univ s = Measure.count s / Fintype.card Ω := by rw [condCount, cond_apply _ MeasurableSet.univ, ← ENNReal.div_eq_inv_mul, Set.univ_inter] congr rw [← Finset.coe_univ, Measure.count_apply, Finset.univ.tsum_subtype' fun _ => (1 : ENNReal)] · simp [Finset.card_univ] · exact (@Finset.coe_univ Ω _).symm ▸ MeasurableSet.univ variable [MeasurableSingletonClass Ω] theorem condCount_isProbabilityMeasure {s : Set Ω} (hs : s.Finite) (hs' : s.Nonempty) : IsProbabilityMeasure (condCount s) := { measure_univ := by rw [condCount, cond_apply _ hs.measurableSet, Set.inter_univ, ENNReal.inv_mul_cancel] · exact fun h => hs'.ne_empty <| Measure.empty_of_count_eq_zero h · exact (Measure.count_apply_lt_top.2 hs).ne } theorem condCount_singleton (ω : Ω) (t : Set Ω) [Decidable (ω ∈ t)] : condCount {ω} t = if ω ∈ t then 1 else 0 := by rw [condCount, cond_apply _ (measurableSet_singleton ω), Measure.count_singleton, inv_one, one_mul] split_ifs · rw [(by simpa : ({ω} : Set Ω) ∩ t = {ω}), Measure.count_singleton] · rw [(by simpa : ({ω} : Set Ω) ∩ t = ∅), Measure.count_empty] variable {s t u : Set Ω} theorem condCount_inter_self (hs : s.Finite) : condCount s (s ∩ t) = condCount s t := by rw [condCount, cond_inter_self _ hs.measurableSet] theorem condCount_self (hs : s.Finite) (hs' : s.Nonempty) : condCount s s = 1 := by rw [condCount, cond_apply _ hs.measurableSet, Set.inter_self, ENNReal.inv_mul_cancel] · exact fun h => hs'.ne_empty <| Measure.empty_of_count_eq_zero h · exact (Measure.count_apply_lt_top.2 hs).ne theorem condCount_eq_one_of (hs : s.Finite) (hs' : s.Nonempty) (ht : s ⊆ t) : condCount s t = 1 := by haveI := condCount_isProbabilityMeasure hs hs' refine eq_of_le_of_not_lt prob_le_one ?_ rw [not_lt, ← condCount_self hs hs'] exact measure_mono ht theorem pred_true_of_condCount_eq_one (h : condCount s t = 1) : s ⊆ t := by have hsf := finite_of_condCount_ne_zero (by rw [h]; exact one_ne_zero) rw [condCount, cond_apply _ hsf.measurableSet, mul_comm] at h replace h := ENNReal.eq_inv_of_mul_eq_one_left h rw [inv_inv, Measure.count_apply_finite _ hsf, Measure.count_apply_finite _ (hsf.inter_of_left _), Nat.cast_inj] at h suffices s ∩ t = s by exact this ▸ fun x hx => hx.2 rw [← @Set.Finite.toFinset_inj _ _ _ (hsf.inter_of_left _) hsf] exact Finset.eq_of_subset_of_card_le (Set.Finite.toFinset_mono s.inter_subset_left) h.ge theorem condCount_eq_zero_iff (hs : s.Finite) : condCount s t = 0 ↔ s ∩ t = ∅ := by simp [condCount, cond_apply _ hs.measurableSet, Measure.count_apply_eq_top, Set.not_infinite.2 hs, Measure.count_apply_finite _ (hs.inter_of_left _)] theorem condCount_of_univ (hs : s.Finite) (hs' : s.Nonempty) : condCount s Set.univ = 1 := condCount_eq_one_of hs hs' s.subset_univ theorem condCount_inter (hs : s.Finite) : condCount s (t ∩ u) = condCount (s ∩ t) u * condCount s t := by by_cases hst : s ∩ t = ∅ · rw [hst, condCount_empty_meas, Measure.coe_zero, Pi.zero_apply, zero_mul, condCount_eq_zero_iff hs, ← Set.inter_assoc, hst, Set.empty_inter] rw [condCount, condCount, cond_apply _ hs.measurableSet, cond_apply _ hs.measurableSet, cond_apply _ (hs.inter_of_left _).measurableSet, mul_comm _ (Measure.count (s ∩ t)), ← mul_assoc, mul_comm _ (Measure.count (s ∩ t)), ← mul_assoc, ENNReal.mul_inv_cancel, one_mul, mul_comm, Set.inter_assoc] · rwa [← Measure.count_eq_zero_iff] at hst · exact (Measure.count_apply_lt_top.2 <| hs.inter_of_left _).ne theorem condCount_inter' (hs : s.Finite) : condCount s (t ∩ u) = condCount (s ∩ u) t * condCount s u := by rw [← Set.inter_comm] exact condCount_inter hs theorem condCount_union (hs : s.Finite) (htu : Disjoint t u) : condCount s (t ∪ u) = condCount s t + condCount s u := by rw [condCount, cond_apply _ hs.measurableSet, cond_apply _ hs.measurableSet, cond_apply _ hs.measurableSet, Set.inter_union_distrib_left, measure_union, mul_add] exacts [htu.mono inf_le_right inf_le_right, (hs.inter_of_left _).measurableSet] theorem condCount_compl (t : Set Ω) (hs : s.Finite) (hs' : s.Nonempty) : condCount s t + condCount s tᶜ = 1 := by rw [← condCount_union hs disjoint_compl_right, Set.union_compl_self, (condCount_isProbabilityMeasure hs hs').measure_univ] theorem condCount_disjoint_union (hs : s.Finite) (ht : t.Finite) (hst : Disjoint s t) : condCount s u * condCount (s ∪ t) s + condCount t u * condCount (s ∪ t) t = condCount (s ∪ t) u := by rcases s.eq_empty_or_nonempty with (rfl | hs') <;> rcases t.eq_empty_or_nonempty with (rfl | ht') · simp · simp [condCount_self ht ht'] · simp [condCount_self hs hs'] rw [condCount, condCount, condCount, cond_apply _ hs.measurableSet, cond_apply _ ht.measurableSet, cond_apply _ (hs.union ht).measurableSet, cond_apply _ (hs.union ht).measurableSet, cond_apply _ (hs.union ht).measurableSet] conv_lhs => rw [Set.union_inter_cancel_left, Set.union_inter_cancel_right, mul_comm (Measure.count (s ∪ t))⁻¹, mul_comm (Measure.count (s ∪ t))⁻¹, ← mul_assoc, ← mul_assoc, mul_comm _ (Measure.count s), mul_comm _ (Measure.count t), ← mul_assoc, ← mul_assoc] rw [ENNReal.mul_inv_cancel, ENNReal.mul_inv_cancel, one_mul, one_mul, ← add_mul, ← measure_union, Set.union_inter_distrib_right, mul_comm] exacts [hst.mono inf_le_left inf_le_left, (ht.inter_of_left _).measurableSet, Measure.count_ne_zero ht', (Measure.count_apply_lt_top.2 ht).ne, Measure.count_ne_zero hs', (Measure.count_apply_lt_top.2 hs).ne] /-- A version of the law of total probability for counting probabilities. -/ theorem condCount_add_compl_eq (u t : Set Ω) (hs : s.Finite) : condCount (s ∩ u) t * condCount s u + condCount (s ∩ uᶜ) t * condCount s uᶜ = condCount s t := by -- Porting note: The original proof used `conv_rhs`. However, that tactic timed out. have : condCount s t = (condCount (s ∩ u) t * condCount (s ∩ u ∪ s ∩ uᶜ) (s ∩ u) + condCount (s ∩ uᶜ) t * condCount (s ∩ u ∪ s ∩ uᶜ) (s ∩ uᶜ)) := by rw [condCount_disjoint_union (hs.inter_of_left _) (hs.inter_of_left _) (disjoint_compl_right.mono inf_le_right inf_le_right), Set.inter_union_compl] rw [this] simp [condCount_inter_self hs] end ProbabilityTheory
Probability\ConditionalExpectation.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Independence.Basic import Mathlib.MeasureTheory.Function.ConditionalExpectation.Basic /-! # Probabilistic properties of the conditional expectation This file contains some properties about the conditional expectation which does not belong in the main conditional expectation file. ## Main result * `MeasureTheory.condexp_indep_eq`: If `m₁, m₂` are independent σ-algebras and `f` is an `m₁`-measurable function, then `𝔼[f | m₂] = 𝔼[f]` almost everywhere. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory open ProbabilityTheory variable {Ω E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {m₁ m₂ m : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → E} /-- If `m₁, m₂` are independent σ-algebras and `f` is `m₁`-measurable, then `𝔼[f | m₂] = 𝔼[f]` almost everywhere. -/ theorem condexp_indep_eq (hle₁ : m₁ ≤ m) (hle₂ : m₂ ≤ m) [SigmaFinite (μ.trim hle₂)] (hf : StronglyMeasurable[m₁] f) (hindp : Indep m₁ m₂ μ) : μ[f|m₂] =ᵐ[μ] fun _ => μ[f] := by by_cases hfint : Integrable f μ swap; · rw [condexp_undef hfint, integral_undef hfint]; rfl refine (ae_eq_condexp_of_forall_setIntegral_eq hle₂ hfint (fun s _ hs => integrableOn_const.2 (Or.inr hs)) (fun s hms hs => ?_) stronglyMeasurable_const.aeStronglyMeasurable').symm rw [setIntegral_const] rw [← memℒp_one_iff_integrable] at hfint refine Memℒp.induction_stronglyMeasurable hle₁ ENNReal.one_ne_top _ ?_ ?_ ?_ ?_ hfint ?_ · exact ⟨f, hf, EventuallyEq.rfl⟩ · intro c t hmt _ rw [Indep_iff] at hindp rw [integral_indicator (hle₁ _ hmt), setIntegral_const, smul_smul, ← ENNReal.toReal_mul, mul_comm, ← hindp _ _ hmt hms, setIntegral_indicator (hle₁ _ hmt), setIntegral_const, Set.inter_comm] · intro u v _ huint hvint hu hv hu_eq hv_eq rw [memℒp_one_iff_integrable] at huint hvint rw [integral_add' huint hvint, smul_add, hu_eq, hv_eq, integral_add' huint.integrableOn hvint.integrableOn] · have heq₁ : (fun f : lpMeas E ℝ m₁ 1 μ => ∫ x, (f : Ω → E) x ∂μ) = (fun f : Lp E 1 μ => ∫ x, f x ∂μ) ∘ Submodule.subtypeL _ := by refine funext fun f => integral_congr_ae ?_ simp_rw [Submodule.coe_subtypeL', Submodule.coeSubtype]; norm_cast have heq₂ : (fun f : lpMeas E ℝ m₁ 1 μ => ∫ x in s, (f : Ω → E) x ∂μ) = (fun f : Lp E 1 μ => ∫ x in s, f x ∂μ) ∘ Submodule.subtypeL _ := by refine funext fun f => integral_congr_ae (ae_restrict_of_ae ?_) simp_rw [Submodule.coe_subtypeL', Submodule.coeSubtype] exact eventually_of_forall fun _ => (by trivial) refine isClosed_eq (Continuous.const_smul ?_ _) ?_ · rw [heq₁] exact continuous_integral.comp (ContinuousLinearMap.continuous _) · rw [heq₂] exact (continuous_setIntegral _).comp (ContinuousLinearMap.continuous _) · intro u v huv _ hueq rwa [← integral_congr_ae huv, ← (setIntegral_congr_ae (hle₂ _ hms) _ : ∫ x in s, u x ∂μ = ∫ x in s, v x ∂μ)] filter_upwards [huv] with x hx _ using hx end MeasureTheory
Probability\ConditionalProbability.lean
/- Copyright (c) 2022 Rishikesh Vaishnav. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rishikesh Vaishnav -/ import Mathlib.MeasureTheory.Measure.Typeclasses /-! # Conditional Probability This file defines conditional probability and includes basic results relating to it. Given some measure `μ` defined on a measure space on some type `Ω` and some `s : Set Ω`, we define the measure of `μ` conditioned on `s` as the restricted measure scaled by the inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling ensures that this is a probability measure (when `μ` is a finite measure). From this definition, we derive the "axiomatic" definition of conditional probability based on application: for any `s t : Set Ω`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`. ## Main Statements * `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent to conditioning on their intersection. * `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`. ## Notations This file uses the notation `μ[|s]` the measure of `μ` conditioned on `s`, and `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the application `μ[|s] t`). These notations are contained in the locale `ProbabilityTheory`. ## Implementation notes Because we have the alternative measure restriction application principles `Measure.restrict_apply` and `Measure.restrict_apply'`, which require measurability of the restricted and restricting sets, respectively, many of the theorems here will have corresponding alternatives as well. For the sake of brevity, we've chosen to only go with `Measure.restrict_apply'` for now, but the alternative theorems can be added if needed. Use of `@[simp]` generally follows the rule of removing conditions on a measure when possible. Hypotheses that are used to "define" a conditional distribution by requiring that the conditioning set has non-zero measure should be named using the abbreviation "c" (which stands for "conditionable") rather than "nz". For example `(hci : μ (s ∩ t) ≠ 0)` (rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined. ## Tags conditional, conditioned, bayes -/ noncomputable section open ENNReal MeasureTheory MeasureTheory.Measure MeasurableSpace Set variable {Ω Ω' α : Type*} {m : MeasurableSpace Ω} {m' : MeasurableSpace Ω'} (μ : Measure Ω) {s t : Set Ω} namespace ProbabilityTheory section Definitions /-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s` and scaled by the inverse of `μ s` (to make it a probability measure): `(μ s)⁻¹ • μ.restrict s`. -/ def cond (s : Set Ω) : Measure Ω := (μ s)⁻¹ • μ.restrict s end Definitions @[inherit_doc] scoped notation μ "[" s "|" t "]" => ProbabilityTheory.cond μ t s @[inherit_doc] scoped notation:max μ "[|" t "]" => ProbabilityTheory.cond μ t /-- The conditional probability measure of measure `μ` on `{ω | X ω = x}`. It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}` (to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/ scoped notation:max μ "[|" X " ← " x "]" => μ[|X ⁻¹' {x}] /-- The conditional probability measure of any measure on any set of finite positive measure is a probability measure. -/ theorem cond_isProbabilityMeasure_of_finite (hcs : μ s ≠ 0) (hs : μ s ≠ ∞) : IsProbabilityMeasure μ[|s] := ⟨by unfold ProbabilityTheory.cond simp only [Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, smul_eq_mul] exact ENNReal.inv_mul_cancel hcs hs⟩ /-- The conditional probability measure of any finite measure on any set of positive measure is a probability measure. -/ theorem cond_isProbabilityMeasure [IsFiniteMeasure μ] (hcs : μ s ≠ 0) : IsProbabilityMeasure μ[|s] := cond_isProbabilityMeasure_of_finite μ hcs (measure_ne_top μ s) instance cond_isFiniteMeasure : IsFiniteMeasure μ[|s] := by constructor simp only [Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, smul_eq_mul, ProbabilityTheory.cond, ← ENNReal.div_eq_inv_mul] exact ENNReal.div_self_le_one.trans_lt ENNReal.one_lt_top theorem cond_toMeasurable_eq : μ[|(toMeasurable μ s)] = μ[|s] := by unfold cond by_cases hnt : μ s = ∞ · simp [hnt] · simp [Measure.restrict_toMeasurable hnt] variable {μ} in lemma cond_absolutelyContinuous : μ[|s] ≪ μ := smul_absolutelyContinuous.trans restrict_le_self.absolutelyContinuous variable {μ} in lemma absolutelyContinuous_cond_univ [IsFiniteMeasure μ] : μ ≪ μ[|univ] := by rw [cond, restrict_univ] refine absolutelyContinuous_smul ?_ simp [measure_ne_top] section Bayes @[simp] theorem cond_empty : μ[|∅] = 0 := by simp [cond] @[simp] theorem cond_univ [IsProbabilityMeasure μ] : μ[|Set.univ] = μ := by simp [cond, measure_univ, Measure.restrict_univ] @[simp] lemma cond_eq_zero (hμs : μ s ≠ ⊤) : μ[|s] = 0 ↔ μ s = 0 := by simp [cond, hμs] lemma cond_eq_zero_of_meas_eq_zero (hμs : μ s = 0) : μ[|s] = 0 := by simp [hμs] /-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/ theorem cond_apply (hms : MeasurableSet s) (t : Set Ω) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by rw [cond, Measure.smul_apply, Measure.restrict_apply' hms, Set.inter_comm, smul_eq_mul] theorem cond_apply' {t : Set Ω} (hA : MeasurableSet t) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by rw [cond, Measure.smul_apply, Measure.restrict_apply hA, Set.inter_comm, smul_eq_mul] theorem cond_inter_self (hms : MeasurableSet s) (t : Set Ω) : μ[s ∩ t|s] = μ[t|s] := by rw [cond_apply _ hms, ← Set.inter_assoc, Set.inter_self, ← cond_apply _ hms] theorem inter_pos_of_cond_ne_zero (hms : MeasurableSet s) (hcst : μ[t|s] ≠ 0) : 0 < μ (s ∩ t) := by refine pos_iff_ne_zero.mpr (right_ne_zero_of_mul (a := (μ s)⁻¹) ?_) convert hcst simp [hms, Set.inter_comm, cond] theorem cond_pos_of_inter_ne_zero [IsFiniteMeasure μ] (hms : MeasurableSet s) (hci : μ (s ∩ t) ≠ 0) : 0 < μ[|s] t := by rw [cond_apply _ hms] refine ENNReal.mul_pos ?_ hci exact ENNReal.inv_ne_zero.mpr (measure_ne_top _ _) lemma cond_cond_eq_cond_inter' (hms : MeasurableSet s) (hmt : MeasurableSet t) (hcs : μ s ≠ ∞) : μ[|s][|t] = μ[|s ∩ t] := by ext u rw [cond_apply _ hmt, cond_apply _ hms, cond_apply _ hms, cond_apply _ (hms.inter hmt)] obtain hst | hst := eq_or_ne (μ (s ∩ t)) 0 · have : μ (s ∩ t ∩ u) = 0 := measure_mono_null Set.inter_subset_left hst simp [this, ← Set.inter_assoc] · have hcs' : μ s ≠ 0 := (measure_pos_of_superset Set.inter_subset_left hst).ne' simp [*, ← mul_assoc, ← Set.inter_assoc, ENNReal.mul_inv, ENNReal.mul_inv_cancel, mul_right_comm _ _ (μ s)⁻¹] /-- Conditioning first on `s` and then on `t` results in the same measure as conditioning on `s ∩ t`. -/ theorem cond_cond_eq_cond_inter [IsFiniteMeasure μ] (hms : MeasurableSet s) (hmt : MeasurableSet t) : μ[|s][|t] = μ[|s ∩ t] := cond_cond_eq_cond_inter' μ hms hmt (measure_ne_top μ s) theorem cond_mul_eq_inter' (hms : MeasurableSet s) (hcs' : μ s ≠ ∞) (t : Set Ω) : μ[t|s] * μ s = μ (s ∩ t) := by obtain hcs | hcs := eq_or_ne (μ s) 0 · simp [hcs, measure_inter_null_of_null_left] · rw [cond_apply μ hms t, mul_comm, ← mul_assoc, ENNReal.mul_inv_cancel hcs hcs', one_mul] theorem cond_mul_eq_inter [IsFiniteMeasure μ] (hms : MeasurableSet s) (t : Set Ω) : μ[t|s] * μ s = μ (s ∩ t) := cond_mul_eq_inter' μ hms (measure_ne_top _ s) t /-- A version of the law of total probability. -/ theorem cond_add_cond_compl_eq [IsFiniteMeasure μ] (hms : MeasurableSet s) : μ[t|s] * μ s + μ[t|sᶜ] * μ sᶜ = μ t := by rw [cond_mul_eq_inter μ hms, cond_mul_eq_inter μ hms.compl, Set.inter_comm _ t, Set.inter_comm _ t] exact measure_inter_add_diff t hms /-- **Bayes' Theorem** -/ theorem cond_eq_inv_mul_cond_mul [IsFiniteMeasure μ] (hms : MeasurableSet s) (hmt : MeasurableSet t) : μ[t|s] = (μ s)⁻¹ * μ[s|t] * μ t := by rw [mul_assoc, cond_mul_eq_inter μ hmt s, Set.inter_comm, cond_apply _ hms] end Bayes lemma comap_cond {i : Ω' → Ω} (hi : MeasurableEmbedding i) (hi' : ∀ᵐ ω ∂μ, ω ∈ range i) (hs : MeasurableSet s) : comap i μ[|s] = (comap i μ)[|i ⁻¹' s] := by ext t ht change μ (range i)ᶜ = 0 at hi' rw [cond_apply, comap_apply, cond_apply, comap_apply, comap_apply, image_inter, image_preimage_eq_inter_range, inter_right_comm, measure_inter_conull hi', measure_inter_conull hi'] all_goals first | exact hi.injective | exact hi.measurableSet_image' | exact hs | exact ht | exact hi.measurable hs | exact (hi.measurable hs).inter ht variable [Fintype α] [MeasurableSpace α] [DiscreteMeasurableSpace α] /-- The **law of total probability** for a random variable taking finitely many values: a measure `μ` can be expressed as a linear combination of its conditional measures `μ[|X ← x]` on fibers of a random variable `X` valued in a fintype. -/ lemma sum_meas_smul_cond_fiber {X : Ω → α} (hX : Measurable X) (μ : Measure Ω) [IsFiniteMeasure μ] : ∑ x, μ (X ⁻¹' {x}) • μ[|X ← x] = μ := by ext E hE calc _ = ∑ x, μ (X ⁻¹' {x} ∩ E) := by simp only [Measure.coe_finset_sum, Measure.coe_smul, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] simp_rw [mul_comm (μ _), cond_mul_eq_inter _ (hX (.singleton _))] _ = _ := by have : ⋃ x ∈ Finset.univ, X ⁻¹' {x} ∩ E = E := by ext; simp rw [← measure_biUnion_finset _ fun _ _ ↦ (hX (.singleton _)).inter hE, this] aesop (add simp [PairwiseDisjoint, Set.Pairwise, Function.onFun, disjoint_left]) end ProbabilityTheory
Probability\Density.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.Decomposition.RadonNikodym import Mathlib.MeasureTheory.Measure.Haar.OfBasis import Mathlib.Probability.Independence.Basic /-! # Probability density function This file defines the probability density function of random variables, by which we mean measurable functions taking values in a Borel space. The probability density function is defined as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f` is said to the probability density function of a random variable `X` if for all measurable sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing the distribution of a random variable, and are useful for calculating probabilities and finding moments (although the latter is better achieved with moment generating functions). This file also defines the continuous uniform distribution and proves some properties about random variables with this distribution. ## Main definitions * `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. * `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. * `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform distribution if it has a constant probability density function with a compact, non-null support. ## Main results * `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician, i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for all measurable `g : E → F`. * `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with pdf `f` has expectation `∫ x, x * f x dx`. * `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ` is the Lebesgue measure. ## TODO Ultimately, we would also like to define characteristic functions to describe distributions as it exists for all random variables. However, to define this, we will need Fourier transforms which we currently do not have. -/ open scoped Classical MeasureTheory NNReal ENNReal open TopologicalSpace MeasureTheory.Measure noncomputable section namespace MeasureTheory variable {Ω E : Type*} [MeasurableSpace E] /-- A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. -/ class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Prop where pdf' : AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ section HasPDF variable {_ : MeasurableSpace Ω} theorem hasPDF_iff {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} : HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := ⟨@HasPDF.pdf' _ _ _ _ _ _ _, HasPDF.mk⟩ theorem hasPDF_iff_of_aemeasurable {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hX : AEMeasurable X ℙ) : HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by rw [hasPDF_iff] simp only [hX, true_and] @[measurability] theorem HasPDF.aemeasurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [hX : HasPDF X ℙ μ] : AEMeasurable X ℙ := hX.pdf'.1 instance HasPDF.haveLebesgueDecomposition {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} [hX : HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ := hX.pdf'.2.1 theorem HasPDF.absolutelyContinuous {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} [hX : HasPDF X ℙ μ] : map X ℙ ≪ μ := hX.pdf'.2.2 /-- A random variable that `HasPDF` is quasi-measure preserving. -/ theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ := { measurable := h absolutelyContinuous := HasPDF.absolutelyContinuous } theorem HasPDF.congr {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ := ⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition, ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩ theorem HasPDF.congr' {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ := ⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩ /-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/ theorem hasPDF_of_map_eq_withDensity {X : Ω → E} {ℙ : Measure Ω} {μ : Measure E} (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ) (h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by refine ⟨hX, ?_, ?_⟩ <;> rw [h] · rw [withDensity_congr_ae hf.ae_eq_mk] exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk · exact withDensity_absolutelyContinuous μ f end HasPDF /-- If `X` is a random variable, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/ def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : E → ℝ≥0∞ := (map X ℙ).rnDeriv μ theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} : pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by rw [pdf_def, map_of_not_aemeasurable hX] exact rnDeriv_zero μ theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 := rnDeriv_of_not_haveLebesgueDecomposition h theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} (X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by contrapose! h exact pdf_of_not_aemeasurable h theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by refine ⟨?_, ?_, hac⟩ · exact aemeasurable_of_pdf_ne_zero X hpdf · contrapose! hpdf have := pdf_of_not_haveLebesgueDecomposition hpdf filter_upwards using congrFun this @[measurability] theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by exact measurable_rnDeriv _ _ theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ := withDensity_rnDeriv_le _ _ theorem setLIntegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) (s : Set E) : ∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by apply (withDensity_apply_le _ s).trans exact withDensity_pdf_le_map _ _ _ s @[deprecated (since := "2024-06-29")] alias set_lintegral_pdf_le_map := setLIntegral_pdf_le_map theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] : map X ℙ = μ.withDensity (pdf X ℙ μ) := by rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous] theorem map_eq_setLIntegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E} (hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ] @[deprecated (since := "2024-06-29")] alias map_eq_set_lintegral_pdf := map_eq_setLIntegral_pdf namespace pdf variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by rw [pdf_def, pdf_def, map_congr hXY] theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] : ∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by rw [← setLIntegral_univ, ← map_eq_setLIntegral_pdf X ℙ μ MeasurableSet.univ, map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ] theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞) (hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by rw [map_eq_withDensity_pdf X ℙ μ] apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf rw [lintegral_eq_measure_univ] exact measure_ne_top _ _ theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞) (hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := map_eq_withDensity_pdf X ℙ μ ▸ withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} : ∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ := rnDeriv_lt_top (map X ℙ) μ nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} : (fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ := ofReal_toReal_ae_eq ae_lt_top section IntegralPDFMul /-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/ theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by rw [pdf_def, ← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ), lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F} (hf : AEStronglyMeasurable f μ) : Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by -- Porting note: using `erw` because `rw` doesn't recognize `(f <| X ·)` as `f ∘ X` -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ), map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous] rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous] /-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ` where `μ` is a measure on the codomain of `X`. -/ theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F} (hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous), map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous, withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous] end IntegralPDFMul section variable {F : Type*} [MeasurableSpace F] {ν : Measure F} /-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving` map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`. `quasiMeasurePreserving_hasPDF` is more useful in the case we are working with a probability measure and a real-valued random variable. -/ theorem quasiMeasurePreserving_hasPDF {X : Ω → E} [HasPDF X ℙ μ] (hX : AEMeasurable X ℙ) {g : E → F} (hg : QuasiMeasurePreserving g μ ν) (hmap : (map g (map X ℙ)).HaveLebesgueDecomposition ν) : HasPDF (g ∘ X) ℙ ν := by wlog hmX : Measurable X · have hae : g ∘ X =ᵐ[ℙ] g ∘ hX.mk := hX.ae_eq_mk.mono fun x h ↦ by dsimp; rw [h] have hXmk : HasPDF hX.mk ℙ μ := HasPDF.congr hX.ae_eq_mk apply (HasPDF.congr' hae).mpr exact this hX.measurable_mk.aemeasurable hg (map_congr hX.ae_eq_mk ▸ hmap) hX.measurable_mk rw [hasPDF_iff, ← map_map hg.measurable hmX] refine ⟨(hg.measurable.comp hmX).aemeasurable, hmap, ?_⟩ rw [map_eq_withDensity_pdf X ℙ μ] refine AbsolutelyContinuous.mk fun s hsm hs => ?_ rw [map_apply hg.measurable hsm, withDensity_apply _ (hg.measurable hsm)] have := hg.absolutelyContinuous hs rw [map_apply hg.measurable hsm] at this exact setLIntegral_measure_zero _ _ this theorem quasiMeasurePreserving_hasPDF' [IsFiniteMeasure ℙ] [SigmaFinite ν] {X : Ω → E} [HasPDF X ℙ μ] (hX : AEMeasurable X ℙ) {g : E → F} (hg : QuasiMeasurePreserving g μ ν) : HasPDF (g ∘ X) ℙ ν := quasiMeasurePreserving_hasPDF hX hg inferInstance end section Real variable [IsFiniteMeasure ℙ] {X : Ω → ℝ} /-- A real-valued random variable `X` `HasPDF X ℙ λ` (where `λ` is the Lebesgue measure) if and only if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `λ`. -/ nonrec theorem _root_.Real.hasPDF_iff_of_aemeasurable (hX : AEMeasurable X ℙ) : HasPDF X ℙ ↔ map X ℙ ≪ volume := by rw [hasPDF_iff_of_aemeasurable hX] exact and_iff_right inferInstance theorem _root_.Real.hasPDF_iff : HasPDF X ℙ ↔ AEMeasurable X ℙ ∧ map X ℙ ≪ volume := by by_cases hX : AEMeasurable X ℙ · rw [Real.hasPDF_iff_of_aemeasurable hX, iff_and_self] exact fun _ => hX · exact ⟨fun h => False.elim (hX h.pdf'.1), fun h => False.elim (hX h.1)⟩ /-- If `X` is a real-valued random variable that has pdf `f`, then the expectation of `X` equals `∫ x, x * f x ∂λ` where `λ` is the Lebesgue measure. -/ theorem integral_mul_eq_integral [HasPDF X ℙ] : ∫ x, x * (pdf X ℙ volume x).toReal = ∫ x, X x ∂ℙ := calc _ = ∫ x, (pdf X ℙ volume x).toReal * x := by congr with x; exact mul_comm _ _ _ = _ := integral_pdf_smul measurable_id.aestronglyMeasurable theorem hasFiniteIntegral_mul {f : ℝ → ℝ} {g : ℝ → ℝ≥0∞} (hg : pdf X ℙ =ᵐ[volume] g) (hgi : ∫⁻ x, ‖f x‖₊ * g x ≠ ∞) : HasFiniteIntegral fun x => f x * (pdf X ℙ volume x).toReal := by rw [HasFiniteIntegral] have : (fun x => ↑‖f x‖₊ * g x) =ᵐ[volume] fun x => ‖f x * (pdf X ℙ volume x).toReal‖₊ := by refine ae_eq_trans (Filter.EventuallyEq.mul (ae_eq_refl fun x => (‖f x‖₊ : ℝ≥0∞)) (ae_eq_trans hg.symm ofReal_toReal_ae_eq.symm)) ?_ simp_rw [← smul_eq_mul, nnnorm_smul, ENNReal.coe_mul, smul_eq_mul] refine Filter.EventuallyEq.mul (ae_eq_refl _) ?_ simp only [Real.ennnorm_eq_ofReal ENNReal.toReal_nonneg, ae_eq_refl] rwa [lt_top_iff_ne_top, ← lintegral_congr_ae this] end Real section TwoVariables open ProbabilityTheory variable {F : Type*} [MeasurableSpace F] {ν : Measure F} {X : Ω → E} {Y : Ω → F} /-- Random variables are independent iff their joint density is a product of marginal densities. -/ theorem indepFun_iff_pdf_prod_eq_pdf_mul_pdf [IsFiniteMeasure ℙ] [SigmaFinite μ] [SigmaFinite ν] [HasPDF (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν)] : IndepFun X Y ℙ ↔ pdf (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν) =ᵐ[μ.prod ν] fun z ↦ pdf X ℙ μ z.1 * pdf Y ℙ ν z.2 := by have : HasPDF X ℙ μ := quasiMeasurePreserving_hasPDF' (μ := μ.prod ν) (HasPDF.aemeasurable (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν)) quasiMeasurePreserving_fst have : HasPDF Y ℙ ν := quasiMeasurePreserving_hasPDF' (μ := μ.prod ν) (HasPDF.aemeasurable (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν)) quasiMeasurePreserving_snd have h₀ : (ℙ.map X).prod (ℙ.map Y) = (μ.prod ν).withDensity fun z ↦ pdf X ℙ μ z.1 * pdf Y ℙ ν z.2 := prod_eq fun s t hs ht ↦ by rw [withDensity_apply _ (hs.prod ht), ← prod_restrict, lintegral_prod_mul (measurable_pdf X ℙ μ).aemeasurable (measurable_pdf Y ℙ ν).aemeasurable, map_eq_setLIntegral_pdf X ℙ μ hs, map_eq_setLIntegral_pdf Y ℙ ν ht] rw [indepFun_iff_map_prod_eq_prod_map_map (HasPDF.aemeasurable X ℙ μ) (HasPDF.aemeasurable Y ℙ ν), ← eq_of_map_eq_withDensity, h₀] exact (((measurable_pdf X ℙ μ).comp measurable_fst).mul ((measurable_pdf Y ℙ ν).comp measurable_snd)).aemeasurable end TwoVariables end pdf end MeasureTheory
Probability\IdentDistrib.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.Probability.Variance import Mathlib.MeasureTheory.Function.UniformIntegrable /-! # Identically distributed random variables Two random variables defined on two (possibly different) probability spaces but taking value in the same space are *identically distributed* if their distributions (i.e., the image probability measures on the target space) coincide. We define this concept and establish its basic properties in this file. ## Main definitions and results * `IdentDistrib f g μ ν` registers that the image of `μ` under `f` coincides with the image of `ν` under `g` (and that `f` and `g` are almost everywhere measurable, as otherwise the image measures don't make sense). The measures can be kept implicit as in `IdentDistrib f g` if the spaces are registered as measure spaces. * `IdentDistrib.comp`: being identically distributed is stable under composition with measurable maps. There are two main kinds of lemmas, under the assumption that `f` and `g` are identically distributed: lemmas saying that two quantities computed for `f` and `g` are the same, and lemmas saying that if `f` has some property then `g` also has it. The first kind is registered as `IdentDistrib.foo_fst`, the second one as `IdentDistrib.foo_snd` (in the latter case, to deduce a property of `f` from one of `g`, use `h.symm.foo_snd` where `h : IdentDistrib f g μ ν`). For instance: * `IdentDistrib.measure_mem_eq`: if `f` and `g` are identically distributed, then the probabilities that they belong to a given measurable set are the same. * `IdentDistrib.integral_eq`: if `f` and `g` are identically distributed, then their integrals are the same. * `IdentDistrib.variance_eq`: if `f` and `g` are identically distributed, then their variances are the same. * `IdentDistrib.aestronglyMeasurable_snd`: if `f` and `g` are identically distributed and `f` is almost everywhere strongly measurable, then so is `g`. * `IdentDistrib.memℒp_snd`: if `f` and `g` are identically distributed and `f` belongs to `ℒp`, then so does `g`. We also register several dot notation shortcuts for convenience. For instance, if `h : IdentDistrib f g μ ν`, then `h.sq` states that `f^2` and `g^2` are identically distributed, and `h.norm` states that `‖f‖` and `‖g‖` are identically distributed, and so on. -/ open MeasureTheory Filter Finset noncomputable section open scoped Topology MeasureTheory ENNReal NNReal variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] namespace ProbabilityTheory /-- Two functions defined on two (possibly different) measure spaces are identically distributed if their image measures coincide. This only makes sense when the functions are ae measurable (as otherwise the image measures are not defined), so we require this as well in the definition. -/ structure IdentDistrib (f : α → γ) (g : β → γ) (μ : Measure α := by volume_tac) (ν : Measure β := by volume_tac) : Prop where aemeasurable_fst : AEMeasurable f μ aemeasurable_snd : AEMeasurable g ν map_eq : Measure.map f μ = Measure.map g ν namespace IdentDistrib open TopologicalSpace variable {μ : Measure α} {ν : Measure β} {f : α → γ} {g : β → γ} protected theorem refl (hf : AEMeasurable f μ) : IdentDistrib f f μ μ := { aemeasurable_fst := hf aemeasurable_snd := hf map_eq := rfl } protected theorem symm (h : IdentDistrib f g μ ν) : IdentDistrib g f ν μ := { aemeasurable_fst := h.aemeasurable_snd aemeasurable_snd := h.aemeasurable_fst map_eq := h.map_eq.symm } protected theorem trans {ρ : Measure δ} {h : δ → γ} (h₁ : IdentDistrib f g μ ν) (h₂ : IdentDistrib g h ν ρ) : IdentDistrib f h μ ρ := { aemeasurable_fst := h₁.aemeasurable_fst aemeasurable_snd := h₂.aemeasurable_snd map_eq := h₁.map_eq.trans h₂.map_eq } protected theorem comp_of_aemeasurable {u : γ → δ} (h : IdentDistrib f g μ ν) (hu : AEMeasurable u (Measure.map f μ)) : IdentDistrib (u ∘ f) (u ∘ g) μ ν := { aemeasurable_fst := hu.comp_aemeasurable h.aemeasurable_fst aemeasurable_snd := by rw [h.map_eq] at hu; exact hu.comp_aemeasurable h.aemeasurable_snd map_eq := by rw [← AEMeasurable.map_map_of_aemeasurable hu h.aemeasurable_fst, ← AEMeasurable.map_map_of_aemeasurable _ h.aemeasurable_snd, h.map_eq] rwa [← h.map_eq] } protected theorem comp {u : γ → δ} (h : IdentDistrib f g μ ν) (hu : Measurable u) : IdentDistrib (u ∘ f) (u ∘ g) μ ν := h.comp_of_aemeasurable hu.aemeasurable protected theorem of_ae_eq {g : α → γ} (hf : AEMeasurable f μ) (heq : f =ᵐ[μ] g) : IdentDistrib f g μ μ := { aemeasurable_fst := hf aemeasurable_snd := hf.congr heq map_eq := Measure.map_congr heq } lemma _root_.MeasureTheory.AEMeasurable.identDistrib_mk (hf : AEMeasurable f μ) : IdentDistrib f (hf.mk f) μ μ := IdentDistrib.of_ae_eq hf hf.ae_eq_mk lemma _root_.MeasureTheory.AEStronglyMeasurable.identDistrib_mk [TopologicalSpace γ] [PseudoMetrizableSpace γ] [BorelSpace γ] (hf : AEStronglyMeasurable f μ) : IdentDistrib f (hf.mk f) μ μ := IdentDistrib.of_ae_eq hf.aemeasurable hf.ae_eq_mk theorem measure_mem_eq (h : IdentDistrib f g μ ν) {s : Set γ} (hs : MeasurableSet s) : μ (f ⁻¹' s) = ν (g ⁻¹' s) := by rw [← Measure.map_apply_of_aemeasurable h.aemeasurable_fst hs, ← Measure.map_apply_of_aemeasurable h.aemeasurable_snd hs, h.map_eq] alias measure_preimage_eq := measure_mem_eq theorem ae_snd (h : IdentDistrib f g μ ν) {p : γ → Prop} (pmeas : MeasurableSet {x | p x}) (hp : ∀ᵐ x ∂μ, p (f x)) : ∀ᵐ x ∂ν, p (g x) := by apply (ae_map_iff h.aemeasurable_snd pmeas).1 rw [← h.map_eq] exact (ae_map_iff h.aemeasurable_fst pmeas).2 hp theorem ae_mem_snd (h : IdentDistrib f g μ ν) {t : Set γ} (tmeas : MeasurableSet t) (ht : ∀ᵐ x ∂μ, f x ∈ t) : ∀ᵐ x ∂ν, g x ∈ t := h.ae_snd tmeas ht /-- In a second countable topology, the first function in an identically distributed pair is a.e. strongly measurable. So is the second function, but use `h.symm.aestronglyMeasurable_fst` as `h.aestronglyMeasurable_snd` has a different meaning. -/ theorem aestronglyMeasurable_fst [TopologicalSpace γ] [MetrizableSpace γ] [OpensMeasurableSpace γ] [SecondCountableTopology γ] (h : IdentDistrib f g μ ν) : AEStronglyMeasurable f μ := h.aemeasurable_fst.aestronglyMeasurable /-- If `f` and `g` are identically distributed and `f` is a.e. strongly measurable, so is `g`. -/ theorem aestronglyMeasurable_snd [TopologicalSpace γ] [MetrizableSpace γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable g ν := by refine aestronglyMeasurable_iff_aemeasurable_separable.2 ⟨h.aemeasurable_snd, ?_⟩ rcases (aestronglyMeasurable_iff_aemeasurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩ refine ⟨closure t, t_sep.closure, ?_⟩ apply h.ae_mem_snd isClosed_closure.measurableSet filter_upwards [ht] with x hx using subset_closure hx theorem aestronglyMeasurable_iff [TopologicalSpace γ] [MetrizableSpace γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : AEStronglyMeasurable f μ ↔ AEStronglyMeasurable g ν := ⟨fun hf => h.aestronglyMeasurable_snd hf, fun hg => h.symm.aestronglyMeasurable_snd hg⟩ theorem essSup_eq [ConditionallyCompleteLinearOrder γ] [TopologicalSpace γ] [OpensMeasurableSpace γ] [OrderClosedTopology γ] (h : IdentDistrib f g μ ν) : essSup f μ = essSup g ν := by have I : ∀ a, μ {x : α | a < f x} = ν {x : β | a < g x} := fun a => h.measure_mem_eq measurableSet_Ioi simp_rw [essSup_eq_sInf, I] theorem lintegral_eq {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (h : IdentDistrib f g μ ν) : ∫⁻ x, f x ∂μ = ∫⁻ x, g x ∂ν := by change ∫⁻ x, id (f x) ∂μ = ∫⁻ x, id (g x) ∂ν rw [← lintegral_map' aemeasurable_id h.aemeasurable_fst, ← lintegral_map' aemeasurable_id h.aemeasurable_snd, h.map_eq] theorem integral_eq [NormedAddCommGroup γ] [NormedSpace ℝ γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : ∫ x, f x ∂μ = ∫ x, g x ∂ν := by by_cases hf : AEStronglyMeasurable f μ · have A : AEStronglyMeasurable id (Measure.map f μ) := by rw [aestronglyMeasurable_iff_aemeasurable_separable] rcases (aestronglyMeasurable_iff_aemeasurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩ refine ⟨aemeasurable_id, ⟨closure t, t_sep.closure, ?_⟩⟩ rw [ae_map_iff h.aemeasurable_fst] · filter_upwards [ht] with x hx using subset_closure hx · exact isClosed_closure.measurableSet change ∫ x, id (f x) ∂μ = ∫ x, id (g x) ∂ν rw [← integral_map h.aemeasurable_fst A] rw [h.map_eq] at A rw [← integral_map h.aemeasurable_snd A, h.map_eq] · rw [integral_non_aestronglyMeasurable hf] rw [h.aestronglyMeasurable_iff] at hf rw [integral_non_aestronglyMeasurable hf] theorem eLpNorm_eq [NormedAddCommGroup γ] [OpensMeasurableSpace γ] (h : IdentDistrib f g μ ν) (p : ℝ≥0∞) : eLpNorm f p μ = eLpNorm g p ν := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp only [h_top, eLpNorm, eLpNormEssSup, ENNReal.top_ne_zero, eq_self_iff_true, if_true, if_false] apply essSup_eq exact h.comp (measurable_coe_nnreal_ennreal.comp measurable_nnnorm) simp only [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', one_div] congr 1 apply lintegral_eq exact h.comp (Measurable.pow_const (measurable_coe_nnreal_ennreal.comp measurable_nnnorm) p.toReal) @[deprecated (since := "2024-07-27")] alias snorm_eq := eLpNorm_eq theorem memℒp_snd [NormedAddCommGroup γ] [BorelSpace γ] {p : ℝ≥0∞} (h : IdentDistrib f g μ ν) (hf : Memℒp f p μ) : Memℒp g p ν := by refine ⟨h.aestronglyMeasurable_snd hf.aestronglyMeasurable, ?_⟩ rw [← h.eLpNorm_eq] exact hf.2 theorem memℒp_iff [NormedAddCommGroup γ] [BorelSpace γ] {p : ℝ≥0∞} (h : IdentDistrib f g μ ν) : Memℒp f p μ ↔ Memℒp g p ν := ⟨fun hf => h.memℒp_snd hf, fun hg => h.symm.memℒp_snd hg⟩ theorem integrable_snd [NormedAddCommGroup γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) (hf : Integrable f μ) : Integrable g ν := by rw [← memℒp_one_iff_integrable] at hf ⊢ exact h.memℒp_snd hf theorem integrable_iff [NormedAddCommGroup γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : Integrable f μ ↔ Integrable g ν := ⟨fun hf => h.integrable_snd hf, fun hg => h.symm.integrable_snd hg⟩ protected theorem norm [NormedAddCommGroup γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : IdentDistrib (fun x => ‖f x‖) (fun x => ‖g x‖) μ ν := h.comp measurable_norm protected theorem nnnorm [NormedAddCommGroup γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : IdentDistrib (fun x => ‖f x‖₊) (fun x => ‖g x‖₊) μ ν := h.comp measurable_nnnorm protected theorem pow [Pow γ ℕ] [MeasurablePow γ ℕ] (h : IdentDistrib f g μ ν) {n : ℕ} : IdentDistrib (fun x => f x ^ n) (fun x => g x ^ n) μ ν := h.comp (measurable_id.pow_const n) protected theorem sq [Pow γ ℕ] [MeasurablePow γ ℕ] (h : IdentDistrib f g μ ν) : IdentDistrib (fun x => f x ^ 2) (fun x => g x ^ 2) μ ν := h.comp (measurable_id.pow_const 2) protected theorem coe_nnreal_ennreal {f : α → ℝ≥0} {g : β → ℝ≥0} (h : IdentDistrib f g μ ν) : IdentDistrib (fun x => (f x : ℝ≥0∞)) (fun x => (g x : ℝ≥0∞)) μ ν := h.comp measurable_coe_nnreal_ennreal @[to_additive] theorem mul_const [Mul γ] [MeasurableMul γ] (h : IdentDistrib f g μ ν) (c : γ) : IdentDistrib (fun x => f x * c) (fun x => g x * c) μ ν := h.comp (measurable_mul_const c) @[to_additive] theorem const_mul [Mul γ] [MeasurableMul γ] (h : IdentDistrib f g μ ν) (c : γ) : IdentDistrib (fun x => c * f x) (fun x => c * g x) μ ν := h.comp (measurable_const_mul c) @[to_additive] theorem div_const [Div γ] [MeasurableDiv γ] (h : IdentDistrib f g μ ν) (c : γ) : IdentDistrib (fun x => f x / c) (fun x => g x / c) μ ν := h.comp (MeasurableDiv.measurable_div_const c) @[to_additive] theorem const_div [Div γ] [MeasurableDiv γ] (h : IdentDistrib f g μ ν) (c : γ) : IdentDistrib (fun x => c / f x) (fun x => c / g x) μ ν := h.comp (MeasurableDiv.measurable_const_div c) @[to_additive] lemma inv [Inv γ] [MeasurableInv γ] (h : IdentDistrib f g μ ν) : IdentDistrib f⁻¹ g⁻¹ μ ν := h.comp measurable_inv theorem evariance_eq {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) : evariance f μ = evariance g ν := by convert (h.sub_const (∫ x, f x ∂μ)).nnnorm.coe_nnreal_ennreal.sq.lintegral_eq rw [h.integral_eq] rfl theorem variance_eq {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) : variance f μ = variance g ν := by rw [variance, h.evariance_eq]; rfl end IdentDistrib section UniformIntegrable open TopologicalSpace variable {E : Type*} [MeasurableSpace E] [NormedAddCommGroup E] [BorelSpace E] {μ : Measure α} [IsFiniteMeasure μ] /-- This lemma is superseded by `Memℒp.uniformIntegrable_of_identDistrib` which only requires `AEStronglyMeasurable`. -/ theorem Memℒp.uniformIntegrable_of_identDistrib_aux {ι : Type*} {f : ι → α → E} {j : ι} {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (hℒp : Memℒp (f j) p μ) (hfmeas : ∀ i, StronglyMeasurable (f i)) (hf : ∀ i, IdentDistrib (f i) (f j) μ μ) : UniformIntegrable f p μ := by refine uniformIntegrable_of' hp hp' hfmeas fun ε hε => ?_ by_cases hι : Nonempty ι swap; · exact ⟨0, fun i => False.elim (hι <| Nonempty.intro i)⟩ obtain ⟨C, hC₁, hC₂⟩ := hℒp.eLpNorm_indicator_norm_ge_pos_le (hfmeas _) hε refine ⟨⟨C, hC₁.le⟩, fun i => le_trans (le_of_eq ?_) hC₂⟩ have : {x | (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖f i x‖₊} = {x | C ≤ ‖f i x‖} := by ext x simp_rw [← norm_toNNReal] exact Real.le_toNNReal_iff_coe_le (norm_nonneg _) rw [this, ← eLpNorm_norm, ← eLpNorm_norm (Set.indicator _ _)] simp_rw [norm_indicator_eq_indicator_norm, coe_nnnorm] let F : E → ℝ := (fun x : E => if (⟨C, hC₁.le⟩ : ℝ≥0) ≤ ‖x‖₊ then ‖x‖ else 0) have F_meas : Measurable F := by apply measurable_norm.indicator (measurableSet_le measurable_const measurable_nnnorm) have : ∀ k, (fun x ↦ Set.indicator {x | C ≤ ‖f k x‖} (fun a ↦ ‖f k a‖) x) = F ∘ f k := by intro k ext x simp only [Set.indicator, Set.mem_setOf_eq]; norm_cast rw [this, this, ← eLpNorm_map_measure F_meas.aestronglyMeasurable (hf i).aemeasurable_fst, (hf i).map_eq, eLpNorm_map_measure F_meas.aestronglyMeasurable (hf j).aemeasurable_fst] /-- A sequence of identically distributed Lᵖ functions is p-uniformly integrable. -/ theorem Memℒp.uniformIntegrable_of_identDistrib {ι : Type*} {f : ι → α → E} {j : ι} {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (hℒp : Memℒp (f j) p μ) (hf : ∀ i, IdentDistrib (f i) (f j) μ μ) : UniformIntegrable f p μ := by have hfmeas : ∀ i, AEStronglyMeasurable (f i) μ := fun i => (hf i).aestronglyMeasurable_iff.2 hℒp.1 set g : ι → α → E := fun i => (hfmeas i).choose have hgmeas : ∀ i, StronglyMeasurable (g i) := fun i => (Exists.choose_spec <| hfmeas i).1 have hgeq : ∀ i, g i =ᵐ[μ] f i := fun i => (Exists.choose_spec <| hfmeas i).2.symm have hgℒp : Memℒp (g j) p μ := hℒp.ae_eq (hgeq j).symm exact UniformIntegrable.ae_eq (Memℒp.uniformIntegrable_of_identDistrib_aux hp hp' hgℒp hgmeas fun i => (IdentDistrib.of_ae_eq (hgmeas i).aemeasurable (hgeq i)).trans ((hf i).trans <| IdentDistrib.of_ae_eq (hfmeas j).aemeasurable (hgeq j).symm)) hgeq end UniformIntegrable /-- If `X` and `Y` are independent and `(X, Y)` and `(X', Y')` are identically distributed, then `X'` and `Y'` are independent. -/ lemma indepFun_of_identDistrib_pair {μ : Measure γ} {μ' : Measure δ} [IsFiniteMeasure μ] [IsFiniteMeasure μ'] {X : γ → α} {X' : δ → α} {Y : γ → β} {Y' : δ → β} (h_indep : IndepFun X Y μ) (h_ident : IdentDistrib (fun ω ↦ (X ω, Y ω)) (fun ω ↦ (X' ω, Y' ω)) μ μ') : IndepFun X' Y' μ' := by rw [indepFun_iff_map_prod_eq_prod_map_map _ _, ← h_ident.map_eq, (indepFun_iff_map_prod_eq_prod_map_map _ _).1 h_indep] · exact congr (congrArg Measure.prod <| (h_ident.comp measurable_fst).map_eq) (h_ident.comp measurable_snd).map_eq · exact measurable_fst.aemeasurable.comp_aemeasurable h_ident.aemeasurable_fst · exact measurable_snd.aemeasurable.comp_aemeasurable h_ident.aemeasurable_fst · exact measurable_fst.aemeasurable.comp_aemeasurable h_ident.aemeasurable_snd · exact measurable_snd.aemeasurable.comp_aemeasurable h_ident.aemeasurable_snd end ProbabilityTheory
Probability\Integration.lean
/- Copyright (c) 2021 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Zinkevich, Vincent Beffara -/ import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.Probability.Independence.Basic /-! # Integration in Probability Theory Integration results for independent random variables. Specifically, for two independent random variables X and Y over the extended non-negative reals, `E[X * Y] = E[X] * E[Y]`, and similar results. ## Implementation notes Many lemmas in this file take two arguments of the same typeclass. It is worth remembering that lean will always pick the later typeclass in this situation, and does not care whether the arguments are `[]`, `{}`, or `()`. All of these use the `MeasurableSpace` `M2` to define `μ`: ```lean example {M1 : MeasurableSpace Ω} [M2 : MeasurableSpace Ω] {μ : Measure Ω} : sorry := sorry example [M1 : MeasurableSpace Ω] {M2 : MeasurableSpace Ω} {μ : Measure Ω} : sorry := sorry ``` -/ noncomputable section open Set MeasureTheory open scoped ENNReal MeasureTheory variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f g : Ω → ℝ≥0∞} {X Y : Ω → ℝ} namespace ProbabilityTheory /-- If a random variable `f` in `ℝ≥0∞` is independent of an event `T`, then if you restrict the random variable to `T`, then `E[f * indicator T c 0]=E[f] * E[indicator T c 0]`. It is useful for `lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace`. -/ theorem lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator {Mf mΩ : MeasurableSpace Ω} {μ : Measure Ω} (hMf : Mf ≤ mΩ) (c : ℝ≥0∞) {T : Set Ω} (h_meas_T : MeasurableSet T) (h_ind : IndepSets {s | MeasurableSet[Mf] s} {T} μ) (h_meas_f : Measurable[Mf] f) : (∫⁻ ω, f ω * T.indicator (fun _ => c) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, T.indicator (fun _ => c) ω ∂μ := by revert f have h_mul_indicator : ∀ g, Measurable g → Measurable fun a => g a * T.indicator (fun _ => c) a := fun g h_mg => h_mg.mul (measurable_const.indicator h_meas_T) apply @Measurable.ennreal_induction _ Mf · intro c' s' h_meas_s' simp_rw [← inter_indicator_mul] rw [lintegral_indicator _ (MeasurableSet.inter (hMf _ h_meas_s') h_meas_T), lintegral_indicator _ (hMf _ h_meas_s'), lintegral_indicator _ h_meas_T] simp only [measurable_const, lintegral_const, univ_inter, lintegral_const_mul, MeasurableSet.univ, Measure.restrict_apply] rw [IndepSets_iff] at h_ind rw [mul_mul_mul_comm, h_ind s' T h_meas_s' (Set.mem_singleton _)] · intro f' g _ h_meas_f' _ h_ind_f' h_ind_g have h_measM_f' : Measurable f' := h_meas_f'.mono hMf le_rfl simp_rw [Pi.add_apply, right_distrib] rw [lintegral_add_left (h_mul_indicator _ h_measM_f'), lintegral_add_left h_measM_f', right_distrib, h_ind_f', h_ind_g] · intro f h_meas_f h_mono_f h_ind_f have h_measM_f : ∀ n, Measurable (f n) := fun n => (h_meas_f n).mono hMf le_rfl simp_rw [ENNReal.iSup_mul] rw [lintegral_iSup h_measM_f h_mono_f, lintegral_iSup, ENNReal.iSup_mul] · simp_rw [← h_ind_f] · exact fun n => h_mul_indicator _ (h_measM_f n) · exact fun m n h_le a => mul_le_mul_right' (h_mono_f h_le a) _ /-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`, then `E[f * g] = E[f] * E[g]`. However, instead of directly using the independence of the random variables, it uses the independence of measurable spaces for the domains of `f` and `g`. This is similar to the sigma-algebra approach to independence. See `lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun` for a more common variant of the product of independent variables. -/ theorem lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace {Mf Mg mΩ : MeasurableSpace Ω} {μ : Measure Ω} (hMf : Mf ≤ mΩ) (hMg : Mg ≤ mΩ) (h_ind : Indep Mf Mg μ) (h_meas_f : Measurable[Mf] f) (h_meas_g : Measurable[Mg] g) : ∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by revert g have h_measM_f : Measurable f := h_meas_f.mono hMf le_rfl apply @Measurable.ennreal_induction _ Mg · intro c s h_s apply lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator hMf _ (hMg _ h_s) _ h_meas_f apply indepSets_of_indepSets_of_le_right h_ind rwa [singleton_subset_iff] · intro f' g _ h_measMg_f' _ h_ind_f' h_ind_g' have h_measM_f' : Measurable f' := h_measMg_f'.mono hMg le_rfl simp_rw [Pi.add_apply, left_distrib] rw [lintegral_add_left h_measM_f', lintegral_add_left (h_measM_f.mul h_measM_f'), left_distrib, h_ind_f', h_ind_g'] · intro f' h_meas_f' h_mono_f' h_ind_f' have h_measM_f' : ∀ n, Measurable (f' n) := fun n => (h_meas_f' n).mono hMg le_rfl simp_rw [ENNReal.mul_iSup] rw [lintegral_iSup, lintegral_iSup h_measM_f' h_mono_f', ENNReal.mul_iSup] · simp_rw [← h_ind_f'] · exact fun n => h_measM_f.mul (h_measM_f' n) · exact fun n m (h_le : n ≤ m) a => mul_le_mul_left' (h_mono_f' h_le a) _ /-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`, then `E[f * g] = E[f] * E[g]`. -/ theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun (h_meas_f : Measurable f) (h_meas_g : Measurable g) (h_indep_fun : IndepFun f g μ) : (∫⁻ ω, (f * g) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace (measurable_iff_comap_le.1 h_meas_f) (measurable_iff_comap_le.1 h_meas_g) h_indep_fun (Measurable.of_comap_le le_rfl) (Measurable.of_comap_le le_rfl) /-- If `f` and `g` with values in `ℝ≥0∞` are independent and almost everywhere measurable, then `E[f * g] = E[f] * E[g]` (slightly generalizing `lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun`). -/ theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' (h_meas_f : AEMeasurable f μ) (h_meas_g : AEMeasurable g μ) (h_indep_fun : IndepFun f g μ) : (∫⁻ ω, (f * g) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by have fg_ae : f * g =ᵐ[μ] h_meas_f.mk _ * h_meas_g.mk _ := h_meas_f.ae_eq_mk.mul h_meas_g.ae_eq_mk rw [lintegral_congr_ae h_meas_f.ae_eq_mk, lintegral_congr_ae h_meas_g.ae_eq_mk, lintegral_congr_ae fg_ae] apply lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun h_meas_f.measurable_mk h_meas_g.measurable_mk exact h_indep_fun.ae_eq h_meas_f.ae_eq_mk h_meas_g.ae_eq_mk theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' (h_meas_f : AEMeasurable f μ) (h_meas_g : AEMeasurable g μ) (h_indep_fun : IndepFun f g μ) : ∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' h_meas_f h_meas_g h_indep_fun /-- The product of two independent, integrable, real-valued random variables is integrable. -/ theorem IndepFun.integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β} [NormedDivisionRing β] [BorelSpace β] (hXY : IndepFun X Y μ) (hX : Integrable X μ) (hY : Integrable Y μ) : Integrable (X * Y) μ := by let nX : Ω → ENNReal := fun a => ‖X a‖₊ let nY : Ω → ENNReal := fun a => ‖Y a‖₊ have hXY' : IndepFun (fun a => ‖X a‖₊) (fun a => ‖Y a‖₊) μ := hXY.comp measurable_nnnorm measurable_nnnorm have hXY'' : IndepFun nX nY μ := hXY'.comp measurable_coe_nnreal_ennreal measurable_coe_nnreal_ennreal have hnX : AEMeasurable nX μ := hX.1.aemeasurable.nnnorm.coe_nnreal_ennreal have hnY : AEMeasurable nY μ := hY.1.aemeasurable.nnnorm.coe_nnreal_ennreal have hmul : ∫⁻ a, nX a * nY a ∂μ = (∫⁻ a, nX a ∂μ) * ∫⁻ a, nY a ∂μ := lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' hnX hnY hXY'' refine ⟨hX.1.mul hY.1, ?_⟩ simp_rw [HasFiniteIntegral, Pi.mul_apply, nnnorm_mul, ENNReal.coe_mul, hmul] exact ENNReal.mul_lt_top hX.2.ne hY.2.ne /-- If the product of two independent real-valued random variables is integrable and the second one is not almost everywhere zero, then the first one is integrable. -/ theorem IndepFun.integrable_left_of_integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β} [NormedDivisionRing β] [BorelSpace β] (hXY : IndepFun X Y μ) (h'XY : Integrable (X * Y) μ) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) (h'Y : ¬Y =ᵐ[μ] 0) : Integrable X μ := by refine ⟨hX, ?_⟩ have I : (∫⁻ ω, ‖Y ω‖₊ ∂μ) ≠ 0 := fun H ↦ by have I : (fun ω => ‖Y ω‖₊ : Ω → ℝ≥0∞) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' hY.ennnorm).1 H apply h'Y filter_upwards [I] with ω hω simpa using hω refine lt_top_iff_ne_top.2 fun H => ?_ have J : IndepFun (fun ω => ‖X ω‖₊ : Ω → ℝ≥0∞) (fun ω => ‖Y ω‖₊ : Ω → ℝ≥0∞) μ := by have M : Measurable fun x : β => (‖x‖₊ : ℝ≥0∞) := measurable_nnnorm.coe_nnreal_ennreal apply IndepFun.comp hXY M M have A : (∫⁻ ω, ‖X ω * Y ω‖₊ ∂μ) < ∞ := h'XY.2 simp only [nnnorm_mul, ENNReal.coe_mul] at A rw [lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' hX.ennnorm hY.ennnorm J, H] at A simp only [ENNReal.top_mul I, lt_self_iff_false] at A /-- If the product of two independent real-valued random variables is integrable and the first one is not almost everywhere zero, then the second one is integrable. -/ theorem IndepFun.integrable_right_of_integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β} [NormedDivisionRing β] [BorelSpace β] (hXY : IndepFun X Y μ) (h'XY : Integrable (X * Y) μ) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) (h'X : ¬X =ᵐ[μ] 0) : Integrable Y μ := by refine ⟨hY, ?_⟩ have I : (∫⁻ ω, ‖X ω‖₊ ∂μ) ≠ 0 := fun H ↦ by have I : (fun ω => ‖X ω‖₊ : Ω → ℝ≥0∞) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' hX.ennnorm).1 H apply h'X filter_upwards [I] with ω hω simpa using hω refine lt_top_iff_ne_top.2 fun H => ?_ have J : IndepFun (fun ω => ‖X ω‖₊ : Ω → ℝ≥0∞) (fun ω => ‖Y ω‖₊ : Ω → ℝ≥0∞) μ := by have M : Measurable fun x : β => (‖x‖₊ : ℝ≥0∞) := measurable_nnnorm.coe_nnreal_ennreal apply IndepFun.comp hXY M M have A : (∫⁻ ω, ‖X ω * Y ω‖₊ ∂μ) < ∞ := h'XY.2 simp only [nnnorm_mul, ENNReal.coe_mul] at A rw [lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' hX.ennnorm hY.ennnorm J, H] at A simp only [ENNReal.mul_top I, lt_self_iff_false] at A /-- The (Bochner) integral of the product of two independent, nonnegative random variables is the product of their integrals. The proof is just plumbing around `lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'`. -/ theorem IndepFun.integral_mul_of_nonneg (hXY : IndepFun X Y μ) (hXp : 0 ≤ X) (hYp : 0 ≤ Y) (hXm : AEMeasurable X μ) (hYm : AEMeasurable Y μ) : integral μ (X * Y) = integral μ X * integral μ Y := by have h1 : AEMeasurable (fun a => ENNReal.ofReal (X a)) μ := ENNReal.measurable_ofReal.comp_aemeasurable hXm have h2 : AEMeasurable (fun a => ENNReal.ofReal (Y a)) μ := ENNReal.measurable_ofReal.comp_aemeasurable hYm have h3 : AEMeasurable (X * Y) μ := hXm.mul hYm have h4 : 0 ≤ᵐ[μ] X * Y := ae_of_all _ fun ω => mul_nonneg (hXp ω) (hYp ω) rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ hXp) hXm.aestronglyMeasurable, integral_eq_lintegral_of_nonneg_ae (ae_of_all _ hYp) hYm.aestronglyMeasurable, integral_eq_lintegral_of_nonneg_ae h4 h3.aestronglyMeasurable] simp_rw [← ENNReal.toReal_mul, Pi.mul_apply, ENNReal.ofReal_mul (hXp _)] congr apply lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' h1 h2 exact hXY.comp ENNReal.measurable_ofReal ENNReal.measurable_ofReal /-- The (Bochner) integral of the product of two independent, integrable random variables is the product of their integrals. The proof is pedestrian decomposition into their positive and negative parts in order to apply `IndepFun.integral_mul_of_nonneg` four times. -/ theorem IndepFun.integral_mul_of_integrable (hXY : IndepFun X Y μ) (hX : Integrable X μ) (hY : Integrable Y μ) : integral μ (X * Y) = integral μ X * integral μ Y := by let pos : ℝ → ℝ := fun x => max x 0 let neg : ℝ → ℝ := fun x => max (-x) 0 have posm : Measurable pos := measurable_id'.max measurable_const have negm : Measurable neg := measurable_id'.neg.max measurable_const let Xp := pos ∘ X -- `X⁺` would look better but it makes `simp_rw` below fail let Xm := neg ∘ X let Yp := pos ∘ Y let Ym := neg ∘ Y have hXpm : X = Xp - Xm := funext fun ω => (max_zero_sub_max_neg_zero_eq_self (X ω)).symm have hYpm : Y = Yp - Ym := funext fun ω => (max_zero_sub_max_neg_zero_eq_self (Y ω)).symm have hp1 : 0 ≤ Xm := fun ω => le_max_right _ _ have hp2 : 0 ≤ Xp := fun ω => le_max_right _ _ have hp3 : 0 ≤ Ym := fun ω => le_max_right _ _ have hp4 : 0 ≤ Yp := fun ω => le_max_right _ _ have hm1 : AEMeasurable Xm μ := hX.1.aemeasurable.neg.max aemeasurable_const have hm2 : AEMeasurable Xp μ := hX.1.aemeasurable.max aemeasurable_const have hm3 : AEMeasurable Ym μ := hY.1.aemeasurable.neg.max aemeasurable_const have hm4 : AEMeasurable Yp μ := hY.1.aemeasurable.max aemeasurable_const have hv1 : Integrable Xm μ := hX.neg_part have hv2 : Integrable Xp μ := hX.pos_part have hv3 : Integrable Ym μ := hY.neg_part have hv4 : Integrable Yp μ := hY.pos_part have hi1 : IndepFun Xm Ym μ := hXY.comp negm negm have hi2 : IndepFun Xp Ym μ := hXY.comp posm negm have hi3 : IndepFun Xm Yp μ := hXY.comp negm posm have hi4 : IndepFun Xp Yp μ := hXY.comp posm posm have hl1 : Integrable (Xm * Ym) μ := hi1.integrable_mul hv1 hv3 have hl2 : Integrable (Xp * Ym) μ := hi2.integrable_mul hv2 hv3 have hl3 : Integrable (Xm * Yp) μ := hi3.integrable_mul hv1 hv4 have hl4 : Integrable (Xp * Yp) μ := hi4.integrable_mul hv2 hv4 have hl5 : Integrable (Xp * Yp - Xm * Yp) μ := hl4.sub hl3 have hl6 : Integrable (Xp * Ym - Xm * Ym) μ := hl2.sub hl1 rw [hXpm, hYpm, mul_sub, sub_mul, sub_mul] rw [integral_sub' hl5 hl6, integral_sub' hl4 hl3, integral_sub' hl2 hl1, integral_sub' hv2 hv1, integral_sub' hv4 hv3, hi1.integral_mul_of_nonneg hp1 hp3 hm1 hm3, hi2.integral_mul_of_nonneg hp2 hp3 hm2 hm3, hi3.integral_mul_of_nonneg hp1 hp4 hm1 hm4, hi4.integral_mul_of_nonneg hp2 hp4 hm2 hm4] ring /-- The (Bochner) integral of the product of two independent random variables is the product of their integrals. -/ theorem IndepFun.integral_mul (hXY : IndepFun X Y μ) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) : integral μ (X * Y) = integral μ X * integral μ Y := by by_cases h'X : X =ᵐ[μ] 0 · have h' : X * Y =ᵐ[μ] 0 := by filter_upwards [h'X] with ω hω simp [hω] simp only [integral_congr_ae h'X, integral_congr_ae h', Pi.zero_apply, integral_const, Algebra.id.smul_eq_mul, mul_zero, zero_mul] by_cases h'Y : Y =ᵐ[μ] 0 · have h' : X * Y =ᵐ[μ] 0 := by filter_upwards [h'Y] with ω hω simp [hω] simp only [integral_congr_ae h'Y, integral_congr_ae h', Pi.zero_apply, integral_const, Algebra.id.smul_eq_mul, mul_zero, zero_mul] by_cases h : Integrable (X * Y) μ · have HX : Integrable X μ := hXY.integrable_left_of_integrable_mul h hX hY h'Y have HY : Integrable Y μ := hXY.integrable_right_of_integrable_mul h hX hY h'X exact hXY.integral_mul_of_integrable HX HY · rw [integral_undef h] have I : ¬(Integrable X μ ∧ Integrable Y μ) := by rintro ⟨HX, HY⟩ exact h (hXY.integrable_mul HX HY) rw [not_and_or] at I cases' I with I I <;> simp [integral_undef I] theorem IndepFun.integral_mul' (hXY : IndepFun X Y μ) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) : (integral μ fun ω => X ω * Y ω) = integral μ X * integral μ Y := hXY.integral_mul hX hY /-- Independence of functions `f` and `g` into arbitrary types is characterized by the relation `E[(φ ∘ f) * (ψ ∘ g)] = E[φ ∘ f] * E[ψ ∘ g]` for all measurable `φ` and `ψ` with values in `ℝ` satisfying appropriate integrability conditions. -/ theorem indepFun_iff_integral_comp_mul [IsFiniteMeasure μ] {β β' : Type*} {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} {f : Ω → β} {g : Ω → β'} {hfm : Measurable f} {hgm : Measurable g} : IndepFun f g μ ↔ ∀ {φ : β → ℝ} {ψ : β' → ℝ}, Measurable φ → Measurable ψ → Integrable (φ ∘ f) μ → Integrable (ψ ∘ g) μ → integral μ (φ ∘ f * ψ ∘ g) = integral μ (φ ∘ f) * integral μ (ψ ∘ g) := by refine ⟨fun hfg _ _ hφ hψ => IndepFun.integral_mul_of_integrable (hfg.comp hφ hψ), ?_⟩ rw [IndepFun_iff] rintro h _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩ specialize h (measurable_one.indicator hA) (measurable_one.indicator hB) ((integrable_const 1).indicator (hfm.comp measurable_id hA)) ((integrable_const 1).indicator (hgm.comp measurable_id hB)) rwa [← ENNReal.toReal_eq_toReal (measure_ne_top μ _), ENNReal.toReal_mul, ← integral_indicator_one ((hfm hA).inter (hgm hB)), ← integral_indicator_one (hfm hA), ← integral_indicator_one (hgm hB), Set.inter_indicator_one] exact ENNReal.mul_ne_top (measure_ne_top μ _) (measure_ne_top μ _) end ProbabilityTheory
Probability\Moments.lean
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Variance /-! # Moments and moment generating function ## Main definitions * `ProbabilityTheory.moment X p μ`: `p`th moment of a real random variable `X` with respect to measure `μ`, `μ[X^p]` * `ProbabilityTheory.centralMoment X p μ`:`p`th central moment of `X` with respect to measure `μ`, `μ[(X - μ[X])^p]` * `ProbabilityTheory.mgf X μ t`: moment generating function of `X` with respect to measure `μ`, `μ[exp(t*X)]` * `ProbabilityTheory.cgf X μ t`: cumulant generating function, logarithm of the moment generating function ## Main results * `ProbabilityTheory.IndepFun.mgf_add`: if two real random variables `X` and `Y` are independent and their mgfs are defined at `t`, then `mgf (X + Y) μ t = mgf X μ t * mgf Y μ t` * `ProbabilityTheory.IndepFun.cgf_add`: if two real random variables `X` and `Y` are independent and their cgfs are defined at `t`, then `cgf (X + Y) μ t = cgf X μ t + cgf Y μ t` * `ProbabilityTheory.measure_ge_le_exp_cgf` and `ProbabilityTheory.measure_le_le_exp_cgf`: Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that the cgf exists, `ℙ(ε ≤ X) ≤ exp(- t*ε + cgf X ℙ t)`. See also `ProbabilityTheory.measure_ge_le_exp_mul_mgf` and `ProbabilityTheory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead of `cgf`. -/ open MeasureTheory Filter Finset Real noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {p : ℕ} {μ : Measure Ω} /-- Moment of a real random variable, `μ[X ^ p]`. -/ def moment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := μ[X ^ p] /-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/ def centralMoment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := by have m := fun (x : Ω) => μ[X] -- Porting note: Lean deems `μ[(X - fun x => μ[X]) ^ p]` ambiguous exact μ[(X - m) ^ p] @[simp] theorem moment_zero (hp : p ≠ 0) : moment 0 p μ = 0 := by simp only [moment, hp, zero_pow, Ne, not_false_iff, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, integral_zero] @[simp] theorem centralMoment_zero (hp : p ≠ 0) : centralMoment 0 p μ = 0 := by simp only [centralMoment, hp, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, zero_sub, Pi.pow_apply, Pi.neg_apply, neg_zero, zero_pow, Ne, not_false_iff] theorem centralMoment_one' [IsFiniteMeasure μ] (h_int : Integrable X μ) : centralMoment X 1 μ = (1 - (μ Set.univ).toReal) * μ[X] := by simp only [centralMoment, Pi.sub_apply, pow_one] rw [integral_sub h_int (integrable_const _)] simp only [sub_mul, integral_const, smul_eq_mul, one_mul] @[simp] theorem centralMoment_one [IsProbabilityMeasure μ] : centralMoment X 1 μ = 0 := by by_cases h_int : Integrable X μ · rw [centralMoment_one' h_int] simp only [measure_univ, ENNReal.one_toReal, sub_self, zero_mul] · simp only [centralMoment, Pi.sub_apply, pow_one] have : ¬Integrable (fun x => X x - integral μ X) μ := by refine fun h_sub => h_int ?_ have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp rw [h_add] exact h_sub.add (integrable_const _) rw [integral_undef this] theorem centralMoment_two_eq_variance [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : centralMoment X 2 μ = variance X μ := by rw [hX.variance_eq]; rfl section MomentGeneratingFunction variable {t : ℝ} /-- Moment generating function of a real random variable `X`: `fun t => μ[exp(t*X)]`. -/ def mgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := μ[fun ω => exp (t * X ω)] /-- Cumulant generating function of a real random variable `X`: `fun t => log μ[exp(t*X)]`. -/ def cgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := log (mgf X μ t) @[simp] theorem mgf_zero_fun : mgf 0 μ t = (μ Set.univ).toReal := by simp only [mgf, Pi.zero_apply, mul_zero, exp_zero, integral_const, smul_eq_mul, mul_one] @[simp] theorem cgf_zero_fun : cgf 0 μ t = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero_fun] @[simp] theorem mgf_zero_measure : mgf X (0 : Measure Ω) t = 0 := by simp only [mgf, integral_zero_measure] @[simp] theorem cgf_zero_measure : cgf X (0 : Measure Ω) t = 0 := by simp only [cgf, log_zero, mgf_zero_measure] @[simp] theorem mgf_const' (c : ℝ) : mgf (fun _ => c) μ t = (μ Set.univ).toReal * exp (t * c) := by simp only [mgf, integral_const, smul_eq_mul] -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_const (c : ℝ) [IsProbabilityMeasure μ] : mgf (fun _ => c) μ t = exp (t * c) := by simp only [mgf_const', measure_univ, ENNReal.one_toReal, one_mul] @[simp] theorem cgf_const' [IsFiniteMeasure μ] (hμ : μ ≠ 0) (c : ℝ) : cgf (fun _ => c) μ t = log (μ Set.univ).toReal + t * c := by simp only [cgf, mgf_const'] rw [log_mul _ (exp_pos _).ne'] · rw [log_exp _] · rw [Ne, ENNReal.toReal_eq_zero_iff, Measure.measure_univ_eq_zero] simp only [hμ, measure_ne_top μ Set.univ, or_self_iff, not_false_iff] @[simp] theorem cgf_const [IsProbabilityMeasure μ] (c : ℝ) : cgf (fun _ => c) μ t = t * c := by simp only [cgf, mgf_const, log_exp] @[simp] theorem mgf_zero' : mgf X μ 0 = (μ Set.univ).toReal := by simp only [mgf, zero_mul, exp_zero, integral_const, smul_eq_mul, mul_one] -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_zero [IsProbabilityMeasure μ] : mgf X μ 0 = 1 := by simp only [mgf_zero', measure_univ, ENNReal.one_toReal] @[simp] theorem cgf_zero' : cgf X μ 0 = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero'] -- @[simp] -- Porting note: `simp only` already proves this theorem cgf_zero [IsProbabilityMeasure μ] : cgf X μ 0 = 0 := by simp only [cgf_zero', measure_univ, ENNReal.one_toReal, log_one] theorem mgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : mgf X μ t = 0 := by simp only [mgf, integral_undef hX] theorem cgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : cgf X μ t = 0 := by simp only [cgf, mgf_undef hX, log_zero] theorem mgf_nonneg : 0 ≤ mgf X μ t := by unfold mgf; positivity theorem mgf_pos' (hμ : μ ≠ 0) (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) : 0 < mgf X μ t := by simp_rw [mgf] have : ∫ x : Ω, exp (t * X x) ∂μ = ∫ x : Ω in Set.univ, exp (t * X x) ∂μ := by simp only [Measure.restrict_univ] rw [this, setIntegral_pos_iff_support_of_nonneg_ae _ _] · have h_eq_univ : (Function.support fun x : Ω => exp (t * X x)) = Set.univ := by ext1 x simp only [Function.mem_support, Set.mem_univ, iff_true_iff] exact (exp_pos _).ne' rw [h_eq_univ, Set.inter_univ _] refine Ne.bot_lt ?_ simp only [hμ, ENNReal.bot_eq_zero, Ne, Measure.measure_univ_eq_zero, not_false_iff] · filter_upwards with x rw [Pi.zero_apply] exact (exp_pos _).le · rwa [integrableOn_univ] theorem mgf_pos [IsProbabilityMeasure μ] (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) : 0 < mgf X μ t := mgf_pos' (IsProbabilityMeasure.ne_zero μ) h_int_X theorem mgf_neg : mgf (-X) μ t = mgf X μ (-t) := by simp_rw [mgf, Pi.neg_apply, mul_neg, neg_mul] theorem cgf_neg : cgf (-X) μ t = cgf X μ (-t) := by simp_rw [cgf, mgf_neg] /-- This is a trivial application of `IndepFun.comp` but it will come up frequently. -/ theorem IndepFun.exp_mul {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (s t : ℝ) : IndepFun (fun ω => exp (s * X ω)) (fun ω => exp (t * Y ω)) μ := by have h_meas : ∀ t, Measurable fun x => exp (t * x) := fun t => (measurable_id'.const_mul t).exp change IndepFun ((fun x => exp (s * x)) ∘ X) ((fun x => exp (t * x)) ∘ Y) μ exact IndepFun.comp h_indep (h_meas s) (h_meas t) theorem IndepFun.mgf_add {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (hX : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ) (hY : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ) : mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by simp_rw [mgf, Pi.add_apply, mul_add, exp_add] exact (h_indep.exp_mul t t).integral_mul hX hY theorem IndepFun.mgf_add' {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) : mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by have A : Continuous fun x : ℝ => exp (t * x) := by fun_prop have h'X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ := A.aestronglyMeasurable.comp_aemeasurable hX.aemeasurable have h'Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ := A.aestronglyMeasurable.comp_aemeasurable hY.aemeasurable exact h_indep.mgf_add h'X h'Y theorem IndepFun.cgf_add {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) (h_int_Y : Integrable (fun ω => exp (t * Y ω)) μ) : cgf (X + Y) μ t = cgf X μ t + cgf Y μ t := by by_cases hμ : μ = 0 · simp [hμ] simp only [cgf, h_indep.mgf_add h_int_X.aestronglyMeasurable h_int_Y.aestronglyMeasurable] exact log_mul (mgf_pos' hμ h_int_X).ne' (mgf_pos' hμ h_int_Y).ne' theorem aestronglyMeasurable_exp_mul_add {X Y : Ω → ℝ} (h_int_X : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ) (h_int_Y : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ) : AEStronglyMeasurable (fun ω => exp (t * (X + Y) ω)) μ := by simp_rw [Pi.add_apply, mul_add, exp_add] exact AEStronglyMeasurable.mul h_int_X h_int_Y theorem aestronglyMeasurable_exp_mul_sum {X : ι → Ω → ℝ} {s : Finset ι} (h_int : ∀ i ∈ s, AEStronglyMeasurable (fun ω => exp (t * X i ω)) μ) : AEStronglyMeasurable (fun ω => exp (t * (∑ i ∈ s, X i) ω)) μ := by classical induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int · simp only [Pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero] exact aestronglyMeasurable_const · have : ∀ i : ι, i ∈ s → AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi => h_int i (mem_insert_of_mem hi) specialize h_rec this rw [sum_insert hi_notin_s] apply aestronglyMeasurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec theorem IndepFun.integrable_exp_mul_add {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) (h_int_Y : Integrable (fun ω => exp (t * Y ω)) μ) : Integrable (fun ω => exp (t * (X + Y) ω)) μ := by simp_rw [Pi.add_apply, mul_add, exp_add] exact (h_indep.exp_mul t t).integrable_mul h_int_X h_int_Y theorem iIndepFun.integrable_exp_mul_sum [IsProbabilityMeasure μ] {X : ι → Ω → ℝ} (h_indep : iIndepFun (fun i => inferInstance) X μ) (h_meas : ∀ i, Measurable (X i)) {s : Finset ι} (h_int : ∀ i ∈ s, Integrable (fun ω => exp (t * X i ω)) μ) : Integrable (fun ω => exp (t * (∑ i ∈ s, X i) ω)) μ := by classical induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int · simp only [Pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero] exact integrable_const _ · have : ∀ i : ι, i ∈ s → Integrable (fun ω : Ω => exp (t * X i ω)) μ := fun i hi => h_int i (mem_insert_of_mem hi) specialize h_rec this rw [sum_insert hi_notin_s] refine IndepFun.integrable_exp_mul_add ?_ (h_int i (mem_insert_self _ _)) h_rec exact (h_indep.indepFun_finset_sum_of_not_mem h_meas hi_notin_s).symm theorem iIndepFun.mgf_sum [IsProbabilityMeasure μ] {X : ι → Ω → ℝ} (h_indep : iIndepFun (fun i => inferInstance) X μ) (h_meas : ∀ i, Measurable (X i)) (s : Finset ι) : mgf (∑ i ∈ s, X i) μ t = ∏ i ∈ s, mgf (X i) μ t := by classical induction' s using Finset.induction_on with i s hi_notin_s h_rec h_int · simp only [sum_empty, mgf_zero_fun, measure_univ, ENNReal.one_toReal, prod_empty] · have h_int' : ∀ i : ι, AEStronglyMeasurable (fun ω : Ω => exp (t * X i ω)) μ := fun i => ((h_meas i).const_mul t).exp.aestronglyMeasurable rw [sum_insert hi_notin_s, IndepFun.mgf_add (h_indep.indepFun_finset_sum_of_not_mem h_meas hi_notin_s).symm (h_int' i) (aestronglyMeasurable_exp_mul_sum fun i _ => h_int' i), h_rec, prod_insert hi_notin_s] theorem iIndepFun.cgf_sum [IsProbabilityMeasure μ] {X : ι → Ω → ℝ} (h_indep : iIndepFun (fun i => inferInstance) X μ) (h_meas : ∀ i, Measurable (X i)) {s : Finset ι} (h_int : ∀ i ∈ s, Integrable (fun ω => exp (t * X i ω)) μ) : cgf (∑ i ∈ s, X i) μ t = ∑ i ∈ s, cgf (X i) μ t := by simp_rw [cgf] rw [← log_prod _ _ fun j hj => ?_] · rw [h_indep.mgf_sum h_meas] · exact (mgf_pos (h_int j hj)).ne' /-- **Chernoff bound** on the upper tail of a real random variable. -/ theorem measure_ge_le_exp_mul_mgf [IsFiniteMeasure μ] (ε : ℝ) (ht : 0 ≤ t) (h_int : Integrable (fun ω => exp (t * X ω)) μ) : (μ {ω | ε ≤ X ω}).toReal ≤ exp (-t * ε) * mgf X μ t := by rcases ht.eq_or_lt with ht_zero_eq | ht_pos · rw [ht_zero_eq.symm] simp only [neg_zero, zero_mul, exp_zero, mgf_zero', one_mul] rw [ENNReal.toReal_le_toReal (measure_ne_top μ _) (measure_ne_top μ _)] exact measure_mono (Set.subset_univ _) calc (μ {ω | ε ≤ X ω}).toReal = (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).toReal := by congr with ω simp only [Set.mem_setOf_eq, exp_le_exp, gt_iff_lt] exact ⟨fun h => mul_le_mul_of_nonneg_left h ht_pos.le, fun h => le_of_mul_le_mul_left h ht_pos⟩ _ ≤ (exp (t * ε))⁻¹ * μ[fun ω => exp (t * X ω)] := by have : exp (t * ε) * (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).toReal ≤ μ[fun ω => exp (t * X ω)] := mul_meas_ge_le_integral_of_nonneg (ae_of_all _ fun x => (exp_pos _).le) h_int _ rwa [mul_comm (exp (t * ε))⁻¹, ← div_eq_mul_inv, le_div_iff' (exp_pos _)] _ = exp (-t * ε) * mgf X μ t := by rw [neg_mul, exp_neg]; rfl /-- **Chernoff bound** on the lower tail of a real random variable. -/ theorem measure_le_le_exp_mul_mgf [IsFiniteMeasure μ] (ε : ℝ) (ht : t ≤ 0) (h_int : Integrable (fun ω => exp (t * X ω)) μ) : (μ {ω | X ω ≤ ε}).toReal ≤ exp (-t * ε) * mgf X μ t := by rw [← neg_neg t, ← mgf_neg, neg_neg, ← neg_mul_neg (-t)] refine Eq.trans_le ?_ (measure_ge_le_exp_mul_mgf (-ε) (neg_nonneg.mpr ht) ?_) · congr with ω simp only [Pi.neg_apply, neg_le_neg_iff] · simp_rw [Pi.neg_apply, neg_mul_neg] exact h_int /-- **Chernoff bound** on the upper tail of a real random variable. -/ theorem measure_ge_le_exp_cgf [IsFiniteMeasure μ] (ε : ℝ) (ht : 0 ≤ t) (h_int : Integrable (fun ω => exp (t * X ω)) μ) : (μ {ω | ε ≤ X ω}).toReal ≤ exp (-t * ε + cgf X μ t) := by refine (measure_ge_le_exp_mul_mgf ε ht h_int).trans ?_ rw [exp_add] exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le /-- **Chernoff bound** on the lower tail of a real random variable. -/ theorem measure_le_le_exp_cgf [IsFiniteMeasure μ] (ε : ℝ) (ht : t ≤ 0) (h_int : Integrable (fun ω => exp (t * X ω)) μ) : (μ {ω | X ω ≤ ε}).toReal ≤ exp (-t * ε + cgf X μ t) := by refine (measure_le_le_exp_mul_mgf ε ht h_int).trans ?_ rw [exp_add] exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le end MomentGeneratingFunction end ProbabilityTheory
Probability\Notation.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.Function.ConditionalExpectation.Basic import Mathlib.MeasureTheory.Decomposition.Lebesgue /-! # Notations for probability theory This file defines the following notations, for functions `X,Y`, measures `P, Q` defined on a measurable space `m0`, and another measurable space structure `m` with `hm : m ≤ m0`, - `P[X] = ∫ a, X a ∂P` - `𝔼[X] = ∫ a, X a` - `𝔼[X|m]`: conditional expectation of `X` with respect to the measure `volume` and the measurable space `m`. The similar `P[X|m]` for a measure `P` is defined in `MeasureTheory.Function.ConditionalExpectation.Basic`. - `P⟦s|m⟧ = P[s.indicator (fun ω => (1 : ℝ)) | m]`, conditional probability of a set. - `X =ₐₛ Y`: `X =ᵐ[volume] Y` - `X ≤ₐₛ Y`: `X ≤ᵐ[volume] Y` - `∂P/∂Q = P.rnDeriv Q` We note that the notation `∂P/∂Q` applies to three different cases, namely, `MeasureTheory.Measure.rnDeriv`, `MeasureTheory.SignedMeasure.rnDeriv` and `MeasureTheory.ComplexMeasure.rnDeriv`. - `ℙ` is a notation for `volume` on a measured space. To use these notations, you need to use `open scoped ProbabilityTheory` or `open ProbabilityTheory`. -/ open MeasureTheory open scoped MeasureTheory -- We define notations `𝔼[f|m]` for the conditional expectation of `f` with respect to `m`. scoped[ProbabilityTheory] notation "𝔼[" X "|" m "]" => MeasureTheory.condexp m MeasureTheory.MeasureSpace.volume X -- Note(kmill): this notation tends to lead to ambiguity with GetElem notation. set_option quotPrecheck false in scoped[ProbabilityTheory] notation P "[" X "]" => ∫ x, ↑(X x) ∂P scoped[ProbabilityTheory] notation "𝔼[" X "]" => ∫ a, (X : _ → _) a scoped[ProbabilityTheory] notation P "⟦" s "|" m "⟧" => MeasureTheory.condexp m P (Set.indicator s fun ω => (1 : ℝ)) scoped[ProbabilityTheory] notation:50 X " =ₐₛ " Y:50 => X =ᵐ[MeasureTheory.MeasureSpace.volume] Y scoped[ProbabilityTheory] notation:50 X " ≤ₐₛ " Y:50 => X ≤ᵐ[MeasureTheory.MeasureSpace.volume] Y scoped[ProbabilityTheory] notation "∂" P "/∂" Q:100 => MeasureTheory.Measure.rnDeriv P Q scoped[ProbabilityTheory] notation "ℙ" => MeasureTheory.MeasureSpace.volume
Probability\StrongLaw.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.Probability.IdentDistrib import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.Analysis.SpecificLimits.FloorPow import Mathlib.Analysis.PSeries import Mathlib.Analysis.Asymptotics.SpecificAsymptotics /-! # The strong law of large numbers We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`: If `X n` is a sequence of independent identically distributed integrable random variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. This file also contains the Lᵖ version of the strong law of large numbers provided by `ProbabilityTheory.strong_law_Lp` which shows `∑ i ∈ range n, X i / n` converges in Lᵖ to `𝔼[X 0]` provided `X n` is independent identically distributed and is Lᵖ. ## Implementation The main point is to prove the result for real-valued random variables, as the general case of Banach-space valued random variables follows from this case and approximation by simple functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`. We follow the proof by Etemadi [Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law], which goes as follows. It suffices to prove the result for nonnegative `X`, as one can prove the general result by splitting a general `X` into its positive part and negative part. Consider `Xₙ` a sequence of nonnegative integrable identically distributed pairwise independent random variables. Let `Yₙ` be the truncation of `Xₙ` up to `n`. We claim that * Almost surely, `Xₙ = Yₙ` for all but finitely many indices. Indeed, `∑ ℙ (Xₙ ≠ Yₙ)` is bounded by `1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`). * Let `c > 1`. Along the sequence `n = c ^ k`, then `(∑_{i=0}^{n-1} Yᵢ - 𝔼[Yᵢ])/n` converges almost surely to `0`. This follows from a variance control, as ``` ∑_k ℙ (|∑_{i=0}^{c^k - 1} Yᵢ - 𝔼[Yᵢ]| > c^k ε) ≤ ∑_k (c^k ε)^{-2} ∑_{i=0}^{c^k - 1} Var[Yᵢ] (by Markov inequality) ≤ ∑_i (C/i^2) Var[Yᵢ] (as ∑_{c^k > i} 1/(c^k)^2 ≤ C/i^2) ≤ ∑_i (C/i^2) 𝔼[Yᵢ^2] ≤ 2C 𝔼[X^2] (see `sum_variance_truncation_le`) ``` * As `𝔼[Yᵢ]` converges to `𝔼[X]`, it follows from the two previous items and Cesàro that, along the sequence `n = c^k`, one has `(∑_{i=0}^{n-1} Xᵢ) / n → 𝔼[X]` almost surely. * To generalize it to all indices, we use the fact that `∑_{i=0}^{n-1} Xᵢ` is nondecreasing and that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small. -/ noncomputable section open MeasureTheory Filter Finset Asymptotics open Set (indicator) open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory /-! ### Prerequisites on truncations -/ section Truncation variable {α : Type*} /-- Truncating a real-valued function to the interval `(-A, A]`. -/ def truncation (f : α → ℝ) (A : ℝ) := indicator (Set.Ioc (-A) A) id ∘ f variable {m : MeasurableSpace α} {μ : Measure α} {f : α → ℝ} theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f μ) {A : ℝ} : AEStronglyMeasurable (truncation f A) μ := by apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable theorem abs_truncation_le_bound (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |A| := by simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs with h · exact abs_le_abs h.2 (neg_le.2 h.1.le) · simp [abs_nonneg] @[simp] theorem truncation_zero (f : α → ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl theorem abs_truncation_le_abs_self (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |f x| := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs · exact le_rfl · simp [abs_nonneg] theorem truncation_eq_self {f : α → ℝ} {A : ℝ} {x : α} (h : |f x| < A) : truncation f A x = f x := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff] intro H apply H.elim simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le] theorem truncation_eq_of_nonneg {f : α → ℝ} {A : ℝ} (h : ∀ x, 0 ≤ f x) : truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by ext x rcases (h x).lt_or_eq with (hx | hx) · simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply, true_and_iff] by_cases h'x : f x ≤ A · have : -A < f x := by linarith [h x] simp only [this, true_and_iff] · simp only [h'x, and_false_iff] · simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self] theorem truncation_nonneg {f : α → ℝ} (A : ℝ) {x : α} (h : 0 ≤ f x) : 0 ≤ truncation f A x := Set.indicator_apply_nonneg fun _ => h theorem _root_.MeasureTheory.AEStronglyMeasurable.memℒp_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} {p : ℝ≥0∞} : Memℒp (truncation f A) p μ := Memℒp.of_bound hf.truncation |A| (eventually_of_forall fun _ => abs_truncation_le_bound _ _ _) theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} : Integrable (truncation f A) μ := by rw [← memℒp_one_iff_integrable]; exact hf.memℒp_truncation theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) {n : ℕ} (hn : n ≠ 0) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in -A..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) ∂μ = _ rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · linarith · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} {n : ℕ} (hn : n ≠ 0) (h'f : 0 ≤ f) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in (0)..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc rw [truncation_eq_of_nonneg h'f] change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) ∂μ = _ rcases le_or_lt 0 A with (hA | hA) · rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable · rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le, ← integral_indicator M'] · simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero, zero_eq_neg] apply integral_eq_zero_of_ae have : ∀ᵐ x ∂Measure.map f μ, (0 : ℝ) ≤ x := (ae_map_iff hf.aemeasurable measurableSet_Ici).2 (eventually_of_forall h'f) filter_upwards [this] with x hx simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp] intro _ h''x have : x = 0 := by linarith simp [this, zero_pow hn] · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) : ∫ x, truncation f A x ∂μ = ∫ y in -A..A, y ∂Measure.map f μ := by simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} (h'f : 0 ≤ f) : ∫ x, truncation f A x ∂μ = ∫ y in (0)..A, y ∂Measure.map f μ := by simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f μ) (h'f : 0 ≤ f) {A : ℝ} : ∫ x, truncation f A x ∂μ ≤ ∫ x, f x ∂μ := by apply integral_mono_of_nonneg (eventually_of_forall fun x => ?_) hf (eventually_of_forall fun x => ?_) · exact truncation_nonneg _ (h'f x) · calc truncation f A x ≤ |truncation f A x| := le_abs_self _ _ ≤ |f x| := abs_truncation_le_abs_self _ _ _ _ = f x := abs_of_nonneg (h'f x) /-- If a function is integrable, then the integral of its truncated versions converges to the integral of the whole function. -/ theorem tendsto_integral_truncation {f : α → ℝ} (hf : Integrable f μ) : Tendsto (fun A => ∫ x, truncation f A x ∂μ) atTop (𝓝 (∫ x, f x ∂μ)) := by refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_ · exact eventually_of_forall fun A ↦ hf.aestronglyMeasurable.truncation · filter_upwards with A filter_upwards with x rw [Real.norm_eq_abs] exact abs_truncation_le_abs_self _ _ _ · exact hf.abs · filter_upwards with x apply tendsto_const_nhds.congr' _ filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA exact (truncation_eq_self hA).symm theorem IdentDistrib.truncation {β : Type*} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) {A : ℝ} : IdentDistrib (truncation f A) (truncation g A) μ ν := h.comp (measurable_id.indicator measurableSet_Ioc) end Truncation section StrongLawAeReal variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] section MomentEstimates theorem sum_prob_mem_Ioc_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) {K : ℕ} {N : ℕ} (hKN : K ≤ N) : ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} ≤ ENNReal.ofReal (𝔼[X] + 1) := by let ρ : Measure ℝ := Measure.map X ℙ haveI : IsProbabilityMeasure ρ := isProbabilityMeasure_map hint.aemeasurable have A : ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ ≤ 𝔼[X] + 1 := calc ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ = ∑ j ∈ range K, ∑ i ∈ Ico j N, ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by apply sum_congr rfl fun j hj => ?_ rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)] intro k _ exact continuous_const.intervalIntegrable _ _ _ = ∑ i ∈ range N, ∑ j ∈ range (min (i + 1) K), ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by simp_rw [sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add simp Nat.lt_succ_iff) _ ≤ ∑ i ∈ range N, (i + 1) * ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by apply sum_le_sum fun i _ => ?_ simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min] refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_ apply intervalIntegral.integral_nonneg · simp only [le_add_iff_nonneg_right, zero_le_one] · simp only [zero_le_one, imp_true_iff] _ ≤ ∑ i ∈ range N, ∫ x in i..(i + 1 : ℕ), x + 1 ∂ρ := by apply sum_le_sum fun i _ => ?_ have I : (i : ℝ) ≤ (i + 1 : ℕ) := by simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] simp_rw [intervalIntegral.integral_of_le I, ← integral_mul_left] apply setIntegral_mono_on · exact continuous_const.integrableOn_Ioc · exact (continuous_id.add continuous_const).integrableOn_Ioc · exact measurableSet_Ioc · intro x hx simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx simp [hx.1.le] _ = ∫ x in (0)..N, x + 1 ∂ρ := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] · norm_cast · exact (continuous_id.add continuous_const).intervalIntegrable _ _ _ = ∫ x in (0)..N, x ∂ρ + ∫ x in (0)..N, 1 ∂ρ := by rw [intervalIntegral.integral_add] · exact continuous_id.intervalIntegrable _ _ · exact continuous_const.intervalIntegrable _ _ _ = 𝔼[truncation X N] + ∫ x in (0)..N, 1 ∂ρ := by rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] _ ≤ 𝔼[X] + ∫ x in (0)..N, 1 ∂ρ := (add_le_add_right (integral_truncation_le_integral_of_nonneg hint hnonneg) _) _ ≤ 𝔼[X] + 1 := by refine add_le_add le_rfl ?_ rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)] simp only [integral_const, Measure.restrict_apply', measurableSet_Ioc, Set.univ_inter, Algebra.id.smul_eq_mul, mul_one] rw [← ENNReal.one_toReal] exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one have B : ∀ a b, ℙ {ω | X ω ∈ Set.Ioc a b} = ENNReal.ofReal (∫ _ in Set.Ioc a b, (1 : ℝ) ∂ρ) := by intro a b rw [ofReal_setIntegral_one ρ _, Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc] rfl calc ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} = ∑ j ∈ range K, ENNReal.ofReal (∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by simp_rw [B] _ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by rw [ENNReal.ofReal_sum_of_nonneg] simp only [integral_const, Algebra.id.smul_eq_mul, mul_one, ENNReal.toReal_nonneg, imp_true_iff] _ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in (j : ℝ)..N, (1 : ℝ) ∂ρ) := by congr 1 refine sum_congr rfl fun j hj => ?_ rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))] _ ≤ ENNReal.ofReal (𝔼[X] + 1) := ENNReal.ofReal_le_ofReal A theorem tsum_prob_mem_Ioi_lt_top {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) : (∑' j : ℕ, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by suffices ∀ K : ℕ, ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)} ≤ ENNReal.ofReal (𝔼[X] + 1) from (le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds (eventually_of_forall this)).trans_lt ENNReal.ofReal_lt_top intro K have A : Tendsto (fun N : ℕ => ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N}) atTop (𝓝 (∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)})) := by refine tendsto_finset_sum _ fun i _ => ?_ have : {ω | X ω ∈ Set.Ioi (i : ℝ)} = ⋃ N : ℕ, {ω | X ω ∈ Set.Ioc (i : ℝ) N} := by apply Set.Subset.antisymm _ _ · intro ω hω obtain ⟨N, hN⟩ : ∃ N : ℕ, X ω ≤ N := exists_nat_ge (X ω) exact Set.mem_iUnion.2 ⟨N, hω, hN⟩ · simp (config := {contextual := true}) only [Set.mem_Ioc, Set.mem_Ioi, Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff] rw [this] apply tendsto_measure_iUnion intro m n hmn x hx exact ⟨hx.1, hx.2.trans (Nat.cast_le.2 hmn)⟩ apply le_of_tendsto_of_tendsto A tendsto_const_nhds filter_upwards [Ici_mem_atTop K] with N hN exact sum_prob_mem_Ioc_le hint hnonneg hN theorem sum_variance_truncation_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) (K : ℕ) : ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation X j ^ 2] ≤ 2 * 𝔼[X] := by set Y := fun n : ℕ => truncation X n let ρ : Measure ℝ := Measure.map X ℙ have Y2 : ∀ n, 𝔼[Y n ^ 2] = ∫ x in (0)..n, x ^ 2 ∂ρ := by intro n change 𝔼[fun x => Y n x ^ 2] = _ rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg] calc ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[Y j ^ 2] = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∫ x in (0)..j, x ^ 2 ∂ρ := by simp_rw [Y2] _ = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∑ k ∈ range j, ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by congr 1 with j congr 1 rw [intervalIntegral.sum_integral_adjacent_intervals] · norm_cast intro k _ exact (continuous_id.pow _).intervalIntegrable _ _ _ = ∑ k ∈ range K, (∑ j ∈ Ioo k K, ((j : ℝ) ^ 2)⁻¹) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add unsafe lt_trans) _ ≤ ∑ k ∈ range K, 2 / (k + 1 : ℝ) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by apply sum_le_sum fun k _ => ?_ refine mul_le_mul_of_nonneg_right (sum_Ioo_inv_sq_le _ _) ?_ refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _ simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] _ ≤ ∑ k ∈ range K, ∫ x in k..(k + 1 : ℕ), 2 * x ∂ρ := by apply sum_le_sum fun k _ => ?_ have Ik : (k : ℝ) ≤ (k + 1 : ℕ) := by simp rw [← intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik, intervalIntegral.integral_of_le Ik] refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_ · apply Continuous.integrableOn_Ioc exact continuous_const.mul (continuous_pow 2) · apply Continuous.integrableOn_Ioc exact continuous_const.mul continuous_id' · calc ↑2 / (↑k + ↑1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring _ ≤ 1 * (2 * x) := (mul_le_mul_of_nonneg_right (by convert (div_le_one _).2 hx.2 · norm_cast simp only [Nat.cast_add, Nat.cast_one] linarith only [show (0 : ℝ) ≤ k from Nat.cast_nonneg k]) (mul_nonneg zero_le_two ((Nat.cast_nonneg k).trans hx.1.le))) _ = 2 * x := by rw [one_mul] _ = 2 * ∫ x in (0 : ℝ)..K, x ∂ρ := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] swap; · exact (continuous_const.mul continuous_id').intervalIntegrable _ _ rw [intervalIntegral.integral_const_mul] norm_cast _ ≤ 2 * 𝔼[X] := mul_le_mul_of_nonneg_left (by rw [← integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two end MomentEstimates /-! Proof of the strong law of large numbers (almost sure version, assuming only pairwise independence) for nonnegative random variables, following Etemadi's proof. -/ section StrongLawNonneg variable (X : ℕ → Ω → ℝ) (hint : Integrable (X 0)) (hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0)) (hnonneg : ∀ i ω, 0 ≤ X i ω) /-- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `ε > 0`. This follows from a variance control. -/ theorem strong_law_aux1 {c : ℝ} (c_one : 1 < c) {ε : ℝ} (εpos : 0 < ε) : ∀ᵐ ω, ∀ᶠ n : ℕ in atTop, |∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - 𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]| < ε * ⌊c ^ n⌋₊ := by /- Let `S n = ∑ i ∈ range n, Y i` where `Y i = truncation (X i) i`. We should show that `|S k - 𝔼[S k]| / k ≤ ε` along the sequence of powers of `c`. For this, we apply Borel-Cantelli: it suffices to show that the converse probabilites are summable. From Chebyshev inequality, this will follow from a variance control `∑' Var[S (c^i)] / (c^i)^2 < ∞`. This is checked in `I2` using pairwise independence to expand the variance of the sum as the sum of the variances, and then a straightforward but tedious computation (essentially boiling down to the fact that the sum of `1/(c ^ i)^2` beyong a threshold `j` is comparable to `1/j^2`). Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer parts everywhere, making things more painful. We write `u i = ⌊c^i⌋₊` for brevity. -/ have c_pos : 0 < c := zero_lt_one.trans c_one have hX : ∀ i, AEStronglyMeasurable (X i) ℙ := fun i => (hident i).symm.aestronglyMeasurable_snd hint.1 have A : ∀ i, StronglyMeasurable (indicator (Set.Ioc (-i : ℝ) i) id) := fun i => stronglyMeasurable_id.indicator measurableSet_Ioc set Y := fun n : ℕ => truncation (X n) n set S := fun n => ∑ i ∈ range n, Y i with hS let u : ℕ → ℕ := fun n => ⌊c ^ n⌋₊ have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_le_pow_right c_one.le hij) have I1 : ∀ K, ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤ 2 * 𝔼[X 0] := by intro K calc ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≤ ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation (X 0) j ^ 2] := by apply sum_le_sum fun j _ => ?_ refine mul_le_mul_of_nonneg_left ?_ (inv_nonneg.2 (sq_nonneg _)) rw [(hident j).truncation.variance_eq] exact variance_le_expectation_sq (hX 0).truncation _ ≤ 2 * 𝔼[X 0] := sum_variance_truncation_le hint (hnonneg 0) K let C := c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) have I2 : ∀ N, ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] ≤ C := by intro N calc ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] = ∑ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * ∑ j ∈ range (u i), Var[Y j] := by congr 1 with i congr 1 rw [hS, IndepFun.variance_sum] · intro j _ exact (hident j).aestronglyMeasurable_fst.memℒp_truncation · intro k _ l _ hkl exact (hindep hkl).comp (A k).measurable (A l).measurable _ = ∑ j ∈ range (u (N - 1)), (∑ i ∈ (range N).filter fun i => j < u i, ((u i : ℝ) ^ 2)⁻¹) * Var[Y j] := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ · simp only [mem_sigma, mem_range, filter_congr_decidable, mem_filter, and_imp, Sigma.forall] exact fun a b haN hb ↦ ⟨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hb⟩ all_goals aesop _ ≤ ∑ j ∈ range (u (N - 1)), c ^ 5 * (c - 1)⁻¹ ^ 3 / ↑j ^ 2 * Var[Y j] := by apply sum_le_sum fun j hj => ?_ rcases @eq_zero_or_pos _ _ j with (rfl | hj) · simp only [Nat.cast_zero, zero_pow, Ne, Nat.one_ne_zero, not_false_iff, div_zero, zero_mul] simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl] apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _) convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2 · simp only [Nat.cast_lt] · simp only [one_div] _ = c ^ 5 * (c - 1)⁻¹ ^ 3 * ∑ j ∈ range (u (N - 1)), ((j : ℝ) ^ 2)⁻¹ * Var[Y j] := by simp_rw [mul_sum, div_eq_mul_inv, mul_assoc] _ ≤ c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) := by apply mul_le_mul_of_nonneg_left (I1 _) apply mul_nonneg (pow_nonneg c_pos.le _) exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _ have I3 : ∀ N, ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by intro N calc ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤ ∑ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * ε) ^ 2) := by refine sum_le_sum fun i _ => ?_ apply meas_ge_le_variance_div_sq · exact memℒp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memℒp_truncation · apply mul_pos (Nat.cast_pos.2 _) εpos refine zero_lt_one.trans_le ?_ apply Nat.le_floor rw [Nat.cast_one] apply one_le_pow_of_one_le c_one.le _ = ENNReal.ofReal (∑ i ∈ range N, Var[S (u i)] / (u i * ε) ^ 2) := by rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_] exact div_nonneg (variance_nonneg _ _) (sq_nonneg _) _ ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by apply ENNReal.ofReal_le_ofReal -- Porting note: do most of the rewrites under `conv` so as not to expand `variance` conv_lhs => enter [2, i] rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ ε⁻¹, mul_pow, mul_assoc] rw [← mul_sum] refine mul_le_mul_of_nonneg_left ?_ (sq_nonneg _) conv_lhs => enter [2, i]; rw [inv_pow] exact I2 N have I4 : (∑' i, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|}) < ∞ := (le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt ENNReal.ofReal_lt_top filter_upwards [ae_eventually_not_mem I4.ne] with ω hω simp_rw [S, not_le, mul_comm, sum_apply] at hω convert hω; simp only [sum_apply] /- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `ε`. -/ theorem strong_law_aux2 {c : ℝ} (c_one : 1 < c) : ∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - 𝔼[∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i]) =o[atTop] fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by obtain ⟨v, -, v_pos, v_lim⟩ : ∃ v : ℕ → ℝ, StrictAnti v ∧ (∀ n : ℕ, 0 < v n) ∧ Tendsto v atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i) filter_upwards [ae_all_iff.2 this] with ω hω apply Asymptotics.isLittleO_iff.2 fun ε εpos => ?_ obtain ⟨i, hi⟩ : ∃ i, v i < ε := ((tendsto_order.1 v_lim).2 ε εpos).exists filter_upwards [hω i] with n hn simp only [Real.norm_eq_abs, abs_abs, Nat.abs_cast] exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _)) /-- The expectation of the truncated version of `Xᵢ` behaves asymptotically like the whole expectation. This follows from convergence and Cesàro averaging. -/ theorem strong_law_aux3 : (fun n => 𝔼[∑ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : ℕ → ℝ) := by have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1 ext i exact (hident i).truncation.integral_eq convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1 ext1 n simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj] rw [integral_finset_sum _ fun i _ => ?_] exact ((hident i).symm.integrable_snd hint).1.integrable_truncation /- The truncation of `Xᵢ` up to `i` satisfies the strong law of large numbers (with respect to the original expectation) along the sequence `c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the fact that the truncated and the original expectations have the same asymptotic behavior. -/ theorem strong_law_aux4 {c : ℝ} (c_one : 1 < c) : ∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, truncation (X i) i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop] fun n : ℕ => (⌊c ^ n⌋₊ : ℝ) := by filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with ω hω have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hω.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1 ext1 n simp /-- The truncated and non-truncated versions of `Xᵢ` have the same asymptotic behavior, as they almost surely coincide at all but finitely many steps. This follows from a probability computation and Borel-Cantelli. -/ theorem strong_law_aux5 : ∀ᵐ ω, (fun n : ℕ => ∑ i ∈ range n, truncation (X i) i ω - ∑ i ∈ range n, X i ω) =o[atTop] fun n : ℕ => (n : ℝ) := by have A : (∑' j : ℕ, ℙ {ω | X j ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by convert tsum_prob_mem_Ioi_lt_top hint (hnonneg 0) using 2 ext1 j exact (hident j).measure_mem_eq measurableSet_Ioi have B : ∀ᵐ ω, Tendsto (fun n : ℕ => truncation (X n) n ω - X n ω) atTop (𝓝 0) := by filter_upwards [ae_eventually_not_mem A.ne] with ω hω apply tendsto_const_nhds.congr' _ filter_upwards [hω, Ioi_mem_atTop 0] with n hn npos simp only [truncation, indicator, Set.mem_Ioc, id, Function.comp_apply] split_ifs with h · exact (sub_self _).symm · have : -(n : ℝ) < X n ω := by apply lt_of_lt_of_le _ (hnonneg n ω) simpa only [Right.neg_neg_iff, Nat.cast_pos] using npos simp only [this, true_and_iff, not_le] at h exact (hn h).elim filter_upwards [B] with ω hω convert isLittleO_sum_range_of_tendsto_zero hω using 1 ext n rw [sum_sub_distrib] /- `Xᵢ` satisfies the strong law of large numbers along the sequence `c^n`, for any `c > 1`. This follows from the version for the truncated `Xᵢ`, and the fact that `Xᵢ` and its truncated version have the same asymptotic behavior. -/ theorem strong_law_aux6 {c : ℝ} (c_one : 1 < c) : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range ⌊c ^ n⌋₊, X i ω) / ⌊c ^ n⌋₊) atTop (𝓝 𝔼[X 0]) := by have H : ∀ n : ℕ, (0 : ℝ) < ⌊c ^ n⌋₊ := by intro n refine zero_lt_one.trans_le ?_ simp only [Nat.one_le_cast, Nat.one_le_floor_iff, one_le_pow_of_one_le c_one.le n] filter_upwards [strong_law_aux4 X hint hindep hident hnonneg c_one, strong_law_aux5 X hint hident hnonneg] with ω hω h'ω rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ] have L : (fun n : ℕ => ∑ i ∈ range ⌊c ^ n⌋₊, X i ω - ⌊c ^ n⌋₊ * 𝔼[X 0]) =o[atTop] fun n => (⌊c ^ n⌋₊ : ℝ) := by have A : Tendsto (fun n : ℕ => ⌊c ^ n⌋₊) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hω.sub (h'ω.comp_tendsto A) using 1 ext1 n simp only [Function.comp_apply, sub_sub_sub_cancel_left] convert L.mul_isBigO (isBigO_refl (fun n : ℕ => (⌊c ^ n⌋₊ : ℝ)⁻¹) atTop) using 1 <;> (ext1 n; field_simp [(H n).ne']) /-- `Xᵢ` satisfies the strong law of large numbers along all integers. This follows from the corresponding fact along the sequences `c^n`, and the fact that any integer can be sandwiched between `c^n` and `c^(n+1)` with comparably small error if `c` is close enough to `1` (which is formalized in `tendsto_div_of_monotone_of_tendsto_div_floor_pow`). -/ theorem strong_law_aux7 : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, X i ω) / n) atTop (𝓝 𝔼[X 0]) := by obtain ⟨c, -, cone, clim⟩ : ∃ c : ℕ → ℝ, StrictAnti c ∧ (∀ n : ℕ, 1 < c n) ∧ Tendsto c atTop (𝓝 1) := exists_seq_strictAnti_tendsto (1 : ℝ) have : ∀ k, ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range ⌊c k ^ n⌋₊, X i ω) / ⌊c k ^ n⌋₊) atTop (𝓝 𝔼[X 0]) := fun k => strong_law_aux6 X hint hindep hident hnonneg (cone k) filter_upwards [ae_all_iff.2 this] with ω hω apply tendsto_div_of_monotone_of_tendsto_div_floor_pow _ _ _ c cone clim _ · intro m n hmn exact sum_le_sum_of_subset_of_nonneg (range_mono hmn) fun i _ _ => hnonneg i ω · exact hω end StrongLawNonneg /-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent identically distributed integrable real-valued random variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. Superseded by `strong_law_ae`, which works for random variables taking values in any Banach space. -/ theorem strong_law_ae_real (X : ℕ → Ω → ℝ) (hint : Integrable (X 0)) (hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0)) : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, X i ω) / n) atTop (𝓝 𝔼[X 0]) := by let pos : ℝ → ℝ := fun x => max x 0 let neg : ℝ → ℝ := fun x => max (-x) 0 have posm : Measurable pos := measurable_id'.max measurable_const have negm : Measurable neg := measurable_id'.neg.max measurable_const have A : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, (pos ∘ X i) ω) / n) atTop (𝓝 𝔼[pos ∘ X 0]) := strong_law_aux7 _ hint.pos_part (fun i j hij => (hindep hij).comp posm posm) (fun i => (hident i).comp posm) fun i ω => le_max_right _ _ have B : ∀ᵐ ω, Tendsto (fun n : ℕ => (∑ i ∈ range n, (neg ∘ X i) ω) / n) atTop (𝓝 𝔼[neg ∘ X 0]) := strong_law_aux7 _ hint.neg_part (fun i j hij => (hindep hij).comp negm negm) (fun i => (hident i).comp negm) fun i ω => le_max_right _ _ filter_upwards [A, B] with ω hωpos hωneg convert hωpos.sub hωneg using 1 · simp only [pos, neg, ← sub_div, ← sum_sub_distrib, max_zero_sub_max_neg_zero_eq_self, Function.comp_apply] · simp only [← integral_sub hint.pos_part hint.neg_part, max_zero_sub_max_neg_zero_eq_self, Function.comp_apply] end StrongLawAeReal section StrongLawVectorSpace variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [MeasurableSpace E] [BorelSpace E] open Set TopologicalSpace /-- Preliminary lemma for the strong law of large numbers for vector-valued random variables: the composition of the random variables with a simple function satisfies the strong law of large numbers. -/ lemma strong_law_ae_simpleFunc_comp (X : ℕ → Ω → E) (h' : Measurable (X 0)) (hindep : Pairwise (fun i j ↦ IndepFun (X i) (X j))) (hident : ∀ i, IdentDistrib (X i) (X 0)) (φ : SimpleFunc E E) : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, φ (X i ω))) atTop (𝓝 𝔼[φ ∘ (X 0)]) := by -- this follows from the one-dimensional version when `φ` takes a single value, and is then -- extended to the general case by linearity. classical refine SimpleFunc.induction (P := fun ψ ↦ ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, ψ (X i ω))) atTop (𝓝 𝔼[ψ ∘ (X 0)])) ?_ ?_ φ · intro c s hs simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero, piecewise_eq_indicator, Function.comp_apply] let F : E → ℝ := indicator s 1 have F_meas : Measurable F := (measurable_indicator_const_iff 1).2 hs let Y : ℕ → Ω → ℝ := fun n ↦ F ∘ (X n) have : ∀ᵐ (ω : Ω), Tendsto (fun (n : ℕ) ↦ (n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y i ω) atTop (𝓝 𝔼[Y 0]) := by simp only [Function.const_one, smul_eq_mul, ← div_eq_inv_mul] apply strong_law_ae_real · exact SimpleFunc.integrable_of_isFiniteMeasure ((SimpleFunc.piecewise s hs (SimpleFunc.const _ (1 : ℝ)) (SimpleFunc.const _ (0 : ℝ))).comp (X 0) h') · exact fun i j hij ↦ IndepFun.comp (hindep hij) F_meas F_meas · exact fun i ↦ (hident i).comp F_meas filter_upwards [this] with ω hω have I : indicator s (Function.const E c) = (fun x ↦ (indicator s (1 : E → ℝ) x) • c) := by ext rw [← indicator_smul_const_apply] congr! 1 ext simp simp only [I, integral_smul_const] convert Tendsto.smul_const hω c using 1 simp [Y, ← sum_smul, smul_smul] · rintro φ ψ - hφ hψ filter_upwards [hφ, hψ] with ω hωφ hωψ convert hωφ.add hωψ using 1 · simp [sum_add_distrib] · congr 1 rw [← integral_add] · rfl · exact (φ.comp (X 0) h').integrable_of_isFiniteMeasure · exact (ψ.comp (X 0) h').integrable_of_isFiniteMeasure /-- Preliminary lemma for the strong law of large numbers for vector-valued random variables, assuming measurability in addition to integrability. This is weakened to ae measurability in the full version `ProbabilityTheory.strong_law_ae`. -/ lemma strong_law_ae_of_measurable (X : ℕ → Ω → E) (hint : Integrable (X 0)) (h' : StronglyMeasurable (X 0)) (hindep : Pairwise (fun i j ↦ IndepFun (X i) (X j))) (hident : ∀ i, IdentDistrib (X i) (X 0)) : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω)) atTop (𝓝 𝔼[X 0]) := by /- Choose a simple function `φ` such that `φ (X 0)` approximates well enough `X 0` -- this is possible as `X 0` is strongly measurable. Then `φ (X n)` approximates well `X n`. Then the strong law for `φ (X n)` implies the strong law for `X n`, up to a small error controlled by `n⁻¹ ∑_{i=0}^{n-1} ‖X i - φ (X i)‖`. This one is also controlled thanks to the one-dimensional law of large numbers: it converges ae to `𝔼[‖X 0 - φ (X 0)‖]`, which is arbitrarily small for well chosen `φ`. -/ let s : Set E := Set.range (X 0) ∪ {0} have zero_s : 0 ∈ s := by simp [s] have : SeparableSpace s := h'.separableSpace_range_union_singleton have : Nonempty s := ⟨0, zero_s⟩ -- sequence of approximating simple functions. let φ : ℕ → SimpleFunc E E := SimpleFunc.nearestPt (fun k => Nat.casesOn k 0 ((↑) ∘ denseSeq s) : ℕ → E) let Y : ℕ → ℕ → Ω → E := fun k i ↦ (φ k) ∘ (X i) -- strong law for `φ (X n)` have A : ∀ᵐ ω, ∀ k, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, Y k i ω)) atTop (𝓝 𝔼[Y k 0]) := ae_all_iff.2 (fun k ↦ strong_law_ae_simpleFunc_comp X h'.measurable hindep hident (φ k)) -- strong law for the error `‖X i - φ (X i)‖` have B : ∀ᵐ ω, ∀ k, Tendsto (fun n : ℕ ↦ (∑ i ∈ range n, ‖(X i - Y k i) ω‖) / n) atTop (𝓝 𝔼[(fun ω ↦ ‖(X 0 - Y k 0) ω‖)]) := by apply ae_all_iff.2 (fun k ↦ ?_) let G : ℕ → E → ℝ := fun k x ↦ ‖x - φ k x‖ have G_meas : ∀ k, Measurable (G k) := fun k ↦ (measurable_id.sub_stronglyMeasurable (φ k).stronglyMeasurable).norm have I : ∀ k i, (fun ω ↦ ‖(X i - Y k i) ω‖) = (G k) ∘ (X i) := fun k i ↦ rfl apply strong_law_ae_real (fun i ω ↦ ‖(X i - Y k i) ω‖) · exact (hint.sub ((φ k).comp (X 0) h'.measurable).integrable_of_isFiniteMeasure).norm · simp_rw [I] intro i j hij exact (hindep hij).comp (G_meas k) (G_meas k) · intro i simp_rw [I] apply (hident i).comp (G_meas k) -- check that, when both convergences above hold, then the strong law is satisfied filter_upwards [A, B] with ω hω h'ω rw [tendsto_iff_norm_sub_tendsto_zero, tendsto_order] refine ⟨fun c hc ↦ eventually_of_forall (fun n ↦ hc.trans_le (norm_nonneg _)), ?_⟩ -- start with some positive `ε` (the desired precision), and fix `δ` with `3 δ < ε`. intro ε (εpos : 0 < ε) obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ δ + δ + δ < ε := ⟨ε/4, by positivity, by linarith⟩ -- choose `k` large enough so that `φₖ (X 0)` approximates well enough `X 0`, up to the -- precision `δ`. obtain ⟨k, hk⟩ : ∃ k, ∫ ω, ‖(X 0 - Y k 0) ω‖ < δ := by simp_rw [Pi.sub_apply, norm_sub_rev (X 0 _)] exact ((tendsto_order.1 (tendsto_integral_norm_approxOn_sub h'.measurable hint)).2 δ δpos).exists have : ‖𝔼[Y k 0] - 𝔼[X 0]‖ < δ := by rw [norm_sub_rev, ← integral_sub hint] · exact (norm_integral_le_integral_norm _).trans_lt hk · exact ((φ k).comp (X 0) h'.measurable).integrable_of_isFiniteMeasure -- consider `n` large enough for which the above convergences have taken place within `δ`. have I : ∀ᶠ n in atTop, (∑ i ∈ range n, ‖(X i - Y k i) ω‖) / n < δ := (tendsto_order.1 (h'ω k)).2 δ hk have J : ∀ᶠ (n : ℕ) in atTop, ‖(n : ℝ) ⁻¹ • (∑ i ∈ range n, Y k i ω) - 𝔼[Y k 0]‖ < δ := by specialize hω k rw [tendsto_iff_norm_sub_tendsto_zero] at hω exact (tendsto_order.1 hω).2 δ δpos filter_upwards [I, J] with n hn h'n -- at such an `n`, the strong law is realized up to `ε`. calc ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, X i ω - 𝔼[X 0]‖ = ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, (X i ω - Y k i ω) + ((n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y k i ω - 𝔼[Y k 0]) + (𝔼[Y k 0] - 𝔼[X 0])‖ := by congr simp only [Function.comp_apply, sum_sub_distrib, smul_sub] abel _ ≤ ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, (X i ω - Y k i ω)‖ + ‖(n : ℝ)⁻¹ • ∑ i ∈ Finset.range n, Y k i ω - 𝔼[Y k 0]‖ + ‖𝔼[Y k 0] - 𝔼[X 0]‖ := norm_add₃_le _ _ _ _ ≤ (∑ i ∈ Finset.range n, ‖X i ω - Y k i ω‖) / n + δ + δ := by gcongr simp only [Function.comp_apply, norm_smul, norm_inv, RCLike.norm_natCast, div_eq_inv_mul, inv_pos, Nat.cast_pos, inv_lt_zero] gcongr exact norm_sum_le _ _ _ ≤ δ + δ + δ := by gcongr exact hn.le _ < ε := hδ /-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent identically distributed integrable random variables taking values in a Banach space, then `n⁻¹ • ∑ i ∈ range n, X i` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. -/ theorem strong_law_ae (X : ℕ → Ω → E) (hint : Integrable (X 0)) (hindep : Pairwise (fun i j ↦ IndepFun (X i) (X j))) (hident : ∀ i, IdentDistrib (X i) (X 0)) : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω)) atTop (𝓝 𝔼[X 0]) := by -- we reduce to the case of strongly measurable random variables, by using `Y i` which is strongly -- measurable and ae equal to `X i`. have A : ∀ i, Integrable (X i) := fun i ↦ (hident i).integrable_iff.2 hint let Y : ℕ → Ω → E := fun i ↦ (A i).1.mk (X i) have B : ∀ᵐ ω, ∀ n, X n ω = Y n ω := ae_all_iff.2 (fun i ↦ AEStronglyMeasurable.ae_eq_mk (A i).1) have Yint : Integrable (Y 0) := Integrable.congr hint (AEStronglyMeasurable.ae_eq_mk (A 0).1) have C : ∀ᵐ ω, Tendsto (fun n : ℕ ↦ (n : ℝ) ⁻¹ • (∑ i ∈ range n, Y i ω)) atTop (𝓝 𝔼[Y 0]) := by apply strong_law_ae_of_measurable Y Yint ((A 0).1.stronglyMeasurable_mk) (fun i j hij ↦ IndepFun.ae_eq (hindep hij) (A i).1.ae_eq_mk (A j).1.ae_eq_mk) (fun i ↦ ((A i).1.identDistrib_mk.symm.trans (hident i)).trans (A 0).1.identDistrib_mk) filter_upwards [B, C] with ω h₁ h₂ have : 𝔼[X 0] = 𝔼[Y 0] := integral_congr_ae (AEStronglyMeasurable.ae_eq_mk (A 0).1) rw [this] apply Tendsto.congr (fun n ↦ ?_) h₂ congr with i exact (h₁ i).symm end StrongLawVectorSpace section StrongLawLp variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [MeasurableSpace E] [BorelSpace E] /-- **Strong law of large numbers**, Lᵖ version: if `X n` is a sequence of independent identically distributed random variables in Lᵖ, then `n⁻¹ • ∑ i ∈ range n, X i` converges in `Lᵖ` to `𝔼[X 0]`. -/ theorem strong_law_Lp {p : ℝ≥0∞} (hp : 1 ≤ p) (hp' : p ≠ ∞) (X : ℕ → Ω → E) (hℒp : Memℒp (X 0) p) (hindep : Pairwise fun i j => IndepFun (X i) (X j)) (hident : ∀ i, IdentDistrib (X i) (X 0)) : Tendsto (fun (n : ℕ) => eLpNorm (fun ω => (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω) - 𝔼[X 0]) p ℙ) atTop (𝓝 0) := by have hmeas : ∀ i, AEStronglyMeasurable (X i) ℙ := fun i => (hident i).aestronglyMeasurable_iff.2 hℒp.1 have hint : Integrable (X 0) ℙ := hℒp.integrable hp have havg : ∀ (n : ℕ), AEStronglyMeasurable (fun ω => (n : ℝ) ⁻¹ • (∑ i ∈ range n, X i ω)) ℙ := by intro n exact AEStronglyMeasurable.const_smul (aestronglyMeasurable_sum _ fun i _ => hmeas i) _ refine tendsto_Lp_finite_of_tendstoInMeasure hp hp' havg (memℒp_const _) ?_ (tendstoInMeasure_of_tendsto_ae havg (strong_law_ae _ hint hindep hident)) rw [(_ : (fun (n : ℕ) ω => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i ω)) = fun (n : ℕ) => (n : ℝ)⁻¹ • (∑ i ∈ range n, X i))] · apply UniformIntegrable.unifIntegrable apply uniformIntegrable_average hp exact Memℒp.uniformIntegrable_of_identDistrib hp hp' hℒp hident · ext n ω simp only [Pi.smul_apply, sum_apply] end StrongLawLp end ProbabilityTheory
Probability\Variance.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, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Integration import Mathlib.MeasureTheory.Function.L2Space /-! # Variance of random variables We define the variance of a real-valued random variable as `Var[X] = 𝔼[(X - 𝔼[X])^2]` (in the `ProbabilityTheory` locale). ## Main definitions * `ProbabilityTheory.evariance`: the variance of a real-valued random variable as an extended non-negative real. * `ProbabilityTheory.variance`: the variance of a real-valued random variable as a real number. ## Main results * `ProbabilityTheory.variance_le_expectation_sq`: the inequality `Var[X] ≤ 𝔼[X^2]`. * `ProbabilityTheory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e., `ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2)`. * `ProbabilityTheory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with `evariance` without requiring the random variables to be L². * `ProbabilityTheory.IndepFun.variance_add`: the variance of the sum of two independent random variables is the sum of the variances. * `ProbabilityTheory.IndepFun.variance_sum`: the variance of a finite sum of pairwise independent random variables is the sum of the variances. -/ open MeasureTheory Filter Finset noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory -- Porting note: Consider if `evariance` or `eVariance` is better. Also, -- consider `eVariationOn` in `Mathlib.Analysis.BoundedVariation`. /-- The `ℝ≥0∞`-valued variance of a real-valued random variable defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/ def evariance {Ω : Type*} {_ : MeasurableSpace Ω} (X : Ω → ℝ) (μ : Measure Ω) : ℝ≥0∞ := ∫⁻ ω, (‖X ω - μ[X]‖₊ : ℝ≥0∞) ^ 2 ∂μ /-- The `ℝ`-valued variance of a real-valued random variable defined by applying `ENNReal.toReal` to `evariance`. -/ def variance {Ω : Type*} {_ : MeasurableSpace Ω} (X : Ω → ℝ) (μ : Measure Ω) : ℝ := (evariance X μ).toReal variable {Ω : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} theorem _root_.MeasureTheory.Memℒp.evariance_lt_top [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : evariance X μ < ∞ := by have := ENNReal.pow_lt_top (hX.sub <| memℒp_const <| μ[X]).2 2 rw [eLpNorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top, ← ENNReal.rpow_two] at this simp only [ENNReal.toReal_ofNat, Pi.sub_apply, ENNReal.one_toReal, one_div] at this rw [← ENNReal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this simp_rw [ENNReal.rpow_two] at this exact this theorem evariance_eq_top [IsFiniteMeasure μ] (hXm : AEStronglyMeasurable X μ) (hX : ¬Memℒp X 2 μ) : evariance X μ = ∞ := by by_contra h rw [← Ne, ← lt_top_iff_ne_top] at h have : Memℒp (fun ω => X ω - μ[X]) 2 μ := by refine ⟨hXm.sub aestronglyMeasurable_const, ?_⟩ rw [eLpNorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top] simp only [ENNReal.toReal_ofNat, ENNReal.one_toReal, ENNReal.rpow_two, Ne] exact ENNReal.rpow_lt_top_of_nonneg (by linarith) h.ne refine hX ?_ -- Porting note: `μ[X]` without whitespace is ambiguous as it could be GetElem, -- and `convert` cannot disambiguate based on typeclass inference failure. convert this.add (memℒp_const <| μ [X]) ext ω rw [Pi.add_apply, sub_add_cancel] theorem evariance_lt_top_iff_memℒp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) : evariance X μ < ∞ ↔ Memℒp X 2 μ := by refine ⟨?_, MeasureTheory.Memℒp.evariance_lt_top⟩ contrapose rw [not_lt, top_le_iff] exact evariance_eq_top hX theorem _root_.MeasureTheory.Memℒp.ofReal_variance_eq [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : ENNReal.ofReal (variance X μ) = evariance X μ := by rw [variance, ENNReal.ofReal_toReal] exact hX.evariance_lt_top.ne theorem evariance_eq_lintegral_ofReal (X : Ω → ℝ) (μ : Measure Ω) : evariance X μ = ∫⁻ ω, ENNReal.ofReal ((X ω - μ[X]) ^ 2) ∂μ := by rw [evariance] congr ext1 ω rw [pow_two, ← ENNReal.coe_mul, ← nnnorm_mul, ← pow_two] congr exact (Real.toNNReal_eq_nnnorm_of_nonneg <| sq_nonneg _).symm theorem _root_.MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero (hX : Memℒp X 2 μ) (hXint : μ[X] = 0) : variance X μ = μ[X ^ (2 : Nat)] := by rw [variance, evariance_eq_lintegral_ofReal, ← ofReal_integral_eq_lintegral_ofReal, ENNReal.toReal_ofReal (by positivity)] <;> simp_rw [hXint, sub_zero] · rfl · convert hX.integrable_norm_rpow two_ne_zero ENNReal.two_ne_top with ω simp only [Pi.sub_apply, Real.norm_eq_abs, ENNReal.toReal_ofNat, ENNReal.one_toReal, Real.rpow_two, sq_abs, abs_pow] · exact ae_of_all _ fun ω => pow_two_nonneg _ theorem _root_.MeasureTheory.Memℒp.variance_eq [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : variance X μ = μ[(X - fun _ => μ[X] :) ^ (2 : Nat)] := by rw [variance, evariance_eq_lintegral_ofReal, ← ofReal_integral_eq_lintegral_ofReal, ENNReal.toReal_ofReal (by positivity)] · rfl · -- Porting note: `μ[X]` without whitespace is ambiguous as it could be GetElem, -- and `convert` cannot disambiguate based on typeclass inference failure. convert (hX.sub <| memℒp_const (μ [X])).integrable_norm_rpow two_ne_zero ENNReal.two_ne_top with ω simp only [Pi.sub_apply, Real.norm_eq_abs, ENNReal.toReal_ofNat, ENNReal.one_toReal, Real.rpow_two, sq_abs, abs_pow] · exact ae_of_all _ fun ω => pow_two_nonneg _ @[simp] theorem evariance_zero : evariance 0 μ = 0 := by simp [evariance] theorem evariance_eq_zero_iff (hX : AEMeasurable X μ) : evariance X μ = 0 ↔ X =ᵐ[μ] fun _ => μ[X] := by rw [evariance, lintegral_eq_zero_iff'] constructor <;> intro hX <;> filter_upwards [hX] with ω hω · simpa only [Pi.zero_apply, sq_eq_zero_iff, ENNReal.coe_eq_zero, nnnorm_eq_zero, sub_eq_zero] using hω · rw [hω] simp · exact (hX.sub_const _).ennnorm.pow_const _ -- TODO `measurability` and `fun_prop` fail theorem evariance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : evariance (fun ω => c * X ω) μ = ENNReal.ofReal (c ^ 2) * evariance X μ := by rw [evariance, evariance, ← lintegral_const_mul' _ _ ENNReal.ofReal_lt_top.ne] congr ext1 ω rw [ENNReal.ofReal, ← ENNReal.coe_pow, ← ENNReal.coe_pow, ← ENNReal.coe_mul] congr rw [← sq_abs, ← Real.rpow_two, Real.toNNReal_rpow_of_nonneg (abs_nonneg _), NNReal.rpow_two, ← mul_pow, Real.toNNReal_mul_nnnorm _ (abs_nonneg _)] conv_rhs => rw [← nnnorm_norm, norm_mul, norm_abs_eq_norm, ← norm_mul, nnnorm_norm, mul_sub] congr rw [mul_comm] simp_rw [← smul_eq_mul, ← integral_smul_const, smul_eq_mul, mul_comm] scoped notation "eVar[" X "]" => ProbabilityTheory.evariance X MeasureTheory.MeasureSpace.volume @[simp] theorem variance_zero (μ : Measure Ω) : variance 0 μ = 0 := by simp only [variance, evariance_zero, ENNReal.zero_toReal] theorem variance_nonneg (X : Ω → ℝ) (μ : Measure Ω) : 0 ≤ variance X μ := ENNReal.toReal_nonneg theorem variance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : variance (fun ω => c * X ω) μ = c ^ 2 * variance X μ := by rw [variance, evariance_mul, ENNReal.toReal_mul, ENNReal.toReal_ofReal (sq_nonneg _)] rfl theorem variance_smul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : variance (c • X) μ = c ^ 2 * variance X μ := variance_mul c X μ theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ) (μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by convert variance_smul (algebraMap A ℝ c) X μ using 1 · congr; simp only [algebraMap_smul] · simp only [Algebra.smul_def, map_pow] scoped notation "Var[" X "]" => ProbabilityTheory.variance X MeasureTheory.MeasureSpace.volume variable [MeasureSpace Ω] theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) : Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left · exact hX.integrable_sq · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2) · apply hX.integrable_sq.add convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2) · exact ((hX.integrable one_le_two).const_mul 2).mul_const' _ simp only [Pi.pow_apply, integral_const, measure_univ, ENNReal.one_toReal, smul_eq_mul, one_mul, Pi.mul_apply, Pi.ofNat_apply, Nat.cast_ofNat, integral_mul_right, integral_mul_left] ring theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by by_cases hX : Memℒp X 2 · rw [variance_def' hX] simp only [sq_nonneg, sub_le_self_iff] rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae] · by_cases hint : Integrable X; swap · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero] exact le_rfl · rw [integral_undef] · exact integral_nonneg fun a => sq_nonneg _ intro h have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ := (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _ apply hX convert A.add B simp · exact eventually_of_forall fun x => sq_nonneg _ · exact (AEMeasurable.pow_const (hm.aemeasurable.sub_const _) _).aestronglyMeasurable theorem evariance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : AEStronglyMeasurable X ℙ) : eVar[X] = (∫⁻ ω, (‖X ω‖₊ ^ 2 :)) - ENNReal.ofReal (𝔼[X] ^ 2) := by by_cases hℒ : Memℒp X 2 · rw [← hℒ.ofReal_variance_eq, variance_def' hℒ, ENNReal.ofReal_sub _ (sq_nonneg _)] congr rw [lintegral_coe_eq_integral] · congr 2 with ω simp only [Pi.pow_apply, NNReal.coe_pow, coe_nnnorm, Real.norm_eq_abs, Even.pow_abs even_two] · exact hℒ.abs.integrable_sq · symm rw [evariance_eq_top hX hℒ, ENNReal.sub_eq_top_iff] refine ⟨?_, ENNReal.ofReal_ne_top⟩ rw [Memℒp, not_and] at hℒ specialize hℒ hX simp only [eLpNorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top, not_lt, top_le_iff, ENNReal.toReal_ofNat, one_div, ENNReal.rpow_eq_top_iff, inv_lt_zero, inv_pos, and_true_iff, or_iff_not_imp_left, not_and_or, zero_lt_two] at hℒ exact mod_cast hℒ fun _ => zero_le_two /-- **Chebyshev's inequality** for `ℝ≥0∞`-valued variance. -/ theorem meas_ge_le_evariance_div_sq {X : Ω → ℝ} (hX : AEStronglyMeasurable X ℙ) {c : ℝ≥0} (hc : c ≠ 0) : ℙ {ω | ↑c ≤ |X ω - 𝔼[X]|} ≤ eVar[X] / c ^ 2 := by have A : (c : ℝ≥0∞) ≠ 0 := by rwa [Ne, ENNReal.coe_eq_zero] have B : AEStronglyMeasurable (fun _ : Ω => 𝔼[X]) ℙ := aestronglyMeasurable_const convert meas_ge_le_mul_pow_eLpNorm ℙ two_ne_zero ENNReal.two_ne_top (hX.sub B) A using 1 · congr simp only [Pi.sub_apply, ENNReal.coe_le_coe, ← Real.norm_eq_abs, ← coe_nnnorm, NNReal.coe_le_coe, ENNReal.ofReal_coe_nnreal] · rw [eLpNorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top] simp only [show ENNReal.ofNNReal (c ^ 2) = (ENNReal.ofNNReal c) ^ 2 by norm_cast, ENNReal.toReal_ofNat, one_div, Pi.sub_apply] rw [div_eq_mul_inv, ENNReal.inv_pow, mul_comm, ENNReal.rpow_two] congr simp_rw [← ENNReal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_two, ENNReal.rpow_one, evariance] /-- **Chebyshev's inequality**: one can control the deviation probability of a real random variable from its expectation in terms of the variance. -/ theorem meas_ge_le_variance_div_sq [@IsFiniteMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) {c : ℝ} (hc : 0 < c) : ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2) := by rw [ENNReal.ofReal_div_of_pos (sq_pos_of_ne_zero hc.ne.symm), hX.ofReal_variance_eq] convert @meas_ge_le_evariance_div_sq _ _ _ hX.1 c.toNNReal (by simp [hc]) using 1 · simp only [Real.coe_toNNReal', max_le_iff, abs_nonneg, and_true_iff] · rw [ENNReal.ofReal_pow hc.le] rfl -- Porting note: supplied `MeasurableSpace Ω` argument of `h` by unification /-- The variance of the sum of two independent random variables is the sum of the variances. -/ theorem IndepFun.variance_add [@IsProbabilityMeasure Ω _ ℙ] {X Y : Ω → ℝ} (hX : Memℒp X 2) (hY : Memℒp Y 2) (h : @IndepFun _ _ _ (_) _ _ X Y ℙ) : Var[X + Y] = Var[X] + Var[Y] := calc Var[X + Y] = 𝔼[fun a => X a ^ 2 + Y a ^ 2 + 2 * X a * Y a] - 𝔼[X + Y] ^ 2 := by simp [variance_def' (hX.add hY), add_sq'] _ = 𝔼[X ^ 2] + 𝔼[Y ^ 2] + (2 : ℝ) * 𝔼[X * Y] - (𝔼[X] + 𝔼[Y]) ^ 2 := by simp only [Pi.add_apply, Pi.pow_apply, Pi.mul_apply, mul_assoc] rw [integral_add, integral_add, integral_add, integral_mul_left] · exact hX.integrable one_le_two · exact hY.integrable one_le_two · exact hX.integrable_sq · exact hY.integrable_sq · exact hX.integrable_sq.add hY.integrable_sq · apply Integrable.const_mul exact h.integrable_mul (hX.integrable one_le_two) (hY.integrable one_le_two) _ = 𝔼[X ^ 2] + 𝔼[Y ^ 2] + 2 * (𝔼[X] * 𝔼[Y]) - (𝔼[X] + 𝔼[Y]) ^ 2 := by congr exact h.integral_mul_of_integrable (hX.integrable one_le_two) (hY.integrable one_le_two) _ = Var[X] + Var[Y] := by simp only [variance_def', hX, hY, Pi.pow_apply]; ring -- Porting note: supplied `MeasurableSpace Ω` argument of `hs`, `h` by unification /-- The variance of a finite sum of pairwise independent random variables is the sum of the variances. -/ theorem IndepFun.variance_sum [@IsProbabilityMeasure Ω _ ℙ] {ι : Type*} {X : ι → Ω → ℝ} {s : Finset ι} (hs : ∀ i ∈ s, @Memℒp _ _ _ (_) (X i) 2 ℙ) (h : Set.Pairwise ↑s fun i j => @IndepFun _ _ _ (_) _ _ (X i) (X j) ℙ) : Var[∑ i ∈ s, X i] = ∑ i ∈ s, Var[X i] := by classical induction' s using Finset.induction_on with k s ks IH · simp only [Finset.sum_empty, variance_zero] rw [variance_def' (memℒp_finset_sum' _ hs), sum_insert ks, sum_insert ks] simp only [add_sq'] calc 𝔼[X k ^ 2 + (∑ i ∈ s, X i) ^ 2 + 2 * X k * ∑ i ∈ s, X i] - 𝔼[X k + ∑ i ∈ s, X i] ^ 2 = 𝔼[X k ^ 2] + 𝔼[(∑ i ∈ s, X i) ^ 2] + 𝔼[2 * X k * ∑ i ∈ s, X i] - (𝔼[X k] + 𝔼[∑ i ∈ s, X i]) ^ 2 := by rw [integral_add', integral_add', integral_add'] · exact Memℒp.integrable one_le_two (hs _ (mem_insert_self _ _)) · apply integrable_finset_sum' _ fun i hi => ?_ exact Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi)) · exact Memℒp.integrable_sq (hs _ (mem_insert_self _ _)) · apply Memℒp.integrable_sq exact memℒp_finset_sum' _ fun i hi => hs _ (mem_insert_of_mem hi) · apply Integrable.add · exact Memℒp.integrable_sq (hs _ (mem_insert_self _ _)) · apply Memℒp.integrable_sq exact memℒp_finset_sum' _ fun i hi => hs _ (mem_insert_of_mem hi) · rw [mul_assoc] apply Integrable.const_mul _ (2 : ℝ) rw [mul_sum, sum_fn] apply integrable_finset_sum _ fun i hi => ?_ apply IndepFun.integrable_mul _ (Memℒp.integrable one_le_two (hs _ (mem_insert_self _ _))) (Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi))) apply h (mem_insert_self _ _) (mem_insert_of_mem hi) exact fun hki => ks (hki.symm ▸ hi) _ = Var[X k] + Var[∑ i ∈ s, X i] + (𝔼[2 * X k * ∑ i ∈ s, X i] - 2 * 𝔼[X k] * 𝔼[∑ i ∈ s, X i]) := by rw [variance_def' (hs _ (mem_insert_self _ _)), variance_def' (memℒp_finset_sum' _ fun i hi => hs _ (mem_insert_of_mem hi))] ring _ = Var[X k] + Var[∑ i ∈ s, X i] := by simp_rw [Pi.mul_apply, Pi.ofNat_apply, Nat.cast_ofNat, sum_apply, mul_sum, mul_assoc, add_right_eq_self] rw [integral_finset_sum s fun i hi => ?_]; swap · apply Integrable.const_mul _ (2 : ℝ) apply IndepFun.integrable_mul _ (Memℒp.integrable one_le_two (hs _ (mem_insert_self _ _))) (Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi))) apply h (mem_insert_self _ _) (mem_insert_of_mem hi) exact fun hki => ks (hki.symm ▸ hi) rw [integral_finset_sum s fun i hi => Memℒp.integrable one_le_two (hs _ (mem_insert_of_mem hi)), mul_sum, mul_sum, ← sum_sub_distrib] apply Finset.sum_eq_zero fun i hi => ?_ rw [integral_mul_left, IndepFun.integral_mul', sub_self] · apply h (mem_insert_self _ _) (mem_insert_of_mem hi) exact fun hki => ks (hki.symm ▸ hi) · exact Memℒp.aestronglyMeasurable (hs _ (mem_insert_self _ _)) · exact Memℒp.aestronglyMeasurable (hs _ (mem_insert_of_mem hi)) _ = Var[X k] + ∑ i ∈ s, Var[X i] := by rw [IH (fun i hi => hs i (mem_insert_of_mem hi)) (h.mono (by simp only [coe_insert, Set.subset_insert]))] end ProbabilityTheory
Probability\Distributions\Exponential.lean
/- Copyright (c) 2023 Claus Clausen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Claus Clausen, Patrick Massot -/ import Mathlib.Probability.Notation import Mathlib.Probability.CDF import Mathlib.Probability.Distributions.Gamma /-! # Exponential distributions over ℝ Define the Exponential measure over the reals. ## Main definitions * `exponentialPDFReal`: the function `r x ↦ r * exp (-(r * x)` for `0 ≤ x` or `0` else, which is the probability density function of a exponential distribution with rate `r` (when `hr : 0 < r`). * `exponentialPDF`: `ℝ≥0∞`-valued pdf, `exponentialPDF r = ENNReal.ofReal (exponentialPDFReal r)`. * `expMeasure`: an exponential measure on `ℝ`, parametrized by its rate `r`. * `exponentialCDFReal`: the CDF given by the definition of CDF in `ProbabilityTheory.CDF` applied to the exponential measure. ## Main results * `exponentialCDFReal_eq`: Proof that the `exponentialCDFReal` given by the definition equals the known function given as `r x ↦ 1 - exp (- (r * x))` for `0 ≤ x` or `0` else. -/ open scoped ENNReal NNReal open MeasureTheory Real Set Filter Topology namespace ProbabilityTheory section ExponentialPDF /-- The pdf of the exponential distribution depending on its rate -/ noncomputable def exponentialPDFReal (r x : ℝ) : ℝ := gammaPDFReal 1 r x /-- The pdf of the exponential distribution, as a function valued in `ℝ≥0∞` -/ noncomputable def exponentialPDF (r x : ℝ) : ℝ≥0∞ := ENNReal.ofReal (exponentialPDFReal r x) lemma exponentialPDF_eq (r x : ℝ) : exponentialPDF r x = ENNReal.ofReal (if 0 ≤ x then r * exp (-(r * x)) else 0) := by rw [exponentialPDF, exponentialPDFReal, gammaPDFReal] simp only [rpow_one, Gamma_one, div_one, sub_self, rpow_zero, mul_one] lemma exponentialPDF_of_neg {r x : ℝ} (hx : x < 0) : exponentialPDF r x = 0 := gammaPDF_of_neg hx lemma exponentialPDF_of_nonneg {r x : ℝ} (hx : 0 ≤ x) : exponentialPDF r x = ENNReal.ofReal (r * rexp (-(r * x))) := by simp only [exponentialPDF_eq, if_pos hx] /-- The Lebesgue integral of the exponential pdf over nonpositive reals equals 0-/ lemma lintegral_exponentialPDF_of_nonpos {x r : ℝ} (hx : x ≤ 0) : ∫⁻ y in Iio x, exponentialPDF r y = 0 := lintegral_gammaPDF_of_nonpos hx /-- The exponential pdf is measurable. -/ @[measurability] lemma measurable_exponentialPDFReal (r : ℝ) : Measurable (exponentialPDFReal r) := measurable_gammaPDFReal 1 r -- The exponential pdf is strongly measurable -/ @[measurability] lemma stronglyMeasurable_exponentialPDFReal (r : ℝ) : StronglyMeasurable (exponentialPDFReal r) := stronglyMeasurable_gammaPDFReal 1 r /-- The exponential pdf is positive for all positive reals -/ lemma exponentialPDFReal_pos {x r : ℝ} (hr : 0 < r) (hx : 0 < x) : 0 < exponentialPDFReal r x := gammaPDFReal_pos zero_lt_one hr hx /-- The exponential pdf is nonnegative-/ lemma exponentialPDFReal_nonneg {r : ℝ} (hr : 0 < r) (x : ℝ) : 0 ≤ exponentialPDFReal r x := gammaPDFReal_nonneg zero_lt_one hr x open Measure /-- The pdf of the exponential distribution integrates to 1 -/ @[simp] lemma lintegral_exponentialPDF_eq_one {r : ℝ} (hr : 0 < r) : ∫⁻ x, exponentialPDF r x = 1 := lintegral_gammaPDF_eq_one zero_lt_one hr end ExponentialPDF open MeasureTheory /-- Measure defined by the exponential distribution -/ noncomputable def expMeasure (r : ℝ) : Measure ℝ := gammaMeasure 1 r lemma isProbabilityMeasureExponential {r : ℝ} (hr : 0 < r) : IsProbabilityMeasure (expMeasure r) := isProbabilityMeasureGamma zero_lt_one hr section ExponentialCDF /-- CDF of the exponential distribution -/ noncomputable def exponentialCDFReal (r : ℝ) : StieltjesFunction := cdf (expMeasure r) lemma exponentialCDFReal_eq_integral {r : ℝ} (hr : 0 < r) (x : ℝ) : exponentialCDFReal r x = ∫ x in Iic x, exponentialPDFReal r x := gammaCDFReal_eq_integral zero_lt_one hr x lemma exponentialCDFReal_eq_lintegral {r : ℝ} (hr : 0 < r) (x : ℝ) : exponentialCDFReal r x = ENNReal.toReal (∫⁻ x in Iic x, exponentialPDF r x) := gammaCDFReal_eq_lintegral zero_lt_one hr x open Topology lemma hasDerivAt_neg_exp_mul_exp {r x : ℝ} : HasDerivAt (fun a ↦ -exp (-(r * a))) (r * exp (-(r * x))) x := by convert (((hasDerivAt_id x).const_mul (-r)).exp.const_mul (-1)) using 1 · simp only [one_mul, id_eq, neg_mul] simp only [id_eq, neg_mul, mul_one, mul_neg, one_mul, neg_neg, mul_comm] /-- A negative exponential function is integrable on intervals in `R≥0` -/ lemma exp_neg_integrableOn_Ioc {b x : ℝ} (hb : 0 < b) : IntegrableOn (fun x ↦ rexp (-(b * x))) (Ioc 0 x) := by simp only [neg_mul_eq_neg_mul] exact (exp_neg_integrableOn_Ioi _ hb).mono_set Ioc_subset_Ioi_self lemma lintegral_exponentialPDF_eq_antiDeriv {r : ℝ} (hr : 0 < r) (x : ℝ) : ∫⁻ y in Iic x, exponentialPDF r y = ENNReal.ofReal (if 0 ≤ x then 1 - exp (-(r * x)) else 0) := by split_ifs with h case neg => simp only [exponentialPDF_eq] rw [setLIntegral_congr_fun measurableSet_Iic, lintegral_zero, ENNReal.ofReal_zero] exact ae_of_all _ fun a (_ : a ≤ _) ↦ by rw [if_neg (by linarith), ENNReal.ofReal_eq_zero] case pos => rw [lintegral_Iic_eq_lintegral_Iio_add_Icc _ h, lintegral_exponentialPDF_of_nonpos (le_refl 0), zero_add] simp only [exponentialPDF_eq] rw [setLIntegral_congr_fun measurableSet_Icc (ae_of_all _ (by intro a ⟨(hle : _ ≤ a), _⟩; rw [if_pos hle]))] rw [← ENNReal.toReal_eq_toReal _ ENNReal.ofReal_ne_top, ← integral_eq_lintegral_of_nonneg_ae (eventually_of_forall fun _ ↦ le_of_lt (mul_pos hr (exp_pos _)))] · have : ∫ a in uIoc 0 x, r * rexp (-(r * a)) = ∫ a in (0)..x, r * rexp (-(r * a)) := by rw [intervalIntegral.intervalIntegral_eq_integral_uIoc, smul_eq_mul, if_pos h, one_mul] rw [integral_Icc_eq_integral_Ioc, ← uIoc_of_le h, this] rw [intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le h (f := fun a ↦ -1 * rexp (-(r * a))) _ _] · rw [ENNReal.toReal_ofReal_eq_iff.2 (by norm_num; positivity)] norm_num; ring · simp only [intervalIntegrable_iff, uIoc_of_le h] exact Integrable.const_mul (exp_neg_integrableOn_Ioc hr) _ · have : Continuous (fun a ↦ rexp (-(r * a))) := by simp only [← neg_mul]; exact (continuous_mul_left (-r)).rexp exact Continuous.continuousOn (Continuous.comp' (continuous_mul_left (-1)) this) · simp only [neg_mul, one_mul] exact fun _ _ ↦ HasDerivAt.hasDerivWithinAt hasDerivAt_neg_exp_mul_exp · apply Integrable.aestronglyMeasurable (Integrable.const_mul _ _) rw [← IntegrableOn, integrableOn_Icc_iff_integrableOn_Ioc] exact exp_neg_integrableOn_Ioc hr · refine ne_of_lt (IntegrableOn.setLIntegral_lt_top ?_) rw [integrableOn_Icc_iff_integrableOn_Ioc] exact Integrable.const_mul (exp_neg_integrableOn_Ioc hr) _ /-- The CDF of the exponential distribution equals ``1 - exp (-(r * x))``-/ lemma exponentialCDFReal_eq {r : ℝ} (hr : 0 < r) (x : ℝ) : exponentialCDFReal r x = if 0 ≤ x then 1 - exp (-(r * x)) else 0 := by rw [exponentialCDFReal_eq_lintegral hr, lintegral_exponentialPDF_eq_antiDeriv hr x, ENNReal.toReal_ofReal_eq_iff] split_ifs with h · simp only [sub_nonneg, exp_le_one_iff, Left.neg_nonpos_iff] exact mul_nonneg hr.le h · exact le_rfl end ExponentialCDF end ProbabilityTheory
Probability\Distributions\Gamma.lean
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Probability.Notation import Mathlib.Probability.CDF import Mathlib.Analysis.SpecialFunctions.Gamma.Basic /-! # Gamma distributions over ℝ Define the gamma measure over the reals. ## Main definitions * `gammaPDFReal`: the function `a r x ↦ r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x))` for `0 ≤ x` or `0` else, which is the probability density function of a gamma distribution with shape `a` and rate `r` (when `ha : 0 < a ` and `hr : 0 < r`). * `gammaPDF`: `ℝ≥0∞`-valued pdf, `gammaPDF a r = ENNReal.ofReal (gammaPDFReal a r)`. * `gammaMeasure`: a gamma measure on `ℝ`, parametrized by its shape `a` and rate `r`. * `gammaCDFReal`: the CDF given by the definition of CDF in `ProbabilityTheory.CDF` applied to the gamma measure. -/ open scoped ENNReal NNReal open MeasureTheory Real Set Filter Topology /-- A Lebesgue Integral from -∞ to y can be expressed as the sum of one from -∞ to 0 and 0 to x -/ lemma lintegral_Iic_eq_lintegral_Iio_add_Icc {y z : ℝ} (f : ℝ → ℝ≥0∞) (hzy : z ≤ y) : ∫⁻ x in Iic y, f x = (∫⁻ x in Iio z, f x) + ∫⁻ x in Icc z y, f x := by rw [← Iio_union_Icc_eq_Iic hzy, lintegral_union measurableSet_Icc] rw [Set.disjoint_iff] rintro x ⟨h1 : x < _, h2, _⟩ linarith namespace ProbabilityTheory section GammaPDF /-- The pdf of the gamma distribution depending on its scale and rate -/ noncomputable def gammaPDFReal (a r x : ℝ) : ℝ := if 0 ≤ x then r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x)) else 0 /-- The pdf of the gamma distribution, as a function valued in `ℝ≥0∞` -/ noncomputable def gammaPDF (a r x : ℝ) : ℝ≥0∞ := ENNReal.ofReal (gammaPDFReal a r x) lemma gammaPDF_eq (a r x : ℝ) : gammaPDF a r x = ENNReal.ofReal (if 0 ≤ x then r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x)) else 0) := rfl lemma gammaPDF_of_neg {a r x : ℝ} (hx : x < 0) : gammaPDF a r x = 0 := by simp only [gammaPDF_eq, if_neg (not_le.mpr hx), ENNReal.ofReal_zero] lemma gammaPDF_of_nonneg {a r x : ℝ} (hx : 0 ≤ x) : gammaPDF a r x = ENNReal.ofReal (r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x))) := by simp only [gammaPDF_eq, if_pos hx] /-- The Lebesgue integral of the gamma pdf over nonpositive reals equals 0 -/ lemma lintegral_gammaPDF_of_nonpos {x a r : ℝ} (hx : x ≤ 0) : ∫⁻ y in Iio x, gammaPDF a r y = 0 := by rw [setLIntegral_congr_fun (g := fun _ ↦ 0) measurableSet_Iio] · rw [lintegral_zero, ← ENNReal.ofReal_zero] · simp only [gammaPDF_eq, ENNReal.ofReal_eq_zero] filter_upwards with a (_ : a < _) rw [if_neg (by linarith)] /-- The gamma pdf is measurable. -/ @[measurability] lemma measurable_gammaPDFReal (a r : ℝ) : Measurable (gammaPDFReal a r) := Measurable.ite measurableSet_Ici (((measurable_id'.pow_const _).const_mul _).mul (measurable_id'.const_mul _).neg.exp) measurable_const /-- The gamma pdf is strongly measurable -/ @[measurability] lemma stronglyMeasurable_gammaPDFReal (a r : ℝ) : StronglyMeasurable (gammaPDFReal a r) := (measurable_gammaPDFReal a r).stronglyMeasurable /-- The gamma pdf is positive for all positive reals -/ lemma gammaPDFReal_pos {x a r : ℝ} (ha : 0 < a) (hr : 0 < r) (hx : 0 < x) : 0 < gammaPDFReal a r x := by simp only [gammaPDFReal, if_pos hx.le] positivity /-- The gamma pdf is nonnegative -/ lemma gammaPDFReal_nonneg {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) : 0 ≤ gammaPDFReal a r x := by unfold gammaPDFReal split_ifs <;> positivity open Measure /-- The pdf of the gamma distribution integrates to 1 -/ @[simp] lemma lintegral_gammaPDF_eq_one {a r : ℝ} (ha : 0 < a) (hr : 0 < r) : ∫⁻ x, gammaPDF a r x = 1 := by have leftSide : ∫⁻ x in Iio 0, gammaPDF a r x = 0 := by rw [setLIntegral_congr_fun measurableSet_Iio (ae_of_all _ (fun x (hx : x < 0) ↦ gammaPDF_of_neg hx)), lintegral_zero] have rightSide : ∫⁻ x in Ici 0, gammaPDF a r x = ∫⁻ x in Ici 0, ENNReal.ofReal (r ^ a / Gamma a * x ^ (a - 1) * exp (-(r * x))) := setLIntegral_congr_fun measurableSet_Ici (ae_of_all _ (fun _ ↦ gammaPDF_of_nonneg)) rw [← ENNReal.toReal_eq_one_iff, ← lintegral_add_compl _ measurableSet_Ici, compl_Ici, leftSide, rightSide, add_zero, ← integral_eq_lintegral_of_nonneg_ae] · simp_rw [integral_Ici_eq_integral_Ioi, mul_assoc] rw [integral_mul_left, integral_rpow_mul_exp_neg_mul_Ioi ha hr, div_mul_eq_mul_div, ← mul_assoc, mul_div_assoc, div_self (Gamma_pos_of_pos ha).ne', mul_one, div_rpow zero_le_one hr.le, one_rpow, mul_one_div, div_self (rpow_pos_of_pos hr _).ne'] · rw [EventuallyLE, ae_restrict_iff' measurableSet_Ici] exact ae_of_all _ (fun x (hx : 0 ≤ x) ↦ by positivity) · apply (measurable_gammaPDFReal a r).aestronglyMeasurable.congr refine (ae_restrict_iff' measurableSet_Ici).mpr <| ae_of_all _ fun x (hx : 0 ≤ x) ↦ ?_ simp_rw [gammaPDFReal, eq_true_intro hx, ite_true] end GammaPDF open MeasureTheory /-- Measure defined by the gamma distribution -/ noncomputable def gammaMeasure (a r : ℝ) : Measure ℝ := volume.withDensity (gammaPDF a r) lemma isProbabilityMeasureGamma {a r : ℝ} (ha : 0 < a) (hr : 0 < r) : IsProbabilityMeasure (gammaMeasure a r) where measure_univ := by simp [gammaMeasure, lintegral_gammaPDF_eq_one ha hr] section GammaCDF /-- CDF of the gamma distribution -/ noncomputable def gammaCDFReal (a r : ℝ) : StieltjesFunction := cdf (gammaMeasure a r) lemma gammaCDFReal_eq_integral {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) : gammaCDFReal a r x = ∫ x in Iic x, gammaPDFReal a r x := by have : IsProbabilityMeasure (gammaMeasure a r) := isProbabilityMeasureGamma ha hr rw [gammaCDFReal, cdf_eq_toReal, gammaMeasure, withDensity_apply _ measurableSet_Iic] refine (integral_eq_lintegral_of_nonneg_ae ?_ ?_).symm · exact ae_of_all _ fun b ↦ by simp only [Pi.zero_apply, gammaPDFReal_nonneg ha hr] · exact (measurable_gammaPDFReal a r).aestronglyMeasurable.restrict lemma gammaCDFReal_eq_lintegral {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) : gammaCDFReal a r x = ENNReal.toReal (∫⁻ x in Iic x, gammaPDF a r x) := by have : IsProbabilityMeasure (gammaMeasure a r) := isProbabilityMeasureGamma ha hr simp only [gammaPDF, gammaCDFReal, cdf_eq_toReal] simp only [gammaMeasure, measurableSet_Iic, withDensity_apply, gammaPDF] end GammaCDF end ProbabilityTheory
Probability\Distributions\Gaussian.lean
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lorenzo Luccioli, Rémy Degenne, Alexander Bentkamp -/ import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral import Mathlib.Probability.Notation import Mathlib.MeasureTheory.Decomposition.Lebesgue /-! # Gaussian distributions over ℝ We define a Gaussian measure over the reals. ## Main definitions * `gaussianPDFReal`: the function `μ v x ↦ (1 / (sqrt (2 * pi * v))) * exp (- (x - μ)^2 / (2 * v))`, which is the probability density function of a Gaussian distribution with mean `μ` and variance `v` (when `v ≠ 0`). * `gaussianPDF`: `ℝ≥0∞`-valued pdf, `gaussianPDF μ v x = ENNReal.ofReal (gaussianPDFReal μ v x)`. * `gaussianReal`: a Gaussian measure on `ℝ`, parametrized by its mean `μ` and variance `v`. If `v = 0`, this is `dirac μ`, otherwise it is defined as the measure with density `gaussianPDF μ v` with respect to the Lebesgue measure. ## Main results * `gaussianReal_add_const`: if `X` is a random variable with Gaussian distribution with mean `μ` and variance `v`, then `X + y` is Gaussian with mean `μ + y` and variance `v`. * `gaussianReal_const_mul`: if `X` is a random variable with Gaussian distribution with mean `μ` and variance `v`, then `c * X` is Gaussian with mean `c * μ` and variance `c^2 * v`. -/ open scoped ENNReal NNReal Real open MeasureTheory namespace ProbabilityTheory section GaussianPDF /-- Probability density function of the gaussian distribution with mean `μ` and variance `v`. -/ noncomputable def gaussianPDFReal (μ : ℝ) (v : ℝ≥0) (x : ℝ) : ℝ := (√(2 * π * v))⁻¹ * rexp (- (x - μ)^2 / (2 * v)) lemma gaussianPDFReal_def (μ : ℝ) (v : ℝ≥0) : gaussianPDFReal μ v = fun x ↦ (Real.sqrt (2 * π * v))⁻¹ * rexp (- (x - μ)^2 / (2 * v)) := rfl @[simp] lemma gaussianPDFReal_zero_var (m : ℝ) : gaussianPDFReal m 0 = 0 := by ext1 x simp [gaussianPDFReal] /-- The gaussian pdf is positive when the variance is not zero. -/ lemma gaussianPDFReal_pos (μ : ℝ) (v : ℝ≥0) (x : ℝ) (hv : v ≠ 0) : 0 < gaussianPDFReal μ v x := by rw [gaussianPDFReal] positivity /-- The gaussian pdf is nonnegative. -/ lemma gaussianPDFReal_nonneg (μ : ℝ) (v : ℝ≥0) (x : ℝ) : 0 ≤ gaussianPDFReal μ v x := by rw [gaussianPDFReal] positivity /-- The gaussian pdf is measurable. -/ lemma measurable_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) : Measurable (gaussianPDFReal μ v) := (((measurable_id.add_const _).pow_const _).neg.div_const _).exp.const_mul _ /-- The gaussian pdf is strongly measurable. -/ lemma stronglyMeasurable_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) : StronglyMeasurable (gaussianPDFReal μ v) := (measurable_gaussianPDFReal μ v).stronglyMeasurable lemma integrable_gaussianPDFReal (μ : ℝ) (v : ℝ≥0) : Integrable (gaussianPDFReal μ v) := by rw [gaussianPDFReal_def] by_cases hv : v = 0 · simp [hv] let g : ℝ → ℝ := fun x ↦ (√(2 * π * v))⁻¹ * rexp (- x ^ 2 / (2 * v)) have hg : Integrable g := by suffices g = fun x ↦ (√(2 * π * v))⁻¹ * rexp (- (2 * v)⁻¹ * x ^ 2) by rw [this] refine (integrable_exp_neg_mul_sq ?_).const_mul (√(2 * π * v))⁻¹ simp [lt_of_le_of_ne (zero_le _) (Ne.symm hv)] ext x simp only [g, zero_lt_two, mul_nonneg_iff_of_pos_left, NNReal.zero_le_coe, Real.sqrt_mul', mul_inv_rev, NNReal.coe_mul, NNReal.coe_inv, NNReal.coe_ofNat, neg_mul, mul_eq_mul_left_iff, Real.exp_eq_exp, mul_eq_zero, inv_eq_zero, Real.sqrt_eq_zero, NNReal.coe_eq_zero, hv, false_or] rw [mul_comm] left field_simp exact Integrable.comp_sub_right hg μ /-- The gaussian distribution pdf integrates to 1 when the variance is not zero. -/ lemma lintegral_gaussianPDFReal_eq_one (μ : ℝ) {v : ℝ≥0} (h : v ≠ 0) : ∫⁻ x, ENNReal.ofReal (gaussianPDFReal μ v x) = 1 := by rw [← ENNReal.toReal_eq_one_iff] have hfm : AEStronglyMeasurable (gaussianPDFReal μ v) volume := (stronglyMeasurable_gaussianPDFReal μ v).aestronglyMeasurable have hf : 0 ≤ₐₛ gaussianPDFReal μ v := ae_of_all _ (gaussianPDFReal_nonneg μ v) rw [← integral_eq_lintegral_of_nonneg_ae hf hfm] simp only [gaussianPDFReal, zero_lt_two, mul_nonneg_iff_of_pos_right, one_div, Nat.cast_ofNat, integral_mul_left] rw [integral_sub_right_eq_self (μ := volume) (fun a ↦ rexp (-a ^ 2 / ((2 : ℝ) * v))) μ] simp only [zero_lt_two, mul_nonneg_iff_of_pos_right, div_eq_inv_mul, mul_inv_rev, mul_neg] simp_rw [← neg_mul] rw [neg_mul, integral_gaussian, ← Real.sqrt_inv, ← Real.sqrt_mul] · field_simp ring · positivity /-- The gaussian distribution pdf integrates to 1 when the variance is not zero. -/ lemma integral_gaussianPDFReal_eq_one (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) : ∫ x, gaussianPDFReal μ v x = 1 := by have h := lintegral_gaussianPDFReal_eq_one μ hv rw [← ofReal_integral_eq_lintegral_ofReal (integrable_gaussianPDFReal _ _) (ae_of_all _ (gaussianPDFReal_nonneg _ _)), ← ENNReal.ofReal_one] at h rwa [← ENNReal.ofReal_eq_ofReal_iff (integral_nonneg (gaussianPDFReal_nonneg _ _)) zero_le_one] lemma gaussianPDFReal_sub {μ : ℝ} {v : ℝ≥0} (x y : ℝ) : gaussianPDFReal μ v (x - y) = gaussianPDFReal (μ + y) v x := by simp only [gaussianPDFReal] rw [sub_add_eq_sub_sub_swap] lemma gaussianPDFReal_add {μ : ℝ} {v : ℝ≥0} (x y : ℝ) : gaussianPDFReal μ v (x + y) = gaussianPDFReal (μ - y) v x := by rw [sub_eq_add_neg, ← gaussianPDFReal_sub, sub_eq_add_neg, neg_neg] lemma gaussianPDFReal_inv_mul {μ : ℝ} {v : ℝ≥0} {c : ℝ} (hc : c ≠ 0) (x : ℝ) : gaussianPDFReal μ v (c⁻¹ * x) = |c| * gaussianPDFReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) x := by simp only [gaussianPDFReal.eq_1, zero_lt_two, mul_nonneg_iff_of_pos_left, NNReal.zero_le_coe, Real.sqrt_mul', one_div, mul_inv_rev, NNReal.coe_mul, NNReal.coe_mk, NNReal.coe_pos] rw [← mul_assoc] refine congr_arg₂ _ ?_ ?_ · field_simp rw [Real.sqrt_sq_eq_abs] ring_nf calc (Real.sqrt ↑v)⁻¹ * (Real.sqrt 2)⁻¹ * (Real.sqrt π)⁻¹ = (Real.sqrt ↑v)⁻¹ * (Real.sqrt 2)⁻¹ * (Real.sqrt π)⁻¹ * (|c| * |c|⁻¹) := by rw [mul_inv_cancel, mul_one] simp only [ne_eq, abs_eq_zero, hc, not_false_eq_true] _ = (Real.sqrt ↑v)⁻¹ * (Real.sqrt 2)⁻¹ * (Real.sqrt π)⁻¹ * |c| * |c|⁻¹ := by ring · congr 1 field_simp congr 1 ring lemma gaussianPDFReal_mul {μ : ℝ} {v : ℝ≥0} {c : ℝ} (hc : c ≠ 0) (x : ℝ) : gaussianPDFReal μ v (c * x) = |c⁻¹| * gaussianPDFReal (c⁻¹ * μ) (⟨(c^2)⁻¹, inv_nonneg.mpr (sq_nonneg _)⟩ * v) x := by conv_lhs => rw [← inv_inv c, gaussianPDFReal_inv_mul (inv_ne_zero hc)] simp /-- The pdf of a Gaussian distribution on ℝ with mean `μ` and variance `v`. -/ noncomputable def gaussianPDF (μ : ℝ) (v : ℝ≥0) (x : ℝ) : ℝ≥0∞ := ENNReal.ofReal (gaussianPDFReal μ v x) lemma gaussianPDF_def (μ : ℝ) (v : ℝ≥0) : gaussianPDF μ v = fun x ↦ ENNReal.ofReal (gaussianPDFReal μ v x) := rfl @[simp] lemma gaussianPDF_zero_var (μ : ℝ) : gaussianPDF μ 0 = 0 := by ext simp [gaussianPDF] lemma gaussianPDF_pos (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (x : ℝ) : 0 < gaussianPDF μ v x := by rw [gaussianPDF, ENNReal.ofReal_pos] exact gaussianPDFReal_pos _ _ _ hv @[measurability] lemma measurable_gaussianPDF (μ : ℝ) (v : ℝ≥0) : Measurable (gaussianPDF μ v) := (measurable_gaussianPDFReal _ _).ennreal_ofReal @[simp] lemma lintegral_gaussianPDF_eq_one (μ : ℝ) {v : ℝ≥0} (h : v ≠ 0) : ∫⁻ x, gaussianPDF μ v x = 1 := lintegral_gaussianPDFReal_eq_one μ h end GaussianPDF section GaussianReal /-- A Gaussian distribution on `ℝ` with mean `μ` and variance `v`. -/ noncomputable def gaussianReal (μ : ℝ) (v : ℝ≥0) : Measure ℝ := if v = 0 then Measure.dirac μ else volume.withDensity (gaussianPDF μ v) lemma gaussianReal_of_var_ne_zero (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) : gaussianReal μ v = volume.withDensity (gaussianPDF μ v) := if_neg hv @[simp] lemma gaussianReal_zero_var (μ : ℝ) : gaussianReal μ 0 = Measure.dirac μ := if_pos rfl instance instIsProbabilityMeasureGaussianReal (μ : ℝ) (v : ℝ≥0) : IsProbabilityMeasure (gaussianReal μ v) where measure_univ := by by_cases h : v = 0 <;> simp [gaussianReal_of_var_ne_zero, h] lemma gaussianReal_apply (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (s : Set ℝ) : gaussianReal μ v s = ∫⁻ x in s, gaussianPDF μ v x := by rw [gaussianReal_of_var_ne_zero _ hv, withDensity_apply' _ s] lemma gaussianReal_apply_eq_integral (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) (s : Set ℝ) : gaussianReal μ v s = ENNReal.ofReal (∫ x in s, gaussianPDFReal μ v x) := by rw [gaussianReal_apply _ hv s, ofReal_integral_eq_lintegral_ofReal] · rfl · exact (integrable_gaussianPDFReal _ _).restrict · exact ae_of_all _ (gaussianPDFReal_nonneg _ _) lemma gaussianReal_absolutelyContinuous (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) : gaussianReal μ v ≪ volume := by rw [gaussianReal_of_var_ne_zero _ hv] exact withDensity_absolutelyContinuous _ _ lemma gaussianReal_absolutelyContinuous' (μ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) : volume ≪ gaussianReal μ v := by rw [gaussianReal_of_var_ne_zero _ hv] refine withDensity_absolutelyContinuous' ?_ ?_ · exact (measurable_gaussianPDF _ _).aemeasurable · exact ae_of_all _ (fun _ ↦ (gaussianPDF_pos _ hv _).ne') lemma rnDeriv_gaussianReal (μ : ℝ) (v : ℝ≥0) : ∂(gaussianReal μ v)/∂volume =ₐₛ gaussianPDF μ v := by by_cases hv : v = 0 · simp only [hv, gaussianReal_zero_var, gaussianPDF_zero_var] refine (Measure.eq_rnDeriv measurable_zero (mutuallySingular_dirac μ volume) ?_).symm rw [withDensity_zero, add_zero] · rw [gaussianReal_of_var_ne_zero _ hv] exact Measure.rnDeriv_withDensity _ (measurable_gaussianPDF μ v) section Transformations variable {μ : ℝ} {v : ℝ≥0} lemma _root_.MeasurableEmbedding.gaussianReal_comap_apply (hv : v ≠ 0) {f : ℝ → ℝ} (hf : MeasurableEmbedding f) {f' : ℝ → ℝ} (h_deriv : ∀ x, HasDerivAt f (f' x) x) {s : Set ℝ} (hs : MeasurableSet s) : (gaussianReal μ v).comap f s = ENNReal.ofReal (∫ x in s, |f' x| * gaussianPDFReal μ v (f x)) := by rw [gaussianReal_of_var_ne_zero _ hv, gaussianPDF_def] exact hf.withDensity_ofReal_comap_apply_eq_integral_abs_deriv_mul' hs h_deriv (ae_of_all _ (gaussianPDFReal_nonneg _ _)) (integrable_gaussianPDFReal _ _) lemma _root_.MeasurableEquiv.gaussianReal_map_symm_apply (hv : v ≠ 0) (f : ℝ ≃ᵐ ℝ) {f' : ℝ → ℝ} (h_deriv : ∀ x, HasDerivAt f (f' x) x) {s : Set ℝ} (hs : MeasurableSet s) : (gaussianReal μ v).map f.symm s = ENNReal.ofReal (∫ x in s, |f' x| * gaussianPDFReal μ v (f x)) := by rw [gaussianReal_of_var_ne_zero _ hv, gaussianPDF_def] exact f.withDensity_ofReal_map_symm_apply_eq_integral_abs_deriv_mul' hs h_deriv (ae_of_all _ (gaussianPDFReal_nonneg _ _)) (integrable_gaussianPDFReal _ _) /-- The map of a Gaussian distribution by addition of a constant is a Gaussian. -/ lemma gaussianReal_map_add_const (y : ℝ) : (gaussianReal μ v).map (· + y) = gaussianReal (μ + y) v := by by_cases hv : v = 0 · simp only [hv, ne_eq, not_true, gaussianReal_zero_var] exact Measure.map_dirac (measurable_id'.add_const _) _ let e : ℝ ≃ᵐ ℝ := (Homeomorph.addRight y).symm.toMeasurableEquiv have he' : ∀ x, HasDerivAt e ((fun _ ↦ 1) x) x := fun _ ↦ (hasDerivAt_id _).sub_const y change (gaussianReal μ v).map e.symm = gaussianReal (μ + y) v ext s' hs' rw [MeasurableEquiv.gaussianReal_map_symm_apply hv e he' hs'] simp only [abs_neg, abs_one, MeasurableEquiv.coe_mk, Equiv.coe_fn_mk, one_mul, ne_eq] rw [gaussianReal_apply_eq_integral _ hv s'] simp [e, gaussianPDFReal_sub _ y, Homeomorph.addRight, ← sub_eq_add_neg] /-- The map of a Gaussian distribution by addition of a constant is a Gaussian. -/ lemma gaussianReal_map_const_add (y : ℝ) : (gaussianReal μ v).map (y + ·) = gaussianReal (μ + y) v := by simp_rw [add_comm y] exact gaussianReal_map_add_const y /-- The map of a Gaussian distribution by multiplication by a constant is a Gaussian. -/ lemma gaussianReal_map_const_mul (c : ℝ) : (gaussianReal μ v).map (c * ·) = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by by_cases hv : v = 0 · simp only [hv, mul_zero, ne_eq, not_true, gaussianReal_zero_var] exact Measure.map_dirac (measurable_id'.const_mul c) μ by_cases hc : c = 0 · simp only [hc, zero_mul, ne_eq, abs_zero, mul_eq_zero] rw [Measure.map_const] simp only [ne_eq, measure_univ, one_smul, mul_eq_zero] convert (gaussianReal_zero_var 0).symm simp only [ne_eq, zero_pow, mul_eq_zero, hv, or_false, not_false_eq_true] rfl let e : ℝ ≃ᵐ ℝ := (Homeomorph.mulLeft₀ c hc).symm.toMeasurableEquiv have he' : ∀ x, HasDerivAt e ((fun _ ↦ c⁻¹) x) x := by suffices ∀ x, HasDerivAt (fun x => c⁻¹ * x) (c⁻¹ * 1) x by rwa [mul_one] at this exact fun _ ↦ HasDerivAt.const_mul _ (hasDerivAt_id _) change (gaussianReal μ v).map e.symm = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) ext s' hs' rw [MeasurableEquiv.gaussianReal_map_symm_apply hv e he' hs', gaussianReal_apply_eq_integral _ _ s'] swap · simp only [ne_eq, mul_eq_zero, hv, or_false] rw [← NNReal.coe_inj] simp [hc] simp only [e, Homeomorph.mulLeft₀, Equiv.toFun_as_coe, Equiv.mulLeft₀_apply, Equiv.invFun_as_coe, Equiv.mulLeft₀_symm_apply, Homeomorph.toMeasurableEquiv_coe, Homeomorph.homeomorph_mk_coe_symm, Equiv.coe_fn_symm_mk, gaussianPDFReal_inv_mul hc] congr with x suffices |c⁻¹| * |c| = 1 by rw [← mul_assoc, this, one_mul] rw [abs_inv, inv_mul_cancel] rwa [ne_eq, abs_eq_zero] /-- The map of a Gaussian distribution by multiplication by a constant is a Gaussian. -/ lemma gaussianReal_map_mul_const (c : ℝ) : (gaussianReal μ v).map (· * c) = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by simp_rw [mul_comm _ c] exact gaussianReal_map_const_mul c variable {Ω : Type} [MeasureSpace Ω] /-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `X + y` has Gaussian law with mean `μ + y` and variance `v`. -/ lemma gaussianReal_add_const {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (y : ℝ) : Measure.map (fun ω ↦ X ω + y) ℙ = gaussianReal (μ + y) v := by have hXm : AEMeasurable X := aemeasurable_of_map_neZero (by rw [hX]; infer_instance) change Measure.map ((fun ω ↦ ω + y) ∘ X) ℙ = gaussianReal (μ + y) v rw [← AEMeasurable.map_map_of_aemeasurable (measurable_id'.add_const _).aemeasurable hXm, hX, gaussianReal_map_add_const y] /-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `y + X` has Gaussian law with mean `μ + y` and variance `v`. -/ lemma gaussianReal_const_add {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (y : ℝ) : Measure.map (fun ω ↦ y + X ω) ℙ = gaussianReal (μ + y) v := by simp_rw [add_comm y] exact gaussianReal_add_const hX y /-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `c * X` has Gaussian law with mean `c * μ` and variance `c^2 * v`. -/ lemma gaussianReal_const_mul {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (c : ℝ) : Measure.map (fun ω ↦ c * X ω) ℙ = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by have hXm : AEMeasurable X := aemeasurable_of_map_neZero (by rw [hX]; infer_instance) change Measure.map ((fun ω ↦ c * ω) ∘ X) ℙ = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) rw [← AEMeasurable.map_map_of_aemeasurable (measurable_id'.const_mul c).aemeasurable hXm, hX] exact gaussianReal_map_const_mul c /-- If `X` is a real random variable with Gaussian law with mean `μ` and variance `v`, then `X * c` has Gaussian law with mean `c * μ` and variance `c^2 * v`. -/ lemma gaussianReal_mul_const {X : Ω → ℝ} (hX : Measure.map X ℙ = gaussianReal μ v) (c : ℝ) : Measure.map (fun ω ↦ X ω * c) ℙ = gaussianReal (c * μ) (⟨c^2, sq_nonneg _⟩ * v) := by simp_rw [mul_comm _ c] exact gaussianReal_const_mul hX c end Transformations end GaussianReal end ProbabilityTheory
Probability\Distributions\Geometric.lean
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Probability.ProbabilityMassFunction.Basic import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Geometric distributions over ℕ Define the geometric measure over the natural numbers ## Main definitions * `geometricPMFReal`: the function `p n ↦ (1-p) ^ n * p` for `n ∈ ℕ`, which is the probability density function of a geometric distribution with success probability `p ∈ (0,1]`. * `geometricPMF`: `ℝ≥0∞`-valued pmf, `geometricPMF p = ENNReal.ofReal (geometricPMFReal p)`. * `geometricMeasure`: a geometric measure on `ℕ`, parametrized by its success probability `p`. -/ open scoped ENNReal NNReal open MeasureTheory Real Set Filter Topology namespace ProbabilityTheory variable {p : ℝ} section GeometricPMF /-- The pmf of the geometric distribution depending on its success probability. -/ noncomputable def geometricPMFReal (p : ℝ) (n : ℕ) : ℝ := (1-p) ^ n * p lemma geometricPMFRealSum (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : HasSum (fun n ↦ geometricPMFReal p n) 1 := by unfold geometricPMFReal have := hasSum_geometric_of_lt_one (sub_nonneg.mpr hp_le_one) (sub_lt_self 1 hp_pos) apply (hasSum_mul_right_iff (hp_pos.ne')).mpr at this simp only [sub_sub_cancel] at this rw [inv_mul_eq_div, div_self hp_pos.ne'] at this exact this /-- The geometric pmf is positive for all natural numbers -/ lemma geometricPMFReal_pos {n : ℕ} (hp_pos : 0 < p) (hp_lt_one : p < 1) : 0 < geometricPMFReal p n := by rw [geometricPMFReal] have : 0 < 1 - p := sub_pos.mpr hp_lt_one positivity lemma geometricPMFReal_nonneg {n : ℕ} (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : 0 ≤ geometricPMFReal p n := by rw [geometricPMFReal] have : 0 ≤ 1 - p := sub_nonneg.mpr hp_le_one positivity /-- Geometric distribution with success probability `p`. -/ noncomputable def geometricPMF (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : PMF ℕ := ⟨fun n ↦ ENNReal.ofReal (geometricPMFReal p n), by apply ENNReal.hasSum_coe.mpr rw [← toNNReal_one] exact (geometricPMFRealSum hp_pos hp_le_one).toNNReal (fun n ↦ geometricPMFReal_nonneg hp_pos hp_le_one)⟩ /-- The geometric pmf is measurable. -/ @[measurability] lemma measurable_geometricPMFReal : Measurable (geometricPMFReal p) := by measurability @[measurability] lemma stronglyMeasurable_geometricPMFReal : StronglyMeasurable (geometricPMFReal p) := stronglyMeasurable_iff_measurable.mpr measurable_geometricPMFReal end GeometricPMF /-- Measure defined by the geometric distribution -/ noncomputable def geometricMeasure (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : Measure ℕ := (geometricPMF hp_pos hp_le_one).toMeasure lemma isProbabilityMeasureGeometric (hp_pos : 0 < p) (hp_le_one : p ≤ 1) : IsProbabilityMeasure (geometricMeasure hp_pos hp_le_one) := PMF.toMeasure.isProbabilityMeasure (geometricPMF hp_pos hp_le_one) end ProbabilityTheory
Probability\Distributions\Poisson.lean
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Analysis.SpecialFunctions.Exponential import Mathlib.Probability.ProbabilityMassFunction.Basic import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Poisson distributions over ℕ Define the Poisson measure over the natural numbers ## Main definitions * `poissonPMFReal`: the function `fun n ↦ exp (- λ) * λ ^ n / n!` for `n ∈ ℕ`, which is the probability density function of a Poisson distribution with rate `λ > 0`. * `poissonPMF`: `ℝ≥0∞`-valued pdf, `poissonPMF λ = ENNReal.ofReal (poissonPMFReal λ)`. * `poissonMeasure`: a Poisson measure on `ℕ`, parametrized by its rate `λ`. -/ open scoped ENNReal NNReal Nat open MeasureTheory Real Set Filter Topology namespace ProbabilityTheory section PoissonPMF /-- The pmf of the Poisson distribution depending on its rate, as a function to ℝ -/ noncomputable def poissonPMFReal (r : ℝ≥0) (n : ℕ) : ℝ := exp (- r) * r ^ n / n ! lemma poissonPMFRealSum (r : ℝ≥0) : HasSum (fun n ↦ poissonPMFReal r n) 1 := by let r := r.toReal unfold poissonPMFReal apply (hasSum_mul_left_iff (exp_ne_zero r)).mp simp only [mul_one] have : (fun i ↦ rexp r * (rexp (-r) * r ^ i / ↑(Nat.factorial i))) = fun i ↦ r ^ i / ↑(Nat.factorial i) := by ext n rw [mul_div_assoc, exp_neg, ← mul_assoc, ← div_eq_mul_inv, div_self (exp_ne_zero r), one_mul] rw [this, exp_eq_exp_ℝ] exact NormedSpace.expSeries_div_hasSum_exp ℝ r /-- The Poisson pmf is positive for all natural numbers -/ lemma poissonPMFReal_pos {r : ℝ≥0} {n : ℕ} (hr : 0 < r) : 0 < poissonPMFReal r n := by rw [poissonPMFReal] positivity lemma poissonPMFReal_nonneg {r : ℝ≥0} {n : ℕ} : 0 ≤ poissonPMFReal r n := by unfold poissonPMFReal positivity /-- The pmf of the Poisson distribution depending on its rate, as a PMF. -/ noncomputable def poissonPMF (r : ℝ≥0) : PMF ℕ := by refine ⟨fun n ↦ ENNReal.ofReal (poissonPMFReal r n), ?_⟩ apply ENNReal.hasSum_coe.mpr rw [← toNNReal_one] exact (poissonPMFRealSum r).toNNReal (fun n ↦ poissonPMFReal_nonneg) /-- The Poisson pmf is measurable. -/ @[measurability] lemma measurable_poissonPMFReal (r : ℝ≥0) : Measurable (poissonPMFReal r) := by measurability @[measurability] lemma stronglyMeasurable_poissonPMFReal (r : ℝ≥0) : StronglyMeasurable (poissonPMFReal r) := stronglyMeasurable_iff_measurable.mpr (measurable_poissonPMFReal r) end PoissonPMF /-- Measure defined by the Poisson distribution -/ noncomputable def poissonMeasure (r : ℝ≥0) : Measure ℕ := (poissonPMF r).toMeasure instance isProbabilityMeasurePoisson (r : ℝ≥0) : IsProbabilityMeasure (poissonMeasure r) := PMF.toMeasure.isProbabilityMeasure (poissonPMF r) end ProbabilityTheory
Probability\Distributions\Uniform.lean
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker, Devon Tuma, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Density import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.ProbabilityMassFunction.Constructions /-! # Uniform distributions and probability mass functions This file defines two related notions of uniform distributions, which will be unified in the future. # Uniform distributions Defines the uniform distribution for any set with finite measure. ## Main definitions * `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the push-forward measure agrees with the rescaled restricted measure `μ`. # Uniform probability mass functions This file defines a number of uniform `PMF` distributions from various inputs, uniformly drawing from the corresponding object. ## Main definitions `PMF.uniformOfFinset` gives each element in the set equal probability, with `0` probability for elements not in the set. `PMF.uniformOfFintype` gives all elements equal probability, equal to the inverse of the size of the `Fintype`. `PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct. Each probability is given by the count of the element divided by the size of the `Multiset` ## TODO * Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`. -/ open scoped Classical MeasureTheory NNReal ENNReal -- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` locale :( open TopologicalSpace MeasureTheory.Measure PMF noncomputable section namespace MeasureTheory variable {E : Type*} [MeasurableSpace E] {m : Measure E} {μ : Measure E} namespace pdf variable {Ω : Type*} variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} /-- A random variable `X` has uniform distribution on `s` if its push-forward measure is `(μ s)⁻¹ • μ.restrict s`. -/ def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) := map X ℙ = ProbabilityTheory.cond μ s namespace IsUniform theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by dsimp [IsUniform, ProbabilityTheory.cond] at hu by_contra h rw [map_of_not_aemeasurable h] at hu apply zero_ne_one' ℝ≥0∞ calc 0 = (0 : Measure E) Set.univ := rfl _ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ, Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt] theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) : ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply', ENNReal.div_eq_inv_mul] theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ := ⟨by have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ, ENNReal.div_self hns hnt]⟩ theorem toMeasurable_iff {X : Ω → E} {s : Set E} : IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by unfold IsUniform rw [ProbabilityTheory.cond_toMeasurable_eq] protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : IsUniform X (toMeasurable μ s) ℙ μ := by unfold IsUniform at * rwa [ProbabilityTheory.cond_toMeasurable_eq] theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by let t := toMeasurable μ s apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (t.indicator ((μ t)⁻¹ • 1)) <| (measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s) rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one, withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable, ProbabilityTheory.cond] theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by rcases hμs with H|H · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H, smul_zero] at hu simp [pdf, hu] · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu simp [pdf, hu] theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by by_cases hnt : μ s = ∞ · simp [pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inr hnt), hnt] by_cases hns : μ s = 0 · filter_upwards [measure_zero_iff_ae_nmem.mp hns, pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inl hns)] with x hx h'x simp [hx, h'x, hns] have : HasPDF X ℙ μ := hasPDF hns hnt hu have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu apply (eq_of_map_eq_withDensity _ _).mp · rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one, ProbabilityTheory.cond] · exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hX : IsUniform X s ℙ μ) : (fun x => (pdf X ℙ μ x).toReal) =ᵐ[μ] fun x => (s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x).toReal := Filter.EventuallyEq.fun_comp (pdf_eq hms hX) ENNReal.toReal variable {X : Ω → ℝ} {s : Set ℝ} theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) : Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by by_cases hnt : volume s = 0 ∨ volume s = ∞ · have I : Integrable (fun x ↦ x * ENNReal.toReal (0)) := by simp apply I.congr filter_upwards [pdf_eq_zero_of_measure_eq_zero_or_top huX hnt] with x hx simp [hx] simp only [not_or] at hnt have : IsProbabilityMeasure ℙ := isProbabilityMeasure hnt.1 hnt.2 huX constructor · exact aestronglyMeasurable_id.mul (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable refine hasFiniteIntegral_mul (pdf_eq hcs.measurableSet huX) ?_ set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞) have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x => (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm simp only [ind, this, lintegral_indicator _ hcs.measurableSet, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply, Pi.smul_apply] rw [lintegral_mul_const _ measurable_nnnorm.coe_nnreal_ennreal] exact (ENNReal.mul_lt_top (setLIntegral_lt_top_of_isCompact hnt.2 hcs continuous_nnnorm).ne (ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hnt.1)).ne).ne /-- A real uniform random variable `X` with support `s` has expectation `(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/ theorem integral_eq (huX : IsUniform X s ℙ) : ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by rw [← smul_eq_mul, ← integral_smul_measure] dsimp only [IsUniform, ProbabilityTheory.cond] at huX rw [← huX] by_cases hX : AEMeasurable X ℙ · exact (integral_map hX aestronglyMeasurable_id).symm · rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable] rwa [aestronglyMeasurable_iff_aemeasurable] end IsUniform variable {X : Ω → E} lemma IsUniform.cond {s : Set E} : IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by unfold IsUniform rw [Measure.map_id] /-- The density of the uniform measure on a set with respect to itself. This allows us to abstract away the choice of random variable and probability space. -/ def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0∞ := s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x /-- Check that indeed any uniform random variable has the uniformPDF. -/ lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) : (fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by unfold uniformPDF exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _) /-- Alternative way of writing the uniformPDF. -/ lemma uniformPDF_ite {s : Set E} {x : E} : uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by unfold uniformPDF unfold Set.indicator simp only [Pi.smul_apply, Pi.one_apply, smul_eq_mul, mul_one] end pdf end MeasureTheory namespace PMF variable {α β γ : Type*} open scoped Classical NNReal ENNReal section UniformOfFinset /-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/ def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by refine ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s ?_ ?_ · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul] have : (s.card : ℝ≥0∞) ≠ 0 := by simpa only [Ne, Nat.cast_eq_zero, Finset.card_eq_zero] using Finset.nonempty_iff_ne_empty.1 hs exact ENNReal.mul_inv_cancel this <| ENNReal.natCast_ne_top s.card · exact fun x hx => by simp only [hx, if_false] variable {s : Finset α} (hs : s.Nonempty) {a : α} @[simp] theorem uniformOfFinset_apply (a : α) : uniformOfFinset s hs a = if a ∈ s then (s.card : ℝ≥0∞)⁻¹ else 0 := rfl theorem uniformOfFinset_apply_of_mem (ha : a ∈ s) : uniformOfFinset s hs a = (s.card : ℝ≥0∞)⁻¹ := by simp [ha] theorem uniformOfFinset_apply_of_not_mem (ha : a ∉ s) : uniformOfFinset s hs a = 0 := by simp [ha] @[simp] theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s := Set.ext (by let ⟨a, ha⟩ := hs simp [mem_support_iff, Finset.ne_empty_of_mem ha]) theorem mem_support_uniformOfFinset_iff (a : α) : a ∈ (uniformOfFinset s hs).support ↔ a ∈ s := by simp section Measure variable (t : Set α) @[simp] theorem toOuterMeasure_uniformOfFinset_apply : (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card := calc (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 := toOuterMeasure_apply (uniformOfFinset s hs) t _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 := (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm]) _ = ∑ x ∈ s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 := (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h)) _ = ∑ _x ∈ s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ := (Finset.sum_congr rfl fun x hx => by let this : x ∈ s ∧ x ∈ t := by simpa using hx simp only [this, and_self_iff, if_true]) _ = (s.filter (· ∈ t)).card / s.card := by simp only [div_eq_mul_inv, Finset.sum_const, nsmul_eq_mul] @[simp] theorem toMeasure_uniformOfFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) : (uniformOfFinset s hs).toMeasure t = (s.filter (· ∈ t)).card / s.card := (toMeasure_apply_eq_toOuterMeasure_apply _ t ht).trans (toOuterMeasure_uniformOfFinset_apply hs t) end Measure end UniformOfFinset section UniformOfFintype /-- The uniform pmf taking the same uniform value on all of the fintype `α` -/ def uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : PMF α := uniformOfFinset Finset.univ Finset.univ_nonempty variable [Fintype α] [Nonempty α] @[simp] theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by simp [uniformOfFintype, Finset.mem_univ, if_true, uniformOfFinset_apply] @[simp] theorem support_uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : (uniformOfFintype α).support = ⊤ := Set.ext fun x => by simp [mem_support_iff] theorem mem_support_uniformOfFintype (a : α) : a ∈ (uniformOfFintype α).support := by simp section Measure variable (s : Set α) theorem toOuterMeasure_uniformOfFintype_apply : (uniformOfFintype α).toOuterMeasure s = Fintype.card s / Fintype.card α := by rw [uniformOfFintype, toOuterMeasure_uniformOfFinset_apply,Fintype.card_ofFinset] rfl theorem toMeasure_uniformOfFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) : (uniformOfFintype α).toMeasure s = Fintype.card s / Fintype.card α := by simp [uniformOfFintype, hs] end Measure end UniformOfFintype section OfMultiset /-- Given a non-empty multiset `s` we construct the `PMF` which sends `a` to the fraction of elements in `s` that are `a`. -/ def ofMultiset (s : Multiset α) (hs : s ≠ 0) : PMF α := ⟨fun a => s.count a / (Multiset.card s), ENNReal.summable.hasSum_iff.2 (calc (∑' b : α, (s.count b : ℝ≥0∞) / (Multiset.card s)) = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑' b, (s.count b : ℝ≥0∞) := by simp_rw [ENNReal.div_eq_inv_mul, ENNReal.tsum_mul_left] _ = (Multiset.card s : ℝ≥0∞)⁻¹ * ∑ b ∈ s.toFinset, (s.count b : ℝ≥0∞) := (congr_arg (fun x => (Multiset.card s : ℝ≥0∞)⁻¹ * x) (tsum_eq_sum fun a ha => Nat.cast_eq_zero.2 <| by rwa [Multiset.count_eq_zero, ← Multiset.mem_toFinset])) _ = 1 := by rw [← Nat.cast_sum, Multiset.toFinset_sum_count_eq s, ENNReal.inv_mul_cancel (Nat.cast_ne_zero.2 (hs ∘ Multiset.card_eq_zero.1)) (ENNReal.natCast_ne_top _)] )⟩ variable {s : Multiset α} (hs : s ≠ 0) @[simp] theorem ofMultiset_apply (a : α) : ofMultiset s hs a = s.count a / (Multiset.card s) := rfl @[simp] theorem support_ofMultiset : (ofMultiset s hs).support = s.toFinset := Set.ext (by simp [mem_support_iff, hs]) theorem mem_support_ofMultiset_iff (a : α) : a ∈ (ofMultiset s hs).support ↔ a ∈ s.toFinset := by simp theorem ofMultiset_apply_of_not_mem {a : α} (ha : a ∉ s) : ofMultiset s hs a = 0 := by simpa only [ofMultiset_apply, ENNReal.div_eq_zero_iff, Nat.cast_eq_zero, Multiset.count_eq_zero, ENNReal.natCast_ne_top, or_false_iff] using ha section Measure variable (t : Set α) @[simp] theorem toOuterMeasure_ofMultiset_apply : (ofMultiset s hs).toOuterMeasure t = (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := by simp_rw [div_eq_mul_inv, ← ENNReal.tsum_mul_right, toOuterMeasure_apply] refine tsum_congr fun x => ?_ by_cases hx : x ∈ t <;> simp [Set.indicator, hx, div_eq_mul_inv] @[simp] theorem toMeasure_ofMultiset_apply [MeasurableSpace α] (ht : MeasurableSet t) : (ofMultiset s hs).toMeasure t = (∑' x, (s.filter (· ∈ t)).count x : ℝ≥0∞) / (Multiset.card s) := (toMeasure_apply_eq_toOuterMeasure_apply _ t ht).trans (toOuterMeasure_ofMultiset_apply hs t) end Measure end OfMultiset end PMF
Probability\Independence\Basic.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.Probability.Independence.Kernel /-! # Independence of sets of sets and measure spaces (σ-algebras) * A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. It will be used for families of π-systems. * A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. I.e., `m : ι → MeasurableSpace Ω` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. * Independence of sets (or events in probabilistic parlance) is defined as independence of the measurable space structures they generate: a set `s` generates the measurable space structure with measurable sets `∅, s, sᶜ, univ`. * Independence of functions (or random variables) is also defined as independence of the measurable space structures they generate: a function `f` for which we have a measurable space `m` on the codomain generates `MeasurableSpace.comap f m`. ## Main statements * `iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `IndepSets.indep`: variant with two π-systems. ## Implementation notes The definitions of independence in this file are a particular case of independence with respect to a kernel and a measure, as defined in the file `Kernel.lean`. We provide four definitions of independence: * `iIndepSets`: independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to be used with π-systems. * `iIndep`: independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`, * `iIndepSet`: independence of a family of sets `s : ι → Set Ω`, * `iIndepFun`: independence of a family of functions. For measurable spaces `m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`. Additionally, we provide four corresponding statements for two measurable space structures (resp. sets of sets, sets, functions) instead of a family. These properties are denoted by the same names as for a family, but without the starting `i`, for example `IndepFun` is the version of `iIndepFun` for two functions. The definition of independence for `iIndepSets` uses finite sets (`Finset`). See `ProbabilityTheory.Kernel.iIndepSets`. An alternative and equivalent way of defining independence would have been to use countable sets. Most of the definitions and lemmas in this file list all variables instead of using the `variable` keyword at the beginning of a section, for example `lemma Indep.symm {Ω} {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : measure Ω} ...` . This is intentional, to be able to control the order of the `MeasurableSpace` variables. Indeed when defining `μ` in the example above, the measurable space used is the last one defined, here `{_mΩ : MeasurableSpace Ω}`, and not `m₁` or `m₂`. ## References * Williams, David. Probability with martingales. Cambridge university press, 1991. Part A, Chapter 4. -/ open MeasureTheory MeasurableSpace Set open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {Ω ι β γ : Type*} {κ : ι → Type*} section Definitions /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i) `. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepSets π (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets `t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepSets s1 s2 (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. `m : ι → MeasurableSpace Ω` is independent with respect to measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndep m (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop := Kernel.Indep m₁ m₂ (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepSet s (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepSet s t (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepFun m f (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [MeasurableSpace β] [MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepFun f g (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) end Definitions section Definition_lemmas variable {π : ι → Set (Set Ω)} {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω} {S : Finset ι} {s : ι → Set Ω} lemma iIndepSets_iff (π : ι → Set (Set Ω)) (μ : Measure Ω) : iIndepSets π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp only [iIndepSets, Kernel.iIndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] lemma iIndepSets.meas_biInter (h : iIndepSets π μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := (iIndepSets_iff _ _).1 h s hf lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π μ) (hs : ∀ i, s i ∈ π i) : μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← h.meas_biInter _ fun _i _ ↦ hs _] lemma IndepSets_iff (s1 s2 : Set (Set Ω)) (μ : Measure Ω) : IndepSets s1 s2 μ ↔ ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (μ (t1 ∩ t2) = μ t1 * μ t2) := by simp only [IndepSets, Kernel.IndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] lemma iIndep_iff_iIndepSets (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : iIndep m μ ↔ iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := by simp only [iIndep, iIndepSets, Kernel.iIndep] lemma iIndep.iIndepSets' {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω} (hμ : iIndep m μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := (iIndep_iff_iIndepSets _ _).1 hμ lemma iIndep_iff (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : iIndep m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)), μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp only [iIndep_iff_iIndepSets, iIndepSets_iff]; rfl lemma iIndep.meas_biInter (hμ : iIndep m μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := (iIndep_iff _ _).1 hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (hμ : iIndep m μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← hμ.meas_biInter fun _ _ ↦ hs _] lemma Indep_iff_IndepSets (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : Indep m₁ m₂ μ ↔ IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by simp only [Indep, IndepSets, Kernel.Indep] lemma Indep_iff (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : Indep m₁ m₂ μ ↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by rw [Indep_iff_IndepSets, IndepSets_iff]; rfl lemma iIndepSet_iff_iIndep (s : ι → Set Ω) (μ : Measure Ω) : iIndepSet s μ ↔ iIndep (fun i ↦ generateFrom {s i}) μ := by simp only [iIndepSet, iIndep, Kernel.iIndepSet] lemma iIndepSet_iff (s : ι → Set Ω) (μ : Measure Ω) : iIndepSet s μ ↔ ∀ (s' : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s' → MeasurableSet[generateFrom {s i}] (f i)), μ (⋂ i ∈ s', f i) = ∏ i ∈ s', μ (f i) := by simp only [iIndepSet_iff_iIndep, iIndep_iff] lemma IndepSet_iff_Indep (s t : Set Ω) (μ : Measure Ω) : IndepSet s t μ ↔ Indep (generateFrom {s}) (generateFrom {t}) μ := by simp only [IndepSet, Indep, Kernel.IndepSet] lemma IndepSet_iff (s t : Set Ω) (μ : Measure Ω) : IndepSet s t μ ↔ ∀ t1 t2, MeasurableSet[generateFrom {s}] t1 → MeasurableSet[generateFrom {t}] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by simp only [IndepSet_iff_Indep, Indep_iff] lemma iIndepFun_iff_iIndep {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) : iIndepFun m f μ ↔ iIndep (fun x ↦ (m x).comap (f x)) μ := by simp only [iIndepFun, iIndep, Kernel.iIndepFun] protected lemma iIndepFun.iIndep {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun m f μ) : iIndep (fun x ↦ (m x).comap (f x)) μ := hf lemma iIndepFun_iff {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) : iIndepFun m f μ ↔ ∀ (s : Finset ι) {f' : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (f' i)), μ (⋂ i ∈ s, f' i) = ∏ i ∈ s, μ (f' i) := by simp only [iIndepFun_iff_iIndep, iIndep_iff] lemma iIndepFun.meas_biInter {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun m f μ) (hs : ∀ i, i ∈ S → MeasurableSet[(m i).comap (f i)] (s i)) : μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun m f μ) (hs : ∀ i, MeasurableSet[(m i).comap (f i)] (s i)) : μ (⋂ i, s i) = ∏ i, μ (s i) := hf.iIndep.meas_iInter hs lemma IndepFun_iff_Indep [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) : IndepFun f g μ ↔ Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) μ := by simp only [IndepFun, Indep, Kernel.IndepFun] lemma IndepFun_iff {β γ} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) : IndepFun f g μ ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1 → MeasurableSet[MeasurableSpace.comap g mγ] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by rw [IndepFun_iff_Indep, Indep_iff] lemma IndepFun.meas_inter [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : μ (s ∩ t) = μ s * μ t := (IndepFun_iff _ _ _).1 hfg _ _ hs ht end Definition_lemmas section Indep variable {m₁ m₂ m₃ : MeasurableSpace Ω} (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} @[symm] theorem IndepSets.symm {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ μ) : IndepSets s₂ s₁ μ := Kernel.IndepSets.symm h @[symm] theorem Indep.symm (h : Indep m₁ m₂ μ) : Indep m₂ m₁ μ := IndepSets.symm h theorem indep_bot_right [IsProbabilityMeasure μ] : Indep m' ⊥ μ := Kernel.indep_bot_right m' theorem indep_bot_left [IsProbabilityMeasure μ] : Indep ⊥ m' μ := (indep_bot_right m').symm theorem indepSet_empty_right [IsProbabilityMeasure μ] (s : Set Ω) : IndepSet s ∅ μ := Kernel.indepSet_empty_right s theorem indepSet_empty_left [IsProbabilityMeasure μ] (s : Set Ω) : IndepSet ∅ s μ := Kernel.indepSet_empty_left s theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : IndepSets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ μ := Kernel.indepSets_of_indepSets_of_le_left h_indep h31 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : IndepSets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ μ := Kernel.indepSets_of_indepSets_of_le_right h_indep h32 theorem indep_of_indep_of_le_left (h_indep : Indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ μ := Kernel.indep_of_indep_of_le_left h_indep h31 theorem indep_of_indep_of_le_right (h_indep : Indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ μ := Kernel.indep_of_indep_of_le_right h_indep h32 theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} (h₁ : IndepSets s₁ s' μ) (h₂ : IndepSets s₂ s' μ) : IndepSets (s₁ ∪ s₂) s' μ := Kernel.IndepSets.union h₁ h₂ @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} : IndepSets (s₁ ∪ s₂) s' μ ↔ IndepSets s₁ s' μ ∧ IndepSets s₂ s' μ := Kernel.IndepSets.union_iff theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (hyp : ∀ n, IndepSets (s n) s' μ) : IndepSets (⋃ n, s n) s' μ := Kernel.IndepSets.iUnion hyp theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' μ) : IndepSets (⋃ n ∈ u, s n) s' μ := Kernel.IndepSets.bUnion hyp theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) (h₁ : IndepSets s₁ s' μ) : IndepSets (s₁ ∩ s₂) s' μ := Kernel.IndepSets.inter s₂ h₁ theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (h : ∃ n, IndepSets (s n) s' μ) : IndepSets (⋂ n, s n) s' μ := Kernel.IndepSets.iInter h theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' μ) : IndepSets (⋂ n ∈ u, s n) s' μ := Kernel.IndepSets.bInter h theorem indepSets_singleton_iff {s t : Set Ω} : IndepSets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t := by simp only [IndepSets, Kernel.indepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] end Indep /-! ### Deducing `Indep` from `iIndep` -/ section FromIndepToIndep variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} (h_indep : iIndepSets s μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) μ := Kernel.iIndepSets.indepSets h_indep hij theorem iIndep.indep (h_indep : iIndep m μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) μ := Kernel.iIndep.indep h_indep hij theorem iIndepFun.indepFun {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun m f μ) {i j : ι} (hij : i ≠ j) : IndepFun (f i) (f j) μ := Kernel.iIndepFun.indepFun hf_Indep hij end FromIndepToIndep /-! ## π-system lemma Independence of measurable spaces is equivalent to independence of generating π-systems. -/ section FromMeasurableSpacesToSetsOfSets variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} /-! ### Independence of measurable space structures implies independence of generating π-systems -/ theorem iIndep.iIndepSets {s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m μ) : iIndepSets s μ := Kernel.iIndep.iIndepSets hms h_indep theorem Indep.indepSets {s1 s2 : Set (Set Ω)} (h_indep : Indep (generateFrom s1) (generateFrom s2) μ) : IndepSets s1 s2 μ := Kernel.Indep.indepSets h_indep end FromMeasurableSpacesToSetsOfSets section FromPiSystemsToMeasurableSpaces variable {m : ι → MeasurableSpace Ω} {m1 m2 _mΩ : MeasurableSpace Ω} {μ : Measure Ω} /-! ### Independence of generating π-systems implies independence of measurable space structures -/ theorem IndepSets.indep [IsProbabilityMeasure μ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ _mΩ) (h2 : m2 ≤ _mΩ) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2) (hyp : IndepSets p1 p2 μ) : Indep m1 m2 μ := Kernel.IndepSets.indep h1 h2 hp1 hp2 hpm1 hpm2 hyp theorem IndepSets.indep' [IsProbabilityMeasure μ] {p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 μ) : Indep (generateFrom p1) (generateFrom p2) μ := Kernel.IndepSets.indep' hp1m hp2m hp1 hp2 hyp theorem indepSets_piiUnionInter_of_disjoint [IsProbabilityMeasure μ] {s : ι → Set (Set Ω)} {S T : Set ι} (h_indep : iIndepSets s μ) (hST : Disjoint S T) : IndepSets (piiUnionInter s S) (piiUnionInter s T) μ := Kernel.indepSets_piiUnionInter_of_disjoint h_indep hST theorem iIndepSet.indep_generateFrom_of_disjoint [IsProbabilityMeasure μ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (S T : Set ι) (hST : Disjoint S T) : Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) μ := Kernel.iIndepSet.indep_generateFrom_of_disjoint hsm hs S T hST theorem indep_iSup_of_disjoint [IsProbabilityMeasure μ] (h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m μ) {S T : Set ι} (hST : Disjoint S T) : Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) μ := Kernel.indep_iSup_of_disjoint h_le h_indep hST theorem indep_iSup_of_directed_le [IsProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Directed (· ≤ ·) m) : Indep (⨆ i, m i) m1 μ := Kernel.indep_iSup_of_directed_le h_indep h_le h_le' hm theorem iIndepSet.indep_generateFrom_lt [Preorder ι] [IsProbabilityMeasure μ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) : Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) μ := Kernel.iIndepSet.indep_generateFrom_lt hsm hs i theorem iIndepSet.indep_generateFrom_le [LinearOrder ι] [IsProbabilityMeasure μ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) {k : ι} (hk : i < k) : Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) μ := Kernel.iIndepSet.indep_generateFrom_le hsm hs i hk theorem iIndepSet.indep_generateFrom_le_nat [IsProbabilityMeasure μ] {s : ℕ → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (n : ℕ) : Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) μ := Kernel.iIndepSet.indep_generateFrom_le_nat hsm hs n theorem indep_iSup_of_monotone [SemilatticeSup ι] [IsProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Monotone m) : Indep (⨆ i, m i) m1 μ := Kernel.indep_iSup_of_monotone h_indep h_le h_le' hm theorem indep_iSup_of_antitone [SemilatticeInf ι] [IsProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Antitone m) : Indep (⨆ i, m i) m1 μ := Kernel.indep_iSup_of_antitone h_indep h_le h_le' hm theorem iIndepSets.piiUnionInter_of_not_mem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι} (hp_ind : iIndepSets π μ) (haS : a ∉ S) : IndepSets (piiUnionInter π S) (π a) μ := Kernel.iIndepSets.piiUnionInter_of_not_mem hp_ind haS /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem iIndepSets.iIndep [IsProbabilityMeasure μ] (h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n)) (h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π μ) : iIndep m μ := Kernel.iIndepSets.iIndep m h_le π h_pi h_generate h_ind end FromPiSystemsToMeasurableSpaces section IndepSet /-! ### Independence of measurable sets We prove the following equivalences on `IndepSet`, for measurable sets `s, t`. * `IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t`, * `IndepSet s t μ ↔ IndepSets {s} {t} μ`. -/ variable {m₁ m₂ _mΩ : MeasurableSpace Ω} {μ : Measure Ω} {s t : Set Ω} (S T : Set (Set Ω)) theorem indepSet_iff_indepSets_singleton (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac) [IsProbabilityMeasure μ] : IndepSet s t μ ↔ IndepSets {s} {t} μ := Kernel.indepSet_iff_indepSets_singleton hs_meas ht_meas _ _ theorem indepSet_iff_measure_inter_eq_mul (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac) [IsProbabilityMeasure μ] : IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t := (indepSet_iff_indepSets_singleton hs_meas ht_meas μ).trans indepSets_singleton_iff theorem IndepSets.indepSet_of_mem (hs : s ∈ S) (ht : t ∈ T) (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac) [IsProbabilityMeasure μ] (h_indep : IndepSets S T μ) : IndepSet s t μ := Kernel.IndepSets.indepSet_of_mem _ _ hs ht hs_meas ht_meas _ _ h_indep theorem Indep.indepSet_of_measurableSet (h_indep : Indep m₁ m₂ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s) (ht : MeasurableSet[m₂] t) : IndepSet s t μ := Kernel.Indep.indepSet_of_measurableSet h_indep hs ht theorem indep_iff_forall_indepSet (μ : Measure Ω) : Indep m₁ m₂ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t μ := Kernel.indep_iff_forall_indepSet m₁ m₂ _ _ theorem iIndep_comap_mem_iff {f : ι → Set Ω} : iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) μ ↔ iIndepSet f μ := Kernel.iIndep_comap_mem_iff alias ⟨_, iIndepSet.iIndep_comap_mem⟩ := iIndep_comap_mem_iff theorem iIndepSets_singleton_iff {s : ι → Set Ω} : iIndepSets (fun i ↦ {s i}) μ ↔ ∀ t, μ (⋂ i ∈ t, s i) = ∏ i ∈ t, μ (s i) := by simp_rw [iIndepSets, Kernel.iIndepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] variable [IsProbabilityMeasure μ] theorem iIndepSet_iff_iIndepSets_singleton {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f μ ↔ iIndepSets (fun i ↦ {f i}) μ := Kernel.iIndepSet_iff_iIndepSets_singleton hf theorem iIndepSet_iff_meas_biInter {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f μ ↔ ∀ s, μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp_rw [iIndepSet, Kernel.iIndepSet_iff_meas_biInter hf, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem iIndepSets.iIndepSet_of_mem {π : ι → Set (Set Ω)} {f : ι → Set Ω} (hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i)) (hπ : iIndepSets π μ) : iIndepSet f μ := Kernel.iIndepSets.iIndepSet_of_mem hfπ hf hπ end IndepSet section IndepFun /-! ### Independence of random variables -/ variable {β β' γ γ' : Type*} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → β} {g : Ω → β'} theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} : IndepFun f g μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → μ (f ⁻¹' s ∩ g ⁻¹' t) = μ (f ⁻¹' s) * μ (g ⁻¹' t) := by simp only [IndepFun, Kernel.indepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*} (m : ∀ x, MeasurableSpace (β x)) (f : ∀ i, Ω → β i) : iIndepFun m f μ ↔ ∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)), μ (⋂ i ∈ S, f i ⁻¹' sets i) = ∏ i ∈ S, μ (f i ⁻¹' sets i) := by simp only [iIndepFun, Kernel.iIndepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} [IsProbabilityMeasure μ] (hf : Measurable f) (hg : Measurable g) : IndepFun f g μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) μ := by simp only [IndepFun, IndepSet, Kernel.indepFun_iff_indepSet_preimage hf hg, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem indepFun_iff_map_prod_eq_prod_map_map {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} [IsFiniteMeasure μ] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : IndepFun f g μ ↔ μ.map (fun ω ↦ (f ω, g ω)) = (μ.map f).prod (μ.map g) := by rw [indepFun_iff_measure_inter_preimage_eq_mul] have h₀ {s : Set β} {t : Set β'} (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (f ⁻¹' s) * μ (g ⁻¹' t) = μ.map f s * μ.map g t ∧ μ (f ⁻¹' s ∩ g ⁻¹' t) = μ.map (fun ω ↦ (f ω, g ω)) (s ×ˢ t) := ⟨by rw [Measure.map_apply_of_aemeasurable hf hs, Measure.map_apply_of_aemeasurable hg ht], (Measure.map_apply_of_aemeasurable (hf.prod_mk hg) (hs.prod ht)).symm⟩ constructor · refine fun h ↦ (Measure.prod_eq fun s t hs ht ↦ ?_).symm rw [← (h₀ hs ht).1, ← (h₀ hs ht).2, h s t hs ht] · intro h s t hs ht rw [(h₀ hs ht).1, (h₀ hs ht).2, h, Measure.prod_prod] @[symm] nonrec theorem IndepFun.symm {_ : MeasurableSpace β} {_ : MeasurableSpace β'} (hfg : IndepFun f g μ) : IndepFun g f μ := hfg.symm theorem IndepFun.ae_eq {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} {f' : Ω → β} {g' : Ω → β'} (hfg : IndepFun f g μ) (hf : f =ᵐ[μ] f') (hg : g =ᵐ[μ] g') : IndepFun f' g' μ := by refine Kernel.IndepFun.ae_eq hfg ?_ ?_ <;> simp only [ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] exacts [hf, hg] theorem IndepFun.comp {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} {_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'} (hfg : IndepFun f g μ) (hφ : Measurable φ) (hψ : Measurable ψ) : IndepFun (φ ∘ f) (ψ ∘ g) μ := Kernel.IndepFun.comp hfg hφ hψ theorem IndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β'] [MeasurableNeg β'] (hfg : IndepFun f g μ) : IndepFun f (-g) μ := hfg.comp measurable_id measurable_neg theorem IndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β] [MeasurableNeg β] (hfg : IndepFun f g μ) : IndepFun (-f) g μ := hfg.comp measurable_neg measurable_id section iIndepFun variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} @[nontriviality] lemma iIndepFun.of_subsingleton [IsProbabilityMeasure μ] [Subsingleton ι] : iIndepFun m f μ := Kernel.iIndepFun.of_subsingleton lemma iIndepFun.isProbabilityMeasure (h : iIndepFun m f μ) : IsProbabilityMeasure μ := ⟨by simpa using h.meas_biInter (S := ∅) (s := fun _ ↦ univ)⟩ /-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the tuple `(f i)_i` for `i ∈ T`. -/ lemma iIndepFun.indepFun_finset (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iIndepFun m f μ) (hf_meas : ∀ i, Measurable (f i)) : IndepFun (fun a (i : S) ↦ f i a) (fun a (i : T) ↦ f i a) μ := have := hf_Indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_finset S T hST hf_Indep hf_meas lemma iIndepFun.indepFun_prod_mk (hf_Indep : iIndepFun m f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : IndepFun (fun a => (f i a, f j a)) (f k) μ := have := hf_Indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_prod_mk hf_Indep hf_meas i j k hik hjk open Finset in lemma iIndepFun.indepFun_prod_mk_prod_mk (h_indep : iIndepFun m f μ) (hf : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ := by classical let g (i j : ι) (v : Π x : ({i, j} : Finset ι), β x) : β i × β j := ⟨v ⟨i, mem_insert_self _ _⟩, v ⟨j, mem_insert_of_mem <| mem_singleton_self _⟩⟩ have hg (i j : ι) : Measurable (g i j) := by fun_prop exact (h_indep.indepFun_finset {i, j} {k, l} (by aesop) hf).comp (hg i j) (hg k l) end iIndepFun section Mul variable {β : Type*} {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β} @[to_additive] lemma iIndepFun.indepFun_mul_left (hf_indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : IndepFun (f i * f j) (f k) μ := have := hf_indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_mul_left hf_indep hf_meas i j k hik hjk @[to_additive] lemma iIndepFun.indepFun_mul_right (hf_indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) : IndepFun (f i) (f j * f k) μ := have := hf_indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_mul_right hf_indep hf_meas i j k hij hik @[to_additive] lemma iIndepFun.indepFun_mul_mul (hf_indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : IndepFun (f i * f j) (f k * f l) μ := have := hf_indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_mul_mul hf_indep hf_meas i j k l hik hil hjk hjl end Mul section Div variable {β : Type*} {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β} @[to_additive] lemma iIndepFun.indepFun_div_left (hf_indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : IndepFun (f i / f j) (f k) μ := have := hf_indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_div_left hf_indep hf_meas i j k hik hjk @[to_additive] lemma iIndepFun.indepFun_div_right (hf_indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) : IndepFun (f i) (f j / f k) μ := have := hf_indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_div_right hf_indep hf_meas i j k hij hik @[to_additive] lemma iIndepFun.indepFun_div_div (hf_indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : IndepFun (f i / f j) (f k / f l) μ := have := hf_indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_div_div hf_indep hf_meas i j k l hik hil hjk hjl end Div section CommMonoid variable {β : Type*} {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β} @[to_additive] lemma iIndepFun.indepFun_finset_prod_of_not_mem (hf_Indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) {s : Finset ι} {i : ι} (hi : i ∉ s) : IndepFun (∏ j ∈ s, f j) (f i) μ := have := hf_Indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_finset_prod_of_not_mem hf_Indep hf_meas hi @[to_additive] lemma iIndepFun.indepFun_prod_range_succ {f : ℕ → Ω → β} (hf_Indep : iIndepFun (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (n : ℕ) : IndepFun (∏ j ∈ Finset.range n, f j) (f n) μ := have := hf_Indep.isProbabilityMeasure Kernel.iIndepFun.indepFun_prod_range_succ hf_Indep hf_meas n end CommMonoid theorem iIndepSet.iIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β} {s : ι → Set Ω} (hs : iIndepSet s μ) : iIndepFun (fun _n => m) (fun n => (s n).indicator fun _ω => 1) μ := Kernel.iIndepSet.iIndepFun_indicator hs end IndepFun end ProbabilityTheory
Probability\Independence\Conditional.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.Probability.Independence.Kernel import Mathlib.Probability.Kernel.Condexp /-! # Conditional Independence We define conditional independence of sets/σ-algebras/functions with respect to a σ-algebra. Two σ-algebras `m₁` and `m₂` are conditionally independent given a third σ-algebra `m'` if for all `m₁`-measurable sets `t₁` and `m₂`-measurable sets `t₂`, `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`. On standard Borel spaces, the conditional expectation with respect to `m'` defines a kernel `ProbabilityTheory.condexpKernel`, and the definition above is equivalent to `∀ᵐ ω ∂μ, condexpKernel μ m' ω (t₁ ∩ t₂) = condexpKernel μ m' ω t₁ * condexpKernel μ m' ω t₂`. We use this property as the definition of conditional independence. ## Main definitions We provide four definitions of conditional independence: * `iCondIndepSets`: conditional independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to be used with π-systems. * `iCondIndep`: conditional independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`, * `iCondIndepSet`: conditional independence of a family of sets `s : ι → Set Ω`, * `iCondIndepFun`: conditional independence of a family of functions. For measurable spaces `m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`. Additionally, we provide four corresponding statements for two measurable space structures (resp. sets of sets, sets, functions) instead of a family. These properties are denoted by the same names as for a family, but without the starting `i`, for example `CondIndepFun` is the version of `iCondIndepFun` for two functions. ## Main statements * `ProbabilityTheory.iCondIndepSets.iCondIndep`: if π-systems are conditionally independent as sets of sets, then the measurable space structures they generate are conditionally independent. * `ProbabilityTheory.condIndepSets.condIndep`: variant with two π-systems. ## Implementation notes The definitions of conditional independence in this file are a particular case of independence with respect to a kernel and a measure, as defined in the file `Probability/Independence/Kernel.lean`. The kernel used is `ProbabilityTheory.condexpKernel`. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {Ω ι : Type*} section Definitions section variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) /-- A family of sets of sets `π : ι → Set (Set Ω)` is conditionally independent given `m'` with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ⟦⋂ i in s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, μ⟦f i | m'⟧`. See `ProbabilityTheory.iCondIndepSets_iff`. It will be used for families of pi_systems. -/ def iCondIndepSets (π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndepSets π (condexpKernel μ m') (μ.trim hm') /-- Two sets of sets `s₁, s₂` are conditionally independent given `m'` with respect to a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`. See `ProbabilityTheory.condIndepSets_iff`. -/ def CondIndepSets (s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.IndepSets s1 s2 (condexpKernel μ m') (μ.trim hm') /-- A family of measurable space structures (i.e. of σ-algebras) is conditionally independent given `m'` with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. `m : ι → MeasurableSpace Ω` is conditionally independent given `m'` with respect to measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ⟦⋂ i in s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, μ⟦f i | m'⟧ `. See `ProbabilityTheory.iCondIndep_iff`. -/ def iCondIndep (m : ι → MeasurableSpace Ω) (μ : @Measure Ω mΩ := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndep m (condexpKernel (mΩ := mΩ) μ m') (μ.trim hm') end /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are conditionally independent given `m'` with respect to a measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`. See `ProbabilityTheory.condIndep_iff`. -/ def CondIndep (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.Indep m₁ m₂ (condexpKernel μ m') (μ.trim hm') section variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) /-- A family of sets is conditionally independent if the family of measurable space structures they generate is conditionally independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. See `ProbabilityTheory.iCondIndepSet_iff`. -/ def iCondIndepSet (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndepSet s (condexpKernel μ m') (μ.trim hm') /-- Two sets are conditionally independent if the two measurable space structures they generate are conditionally independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. See `ProbabilityTheory.condIndepSet_iff`. -/ def CondIndepSet (s t : Set Ω) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.IndepSet s t (condexpKernel μ m') (μ.trim hm') /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is conditionally independent if the family of measurable space structures they generate on `Ω` is conditionally independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `m.comap g`. See `ProbabilityTheory.iCondIndepFun_iff`. -/ def iCondIndepFun {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndepFun m f (condexpKernel μ m') (μ.trim hm') /-- Two functions are conditionally independent if the two measurable space structures they generate are conditionally independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `m.comap f`. See `ProbabilityTheory.condIndepFun_iff`. -/ def CondIndepFun {β γ : Type*} [MeasurableSpace β] [MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.IndepFun f g (condexpKernel μ m') (μ.trim hm') end end Definitions section DefinitionLemmas section variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) lemma iCondIndepSets_iff (π : ι → Set (Set Ω)) (hπ : ∀ i s (_hs : s ∈ π i), MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSets m' hm' π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), μ⟦⋂ i ∈ s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦f i | m'⟧) := by simp only [iCondIndepSets, Kernel.iIndepSets] have h_eq' : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i) i (_hi : i ∈ s), (fun ω ↦ ENNReal.toReal (condexpKernel μ m' ω (f i))) =ᵐ[μ] μ⟦f i | m'⟧ := fun s f H i hi ↦ condexpKernel_ae_eq_condexp hm' (hπ i (f i) (H i hi)) have h_eq : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ ω ∂μ, ∀ i ∈ s, ENNReal.toReal (condexpKernel μ m' ω (f i)) = (μ⟦f i | m'⟧) ω := by intros s f H simp_rw [← Finset.mem_coe] rw [ae_ball_iff (Finset.countable_toSet s)] exact h_eq' s f H have h_inter_eq : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i), (fun ω ↦ ENNReal.toReal (condexpKernel μ m' ω (⋂ i ∈ s, f i))) =ᵐ[μ] μ⟦⋂ i ∈ s, f i | m'⟧ := by refine fun s f H ↦ condexpKernel_ae_eq_condexp hm' ?_ exact MeasurableSet.biInter (Finset.countable_toSet _) (fun i hi ↦ hπ i _ (H i hi)) refine ⟨fun h s f hf ↦ ?_, fun h s f hf ↦ ?_⟩ <;> specialize h s hf · have h' := ae_eq_of_ae_eq_trim h filter_upwards [h_eq s f hf, h_inter_eq s f hf, h'] with ω h_eq h_inter_eq h' rw [← h_inter_eq, h', ENNReal.toReal_prod, Finset.prod_apply] exact Finset.prod_congr rfl h_eq · refine (ae_eq_trim_iff hm' ?_ ?_).mpr ?_ · refine stronglyMeasurable_condexpKernel ?_ exact MeasurableSet.biInter (Finset.countable_toSet _) (fun i hi ↦ hπ i _ (hf i hi)) · refine Measurable.stronglyMeasurable ?_ exact Finset.measurable_prod s (fun i hi ↦ measurable_condexpKernel (hπ i _ (hf i hi))) filter_upwards [h_eq s f hf, h_inter_eq s f hf, h] with ω h_eq h_inter_eq h have h_ne_top : condexpKernel μ m' ω (⋂ i ∈ s, f i) ≠ ∞ := (measure_ne_top (condexpKernel μ m' ω) _) have : (∏ i ∈ s, condexpKernel μ m' ω (f i)) ≠ ∞ := (ENNReal.prod_lt_top (fun _ _ ↦ measure_ne_top (condexpKernel μ m' ω) _)).ne rw [← ENNReal.ofReal_toReal h_ne_top, h_inter_eq, h, Finset.prod_apply, ← ENNReal.ofReal_toReal this, ENNReal.toReal_prod] congr 1 exact Finset.prod_congr rfl (fun i hi ↦ (h_eq i hi).symm) lemma condIndepSets_iff (s1 s2 : Set (Set Ω)) (hs1 : ∀ s ∈ s1, MeasurableSet s) (hs2 : ∀ s ∈ s2, MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepSets m' hm' s1 s2 μ ↔ ∀ (t1 t2 : Set Ω) (_ : t1 ∈ s1) (_ : t2 ∈ s2), (μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by simp only [CondIndepSets, Kernel.IndepSets] have hs1_eq : ∀ s ∈ s1, (fun ω ↦ ENNReal.toReal (condexpKernel μ m' ω s)) =ᵐ[μ] μ⟦s | m'⟧ := fun s hs ↦ condexpKernel_ae_eq_condexp hm' (hs1 s hs) have hs2_eq : ∀ s ∈ s2, (fun ω ↦ ENNReal.toReal (condexpKernel μ m' ω s)) =ᵐ[μ] μ⟦s | m'⟧ := fun s hs ↦ condexpKernel_ae_eq_condexp hm' (hs2 s hs) have hs12_eq : ∀ s ∈ s1, ∀ t ∈ s2, (fun ω ↦ ENNReal.toReal (condexpKernel μ m' ω (s ∩ t))) =ᵐ[μ] μ⟦s ∩ t | m'⟧ := fun s hs t ht ↦ condexpKernel_ae_eq_condexp hm' ((hs1 s hs).inter ((hs2 t ht))) refine ⟨fun h s t hs ht ↦ ?_, fun h s t hs ht ↦ ?_⟩ <;> specialize h s t hs ht · have h' := ae_eq_of_ae_eq_trim h filter_upwards [hs1_eq s hs, hs2_eq t ht, hs12_eq s hs t ht, h'] with ω hs_eq ht_eq hst_eq h' rw [← hst_eq, Pi.mul_apply, ← hs_eq, ← ht_eq, h', ENNReal.toReal_mul] · refine (ae_eq_trim_iff hm' ?_ ?_).mpr ?_ · exact stronglyMeasurable_condexpKernel ((hs1 s hs).inter ((hs2 t ht))) · refine Measurable.stronglyMeasurable (Measurable.mul ?_ ?_) · exact measurable_condexpKernel (hs1 s hs) · exact measurable_condexpKernel (hs2 t ht) filter_upwards [hs1_eq s hs, hs2_eq t ht, hs12_eq s hs t ht, h] with ω hs_eq ht_eq hst_eq h have h_ne_top : condexpKernel μ m' ω (s ∩ t) ≠ ∞ := measure_ne_top (condexpKernel μ m' ω) _ rw [← ENNReal.ofReal_toReal h_ne_top, hst_eq, h, Pi.mul_apply, ← hs_eq, ← ht_eq, ← ENNReal.toReal_mul, ENNReal.ofReal_toReal] exact ENNReal.mul_ne_top (measure_ne_top (condexpKernel μ m' ω) s) (measure_ne_top (condexpKernel μ m' ω) t) lemma iCondIndepSets_singleton_iff (s : ι → Set Ω) (hπ : ∀ i, MeasurableSet (s i)) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSets m' hm' (fun i ↦ {s i}) μ ↔ ∀ S : Finset ι, μ⟦⋂ i ∈ S, s i | m'⟧ =ᵐ[μ] ∏ i ∈ S, (μ⟦s i | m'⟧) := by rw [iCondIndepSets_iff] · simp only [Set.mem_singleton_iff] refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩ filter_upwards [h S] with a ha refine Eq.trans ?_ (ha.trans ?_) · congr apply congr_arg₂ · exact Set.iInter₂_congr hf · rfl · simp_rw [Finset.prod_apply] refine Finset.prod_congr rfl (fun i hi ↦ ?_) rw [hf i hi] · simpa only [Set.mem_singleton_iff, forall_eq] theorem condIndepSets_singleton_iff {μ : Measure Ω} [IsFiniteMeasure μ] {s t : Set Ω} (hs : MeasurableSet s) (ht : MeasurableSet t) : CondIndepSets m' hm' {s} {t} μ ↔ (μ⟦s ∩ t | m'⟧) =ᵐ[μ] (μ⟦s | m'⟧) * (μ⟦t | m'⟧) := by rw [condIndepSets_iff _ _ _ _ ?_ ?_] · simp only [Set.mem_singleton_iff, forall_eq_apply_imp_iff, forall_eq] · intros s' hs' rw [Set.mem_singleton_iff] at hs' rwa [hs'] · intros s' hs' rw [Set.mem_singleton_iff] at hs' rwa [hs'] lemma iCondIndep_iff_iCondIndepSets (m : ι → MeasurableSpace Ω) (μ : @Measure Ω mΩ) [IsFiniteMeasure μ] : iCondIndep m' hm' m μ ↔ iCondIndepSets m' hm' (fun x ↦ {s | MeasurableSet[m x] s}) μ := by simp only [iCondIndep, iCondIndepSets, Kernel.iIndep] lemma iCondIndep_iff (m : ι → MeasurableSpace Ω) (hm : ∀ i, m i ≤ mΩ) (μ : @Measure Ω mΩ) [IsFiniteMeasure μ] : iCondIndep m' hm' m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)), μ⟦⋂ i ∈ s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦f i | m'⟧) := by rw [iCondIndep_iff_iCondIndepSets, iCondIndepSets_iff] · rfl · exact hm end section CondIndep lemma condIndep_iff_condIndepSets (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) (μ : Measure Ω ) [IsFiniteMeasure μ] : CondIndep m' m₁ m₂ hm' μ ↔ CondIndepSets m' hm' {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by simp only [CondIndep, CondIndepSets, Kernel.Indep] lemma condIndep_iff (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) (hm₁ : m₁ ≤ mΩ) (hm₂ : m₂ ≤ mΩ) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndep m' m₁ m₂ hm' μ ↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2 → (μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by rw [condIndep_iff_condIndepSets, condIndepSets_iff] · rfl · exact hm₁ · exact hm₂ end CondIndep variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] (hm' : m' ≤ mΩ) lemma iCondIndepSet_iff_iCondIndep (s : ι → Set Ω) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSet m' hm' s μ ↔ iCondIndep m' hm' (fun i ↦ generateFrom {s i}) μ := by simp only [iCondIndepSet, iCondIndep, Kernel.iIndepSet] theorem iCondIndepSet_iff_iCondIndepSets_singleton (s : ι → Set Ω) (hs : ∀ i, MeasurableSet (s i)) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSet m' hm' s μ ↔ iCondIndepSets m' hm' (fun i ↦ {s i}) μ := Kernel.iIndepSet_iff_iIndepSets_singleton hs lemma iCondIndepSet_iff (s : ι → Set Ω) (hs : ∀ i, MeasurableSet (s i)) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSet m' hm' s μ ↔ ∀ S : Finset ι, μ⟦⋂ i ∈ S, s i | m'⟧ =ᵐ[μ] ∏ i ∈ S, μ⟦s i | m'⟧ := by rw [iCondIndepSet_iff_iCondIndepSets_singleton _ _ _ hs, iCondIndepSets_singleton_iff _ _ _ hs] lemma condIndepSet_iff_condIndep (s t : Set Ω) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepSet m' hm' s t μ ↔ CondIndep m' (generateFrom {s}) (generateFrom {t}) hm' μ := by simp only [CondIndepSet, CondIndep, Kernel.IndepSet] theorem condIndepSet_iff_condIndepSets_singleton {s t : Set Ω} (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepSet m' hm' s t μ ↔ CondIndepSets m' hm' {s} {t} μ := Kernel.indepSet_iff_indepSets_singleton hs_meas ht_meas _ _ lemma condIndepSet_iff (s t : Set Ω) (hs : MeasurableSet s) (ht : MeasurableSet t) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepSet m' hm' s t μ ↔ (μ⟦s ∩ t | m'⟧) =ᵐ[μ] (μ⟦s | m'⟧) * (μ⟦t | m'⟧) := by rw [condIndepSet_iff_condIndepSets_singleton _ _ hs ht μ, condIndepSets_singleton_iff _ _ hs ht] lemma iCondIndepFun_iff_iCondIndep {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepFun m' hm' m f μ ↔ iCondIndep m' hm' (fun x ↦ MeasurableSpace.comap (f x) (m x)) μ := by simp only [iCondIndepFun, iCondIndep, Kernel.iIndepFun] lemma iCondIndepFun_iff {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (hf : ∀ i, Measurable (f i)) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepFun m' hm' m f μ ↔ ∀ (s : Finset ι) {g : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (g i)), μ⟦⋂ i ∈ s, g i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦g i | m'⟧) := by simp only [iCondIndepFun_iff_iCondIndep] rw [iCondIndep_iff] exact fun i ↦ (hf i).comap_le lemma condIndepFun_iff_condIndep {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepFun m' hm' f g μ ↔ CondIndep m' (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) hm' μ := by simp only [CondIndepFun, CondIndep, Kernel.IndepFun] lemma condIndepFun_iff {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (hf : Measurable f) (hg : Measurable g) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepFun m' hm' f g μ ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1 → MeasurableSet[MeasurableSpace.comap g mγ] t2 → (μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by rw [condIndepFun_iff_condIndep, condIndep_iff _ _ _ _ hf.comap_le hg.comap_le] end DefinitionLemmas section CondIndepSets variable {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] @[symm] theorem CondIndepSets.symm {s₁ s₂ : Set (Set Ω)} (h : CondIndepSets m' hm' s₁ s₂ μ) : CondIndepSets m' hm' s₂ s₁ μ := Kernel.IndepSets.symm h theorem condIndepSets_of_condIndepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : CondIndepSets m' hm' s₁ s₂ μ) (h31 : s₃ ⊆ s₁) : CondIndepSets m' hm' s₃ s₂ μ := Kernel.indepSets_of_indepSets_of_le_left h_indep h31 theorem condIndepSets_of_condIndepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : CondIndepSets m' hm' s₁ s₂ μ) (h32 : s₃ ⊆ s₂) : CondIndepSets m' hm' s₁ s₃ μ := Kernel.indepSets_of_indepSets_of_le_right h_indep h32 theorem CondIndepSets.union {s₁ s₂ s' : Set (Set Ω)} (h₁ : CondIndepSets m' hm' s₁ s' μ) (h₂ : CondIndepSets m' hm' s₂ s' μ) : CondIndepSets m' hm' (s₁ ∪ s₂) s' μ := Kernel.IndepSets.union h₁ h₂ @[simp] theorem CondIndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} : CondIndepSets m' hm' (s₁ ∪ s₂) s' μ ↔ CondIndepSets m' hm' s₁ s' μ ∧ CondIndepSets m' hm' s₂ s' μ := Kernel.IndepSets.union_iff theorem CondIndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (hyp : ∀ n, CondIndepSets m' hm' (s n) s' μ) : CondIndepSets m' hm' (⋃ n, s n) s' μ := Kernel.IndepSets.iUnion hyp theorem CondIndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (hyp : ∀ n ∈ u, CondIndepSets m' hm' (s n) s' μ) : CondIndepSets m' hm' (⋃ n ∈ u, s n) s' μ := Kernel.IndepSets.bUnion hyp theorem CondIndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) (h₁ : CondIndepSets m' hm' s₁ s' μ) : CondIndepSets m' hm' (s₁ ∩ s₂) s' μ := Kernel.IndepSets.inter s₂ h₁ theorem CondIndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (h : ∃ n, CondIndepSets m' hm' (s n) s' μ) : CondIndepSets m' hm' (⋂ n, s n) s' μ := Kernel.IndepSets.iInter h theorem CondIndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (h : ∃ n ∈ u, CondIndepSets m' hm' (s n) s' μ) : CondIndepSets m' hm' (⋂ n ∈ u, s n) s' μ := Kernel.IndepSets.bInter h end CondIndepSets section CondIndepSet variable {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] theorem condIndepSet_empty_right (s : Set Ω) : CondIndepSet m' hm' s ∅ μ := Kernel.indepSet_empty_right s theorem condIndepSet_empty_left (s : Set Ω) : CondIndepSet m' hm' ∅ s μ := Kernel.indepSet_empty_left s end CondIndepSet section CondIndep @[symm] theorem CondIndep.symm {m' m₁ m₂ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] (h : CondIndep m' m₁ m₂ hm' μ) : CondIndep m' m₂ m₁ hm' μ := CondIndepSets.symm h theorem condIndep_bot_right (m₁ : MeasurableSpace Ω) {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] : CondIndep m' m₁ ⊥ hm' μ := Kernel.indep_bot_right m₁ theorem condIndep_bot_left (m₁ : MeasurableSpace Ω) {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] : CondIndep m' ⊥ m₁ hm' μ := (Kernel.indep_bot_right m₁).symm theorem condIndep_of_condIndep_of_le_left {m' m₁ m₂ m₃ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] (h_indep : CondIndep m' m₁ m₂ hm' μ) (h31 : m₃ ≤ m₁) : CondIndep m' m₃ m₂ hm' μ := Kernel.indep_of_indep_of_le_left h_indep h31 theorem condIndep_of_condIndep_of_le_right {m' m₁ m₂ m₃ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] (h_indep : CondIndep m' m₁ m₂ hm' μ) (h32 : m₃ ≤ m₂) : CondIndep m' m₁ m₃ hm' μ := Kernel.indep_of_indep_of_le_right h_indep h32 end CondIndep /-! ### Deducing `CondIndep` from `iCondIndep` -/ section FromiCondIndepToCondIndep variable {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] theorem iCondIndepSets.condIndepSets {s : ι → Set (Set Ω)} (h_indep : iCondIndepSets m' hm' s μ) {i j : ι} (hij : i ≠ j) : CondIndepSets m' hm' (s i) (s j) μ := Kernel.iIndepSets.indepSets h_indep hij theorem iCondIndep.condIndep {m : ι → MeasurableSpace Ω} (h_indep : iCondIndep m' hm' m μ) {i j : ι} (hij : i ≠ j) : CondIndep m' (m i) (m j) hm' μ := Kernel.iIndep.indep h_indep hij theorem iCondIndepFun.condIndepFun {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iCondIndepFun m' hm' m f μ) {i j : ι} (hij : i ≠ j) : CondIndepFun m' hm' (f i) (f j) μ := Kernel.iIndepFun.indepFun hf_Indep hij end FromiCondIndepToCondIndep /-! ## π-system lemma Conditional independence of measurable spaces is equivalent to conditional independence of generating π-systems. -/ section FromMeasurableSpacesToSetsOfSets /-! ### Conditional independence of σ-algebras implies conditional independence of generating π-systems -/ variable {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] theorem iCondIndep.iCondIndepSets {m : ι → MeasurableSpace Ω} {s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iCondIndep m' hm' m μ) : iCondIndepSets m' hm' s μ := Kernel.iIndep.iIndepSets hms h_indep theorem CondIndep.condIndepSets {s1 s2 : Set (Set Ω)} (h_indep : CondIndep m' (generateFrom s1) (generateFrom s2) hm' μ) : CondIndepSets m' hm' s1 s2 μ := Kernel.Indep.indepSets h_indep end FromMeasurableSpacesToSetsOfSets section FromPiSystemsToMeasurableSpaces /-! ### Conditional independence of generating π-systems implies conditional independence of σ-algebras -/ variable {m' m₁ m₂ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] theorem CondIndepSets.condIndep {p1 p2 : Set (Set Ω)} (h1 : m₁ ≤ mΩ) (h2 : m₂ ≤ mΩ) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hpm1 : m₁ = generateFrom p1) (hpm2 : m₂ = generateFrom p2) (hyp : CondIndepSets m' hm' p1 p2 μ) : CondIndep m' m₁ m₂ hm' μ := Kernel.IndepSets.indep h1 h2 hp1 hp2 hpm1 hpm2 hyp theorem CondIndepSets.condIndep' {p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : CondIndepSets m' hm' p1 p2 μ) : CondIndep m' (generateFrom p1) (generateFrom p2) hm' μ := Kernel.IndepSets.indep' hp1m hp2m hp1 hp2 hyp theorem condIndepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)} {S T : Set ι} (h_indep : iCondIndepSets m' hm' s μ) (hST : Disjoint S T) : CondIndepSets m' hm' (piiUnionInter s S) (piiUnionInter s T) μ := Kernel.indepSets_piiUnionInter_of_disjoint h_indep hST theorem iCondIndepSet.condIndep_generateFrom_of_disjoint {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (S T : Set ι) (hST : Disjoint S T) : CondIndep m' (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) hm' μ := Kernel.iIndepSet.indep_generateFrom_of_disjoint hsm hs S T hST theorem condIndep_iSup_of_disjoint {m : ι → MeasurableSpace Ω} (h_le : ∀ i, m i ≤ mΩ) (h_indep : iCondIndep m' hm' m μ) {S T : Set ι} (hST : Disjoint S T) : CondIndep m' (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) hm' μ := Kernel.indep_iSup_of_disjoint h_le h_indep hST theorem condIndep_iSup_of_directed_le {m : ι → MeasurableSpace Ω} (h_indep : ∀ i, CondIndep m' (m i) m₁ hm' μ) (h_le : ∀ i, m i ≤ mΩ) (h_le' : m₁ ≤ mΩ) (hm : Directed (· ≤ ·) m) : CondIndep m' (⨆ i, m i) m₁ hm' μ := Kernel.indep_iSup_of_directed_le h_indep h_le h_le' hm theorem iCondIndepSet.condIndep_generateFrom_lt [Preorder ι] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (i : ι) : CondIndep m' (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) hm' μ := Kernel.iIndepSet.indep_generateFrom_lt hsm hs i theorem iCondIndepSet.condIndep_generateFrom_le [LinearOrder ι] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (i : ι) {k : ι} (hk : i < k) : CondIndep m' (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) hm' μ := Kernel.iIndepSet.indep_generateFrom_le hsm hs i hk theorem iCondIndepSet.condIndep_generateFrom_le_nat {s : ℕ → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iCondIndepSet m' hm' s μ) (n : ℕ) : CondIndep m' (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) hm' μ := Kernel.iIndepSet.indep_generateFrom_le_nat hsm hs n theorem condIndep_iSup_of_monotone [SemilatticeSup ι] {m : ι → MeasurableSpace Ω} (h_indep : ∀ i, CondIndep m' (m i) m₁ hm' μ) (h_le : ∀ i, m i ≤ mΩ) (h_le' : m₁ ≤ mΩ) (hm : Monotone m) : CondIndep m' (⨆ i, m i) m₁ hm' μ := Kernel.indep_iSup_of_monotone h_indep h_le h_le' hm theorem condIndep_iSup_of_antitone [SemilatticeInf ι] {m : ι → MeasurableSpace Ω} (h_indep : ∀ i, CondIndep m' (m i) m₁ hm' μ) (h_le : ∀ i, m i ≤ mΩ) (h_le' : m₁ ≤ mΩ) (hm : Antitone m) : CondIndep m' (⨆ i, m i) m₁ hm' μ := Kernel.indep_iSup_of_antitone h_indep h_le h_le' hm theorem iCondIndepSets.piiUnionInter_of_not_mem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι} (hp_ind : iCondIndepSets m' hm' π μ) (haS : a ∉ S) : CondIndepSets m' hm' (piiUnionInter π S) (π a) μ := Kernel.iIndepSets.piiUnionInter_of_not_mem hp_ind haS /-- The σ-algebras generated by conditionally independent pi-systems are conditionally independent. -/ theorem iCondIndepSets.iCondIndep (m : ι → MeasurableSpace Ω) (h_le : ∀ i, m i ≤ mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n)) (h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iCondIndepSets m' hm' π μ) : iCondIndep m' hm' m μ := Kernel.iIndepSets.iIndep m h_le π h_pi h_generate h_ind end FromPiSystemsToMeasurableSpaces section CondIndepSet /-! ### Conditional independence of measurable sets -/ variable {m' m₁ m₂ : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {s t : Set Ω} (S T : Set (Set Ω)) theorem CondIndepSets.condIndepSet_of_mem (hs : s ∈ S) (ht : t ∈ T) (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω) [IsFiniteMeasure μ] (h_indep : CondIndepSets m' hm' S T μ) : CondIndepSet m' hm' s t μ := Kernel.IndepSets.indepSet_of_mem _ _ hs ht hs_meas ht_meas _ _ h_indep theorem CondIndep.condIndepSet_of_measurableSet {μ : Measure Ω} [IsFiniteMeasure μ] (h_indep : CondIndep m' m₁ m₂ hm' μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s) (ht : MeasurableSet[m₂] t) : CondIndepSet m' hm' s t μ := Kernel.Indep.indepSet_of_measurableSet h_indep hs ht theorem condIndep_iff_forall_condIndepSet (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndep m' m₁ m₂ hm' μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → CondIndepSet m' hm' s t μ := Kernel.indep_iff_forall_indepSet m₁ m₂ _ _ end CondIndepSet section CondIndepFun /-! ### Conditional independence of random variables -/ variable {β β' : Type*} {m' : MeasurableSpace Ω} {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] [Nonempty Ω] {hm' : m' ≤ mΩ} {μ : Measure Ω} [IsFiniteMeasure μ] {f : Ω → β} {g : Ω → β'} theorem condIndepFun_iff_condexp_inter_preimage_eq_mul {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} (hf : Measurable f) (hg : Measurable g) : CondIndepFun m' hm' f g μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → (μ⟦f ⁻¹' s ∩ g ⁻¹' t | m'⟧) =ᵐ[μ] fun ω ↦ (μ⟦f ⁻¹' s | m'⟧) ω * (μ⟦g ⁻¹' t | m'⟧) ω := by rw [condIndepFun_iff _ _ _ _ hf hg] refine ⟨fun h s t hs ht ↦ ?_, fun h s t ↦ ?_⟩ · exact h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩ · rintro ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩ exact h s t hs ht theorem iCondIndepFun_iff_condexp_inter_preimage_eq_mul {β : ι → Type*} (m : ∀ x, MeasurableSpace (β x)) (f : ∀ i, Ω → β i) (hf : ∀ i, Measurable (f i)) : iCondIndepFun m' hm' m f μ ↔ ∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)), (μ⟦⋂ i ∈ S, f i ⁻¹' sets i| m'⟧) =ᵐ[μ] ∏ i ∈ S, (μ⟦f i ⁻¹' sets i | m'⟧) := by rw [iCondIndepFun_iff] swap · exact hf refine ⟨fun h s sets h_sets ↦ ?_, fun h s sets h_sets ↦ ?_⟩ · refine h s (g := fun i ↦ f i ⁻¹' (sets i)) (fun i hi ↦ ?_) exact ⟨sets i, h_sets i hi, rfl⟩ · classical let g := fun i ↦ if hi : i ∈ s then (h_sets i hi).choose else Set.univ specialize h s (sets := g) (fun i hi ↦ ?_) · simp only [g, dif_pos hi] exact (h_sets i hi).choose_spec.1 · have hg : ∀ i ∈ s, sets i = f i ⁻¹' g i := by intro i hi rw [(h_sets i hi).choose_spec.2.symm] simp only [g, dif_pos hi] convert h with i hi i hi <;> exact hg i hi theorem condIndepFun_iff_condIndepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} (hf : Measurable f) (hg : Measurable g) : CondIndepFun m' hm' f g μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → CondIndepSet m' hm' (f ⁻¹' s) (g ⁻¹' t) μ := by simp only [CondIndepFun, CondIndepSet, Kernel.indepFun_iff_indepSet_preimage hf hg] @[symm] nonrec theorem CondIndepFun.symm {_ : MeasurableSpace β} {f g : Ω → β} (hfg : CondIndepFun m' hm' f g μ) : CondIndepFun m' hm' g f μ := hfg.symm theorem CondIndepFun.comp {γ γ' : Type*} {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} {_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'} (hfg : CondIndepFun m' hm' f g μ) (hφ : Measurable φ) (hψ : Measurable ψ) : CondIndepFun m' hm' (φ ∘ f) (ψ ∘ g) μ := Kernel.IndepFun.comp hfg hφ hψ theorem CondIndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β'] [MeasurableNeg β'] (hfg : CondIndepFun m' hm' f g μ) : CondIndepFun m' hm' f (-g) μ := hfg.comp measurable_id measurable_neg theorem CondIndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β] [MeasurableNeg β] (hfg : CondIndepFun m' hm' f g μ) : CondIndepFun m' hm' (-f) g μ := hfg.comp measurable_neg measurable_id section iCondIndepFun variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} @[nontriviality] lemma iCondIndepFun.of_subsingleton [Subsingleton ι] : iCondIndepFun m' hm' m f μ := Kernel.iIndepFun.of_subsingleton /-- If `f` is a family of mutually conditionally independent random variables (`iCondIndepFun m' hm' m f μ`) and `S, T` are two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is conditionally independent of the tuple `(f i)_i` for `i ∈ T`. -/ theorem iCondIndepFun.condIndepFun_finset {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iCondIndepFun m' hm' m f μ) (hf_meas : ∀ i, Measurable (f i)) : CondIndepFun m' hm' (fun a (i : S) => f i a) (fun a (i : T) => f i a) μ := Kernel.iIndepFun.indepFun_finset S T hST hf_Indep hf_meas theorem iCondIndepFun.condIndepFun_prod_mk {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} (hf_Indep : iCondIndepFun m' hm' m f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : CondIndepFun m' hm' (fun a => (f i a, f j a)) (f k) μ := Kernel.iIndepFun.indepFun_prod_mk hf_Indep hf_meas i j k hik hjk open Finset in lemma iCondIndepFun.condIndepFun_prod_mk_prod_mk (h_indep : iCondIndepFun m' hm' m f μ) (hf : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : CondIndepFun m' hm' (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ := by classical let g (i j : ι) (v : Π x : ({i, j} : Finset ι), β x) : β i × β j := ⟨v ⟨i, mem_insert_self _ _⟩, v ⟨j, mem_insert_of_mem <| mem_singleton_self _⟩⟩ have hg (i j : ι) : Measurable (g i j) := by fun_prop exact (h_indep.indepFun_finset {i, j} {k, l} (by aesop) hf).comp (hg i j) (hg k l) end iCondIndepFun section Mul variable {β : Type*} {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β} @[to_additive] lemma iCondIndepFun.indepFun_mul_left (hf_indep : iCondIndepFun m' hm' (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : CondIndepFun m' hm' (f i * f j) (f k) μ := Kernel.iIndepFun.indepFun_mul_left hf_indep hf_meas i j k hik hjk @[to_additive] lemma iCondIndepFun.indepFun_mul_right (hf_indep : iCondIndepFun m' hm' (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) : CondIndepFun m' hm' (f i) (f j * f k) μ := Kernel.iIndepFun.indepFun_mul_right hf_indep hf_meas i j k hij hik @[to_additive] lemma iCondIndepFun.indepFun_mul_mul (hf_indep : iCondIndepFun m' hm' (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : CondIndepFun m' hm' (f i * f j) (f k * f l) μ := Kernel.iIndepFun.indepFun_mul_mul hf_indep hf_meas i j k l hik hil hjk hjl end Mul section Div variable {β : Type*} {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β} @[to_additive] lemma iCondIndepFun.indepFun_div_left (hf_indep : iCondIndepFun m' hm' (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : CondIndepFun m' hm' (f i / f j) (f k) μ := Kernel.iIndepFun.indepFun_div_left hf_indep hf_meas i j k hik hjk @[to_additive] lemma iCondIndepFun.indepFun_div_right (hf_indep : iCondIndepFun m' hm' (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) : CondIndepFun m' hm' (f i) (f j / f k) μ := Kernel.iIndepFun.indepFun_div_right hf_indep hf_meas i j k hij hik @[to_additive] lemma iCondIndepFun.indepFun_div_div (hf_indep : iCondIndepFun m' hm' (fun _ ↦ m) f μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : CondIndepFun m' hm' (f i / f j) (f k / f l) μ := Kernel.iIndepFun.indepFun_div_div hf_indep hf_meas i j k l hik hil hjk hjl end Div section CommMonoid variable {β : Type*} {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β} @[to_additive] theorem iCondIndepFun.condIndepFun_finset_prod_of_not_mem (hf_Indep : iCondIndepFun m' hm' (fun _ => m) f μ) (hf_meas : ∀ i, Measurable (f i)) {s : Finset ι} {i : ι} (hi : i ∉ s) : CondIndepFun m' hm' (∏ j ∈ s, f j) (f i) μ := Kernel.iIndepFun.indepFun_finset_prod_of_not_mem hf_Indep hf_meas hi @[to_additive] theorem iCondIndepFun.condIndepFun_prod_range_succ {f : ℕ → Ω → β} (hf_Indep : iCondIndepFun m' hm' (fun _ => m) f μ) (hf_meas : ∀ i, Measurable (f i)) (n : ℕ) : CondIndepFun m' hm' (∏ j ∈ Finset.range n, f j) (f n) μ := Kernel.iIndepFun.indepFun_prod_range_succ hf_Indep hf_meas n end CommMonoid theorem iCondIndepSet.iCondIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β} {s : ι → Set Ω} (hs : iCondIndepSet m' hm' s μ) : iCondIndepFun m' hm' (fun _n => m) (fun n => (s n).indicator fun _ω => 1) μ := Kernel.iIndepSet.iIndepFun_indicator hs end CondIndepFun end ProbabilityTheory
Probability\Independence\Kernel.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.Constructions.Pi import Mathlib.Probability.Kernel.Basic /-! # Independence with respect to a kernel and a measure A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ : Kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`, `κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. This notion of independence is a generalization of both independence and conditional independence. For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condexpKernel` and `μ` is the ambiant measure. For (non-conditional) independence, `κ = Kernel.const Unit μ` and the measure is the Dirac measure on `Unit`. The main purpose of this file is to prove only once the properties that hold for both conditional and non-conditional independence. ## Main definitions * `ProbabilityTheory.Kernel.iIndepSets`: independence of a family of sets of sets. Variant for two sets of sets: `ProbabilityTheory.Kernel.IndepSets`. * `ProbabilityTheory.Kernel.iIndep`: independence of a family of σ-algebras. Variant for two σ-algebras: `Indep`. * `ProbabilityTheory.Kernel.iIndepSet`: independence of a family of sets. Variant for two sets: `ProbabilityTheory.Kernel.IndepSet`. * `ProbabilityTheory.Kernel.iIndepFun`: independence of a family of functions (random variables). Variant for two functions: `ProbabilityTheory.Kernel.IndepFun`. See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these definitions in the particular case of the usual independence notion. ## Main statements * `ProbabilityTheory.Kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `ProbabilityTheory.Kernel.IndepSets.Indep`: variant with two π-systems. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory.Kernel variable {α Ω ι : Type*} section Definitions variable {_mα : MeasurableSpace α} /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) /-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (fun i ↦ generateFrom {s i}) κ μ /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (generateFrom {s}) (generateFrom {t}) κ μ /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ end Definitions section ByDefinition variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x} lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha] lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha simp [← ha] protected lemma iIndepFun.iIndep (hf : iIndepFun mβ f κ μ) : iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf lemma iIndepFun.meas_biInter (hf : iIndepFun mβ f κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun mβ f κ μ) (hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht end ByDefinition section Indep variable {_mα : MeasurableSpace α} @[symm] theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) : IndepSets s₂ s₁ κ μ := by intros t1 t2 ht1 ht2 filter_upwards [h t2 t1 ht2 ht1] with a ha rwa [Set.inter_comm, mul_comm] @[symm] theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h : Indep m₁ m₂ κ μ) : Indep m₂ m₁ κ μ := IndepSets.symm h theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] : Indep m' ⊥ κ μ := by intros s t _ ht rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht refine Filter.eventually_of_forall (fun a ↦ ?_) cases' ht with ht ht · rw [ht, Set.inter_empty, measure_empty, mul_zero] · rw [ht, Set.inter_univ, measure_univ, mul_one] theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] : Indep ⊥ m' κ μ := (indep_bot_right m').symm theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (s : Set Ω) : IndepSet s ∅ κ μ := by simp only [IndepSet, generateFrom_singleton_empty] exact indep_bot_right _ theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (s : Set Ω) : IndepSet ∅ s κ μ := (indepSet_empty_right s).symm theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2) theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2 theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2) theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) : IndepSets (s₁ ∪ s₂) s' κ μ := by intro t1 t2 ht1 ht2 cases' (Set.mem_union _ _ _).mp ht1 with ht1₁ ht1₂ · exact h₁ t1 t2 ht1₁ ht2 · exact h₂ t1 t2 ht1₂ ht2 @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ := ⟨fun h => ⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left, indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩, fun h => IndepSets.union h.left h.right⟩ theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) : IndepSets (⋃ n, s n) s' κ μ := by intro t1 t2 ht1 ht2 rw [Set.mem_iUnion] at ht1 cases' ht1 with n ht1 exact hyp n t1 t2 ht1 ht2 theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋃ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 simp_rw [Set.mem_iUnion] at ht1 rcases ht1 with ⟨n, hpn, ht1⟩ exact hyp n hpn t1 t2 ht1 ht2 theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) : IndepSets (s₁ ∩ s₂) s' κ μ := fun t1 t2 ht1 ht2 => h₁ t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2 theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h : ∃ n, IndepSets (s n) s' κ μ) : IndepSets (⋂ n, s n) s' κ μ := by intro t1 t2 ht1 ht2; cases' h with n h; exact h t1 t2 (Set.mem_iInter.mp ht1 n) ht2 theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋂ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 rcases h with ⟨n, hn, h⟩ exact h t1 t2 (Set.biInter_subset_of_mem hn ht1) ht2 theorem iIndep_comap_mem_iff {f : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) κ μ ↔ iIndepSet f κ μ := by simp_rw [← generateFrom_singleton, iIndepSet] theorem iIndepSets_singleton_iff {s : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : iIndepSets (fun i ↦ {s i}) κ μ ↔ ∀ S : Finset ι, ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := by refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩ filter_upwards [h S] with a ha have : ∀ i ∈ S, κ a (f i) = κ a (s i) := fun i hi ↦ by rw [hf i hi] rwa [Finset.prod_congr rfl this, Set.iInter₂_congr hf] theorem indepSets_singleton_iff {s t : Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : IndepSets {s} {t} κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := ⟨fun h ↦ h s t rfl rfl, fun h s1 t1 hs1 ht1 ↦ by rwa [Set.mem_singleton_iff.mp hs1, Set.mem_singleton_iff.mp ht1]⟩ end Indep /-! ### Deducing `Indep` from `iIndep` -/ section FromiIndepToIndep variable {_mα : MeasurableSpace α} theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : iIndepSets s κ μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) κ μ := by classical intro t₁ t₂ ht₁ ht₂ have hf_m : ∀ x : ι, x ∈ ({i, j} : Finset ι) → ite (x = i) t₁ t₂ ∈ s x := by intro x hx cases' Finset.mem_insert.mp hx with hx hx · simp [hx, ht₁] · simp [Finset.mem_singleton.mp hx, hij.symm, ht₂] have h1 : t₁ = ite (i = i) t₁ t₂ := by simp only [if_true, eq_self_iff_true] have h2 : t₂ = ite (j = i) t₁ t₂ := by simp only [hij.symm, if_false] have h_inter : ⋂ (t : ι) (_ : t ∈ ({i, j} : Finset ι)), ite (t = i) t₁ t₂ = ite (i = i) t₁ t₂ ∩ ite (j = i) t₁ t₂ := by simp only [Finset.set_biInter_singleton, Finset.set_biInter_insert] filter_upwards [h_indep {i, j} hf_m] with a h_indep' have h_prod : (∏ t ∈ ({i, j} : Finset ι), κ a (ite (t = i) t₁ t₂)) = κ a (ite (i = i) t₁ t₂) * κ a (ite (j = i) t₁ t₂) := by simp only [hij, Finset.prod_singleton, Finset.prod_insert, not_false_iff, Finset.mem_singleton] rw [h1] nth_rw 2 [h2] nth_rw 4 [h2] rw [← h_inter, ← h_prod, h_indep'] theorem iIndep.indep {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : iIndep m κ μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) κ μ := iIndepSets.indepSets h_indep hij theorem iIndepFun.indepFun {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun m f κ μ) {i j : ι} (hij : i ≠ j) : IndepFun (f i) (f j) κ μ := hf_Indep.indep hij end FromiIndepToIndep /-! ## π-system lemma Independence of measurable spaces is equivalent to independence of generating π-systems. -/ section FromMeasurableSpacesToSetsOfSets /-! ### Independence of measurable space structures implies independence of generating π-systems -/ variable {_mα : MeasurableSpace α} theorem iIndep.iIndepSets {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {m : ι → MeasurableSpace Ω} {s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m κ μ) : iIndepSets s κ μ := fun S f hfs => h_indep S fun x hxS => ((hms x).symm ▸ measurableSet_generateFrom (hfs x hxS) : MeasurableSet[m x] (f x)) theorem Indep.indepSets {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {s1 s2 : Set (Set Ω)} (h_indep : Indep (generateFrom s1) (generateFrom s2) κ μ) : IndepSets s1 s2 κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (measurableSet_generateFrom ht1) (measurableSet_generateFrom ht2) end FromMeasurableSpacesToSetsOfSets section FromPiSystemsToMeasurableSpaces /-! ### Independence of generating π-systems implies independence of measurable space structures -/ variable {_mα : MeasurableSpace α} theorem IndepSets.indep_aux {m₂ m : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h2 : m₂ ≤ m) (hp2 : IsPiSystem p2) (hpm2 : m₂ = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) {t1 t2 : Set Ω} (ht1 : t1 ∈ p1) (ht1m : MeasurableSet[m] t1) (ht2m : MeasurableSet[m₂] t2) : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2 := by refine @induction_on_inter _ (fun t ↦ ∀ᵐ a ∂μ, κ a (t1 ∩ t) = κ a t1 * κ a t) _ m₂ hpm2 hp2 ?_ ?_ ?_ ?_ t2 ht2m · simp only [Set.inter_empty, measure_empty, mul_zero, eq_self_iff_true, Filter.eventually_true] · exact fun t ht_mem_p2 ↦ hyp t1 t ht1 ht_mem_p2 · intros t ht h filter_upwards [h] with a ha have : t1 ∩ tᶜ = t1 \ (t1 ∩ t) := by rw [Set.diff_self_inter, Set.diff_eq_compl_inter, Set.inter_comm] rw [this, measure_diff Set.inter_subset_left (ht1m.inter (h2 _ ht)) (measure_ne_top (κ a) _), measure_compl (h2 _ ht) (measure_ne_top (κ a) t), measure_univ, ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, ha] · intros f hf_disj hf_meas h rw [← ae_all_iff] at h filter_upwards [h] with a ha rw [Set.inter_iUnion, measure_iUnion] · rw [measure_iUnion hf_disj (fun i ↦ h2 _ (hf_meas i))] rw [← ENNReal.tsum_mul_left] congr with i rw [ha i] · intros i j hij rw [Function.onFun, Set.inter_comm t1, Set.inter_comm t1] exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij)) · exact fun i ↦ ht1m.inter (h2 _ (hf_meas i)) /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem IndepSets.indep {m1 m2 m : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) : Indep m1 m2 κ μ := by intros t1 t2 ht1 ht2 refine @induction_on_inter _ (fun t ↦ ∀ᵐ (a : α) ∂μ, κ a (t ∩ t2) = κ a t * κ a t2) _ m1 hpm1 hp1 ?_ ?_ ?_ ?_ _ ht1 · simp only [Set.empty_inter, measure_empty, zero_mul, eq_self_iff_true, Filter.eventually_true] · intros t ht_mem_p1 have ht1 : MeasurableSet[m] t := by refine h1 _ ?_ rw [hpm1] exact measurableSet_generateFrom ht_mem_p1 exact IndepSets.indep_aux h2 hp2 hpm2 hyp ht_mem_p1 ht1 ht2 · intros t ht h filter_upwards [h] with a ha have : tᶜ ∩ t2 = t2 \ (t ∩ t2) := by rw [Set.inter_comm t, Set.diff_self_inter, Set.diff_eq_compl_inter] rw [this, Set.inter_comm t t2, measure_diff Set.inter_subset_left ((h2 _ ht2).inter (h1 _ ht)) (measure_ne_top (κ a) _), Set.inter_comm, ha, measure_compl (h1 _ ht) (measure_ne_top (κ a) t), measure_univ, mul_comm (1 - κ a t), ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, mul_comm] · intros f hf_disj hf_meas h rw [← ae_all_iff] at h filter_upwards [h] with a ha rw [Set.inter_comm, Set.inter_iUnion, measure_iUnion] · rw [measure_iUnion hf_disj (fun i ↦ h1 _ (hf_meas i))] rw [← ENNReal.tsum_mul_right] congr 1 with i rw [Set.inter_comm t2, ha i] · intros i j hij rw [Function.onFun, Set.inter_comm t2, Set.inter_comm t2] exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij)) · exact fun i ↦ (h2 _ ht2).inter (h1 _ (hf_meas i)) theorem IndepSets.indep' {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] {p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 κ μ) : Indep (generateFrom p1) (generateFrom p2) κ μ := hyp.indep (generateFrom_le hp1m) (generateFrom_le hp2m) hp1 hp2 rfl rfl variable {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} theorem indepSets_piiUnionInter_of_disjoint [IsMarkovKernel κ] {s : ι → Set (Set Ω)} {S T : Set ι} (h_indep : iIndepSets s κ μ) (hST : Disjoint S T) : IndepSets (piiUnionInter s S) (piiUnionInter s T) κ μ := by rintro t1 t2 ⟨p1, hp1, f1, ht1_m, ht1_eq⟩ ⟨p2, hp2, f2, ht2_m, ht2_eq⟩ classical let g i := ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ have h_P_inter : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = ∏ n ∈ p1 ∪ p2, κ a (g n) := by have hgm : ∀ i ∈ p1 ∪ p2, g i ∈ s i := by intro i hi_mem_union rw [Finset.mem_union] at hi_mem_union cases' hi_mem_union with hi1 hi2 · have hi2 : i ∉ p2 := fun hip2 => Set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2) simp_rw [g, if_pos hi1, if_neg hi2, Set.inter_univ] exact ht1_m i hi1 · have hi1 : i ∉ p1 := fun hip1 => Set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1) simp_rw [g, if_neg hi1, if_pos hi2, Set.univ_inter] exact ht2_m i hi2 have h_p1_inter_p2 : ((⋂ x ∈ p1, f1 x) ∩ ⋂ x ∈ p2, f2 x) = ⋂ i ∈ p1 ∪ p2, ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ := by ext1 x simp only [Set.mem_ite_univ_right, Set.mem_inter_iff, Set.mem_iInter, Finset.mem_union] exact ⟨fun h i _ => ⟨h.1 i, h.2 i⟩, fun h => ⟨fun i hi => (h i (Or.inl hi)).1 hi, fun i hi => (h i (Or.inr hi)).2 hi⟩⟩ filter_upwards [h_indep _ hgm] with a ha rw [ht1_eq, ht2_eq, h_p1_inter_p2, ← ha] filter_upwards [h_P_inter, h_indep p1 ht1_m, h_indep p2 ht2_m] with a h_P_inter ha1 ha2 have h_μg : ∀ n, κ a (g n) = (ite (n ∈ p1) (κ a (f1 n)) 1) * (ite (n ∈ p2) (κ a (f2 n)) 1) := by intro n dsimp only [g] split_ifs with h1 h2 · exact absurd rfl (Set.disjoint_iff_forall_ne.mp hST (hp1 h1) (hp2 h2)) all_goals simp only [measure_univ, one_mul, mul_one, Set.inter_univ, Set.univ_inter] simp_rw [h_P_inter, h_μg, Finset.prod_mul_distrib, Finset.prod_ite_mem (p1 ∪ p2) p1 (fun x ↦ κ a (f1 x)), Finset.union_inter_cancel_left, Finset.prod_ite_mem (p1 ∪ p2) p2 (fun x => κ a (f2 x)), Finset.union_inter_cancel_right, ht1_eq, ← ha1, ht2_eq, ← ha2] theorem iIndepSet.indep_generateFrom_of_disjoint [IsMarkovKernel κ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (S T : Set ι) (hST : Disjoint S T) : Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) κ μ := by rw [← generateFrom_piiUnionInter_singleton_left, ← generateFrom_piiUnionInter_singleton_left] refine IndepSets.indep' (fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) (fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) ?_ ?_ ?_ · exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k · exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k · exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _ · exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _ · classical exact indepSets_piiUnionInter_of_disjoint (iIndep.iIndepSets (fun n => rfl) hs) hST theorem indep_iSup_of_disjoint [IsMarkovKernel κ] {m : ι → MeasurableSpace Ω} (h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m κ μ) {S T : Set ι} (hST : Disjoint S T) : Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) κ μ := by refine IndepSets.indep (iSup₂_le fun i _ => h_le i) (iSup₂_le fun i _ => h_le i) ?_ ?_ (generateFrom_piiUnionInter_measurableSet m S).symm (generateFrom_piiUnionInter_measurableSet m T).symm ?_ · exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _ · exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _ · classical exact indepSets_piiUnionInter_of_disjoint h_indep hST theorem indep_iSup_of_directed_le {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Directed (· ≤ ·) m) : Indep (⨆ i, m i) m' κ μ := by let p : ι → Set (Set Ω) := fun n => { t | MeasurableSet[m n] t } have hp : ∀ n, IsPiSystem (p n) := fun n => @isPiSystem_measurableSet Ω (m n) have h_gen_n : ∀ n, m n = generateFrom (p n) := fun n => (@generateFrom_measurableSet Ω (m n)).symm have hp_supr_pi : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp hm let p' := { t : Set Ω | MeasurableSet[m'] t } have hp'_pi : IsPiSystem p' := @isPiSystem_measurableSet Ω m' have h_gen' : m' = generateFrom p' := (@generateFrom_measurableSet Ω m').symm -- the π-systems defined are independent have h_pi_system_indep : IndepSets (⋃ n, p n) p' κ μ := by refine IndepSets.iUnion ?_ conv at h_indep => intro i rw [h_gen_n i, h_gen'] exact fun n => (h_indep n).indepSets -- now go from π-systems to σ-algebras refine IndepSets.indep (iSup_le h_le) h_le' hp_supr_pi hp'_pi ?_ h_gen' h_pi_system_indep exact (generateFrom_iUnion_measurableSet _).symm theorem iIndepSet.indep_generateFrom_lt [Preorder ι] [IsMarkovKernel κ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) : Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) κ μ := by convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {i} { j | j < i } (Set.disjoint_singleton_left.mpr (lt_irrefl _)) simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton'] theorem iIndepSet.indep_generateFrom_le [LinearOrder ι] [IsMarkovKernel κ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) {k : ι} (hk : i < k) : Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) κ μ := by convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {k} { j | j ≤ i } (Set.disjoint_singleton_left.mpr hk.not_le) simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton'] theorem iIndepSet.indep_generateFrom_le_nat [IsMarkovKernel κ] {s : ℕ → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (n : ℕ) : Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) κ μ := iIndepSet.indep_generateFrom_le hsm hs _ n.lt_succ_self theorem indep_iSup_of_monotone [SemilatticeSup ι] {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Monotone m) : Indep (⨆ i, m i) m' κ μ := indep_iSup_of_directed_le h_indep h_le h_le' (Monotone.directed_le hm) theorem indep_iSup_of_antitone [SemilatticeInf ι] {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Antitone m) : Indep (⨆ i, m i) m' κ μ := indep_iSup_of_directed_le h_indep h_le h_le' hm.directed_le theorem iIndepSets.piiUnionInter_of_not_mem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι} (hp_ind : iIndepSets π κ μ) (haS : a ∉ S) : IndepSets (piiUnionInter π S) (π a) κ μ := by rintro t1 t2 ⟨s, hs_mem, ft1, hft1_mem, ht1_eq⟩ ht2_mem_pia rw [Finset.coe_subset] at hs_mem classical let f := fun n => ite (n = a) t2 (ite (n ∈ s) (ft1 n) Set.univ) have h_f_mem : ∀ n ∈ insert a s, f n ∈ π n := by intro n hn_mem_insert dsimp only [f] cases' Finset.mem_insert.mp hn_mem_insert with hn_mem hn_mem · simp [hn_mem, ht2_mem_pia] · have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hn_mem) simp [hn_ne_a, hn_mem, hft1_mem n hn_mem] have h_f_mem_pi : ∀ n ∈ s, f n ∈ π n := fun x hxS => h_f_mem x (by simp [hxS]) have h_t1 : t1 = ⋂ n ∈ s, f n := by suffices h_forall : ∀ n ∈ s, f n = ft1 n by rw [ht1_eq] ext x simp_rw [Set.mem_iInter] conv => lhs; intro i hns; rw [← h_forall i hns] intro n hnS have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hnS) simp_rw [f, if_pos hnS, if_neg hn_ne_a] have h_μ_t1 : ∀ᵐ a' ∂μ, κ a' t1 = ∏ n ∈ s, κ a' (f n) := by filter_upwards [hp_ind s h_f_mem_pi] with a' ha' rw [h_t1, ← ha'] have h_t2 : t2 = f a := by simp [f] have h_μ_inter : ∀ᵐ a' ∂μ, κ a' (t1 ∩ t2) = ∏ n ∈ insert a s, κ a' (f n) := by have h_t1_inter_t2 : t1 ∩ t2 = ⋂ n ∈ insert a s, f n := by rw [h_t1, h_t2, Finset.set_biInter_insert, Set.inter_comm] filter_upwards [hp_ind (insert a s) h_f_mem] with a' ha' rw [h_t1_inter_t2, ← ha'] have has : a ∉ s := fun has_mem => haS (hs_mem has_mem) filter_upwards [h_μ_t1, h_μ_inter] with a' ha1 ha2 rw [ha2, Finset.prod_insert has, h_t2, mul_comm, ha1] /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem iIndepSets.iIndep [IsMarkovKernel κ] (m : ι → MeasurableSpace Ω) (h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n)) (h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π κ μ) : iIndep m κ μ := by classical intro s f refine Finset.induction ?_ ?_ s · simp only [Finset.not_mem_empty, Set.mem_setOf_eq, IsEmpty.forall_iff, implies_true, Set.iInter_of_empty, Set.iInter_univ, measure_univ, Finset.prod_empty, Filter.eventually_true, forall_true_left] · intro a S ha_notin_S h_rec hf_m have hf_m_S : ∀ x ∈ S, MeasurableSet[m x] (f x) := fun x hx => hf_m x (by simp [hx]) let p := piiUnionInter π S set m_p := generateFrom p with hS_eq_generate have h_indep : Indep m_p (m a) κ μ := by have hp : IsPiSystem p := isPiSystem_piiUnionInter π h_pi S have h_le' : ∀ i, generateFrom (π i) ≤ _mΩ := fun i ↦ (h_generate i).symm.trans_le (h_le i) have hm_p : m_p ≤ _mΩ := generateFrom_piiUnionInter_le π h_le' S exact IndepSets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a) (iIndepSets.piiUnionInter_of_not_mem h_ind ha_notin_S) have h := h_indep.symm (f a) (⋂ n ∈ S, f n) (hf_m a (Finset.mem_insert_self a S)) ?_ · filter_upwards [h_rec hf_m_S, h] with a' ha' h' rwa [Finset.set_biInter_insert, Finset.prod_insert ha_notin_S, ← ha'] · have h_le_p : ∀ i ∈ S, m i ≤ m_p := by intros n hn rw [hS_eq_generate, h_generate n] exact le_generateFrom_piiUnionInter (S : Set ι) hn have h_S_f : ∀ i ∈ S, MeasurableSet[m_p] (f i) := fun i hi ↦ (h_le_p i hi) (f i) (hf_m_S i hi) exact S.measurableSet_biInter h_S_f end FromPiSystemsToMeasurableSpaces section IndepSet /-! ### Independence of measurable sets We prove the following equivalences on `IndepSet`, for measurable sets `s, t`. * `IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t`, * `IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ`. -/ variable {_mα : MeasurableSpace α} theorem iIndepSet_iff_iIndepSets_singleton {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} [IsMarkovKernel κ] {μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f κ μ ↔ iIndepSets (fun i ↦ {f i}) κ μ := ⟨iIndep.iIndepSets fun _ ↦ rfl, iIndepSets.iIndep _ (fun i ↦ generateFrom_le <| by rintro t (rfl : t = _); exact hf _) _ (fun _ ↦ IsPiSystem.singleton _) fun _ ↦ rfl⟩ theorem iIndepSet_iff_meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} [IsMarkovKernel κ] {μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f κ μ ↔ ∀ s, ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := (iIndepSet_iff_iIndepSets_singleton hf).trans iIndepSets_singleton_iff theorem iIndepSets.iIndepSet_of_mem {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} [IsMarkovKernel κ] {μ : Measure α} {π : ι → Set (Set Ω)} {f : ι → Set Ω} (hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i)) (hπ : iIndepSets π κ μ) : iIndepSet f κ μ := (iIndepSet_iff_meas_biInter hf).2 fun _t ↦ hπ.meas_biInter _ fun _i _ ↦ hfπ _ variable {s t : Set Ω} (S T : Set (Set Ω)) theorem indepSet_iff_indepSets_singleton {m0 : MeasurableSpace Ω} (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α) [IsMarkovKernel κ] : IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ := ⟨Indep.indepSets, fun h => IndepSets.indep (generateFrom_le fun u hu => by rwa [Set.mem_singleton_iff.mp hu]) (generateFrom_le fun u hu => by rwa [Set.mem_singleton_iff.mp hu]) (IsPiSystem.singleton s) (IsPiSystem.singleton t) rfl rfl h⟩ theorem indepSet_iff_measure_inter_eq_mul {_m0 : MeasurableSpace Ω} (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α) [IsMarkovKernel κ] : IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := (indepSet_iff_indepSets_singleton hs_meas ht_meas κ μ).trans indepSets_singleton_iff theorem IndepSets.indepSet_of_mem {_m0 : MeasurableSpace Ω} (hs : s ∈ S) (ht : t ∈ T) (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α) [IsMarkovKernel κ] (h_indep : IndepSets S T κ μ) : IndepSet s t κ μ := (indepSet_iff_measure_inter_eq_mul hs_meas ht_meas κ μ).mpr (h_indep s t hs ht) theorem Indep.indepSet_of_measurableSet {m₁ m₂ m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s) (ht : MeasurableSet[m₂] t) : IndepSet s t κ μ := by refine fun s' t' hs' ht' => h_indep s' t' ?_ ?_ · refine @generateFrom_induction _ (fun u => MeasurableSet[m₁] u) {s} ?_ ?_ ?_ ?_ _ hs' · simp only [Set.mem_singleton_iff, forall_eq, hs] · exact @MeasurableSet.empty _ m₁ · exact fun u hu => hu.compl · exact fun f hf => MeasurableSet.iUnion hf · refine @generateFrom_induction _ (fun u => MeasurableSet[m₂] u) {t} ?_ ?_ ?_ ?_ _ ht' · simp only [Set.mem_singleton_iff, forall_eq, ht] · exact @MeasurableSet.empty _ m₂ · exact fun u hu => hu.compl · exact fun f hf => MeasurableSet.iUnion hf theorem indep_iff_forall_indepSet (m₁ m₂ : MeasurableSpace Ω) {_m0 : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α) : Indep m₁ m₂ κ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t κ μ := ⟨fun h => fun _s _t hs ht => h.indepSet_of_measurableSet hs ht, fun h s t hs ht => h s t hs ht s t (measurableSet_generateFrom (Set.mem_singleton s)) (measurableSet_generateFrom (Set.mem_singleton t))⟩ end IndepSet section IndepFun /-! ### Independence of random variables -/ variable {β β' γ γ' : Type*} {_mα : MeasurableSpace α} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {f : Ω → β} {g : Ω → β'} theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} : IndepFun f g κ μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → ∀ᵐ a ∂μ, κ a (f ⁻¹' s ∩ g ⁻¹' t) = κ a (f ⁻¹' s) * κ a (g ⁻¹' t) := by constructor <;> intro h · refine fun s t hs ht => h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩ · rintro _ _ ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩; exact h s t hs ht theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*} (m : ∀ x, MeasurableSpace (β x)) (f : ∀ i, Ω → β i) : iIndepFun m f κ μ ↔ ∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)), ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, (f i) ⁻¹' (sets i)) = ∏ i ∈ S, κ a ((f i) ⁻¹' (sets i)) := by refine ⟨fun h S sets h_meas => h _ fun i hi_mem => ⟨sets i, h_meas i hi_mem, rfl⟩, ?_⟩ intro h S setsΩ h_meas classical let setsβ : ∀ i : ι, Set (β i) := fun i => dite (i ∈ S) (fun hi_mem => (h_meas i hi_mem).choose) fun _ => Set.univ have h_measβ : ∀ i ∈ S, MeasurableSet[m i] (setsβ i) := by intro i hi_mem simp_rw [setsβ, dif_pos hi_mem] exact (h_meas i hi_mem).choose_spec.1 have h_preim : ∀ i ∈ S, setsΩ i = f i ⁻¹' setsβ i := by intro i hi_mem simp_rw [setsβ, dif_pos hi_mem] exact (h_meas i hi_mem).choose_spec.2.symm have h_left_eq : ∀ a, κ a (⋂ i ∈ S, setsΩ i) = κ a (⋂ i ∈ S, (f i) ⁻¹' (setsβ i)) := by intro a congr with x simp_rw [Set.mem_iInter] constructor <;> intro h i hi_mem <;> specialize h i hi_mem · rwa [h_preim i hi_mem] at h · rwa [h_preim i hi_mem] have h_right_eq : ∀ a, (∏ i ∈ S, κ a (setsΩ i)) = ∏ i ∈ S, κ a ((f i) ⁻¹' (setsβ i)) := by refine fun a ↦ Finset.prod_congr rfl fun i hi_mem => ?_ rw [h_preim i hi_mem] filter_upwards [h S h_measβ] with a ha rw [h_left_eq a, h_right_eq a, ha] theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} [IsMarkovKernel κ] (hf : Measurable f) (hg : Measurable g) : IndepFun f g κ μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) κ μ := by refine indepFun_iff_measure_inter_preimage_eq_mul.trans ?_ constructor <;> intro h s t hs ht <;> specialize h s t hs ht · rwa [indepSet_iff_measure_inter_eq_mul (hf hs) (hg ht) κ μ] · rwa [← indepSet_iff_measure_inter_eq_mul (hf hs) (hg ht) κ μ] @[symm] nonrec theorem IndepFun.symm {_ : MeasurableSpace β} {_ : MeasurableSpace β'} (hfg : IndepFun f g κ μ) : IndepFun g f κ μ := hfg.symm theorem IndepFun.ae_eq {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} {f' : Ω → β} {g' : Ω → β'} (hfg : IndepFun f g κ μ) (hf : ∀ᵐ a ∂μ, f =ᵐ[κ a] f') (hg : ∀ᵐ a ∂μ, g =ᵐ[κ a] g') : IndepFun f' g' κ μ := by rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩ filter_upwards [hf, hg, hfg _ _ ⟨_, hA, rfl⟩ ⟨_, hB, rfl⟩] with a hf' hg' hfg' have h1 : f ⁻¹' A =ᵐ[κ a] f' ⁻¹' A := hf'.fun_comp A have h2 : g ⁻¹' B =ᵐ[κ a] g' ⁻¹' B := hg'.fun_comp B rwa [← measure_congr h1, ← measure_congr h2, ← measure_congr (h1.inter h2)] theorem IndepFun.comp {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} {mγ : MeasurableSpace γ} {mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'} (hfg : IndepFun f g κ μ) (hφ : Measurable φ) (hψ : Measurable ψ) : IndepFun (φ ∘ f) (ψ ∘ g) κ μ := by rintro _ _ ⟨A, hA, rfl⟩ ⟨B, hB, rfl⟩ apply hfg · exact ⟨φ ⁻¹' A, hφ hA, Set.preimage_comp.symm⟩ · exact ⟨ψ ⁻¹' B, hψ hB, Set.preimage_comp.symm⟩ theorem IndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β'] [MeasurableNeg β'] (hfg : IndepFun f g κ μ) : IndepFun f (-g) κ μ := hfg.comp measurable_id measurable_neg theorem IndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β] [MeasurableNeg β] (hfg : IndepFun f g κ μ) : IndepFun (-f) g κ μ := hfg.comp measurable_neg measurable_id section iIndepFun variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} @[nontriviality] lemma iIndepFun.of_subsingleton [IsMarkovKernel κ] [Subsingleton ι] : iIndepFun m f κ μ := by refine (iIndepFun_iff_measure_inter_preimage_eq_mul ..).2 fun s f' hf' ↦ ?_ obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty · simp · have : s = {x} := by ext y; simp [Subsingleton.elim y x, hx] simp [this] lemma iIndepFun.ae_isProbabilityMeasure (h : iIndepFun m f κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := by simpa [isProbabilityMeasure_iff] using h.meas_biInter (S := ∅) (s := fun _ ↦ Set.univ) /-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the tuple `(f i)_i` for `i ∈ T`. -/ theorem iIndepFun.indepFun_finset [IsMarkovKernel κ] (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iIndepFun m f κ μ) (hf_meas : ∀ i, Measurable (f i)) : IndepFun (fun a (i : S) => f i a) (fun a (i : T) => f i a) κ μ := by -- We introduce π-systems, built from the π-system of boxes which generates `MeasurableSpace.pi`. let πSβ := Set.pi (Set.univ : Set S) '' Set.pi (Set.univ : Set S) fun i => { s : Set (β i) | MeasurableSet[m i] s } let πS := { s : Set Ω | ∃ t ∈ πSβ, (fun a (i : S) => f i a) ⁻¹' t = s } have hπS_pi : IsPiSystem πS := by exact IsPiSystem.comap (@isPiSystem_pi _ _ ?_) _ have hπS_gen : (MeasurableSpace.pi.comap fun a (i : S) => f i a) = generateFrom πS := by rw [generateFrom_pi.symm, comap_generateFrom] congr let πTβ := Set.pi (Set.univ : Set T) '' Set.pi (Set.univ : Set T) fun i => { s : Set (β i) | MeasurableSet[m i] s } let πT := { s : Set Ω | ∃ t ∈ πTβ, (fun a (i : T) => f i a) ⁻¹' t = s } have hπT_pi : IsPiSystem πT := by exact IsPiSystem.comap (@isPiSystem_pi _ _ ?_) _ have hπT_gen : (MeasurableSpace.pi.comap fun a (i : T) => f i a) = generateFrom πT := by rw [generateFrom_pi.symm, comap_generateFrom] congr -- To prove independence, we prove independence of the generating π-systems. refine IndepSets.indep (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i)) (Measurable.comap_le (measurable_pi_iff.mpr fun i => hf_meas i)) hπS_pi hπT_pi hπS_gen hπT_gen ?_ rintro _ _ ⟨s, ⟨sets_s, hs1, hs2⟩, rfl⟩ ⟨t, ⟨sets_t, ht1, ht2⟩, rfl⟩ simp only [Set.mem_univ_pi, Set.mem_setOf_eq] at hs1 ht1 rw [← hs2, ← ht2] classical let sets_s' : ∀ i : ι, Set (β i) := fun i => dite (i ∈ S) (fun hi => sets_s ⟨i, hi⟩) fun _ => Set.univ have h_sets_s'_eq : ∀ {i} (hi : i ∈ S), sets_s' i = sets_s ⟨i, hi⟩ := by intro i hi; simp_rw [sets_s', dif_pos hi] have h_sets_s'_univ : ∀ {i} (_hi : i ∈ T), sets_s' i = Set.univ := by intro i hi; simp_rw [sets_s', dif_neg (Finset.disjoint_right.mp hST hi)] let sets_t' : ∀ i : ι, Set (β i) := fun i => dite (i ∈ T) (fun hi => sets_t ⟨i, hi⟩) fun _ => Set.univ have h_sets_t'_univ : ∀ {i} (_hi : i ∈ S), sets_t' i = Set.univ := by intro i hi; simp_rw [sets_t', dif_neg (Finset.disjoint_left.mp hST hi)] have h_meas_s' : ∀ i ∈ S, MeasurableSet (sets_s' i) := by intro i hi; rw [h_sets_s'_eq hi]; exact hs1 _ have h_meas_t' : ∀ i ∈ T, MeasurableSet (sets_t' i) := by intro i hi; simp_rw [sets_t', dif_pos hi]; exact ht1 _ have h_eq_inter_S : (fun (ω : Ω) (i : ↥S) => f (↑i) ω) ⁻¹' Set.pi Set.univ sets_s = ⋂ i ∈ S, f i ⁻¹' sets_s' i := by ext1 x simp_rw [Set.mem_preimage, Set.mem_univ_pi, Set.mem_iInter] constructor <;> intro h · intro i hi; simp only [h_sets_s'_eq hi, Set.mem_preimage]; exact h ⟨i, hi⟩ · rintro ⟨i, hi⟩; specialize h i hi; simp only [sets_s'] at h; rwa [dif_pos hi] at h have h_eq_inter_T : (fun (ω : Ω) (i : ↥T) => f (↑i) ω) ⁻¹' Set.pi Set.univ sets_t = ⋂ i ∈ T, f i ⁻¹' sets_t' i := by ext1 x simp only [Set.mem_preimage, Set.mem_univ_pi, Set.mem_iInter] constructor <;> intro h · intro i hi; simp_rw [sets_t', dif_pos hi]; exact h ⟨i, hi⟩ · rintro ⟨i, hi⟩; specialize h i hi; simp_rw [sets_t', dif_pos hi] at h; exact h rw [iIndepFun_iff_measure_inter_preimage_eq_mul] at hf_Indep have h_Inter_inter : ((⋂ i ∈ S, f i ⁻¹' sets_s' i) ∩ ⋂ i ∈ T, f i ⁻¹' sets_t' i) = ⋂ i ∈ S ∪ T, f i ⁻¹' (sets_s' i ∩ sets_t' i) := by ext1 x simp_rw [Set.mem_inter_iff, Set.mem_iInter, Set.mem_preimage, Finset.mem_union] constructor <;> intro h · intro i hi cases' hi with hiS hiT · replace h := h.1 i hiS simp_rw [sets_s', sets_t', dif_pos hiS, dif_neg (Finset.disjoint_left.mp hST hiS)] simp only [sets_s'] at h exact ⟨by rwa [dif_pos hiS] at h, Set.mem_univ _⟩ · replace h := h.2 i hiT simp_rw [sets_s', sets_t', dif_pos hiT, dif_neg (Finset.disjoint_right.mp hST hiT)] simp only [sets_t'] at h exact ⟨Set.mem_univ _, by rwa [dif_pos hiT] at h⟩ · exact ⟨fun i hi => (h i (Or.inl hi)).1, fun i hi => (h i (Or.inr hi)).2⟩ have h_meas_inter : ∀ i ∈ S ∪ T, MeasurableSet (sets_s' i ∩ sets_t' i) := by intros i hi_mem rw [Finset.mem_union] at hi_mem cases' hi_mem with hi_mem hi_mem · rw [h_sets_t'_univ hi_mem, Set.inter_univ] exact h_meas_s' i hi_mem · rw [h_sets_s'_univ hi_mem, Set.univ_inter] exact h_meas_t' i hi_mem filter_upwards [hf_Indep S h_meas_s', hf_Indep T h_meas_t', hf_Indep (S ∪ T) h_meas_inter] with a h_indepS h_indepT h_indepST rw [h_eq_inter_S, h_eq_inter_T, h_indepS, h_indepT, h_Inter_inter, h_indepST, Finset.prod_union hST] congr 1 · refine Finset.prod_congr rfl fun i hi => ?_ rw [h_sets_t'_univ hi, Set.inter_univ] · refine Finset.prod_congr rfl fun i hi => ?_ rw [h_sets_s'_univ hi, Set.univ_inter] theorem iIndepFun.indepFun_prod_mk [IsMarkovKernel κ] (hf_Indep : iIndepFun m f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : IndepFun (fun a => (f i a, f j a)) (f k) κ μ := by classical have h_right : f k = (fun p : ∀ j : ({k} : Finset ι), β j => p ⟨k, Finset.mem_singleton_self k⟩) ∘ fun a (j : ({k} : Finset ι)) => f j a := rfl have h_meas_right : Measurable fun p : ∀ j : ({k} : Finset ι), β j => p ⟨k, Finset.mem_singleton_self k⟩ := measurable_pi_apply _ let s : Finset ι := {i, j} have h_left : (fun ω => (f i ω, f j ω)) = (fun p : ∀ l : s, β l => (p ⟨i, Finset.mem_insert_self i _⟩, p ⟨j, Finset.mem_insert_of_mem (Finset.mem_singleton_self _)⟩)) ∘ fun a (j : s) => f j a := by ext1 a simp only [Prod.mk.inj_iff] constructor have h_meas_left : Measurable fun p : ∀ l : s, β l => (p ⟨i, Finset.mem_insert_self i _⟩, p ⟨j, Finset.mem_insert_of_mem (Finset.mem_singleton_self _)⟩) := Measurable.prod (measurable_pi_apply _) (measurable_pi_apply _) rw [h_left, h_right] refine (hf_Indep.indepFun_finset s {k} ?_ hf_meas).comp h_meas_left h_meas_right rw [Finset.disjoint_singleton_right] simp only [s, Finset.mem_insert, Finset.mem_singleton, not_or] exact ⟨hik.symm, hjk.symm⟩ open Finset in lemma iIndepFun.indepFun_prod_mk_prod_mk [IsMarkovKernel κ] (hf_indep : iIndepFun m f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) κ μ := by classical let g (i j : ι) (v : Π x : ({i, j} : Finset ι), β x) : β i × β j := ⟨v ⟨i, mem_insert_self _ _⟩, v ⟨j, mem_insert_of_mem <| mem_singleton_self _⟩⟩ have hg (i j : ι) : Measurable (g i j) := by fun_prop exact (hf_indep.indepFun_finset {i, j} {k, l} (by aesop) hf_meas).comp (hg i j) (hg k l) end iIndepFun section Mul variable {β : Type*} {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β} [IsMarkovKernel κ] @[to_additive] lemma iIndepFun.indepFun_mul_left (hf_indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : IndepFun (f i * f j) (f k) κ μ := by have : IndepFun (fun ω => (f i ω, f j ω)) (f k) κ μ := hf_indep.indepFun_prod_mk hf_meas i j k hik hjk simpa using this.comp (measurable_fst.mul measurable_snd) measurable_id @[to_additive] lemma iIndepFun.indepFun_mul_right (hf_indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) : IndepFun (f i) (f j * f k) κ μ := (hf_indep.indepFun_mul_left hf_meas _ _ _ hij.symm hik.symm).symm @[to_additive] lemma iIndepFun.indepFun_mul_mul (hf_indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : IndepFun (f i * f j) (f k * f l) κ μ := (hf_indep.indepFun_prod_mk_prod_mk hf_meas i j k l hik hil hjk hjl).comp measurable_mul measurable_mul end Mul section Div variable {β : Type*} {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β} [IsMarkovKernel κ] @[to_additive] lemma iIndepFun.indepFun_div_left (hf_indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) : IndepFun (f i / f j) (f k) κ μ := by have : IndepFun (fun ω => (f i ω, f j ω)) (f k) κ μ := hf_indep.indepFun_prod_mk hf_meas i j k hik hjk simpa using this.comp (measurable_fst.div measurable_snd) measurable_id @[to_additive] lemma iIndepFun.indepFun_div_right (hf_indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) : IndepFun (f i) (f j / f k) κ μ := (hf_indep.indepFun_div_left hf_meas _ _ _ hij.symm hik.symm).symm @[to_additive] lemma iIndepFun.indepFun_div_div (hf_indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) : IndepFun (f i / f j) (f k / f l) κ μ := (hf_indep.indepFun_prod_mk_prod_mk hf_meas i j k l hik hil hjk hjl).comp measurable_div measurable_div end Div section CommMonoid variable {β : Type*} {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β} [IsMarkovKernel κ] @[to_additive] theorem iIndepFun.indepFun_finset_prod_of_not_mem (hf_Indep : iIndepFun (fun _ ↦ m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) {s : Finset ι} {i : ι} (hi : i ∉ s) : IndepFun (∏ j ∈ s, f j) (f i) κ μ := by classical have h_right : f i = (fun p : ({i} : Finset ι) → β => p ⟨i, Finset.mem_singleton_self i⟩) ∘ fun a (j : ({i} : Finset ι)) => f j a := rfl have h_meas_right : Measurable fun p : ({i} : Finset ι) → β => p ⟨i, Finset.mem_singleton_self i⟩ := measurable_pi_apply ⟨i, Finset.mem_singleton_self i⟩ have h_left : ∏ j ∈ s, f j = (fun p : s → β => ∏ j, p j) ∘ fun a (j : s) => f j a := by ext1 a simp only [Function.comp_apply] have : (∏ j : ↥s, f (↑j) a) = (∏ j : ↥s, f ↑j) a := by rw [Finset.prod_apply] rw [this, Finset.prod_coe_sort] have h_meas_left : Measurable fun p : s → β => ∏ j, p j := Finset.univ.measurable_prod fun (j : ↥s) (_H : j ∈ Finset.univ) => measurable_pi_apply j rw [h_left, h_right] exact (hf_Indep.indepFun_finset s {i} (Finset.disjoint_singleton_left.mpr hi).symm hf_meas).comp h_meas_left h_meas_right @[to_additive] theorem iIndepFun.indepFun_prod_range_succ {f : ℕ → Ω → β} (hf_Indep : iIndepFun (fun _ => m) f κ μ) (hf_meas : ∀ i, Measurable (f i)) (n : ℕ) : IndepFun (∏ j ∈ Finset.range n, f j) (f n) κ μ := hf_Indep.indepFun_finset_prod_of_not_mem hf_meas Finset.not_mem_range_self end CommMonoid theorem iIndepSet.iIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β} {s : ι → Set Ω} (hs : iIndepSet s κ μ) : iIndepFun (fun _n => m) (fun n => (s n).indicator fun _ω => 1) κ μ := by classical rw [iIndepFun_iff_measure_inter_preimage_eq_mul] rintro S π _hπ simp_rw [Set.indicator_const_preimage_eq_union] refine @hs S (fun i => ite (1 ∈ π i) (s i) ∅ ∪ ite ((0 : β) ∈ π i) (s i)ᶜ ∅) fun i _hi => ?_ have hsi : MeasurableSet[generateFrom {s i}] (s i) := measurableSet_generateFrom (Set.mem_singleton _) refine MeasurableSet.union (MeasurableSet.ite' (fun _ => hsi) fun _ => ?_) (MeasurableSet.ite' (fun _ => hsi.compl) fun _ => ?_) · exact @MeasurableSet.empty _ (generateFrom {s i}) · exact @MeasurableSet.empty _ (generateFrom {s i}) end IndepFun end ProbabilityTheory.Kernel
Probability\Independence\ZeroOne.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.Probability.Independence.Basic import Mathlib.Probability.Independence.Conditional /-! # Kolmogorov's 0-1 law Let `s : ι → MeasurableSpace Ω` be an independent sequence of sub-σ-algebras. Then any set which is measurable with respect to the tail σ-algebra `limsup s atTop` has probability 0 or 1. ## Main statements * `measure_zero_or_one_of_measurableSet_limsup_atTop`: Kolmogorov's 0-1 law. Any set which is measurable with respect to the tail σ-algebra `limsup s atTop` of an independent sequence of σ-algebras `s` has probability 0 or 1. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {α Ω ι : Type*} {_mα : MeasurableSpace α} {s : ι → MeasurableSpace Ω} {m m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μα : Measure α} {μ : Measure Ω} theorem Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ω} (h_indep : Kernel.IndepSet t t κ μα) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 ∨ κ a t = ∞ := by specialize h_indep t t (measurableSet_generateFrom (Set.mem_singleton t)) (measurableSet_generateFrom (Set.mem_singleton t)) filter_upwards [h_indep] with a ha by_cases h0 : κ a t = 0 · exact Or.inl h0 by_cases h_top : κ a t = ∞ · exact Or.inr (Or.inr h_top) rw [← one_mul (κ a (t ∩ t)), Set.inter_self, ENNReal.mul_eq_mul_right h0 h_top] at ha exact Or.inr (Or.inl ha.symm) theorem measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ω} (h_indep : IndepSet t t μ) : μ t = 0 ∨ μ t = 1 ∨ μ t = ∞ := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self h_indep theorem Kernel.measure_eq_zero_or_one_of_indepSet_self [∀ a, IsFiniteMeasure (κ a)] {t : Set Ω} (h_indep : IndepSet t t κ μα) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := by filter_upwards [measure_eq_zero_or_one_or_top_of_indepSet_self h_indep] with a h_0_1_top simpa only [measure_ne_top (κ a), or_false] using h_0_1_top theorem measure_eq_zero_or_one_of_indepSet_self [IsFiniteMeasure μ] {t : Set Ω} (h_indep : IndepSet t t μ) : μ t = 0 ∨ μ t = 1 := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep theorem condexp_eq_zero_or_one_of_condIndepSet_self [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [hμ : IsFiniteMeasure μ] {t : Set Ω} (ht : MeasurableSet t) (h_indep : CondIndepSet m hm t t μ) : ∀ᵐ ω ∂μ, (μ⟦t | m⟧) ω = 0 ∨ (μ⟦t | m⟧) ω = 1 := by -- TODO: Why is not inferred? have (a) : IsFiniteMeasure (condexpKernel μ m a) := inferInstance have h := ae_of_ae_trim hm (Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep) filter_upwards [condexpKernel_ae_eq_condexp hm ht, h] with ω hω_eq hω rw [← hω_eq, ENNReal.toReal_eq_zero_iff, ENNReal.toReal_eq_one_iff] cases hω with | inl h => exact Or.inl (Or.inl h) | inr h => exact Or.inr h variable [IsMarkovKernel κ] [IsProbabilityMeasure μ] open Filter theorem Kernel.indep_biSup_compl (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (t : Set ι) : Indep (⨆ n ∈ t, s n) (⨆ n ∈ tᶜ, s n) κ μα := indep_iSup_of_disjoint h_le h_indep disjoint_compl_right theorem indep_biSup_compl (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (t : Set ι) : Indep (⨆ n ∈ t, s n) (⨆ n ∈ tᶜ, s n) μ := Kernel.indep_biSup_compl h_le h_indep t theorem condIndep_biSup_compl [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (t : Set ι) : CondIndep m (⨆ n ∈ t, s n) (⨆ n ∈ tᶜ, s n) hm μ := Kernel.indep_biSup_compl h_le h_indep t section Abstract variable {α : Type*} {p : Set ι → Prop} {f : Filter ι} {ns : α → Set ι} /-! We prove a version of Kolmogorov's 0-1 law for the σ-algebra `limsup s f` where `f` is a filter for which we can define the following two functions: * `p : Set ι → Prop` such that for a set `t`, `p t → tᶜ ∈ f`, * `ns : α → Set ι` a directed sequence of sets which all verify `p` and such that `⋃ a, ns a = Set.univ`. For the example of `f = atTop`, we can take `p = bddAbove` and `ns : ι → Set ι := fun i => Set.Iic i`. -/ theorem Kernel.indep_biSup_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (hf : ∀ t, p t → tᶜ ∈ f) {t : Set ι} (ht : p t) : Indep (⨆ n ∈ t, s n) (limsup s f) κ μα := by refine indep_of_indep_of_le_right (indep_biSup_compl h_le h_indep t) ?_ refine limsSup_le_of_le (by isBoundedDefault) ?_ simp only [Set.mem_compl_iff, eventually_map] exact eventually_of_mem (hf t ht) le_iSup₂ theorem indep_biSup_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f) {t : Set ι} (ht : p t) : Indep (⨆ n ∈ t, s n) (limsup s f) μ := Kernel.indep_biSup_limsup h_le h_indep hf ht theorem condIndep_biSup_limsup [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f) {t : Set ι} (ht : p t) : CondIndep m (⨆ n ∈ t, s n) (limsup s f) hm μ := Kernel.indep_biSup_limsup h_le h_indep hf ht theorem Kernel.indep_iSup_directed_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) : Indep (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) κ μα := by apply indep_iSup_of_directed_le · exact fun a => indep_biSup_limsup h_le h_indep hf (hnsp a) · exact fun a => iSup₂_le fun n _ => h_le n · exact limsup_le_iSup.trans (iSup_le h_le) · intro a b obtain ⟨c, hc⟩ := hns a b refine ⟨c, ?_, ?_⟩ <;> refine iSup_mono fun n => iSup_mono' fun hn => ⟨?_, le_rfl⟩ · exact hc.1 hn · exact hc.2 hn theorem indep_iSup_directed_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) : Indep (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) μ := Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp theorem condIndep_iSup_directed_limsup [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) : CondIndep m (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) hm μ := Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp theorem Kernel.indep_iSup_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) : Indep (⨆ n, s n) (limsup s f) κ μα := by suffices (⨆ a, ⨆ n ∈ ns a, s n) = ⨆ n, s n by rw [← this] exact indep_iSup_directed_limsup h_le h_indep hf hns hnsp rw [iSup_comm] refine iSup_congr fun n => ?_ have h : ⨆ (i : α) (_ : n ∈ ns i), s n = ⨆ _ : ∃ i, n ∈ ns i, s n := by rw [iSup_exists] haveI : Nonempty (∃ i : α, n ∈ ns i) := ⟨hns_univ n⟩ rw [h, iSup_const] theorem indep_iSup_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) : Indep (⨆ n, s n) (limsup s f) μ := Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ theorem condIndep_iSup_limsup [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) : CondIndep m (⨆ n, s n) (limsup s f) hm μ := Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ theorem Kernel.indep_limsup_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) : Indep (limsup s f) (limsup s f) κ μα := indep_of_indep_of_le_left (indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ) limsup_le_iSup theorem indep_limsup_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) : Indep (limsup s f) (limsup s f) μ := Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ theorem condIndep_limsup_self [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) : CondIndep m (limsup s f) (limsup s f) hm μ := Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ theorem Kernel.measure_zero_or_one_of_measurableSet_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) {t : Set Ω} (ht_tail : MeasurableSet[limsup s f] t) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := measure_eq_zero_or_one_of_indepSet_self ((indep_limsup_self h_le h_indep hf hns hnsp hns_univ).indepSet_of_measurableSet ht_tail ht_tail) theorem measure_zero_or_one_of_measurableSet_limsup (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) {t : Set Ω} (ht_tail : MeasurableSet[limsup s f] t) : μ t = 0 ∨ μ t = 1 := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_zero_or_one_of_measurableSet_limsup h_le h_indep hf hns hnsp hns_univ ht_tail theorem condexp_zero_or_one_of_measurableSet_limsup [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) (hf : ∀ t, p t → tᶜ ∈ f) (hns : Directed (· ≤ ·) ns) (hnsp : ∀ a, p (ns a)) (hns_univ : ∀ n, ∃ a, n ∈ ns a) {t : Set Ω} (ht_tail : MeasurableSet[limsup s f] t) : ∀ᵐ ω ∂μ, (μ⟦t | m⟧) ω = 0 ∨ (μ⟦t | m⟧) ω = 1 := by have h := ae_of_ae_trim hm (Kernel.measure_zero_or_one_of_measurableSet_limsup h_le h_indep hf hns hnsp hns_univ ht_tail) have ht : MeasurableSet t := limsup_le_iSup.trans (iSup_le h_le) t ht_tail filter_upwards [condexpKernel_ae_eq_condexp hm ht, h] with ω hω_eq hω rw [← hω_eq, ENNReal.toReal_eq_zero_iff, ENNReal.toReal_eq_one_iff] cases hω with | inl h => exact Or.inl (Or.inl h) | inr h => exact Or.inr h end Abstract section AtTop variable [SemilatticeSup ι] [NoMaxOrder ι] [Nonempty ι] theorem Kernel.indep_limsup_atTop_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) : Indep (limsup s atTop) (limsup s atTop) κ μα := by let ns : ι → Set ι := Set.Iic have hnsp : ∀ i, BddAbove (ns i) := fun i => bddAbove_Iic refine indep_limsup_self h_le h_indep ?_ ?_ hnsp ?_ · simp only [mem_atTop_sets, Set.mem_compl_iff, BddAbove, upperBounds, Set.Nonempty] rintro t ⟨a, ha⟩ obtain ⟨b, hb⟩ : ∃ b, a < b := exists_gt a refine ⟨b, fun c hc hct => ?_⟩ suffices ∀ i ∈ t, i < c from lt_irrefl c (this c hct) exact fun i hi => (ha hi).trans_lt (hb.trans_le hc) · exact Monotone.directed_le fun i j hij k hki => le_trans hki hij · exact fun n => ⟨n, le_rfl⟩ theorem indep_limsup_atTop_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) : Indep (limsup s atTop) (limsup s atTop) μ := Kernel.indep_limsup_atTop_self h_le h_indep theorem condIndep_limsup_atTop_self [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) : CondIndep m (limsup s atTop) (limsup s atTop) hm μ := Kernel.indep_limsup_atTop_self h_le h_indep theorem Kernel.measure_zero_or_one_of_measurableSet_limsup_atTop (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atTop] t) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := measure_eq_zero_or_one_of_indepSet_self ((indep_limsup_atTop_self h_le h_indep).indepSet_of_measurableSet ht_tail ht_tail) /-- **Kolmogorov's 0-1 law** : any event in the tail σ-algebra of an independent sequence of sub-σ-algebras has probability 0 or 1. The tail σ-algebra `limsup s atTop` is the same as `⋂ n, ⋃ i ≥ n, s i`. -/ theorem measure_zero_or_one_of_measurableSet_limsup_atTop (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atTop] t) : μ t = 0 ∨ μ t = 1 := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_zero_or_one_of_measurableSet_limsup_atTop h_le h_indep ht_tail theorem condexp_zero_or_one_of_measurableSet_limsup_atTop [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atTop] t) : ∀ᵐ ω ∂μ, (μ⟦t | m⟧) ω = 0 ∨ (μ⟦t | m⟧) ω = 1 := condexp_eq_zero_or_one_of_condIndepSet_self hm (limsup_le_iSup.trans (iSup_le h_le) t ht_tail) ((condIndep_limsup_atTop_self hm h_le h_indep).condIndepSet_of_measurableSet ht_tail ht_tail) end AtTop section AtBot variable [SemilatticeInf ι] [NoMinOrder ι] [Nonempty ι] theorem Kernel.indep_limsup_atBot_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) : Indep (limsup s atBot) (limsup s atBot) κ μα := by let ns : ι → Set ι := Set.Ici have hnsp : ∀ i, BddBelow (ns i) := fun i => bddBelow_Ici refine indep_limsup_self h_le h_indep ?_ ?_ hnsp ?_ · simp only [mem_atBot_sets, Set.mem_compl_iff, BddBelow, lowerBounds, Set.Nonempty] rintro t ⟨a, ha⟩ obtain ⟨b, hb⟩ : ∃ b, b < a := exists_lt a refine ⟨b, fun c hc hct => ?_⟩ suffices ∀ i ∈ t, c < i from lt_irrefl c (this c hct) exact fun i hi => hc.trans_lt (hb.trans_le (ha hi)) · exact Antitone.directed_le fun _ _ ↦ Set.Ici_subset_Ici.2 · exact fun n => ⟨n, le_rfl⟩ theorem indep_limsup_atBot_self (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) : Indep (limsup s atBot) (limsup s atBot) μ := Kernel.indep_limsup_atBot_self h_le h_indep theorem condIndep_limsup_atBot_self [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) : CondIndep m (limsup s atBot) (limsup s atBot) hm μ := Kernel.indep_limsup_atBot_self h_le h_indep /-- **Kolmogorov's 0-1 law**, kernel version: any event in the tail σ-algebra of an independent sequence of sub-σ-algebras has probability 0 or 1 almost surely. -/ theorem Kernel.measure_zero_or_one_of_measurableSet_limsup_atBot (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s κ μα) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atBot] t) : ∀ᵐ a ∂μα, κ a t = 0 ∨ κ a t = 1 := measure_eq_zero_or_one_of_indepSet_self ((indep_limsup_atBot_self h_le h_indep).indepSet_of_measurableSet ht_tail ht_tail) /-- **Kolmogorov's 0-1 law** : any event in the tail σ-algebra of an independent sequence of sub-σ-algebras has probability 0 or 1. -/ theorem measure_zero_or_one_of_measurableSet_limsup_atBot (h_le : ∀ n, s n ≤ m0) (h_indep : iIndep s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atBot] t) : μ t = 0 ∨ μ t = 1 := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_zero_or_one_of_measurableSet_limsup_atBot h_le h_indep ht_tail /-- **Kolmogorov's 0-1 law**, conditional version: any event in the tail σ-algebra of a conditinoally independent sequence of sub-σ-algebras has conditional probability 0 or 1. -/ theorem condexp_zero_or_one_of_measurableSet_limsup_atBot [StandardBorelSpace Ω] [Nonempty Ω] (hm : m ≤ m0) [IsFiniteMeasure μ] (h_le : ∀ n, s n ≤ m0) (h_indep : iCondIndep m hm s μ) {t : Set Ω} (ht_tail : MeasurableSet[limsup s atBot] t) : ∀ᵐ ω ∂μ, (μ⟦t | m⟧) ω = 0 ∨ (μ⟦t | m⟧) ω = 1 := condexp_eq_zero_or_one_of_condIndepSet_self hm (limsup_le_iSup.trans (iSup_le h_le) t ht_tail) ((condIndep_limsup_atBot_self hm h_le h_indep).condIndepSet_of_measurableSet ht_tail ht_tail) end AtBot end ProbabilityTheory
Probability\Kernel\Basic.lean
/- Copyright (c) 2022 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.Integral.Bochner import Mathlib.MeasureTheory.Measure.GiryMonad /-! # Markov Kernels A kernel from a measurable space `α` to another measurable space `β` is a measurable map `α → MeasureTheory.Measure β`, where the measurable space instance on `measure β` is the one defined in `MeasureTheory.Measure.instMeasurableSpace`. That is, a kernel `κ` verifies that for all measurable sets `s` of `β`, `a ↦ κ a s` is measurable. ## Main definitions Classes of kernels: * `ProbabilityTheory.Kernel α β`: kernels from `α` to `β`. * `ProbabilityTheory.IsMarkovKernel κ`: a kernel from `α` to `β` is said to be a Markov kernel if for all `a : α`, `k a` is a probability measure. * `ProbabilityTheory.IsFiniteKernel κ`: a kernel from `α` to `β` is said to be finite if there exists `C : ℝ≥0∞` such that `C < ∞` and for all `a : α`, `κ a univ ≤ C`. This implies in particular that all measures in the image of `κ` are finite, but is stronger since it requires a uniform bound. This stronger condition is necessary to ensure that the composition of two finite kernels is finite. * `ProbabilityTheory.IsSFiniteKernel κ`: a kernel is called s-finite if it is a countable sum of finite kernels. Particular kernels: * `ProbabilityTheory.Kernel.deterministic (f : α → β) (hf : Measurable f)`: kernel `a ↦ Measure.dirac (f a)`. * `ProbabilityTheory.Kernel.const α (μβ : measure β)`: constant kernel `a ↦ μβ`. * `ProbabilityTheory.Kernel.restrict κ (hs : MeasurableSet s)`: kernel for which the image of `a : α` is `(κ a).restrict s`. Integral: `∫⁻ b, f b ∂(κ.restrict hs a) = ∫⁻ b in s, f b ∂(κ a)` ## Main statements * `ProbabilityTheory.Kernel.ext_fun`: if `∫⁻ b, f b ∂(κ a) = ∫⁻ b, f b ∂(η a)` for all measurable functions `f` and all `a`, then the two kernels `κ` and `η` are equal. -/ open MeasureTheory open scoped MeasureTheory ENNReal NNReal namespace ProbabilityTheory /-- A kernel from a measurable space `α` to another measurable space `β` is a measurable function `κ : α → Measure β`. The measurable space structure on `MeasureTheory.Measure β` is given by `MeasureTheory.Measure.instMeasurableSpace`. A map `κ : α → MeasureTheory.Measure β` is measurable iff `∀ s : Set β, MeasurableSet s → Measurable (fun a ↦ κ a s)`. -/ structure Kernel (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] where /-- The underlying function of a kernel. Do not use this function directly. Instead use the coercion coming from the `DFunLike` instance. -/ toFun : α → Measure β /-- A kernel is a measurable map. Do not use this lemma directly. Use `Kernel.measurable` instead. -/ measurable' : Measurable toFun @[deprecated (since := "2024-07-22")] alias kernel := Kernel /-- Notation for `Kernel` with respect to a non-standard σ-algebra in the domain. -/ scoped notation "Kernel[" mα "]" α:arg β:arg => @Kernel α β mα _ /-- Notation for `Kernel` with respect to a non-standard σ-algebra in the domain and codomain. -/ scoped notation "Kernel[" mα ", " mβ "]" α:arg β:arg => @Kernel α β mα mβ initialize_simps_projections Kernel (toFun → apply) variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} namespace Kernel instance instFunLike : FunLike (Kernel α β) α (Measure β) where coe := toFun coe_injective' f g h := by cases f; cases g; congr lemma measurable (κ : Kernel α β) : Measurable κ := κ.measurable' instance instZero : Zero (Kernel α β) where zero := ⟨0, measurable_zero⟩ noncomputable instance instAdd : Add (Kernel α β) where add κ η := ⟨κ + η, κ.2.add η.2⟩ noncomputable instance instSMulNat : SMul ℕ (Kernel α β) where smul n κ := ⟨n • κ, (measurable_const (a := n)).smul κ.2⟩ @[simp, norm_cast] lemma coe_zero : ⇑(0 : Kernel α β) = 0 := rfl @[simp, norm_cast] lemma coe_add (κ η : Kernel α β) : ⇑(κ + η) = κ + η := rfl @[simp, norm_cast] lemma coe_nsmul (n : ℕ) (κ : Kernel α β) : ⇑(n • κ) = n • κ := rfl @[simp] lemma zero_apply (a : α) : (0 : Kernel α β) a = 0 := rfl @[simp] lemma add_apply (κ η : Kernel α β) (a : α) : (κ + η) a = κ a + η a := rfl @[simp] lemma nsmul_apply (n : ℕ) (κ : Kernel α β) (a : α) : (n • κ) a = n • κ a := rfl noncomputable instance instAddCommMonoid : AddCommMonoid (Kernel α β) := DFunLike.coe_injective.addCommMonoid _ coe_zero coe_add (by intros; rfl) instance instPartialOrder : PartialOrder (Kernel α β) := .lift _ DFunLike.coe_injective instance instCovariantAddLE {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] : CovariantClass (Kernel α β) (Kernel α β) (· + ·) (· ≤ ·) := ⟨fun _ _ _ hμ a ↦ add_le_add_left (hμ a) _⟩ noncomputable instance instOrderBot {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] : OrderBot (Kernel α β) where bot := 0 bot_le κ a := by simp only [coe_zero, Pi.zero_apply, Measure.zero_le] /-- Coercion to a function as an additive monoid homomorphism. -/ def coeAddHom (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] : Kernel α β →+ α → Measure β where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add @[simp] theorem coe_finset_sum (I : Finset ι) (κ : ι → Kernel α β) : ⇑(∑ i ∈ I, κ i) = ∑ i ∈ I, ⇑(κ i) := map_sum (coeAddHom α β) _ _ theorem finset_sum_apply (I : Finset ι) (κ : ι → Kernel α β) (a : α) : (∑ i ∈ I, κ i) a = ∑ i ∈ I, κ i a := by rw [coe_finset_sum, Finset.sum_apply] theorem finset_sum_apply' (I : Finset ι) (κ : ι → Kernel α β) (a : α) (s : Set β) : (∑ i ∈ I, κ i) a s = ∑ i ∈ I, κ i a s := by rw [finset_sum_apply, Measure.finset_sum_apply] end Kernel /-- A kernel is a Markov kernel if every measure in its image is a probability measure. -/ class IsMarkovKernel (κ : Kernel α β) : Prop where isProbabilityMeasure : ∀ a, IsProbabilityMeasure (κ a) /-- A kernel is finite if every measure in its image is finite, with a uniform bound. -/ class IsFiniteKernel (κ : Kernel α β) : Prop where exists_univ_le : ∃ C : ℝ≥0∞, C < ∞ ∧ ∀ a, κ a Set.univ ≤ C /-- A constant `C : ℝ≥0∞` such that `C < ∞` (`ProbabilityTheory.IsFiniteKernel.bound_lt_top κ`) and for all `a : α` and `s : Set β`, `κ a s ≤ C` (`ProbabilityTheory.Kernel.measure_le_bound κ a s`). Porting note (#11215): TODO: does it make sense to -- make `ProbabilityTheory.IsFiniteKernel.bound` the least possible bound? -- Should it be an `NNReal` number? -/ noncomputable def IsFiniteKernel.bound (κ : Kernel α β) [h : IsFiniteKernel κ] : ℝ≥0∞ := h.exists_univ_le.choose theorem IsFiniteKernel.bound_lt_top (κ : Kernel α β) [h : IsFiniteKernel κ] : IsFiniteKernel.bound κ < ∞ := h.exists_univ_le.choose_spec.1 theorem IsFiniteKernel.bound_ne_top (κ : Kernel α β) [IsFiniteKernel κ] : IsFiniteKernel.bound κ ≠ ∞ := (IsFiniteKernel.bound_lt_top κ).ne theorem Kernel.measure_le_bound (κ : Kernel α β) [h : IsFiniteKernel κ] (a : α) (s : Set β) : κ a s ≤ IsFiniteKernel.bound κ := (measure_mono (Set.subset_univ s)).trans (h.exists_univ_le.choose_spec.2 a) instance isFiniteKernel_zero (α β : Type*) {mα : MeasurableSpace α} {mβ : MeasurableSpace β} : IsFiniteKernel (0 : Kernel α β) := ⟨⟨0, ENNReal.coe_lt_top, fun _ => by simp only [Kernel.zero_apply, Measure.coe_zero, Pi.zero_apply, le_zero_iff]⟩⟩ instance IsFiniteKernel.add (κ η : Kernel α β) [IsFiniteKernel κ] [IsFiniteKernel η] : IsFiniteKernel (κ + η) := by refine ⟨⟨IsFiniteKernel.bound κ + IsFiniteKernel.bound η, ENNReal.add_lt_top.mpr ⟨IsFiniteKernel.bound_lt_top κ, IsFiniteKernel.bound_lt_top η⟩, fun a => ?_⟩⟩ exact add_le_add (Kernel.measure_le_bound _ _ _) (Kernel.measure_le_bound _ _ _) lemma isFiniteKernel_of_le {κ ν : Kernel α β} [hν : IsFiniteKernel ν] (hκν : κ ≤ ν) : IsFiniteKernel κ := by refine ⟨hν.bound, hν.bound_lt_top, fun a ↦ (hκν _ _).trans (Kernel.measure_le_bound ν a Set.univ)⟩ variable {κ : Kernel α β} instance IsMarkovKernel.is_probability_measure' [IsMarkovKernel κ] (a : α) : IsProbabilityMeasure (κ a) := IsMarkovKernel.isProbabilityMeasure a instance IsFiniteKernel.isFiniteMeasure [IsFiniteKernel κ] (a : α) : IsFiniteMeasure (κ a) := ⟨(Kernel.measure_le_bound κ a Set.univ).trans_lt (IsFiniteKernel.bound_lt_top κ)⟩ instance (priority := 100) IsMarkovKernel.isFiniteKernel [IsMarkovKernel κ] : IsFiniteKernel κ := ⟨⟨1, ENNReal.one_lt_top, fun _ => prob_le_one⟩⟩ namespace Kernel @[ext] theorem ext {η : Kernel α β} (h : ∀ a, κ a = η a) : κ = η := DFunLike.ext _ _ h theorem ext_iff' {η : Kernel α β} : κ = η ↔ ∀ a s, MeasurableSet s → κ a s = η a s := by simp_rw [Kernel.ext_iff, Measure.ext_iff] theorem ext_fun {η : Kernel α β} (h : ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a) : κ = η := by ext a s hs specialize h a (s.indicator fun _ => 1) (Measurable.indicator measurable_const hs) simp_rw [lintegral_indicator_const hs, one_mul] at h rw [h] theorem ext_fun_iff {η : Kernel α β} : κ = η ↔ ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a := ⟨fun h a f _ => by rw [h], ext_fun⟩ protected theorem measurable_coe (κ : Kernel α β) {s : Set β} (hs : MeasurableSet s) : Measurable fun a => κ a s := (Measure.measurable_coe hs).comp κ.measurable lemma apply_congr_of_mem_measurableAtom (κ : Kernel α β) {y' y : α} (hy' : y' ∈ measurableAtom y) : κ y' = κ y := by ext s hs exact mem_of_mem_measurableAtom hy' (κ.measurable_coe hs (measurableSet_singleton (κ y s))) rfl lemma IsFiniteKernel.integrable (μ : Measure α) [IsFiniteMeasure μ] (κ : Kernel α β) [IsFiniteKernel κ] {s : Set β} (hs : MeasurableSet s) : Integrable (fun x => (κ x s).toReal) μ := by refine Integrable.mono' (integrable_const (IsFiniteKernel.bound κ).toReal) ((κ.measurable_coe hs).ennreal_toReal.aestronglyMeasurable) (ae_of_all μ fun x => ?_) rw [Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg, ENNReal.toReal_le_toReal (measure_ne_top _ _) (IsFiniteKernel.bound_ne_top _)] exact Kernel.measure_le_bound _ _ _ lemma IsMarkovKernel.integrable (μ : Measure α) [IsFiniteMeasure μ] (κ : Kernel α β) [IsMarkovKernel κ] {s : Set β} (hs : MeasurableSet s) : Integrable (fun x => (κ x s).toReal) μ := IsFiniteKernel.integrable μ κ hs section Sum /-- Sum of an indexed family of kernels. -/ protected noncomputable def sum [Countable ι] (κ : ι → Kernel α β) : Kernel α β where toFun a := Measure.sum fun n => κ n a measurable' := by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [Measure.sum_apply _ hs] exact Measurable.ennreal_tsum fun n => Kernel.measurable_coe (κ n) hs theorem sum_apply [Countable ι] (κ : ι → Kernel α β) (a : α) : Kernel.sum κ a = Measure.sum fun n => κ n a := rfl theorem sum_apply' [Countable ι] (κ : ι → Kernel α β) (a : α) {s : Set β} (hs : MeasurableSet s) : Kernel.sum κ a s = ∑' n, κ n a s := by rw [sum_apply κ a, Measure.sum_apply _ hs] @[simp] theorem sum_zero [Countable ι] : (Kernel.sum fun _ : ι => (0 : Kernel α β)) = 0 := by ext a s hs rw [sum_apply' _ a hs] simp only [zero_apply, Measure.coe_zero, Pi.zero_apply, tsum_zero] theorem sum_comm [Countable ι] (κ : ι → ι → Kernel α β) : (Kernel.sum fun n => Kernel.sum (κ n)) = Kernel.sum fun m => Kernel.sum fun n => κ n m := by ext a s; simp_rw [sum_apply]; rw [Measure.sum_comm] @[simp] theorem sum_fintype [Fintype ι] (κ : ι → Kernel α β) : Kernel.sum κ = ∑ i, κ i := by ext a s hs simp only [sum_apply' κ a hs, finset_sum_apply' _ κ a s, tsum_fintype] theorem sum_add [Countable ι] (κ η : ι → Kernel α β) : (Kernel.sum fun n => κ n + η n) = Kernel.sum κ + Kernel.sum η := by ext a s hs simp only [coe_add, Pi.add_apply, sum_apply, Measure.sum_apply _ hs, Pi.add_apply, Measure.coe_add, tsum_add ENNReal.summable ENNReal.summable] end Sum section SFinite /-- A kernel is s-finite if it can be written as the sum of countably many finite kernels. -/ class _root_.ProbabilityTheory.IsSFiniteKernel (κ : Kernel α β) : Prop where tsum_finite : ∃ κs : ℕ → Kernel α β, (∀ n, IsFiniteKernel (κs n)) ∧ κ = Kernel.sum κs instance (priority := 100) IsFiniteKernel.isSFiniteKernel [h : IsFiniteKernel κ] : IsSFiniteKernel κ := ⟨⟨fun n => if n = 0 then κ else 0, fun n => by simp only; split_ifs · exact h · infer_instance, by ext a s hs rw [Kernel.sum_apply' _ _ hs] have : (fun i => ((ite (i = 0) κ 0) a) s) = fun i => ite (i = 0) (κ a s) 0 := by ext1 i; split_ifs <;> rfl rw [this, tsum_ite_eq]⟩⟩ /-- A sequence of finite kernels such that `κ = ProbabilityTheory.Kernel.sum (seq κ)`. See `ProbabilityTheory.Kernel.isFiniteKernel_seq` and `ProbabilityTheory.Kernel.kernel_sum_seq`. -/ noncomputable def seq (κ : Kernel α β) [h : IsSFiniteKernel κ] : ℕ → Kernel α β := h.tsum_finite.choose theorem kernel_sum_seq (κ : Kernel α β) [h : IsSFiniteKernel κ] : Kernel.sum (seq κ) = κ := h.tsum_finite.choose_spec.2.symm theorem measure_sum_seq (κ : Kernel α β) [h : IsSFiniteKernel κ] (a : α) : (Measure.sum fun n => seq κ n a) = κ a := by rw [← Kernel.sum_apply, kernel_sum_seq κ] instance isFiniteKernel_seq (κ : Kernel α β) [h : IsSFiniteKernel κ] (n : ℕ) : IsFiniteKernel (Kernel.seq κ n) := h.tsum_finite.choose_spec.1 n instance _root_.ProbabilityTheory.IsSFiniteKernel.sFinite [IsSFiniteKernel κ] (a : α) : SFinite (κ a) := ⟨⟨fun n ↦ seq κ n a, inferInstance, (measure_sum_seq κ a).symm⟩⟩ instance IsSFiniteKernel.add (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] : IsSFiniteKernel (κ + η) := by refine ⟨⟨fun n => seq κ n + seq η n, fun n => inferInstance, ?_⟩⟩ rw [sum_add, kernel_sum_seq κ, kernel_sum_seq η] theorem IsSFiniteKernel.finset_sum {κs : ι → Kernel α β} (I : Finset ι) (h : ∀ i ∈ I, IsSFiniteKernel (κs i)) : IsSFiniteKernel (∑ i ∈ I, κs i) := by classical induction' I using Finset.induction with i I hi_nmem_I h_ind h · rw [Finset.sum_empty]; infer_instance · rw [Finset.sum_insert hi_nmem_I] haveI : IsSFiniteKernel (κs i) := h i (Finset.mem_insert_self _ _) have : IsSFiniteKernel (∑ x ∈ I, κs x) := h_ind fun i hiI => h i (Finset.mem_insert_of_mem hiI) exact IsSFiniteKernel.add _ _ theorem isSFiniteKernel_sum_of_denumerable [Denumerable ι] {κs : ι → Kernel α β} (hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (Kernel.sum κs) := by let e : ℕ ≃ ι × ℕ := (Denumerable.eqv (ι × ℕ)).symm refine ⟨⟨fun n => seq (κs (e n).1) (e n).2, inferInstance, ?_⟩⟩ have hκ_eq : Kernel.sum κs = Kernel.sum fun n => Kernel.sum (seq (κs n)) := by simp_rw [kernel_sum_seq] ext a s hs rw [hκ_eq] simp_rw [Kernel.sum_apply' _ _ hs] change (∑' i, ∑' m, seq (κs i) m a s) = ∑' n, (fun im : ι × ℕ => seq (κs im.fst) im.snd a s) (e n) rw [e.tsum_eq (fun im : ι × ℕ => seq (κs im.fst) im.snd a s), tsum_prod' ENNReal.summable fun _ => ENNReal.summable] theorem isSFiniteKernel_sum [Countable ι] {κs : ι → Kernel α β} (hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (Kernel.sum κs) := by cases fintypeOrInfinite ι · rw [sum_fintype] exact IsSFiniteKernel.finset_sum Finset.univ fun i _ => hκs i cases nonempty_denumerable ι exact isSFiniteKernel_sum_of_denumerable hκs end SFinite section Deterministic /-- Kernel which to `a` associates the dirac measure at `f a`. This is a Markov kernel. -/ noncomputable def deterministic (f : α → β) (hf : Measurable f) : Kernel α β where toFun a := Measure.dirac (f a) measurable' := by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [Measure.dirac_apply' _ hs] exact measurable_one.indicator (hf hs) theorem deterministic_apply {f : α → β} (hf : Measurable f) (a : α) : deterministic f hf a = Measure.dirac (f a) := rfl theorem deterministic_apply' {f : α → β} (hf : Measurable f) (a : α) {s : Set β} (hs : MeasurableSet s) : deterministic f hf a s = s.indicator (fun _ => 1) (f a) := by rw [deterministic] change Measure.dirac (f a) s = s.indicator 1 (f a) simp_rw [Measure.dirac_apply' _ hs] instance isMarkovKernel_deterministic {f : α → β} (hf : Measurable f) : IsMarkovKernel (deterministic f hf) := ⟨fun a => by rw [deterministic_apply hf]; infer_instance⟩ theorem lintegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g) (hf : Measurable f) : ∫⁻ x, f x ∂deterministic g hg a = f (g a) := by rw [deterministic_apply, lintegral_dirac' _ hf] @[simp] theorem lintegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g) [MeasurableSingletonClass β] : ∫⁻ x, f x ∂deterministic g hg a = f (g a) := by rw [deterministic_apply, lintegral_dirac (g a) f] theorem setLIntegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g) (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) [Decidable (g a ∈ s)] : ∫⁻ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by rw [deterministic_apply, setLIntegral_dirac' hf hs] @[deprecated (since := "2024-06-29")] alias set_lintegral_deterministic' := setLIntegral_deterministic' @[simp] theorem setLIntegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g) [MeasurableSingletonClass β] (s : Set β) [Decidable (g a ∈ s)] : ∫⁻ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by rw [deterministic_apply, setLIntegral_dirac f s] @[deprecated (since := "2024-06-29")] alias set_lintegral_deterministic := setLIntegral_deterministic theorem integral_deterministic' {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g) (hf : StronglyMeasurable f) : ∫ x, f x ∂deterministic g hg a = f (g a) := by rw [deterministic_apply, integral_dirac' _ _ hf] @[simp] theorem integral_deterministic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g) [MeasurableSingletonClass β] : ∫ x, f x ∂deterministic g hg a = f (g a) := by rw [deterministic_apply, integral_dirac _ (g a)] theorem setIntegral_deterministic' {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g) (hf : StronglyMeasurable f) {s : Set β} (hs : MeasurableSet s) [Decidable (g a ∈ s)] : ∫ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by rw [deterministic_apply, setIntegral_dirac' hf _ hs] @[deprecated (since := "2024-04-17")] alias set_integral_deterministic' := setIntegral_deterministic' @[simp] theorem setIntegral_deterministic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g) [MeasurableSingletonClass β] (s : Set β) [Decidable (g a ∈ s)] : ∫ x in s, f x ∂deterministic g hg a = if g a ∈ s then f (g a) else 0 := by rw [deterministic_apply, setIntegral_dirac f _ s] @[deprecated (since := "2024-04-17")] alias set_integral_deterministic := setIntegral_deterministic end Deterministic section Const /-- Constant kernel, which always returns the same measure. -/ def const (α : Type*) {β : Type*} [MeasurableSpace α] {_ : MeasurableSpace β} (μβ : Measure β) : Kernel α β where toFun _ := μβ measurable' := measurable_const @[simp] theorem const_apply (μβ : Measure β) (a : α) : const α μβ a = μβ := rfl @[simp] lemma const_zero : const α (0 : Measure β) = 0 := by ext x s _; simp [const_apply] lemma const_add (β : Type*) [MeasurableSpace β] (μ ν : Measure α) : const β (μ + ν) = const β μ + const β ν := by ext; simp lemma sum_const [Countable ι] (μ : ι → Measure β) : Kernel.sum (fun n ↦ const α (μ n)) = const α (Measure.sum μ) := by ext x s hs rw [const_apply, Measure.sum_apply _ hs, Kernel.sum_apply' _ _ hs] simp only [const_apply] instance const.instIsFiniteKernel {μβ : Measure β} [IsFiniteMeasure μβ] : IsFiniteKernel (const α μβ) := ⟨⟨μβ Set.univ, measure_lt_top _ _, fun _ => le_rfl⟩⟩ instance const.instIsSFiniteKernel {μβ : Measure β} [SFinite μβ] : IsSFiniteKernel (const α μβ) := ⟨fun n ↦ const α (sFiniteSeq μβ n), fun n ↦ inferInstance, by rw [sum_const, sum_sFiniteSeq]⟩ instance const.instIsMarkovKernel {μβ : Measure β} [hμβ : IsProbabilityMeasure μβ] : IsMarkovKernel (const α μβ) := ⟨fun _ => hμβ⟩ lemma isSFiniteKernel_const [Nonempty α] {μβ : Measure β} : IsSFiniteKernel (const α μβ) ↔ SFinite μβ := ⟨fun h ↦ h.sFinite (Classical.arbitrary α), fun _ ↦ inferInstance⟩ @[simp] theorem lintegral_const {f : β → ℝ≥0∞} {μ : Measure β} {a : α} : ∫⁻ x, f x ∂const α μ a = ∫⁻ x, f x ∂μ := by rw [const_apply] @[simp] theorem setLIntegral_const {f : β → ℝ≥0∞} {μ : Measure β} {a : α} {s : Set β} : ∫⁻ x in s, f x ∂const α μ a = ∫⁻ x in s, f x ∂μ := by rw [const_apply] @[deprecated (since := "2024-06-29")] alias set_lintegral_const := setLIntegral_const @[simp] theorem integral_const {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} {μ : Measure β} {a : α} : ∫ x, f x ∂const α μ a = ∫ x, f x ∂μ := by rw [const_apply] @[simp] theorem setIntegral_const {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} {μ : Measure β} {a : α} {s : Set β} : ∫ x in s, f x ∂const α μ a = ∫ x in s, f x ∂μ := by rw [const_apply] @[deprecated (since := "2024-04-17")] alias set_integral_const := setIntegral_const end Const /-- In a countable space with measurable singletons, every function `α → MeasureTheory.Measure β` defines a kernel. -/ def ofFunOfCountable [MeasurableSpace α] {_ : MeasurableSpace β} [Countable α] [MeasurableSingletonClass α] (f : α → Measure β) : Kernel α β where toFun := f measurable' := measurable_of_countable f section Restrict variable {s t : Set β} /-- Kernel given by the restriction of the measures in the image of a kernel to a set. -/ protected noncomputable def restrict (κ : Kernel α β) (hs : MeasurableSet s) : Kernel α β where toFun a := (κ a).restrict s measurable' := by refine Measure.measurable_of_measurable_coe _ fun t ht => ?_ simp_rw [Measure.restrict_apply ht] exact Kernel.measurable_coe κ (ht.inter hs) theorem restrict_apply (κ : Kernel α β) (hs : MeasurableSet s) (a : α) : κ.restrict hs a = (κ a).restrict s := rfl theorem restrict_apply' (κ : Kernel α β) (hs : MeasurableSet s) (a : α) (ht : MeasurableSet t) : κ.restrict hs a t = (κ a) (t ∩ s) := by rw [restrict_apply κ hs a, Measure.restrict_apply ht] @[simp] theorem restrict_univ : κ.restrict MeasurableSet.univ = κ := by ext1 a rw [Kernel.restrict_apply, Measure.restrict_univ] @[simp] theorem lintegral_restrict (κ : Kernel α β) (hs : MeasurableSet s) (a : α) (f : β → ℝ≥0∞) : ∫⁻ b, f b ∂κ.restrict hs a = ∫⁻ b in s, f b ∂κ a := by rw [restrict_apply] @[simp] theorem setLIntegral_restrict (κ : Kernel α β) (hs : MeasurableSet s) (a : α) (f : β → ℝ≥0∞) (t : Set β) : ∫⁻ b in t, f b ∂κ.restrict hs a = ∫⁻ b in t ∩ s, f b ∂κ a := by rw [restrict_apply, Measure.restrict_restrict' hs] @[deprecated (since := "2024-06-29")] alias set_lintegral_restrict := setLIntegral_restrict @[simp] theorem setIntegral_restrict {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} {a : α} (hs : MeasurableSet s) (t : Set β) : ∫ x in t, f x ∂κ.restrict hs a = ∫ x in t ∩ s, f x ∂κ a := by rw [restrict_apply, Measure.restrict_restrict' hs] @[deprecated (since := "2024-04-17")] alias set_integral_restrict := setIntegral_restrict instance IsFiniteKernel.restrict (κ : Kernel α β) [IsFiniteKernel κ] (hs : MeasurableSet s) : IsFiniteKernel (κ.restrict hs) := by refine ⟨⟨IsFiniteKernel.bound κ, IsFiniteKernel.bound_lt_top κ, fun a => ?_⟩⟩ rw [restrict_apply' κ hs a MeasurableSet.univ] exact measure_le_bound κ a _ instance IsSFiniteKernel.restrict (κ : Kernel α β) [IsSFiniteKernel κ] (hs : MeasurableSet s) : IsSFiniteKernel (κ.restrict hs) := by refine ⟨⟨fun n => Kernel.restrict (seq κ n) hs, inferInstance, ?_⟩⟩ ext1 a simp_rw [sum_apply, restrict_apply, ← Measure.restrict_sum _ hs, ← sum_apply, kernel_sum_seq] end Restrict section ComapRight variable {γ : Type*} {mγ : MeasurableSpace γ} {f : γ → β} /-- Kernel with value `(κ a).comap f`, for a measurable embedding `f`. That is, for a measurable set `t : Set β`, `ProbabilityTheory.Kernel.comapRight κ hf a t = κ a (f '' t)`. -/ noncomputable def comapRight (κ : Kernel α β) (hf : MeasurableEmbedding f) : Kernel α γ where toFun a := (κ a).comap f measurable' := by refine Measure.measurable_measure.mpr fun t ht => ?_ have : (fun a => Measure.comap f (κ a) t) = fun a => κ a (f '' t) := by ext1 a rw [Measure.comap_apply _ hf.injective _ _ ht] exact fun s' hs' ↦ hf.measurableSet_image.mpr hs' rw [this] exact Kernel.measurable_coe _ (hf.measurableSet_image.mpr ht) theorem comapRight_apply (κ : Kernel α β) (hf : MeasurableEmbedding f) (a : α) : comapRight κ hf a = Measure.comap f (κ a) := rfl theorem comapRight_apply' (κ : Kernel α β) (hf : MeasurableEmbedding f) (a : α) {t : Set γ} (ht : MeasurableSet t) : comapRight κ hf a t = κ a (f '' t) := by rw [comapRight_apply, Measure.comap_apply _ hf.injective (fun s => hf.measurableSet_image.mpr) _ ht] @[simp] lemma comapRight_id (κ : Kernel α β) : comapRight κ MeasurableEmbedding.id = κ := by ext _ _ hs; rw [comapRight_apply' _ _ _ hs]; simp theorem IsMarkovKernel.comapRight (κ : Kernel α β) (hf : MeasurableEmbedding f) (hκ : ∀ a, κ a (Set.range f) = 1) : IsMarkovKernel (comapRight κ hf) := by refine ⟨fun a => ⟨?_⟩⟩ rw [comapRight_apply' κ hf a MeasurableSet.univ] simp only [Set.image_univ, Subtype.range_coe_subtype, Set.setOf_mem_eq] exact hκ a instance IsFiniteKernel.comapRight (κ : Kernel α β) [IsFiniteKernel κ] (hf : MeasurableEmbedding f) : IsFiniteKernel (comapRight κ hf) := by refine ⟨⟨IsFiniteKernel.bound κ, IsFiniteKernel.bound_lt_top κ, fun a => ?_⟩⟩ rw [comapRight_apply' κ hf a .univ] exact measure_le_bound κ a _ protected instance IsSFiniteKernel.comapRight (κ : Kernel α β) [IsSFiniteKernel κ] (hf : MeasurableEmbedding f) : IsSFiniteKernel (comapRight κ hf) := by refine ⟨⟨fun n => comapRight (seq κ n) hf, inferInstance, ?_⟩⟩ ext1 a rw [sum_apply] simp_rw [comapRight_apply _ hf] have : (Measure.sum fun n => Measure.comap f (seq κ n a)) = Measure.comap f (Measure.sum fun n => seq κ n a) := by ext1 t ht rw [Measure.comap_apply _ hf.injective (fun s' => hf.measurableSet_image.mpr) _ ht, Measure.sum_apply _ ht, Measure.sum_apply _ (hf.measurableSet_image.mpr ht)] congr with n : 1 rw [Measure.comap_apply _ hf.injective (fun s' => hf.measurableSet_image.mpr) _ ht] rw [this, measure_sum_seq] end ComapRight section Piecewise variable {η : Kernel α β} {s : Set α} {hs : MeasurableSet s} [DecidablePred (· ∈ s)] /-- `ProbabilityTheory.Kernel.piecewise hs κ η` is the kernel equal to `κ` on the measurable set `s` and to `η` on its complement. -/ def piecewise (hs : MeasurableSet s) (κ η : Kernel α β) : Kernel α β where toFun a := if a ∈ s then κ a else η a measurable' := κ.measurable.piecewise hs η.measurable theorem piecewise_apply (a : α) : piecewise hs κ η a = if a ∈ s then κ a else η a := rfl theorem piecewise_apply' (a : α) (t : Set β) : piecewise hs κ η a t = if a ∈ s then κ a t else η a t := by rw [piecewise_apply]; split_ifs <;> rfl instance IsMarkovKernel.piecewise [IsMarkovKernel κ] [IsMarkovKernel η] : IsMarkovKernel (piecewise hs κ η) := by refine ⟨fun a => ⟨?_⟩⟩ rw [piecewise_apply', measure_univ, measure_univ, ite_self] instance IsFiniteKernel.piecewise [IsFiniteKernel κ] [IsFiniteKernel η] : IsFiniteKernel (piecewise hs κ η) := by refine ⟨⟨max (IsFiniteKernel.bound κ) (IsFiniteKernel.bound η), ?_, fun a => ?_⟩⟩ · exact max_lt (IsFiniteKernel.bound_lt_top κ) (IsFiniteKernel.bound_lt_top η) rw [piecewise_apply'] exact (ite_le_sup _ _ _).trans (sup_le_sup (measure_le_bound _ _ _) (measure_le_bound _ _ _)) protected instance IsSFiniteKernel.piecewise [IsSFiniteKernel κ] [IsSFiniteKernel η] : IsSFiniteKernel (piecewise hs κ η) := by refine ⟨⟨fun n => piecewise hs (seq κ n) (seq η n), inferInstance, ?_⟩⟩ ext1 a simp_rw [sum_apply, Kernel.piecewise_apply] split_ifs <;> exact (measure_sum_seq _ a).symm theorem lintegral_piecewise (a : α) (g : β → ℝ≥0∞) : ∫⁻ b, g b ∂piecewise hs κ η a = if a ∈ s then ∫⁻ b, g b ∂κ a else ∫⁻ b, g b ∂η a := by simp_rw [piecewise_apply]; split_ifs <;> rfl theorem setLIntegral_piecewise (a : α) (g : β → ℝ≥0∞) (t : Set β) : ∫⁻ b in t, g b ∂piecewise hs κ η a = if a ∈ s then ∫⁻ b in t, g b ∂κ a else ∫⁻ b in t, g b ∂η a := by simp_rw [piecewise_apply]; split_ifs <;> rfl @[deprecated (since := "2024-06-29")] alias set_lintegral_piecewise := setLIntegral_piecewise theorem integral_piecewise {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (a : α) (g : β → E) : ∫ b, g b ∂piecewise hs κ η a = if a ∈ s then ∫ b, g b ∂κ a else ∫ b, g b ∂η a := by simp_rw [piecewise_apply]; split_ifs <;> rfl theorem setIntegral_piecewise {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (a : α) (g : β → E) (t : Set β) : ∫ b in t, g b ∂piecewise hs κ η a = if a ∈ s then ∫ b in t, g b ∂κ a else ∫ b in t, g b ∂η a := by simp_rw [piecewise_apply]; split_ifs <;> rfl @[deprecated (since := "2024-04-17")] alias set_integral_piecewise := setIntegral_piecewise end Piecewise end Kernel end ProbabilityTheory
Probability\Kernel\Composition.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.Probability.Kernel.MeasurableIntegral /-! # Product and composition of kernels We define * the composition-product `κ ⊗ₖ η` of two s-finite kernels `κ : Kernel α β` and `η : Kernel (α × β) γ`, a kernel from `α` to `β × γ`. * the map and comap of a kernel along a measurable function. * the composition `η ∘ₖ κ` of kernels `κ : Kernel α β` and `η : Kernel β γ`, kernel from `α` to `γ`. * the product `κ ×ₖ η` of s-finite kernels `κ : Kernel α β` and `η : Kernel α γ`, a kernel from `α` to `β × γ`. A note on names: The composition-product `Kernel α β → Kernel (α × β) γ → Kernel α (β × γ)` is named composition in [kallenberg2021] and product on the wikipedia article on transition kernels. Most papers studying categories of kernels call composition the map we call composition. We adopt that convention because it fits better with the use of the name `comp` elsewhere in mathlib. ## Main definitions Kernels built from other kernels: * `compProd (κ : Kernel α β) (η : Kernel (α × β) γ) : Kernel α (β × γ)`: composition-product of 2 s-finite kernels. We define a notation `κ ⊗ₖ η = compProd κ η`. `∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)` * `map (κ : Kernel α β) (f : β → γ) (hf : Measurable f) : Kernel α γ` `∫⁻ c, g c ∂(map κ f hf a) = ∫⁻ b, g (f b) ∂(κ a)` * `comap (κ : Kernel α β) (f : γ → α) (hf : Measurable f) : Kernel γ β` `∫⁻ b, g b ∂(comap κ f hf c) = ∫⁻ b, g b ∂(κ (f c))` * `comp (η : Kernel β γ) (κ : Kernel α β) : Kernel α γ`: composition of 2 kernels. We define a notation `η ∘ₖ κ = comp η κ`. `∫⁻ c, g c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂(η b) ∂(κ a)` * `prod (κ : Kernel α β) (η : Kernel α γ) : Kernel α (β × γ)`: product of 2 s-finite kernels. `∫⁻ bc, f bc ∂((κ ×ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η a) ∂(κ a)` ## Main statements * `lintegral_compProd`, `lintegral_map`, `lintegral_comap`, `lintegral_comp`, `lintegral_prod`: Lebesgue integral of a function against a composition-product/map/comap/composition/product of kernels. * Instances of the form `<class>.<operation>` where class is one of `IsMarkovKernel`, `IsFiniteKernel`, `IsSFiniteKernel` and operation is one of `compProd`, `map`, `comap`, `comp`, `prod`. These instances state that the three classes are stable by the various operations. ## Notations * `κ ⊗ₖ η = ProbabilityTheory.Kernel.compProd κ η` * `η ∘ₖ κ = ProbabilityTheory.Kernel.comp η κ` * `κ ×ₖ η = ProbabilityTheory.Kernel.prod κ η` -/ open MeasureTheory open scoped ENNReal namespace ProbabilityTheory namespace Kernel variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} section CompositionProduct /-! ### Composition-Product of kernels We define a kernel composition-product `compProd : Kernel α β → Kernel (α × β) γ → Kernel α (β × γ)`. -/ variable {γ : Type*} {mγ : MeasurableSpace γ} {s : Set (β × γ)} /-- Auxiliary function for the definition of the composition-product of two kernels. For all `a : α`, `compProdFun κ η a` is a countably additive function with value zero on the empty set, and the composition-product of kernels is defined in `Kernel.compProd` through `Measure.ofMeasurable`. -/ noncomputable def compProdFun (κ : Kernel α β) (η : Kernel (α × β) γ) (a : α) (s : Set (β × γ)) : ℝ≥0∞ := ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a theorem compProdFun_empty (κ : Kernel α β) (η : Kernel (α × β) γ) (a : α) : compProdFun κ η a ∅ = 0 := by simp only [compProdFun, Set.mem_empty_iff_false, Set.setOf_false, measure_empty, MeasureTheory.lintegral_const, zero_mul] theorem compProdFun_iUnion (κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (f : ℕ → Set (β × γ)) (hf_meas : ∀ i, MeasurableSet (f i)) (hf_disj : Pairwise (Disjoint on f)) : compProdFun κ η a (⋃ i, f i) = ∑' i, compProdFun κ η a (f i) := by have h_Union : (fun b => η (a, b) {c : γ | (b, c) ∈ ⋃ i, f i}) = fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i}) := by ext1 b congr with c simp only [Set.mem_iUnion, Set.iSup_eq_iUnion, Set.mem_setOf_eq] rw [compProdFun, h_Union] have h_tsum : (fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i})) = fun b => ∑' i, η (a, b) {c : γ | (b, c) ∈ f i} := by ext1 b rw [measure_iUnion] · intro i j hij s hsi hsj c hcs have hbci : {(b, c)} ⊆ f i := by rw [Set.singleton_subset_iff]; exact hsi hcs have hbcj : {(b, c)} ⊆ f j := by rw [Set.singleton_subset_iff]; exact hsj hcs simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff, Set.mem_empty_iff_false] using hf_disj hij hbci hbcj · -- Porting note: behavior of `@` changed relative to lean 3, was -- exact fun i => (@measurable_prod_mk_left β γ _ _ b) _ (hf_meas i) exact fun i => (@measurable_prod_mk_left β γ _ _ b) (hf_meas i) rw [h_tsum, lintegral_tsum] · rfl · intro i have hm : MeasurableSet {p : (α × β) × γ | (p.1.2, p.2) ∈ f i} := measurable_fst.snd.prod_mk measurable_snd (hf_meas i) exact ((measurable_kernel_prod_mk_left hm).comp measurable_prod_mk_left).aemeasurable theorem compProdFun_tsum_right (κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : compProdFun κ η a s = ∑' n, compProdFun κ (seq η n) a s := by simp_rw [compProdFun, (measure_sum_seq η _).symm] have : ∫⁻ b, Measure.sum (fun n => seq η n (a, b)) {c : γ | (b, c) ∈ s} ∂κ a = ∫⁻ b, ∑' n, seq η n (a, b) {c : γ | (b, c) ∈ s} ∂κ a := by congr ext1 b rw [Measure.sum_apply] exact measurable_prod_mk_left hs rw [this, lintegral_tsum] exact fun n => ((measurable_kernel_prod_mk_left (κ := (seq η n)) ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp measurable_prod_mk_left).aemeasurable theorem compProdFun_tsum_left (κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel κ] (a : α) (s : Set (β × γ)) : compProdFun κ η a s = ∑' n, compProdFun (seq κ n) η a s := by simp_rw [compProdFun, (measure_sum_seq κ _).symm, lintegral_sum_measure] theorem compProdFun_eq_tsum (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : compProdFun κ η a s = ∑' (n) (m), compProdFun (seq κ n) (seq η m) a s := by simp_rw [compProdFun_tsum_left κ η a s, compProdFun_tsum_right _ η a hs] /-- Auxiliary lemma for `measurable_compProdFun`. -/ theorem measurable_compProdFun_of_finite (κ : Kernel α β) [IsFiniteKernel κ] (η : Kernel (α × β) γ) [IsFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by simp only [compProdFun] have h_meas : Measurable (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) := by have : (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) = fun p => η p {c : γ | (p.2, c) ∈ s} := by ext1 p rw [Function.uncurry_apply_pair] rw [this] exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs) exact h_meas.lintegral_kernel_prod_right theorem measurable_compProdFun (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by simp_rw [compProdFun_tsum_right κ η _ hs] refine Measurable.ennreal_tsum fun n => ?_ simp only [compProdFun] have h_meas : Measurable (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) := by have : (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) = fun p => seq η n p {c : γ | (p.2, c) ∈ s} := by ext1 p rw [Function.uncurry_apply_pair] rw [this] exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs) exact h_meas.lintegral_kernel_prod_right open scoped Classical /-- Composition-Product of kernels. For s-finite kernels, it satisfies `∫⁻ bc, f bc ∂(compProd κ η a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)` (see `ProbabilityTheory.Kernel.lintegral_compProd`). If either of the kernels is not s-finite, `compProd` is given the junk value 0. -/ noncomputable def compProd (κ : Kernel α β) (η : Kernel (α × β) γ) : Kernel α (β × γ) := if h : IsSFiniteKernel κ ∧ IsSFiniteKernel η then { toFun := fun a ↦ Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (@compProdFun_iUnion _ _ _ _ _ _ κ η h.2 a) measurable' := by have : IsSFiniteKernel κ := h.1 have : IsSFiniteKernel η := h.2 refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ have : (fun a => Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (compProdFun_iUnion κ η a) s) = fun a => compProdFun κ η a s := by ext1 a; rwa [Measure.ofMeasurable_apply] rw [this] exact measurable_compProdFun κ η hs } else 0 scoped[ProbabilityTheory] infixl:100 " ⊗ₖ " => ProbabilityTheory.Kernel.compProd theorem compProd_apply_eq_compProdFun (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = compProdFun κ η a s := by rw [compProd, dif_pos] swap · constructor <;> infer_instance change Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (compProdFun_iUnion κ η a) s = ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a rw [Measure.ofMeasurable_apply _ hs] rfl theorem compProd_of_not_isSFiniteKernel_left (κ : Kernel α β) (η : Kernel (α × β) γ) (h : ¬ IsSFiniteKernel κ) : κ ⊗ₖ η = 0 := by rw [compProd, dif_neg] simp [h] theorem compProd_of_not_isSFiniteKernel_right (κ : Kernel α β) (η : Kernel (α × β) γ) (h : ¬ IsSFiniteKernel η) : κ ⊗ₖ η = 0 := by rw [compProd, dif_neg] simp [h] theorem compProd_apply (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a := compProd_apply_eq_compProdFun κ η a hs theorem le_compProd_apply (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (s : Set (β × γ)) : ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a ≤ (κ ⊗ₖ η) a s := calc ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a ≤ ∫⁻ b, η (a, b) {c | (b, c) ∈ toMeasurable ((κ ⊗ₖ η) a) s} ∂κ a := lintegral_mono fun _ => measure_mono fun _ h_mem => subset_toMeasurable _ _ h_mem _ = (κ ⊗ₖ η) a (toMeasurable ((κ ⊗ₖ η) a) s) := (Kernel.compProd_apply_eq_compProdFun κ η a (measurableSet_toMeasurable _ _)).symm _ = (κ ⊗ₖ η) a s := measure_toMeasurable s @[simp] lemma compProd_zero_left (κ : Kernel (α × β) γ) : (0 : Kernel α β) ⊗ₖ κ = 0 := by by_cases h : IsSFiniteKernel κ · ext a s hs rw [Kernel.compProd_apply _ _ _ hs] simp · rw [Kernel.compProd_of_not_isSFiniteKernel_right _ _ h] @[simp] lemma compProd_zero_right (κ : Kernel α β) (γ : Type*) [MeasurableSpace γ] : κ ⊗ₖ (0 : Kernel (α × β) γ) = 0 := by by_cases h : IsSFiniteKernel κ · ext a s hs rw [Kernel.compProd_apply _ _ _ hs] simp · rw [Kernel.compProd_of_not_isSFiniteKernel_left _ _ h] section Ae /-! ### `ae` filter of the composition-product -/ variable {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η] {a : α} theorem ae_kernel_lt_top (a : α) (h2s : (κ ⊗ₖ η) a s ≠ ∞) : ∀ᵐ b ∂κ a, η (a, b) (Prod.mk b ⁻¹' s) < ∞ := by let t := toMeasurable ((κ ⊗ₖ η) a) s have : ∀ b : β, η (a, b) (Prod.mk b ⁻¹' s) ≤ η (a, b) (Prod.mk b ⁻¹' t) := fun b => measure_mono (Set.preimage_mono (subset_toMeasurable _ _)) have ht : MeasurableSet t := measurableSet_toMeasurable _ _ have h2t : (κ ⊗ₖ η) a t ≠ ∞ := by rwa [measure_toMeasurable] have ht_lt_top : ∀ᵐ b ∂κ a, η (a, b) (Prod.mk b ⁻¹' t) < ∞ := by rw [Kernel.compProd_apply _ _ _ ht] at h2t exact ae_lt_top (Kernel.measurable_kernel_prod_mk_left' ht a) h2t filter_upwards [ht_lt_top] with b hb exact (this b).trans_lt hb theorem compProd_null (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = 0 ↔ (fun b => η (a, b) (Prod.mk b ⁻¹' s)) =ᵐ[κ a] 0 := by rw [Kernel.compProd_apply _ _ _ hs, lintegral_eq_zero_iff] · rfl · exact Kernel.measurable_kernel_prod_mk_left' hs a theorem ae_null_of_compProd_null (h : (κ ⊗ₖ η) a s = 0) : (fun b => η (a, b) (Prod.mk b ⁻¹' s)) =ᵐ[κ a] 0 := by obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h simp_rw [compProd_null a mt] at ht rw [Filter.eventuallyLE_antisymm_iff] exact ⟨Filter.EventuallyLE.trans_eq (Filter.eventually_of_forall fun x => (measure_mono (Set.preimage_mono hst) : _)) ht, Filter.eventually_of_forall fun x => zero_le _⟩ theorem ae_ae_of_ae_compProd {p : β × γ → Prop} (h : ∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc) : ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c) := ae_null_of_compProd_null h lemma ae_compProd_of_ae_ae {p : β × γ → Prop} (hp : MeasurableSet {x | p x}) (h : ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c)) : ∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc := by simp_rw [ae_iff] at h ⊢ rw [compProd_null] · exact h · exact hp.compl lemma ae_compProd_iff {p : β × γ → Prop} (hp : MeasurableSet {x | p x}) : (∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc) ↔ ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c) := ⟨fun h ↦ ae_ae_of_ae_compProd h, fun h ↦ ae_compProd_of_ae_ae hp h⟩ end Ae section Restrict variable {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η] {a : α} theorem compProd_restrict {s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) : Kernel.restrict κ hs ⊗ₖ Kernel.restrict η ht = Kernel.restrict (κ ⊗ₖ η) (hs.prod ht) := by ext a u hu rw [compProd_apply _ _ _ hu, restrict_apply' _ _ _ hu, compProd_apply _ _ _ (hu.inter (hs.prod ht))] simp only [Kernel.restrict_apply, Measure.restrict_apply' ht, Set.mem_inter_iff, Set.prod_mk_mem_set_prod_eq] have : ∀ b, η (a, b) {c : γ | (b, c) ∈ u ∧ b ∈ s ∧ c ∈ t} = s.indicator (fun b => η (a, b) ({c : γ | (b, c) ∈ u} ∩ t)) b := by intro b classical rw [Set.indicator_apply] split_ifs with h · simp only [h, true_and_iff] rfl · simp only [h, false_and_iff, and_false_iff, Set.setOf_false, measure_empty] simp_rw [this] rw [lintegral_indicator _ hs] theorem compProd_restrict_left {s : Set β} (hs : MeasurableSet s) : Kernel.restrict κ hs ⊗ₖ η = Kernel.restrict (κ ⊗ₖ η) (hs.prod MeasurableSet.univ) := by rw [← compProd_restrict] · congr; exact Kernel.restrict_univ.symm theorem compProd_restrict_right {t : Set γ} (ht : MeasurableSet t) : κ ⊗ₖ Kernel.restrict η ht = Kernel.restrict (κ ⊗ₖ η) (MeasurableSet.univ.prod ht) := by rw [← compProd_restrict] · congr; exact Kernel.restrict_univ.symm end Restrict section Lintegral /-! ### Lebesgue integral -/ /-- Lebesgue integral against the composition-product of two kernels. -/ theorem lintegral_compProd' (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β → γ → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) : ∫⁻ bc, f bc.1 bc.2 ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, f b c ∂η (a, b) ∂κ a := by let F : ℕ → SimpleFunc (β × γ) ℝ≥0∞ := SimpleFunc.eapprox (Function.uncurry f) have h : ∀ a, ⨆ n, F n a = Function.uncurry f a := SimpleFunc.iSup_eapprox_apply (Function.uncurry f) hf simp only [Prod.forall, Function.uncurry_apply_pair] at h simp_rw [← h] have h_mono : Monotone F := fun i j hij b => SimpleFunc.monotone_eapprox (Function.uncurry f) hij _ rw [lintegral_iSup (fun n => (F n).measurable) h_mono] have : ∀ b, ∫⁻ c, ⨆ n, F n (b, c) ∂η (a, b) = ⨆ n, ∫⁻ c, F n (b, c) ∂η (a, b) := by intro a rw [lintegral_iSup] · exact fun n => (F n).measurable.comp measurable_prod_mk_left · exact fun i j hij b => h_mono hij _ simp_rw [this] have h_some_meas_integral : ∀ f' : SimpleFunc (β × γ) ℝ≥0∞, Measurable fun b => ∫⁻ c, f' (b, c) ∂η (a, b) := by intro f' have : (fun b => ∫⁻ c, f' (b, c) ∂η (a, b)) = (fun ab => ∫⁻ c, f' (ab.2, c) ∂η ab) ∘ fun b => (a, b) := by ext1 ab; rfl rw [this] apply Measurable.comp _ (measurable_prod_mk_left (m := mα)) exact Measurable.lintegral_kernel_prod_right ((SimpleFunc.measurable _).comp (measurable_fst.snd.prod_mk measurable_snd)) rw [lintegral_iSup] rotate_left · exact fun n => h_some_meas_integral (F n) · exact fun i j hij b => lintegral_mono fun c => h_mono hij _ congr ext1 n refine SimpleFunc.induction ?_ ?_ (F n) · intro c s hs classical -- Porting note: Added `classical` for `Set.piecewise_eq_indicator` simp (config := { unfoldPartialApp := true }) only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, Function.const, lintegral_indicator_const hs] rw [compProd_apply κ η _ hs, ← lintegral_const_mul c _] swap · exact (measurable_kernel_prod_mk_left ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp measurable_prod_mk_left congr ext1 b rw [lintegral_indicator_const_comp measurable_prod_mk_left hs] rfl · intro f f' _ hf_eq hf'_eq simp_rw [SimpleFunc.coe_add, Pi.add_apply] change ∫⁻ x, (f : β × γ → ℝ≥0∞) x + f' x ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c : γ, f (b, c) + f' (b, c) ∂η (a, b) ∂κ a rw [lintegral_add_left (SimpleFunc.measurable _), hf_eq, hf'_eq, ← lintegral_add_left] swap · exact h_some_meas_integral f congr with b rw [lintegral_add_left] exact (SimpleFunc.measurable _).comp measurable_prod_mk_left /-- Lebesgue integral against the composition-product of two kernels. -/ theorem lintegral_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) : ∫⁻ bc, f bc ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, f (b, c) ∂η (a, b) ∂κ a := by let g := Function.curry f change ∫⁻ bc, f bc ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, g b c ∂η (a, b) ∂κ a rw [← lintegral_compProd'] · simp_rw [g, Function.curry_apply] · simp_rw [g, Function.uncurry_curry]; exact hf /-- Lebesgue integral against the composition-product of two kernels. -/ theorem lintegral_compProd₀ (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : AEMeasurable f ((κ ⊗ₖ η) a)) : ∫⁻ z, f z ∂(κ ⊗ₖ η) a = ∫⁻ x, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a := by have A : ∫⁻ z, f z ∂(κ ⊗ₖ η) a = ∫⁻ z, hf.mk f z ∂(κ ⊗ₖ η) a := lintegral_congr_ae hf.ae_eq_mk have B : ∫⁻ x, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a = ∫⁻ x, ∫⁻ y, hf.mk f (x, y) ∂η (a, x) ∂κ a := by apply lintegral_congr_ae filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with _ ha using lintegral_congr_ae ha rw [A, B, lintegral_compProd] exact hf.measurable_mk theorem setLIntegral_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) : ∫⁻ z in s ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫⁻ x in s, ∫⁻ y in t, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [← Kernel.restrict_apply (κ ⊗ₖ η) (hs.prod ht), ← compProd_restrict hs ht, lintegral_compProd _ _ _ hf, Kernel.restrict_apply] @[deprecated (since := "2024-06-29")] alias set_lintegral_compProd := setLIntegral_compProd theorem setLIntegral_compProd_univ_right (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : ∫⁻ z in s ×ˢ Set.univ, f z ∂(κ ⊗ₖ η) a = ∫⁻ x in s, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [setLIntegral_compProd κ η a hf hs MeasurableSet.univ, Measure.restrict_univ] @[deprecated (since := "2024-06-29")] alias set_lintegral_compProd_univ_right := setLIntegral_compProd_univ_right theorem setLIntegral_compProd_univ_left (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {t : Set γ} (ht : MeasurableSet t) : ∫⁻ z in Set.univ ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫⁻ x, ∫⁻ y in t, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [setLIntegral_compProd κ η a hf MeasurableSet.univ ht, Measure.restrict_univ] @[deprecated (since := "2024-06-29")] alias set_lintegral_compProd_univ_left := setLIntegral_compProd_univ_left end Lintegral theorem compProd_eq_tsum_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = ∑' (n : ℕ) (m : ℕ), (seq κ n ⊗ₖ seq η m) a s := by simp_rw [compProd_apply_eq_compProdFun _ _ _ hs]; exact compProdFun_eq_tsum κ η a hs theorem compProd_eq_sum_compProd (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] : κ ⊗ₖ η = Kernel.sum fun n => Kernel.sum fun m => seq κ n ⊗ₖ seq η m := by ext a s hs; simp_rw [Kernel.sum_apply' _ a hs]; rw [compProd_eq_tsum_compProd κ η a hs] theorem compProd_eq_sum_compProd_left (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) : κ ⊗ₖ η = Kernel.sum fun n => seq κ n ⊗ₖ η := by by_cases h : IsSFiniteKernel η swap · simp_rw [compProd_of_not_isSFiniteKernel_right _ _ h] simp rw [compProd_eq_sum_compProd] congr with n a s hs simp_rw [Kernel.sum_apply' _ _ hs, compProd_apply_eq_compProdFun _ _ _ hs, compProdFun_tsum_right _ η a hs] theorem compProd_eq_sum_compProd_right (κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel η] : κ ⊗ₖ η = Kernel.sum fun n => κ ⊗ₖ seq η n := by by_cases hκ : IsSFiniteKernel κ swap · simp_rw [compProd_of_not_isSFiniteKernel_left _ _ hκ] simp rw [compProd_eq_sum_compProd] simp_rw [compProd_eq_sum_compProd_left κ _] rw [Kernel.sum_comm] instance IsMarkovKernel.compProd (κ : Kernel α β) [IsMarkovKernel κ] (η : Kernel (α × β) γ) [IsMarkovKernel η] : IsMarkovKernel (κ ⊗ₖ η) := ⟨fun a => ⟨by rw [compProd_apply κ η a MeasurableSet.univ] simp only [Set.mem_univ, Set.setOf_true, measure_univ, lintegral_one]⟩⟩ theorem compProd_apply_univ_le (κ : Kernel α β) (η : Kernel (α × β) γ) [IsFiniteKernel η] (a : α) : (κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * IsFiniteKernel.bound η := by by_cases hκ : IsSFiniteKernel κ swap · rw [compProd_of_not_isSFiniteKernel_left _ _ hκ] simp rw [compProd_apply κ η a MeasurableSet.univ] simp only [Set.mem_univ, Set.setOf_true] let Cη := IsFiniteKernel.bound η calc ∫⁻ b, η (a, b) Set.univ ∂κ a ≤ ∫⁻ _, Cη ∂κ a := lintegral_mono fun b => measure_le_bound η (a, b) Set.univ _ = Cη * κ a Set.univ := MeasureTheory.lintegral_const Cη _ = κ a Set.univ * Cη := mul_comm _ _ instance IsFiniteKernel.compProd (κ : Kernel α β) [IsFiniteKernel κ] (η : Kernel (α × β) γ) [IsFiniteKernel η] : IsFiniteKernel (κ ⊗ₖ η) := ⟨⟨IsFiniteKernel.bound κ * IsFiniteKernel.bound η, ENNReal.mul_lt_top (IsFiniteKernel.bound_ne_top κ) (IsFiniteKernel.bound_ne_top η), fun a => calc (κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * IsFiniteKernel.bound η := compProd_apply_univ_le κ η a _ ≤ IsFiniteKernel.bound κ * IsFiniteKernel.bound η := mul_le_mul (measure_le_bound κ a Set.univ) le_rfl (zero_le _) (zero_le _)⟩⟩ instance IsSFiniteKernel.compProd (κ : Kernel α β) (η : Kernel (α × β) γ) : IsSFiniteKernel (κ ⊗ₖ η) := by by_cases h : IsSFiniteKernel κ swap · rw [compProd_of_not_isSFiniteKernel_left _ _ h] infer_instance by_cases h : IsSFiniteKernel η swap · rw [compProd_of_not_isSFiniteKernel_right _ _ h] infer_instance rw [compProd_eq_sum_compProd] exact Kernel.isSFiniteKernel_sum fun n => Kernel.isSFiniteKernel_sum inferInstance lemma compProd_add_left (μ κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel μ] [IsSFiniteKernel κ] [IsSFiniteKernel η] : (μ + κ) ⊗ₖ η = μ ⊗ₖ η + κ ⊗ₖ η := by ext _ _ hs; simp [compProd_apply _ _ _ hs] lemma compProd_add_right (μ : Kernel α β) (κ η : Kernel (α × β) γ) [IsSFiniteKernel μ] [IsSFiniteKernel κ] [IsSFiniteKernel η] : μ ⊗ₖ (κ + η) = μ ⊗ₖ κ + μ ⊗ₖ η := by ext a s hs simp only [compProd_apply _ _ _ hs, coe_add, Pi.add_apply, Measure.coe_add] rw [lintegral_add_left] exact measurable_kernel_prod_mk_left' hs a lemma comapRight_compProd_id_prod {δ : Type*} {mδ : MeasurableSpace δ} (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel (α × β) γ) [IsSFiniteKernel η] {f : δ → γ} (hf : MeasurableEmbedding f) : comapRight (κ ⊗ₖ η) (MeasurableEmbedding.id.prod_mk hf) = κ ⊗ₖ (comapRight η hf) := by ext a t ht rw [comapRight_apply' _ _ _ ht, compProd_apply, compProd_apply _ _ _ ht] swap; · exact (MeasurableEmbedding.id.prod_mk hf).measurableSet_image.mpr ht refine lintegral_congr (fun b ↦ ?_) simp only [id_eq, Set.mem_image, Prod.mk.injEq, Prod.exists] rw [comapRight_apply'] swap; · exact measurable_prod_mk_left ht congr with x simp only [Set.mem_setOf_eq, Set.mem_image] constructor · rintro ⟨b', c, h, rfl, rfl⟩ exact ⟨c, h, rfl⟩ · rintro ⟨c, h, rfl⟩ exact ⟨b, c, h, rfl, rfl⟩ end CompositionProduct section MapComap /-! ### map, comap -/ variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : β → γ} {g : γ → α} /-- The pushforward of a kernel along a measurable function. We include measurability in the assumptions instead of using junk values to make sure that typeclass inference can infer that the `map` of a Markov kernel is again a Markov kernel. -/ noncomputable def map (κ : Kernel α β) (f : β → γ) (hf : Measurable f) : Kernel α γ where toFun a := (κ a).map f measurable' := (Measure.measurable_map _ hf).comp (Kernel.measurable κ) theorem map_apply (κ : Kernel α β) (hf : Measurable f) (a : α) : map κ f hf a = (κ a).map f := rfl theorem map_apply' (κ : Kernel α β) (hf : Measurable f) (a : α) {s : Set γ} (hs : MeasurableSet s) : map κ f hf a s = κ a (f ⁻¹' s) := by rw [map_apply, Measure.map_apply hf hs] @[simp] lemma map_zero (hf : Measurable f) : Kernel.map (0 : Kernel α β) f hf = 0 := by ext; rw [Kernel.map_apply]; simp @[simp] lemma map_id (κ : Kernel α β) : map κ id measurable_id = κ := by ext a; rw [map_apply]; simp @[simp] lemma map_id' (κ : Kernel α β) : map κ (fun a ↦ a) measurable_id = κ := map_id κ nonrec theorem lintegral_map (κ : Kernel α β) (hf : Measurable f) (a : α) {g' : γ → ℝ≥0∞} (hg : Measurable g') : ∫⁻ b, g' b ∂map κ f hf a = ∫⁻ a, g' (f a) ∂κ a := by rw [map_apply _ hf, lintegral_map hg hf] theorem sum_map_seq (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable f) : (Kernel.sum fun n => map (seq κ n) f hf) = map κ f hf := by ext a s hs rw [Kernel.sum_apply, map_apply' κ hf a hs, Measure.sum_apply _ hs, ← measure_sum_seq κ, Measure.sum_apply _ (hf hs)] simp_rw [map_apply' _ hf _ hs] instance IsMarkovKernel.map (κ : Kernel α β) [IsMarkovKernel κ] (hf : Measurable f) : IsMarkovKernel (map κ f hf) := ⟨fun a => ⟨by rw [map_apply' κ hf a MeasurableSet.univ, Set.preimage_univ, measure_univ]⟩⟩ instance IsFiniteKernel.map (κ : Kernel α β) [IsFiniteKernel κ] (hf : Measurable f) : IsFiniteKernel (map κ f hf) := by refine ⟨⟨IsFiniteKernel.bound κ, IsFiniteKernel.bound_lt_top κ, fun a => ?_⟩⟩ rw [map_apply' κ hf a MeasurableSet.univ] exact measure_le_bound κ a _ instance IsSFiniteKernel.map (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable f) : IsSFiniteKernel (map κ f hf) := ⟨⟨fun n => Kernel.map (seq κ n) f hf, inferInstance, (sum_map_seq κ hf).symm⟩⟩ @[simp] lemma map_const (μ : Measure α) {f : α → β} (hf : Measurable f) : map (const γ μ) f hf = const γ (μ.map f) := by ext x s hs rw [map_apply' _ _ _ hs, const_apply, const_apply, Measure.map_apply hf hs] /-- Pullback of a kernel, such that for each set s `comap κ g hg c s = κ (g c) s`. We include measurability in the assumptions instead of using junk values to make sure that typeclass inference can infer that the `comap` of a Markov kernel is again a Markov kernel. -/ def comap (κ : Kernel α β) (g : γ → α) (hg : Measurable g) : Kernel γ β where toFun a := κ (g a) measurable' := κ.measurable.comp hg theorem comap_apply (κ : Kernel α β) (hg : Measurable g) (c : γ) : comap κ g hg c = κ (g c) := rfl theorem comap_apply' (κ : Kernel α β) (hg : Measurable g) (c : γ) (s : Set β) : comap κ g hg c s = κ (g c) s := rfl @[simp] lemma comap_zero (hg : Measurable g) : Kernel.comap (0 : Kernel α β) g hg = 0 := by ext; rw [Kernel.comap_apply]; simp @[simp] lemma comap_id (κ : Kernel α β) : comap κ id measurable_id = κ := by ext a; rw [comap_apply]; simp @[simp] lemma comap_id' (κ : Kernel α β) : comap κ (fun a ↦ a) measurable_id = κ := comap_id κ theorem lintegral_comap (κ : Kernel α β) (hg : Measurable g) (c : γ) (g' : β → ℝ≥0∞) : ∫⁻ b, g' b ∂comap κ g hg c = ∫⁻ b, g' b ∂κ (g c) := rfl theorem sum_comap_seq (κ : Kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) : (Kernel.sum fun n => comap (seq κ n) g hg) = comap κ g hg := by ext a s hs rw [Kernel.sum_apply, comap_apply' κ hg a s, Measure.sum_apply _ hs, ← measure_sum_seq κ, Measure.sum_apply _ hs] simp_rw [comap_apply' _ hg _ s] instance IsMarkovKernel.comap (κ : Kernel α β) [IsMarkovKernel κ] (hg : Measurable g) : IsMarkovKernel (comap κ g hg) := ⟨fun a => ⟨by rw [comap_apply' κ hg a Set.univ, measure_univ]⟩⟩ instance IsFiniteKernel.comap (κ : Kernel α β) [IsFiniteKernel κ] (hg : Measurable g) : IsFiniteKernel (comap κ g hg) := by refine ⟨⟨IsFiniteKernel.bound κ, IsFiniteKernel.bound_lt_top κ, fun a => ?_⟩⟩ rw [comap_apply' κ hg a Set.univ] exact measure_le_bound κ _ _ instance IsSFiniteKernel.comap (κ : Kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) : IsSFiniteKernel (comap κ g hg) := ⟨⟨fun n => Kernel.comap (seq κ n) g hg, inferInstance, (sum_comap_seq κ hg).symm⟩⟩ lemma comap_map_comm (κ : Kernel β γ) {f : α → β} {g : γ → δ} (hf : Measurable f) (hg : Measurable g) : comap (map κ g hg) f hf = map (comap κ f hf) g hg := by ext x s _ rw [comap_apply, map_apply, map_apply, comap_apply] end MapComap open scoped ProbabilityTheory section FstSnd variable {δ : Type*} {mδ : MeasurableSpace δ} /-- Define a `Kernel (γ × α) β` from a `Kernel α β` by taking the comap of the projection. -/ def prodMkLeft (γ : Type*) [MeasurableSpace γ] (κ : Kernel α β) : Kernel (γ × α) β := comap κ Prod.snd measurable_snd /-- Define a `Kernel (α × γ) β` from a `Kernel α β` by taking the comap of the projection. -/ def prodMkRight (γ : Type*) [MeasurableSpace γ] (κ : Kernel α β) : Kernel (α × γ) β := comap κ Prod.fst measurable_fst variable {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α} @[simp] theorem prodMkLeft_apply (κ : Kernel α β) (ca : γ × α) : prodMkLeft γ κ ca = κ ca.snd := rfl @[simp] theorem prodMkRight_apply (κ : Kernel α β) (ca : α × γ) : prodMkRight γ κ ca = κ ca.fst := rfl theorem prodMkLeft_apply' (κ : Kernel α β) (ca : γ × α) (s : Set β) : prodMkLeft γ κ ca s = κ ca.snd s := rfl theorem prodMkRight_apply' (κ : Kernel α β) (ca : α × γ) (s : Set β) : prodMkRight γ κ ca s = κ ca.fst s := rfl @[simp] lemma prodMkLeft_zero : Kernel.prodMkLeft α (0 : Kernel β γ) = 0 := by ext x s _; simp @[simp] lemma prodMkRight_zero : Kernel.prodMkRight α (0 : Kernel β γ) = 0 := by ext x s _; simp @[simp] lemma prodMkLeft_add (κ η : Kernel α β) : prodMkLeft γ (κ + η) = prodMkLeft γ κ + prodMkLeft γ η := by ext; simp @[simp] lemma prodMkRight_add (κ η : Kernel α β) : prodMkRight γ (κ + η) = prodMkRight γ κ + prodMkRight γ η := by ext; simp theorem lintegral_prodMkLeft (κ : Kernel α β) (ca : γ × α) (g : β → ℝ≥0∞) : ∫⁻ b, g b ∂prodMkLeft γ κ ca = ∫⁻ b, g b ∂κ ca.snd := rfl theorem lintegral_prodMkRight (κ : Kernel α β) (ca : α × γ) (g : β → ℝ≥0∞) : ∫⁻ b, g b ∂prodMkRight γ κ ca = ∫⁻ b, g b ∂κ ca.fst := rfl instance IsMarkovKernel.prodMkLeft (κ : Kernel α β) [IsMarkovKernel κ] : IsMarkovKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance instance IsMarkovKernel.prodMkRight (κ : Kernel α β) [IsMarkovKernel κ] : IsMarkovKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance instance IsFiniteKernel.prodMkLeft (κ : Kernel α β) [IsFiniteKernel κ] : IsFiniteKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance instance IsFiniteKernel.prodMkRight (κ : Kernel α β) [IsFiniteKernel κ] : IsFiniteKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance instance IsSFiniteKernel.prodMkLeft (κ : Kernel α β) [IsSFiniteKernel κ] : IsSFiniteKernel (prodMkLeft γ κ) := by rw [Kernel.prodMkLeft]; infer_instance instance IsSFiniteKernel.prodMkRight (κ : Kernel α β) [IsSFiniteKernel κ] : IsSFiniteKernel (prodMkRight γ κ) := by rw [Kernel.prodMkRight]; infer_instance lemma isSFiniteKernel_prodMkLeft_unit {κ : Kernel α β} : IsSFiniteKernel (prodMkLeft Unit κ) ↔ IsSFiniteKernel κ := by refine ⟨fun _ ↦ ?_, fun _ ↦ inferInstance⟩ change IsSFiniteKernel ((prodMkLeft Unit κ).comap (fun a ↦ ((), a)) (by fun_prop)) infer_instance lemma isSFiniteKernel_prodMkRight_unit {κ : Kernel α β} : IsSFiniteKernel (prodMkRight Unit κ) ↔ IsSFiniteKernel κ := by refine ⟨fun _ ↦ ?_, fun _ ↦ inferInstance⟩ change IsSFiniteKernel ((prodMkRight Unit κ).comap (fun a ↦ (a, ())) (by fun_prop)) infer_instance lemma map_prodMkLeft (γ : Type*) [MeasurableSpace γ] (κ : Kernel α β) {f : β → δ} (hf : Measurable f) : map (prodMkLeft γ κ) f hf = prodMkLeft γ (map κ f hf) := rfl lemma map_prodMkRight (κ : Kernel α β) (γ : Type*) [MeasurableSpace γ] {f : β → δ} (hf : Measurable f) : map (prodMkRight γ κ) f hf = prodMkRight γ (map κ f hf) := rfl /-- Define a `Kernel (β × α) γ` from a `Kernel (α × β) γ` by taking the comap of `Prod.swap`. -/ def swapLeft (κ : Kernel (α × β) γ) : Kernel (β × α) γ := comap κ Prod.swap measurable_swap @[simp] theorem swapLeft_apply (κ : Kernel (α × β) γ) (a : β × α) : swapLeft κ a = κ a.swap := rfl theorem swapLeft_apply' (κ : Kernel (α × β) γ) (a : β × α) (s : Set γ) : swapLeft κ a s = κ a.swap s := rfl theorem lintegral_swapLeft (κ : Kernel (α × β) γ) (a : β × α) (g : γ → ℝ≥0∞) : ∫⁻ c, g c ∂swapLeft κ a = ∫⁻ c, g c ∂κ a.swap := by rw [swapLeft_apply] instance IsMarkovKernel.swapLeft (κ : Kernel (α × β) γ) [IsMarkovKernel κ] : IsMarkovKernel (swapLeft κ) := by rw [Kernel.swapLeft]; infer_instance instance IsFiniteKernel.swapLeft (κ : Kernel (α × β) γ) [IsFiniteKernel κ] : IsFiniteKernel (swapLeft κ) := by rw [Kernel.swapLeft]; infer_instance instance IsSFiniteKernel.swapLeft (κ : Kernel (α × β) γ) [IsSFiniteKernel κ] : IsSFiniteKernel (swapLeft κ) := by rw [Kernel.swapLeft]; infer_instance @[simp] lemma swapLeft_prodMkLeft (κ : Kernel α β) (γ : Type*) [MeasurableSpace γ] : swapLeft (prodMkLeft γ κ) = prodMkRight γ κ := rfl @[simp] lemma swapLeft_prodMkRight (κ : Kernel α β) (γ : Type*) [MeasurableSpace γ] : swapLeft (prodMkRight γ κ) = prodMkLeft γ κ := rfl /-- Define a `Kernel α (γ × β)` from a `Kernel α (β × γ)` by taking the map of `Prod.swap`. -/ noncomputable def swapRight (κ : Kernel α (β × γ)) : Kernel α (γ × β) := map κ Prod.swap measurable_swap theorem swapRight_apply (κ : Kernel α (β × γ)) (a : α) : swapRight κ a = (κ a).map Prod.swap := rfl theorem swapRight_apply' (κ : Kernel α (β × γ)) (a : α) {s : Set (γ × β)} (hs : MeasurableSet s) : swapRight κ a s = κ a {p | p.swap ∈ s} := by rw [swapRight_apply, Measure.map_apply measurable_swap hs]; rfl theorem lintegral_swapRight (κ : Kernel α (β × γ)) (a : α) {g : γ × β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂swapRight κ a = ∫⁻ bc : β × γ, g bc.swap ∂κ a := by rw [swapRight, lintegral_map _ measurable_swap a hg] instance IsMarkovKernel.swapRight (κ : Kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (swapRight κ) := by rw [Kernel.swapRight]; infer_instance instance IsFiniteKernel.swapRight (κ : Kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (swapRight κ) := by rw [Kernel.swapRight]; infer_instance instance IsSFiniteKernel.swapRight (κ : Kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (swapRight κ) := by rw [Kernel.swapRight]; infer_instance /-- Define a `Kernel α β` from a `Kernel α (β × γ)` by taking the map of the first projection. -/ noncomputable def fst (κ : Kernel α (β × γ)) : Kernel α β := map κ Prod.fst measurable_fst theorem fst_apply (κ : Kernel α (β × γ)) (a : α) : fst κ a = (κ a).map Prod.fst := rfl theorem fst_apply' (κ : Kernel α (β × γ)) (a : α) {s : Set β} (hs : MeasurableSet s) : fst κ a s = κ a {p | p.1 ∈ s} := by rw [fst_apply, Measure.map_apply measurable_fst hs]; rfl @[simp] lemma fst_zero : fst (0 : Kernel α (β × γ)) = 0 := by simp [fst] theorem lintegral_fst (κ : Kernel α (β × γ)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂fst κ a = ∫⁻ bc : β × γ, g bc.fst ∂κ a := by rw [fst, lintegral_map _ measurable_fst a hg] instance IsMarkovKernel.fst (κ : Kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (fst κ) := by rw [Kernel.fst]; infer_instance instance IsFiniteKernel.fst (κ : Kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (fst κ) := by rw [Kernel.fst]; infer_instance instance IsSFiniteKernel.fst (κ : Kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (fst κ) := by rw [Kernel.fst]; infer_instance instance (priority := 100) isFiniteKernel_of_isFiniteKernel_fst {κ : Kernel α (β × γ)} [h : IsFiniteKernel (fst κ)] : IsFiniteKernel κ := by refine ⟨h.bound, h.bound_lt_top, fun a ↦ le_trans ?_ (measure_le_bound (fst κ) a Set.univ)⟩ rw [fst_apply' _ _ MeasurableSet.univ] simp lemma fst_map_prod (κ : Kernel α β) {f : β → γ} {g : β → δ} (hf : Measurable f) (hg : Measurable g) : fst (map κ (fun x ↦ (f x, g x)) (hf.prod_mk hg)) = map κ f hf := by ext x s hs rw [fst_apply' _ _ hs, map_apply', map_apply' _ _ _ hs] · rfl · exact measurable_fst hs lemma fst_map_id_prod (κ : Kernel α β) {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} (hf : Measurable f) : fst (map κ (fun a ↦ (a, f a)) (measurable_id.prod_mk hf)) = κ := by rw [fst_map_prod _ measurable_id' hf, Kernel.map_id'] @[simp] lemma fst_compProd (κ : Kernel α β) (η : Kernel (α × β) γ) [IsSFiniteKernel κ] [IsMarkovKernel η] : fst (κ ⊗ₖ η) = κ := by ext x s hs rw [fst_apply' _ _ hs, compProd_apply] swap; · exact measurable_fst hs simp only [Set.mem_setOf_eq] classical have : ∀ b : β, η (x, b) {_c | b ∈ s} = s.indicator (fun _ ↦ 1) b := by intro b by_cases hb : b ∈ s <;> simp [hb] simp_rw [this] rw [lintegral_indicator_const hs, one_mul] lemma fst_prodMkLeft (δ : Type*) [MeasurableSpace δ] (κ : Kernel α (β × γ)) : fst (prodMkLeft δ κ) = prodMkLeft δ (fst κ) := rfl lemma fst_prodMkRight (κ : Kernel α (β × γ)) (δ : Type*) [MeasurableSpace δ] : fst (prodMkRight δ κ) = prodMkRight δ (fst κ) := rfl /-- Define a `Kernel α γ` from a `Kernel α (β × γ)` by taking the map of the second projection. -/ noncomputable def snd (κ : Kernel α (β × γ)) : Kernel α γ := map κ Prod.snd measurable_snd theorem snd_apply (κ : Kernel α (β × γ)) (a : α) : snd κ a = (κ a).map Prod.snd := rfl theorem snd_apply' (κ : Kernel α (β × γ)) (a : α) {s : Set γ} (hs : MeasurableSet s) : snd κ a s = κ a {p | p.2 ∈ s} := by rw [snd_apply, Measure.map_apply measurable_snd hs]; rfl @[simp] lemma snd_zero : snd (0 : Kernel α (β × γ)) = 0 := by simp [snd] theorem lintegral_snd (κ : Kernel α (β × γ)) (a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂snd κ a = ∫⁻ bc : β × γ, g bc.snd ∂κ a := by rw [snd, lintegral_map _ measurable_snd a hg] instance IsMarkovKernel.snd (κ : Kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (snd κ) := by rw [Kernel.snd]; infer_instance instance IsFiniteKernel.snd (κ : Kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (snd κ) := by rw [Kernel.snd]; infer_instance instance IsSFiniteKernel.snd (κ : Kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (snd κ) := by rw [Kernel.snd]; infer_instance instance (priority := 100) isFiniteKernel_of_isFiniteKernel_snd {κ : Kernel α (β × γ)} [h : IsFiniteKernel (snd κ)] : IsFiniteKernel κ := by refine ⟨h.bound, h.bound_lt_top, fun a ↦ le_trans ?_ (measure_le_bound (snd κ) a Set.univ)⟩ rw [snd_apply' _ _ MeasurableSet.univ] simp lemma snd_map_prod (κ : Kernel α β) {f : β → γ} {g : β → δ} (hf : Measurable f) (hg : Measurable g) : snd (map κ (fun x ↦ (f x, g x)) (hf.prod_mk hg)) = map κ g hg := by ext x s hs rw [snd_apply' _ _ hs, map_apply', map_apply' _ _ _ hs] · rfl · exact measurable_snd hs lemma snd_map_prod_id (κ : Kernel α β) {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} (hf : Measurable f) : snd (map κ (fun a ↦ (f a, a)) (hf.prod_mk measurable_id)) = κ := by rw [snd_map_prod _ hf measurable_id', Kernel.map_id'] lemma snd_prodMkLeft (δ : Type*) [MeasurableSpace δ] (κ : Kernel α (β × γ)) : snd (prodMkLeft δ κ) = prodMkLeft δ (snd κ) := rfl lemma snd_prodMkRight (κ : Kernel α (β × γ)) (δ : Type*) [MeasurableSpace δ] : snd (prodMkRight δ κ) = prodMkRight δ (snd κ) := rfl @[simp] lemma fst_swapRight (κ : Kernel α (β × γ)) : fst (swapRight κ) = snd κ := by ext a s hs rw [fst_apply' _ _ hs, swapRight_apply', snd_apply' _ _ hs] · rfl · exact measurable_fst hs @[simp] lemma snd_swapRight (κ : Kernel α (β × γ)) : snd (swapRight κ) = fst κ := by ext a s hs rw [snd_apply' _ _ hs, swapRight_apply', fst_apply' _ _ hs] · rfl · exact measurable_snd hs end FstSnd section Comp /-! ### Composition of two kernels -/ variable {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α} /-- Composition of two kernels. -/ noncomputable def comp (η : Kernel β γ) (κ : Kernel α β) : Kernel α γ where toFun a := (κ a).bind η measurable' := (Measure.measurable_bind' η.measurable).comp κ.measurable scoped[ProbabilityTheory] infixl:100 " ∘ₖ " => ProbabilityTheory.Kernel.comp theorem comp_apply (η : Kernel β γ) (κ : Kernel α β) (a : α) : (η ∘ₖ κ) a = (κ a).bind η := rfl theorem comp_apply' (η : Kernel β γ) (κ : Kernel α β) (a : α) {s : Set γ} (hs : MeasurableSet s) : (η ∘ₖ κ) a s = ∫⁻ b, η b s ∂κ a := by rw [comp_apply, Measure.bind_apply hs (Kernel.measurable _)] theorem comp_eq_snd_compProd (η : Kernel β γ) [IsSFiniteKernel η] (κ : Kernel α β) [IsSFiniteKernel κ] : η ∘ₖ κ = snd (κ ⊗ₖ prodMkLeft α η) := by ext a s hs rw [comp_apply' _ _ _ hs, snd_apply' _ _ hs, compProd_apply] swap · exact measurable_snd hs simp only [Set.mem_setOf_eq, Set.setOf_mem_eq, prodMkLeft_apply' _ _ s] theorem lintegral_comp (η : Kernel β γ) (κ : Kernel α β) (a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂(η ∘ₖ κ) a = ∫⁻ b, ∫⁻ c, g c ∂η b ∂κ a := by rw [comp_apply, Measure.lintegral_bind (Kernel.measurable _) hg] instance IsMarkovKernel.comp (η : Kernel β γ) [IsMarkovKernel η] (κ : Kernel α β) [IsMarkovKernel κ] : IsMarkovKernel (η ∘ₖ κ) := by rw [comp_eq_snd_compProd]; infer_instance instance IsFiniteKernel.comp (η : Kernel β γ) [IsFiniteKernel η] (κ : Kernel α β) [IsFiniteKernel κ] : IsFiniteKernel (η ∘ₖ κ) := by rw [comp_eq_snd_compProd]; infer_instance instance IsSFiniteKernel.comp (η : Kernel β γ) [IsSFiniteKernel η] (κ : Kernel α β) [IsSFiniteKernel κ] : IsSFiniteKernel (η ∘ₖ κ) := by rw [comp_eq_snd_compProd]; infer_instance /-- Composition of kernels is associative. -/ theorem comp_assoc {δ : Type*} {mδ : MeasurableSpace δ} (ξ : Kernel γ δ) [IsSFiniteKernel ξ] (η : Kernel β γ) (κ : Kernel α β) : ξ ∘ₖ η ∘ₖ κ = ξ ∘ₖ (η ∘ₖ κ) := by refine ext_fun fun a f hf => ?_ simp_rw [lintegral_comp _ _ _ hf, lintegral_comp _ _ _ hf.lintegral_kernel] theorem deterministic_comp_eq_map (hf : Measurable f) (κ : Kernel α β) : deterministic f hf ∘ₖ κ = map κ f hf := by ext a s hs simp_rw [map_apply' _ _ _ hs, comp_apply' _ _ _ hs, deterministic_apply' hf _ hs, lintegral_indicator_const_comp hf hs, one_mul] theorem comp_deterministic_eq_comap (κ : Kernel α β) (hg : Measurable g) : κ ∘ₖ deterministic g hg = comap κ g hg := by ext a s hs simp_rw [comap_apply' _ _ _ s, comp_apply' _ _ _ hs, deterministic_apply hg a, lintegral_dirac' _ (Kernel.measurable_coe κ hs)] lemma const_comp (μ : Measure γ) (κ : Kernel α β) : const β μ ∘ₖ κ = fun a ↦ (κ a) Set.univ • μ := by ext _ _ hs simp_rw [comp_apply' _ _ _ hs, const_apply, MeasureTheory.lintegral_const, Measure.smul_apply, smul_eq_mul, mul_comm] @[simp] lemma const_comp' (μ : Measure γ) (κ : Kernel α β) [IsMarkovKernel κ] : const β μ ∘ₖ κ = const α μ := by ext; simp_rw [const_comp, measure_univ, one_smul, const_apply] end Comp section Prod /-! ### Product of two kernels -/ variable {γ : Type*} {mγ : MeasurableSpace γ} /-- Product of two kernels. This is meaningful only when the kernels are s-finite. -/ noncomputable def prod (κ : Kernel α β) (η : Kernel α γ) : Kernel α (β × γ) := κ ⊗ₖ swapLeft (prodMkLeft β η) scoped[ProbabilityTheory] infixl:100 " ×ₖ " => ProbabilityTheory.Kernel.prod theorem prod_apply' (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η] (a : α) {s : Set (β × γ)} (hs : MeasurableSet s) : (κ ×ₖ η) a s = ∫⁻ b : β, (η a) {c : γ | (b, c) ∈ s} ∂κ a := by simp_rw [prod, compProd_apply _ _ _ hs, swapLeft_apply _ _, prodMkLeft_apply, Prod.swap_prod_mk] lemma prod_apply (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η] (a : α) : (κ ×ₖ η) a = (κ a).prod (η a) := by ext s hs rw [prod_apply' _ _ _ hs, Measure.prod_apply hs] rfl lemma prod_const (μ : Measure β) [SFinite μ] (ν : Measure γ) [SFinite ν] : const α μ ×ₖ const α ν = const α (μ.prod ν) := by ext x rw [const_apply, prod_apply, const_apply, const_apply] theorem lintegral_prod (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsSFiniteKernel η] (a : α) {g : β × γ → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂(κ ×ₖ η) a = ∫⁻ b, ∫⁻ c, g (b, c) ∂η a ∂κ a := by simp_rw [prod, lintegral_compProd _ _ _ hg, swapLeft_apply, prodMkLeft_apply, Prod.swap_prod_mk] instance IsMarkovKernel.prod (κ : Kernel α β) [IsMarkovKernel κ] (η : Kernel α γ) [IsMarkovKernel η] : IsMarkovKernel (κ ×ₖ η) := by rw [Kernel.prod]; infer_instance instance IsFiniteKernel.prod (κ : Kernel α β) [IsFiniteKernel κ] (η : Kernel α γ) [IsFiniteKernel η] : IsFiniteKernel (κ ×ₖ η) := by rw [Kernel.prod]; infer_instance instance IsSFiniteKernel.prod (κ : Kernel α β) (η : Kernel α γ) : IsSFiniteKernel (κ ×ₖ η) := by rw [Kernel.prod]; infer_instance @[simp] lemma fst_prod (κ : Kernel α β) [IsSFiniteKernel κ] (η : Kernel α γ) [IsMarkovKernel η] : fst (κ ×ₖ η) = κ := by rw [prod]; simp @[simp] lemma snd_prod (κ : Kernel α β) [IsMarkovKernel κ] (η : Kernel α γ) [IsSFiniteKernel η] : snd (κ ×ₖ η) = η := by ext x; simp [snd_apply, prod_apply] end Prod end Kernel end ProbabilityTheory
Probability\Kernel\CondDistrib.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.Probability.Kernel.Disintegration.Unique import Mathlib.Probability.Notation /-! # Regular conditional probability distribution We define the regular conditional probability distribution of `Y : α → Ω` given `X : α → β`, where `Ω` is a standard Borel space. This is a `Kernel β Ω` such that for almost all `a`, `condDistrib` evaluated at `X a` and a measurable set `s` is equal to the conditional expectation `μ⟦Y ⁻¹' s | mβ.comap X⟧` evaluated at `a`. `μ⟦Y ⁻¹' s | mβ.comap X⟧` maps a measurable set `s` to a function `α → ℝ≥0∞`, and for all `s` that map is unique up to a `μ`-null set. For all `a`, the map from sets to `ℝ≥0∞` that we obtain that way verifies some of the properties of a measure, but in general the fact that the `μ`-null set depends on `s` can prevent us from finding versions of the conditional expectation that combine into a true measure. The standard Borel space assumption on `Ω` allows us to do so. The case `Y = X = id` is developed in more detail in `Probability/Kernel/Condexp.lean`: here `X` is understood as a map from `Ω` with a sub-σ-algebra `m` to `Ω` with its default σ-algebra and the conditional distribution defines a kernel associated with the conditional expectation with respect to `m`. ## Main definitions * `condDistrib Y X μ`: regular conditional probability distribution of `Y : α → Ω` given `X : α → β`, where `Ω` is a standard Borel space. ## Main statements * `condDistrib_ae_eq_condexp`: for almost all `a`, `condDistrib` evaluated at `X a` and a measurable set `s` is equal to the conditional expectation `μ⟦Y ⁻¹' s | mβ.comap X⟧ a`. * `condexp_prod_ae_eq_integral_condDistrib`: the conditional expectation `μ[(fun a => f (X a, Y a)) | X; mβ]` is almost everywhere equal to the integral `∫ y, f (X a, y) ∂(condDistrib Y X μ (X a))`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped ENNReal MeasureTheory ProbabilityTheory namespace ProbabilityTheory variable {α β Ω F : Type*} [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] [NormedAddCommGroup F] {mα : MeasurableSpace α} {μ : Measure α} [IsFiniteMeasure μ] {X : α → β} {Y : α → Ω} /-- **Regular conditional probability distribution**: kernel associated with the conditional expectation of `Y` given `X`. For almost all `a`, `condDistrib Y X μ` evaluated at `X a` and a measurable set `s` is equal to the conditional expectation `μ⟦Y ⁻¹' s | mβ.comap X⟧ a`. It also satisfies the equality `μ[(fun a => f (X a, Y a)) | mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a, y) ∂(condDistrib Y X μ (X a))` for all integrable functions `f`. -/ noncomputable irreducible_def condDistrib {_ : MeasurableSpace α} [MeasurableSpace β] (Y : α → Ω) (X : α → β) (μ : Measure α) [IsFiniteMeasure μ] : Kernel β Ω := (μ.map fun a => (X a, Y a)).condKernel instance [MeasurableSpace β] : IsMarkovKernel (condDistrib Y X μ) := by rw [condDistrib]; infer_instance variable {mβ : MeasurableSpace β} {s : Set Ω} {t : Set β} {f : β × Ω → F} /-- If the singleton `{x}` has non-zero mass for `μ.map X`, then for all `s : Set Ω`, `condDistrib Y X μ x s = (μ.map X {x})⁻¹ * μ.map (fun a => (X a, Y a)) ({x} ×ˢ s)` . -/ lemma condDistrib_apply_of_ne_zero [MeasurableSingletonClass β] (hY : Measurable Y) (x : β) (hX : μ.map X {x} ≠ 0) (s : Set Ω) : condDistrib Y X μ x s = (μ.map X {x})⁻¹ * μ.map (fun a => (X a, Y a)) ({x} ×ˢ s) := by rw [condDistrib, Measure.condKernel_apply_of_ne_zero _ s] · rw [Measure.fst_map_prod_mk hY] · rwa [Measure.fst_map_prod_mk hY] section Measurability theorem measurable_condDistrib (hs : MeasurableSet s) : Measurable[mβ.comap X] fun a => condDistrib Y X μ (X a) s := (Kernel.measurable_coe _ hs).comp (Measurable.of_comap_le le_rfl) theorem _root_.MeasureTheory.AEStronglyMeasurable.ae_integrable_condDistrib_map_iff (hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) : (∀ᵐ a ∂μ.map X, Integrable (fun ω => f (a, ω)) (condDistrib Y X μ a)) ∧ Integrable (fun a => ∫ ω, ‖f (a, ω)‖ ∂condDistrib Y X μ a) (μ.map X) ↔ Integrable f (μ.map fun a => (X a, Y a)) := by rw [condDistrib, ← hf.ae_integrable_condKernel_iff, Measure.fst_map_prod_mk₀ hY] variable [NormedSpace ℝ F] [CompleteSpace F] theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condDistrib_map (hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) : AEStronglyMeasurable (fun x => ∫ y, f (x, y) ∂condDistrib Y X μ x) (μ.map X) := by rw [← Measure.fst_map_prod_mk₀ hY, condDistrib]; exact hf.integral_condKernel theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condDistrib (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) : AEStronglyMeasurable (fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) μ := (hf.integral_condDistrib_map hY).comp_aemeasurable hX theorem aestronglyMeasurable'_integral_condDistrib (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) : AEStronglyMeasurable' (mβ.comap X) (fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) μ := (hf.integral_condDistrib_map hY).comp_ae_measurable' hX end Measurability /-- `condDistrib` is a.e. uniquely defined as the kernel satisfying the defining property of `condKernel`. -/ theorem condDistrib_ae_eq_of_measure_eq_compProd (hX : Measurable X) (hY : Measurable Y) (κ : Kernel β Ω) [IsFiniteKernel κ] (hκ : μ.map (fun x => (X x, Y x)) = μ.map X ⊗ₘ κ) : ∀ᵐ x ∂μ.map X, κ x = condDistrib Y X μ x := by have heq : μ.map X = (μ.map (fun x ↦ (X x, Y x))).fst := by ext s hs rw [Measure.map_apply hX hs, Measure.fst_apply hs, Measure.map_apply] exacts [rfl, Measurable.prod hX hY, measurable_fst hs] rw [heq, condDistrib] refine eq_condKernel_of_measure_eq_compProd _ ?_ convert hκ exact heq.symm section Integrability theorem integrable_toReal_condDistrib (hX : AEMeasurable X μ) (hs : MeasurableSet s) : Integrable (fun a => (condDistrib Y X μ (X a) s).toReal) μ := by refine integrable_toReal_of_lintegral_ne_top ?_ ?_ · exact Measurable.comp_aemeasurable (Kernel.measurable_coe _ hs) hX · refine ne_of_lt ?_ calc ∫⁻ a, condDistrib Y X μ (X a) s ∂μ ≤ ∫⁻ _, 1 ∂μ := lintegral_mono fun a => prob_le_one _ = μ univ := lintegral_one _ < ∞ := measure_lt_top _ _ theorem _root_.MeasureTheory.Integrable.condDistrib_ae_map (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : ∀ᵐ b ∂μ.map X, Integrable (fun ω => f (b, ω)) (condDistrib Y X μ b) := by rw [condDistrib, ← Measure.fst_map_prod_mk₀ (X := X) hY]; exact hf_int.condKernel_ae theorem _root_.MeasureTheory.Integrable.condDistrib_ae (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : ∀ᵐ a ∂μ, Integrable (fun ω => f (X a, ω)) (condDistrib Y X μ (X a)) := ae_of_ae_map hX (hf_int.condDistrib_ae_map hY) theorem _root_.MeasureTheory.Integrable.integral_norm_condDistrib_map (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂condDistrib Y X μ x) (μ.map X) := by rw [condDistrib, ← Measure.fst_map_prod_mk₀ (X := X) hY]; exact hf_int.integral_norm_condKernel theorem _root_.MeasureTheory.Integrable.integral_norm_condDistrib (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : Integrable (fun a => ∫ y, ‖f (X a, y)‖ ∂condDistrib Y X μ (X a)) μ := (hf_int.integral_norm_condDistrib_map hY).comp_aemeasurable hX variable [NormedSpace ℝ F] [CompleteSpace F] theorem _root_.MeasureTheory.Integrable.norm_integral_condDistrib_map (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : Integrable (fun x => ‖∫ y, f (x, y) ∂condDistrib Y X μ x‖) (μ.map X) := by rw [condDistrib, ← Measure.fst_map_prod_mk₀ (X := X) hY]; exact hf_int.norm_integral_condKernel theorem _root_.MeasureTheory.Integrable.norm_integral_condDistrib (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : Integrable (fun a => ‖∫ y, f (X a, y) ∂condDistrib Y X μ (X a)‖) μ := (hf_int.norm_integral_condDistrib_map hY).comp_aemeasurable hX theorem _root_.MeasureTheory.Integrable.integral_condDistrib_map (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : Integrable (fun x => ∫ y, f (x, y) ∂condDistrib Y X μ x) (μ.map X) := (integrable_norm_iff (hf_int.1.integral_condDistrib_map hY)).mp (hf_int.norm_integral_condDistrib_map hY) theorem _root_.MeasureTheory.Integrable.integral_condDistrib (hX : AEMeasurable X μ) (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : Integrable (fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a)) μ := (hf_int.integral_condDistrib_map hY).comp_aemeasurable hX end Integrability theorem setLIntegral_preimage_condDistrib (hX : Measurable X) (hY : AEMeasurable Y μ) (hs : MeasurableSet s) (ht : MeasurableSet t) : ∫⁻ a in X ⁻¹' t, condDistrib Y X μ (X a) s ∂μ = μ (X ⁻¹' t ∩ Y ⁻¹' s) := by -- Porting note: need to massage the LHS integrand into the form accepted by `lintegral_comp` -- (`rw` does not see that the two forms are defeq) conv_lhs => arg 2; change (fun a => ((condDistrib Y X μ) a) s) ∘ X rw [lintegral_comp (Kernel.measurable_coe _ hs) hX, condDistrib, ← Measure.restrict_map hX ht, ← Measure.fst_map_prod_mk₀ hY, Measure.setLIntegral_condKernel_eq_measure_prod ht hs, Measure.map_apply_of_aemeasurable (hX.aemeasurable.prod_mk hY) (ht.prod hs), mk_preimage_prod] @[deprecated (since := "2024-06-29")] alias set_lintegral_preimage_condDistrib := setLIntegral_preimage_condDistrib theorem setLIntegral_condDistrib_of_measurableSet (hX : Measurable X) (hY : AEMeasurable Y μ) (hs : MeasurableSet s) {t : Set α} (ht : MeasurableSet[mβ.comap X] t) : ∫⁻ a in t, condDistrib Y X μ (X a) s ∂μ = μ (t ∩ Y ⁻¹' s) := by obtain ⟨t', ht', rfl⟩ := ht rw [setLIntegral_preimage_condDistrib hX hY hs ht'] @[deprecated (since := "2024-06-29")] alias set_lintegral_condDistrib_of_measurableSet := setLIntegral_condDistrib_of_measurableSet /-- For almost every `a : α`, the `condDistrib Y X μ` kernel applied to `X a` and a measurable set `s` is equal to the conditional expectation of the indicator of `Y ⁻¹' s`. -/ theorem condDistrib_ae_eq_condexp (hX : Measurable X) (hY : Measurable Y) (hs : MeasurableSet s) : (fun a => (condDistrib Y X μ (X a) s).toReal) =ᵐ[μ] μ⟦Y ⁻¹' s|mβ.comap X⟧ := by refine ae_eq_condexp_of_forall_setIntegral_eq hX.comap_le ?_ ?_ ?_ ?_ · exact (integrable_const _).indicator (hY hs) · exact fun t _ _ => (integrable_toReal_condDistrib hX.aemeasurable hs).integrableOn · intro t ht _ rw [integral_toReal ((measurable_condDistrib hs).mono hX.comap_le le_rfl).aemeasurable (eventually_of_forall fun ω => measure_lt_top (condDistrib Y X μ (X ω)) _), integral_indicator_const _ (hY hs), Measure.restrict_apply (hY hs), smul_eq_mul, mul_one, inter_comm, setLIntegral_condDistrib_of_measurableSet hX hY.aemeasurable hs ht] · refine (Measurable.stronglyMeasurable ?_).aeStronglyMeasurable' exact @Measurable.ennreal_toReal _ (mβ.comap X) _ (measurable_condDistrib hs) /-- The conditional expectation of a function `f` of the product `(X, Y)` is almost everywhere equal to the integral of `y ↦ f(X, y)` against the `condDistrib` kernel. -/ theorem condexp_prod_ae_eq_integral_condDistrib' [NormedSpace ℝ F] [CompleteSpace F] (hX : Measurable X) (hY : AEMeasurable Y μ) (hf_int : Integrable f (μ.map fun a => (X a, Y a))) : μ[fun a => f (X a, Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a,y) ∂condDistrib Y X μ (X a) := by have hf_int' : Integrable (fun a => f (X a, Y a)) μ := (integrable_map_measure hf_int.1 (hX.aemeasurable.prod_mk hY)).mp hf_int refine (ae_eq_condexp_of_forall_setIntegral_eq hX.comap_le hf_int' (fun s _ _ => ?_) ?_ ?_).symm · exact (hf_int.integral_condDistrib hX.aemeasurable hY).integrableOn · rintro s ⟨t, ht, rfl⟩ _ change ∫ a in X ⁻¹' t, ((fun x' => ∫ y, f (x', y) ∂(condDistrib Y X μ) x') ∘ X) a ∂μ = ∫ a in X ⁻¹' t, f (X a, Y a) ∂μ simp only [Function.comp_apply] rw [← integral_map hX.aemeasurable (f := fun x' => ∫ y, f (x', y) ∂(condDistrib Y X μ) x')] swap · rw [← Measure.restrict_map hX ht] exact (hf_int.1.integral_condDistrib_map hY).restrict rw [← Measure.restrict_map hX ht, ← Measure.fst_map_prod_mk₀ hY, condDistrib, Measure.setIntegral_condKernel_univ_right ht hf_int.integrableOn, setIntegral_map (ht.prod MeasurableSet.univ) hf_int.1 (hX.aemeasurable.prod_mk hY), mk_preimage_prod, preimage_univ, inter_univ] · exact aestronglyMeasurable'_integral_condDistrib hX.aemeasurable hY hf_int.1 /-- The conditional expectation of a function `f` of the product `(X, Y)` is almost everywhere equal to the integral of `y ↦ f(X, y)` against the `condDistrib` kernel. -/ theorem condexp_prod_ae_eq_integral_condDistrib₀ [NormedSpace ℝ F] [CompleteSpace F] (hX : Measurable X) (hY : AEMeasurable Y μ) (hf : AEStronglyMeasurable f (μ.map fun a => (X a, Y a))) (hf_int : Integrable (fun a => f (X a, Y a)) μ) : μ[fun a => f (X a, Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a) := haveI hf_int' : Integrable f (μ.map fun a => (X a, Y a)) := by rwa [integrable_map_measure hf (hX.aemeasurable.prod_mk hY)] condexp_prod_ae_eq_integral_condDistrib' hX hY hf_int' /-- The conditional expectation of a function `f` of the product `(X, Y)` is almost everywhere equal to the integral of `y ↦ f(X, y)` against the `condDistrib` kernel. -/ theorem condexp_prod_ae_eq_integral_condDistrib [NormedSpace ℝ F] [CompleteSpace F] (hX : Measurable X) (hY : AEMeasurable Y μ) (hf : StronglyMeasurable f) (hf_int : Integrable (fun a => f (X a, Y a)) μ) : μ[fun a => f (X a, Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f (X a, y) ∂condDistrib Y X μ (X a) := haveI hf_int' : Integrable f (μ.map fun a => (X a, Y a)) := by rwa [integrable_map_measure hf.aestronglyMeasurable (hX.aemeasurable.prod_mk hY)] condexp_prod_ae_eq_integral_condDistrib' hX hY hf_int' theorem condexp_ae_eq_integral_condDistrib [NormedSpace ℝ F] [CompleteSpace F] (hX : Measurable X) (hY : AEMeasurable Y μ) {f : Ω → F} (hf : StronglyMeasurable f) (hf_int : Integrable (fun a => f (Y a)) μ) : μ[fun a => f (Y a)|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f y ∂condDistrib Y X μ (X a) := condexp_prod_ae_eq_integral_condDistrib hX hY (hf.comp_measurable measurable_snd) hf_int /-- The conditional expectation of `Y` given `X` is almost everywhere equal to the integral `∫ y, y ∂(condDistrib Y X μ (X a))`. -/ theorem condexp_ae_eq_integral_condDistrib' {Ω} [NormedAddCommGroup Ω] [NormedSpace ℝ Ω] [CompleteSpace Ω] [MeasurableSpace Ω] [BorelSpace Ω] [SecondCountableTopology Ω] {Y : α → Ω} (hX : Measurable X) (hY_int : Integrable Y μ) : μ[Y|mβ.comap X] =ᵐ[μ] fun a => ∫ y, y ∂condDistrib Y X μ (X a) := condexp_ae_eq_integral_condDistrib hX hY_int.1.aemeasurable stronglyMeasurable_id hY_int open MeasureTheory theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_mk {Ω F} {mΩ : MeasurableSpace Ω} (X : Ω → β) {μ : Measure Ω} [TopologicalSpace F] {f : Ω → F} (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) := by refine ⟨fun x => hf.mk f x.2, hf.stronglyMeasurable_mk.comp_measurable measurable_snd, ?_⟩ suffices h : Measure.QuasiMeasurePreserving Prod.snd (μ.map fun ω ↦ (X ω, ω)) μ from Measure.QuasiMeasurePreserving.ae_eq h hf.ae_eq_mk refine ⟨measurable_snd, Measure.AbsolutelyContinuous.mk fun s hs hμs => ?_⟩ rw [Measure.map_apply _ hs] swap; · exact measurable_snd by_cases hX : AEMeasurable X μ · rw [Measure.map_apply_of_aemeasurable] · rw [← univ_prod, mk_preimage_prod, preimage_univ, univ_inter, preimage_id'] exact hμs · exact hX.prod_mk aemeasurable_id · exact measurable_snd hs · rw [Measure.map_of_not_aemeasurable] · simp · contrapose! hX; exact measurable_fst.comp_aemeasurable hX theorem _root_.MeasureTheory.Integrable.comp_snd_map_prod_mk {Ω} {mΩ : MeasurableSpace Ω} (X : Ω → β) {μ : Measure Ω} {f : Ω → F} (hf_int : Integrable f μ) : Integrable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) := by by_cases hX : AEMeasurable X μ · have hf := hf_int.1.comp_snd_map_prod_mk X (mΩ := mΩ) (mβ := mβ) refine ⟨hf, ?_⟩ rw [HasFiniteIntegral, lintegral_map' hf.ennnorm (hX.prod_mk aemeasurable_id)] exact hf_int.2 · rw [Measure.map_of_not_aemeasurable] · simp · contrapose! hX; exact measurable_fst.comp_aemeasurable hX theorem aestronglyMeasurable_comp_snd_map_prod_mk_iff {Ω F} {_ : MeasurableSpace Ω} [TopologicalSpace F] {X : Ω → β} {μ : Measure Ω} (hX : Measurable X) {f : Ω → F} : AEStronglyMeasurable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) ↔ AEStronglyMeasurable f μ := ⟨fun h => h.comp_measurable (hX.prod_mk measurable_id), fun h => h.comp_snd_map_prod_mk X⟩ theorem integrable_comp_snd_map_prod_mk_iff {Ω} {_ : MeasurableSpace Ω} {X : Ω → β} {μ : Measure Ω} (hX : Measurable X) {f : Ω → F} : Integrable (fun x : β × Ω => f x.2) (μ.map fun ω => (X ω, ω)) ↔ Integrable f μ := ⟨fun h => h.comp_measurable (hX.prod_mk measurable_id), fun h => h.comp_snd_map_prod_mk X⟩ theorem condexp_ae_eq_integral_condDistrib_id [NormedSpace ℝ F] [CompleteSpace F] {X : Ω → β} {μ : Measure Ω} [IsFiniteMeasure μ] (hX : Measurable X) {f : Ω → F} (hf_int : Integrable f μ) : μ[f|mβ.comap X] =ᵐ[μ] fun a => ∫ y, f y ∂condDistrib id X μ (X a) := condexp_prod_ae_eq_integral_condDistrib' hX aemeasurable_id (hf_int.comp_snd_map_prod_mk X) end ProbabilityTheory
Probability\Kernel\Condexp.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.Probability.Kernel.CondDistrib /-! # Kernel associated with a conditional expectation We define `condexpKernel μ m`, a kernel from `Ω` to `Ω` such that for all integrable functions `f`, `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. This kernel is defined if `Ω` is a standard Borel space. In general, `μ⟦s | m⟧` maps a measurable set `s` to a function `Ω → ℝ≥0∞`, and for all `s` that map is unique up to a `μ`-null set. For all `a`, the map from sets to `ℝ≥0∞` that we obtain that way verifies some of the properties of a measure, but the fact that the `μ`-null set depends on `s` can prevent us from finding versions of the conditional expectation that combine into a true measure. The standard Borel space assumption on `Ω` allows us to do so. ## Main definitions * `condexpKernel μ m`: kernel such that `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. ## Main statements * `condexp_ae_eq_integral_condexpKernel`: `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped ENNReal MeasureTheory ProbabilityTheory namespace ProbabilityTheory section AuxLemmas variable {Ω F : Type*} {m mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → F} theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id [TopologicalSpace F] (hm : m ≤ mΩ) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) (m.prod mΩ) mΩ (fun ω => (id ω, id ω)) μ) := by rw [← aestronglyMeasurable_comp_snd_map_prod_mk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf theorem _root_.MeasureTheory.Integrable.comp_snd_map_prod_id [NormedAddCommGroup F] (hm : m ≤ mΩ) (hf : Integrable f μ) : Integrable (fun x : Ω × Ω => f x.2) (@Measure.map Ω (Ω × Ω) (m.prod mΩ) mΩ (fun ω => (id ω, id ω)) μ) := by rw [← integrable_comp_snd_map_prod_mk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊢ exact hf end AuxLemmas variable {Ω F : Type*} {m : MeasurableSpace Ω} [mΩ : MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] {μ : Measure Ω} [IsFiniteMeasure μ] /-- Kernel associated with the conditional expectation with respect to a σ-algebra. It satisfies `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condexpKernel μ m ω)`. It is defined as the conditional distribution of the identity given the identity, where the second identity is understood as a map from `Ω` with the σ-algebra `mΩ` to `Ω` with σ-algebra `m ⊓ mΩ`. We use `m ⊓ mΩ` instead of `m` to ensure that it is a sub-σ-algebra of `mΩ`. We then use `Kernel.comap` to get a kernel from `m` to `mΩ` instead of from `m ⊓ mΩ` to `mΩ`. -/ noncomputable irreducible_def condexpKernel (μ : Measure Ω) [IsFiniteMeasure μ] (m : MeasurableSpace Ω) : @Kernel Ω Ω m mΩ := Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id (measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m)) lemma condexpKernel_apply_eq_condDistrib {ω : Ω} : condexpKernel μ m ω = @condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _ (id ω) := by simp_rw [condexpKernel, Kernel.comap_apply] instance : IsMarkovKernel (condexpKernel μ m) := by simp only [condexpKernel]; infer_instance section Measurability variable [NormedAddCommGroup F] {f : Ω → F} theorem measurable_condexpKernel {s : Set Ω} (hs : MeasurableSet s) : Measurable[m] fun ω => condexpKernel μ m ω s := by simp_rw [condexpKernel_apply_eq_condDistrib] refine Measurable.mono ?_ (inf_le_left : m ⊓ mΩ ≤ m) le_rfl convert measurable_condDistrib (μ := μ) hs rw [MeasurableSpace.comap_id] theorem stronglyMeasurable_condexpKernel {s : Set Ω} (hs : MeasurableSet s) : StronglyMeasurable[m] fun ω => condexpKernel μ m ω s := Measurable.stronglyMeasurable (measurable_condexpKernel hs) theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condexpKernel [NormedSpace ℝ F] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun ω => ∫ y, f y ∂condexpKernel μ m ω) μ := by simp_rw [condexpKernel_apply_eq_condDistrib] exact AEStronglyMeasurable.integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf.comp_snd_map_prod_id inf_le_right) theorem aestronglyMeasurable'_integral_condexpKernel [NormedSpace ℝ F] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable' m (fun ω => ∫ y, f y ∂condexpKernel μ m ω) μ := by rw [condexpKernel] have h := aestronglyMeasurable'_integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) rw [MeasurableSpace.comap_id] at h exact AEStronglyMeasurable'.mono h inf_le_left end Measurability section Integrability variable [NormedAddCommGroup F] {f : Ω → F} theorem _root_.MeasureTheory.Integrable.condexpKernel_ae (hf_int : Integrable f μ) : ∀ᵐ ω ∂μ, Integrable f (condexpKernel μ m ω) := by rw [condexpKernel] convert Integrable.condDistrib_ae (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 theorem _root_.MeasureTheory.Integrable.integral_norm_condexpKernel (hf_int : Integrable f μ) : Integrable (fun ω => ∫ y, ‖f y‖ ∂condexpKernel μ m ω) μ := by rw [condexpKernel] convert Integrable.integral_norm_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 theorem _root_.MeasureTheory.Integrable.norm_integral_condexpKernel [NormedSpace ℝ F] (hf_int : Integrable f μ) : Integrable (fun ω => ‖∫ y, f y ∂condexpKernel μ m ω‖) μ := by rw [condexpKernel] convert Integrable.norm_integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 theorem _root_.MeasureTheory.Integrable.integral_condexpKernel [NormedSpace ℝ F] (hf_int : Integrable f μ) : Integrable (fun ω => ∫ y, f y ∂condexpKernel μ m ω) μ := by rw [condexpKernel] convert Integrable.integral_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) aemeasurable_id (hf_int.comp_snd_map_prod_id (inf_le_right : m ⊓ mΩ ≤ mΩ)) using 1 theorem integrable_toReal_condexpKernel {s : Set Ω} (hs : MeasurableSet s) : Integrable (fun ω => (condexpKernel μ m ω s).toReal) μ := by rw [condexpKernel] exact integrable_toReal_condDistrib (aemeasurable_id'' μ (inf_le_right : m ⊓ mΩ ≤ mΩ)) hs end Integrability lemma condexpKernel_ae_eq_condexp' [IsFiniteMeasure μ] {s : Set Ω} (hs : MeasurableSet s) : (fun ω ↦ (condexpKernel μ m ω s).toReal) =ᵐ[μ] μ⟦s | m ⊓ mΩ⟧ := by have h := condDistrib_ae_eq_condexp (μ := μ) (measurable_id'' (inf_le_right : m ⊓ mΩ ≤ mΩ)) measurable_id hs simp only [id_eq, MeasurableSpace.comap_id, preimage_id_eq] at h simp_rw [condexpKernel_apply_eq_condDistrib] exact h lemma condexpKernel_ae_eq_condexp [IsFiniteMeasure μ] (hm : m ≤ mΩ) {s : Set Ω} (hs : MeasurableSet s) : (fun ω ↦ (condexpKernel μ m ω s).toReal) =ᵐ[μ] μ⟦s | m⟧ := (condexpKernel_ae_eq_condexp' hs).trans (by rw [inf_of_le_left hm]) lemma condexpKernel_ae_eq_trim_condexp [IsFiniteMeasure μ] (hm : m ≤ mΩ) {s : Set Ω} (hs : MeasurableSet s) : (fun ω ↦ (condexpKernel μ m ω s).toReal) =ᵐ[μ.trim hm] μ⟦s | m⟧ := by rw [ae_eq_trim_iff hm _ stronglyMeasurable_condexp] · exact condexpKernel_ae_eq_condexp hm hs · refine Measurable.stronglyMeasurable ?_ exact @Measurable.ennreal_toReal _ m _ (measurable_condexpKernel hs) theorem condexp_ae_eq_integral_condexpKernel' [NormedAddCommGroup F] {f : Ω → F} [NormedSpace ℝ F] [CompleteSpace F] (hf_int : Integrable f μ) : μ[f|m ⊓ mΩ] =ᵐ[μ] fun ω => ∫ y, f y ∂condexpKernel μ m ω := by have hX : @Measurable Ω Ω mΩ (m ⊓ mΩ) id := measurable_id.mono le_rfl (inf_le_right : m ⊓ mΩ ≤ mΩ) simp_rw [condexpKernel_apply_eq_condDistrib] have h := condexp_ae_eq_integral_condDistrib_id hX hf_int simpa only [MeasurableSpace.comap_id, id_eq] using h /-- The conditional expectation of `f` with respect to a σ-algebra `m` is almost everywhere equal to the integral `∫ y, f y ∂(condexpKernel μ m ω)`. -/ theorem condexp_ae_eq_integral_condexpKernel [NormedAddCommGroup F] {f : Ω → F} [NormedSpace ℝ F] [CompleteSpace F] (hm : m ≤ mΩ) (hf_int : Integrable f μ) : μ[f|m] =ᵐ[μ] fun ω => ∫ y, f y ∂condexpKernel μ m ω := ((condexp_ae_eq_integral_condexpKernel' hf_int).symm.trans (by rw [inf_of_le_left hm])).symm end ProbabilityTheory
Probability\Kernel\IntegralCompProd.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.Probability.Kernel.Composition import Mathlib.MeasureTheory.Integral.SetIntegral /-! # Bochner integral of a function against the composition-product of two kernels We prove properties of the composition-product of two kernels. If `κ` is an s-finite kernel from `α` to `β` and `η` is an s-finite kernel from `α × β` to `γ`, we can form their composition-product `κ ⊗ₖ η : Kernel α (β × γ)`. We proved in `ProbabilityTheory.Kernel.lintegral_compProd` that it verifies `∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`. In this file, we prove the same equality for the Bochner integral. ## Main statements * `ProbabilityTheory.integral_compProd`: the integral against the composition-product is `∫ z, f z ∂((κ ⊗ₖ η) a) = ∫ x, ∫ y, f (x, y) ∂(η (a, x)) ∂(κ a)` ## Implementation details This file is to a large extent a copy of part of `Mathlib/MeasureTheory/Constructions/Prod/Basic.lean`. The product of two measures is a particular case of composition-product of kernels and it turns out that once the measurablity of the Lebesgue integral of a kernel is proved, almost all proofs about integrals against products of measures extend with minimal modifications to the composition-product of two kernels. -/ noncomputable section open Set Function Real ENNReal MeasureTheory Filter ProbabilityTheory ProbabilityTheory.Kernel open scoped Topology ENNReal MeasureTheory variable {α β γ E : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} [NormedAddCommGroup E] {κ : Kernel α β} [IsSFiniteKernel κ] {η : Kernel (α × β) γ} [IsSFiniteKernel η] {a : α} namespace ProbabilityTheory theorem hasFiniteIntegral_prod_mk_left (a : α) {s : Set (β × γ)} (h2s : (κ ⊗ₖ η) a s ≠ ∞) : HasFiniteIntegral (fun b => (η (a, b) (Prod.mk b ⁻¹' s)).toReal) (κ a) := by let t := toMeasurable ((κ ⊗ₖ η) a) s simp_rw [HasFiniteIntegral, ennnorm_eq_ofReal toReal_nonneg] calc ∫⁻ b, ENNReal.ofReal (η (a, b) (Prod.mk b ⁻¹' s)).toReal ∂κ a _ ≤ ∫⁻ b, η (a, b) (Prod.mk b ⁻¹' t) ∂κ a := by refine lintegral_mono_ae ?_ filter_upwards [ae_kernel_lt_top a h2s] with b hb rw [ofReal_toReal hb.ne] exact measure_mono (preimage_mono (subset_toMeasurable _ _)) _ ≤ (κ ⊗ₖ η) a t := le_compProd_apply _ _ _ _ _ = (κ ⊗ₖ η) a s := measure_toMeasurable s _ < ⊤ := h2s.lt_top theorem integrable_kernel_prod_mk_left (a : α) {s : Set (β × γ)} (hs : MeasurableSet s) (h2s : (κ ⊗ₖ η) a s ≠ ∞) : Integrable (fun b => (η (a, b) (Prod.mk b ⁻¹' s)).toReal) (κ a) := by constructor · exact (measurable_kernel_prod_mk_left' hs a).ennreal_toReal.aestronglyMeasurable · exact hasFiniteIntegral_prod_mk_left a h2s theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_kernel_compProd [NormedSpace ℝ E] ⦃f : β × γ → E⦄ (hf : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) : AEStronglyMeasurable (fun x => ∫ y, f (x, y) ∂η (a, x)) (κ a) := ⟨fun x => ∫ y, hf.mk f (x, y) ∂η (a, x), hf.stronglyMeasurable_mk.integral_kernel_prod_right'', by filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with _ hx using integral_congr_ae hx⟩ theorem _root_.MeasureTheory.AEStronglyMeasurable.compProd_mk_left {δ : Type*} [TopologicalSpace δ] {f : β × γ → δ} (hf : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) : ∀ᵐ x ∂κ a, AEStronglyMeasurable (fun y => f (x, y)) (η (a, x)) := by filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with x hx using ⟨fun y => hf.mk f (x, y), hf.stronglyMeasurable_mk.comp_measurable measurable_prod_mk_left, hx⟩ /-! ### Integrability -/ theorem hasFiniteIntegral_compProd_iff ⦃f : β × γ → E⦄ (h1f : StronglyMeasurable f) : HasFiniteIntegral f ((κ ⊗ₖ η) a) ↔ (∀ᵐ x ∂κ a, HasFiniteIntegral (fun y => f (x, y)) (η (a, x))) ∧ HasFiniteIntegral (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := by simp only [HasFiniteIntegral] rw [Kernel.lintegral_compProd _ _ _ h1f.ennnorm] have : ∀ x, ∀ᵐ y ∂η (a, x), 0 ≤ ‖f (x, y)‖ := fun x => eventually_of_forall fun y => norm_nonneg _ simp_rw [integral_eq_lintegral_of_nonneg_ae (this _) (h1f.norm.comp_measurable measurable_prod_mk_left).aestronglyMeasurable, ennnorm_eq_ofReal toReal_nonneg, ofReal_norm_eq_coe_nnnorm] have : ∀ {p q r : Prop} (_ : r → p), (r ↔ p ∧ q) ↔ p → (r ↔ q) := fun {p q r} h1 => by rw [← and_congr_right_iff, and_iff_right_of_imp h1] rw [this] · intro h2f; rw [lintegral_congr_ae] filter_upwards [h2f] with x hx rw [ofReal_toReal]; rw [← lt_top_iff_ne_top]; exact hx · intro h2f; refine ae_lt_top ?_ h2f.ne; exact h1f.ennnorm.lintegral_kernel_prod_right'' theorem hasFiniteIntegral_compProd_iff' ⦃f : β × γ → E⦄ (h1f : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) : HasFiniteIntegral f ((κ ⊗ₖ η) a) ↔ (∀ᵐ x ∂κ a, HasFiniteIntegral (fun y => f (x, y)) (η (a, x))) ∧ HasFiniteIntegral (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := by rw [hasFiniteIntegral_congr h1f.ae_eq_mk, hasFiniteIntegral_compProd_iff h1f.stronglyMeasurable_mk] apply and_congr · apply eventually_congr filter_upwards [ae_ae_of_ae_compProd h1f.ae_eq_mk.symm] with x hx using hasFiniteIntegral_congr hx · apply hasFiniteIntegral_congr filter_upwards [ae_ae_of_ae_compProd h1f.ae_eq_mk.symm] with _ hx using integral_congr_ae (EventuallyEq.fun_comp hx _) theorem integrable_compProd_iff ⦃f : β × γ → E⦄ (hf : AEStronglyMeasurable f ((κ ⊗ₖ η) a)) : Integrable f ((κ ⊗ₖ η) a) ↔ (∀ᵐ x ∂κ a, Integrable (fun y => f (x, y)) (η (a, x))) ∧ Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := by simp only [Integrable, hasFiniteIntegral_compProd_iff' hf, hf.norm.integral_kernel_compProd, hf, hf.compProd_mk_left, eventually_and, true_and_iff] theorem _root_.MeasureTheory.Integrable.compProd_mk_left_ae ⦃f : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) : ∀ᵐ x ∂κ a, Integrable (fun y => f (x, y)) (η (a, x)) := ((integrable_compProd_iff hf.aestronglyMeasurable).mp hf).1 theorem _root_.MeasureTheory.Integrable.integral_norm_compProd ⦃f : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) : Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂η (a, x)) (κ a) := ((integrable_compProd_iff hf.aestronglyMeasurable).mp hf).2 theorem _root_.MeasureTheory.Integrable.integral_compProd [NormedSpace ℝ E] ⦃f : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) : Integrable (fun x => ∫ y, f (x, y) ∂η (a, x)) (κ a) := Integrable.mono hf.integral_norm_compProd hf.aestronglyMeasurable.integral_kernel_compProd <| eventually_of_forall fun x => (norm_integral_le_integral_norm _).trans_eq <| (norm_of_nonneg <| integral_nonneg_of_ae <| eventually_of_forall fun y => (norm_nonneg (f (x, y)) : _)).symm /-! ### Bochner integral -/ variable [NormedSpace ℝ E] {E' : Type*} [NormedAddCommGroup E'] [CompleteSpace E'] [NormedSpace ℝ E'] theorem Kernel.integral_fn_integral_add ⦃f g : β × γ → E⦄ (F : E → E') (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫ x, F (∫ y, f (x, y) + g (x, y) ∂η (a, x)) ∂κ a = ∫ x, F (∫ y, f (x, y) ∂η (a, x) + ∫ y, g (x, y) ∂η (a, x)) ∂κ a := by refine integral_congr_ae ?_ filter_upwards [hf.compProd_mk_left_ae, hg.compProd_mk_left_ae] with _ h2f h2g simp [integral_add h2f h2g] theorem Kernel.integral_fn_integral_sub ⦃f g : β × γ → E⦄ (F : E → E') (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫ x, F (∫ y, f (x, y) - g (x, y) ∂η (a, x)) ∂κ a = ∫ x, F (∫ y, f (x, y) ∂η (a, x) - ∫ y, g (x, y) ∂η (a, x)) ∂κ a := by refine integral_congr_ae ?_ filter_upwards [hf.compProd_mk_left_ae, hg.compProd_mk_left_ae] with _ h2f h2g simp [integral_sub h2f h2g] theorem Kernel.lintegral_fn_integral_sub ⦃f g : β × γ → E⦄ (F : E → ℝ≥0∞) (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫⁻ x, F (∫ y, f (x, y) - g (x, y) ∂η (a, x)) ∂κ a = ∫⁻ x, F (∫ y, f (x, y) ∂η (a, x) - ∫ y, g (x, y) ∂η (a, x)) ∂κ a := by refine lintegral_congr_ae ?_ filter_upwards [hf.compProd_mk_left_ae, hg.compProd_mk_left_ae] with _ h2f h2g simp [integral_sub h2f h2g] theorem Kernel.integral_integral_add ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫ x, ∫ y, f (x, y) + g (x, y) ∂η (a, x) ∂κ a = ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a + ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a := (Kernel.integral_fn_integral_add id hf hg).trans <| integral_add hf.integral_compProd hg.integral_compProd theorem Kernel.integral_integral_add' ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫ x, ∫ y, (f + g) (x, y) ∂η (a, x) ∂κ a = ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a + ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a := Kernel.integral_integral_add hf hg theorem Kernel.integral_integral_sub ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫ x, ∫ y, f (x, y) - g (x, y) ∂η (a, x) ∂κ a = ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a - ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a := (Kernel.integral_fn_integral_sub id hf hg).trans <| integral_sub hf.integral_compProd hg.integral_compProd theorem Kernel.integral_integral_sub' ⦃f g : β × γ → E⦄ (hf : Integrable f ((κ ⊗ₖ η) a)) (hg : Integrable g ((κ ⊗ₖ η) a)) : ∫ x, ∫ y, (f - g) (x, y) ∂η (a, x) ∂κ a = ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a - ∫ x, ∫ y, g (x, y) ∂η (a, x) ∂κ a := Kernel.integral_integral_sub hf hg -- Porting note: couldn't get the `→₁[]` syntax to work theorem Kernel.continuous_integral_integral : -- Continuous fun f : α × β →₁[(κ ⊗ₖ η) a] E => ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by Continuous fun f : (MeasureTheory.Lp (α := β × γ) E 1 (((κ ⊗ₖ η) a) : Measure (β × γ))) => ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by rw [continuous_iff_continuousAt]; intro g refine tendsto_integral_of_L1 _ (L1.integrable_coeFn g).integral_compProd (eventually_of_forall fun h => (L1.integrable_coeFn h).integral_compProd) ?_ simp_rw [← Kernel.lintegral_fn_integral_sub (fun x => (‖x‖₊ : ℝ≥0∞)) (L1.integrable_coeFn _) (L1.integrable_coeFn g)] apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds _ (fun i => zero_le _) _ · exact fun i => ∫⁻ x, ∫⁻ y, ‖i (x, y) - g (x, y)‖₊ ∂η (a, x) ∂κ a swap; · exact fun i => lintegral_mono fun x => ennnorm_integral_le_lintegral_ennnorm _ show Tendsto (fun i : β × γ →₁[(κ ⊗ₖ η) a] E => ∫⁻ x, ∫⁻ y : γ, ‖i (x, y) - g (x, y)‖₊ ∂η (a, x) ∂κ a) (𝓝 g) (𝓝 0) have : ∀ i : (MeasureTheory.Lp (α := β × γ) E 1 (((κ ⊗ₖ η) a) : Measure (β × γ))), Measurable fun z => (‖i z - g z‖₊ : ℝ≥0∞) := fun i => ((Lp.stronglyMeasurable i).sub (Lp.stronglyMeasurable g)).ennnorm simp_rw [← Kernel.lintegral_compProd _ _ _ (this _), ← L1.ofReal_norm_sub_eq_lintegral, ← ofReal_zero] refine (continuous_ofReal.tendsto 0).comp ?_ rw [← tendsto_iff_norm_sub_tendsto_zero] exact tendsto_id theorem integral_compProd : ∀ {f : β × γ → E} (_ : Integrable f ((κ ⊗ₖ η) a)), ∫ z, f z ∂(κ ⊗ₖ η) a = ∫ x, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by by_cases hE : CompleteSpace E; swap · simp [integral, hE] apply Integrable.induction · intro c s hs h2s simp_rw [integral_indicator hs, ← indicator_comp_right, Function.comp, integral_indicator (measurable_prod_mk_left hs), MeasureTheory.setIntegral_const, integral_smul_const] congr 1 rw [integral_toReal] rotate_left · exact (Kernel.measurable_kernel_prod_mk_left' hs _).aemeasurable · exact ae_kernel_lt_top a h2s.ne rw [Kernel.compProd_apply _ _ _ hs] rfl · intro f g _ i_f i_g hf hg simp_rw [integral_add' i_f i_g, Kernel.integral_integral_add' i_f i_g, hf, hg] · exact isClosed_eq continuous_integral Kernel.continuous_integral_integral · intro f g hfg _ hf convert hf using 1 · exact integral_congr_ae hfg.symm · apply integral_congr_ae filter_upwards [ae_ae_of_ae_compProd hfg] with x hfgx using integral_congr_ae (ae_eq_symm hfgx) theorem setIntegral_compProd {f : β × γ → E} {s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) (hf : IntegrableOn f (s ×ˢ t) ((κ ⊗ₖ η) a)) : ∫ z in s ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫ x in s, ∫ y in t, f (x, y) ∂η (a, x) ∂κ a := by -- Porting note: `compProd_restrict` needed some explicit argumnts rw [← Kernel.restrict_apply (κ ⊗ₖ η) (hs.prod ht), ← compProd_restrict hs ht, integral_compProd] · simp_rw [Kernel.restrict_apply] · rw [compProd_restrict, Kernel.restrict_apply]; exact hf @[deprecated (since := "2024-04-17")] alias set_integral_compProd := setIntegral_compProd theorem setIntegral_compProd_univ_right (f : β × γ → E) {s : Set β} (hs : MeasurableSet s) (hf : IntegrableOn f (s ×ˢ univ) ((κ ⊗ₖ η) a)) : ∫ z in s ×ˢ univ, f z ∂(κ ⊗ₖ η) a = ∫ x in s, ∫ y, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [setIntegral_compProd hs MeasurableSet.univ hf, Measure.restrict_univ] @[deprecated (since := "2024-04-17")] alias set_integral_compProd_univ_right := setIntegral_compProd_univ_right theorem setIntegral_compProd_univ_left (f : β × γ → E) {t : Set γ} (ht : MeasurableSet t) (hf : IntegrableOn f (univ ×ˢ t) ((κ ⊗ₖ η) a)) : ∫ z in univ ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫ x, ∫ y in t, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [setIntegral_compProd MeasurableSet.univ ht hf, Measure.restrict_univ] @[deprecated (since := "2024-04-17")] alias set_integral_compProd_univ_left := setIntegral_compProd_univ_left end ProbabilityTheory
Probability\Kernel\Invariance.lean
/- Copyright (c) 2023 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Kernel.Composition /-! # Invariance of measures along a kernel We say that a measure `μ` is invariant with respect to a kernel `κ` if its push-forward along the kernel `μ.bind κ` is the same measure. ## Main definitions * `ProbabilityTheory.Kernel.Invariant`: invariance of a given measure with respect to a kernel. ## Useful lemmas * `ProbabilityTheory.Kernel.const_bind_eq_comp_const`, and `ProbabilityTheory.Kernel.comp_const_apply_eq_bind` established the relationship between the push-forward measure and the composition of kernels. -/ open MeasureTheory open scoped MeasureTheory ENNReal ProbabilityTheory namespace ProbabilityTheory variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} namespace Kernel /-! ### Push-forward of measures along a kernel -/ @[simp] theorem bind_add (μ ν : Measure α) (κ : Kernel α β) : (μ + ν).bind κ = μ.bind κ + ν.bind κ := by ext1 s hs rw [Measure.bind_apply hs (Kernel.measurable _), lintegral_add_measure, Measure.coe_add, Pi.add_apply, Measure.bind_apply hs (Kernel.measurable _), Measure.bind_apply hs (Kernel.measurable _)] @[simp] theorem bind_smul (κ : Kernel α β) (μ : Measure α) (r : ℝ≥0∞) : (r • μ).bind κ = r • μ.bind κ := by ext1 s hs rw [Measure.bind_apply hs (Kernel.measurable _), lintegral_smul_measure, Measure.coe_smul, Pi.smul_apply, Measure.bind_apply hs (Kernel.measurable _), smul_eq_mul] theorem const_bind_eq_comp_const (κ : Kernel α β) (μ : Measure α) : const α (μ.bind κ) = κ ∘ₖ const α μ := by ext a s hs simp_rw [comp_apply' _ _ _ hs, const_apply, Measure.bind_apply hs (Kernel.measurable _)] theorem comp_const_apply_eq_bind (κ : Kernel α β) (μ : Measure α) (a : α) : (κ ∘ₖ const α μ) a = μ.bind κ := by rw [← const_apply (μ.bind κ) a, const_bind_eq_comp_const κ μ] /-! ### Invariant measures of kernels -/ /-- A measure `μ` is invariant with respect to the kernel `κ` if the push-forward measure of `μ` along `κ` equals `μ`. -/ def Invariant (κ : Kernel α α) (μ : Measure α) : Prop := μ.bind κ = μ variable {κ η : Kernel α α} {μ : Measure α} theorem Invariant.def (hκ : Invariant κ μ) : μ.bind κ = μ := hκ theorem Invariant.comp_const (hκ : Invariant κ μ) : κ ∘ₖ const α μ = const α μ := by rw [← const_bind_eq_comp_const κ μ, hκ.def] theorem Invariant.comp [IsSFiniteKernel κ] (hκ : Invariant κ μ) (hη : Invariant η μ) : Invariant (κ ∘ₖ η) μ := by cases' isEmpty_or_nonempty α with _ hα · exact Subsingleton.elim _ _ · simp_rw [Invariant, ← comp_const_apply_eq_bind (κ ∘ₖ η) μ hα.some, comp_assoc, hη.comp_const, hκ.comp_const, const_apply] end Kernel end ProbabilityTheory
Probability\Kernel\MeasurableIntegral.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.Probability.Kernel.Basic import Mathlib.MeasureTheory.Constructions.Prod.Basic import Mathlib.MeasureTheory.Integral.DominatedConvergence /-! # Measurability of the integral against a kernel The Lebesgue integral of a measurable function against a kernel is measurable. The Bochner integral is strongly measurable. ## Main statements * `Measurable.lintegral_kernel_prod_right`: the function `a ↦ ∫⁻ b, f a b ∂(κ a)` is measurable, for an s-finite kernel `κ : Kernel α β` and a function `f : α → β → ℝ≥0∞` such that `uncurry f` is measurable. * `MeasureTheory.StronglyMeasurable.integral_kernel_prod_right`: the function `a ↦ ∫ b, f a b ∂(κ a)` is measurable, for an s-finite kernel `κ : Kernel α β` and a function `f : α → β → E` such that `uncurry f` is measurable. -/ open MeasureTheory ProbabilityTheory Function Set Filter open scoped MeasureTheory ENNReal Topology variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} {κ : Kernel α β} {η : Kernel (α × β) γ} {a : α} namespace ProbabilityTheory namespace Kernel /-- This is an auxiliary lemma for `measurable_kernel_prod_mk_left`. -/ theorem measurable_kernel_prod_mk_left_of_finite {t : Set (α × β)} (ht : MeasurableSet t) (hκs : ∀ a, IsFiniteMeasure (κ a)) : Measurable fun a => κ a (Prod.mk a ⁻¹' t) := by -- `t` is a measurable set in the product `α × β`: we use that the product σ-algebra is generated -- by boxes to prove the result by induction. -- Porting note: added motive refine MeasurableSpace.induction_on_inter (C := fun t => Measurable fun a => κ a (Prod.mk a ⁻¹' t)) generateFrom_prod.symm isPiSystem_prod ?_ ?_ ?_ ?_ ht ·-- case `t = ∅` simp only [preimage_empty, measure_empty, measurable_const] · -- case of a box: `t = t₁ ×ˢ t₂` for measurable sets `t₁` and `t₂` intro t' ht' simp only [Set.mem_image2, Set.mem_setOf_eq, exists_and_left] at ht' obtain ⟨t₁, ht₁, t₂, ht₂, rfl⟩ := ht' classical simp_rw [mk_preimage_prod_right_eq_if] have h_eq_ite : (fun a => κ a (ite (a ∈ t₁) t₂ ∅)) = fun a => ite (a ∈ t₁) (κ a t₂) 0 := by ext1 a split_ifs exacts [rfl, measure_empty] rw [h_eq_ite] exact Measurable.ite ht₁ (Kernel.measurable_coe κ ht₂) measurable_const · -- we assume that the result is true for `t` and we prove it for `tᶜ` intro t' ht' h_meas have h_eq_sdiff : ∀ a, Prod.mk a ⁻¹' t'ᶜ = Set.univ \ Prod.mk a ⁻¹' t' := by intro a ext1 b simp only [mem_compl_iff, mem_preimage, mem_diff, mem_univ, true_and_iff] simp_rw [h_eq_sdiff] have : (fun a => κ a (Set.univ \ Prod.mk a ⁻¹' t')) = fun a => κ a Set.univ - κ a (Prod.mk a ⁻¹' t') := by ext1 a rw [← Set.diff_inter_self_eq_diff, Set.inter_univ, measure_diff (Set.subset_univ _)] · exact (@measurable_prod_mk_left α β _ _ a) ht' · exact measure_ne_top _ _ rw [this] exact Measurable.sub (Kernel.measurable_coe κ MeasurableSet.univ) h_meas · -- we assume that the result is true for a family of disjoint sets and prove it for their union intro f h_disj hf_meas hf have h_Union : (fun a => κ a (Prod.mk a ⁻¹' ⋃ i, f i)) = fun a => κ a (⋃ i, Prod.mk a ⁻¹' f i) := by ext1 a congr with b simp only [mem_iUnion, mem_preimage] rw [h_Union] have h_tsum : (fun a => κ a (⋃ i, Prod.mk a ⁻¹' f i)) = fun a => ∑' i, κ a (Prod.mk a ⁻¹' f i) := by ext1 a rw [measure_iUnion] · intro i j hij s hsi hsj b hbs have habi : {(a, b)} ⊆ f i := by rw [Set.singleton_subset_iff]; exact hsi hbs have habj : {(a, b)} ⊆ f j := by rw [Set.singleton_subset_iff]; exact hsj hbs simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff, Set.mem_empty_iff_false] using h_disj hij habi habj · exact fun i => (@measurable_prod_mk_left α β _ _ a) (hf_meas i) rw [h_tsum] exact Measurable.ennreal_tsum hf theorem measurable_kernel_prod_mk_left [IsSFiniteKernel κ] {t : Set (α × β)} (ht : MeasurableSet t) : Measurable fun a => κ a (Prod.mk a ⁻¹' t) := by rw [← Kernel.kernel_sum_seq κ] have : ∀ a, Kernel.sum (Kernel.seq κ) a (Prod.mk a ⁻¹' t) = ∑' n, Kernel.seq κ n a (Prod.mk a ⁻¹' t) := fun a => Kernel.sum_apply' _ _ (measurable_prod_mk_left ht) simp_rw [this] refine Measurable.ennreal_tsum fun n => ?_ exact measurable_kernel_prod_mk_left_of_finite ht inferInstance theorem measurable_kernel_prod_mk_left' [IsSFiniteKernel η] {s : Set (β × γ)} (hs : MeasurableSet s) (a : α) : Measurable fun b => η (a, b) (Prod.mk b ⁻¹' s) := by have : ∀ b, Prod.mk b ⁻¹' s = {c | ((a, b), c) ∈ {p : (α × β) × γ | (p.1.2, p.2) ∈ s}} := by intro b; rfl simp_rw [this] refine (measurable_kernel_prod_mk_left ?_).comp measurable_prod_mk_left exact (measurable_fst.snd.prod_mk measurable_snd) hs theorem measurable_kernel_prod_mk_right [IsSFiniteKernel κ] {s : Set (β × α)} (hs : MeasurableSet s) : Measurable fun y => κ y ((fun x => (x, y)) ⁻¹' s) := measurable_kernel_prod_mk_left (measurableSet_swap_iff.mpr hs) end Kernel open ProbabilityTheory.Kernel section Lintegral variable [IsSFiniteKernel κ] [IsSFiniteKernel η] /-- Auxiliary lemma for `Measurable.lintegral_kernel_prod_right`. -/ theorem Kernel.measurable_lintegral_indicator_const {t : Set (α × β)} (ht : MeasurableSet t) (c : ℝ≥0∞) : Measurable fun a => ∫⁻ b, t.indicator (Function.const (α × β) c) (a, b) ∂κ a := by -- Porting note: was originally by -- `simp_rw [lintegral_indicator_const_comp measurable_prod_mk_left ht _]` -- but this has no effect, so added the `conv` below conv => congr ext erw [lintegral_indicator_const_comp measurable_prod_mk_left ht _] exact Measurable.const_mul (measurable_kernel_prod_mk_left ht) c /-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is measurable when seen as a map from `α × β` (hypothesis `Measurable (uncurry f)`), the integral `a ↦ ∫⁻ b, f a b ∂(κ a)` is measurable. -/ theorem _root_.Measurable.lintegral_kernel_prod_right {f : α → β → ℝ≥0∞} (hf : Measurable (uncurry f)) : Measurable fun a => ∫⁻ b, f a b ∂κ a := by let F : ℕ → SimpleFunc (α × β) ℝ≥0∞ := SimpleFunc.eapprox (uncurry f) have h : ∀ a, ⨆ n, F n a = uncurry f a := SimpleFunc.iSup_eapprox_apply (uncurry f) hf simp only [Prod.forall, uncurry_apply_pair] at h simp_rw [← h] have : ∀ a, (∫⁻ b, ⨆ n, F n (a, b) ∂κ a) = ⨆ n, ∫⁻ b, F n (a, b) ∂κ a := by intro a rw [lintegral_iSup] · exact fun n => (F n).measurable.comp measurable_prod_mk_left · exact fun i j hij b => SimpleFunc.monotone_eapprox (uncurry f) hij _ simp_rw [this] refine measurable_iSup fun n => ?_ refine SimpleFunc.induction (P := fun f => Measurable (fun (a : α) => ∫⁻ (b : β), f (a, b) ∂κ a)) ?_ ?_ (F n) · intro c t ht simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero, Set.piecewise_eq_indicator] exact Kernel.measurable_lintegral_indicator_const (κ := κ) ht c · intro g₁ g₂ _ hm₁ hm₂ simp only [SimpleFunc.coe_add, Pi.add_apply] have h_add : (fun a => ∫⁻ b, g₁ (a, b) + g₂ (a, b) ∂κ a) = (fun a => ∫⁻ b, g₁ (a, b) ∂κ a) + fun a => ∫⁻ b, g₂ (a, b) ∂κ a := by ext1 a rw [Pi.add_apply] -- Porting note (#10691): was `rw` (`Function.comp` reducibility) erw [lintegral_add_left (g₁.measurable.comp measurable_prod_mk_left)] simp_rw [Function.comp_apply] rw [h_add] exact Measurable.add hm₁ hm₂ theorem _root_.Measurable.lintegral_kernel_prod_right' {f : α × β → ℝ≥0∞} (hf : Measurable f) : Measurable fun a => ∫⁻ b, f (a, b) ∂κ a := by refine Measurable.lintegral_kernel_prod_right ?_ have : (uncurry fun (a : α) (b : β) => f (a, b)) = f := by ext x; rw [uncurry_apply_pair] rwa [this] theorem _root_.Measurable.lintegral_kernel_prod_right'' {f : β × γ → ℝ≥0∞} (hf : Measurable f) : Measurable fun x => ∫⁻ y, f (x, y) ∂η (a, x) := by -- Porting note: used `Prod.mk a` instead of `fun x => (a, x)` below change Measurable ((fun x => ∫⁻ y, (fun u : (α × β) × γ => f (u.1.2, u.2)) (x, y) ∂η x) ∘ Prod.mk a) -- Porting note: specified `κ`, `f`. refine (Measurable.lintegral_kernel_prod_right' (κ := η) (f := (fun u ↦ f (u.fst.snd, u.snd))) ?_).comp measurable_prod_mk_left exact hf.comp (measurable_fst.snd.prod_mk measurable_snd) theorem _root_.Measurable.setLIntegral_kernel_prod_right {f : α → β → ℝ≥0∞} (hf : Measurable (uncurry f)) {s : Set β} (hs : MeasurableSet s) : Measurable fun a => ∫⁻ b in s, f a b ∂κ a := by simp_rw [← lintegral_restrict κ hs]; exact hf.lintegral_kernel_prod_right @[deprecated (since := "2024-06-29")] alias _root_.Measurable.set_lintegral_kernel_prod_right := _root_.Measurable.setLIntegral_kernel_prod_right theorem _root_.Measurable.lintegral_kernel_prod_left' {f : β × α → ℝ≥0∞} (hf : Measurable f) : Measurable fun y => ∫⁻ x, f (x, y) ∂κ y := (measurable_swap_iff.mpr hf).lintegral_kernel_prod_right' theorem _root_.Measurable.lintegral_kernel_prod_left {f : β → α → ℝ≥0∞} (hf : Measurable (uncurry f)) : Measurable fun y => ∫⁻ x, f x y ∂κ y := hf.lintegral_kernel_prod_left' theorem _root_.Measurable.setLIntegral_kernel_prod_left {f : β → α → ℝ≥0∞} (hf : Measurable (uncurry f)) {s : Set β} (hs : MeasurableSet s) : Measurable fun b => ∫⁻ a in s, f a b ∂κ b := by simp_rw [← lintegral_restrict κ hs]; exact hf.lintegral_kernel_prod_left @[deprecated (since := "2024-06-29")] alias _root_.Measurable.set_lintegral_kernel_prod_left := _root_.Measurable.setLIntegral_kernel_prod_left theorem _root_.Measurable.lintegral_kernel {f : β → ℝ≥0∞} (hf : Measurable f) : Measurable fun a => ∫⁻ b, f b ∂κ a := Measurable.lintegral_kernel_prod_right (hf.comp measurable_snd) theorem _root_.Measurable.setLIntegral_kernel {f : β → ℝ≥0∞} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : Measurable fun a => ∫⁻ b in s, f b ∂κ a := by -- Porting note: was term mode proof (`Function.comp` reducibility) refine Measurable.setLIntegral_kernel_prod_right ?_ hs convert hf.comp measurable_snd @[deprecated (since := "2024-06-29")] alias _root_.Measurable.set_lintegral_kernel := _root_.Measurable.setLIntegral_kernel end Lintegral variable {E : Type*} [NormedAddCommGroup E] [IsSFiniteKernel κ] [IsSFiniteKernel η] theorem measurableSet_kernel_integrable ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : MeasurableSet {x | Integrable (f x) (κ x)} := by simp_rw [Integrable, hf.of_uncurry_left.aestronglyMeasurable, true_and_iff] exact measurableSet_lt (Measurable.lintegral_kernel_prod_right hf.ennnorm) measurable_const end ProbabilityTheory open ProbabilityTheory.Kernel namespace MeasureTheory variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [IsSFiniteKernel κ] [IsSFiniteKernel η] theorem StronglyMeasurable.integral_kernel_prod_right ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun x => ∫ y, f x y ∂κ x := by classical by_cases hE : CompleteSpace E; swap · simp [integral, hE, stronglyMeasurable_const] borelize E haveI : TopologicalSpace.SeparableSpace (range (uncurry f) ∪ {0} : Set E) := hf.separableSpace_range_union_singleton let s : ℕ → SimpleFunc (α × β) E := SimpleFunc.approxOn _ hf.measurable (range (uncurry f) ∪ {0}) 0 (by simp) let s' : ℕ → α → SimpleFunc β E := fun n x => (s n).comp (Prod.mk x) measurable_prod_mk_left let f' : ℕ → α → E := fun n => {x | Integrable (f x) (κ x)}.indicator fun x => (s' n x).integral (κ x) have hf' : ∀ n, StronglyMeasurable (f' n) := by intro n; refine StronglyMeasurable.indicator ?_ (measurableSet_kernel_integrable hf) have : ∀ x, ((s' n x).range.filter fun x => x ≠ 0) ⊆ (s n).range := by intro x; refine Finset.Subset.trans (Finset.filter_subset _ _) ?_; intro y simp_rw [SimpleFunc.mem_range]; rintro ⟨z, rfl⟩; exact ⟨(x, z), rfl⟩ simp only [SimpleFunc.integral_eq_sum_of_subset (this _)] refine Finset.stronglyMeasurable_sum _ fun x _ => ?_ refine (Measurable.ennreal_toReal ?_).stronglyMeasurable.smul_const _ simp only [s', SimpleFunc.coe_comp, preimage_comp] apply Kernel.measurable_kernel_prod_mk_left exact (s n).measurableSet_fiber x have h2f' : Tendsto f' atTop (𝓝 fun x : α => ∫ y : β, f x y ∂κ x) := by rw [tendsto_pi_nhds]; intro x by_cases hfx : Integrable (f x) (κ x) · have (n) : Integrable (s' n x) (κ x) := by apply (hfx.norm.add hfx.norm).mono' (s' n x).aestronglyMeasurable filter_upwards with y simp_rw [s', SimpleFunc.coe_comp]; exact SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n simp only [f', hfx, SimpleFunc.integral_eq_integral _ (this _), indicator_of_mem, mem_setOf_eq] refine tendsto_integral_of_dominated_convergence (fun y => ‖f x y‖ + ‖f x y‖) (fun n => (s' n x).aestronglyMeasurable) (hfx.norm.add hfx.norm) ?_ ?_ · -- Porting note: was -- exact fun n => eventually_of_forall fun y => -- SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n exact fun n => eventually_of_forall fun y => SimpleFunc.norm_approxOn_zero_le hf.measurable (by simp) (x, y) n · refine eventually_of_forall fun y => SimpleFunc.tendsto_approxOn hf.measurable (by simp) ?_ apply subset_closure simp [-uncurry_apply_pair] · simp [f', hfx, integral_undef] exact stronglyMeasurable_of_tendsto _ hf' h2f' theorem StronglyMeasurable.integral_kernel_prod_right' ⦃f : α × β → E⦄ (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ∫ y, f (x, y) ∂κ x := by rw [← uncurry_curry f] at hf exact hf.integral_kernel_prod_right theorem StronglyMeasurable.integral_kernel_prod_right'' {f : β × γ → E} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ∫ y, f (x, y) ∂η (a, x) := by change StronglyMeasurable ((fun x => ∫ y, (fun u : (α × β) × γ => f (u.1.2, u.2)) (x, y) ∂η x) ∘ fun x => (a, x)) apply StronglyMeasurable.comp_measurable _ (measurable_prod_mk_left (m := mα)) · have := MeasureTheory.StronglyMeasurable.integral_kernel_prod_right' (κ := η) (hf.comp_measurable (measurable_fst.snd.prod_mk measurable_snd)) simpa using this theorem StronglyMeasurable.integral_kernel_prod_left ⦃f : β → α → E⦄ (hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun y => ∫ x, f x y ∂κ y := (hf.comp_measurable measurable_swap).integral_kernel_prod_right' theorem StronglyMeasurable.integral_kernel_prod_left' ⦃f : β × α → E⦄ (hf : StronglyMeasurable f) : StronglyMeasurable fun y => ∫ x, f (x, y) ∂κ y := (hf.comp_measurable measurable_swap).integral_kernel_prod_right' theorem StronglyMeasurable.integral_kernel_prod_left'' {f : γ × β → E} (hf : StronglyMeasurable f) : StronglyMeasurable fun y => ∫ x, f (x, y) ∂η (a, y) := by change StronglyMeasurable ((fun y => ∫ x, (fun u : γ × α × β => f (u.1, u.2.2)) (x, y) ∂η y) ∘ fun x => (a, x)) apply StronglyMeasurable.comp_measurable _ (measurable_prod_mk_left (m := mα)) · have := MeasureTheory.StronglyMeasurable.integral_kernel_prod_left' (κ := η) (hf.comp_measurable (measurable_fst.prod_mk measurable_snd.snd)) simpa using this end MeasureTheory
Probability\Kernel\MeasureCompProd.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.Probability.Kernel.IntegralCompProd /-! # Composition-Product of a measure and a kernel This operation, denoted by `⊗ₘ`, takes `μ : Measure α` and `κ : Kernel α β` and creates `μ ⊗ₘ κ : Measure (α × β)`. The integral of a function against `μ ⊗ₘ κ` is `∫⁻ x, f x ∂(μ ⊗ₘ κ) = ∫⁻ a, ∫⁻ b, f (a, b) ∂(κ a) ∂μ`. `μ ⊗ₘ κ` is defined as `((Kernel.const Unit μ) ⊗ₖ (Kernel.prodMkLeft Unit κ)) ()`. ## Main definitions * `Measure.compProd`: from `μ : Measure α` and `κ : Kernel α β`, get a `Measure (α × β)`. ## Notations * `μ ⊗ₘ κ = μ.compProd κ` -/ open scoped ENNReal open ProbabilityTheory namespace MeasureTheory.Measure variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {μ : Measure α} {κ η : Kernel α β} /-- The composition-product of a measure and a kernel. -/ noncomputable def compProd (μ : Measure α) (κ : Kernel α β) : Measure (α × β) := (Kernel.const Unit μ ⊗ₖ Kernel.prodMkLeft Unit κ) () @[inherit_doc] scoped[ProbabilityTheory] infixl:100 " ⊗ₘ " => MeasureTheory.Measure.compProd lemma compProd_of_not_sfinite (μ : Measure α) (κ : Kernel α β) (h : ¬ SFinite μ) : μ ⊗ₘ κ = 0 := by rw [compProd, Kernel.compProd_of_not_isSFiniteKernel_left, Kernel.zero_apply] rwa [Kernel.isSFiniteKernel_const] lemma compProd_of_not_isSFiniteKernel (μ : Measure α) (κ : Kernel α β) (h : ¬ IsSFiniteKernel κ) : μ ⊗ₘ κ = 0 := by rw [compProd, Kernel.compProd_of_not_isSFiniteKernel_right, Kernel.zero_apply] rwa [Kernel.isSFiniteKernel_prodMkLeft_unit] @[simp] lemma compProd_zero_left (κ : Kernel α β) : (0 : Measure α) ⊗ₘ κ = 0 := by simp [compProd] @[simp] lemma compProd_zero_right (μ : Measure α) : μ ⊗ₘ (0 : Kernel α β) = 0 := by simp [compProd] lemma compProd_apply [SFinite μ] [IsSFiniteKernel κ] {s : Set (α × β)} (hs : MeasurableSet s) : (μ ⊗ₘ κ) s = ∫⁻ a, κ a (Prod.mk a ⁻¹' s) ∂μ := by simp_rw [compProd, Kernel.compProd_apply _ _ _ hs, Kernel.const_apply, Kernel.prodMkLeft_apply'] rfl lemma compProd_apply_prod [SFinite μ] [IsSFiniteKernel κ] {s : Set α} {t : Set β} (hs : MeasurableSet s) (ht : MeasurableSet t) : (μ ⊗ₘ κ) (s ×ˢ t) = ∫⁻ a in s, κ a t ∂μ := by rw [compProd_apply (hs.prod ht), ← lintegral_indicator _ hs] congr with a classical rw [Set.indicator_apply] split_ifs with ha <;> simp [ha] lemma compProd_congr [SFinite μ] [IsSFiniteKernel κ] [IsSFiniteKernel η] (h : κ =ᵐ[μ] η) : μ ⊗ₘ κ = μ ⊗ₘ η := by ext s hs have : (fun a ↦ κ a (Prod.mk a ⁻¹' s)) =ᵐ[μ] fun a ↦ η a (Prod.mk a ⁻¹' s) := by filter_upwards [h] with a ha using by rw [ha] rw [compProd_apply hs, lintegral_congr_ae this, compProd_apply hs] lemma ae_compProd_of_ae_ae [SFinite μ] [IsSFiniteKernel κ] {p : α × β → Prop} (hp : MeasurableSet {x | p x}) (h : ∀ᵐ a ∂μ, ∀ᵐ b ∂(κ a), p (a, b)) : ∀ᵐ x ∂(μ ⊗ₘ κ), p x := Kernel.ae_compProd_of_ae_ae hp h lemma ae_ae_of_ae_compProd [SFinite μ] [IsSFiniteKernel κ] {p : α × β → Prop} (h : ∀ᵐ x ∂(μ ⊗ₘ κ), p x) : ∀ᵐ a ∂μ, ∀ᵐ b ∂κ a, p (a, b) := by convert Kernel.ae_ae_of_ae_compProd h -- Much faster with `convert` lemma ae_compProd_iff [SFinite μ] [IsSFiniteKernel κ] {p : α × β → Prop} (hp : MeasurableSet {x | p x}) : (∀ᵐ x ∂(μ ⊗ₘ κ), p x) ↔ ∀ᵐ a ∂μ, ∀ᵐ b ∂(κ a), p (a, b) := Kernel.ae_compProd_iff hp lemma compProd_add_left (μ ν : Measure α) [SFinite μ] [SFinite ν] (κ : Kernel α β) [IsSFiniteKernel κ] : (μ + ν) ⊗ₘ κ = μ ⊗ₘ κ + ν ⊗ₘ κ := by rw [Measure.compProd, Kernel.const_add, Kernel.compProd_add_left]; rfl lemma compProd_add_right (μ : Measure α) [SFinite μ] (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] : μ ⊗ₘ (κ + η) = μ ⊗ₘ κ + μ ⊗ₘ η := by rw [Measure.compProd, Kernel.prodMkLeft_add, Kernel.compProd_add_right]; rfl section Integral lemma lintegral_compProd [SFinite μ] [IsSFiniteKernel κ] {f : α × β → ℝ≥0∞} (hf : Measurable f) : ∫⁻ x, f x ∂(μ ⊗ₘ κ) = ∫⁻ a, ∫⁻ b, f (a, b) ∂(κ a) ∂μ := by rw [compProd, Kernel.lintegral_compProd _ _ _ hf] simp lemma setLIntegral_compProd [SFinite μ] [IsSFiniteKernel κ] {f : α × β → ℝ≥0∞} (hf : Measurable f) {s : Set α} (hs : MeasurableSet s) {t : Set β} (ht : MeasurableSet t) : ∫⁻ x in s ×ˢ t, f x ∂(μ ⊗ₘ κ) = ∫⁻ a in s, ∫⁻ b in t, f (a, b) ∂(κ a) ∂μ := by rw [compProd, Kernel.setLIntegral_compProd _ _ _ hf hs ht] simp @[deprecated (since := "2024-06-29")] alias set_lintegral_compProd := setLIntegral_compProd lemma integrable_compProd_iff [SFinite μ] [IsSFiniteKernel κ] {E : Type*} [NormedAddCommGroup E] {f : α × β → E} (hf : AEStronglyMeasurable f (μ ⊗ₘ κ)) : Integrable f (μ ⊗ₘ κ) ↔ (∀ᵐ x ∂μ, Integrable (fun y => f (x, y)) (κ x)) ∧ Integrable (fun x => ∫ y, ‖f (x, y)‖ ∂(κ x)) μ := by rw [Measure.compProd, ProbabilityTheory.integrable_compProd_iff hf] rfl lemma integral_compProd [SFinite μ] [IsSFiniteKernel κ] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : α × β → E} (hf : Integrable f (μ ⊗ₘ κ)) : ∫ x, f x ∂(μ ⊗ₘ κ) = ∫ a, ∫ b, f (a, b) ∂(κ a) ∂μ := by rw [compProd, ProbabilityTheory.integral_compProd hf] simp lemma setIntegral_compProd [SFinite μ] [IsSFiniteKernel κ] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {s : Set α} (hs : MeasurableSet s) {t : Set β} (ht : MeasurableSet t) {f : α × β → E} (hf : IntegrableOn f (s ×ˢ t) (μ ⊗ₘ κ)) : ∫ x in s ×ˢ t, f x ∂(μ ⊗ₘ κ) = ∫ a in s, ∫ b in t, f (a, b) ∂(κ a) ∂μ := by rw [compProd, ProbabilityTheory.setIntegral_compProd hs ht hf] simp @[deprecated (since := "2024-04-17")] alias set_integral_compProd := setIntegral_compProd end Integral lemma dirac_compProd_apply [MeasurableSingletonClass α] {a : α} [IsSFiniteKernel κ] {s : Set (α × β)} (hs : MeasurableSet s) : (Measure.dirac a ⊗ₘ κ) s = κ a (Prod.mk a ⁻¹' s) := by rw [compProd_apply hs, lintegral_dirac] lemma dirac_unit_compProd (κ : Kernel Unit β) [IsSFiniteKernel κ] : Measure.dirac () ⊗ₘ κ = (κ ()).map (Prod.mk ()) := by ext s hs; rw [dirac_compProd_apply hs, Measure.map_apply measurable_prod_mk_left hs] lemma dirac_unit_compProd_const (μ : Measure β) [IsFiniteMeasure μ] : Measure.dirac () ⊗ₘ Kernel.const Unit μ = μ.map (Prod.mk ()) := by rw [dirac_unit_compProd, Kernel.const_apply] @[simp] lemma snd_dirac_unit_compProd_const (μ : Measure β) [IsFiniteMeasure μ] : snd (Measure.dirac () ⊗ₘ Kernel.const Unit μ) = μ := by rw [dirac_unit_compProd_const, snd, map_map measurable_snd measurable_prod_mk_left] simp instance : SFinite (μ ⊗ₘ κ) := by rw [compProd]; infer_instance instance [IsFiniteMeasure μ] [IsFiniteKernel κ] : IsFiniteMeasure (μ ⊗ₘ κ) := by rw [compProd]; infer_instance instance [IsProbabilityMeasure μ] [IsMarkovKernel κ] : IsProbabilityMeasure (μ ⊗ₘ κ) := by rw [compProd]; infer_instance end MeasureTheory.Measure
Probability\Kernel\RadonNikodym.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.Probability.Kernel.Disintegration.Density import Mathlib.Probability.Kernel.WithDensity /-! # Radon-Nikodym derivative and Lebesgue decomposition for kernels Let `α` and `γ` be two measurable space, where either `α` is countable or `γ` is countably generated. Let `κ, η : Kernel α γ` be finite kernels. Then there exists a function `Kernel.rnDeriv κ η : α → γ → ℝ≥0∞` jointly measurable on `α × γ` and a kernel `Kernel.singularPart κ η : Kernel α γ` such that * `κ = Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η`, * for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a`, * for all `a : α`, `Kernel.singularPart κ η a = 0 ↔ κ a ≪ η a`, * for all `a : α`, `Kernel.withDensity η (Kernel.rnDeriv κ η) a = 0 ↔ κ a ⟂ₘ η a`. Furthermore, the sets `{a | κ a ≪ η a}` and `{a | κ a ⟂ₘ η a}` are measurable. When `γ` is countably generated, the construction of the derivative starts from `Kernel.density`: for two finite kernels `κ' : Kernel α (γ × β)` and `η' : Kernel α γ` with `fst κ' ≤ η'`, the function `density κ' η' : α → γ → Set β → ℝ` is jointly measurable in the first two arguments and satisfies that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`, `∫ x in A, density κ' η' a x s ∂(η' a) = (κ' a (A ×ˢ s)).toReal`. We use that definition for `β = Unit` and `κ' = map κ (fun a ↦ (a, ()))`. We can't choose `η' = η` in general because we might not have `κ ≤ η`, but if we could, we would get a measurable function `f` with the property `κ = withDensity η f`, which is the decomposition we want for `κ ≤ η`. To circumvent that difficulty, we take `η' = κ + η` and thus define `rnDerivAux κ η`. Finally, `rnDeriv κ η a x` is given by `ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)`. Up to some conversions between `ℝ` and `ℝ≥0`, the singular part is `withDensity (κ + η) (rnDerivAux κ (κ + η) - (1 - rnDerivAux κ (κ + η)) * rnDeriv κ η)`. The countably generated measurable space assumption is not needed to have a decomposition for measures, but the additional difficulty with kernels is to obtain joint measurability of the derivative. This is why we can't simply define `rnDeriv κ η` by `a ↦ (κ a).rnDeriv (ν a)` everywhere unless `α` is countable (although `rnDeriv κ η` has that value almost everywhere). See the construction of `Kernel.density` for details on how the countably generated hypothesis is used. ## Main definitions * `ProbabilityTheory.Kernel.rnDeriv`: a function `α → γ → ℝ≥0∞` jointly measurable on `α × γ` * `ProbabilityTheory.Kernel.singularPart`: a `Kernel α γ` ## Main statements * `ProbabilityTheory.Kernel.mutuallySingular_singularPart`: for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a` * `ProbabilityTheory.Kernel.rnDeriv_add_singularPart`: `Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η = κ` * `ProbabilityTheory.Kernel.measurableSet_absolutelyContinuous` : the set `{a | κ a ≪ η a}` is Measurable * `ProbabilityTheory.Kernel.measurableSet_mutuallySingular` : the set `{a | κ a ⟂ₘ η a}` is Measurable ## References Theorem 1.28 in [O. Kallenberg, Random Measures, Theory and Applications][kallenberg2017]. ## TODO * prove uniqueness results. * link kernel Radon-Nikodym derivative and Radon-Nikodym derivative of measures, and similarly for singular parts. -/ open MeasureTheory Set Filter open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory.Kernel variable {α γ : Type*} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} {κ η : Kernel α γ} [hαγ : MeasurableSpace.CountableOrCountablyGenerated α γ] open Classical in /-- Auxiliary function used to define `ProbabilityTheory.Kernel.rnDeriv` and `ProbabilityTheory.Kernel.singularPart`. This has the properties we want for a Radon-Nikodym derivative only if `κ ≪ ν`. The definition of `rnDeriv κ η` will be built from `rnDerivAux κ (κ + η)`. -/ noncomputable def rnDerivAux (κ η : Kernel α γ) (a : α) (x : γ) : ℝ := if hα : Countable α then ((κ a).rnDeriv (η a) x).toReal else haveI := hαγ.countableOrCountablyGenerated.resolve_left hα density (map κ (fun a ↦ (a, ())) (@measurable_prod_mk_right γ Unit _ inferInstance _)) η a x univ lemma rnDerivAux_nonneg (hκη : κ ≤ η) {a : α} {x : γ} : 0 ≤ rnDerivAux κ η a x := by rw [rnDerivAux] split_ifs with hα · exact ENNReal.toReal_nonneg · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact density_nonneg ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _ lemma rnDerivAux_le_one [IsFiniteKernel η] (hκη : κ ≤ η) {a : α} : rnDerivAux κ η a ≤ᵐ[η a] 1 := by filter_upwards [Measure.rnDeriv_le_one_of_le (hκη a)] with x hx_le_one simp_rw [rnDerivAux] split_ifs with hα · refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_ simp only [Pi.one_apply, ENNReal.ofReal_one] exact hx_le_one · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact density_le_one ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _ lemma measurable_rnDerivAux (κ η : Kernel α γ) : Measurable (fun p : α × γ ↦ Kernel.rnDerivAux κ η p.1 p.2) := by simp_rw [rnDerivAux] split_ifs with hα · refine Measurable.ennreal_toReal ?_ change Measurable ((fun q : γ × α ↦ (κ q.2).rnDeriv (η q.2) q.1) ∘ Prod.swap) refine (measurable_from_prod_countable' (fun a ↦ ?_) ?_).comp measurable_swap · exact Measure.measurable_rnDeriv (κ a) (η a) · intro a a' c ha'_mem_a have h_eq : ∀ κ : Kernel α γ, κ a' = κ a := fun κ ↦ by ext s hs exact mem_of_mem_measurableAtom ha'_mem_a (Kernel.measurable_coe κ hs (measurableSet_singleton (κ a s))) rfl rw [h_eq κ, h_eq η] · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact measurable_density _ η MeasurableSet.univ lemma measurable_rnDerivAux_right (κ η : Kernel α γ) (a : α) : Measurable (fun x : γ ↦ rnDerivAux κ η a x) := by change Measurable ((fun p : α × γ ↦ rnDerivAux κ η p.1 p.2) ∘ (fun x ↦ (a, x))) exact (measurable_rnDerivAux _ _).comp measurable_prod_mk_left lemma setLIntegral_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) {s : Set γ} (hs : MeasurableSet s) : ∫⁻ x in s, ENNReal.ofReal (rnDerivAux κ (κ + η) a x) ∂(κ + η) a = κ a s := by have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le simp_rw [rnDerivAux] split_ifs with hα · have h_ac : κ a ≪ (κ + η) a := Measure.absolutelyContinuous_of_le (h_le a) rw [← Measure.setLIntegral_rnDeriv h_ac] refine setLIntegral_congr_fun hs ?_ filter_upwards [Measure.rnDeriv_lt_top (κ a) ((κ + η) a)] with x hx_lt _ rw [ENNReal.ofReal_toReal hx_lt.ne] · have := hαγ.countableOrCountablyGenerated.resolve_left hα rw [setLIntegral_density ((fst_map_id_prod _ measurable_const).trans_le h_le) _ MeasurableSet.univ hs, map_apply' _ _ _ (hs.prod MeasurableSet.univ)] congr with x simp @[deprecated (since := "2024-06-29")] alias set_lintegral_rnDerivAux := setLIntegral_rnDerivAux lemma withDensity_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ := by ext a s hs rw [Kernel.withDensity_apply'] swap · exact (measurable_rnDerivAux _ _).ennreal_ofReal have : ∀ b, (Real.toNNReal b : ℝ≥0∞) = ENNReal.ofReal b := fun _ ↦ rfl simp_rw [this] exact setLIntegral_rnDerivAux κ η a hs lemma withDensity_one_sub_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) = η := by have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) + withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ + η by ext a s have h : (withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) + withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x))) a s = κ a s + η a s := by rw [this] simp simp only [coe_add, Pi.add_apply, Measure.coe_add] at h rwa [withDensity_rnDerivAux, add_comm, ENNReal.add_right_inj (measure_ne_top _ _)] at h have : ∀ b, (Real.toNNReal b : ℝ≥0∞) = ENNReal.ofReal b := fun _ ↦ rfl simp_rw [this, ENNReal.ofReal_sub _ (rnDerivAux_nonneg h_le), ENNReal.ofReal_one] rw [withDensity_sub_add_cancel] · rw [withDensity_one'] · exact measurable_const · exact (measurable_rnDerivAux _ _).ennreal_ofReal · intro a filter_upwards [rnDerivAux_le_one h_le] with x hx simp only [ENNReal.ofReal_le_one] exact hx /-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of `κ` and `η`. -/ def mutuallySingularSet (κ η : Kernel α γ) : Set (α × γ) := {p | 1 ≤ rnDerivAux κ (κ + η) p.1 p.2} /-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of `κ` and `η`. That is, * `withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a) = 0`, * `singularPart κ η a (mutuallySingularSetSlice κ η a)ᶜ = 0`. -/ def mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) : Set γ := {x | 1 ≤ rnDerivAux κ (κ + η) a x} lemma mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) : x ∈ mutuallySingularSetSlice κ η a ↔ 1 ≤ rnDerivAux κ (κ + η) a x := by rw [mutuallySingularSetSlice]; rfl lemma not_mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) : x ∉ mutuallySingularSetSlice κ η a ↔ rnDerivAux κ (κ + η) a x < 1 := by simp [mutuallySingularSetSlice] lemma measurableSet_mutuallySingularSet (κ η : Kernel α γ) : MeasurableSet (mutuallySingularSet κ η) := measurable_rnDerivAux κ (κ + η) measurableSet_Ici lemma measurableSet_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) : MeasurableSet (mutuallySingularSetSlice κ η a) := measurable_prod_mk_left (measurableSet_mutuallySingularSet κ η) lemma measure_mutuallySingularSetSlice (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : η a (mutuallySingularSetSlice κ η a) = 0 := by have h_coe : ∀ b, (Real.toNNReal b : ℝ≥0∞) = ENNReal.ofReal b := fun _ ↦ rfl suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) a {x | 1 ≤ rnDerivAux κ (κ + η) a x} = 0 by rwa [withDensity_one_sub_rnDerivAux κ η] at this simp_rw [h_coe] rw [Kernel.withDensity_apply', lintegral_eq_zero_iff, EventuallyEq, ae_restrict_iff] rotate_left · exact (measurable_const.sub ((measurable_rnDerivAux _ _).comp measurable_prod_mk_left)).ennreal_ofReal (measurableSet_singleton _) · exact (measurable_const.sub ((measurable_rnDerivAux _ _).comp measurable_prod_mk_left)).ennreal_ofReal · exact (measurable_const.sub (measurable_rnDerivAux _ _)).ennreal_ofReal refine ae_of_all _ (fun x hx ↦ ?_) simp only [mem_setOf_eq] at hx simp [hx] /-- Radon-Nikodym derivative of the kernel `κ` with respect to the kernel `η`. -/ noncomputable irreducible_def rnDeriv (κ η : Kernel α γ) (a : α) (x : γ) : ℝ≥0∞ := ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x) lemma rnDeriv_def' (κ η : Kernel α γ) : rnDeriv κ η = fun a x ↦ ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x) := by ext; rw [rnDeriv_def] lemma measurable_rnDeriv (κ η : Kernel α γ) : Measurable (fun p : α × γ ↦ rnDeriv κ η p.1 p.2) := by simp_rw [rnDeriv_def] exact (measurable_rnDerivAux κ _).ennreal_ofReal.div (measurable_const.sub (measurable_rnDerivAux κ _)).ennreal_ofReal lemma measurable_rnDeriv_right (κ η : Kernel α γ) (a : α) : Measurable (fun x : γ ↦ rnDeriv κ η a x) := by change Measurable ((fun p : α × γ ↦ rnDeriv κ η p.1 p.2) ∘ (fun x ↦ (a, x))) exact (measurable_rnDeriv _ _).comp measurable_prod_mk_left lemma rnDeriv_eq_top_iff (κ η : Kernel α γ) (a : α) (x : γ) : rnDeriv κ η a x = ∞ ↔ (a, x) ∈ mutuallySingularSet κ η := by simp only [rnDeriv, ENNReal.div_eq_top, ne_eq, ENNReal.ofReal_eq_zero, not_le, tsub_le_iff_right, zero_add, ENNReal.ofReal_ne_top, not_false_eq_true, and_true, or_false, mutuallySingularSet, mem_setOf_eq, and_iff_right_iff_imp] exact fun h ↦ zero_lt_one.trans_le h lemma rnDeriv_eq_top_iff' (κ η : Kernel α γ) (a : α) (x : γ) : rnDeriv κ η a x = ∞ ↔ x ∈ mutuallySingularSetSlice κ η a := by rw [rnDeriv_eq_top_iff, mutuallySingularSet, mutuallySingularSetSlice, mem_setOf, mem_setOf] /-- Singular part of the kernel `κ` with respect to the kernel `η`. -/ noncomputable irreducible_def singularPart (κ η : Kernel α γ) [IsSFiniteKernel κ] [IsSFiniteKernel η] : Kernel α γ := withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x) - Real.toNNReal (1 - rnDerivAux κ (κ + η) a x) * rnDeriv κ η a x) lemma measurable_singularPart_fun (κ η : Kernel α γ) : Measurable (fun p : α × γ ↦ Real.toNNReal (rnDerivAux κ (κ + η) p.1 p.2) - Real.toNNReal (1 - rnDerivAux κ (κ + η) p.1 p.2) * rnDeriv κ η p.1 p.2) := (measurable_rnDerivAux _ _).ennreal_ofReal.sub ((measurable_const.sub (measurable_rnDerivAux _ _)).ennreal_ofReal.mul (measurable_rnDeriv _ _)) lemma measurable_singularPart_fun_right (κ η : Kernel α γ) (a : α) : Measurable (fun x : γ ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x) - Real.toNNReal (1 - rnDerivAux κ (κ + η) a x) * rnDeriv κ η a x) := by change Measurable ((Function.uncurry fun a b ↦ ENNReal.ofReal (rnDerivAux κ (κ + η) a b) - ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a b) * rnDeriv κ η a b) ∘ (fun b ↦ (a, b))) exact (measurable_singularPart_fun κ η).comp measurable_prod_mk_left lemma singularPart_compl_mutuallySingularSetSlice (κ η : Kernel α γ) [IsSFiniteKernel κ] [IsSFiniteKernel η] (a : α) : singularPart κ η a (mutuallySingularSetSlice κ η a)ᶜ = 0 := by have h_coe : ∀ b, (Real.toNNReal b : ℝ≥0∞) = ENNReal.ofReal b := fun _ ↦ rfl rw [singularPart, Kernel.withDensity_apply', lintegral_eq_zero_iff, EventuallyEq, ae_restrict_iff] all_goals simp_rw [h_coe] rotate_left · exact measurableSet_preimage (measurable_singularPart_fun_right κ η a) (measurableSet_singleton _) · exact measurable_singularPart_fun_right κ η a · exact measurable_singularPart_fun κ η refine ae_of_all _ (fun x hx ↦ ?_) simp only [mem_compl_iff, mutuallySingularSetSlice, mem_setOf, not_le] at hx simp_rw [rnDeriv] rw [← ENNReal.ofReal_div_of_pos, div_eq_inv_mul, ← ENNReal.ofReal_mul, ← mul_assoc, mul_inv_cancel, one_mul, tsub_self, Pi.zero_apply] · simp only [ne_eq, sub_eq_zero, hx.ne', not_false_eq_true] · simp only [sub_nonneg, hx.le] · simp only [sub_pos, hx] lemma singularPart_of_subset_compl_mutuallySingularSetSlice [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} {s : Set γ} (hs : s ⊆ (mutuallySingularSetSlice κ η a)ᶜ) : singularPart κ η a s = 0 := measure_mono_null hs (singularPart_compl_mutuallySingularSetSlice κ η a) lemma singularPart_of_subset_mutuallySingularSetSlice [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} {s : Set γ} (hsm : MeasurableSet s) (hs : s ⊆ mutuallySingularSetSlice κ η a) : singularPart κ η a s = κ a s := by have hs' : ∀ x ∈ s, 1 ≤ rnDerivAux κ (κ + η) a x := fun _ hx ↦ hs hx rw [singularPart, Kernel.withDensity_apply'] swap; · exact measurable_singularPart_fun κ η calc ∫⁻ x in s, ↑(Real.toNNReal (rnDerivAux κ (κ + η) a x)) - ↑(Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) * rnDeriv κ η a x ∂(κ + η) a = ∫⁻ _ in s, 1 ∂(κ + η) a := by refine setLIntegral_congr_fun hsm ?_ have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le filter_upwards [rnDerivAux_le_one h_le] with x hx hxs have h_eq_one : rnDerivAux κ (κ + η) a x = 1 := le_antisymm hx (hs' x hxs) simp [h_eq_one] _ = (κ + η) a s := by simp _ = κ a s := by suffices η a s = 0 by simp [this] exact measure_mono_null hs (measure_mutuallySingularSetSlice κ η a) lemma withDensity_rnDeriv_mutuallySingularSetSlice (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a) = 0 := by rw [Kernel.withDensity_apply'] · exact setLIntegral_measure_zero _ _ (measure_mutuallySingularSetSlice κ η a) · exact measurable_rnDeriv κ η lemma withDensity_rnDeriv_of_subset_mutuallySingularSetSlice [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} {s : Set γ} (hs : s ⊆ mutuallySingularSetSlice κ η a) : withDensity η (rnDeriv κ η) a s = 0 := measure_mono_null hs (withDensity_rnDeriv_mutuallySingularSetSlice κ η a) lemma withDensity_rnDeriv_of_subset_compl_mutuallySingularSetSlice [IsFiniteKernel κ] [IsFiniteKernel η] {a : α} {s : Set γ} (hsm : MeasurableSet s) (hs : s ⊆ (mutuallySingularSetSlice κ η a)ᶜ) : withDensity η (rnDeriv κ η) a s = κ a s := by have h_coe : ∀ b, (Real.toNNReal b : ℝ≥0∞) = ENNReal.ofReal b := fun _ ↦ rfl have : withDensity η (rnDeriv κ η) = withDensity (withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x))) (rnDeriv κ η) := by rw [rnDeriv_def'] congr exact (withDensity_one_sub_rnDerivAux κ η).symm rw [this, ← withDensity_mul, Kernel.withDensity_apply'] rotate_left · exact ((measurable_const.sub (measurable_rnDerivAux _ _)).ennreal_ofReal.mul (measurable_rnDeriv _ _)) · exact (measurable_const.sub (measurable_rnDerivAux _ _)).real_toNNReal · exact measurable_rnDeriv _ _ simp_rw [rnDeriv] have hs' : ∀ x ∈ s, rnDerivAux κ (κ + η) a x < 1 := by simp_rw [← not_mem_mutuallySingularSetSlice] exact fun x hx hx_mem ↦ hs hx hx_mem calc ∫⁻ x in s, ↑(Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) * (ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)) ∂(κ + η) a _ = ∫⁻ x in s, ENNReal.ofReal (rnDerivAux κ (κ + η) a x) ∂(κ + η) a := by refine setLIntegral_congr_fun hsm (ae_of_all _ fun x hx ↦ ?_) rw [h_coe, ← ENNReal.ofReal_div_of_pos, div_eq_inv_mul, ← ENNReal.ofReal_mul, ← mul_assoc, mul_inv_cancel, one_mul] · rw [ne_eq, sub_eq_zero] exact (hs' x hx).ne' · simp [(hs' x hx).le] · simp [hs' x hx] _ = κ a s := setLIntegral_rnDerivAux κ η a hsm /-- The singular part of `κ` with respect to `η` is mutually singular with `η`. -/ lemma mutuallySingular_singularPart (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : singularPart κ η a ⟂ₘ η a := by symm exact ⟨mutuallySingularSetSlice κ η a, measurableSet_mutuallySingularSetSlice κ η a, measure_mutuallySingularSetSlice κ η a, singularPart_compl_mutuallySingularSetSlice κ η a⟩ /-- Lebesgue decomposition of a finite kernel `κ` with respect to another one `η`. `κ` is the sum of an abolutely continuous part `withDensity η (rnDeriv κ η)` and a singular part `singularPart κ η`. -/ lemma rnDeriv_add_singularPart (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity η (rnDeriv κ η) + singularPart κ η = κ := by ext a s hs rw [← inter_union_diff s (mutuallySingularSetSlice κ η a)] simp only [coe_add, Pi.add_apply, Measure.coe_add] have hm := measurableSet_mutuallySingularSetSlice κ η a simp only [measure_union (Disjoint.mono inter_subset_right subset_rfl disjoint_sdiff_right) (hs.diff hm)] rw [singularPart_of_subset_mutuallySingularSetSlice (hs.inter hm) inter_subset_right, singularPart_of_subset_compl_mutuallySingularSetSlice (diff_subset_iff.mpr (by simp)), add_zero, withDensity_rnDeriv_of_subset_mutuallySingularSetSlice inter_subset_right, zero_add, withDensity_rnDeriv_of_subset_compl_mutuallySingularSetSlice (hs.diff hm) (diff_subset_iff.mpr (by simp)), add_comm] lemma singularPart_eq_zero_iff_apply_eq_zero (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : singularPart κ η a = 0 ↔ singularPart κ η a (mutuallySingularSetSlice κ η a) = 0 := by rw [← Measure.measure_univ_eq_zero] have : univ = (mutuallySingularSetSlice κ η a) ∪ (mutuallySingularSetSlice κ η a)ᶜ := by simp rw [this, measure_union disjoint_compl_right (measurableSet_mutuallySingularSetSlice κ η a).compl, singularPart_compl_mutuallySingularSetSlice, add_zero] lemma withDensity_rnDeriv_eq_zero_iff_apply_eq_zero (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : withDensity η (rnDeriv κ η) a = 0 ↔ withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a)ᶜ = 0 := by rw [← Measure.measure_univ_eq_zero] have : univ = (mutuallySingularSetSlice κ η a) ∪ (mutuallySingularSetSlice κ η a)ᶜ := by simp rw [this, measure_union disjoint_compl_right (measurableSet_mutuallySingularSetSlice κ η a).compl, withDensity_rnDeriv_mutuallySingularSetSlice, zero_add] lemma singularPart_eq_zero_iff_absolutelyContinuous (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : singularPart κ η a = 0 ↔ κ a ≪ η a := by conv_rhs => rw [← rnDeriv_add_singularPart κ η, coe_add, Pi.add_apply] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [h, add_zero] exact withDensity_absolutelyContinuous _ _ rw [Measure.AbsolutelyContinuous.add_left_iff] at h exact Measure.eq_zero_of_absolutelyContinuous_of_mutuallySingular h.2 (mutuallySingular_singularPart _ _ _) lemma withDensity_rnDeriv_eq_zero_iff_mutuallySingular (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : withDensity η (rnDeriv κ η) a = 0 ↔ κ a ⟂ₘ η a := by conv_rhs => rw [← rnDeriv_add_singularPart κ η, coe_add, Pi.add_apply] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [h, zero_add] exact mutuallySingular_singularPart _ _ _ rw [Measure.MutuallySingular.add_left_iff] at h rw [← Measure.MutuallySingular.self_iff] exact h.1.mono_ac Measure.AbsolutelyContinuous.rfl (withDensity_absolutelyContinuous (κ := η) (rnDeriv κ η) a) lemma singularPart_eq_zero_iff_measure_eq_zero (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : singularPart κ η a = 0 ↔ κ a (mutuallySingularSetSlice κ η a) = 0 := by have h_eq_add := rnDeriv_add_singularPart κ η simp_rw [Kernel.ext_iff, Measure.ext_iff] at h_eq_add specialize h_eq_add a (mutuallySingularSetSlice κ η a) (measurableSet_mutuallySingularSetSlice κ η a) simp only [coe_add, Pi.add_apply, Measure.coe_add, withDensity_rnDeriv_mutuallySingularSetSlice κ η, zero_add] at h_eq_add rw [← h_eq_add] exact singularPart_eq_zero_iff_apply_eq_zero κ η a lemma withDensity_rnDeriv_eq_zero_iff_measure_eq_zero (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : withDensity η (rnDeriv κ η) a = 0 ↔ κ a (mutuallySingularSetSlice κ η a)ᶜ = 0 := by have h_eq_add := rnDeriv_add_singularPart κ η simp_rw [Kernel.ext_iff, Measure.ext_iff] at h_eq_add specialize h_eq_add a (mutuallySingularSetSlice κ η a)ᶜ (measurableSet_mutuallySingularSetSlice κ η a).compl simp only [coe_add, Pi.add_apply, Measure.coe_add, singularPart_compl_mutuallySingularSetSlice κ η, add_zero] at h_eq_add rw [← h_eq_add] exact withDensity_rnDeriv_eq_zero_iff_apply_eq_zero κ η a /-- The set of points `a : α` such that `κ a ≪ η a` is measurable. -/ @[measurability] lemma measurableSet_absolutelyContinuous (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : MeasurableSet {a | κ a ≪ η a} := by simp_rw [← singularPart_eq_zero_iff_absolutelyContinuous, singularPart_eq_zero_iff_measure_eq_zero] exact measurable_kernel_prod_mk_left (measurableSet_mutuallySingularSet κ η) (measurableSet_singleton 0) /-- The set of points `a : α` such that `κ a ⟂ₘ η a` is measurable. -/ @[measurability] lemma measurableSet_mutuallySingular (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : MeasurableSet {a | κ a ⟂ₘ η a} := by simp_rw [← withDensity_rnDeriv_eq_zero_iff_mutuallySingular, withDensity_rnDeriv_eq_zero_iff_measure_eq_zero] exact measurable_kernel_prod_mk_left (measurableSet_mutuallySingularSet κ η).compl (measurableSet_singleton 0) end ProbabilityTheory.Kernel
Probability\Kernel\WithDensity.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.Probability.Kernel.MeasurableIntegral import Mathlib.MeasureTheory.Integral.SetIntegral /-! # With Density For an s-finite kernel `κ : Kernel α β` and a function `f : α → β → ℝ≥0∞` which is finite everywhere, we define `withDensity κ f` as the kernel `a ↦ (κ a).withDensity (f a)`. This is an s-finite kernel. ## Main definitions * `ProbabilityTheory.Kernel.withDensity κ (f : α → β → ℝ≥0∞)`: kernel `a ↦ (κ a).withDensity (f a)`. It is defined if `κ` is s-finite. If `f` is finite everywhere, then this is also an s-finite kernel. The class of s-finite kernels is the smallest class of kernels that contains finite kernels and which is stable by `withDensity`. Integral: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)` ## Main statements * `ProbabilityTheory.Kernel.lintegral_withDensity`: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)` -/ open MeasureTheory ProbabilityTheory open scoped MeasureTheory ENNReal NNReal namespace ProbabilityTheory.Kernel variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} variable {κ : Kernel α β} {f : α → β → ℝ≥0∞} /-- Kernel with image `(κ a).withDensity (f a)` if `Function.uncurry f` is measurable, and with image 0 otherwise. If `Function.uncurry f` is measurable, it satisfies `∫⁻ b, g b ∂(withDensity κ f hf a) = ∫⁻ b, f a b * g b ∂(κ a)`. -/ noncomputable def withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) : Kernel α β := @dite _ (Measurable (Function.uncurry f)) (Classical.dec _) (fun hf => (⟨fun a => (κ a).withDensity (f a), by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [withDensity_apply _ hs] exact hf.setLIntegral_kernel_prod_right hs⟩ : Kernel α β)) fun _ => 0 theorem withDensity_of_not_measurable (κ : Kernel α β) [IsSFiniteKernel κ] (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf protected theorem withDensity_apply (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) := by classical rw [withDensity, dif_pos hf] rfl protected theorem withDensity_apply' (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) (s : Set β) : withDensity κ f a s = ∫⁻ b in s, f a b ∂κ a := by rw [Kernel.withDensity_apply κ hf, withDensity_apply' _ s] nonrec lemma withDensity_congr_ae (κ : Kernel α β) [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) (hfg : ∀ a, f a =ᵐ[κ a] g a) : withDensity κ f = withDensity κ g := by ext a rw [Kernel.withDensity_apply _ hf,Kernel.withDensity_apply _ hg, withDensity_congr_ae (hfg a)] nonrec lemma withDensity_absolutelyContinuous [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) (a : α) : Kernel.withDensity κ f a ≪ κ a := by by_cases hf : Measurable (Function.uncurry f) · rw [Kernel.withDensity_apply _ hf] exact withDensity_absolutelyContinuous _ _ · rw [withDensity_of_not_measurable _ hf] simp [Measure.AbsolutelyContinuous.zero] @[simp] lemma withDensity_one (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ 1 = κ := by ext; rw [Kernel.withDensity_apply _ measurable_const]; simp @[simp] lemma withDensity_one' (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ (fun _ _ ↦ 1) = κ := Kernel.withDensity_one _ @[simp] lemma withDensity_zero (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ 0 = 0 := by ext; rw [Kernel.withDensity_apply _ measurable_const]; simp @[simp] lemma withDensity_zero' (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ (fun _ _ ↦ 0) = 0 := Kernel.withDensity_zero _ theorem lintegral_withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a := by rw [Kernel.withDensity_apply _ hf, lintegral_withDensity_eq_lintegral_mul _ (Measurable.of_uncurry_left hf) hg] simp_rw [Pi.mul_apply] theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0} (hg : Measurable (Function.uncurry g)) : ∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a := by rw [Kernel.withDensity_apply, integral_withDensity_eq_integral_smul] · exact Measurable.of_uncurry_left hg · exact measurable_coe_nnreal_ennreal.comp hg theorem withDensity_add_left (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f := by by_cases hf : Measurable (Function.uncurry f) · ext a s simp only [Kernel.withDensity_apply _ hf, coe_add, Pi.add_apply, withDensity_add_measure, Measure.add_apply] · simp_rw [withDensity_of_not_measurable _ hf] rw [zero_add] theorem withDensity_kernel_sum [Countable ι] (κ : ι → Kernel α β) (hκ : ∀ i, IsSFiniteKernel (κ i)) (f : α → β → ℝ≥0∞) : @withDensity _ _ _ _ (Kernel.sum κ) (isSFiniteKernel_sum hκ) f = Kernel.sum fun i => withDensity (κ i) f := by by_cases hf : Measurable (Function.uncurry f) · ext1 a simp_rw [sum_apply, Kernel.withDensity_apply _ hf, sum_apply, withDensity_sum (fun n => κ n a) (f a)] · simp_rw [withDensity_of_not_measurable _ hf] exact sum_zero.symm lemma withDensity_add_right [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) : withDensity κ (f + g) = withDensity κ f + withDensity κ g := by ext a rw [coe_add, Pi.add_apply, Kernel.withDensity_apply _ hf, Kernel.withDensity_apply _ hg, Kernel.withDensity_apply, Pi.add_apply, MeasureTheory.withDensity_add_right] · exact hg.comp measurable_prod_mk_left · exact hf.add hg lemma withDensity_sub_add_cancel [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) (hfg : ∀ a, g a ≤ᵐ[κ a] f a) : withDensity κ (fun a x ↦ f a x - g a x) + withDensity κ g = withDensity κ f := by rw [← withDensity_add_right _ hg] swap; · exact hf.sub hg refine withDensity_congr_ae κ ((hf.sub hg).add hg) hf (fun a ↦ ?_) filter_upwards [hfg a] with x hx rwa [Pi.add_apply, Pi.add_apply, tsub_add_cancel_iff_le] theorem withDensity_tsum [Countable ι] (κ : Kernel α β) [IsSFiniteKernel κ] {f : ι → α → β → ℝ≥0∞} (hf : ∀ i, Measurable (Function.uncurry (f i))) : withDensity κ (∑' n, f n) = Kernel.sum fun n => withDensity κ (f n) := by have h_sum_a : ∀ a, Summable fun n => f n a := fun a => Pi.summable.mpr fun b => ENNReal.summable have h_sum : Summable fun n => f n := Pi.summable.mpr h_sum_a ext a s hs rw [sum_apply' _ a hs, Kernel.withDensity_apply' κ _ a s] swap · have : Function.uncurry (∑' n, f n) = ∑' n, Function.uncurry (f n) := by ext1 p simp only [Function.uncurry_def] rw [tsum_apply h_sum, tsum_apply (h_sum_a _), tsum_apply] exact Pi.summable.mpr fun p => ENNReal.summable rw [this] exact Measurable.ennreal_tsum' hf have : ∫⁻ b in s, (∑' n, f n) a b ∂κ a = ∫⁻ b in s, ∑' n, (fun b => f n a b) b ∂κ a := by congr with b rw [tsum_apply h_sum, tsum_apply (h_sum_a a)] rw [this, lintegral_tsum fun n => (Measurable.of_uncurry_left (hf n)).aemeasurable] congr with n rw [Kernel.withDensity_apply' _ (hf n) a s] /-- If a kernel `κ` is finite and a function `f : α → β → ℝ≥0∞` is bounded, then `withDensity κ f` is finite. -/ theorem isFiniteKernel_withDensity_of_bounded (κ : Kernel α β) [IsFiniteKernel κ] {B : ℝ≥0∞} (hB_top : B ≠ ∞) (hf_B : ∀ a b, f a b ≤ B) : IsFiniteKernel (withDensity κ f) := by by_cases hf : Measurable (Function.uncurry f) · exact ⟨⟨B * IsFiniteKernel.bound κ, ENNReal.mul_lt_top hB_top (IsFiniteKernel.bound_ne_top κ), fun a => by rw [Kernel.withDensity_apply' κ hf a Set.univ] calc ∫⁻ b in Set.univ, f a b ∂κ a ≤ ∫⁻ _ in Set.univ, B ∂κ a := lintegral_mono (hf_B a) _ = B * κ a Set.univ := by simp only [Measure.restrict_univ, MeasureTheory.lintegral_const] _ ≤ B * IsFiniteKernel.bound κ := mul_le_mul_left' (measure_le_bound κ a Set.univ) _⟩⟩ · rw [withDensity_of_not_measurable _ hf] infer_instance /-- Auxiliary lemma for `IsSFiniteKernel.withDensity`. If a kernel `κ` is finite, then `withDensity κ f` is s-finite. -/ theorem isSFiniteKernel_withDensity_of_isFiniteKernel (κ : Kernel α β) [IsFiniteKernel κ] (hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by -- We already have that for `f` bounded from above and a `κ` a finite kernel, -- `withDensity κ f` is finite. We write any function as a countable sum of bounded -- functions, and decompose an s-finite kernel as a sum of finite kernels. We then use that -- `withDensity` commutes with sums for both arguments and get a sum of finite kernels. by_cases hf : Measurable (Function.uncurry f) swap; · rw [withDensity_of_not_measurable _ hf]; infer_instance let fs : ℕ → α → β → ℝ≥0∞ := fun n a b => min (f a b) (n + 1) - min (f a b) n have h_le : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → f a b ≤ n := by intro a b n hn have : (f a b).toReal ≤ n := Nat.le_of_ceil_le hn rw [← ENNReal.le_ofReal_iff_toReal_le (hf_ne_top a b) _] at this · refine this.trans (le_of_eq ?_) rw [ENNReal.ofReal_natCast] · norm_cast exact zero_le _ have h_zero : ∀ a b n, ⌈(f a b).toReal⌉₊ ≤ n → fs n a b = 0 := by intro a b n hn suffices min (f a b) (n + 1) = f a b ∧ min (f a b) n = f a b by simp_rw [fs, this.1, this.2, tsub_self (f a b)] exact ⟨min_eq_left ((h_le a b n hn).trans (le_add_of_nonneg_right zero_le_one)), min_eq_left (h_le a b n hn)⟩ have hf_eq_tsum : f = ∑' n, fs n := by have h_sum_a : ∀ a, Summable fun n => fs n a := by refine fun a => Pi.summable.mpr fun b => ?_ suffices ∀ n, n ∉ Finset.range ⌈(f a b).toReal⌉₊ → fs n a b = 0 from summable_of_ne_finset_zero this intro n hn_not_mem rw [Finset.mem_range, not_lt] at hn_not_mem exact h_zero a b n hn_not_mem ext a b : 2 rw [tsum_apply (Pi.summable.mpr h_sum_a), tsum_apply (h_sum_a a), ENNReal.tsum_eq_liminf_sum_nat] have h_finset_sum : ∀ n, ∑ i ∈ Finset.range n, fs i a b = min (f a b) n := by intro n induction' n with n hn · simp rw [Finset.sum_range_succ, hn] simp [fs] simp_rw [h_finset_sum] refine (Filter.Tendsto.liminf_eq ?_).symm refine Filter.Tendsto.congr' ?_ tendsto_const_nhds rw [Filter.EventuallyEq, Filter.eventually_atTop] exact ⟨⌈(f a b).toReal⌉₊, fun n hn => (min_eq_left (h_le a b n hn)).symm⟩ rw [hf_eq_tsum, withDensity_tsum _ fun n : ℕ => _] swap; · exact fun _ => (hf.min measurable_const).sub (hf.min measurable_const) refine isSFiniteKernel_sum fun n => ?_ suffices IsFiniteKernel (withDensity κ (fs n)) by haveI := this; infer_instance refine isFiniteKernel_withDensity_of_bounded _ (ENNReal.coe_ne_top : ↑n + 1 ≠ ∞) fun a b => ?_ -- After leanprover/lean4#2734, we need to do beta reduction before `norm_cast` beta_reduce norm_cast calc fs n a b ≤ min (f a b) (n + 1) := tsub_le_self _ ≤ n + 1 := min_le_right _ _ _ = ↑(n + 1) := by norm_cast /-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0∞` which is everywhere finite, `withDensity κ f` is s-finite. -/ nonrec theorem IsSFiniteKernel.withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (hf_ne_top : ∀ a b, f a b ≠ ∞) : IsSFiniteKernel (withDensity κ f) := by have h_eq_sum : withDensity κ f = Kernel.sum fun i => withDensity (seq κ i) f := by rw [← withDensity_kernel_sum _ _] congr exact (kernel_sum_seq κ).symm rw [h_eq_sum] exact isSFiniteKernel_sum fun n => isSFiniteKernel_withDensity_of_isFiniteKernel (seq κ n) hf_ne_top /-- For an s-finite kernel `κ` and a function `f : α → β → ℝ≥0`, `withDensity κ f` is s-finite. -/ instance (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0) : IsSFiniteKernel (withDensity κ fun a b => f a b) := IsSFiniteKernel.withDensity κ fun _ _ => ENNReal.coe_ne_top nonrec lemma withDensity_mul [IsSFiniteKernel κ] {f : α → β → ℝ≥0} {g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) : withDensity κ (fun a x ↦ f a x * g a x) = withDensity (withDensity κ fun a x ↦ f a x) g := by ext a : 1 rw [Kernel.withDensity_apply] swap; · exact (measurable_coe_nnreal_ennreal.comp hf).mul hg change (Measure.withDensity (κ a) ((fun x ↦ (f a x : ℝ≥0∞)) * (fun x ↦ (g a x : ℝ≥0∞)))) = (withDensity (withDensity κ fun a x ↦ f a x) g) a rw [withDensity_mul] · rw [Kernel.withDensity_apply _ hg, Kernel.withDensity_apply] exact measurable_coe_nnreal_ennreal.comp hf · rw [measurable_coe_nnreal_ennreal_iff] exact hf.comp measurable_prod_mk_left · exact hg.comp measurable_prod_mk_left end ProbabilityTheory.Kernel
Probability\Kernel\Disintegration\Basic.lean
/- Copyright (c) 2024 Yaël Dillies, Kin Yau James Wong. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Kin Yau James Wong, Rémy Degenne -/ import Mathlib.Probability.Kernel.MeasureCompProd /-! # Disintegration of measures and kernels This file defines predicates for a kernel to "disintegrate" a measure or a kernel. This kernel is also called the "conditional kernel" of the measure or kernel. A measure `ρ : Measure (α × Ω)` is disintegrated by a kernel `ρCond : Kernel α Ω` if `ρ.fst ⊗ₘ ρCond = ρ`. A kernel `ρ : Kernel α (β × Ω)` is disintegrated by a kernel `κCond : Kernel (α × β) Ω` if `κ.fst ⊗ₖ κCond = κ`. ## Main definitions * `MeasureTheory.Measure.IsCondKernel ρ ρCond`: Predicate for the kernel `ρCond` to disintegrate the measure `ρ`. * `ProbabilityTheory.Kernel.IsCondKernel κ κCond`: Predicate for the kernel `κ Cond` to disintegrate the kernel `κ`. Further, if `κ` is an s-finite kernel from a countable `α` such that each measure `κ a` is disintegrated by some kernel, then `κ` itself is disintegrated by a kernel, namely `ProbabilityTheory.Kernel.condKernelCountable`. ## See also `Mathlib.Probability.Kernel.Disintegration.StandardBorel` for a **construction** of disintegrating kernels. -/ open MeasureTheory Set Filter MeasurableSpace ProbabilityTheory open scoped ENNReal MeasureTheory Topology variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mΩ : MeasurableSpace Ω} /-! ### Disintegration of measures This section provides a predicate for a kernel to disintegrate a measure. -/ namespace MeasureTheory.Measure variable (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] (ρCond : Kernel α Ω) /-- A kernel `ρCond` is a conditional kernel for a measure `ρ` if it disintegrates it in the sense that `ρ.fst ⊗ₘ ρCond = ρ`. -/ class IsCondKernel : Prop where disintegrate : ρ.fst ⊗ₘ ρCond = ρ variable [ρ.IsCondKernel ρCond] lemma disintegrate : ρ.fst ⊗ₘ ρCond = ρ := IsCondKernel.disintegrate lemma IsCondKernel.isSFiniteKernel (hρ : ρ ≠ 0) : IsSFiniteKernel ρCond := by contrapose! hρ; rwa [← ρ.disintegrate ρCond, Measure.compProd_of_not_isSFiniteKernel] /-- Auxiliary lemma for `IsCondKernel.apply_of_ne_zero`. -/ private lemma IsCondKernel.apply_of_ne_zero_of_measurableSet [MeasurableSingletonClass α] {x : α} (hx : ρ.fst {x} ≠ 0) {s : Set Ω} (hs : MeasurableSet s) : ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := by have := isSFiniteKernel ρ ρCond (by rintro rfl; simp at hx) nth_rewrite 2 [← ρ.disintegrate ρCond] rw [Measure.compProd_apply (measurableSet_prod.mpr (Or.inl ⟨measurableSet_singleton x, hs⟩))] classical have (a) : ρCond a (Prod.mk a ⁻¹' {x} ×ˢ s) = ({x} : Set α).indicator (ρCond · s) a := by obtain rfl | hax := eq_or_ne a x · simp only [singleton_prod, mem_singleton_iff, indicator_of_mem] congr with y simp · simp only [singleton_prod, mem_singleton_iff, hax, not_false_eq_true, indicator_of_not_mem] have : Prod.mk a ⁻¹' (Prod.mk x '' s) = ∅ := by ext y; simp [Ne.symm hax] simp only [this, measure_empty] simp_rw [this] rw [MeasureTheory.lintegral_indicator _ (measurableSet_singleton x)] simp only [Measure.restrict_singleton, lintegral_smul_measure, lintegral_dirac] rw [← mul_assoc, ENNReal.inv_mul_cancel hx (measure_ne_top _ _), one_mul] /-- If the singleton `{x}` has non-zero mass for `ρ.fst`, then for all `s : Set Ω`, `ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s)` . -/ lemma IsCondKernel.apply_of_ne_zero [MeasurableSingletonClass α] {x : α} (hx : ρ.fst {x} ≠ 0) (s : Set Ω) : ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := by have : ρCond x s = ((ρ.fst {x})⁻¹ • ρ).comap (fun (y : Ω) ↦ (x, y)) s := by congr 2 with s hs simp [IsCondKernel.apply_of_ne_zero_of_measurableSet _ _ hx hs, (measurableEmbedding_prod_mk_left x).comap_apply] simp [this, (measurableEmbedding_prod_mk_left x).comap_apply, hx] lemma IsCondKernel.isProbabilityMeasure [MeasurableSingletonClass α] {a : α} (ha : ρ.fst {a} ≠ 0) : IsProbabilityMeasure (ρCond a) := by constructor rw [IsCondKernel.apply_of_ne_zero _ _ ha, prod_univ, ← Measure.fst_apply (measurableSet_singleton _), ENNReal.inv_mul_cancel ha (measure_ne_top _ _)] lemma IsCondKernel.isMarkovKernel [MeasurableSingletonClass α] (hρ : ∀ a, ρ.fst {a} ≠ 0) : IsMarkovKernel ρCond := ⟨fun _ ↦ isProbabilityMeasure _ _ (hρ _)⟩ end MeasureTheory.Measure /-! ### Disintegration of kernels This section provides a predicate for a kernel to disintegrate a kernel. It also proves that if `κ` is an s-finite kernel from a countable `α` such that each measure `κ a` is disintegrated by some kernel, then `κ` itself is disintegrated by a kernel, namely `ProbabilityTheory.Kernel.condKernelCountable`.. -/ namespace ProbabilityTheory.Kernel variable (κ : Kernel α (β × Ω)) (κCond : Kernel (α × β) Ω) /-! #### Predicate for a kernel to disintegrate a kernel -/ /-- A kernel `κCond` is a conditional kernel for a kernel `κ` if it disintegrates it in the sense that `κ.fst ⊗ₖ κCond = κ`. -/ class IsCondKernel : Prop where protected disintegrate : κ.fst ⊗ₖ κCond = κ instance instIsCondKernel_zero (κCond : Kernel (α × β) Ω) : IsCondKernel 0 κCond where disintegrate := by simp variable [κ.IsCondKernel κCond] lemma disintegrate : κ.fst ⊗ₖ κCond = κ := IsCondKernel.disintegrate /-! #### Existence of a disintegrating kernel in a countable space -/ section Countable variable [Countable α] (κCond : α → Kernel β Ω) /-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`. A conditional kernel for `κ : Kernel α (β × Ω)` where `α` is countable and `Ω` is a measurable space. -/ noncomputable def condKernelCountable (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) : Kernel (α × β) Ω where toFun p := κCond p.1 p.2 measurable' := by change Measurable ((fun q : β × α ↦ (κCond q.2) q.1) ∘ Prod.swap) refine (measurable_from_prod_countable' (fun a ↦ (κCond a).measurable) ?_).comp measurable_swap · intro x y hx hy simpa using DFunLike.congr (h_atom _ _ hy) rfl lemma condKernelCountable_apply (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) (p : α × β) : condKernelCountable κCond h_atom p = κCond p.1 p.2 := rfl instance condKernelCountable.instIsMarkovKernel [∀ a, IsMarkovKernel (κCond a)] (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) : IsMarkovKernel (condKernelCountable κCond h_atom) where isProbabilityMeasure p := (‹∀ a, IsMarkovKernel (κCond a)› p.1).isProbabilityMeasure p.2 instance condKernelCountable.instIsCondKernel [∀ a, IsMarkovKernel (κCond a)] (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) (κ : Kernel α (β × Ω)) [IsSFiniteKernel κ] [∀ a, (κ a).IsCondKernel (κCond a)] : κ.IsCondKernel (condKernelCountable κCond h_atom) := by constructor ext a s hs conv_rhs => rw [← (κ a).disintegrate (κCond a)] simp_rw [compProd_apply _ _ _ hs, condKernelCountable_apply, Measure.compProd_apply hs] congr end Countable end ProbabilityTheory.Kernel
Probability\Kernel\Disintegration\CDFToKernel.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.Function.AEEqOfIntegral import Mathlib.Probability.Kernel.Composition import Mathlib.Probability.Kernel.Disintegration.MeasurableStieltjes /-! # Building a Markov kernel from a conditional cumulative distribution function Let `κ : Kernel α (β × ℝ)` and `ν : Kernel α β` be two finite kernels. A function `f : α × β → StieltjesFunction` is called a conditional kernel CDF of `κ` with respect to `ν` if it is measurable, tends to to 0 at -∞ and to 1 at +∞ for all `p : α × β`, `fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ` and for all measurable sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a (s ×ˢ Iic x)).toReal`. From such a function with property `hf : IsCondKernelCDF f κ ν`, we can build a `Kernel (α × β) ℝ` denoted by `hf.toKernel f` such that `κ = ν ⊗ₖ hf.toKernel f`. ## Main definitions Let `κ : Kernel α (β × ℝ)` and `ν : Kernel α β`. * `ProbabilityTheory.IsCondKernelCDF`: a function `f : α × β → StieltjesFunction` is called a conditional kernel CDF of `κ` with respect to `ν` if it is measurable, tends to to 0 at -∞ and to 1 at +∞ for all `p : α × β`, if `fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ` and for all measurable sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a (s ×ˢ Iic x)).toReal`. * `ProbabilityTheory.IsCondKernelCDF.toKernel`: from a function `f : α × β → StieltjesFunction` with the property `hf : IsCondKernelCDF f κ ν`, build a `Kernel (α × β) ℝ` such that `κ = ν ⊗ₖ hf.toKernel f`. * `ProbabilityTheory.IsRatCondKernelCDF`: a function `f : α × β → ℚ → ℝ` is called a rational conditional kernel CDF of `κ` with respect to `ν` if is measurable and satisfies the same integral conditions as in the definition of `IsCondKernelCDF`, and the `ℚ → ℝ` function `f (a, b)` satisfies the properties of a Stieltjes function for `(ν a)`-almost all `b : β`. ## Main statements * `ProbabilityTheory.isCondKernelCDF_stieltjesOfMeasurableRat`: if `f : α × β → ℚ → ℝ` has the property `IsRatCondKernelCDF`, then `stieltjesOfMeasurableRat f` is a function `α × β → StieltjesFunction` with the property `IsCondKernelCDF`. * `ProbabilityTheory.compProd_toKernel`: for `hf : IsCondKernelCDF f κ ν`, `ν ⊗ₖ hf.toKernel f = κ`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory variable {α β : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {κ : Kernel α (β × ℝ)} {ν : Kernel α β} section stieltjesOfMeasurableRat variable {f : α × β → ℚ → ℝ} /-- a function `f : α × β → ℚ → ℝ` is called a rational conditional kernel CDF of `κ` with respect to `ν` if is measurable, if `fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ` and for all measurable sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a (s ×ˢ Iic x)).toReal`. Also the `ℚ → ℝ` function `f (a, b)` should satisfy the properties of a Sieltjes function for `(ν a)`-almost all `b : β`. -/ structure IsRatCondKernelCDF (f : α × β → ℚ → ℝ) (κ : Kernel α (β × ℝ)) (ν : Kernel α β) : Prop := measurable : Measurable f isRatStieltjesPoint_ae (a : α) : ∀ᵐ b ∂(ν a), IsRatStieltjesPoint f (a, b) integrable (a : α) (q : ℚ) : Integrable (fun b ↦ f (a, b) q) (ν a) setIntegral (a : α) {s : Set β} (_hs : MeasurableSet s) (q : ℚ) : ∫ b in s, f (a, b) q ∂(ν a) = (κ a (s ×ˢ Iic (q : ℝ))).toReal lemma IsRatCondKernelCDF.mono (hf : IsRatCondKernelCDF f κ ν) (a : α) : ∀ᵐ b ∂(ν a), Monotone (f (a, b)) := by filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.mono lemma IsRatCondKernelCDF.tendsto_atTop_one (hf : IsRatCondKernelCDF f κ ν) (a : α) : ∀ᵐ b ∂(ν a), Tendsto (f (a, b)) atTop (𝓝 1) := by filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.tendsto_atTop_one lemma IsRatCondKernelCDF.tendsto_atBot_zero (hf : IsRatCondKernelCDF f κ ν) (a : α) : ∀ᵐ b ∂(ν a), Tendsto (f (a, b)) atBot (𝓝 0) := by filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.tendsto_atBot_zero lemma IsRatCondKernelCDF.iInf_rat_gt_eq (hf : IsRatCondKernelCDF f κ ν) (a : α) : ∀ᵐ b ∂(ν a), ∀ q, ⨅ r : Ioi q, f (a, b) r = f (a, b) q := by filter_upwards [hf.isRatStieltjesPoint_ae a] with b hb using hb.iInf_rat_gt_eq lemma stieltjesOfMeasurableRat_ae_eq (hf : IsRatCondKernelCDF f κ ν) (a : α) (q : ℚ) : (fun b ↦ stieltjesOfMeasurableRat f hf.measurable (a, b) q) =ᵐ[ν a] fun b ↦ f (a, b) q := by filter_upwards [hf.isRatStieltjesPoint_ae a] with a ha rw [stieltjesOfMeasurableRat_eq, toRatCDF_of_isRatStieltjesPoint ha] lemma setIntegral_stieltjesOfMeasurableRat_rat (hf : IsRatCondKernelCDF f κ ν) (a : α) (q : ℚ) {s : Set β} (hs : MeasurableSet s) : ∫ b in s, stieltjesOfMeasurableRat f hf.measurable (a, b) q ∂(ν a) = (κ a (s ×ˢ Iic (q : ℝ))).toReal := by rw [setIntegral_congr_ae hs (g := fun b ↦ f (a, b) q) ?_, hf.setIntegral a hs] filter_upwards [stieltjesOfMeasurableRat_ae_eq hf a q] with b hb using fun _ ↦ hb @[deprecated (since := "2024-04-17")] alias set_integral_stieltjesOfMeasurableRat_rat := setIntegral_stieltjesOfMeasurableRat_rat lemma setLIntegral_stieltjesOfMeasurableRat_rat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν) (a : α) (q : ℚ) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) q) ∂(ν a) = κ a (s ×ˢ Iic (q : ℝ)) := by rw [← ofReal_integral_eq_lintegral_ofReal] · rw [setIntegral_stieltjesOfMeasurableRat_rat hf a q hs, ENNReal.ofReal_toReal] exact measure_ne_top _ _ · refine Integrable.restrict ?_ rw [integrable_congr (stieltjesOfMeasurableRat_ae_eq hf a q)] exact hf.integrable a q · exact ae_of_all _ (fun x ↦ stieltjesOfMeasurableRat_nonneg _ _ _) @[deprecated (since := "2024-06-29")] alias set_lintegral_stieltjesOfMeasurableRat_rat := setLIntegral_stieltjesOfMeasurableRat_rat lemma setLIntegral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν) (a : α) (x : ℝ) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x) ∂(ν a) = κ a (s ×ˢ Iic x) := by -- We have the result for `x : ℚ` thanks to `setLIntegral_stieltjesOfMeasurableRat_rat`. -- We use a monotone convergence argument to extend it to the reals. by_cases hρ_zero : (ν a).restrict s = 0 · rw [hρ_zero, lintegral_zero_measure] have ⟨q, hq⟩ := exists_rat_gt x suffices κ a (s ×ˢ Iic (q : ℝ)) = 0 by symm refine measure_mono_null (fun p ↦ ?_) this simp only [mem_prod, mem_Iic, and_imp] exact fun h1 h2 ↦ ⟨h1, h2.trans hq.le⟩ suffices (κ a (s ×ˢ Iic (q : ℝ))).toReal = 0 by rw [ENNReal.toReal_eq_zero_iff] at this simpa [measure_ne_top] using this rw [← hf.setIntegral a hs q] simp [hρ_zero] have h : ∫⁻ b in s, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x) ∂(ν a) = ∫⁻ b in s, ⨅ r : { r' : ℚ // x < r' }, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) r) ∂(ν a) := by congr with b : 1 simp_rw [← measure_stieltjesOfMeasurableRat_Iic] rw [← measure_iInter_eq_iInf] · congr with y : 1 simp only [mem_Iic, mem_iInter, Subtype.forall] refine ⟨fun h a ha ↦ h.trans ?_, fun h ↦ ?_⟩ · exact mod_cast ha.le · refine le_of_forall_lt_rat_imp_le fun q hq ↦ h q ?_ exact mod_cast hq · exact fun _ ↦ measurableSet_Iic · refine Monotone.directed_ge fun r r' hrr' ↦ Iic_subset_Iic.mpr ?_ exact mod_cast hrr' · obtain ⟨q, hq⟩ := exists_rat_gt x exact ⟨⟨q, hq⟩, measure_ne_top _ _⟩ have h_nonempty : Nonempty { r' : ℚ // x < ↑r' } := by obtain ⟨r, hrx⟩ := exists_rat_gt x exact ⟨⟨r, hrx⟩⟩ rw [h, lintegral_iInf_directed_of_measurable hρ_zero fun q : { r' : ℚ // x < ↑r' } ↦ ?_] rotate_left · intro b rw [setLIntegral_stieltjesOfMeasurableRat_rat hf a _ hs] exact measure_ne_top _ _ · refine Monotone.directed_ge fun i j hij b ↦ ?_ simp_rw [← measure_stieltjesOfMeasurableRat_Iic] refine measure_mono (Iic_subset_Iic.mpr ?_) exact mod_cast hij · refine Measurable.ennreal_ofReal ?_ exact (measurable_stieltjesOfMeasurableRat hf.measurable _).comp measurable_prod_mk_left simp_rw [setLIntegral_stieltjesOfMeasurableRat_rat hf _ _ hs] rw [← measure_iInter_eq_iInf] · rw [← prod_iInter] congr with y simp only [mem_iInter, mem_Iic, Subtype.forall, Subtype.coe_mk] exact ⟨le_of_forall_lt_rat_imp_le, fun hyx q hq ↦ hyx.trans hq.le⟩ · exact fun i ↦ hs.prod measurableSet_Iic · refine Monotone.directed_ge fun i j hij ↦ ?_ refine prod_subset_prod_iff.mpr (Or.inl ⟨subset_rfl, Iic_subset_Iic.mpr ?_⟩) exact mod_cast hij · exact ⟨h_nonempty.some, measure_ne_top _ _⟩ @[deprecated (since := "2024-06-29")] alias set_lintegral_stieltjesOfMeasurableRat := setLIntegral_stieltjesOfMeasurableRat lemma lintegral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν) (a : α) (x : ℝ) : ∫⁻ b, ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x) ∂(ν a) = κ a (univ ×ˢ Iic x) := by rw [← setLIntegral_univ, setLIntegral_stieltjesOfMeasurableRat hf _ _ MeasurableSet.univ] lemma integrable_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν) (a : α) (x : ℝ) : Integrable (fun b ↦ stieltjesOfMeasurableRat f hf.measurable (a, b) x) (ν a) := by have : (fun b ↦ stieltjesOfMeasurableRat f hf.measurable (a, b) x) = fun b ↦ (ENNReal.ofReal (stieltjesOfMeasurableRat f hf.measurable (a, b) x)).toReal := by ext t rw [ENNReal.toReal_ofReal] exact stieltjesOfMeasurableRat_nonneg _ _ _ rw [this] refine integrable_toReal_of_lintegral_ne_top ?_ ?_ · refine (Measurable.ennreal_ofReal ?_).aemeasurable exact (measurable_stieltjesOfMeasurableRat hf.measurable x).comp measurable_prod_mk_left · rw [lintegral_stieltjesOfMeasurableRat hf] exact measure_ne_top _ _ lemma setIntegral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν) (a : α) (x : ℝ) {s : Set β} (hs : MeasurableSet s) : ∫ b in s, stieltjesOfMeasurableRat f hf.measurable (a, b) x ∂(ν a) = (κ a (s ×ˢ Iic x)).toReal := by rw [← ENNReal.ofReal_eq_ofReal_iff, ENNReal.ofReal_toReal] rotate_left · exact measure_ne_top _ _ · exact setIntegral_nonneg hs (fun _ _ ↦ stieltjesOfMeasurableRat_nonneg _ _ _) · exact ENNReal.toReal_nonneg rw [ofReal_integral_eq_lintegral_ofReal, setLIntegral_stieltjesOfMeasurableRat hf _ _ hs] · exact (integrable_stieltjesOfMeasurableRat hf _ _).restrict · exact ae_of_all _ (fun _ ↦ stieltjesOfMeasurableRat_nonneg _ _ _) @[deprecated (since := "2024-04-17")] alias set_integral_stieltjesOfMeasurableRat := setIntegral_stieltjesOfMeasurableRat lemma integral_stieltjesOfMeasurableRat [IsFiniteKernel κ] (hf : IsRatCondKernelCDF f κ ν) (a : α) (x : ℝ) : ∫ b, stieltjesOfMeasurableRat f hf.measurable (a, b) x ∂(ν a) = (κ a (univ ×ˢ Iic x)).toReal := by rw [← integral_univ, setIntegral_stieltjesOfMeasurableRat hf _ _ MeasurableSet.univ] end stieltjesOfMeasurableRat section isRatCondKernelCDFAux variable {f : α × β → ℚ → ℝ} /-- This property implies `IsRatCondKernelCDF`. The measurability, integrability and integral conditions are the same, but the limit properties of `IsRatCondKernelCDF` are replaced by limits of integrals. -/ structure IsRatCondKernelCDFAux (f : α × β → ℚ → ℝ) (κ : Kernel α (β × ℝ)) (ν : Kernel α β) : Prop := measurable : Measurable f mono' (a : α) {q r : ℚ} (_hqr : q ≤ r) : ∀ᵐ c ∂(ν a), f (a, c) q ≤ f (a, c) r nonneg' (a : α) (q : ℚ) : ∀ᵐ c ∂(ν a), 0 ≤ f (a, c) q le_one' (a : α) (q : ℚ) : ∀ᵐ c ∂(ν a), f (a, c) q ≤ 1 /- Same as `Tendsto (fun q : ℚ ↦ ∫ c, f (a, c) q ∂(ν a)) atBot (𝓝 0)` but slightly easier to prove in the current applications of this definition (some integral convergence lemmas currently apply only to `ℕ`, not `ℚ`) -/ tendsto_integral_of_antitone (a : α) (seq : ℕ → ℚ) (_hs : Antitone seq) (_hs_tendsto : Tendsto seq atTop atBot) : Tendsto (fun m ↦ ∫ c, f (a, c) (seq m) ∂(ν a)) atTop (𝓝 0) /- Same as `Tendsto (fun q : ℚ ↦ ∫ c, f (a, c) q ∂(ν a)) atTop (𝓝 (ν a univ).toReal)` but slightly easier to prove in the current applications of this definition (some integral convergence lemmas currently apply only to `ℕ`, not `ℚ`) -/ tendsto_integral_of_monotone (a : α) (seq : ℕ → ℚ) (_hs : Monotone seq) (_hs_tendsto : Tendsto seq atTop atTop) : Tendsto (fun m ↦ ∫ c, f (a, c) (seq m) ∂(ν a)) atTop (𝓝 (ν a univ).toReal) integrable (a : α) (q : ℚ) : Integrable (fun c ↦ f (a, c) q) (ν a) setIntegral (a : α) {A : Set β} (_hA : MeasurableSet A) (q : ℚ) : ∫ c in A, f (a, c) q ∂(ν a) = (κ a (A ×ˢ Iic ↑q)).toReal lemma IsRatCondKernelCDFAux.measurable_right (hf : IsRatCondKernelCDFAux f κ ν) (a : α) (q : ℚ) : Measurable (fun t ↦ f (a, t) q) := by let h := hf.measurable rw [measurable_pi_iff] at h exact (h q).comp measurable_prod_mk_left lemma IsRatCondKernelCDFAux.mono (hf : IsRatCondKernelCDFAux f κ ν) (a : α) : ∀ᵐ c ∂(ν a), Monotone (f (a, c)) := by unfold Monotone simp_rw [ae_all_iff] exact fun _ _ hqr ↦ hf.mono' a hqr lemma IsRatCondKernelCDFAux.nonneg (hf : IsRatCondKernelCDFAux f κ ν) (a : α) : ∀ᵐ c ∂(ν a), ∀ q, 0 ≤ f (a, c) q := ae_all_iff.mpr <| hf.nonneg' a lemma IsRatCondKernelCDFAux.le_one (hf : IsRatCondKernelCDFAux f κ ν) (a : α) : ∀ᵐ c ∂(ν a), ∀ q, f (a, c) q ≤ 1 := ae_all_iff.mpr <| hf.le_one' a lemma IsRatCondKernelCDFAux.tendsto_zero_of_antitone (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν] (a : α) (seq : ℕ → ℚ) (hseq : Antitone seq) (hseq_tendsto : Tendsto seq atTop atBot) : ∀ᵐ c ∂(ν a), Tendsto (fun m ↦ f (a, c) (seq m)) atTop (𝓝 0) := by refine tendsto_of_integral_tendsto_of_antitone ?_ (integrable_const _) ?_ ?_ ?_ · exact fun n ↦ hf.integrable a (seq n) · rw [integral_zero] exact hf.tendsto_integral_of_antitone a seq hseq hseq_tendsto · filter_upwards [hf.mono a] with t ht using fun n m hnm ↦ ht (hseq hnm) · filter_upwards [hf.nonneg a] with c hc using fun i ↦ hc (seq i) lemma IsRatCondKernelCDFAux.tendsto_one_of_monotone (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν] (a : α) (seq : ℕ → ℚ) (hseq : Monotone seq) (hseq_tendsto : Tendsto seq atTop atTop) : ∀ᵐ c ∂(ν a), Tendsto (fun m ↦ f (a, c) (seq m)) atTop (𝓝 1) := by refine tendsto_of_integral_tendsto_of_monotone ?_ (integrable_const _) ?_ ?_ ?_ · exact fun n ↦ hf.integrable a (seq n) · rw [MeasureTheory.integral_const, smul_eq_mul, mul_one] exact hf.tendsto_integral_of_monotone a seq hseq hseq_tendsto · filter_upwards [hf.mono a] with t ht using fun n m hnm ↦ ht (hseq hnm) · filter_upwards [hf.le_one a] with c hc using fun i ↦ hc (seq i) lemma IsRatCondKernelCDFAux.tendsto_atTop_one (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν] (a : α) : ∀ᵐ t ∂(ν a), Tendsto (f (a, t)) atTop (𝓝 1) := by suffices ∀ᵐ t ∂(ν a), Tendsto (fun (n : ℕ) ↦ f (a, t) n) atTop (𝓝 1) by filter_upwards [this, hf.mono a] with t ht h_mono rw [tendsto_iff_tendsto_subseq_of_monotone h_mono tendsto_natCast_atTop_atTop] exact ht filter_upwards [hf.tendsto_one_of_monotone a Nat.cast Nat.mono_cast tendsto_natCast_atTop_atTop] with x hx using hx lemma IsRatCondKernelCDFAux.tendsto_atBot_zero (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν] (a : α) : ∀ᵐ t ∂(ν a), Tendsto (f (a, t)) atBot (𝓝 0) := by suffices ∀ᵐ t ∂(ν a), Tendsto (fun q : ℚ ↦ f (a, t) (-q)) atTop (𝓝 0) by filter_upwards [this] with t ht have h_eq_neg : f (a, t) = fun q : ℚ ↦ f (a, t) (- -q) := by simp_rw [neg_neg] rw [h_eq_neg] convert ht.comp tendsto_neg_atBot_atTop simp suffices ∀ᵐ t ∂(ν a), Tendsto (fun (n : ℕ) ↦ f (a, t) (-n)) atTop (𝓝 0) by filter_upwards [this, hf.mono a] with t ht h_mono have h_anti : Antitone (fun q ↦ f (a, t) (-q)) := h_mono.comp_antitone monotone_id.neg exact (tendsto_iff_tendsto_subseq_of_antitone h_anti tendsto_natCast_atTop_atTop).mpr ht exact hf.tendsto_zero_of_antitone _ _ Nat.mono_cast.neg (tendsto_neg_atBot_iff.mpr tendsto_natCast_atTop_atTop) lemma IsRatCondKernelCDFAux.bddBelow_range (hf : IsRatCondKernelCDFAux f κ ν) (a : α) : ∀ᵐ t ∂(ν a), ∀ q : ℚ, BddBelow (range fun (r : Ioi q) ↦ f (a, t) r) := by filter_upwards [hf.nonneg a] with c hc refine fun q ↦ ⟨0, ?_⟩ simp [mem_lowerBounds, hc] lemma IsRatCondKernelCDFAux.integrable_iInf_rat_gt (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel ν] (a : α) (q : ℚ) : Integrable (fun t ↦ ⨅ r : Ioi q, f (a, t) r) (ν a) := by rw [← memℒp_one_iff_integrable] refine ⟨(measurable_iInf fun i ↦ hf.measurable_right a _).aestronglyMeasurable, ?_⟩ refine (?_ : _ ≤ (ν a univ : ℝ≥0∞)).trans_lt (measure_lt_top _ _) refine (eLpNorm_le_of_ae_bound (C := 1) ?_).trans (by simp) filter_upwards [hf.bddBelow_range a, hf.nonneg a, hf.le_one a] with t hbdd_below h_nonneg h_le_one rw [Real.norm_eq_abs, abs_of_nonneg] · refine ciInf_le_of_le ?_ ?_ ?_ · exact hbdd_below _ · exact ⟨q + 1, by simp⟩ · exact h_le_one _ · exact le_ciInf fun r ↦ h_nonneg _ lemma _root_.MeasureTheory.Measure.iInf_rat_gt_prod_Iic {ρ : Measure (α × ℝ)} [IsFiniteMeasure ρ] {s : Set α} (hs : MeasurableSet s) (t : ℚ) : ⨅ r : { r' : ℚ // t < r' }, ρ (s ×ˢ Iic (r : ℝ)) = ρ (s ×ˢ Iic (t : ℝ)) := by rw [← measure_iInter_eq_iInf] · rw [← prod_iInter] congr with x : 1 simp only [mem_iInter, mem_Iic, Subtype.forall, Subtype.coe_mk] refine ⟨fun h ↦ ?_, fun h a hta ↦ h.trans ?_⟩ · refine le_of_forall_lt_rat_imp_le fun q htq ↦ h q ?_ exact mod_cast htq · exact mod_cast hta.le · exact fun _ => hs.prod measurableSet_Iic · refine Monotone.directed_ge fun r r' hrr' ↦ prod_subset_prod_iff.mpr (Or.inl ⟨subset_rfl, ?_⟩) refine Iic_subset_Iic.mpr ?_ exact mod_cast hrr' · exact ⟨⟨t + 1, lt_add_one _⟩, measure_ne_top ρ _⟩ lemma IsRatCondKernelCDFAux.setIntegral_iInf_rat_gt (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel κ] [IsFiniteKernel ν] (a : α) (q : ℚ) {A : Set β} (hA : MeasurableSet A) : ∫ t in A, ⨅ r : Ioi q, f (a, t) r ∂(ν a) = (κ a (A ×ˢ Iic (q : ℝ))).toReal := by refine le_antisymm ?_ ?_ · have h : ∀ r : Ioi q, ∫ t in A, ⨅ r' : Ioi q, f (a, t) r' ∂(ν a) ≤ (κ a (A ×ˢ Iic (r : ℝ))).toReal := by intro r rw [← hf.setIntegral a hA] refine setIntegral_mono_ae ?_ ?_ ?_ · exact (hf.integrable_iInf_rat_gt _ _).integrableOn · exact (hf.integrable _ _).integrableOn · filter_upwards [hf.bddBelow_range a] with t ht using ciInf_le (ht _) r calc ∫ t in A, ⨅ r : Ioi q, f (a, t) r ∂(ν a) ≤ ⨅ r : Ioi q, (κ a (A ×ˢ Iic (r : ℝ))).toReal := le_ciInf h _ = (κ a (A ×ˢ Iic (q : ℝ))).toReal := by rw [← Measure.iInf_rat_gt_prod_Iic hA q] exact (ENNReal.toReal_iInf (fun r ↦ measure_ne_top _ _)).symm · rw [← hf.setIntegral a hA] refine setIntegral_mono_ae ?_ ?_ ?_ · exact (hf.integrable _ _).integrableOn · exact (hf.integrable_iInf_rat_gt _ _).integrableOn · filter_upwards [hf.mono a] with c h_mono using le_ciInf (fun r ↦ h_mono (le_of_lt r.prop)) @[deprecated (since := "2024-04-17")] alias IsRatCondKernelCDFAux.set_integral_iInf_rat_gt := IsRatCondKernelCDFAux.setIntegral_iInf_rat_gt lemma IsRatCondKernelCDFAux.iInf_rat_gt_eq (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel κ] [IsFiniteKernel ν] (a : α) : ∀ᵐ t ∂(ν a), ∀ q : ℚ, ⨅ r : Ioi q, f (a, t) r = f (a, t) q := by rw [ae_all_iff] refine fun q ↦ ae_eq_of_forall_setIntegral_eq_of_sigmaFinite (μ := ν a) ?_ ?_ ?_ · exact fun _ _ _ ↦ (hf.integrable_iInf_rat_gt _ _).integrableOn · exact fun _ _ _ ↦ (hf.integrable a _).integrableOn · intro s hs _ rw [hf.setIntegral _ hs, hf.setIntegral_iInf_rat_gt _ _ hs] lemma IsRatCondKernelCDFAux.isRatStieltjesPoint_ae (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel κ] [IsFiniteKernel ν] (a : α) : ∀ᵐ t ∂(ν a), IsRatStieltjesPoint f (a, t) := by filter_upwards [hf.tendsto_atTop_one a, hf.tendsto_atBot_zero a, hf.iInf_rat_gt_eq a, hf.mono a] with t ht_top ht_bot ht_iInf h_mono exact ⟨h_mono, ht_top, ht_bot, ht_iInf⟩ lemma IsRatCondKernelCDFAux.isRatCondKernelCDF (hf : IsRatCondKernelCDFAux f κ ν) [IsFiniteKernel κ] [IsFiniteKernel ν] : IsRatCondKernelCDF f κ ν where measurable := hf.measurable isRatStieltjesPoint_ae := hf.isRatStieltjesPoint_ae integrable := hf.integrable setIntegral := hf.setIntegral end isRatCondKernelCDFAux section IsCondKernelCDF variable {f : α × β → StieltjesFunction} /-- A function `f : α × β → StieltjesFunction` is called a conditional kernel CDF of `κ` with respect to `ν` if it is measurable, tends to to 0 at -∞ and to 1 at +∞ for all `p : α × β`, `fun b ↦ f (a, b) x` is `(ν a)`-integrable for all `a : α` and `x : ℝ` and for all measurable sets `s : Set β`, `∫ b in s, f (a, b) x ∂(ν a) = (κ a (s ×ˢ Iic x)).toReal`. -/ structure IsCondKernelCDF (f : α × β → StieltjesFunction) (κ : Kernel α (β × ℝ)) (ν : Kernel α β) : Prop := measurable (x : ℝ) : Measurable fun p ↦ f p x integrable (a : α) (x : ℝ) : Integrable (fun b ↦ f (a, b) x) (ν a) tendsto_atTop_one (p : α × β) : Tendsto (f p) atTop (𝓝 1) tendsto_atBot_zero (p : α × β) : Tendsto (f p) atBot (𝓝 0) setIntegral (a : α) {s : Set β} (_hs : MeasurableSet s) (x : ℝ) : ∫ b in s, f (a, b) x ∂(ν a) = (κ a (s ×ˢ Iic x)).toReal lemma IsCondKernelCDF.nonneg (hf : IsCondKernelCDF f κ ν) (p : α × β) (x : ℝ) : 0 ≤ f p x := Monotone.le_of_tendsto (f p).mono (hf.tendsto_atBot_zero p) x lemma IsCondKernelCDF.le_one (hf : IsCondKernelCDF f κ ν) (p : α × β) (x : ℝ) : f p x ≤ 1 := Monotone.ge_of_tendsto (f p).mono (hf.tendsto_atTop_one p) x lemma IsCondKernelCDF.integral {f : α × β → StieltjesFunction} (hf : IsCondKernelCDF f κ ν) (a : α) (x : ℝ) : ∫ b, f (a, b) x ∂(ν a) = (κ a (univ ×ˢ Iic x)).toReal := by rw [← hf.setIntegral _ MeasurableSet.univ, Measure.restrict_univ] lemma IsCondKernelCDF.setLIntegral [IsFiniteKernel κ] {f : α × β → StieltjesFunction} (hf : IsCondKernelCDF f κ ν) (a : α) {s : Set β} (hs : MeasurableSet s) (x : ℝ) : ∫⁻ b in s, ENNReal.ofReal (f (a, b) x) ∂(ν a) = κ a (s ×ˢ Iic x) := by rw [← ofReal_integral_eq_lintegral_ofReal (hf.integrable a x).restrict (ae_of_all _ (fun _ ↦ hf.nonneg _ _)), hf.setIntegral a hs x, ENNReal.ofReal_toReal] exact measure_ne_top _ _ @[deprecated (since := "2024-06-29")] alias IsCondKernelCDF.set_lintegral := IsCondKernelCDF.setLIntegral lemma IsCondKernelCDF.lintegral [IsFiniteKernel κ] {f : α × β → StieltjesFunction} (hf : IsCondKernelCDF f κ ν) (a : α) (x : ℝ) : ∫⁻ b, ENNReal.ofReal (f (a, b) x) ∂(ν a) = κ a (univ ×ˢ Iic x) := by rw [← hf.setLIntegral _ MeasurableSet.univ, Measure.restrict_univ] lemma isCondKernelCDF_stieltjesOfMeasurableRat {f : α × β → ℚ → ℝ} (hf : IsRatCondKernelCDF f κ ν) [IsFiniteKernel κ] : IsCondKernelCDF (stieltjesOfMeasurableRat f hf.measurable) κ ν where measurable := measurable_stieltjesOfMeasurableRat hf.measurable integrable := integrable_stieltjesOfMeasurableRat hf tendsto_atTop_one := tendsto_stieltjesOfMeasurableRat_atTop hf.measurable tendsto_atBot_zero := tendsto_stieltjesOfMeasurableRat_atBot hf.measurable setIntegral a _ hs x := setIntegral_stieltjesOfMeasurableRat hf a x hs end IsCondKernelCDF section ToKernel variable {_ : MeasurableSpace β} {f : α × β → StieltjesFunction} {κ : Kernel α (β × ℝ)} {ν : Kernel α β} /-- A measurable function `α → StieltjesFunction` with limits 0 at -∞ and 1 at +∞ gives a measurable function `α → Measure ℝ` by taking `StieltjesFunction.measure` at each point. -/ lemma StieltjesFunction.measurable_measure {f : α → StieltjesFunction} (hf : ∀ q, Measurable fun a ↦ f a q) (hf_bot : ∀ a, Tendsto (f a) atBot (𝓝 0)) (hf_top : ∀ a, Tendsto (f a) atTop (𝓝 1)) : Measurable fun a ↦ (f a).measure := by refine Measure.measurable_measure.mpr fun s hs ↦ ?_ have : ∀ a, IsProbabilityMeasure (f a).measure := fun a ↦ (f a).isProbabilityMeasure (hf_bot a) (hf_top a) refine MeasurableSpace.induction_on_inter (C := fun s ↦ Measurable fun b ↦ StieltjesFunction.measure (f b) s) (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic ?_ ?_ ?_ ?_ hs · simp only [measure_empty, measurable_const] · rintro S ⟨u, rfl⟩ simp_rw [StieltjesFunction.measure_Iic (f _) (hf_bot _), sub_zero] exact (hf _).ennreal_ofReal · intro t ht ht_cd_meas have : (fun a ↦ (f a).measure tᶜ) = (fun a ↦ (f a).measure univ) - fun a ↦ (f a).measure t := by ext1 a rw [measure_compl ht, Pi.sub_apply] exact measure_ne_top _ _ simp_rw [this, measure_univ] exact Measurable.sub measurable_const ht_cd_meas · intro f hf_disj hf_meas hf_cd_meas simp_rw [measure_iUnion hf_disj hf_meas] exact Measurable.ennreal_tsum hf_cd_meas /-- A function `f : α × β → StieltjesFunction` with the property `IsCondKernelCDF f κ ν` gives a Markov kernel from `α × β` to `ℝ`, by taking for each `p : α × β` the measure defined by `f p`. -/ noncomputable def IsCondKernelCDF.toKernel (f : α × β → StieltjesFunction) (hf : IsCondKernelCDF f κ ν) : Kernel (α × β) ℝ where toFun p := (f p).measure measurable' := StieltjesFunction.measurable_measure hf.measurable hf.tendsto_atBot_zero hf.tendsto_atTop_one lemma IsCondKernelCDF.toKernel_apply {hf : IsCondKernelCDF f κ ν} (p : α × β) : hf.toKernel f p = (f p).measure := rfl instance instIsMarkovKernel_toKernel {hf : IsCondKernelCDF f κ ν} : IsMarkovKernel (hf.toKernel f) := ⟨fun _ ↦ (f _).isProbabilityMeasure (hf.tendsto_atBot_zero _) (hf.tendsto_atTop_one _)⟩ lemma IsCondKernelCDF.toKernel_Iic {hf : IsCondKernelCDF f κ ν} (p : α × β) (x : ℝ) : hf.toKernel f p (Iic x) = ENNReal.ofReal (f p x) := by rw [IsCondKernelCDF.toKernel_apply p, (f p).measure_Iic (hf.tendsto_atBot_zero p)] simp end ToKernel section variable {f : α × β → StieltjesFunction} lemma setLIntegral_toKernel_Iic [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν) (a : α) (x : ℝ) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, hf.toKernel f (a, b) (Iic x) ∂(ν a) = κ a (s ×ˢ Iic x) := by simp_rw [IsCondKernelCDF.toKernel_Iic] exact hf.setLIntegral _ hs _ @[deprecated (since := "2024-06-29")] alias set_lintegral_toKernel_Iic := setLIntegral_toKernel_Iic lemma setLIntegral_toKernel_univ [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν) (a : α) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, hf.toKernel f (a, b) univ ∂(ν a) = κ a (s ×ˢ univ) := by rw [← Real.iUnion_Iic_rat, prod_iUnion] have h_dir : Directed (fun x y ↦ x ⊆ y) fun q : ℚ ↦ Iic (q : ℝ) := by refine Monotone.directed_le fun r r' hrr' ↦ Iic_subset_Iic.mpr ?_ exact mod_cast hrr' have h_dir_prod : Directed (fun x y ↦ x ⊆ y) fun q : ℚ ↦ s ×ˢ Iic (q : ℝ) := by refine Monotone.directed_le fun i j hij ↦ ?_ refine prod_subset_prod_iff.mpr (Or.inl ⟨subset_rfl, Iic_subset_Iic.mpr ?_⟩) exact mod_cast hij simp_rw [measure_iUnion_eq_iSup h_dir, measure_iUnion_eq_iSup h_dir_prod] rw [lintegral_iSup_directed] · simp_rw [setLIntegral_toKernel_Iic hf _ _ hs] · refine fun q ↦ Measurable.aemeasurable ?_ exact (Kernel.measurable_coe _ measurableSet_Iic).comp measurable_prod_mk_left · refine Monotone.directed_le fun i j hij t ↦ measure_mono (Iic_subset_Iic.mpr ?_) exact mod_cast hij @[deprecated (since := "2024-06-29")] alias set_lintegral_toKernel_univ := setLIntegral_toKernel_univ lemma lintegral_toKernel_univ [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν) (a : α) : ∫⁻ b, hf.toKernel f (a, b) univ ∂(ν a) = κ a univ := by rw [← setLIntegral_univ, setLIntegral_toKernel_univ hf a MeasurableSet.univ, univ_prod_univ] lemma setLIntegral_toKernel_prod [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν) (a : α) {s : Set β} (hs : MeasurableSet s) {t : Set ℝ} (ht : MeasurableSet t) : ∫⁻ b in s, hf.toKernel f (a, b) t ∂(ν a) = κ a (s ×ˢ t) := by -- `setLIntegral_toKernel_Iic` gives the result for `t = Iic x`. These sets form a -- π-system that generates the Borel σ-algebra, hence we can get the same equality for any -- measurable set `t`. apply MeasurableSpace.induction_on_inter (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic _ _ _ _ ht · simp only [measure_empty, lintegral_const, zero_mul, prod_empty] · rintro t ⟨q, rfl⟩ exact setLIntegral_toKernel_Iic hf a _ hs · intro t ht ht_lintegral calc ∫⁻ b in s, hf.toKernel f (a, b) tᶜ ∂(ν a) = ∫⁻ b in s, hf.toKernel f (a, b) univ - hf.toKernel f (a, b) t ∂(ν a) := by congr with x; rw [measure_compl ht (measure_ne_top (hf.toKernel f (a, x)) _)] _ = ∫⁻ b in s, hf.toKernel f (a, b) univ ∂(ν a) - ∫⁻ b in s, hf.toKernel f (a, b) t ∂(ν a) := by rw [lintegral_sub] · exact (Kernel.measurable_coe (hf.toKernel f) ht).comp measurable_prod_mk_left · rw [ht_lintegral] exact measure_ne_top _ _ · exact eventually_of_forall fun a ↦ measure_mono (subset_univ _) _ = κ a (s ×ˢ univ) - κ a (s ×ˢ t) := by rw [setLIntegral_toKernel_univ hf a hs, ht_lintegral] _ = κ a (s ×ˢ tᶜ) := by rw [← measure_diff _ (hs.prod ht) (measure_ne_top _ _)] · rw [prod_diff_prod, compl_eq_univ_diff] simp only [diff_self, empty_prod, union_empty] · rw [prod_subset_prod_iff] exact Or.inl ⟨subset_rfl, subset_univ t⟩ · intro f hf_disj hf_meas hf_eq simp_rw [measure_iUnion hf_disj hf_meas] rw [lintegral_tsum, prod_iUnion, measure_iUnion] · simp_rw [hf_eq] · intro i j hij rw [Function.onFun, Set.disjoint_prod] exact Or.inr (hf_disj hij) · exact fun i ↦ MeasurableSet.prod hs (hf_meas i) · exact fun i ↦ ((Kernel.measurable_coe _ (hf_meas i)).comp measurable_prod_mk_left).aemeasurable.restrict @[deprecated (since := "2024-06-29")] alias set_lintegral_toKernel_prod := setLIntegral_toKernel_prod lemma lintegral_toKernel_mem [IsFiniteKernel κ] (hf : IsCondKernelCDF f κ ν) (a : α) {s : Set (β × ℝ)} (hs : MeasurableSet s) : ∫⁻ b, hf.toKernel f (a, b) {y | (b, y) ∈ s} ∂(ν a) = κ a s := by -- `setLIntegral_toKernel_prod` gives the result for sets of the form `t₁ × t₂`. These -- sets form a π-system that generates the product σ-algebra, hence we can get the same equality -- for any measurable set `s`. apply MeasurableSpace.induction_on_inter generateFrom_prod.symm isPiSystem_prod _ _ _ _ hs · simp only [mem_empty_iff_false, setOf_false, measure_empty, lintegral_const, zero_mul] · rintro _ ⟨t₁, ht₁, t₂, ht₂, rfl⟩ simp only [mem_setOf_eq] at ht₁ ht₂ have h_prod_eq_snd : ∀ a ∈ t₁, {x : ℝ | (a, x) ∈ t₁ ×ˢ t₂} = t₂ := by intro a ha simp only [ha, prod_mk_mem_set_prod_eq, true_and_iff, setOf_mem_eq] rw [← lintegral_add_compl _ ht₁] have h_eq1 : ∫⁻ x in t₁, hf.toKernel f (a, x) {y : ℝ | (x, y) ∈ t₁ ×ˢ t₂} ∂(ν a) = ∫⁻ x in t₁, hf.toKernel f (a, x) t₂ ∂(ν a) := by refine setLIntegral_congr_fun ht₁ (eventually_of_forall fun a ha ↦ ?_) rw [h_prod_eq_snd a ha] have h_eq2 : ∫⁻ x in t₁ᶜ, hf.toKernel f (a, x) {y : ℝ | (x, y) ∈ t₁ ×ˢ t₂} ∂(ν a) = 0 := by suffices h_eq_zero : ∀ x ∈ t₁ᶜ, hf.toKernel f (a, x) {y : ℝ | (x, y) ∈ t₁ ×ˢ t₂} = 0 by rw [setLIntegral_congr_fun ht₁.compl (eventually_of_forall h_eq_zero)] simp only [lintegral_const, zero_mul] intro a hat₁ rw [mem_compl_iff] at hat₁ simp only [hat₁, prod_mk_mem_set_prod_eq, false_and_iff, setOf_false, measure_empty] rw [h_eq1, h_eq2, add_zero] exact setLIntegral_toKernel_prod hf a ht₁ ht₂ · intro t ht ht_eq calc ∫⁻ b, hf.toKernel f (a, b) {y : ℝ | (b, y) ∈ tᶜ} ∂(ν a) = ∫⁻ b, hf.toKernel f (a, b) {y : ℝ | (b, y) ∈ t}ᶜ ∂(ν a) := rfl _ = ∫⁻ b, hf.toKernel f (a, b) univ - hf.toKernel f (a, b) {y : ℝ | (b, y) ∈ t} ∂(ν a) := by congr with x : 1 exact measure_compl (measurable_prod_mk_left ht) (measure_ne_top (hf.toKernel f (a, x)) _) _ = ∫⁻ x, hf.toKernel f (a, x) univ ∂(ν a) - ∫⁻ x, hf.toKernel f (a, x) {y : ℝ | (x, y) ∈ t} ∂(ν a) := by have h_le : (fun x ↦ hf.toKernel f (a, x) {y : ℝ | (x, y) ∈ t}) ≤ᵐ[ν a] fun x ↦ hf.toKernel f (a, x) univ := eventually_of_forall fun _ ↦ measure_mono (subset_univ _) rw [lintegral_sub _ _ h_le] · exact Kernel.measurable_kernel_prod_mk_left' ht a refine ((lintegral_mono_ae h_le).trans_lt ?_).ne rw [lintegral_toKernel_univ hf] exact measure_lt_top _ univ _ = κ a univ - κ a t := by rw [ht_eq, lintegral_toKernel_univ hf] _ = κ a tᶜ := (measure_compl ht (measure_ne_top _ _)).symm · intro f' hf_disj hf_meas hf_eq have h_eq : ∀ a, {x | (a, x) ∈ ⋃ i, f' i} = ⋃ i, {x | (a, x) ∈ f' i} := by intro a; ext x; simp only [mem_iUnion, mem_setOf_eq] simp_rw [h_eq] have h_disj : ∀ a, Pairwise (Disjoint on fun i ↦ {x | (a, x) ∈ f' i}) := by intro a i j hij have h_disj := hf_disj hij rw [Function.onFun, disjoint_iff_inter_eq_empty] at h_disj ⊢ ext1 x simp only [mem_inter_iff, mem_setOf_eq, mem_empty_iff_false, iff_false_iff] intro h_mem_both suffices (a, x) ∈ ∅ by rwa [mem_empty_iff_false] at this rwa [← h_disj, mem_inter_iff] calc ∫⁻ b, hf.toKernel f (a, b) (⋃ i, {y | (b, y) ∈ f' i}) ∂(ν a) = ∫⁻ b, ∑' i, hf.toKernel f (a, b) {y | (b, y) ∈ f' i} ∂(ν a) := by congr with x : 1 rw [measure_iUnion (h_disj x) fun i ↦ measurable_prod_mk_left (hf_meas i)] _ = ∑' i, ∫⁻ b, hf.toKernel f (a, b) {y | (b, y) ∈ f' i} ∂(ν a) := lintegral_tsum fun i ↦ (Kernel.measurable_kernel_prod_mk_left' (hf_meas i) a).aemeasurable _ = ∑' i, κ a (f' i) := by simp_rw [hf_eq] _ = κ a (iUnion f') := (measure_iUnion hf_disj hf_meas).symm lemma compProd_toKernel [IsFiniteKernel κ] [IsSFiniteKernel ν] (hf : IsCondKernelCDF f κ ν) : ν ⊗ₖ hf.toKernel f = κ := by ext a s hs rw [Kernel.compProd_apply _ _ _ hs, lintegral_toKernel_mem hf a hs] end end ProbabilityTheory
Probability\Kernel\Disintegration\CondCDF.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 import Mathlib.Probability.Kernel.Disintegration.CDFToKernel /-! # Conditional cumulative distribution function Given `ρ : Measure (α × ℝ)`, we define the conditional cumulative distribution function (conditional cdf) of `ρ`. It is a function `condCDF ρ : α → ℝ → ℝ` such that if `ρ` is a finite measure, then for all `a : α` `condCDF ρ a` is monotone and right-continuous with limit 0 at -∞ and limit 1 at +∞, and such that for all `x : ℝ`, `a ↦ condCDF ρ a x` is measurable. For all `x : ℝ` and measurable set `s`, that function satisfies `∫⁻ a in s, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (s ×ˢ Iic x)`. `condCDF` is build from the more general tools about kernel CDFs developed in the file `Probability.Kernel.Disintegration.CDFToKernel`. In that file, we build a function `α × β → StieltjesFunction` (which is `α × β → ℝ → ℝ` with additional properties) from a function `α × β → ℚ → ℝ`. The restriction to `ℚ` allows to prove some properties like measurability more easily. Here we apply that construction to the case `β = Unit` and then drop `β` to build `condCDF : α → StieltjesFunction`. ## Main definitions * `ProbabilityTheory.condCDF ρ : α → StieltjesFunction`: the conditional cdf of `ρ : Measure (α × ℝ)`. A `StieltjesFunction` is a function `ℝ → ℝ` which is monotone and right-continuous. ## Main statements * `ProbabilityTheory.setLIntegral_condCDF`: for all `a : α` and `x : ℝ`, all measurable set `s`, `∫⁻ a in s, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (s ×ˢ Iic x)`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped NNReal ENNReal MeasureTheory Topology namespace MeasureTheory.Measure variable {α β : Type*} {mα : MeasurableSpace α} (ρ : Measure (α × ℝ)) /-- Measure on `α` such that for a measurable set `s`, `ρ.IicSnd r s = ρ (s ×ˢ Iic r)`. -/ noncomputable def IicSnd (r : ℝ) : Measure α := (ρ.restrict (univ ×ˢ Iic r)).fst theorem IicSnd_apply (r : ℝ) {s : Set α} (hs : MeasurableSet s) : ρ.IicSnd r s = ρ (s ×ˢ Iic r) := by rw [IicSnd, fst_apply hs, restrict_apply' (MeasurableSet.univ.prod (measurableSet_Iic : MeasurableSet (Iic r))), ← prod_univ, prod_inter_prod, inter_univ, univ_inter] theorem IicSnd_univ (r : ℝ) : ρ.IicSnd r univ = ρ (univ ×ˢ Iic r) := IicSnd_apply ρ r MeasurableSet.univ theorem IicSnd_mono {r r' : ℝ} (h_le : r ≤ r') : ρ.IicSnd r ≤ ρ.IicSnd r' := by refine Measure.le_iff.2 fun s hs ↦ ?_ simp_rw [IicSnd_apply ρ _ hs] refine measure_mono (prod_subset_prod_iff.mpr (Or.inl ⟨subset_rfl, Iic_subset_Iic.mpr ?_⟩)) exact mod_cast h_le theorem IicSnd_le_fst (r : ℝ) : ρ.IicSnd r ≤ ρ.fst := by refine Measure.le_iff.2 fun s hs ↦ ?_ simp_rw [fst_apply hs, IicSnd_apply ρ r hs] exact measure_mono (prod_subset_preimage_fst _ _) theorem IicSnd_ac_fst (r : ℝ) : ρ.IicSnd r ≪ ρ.fst := Measure.absolutelyContinuous_of_le (IicSnd_le_fst ρ r) theorem IsFiniteMeasure.IicSnd {ρ : Measure (α × ℝ)} [IsFiniteMeasure ρ] (r : ℝ) : IsFiniteMeasure (ρ.IicSnd r) := isFiniteMeasure_of_le _ (IicSnd_le_fst ρ _) theorem iInf_IicSnd_gt (t : ℚ) {s : Set α} (hs : MeasurableSet s) [IsFiniteMeasure ρ] : ⨅ r : { r' : ℚ // t < r' }, ρ.IicSnd r s = ρ.IicSnd t s := by simp_rw [ρ.IicSnd_apply _ hs, Measure.iInf_rat_gt_prod_Iic hs] theorem tendsto_IicSnd_atTop {s : Set α} (hs : MeasurableSet s) : Tendsto (fun r : ℚ ↦ ρ.IicSnd r s) atTop (𝓝 (ρ.fst s)) := by simp_rw [ρ.IicSnd_apply _ hs, fst_apply hs, ← prod_univ] rw [← Real.iUnion_Iic_rat, prod_iUnion] refine tendsto_measure_iUnion fun r q hr_le_q x ↦ ?_ simp only [mem_prod, mem_Iic, and_imp] refine fun hxs hxr ↦ ⟨hxs, hxr.trans ?_⟩ exact mod_cast hr_le_q theorem tendsto_IicSnd_atBot [IsFiniteMeasure ρ] {s : Set α} (hs : MeasurableSet s) : Tendsto (fun r : ℚ ↦ ρ.IicSnd r s) atBot (𝓝 0) := by simp_rw [ρ.IicSnd_apply _ hs] have h_empty : ρ (s ×ˢ ∅) = 0 := by simp only [prod_empty, measure_empty] rw [← h_empty, ← Real.iInter_Iic_rat, prod_iInter] suffices h_neg : Tendsto (fun r : ℚ ↦ ρ (s ×ˢ Iic ↑(-r))) atTop (𝓝 (ρ (⋂ r : ℚ, s ×ˢ Iic ↑(-r)))) by have h_inter_eq : ⋂ r : ℚ, s ×ˢ Iic ↑(-r) = ⋂ r : ℚ, s ×ˢ Iic (r : ℝ) := by ext1 x simp only [Rat.cast_eq_id, id, mem_iInter, mem_prod, mem_Iic] refine ⟨fun h i ↦ ⟨(h i).1, ?_⟩, fun h i ↦ ⟨(h i).1, ?_⟩⟩ <;> have h' := h (-i) · rw [neg_neg] at h'; exact h'.2 · exact h'.2 rw [h_inter_eq] at h_neg have h_fun_eq : (fun r : ℚ ↦ ρ (s ×ˢ Iic (r : ℝ))) = fun r : ℚ ↦ ρ (s ×ˢ Iic ↑(- -r)) := by simp_rw [neg_neg] rw [h_fun_eq] exact h_neg.comp tendsto_neg_atBot_atTop refine tendsto_measure_iInter (fun q ↦ hs.prod measurableSet_Iic) ?_ ⟨0, measure_ne_top ρ _⟩ refine fun q r hqr ↦ prod_subset_prod_iff.mpr (Or.inl ⟨subset_rfl, fun x hx ↦ ?_⟩) simp only [Rat.cast_neg, mem_Iic] at hx ⊢ refine hx.trans (neg_le_neg ?_) exact mod_cast hqr end MeasureTheory.Measure open MeasureTheory namespace ProbabilityTheory variable {α β ι : Type*} {mα : MeasurableSpace α} attribute [local instance] MeasureTheory.Measure.IsFiniteMeasure.IicSnd /-! ### Auxiliary definitions We build towards the definition of `ProbabilityTheory.condCDF`. We first define `ProbabilityTheory.preCDF`, a function defined on `α × ℚ` with the properties of a cdf almost everywhere. -/ /-- `preCDF` is the Radon-Nikodym derivative of `ρ.IicSnd` with respect to `ρ.fst` at each `r : ℚ`. This function `ℚ → α → ℝ≥0∞` is such that for almost all `a : α`, the function `ℚ → ℝ≥0∞` satisfies the properties of a cdf (monotone with limit 0 at -∞ and 1 at +∞, right-continuous). We define this function on `ℚ` and not `ℝ` because `ℚ` is countable, which allows us to prove properties of the form `∀ᵐ a ∂ρ.fst, ∀ q, P (preCDF q a)`, instead of the weaker `∀ q, ∀ᵐ a ∂ρ.fst, P (preCDF q a)`. -/ noncomputable def preCDF (ρ : Measure (α × ℝ)) (r : ℚ) : α → ℝ≥0∞ := Measure.rnDeriv (ρ.IicSnd r) ρ.fst theorem measurable_preCDF {ρ : Measure (α × ℝ)} {r : ℚ} : Measurable (preCDF ρ r) := Measure.measurable_rnDeriv _ _ lemma measurable_preCDF' {ρ : Measure (α × ℝ)} : Measurable fun a r ↦ (preCDF ρ r a).toReal := by rw [measurable_pi_iff] exact fun _ ↦ measurable_preCDF.ennreal_toReal theorem withDensity_preCDF (ρ : Measure (α × ℝ)) (r : ℚ) [IsFiniteMeasure ρ] : ρ.fst.withDensity (preCDF ρ r) = ρ.IicSnd r := Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq.mp (Measure.IicSnd_ac_fst ρ r) theorem setLIntegral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) {s : Set α} (hs : MeasurableSet s) [IsFiniteMeasure ρ] : ∫⁻ x in s, preCDF ρ r x ∂ρ.fst = ρ.IicSnd r s := by have : ∀ r, ∫⁻ x in s, preCDF ρ r x ∂ρ.fst = ∫⁻ x in s, (preCDF ρ r * 1) x ∂ρ.fst := by simp only [mul_one, eq_self_iff_true, forall_const] rw [this, ← setLIntegral_withDensity_eq_setLIntegral_mul _ measurable_preCDF _ hs] · simp only [withDensity_preCDF ρ r, Pi.one_apply, lintegral_one, Measure.restrict_apply, MeasurableSet.univ, univ_inter] · rw [(_ : (1 : α → ℝ≥0∞) = fun _ ↦ 1)] exacts [measurable_const, rfl] @[deprecated (since := "2024-06-29")] alias set_lintegral_preCDF_fst := setLIntegral_preCDF_fst lemma lintegral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) [IsFiniteMeasure ρ] : ∫⁻ x, preCDF ρ r x ∂ρ.fst = ρ.IicSnd r univ := by rw [← setLIntegral_univ, setLIntegral_preCDF_fst ρ r MeasurableSet.univ] theorem monotone_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] : ∀ᵐ a ∂ρ.fst, Monotone fun r ↦ preCDF ρ r a := by simp_rw [Monotone, ae_all_iff] refine fun r r' hrr' ↦ ae_le_of_forall_setLIntegral_le_of_sigmaFinite measurable_preCDF fun s hs _ ↦ ?_ rw [setLIntegral_preCDF_fst ρ r hs, setLIntegral_preCDF_fst ρ r' hs] exact Measure.IicSnd_mono ρ (mod_cast hrr') s theorem preCDF_le_one (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] : ∀ᵐ a ∂ρ.fst, ∀ r, preCDF ρ r a ≤ 1 := by rw [ae_all_iff] refine fun r ↦ ae_le_of_forall_setLIntegral_le_of_sigmaFinite measurable_preCDF fun s hs _ ↦ ?_ rw [setLIntegral_preCDF_fst ρ r hs] simp only [Pi.one_apply, lintegral_one, Measure.restrict_apply, MeasurableSet.univ, univ_inter] exact Measure.IicSnd_le_fst ρ r s lemma setIntegral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) {s : Set α} (hs : MeasurableSet s) [IsFiniteMeasure ρ] : ∫ x in s, (preCDF ρ r x).toReal ∂ρ.fst = (ρ.IicSnd r s).toReal := by rw [integral_toReal] · rw [setLIntegral_preCDF_fst _ _ hs] · exact measurable_preCDF.aemeasurable · refine ae_restrict_of_ae ?_ filter_upwards [preCDF_le_one ρ] with a ha exact (ha r).trans_lt ENNReal.one_lt_top @[deprecated (since := "2024-04-17")] alias set_integral_preCDF_fst := setIntegral_preCDF_fst lemma integral_preCDF_fst (ρ : Measure (α × ℝ)) (r : ℚ) [IsFiniteMeasure ρ] : ∫ x, (preCDF ρ r x).toReal ∂ρ.fst = (ρ.IicSnd r univ).toReal := by rw [← integral_univ, setIntegral_preCDF_fst ρ _ MeasurableSet.univ] lemma integrable_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℚ) : Integrable (fun a ↦ (preCDF ρ x a).toReal) ρ.fst := by refine integrable_of_forall_fin_meas_le _ (measure_lt_top ρ.fst univ) ?_ fun t _ _ ↦ ?_ · exact measurable_preCDF.ennreal_toReal.aestronglyMeasurable · simp_rw [← ofReal_norm_eq_coe_nnnorm, Real.norm_of_nonneg ENNReal.toReal_nonneg] rw [← lintegral_one] refine (setLIntegral_le_lintegral _ _).trans (lintegral_mono_ae ?_) filter_upwards [preCDF_le_one ρ] with a ha using ENNReal.ofReal_toReal_le.trans (ha _) lemma isRatCondKernelCDFAux_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] : IsRatCondKernelCDFAux (fun p r ↦ (preCDF ρ r p.2).toReal) (Kernel.const Unit ρ) (Kernel.const Unit ρ.fst) where measurable := measurable_preCDF'.comp measurable_snd mono' a r r' hrr' := by filter_upwards [monotone_preCDF ρ, preCDF_le_one ρ] with a h1 h2 have h_ne_top : ∀ r, preCDF ρ r a ≠ ∞ := fun r ↦ ((h2 r).trans_lt ENNReal.one_lt_top).ne rw [ENNReal.toReal_le_toReal (h_ne_top _) (h_ne_top _)] exact h1 hrr' nonneg' _ q := by simp le_one' a q := by simp only [Kernel.const_apply, forall_const] filter_upwards [preCDF_le_one ρ] with a ha refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_ simp [ha] tendsto_integral_of_antitone a s _ hs_tendsto := by simp_rw [Kernel.const_apply, integral_preCDF_fst ρ] have h := ρ.tendsto_IicSnd_atBot MeasurableSet.univ rw [← ENNReal.zero_toReal] have h0 : Tendsto ENNReal.toReal (𝓝 0) (𝓝 0) := ENNReal.continuousAt_toReal ENNReal.zero_ne_top exact h0.comp (h.comp hs_tendsto) tendsto_integral_of_monotone a s _ hs_tendsto := by simp_rw [Kernel.const_apply, integral_preCDF_fst ρ] have h := ρ.tendsto_IicSnd_atTop MeasurableSet.univ have h0 : Tendsto ENNReal.toReal (𝓝 (ρ.fst univ)) (𝓝 (ρ.fst univ).toReal) := ENNReal.continuousAt_toReal (measure_ne_top _ _) exact h0.comp (h.comp hs_tendsto) integrable _ q := integrable_preCDF ρ q setIntegral a s hs q := by rw [Kernel.const_apply, Kernel.const_apply, setIntegral_preCDF_fst _ _ hs, Measure.IicSnd_apply _ _ hs] lemma isRatCondKernelCDF_preCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] : IsRatCondKernelCDF (fun p r ↦ (preCDF ρ r p.2).toReal) (Kernel.const Unit ρ) (Kernel.const Unit ρ.fst) := (isRatCondKernelCDFAux_preCDF ρ).isRatCondKernelCDF /-! ### Conditional cdf -/ /-- Conditional cdf of the measure given the value on `α`, as a Stieltjes function. -/ noncomputable def condCDF (ρ : Measure (α × ℝ)) (a : α) : StieltjesFunction := stieltjesOfMeasurableRat (fun a r ↦ (preCDF ρ r a).toReal) measurable_preCDF' a lemma condCDF_eq_stieltjesOfMeasurableRat_unit_prod (ρ : Measure (α × ℝ)) (a : α) : condCDF ρ a = stieltjesOfMeasurableRat (fun (p : Unit × α) r ↦ (preCDF ρ r p.2).toReal) (measurable_preCDF'.comp measurable_snd) ((), a) := by ext x rw [condCDF, ← stieltjesOfMeasurableRat_unit_prod] lemma isCondKernelCDF_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] : IsCondKernelCDF (fun p : Unit × α ↦ condCDF ρ p.2) (Kernel.const Unit ρ) (Kernel.const Unit ρ.fst) := by simp_rw [condCDF_eq_stieltjesOfMeasurableRat_unit_prod ρ] exact isCondKernelCDF_stieltjesOfMeasurableRat (isRatCondKernelCDF_preCDF ρ) /-- The conditional cdf is non-negative for all `a : α`. -/ theorem condCDF_nonneg (ρ : Measure (α × ℝ)) (a : α) (r : ℝ) : 0 ≤ condCDF ρ a r := stieltjesOfMeasurableRat_nonneg _ a r /-- The conditional cdf is lower or equal to 1 for all `a : α`. -/ theorem condCDF_le_one (ρ : Measure (α × ℝ)) (a : α) (x : ℝ) : condCDF ρ a x ≤ 1 := stieltjesOfMeasurableRat_le_one _ _ _ /-- The conditional cdf tends to 0 at -∞ for all `a : α`. -/ theorem tendsto_condCDF_atBot (ρ : Measure (α × ℝ)) (a : α) : Tendsto (condCDF ρ a) atBot (𝓝 0) := tendsto_stieltjesOfMeasurableRat_atBot _ _ /-- The conditional cdf tends to 1 at +∞ for all `a : α`. -/ theorem tendsto_condCDF_atTop (ρ : Measure (α × ℝ)) (a : α) : Tendsto (condCDF ρ a) atTop (𝓝 1) := tendsto_stieltjesOfMeasurableRat_atTop _ _ theorem condCDF_ae_eq (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (r : ℚ) : (fun a ↦ condCDF ρ a r) =ᵐ[ρ.fst] fun a ↦ (preCDF ρ r a).toReal := by simp_rw [condCDF_eq_stieltjesOfMeasurableRat_unit_prod ρ] exact stieltjesOfMeasurableRat_ae_eq (isRatCondKernelCDF_preCDF ρ) () r theorem ofReal_condCDF_ae_eq (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (r : ℚ) : (fun a ↦ ENNReal.ofReal (condCDF ρ a r)) =ᵐ[ρ.fst] preCDF ρ r := by filter_upwards [condCDF_ae_eq ρ r, preCDF_le_one ρ] with a ha ha_le_one rw [ha, ENNReal.ofReal_toReal] exact ((ha_le_one r).trans_lt ENNReal.one_lt_top).ne /-- The conditional cdf is a measurable function of `a : α` for all `x : ℝ`. -/ theorem measurable_condCDF (ρ : Measure (α × ℝ)) (x : ℝ) : Measurable fun a ↦ condCDF ρ a x := measurable_stieltjesOfMeasurableRat _ _ /-- The conditional cdf is a strongly measurable function of `a : α` for all `x : ℝ`. -/ theorem stronglyMeasurable_condCDF (ρ : Measure (α × ℝ)) (x : ℝ) : StronglyMeasurable fun a ↦ condCDF ρ a x := stronglyMeasurable_stieltjesOfMeasurableRat _ _ theorem setLIntegral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a in s, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (s ×ˢ Iic x) := (isCondKernelCDF_condCDF ρ).setLIntegral () hs x @[deprecated (since := "2024-06-29")] alias set_lintegral_condCDF := setLIntegral_condCDF theorem lintegral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) : ∫⁻ a, ENNReal.ofReal (condCDF ρ a x) ∂ρ.fst = ρ (univ ×ˢ Iic x) := (isCondKernelCDF_condCDF ρ).lintegral () x theorem integrable_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) : Integrable (fun a ↦ condCDF ρ a x) ρ.fst := (isCondKernelCDF_condCDF ρ).integrable () x theorem setIntegral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) {s : Set α} (hs : MeasurableSet s) : ∫ a in s, condCDF ρ a x ∂ρ.fst = (ρ (s ×ˢ Iic x)).toReal := (isCondKernelCDF_condCDF ρ).setIntegral () hs x @[deprecated (since := "2024-04-17")] alias set_integral_condCDF := setIntegral_condCDF theorem integral_condCDF (ρ : Measure (α × ℝ)) [IsFiniteMeasure ρ] (x : ℝ) : ∫ a, condCDF ρ a x ∂ρ.fst = (ρ (univ ×ˢ Iic x)).toReal := (isCondKernelCDF_condCDF ρ).integral () x section Measure theorem measure_condCDF_Iic (ρ : Measure (α × ℝ)) (a : α) (x : ℝ) : (condCDF ρ a).measure (Iic x) = ENNReal.ofReal (condCDF ρ a x) := by rw [← sub_zero (condCDF ρ a x)] exact (condCDF ρ a).measure_Iic (tendsto_condCDF_atBot ρ a) _ theorem measure_condCDF_univ (ρ : Measure (α × ℝ)) (a : α) : (condCDF ρ a).measure univ = 1 := by rw [← ENNReal.ofReal_one, ← sub_zero (1 : ℝ)] exact StieltjesFunction.measure_univ _ (tendsto_condCDF_atBot ρ a) (tendsto_condCDF_atTop ρ a) instance instIsProbabilityMeasureCondCDF (ρ : Measure (α × ℝ)) (a : α) : IsProbabilityMeasure (condCDF ρ a).measure := ⟨measure_condCDF_univ ρ a⟩ /-- The function `a ↦ (condCDF ρ a).measure` is measurable. -/ theorem measurable_measure_condCDF (ρ : Measure (α × ℝ)) : Measurable fun a => (condCDF ρ a).measure := by rw [Measure.measurable_measure] refine fun s hs => ?_ -- Porting note: supplied `C` refine MeasurableSpace.induction_on_inter (C := fun s => Measurable fun b ↦ StieltjesFunction.measure (condCDF ρ b) s) (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic ?_ ?_ ?_ ?_ hs · simp only [measure_empty, measurable_const] · rintro S ⟨u, rfl⟩ simp_rw [measure_condCDF_Iic ρ _ u] exact (measurable_condCDF ρ u).ennreal_ofReal · intro t ht ht_cd_meas have : (fun a => (condCDF ρ a).measure tᶜ) = (fun a => (condCDF ρ a).measure univ) - fun a => (condCDF ρ a).measure t := by ext1 a rw [measure_compl ht (measure_ne_top (condCDF ρ a).measure _), Pi.sub_apply] simp_rw [this, measure_condCDF_univ ρ] exact Measurable.sub measurable_const ht_cd_meas · intro f hf_disj hf_meas hf_cd_meas simp_rw [measure_iUnion hf_disj hf_meas] exact Measurable.ennreal_tsum hf_cd_meas end Measure end ProbabilityTheory
Probability\Kernel\Disintegration\Density.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.Probability.Kernel.Composition import Mathlib.Probability.Martingale.Convergence import Mathlib.Probability.Process.PartitionFiltration /-! # Kernel density Let `κ : Kernel α (γ × β)` and `ν : Kernel α γ` be two finite kernels with `Kernel.fst κ ≤ ν`, where `γ` has a countably generated σ-algebra (true in particular for standard Borel spaces). We build a function `density κ ν : α → γ → Set β → ℝ` jointly measurable in the first two arguments such that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`, `∫ x in A, density κ ν a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal`. There are two main applications of this construction (still TODO, in other files). * Disintegration of kernels: for `κ : Kernel α (γ × β)`, we want to build a kernel `η : Kernel (α × γ) β` such that `κ = fst κ ⊗ₖ η`. For `β = ℝ`, we can use the density of `κ` with respect to `fst κ` for intervals to build a kernel cumulative distribution function for `η`. The construction can then be extended to `β` standard Borel. * Radon-Nikodym theorem for kernels: for `κ ν : Kernel α γ`, we can use the density to build a Radon-Nikodym derivative of `κ` with respect to `ν`. We don't need `β` here but we can apply the density construction to `β = Unit`. The derivative construction will use `density` but will not be exactly equal to it because we will want to remove the `fst κ ≤ ν` assumption. ## Main definitions * `ProbabilityTheory.Kernel.density`: for `κ : Kernel α (γ × β)` and `ν : Kernel α γ` two finite kernels, `Kernel.density κ ν` is a function `α → γ → Set β → ℝ`. ## Main statements * `ProbabilityTheory.Kernel.setIntegral_density`: for all measurable sets `A : Set γ` and `s : Set β`, `∫ x in A, Kernel.density κ ν a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal`. * `ProbabilityTheory.Kernel.measurable_density`: the function `p : α × γ ↦ Kernel.density κ ν p.1 p.2 s` is measurable. ## Construction of the density If we were interested only in a fixed `a : α`, then we could use the Radon-Nikodym derivative to build the density function `density κ ν`, as follows. ``` def density' (κ : Kernel α (γ × β)) (ν : kernel a γ) (a : α) (x : γ) (s : Set β) : ℝ := (((κ a).restrict (univ ×ˢ s)).fst.rnDeriv (ν a) x).toReal ``` However, we can't turn those functions for each `a` into a measurable function of the pair `(a, x)`. In order to obtain measurability through countability, we use the fact that the measurable space `γ` is countably generated. For each `n : ℕ`, we define (in the file `Mathlib.Probability.Process.PartitionFiltration`) a finite partition of `γ`, such that those partitions are finer as `n` grows, and the σ-algebra generated by the union of all partitions is the σ-algebra of `γ`. For `x : γ`, `countablePartitionSet n x` denotes the set in the partition such that `x ∈ countablePartitionSet n x`. For a given `n`, the function `densityProcess κ ν n : α → γ → Set β → ℝ` defined by `fun a x s ↦ (κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal` has the desired property that `∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal` for all `A` in the σ-algebra generated by the partition at scale `n` and is measurable in `(a, x)`. `countableFiltration γ` is the filtration of those σ-algebras for all `n : ℕ`. The functions `densityProcess κ ν n` described here are a bounded `ν`-martingale for the filtration `countableFiltration γ`. By Doob's martingale L1 convergence theorem, that martingale converges to a limit, which has a product-measurable version and satisfies the integral equality for all `A` in `⨆ n, countableFiltration γ n`. Finally, the partitions were chosen such that that supremum is equal to the σ-algebra on `γ`, hence the equality holds for all measurable sets. We have obtained the desired density function. ## References The construction of the density process in this file follows the proof of Theorem 9.27 in [O. Kallenberg, Foundations of modern probability][kallenberg2021], adapted to use a countably generated hypothesis instead of specializing to `ℝ`. -/ open MeasureTheory Set Filter MeasurableSpace open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory.Kernel variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} [CountablyGenerated γ] {κ : Kernel α (γ × β)} {ν : Kernel α γ} section DensityProcess /-- An `ℕ`-indexed martingale that is a density for `κ` with respect to `ν` on the sets in `countablePartition γ n`. Used to define its limit `ProbabilityTheory.Kernel.density`, which is a density for those kernels for all measurable sets. -/ noncomputable def densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) (s : Set β) : ℝ := (κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal lemma densityProcess_def (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (s : Set β) : (fun t ↦ densityProcess κ ν n a t s) = fun t ↦ (κ a (countablePartitionSet n t ×ˢ s) / ν a (countablePartitionSet n t)).toReal := rfl lemma measurable_densityProcess_countableFiltration_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) {s : Set β} (hs : MeasurableSet s) : Measurable[mα.prod (countableFiltration γ n)] (fun (p : α × γ) ↦ κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by change Measurable[mα.prod (countableFiltration γ n)] ((fun (p : α × countablePartition γ n) ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2) ∘ (fun (p : α × γ) ↦ (p.1, ⟨countablePartitionSet n p.2, countablePartitionSet_mem n p.2⟩))) have h1 : @Measurable _ _ (mα.prod ⊤) _ (fun p : α × countablePartition γ n ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2) := by refine Measurable.div ?_ ?_ · refine measurable_from_prod_countable (fun t ↦ ?_) exact Kernel.measurable_coe _ ((measurableSet_countablePartition _ t.prop).prod hs) · refine measurable_from_prod_countable ?_ rintro ⟨t, ht⟩ exact Kernel.measurable_coe _ (measurableSet_countablePartition _ ht) refine h1.comp (measurable_fst.prod_mk ?_) change @Measurable (α × γ) (countablePartition γ n) (mα.prod (countableFiltration γ n)) ⊤ ((fun c ↦ ⟨countablePartitionSet n c, countablePartitionSet_mem n c⟩) ∘ (fun p : α × γ ↦ p.2)) exact (measurable_countablePartitionSet_subtype n ⊤).comp measurable_snd lemma measurable_densityProcess_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) {s : Set β} (hs : MeasurableSet s) : Measurable (fun (p : α × γ) ↦ κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by refine Measurable.mono (measurable_densityProcess_countableFiltration_aux κ ν n hs) ?_ le_rfl exact sup_le_sup le_rfl (comap_mono ((countableFiltration γ).le _)) lemma measurable_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) {s : Set β} (hs : MeasurableSet s) : Measurable (fun (p : α × γ) ↦ densityProcess κ ν n p.1 p.2 s) := (measurable_densityProcess_aux κ ν n hs).ennreal_toReal lemma measurable_densityProcess_left (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (x : γ) {s : Set β} (hs : MeasurableSet s) : Measurable (fun a ↦ densityProcess κ ν n a x s) := (measurable_densityProcess κ ν n hs).comp (measurable_id.prod_mk measurable_const) lemma measurable_densityProcess_right (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) {s : Set β} (a : α) (hs : MeasurableSet s) : Measurable (fun x ↦ densityProcess κ ν n a x s) := (measurable_densityProcess κ ν n hs).comp (measurable_const.prod_mk measurable_id) lemma measurable_countableFiltration_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) : Measurable[countableFiltration γ n] (fun x ↦ densityProcess κ ν n a x s) := by refine @Measurable.ennreal_toReal _ (countableFiltration γ n) _ ?_ exact (measurable_densityProcess_countableFiltration_aux κ ν n hs).comp measurable_prod_mk_left lemma stronglyMeasurable_countableFiltration_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) : StronglyMeasurable[countableFiltration γ n] (fun x ↦ densityProcess κ ν n a x s) := (measurable_countableFiltration_densityProcess κ ν n a hs).stronglyMeasurable lemma adapted_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (a : α) {s : Set β} (hs : MeasurableSet s) : Adapted (countableFiltration γ) (fun n x ↦ densityProcess κ ν n a x s) := fun n ↦ stronglyMeasurable_countableFiltration_densityProcess κ ν n a hs lemma densityProcess_nonneg (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) (s : Set β) : 0 ≤ densityProcess κ ν n a x s := ENNReal.toReal_nonneg lemma meas_countablePartitionSet_le_of_fst_le (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) : κ a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) := by calc κ a (countablePartitionSet n x ×ˢ s) ≤ fst κ a (countablePartitionSet n x) := by rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] refine measure_mono (fun x ↦ ?_) simp only [mem_prod, mem_setOf_eq, and_imp] exact fun h _ ↦ h _ ≤ ν a (countablePartitionSet n x) := hκν a _ lemma densityProcess_le_one (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) : densityProcess κ ν n a x s ≤ 1 := by refine ENNReal.toReal_le_of_le_ofReal zero_le_one (ENNReal.div_le_of_le_mul ?_) rw [ENNReal.ofReal_one, one_mul] exact meas_countablePartitionSet_le_of_fst_le hκν n a x s lemma eLpNorm_densityProcess_le (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (s : Set β) : eLpNorm (fun x ↦ densityProcess κ ν n a x s) 1 (ν a) ≤ ν a univ := by refine (eLpNorm_le_of_ae_bound (C := 1) (ae_of_all _ (fun x ↦ ?_))).trans ?_ · simp only [Real.norm_eq_abs, abs_of_nonneg (densityProcess_nonneg κ ν n a x s), densityProcess_le_one hκν n a x s] · simp @[deprecated (since := "2024-07-27")] alias snorm_densityProcess_le := eLpNorm_densityProcess_le lemma integrable_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) : Integrable (fun x ↦ densityProcess κ ν n a x s) (ν a) := by rw [← memℒp_one_iff_integrable] refine ⟨Measurable.aestronglyMeasurable ?_, ?_⟩ · exact measurable_densityProcess_right κ ν n a hs · exact (eLpNorm_densityProcess_le hκν n a s).trans_lt (measure_lt_top _ _) lemma setIntegral_densityProcess_of_mem (hκν : fst κ ≤ ν) [hν : IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {u : Set γ} (hu : u ∈ countablePartition γ n) : ∫ x in u, densityProcess κ ν n a x s ∂(ν a) = (κ a (u ×ˢ s)).toReal := by have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν) have hu_meas : MeasurableSet u := measurableSet_countablePartition n hu simp_rw [densityProcess] rw [integral_toReal] rotate_left · refine Measurable.aemeasurable ?_ change Measurable ((fun (p : α × _) ↦ κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) ∘ (fun x ↦ (a, x))) exact (measurable_densityProcess_aux κ ν n hs).comp measurable_prod_mk_left · refine ae_of_all _ (fun x ↦ ?_) by_cases h0 : ν a (countablePartitionSet n x) = 0 · suffices κ a (countablePartitionSet n x ×ˢ s) = 0 by simp [h0, this] have h0' : fst κ a (countablePartitionSet n x) = 0 := le_antisymm ((hκν a _).trans h0.le) zero_le' rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h0' refine measure_mono_null (fun x ↦ ?_) h0' simp only [mem_prod, mem_setOf_eq, and_imp] exact fun h _ ↦ h · exact ENNReal.div_lt_top (measure_ne_top _ _) h0 congr have : ∫⁻ x in u, κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x) ∂(ν a) = ∫⁻ _ in u, κ a (u ×ˢ s) / ν a u ∂(ν a) := by refine setLIntegral_congr_fun hu_meas (ae_of_all _ (fun t ht ↦ ?_)) rw [countablePartitionSet_of_mem hu ht] rw [this] simp only [MeasureTheory.lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter] by_cases h0 : ν a u = 0 · simp only [h0, mul_zero] have h0' : fst κ a u = 0 := le_antisymm ((hκν a _).trans h0.le) zero_le' rw [fst_apply' _ _ hu_meas] at h0' refine (measure_mono_null ?_ h0').symm intro p simp only [mem_prod, mem_setOf_eq, and_imp] exact fun h _ ↦ h rw [div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel h0, mul_one] exact measure_ne_top _ _ @[deprecated (since := "2024-04-17")] alias set_integral_densityProcess_of_mem := setIntegral_densityProcess_of_mem lemma setIntegral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet[countableFiltration γ n] A) : ∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal := by have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν) obtain ⟨S, hS_subset, rfl⟩ := (measurableSet_generateFrom_countablePartition_iff _ _).mp hA simp_rw [sUnion_eq_iUnion] have h_disj : Pairwise (Disjoint on fun i : S ↦ (i : Set γ)) := by intro u v huv #adaptation_note /-- nightly-2024-03-16 Previously `Function.onFun` unfolded in the following `simp only`, but now needs a `rw`. This may be a bug: a no import minimization may be required. simp only [Finset.coe_sort_coe, Function.onFun] -/ rw [Function.onFun] refine disjoint_countablePartition (hS_subset (by simp)) (hS_subset (by simp)) ?_ rwa [ne_eq, ← Subtype.ext_iff] rw [integral_iUnion, iUnion_prod_const, measure_iUnion, ENNReal.tsum_toReal_eq (fun _ ↦ measure_ne_top _ _)] · congr with u rw [setIntegral_densityProcess_of_mem hκν _ _ hs (hS_subset (by simp))] · intro u v huv simp only [Finset.coe_sort_coe, Set.disjoint_prod, disjoint_self, bot_eq_empty] exact Or.inl (h_disj huv) · exact fun _ ↦ (measurableSet_countablePartition n (hS_subset (by simp))).prod hs · exact fun _ ↦ measurableSet_countablePartition n (hS_subset (by simp)) · exact h_disj · exact (integrable_densityProcess hκν _ _ hs).integrableOn @[deprecated (since := "2024-04-17")] alias set_integral_densityProcess := setIntegral_densityProcess lemma integral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) : ∫ x, densityProcess κ ν n a x s ∂(ν a) = (κ a (univ ×ˢ s)).toReal := by rw [← integral_univ, setIntegral_densityProcess hκν _ _ hs MeasurableSet.univ] lemma setIntegral_densityProcess_of_le (hκν : fst κ ≤ ν) [IsFiniteKernel ν] {n m : ℕ} (hnm : n ≤ m) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet[countableFiltration γ n] A) : ∫ x in A, densityProcess κ ν m a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal := setIntegral_densityProcess hκν m a hs ((countableFiltration γ).mono hnm A hA) @[deprecated (since := "2024-04-17")] alias set_integral_densityProcess_of_le := setIntegral_densityProcess_of_le lemma condexp_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] {i j : ℕ} (hij : i ≤ j) (a : α) {s : Set β} (hs : MeasurableSet s) : (ν a)[fun x ↦ densityProcess κ ν j a x s | countableFiltration γ i] =ᵐ[ν a] fun x ↦ densityProcess κ ν i a x s := by refine (ae_eq_condexp_of_forall_setIntegral_eq ?_ ?_ ?_ ?_ ?_).symm · exact integrable_densityProcess hκν j a hs · exact fun _ _ _ ↦ (integrable_densityProcess hκν _ _ hs).integrableOn · intro x hx _ rw [setIntegral_densityProcess hκν i a hs hx, setIntegral_densityProcess_of_le hκν hij a hs hx] · exact StronglyMeasurable.aeStronglyMeasurable' (stronglyMeasurable_countableFiltration_densityProcess κ ν i a hs) lemma martingale_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : Martingale (fun n x ↦ densityProcess κ ν n a x s) (countableFiltration γ) (ν a) := ⟨adapted_densityProcess κ ν a hs, fun _ _ h ↦ condexp_densityProcess hκν h a hs⟩ lemma densityProcess_mono_set (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) {s s' : Set β} (h : s ⊆ s') : densityProcess κ ν n a x s ≤ densityProcess κ ν n a x s' := by unfold densityProcess by_cases h0 : ν a (countablePartitionSet n x) = 0 · rw [h0, ENNReal.toReal_div, ENNReal.toReal_div] simp have h_ne_top : ∀ s, κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x) ≠ ⊤ := by intro s rw [ne_eq, ENNReal.div_eq_top] simp only [ne_eq, h0, and_false, false_or, not_and, not_not] refine fun h_top ↦ eq_top_mono ?_ h_top exact meas_countablePartitionSet_le_of_fst_le hκν n a x s rw [ENNReal.toReal_le_toReal (h_ne_top s) (h_ne_top s')] gcongr lemma densityProcess_mono_kernel_left {κ' : Kernel α (γ × β)} (hκκ' : κ ≤ κ') (hκ'ν : fst κ' ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) : densityProcess κ ν n a x s ≤ densityProcess κ' ν n a x s := by unfold densityProcess by_cases h0 : ν a (countablePartitionSet n x) = 0 · rw [h0, ENNReal.toReal_div, ENNReal.toReal_div] simp have h_le : κ' a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) := meas_countablePartitionSet_le_of_fst_le hκ'ν n a x s rw [ENNReal.toReal_le_toReal] · gcongr exact hκκ' _ _ · rw [ne_eq, ENNReal.div_eq_top] simp only [ne_eq, h0, and_false, false_or, not_and, not_not] refine fun h_top ↦ eq_top_mono ?_ h_top exact (hκκ' _ _).trans h_le · rw [ne_eq, ENNReal.div_eq_top] simp only [ne_eq, h0, and_false, false_or, not_and, not_not] exact fun h_top ↦ eq_top_mono h_le h_top lemma densityProcess_antitone_kernel_right {ν' : Kernel α γ} (hνν' : ν ≤ ν') (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) : densityProcess κ ν' n a x s ≤ densityProcess κ ν n a x s := by unfold densityProcess have h_le : κ a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) := meas_countablePartitionSet_le_of_fst_le hκν n a x s by_cases h0 : ν a (countablePartitionSet n x) = 0 · simp [le_antisymm (h_le.trans h0.le) zero_le', h0] have h0' : ν' a (countablePartitionSet n x) ≠ 0 := fun h ↦ h0 (le_antisymm ((hνν' _ _).trans h.le) zero_le') rw [ENNReal.toReal_le_toReal] · gcongr exact hνν' _ _ · simp only [ne_eq, ENNReal.div_eq_top, h0', and_false, false_or, not_and, not_not] refine fun h_top ↦ eq_top_mono ?_ h_top exact h_le.trans (hνν' _ _) · simp only [ne_eq, ENNReal.div_eq_top, h0, and_false, false_or, not_and, not_not] exact fun h_top ↦ eq_top_mono h_le h_top @[simp] lemma densityProcess_empty (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) : densityProcess κ ν n a x ∅ = 0 := by simp [densityProcess] lemma tendsto_densityProcess_atTop_empty_of_antitone (κ : Kernel α (γ × β)) (ν : Kernel α γ) [IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ) (seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅) (hseq_meas : ∀ m, MeasurableSet (seq m)) : Tendsto (fun m ↦ densityProcess κ ν n a x (seq m)) atTop (𝓝 (densityProcess κ ν n a x ∅)) := by simp_rw [densityProcess] by_cases h0 : ν a (countablePartitionSet n x) = 0 · simp_rw [h0, ENNReal.toReal_div] simp refine (ENNReal.tendsto_toReal ?_).comp ?_ · rw [ne_eq, ENNReal.div_eq_top] push_neg simp refine ENNReal.Tendsto.div_const ?_ ?_ · have h := tendsto_measure_iInter (μ := κ a) (s := fun m ↦ countablePartitionSet n x ×ˢ seq m) ?_ ?_ ?_ · convert h rw [← prod_iInter, hseq_iInter] · exact fun m ↦ MeasurableSet.prod (measurableSet_countablePartitionSet _ _) (hseq_meas m) · intro m m' hmm' simp only [le_eq_subset, prod_subset_prod_iff, subset_rfl, true_and] exact Or.inl <| hseq hmm' · exact ⟨0, measure_ne_top _ _⟩ · exact .inr h0 lemma tendsto_densityProcess_atTop_of_antitone (κ : Kernel α (γ × β)) (ν : Kernel α γ) [IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ) (seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅) (hseq_meas : ∀ m, MeasurableSet (seq m)) : Tendsto (fun m ↦ densityProcess κ ν n a x (seq m)) atTop (𝓝 0) := by rw [← densityProcess_empty κ ν n a x] exact tendsto_densityProcess_atTop_empty_of_antitone κ ν n a x seq hseq hseq_iInter hseq_meas lemma tendsto_densityProcess_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : ∀ᵐ x ∂(ν a), Tendsto (fun n ↦ densityProcess κ ν n a x s) atTop (𝓝 ((countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a) x)) := by refine Submartingale.ae_tendsto_limitProcess (martingale_densityProcess hκν a hs).submartingale (R := (ν a univ).toNNReal) (fun n ↦ ?_) refine (eLpNorm_densityProcess_le hκν n a s).trans_eq ?_ rw [ENNReal.coe_toNNReal] exact measure_ne_top _ _ lemma memL1_limitProcess_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : Memℒp ((countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a)) 1 (ν a) := by refine Submartingale.memℒp_limitProcess (martingale_densityProcess hκν a hs).submartingale (R := (ν a univ).toNNReal) (fun n ↦ ?_) refine (eLpNorm_densityProcess_le hκν n a s).trans_eq ?_ rw [ENNReal.coe_toNNReal] exact measure_ne_top _ _ lemma tendsto_eLpNorm_one_densityProcess_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : Tendsto (fun n ↦ eLpNorm ((fun x ↦ densityProcess κ ν n a x s) - (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a)) 1 (ν a)) atTop (𝓝 0) := by refine Submartingale.tendsto_eLpNorm_one_limitProcess ?_ ?_ · exact (martingale_densityProcess hκν a hs).submartingale · refine uniformIntegrable_of le_rfl ENNReal.one_ne_top ?_ ?_ · exact fun n ↦ (measurable_densityProcess_right κ ν n a hs).aestronglyMeasurable · refine fun ε _ ↦ ⟨2, fun n ↦ le_of_eq_of_le ?_ (?_ : 0 ≤ ENNReal.ofReal ε)⟩ · suffices {x | 2 ≤ ‖densityProcess κ ν n a x s‖₊} = ∅ by simp [this] ext x simp only [mem_setOf_eq, mem_empty_iff_false, iff_false, not_le] refine (?_ : _ ≤ (1 : ℝ≥0)).trans_lt one_lt_two rw [Real.nnnorm_of_nonneg (densityProcess_nonneg _ _ _ _ _ _)] exact mod_cast (densityProcess_le_one hκν _ _ _ _) · simp @[deprecated (since := "2024-07-27")] alias tendsto_snorm_one_densityProcess_limitProcess := tendsto_eLpNorm_one_densityProcess_limitProcess lemma tendsto_eLpNorm_one_restrict_densityProcess_limitProcess [IsFiniteKernel ν] (hκν : fst κ ≤ ν) (a : α) {s : Set β} (hs : MeasurableSet s) (A : Set γ) : Tendsto (fun n ↦ eLpNorm ((fun x ↦ densityProcess κ ν n a x s) - (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a)) 1 ((ν a).restrict A)) atTop (𝓝 0) := tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (tendsto_eLpNorm_one_densityProcess_limitProcess hκν a hs) (fun _ ↦ zero_le') (fun _ ↦ eLpNorm_restrict_le _ _ _ _) @[deprecated (since := "2024-07-27")] alias tendsto_snorm_one_restrict_densityProcess_limitProcess := tendsto_eLpNorm_one_restrict_densityProcess_limitProcess end DensityProcess section Density /-- Density of the kernel `κ` with respect to `ν`. This is a function `α → γ → Set β → ℝ` which is measurable on `α × γ` for all measurable sets `s : Set β` and satisfies that `∫ x in A, density κ ν a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal` for all measurable `A : Set γ`. -/ noncomputable def density (κ : Kernel α (γ × β)) (ν : Kernel α γ) (a : α) (x : γ) (s : Set β) : ℝ := limsup (fun n ↦ densityProcess κ ν n a x s) atTop lemma density_ae_eq_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : (fun x ↦ density κ ν a x s) =ᵐ[ν a] (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a) := by filter_upwards [tendsto_densityProcess_limitProcess hκν a hs] with t ht using ht.limsup_eq lemma tendsto_m_density (hκν : fst κ ≤ ν) (a : α) [IsFiniteKernel ν] {s : Set β} (hs : MeasurableSet s) : ∀ᵐ x ∂(ν a), Tendsto (fun n ↦ densityProcess κ ν n a x s) atTop (𝓝 (density κ ν a x s)) := by filter_upwards [tendsto_densityProcess_limitProcess hκν a hs, density_ae_eq_limitProcess hκν a hs] with t h1 h2 using h2 ▸ h1 lemma measurable_density (κ : Kernel α (γ × β)) (ν : Kernel α γ) {s : Set β} (hs : MeasurableSet s) : Measurable (fun (p : α × γ) ↦ density κ ν p.1 p.2 s) := measurable_limsup (fun n ↦ measurable_densityProcess κ ν n hs) lemma measurable_density_left (κ : Kernel α (γ × β)) (ν : Kernel α γ) (x : γ) {s : Set β} (hs : MeasurableSet s) : Measurable (fun a ↦ density κ ν a x s) := by change Measurable ((fun (p : α × γ) ↦ density κ ν p.1 p.2 s) ∘ (fun a ↦ (a, x))) exact (measurable_density κ ν hs).comp measurable_prod_mk_right lemma measurable_density_right (κ : Kernel α (γ × β)) (ν : Kernel α γ) {s : Set β} (hs : MeasurableSet s) (a : α) : Measurable (fun x ↦ density κ ν a x s) := by change Measurable ((fun (p : α × γ) ↦ density κ ν p.1 p.2 s) ∘ (fun x ↦ (a, x))) exact (measurable_density κ ν hs).comp measurable_prod_mk_left lemma density_mono_set (hκν : fst κ ≤ ν) (a : α) (x : γ) {s s' : Set β} (h : s ⊆ s') : density κ ν a x s ≤ density κ ν a x s' := by refine limsup_le_limsup ?_ ?_ ?_ · exact eventually_of_forall (fun n ↦ densityProcess_mono_set hκν n a x h) · exact isCoboundedUnder_le_of_le atTop (fun i ↦ densityProcess_nonneg _ _ _ _ _ _) · exact isBoundedUnder_of ⟨1, fun n ↦ densityProcess_le_one hκν _ _ _ _⟩ lemma density_nonneg (hκν : fst κ ≤ ν) (a : α) (x : γ) (s : Set β) : 0 ≤ density κ ν a x s := by refine le_limsup_of_frequently_le ?_ ?_ · exact frequently_of_forall (fun n ↦ densityProcess_nonneg _ _ _ _ _ _) · exact isBoundedUnder_of ⟨1, fun n ↦ densityProcess_le_one hκν _ _ _ _⟩ lemma density_le_one (hκν : fst κ ≤ ν) (a : α) (x : γ) (s : Set β) : density κ ν a x s ≤ 1 := by refine limsup_le_of_le ?_ ?_ · exact isCoboundedUnder_le_of_le atTop (fun i ↦ densityProcess_nonneg _ _ _ _ _ _) · exact eventually_of_forall (fun n ↦ densityProcess_le_one hκν _ _ _ _) section Integral lemma eLpNorm_density_le (hκν : fst κ ≤ ν) (a : α) (s : Set β) : eLpNorm (fun x ↦ density κ ν a x s) 1 (ν a) ≤ ν a univ := by refine (eLpNorm_le_of_ae_bound (C := 1) (ae_of_all _ (fun t ↦ ?_))).trans ?_ · simp only [Real.norm_eq_abs, abs_of_nonneg (density_nonneg hκν a t s), density_le_one hκν a t s] · simp @[deprecated (since := "2024-07-27")] alias snorm_density_le := eLpNorm_density_le lemma integrable_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : Integrable (fun x ↦ density κ ν a x s) (ν a) := by rw [← memℒp_one_iff_integrable] refine ⟨Measurable.aestronglyMeasurable ?_, ?_⟩ · exact measurable_density_right κ ν hs a · exact (eLpNorm_density_le hκν a s).trans_lt (measure_lt_top _ _) lemma tendsto_setIntegral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) (A : Set γ) : Tendsto (fun i ↦ ∫ x in A, densityProcess κ ν i a x s ∂(ν a)) atTop (𝓝 (∫ x in A, density κ ν a x s ∂(ν a))) := by refine tendsto_setIntegral_of_L1' (μ := ν a) (fun x ↦ density κ ν a x s) (integrable_density hκν a hs) (F := fun i x ↦ densityProcess κ ν i a x s) (l := atTop) (eventually_of_forall (fun n ↦ integrable_densityProcess hκν _ _ hs)) ?_ A refine (tendsto_congr fun n ↦ ?_).mp (tendsto_eLpNorm_one_densityProcess_limitProcess hκν a hs) refine eLpNorm_congr_ae ?_ exact EventuallyEq.rfl.sub (density_ae_eq_limitProcess hκν a hs).symm @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_densityProcess := tendsto_setIntegral_densityProcess /-- Auxiliary lemma for `setIntegral_density`. -/ lemma setIntegral_density_of_measurableSet (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet[countableFiltration γ n] A) : ∫ x in A, density κ ν a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal := by suffices ∫ x in A, density κ ν a x s ∂(ν a) = ∫ x in A, densityProcess κ ν n a x s ∂(ν a) by exact this ▸ setIntegral_densityProcess hκν _ _ hs hA suffices ∫ x in A, density κ ν a x s ∂(ν a) = limsup (fun i ↦ ∫ x in A, densityProcess κ ν i a x s ∂(ν a)) atTop by rw [this, ← limsup_const (α := ℕ) (f := atTop) (∫ x in A, densityProcess κ ν n a x s ∂(ν a)), limsup_congr] simp only [eventually_atTop] refine ⟨n, fun m hnm ↦ ?_⟩ rw [setIntegral_densityProcess_of_le hκν hnm _ hs hA, setIntegral_densityProcess hκν _ _ hs hA] -- use L1 convergence have h := tendsto_setIntegral_densityProcess hκν a hs A rw [h.limsup_eq] @[deprecated (since := "2024-04-17")] alias set_integral_density_of_measurableSet := setIntegral_density_of_measurableSet lemma integral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : ∫ x, density κ ν a x s ∂(ν a) = (κ a (univ ×ˢ s)).toReal := by rw [← integral_univ, setIntegral_density_of_measurableSet hκν 0 a hs MeasurableSet.univ] lemma setIntegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet A) : ∫ x in A, density κ ν a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal := by have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν) have hA' : MeasurableSet[⨆ n, countableFiltration γ n] A := by rwa [iSup_countableFiltration] refine induction_on_inter (m := ⨆ n, countableFiltration γ n) (C := fun A ↦ ∫ x in A, density κ ν a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal) (measurableSpace_iSup_eq (countableFiltration γ)) ?_ ?_ ?_ ?_ ?_ hA' · rintro s ⟨n, hs⟩ t ⟨m, ht⟩ _ exact ⟨max n m, ((countableFiltration γ).mono (le_max_left n m) _ hs).inter ((countableFiltration γ).mono (le_max_right n m) _ ht)⟩ · simp · intro A ⟨n, hA⟩ exact setIntegral_density_of_measurableSet hκν n a hs hA · intro A hA hA_eq rw [iSup_countableFiltration] at hA have h := integral_add_compl hA (integrable_density hκν a hs) rw [hA_eq, integral_density hκν a hs] at h have : Aᶜ ×ˢ s = univ ×ˢ s \ A ×ˢ s := by rw [prod_diff_prod, compl_eq_univ_diff] simp rw [this, measure_diff (by intro x; simp) (hA.prod hs) (measure_ne_top (κ a) _), ENNReal.toReal_sub_of_le (measure_mono (by intro x; simp)) (measure_ne_top _ _)] rw [eq_tsub_iff_add_eq_of_le, add_comm] · exact h · rw [ENNReal.toReal_le_toReal (measure_ne_top _ _) (measure_ne_top _ _)] exact measure_mono (by intro x; simp) · intro f hf_disj hf h_eq rw [integral_iUnion _ hf_disj (integrable_density hκν _ hs).integrableOn] · simp_rw [h_eq] rw [← ENNReal.tsum_toReal_eq (fun _ ↦ measure_ne_top _ _)] congr rw [iUnion_prod_const, measure_iUnion] · intro i j hij rw [Function.onFun, Set.disjoint_prod] exact Or.inl (hf_disj hij) · rw [iSup_countableFiltration] at hf exact fun i ↦ (hf i).prod hs · rwa [iSup_countableFiltration] at hf @[deprecated (since := "2024-04-17")] alias set_integral_density := setIntegral_density lemma setLIntegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet A) : ∫⁻ x in A, ENNReal.ofReal (density κ ν a x s) ∂(ν a) = κ a (A ×ˢ s) := by have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν) rw [← ofReal_integral_eq_lintegral_ofReal] · rw [setIntegral_density hκν a hs hA, ENNReal.ofReal_toReal (measure_ne_top _ _)] · exact (integrable_density hκν a hs).restrict · exact ae_of_all _ (fun _ ↦ density_nonneg hκν _ _ _) @[deprecated (since := "2024-06-29")] alias set_lintegral_density := setLIntegral_density lemma lintegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) : ∫⁻ x, ENNReal.ofReal (density κ ν a x s) ∂(ν a) = κ a (univ ×ˢ s) := by rw [← setLIntegral_univ] exact setLIntegral_density hκν a hs MeasurableSet.univ end Integral lemma tendsto_integral_density_of_monotone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ) (hseq_meas : ∀ m, MeasurableSet (seq m)) : Tendsto (fun m ↦ ∫ x, density κ ν a x (seq m) ∂(ν a)) atTop (𝓝 (κ a univ).toReal) := by have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν) simp_rw [integral_density hκν a (hseq_meas _)] have h_cont := ENNReal.continuousOn_toReal.continuousAt (x := κ a univ) ?_ swap · rw [mem_nhds_iff] refine ⟨Iio (κ a univ + 1), fun x hx ↦ ne_top_of_lt (?_ : x < κ a univ + 1), isOpen_Iio, ?_⟩ · simpa using hx · simp only [mem_Iio] exact ENNReal.lt_add_right (measure_ne_top _ _) one_ne_zero refine h_cont.tendsto.comp ?_ have h := tendsto_measure_iUnion (s := fun m ↦ univ ×ˢ seq m) (μ := κ a) ?_ swap; · intro n m hnm x; simp only [mem_prod, mem_univ, true_and]; exact fun h ↦ hseq hnm h convert h rw [← prod_iUnion, hseq_iUnion] simp only [univ_prod_univ, measure_univ] lemma tendsto_integral_density_of_antitone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) (seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅) (hseq_meas : ∀ m, MeasurableSet (seq m)) : Tendsto (fun m ↦ ∫ x, density κ ν a x (seq m) ∂(ν a)) atTop (𝓝 0) := by have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν) simp_rw [integral_density hκν a (hseq_meas _)] rw [← ENNReal.zero_toReal] have h_cont := ENNReal.continuousOn_toReal.continuousAt (x := 0) ?_ swap · rw [mem_nhds_iff] refine ⟨Iio 1, fun x hx ↦ ne_top_of_lt (?_ : x < 1), isOpen_Iio, ?_⟩ · simpa using hx · simp refine h_cont.tendsto.comp ?_ have h := tendsto_measure_iInter (s := fun m ↦ univ ×ˢ seq m) (μ := κ a) (fun m ↦ MeasurableSet.univ.prod (hseq_meas m)) ?_ ?_ rotate_left · intro n m hnm x; simp only [mem_prod, mem_univ, true_and]; exact fun h ↦ hseq hnm h · refine ⟨0, measure_ne_top _ _⟩ convert h rw [← prod_iInter, hseq_iInter] simp lemma tendsto_density_atTop_ae_of_antitone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α) (seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅) (hseq_meas : ∀ m, MeasurableSet (seq m)) : ∀ᵐ x ∂(ν a), Tendsto (fun m ↦ density κ ν a x (seq m)) atTop (𝓝 0) := by refine tendsto_of_integral_tendsto_of_antitone ?_ (integrable_const _) ?_ ?_ ?_ · exact fun m ↦ integrable_density hκν _ (hseq_meas m) · rw [integral_zero] exact tendsto_integral_density_of_antitone hκν a seq hseq hseq_iInter hseq_meas · exact ae_of_all _ (fun c n m hnm ↦ density_mono_set hκν a c (hseq hnm)) · exact ae_of_all _ (fun x m ↦ density_nonneg hκν a x (seq m)) section UnivFst /-! We specialize to `ν = fst κ`, for which `density κ (fst κ) a t univ = 1` almost everywhere. -/ lemma densityProcess_fst_univ [IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ) : densityProcess κ (fst κ) n a x univ = if fst κ a (countablePartitionSet n x) = 0 then 0 else 1 := by rw [densityProcess] split_ifs with h · simp only [h] by_cases h' : κ a (countablePartitionSet n x ×ˢ univ) = 0 · simp [h'] · rw [ENNReal.div_zero h'] simp · rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] have : countablePartitionSet n x ×ˢ univ = {p : γ × β | p.1 ∈ countablePartitionSet n x} := by ext x simp rw [this, ENNReal.div_self] · simp · rwa [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h · exact measure_ne_top _ _ lemma densityProcess_fst_univ_ae (κ : Kernel α (γ × β)) [IsFiniteKernel κ] (n : ℕ) (a : α) : ∀ᵐ x ∂(fst κ a), densityProcess κ (fst κ) n a x univ = 1 := by rw [ae_iff] have : {x | ¬ densityProcess κ (fst κ) n a x univ = 1} ⊆ {x | fst κ a (countablePartitionSet n x) = 0} := by intro x hx simp only [mem_setOf_eq] at hx ⊢ rw [densityProcess_fst_univ] at hx simpa using hx refine measure_mono_null this ?_ have : {x | fst κ a (countablePartitionSet n x) = 0} ⊆ ⋃ (u) (_ : u ∈ countablePartition γ n) (_ : fst κ a u = 0), u := by intro t ht simp only [mem_setOf_eq, mem_iUnion, exists_prop] at ht ⊢ exact ⟨countablePartitionSet n t, countablePartitionSet_mem _ _, ht, mem_countablePartitionSet _ _⟩ refine measure_mono_null this ?_ rw [measure_biUnion] · simp · exact (finite_countablePartition _ _).countable · intro s hs t ht hst simp only [disjoint_iUnion_right, disjoint_iUnion_left] exact fun _ _ ↦ disjoint_countablePartition hs ht hst · intro s hs by_cases h : fst κ a s = 0 · simp [h, measurableSet_countablePartition n hs] · simp [h] lemma tendsto_densityProcess_fst_atTop_univ_of_monotone (κ : Kernel α (γ × β)) (n : ℕ) (a : α) (x : γ) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ) : Tendsto (fun m ↦ densityProcess κ (fst κ) n a x (seq m)) atTop (𝓝 (densityProcess κ (fst κ) n a x univ)) := by simp_rw [densityProcess] refine (ENNReal.tendsto_toReal ?_).comp ?_ · rw [ne_eq, ENNReal.div_eq_top] push_neg simp_rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] constructor · refine fun h h0 ↦ h (measure_mono_null (fun x ↦ ?_) h0) simp only [mem_prod, mem_setOf_eq, and_imp] exact fun h _ ↦ h · refine fun h_top ↦ eq_top_mono (measure_mono (fun x ↦ ?_)) h_top simp only [mem_prod, mem_setOf_eq, and_imp] exact fun h _ ↦ h by_cases h0 : fst κ a (countablePartitionSet n x) = 0 · rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h0 ⊢ suffices ∀ m, κ a (countablePartitionSet n x ×ˢ seq m) = 0 by simp only [this, h0, ENNReal.zero_div, tendsto_const_nhds_iff] suffices κ a (countablePartitionSet n x ×ˢ univ) = 0 by simp only [this, ENNReal.zero_div] convert h0 ext x simp only [mem_prod, mem_univ, and_true, mem_setOf_eq] refine fun m ↦ measure_mono_null (fun x ↦ ?_) h0 simp only [mem_prod, mem_setOf_eq, and_imp] exact fun h _ ↦ h refine ENNReal.Tendsto.div_const ?_ ?_ · have h := tendsto_measure_iUnion (μ := κ a) (s := fun m ↦ countablePartitionSet n x ×ˢ seq m) ?_ swap · intro m m' hmm' simp only [le_eq_subset, prod_subset_prod_iff, subset_rfl, true_and] exact Or.inl <| hseq hmm' convert h rw [← prod_iUnion, hseq_iUnion] · exact Or.inr h0 lemma tendsto_densityProcess_fst_atTop_ae_of_monotone (κ : Kernel α (γ × β)) [IsFiniteKernel κ] (n : ℕ) (a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ) : ∀ᵐ x ∂(fst κ a), Tendsto (fun m ↦ densityProcess κ (fst κ) n a x (seq m)) atTop (𝓝 1) := by filter_upwards [densityProcess_fst_univ_ae κ n a] with x hx rw [← hx] exact tendsto_densityProcess_fst_atTop_univ_of_monotone κ n a x seq hseq hseq_iUnion lemma density_fst_univ (κ : Kernel α (γ × β)) [IsFiniteKernel κ] (a : α) : ∀ᵐ x ∂(fst κ a), density κ (fst κ) a x univ = 1 := by have h := fun n ↦ densityProcess_fst_univ_ae κ n a rw [← ae_all_iff] at h filter_upwards [h] with x hx simp [density, hx] lemma tendsto_density_fst_atTop_ae_of_monotone [IsFiniteKernel κ] (a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ) (hseq_meas : ∀ m, MeasurableSet (seq m)) : ∀ᵐ x ∂(fst κ a), Tendsto (fun m ↦ density κ (fst κ) a x (seq m)) atTop (𝓝 1) := by refine tendsto_of_integral_tendsto_of_monotone ?_ (integrable_const _) ?_ ?_ ?_ · exact fun m ↦ integrable_density le_rfl _ (hseq_meas m) · rw [MeasureTheory.integral_const, smul_eq_mul, mul_one] convert tendsto_integral_density_of_monotone (κ := κ) le_rfl a seq hseq hseq_iUnion hseq_meas rw [fst_apply' _ _ MeasurableSet.univ] simp only [mem_univ, setOf_true] · exact ae_of_all _ (fun c n m hnm ↦ density_mono_set le_rfl a c (hseq hnm)) · exact ae_of_all _ (fun x m ↦ density_le_one le_rfl a x (seq m)) end UnivFst end Density end Kernel end ProbabilityTheory
Probability\Kernel\Disintegration\Integral.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.Probability.Kernel.Disintegration.StandardBorel /-! # Lebesgue and Bochner integrals of conditional kernels Integrals of `ProbabilityTheory.Kernel.condKernel` and `MeasureTheory.Measure.condKernel`. ## Main statements * `ProbabilityTheory.setIntegral_condKernel`: the integral `∫ b in s, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)` is equal to `∫ x in s ×ˢ t, f x ∂(κ a)`. * `MeasureTheory.Measure.setIntegral_condKernel`: `∫ b in s, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ t, f x ∂ρ` Corresponding statements for the Lebesgue integral and/or without the sets `s` and `t` are also provided. -/ open MeasureTheory ProbabilityTheory MeasurableSpace open scoped ENNReal namespace ProbabilityTheory variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] section Lintegral variable [CountableOrCountablyGenerated α β] {κ : Kernel α (β × Ω)} [IsFiniteKernel κ] {f : β × Ω → ℝ≥0∞} lemma lintegral_condKernel_mem (a : α) {s : Set (β × Ω)} (hs : MeasurableSet s) : ∫⁻ x, Kernel.condKernel κ (a, x) {y | (x, y) ∈ s} ∂(Kernel.fst κ a) = κ a s := by conv_rhs => rw [← κ.disintegrate κ.condKernel] simp_rw [Kernel.compProd_apply _ _ _ hs] lemma setLIntegral_condKernel_eq_measure_prod (a : α) {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b in s, Kernel.condKernel κ (a, b) t ∂(Kernel.fst κ a) = κ a (s ×ˢ t) := by have : κ a (s ×ˢ t) = (Kernel.fst κ ⊗ₖ Kernel.condKernel κ) a (s ×ˢ t) := by congr; exact (κ.disintegrate _).symm rw [this, Kernel.compProd_apply _ _ _ (hs.prod ht)] classical have : ∀ b, Kernel.condKernel κ (a, b) {c | (b, c) ∈ s ×ˢ t} = s.indicator (fun b ↦ Kernel.condKernel κ (a, b) t) b := by intro b by_cases hb : b ∈ s <;> simp [hb] simp_rw [this] rw [lintegral_indicator _ hs] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel_eq_measure_prod := setLIntegral_condKernel_eq_measure_prod lemma lintegral_condKernel (hf : Measurable f) (a : α) : ∫⁻ b, ∫⁻ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x, f x ∂(κ a) := by conv_rhs => rw [← κ.disintegrate κ.condKernel] rw [Kernel.lintegral_compProd _ _ _ hf] lemma setLIntegral_condKernel (hf : Measurable f) (a : α) {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b in s, ∫⁻ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x in s ×ˢ t, f x ∂(κ a) := by conv_rhs => rw [← κ.disintegrate κ.condKernel] rw [Kernel.setLIntegral_compProd _ _ _ hf hs ht] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel := setLIntegral_condKernel lemma setLIntegral_condKernel_univ_right (hf : Measurable f) (a : α) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, ∫⁻ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x in s ×ˢ Set.univ, f x ∂(κ a) := by rw [← setLIntegral_condKernel hf a hs MeasurableSet.univ]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel_univ_right := setLIntegral_condKernel_univ_right lemma setLIntegral_condKernel_univ_left (hf : Measurable f) (a : α) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b, ∫⁻ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫⁻ x in Set.univ ×ˢ t, f x ∂(κ a) := by rw [← setLIntegral_condKernel hf a MeasurableSet.univ ht]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel_univ_left := setLIntegral_condKernel_univ_left end Lintegral section Integral variable [CountableOrCountablyGenerated α β] {κ : Kernel α (β × Ω)} [IsFiniteKernel κ] {E : Type*} {f : β × Ω → E} [NormedAddCommGroup E] [NormedSpace ℝ E] lemma _root_.MeasureTheory.AEStronglyMeasurable.integral_kernel_condKernel (a : α) (hf : AEStronglyMeasurable f (κ a)) : AEStronglyMeasurable (fun x ↦ ∫ y, f (x, y) ∂(Kernel.condKernel κ (a, x))) (Kernel.fst κ a) := by rw [← κ.disintegrate κ.condKernel] at hf exact AEStronglyMeasurable.integral_kernel_compProd hf lemma integral_condKernel (a : α) (hf : Integrable f (κ a)) : ∫ b, ∫ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫ x, f x ∂(κ a) := by conv_rhs => rw [← κ.disintegrate κ.condKernel] rw [← κ.disintegrate κ.condKernel] at hf rw [integral_compProd hf] lemma setIntegral_condKernel (a : α) {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) (hf : IntegrableOn f (s ×ˢ t) (κ a)) : ∫ b in s, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫ x in s ×ˢ t, f x ∂(κ a) := by conv_rhs => rw [← κ.disintegrate κ.condKernel] rw [← κ.disintegrate κ.condKernel] at hf rw [setIntegral_compProd hs ht hf] @[deprecated (since := "2024-04-17")] alias set_integral_condKernel := setIntegral_condKernel lemma setIntegral_condKernel_univ_right (a : α) {s : Set β} (hs : MeasurableSet s) (hf : IntegrableOn f (s ×ˢ Set.univ) (κ a)) : ∫ b in s, ∫ ω, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫ x in s ×ˢ Set.univ, f x ∂(κ a) := by rw [← setIntegral_condKernel a hs MeasurableSet.univ hf]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-04-17")] alias set_integral_condKernel_univ_right := setIntegral_condKernel_univ_right lemma setIntegral_condKernel_univ_left (a : α) {t : Set Ω} (ht : MeasurableSet t) (hf : IntegrableOn f (Set.univ ×ˢ t) (κ a)) : ∫ b, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a) = ∫ x in Set.univ ×ˢ t, f x ∂(κ a) := by rw [← setIntegral_condKernel a MeasurableSet.univ ht hf]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-04-17")] alias set_integral_condKernel_univ_left := setIntegral_condKernel_univ_left end Integral end ProbabilityTheory namespace MeasureTheory.Measure variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] section Lintegral variable [CountableOrCountablyGenerated α β] {ρ : Measure (β × Ω)} [IsFiniteMeasure ρ] {f : β × Ω → ℝ≥0∞} lemma lintegral_condKernel_mem {s : Set (β × Ω)} (hs : MeasurableSet s) : ∫⁻ x, ρ.condKernel x {y | (x, y) ∈ s} ∂ρ.fst = ρ s := by conv_rhs => rw [← ρ.disintegrate ρ.condKernel] simp_rw [compProd_apply hs] rfl lemma setLIntegral_condKernel_eq_measure_prod {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b in s, ρ.condKernel b t ∂ρ.fst = ρ (s ×ˢ t) := by have : ρ (s ×ˢ t) = (ρ.fst ⊗ₘ ρ.condKernel) (s ×ˢ t) := by congr; exact (ρ.disintegrate _).symm rw [this, compProd_apply (hs.prod ht)] classical have : ∀ b, ρ.condKernel b (Prod.mk b ⁻¹' s ×ˢ t) = s.indicator (fun b ↦ ρ.condKernel b t) b := by intro b by_cases hb : b ∈ s <;> simp [hb] simp_rw [this] rw [lintegral_indicator _ hs] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel_eq_measure_prod := setLIntegral_condKernel_eq_measure_prod lemma lintegral_condKernel (hf : Measurable f) : ∫⁻ b, ∫⁻ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫⁻ x, f x ∂ρ := by conv_rhs => rw [← ρ.disintegrate ρ.condKernel] rw [lintegral_compProd hf] lemma setLIntegral_condKernel (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b in s, ∫⁻ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫⁻ x in s ×ˢ t, f x ∂ρ := by conv_rhs => rw [← ρ.disintegrate ρ.condKernel] rw [setLIntegral_compProd hf hs ht] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel := setLIntegral_condKernel lemma setLIntegral_condKernel_univ_right (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : ∫⁻ b in s, ∫⁻ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫⁻ x in s ×ˢ Set.univ, f x ∂ρ := by rw [← setLIntegral_condKernel hf hs MeasurableSet.univ]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel_univ_right := setLIntegral_condKernel_univ_right lemma setLIntegral_condKernel_univ_left (hf : Measurable f) {t : Set Ω} (ht : MeasurableSet t) : ∫⁻ b, ∫⁻ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫⁻ x in Set.univ ×ˢ t, f x ∂ρ := by rw [← setLIntegral_condKernel hf MeasurableSet.univ ht]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-06-29")] alias set_lintegral_condKernel_univ_left := setLIntegral_condKernel_univ_left end Lintegral section Integral variable {ρ : Measure (β × Ω)} [IsFiniteMeasure ρ] {E : Type*} {f : β × Ω → E} [NormedAddCommGroup E] [NormedSpace ℝ E] lemma _root_.MeasureTheory.AEStronglyMeasurable.integral_condKernel (hf : AEStronglyMeasurable f ρ) : AEStronglyMeasurable (fun x ↦ ∫ y, f (x, y) ∂ρ.condKernel x) ρ.fst := by rw [← ρ.disintegrate ρ.condKernel] at hf exact AEStronglyMeasurable.integral_kernel_compProd hf lemma integral_condKernel (hf : Integrable f ρ) : ∫ b, ∫ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x, f x ∂ρ := by conv_rhs => rw [← ρ.disintegrate ρ.condKernel] rw [← ρ.disintegrate ρ.condKernel] at hf rw [integral_compProd hf] lemma setIntegral_condKernel {s : Set β} (hs : MeasurableSet s) {t : Set Ω} (ht : MeasurableSet t) (hf : IntegrableOn f (s ×ˢ t) ρ) : ∫ b in s, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ t, f x ∂ρ := by conv_rhs => rw [← ρ.disintegrate ρ.condKernel] rw [← ρ.disintegrate ρ.condKernel] at hf rw [setIntegral_compProd hs ht hf] @[deprecated (since := "2024-04-17")] alias set_integral_condKernel := setIntegral_condKernel lemma setIntegral_condKernel_univ_right {s : Set β} (hs : MeasurableSet s) (hf : IntegrableOn f (s ×ˢ Set.univ) ρ) : ∫ b in s, ∫ ω, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ Set.univ, f x ∂ρ := by rw [← setIntegral_condKernel hs MeasurableSet.univ hf]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-04-17")] alias set_integral_condKernel_univ_right := setIntegral_condKernel_univ_right lemma setIntegral_condKernel_univ_left {t : Set Ω} (ht : MeasurableSet t) (hf : IntegrableOn f (Set.univ ×ˢ t) ρ) : ∫ b, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in Set.univ ×ˢ t, f x ∂ρ := by rw [← setIntegral_condKernel MeasurableSet.univ ht hf]; simp_rw [Measure.restrict_univ] @[deprecated (since := "2024-04-17")] alias set_integral_condKernel_univ_left := setIntegral_condKernel_univ_left end Integral end MeasureTheory.Measure namespace MeasureTheory /-! ### Integrability We place these lemmas in the `MeasureTheory` namespace to enable dot notation. -/ open ProbabilityTheory variable {α Ω E F : Type*} {mα : MeasurableSpace α} [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] {ρ : Measure (α × Ω)} [IsFiniteMeasure ρ] theorem AEStronglyMeasurable.ae_integrable_condKernel_iff {f : α × Ω → F} (hf : AEStronglyMeasurable f ρ) : (∀ᵐ a ∂ρ.fst, Integrable (fun ω ↦ f (a, ω)) (ρ.condKernel a)) ∧ Integrable (fun a ↦ ∫ ω, ‖f (a, ω)‖ ∂ρ.condKernel a) ρ.fst ↔ Integrable f ρ := by rw [← ρ.disintegrate ρ.condKernel] at hf conv_rhs => rw [← ρ.disintegrate ρ.condKernel] rw [Measure.integrable_compProd_iff hf] theorem Integrable.condKernel_ae {f : α × Ω → F} (hf_int : Integrable f ρ) : ∀ᵐ a ∂ρ.fst, Integrable (fun ω ↦ f (a, ω)) (ρ.condKernel a) := by have hf_ae : AEStronglyMeasurable f ρ := hf_int.1 rw [← hf_ae.ae_integrable_condKernel_iff] at hf_int exact hf_int.1 theorem Integrable.integral_norm_condKernel {f : α × Ω → F} (hf_int : Integrable f ρ) : Integrable (fun x ↦ ∫ y, ‖f (x, y)‖ ∂ρ.condKernel x) ρ.fst := by have hf_ae : AEStronglyMeasurable f ρ := hf_int.1 rw [← hf_ae.ae_integrable_condKernel_iff] at hf_int exact hf_int.2 theorem Integrable.norm_integral_condKernel {f : α × Ω → E} (hf_int : Integrable f ρ) : Integrable (fun x ↦ ‖∫ y, f (x, y) ∂ρ.condKernel x‖) ρ.fst := by refine hf_int.integral_norm_condKernel.mono hf_int.1.integral_condKernel.norm ?_ refine Filter.eventually_of_forall fun x ↦ ?_ rw [norm_norm] refine (norm_integral_le_integral_norm _).trans_eq (Real.norm_of_nonneg ?_).symm exact integral_nonneg_of_ae (Filter.eventually_of_forall fun y ↦ norm_nonneg _) theorem Integrable.integral_condKernel {f : α × Ω → E} (hf_int : Integrable f ρ) : Integrable (fun x ↦ ∫ y, f (x, y) ∂ρ.condKernel x) ρ.fst := (integrable_norm_iff hf_int.1.integral_condKernel).mp hf_int.norm_integral_condKernel end MeasureTheory
Probability\Kernel\Disintegration\MeasurableStieltjes.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.Data.Complex.Abs import Mathlib.MeasureTheory.Measure.GiryMonad import Mathlib.MeasureTheory.Measure.Stieltjes import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Measurable parametric Stieltjes functions We provide tools to build a measurable function `α → StieltjesFunction` with limits 0 at -∞ and 1 at +∞ for all `a : α` from a measurable function `f : α → ℚ → ℝ`. These measurable parametric Stieltjes functions are cumulative distribution functions (CDF) of transition kernels. The reason for going through `ℚ` instead of defining directly a Stieltjes function is that since `ℚ` is countable, building a measurable function is easier and we can obtain properties of the form `∀ᵐ (a : α) ∂μ, ∀ (q : ℚ), ...` (for some measure `μ` on `α`) by proving the weaker `∀ (q : ℚ), ∀ᵐ (a : α) ∂μ, ...`. This construction will be possible if `f a : ℚ → ℝ` satisfies a package of properties for all `a`: monotonicity, limits at +-∞ and a continuity property. We define `IsRatStieltjesPoint f a` to state that this is the case at `a` and define the property `IsMeasurableRatCDF f` that `f` is measurable and `IsRatStieltjesPoint f a` for all `a`. The function `α → StieltjesFunction` obtained by extending `f` by continuity from the right is then called `IsMeasurableRatCDF.stieltjesFunction`. In applications, we will often only have `IsRatStieltjesPoint f a` almost surely with respect to some measure. In order to turn that almost everywhere property into an everywhere property we define `toRatCDF (f : α → ℚ → ℝ) := fun a q ↦ if IsRatStieltjesPoint f a then f a q else defaultRatCDF q`, which satisfies the property `IsMeasurableRatCDF (toRatCDF f)`. Finally, we define `stieltjesOfMeasurableRat`, composition of `toRatCDF` and `IsMeasurableRatCDF.stieltjesFunction`. ## Main definitions * `stieltjesOfMeasurableRat`: turn a measurable function `f : α → ℚ → ℝ` into a measurable function `α → StieltjesFunction`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped NNReal ENNReal MeasureTheory Topology namespace ProbabilityTheory variable {α β ι : Type*} [MeasurableSpace α] section IsMeasurableRatCDF variable {f : α → ℚ → ℝ} /-- `a : α` is a Stieltjes point for `f : α → ℚ → ℝ` if `f a` is monotone with limit 0 at -∞ and 1 at +∞ and satisfies a continuity property. -/ structure IsRatStieltjesPoint (f : α → ℚ → ℝ) (a : α) : Prop where mono : Monotone (f a) tendsto_atTop_one : Tendsto (f a) atTop (𝓝 1) tendsto_atBot_zero : Tendsto (f a) atBot (𝓝 0) iInf_rat_gt_eq : ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t lemma isRatStieltjesPoint_unit_prod_iff (f : α → ℚ → ℝ) (a : α) : IsRatStieltjesPoint (fun p : Unit × α ↦ f p.2) ((), a) ↔ IsRatStieltjesPoint f a := by constructor <;> exact fun h ↦ ⟨h.mono, h.tendsto_atTop_one, h.tendsto_atBot_zero, h.iInf_rat_gt_eq⟩ lemma measurableSet_isRatStieltjesPoint (hf : Measurable f) : MeasurableSet {a | IsRatStieltjesPoint f a} := by have h1 : MeasurableSet {a | Monotone (f a)} := by change MeasurableSet {a | ∀ q r (_ : q ≤ r), f a q ≤ f a r} simp_rw [Set.setOf_forall] refine MeasurableSet.iInter (fun q ↦ ?_) refine MeasurableSet.iInter (fun r ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) exact measurableSet_le hf.eval hf.eval have h2 : MeasurableSet {a | Tendsto (f a) atTop (𝓝 1)} := measurableSet_tendsto _ (fun q ↦ hf.eval) have h3 : MeasurableSet {a | Tendsto (f a) atBot (𝓝 0)} := measurableSet_tendsto _ (fun q ↦ hf.eval) have h4 : MeasurableSet {a | ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t} := by rw [Set.setOf_forall] refine MeasurableSet.iInter (fun q ↦ ?_) exact measurableSet_eq_fun (measurable_iInf fun _ ↦ hf.eval) hf.eval suffices {a | IsRatStieltjesPoint f a} = ({a | Monotone (f a)} ∩ {a | Tendsto (f a) atTop (𝓝 1)} ∩ {a | Tendsto (f a) atBot (𝓝 0)} ∩ {a | ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t}) by rw [this] exact (((h1.inter h2).inter h3).inter h4) ext a simp only [mem_setOf_eq, mem_inter_iff] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · exact ⟨⟨⟨h.mono, h.tendsto_atTop_one⟩, h.tendsto_atBot_zero⟩, h.iInf_rat_gt_eq⟩ · exact ⟨h.1.1.1, h.1.1.2, h.1.2, h.2⟩ lemma IsRatStieltjesPoint.ite {f g : α → ℚ → ℝ} {a : α} (p : α → Prop) [DecidablePred p] (hf : p a → IsRatStieltjesPoint f a) (hg : ¬ p a → IsRatStieltjesPoint g a) : IsRatStieltjesPoint (fun a ↦ if p a then f a else g a) a where mono := by split_ifs with h; exacts [(hf h).mono, (hg h).mono] tendsto_atTop_one := by split_ifs with h; exacts [(hf h).tendsto_atTop_one, (hg h).tendsto_atTop_one] tendsto_atBot_zero := by split_ifs with h; exacts [(hf h).tendsto_atBot_zero, (hg h).tendsto_atBot_zero] iInf_rat_gt_eq := by split_ifs with h; exacts [(hf h).iInf_rat_gt_eq, (hg h).iInf_rat_gt_eq] /-- A function `f : α → ℚ → ℝ` is a (kernel) rational cumulative distribution function if it is measurable in the first argument and if `f a` satisfies a list of properties for all `a : α`: monotonicity between 0 at -∞ and 1 at +∞ and a form of continuity. A function with these properties can be extended to a measurable function `α → StieltjesFunction`. See `ProbabilityTheory.IsMeasurableRatCDF.stieltjesFunction`. -/ structure IsMeasurableRatCDF (f : α → ℚ → ℝ) : Prop where isRatStieltjesPoint : ∀ a, IsRatStieltjesPoint f a measurable : Measurable f lemma IsMeasurableRatCDF.nonneg {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) : 0 ≤ f a q := Monotone.le_of_tendsto (hf.isRatStieltjesPoint a).mono (hf.isRatStieltjesPoint a).tendsto_atBot_zero q lemma IsMeasurableRatCDF.le_one {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) : f a q ≤ 1 := Monotone.ge_of_tendsto (hf.isRatStieltjesPoint a).mono (hf.isRatStieltjesPoint a).tendsto_atTop_one q lemma IsMeasurableRatCDF.tendsto_atTop_one {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) : Tendsto (f a) atTop (𝓝 1) := (hf.isRatStieltjesPoint a).tendsto_atTop_one lemma IsMeasurableRatCDF.tendsto_atBot_zero {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) : Tendsto (f a) atBot (𝓝 0) := (hf.isRatStieltjesPoint a).tendsto_atBot_zero lemma IsMeasurableRatCDF.iInf_rat_gt_eq {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) : ⨅ r : Ioi q, f a r = f a q := (hf.isRatStieltjesPoint a).iInf_rat_gt_eq q end IsMeasurableRatCDF section DefaultRatCDF /-- A function with the property `IsMeasurableRatCDF`. Used in a piecewise construction to convert a function which only satisfies the properties defining `IsMeasurableRatCDF` on some set into a true `IsMeasurableRatCDF`. -/ def defaultRatCDF (q : ℚ) := if q < 0 then (0 : ℝ) else 1 lemma monotone_defaultRatCDF : Monotone defaultRatCDF := by unfold defaultRatCDF intro x y hxy dsimp only split_ifs with h_1 h_2 h_2 exacts [le_rfl, zero_le_one, absurd (hxy.trans_lt h_2) h_1, le_rfl] lemma defaultRatCDF_nonneg (q : ℚ) : 0 ≤ defaultRatCDF q := by unfold defaultRatCDF split_ifs exacts [le_rfl, zero_le_one] lemma defaultRatCDF_le_one (q : ℚ) : defaultRatCDF q ≤ 1 := by unfold defaultRatCDF split_ifs <;> simp lemma tendsto_defaultRatCDF_atTop : Tendsto defaultRatCDF atTop (𝓝 1) := by refine (tendsto_congr' ?_).mp tendsto_const_nhds rw [EventuallyEq, eventually_atTop] exact ⟨0, fun q hq => (if_neg (not_lt.mpr hq)).symm⟩ lemma tendsto_defaultRatCDF_atBot : Tendsto defaultRatCDF atBot (𝓝 0) := by refine (tendsto_congr' ?_).mp tendsto_const_nhds rw [EventuallyEq, eventually_atBot] refine ⟨-1, fun q hq => (if_pos (hq.trans_lt ?_)).symm⟩ linarith lemma iInf_rat_gt_defaultRatCDF (t : ℚ) : ⨅ r : Ioi t, defaultRatCDF r = defaultRatCDF t := by simp only [defaultRatCDF] have h_bdd : BddBelow (range fun r : ↥(Ioi t) ↦ ite ((r : ℚ) < 0) (0 : ℝ) 1) := by refine ⟨0, fun x hx ↦ ?_⟩ obtain ⟨y, rfl⟩ := mem_range.mpr hx dsimp only split_ifs exacts [le_rfl, zero_le_one] split_ifs with h · refine le_antisymm ?_ (le_ciInf fun x ↦ ?_) · obtain ⟨q, htq, hq_neg⟩ : ∃ q, t < q ∧ q < 0 := ⟨t / 2, by linarith, by linarith⟩ refine (ciInf_le h_bdd ⟨q, htq⟩).trans ?_ rw [if_pos] rwa [Subtype.coe_mk] · split_ifs exacts [le_rfl, zero_le_one] · refine le_antisymm ?_ ?_ · refine (ciInf_le h_bdd ⟨t + 1, lt_add_one t⟩).trans ?_ split_ifs exacts [zero_le_one, le_rfl] · refine le_ciInf fun x ↦ ?_ rw [if_neg] rw [not_lt] at h ⊢ exact h.trans (mem_Ioi.mp x.prop).le lemma isRatStieltjesPoint_defaultRatCDF (a : α) : IsRatStieltjesPoint (fun (_ : α) ↦ defaultRatCDF) a where mono := monotone_defaultRatCDF tendsto_atTop_one := tendsto_defaultRatCDF_atTop tendsto_atBot_zero := tendsto_defaultRatCDF_atBot iInf_rat_gt_eq := iInf_rat_gt_defaultRatCDF lemma IsMeasurableRatCDF_defaultRatCDF (α : Type*) [MeasurableSpace α] : IsMeasurableRatCDF (fun (_ : α) (q : ℚ) ↦ defaultRatCDF q) where isRatStieltjesPoint := isRatStieltjesPoint_defaultRatCDF measurable := measurable_const end DefaultRatCDF section ToRatCDF variable {f : α → ℚ → ℝ} open scoped Classical in /-- Turn a function `f : α → ℚ → ℝ` into another with the property `IsRatStieltjesPoint f a` everywhere. At `a` that does not satisfy that property, `f a` is replaced by an arbitrary suitable function. Mainly useful when `f` satisfies the property `IsRatStieltjesPoint f a` almost everywhere with respect to some measure. -/ noncomputable def toRatCDF (f : α → ℚ → ℝ) : α → ℚ → ℝ := fun a ↦ if IsRatStieltjesPoint f a then f a else defaultRatCDF lemma toRatCDF_of_isRatStieltjesPoint {a : α} (h : IsRatStieltjesPoint f a) (q : ℚ) : toRatCDF f a q = f a q := by rw [toRatCDF, if_pos h] lemma measurable_toRatCDF (hf : Measurable f) : Measurable (toRatCDF f) := Measurable.ite (measurableSet_isRatStieltjesPoint hf) hf measurable_const lemma isMeasurableRatCDF_toRatCDF (hf : Measurable f) : IsMeasurableRatCDF (toRatCDF f) where isRatStieltjesPoint a := by classical exact IsRatStieltjesPoint.ite (IsRatStieltjesPoint f) id (fun _ ↦ isRatStieltjesPoint_defaultRatCDF a) measurable := measurable_toRatCDF hf lemma toRatCDF_unit_prod (a : α) : toRatCDF (fun (p : Unit × α) ↦ f p.2) ((), a) = toRatCDF f a := by unfold toRatCDF rw [isRatStieltjesPoint_unit_prod_iff] end ToRatCDF section IsMeasurableRatCDF.stieltjesFunction /-- Auxiliary definition for `IsMeasurableRatCDF.stieltjesFunction`: turn `f : α → ℚ → ℝ` into a function `α → ℝ → ℝ` by assigning to `f a x` the infimum of `f a q` over `q : ℚ` with `x < q`. -/ noncomputable irreducible_def IsMeasurableRatCDF.stieltjesFunctionAux (f : α → ℚ → ℝ) : α → ℝ → ℝ := fun a x ↦ ⨅ q : { q' : ℚ // x < q' }, f a q lemma IsMeasurableRatCDF.stieltjesFunctionAux_def' (f : α → ℚ → ℝ) (a : α) : IsMeasurableRatCDF.stieltjesFunctionAux f a = fun (t : ℝ) ↦ ⨅ r : { r' : ℚ // t < r' }, f a r := by ext t; exact IsMeasurableRatCDF.stieltjesFunctionAux_def f a t lemma IsMeasurableRatCDF.stieltjesFunctionAux_unit_prod {f : α → ℚ → ℝ} (a : α) : IsMeasurableRatCDF.stieltjesFunctionAux (fun (p : Unit × α) ↦ f p.2) ((), a) = IsMeasurableRatCDF.stieltjesFunctionAux f a := by simp_rw [IsMeasurableRatCDF.stieltjesFunctionAux_def'] variable {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) lemma IsMeasurableRatCDF.stieltjesFunctionAux_eq (a : α) (r : ℚ) : IsMeasurableRatCDF.stieltjesFunctionAux f a r = f a r := by rw [← hf.iInf_rat_gt_eq a r, IsMeasurableRatCDF.stieltjesFunctionAux] refine Equiv.iInf_congr ?_ ?_ · exact { toFun := fun t ↦ ⟨t.1, mod_cast t.2⟩ invFun := fun t ↦ ⟨t.1, mod_cast t.2⟩ left_inv := fun t ↦ by simp only [Subtype.coe_eta] right_inv := fun t ↦ by simp only [Subtype.coe_eta] } · intro t simp only [Equiv.coe_fn_mk, Subtype.coe_mk] lemma IsMeasurableRatCDF.stieltjesFunctionAux_nonneg (a : α) (r : ℝ) : 0 ≤ IsMeasurableRatCDF.stieltjesFunctionAux f a r := by have : Nonempty { r' : ℚ // r < ↑r' } := by obtain ⟨r, hrx⟩ := exists_rat_gt r exact ⟨⟨r, hrx⟩⟩ rw [IsMeasurableRatCDF.stieltjesFunctionAux_def] exact le_ciInf fun r' ↦ hf.nonneg a _ lemma IsMeasurableRatCDF.monotone_stieltjesFunctionAux (a : α) : Monotone (IsMeasurableRatCDF.stieltjesFunctionAux f a) := by intro x y hxy have : Nonempty { r' : ℚ // y < ↑r' } := by obtain ⟨r, hrx⟩ := exists_rat_gt y exact ⟨⟨r, hrx⟩⟩ simp_rw [IsMeasurableRatCDF.stieltjesFunctionAux_def] refine le_ciInf fun r ↦ (ciInf_le ?_ ?_).trans_eq ?_ · refine ⟨0, fun z ↦ ?_⟩; rintro ⟨u, rfl⟩; exact hf.nonneg a _ · exact ⟨r.1, hxy.trans_lt r.prop⟩ · rfl lemma IsMeasurableRatCDF.continuousWithinAt_stieltjesFunctionAux_Ici (a : α) (x : ℝ) : ContinuousWithinAt (IsMeasurableRatCDF.stieltjesFunctionAux f a) (Ici x) x := by rw [← continuousWithinAt_Ioi_iff_Ici] convert Monotone.tendsto_nhdsWithin_Ioi (monotone_stieltjesFunctionAux hf a) x rw [sInf_image'] have h' : ⨅ r : Ioi x, stieltjesFunctionAux f a r = ⨅ r : { r' : ℚ // x < r' }, stieltjesFunctionAux f a r := by refine Real.iInf_Ioi_eq_iInf_rat_gt x ?_ (monotone_stieltjesFunctionAux hf a) refine ⟨0, fun z ↦ ?_⟩ rintro ⟨u, -, rfl⟩ exact stieltjesFunctionAux_nonneg hf a u have h'' : ⨅ r : { r' : ℚ // x < r' }, stieltjesFunctionAux f a r = ⨅ r : { r' : ℚ // x < r' }, f a r := by congr with r exact stieltjesFunctionAux_eq hf a r rw [h', h'', ContinuousWithinAt] congr! rw [stieltjesFunctionAux_def] /-- Extend a function `f : α → ℚ → ℝ` with property `IsMeasurableRatCDF` from `ℚ` to `ℝ`, to a function `α → StieltjesFunction`. -/ noncomputable def IsMeasurableRatCDF.stieltjesFunction (a : α) : StieltjesFunction where toFun := stieltjesFunctionAux f a mono' := monotone_stieltjesFunctionAux hf a right_continuous' x := continuousWithinAt_stieltjesFunctionAux_Ici hf a x lemma IsMeasurableRatCDF.stieltjesFunction_eq (a : α) (r : ℚ) : hf.stieltjesFunction a r = f a r := stieltjesFunctionAux_eq hf a r lemma IsMeasurableRatCDF.stieltjesFunction_nonneg (a : α) (r : ℝ) : 0 ≤ hf.stieltjesFunction a r := stieltjesFunctionAux_nonneg hf a r lemma IsMeasurableRatCDF.stieltjesFunction_le_one (a : α) (x : ℝ) : hf.stieltjesFunction a x ≤ 1 := by obtain ⟨r, hrx⟩ := exists_rat_gt x rw [← StieltjesFunction.iInf_rat_gt_eq] simp_rw [IsMeasurableRatCDF.stieltjesFunction_eq] refine ciInf_le_of_le ?_ ?_ (hf.le_one _ _) · refine ⟨0, fun z ↦ ?_⟩; rintro ⟨u, rfl⟩; exact hf.nonneg a _ · exact ⟨r, hrx⟩ lemma IsMeasurableRatCDF.tendsto_stieltjesFunction_atBot (a : α) : Tendsto (hf.stieltjesFunction a) atBot (𝓝 0) := by have h_exists : ∀ x : ℝ, ∃ q : ℚ, x < q ∧ ↑q < x + 1 := fun x ↦ exists_rat_btwn (lt_add_one x) let qs : ℝ → ℚ := fun x ↦ (h_exists x).choose have hqs_tendsto : Tendsto qs atBot atBot := by rw [tendsto_atBot_atBot] refine fun q ↦ ⟨q - 1, fun y hy ↦ ?_⟩ have h_le : ↑(qs y) ≤ (q : ℝ) - 1 + 1 := (h_exists y).choose_spec.2.le.trans (add_le_add hy le_rfl) rw [sub_add_cancel] at h_le exact mod_cast h_le refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds ((hf.tendsto_atBot_zero a).comp hqs_tendsto) (stieltjesFunction_nonneg hf a) fun x ↦ ?_ rw [Function.comp_apply, ← stieltjesFunction_eq hf] exact (hf.stieltjesFunction a).mono (h_exists x).choose_spec.1.le lemma IsMeasurableRatCDF.tendsto_stieltjesFunction_atTop (a : α) : Tendsto (hf.stieltjesFunction a) atTop (𝓝 1) := by have h_exists : ∀ x : ℝ, ∃ q : ℚ, x - 1 < q ∧ ↑q < x := fun x ↦ exists_rat_btwn (sub_one_lt x) let qs : ℝ → ℚ := fun x ↦ (h_exists x).choose have hqs_tendsto : Tendsto qs atTop atTop := by rw [tendsto_atTop_atTop] refine fun q ↦ ⟨q + 1, fun y hy ↦ ?_⟩ have h_le : y - 1 ≤ qs y := (h_exists y).choose_spec.1.le rw [sub_le_iff_le_add] at h_le exact_mod_cast le_of_add_le_add_right (hy.trans h_le) refine tendsto_of_tendsto_of_tendsto_of_le_of_le ((hf.tendsto_atTop_one a).comp hqs_tendsto) tendsto_const_nhds ?_ (stieltjesFunction_le_one hf a) intro x rw [Function.comp_apply, ← stieltjesFunction_eq hf] exact (hf.stieltjesFunction a).mono (le_of_lt (h_exists x).choose_spec.2) lemma IsMeasurableRatCDF.measurable_stieltjesFunction (x : ℝ) : Measurable fun a ↦ hf.stieltjesFunction a x := by have : (fun a ↦ hf.stieltjesFunction a x) = fun a ↦ ⨅ r : { r' : ℚ // x < r' }, f a ↑r := by ext1 a rw [← StieltjesFunction.iInf_rat_gt_eq] congr with q rw [stieltjesFunction_eq] rw [this] exact measurable_iInf (fun q ↦ hf.measurable.eval) lemma IsMeasurableRatCDF.stronglyMeasurable_stieltjesFunction (x : ℝ) : StronglyMeasurable fun a ↦ hf.stieltjesFunction a x := (measurable_stieltjesFunction hf x).stronglyMeasurable section Measure lemma IsMeasurableRatCDF.measure_stieltjesFunction_Iic (a : α) (x : ℝ) : (hf.stieltjesFunction a).measure (Iic x) = ENNReal.ofReal (hf.stieltjesFunction a x) := by rw [← sub_zero (hf.stieltjesFunction a x)] exact (hf.stieltjesFunction a).measure_Iic (tendsto_stieltjesFunction_atBot hf a) _ lemma IsMeasurableRatCDF.measure_stieltjesFunction_univ (a : α) : (hf.stieltjesFunction a).measure univ = 1 := by rw [← ENNReal.ofReal_one, ← sub_zero (1 : ℝ)] exact StieltjesFunction.measure_univ _ (tendsto_stieltjesFunction_atBot hf a) (tendsto_stieltjesFunction_atTop hf a) instance IsMeasurableRatCDF.instIsProbabilityMeasure_stieltjesFunction (a : α) : IsProbabilityMeasure (hf.stieltjesFunction a).measure := ⟨measure_stieltjesFunction_univ hf a⟩ lemma IsMeasurableRatCDF.measurable_measure_stieltjesFunction : Measurable fun a ↦ (hf.stieltjesFunction a).measure := by rw [Measure.measurable_measure] refine fun s hs ↦ MeasurableSpace.induction_on_inter (C := fun s ↦ Measurable fun b ↦ StieltjesFunction.measure (hf.stieltjesFunction b) s) (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic ?_ ?_ ?_ ?_ hs · simp only [measure_empty, measurable_const] · rintro S ⟨u, rfl⟩ simp_rw [measure_stieltjesFunction_Iic hf _ u] exact (measurable_stieltjesFunction hf u).ennreal_ofReal · intro t ht ht_cd_meas have : (fun a ↦ (hf.stieltjesFunction a).measure tᶜ) = (fun a ↦ (hf.stieltjesFunction a).measure univ) - fun a ↦ (hf.stieltjesFunction a).measure t := by ext1 a rw [measure_compl ht (measure_ne_top (hf.stieltjesFunction a).measure _), Pi.sub_apply] simp_rw [this, measure_stieltjesFunction_univ hf] exact Measurable.sub measurable_const ht_cd_meas · intro f hf_disj hf_meas hf_cd_meas simp_rw [measure_iUnion hf_disj hf_meas] exact Measurable.ennreal_tsum hf_cd_meas end Measure end IsMeasurableRatCDF.stieltjesFunction section stieltjesOfMeasurableRat variable {f : α → ℚ → ℝ} /-- Turn a measurable function `f : α → ℚ → ℝ` into a measurable function `α → StieltjesFunction`. Composition of `toRatCDF` and `IsMeasurableRatCDF.stieltjesFunction`. -/ noncomputable def stieltjesOfMeasurableRat (f : α → ℚ → ℝ) (hf : Measurable f) : α → StieltjesFunction := (isMeasurableRatCDF_toRatCDF hf).stieltjesFunction lemma stieltjesOfMeasurableRat_eq (hf : Measurable f) (a : α) (r : ℚ) : stieltjesOfMeasurableRat f hf a r = toRatCDF f a r := IsMeasurableRatCDF.stieltjesFunction_eq _ a r lemma stieltjesOfMeasurableRat_unit_prod (hf : Measurable f) (a : α) : stieltjesOfMeasurableRat (fun (p : Unit × α) ↦ f p.2) (hf.comp measurable_snd) ((), a) = stieltjesOfMeasurableRat f hf a := by simp_rw [stieltjesOfMeasurableRat,IsMeasurableRatCDF.stieltjesFunction, ← IsMeasurableRatCDF.stieltjesFunctionAux_unit_prod a] congr with x congr 1 with p : 1 cases p with | mk _ b => rw [← toRatCDF_unit_prod b] lemma stieltjesOfMeasurableRat_nonneg (hf : Measurable f) (a : α) (r : ℝ) : 0 ≤ stieltjesOfMeasurableRat f hf a r := IsMeasurableRatCDF.stieltjesFunction_nonneg _ a r lemma stieltjesOfMeasurableRat_le_one (hf : Measurable f) (a : α) (x : ℝ) : stieltjesOfMeasurableRat f hf a x ≤ 1 := IsMeasurableRatCDF.stieltjesFunction_le_one _ a x lemma tendsto_stieltjesOfMeasurableRat_atBot (hf : Measurable f) (a : α) : Tendsto (stieltjesOfMeasurableRat f hf a) atBot (𝓝 0) := IsMeasurableRatCDF.tendsto_stieltjesFunction_atBot _ a lemma tendsto_stieltjesOfMeasurableRat_atTop (hf : Measurable f) (a : α) : Tendsto (stieltjesOfMeasurableRat f hf a) atTop (𝓝 1) := IsMeasurableRatCDF.tendsto_stieltjesFunction_atTop _ a lemma measurable_stieltjesOfMeasurableRat (hf : Measurable f) (x : ℝ) : Measurable fun a ↦ stieltjesOfMeasurableRat f hf a x := IsMeasurableRatCDF.measurable_stieltjesFunction _ x lemma stronglyMeasurable_stieltjesOfMeasurableRat (hf : Measurable f) (x : ℝ) : StronglyMeasurable fun a ↦ stieltjesOfMeasurableRat f hf a x := IsMeasurableRatCDF.stronglyMeasurable_stieltjesFunction _ x section Measure lemma measure_stieltjesOfMeasurableRat_Iic (hf : Measurable f) (a : α) (x : ℝ) : (stieltjesOfMeasurableRat f hf a).measure (Iic x) = ENNReal.ofReal (stieltjesOfMeasurableRat f hf a x) := IsMeasurableRatCDF.measure_stieltjesFunction_Iic _ _ _ lemma measure_stieltjesOfMeasurableRat_univ (hf : Measurable f) (a : α) : (stieltjesOfMeasurableRat f hf a).measure univ = 1 := IsMeasurableRatCDF.measure_stieltjesFunction_univ _ _ instance instIsProbabilityMeasure_stieltjesOfMeasurableRat (hf : Measurable f) (a : α) : IsProbabilityMeasure (stieltjesOfMeasurableRat f hf a).measure := IsMeasurableRatCDF.instIsProbabilityMeasure_stieltjesFunction _ _ lemma measurable_measure_stieltjesOfMeasurableRat (hf : Measurable f) : Measurable fun a ↦ (stieltjesOfMeasurableRat f hf a).measure := IsMeasurableRatCDF.measurable_measure_stieltjesFunction _ end Measure end stieltjesOfMeasurableRat end ProbabilityTheory
Probability\Kernel\Disintegration\StandardBorel.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.Probability.Kernel.MeasureCompProd import Mathlib.Probability.Kernel.Disintegration.Basic import Mathlib.Probability.Kernel.Disintegration.CondCDF import Mathlib.Probability.Kernel.Disintegration.Density import Mathlib.Probability.Kernel.Disintegration.CDFToKernel import Mathlib.MeasureTheory.Constructions.Polish.EmbeddingReal /-! # Existence of disintegration of measures and kernels for standard Borel spaces Let `κ : Kernel α (β × Ω)` be a finite kernel, where `Ω` is a standard Borel space. Then if `α` is countable or `β` has a countably generated σ-algebra (for example if it is standard Borel), then there exists a `Kernel (α × β) Ω` called conditional kernel and denoted by `condKernel κ` such that `κ = fst κ ⊗ₖ condKernel κ`. We also define a conditional kernel for a measure `ρ : Measure (β × Ω)`, where `Ω` is a standard Borel space. This is a `Kernel β Ω` denoted by `ρ.condKernel` such that `ρ = ρ.fst ⊗ₘ ρ.condKernel`. In order to obtain a disintegration for any standard Borel space `Ω`, we use that these spaces embed measurably into `ℝ`: it then suffices to define a suitable kernel for `Ω = ℝ`. For `κ : Kernel α (β × ℝ)`, the construction of the conditional kernel proceeds as follows: * Build a measurable function `f : (α × β) → ℚ → ℝ` such that for all measurable sets `s` and all `q : ℚ`, `∫ x in s, f (a, x) q ∂(Kernel.fst κ a) = (κ a (s ×ˢ Iic (q : ℝ))).toReal`. We restrict to `ℚ` here to be able to prove the measurability. * Extend that function to `(α × β) → StieltjesFunction`. See the file `MeasurableStieltjes.lean`. * Finally obtain from the measurable Stieltjes function a measure on `ℝ` for each element of `α × β` in a measurable way: we have obtained a `Kernel (α × β) ℝ`. See the file `CDFToKernel.lean` for that step. The first step (building the measurable function on `ℚ`) is done differently depending on whether `α` is countable or not. * If `α` is countable, we can provide for each `a : α` a function `f : β → ℚ → ℝ` and proceed as above to obtain a `Kernel β ℝ`. Since `α` is countable, measurability is not an issue and we can put those together into a `Kernel (α × β) ℝ`. The construction of that `f` is done in the `CondCDF.lean` file. * If `α` is not countable, we can't proceed separately for each `a : α` and have to build a function `f : α × β → ℚ → ℝ` which is measurable on the product. We are able to do so if `β` has a countably generated σ-algebra (this is the case in particular for standard Borel spaces). See the file `Density.lean`. The conditional kernel is defined under the typeclass assumption `CountableOrCountablyGenerated α β`, which encodes the property `Countable α ∨ CountablyGenerated β`. Properties of integrals involving `condKernel` are collated in the file `Integral.lean`. The conditional kernel is unique (almost everywhere w.r.t. `fst κ`): this is proved in the file `Unique.lean`. ## Main definitions * `ProbabilityTheory.Kernel.condKernel κ : Kernel (α × β) Ω`: conditional kernel described above. * `MeasureTheory.Measure.condKernel ρ : Kernel β Ω`: conditional kernel of a measure. ## Main statements * `ProbabilityTheory.Kernel.compProd_fst_condKernel`: `fst κ ⊗ₖ condKernel κ = κ` * `MeasureTheory.Measure.compProd_fst_condKernel`: `ρ.fst ⊗ₘ ρ.condKernel = ρ` -/ open MeasureTheory Set Filter MeasurableSpace open scoped ENNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory.Kernel variable {α β γ Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} [MeasurableSpace.CountablyGenerated γ] [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] section Real /-! ### Disintegration of kernels from `α` to `γ × ℝ` for countably generated `γ` -/ lemma isRatCondKernelCDFAux_density_Iic (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : IsRatCondKernelCDFAux (fun (p : α × γ) q ↦ density κ (fst κ) p.1 p.2 (Iic q)) κ (fst κ) where measurable := measurable_pi_iff.mpr fun _ ↦ measurable_density κ (fst κ) measurableSet_Iic mono' a q r hqr := ae_of_all _ fun c ↦ density_mono_set le_rfl a c (Iic_subset_Iic.mpr (by exact_mod_cast hqr)) nonneg' a q := ae_of_all _ fun c ↦ density_nonneg le_rfl _ _ _ le_one' a q := ae_of_all _ fun c ↦ density_le_one le_rfl _ _ _ tendsto_integral_of_antitone a s hs_anti hs_tendsto := by let s' : ℕ → Set ℝ := fun n ↦ Iic (s n) refine tendsto_integral_density_of_antitone le_rfl a s' ?_ ?_ (fun _ ↦ measurableSet_Iic) · refine fun i j hij ↦ Iic_subset_Iic.mpr ?_ exact mod_cast hs_anti hij · ext x simp only [mem_iInter, mem_Iic, mem_empty_iff_false, iff_false, not_forall, not_le, s'] rw [tendsto_atTop_atBot] at hs_tendsto have ⟨q, hq⟩ := exists_rat_lt x obtain ⟨i, hi⟩ := hs_tendsto q refine ⟨i, lt_of_le_of_lt ?_ hq⟩ exact mod_cast hi i le_rfl tendsto_integral_of_monotone a s hs_mono hs_tendsto := by rw [fst_apply' _ _ MeasurableSet.univ] let s' : ℕ → Set ℝ := fun n ↦ Iic (s n) refine tendsto_integral_density_of_monotone (le_rfl : fst κ ≤ fst κ) a s' ?_ ?_ (fun _ ↦ measurableSet_Iic) · exact fun i j hij ↦ Iic_subset_Iic.mpr (by exact mod_cast hs_mono hij) · ext x simp only [mem_iUnion, mem_Iic, mem_univ, iff_true] rw [tendsto_atTop_atTop] at hs_tendsto have ⟨q, hq⟩ := exists_rat_gt x obtain ⟨i, hi⟩ := hs_tendsto q refine ⟨i, hq.le.trans ?_⟩ exact mod_cast hi i le_rfl integrable a q := integrable_density le_rfl a measurableSet_Iic setIntegral a A hA q := setIntegral_density le_rfl a measurableSet_Iic hA /-- Taking the kernel density of intervals `Iic q` for `q : ℚ` gives a function with the property `isRatCondKernelCDF`. -/ lemma isRatCondKernelCDF_density_Iic (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : IsRatCondKernelCDF (fun (p : α × γ) q ↦ density κ (fst κ) p.1 p.2 (Iic q)) κ (fst κ) := (isRatCondKernelCDFAux_density_Iic κ).isRatCondKernelCDF /-- The conditional kernel CDF of a kernel `κ : Kernel α (γ × ℝ)`, where `γ` is countably generated. -/ noncomputable def condKernelCDF (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : α × γ → StieltjesFunction := stieltjesOfMeasurableRat (fun (p : α × γ) q ↦ density κ (fst κ) p.1 p.2 (Iic q)) (isRatCondKernelCDF_density_Iic κ).measurable lemma isCondKernelCDF_condKernelCDF (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : IsCondKernelCDF (condKernelCDF κ) κ (fst κ) := isCondKernelCDF_stieltjesOfMeasurableRat (isRatCondKernelCDF_density_Iic κ) /-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`. A conditional kernel for `κ : Kernel α (γ × ℝ)` where `γ` is countably generated. -/ noncomputable def condKernelReal (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : Kernel (α × γ) ℝ := (isCondKernelCDF_condKernelCDF κ).toKernel instance instIsMarkovKernelCondKernelReal (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : IsMarkovKernel (condKernelReal κ) := by rw [condKernelReal] infer_instance lemma compProd_fst_condKernelReal (κ : Kernel α (γ × ℝ)) [IsFiniteKernel κ] : fst κ ⊗ₖ condKernelReal κ = κ := by rw [condKernelReal, compProd_toKernel] /-- Auxiliary definition for `MeasureTheory.Measure.condKernel` and `ProbabilityTheory.Kernel.condKernel`. A conditional kernel for `κ : Kernel Unit (α × ℝ)`. -/ noncomputable def condKernelUnitReal (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] : Kernel (Unit × α) ℝ := (isCondKernelCDF_condCDF (κ ())).toKernel instance instIsMarkovKernelCondKernelUnitReal (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] : IsMarkovKernel (condKernelUnitReal κ) := by rw [condKernelUnitReal] infer_instance instance condKernelUnitReal.instIsCondKernel (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] : κ.IsCondKernel κ.condKernelUnitReal where disintegrate := by rw [condKernelUnitReal, compProd_toKernel]; ext; simp @[deprecated disintegrate (since := "2024-07-26")] lemma compProd_fst_condKernelUnitReal (κ : Kernel Unit (α × ℝ)) [IsFiniteKernel κ] : fst κ ⊗ₖ condKernelUnitReal κ = κ := disintegrate _ _ end Real section BorelSnd /-! ### Disintegration of kernels on standard Borel spaces Since every standard Borel space embeds measurably into `ℝ`, we can generalize a disintegration property on `ℝ` to all these spaces. -/ open Classical in /-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`. A Borel space `Ω` embeds measurably into `ℝ` (with embedding `e`), hence we can get a `Kernel α Ω` from a `Kernel α ℝ` by taking the comap by `e`. Here we take the comap of a modification of `η : Kernel α ℝ`, useful when `η a` is a probability measure with all its mass on `range e` almost everywhere with respect to some measure and we want to ensure that the comap is a Markov kernel. We thus take the comap by `e` of a kernel defined piecewise: `η` when `η a (range (embeddingReal Ω))ᶜ = 0`, and an arbitrary deterministic kernel otherwise. -/ noncomputable def borelMarkovFromReal (Ω : Type*) [Nonempty Ω] [MeasurableSpace Ω] [StandardBorelSpace Ω] (η : Kernel α ℝ) : Kernel α Ω := have he := measurableEmbedding_embeddingReal Ω let x₀ := (range_nonempty (embeddingReal Ω)).choose comapRight (piecewise ((Kernel.measurable_coe η he.measurableSet_range.compl) (measurableSet_singleton 0) : MeasurableSet {a | η a (range (embeddingReal Ω))ᶜ = 0}) η (deterministic (fun _ ↦ x₀) measurable_const)) he lemma borelMarkovFromReal_apply (Ω : Type*) [Nonempty Ω] [MeasurableSpace Ω] [StandardBorelSpace Ω] (η : Kernel α ℝ) (a : α) : borelMarkovFromReal Ω η a = if η a (range (embeddingReal Ω))ᶜ = 0 then (η a).comap (embeddingReal Ω) else (Measure.dirac (range_nonempty (embeddingReal Ω)).choose).comap (embeddingReal Ω) := by classical rw [borelMarkovFromReal, comapRight_apply, piecewise_apply, deterministic_apply] simp only [mem_preimage, mem_singleton_iff] split_ifs <;> rfl lemma borelMarkovFromReal_apply' (Ω : Type*) [Nonempty Ω] [MeasurableSpace Ω] [StandardBorelSpace Ω] (η : Kernel α ℝ) (a : α) {s : Set Ω} (hs : MeasurableSet s) : borelMarkovFromReal Ω η a s = if η a (range (embeddingReal Ω))ᶜ = 0 then η a (embeddingReal Ω '' s) else (embeddingReal Ω '' s).indicator 1 (range_nonempty (embeddingReal Ω)).choose := by have he := measurableEmbedding_embeddingReal Ω rw [borelMarkovFromReal_apply] split_ifs with h · rw [Measure.comap_apply _ he.injective he.measurableSet_image' _ hs] · rw [Measure.comap_apply _ he.injective he.measurableSet_image' _ hs, Measure.dirac_apply] /-- When `η` is an s-finite kernel, `borelMarkovFromReal Ω η` is an s-finite kernel. -/ instance instIsSFiniteKernelBorelMarkovFromReal (η : Kernel α ℝ) [IsSFiniteKernel η] : IsSFiniteKernel (borelMarkovFromReal Ω η) := IsSFiniteKernel.comapRight _ (measurableEmbedding_embeddingReal Ω) /-- When `η` is a finite kernel, `borelMarkovFromReal Ω η` is a finite kernel. -/ instance instIsFiniteKernelBorelMarkovFromReal (η : Kernel α ℝ) [IsFiniteKernel η] : IsFiniteKernel (borelMarkovFromReal Ω η) := IsFiniteKernel.comapRight _ (measurableEmbedding_embeddingReal Ω) /-- When `η` is a Markov kernel, `borelMarkovFromReal Ω η` is a Markov kernel. -/ instance instIsMarkovKernelBorelMarkovFromReal (η : Kernel α ℝ) [IsMarkovKernel η] : IsMarkovKernel (borelMarkovFromReal Ω η) := by refine IsMarkovKernel.comapRight _ (measurableEmbedding_embeddingReal Ω) (fun a ↦ ?_) classical rw [piecewise_apply] split_ifs with h · rwa [← prob_compl_eq_zero_iff (measurableEmbedding_embeddingReal Ω).measurableSet_range] · rw [deterministic_apply] simp [(range_nonempty (embeddingReal Ω)).choose_spec] /-- For `κ' := map κ (Prod.map (id : β → β) e) (measurable_id.prod_map he.measurable)`, the hypothesis `hη` is `fst κ' ⊗ₖ η = κ'`. The conclusion of the lemma is `fst κ ⊗ₖ borelMarkovFromReal Ω η = comapRight (fst κ' ⊗ₖ η) _`. -/ lemma compProd_fst_borelMarkovFromReal_eq_comapRight_compProd (κ : Kernel α (β × Ω)) [IsSFiniteKernel κ] (η : Kernel (α × β) ℝ) [IsSFiniteKernel η] (hη : (fst (map κ (Prod.map (id : β → β) (embeddingReal Ω)) (measurable_id.prod_map (measurableEmbedding_embeddingReal Ω).measurable))) ⊗ₖ η = map κ (Prod.map (id : β → β) (embeddingReal Ω)) (measurable_id.prod_map (measurableEmbedding_embeddingReal Ω).measurable)) : fst κ ⊗ₖ borelMarkovFromReal Ω η = comapRight (fst (map κ (Prod.map (id : β → β) (embeddingReal Ω)) (measurable_id.prod_map (measurableEmbedding_embeddingReal Ω).measurable)) ⊗ₖ η) (MeasurableEmbedding.id.prod_mk (measurableEmbedding_embeddingReal Ω)) := by let e := embeddingReal Ω let he := measurableEmbedding_embeddingReal Ω let κ' := map κ (Prod.map (id : β → β) e) (measurable_id.prod_map he.measurable) have hη' : fst κ' ⊗ₖ η = κ' := hη have h_prod_embed : MeasurableEmbedding (Prod.map (id : β → β) e) := MeasurableEmbedding.id.prod_mk he change fst κ ⊗ₖ borelMarkovFromReal Ω η = comapRight (fst κ' ⊗ₖ η) h_prod_embed rw [comapRight_compProd_id_prod _ _ he] have h_fst : fst κ' = fst κ := by ext a u unfold_let κ' rw [fst_apply, map_apply, Measure.map_map measurable_fst h_prod_embed.measurable, fst_apply] congr rw [h_fst] ext a t ht : 2 simp_rw [compProd_apply _ _ _ ht] refine lintegral_congr_ae ?_ have h_ae : ∀ᵐ t ∂(fst κ a), (a, t) ∈ {p : α × β | η p (range e)ᶜ = 0} := by rw [← h_fst] have h_compProd : κ' a (univ ×ˢ range e)ᶜ = 0 := by unfold_let κ' rw [map_apply'] swap; · exact (MeasurableSet.univ.prod he.measurableSet_range).compl suffices Prod.map id e ⁻¹' (univ ×ˢ range e)ᶜ = ∅ by rw [this]; simp ext x simp rw [← hη', compProd_null] at h_compProd swap; · exact (MeasurableSet.univ.prod he.measurableSet_range).compl simp only [preimage_compl, mem_univ, mk_preimage_prod_right] at h_compProd exact h_compProd filter_upwards [h_ae] with a ha rw [borelMarkovFromReal, comapRight_apply', comapRight_apply'] rotate_left · exact measurable_prod_mk_left ht · exact measurable_prod_mk_left ht classical rw [piecewise_apply, if_pos] exact ha /-- For `κ' := map κ (Prod.map (id : β → β) e) (measurable_id.prod_map he.measurable)`, the hypothesis `hη` is `fst κ' ⊗ₖ η = κ'`. With that hypothesis, `fst κ ⊗ₖ borelMarkovFromReal κ η = κ`.-/ lemma compProd_fst_borelMarkovFromReal (κ : Kernel α (β × Ω)) [IsSFiniteKernel κ] (η : Kernel (α × β) ℝ) [IsSFiniteKernel η] (hη : (fst (map κ (Prod.map (id : β → β) (embeddingReal Ω)) (measurable_id.prod_map (measurableEmbedding_embeddingReal Ω).measurable))) ⊗ₖ η = map κ (Prod.map (id : β → β) (embeddingReal Ω)) (measurable_id.prod_map (measurableEmbedding_embeddingReal Ω).measurable)) : fst κ ⊗ₖ borelMarkovFromReal Ω η = κ := by let e := embeddingReal Ω let he := measurableEmbedding_embeddingReal Ω let κ' := map κ (Prod.map (id : β → β) e) (measurable_id.prod_map he.measurable) have hη' : fst κ' ⊗ₖ η = κ' := hη have h_prod_embed : MeasurableEmbedding (Prod.map (id : β → β) e) := MeasurableEmbedding.id.prod_mk he have : κ = comapRight κ' h_prod_embed := by ext c t : 2 unfold_let κ' rw [comapRight_apply, map_apply, h_prod_embed.comap_map] conv_rhs => rw [this, ← hη'] exact compProd_fst_borelMarkovFromReal_eq_comapRight_compProd κ η hη end BorelSnd section CountablyGenerated open ProbabilityTheory.Kernel /-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`. A conditional kernel for `κ : Kernel α (γ × Ω)` where `γ` is countably generated and `Ω` is standard Borel. -/ noncomputable def condKernelBorel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] : Kernel (α × γ) Ω := let e := embeddingReal Ω let he := measurableEmbedding_embeddingReal Ω let κ' := map κ (Prod.map (id : γ → γ) e) (measurable_id.prod_map he.measurable) borelMarkovFromReal Ω (condKernelReal κ') instance instIsMarkovKernelCondKernelBorel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] : IsMarkovKernel (condKernelBorel κ) := by rw [condKernelBorel] infer_instance instance condKernelBorel.instIsCondKernel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] : κ.IsCondKernel κ.condKernelBorel where disintegrate := by rw [condKernelBorel, compProd_fst_borelMarkovFromReal _ _ (compProd_fst_condKernelReal _)] @[deprecated disintegrate (since := "2024-07-26")] lemma compProd_fst_condKernelBorel (κ : Kernel α (γ × Ω)) [IsFiniteKernel κ] : fst κ ⊗ₖ condKernelBorel κ = κ := disintegrate _ _ end CountablyGenerated section Unit variable (κ : Kernel Unit (α × Ω)) [IsFiniteKernel κ] /-- Auxiliary definition for `MeasureTheory.Measure.condKernel` and `ProbabilityTheory.Kernel.condKernel`. A conditional kernel for `κ : Kernel Unit (α × Ω)` where `Ω` is standard Borel. -/ noncomputable def condKernelUnitBorel : Kernel (Unit × α) Ω := let e := embeddingReal Ω let he := measurableEmbedding_embeddingReal Ω let κ' := map κ (Prod.map (id : α → α) e) (measurable_id.prod_map he.measurable) borelMarkovFromReal Ω (condKernelUnitReal κ') instance instIsMarkovKernelCondKernelUnitBorel : IsMarkovKernel κ.condKernelUnitBorel := by rw [condKernelUnitBorel] infer_instance instance condKernelUnitBorel.instIsCondKernel : κ.IsCondKernel κ.condKernelUnitBorel where disintegrate := by rw [condKernelUnitBorel, compProd_fst_borelMarkovFromReal _ _ (disintegrate _ _)] @[deprecated disintegrate (since := "2024-07-26")] lemma compProd_fst_condKernelUnitBorel (κ : Kernel Unit (α × Ω)) [IsFiniteKernel κ] : fst κ ⊗ₖ condKernelUnitBorel κ = κ := disintegrate _ _ end Unit section Measure variable {ρ : Measure (α × Ω)} [IsFiniteMeasure ρ] /-- Conditional kernel of a measure on a product space: a Markov kernel such that `ρ = ρ.fst ⊗ₘ ρ.condKernel` (see `MeasureTheory.Measure.compProd_fst_condKernel`). -/ noncomputable irreducible_def _root_.MeasureTheory.Measure.condKernel (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] : Kernel α Ω := comap (condKernelUnitBorel (const Unit ρ)) (fun a ↦ ((), a)) measurable_prod_mk_left lemma _root_.MeasureTheory.Measure.condKernel_apply (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] (a : α) : ρ.condKernel a = condKernelUnitBorel (const Unit ρ) ((), a) := by rw [Measure.condKernel]; rfl instance _root_.MeasureTheory.Measure.condKernel.instIsCondKernel (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] : ρ.IsCondKernel ρ.condKernel where disintegrate := by have h1 : const Unit (Measure.fst ρ) = fst (const Unit ρ) := by ext simp only [fst_apply, Measure.fst, const_apply] have h2 : prodMkLeft Unit (Measure.condKernel ρ) = condKernelUnitBorel (const Unit ρ) := by ext simp only [prodMkLeft_apply, Measure.condKernel_apply] rw [Measure.compProd, h1, h2, disintegrate] simp instance _root_.MeasureTheory.Measure.instIsMarkovKernelCondKernel (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] : IsMarkovKernel ρ.condKernel := by rw [Measure.condKernel] infer_instance /-- **Disintegration** of finite product measures on `α × Ω`, where `Ω` is standard Borel. Such a measure can be written as the composition-product of `ρ.fst` (marginal measure over `α`) and a Markov kernel from `α` to `Ω`. We call that Markov kernel `ρ.condKernel`. -/ @[deprecated Measure.disintegrate (since := "2024-07-24")] lemma _root_.MeasureTheory.Measure.compProd_fst_condKernel (ρ : Measure (α × Ω)) [IsFiniteMeasure ρ] : ρ.fst ⊗ₘ ρ.condKernel = ρ := ρ.disintegrate ρ.condKernel set_option linter.unusedVariables false in /-- Auxiliary lemma for `condKernel_apply_of_ne_zero`. -/ @[deprecated Measure.IsCondKernel.apply_of_ne_zero (since := "2024-07-24"), nolint unusedArguments] lemma _root_.MeasureTheory.Measure.condKernel_apply_of_ne_zero_of_measurableSet [MeasurableSingletonClass α] {x : α} (hx : ρ.fst {x} ≠ 0) {s : Set Ω} (hs : MeasurableSet s) : ρ.condKernel x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := Measure.IsCondKernel.apply_of_ne_zero _ _ hx _ /-- If the singleton `{x}` has non-zero mass for `ρ.fst`, then for all `s : Set Ω`, `ρ.condKernel x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s)` . -/ lemma _root_.MeasureTheory.Measure.condKernel_apply_of_ne_zero [MeasurableSingletonClass α] {x : α} (hx : ρ.fst {x} ≠ 0) (s : Set Ω) : ρ.condKernel x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := Measure.IsCondKernel.apply_of_ne_zero _ _ hx _ end Measure section Countable variable [Countable α] @[deprecated disintegrate (since := "2024-07-24")] lemma compProd_fst_condKernelCountable (κ : Kernel α (β × Ω)) [IsFiniteKernel κ] : fst κ ⊗ₖ condKernelCountable (fun a ↦ (κ a).condKernel) (fun x y h ↦ by simp [apply_congr_of_mem_measurableAtom _ h]) = κ := disintegrate _ _ end Countable section CountableOrCountablyGenerated variable [h : CountableOrCountablyGenerated α β] (κ : Kernel α (β × Ω)) [IsFiniteKernel κ] open Classical in /-- Conditional kernel of a kernel `κ : Kernel α (β × Ω)`: a Markov kernel such that `fst κ ⊗ₖ condKernel κ = κ` (see `MeasureTheory.Measure.compProd_fst_condKernel`). It exists whenever `Ω` is standard Borel and either `α` is countable or `β` is countably generated. -/ noncomputable irreducible_def condKernel : Kernel (α × β) Ω := if hα : Countable α then condKernelCountable (fun a ↦ (κ a).condKernel) fun x y h ↦ by simp [apply_congr_of_mem_measurableAtom _ h] else letI := h.countableOrCountablyGenerated.resolve_left hα; condKernelBorel κ /-- `condKernel κ` is a Markov kernel. -/ instance instIsMarkovKernelCondKernel : IsMarkovKernel (condKernel κ) := by rw [condKernel_def] split_ifs <;> infer_instance instance condKernel.instIsCondKernel : κ.IsCondKernel κ.condKernel where disintegrate := by rw [condKernel_def]; split_ifs with hα <;> exact disintegrate _ _ /-- **Disintegration** of finite kernels. The composition-product of `fst κ` and `condKernel κ` is equal to `κ`. -/ @[deprecated Kernel.disintegrate (since := "2024-07-26")] lemma compProd_fst_condKernel : fst κ ⊗ₖ condKernel κ = κ := κ.disintegrate κ.condKernel end CountableOrCountablyGenerated end ProbabilityTheory.Kernel
Probability\Kernel\Disintegration\Unique.lean
/- Copyright (c) 2023 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Kernel.Disintegration.Integral /-! # Uniqueness of the conditional kernel We prove that the conditional kernels `ProbabilityTheory.Kernel.condKernel` and `MeasureTheory.Measure.condKernel` are almost everywhere unique. ## Main statements * `ProbabilityTheory.eq_condKernel_of_kernel_eq_compProd`: a.e. uniqueness of `ProbabilityTheory.Kernel.condKernel` * `ProbabilityTheory.eq_condKernel_of_measure_eq_compProd`: a.e. uniqueness of `MeasureTheory.Measure.condKernel` * `ProbabilityTheory.Kernel.condKernel_apply_eq_condKernel`: the kernel `condKernel` is almost everywhere equal to the measure `condKernel`. -/ open MeasureTheory Set Filter MeasurableSpace open scoped ENNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω] section Measure variable {ρ : Measure (α × Ω)} [IsFiniteMeasure ρ] /-! ### Uniqueness of `Measure.condKernel` The conditional kernel of a measure is unique almost everywhere. -/ /-- A s-finite kernel which satisfy the disintegration property of the given measure `ρ` is almost everywhere equal to the disintegration kernel of `ρ` when evaluated on a measurable set. This theorem in the case of finite kernels is weaker than `eq_condKernel_of_measure_eq_compProd` which asserts that the kernels are equal almost everywhere and not just on a given measurable set. -/ theorem eq_condKernel_of_measure_eq_compProd' (κ : Kernel α Ω) [IsSFiniteKernel κ] (hκ : ρ = ρ.fst ⊗ₘ κ) {s : Set Ω} (hs : MeasurableSet s) : ∀ᵐ x ∂ρ.fst, κ x s = ρ.condKernel x s := by refine ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite (Kernel.measurable_coe κ hs) (Kernel.measurable_coe ρ.condKernel hs) (fun t ht _ ↦ ?_) conv_rhs => rw [Measure.setLIntegral_condKernel_eq_measure_prod ht hs, hκ] simp only [Measure.compProd_apply (ht.prod hs), Set.mem_prod, ← lintegral_indicator _ ht] congr with x by_cases hx : x ∈ t all_goals simp [hx] /-- Auxiliary lemma for `eq_condKernel_of_measure_eq_compProd`. Uniqueness of the disintegration kernel on ℝ. -/ lemma eq_condKernel_of_measure_eq_compProd_real {ρ : Measure (α × ℝ)} [IsFiniteMeasure ρ] (κ : Kernel α ℝ) [IsFiniteKernel κ] (hκ : ρ = ρ.fst ⊗ₘ κ) : ∀ᵐ x ∂ρ.fst, κ x = ρ.condKernel x := by have huniv : ∀ᵐ x ∂ρ.fst, κ x Set.univ = ρ.condKernel x Set.univ := eq_condKernel_of_measure_eq_compProd' κ hκ MeasurableSet.univ suffices ∀ᵐ x ∂ρ.fst, ∀ ⦃t⦄, MeasurableSet t → κ x t = ρ.condKernel x t by filter_upwards [this] with x hx ext t ht; exact hx ht apply MeasurableSpace.ae_induction_on_inter Real.borel_eq_generateFrom_Iic_rat Real.isPiSystem_Iic_rat · simp · simp only [iUnion_singleton_eq_range, mem_range, forall_exists_index, forall_apply_eq_imp_iff] exact ae_all_iff.2 fun q ↦ eq_condKernel_of_measure_eq_compProd' κ hκ measurableSet_Iic · filter_upwards [huniv] with x hxuniv t ht heq rw [measure_compl ht <| measure_ne_top _ _, heq, hxuniv, measure_compl ht <| measure_ne_top _ _] · refine ae_of_all _ (fun x f hdisj hf heq ↦ ?_) rw [measure_iUnion hdisj hf, measure_iUnion hdisj hf] exact tsum_congr heq /-- A finite kernel which satisfies the disintegration property is almost everywhere equal to the disintegration kernel. -/ theorem eq_condKernel_of_measure_eq_compProd (κ : Kernel α Ω) [IsFiniteKernel κ] (hκ : ρ = ρ.fst ⊗ₘ κ) : ∀ᵐ x ∂ρ.fst, κ x = ρ.condKernel x := by -- The idea is to transport the question to `ℝ` from `Ω` using `embeddingReal` -- and then construct a measure on `α × ℝ` let f := embeddingReal Ω have hf := measurableEmbedding_embeddingReal Ω set ρ' : Measure (α × ℝ) := ρ.map (Prod.map id f) with hρ'def have hρ' : ρ'.fst = ρ.fst := by ext s hs rw [hρ'def, Measure.fst_apply, Measure.fst_apply, Measure.map_apply] exacts [rfl, Measurable.prod measurable_fst <| hf.measurable.comp measurable_snd, measurable_fst hs, hs, hs] have hρ'' : ∀ᵐ x ∂ρ.fst, Kernel.map κ f hf.measurable x = ρ'.condKernel x := by rw [← hρ'] refine eq_condKernel_of_measure_eq_compProd_real (Kernel.map κ f hf.measurable) ?_ ext s hs conv_lhs => rw [hρ'def, hκ] rw [Measure.map_apply (measurable_id.prod_map hf.measurable) hs, hρ', Measure.compProd_apply hs, Measure.compProd_apply (measurable_id.prod_map hf.measurable hs)] congr with a rw [Kernel.map_apply'] exacts [rfl, measurable_prod_mk_left hs] suffices ∀ᵐ x ∂ρ.fst, ∀ s, MeasurableSet s → ρ'.condKernel x s = ρ.condKernel x (f ⁻¹' s) by filter_upwards [hρ'', this] with x hx h rw [Kernel.map_apply] at hx ext s hs rw [← Set.preimage_image_eq s hf.injective, ← Measure.map_apply hf.measurable <| hf.measurableSet_image.2 hs, hx, h _ <| hf.measurableSet_image.2 hs] suffices ρ.map (Prod.map id f) = (ρ.fst ⊗ₘ (Kernel.map ρ.condKernel f hf.measurable)) by rw [← hρ'] at this have heq := eq_condKernel_of_measure_eq_compProd_real _ this rw [hρ'] at heq filter_upwards [heq] with x hx s hs rw [← hx, Kernel.map_apply, Measure.map_apply hf.measurable hs] ext s hs conv_lhs => rw [← ρ.disintegrate ρ.condKernel] rw [Measure.compProd_apply hs, Measure.map_apply (measurable_id.prod_map hf.measurable) hs, Measure.compProd_apply] · congr with a rw [Kernel.map_apply'] exacts [rfl, measurable_prod_mk_left hs] · exact measurable_id.prod_map hf.measurable hs end Measure section KernelAndMeasure lemma Kernel.apply_eq_measure_condKernel_of_compProd_eq {ρ : Kernel α (β × Ω)} [IsFiniteKernel ρ] {κ : Kernel (α × β) Ω} [IsFiniteKernel κ] (hκ : Kernel.fst ρ ⊗ₖ κ = ρ) (a : α) : (fun b ↦ κ (a, b)) =ᵐ[Kernel.fst ρ a] (ρ a).condKernel := by have : ρ a = (ρ a).fst ⊗ₘ Kernel.comap κ (fun b ↦ (a, b)) measurable_prod_mk_left := by ext s hs conv_lhs => rw [← hκ] rw [Measure.compProd_apply hs, Kernel.compProd_apply _ _ _ hs] rfl have h := eq_condKernel_of_measure_eq_compProd _ this rw [Kernel.fst_apply] filter_upwards [h] with b hb rw [← hb, Kernel.comap_apply] /-- For `fst κ a`-almost all `b`, the conditional kernel `Kernel.condKernel κ` applied to `(a, b)` is equal to the conditional kernel of the measure `κ a` applied to `b`. -/ lemma Kernel.condKernel_apply_eq_condKernel [CountableOrCountablyGenerated α β] (κ : Kernel α (β × Ω)) [IsFiniteKernel κ] (a : α) : (fun b ↦ Kernel.condKernel κ (a, b)) =ᵐ[Kernel.fst κ a] (κ a).condKernel := Kernel.apply_eq_measure_condKernel_of_compProd_eq (κ.disintegrate _) a lemma condKernel_const [CountableOrCountablyGenerated α β] (ρ : Measure (β × Ω)) [IsFiniteMeasure ρ] (a : α) : (fun b ↦ Kernel.condKernel (Kernel.const α ρ) (a, b)) =ᵐ[ρ.fst] ρ.condKernel := by have h := Kernel.condKernel_apply_eq_condKernel (Kernel.const α ρ) a simp_rw [Kernel.fst_apply, Kernel.const_apply] at h filter_upwards [h] with b hb using hb end KernelAndMeasure section Kernel /-! ### Uniqueness of `Kernel.condKernel` The conditional kernel is unique almost everywhere. -/ /-- A finite kernel which satisfies the disintegration property is almost everywhere equal to the disintegration kernel. -/ theorem eq_condKernel_of_kernel_eq_compProd [CountableOrCountablyGenerated α β] {ρ : Kernel α (β × Ω)} [IsFiniteKernel ρ] {κ : Kernel (α × β) Ω} [IsFiniteKernel κ] (hκ : Kernel.fst ρ ⊗ₖ κ = ρ) (a : α) : ∀ᵐ x ∂(Kernel.fst ρ a), κ (a, x) = Kernel.condKernel ρ (a, x) := by filter_upwards [Kernel.condKernel_apply_eq_condKernel ρ a, Kernel.apply_eq_measure_condKernel_of_compProd_eq hκ a] with a h1 h2 rw [h1, h2] end Kernel end ProbabilityTheory
Probability\Martingale\Basic.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, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Process.Stopping /-! # Martingales A family of functions `f : ι → Ω → E` is a martingale with respect to a filtration `ℱ` if every `f i` is integrable, `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] =ᵐ[μ] f i`. On the other hand, `f : ι → Ω → E` is said to be a supermartingale with respect to the filtration `ℱ` if `f i` is integrable, `f` is adapted with resepct to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] ≤ᵐ[μ] f i`. Finally, `f : ι → Ω → E` is said to be a submartingale with respect to the filtration `ℱ` if `f i` is integrable, `f` is adapted with resepct to `ℱ` and for all `i ≤ j`, `f i ≤ᵐ[μ] μ[f j | ℱ i]`. The definitions of filtration and adapted can be found in `Probability.Process.Stopping`. ### Definitions * `MeasureTheory.Martingale f ℱ μ`: `f` is a martingale with respect to filtration `ℱ` and measure `μ`. * `MeasureTheory.Supermartingale f ℱ μ`: `f` is a supermartingale with respect to filtration `ℱ` and measure `μ`. * `MeasureTheory.Submartingale f ℱ μ`: `f` is a submartingale with respect to filtration `ℱ` and measure `μ`. ### Results * `MeasureTheory.martingale_condexp f ℱ μ`: the sequence `fun i => μ[f | ℱ i, ℱ.le i])` is a martingale with respect to `ℱ` and `μ`. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory variable {Ω E ι : Type*} [Preorder ι] {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f g : ι → Ω → E} {ℱ : Filtration ι m0} /-- A family of functions `f : ι → Ω → E` is a martingale with respect to a filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] =ᵐ[μ] f i`. -/ def Martingale (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop := Adapted ℱ f ∧ ∀ i j, i ≤ j → μ[f j|ℱ i] =ᵐ[μ] f i /-- A family of integrable functions `f : ι → Ω → E` is a supermartingale with respect to a filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ.le i] ≤ᵐ[μ] f i`. -/ def Supermartingale [LE E] (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop := Adapted ℱ f ∧ (∀ i j, i ≤ j → μ[f j|ℱ i] ≤ᵐ[μ] f i) ∧ ∀ i, Integrable (f i) μ /-- A family of integrable functions `f : ι → Ω → E` is a submartingale with respect to a filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `f i ≤ᵐ[μ] μ[f j | ℱ.le i]`. -/ def Submartingale [LE E] (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop := Adapted ℱ f ∧ (∀ i j, i ≤ j → f i ≤ᵐ[μ] μ[f j|ℱ i]) ∧ ∀ i, Integrable (f i) μ theorem martingale_const (ℱ : Filtration ι m0) (μ : Measure Ω) [IsFiniteMeasure μ] (x : E) : Martingale (fun _ _ => x) ℱ μ := ⟨adapted_const ℱ _, fun i j _ => by rw [condexp_const (ℱ.le _)]⟩ theorem martingale_const_fun [OrderBot ι] (ℱ : Filtration ι m0) (μ : Measure Ω) [IsFiniteMeasure μ] {f : Ω → E} (hf : StronglyMeasurable[ℱ ⊥] f) (hfint : Integrable f μ) : Martingale (fun _ => f) ℱ μ := by refine ⟨fun i => hf.mono <| ℱ.mono bot_le, fun i j _ => ?_⟩ rw [condexp_of_stronglyMeasurable (ℱ.le _) (hf.mono <| ℱ.mono bot_le) hfint] variable (E) theorem martingale_zero (ℱ : Filtration ι m0) (μ : Measure Ω) : Martingale (0 : ι → Ω → E) ℱ μ := ⟨adapted_zero E ℱ, fun i j _ => by rw [Pi.zero_apply, condexp_zero]; simp⟩ variable {E} namespace Martingale protected theorem adapted (hf : Martingale f ℱ μ) : Adapted ℱ f := hf.1 protected theorem stronglyMeasurable (hf : Martingale f ℱ μ) (i : ι) : StronglyMeasurable[ℱ i] (f i) := hf.adapted i theorem condexp_ae_eq (hf : Martingale f ℱ μ) {i j : ι} (hij : i ≤ j) : μ[f j|ℱ i] =ᵐ[μ] f i := hf.2 i j hij protected theorem integrable (hf : Martingale f ℱ μ) (i : ι) : Integrable (f i) μ := integrable_condexp.congr (hf.condexp_ae_eq (le_refl i)) theorem setIntegral_eq [SigmaFiniteFiltration μ ℱ] (hf : Martingale f ℱ μ) {i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f i ω ∂μ = ∫ ω in s, f j ω ∂μ := by rw [← @setIntegral_condexp _ _ _ _ _ (ℱ i) m0 _ _ _ (ℱ.le i) _ (hf.integrable j) hs] refine setIntegral_congr_ae (ℱ.le i s hs) ?_ filter_upwards [hf.2 i j hij] with _ heq _ using heq.symm @[deprecated (since := "2024-04-17")] alias set_integral_eq := setIntegral_eq theorem add (hf : Martingale f ℱ μ) (hg : Martingale g ℱ μ) : Martingale (f + g) ℱ μ := by refine ⟨hf.adapted.add hg.adapted, fun i j hij => ?_⟩ exact (condexp_add (hf.integrable j) (hg.integrable j)).trans ((hf.2 i j hij).add (hg.2 i j hij)) theorem neg (hf : Martingale f ℱ μ) : Martingale (-f) ℱ μ := ⟨hf.adapted.neg, fun i j hij => (condexp_neg (f j)).trans (hf.2 i j hij).neg⟩ theorem sub (hf : Martingale f ℱ μ) (hg : Martingale g ℱ μ) : Martingale (f - g) ℱ μ := by rw [sub_eq_add_neg]; exact hf.add hg.neg theorem smul (c : ℝ) (hf : Martingale f ℱ μ) : Martingale (c • f) ℱ μ := by refine ⟨hf.adapted.smul c, fun i j hij => ?_⟩ refine (condexp_smul c (f j)).trans ((hf.2 i j hij).mono fun x hx => ?_) simp only [Pi.smul_apply, hx] theorem supermartingale [Preorder E] (hf : Martingale f ℱ μ) : Supermartingale f ℱ μ := ⟨hf.1, fun i j hij => (hf.2 i j hij).le, fun i => hf.integrable i⟩ theorem submartingale [Preorder E] (hf : Martingale f ℱ μ) : Submartingale f ℱ μ := ⟨hf.1, fun i j hij => (hf.2 i j hij).symm.le, fun i => hf.integrable i⟩ end Martingale theorem martingale_iff [PartialOrder E] : Martingale f ℱ μ ↔ Supermartingale f ℱ μ ∧ Submartingale f ℱ μ := ⟨fun hf => ⟨hf.supermartingale, hf.submartingale⟩, fun ⟨hf₁, hf₂⟩ => ⟨hf₁.1, fun i j hij => (hf₁.2.1 i j hij).antisymm (hf₂.2.1 i j hij)⟩⟩ theorem martingale_condexp (f : Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) [SigmaFiniteFiltration μ ℱ] : Martingale (fun i => μ[f|ℱ i]) ℱ μ := ⟨fun _ => stronglyMeasurable_condexp, fun _ j hij => condexp_condexp_of_le (ℱ.mono hij) (ℱ.le j)⟩ namespace Supermartingale protected theorem adapted [LE E] (hf : Supermartingale f ℱ μ) : Adapted ℱ f := hf.1 protected theorem stronglyMeasurable [LE E] (hf : Supermartingale f ℱ μ) (i : ι) : StronglyMeasurable[ℱ i] (f i) := hf.adapted i protected theorem integrable [LE E] (hf : Supermartingale f ℱ μ) (i : ι) : Integrable (f i) μ := hf.2.2 i theorem condexp_ae_le [LE E] (hf : Supermartingale f ℱ μ) {i j : ι} (hij : i ≤ j) : μ[f j|ℱ i] ≤ᵐ[μ] f i := hf.2.1 i j hij theorem setIntegral_le [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} (hf : Supermartingale f ℱ μ) {i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f j ω ∂μ ≤ ∫ ω in s, f i ω ∂μ := by rw [← setIntegral_condexp (ℱ.le i) (hf.integrable j) hs] refine setIntegral_mono_ae integrable_condexp.integrableOn (hf.integrable i).integrableOn ?_ filter_upwards [hf.2.1 i j hij] with _ heq using heq @[deprecated (since := "2024-04-17")] alias set_integral_le := setIntegral_le theorem add [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Supermartingale f ℱ μ) (hg : Supermartingale g ℱ μ) : Supermartingale (f + g) ℱ μ := by refine ⟨hf.1.add hg.1, fun i j hij => ?_, fun i => (hf.2.2 i).add (hg.2.2 i)⟩ refine (condexp_add (hf.integrable j) (hg.integrable j)).le.trans ?_ filter_upwards [hf.2.1 i j hij, hg.2.1 i j hij] intros refine add_le_add ?_ ?_ <;> assumption theorem add_martingale [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Supermartingale f ℱ μ) (hg : Martingale g ℱ μ) : Supermartingale (f + g) ℱ μ := hf.add hg.supermartingale theorem neg [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Supermartingale f ℱ μ) : Submartingale (-f) ℱ μ := by refine ⟨hf.1.neg, fun i j hij => ?_, fun i => (hf.2.2 i).neg⟩ refine EventuallyLE.trans ?_ (condexp_neg (f j)).symm.le filter_upwards [hf.2.1 i j hij] with _ _ simpa end Supermartingale namespace Submartingale protected theorem adapted [LE E] (hf : Submartingale f ℱ μ) : Adapted ℱ f := hf.1 protected theorem stronglyMeasurable [LE E] (hf : Submartingale f ℱ μ) (i : ι) : StronglyMeasurable[ℱ i] (f i) := hf.adapted i protected theorem integrable [LE E] (hf : Submartingale f ℱ μ) (i : ι) : Integrable (f i) μ := hf.2.2 i theorem ae_le_condexp [LE E] (hf : Submartingale f ℱ μ) {i j : ι} (hij : i ≤ j) : f i ≤ᵐ[μ] μ[f j|ℱ i] := hf.2.1 i j hij theorem add [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Submartingale f ℱ μ) (hg : Submartingale g ℱ μ) : Submartingale (f + g) ℱ μ := by refine ⟨hf.1.add hg.1, fun i j hij => ?_, fun i => (hf.2.2 i).add (hg.2.2 i)⟩ refine EventuallyLE.trans ?_ (condexp_add (hf.integrable j) (hg.integrable j)).symm.le filter_upwards [hf.2.1 i j hij, hg.2.1 i j hij] intros refine add_le_add ?_ ?_ <;> assumption theorem add_martingale [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Submartingale f ℱ μ) (hg : Martingale g ℱ μ) : Submartingale (f + g) ℱ μ := hf.add hg.submartingale theorem neg [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Submartingale f ℱ μ) : Supermartingale (-f) ℱ μ := by refine ⟨hf.1.neg, fun i j hij => (condexp_neg (f j)).le.trans ?_, fun i => (hf.2.2 i).neg⟩ filter_upwards [hf.2.1 i j hij] with _ _ simpa /-- The converse of this lemma is `MeasureTheory.submartingale_of_setIntegral_le`. -/ theorem setIntegral_le [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) {i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f j ω ∂μ := by rw [← neg_le_neg_iff, ← integral_neg, ← integral_neg] exact Supermartingale.setIntegral_le hf.neg hij hs @[deprecated (since := "2024-04-17")] alias set_integral_le := setIntegral_le theorem sub_supermartingale [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Submartingale f ℱ μ) (hg : Supermartingale g ℱ μ) : Submartingale (f - g) ℱ μ := by rw [sub_eq_add_neg]; exact hf.add hg.neg theorem sub_martingale [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Submartingale f ℱ μ) (hg : Martingale g ℱ μ) : Submartingale (f - g) ℱ μ := hf.sub_supermartingale hg.supermartingale protected theorem sup {f g : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) (hg : Submartingale g ℱ μ) : Submartingale (f ⊔ g) ℱ μ := by refine ⟨fun i => @StronglyMeasurable.sup _ _ _ _ (ℱ i) _ _ _ (hf.adapted i) (hg.adapted i), fun i j hij => ?_, fun i => Integrable.sup (hf.integrable _) (hg.integrable _)⟩ refine EventuallyLE.sup_le ?_ ?_ · exact EventuallyLE.trans (hf.2.1 i j hij) (condexp_mono (hf.integrable _) (Integrable.sup (hf.integrable j) (hg.integrable j)) (eventually_of_forall fun x => le_max_left _ _)) · exact EventuallyLE.trans (hg.2.1 i j hij) (condexp_mono (hg.integrable _) (Integrable.sup (hf.integrable j) (hg.integrable j)) (eventually_of_forall fun x => le_max_right _ _)) protected theorem pos {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) : Submartingale (f⁺) ℱ μ := hf.sup (martingale_zero _ _ _).submartingale end Submartingale section Submartingale theorem submartingale_of_setIntegral_le [IsFiniteMeasure μ] {f : ι → Ω → ℝ} (hadp : Adapted ℱ f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i j : ι, i ≤ j → ∀ s : Set Ω, MeasurableSet[ℱ i] s → ∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f j ω ∂μ) : Submartingale f ℱ μ := by refine ⟨hadp, fun i j hij => ?_, hint⟩ suffices f i ≤ᵐ[μ.trim (ℱ.le i)] μ[f j|ℱ i] by exact ae_le_of_ae_le_trim this suffices 0 ≤ᵐ[μ.trim (ℱ.le i)] μ[f j|ℱ i] - f i by filter_upwards [this] with x hx rwa [← sub_nonneg] refine ae_nonneg_of_forall_setIntegral_nonneg ((integrable_condexp.sub (hint i)).trim _ (stronglyMeasurable_condexp.sub <| hadp i)) fun s hs _ => ?_ specialize hf i j hij s hs rwa [← setIntegral_trim _ (stronglyMeasurable_condexp.sub <| hadp i) hs, integral_sub' integrable_condexp.integrableOn (hint i).integrableOn, sub_nonneg, setIntegral_condexp (ℱ.le i) (hint j) hs] @[deprecated (since := "2024-04-17")] alias submartingale_of_set_integral_le := submartingale_of_setIntegral_le theorem submartingale_of_condexp_sub_nonneg [IsFiniteMeasure μ] {f : ι → Ω → ℝ} (hadp : Adapted ℱ f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i j, i ≤ j → 0 ≤ᵐ[μ] μ[f j - f i|ℱ i]) : Submartingale f ℱ μ := by refine ⟨hadp, fun i j hij => ?_, hint⟩ rw [← condexp_of_stronglyMeasurable (ℱ.le _) (hadp _) (hint _), ← eventually_sub_nonneg] exact EventuallyLE.trans (hf i j hij) (condexp_sub (hint _) (hint _)).le theorem Submartingale.condexp_sub_nonneg {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) {i j : ι} (hij : i ≤ j) : 0 ≤ᵐ[μ] μ[f j - f i|ℱ i] := by by_cases h : SigmaFinite (μ.trim (ℱ.le i)) swap; · rw [condexp_of_not_sigmaFinite (ℱ.le i) h] refine EventuallyLE.trans ?_ (condexp_sub (hf.integrable _) (hf.integrable _)).symm.le rw [eventually_sub_nonneg, condexp_of_stronglyMeasurable (ℱ.le _) (hf.adapted _) (hf.integrable _)] exact hf.2.1 i j hij theorem submartingale_iff_condexp_sub_nonneg [IsFiniteMeasure μ] {f : ι → Ω → ℝ} : Submartingale f ℱ μ ↔ Adapted ℱ f ∧ (∀ i, Integrable (f i) μ) ∧ ∀ i j, i ≤ j → 0 ≤ᵐ[μ] μ[f j - f i|ℱ i] := ⟨fun h => ⟨h.adapted, h.integrable, fun _ _ => h.condexp_sub_nonneg⟩, fun ⟨hadp, hint, h⟩ => submartingale_of_condexp_sub_nonneg hadp hint h⟩ end Submartingale namespace Supermartingale theorem sub_submartingale [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Supermartingale f ℱ μ) (hg : Submartingale g ℱ μ) : Supermartingale (f - g) ℱ μ := by rw [sub_eq_add_neg]; exact hf.add hg.neg theorem sub_martingale [Preorder E] [CovariantClass E E (· + ·) (· ≤ ·)] (hf : Supermartingale f ℱ μ) (hg : Martingale g ℱ μ) : Supermartingale (f - g) ℱ μ := hf.sub_submartingale hg.submartingale section variable {F : Type*} [NormedLatticeAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] [OrderedSMul ℝ F] theorem smul_nonneg {f : ι → Ω → F} {c : ℝ} (hc : 0 ≤ c) (hf : Supermartingale f ℱ μ) : Supermartingale (c • f) ℱ μ := by refine ⟨hf.1.smul c, fun i j hij => ?_, fun i => (hf.2.2 i).smul c⟩ refine (condexp_smul c (f j)).le.trans ?_ filter_upwards [hf.2.1 i j hij] with _ hle simp_rw [Pi.smul_apply] exact smul_le_smul_of_nonneg_left hle hc theorem smul_nonpos {f : ι → Ω → F} {c : ℝ} (hc : c ≤ 0) (hf : Supermartingale f ℱ μ) : Submartingale (c • f) ℱ μ := by rw [← neg_neg c, (by ext (i x); simp : - -c • f = -(-c • f))] exact (hf.smul_nonneg <| neg_nonneg.2 hc).neg end end Supermartingale namespace Submartingale section variable {F : Type*} [NormedLatticeAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] [OrderedSMul ℝ F] theorem smul_nonneg {f : ι → Ω → F} {c : ℝ} (hc : 0 ≤ c) (hf : Submartingale f ℱ μ) : Submartingale (c • f) ℱ μ := by rw [← neg_neg c, (by ext (i x); simp : - -c • f = -(c • -f))] exact Supermartingale.neg (hf.neg.smul_nonneg hc) theorem smul_nonpos {f : ι → Ω → F} {c : ℝ} (hc : c ≤ 0) (hf : Submartingale f ℱ μ) : Supermartingale (c • f) ℱ μ := by rw [← neg_neg c, (by ext (i x); simp : - -c • f = -(-c • f))] exact (hf.smul_nonneg <| neg_nonneg.2 hc).neg end end Submartingale section Nat variable {𝒢 : Filtration ℕ m0} theorem submartingale_of_setIntegral_le_succ [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, ∀ s : Set Ω, MeasurableSet[𝒢 i] s → ∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f (i + 1) ω ∂μ) : Submartingale f 𝒢 μ := by refine submartingale_of_setIntegral_le hadp hint fun i j hij s hs => ?_ induction' hij with k hk₁ hk₂ · exact le_rfl · exact le_trans hk₂ (hf k s (𝒢.mono hk₁ _ hs)) @[deprecated (since := "2024-04-17")] alias submartingale_of_set_integral_le_succ := submartingale_of_setIntegral_le_succ theorem supermartingale_of_setIntegral_succ_le [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, ∀ s : Set Ω, MeasurableSet[𝒢 i] s → ∫ ω in s, f (i + 1) ω ∂μ ≤ ∫ ω in s, f i ω ∂μ) : Supermartingale f 𝒢 μ := by rw [← neg_neg f] refine (submartingale_of_setIntegral_le_succ hadp.neg (fun i => (hint i).neg) ?_).neg simpa only [integral_neg, Pi.neg_apply, neg_le_neg_iff] @[deprecated (since := "2024-04-17")] alias supermartingale_of_set_integral_succ_le := supermartingale_of_setIntegral_succ_le theorem martingale_of_setIntegral_eq_succ [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, ∀ s : Set Ω, MeasurableSet[𝒢 i] s → ∫ ω in s, f i ω ∂μ = ∫ ω in s, f (i + 1) ω ∂μ) : Martingale f 𝒢 μ := martingale_iff.2 ⟨supermartingale_of_setIntegral_succ_le hadp hint fun i s hs => (hf i s hs).ge, submartingale_of_setIntegral_le_succ hadp hint fun i s hs => (hf i s hs).le⟩ @[deprecated (since := "2024-04-17")] alias martingale_of_set_integral_eq_succ := martingale_of_setIntegral_eq_succ theorem submartingale_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, f i ≤ᵐ[μ] μ[f (i + 1)|𝒢 i]) : Submartingale f 𝒢 μ := by refine submartingale_of_setIntegral_le_succ hadp hint fun i s hs => ?_ have : ∫ ω in s, f (i + 1) ω ∂μ = ∫ ω in s, (μ[f (i + 1)|𝒢 i]) ω ∂μ := (setIntegral_condexp (𝒢.le i) (hint _) hs).symm rw [this] exact setIntegral_mono_ae (hint i).integrableOn integrable_condexp.integrableOn (hf i) theorem supermartingale_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, μ[f (i + 1)|𝒢 i] ≤ᵐ[μ] f i) : Supermartingale f 𝒢 μ := by rw [← neg_neg f] refine (submartingale_nat hadp.neg (fun i => (hint i).neg) fun i => EventuallyLE.trans ?_ (condexp_neg _).symm.le).neg filter_upwards [hf i] with x hx using neg_le_neg hx theorem martingale_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, f i =ᵐ[μ] μ[f (i + 1)|𝒢 i]) : Martingale f 𝒢 μ := martingale_iff.2 ⟨supermartingale_nat hadp hint fun i => (hf i).symm.le, submartingale_nat hadp hint fun i => (hf i).le⟩ theorem submartingale_of_condexp_sub_nonneg_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, 0 ≤ᵐ[μ] μ[f (i + 1) - f i|𝒢 i]) : Submartingale f 𝒢 μ := by refine submartingale_nat hadp hint fun i => ?_ rw [← condexp_of_stronglyMeasurable (𝒢.le _) (hadp _) (hint _), ← eventually_sub_nonneg] exact EventuallyLE.trans (hf i) (condexp_sub (hint _) (hint _)).le theorem supermartingale_of_condexp_sub_nonneg_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, 0 ≤ᵐ[μ] μ[f i - f (i + 1)|𝒢 i]) : Supermartingale f 𝒢 μ := by rw [← neg_neg f] refine (submartingale_of_condexp_sub_nonneg_nat hadp.neg (fun i => (hint i).neg) ?_).neg simpa only [Pi.zero_apply, Pi.neg_apply, neg_sub_neg] theorem martingale_of_condexp_sub_eq_zero_nat [IsFiniteMeasure μ] {f : ℕ → Ω → ℝ} (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ i, μ[f (i + 1) - f i|𝒢 i] =ᵐ[μ] 0) : Martingale f 𝒢 μ := by refine martingale_iff.2 ⟨supermartingale_of_condexp_sub_nonneg_nat hadp hint fun i => ?_, submartingale_of_condexp_sub_nonneg_nat hadp hint fun i => (hf i).symm.le⟩ rw [← neg_sub] refine (EventuallyEq.trans ?_ (condexp_neg _).symm).le filter_upwards [hf i] with x hx simpa only [Pi.zero_apply, Pi.neg_apply, zero_eq_neg] -- Note that one cannot use `Submartingale.zero_le_of_predictable` to prove the other two -- corresponding lemmas without imposing more restrictions to the ordering of `E` /-- A predictable submartingale is a.e. greater equal than its initial state. -/ theorem Submartingale.zero_le_of_predictable [Preorder E] [SigmaFiniteFiltration μ 𝒢] {f : ℕ → Ω → E} (hfmgle : Submartingale f 𝒢 μ) (hfadp : Adapted 𝒢 fun n => f (n + 1)) (n : ℕ) : f 0 ≤ᵐ[μ] f n := by induction' n with k ih · rfl · exact ih.trans ((hfmgle.2.1 k (k + 1) k.le_succ).trans_eq <| Germ.coe_eq.mp <| congr_arg Germ.ofFun <| condexp_of_stronglyMeasurable (𝒢.le _) (hfadp _) <| hfmgle.integrable _) /-- A predictable supermartingale is a.e. less equal than its initial state. -/ theorem Supermartingale.le_zero_of_predictable [Preorder E] [SigmaFiniteFiltration μ 𝒢] {f : ℕ → Ω → E} (hfmgle : Supermartingale f 𝒢 μ) (hfadp : Adapted 𝒢 fun n => f (n + 1)) (n : ℕ) : f n ≤ᵐ[μ] f 0 := by induction' n with k ih · rfl · exact ((Germ.coe_eq.mp <| congr_arg Germ.ofFun <| condexp_of_stronglyMeasurable (𝒢.le _) (hfadp _) <| hfmgle.integrable _).symm.trans_le (hfmgle.2.1 k (k + 1) k.le_succ)).trans ih /-- A predictable martingale is a.e. equal to its initial state. -/ theorem Martingale.eq_zero_of_predictable [SigmaFiniteFiltration μ 𝒢] {f : ℕ → Ω → E} (hfmgle : Martingale f 𝒢 μ) (hfadp : Adapted 𝒢 fun n => f (n + 1)) (n : ℕ) : f n =ᵐ[μ] f 0 := by induction' n with k ih · rfl · exact ((Germ.coe_eq.mp (congr_arg Germ.ofFun <| condexp_of_stronglyMeasurable (𝒢.le _) (hfadp _) (hfmgle.integrable _))).symm.trans (hfmgle.2 k (k + 1) k.le_succ)).trans ih namespace Submartingale protected theorem integrable_stoppedValue [LE E] {f : ℕ → Ω → E} (hf : Submartingale f 𝒢 μ) {τ : Ω → ℕ} (hτ : IsStoppingTime 𝒢 τ) {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : Integrable (stoppedValue f τ) μ := integrable_stoppedValue ℕ hτ hf.integrable hbdd end Submartingale theorem Submartingale.sum_mul_sub [IsFiniteMeasure μ] {R : ℝ} {ξ f : ℕ → Ω → ℝ} (hf : Submartingale f 𝒢 μ) (hξ : Adapted 𝒢 ξ) (hbdd : ∀ n ω, ξ n ω ≤ R) (hnonneg : ∀ n ω, 0 ≤ ξ n ω) : Submartingale (fun n => ∑ k ∈ Finset.range n, ξ k * (f (k + 1) - f k)) 𝒢 μ := by have hξbdd : ∀ i, ∃ C, ∀ ω, |ξ i ω| ≤ C := fun i => ⟨R, fun ω => (abs_of_nonneg (hnonneg i ω)).trans_le (hbdd i ω)⟩ have hint : ∀ m, Integrable (∑ k ∈ Finset.range m, ξ k * (f (k + 1) - f k)) μ := fun m => integrable_finset_sum' _ fun i _ => Integrable.bdd_mul ((hf.integrable _).sub (hf.integrable _)) hξ.stronglyMeasurable.aestronglyMeasurable (hξbdd _) have hadp : Adapted 𝒢 fun n => ∑ k ∈ Finset.range n, ξ k * (f (k + 1) - f k) := by intro m refine Finset.stronglyMeasurable_sum' _ fun i hi => ?_ rw [Finset.mem_range] at hi exact (hξ.stronglyMeasurable_le hi.le).mul ((hf.adapted.stronglyMeasurable_le (Nat.succ_le_of_lt hi)).sub (hf.adapted.stronglyMeasurable_le hi.le)) refine submartingale_of_condexp_sub_nonneg_nat hadp hint fun i => ?_ simp only [← Finset.sum_Ico_eq_sub _ (Nat.le_succ _), Finset.sum_apply, Pi.mul_apply, Pi.sub_apply, Nat.Ico_succ_singleton, Finset.sum_singleton] exact EventuallyLE.trans (EventuallyLE.mul_nonneg (eventually_of_forall (hnonneg _)) (hf.condexp_sub_nonneg (Nat.le_succ _))) (condexp_stronglyMeasurable_mul (hξ _) (((hf.integrable _).sub (hf.integrable _)).bdd_mul hξ.stronglyMeasurable.aestronglyMeasurable (hξbdd _)) ((hf.integrable _).sub (hf.integrable _))).symm.le /-- Given a discrete submartingale `f` and a predictable process `ξ` (i.e. `ξ (n + 1)` is adapted) the process defined by `fun n => ∑ k ∈ Finset.range n, ξ (k + 1) * (f (k + 1) - f k)` is also a submartingale. -/ theorem Submartingale.sum_mul_sub' [IsFiniteMeasure μ] {R : ℝ} {ξ f : ℕ → Ω → ℝ} (hf : Submartingale f 𝒢 μ) (hξ : Adapted 𝒢 fun n => ξ (n + 1)) (hbdd : ∀ n ω, ξ n ω ≤ R) (hnonneg : ∀ n ω, 0 ≤ ξ n ω) : Submartingale (fun n => ∑ k ∈ Finset.range n, ξ (k + 1) * (f (k + 1) - f k)) 𝒢 μ := hf.sum_mul_sub hξ (fun _ => hbdd _) fun _ => hnonneg _ end Nat end MeasureTheory
Probability\Martingale\BorelCantelli.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Martingale.Convergence import Mathlib.Probability.Martingale.OptionalStopping import Mathlib.Probability.Martingale.Centering /-! # Generalized Borel-Cantelli lemma This file proves Lévy's generalized Borel-Cantelli lemma which is a generalization of the Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas by choosing appropriate filtrations. This file also contains the one sided martingale bound which is required to prove the generalized Borel-Cantelli. **Note**: the usual Borel-Cantelli lemmas are not in this file. See `MeasureTheory.measure_limsup_eq_zero` for the first (which does not depend on the results here), and `ProbabilityTheory.measure_limsup_eq_one` for the second (which does). ## Main results - `MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto`: the one sided martingale bound: given a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost everywhere equal to the set for which it is bounded. - `MeasureTheory.ae_mem_limsup_atTop_iff`: Lévy's generalized Borel-Cantelli: given a filtration `ℱ` and a sequence of sets `s` such that `s n ∈ ℱ n` for all `n`, `limsup atTop s` is almost everywhere equal to the set for which `∑ ℙ[s (n + 1)∣ℱ n] = ∞`. -/ open Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators Topology namespace MeasureTheory variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {ω : Ω} /-! ### One sided martingale bound -/ -- TODO: `leastGE` should be defined taking values in `WithTop ℕ` once the `stoppedProcess` -- refactor is complete /-- `leastGE f r n` is the stopping time corresponding to the first time `f ≥ r`. -/ noncomputable def leastGE (f : ℕ → Ω → ℝ) (r : ℝ) (n : ℕ) := hitting f (Set.Ici r) 0 n theorem Adapted.isStoppingTime_leastGE (r : ℝ) (n : ℕ) (hf : Adapted ℱ f) : IsStoppingTime ℱ (leastGE f r n) := hitting_isStoppingTime hf measurableSet_Ici theorem leastGE_le {i : ℕ} {r : ℝ} (ω : Ω) : leastGE f r i ω ≤ i := hitting_le ω -- The following four lemmas shows `leastGE` behaves like a stopped process. Ideally we should -- define `leastGE` as a stopping time and take its stopped process. However, we can't do that -- with our current definition since a stopping time takes only finite indicies. An upcomming -- refactor should hopefully make it possible to have stopping times taking infinity as a value theorem leastGE_mono {n m : ℕ} (hnm : n ≤ m) (r : ℝ) (ω : Ω) : leastGE f r n ω ≤ leastGE f r m ω := hitting_mono hnm theorem leastGE_eq_min (π : Ω → ℕ) (r : ℝ) (ω : Ω) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : leastGE f r (π ω) ω = min (π ω) (leastGE f r n ω) := by classical refine le_antisymm (le_min (leastGE_le _) (leastGE_mono (hπn ω) r ω)) ?_ by_cases hle : π ω ≤ leastGE f r n ω · rw [min_eq_left hle, leastGE] by_cases h : ∃ j ∈ Set.Icc 0 (π ω), f j ω ∈ Set.Ici r · refine hle.trans (Eq.le ?_) rw [leastGE, ← hitting_eq_hitting_of_exists (hπn ω) h] · simp only [hitting, if_neg h, le_rfl] · rw [min_eq_right (not_le.1 hle).le, leastGE, leastGE, ← hitting_eq_hitting_of_exists (hπn ω) _] rw [not_le, leastGE, hitting_lt_iff _ (hπn ω)] at hle exact let ⟨j, hj₁, hj₂⟩ := hle ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ theorem stoppedValue_stoppedValue_leastGE (f : ℕ → Ω → ℝ) (π : Ω → ℕ) (r : ℝ) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : stoppedValue (fun i => stoppedValue f (leastGE f r i)) π = stoppedValue (stoppedProcess f (leastGE f r n)) π := by ext1 ω simp (config := { unfoldPartialApp := true }) only [stoppedProcess, stoppedValue] rw [leastGE_eq_min _ _ _ hπn] theorem Submartingale.stoppedValue_leastGE [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (r : ℝ) : Submartingale (fun i => stoppedValue f (leastGE f r i)) ℱ μ := by rw [submartingale_iff_expected_stoppedValue_mono] · intro σ π hσ hπ hσ_le_π hπ_bdd obtain ⟨n, hπ_le_n⟩ := hπ_bdd simp_rw [stoppedValue_stoppedValue_leastGE f σ r fun i => (hσ_le_π i).trans (hπ_le_n i)] simp_rw [stoppedValue_stoppedValue_leastGE f π r hπ_le_n] refine hf.expected_stoppedValue_mono ?_ ?_ ?_ fun ω => (min_le_left _ _).trans (hπ_le_n ω) · exact hσ.min (hf.adapted.isStoppingTime_leastGE _ _) · exact hπ.min (hf.adapted.isStoppingTime_leastGE _ _) · exact fun ω => min_le_min (hσ_le_π ω) le_rfl · exact fun i => stronglyMeasurable_stoppedValue_of_le hf.adapted.progMeasurable_of_discrete (hf.adapted.isStoppingTime_leastGE _ _) leastGE_le · exact fun i => integrable_stoppedValue _ (hf.adapted.isStoppingTime_leastGE _ _) hf.integrable leastGE_le variable {r : ℝ} {R : ℝ≥0} theorem norm_stoppedValue_leastGE_le (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : ∀ᵐ ω ∂μ, stoppedValue f (leastGE f r i) ω ≤ r + R := by filter_upwards [hbdd] with ω hbddω change f (leastGE f r i ω) ω ≤ r + R by_cases heq : leastGE f r i ω = 0 · rw [heq, hf0, Pi.zero_apply] exact add_nonneg hr R.coe_nonneg · obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero heq rw [hk, add_comm, ← sub_le_iff_le_add] have := not_mem_of_lt_hitting (hk.symm ▸ k.lt_succ_self : k < leastGE f r i ω) (zero_le _) simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ici, not_or, not_le] at this exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddω _)) theorem Submartingale.stoppedValue_leastGE_eLpNorm_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : eLpNorm (stoppedValue f (leastGE f r i)) 1 μ ≤ 2 * μ Set.univ * ENNReal.ofReal (r + R) := by refine eLpNorm_one_le_of_le' ((hf.stoppedValue_leastGE r).integrable _) ?_ (norm_stoppedValue_leastGE_le hr hf0 hbdd i) rw [← integral_univ] refine le_trans ?_ ((hf.stoppedValue_leastGE r).setIntegral_le (zero_le _) MeasurableSet.univ) simp_rw [stoppedValue, leastGE, hitting_of_le le_rfl, hf0, integral_zero', le_rfl] @[deprecated (since := "2024-07-27")] alias Submartingale.stoppedValue_leastGE_snorm_le := Submartingale.stoppedValue_leastGE_eLpNorm_le theorem Submartingale.stoppedValue_leastGE_eLpNorm_le' [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : eLpNorm (stoppedValue f (leastGE f r i)) 1 μ ≤ ENNReal.toNNReal (2 * μ Set.univ * ENNReal.ofReal (r + R)) := by refine (hf.stoppedValue_leastGE_eLpNorm_le hr hf0 hbdd i).trans ?_ simp [ENNReal.coe_toNNReal (measure_ne_top μ _), ENNReal.coe_toNNReal] @[deprecated (since := "2024-07-27")] alias Submartingale.stoppedValue_leastGE_snorm_le' := Submartingale.stoppedValue_leastGE_eLpNorm_le' /-- This lemma is superseded by `Submartingale.bddAbove_iff_exists_tendsto`. -/ theorem Submartingale.exists_tendsto_of_abs_bddAbove_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) → ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by have ht : ∀ᵐ ω ∂μ, ∀ i : ℕ, ∃ c, Tendsto (fun n => stoppedValue f (leastGE f i n) ω) atTop (𝓝 c) := by rw [ae_all_iff] exact fun i => Submartingale.exists_ae_tendsto_of_bdd (hf.stoppedValue_leastGE i) (hf.stoppedValue_leastGE_eLpNorm_le' i.cast_nonneg hf0 hbdd) filter_upwards [ht] with ω hω hωb rw [BddAbove] at hωb obtain ⟨i, hi⟩ := exists_nat_gt hωb.some have hib : ∀ n, f n ω < i := by intro n exact lt_of_le_of_lt ((mem_upperBounds.1 hωb.some_mem) _ ⟨n, rfl⟩) hi have heq : ∀ n, stoppedValue f (leastGE f i n) ω = f n ω := by intro n rw [leastGE]; unfold hitting; rw [stoppedValue] rw [if_neg] simp only [Set.mem_Icc, Set.mem_union, Set.mem_Ici] push_neg exact fun j _ => hib j simp only [← heq, hω i] theorem Submartingale.bddAbove_iff_exists_tendsto_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by filter_upwards [hf.exists_tendsto_of_abs_bddAbove_aux hf0 hbdd] with ω hω using ⟨hω, fun ⟨c, hc⟩ => hc.bddAbove_range⟩ /-- One sided martingale bound: If `f` is a submartingale which has uniformly bounded differences, then for almost every `ω`, `f n ω` is bounded above (in `n`) if and only if it converges. -/ theorem Submartingale.bddAbove_iff_exists_tendsto [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by set g : ℕ → Ω → ℝ := fun n ω => f n ω - f 0 ω have hg : Submartingale g ℱ μ := hf.sub_martingale (martingale_const_fun _ _ (hf.adapted 0) (hf.integrable 0)) have hg0 : g 0 = 0 := by ext ω simp only [g, sub_self, Pi.zero_apply] have hgbdd : ∀ᵐ ω ∂μ, ∀ i : ℕ, |g (i + 1) ω - g i ω| ≤ ↑R := by simpa only [g, sub_sub_sub_cancel_right] filter_upwards [hg.bddAbove_iff_exists_tendsto_aux hg0 hgbdd] with ω hω convert hω using 1 · refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨b, hb⟩ := h <;> refine ⟨b + |f 0 ω|, fun y hy => ?_⟩ <;> obtain ⟨n, rfl⟩ := hy · simp_rw [g, sub_eq_add_neg] exact add_le_add (hb ⟨n, rfl⟩) (neg_le_abs _) · exact sub_le_iff_le_add.1 (le_trans (sub_le_sub_left (le_abs_self _) _) (hb ⟨n, rfl⟩)) · refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨c, hc⟩ := h · exact ⟨c - f 0 ω, hc.sub_const _⟩ · refine ⟨c + f 0 ω, ?_⟩ have := hc.add_const (f 0 ω) simpa only [g, sub_add_cancel] /-! ### Lévy's generalization of the Borel-Cantelli lemma Lévy's generalization of the Borel-Cantelli lemma states that: given a natural number indexed filtration $(\mathcal{F}_n)$, and a sequence of sets $(s_n)$ such that for all $n$, $s_n \in \mathcal{F}_n$, $limsup_n s_n$ is almost everywhere equal to the set for which $\sum_n \mathbb{P}[s_n \mid \mathcal{F}_n] = \infty$. The proof strategy follows by constructing a martingale satisfying the one sided martingale bound. In particular, we define $$ f_n := \sum_{k < n} \mathbf{1}_{s_{n + 1}} - \mathbb{P}[s_{n + 1} \mid \mathcal{F}_n]. $$ Then, as a martingale is both a sub and a super-martingale, the set for which it is unbounded from above must agree with the set for which it is unbounded from below almost everywhere. Thus, it can only converge to $\pm \infty$ with probability 0. Thus, by considering $$ \limsup_n s_n = \{\sum_n \mathbf{1}_{s_n} = \infty\} $$ almost everywhere, the result follows. -/ theorem Martingale.bddAbove_range_iff_bddBelow_range [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ BddBelow (Set.range fun n => f n ω) := by have hbdd' : ∀ᵐ ω ∂μ, ∀ i, |(-f) (i + 1) ω - (-f) i ω| ≤ R := by filter_upwards [hbdd] with ω hω i erw [← abs_neg, neg_sub, sub_neg_eq_add, neg_add_eq_sub] exact hω i have hup := hf.submartingale.bddAbove_iff_exists_tendsto hbdd have hdown := hf.neg.submartingale.bddAbove_iff_exists_tendsto hbdd' filter_upwards [hup, hdown] with ω hω₁ hω₂ have : (∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c)) ↔ ∃ c, Tendsto (fun n => (-f) n ω) atTop (𝓝 c) := by constructor <;> rintro ⟨c, hc⟩ · exact ⟨-c, hc.neg⟩ · refine ⟨-c, ?_⟩ convert hc.neg simp only [neg_neg, Pi.neg_apply] rw [hω₁, this, ← hω₂] constructor <;> rintro ⟨c, hc⟩ <;> refine ⟨-c, fun ω hω => ?_⟩ · rw [mem_upperBounds] at hc refine neg_le.2 (hc _ ?_) simpa only [Pi.neg_apply, Set.mem_range, neg_inj] · rw [mem_lowerBounds] at hc simp_rw [Set.mem_range, Pi.neg_apply, neg_eq_iff_eq_neg] at hω refine le_neg.1 (hc _ ?_) simpa only [Set.mem_range] theorem Martingale.ae_not_tendsto_atTop_atTop [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atTop := by filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using unbounded_of_tendsto_atTop htop (hω.2 <| bddBelow_range_of_tendsto_atTop_atTop htop) theorem Martingale.ae_not_tendsto_atTop_atBot [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atBot := by filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using unbounded_of_tendsto_atBot htop (hω.1 <| bddAbove_range_of_tendsto_atTop_atBot htop) namespace BorelCantelli /-- Auxiliary definition required to prove Lévy's generalization of the Borel-Cantelli lemmas for which we will take the martingale part. -/ noncomputable def process (s : ℕ → Set Ω) (n : ℕ) : Ω → ℝ := ∑ k ∈ Finset.range n, (s (k + 1)).indicator 1 variable {s : ℕ → Set Ω} theorem process_zero : process s 0 = 0 := by rw [process, Finset.range_zero, Finset.sum_empty] theorem adapted_process (hs : ∀ n, MeasurableSet[ℱ n] (s n)) : Adapted ℱ (process s) := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hk => stronglyMeasurable_one.indicator <| ℱ.mono (Finset.mem_range.1 hk) _ <| hs _ theorem martingalePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) : martingalePart (process s) ℱ μ n = ∑ k ∈ Finset.range n, ((s (k + 1)).indicator 1 - μ[(s (k + 1)).indicator 1|ℱ k]) := by simp only [martingalePart_eq_sum, process_zero, zero_add] refine Finset.sum_congr rfl fun k _ => ?_ simp only [process, Finset.sum_range_succ_sub_sum] theorem predictablePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) : predictablePart (process s) ℱ μ n = ∑ k ∈ Finset.range n, μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k] := by have := martingalePart_process_ae_eq ℱ μ s n simp_rw [martingalePart, process, Finset.sum_sub_distrib] at this exact sub_right_injective this theorem process_difference_le (s : ℕ → Set Ω) (ω : Ω) (n : ℕ) : |process s (n + 1) ω - process s n ω| ≤ (1 : ℝ≥0) := by norm_cast rw [process, process, Finset.sum_apply, Finset.sum_apply, Finset.sum_range_succ_sub_sum, ← Real.norm_eq_abs, norm_indicator_eq_indicator_norm] refine Set.indicator_le' (fun _ _ => ?_) (fun _ _ => zero_le_one) _ rw [Pi.one_apply, norm_one] theorem integrable_process (μ : Measure Ω) [IsFiniteMeasure μ] (hs : ∀ n, MeasurableSet[ℱ n] (s n)) (n : ℕ) : Integrable (process s n) μ := integrable_finset_sum' _ fun _ _ => IntegrableOn.integrable_indicator (integrable_const 1) <| ℱ.le _ _ <| hs _ end BorelCantelli open BorelCantelli /-- An a.e. monotone adapted process `f` with uniformly bounded differences converges to `+∞` if and only if its predictable part also converges to `+∞`. -/ theorem tendsto_sum_indicator_atTop_iff [IsFiniteMeasure μ] (hfmono : ∀ᵐ ω ∂μ, ∀ n, f n ω ≤ f (n + 1) ω) (hf : Adapted ℱ f) (hint : ∀ n, Integrable (f n) μ) (hbdd : ∀ᵐ ω ∂μ, ∀ n, |f (n + 1) ω - f n ω| ≤ R) : ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop atTop ↔ Tendsto (fun n => predictablePart f ℱ μ n ω) atTop atTop := by have h₁ := (martingale_martingalePart hf hint).ae_not_tendsto_atTop_atTop (martingalePart_bdd_difference ℱ hbdd) have h₂ := (martingale_martingalePart hf hint).ae_not_tendsto_atTop_atBot (martingalePart_bdd_difference ℱ hbdd) have h₃ : ∀ᵐ ω ∂μ, ∀ n, 0 ≤ (μ[f (n + 1) - f n|ℱ n]) ω := by refine ae_all_iff.2 fun n => condexp_nonneg ?_ filter_upwards [ae_all_iff.1 hfmono n] with ω hω using sub_nonneg.2 hω filter_upwards [h₁, h₂, h₃, hfmono] with ω hω₁ hω₂ hω₃ hω₄ constructor <;> intro ht · refine tendsto_atTop_atTop_of_monotone' ?_ ?_ · intro n m hnm simp only [predictablePart, Finset.sum_apply] exact Finset.sum_mono_set_of_nonneg hω₃ (Finset.range_mono hnm) rintro ⟨b, hbdd⟩ rw [← tendsto_neg_atBot_iff] at ht simp only [martingalePart, sub_eq_add_neg] at hω₁ exact hω₁ (tendsto_atTop_add_right_of_le _ (-b) (tendsto_neg_atBot_iff.1 ht) fun n => neg_le_neg (hbdd ⟨n, rfl⟩)) · refine tendsto_atTop_atTop_of_monotone' (monotone_nat_of_le_succ hω₄) ?_ rintro ⟨b, hbdd⟩ exact hω₂ ((tendsto_atBot_add_left_of_ge _ b fun n => hbdd ⟨n, rfl⟩) <| tendsto_neg_atBot_iff.2 ht) open BorelCantelli theorem tendsto_sum_indicator_atTop_iff' [IsFiniteMeasure μ] {s : ℕ → Set Ω} (hs : ∀ n, MeasurableSet[ℱ n] (s n)) : ∀ᵐ ω ∂μ, Tendsto (fun n => ∑ k ∈ Finset.range n, (s (k + 1)).indicator (1 : Ω → ℝ) ω) atTop atTop ↔ Tendsto (fun n => ∑ k ∈ Finset.range n, (μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k]) ω) atTop atTop := by have := tendsto_sum_indicator_atTop_iff (eventually_of_forall fun ω n => ?_) (adapted_process hs) (integrable_process μ hs) (eventually_of_forall <| process_difference_le s) swap · rw [process, process, ← sub_nonneg, Finset.sum_apply, Finset.sum_apply, Finset.sum_range_succ_sub_sum] exact Set.indicator_nonneg (fun _ _ => zero_le_one) _ simp_rw [process, predictablePart_process_ae_eq] at this simpa using this /-- **Lévy's generalization of the Borel-Cantelli lemma**: given a sequence of sets `s` and a filtration `ℱ` such that for all `n`, `s n` is `ℱ n`-measurable, `limsup s atTop` is almost everywhere equal to the set for which `∑ k, ℙ(s (k + 1) | ℱ k) = ∞`. -/ theorem ae_mem_limsup_atTop_iff (μ : Measure Ω) [IsFiniteMeasure μ] {s : ℕ → Set Ω} (hs : ∀ n, MeasurableSet[ℱ n] (s n)) : ∀ᵐ ω ∂μ, ω ∈ limsup s atTop ↔ Tendsto (fun n => ∑ k ∈ Finset.range n, (μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k]) ω) atTop atTop := (limsup_eq_tendsto_sum_indicator_atTop ℝ s).symm ▸ tendsto_sum_indicator_atTop_iff' hs end MeasureTheory
Probability\Martingale\Centering.lean
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Martingale.Basic /-! # Centering lemma for stochastic processes Any `ℕ`-indexed stochastic process which is adapted and integrable can be written as the sum of a martingale and a predictable process. This result is also known as **Doob's decomposition theorem**. From a process `f`, a filtration `ℱ` and a measure `μ`, we define two processes `martingalePart f ℱ μ` and `predictablePart f ℱ μ`. ## Main definitions * `MeasureTheory.predictablePart f ℱ μ`: a predictable process such that `f = predictablePart f ℱ μ + martingalePart f ℱ μ` * `MeasureTheory.martingalePart f ℱ μ`: a martingale such that `f = predictablePart f ℱ μ + martingalePart f ℱ μ` ## Main statements * `MeasureTheory.adapted_predictablePart`: `(fun n => predictablePart f ℱ μ (n+1))` is adapted. That is, `predictablePart` is predictable. * `MeasureTheory.martingale_martingalePart`: `martingalePart f ℱ μ` is a martingale. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory variable {Ω E : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℕ → Ω → E} {ℱ : Filtration ℕ m0} {n : ℕ} /-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable process. This is the predictable process. See `martingalePart` for the martingale. -/ noncomputable def predictablePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0) (μ : Measure Ω) : ℕ → Ω → E := fun n => ∑ i ∈ Finset.range n, μ[f (i + 1) - f i|ℱ i] @[simp] theorem predictablePart_zero : predictablePart f ℱ μ 0 = 0 := by simp_rw [predictablePart, Finset.range_zero, Finset.sum_empty] theorem adapted_predictablePart : Adapted ℱ fun n => predictablePart f ℱ μ (n + 1) := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hin => stronglyMeasurable_condexp.mono (ℱ.mono (Finset.mem_range_succ_iff.mp hin)) theorem adapted_predictablePart' : Adapted ℱ fun n => predictablePart f ℱ μ n := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hin => stronglyMeasurable_condexp.mono (ℱ.mono (Finset.mem_range_le hin)) /-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable process. This is the martingale. See `predictablePart` for the predictable process. -/ noncomputable def martingalePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0) (μ : Measure Ω) : ℕ → Ω → E := fun n => f n - predictablePart f ℱ μ n theorem martingalePart_add_predictablePart (ℱ : Filtration ℕ m0) (μ : Measure Ω) (f : ℕ → Ω → E) : martingalePart f ℱ μ + predictablePart f ℱ μ = f := sub_add_cancel _ _ theorem martingalePart_eq_sum : martingalePart f ℱ μ = fun n => f 0 + ∑ i ∈ Finset.range n, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]) := by unfold martingalePart predictablePart ext1 n rw [Finset.eq_sum_range_sub f n, ← add_sub, ← Finset.sum_sub_distrib] theorem adapted_martingalePart (hf : Adapted ℱ f) : Adapted ℱ (martingalePart f ℱ μ) := Adapted.sub hf adapted_predictablePart' theorem integrable_martingalePart (hf_int : ∀ n, Integrable (f n) μ) (n : ℕ) : Integrable (martingalePart f ℱ μ n) μ := by rw [martingalePart_eq_sum] exact (hf_int 0).add (integrable_finset_sum' _ fun i _ => ((hf_int _).sub (hf_int _)).sub integrable_condexp) theorem martingale_martingalePart (hf : Adapted ℱ f) (hf_int : ∀ n, Integrable (f n) μ) [SigmaFiniteFiltration μ ℱ] : Martingale (martingalePart f ℱ μ) ℱ μ := by refine ⟨adapted_martingalePart hf, fun i j hij => ?_⟩ -- ⊢ μ[martingalePart f ℱ μ j | ℱ i] =ᵐ[μ] martingalePart f ℱ μ i have h_eq_sum : μ[martingalePart f ℱ μ j|ℱ i] =ᵐ[μ] f 0 + ∑ k ∈ Finset.range j, (μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i]) := by rw [martingalePart_eq_sum] refine (condexp_add (hf_int 0) ?_).trans ?_ · exact integrable_finset_sum' _ fun i _ => ((hf_int _).sub (hf_int _)).sub integrable_condexp refine (EventuallyEq.add EventuallyEq.rfl (condexp_finset_sum fun i _ => ?_)).trans ?_ · exact ((hf_int _).sub (hf_int _)).sub integrable_condexp refine EventuallyEq.add ?_ ?_ · rw [condexp_of_stronglyMeasurable (ℱ.le _) _ (hf_int 0)] · exact (hf 0).mono (ℱ.mono (zero_le i)) · exact eventuallyEq_sum fun k _ => condexp_sub ((hf_int _).sub (hf_int _)) integrable_condexp refine h_eq_sum.trans ?_ have h_ge : ∀ k, i ≤ k → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] 0 := by intro k hk have : μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] μ[f (k + 1) - f k|ℱ i] := condexp_condexp_of_le (ℱ.mono hk) (ℱ.le k) filter_upwards [this] with x hx rw [Pi.sub_apply, Pi.zero_apply, hx, sub_self] have h_lt : ∀ k, k < i → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] f (k + 1) - f k - μ[f (k + 1) - f k|ℱ k] := by refine fun k hk => EventuallyEq.sub ?_ ?_ · rw [condexp_of_stronglyMeasurable] · exact ((hf (k + 1)).mono (ℱ.mono (Nat.succ_le_of_lt hk))).sub ((hf k).mono (ℱ.mono hk.le)) · exact (hf_int _).sub (hf_int _) · rw [condexp_of_stronglyMeasurable] · exact stronglyMeasurable_condexp.mono (ℱ.mono hk.le) · exact integrable_condexp rw [martingalePart_eq_sum] refine EventuallyEq.add EventuallyEq.rfl ?_ rw [← Finset.sum_range_add_sum_Ico _ hij, ← add_zero (∑ i ∈ Finset.range i, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]))] refine (eventuallyEq_sum fun k hk => h_lt k (Finset.mem_range.mp hk)).add ?_ refine (eventuallyEq_sum fun k hk => h_ge k (Finset.mem_Ico.mp hk).1).trans ?_ simp only [Finset.sum_const_zero, Pi.zero_apply] rfl -- The following two lemmas demonstrate the essential uniqueness of the decomposition theorem martingalePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E} (hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0) (hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : martingalePart (f + g) ℱ μ n =ᵐ[μ] f n := by set h := f - martingalePart (f + g) ℱ μ with hhdef have hh : h = predictablePart (f + g) ℱ μ - g := by rw [hhdef, sub_eq_sub_iff_add_eq_add, add_comm (predictablePart (f + g) ℱ μ), martingalePart_add_predictablePart] have hhpred : Adapted ℱ fun n => h (n + 1) := by rw [hh] exact adapted_predictablePart.sub hg have hhmgle : Martingale h ℱ μ := hf.sub (martingale_martingalePart (hf.adapted.add <| Predictable.adapted hg <| hg0.symm ▸ stronglyMeasurable_zero) fun n => (hf.integrable n).add <| hgint n) refine (eventuallyEq_iff_sub.2 ?_).symm filter_upwards [hhmgle.eq_zero_of_predictable hhpred n] with ω hω unfold_let h at hω rw [Pi.sub_apply] at hω rw [hω, Pi.sub_apply, martingalePart] simp [hg0] theorem predictablePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E} (hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0) (hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : predictablePart (f + g) ℱ μ n =ᵐ[μ] g n := by filter_upwards [martingalePart_add_ae_eq hf hg hg0 hgint n] with ω hω rw [← add_right_inj (f n ω)] conv_rhs => rw [← Pi.add_apply, ← Pi.add_apply, ← martingalePart_add_predictablePart ℱ μ (f + g)] rw [Pi.add_apply, Pi.add_apply, hω] section Difference theorem predictablePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ∀ i, |predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω| ≤ R := by simp_rw [predictablePart, Finset.sum_apply, Finset.sum_range_succ_sub_sum] exact ae_all_iff.2 fun i => ae_bdd_condexp_of_ae_bdd <| ae_all_iff.1 hbdd i theorem martingalePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ∀ i, |martingalePart f ℱ μ (i + 1) ω - martingalePart f ℱ μ i ω| ≤ ↑(2 * R) := by filter_upwards [hbdd, predictablePart_bdd_difference ℱ hbdd] with ω hω₁ hω₂ i simp only [two_mul, martingalePart, Pi.sub_apply] have : |f (i + 1) ω - predictablePart f ℱ μ (i + 1) ω - (f i ω - predictablePart f ℱ μ i ω)| = |f (i + 1) ω - f i ω - (predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω)| := by ring_nf -- `ring` suggests `ring_nf` despite proving the goal rw [this] exact (abs_sub _ _).trans (add_le_add (hω₁ i) (hω₂ i)) end Difference end MeasureTheory
Probability\Martingale\Convergence.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Constructions.Polish.Basic import Mathlib.MeasureTheory.Function.UniformIntegrable import Mathlib.Probability.Martingale.Upcrossing /-! # Martingale convergence theorems The martingale convergence theorems are a collection of theorems characterizing the convergence of a martingale provided it satisfies some boundedness conditions. This file contains the almost everywhere martingale convergence theorem which provides an almost everywhere limit to an L¹ bounded submartingale. It also contains the L¹ martingale convergence theorem which provides an L¹ limit to a uniformly integrable submartingale. Finally, it also contains the Lévy upwards theorems. ## Main results * `MeasureTheory.Submartingale.ae_tendsto_limitProcess`: the almost everywhere martingale convergence theorem: an L¹-bounded submartingale adapted to the filtration `ℱ` converges almost everywhere to its limit process. * `MeasureTheory.Submartingale.memℒp_limitProcess`: the limit process of an Lᵖ-bounded submartingale is Lᵖ. * `MeasureTheory.Submartingale.tendsto_eLpNorm_one_limitProcess`: part a of the L¹ martingale convergence theorem: a uniformly integrable submartingale adapted to the filtration `ℱ` converges almost everywhere and in L¹ to an integrable function which is measurable with respect to the σ-algebra `⨆ n, ℱ n`. * `MeasureTheory.Martingale.ae_eq_condexp_limitProcess`: part b the L¹ martingale convergence theorem: if `f` is a uniformly integrable martingale adapted to the filtration `ℱ`, then `f n` equals `𝔼[g | ℱ n]` almost everywhere where `g` is the limiting process of `f`. * `MeasureTheory.Integrable.tendsto_ae_condexp`: part c the L¹ martingale convergence theorem: given a `⨆ n, ℱ n`-measurable function `g` where `ℱ` is a filtration, `𝔼[g | ℱ n]` converges almost everywhere to `g`. * `MeasureTheory.Integrable.tendsto_eLpNorm_condexp`: part c the L¹ martingale convergence theorem: given a `⨆ n, ℱ n`-measurable function `g` where `ℱ` is a filtration, `𝔼[g | ℱ n]` converges in L¹ to `g`. -/ open TopologicalSpace Filter MeasureTheory.Filtration open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0} variable {a b : ℝ} {f : ℕ → Ω → ℝ} {ω : Ω} {R : ℝ≥0} section AeConvergence /-! ### Almost everywhere martingale convergence theorem We will now prove the almost everywhere martingale convergence theorem. The a.e. martingale convergence theorem states: if `f` is an L¹-bounded `ℱ`-submartingale, then it converges almost everywhere to an integrable function which is measurable with respect to the σ-algebra `ℱ∞ := ⨆ n, ℱ n`. Mathematically, we proceed by first noting that a real sequence $(x_n)$ converges if (a) $\limsup_{n \to \infty} |x_n| < \infty$, (b) for all $a < b \in \mathbb{Q}$ we have the number of upcrossings of $(x_n)$ from below $a$ to above $b$ is finite. Thus, for all $\omega$ satisfying $\limsup_{n \to \infty} |f_n(\omega)| < \infty$ and the number of upcrossings of $(f_n(\omega))$ from below $a$ to above $b$ is finite for all $a < b \in \mathbb{Q}$, we have $(f_n(\omega))$ is convergent. Hence, assuming $(f_n)$ is L¹-bounded, using Fatou's lemma, we have $$ \mathbb{E} \limsup_{n \to \infty} |f_n| \le \limsup_{n \to \infty} \mathbb{E}|f_n| < \infty $$ implying $\limsup_{n \to \infty} |f_n| < \infty$ a.e. Furthermore, by the upcrossing estimate, the number of upcrossings is finite almost everywhere implying $f$ converges pointwise almost everywhere. Thus, denoting $g$ the a.e. limit of $(f_n)$, $g$ is $\mathcal{F}_\infty$-measurable as for all $n$, $f_n$ is $\mathcal{F}_n$-measurable and $\mathcal{F}_n \le \mathcal{F}_\infty$. Finally, $g$ is integrable as $|g| \le \liminf_{n \to \infty} |f_n|$ so $$ \mathbb{E}|g| \le \mathbb{E} \limsup_{n \to \infty} |f_n| \le \limsup_{n \to \infty} \mathbb{E}|f_n| < \infty $$ as required. Implementationwise, we have `tendsto_of_no_upcrossings` which shows that a bounded sequence converges if it does not visit below $a$ and above $b$ infinitely often for all $a, b ∈ s$ for some dense set $s$. So, we may skip the first step provided we can prove that the realizations are bounded almost everywhere. Indeed, suppose $|f_n(\omega)|$ is not bounded, then either $f_n(\omega) \to \pm \infty$ or one of $\limsup f_n(\omega)$ or $\liminf f_n(\omega)$ equals $\pm \infty$ while the other is finite. But the first case contradicts $\liminf |f_n(\omega)| < \infty$ while the second case contradicts finite upcrossings. Furthermore, we introduce `Filtration.limitProcess` which chooses the limiting random variable of a stochastic process if it exists, otherwise returning 0. Hence, instead of showing an existence statement, we phrase the a.e. martingale convergence theorem by showing that a submartingale converges to its `limitProcess` almost everywhere. -/ /-- If a stochastic process has bounded upcrossing from below `a` to above `b`, then it does not frequently visit both below `a` and above `b`. -/ theorem not_frequently_of_upcrossings_lt_top (hab : a < b) (hω : upcrossings a b f ω ≠ ∞) : ¬((∃ᶠ n in atTop, f n ω < a) ∧ ∃ᶠ n in atTop, b < f n ω) := by rw [← lt_top_iff_ne_top, upcrossings_lt_top_iff] at hω replace hω : ∃ k, ∀ N, upcrossingsBefore a b f N ω < k := by obtain ⟨k, hk⟩ := hω exact ⟨k + 1, fun N => lt_of_le_of_lt (hk N) k.lt_succ_self⟩ rintro ⟨h₁, h₂⟩ rw [frequently_atTop] at h₁ h₂ refine Classical.not_not.2 hω ?_ push_neg intro k induction' k with k ih · simp only [Nat.zero_eq, zero_le, exists_const] · obtain ⟨N, hN⟩ := ih obtain ⟨N₁, hN₁, hN₁'⟩ := h₁ N obtain ⟨N₂, hN₂, hN₂'⟩ := h₂ N₁ exact ⟨N₂ + 1, Nat.succ_le_of_lt <| lt_of_le_of_lt hN (upcrossingsBefore_lt_of_exists_upcrossing hab hN₁ hN₁' hN₂ hN₂')⟩ /-- A stochastic process that frequently visits below `a` and above `b` has infinite upcrossings. -/ theorem upcrossings_eq_top_of_frequently_lt (hab : a < b) (h₁ : ∃ᶠ n in atTop, f n ω < a) (h₂ : ∃ᶠ n in atTop, b < f n ω) : upcrossings a b f ω = ∞ := by_contradiction fun h => not_frequently_of_upcrossings_lt_top hab h ⟨h₁, h₂⟩ /-- A realization of a stochastic process with bounded upcrossings and bounded liminfs is convergent. We use the spelling `< ∞` instead of the standard `≠ ∞` in the assumptions since it is not as easy to change `<` to `≠` under binders. -/ theorem tendsto_of_uncrossing_lt_top (hf₁ : liminf (fun n => (‖f n ω‖₊ : ℝ≥0∞)) atTop < ∞) (hf₂ : ∀ a b : ℚ, a < b → upcrossings a b f ω < ∞) : ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by by_cases h : IsBoundedUnder (· ≤ ·) atTop fun n => |f n ω| · rw [isBoundedUnder_le_abs] at h refine tendsto_of_no_upcrossings Rat.denseRange_cast ?_ h.1 h.2 rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ hab exact not_frequently_of_upcrossings_lt_top hab (hf₂ a b (Rat.cast_lt.1 hab)).ne · obtain ⟨a, b, hab, h₁, h₂⟩ := ENNReal.exists_upcrossings_of_not_bounded_under hf₁.ne h exact False.elim ((hf₂ a b hab).ne (upcrossings_eq_top_of_frequently_lt (Rat.cast_lt.2 hab) h₁ h₂)) /-- An L¹-bounded submartingale has bounded upcrossings almost everywhere. -/ theorem Submartingale.upcrossings_ae_lt_top' [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) (hab : a < b) : ∀ᵐ ω ∂μ, upcrossings a b f ω < ∞ := by refine ae_lt_top (hf.adapted.measurable_upcrossings hab) ?_ have := hf.mul_lintegral_upcrossings_le_lintegral_pos_part a b rw [mul_comm, ← ENNReal.le_div_iff_mul_le] at this · refine (lt_of_le_of_lt this (ENNReal.div_lt_top ?_ ?_)).ne · have hR' : ∀ n, ∫⁻ ω, ‖f n ω - a‖₊ ∂μ ≤ R + ‖a‖₊ * μ Set.univ := by simp_rw [eLpNorm_one_eq_lintegral_nnnorm] at hbdd intro n refine (lintegral_mono ?_ : ∫⁻ ω, ‖f n ω - a‖₊ ∂μ ≤ ∫⁻ ω, ‖f n ω‖₊ + ‖a‖₊ ∂μ).trans ?_ · intro ω simp_rw [sub_eq_add_neg, ← nnnorm_neg a, ← ENNReal.coe_add, ENNReal.coe_le_coe] exact nnnorm_add_le _ _ · simp_rw [lintegral_add_right _ measurable_const, lintegral_const] exact add_le_add (hbdd _) le_rfl refine ne_of_lt (iSup_lt_iff.2 ⟨R + ‖a‖₊ * μ Set.univ, ENNReal.add_lt_top.2 ⟨ENNReal.coe_lt_top, ENNReal.mul_lt_top ENNReal.coe_lt_top.ne (measure_ne_top _ _)⟩, fun n => le_trans ?_ (hR' n)⟩) refine lintegral_mono fun ω => ?_ rw [ENNReal.ofReal_le_iff_le_toReal, ENNReal.coe_toReal, coe_nnnorm] · by_cases hnonneg : 0 ≤ f n ω - a · rw [posPart_eq_self.2 hnonneg, Real.norm_eq_abs, abs_of_nonneg hnonneg] · rw [posPart_eq_zero.2 (not_le.1 hnonneg).le] exact norm_nonneg _ · simp only [Ne, ENNReal.coe_ne_top, not_false_iff] · simp only [hab, Ne, ENNReal.ofReal_eq_zero, sub_nonpos, not_le] · simp only [hab, Ne, ENNReal.ofReal_eq_zero, sub_nonpos, not_le, true_or_iff] · simp only [Ne, ENNReal.ofReal_ne_top, not_false_iff, true_or_iff] theorem Submartingale.upcrossings_ae_lt_top [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) : ∀ᵐ ω ∂μ, ∀ a b : ℚ, a < b → upcrossings a b f ω < ∞ := by simp only [ae_all_iff, eventually_imp_distrib_left] rintro a b hab exact hf.upcrossings_ae_lt_top' hbdd (Rat.cast_lt.2 hab) /-- An L¹-bounded submartingale converges almost everywhere. -/ theorem Submartingale.exists_ae_tendsto_of_bdd [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) : ∀ᵐ ω ∂μ, ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by filter_upwards [hf.upcrossings_ae_lt_top hbdd, ae_bdd_liminf_atTop_of_eLpNorm_bdd one_ne_zero (fun n => (hf.stronglyMeasurable n).measurable.mono (ℱ.le n) le_rfl) hbdd] with ω h₁ h₂ exact tendsto_of_uncrossing_lt_top h₂ h₁ theorem Submartingale.exists_ae_trim_tendsto_of_bdd [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) : ∀ᵐ ω ∂μ.trim (sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _ : ⨆ n, ℱ n ≤ m0), ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by letI := (⨆ n, ℱ n) rw [ae_iff, trim_measurableSet_eq] · exact hf.exists_ae_tendsto_of_bdd hbdd · exact MeasurableSet.compl <| measurableSet_exists_tendsto fun n => (hf.stronglyMeasurable n).measurable.mono (le_sSup ⟨n, rfl⟩) le_rfl /-- **Almost everywhere martingale convergence theorem**: An L¹-bounded submartingale converges almost everywhere to a `⨆ n, ℱ n`-measurable function. -/ theorem Submartingale.ae_tendsto_limitProcess [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) 1 μ ≤ R) : ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (ℱ.limitProcess f μ ω)) := by classical suffices ∃ g, StronglyMeasurable[⨆ n, ℱ n] g ∧ ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) by rw [limitProcess, dif_pos this] exact (Classical.choose_spec this).2 set g' : Ω → ℝ := fun ω => if h : ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) then h.choose else 0 have hle : ⨆ n, ℱ n ≤ m0 := sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _ have hg' : ∀ᵐ ω ∂μ.trim hle, Tendsto (fun n => f n ω) atTop (𝓝 (g' ω)) := by filter_upwards [hf.exists_ae_trim_tendsto_of_bdd hbdd] with ω hω simp_rw [g', dif_pos hω] exact hω.choose_spec have hg'm : @AEStronglyMeasurable _ _ _ (⨆ n, ℱ n) g' (μ.trim hle) := (@aemeasurable_of_tendsto_metrizable_ae' _ _ (⨆ n, ℱ n) _ _ _ _ _ _ _ (fun n => ((hf.stronglyMeasurable n).measurable.mono (le_sSup ⟨n, rfl⟩ : ℱ n ≤ ⨆ n, ℱ n) le_rfl).aemeasurable) hg').aestronglyMeasurable obtain ⟨g, hgm, hae⟩ := hg'm have hg : ∀ᵐ ω ∂μ.trim hle, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) := by filter_upwards [hae, hg'] with ω hω hg'ω exact hω ▸ hg'ω exact ⟨g, hgm, measure_eq_zero_of_trim_eq_zero hle hg⟩ /-- The limiting process of an Lᵖ-bounded submartingale is Lᵖ. -/ theorem Submartingale.memℒp_limitProcess {p : ℝ≥0∞} (hf : Submartingale f ℱ μ) (hbdd : ∀ n, eLpNorm (f n) p μ ≤ R) : Memℒp (ℱ.limitProcess f μ) p μ := memℒp_limitProcess_of_eLpNorm_bdd (fun n => ((hf.stronglyMeasurable n).mono (ℱ.le n)).aestronglyMeasurable) hbdd end AeConvergence section L1Convergence variable [IsFiniteMeasure μ] {g : Ω → ℝ} /-! ### L¹ martingale convergence theorem We will now prove the L¹ martingale convergence theorems. The L¹ martingale convergence theorem states that: (a) if `f` is a uniformly integrable (in the probability sense) submartingale adapted to the filtration `ℱ`, it converges in L¹ to an integrable function `g` which is measurable with respect to `ℱ∞ := ⨆ n, ℱ n` and (b) if `f` is actually a martingale, `f n = 𝔼[g | ℱ n]` almost everywhere. (c) Finally, if `h` is integrable and measurable with respect to `ℱ∞`, `(𝔼[h | ℱ n])ₙ` is a uniformly integrable martingale which converges to `h` almost everywhere and in L¹. The proof is quite simple. (a) follows directly from the a.e. martingale convergence theorem and the Vitali convergence theorem as our definition of uniform integrability (in the probability sense) directly implies L¹-uniform boundedness. We note that our definition of uniform integrability is slightly non-standard but is equivalent to the usual literary definition. This equivalence is provided by `MeasureTheory.uniformIntegrable_iff`. (b) follows since given $n$, we have for all $m \ge n$, $$ \|f_n - \mathbb{E}[g \mid \mathcal{F}_n]\|_1 = \|\mathbb{E}[f_m - g \mid \mathcal{F}_n]\|_1 \le \|\|f_m - g\|_1. $$ Thus, taking $m \to \infty$ provides the almost everywhere equality. Finally, to prove (c), we define $f_n := \mathbb{E}[h \mid \mathcal{F}_n]$. It is clear that $(f_n)_n$ is a martingale by the tower property for conditional expectations. Furthermore, $(f_n)_n$ is uniformly integrable in the probability sense. Indeed, as a single function is uniformly integrable in the measure theory sense, for all $\epsilon > 0$, there exists some $\delta > 0$ such that for all measurable set $A$ with $\mu(A) < δ$, we have $\mathbb{E}|h|\mathbf{1}_A < \epsilon$. So, since for sufficently large $\lambda$, by the Markov inequality, we have for all $n$, $$ \mu(|f_n| \ge \lambda) \le \lambda^{-1}\mathbb{E}|f_n| \le \lambda^{-1}\mathbb|g| < \delta, $$ we have for sufficently large $\lambda$, for all $n$, $$ \mathbb{E}|f_n|\mathbf{1}_{|f_n| \ge \lambda} \le \mathbb|g|\mathbf{1}_{|f_n| \ge \lambda} < \epsilon, $$ implying $(f_n)_n$ is uniformly integrable. Now, to prove $f_n \to h$ almost everywhere and in L¹, it suffices to show that $h = g$ almost everywhere where $g$ is the almost everywhere and L¹ limit of $(f_n)_n$ from part (b) of the theorem. By noting that, for all $s \in \mathcal{F}_n$, we have $$ \mathbb{E}g\mathbf{1}_s = \mathbb{E}[\mathbb{E}[g \mid \mathcal{F}_n]\mathbf{1}_s] = \mathbb{E}[\mathbb{E}[h \mid \mathcal{F}_n]\mathbf{1}_s] = \mathbb{E}h\mathbf{1}_s $$ where $\mathbb{E}[g \mid \mathcal{F}_n = \mathbb{E}[h \mid \mathcal{F}_n]$ almost everywhere by part (b); the equality also holds for all $s \in \mathcal{F}_\infty$ by Dynkin's theorem. Thus, as both $h$ and $g$ are $\mathcal{F}_\infty$-measurable, $h = g$ almost everywhere as required. Similar to the a.e. martingale convergence theorem, rather than showing the existence of the limiting process, we phrase the L¹-martingale convergence theorem by proving that a submartingale does converge in L¹ to its `limitProcess`. However, in contrast to the a.e. martingale convergence theorem, we do not need to introduce an L¹ version of `Filtration.limitProcess` as the L¹ limit and the a.e. limit of a submartingale coincide. -/ /-- Part a of the **L¹ martingale convergence theorem**: a uniformly integrable submartingale adapted to the filtration `ℱ` converges a.e. and in L¹ to an integrable function which is measurable with respect to the σ-algebra `⨆ n, ℱ n`. -/ theorem Submartingale.tendsto_eLpNorm_one_limitProcess (hf : Submartingale f ℱ μ) (hunif : UniformIntegrable f 1 μ) : Tendsto (fun n => eLpNorm (f n - ℱ.limitProcess f μ) 1 μ) atTop (𝓝 0) := by obtain ⟨R, hR⟩ := hunif.2.2 have hmeas : ∀ n, AEStronglyMeasurable (f n) μ := fun n => ((hf.stronglyMeasurable n).mono (ℱ.le _)).aestronglyMeasurable exact tendsto_Lp_finite_of_tendstoInMeasure le_rfl ENNReal.one_ne_top hmeas (memℒp_limitProcess_of_eLpNorm_bdd hmeas hR) hunif.2.1 (tendstoInMeasure_of_tendsto_ae hmeas <| hf.ae_tendsto_limitProcess hR) @[deprecated (since := "2024-07-27")] alias Submartingale.tendsto_snorm_one_limitProcess := Submartingale.tendsto_eLpNorm_one_limitProcess theorem Submartingale.ae_tendsto_limitProcess_of_uniformIntegrable (hf : Submartingale f ℱ μ) (hunif : UniformIntegrable f 1 μ) : ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (ℱ.limitProcess f μ ω)) := let ⟨_, hR⟩ := hunif.2.2 hf.ae_tendsto_limitProcess hR /-- If a martingale `f` adapted to `ℱ` converges in L¹ to `g`, then for all `n`, `f n` is almost everywhere equal to `𝔼[g | ℱ n]`. -/ theorem Martingale.eq_condexp_of_tendsto_eLpNorm {μ : Measure Ω} (hf : Martingale f ℱ μ) (hg : Integrable g μ) (hgtends : Tendsto (fun n => eLpNorm (f n - g) 1 μ) atTop (𝓝 0)) (n : ℕ) : f n =ᵐ[μ] μ[g|ℱ n] := by rw [← sub_ae_eq_zero, ← eLpNorm_eq_zero_iff (((hf.stronglyMeasurable n).mono (ℱ.le _)).sub (stronglyMeasurable_condexp.mono (ℱ.le _))).aestronglyMeasurable one_ne_zero] have ht : Tendsto (fun m => eLpNorm (μ[f m - g|ℱ n]) 1 μ) atTop (𝓝 0) := haveI hint : ∀ m, Integrable (f m - g) μ := fun m => (hf.integrable m).sub hg tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hgtends (fun m => zero_le _) fun m => eLpNorm_one_condexp_le_eLpNorm _ have hev : ∀ m ≥ n, eLpNorm (μ[f m - g|ℱ n]) 1 μ = eLpNorm (f n - μ[g|ℱ n]) 1 μ := by refine fun m hm => eLpNorm_congr_ae ((condexp_sub (hf.integrable m) hg).trans ?_) filter_upwards [hf.2 n m hm] with x hx simp only [hx, Pi.sub_apply] exact tendsto_nhds_unique (tendsto_atTop_of_eventually_const hev) ht @[deprecated (since := "2024-07-27")] alias Martingale.eq_condexp_of_tendsto_snorm := Martingale.eq_condexp_of_tendsto_eLpNorm /-- Part b of the **L¹ martingale convergence theorem**: if `f` is a uniformly integrable martingale adapted to the filtration `ℱ`, then for all `n`, `f n` is almost everywhere equal to the conditional expectation of its limiting process wrt. `ℱ n`. -/ theorem Martingale.ae_eq_condexp_limitProcess (hf : Martingale f ℱ μ) (hbdd : UniformIntegrable f 1 μ) (n : ℕ) : f n =ᵐ[μ] μ[ℱ.limitProcess f μ|ℱ n] := let ⟨_, hR⟩ := hbdd.2.2 hf.eq_condexp_of_tendsto_eLpNorm ((memℒp_limitProcess_of_eLpNorm_bdd hbdd.1 hR).integrable le_rfl) (hf.submartingale.tendsto_eLpNorm_one_limitProcess hbdd) n /-- Part c of the **L¹ martingale convergence theorem**: Given an integrable function `g` which is measurable with respect to `⨆ n, ℱ n` where `ℱ` is a filtration, the martingale defined by `𝔼[g | ℱ n]` converges almost everywhere to `g`. This martingale also converges to `g` in L¹ and this result is provided by `MeasureTheory.Integrable.tendsto_eLpNorm_condexp` -/ theorem Integrable.tendsto_ae_condexp (hg : Integrable g μ) (hgmeas : StronglyMeasurable[⨆ n, ℱ n] g) : ∀ᵐ x ∂μ, Tendsto (fun n => (μ[g|ℱ n]) x) atTop (𝓝 (g x)) := by have hle : ⨆ n, ℱ n ≤ m0 := sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _ have hunif : UniformIntegrable (fun n => μ[g|ℱ n]) 1 μ := hg.uniformIntegrable_condexp_filtration obtain ⟨R, hR⟩ := hunif.2.2 have hlimint : Integrable (ℱ.limitProcess (fun n => μ[g|ℱ n]) μ) μ := (memℒp_limitProcess_of_eLpNorm_bdd hunif.1 hR).integrable le_rfl suffices g =ᵐ[μ] ℱ.limitProcess (fun n x => (μ[g|ℱ n]) x) μ by filter_upwards [this, (martingale_condexp g ℱ μ).submartingale.ae_tendsto_limitProcess hR] with x heq ht rwa [heq] have : ∀ n s, MeasurableSet[ℱ n] s → ∫ x in s, g x ∂μ = ∫ x in s, ℱ.limitProcess (fun n x => (μ[g|ℱ n]) x) μ x ∂μ := by intro n s hs rw [← setIntegral_condexp (ℱ.le n) hg hs, ← setIntegral_condexp (ℱ.le n) hlimint hs] refine setIntegral_congr_ae (ℱ.le _ _ hs) ?_ filter_upwards [(martingale_condexp g ℱ μ).ae_eq_condexp_limitProcess hunif n] with x hx _ rw [hx] refine ae_eq_of_forall_setIntegral_eq_of_sigmaFinite' hle (fun s _ _ => hg.integrableOn) (fun s _ _ => hlimint.integrableOn) (fun s hs => ?_) hgmeas.aeStronglyMeasurable' stronglyMeasurable_limitProcess.aeStronglyMeasurable' apply @MeasurableSpace.induction_on_inter _ _ _ (⨆ n, ℱ n) (MeasurableSpace.measurableSpace_iSup_eq ℱ) _ _ _ _ _ _ hs · rintro s ⟨n, hs⟩ t ⟨m, ht⟩ - by_cases hnm : n ≤ m · exact ⟨m, (ℱ.mono hnm _ hs).inter ht⟩ · exact ⟨n, hs.inter (ℱ.mono (not_le.1 hnm).le _ ht)⟩ · simp only [measure_empty, ENNReal.zero_lt_top, Measure.restrict_empty, integral_zero_measure, forall_true_left] · rintro t ⟨n, ht⟩ - exact this n _ ht · rintro t htmeas ht - have hgeq := @setIntegral_compl _ _ (⨆ n, ℱ n) _ _ _ _ _ htmeas (hg.trim hle hgmeas) have hheq := @setIntegral_compl _ _ (⨆ n, ℱ n) _ _ _ _ _ htmeas (hlimint.trim hle stronglyMeasurable_limitProcess) rw [setIntegral_trim hle hgmeas htmeas.compl, setIntegral_trim hle stronglyMeasurable_limitProcess htmeas.compl, hgeq, hheq, ← setIntegral_trim hle hgmeas htmeas, ← setIntegral_trim hle stronglyMeasurable_limitProcess htmeas, ← integral_trim hle hgmeas, ← integral_trim hle stronglyMeasurable_limitProcess, ← integral_univ, this 0 _ MeasurableSet.univ, integral_univ, ht (measure_lt_top _ _)] · rintro f hf hfmeas heq - rw [integral_iUnion (fun n => hle _ (hfmeas n)) hf hg.integrableOn, integral_iUnion (fun n => hle _ (hfmeas n)) hf hlimint.integrableOn] exact tsum_congr fun n => heq _ (measure_lt_top _ _) /-- Part c of the **L¹ martingale convergence theorem**: Given an integrable function `g` which is measurable with respect to `⨆ n, ℱ n` where `ℱ` is a filtration, the martingale defined by `𝔼[g | ℱ n]` converges in L¹ to `g`. This martingale also converges to `g` almost everywhere and this result is provided by `MeasureTheory.Integrable.tendsto_ae_condexp` -/ theorem Integrable.tendsto_eLpNorm_condexp (hg : Integrable g μ) (hgmeas : StronglyMeasurable[⨆ n, ℱ n] g) : Tendsto (fun n => eLpNorm (μ[g|ℱ n] - g) 1 μ) atTop (𝓝 0) := tendsto_Lp_finite_of_tendstoInMeasure le_rfl ENNReal.one_ne_top (fun n => (stronglyMeasurable_condexp.mono (ℱ.le n)).aestronglyMeasurable) (memℒp_one_iff_integrable.2 hg) hg.uniformIntegrable_condexp_filtration.2.1 (tendstoInMeasure_of_tendsto_ae (fun n => (stronglyMeasurable_condexp.mono (ℱ.le n)).aestronglyMeasurable) (hg.tendsto_ae_condexp hgmeas)) @[deprecated (since := "2024-07-27")] alias Integrable.tendsto_snorm_condexp := Integrable.tendsto_eLpNorm_condexp /-- **Lévy's upward theorem**, almost everywhere version: given a function `g` and a filtration `ℱ`, the sequence defined by `𝔼[g | ℱ n]` converges almost everywhere to `𝔼[g | ⨆ n, ℱ n]`. -/ theorem tendsto_ae_condexp (g : Ω → ℝ) : ∀ᵐ x ∂μ, Tendsto (fun n => (μ[g|ℱ n]) x) atTop (𝓝 ((μ[g|⨆ n, ℱ n]) x)) := by have ht : ∀ᵐ x ∂μ, Tendsto (fun n => (μ[μ[g|⨆ n, ℱ n]|ℱ n]) x) atTop (𝓝 ((μ[g|⨆ n, ℱ n]) x)) := integrable_condexp.tendsto_ae_condexp stronglyMeasurable_condexp have heq : ∀ n, ∀ᵐ x ∂μ, (μ[μ[g|⨆ n, ℱ n]|ℱ n]) x = (μ[g|ℱ n]) x := fun n => condexp_condexp_of_le (le_iSup _ n) (iSup_le fun n => ℱ.le n) rw [← ae_all_iff] at heq filter_upwards [heq, ht] with x hxeq hxt exact hxt.congr hxeq /-- **Lévy's upward theorem**, L¹ version: given a function `g` and a filtration `ℱ`, the sequence defined by `𝔼[g | ℱ n]` converges in L¹ to `𝔼[g | ⨆ n, ℱ n]`. -/ theorem tendsto_eLpNorm_condexp (g : Ω → ℝ) : Tendsto (fun n => eLpNorm (μ[g|ℱ n] - μ[g|⨆ n, ℱ n]) 1 μ) atTop (𝓝 0) := by have ht : Tendsto (fun n => eLpNorm (μ[μ[g|⨆ n, ℱ n]|ℱ n] - μ[g|⨆ n, ℱ n]) 1 μ) atTop (𝓝 0) := integrable_condexp.tendsto_eLpNorm_condexp stronglyMeasurable_condexp have heq : ∀ n, ∀ᵐ x ∂μ, (μ[μ[g|⨆ n, ℱ n]|ℱ n]) x = (μ[g|ℱ n]) x := fun n => condexp_condexp_of_le (le_iSup _ n) (iSup_le fun n => ℱ.le n) refine ht.congr fun n => eLpNorm_congr_ae ?_ filter_upwards [heq n] with x hxeq simp only [hxeq, Pi.sub_apply] @[deprecated (since := "2024-07-27")] alias tendsto_snorm_condexp := tendsto_eLpNorm_condexp end L1Convergence end MeasureTheory
Probability\Martingale\OptionalSampling.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.Order.SuccPred.LinearLocallyFinite import Mathlib.Probability.Martingale.Basic /-! # Optional sampling theorem If `τ` is a bounded stopping time and `σ` is another stopping time, then the value of a martingale `f` at the stopping time `min τ σ` is almost everywhere equal to `μ[stoppedValue f τ | hσ.measurableSpace]`. ## Main results * `stoppedValue_ae_eq_condexp_of_le_const`: the value of a martingale `f` at a stopping time `τ` bounded by `n` is the conditional expectation of `f n` with respect to the σ-algebra generated by `τ`. * `stoppedValue_ae_eq_condexp_of_le`: if `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is bounded, then the value of a martingale `f` at `σ` is the conditional expectation of its value at `τ` with respect to the σ-algebra generated by `σ`. * `stoppedValue_min_ae_eq_condexp`: the optional sampling theorem. If `τ` is a bounded stopping time and `σ` is another stopping time, then the value of a martingale `f` at the stopping time `min τ σ` is almost everywhere equal to the conditional expectation of `f` stopped at `τ` with respect to the σ-algebra generated by `σ`. -/ open scoped MeasureTheory ENNReal open TopologicalSpace namespace MeasureTheory namespace Martingale variable {Ω E : Type*} {m : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] section FirstCountableTopology variable {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] {ℱ : Filtration ι m} [SigmaFiniteFiltration μ ℱ] {τ σ : Ω → ι} {f : ι → Ω → E} {i n : ι} theorem condexp_stopping_time_ae_eq_restrict_eq_const [(Filter.atTop : Filter ι).IsCountablyGenerated] (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le)] (hin : i ≤ n) : μ[f n|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] f i := by refine Filter.EventuallyEq.trans ?_ (ae_restrict_of_ae (h.condexp_ae_eq hin)) refine condexp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (ℱ.le i) (hτ.measurableSet_eq' i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] theorem condexp_stopping_time_ae_eq_restrict_eq_const_of_le_const (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] (i : ι) : μ[f n|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] f i := by by_cases hin : i ≤ n · refine Filter.EventuallyEq.trans ?_ (ae_restrict_of_ae (h.condexp_ae_eq hin)) refine condexp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_le hτ_le) (ℱ.le i) (hτ.measurableSet_eq' i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] · suffices {x : Ω | τ x = i} = ∅ by simp [this]; norm_cast ext1 x simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] rintro rfl exact hin (hτ_le x) theorem stoppedValue_ae_eq_restrict_eq (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] (i : ι) : stoppedValue f τ =ᵐ[μ.restrict {x | τ x = i}] μ[f n|hτ.measurableSpace] := by refine Filter.EventuallyEq.trans ?_ (condexp_stopping_time_ae_eq_restrict_eq_const_of_le_const h hτ hτ_le i).symm rw [Filter.EventuallyEq, ae_restrict_iff' (ℱ.le _ _ (hτ.measurableSet_eq i))] refine Filter.eventually_of_forall fun x hx => ?_ rw [Set.mem_setOf_eq] at hx simp_rw [stoppedValue, hx] /-- The value of a martingale `f` at a stopping time `τ` bounded by `n` is the conditional expectation of `f n` with respect to the σ-algebra generated by `τ`. -/ theorem stoppedValue_ae_eq_condexp_of_le_const_of_countable_range (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n) (h_countable_range : (Set.range τ).Countable) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] : stoppedValue f τ =ᵐ[μ] μ[f n|hτ.measurableSpace] := by have : Set.univ = ⋃ i ∈ Set.range τ, {x | τ x = i} := by ext1 x simp only [Set.mem_univ, Set.mem_range, true_and_iff, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_iUnion, Set.mem_setOf_eq, exists_apply_eq_apply'] nth_rw 1 [← @Measure.restrict_univ Ω _ μ] rw [this, ae_eq_restrict_biUnion_iff _ h_countable_range] exact fun i _ => stoppedValue_ae_eq_restrict_eq h _ hτ_le i /-- The value of a martingale `f` at a stopping time `τ` bounded by `n` is the conditional expectation of `f n` with respect to the σ-algebra generated by `τ`. -/ theorem stoppedValue_ae_eq_condexp_of_le_const [Countable ι] (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] : stoppedValue f τ =ᵐ[μ] μ[f n|hτ.measurableSpace] := h.stoppedValue_ae_eq_condexp_of_le_const_of_countable_range hτ hτ_le (Set.to_countable _) /-- If `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is bounded, then the value of a martingale `f` at `σ` is the conditional expectation of its value at `τ` with respect to the σ-algebra generated by `σ`. -/ theorem stoppedValue_ae_eq_condexp_of_le_of_countable_range (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) (hσ_le_τ : σ ≤ τ) (hτ_le : ∀ x, τ x ≤ n) (hτ_countable_range : (Set.range τ).Countable) (hσ_countable_range : (Set.range σ).Countable) [SigmaFinite (μ.trim (hσ.measurableSpace_le_of_le fun x => (hσ_le_τ x).trans (hτ_le x)))] : stoppedValue f σ =ᵐ[μ] μ[stoppedValue f τ|hσ.measurableSpace] := by have : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := sigmaFiniteTrim_mono _ (IsStoppingTime.measurableSpace_mono hσ hτ hσ_le_τ) have : μ[stoppedValue f τ|hσ.measurableSpace] =ᵐ[μ] μ[μ[f n|hτ.measurableSpace]|hσ.measurableSpace] := condexp_congr_ae (h.stoppedValue_ae_eq_condexp_of_le_const_of_countable_range hτ hτ_le hτ_countable_range) refine (Filter.EventuallyEq.trans ?_ (condexp_condexp_of_le ?_ (hτ.measurableSpace_le_of_le hτ_le)).symm).trans this.symm · exact h.stoppedValue_ae_eq_condexp_of_le_const_of_countable_range hσ (fun x => (hσ_le_τ x).trans (hτ_le x)) hσ_countable_range · exact hσ.measurableSpace_mono hτ hσ_le_τ /-- If `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is bounded, then the value of a martingale `f` at `σ` is the conditional expectation of its value at `τ` with respect to the σ-algebra generated by `σ`. -/ theorem stoppedValue_ae_eq_condexp_of_le [Countable ι] (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) (hσ_le_τ : σ ≤ τ) (hτ_le : ∀ x, τ x ≤ n) [SigmaFinite (μ.trim hσ.measurableSpace_le)] : stoppedValue f σ =ᵐ[μ] μ[stoppedValue f τ|hσ.measurableSpace] := h.stoppedValue_ae_eq_condexp_of_le_of_countable_range hτ hσ hσ_le_τ hτ_le (Set.to_countable _) (Set.to_countable _) end FirstCountableTopology section SubsetOfNat /-! In the following results the index set verifies `[LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι]`, which means that it is order-isomorphic to a subset of `ℕ`. `ι` is equipped with the discrete topology, which is also the order topology, and is a measurable space with the Borel σ-algebra. -/ variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι] [TopologicalSpace ι] [DiscreteTopology ι] [MeasurableSpace ι] [BorelSpace ι] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] {ℱ : Filtration ι m} {τ σ : Ω → ι} {f : ι → Ω → E} {i n : ι} theorem condexp_stoppedValue_stopping_time_ae_eq_restrict_le (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) [SigmaFinite (μ.trim hσ.measurableSpace_le)] (hτ_le : ∀ x, τ x ≤ n) : μ[stoppedValue f τ|hσ.measurableSpace] =ᵐ[μ.restrict {x : Ω | τ x ≤ σ x}] stoppedValue f τ := by rw [ae_eq_restrict_iff_indicator_ae_eq (hτ.measurableSpace_le _ (hτ.measurableSet_le_stopping_time hσ))] refine (condexp_indicator (integrable_stoppedValue ι hτ h.integrable hτ_le) (hτ.measurableSet_stopping_time_le hσ)).symm.trans ?_ have h_int : Integrable ({ω : Ω | τ ω ≤ σ ω}.indicator (stoppedValue (fun n : ι => f n) τ)) μ := by refine (integrable_stoppedValue ι hτ h.integrable hτ_le).indicator ?_ exact hτ.measurableSpace_le _ (hτ.measurableSet_le_stopping_time hσ) have h_meas : AEStronglyMeasurable' hσ.measurableSpace ({ω : Ω | τ ω ≤ σ ω}.indicator (stoppedValue (fun n : ι => f n) τ)) μ := by refine StronglyMeasurable.aeStronglyMeasurable' ?_ refine StronglyMeasurable.stronglyMeasurable_of_measurableSpace_le_on (hτ.measurableSet_le_stopping_time hσ) ?_ ?_ ?_ · intro t ht rw [Set.inter_comm _ t] at ht ⊢ rw [hτ.measurableSet_inter_le_iff hσ, IsStoppingTime.measurableSet_min_iff hτ hσ] at ht exact ht.2 · refine StronglyMeasurable.indicator ?_ (hτ.measurableSet_le_stopping_time hσ) refine Measurable.stronglyMeasurable ?_ exact measurable_stoppedValue h.adapted.progMeasurable_of_discrete hτ · intro x hx simp only [hx, Set.indicator_of_not_mem, not_false_iff] exact condexp_of_aestronglyMeasurable' hσ.measurableSpace_le h_meas h_int /-- **Optional Sampling theorem**. If `τ` is a bounded stopping time and `σ` is another stopping time, then the value of a martingale `f` at the stopping time `min τ σ` is almost everywhere equal to the conditional expectation of `f` stopped at `τ` with respect to the σ-algebra generated by `σ`. -/ theorem stoppedValue_min_ae_eq_condexp [SigmaFiniteFiltration μ ℱ] (h : Martingale f ℱ μ) (hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) {n : ι} (hτ_le : ∀ x, τ x ≤ n) [h_sf_min : SigmaFinite (μ.trim (hτ.min hσ).measurableSpace_le)] : (stoppedValue f fun x => min (σ x) (τ x)) =ᵐ[μ] μ[stoppedValue f τ|hσ.measurableSpace] := by refine (h.stoppedValue_ae_eq_condexp_of_le hτ (hσ.min hτ) (fun x => min_le_right _ _) hτ_le).trans ?_ refine ae_of_ae_restrict_of_ae_restrict_compl {x | σ x ≤ τ x} ?_ ?_ · exact condexp_min_stopping_time_ae_eq_restrict_le hσ hτ · suffices μ[stoppedValue f τ|(hσ.min hτ).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ σ x}] μ[stoppedValue f τ|hσ.measurableSpace] by rw [ae_restrict_iff' (hσ.measurableSpace_le _ (hσ.measurableSet_le_stopping_time hτ).compl)] rw [Filter.EventuallyEq, ae_restrict_iff'] at this swap; · exact hτ.measurableSpace_le _ (hτ.measurableSet_le_stopping_time hσ) filter_upwards [this] with x hx hx_mem simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hx_mem exact hx hx_mem.le apply Filter.EventuallyEq.trans _ ((condexp_min_stopping_time_ae_eq_restrict_le hτ hσ).trans _) · exact stoppedValue f τ · rw [IsStoppingTime.measurableSpace_min hσ, IsStoppingTime.measurableSpace_min hτ, inf_comm] · have h1 : μ[stoppedValue f τ|hτ.measurableSpace] = stoppedValue f τ := by apply condexp_of_stronglyMeasurable hτ.measurableSpace_le · exact Measurable.stronglyMeasurable <| measurable_stoppedValue h.adapted.progMeasurable_of_discrete hτ · exact integrable_stoppedValue ι hτ h.integrable hτ_le rw [h1] exact (condexp_stoppedValue_stopping_time_ae_eq_restrict_le h hτ hσ hτ_le).symm end SubsetOfNat end Martingale end MeasureTheory
Probability\Martingale\OptionalStopping.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Process.HittingTime import Mathlib.Probability.Martingale.Basic /-! # Optional stopping theorem (fair game theorem) The optional stopping theorem states that an adapted integrable process `f` is a submartingale if and only if for all bounded stopping times `τ` and `π` such that `τ ≤ π`, the stopped value of `f` at `τ` has expectation smaller than its stopped value at `π`. This file also contains Doob's maximal inequality: given a non-negative submartingale `f`, for all `ε : ℝ≥0`, we have `ε • μ {ε ≤ f* n} ≤ ∫ ω in {ε ≤ f* n}, f n` where `f* n ω = max_{k ≤ n}, f k ω`. ### Main results * `MeasureTheory.submartingale_iff_expected_stoppedValue_mono`: the optional stopping theorem. * `MeasureTheory.Submartingale.stoppedProcess`: the stopped process of a submartingale with respect to a stopping time is a submartingale. * `MeasureTheory.maximal_ineq`: Doob's maximal inequality. -/ open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {𝒢 : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {τ π : Ω → ℕ} -- We may generalize the below lemma to functions taking value in a `NormedLatticeAddCommGroup`. -- Similarly, generalize `(Super/Sub)martingale.setIntegral_le`. /-- Given a submartingale `f` and bounded stopping times `τ` and `π` such that `τ ≤ π`, the expectation of `stoppedValue f τ` is less than or equal to the expectation of `stoppedValue f π`. This is the forward direction of the optional stopping theorem. -/ theorem Submartingale.expected_stoppedValue_mono [SigmaFiniteFiltration μ 𝒢] (hf : Submartingale f 𝒢 μ) (hτ : IsStoppingTime 𝒢 τ) (hπ : IsStoppingTime 𝒢 π) (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) : μ[stoppedValue f τ] ≤ μ[stoppedValue f π] := by rw [← sub_nonneg, ← integral_sub', stoppedValue_sub_eq_sum' hle hbdd] · simp only [Finset.sum_apply] have : ∀ i, MeasurableSet[𝒢 i] {ω : Ω | τ ω ≤ i ∧ i < π ω} := by intro i refine (hτ i).inter ?_ convert (hπ i).compl using 1 ext x simp; rfl rw [integral_finset_sum] · refine Finset.sum_nonneg fun i _ => ?_ rw [integral_indicator (𝒢.le _ _ (this _)), integral_sub', sub_nonneg] · exact hf.setIntegral_le (Nat.le_succ i) (this _) · exact (hf.integrable _).integrableOn · exact (hf.integrable _).integrableOn intro i _ exact Integrable.indicator (Integrable.sub (hf.integrable _) (hf.integrable _)) (𝒢.le _ _ (this _)) · exact hf.integrable_stoppedValue hπ hbdd · exact hf.integrable_stoppedValue hτ fun ω => le_trans (hle ω) (hbdd ω) /-- The converse direction of the optional stopping theorem, i.e. an adapted integrable process `f` is a submartingale if for all bounded stopping times `τ` and `π` such that `τ ≤ π`, the stopped value of `f` at `τ` has expectation smaller than its stopped value at `π`. -/ theorem submartingale_of_expected_stoppedValue_mono [IsFiniteMeasure μ] (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) (hf : ∀ τ π : Ω → ℕ, IsStoppingTime 𝒢 τ → IsStoppingTime 𝒢 π → τ ≤ π → (∃ N, ∀ ω, π ω ≤ N) → μ[stoppedValue f τ] ≤ μ[stoppedValue f π]) : Submartingale f 𝒢 μ := by refine submartingale_of_setIntegral_le hadp hint fun i j hij s hs => ?_ classical specialize hf (s.piecewise (fun _ => i) fun _ => j) _ (isStoppingTime_piecewise_const hij hs) (isStoppingTime_const 𝒢 j) (fun x => (ite_le_sup _ _ (x ∈ s)).trans (max_eq_right hij).le) ⟨j, fun _ => le_rfl⟩ rwa [stoppedValue_const, stoppedValue_piecewise_const, integral_piecewise (𝒢.le _ _ hs) (hint _).integrableOn (hint _).integrableOn, ← integral_add_compl (𝒢.le _ _ hs) (hint j), add_le_add_iff_right] at hf /-- **The optional stopping theorem** (fair game theorem): an adapted integrable process `f` is a submartingale if and only if for all bounded stopping times `τ` and `π` such that `τ ≤ π`, the stopped value of `f` at `τ` has expectation smaller than its stopped value at `π`. -/ theorem submartingale_iff_expected_stoppedValue_mono [IsFiniteMeasure μ] (hadp : Adapted 𝒢 f) (hint : ∀ i, Integrable (f i) μ) : Submartingale f 𝒢 μ ↔ ∀ τ π : Ω → ℕ, IsStoppingTime 𝒢 τ → IsStoppingTime 𝒢 π → τ ≤ π → (∃ N, ∀ x, π x ≤ N) → μ[stoppedValue f τ] ≤ μ[stoppedValue f π] := ⟨fun hf _ _ hτ hπ hle ⟨_, hN⟩ => hf.expected_stoppedValue_mono hτ hπ hle hN, submartingale_of_expected_stoppedValue_mono hadp hint⟩ /-- The stopped process of a submartingale with respect to a stopping time is a submartingale. -/ protected theorem Submartingale.stoppedProcess [IsFiniteMeasure μ] (h : Submartingale f 𝒢 μ) (hτ : IsStoppingTime 𝒢 τ) : Submartingale (stoppedProcess f τ) 𝒢 μ := by rw [submartingale_iff_expected_stoppedValue_mono] · intro σ π hσ hπ hσ_le_π hπ_bdd simp_rw [stoppedValue_stoppedProcess] obtain ⟨n, hπ_le_n⟩ := hπ_bdd exact h.expected_stoppedValue_mono (hσ.min hτ) (hπ.min hτ) (fun ω => min_le_min (hσ_le_π ω) le_rfl) fun ω => (min_le_left _ _).trans (hπ_le_n ω) · exact Adapted.stoppedProcess_of_discrete h.adapted hτ · exact fun i => h.integrable_stoppedValue ((isStoppingTime_const _ i).min hτ) fun ω => min_le_left _ _ section Maximal open Finset theorem smul_le_stoppedValue_hitting [IsFiniteMeasure μ] (hsub : Submartingale f 𝒢 μ) {ε : ℝ≥0} (n : ℕ) : ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω} ≤ ENNReal.ofReal (∫ ω in {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω}, stoppedValue f (hitting f {y : ℝ | ↑ε ≤ y} 0 n) ω ∂μ) := by have hn : Set.Icc 0 n = {k | k ≤ n} := by ext x; simp have : ∀ ω, ((ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω) → (ε : ℝ) ≤ stoppedValue f (hitting f {y : ℝ | ↑ε ≤ y} 0 n) ω := by intro x hx simp_rw [le_sup'_iff, mem_range, Nat.lt_succ_iff] at hx refine stoppedValue_hitting_mem ?_ simp only [Set.mem_setOf_eq, exists_prop, hn] exact let ⟨j, hj₁, hj₂⟩ := hx ⟨j, hj₁, hj₂⟩ have h := setIntegral_ge_of_const_le (measurableSet_le measurable_const (Finset.measurable_range_sup'' fun n _ => (hsub.stronglyMeasurable n).measurable.le (𝒢.le n))) (measure_ne_top _ _) this (Integrable.integrableOn (hsub.integrable_stoppedValue (hitting_isStoppingTime hsub.adapted measurableSet_Ici) hitting_le)) rw [ENNReal.le_ofReal_iff_toReal_le, ENNReal.toReal_smul] · exact h · exact ENNReal.mul_ne_top (by simp) (measure_ne_top _ _) · exact le_trans (mul_nonneg ε.coe_nonneg ENNReal.toReal_nonneg) h /-- **Doob's maximal inequality**: Given a non-negative submartingale `f`, for all `ε : ℝ≥0`, we have `ε • μ {ε ≤ f* n} ≤ ∫ ω in {ε ≤ f* n}, f n` where `f* n ω = max_{k ≤ n}, f k ω`. In some literature, the Doob's maximal inequality refers to what we call Doob's Lp inequality (which is a corollary of this lemma and will be proved in an upcomming PR). -/ theorem maximal_ineq [IsFiniteMeasure μ] (hsub : Submartingale f 𝒢 μ) (hnonneg : 0 ≤ f) {ε : ℝ≥0} (n : ℕ) : ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω} ≤ ENNReal.ofReal (∫ ω in {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω}, f n ω ∂μ) := by suffices ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω} + ENNReal.ofReal (∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_succ fun k => f k ω) < ε}, f n ω ∂μ) ≤ ENNReal.ofReal (μ[f n]) by have hadd : ENNReal.ofReal (∫ ω, f n ω ∂μ) = ENNReal.ofReal (∫ ω in {ω | ↑ε ≤ (range (n+1)).sup' nonempty_range_succ fun k => f k ω}, f n ω ∂μ) + ENNReal.ofReal (∫ ω in {ω | ((range (n+1)).sup' nonempty_range_succ fun k => f k ω) < ↑ε}, f n ω ∂μ) := by rw [← ENNReal.ofReal_add, ← integral_union] · rw [← integral_univ] convert rfl ext ω change (ε : ℝ) ≤ _ ∨ _ < (ε : ℝ) ↔ _ simp only [le_or_lt, Set.mem_univ] · rw [disjoint_iff_inf_le] rintro ω ⟨hω₁, hω₂⟩ change (ε : ℝ) ≤ _ at hω₁ change _ < (ε : ℝ) at hω₂ exact (not_le.2 hω₂) hω₁ · exact measurableSet_lt (Finset.measurable_range_sup'' fun n _ => (hsub.stronglyMeasurable n).measurable.le (𝒢.le n)) measurable_const exacts [(hsub.integrable _).integrableOn, (hsub.integrable _).integrableOn, integral_nonneg (hnonneg _), integral_nonneg (hnonneg _)] rwa [hadd, ENNReal.add_le_add_iff_right ENNReal.ofReal_ne_top] at this calc ε • μ {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω} + ENNReal.ofReal (∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_succ fun k => f k ω) < ε}, f n ω ∂μ) ≤ ENNReal.ofReal (∫ ω in {ω | (ε : ℝ) ≤ (range (n + 1)).sup' nonempty_range_succ fun k => f k ω}, stoppedValue f (hitting f {y : ℝ | ↑ε ≤ y} 0 n) ω ∂μ) + ENNReal.ofReal (∫ ω in {ω | ((range (n + 1)).sup' nonempty_range_succ fun k => f k ω) < ε}, stoppedValue f (hitting f {y : ℝ | ↑ε ≤ y} 0 n) ω ∂μ) := by refine add_le_add (smul_le_stoppedValue_hitting hsub _) (ENNReal.ofReal_le_ofReal (setIntegral_mono_on (hsub.integrable n).integrableOn (Integrable.integrableOn (hsub.integrable_stoppedValue (hitting_isStoppingTime hsub.adapted measurableSet_Ici) hitting_le)) (measurableSet_lt (Finset.measurable_range_sup'' fun n _ => (hsub.stronglyMeasurable n).measurable.le (𝒢.le n)) measurable_const) ?_)) intro ω hω rw [Set.mem_setOf_eq] at hω have : hitting f {y : ℝ | ↑ε ≤ y} 0 n ω = n := by classical simp only [hitting, Set.mem_setOf_eq, exists_prop, Pi.natCast_def, Nat.cast_id, ite_eq_right_iff, forall_exists_index, and_imp] intro m hm hεm exact False.elim ((not_le.2 hω) ((le_sup'_iff _).2 ⟨m, mem_range.2 (Nat.lt_succ_of_le hm.2), hεm⟩)) simp_rw [stoppedValue, this, le_rfl] _ = ENNReal.ofReal (∫ ω, stoppedValue f (hitting f {y : ℝ | ↑ε ≤ y} 0 n) ω ∂μ) := by rw [← ENNReal.ofReal_add, ← integral_union] · rw [← integral_univ (μ := μ)] convert rfl ext ω change _ ↔ (ε : ℝ) ≤ _ ∨ _ < (ε : ℝ) simp only [le_or_lt, Set.mem_univ] · rw [disjoint_iff_inf_le] rintro ω ⟨hω₁, hω₂⟩ change (ε : ℝ) ≤ _ at hω₁ change _ < (ε : ℝ) at hω₂ exact (not_le.2 hω₂) hω₁ · exact measurableSet_lt (Finset.measurable_range_sup'' fun n _ => (hsub.stronglyMeasurable n).measurable.le (𝒢.le n)) measurable_const · exact Integrable.integrableOn (hsub.integrable_stoppedValue (hitting_isStoppingTime hsub.adapted measurableSet_Ici) hitting_le) · exact Integrable.integrableOn (hsub.integrable_stoppedValue (hitting_isStoppingTime hsub.adapted measurableSet_Ici) hitting_le) exacts [integral_nonneg fun x => hnonneg _ _, integral_nonneg fun x => hnonneg _ _] _ ≤ ENNReal.ofReal (μ[f n]) := by refine ENNReal.ofReal_le_ofReal ?_ rw [← stoppedValue_const f n] exact hsub.expected_stoppedValue_mono (hitting_isStoppingTime hsub.adapted measurableSet_Ici) (isStoppingTime_const _ _) (fun ω => hitting_le ω) (fun _ => le_refl n) end Maximal end MeasureTheory
Probability\Martingale\Upcrossing.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Order.Interval.Set.Monotone import Mathlib.Probability.Process.HittingTime import Mathlib.Probability.Martingale.Basic import Mathlib.Tactic.AdaptationNote /-! # Doob's upcrossing estimate Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting by $U_N(a, b)$ the number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing estimate (also known as Doob's inequality) states that $$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$ Doob's upcrossing estimate is an important inequality and is central in proving the martingale convergence theorems. ## Main definitions * `MeasureTheory.upperCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.lowerCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.upcrossingStrat a b f N`: is the predictable process which is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. Intuitively one might think of the `upcrossingStrat` as the strategy of buying 1 share whenever the process crosses below `a` for the first time after selling and selling 1 share whenever the process crosses above `b` for the first time after buying. * `MeasureTheory.upcrossingsBefore a b f N`: is the number of times `f` crosses from below `a` to above `b` before time `N`. * `MeasureTheory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above `b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`. ## Main results * `MeasureTheory.Adapted.isStoppingTime_upperCrossingTime`: `upperCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime`: `lowerCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part`: Doob's upcrossing estimate. * `MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality obtained by taking the supremum on both sides of Doob's upcrossing estimate. ### References We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021] -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} /-! ## Proof outline In this section, we will denote by $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to above $b$ before time $N$. To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses below $a$ and above $b$. Namely, we define $$ \sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N; $$ $$ \tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N. $$ These are `lowerCrossingTime` and `upperCrossingTime` in our formalization which are defined using `MeasureTheory.hitting` allowing us to specify a starting and ending time. Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$. Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that $0 \le f_0$ and $a \le f_N$. In particular, we will show $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N]. $$ This is `MeasureTheory.integral_mul_upcrossingsBefore_le_integral` in our formalization. To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$ (i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is a submartingale if $(f_n)$ is. Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that $(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$, $(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property, $0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying $$ \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0]. $$ Furthermore, \begin{align} (C \bullet f)_N & = \sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1} + \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\ & = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k}) \ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b) \end{align} where the inequality follows since for all $k < U_N(a, b)$, $f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$, $f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and $f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N], $$ as required. To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$. -/ /-- `lowerCrossingTimeAux a f c N` is the first time `f` reached below `a` after time `c` before time `N`. -/ noncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) : Ω → ι := hitting f (Set.Iic a) c N /-- `upperCrossingTime a b f N n` is the first time before time `N`, `f` reaches above `b` after `f` reached below `a` for the `n - 1`-th time. -/ noncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) : ℕ → Ω → ι | 0 => ⊥ | n + 1 => fun ω => hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω /-- `lowerCrossingTime a b f N n` is the first time before time `N`, `f` reaches below `a` after `f` reached above `b` for the `n`-th time. -/ noncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (n : ℕ) : Ω → ι := fun ω => hitting f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω section variable [Preorder ι] [OrderBot ι] [InfSet ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} @[simp] theorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ := rfl @[simp] theorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hitting f (Set.Iic a) ⊥ N := rfl theorem upperCrossingTime_succ : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω := by rw [upperCrossingTime] theorem upperCrossingTime_succ_eq (ω : Ω) : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω := by simp only [upperCrossingTime_succ] rfl end section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} theorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≤ N := by cases n · simp only [upperCrossingTime_zero, Pi.bot_apply, bot_le, Nat.zero_eq] · simp only [upperCrossingTime_succ, hitting_le] @[simp] theorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ := eq_bot_iff.2 upperCrossingTime_le theorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≤ N := by simp only [lowerCrossingTime, hitting_le ω] theorem upperCrossingTime_le_lowerCrossingTime : upperCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N n ω := by simp only [lowerCrossingTime, le_hitting upperCrossingTime_le ω] theorem lowerCrossingTime_le_upperCrossingTime_succ : lowerCrossingTime a b f N n ω ≤ upperCrossingTime a b f N (n + 1) ω := by rw [upperCrossingTime_succ] exact le_hitting lowerCrossingTime_le ω theorem lowerCrossingTime_mono (hnm : n ≤ m) : lowerCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N m ω := by suffices Monotone fun n => lowerCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans lowerCrossingTime_le_upperCrossingTime_succ upperCrossingTime_le_lowerCrossingTime theorem upperCrossingTime_mono (hnm : n ≤ m) : upperCrossingTime a b f N n ω ≤ upperCrossingTime a b f N m ω := by suffices Monotone fun n => upperCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans upperCrossingTime_le_lowerCrossingTime lowerCrossingTime_le_upperCrossingTime_succ end ConditionallyCompleteLinearOrderBot variable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω} theorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) : stoppedValue f (lowerCrossingTime a b f N n) ω ≤ a := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne lowerCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lowerCrossingTime_le⟩, hj₂⟩ theorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) : b ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne upperCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩ theorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b) (hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne upperCrossingTime_le_lowerCrossingTime fun h => not_le.2 hab <| le_trans ?_ (stoppedValue_lowerCrossingTime hn) simp only [stoppedValue] rw [← h] exact stoppedValue_upperCrossingTime (h.symm ▸ hn) theorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne lowerCrossingTime_le_upperCrossingTime_succ fun h => not_le.2 hab <| le_trans (stoppedValue_upperCrossingTime hn) ?_ simp only [stoppedValue] rw [← h] exact stoppedValue_lowerCrossingTime (h.symm ▸ hn) theorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_lt_upperCrossingTime hab hn) theorem lowerCrossingTime_stabilize (hnm : n ≤ m) (hn : lowerCrossingTime a b f N n ω = N) : lowerCrossingTime a b f N m ω = N := le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm)) theorem upperCrossingTime_stabilize (hnm : n ≤ m) (hn : upperCrossingTime a b f N n ω = N) : upperCrossingTime a b f N m ω = N := le_antisymm upperCrossingTime_le (le_trans (le_of_eq hn.symm) (upperCrossingTime_mono hnm)) theorem lowerCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ lowerCrossingTime a b f N n ω) : lowerCrossingTime a b f N m ω = N := lowerCrossingTime_stabilize hnm (le_antisymm lowerCrossingTime_le hn) theorem upperCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ upperCrossingTime a b f N n ω) : upperCrossingTime a b f N m ω = N := upperCrossingTime_stabilize hnm (le_antisymm upperCrossingTime_le hn) -- `upperCrossingTime_bound_eq` provides an explicit bound theorem exists_upperCrossingTime_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : ∃ n, upperCrossingTime a b f N n ω = N := by by_contra h; push_neg at h have : StrictMono fun n => upperCrossingTime a b f N n ω := strictMono_nat_of_lt_succ fun n => upperCrossingTime_lt_succ hab (h _) obtain ⟨_, ⟨k, rfl⟩, hk⟩ : ∃ (m : _) (_ : m ∈ Set.range fun n => upperCrossingTime a b f N n ω), N < m := ⟨upperCrossingTime a b f N (N + 1) ω, ⟨N + 1, rfl⟩, lt_of_lt_of_le N.lt_succ_self (StrictMono.id_le this (N + 1))⟩ exact not_le.2 hk upperCrossingTime_le theorem upperCrossingTime_lt_bddAbove (hab : a < b) : BddAbove {n | upperCrossingTime a b f N n ω < N} := by obtain ⟨k, hk⟩ := exists_upperCrossingTime_eq f N ω hab refine ⟨k, fun n (hn : upperCrossingTime a b f N n ω < N) => ?_⟩ by_contra hn' exact hn.ne (upperCrossingTime_stabilize (not_le.1 hn').le hk) theorem upperCrossingTime_lt_nonempty (hN : 0 < N) : {n | upperCrossingTime a b f N n ω < N}.Nonempty := ⟨0, hN⟩ theorem upperCrossingTime_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : upperCrossingTime a b f N N ω = N := by by_cases hN' : N < Nat.find (exists_upperCrossingTime_eq f N ω hab) · refine le_antisymm upperCrossingTime_le ?_ have hmono : StrictMonoOn (fun n => upperCrossingTime a b f N n ω) (Set.Iic (Nat.find (exists_upperCrossingTime_eq f N ω hab)).pred) := by refine strictMonoOn_Iic_of_lt_succ fun m hm => upperCrossingTime_lt_succ hab ?_ rw [Nat.lt_pred_iff] at hm convert Nat.find_min _ hm convert StrictMonoOn.Iic_id_le hmono N (Nat.le_sub_one_of_lt hN') · rw [not_lt] at hN' exact upperCrossingTime_stabilize hN' (Nat.find_spec (exists_upperCrossingTime_eq f N ω hab)) theorem upperCrossingTime_eq_of_bound_le (hab : a < b) (hn : N ≤ n) : upperCrossingTime a b f N n ω = N := le_antisymm upperCrossingTime_le (le_trans (upperCrossingTime_bound_eq f N ω hab).symm.le (upperCrossingTime_mono hn)) variable {ℱ : Filtration ℕ m0} theorem Adapted.isStoppingTime_crossing (hf : Adapted ℱ f) : IsStoppingTime ℱ (upperCrossingTime a b f N n) ∧ IsStoppingTime ℱ (lowerCrossingTime a b f N n) := by induction' n with k ih · refine ⟨isStoppingTime_const _ 0, ?_⟩ simp [hitting_isStoppingTime hf measurableSet_Iic] · obtain ⟨_, ih₂⟩ := ih have : IsStoppingTime ℱ (upperCrossingTime a b f N (k + 1)) := by intro n simp_rw [upperCrossingTime_succ_eq] exact isStoppingTime_hitting_isStoppingTime ih₂ (fun _ => lowerCrossingTime_le) measurableSet_Ici hf _ refine ⟨this, ?_⟩ intro n exact isStoppingTime_hitting_isStoppingTime this (fun _ => upperCrossingTime_le) measurableSet_Iic hf _ theorem Adapted.isStoppingTime_upperCrossingTime (hf : Adapted ℱ f) : IsStoppingTime ℱ (upperCrossingTime a b f N n) := hf.isStoppingTime_crossing.1 theorem Adapted.isStoppingTime_lowerCrossingTime (hf : Adapted ℱ f) : IsStoppingTime ℱ (lowerCrossingTime a b f N n) := hf.isStoppingTime_crossing.2 /-- `upcrossingStrat a b f N n` is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. `upcrossingStrat` is shifted by one index so that it is adapted rather than predictable. -/ noncomputable def upcrossingStrat (a b : ℝ) (f : ℕ → Ω → ℝ) (N n : ℕ) (ω : Ω) : ℝ := ∑ k ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator 1 n theorem upcrossingStrat_nonneg : 0 ≤ upcrossingStrat a b f N n ω := Finset.sum_nonneg fun _ _ => Set.indicator_nonneg (fun _ _ => zero_le_one) _ theorem upcrossingStrat_le_one : upcrossingStrat a b f N n ω ≤ 1 := by rw [upcrossingStrat, ← Finset.indicator_biUnion_apply] · exact Set.indicator_le_self' (fun _ _ => zero_le_one) _ intro i _ j _ hij simp only [Set.Ico_disjoint_Ico] obtain hij' | hij' := lt_or_gt_of_ne hij · rw [min_eq_left (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) : upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω), max_eq_right (lowerCrossingTime_mono hij'.le : lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)] refine le_trans upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_mono (Nat.succ_le_of_lt hij')) · rw [gt_iff_lt] at hij' rw [min_eq_right (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) : upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω), max_eq_left (lowerCrossingTime_mono hij'.le : lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)] refine le_trans upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_mono (Nat.succ_le_of_lt hij')) theorem Adapted.upcrossingStrat_adapted (hf : Adapted ℱ f) : Adapted ℱ (upcrossingStrat a b f N) := by intro n change StronglyMeasurable[ℱ n] fun ω => ∑ k ∈ Finset.range N, ({n | lowerCrossingTime a b f N k ω ≤ n} ∩ {n | n < upperCrossingTime a b f N (k + 1) ω}).indicator 1 n refine Finset.stronglyMeasurable_sum _ fun i _ => stronglyMeasurable_const.indicator ((hf.isStoppingTime_lowerCrossingTime n).inter ?_) simp_rw [← not_le] exact (hf.isStoppingTime_upperCrossingTime n).compl theorem Submartingale.sum_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ => ∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)) ℱ μ := hf.sum_mul_sub hf.adapted.upcrossingStrat_adapted (fun _ _ => upcrossingStrat_le_one) fun _ _ => upcrossingStrat_nonneg theorem Submartingale.sum_sub_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ => ∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)) ℱ μ := by refine hf.sum_mul_sub (fun n => (adapted_const ℱ 1 n).sub (hf.adapted.upcrossingStrat_adapted n)) (?_ : ∀ n ω, (1 - upcrossingStrat a b f N n) ω ≤ 1) ?_ · exact fun n ω => sub_le_self _ upcrossingStrat_nonneg · intro n ω simp [upcrossingStrat_le_one] theorem Submartingale.sum_mul_upcrossingStrat_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) : μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] ≤ μ[f n] - μ[f 0] := by have h₁ : (0 : ℝ) ≤ μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] := by have := (hf.sum_sub_upcrossingStrat_mul a b N).setIntegral_le (zero_le n) MeasurableSet.univ rw [integral_univ, integral_univ] at this refine le_trans ?_ this simp only [Finset.range_zero, Finset.sum_empty, integral_zero', le_refl] have h₂ : μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] = μ[∑ k ∈ Finset.range n, (f (k + 1) - f k)] - μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by simp only [sub_mul, one_mul, Finset.sum_sub_distrib, Pi.sub_apply, Finset.sum_apply, Pi.mul_apply] refine integral_sub (Integrable.sub (integrable_finset_sum _ fun i _ => hf.integrable _) (integrable_finset_sum _ fun i _ => hf.integrable _)) ?_ convert (hf.sum_upcrossingStrat_mul a b N).integrable n using 1 ext; simp rw [h₂, sub_nonneg] at h₁ refine le_trans h₁ ?_ simp_rw [Finset.sum_range_sub, integral_sub' (hf.integrable _) (hf.integrable _), le_refl] /-- The number of upcrossings (strictly) before time `N`. -/ noncomputable def upcrossingsBefore [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (ω : Ω) : ℕ := sSup {n | upperCrossingTime a b f N n ω < N} @[simp] theorem upcrossingsBefore_bot [Preorder ι] [OrderBot ι] [InfSet ι] {a b : ℝ} {f : ι → Ω → ℝ} {ω : Ω} : upcrossingsBefore a b f ⊥ ω = ⊥ := by simp [upcrossingsBefore] theorem upcrossingsBefore_zero : upcrossingsBefore a b f 0 ω = 0 := by simp [upcrossingsBefore] @[simp] theorem upcrossingsBefore_zero' : upcrossingsBefore a b f 0 = 0 := by ext ω; exact upcrossingsBefore_zero theorem upperCrossingTime_lt_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n ≤ upcrossingsBefore a b f N ω) : upperCrossingTime a b f N n ω < N := haveI : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N := (upperCrossingTime_lt_nonempty hN).csSup_mem ((OrderBot.bddBelow _).finite_of_bddAbove (upperCrossingTime_lt_bddAbove hab)) lt_of_le_of_lt (upperCrossingTime_mono hn) this theorem upperCrossingTime_eq_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) : upperCrossingTime a b f N n ω = N := by refine le_antisymm upperCrossingTime_le (not_lt.1 ?_) convert not_mem_of_csSup_lt hn (upperCrossingTime_lt_bddAbove hab) theorem upcrossingsBefore_le (f : ℕ → Ω → ℝ) (ω : Ω) (hab : a < b) : upcrossingsBefore a b f N ω ≤ N := by by_cases hN : N = 0 · subst hN rw [upcrossingsBefore_zero] · refine csSup_le ⟨0, zero_lt_iff.2 hN⟩ fun n (hn : _ < N) => ?_ by_contra hnN exact hn.ne (upperCrossingTime_eq_of_bound_le hab (not_le.1 hnN).le) theorem crossing_eq_crossing_of_lowerCrossingTime_lt {M : ℕ} (hNM : N ≤ M) (h : lowerCrossingTime a b f N n ω < N) : upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω ∧ lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by have h' : upperCrossingTime a b f N n ω < N := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime h induction' n with k ih · simp only [Nat.zero_eq, upperCrossingTime_zero, bot_eq_zero', eq_self_iff_true, lowerCrossingTime_zero, true_and_iff, eq_comm] refine hitting_eq_hitting_of_exists hNM ?_ rw [lowerCrossingTime, hitting_lt_iff] at h · obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl · specialize ih (lt_of_le_of_lt (lowerCrossingTime_mono (Nat.le_succ _)) h) (lt_of_le_of_lt (upperCrossingTime_mono (Nat.le_succ _)) h') have : upperCrossingTime a b f M k.succ ω = upperCrossingTime a b f N k.succ ω := by rw [upperCrossingTime_succ_eq, hitting_lt_iff] at h' · simp only [upperCrossingTime_succ_eq] obtain ⟨j, hj₁, hj₂⟩ := h' rw [eq_comm, ih.2] exact hitting_eq_hitting_of_exists hNM ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl refine ⟨this, ?_⟩ simp only [lowerCrossingTime, eq_comm, this, Nat.succ_eq_add_one] refine hitting_eq_hitting_of_exists hNM ?_ rw [lowerCrossingTime, hitting_lt_iff _ le_rfl] at h obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ theorem crossing_eq_crossing_of_upperCrossingTime_lt {M : ℕ} (hNM : N ≤ M) (h : upperCrossingTime a b f N (n + 1) ω < N) : upperCrossingTime a b f M (n + 1) ω = upperCrossingTime a b f N (n + 1) ω ∧ lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by have := (crossing_eq_crossing_of_lowerCrossingTime_lt hNM (lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ h)).2 refine ⟨?_, this⟩ rw [upperCrossingTime_succ_eq, upperCrossingTime_succ_eq, eq_comm, this] refine hitting_eq_hitting_of_exists hNM ?_ rw [upperCrossingTime_succ_eq, hitting_lt_iff] at h · obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl theorem upperCrossingTime_eq_upperCrossingTime_of_lt {M : ℕ} (hNM : N ≤ M) (h : upperCrossingTime a b f N n ω < N) : upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω := by cases n · simp · exact (crossing_eq_crossing_of_upperCrossingTime_lt hNM h).1 theorem upcrossingsBefore_mono (hab : a < b) : Monotone fun N ω => upcrossingsBefore a b f N ω := by intro N M hNM ω simp only [upcrossingsBefore] by_cases hemp : {n : ℕ | upperCrossingTime a b f N n ω < N}.Nonempty · refine csSup_le_csSup (upperCrossingTime_lt_bddAbove hab) hemp fun n hn => ?_ rw [Set.mem_setOf_eq, upperCrossingTime_eq_upperCrossingTime_of_lt hNM hn] exact lt_of_lt_of_le hn hNM · rw [Set.not_nonempty_iff_eq_empty] at hemp simp [hemp, csSup_empty, bot_eq_zero', zero_le'] theorem upcrossingsBefore_lt_of_exists_upcrossing (hab : a < b) {N₁ N₂ : ℕ} (hN₁ : N ≤ N₁) (hN₁' : f N₁ ω < a) (hN₂ : N₁ ≤ N₂) (hN₂' : b < f N₂ ω) : upcrossingsBefore a b f N ω < upcrossingsBefore a b f (N₂ + 1) ω := by refine lt_of_lt_of_le (Nat.lt_succ_self _) (le_csSup (upperCrossingTime_lt_bddAbove hab) ?_) rw [Set.mem_setOf_eq, upperCrossingTime_succ_eq, hitting_lt_iff _ le_rfl] refine ⟨N₂, ⟨?_, Nat.lt_succ_self _⟩, hN₂'.le⟩ rw [lowerCrossingTime, hitting_le_iff_of_lt _ (Nat.lt_succ_self _)] refine ⟨N₁, ⟨le_trans ?_ hN₁, hN₂⟩, hN₁'.le⟩ by_cases hN : 0 < N · have : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N := Nat.sSup_mem (upperCrossingTime_lt_nonempty hN) (upperCrossingTime_lt_bddAbove hab) rw [upperCrossingTime_eq_upperCrossingTime_of_lt (hN₁.trans (hN₂.trans <| Nat.le_succ _)) this] exact this.le · rw [not_lt, Nat.le_zero] at hN rw [hN, upcrossingsBefore_zero, upperCrossingTime_zero, Pi.bot_apply, bot_eq_zero'] theorem lowerCrossingTime_lt_of_lt_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n < upcrossingsBefore a b f N ω) : lowerCrossingTime a b f N n ω < N := lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn) theorem le_sub_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n < upcrossingsBefore a b f N ω) : b - a ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω - stoppedValue f (lowerCrossingTime a b f N n) ω := sub_le_sub (stoppedValue_upperCrossingTime (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn).ne) (stoppedValue_lowerCrossingTime (lowerCrossingTime_lt_of_lt_upcrossingsBefore hN hab hn).ne) theorem sub_eq_zero_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) : stoppedValue f (upperCrossingTime a b f N (n + 1)) ω - stoppedValue f (lowerCrossingTime a b f N n) ω = 0 := by have : N ≤ upperCrossingTime a b f N n ω := by rw [upcrossingsBefore] at hn rw [← not_lt] exact fun h => not_le.2 hn (le_csSup (upperCrossingTime_lt_bddAbove hab) h) simp [stoppedValue, upperCrossingTime_stabilize' (Nat.le_succ n) this, lowerCrossingTime_stabilize' le_rfl (le_trans this upperCrossingTime_le_lowerCrossingTime)] theorem mul_upcrossingsBefore_le (hf : a ≤ f N ω) (hab : a < b) : (b - a) * upcrossingsBefore a b f N ω ≤ ∑ k ∈ Finset.range N, upcrossingStrat a b f N k ω * (f (k + 1) - f k) ω := by classical by_cases hN : N = 0 · simp [hN] simp_rw [upcrossingStrat, Finset.sum_mul, ← Set.indicator_mul_left _ _ (fun x ↦ (f (x + 1) - f x) ω), Pi.one_apply, Pi.sub_apply, one_mul] rw [Finset.sum_comm] have h₁ : ∀ k, ∑ n ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator (fun m => f (m + 1) ω - f m ω) n = stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω := by intro k rw [Finset.sum_indicator_eq_sum_filter, (_ : Finset.filter (fun i => i ∈ Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)) (Finset.range N) = Finset.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)), Finset.sum_Ico_eq_add_neg _ lowerCrossingTime_le_upperCrossingTime_succ, Finset.sum_range_sub fun n => f n ω, Finset.sum_range_sub fun n => f n ω, neg_sub, sub_add_sub_cancel] · rfl · ext i simp only [Set.mem_Ico, Finset.mem_filter, Finset.mem_range, Finset.mem_Ico, and_iff_right_iff_imp, and_imp] exact fun _ h => lt_of_lt_of_le h upperCrossingTime_le simp_rw [h₁] have h₂ : ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤ ∑ k ∈ Finset.range N, (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by calc ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤ ∑ k ∈ Finset.range (upcrossingsBefore a b f N ω), (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by refine Finset.sum_le_sum fun i hi => le_sub_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab ?_ rwa [Finset.mem_range] at hi _ ≤ ∑ k ∈ Finset.range N, (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_subset.2 (upcrossingsBefore_le f ω hab)) fun i _ hi => ?_ by_cases hi' : i = upcrossingsBefore a b f N ω · subst hi' simp only [stoppedValue] rw [upperCrossingTime_eq_of_upcrossingsBefore_lt hab (Nat.lt_succ_self _)] by_cases heq : lowerCrossingTime a b f N (upcrossingsBefore a b f N ω) ω = N · rw [heq, sub_self] · rw [sub_nonneg] exact le_trans (stoppedValue_lowerCrossingTime heq) hf · rw [sub_eq_zero_of_upcrossingsBefore_lt hab] rw [Finset.mem_range, not_lt] at hi exact lt_of_le_of_ne hi (Ne.symm hi') refine le_trans ?_ h₂ rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_comm] theorem integral_mul_upcrossingsBefore_le_integral [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hfN : ∀ ω, a ≤ f N ω) (hfzero : 0 ≤ f 0) (hab : a < b) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[f N] := calc (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[∑ k ∈ Finset.range N, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by rw [← integral_mul_left] refine integral_mono_of_nonneg ?_ ((hf.sum_upcrossingStrat_mul a b N).integrable N) ?_ · exact eventually_of_forall fun ω => mul_nonneg (sub_nonneg.2 hab.le) (Nat.cast_nonneg _) · filter_upwards with ω simpa using mul_upcrossingsBefore_le (hfN ω) hab _ ≤ μ[f N] - μ[f 0] := hf.sum_mul_upcrossingStrat_le _ ≤ μ[f N] := (sub_le_self_iff _).2 (integral_nonneg hfzero) theorem crossing_pos_eq (hab : a < b) : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = upperCrossingTime a b f N n ∧ lowerCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = lowerCrossingTime a b f N n := by have hab' : 0 < b - a := sub_pos.2 hab have hf : ∀ ω i, b - a ≤ (f i ω - a)⁺ ↔ b ≤ f i ω := by intro i ω refine ⟨fun h => ?_, fun h => ?_⟩ · rwa [← sub_le_sub_iff_right a, ← posPart_eq_of_posPart_pos (lt_of_lt_of_le hab' h)] · rw [← sub_le_sub_iff_right a] at h rwa [posPart_eq_self.2 (le_trans hab'.le h)] have hf' (ω i) : (f i ω - a)⁺ ≤ 0 ↔ f i ω ≤ a := by rw [posPart_nonpos, sub_nonpos] induction' n with k ih · refine ⟨rfl, ?_⟩ #adaptation_note /-- nightly-2024-03-16: simp was simp (config := { unfoldPartialApp := true }) only [lowerCrossingTime_zero, hitting, Set.mem_Icc, Set.mem_Iic, Nat.zero_eq] -/ simp (config := { unfoldPartialApp := true }) only [lowerCrossingTime_zero, hitting_def, Set.mem_Icc, Set.mem_Iic, Nat.zero_eq] ext ω split_ifs with h₁ h₂ h₂ · simp_rw [hf'] · simp_rw [Set.mem_Iic, ← hf' _ _] at h₂ exact False.elim (h₂ h₁) · simp_rw [Set.mem_Iic, hf' _ _] at h₁ exact False.elim (h₁ h₂) · rfl · have : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N (k + 1) = upperCrossingTime a b f N (k + 1) := by ext ω simp only [upperCrossingTime_succ_eq, ← ih.2, hitting, Set.mem_Ici, tsub_le_iff_right] split_ifs with h₁ h₂ h₂ · simp_rw [← sub_le_iff_le_add, hf ω] · refine False.elim (h₂ ?_) simp_all only [Set.mem_Ici, not_true_eq_false] · refine False.elim (h₁ ?_) simp_all only [Set.mem_Ici] · rfl refine ⟨this, ?_⟩ ext ω simp only [lowerCrossingTime, this, hitting, Set.mem_Iic] split_ifs with h₁ h₂ h₂ · simp_rw [hf' ω] · refine False.elim (h₂ ?_) simp_all only [Set.mem_Iic, not_true_eq_false] · refine False.elim (h₁ ?_) simp_all only [Set.mem_Iic] · rfl theorem upcrossingsBefore_pos_eq (hab : a < b) : upcrossingsBefore 0 (b - a) (fun n ω => (f n ω - a)⁺) N ω = upcrossingsBefore a b f N ω := by simp_rw [upcrossingsBefore, (crossing_pos_eq hab).1] theorem mul_integral_upcrossingsBefore_le_integral_pos_part_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hab : a < b) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by refine le_trans (le_of_eq ?_) (integral_mul_upcrossingsBefore_le_integral (hf.sub_martingale (martingale_const _ _ _)).pos (fun ω => posPart_nonneg _) (fun ω => posPart_nonneg _) (sub_pos.2 hab)) simp_rw [sub_zero, ← upcrossingsBefore_pos_eq hab] rfl /-- **Doob's upcrossing estimate**: given a real valued discrete submartingale `f` and real values `a` and `b`, we have `(b - a) * 𝔼[upcrossingsBefore a b f N] ≤ 𝔼[(f N - a)⁺]` where `upcrossingsBefore a b f N` is the number of times the process `f` crossed from below `a` to above `b` before the time `N`. -/ theorem Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part [IsFiniteMeasure μ] (a b : ℝ) (hf : Submartingale f ℱ μ) (N : ℕ) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by by_cases hab : a < b · exact mul_integral_upcrossingsBefore_le_integral_pos_part_aux hf hab · rw [not_lt, ← sub_nonpos] at hab exact le_trans (mul_nonpos_of_nonpos_of_nonneg hab (by positivity)) (integral_nonneg fun ω => posPart_nonneg _) /-! ### Variant of the upcrossing estimate Now, we would like to prove a variant of the upcrossing estimate obtained by taking the supremum over $N$ of the original upcrossing estimate. Namely, we want the inequality $$ (b - a) \sup_N \mathbb{E}[U_N(a, b)] \le \sup_N \mathbb{E}[f_N]. $$ This inequality is central for the martingale convergence theorem as it provides a uniform bound for the upcrossings. We note that on top of taking the supremum on both sides of the inequality, we had also used the monotone convergence theorem on the left hand side to take the supremum outside of the integral. To do this, we need to make sure $U_N(a, b)$ is measurable and integrable. Integrability is easy to check as $U_N(a, b) ≤ N$ and so it suffices to show measurability. Indeed, by noting that $$ U_N(a, b) = \sum_{i = 1}^N \mathbf{1}_{\{U_N(a, b) < N\}} $$ $U_N(a, b)$ is measurable as $\{U_N(a, b) < N\}$ is a measurable set since $U_N(a, b)$ is a stopping time. -/ theorem upcrossingsBefore_eq_sum (hab : a < b) : upcrossingsBefore a b f N ω = ∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by by_cases hN : N = 0 · simp [hN] rw [← Finset.sum_Ico_consecutive _ (Nat.succ_le_succ zero_le') (Nat.succ_le_succ (upcrossingsBefore_le f ω hab))] have h₁ : ∀ k ∈ Finset.Ico 1 (upcrossingsBefore a b f N ω + 1), {n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 1 := by rintro k hk rw [Finset.mem_Ico] at hk rw [Set.indicator_of_mem] · rfl · exact upperCrossingTime_lt_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab (Nat.lt_succ_iff.1 hk.2) have h₂ : ∀ k ∈ Finset.Ico (upcrossingsBefore a b f N ω + 1) (N + 1), {n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 0 := by rintro k hk rw [Finset.mem_Ico, Nat.succ_le_iff] at hk rw [Set.indicator_of_not_mem] simp only [Set.mem_setOf_eq, not_lt] exact (upperCrossingTime_eq_of_upcrossingsBefore_lt hab hk.1).symm.le rw [Finset.sum_congr rfl h₁, Finset.sum_congr rfl h₂, Finset.sum_const, Finset.sum_const, smul_eq_mul, mul_one, smul_eq_mul, mul_zero, Nat.card_Ico, Nat.add_succ_sub_one, add_zero, add_zero] theorem Adapted.measurable_upcrossingsBefore (hf : Adapted ℱ f) (hab : a < b) : Measurable (upcrossingsBefore a b f N) := by have : upcrossingsBefore a b f N = fun ω => ∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by ext ω exact upcrossingsBefore_eq_sum hab rw [this] exact Finset.measurable_sum _ fun i _ => Measurable.indicator measurable_const <| ℱ.le N _ (hf.isStoppingTime_upperCrossingTime.measurableSet_lt_of_pred N) theorem Adapted.integrable_upcrossingsBefore [IsFiniteMeasure μ] (hf : Adapted ℱ f) (hab : a < b) : Integrable (fun ω => (upcrossingsBefore a b f N ω : ℝ)) μ := haveI : ∀ᵐ ω ∂μ, ‖(upcrossingsBefore a b f N ω : ℝ)‖ ≤ N := by filter_upwards with ω rw [Real.norm_eq_abs, Nat.abs_cast, Nat.cast_le] exact upcrossingsBefore_le _ _ hab ⟨Measurable.aestronglyMeasurable (measurable_from_top.comp (hf.measurable_upcrossingsBefore hab)), hasFiniteIntegral_of_bounded this⟩ /-- The number of upcrossings of a realization of a stochastic process (`upcrossings` takes value in `ℝ≥0∞` and so is allowed to be `∞`). -/ noncomputable def upcrossings [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (ω : Ω) : ℝ≥0∞ := ⨆ N, (upcrossingsBefore a b f N ω : ℝ≥0∞) theorem Adapted.measurable_upcrossings (hf : Adapted ℱ f) (hab : a < b) : Measurable (upcrossings a b f) := measurable_iSup fun _ => measurable_from_top.comp (hf.measurable_upcrossingsBefore hab) theorem upcrossings_lt_top_iff : upcrossings a b f ω < ∞ ↔ ∃ k, ∀ N, upcrossingsBefore a b f N ω ≤ k := by have : upcrossings a b f ω < ∞ ↔ ∃ k : ℝ≥0, upcrossings a b f ω ≤ k := by constructor · intro h lift upcrossings a b f ω to ℝ≥0 using h.ne with r hr exact ⟨r, le_rfl⟩ · rintro ⟨k, hk⟩ exact lt_of_le_of_lt hk ENNReal.coe_lt_top simp_rw [this, upcrossings, iSup_le_iff] constructor <;> rintro ⟨k, hk⟩ · obtain ⟨m, hm⟩ := exists_nat_ge k refine ⟨m, fun N => Nat.cast_le.1 ((hk N).trans ?_)⟩ rwa [← ENNReal.coe_natCast, ENNReal.coe_le_coe] · refine ⟨k, fun N => ?_⟩ simp only [ENNReal.coe_natCast, Nat.cast_le, hk N] /-- A variant of Doob's upcrossing estimate obtained by taking the supremum on both sides. -/ theorem Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part [IsFiniteMeasure μ] (a b : ℝ) (hf : Submartingale f ℱ μ) : ENNReal.ofReal (b - a) * ∫⁻ ω, upcrossings a b f ω ∂μ ≤ ⨆ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ := by by_cases hab : a < b · simp_rw [upcrossings] have : ∀ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ = ENNReal.ofReal (∫ ω, (f N ω - a)⁺ ∂μ) := by intro N rw [ofReal_integral_eq_lintegral_ofReal] · exact (hf.sub_martingale (martingale_const _ _ _)).pos.integrable _ · exact eventually_of_forall fun ω => posPart_nonneg _ rw [lintegral_iSup'] · simp_rw [this, ENNReal.mul_iSup, iSup_le_iff] intro N rw [(by simp : ∫⁻ ω, upcrossingsBefore a b f N ω ∂μ = ∫⁻ ω, ↑(upcrossingsBefore a b f N ω : ℝ≥0) ∂μ), lintegral_coe_eq_integral, ← ENNReal.ofReal_mul (sub_pos.2 hab).le] · simp_rw [NNReal.coe_natCast] exact (ENNReal.ofReal_le_ofReal (hf.mul_integral_upcrossingsBefore_le_integral_pos_part a b N)).trans (le_iSup (α := ℝ≥0∞) _ N) · simp only [NNReal.coe_natCast, hf.adapted.integrable_upcrossingsBefore hab] · exact fun n => measurable_from_top.comp_aemeasurable (hf.adapted.measurable_upcrossingsBefore hab).aemeasurable · filter_upwards with ω N M hNM rw [Nat.cast_le] exact upcrossingsBefore_mono hab hNM ω · rw [not_lt, ← sub_nonpos] at hab rw [ENNReal.ofReal_of_nonpos hab, zero_mul] exact zero_le _ end MeasureTheory
Probability\ProbabilityMassFunction\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, Devon Tuma -/ import Mathlib.Topology.Instances.ENNReal import Mathlib.MeasureTheory.Measure.Dirac /-! # Probability mass functions This file is about probability mass functions or discrete probability measures: a function `α → ℝ≥0∞` such that the values have (infinite) sum `1`. Construction of monadic `pure` and `bind` is found in `ProbabilityMassFunction/Monad.lean`, other constructions of `PMF`s are found in `ProbabilityMassFunction/Constructions.lean`. Given `p : PMF α`, `PMF.toOuterMeasure` constructs an `OuterMeasure` on `α`, by assigning each set the sum of the probabilities of each of its elements. Under this outer measure, every set is Carathéodory-measurable, so we can further extend this to a `Measure` on `α`, see `PMF.toMeasure`. `PMF.toMeasure.isProbabilityMeasure` shows this associated measure is a probability measure. Conversely, given a probability measure `μ` on a measurable space `α` with all singleton sets measurable, `μ.toPMF` constructs a `PMF` on `α`, setting the probability mass of a point `x` to be the measure of the singleton set `{x}`. ## Tags probability mass function, discrete probability measure -/ noncomputable section variable {α β γ : Type*} open scoped Classical open NNReal ENNReal MeasureTheory /-- A probability mass function, or discrete probability measures is a function `α → ℝ≥0∞` such that the values have (infinite) sum `1`. -/ def PMF.{u} (α : Type u) : Type u := { f : α → ℝ≥0∞ // HasSum f 1 } namespace PMF instance instFunLike : FunLike (PMF α) α ℝ≥0∞ where coe p a := p.1 a coe_injective' _ _ h := Subtype.eq h @[ext] protected theorem ext {p q : PMF α} (h : ∀ x, p x = q x) : p = q := DFunLike.ext p q h theorem hasSum_coe_one (p : PMF α) : HasSum p 1 := p.2 @[simp] theorem tsum_coe (p : PMF α) : ∑' a, p a = 1 := p.hasSum_coe_one.tsum_eq theorem tsum_coe_ne_top (p : PMF α) : ∑' a, p a ≠ ∞ := p.tsum_coe.symm ▸ ENNReal.one_ne_top theorem tsum_coe_indicator_ne_top (p : PMF α) (s : Set α) : ∑' a, s.indicator p a ≠ ∞ := ne_of_lt (lt_of_le_of_lt (tsum_le_tsum (fun _ => Set.indicator_apply_le fun _ => le_rfl) ENNReal.summable ENNReal.summable) (lt_of_le_of_ne le_top p.tsum_coe_ne_top)) @[simp] theorem coe_ne_zero (p : PMF α) : ⇑p ≠ 0 := fun hp => zero_ne_one ((tsum_zero.symm.trans (tsum_congr fun x => symm (congr_fun hp x))).trans p.tsum_coe) /-- The support of a `PMF` is the set where it is nonzero. -/ def support (p : PMF α) : Set α := Function.support p @[simp] theorem mem_support_iff (p : PMF α) (a : α) : a ∈ p.support ↔ p a ≠ 0 := Iff.rfl @[simp] theorem support_nonempty (p : PMF α) : p.support.Nonempty := Function.support_nonempty_iff.2 p.coe_ne_zero @[simp] theorem support_countable (p : PMF α) : p.support.Countable := Summable.countable_support_ennreal (tsum_coe_ne_top p) theorem apply_eq_zero_iff (p : PMF α) (a : α) : p a = 0 ↔ a ∉ p.support := by rw [mem_support_iff, Classical.not_not] theorem apply_pos_iff (p : PMF α) (a : α) : 0 < p a ↔ a ∈ p.support := pos_iff_ne_zero.trans (p.mem_support_iff a).symm theorem apply_eq_one_iff (p : PMF α) (a : α) : p a = 1 ↔ p.support = {a} := by refine ⟨fun h => Set.Subset.antisymm (fun a' ha' => by_contra fun ha => ?_) fun a' ha' => ha'.symm ▸ (p.mem_support_iff a).2 fun ha => zero_ne_one <| ha.symm.trans h, fun h => _root_.trans (symm <| tsum_eq_single a fun a' ha' => (p.apply_eq_zero_iff a').2 (h.symm ▸ ha')) p.tsum_coe⟩ suffices 1 < ∑' a, p a from ne_of_lt this p.tsum_coe.symm have : 0 < ∑' b, ite (b = a) 0 (p b) := lt_of_le_of_ne' zero_le' ((tsum_ne_zero_iff ENNReal.summable).2 ⟨a', ite_ne_left_iff.2 ⟨ha, Ne.symm <| (p.mem_support_iff a').2 ha'⟩⟩) calc 1 = 1 + 0 := (add_zero 1).symm _ < p a + ∑' b, ite (b = a) 0 (p b) := (ENNReal.add_lt_add_of_le_of_lt ENNReal.one_ne_top (le_of_eq h.symm) this) _ = ite (a = a) (p a) 0 + ∑' b, ite (b = a) 0 (p b) := by rw [eq_self_iff_true, if_true] _ = (∑' b, ite (b = a) (p b) 0) + ∑' b, ite (b = a) 0 (p b) := by congr exact symm (tsum_eq_single a fun b hb => if_neg hb) _ = ∑' b, (ite (b = a) (p b) 0 + ite (b = a) 0 (p b)) := ENNReal.tsum_add.symm _ = ∑' b, p b := tsum_congr fun b => by split_ifs <;> simp only [zero_add, add_zero, le_rfl] theorem coe_le_one (p : PMF α) (a : α) : p a ≤ 1 := by refine hasSum_le (fun b => ?_) (hasSum_ite_eq a (p a)) (hasSum_coe_one p) split_ifs with h <;> simp only [h, zero_le', le_rfl] theorem apply_ne_top (p : PMF α) (a : α) : p a ≠ ∞ := ne_of_lt (lt_of_le_of_lt (p.coe_le_one a) ENNReal.one_lt_top) theorem apply_lt_top (p : PMF α) (a : α) : p a < ∞ := lt_of_le_of_ne le_top (p.apply_ne_top a) section OuterMeasure open MeasureTheory MeasureTheory.OuterMeasure /-- Construct an `OuterMeasure` from a `PMF`, by assigning measure to each set `s : Set α` equal to the sum of `p x` for each `x ∈ α`. -/ def toOuterMeasure (p : PMF α) : OuterMeasure α := OuterMeasure.sum fun x : α => p x • dirac x variable (p : PMF α) (s t : Set α) theorem toOuterMeasure_apply : p.toOuterMeasure s = ∑' x, s.indicator p x := tsum_congr fun x => smul_dirac_apply (p x) x s @[simp] theorem toOuterMeasure_caratheodory : p.toOuterMeasure.caratheodory = ⊤ := by refine eq_top_iff.2 <| le_trans (le_sInf fun x hx => ?_) (le_sum_caratheodory _) have ⟨y, hy⟩ := hx exact ((le_of_eq (dirac_caratheodory y).symm).trans (le_smul_caratheodory _ _)).trans (le_of_eq hy) @[simp] theorem toOuterMeasure_apply_finset (s : Finset α) : p.toOuterMeasure s = ∑ x ∈ s, p x := by refine (toOuterMeasure_apply p s).trans ((tsum_eq_sum (s := s) ?_).trans ?_) · exact fun x hx => Set.indicator_of_not_mem (Finset.mem_coe.not.2 hx) _ · exact Finset.sum_congr rfl fun x hx => Set.indicator_of_mem (Finset.mem_coe.2 hx) _ theorem toOuterMeasure_apply_singleton (a : α) : p.toOuterMeasure {a} = p a := by refine (p.toOuterMeasure_apply {a}).trans ((tsum_eq_single a fun b hb => ?_).trans ?_) · exact ite_eq_right_iff.2 fun hb' => False.elim <| hb hb' · exact ite_eq_left_iff.2 fun ha' => False.elim <| ha' rfl theorem toOuterMeasure_injective : (toOuterMeasure : PMF α → OuterMeasure α).Injective := fun p q h => PMF.ext fun x => (p.toOuterMeasure_apply_singleton x).symm.trans ((congr_fun (congr_arg _ h) _).trans <| q.toOuterMeasure_apply_singleton x) @[simp] theorem toOuterMeasure_inj {p q : PMF α} : p.toOuterMeasure = q.toOuterMeasure ↔ p = q := toOuterMeasure_injective.eq_iff theorem toOuterMeasure_apply_eq_zero_iff : p.toOuterMeasure s = 0 ↔ Disjoint p.support s := by rw [toOuterMeasure_apply, ENNReal.tsum_eq_zero] exact Function.funext_iff.symm.trans Set.indicator_eq_zero' theorem toOuterMeasure_apply_eq_one_iff : p.toOuterMeasure s = 1 ↔ p.support ⊆ s := by refine (p.toOuterMeasure_apply s).symm ▸ ⟨fun h a hap => ?_, fun h => ?_⟩ · refine by_contra fun hs => ne_of_lt ?_ (h.trans p.tsum_coe.symm) have hs' : s.indicator p a = 0 := Set.indicator_apply_eq_zero.2 fun hs' => False.elim <| hs hs' have hsa : s.indicator p a < p a := hs'.symm ▸ (p.apply_pos_iff a).2 hap exact ENNReal.tsum_lt_tsum (p.tsum_coe_indicator_ne_top s) (fun x => Set.indicator_apply_le fun _ => le_rfl) hsa · suffices ∀ (x) (_ : x ∉ s), p x = 0 from _root_.trans (tsum_congr fun a => (Set.indicator_apply s p a).trans (ite_eq_left_iff.2 <| symm ∘ this a)) p.tsum_coe exact fun a ha => (p.apply_eq_zero_iff a).2 <| Set.not_mem_subset h ha @[simp] theorem toOuterMeasure_apply_inter_support : p.toOuterMeasure (s ∩ p.support) = p.toOuterMeasure s := by simp only [toOuterMeasure_apply, PMF.support, Set.indicator_inter_support] /-- Slightly stronger than `OuterMeasure.mono` having an intersection with `p.support`. -/ theorem toOuterMeasure_mono {s t : Set α} (h : s ∩ p.support ⊆ t) : p.toOuterMeasure s ≤ p.toOuterMeasure t := le_trans (le_of_eq (toOuterMeasure_apply_inter_support p s).symm) (p.toOuterMeasure.mono h) theorem toOuterMeasure_apply_eq_of_inter_support_eq {s t : Set α} (h : s ∩ p.support = t ∩ p.support) : p.toOuterMeasure s = p.toOuterMeasure t := le_antisymm (p.toOuterMeasure_mono (h.symm ▸ Set.inter_subset_left)) (p.toOuterMeasure_mono (h ▸ Set.inter_subset_left)) @[simp] theorem toOuterMeasure_apply_fintype [Fintype α] : p.toOuterMeasure s = ∑ x, s.indicator p x := (p.toOuterMeasure_apply s).trans (tsum_eq_sum fun x h => absurd (Finset.mem_univ x) h) end OuterMeasure section Measure open MeasureTheory /-- Since every set is Carathéodory-measurable under `PMF.toOuterMeasure`, we can further extend this `OuterMeasure` to a `Measure` on `α`. -/ def toMeasure [MeasurableSpace α] (p : PMF α) : Measure α := p.toOuterMeasure.toMeasure ((toOuterMeasure_caratheodory p).symm ▸ le_top) variable [MeasurableSpace α] (p : PMF α) (s t : Set α) theorem toOuterMeasure_apply_le_toMeasure_apply : p.toOuterMeasure s ≤ p.toMeasure s := le_toMeasure_apply p.toOuterMeasure _ s theorem toMeasure_apply_eq_toOuterMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = p.toOuterMeasure s := toMeasure_apply p.toOuterMeasure _ hs theorem toMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = ∑' x, s.indicator p x := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs).trans (p.toOuterMeasure_apply s) theorem toMeasure_apply_singleton (a : α) (h : MeasurableSet ({a} : Set α)) : p.toMeasure {a} = p a := by simp [toMeasure_apply_eq_toOuterMeasure_apply _ _ h, toOuterMeasure_apply_singleton] theorem toMeasure_apply_eq_zero_iff (hs : MeasurableSet s) : p.toMeasure s = 0 ↔ Disjoint p.support s := by rw [toMeasure_apply_eq_toOuterMeasure_apply p s hs, toOuterMeasure_apply_eq_zero_iff] theorem toMeasure_apply_eq_one_iff (hs : MeasurableSet s) : p.toMeasure s = 1 ↔ p.support ⊆ s := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs).symm ▸ p.toOuterMeasure_apply_eq_one_iff s @[simp] theorem toMeasure_apply_inter_support (hs : MeasurableSet s) (hp : MeasurableSet p.support) : p.toMeasure (s ∩ p.support) = p.toMeasure s := by simp [p.toMeasure_apply_eq_toOuterMeasure_apply s hs, p.toMeasure_apply_eq_toOuterMeasure_apply _ (hs.inter hp)] @[simp] theorem restrict_toMeasure_support [MeasurableSingletonClass α] (p : PMF α) : Measure.restrict (toMeasure p) (support p) = toMeasure p := by ext s hs apply (MeasureTheory.Measure.restrict_apply hs).trans apply toMeasure_apply_inter_support p s hs p.support_countable.measurableSet theorem toMeasure_mono {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : s ∩ p.support ⊆ t) : p.toMeasure s ≤ p.toMeasure t := by simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using toOuterMeasure_mono p h theorem toMeasure_apply_eq_of_inter_support_eq {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : s ∩ p.support = t ∩ p.support) : p.toMeasure s = p.toMeasure t := by simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using toOuterMeasure_apply_eq_of_inter_support_eq p h section MeasurableSingletonClass variable [MeasurableSingletonClass α] theorem toMeasure_injective : (toMeasure : PMF α → Measure α).Injective := by intro p q h ext x rw [← p.toMeasure_apply_singleton x <| measurableSet_singleton x, ← q.toMeasure_apply_singleton x <| measurableSet_singleton x, h] @[simp] theorem toMeasure_inj {p q : PMF α} : p.toMeasure = q.toMeasure ↔ p = q := toMeasure_injective.eq_iff @[simp] theorem toMeasure_apply_finset (s : Finset α) : p.toMeasure s = ∑ x ∈ s, p x := (p.toMeasure_apply_eq_toOuterMeasure_apply s s.measurableSet).trans (p.toOuterMeasure_apply_finset s) theorem toMeasure_apply_of_finite (hs : s.Finite) : p.toMeasure s = ∑' x, s.indicator p x := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs.measurableSet).trans (p.toOuterMeasure_apply s) @[simp] theorem toMeasure_apply_fintype [Fintype α] : p.toMeasure s = ∑ x, s.indicator p x := (p.toMeasure_apply_eq_toOuterMeasure_apply s s.toFinite.measurableSet).trans (p.toOuterMeasure_apply_fintype s) end MeasurableSingletonClass end Measure end PMF namespace MeasureTheory open PMF namespace Measure /-- Given that `α` is a countable, measurable space with all singleton sets measurable, we can convert any probability measure into a `PMF`, where the mass of a point is the measure of the singleton set under the original measure. -/ def toPMF [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] (μ : Measure α) [h : IsProbabilityMeasure μ] : PMF α := ⟨fun x => μ ({x} : Set α), ENNReal.summable.hasSum_iff.2 (_root_.trans (symm <| (tsum_indicator_apply_singleton μ Set.univ MeasurableSet.univ).symm.trans (tsum_congr fun x => congr_fun (Set.indicator_univ _) x)) h.measure_univ)⟩ variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] (μ : Measure α) [IsProbabilityMeasure μ] theorem toPMF_apply (x : α) : μ.toPMF x = μ {x} := rfl @[simp] theorem toPMF_toMeasure : μ.toPMF.toMeasure = μ := Measure.ext fun s hs => by rw [μ.toPMF.toMeasure_apply s hs, ← μ.tsum_indicator_apply_singleton s hs] rfl end Measure end MeasureTheory namespace PMF open MeasureTheory /-- The measure associated to a `PMF` by `toMeasure` is a probability measure. -/ instance toMeasure.isProbabilityMeasure [MeasurableSpace α] (p : PMF α) : IsProbabilityMeasure p.toMeasure := ⟨by simpa only [MeasurableSet.univ, toMeasure_apply_eq_toOuterMeasure_apply, Set.indicator_univ, toOuterMeasure_apply, ENNReal.coe_eq_one] using tsum_coe p⟩ variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] (p : PMF α) (μ : Measure α) [IsProbabilityMeasure μ] @[simp] theorem toMeasure_toPMF : p.toMeasure.toPMF = p := PMF.ext fun x => by rw [← p.toMeasure_apply_singleton x (measurableSet_singleton x), p.toMeasure.toPMF_apply] theorem toMeasure_eq_iff_eq_toPMF (μ : Measure α) [IsProbabilityMeasure μ] : p.toMeasure = μ ↔ p = μ.toPMF := by rw [← toMeasure_inj, Measure.toPMF_toMeasure] theorem toPMF_eq_iff_toMeasure_eq (μ : Measure α) [IsProbabilityMeasure μ] : μ.toPMF = p ↔ μ = p.toMeasure := by rw [← toMeasure_inj, Measure.toPMF_toMeasure] end PMF
Probability\ProbabilityMassFunction\Binomial.lean
/- Copyright (c) 2023 Joachim Breitner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joachim Breitner -/ import Mathlib.Probability.ProbabilityMassFunction.Constructions import Mathlib.Tactic.FinCases /-! # The binomial distribution This file defines the probability mass function of the binomial distribution. ## Main results * `binomial_one_eq_bernoulli`: For `n = 1`, it is equal to `PMF.bernoulli`. -/ namespace PMF open ENNReal /-- The binomial `PMF`: the probability of observing exactly `i` “heads” in a sequence of `n` independent coin tosses, each having probability `p` of coming up “heads”. -/ noncomputable def binomial (p : ℝ≥0∞) (h : p ≤ 1) (n : ℕ) : PMF (Fin (n + 1)) := .ofFintype (fun i => p^(i : ℕ) * (1-p)^((Fin.last n - i) : ℕ) * (n.choose i : ℕ)) (by convert (add_pow p (1-p) n).symm · rw [Finset.sum_fin_eq_sum_range] apply Finset.sum_congr rfl intro i hi rw [Finset.mem_range] at hi rw [dif_pos hi, Fin.last] · simp [h]) theorem binomial_apply (p : ℝ≥0∞) (h : p ≤ 1) (n : ℕ) (i : Fin (n + 1)) : binomial p h n i = p^(i : ℕ) * (1-p)^((Fin.last n - i) : ℕ) * (n.choose i : ℕ) := rfl @[simp] theorem binomial_apply_zero (p : ℝ≥0∞) (h : p ≤ 1) (n : ℕ) : binomial p h n 0 = (1-p)^n := by simp [binomial_apply] @[simp] theorem binomial_apply_last (p : ℝ≥0∞) (h : p ≤ 1) (n : ℕ) : binomial p h n (.last n) = p^n := by simp [binomial_apply] theorem binomial_apply_self (p : ℝ≥0∞) (h : p ≤ 1) (n : ℕ) : binomial p h n n = p^n := by simp /-- The binomial distribution on one coin is the bernoully distribution. -/ theorem binomial_one_eq_bernoulli (p : ℝ≥0∞) (h : p ≤ 1) : binomial p h 1 = (bernoulli p h).map (cond · 1 0) := by ext i; fin_cases i <;> simp [tsum_bool, binomial_apply] end PMF
Probability\ProbabilityMassFunction\Constructions.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, Devon Tuma -/ import Mathlib.Probability.ProbabilityMassFunction.Monad /-! # Specific Constructions of Probability Mass Functions This file gives a number of different `PMF` constructions for common probability distributions. `map` and `seq` allow pushing a `PMF α` along a function `f : α → β` (or distribution of functions `f : PMF (α → β)`) to get a `PMF β`. `ofFinset` and `ofFintype` simplify the construction of a `PMF α` from a function `f : α → ℝ≥0∞`, by allowing the "sum equals 1" constraint to be in terms of `Finset.sum` instead of `tsum`. `normalize` constructs a `PMF α` by normalizing a function `f : α → ℝ≥0∞` by its sum, and `filter` uses this to filter the support of a `PMF` and re-normalize the new distribution. `bernoulli` represents the bernoulli distribution on `Bool`. -/ universe u namespace PMF noncomputable section variable {α β γ : Type*} open scoped Classical open NNReal ENNReal section Map /-- The functorial action of a function on a `PMF`. -/ def map (f : α → β) (p : PMF α) : PMF β := bind p (pure ∘ f) variable (f : α → β) (p : PMF α) (b : β) theorem monad_map_eq_map {α β : Type u} (f : α → β) (p : PMF α) : f <$> p = p.map f := rfl @[simp] theorem map_apply : (map f p) b = ∑' a, if b = f a then p a else 0 := by simp [map] @[simp] theorem support_map : (map f p).support = f '' p.support := Set.ext fun b => by simp [map, @eq_comm β b] theorem mem_support_map_iff : b ∈ (map f p).support ↔ ∃ a ∈ p.support, f a = b := by simp theorem bind_pure_comp : bind p (pure ∘ f) = map f p := rfl theorem map_id : map id p = p := bind_pure _ theorem map_comp (g : β → γ) : (p.map f).map g = p.map (g ∘ f) := by simp [map, Function.comp] theorem pure_map (a : α) : (pure a).map f = pure (f a) := pure_bind _ _ theorem map_bind (q : α → PMF β) (f : β → γ) : (p.bind q).map f = p.bind fun a => (q a).map f := bind_bind _ _ _ @[simp] theorem bind_map (p : PMF α) (f : α → β) (q : β → PMF γ) : (p.map f).bind q = p.bind (q ∘ f) := (bind_bind _ _ _).trans (congr_arg _ (funext fun _ => pure_bind _ _)) @[simp] theorem map_const : p.map (Function.const α b) = pure b := by simp only [map, Function.comp, bind_const, Function.const] section Measure variable (s : Set β) @[simp] theorem toOuterMeasure_map_apply : (p.map f).toOuterMeasure s = p.toOuterMeasure (f ⁻¹' s) := by simp [map, Set.indicator, toOuterMeasure_apply p (f ⁻¹' s)] @[simp] theorem toMeasure_map_apply [MeasurableSpace α] [MeasurableSpace β] (hf : Measurable f) (hs : MeasurableSet s) : (p.map f).toMeasure s = p.toMeasure (f ⁻¹' s) := by rw [toMeasure_apply_eq_toOuterMeasure_apply _ s hs, toMeasure_apply_eq_toOuterMeasure_apply _ (f ⁻¹' s) (measurableSet_preimage hf hs)] exact toOuterMeasure_map_apply f p s end Measure end Map section Seq /-- The monadic sequencing operation for `PMF`. -/ def seq (q : PMF (α → β)) (p : PMF α) : PMF β := q.bind fun m => p.bind fun a => pure (m a) variable (q : PMF (α → β)) (p : PMF α) (b : β) theorem monad_seq_eq_seq {α β : Type u} (q : PMF (α → β)) (p : PMF α) : q <*> p = q.seq p := rfl @[simp] theorem seq_apply : (seq q p) b = ∑' (f : α → β) (a : α), if b = f a then q f * p a else 0 := by simp only [seq, mul_boole, bind_apply, pure_apply] refine tsum_congr fun f => ENNReal.tsum_mul_left.symm.trans (tsum_congr fun a => ?_) simpa only [mul_zero] using mul_ite (b = f a) (q f) (p a) 0 @[simp] theorem support_seq : (seq q p).support = ⋃ f ∈ q.support, f '' p.support := Set.ext fun b => by simp [-mem_support_iff, seq, @eq_comm β b] theorem mem_support_seq_iff : b ∈ (seq q p).support ↔ ∃ f ∈ q.support, b ∈ f '' p.support := by simp end Seq instance : LawfulFunctor PMF where map_const := rfl id_map := bind_pure comp_map _ _ _ := (map_comp _ _ _).symm instance : LawfulMonad PMF := LawfulMonad.mk' (bind_pure_comp := fun f x => rfl) (id_map := id_map) (pure_bind := pure_bind) (bind_assoc := bind_bind) section OfFinset /-- Given a finset `s` and a function `f : α → ℝ≥0∞` with sum `1` on `s`, such that `f a = 0` for `a ∉ s`, we get a `PMF`. -/ def ofFinset (f : α → ℝ≥0∞) (s : Finset α) (h : ∑ a ∈ s, f a = 1) (h' : ∀ (a) (_ : a ∉ s), f a = 0) : PMF α := ⟨f, h ▸ hasSum_sum_of_ne_finset_zero h'⟩ variable {f : α → ℝ≥0∞} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ (a) (_ : a ∉ s), f a = 0) @[simp] theorem ofFinset_apply (a : α) : ofFinset f s h h' a = f a := rfl @[simp] theorem support_ofFinset : (ofFinset f s h h').support = ↑s ∩ Function.support f := Set.ext fun a => by simpa [mem_support_iff] using mt (h' a) theorem mem_support_ofFinset_iff (a : α) : a ∈ (ofFinset f s h h').support ↔ a ∈ s ∧ f a ≠ 0 := by simp theorem ofFinset_apply_of_not_mem {a : α} (ha : a ∉ s) : ofFinset f s h h' a = 0 := h' a ha section Measure variable (t : Set α) @[simp] theorem toOuterMeasure_ofFinset_apply : (ofFinset f s h h').toOuterMeasure t = ∑' x, t.indicator f x := toOuterMeasure_apply (ofFinset f s h h') t @[simp] theorem toMeasure_ofFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) : (ofFinset f s h h').toMeasure t = ∑' x, t.indicator f x := (toMeasure_apply_eq_toOuterMeasure_apply _ t ht).trans (toOuterMeasure_ofFinset_apply h h' t) end Measure end OfFinset section OfFintype /-- Given a finite type `α` and a function `f : α → ℝ≥0∞` with sum 1, we get a `PMF`. -/ def ofFintype [Fintype α] (f : α → ℝ≥0∞) (h : ∑ a, f a = 1) : PMF α := ofFinset f Finset.univ h fun a ha => absurd (Finset.mem_univ a) ha variable [Fintype α] {f : α → ℝ≥0∞} (h : ∑ a, f a = 1) @[simp] theorem ofFintype_apply (a : α) : ofFintype f h a = f a := rfl @[simp] theorem support_ofFintype : (ofFintype f h).support = Function.support f := rfl theorem mem_support_ofFintype_iff (a : α) : a ∈ (ofFintype f h).support ↔ f a ≠ 0 := Iff.rfl section Measure variable (s : Set α) @[simp high] theorem toOuterMeasure_ofFintype_apply : (ofFintype f h).toOuterMeasure s = ∑' x, s.indicator f x := toOuterMeasure_apply (ofFintype f h) s @[simp] theorem toMeasure_ofFintype_apply [MeasurableSpace α] (hs : MeasurableSet s) : (ofFintype f h).toMeasure s = ∑' x, s.indicator f x := (toMeasure_apply_eq_toOuterMeasure_apply _ s hs).trans (toOuterMeasure_ofFintype_apply h s) end Measure end OfFintype section normalize /-- Given an `f` with non-zero and non-infinite sum, get a `PMF` by normalizing `f` by its `tsum`. -/ def normalize (f : α → ℝ≥0∞) (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ∞) : PMF α := ⟨fun a => f a * (∑' x, f x)⁻¹, ENNReal.summable.hasSum_iff.2 (ENNReal.tsum_mul_right.trans (ENNReal.mul_inv_cancel hf0 hf))⟩ variable {f : α → ℝ≥0∞} (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ∞) @[simp] theorem normalize_apply (a : α) : (normalize f hf0 hf) a = f a * (∑' x, f x)⁻¹ := rfl @[simp] theorem support_normalize : (normalize f hf0 hf).support = Function.support f := Set.ext fun a => by simp [hf, mem_support_iff] theorem mem_support_normalize_iff (a : α) : a ∈ (normalize f hf0 hf).support ↔ f a ≠ 0 := by simp end normalize section Filter /-- Create new `PMF` by filtering on a set with non-zero measure and normalizing. -/ def filter (p : PMF α) (s : Set α) (h : ∃ a ∈ s, a ∈ p.support) : PMF α := PMF.normalize (s.indicator p) (by simpa using h) (p.tsum_coe_indicator_ne_top s) variable {p : PMF α} {s : Set α} (h : ∃ a ∈ s, a ∈ p.support) @[simp] theorem filter_apply (a : α) : (p.filter s h) a = s.indicator p a * (∑' a', (s.indicator p) a')⁻¹ := by rw [filter, normalize_apply] theorem filter_apply_eq_zero_of_not_mem {a : α} (ha : a ∉ s) : (p.filter s h) a = 0 := by rw [filter_apply, Set.indicator_apply_eq_zero.mpr fun ha' => absurd ha' ha, zero_mul] theorem mem_support_filter_iff {a : α} : a ∈ (p.filter s h).support ↔ a ∈ s ∧ a ∈ p.support := (mem_support_normalize_iff _ _ _).trans Set.indicator_apply_ne_zero @[simp] theorem support_filter : (p.filter s h).support = s ∩ p.support := Set.ext fun _ => mem_support_filter_iff _ theorem filter_apply_eq_zero_iff (a : α) : (p.filter s h) a = 0 ↔ a ∉ s ∨ a ∉ p.support := by erw [apply_eq_zero_iff, support_filter, Set.mem_inter_iff, not_and_or] theorem filter_apply_ne_zero_iff (a : α) : (p.filter s h) a ≠ 0 ↔ a ∈ s ∧ a ∈ p.support := by rw [Ne, filter_apply_eq_zero_iff, not_or, Classical.not_not, Classical.not_not] end Filter section bernoulli /-- A `PMF` which assigns probability `p` to `true` and `1 - p` to `false`. -/ def bernoulli (p : ℝ≥0∞) (h : p ≤ 1) : PMF Bool := ofFintype (fun b => cond b p (1 - p)) (by simp [h]) variable {p : ℝ≥0∞} (h : p ≤ 1) (b : Bool) @[simp] theorem bernoulli_apply : bernoulli p h b = cond b p (1 - p) := rfl @[simp] theorem support_bernoulli : (bernoulli p h).support = { b | cond b (p ≠ 0) (p ≠ 1) } := by refine Set.ext fun b => ?_ induction b · simp_rw [mem_support_iff, bernoulli_apply, Bool.cond_false, Ne, tsub_eq_zero_iff_le, not_le] exact ⟨ne_of_lt, lt_of_le_of_ne h⟩ · simp only [mem_support_iff, bernoulli_apply, Bool.cond_true, Set.mem_setOf_eq] theorem mem_support_bernoulli_iff : b ∈ (bernoulli p h).support ↔ cond b (p ≠ 0) (p ≠ 1) := by simp end bernoulli end end PMF
Probability\ProbabilityMassFunction\Integrals.lean
/- Copyright (c) 2023 Joachim Breitner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joachim Breitner -/ import Mathlib.Probability.ProbabilityMassFunction.Basic import Mathlib.Probability.ProbabilityMassFunction.Constructions import Mathlib.MeasureTheory.Integral.Bochner /-! # Integrals with a measure derived from probability mass functions. This files connects `PMF` with `integral`. The main result is that the integral (i.e. the expected value) with regard to a measure derived from a `PMF` is a sum weighted by the `PMF`. It also provides the expected value for specific probability mass functions. -/ namespace PMF open MeasureTheory ENNReal TopologicalSpace section General variable {α : Type*} [MeasurableSpace α] [MeasurableSingletonClass α] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] theorem integral_eq_tsum (p : PMF α) (f : α → E) (hf : Integrable f p.toMeasure) : ∫ a, f a ∂(p.toMeasure) = ∑' a, (p a).toReal • f a := calc _ = ∫ a in p.support, f a ∂(p.toMeasure) := by rw [restrict_toMeasure_support p] _ = ∑' (a : support p), (p.toMeasure {a.val}).toReal • f a := by apply integral_countable f p.support_countable rwa [restrict_toMeasure_support p] _ = ∑' (a : support p), (p a).toReal • f a := by congr with x; congr 2 apply PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _) _ = ∑' a, (p a).toReal • f a := tsum_subtype_eq_of_support_subset <| by calc (fun a ↦ (p a).toReal • f a).support ⊆ (fun a ↦ (p a).toReal).support := Function.support_smul_subset_left _ _ _ ⊆ support p := fun x h1 h2 => h1 (by simp [h2]) theorem integral_eq_sum [Fintype α] (p : PMF α) (f : α → E) : ∫ a, f a ∂(p.toMeasure) = ∑ a, (p a).toReal • f a := by rw [integral_fintype _ (.of_finite _ f)] congr with x; congr 2 exact PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _) end General theorem bernoulli_expectation {p : ℝ≥0∞} (h : p ≤ 1) : ∫ b, cond b 1 0 ∂((bernoulli p h).toMeasure) = p.toReal := by simp [integral_eq_sum] end PMF
Probability\ProbabilityMassFunction\Monad.lean
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Devon Tuma -/ import Mathlib.Probability.ProbabilityMassFunction.Basic /-! # Monad Operations for Probability Mass Functions This file constructs two operations on `PMF` that give it a monad structure. `pure a` is the distribution where a single value `a` has probability `1`. `bind pa pb : PMF β` is the distribution given by sampling `a : α` from `pa : PMF α`, and then sampling from `pb a : PMF β` to get a final result `b : β`. `bindOnSupport` generalizes `bind` to allow binding to a partial function, so that the second argument only needs to be defined on the support of the first argument. -/ noncomputable section variable {α β γ : Type*} open scoped Classical open NNReal ENNReal open MeasureTheory namespace PMF section Pure /-- The pure `PMF` is the `PMF` where all the mass lies in one point. The value of `pure a` is `1` at `a` and `0` elsewhere. -/ def pure (a : α) : PMF α := ⟨fun a' => if a' = a then 1 else 0, hasSum_ite_eq _ _⟩ variable (a a' : α) @[simp] theorem pure_apply : pure a a' = if a' = a then 1 else 0 := rfl @[simp] theorem support_pure : (pure a).support = {a} := Set.ext fun a' => by simp [mem_support_iff] theorem mem_support_pure_iff : a' ∈ (pure a).support ↔ a' = a := by simp -- @[simp] -- Porting note (#10618): simp can prove this theorem pure_apply_self : pure a a = 1 := if_pos rfl theorem pure_apply_of_ne (h : a' ≠ a) : pure a a' = 0 := if_neg h instance [Inhabited α] : Inhabited (PMF α) := ⟨pure default⟩ section Measure variable (s : Set α) @[simp] theorem toOuterMeasure_pure_apply : (pure a).toOuterMeasure s = if a ∈ s then 1 else 0 := by refine (toOuterMeasure_apply (pure a) s).trans ?_ split_ifs with ha · refine (tsum_congr fun b => ?_).trans (tsum_ite_eq a 1) exact ite_eq_left_iff.2 fun hb => symm (ite_eq_right_iff.2 fun h => (hb <| h.symm ▸ ha).elim) · refine (tsum_congr fun b => ?_).trans tsum_zero exact ite_eq_right_iff.2 fun hb => ite_eq_right_iff.2 fun h => (ha <| h ▸ hb).elim variable [MeasurableSpace α] /-- The measure of a set under `pure a` is `1` for sets containing `a` and `0` otherwise. -/ @[simp] theorem toMeasure_pure_apply (hs : MeasurableSet s) : (pure a).toMeasure s = if a ∈ s then 1 else 0 := (toMeasure_apply_eq_toOuterMeasure_apply (pure a) s hs).trans (toOuterMeasure_pure_apply a s) theorem toMeasure_pure : (pure a).toMeasure = Measure.dirac a := Measure.ext fun s hs => by rw [toMeasure_pure_apply a s hs, Measure.dirac_apply' a hs]; rfl @[simp] theorem toPMF_dirac [Countable α] [h : MeasurableSingletonClass α] : (Measure.dirac a).toPMF = pure a := by rw [toPMF_eq_iff_toMeasure_eq, toMeasure_pure] end Measure end Pure section Bind /-- The monadic bind operation for `PMF`. -/ def bind (p : PMF α) (f : α → PMF β) : PMF β := ⟨fun b => ∑' a, p a * f a b, ENNReal.summable.hasSum_iff.2 (ENNReal.tsum_comm.trans <| by simp only [ENNReal.tsum_mul_left, tsum_coe, mul_one])⟩ variable (p : PMF α) (f : α → PMF β) (g : β → PMF γ) @[simp] theorem bind_apply (b : β) : p.bind f b = ∑' a, p a * f a b := rfl @[simp] theorem support_bind : (p.bind f).support = ⋃ a ∈ p.support, (f a).support := Set.ext fun b => by simp [mem_support_iff, ENNReal.tsum_eq_zero, not_or] theorem mem_support_bind_iff (b : β) : b ∈ (p.bind f).support ↔ ∃ a ∈ p.support, b ∈ (f a).support := by simp only [support_bind, Set.mem_iUnion, Set.mem_setOf_eq, exists_prop] @[simp] theorem pure_bind (a : α) (f : α → PMF β) : (pure a).bind f = f a := by have : ∀ b a', ite (a' = a) (f a' b) 0 = ite (a' = a) (f a b) 0 := fun b a' => by split_ifs with h <;> simp [h] ext b simp [this] @[simp] theorem bind_pure : p.bind pure = p := PMF.ext fun x => (bind_apply _ _ _).trans (_root_.trans (tsum_eq_single x fun y hy => by rw [pure_apply_of_ne _ _ hy.symm, mul_zero]) <| by rw [pure_apply_self, mul_one]) @[simp] theorem bind_const (p : PMF α) (q : PMF β) : (p.bind fun _ => q) = q := PMF.ext fun x => by rw [bind_apply, ENNReal.tsum_mul_right, tsum_coe, one_mul] @[simp] theorem bind_bind : (p.bind f).bind g = p.bind fun a => (f a).bind g := PMF.ext fun b => by simpa only [ENNReal.coe_inj.symm, bind_apply, ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm, mul_assoc, mul_left_comm, mul_comm] using ENNReal.tsum_comm theorem bind_comm (p : PMF α) (q : PMF β) (f : α → β → PMF γ) : (p.bind fun a => q.bind (f a)) = q.bind fun b => p.bind fun a => f a b := PMF.ext fun b => by simpa only [ENNReal.coe_inj.symm, bind_apply, ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm, mul_assoc, mul_left_comm, mul_comm] using ENNReal.tsum_comm section Measure variable (s : Set β) @[simp] theorem toOuterMeasure_bind_apply : (p.bind f).toOuterMeasure s = ∑' a, p a * (f a).toOuterMeasure s := calc (p.bind f).toOuterMeasure s = ∑' b, if b ∈ s then ∑' a, p a * f a b else 0 := by simp [toOuterMeasure_apply, Set.indicator_apply] _ = ∑' (b) (a), p a * if b ∈ s then f a b else 0 := tsum_congr fun b => by split_ifs <;> simp _ = ∑' (a) (b), p a * if b ∈ s then f a b else 0 := (tsum_comm' ENNReal.summable (fun _ => ENNReal.summable) fun _ => ENNReal.summable) _ = ∑' a, p a * ∑' b, if b ∈ s then f a b else 0 := tsum_congr fun a => ENNReal.tsum_mul_left _ = ∑' a, p a * ∑' b, if b ∈ s then f a b else 0 := (tsum_congr fun a => (congr_arg fun x => p a * x) <| tsum_congr fun b => by split_ifs <;> rfl) _ = ∑' a, p a * (f a).toOuterMeasure s := tsum_congr fun a => by simp only [toOuterMeasure_apply, Set.indicator_apply] /-- The measure of a set under `p.bind f` is the sum over `a : α` of the probability of `a` under `p` times the measure of the set under `f a`. -/ @[simp] theorem toMeasure_bind_apply [MeasurableSpace β] (hs : MeasurableSet s) : (p.bind f).toMeasure s = ∑' a, p a * (f a).toMeasure s := (toMeasure_apply_eq_toOuterMeasure_apply (p.bind f) s hs).trans ((toOuterMeasure_bind_apply p f s).trans (tsum_congr fun a => congr_arg (fun x => p a * x) (toMeasure_apply_eq_toOuterMeasure_apply (f a) s hs).symm)) end Measure end Bind instance : Monad PMF where pure a := pure a bind pa pb := pa.bind pb section BindOnSupport /-- Generalized version of `bind` allowing `f` to only be defined on the support of `p`. `p.bind f` is equivalent to `p.bindOnSupport (fun a _ ↦ f a)`, see `bindOnSupport_eq_bind`. -/ def bindOnSupport (p : PMF α) (f : ∀ a ∈ p.support, PMF β) : PMF β := ⟨fun b => ∑' a, p a * if h : p a = 0 then 0 else f a h b, ENNReal.summable.hasSum_iff.2 (by refine ENNReal.tsum_comm.trans (_root_.trans (tsum_congr fun a => ?_) p.tsum_coe) simp_rw [ENNReal.tsum_mul_left] split_ifs with h · simp only [h, zero_mul] · rw [(f a h).tsum_coe, mul_one])⟩ variable {p : PMF α} (f : ∀ a ∈ p.support, PMF β) @[simp] theorem bindOnSupport_apply (b : β) : p.bindOnSupport f b = ∑' a, p a * if h : p a = 0 then 0 else f a h b := rfl @[simp] theorem support_bindOnSupport : (p.bindOnSupport f).support = ⋃ (a : α) (h : a ∈ p.support), (f a h).support := by refine Set.ext fun b => ?_ simp only [ENNReal.tsum_eq_zero, not_or, mem_support_iff, bindOnSupport_apply, Ne, not_forall, mul_eq_zero, Set.mem_iUnion] exact ⟨fun hb => let ⟨a, ⟨ha, ha'⟩⟩ := hb ⟨a, ha, by simpa [ha] using ha'⟩, fun hb => let ⟨a, ha, ha'⟩ := hb ⟨a, ⟨ha, by simpa [(mem_support_iff _ a).1 ha] using ha'⟩⟩⟩ theorem mem_support_bindOnSupport_iff (b : β) : b ∈ (p.bindOnSupport f).support ↔ ∃ (a : α) (h : a ∈ p.support), b ∈ (f a h).support := by simp only [support_bindOnSupport, Set.mem_setOf_eq, Set.mem_iUnion] /-- `bindOnSupport` reduces to `bind` if `f` doesn't depend on the additional hypothesis. -/ @[simp] theorem bindOnSupport_eq_bind (p : PMF α) (f : α → PMF β) : (p.bindOnSupport fun a _ => f a) = p.bind f := by ext b have : ∀ a, ite (p a = 0) 0 (p a * f a b) = p a * f a b := fun a => ite_eq_right_iff.2 fun h => h.symm ▸ symm (zero_mul <| f a b) simp only [bindOnSupport_apply fun a _ => f a, p.bind_apply f, dite_eq_ite, mul_ite, mul_zero, this] theorem bindOnSupport_eq_zero_iff (b : β) : p.bindOnSupport f b = 0 ↔ ∀ (a) (ha : p a ≠ 0), f a ha b = 0 := by simp only [bindOnSupport_apply, ENNReal.tsum_eq_zero, mul_eq_zero, or_iff_not_imp_left] exact ⟨fun h a ha => Trans.trans (dif_neg ha).symm (h a ha), fun h a ha => Trans.trans (dif_neg ha) (h a ha)⟩ @[simp] theorem pure_bindOnSupport (a : α) (f : ∀ (a' : α) (_ : a' ∈ (pure a).support), PMF β) : (pure a).bindOnSupport f = f a ((mem_support_pure_iff a a).mpr rfl) := by refine PMF.ext fun b => ?_ simp only [bindOnSupport_apply, pure_apply] refine _root_.trans (tsum_congr fun a' => ?_) (tsum_ite_eq a _) by_cases h : a' = a <;> simp [h] theorem bindOnSupport_pure (p : PMF α) : (p.bindOnSupport fun a _ => pure a) = p := by simp only [PMF.bind_pure, PMF.bindOnSupport_eq_bind] @[simp] theorem bindOnSupport_bindOnSupport (p : PMF α) (f : ∀ a ∈ p.support, PMF β) (g : ∀ b ∈ (p.bindOnSupport f).support, PMF γ) : (p.bindOnSupport f).bindOnSupport g = p.bindOnSupport fun a ha => (f a ha).bindOnSupport fun b hb => g b ((mem_support_bindOnSupport_iff f b).mpr ⟨a, ha, hb⟩) := by refine PMF.ext fun a => ?_ dsimp only [bindOnSupport_apply] simp only [← tsum_dite_right, ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm] simp only [ENNReal.tsum_eq_zero, dite_eq_left_iff] refine ENNReal.tsum_comm.trans (tsum_congr fun a' => tsum_congr fun b => ?_) split_ifs with h _ h_1 _ h_2 any_goals ring1 · have := h_1 a' simp? [h] at this says simp only [h, ↓reduceDIte, mul_eq_zero, false_or] at this contradiction · simp [h_2] theorem bindOnSupport_comm (p : PMF α) (q : PMF β) (f : ∀ a ∈ p.support, ∀ b ∈ q.support, PMF γ) : (p.bindOnSupport fun a ha => q.bindOnSupport (f a ha)) = q.bindOnSupport fun b hb => p.bindOnSupport fun a ha => f a ha b hb := by apply PMF.ext; rintro c simp only [ENNReal.coe_inj.symm, bindOnSupport_apply, ← tsum_dite_right, ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm] refine _root_.trans ENNReal.tsum_comm (tsum_congr fun b => tsum_congr fun a => ?_) split_ifs with h1 h2 h2 <;> ring section Measure variable (s : Set β) @[simp] theorem toOuterMeasure_bindOnSupport_apply : (p.bindOnSupport f).toOuterMeasure s = ∑' a, p a * if h : p a = 0 then 0 else (f a h).toOuterMeasure s := by simp only [toOuterMeasure_apply, Set.indicator_apply, bindOnSupport_apply] calc (∑' b, ite (b ∈ s) (∑' a, p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0) = ∑' (b) (a), ite (b ∈ s) (p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0 := tsum_congr fun b => by split_ifs with hbs <;> simp only [eq_self_iff_true, tsum_zero] _ = ∑' (a) (b), ite (b ∈ s) (p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0 := ENNReal.tsum_comm _ = ∑' a, p a * ∑' b, ite (b ∈ s) (dite (p a = 0) (fun h => 0) fun h => f a h b) 0 := (tsum_congr fun a => by simp only [← ENNReal.tsum_mul_left, mul_ite, mul_zero]) _ = ∑' a, p a * dite (p a = 0) (fun h => 0) fun h => ∑' b, ite (b ∈ s) (f a h b) 0 := tsum_congr fun a => by split_ifs with ha <;> simp only [ite_self, tsum_zero, eq_self_iff_true] /-- The measure of a set under `p.bindOnSupport f` is the sum over `a : α` of the probability of `a` under `p` times the measure of the set under `f a _`. The additional if statement is needed since `f` is only a partial function. -/ @[simp] theorem toMeasure_bindOnSupport_apply [MeasurableSpace β] (hs : MeasurableSet s) : (p.bindOnSupport f).toMeasure s = ∑' a, p a * if h : p a = 0 then 0 else (f a h).toMeasure s := by simp only [toMeasure_apply_eq_toOuterMeasure_apply _ _ hs, toOuterMeasure_bindOnSupport_apply] end Measure end BindOnSupport end PMF
Probability\Process\Adapted.lean
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Filtration import Mathlib.Topology.Instances.Discrete /-! # Adapted and progressively measurable processes This file defines some standard definition from the theory of stochastic processes including filtrations and stopping times. These definitions are used to model the amount of information at a specific time and are the first step in formalizing stochastic processes. ## Main definitions * `MeasureTheory.Adapted`: a sequence of functions `u` is said to be adapted to a filtration `f` if at each point in time `i`, `u i` is `f i`-strongly measurable * `MeasureTheory.ProgMeasurable`: a sequence of functions `u` is said to be progressively measurable with respect to a filtration `f` if at each point in time `i`, `u` restricted to `Set.Iic i × Ω` is strongly measurable with respect to the product `MeasurableSpace` structure where the σ-algebra used for `Ω` is `f i`. ## Main results * `Adapted.progMeasurable_of_continuous`: a continuous adapted process is progressively measurable. ## Tags adapted, progressively measurable -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} [TopologicalSpace β] [Preorder ι] {u v : ι → Ω → β} {f : Filtration ι m} /-- A sequence of functions `u` is adapted to a filtration `f` if for all `i`, `u i` is `f i`-measurable. -/ def Adapted (f : Filtration ι m) (u : ι → Ω → β) : Prop := ∀ i : ι, StronglyMeasurable[f i] (u i) namespace Adapted @[to_additive] protected theorem mul [Mul β] [ContinuousMul β] (hu : Adapted f u) (hv : Adapted f v) : Adapted f (u * v) := fun i => (hu i).mul (hv i) @[to_additive] protected theorem div [Div β] [ContinuousDiv β] (hu : Adapted f u) (hv : Adapted f v) : Adapted f (u / v) := fun i => (hu i).div (hv i) @[to_additive] protected theorem inv [Group β] [TopologicalGroup β] (hu : Adapted f u) : Adapted f u⁻¹ := fun i => (hu i).inv protected theorem smul [SMul ℝ β] [ContinuousSMul ℝ β] (c : ℝ) (hu : Adapted f u) : Adapted f (c • u) := fun i => (hu i).const_smul c protected theorem stronglyMeasurable {i : ι} (hf : Adapted f u) : StronglyMeasurable[m] (u i) := (hf i).mono (f.le i) theorem stronglyMeasurable_le {i j : ι} (hf : Adapted f u) (hij : i ≤ j) : StronglyMeasurable[f j] (u i) := (hf i).mono (f.mono hij) end Adapted theorem adapted_const (f : Filtration ι m) (x : β) : Adapted f fun _ _ => x := fun _ => stronglyMeasurable_const variable (β) theorem adapted_zero [Zero β] (f : Filtration ι m) : Adapted f (0 : ι → Ω → β) := fun i => @stronglyMeasurable_zero Ω β (f i) _ _ variable {β} theorem Filtration.adapted_natural [MetrizableSpace β] [mβ : MeasurableSpace β] [BorelSpace β] {u : ι → Ω → β} (hum : ∀ i, StronglyMeasurable[m] (u i)) : Adapted (Filtration.natural u hum) u := by intro i refine StronglyMeasurable.mono ?_ (le_iSup₂_of_le i (le_refl i) le_rfl) rw [stronglyMeasurable_iff_measurable_separable] exact ⟨measurable_iff_comap_le.2 le_rfl, (hum i).isSeparable_range⟩ /-- Progressively measurable process. A sequence of functions `u` is said to be progressively measurable with respect to a filtration `f` if at each point in time `i`, `u` restricted to `Set.Iic i × Ω` is measurable with respect to the product `MeasurableSpace` structure where the σ-algebra used for `Ω` is `f i`. The usual definition uses the interval `[0,i]`, which we replace by `Set.Iic i`. We recover the usual definition for index types `ℝ≥0` or `ℕ`. -/ def ProgMeasurable [MeasurableSpace ι] (f : Filtration ι m) (u : ι → Ω → β) : Prop := ∀ i, StronglyMeasurable[Subtype.instMeasurableSpace.prod (f i)] fun p : Set.Iic i × Ω => u p.1 p.2 theorem progMeasurable_const [MeasurableSpace ι] (f : Filtration ι m) (b : β) : ProgMeasurable f (fun _ _ => b : ι → Ω → β) := fun i => @stronglyMeasurable_const _ _ (Subtype.instMeasurableSpace.prod (f i)) _ _ namespace ProgMeasurable variable [MeasurableSpace ι] protected theorem adapted (h : ProgMeasurable f u) : Adapted f u := by intro i have : u i = (fun p : Set.Iic i × Ω => u p.1 p.2) ∘ fun x => (⟨i, Set.mem_Iic.mpr le_rfl⟩, x) := rfl rw [this] exact (h i).comp_measurable measurable_prod_mk_left protected theorem comp {t : ι → Ω → ι} [TopologicalSpace ι] [BorelSpace ι] [MetrizableSpace ι] (h : ProgMeasurable f u) (ht : ProgMeasurable f t) (ht_le : ∀ i ω, t i ω ≤ i) : ProgMeasurable f fun i ω => u (t i ω) ω := by intro i have : (fun p : ↥(Set.Iic i) × Ω => u (t (p.fst : ι) p.snd) p.snd) = (fun p : ↥(Set.Iic i) × Ω => u (p.fst : ι) p.snd) ∘ fun p : ↥(Set.Iic i) × Ω => (⟨t (p.fst : ι) p.snd, Set.mem_Iic.mpr ((ht_le _ _).trans p.fst.prop)⟩, p.snd) := rfl rw [this] exact (h i).comp_measurable ((ht i).measurable.subtype_mk.prod_mk measurable_snd) section Arithmetic @[to_additive] protected theorem mul [Mul β] [ContinuousMul β] (hu : ProgMeasurable f u) (hv : ProgMeasurable f v) : ProgMeasurable f fun i ω => u i ω * v i ω := fun i => (hu i).mul (hv i) @[to_additive] protected theorem finset_prod' {γ} [CommMonoid β] [ContinuousMul β] {U : γ → ι → Ω → β} {s : Finset γ} (h : ∀ c ∈ s, ProgMeasurable f (U c)) : ProgMeasurable f (∏ c ∈ s, U c) := Finset.prod_induction U (ProgMeasurable f) (fun _ _ => ProgMeasurable.mul) (progMeasurable_const _ 1) h @[to_additive] protected theorem finset_prod {γ} [CommMonoid β] [ContinuousMul β] {U : γ → ι → Ω → β} {s : Finset γ} (h : ∀ c ∈ s, ProgMeasurable f (U c)) : ProgMeasurable f fun i a => ∏ c ∈ s, U c i a := by convert ProgMeasurable.finset_prod' h using 1; ext (i a); simp only [Finset.prod_apply] @[to_additive] protected theorem inv [Group β] [TopologicalGroup β] (hu : ProgMeasurable f u) : ProgMeasurable f fun i ω => (u i ω)⁻¹ := fun i => (hu i).inv @[to_additive] protected theorem div [Group β] [TopologicalGroup β] (hu : ProgMeasurable f u) (hv : ProgMeasurable f v) : ProgMeasurable f fun i ω => u i ω / v i ω := fun i => (hu i).div (hv i) end Arithmetic end ProgMeasurable theorem progMeasurable_of_tendsto' {γ} [MeasurableSpace ι] [PseudoMetrizableSpace β] (fltr : Filter γ) [fltr.NeBot] [fltr.IsCountablyGenerated] {U : γ → ι → Ω → β} (h : ∀ l, ProgMeasurable f (U l)) (h_tendsto : Tendsto U fltr (𝓝 u)) : ProgMeasurable f u := by intro i apply @stronglyMeasurable_of_tendsto (Set.Iic i × Ω) β γ (MeasurableSpace.prod _ (f i)) _ _ fltr _ _ _ _ fun l => h l i rw [tendsto_pi_nhds] at h_tendsto ⊢ intro x specialize h_tendsto x.fst rw [tendsto_nhds] at h_tendsto ⊢ exact fun s hs h_mem => h_tendsto {g | g x.snd ∈ s} (hs.preimage (continuous_apply x.snd)) h_mem theorem progMeasurable_of_tendsto [MeasurableSpace ι] [PseudoMetrizableSpace β] {U : ℕ → ι → Ω → β} (h : ∀ l, ProgMeasurable f (U l)) (h_tendsto : Tendsto U atTop (𝓝 u)) : ProgMeasurable f u := progMeasurable_of_tendsto' atTop h h_tendsto /-- A continuous and adapted process is progressively measurable. -/ theorem Adapted.progMeasurable_of_continuous [TopologicalSpace ι] [MetrizableSpace ι] [SecondCountableTopology ι] [MeasurableSpace ι] [OpensMeasurableSpace ι] [PseudoMetrizableSpace β] (h : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) : ProgMeasurable f u := fun i => @stronglyMeasurable_uncurry_of_continuous_of_stronglyMeasurable _ _ (Set.Iic i) _ _ _ _ _ _ _ (f i) _ (fun ω => (hu_cont ω).comp continuous_induced_dom) fun j => (h j).mono (f.mono j.prop) /-- For filtrations indexed by a discrete order, `Adapted` and `ProgMeasurable` are equivalent. This lemma provides `Adapted f u → ProgMeasurable f u`. See `ProgMeasurable.adapted` for the reverse direction, which is true more generally. -/ theorem Adapted.progMeasurable_of_discrete [TopologicalSpace ι] [DiscreteTopology ι] [SecondCountableTopology ι] [MeasurableSpace ι] [OpensMeasurableSpace ι] [PseudoMetrizableSpace β] (h : Adapted f u) : ProgMeasurable f u := h.progMeasurable_of_continuous fun _ => continuous_of_discreteTopology -- this dot notation will make more sense once we have a more general definition for predictable theorem Predictable.adapted {f : Filtration ℕ m} {u : ℕ → Ω → β} (hu : Adapted f fun n => u (n + 1)) (hu0 : StronglyMeasurable[f 0] (u 0)) : Adapted f u := fun n => match n with | 0 => hu0 | n + 1 => (hu n).mono (f.mono n.le_succ) end MeasureTheory
Probability\Process\Filtration.lean
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.MeasureTheory.Function.ConditionalExpectation.Real /-! # Filtrations This file defines filtrations of a measurable space and σ-finite filtrations. ## Main definitions * `MeasureTheory.Filtration`: a filtration on a measurable space. That is, a monotone sequence of sub-σ-algebras. * `MeasureTheory.SigmaFiniteFiltration`: a filtration `f` is σ-finite with respect to a measure `μ` if for all `i`, `μ.trim (f.le i)` is σ-finite. * `MeasureTheory.Filtration.natural`: the smallest filtration that makes a process adapted. That notion `adapted` is not defined yet in this file. See `MeasureTheory.adapted`. ## Main results * `MeasureTheory.Filtration.instCompleteLattice`: filtrations are a complete lattice. ## Tags filtration, stochastic process -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory /-- A `Filtration` on a measurable space `Ω` with σ-algebra `m` is a monotone sequence of sub-σ-algebras of `m`. -/ structure Filtration {Ω : Type*} (ι : Type*) [Preorder ι] (m : MeasurableSpace Ω) where seq : ι → MeasurableSpace Ω mono' : Monotone seq le' : ∀ i : ι, seq i ≤ m attribute [coe] Filtration.seq variable {Ω β ι : Type*} {m : MeasurableSpace Ω} instance [Preorder ι] : CoeFun (Filtration ι m) fun _ => ι → MeasurableSpace Ω := ⟨fun f => f.seq⟩ namespace Filtration variable [Preorder ι] protected theorem mono {i j : ι} (f : Filtration ι m) (hij : i ≤ j) : f i ≤ f j := f.mono' hij protected theorem le (f : Filtration ι m) (i : ι) : f i ≤ m := f.le' i @[ext] protected theorem ext {f g : Filtration ι m} (h : (f : ι → MeasurableSpace Ω) = g) : f = g := by cases f; cases g; congr variable (ι) /-- The constant filtration which is equal to `m` for all `i : ι`. -/ def const (m' : MeasurableSpace Ω) (hm' : m' ≤ m) : Filtration ι m := ⟨fun _ => m', monotone_const, fun _ => hm'⟩ variable {ι} @[simp] theorem const_apply {m' : MeasurableSpace Ω} {hm' : m' ≤ m} (i : ι) : const ι m' hm' i = m' := rfl instance : Inhabited (Filtration ι m) := ⟨const ι m le_rfl⟩ instance : LE (Filtration ι m) := ⟨fun f g => ∀ i, f i ≤ g i⟩ instance : Bot (Filtration ι m) := ⟨const ι ⊥ bot_le⟩ instance : Top (Filtration ι m) := ⟨const ι m le_rfl⟩ instance : Sup (Filtration ι m) := ⟨fun f g => { seq := fun i => f i ⊔ g i mono' := fun _ _ hij => sup_le ((f.mono hij).trans le_sup_left) ((g.mono hij).trans le_sup_right) le' := fun i => sup_le (f.le i) (g.le i) }⟩ @[norm_cast] theorem coeFn_sup {f g : Filtration ι m} : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g := rfl instance : Inf (Filtration ι m) := ⟨fun f g => { seq := fun i => f i ⊓ g i mono' := fun _ _ hij => le_inf (inf_le_left.trans (f.mono hij)) (inf_le_right.trans (g.mono hij)) le' := fun i => inf_le_left.trans (f.le i) }⟩ @[norm_cast] theorem coeFn_inf {f g : Filtration ι m} : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl instance : SupSet (Filtration ι m) := ⟨fun s => { seq := fun i => sSup ((fun f : Filtration ι m => f i) '' s) mono' := fun i j hij => by refine sSup_le fun m' hm' => ?_ rw [Set.mem_image] at hm' obtain ⟨f, hf_mem, hfm'⟩ := hm' rw [← hfm'] refine (f.mono hij).trans ?_ have hfj_mem : f j ∈ (fun g : Filtration ι m => g j) '' s := ⟨f, hf_mem, rfl⟩ exact le_sSup hfj_mem le' := fun i => by refine sSup_le fun m' hm' => ?_ rw [Set.mem_image] at hm' obtain ⟨f, _, hfm'⟩ := hm' rw [← hfm'] exact f.le i }⟩ theorem sSup_def (s : Set (Filtration ι m)) (i : ι) : sSup s i = sSup ((fun f : Filtration ι m => f i) '' s) := rfl noncomputable instance : InfSet (Filtration ι m) := ⟨fun s => { seq := fun i => if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m mono' := fun i j hij => by by_cases h_nonempty : Set.Nonempty s swap; · simp only [h_nonempty, Set.image_nonempty, if_false, le_refl] simp only [h_nonempty, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] refine fun f hf_mem => le_trans ?_ (f.mono hij) have hfi_mem : f i ∈ (fun g : Filtration ι m => g i) '' s := ⟨f, hf_mem, rfl⟩ exact sInf_le hfi_mem le' := fun i => by by_cases h_nonempty : Set.Nonempty s swap; · simp only [h_nonempty, if_false, le_refl] simp only [h_nonempty, if_true] obtain ⟨f, hf_mem⟩ := h_nonempty exact le_trans (sInf_le ⟨f, hf_mem, rfl⟩) (f.le i) }⟩ theorem sInf_def (s : Set (Filtration ι m)) (i : ι) : sInf s i = if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m := rfl noncomputable instance instCompleteLattice : CompleteLattice (Filtration ι m) where le := (· ≤ ·) le_refl f i := le_rfl le_trans f g h h_fg h_gh i := (h_fg i).trans (h_gh i) le_antisymm f g h_fg h_gf := Filtration.ext <| funext fun i => (h_fg i).antisymm (h_gf i) sup := (· ⊔ ·) le_sup_left f g i := le_sup_left le_sup_right f g i := le_sup_right sup_le f g h h_fh h_gh i := sup_le (h_fh i) (h_gh _) inf := (· ⊓ ·) inf_le_left f g i := inf_le_left inf_le_right f g i := inf_le_right le_inf f g h h_fg h_fh i := le_inf (h_fg i) (h_fh i) sSup := sSup le_sSup s f hf_mem i := le_sSup ⟨f, hf_mem, rfl⟩ sSup_le s f h_forall i := sSup_le fun m' hm' => by obtain ⟨g, hg_mem, hfm'⟩ := hm' rw [← hfm'] exact h_forall g hg_mem i sInf := sInf sInf_le s f hf_mem i := by have hs : s.Nonempty := ⟨f, hf_mem⟩ simp only [sInf_def, hs, if_true] exact sInf_le ⟨f, hf_mem, rfl⟩ le_sInf s f h_forall i := by by_cases hs : s.Nonempty swap; · simp only [sInf_def, hs, if_false]; exact f.le i simp only [sInf_def, hs, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] exact fun g hg_mem => h_forall g hg_mem i top := ⊤ bot := ⊥ le_top f i := f.le' i bot_le f i := bot_le end Filtration theorem measurableSet_of_filtration [Preorder ι] {f : Filtration ι m} {s : Set Ω} {i : ι} (hs : MeasurableSet[f i] s) : MeasurableSet[m] s := f.le i s hs /-- A measure is σ-finite with respect to filtration if it is σ-finite with respect to all the sub-σ-algebra of the filtration. -/ class SigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m) : Prop where SigmaFinite : ∀ i : ι, SigmaFinite (μ.trim (f.le i)) instance sigmaFinite_of_sigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m) [hf : SigmaFiniteFiltration μ f] (i : ι) : SigmaFinite (μ.trim (f.le i)) := hf.SigmaFinite _ instance (priority := 100) IsFiniteMeasure.sigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m) [IsFiniteMeasure μ] : SigmaFiniteFiltration μ f := ⟨fun n => by infer_instance⟩ /-- Given an integrable function `g`, the conditional expectations of `g` with respect to a filtration is uniformly integrable. -/ theorem Integrable.uniformIntegrable_condexp_filtration [Preorder ι] {μ : Measure Ω} [IsFiniteMeasure μ] {f : Filtration ι m} {g : Ω → ℝ} (hg : Integrable g μ) : UniformIntegrable (fun i => μ[g|f i]) 1 μ := hg.uniformIntegrable_condexp f.le section OfSet variable [Preorder ι] /-- Given a sequence of measurable sets `(sₙ)`, `filtrationOfSet` is the smallest filtration such that `sₙ` is measurable with respect to the `n`-th sub-σ-algebra in `filtrationOfSet`. -/ def filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet (s i)) : Filtration ι m where seq i := MeasurableSpace.generateFrom {t | ∃ j ≤ i, s j = t} mono' _ _ hnm := MeasurableSpace.generateFrom_mono fun _ ⟨k, hk₁, hk₂⟩ => ⟨k, hk₁.trans hnm, hk₂⟩ le' _ := MeasurableSpace.generateFrom_le fun _ ⟨k, _, hk₂⟩ => hk₂ ▸ hsm k theorem measurableSet_filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) (i : ι) {j : ι} (hj : j ≤ i) : MeasurableSet[filtrationOfSet hsm i] (s j) := MeasurableSpace.measurableSet_generateFrom ⟨j, hj, rfl⟩ theorem measurableSet_filtrationOfSet' {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet[m] (s n)) (i : ι) : MeasurableSet[filtrationOfSet hsm i] (s i) := measurableSet_filtrationOfSet hsm i le_rfl end OfSet namespace Filtration variable [TopologicalSpace β] [MetrizableSpace β] [mβ : MeasurableSpace β] [BorelSpace β] [Preorder ι] /-- Given a sequence of functions, the natural filtration is the smallest sequence of σ-algebras such that that sequence of functions is measurable with respect to the filtration. -/ def natural (u : ι → Ω → β) (hum : ∀ i, StronglyMeasurable (u i)) : Filtration ι m where seq i := ⨆ j ≤ i, MeasurableSpace.comap (u j) mβ mono' i j hij := biSup_mono fun k => ge_trans hij le' i := by refine iSup₂_le ?_ rintro j _ s ⟨t, ht, rfl⟩ exact (hum j).measurable ht section open MeasurableSpace theorem filtrationOfSet_eq_natural [MulZeroOneClass β] [Nontrivial β] {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) : filtrationOfSet hsm = natural (fun i => (s i).indicator (fun _ => 1 : Ω → β)) fun i => stronglyMeasurable_one.indicator (hsm i) := by simp only [filtrationOfSet, natural, measurableSpace_iSup_eq, exists_prop, mk.injEq] ext1 i refine le_antisymm (generateFrom_le ?_) (generateFrom_le ?_) · rintro _ ⟨j, hij, rfl⟩ refine measurableSet_generateFrom ⟨j, measurableSet_generateFrom ⟨hij, ?_⟩⟩ rw [comap_eq_generateFrom] refine measurableSet_generateFrom ⟨{1}, measurableSet_singleton 1, ?_⟩ ext x simp [Set.indicator_const_preimage_eq_union] · rintro t ⟨n, ht⟩ suffices MeasurableSpace.generateFrom {t | n ≤ i ∧ MeasurableSet[MeasurableSpace.comap ((s n).indicator (fun _ => 1 : Ω → β)) mβ] t} ≤ MeasurableSpace.generateFrom {t | ∃ (j : ι), j ≤ i ∧ s j = t} by exact this _ ht refine generateFrom_le ?_ rintro t ⟨hn, u, _, hu'⟩ obtain heq | heq | heq | heq := Set.indicator_const_preimage (s n) u (1 : β) on_goal 4 => rw [Set.mem_singleton_iff] at heq all_goals rw [heq] at hu'; rw [← hu'] exacts [MeasurableSet.univ, measurableSet_generateFrom ⟨n, hn, rfl⟩, MeasurableSet.compl (measurableSet_generateFrom ⟨n, hn, rfl⟩), measurableSet_empty _] end section Limit variable {E : Type*} [Zero E] [TopologicalSpace E] {ℱ : Filtration ι m} {f : ι → Ω → E} {μ : Measure Ω} /-- Given a process `f` and a filtration `ℱ`, if `f` converges to some `g` almost everywhere and `g` is `⨆ n, ℱ n`-measurable, then `limitProcess f ℱ μ` chooses said `g`, else it returns 0. This definition is used to phrase the a.e. martingale convergence theorem `Submartingale.ae_tendsto_limitProcess` where an L¹-bounded submartingale `f` adapted to `ℱ` converges to `limitProcess f ℱ μ` `μ`-almost everywhere. -/ noncomputable def limitProcess (f : ι → Ω → E) (ℱ : Filtration ι m) (μ : Measure Ω) := if h : ∃ g : Ω → E, StronglyMeasurable[⨆ n, ℱ n] g ∧ ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) then Classical.choose h else 0 theorem stronglyMeasurable_limitProcess : StronglyMeasurable[⨆ n, ℱ n] (limitProcess f ℱ μ) := by rw [limitProcess] split_ifs with h exacts [(Classical.choose_spec h).1, stronglyMeasurable_zero] theorem stronglyMeasurable_limit_process' : StronglyMeasurable[m] (limitProcess f ℱ μ) := stronglyMeasurable_limitProcess.mono (sSup_le fun _ ⟨_, hn⟩ => hn ▸ ℱ.le _) theorem memℒp_limitProcess_of_eLpNorm_bdd {R : ℝ≥0} {p : ℝ≥0∞} {F : Type*} [NormedAddCommGroup F] {ℱ : Filtration ℕ m} {f : ℕ → Ω → F} (hfm : ∀ n, AEStronglyMeasurable (f n) μ) (hbdd : ∀ n, eLpNorm (f n) p μ ≤ R) : Memℒp (limitProcess f ℱ μ) p μ := by rw [limitProcess] split_ifs with h · refine ⟨StronglyMeasurable.aestronglyMeasurable ((Classical.choose_spec h).1.mono (sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _)), lt_of_le_of_lt (Lp.eLpNorm_lim_le_liminf_eLpNorm hfm _ (Classical.choose_spec h).2) (lt_of_le_of_lt ?_ (ENNReal.coe_lt_top : ↑R < ∞))⟩ simp_rw [liminf_eq, eventually_atTop] exact sSup_le fun b ⟨a, ha⟩ => (ha a le_rfl).trans (hbdd _) · exact zero_memℒp @[deprecated (since := "2024-07-27")] alias memℒp_limitProcess_of_snorm_bdd := memℒp_limitProcess_of_eLpNorm_bdd end Limit end Filtration end MeasureTheory
Probability\Process\HittingTime.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Stopping import Mathlib.Tactic.AdaptationNote /-! # Hitting time Given a stochastic process, the hitting time provides the first time the process "hits" some subset of the state space. The hitting time is a stopping time in the case that the time index is discrete and the process is adapted (this is true in a far more general setting however we have only proved it for the discrete case so far). ## Main definition * `MeasureTheory.hitting`: the hitting time of a stochastic process ## Main results * `MeasureTheory.hitting_isStoppingTime`: a discrete hitting time of an adapted process is a stopping time ## Implementation notes In the definition of the hitting time, we bound the hitting time by an upper and lower bound. This is to ensure that our result is meaningful in the case we are taking the infimum of an empty set or the infimum of a set which is unbounded from below. With this, we can talk about hitting times indexed by the natural numbers or the reals. By taking the bounds to be `⊤` and `⊥`, we obtain the standard definition in the case that the index is `ℕ∞` or `ℝ≥0∞`. -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time `u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and before `m` then the hitting time is simply `m`). The hitting time is a stopping time if the process is adapted and discrete. -/ noncomputable def hitting [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : Ω → ι := fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m #adaptation_note /-- nightly-2024-03-16: added to replace simp [hitting] -/ theorem hitting_def [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : hitting u s n m = fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m := rfl section Inequalities variable [ConditionallyCompleteLinearOrder ι] {u : ι → Ω → β} {s : Set β} {n i : ι} {ω : Ω} /-- This lemma is strictly weaker than `hitting_of_le`. -/ theorem hitting_of_lt {m : ι} (h : m < n) : hitting u s n m ω = m := by simp_rw [hitting] have h_not : ¬∃ (j : ι) (_ : j ∈ Set.Icc n m), u j ω ∈ s := by push_neg intro j rw [Set.Icc_eq_empty_of_lt h] simp only [Set.mem_empty_iff_false, IsEmpty.forall_iff] simp only [exists_prop] at h_not simp only [h_not, if_false] theorem hitting_le {m : ι} (ω : Ω) : hitting u s n m ω ≤ m := by simp only [hitting] split_ifs with h · obtain ⟨j, hj₁, hj₂⟩ := h change j ∈ {i | u i ω ∈ s} at hj₂ exact (csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter hj₁ hj₂)).trans hj₁.2 · exact le_rfl theorem not_mem_of_lt_hitting {m k : ι} (hk₁ : k < hitting u s n m ω) (hk₂ : n ≤ k) : u k ω ∉ s := by classical intro h have hexists : ∃ j ∈ Set.Icc n m, u j ω ∈ s := ⟨k, ⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ refine not_le.2 hk₁ ?_ simp_rw [hitting, if_pos hexists] exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ theorem hitting_eq_end_iff {m : ι} : hitting u s n m ω = m ↔ (∃ j ∈ Set.Icc n m, u j ω ∈ s) → sInf (Set.Icc n m ∩ {i : ι | u i ω ∈ s}) = m := by rw [hitting, ite_eq_right_iff] theorem hitting_of_le {m : ι} (hmn : m ≤ n) : hitting u s n m ω = m := by obtain rfl | h := le_iff_eq_or_lt.1 hmn · rw [hitting, ite_eq_right_iff, forall_exists_index] conv => intro; rw [Set.mem_Icc, Set.Icc_self, and_imp, and_imp] intro i hi₁ hi₂ hi rw [Set.inter_eq_left.2, csInf_singleton] exact Set.singleton_subset_iff.2 (le_antisymm hi₂ hi₁ ▸ hi) · exact hitting_of_lt h theorem le_hitting {m : ι} (hnm : n ≤ m) (ω : Ω) : n ≤ hitting u s n m ω := by simp only [hitting] split_ifs with h · refine le_csInf ?_ fun b hb => ?_ · obtain ⟨k, hk_Icc, hk_s⟩ := h exact ⟨k, hk_Icc, hk_s⟩ · rw [Set.mem_inter_iff] at hb exact hb.1.1 · exact hnm theorem le_hitting_of_exists {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : n ≤ hitting u s n m ω := by refine le_hitting ?_ ω by_contra h rw [Set.Icc_eq_empty_of_lt (not_le.mp h)] at h_exists simp at h_exists theorem hitting_mem_Icc {m : ι} (hnm : n ≤ m) (ω : Ω) : hitting u s n m ω ∈ Set.Icc n m := ⟨le_hitting hnm ω, hitting_le ω⟩ theorem hitting_mem_set [IsWellOrder ι (· < ·)] {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : u (hitting u s n m ω) ω ∈ s := by simp_rw [hitting, if_pos h_exists] have h_nonempty : (Set.Icc n m ∩ {i : ι | u i ω ∈ s}).Nonempty := by obtain ⟨k, hk₁, hk₂⟩ := h_exists exact ⟨k, Set.mem_inter hk₁ hk₂⟩ have h_mem := csInf_mem h_nonempty rw [Set.mem_inter_iff] at h_mem exact h_mem.2 theorem hitting_mem_set_of_hitting_lt [IsWellOrder ι (· < ·)] {m : ι} (hl : hitting u s n m ω < m) : u (hitting u s n m ω) ω ∈ s := by by_cases h : ∃ j ∈ Set.Icc n m, u j ω ∈ s · exact hitting_mem_set h · simp_rw [hitting, if_neg h] at hl exact False.elim (hl.ne rfl) theorem hitting_le_of_mem {m : ι} (hin : n ≤ i) (him : i ≤ m) (his : u i ω ∈ s) : hitting u s n m ω ≤ i := by have h_exists : ∃ k ∈ Set.Icc n m, u k ω ∈ s := ⟨i, ⟨hin, him⟩, his⟩ simp_rw [hitting, if_pos h_exists] exact csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter ⟨hin, him⟩ his) theorem hitting_le_iff_of_exists [IsWellOrder ι (· < ·)] {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : hitting u s n m ω ≤ i ↔ ∃ j ∈ Set.Icc n i, u j ω ∈ s := by constructor <;> intro h' · exact ⟨hitting u s n m ω, ⟨le_hitting_of_exists h_exists, h'⟩, hitting_mem_set h_exists⟩ · have h'' : ∃ k ∈ Set.Icc n (min m i), u k ω ∈ s := by obtain ⟨k₁, hk₁_mem, hk₁_s⟩ := h_exists obtain ⟨k₂, hk₂_mem, hk₂_s⟩ := h' refine ⟨min k₁ k₂, ⟨le_min hk₁_mem.1 hk₂_mem.1, min_le_min hk₁_mem.2 hk₂_mem.2⟩, ?_⟩ exact min_rec' (fun j => u j ω ∈ s) hk₁_s hk₂_s obtain ⟨k, hk₁, hk₂⟩ := h'' refine le_trans ?_ (hk₁.2.trans (min_le_right _ _)) exact hitting_le_of_mem hk₁.1 (hk₁.2.trans (min_le_left _ _)) hk₂ theorem hitting_le_iff_of_lt [IsWellOrder ι (· < ·)] {m : ι} (i : ι) (hi : i < m) : hitting u s n m ω ≤ i ↔ ∃ j ∈ Set.Icc n i, u j ω ∈ s := by by_cases h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s · rw [hitting_le_iff_of_exists h_exists] · simp_rw [hitting, if_neg h_exists] push_neg at h_exists simp only [not_le.mpr hi, Set.mem_Icc, false_iff_iff, not_exists, not_and, and_imp] exact fun k hkn hki => h_exists k ⟨hkn, hki.trans hi.le⟩ theorem hitting_lt_iff [IsWellOrder ι (· < ·)] {m : ι} (i : ι) (hi : i ≤ m) : hitting u s n m ω < i ↔ ∃ j ∈ Set.Ico n i, u j ω ∈ s := by constructor <;> intro h' · have h : ∃ j ∈ Set.Icc n m, u j ω ∈ s := by by_contra h simp_rw [hitting, if_neg h, ← not_le] at h' exact h' hi exact ⟨hitting u s n m ω, ⟨le_hitting_of_exists h, h'⟩, hitting_mem_set h⟩ · obtain ⟨k, hk₁, hk₂⟩ := h' refine lt_of_le_of_lt ?_ hk₁.2 exact hitting_le_of_mem hk₁.1 (hk₁.2.le.trans hi) hk₂ theorem hitting_eq_hitting_of_exists {m₁ m₂ : ι} (h : m₁ ≤ m₂) (h' : ∃ j ∈ Set.Icc n m₁, u j ω ∈ s) : hitting u s n m₁ ω = hitting u s n m₂ ω := by simp only [hitting, if_pos h'] obtain ⟨j, hj₁, hj₂⟩ := h' rw [if_pos] · refine le_antisymm ?_ (csInf_le_csInf bddBelow_Icc.inter_of_left ⟨j, hj₁, hj₂⟩ (Set.inter_subset_inter_left _ (Set.Icc_subset_Icc_right h))) refine le_csInf ⟨j, Set.Icc_subset_Icc_right h hj₁, hj₂⟩ fun i hi => ?_ by_cases hi' : i ≤ m₁ · exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hi.1.1, hi'⟩, hi.2⟩ · change j ∈ {i | u i ω ∈ s} at hj₂ exact ((csInf_le bddBelow_Icc.inter_of_left ⟨hj₁, hj₂⟩).trans (hj₁.2.trans le_rfl)).trans (le_of_lt (not_le.1 hi')) exact ⟨j, ⟨hj₁.1, hj₁.2.trans h⟩, hj₂⟩ theorem hitting_mono {m₁ m₂ : ι} (hm : m₁ ≤ m₂) : hitting u s n m₁ ω ≤ hitting u s n m₂ ω := by by_cases h : ∃ j ∈ Set.Icc n m₁, u j ω ∈ s · exact (hitting_eq_hitting_of_exists hm h).le · simp_rw [hitting, if_neg h] split_ifs with h' · obtain ⟨j, hj₁, hj₂⟩ := h' refine le_csInf ⟨j, hj₁, hj₂⟩ ?_ by_contra hneg; push_neg at hneg obtain ⟨i, hi₁, hi₂⟩ := hneg exact h ⟨i, ⟨hi₁.1.1, hi₂.le⟩, hi₁.2⟩ · exact hm end Inequalities /-- A discrete hitting time is a stopping time. -/ theorem hitting_isStoppingTime [ConditionallyCompleteLinearOrder ι] [IsWellOrder ι (· < ·)] [Countable ι] [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {f : Filtration ι m} {u : ι → Ω → β} {s : Set β} {n n' : ι} (hu : Adapted f u) (hs : MeasurableSet s) : IsStoppingTime f (hitting u s n n') := by intro i rcases le_or_lt n' i with hi | hi · have h_le : ∀ ω, hitting u s n n' ω ≤ i := fun x => (hitting_le x).trans hi simp [h_le] · have h_set_eq_Union : {ω | hitting u s n n' ω ≤ i} = ⋃ j ∈ Set.Icc n i, u j ⁻¹' s := by ext x rw [Set.mem_setOf_eq, hitting_le_iff_of_lt _ hi] simp only [Set.mem_Icc, exists_prop, Set.mem_iUnion, Set.mem_preimage] rw [h_set_eq_Union] exact MeasurableSet.iUnion fun j => MeasurableSet.iUnion fun hj => f.mono hj.2 _ ((hu j).measurable hs) theorem stoppedValue_hitting_mem [ConditionallyCompleteLinearOrder ι] [IsWellOrder ι (· < ·)] {u : ι → Ω → β} {s : Set β} {n m : ι} {ω : Ω} (h : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : stoppedValue u (hitting u s n m) ω ∈ s := by simp only [stoppedValue, hitting, if_pos h] obtain ⟨j, hj₁, hj₂⟩ := h have : sInf (Set.Icc n m ∩ {i | u i ω ∈ s}) ∈ Set.Icc n m ∩ {i | u i ω ∈ s} := csInf_mem (Set.nonempty_of_mem ⟨hj₁, hj₂⟩) exact this.2 /-- The hitting time of a discrete process with the starting time indexed by a stopping time is a stopping time. -/ theorem isStoppingTime_hitting_isStoppingTime [ConditionallyCompleteLinearOrder ι] [IsWellOrder ι (· < ·)] [Countable ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {N : ι} (hτbdd : ∀ x, τ x ≤ N) {s : Set β} (hs : MeasurableSet s) (hf : Adapted f u) : IsStoppingTime f fun x => hitting u s (τ x) N x := by intro n have h₁ : {x | hitting u s (τ x) N x ≤ n} = (⋃ i ≤ n, {x | τ x = i} ∩ {x | hitting u s i N x ≤ n}) ∪ ⋃ i > n, {x | τ x = i} ∩ {x | hitting u s i N x ≤ n} := by ext x simp [← exists_or, ← or_and_right, le_or_lt] have h₂ : ⋃ i > n, {x | τ x = i} ∩ {x | hitting u s i N x ≤ n} = ∅ := by ext x simp only [gt_iff_lt, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, Set.mem_empty_iff_false, iff_false_iff, not_exists, not_and, not_le] rintro m hm rfl exact lt_of_lt_of_le hm (le_hitting (hτbdd _) _) rw [h₁, h₂, Set.union_empty] exact MeasurableSet.iUnion fun i => MeasurableSet.iUnion fun hi => (f.mono hi _ (hτ.measurableSet_eq i)).inter (hitting_isStoppingTime hf hs n) section CompleteLattice variable [CompleteLattice ι] {u : ι → Ω → β} {s : Set β} {f : Filtration ι m} theorem hitting_eq_sInf (ω : Ω) : hitting u s ⊥ ⊤ ω = sInf {i : ι | u i ω ∈ s} := by simp only [hitting, Set.mem_Icc, bot_le, le_top, and_self_iff, exists_true_left, Set.Icc_bot, Set.Iic_top, Set.univ_inter, ite_eq_left_iff, not_exists] intro h_nmem_s symm rw [sInf_eq_top] simp only [Set.mem_univ, true_and] at h_nmem_s exact fun i hi_mem_s => absurd hi_mem_s (h_nmem_s i) end CompleteLattice section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] [IsWellOrder ι (· < ·)] variable {u : ι → Ω → β} {s : Set β} {f : Filtration ℕ m} theorem hitting_bot_le_iff {i n : ι} {ω : Ω} (hx : ∃ j, j ≤ n ∧ u j ω ∈ s) : hitting u s ⊥ n ω ≤ i ↔ ∃ j ≤ i, u j ω ∈ s := by cases' lt_or_le i n with hi hi · rw [hitting_le_iff_of_lt _ hi] simp · simp only [(hitting_le ω).trans hi, true_iff_iff] obtain ⟨j, hj₁, hj₂⟩ := hx exact ⟨j, hj₁.trans hi, hj₂⟩ end ConditionallyCompleteLinearOrderBot end MeasureTheory
Probability\Process\PartitionFiltration.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.MeasurableSpace.CountablyGenerated import Mathlib.Probability.Process.Filtration /-! # Filtration built from the finite partitions of a countably generated measurable space In a countably generated measurable space `α`, we can build a sequence of finer and finer finite measurable partitions of the space such that the measurable space is generated by the union of all partitions. This sequence of partitions is defined in `MeasureTheory.MeasurableSpace.CountablyGenerated`. Here, we build the filtration of the measurable spaces generated by `countablePartition α n` for all `n : ℕ`, which we call `countableFiltration α`. Since each measurable space in the filtration is finite, we can easily build measurable functions on those spaces. A potential application of `countableFiltration α` is to build a martingale with respect to that filtration and use the martingale convergence theorems to define a measurable function on `α`. ## Main definitions * `ProbabilityTheory.partitionFiltration`: for a sequence of sets `t : ℕ → Set α`, a filtration built from the measurable spaces generated by `memPartition t n` for all `n : ℕ`. * `ProbabilityTheory.countableFiltration`: A filtration built from the measurable spaces generated by `countablePartition α n` for all `n : ℕ`. ## Main statements * `ProbabilityTheory.iSup_partitionFiltration`: `⨆ n, partitionFiltration α n` is the measurable space on `α`. -/ open MeasureTheory MeasurableSpace namespace ProbabilityTheory section MemPartition variable {α : Type*} [m : MeasurableSpace α] {t : ℕ → Set α} /-- A filtration built from the measurable spaces generated by the partitions `memPartition t n` for all `n : ℕ`. -/ def partitionFiltration (ht : ∀ n, MeasurableSet (t n)) : Filtration ℕ m where seq n := generateFrom (memPartition t n) mono' := monotone_nat_of_le_succ (generateFrom_memPartition_le_succ _) le' := generateFrom_memPartition_le ht lemma measurableSet_partitionFiltration_of_mem (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) {s : Set α} (hs : s ∈ memPartition t n) : MeasurableSet[partitionFiltration ht n] s := measurableSet_generateFrom hs lemma measurableSet_partitionFiltration_memPartitionSet (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) (a : α) : MeasurableSet[partitionFiltration ht n] (memPartitionSet t n a) := measurableSet_partitionFiltration_of_mem ht n (memPartitionSet_mem t n a) lemma measurable_memPartitionSet_subtype (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) (m : MeasurableSpace (memPartition t n)) : @Measurable α (memPartition t n) (partitionFiltration ht n) m (fun a ↦ ⟨memPartitionSet t n a, memPartitionSet_mem t n a⟩) := by refine @measurable_to_countable' (memPartition t n) α m _ (partitionFiltration ht n) _ (fun s ↦ ?_) rcases s with ⟨s, hs⟩ suffices MeasurableSet[partitionFiltration ht n] {x | memPartitionSet t n x = s} by convert this ext x simp simp_rw [memPartitionSet_eq_iff _ hs] exact measurableSet_partitionFiltration_of_mem _ _ hs lemma measurable_partitionFiltration_memPartitionSet (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) : Measurable[partitionFiltration ht n] (memPartitionSet t n) := measurable_subtype_coe.comp (measurable_memPartitionSet_subtype ht _ _) lemma measurable_memPartitionSet (ht : ∀ n, MeasurableSet (t n)) (n : ℕ) : Measurable (memPartitionSet t n) := (measurable_partitionFiltration_memPartitionSet ht n).mono ((partitionFiltration ht).le n) le_rfl lemma iSup_partitionFiltration_eq_generateFrom_range (ht : ∀ n, MeasurableSet (t n)) : ⨆ n, partitionFiltration ht n = generateFrom (Set.range t) := by conv_rhs => rw [← generateFrom_iUnion_memPartition t, ← iSup_generateFrom] rfl lemma iSup_partitionFiltration (ht : ∀ n, MeasurableSet (t n)) (ht_range : generateFrom (Set.range t) = m) : ⨆ n, partitionFiltration ht n = m := by rw [iSup_partitionFiltration_eq_generateFrom_range ht, ht_range] end MemPartition section CountableFiltration variable {α : Type*} [MeasurableSpace α] [CountablyGenerated α] /-- A filtration built from the measurable spaces generated by `countablePartition α n` for all `n : ℕ`. -/ def countableFiltration (α : Type*) [m : MeasurableSpace α] [CountablyGenerated α] : Filtration ℕ m where seq n := generateFrom (countablePartition α n) mono' := monotone_nat_of_le_succ (generateFrom_countablePartition_le_succ _) le' := generateFrom_countablePartition_le α lemma measurableSet_countableFiltration_of_mem (n : ℕ) {s : Set α} (hs : s ∈ countablePartition α n) : MeasurableSet[countableFiltration α n] s := measurableSet_generateFrom hs lemma measurableSet_countableFiltration_countablePartitionSet (n : ℕ) (t : α) : MeasurableSet[countableFiltration α n] (countablePartitionSet n t) := measurableSet_countableFiltration_of_mem n (countablePartitionSet_mem n t) lemma measurable_countablePartitionSet_subtype (n : ℕ) (m : MeasurableSpace (countablePartition α n)) : @Measurable α (countablePartition α n) (countableFiltration α n) m (fun a ↦ ⟨countablePartitionSet n a, countablePartitionSet_mem n a⟩) := measurable_memPartitionSet_subtype (measurableSet_enumerateCountable_countableGeneratingSet (α := α)) n m lemma measurable_countableFiltration_countablePartitionSet (α : Type*) [MeasurableSpace α] [CountablyGenerated α] (n : ℕ) : Measurable[countableFiltration α n] (countablePartitionSet n) := measurable_subtype_coe.comp (measurable_countablePartitionSet_subtype _ _) lemma measurable_countablePartitionSet (α : Type*) [MeasurableSpace α] [CountablyGenerated α] (n : ℕ) : Measurable (countablePartitionSet (α := α) n) := (measurable_countableFiltration_countablePartitionSet α n).mono ((countableFiltration α).le n) le_rfl lemma iSup_countableFiltration (α : Type*) [m : MeasurableSpace α] [CountablyGenerated α] : ⨆ n, countableFiltration α n = m := by conv_rhs => rw [← generateFrom_iUnion_countablePartition α, ← iSup_generateFrom] rfl end CountableFiltration end ProbabilityTheory
Probability\Process\Stopping.lean
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memℒp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped process belongs to `ℒp` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) := ∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i} theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] section MeasurableSet section Preorder variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι} protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω ≤ i} := hτ i theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (τ ω) have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i) end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ι] {τ : Ω → ι} {f : Filtration ι m} protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h · simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] · exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hτ.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ rw [Set.iUnion_eq_if] split_ifs with hji · exact f.mono hji.le _ (hτ.measurableSet_le j) · exact @MeasurableSet.empty _ (f i) protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne] rw [this] exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i) protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i < τ ω} := by have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hτ.measurableSet_le i).compl section TopologicalSpace variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] exact isMin_iff_forall_not_lt.mp hi_min (τ ω) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : ∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≤ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ · rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ · obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n)) theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i cases' lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i h_Iio_eq_Iic · rw [← hi'_eq_i] at hi'_lub ⊢ exact hτ.measurableSet_lt_of_isLUB i' hi'_lub · have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i') theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt i).compl theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i) theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω = i} := f.mono hle _ <| hτ.measurableSet_eq i theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω < i} := f.mono hle _ <| hτ.measurableSet_lt i end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by intro i rw [show {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hτ k) end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hτ i).inter (hπ i) protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i := hτ.max (isStoppingTime_const f i) protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => min (τ ω) (π ω) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hτ i).union (hπ i) protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i := hτ.min (isStoppingTime_const f i) theorem add_const [AddGroup ι] [Preorder ι] [CovariantClass ι ι (Function.swap (· + ·)) (· ≤ ·)] [CovariantClass ι ι (· + ·) (· ≤ ·)] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by intro j simp_rw [← le_sub_iff_add_le] exact f.mono (sub_le_self j hi) _ (hτ (j - i)) theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} : IsStoppingTime f fun ω => τ ω + i := by refine isStoppingTime_of_measurableSet_eq fun j => ?_ by_cases hij : i ≤ j · simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm] exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i)) · rw [not_le] at hij convert @MeasurableSet.empty _ (f.1 j) ext ω simp only [Set.mem_empty_iff_false, iff_false_iff, Set.mem_setOf] omega -- generalize to certain countable type? theorem add {f : Filtration ℕ m} {τ π : Ω → ℕ} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f (τ + π) := by intro i rw [(_ : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i})] · exact MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i) ext ω simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_prop] refine ⟨fun h => ⟨π ω, by omega, rfl, h⟩, ?_⟩ rintro ⟨j, hj, rfl, h⟩ assumption section Preorder variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → ι} /-- The associated σ-algebra with a stopping time. -/ protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where MeasurableSet' s := ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) measurableSet_empty i := (Set.empty_inter {ω | τ ω ≤ i}).symm ▸ @MeasurableSet.empty _ (f i) measurableSet_compl s hs i := by rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})] · refine MeasurableSet.inter ?_ ?_ · rw [← Set.compl_inter] exact (hs i).compl · exact hτ i · rw [Set.union_inter_distrib_right] simp only [Set.compl_inter_self, Set.union_empty] measurableSet_iUnion s hs i := by rw [forall_swap] at hs rw [Set.iUnion_inter] exact MeasurableSet.iUnion (hs i) protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) := Iff.rfl theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) : hτ.measurableSpace ≤ hπ.measurableSpace := by intro s hs i rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})] · exact (hs i).inter (hπ i) · ext simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq] intro hle' _ exact le_trans (hle _) hle' theorem measurableSpace_le_of_countable [Countable ι] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.iUnion fun i => f.le i _ (hs i) · ext ω; constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, hx, le_rfl⟩ · rintro ⟨_, hx, _⟩ exact hx theorem measurableSpace_le' [IsCountablyGenerated (atTop : Filter ι)] [(atTop : Filter ι).NeBot] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto rw [(_ : s = ⋃ n, s ∩ {ω | τ ω ≤ seq n})] · exact MeasurableSet.iUnion fun i => f.le (seq i) _ (hs (seq i)) · ext ω; constructor <;> rw [Set.mem_iUnion] · intro hx suffices ∃ i, τ ω ≤ seq i from ⟨this.choose, hx, this.choose_spec⟩ rw [tendsto_atTop] at h_seq_tendsto exact (h_seq_tendsto (τ ω)).exists · rintro ⟨_, hx, _⟩ exact hx theorem measurableSpace_le {ι} [SemilatticeSup ι] {f : Filtration ι m} {τ : Ω → ι} [IsCountablyGenerated (atTop : Filter ι)] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by cases isEmpty_or_nonempty ι · haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩ intro s _ suffices hs : s = ∅ by rw [hs]; exact MeasurableSet.empty haveI : Unique (Set Ω) := Set.uniqueEmpty rw [Unique.eq_default s, Unique.eq_default ∅] exact measurableSpace_le' hτ example {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le example {f : Filtration ℝ m} {τ : Ω → ℝ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le @[simp] theorem measurableSpace_const (f : Filtration ι m) (i : ι) : (isStoppingTime_const f i).measurableSpace = f i := by ext1 s change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s rw [IsStoppingTime.measurableSet] constructor <;> intro h · specialize h i simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h · intro j by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)] theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔ MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by intro j ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] intro hxi rw [hxi] constructor <;> intro h · specialize h i simpa only [Set.inter_assoc, this, le_refl, Set.setOf_true, Set.inter_univ] using h · intro j rw [Set.inter_assoc, this] by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · set_option tactic.skipAssignedInstances false in simp [hij] convert @MeasurableSet.empty _ (Filtration.seq f j) theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : hτ.measurableSpace ≤ f i := (measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : hτ.measurableSpace ≤ m := (hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n) theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) : f i ≤ hτ.measurableSpace := (measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le) end Preorder instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι] [(Filter.atTop : Filter ι).IsCountablyGenerated] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) : SigmaFinite (μ.trim hτ.measurableSpace_le) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by intro j have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by ext1 ω; simp only [Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff] rw [this] exact f.mono (min_le_right i j) _ (hτ _) protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp rw [this] exact (hτ.measurableSet_le' i).compl protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq i protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i) protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i) section Countable protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq_of_countable_range h_countable i protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i) protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i) protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i protected theorem measurableSpace_le_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i ∈ Set.range τ, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.biUnion h_countable fun i _ => f.le i _ (hs i) · ext ω constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, by simpa using hx⟩ · rintro ⟨i, hx⟩ simp only [Set.mem_range, Set.iUnion_exists, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, exists_and_right] at hx exact hx.2.1 end Countable protected theorem measurable [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] τ := @measurable_of_Iic ι Ω _ _ _ hτ.measurableSpace _ _ _ _ fun i => hτ.measurableSet_le' i protected theorem measurable_of_le [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ := hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : (hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by refine le_antisymm ?_ ?_ · exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _) (measurableSpace_mono _ hπ fun _ => min_le_right _ _) · intro s change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s → MeasurableSet[(hτ.min hπ).measurableSpace] s simp_rw [IsStoppingTime.measurableSet] have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by intro i; ext1 ω; simp simp_rw [this, Set.inter_union_distrib_left] exact fun h i => (h.left i).union (h.right i) theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[(hτ.min hπ).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by rw [measurableSpace_min hτ hπ]; rfl theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} : (hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const] theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} : MeasurableSet[(hτ.min_const i).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) : MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by simp_rw [IsStoppingTime.measurableSet] at hs ⊢ intro i have : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩ {ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by ext1 ω simp only [min_le_iff, Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff, le_refl, true_and_iff, and_true_iff, true_or_iff, or_true_iff] by_cases hτi : τ ω ≤ i · simp only [hτi, true_or_iff, and_true_iff, and_congr_right_iff] intro constructor <;> intro h · exact Or.inl h · cases' h with h h · exact h · exact hτi.trans h simp only [hτi, false_or_iff, and_false_iff, false_and_iff, iff_false_iff, not_and, not_le, and_imp] refine fun _ hτ_le_π => lt_of_lt_of_le ?_ hτ_le_π rw [← not_le] exact hτi rw [this] refine ((hs i).inter ((hτ.min hπ) i)).inter ?_ apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _ · exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔ MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by constructor <;> intro h · have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by rw [Set.inter_assoc, Set.inter_self] rw [this] exact measurableSet_inter_le _ hπ _ h · rw [measurableSet_min_iff hτ hπ] at h exact h.1 theorem measurableSet_inter_le_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ i}) ↔ MeasurableSet[(hτ.min_const i).measurableSpace] (s ∩ {ω | τ ω ≤ i}) := by rw [IsStoppingTime.measurableSet_min_iff hτ (isStoppingTime_const _ i), IsStoppingTime.measurableSpace_const, IsStoppingTime.measurableSet] refine ⟨fun h => ⟨h, ?_⟩, fun h j => h.1 j⟩ specialize h i rwa [Set.inter_assoc, Set.inter_self] at h theorem measurableSet_le_stopping_time [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j ≤ min (π ω) j} ∩ {ω | τ ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, min_le_iff, le_min_iff, le_refl, and_true_iff, and_congr_left_iff] intro h simp only [h, or_self_iff, and_true_iff] rw [Iff.comm, or_iff_left_iff_imp] exact h.trans rw [this] refine MeasurableSet.inter ?_ (hτ.measurableSet_le j) apply @measurableSet_le _ _ _ _ _ (Filtration.seq f j) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_stopping_time_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hπ.measurableSpace] {ω | τ ω ≤ π ω} := by suffices MeasurableSet[(hτ.min hπ).measurableSpace] {ω : Ω | τ ω ≤ π ω} by rw [measurableSet_min_iff hτ hπ] at this; exact this.2 rw [← Set.univ_inter {ω : Ω | τ ω ≤ π ω}, ← hτ.measurableSet_inter_le_iff hπ, Set.univ_inter] exact measurableSet_le_stopping_time hτ hπ theorem measurableSet_eq_stopping_time [AddGroup ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] [MeasurableSub₂ ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · cases' h with h' hσ_le cases' h' with h_eq hτ_le rwa [min_eq_left hτ_le, min_eq_left hσ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_eq_stopping_time_of_countable [Countable ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · cases' h with h' hπ_le cases' h' with h_eq hτ_le rwa [min_eq_left hτ_le, min_eq_left hπ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun_of_countable · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ end LinearOrder end IsStoppingTime section LinearOrder /-! ## Stopped value and stopped process -/ /-- Given a map `u : ι → Ω → E`, its stopped value with respect to the stopping time `τ` is the map `x ↦ u (τ ω) ω`. -/ def stoppedValue (u : ι → Ω → β) (τ : Ω → ι) : Ω → β := fun ω => u (τ ω) ω theorem stoppedValue_const (u : ι → Ω → β) (i : ι) : (stoppedValue u fun _ => i) = u i := rfl variable [LinearOrder ι] /-- Given a map `u : ι → Ω → E`, the stopped process with respect to `τ` is `u i ω` if `i ≤ τ ω`, and `u (τ ω) ω` otherwise. Intuitively, the stopped process stops evolving once the stopping time has occured. -/ def stoppedProcess (u : ι → Ω → β) (τ : Ω → ι) : ι → Ω → β := fun i ω => u (min i (τ ω)) ω theorem stoppedProcess_eq_stoppedValue {u : ι → Ω → β} {τ : Ω → ι} : stoppedProcess u τ = fun i => stoppedValue u fun ω => min i (τ ω) := rfl theorem stoppedValue_stoppedProcess {u : ι → Ω → β} {τ σ : Ω → ι} : stoppedValue (stoppedProcess u τ) σ = stoppedValue u fun ω => min (σ ω) (τ ω) := rfl theorem stoppedProcess_eq_of_le {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : i ≤ τ ω) : stoppedProcess u τ i ω = u i ω := by simp [stoppedProcess, min_eq_left h] theorem stoppedProcess_eq_of_ge {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : τ ω ≤ i) : stoppedProcess u τ i ω = u (τ ω) ω := by simp [stoppedProcess, min_eq_right h] section ProgMeasurable variable [MeasurableSpace ι] [TopologicalSpace ι] [OrderTopology ι] [SecondCountableTopology ι] [BorelSpace ι] [TopologicalSpace β] {u : ι → Ω → β} {τ : Ω → ι} {f : Filtration ι m} theorem progMeasurable_min_stopping_time [MetrizableSpace ι] (hτ : IsStoppingTime f τ) : ProgMeasurable f fun i ω => min i (τ ω) := by intro i let m_prod : MeasurableSpace (Set.Iic i × Ω) := Subtype.instMeasurableSpace.prod (f i) let m_set : ∀ t : Set (Set.Iic i × Ω), MeasurableSpace t := fun _ => @Subtype.instMeasurableSpace (Set.Iic i × Ω) _ m_prod let s := {p : Set.Iic i × Ω | τ p.2 ≤ i} have hs : MeasurableSet[m_prod] s := @measurable_snd (Set.Iic i) Ω _ (f i) _ (hτ i) have h_meas_fst : ∀ t : Set (Set.Iic i × Ω), Measurable[m_set t] fun x : t => ((x : Set.Iic i × Ω).fst : ι) := fun t => (@measurable_subtype_coe (Set.Iic i × Ω) m_prod _).fst.subtype_val apply Measurable.stronglyMeasurable refine measurable_of_restrict_of_restrict_compl hs ?_ ?_ · refine @Measurable.min _ _ _ _ _ (m_set s) _ _ _ _ _ (h_meas_fst s) ?_ refine @measurable_of_Iic ι s _ _ _ (m_set s) _ _ _ _ fun j => ?_ have h_set_eq : (fun x : s => τ (x : Set.Iic i × Ω).snd) ⁻¹' Set.Iic j = (fun x : s => (x : Set.Iic i × Ω).snd) ⁻¹' {ω | τ ω ≤ min i j} := by ext1 ω simp only [Set.mem_preimage, Set.mem_Iic, iff_and_self, le_min_iff, Set.mem_setOf_eq] exact fun _ => ω.prop rw [h_set_eq] suffices h_meas : @Measurable _ _ (m_set s) (f i) fun x : s ↦ (x : Set.Iic i × Ω).snd from h_meas (f.mono (min_le_left _ _) _ (hτ.measurableSet_le (min i j))) exact measurable_snd.comp (@measurable_subtype_coe _ m_prod _) · letI sc := sᶜ suffices h_min_eq_left : (fun x : sc => min (↑(x : Set.Iic i × Ω).fst) (τ (x : Set.Iic i × Ω).snd)) = fun x : sc => ↑(x : Set.Iic i × Ω).fst by simp (config := { unfoldPartialApp := true }) only [Set.restrict, h_min_eq_left] exact h_meas_fst _ ext1 ω rw [min_eq_left] have hx_fst_le : ↑(ω : Set.Iic i × Ω).fst ≤ i := (ω : Set.Iic i × Ω).fst.prop refine hx_fst_le.trans (le_of_lt ?_) convert ω.prop simp only [sc, s, not_le, Set.mem_compl_iff, Set.mem_setOf_eq] theorem ProgMeasurable.stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : ProgMeasurable f (stoppedProcess u τ) := h.comp (progMeasurable_min_stopping_time hτ) fun _ _ => min_le_left _ _ theorem ProgMeasurable.adapted_stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (h.stoppedProcess hτ).adapted theorem ProgMeasurable.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : ProgMeasurable f u) (hτ : IsStoppingTime f τ) (i : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ i) := (hu.adapted_stoppedProcess hτ i).mono (f.le _) theorem stronglyMeasurable_stoppedValue_of_le (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : StronglyMeasurable[f n] (stoppedValue u τ) := by have : stoppedValue u τ = (fun p : Set.Iic n × Ω => u (↑p.fst) p.snd) ∘ fun ω => (⟨τ ω, hτ_le ω⟩, ω) := by ext1 ω; simp only [stoppedValue, Function.comp_apply, Subtype.coe_mk] rw [this] refine StronglyMeasurable.comp_measurable (h n) ?_ exact (hτ.measurable_of_le hτ_le).subtype_mk.prod_mk measurable_id theorem measurable_stoppedValue [MetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] (stoppedValue u τ) := by have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i => stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _ intro t ht i suffices stoppedValue u τ ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} = (stoppedValue u fun ω => min (τ ω) i) ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} by rw [this]; exact ((h_str_meas i).measurable ht).inter (hτ.measurableSet_le i) ext1 ω simp only [stoppedValue, Set.mem_inter_iff, Set.mem_preimage, Set.mem_setOf_eq, and_congr_left_iff] intro h rw [min_eq_left h] end ProgMeasurable end LinearOrder section StoppedValueOfMemFinset variable {μ : Measure Ω} {τ σ : Ω → ι} {E : Type*} {p : ℝ≥0∞} {u : ι → Ω → E} theorem stoppedValue_eq_of_mem_finset [AddCommMonoid E] {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : stoppedValue u τ = ∑ i ∈ s, Set.indicator {ω | τ ω = i} (u i) := by ext y rw [stoppedValue, Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] suffices Finset.filter (fun i => y ∈ {ω : Ω | τ ω = i}) s = ({τ y} : Finset ι) by rw [this, Finset.sum_singleton] ext1 ω simp only [Set.mem_setOf_eq, Finset.mem_filter, Finset.mem_singleton] constructor <;> intro h · exact h.2.symm · refine ⟨?_, h.symm⟩; rw [h]; exact hbdd y theorem stoppedValue_eq' [Preorder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = ∑ i ∈ Finset.Iic N, Set.indicator {ω | τ ω = i} (u i) := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_Iic.mpr (hbdd ω) theorem stoppedProcess_eq_of_mem_finset [LinearOrder ι] [AddCommMonoid E] {s : Finset ι} (n : ι) (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ s.filter (· < n), Set.indicator {ω | τ ω = i} (u i) := by ext ω rw [Pi.add_apply, Finset.sum_apply] rcases le_or_lt n (τ ω) with h | h · rw [stoppedProcess_eq_of_le h, Set.indicator_of_mem, Finset.sum_eq_zero, add_zero] · intro m hm refine Set.indicator_of_not_mem ?_ _ rw [Finset.mem_filter] at hm exact (hm.2.trans_le h).ne' · exact h · rw [stoppedProcess_eq_of_ge (le_of_lt h), Finset.sum_eq_single_of_mem (τ ω)] · rw [Set.indicator_of_not_mem, zero_add, Set.indicator_of_mem] <;> rw [Set.mem_setOf] exact not_le.2 h · rw [Finset.mem_filter] exact ⟨hbdd ω h, h⟩ · intro b _ hneq rw [Set.indicator_of_not_mem] rw [Set.mem_setOf] exact hneq.symm theorem stoppedProcess_eq'' [LinearOrder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] (n : ι) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.Iio n, Set.indicator {ω | τ ω = i} (u i) := by have h_mem : ∀ ω, τ ω < n → τ ω ∈ Finset.Iio n := fun ω h => Finset.mem_Iio.mpr h rw [stoppedProcess_eq_of_mem_finset n h_mem] congr with i simp section StoppedValue variable [PartialOrder ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memℒp_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Memℒp (stoppedValue u τ) p μ := by rw [stoppedValue_eq_of_mem_finset hbdd] refine memℒp_finset_sum' _ fun i _ => Memℒp.indicator ?_ (hu i) refine ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq_of_countable_range ?_ i) refine ((Finset.finite_toSet s).subset fun ω hω => ?_).countable obtain ⟨y, rfl⟩ := hω exact hbdd y theorem memℒp_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Memℒp (stoppedValue u τ) p μ := memℒp_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) theorem integrable_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Integrable (stoppedValue u τ) μ := by simp_rw [← memℒp_one_iff_integrable] at hu ⊢ exact memℒp_stoppedValue_of_mem_finset hτ hu hbdd variable (ι) theorem integrable_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Integrable (stoppedValue u τ) μ := integrable_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) end StoppedValue section StoppedProcess variable [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memℒp_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Memℒp (stoppedProcess u τ n) p μ := by rw [stoppedProcess_eq_of_mem_finset n hbdd] refine Memℒp.add ?_ ?_ · exact Memℒp.indicator (ℱ.le n {a : Ω | n ≤ τ a} (hτ.measurableSet_ge n)) (hu n) · suffices Memℒp (fun ω => ∑ i ∈ s.filter (· < n), {a : Ω | τ a = i}.indicator (u i) ω) p μ by convert this using 1; ext1 ω; simp only [Finset.sum_apply] refine memℒp_finset_sum _ fun i _ => Memℒp.indicator ?_ (hu i) exact ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq i) theorem memℒp_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) (n : ι) : Memℒp (stoppedProcess u τ n) p μ := memℒp_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h theorem integrable_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Integrable (stoppedProcess u τ n) μ := by simp_rw [← memℒp_one_iff_integrable] at hu ⊢ exact memℒp_stoppedProcess_of_mem_finset hτ hu n hbdd theorem integrable_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) : Integrable (stoppedProcess u τ n) μ := integrable_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h end StoppedProcess end StoppedValueOfMemFinset section AdaptedStoppedProcess variable [TopologicalSpace β] [PseudoMetrizableSpace β] [LinearOrder ι] [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] {f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι} /-- The stopped process of an adapted process with continuous paths is adapted. -/ theorem Adapted.stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) : Adapted f (stoppedProcess u τ) := ((hu.progMeasurable_of_continuous hu_cont).stoppedProcess hτ).adapted /-- If the indexing order has the discrete topology, then the stopped process of an adapted process is adapted. -/ theorem Adapted.stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (hu.progMeasurable_of_discrete.stoppedProcess hτ).adapted theorem Adapted.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := (hu.progMeasurable_of_continuous hu_cont).stronglyMeasurable_stoppedProcess hτ n theorem Adapted.stronglyMeasurable_stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := hu.progMeasurable_of_discrete.stronglyMeasurable_stoppedProcess hτ n end AdaptedStoppedProcess section Nat /-! ### Filtrations indexed by `ℕ` -/ open Filtration variable {f : Filtration ℕ m} {u : ℕ → Ω → β} {τ π : Ω → ℕ} theorem stoppedValue_sub_eq_sum [AddCommGroup β] (hle : τ ≤ π) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.Ico (τ ω) (π ω), (u (i + 1) - u i)) ω := by ext ω rw [Finset.sum_Ico_eq_sub _ (hle ω), Finset.sum_range_sub, Finset.sum_range_sub] simp [stoppedValue] theorem stoppedValue_sub_eq_sum' [AddCommGroup β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω ≤ i ∧ i < π ω} (u (i + 1) - u i)) ω := by rw [stoppedValue_sub_eq_sum hle] ext ω simp only [Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] refine Finset.sum_congr ?_ fun _ _ => rfl ext i simp only [Finset.mem_filter, Set.mem_setOf_eq, Finset.mem_range, Finset.mem_Ico] exact ⟨fun h => ⟨lt_trans h.2 (Nat.lt_succ_iff.2 <| hbdd _), h⟩, fun h => h.2⟩ section AddCommMonoid variable [AddCommMonoid β] theorem stoppedValue_eq {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = fun x => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω = i} (u i)) x := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_range_succ_iff.mpr (hbdd ω) theorem stoppedProcess_eq (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.range n, Set.indicator {ω | τ ω = i} (u i) := by rw [stoppedProcess_eq'' n] congr with i rw [Finset.mem_Iio, Finset.mem_range] theorem stoppedProcess_eq' (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n + 1 ≤ τ a} (u n) + ∑ i ∈ Finset.range (n + 1), Set.indicator {a | τ a = i} (u i) := by have : {a | n ≤ τ a}.indicator (u n) = {a | n + 1 ≤ τ a}.indicator (u n) + {a | τ a = n}.indicator (u n) := by ext x rw [add_comm, Pi.add_apply, ← Set.indicator_union_of_not_mem_inter] · simp_rw [@eq_comm _ _ n, @le_iff_eq_or_lt _ _ n, Nat.succ_le_iff, Set.setOf_or] · rintro ⟨h₁, h₂⟩ rw [Set.mem_setOf] at h₁ h₂ exact (Nat.succ_le_iff.1 h₂).ne h₁.symm rw [stoppedProcess_eq, this, Finset.sum_range_succ_comm, ← add_assoc] end AddCommMonoid end Nat section PiecewiseConst variable [Preorder ι] {𝒢 : Filtration ι m} {τ η : Ω → ι} {i j : ι} {s : Set Ω} [DecidablePred (· ∈ s)] /-- Given stopping times `τ` and `η` which are bounded below, `Set.piecewise s τ η` is also a stopping time with respect to the same filtration. -/ theorem IsStoppingTime.piecewise_of_le (hτ_st : IsStoppingTime 𝒢 τ) (hη_st : IsStoppingTime 𝒢 η) (hτ : ∀ ω, i ≤ τ ω) (hη : ∀ ω, i ≤ η ω) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise τ η) := by intro n have : {ω | s.piecewise τ η ω ≤ n} = s ∩ {ω | τ ω ≤ n} ∪ sᶜ ∩ {ω | η ω ≤ n} := by ext1 ω simp only [Set.piecewise, Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] by_cases hx : ω ∈ s <;> simp [hx] rw [this] by_cases hin : i ≤ n · have hs_n : MeasurableSet[𝒢 n] s := 𝒢.mono hin _ hs exact (hs_n.inter (hτ_st n)).union (hs_n.compl.inter (hη_st n)) · have hτn : ∀ ω, ¬τ ω ≤ n := fun ω hτn => hin ((hτ ω).trans hτn) have hηn : ∀ ω, ¬η ω ≤ n := fun ω hηn => hin ((hη ω).trans hηn) simp [hτn, hηn, @MeasurableSet.empty _ _] theorem isStoppingTime_piecewise_const (hij : i ≤ j) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise (fun _ => i) fun _ => j) := (isStoppingTime_const 𝒢 i).piecewise_of_le (isStoppingTime_const 𝒢 j) (fun _ => le_rfl) (fun _ => hij) hs theorem stoppedValue_piecewise_const {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.piecewise (f i) (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] theorem stoppedValue_piecewise_const' {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.indicator (f i) + sᶜ.indicator (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] end PiecewiseConst section Condexp /-! ### Conditional expectation with respect to the σ-algebra generated by a stopping time -/ variable [LinearOrder ι] {μ : Measure Ω} {ℱ : Filtration ι m} {τ σ : Ω → ι} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : Ω → E} theorem condexp_stopping_time_ae_eq_restrict_eq_of_countable_range [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) (h_countable : (Set.range τ).Countable) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_countable_range h_countable))] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by refine condexp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_countable_range h_countable) (ℱ.le i) (hτ.measurableSet_eq_of_countable_range' h_countable i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] theorem condexp_stopping_time_ae_eq_restrict_eq_of_countable [Countable ι] [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le_of_countable)] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := condexp_stopping_time_ae_eq_restrict_eq_of_countable_range hτ (Set.to_countable _) i variable [(Filter.atTop : Filter ι).IsCountablyGenerated] theorem condexp_min_stopping_time_ae_eq_restrict_le_const (hτ : IsStoppingTime ℱ τ) (i : ι) [SigmaFinite (μ.trim (hτ.min_const i).measurableSpace_le)] : μ[f|(hτ.min_const i).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ i}] μ[f|hτ.measurableSpace] := by have : SigmaFinite (μ.trim hτ.measurableSpace_le) := haveI h_le : (hτ.min_const i).measurableSpace ≤ hτ.measurableSpace := by rw [IsStoppingTime.measurableSpace_min_const] exact inf_le_left sigmaFiniteTrim_mono _ h_le refine (condexp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (hτ.min_const i).measurableSpace_le (hτ.measurableSet_le' i) fun t => ?_).symm rw [Set.inter_comm _ t, hτ.measurableSet_inter_le_const_iff] variable [TopologicalSpace ι] [OrderTopology ι] theorem condexp_stopping_time_ae_eq_restrict_eq [FirstCountableTopology ι] [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le)] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by refine condexp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (ℱ.le i) (hτ.measurableSet_eq' i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] theorem condexp_min_stopping_time_ae_eq_restrict_le [MeasurableSpace ι] [SecondCountableTopology ι] [BorelSpace ι] (hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) [SigmaFinite (μ.trim (hτ.min hσ).measurableSpace_le)] : μ[f|(hτ.min hσ).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ σ x}] μ[f|hτ.measurableSpace] := by have : SigmaFinite (μ.trim hτ.measurableSpace_le) := haveI h_le : (hτ.min hσ).measurableSpace ≤ hτ.measurableSpace := by rw [IsStoppingTime.measurableSpace_min] · exact inf_le_left · simp_all only sigmaFiniteTrim_mono _ h_le refine (condexp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (hτ.min hσ).measurableSpace_le (hτ.measurableSet_le_stopping_time hσ) fun t => ?_).symm rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_le_iff]; simp_all only end Condexp end MeasureTheory
RepresentationTheory\Basic.lean
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.Algebra.Group.Equiv.TypeTags import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.LinearAlgebra.Dual import Mathlib.LinearAlgebra.Contraction import Mathlib.RingTheory.TensorProduct.Basic /-! # Monoid representations This file introduces monoid representations and their characters and defines a few ways to construct representations. ## Main definitions * Representation.Representation * Representation.character * Representation.tprod * Representation.linHom * Representation.dual ## Implementation notes Representations of a monoid `G` on a `k`-module `V` are implemented as homomorphisms `G →* (V →ₗ[k] V)`. We use the abbreviation `Representation` for this hom space. The theorem `asAlgebraHom_def` constructs a module over the group `k`-algebra of `G` (implemented as `MonoidAlgebra k G`) corresponding to a representation. If `ρ : Representation k G V`, this module can be accessed via `ρ.asModule`. Conversely, given a `MonoidAlgebra k G-module `M` `M.ofModule` is the associociated representation seen as a homomorphism. -/ open MonoidAlgebra (lift of) open LinearMap section variable (k G V : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] /-- A representation of `G` on the `k`-module `V` is a homomorphism `G →* (V →ₗ[k] V)`. -/ abbrev Representation := G →* V →ₗ[k] V end namespace Representation section trivial variable (k : Type*) {G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] /-- The trivial representation of `G` on a `k`-module V. -/ def trivial : Representation k G V := 1 -- Porting note: why is `V` implicit theorem trivial_def (g : G) (v : V) : trivial k (V := V) g v = v := rfl variable {k} /-- A predicate for representations that fix every element. -/ class IsTrivial (ρ : Representation k G V) : Prop where out : ∀ g x, ρ g x = x := by aesop instance : IsTrivial (trivial k (G := G) (V := V)) where @[simp] theorem apply_eq_self (ρ : Representation k G V) (g : G) (x : V) [h : IsTrivial ρ] : ρ g x = x := h.out g x end trivial section MonoidAlgebra variable {k G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] variable (ρ : Representation k G V) /-- A `k`-linear representation of `G` on `V` can be thought of as an algebra map from `MonoidAlgebra k G` into the `k`-linear endomorphisms of `V`. -/ noncomputable def asAlgebraHom : MonoidAlgebra k G →ₐ[k] Module.End k V := (lift k G _) ρ theorem asAlgebraHom_def : asAlgebraHom ρ = (lift k G _) ρ := rfl @[simp] theorem asAlgebraHom_single (g : G) (r : k) : asAlgebraHom ρ (Finsupp.single g r) = r • ρ g := by simp only [asAlgebraHom_def, MonoidAlgebra.lift_single] theorem asAlgebraHom_single_one (g : G) : asAlgebraHom ρ (Finsupp.single g 1) = ρ g := by simp theorem asAlgebraHom_of (g : G) : asAlgebraHom ρ (of k G g) = ρ g := by simp only [MonoidAlgebra.of_apply, asAlgebraHom_single, one_smul] /-- If `ρ : Representation k G V`, then `ρ.asModule` is a type synonym for `V`, which we equip with an instance `Module (MonoidAlgebra k G) ρ.asModule`. You should use `asModuleEquiv : ρ.asModule ≃+ V` to translate terms. -/ @[nolint unusedArguments] def asModule (_ : Representation k G V) := V -- Porting note: no derive handler instance : AddCommMonoid (ρ.asModule) := inferInstanceAs <| AddCommMonoid V instance : Inhabited ρ.asModule where default := 0 /-- A `k`-linear representation of `G` on `V` can be thought of as a module over `MonoidAlgebra k G`. -/ noncomputable instance asModuleModule : Module (MonoidAlgebra k G) ρ.asModule := Module.compHom V (asAlgebraHom ρ).toRingHom -- Porting note: ρ.asModule doesn't unfold now instance : Module k ρ.asModule := inferInstanceAs <| Module k V /-- The additive equivalence from the `Module (MonoidAlgebra k G)` to the original vector space of the representative. This is just the identity, but it is helpful for typechecking and keeping track of instances. -/ def asModuleEquiv : ρ.asModule ≃+ V := AddEquiv.refl _ @[simp] theorem asModuleEquiv_map_smul (r : MonoidAlgebra k G) (x : ρ.asModule) : ρ.asModuleEquiv (r • x) = ρ.asAlgebraHom r (ρ.asModuleEquiv x) := rfl @[simp] theorem asModuleEquiv_symm_map_smul (r : k) (x : V) : ρ.asModuleEquiv.symm (r • x) = algebraMap k (MonoidAlgebra k G) r • ρ.asModuleEquiv.symm x := by apply_fun ρ.asModuleEquiv simp @[simp] theorem asModuleEquiv_symm_map_rho (g : G) (x : V) : ρ.asModuleEquiv.symm (ρ g x) = MonoidAlgebra.of k G g • ρ.asModuleEquiv.symm x := by apply_fun ρ.asModuleEquiv simp /-- Build a `Representation k G M` from a `[Module (MonoidAlgebra k G) M]`. This version is not always what we want, as it relies on an existing `[Module k M]` instance, along with a `[IsScalarTower k (MonoidAlgebra k G) M]` instance. We remedy this below in `ofModule` (with the tradeoff that the representation is defined only on a type synonym of the original module.) -/ noncomputable def ofModule' (M : Type*) [AddCommMonoid M] [Module k M] [Module (MonoidAlgebra k G) M] [IsScalarTower k (MonoidAlgebra k G) M] : Representation k G M := (MonoidAlgebra.lift k G (M →ₗ[k] M)).symm (Algebra.lsmul k k M) section variable (M : Type*) [AddCommMonoid M] [Module (MonoidAlgebra k G) M] /-- Build a `Representation` from a `[Module (MonoidAlgebra k G) M]`. Note that the representation is built on `restrictScalars k (MonoidAlgebra k G) M`, rather than on `M` itself. -/ noncomputable def ofModule : Representation k G (RestrictScalars k (MonoidAlgebra k G) M) := (MonoidAlgebra.lift k G (RestrictScalars k (MonoidAlgebra k G) M →ₗ[k] RestrictScalars k (MonoidAlgebra k G) M)).symm (RestrictScalars.lsmul k (MonoidAlgebra k G) M) /-! ## `ofModule` and `asModule` are inverses. This requires a little care in both directions: this is a categorical equivalence, not an isomorphism. See `Rep.equivalenceModuleMonoidAlgebra` for the full statement. Starting with `ρ : Representation k G V`, converting to a module and back again we have a `Representation k G (restrictScalars k (MonoidAlgebra k G) ρ.asModule)`. To compare these, we use the composition of `restrictScalarsAddEquiv` and `ρ.asModuleEquiv`. Similarly, starting with `Module (MonoidAlgebra k G) M`, after we convert to a representation and back to a module, we have `Module (MonoidAlgebra k G) (restrictScalars k (MonoidAlgebra k G) M)`. -/ @[simp] theorem ofModule_asAlgebraHom_apply_apply (r : MonoidAlgebra k G) (m : RestrictScalars k (MonoidAlgebra k G) M) : ((ofModule M).asAlgebraHom r) m = (RestrictScalars.addEquiv _ _ _).symm (r • RestrictScalars.addEquiv _ _ _ m) := by apply MonoidAlgebra.induction_on r · intro g simp only [one_smul, MonoidAlgebra.lift_symm_apply, MonoidAlgebra.of_apply, Representation.asAlgebraHom_single, Representation.ofModule, AddEquiv.apply_eq_iff_eq, RestrictScalars.lsmul_apply_apply] · intro f g fw gw simp only [fw, gw, map_add, add_smul, LinearMap.add_apply] · intro r f w simp only [w, map_smul, LinearMap.smul_apply, RestrictScalars.addEquiv_symm_map_smul_smul] @[simp] theorem ofModule_asModule_act (g : G) (x : RestrictScalars k (MonoidAlgebra k G) ρ.asModule) : ofModule (k := k) (G := G) ρ.asModule g x = -- Porting note: more help with implicit (RestrictScalars.addEquiv _ _ _).symm (ρ.asModuleEquiv.symm (ρ g (ρ.asModuleEquiv (RestrictScalars.addEquiv _ _ _ x)))) := by apply_fun RestrictScalars.addEquiv _ _ ρ.asModule using (RestrictScalars.addEquiv _ _ ρ.asModule).injective dsimp [ofModule, RestrictScalars.lsmul_apply_apply] simp theorem smul_ofModule_asModule (r : MonoidAlgebra k G) (m : (ofModule M).asModule) : (RestrictScalars.addEquiv k _ _) ((ofModule M).asModuleEquiv (r • m)) = r • (RestrictScalars.addEquiv k _ _) ((ofModule M).asModuleEquiv (G := G) m) := by dsimp simp only [AddEquiv.apply_symm_apply, ofModule_asAlgebraHom_apply_apply] end end MonoidAlgebra section AddCommGroup variable {k G V : Type*} [CommRing k] [Monoid G] [I : AddCommGroup V] [Module k V] variable (ρ : Representation k G V) instance : AddCommGroup ρ.asModule := I end AddCommGroup section MulAction variable (k : Type*) [CommSemiring k] (G : Type*) [Monoid G] (H : Type*) [MulAction G H] /-- A `G`-action on `H` induces a representation `G →* End(k[H])` in the natural way. -/ noncomputable def ofMulAction : Representation k G (H →₀ k) where toFun g := Finsupp.lmapDomain k k (g • ·) map_one' := by ext x y dsimp simp map_mul' x y := by ext z w simp [mul_smul] variable {k G H} theorem ofMulAction_def (g : G) : ofMulAction k G H g = Finsupp.lmapDomain k k (g • ·) := rfl theorem ofMulAction_single (g : G) (x : H) (r : k) : ofMulAction k G H g (Finsupp.single x r) = Finsupp.single (g • x) r := Finsupp.mapDomain_single end MulAction section DistribMulAction variable (k G A : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid A] [Module k A] [DistribMulAction G A] [SMulCommClass G k A] /-- Turns a `k`-module `A` with a compatible `DistribMulAction` of a monoid `G` into a `k`-linear `G`-representation on `A`. -/ def ofDistribMulAction : Representation k G A where toFun := fun m => { DistribMulAction.toAddMonoidEnd G A m with map_smul' := smul_comm _ } map_one' := by ext; exact one_smul _ _ map_mul' := by intros; ext; exact mul_smul _ _ _ variable {k G A} @[simp] theorem ofDistribMulAction_apply_apply (g : G) (a : A) : ofDistribMulAction k G A g a = g • a := rfl end DistribMulAction section MulDistribMulAction variable (M G : Type*) [Monoid M] [CommGroup G] [MulDistribMulAction M G] /-- Turns a `CommGroup` `G` with a `MulDistribMulAction` of a monoid `M` into a `ℤ`-linear `M`-representation on `Additive G`. -/ def ofMulDistribMulAction : Representation ℤ M (Additive G) := (addMonoidEndRingEquivInt (Additive G) : AddMonoid.End (Additive G) →* _).comp ((monoidEndToAdditive G : _ →* _).comp (MulDistribMulAction.toMonoidEnd M G)) @[simp] theorem ofMulDistribMulAction_apply_apply (g : M) (a : Additive G) : ofMulDistribMulAction M G g a = Additive.ofMul (g • Additive.toMul a) := rfl end MulDistribMulAction section Group variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V] variable (ρ : Representation k G V) @[simp] theorem ofMulAction_apply {H : Type*} [MulAction G H] (g : G) (f : H →₀ k) (h : H) : ofMulAction k G H g f h = f (g⁻¹ • h) := by conv_lhs => rw [← smul_inv_smul g h] let h' := g⁻¹ • h change ofMulAction k G H g f (g • h') = f h' have hg : Function.Injective (g • · : H → H) := by intro h₁ h₂ simp simp only [ofMulAction_def, Finsupp.lmapDomain_apply, Finsupp.mapDomain_apply, hg] -- Porting note: did not need this in ML3; noncomputable because IR check complains noncomputable instance : HMul (MonoidAlgebra k G) ((ofMulAction k G G).asModule) (MonoidAlgebra k G) := inferInstanceAs <| HMul (MonoidAlgebra k G) (MonoidAlgebra k G) (MonoidAlgebra k G) theorem ofMulAction_self_smul_eq_mul (x : MonoidAlgebra k G) (y : (ofMulAction k G G).asModule) : x • y = (x * y : MonoidAlgebra k G) := -- by -- Porting note: trouble figuring out the motive x.induction_on (p := fun z => z • y = z * y) (fun g => by show asAlgebraHom (ofMulAction k G G) _ _ = _; ext simp only [MonoidAlgebra.of_apply, asAlgebraHom_single, one_smul, ofMulAction_apply, smul_eq_mul] -- Porting note: single_mul_apply not firing in simp rw [MonoidAlgebra.single_mul_apply, one_mul] ) (fun x y hx hy => by simp only [hx, hy, add_mul, add_smul]) fun r x hx => by show asAlgebraHom (ofMulAction k G G) _ _ = _ -- Porting note: was simpa [← hx] simp only [map_smul, smul_apply, Algebra.smul_mul_assoc] rw [← hx] rfl /-- If we equip `k[G]` with the `k`-linear `G`-representation induced by the left regular action of `G` on itself, the resulting object is isomorphic as a `k[G]`-module to `k[G]` with its natural `k[G]`-module structure. -/ @[simps] noncomputable def ofMulActionSelfAsModuleEquiv : (ofMulAction k G G).asModule ≃ₗ[MonoidAlgebra k G] MonoidAlgebra k G := { asModuleEquiv _ with map_smul' := ofMulAction_self_smul_eq_mul } /-- When `G` is a group, a `k`-linear representation of `G` on `V` can be thought of as a group homomorphism from `G` into the invertible `k`-linear endomorphisms of `V`. -/ def asGroupHom : G →* Units (V →ₗ[k] V) := MonoidHom.toHomUnits ρ theorem asGroupHom_apply (g : G) : ↑(asGroupHom ρ g) = ρ g := by simp only [asGroupHom, MonoidHom.coe_toHomUnits] end Group section TensorProduct variable {k G V W : Type*} [CommSemiring k] [Monoid G] variable [AddCommMonoid V] [Module k V] [AddCommMonoid W] [Module k W] variable (ρV : Representation k G V) (ρW : Representation k G W) open TensorProduct /-- Given representations of `G` on `V` and `W`, there is a natural representation of `G` on their tensor product `V ⊗[k] W`. -/ noncomputable def tprod : Representation k G (V ⊗[k] W) where toFun g := TensorProduct.map (ρV g) (ρW g) map_one' := by simp only [_root_.map_one, TensorProduct.map_one] map_mul' g h := by simp only [_root_.map_mul, TensorProduct.map_mul] local notation ρV " ⊗ " ρW => tprod ρV ρW @[simp] theorem tprod_apply (g : G) : (ρV ⊗ ρW) g = TensorProduct.map (ρV g) (ρW g) := rfl theorem smul_tprod_one_asModule (r : MonoidAlgebra k G) (x : V) (y : W) : -- Porting note: required to since Lean 4 doesn't unfold asModule let x' : ρV.asModule := x let z : (ρV.tprod 1).asModule := x ⊗ₜ y r • z = (r • x') ⊗ₜ y := by show asAlgebraHom (ρV ⊗ 1) _ _ = asAlgebraHom ρV _ _ ⊗ₜ _ simp only [asAlgebraHom_def, MonoidAlgebra.lift_apply, tprod_apply, MonoidHom.one_apply, LinearMap.finsupp_sum_apply, LinearMap.smul_apply, TensorProduct.map_tmul, LinearMap.one_apply] simp only [Finsupp.sum, TensorProduct.sum_tmul] rfl theorem smul_one_tprod_asModule (r : MonoidAlgebra k G) (x : V) (y : W) : -- Porting note: required to since Lean 4 doesn't unfold asModule let y' : ρW.asModule := y let z : (1 ⊗ ρW).asModule := x ⊗ₜ y r • z = x ⊗ₜ (r • y') := by show asAlgebraHom (1 ⊗ ρW) _ _ = _ ⊗ₜ asAlgebraHom ρW _ _ simp only [asAlgebraHom_def, MonoidAlgebra.lift_apply, tprod_apply, MonoidHom.one_apply, LinearMap.finsupp_sum_apply, LinearMap.smul_apply, TensorProduct.map_tmul, LinearMap.one_apply] simp only [Finsupp.sum, TensorProduct.tmul_sum, TensorProduct.tmul_smul] end TensorProduct section LinearHom variable {k G V W : Type*} [CommSemiring k] [Group G] variable [AddCommMonoid V] [Module k V] [AddCommMonoid W] [Module k W] variable (ρV : Representation k G V) (ρW : Representation k G W) /-- Given representations of `G` on `V` and `W`, there is a natural representation of `G` on the module `V →ₗ[k] W`, where `G` acts by conjugation. -/ def linHom : Representation k G (V →ₗ[k] W) where toFun g := { toFun := fun f => ρW g ∘ₗ f ∘ₗ ρV g⁻¹ map_add' := fun f₁ f₂ => by simp_rw [add_comp, comp_add] map_smul' := fun r f => by simp_rw [RingHom.id_apply, smul_comp, comp_smul] } map_one' := LinearMap.ext fun x => by dsimp -- Porting note (#11227):now needed simp_rw [inv_one, map_one, one_eq_id, comp_id, id_comp] map_mul' g h := LinearMap.ext fun x => by dsimp -- Porting note (#11227):now needed simp_rw [mul_inv_rev, map_mul, mul_eq_comp, comp_assoc] @[simp] theorem linHom_apply (g : G) (f : V →ₗ[k] W) : (linHom ρV ρW) g f = ρW g ∘ₗ f ∘ₗ ρV g⁻¹ := rfl /-- The dual of a representation `ρ` of `G` on a module `V`, given by `(dual ρ) g f = f ∘ₗ (ρ g⁻¹)`, where `f : Module.Dual k V`. -/ def dual : Representation k G (Module.Dual k V) where toFun g := { toFun := fun f => f ∘ₗ ρV g⁻¹ map_add' := fun f₁ f₂ => by simp only [add_comp] map_smul' := fun r f => by ext simp only [coe_comp, Function.comp_apply, smul_apply, RingHom.id_apply] } map_one' := by ext dsimp -- Porting note (#11227):now needed simp only [coe_comp, Function.comp_apply, map_one, inv_one, coe_mk, one_apply] map_mul' g h := by ext dsimp -- Porting note (#11227):now needed simp only [coe_comp, Function.comp_apply, mul_inv_rev, map_mul, coe_mk, mul_apply] @[simp] theorem dual_apply (g : G) : (dual ρV) g = Module.Dual.transpose (R := k) (ρV g⁻¹) := rfl /-- Given $k$-modules $V, W$, there is a homomorphism $φ : V^* ⊗ W → Hom_k(V, W)$ (implemented by `LinearAlgebra.Contraction.dualTensorHom`). Given representations of $G$ on $V$ and $W$,there are representations of $G$ on $V^* ⊗ W$ and on $Hom_k(V, W)$. This lemma says that $φ$ is $G$-linear. -/ theorem dualTensorHom_comm (g : G) : dualTensorHom k V W ∘ₗ TensorProduct.map (ρV.dual g) (ρW g) = (linHom ρV ρW) g ∘ₗ dualTensorHom k V W := by ext; simp [Module.Dual.transpose_apply] end LinearHom end Representation
RepresentationTheory\Character.lean
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.RepresentationTheory.FDRep import Mathlib.LinearAlgebra.Trace import Mathlib.RepresentationTheory.Invariants /-! # Characters of representations This file introduces characters of representation and proves basic lemmas about how characters behave under various operations on representations. A key result is the orthogonality of characters for irreducible representations of finite group over an algebraically closed field whose characteristic doesn't divide the order of the group. It is the theorem `char_orthonormal` ## Implementation notes Irreducible representations are implemented categorically, using the `Simple` class defined in `Mathlib.CategoryTheory.Simple` ## TODO * Once we have the monoidal closed structure on `FdRep k G` and a better API for the rigid structure, `char_dual` and `char_linHom` should probably be stated in terms of `Vᘁ` and `ihom V W`. -/ noncomputable section universe u open CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation FiniteDimensional variable {k : Type u} [Field k] namespace FDRep section Monoid variable {G : Type u} [Monoid G] /-- The character of a representation `V : FDRep k G` is the function associating to `g : G` the trace of the linear map `V.ρ g`. -/ def character (V : FDRep k G) (g : G) := LinearMap.trace k V (V.ρ g) theorem char_mul_comm (V : FDRep k G) (g : G) (h : G) : V.character (h * g) = V.character (g * h) := by simp only [trace_mul_comm, character, map_mul] @[simp] theorem char_one (V : FDRep k G) : V.character 1 = FiniteDimensional.finrank k V := by simp only [character, map_one, trace_one] /-- The character is multiplicative under the tensor product. -/ theorem char_tensor (V W : FDRep k G) : (V ⊗ W).character = V.character * W.character := by ext g; convert trace_tensorProduct' (V.ρ g) (W.ρ g) -- Porting note: adding variant of `char_tensor` to make the simp-set confluent @[simp] theorem char_tensor' (V W : FDRep k G) : character (Action.FunctorCategoryEquivalence.inverse.obj (Action.FunctorCategoryEquivalence.functor.obj V ⊗ Action.FunctorCategoryEquivalence.functor.obj W)) = V.character * W.character := by simp [← char_tensor] /-- The character of isomorphic representations is the same. -/ theorem char_iso {V W : FDRep k G} (i : V ≅ W) : V.character = W.character := by ext g simp only [character, FDRep.Iso.conj_ρ i] exact (trace_conj' (V.ρ g) _).symm end Monoid section Group variable {G : Type u} [Group G] /-- The character of a representation is constant on conjugacy classes. -/ @[simp] theorem char_conj (V : FDRep k G) (g : G) (h : G) : V.character (h * g * h⁻¹) = V.character g := by rw [char_mul_comm, inv_mul_cancel_left] @[simp] theorem char_dual (V : FDRep k G) (g : G) : (of (dual V.ρ)).character g = V.character g⁻¹ := trace_transpose' (V.ρ g⁻¹) @[simp] theorem char_linHom (V W : FDRep k G) (g : G) : (of (linHom V.ρ W.ρ)).character g = V.character g⁻¹ * W.character g := by rw [← char_iso (dualTensorIsoLinHom _ _), char_tensor, Pi.mul_apply, char_dual] variable [Fintype G] [Invertible (Fintype.card G : k)] theorem average_char_eq_finrank_invariants (V : FDRep k G) : ⅟ (Fintype.card G : k) • ∑ g : G, V.character g = finrank k (invariants V.ρ) := by erw [← (isProj_averageMap V.ρ).trace] -- Porting note: Changed `rw` to `erw` simp [character, GroupAlgebra.average, _root_.map_sum] end Group section Orthogonality variable {G : Grp.{u}} [IsAlgClosed k] open scoped Classical variable [Fintype G] [Invertible (Fintype.card G : k)] /-- Orthogonality of characters for irreducible representations of finite group over an algebraically closed field whose characteristic doesn't divide the order of the group. -/ theorem char_orthonormal (V W : FDRep k G) [Simple V] [Simple W] : ⅟ (Fintype.card G : k) • ∑ g : G, V.character g * W.character g⁻¹ = if Nonempty (V ≅ W) then ↑1 else ↑0 := by -- First, we can rewrite the summand `V.character g * W.character g⁻¹` as the character -- of the representation `V ⊗ W* ≅ Hom(W, V)` applied to `g`. -- Porting note: Originally `conv in V.character _ * W.character _ =>` conv_lhs => enter [2, 2, g] rw [mul_comm, ← char_dual, ← Pi.mul_apply, ← char_tensor] rw [char_iso (FDRep.dualTensorIsoLinHom W.ρ V)] -- The average over the group of the character of a representation equals the dimension of the -- space of invariants. rw [average_char_eq_finrank_invariants] rw [show (of (linHom W.ρ V.ρ)).ρ = linHom W.ρ V.ρ from FDRep.of_ρ (linHom W.ρ V.ρ)] -- The space of invariants of `Hom(W, V)` is the subspace of `G`-equivariant linear maps, -- `Hom_G(W, V)`. erw [(linHom.invariantsEquivFDRepHom W V).finrank_eq] -- Porting note: Changed `rw` to `erw` -- By Schur's Lemma, the dimension of `Hom_G(W, V)` is `1` is `V ≅ W` and `0` otherwise. rw_mod_cast [finrank_hom_simple_simple W V, Iso.nonempty_iso_symm] end Orthogonality end FDRep
RepresentationTheory\FDRep.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.RepresentationTheory.Rep import Mathlib.Algebra.Category.FGModuleCat.Limits import Mathlib.CategoryTheory.Preadditive.Schur import Mathlib.RepresentationTheory.Basic /-! # `FDRep k G` is the category of finite dimensional `k`-linear representations of `G`. If `V : FDRep k G`, there is a coercion that allows you to treat `V` as a type, and this type comes equipped with `Module k V` and `FiniteDimensional k V` instances. Also `V.ρ` gives the homomorphism `G →* (V →ₗ[k] V)`. Conversely, given a homomorphism `ρ : G →* (V →ₗ[k] V)`, you can construct the bundled representation as `Rep.of ρ`. We prove Schur's Lemma: the dimension of the `Hom`-space between two irreducible representation is `0` if they are not isomorphic, and `1` if they are. This is the content of `finrank_hom_simple_simple` We verify that `FDRep k G` is a `k`-linear monoidal category, and rigid when `G` is a group. `FDRep k G` has all finite limits. ## TODO * `FDRep k G ≌ FullSubcategory (FiniteDimensional k)` * Upgrade the right rigid structure to a rigid structure (this just needs to be done for `FGModuleCat`). * `FDRep k G` has all finite colimits. * `FDRep k G` is abelian. * `FDRep k G ≌ FGModuleCat (MonoidAlgebra k G)`. -/ suppress_compilation universe u open CategoryTheory open CategoryTheory.Limits /-- The category of finite dimensional `k`-linear representations of a monoid `G`. -/ abbrev FDRep (k G : Type u) [Field k] [Monoid G] := Action (FGModuleCat.{u} k) (MonCat.of G) @[deprecated (since := "2024-07-05")] alias FdRep := FDRep namespace FDRep variable {k G : Type u} [Field k] [Monoid G] -- Porting note: `@[derive]` didn't work for `FDRep`. Add the 4 instances here. instance : LargeCategory (FDRep k G) := inferInstance instance : ConcreteCategory (FDRep k G) := inferInstance instance : Preadditive (FDRep k G) := inferInstance instance : HasFiniteLimits (FDRep k G) := inferInstance instance : Linear k (FDRep k G) := by infer_instance instance : CoeSort (FDRep k G) (Type u) := ConcreteCategory.hasCoeToSort _ instance (V : FDRep k G) : AddCommGroup V := by change AddCommGroup ((forget₂ (FDRep k G) (FGModuleCat k)).obj V).obj; infer_instance instance (V : FDRep k G) : Module k V := by change Module k ((forget₂ (FDRep k G) (FGModuleCat k)).obj V).obj; infer_instance instance (V : FDRep k G) : FiniteDimensional k V := by change FiniteDimensional k ((forget₂ (FDRep k G) (FGModuleCat k)).obj V); infer_instance /-- All hom spaces are finite dimensional. -/ instance (V W : FDRep k G) : FiniteDimensional k (V ⟶ W) := FiniteDimensional.of_injective ((forget₂ (FDRep k G) (FGModuleCat k)).mapLinearMap k) (Functor.map_injective (forget₂ (FDRep k G) (FGModuleCat k))) /-- The monoid homomorphism corresponding to the action of `G` onto `V : FDRep k G`. -/ def ρ (V : FDRep k G) : G →* V →ₗ[k] V := Action.ρ V /-- The underlying `LinearEquiv` of an isomorphism of representations. -/ def isoToLinearEquiv {V W : FDRep k G} (i : V ≅ W) : V ≃ₗ[k] W := FGModuleCat.isoToLinearEquiv ((Action.forget (FGModuleCat k) (MonCat.of G)).mapIso i) theorem Iso.conj_ρ {V W : FDRep k G} (i : V ≅ W) (g : G) : W.ρ g = (FDRep.isoToLinearEquiv i).conj (V.ρ g) := by -- Porting note: Changed `rw` to `erw` erw [FDRep.isoToLinearEquiv, ← FGModuleCat.Iso.conj_eq_conj, Iso.conj_apply] rw [Iso.eq_inv_comp ((Action.forget (FGModuleCat k) (MonCat.of G)).mapIso i)] exact (i.hom.comm g).symm /-- Lift an unbundled representation to `FDRep`. -/ @[simps ρ] def of {V : Type u} [AddCommGroup V] [Module k V] [FiniteDimensional k V] (ρ : Representation k G V) : FDRep k G := ⟨FGModuleCat.of k V, ρ⟩ instance : HasForget₂ (FDRep k G) (Rep k G) where forget₂ := (forget₂ (FGModuleCat k) (ModuleCat k)).mapAction (MonCat.of G) theorem forget₂_ρ (V : FDRep k G) : ((forget₂ (FDRep k G) (Rep k G)).obj V).ρ = V.ρ := by ext g v; rfl -- Verify that the monoidal structure is available. example : MonoidalCategory (FDRep k G) := by infer_instance example : MonoidalPreadditive (FDRep k G) := by infer_instance example : MonoidalLinear k (FDRep k G) := by infer_instance open FiniteDimensional open scoped Classical -- We need to provide this instance explicitely as otherwise `finrank_hom_simple_simple` gives a -- deterministic timeout. instance : HasKernels (FDRep k G) := by infer_instance /-- Schur's Lemma: the dimension of the `Hom`-space between two irreducible representation is `0` if they are not isomorphic, and `1` if they are. -/ theorem finrank_hom_simple_simple [IsAlgClosed k] (V W : FDRep k G) [Simple V] [Simple W] : finrank k (V ⟶ W) = if Nonempty (V ≅ W) then 1 else 0 := CategoryTheory.finrank_hom_simple_simple k V W /-- The forgetful functor to `Rep k G` preserves hom-sets and their vector space structure. -/ def forget₂HomLinearEquiv (X Y : FDRep k G) : ((forget₂ (FDRep k G) (Rep k G)).obj X ⟶ (forget₂ (FDRep k G) (Rep k G)).obj Y) ≃ₗ[k] X ⟶ Y where toFun f := ⟨f.hom, f.comm⟩ map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := ⟨(forget₂ (FGModuleCat k) (ModuleCat k)).map f.hom, f.comm⟩ left_inv _ := by ext; rfl right_inv _ := by ext; rfl end FDRep namespace FDRep variable {k G : Type u} [Field k] [Group G] -- Verify that the right rigid structure is available when the monoid is a group. noncomputable instance : RightRigidCategory (FDRep k G) := by change RightRigidCategory (Action (FGModuleCat k) (Grp.of G)); infer_instance end FDRep namespace FDRep -- The variables in this section are slightly weird, living half in `Representation` and half in -- `FDRep`. When we have a better API for general monoidal closed and rigid categories and these -- structures on `FDRep`, we should remove the dependency of statements about `FDRep` on -- `Representation.linHom` and `Representation.dual`. The isomorphism `dualTensorIsoLinHom` -- below should then just be obtained from general results about rigid categories. open Representation variable {k G V : Type u} [Field k] [Group G] variable [AddCommGroup V] [Module k V] variable [FiniteDimensional k V] variable (ρV : Representation k G V) (W : FDRep k G) open scoped MonoidalCategory /-- Auxiliary definition for `FDRep.dualTensorIsoLinHom`. -/ noncomputable def dualTensorIsoLinHomAux : (FDRep.of ρV.dual ⊗ W).V ≅ (FDRep.of (linHom ρV W.ρ)).V := -- Porting note: had to make all types explicit arguments @LinearEquiv.toFGModuleCatIso k _ (FDRep.of ρV.dual ⊗ W).V (V →ₗ[k] W) _ _ _ _ _ _ (dualTensorHomEquiv k V W) /-- When `V` and `W` are finite dimensional representations of a group `G`, the isomorphism `dualTensorHomEquiv k V W` of vector spaces induces an isomorphism of representations. -/ noncomputable def dualTensorIsoLinHom : FDRep.of ρV.dual ⊗ W ≅ FDRep.of (linHom ρV W.ρ) := by refine Action.mkIso (dualTensorIsoLinHomAux ρV W) ?_ convert dualTensorHom_comm ρV W.ρ @[simp] theorem dualTensorIsoLinHom_hom_hom : (dualTensorIsoLinHom ρV W).hom.hom = dualTensorHom k V W := rfl end FDRep
RepresentationTheory\Invariants.lean
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.RepresentationTheory.Basic import Mathlib.RepresentationTheory.FDRep /-! # Subspace of invariants a group representation This file introduces the subspace of invariants of a group representation and proves basic results about it. The main tool used is the average of all elements of the group, seen as an element of `MonoidAlgebra k G`. The action of this special element gives a projection onto the subspace of invariants. In order for the definition of the average element to make sense, we need to assume for most of the results that the order of `G` is invertible in `k` (e. g. `k` has characteristic `0`). -/ suppress_compilation open MonoidAlgebra open Representation namespace GroupAlgebra variable (k G : Type*) [CommSemiring k] [Group G] variable [Fintype G] [Invertible (Fintype.card G : k)] /-- The average of all elements of the group `G`, considered as an element of `MonoidAlgebra k G`. -/ noncomputable def average : MonoidAlgebra k G := ⅟ (Fintype.card G : k) • ∑ g : G, of k G g /-- `average k G` is invariant under left multiplication by elements of `G`. -/ @[simp] theorem mul_average_left (g : G) : ↑(Finsupp.single g 1) * average k G = average k G := by simp only [mul_one, Finset.mul_sum, Algebra.mul_smul_comm, average, MonoidAlgebra.of_apply, Finset.sum_congr, MonoidAlgebra.single_mul_single] set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1 show ⅟ (Fintype.card G : k) • ∑ x : G, f (g * x) = ⅟ (Fintype.card G : k) • ∑ x : G, f x rw [Function.Bijective.sum_comp (Group.mulLeft_bijective g) _] /-- `average k G` is invariant under right multiplication by elements of `G`. -/ @[simp] theorem mul_average_right (g : G) : average k G * ↑(Finsupp.single g 1) = average k G := by simp only [mul_one, Finset.sum_mul, Algebra.smul_mul_assoc, average, MonoidAlgebra.of_apply, Finset.sum_congr, MonoidAlgebra.single_mul_single] set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1 show ⅟ (Fintype.card G : k) • ∑ x : G, f (x * g) = ⅟ (Fintype.card G : k) • ∑ x : G, f x rw [Function.Bijective.sum_comp (Group.mulRight_bijective g) _] end GroupAlgebra namespace Representation section Invariants open GroupAlgebra variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V] variable (ρ : Representation k G V) /-- The subspace of invariants, consisting of the vectors fixed by all elements of `G`. -/ def invariants : Submodule k V where carrier := setOf fun v => ∀ g : G, ρ g v = v zero_mem' g := by simp only [map_zero] add_mem' hv hw g := by simp only [hv g, hw g, map_add] smul_mem' r v hv g := by simp only [hv g, LinearMap.map_smulₛₗ, RingHom.id_apply] @[simp] theorem mem_invariants (v : V) : v ∈ invariants ρ ↔ ∀ g : G, ρ g v = v := by rfl theorem invariants_eq_inter : (invariants ρ).carrier = ⋂ g : G, Function.fixedPoints (ρ g) := by ext; simp [Function.IsFixedPt] theorem invariants_eq_top [ρ.IsTrivial] : invariants ρ = ⊤ := eq_top_iff.2 (fun x _ g => ρ.apply_eq_self g x) variable [Fintype G] [Invertible (Fintype.card G : k)] /-- The action of `average k G` gives a projection map onto the subspace of invariants. -/ @[simp] noncomputable def averageMap : V →ₗ[k] V := asAlgebraHom ρ (average k G) /-- The `averageMap` sends elements of `V` to the subspace of invariants. -/ theorem averageMap_invariant (v : V) : averageMap ρ v ∈ invariants ρ := fun g => by rw [averageMap, ← asAlgebraHom_single_one, ← LinearMap.mul_apply, ← map_mul (asAlgebraHom ρ), mul_average_left] /-- The `averageMap` acts as the identity on the subspace of invariants. -/ theorem averageMap_id (v : V) (hv : v ∈ invariants ρ) : averageMap ρ v = v := by rw [mem_invariants] at hv simp [average, map_sum, hv, Finset.card_univ, ← Nat.cast_smul_eq_nsmul k _ v, smul_smul] theorem isProj_averageMap : LinearMap.IsProj ρ.invariants ρ.averageMap := ⟨ρ.averageMap_invariant, ρ.averageMap_id⟩ end Invariants namespace linHom universe u open CategoryTheory Action section Rep variable {k : Type u} [CommRing k] {G : Grp.{u}} theorem mem_invariants_iff_comm {X Y : Rep k G} (f : X.V →ₗ[k] Y.V) (g : G) : (linHom X.ρ Y.ρ) g f = f ↔ f.comp (X.ρ g) = (Y.ρ g).comp f := by dsimp erw [← ρAut_apply_inv] rw [← LinearMap.comp_assoc, ← ModuleCat.comp_def, ← ModuleCat.comp_def, Iso.inv_comp_eq, ρAut_apply_hom] exact comm /-- The invariants of the representation `linHom X.ρ Y.ρ` correspond to the representation homomorphisms from `X` to `Y`. -/ @[simps] def invariantsEquivRepHom (X Y : Rep k G) : (linHom X.ρ Y.ρ).invariants ≃ₗ[k] X ⟶ Y where toFun f := ⟨f.val, fun g => (mem_invariants_iff_comm _ g).1 (f.property g)⟩ map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := ⟨f.hom, fun g => (mem_invariants_iff_comm _ g).2 (f.comm g)⟩ left_inv _ := by apply Subtype.ext; ext; rfl -- Porting note: Added `apply Subtype.ext` right_inv _ := by ext; rfl end Rep section FDRep variable {k : Type u} [Field k] {G : Grp.{u}} /-- The invariants of the representation `linHom X.ρ Y.ρ` correspond to the representation homomorphisms from `X` to `Y`. -/ def invariantsEquivFDRepHom (X Y : FDRep k G) : (linHom X.ρ Y.ρ).invariants ≃ₗ[k] X ⟶ Y := by rw [← FDRep.forget₂_ρ, ← FDRep.forget₂_ρ] -- Porting note: The original version used `linHom.invariantsEquivRepHom _ _ ≪≫ₗ` exact linHom.invariantsEquivRepHom ((forget₂ (FDRep k G) (Rep k G)).obj X) ((forget₂ (FDRep k G) (Rep k G)).obj Y) ≪≫ₗ FDRep.forget₂HomLinearEquiv X Y end FDRep end linHom end Representation
RepresentationTheory\Maschke.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.LinearAlgebra.Basis.VectorSpace import Mathlib.RingTheory.SimpleModule /-! # Maschke's theorem We prove **Maschke's theorem** for finite groups, in the formulation that every submodule of a `k[G]` module has a complement, when `k` is a field with `Invertible (Fintype.card G : k)`. We do the core computation in greater generality. For any `[CommRing k]` in which `[Invertible (Fintype.card G : k)]`, and a `k[G]`-linear map `i : V → W` which admits a `k`-linear retraction `π`, we produce a `k[G]`-linear retraction by taking the average over `G` of the conjugates of `π`. ## Implementation Notes * These results assume `Invertible (Fintype.card G : k)` which is equivalent to the more familiar `¬(ringChar k ∣ Fintype.card G)`. It is possible to convert between them using `invertibleOfRingCharNotDvd` and `not_ringChar_dvd_of_invertible`. ## Future work It's not so far to give the usual statement, that every finite dimensional representation of a finite group is semisimple (i.e. a direct sum of irreducibles). -/ universe u v w noncomputable section open Module MonoidAlgebra /-! We now do the key calculation in Maschke's theorem. Given `V → W`, an inclusion of `k[G]` modules, assume we have some retraction `π` (i.e. `∀ v, π (i v) = v`), just as a `k`-linear map. (When `k` is a field, this will be available cheaply, by choosing a basis.) We now construct a retraction of the inclusion as a `k[G]`-linear map, by the formula $$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$ -/ namespace LinearMap -- At first we work with any `[CommRing k]`, and add the assumption that -- `[Invertible (Fintype.card G : k)]` when it is required. variable {k : Type u} [CommRing k] {G : Type u} [Group G] variable {V : Type v} [AddCommGroup V] [Module k V] [Module (MonoidAlgebra k G) V] variable [IsScalarTower k (MonoidAlgebra k G) V] variable {W : Type w} [AddCommGroup W] [Module k W] [Module (MonoidAlgebra k G) W] variable [IsScalarTower k (MonoidAlgebra k G) W] variable (π : W →ₗ[k] V) /-- We define the conjugate of `π` by `g`, as a `k`-linear map. -/ def conjugate (g : G) : W →ₗ[k] V := .comp (.comp (GroupSMul.linearMap k V g⁻¹) π) (GroupSMul.linearMap k W g) theorem conjugate_apply (g : G) (v : W) : π.conjugate g v = MonoidAlgebra.single g⁻¹ (1 : k) • π (MonoidAlgebra.single g (1 : k) • v) := rfl variable (i : V →ₗ[MonoidAlgebra k G] W) section theorem conjugate_i (h : ∀ v : V, (π : W → V) (i v) = v) (g : G) (v : V) : (conjugate π g : W → V) (i v) = v := by rw [conjugate_apply, ← i.map_smul, h, ← mul_smul, single_mul_single, mul_one, mul_left_inv, ← one_def, one_smul] end variable (G) [Fintype G] /-- The sum of the conjugates of `π` by each element `g : G`, as a `k`-linear map. (We postpone dividing by the size of the group as long as possible.) -/ def sumOfConjugates : W →ₗ[k] V := ∑ g : G, π.conjugate g lemma sumOfConjugates_apply (v : W) : π.sumOfConjugates G v = ∑ g : G, π.conjugate g v := LinearMap.sum_apply _ _ _ /-- In fact, the sum over `g : G` of the conjugate of `π` by `g` is a `k[G]`-linear map. -/ def sumOfConjugatesEquivariant : W →ₗ[MonoidAlgebra k G] V := MonoidAlgebra.equivariantOfLinearOfComm (π.sumOfConjugates G) fun g v => by simp only [sumOfConjugates_apply, Finset.smul_sum, conjugate_apply] refine Fintype.sum_bijective (· * g) (Group.mulRight_bijective g) _ _ fun i ↦ ?_ simp only [smul_smul, single_mul_single, mul_inv_rev, mul_inv_cancel_left, one_mul] theorem sumOfConjugatesEquivariant_apply (v : W) : π.sumOfConjugatesEquivariant G v = ∑ g : G, π.conjugate g v := π.sumOfConjugates_apply G v section variable [Invertible (Fintype.card G : k)] /-- We construct our `k[G]`-linear retraction of `i` as $$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$ -/ def equivariantProjection : W →ₗ[MonoidAlgebra k G] V := ⅟(Fintype.card G : k) • π.sumOfConjugatesEquivariant G theorem equivariantProjection_apply (v : W) : π.equivariantProjection G v = ⅟(Fintype.card G : k) • ∑ g : G, π.conjugate g v := by simp only [equivariantProjection, smul_apply, sumOfConjugatesEquivariant_apply] theorem equivariantProjection_condition (h : ∀ v : V, (π : W → V) (i v) = v) (v : V) : (π.equivariantProjection G) (i v) = v := by rw [equivariantProjection_apply] simp only [conjugate_i π i h] rw [Finset.sum_const, Finset.card_univ, ← Nat.cast_smul_eq_nsmul k, smul_smul, Invertible.invOf_mul_self, one_smul] end end LinearMap end namespace MonoidAlgebra -- Now we work over a `[Field k]`. variable {k : Type u} [Field k] {G : Type u} [Fintype G] [Invertible (Fintype.card G : k)] variable [Group G] variable {V : Type u} [AddCommGroup V] [Module (MonoidAlgebra k G) V] variable {W : Type u} [AddCommGroup W] [Module (MonoidAlgebra k G) W] theorem exists_leftInverse_of_injective (f : V →ₗ[MonoidAlgebra k G] W) (hf : LinearMap.ker f = ⊥) : ∃ g : W →ₗ[MonoidAlgebra k G] V, g.comp f = LinearMap.id := by let A := MonoidAlgebra k G letI : Module k W := .compHom W (algebraMap k A) letI : Module k V := .compHom V (algebraMap k A) have := IsScalarTower.of_compHom k A W have := IsScalarTower.of_compHom k A V obtain ⟨φ, hφ⟩ := (f.restrictScalars k).exists_leftInverse_of_injective <| by simp only [hf, Submodule.restrictScalars_bot, LinearMap.ker_restrictScalars] refine ⟨φ.equivariantProjection G, DFunLike.ext _ _ ?_⟩ exact φ.equivariantProjection_condition G _ <| DFunLike.congr_fun hφ namespace Submodule theorem exists_isCompl (p : Submodule (MonoidAlgebra k G) V) : ∃ q : Submodule (MonoidAlgebra k G) V, IsCompl p q := by rcases MonoidAlgebra.exists_leftInverse_of_injective p.subtype p.ker_subtype with ⟨f, hf⟩ exact ⟨LinearMap.ker f, LinearMap.isCompl_of_proj <| DFunLike.congr_fun hf⟩ /-- This also implies instances `IsSemisimpleModule (MonoidAlgebra k G) V` and `IsSemisimpleRing (MonoidAlgebra k G)`. -/ instance complementedLattice : ComplementedLattice (Submodule (MonoidAlgebra k G) V) := ⟨exists_isCompl⟩ instance [AddGroup G] : IsSemisimpleRing (AddMonoidAlgebra k G) := letI : Invertible (Fintype.card (Multiplicative G) : k) := by rwa [Fintype.card_congr Multiplicative.toAdd] (AddMonoidAlgebra.toMultiplicativeAlgEquiv k G (R := ℕ)).toRingEquiv.symm.isSemisimpleRing end Submodule end MonoidAlgebra
RepresentationTheory\Rep.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Category.ModuleCat.Adjunctions import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.Algebra.Category.ModuleCat.Colimits import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric import Mathlib.CategoryTheory.Elementwise import Mathlib.RepresentationTheory.Action.Monoidal import Mathlib.RepresentationTheory.Basic /-! # `Rep k G` is the category of `k`-linear representations of `G`. If `V : Rep k G`, there is a coercion that allows you to treat `V` as a type, and this type comes equipped with a `Module k V` instance. Also `V.ρ` gives the homomorphism `G →* (V →ₗ[k] V)`. Conversely, given a homomorphism `ρ : G →* (V →ₗ[k] V)`, you can construct the bundled representation as `Rep.of ρ`. We construct the categorical equivalence `Rep k G ≌ ModuleCat (MonoidAlgebra k G)`. We verify that `Rep k G` is a `k`-linear abelian symmetric monoidal category with all (co)limits. -/ suppress_compilation universe u open CategoryTheory open CategoryTheory.Limits /-- The category of `k`-linear representations of a monoid `G`. -/ abbrev Rep (k G : Type u) [Ring k] [Monoid G] := Action (ModuleCat.{u} k) (MonCat.of G) instance (k G : Type u) [CommRing k] [Monoid G] : Linear k (Rep k G) := by infer_instance namespace Rep variable {k G : Type u} [CommRing k] section variable [Monoid G] instance : CoeSort (Rep k G) (Type u) := ConcreteCategory.hasCoeToSort _ instance (V : Rep k G) : AddCommGroup V := by change AddCommGroup ((forget₂ (Rep k G) (ModuleCat k)).obj V); infer_instance instance (V : Rep k G) : Module k V := by change Module k ((forget₂ (Rep k G) (ModuleCat k)).obj V) infer_instance /-- Specialize the existing `Action.ρ`, changing the type to `Representation k G V`. -/ def ρ (V : Rep k G) : Representation k G V := -- Porting note: was `V.ρ` Action.ρ V /-- Lift an unbundled representation to `Rep`. -/ def of {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : Rep k G := ⟨ModuleCat.of k V, ρ⟩ @[simp] theorem coe_of {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : (of ρ : Type u) = V := rfl @[simp] theorem of_ρ {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : (of ρ).ρ = ρ := rfl theorem Action_ρ_eq_ρ {A : Rep k G} : Action.ρ A = A.ρ := rfl /-- Allows us to apply lemmas about the underlying `ρ`, which would take an element `g : G` rather than `g : MonCat.of G` as an argument. -/ theorem of_ρ_apply {V : Type u} [AddCommGroup V] [Module k V] (ρ : Representation k G V) (g : MonCat.of G) : (Rep.of ρ).ρ g = ρ (g : G) := rfl @[simp] theorem ρ_inv_self_apply {G : Type u} [Group G] (A : Rep k G) (g : G) (x : A) : A.ρ g⁻¹ (A.ρ g x) = x := show (A.ρ g⁻¹ * A.ρ g) x = x by rw [← map_mul, inv_mul_self, map_one, LinearMap.one_apply] @[simp] theorem ρ_self_inv_apply {G : Type u} [Group G] {A : Rep k G} (g : G) (x : A) : A.ρ g (A.ρ g⁻¹ x) = x := show (A.ρ g * A.ρ g⁻¹) x = x by rw [← map_mul, mul_inv_self, map_one, LinearMap.one_apply] theorem hom_comm_apply {A B : Rep k G} (f : A ⟶ B) (g : G) (x : A) : f.hom (A.ρ g x) = B.ρ g (f.hom x) := LinearMap.ext_iff.1 (f.comm g) x variable (k G) /-- The trivial `k`-linear `G`-representation on a `k`-module `V.` -/ def trivial (V : Type u) [AddCommGroup V] [Module k V] : Rep k G := Rep.of (@Representation.trivial k G V _ _ _ _) variable {k G} theorem trivial_def {V : Type u} [AddCommGroup V] [Module k V] (g : G) (v : V) : (trivial k G V).ρ g v = v := rfl /-- A predicate for representations that fix every element. -/ abbrev IsTrivial (A : Rep k G) := A.ρ.IsTrivial instance {V : Type u} [AddCommGroup V] [Module k V] : IsTrivial (Rep.trivial k G V) where instance {V : Type u} [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsTrivial] : IsTrivial (Rep.of ρ) where -- Porting note: the two following instances were found automatically in mathlib3 noncomputable instance : PreservesLimits (forget₂ (Rep k G) (ModuleCat.{u} k)) := Action.instPreservesLimitsForget.{u} _ _ noncomputable instance : PreservesColimits (forget₂ (Rep k G) (ModuleCat.{u} k)) := Action.instPreservesColimitsForget.{u} _ _ /- Porting note: linter complains `simp` unfolds some types in the LHS, so have removed `@[simp]`. -/ theorem MonoidalCategory.braiding_hom_apply {A B : Rep k G} (x : A) (y : B) : Action.Hom.hom (β_ A B).hom (TensorProduct.tmul k x y) = TensorProduct.tmul k y x := rfl /- Porting note: linter complains `simp` unfolds some types in the LHS, so have removed `@[simp]`. -/ theorem MonoidalCategory.braiding_inv_apply {A B : Rep k G} (x : A) (y : B) : Action.Hom.hom (β_ A B).inv (TensorProduct.tmul k y x) = TensorProduct.tmul k x y := rfl section Linearization variable (k G) /-- The monoidal functor sending a type `H` with a `G`-action to the induced `k`-linear `G`-representation on `k[H].` -/ noncomputable def linearization : MonoidalFunctor (Action (Type u) (MonCat.of G)) (Rep k G) := (ModuleCat.monoidalFree k).mapAction (MonCat.of G) variable {k G} @[simp] theorem linearization_obj_ρ (X : Action (Type u) (MonCat.of G)) (g : G) (x : X.V →₀ k) : ((linearization k G).obj X).ρ g x = Finsupp.lmapDomain k k (X.ρ g) x := rfl theorem linearization_of (X : Action (Type u) (MonCat.of G)) (g : G) (x : X.V) : ((linearization k G).obj X).ρ g (Finsupp.single x (1 : k)) = Finsupp.single (X.ρ g x) (1 : k) := by rw [linearization_obj_ρ, Finsupp.lmapDomain_apply, Finsupp.mapDomain_single] -- Porting note (#11041): helps fixing `linearizationTrivialIso` since change in behaviour of `ext`. theorem linearization_single (X : Action (Type u) (MonCat.of G)) (g : G) (x : X.V) (r : k) : ((linearization k G).obj X).ρ g (Finsupp.single x r) = Finsupp.single (X.ρ g x) r := by rw [linearization_obj_ρ, Finsupp.lmapDomain_apply, Finsupp.mapDomain_single] variable {X Y : Action (Type u) (MonCat.of G)} (f : X ⟶ Y) @[simp] theorem linearization_map_hom : ((linearization k G).map f).hom = Finsupp.lmapDomain k k f.hom := rfl theorem linearization_map_hom_single (x : X.V) (r : k) : ((linearization k G).map f).hom (Finsupp.single x r) = Finsupp.single (f.hom x) r := Finsupp.mapDomain_single @[simp] theorem linearization_μ_hom (X Y : Action (Type u) (MonCat.of G)) : ((linearization k G).μ X Y).hom = (finsuppTensorFinsupp' k X.V Y.V).toLinearMap := rfl @[simp] theorem linearization_μ_inv_hom (X Y : Action (Type u) (MonCat.of G)) : (inv ((linearization k G).μ X Y)).hom = (finsuppTensorFinsupp' k X.V Y.V).symm.toLinearMap := by -- Porting note (#11039): broken proof was /- simp_rw [← Action.forget_map, Functor.map_inv, Action.forget_map, linearization_μ_hom] apply IsIso.inv_eq_of_hom_inv_id _ exact LinearMap.ext fun x => LinearEquiv.symm_apply_apply _ _-/ rw [← Action.forget_map, Functor.map_inv] apply IsIso.inv_eq_of_hom_inv_id exact LinearMap.ext fun x => LinearEquiv.symm_apply_apply (finsuppTensorFinsupp' k X.V Y.V) x @[simp] theorem linearization_ε_hom : (linearization k G).ε.hom = Finsupp.lsingle PUnit.unit := rfl theorem linearization_ε_inv_hom_apply (r : k) : (inv (linearization k G).ε).hom (Finsupp.single PUnit.unit r) = r := IsIso.hom_inv_id_apply (linearization k G).ε r variable (k G) /-- The linearization of a type `X` on which `G` acts trivially is the trivial `G`-representation on `k[X]`. -/ @[simps!] noncomputable def linearizationTrivialIso (X : Type u) : (linearization k G).obj (Action.mk X 1) ≅ trivial k G (X →₀ k) := Action.mkIso (Iso.refl _) fun _ => Finsupp.lhom_ext' fun _ => LinearMap.ext fun _ => linearization_single .. /-- Given a `G`-action on `H`, this is `k[H]` bundled with the natural representation `G →* End(k[H])` as a term of type `Rep k G`. -/ noncomputable abbrev ofMulAction (H : Type u) [MulAction G H] : Rep k G := of <| Representation.ofMulAction k G H /-- The `k`-linear `G`-representation on `k[G]`, induced by left multiplication. -/ noncomputable def leftRegular : Rep k G := ofMulAction k G G /-- The `k`-linear `G`-representation on `k[Gⁿ]`, induced by left multiplication. -/ noncomputable def diagonal (n : ℕ) : Rep k G := ofMulAction k G (Fin n → G) /-- The linearization of a type `H` with a `G`-action is definitionally isomorphic to the `k`-linear `G`-representation on `k[H]` induced by the `G`-action on `H`. -/ noncomputable def linearizationOfMulActionIso (H : Type u) [MulAction G H] : (linearization k G).obj (Action.ofMulAction G H) ≅ ofMulAction k G H := Iso.refl _ section variable (k G A : Type u) [CommRing k] [Monoid G] [AddCommGroup A] [Module k A] [DistribMulAction G A] [SMulCommClass G k A] /-- Turns a `k`-module `A` with a compatible `DistribMulAction` of a monoid `G` into a `k`-linear `G`-representation on `A`. -/ def ofDistribMulAction : Rep k G := Rep.of (Representation.ofDistribMulAction k G A) @[simp] theorem ofDistribMulAction_ρ_apply_apply (g : G) (a : A) : (ofDistribMulAction k G A).ρ g a = g • a := rfl /-- Given an `R`-algebra `S`, the `ℤ`-linear representation associated to the natural action of `S ≃ₐ[R] S` on `S`. -/ @[simp] def ofAlgebraAut (R S : Type) [CommRing R] [CommRing S] [Algebra R S] : Rep ℤ (S ≃ₐ[R] S) := ofDistribMulAction ℤ (S ≃ₐ[R] S) S end section variable (M G : Type) [Monoid M] [CommGroup G] [MulDistribMulAction M G] /-- Turns a `CommGroup` `G` with a `MulDistribMulAction` of a monoid `M` into a `ℤ`-linear `M`-representation on `Additive G`. -/ def ofMulDistribMulAction : Rep ℤ M := Rep.of (Representation.ofMulDistribMulAction M G) @[simp] theorem ofMulDistribMulAction_ρ_apply_apply (g : M) (a : Additive G) : (ofMulDistribMulAction M G).ρ g a = Additive.ofMul (g • Additive.toMul a) := rfl /-- Given an `R`-algebra `S`, the `ℤ`-linear representation associated to the natural action of `S ≃ₐ[R] S` on `Sˣ`. -/ @[simp] def ofAlgebraAutOnUnits (R S : Type) [CommRing R] [CommRing S] [Algebra R S] : Rep ℤ (S ≃ₐ[R] S) := Rep.ofMulDistribMulAction (S ≃ₐ[R] S) Sˣ end variable {k G} /-- Given an element `x : A`, there is a natural morphism of representations `k[G] ⟶ A` sending `g ↦ A.ρ(g)(x).` -/ @[simps] noncomputable def leftRegularHom (A : Rep k G) (x : A) : Rep.ofMulAction k G G ⟶ A where hom := Finsupp.lift _ _ _ fun g => A.ρ g x comm g := by refine Finsupp.lhom_ext' fun y => LinearMap.ext_ring ?_ /- Porting note: rest of broken proof was simpa only [LinearMap.comp_apply, ModuleCat.comp_def, Finsupp.lsingle_apply, Finsupp.lift_apply, Action_ρ_eq_ρ, of_ρ_apply, Representation.ofMulAction_single, Finsupp.sum_single_index, zero_smul, one_smul, smul_eq_mul, A.ρ.map_mul] -/ simp only [LinearMap.comp_apply, ModuleCat.comp_def, Finsupp.lsingle_apply] erw [Finsupp.lift_apply, Finsupp.lift_apply, Representation.ofMulAction_single (G := G)] simp only [Finsupp.sum_single_index, zero_smul, one_smul, smul_eq_mul, A.ρ.map_mul, of_ρ] rfl theorem leftRegularHom_apply {A : Rep k G} (x : A) : (leftRegularHom A x).hom (Finsupp.single 1 1) = x := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [leftRegularHom_hom, Finsupp.lift_apply, Finsupp.sum_single_index, one_smul, A.ρ.map_one, LinearMap.one_apply] rw [zero_smul] /-- Given a `k`-linear `G`-representation `A`, there is a `k`-linear isomorphism between representation morphisms `Hom(k[G], A)` and `A`. -/ @[simps] noncomputable def leftRegularHomEquiv (A : Rep k G) : (Rep.ofMulAction k G G ⟶ A) ≃ₗ[k] A where toFun f := f.hom (Finsupp.single 1 1) map_add' x y := rfl map_smul' r x := rfl invFun x := leftRegularHom A x left_inv f := by refine Action.Hom.ext (Finsupp.lhom_ext' fun x : G => LinearMap.ext_ring ?_) have : f.hom ((ofMulAction k G G).ρ x (Finsupp.single (1 : G) (1 : k))) = A.ρ x (f.hom (Finsupp.single (1 : G) (1 : k))) := LinearMap.ext_iff.1 (f.comm x) (Finsupp.single 1 1) simp only [leftRegularHom_hom, LinearMap.comp_apply, Finsupp.lsingle_apply, Finsupp.lift_apply, ← this, coe_of, of_ρ, Representation.ofMulAction_single x (1 : G) (1 : k), smul_eq_mul, mul_one, zero_smul, Finsupp.sum_single_index, one_smul] -- Mismatched `Zero k` instances rfl right_inv x := leftRegularHom_apply x theorem leftRegularHomEquiv_symm_single {A : Rep k G} (x : A) (g : G) : ((leftRegularHomEquiv A).symm x).hom (Finsupp.single g 1) = A.ρ g x := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [leftRegularHomEquiv_symm_apply, leftRegularHom_hom, Finsupp.lift_apply, Finsupp.sum_single_index, one_smul] rw [zero_smul] end Linearization end section MonoidalClosed open MonoidalCategory Action variable [Group G] (A B C : Rep k G) /-- Given a `k`-linear `G`-representation `(A, ρ₁)`, this is the 'internal Hom' functor sending `(B, ρ₂)` to the representation `Homₖ(A, B)` that maps `g : G` and `f : A →ₗ[k] B` to `(ρ₂ g) ∘ₗ f ∘ₗ (ρ₁ g⁻¹)`. -/ @[simps] protected def ihom (A : Rep k G) : Rep k G ⥤ Rep k G where obj B := Rep.of (Representation.linHom A.ρ B.ρ) map := fun {X} {Y} f => { hom := ModuleCat.ofHom (LinearMap.llcomp k _ _ _ f.hom) comm := fun g => LinearMap.ext fun x => LinearMap.ext fun y => by show f.hom (X.ρ g _) = _ simp only [hom_comm_apply]; rfl } map_id := fun _ => by ext; rfl map_comp := fun _ _ => by ext; rfl @[simp] theorem ihom_obj_ρ_apply {A B : Rep k G} (g : G) (x : A →ₗ[k] B) : ((Rep.ihom A).obj B).ρ g x = B.ρ g ∘ₗ x ∘ₗ A.ρ g⁻¹ := rfl /-- Given a `k`-linear `G`-representation `A`, this is the Hom-set bijection in the adjunction `A ⊗ - ⊣ ihom(A, -)`. It sends `f : A ⊗ B ⟶ C` to a `Rep k G` morphism defined by currying the `k`-linear map underlying `f`, giving a map `A →ₗ[k] B →ₗ[k] C`, then flipping the arguments. -/ def homEquiv (A B C : Rep k G) : (A ⊗ B ⟶ C) ≃ (B ⟶ (Rep.ihom A).obj C) where toFun f := { hom := (TensorProduct.curry f.hom).flip comm := fun g => by refine LinearMap.ext fun x => LinearMap.ext fun y => ?_ change f.hom (_ ⊗ₜ[k] _) = C.ρ g (f.hom (_ ⊗ₜ[k] _)) rw [← hom_comm_apply] change _ = f.hom ((A.ρ g * A.ρ g⁻¹) y ⊗ₜ[k] _) simp only [← map_mul, mul_inv_self, map_one] rfl } invFun f := { hom := TensorProduct.uncurry k _ _ _ f.hom.flip comm := fun g => TensorProduct.ext' fun x y => by /- Porting note: rest of broken proof was dsimp only [MonoidalCategory.tensorLeft_obj, ModuleCat.comp_def, LinearMap.comp_apply, tensor_rho, ModuleCat.MonoidalCategory.hom_apply, TensorProduct.map_tmul] simp only [TensorProduct.uncurry_apply f.hom.flip, LinearMap.flip_apply, Action_ρ_eq_ρ, hom_comm_apply f g y, Rep.ihom_obj_ρ_apply, LinearMap.comp_apply, ρ_inv_self_apply] -/ change TensorProduct.uncurry k _ _ _ f.hom.flip (A.ρ g x ⊗ₜ[k] B.ρ g y) = C.ρ g (TensorProduct.uncurry k _ _ _ f.hom.flip (x ⊗ₜ[k] y)) -- The next 3 tactics used to be `rw` before leanprover/lean4#2644 erw [TensorProduct.uncurry_apply, LinearMap.flip_apply, hom_comm_apply, Rep.ihom_obj_ρ_apply, LinearMap.comp_apply, LinearMap.comp_apply] --, ρ_inv_self_apply (A := C)] dsimp erw [ρ_inv_self_apply] rfl} left_inv f := Action.Hom.ext (TensorProduct.ext' fun _ _ => rfl) right_inv f := by ext; rfl variable {A B C} /-- Porting note: if we generate this with `@[simps]` the linter complains some types in the LHS simplify. -/ theorem homEquiv_apply_hom (f : A ⊗ B ⟶ C) : (homEquiv A B C f).hom = (TensorProduct.curry f.hom).flip := rfl /-- Porting note: if we generate this with `@[simps]` the linter complains some types in the LHS simplify. -/ theorem homEquiv_symm_apply_hom (f : B ⟶ (Rep.ihom A).obj C) : ((homEquiv A B C).symm f).hom = TensorProduct.uncurry k A B C f.hom.flip := rfl instance : MonoidalClosed (Rep k G) where closed A := { rightAdj := Rep.ihom A adj := Adjunction.mkOfHomEquiv ( { homEquiv := Rep.homEquiv A homEquiv_naturality_left_symm := fun _ _ => Action.Hom.ext (TensorProduct.ext' fun _ _ => rfl) homEquiv_naturality_right := fun _ _ => Action.Hom.ext (LinearMap.ext fun _ => LinearMap.ext fun _ => rfl) })} @[simp] theorem ihom_obj_ρ_def (A B : Rep k G) : ((ihom A).obj B).ρ = ((Rep.ihom A).obj B).ρ := rfl @[simp] theorem homEquiv_def (A B C : Rep k G) : (ihom.adjunction A).homEquiv B C = Rep.homEquiv A B C := rfl @[simp] theorem ihom_ev_app_hom (A B : Rep k G) : Action.Hom.hom ((ihom.ev A).app B) = TensorProduct.uncurry k A (A →ₗ[k] B) B LinearMap.id.flip := by ext; rfl @[simp] theorem ihom_coev_app_hom (A B : Rep k G) : Action.Hom.hom ((ihom.coev A).app B) = (TensorProduct.mk k _ _).flip := LinearMap.ext fun _ => LinearMap.ext fun _ => rfl variable (A B C) /-- There is a `k`-linear isomorphism between the sets of representation morphisms`Hom(A ⊗ B, C)` and `Hom(B, Homₖ(A, C))`. -/ def MonoidalClosed.linearHomEquiv : (A ⊗ B ⟶ C) ≃ₗ[k] B ⟶ A ⟶[Rep k G] C := { (ihom.adjunction A).homEquiv _ _ with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } /-- There is a `k`-linear isomorphism between the sets of representation morphisms`Hom(A ⊗ B, C)` and `Hom(A, Homₖ(B, C))`. -/ def MonoidalClosed.linearHomEquivComm : (A ⊗ B ⟶ C) ≃ₗ[k] A ⟶ B ⟶[Rep k G] C := Linear.homCongr k (β_ A B) (Iso.refl _) ≪≫ₗ MonoidalClosed.linearHomEquiv _ _ _ variable {A B C} -- `simpNF` times out @[simp, nolint simpNF] theorem MonoidalClosed.linearHomEquiv_hom (f : A ⊗ B ⟶ C) : (MonoidalClosed.linearHomEquiv A B C f).hom = (TensorProduct.curry f.hom).flip := rfl -- `simpNF` times out @[simp, nolint simpNF] theorem MonoidalClosed.linearHomEquivComm_hom (f : A ⊗ B ⟶ C) : (MonoidalClosed.linearHomEquivComm A B C f).hom = TensorProduct.curry f.hom := rfl theorem MonoidalClosed.linearHomEquiv_symm_hom (f : B ⟶ A ⟶[Rep k G] C) : ((MonoidalClosed.linearHomEquiv A B C).symm f).hom = TensorProduct.uncurry k A B C f.hom.flip := rfl theorem MonoidalClosed.linearHomEquivComm_symm_hom (f : A ⟶ B ⟶[Rep k G] C) : ((MonoidalClosed.linearHomEquivComm A B C).symm f).hom = TensorProduct.uncurry k A B C f.hom := TensorProduct.ext' fun _ _ => rfl end MonoidalClosed end Rep namespace Representation open MonoidalCategory variable {k G : Type u} [CommRing k] [Monoid G] {V W : Type u} [AddCommGroup V] [AddCommGroup W] [Module k V] [Module k W] (ρ : Representation k G V) (τ : Representation k G W) /-- Tautological isomorphism to help Lean in typechecking. -/ def repOfTprodIso : Rep.of (ρ.tprod τ) ≅ Rep.of ρ ⊗ Rep.of τ := Iso.refl _ theorem repOfTprodIso_apply (x : TensorProduct k V W) : (repOfTprodIso ρ τ).hom.hom x = x := rfl theorem repOfTprodIso_inv_apply (x : TensorProduct k V W) : (repOfTprodIso ρ τ).inv.hom x = x := rfl end Representation /-! # The categorical equivalence `Rep k G ≌ Module.{u} (MonoidAlgebra k G)`. -/ namespace Rep variable {k G : Type u} [CommRing k] [Monoid G] -- Verify that the symmetric monoidal structure is available. example : SymmetricCategory (Rep k G) := by infer_instance example : MonoidalPreadditive (Rep k G) := by infer_instance example : MonoidalLinear k (Rep k G) := by infer_instance noncomputable section /-- Auxiliary lemma for `toModuleMonoidAlgebra`. -/ theorem to_Module_monoidAlgebra_map_aux {k G : Type*} [CommRing k] [Monoid G] (V W : Type*) [AddCommGroup V] [AddCommGroup W] [Module k V] [Module k W] (ρ : G →* V →ₗ[k] V) (σ : G →* W →ₗ[k] W) (f : V →ₗ[k] W) (w : ∀ g : G, f.comp (ρ g) = (σ g).comp f) (r : MonoidAlgebra k G) (x : V) : f ((((MonoidAlgebra.lift k G (V →ₗ[k] V)) ρ) r) x) = (((MonoidAlgebra.lift k G (W →ₗ[k] W)) σ) r) (f x) := by apply MonoidAlgebra.induction_on r · intro g simp only [one_smul, MonoidAlgebra.lift_single, MonoidAlgebra.of_apply] exact LinearMap.congr_fun (w g) x · intro g h gw hw; simp only [map_add, add_left_inj, LinearMap.add_apply, hw, gw] · intro r g w simp only [map_smul, w, RingHom.id_apply, LinearMap.smul_apply, LinearMap.map_smulₛₗ] /-- Auxiliary definition for `toModuleMonoidAlgebra`. -/ def toModuleMonoidAlgebraMap {V W : Rep k G} (f : V ⟶ W) : ModuleCat.of (MonoidAlgebra k G) V.ρ.asModule ⟶ ModuleCat.of (MonoidAlgebra k G) W.ρ.asModule := { f.hom with map_smul' := fun r x => to_Module_monoidAlgebra_map_aux V.V W.V V.ρ W.ρ f.hom f.comm r x } /-- Functorially convert a representation of `G` into a module over `MonoidAlgebra k G`. -/ def toModuleMonoidAlgebra : Rep k G ⥤ ModuleCat.{u} (MonoidAlgebra k G) where obj V := ModuleCat.of _ V.ρ.asModule map f := toModuleMonoidAlgebraMap f /-- Functorially convert a module over `MonoidAlgebra k G` into a representation of `G`. -/ def ofModuleMonoidAlgebra : ModuleCat.{u} (MonoidAlgebra k G) ⥤ Rep k G where obj M := Rep.of (Representation.ofModule M) map f := { hom := { f with map_smul' := fun r x => f.map_smul (algebraMap k _ r) x } comm := fun g => by ext; apply f.map_smul } theorem ofModuleMonoidAlgebra_obj_coe (M : ModuleCat.{u} (MonoidAlgebra k G)) : (ofModuleMonoidAlgebra.obj M : Type u) = RestrictScalars k (MonoidAlgebra k G) M := rfl theorem ofModuleMonoidAlgebra_obj_ρ (M : ModuleCat.{u} (MonoidAlgebra k G)) : (ofModuleMonoidAlgebra.obj M).ρ = Representation.ofModule M := rfl /-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/ def counitIsoAddEquiv {M : ModuleCat.{u} (MonoidAlgebra k G)} : (ofModuleMonoidAlgebra ⋙ toModuleMonoidAlgebra).obj M ≃+ M := by dsimp [ofModuleMonoidAlgebra, toModuleMonoidAlgebra] exact (Representation.ofModule M).asModuleEquiv.trans (RestrictScalars.addEquiv k (MonoidAlgebra k G) _) /-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/ def unitIsoAddEquiv {V : Rep k G} : V ≃+ (toModuleMonoidAlgebra ⋙ ofModuleMonoidAlgebra).obj V := by dsimp [ofModuleMonoidAlgebra, toModuleMonoidAlgebra] refine V.ρ.asModuleEquiv.symm.trans ?_ exact (RestrictScalars.addEquiv _ _ _).symm /-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/ def counitIso (M : ModuleCat.{u} (MonoidAlgebra k G)) : (ofModuleMonoidAlgebra ⋙ toModuleMonoidAlgebra).obj M ≅ M := LinearEquiv.toModuleIso' { counitIsoAddEquiv with map_smul' := fun r x => by set_option tactic.skipAssignedInstances false in dsimp [counitIsoAddEquiv] /- Porting note: rest of broken proof was `simp`. -/ rw [AddEquiv.trans_apply] rw [AddEquiv.trans_apply] erw [@Representation.ofModule_asAlgebraHom_apply_apply k G _ _ _ _ (_)] exact AddEquiv.symm_apply_apply _ _} theorem unit_iso_comm (V : Rep k G) (g : G) (x : V) : unitIsoAddEquiv ((V.ρ g).toFun x) = ((ofModuleMonoidAlgebra.obj (toModuleMonoidAlgebra.obj V)).ρ g).toFun (unitIsoAddEquiv x) := by dsimp [unitIsoAddEquiv, ofModuleMonoidAlgebra, toModuleMonoidAlgebra] /- Porting note: rest of broken proof was simp only [AddEquiv.apply_eq_iff_eq, AddEquiv.apply_symm_apply, Representation.asModuleEquiv_symm_map_rho, Representation.ofModule_asModule_act] -/ erw [Representation.asModuleEquiv_symm_map_rho] rfl /-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/ def unitIso (V : Rep k G) : V ≅ (toModuleMonoidAlgebra ⋙ ofModuleMonoidAlgebra).obj V := Action.mkIso (LinearEquiv.toModuleIso' { unitIsoAddEquiv with map_smul' := fun r x => by dsimp [unitIsoAddEquiv] /- Porting note: rest of broken proof was simp only [Representation.asModuleEquiv_symm_map_smul, RestrictScalars.addEquiv_symm_map_algebraMap_smul] -/ -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [AddEquiv.trans_apply, Representation.asModuleEquiv_symm_map_smul] rfl }) fun g => by ext; apply unit_iso_comm /-- The categorical equivalence `Rep k G ≌ ModuleCat (MonoidAlgebra k G)`. -/ def equivalenceModuleMonoidAlgebra : Rep k G ≌ ModuleCat.{u} (MonoidAlgebra k G) where functor := toModuleMonoidAlgebra inverse := ofModuleMonoidAlgebra unitIso := NatIso.ofComponents (fun V => unitIso V) (by aesop_cat) counitIso := NatIso.ofComponents (fun M => counitIso M) (by aesop_cat) -- TODO Verify that the equivalence with `ModuleCat (MonoidAlgebra k G)` is a monoidal functor. end end Rep
RepresentationTheory\Action\Basic.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Category.Grp.Basic import Mathlib.CategoryTheory.SingleObj import Mathlib.CategoryTheory.Limits.FunctorCategory import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Conj /-! # `Action V G`, the category of actions of a monoid `G` inside some category `V`. The prototypical example is `V = ModuleCat R`, where `Action (ModuleCat R) G` is the category of `R`-linear representations of `G`. We check `Action V G ≌ (singleObj G ⥤ V)`, and construct the restriction functors `res {G H : MonCat} (f : G ⟶ H) : Action V H ⥤ Action V G`. -/ universe u v open CategoryTheory Limits variable (V : Type (u + 1)) [LargeCategory V] -- Note: this is _not_ a categorical action of `G` on `V`. /-- An `Action V G` represents a bundled action of the monoid `G` on an object of some category `V`. As an example, when `V = ModuleCat R`, this is an `R`-linear representation of `G`, while when `V = Type` this is a `G`-action. -/ structure Action (G : MonCat.{u}) where V : V ρ : G ⟶ MonCat.of (End V) namespace Action variable {V} @[simp 1100] theorem ρ_one {G : MonCat.{u}} (A : Action V G) : A.ρ 1 = 𝟙 A.V := by rw [MonoidHom.map_one]; rfl /-- When a group acts, we can lift the action to the group of automorphisms. -/ @[simps] def ρAut {G : Grp.{u}} (A : Action V (MonCat.of G)) : G ⟶ Grp.of (Aut A.V) where toFun g := { hom := A.ρ g inv := A.ρ (g⁻¹ : G) hom_inv_id := (A.ρ.map_mul (g⁻¹ : G) g).symm.trans (by rw [inv_mul_self, ρ_one]) inv_hom_id := (A.ρ.map_mul g (g⁻¹ : G)).symm.trans (by rw [mul_inv_self, ρ_one]) } map_one' := Aut.ext A.ρ.map_one map_mul' x y := Aut.ext (A.ρ.map_mul x y) -- These lemmas have always been bad (#7657), but lean4#2644 made `simp` start noticing attribute [nolint simpNF] Action.ρAut_apply_inv Action.ρAut_apply_hom variable (G : MonCat.{u}) section instance inhabited' : Inhabited (Action (Type u) G) := ⟨⟨PUnit, 1⟩⟩ /-- The trivial representation of a group. -/ def trivial : Action AddCommGrp G where V := AddCommGrp.of PUnit ρ := 1 instance : Inhabited (Action AddCommGrp G) := ⟨trivial G⟩ end variable {G} /-- A homomorphism of `Action V G`s is a morphism between the underlying objects, commuting with the action of `G`. -/ @[ext] structure Hom (M N : Action V G) where hom : M.V ⟶ N.V comm : ∀ g : G, M.ρ g ≫ hom = hom ≫ N.ρ g := by aesop_cat namespace Hom attribute [reassoc] comm attribute [local simp] comm comm_assoc /-- The identity morphism on an `Action V G`. -/ @[simps] def id (M : Action V G) : Action.Hom M M where hom := 𝟙 M.V instance (M : Action V G) : Inhabited (Action.Hom M M) := ⟨id M⟩ /-- The composition of two `Action V G` homomorphisms is the composition of the underlying maps. -/ @[simps] def comp {M N K : Action V G} (p : Action.Hom M N) (q : Action.Hom N K) : Action.Hom M K where hom := p.hom ≫ q.hom end Hom instance : Category (Action V G) where Hom M N := Hom M N id M := Hom.id M comp f g := Hom.comp f g -- Porting note: added because `Hom.ext` is not triggered automatically @[ext] lemma hom_ext {M N : Action V G} (φ₁ φ₂ : M ⟶ N) (h : φ₁.hom = φ₂.hom) : φ₁ = φ₂ := Hom.ext h @[simp] theorem id_hom (M : Action V G) : (𝟙 M : Hom M M).hom = 𝟙 M.V := rfl @[simp] theorem comp_hom {M N K : Action V G} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl /-- Construct an isomorphism of `G` actions/representations from an isomorphism of the underlying objects, where the forward direction commutes with the group action. -/ @[simps] def mkIso {M N : Action V G} (f : M.V ≅ N.V) (comm : ∀ g : G, M.ρ g ≫ f.hom = f.hom ≫ N.ρ g := by aesop_cat) : M ≅ N where hom := { hom := f.hom comm := comm } inv := { hom := f.inv comm := fun g => by have w := comm g =≫ f.inv; simp at w; simp [w] } instance (priority := 100) isIso_of_hom_isIso {M N : Action V G} (f : M ⟶ N) [IsIso f.hom] : IsIso f := (mkIso (asIso f.hom) f.comm).isIso_hom instance isIso_hom_mk {M N : Action V G} (f : M.V ⟶ N.V) [IsIso f] (w) : @IsIso _ _ M N (Hom.mk f w) := (mkIso (asIso f) w).isIso_hom namespace FunctorCategoryEquivalence /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps] def functor : Action V G ⥤ SingleObj G ⥤ V where obj M := { obj := fun _ => M.V map := fun g => M.ρ g map_id := fun _ => M.ρ.map_one map_comp := fun g h => M.ρ.map_mul h g } map f := { app := fun _ => f.hom naturality := fun _ _ g => f.comm g } /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps] def inverse : (SingleObj G ⥤ V) ⥤ Action V G where obj F := { V := F.obj PUnit.unit ρ := { toFun := fun g => F.map g map_one' := F.map_id PUnit.unit map_mul' := fun g h => F.map_comp h g } } map f := { hom := f.app PUnit.unit comm := fun g => f.naturality g } /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps!] def unitIso : 𝟭 (Action V G) ≅ functor ⋙ inverse := NatIso.ofComponents fun M => mkIso (Iso.refl _) /-- Auxiliary definition for `functorCategoryEquivalence`. -/ @[simps!] def counitIso : inverse ⋙ functor ≅ 𝟭 (SingleObj G ⥤ V) := NatIso.ofComponents fun M => NatIso.ofComponents fun X => Iso.refl _ end FunctorCategoryEquivalence section open FunctorCategoryEquivalence variable (V G) /-- The category of actions of `G` in the category `V` is equivalent to the functor category `singleObj G ⥤ V`. -/ @[simps] def functorCategoryEquivalence : Action V G ≌ SingleObj G ⥤ V where functor := functor inverse := inverse unitIso := unitIso counitIso := counitIso /- porting note: these two lemmas are redundant with the projections created by the @[simps] attribute above theorem functorCategoryEquivalence.functor_def : (functorCategoryEquivalence V G).functor = FunctorCategoryEquivalence.functor := rfl theorem functorCategoryEquivalence.inverse_def : (functorCategoryEquivalence V G).inverse = FunctorCategoryEquivalence.inverse := rfl -/ end section Forget variable (V G) /-- (implementation) The forgetful functor from bundled actions to the underlying objects. Use the `CategoryTheory.forget` API provided by the `ConcreteCategory` instance below, rather than using this directly. -/ @[simps] def forget : Action V G ⥤ V where obj M := M.V map f := f.hom instance : (forget V G).Faithful where map_injective w := Hom.ext w instance [ConcreteCategory V] : ConcreteCategory (Action V G) where forget := forget V G ⋙ ConcreteCategory.forget instance hasForgetToV [ConcreteCategory V] : HasForget₂ (Action V G) V where forget₂ := forget V G /-- The forgetful functor is intertwined by `functorCategoryEquivalence` with evaluation at `PUnit.star`. -/ def functorCategoryEquivalenceCompEvaluation : (functorCategoryEquivalence V G).functor ⋙ (evaluation _ _).obj PUnit.unit ≅ forget V G := Iso.refl _ noncomputable instance instPreservesLimitsForget [HasLimits V] : Limits.PreservesLimits (forget V G) := Limits.preservesLimitsOfNatIso (Action.functorCategoryEquivalenceCompEvaluation V G) noncomputable instance instPreservesColimitsForget [HasColimits V] : PreservesColimits (forget V G) := preservesColimitsOfNatIso (Action.functorCategoryEquivalenceCompEvaluation V G) -- TODO construct categorical images? end Forget theorem Iso.conj_ρ {M N : Action V G} (f : M ≅ N) (g : G) : N.ρ g = ((forget V G).mapIso f).conj (M.ρ g) := by rw [Iso.conj_apply, Iso.eq_inv_comp]; simp [f.hom.comm] /-- Actions/representations of the trivial group are just objects in the ambient category. -/ def actionPunitEquivalence : Action V (MonCat.of PUnit) ≌ V where functor := forget V _ inverse := { obj := fun X => ⟨X, 1⟩ map := fun f => ⟨f, fun ⟨⟩ => by simp⟩ } unitIso := NatIso.ofComponents fun X => mkIso (Iso.refl _) fun ⟨⟩ => by simp only [MonCat.oneHom_apply, MonCat.one_of, End.one_def, id_eq, Functor.comp_obj, forget_obj, Iso.refl_hom, Category.comp_id] exact ρ_one X counitIso := NatIso.ofComponents fun X => Iso.refl _ variable (V) /-- The "restriction" functor along a monoid homomorphism `f : G ⟶ H`, taking actions of `H` to actions of `G`. (This makes sense for any homomorphism, but the name is natural when `f` is a monomorphism.) -/ @[simps] def res {G H : MonCat} (f : G ⟶ H) : Action V H ⥤ Action V G where obj M := { V := M.V ρ := f ≫ M.ρ } map p := { hom := p.hom comm := fun g => p.comm (f g) } /-- The natural isomorphism from restriction along the identity homomorphism to the identity functor on `Action V G`. -/ @[simps!] def resId {G : MonCat} : res V (𝟙 G) ≅ 𝟭 (Action V G) := NatIso.ofComponents fun M => mkIso (Iso.refl _) /-- The natural isomorphism from the composition of restrictions along homomorphisms to the restriction along the composition of homomorphism. -/ @[simps!] def resComp {G H K : MonCat} (f : G ⟶ H) (g : H ⟶ K) : res V g ⋙ res V f ≅ res V (f ≫ g) := NatIso.ofComponents fun M => mkIso (Iso.refl _) -- TODO promote `res` to a pseudofunctor from -- the locally discrete bicategory constructed from `Monᵒᵖ` to `Cat`, sending `G` to `Action V G`. end Action namespace CategoryTheory.Functor variable {V} {W : Type (u + 1)} [LargeCategory W] /-- A functor between categories induces a functor between the categories of `G`-actions within those categories. -/ @[simps] def mapAction (F : V ⥤ W) (G : MonCat.{u}) : Action V G ⥤ Action W G where obj M := { V := F.obj M.V ρ := { toFun := fun g => F.map (M.ρ g) map_one' := by simp only [End.one_def, Action.ρ_one, F.map_id, MonCat.one_of] map_mul' := fun g h => by dsimp rw [map_mul, MonCat.mul_of, End.mul_def, End.mul_def, F.map_comp] } } map f := { hom := F.map f.hom comm := fun g => by dsimp; rw [← F.map_comp, f.comm, F.map_comp] } map_id M := by ext; simp only [Action.id_hom, F.map_id] map_comp f g := by ext; simp only [Action.comp_hom, F.map_comp] end CategoryTheory.Functor
RepresentationTheory\Action\Concrete.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Action.Pi import Mathlib.CategoryTheory.FintypeCat import Mathlib.RepresentationTheory.Action.Basic /-! # Constructors for `Action V G` for some concrete categories We construct `Action (Type u) G` from a `[MulAction G X]` instance and give some applications. -/ universe u v open CategoryTheory Limits namespace Action /-- Bundles a type `H` with a multiplicative action of `G` as an `Action`. -/ def ofMulAction (G H : Type u) [Monoid G] [MulAction G H] : Action (Type u) (MonCat.of G) where V := H ρ := @MulAction.toEndHom _ _ _ (by assumption) @[simp] theorem ofMulAction_apply {G H : Type u} [Monoid G] [MulAction G H] (g : G) (x : H) : (ofMulAction G H).ρ g x = (g • x : H) := rfl /-- Given a family `F` of types with `G`-actions, this is the limit cone demonstrating that the product of `F` as types is a product in the category of `G`-sets. -/ def ofMulActionLimitCone {ι : Type v} (G : Type max v u) [Monoid G] (F : ι → Type max v u) [∀ i : ι, MulAction G (F i)] : LimitCone (Discrete.functor fun i : ι => Action.ofMulAction G (F i)) where cone := { pt := Action.ofMulAction G (∀ i : ι, F i) π := Discrete.natTrans (fun i => ⟨fun x => x i.as, fun g => rfl⟩) } isLimit := { lift := fun s => { hom := fun x i => (s.π.app ⟨i⟩).hom x comm := fun g => by ext x funext j exact congr_fun ((s.π.app ⟨j⟩).comm g) x } fac := fun s j => rfl uniq := fun s f h => by ext x funext j dsimp at * rw [← h ⟨j⟩] rfl } /-- The `G`-set `G`, acting on itself by left multiplication. -/ @[simps!] def leftRegular (G : Type u) [Monoid G] : Action (Type u) (MonCat.of G) := Action.ofMulAction G G /-- The `G`-set `Gⁿ`, acting on itself by left multiplication. -/ @[simps!] def diagonal (G : Type u) [Monoid G] (n : ℕ) : Action (Type u) (MonCat.of G) := Action.ofMulAction G (Fin n → G) /-- We have `Fin 1 → G ≅ G` as `G`-sets, with `G` acting by left multiplication. -/ def diagonalOneIsoLeftRegular (G : Type u) [Monoid G] : diagonal G 1 ≅ leftRegular G := Action.mkIso (Equiv.funUnique _ _).toIso fun _ => rfl namespace FintypeCat /-- Bundles a finite type `H` with a multiplicative action of `G` as an `Action`. -/ def ofMulAction (G : Type u) (H : FintypeCat.{u}) [Monoid G] [MulAction G H] : Action FintypeCat (MonCat.of G) where V := H ρ := @MulAction.toEndHom _ _ _ (by assumption) @[simp] theorem ofMulAction_apply {G : Type u} {H : FintypeCat.{u}} [Monoid G] [MulAction G H] (g : G) (x : H) : (FintypeCat.ofMulAction G H).ρ g x = (g • x : H) := rfl end FintypeCat section ToMulAction variable {V : Type (u + 1)} [LargeCategory V] [ConcreteCategory V] instance instMulAction {G : MonCat.{u}} (X : Action V G) : MulAction G ((CategoryTheory.forget _).obj X) where smul g x := ((CategoryTheory.forget _).map (X.ρ g)) x one_smul x := by show ((CategoryTheory.forget _).map (X.ρ 1)) x = x simp only [Action.ρ_one, FunctorToTypes.map_id_apply] mul_smul g h x := by show (CategoryTheory.forget V).map (X.ρ (g * h)) x = ((CategoryTheory.forget V).map (X.ρ h) ≫ (CategoryTheory.forget V).map (X.ρ g)) x rw [← Functor.map_comp, map_mul] rfl /- Specialize `instMulAction` to assist typeclass inference. -/ instance {G : MonCat.{u}} (X : Action FintypeCat G) : MulAction G X.V := Action.instMulAction X instance {G : Type u} [Group G] (X : Action FintypeCat (MonCat.of G)) : MulAction G X.V := Action.instMulAction X end ToMulAction end Action
RepresentationTheory\Action\Continuous.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.RepresentationTheory.Action.Basic import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.Category.TopCat.Basic /-! # Topological subcategories of `Action V G` For a concrete category `V`, where the forgetful functor factors via `TopCat`, and a monoid `G`, equipped with a topological space instance, we define the full subcategory `ContAction V G` of all objects of `Action V G` where the induced action is continuous. We also define a category `DiscreteContAction V G` as the full subcategory of `ContAction V G`, where the underlying topological space is discrete. Finally we define inclusion functors into `Action V G` and `TopCat` in terms of `HasForget₂` instances. -/ universe u v open CategoryTheory Limits variable (V : Type (u + 1)) [LargeCategory V] [ConcreteCategory V] [HasForget₂ V TopCat] variable (G : MonCat.{u}) [TopologicalSpace G] namespace Action instance : HasForget₂ (Action V G) TopCat := HasForget₂.trans (Action V G) V TopCat instance (X : Action V G) : MulAction G ((CategoryTheory.forget₂ _ TopCat).obj X) where smul g x := ((CategoryTheory.forget₂ _ TopCat).map (X.ρ g)) x one_smul x := by show ((CategoryTheory.forget₂ _ TopCat).map (X.ρ 1)) x = x simp mul_smul g h x := by show (CategoryTheory.forget₂ _ TopCat).map (X.ρ (g * h)) x = ((CategoryTheory.forget₂ _ TopCat).map (X.ρ h) ≫ (CategoryTheory.forget₂ _ TopCat).map (X.ρ g)) x rw [← Functor.map_comp, map_mul] rfl variable {V G} /-- For `HasForget₂ V TopCat` a predicate on an `X : Action V G` saying that the induced action on the underlying topological space is continuous. -/ abbrev IsContinuous (X : Action V G) : Prop := ContinuousSMul G ((CategoryTheory.forget₂ _ TopCat).obj X) end Action open Action /-- For `HasForget₂ V TopCat`, this is the full subcategory of `Action V G` where the induced action is continuous. -/ def ContAction : Type _ := FullSubcategory (IsContinuous (V := V) (G := G)) namespace ContAction instance : Category (ContAction V G) := FullSubcategory.category (IsContinuous (V := V) (G := G)) instance : ConcreteCategory (ContAction V G) := FullSubcategory.concreteCategory (IsContinuous (V := V) (G := G)) instance : HasForget₂ (ContAction V G) (Action V G) := FullSubcategory.hasForget₂ (IsContinuous (V := V) (G := G)) instance : HasForget₂ (ContAction V G) V := HasForget₂.trans (ContAction V G) (Action V G) V instance : HasForget₂ (ContAction V G) TopCat := HasForget₂.trans (ContAction V G) (Action V G) TopCat instance : Coe (ContAction V G) (Action V G) where coe X := X.obj variable {V G} /-- A predicate on an `X : ContAction V G` saying that the topology on the underlying type of `X` is discrete. -/ abbrev IsDiscrete (X : ContAction V G) : Prop := DiscreteTopology ((CategoryTheory.forget₂ _ TopCat).obj X) end ContAction open ContAction /-- The subcategory of `ContAction V G` where the topology is discrete. -/ def DiscreteContAction : Type _ := FullSubcategory (IsDiscrete (V := V) (G := G)) namespace DiscreteContAction instance : Category (DiscreteContAction V G) := FullSubcategory.category (IsDiscrete (V := V) (G := G)) instance : ConcreteCategory (DiscreteContAction V G) := FullSubcategory.concreteCategory (IsDiscrete (V := V) (G := G)) instance : HasForget₂ (DiscreteContAction V G) (ContAction V G) := FullSubcategory.hasForget₂ (IsDiscrete (V := V) (G := G)) instance : HasForget₂ (DiscreteContAction V G) TopCat := HasForget₂.trans (DiscreteContAction V G) (ContAction V G) TopCat variable {V G} instance (X : DiscreteContAction V G) : DiscreteTopology ((CategoryTheory.forget₂ _ TopCat).obj X) := X.property end DiscreteContAction
RepresentationTheory\Action\Limits.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Abelian.FunctorCategory import Mathlib.CategoryTheory.Abelian.Transfer import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.CategoryTheory.Linear.FunctorCategory import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.RepresentationTheory.Action.Basic /-! # Categorical properties of `Action V G` We show: * When `V` has (co)limits so does `Action V G`. * When `V` is preadditive, linear, or abelian so is `Action V G`. -/ universe u v w₁ w₂ t₁ t₂ open CategoryTheory Limits variable {V : Type (u + 1)} [LargeCategory V] {G : MonCat.{u}} namespace Action section Limits instance [HasFiniteProducts V] : HasFiniteProducts (Action V G) where out _ := Adjunction.hasLimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasFiniteLimits V] : HasFiniteLimits (Action V G) where out _ _ _ := Adjunction.hasLimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasLimits V] : HasLimits (Action V G) := Adjunction.has_limits_of_equivalence (Action.functorCategoryEquivalence _ _).functor /-- If `V` has limits of shape `J`, so does `Action V G`. -/ instance hasLimitsOfShape {J : Type w₁} [Category.{w₂} J] [HasLimitsOfShape J V] : HasLimitsOfShape J (Action V G) := Adjunction.hasLimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasFiniteCoproducts V] : HasFiniteCoproducts (Action V G) where out _ := Adjunction.hasColimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasFiniteColimits V] : HasFiniteColimits (Action V G) where out _ _ _ := Adjunction.hasColimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor instance [HasColimits V] : HasColimits (Action V G) := Adjunction.has_colimits_of_equivalence (Action.functorCategoryEquivalence _ _).functor /-- If `V` has colimits of shape `J`, so does `Action V G`. -/ instance hasColimitsOfShape {J : Type w₁} [Category.{w₂} J] [HasColimitsOfShape J V] : HasColimitsOfShape J (Action V G) := Adjunction.hasColimitsOfShape_of_equivalence (Action.functorCategoryEquivalence _ _).functor end Limits section Preservation variable {C : Type t₁} [Category.{t₂} C] /-- `F : C ⥤ SingleObj G ⥤ V` preserves the limit of some `K : J ⥤ C` if it does evaluated at `SingleObj.star G`. -/ private def SingleObj.preservesLimit (F : C ⥤ SingleObj G ⥤ V) {J : Type w₁} [Category.{w₂} J] (K : J ⥤ C) (h : PreservesLimit K (F ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G))) : PreservesLimit K F := by apply preservesLimitOfEvaluation intro _ exact h /-- `F : C ⥤ Action V G` preserves the limit of some `K : J ⥤ C` if if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ noncomputable def preservesLimitOfPreserves (F : C ⥤ Action V G) {J : Type w₁} [Category.{w₂} J] (K : J ⥤ C) (h : PreservesLimit K (F ⋙ Action.forget V G)) : PreservesLimit K F := by let F' : C ⥤ SingleObj G ⥤ V := F ⋙ (Action.functorCategoryEquivalence V G).functor have : PreservesLimit K F' := SingleObj.preservesLimit _ _ h apply preservesLimitOfReflectsOfPreserves F (Action.functorCategoryEquivalence V G).functor /-- `F : C ⥤ Action V G` preserves limits of some shape `J` if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ noncomputable def preservesLimitsOfShapeOfPreserves (F : C ⥤ Action V G) {J : Type w₁} [Category.{w₂} J] (h : PreservesLimitsOfShape J (F ⋙ Action.forget V G)) : PreservesLimitsOfShape J F := by constructor intro K apply Action.preservesLimitOfPreserves exact PreservesLimitsOfShape.preservesLimit /-- `F : C ⥤ Action V G` preserves limits of some size if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ noncomputable def preservesLimitsOfSizeOfPreserves (F : C ⥤ Action V G) (h : PreservesLimitsOfSize.{w₂, w₁} (F ⋙ Action.forget V G)) : PreservesLimitsOfSize.{w₂, w₁} F := by constructor intro J _ apply Action.preservesLimitsOfShapeOfPreserves exact PreservesLimitsOfSize.preservesLimitsOfShape /-- `F : C ⥤ SingleObj G ⥤ V` preserves the colimit of some `K : J ⥤ C` if it does evaluated at `SingleObj.star G`. -/ private def SingleObj.preservesColimit (F : C ⥤ SingleObj G ⥤ V) {J : Type w₁} [Category.{w₂} J] (K : J ⥤ C) (h : PreservesColimit K (F ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G))) : PreservesColimit K F := by apply preservesColimitOfEvaluation intro _ exact h /-- `F : C ⥤ Action V G` preserves the colimit of some `K : J ⥤ C` if if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ noncomputable def preservesColimitOfPreserves (F : C ⥤ Action V G) {J : Type w₁} [Category.{w₂} J] (K : J ⥤ C) (h : PreservesColimit K (F ⋙ Action.forget V G)) : PreservesColimit K F := by let F' : C ⥤ SingleObj G ⥤ V := F ⋙ (Action.functorCategoryEquivalence V G).functor have : PreservesColimit K F' := SingleObj.preservesColimit _ _ h apply preservesColimitOfReflectsOfPreserves F (Action.functorCategoryEquivalence V G).functor /-- `F : C ⥤ Action V G` preserves colimits of some shape `J` if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ noncomputable def preservesColimitsOfShapeOfPreserves (F : C ⥤ Action V G) {J : Type w₁} [Category.{w₂} J] (h : PreservesColimitsOfShape J (F ⋙ Action.forget V G)) : PreservesColimitsOfShape J F := by constructor intro K apply Action.preservesColimitOfPreserves exact PreservesColimitsOfShape.preservesColimit /-- `F : C ⥤ Action V G` preserves colimits of some size if it does after postcomposing with the forgetful functor `Action V G ⥤ V`. -/ noncomputable def preservesColimitsOfSizeOfPreserves (F : C ⥤ Action V G) (h : PreservesColimitsOfSize.{w₂, w₁} (F ⋙ Action.forget V G)) : PreservesColimitsOfSize.{w₂, w₁} F := by constructor intro J _ apply Action.preservesColimitsOfShapeOfPreserves exact PreservesColimitsOfSize.preservesColimitsOfShape end Preservation section Forget noncomputable instance {J : Type w₁} [Category.{w₂} J] [HasLimitsOfShape J V] : PreservesLimitsOfShape J (Action.forget V G) := by show PreservesLimitsOfShape J ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) infer_instance noncomputable instance {J : Type w₁} [Category.{w₂} J] [HasColimitsOfShape J V] : PreservesColimitsOfShape J (Action.forget V G) := by show PreservesColimitsOfShape J ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) infer_instance noncomputable instance [HasFiniteLimits V] : PreservesFiniteLimits (Action.forget V G) := by show PreservesFiniteLimits ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) have : PreservesFiniteLimits ((evaluation (SingleObj G) V).obj (SingleObj.star G)) := by constructor intro _ _ _ infer_instance apply compPreservesFiniteLimits noncomputable instance [HasFiniteColimits V] : PreservesFiniteColimits (Action.forget V G) := by show PreservesFiniteColimits ((Action.functorCategoryEquivalence V G).functor ⋙ (evaluation (SingleObj G) V).obj (SingleObj.star G)) have : PreservesFiniteColimits ((evaluation (SingleObj G) V).obj (SingleObj.star G)) := by constructor intro _ _ _ infer_instance apply compPreservesFiniteColimits noncomputable instance {J : Type w₁} [Category.{w₂} J] (F : J ⥤ Action V G) : ReflectsLimit F (Action.forget V G) where reflects h := by apply isLimitOfReflects ((Action.functorCategoryEquivalence V G).functor) exact evaluationJointlyReflectsLimits _ (fun _ => h) noncomputable instance {J : Type w₁} [Category.{w₂} J] : ReflectsLimitsOfShape J (Action.forget V G) where noncomputable instance : ReflectsLimits (Action.forget V G) where noncomputable instance {J : Type w₁} [Category.{w₂} J] (F : J ⥤ Action V G) : ReflectsColimit F (Action.forget V G) where reflects h := by apply isColimitOfReflects ((Action.functorCategoryEquivalence V G).functor) exact evaluationJointlyReflectsColimits _ (fun _ => h) noncomputable instance {J : Type w₁} [Category.{w₂} J] : ReflectsColimitsOfShape J (Action.forget V G) where noncomputable instance : ReflectsColimits (Action.forget V G) where end Forget section HasZeroMorphisms variable [HasZeroMorphisms V] -- porting note (#10688): in order to ease automation, the `Zero` instance is introduced separately, -- and the lemma `Action.zero_hom` was moved just below instance {X Y : Action V G} : Zero (X ⟶ Y) := ⟨0, by aesop_cat⟩ @[simp] theorem zero_hom {X Y : Action V G} : (0 : X ⟶ Y).hom = 0 := rfl instance : HasZeroMorphisms (Action V G) where instance forget_preservesZeroMorphisms : Functor.PreservesZeroMorphisms (forget V G) where instance forget₂_preservesZeroMorphisms [ConcreteCategory V] : Functor.PreservesZeroMorphisms (forget₂ (Action V G) V) where instance functorCategoryEquivalence_preservesZeroMorphisms : Functor.PreservesZeroMorphisms (functorCategoryEquivalence V G).functor where end HasZeroMorphisms section Preadditive variable [Preadditive V] instance {X Y : Action V G} : Add (X ⟶ Y) where add f g := ⟨f.hom + g.hom, by simp [f.comm, g.comm]⟩ instance {X Y : Action V G} : Neg (X ⟶ Y) where neg f := ⟨-f.hom, by simp [f.comm]⟩ instance : Preadditive (Action V G) where homGroup X Y := { nsmul := nsmulRec zsmul := zsmulRec zero_add := by intros; ext; exact zero_add _ add_zero := by intros; ext; exact add_zero _ add_assoc := by intros; ext; exact add_assoc _ _ _ add_left_neg := by intros; ext; exact add_left_neg _ add_comm := by intros; ext; exact add_comm _ _ } add_comp := by intros; ext; exact Preadditive.add_comp _ _ _ _ _ _ comp_add := by intros; ext; exact Preadditive.comp_add _ _ _ _ _ _ instance forget_additive : Functor.Additive (forget V G) where instance forget₂_additive [ConcreteCategory V] : Functor.Additive (forget₂ (Action V G) V) where instance functorCategoryEquivalence_additive : Functor.Additive (functorCategoryEquivalence V G).functor where @[simp] theorem neg_hom {X Y : Action V G} (f : X ⟶ Y) : (-f).hom = -f.hom := rfl @[simp] theorem add_hom {X Y : Action V G} (f g : X ⟶ Y) : (f + g).hom = f.hom + g.hom := rfl @[simp] theorem sum_hom {X Y : Action V G} {ι : Type*} (f : ι → (X ⟶ Y)) (s : Finset ι) : (s.sum f).hom = s.sum fun i => (f i).hom := (forget V G).map_sum f s end Preadditive section Linear variable [Preadditive V] {R : Type*} [Semiring R] [Linear R V] instance : Linear R (Action V G) where homModule X Y := { smul := fun r f => ⟨r • f.hom, by simp [f.comm]⟩ one_smul := by intros; ext; exact one_smul _ _ smul_zero := by intros; ext; exact smul_zero _ zero_smul := by intros; ext; exact zero_smul _ _ add_smul := by intros; ext; exact add_smul _ _ _ smul_add := by intros; ext; exact smul_add _ _ _ mul_smul := by intros; ext; exact mul_smul _ _ _ } smul_comp := by intros; ext; exact Linear.smul_comp _ _ _ _ _ _ comp_smul := by intros; ext; exact Linear.comp_smul _ _ _ _ _ _ instance forget_linear : Functor.Linear R (forget V G) where instance forget₂_linear [ConcreteCategory V] : Functor.Linear R (forget₂ (Action V G) V) where instance functorCategoryEquivalence_linear : Functor.Linear R (functorCategoryEquivalence V G).functor where @[simp] theorem smul_hom {X Y : Action V G} (r : R) (f : X ⟶ Y) : (r • f).hom = r • f.hom := rfl variable {H : MonCat.{u}} (f : G ⟶ H) instance res_additive : (res V f).Additive where instance res_linear : (res V f).Linear R where end Linear section Abelian /-- Auxiliary construction for the `Abelian (Action V G)` instance. -/ def abelianAux : Action V G ≌ ULift.{u} (SingleObj G) ⥤ V := (functorCategoryEquivalence V G).trans (Equivalence.congrLeft ULift.equivalence) noncomputable instance [Abelian V] : Abelian (Action V G) := abelianOfEquivalence abelianAux.functor end Abelian end Action namespace CategoryTheory.Functor variable {W : Type (u + 1)} [LargeCategory W] (F : V ⥤ W) (G : MonCat.{u}) [Preadditive V] [Preadditive W] instance mapAction_preadditive [F.Additive] : (F.mapAction G).Additive where variable {R : Type*} [Semiring R] [CategoryTheory.Linear R V] [CategoryTheory.Linear R W] instance mapAction_linear [F.Additive] [F.Linear R] : (F.mapAction G).Linear R where end CategoryTheory.Functor
RepresentationTheory\Action\Monoidal.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.RepresentationTheory.Action.Limits import Mathlib.RepresentationTheory.Action.Concrete import Mathlib.CategoryTheory.Monoidal.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.CategoryTheory.Monoidal.Rigid.OfEquivalence import Mathlib.CategoryTheory.Monoidal.Rigid.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Linear import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.Types.Basic /-! # Induced monoidal structure on `Action V G` We show: * When `V` is monoidal, braided, or symmetric, so is `Action V G`. -/ universe u v open CategoryTheory Limits variable {V : Type (u + 1)} [LargeCategory V] {G : MonCat.{u}} namespace Action section Monoidal open MonoidalCategory variable [MonoidalCategory V] instance instMonoidalCategory : MonoidalCategory (Action V G) := Monoidal.transport (Action.functorCategoryEquivalence _ _).symm @[simp] theorem tensorUnit_v : (𝟙_ (Action V G)).V = 𝟙_ V := rfl -- Porting note: removed @[simp] as the simpNF linter complains theorem tensorUnit_rho {g : G} : (𝟙_ (Action V G)).ρ g = 𝟙 (𝟙_ V) := rfl @[simp] theorem tensor_v {X Y : Action V G} : (X ⊗ Y).V = X.V ⊗ Y.V := rfl -- Porting note: removed @[simp] as the simpNF linter complains theorem tensor_rho {X Y : Action V G} {g : G} : (X ⊗ Y).ρ g = X.ρ g ⊗ Y.ρ g := rfl @[simp] theorem tensor_hom {W X Y Z : Action V G} (f : W ⟶ X) (g : Y ⟶ Z) : (f ⊗ g).hom = f.hom ⊗ g.hom := rfl @[simp] theorem whiskerLeft_hom (X : Action V G) {Y Z : Action V G} (f : Y ⟶ Z) : (X ◁ f).hom = X.V ◁ f.hom := rfl @[simp] theorem whiskerRight_hom {X Y : Action V G} (f : X ⟶ Y) (Z : Action V G) : (f ▷ Z).hom = f.hom ▷ Z.V := rfl -- Porting note: removed @[simp] as the simpNF linter complains theorem associator_hom_hom {X Y Z : Action V G} : Hom.hom (α_ X Y Z).hom = (α_ X.V Y.V Z.V).hom := by dsimp simp -- Porting note: removed @[simp] as the simpNF linter complains theorem associator_inv_hom {X Y Z : Action V G} : Hom.hom (α_ X Y Z).inv = (α_ X.V Y.V Z.V).inv := by dsimp simp -- Porting note: removed @[simp] as the simpNF linter complains theorem leftUnitor_hom_hom {X : Action V G} : Hom.hom (λ_ X).hom = (λ_ X.V).hom := by dsimp simp -- Porting note: removed @[simp] as the simpNF linter complains theorem leftUnitor_inv_hom {X : Action V G} : Hom.hom (λ_ X).inv = (λ_ X.V).inv := by dsimp simp -- Porting note: removed @[simp] as the simpNF linter complains theorem rightUnitor_hom_hom {X : Action V G} : Hom.hom (ρ_ X).hom = (ρ_ X.V).hom := by dsimp simp -- Porting note: removed @[simp] as the simpNF linter complains theorem rightUnitor_inv_hom {X : Action V G} : Hom.hom (ρ_ X).inv = (ρ_ X.V).inv := by dsimp simp /-- Given an object `X` isomorphic to the tensor unit of `V`, `X` equipped with the trivial action is isomorphic to the tensor unit of `Action V G`. -/ def tensorUnitIso {X : V} (f : 𝟙_ V ≅ X) : 𝟙_ (Action V G) ≅ Action.mk X 1 := Action.mkIso f fun _ => by simp only [MonoidHom.one_apply, End.one_def, Category.id_comp f.hom, tensorUnit_rho, MonCat.oneHom_apply, MonCat.one_of, Category.comp_id] variable (V G) /-- When `V` is monoidal the forgetful functor `Action V G` to `V` is monoidal. -/ @[simps] def forgetMonoidal : MonoidalFunctor (Action V G) V := { toFunctor := Action.forget _ _ ε := 𝟙 _ μ := fun X Y => 𝟙 _ } instance forgetMonoidal_faithful : (forgetMonoidal V G).Faithful := by change (forget V G).Faithful; infer_instance section variable [BraidedCategory V] instance : BraidedCategory (Action V G) := braidedCategoryOfFaithful (forgetMonoidal V G) (fun X Y => mkIso (β_ _ _) (fun g => by simp [FunctorCategoryEquivalence.inverse])) (by aesop_cat) /-- When `V` is braided the forgetful functor `Action V G` to `V` is braided. -/ @[simps!] def forgetBraided : BraidedFunctor (Action V G) V := { forgetMonoidal _ _ with } instance forgetBraided_faithful : (forgetBraided V G).Faithful := by change (forget V G).Faithful; infer_instance end instance [SymmetricCategory V] : SymmetricCategory (Action V G) := symmetricCategoryOfFaithful (forgetBraided V G) section variable [Preadditive V] [MonoidalPreadditive V] attribute [local simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight instance : MonoidalPreadditive (Action V G) where variable {R : Type*} [Semiring R] [Linear R V] [MonoidalLinear R V] instance : MonoidalLinear R (Action V G) where end noncomputable section /-- Upgrading the functor `Action V G ⥤ (SingleObj G ⥤ V)` to a monoidal functor. -/ def functorCategoryMonoidalEquivalence : MonoidalFunctor (Action V G) (SingleObj G ⥤ V) := Monoidal.fromTransported (Action.functorCategoryEquivalence _ _).symm /-- Upgrading the functor `(SingleObj G ⥤ V) ⥤ Action V G` to a monoidal functor. -/ def functorCategoryMonoidalEquivalenceInverse : MonoidalFunctor (SingleObj G ⥤ V) (Action V G) := Monoidal.toTransported (Action.functorCategoryEquivalence _ _).symm /-- The adjunction (which is an equivalence) between the categories `Action V G` and `(SingleObj G ⥤ V)`. -/ def functorCategoryMonoidalAdjunction : (functorCategoryMonoidalEquivalence V G).toFunctor ⊣ (functorCategoryMonoidalEquivalenceInverse V G).toFunctor := (Action.functorCategoryEquivalence _ _).toAdjunction instance : (functorCategoryMonoidalEquivalence V G).IsEquivalence := by change (Action.functorCategoryEquivalence _ _).functor.IsEquivalence; infer_instance @[simp] theorem functorCategoryMonoidalEquivalence.μ_app (A B : Action V G) : ((functorCategoryMonoidalEquivalence V G).μ A B).app PUnit.unit = 𝟙 _ := rfl @[simp] theorem functorCategoryMonoidalEquivalence.μIso_inv_app (A B : Action V G) : ((functorCategoryMonoidalEquivalence V G).μIso A B).inv.app PUnit.unit = 𝟙 _ := by rw [← NatIso.app_inv, ← IsIso.Iso.inv_hom] refine IsIso.inv_eq_of_hom_inv_id ?_ rw [Category.comp_id, NatIso.app_hom, MonoidalFunctor.μIso_hom, functorCategoryMonoidalEquivalence.μ_app] @[simp] theorem functorCategoryMonoidalEquivalence.ε_app : (functorCategoryMonoidalEquivalence V G).ε.app PUnit.unit = 𝟙 _ := by dsimp only [functorCategoryMonoidalEquivalence] simp only [Monoidal.fromTransported_toLaxMonoidalFunctor_ε] rfl @[simp] theorem functorCategoryMonoidalAdjunction.unit_app_hom (A : Action V G) : ((functorCategoryMonoidalAdjunction _ _).unit.app A).hom = 𝟙 _ := rfl @[simp] theorem functorCategoryMonoidalAdjunction.counit_app_app (A : SingleObj G ⥤ V) : ((functorCategoryMonoidalAdjunction _ _).counit.app A).app PUnit.unit = 𝟙 _ := rfl @[simp] theorem functorCategoryMonoidalEquivalence.functor_map {A B : Action V G} (f : A ⟶ B) : (functorCategoryMonoidalEquivalence _ _).map f = FunctorCategoryEquivalence.functor.map f := rfl @[simp] theorem functorCategoryMonoidalEquivalence.inverse_map {A B : SingleObj G ⥤ V} (f : A ⟶ B) : (functorCategoryMonoidalEquivalenceInverse _ _).map f = FunctorCategoryEquivalence.inverse.map f := rfl variable (H : Grp.{u}) instance [RightRigidCategory V] : RightRigidCategory (SingleObj (H : MonCat.{u}) ⥤ V) := by change RightRigidCategory (SingleObj H ⥤ V); infer_instance /-- If `V` is right rigid, so is `Action V G`. -/ instance [RightRigidCategory V] : RightRigidCategory (Action V H) := rightRigidCategoryOfEquivalence (functorCategoryMonoidalAdjunction V _) instance [LeftRigidCategory V] : LeftRigidCategory (SingleObj (H : MonCat.{u}) ⥤ V) := by change LeftRigidCategory (SingleObj H ⥤ V); infer_instance /-- If `V` is left rigid, so is `Action V G`. -/ instance [LeftRigidCategory V] : LeftRigidCategory (Action V H) := leftRigidCategoryOfEquivalence (functorCategoryMonoidalAdjunction V _) instance [RigidCategory V] : RigidCategory (SingleObj (H : MonCat.{u}) ⥤ V) := by change RigidCategory (SingleObj H ⥤ V); infer_instance /-- If `V` is rigid, so is `Action V G`. -/ instance [RigidCategory V] : RigidCategory (Action V H) := rigidCategoryOfEquivalence (functorCategoryMonoidalAdjunction V _) variable {V H} variable (X : Action V H) @[simp] theorem rightDual_v [RightRigidCategory V] : Xᘁ.V = X.Vᘁ := rfl @[simp] theorem leftDual_v [LeftRigidCategory V] : (ᘁX).V = ᘁX.V := rfl -- This lemma was always bad, but the linter only noticed after lean4#2644 @[simp, nolint simpNF] theorem rightDual_ρ [RightRigidCategory V] (h : H) : Xᘁ.ρ h = (X.ρ (h⁻¹ : H))ᘁ := by rw [← SingleObj.inv_as_inv]; rfl -- This lemma was always bad, but the linter only noticed after lean4#2644 @[simp, nolint simpNF] theorem leftDual_ρ [LeftRigidCategory V] (h : H) : (ᘁX).ρ h = ᘁX.ρ (h⁻¹ : H) := by rw [← SingleObj.inv_as_inv]; rfl end end Monoidal open MonoidalCategory /-- Given `X : Action (Type u) (MonCat.of G)` for `G` a group, then `G × X` (with `G` acting as left multiplication on the first factor and by `X.ρ` on the second) is isomorphic as a `G`-set to `G × X` (with `G` acting as left multiplication on the first factor and trivially on the second). The isomorphism is given by `(g, x) ↦ (g, g⁻¹ • x)`. -/ @[simps] noncomputable def leftRegularTensorIso (G : Type u) [Group G] (X : Action (Type u) (MonCat.of G)) : leftRegular G ⊗ X ≅ leftRegular G ⊗ Action.mk X.V 1 where hom := { hom := fun g => ⟨g.1, (X.ρ (g.1⁻¹ : G) g.2 : X.V)⟩ comm := fun (g : G) => by funext ⟨(x₁ : G), (x₂ : X.V)⟩ refine Prod.ext rfl ?_ change (X.ρ ((g * x₁)⁻¹ : G) * X.ρ g) x₂ = X.ρ _ _ rw [mul_inv_rev, ← X.ρ.map_mul, inv_mul_cancel_right] } inv := { hom := fun g => ⟨g.1, X.ρ g.1 g.2⟩ comm := fun (g : G) => by funext ⟨(x₁ : G), (x₂ : X.V)⟩ refine Prod.ext rfl ?_ erw [tensor_rho, tensor_rho] dsimp -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [leftRegular_ρ_apply] erw [map_mul] rfl } hom_inv_id := by apply Hom.ext funext x refine Prod.ext rfl ?_ change (X.ρ x.1 * X.ρ (x.1⁻¹ : G)) x.2 = x.2 rw [← X.ρ.map_mul, mul_inv_self, X.ρ.map_one, MonCat.one_of, End.one_def, types_id_apply] inv_hom_id := by apply Hom.ext funext x refine Prod.ext rfl ?_ change (X.ρ (x.1⁻¹ : G) * X.ρ x.1) x.2 = x.2 rw [← X.ρ.map_mul, inv_mul_self, X.ρ.map_one, MonCat.one_of, End.one_def, types_id_apply] /-- The natural isomorphism of `G`-sets `Gⁿ⁺¹ ≅ G × Gⁿ`, where `G` acts by left multiplication on each factor. -/ @[simps!] noncomputable def diagonalSucc (G : Type u) [Monoid G] (n : ℕ) : diagonal G (n + 1) ≅ leftRegular G ⊗ diagonal G n := mkIso (Equiv.piFinSuccAbove _ 0).toIso fun _ => rfl end Action namespace CategoryTheory.MonoidalFunctor open Action variable {W : Type (u + 1)} [LargeCategory W] [MonoidalCategory V] [MonoidalCategory W] /-- A lax monoidal functor induces a lax monoidal functor between the categories of `G`-actions within those categories. -/ @[simps!] def mapActionLax (F : LaxMonoidalFunctor V W) (G : MonCat.{u}) : LaxMonoidalFunctor (Action V G) (Action W G) := .ofTensorHom (F := F.toFunctor.mapAction G) (ε := { hom := F.ε comm := fun g => by dsimp [FunctorCategoryEquivalence.inverse, Functor.mapAction] rw [Category.id_comp, F.map_id, Category.comp_id] }) (μ := fun X Y => { hom := F.μ X.V Y.V comm := fun g => F.μ_natural (X.ρ g) (Y.ρ g) }) (μ_natural := by intros; ext; simp) (associativity := by intros; ext; simp) (left_unitality := by intros; ext; simp) (right_unitality := by intros; ext; simp) variable (F : MonoidalFunctor V W) (G : MonCat.{u}) /-- A monoidal functor induces a monoidal functor between the categories of `G`-actions within those categories. -/ @[simps!] def mapAction : MonoidalFunctor (Action V G) (Action W G) := { mapActionLax F.toLaxMonoidalFunctor G with ε_isIso := by dsimp [mapActionLax]; infer_instance μ_isIso := by dsimp [mapActionLax]; infer_instance } @[simp] theorem mapAction_ε_inv_hom : (inv (F.mapAction G).ε).hom = inv F.ε := by rw [← cancel_mono F.ε, IsIso.inv_hom_id, ← F.mapAction_toLaxMonoidalFunctor_ε_hom G, ← Action.comp_hom, IsIso.inv_hom_id, Action.id_hom] @[simp] theorem mapAction_μ_inv_hom (X Y : Action V G) : (inv ((F.mapAction G).μ X Y)).hom = inv (F.μ X.V Y.V) := by rw [← cancel_mono (F.μ X.V Y.V), IsIso.inv_hom_id, ← F.mapAction_toLaxMonoidalFunctor_μ_hom G, ← Action.comp_hom, IsIso.inv_hom_id, Action.id_hom] end CategoryTheory.MonoidalFunctor
RepresentationTheory\GroupCohomology\Basic.lean
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Homology.Opposite import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex import Mathlib.RepresentationTheory.GroupCohomology.Resolution /-! # The group cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file defines the group cohomology of `A : Rep k G` to be the cohomology of the complex $$0 \to \mathrm{Fun}(G^0, A) \to \mathrm{Fun}(G^1, A) \to \mathrm{Fun}(G^2, A) \to \dots$$ with differential $d^n$ sending $f: G^n \to A$ to the function mapping $(g_0, \dots, g_n)$ to $$\rho(g_0)(f(g_1, \dots, g_n))$$ $$+ \sum_{i = 0}^{n - 1} (-1)^{i + 1}\cdot f(g_0, \dots, g_ig_{i + 1}, \dots, g_n)$$ $$+ (-1)^{n + 1}\cdot f(g_0, \dots, g_{n - 1})$$ (where `ρ` is the representation attached to `A`). We have a `k`-linear isomorphism $\mathrm{Fun}(G^n, A) \cong \mathrm{Hom}(k[G^{n + 1}], A)$, where the righthand side is morphisms in `Rep k G`, and the representation on $k[G^{n + 1}]$ is induced by the diagonal action of `G`. If we conjugate the $n$th differential in $\mathrm{Hom}(P, A)$ by this isomorphism, where `P` is the standard resolution of `k` as a trivial `k`-linear `G`-representation, then the resulting map agrees with the differential $d^n$ defined above, a fact we prove. This gives us for free a proof that our $d^n$ squares to zero. It also gives us an isomorphism $\mathrm{H}^n(G, A) \cong \mathrm{Ext}^n(k, A),$ where $\mathrm{Ext}$ is taken in the category `Rep k G`. To talk about cohomology in low degree, please see the file `RepresentationTheory.GroupCohomology.LowDegree`, which gives simpler expressions for `H⁰, H¹, H²` than the definition `groupCohomology` in this file. ## Main definitions * `groupCohomology.linearYonedaObjResolution A`: a complex whose objects are the representation morphisms $\mathrm{Hom}(k[G^{n + 1}], A)$ and whose cohomology is the group cohomology $\mathrm{H}^n(G, A)$. * `groupCohomology.inhomogeneousCochains A`: a complex whose objects are $\mathrm{Fun}(G^n, A)$ and whose cohomology is the group cohomology $\mathrm{H}^n(G, A).$ * `groupCohomology.inhomogeneousCochainsIso A`: an isomorphism between the above two complexes. * `groupCohomology A n`: this is $\mathrm{H}^n(G, A),$ defined as the $n$th cohomology of the second complex, `inhomogeneousCochains A`. * `groupCohomologyIsoExt A n`: an isomorphism $\mathrm{H}^n(G, A) \cong \mathrm{Ext}^n(k, A)$ (where $\mathrm{Ext}$ is taken in the category `Rep k G`) induced by `inhomogeneousCochainsIso A`. ## Implementation notes Group cohomology is typically stated for `G`-modules, or equivalently modules over the group ring `ℤ[G].` However, `ℤ` can be generalized to any commutative ring `k`, which is what we use. Moreover, we express `k[G]`-module structures on a module `k`-module `A` using the `Rep` definition. We avoid using instances `Module (MonoidAlgebra k G) A` so that we do not run into possible scalar action diamonds. ## TODO * API for cohomology in low degree: $\mathrm{H}^0, \mathrm{H}^1$ and $\mathrm{H}^2.$ For example, the inflation-restriction exact sequence. * The long exact sequence in cohomology attached to a short exact sequence of representations. * Upgrading `groupCohomologyIsoExt` to an isomorphism of derived functors. * Profinite cohomology. Longer term: * The Hochschild-Serre spectral sequence (this is perhaps a good toy example for the theory of spectral sequences in general). -/ noncomputable section universe u variable {k G : Type u} [CommRing k] {n : ℕ} open CategoryTheory namespace groupCohomology variable [Monoid G] /-- The complex `Hom(P, A)`, where `P` is the standard resolution of `k` as a trivial `k`-linear `G`-representation. -/ abbrev linearYonedaObjResolution (A : Rep k G) : CochainComplex (ModuleCat.{u} k) ℕ := (groupCohomology.resolution k G).linearYonedaObj k A theorem linearYonedaObjResolution_d_apply {A : Rep k G} (i j : ℕ) (x : (resolution k G).X i ⟶ A) : (linearYonedaObjResolution A).d i j x = (resolution k G).d j i ≫ x := rfl end groupCohomology namespace inhomogeneousCochains open Rep groupCohomology /-- The differential in the complex of inhomogeneous cochains used to calculate group cohomology. -/ @[simps] def d [Monoid G] (n : ℕ) (A : Rep k G) : ((Fin n → G) → A) →ₗ[k] (Fin (n + 1) → G) → A where toFun f g := A.ρ (g 0) (f fun i => g i.succ) + Finset.univ.sum fun j : Fin (n + 1) => (-1 : k) ^ ((j : ℕ) + 1) • f (Fin.contractNth j (· * ·) g) map_add' f g := by ext x /- Porting note: changed from `simp only` which needed extra heartbeats -/ simp_rw [Pi.add_apply, map_add, smul_add, Finset.sum_add_distrib, add_add_add_comm] map_smul' r f := by ext x /- Porting note: changed from `simp only` which needed extra heartbeats -/ simp_rw [Pi.smul_apply, RingHom.id_apply, map_smul, smul_add, Finset.smul_sum, ← smul_assoc, smul_eq_mul, mul_comm r] variable [Group G] (n) (A : Rep k G) /- Porting note: linter says the statement doesn't typecheck, so we add `@[nolint checkType]` -/ /-- The theorem that our isomorphism `Fun(Gⁿ, A) ≅ Hom(k[Gⁿ⁺¹], A)` (where the righthand side is morphisms in `Rep k G`) commutes with the differentials in the complex of inhomogeneous cochains and the homogeneous `linearYonedaObjResolution`. -/ @[nolint checkType] theorem d_eq : d n A = (diagonalHomEquiv n A).toModuleIso.inv ≫ (linearYonedaObjResolution A).d n (n + 1) ≫ (diagonalHomEquiv (n + 1) A).toModuleIso.hom := by ext f g /- Porting note (#11039): broken proof was simp only [ModuleCat.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.toModuleIso_inv, linearYonedaObjResolution_d_apply, LinearEquiv.toModuleIso_hom, diagonalHomEquiv_apply, Action.comp_hom, Resolution.d_eq k G n, Resolution.d_of (Fin.partialProd g), LinearMap.map_sum, ← Finsupp.smul_single_one _ ((-1 : k) ^ _), map_smul, d_apply] simp only [@Fin.sum_univ_succ _ _ (n + 1), Fin.val_zero, pow_zero, one_smul, Fin.succAbove_zero, diagonalHomEquiv_symm_apply f (Fin.partialProd g ∘ @Fin.succ (n + 1)), Function.comp_apply, Fin.partialProd_succ, Fin.castSucc_zero, Fin.partialProd_zero, one_mul] congr 1 · congr ext have := Fin.partialProd_right_inv g (Fin.castSucc x) simp only [mul_inv_rev, Fin.castSucc_fin_succ] at * rw [mul_assoc, ← mul_assoc _ _ (g x.succ), this, inv_mul_cancel_left] · exact Finset.sum_congr rfl fun j hj => by rw [diagonalHomEquiv_symm_partialProd_succ, Fin.val_succ] -/ -- https://github.com/leanprover-community/mathlib4/issues/5026 -- https://github.com/leanprover-community/mathlib4/issues/5164 change d n A f g = diagonalHomEquiv (n + 1) A ((resolution k G).d (n + 1) n ≫ (diagonalHomEquiv n A).symm f) g -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [diagonalHomEquiv_apply, Action.comp_hom, ModuleCat.comp_def, LinearMap.comp_apply, resolution.d_eq] erw [resolution.d_of (Fin.partialProd g)] simp only [map_sum, ← Finsupp.smul_single_one _ ((-1 : k) ^ _)] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [d_apply, @Fin.sum_univ_succ _ _ (n + 1), Fin.val_zero, pow_zero, one_smul, Fin.succAbove_zero, diagonalHomEquiv_symm_apply f (Fin.partialProd g ∘ @Fin.succ (n + 1))] simp_rw [Function.comp_apply, Fin.partialProd_succ, Fin.castSucc_zero, Fin.partialProd_zero, one_mul] rcongr x · have := Fin.partialProd_right_inv g (Fin.castSucc x) simp only [mul_inv_rev, Fin.castSucc_fin_succ] at this ⊢ rw [mul_assoc, ← mul_assoc _ _ (g x.succ), this, inv_mul_cancel_left] · -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [map_smul, diagonalHomEquiv_symm_partialProd_succ, Fin.val_succ] end inhomogeneousCochains namespace groupCohomology variable [Group G] (n) (A : Rep k G) open inhomogeneousCochains /-- Given a `k`-linear `G`-representation `A`, this is the complex of inhomogeneous cochains $$0 \to \mathrm{Fun}(G^0, A) \to \mathrm{Fun}(G^1, A) \to \mathrm{Fun}(G^2, A) \to \dots$$ which calculates the group cohomology of `A`. -/ noncomputable abbrev inhomogeneousCochains : CochainComplex (ModuleCat k) ℕ := CochainComplex.of (fun n => ModuleCat.of k ((Fin n → G) → A)) (fun n => inhomogeneousCochains.d n A) fun n => by /- Porting note (#11039): broken proof was ext x y have := LinearMap.ext_iff.1 ((linearYonedaObjResolution A).d_comp_d n (n + 1) (n + 2)) simp only [ModuleCat.coe_comp, Function.comp_apply] at this simp only [ModuleCat.coe_comp, Function.comp_apply, d_eq, LinearEquiv.toModuleIso_hom, LinearEquiv.toModuleIso_inv, LinearEquiv.coe_coe, LinearEquiv.symm_apply_apply, this, LinearMap.zero_apply, map_zero, Pi.zero_apply] -/ ext x have := LinearMap.ext_iff.1 ((linearYonedaObjResolution A).d_comp_d n (n + 1) (n + 2)) simp only [ModuleCat.comp_def, LinearMap.comp_apply] at this dsimp only simp only [d_eq, LinearEquiv.toModuleIso_inv, LinearEquiv.toModuleIso_hom, ModuleCat.coe_comp, Function.comp_apply] /- Porting note: I can see I need to rewrite `LinearEquiv.coe_coe` twice to at least reduce the need for `symm_apply_apply` to be an `erw`. However, even `erw` refuses to rewrite the second `coe_coe`... -/ erw [LinearEquiv.symm_apply_apply, this] exact map_zero _ @[simp] theorem inhomogeneousCochains.d_def (n : ℕ) : (inhomogeneousCochains A).d n (n + 1) = inhomogeneousCochains.d n A := CochainComplex.of_d _ _ _ _ /-- Given a `k`-linear `G`-representation `A`, the complex of inhomogeneous cochains is isomorphic to `Hom(P, A)`, where `P` is the standard resolution of `k` as a trivial `G`-representation. -/ def inhomogeneousCochainsIso : inhomogeneousCochains A ≅ linearYonedaObjResolution A := by refine HomologicalComplex.Hom.isoOfComponents (fun i => (Rep.diagonalHomEquiv i A).toModuleIso.symm) ?_ rintro i j (h : i + 1 = j) subst h simp only [CochainComplex.of_d, d_eq, Category.assoc, Iso.symm_hom, Iso.hom_inv_id, Category.comp_id] /-- The `n`-cocycles `Zⁿ(G, A)` of a `k`-linear `G`-representation `A`, i.e. the kernel of the `n`th differential in the complex of inhomogeneous cochains. -/ abbrev cocycles (n : ℕ) : ModuleCat k := (inhomogeneousCochains A).cycles n /-- The natural inclusion of the `n`-cocycles `Zⁿ(G, A)` into the `n`-cochains `Cⁿ(G, A).` -/ abbrev iCocycles (n : ℕ) : cocycles A n ⟶ ModuleCat.of k ((Fin n → G) → A) := (inhomogeneousCochains A).iCycles n /-- This is the map from `i`-cochains to `j`-cocycles induced by the differential in the complex of inhomogeneous cochains. -/ abbrev toCocycles (i j : ℕ) : ModuleCat.of k ((Fin i → G) → A) ⟶ cocycles A j := (inhomogeneousCochains A).toCycles i j end groupCohomology open groupCohomology /-- The group cohomology of a `k`-linear `G`-representation `A`, as the cohomology of its complex of inhomogeneous cochains. -/ def groupCohomology [Group G] (A : Rep k G) (n : ℕ) : ModuleCat k := (inhomogeneousCochains A).homology n /-- The natural map from `n`-cocycles to `n`th group cohomology for a `k`-linear `G`-representation `A`. -/ abbrev groupCohomologyπ [Group G] (A : Rep k G) (n : ℕ) : groupCohomology.cocycles A n ⟶ groupCohomology A n := (inhomogeneousCochains A).homologyπ n /-- The `n`th group cohomology of a `k`-linear `G`-representation `A` is isomorphic to `Extⁿ(k, A)` (taken in `Rep k G`), where `k` is a trivial `k`-linear `G`-representation. -/ def groupCohomologyIsoExt [Group G] (A : Rep k G) (n : ℕ) : groupCohomology A n ≅ ((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj A := isoOfQuasiIsoAt (HomotopyEquiv.ofIso (inhomogeneousCochainsIso A)).hom n ≪≫ (extIso k G A n).symm
RepresentationTheory\GroupCohomology\Hilbert90.lean
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.FieldTheory.Fixed import Mathlib.RepresentationTheory.GroupCohomology.LowDegree import Mathlib.LinearAlgebra.LinearIndependent /-! # Hilbert's Theorem 90 Let `L/K` be a finite extension of fields. Then this file proves Noether's generalization of Hilbert's Theorem 90: that the 1st group cohomology $H^1(Aut_K(L), Lˣ)$ is trivial. We state it both in terms of $H^1$ and in terms of cocycles being coboundaries. Hilbert's original statement was that if $L/K$ is Galois, and $Gal(L/K)$ is cyclic, generated by an element `σ`, then for every `x : L` such that $N_{L/K}(x) = 1,$ there exists `y : L` such that $x = y/σ(y).$ This can be deduced from the fact that the function $Gal(L/K) → L^\times$ sending $σ^i \mapsto xσ(x)σ^2(x)...σ^{i-1}(x)$ is a 1-cocycle. Alternatively, we can derive it by analyzing the cohomology of finite cyclic groups in general. Noether's generalization also holds for infinite Galois extensions. ## Main statements * `groupCohomology.isMulOneCoboundary_of_isMulOneCocycle_of_aut_to_units`: Noether's generalization of Hilbert's Theorem 90: for all $f: Aut_K(L) \to L^\times$ satisfying the 1-cocycle condition, there exists `β : Lˣ` such that $g(β)/β = f(g)$ for all `g : Aut_K(L)`. * `groupCohomology.H1ofAutOnUnitsUnique`: Noether's generalization of Hilbert's Theorem 90: $H^1(Aut_K(L), L^\times)$ is trivial. ## Implementation notes Given a commutative ring `k` and a group `G`, group cohomology is developed in terms of `k`-linear `G`-representations on `k`-modules. Therefore stating Noether's generalization of Hilbert 90 in terms of `H¹` requires us to turn the natural action of `Aut_K(L)` on `Lˣ` into a morphism `Aut_K(L) →* (Additive Lˣ →ₗ[ℤ] Additive Lˣ)`. Thus we provide the non-`H¹` version too, as its statement is clearer. ## TODO * The original Hilbert's Theorem 90, deduced from the cohomology of general finite cyclic groups. * Develop Galois cohomology to extend Noether's result to infinite Galois extensions. * "Additive Hilbert 90": let `L/K` be a finite Galois extension. Then $H^n(Gal(L/K), L)$ is trivial for all $1 ≤ n.$ -/ namespace groupCohomology namespace Hilbert90 variable {K L : Type*} [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- Given `f : Aut_K(L) → Lˣ`, the sum `∑ f(φ) • φ` for `φ ∈ Aut_K(L)`, as a function `L → L`. -/ noncomputable def aux (f : (L ≃ₐ[K] L) → Lˣ) : L → L := Finsupp.total (L ≃ₐ[K] L) (L → L) L (fun φ => φ) (Finsupp.equivFunOnFinite.symm (fun φ => (f φ : L))) theorem aux_ne_zero (f : (L ≃ₐ[K] L) → Lˣ) : aux f ≠ 0 := /- the set `Aut_K(L)` is linearly independent in the `L`-vector space `L → L`, by Dedekind's linear independence of characters -/ have : LinearIndependent L (fun (f : L ≃ₐ[K] L) => (f : L → L)) := LinearIndependent.comp (ι' := L ≃ₐ[K] L) (linearIndependent_monoidHom L L) (fun f => f) (fun x y h => by ext; exact DFunLike.ext_iff.1 h _) have h := linearIndependent_iff.1 this (Finsupp.equivFunOnFinite.symm (fun φ => (f φ : L))) fun H => Units.ne_zero (f 1) (DFunLike.ext_iff.1 (h H) 1) end Hilbert90 section open Hilbert90 variable {K L : Type*} [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- Noether's generalization of Hilbert's Theorem 90: given a finite extension of fields and a function `f : Aut_K(L) → Lˣ` satisfying `f(gh) = g(f(h)) * f(g)` for all `g, h : Aut_K(L)`, there exists `β : Lˣ` such that `g(β)/β = f(g)` for all `g : Aut_K(L).` -/ theorem isMulOneCoboundary_of_isMulOneCocycle_of_aut_to_units (f : (L ≃ₐ[K] L) → Lˣ) (hf : IsMulOneCocycle f) : IsMulOneCoboundary f := by /- Let `z : L` be such that `∑ f(h) * h(z) ≠ 0`, for `h ∈ Aut_K(L)` -/ obtain ⟨z, hz⟩ : ∃ z, aux f z ≠ 0 := not_forall.1 (fun H => aux_ne_zero f <| funext <| fun x => H x) have : aux f z = ∑ h, f h * h z := by simp [aux, Finsupp.total, Finsupp.sum_fintype] /- Let `β = (∑ f(h) * h(z))⁻¹.` -/ use (Units.mk0 (aux f z) hz)⁻¹ intro g /- Then the equality follows from the hypothesis that `f` is a 1-cocycle. -/ simp only [IsMulOneCocycle, IsMulOneCoboundary, AlgEquiv.smul_units_def, map_inv, div_inv_eq_mul, inv_mul_eq_iff_eq_mul, Units.ext_iff, this, Units.val_mul, Units.coe_map, Units.val_mk0, MonoidHom.coe_coe] at hf ⊢ simp_rw [map_sum, map_mul, Finset.sum_mul, mul_assoc, mul_comm _ (f _ : L), ← mul_assoc, ← hf g] exact eq_comm.1 (Fintype.sum_bijective (fun i => g * i) (Group.mulLeft_bijective g) _ _ (fun i => rfl)) end variable (K L : Type) [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- Noether's generalization of Hilbert's Theorem 90: given a finite extension of fields `L/K`, the first group cohomology `H¹(Aut_K(L), Lˣ)` is trivial. -/ noncomputable instance H1ofAutOnUnitsUnique : Unique (H1 (Rep.ofAlgebraAutOnUnits K L)) where default := 0 uniq := fun a => Quotient.inductionOn' a fun x => (Submodule.Quotient.mk_eq_zero _).2 <| by refine (oneCoboundariesOfIsMulOneCoboundary ?_).2 rcases isMulOneCoboundary_of_isMulOneCocycle_of_aut_to_units x.1 (isMulOneCocycle_of_oneCocycles x) with ⟨β, hβ⟩ use β end groupCohomology
RepresentationTheory\GroupCohomology\LowDegree.lean
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Equiv.piFinSucc 2 G).trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, Function.funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, apply_eq_self, sub_self, LinearMap.zero_apply, Pi.zero_apply] /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 0 1 := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.coe_fin_one, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 1 2 := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 2 3 := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, LinearMap.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by show ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A) = _ have h1 : _ ≫ ModuleCat.ofHom (dOne A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 : _ ≫ ModuleCat.ofHom (dTwo A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero] end Differentials section Cocycles /-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A) /-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G × G, A) → Fun(G × G × G, A)` sending `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A) variable {A} theorem mem_oneCocycles_def (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 := LinearMap.mem_ker.trans <| by rw [Function.funext_iff] simp only [dOne_apply, Pi.zero_apply, Prod.forall] theorem mem_oneCocycles_iff (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm] @[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f.1 1 = 0 := by have := (mem_oneCocycles_def f.1).1 f.2 1 1 simpa only [map_one, LinearMap.one_apply, mul_one, sub_self, zero_add] using this @[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) : A.ρ g (f.1 g⁻¹) = - f.1 g := by rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_self g, (mem_oneCocycles_iff f.1).1 f.2 g g⁻¹] theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) : f.1 (g * h) = f.1 g + f.1 h := by rw [(mem_oneCocycles_iff f.1).1 f.2, apply_eq_self A.ρ g (f.1 h), add_comm] theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) : f ∘ Additive.ofMul ∈ oneCocycles A := (mem_oneCocycles_iff _).2 fun g h => by simp only [Function.comp_apply, ofMul_mul, map_add, oneCocycles_map_mul_of_isTrivial, apply_eq_self A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))] variable (A) /-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the group homs `G → A`. -/ @[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] : oneCocycles A ≃ₗ[k] Additive G →+ A where toFun f := { toFun := f.1 ∘ Additive.toMul map_zero' := oneCocycles_map_one f map_add' := oneCocycles_map_mul_of_isTrivial f } map_add' x y := rfl map_smul' r x := rfl invFun f := { val := f property := mem_oneCocycles_of_addMonoidHom f } left_inv f := by ext; rfl right_inv f := by ext; rfl variable {A} theorem mem_twoCocycles_def (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 := LinearMap.mem_ker.trans <| by rw [Function.funext_iff] simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall] theorem mem_twoCocycles_iff (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, f (g * h, j) + f (g, h) = A.ρ g (f (h, j)) + f (g, h * j) := by simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm, add_comm (f (_ * _, _))] theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) : f.1 (1, g) = f.1 (1, 1) := by have := ((mem_twoCocycles_iff f.1).1 f.2 1 1 g).symm simpa only [map_one, LinearMap.one_apply, one_mul, add_right_inj, this] theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) : f.1 (g, 1) = A.ρ g (f.1 (1, 1)) := by have := (mem_twoCocycles_iff f.1).1 f.2 g 1 1 simpa only [mul_one, add_left_inj, this] lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) : A.ρ g (f.1 (g⁻¹, g)) - f.1 (g, g⁻¹) = f.1 (1, 1) - f.1 (g, 1) := by have := (mem_twoCocycles_iff f.1).1 f.2 g g⁻¹ g simp only [mul_right_inv, mul_left_inv, twoCocycles_map_one_fst _ g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm end Cocycles section Coboundaries /-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map `A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/ def oneCoboundaries : Submodule k (oneCocycles A) := LinearMap.range ((dZero A).codRestrict (oneCocycles A) fun c => LinearMap.ext_iff.1 (dOne_comp_dZero A) c) /-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def twoCoboundaries : Submodule k (twoCocycles A) := LinearMap.range ((dOne A).codRestrict (twoCocycles A) fun c => LinearMap.ext_iff.1 (dTwo_comp_dOne.{u} A) c) variable {A} /-- Makes a 1-coboundary out of `f ∈ Im(d⁰)`. -/ def oneCoboundariesOfMemRange {f : G → A} (h : f ∈ LinearMap.range (dZero A)) : oneCoboundaries A := ⟨⟨f, LinearMap.range_le_ker_iff.2 (dOne_comp_dZero A) h⟩, by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩⟩ theorem oneCoboundaries_of_mem_range_apply {f : G → A} (h : f ∈ LinearMap.range (dZero A)) : (oneCoboundariesOfMemRange h).1.1 = f := rfl /-- Makes a 1-coboundary out of `f : G → A` and `x` such that `ρ(g)(x) - x = f(g)` for all `g : G`. -/ def oneCoboundariesOfEq {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) : oneCoboundaries A := oneCoboundariesOfMemRange ⟨x, by ext g; exact hf g⟩ theorem oneCoboundariesOfEq_apply {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) : (oneCoboundariesOfEq hf).1.1 = f := rfl theorem mem_range_of_mem_oneCoboundaries {f : oneCocycles A} (h : f ∈ oneCoboundaries A) : f.1 ∈ LinearMap.range (dZero A) := by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩ theorem oneCoboundaries_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] : oneCoboundaries A = ⊥ := by simp_rw [oneCoboundaries, dZero_eq_zero] exact LinearMap.range_eq_bot.2 rfl /-- Makes a 2-coboundary out of `f ∈ Im(d¹)`. -/ def twoCoboundariesOfMemRange {f : G × G → A} (h : f ∈ LinearMap.range (dOne A)) : twoCoboundaries A := ⟨⟨f, LinearMap.range_le_ker_iff.2 (dTwo_comp_dOne A) h⟩, by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩⟩ theorem twoCoboundariesOfMemRange_apply {f : G × G → A} (h : f ∈ LinearMap.range (dOne A)) : (twoCoboundariesOfMemRange h).1.1 = f := rfl /-- Makes a 2-coboundary out of `f : G × G → A` and `x : G → A` such that `ρ(g)(x(h)) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/ def twoCoboundariesOfEq {f : G × G → A} {x : G → A} (hf : ∀ g h, A.ρ g (x h) - x (g * h) + x g = f (g, h)) : twoCoboundaries A := twoCoboundariesOfMemRange ⟨x, by ext g; exact hf g.1 g.2⟩ theorem twoCoboundariesOfEq_apply {f : G × G → A} {x : G → A} (hf : ∀ g h, A.ρ g (x h) - x (g * h) + x g = f (g, h)) : (twoCoboundariesOfEq hf).1.1 = f := rfl theorem mem_range_of_mem_twoCoboundaries {f : twoCocycles A} (h : f ∈ twoCoboundaries A) : (twoCocycles A).subtype f ∈ LinearMap.range (dOne A) := by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩ end Coboundaries section IsCocycle section variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A] /-- A function `f : G → A` satisfies the 1-cocycle condition if `f(gh) = g • f(h) + f(g)` for all `g, h : G`. -/ def IsOneCocycle (f : G → A) : Prop := ∀ g h : G, f (g * h) = g • f h + f g /-- A function `f : G × G → A` satisfies the 2-cocycle condition if `f(gh, j) + f(g, h) = g • f(h, j) + f(g, hj)` for all `g, h : G`. -/ def IsTwoCocycle (f : G × G → A) : Prop := ∀ g h j : G, f (g * h, j) + f (g, h) = g • (f (h, j)) + f (g, h * j) end section variable {G A : Type*} [Monoid G] [AddCommGroup A] [MulAction G A] theorem map_one_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) : f 1 = 0 := by simpa only [mul_one, one_smul, self_eq_add_right] using hf 1 1 theorem map_one_fst_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : f (1, g) = f (1, 1) := by simpa only [one_smul, one_mul, mul_one, add_right_inj] using (hf 1 1 g).symm theorem map_one_snd_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : f (g, 1) = g • f (1, 1) := by simpa only [mul_one, add_left_inj] using hf g 1 1 end section variable {G A : Type*} [Group G] [AddCommGroup A] [MulAction G A] @[simp] theorem map_inv_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) (g : G) : g • f g⁻¹ = - f g := by rw [← add_eq_zero_iff_eq_neg, ← map_one_of_isOneCocycle hf, ← mul_inv_self g, hf g g⁻¹] theorem smul_map_inv_sub_map_inv_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : g • f (g⁻¹, g) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by have := hf g g⁻¹ g simp only [mul_right_inv, mul_left_inv, map_one_fst_of_isTwoCocycle hf g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm end end IsCocycle section IsCoboundary variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A] /-- A function `f : G → A` satisfies the 1-coboundary condition if there's `x : A` such that `g • x - x = f(g)` for all `g : G`. -/ def IsOneCoboundary (f : G → A) : Prop := ∃ x : A, ∀ g : G, g • x - x = f g /-- A function `f : G × G → A` satisfies the 2-coboundary condition if there's `x : G → A` such that `g • x(h) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/ def IsTwoCoboundary (f : G × G → A) : Prop := ∃ x : G → A, ∀ g h : G, g • x h - x (g * h) + x g = f (g, h) end IsCoboundary section ofDistribMulAction variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A] [DistribMulAction G A] [SMulCommClass G k A] /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G → A` satisfying the 1-cocycle condition, produces a 1-cocycle for the representation on `A` induced by the `DistribMulAction`. -/ def oneCocyclesOfIsOneCocycle {f : G → A} (hf : IsOneCocycle f) : oneCocycles (Rep.ofDistribMulAction k G A) := ⟨f, (mem_oneCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩ theorem isOneCocycle_of_oneCocycles (f : oneCocycles (Rep.ofDistribMulAction k G A)) : IsOneCocycle (A := A) f.1 := (mem_oneCocycles_iff f.1).1 f.2 /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G → A` satisfying the 1-coboundary condition, produces a 1-coboundary for the representation on `A` induced by the `DistribMulAction`. -/ def oneCoboundariesOfIsOneCoboundary {f : G → A} (hf : IsOneCoboundary f) : oneCoboundaries (Rep.ofDistribMulAction k G A) := oneCoboundariesOfMemRange (by rcases hf with ⟨x, hx⟩; exact ⟨x, by ext g; exact hx g⟩) theorem isOneCoboundary_of_oneCoboundaries (f : oneCoboundaries (Rep.ofDistribMulAction k G A)) : IsOneCoboundary (A := A) f.1.1 := by rcases mem_range_of_mem_oneCoboundaries f.2 with ⟨x, hx⟩ exact ⟨x, by rw [← hx]; intro g; rfl⟩ /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G × G → A` satisfying the 2-cocycle condition, produces a 2-cocycle for the representation on `A` induced by the `DistribMulAction`. -/ def twoCocyclesOfIsTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) : twoCocycles (Rep.ofDistribMulAction k G A) := ⟨f, (mem_twoCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩ theorem isTwoCocycle_of_twoCocycles (f : twoCocycles (Rep.ofDistribMulAction k G A)) : IsTwoCocycle (A := A) f.1 := (mem_twoCocycles_iff f.1).1 f.2 /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G × G → A` satisfying the 2-coboundary condition, produces a 2-coboundary for the representation on `A` induced by the `DistribMulAction`. -/ def twoCoboundariesOfIsTwoCoboundary {f : G × G → A} (hf : IsTwoCoboundary f) : twoCoboundaries (Rep.ofDistribMulAction k G A) := twoCoboundariesOfMemRange (by rcases hf with ⟨x, hx⟩; exact ⟨x, by ext g; exact hx g.1 g.2⟩) theorem isTwoCoboundary_of_twoCoboundaries (f : twoCoboundaries (Rep.ofDistribMulAction k G A)) : IsTwoCoboundary (A := A) f.1.1 := by rcases mem_range_of_mem_twoCoboundaries f.2 with ⟨x, hx⟩ exact ⟨x, fun g h => Function.funext_iff.1 hx (g, h)⟩ end ofDistribMulAction /-! The next few sections, until the section `Cohomology`, are a multiplicative copy of the previous few sections beginning with `IsCocycle`. Unfortunately `@[to_additive]` doesn't work with scalar actions. -/ section IsMulCocycle section variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M] /-- A function `f : G → M` satisfies the multiplicative 1-cocycle condition if `f(gh) = g • f(h) * f(g)` for all `g, h : G`. -/ def IsMulOneCocycle (f : G → M) : Prop := ∀ g h : G, f (g * h) = g • f h * f g /-- A function `f : G × G → M` satisfies the multiplicative 2-cocycle condition if `f(gh, j) * f(g, h) = g • f(h, j) * f(g, hj)` for all `g, h : G`. -/ def IsMulTwoCocycle (f : G × G → M) : Prop := ∀ g h j : G, f (g * h, j) * f (g, h) = g • (f (h, j)) * f (g, h * j) end section variable {G M : Type*} [Monoid G] [CommGroup M] [MulAction G M] theorem map_one_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) : f 1 = 1 := by simpa only [mul_one, one_smul, self_eq_mul_right] using hf 1 1 theorem map_one_fst_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) : f (1, g) = f (1, 1) := by simpa only [one_smul, one_mul, mul_one, mul_right_inj] using (hf 1 1 g).symm theorem map_one_snd_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) : f (g, 1) = g • f (1, 1) := by simpa only [mul_one, mul_left_inj] using hf g 1 1 end section variable {G M : Type*} [Group G] [CommGroup M] [MulAction G M] @[simp] theorem map_inv_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) (g : G) : g • f g⁻¹ = (f g)⁻¹ := by rw [← mul_eq_one_iff_eq_inv, ← map_one_of_isMulOneCocycle hf, ← mul_inv_self g, hf g g⁻¹] theorem smul_map_inv_div_map_inv_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) : g • f (g⁻¹, g) / f (g, g⁻¹) = f (1, 1) / f (g, 1) := by have := hf g g⁻¹ g simp only [mul_right_inv, mul_left_inv, map_one_fst_of_isMulTwoCocycle hf g] at this exact div_eq_div_iff_mul_eq_mul.2 this.symm end end IsMulCocycle section IsMulCoboundary variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M] /-- A function `f : G → M` satisfies the multiplicative 1-coboundary condition if there's `x : M` such that `g • x / x = f(g)` for all `g : G`. -/ def IsMulOneCoboundary (f : G → M) : Prop := ∃ x : M, ∀ g : G, g • x / x = f g /-- A function `f : G × G → M` satisfies the 2-coboundary condition if there's `x : G → M` such that `g • x(h) / x(gh) * x(g) = f(g, h)` for all `g, h : G`. -/ def IsMulTwoCoboundary (f : G × G → M) : Prop := ∃ x : G → M, ∀ g h : G, g • x h / x (g * h) * x g = f (g, h) end IsMulCoboundary section ofMulDistribMulAction variable {G M : Type} [Group G] [CommGroup M] [MulDistribMulAction G M] /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G → M` satisfying the multiplicative 1-cocycle condition, produces a 1-cocycle for the representation on `Additive M` induced by the `MulDistribMulAction`. -/ def oneCocyclesOfIsMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) : oneCocycles (Rep.ofMulDistribMulAction G M) := ⟨Additive.ofMul ∘ f, (mem_oneCocycles_iff (A := Rep.ofMulDistribMulAction G M) f).2 hf⟩ theorem isMulOneCocycle_of_oneCocycles (f : oneCocycles (Rep.ofMulDistribMulAction G M)) : IsMulOneCocycle (M := M) (Additive.toMul ∘ f.1) := (mem_oneCocycles_iff f.1).1 f.2 /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G → M` satisfying the multiplicative 1-coboundary condition, produces a 1-coboundary for the representation on `Additive M` induced by the `MulDistribMulAction`. -/ def oneCoboundariesOfIsMulOneCoboundary {f : G → M} (hf : IsMulOneCoboundary f) : oneCoboundaries (Rep.ofMulDistribMulAction G M) := oneCoboundariesOfMemRange (f := Additive.ofMul ∘ f) (by rcases hf with ⟨x, hx⟩; exact ⟨x, by ext g; exact hx g⟩) theorem isMulOneCoboundary_of_oneCoboundaries (f : oneCoboundaries (Rep.ofMulDistribMulAction G M)) : IsMulOneCoboundary (M := M) (Additive.ofMul ∘ f.1.1) := by rcases mem_range_of_mem_oneCoboundaries f.2 with ⟨x, hx⟩ exact ⟨x, by rw [← hx]; intro g; rfl⟩ /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G × G → M` satisfying the multiplicative 2-cocycle condition, produces a 2-cocycle for the representation on `Additive M` induced by the `MulDistribMulAction`. -/ def twoCocyclesOfIsMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) : twoCocycles (Rep.ofMulDistribMulAction G M) := ⟨Additive.ofMul ∘ f, (mem_twoCocycles_iff (A := Rep.ofMulDistribMulAction G M) f).2 hf⟩ theorem isMulTwoCocycle_of_twoCocycles (f : twoCocycles (Rep.ofMulDistribMulAction G M)) : IsMulTwoCocycle (M := M) (Additive.toMul ∘ f.1) := (mem_twoCocycles_iff f.1).1 f.2 /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G × G → M` satisfying the multiplicative 2-coboundary condition, produces a 2-coboundary for the representation on `M` induced by the `MulDistribMulAction`. -/ def twoCoboundariesOfIsMulTwoCoboundary {f : G × G → M} (hf : IsMulTwoCoboundary f) : twoCoboundaries (Rep.ofMulDistribMulAction G M) := twoCoboundariesOfMemRange (by rcases hf with ⟨x, hx⟩; exact ⟨x, by ext g; exact hx g.1 g.2⟩) theorem isMulTwoCoboundary_of_twoCoboundaries (f : twoCoboundaries (Rep.ofMulDistribMulAction G M)) : IsMulTwoCoboundary (M := M) (Additive.toMul ∘ f.1.1) := by rcases mem_range_of_mem_twoCoboundaries f.2 with ⟨x, hx⟩ exact ⟨x, fun g h => Function.funext_iff.1 hx (g, h)⟩ end ofMulDistribMulAction section Cohomology /-- We define the 0th group cohomology of a `k`-linear `G`-representation `A`, `H⁰(G, A)`, to be the invariants of the representation, `Aᴳ`. -/ abbrev H0 := A.ρ.invariants /-- We define the 1st group cohomology of a `k`-linear `G`-representation `A`, `H¹(G, A)`, to be 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). -/ abbrev H1 := oneCocycles A ⧸ oneCoboundaries A /-- The quotient map `Z¹(G, A) → H¹(G, A).` -/ def H1_π : oneCocycles A →ₗ[k] H1 A := (oneCoboundaries A).mkQ /-- We define the 2nd group cohomology of a `k`-linear `G`-representation `A`, `H²(G, A)`, to be 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). -/ abbrev H2 := twoCocycles A ⧸ twoCoboundaries A /-- The quotient map `Z²(G, A) → H²(G, A).` -/ def H2_π : twoCocycles A →ₗ[k] H2 A := (twoCoboundaries A).mkQ end Cohomology section H0 /-- When the representation on `A` is trivial, then `H⁰(G, A)` is all of `A.` -/ def H0LequivOfIsTrivial [A.IsTrivial] : H0 A ≃ₗ[k] A := LinearEquiv.ofTop _ (invariants_eq_top A.ρ) @[simp] theorem H0LequivOfIsTrivial_eq_subtype [A.IsTrivial] : H0LequivOfIsTrivial A = A.ρ.invariants.subtype := rfl theorem H0LequivOfIsTrivial_apply [A.IsTrivial] (x : H0 A) : H0LequivOfIsTrivial A x = x := rfl @[simp] theorem H0LequivOfIsTrivial_symm_apply [A.IsTrivial] (x : A) : (H0LequivOfIsTrivial A).symm x = x := rfl end H0 section H1 /-- When `A : Rep k G` is a trivial representation of `G`, `H¹(G, A)` is isomorphic to the group homs `G → A`. -/ def H1LequivOfIsTrivial [A.IsTrivial] : H1 A ≃ₗ[k] Additive G →+ A := (Submodule.quotEquivOfEqBot _ (oneCoboundaries_eq_bot_of_isTrivial A)).trans (oneCocyclesLequivOfIsTrivial A) theorem H1LequivOfIsTrivial_comp_H1_π [A.IsTrivial] : (H1LequivOfIsTrivial A).comp (H1_π A) = oneCocyclesLequivOfIsTrivial A := by ext; rfl @[simp] theorem H1LequivOfIsTrivial_H1_π_apply_apply [A.IsTrivial] (f : oneCocycles A) (x : Additive G) : H1LequivOfIsTrivial A (H1_π A f) x = f.1 (Additive.toMul x) := rfl @[simp] theorem H1LequivOfIsTrivial_symm_apply [A.IsTrivial] (f : Additive G →+ A) : (H1LequivOfIsTrivial A).symm f = H1_π A ((oneCocyclesLequivOfIsTrivial A).symm f) := rfl end H1 section groupCohomologyIso open ShortComplex section H0 lemma dZero_comp_H0_subtype : dZero A ∘ₗ (H0 A).subtype = 0 := by ext ⟨x, hx⟩ g replace hx := hx g rw [← sub_eq_zero] at hx exact hx /-- The (exact) short complex `A.ρ.invariants ⟶ A ⟶ (G → A)`. -/ def shortComplexH0 : ShortComplex (ModuleCat k) := ShortComplex.moduleCatMk _ _ (dZero_comp_H0_subtype A) instance : Mono (shortComplexH0 A).f := by rw [ModuleCat.mono_iff_injective] apply Submodule.injective_subtype lemma shortComplexH0_exact : (shortComplexH0 A).Exact := by rw [ShortComplex.moduleCat_exact_iff] intro (x : A) (hx : dZero _ x = 0) refine ⟨⟨x, fun g => ?_⟩, rfl⟩ rw [← sub_eq_zero] exact congr_fun hx g /-- The arrow `A --dZero--> Fun(G, A)` is isomorphic to the differential `(inhomogeneousCochains A).d 0 1` of the complex of inhomogeneous cochains of `A`. -/ @[simps! hom_left hom_right inv_left inv_right] def dZeroArrowIso : Arrow.mk ((inhomogeneousCochains A).d 0 1) ≅ Arrow.mk (ModuleCat.ofHom (dZero A)) := Arrow.isoMk (zeroCochainsLequiv A).toModuleIso (oneCochainsLequiv A).toModuleIso (dZero_comp_eq A) /-- The 0-cocycles of the complex of inhomogeneous cochains of `A` are isomorphic to `A.ρ.invariants`, which is a simpler type. -/ def isoZeroCocycles : cocycles A 0 ≅ ModuleCat.of k A.ρ.invariants := KernelFork.mapIsoOfIsLimit ((inhomogeneousCochains A).cyclesIsKernel 0 1 (by simp)) (shortComplexH0_exact A).fIsKernel (dZeroArrowIso A) lemma isoZeroCocycles_hom_comp_subtype : (isoZeroCocycles A).hom ≫ A.ρ.invariants.subtype = iCocycles A 0 ≫ (zeroCochainsLequiv A).toModuleIso.hom := by dsimp [isoZeroCocycles] apply KernelFork.mapOfIsLimit_ι /-- The 0th group cohomology of `A`, defined as the 0th cohomology of the complex of inhomogeneous cochains, is isomorphic to the invariants of the representation on `A`. -/ def isoH0 : groupCohomology A 0 ≅ ModuleCat.of k (H0 A) := (CochainComplex.isoHomologyπ₀ _).symm ≪≫ isoZeroCocycles A lemma groupCohomologyπ_comp_isoH0_hom : groupCohomologyπ A 0 ≫ (isoH0 A).hom = (isoZeroCocycles A).hom := by simp [isoH0] end H0 section H1 /-- The short complex `A --dZero--> Fun(G, A) --dOne--> Fun(G × G, A)`. -/ def shortComplexH1 : ShortComplex (ModuleCat k) := moduleCatMk (dZero A) (dOne A) (dOne_comp_dZero A) /-- The short complex `A --dZero--> Fun(G, A) --dOne--> Fun(G × G, A)` is isomorphic to the 1st short complex associated to the complex of inhomogeneous cochains of `A`. -/ @[simps! hom inv] def shortComplexH1Iso : (inhomogeneousCochains A).sc' 0 1 2 ≅ shortComplexH1 A := isoMk (zeroCochainsLequiv A).toModuleIso (oneCochainsLequiv A).toModuleIso (twoCochainsLequiv A).toModuleIso (dZero_comp_eq A) (dOne_comp_eq A) /-- The 1-cocycles of the complex of inhomogeneous cochains of `A` are isomorphic to `oneCocycles A`, which is a simpler type. -/ def isoOneCocycles : cocycles A 1 ≅ ModuleCat.of k (oneCocycles A) := (inhomogeneousCochains A).cyclesIsoSc' _ _ _ (by aesop) (by aesop) ≪≫ cyclesMapIso (shortComplexH1Iso A) ≪≫ (shortComplexH1 A).moduleCatCyclesIso lemma isoOneCocycles_hom_comp_subtype : (isoOneCocycles A).hom ≫ ModuleCat.ofHom (oneCocycles A).subtype = iCocycles A 1 ≫ (oneCochainsLequiv A).toModuleIso.hom := by dsimp [isoOneCocycles] rw [Category.assoc, Category.assoc] erw [(shortComplexH1 A).moduleCatCyclesIso_hom_subtype] rw [cyclesMap_i, HomologicalComplex.cyclesIsoSc'_hom_iCycles_assoc] lemma toCocycles_comp_isoOneCocycles_hom : toCocycles A 0 1 ≫ (isoOneCocycles A).hom = (zeroCochainsLequiv A).toModuleIso.hom ≫ ModuleCat.ofHom (shortComplexH1 A).moduleCatToCycles := by simp [isoOneCocycles] rfl /-- The 1st group cohomology of `A`, defined as the 1st cohomology of the complex of inhomogeneous cochains, is isomorphic to `oneCocycles A ⧸ oneCoboundaries A`, which is a simpler type. -/ def isoH1 : groupCohomology A 1 ≅ ModuleCat.of k (H1 A) := (inhomogeneousCochains A).homologyIsoSc' _ _ _ (by aesop) (by aesop) ≪≫ homologyMapIso (shortComplexH1Iso A) ≪≫ (shortComplexH1 A).moduleCatHomologyIso lemma groupCohomologyπ_comp_isoH1_hom : groupCohomologyπ A 1 ≫ (isoH1 A).hom = (isoOneCocycles A).hom ≫ (shortComplexH1 A).moduleCatHomologyπ := by simp [isoH1, isoOneCocycles] end H1 section H2 /-- The short complex `Fun(G, A) --dOne--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)`. -/ def shortComplexH2 : ShortComplex (ModuleCat k) := moduleCatMk (dOne A) (dTwo A) (dTwo_comp_dOne A) /-- The short complex `Fun(G, A) --dOne--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)` is isomorphic to the 2nd short complex associated to the complex of inhomogeneous cochains of `A`. -/ @[simps! hom inv] def shortComplexH2Iso : (inhomogeneousCochains A).sc' 1 2 3 ≅ shortComplexH2 A := isoMk (oneCochainsLequiv A).toModuleIso (twoCochainsLequiv A).toModuleIso (threeCochainsLequiv A).toModuleIso (dOne_comp_eq A) (dTwo_comp_eq A) /-- The 2-cocycles of the complex of inhomogeneous cochains of `A` are isomorphic to `twoCocycles A`, which is a simpler type. -/ def isoTwoCocycles : cocycles A 2 ≅ ModuleCat.of k (twoCocycles A) := (inhomogeneousCochains A).cyclesIsoSc' _ _ _ (by aesop) (by aesop) ≪≫ cyclesMapIso (shortComplexH2Iso A) ≪≫ (shortComplexH2 A).moduleCatCyclesIso lemma isoTwoCocycles_hom_comp_subtype : (isoTwoCocycles A).hom ≫ ModuleCat.ofHom (twoCocycles A).subtype = iCocycles A 2 ≫ (twoCochainsLequiv A).toModuleIso.hom := by dsimp [isoTwoCocycles] rw [Category.assoc, Category.assoc] erw [(shortComplexH2 A).moduleCatCyclesIso_hom_subtype] rw [cyclesMap_i, HomologicalComplex.cyclesIsoSc'_hom_iCycles_assoc] lemma toCocycles_comp_isoTwoCocycles_hom : toCocycles A 1 2 ≫ (isoTwoCocycles A).hom = (oneCochainsLequiv A).toModuleIso.hom ≫ ModuleCat.ofHom (shortComplexH2 A).moduleCatToCycles := by simp [isoTwoCocycles] rfl /-- The 2nd group cohomology of `A`, defined as the 2nd cohomology of the complex of inhomogeneous cochains, is isomorphic to `twoCocycles A ⧸ twoCoboundaries A`, which is a simpler type. -/ def isoH2 : groupCohomology A 2 ≅ ModuleCat.of k (H2 A) := (inhomogeneousCochains A).homologyIsoSc' _ _ _ (by aesop) (by aesop) ≪≫ homologyMapIso (shortComplexH2Iso A) ≪≫ (shortComplexH2 A).moduleCatHomologyIso lemma groupCohomologyπ_comp_isoH2_hom : groupCohomologyπ A 2 ≫ (isoH2 A).hom = (isoTwoCocycles A).hom ≫ (shortComplexH2 A).moduleCatHomologyπ := by simp [isoH2, isoTwoCocycles] end H2 end groupCohomologyIso end groupCohomology
RepresentationTheory\GroupCohomology\Resolution.lean
/- Copyright (c) 2022 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Category.ModuleCat.Projective import Mathlib.AlgebraicTopology.ExtraDegeneracy import Mathlib.CategoryTheory.Abelian.Ext import Mathlib.RepresentationTheory.Rep /-! # The structure of the `k[G]`-module `k[Gⁿ]` This file contains facts about an important `k[G]`-module structure on `k[Gⁿ]`, where `k` is a commutative ring and `G` is a group. The module structure arises from the representation `G →* End(k[Gⁿ])` induced by the diagonal action of `G` on `Gⁿ.` In particular, we define an isomorphism of `k`-linear `G`-representations between `k[Gⁿ⁺¹]` and `k[G] ⊗ₖ k[Gⁿ]` (on which `G` acts by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`). This allows us to define a `k[G]`-basis on `k[Gⁿ⁺¹]`, by mapping the natural `k[G]`-basis of `k[G] ⊗ₖ k[Gⁿ]` along the isomorphism. We then define the standard resolution of `k` as a trivial representation, by taking the alternating face map complex associated to an appropriate simplicial `k`-linear `G`-representation. This simplicial object is the `linearization` of the simplicial `G`-set given by the universal cover of the classifying space of `G`, `EG`. We prove this simplicial `G`-set `EG` is isomorphic to the Čech nerve of the natural arrow of `G`-sets `G ⟶ {pt}`. We then use this isomorphism to deduce that as a complex of `k`-modules, the standard resolution of `k` as a trivial `G`-representation is homotopy equivalent to the complex with `k` at 0 and 0 elsewhere. Putting this material together allows us to define `groupCohomology.projectiveResolution`, the standard projective resolution of `k` as a trivial `k`-linear `G`-representation. ## Main definitions * `groupCohomology.resolution.actionDiagonalSucc` * `groupCohomology.resolution.diagonalSucc` * `groupCohomology.resolution.ofMulActionBasis` * `classifyingSpaceUniversalCover` * `groupCohomology.resolution.forget₂ToModuleCatHomotopyEquiv` * `groupCohomology.projectiveResolution` ## Implementation notes We express `k[G]`-module structures on a module `k`-module `V` using the `Representation` definition. We avoid using instances `Module (G →₀ k) V` so that we do not run into possible scalar action diamonds. We also use the category theory library to bundle the type `k[Gⁿ]` - or more generally `k[H]` when `H` has `G`-action - and the representation together, as a term of type `Rep k G`, and call it `Rep.ofMulAction k G H.` This enables us to express the fact that certain maps are `G`-equivariant by constructing morphisms in the category `Rep k G`, i.e., representations of `G` over `k`. -/ /- Porting note: most altered proofs in this file involved changing `simp` to `rw` or `erw`, so https://github.com/leanprover-community/mathlib4/issues/5026 and https://github.com/leanprover-community/mathlib4/issues/5164 are relevant. -/ suppress_compilation noncomputable section universe u v w variable {k G : Type u} [CommRing k] {n : ℕ} open CategoryTheory local notation "Gⁿ" => Fin n → G set_option quotPrecheck false local notation "Gⁿ⁺¹" => Fin (n + 1) → G namespace groupCohomology.resolution open Finsupp hiding lift open MonoidalCategory open Fin (partialProd) section Basis variable (k G n) [Group G] section Action open Action /-- An isomorphism of `G`-sets `Gⁿ⁺¹ ≅ G × Gⁿ`, where `G` acts by left multiplication on `Gⁿ⁺¹` and `G` but trivially on `Gⁿ`. The map sends `(g₀, ..., gₙ) ↦ (g₀, (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ))`, and the inverse is `(g₀, (g₁, ..., gₙ)) ↦ (g₀, g₀g₁, g₀g₁g₂, ..., g₀g₁...gₙ).` -/ def actionDiagonalSucc (G : Type u) [Group G] : ∀ n : ℕ, diagonal G (n + 1) ≅ leftRegular G ⊗ Action.mk (Fin n → G) 1 | 0 => diagonalOneIsoLeftRegular G ≪≫ (ρ_ _).symm ≪≫ tensorIso (Iso.refl _) (tensorUnitIso (Equiv.equivOfUnique PUnit _).toIso) | n + 1 => diagonalSucc _ _ ≪≫ tensorIso (Iso.refl _) (actionDiagonalSucc G n) ≪≫ leftRegularTensorIso _ _ ≪≫ tensorIso (Iso.refl _) (mkIso (Equiv.piFinSuccAbove (fun _ => G) 0).symm.toIso fun _ => rfl) theorem actionDiagonalSucc_hom_apply {G : Type u} [Group G] {n : ℕ} (f : Fin (n + 1) → G) : (actionDiagonalSucc G n).hom.hom f = (f 0, fun i => (f (Fin.castSucc i))⁻¹ * f i.succ) := by induction' n with n hn · exact Prod.ext rfl (funext fun x => Fin.elim0 x) · refine Prod.ext rfl (funext fun x => ?_) /- Porting note (#11039): broken proof was · dsimp only [actionDiagonalSucc] simp only [Iso.trans_hom, comp_hom, types_comp_apply, diagonalSucc_hom_hom, leftRegularTensorIso_hom_hom, tensorIso_hom, mkIso_hom_hom, Equiv.toIso_hom, Action.tensorHom, Equiv.piFinSuccAbove_symm_apply, tensor_apply, types_id_apply, tensor_rho, MonoidHom.one_apply, End.one_def, hn fun j : Fin (n + 1) => f j.succ, Fin.insertNth_zero'] refine' Fin.cases (Fin.cons_zero _ _) (fun i => _) x · simp only [Fin.cons_succ, mul_left_inj, inv_inj, Fin.castSucc_fin_succ] -/ dsimp [actionDiagonalSucc] erw [hn (fun (j : Fin (n + 1)) => f j.succ)] exact Fin.cases rfl (fun i => rfl) x theorem actionDiagonalSucc_inv_apply {G : Type u} [Group G] {n : ℕ} (g : G) (f : Fin n → G) : (actionDiagonalSucc G n).inv.hom (g, f) = (g • Fin.partialProd f : Fin (n + 1) → G) := by revert g induction' n with n hn · intro g funext (x : Fin 1) simp only [Subsingleton.elim x 0, Pi.smul_apply, Fin.partialProd_zero, smul_eq_mul, mul_one] rfl · intro g /- Porting note (#11039): broken proof was ext dsimp only [actionDiagonalSucc] simp only [Iso.trans_inv, comp_hom, hn, diagonalSucc_inv_hom, types_comp_apply, tensorIso_inv, Iso.refl_inv, Action.tensorHom, id_hom, tensor_apply, types_id_apply, leftRegularTensorIso_inv_hom, tensor_rho, leftRegular_ρ_apply, Pi.smul_apply, smul_eq_mul] refine' Fin.cases _ _ x · simp only [Fin.cons_zero, Fin.partialProd_zero, mul_one] · intro i simpa only [Fin.cons_succ, Pi.smul_apply, smul_eq_mul, Fin.partialProd_succ', mul_assoc] -/ funext x dsimp [actionDiagonalSucc] erw [hn, Equiv.piFinSuccAbove_symm_apply] refine Fin.cases ?_ (fun i => ?_) x · simp only [Fin.insertNth_zero, Fin.cons_zero, Fin.partialProd_zero, mul_one] · simp only [Fin.cons_succ, Pi.smul_apply, smul_eq_mul, Fin.partialProd_succ', ← mul_assoc] rfl end Action section Rep open Rep /-- An isomorphism of `k`-linear representations of `G` from `k[Gⁿ⁺¹]` to `k[G] ⊗ₖ k[Gⁿ]` (on which `G` acts by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`) sending `(g₀, ..., gₙ)` to `g₀ ⊗ (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ)`. The inverse sends `g₀ ⊗ (g₁, ..., gₙ)` to `(g₀, g₀g₁, ..., g₀g₁...gₙ)`. -/ def diagonalSucc (n : ℕ) : diagonal k G (n + 1) ≅ leftRegular k G ⊗ trivial k G ((Fin n → G) →₀ k) := (linearization k G).mapIso (actionDiagonalSucc G n) ≪≫ (asIso ((linearization k G).μ (Action.leftRegular G) _)).symm ≪≫ tensorIso (Iso.refl _) (linearizationTrivialIso k G (Fin n → G)) variable {k G n} theorem diagonalSucc_hom_single (f : Gⁿ⁺¹) (a : k) : (diagonalSucc k G n).hom.hom (single f a) = single (f 0) 1 ⊗ₜ single (fun i => (f (Fin.castSucc i))⁻¹ * f i.succ) a := by /- Porting note (#11039): broken proof was dsimp only [diagonalSucc] simpa only [Iso.trans_hom, Iso.symm_hom, Action.comp_hom, ModuleCat.comp_def, LinearMap.comp_apply, Functor.mapIso_hom, linearization_map_hom_single (actionDiagonalSucc G n).hom f a, asIso_inv, linearization_μ_inv_hom, actionDiagonalSucc_hom_apply, finsuppTensorFinsupp', LinearEquiv.trans_symm, lcongr_symm, LinearEquiv.trans_apply, lcongr_single, TensorProduct.lid_symm_apply, finsuppTensorFinsupp_symm_single, LinearEquiv.coe_toLinearMap] -/ change (𝟙 ((linearization k G).1.obj (Action.leftRegular G)).V ⊗ (linearizationTrivialIso k G (Fin n → G)).hom.hom) ((inv ((linearization k G).μ (Action.leftRegular G) { V := Fin n → G, ρ := 1 })).hom ((lmapDomain k k (actionDiagonalSucc G n).hom.hom) (single f a))) = _ simp only [CategoryTheory.Functor.map_id, linearization_μ_inv_hom] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [lmapDomain_apply, mapDomain_single, LinearEquiv.coe_toLinearMap, finsuppTensorFinsupp', LinearEquiv.trans_symm, LinearEquiv.trans_apply, lcongr_symm, Equiv.refl_symm] erw [lcongr_single] rw [TensorProduct.lid_symm_apply, actionDiagonalSucc_hom_apply, finsuppTensorFinsupp_symm_single] rfl theorem diagonalSucc_inv_single_single (g : G) (f : Gⁿ) (a b : k) : (diagonalSucc k G n).inv.hom (Finsupp.single g a ⊗ₜ Finsupp.single f b) = single (g • partialProd f) (a * b) := by /- Porting note (#11039): broken proof was dsimp only [diagonalSucc] simp only [Iso.trans_inv, Iso.symm_inv, Iso.refl_inv, tensorIso_inv, Action.tensorHom, Action.comp_hom, ModuleCat.comp_def, LinearMap.comp_apply, asIso_hom, Functor.mapIso_inv, ModuleCat.MonoidalCategory.hom_apply, linearizationTrivialIso_inv_hom_apply, linearization_μ_hom, Action.id_hom ((linearization k G).obj _), actionDiagonalSucc_inv_apply, ModuleCat.id_apply, LinearEquiv.coe_toLinearMap, finsuppTensorFinsupp'_single_tmul_single k (Action.leftRegular G).V, linearization_map_hom_single (actionDiagonalSucc G n).inv (g, f) (a * b)] -/ change mapDomain (actionDiagonalSucc G n).inv.hom (lcongr (Equiv.refl (G × (Fin n → G))) (TensorProduct.lid k k) (finsuppTensorFinsupp k k k k G (Fin n → G) (single g a ⊗ₜ[k] single f b))) = single (g • partialProd f) (a * b) rw [finsuppTensorFinsupp_single, lcongr_single, mapDomain_single, Equiv.refl_apply, actionDiagonalSucc_inv_apply] rfl theorem diagonalSucc_inv_single_left (g : G) (f : Gⁿ →₀ k) (r : k) : (diagonalSucc k G n).inv.hom (Finsupp.single g r ⊗ₜ f) = Finsupp.lift (Gⁿ⁺¹ →₀ k) k Gⁿ (fun f => single (g • partialProd f) r) f := by refine f.induction ?_ ?_ /- Porting note (#11039): broken proof was · simp only [TensorProduct.tmul_zero, map_zero] · intro a b x ha hb hx simp only [lift_apply, smul_single', mul_one, TensorProduct.tmul_add, map_add, diagonalSucc_inv_single_single, hx, Finsupp.sum_single_index, mul_comm b, zero_mul, single_zero] -/ · rw [TensorProduct.tmul_zero, map_zero] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [map_zero] · intro _ _ _ _ _ hx rw [TensorProduct.tmul_add, map_add]; erw [map_add, hx] simp_rw [lift_apply, smul_single, smul_eq_mul] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [diagonalSucc_inv_single_single] rw [sum_single_index, mul_comm] rw [zero_mul, single_zero] theorem diagonalSucc_inv_single_right (g : G →₀ k) (f : Gⁿ) (r : k) : (diagonalSucc k G n).inv.hom (g ⊗ₜ Finsupp.single f r) = Finsupp.lift _ k G (fun a => single (a • partialProd f) r) g := by refine g.induction ?_ ?_ /- Porting note (#11039): broken proof was · simp only [TensorProduct.zero_tmul, map_zero] · intro a b x ha hb hx simp only [lift_apply, smul_single', map_add, hx, diagonalSucc_inv_single_single, TensorProduct.add_tmul, Finsupp.sum_single_index, zero_mul, single_zero] -/ · rw [TensorProduct.zero_tmul, map_zero] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [map_zero] · intro _ _ _ _ _ hx rw [TensorProduct.add_tmul, map_add]; erw [map_add, hx] simp_rw [lift_apply, smul_single'] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [diagonalSucc_inv_single_single] rw [sum_single_index] rw [zero_mul, single_zero] end Rep open scoped TensorProduct open Representation /-- The `k[G]`-linear isomorphism `k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹]`, where the `k[G]`-module structure on the lefthand side is `TensorProduct.leftModule`, whilst that of the righthand side comes from `Representation.asModule`. Allows us to use `Algebra.TensorProduct.basis` to get a `k[G]`-basis of the righthand side. -/ def ofMulActionBasisAux : MonoidAlgebra k G ⊗[k] ((Fin n → G) →₀ k) ≃ₗ[MonoidAlgebra k G] (ofMulAction k G (Fin (n + 1) → G)).asModule := { (Rep.equivalenceModuleMonoidAlgebra.1.mapIso (diagonalSucc k G n).symm).toLinearEquiv with map_smul' := fun r x => by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [RingHom.id_apply, LinearEquiv.toFun_eq_coe, ← LinearEquiv.map_smul] congr 1 /- Porting note (#11039): broken proof was refine' x.induction_on _ (fun x y => _) fun y z hy hz => _ · simp only [smul_zero] · simp only [TensorProduct.smul_tmul'] show (r * x) ⊗ₜ y = _ rw [← ofMulAction_self_smul_eq_mul, smul_tprod_one_asModule] · rw [smul_add, hz, hy, smul_add] -/ show _ = Representation.asAlgebraHom (tensorObj (Rep.leftRegular k G) (Rep.trivial k G ((Fin n → G) →₀ k))).ρ r _ refine x.induction_on ?_ (fun x y => ?_) fun y z hy hz => ?_ · rw [smul_zero, map_zero] · rw [TensorProduct.smul_tmul', smul_eq_mul, ← ofMulAction_self_smul_eq_mul] exact (smul_tprod_one_asModule (Representation.ofMulAction k G G) r x y).symm · rw [smul_add, hz, hy, map_add] } /-- A `k[G]`-basis of `k[Gⁿ⁺¹]`, coming from the `k[G]`-linear isomorphism `k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹].` -/ def ofMulActionBasis : Basis (Fin n → G) (MonoidAlgebra k G) (ofMulAction k G (Fin (n + 1) → G)).asModule := Basis.map (Algebra.TensorProduct.basis (MonoidAlgebra k G) (Finsupp.basisSingleOne : Basis (Fin n → G) k ((Fin n → G) →₀ k))) (ofMulActionBasisAux k G n) theorem ofMulAction_free : Module.Free (MonoidAlgebra k G) (ofMulAction k G (Fin (n + 1) → G)).asModule := Module.Free.of_basis (ofMulActionBasis k G n) end Basis end groupCohomology.resolution namespace Rep variable (n) [Group G] (A : Rep k G) open groupCohomology.resolution /-- Given a `k`-linear `G`-representation `A`, the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` is `k`-linearly isomorphic to the set of functions `Gⁿ → A`. -/ noncomputable def diagonalHomEquiv : (Rep.ofMulAction k G (Fin (n + 1) → G) ⟶ A) ≃ₗ[k] (Fin n → G) → A := Linear.homCongr k ((diagonalSucc k G n).trans ((Representation.ofMulAction k G G).repOfTprodIso 1)) (Iso.refl _) ≪≫ₗ (Rep.MonoidalClosed.linearHomEquivComm _ _ _ ≪≫ₗ Rep.leftRegularHomEquiv _) ≪≫ₗ (Finsupp.llift A k k (Fin n → G)).symm variable {n A} /-- Given a `k`-linear `G`-representation `A`, `diagonalHomEquiv` is a `k`-linear isomorphism of the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` with `Fun(Gⁿ, A)`. This lemma says that this sends a morphism of representations `f : k[Gⁿ⁺¹] ⟶ A` to the function `(g₁, ..., gₙ) ↦ f(1, g₁, g₁g₂, ..., g₁g₂...gₙ).` -/ theorem diagonalHomEquiv_apply (f : Rep.ofMulAction k G (Fin (n + 1) → G) ⟶ A) (x : Fin n → G) : diagonalHomEquiv n A f x = f.hom (Finsupp.single (Fin.partialProd x) 1) := by /- Porting note (#11039): broken proof was unfold diagonalHomEquiv simpa only [LinearEquiv.trans_apply, Rep.leftRegularHomEquiv_apply, MonoidalClosed.linearHomEquivComm_hom, Finsupp.llift_symm_apply, TensorProduct.curry_apply, Linear.homCongr_apply, Iso.refl_hom, Iso.trans_inv, Action.comp_hom, ModuleCat.comp_def, LinearMap.comp_apply, Representation.repOfTprodIso_inv_apply, diagonalSucc_inv_single_single (1 : G) x, one_smul, one_mul] -/ change f.hom ((diagonalSucc k G n).inv.hom (Finsupp.single 1 1 ⊗ₜ[k] Finsupp.single x 1)) = _ rw [diagonalSucc_inv_single_single, one_smul, one_mul] /-- Given a `k`-linear `G`-representation `A`, `diagonalHomEquiv` is a `k`-linear isomorphism of the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` with `Fun(Gⁿ, A)`. This lemma says that the inverse map sends a function `f : Gⁿ → A` to the representation morphism sending `(g₀, ... gₙ) ↦ ρ(g₀)(f(g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ))`, where `ρ` is the representation attached to `A`. -/ theorem diagonalHomEquiv_symm_apply (f : (Fin n → G) → A) (x : Fin (n + 1) → G) : ((diagonalHomEquiv n A).symm f).hom (Finsupp.single x 1) = A.ρ (x 0) (f fun i : Fin n => (x (Fin.castSucc i))⁻¹ * x i.succ) := by unfold diagonalHomEquiv /- Porting note (#11039): broken proof was simp only [LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.trans_apply, Rep.leftRegularHomEquiv_symm_apply, Linear.homCongr_symm_apply, Action.comp_hom, Iso.refl_inv, Category.comp_id, Rep.MonoidalClosed.linearHomEquivComm_symm_hom, Iso.trans_hom, ModuleCat.comp_def, LinearMap.comp_apply, Representation.repOfTprodIso_apply, diagonalSucc_hom_single x (1 : k), TensorProduct.uncurry_apply, Rep.leftRegularHom_hom, Finsupp.lift_apply, ihom_obj_ρ_def, Rep.ihom_obj_ρ_apply, Finsupp.sum_single_index, zero_smul, one_smul, Rep.of_ρ, Rep.Action_ρ_eq_ρ, Rep.trivial_def (x 0)⁻¹, Finsupp.llift_apply A k k] -/ simp only [LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.trans_apply, leftRegularHomEquiv_symm_apply, Linear.homCongr_symm_apply, Iso.trans_hom, Iso.refl_inv, Category.comp_id, Action.comp_hom, MonoidalClosed.linearHomEquivComm_symm_hom] -- Porting note: This is a sure sign that coercions for morphisms in `ModuleCat` -- are still not set up properly. -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [ModuleCat.coe_comp] simp only [ModuleCat.coe_comp, Function.comp_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [diagonalSucc_hom_single] erw [TensorProduct.uncurry_apply, Finsupp.lift_apply, Finsupp.sum_single_index] · simp only [one_smul] erw [Representation.linHom_apply] simp only [LinearMap.comp_apply, MonoidHom.one_apply, LinearMap.one_apply] erw [Finsupp.llift_apply] rw [Finsupp.lift_apply] erw [Finsupp.sum_single_index] · rw [one_smul] · rw [zero_smul] · rw [zero_smul] /-- Auxiliary lemma for defining group cohomology, used to show that the isomorphism `diagonalHomEquiv` commutes with the differentials in two complexes which compute group cohomology. -/ theorem diagonalHomEquiv_symm_partialProd_succ (f : (Fin n → G) → A) (g : Fin (n + 1) → G) (a : Fin (n + 1)) : ((diagonalHomEquiv n A).symm f).hom (Finsupp.single (Fin.partialProd g ∘ a.succ.succAbove) 1) = f (Fin.contractNth a (· * ·) g) := by simp only [diagonalHomEquiv_symm_apply, Function.comp_apply, Fin.succ_succAbove_zero, Fin.partialProd_zero, map_one, Fin.succ_succAbove_succ, LinearMap.one_apply, Fin.partialProd_succ] congr ext rw [← Fin.partialProd_succ, Fin.inv_partialProd_mul_eq_contractNth] end Rep variable (G) /-- The simplicial `G`-set sending `[n]` to `Gⁿ⁺¹` equipped with the diagonal action of `G`. -/ def classifyingSpaceUniversalCover [Monoid G] : SimplicialObject (Action (Type u) <| MonCat.of G) where obj n := Action.ofMulAction G (Fin (n.unop.len + 1) → G) map f := { hom := fun x => x ∘ f.unop.toOrderHom comm := fun _ => rfl } map_id _ := rfl map_comp _ _ := rfl namespace classifyingSpaceUniversalCover open CategoryTheory CategoryTheory.Limits variable [Monoid G] /-- When the category is `G`-Set, `cechNerveTerminalFrom` of `G` with the left regular action is isomorphic to `EG`, the universal cover of the classifying space of `G` as a simplicial `G`-set. -/ def cechNerveTerminalFromIso : cechNerveTerminalFrom (Action.ofMulAction G G) ≅ classifyingSpaceUniversalCover G := NatIso.ofComponents (fun n => limit.isoLimitCone (Action.ofMulActionLimitCone _ _)) fun f => by refine IsLimit.hom_ext (Action.ofMulActionLimitCone.{u, 0} G fun _ => G).2 fun j => ?_ dsimp only [cechNerveTerminalFrom, Pi.lift] rw [Category.assoc, limit.isoLimitCone_hom_π, limit.lift_π, Category.assoc] exact (limit.isoLimitCone_hom_π _ _).symm /-- As a simplicial set, `cechNerveTerminalFrom` of a monoid `G` is isomorphic to the universal cover of the classifying space of `G` as a simplicial set. -/ def cechNerveTerminalFromIsoCompForget : cechNerveTerminalFrom G ≅ classifyingSpaceUniversalCover G ⋙ forget _ := NatIso.ofComponents (fun _ => Types.productIso _) fun _ => Matrix.ext fun _ _ => Types.Limit.lift_π_apply (Discrete.functor fun _ ↦ G) _ _ _ variable (k) open AlgebraicTopology SimplicialObject.Augmented SimplicialObject CategoryTheory.Arrow /-- The universal cover of the classifying space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object in `Type u`. -/ def compForgetAugmented : SimplicialObject.Augmented (Type u) := SimplicialObject.augment (classifyingSpaceUniversalCover G ⋙ forget _) (terminal _) (terminal.from _) fun _ _ _ => Subsingleton.elim _ _ /-- The augmented Čech nerve of the map from `Fin 1 → G` to the terminal object in `Type u` has an extra degeneracy. -/ def extraDegeneracyAugmentedCechNerve : ExtraDegeneracy (Arrow.mk <| terminal.from G).augmentedCechNerve := AugmentedCechNerve.extraDegeneracy (Arrow.mk <| terminal.from G) ⟨fun _ => (1 : G), @Subsingleton.elim _ (@Unique.instSubsingleton _ (Limits.uniqueToTerminal _)) _ _⟩ /-- The universal cover of the classifying space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object in `Type u`, has an extra degeneracy. -/ def extraDegeneracyCompForgetAugmented : ExtraDegeneracy (compForgetAugmented G) := by refine ExtraDegeneracy.ofIso (?_ : (Arrow.mk <| terminal.from G).augmentedCechNerve ≅ _) (extraDegeneracyAugmentedCechNerve G) exact Comma.isoMk (CechNerveTerminalFrom.iso G ≪≫ cechNerveTerminalFromIsoCompForget G) (Iso.refl _) (by ext : 1; exact IsTerminal.hom_ext terminalIsTerminal _ _) /-- The free functor `Type u ⥤ ModuleCat.{u} k` applied to the universal cover of the classifying space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object in `Type u`. -/ def compForgetAugmented.toModule : SimplicialObject.Augmented (ModuleCat.{u} k) := ((SimplicialObject.Augmented.whiskering _ _).obj (ModuleCat.free k)).obj (compForgetAugmented G) /-- If we augment the universal cover of the classifying space of `G` as a simplicial set by the map from `Fin 1 → G` to the terminal object in `Type u`, then apply the free functor `Type u ⥤ ModuleCat.{u} k`, the resulting augmented simplicial `k`-module has an extra degeneracy. -/ def extraDegeneracyCompForgetAugmentedToModule : ExtraDegeneracy (compForgetAugmented.toModule k G) := ExtraDegeneracy.map (extraDegeneracyCompForgetAugmented G) (ModuleCat.free k) end classifyingSpaceUniversalCover variable (k) /-- The standard resolution of `k` as a trivial representation, defined as the alternating face map complex of a simplicial `k`-linear `G`-representation. -/ def groupCohomology.resolution [Monoid G] := (AlgebraicTopology.alternatingFaceMapComplex (Rep k G)).obj (classifyingSpaceUniversalCover G ⋙ (Rep.linearization k G).1.1) namespace groupCohomology.resolution open classifyingSpaceUniversalCover AlgebraicTopology CategoryTheory CategoryTheory.Limits variable [Monoid G] /-- The `k`-linear map underlying the differential in the standard resolution of `k` as a trivial `k`-linear `G`-representation. It sends `(g₀, ..., gₙ) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ)`. -/ def d (G : Type u) (n : ℕ) : ((Fin (n + 1) → G) →₀ k) →ₗ[k] (Fin n → G) →₀ k := Finsupp.lift ((Fin n → G) →₀ k) k (Fin (n + 1) → G) fun g => (@Finset.univ (Fin (n + 1)) _).sum fun p => Finsupp.single (g ∘ p.succAbove) ((-1 : k) ^ (p : ℕ)) variable {k G} @[simp] theorem d_of {G : Type u} {n : ℕ} (c : Fin (n + 1) → G) : d k G n (Finsupp.single c 1) = Finset.univ.sum fun p : Fin (n + 1) => Finsupp.single (c ∘ p.succAbove) ((-1 : k) ^ (p : ℕ)) := by simp [d] variable (k G) /-- The `n`th object of the standard resolution of `k` is definitionally isomorphic to `k[Gⁿ⁺¹]` equipped with the representation induced by the diagonal action of `G`. -/ def xIso (n : ℕ) : (groupCohomology.resolution k G).X n ≅ Rep.ofMulAction k G (Fin (n + 1) → G) := Iso.refl _ instance x_projective (G : Type u) [Group G] (n : ℕ) : Projective ((groupCohomology.resolution k G).X n) := Rep.equivalenceModuleMonoidAlgebra.toAdjunction.projective_of_map_projective _ <| @ModuleCat.projective_of_free.{u} _ _ (ModuleCat.of (MonoidAlgebra k G) (Representation.ofMulAction k G (Fin (n + 1) → G)).asModule) _ (ofMulActionBasis k G n) /-- Simpler expression for the differential in the standard resolution of `k` as a `G`-representation. It sends `(g₀, ..., gₙ₊₁) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ₊₁)`. -/ theorem d_eq (n : ℕ) : ((groupCohomology.resolution k G).d (n + 1) n).hom = d k G (n + 1) := by refine Finsupp.lhom_ext' fun x => LinearMap.ext_ring ?_ dsimp [groupCohomology.resolution] /- Porting note (#11039): broken proof was simpa [← @intCast_smul k, simplicial_object.δ] -/ simp_rw [alternatingFaceMapComplex_obj_d, AlternatingFaceMapComplex.objD, SimplicialObject.δ, Functor.comp_map, ← Int.cast_smul_eq_zsmul k ((-1) ^ _ : ℤ), Int.cast_pow, Int.cast_neg, Int.cast_one, Action.sum_hom, Action.smul_hom, Rep.linearization_map_hom] rw [LinearMap.coeFn_sum, Fintype.sum_apply] erw [d_of (k := k) x] /- Porting note: want to rewrite `LinearMap.smul_apply` but simp/simp_rw won't do it; I need erw, so using Finset.sum_congr to get rid of the binder -/ refine Finset.sum_congr rfl fun _ _ => ?_ erw [LinearMap.smul_apply] rw [Finsupp.lmapDomain_apply, Finsupp.mapDomain_single, Finsupp.smul_single', mul_one] rfl section Exactness /-- The standard resolution of `k` as a trivial representation as a complex of `k`-modules. -/ def forget₂ToModuleCat := ((forget₂ (Rep k G) (ModuleCat.{u} k)).mapHomologicalComplex _).obj (groupCohomology.resolution k G) /-- If we apply the free functor `Type u ⥤ ModuleCat.{u} k` to the universal cover of the classifying space of `G` as a simplicial set, then take the alternating face map complex, the result is isomorphic to the standard resolution of the trivial `G`-representation `k` as a complex of `k`-modules. -/ def compForgetAugmentedIso : AlternatingFaceMapComplex.obj (SimplicialObject.Augmented.drop.obj (compForgetAugmented.toModule k G)) ≅ groupCohomology.resolution.forget₂ToModuleCat k G := eqToIso (Functor.congr_obj (map_alternatingFaceMapComplex (forget₂ (Rep k G) (ModuleCat.{u} k))).symm (classifyingSpaceUniversalCover G ⋙ (Rep.linearization k G).1.1)) /-- As a complex of `k`-modules, the standard resolution of the trivial `G`-representation `k` is homotopy equivalent to the complex which is `k` at 0 and 0 elsewhere. -/ def forget₂ToModuleCatHomotopyEquiv : HomotopyEquiv (groupCohomology.resolution.forget₂ToModuleCat k G) ((ChainComplex.single₀ (ModuleCat k)).obj ((forget₂ (Rep k G) _).obj <| Rep.trivial k G k)) := (HomotopyEquiv.ofIso (compForgetAugmentedIso k G).symm).trans <| (SimplicialObject.Augmented.ExtraDegeneracy.homotopyEquiv (extraDegeneracyCompForgetAugmentedToModule k G)).trans (HomotopyEquiv.ofIso <| (ChainComplex.single₀ (ModuleCat.{u} k)).mapIso (@Finsupp.LinearEquiv.finsuppUnique k k _ _ _ (⊤_ Type u) Types.terminalIso.toEquiv.unique).toModuleIso) /-- The hom of `k`-linear `G`-representations `k[G¹] → k` sending `∑ nᵢgᵢ ↦ ∑ nᵢ`. -/ def ε : Rep.ofMulAction k G (Fin 1 → G) ⟶ Rep.trivial k G k where hom := Finsupp.total _ _ _ fun _ => (1 : k) comm g := Finsupp.lhom_ext' fun _ => LinearMap.ext_ring (by show Finsupp.total (Fin 1 → G) k k (fun _ => (1 : k)) (Finsupp.mapDomain _ (Finsupp.single _ _)) = Finsupp.total (Fin 1 → G) k k (fun _ => (1 : k)) (Finsupp.single _ _) simp only [Finsupp.mapDomain_single, Finsupp.total_single]) /-- The homotopy equivalence of complexes of `k`-modules between the standard resolution of `k` as a trivial `G`-representation, and the complex which is `k` at 0 and 0 everywhere else, acts as `∑ nᵢgᵢ ↦ ∑ nᵢ : k[G¹] → k` at 0. -/ theorem forget₂ToModuleCatHomotopyEquiv_f_0_eq : (forget₂ToModuleCatHomotopyEquiv k G).1.f 0 = (forget₂ (Rep k G) _).map (ε k G) := by show (HomotopyEquiv.hom _ ≫ HomotopyEquiv.hom _ ≫ HomotopyEquiv.hom _).f 0 = _ simp only [HomologicalComplex.comp_f] dsimp convert Category.id_comp (X := (forget₂ToModuleCat k G).X 0) _ · dsimp only [HomotopyEquiv.ofIso, compForgetAugmentedIso] simp only [Iso.symm_hom, eqToIso.inv, HomologicalComplex.eqToHom_f, eqToHom_refl] trans (Finsupp.total _ _ _ fun _ => (1 : k)).comp ((ModuleCat.free k).map (terminal.from _)) · dsimp erw [Finsupp.lmapDomain_total (α := Fin 1 → G) (R := k) (α' := ⊤_ Type u) (v := fun _ => (1 : k)) (v' := fun _ => (1 : k)) (terminal.from ((classifyingSpaceUniversalCover G).obj (Opposite.op (SimplexCategory.mk 0))).V) LinearMap.id fun i => rfl, LinearMap.id_comp] rfl · congr · ext x dsimp (config := { unfoldPartialApp := true }) [HomotopyEquiv.ofIso, Finsupp.LinearEquiv.finsuppUnique] rw [Finsupp.total_single, one_smul, @Unique.eq_default _ Types.terminalIso.toEquiv.unique x, ChainComplex.single₀_map_f_zero, LinearMap.coe_mk, AddHom.coe_mk, Function.comp_apply, Finsupp.equivFunOnFinite_apply, Finsupp.single_eq_same] · exact @Subsingleton.elim _ (@Unique.instSubsingleton _ (Limits.uniqueToTerminal _)) _ _ theorem d_comp_ε : (groupCohomology.resolution k G).d 1 0 ≫ ε k G = 0 := by ext : 1 refine LinearMap.ext fun x => ?_ have : (forget₂ToModuleCat k G).d 1 0 ≫ (forget₂ (Rep k G) (ModuleCat.{u} k)).map (ε k G) = 0 := by rw [← forget₂ToModuleCatHomotopyEquiv_f_0_eq, ← (forget₂ToModuleCatHomotopyEquiv k G).1.2 1 0 rfl] exact comp_zero exact LinearMap.ext_iff.1 this _ /-- The chain map from the standard resolution of `k` to `k[0]` given by `∑ nᵢgᵢ ↦ ∑ nᵢ` in degree zero. -/ def εToSingle₀ : groupCohomology.resolution k G ⟶ (ChainComplex.single₀ _).obj (Rep.trivial k G k) := ((groupCohomology.resolution k G).toSingle₀Equiv _).symm ⟨ε k G, d_comp_ε k G⟩ theorem εToSingle₀_comp_eq : ((forget₂ _ (ModuleCat.{u} k)).mapHomologicalComplex _).map (εToSingle₀ k G) ≫ (HomologicalComplex.singleMapHomologicalComplex _ _ _).hom.app _ = (forget₂ToModuleCatHomotopyEquiv k G).hom := by dsimp ext1 dsimp simpa using (forget₂ToModuleCatHomotopyEquiv_f_0_eq k G).symm theorem quasiIso_forget₂_εToSingle₀ : QuasiIso (((forget₂ _ (ModuleCat.{u} k)).mapHomologicalComplex _).map (εToSingle₀ k G)) := by have h : QuasiIso (forget₂ToModuleCatHomotopyEquiv k G).hom := inferInstance rw [← εToSingle₀_comp_eq k G] at h exact quasiIso_of_comp_right (hφφ' := h) instance : QuasiIso (εToSingle₀ k G) := by rw [← HomologicalComplex.quasiIso_map_iff_of_preservesHomology _ (forget₂ _ (ModuleCat.{u} k))] apply quasiIso_forget₂_εToSingle₀ end Exactness end groupCohomology.resolution open groupCohomology.resolution HomologicalComplex.Hom variable [Group G] /-- The standard projective resolution of `k` as a trivial `k`-linear `G`-representation. -/ def groupCohomology.projectiveResolution : ProjectiveResolution (Rep.trivial k G k) where π := εToSingle₀ k G instance : EnoughProjectives (Rep k G) := Rep.equivalenceModuleMonoidAlgebra.enoughProjectives_iff.2 ModuleCat.moduleCat_enoughProjectives.{u} /-- Given a `k`-linear `G`-representation `V`, `Extⁿ(k, V)` (where `k` is a trivial `k`-linear `G`-representation) is isomorphic to the `n`th cohomology group of `Hom(P, V)`, where `P` is the standard resolution of `k` called `groupCohomology.resolution k G`. -/ def groupCohomology.extIso (V : Rep k G) (n : ℕ) : ((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj V ≅ ((groupCohomology.resolution k G).linearYonedaObj k V).homology n := (groupCohomology.projectiveResolution k G).isoExt n V
RingTheory\AdjoinRoot.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.PowerBasis import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.RingTheory.QuotientNoetherian import Mathlib.RingTheory.Polynomial.Quotient /-! # Adjoining roots of polynomials This file defines the commutative ring `AdjoinRoot f`, the ring R[X]/(f) obtained from a commutative ring `R` and a polynomial `f : R[X]`. If furthermore `R` is a field and `f` is irreducible, the field structure on `AdjoinRoot f` is constructed. We suggest stating results on `IsAdjoinRoot` instead of `AdjoinRoot` to achieve higher generality, since `IsAdjoinRoot` works for all different constructions of `R[α]` including `AdjoinRoot f = R[X]/(f)` itself. ## Main definitions and results The main definitions are in the `AdjoinRoot` namespace. * `mk f : R[X] →+* AdjoinRoot f`, the natural ring homomorphism. * `of f : R →+* AdjoinRoot f`, the natural ring homomorphism. * `root f : AdjoinRoot f`, the image of X in R[X]/(f). * `lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : (AdjoinRoot f) →+* S`, the ring homomorphism from R[X]/(f) to S extending `i : R →+* S` and sending `X` to `x`. * `lift_hom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S`, the algebra homomorphism from R[X]/(f) to S extending `algebraMap R S` and sending `X` to `x` * `equiv : (AdjoinRoot f →ₐ[F] E) ≃ {x // x ∈ f.aroots E}` a bijection between algebra homomorphisms from `AdjoinRoot` and roots of `f` in `S` -/ noncomputable section open scoped Classical open Polynomial universe u v w variable {R : Type u} {S : Type v} {K : Type w} open Polynomial Ideal /-- Adjoin a root of a polynomial `f` to a commutative ring `R`. We define the new ring as the quotient of `R[X]` by the principal ideal generated by `f`. -/ def AdjoinRoot [CommRing R] (f : R[X]) : Type u := Polynomial R ⧸ (span {f} : Ideal R[X]) namespace AdjoinRoot section CommRing variable [CommRing R] (f : R[X]) instance instCommRing : CommRing (AdjoinRoot f) := Ideal.Quotient.commRing _ instance : Inhabited (AdjoinRoot f) := ⟨0⟩ instance : DecidableEq (AdjoinRoot f) := Classical.decEq _ protected theorem nontrivial [IsDomain R] (h : degree f ≠ 0) : Nontrivial (AdjoinRoot f) := Ideal.Quotient.nontrivial (by simp_rw [Ne, span_singleton_eq_top, Polynomial.isUnit_iff, not_exists, not_and] rintro x hx rfl exact h (degree_C hx.ne_zero)) /-- Ring homomorphism from `R[x]` to `AdjoinRoot f` sending `X` to the `root`. -/ def mk : R[X] →+* AdjoinRoot f := Ideal.Quotient.mk _ @[elab_as_elim] theorem induction_on {C : AdjoinRoot f → Prop} (x : AdjoinRoot f) (ih : ∀ p : R[X], C (mk f p)) : C x := Quotient.inductionOn' x ih /-- Embedding of the original ring `R` into `AdjoinRoot f`. -/ def of : R →+* AdjoinRoot f := (mk f).comp C instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) := Submodule.Quotient.instSMul' _ instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) := Submodule.Quotient.distribSMul' _ @[simp] theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) : a • mk f x = mk f (a • x) := rfl theorem smul_of [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R) : a • of f x = of f (a • x) := by rw [of, RingHom.comp_apply, RingHom.comp_apply, smul_mk, smul_C] instance (R₁ R₂ : Type*) [SMul R₁ R₂] [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [IsScalarTower R₁ R₂ R] (f : R[X]) : IsScalarTower R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.isScalarTower _ _ instance (R₁ R₂ : Type*) [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [SMulCommClass R₁ R₂ R] (f : R[X]) : SMulCommClass R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.smulCommClass _ _ instance isScalarTower_right [DistribSMul S R] [IsScalarTower S R R] : IsScalarTower S (AdjoinRoot f) (AdjoinRoot f) := Ideal.Quotient.isScalarTower_right instance [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (f : R[X]) : DistribMulAction S (AdjoinRoot f) := Submodule.Quotient.distribMulAction' _ instance [CommSemiring S] [Algebra S R] : Algebra S (AdjoinRoot f) := Ideal.Quotient.algebra S @[simp] theorem algebraMap_eq : algebraMap R (AdjoinRoot f) = of f := rfl variable (S) theorem algebraMap_eq' [CommSemiring S] [Algebra S R] : algebraMap S (AdjoinRoot f) = (of f).comp (algebraMap S R) := rfl variable {S} theorem finiteType : Algebra.FiniteType R (AdjoinRoot f) := (Algebra.FiniteType.polynomial R).of_surjective _ (Ideal.Quotient.mkₐ_surjective R _) theorem finitePresentation : Algebra.FinitePresentation R (AdjoinRoot f) := (Algebra.FinitePresentation.polynomial R).quotient (Submodule.fg_span_singleton f) /-- The adjoined root. -/ def root : AdjoinRoot f := mk f X variable {f} instance hasCoeT : CoeTC R (AdjoinRoot f) := ⟨of f⟩ /-- Two `R`-`AlgHom` from `AdjoinRoot f` to the same `R`-algebra are the same iff they agree on `root f`. -/ @[ext] theorem algHom_ext [Semiring S] [Algebra R S] {g₁ g₂ : AdjoinRoot f →ₐ[R] S} (h : g₁ (root f) = g₂ (root f)) : g₁ = g₂ := Ideal.Quotient.algHom_ext R <| Polynomial.algHom_ext h @[simp] theorem mk_eq_mk {g h : R[X]} : mk f g = mk f h ↔ f ∣ g - h := Ideal.Quotient.eq.trans Ideal.mem_span_singleton @[simp] theorem mk_eq_zero {g : R[X]} : mk f g = 0 ↔ f ∣ g := mk_eq_mk.trans <| by rw [sub_zero] @[simp] theorem mk_self : mk f f = 0 := Quotient.sound' <| QuotientAddGroup.leftRel_apply.mpr (mem_span_singleton.2 <| by simp) @[simp] theorem mk_C (x : R) : mk f (C x) = x := rfl @[simp] theorem mk_X : mk f X = root f := rfl theorem mk_ne_zero_of_degree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : degree g < degree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_degree_lt h0 hd theorem mk_ne_zero_of_natDegree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : natDegree g < natDegree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_natDegree_lt h0 hd @[simp] theorem aeval_eq (p : R[X]) : aeval (root f) p = mk f p := Polynomial.induction_on p (fun x => by rw [aeval_C] rfl) (fun p q ihp ihq => by rw [map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [_root_.map_mul, aeval_C, map_pow, aeval_X, RingHom.map_mul, mk_C, RingHom.map_pow, mk_X] rfl -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem adjoinRoot_eq_top : Algebra.adjoin R ({root f} : Set (AdjoinRoot f)) = ⊤ := by refine Algebra.eq_top_iff.2 fun x => ?_ induction x using AdjoinRoot.induction_on with | ih p => exact (Algebra.adjoin_singleton_eq_range_aeval R (root f)).symm ▸ ⟨p, aeval_eq p⟩ @[simp] theorem eval₂_root (f : R[X]) : f.eval₂ (of f) (root f) = 0 := by rw [← algebraMap_eq, ← aeval_def, aeval_eq, mk_self] theorem isRoot_root (f : R[X]) : IsRoot (f.map (of f)) (root f) := by rw [IsRoot, eval_map, eval₂_root] theorem isAlgebraic_root (hf : f ≠ 0) : IsAlgebraic R (root f) := ⟨f, hf, eval₂_root f⟩ theorem of.injective_of_degree_ne_zero [IsDomain R] (hf : f.degree ≠ 0) : Function.Injective (AdjoinRoot.of f) := by rw [injective_iff_map_eq_zero] intro p hp rw [AdjoinRoot.of, RingHom.comp_apply, AdjoinRoot.mk_eq_zero] at hp by_cases h : f = 0 · exact C_eq_zero.mp (eq_zero_of_zero_dvd (by rwa [h] at hp)) · contrapose! hf with h_contra rw [← degree_C h_contra] apply le_antisymm (degree_le_of_dvd hp (by rwa [Ne, C_eq_zero])) _ rwa [degree_C h_contra, zero_le_degree_iff] variable [CommRing S] /-- Lift a ring homomorphism `i : R →+* S` to `AdjoinRoot f →+* S`. -/ def lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : AdjoinRoot f →+* S := by apply Ideal.Quotient.lift _ (eval₂RingHom i x) intro g H rcases mem_span_singleton.1 H with ⟨y, hy⟩ rw [hy, RingHom.map_mul, coe_eval₂RingHom, h, zero_mul] variable {i : R →+* S} {a : S} (h : f.eval₂ i a = 0) @[simp] theorem lift_mk (g : R[X]) : lift i a h (mk f g) = g.eval₂ i a := Ideal.Quotient.lift_mk _ _ _ @[simp] theorem lift_root : lift i a h (root f) = a := by rw [root, lift_mk, eval₂_X] @[simp] theorem lift_of {x : R} : lift i a h x = i x := by rw [← mk_C x, lift_mk, eval₂_C] @[simp] theorem lift_comp_of : (lift i a h).comp (of f) = i := RingHom.ext fun _ => @lift_of _ _ _ _ _ _ _ h _ variable (f) [Algebra R S] /-- Produce an algebra homomorphism `AdjoinRoot f →ₐ[R] S` sending `root f` to a root of `f` in `S`. -/ def liftHom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S := { lift (algebraMap R S) x hfx with commutes' := fun r => show lift _ _ hfx r = _ from lift_of hfx } @[simp] theorem coe_liftHom (x : S) (hfx : aeval x f = 0) : (liftHom f x hfx : AdjoinRoot f →+* S) = lift (algebraMap R S) x hfx := rfl @[simp] theorem aeval_algHom_eq_zero (ϕ : AdjoinRoot f →ₐ[R] S) : aeval (ϕ (root f)) f = 0 := by have h : ϕ.toRingHom.comp (of f) = algebraMap R S := RingHom.ext_iff.mpr ϕ.commutes rw [aeval_def, ← h, ← RingHom.map_zero ϕ.toRingHom, ← eval₂_root f, hom_eval₂] rfl @[simp] theorem liftHom_eq_algHom (f : R[X]) (ϕ : AdjoinRoot f →ₐ[R] S) : liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ) = ϕ := by suffices AlgHom.equalizer ϕ (liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ)) = ⊤ by exact (AlgHom.ext fun x => (SetLike.ext_iff.mp this x).mpr Algebra.mem_top).symm rw [eq_top_iff, ← adjoinRoot_eq_top, Algebra.adjoin_le_iff, Set.singleton_subset_iff] exact (@lift_root _ _ _ _ _ _ _ (aeval_algHom_eq_zero f ϕ)).symm variable (hfx : aeval a f = 0) @[simp] theorem liftHom_mk {g : R[X]} : liftHom f a hfx (mk f g) = aeval a g := lift_mk hfx g @[simp] theorem liftHom_root : liftHom f a hfx (root f) = a := lift_root hfx @[simp] theorem liftHom_of {x : R} : liftHom f a hfx (of f x) = algebraMap _ _ x := lift_of hfx section AdjoinInv @[simp] theorem root_isInv (r : R) : of _ r * root (C r * X - 1) = 1 := by convert sub_eq_zero.1 ((eval₂_sub _).symm.trans <| eval₂_root <| C r * X - 1) <;> simp only [eval₂_mul, eval₂_C, eval₂_X, eval₂_one] theorem algHom_subsingleton {S : Type*} [CommRing S] [Algebra R S] {r : R} : Subsingleton (AdjoinRoot (C r * X - 1) →ₐ[R] S) := ⟨fun f g => algHom_ext (@inv_unique _ _ (algebraMap R S r) _ _ (by rw [← f.commutes, ← _root_.map_mul, algebraMap_eq, root_isInv, map_one]) (by rw [← g.commutes, ← _root_.map_mul, algebraMap_eq, root_isInv, map_one]))⟩ end AdjoinInv section Prime variable {f} theorem isDomain_of_prime (hf : Prime f) : IsDomain (AdjoinRoot f) := (Ideal.Quotient.isDomain_iff_prime (span {f} : Ideal R[X])).mpr <| (Ideal.span_singleton_prime hf.ne_zero).mpr hf theorem noZeroSMulDivisors_of_prime_of_degree_ne_zero [IsDomain R] (hf : Prime f) (hf' : f.degree ≠ 0) : NoZeroSMulDivisors R (AdjoinRoot f) := haveI := isDomain_of_prime hf NoZeroSMulDivisors.iff_algebraMap_injective.mpr (of.injective_of_degree_ne_zero hf') end Prime end CommRing section Irreducible variable [Field K] {f : K[X]} instance span_maximal_of_irreducible [Fact (Irreducible f)] : (span {f}).IsMaximal := PrincipalIdealRing.isMaximal_of_irreducible <| Fact.out noncomputable instance instGroupWithZero [Fact (Irreducible f)] : GroupWithZero (AdjoinRoot f) := Quotient.groupWithZero (span {f} : Ideal K[X]) noncomputable instance instField [Fact (Irreducible f)] : Field (AdjoinRoot f) where __ := instCommRing _ __ := instGroupWithZero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def q := by rw [← map_natCast (of f), ← map_natCast (of f), ← map_div₀, ← NNRat.cast_def]; rfl ratCast_def q := by rw [← map_natCast (of f), ← map_intCast (of f), ← map_div₀, ← Rat.cast_def]; rfl nnqsmul_def q x := AdjoinRoot.induction_on (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.nnqsmul_eq_C_mul] qsmul_def q x := -- Porting note: I gave the explicit motive and changed `rw` to `simp`. AdjoinRoot.induction_on (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.qsmul_eq_C_mul] theorem coe_injective (h : degree f ≠ 0) : Function.Injective ((↑) : K → AdjoinRoot f) := have := AdjoinRoot.nontrivial f h (of f).injective theorem coe_injective' [Fact (Irreducible f)] : Function.Injective ((↑) : K → AdjoinRoot f) := (of f).injective variable (f) theorem mul_div_root_cancel [Fact (Irreducible f)] : (X - C (root f)) * ((f.map (of f)) / (X - C (root f))) = f.map (of f) := mul_div_eq_iff_isRoot.2 <| isRoot_root _ end Irreducible section IsNoetherianRing instance [CommRing R] [IsNoetherianRing R] {f : R[X]} : IsNoetherianRing (AdjoinRoot f) := Ideal.Quotient.isNoetherianRing _ end IsNoetherianRing section PowerBasis variable [CommRing R] {g : R[X]} theorem isIntegral_root' (hg : g.Monic) : IsIntegral R (root g) := ⟨g, hg, eval₂_root g⟩ /-- `AdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. This is a well-defined right inverse to `AdjoinRoot.mk`, see `AdjoinRoot.mk_leftInverse`. -/ def modByMonicHom (hg : g.Monic) : AdjoinRoot g →ₗ[R] R[X] := (Submodule.liftQ _ (Polynomial.modByMonicHom g) fun f (hf : f ∈ (Ideal.span {g}).restrictScalars R) => (mem_ker_modByMonic hg).mpr (Ideal.mem_span_singleton.mp hf)).comp <| (Submodule.Quotient.restrictScalarsEquiv R (Ideal.span {g} : Ideal R[X])).symm.toLinearMap @[simp] theorem modByMonicHom_mk (hg : g.Monic) (f : R[X]) : modByMonicHom hg (mk g f) = f %ₘ g := rfl -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem mk_leftInverse (hg : g.Monic) : Function.LeftInverse (mk g) (modByMonicHom hg) := by intro f induction f using AdjoinRoot.induction_on rw [modByMonicHom_mk hg, mk_eq_mk, modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel_left, dvd_neg] apply dvd_mul_right theorem mk_surjective : Function.Surjective (mk g) := Ideal.Quotient.mk_surjective /-- The elements `1, root g, ..., root g ^ (d - 1)` form a basis for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ def powerBasisAux' (hg : g.Monic) : Basis (Fin g.natDegree) R (AdjoinRoot g) := Basis.ofEquivFun { toFun := fun f i => (modByMonicHom hg f).coeff i invFun := fun c => mk g <| ∑ i : Fin g.natDegree, monomial i (c i) map_add' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_add, coeff_add, Pi.add_apply] map_smul' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_smul, coeff_smul, Pi.smul_apply, RingHom.id_apply] -- Porting note: another proof that I converted to tactic mode left_inv := by intro f induction f using AdjoinRoot.induction_on simp only [modByMonicHom_mk, sum_modByMonic_coeff hg degree_le_natDegree] refine (mk_eq_mk.mpr ?_).symm rw [modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel] exact dvd_mul_right _ _ right_inv := fun x => funext fun i => by nontriviality R simp only [modByMonicHom_mk] rw [(modByMonic_eq_self_iff hg).mpr, finset_sum_coeff] · simp_rw [coeff_monomial, Fin.val_eq_val, Finset.sum_ite_eq', if_pos (Finset.mem_univ _)] · simp_rw [← C_mul_X_pow_eq_monomial] exact (degree_eq_natDegree <| hg.ne_zero).symm ▸ degree_sum_fin_lt _ } -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. -- This lemma should have the simp tag but this causes a lint issue. theorem powerBasisAux'_repr_symm_apply (hg : g.Monic) (c : Fin g.natDegree →₀ R) : (powerBasisAux' hg).repr.symm c = mk g (∑ i : Fin _, monomial i (c i)) := rfl -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. @[simp] theorem powerBasisAux'_repr_apply_to_fun (hg : g.Monic) (f : AdjoinRoot g) (i : Fin g.natDegree) : (powerBasisAux' hg).repr f i = (modByMonicHom hg f).coeff ↑i := rfl /-- The power basis `1, root g, ..., root g ^ (d - 1)` for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ @[simps] def powerBasis' (hg : g.Monic) : PowerBasis R (AdjoinRoot g) where gen := root g dim := g.natDegree basis := powerBasisAux' hg basis_eq_pow i := by simp only [powerBasisAux', Basis.coe_ofEquivFun, LinearEquiv.coe_symm_mk] rw [Finset.sum_eq_single i] · rw [Function.update_same, monomial_one_right_eq_X_pow, (mk g).map_pow, mk_X] · intro j _ hj rw [← monomial_zero_right _] convert congr_arg _ (Function.update_noteq hj _ _) -- Fix `DecidableEq` mismatch · intros have := Finset.mem_univ i contradiction variable [Field K] {f : K[X]} theorem isIntegral_root (hf : f ≠ 0) : IsIntegral K (root f) := (isAlgebraic_root hf).isIntegral theorem minpoly_root (hf : f ≠ 0) : minpoly K (root f) = f * C f.leadingCoeff⁻¹ := by have f'_monic : Monic _ := monic_mul_leadingCoeff_inv hf refine (minpoly.unique K _ f'_monic ?_ ?_).symm · rw [_root_.map_mul, aeval_eq, mk_self, zero_mul] intro q q_monic q_aeval have commutes : (lift (algebraMap K (AdjoinRoot f)) (root f) q_aeval).comp (mk q) = mk f := by ext · simp only [RingHom.comp_apply, mk_C, lift_of] rfl · simp only [RingHom.comp_apply, mk_X, lift_root] rw [degree_eq_natDegree f'_monic.ne_zero, degree_eq_natDegree q_monic.ne_zero, Nat.cast_le, natDegree_mul hf, natDegree_C, add_zero] · apply natDegree_le_of_dvd · have : mk f q = 0 := by rw [← commutes, RingHom.comp_apply, mk_self, RingHom.map_zero] exact mk_eq_zero.1 this · exact q_monic.ne_zero · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] /-- The elements `1, root f, ..., root f ^ (d - 1)` form a basis for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ def powerBasisAux (hf : f ≠ 0) : Basis (Fin f.natDegree) K (AdjoinRoot f) := by let f' := f * C f.leadingCoeff⁻¹ have deg_f' : f'.natDegree = f.natDegree := by rw [natDegree_mul hf, natDegree_C, add_zero] · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] have minpoly_eq : minpoly K (root f) = f' := minpoly_root hf apply @Basis.mk _ _ _ fun i : Fin f.natDegree => root f ^ i.val · rw [← deg_f', ← minpoly_eq] exact linearIndependent_pow (root f) · rintro y - rw [← deg_f', ← minpoly_eq] apply (isIntegral_root hf).mem_span_pow obtain ⟨g⟩ := y use g rw [aeval_eq] rfl /-- The power basis `1, root f, ..., root f ^ (d - 1)` for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ @[simps!] -- Porting note: was `[simps]` def powerBasis (hf : f ≠ 0) : PowerBasis K (AdjoinRoot f) where gen := root f dim := f.natDegree basis := powerBasisAux hf basis_eq_pow := by simp [powerBasisAux] theorem minpoly_powerBasis_gen (hf : f ≠ 0) : minpoly K (powerBasis hf).gen = f * C f.leadingCoeff⁻¹ := by rw [powerBasis_gen, minpoly_root hf] theorem minpoly_powerBasis_gen_of_monic (hf : f.Monic) (hf' : f ≠ 0 := hf.ne_zero) : minpoly K (powerBasis hf').gen = f := by rw [minpoly_powerBasis_gen hf', hf.leadingCoeff, inv_one, C.map_one, mul_one] end PowerBasis section Equiv section minpoly variable [CommRing R] [CommRing S] [Algebra R S] (x : S) (R) open Algebra Polynomial /-- The surjective algebra morphism `R[X]/(minpoly R x) → R[x]`. If `R` is a integrally closed domain and `x` is integral, this is an isomorphism, see `minpoly.equivAdjoin`. -/ @[simps!] def Minpoly.toAdjoin : AdjoinRoot (minpoly R x) →ₐ[R] adjoin R ({x} : Set S) := liftHom _ ⟨x, self_mem_adjoin_singleton R x⟩ (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) variable {R x} theorem Minpoly.toAdjoin_apply' (a : AdjoinRoot (minpoly R x)) : Minpoly.toAdjoin R x a = liftHom (minpoly R x) (⟨x, self_mem_adjoin_singleton R x⟩ : adjoin R ({x} : Set S)) (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) a := rfl theorem Minpoly.toAdjoin.apply_X : Minpoly.toAdjoin R x (mk (minpoly R x) X) = ⟨x, self_mem_adjoin_singleton R x⟩ := by simp [toAdjoin] variable (R x) theorem Minpoly.toAdjoin.surjective : Function.Surjective (Minpoly.toAdjoin R x) := by rw [← range_top_iff_surjective, _root_.eq_top_iff, ← adjoin_adjoin_coe_preimage] exact adjoin_le fun ⟨y₁, y₂⟩ h ↦ ⟨mk (minpoly R x) X, by simpa [toAdjoin] using h.symm⟩ end minpoly section Equiv' variable [CommRing R] [CommRing S] [Algebra R S] variable (g : R[X]) (pb : PowerBasis R S) /-- If `S` is an extension of `R` with power basis `pb` and `g` is a monic polynomial over `R` such that `pb.gen` has a minimal polynomial `g`, then `S` is isomorphic to `AdjoinRoot g`. Compare `PowerBasis.equivOfRoot`, which would require `h₂ : aeval pb.gen (minpoly R (root g)) = 0`; that minimal polynomial is not guaranteed to be identical to `g`. -/ @[simps (config := .asFn)] def equiv' (h₁ : aeval (root g) (minpoly R pb.gen) = 0) (h₂ : aeval pb.gen g = 0) : AdjoinRoot g ≃ₐ[R] S := { AdjoinRoot.liftHom g pb.gen h₂ with toFun := AdjoinRoot.liftHom g pb.gen h₂ invFun := pb.lift (root g) h₁ -- Porting note: another term-mode proof converted to tactic-mode. left_inv := fun x => by induction x using AdjoinRoot.induction_on rw [liftHom_mk, pb.lift_aeval, aeval_eq] right_inv := fun x => by nontriviality S obtain ⟨f, _hf, rfl⟩ := pb.exists_eq_aeval x rw [pb.lift_aeval, aeval_eq, liftHom_mk] } -- This lemma should have the simp tag but this causes a lint issue. theorem equiv'_toAlgHom (h₁ : aeval (root g) (minpoly R pb.gen) = 0) (h₂ : aeval pb.gen g = 0) : (equiv' g pb h₁ h₂).toAlgHom = AdjoinRoot.liftHom g pb.gen h₂ := rfl -- This lemma should have the simp tag but this causes a lint issue. theorem equiv'_symm_toAlgHom (h₁ : aeval (root g) (minpoly R pb.gen) = 0) (h₂ : aeval pb.gen g = 0) : (equiv' g pb h₁ h₂).symm.toAlgHom = pb.lift (root g) h₁ := rfl end Equiv' section Field variable (L F : Type*) [Field F] [CommRing L] [IsDomain L] [Algebra F L] /-- If `L` is a field extension of `F` and `f` is a polynomial over `F` then the set of maps from `F[x]/(f)` into `L` is in bijection with the set of roots of `f` in `L`. -/ def equiv (f : F[X]) (hf : f ≠ 0) : (AdjoinRoot f →ₐ[F] L) ≃ { x // x ∈ f.aroots L } := (powerBasis hf).liftEquiv'.trans ((Equiv.refl _).subtypeEquiv fun x => by rw [powerBasis_gen, minpoly_root hf, aroots_mul, aroots_C, add_zero, Equiv.refl_apply] exact (monic_mul_leadingCoeff_inv hf).ne_zero) end Field end Equiv -- Porting note: consider splitting the file here. In the current mathlib3, the only result -- that depends any of these lemmas was -- `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` in `NumberTheory.KummerDedekind` -- that uses -- `PowerBasis.quotientEquivQuotientMinpolyMap == PowerBasis.quotientEquivQuotientMinpolyMap` section open Ideal DoubleQuot Polynomial variable [CommRing R] (I : Ideal R) (f : R[X]) /-- The natural isomorphism `R[α]/(I[α]) ≅ R[α]/((I[x] ⊔ (f)) / (f))` for `α` a root of `f : R[X]` and `I : Ideal R`. See `adjoin_root.quot_map_of_equiv` for the isomorphism with `(R/I)[X] / (f mod I)`. -/ def quotMapOfEquivQuotMapCMapSpanMk : AdjoinRoot f ⧸ I.map (of f) ≃+* AdjoinRoot f ⧸ (I.map (C : R →+* R[X])).map (Ideal.Quotient.mk (span {f})) := Ideal.quotEquivOfEq (by rw [of, AdjoinRoot.mk, Ideal.map_map]) @[simp] theorem quotMapOfEquivQuotMapCMapSpanMk_mk (x : AdjoinRoot f) : quotMapOfEquivQuotMapCMapSpanMk I f (Ideal.Quotient.mk (I.map (of f)) x) = Ideal.Quotient.mk (Ideal.map (Ideal.Quotient.mk (span {f})) (I.map (C : R →+* R[X]))) x := rfl --this lemma should have the simp tag but this causes a lint issue theorem quotMapOfEquivQuotMapCMapSpanMk_symm_mk (x : AdjoinRoot f) : (quotMapOfEquivQuotMapCMapSpanMk I f).symm (Ideal.Quotient.mk ((I.map (C : R →+* R[X])).map (Ideal.Quotient.mk (span {f}))) x) = Ideal.Quotient.mk (I.map (of f)) x := by rw [quotMapOfEquivQuotMapCMapSpanMk, Ideal.quotEquivOfEq_symm] exact Ideal.quotEquivOfEq_mk _ _ /-- The natural isomorphism `R[α]/((I[x] ⊔ (f)) / (f)) ≅ (R[x]/I[x])/((f) ⊔ I[x] / I[x])` for `α` a root of `f : R[X]` and `I : Ideal R`-/ def quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk : AdjoinRoot f ⧸ (I.map (C : R →+* R[X])).map (Ideal.Quotient.mk (span ({f} : Set R[X]))) ≃+* (R[X] ⧸ I.map (C : R →+* R[X])) ⧸ (span ({f} : Set R[X])).map (Ideal.Quotient.mk (I.map (C : R →+* R[X]))) := quotQuotEquivComm (Ideal.span ({f} : Set R[X])) (I.map (C : R →+* R[X])) -- This lemma should have the simp tag but this causes a lint issue. theorem quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_mk (p : R[X]) : quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk I f (Ideal.Quotient.mk _ (mk f p)) = quotQuotMk (I.map C) (span {f}) p := rfl @[simp] theorem quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_symm_quotQuotMk (p : R[X]) : (quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk I f).symm (quotQuotMk (I.map C) (span {f}) p) = Ideal.Quotient.mk (Ideal.map (Ideal.Quotient.mk (span {f})) (I.map (C : R →+* R[X]))) (mk f p) := rfl /-- The natural isomorphism `(R/I)[x]/(f mod I) ≅ (R[x]/I*R[x])/(f mod I[x])` where `f : R[X]` and `I : Ideal R`-/ def Polynomial.quotQuotEquivComm : (R ⧸ I)[X] ⧸ span ({f.map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I))) ≃+* (R[X] ⧸ (I.map C)) ⧸ span ({(Ideal.Quotient.mk (I.map C)) f} : Set (R[X] ⧸ (I.map C))) := quotientEquiv (span ({f.map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I)))) (span {Ideal.Quotient.mk (I.map Polynomial.C) f}) (polynomialQuotientEquivQuotientPolynomial I) (by rw [map_span, Set.image_singleton, RingEquiv.coe_toRingHom, polynomialQuotientEquivQuotientPolynomial_map_mk I f]) @[simp] theorem Polynomial.quotQuotEquivComm_mk (p : R[X]) : (Polynomial.quotQuotEquivComm I f) (Ideal.Quotient.mk _ (p.map (Ideal.Quotient.mk I))) = Ideal.Quotient.mk (span ({(Ideal.Quotient.mk (I.map C)) f} : Set (R[X] ⧸ (I.map C)))) (Ideal.Quotient.mk (I.map C) p) := by simp only [Polynomial.quotQuotEquivComm, quotientEquiv_mk, polynomialQuotientEquivQuotientPolynomial_map_mk] @[simp] theorem Polynomial.quotQuotEquivComm_symm_mk_mk (p : R[X]) : (Polynomial.quotQuotEquivComm I f).symm (Ideal.Quotient.mk (span ({(Ideal.Quotient.mk (I.map C)) f} : Set (R[X] ⧸ (I.map C)))) (Ideal.Quotient.mk (I.map C) p)) = Ideal.Quotient.mk (span {f.map (Ideal.Quotient.mk I)}) (p.map (Ideal.Quotient.mk I)) := by simp only [Polynomial.quotQuotEquivComm, quotientEquiv_symm_mk, polynomialQuotientEquivQuotientPolynomial_symm_mk] /-- The natural isomorphism `R[α]/I[α] ≅ (R/I)[X]/(f mod I)` for `α` a root of `f : R[X]` and `I : Ideal R`. -/ def quotAdjoinRootEquivQuotPolynomialQuot : AdjoinRoot f ⧸ I.map (of f) ≃+* (R ⧸ I)[X] ⧸ span ({f.map (Ideal.Quotient.mk I)} : Set (R ⧸ I)[X]) := (quotMapOfEquivQuotMapCMapSpanMk I f).trans ((quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk I f).trans ((Ideal.quotEquivOfEq (by rw [map_span, Set.image_singleton])).trans (Polynomial.quotQuotEquivComm I f).symm)) -- Porting note: mathlib3 proof was a long `rw` that timeouts. @[simp] theorem quotAdjoinRootEquivQuotPolynomialQuot_mk_of (p : R[X]) : quotAdjoinRootEquivQuotPolynomialQuot I f (Ideal.Quotient.mk (I.map (of f)) (mk f p)) = Ideal.Quotient.mk (span ({f.map (Ideal.Quotient.mk I)} : Set (R ⧸ I)[X])) (p.map (Ideal.Quotient.mk I)) := rfl @[simp] theorem quotAdjoinRootEquivQuotPolynomialQuot_symm_mk_mk (p : R[X]) : (quotAdjoinRootEquivQuotPolynomialQuot I f).symm (Ideal.Quotient.mk (span ({f.map (Ideal.Quotient.mk I)} : Set (R ⧸ I)[X])) (p.map (Ideal.Quotient.mk I))) = Ideal.Quotient.mk (I.map (of f)) (mk f p) := by rw [quotAdjoinRootEquivQuotPolynomialQuot, RingEquiv.symm_trans_apply, RingEquiv.symm_trans_apply, RingEquiv.symm_trans_apply, RingEquiv.symm_symm, Polynomial.quotQuotEquivComm_mk, Ideal.quotEquivOfEq_symm, Ideal.quotEquivOfEq_mk, ← RingHom.comp_apply, ← DoubleQuot.quotQuotMk, quotMapCMapSpanMkEquivQuotMapCQuotMapSpanMk_symm_quotQuotMk, quotMapOfEquivQuotMapCMapSpanMk_symm_mk] /-- Promote `AdjoinRoot.quotAdjoinRootEquivQuotPolynomialQuot` to an alg_equiv. -/ @[simps!] noncomputable def quotEquivQuotMap (f : R[X]) (I : Ideal R) : (AdjoinRoot f ⧸ Ideal.map (of f) I) ≃ₐ[R] (R ⧸ I)[X] ⧸ Ideal.span ({Polynomial.map (Ideal.Quotient.mk I) f} : Set (R ⧸ I)[X]) := AlgEquiv.ofRingEquiv (show ∀ x, (quotAdjoinRootEquivQuotPolynomialQuot I f) (algebraMap R _ x) = algebraMap R _ x from fun x => by have : algebraMap R (AdjoinRoot f ⧸ Ideal.map (of f) I) x = Ideal.Quotient.mk (Ideal.map (AdjoinRoot.of f) I) ((mk f) (C x)) := rfl rw [this, quotAdjoinRootEquivQuotPolynomialQuot_mk_of, map_C] -- Porting note: the following `rfl` was not needed rfl) @[simp] theorem quotEquivQuotMap_apply_mk (f g : R[X]) (I : Ideal R) : AdjoinRoot.quotEquivQuotMap f I (Ideal.Quotient.mk (Ideal.map (of f) I) (AdjoinRoot.mk f g)) = Ideal.Quotient.mk (Ideal.span ({Polynomial.map (Ideal.Quotient.mk I) f} : Set (R ⧸ I)[X])) (g.map (Ideal.Quotient.mk I)) := by rw [AdjoinRoot.quotEquivQuotMap_apply, AdjoinRoot.quotAdjoinRootEquivQuotPolynomialQuot_mk_of] theorem quotEquivQuotMap_symm_apply_mk (f g : R[X]) (I : Ideal R) : (AdjoinRoot.quotEquivQuotMap f I).symm (Ideal.Quotient.mk _ (Polynomial.map (Ideal.Quotient.mk I) g)) = Ideal.Quotient.mk (Ideal.map (of f) I) (AdjoinRoot.mk f g) := by rw [AdjoinRoot.quotEquivQuotMap_symm_apply, AdjoinRoot.quotAdjoinRootEquivQuotPolynomialQuot_symm_mk_mk] end end AdjoinRoot namespace PowerBasis open AdjoinRoot AlgEquiv variable [CommRing R] [CommRing S] [Algebra R S] /-- Let `α` have minimal polynomial `f` over `R` and `I` be an ideal of `R`, then `R[α] / (I) = (R[x] / (f)) / pS = (R/p)[x] / (f mod p)`. -/ @[simps!] noncomputable def quotientEquivQuotientMinpolyMap (pb : PowerBasis R S) (I : Ideal R) : (S ⧸ I.map (algebraMap R S)) ≃ₐ[R] Polynomial (R ⧸ I) ⧸ Ideal.span ({(minpoly R pb.gen).map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I))) := (ofRingEquiv (show ∀ x, (Ideal.quotientEquiv _ (Ideal.map (AdjoinRoot.of (minpoly R pb.gen)) I) (AdjoinRoot.equiv' (minpoly R pb.gen) pb (by rw [AdjoinRoot.aeval_eq, AdjoinRoot.mk_self]) (minpoly.aeval _ _)).symm.toRingEquiv (by rw [Ideal.map_map, AlgEquiv.toRingEquiv_eq_coe, ← AlgEquiv.coe_ringHom_commutes, ← AdjoinRoot.algebraMap_eq, AlgHom.comp_algebraMap])) (algebraMap R (S ⧸ I.map (algebraMap R S)) x) = algebraMap R _ x from fun x => by rw [← Ideal.Quotient.mk_algebraMap, Ideal.quotientEquiv_apply, RingHom.toFun_eq_coe, Ideal.quotientMap_mk, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.coe_toRingHom, AlgEquiv.coe_ringEquiv, AlgEquiv.commutes, Quotient.mk_algebraMap])).trans (AdjoinRoot.quotEquivQuotMap _ _) -- This lemma should have the simp tag but this causes a lint issue. theorem quotientEquivQuotientMinpolyMap_apply_mk (pb : PowerBasis R S) (I : Ideal R) (g : R[X]) : pb.quotientEquivQuotientMinpolyMap I (Ideal.Quotient.mk (I.map (algebraMap R S)) (aeval pb.gen g)) = Ideal.Quotient.mk (Ideal.span ({(minpoly R pb.gen).map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I)))) (g.map (Ideal.Quotient.mk I)) := by rw [PowerBasis.quotientEquivQuotientMinpolyMap, AlgEquiv.trans_apply, AlgEquiv.ofRingEquiv_apply, quotientEquiv_mk, AlgEquiv.coe_ringEquiv', AdjoinRoot.equiv'_symm_apply, PowerBasis.lift_aeval, AdjoinRoot.aeval_eq, AdjoinRoot.quotEquivQuotMap_apply_mk] -- This lemma should have the simp tag but this causes a lint issue. theorem quotientEquivQuotientMinpolyMap_symm_apply_mk (pb : PowerBasis R S) (I : Ideal R) (g : R[X]) : (pb.quotientEquivQuotientMinpolyMap I).symm (Ideal.Quotient.mk (Ideal.span ({(minpoly R pb.gen).map (Ideal.Quotient.mk I)} : Set (Polynomial (R ⧸ I)))) (g.map (Ideal.Quotient.mk I))) = Ideal.Quotient.mk (I.map (algebraMap R S)) (aeval pb.gen g) := by simp only [quotientEquivQuotientMinpolyMap, toRingEquiv_eq_coe, symm_trans_apply, quotEquivQuotMap_symm_apply_mk, ofRingEquiv_symm_apply, quotientEquiv_symm_mk, toRingEquiv_symm, RingEquiv.symm_symm, AdjoinRoot.equiv'_apply, coe_ringEquiv, liftHom_mk, symm_toRingEquiv] end PowerBasis /-- If `L / K` is an integral extension, `K` is a domain, `L` is a field, then any irreducible polynomial over `L` divides some monic irreducible polynomial over `K`. -/ theorem Irreducible.exists_dvd_monic_irreducible_of_isIntegral {K L : Type*} [CommRing K] [IsDomain K] [Field L] [Algebra K L] [Algebra.IsIntegral K L] {f : L[X]} (hf : Irreducible f) : ∃ g : K[X], g.Monic ∧ Irreducible g ∧ f ∣ g.map (algebraMap K L) := by haveI := Fact.mk hf have h := hf.ne_zero have h2 := isIntegral_trans (R := K) _ (AdjoinRoot.isIntegral_root h) have h3 := (AdjoinRoot.minpoly_root h) ▸ minpoly.dvd_map_of_isScalarTower K L (AdjoinRoot.root f) exact ⟨_, minpoly.monic h2, minpoly.irreducible h2, dvd_of_mul_right_dvd h3⟩
RingTheory\Algebraic.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.RingTheory.IntegralClosure.IsIntegralClosure.Basic import Mathlib.RingTheory.Polynomial.IntegralNormalization /-! # Algebraic elements and algebraic extensions An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial. An R-algebra is algebraic over R if and only if all its elements are algebraic over R. The main result in this file proves transitivity of algebraicity: a tower of algebraic field extensions is algebraic. -/ universe u v w open scoped Classical open Polynomial section variable (R : Type u) {A : Type v} [CommRing R] [Ring A] [Algebra R A] /-- An element of an R-algebra is algebraic over R if it is a root of a nonzero polynomial with coefficients in R. -/ def IsAlgebraic (x : A) : Prop := ∃ p : R[X], p ≠ 0 ∧ aeval x p = 0 /-- An element of an R-algebra is transcendental over R if it is not algebraic over R. -/ def Transcendental (x : A) : Prop := ¬IsAlgebraic R x theorem is_transcendental_of_subsingleton [Subsingleton R] (x : A) : Transcendental R x := fun ⟨p, h, _⟩ => h <| Subsingleton.elim p 0 variable {R} /-- A subalgebra is algebraic if all its elements are algebraic. -/ nonrec def Subalgebra.IsAlgebraic (S : Subalgebra R A) : Prop := ∀ x ∈ S, IsAlgebraic R x variable (R A) /-- An algebra is algebraic if all its elements are algebraic. -/ protected class Algebra.IsAlgebraic : Prop := isAlgebraic : ∀ x : A, IsAlgebraic R x /-- An algebra is transcendental if some element is transcendental. -/ protected class Algebra.Transcendental : Prop := transcendental : ∃ x : A, Transcendental R x variable {R A} lemma Algebra.isAlgebraic_def : Algebra.IsAlgebraic R A ↔ ∀ x : A, IsAlgebraic R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ lemma Algebra.transcendental_def : Algebra.Transcendental R A ↔ ∃ x : A, Transcendental R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ theorem Algebra.transcendental_iff_not_isAlgebraic : Algebra.Transcendental R A ↔ ¬ Algebra.IsAlgebraic R A := by simp [isAlgebraic_def, transcendental_def, Transcendental] /-- A subalgebra is algebraic if and only if it is algebraic as an algebra. -/ theorem Subalgebra.isAlgebraic_iff (S : Subalgebra R A) : S.IsAlgebraic ↔ @Algebra.IsAlgebraic R S _ _ S.algebra := by delta Subalgebra.IsAlgebraic rw [Subtype.forall', Algebra.isAlgebraic_def] refine forall_congr' fun x => exists_congr fun p => and_congr Iff.rfl ?_ have h : Function.Injective S.val := Subtype.val_injective conv_rhs => rw [← h.eq_iff, map_zero] rw [← aeval_algHom_apply, S.val_apply] /-- An algebra is algebraic if and only if it is algebraic as a subalgebra. -/ theorem Algebra.isAlgebraic_iff : Algebra.IsAlgebraic R A ↔ (⊤ : Subalgebra R A).IsAlgebraic := by delta Subalgebra.IsAlgebraic simp only [Algebra.isAlgebraic_def, Algebra.mem_top, forall_prop_of_true, iff_self_iff] theorem isAlgebraic_iff_not_injective {x : A} : IsAlgebraic R x ↔ ¬Function.Injective (Polynomial.aeval x : R[X] →ₐ[R] A) := by simp only [IsAlgebraic, injective_iff_map_eq_zero, not_forall, and_comm, exists_prop] theorem transcendental_iff_injective {x : A} : Transcendental R x ↔ Function.Injective (Polynomial.aeval x : R[X] →ₐ[R] A) := isAlgebraic_iff_not_injective.not_left end section zero_ne_one variable {R : Type u} {S : Type*} {A : Type v} [CommRing R] variable [CommRing S] [Ring A] [Algebra R A] [Algebra R S] [Algebra S A] variable [IsScalarTower R S A] /-- An integral element of an algebra is algebraic. -/ theorem IsIntegral.isAlgebraic [Nontrivial R] {x : A} : IsIntegral R x → IsAlgebraic R x := fun ⟨p, hp, hpx⟩ => ⟨p, hp.ne_zero, hpx⟩ instance Algebra.IsIntegral.isAlgebraic [Nontrivial R] [Algebra.IsIntegral R A] : Algebra.IsAlgebraic R A := ⟨fun a ↦ (Algebra.IsIntegral.isIntegral a).isAlgebraic⟩ theorem isAlgebraic_zero [Nontrivial R] : IsAlgebraic R (0 : A) := ⟨_, X_ne_zero, aeval_X 0⟩ /-- An element of `R` is algebraic, when viewed as an element of the `R`-algebra `A`. -/ theorem isAlgebraic_algebraMap [Nontrivial R] (x : R) : IsAlgebraic R (algebraMap R A x) := ⟨_, X_sub_C_ne_zero x, by rw [_root_.map_sub, aeval_X, aeval_C, sub_self]⟩ theorem isAlgebraic_one [Nontrivial R] : IsAlgebraic R (1 : A) := by rw [← _root_.map_one (algebraMap R A)] exact isAlgebraic_algebraMap 1 theorem isAlgebraic_nat [Nontrivial R] (n : ℕ) : IsAlgebraic R (n : A) := by rw [← map_natCast (_ : R →+* A) n] exact isAlgebraic_algebraMap (Nat.cast n) theorem isAlgebraic_int [Nontrivial R] (n : ℤ) : IsAlgebraic R (n : A) := by rw [← _root_.map_intCast (algebraMap R A)] exact isAlgebraic_algebraMap (Int.cast n) theorem isAlgebraic_rat (R : Type u) {A : Type v} [DivisionRing A] [Field R] [Algebra R A] (n : ℚ) : IsAlgebraic R (n : A) := by rw [← map_ratCast (algebraMap R A)] exact isAlgebraic_algebraMap (Rat.cast n) theorem isAlgebraic_of_mem_rootSet {R : Type u} {A : Type v} [Field R] [Field A] [Algebra R A] {p : R[X]} {x : A} (hx : x ∈ p.rootSet A) : IsAlgebraic R x := ⟨p, ne_zero_of_mem_rootSet hx, aeval_eq_zero_of_mem_rootSet hx⟩ open IsScalarTower protected theorem IsAlgebraic.algebraMap {a : S} : IsAlgebraic R a → IsAlgebraic R (algebraMap S A a) := fun ⟨f, hf₁, hf₂⟩ => ⟨f, hf₁, by rw [aeval_algebraMap_apply, hf₂, map_zero]⟩ section variable {B} [Ring B] [Algebra R B] /-- This is slightly more general than `IsAlgebraic.algebraMap` in that it allows noncommutative intermediate rings `A`. -/ protected theorem IsAlgebraic.algHom (f : A →ₐ[R] B) {a : A} (h : IsAlgebraic R a) : IsAlgebraic R (f a) := let ⟨p, hp, ha⟩ := h ⟨p, hp, by rw [aeval_algHom, f.comp_apply, ha, map_zero]⟩ theorem isAlgebraic_algHom_iff (f : A →ₐ[R] B) (hf : Function.Injective f) {a : A} : IsAlgebraic R (f a) ↔ IsAlgebraic R a := ⟨fun ⟨p, hp0, hp⟩ ↦ ⟨p, hp0, hf <| by rwa [map_zero, ← f.comp_apply, ← aeval_algHom]⟩, IsAlgebraic.algHom f⟩ theorem Algebra.IsAlgebraic.of_injective (f : A →ₐ[R] B) (hf : Function.Injective f) [Algebra.IsAlgebraic R B] : Algebra.IsAlgebraic R A := ⟨fun _ ↦ (isAlgebraic_algHom_iff f hf).mp (Algebra.IsAlgebraic.isAlgebraic _)⟩ /-- Transfer `Algebra.IsAlgebraic` across an `AlgEquiv`. -/ theorem AlgEquiv.isAlgebraic (e : A ≃ₐ[R] B) [Algebra.IsAlgebraic R A] : Algebra.IsAlgebraic R B := Algebra.IsAlgebraic.of_injective e.symm.toAlgHom e.symm.injective theorem AlgEquiv.isAlgebraic_iff (e : A ≃ₐ[R] B) : Algebra.IsAlgebraic R A ↔ Algebra.IsAlgebraic R B := ⟨fun _ ↦ e.isAlgebraic, fun _ ↦ e.symm.isAlgebraic⟩ end theorem isAlgebraic_algebraMap_iff {a : S} (h : Function.Injective (algebraMap S A)) : IsAlgebraic R (algebraMap S A a) ↔ IsAlgebraic R a := isAlgebraic_algHom_iff (IsScalarTower.toAlgHom R S A) h theorem IsAlgebraic.of_pow {r : A} {n : ℕ} (hn : 0 < n) (ht : IsAlgebraic R (r ^ n)) : IsAlgebraic R r := by obtain ⟨p, p_nonzero, hp⟩ := ht refine ⟨Polynomial.expand _ n p, ?_, ?_⟩ · rwa [Polynomial.expand_ne_zero hn] · rwa [Polynomial.expand_aeval n p r] theorem Transcendental.pow {r : A} (ht : Transcendental R r) {n : ℕ} (hn : 0 < n) : Transcendental R (r ^ n) := fun ht' ↦ ht <| ht'.of_pow hn lemma IsAlgebraic.invOf {x : S} [Invertible x] (h : IsAlgebraic R x) : IsAlgebraic R (⅟ x) := by obtain ⟨p, hp, hp'⟩ := h refine ⟨p.reverse, by simpa using hp, ?_⟩ rwa [Polynomial.aeval_def, Polynomial.eval₂_reverse_eq_zero_iff, ← Polynomial.aeval_def] lemma IsAlgebraic.invOf_iff {x : S} [Invertible x] : IsAlgebraic R (⅟ x) ↔ IsAlgebraic R x := ⟨IsAlgebraic.invOf, IsAlgebraic.invOf⟩ lemma IsAlgebraic.inv_iff {K} [Field K] [Algebra R K] {x : K} : IsAlgebraic R (x⁻¹) ↔ IsAlgebraic R x := by by_cases hx : x = 0 · simp [hx] letI := invertibleOfNonzero hx exact IsAlgebraic.invOf_iff (R := R) (x := x) alias ⟨_, IsAlgebraic.inv⟩ := IsAlgebraic.inv_iff end zero_ne_one section Field variable {K : Type u} {A : Type v} [Field K] [Ring A] [Algebra K A] /-- An element of an algebra over a field is algebraic if and only if it is integral. -/ theorem isAlgebraic_iff_isIntegral {x : A} : IsAlgebraic K x ↔ IsIntegral K x := by refine ⟨?_, IsIntegral.isAlgebraic⟩ rintro ⟨p, hp, hpx⟩ refine ⟨_, monic_mul_leadingCoeff_inv hp, ?_⟩ rw [← aeval_def, map_mul, hpx, zero_mul] protected theorem Algebra.isAlgebraic_iff_isIntegral : Algebra.IsAlgebraic K A ↔ Algebra.IsIntegral K A := by rw [Algebra.isAlgebraic_def, Algebra.isIntegral_def, forall_congr' fun _ ↦ isAlgebraic_iff_isIntegral] alias ⟨IsAlgebraic.isIntegral, _⟩ := isAlgebraic_iff_isIntegral /-- This used to be an `alias` of `Algebra.isAlgebraic_iff_isIntegral` but that would make `Algebra.IsAlgebraic K A` an explicit parameter instead of instance implicit. -/ protected instance Algebra.IsAlgebraic.isIntegral [Algebra.IsAlgebraic K A] : Algebra.IsIntegral K A := Algebra.isAlgebraic_iff_isIntegral.mp ‹_› end Field section variable {K L R S A : Type*} section Ring section CommRing variable [CommRing R] [CommRing S] [Ring A] variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A] /-- If x is algebraic over R, then x is algebraic over S when S is an extension of R, and the map from `R` to `S` is injective. -/ theorem IsAlgebraic.tower_top_of_injective (hinj : Function.Injective (algebraMap R S)) {x : A} (A_alg : IsAlgebraic R x) : IsAlgebraic S x := let ⟨p, hp₁, hp₂⟩ := A_alg ⟨p.map (algebraMap _ _), by rwa [Ne, ← degree_eq_bot, degree_map_eq_of_injective hinj, degree_eq_bot], by simpa⟩ /-- If A is an algebraic algebra over R, then A is algebraic over S when S is an extension of R, and the map from `R` to `S` is injective. -/ theorem Algebra.IsAlgebraic.tower_top_of_injective (hinj : Function.Injective (algebraMap R S)) [Algebra.IsAlgebraic R A] : Algebra.IsAlgebraic S A := ⟨fun _ ↦ _root_.IsAlgebraic.tower_top_of_injective hinj (Algebra.IsAlgebraic.isAlgebraic _)⟩ end CommRing section Field variable [Field K] [Field L] [Ring A] variable [Algebra K L] [Algebra L A] [Algebra K A] [IsScalarTower K L A] variable (L) /-- If x is algebraic over K, then x is algebraic over L when L is an extension of K -/ theorem IsAlgebraic.tower_top {x : A} (A_alg : IsAlgebraic K x) : IsAlgebraic L x := A_alg.tower_top_of_injective (algebraMap K L).injective /-- If A is an algebraic algebra over K, then A is algebraic over L when L is an extension of K -/ theorem Algebra.IsAlgebraic.tower_top [Algebra.IsAlgebraic K A] : Algebra.IsAlgebraic L A := Algebra.IsAlgebraic.tower_top_of_injective (algebraMap K L).injective variable (K) theorem IsAlgebraic.of_finite (e : A) [FiniteDimensional K A] : IsAlgebraic K e := (IsIntegral.of_finite K e).isAlgebraic variable (A) /-- A field extension is algebraic if it is finite. -/ instance Algebra.IsAlgebraic.of_finite [FiniteDimensional K A] : Algebra.IsAlgebraic K A := (IsIntegral.of_finite K A).isAlgebraic end Field end Ring section CommRing variable [Field K] [Field L] [Ring A] variable [Algebra K L] [Algebra L A] [Algebra K A] [IsScalarTower K L A] /-- If L is an algebraic field extension of K and A is an algebraic algebra over L, then A is algebraic over K. -/ protected theorem Algebra.IsAlgebraic.trans [L_alg : Algebra.IsAlgebraic K L] [A_alg : Algebra.IsAlgebraic L A] : Algebra.IsAlgebraic K A := by rw [Algebra.isAlgebraic_iff_isIntegral] at L_alg A_alg ⊢ exact Algebra.IsIntegral.trans L end CommRing section NoZeroSMulDivisors namespace Algebra.IsAlgebraic variable [CommRing K] [Field L] variable [Algebra K L] [NoZeroSMulDivisors K L] theorem algHom_bijective [Algebra.IsAlgebraic K L] (f : L →ₐ[K] L) : Function.Bijective f := by refine ⟨f.injective, fun b ↦ ?_⟩ obtain ⟨p, hp, he⟩ := Algebra.IsAlgebraic.isAlgebraic (R := K) b let f' : p.rootSet L → p.rootSet L := (rootSet_maps_to' (fun x ↦ x) f).restrict f _ _ have : f'.Surjective := Finite.injective_iff_surjective.1 fun _ _ h ↦ Subtype.eq <| f.injective <| Subtype.ext_iff.1 h obtain ⟨a, ha⟩ := this ⟨b, mem_rootSet.2 ⟨hp, he⟩⟩ exact ⟨a, Subtype.ext_iff.1 ha⟩ theorem algHom_bijective₂ [Field R] [Algebra K R] [Algebra.IsAlgebraic K L] (f : L →ₐ[K] R) (g : R →ₐ[K] L) : Function.Bijective f ∧ Function.Bijective g := (g.injective.bijective₂_of_surjective f.injective (algHom_bijective <| g.comp f).2).symm theorem bijective_of_isScalarTower [Algebra.IsAlgebraic K L] [Field R] [Algebra K R] [Algebra L R] [IsScalarTower K L R] (f : R →ₐ[K] L) : Function.Bijective f := (algHom_bijective₂ (IsScalarTower.toAlgHom K L R) f).2 theorem bijective_of_isScalarTower' [Field R] [Algebra K R] [NoZeroSMulDivisors K R] [Algebra.IsAlgebraic K R] [Algebra L R] [IsScalarTower K L R] (f : R →ₐ[K] L) : Function.Bijective f := (algHom_bijective₂ f (IsScalarTower.toAlgHom K L R)).1 variable (K L) /-- Bijection between algebra equivalences and algebra homomorphisms -/ @[simps] noncomputable def algEquivEquivAlgHom [Algebra.IsAlgebraic K L] : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) where toFun ϕ := ϕ.toAlgHom invFun ϕ := AlgEquiv.ofBijective ϕ (algHom_bijective ϕ) left_inv _ := by ext; rfl right_inv _ := by ext; rfl map_mul' _ _ := rfl end Algebra.IsAlgebraic end NoZeroSMulDivisors section Field variable [Field K] [Field L] variable [Algebra K L] theorem AlgHom.bijective [FiniteDimensional K L] (ϕ : L →ₐ[K] L) : Function.Bijective ϕ := (Algebra.IsAlgebraic.of_finite K L).algHom_bijective ϕ variable (K L) /-- Bijection between algebra equivalences and algebra homomorphisms -/ noncomputable abbrev algEquivEquivAlgHom [FiniteDimensional K L] : (L ≃ₐ[K] L) ≃* (L →ₐ[K] L) := Algebra.IsAlgebraic.algEquivEquivAlgHom K L end Field end variable {R S : Type*} [CommRing R] [IsDomain R] [CommRing S] theorem exists_integral_multiple [Algebra R S] {z : S} (hz : IsAlgebraic R z) (inj : ∀ x, algebraMap R S x = 0 → x = 0) : ∃ᵉ (x : integralClosure R S) (y ≠ (0 : R)), z * algebraMap R S y = x := by rcases hz with ⟨p, p_ne_zero, px⟩ set a := p.leadingCoeff have a_ne_zero : a ≠ 0 := mt Polynomial.leadingCoeff_eq_zero.mp p_ne_zero have x_integral : IsIntegral R (z * algebraMap R S a) := ⟨p.integralNormalization, monic_integralNormalization p_ne_zero, integralNormalization_aeval_eq_zero px inj⟩ exact ⟨⟨_, x_integral⟩, a, a_ne_zero, rfl⟩ /-- A fraction `(a : S) / (b : S)` can be reduced to `(c : S) / (d : R)`, if `S` is the integral closure of `R` in an algebraic extension `L` of `R`. -/ theorem IsIntegralClosure.exists_smul_eq_mul {L : Type*} [Field L] [Algebra R S] [Algebra S L] [Algebra R L] [IsScalarTower R S L] [IsIntegralClosure S R L] [Algebra.IsAlgebraic R L] (inj : Function.Injective (algebraMap R L)) (a : S) {b : S} (hb : b ≠ 0) : ∃ᵉ (c : S) (d ≠ (0 : R)), d • a = b * c := by obtain ⟨c, d, d_ne, hx⟩ := exists_integral_multiple (Algebra.IsAlgebraic.isAlgebraic (algebraMap _ L a / algebraMap _ L b)) ((injective_iff_map_eq_zero _).mp inj) refine ⟨IsIntegralClosure.mk' S (c : L) c.2, d, d_ne, IsIntegralClosure.algebraMap_injective S R L ?_⟩ simp only [Algebra.smul_def, RingHom.map_mul, IsIntegralClosure.algebraMap_mk', ← hx, ← IsScalarTower.algebraMap_apply] rw [← mul_assoc _ (_ / _), mul_div_cancel₀ (algebraMap S L a), mul_comm] exact mt ((injective_iff_map_eq_zero _).mp (IsIntegralClosure.algebraMap_injective S R L) _) hb section Field variable {K L : Type*} [Field K] [Field L] [Algebra K L] (A : Subalgebra K L) theorem inv_eq_of_aeval_divX_ne_zero {x : L} {p : K[X]} (aeval_ne : aeval x (divX p) ≠ 0) : x⁻¹ = aeval x (divX p) / (aeval x p - algebraMap _ _ (p.coeff 0)) := by rw [inv_eq_iff_eq_inv, inv_div, eq_comm, div_eq_iff, sub_eq_iff_eq_add, mul_comm] conv_lhs => rw [← divX_mul_X_add p] · rw [map_add, map_mul, aeval_X, aeval_C] · exact aeval_ne theorem inv_eq_of_root_of_coeff_zero_ne_zero {x : L} {p : K[X]} (aeval_eq : aeval x p = 0) (coeff_zero_ne : p.coeff 0 ≠ 0) : x⁻¹ = -(aeval x (divX p) / algebraMap _ _ (p.coeff 0)) := by convert inv_eq_of_aeval_divX_ne_zero (p := p) (L := L) (mt (fun h => (algebraMap K L).injective ?_) coeff_zero_ne) using 1 · rw [aeval_eq, zero_sub, div_neg] rw [RingHom.map_zero] convert aeval_eq conv_rhs => rw [← divX_mul_X_add p] rw [map_add, map_mul, h, zero_mul, zero_add, aeval_C] theorem Subalgebra.inv_mem_of_root_of_coeff_zero_ne_zero {x : A} {p : K[X]} (aeval_eq : aeval x p = 0) (coeff_zero_ne : p.coeff 0 ≠ 0) : (x⁻¹ : L) ∈ A := by suffices (x⁻¹ : L) = (-p.coeff 0)⁻¹ • aeval x (divX p) by rw [this] exact A.smul_mem (aeval x _).2 _ have : aeval (x : L) p = 0 := by rw [Subalgebra.aeval_coe, aeval_eq, Subalgebra.coe_zero] -- Porting note: this was a long sequence of `rw`. rw [inv_eq_of_root_of_coeff_zero_ne_zero this coeff_zero_ne, div_eq_inv_mul, Algebra.smul_def] simp only [aeval_coe, Submonoid.coe_mul, Subsemiring.coe_toSubmonoid, coe_toSubsemiring, coe_algebraMap] rw [map_inv₀, map_neg, inv_neg, neg_mul] theorem Subalgebra.inv_mem_of_algebraic {x : A} (hx : _root_.IsAlgebraic K (x : L)) : (x⁻¹ : L) ∈ A := by obtain ⟨p, ne_zero, aeval_eq⟩ := hx rw [Subalgebra.aeval_coe, Subalgebra.coe_eq_zero] at aeval_eq revert ne_zero aeval_eq refine p.recOnHorner ?_ ?_ ?_ · intro h contradiction · intro p a hp ha _ih _ne_zero aeval_eq refine A.inv_mem_of_root_of_coeff_zero_ne_zero aeval_eq ?_ rwa [coeff_add, hp, zero_add, coeff_C, if_pos rfl] · intro p hp ih _ne_zero aeval_eq rw [map_mul, aeval_X, mul_eq_zero] at aeval_eq cases' aeval_eq with aeval_eq x_eq · exact ih hp aeval_eq · rw [x_eq, Subalgebra.coe_zero, inv_zero] exact A.zero_mem /-- In an algebraic extension L/K, an intermediate subalgebra is a field. -/ theorem Subalgebra.isField_of_algebraic [Algebra.IsAlgebraic K L] : IsField A := { show Nontrivial A by infer_instance, Subalgebra.toCommRing A with mul_inv_cancel := fun {a} ha => ⟨⟨a⁻¹, A.inv_mem_of_algebraic (Algebra.IsAlgebraic.isAlgebraic (a : L))⟩, Subtype.ext (mul_inv_cancel (mt (Subalgebra.coe_eq_zero _).mp ha))⟩ } end Field section Pi variable (R' : Type u) (S' : Type v) (T' : Type w) /-- This is not an instance as it forms a diamond with `Pi.instSMul`. See the `instance_diamonds` test for details. -/ def Polynomial.hasSMulPi [Semiring R'] [SMul R' S'] : SMul R'[X] (R' → S') := ⟨fun p f x => eval x p • f x⟩ /-- This is not an instance as it forms a diamond with `Pi.instSMul`. See the `instance_diamonds` test for details. -/ noncomputable def Polynomial.hasSMulPi' [CommSemiring R'] [Semiring S'] [Algebra R' S'] [SMul S' T'] : SMul R'[X] (S' → T') := ⟨fun p f x => aeval x p • f x⟩ attribute [local instance] Polynomial.hasSMulPi Polynomial.hasSMulPi' @[simp] theorem polynomial_smul_apply [Semiring R'] [SMul R' S'] (p : R'[X]) (f : R' → S') (x : R') : (p • f) x = eval x p • f x := rfl @[simp] theorem polynomial_smul_apply' [CommSemiring R'] [Semiring S'] [Algebra R' S'] [SMul S' T'] (p : R'[X]) (f : S' → T') (x : S') : (p • f) x = aeval x p • f x := rfl variable [CommSemiring R'] [CommSemiring S'] [CommSemiring T'] [Algebra R' S'] [Algebra S' T'] -- Porting note: the proofs in this definition used `funext` in term-mode, but I was not able -- to get them to work anymore. /-- This is not an instance for the same reasons as `Polynomial.hasSMulPi'`. -/ noncomputable def Polynomial.algebraPi : Algebra R'[X] (S' → T') := { Polynomial.hasSMulPi' R' S' T' with toFun := fun p z => algebraMap S' T' (aeval z p) map_one' := by funext z simp only [Polynomial.aeval_one, Pi.one_apply, map_one] map_mul' := fun f g => by funext z simp only [Pi.mul_apply, map_mul] map_zero' := by funext z simp only [Polynomial.aeval_zero, Pi.zero_apply, map_zero] map_add' := fun f g => by funext z simp only [Polynomial.aeval_add, Pi.add_apply, map_add] commutes' := fun p f => by funext z exact mul_comm _ _ smul_def' := fun p f => by funext z simp only [polynomial_smul_apply', Algebra.algebraMap_eq_smul_one, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Pi.mul_apply, Algebra.smul_mul_assoc, one_mul] } attribute [local instance] Polynomial.algebraPi @[simp] theorem Polynomial.algebraMap_pi_eq_aeval : (algebraMap R'[X] (S' → T') : R'[X] → S' → T') = fun p z => algebraMap _ _ (aeval z p) := rfl @[simp] theorem Polynomial.algebraMap_pi_self_eq_eval : (algebraMap R'[X] (R' → R') : R'[X] → R' → R') = fun p z => eval z p := rfl end Pi
RingTheory\AlgebraicIndependent.lean
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.MvPolynomial.Basic /-! # Algebraic Independence This file defines algebraic independence of a family of element of an `R` algebra. ## Main definitions * `AlgebraicIndependent` - `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. * `AlgebraicIndependent.repr` - The canonical map from the subalgebra generated by an algebraic independent family into the polynomial ring. ## References * [Stacks: Transcendence](https://stacks.math.columbia.edu/tag/030D) ## TODO Define the transcendence degree and show it is independent of the choice of a transcendence basis. ## Tags transcendence basis, transcendence degree, transcendence -/ noncomputable section open Function Set Subalgebra MvPolynomial Algebra open scoped Classical universe x u v w variable {ι : Type*} {ι' : Type*} (R : Type*) {K : Type*} variable {A : Type*} {A' A'' : Type*} {V : Type u} {V' : Type*} variable (x : ι → A) variable [CommRing R] [CommRing A] [CommRing A'] [CommRing A''] variable [Algebra R A] [Algebra R A'] [Algebra R A''] variable {a b : R} /-- `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. -/ def AlgebraicIndependent : Prop := Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) variable {R} {x} theorem algebraicIndependent_iff_ker_eq_bot : AlgebraicIndependent R x ↔ RingHom.ker (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom = ⊥ := RingHom.injective_iff_ker_eq_bot _ theorem algebraicIndependent_iff : AlgebraicIndependent R x ↔ ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := injective_iff_map_eq_zero _ theorem AlgebraicIndependent.eq_zero_of_aeval_eq_zero (h : AlgebraicIndependent R x) : ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := algebraicIndependent_iff.1 h theorem algebraicIndependent_iff_injective_aeval : AlgebraicIndependent R x ↔ Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) := Iff.rfl @[simp] theorem algebraicIndependent_empty_type_iff [IsEmpty ι] : AlgebraicIndependent R x ↔ Injective (algebraMap R A) := by have : aeval x = (Algebra.ofId R A).comp (@isEmptyAlgEquiv R ι _ _).toAlgHom := by ext i exact IsEmpty.elim' ‹IsEmpty ι› i rw [AlgebraicIndependent, this, ← Injective.of_comp_iff' _ (@isEmptyAlgEquiv R ι _ _).bijective] rfl namespace AlgebraicIndependent variable (hx : AlgebraicIndependent R x) theorem algebraMap_injective : Injective (algebraMap R A) := by simpa [Function.comp] using (Injective.of_comp_iff (algebraicIndependent_iff_injective_aeval.1 hx) MvPolynomial.C).2 (MvPolynomial.C_injective _ _) theorem linearIndependent : LinearIndependent R x := by rw [linearIndependent_iff_injective_total] have : Finsupp.total ι A R x = (MvPolynomial.aeval x).toLinearMap.comp (Finsupp.total ι _ R X) := by ext simp rw [this] refine hx.comp ?_ rw [← linearIndependent_iff_injective_total] exact linearIndependent_X _ _ protected theorem injective [Nontrivial R] : Injective x := hx.linearIndependent.injective theorem ne_zero [Nontrivial R] (i : ι) : x i ≠ 0 := hx.linearIndependent.ne_zero i theorem comp (f : ι' → ι) (hf : Function.Injective f) : AlgebraicIndependent R (x ∘ f) := by intro p q simpa [aeval_rename, (rename_injective f hf).eq_iff] using @hx (rename f p) (rename f q) theorem coe_range : AlgebraicIndependent R ((↑) : range x → A) := by simpa using hx.comp _ (rangeSplitting_injective x) theorem map {f : A →ₐ[R] A'} (hf_inj : Set.InjOn f (adjoin R (range x))) : AlgebraicIndependent R (f ∘ x) := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp have h : ∀ p : MvPolynomial ι R, aeval x p ∈ (@aeval R _ _ _ _ _ ((↑) : range x → A)).range := by intro p rw [AlgHom.mem_range] refine ⟨MvPolynomial.rename (codRestrict x (range x) mem_range_self) p, ?_⟩ simp [Function.comp, aeval_rename] intro x y hxy rw [this] at hxy rw [adjoin_eq_range] at hf_inj exact hx (hf_inj (h x) (h y) hxy) theorem map' {f : A →ₐ[R] A'} (hf_inj : Injective f) : AlgebraicIndependent R (f ∘ x) := hx.map hf_inj.injOn theorem of_comp (f : A →ₐ[R] A') (hfv : AlgebraicIndependent R (f ∘ x)) : AlgebraicIndependent R x := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp rw [AlgebraicIndependent, this, AlgHom.coe_comp] at hfv exact hfv.of_comp end AlgebraicIndependent open AlgebraicIndependent theorem AlgHom.algebraicIndependent_iff (f : A →ₐ[R] A') (hf : Injective f) : AlgebraicIndependent R (f ∘ x) ↔ AlgebraicIndependent R x := ⟨fun h => h.of_comp f, fun h => h.map hf.injOn⟩ @[nontriviality] theorem algebraicIndependent_of_subsingleton [Subsingleton R] : AlgebraicIndependent R x := algebraicIndependent_iff.2 fun _ _ => Subsingleton.elim _ _ theorem algebraicIndependent_equiv (e : ι ≃ ι') {f : ι' → A} : AlgebraicIndependent R (f ∘ e) ↔ AlgebraicIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ theorem algebraicIndependent_equiv' (e : ι ≃ ι') {f : ι' → A} {g : ι → A} (h : f ∘ e = g) : AlgebraicIndependent R g ↔ AlgebraicIndependent R f := h ▸ algebraicIndependent_equiv e theorem algebraicIndependent_subtype_range {ι} {f : ι → A} (hf : Injective f) : AlgebraicIndependent R ((↑) : range f → A) ↔ AlgebraicIndependent R f := Iff.symm <| algebraicIndependent_equiv' (Equiv.ofInjective f hf) rfl alias ⟨AlgebraicIndependent.of_subtype_range, _⟩ := algebraicIndependent_subtype_range theorem algebraicIndependent_image {ι} {s : Set ι} {f : ι → A} (hf : Set.InjOn f s) : (AlgebraicIndependent R fun x : s => f x) ↔ AlgebraicIndependent R fun x : f '' s => (x : A) := algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl theorem algebraicIndependent_adjoin (hs : AlgebraicIndependent R x) : @AlgebraicIndependent ι R (adjoin R (range x)) (fun i : ι => ⟨x i, subset_adjoin (mem_range_self i)⟩) _ _ _ := AlgebraicIndependent.of_comp (adjoin R (range x)).val hs /-- A set of algebraically independent elements in an algebra `A` over a ring `K` is also algebraically independent over a subring `R` of `K`. -/ theorem AlgebraicIndependent.restrictScalars {K : Type*} [CommRing K] [Algebra R K] [Algebra K A] [IsScalarTower R K A] (hinj : Function.Injective (algebraMap R K)) (ai : AlgebraicIndependent K x) : AlgebraicIndependent R x := by have : (aeval x : MvPolynomial ι K →ₐ[K] A).toRingHom.comp (MvPolynomial.map (algebraMap R K)) = (aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom := by ext <;> simp [algebraMap_eq_smul_one] show Injective (aeval x).toRingHom rw [← this, RingHom.coe_comp] exact Injective.comp ai (MvPolynomial.map_injective _ hinj) /-- Every finite subset of an algebraically independent set is algebraically independent. -/ theorem algebraicIndependent_finset_map_embedding_subtype (s : Set A) (li : AlgebraicIndependent R ((↑) : s → A)) (t : Finset s) : AlgebraicIndependent R ((↑) : Finset.map (Embedding.subtype s) t → A) := by let f : t.map (Embedding.subtype s) → s := fun x => ⟨x.1, by obtain ⟨x, h⟩ := x rw [Finset.mem_map] at h obtain ⟨a, _, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert AlgebraicIndependent.comp li f _ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _, rfl⟩ := hx obtain ⟨b, _, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] /-- If every finite set of algebraically independent element has cardinality at most `n`, then the same is true for arbitrary sets of algebraically independent elements. -/ theorem algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded {n : ℕ} (H : ∀ s : Finset A, (AlgebraicIndependent R fun i : s => (i : A)) → s.card ≤ n) : ∀ s : Set A, AlgebraicIndependent R ((↑) : s → A) → Cardinal.mk s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply algebraicIndependent_finset_map_embedding_subtype _ li section Subtype theorem AlgebraicIndependent.restrict_of_comp_subtype {s : Set ι} (hs : AlgebraicIndependent R (x ∘ (↑) : s → A)) : AlgebraicIndependent R (s.restrict x) := hs variable (R A) theorem algebraicIndependent_empty_iff : AlgebraicIndependent R ((↑) : (∅ : Set A) → A) ↔ Injective (algebraMap R A) := by simp variable {R A} theorem AlgebraicIndependent.mono {t s : Set A} (h : t ⊆ s) (hx : AlgebraicIndependent R ((↑) : s → A)) : AlgebraicIndependent R ((↑) : t → A) := by simpa [Function.comp] using hx.comp (inclusion h) (inclusion_injective h) end Subtype theorem AlgebraicIndependent.to_subtype_range {ι} {f : ι → A} (hf : AlgebraicIndependent R f) : AlgebraicIndependent R ((↑) : range f → A) := by nontriviality R rwa [algebraicIndependent_subtype_range hf.injective] theorem AlgebraicIndependent.to_subtype_range' {ι} {f : ι → A} (hf : AlgebraicIndependent R f) {t} (ht : range f = t) : AlgebraicIndependent R ((↑) : t → A) := ht ▸ hf.to_subtype_range theorem algebraicIndependent_comp_subtype {s : Set ι} : AlgebraicIndependent R (x ∘ (↑) : s → A) ↔ ∀ p ∈ MvPolynomial.supported R s, aeval x p = 0 → p = 0 := by have : (aeval (x ∘ (↑) : s → A) : _ →ₐ[R] _) = (aeval x).comp (rename (↑)) := by ext; simp have : ∀ p : MvPolynomial s R, rename ((↑) : s → ι) p = 0 ↔ p = 0 := (injective_iff_map_eq_zero' (rename ((↑) : s → ι) : MvPolynomial s R →ₐ[R] _).toRingHom).1 (rename_injective _ Subtype.val_injective) simp [algebraicIndependent_iff, supported_eq_range_rename, *] theorem algebraicIndependent_subtype {s : Set A} : AlgebraicIndependent R ((↑) : s → A) ↔ ∀ p : MvPolynomial A R, p ∈ MvPolynomial.supported R s → aeval id p = 0 → p = 0 := by apply @algebraicIndependent_comp_subtype _ _ _ id theorem algebraicIndependent_of_finite (s : Set A) (H : ∀ t ⊆ s, t.Finite → AlgebraicIndependent R ((↑) : t → A)) : AlgebraicIndependent R ((↑) : s → A) := algebraicIndependent_subtype.2 fun p hp => algebraicIndependent_subtype.1 (H _ (mem_supported.1 hp) (Finset.finite_toSet _)) _ (by simp) theorem AlgebraicIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → A) (hs : AlgebraicIndependent R fun x : s => g (f x)) : AlgebraicIndependent R fun x : f '' s => g x := by nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs theorem AlgebraicIndependent.image {ι} {s : Set ι} {f : ι → A} (hs : AlgebraicIndependent R fun x : s => f x) : AlgebraicIndependent R fun x : f '' s => (x : A) := by convert AlgebraicIndependent.image_of_comp s f id hs theorem algebraicIndependent_iUnion_of_directed {η : Type*} [Nonempty η] {s : η → Set A} (hs : Directed (· ⊆ ·) s) (h : ∀ i, AlgebraicIndependent R ((↑) : s i → A)) : AlgebraicIndependent R ((↑) : (⋃ i, s i) → A) := by refine algebraicIndependent_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) theorem algebraicIndependent_sUnion_of_directed {s : Set (Set A)} (hsn : s.Nonempty) (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, AlgebraicIndependent R ((↑) : a → A)) : AlgebraicIndependent R ((↑) : ⋃₀ s → A) := by letI : Nonempty s := Nonempty.to_subtype hsn rw [sUnion_eq_iUnion] exact algebraicIndependent_iUnion_of_directed hs.directed_val (by simpa using h) theorem exists_maximal_algebraicIndependent (s t : Set A) (hst : s ⊆ t) (hs : AlgebraicIndependent R ((↑) : s → A)) : ∃ u : Set A, AlgebraicIndependent R ((↑) : u → A) ∧ s ⊆ u ∧ u ⊆ t ∧ ∀ x : Set A, AlgebraicIndependent R ((↑) : x → A) → u ⊆ x → x ⊆ t → x = u := by rcases zorn_subset_nonempty { u : Set A | AlgebraicIndependent R ((↑) : u → A) ∧ s ⊆ u ∧ u ⊆ t } (fun c hc chainc hcn => ⟨⋃₀ c, by refine ⟨⟨algebraicIndependent_sUnion_of_directed hcn chainc.directedOn fun a ha => (hc ha).1, ?_, ?_⟩, ?_⟩ · cases' hcn with x hx exact subset_sUnion_of_subset _ x (hc hx).2.1 hx · exact sUnion_subset fun x hx => (hc hx).2.2 · intro s exact subset_sUnion_of_mem⟩) s ⟨hs, Set.Subset.refl s, hst⟩ with ⟨u, ⟨huai, _, hut⟩, hsu, hx⟩ use u, huai, hsu, hut intro x hxai huv hxt exact hx _ ⟨hxai, _root_.trans hsu huv, hxt⟩ huv section repr variable (hx : AlgebraicIndependent R x) /-- Canonical isomorphism between polynomials and the subalgebra generated by algebraically independent elements. -/ @[simps!] def AlgebraicIndependent.aevalEquiv (hx : AlgebraicIndependent R x) : MvPolynomial ι R ≃ₐ[R] Algebra.adjoin R (range x) := by apply AlgEquiv.ofBijective (AlgHom.codRestrict (@aeval R A ι _ _ _ x) (Algebra.adjoin R (range x)) _) swap · intro x rw [adjoin_range_eq_range_aeval] exact AlgHom.mem_range_self _ _ · constructor · exact (AlgHom.injective_codRestrict _ _ _).2 hx · rintro ⟨x, hx⟩ rw [adjoin_range_eq_range_aeval] at hx rcases hx with ⟨y, rfl⟩ use y ext simp --@[simp] Porting note: removing simp because the linter complains about deterministic timeout theorem AlgebraicIndependent.algebraMap_aevalEquiv (hx : AlgebraicIndependent R x) (p : MvPolynomial ι R) : algebraMap (Algebra.adjoin R (range x)) A (hx.aevalEquiv p) = aeval x p := rfl /-- The canonical map from the subalgebra generated by an algebraic independent family into the polynomial ring. -/ def AlgebraicIndependent.repr (hx : AlgebraicIndependent R x) : Algebra.adjoin R (range x) →ₐ[R] MvPolynomial ι R := hx.aevalEquiv.symm @[simp] theorem AlgebraicIndependent.aeval_repr (p) : aeval x (hx.repr p) = p := Subtype.ext_iff.1 (AlgEquiv.apply_symm_apply hx.aevalEquiv p) theorem AlgebraicIndependent.aeval_comp_repr : (aeval x).comp hx.repr = Subalgebra.val _ := AlgHom.ext <| hx.aeval_repr theorem AlgebraicIndependent.repr_ker : RingHom.ker (hx.repr : adjoin R (range x) →+* MvPolynomial ι R) = ⊥ := (RingHom.injective_iff_ker_eq_bot _).1 (AlgEquiv.injective _) end repr -- TODO - make this an `AlgEquiv` /-- The isomorphism between `MvPolynomial (Option ι) R` and the polynomial ring over the algebra generated by an algebraically independent family. -/ def AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin (hx : AlgebraicIndependent R x) : MvPolynomial (Option ι) R ≃+* Polynomial (adjoin R (Set.range x)) := (MvPolynomial.optionEquivLeft _ _).toRingEquiv.trans (Polynomial.mapEquiv hx.aevalEquiv.toRingEquiv) @[simp] theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply (hx : AlgebraicIndependent R x) (y) : hx.mvPolynomialOptionEquivPolynomialAdjoin y = Polynomial.map (hx.aevalEquiv : MvPolynomial ι R →+* adjoin R (range x)) (aeval (fun o : Option ι => o.elim Polynomial.X fun s : ι => Polynomial.C (X s)) y) := rfl --@[simp] Porting note: removing simp because the linter complains about deterministic timeout theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_C (hx : AlgebraicIndependent R x) (r) : hx.mvPolynomialOptionEquivPolynomialAdjoin (C r) = Polynomial.C (algebraMap _ _ r) := by rw [AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply, aeval_C, IsScalarTower.algebraMap_apply R (MvPolynomial ι R), ← Polynomial.C_eq_algebraMap, Polynomial.map_C, RingHom.coe_coe, AlgEquiv.commutes] --@[simp] Porting note (#10618): simp can prove it theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_X_none (hx : AlgebraicIndependent R x) : hx.mvPolynomialOptionEquivPolynomialAdjoin (X none) = Polynomial.X := by rw [AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply, aeval_X, Option.elim, Polynomial.map_X] --@[simp] Porting note (#10618): simp can prove it theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_X_some (hx : AlgebraicIndependent R x) (i) : hx.mvPolynomialOptionEquivPolynomialAdjoin (X (some i)) = Polynomial.C (hx.aevalEquiv (X i)) := by rw [AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply, aeval_X, Option.elim, Polynomial.map_C, RingHom.coe_coe] theorem AlgebraicIndependent.aeval_comp_mvPolynomialOptionEquivPolynomialAdjoin (hx : AlgebraicIndependent R x) (a : A) : RingHom.comp (↑(Polynomial.aeval a : Polynomial (adjoin R (Set.range x)) →ₐ[_] A) : Polynomial (adjoin R (Set.range x)) →+* A) hx.mvPolynomialOptionEquivPolynomialAdjoin.toRingHom = ↑(MvPolynomial.aeval fun o : Option ι => o.elim a x : MvPolynomial (Option ι) R →ₐ[R] A) := by refine MvPolynomial.ringHom_ext ?_ ?_ <;> simp only [RingHom.comp_apply, RingEquiv.toRingHom_eq_coe, RingEquiv.coe_toRingHom, AlgHom.coe_toRingHom, AlgHom.coe_toRingHom] · intro r rw [hx.mvPolynomialOptionEquivPolynomialAdjoin_C, aeval_C, Polynomial.aeval_C, IsScalarTower.algebraMap_apply R (adjoin R (range x)) A] · rintro (⟨⟩ | ⟨i⟩) · rw [hx.mvPolynomialOptionEquivPolynomialAdjoin_X_none, aeval_X, Polynomial.aeval_X, Option.elim] · rw [hx.mvPolynomialOptionEquivPolynomialAdjoin_X_some, Polynomial.aeval_C, hx.algebraMap_aevalEquiv, aeval_X, aeval_X, Option.elim] theorem AlgebraicIndependent.option_iff (hx : AlgebraicIndependent R x) (a : A) : (AlgebraicIndependent R fun o : Option ι => o.elim a x) ↔ ¬IsAlgebraic (adjoin R (Set.range x)) a := by rw [algebraicIndependent_iff_injective_aeval, isAlgebraic_iff_not_injective, Classical.not_not, ← AlgHom.coe_toRingHom, ← hx.aeval_comp_mvPolynomialOptionEquivPolynomialAdjoin, RingHom.coe_comp] exact Injective.of_comp_iff' (Polynomial.aeval a) (mvPolynomialOptionEquivPolynomialAdjoin hx).bijective variable (R) /-- A family is a transcendence basis if it is a maximal algebraically independent subset. -/ def IsTranscendenceBasis (x : ι → A) : Prop := AlgebraicIndependent R x ∧ ∀ (s : Set A) (_ : AlgebraicIndependent R ((↑) : s → A)) (_ : range x ≤ s), range x = s theorem exists_isTranscendenceBasis (h : Injective (algebraMap R A)) : ∃ s : Set A, IsTranscendenceBasis R ((↑) : s → A) := by cases' exists_maximal_algebraicIndependent (∅ : Set A) Set.univ (Set.subset_univ _) ((algebraicIndependent_empty_iff R A).2 h) with s hs use s, hs.1 intro t ht hr simp only [Subtype.range_coe_subtype, setOf_mem_eq] at * exact Eq.symm (hs.2.2.2 t ht hr (Set.subset_univ _)) variable {R} theorem AlgebraicIndependent.isTranscendenceBasis_iff {ι : Type w} {R : Type u} [CommRing R] [Nontrivial R] {A : Type v} [CommRing A] [Algebra R A] {x : ι → A} (i : AlgebraicIndependent R x) : IsTranscendenceBasis R x ↔ ∀ (κ : Type v) (w : κ → A) (_ : AlgebraicIndependent R w) (j : ι → κ) (_ : w ∘ j = x), Surjective j := by fconstructor · rintro p κ w i' j rfl have p := p.2 (range w) i'.coe_range (range_comp_subset_range _ _) rw [range_comp, ← @image_univ _ _ w] at p exact range_iff_surjective.mp (image_injective.mpr i'.injective p) · intro p use i intro w i' h specialize p w ((↑) : w → A) i' (fun i => ⟨x i, range_subset_iff.mp h i⟩) (by ext; simp) have q := congr_arg (fun s => ((↑) : w → A) '' s) p.range_eq dsimp at q rw [← image_univ, image_image] at q simpa using q theorem IsTranscendenceBasis.isAlgebraic [Nontrivial R] (hx : IsTranscendenceBasis R x) : Algebra.IsAlgebraic (adjoin R (range x)) A := by constructor intro a rw [← not_iff_comm.1 (hx.1.option_iff _).symm] intro ai have h₁ : range x ⊆ range fun o : Option ι => o.elim a x := by rintro x ⟨y, rfl⟩ exact ⟨some y, rfl⟩ have h₂ : range x ≠ range fun o : Option ι => o.elim a x := by intro h have : a ∈ range x := by rw [h] exact ⟨none, rfl⟩ rcases this with ⟨b, rfl⟩ have : some b = none := ai.injective rfl simpa exact h₂ (hx.2 (Set.range fun o : Option ι => o.elim a x) ((algebraicIndependent_subtype_range ai.injective).2 ai) h₁) section Field variable [Field K] [Algebra K A] /- Porting note: removing `simp`, not in simp normal form. Could make `Function.Injective f` a simp lemma when `f` is a field hom, and then simp would prove this -/ theorem algebraicIndependent_empty_type [IsEmpty ι] [Nontrivial A] : AlgebraicIndependent K x := by rw [algebraicIndependent_empty_type_iff] exact RingHom.injective _ theorem algebraicIndependent_empty [Nontrivial A] : AlgebraicIndependent K ((↑) : (∅ : Set A) → A) := algebraicIndependent_empty_type end Field
RingTheory\AlgebraTower.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.Basis /-! # Towers of algebras We set up the basic theory of algebra towers. An algebra tower A/S/R is expressed by having instances of `Algebra A S`, `Algebra R S`, `Algebra R A` and `IsScalarTower R S A`, the later asserting the compatibility condition `(r • s) • a = r • (s • a)`. In `FieldTheory/Tower.lean` we use this to prove the tower law for finite extensions, that if `R` and `S` are both fields, then `[A:R] = [A:S] [S:A]`. In this file we prepare the main lemma: if `{bi | i ∈ I}` is an `R`-basis of `S` and `{cj | j ∈ J}` is an `S`-basis of `A`, then `{bi cj | i ∈ I, j ∈ J}` is an `R`-basis of `A`. This statement does not require the base rings to be a field, so we also generalize the lemma to rings in this file. -/ open Pointwise universe u v w u₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) namespace IsScalarTower section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra S A] [Algebra S B] [Algebra R A] [Algebra R B] variable [IsScalarTower R S A] [IsScalarTower R S B] /-- Suppose that `R → S → A` is a tower of algebras. If an element `r : R` is invertible in `S`, then it is invertible in `A`. -/ def Invertible.algebraTower (r : R) [Invertible (algebraMap R S r)] : Invertible (algebraMap R A r) := Invertible.copy (Invertible.map (algebraMap S A) (algebraMap R S r)) (algebraMap R A r) (IsScalarTower.algebraMap_apply R S A r) /-- A natural number that is invertible when coerced to `R` is also invertible when coerced to any `R`-algebra. -/ def invertibleAlgebraCoeNat (n : ℕ) [inv : Invertible (n : R)] : Invertible (n : A) := haveI : Invertible (algebraMap ℕ R n) := inv Invertible.algebraTower ℕ R A n end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] [CommSemiring B] variable [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] end CommSemiring end IsScalarTower section AlgebraMapCoeffs variable {R} {ι M : Type*} [CommSemiring R] [Semiring A] [AddCommMonoid M] variable [Algebra R A] [Module A M] [Module R M] [IsScalarTower R A M] variable (b : Basis ι R M) (h : Function.Bijective (algebraMap R A)) /-- If `R` and `A` have a bijective `algebraMap R A` and act identically on `M`, then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module. -/ @[simps! repr_apply_support_val repr_apply_toFun] noncomputable def Basis.algebraMapCoeffs : Basis ι A M := b.mapCoeffs (RingEquiv.ofBijective _ h) fun c x => by simp theorem Basis.algebraMapCoeffs_apply (i : ι) : b.algebraMapCoeffs A h i = b i := b.mapCoeffs_apply _ _ _ @[simp] theorem Basis.coe_algebraMapCoeffs : (b.algebraMapCoeffs A h : ι → M) = b := b.coe_mapCoeffs _ _ end AlgebraMapCoeffs section Semiring open Finsupp open scoped Classical universe v₁ w₁ variable {R S A} variable [Semiring R] [Semiring S] [AddCommMonoid A] variable [Module R S] [Module S A] [Module R A] [IsScalarTower R S A] theorem linearIndependent_smul {ι : Type v₁} {b : ι → S} {ι' : Type w₁} {c : ι' → A} (hb : LinearIndependent R b) (hc : LinearIndependent S c) : LinearIndependent R fun p : ι × ι' => b p.1 • c p.2 := by rw [linearIndependent_iff'] at hb hc; rw [linearIndependent_iff'']; rintro s g hg hsg ⟨i, k⟩ by_cases hik : (i, k) ∈ s · have h1 : ∑ i ∈ s.image Prod.fst ×ˢ s.image Prod.snd, g i • b i.1 • c i.2 = 0 := by rw [← hsg] exact (Finset.sum_subset Finset.subset_product fun p _ hp => show g p • b p.1 • c p.2 = 0 by rw [hg p hp, zero_smul]).symm rw [Finset.sum_product_right] at h1 simp_rw [← smul_assoc, ← Finset.sum_smul] at h1 exact hb _ _ (hc _ _ h1 k (Finset.mem_image_of_mem _ hik)) i (Finset.mem_image_of_mem _ hik) exact hg _ hik variable (R) -- LinearIndependent is enough if S is a ring rather than semiring. theorem Basis.isScalarTower_of_nonempty {ι} [Nonempty ι] (b : Basis ι S A) : IsScalarTower R S S := (b.repr.symm.comp <| lsingle <| Classical.arbitrary ι).isScalarTower_of_injective R (b.repr.symm.injective.comp <| single_injective _) theorem Basis.isScalarTower_finsupp {ι} (b : Basis ι S A) : IsScalarTower R S (ι →₀ S) := b.repr.symm.isScalarTower_of_injective R b.repr.symm.injective variable {R} /-- `Basis.smulTower (b : Basis ι R S) (c : Basis ι S A)` is the `R`-basis on `A` where the `(i, j)`th basis vector is `b i • c j`. -/ noncomputable def Basis.smulTower {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) : Basis (ι × ι') R A := haveI := c.isScalarTower_finsupp R .ofRepr (c.repr.restrictScalars R ≪≫ₗ (Finsupp.lcongr (Equiv.refl _) b.repr ≪≫ₗ ((finsuppProdLEquiv R).symm ≪≫ₗ Finsupp.lcongr (Equiv.prodComm ι' ι) (LinearEquiv.refl _ _)))) @[simp] theorem Basis.smulTower_repr {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) (x ij) : (b.smulTower c).repr x ij = b.repr (c.repr x ij.2) ij.1 := by simp [smulTower] theorem Basis.smulTower_repr_mk {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) (x i j) : (b.smulTower c).repr x (i, j) = b.repr (c.repr x j) i := b.smulTower_repr c x (i, j) @[simp] theorem Basis.smulTower_apply {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) (ij) : (b.smulTower c) ij = b ij.1 • c ij.2 := by obtain ⟨i, j⟩ := ij rw [Basis.apply_eq_iff] ext ⟨i', j'⟩ rw [Basis.smulTower_repr, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_apply, Finsupp.single_apply] dsimp only split_ifs with hi · simp [hi, Finsupp.single_apply] · simp [hi] end Semiring section Ring variable {R S} variable [CommRing R] [Ring S] [Algebra R S] -- Porting note: Needed to add Algebra.toModule below theorem Basis.algebraMap_injective {ι : Type*} [NoZeroDivisors R] [Nontrivial S] (b : @Basis ι R S _ _ Algebra.toModule) : Function.Injective (algebraMap R S) := have : NoZeroSMulDivisors R S := b.noZeroSMulDivisors NoZeroSMulDivisors.algebraMap_injective R S end Ring section AlgHomTower variable {A} {C D : Type*} [CommSemiring A] [CommSemiring C] [CommSemiring D] [Algebra A C] [Algebra A D] variable (f : C →ₐ[A] D) [CommSemiring B] [Algebra A B] [Algebra B C] [IsScalarTower A B C] /-- Restrict the domain of an `AlgHom`. -/ def AlgHom.restrictDomain : B →ₐ[A] D := f.comp (IsScalarTower.toAlgHom A B C) -- Porting note: definition below used to be -- { f with commutes' := fun _ => rfl } -- but it complains about not finding (Algebra B D), despite it being given in the header of the thm /-- Extend the scalars of an `AlgHom`. -/ def AlgHom.extendScalars : @AlgHom B C D _ _ _ _ (f.restrictDomain B).toRingHom.toAlgebra where toFun := f.toFun map_one' := by simp only [toRingHom_eq_coe, RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, map_one] map_mul' := by simp only [toRingHom_eq_coe, RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, map_mul, MonoidHom.coe_coe, RingHom.coe_coe, forall_const] map_zero' := by simp only [toRingHom_eq_coe, RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, MonoidHom.coe_coe, map_zero] map_add' := by simp only [toRingHom_eq_coe, RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, MonoidHom.coe_coe, map_add, RingHom.coe_coe, forall_const] commutes' := fun _ ↦ rfl __ := (f.restrictDomain B).toRingHom.toAlgebra variable {B} /-- `AlgHom`s from the top of a tower are equivalent to a pair of `AlgHom`s. -/ def algHomEquivSigma : (C →ₐ[A] D) ≃ Σf : B →ₐ[A] D, @AlgHom B C D _ _ _ _ f.toRingHom.toAlgebra where toFun f := ⟨f.restrictDomain B, f.extendScalars B⟩ invFun fg := let _ := fg.1.toRingHom.toAlgebra fg.2.restrictScalars A left_inv f := by dsimp only ext rfl right_inv := by rintro ⟨⟨⟨⟨⟨f, _⟩, _⟩, _⟩, _⟩, ⟨⟨⟨⟨g, _⟩, _⟩, _⟩, hg⟩⟩ obtain rfl : f = fun x => g (algebraMap B C x) := by ext x exact (hg x).symm rfl end AlgHomTower
RingTheory\Artinian.lean
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.SetLike.Fintype import Mathlib.Algebra.Divisibility.Prod import Mathlib.RingTheory.Nakayama import Mathlib.RingTheory.SimpleModule import Mathlib.Tactic.RSuffices /-! # Artinian rings and modules A module satisfying these equivalent conditions is said to be an *Artinian* R-module if every decreasing chain of submodules is eventually constant, or equivalently, if the relation `<` on submodules is well founded. A ring is said to be left (or right) Artinian if it is Artinian as a left (or right) module over itself, or simply Artinian if it is both left and right Artinian. ## Main definitions Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`. * `IsArtinian R M` is the proposition that `M` is an Artinian `R`-module. It is a class, implemented as the predicate that the `<` relation on submodules is well founded. * `IsArtinianRing R` is the proposition that `R` is a left Artinian ring. ## Main results * `IsArtinianRing.localization_surjective`: the canonical homomorphism from a commutative artinian ring to any localization of itself is surjective. * `IsArtinianRing.isNilpotent_jacobson_bot`: the Jacobson radical of a commutative artinian ring is a nilpotent ideal. (TODO: generalize to noncommutative rings.) * `IsArtinianRing.primeSpectrum_finite`, `IsArtinianRing.isMaximal_of_isPrime`: there are only finitely prime ideals in a commutative artinian ring, and each of them is maximal. * `IsArtinianRing.equivPi`: a reduced commutative artinian ring `R` is isomorphic to a finite product of fields (and therefore is a semisimple ring and a decomposition monoid; moreover `R[X]` is also a decomposition monoid). ## References * [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald] * [samuel] ## Tags Artinian, artinian, Artinian ring, Artinian module, artinian ring, artinian module -/ open Set Filter Pointwise /-- `IsArtinian R M` is the proposition that `M` is an Artinian `R`-module, implemented as the well-foundedness of submodule inclusion. -/ class IsArtinian (R M) [Semiring R] [AddCommMonoid M] [Module R M] : Prop where wellFounded_submodule_lt' : WellFounded ((· < ·) : Submodule R M → Submodule R M → Prop) section variable {R M P N : Type*} variable [Ring R] [AddCommGroup M] [AddCommGroup P] [AddCommGroup N] variable [Module R M] [Module R P] [Module R N] open IsArtinian /- Porting note: added this version with `R` and `M` explicit because infer kinds are unsupported in Lean 4-/ theorem IsArtinian.wellFounded_submodule_lt (R M) [Semiring R] [AddCommMonoid M] [Module R M] [IsArtinian R M] : WellFounded ((· < ·) : Submodule R M → Submodule R M → Prop) := IsArtinian.wellFounded_submodule_lt' theorem isArtinian_of_injective (f : M →ₗ[R] P) (h : Function.Injective f) [IsArtinian R P] : IsArtinian R M := ⟨Subrelation.wf (fun {A B} hAB => show A.map f < B.map f from Submodule.map_strictMono_of_injective h hAB) (InvImage.wf (Submodule.map f) (IsArtinian.wellFounded_submodule_lt R P))⟩ instance isArtinian_submodule' [IsArtinian R M] (N : Submodule R M) : IsArtinian R N := isArtinian_of_injective N.subtype Subtype.val_injective theorem isArtinian_of_le {s t : Submodule R M} [IsArtinian R t] (h : s ≤ t) : IsArtinian R s := isArtinian_of_injective (Submodule.inclusion h) (Submodule.inclusion_injective h) variable (M) theorem isArtinian_of_surjective (f : M →ₗ[R] P) (hf : Function.Surjective f) [IsArtinian R M] : IsArtinian R P := ⟨Subrelation.wf (fun {A B} hAB => show A.comap f < B.comap f from Submodule.comap_strictMono_of_surjective hf hAB) (InvImage.wf (Submodule.comap f) (IsArtinian.wellFounded_submodule_lt R M))⟩ variable {M} theorem isArtinian_of_linearEquiv (f : M ≃ₗ[R] P) [IsArtinian R M] : IsArtinian R P := isArtinian_of_surjective _ f.toLinearMap f.toEquiv.surjective theorem isArtinian_of_range_eq_ker [IsArtinian R M] [IsArtinian R P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (hf : Function.Injective f) (hg : Function.Surjective g) (h : LinearMap.range f = LinearMap.ker g) : IsArtinian R N := ⟨wellFounded_lt_exact_sequence (IsArtinian.wellFounded_submodule_lt R M) (IsArtinian.wellFounded_submodule_lt R P) (LinearMap.range f) (Submodule.map f) (Submodule.comap f) (Submodule.comap g) (Submodule.map g) (Submodule.gciMapComap hf) (Submodule.giMapComap hg) (by simp [Submodule.map_comap_eq, inf_comm]) (by simp [Submodule.comap_map_eq, h])⟩ instance isArtinian_prod [IsArtinian R M] [IsArtinian R P] : IsArtinian R (M × P) := isArtinian_of_range_eq_ker (LinearMap.inl R M P) (LinearMap.snd R M P) LinearMap.inl_injective LinearMap.snd_surjective (LinearMap.range_inl R M P) instance (priority := 100) isArtinian_of_finite [Finite M] : IsArtinian R M := ⟨Finite.wellFounded_of_trans_of_irrefl _⟩ -- Porting note: elab_as_elim can only be global and cannot be changed on an imported decl -- attribute [local elab_as_elim] Finite.induction_empty_option instance isArtinian_pi {R ι : Type*} [Finite ι] : ∀ {M : ι → Type*} [Ring R] [∀ i, AddCommGroup (M i)], ∀ [∀ i, Module R (M i)], ∀ [∀ i, IsArtinian R (M i)], IsArtinian R (∀ i, M i) := by apply Finite.induction_empty_option _ _ _ ι · intro α β e hα M _ _ _ _ have := @hα exact isArtinian_of_linearEquiv (LinearEquiv.piCongrLeft R M e) · intro M _ _ _ _ infer_instance · intro α _ ih M _ _ _ _ have := @ih exact isArtinian_of_linearEquiv (LinearEquiv.piOptionEquivProd R).symm /-- A version of `isArtinian_pi` for non-dependent functions. We need this instance because sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to prove that `ι → ℝ` is finite dimensional over `ℝ`). -/ instance isArtinian_pi' {R ι M : Type*} [Ring R] [AddCommGroup M] [Module R M] [Finite ι] [IsArtinian R M] : IsArtinian R (ι → M) := isArtinian_pi --porting note (#10754): new instance instance isArtinian_finsupp {R ι M : Type*} [Ring R] [AddCommGroup M] [Module R M] [Finite ι] [IsArtinian R M] : IsArtinian R (ι →₀ M) := isArtinian_of_linearEquiv (Finsupp.linearEquivFunOnFinite _ _ _).symm end open IsArtinian Submodule Function section Ring variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] theorem isArtinian_iff_wellFounded : IsArtinian R M ↔ WellFounded ((· < ·) : Submodule R M → Submodule R M → Prop) := ⟨fun h => h.1, IsArtinian.mk⟩ theorem IsArtinian.finite_of_linearIndependent [Nontrivial R] [IsArtinian R M] {s : Set M} (hs : LinearIndependent R ((↑) : s → M)) : s.Finite := by refine by_contradiction fun hf => (RelEmbedding.wellFounded_iff_no_descending_seq.1 (wellFounded_submodule_lt (R := R) (M := M))).elim' ?_ have f : ℕ ↪ s := Set.Infinite.natEmbedding s hf have : ∀ n, (↑) ∘ f '' { m | n ≤ m } ⊆ s := by rintro n x ⟨y, _, rfl⟩ exact (f y).2 have : ∀ a b : ℕ, a ≤ b ↔ span R (Subtype.val ∘ f '' { m | b ≤ m }) ≤ span R (Subtype.val ∘ f '' { m | a ≤ m }) := by intro a b rw [span_le_span_iff hs (this b) (this a), Set.image_subset_image_iff (Subtype.coe_injective.comp f.injective), Set.subset_def] simp only [Set.mem_setOf_eq] exact ⟨fun hab x => le_trans hab, fun h => h _ le_rfl⟩ exact ⟨⟨fun n => span R (Subtype.val ∘ f '' { m | n ≤ m }), fun x y => by rw [le_antisymm_iff, ← this y x, ← this x y] exact fun ⟨h₁, h₂⟩ => le_antisymm_iff.2 ⟨h₂, h₁⟩⟩, by intro a b conv_rhs => rw [GT.gt, lt_iff_le_not_le, this, this, ← lt_iff_le_not_le] rfl⟩ /-- A module is Artinian iff every nonempty set of submodules has a minimal submodule among them. -/ theorem set_has_minimal_iff_artinian : (∀ a : Set <| Submodule R M, a.Nonempty → ∃ M' ∈ a, ∀ I ∈ a, ¬I < M') ↔ IsArtinian R M := by rw [isArtinian_iff_wellFounded, WellFounded.wellFounded_iff_has_min] theorem IsArtinian.set_has_minimal [IsArtinian R M] (a : Set <| Submodule R M) (ha : a.Nonempty) : ∃ M' ∈ a, ∀ I ∈ a, ¬I < M' := set_has_minimal_iff_artinian.mpr ‹_› a ha /-- A module is Artinian iff every decreasing chain of submodules stabilizes. -/ theorem monotone_stabilizes_iff_artinian : (∀ f : ℕ →o (Submodule R M)ᵒᵈ, ∃ n, ∀ m, n ≤ m → f n = f m) ↔ IsArtinian R M := by rw [isArtinian_iff_wellFounded] exact WellFounded.monotone_chain_condition.symm namespace IsArtinian variable [IsArtinian R M] theorem monotone_stabilizes (f : ℕ →o (Submodule R M)ᵒᵈ) : ∃ n, ∀ m, n ≤ m → f n = f m := monotone_stabilizes_iff_artinian.mpr ‹_› f theorem eventuallyConst_of_isArtinian (f : ℕ →o (Submodule R M)ᵒᵈ) : atTop.EventuallyConst f := by simp_rw [eventuallyConst_atTop, eq_comm] exact monotone_stabilizes f /-- If `∀ I > J, P I` implies `P J`, then `P` holds for all submodules. -/ theorem induction {P : Submodule R M → Prop} (hgt : ∀ I, (∀ J < I, P J) → P I) (I : Submodule R M) : P I := (wellFounded_submodule_lt R M).recursion I hgt end IsArtinian namespace LinearMap variable [IsArtinian R M] /-- For any endomorphism of an Artinian module, any sufficiently high iterate has codisjoint kernel and range. -/ theorem eventually_codisjoint_ker_pow_range_pow (f : M →ₗ[R] M) : ∀ᶠ n in atTop, Codisjoint (LinearMap.ker (f ^ n)) (LinearMap.range (f ^ n)) := by obtain ⟨n, hn : ∀ m, n ≤ m → LinearMap.range (f ^ n) = LinearMap.range (f ^ m)⟩ := monotone_stabilizes f.iterateRange refine eventually_atTop.mpr ⟨n, fun m hm ↦ codisjoint_iff.mpr ?_⟩ simp_rw [← hn _ hm, Submodule.eq_top_iff', Submodule.mem_sup] intro x rsuffices ⟨y, hy⟩ : ∃ y, (f ^ m) ((f ^ n) y) = (f ^ m) x · exact ⟨x - (f ^ n) y, by simp [hy], (f ^ n) y, by simp⟩ -- Note: #8386 had to change `mem_range` into `mem_range (f := _)` simp_rw [f.pow_apply n, f.pow_apply m, ← iterate_add_apply, ← f.pow_apply (m + n), ← f.pow_apply m, ← mem_range (f := _), ← hn _ (n.le_add_left m), hn _ hm] exact LinearMap.mem_range_self (f ^ m) x lemma eventually_iInf_range_pow_eq (f : Module.End R M) : ∀ᶠ n in atTop, ⨅ m, LinearMap.range (f ^ m) = LinearMap.range (f ^ n) := by obtain ⟨n, hn : ∀ m, n ≤ m → LinearMap.range (f ^ n) = LinearMap.range (f ^ m)⟩ := monotone_stabilizes f.iterateRange refine eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_lt l m with h | h · rw [← hn _ (hl.trans h), hn _ hl] · exact f.iterateRange.monotone h.le /-- This is the Fitting decomposition of the module `M` with respect to the endomorphism `f`. See also `LinearMap.isCompl_iSup_ker_pow_iInf_range_pow` for an alternative spelling. -/ theorem eventually_isCompl_ker_pow_range_pow [IsNoetherian R M] (f : M →ₗ[R] M) : ∀ᶠ n in atTop, IsCompl (LinearMap.ker (f ^ n)) (LinearMap.range (f ^ n)) := by filter_upwards [f.eventually_disjoint_ker_pow_range_pow.and f.eventually_codisjoint_ker_pow_range_pow] with n hn simpa only [isCompl_iff] /-- This is the Fitting decomposition of the module `M` with respect to the endomorphism `f`. See also `LinearMap.eventually_isCompl_ker_pow_range_pow` for an alternative spelling. -/ theorem isCompl_iSup_ker_pow_iInf_range_pow [IsNoetherian R M] (f : M →ₗ[R] M) : IsCompl (⨆ n, LinearMap.ker (f ^ n)) (⨅ n, LinearMap.range (f ^ n)) := by obtain ⟨k, hk⟩ := eventually_atTop.mp <| f.eventually_isCompl_ker_pow_range_pow.and <| f.eventually_iInf_range_pow_eq.and f.eventually_iSup_ker_pow_eq obtain ⟨h₁, h₂, h₃⟩ := hk k (le_refl k) rwa [h₂, h₃] end LinearMap namespace IsArtinian variable [IsArtinian R M] /-- Any injective endomorphism of an Artinian module is surjective. -/ theorem surjective_of_injective_endomorphism (f : M →ₗ[R] M) (s : Injective f) : Surjective f := by obtain ⟨n, hn⟩ := eventually_atTop.mp f.eventually_codisjoint_ker_pow_range_pow specialize hn (n + 1) (n.le_add_right 1) rw [codisjoint_iff, LinearMap.ker_eq_bot.mpr (LinearMap.iterate_injective s _), bot_sup_eq, LinearMap.range_eq_top] at hn exact LinearMap.surjective_of_iterate_surjective n.succ_ne_zero hn /-- Any injective endomorphism of an Artinian module is bijective. -/ theorem bijective_of_injective_endomorphism (f : M →ₗ[R] M) (s : Injective f) : Bijective f := ⟨s, surjective_of_injective_endomorphism f s⟩ /-- A sequence `f` of submodules of an artinian module, with the supremum `f (n+1)` and the infimum of `f 0`, ..., `f n` being ⊤, is eventually ⊤. -/ theorem disjoint_partial_infs_eventually_top (f : ℕ → Submodule R M) (h : ∀ n, Disjoint (partialSups (OrderDual.toDual ∘ f) n) (OrderDual.toDual (f (n + 1)))) : ∃ n : ℕ, ∀ m, n ≤ m → f m = ⊤ := by -- A little off-by-one cleanup first: rsuffices ⟨n, w⟩ : ∃ n : ℕ, ∀ m, n ≤ m → OrderDual.toDual f (m + 1) = ⊤ · use n + 1 rintro (_ | m) p · cases p · apply w exact Nat.succ_le_succ_iff.mp p obtain ⟨n, w⟩ := monotone_stabilizes (partialSups (OrderDual.toDual ∘ f)) refine ⟨n, fun m p => ?_⟩ exact (h m).eq_bot_of_ge (sup_eq_left.1 <| (w (m + 1) <| le_add_right p).symm.trans <| w m p) end IsArtinian end Ring section CommRing variable {R : Type*} (M : Type*) [CommRing R] [AddCommGroup M] [Module R M] [IsArtinian R M] namespace IsArtinian theorem range_smul_pow_stabilizes (r : R) : ∃ n : ℕ, ∀ m, n ≤ m → LinearMap.range (r ^ n • LinearMap.id : M →ₗ[R] M) = LinearMap.range (r ^ m • LinearMap.id : M →ₗ[R] M) := monotone_stabilizes ⟨fun n => LinearMap.range (r ^ n • LinearMap.id : M →ₗ[R] M), fun n m h x ⟨y, hy⟩ => ⟨r ^ (m - n) • y, by dsimp at hy ⊢ rw [← smul_assoc, smul_eq_mul, ← pow_add, ← hy, add_tsub_cancel_of_le h]⟩⟩ variable {M} theorem exists_pow_succ_smul_dvd (r : R) (x : M) : ∃ (n : ℕ) (y : M), r ^ n.succ • y = r ^ n • x := by obtain ⟨n, hn⟩ := IsArtinian.range_smul_pow_stabilizes M r simp_rw [SetLike.ext_iff] at hn exact ⟨n, by simpa using hn n.succ n.le_succ (r ^ n • x)⟩ end IsArtinian end CommRing /-- A ring is Artinian if it is Artinian as a module over itself. Strictly speaking, this should be called `IsLeftArtinianRing` but we omit the `Left` for convenience in the commutative case. For a right Artinian ring, use `IsArtinian Rᵐᵒᵖ R`. -/ abbrev IsArtinianRing (R) [Ring R] := IsArtinian R R theorem isArtinianRing_iff {R} [Ring R] : IsArtinianRing R ↔ IsArtinian R R := Iff.rfl instance DivisionRing.instIsArtinianRing {K : Type*} [DivisionRing K] : IsArtinianRing K := ⟨Finite.wellFounded_of_trans_of_irrefl _⟩ theorem Ring.isArtinian_of_zero_eq_one {R} [Ring R] (h01 : (0 : R) = 1) : IsArtinianRing R := have := subsingleton_of_zero_eq_one h01 inferInstance theorem isArtinian_of_submodule_of_artinian (R M) [Ring R] [AddCommGroup M] [Module R M] (N : Submodule R M) (_ : IsArtinian R M) : IsArtinian R N := inferInstance instance isArtinian_of_quotient_of_artinian (R) [Ring R] (M) [AddCommGroup M] [Module R M] (N : Submodule R M) [IsArtinian R M] : IsArtinian R (M ⧸ N) := isArtinian_of_surjective M (Submodule.mkQ N) (Submodule.Quotient.mk_surjective N) /-- If `M / S / R` is a scalar tower, and `M / R` is Artinian, then `M / S` is also Artinian. -/ theorem isArtinian_of_tower (R) {S M} [CommRing R] [Ring S] [AddCommGroup M] [Algebra R S] [Module S M] [Module R M] [IsScalarTower R S M] (h : IsArtinian R M) : IsArtinian S M := by rw [isArtinian_iff_wellFounded] at h ⊢ exact (Submodule.restrictScalarsEmbedding R S M).wellFounded h instance (R) [CommRing R] [IsArtinianRing R] (I : Ideal R) : IsArtinianRing (R ⧸ I) := isArtinian_of_tower R inferInstance theorem isArtinian_of_fg_of_artinian {R M} [Ring R] [AddCommGroup M] [Module R M] (N : Submodule R M) [IsArtinianRing R] (hN : N.FG) : IsArtinian R N := by let ⟨s, hs⟩ := hN haveI := Classical.decEq M haveI := Classical.decEq R have : ∀ x ∈ s, x ∈ N := fun x hx => hs ▸ Submodule.subset_span hx refine @isArtinian_of_surjective _ ((↑s : Set M) →₀ R) N _ _ _ _ _ ?_ ?_ isArtinian_finsupp · exact Finsupp.total (↑s : Set M) N R (fun i => ⟨i, hs ▸ subset_span i.2⟩) · rw [← LinearMap.range_eq_top, eq_top_iff, ← map_le_map_iff_of_injective (show Injective (Submodule.subtype N) from Subtype.val_injective), Submodule.map_top, range_subtype, ← Submodule.map_top, ← Submodule.map_comp, Submodule.map_top] subst N refine span_le.2 (fun i hi => ?_) use Finsupp.single ⟨i, hi⟩ 1 simp instance isArtinian_of_fg_of_artinian' {R M} [Ring R] [AddCommGroup M] [Module R M] [IsArtinianRing R] [Module.Finite R M] : IsArtinian R M := have : IsArtinian R (⊤ : Submodule R M) := isArtinian_of_fg_of_artinian _ Module.Finite.out isArtinian_of_linearEquiv (LinearEquiv.ofTop (⊤ : Submodule R M) rfl) theorem IsArtinianRing.of_finite (R S) [CommRing R] [Ring S] [Algebra R S] [IsArtinianRing R] [Module.Finite R S] : IsArtinianRing S := isArtinian_of_tower R isArtinian_of_fg_of_artinian' /-- In a module over an artinian ring, the submodule generated by finitely many vectors is artinian. -/ theorem isArtinian_span_of_finite (R) {M} [Ring R] [AddCommGroup M] [Module R M] [IsArtinianRing R] {A : Set M} (hA : A.Finite) : IsArtinian R (Submodule.span R A) := isArtinian_of_fg_of_artinian _ (Submodule.fg_def.mpr ⟨A, hA, rfl⟩) theorem Function.Surjective.isArtinianRing {R} [Ring R] {S} [Ring S] {F} [FunLike F R S] [RingHomClass F R S] {f : F} (hf : Function.Surjective f) [H : IsArtinianRing R] : IsArtinianRing S := by rw [isArtinianRing_iff, isArtinian_iff_wellFounded] at H ⊢ exact (Ideal.orderEmbeddingOfSurjective f hf).wellFounded H instance isArtinianRing_range {R} [Ring R] {S} [Ring S] (f : R →+* S) [IsArtinianRing R] : IsArtinianRing f.range := f.rangeRestrict_surjective.isArtinianRing namespace IsArtinianRing open IsArtinian variable {R : Type*} [CommRing R] [IsArtinianRing R] theorem isNilpotent_jacobson_bot : IsNilpotent (Ideal.jacobson (⊥ : Ideal R)) := by let Jac := Ideal.jacobson (⊥ : Ideal R) let f : ℕ →o (Ideal R)ᵒᵈ := ⟨fun n => Jac ^ n, fun _ _ h => Ideal.pow_le_pow_right h⟩ obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → Jac ^ n = Jac ^ m := IsArtinian.monotone_stabilizes f refine ⟨n, ?_⟩ let J : Ideal R := annihilator (Jac ^ n) suffices J = ⊤ by have hJ : J • Jac ^ n = ⊥ := annihilator_smul (Jac ^ n) simpa only [this, top_smul, Ideal.zero_eq_bot] using hJ by_contra hJ change J ≠ ⊤ at hJ rcases IsArtinian.set_has_minimal { J' : Ideal R | J < J' } ⟨⊤, hJ.lt_top⟩ with ⟨J', hJJ' : J < J', hJ' : ∀ I, J < I → ¬I < J'⟩ rcases SetLike.exists_of_lt hJJ' with ⟨x, hxJ', hxJ⟩ obtain rfl : J ⊔ Ideal.span {x} = J' := by apply eq_of_le_of_not_lt _ (hJ' (J ⊔ Ideal.span {x}) _) · exact sup_le hJJ'.le (span_le.2 (singleton_subset_iff.2 hxJ')) · rw [SetLike.lt_iff_le_and_exists] exact ⟨le_sup_left, ⟨x, mem_sup_right (mem_span_singleton_self x), hxJ⟩⟩ have : J ⊔ Jac • Ideal.span {x} ≤ J ⊔ Ideal.span {x} := sup_le_sup_left (smul_le.2 fun _ _ _ => Submodule.smul_mem _ _) _ have : Jac * Ideal.span {x} ≤ J := by -- Need version 4 of Nakayama's lemma on Stacks by_contra H refine H (Ideal.mul_le_left.trans (le_of_le_smul_of_le_jacobson_bot (fg_span_singleton _) le_rfl (le_sup_right.trans_eq (this.eq_of_not_lt (hJ' _ ?_)).symm))) exact lt_of_le_of_ne le_sup_left fun h => H <| h.symm ▸ le_sup_right have : Ideal.span {x} * Jac ^ (n + 1) ≤ ⊥ := calc Ideal.span {x} * Jac ^ (n + 1) = Ideal.span {x} * Jac * Jac ^ n := by rw [pow_succ', ← mul_assoc] _ ≤ J * Jac ^ n := mul_le_mul (by rwa [mul_comm]) le_rfl _ = ⊥ := by simp [J] refine hxJ (mem_annihilator.2 fun y hy => (mem_bot R).1 ?_) refine this (mul_mem_mul (mem_span_singleton_self x) ?_) rwa [← hn (n + 1) (Nat.le_succ _)] section Localization variable (S : Submonoid R) (L : Type*) [CommRing L] [Algebra R L] [IsLocalization S L] /-- Localizing an artinian ring can only reduce the amount of elements. -/ theorem localization_surjective : Function.Surjective (algebraMap R L) := by intro r' obtain ⟨r₁, s, rfl⟩ := IsLocalization.mk'_surjective S r' -- TODO: can `rsuffices` be used to move the `exact` below before the proof of this `obtain`? obtain ⟨r₂, h⟩ : ∃ r : R, IsLocalization.mk' L 1 s = algebraMap R L r := by obtain ⟨n, r, hr⟩ := IsArtinian.exists_pow_succ_smul_dvd (s : R) (1 : R) use r rw [smul_eq_mul, smul_eq_mul, pow_succ, mul_assoc] at hr apply_fun algebraMap R L at hr simp only [map_mul] at hr rw [← IsLocalization.mk'_one (M := S) L, IsLocalization.mk'_eq_iff_eq, mul_one, Submonoid.coe_one, ← (IsLocalization.map_units L (s ^ n)).mul_left_cancel hr, map_mul] exact ⟨r₁ * r₂, by rw [IsLocalization.mk'_eq_mul_mk'_one, map_mul, h]⟩ theorem localization_artinian : IsArtinianRing L := (localization_surjective S L).isArtinianRing /-- `IsArtinianRing.localization_artinian` can't be made an instance, as it would make `S` + `R` into metavariables. However, this is safe. -/ instance : IsArtinianRing (Localization S) := localization_artinian S _ end Localization instance isMaximal_of_isPrime (p : Ideal R) [p.IsPrime] : p.IsMaximal := Ideal.Quotient.maximal_of_isField _ <| (MulEquiv.ofBijective _ ⟨IsFractionRing.injective (R ⧸ p) (FractionRing (R ⧸ p)), localization_surjective (nonZeroDivisors (R ⧸ p)) (FractionRing (R ⧸ p))⟩).isField _ <| Field.toIsField <| FractionRing (R ⧸ p) lemma isPrime_iff_isMaximal (p : Ideal R) : p.IsPrime ↔ p.IsMaximal := ⟨fun _ ↦ isMaximal_of_isPrime p, fun h ↦ h.isPrime⟩ variable (R) in lemma primeSpectrum_finite : {I : Ideal R | I.IsPrime}.Finite := by set Spec := {I : Ideal R | I.IsPrime} obtain ⟨_, ⟨s, rfl⟩, H⟩ := set_has_minimal (range (Finset.inf · Subtype.val : Finset Spec → Ideal R)) ⟨⊤, ∅, by simp⟩ refine Set.finite_def.2 ⟨s, fun p ↦ ?_⟩ classical obtain ⟨q, hq1, hq2⟩ := p.2.inf_le'.mp <| inf_eq_right.mp <| inf_le_right.eq_of_not_lt (H (p ⊓ s.inf Subtype.val) ⟨insert p s, by simp⟩) rwa [← Subtype.ext <| (@isMaximal_of_isPrime _ _ _ _ q.2).eq_of_le p.2.1 hq2] variable (R) /-- [Stacks Lemma 00J7](https://stacks.math.columbia.edu/tag/00J7) -/ lemma maximal_ideals_finite : {I : Ideal R | I.IsMaximal}.Finite := by simp_rw [← isPrime_iff_isMaximal] apply primeSpectrum_finite R @[local instance] lemma subtype_isMaximal_finite : Finite {I : Ideal R | I.IsMaximal} := (maximal_ideals_finite R).to_subtype /-- A temporary field instance on the quotients by maximal ideals. -/ @[local instance] noncomputable def fieldOfSubtypeIsMaximal (I : {I : Ideal R | I.IsMaximal}) : Field (R ⧸ I.1) := have := mem_setOf.mp I.2; Ideal.Quotient.field I.1 /-- The quotient of a commutative artinian ring by its nilradical is isomorphic to a finite product of fields, namely the quotients by the maximal ideals. -/ noncomputable def quotNilradicalEquivPi : R ⧸ nilradical R ≃+* ∀ I : {I : Ideal R | I.IsMaximal}, R ⧸ I.1 := .trans (Ideal.quotEquivOfEq <| ext fun x ↦ by simp_rw [mem_nilradical, nilpotent_iff_mem_prime, Submodule.mem_iInf, Subtype.forall, isPrime_iff_isMaximal, mem_setOf]) (Ideal.quotientInfRingEquivPiQuotient _ fun I J h ↦ Ideal.isCoprime_iff_sup_eq.mpr <| I.2.coprime_of_ne J.2 <| by rwa [Ne, Subtype.coe_inj]) /-- A reduced commutative artinian ring is isomorphic to a finite product of fields, namely the quotients by the maximal ideals. -/ noncomputable def equivPi [IsReduced R] : R ≃+* ∀ I : {I : Ideal R | I.IsMaximal}, R ⧸ I.1 := .trans (.symm <| .quotientBot R) <| .trans (Ideal.quotEquivOfEq (nilradical_eq_zero R).symm) (quotNilradicalEquivPi R) instance [IsReduced R] : DecompositionMonoid R := MulEquiv.decompositionMonoid (equivPi R) instance [IsReduced R] : DecompositionMonoid (Polynomial R) := MulEquiv.decompositionMonoid <| (Polynomial.mapEquiv <| equivPi R).trans (Polynomial.piEquiv _) theorem isSemisimpleRing_of_isReduced [IsReduced R] : IsSemisimpleRing R := (equivPi R).symm.isSemisimpleRing proof_wanted IsSemisimpleRing.isArtinianRing [IsSemisimpleRing R] : IsArtinianRing R end IsArtinianRing
RingTheory\Bezout.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.PrincipalIdealDomain /-! # Bézout rings A Bézout ring (Bezout ring) is a ring whose finitely generated ideals are principal. Notable examples include principal ideal rings, valuation rings, and the ring of algebraic integers. ## Main results - `IsBezout.iff_span_pair_isPrincipal`: It suffices to verify every `span {x, y}` is principal. - `IsBezout.TFAE`: For a Bézout domain, noetherian ↔ PID ↔ UFD ↔ ACCP -/ universe u v variable {R : Type u} [CommRing R] namespace IsBezout theorem iff_span_pair_isPrincipal : IsBezout R ↔ ∀ x y : R, (Ideal.span {x, y} : Ideal R).IsPrincipal := by classical constructor · intro H x y; infer_instance · intro H constructor apply Submodule.fg_induction · exact fun _ => ⟨⟨_, rfl⟩⟩ · rintro _ _ ⟨⟨x, rfl⟩⟩ ⟨⟨y, rfl⟩⟩; rw [← Submodule.span_insert]; exact H _ _ theorem _root_.Function.Surjective.isBezout {S : Type v} [CommRing S] (f : R →+* S) (hf : Function.Surjective f) [IsBezout R] : IsBezout S := by rw [iff_span_pair_isPrincipal] intro x y obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := hf x, hf y use f (gcd x y) trans Ideal.map f (Ideal.span {gcd x y}) · rw [span_gcd, Ideal.map_span, Set.image_insert_eq, Set.image_singleton] · rw [Ideal.map_span, Set.image_singleton]; rfl theorem TFAE [IsBezout R] [IsDomain R] : List.TFAE [IsNoetherianRing R, IsPrincipalIdealRing R, UniqueFactorizationMonoid R, WfDvdMonoid R] := by classical tfae_have 1 → 2 · intro H; exact ⟨fun I => isPrincipal_of_FG _ (IsNoetherian.noetherian _)⟩ tfae_have 2 → 3 · intro; infer_instance tfae_have 3 → 4 · intro; infer_instance tfae_have 4 → 1 · rintro ⟨h⟩ rw [isNoetherianRing_iff, isNoetherian_iff_fg_wellFounded] apply RelEmbedding.wellFounded _ h have : ∀ I : { J : Ideal R // J.FG }, ∃ x : R, (I : Ideal R) = Ideal.span {x} := fun ⟨I, hI⟩ => (IsBezout.isPrincipal_of_FG I hI).1 choose f hf using this exact { toFun := f inj' := fun x y e => by ext1; rw [hf, hf, e] map_rel_iff' := by dsimp intro a b rw [← Ideal.span_singleton_lt_span_singleton, ← hf, ← hf] rfl } tfae_finish end IsBezout
RingTheory\Binomial.lean
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Algebra.Polynomial.Smeval import Mathlib.Algebra.Order.Floor import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.RingTheory.Polynomial.Pochhammer import Mathlib.Tactic.FieldSimp /-! # Binomial rings In this file we introduce the binomial property as a mixin, and define the `multichoose` and `choose` functions generalizing binomial coefficients. According to our main reference [elliott2006binomial] (which lists many equivalent conditions), a binomial ring is a torsion-free commutative ring `R` such that for any `x ∈ R` and any `k ∈ ℕ`, the product `x(x-1)⋯(x-k+1)` is divisible by `k!`. The torsion-free condition lets us divide by `k!` unambiguously, so we get uniquely defined binomial coefficients. The defining condition doesn't require commutativity or associativity, and we get a theory with essentially the same power by replacing subtraction with addition. Thus, we consider any additive commutative monoid with a notion of natural number exponents in which multiplication by positive integers is injective, and demand that the evaluation of the ascending Pochhammer polynomial `X(X+1)⋯(X+(k-1))` at any element is divisible by `k!`. The quotient is called `multichoose r k`, because for `r` a natural number, it is the number of multisets of cardinality `k` taken from a type of cardinality `n`. ## Definitions * `BinomialRing`: a mixin class specifying a suitable `multichoose` function. * `Ring.multichoose`: the quotient of an ascending Pochhammer evaluation by a factorial. * `Ring.choose`: the quotient of a descending Pochhammer evaluation by a factorial. ## Results * Basic results with choose and multichoose, e.g., `choose_zero_right` * Relations between choose and multichoose, negated input. * Fundamental recursion: `choose_succ_succ` * Chu-Vandermonde identity: `add_choose_eq` * Pochhammer API ## References * [J. Elliott, *Binomial rings, integer-valued polynomials, and λ-rings*][elliott2006binomial] ## TODO Further results in Elliot's paper: * A CommRing is binomial if and only if it admits a λ-ring structure with trivial Adams operations. * The free commutative binomial ring on a set `X` is the ring of integer-valued polynomials in the variables `X`. (also, noncommutative version?) * Given a commutative binomial ring `A` and an `A`-algebra `B` that is complete with respect to an ideal `I`, formal exponentiation induces an `A`-module structure on the multiplicative subgroup `1 + I`. -/ section Multichoose open Function Polynomial /-- A binomial ring is a ring for which ascending Pochhammer evaluations are uniquely divisible by suitable factorials. We define this notion as a mixin for additive commutative monoids with natural number powers, but retain the ring name. We introduce `Ring.multichoose` as the uniquely defined quotient. -/ class BinomialRing (R : Type*) [AddCommMonoid R] [Pow R ℕ] where /-- Scalar multiplication by positive integers is injective -/ nsmul_right_injective (n : ℕ) (h : n ≠ 0) : Injective (n • · : R → R) /-- A multichoose function, giving the quotient of Pochhammer evaluations by factorials. -/ multichoose : R → ℕ → R /-- The `n`th ascending Pochhammer polynomial evaluated at any element is divisible by `n!` -/ factorial_nsmul_multichoose (r : R) (n : ℕ) : n.factorial • multichoose r n = (ascPochhammer ℕ n).smeval r namespace Ring variable {R : Type*} [AddCommMonoid R] [Pow R ℕ] [BinomialRing R] theorem nsmul_right_injective (n : ℕ) (h : n ≠ 0) : Injective (n • · : R → R) := BinomialRing.nsmul_right_injective n h /-- The multichoose function is the quotient of ascending Pochhammer evaluation by the corresponding factorial. When applied to natural numbers, `multichoose k n` describes choosing a multiset of `n` items from a type of size `k`, i.e., choosing with replacement. -/ def multichoose (r : R) (n : ℕ) : R := BinomialRing.multichoose r n @[simp] theorem multichoose_eq_multichoose (r : R) (n : ℕ) : BinomialRing.multichoose r n = multichoose r n := rfl theorem factorial_nsmul_multichoose_eq_ascPochhammer (r : R) (n : ℕ) : n.factorial • multichoose r n = (ascPochhammer ℕ n).smeval r := BinomialRing.factorial_nsmul_multichoose r n @[simp] theorem multichoose_zero_right' (r : R) : multichoose r 0 = r ^ 0 := by refine nsmul_right_injective (Nat.factorial 0) (Nat.factorial_ne_zero 0) ?_ simp only rw [factorial_nsmul_multichoose_eq_ascPochhammer, ascPochhammer_zero, smeval_one, Nat.factorial] theorem multichoose_zero_right [MulOneClass R] [NatPowAssoc R] (r : R) : multichoose r 0 = 1 := by rw [multichoose_zero_right', npow_zero] @[simp] theorem multichoose_one_right' (r : R) : multichoose r 1 = r ^ 1 := by refine nsmul_right_injective (Nat.factorial 1) (Nat.factorial_ne_zero 1) ?_ simp only rw [factorial_nsmul_multichoose_eq_ascPochhammer, ascPochhammer_one, smeval_X, Nat.factorial_one, one_smul] theorem multichoose_one_right [MulOneClass R] [NatPowAssoc R] (r : R) : multichoose r 1 = r := by rw [multichoose_one_right', npow_one] variable {R : Type*} [NonAssocSemiring R] [Pow R ℕ] [NatPowAssoc R] [BinomialRing R] @[simp] theorem multichoose_zero_succ (k : ℕ) : multichoose (0 : R) (k + 1) = 0 := by refine nsmul_right_injective (Nat.factorial (k + 1)) (Nat.factorial_ne_zero (k + 1)) ?_ simp only rw [factorial_nsmul_multichoose_eq_ascPochhammer, smul_zero, ascPochhammer_succ_left, smeval_X_mul, zero_mul] theorem ascPochhammer_succ_succ (r : R) (k : ℕ) : smeval (ascPochhammer ℕ (k + 1)) (r + 1) = Nat.factorial (k + 1) • multichoose (r + 1) k + smeval (ascPochhammer ℕ (k + 1)) r := by nth_rw 1 [ascPochhammer_succ_right, ascPochhammer_succ_left, mul_comm (ascPochhammer ℕ k)] simp only [smeval_mul, smeval_comp ℕ _ _ r, smeval_add, smeval_X] rw [Nat.factorial, mul_smul, factorial_nsmul_multichoose_eq_ascPochhammer] simp only [smeval_one, npow_one, npow_zero, one_smul] rw [← C_eq_natCast, smeval_C, npow_zero, add_assoc, add_mul, add_comm 1, @nsmul_one, add_mul] rw [← @nsmul_eq_mul, @add_rotate', @succ_nsmul, add_assoc] simp_all only [Nat.cast_id, nsmul_eq_mul, one_mul] theorem multichoose_succ_succ (r : R) (k : ℕ) : multichoose (r + 1) (k + 1) = multichoose r (k + 1) + multichoose (r + 1) k := by refine nsmul_right_injective (Nat.factorial (k + 1)) (Nat.factorial_ne_zero (k + 1)) ?_ simp only [factorial_nsmul_multichoose_eq_ascPochhammer, smul_add] rw [add_comm (smeval (ascPochhammer ℕ (k+1)) r), ascPochhammer_succ_succ r k] @[simp] theorem multichoose_one (k : ℕ) : multichoose (1 : R) k = 1 := by induction k with | zero => exact multichoose_zero_right 1 | succ n ih => rw [show (1 : R) = 0 + 1 by exact (@zero_add R _ 1).symm, multichoose_succ_succ, multichoose_zero_succ, zero_add, zero_add, ih] theorem multichoose_two (k : ℕ) : multichoose (2 : R) k = k + 1 := by induction k with | zero => rw [multichoose_zero_right, Nat.cast_zero, zero_add] | succ n ih => rw [one_add_one_eq_two.symm, multichoose_succ_succ, multichoose_one, one_add_one_eq_two, ih, Nat.cast_succ, add_comm] end Ring end Multichoose section Pochhammer namespace Polynomial @[simp] theorem ascPochhammer_smeval_cast (R : Type*) [Semiring R] {S : Type*} [NonAssocSemiring S] [Pow S ℕ] [Module R S] [IsScalarTower R S S] [NatPowAssoc S] (x : S) (n : ℕ) : (ascPochhammer R n).smeval x = (ascPochhammer ℕ n).smeval x := by induction' n with n hn · simp only [Nat.zero_eq, ascPochhammer_zero, smeval_one, one_smul] · simp only [ascPochhammer_succ_right, mul_add, smeval_add, smeval_mul_X, ← Nat.cast_comm] simp only [← C_eq_natCast, smeval_C_mul, hn, Nat.cast_smul_eq_nsmul R n] simp only [nsmul_eq_mul, Nat.cast_id] variable {R S : Type*} theorem ascPochhammer_smeval_eq_eval [Semiring R] (r : R) (n : ℕ) : (ascPochhammer ℕ n).smeval r = (ascPochhammer R n).eval r := by rw [eval_eq_smeval, ascPochhammer_smeval_cast R] variable [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] theorem descPochhammer_smeval_eq_ascPochhammer (r : R) (n : ℕ) : (descPochhammer ℤ n).smeval r = (ascPochhammer ℕ n).smeval (r - n + 1) := by induction n with | zero => simp only [descPochhammer_zero, ascPochhammer_zero, smeval_one, npow_zero] | succ n ih => rw [Nat.cast_succ, sub_add, add_sub_cancel_right, descPochhammer_succ_right, smeval_mul, ih, ascPochhammer_succ_left, X_mul, smeval_mul_X, smeval_comp, smeval_sub, ← C_eq_natCast, smeval_add, smeval_one, smeval_C] simp only [smeval_X, npow_one, npow_zero, zsmul_one, Int.cast_natCast, one_smul] theorem descPochhammer_smeval_eq_descFactorial (n k : ℕ) : (descPochhammer ℤ k).smeval (n : R) = n.descFactorial k := by induction k with | zero => rw [descPochhammer_zero, Nat.descFactorial_zero, Nat.cast_one, smeval_one, npow_zero, one_smul] | succ k ih => rw [descPochhammer_succ_right, Nat.descFactorial_succ, smeval_mul, ih, mul_comm, Nat.cast_mul, smeval_sub, smeval_X, smeval_natCast, npow_one, npow_zero, nsmul_one] by_cases h : n < k · simp only [Nat.descFactorial_eq_zero_iff_lt.mpr h, Nat.cast_zero, zero_mul] · rw [Nat.cast_sub <| not_lt.mp h] theorem ascPochhammer_smeval_neg_eq_descPochhammer (r : R) (k : ℕ) : (ascPochhammer ℕ k).smeval (-r) = (-1)^k * (descPochhammer ℤ k).smeval r := by induction k with | zero => simp only [ascPochhammer_zero, descPochhammer_zero, smeval_one, npow_zero, one_mul] | succ k ih => simp only [ascPochhammer_succ_right, smeval_mul, ih, descPochhammer_succ_right, sub_eq_add_neg] have h : (X + (k : ℕ[X])).smeval (-r) = - (X + (-k : ℤ[X])).smeval r := by simp only [smeval_add, smeval_X, npow_one, smeval_neg, smeval_natCast, npow_zero, nsmul_one] abel rw [h, ← neg_mul_comm, neg_mul_eq_neg_mul, ← mul_neg_one, ← neg_npow_assoc, npow_add, npow_one] end Polynomial end Pochhammer section Basic_Instances open Polynomial instance Nat.instBinomialRing : BinomialRing ℕ where nsmul_right_injective n hn r s hrs := Nat.eq_of_mul_eq_mul_left (Nat.pos_of_ne_zero hn) hrs multichoose n k := Nat.choose (n + k - 1) k factorial_nsmul_multichoose r n := by rw [smul_eq_mul, ← Nat.descFactorial_eq_factorial_mul_choose, ← eval_eq_smeval r (ascPochhammer ℕ n), ascPochhammer_nat_eq_descFactorial] /-- The multichoose function for integers. -/ def Int.multichoose (n : ℤ) (k : ℕ) : ℤ := match n with | ofNat n => (Nat.choose (n + k - 1) k : ℤ) | negSucc n => (-1) ^ k * Nat.choose (n + 1) k instance Int.instBinomialRing : BinomialRing ℤ where nsmul_right_injective n hn r s hrs := Int.eq_of_mul_eq_mul_left (Int.ofNat_ne_zero.mpr hn) hrs multichoose := Int.multichoose factorial_nsmul_multichoose r k := by rw [Int.multichoose, nsmul_eq_mul] cases r with | ofNat n => simp only [multichoose, nsmul_eq_mul, Int.ofNat_eq_coe, Int.ofNat_mul_out] rw [← Nat.descFactorial_eq_factorial_mul_choose, smeval_at_natCast, ← eval_eq_smeval n, ascPochhammer_nat_eq_descFactorial] | negSucc n => simp only [Int.multichoose, nsmul_eq_mul] rw [mul_comm, mul_assoc, ← Nat.cast_mul, mul_comm _ (k.factorial), ← Nat.descFactorial_eq_factorial_mul_choose, ← descPochhammer_smeval_eq_descFactorial, ← Int.neg_ofNat_succ, ascPochhammer_smeval_neg_eq_descPochhammer] noncomputable instance {R : Type*} [AddCommMonoid R] [Module ℚ≥0 R] [Pow R ℕ] : BinomialRing R where nsmul_right_injective n hn r s hrs := by rw [← one_smul ℚ≥0 r, ← one_smul ℚ≥0 s, show 1 = (n : ℚ≥0)⁻¹ • (n : ℚ≥0) by simp_all] simp_all only [smul_assoc, Nat.cast_smul_eq_nsmul] multichoose r n := (n.factorial : ℚ≥0)⁻¹ • Polynomial.smeval (ascPochhammer ℕ n) r factorial_nsmul_multichoose r n := by simp only [← smul_assoc] field_simp end Basic_Instances section Neg namespace Ring open Polynomial variable {R : Type*} [NonAssocRing R] [Pow R ℕ] [BinomialRing R] @[simp] theorem smeval_ascPochhammer_self_neg : ∀ n : ℕ, smeval (ascPochhammer ℕ n) (-n : ℤ) = (-1)^n * n.factorial | 0 => by rw [Nat.cast_zero, neg_zero, ascPochhammer_zero, Nat.factorial_zero, smeval_one, pow_zero, one_smul, pow_zero, Nat.cast_one, one_mul] | n + 1 => by rw [ascPochhammer_succ_left, smeval_X_mul, smeval_comp, smeval_add, smeval_X, smeval_one, pow_zero, pow_one, one_smul, Nat.cast_add, Nat.cast_one, neg_add_rev, neg_add_cancel_comm, smeval_ascPochhammer_self_neg n, ← mul_assoc, mul_comm _ ((-1) ^ n), show (-1 + -↑n = (-1 : ℤ) * (n + 1)) by omega, ← mul_assoc, pow_add, pow_one, Nat.factorial, Nat.cast_mul, ← mul_assoc, Nat.cast_succ] @[simp] theorem smeval_ascPochhammer_succ_neg (n : ℕ) : smeval (ascPochhammer ℕ (n + 1)) (-n : ℤ) = 0 := by rw [ascPochhammer_succ_right, smeval_mul, smeval_add, smeval_X, ← C_eq_natCast, smeval_C, pow_zero, pow_one, Nat.cast_id, nsmul_eq_mul, mul_one, add_left_neg, mul_zero] theorem smeval_ascPochhammer_neg_add (n : ℕ) : ∀ k : ℕ, smeval (ascPochhammer ℕ (n + k + 1)) (-n : ℤ) = 0 | 0 => by rw [add_zero, smeval_ascPochhammer_succ_neg] | k + 1 => by rw [ascPochhammer_succ_right, smeval_mul, ← add_assoc, smeval_ascPochhammer_neg_add n k, zero_mul] @[simp] theorem smeval_ascPochhammer_neg_of_lt {n k : ℕ} (h : n < k) : smeval (ascPochhammer ℕ k) (-n : ℤ) = 0 := by rw [show k = n + (k - n - 1) + 1 by omega, smeval_ascPochhammer_neg_add] theorem smeval_ascPochhammer_nat_cast {R} [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] (n k : ℕ) : smeval (ascPochhammer ℕ k) (n : R) = smeval (ascPochhammer ℕ k) n := by rw [smeval_at_natCast (ascPochhammer ℕ k) n] theorem multichoose_neg_self (n : ℕ) : multichoose (-n : ℤ) n = (-1)^n := by apply nsmul_right_injective _ (Nat.factorial_ne_zero _) on_goal 1 => simp only -- This closes both remaining goals at once. rw [factorial_nsmul_multichoose_eq_ascPochhammer, smeval_ascPochhammer_self_neg, nsmul_eq_mul, Nat.cast_comm] @[simp] theorem multichoose_neg_succ (n : ℕ) : multichoose (-n : ℤ) (n + 1) = 0 := by apply nsmul_right_injective _ (Nat.factorial_ne_zero _) on_goal 1 => simp only -- This closes both remaining goals at once. rw [factorial_nsmul_multichoose_eq_ascPochhammer, smeval_ascPochhammer_succ_neg, smul_zero] theorem multichoose_neg_add (n k : ℕ) : multichoose (-n : ℤ) (n + k + 1) = 0 := by refine nsmul_right_injective (Nat.factorial (n + k + 1)) (Nat.factorial_ne_zero (n + k + 1)) ?_ simp only rw [factorial_nsmul_multichoose_eq_ascPochhammer, smeval_ascPochhammer_neg_add, smul_zero] @[simp] theorem multichoose_neg_of_lt (n k : ℕ) (h : n < k) : multichoose (-n : ℤ) k = 0 := by refine nsmul_right_injective (Nat.factorial k) (Nat.factorial_ne_zero k) ?_ simp only rw [factorial_nsmul_multichoose_eq_ascPochhammer, smeval_ascPochhammer_neg_of_lt h, smul_zero] theorem multichoose_succ_neg_natCast [NatPowAssoc R] (n : ℕ) : multichoose (-n : R) (n + 1) = 0 := by refine nsmul_right_injective (Nat.factorial (n + 1)) (Nat.factorial_ne_zero (n + 1)) ?_ simp only [smul_zero] rw [factorial_nsmul_multichoose_eq_ascPochhammer, smeval_neg_nat, smeval_ascPochhammer_succ_neg n, Int.cast_zero] theorem smeval_ascPochhammer_int_ofNat {R} [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] (r : R) : ∀ n : ℕ, smeval (ascPochhammer ℤ n) r = smeval (ascPochhammer ℕ n) r | 0 => by simp only [ascPochhammer_zero, smeval_one] | n + 1 => by simp only [ascPochhammer_succ_right, smeval_mul] rw [smeval_ascPochhammer_int_ofNat r n] simp only [smeval_add, smeval_X, ← C_eq_natCast, smeval_C, natCast_zsmul, nsmul_eq_mul, Nat.cast_id] end Ring end Neg section Choose namespace Ring open Polynomial variable {R : Type*} section /-- The binomial coefficient `choose r n` generalizes the natural number `choose` function, interpreted in terms of choosing without replacement. -/ def choose [AddCommGroupWithOne R] [Pow R ℕ] [BinomialRing R] (r : R) (n : ℕ) : R := multichoose (r - n + 1) n variable [NonAssocRing R] [Pow R ℕ] [BinomialRing R] theorem descPochhammer_eq_factorial_smul_choose [NatPowAssoc R] (r : R) (n : ℕ) : (descPochhammer ℤ n).smeval r = n.factorial • choose r n := by rw [choose, factorial_nsmul_multichoose_eq_ascPochhammer, descPochhammer_eq_ascPochhammer, smeval_comp, add_comm_sub, smeval_add, smeval_X, npow_one] have h : smeval (1 - n : Polynomial ℤ) r = 1 - n := by rw [← C_eq_natCast, ← C_1, ← C_sub, smeval_C] simp only [npow_zero, zsmul_one, Int.cast_sub, Int.cast_one, Int.cast_natCast] rw [h, ascPochhammer_smeval_cast, add_comm_sub] theorem choose_natCast [NatPowAssoc R] (n k : ℕ) : choose (n : R) k = Nat.choose n k := by refine nsmul_right_injective (Nat.factorial k) (Nat.factorial_ne_zero k) ?_ simp only rw [← descPochhammer_eq_factorial_smul_choose, nsmul_eq_mul, ← Nat.cast_mul, ← Nat.descFactorial_eq_factorial_mul_choose, ← descPochhammer_smeval_eq_descFactorial] @[deprecated (since := "2024-04-17")] alias choose_nat_cast := choose_natCast @[simp] theorem choose_zero_right' (r : R) : choose r 0 = (r + 1) ^ 0 := by dsimp only [choose] refine nsmul_right_injective (Nat.factorial 0) (Nat.factorial_ne_zero 0) ?_ simp [factorial_nsmul_multichoose_eq_ascPochhammer] theorem choose_zero_right [NatPowAssoc R] (r : R) : choose r 0 = 1 := by rw [choose_zero_right', npow_zero] @[simp] theorem choose_zero_succ (R) [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] [BinomialRing R] (n : ℕ) : choose (0 : R) (n + 1) = 0 := by rw [choose, Nat.cast_succ, zero_sub, neg_add, neg_add_cancel_right, multichoose_succ_neg_natCast] theorem choose_zero_pos (R) [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] [BinomialRing R] {k : ℕ} (h_pos: 0 < k) : choose (0 : R) k = 0 := by rw [← Nat.succ_pred_eq_of_pos h_pos, choose_zero_succ] theorem choose_zero_ite (R) [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] [BinomialRing R] (k : ℕ) : choose (0 : R) k = if k = 0 then 1 else 0 := by split_ifs with hk · rw [hk, choose_zero_right] · rw [choose_zero_pos R <| Nat.pos_of_ne_zero hk] @[simp] theorem choose_one_right' (r : R) : choose r 1 = r ^ 1 := by rw [choose, Nat.cast_one, sub_add_cancel, multichoose_one_right'] theorem choose_one_right [NatPowAssoc R] (r : R) : choose r 1 = r := by rw [choose_one_right', npow_one] theorem descPochhammer_succ_succ_smeval {R} [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] (r : R) (k : ℕ) : smeval (descPochhammer ℤ (k + 1)) (r + 1) = (k + 1) • smeval (descPochhammer ℤ k) r + smeval (descPochhammer ℤ (k + 1)) r := by nth_rw 1 [descPochhammer_succ_left] rw [descPochhammer_succ_right, mul_comm (descPochhammer ℤ k)] simp only [smeval_comp ℤ _ _ (r + 1), smeval_sub, smeval_add, smeval_mul, smeval_X, smeval_one, npow_one, npow_zero, one_smul, add_sub_cancel_right, sub_mul, add_mul, add_smul, one_mul] rw [← C_eq_natCast, smeval_C, npow_zero, add_comm (k • smeval (descPochhammer ℤ k) r) _, add_assoc, add_comm (k • smeval (descPochhammer ℤ k) r) _, ← add_assoc, ← add_sub_assoc, nsmul_eq_mul, zsmul_one, Int.cast_natCast, sub_add_cancel, add_comm] theorem choose_succ_succ [NatPowAssoc R] (r : R) (k : ℕ) : choose (r + 1) (k + 1) = choose r k + choose r (k + 1) := by refine nsmul_right_injective (Nat.factorial (k + 1)) (Nat.factorial_ne_zero (k + 1)) ?_ simp only [smul_add, ← descPochhammer_eq_factorial_smul_choose] rw [Nat.factorial_succ, mul_smul, ← descPochhammer_eq_factorial_smul_choose r, descPochhammer_succ_succ_smeval r k] theorem choose_eq_nat_choose [NatPowAssoc R] (n k : ℕ) : choose (n : R) k = Nat.choose n k := by induction n generalizing k with | zero => cases k with | zero => rw [choose_zero_right, Nat.choose_zero_right, Nat.cast_one] | succ k => rw [Nat.cast_zero, choose_zero_succ, Nat.choose_zero_succ, Nat.cast_zero] | succ n ih => cases k with | zero => rw [choose_zero_right, Nat.choose_zero_right, Nat.cast_one] | succ k => rw [Nat.cast_succ, choose_succ_succ, ih, ih, Nat.choose_succ_succ, Nat.cast_add] theorem choose_smul_choose [NatPowAssoc R] (r : R) (n k : ℕ) (hkn : k ≤ n) : (Nat.choose n k) • choose r n = choose r k * choose (r - k) (n - k) := by refine nsmul_right_injective (Nat.factorial n) (Nat.factorial_ne_zero n) ?_ simp only rw [nsmul_left_comm, ← descPochhammer_eq_factorial_smul_choose, ← Nat.choose_mul_factorial_mul_factorial hkn, ← smul_mul_smul, ← descPochhammer_eq_factorial_smul_choose, mul_nsmul', ← descPochhammer_eq_factorial_smul_choose, smul_mul_assoc] nth_rw 2 [← Nat.sub_add_cancel hkn] rw [add_comm, ← descPochhammer_mul, smeval_mul, smeval_comp, smeval_sub, smeval_X, ← C_eq_natCast, smeval_C, npow_one, npow_zero, zsmul_one, Int.cast_natCast, nsmul_eq_mul] theorem choose_add_smul_choose [NatPowAssoc R] (r : R) (n k : ℕ) : (Nat.choose (n + k) k) • choose (r + k) (n + k) = choose (r + k) k * choose r n := by rw [choose_smul_choose (r + k) (n + k) k (Nat.le_add_left k n), Nat.add_sub_cancel, add_sub_cancel_right] end open Finset /-- Pochhammer version of Chu-Vandermonde identity -/ theorem descPochhammer_smeval_add [Ring R] {r s : R} (k : ℕ) (h: Commute r s) : (descPochhammer ℤ k).smeval (r + s) = ∑ ij ∈ antidiagonal k, Nat.choose k ij.1 * ((descPochhammer ℤ ij.1).smeval r * (descPochhammer ℤ ij.2).smeval s) := by induction k with | zero => simp | succ k ih => rw [descPochhammer_succ_right, mul_comm, smeval_mul, sum_antidiagonal_choose_succ_mul fun i j => ((descPochhammer ℤ i).smeval r * (descPochhammer ℤ j).smeval s), ← sum_add_distrib, smeval_sub, smeval_X, smeval_natCast, pow_zero, pow_one, ih, mul_sum] refine sum_congr rfl ?_ intro ij hij -- try to move descPochhammers to right, gather multipliers. have hdx : (descPochhammer ℤ ij.1).smeval r * (X - (ij.2 : ℤ[X])).smeval s = (X - (ij.2 : ℤ[X])).smeval s * (descPochhammer ℤ ij.1).smeval r := by refine (commute_iff_eq ((descPochhammer ℤ ij.1).smeval r) ((X - (ij.2 : ℤ[X])).smeval s)).mp ?_ exact smeval_commute ℤ (descPochhammer ℤ ij.1) (X - (ij.2 : ℤ[X])) h rw [descPochhammer_succ_right, mul_comm, smeval_mul, descPochhammer_succ_right, mul_comm, smeval_mul, ← mul_assoc ((descPochhammer ℤ ij.1).smeval r), hdx] simp only [mul_assoc _ ((descPochhammer ℤ ij.1).smeval r) _, ← mul_assoc _ _ (((descPochhammer ℤ ij.1).smeval r) * _)] have hl : (r + s - k • 1) * (k.choose ij.1) = (k.choose ij.1) * (X - (ij.2 : ℤ[X])).smeval s + ↑(k.choose ij.2) * (X - (ij.1 : ℤ[X])).smeval r := by simp only [smeval_sub, smeval_X, pow_one, smeval_natCast, pow_zero, ← mul_sub] rw [← Nat.choose_symm_of_eq_add (List.Nat.mem_antidiagonal.mp hij).symm, (List.Nat.mem_antidiagonal.mp hij).symm, ← mul_add, Nat.cast_comm, add_smul] abel_nf rw [hl, ← add_mul] /-- The Chu-Vandermonde identity for binomial rings -/ theorem add_choose_eq [Ring R] [BinomialRing R] {r s : R} (k : ℕ) (h : Commute r s) : choose (r + s) k = ∑ ij ∈ antidiagonal k, choose r ij.1 * choose s ij.2 := by refine nsmul_right_injective (Nat.factorial k) (Nat.factorial_ne_zero k) ?_ simp only rw [← descPochhammer_eq_factorial_smul_choose, smul_sum, descPochhammer_smeval_add _ h] refine sum_congr rfl ?_ intro x hx rw [← Nat.choose_mul_factorial_mul_factorial (antidiagonal.fst_le hx), tsub_eq_of_eq_add_rev (List.Nat.mem_antidiagonal.mp hx).symm, mul_assoc, nsmul_eq_mul, Nat.cast_mul, Nat.cast_mul, ← mul_assoc _ (x.1.factorial : R), mul_assoc _ (x.2.factorial : R), ← mul_assoc (x.2.factorial : R), Nat.cast_commute x.2.factorial, mul_assoc _ (x.2.factorial : R), ← nsmul_eq_mul x.2.factorial] simp [mul_assoc, descPochhammer_eq_factorial_smul_choose] end Ring end Choose
RingTheory\ChainOfDivisors.lean
/- Copyright (c) 2021 Paul Lezeau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.Algebra.IsPrimePow import Mathlib.Algebra.Squarefree.Basic import Mathlib.Order.Hom.Bounded import Mathlib.Algebra.GCDMonoid.Basic /-! # Chains of divisors The results in this file show that in the monoid `Associates M` of a `UniqueFactorizationMonoid` `M`, an element `a` is an n-th prime power iff its set of divisors is a strictly increasing chain of length `n + 1`, meaning that we can find a strictly increasing bijection between `Fin (n + 1)` and the set of factors of `a`. ## Main results - `DivisorChain.exists_chain_of_prime_pow` : existence of a chain for prime powers. - `DivisorChain.is_prime_pow_of_has_chain` : elements that have a chain are prime powers. - `multiplicity_prime_eq_multiplicity_image_by_factor_orderIso` : if there is a monotone bijection `d` between the set of factors of `a : Associates M` and the set of factors of `b : Associates N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b`. - `multiplicity_eq_multiplicity_factor_dvd_iso_of_mem_normalizedFactors` : if there is a bijection between the set of factors of `a : M` and `b : N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b` ## TODO - Create a structure for chains of divisors. - Simplify proof of `mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors` using `mem_normalizedFactors_factor_order_iso_of_mem_normalizedFactors` or vice versa. -/ variable {M : Type*} [CancelCommMonoidWithZero M] theorem Associates.isAtom_iff {p : Associates M} (h₁ : p ≠ 0) : IsAtom p ↔ Irreducible p := ⟨fun hp => ⟨by simpa only [Associates.isUnit_iff_eq_one] using hp.1, fun a b h => (hp.le_iff.mp ⟨_, h⟩).casesOn (fun ha => Or.inl (a.isUnit_iff_eq_one.mpr ha)) fun ha => Or.inr (show IsUnit b by rw [ha] at h apply isUnit_of_associated_mul (show Associated (p * b) p by conv_rhs => rw [h]) h₁)⟩, fun hp => ⟨by simpa only [Associates.isUnit_iff_eq_one, Associates.bot_eq_one] using hp.1, fun b ⟨⟨a, hab⟩, hb⟩ => (hp.isUnit_or_isUnit hab).casesOn (fun hb => show b = ⊥ by rwa [Associates.isUnit_iff_eq_one, ← Associates.bot_eq_one] at hb) fun ha => absurd (show p ∣ b from ⟨(ha.unit⁻¹ : Units _), by rw [hab, mul_assoc, IsUnit.mul_val_inv ha, mul_one]⟩) hb⟩⟩ open UniqueFactorizationMonoid multiplicity Irreducible Associates namespace DivisorChain theorem exists_chain_of_prime_pow {p : Associates M} {n : ℕ} (hn : n ≠ 0) (hp : Prime p) : ∃ c : Fin (n + 1) → Associates M, c 1 = p ∧ StrictMono c ∧ ∀ {r : Associates M}, r ≤ p ^ n ↔ ∃ i, r = c i := by refine ⟨fun i => p ^ (i : ℕ), ?_, fun n m h => ?_, @fun y => ⟨fun h => ?_, ?_⟩⟩ · dsimp only rw [Fin.val_one', Nat.mod_eq_of_lt, pow_one] exact Nat.lt_succ_of_le (Nat.one_le_iff_ne_zero.mpr hn) · exact Associates.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero n hp.ne_zero, p ^ (m - n : ℕ), not_isUnit_of_not_isUnit_dvd hp.not_unit (dvd_pow dvd_rfl (Nat.sub_pos_of_lt h).ne'), (pow_mul_pow_sub p h.le).symm⟩ · obtain ⟨i, i_le, hi⟩ := (dvd_prime_pow hp n).1 h rw [associated_iff_eq] at hi exact ⟨⟨i, Nat.lt_succ_of_le i_le⟩, hi⟩ · rintro ⟨i, rfl⟩ exact ⟨p ^ (n - i : ℕ), (pow_mul_pow_sub p (Nat.succ_le_succ_iff.mp i.2)).symm⟩ theorem element_of_chain_not_isUnit_of_index_ne_zero {n : ℕ} {i : Fin (n + 1)} (i_pos : i ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) : ¬IsUnit (c i) := DvdNotUnit.not_unit (Associates.dvdNotUnit_iff_lt.2 (h₁ <| show (0 : Fin (n + 1)) < i from Fin.pos_iff_ne_zero.mpr i_pos)) theorem first_of_chain_isUnit {q : Associates M} {n : ℕ} {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) : IsUnit (c 0) := by obtain ⟨i, hr⟩ := h₂.mp Associates.one_le rw [Associates.isUnit_iff_eq_one, ← Associates.le_one_iff, hr] exact h₁.monotone (Fin.zero_le i) /-- The second element of a chain is irreducible. -/ theorem second_of_chain_is_irreducible {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : Irreducible (c 1) := by cases' n with n; · contradiction refine (Associates.isAtom_iff (ne_zero_of_dvd_ne_zero hq (h₂.2 ⟨1, rfl⟩))).mp ⟨?_, fun b hb => ?_⟩ · exact ne_bot_of_gt (h₁ (show (0 : Fin (n + 2)) < 1 from Fin.one_pos)) obtain ⟨⟨i, hi⟩, rfl⟩ := h₂.1 (hb.le.trans (h₂.2 ⟨1, rfl⟩)) cases i · exact (Associates.isUnit_iff_eq_one _).mp (first_of_chain_isUnit h₁ @h₂) · simpa [Fin.lt_iff_val_lt_val] using h₁.lt_iff_lt.mp hb theorem eq_second_of_chain_of_prime_dvd {p q r : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hp : Prime p) (hr : r ∣ q) (hp' : p ∣ r) : p = c 1 := by cases' n with n · contradiction obtain ⟨i, rfl⟩ := h₂.1 (dvd_trans hp' hr) refine congr_arg c (eq_of_ge_of_not_gt ?_ fun hi => ?_) · rw [Fin.le_iff_val_le_val, Fin.val_one, Nat.succ_le_iff, ← Fin.val_zero' (n.succ + 1), ← Fin.lt_iff_val_lt_val, Fin.pos_iff_ne_zero] rintro rfl exact hp.not_unit (first_of_chain_isUnit h₁ @h₂) obtain rfl | ⟨j, rfl⟩ := i.eq_zero_or_eq_succ · cases hi refine not_irreducible_of_not_unit_dvdNotUnit (DvdNotUnit.not_unit (Associates.dvdNotUnit_iff_lt.2 (h₁ (show (0 : Fin (n + 2)) < j from ?_)))) ?_ hp.irreducible · simpa [Fin.succ_lt_succ_iff, Fin.lt_iff_val_lt_val] using hi · refine Associates.dvdNotUnit_iff_lt.2 (h₁ ?_) simpa only [Fin.coe_eq_castSucc] using Fin.lt_succ theorem card_subset_divisors_le_length_of_chain {q : Associates M} {n : ℕ} {c : Fin (n + 1) → Associates M} (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) {m : Finset (Associates M)} (hm : ∀ r, r ∈ m → r ≤ q) : m.card ≤ n + 1 := by classical have mem_image : ∀ r : Associates M, r ≤ q → r ∈ Finset.univ.image c := by intro r hr obtain ⟨i, hi⟩ := h₂.1 hr exact Finset.mem_image.2 ⟨i, Finset.mem_univ _, hi.symm⟩ rw [← Finset.card_fin (n + 1)] exact (Finset.card_le_card fun x hx => mem_image x <| hm x hx).trans Finset.card_image_le variable [UniqueFactorizationMonoid M] theorem element_of_chain_eq_pow_second_of_chain {q r : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hr : r ∣ q) (hq : q ≠ 0) : ∃ i : Fin (n + 1), r = c 1 ^ (i : ℕ) := by classical let i := Multiset.card (normalizedFactors r) have hi : normalizedFactors r = Multiset.replicate i (c 1) := by apply Multiset.eq_replicate_of_mem intro b hb refine eq_second_of_chain_of_prime_dvd hn h₁ (@fun r' => h₂) (prime_of_normalized_factor b hb) hr (dvd_of_mem_normalizedFactors hb) have H : r = c 1 ^ i := by have := UniqueFactorizationMonoid.normalizedFactors_prod (ne_zero_of_dvd_ne_zero hq hr) rw [associated_iff_eq, hi, Multiset.prod_replicate] at this rw [this] refine ⟨⟨i, ?_⟩, H⟩ have : (Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ)).card = i + 1 := by conv_rhs => rw [← Finset.card_fin (i + 1)] cases n · contradiction rw [Finset.card_image_iff] refine Set.injOn_of_injective (fun m m' h => Fin.ext ?_) refine pow_injective_of_not_unit (element_of_chain_not_isUnit_of_index_ne_zero (by simp) h₁) ?_ h exact Irreducible.ne_zero (second_of_chain_is_irreducible hn h₁ (@h₂) hq) suffices H' : ∀ r ∈ Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ), r ≤ q by simp only [← Nat.succ_le_iff, Nat.succ_eq_add_one, ← this] apply card_subset_divisors_le_length_of_chain (@h₂) H' simp only [Finset.mem_image] rintro r ⟨a, _, rfl⟩ refine dvd_trans ?_ hr use c 1 ^ (i - (a : ℕ)) rw [pow_mul_pow_sub (c 1)] · exact H · exact Nat.succ_le_succ_iff.mp a.2 theorem eq_pow_second_of_chain_of_has_chain {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : q = c 1 ^ n := by classical obtain ⟨i, hi'⟩ := element_of_chain_eq_pow_second_of_chain hn h₁ (@fun r => h₂) (dvd_refl q) hq convert hi' refine (Nat.lt_succ_iff.1 i.prop).antisymm' (Nat.le_of_succ_le_succ ?_) calc n + 1 = (Finset.univ : Finset (Fin (n + 1))).card := (Finset.card_fin _).symm _ = (Finset.univ.image c).card := (Finset.card_image_iff.mpr h₁.injective.injOn).symm _ ≤ (Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ)).card := (Finset.card_le_card ?_) _ ≤ (Finset.univ : Finset (Fin (i + 1))).card := Finset.card_image_le _ = i + 1 := Finset.card_fin _ intro r hr obtain ⟨j, -, rfl⟩ := Finset.mem_image.1 hr have := h₂.2 ⟨j, rfl⟩ rw [hi'] at this have h := (dvd_prime_pow (show Prime (c 1) from ?_) i).1 this · rcases h with ⟨u, hu, hu'⟩ refine Finset.mem_image.mpr ⟨u, Finset.mem_univ _, ?_⟩ rw [associated_iff_eq] at hu' rw [Fin.val_cast_of_lt (Nat.lt_succ_of_le hu), hu'] · rw [← irreducible_iff_prime] exact second_of_chain_is_irreducible hn h₁ (@h₂) hq theorem isPrimePow_of_has_chain {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : IsPrimePow q := ⟨c 1, n, irreducible_iff_prime.mp (second_of_chain_is_irreducible hn h₁ (@h₂) hq), zero_lt_iff.mpr hn, (eq_pow_second_of_chain_of_has_chain hn h₁ (@h₂) hq).symm⟩ end DivisorChain variable {N : Type*} [CancelCommMonoidWithZero N] theorem factor_orderIso_map_one_eq_bot {m : Associates M} {n : Associates N} (d : { l : Associates M // l ≤ m } ≃o { l : Associates N // l ≤ n }) : (d ⟨1, one_dvd m⟩ : Associates N) = 1 := by letI : OrderBot { l : Associates M // l ≤ m } := Subtype.orderBot bot_le letI : OrderBot { l : Associates N // l ≤ n } := Subtype.orderBot bot_le simp only [← Associates.bot_eq_one, Subtype.mk_bot, bot_le, Subtype.coe_eq_bot_iff] letI : BotHomClass ({ l // l ≤ m } ≃o { l // l ≤ n }) _ _ := OrderIsoClass.toBotHomClass exact map_bot d theorem coe_factor_orderIso_map_eq_one_iff {m u : Associates M} {n : Associates N} (hu' : u ≤ m) (d : Set.Iic m ≃o Set.Iic n) : (d ⟨u, hu'⟩ : Associates N) = 1 ↔ u = 1 := ⟨fun hu => by rw [show u = (d.symm ⟨d ⟨u, hu'⟩, (d ⟨u, hu'⟩).prop⟩) by simp only [Subtype.coe_eta, OrderIso.symm_apply_apply, Subtype.coe_mk]] conv_rhs => rw [← factor_orderIso_map_one_eq_bot d.symm] congr, fun hu => by simp_rw [hu] conv_rhs => rw [← factor_orderIso_map_one_eq_bot d] rfl⟩ section variable [UniqueFactorizationMonoid N] [UniqueFactorizationMonoid M] open DivisorChain theorem pow_image_of_prime_by_factor_orderIso_dvd {m p : Associates M} {n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) {s : ℕ} (hs' : p ^ s ≤ m) : (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) ^ s ≤ n := by by_cases hs : s = 0 · simp [← Associates.bot_eq_one, hs] suffices (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) ^ s = (d ⟨p ^ s, hs'⟩) by rw [this] apply Subtype.prop (d ⟨p ^ s, hs'⟩) obtain ⟨c₁, rfl, hc₁', hc₁''⟩ := exists_chain_of_prime_pow hs (prime_of_normalized_factor p hp) let c₂ : Fin (s + 1) → Associates N := fun t => d ⟨c₁ t, le_trans (hc₁''.2 ⟨t, by simp⟩) hs'⟩ have c₂_def : ∀ t, c₂ t = d ⟨c₁ t, _⟩ := fun t => rfl rw [← c₂_def] refine (eq_pow_second_of_chain_of_has_chain hs (fun t u h => ?_) (@fun r => ⟨@fun hr => ?_, ?_⟩) ?_).symm · rw [c₂_def, c₂_def, Subtype.coe_lt_coe, d.lt_iff_lt, Subtype.mk_lt_mk, hc₁'.lt_iff_lt] exact h · have : r ≤ n := hr.trans (d ⟨c₁ 1 ^ s, _⟩).2 suffices d.symm ⟨r, this⟩ ≤ ⟨c₁ 1 ^ s, hs'⟩ by obtain ⟨i, hi⟩ := hc₁''.1 this use i simp only [c₂_def, ← hi, d.apply_symm_apply, Subtype.coe_eta, Subtype.coe_mk] conv_rhs => rw [← d.symm_apply_apply ⟨c₁ 1 ^ s, hs'⟩] rw [d.symm.le_iff_le] simpa only [← Subtype.coe_le_coe, Subtype.coe_mk] using hr · rintro ⟨i, hr⟩ rw [hr, c₂_def, Subtype.coe_le_coe, d.le_iff_le] simpa [Subtype.mk_le_mk] using hc₁''.2 ⟨i, rfl⟩ exact ne_zero_of_dvd_ne_zero hn (Subtype.prop (d ⟨c₁ 1 ^ s, _⟩)) theorem map_prime_of_factor_orderIso {m p : Associates M} {n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) : Prime (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) := by rw [← irreducible_iff_prime] refine (Associates.isAtom_iff <| ne_zero_of_dvd_ne_zero hn (d ⟨p, _⟩).prop).mp ⟨?_, fun b hb => ?_⟩ · rw [Ne, ← Associates.isUnit_iff_eq_bot, Associates.isUnit_iff_eq_one, coe_factor_orderIso_map_eq_one_iff _ d] rintro rfl exact (prime_of_normalized_factor 1 hp).not_unit isUnit_one · obtain ⟨x, hx⟩ := d.surjective ⟨b, le_trans (le_of_lt hb) (d ⟨p, dvd_of_mem_normalizedFactors hp⟩).prop⟩ rw [← Subtype.coe_mk b _, ← hx] at hb letI : OrderBot { l : Associates M // l ≤ m } := Subtype.orderBot bot_le letI : OrderBot { l : Associates N // l ≤ n } := Subtype.orderBot bot_le suffices x = ⊥ by rw [this, OrderIso.map_bot d] at hx refine (Subtype.mk_eq_bot_iff ?_ _).mp hx.symm simp obtain ⟨a, ha⟩ := x rw [Subtype.mk_eq_bot_iff] · exact ((Associates.isAtom_iff <| Prime.ne_zero <| prime_of_normalized_factor p hp).mpr <| irreducible_of_normalized_factor p hp).right a (Subtype.mk_lt_mk.mp <| d.lt_iff_lt.mp hb) simp theorem mem_normalizedFactors_factor_orderIso_of_mem_normalizedFactors {m p : Associates M} {n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) : (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) ∈ normalizedFactors n := by obtain ⟨q, hq, hq'⟩ := exists_mem_normalizedFactors_of_dvd hn (map_prime_of_factor_orderIso hn hp d).irreducible (d ⟨p, dvd_of_mem_normalizedFactors hp⟩).prop rw [associated_iff_eq] at hq' rwa [hq'] variable [DecidableRel ((· ∣ ·) : M → M → Prop)] [DecidableRel ((· ∣ ·) : N → N → Prop)] theorem multiplicity_prime_le_multiplicity_image_by_factor_orderIso {m p : Associates M} {n : Associates N} (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) : multiplicity p m ≤ multiplicity (↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩)) n := by by_cases hn : n = 0 · simp [hn] by_cases hm : m = 0 · simp [hm] at hp rw [← PartENat.natCast_get (finite_iff_dom.1 <| finite_prime_left (prime_of_normalized_factor p hp) hm), ← pow_dvd_iff_le_multiplicity] exact pow_image_of_prime_by_factor_orderIso_dvd hn hp d (pow_multiplicity_dvd _) theorem multiplicity_prime_eq_multiplicity_image_by_factor_orderIso {m p : Associates M} {n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) : multiplicity p m = multiplicity (↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩)) n := by refine le_antisymm (multiplicity_prime_le_multiplicity_image_by_factor_orderIso hp d) ?_ suffices multiplicity (↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩)) n ≤ multiplicity (↑(d.symm (d ⟨p, dvd_of_mem_normalizedFactors hp⟩))) m by rw [d.symm_apply_apply ⟨p, dvd_of_mem_normalizedFactors hp⟩, Subtype.coe_mk] at this exact this letI := Classical.decEq (Associates N) simpa only [Subtype.coe_eta] using multiplicity_prime_le_multiplicity_image_by_factor_orderIso (mem_normalizedFactors_factor_orderIso_of_mem_normalizedFactors hn hp d) d.symm end variable [Unique Mˣ] [Unique Nˣ] /-- The order isomorphism between the factors of `mk m` and the factors of `mk n` induced by a bijection between the factors of `m` and the factors of `n` that preserves `∣`. -/ @[simps] def mkFactorOrderIsoOfFactorDvdEquiv {m : M} {n : N} {d : { l : M // l ∣ m } ≃ { l : N // l ∣ n }} (hd : ∀ l l', (d l : N) ∣ d l' ↔ (l : M) ∣ (l' : M)) : Set.Iic (Associates.mk m) ≃o Set.Iic (Associates.mk n) where toFun l := ⟨Associates.mk (d ⟨associatesEquivOfUniqueUnits ↑l, by obtain ⟨x, hx⟩ := l rw [Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, out_dvd_iff] exact hx⟩), mk_le_mk_iff_dvd.mpr (Subtype.prop (d ⟨associatesEquivOfUniqueUnits ↑l, _⟩))⟩ invFun l := ⟨Associates.mk (d.symm ⟨associatesEquivOfUniqueUnits ↑l, by obtain ⟨x, hx⟩ := l rw [Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, out_dvd_iff] exact hx⟩), mk_le_mk_iff_dvd.mpr (Subtype.prop (d.symm ⟨associatesEquivOfUniqueUnits ↑l, _⟩))⟩ left_inv := fun ⟨l, hl⟩ => by simp only [Subtype.coe_eta, Equiv.symm_apply_apply, Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, mk_out, out_mk, normalize_eq] right_inv := fun ⟨l, hl⟩ => by simp only [Subtype.coe_eta, Equiv.apply_symm_apply, Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq, mk_out] map_rel_iff' := by rintro ⟨a, ha⟩ ⟨b, hb⟩ simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Associates.mk_le_mk_iff_dvd, hd, Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, out_dvd_iff, mk_out] variable [UniqueFactorizationMonoid M] [UniqueFactorizationMonoid N] theorem mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors {m p : M} {n : N} (hm : m ≠ 0) (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) {d : { l : M // l ∣ m } ≃ { l : N // l ∣ n }} (hd : ∀ l l', (d l : N) ∣ d l' ↔ (l : M) ∣ (l' : M)) : ↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩) ∈ normalizedFactors n := by suffices Prime (d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by simp [dvd_of_mem_normalizedFactors hp]⟩ : N) by simp only [associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq, associatesEquivOfUniqueUnits_symm_apply] at this obtain ⟨q, hq, hq'⟩ := exists_mem_normalizedFactors_of_dvd hn this.irreducible (d ⟨p, by apply dvd_of_mem_normalizedFactors; convert hp⟩).prop rwa [associated_iff_eq.mp hq'] have : Associates.mk (d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by simp only [dvd_of_mem_normalizedFactors hp, associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq, associatesEquivOfUniqueUnits_symm_apply]⟩ : N) = ↑(mkFactorOrderIsoOfFactorDvdEquiv hd ⟨associatesEquivOfUniqueUnits.symm p, by simp only [associatesEquivOfUniqueUnits_symm_apply] exact mk_dvd_mk.mpr (dvd_of_mem_normalizedFactors hp)⟩) := by rw [mkFactorOrderIsoOfFactorDvdEquiv_apply_coe] rw [← Associates.prime_mk, this] letI := Classical.decEq (Associates M) refine map_prime_of_factor_orderIso (mk_ne_zero.mpr hn) ?_ _ obtain ⟨q, hq, hq'⟩ := exists_mem_normalizedFactors_of_dvd (mk_ne_zero.mpr hm) (prime_mk.mpr (prime_of_normalized_factor p (by convert hp))).irreducible (mk_le_mk_of_dvd (dvd_of_mem_normalizedFactors hp)) simpa only [associated_iff_eq.mp hq', associatesEquivOfUniqueUnits_symm_apply] using hq variable [DecidableRel ((· ∣ ·) : M → M → Prop)] [DecidableRel ((· ∣ ·) : N → N → Prop)] theorem multiplicity_factor_dvd_iso_eq_multiplicity_of_mem_normalizedFactors {m p : M} {n : N} (hm : m ≠ 0) (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) {d : { l : M // l ∣ m } ≃ { l : N // l ∣ n }} (hd : ∀ l l', (d l : N) ∣ d l' ↔ (l : M) ∣ l') : multiplicity (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : N) n = multiplicity p m := by apply Eq.symm suffices multiplicity (Associates.mk p) (Associates.mk m) = multiplicity (Associates.mk ↑(d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by simp [dvd_of_mem_normalizedFactors hp]⟩)) (Associates.mk n) by simpa only [multiplicity_mk_eq_multiplicity, associatesEquivOfUniqueUnits_symm_apply, associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq] using this have : Associates.mk (d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by simp only [dvd_of_mem_normalizedFactors hp, associatesEquivOfUniqueUnits_symm_apply, associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq]⟩ : N) = ↑(mkFactorOrderIsoOfFactorDvdEquiv hd ⟨associatesEquivOfUniqueUnits.symm p, by rw [associatesEquivOfUniqueUnits_symm_apply] exact mk_le_mk_of_dvd (dvd_of_mem_normalizedFactors hp)⟩) := by rw [mkFactorOrderIsoOfFactorDvdEquiv_apply_coe] rw [this] refine multiplicity_prime_eq_multiplicity_image_by_factor_orderIso (mk_ne_zero.mpr hn) ?_ (mkFactorOrderIsoOfFactorDvdEquiv hd) obtain ⟨q, hq, hq'⟩ := exists_mem_normalizedFactors_of_dvd (mk_ne_zero.mpr hm) (prime_mk.mpr (prime_of_normalized_factor p hp)).irreducible (mk_le_mk_of_dvd (dvd_of_mem_normalizedFactors hp)) rwa [associated_iff_eq.mp hq']
RingTheory\ClassGroup.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.GroupTheory.QuotientGroup import Mathlib.RingTheory.DedekindDomain.Ideal /-! # The ideal class group This file defines the ideal class group `ClassGroup R` of fractional ideals of `R` inside its field of fractions. ## Main definitions - `toPrincipalIdeal` sends an invertible `x : K` to an invertible fractional ideal - `ClassGroup` is the quotient of invertible fractional ideals modulo `toPrincipalIdeal.range` - `ClassGroup.mk0` sends a nonzero integral ideal in a Dedekind domain to its class ## Main results - `ClassGroup.mk0_eq_mk0_iff` shows the equivalence with the "classical" definition, where `I ~ J` iff `x I = y J` for `x y ≠ (0 : R)` ## Implementation details The definition of `ClassGroup R` involves `FractionRing R`. However, the API should be completely identical no matter the choice of field of fractions for `R`. -/ variable {R K L : Type*} [CommRing R] variable [Field K] [Field L] [DecidableEq L] variable [Algebra R K] [IsFractionRing R K] variable [Algebra K L] [FiniteDimensional K L] variable [Algebra R L] [IsScalarTower R K L] open scoped nonZeroDivisors open IsLocalization IsFractionRing FractionalIdeal Units section variable (R K) /-- `toPrincipalIdeal R K x` sends `x ≠ 0 : K` to the fractional `R`-ideal generated by `x` -/ irreducible_def toPrincipalIdeal : Kˣ →* (FractionalIdeal R⁰ K)ˣ := { toFun := fun x => ⟨spanSingleton _ x, spanSingleton _ x⁻¹, by simp only [spanSingleton_one, Units.mul_inv', spanSingleton_mul_spanSingleton], by simp only [spanSingleton_one, Units.inv_mul', spanSingleton_mul_spanSingleton]⟩ map_mul' := fun x y => ext (by simp only [Units.val_mk, Units.val_mul, spanSingleton_mul_spanSingleton]) map_one' := ext (by simp only [spanSingleton_one, Units.val_mk, Units.val_one]) } variable {R K} @[simp] theorem coe_toPrincipalIdeal (x : Kˣ) : (toPrincipalIdeal R K x : FractionalIdeal R⁰ K) = spanSingleton _ (x : K) := by simp only [toPrincipalIdeal]; rfl @[simp] theorem toPrincipalIdeal_eq_iff {I : (FractionalIdeal R⁰ K)ˣ} {x : Kˣ} : toPrincipalIdeal R K x = I ↔ spanSingleton R⁰ (x : K) = I := by simp only [toPrincipalIdeal]; exact Units.ext_iff theorem mem_principal_ideals_iff {I : (FractionalIdeal R⁰ K)ˣ} : I ∈ (toPrincipalIdeal R K).range ↔ ∃ x : K, spanSingleton R⁰ x = I := by simp only [MonoidHom.mem_range, toPrincipalIdeal_eq_iff] constructor <;> rintro ⟨x, hx⟩ · exact ⟨x, hx⟩ · refine ⟨Units.mk0 x ?_, hx⟩ rintro rfl simp [I.ne_zero.symm] at hx instance PrincipalIdeals.normal : (toPrincipalIdeal R K).range.Normal := Subgroup.normal_of_comm _ end variable (R) variable [IsDomain R] /-- The ideal class group of `R` is the group of invertible fractional ideals modulo the principal ideals. -/ def ClassGroup := (FractionalIdeal R⁰ (FractionRing R))ˣ ⧸ (toPrincipalIdeal R (FractionRing R)).range noncomputable instance : CommGroup (ClassGroup R) := QuotientGroup.Quotient.commGroup (toPrincipalIdeal R (FractionRing R)).range noncomputable instance : Inhabited (ClassGroup R) := ⟨1⟩ variable {R} /-- Send a nonzero fractional ideal to the corresponding class in the class group. -/ noncomputable def ClassGroup.mk : (FractionalIdeal R⁰ K)ˣ →* ClassGroup R := (QuotientGroup.mk' (toPrincipalIdeal R (FractionRing R)).range).comp (Units.map (FractionalIdeal.canonicalEquiv R⁰ K (FractionRing R))) -- Can't be `@[simp]` because it can't figure out the quotient relation. theorem ClassGroup.Quot_mk_eq_mk (I : (FractionalIdeal R⁰ (FractionRing R))ˣ) : Quot.mk _ I = ClassGroup.mk I := by rw [ClassGroup.mk, canonicalEquiv_self, RingEquiv.coe_monoidHom_refl, Units.map_id] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [MonoidHom.comp_apply] rw [MonoidHom.id_apply, QuotientGroup.mk'_apply] rfl theorem ClassGroup.mk_eq_mk {I J : (FractionalIdeal R⁰ <| FractionRing R)ˣ} : ClassGroup.mk I = ClassGroup.mk J ↔ ∃ x : (FractionRing R)ˣ, I * toPrincipalIdeal R (FractionRing R) x = J := by erw [QuotientGroup.mk'_eq_mk', canonicalEquiv_self, Units.map_id, Set.exists_range_iff] rfl theorem ClassGroup.mk_eq_mk_of_coe_ideal {I J : (FractionalIdeal R⁰ <| FractionRing R)ˣ} {I' J' : Ideal R} (hI : (I : FractionalIdeal R⁰ <| FractionRing R) = I') (hJ : (J : FractionalIdeal R⁰ <| FractionRing R) = J') : ClassGroup.mk I = ClassGroup.mk J ↔ ∃ x y : R, x ≠ 0 ∧ y ≠ 0 ∧ Ideal.span {x} * I' = Ideal.span {y} * J' := by rw [ClassGroup.mk_eq_mk] constructor · rintro ⟨x, rfl⟩ rw [Units.val_mul, hI, coe_toPrincipalIdeal, mul_comm, spanSingleton_mul_coeIdeal_eq_coeIdeal] at hJ exact ⟨_, _, sec_fst_ne_zero (R := R) le_rfl x.ne_zero, sec_snd_ne_zero (R := R) le_rfl (x : FractionRing R), hJ⟩ · rintro ⟨x, y, hx, hy, h⟩ have : IsUnit (mk' (FractionRing R) x ⟨y, mem_nonZeroDivisors_of_ne_zero hy⟩) := by simpa only [isUnit_iff_ne_zero, ne_eq, mk'_eq_zero_iff_eq_zero] using hx refine ⟨this.unit, ?_⟩ rw [mul_comm, ← Units.eq_iff, Units.val_mul, coe_toPrincipalIdeal] convert (mk'_mul_coeIdeal_eq_coeIdeal (FractionRing R) <| mem_nonZeroDivisors_of_ne_zero hy).2 h theorem ClassGroup.mk_eq_one_of_coe_ideal {I : (FractionalIdeal R⁰ <| FractionRing R)ˣ} {I' : Ideal R} (hI : (I : FractionalIdeal R⁰ <| FractionRing R) = I') : ClassGroup.mk I = 1 ↔ ∃ x : R, x ≠ 0 ∧ I' = Ideal.span {x} := by rw [← _root_.map_one (ClassGroup.mk (R := R) (K := FractionRing R)), ClassGroup.mk_eq_mk_of_coe_ideal hI (?_ : _ = ↑(⊤ : Ideal R))] any_goals rfl constructor · rintro ⟨x, y, hx, hy, h⟩ rw [Ideal.mul_top] at h rcases Ideal.mem_span_singleton_mul.mp ((Ideal.span_singleton_le_iff_mem _).mp h.ge) with ⟨i, _hi, rfl⟩ rw [← Ideal.span_singleton_mul_span_singleton, Ideal.span_singleton_mul_right_inj hx] at h exact ⟨i, right_ne_zero_of_mul hy, h⟩ · rintro ⟨x, hx, rfl⟩ exact ⟨1, x, one_ne_zero, hx, by rw [Ideal.span_singleton_one, Ideal.top_mul, Ideal.mul_top]⟩ variable (K) /-- Induction principle for the class group: to show something holds for all `x : ClassGroup R`, we can choose a fraction field `K` and show it holds for the equivalence class of each `I : FractionalIdeal R⁰ K`. -/ @[elab_as_elim] theorem ClassGroup.induction {P : ClassGroup R → Prop} (h : ∀ I : (FractionalIdeal R⁰ K)ˣ, P (ClassGroup.mk I)) (x : ClassGroup R) : P x := QuotientGroup.induction_on x fun I => by have : I = (Units.mapEquiv (canonicalEquiv R⁰ K (FractionRing R)).toMulEquiv) (Units.mapEquiv (canonicalEquiv R⁰ (FractionRing R) K).toMulEquiv I) := by simp [← Units.eq_iff] rw [congr_arg (QuotientGroup.mk (s := (toPrincipalIdeal R (FractionRing R)).range)) this] exact h _ /-- The definition of the class group does not depend on the choice of field of fractions. -/ noncomputable def ClassGroup.equiv : ClassGroup R ≃* (FractionalIdeal R⁰ K)ˣ ⧸ (toPrincipalIdeal R K).range := by haveI : Subgroup.map (Units.mapEquiv (canonicalEquiv R⁰ (FractionRing R) K).toMulEquiv).toMonoidHom (toPrincipalIdeal R (FractionRing R)).range = (toPrincipalIdeal R K).range := by ext I simp only [Subgroup.mem_map, mem_principal_ideals_iff] constructor · rintro ⟨I, ⟨x, hx⟩, rfl⟩ refine ⟨FractionRing.algEquiv R K x, ?_⟩ simp only [RingEquiv.toMulEquiv_eq_coe, MulEquiv.coe_toMonoidHom, coe_mapEquiv, ← hx, RingEquiv.coe_toMulEquiv, canonicalEquiv_spanSingleton] rfl · rintro ⟨x, hx⟩ refine ⟨Units.mapEquiv (canonicalEquiv R⁰ K (FractionRing R)).toMulEquiv I, ⟨(FractionRing.algEquiv R K).symm x, ?_⟩, Units.ext ?_⟩ · simp only [RingEquiv.toMulEquiv_eq_coe, coe_mapEquiv, ← hx, RingEquiv.coe_toMulEquiv, canonicalEquiv_spanSingleton] rfl · simp only [RingEquiv.toMulEquiv_eq_coe, MulEquiv.coe_toMonoidHom, coe_mapEquiv, RingEquiv.coe_toMulEquiv, canonicalEquiv_canonicalEquiv, canonicalEquiv_self, RingEquiv.refl_apply] exact @QuotientGroup.congr (FractionalIdeal R⁰ (FractionRing R))ˣ _ (FractionalIdeal R⁰ K)ˣ _ (toPrincipalIdeal R (FractionRing R)).range (toPrincipalIdeal R K).range _ _ (Units.mapEquiv (FractionalIdeal.canonicalEquiv R⁰ (FractionRing R) K).toMulEquiv) this @[simp] theorem ClassGroup.equiv_mk (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (FractionalIdeal R⁰ K)ˣ) : ClassGroup.equiv K' (ClassGroup.mk I) = QuotientGroup.mk' _ (Units.mapEquiv (↑(FractionalIdeal.canonicalEquiv R⁰ K K')) I) := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [ClassGroup.equiv, ClassGroup.mk, MonoidHom.comp_apply, QuotientGroup.congr_mk'] congr rw [← Units.eq_iff, Units.coe_mapEquiv, Units.coe_mapEquiv, Units.coe_map] exact FractionalIdeal.canonicalEquiv_canonicalEquiv _ _ _ _ _ @[simp] theorem ClassGroup.mk_canonicalEquiv (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (FractionalIdeal R⁰ K)ˣ) : ClassGroup.mk (Units.map (↑(canonicalEquiv R⁰ K K')) I : (FractionalIdeal R⁰ K')ˣ) = ClassGroup.mk I := by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [ClassGroup.mk, MonoidHom.comp_apply, ← MonoidHom.comp_apply (Units.map _), ← Units.map_comp, ← RingEquiv.coe_monoidHom_trans, FractionalIdeal.canonicalEquiv_trans_canonicalEquiv] rfl /-- Send a nonzero integral ideal to an invertible fractional ideal. -/ noncomputable def FractionalIdeal.mk0 [IsDedekindDomain R] : (Ideal R)⁰ →* (FractionalIdeal R⁰ K)ˣ where toFun I := Units.mk0 I (coeIdeal_ne_zero.mpr <| mem_nonZeroDivisors_iff_ne_zero.mp I.2) map_one' := by simp map_mul' x y := by simp @[simp] theorem FractionalIdeal.coe_mk0 [IsDedekindDomain R] (I : (Ideal R)⁰) : (FractionalIdeal.mk0 K I : FractionalIdeal R⁰ K) = I := rfl theorem FractionalIdeal.canonicalEquiv_mk0 [IsDedekindDomain R] (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (Ideal R)⁰) : FractionalIdeal.canonicalEquiv R⁰ K K' (FractionalIdeal.mk0 K I) = FractionalIdeal.mk0 K' I := by simp only [FractionalIdeal.coe_mk0, FractionalIdeal.canonicalEquiv_coeIdeal] @[simp] theorem FractionalIdeal.map_canonicalEquiv_mk0 [IsDedekindDomain R] (K' : Type*) [Field K'] [Algebra R K'] [IsFractionRing R K'] (I : (Ideal R)⁰) : Units.map (↑(FractionalIdeal.canonicalEquiv R⁰ K K')) (FractionalIdeal.mk0 K I) = FractionalIdeal.mk0 K' I := Units.ext (FractionalIdeal.canonicalEquiv_mk0 K K' I) /-- Send a nonzero ideal to the corresponding class in the class group. -/ noncomputable def ClassGroup.mk0 [IsDedekindDomain R] : (Ideal R)⁰ →* ClassGroup R := ClassGroup.mk.comp (FractionalIdeal.mk0 (FractionRing R)) @[simp] theorem ClassGroup.mk_mk0 [IsDedekindDomain R] (I : (Ideal R)⁰) : ClassGroup.mk (FractionalIdeal.mk0 K I) = ClassGroup.mk0 I := by rw [ClassGroup.mk0, MonoidHom.comp_apply, ← ClassGroup.mk_canonicalEquiv K (FractionRing R), FractionalIdeal.map_canonicalEquiv_mk0] @[simp] theorem ClassGroup.equiv_mk0 [IsDedekindDomain R] (I : (Ideal R)⁰) : ClassGroup.equiv K (ClassGroup.mk0 I) = QuotientGroup.mk' (toPrincipalIdeal R K).range (FractionalIdeal.mk0 K I) := by rw [ClassGroup.mk0, MonoidHom.comp_apply, ClassGroup.equiv_mk] congr 1 simp [← Units.eq_iff] theorem ClassGroup.mk0_eq_mk0_iff_exists_fraction_ring [IsDedekindDomain R] {I J : (Ideal R)⁰} : ClassGroup.mk0 I = ClassGroup.mk0 J ↔ ∃ (x : _) (_ : x ≠ (0 : K)), spanSingleton R⁰ x * I = J := by refine (ClassGroup.equiv K).injective.eq_iff.symm.trans ?_ simp only [ClassGroup.equiv_mk0, QuotientGroup.mk'_eq_mk', mem_principal_ideals_iff, Units.ext_iff, Units.val_mul, FractionalIdeal.coe_mk0, exists_prop] constructor · rintro ⟨X, ⟨x, hX⟩, hx⟩ refine ⟨x, ?_, ?_⟩ · rintro rfl; simp [X.ne_zero.symm] at hX simpa only [hX, mul_comm] using hx · rintro ⟨x, hx, eq_J⟩ refine ⟨Units.mk0 _ (spanSingleton_ne_zero_iff.mpr hx), ⟨x, rfl⟩, ?_⟩ simpa only [mul_comm] using eq_J variable {K} theorem ClassGroup.mk0_eq_mk0_iff [IsDedekindDomain R] {I J : (Ideal R)⁰} : ClassGroup.mk0 I = ClassGroup.mk0 J ↔ ∃ (x y : R) (_hx : x ≠ 0) (_hy : y ≠ 0), Ideal.span {x} * (I : Ideal R) = Ideal.span {y} * J := by refine (ClassGroup.mk0_eq_mk0_iff_exists_fraction_ring (FractionRing R)).trans ⟨?_, ?_⟩ · rintro ⟨z, hz, h⟩ obtain ⟨x, ⟨y, hy⟩, rfl⟩ := IsLocalization.mk'_surjective R⁰ z refine ⟨x, y, ?_, mem_nonZeroDivisors_iff_ne_zero.mp hy, ?_⟩ · rintro hx; apply hz rw [hx, IsFractionRing.mk'_eq_div, _root_.map_zero, zero_div] · exact (FractionalIdeal.mk'_mul_coeIdeal_eq_coeIdeal _ hy).mp h · rintro ⟨x, y, hx, hy, h⟩ have hy' : y ∈ R⁰ := mem_nonZeroDivisors_iff_ne_zero.mpr hy refine ⟨IsLocalization.mk' _ x ⟨y, hy'⟩, ?_, ?_⟩ · contrapose! hx rwa [mk'_eq_iff_eq_mul, zero_mul, ← (algebraMap R (FractionRing R)).map_zero, (IsFractionRing.injective R (FractionRing R)).eq_iff] at hx · exact (FractionalIdeal.mk'_mul_coeIdeal_eq_coeIdeal _ hy').mpr h /-- Maps a nonzero fractional ideal to an integral representative in the class group. -/ noncomputable def ClassGroup.integralRep (I : FractionalIdeal R⁰ (FractionRing R)) : Ideal R := I.num theorem ClassGroup.integralRep_mem_nonZeroDivisors {I : FractionalIdeal R⁰ (FractionRing R)} (hI : I ≠ 0) : I.num ∈ (Ideal R)⁰ := by rwa [mem_nonZeroDivisors_iff_ne_zero, ne_eq, FractionalIdeal.num_eq_zero_iff] theorem ClassGroup.mk0_integralRep [IsDedekindDomain R] (I : (FractionalIdeal R⁰ (FractionRing R))ˣ) : ClassGroup.mk0 ⟨ClassGroup.integralRep I, ClassGroup.integralRep_mem_nonZeroDivisors I.ne_zero⟩ = ClassGroup.mk I := by rw [← ClassGroup.mk_mk0 (FractionRing R), eq_comm, ClassGroup.mk_eq_mk] have fd_ne_zero : (algebraMap R (FractionRing R)) I.1.den ≠ 0 := by exact IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors (SetLike.coe_mem _) refine ⟨Units.mk0 (algebraMap R _ I.1.den) fd_ne_zero, ?_⟩ apply Units.ext rw [mul_comm, val_mul, coe_toPrincipalIdeal, val_mk0] exact FractionalIdeal.den_mul_self_eq_num' R⁰ (FractionRing R) I theorem ClassGroup.mk0_surjective [IsDedekindDomain R] : Function.Surjective (ClassGroup.mk0 : (Ideal R)⁰ → ClassGroup R) := by rintro ⟨I⟩ refine ⟨⟨ClassGroup.integralRep I.1, ClassGroup.integralRep_mem_nonZeroDivisors I.ne_zero⟩, ?_⟩ rw [ClassGroup.mk0_integralRep, ClassGroup.Quot_mk_eq_mk] theorem ClassGroup.mk_eq_one_iff {I : (FractionalIdeal R⁰ K)ˣ} : ClassGroup.mk I = 1 ↔ (I : Submodule R K).IsPrincipal := by rw [← (ClassGroup.equiv K).injective.eq_iff] simp only [equiv_mk, canonicalEquiv_self, RingEquiv.coe_mulEquiv_refl, QuotientGroup.mk'_apply, _root_.map_one, QuotientGroup.eq_one_iff, MonoidHom.mem_range, Units.ext_iff, coe_toPrincipalIdeal, coe_mapEquiv, MulEquiv.refl_apply] refine ⟨fun ⟨x, hx⟩ => ⟨⟨x, by rw [← hx, coe_spanSingleton]⟩⟩, ?_⟩ intro hI obtain ⟨x, hx⟩ := @Submodule.IsPrincipal.principal _ _ _ _ _ _ hI have hx' : (I : FractionalIdeal R⁰ K) = spanSingleton R⁰ x := by apply Subtype.coe_injective simp only [val_eq_coe, hx, coe_spanSingleton] refine ⟨Units.mk0 x ?_, ?_⟩ · intro x_eq; apply Units.ne_zero I; simp [hx', x_eq] · simp [hx'] theorem ClassGroup.mk0_eq_one_iff [IsDedekindDomain R] {I : Ideal R} (hI : I ∈ (Ideal R)⁰) : ClassGroup.mk0 ⟨I, hI⟩ = 1 ↔ I.IsPrincipal := ClassGroup.mk_eq_one_iff.trans (coeSubmodule_isPrincipal R _) theorem ClassGroup.mk0_eq_mk0_inv_iff [IsDedekindDomain R] {I J : (Ideal R)⁰} : ClassGroup.mk0 I = (ClassGroup.mk0 J)⁻¹ ↔ ∃ x ≠ (0 : R), I * J = Ideal.span {x} := by rw [eq_inv_iff_mul_eq_one, ← _root_.map_mul, ClassGroup.mk0_eq_one_iff, Submodule.isPrincipal_iff, Submonoid.coe_mul] refine ⟨fun ⟨a, ha⟩ ↦ ⟨a, ?_, ha⟩, fun ⟨a, _, ha⟩ ↦ ⟨a, ha⟩⟩ by_contra! rw [this, Submodule.span_zero_singleton] at ha exact nonZeroDivisors.coe_ne_zero _ <| J.prop _ ha /-- The class group of principal ideal domain is finite (in fact a singleton). See `ClassGroup.fintypeOfAdmissibleOfFinite` for a finiteness proof that works for rings of integers of global fields. -/ noncomputable instance [IsPrincipalIdealRing R] : Fintype (ClassGroup R) where elems := {1} complete := by refine ClassGroup.induction (R := R) (FractionRing R) (fun I => ?_) rw [Finset.mem_singleton] exact ClassGroup.mk_eq_one_iff.mpr (I : FractionalIdeal R⁰ (FractionRing R)).isPrincipal /-- The class number of a principal ideal domain is `1`. -/ theorem card_classGroup_eq_one [IsPrincipalIdealRing R] : Fintype.card (ClassGroup R) = 1 := by rw [Fintype.card_eq_one_iff] use 1 refine ClassGroup.induction (R := R) (FractionRing R) (fun I => ?_) exact ClassGroup.mk_eq_one_iff.mpr (I : FractionalIdeal R⁰ (FractionRing R)).isPrincipal /-- The class number is `1` iff the ring of integers is a principal ideal domain. -/ theorem card_classGroup_eq_one_iff [IsDedekindDomain R] [Fintype (ClassGroup R)] : Fintype.card (ClassGroup R) = 1 ↔ IsPrincipalIdealRing R := by constructor; swap; · intros; convert card_classGroup_eq_one (R := R) rw [Fintype.card_eq_one_iff] rintro ⟨I, hI⟩ have eq_one : ∀ J : ClassGroup R, J = 1 := fun J => (hI J).trans (hI 1).symm refine ⟨fun I => ?_⟩ by_cases hI : I = ⊥ · rw [hI]; exact bot_isPrincipal · exact (ClassGroup.mk0_eq_one_iff (mem_nonZeroDivisors_iff_ne_zero.mpr hI)).mp (eq_one _)
RingTheory\Complex.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Data.Complex.Module import Mathlib.RingTheory.Norm.Defs import Mathlib.RingTheory.Trace.Defs /-! # Lemmas about `Algebra.trace` and `Algebra.norm` on `ℂ` -/ open Complex theorem Algebra.leftMulMatrix_complex (z : ℂ) : Algebra.leftMulMatrix Complex.basisOneI z = !![z.re, -z.im; z.im, z.re] := by ext i j rw [Algebra.leftMulMatrix_eq_repr_mul, Complex.coe_basisOneI_repr, Complex.coe_basisOneI, mul_re, mul_im, Matrix.of_apply] fin_cases j · simp only [Fin.mk_zero, Matrix.cons_val_zero, one_re, mul_one, one_im, mul_zero, sub_zero, zero_add] fin_cases i <;> rfl · simp only [Fin.mk_one, Matrix.cons_val_one, Matrix.head_cons, I_re, mul_zero, I_im, mul_one, zero_sub, add_zero] fin_cases i <;> rfl theorem Algebra.trace_complex_apply (z : ℂ) : Algebra.trace ℝ ℂ z = 2 * z.re := by rw [Algebra.trace_eq_matrix_trace Complex.basisOneI, Algebra.leftMulMatrix_complex, Matrix.trace_fin_two] exact (two_mul _).symm theorem Algebra.norm_complex_apply (z : ℂ) : Algebra.norm ℝ z = Complex.normSq z := by rw [Algebra.norm_eq_matrix_det Complex.basisOneI, Algebra.leftMulMatrix_complex, Matrix.det_fin_two, normSq_apply] simp theorem Algebra.norm_complex_eq : Algebra.norm ℝ = normSq.toMonoidHom := MonoidHom.ext Algebra.norm_complex_apply
RingTheory\Discriminant.lean
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed import Mathlib.RingTheory.Trace.Basic import Mathlib.RingTheory.Norm.Basic /-! # Discriminant of a family of vectors Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define the *discriminant* of `b` as the determinant of the matrix whose `(i j)`-th element is the trace of `b i * b j`. ## Main definition * `Algebra.discr A b` : the discriminant of `b : ι → B`. ## Main results * `Algebra.discr_zero_of_not_linearIndependent` : if `b` is not linear independent, then `Algebra.discr A b = 0`. * `Algebra.discr_of_matrix_vecMul` and `Algebra.discr_of_matrix_mulVec` : formulas relating `Algebra.discr A ι b` with `Algebra.discr A (b ᵥ* P.map (algebraMap A B))` and `Algebra.discr A (P.map (algebraMap A B) *ᵥ b)`. * `Algebra.discr_not_zero_of_basis` : over a field, if `b` is a basis, then `Algebra.discr K b ≠ 0`. * `Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two` : if `L/K` is a field extension and `b : ι → L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : L →ₐ[K] E` is the embedding in an algebraically closed field `E` corresponding to `j : ι` via a bijection `e : ι ≃ (L →ₐ[K] E)`. * `Algebra.discr_powerBasis_eq_prod` : the discriminant of a power basis. * `Algebra.discr_isIntegral` : if `K` and `L` are fields and `IsScalarTower R K L`, if `b : ι → L` satisfies `∀ i, IsIntegral R (b i)`, then `IsIntegral R (discr K b)`. * `Algebra.discr_mul_isIntegral_mem_adjoin` : let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite separable extension of `K`. Let `B : PowerBasis K L` be such that `IsIntegral R B.gen`. Then for all, `z : L` we have `(discr K B.basis) • z ∈ adjoin R ({B.gen} : Set L)`. ## Implementation details Our definition works for any `A`-algebra `B`, but note that if `B` is not free as an `A`-module, then `trace A B = 0` by definition, so `discr A b = 0` for any `b`. -/ universe u v w z open scoped Matrix open Matrix FiniteDimensional Fintype Polynomial Finset IntermediateField namespace Algebra variable (A : Type u) {B : Type v} (C : Type z) {ι : Type w} [DecidableEq ι] variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C] section Discr /-- Given an `A`-algebra `B` and `b`, an `ι`-indexed family of elements of `B`, we define `discr A ι b` as the determinant of `traceMatrix A ι b`. -/ -- Porting note: using `[DecidableEq ι]` instead of `by classical...` did not work in -- mathlib3. noncomputable def discr (A : Type u) {B : Type v} [CommRing A] [CommRing B] [Algebra A B] [Fintype ι] (b : ι → B) := (traceMatrix A b).det theorem discr_def [Fintype ι] (b : ι → B) : discr A b = (traceMatrix A b).det := rfl variable {A C} in /-- Mapping a family of vectors along an `AlgEquiv` preserves the discriminant. -/ theorem discr_eq_discr_of_algEquiv [Fintype ι] (b : ι → B) (f : B ≃ₐ[A] C) : Algebra.discr A b = Algebra.discr A (f ∘ b) := by rw [discr_def]; congr; ext simp_rw [traceMatrix_apply, traceForm_apply, Function.comp, ← map_mul f, trace_eq_of_algEquiv] variable {ι' : Type*} [Fintype ι'] [Fintype ι] [DecidableEq ι'] section Basic @[simp] theorem discr_reindex (b : Basis ι A B) (f : ι ≃ ι') : discr A (b ∘ ⇑f.symm) = discr A b := by classical rw [← Basis.coe_reindex, discr_def, traceMatrix_reindex, det_reindex_self, ← discr_def] /-- If `b` is not linear independent, then `Algebra.discr A b = 0`. -/ theorem discr_zero_of_not_linearIndependent [IsDomain A] {b : ι → B} (hli : ¬LinearIndependent A b) : discr A b = 0 := by classical obtain ⟨g, hg, i, hi⟩ := Fintype.not_linearIndependent_iff.1 hli have : (traceMatrix A b) *ᵥ g = 0 := by ext i have : ∀ j, (trace A B) (b i * b j) * g j = (trace A B) (g j • b j * b i) := by intro j simp [mul_comm] simp only [mulVec, dotProduct, traceMatrix_apply, Pi.zero_apply, traceForm_apply, fun j => this j, ← map_sum, ← sum_mul, hg, zero_mul, LinearMap.map_zero] by_contra h rw [discr_def] at h simp [Matrix.eq_zero_of_mulVec_eq_zero h this] at hi variable {A} /-- Relation between `Algebra.discr A ι b` and `Algebra.discr A (b ᵥ* P.map (algebraMap A B))`. -/ theorem discr_of_matrix_vecMul (b : ι → B) (P : Matrix ι ι A) : discr A (b ᵥ* P.map (algebraMap A B)) = P.det ^ 2 * discr A b := by rw [discr_def, traceMatrix_of_matrix_vecMul, det_mul, det_mul, det_transpose, mul_comm, ← mul_assoc, discr_def, pow_two] /-- Relation between `Algebra.discr A ι b` and `Algebra.discr A ((P.map (algebraMap A B)) *ᵥ b)`. -/ theorem discr_of_matrix_mulVec (b : ι → B) (P : Matrix ι ι A) : discr A (P.map (algebraMap A B) *ᵥ b) = P.det ^ 2 * discr A b := by rw [discr_def, traceMatrix_of_matrix_mulVec, det_mul, det_mul, det_transpose, mul_comm, ← mul_assoc, discr_def, pow_two] end Basic section Field variable (K : Type u) {L : Type v} (E : Type z) [Field K] [Field L] [Field E] variable [Algebra K L] [Algebra K E] variable [Module.Finite K L] [IsAlgClosed E] /-- If `b` is a basis of a finite separable field extension `L/K`, then `Algebra.discr K b ≠ 0`. -/ theorem discr_not_zero_of_basis [Algebra.IsSeparable K L] (b : Basis ι K L) : discr K b ≠ 0 := by rw [discr_def, traceMatrix_of_basis, ← LinearMap.BilinForm.nondegenerate_iff_det_ne_zero] exact traceForm_nondegenerate _ _ /-- If `b` is a basis of a finite separable field extension `L/K`, then `Algebra.discr K b` is a unit. -/ theorem discr_isUnit_of_basis [Algebra.IsSeparable K L] (b : Basis ι K L) : IsUnit (discr K b) := IsUnit.mk0 _ (discr_not_zero_of_basis _ _) variable (b : ι → L) (pb : PowerBasis K L) /-- If `L/K` is a field extension and `b : ι → L`, then `discr K b` is the square of the determinant of the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : L →ₐ[K] E` is the embedding in an algebraically closed field `E` corresponding to `j : ι` via a bijection `e : ι ≃ (L →ₐ[K] E)`. -/ theorem discr_eq_det_embeddingsMatrixReindex_pow_two [Algebra.IsSeparable K L] (e : ι ≃ (L →ₐ[K] E)) : algebraMap K E (discr K b) = (embeddingsMatrixReindex K E b e).det ^ 2 := by rw [discr_def, RingHom.map_det, RingHom.mapMatrix_apply, traceMatrix_eq_embeddingsMatrixReindex_mul_trans, det_mul, det_transpose, pow_two] /-- The discriminant of a power basis. -/ theorem discr_powerBasis_eq_prod (e : Fin pb.dim ≃ (L →ₐ[K] E)) [Algebra.IsSeparable K L] : algebraMap K E (discr K pb.basis) = ∏ i : Fin pb.dim, ∏ j ∈ Ioi i, (e j pb.gen - e i pb.gen) ^ 2 := by rw [discr_eq_det_embeddingsMatrixReindex_pow_two K E pb.basis e, embeddingsMatrixReindex_eq_vandermonde, det_transpose, det_vandermonde, ← prod_pow] congr; ext i rw [← prod_pow] /-- A variation of `Algebra.discr_powerBasis_eq_prod`. -/ theorem discr_powerBasis_eq_prod' [Algebra.IsSeparable K L] (e : Fin pb.dim ≃ (L →ₐ[K] E)) : algebraMap K E (discr K pb.basis) = ∏ i : Fin pb.dim, ∏ j ∈ Ioi i, -((e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen)) := by rw [discr_powerBasis_eq_prod _ _ _ e] congr; ext i; congr; ext j ring local notation "n" => finrank K L /-- A variation of `Algebra.discr_powerBasis_eq_prod`. -/ theorem discr_powerBasis_eq_prod'' [Algebra.IsSeparable K L] (e : Fin pb.dim ≃ (L →ₐ[K] E)) : algebraMap K E (discr K pb.basis) = (-1) ^ (n * (n - 1) / 2) * ∏ i : Fin pb.dim, ∏ j ∈ Ioi i, (e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen) := by rw [discr_powerBasis_eq_prod' _ _ _ e] simp_rw [fun i j => neg_eq_neg_one_mul ((e j pb.gen - e i pb.gen) * (e i pb.gen - e j pb.gen)), prod_mul_distrib] congr simp only [prod_pow_eq_pow_sum, prod_const] congr rw [← @Nat.cast_inj ℚ, Nat.cast_sum] have : ∀ x : Fin pb.dim, ↑x + 1 ≤ pb.dim := by simp [Nat.succ_le_iff, Fin.is_lt] simp_rw [Fin.card_Ioi, Nat.sub_sub, add_comm 1] simp only [Nat.cast_sub, this, Finset.card_fin, nsmul_eq_mul, sum_const, sum_sub_distrib, Nat.cast_add, Nat.cast_one, sum_add_distrib, mul_one] rw [← Nat.cast_sum, ← @Finset.sum_range ℕ _ pb.dim fun i => i, sum_range_id] have hn : n = pb.dim := by rw [← AlgHom.card K L E, ← Fintype.card_fin pb.dim] -- FIXME: Without the `Fintype` namespace, why does it complain about `Finset.card_congr` being -- deprecated? exact Fintype.card_congr e.symm have h₂ : 2 ∣ pb.dim * (pb.dim - 1) := pb.dim.even_mul_pred_self.two_dvd have hne : ((2 : ℕ) : ℚ) ≠ 0 := by simp have hle : 1 ≤ pb.dim := by rw [← hn, Nat.one_le_iff_ne_zero, ← zero_lt_iff, FiniteDimensional.finrank_pos_iff] infer_instance rw [hn, Nat.cast_div h₂ hne, Nat.cast_mul, Nat.cast_sub hle] field_simp ring /-- Formula for the discriminant of a power basis using the norm of the field extension. -/ -- Porting note: `(minpoly K pb.gen).derivative` does not work anymore. theorem discr_powerBasis_eq_norm [Algebra.IsSeparable K L] : discr K pb.basis = (-1) ^ (n * (n - 1) / 2) * norm K (aeval pb.gen (derivative (R := K) (minpoly K pb.gen))) := by let E := AlgebraicClosure L letI := fun a b : E => Classical.propDecidable (Eq a b) have e : Fin pb.dim ≃ (L →ₐ[K] E) := by refine equivOfCardEq ?_ rw [Fintype.card_fin, AlgHom.card] exact (PowerBasis.finrank pb).symm have hnodup : ((minpoly K pb.gen).aroots E).Nodup := nodup_roots (Separable.map (Algebra.IsSeparable.isSeparable K pb.gen)) have hroots : ∀ σ : L →ₐ[K] E, σ pb.gen ∈ (minpoly K pb.gen).aroots E := by intro σ rw [mem_roots, IsRoot.def, eval_map, ← aeval_def, aeval_algHom_apply] repeat' simp [minpoly.ne_zero (Algebra.IsSeparable.isIntegral K pb.gen)] apply (algebraMap K E).injective rw [RingHom.map_mul, RingHom.map_pow, RingHom.map_neg, RingHom.map_one, discr_powerBasis_eq_prod'' _ _ _ e] congr rw [norm_eq_prod_embeddings, prod_prod_Ioi_mul_eq_prod_prod_off_diag] conv_rhs => congr rfl ext σ rw [← aeval_algHom_apply, aeval_root_derivative_of_splits (minpoly.monic (Algebra.IsSeparable.isIntegral K pb.gen)) (IsAlgClosed.splits_codomain _) (hroots σ), ← Finset.prod_mk _ (hnodup.erase _)] rw [prod_sigma', prod_sigma'] refine prod_bij' (fun i _ ↦ ⟨e i.2, e i.1 pb.gen⟩) (fun σ hσ ↦ ⟨e.symm (PowerBasis.lift pb σ.2 ?_), e.symm σ.1⟩) ?_ ?_ ?_ ?_ (fun i _ ↦ by simp) -- Porting note: `@mem_compl` was not necessary. <;> simp only [mem_sigma, mem_univ, Finset.mem_mk, hnodup.mem_erase_iff, IsRoot.def, mem_roots', minpoly.ne_zero (Algebra.IsSeparable.isIntegral K pb.gen), not_false_eq_true, mem_singleton, true_and, @mem_compl _ _ _ (_), Sigma.forall, Equiv.apply_symm_apply, PowerBasis.lift_gen, and_imp, implies_true, forall_const, Equiv.symm_apply_apply, Sigma.ext_iff, Equiv.symm_apply_eq, heq_eq_eq, and_true] at * · simpa only [aeval_def, eval₂_eq_eval_map] using hσ.2.2 · exact fun a b hba ↦ ⟨fun h ↦ hba <| e.injective <| pb.algHom_ext h.symm, hroots _⟩ · rintro a b hba ha rw [ha, PowerBasis.lift_gen] at hba exact hba.1 rfl · exact fun a b _ ↦ pb.algHom_ext <| pb.lift_gen _ _ section Integral variable {R : Type z} [CommRing R] [Algebra R K] [Algebra R L] [IsScalarTower R K L] /-- If `K` and `L` are fields and `IsScalarTower R K L`, and `b : ι → L` satisfies ` ∀ i, IsIntegral R (b i)`, then `IsIntegral R (discr K b)`. -/ theorem discr_isIntegral {b : ι → L} (h : ∀ i, IsIntegral R (b i)) : IsIntegral R (discr K b) := by classical rw [discr_def] exact IsIntegral.det fun i j ↦ isIntegral_trace ((h i).mul (h j)) /-- Let `K` be the fraction field of an integrally closed domain `R` and let `L` be a finite separable extension of `K`. Let `B : PowerBasis K L` be such that `IsIntegral R B.gen`. Then for all, `z : L` that are integral over `R`, we have `(discr K B.basis) • z ∈ adjoin R ({B.gen} : Set L)`. -/ theorem discr_mul_isIntegral_mem_adjoin [Algebra.IsSeparable K L] [IsIntegrallyClosed R] [IsFractionRing R K] {B : PowerBasis K L} (hint : IsIntegral R B.gen) {z : L} (hz : IsIntegral R z) : discr K B.basis • z ∈ adjoin R ({B.gen} : Set L) := by have hinv : IsUnit (traceMatrix K B.basis).det := by simpa [← discr_def] using discr_isUnit_of_basis _ B.basis have H : (traceMatrix K B.basis).det • (traceMatrix K B.basis) *ᵥ (B.basis.equivFun z) = (traceMatrix K B.basis).det • fun i => trace K L (z * B.basis i) := by congr; exact traceMatrix_of_basis_mulVec _ _ have cramer := mulVec_cramer (traceMatrix K B.basis) fun i => trace K L (z * B.basis i) suffices ∀ i, ((traceMatrix K B.basis).det • B.basis.equivFun z) i ∈ (⊥ : Subalgebra R K) by rw [← B.basis.sum_repr z, Finset.smul_sum] refine Subalgebra.sum_mem _ fun i _ => ?_ replace this := this i rw [← discr_def, Pi.smul_apply, mem_bot] at this obtain ⟨r, hr⟩ := this rw [Basis.equivFun_apply] at hr rw [← smul_assoc, ← hr, algebraMap_smul] refine Subalgebra.smul_mem _ ?_ _ rw [B.basis_eq_pow i] exact Subalgebra.pow_mem _ (subset_adjoin (Set.mem_singleton _)) _ intro i rw [← H, ← mulVec_smul] at cramer replace cramer := congr_arg (mulVec (traceMatrix K B.basis)⁻¹) cramer rw [mulVec_mulVec, nonsing_inv_mul _ hinv, mulVec_mulVec, nonsing_inv_mul _ hinv, one_mulVec, one_mulVec] at cramer rw [← congr_fun cramer i, cramer_apply, det_apply] refine Subalgebra.sum_mem _ fun σ _ => Subalgebra.zsmul_mem _ (Subalgebra.prod_mem _ fun j _ => ?_) _ by_cases hji : j = i · simp only [updateColumn_apply, hji, eq_self_iff_true, PowerBasis.coe_basis] exact mem_bot.2 (IsIntegrallyClosed.isIntegral_iff.1 <| isIntegral_trace (hz.mul <| hint.pow _)) · simp only [updateColumn_apply, hji, PowerBasis.coe_basis] exact mem_bot.2 (IsIntegrallyClosed.isIntegral_iff.1 <| isIntegral_trace <| (hint.pow _).mul (hint.pow _)) end Integral end Field section Int /-- Two (finite) ℤ-bases have the same discriminant. -/ theorem discr_eq_discr [Fintype ι] (b : Basis ι ℤ A) (b' : Basis ι ℤ A) : Algebra.discr ℤ b = Algebra.discr ℤ b' := by convert Algebra.discr_of_matrix_vecMul b' (b'.toMatrix b) · rw [Basis.toMatrix_map_vecMul] · suffices IsUnit (b'.toMatrix b).det by rw [Int.isUnit_iff, ← sq_eq_one_iff] at this rw [this, one_mul] rw [← LinearMap.toMatrix_id_eq_basis_toMatrix b b'] exact LinearEquiv.isUnit_det (LinearEquiv.refl ℤ A) b b' end Int end Discr end Algebra
RingTheory\EisensteinCriterion.lean
/- Copyright (c) 2020 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Nat.Cast.WithTop import Mathlib.RingTheory.Prime import Mathlib.RingTheory.Polynomial.Content import Mathlib.RingTheory.Ideal.Quotient /-! # Eisenstein's criterion A proof of a slight generalisation of Eisenstein's criterion for the irreducibility of a polynomial over an integral domain. -/ open Polynomial Ideal.Quotient variable {R : Type*} [CommRing R] namespace Polynomial open Polynomial namespace EisensteinCriterionAux -- Section for auxiliary lemmas used in the proof of `irreducible_of_eisenstein_criterion` theorem map_eq_C_mul_X_pow_of_forall_coeff_mem {f : R[X]} {P : Ideal R} (hfP : ∀ n : ℕ, ↑n < f.degree → f.coeff n ∈ P) : map (mk P) f = C ((mk P) f.leadingCoeff) * X ^ f.natDegree := Polynomial.ext fun n => by by_cases hf0 : f = 0 · simp [hf0] rcases lt_trichotomy (n : WithBot ℕ) (degree f) with (h | h | h) · erw [coeff_map, eq_zero_iff_mem.2 (hfP n h), coeff_C_mul, coeff_X_pow, if_neg, mul_zero] rintro rfl exact not_lt_of_ge degree_le_natDegree h · have : natDegree f = n := natDegree_eq_of_degree_eq_some h.symm rw [coeff_C_mul, coeff_X_pow, if_pos this.symm, mul_one, leadingCoeff, this, coeff_map] · rw [coeff_eq_zero_of_degree_lt, coeff_eq_zero_of_degree_lt] · refine lt_of_le_of_lt (degree_C_mul_X_pow_le _ _) ?_ rwa [← degree_eq_natDegree hf0] · exact lt_of_le_of_lt (degree_map_le _ _) h theorem le_natDegree_of_map_eq_mul_X_pow {n : ℕ} {P : Ideal R} (hP : P.IsPrime) {q : R[X]} {c : Polynomial (R ⧸ P)} (hq : map (mk P) q = c * X ^ n) (hc0 : c.degree = 0) : n ≤ q.natDegree := Nat.cast_le.1 (calc ↑n = degree (q.map (mk P)) := by rw [hq, degree_mul, hc0, zero_add, degree_pow, degree_X, nsmul_one] _ ≤ degree q := degree_map_le _ _ _ ≤ natDegree q := degree_le_natDegree ) theorem eval_zero_mem_ideal_of_eq_mul_X_pow {n : ℕ} {P : Ideal R} {q : R[X]} {c : Polynomial (R ⧸ P)} (hq : map (mk P) q = c * X ^ n) (hn0 : n ≠ 0) : eval 0 q ∈ P := by rw [← coeff_zero_eq_eval_zero, ← eq_zero_iff_mem, ← coeff_map, hq, coeff_zero_eq_eval_zero, eval_mul, eval_pow, eval_X, zero_pow hn0, mul_zero] theorem isUnit_of_natDegree_eq_zero_of_isPrimitive {p q : R[X]} -- Porting note: stated using `IsPrimitive` which is defeq to old statement. (hu : IsPrimitive (p * q)) (hpm : p.natDegree = 0) : IsUnit p := by rw [eq_C_of_degree_le_zero (natDegree_eq_zero_iff_degree_le_zero.1 hpm), isUnit_C] refine hu _ ?_ rw [← eq_C_of_degree_le_zero (natDegree_eq_zero_iff_degree_le_zero.1 hpm)] exact dvd_mul_right _ _ end EisensteinCriterionAux open EisensteinCriterionAux variable [IsDomain R] /-- If `f` is a non constant polynomial with coefficients in `R`, and `P` is a prime ideal in `R`, then if every coefficient in `R` except the leading coefficient is in `P`, and the trailing coefficient is not in `P^2` and no non units in `R` divide `f`, then `f` is irreducible. -/ theorem irreducible_of_eisenstein_criterion {f : R[X]} {P : Ideal R} (hP : P.IsPrime) (hfl : f.leadingCoeff ∉ P) (hfP : ∀ n : ℕ, ↑n < degree f → f.coeff n ∈ P) (hfd0 : 0 < degree f) (h0 : f.coeff 0 ∉ P ^ 2) (hu : f.IsPrimitive) : Irreducible f := have hf0 : f ≠ 0 := fun _ => by simp_all only [not_true, Submodule.zero_mem, coeff_zero] have hf : f.map (mk P) = C (mk P (leadingCoeff f)) * X ^ natDegree f := map_eq_C_mul_X_pow_of_forall_coeff_mem hfP have hfd0 : 0 < f.natDegree := WithBot.coe_lt_coe.1 (lt_of_lt_of_le hfd0 degree_le_natDegree) ⟨mt degree_eq_zero_of_isUnit fun h => by simp_all only [lt_irrefl], by rintro p q rfl rw [Polynomial.map_mul] at hf rcases mul_eq_mul_prime_pow (show Prime (X : Polynomial (R ⧸ P)) from monic_X.prime_of_degree_eq_one degree_X) hf with ⟨m, n, b, c, hmnd, hbc, hp, hq⟩ have hmn : 0 < m → 0 < n → False := by intro hm0 hn0 refine h0 ?_ rw [coeff_zero_eq_eval_zero, eval_mul, sq] exact Ideal.mul_mem_mul (eval_zero_mem_ideal_of_eq_mul_X_pow hp hm0.ne') (eval_zero_mem_ideal_of_eq_mul_X_pow hq hn0.ne') have hpql0 : (mk P) (p * q).leadingCoeff ≠ 0 := by rwa [Ne, eq_zero_iff_mem] have hp0 : p ≠ 0 := fun h => by simp_all only [zero_mul, eq_self_iff_true, not_true, Ne] have hq0 : q ≠ 0 := fun h => by simp_all only [eq_self_iff_true, not_true, Ne, mul_zero] have hbc0 : degree b = 0 ∧ degree c = 0 := by apply_fun degree at hbc rwa [degree_C hpql0, degree_mul, eq_comm, Nat.WithBot.add_eq_zero_iff] at hbc have hmp : m ≤ natDegree p := le_natDegree_of_map_eq_mul_X_pow hP hp hbc0.1 have hnq : n ≤ natDegree q := le_natDegree_of_map_eq_mul_X_pow hP hq hbc0.2 have hpmqn : p.natDegree = m ∧ q.natDegree = n := by rw [natDegree_mul hp0 hq0] at hmnd contrapose hmnd apply ne_of_lt rw [not_and_or] at hmnd cases' hmnd with hmnd hmnd · exact add_lt_add_of_lt_of_le (lt_of_le_of_ne hmp (Ne.symm hmnd)) hnq · exact add_lt_add_of_le_of_lt hmp (lt_of_le_of_ne hnq (Ne.symm hmnd)) obtain rfl | rfl : m = 0 ∨ n = 0 := by rwa [pos_iff_ne_zero, pos_iff_ne_zero, imp_false, Classical.not_not, ← or_iff_not_imp_left] at hmn · exact Or.inl (isUnit_of_natDegree_eq_zero_of_isPrimitive hu hpmqn.1) · exact Or.inr (isUnit_of_natDegree_eq_zero_of_isPrimitive (show IsPrimitive (q * p) by simpa [mul_comm] using hu) hpmqn.2)⟩ end Polynomial
RingTheory\EssentialFiniteness.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.TensorProduct.Basic /-! # Essentially of finite type algebras ## Main results - `Algebra.EssFiniteType`: The class of essentially of finite type algebras. An `R`-algebra is essentially of finite type if it is the localization of an algebra of finite type. - `Algebra.EssFiniteType.algHom_ext`: The algebra homomorphisms out from an algebra essentially of finite type is determined by its values on a finite set. -/ open scoped TensorProduct namespace Algebra variable (R S T : Type*) [CommRing R] [CommRing S] [CommRing T] variable [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] /-- An `R`-algebra is essentially of finite type if it is the localization of an algebra of finite type. See `essFiniteType_iff_exists_subalgebra`. -/ class EssFiniteType : Prop where cond : ∃ s : Finset S, IsLocalization ((IsUnit.submonoid S).comap (algebraMap (adjoin R (s : Set S)) S)) S /-- Let `S` be an `R`-algebra essentially of finite type, this is a choice of a finset `s ⊆ S` such that `S` is the localization of `R[s]`. -/ noncomputable def EssFiniteType.finset [h : EssFiniteType R S] : Finset S := h.cond.choose /-- A choice of a subalgebra of finite type in an essentially of finite type algebra, such that its localization is the whole ring. -/ noncomputable abbrev EssFiniteType.subalgebra [EssFiniteType R S] : Subalgebra R S := Algebra.adjoin R (finset R S : Set S) lemma EssFiniteType.adjoin_mem_finset [EssFiniteType R S] : adjoin R { x : subalgebra R S | x.1 ∈ finset R S } = ⊤ := adjoin_adjoin_coe_preimage instance [EssFiniteType R S] : Algebra.FiniteType R (EssFiniteType.subalgebra R S) := by constructor rw [Subalgebra.fg_top, EssFiniteType.subalgebra] exact ⟨_, rfl⟩ /-- A submonoid of `EssFiniteType.subalgebra R S`, whose localization is the whole algebra `S`. -/ noncomputable def EssFiniteType.submonoid [EssFiniteType R S] : Submonoid (EssFiniteType.subalgebra R S) := ((IsUnit.submonoid S).comap (algebraMap (EssFiniteType.subalgebra R S) S)) instance EssFiniteType.isLocalization [h : EssFiniteType R S] : IsLocalization (EssFiniteType.submonoid R S) S := h.cond.choose_spec lemma essFiniteType_cond_iff (σ : Finset S) : IsLocalization ((IsUnit.submonoid S).comap (algebraMap (adjoin R (σ : Set S)) S)) S ↔ (∀ s : S, ∃ t ∈ Algebra.adjoin R (σ : Set S), IsUnit t ∧ s * t ∈ Algebra.adjoin R (σ : Set S)) := by constructor <;> intro hσ · intro s obtain ⟨⟨⟨x, hx⟩, ⟨t, ht⟩, ht'⟩, h⟩ := hσ.2 s exact ⟨t, ht, ht', h ▸ hx⟩ · constructor · exact fun y ↦ y.prop · intro s obtain ⟨t, ht, ht', h⟩ := hσ s exact ⟨⟨⟨_, h⟩, ⟨t, ht⟩, ht'⟩, rfl⟩ · intros x y e exact ⟨1, by simpa using Subtype.ext e⟩ lemma essFiniteType_iff : EssFiniteType R S ↔ ∃ (σ : Finset S), (∀ s : S, ∃ t ∈ Algebra.adjoin R (σ : Set S), IsUnit t ∧ s * t ∈ Algebra.adjoin R (σ : Set S)) := by simp_rw [← essFiniteType_cond_iff] constructor <;> exact fun ⟨a, b⟩ ↦ ⟨a, b⟩ instance EssFiniteType.of_finiteType [FiniteType R S] : EssFiniteType R S := by obtain ⟨s, hs⟩ := ‹FiniteType R S› rw [essFiniteType_iff] exact ⟨s, fun _ ↦ by simpa only [hs, mem_top, and_true, true_and] using ⟨1, isUnit_one⟩⟩ variable {R} in lemma EssFiniteType.of_isLocalization (M : Submonoid R) [IsLocalization M S] : EssFiniteType R S := by rw [essFiniteType_iff] use ∅ simp only [Finset.coe_empty, Algebra.adjoin_empty, exists_and_left, Algebra.mem_bot, Set.mem_range, exists_exists_eq_and] intro s obtain ⟨⟨x, t⟩, e⟩ := IsLocalization.surj M s exact ⟨_, IsLocalization.map_units S t, x, e.symm⟩ lemma EssFiniteType.of_id : EssFiniteType R R := inferInstance lemma EssFiniteType.aux (σ : Subalgebra R S) (hσ : ∀ s : S, ∃ t ∈ σ, IsUnit t ∧ s * t ∈ σ) (τ : Set T) (t : T) (ht : t ∈ Algebra.adjoin S τ) : ∃ s ∈ σ, IsUnit s ∧ s • t ∈ σ.map (IsScalarTower.toAlgHom R S T) ⊔ Algebra.adjoin R τ := by refine Algebra.adjoin_induction ht ?_ ?_ ?_ ?_ · intro t ht exact ⟨1, Subalgebra.one_mem _, isUnit_one, (one_smul S t).symm ▸ Algebra.mem_sup_right (Algebra.subset_adjoin ht)⟩ · intro s obtain ⟨s', hs₁, hs₂, hs₃⟩ := hσ s refine ⟨_, hs₁, hs₂, Algebra.mem_sup_left ?_⟩ rw [Algebra.smul_def, ← map_mul, mul_comm] exact ⟨_, hs₃, rfl⟩ · rintro x y ⟨sx, hsx, hsx', hsx''⟩ ⟨sy, hsy, hsy', hsy''⟩ refine ⟨_, σ.mul_mem hsx hsy, hsx'.mul hsy', ?_⟩ rw [smul_add, mul_smul, mul_smul, Algebra.smul_def sx (sy • y), smul_comm, Algebra.smul_def sy (sx • x)] apply add_mem (mul_mem _ hsx'') (mul_mem _ hsy'') <;> exact Algebra.mem_sup_left ⟨_, ‹_›, rfl⟩ · rintro x y ⟨sx, hsx, hsx', hsx''⟩ ⟨sy, hsy, hsy', hsy''⟩ refine ⟨_, σ.mul_mem hsx hsy, hsx'.mul hsy', ?_⟩ rw [mul_smul, ← smul_eq_mul, smul_comm sy x, ← smul_assoc, smul_eq_mul] exact mul_mem hsx'' hsy'' lemma EssFiniteType.comp [h₁ : EssFiniteType R S] [h₂ : EssFiniteType S T] : EssFiniteType R T := by rw [essFiniteType_iff] at h₁ h₂ ⊢ classical obtain ⟨s, hs⟩ := h₁ obtain ⟨t, ht⟩ := h₂ use s.image (IsScalarTower.toAlgHom R S T) ∪ t simp only [Finset.coe_union, Finset.coe_image, Algebra.adjoin_union, Algebra.adjoin_image] intro x obtain ⟨y, hy₁, hy₂, hy₃⟩ := ht x obtain ⟨t₁, h₁, h₂, h₃⟩ := EssFiniteType.aux _ _ _ _ hs _ y hy₁ obtain ⟨t₂, h₄, h₅, h₆⟩ := EssFiniteType.aux _ _ _ _ hs _ _ hy₃ refine ⟨t₂ • t₁ • y, ?_, ?_, ?_⟩ · rw [Algebra.smul_def] exact mul_mem (Algebra.mem_sup_left ⟨_, h₄, rfl⟩) h₃ · rw [Algebra.smul_def, Algebra.smul_def] exact (h₅.map _).mul ((h₂.map _).mul hy₂) · rw [← mul_smul, mul_comm, smul_mul_assoc, mul_comm, mul_comm y, mul_smul, Algebra.smul_def] exact mul_mem (Algebra.mem_sup_left ⟨_, h₁, rfl⟩) h₆ open EssFiniteType in lemma essFiniteType_iff_exists_subalgebra : EssFiniteType R S ↔ ∃ (S₀ : Subalgebra R S) (M : Submonoid S₀), FiniteType R S₀ ∧ IsLocalization M S := by refine ⟨fun h ↦ ⟨subalgebra R S, submonoid R S, inferInstance, inferInstance⟩, ?_⟩ rintro ⟨S₀, M, _, _⟩ letI := of_isLocalization S M exact comp R S₀ S instance EssFiniteType.baseChange [h : EssFiniteType R S] : EssFiniteType T (T ⊗[R] S) := by classical rw [essFiniteType_iff] at h ⊢ obtain ⟨σ, hσ⟩ := h use σ.image Algebra.TensorProduct.includeRight intro s induction' s using TensorProduct.induction_on with x y x y hx hy · exact ⟨1, one_mem _, isUnit_one, by simpa using zero_mem _⟩ · obtain ⟨t, h₁, h₂, h₃⟩ := hσ y have H (x : S) (hx : x ∈ Algebra.adjoin R (σ : Set S)) : 1 ⊗ₜ[R] x ∈ Algebra.adjoin T ((σ.image Algebra.TensorProduct.includeRight : Finset (T ⊗[R] S)) : Set (T ⊗[R] S)) := by have : Algebra.TensorProduct.includeRight x ∈ (Algebra.adjoin R (σ : Set S)).map (Algebra.TensorProduct.includeRight (A := T)) := Subalgebra.mem_map.mpr ⟨_, hx, rfl⟩ rw [← Algebra.adjoin_adjoin_of_tower R] apply Algebra.subset_adjoin simpa [← Algebra.adjoin_image] using this refine ⟨Algebra.TensorProduct.includeRight t, H _ h₁, h₂.map _, ?_⟩ simp only [Algebra.TensorProduct.includeRight_apply, Algebra.TensorProduct.tmul_mul_tmul, mul_one] rw [← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul'] apply Subalgebra.smul_mem exact H _ h₃ · obtain ⟨tx, hx₁, hx₂, hx₃⟩ := hx obtain ⟨ty, hy₁, hy₂, hy₃⟩ := hy refine ⟨_, mul_mem hx₁ hy₁, hx₂.mul hy₂, ?_⟩ rw [add_mul, ← mul_assoc, mul_comm tx ty, ← mul_assoc] exact add_mem (mul_mem hx₃ hy₁) (mul_mem hy₃ hx₁) lemma EssFiniteType.of_comp [h : EssFiniteType R T] : EssFiniteType S T := by rw [essFiniteType_iff] at h ⊢ classical obtain ⟨σ, hσ⟩ := h use σ intro x obtain ⟨y, hy₁, hy₂, hy₃⟩ := hσ x simp_rw [← Algebra.adjoin_adjoin_of_tower R (S := S) (σ : Set T)] exact ⟨y, Algebra.subset_adjoin hy₁, hy₂, Algebra.subset_adjoin hy₃⟩ lemma EssFiniteType.comp_iff [EssFiniteType R S] : EssFiniteType R T ↔ EssFiniteType S T := ⟨fun _ ↦ of_comp R S T, fun _ ↦ comp R S T⟩ variable {R S} in lemma EssFiniteType.algHom_ext [EssFiniteType R S] (f g : S →ₐ[R] T) (H : ∀ s ∈ finset R S, f s = g s) : f = g := by suffices f.toRingHom = g.toRingHom by ext; exact RingHom.congr_fun this _ apply IsLocalization.ringHom_ext (EssFiniteType.submonoid R S) suffices f.comp (IsScalarTower.toAlgHom R _ S) = g.comp (IsScalarTower.toAlgHom R _ S) by ext; exact AlgHom.congr_fun this _ apply AlgHom.ext_of_adjoin_eq_top (s := { x | x.1 ∈ finset R S }) · rw [← top_le_iff] rintro x _ refine Algebra.adjoin_induction' ?_ ?_ ?_ ?_ x · intro x hx; exact Algebra.subset_adjoin hx · intro r; exact Subalgebra.algebraMap_mem _ _ · intro x y hx hy; exact add_mem hx hy · intro x y hx hy; exact mul_mem hx hy · rintro ⟨x, hx⟩ hx'; exact H x hx' end Algebra
RingTheory\EuclideanDomain.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.PrincipalIdealDomain /-! # Lemmas about Euclidean domains Various about Euclidean domains are proved; all of them seem to be true more generally for principal ideal domains, so these lemmas should probably be reproved in more generality and this file perhaps removed? ## Tags euclidean domain -/ section open EuclideanDomain Set Ideal section GCDMonoid variable {R : Type*} [EuclideanDomain R] [GCDMonoid R] {p q : R} theorem gcd_ne_zero_of_left (hp : p ≠ 0) : GCDMonoid.gcd p q ≠ 0 := fun h => hp <| eq_zero_of_zero_dvd (h ▸ gcd_dvd_left p q) theorem gcd_ne_zero_of_right (hp : q ≠ 0) : GCDMonoid.gcd p q ≠ 0 := fun h => hp <| eq_zero_of_zero_dvd (h ▸ gcd_dvd_right p q) theorem left_div_gcd_ne_zero {p q : R} (hp : p ≠ 0) : p / GCDMonoid.gcd p q ≠ 0 := by obtain ⟨r, hr⟩ := GCDMonoid.gcd_dvd_left p q obtain ⟨pq0, r0⟩ : GCDMonoid.gcd p q ≠ 0 ∧ r ≠ 0 := mul_ne_zero_iff.mp (hr ▸ hp) nth_rw 1 [hr] rw [mul_comm, mul_div_cancel_right₀ _ pq0] exact r0 theorem right_div_gcd_ne_zero {p q : R} (hq : q ≠ 0) : q / GCDMonoid.gcd p q ≠ 0 := by obtain ⟨r, hr⟩ := GCDMonoid.gcd_dvd_right p q obtain ⟨pq0, r0⟩ : GCDMonoid.gcd p q ≠ 0 ∧ r ≠ 0 := mul_ne_zero_iff.mp (hr ▸ hq) nth_rw 1 [hr] rw [mul_comm, mul_div_cancel_right₀ _ pq0] exact r0 theorem isCoprime_div_gcd_div_gcd (hq : q ≠ 0) : IsCoprime (p / GCDMonoid.gcd p q) (q / GCDMonoid.gcd p q) := (gcd_isUnit_iff _ _).1 <| isUnit_gcd_of_eq_mul_gcd (EuclideanDomain.mul_div_cancel' (gcd_ne_zero_of_right hq) <| gcd_dvd_left _ _).symm (EuclideanDomain.mul_div_cancel' (gcd_ne_zero_of_right hq) <| gcd_dvd_right _ _).symm <| gcd_ne_zero_of_right hq end GCDMonoid namespace EuclideanDomain /-- Create a `GCDMonoid` whose `GCDMonoid.gcd` matches `EuclideanDomain.gcd`. -/ -- Porting note: added `DecidableEq R` def gcdMonoid (R) [EuclideanDomain R] [DecidableEq R] : GCDMonoid R where gcd := gcd lcm := lcm gcd_dvd_left := gcd_dvd_left gcd_dvd_right := gcd_dvd_right dvd_gcd := dvd_gcd gcd_mul_lcm a b := by rw [EuclideanDomain.gcd_mul_lcm] lcm_zero_left := lcm_zero_left lcm_zero_right := lcm_zero_right variable {α : Type*} [EuclideanDomain α] theorem span_gcd [DecidableEq α] (x y : α) : span ({gcd x y} : Set α) = span ({x, y} : Set α) := letI := EuclideanDomain.gcdMonoid α _root_.span_gcd x y theorem gcd_isUnit_iff [DecidableEq α] {x y : α} : IsUnit (gcd x y) ↔ IsCoprime x y := letI := EuclideanDomain.gcdMonoid α _root_.gcd_isUnit_iff x y -- this should be proved for UFDs surely? theorem isCoprime_of_dvd {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z ∈ nonunits α, z ≠ 0 → z ∣ x → ¬z ∣ y) : IsCoprime x y := letI := Classical.decEq α letI := EuclideanDomain.gcdMonoid α _root_.isCoprime_of_dvd x y nonzero H -- this should be proved for UFDs surely? theorem dvd_or_coprime (x y : α) (h : Irreducible x) : x ∣ y ∨ IsCoprime x y := letI := Classical.decEq α letI := EuclideanDomain.gcdMonoid α _root_.dvd_or_coprime x y h end EuclideanDomain end
RingTheory\Filtration.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Polynomial.Module.Basic import Mathlib.Algebra.Ring.Idempotents import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.ReesAlgebra import Mathlib.RingTheory.Finiteness import Mathlib.Order.Basic import Mathlib.Order.Hom.Lattice import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic /-! # `I`-filtrations of modules This file contains the definitions and basic results around (stable) `I`-filtrations of modules. ## Main results - `Ideal.Filtration`: An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that `∀ i, I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`. - `Ideal.Filtration.Stable`: An `I`-filtration is stable if `I • (N i) = N (i + 1)` for large enough `i`. - `Ideal.Filtration.submodule`: The associated module `⨁ Nᵢ` of a filtration, implemented as a submodule of `M[X]`. - `Ideal.Filtration.submodule_fg_iff_stable`: If `F.N i` are all finitely generated, then `F.Stable` iff `F.submodule.FG`. - `Ideal.Filtration.Stable.of_le`: In a finite module over a noetherian ring, if `F' ≤ F`, then `F.Stable → F'.Stable`. - `Ideal.exists_pow_inf_eq_pow_smul`: **Artin-Rees lemma**. given `N ≤ M`, there exists a `k` such that `IⁿM ⊓ N = Iⁿ⁻ᵏ(IᵏM ⊓ N)` for all `n ≥ k`. - `Ideal.iInf_pow_eq_bot_of_localRing`: **Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian local rings. - `Ideal.iInf_pow_eq_bot_of_isDomain`: **Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian domains. -/ universe u v variable {R M : Type u} [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) open Polynomial open scoped Polynomial /-- An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that `I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`. -/ @[ext] structure Ideal.Filtration (M : Type u) [AddCommGroup M] [Module R M] where N : ℕ → Submodule R M mono : ∀ i, N (i + 1) ≤ N i smul_le : ∀ i, I • N i ≤ N (i + 1) variable (F F' : I.Filtration M) {I} namespace Ideal.Filtration theorem pow_smul_le (i j : ℕ) : I ^ i • F.N j ≤ F.N (i + j) := by induction' i with _ ih · simp · rw [pow_succ', mul_smul, add_assoc, add_comm 1, ← add_assoc] exact (smul_mono_right _ ih).trans (F.smul_le _) theorem pow_smul_le_pow_smul (i j k : ℕ) : I ^ (i + k) • F.N j ≤ I ^ k • F.N (i + j) := by rw [add_comm, pow_add, mul_smul] exact smul_mono_right _ (F.pow_smul_le i j) protected theorem antitone : Antitone F.N := antitone_nat_of_succ_le F.mono /-- The trivial `I`-filtration of `N`. -/ @[simps] def _root_.Ideal.trivialFiltration (I : Ideal R) (N : Submodule R M) : I.Filtration M where N _ := N mono _ := le_rfl smul_le _ := Submodule.smul_le_right /-- The `sup` of two `I.Filtration`s is an `I.Filtration`. -/ instance : Sup (I.Filtration M) := ⟨fun F F' => ⟨F.N ⊔ F'.N, fun i => sup_le_sup (F.mono i) (F'.mono i), fun i => (Submodule.smul_sup _ _ _).trans_le <| sup_le_sup (F.smul_le i) (F'.smul_le i)⟩⟩ /-- The `sSup` of a family of `I.Filtration`s is an `I.Filtration`. -/ instance : SupSet (I.Filtration M) := ⟨fun S => { N := sSup (Ideal.Filtration.N '' S) mono := fun i => by apply sSup_le_sSup_of_forall_exists_le _ rintro _ ⟨⟨_, F, hF, rfl⟩, rfl⟩ exact ⟨_, ⟨⟨_, F, hF, rfl⟩, rfl⟩, F.mono i⟩ smul_le := fun i => by rw [sSup_eq_iSup', iSup_apply, Submodule.smul_iSup, iSup_apply] apply iSup_mono _ rintro ⟨_, F, hF, rfl⟩ exact F.smul_le i }⟩ /-- The `inf` of two `I.Filtration`s is an `I.Filtration`. -/ instance : Inf (I.Filtration M) := ⟨fun F F' => ⟨F.N ⊓ F'.N, fun i => inf_le_inf (F.mono i) (F'.mono i), fun i => (smul_inf_le _ _ _).trans <| inf_le_inf (F.smul_le i) (F'.smul_le i)⟩⟩ /-- The `sInf` of a family of `I.Filtration`s is an `I.Filtration`. -/ instance : InfSet (I.Filtration M) := ⟨fun S => { N := sInf (Ideal.Filtration.N '' S) mono := fun i => by apply sInf_le_sInf_of_forall_exists_le _ rintro _ ⟨⟨_, F, hF, rfl⟩, rfl⟩ exact ⟨_, ⟨⟨_, F, hF, rfl⟩, rfl⟩, F.mono i⟩ smul_le := fun i => by rw [sInf_eq_iInf', iInf_apply, iInf_apply] refine smul_iInf_le.trans ?_ apply iInf_mono _ rintro ⟨_, F, hF, rfl⟩ exact F.smul_le i }⟩ instance : Top (I.Filtration M) := ⟨I.trivialFiltration ⊤⟩ instance : Bot (I.Filtration M) := ⟨I.trivialFiltration ⊥⟩ @[simp] theorem sup_N : (F ⊔ F').N = F.N ⊔ F'.N := rfl @[simp] theorem sSup_N (S : Set (I.Filtration M)) : (sSup S).N = sSup (Ideal.Filtration.N '' S) := rfl @[simp] theorem inf_N : (F ⊓ F').N = F.N ⊓ F'.N := rfl @[simp] theorem sInf_N (S : Set (I.Filtration M)) : (sInf S).N = sInf (Ideal.Filtration.N '' S) := rfl @[simp] theorem top_N : (⊤ : I.Filtration M).N = ⊤ := rfl @[simp] theorem bot_N : (⊥ : I.Filtration M).N = ⊥ := rfl @[simp] theorem iSup_N {ι : Sort*} (f : ι → I.Filtration M) : (iSup f).N = ⨆ i, (f i).N := congr_arg sSup (Set.range_comp _ _).symm @[simp] theorem iInf_N {ι : Sort*} (f : ι → I.Filtration M) : (iInf f).N = ⨅ i, (f i).N := congr_arg sInf (Set.range_comp _ _).symm instance : CompleteLattice (I.Filtration M) := Function.Injective.completeLattice Ideal.Filtration.N (fun _ _ => Ideal.Filtration.ext) sup_N inf_N (fun _ => sSup_image) (fun _ => sInf_image) top_N bot_N instance : Inhabited (I.Filtration M) := ⟨⊥⟩ /-- An `I` filtration is stable if `I • F.N n = F.N (n+1)` for large enough `n`. -/ def Stable : Prop := ∃ n₀, ∀ n ≥ n₀, I • F.N n = F.N (n + 1) /-- The trivial stable `I`-filtration of `N`. -/ @[simps] def _root_.Ideal.stableFiltration (I : Ideal R) (N : Submodule R M) : I.Filtration M where N i := I ^ i • N mono i := by dsimp only; rw [add_comm, pow_add, mul_smul]; exact Submodule.smul_le_right smul_le i := by dsimp only; rw [add_comm, pow_add, mul_smul, pow_one] theorem _root_.Ideal.stableFiltration_stable (I : Ideal R) (N : Submodule R M) : (I.stableFiltration N).Stable := by use 0 intro n _ dsimp rw [add_comm, pow_add, mul_smul, pow_one] variable {F F'} theorem Stable.exists_pow_smul_eq (h : F.Stable) : ∃ n₀, ∀ k, F.N (n₀ + k) = I ^ k • F.N n₀ := by obtain ⟨n₀, hn⟩ := h use n₀ intro k induction' k with _ ih · simp · rw [← add_assoc, ← hn, ih, add_comm, pow_add, mul_smul, pow_one] omega theorem Stable.exists_pow_smul_eq_of_ge (h : F.Stable) : ∃ n₀, ∀ n ≥ n₀, F.N n = I ^ (n - n₀) • F.N n₀ := by obtain ⟨n₀, hn₀⟩ := h.exists_pow_smul_eq use n₀ intro n hn convert hn₀ (n - n₀) rw [add_comm, tsub_add_cancel_of_le hn] theorem stable_iff_exists_pow_smul_eq_of_ge : F.Stable ↔ ∃ n₀, ∀ n ≥ n₀, F.N n = I ^ (n - n₀) • F.N n₀ := by refine ⟨Stable.exists_pow_smul_eq_of_ge, fun h => ⟨h.choose, fun n hn => ?_⟩⟩ rw [h.choose_spec n hn, h.choose_spec (n + 1) (by omega), smul_smul, ← pow_succ', tsub_add_eq_add_tsub hn] theorem Stable.exists_forall_le (h : F.Stable) (e : F.N 0 ≤ F'.N 0) : ∃ n₀, ∀ n, F.N (n + n₀) ≤ F'.N n := by obtain ⟨n₀, hF⟩ := h use n₀ intro n induction' n with n hn · refine (F.antitone ?_).trans e; simp · rw [add_right_comm, ← hF] · exact (smul_mono_right _ hn).trans (F'.smul_le _) simp theorem Stable.bounded_difference (h : F.Stable) (h' : F'.Stable) (e : F.N 0 = F'.N 0) : ∃ n₀, ∀ n, F.N (n + n₀) ≤ F'.N n ∧ F'.N (n + n₀) ≤ F.N n := by obtain ⟨n₁, h₁⟩ := h.exists_forall_le (le_of_eq e) obtain ⟨n₂, h₂⟩ := h'.exists_forall_le (le_of_eq e.symm) use max n₁ n₂ intro n refine ⟨(F.antitone ?_).trans (h₁ n), (F'.antitone ?_).trans (h₂ n)⟩ <;> simp open PolynomialModule variable (F F') /-- The `R[IX]`-submodule of `M[X]` associated with an `I`-filtration. -/ protected def submodule : Submodule (reesAlgebra I) (PolynomialModule R M) where carrier := { f | ∀ i, f i ∈ F.N i } add_mem' hf hg i := Submodule.add_mem _ (hf i) (hg i) zero_mem' i := Submodule.zero_mem _ smul_mem' r f hf i := by rw [Subalgebra.smul_def, PolynomialModule.smul_apply] apply Submodule.sum_mem rintro ⟨j, k⟩ e rw [Finset.mem_antidiagonal] at e subst e exact F.pow_smul_le j k (Submodule.smul_mem_smul (r.2 j) (hf k)) @[simp] theorem mem_submodule (f : PolynomialModule R M) : f ∈ F.submodule ↔ ∀ i, f i ∈ F.N i := Iff.rfl theorem inf_submodule : (F ⊓ F').submodule = F.submodule ⊓ F'.submodule := by ext exact forall_and variable (I M) /-- `Ideal.Filtration.submodule` as an `InfHom`. -/ def submoduleInfHom : InfHom (I.Filtration M) (Submodule (reesAlgebra I) (PolynomialModule R M)) where toFun := Ideal.Filtration.submodule map_inf' := inf_submodule variable {I M} theorem submodule_closure_single : AddSubmonoid.closure (⋃ i, single R i '' (F.N i : Set M)) = F.submodule.toAddSubmonoid := by apply le_antisymm · rw [AddSubmonoid.closure_le, Set.iUnion_subset_iff] rintro i _ ⟨m, hm, rfl⟩ j rw [single_apply] split_ifs with h · rwa [← h] · exact (F.N j).zero_mem · intro f hf rw [← f.sum_single] apply AddSubmonoid.sum_mem _ _ rintro c - exact AddSubmonoid.subset_closure (Set.subset_iUnion _ c <| Set.mem_image_of_mem _ (hf c)) theorem submodule_span_single : Submodule.span (reesAlgebra I) (⋃ i, single R i '' (F.N i : Set M)) = F.submodule := by rw [← Submodule.span_closure, submodule_closure_single, Submodule.coe_toAddSubmonoid] exact Submodule.span_eq (Filtration.submodule F) theorem submodule_eq_span_le_iff_stable_ge (n₀ : ℕ) : F.submodule = Submodule.span _ (⋃ i ≤ n₀, single R i '' (F.N i : Set M)) ↔ ∀ n ≥ n₀, I • F.N n = F.N (n + 1) := by rw [← submodule_span_single, ← LE.le.le_iff_eq, Submodule.span_le, Set.iUnion_subset_iff] swap; · exact Submodule.span_mono (Set.iUnion₂_subset_iUnion _ _) constructor · intro H n hn refine (F.smul_le n).antisymm ?_ intro x hx obtain ⟨l, hl⟩ := (Finsupp.mem_span_iff_total _ _ _).mp (H _ ⟨x, hx, rfl⟩) replace hl := congr_arg (fun f : ℕ →₀ M => f (n + 1)) hl dsimp only at hl erw [Finsupp.single_eq_same] at hl rw [← hl, Finsupp.total_apply, Finsupp.sum_apply] apply Submodule.sum_mem _ _ rintro ⟨_, _, ⟨n', rfl⟩, _, ⟨hn', rfl⟩, m, hm, rfl⟩ - dsimp only [Subtype.coe_mk] rw [Subalgebra.smul_def, smul_single_apply, if_pos (show n' ≤ n + 1 by omega)] have e : n' ≤ n := by omega have := F.pow_smul_le_pow_smul (n - n') n' 1 rw [tsub_add_cancel_of_le e, pow_one, add_comm _ 1, ← add_tsub_assoc_of_le e, add_comm] at this exact this (Submodule.smul_mem_smul ((l _).2 <| n + 1 - n') hm) · let F' := Submodule.span (reesAlgebra I) (⋃ i ≤ n₀, single R i '' (F.N i : Set M)) intro hF i have : ∀ i ≤ n₀, single R i '' (F.N i : Set M) ⊆ F' := by -- Porting note: Original proof was -- `fun i hi => Set.Subset.trans (Set.subset_iUnion₂ i hi) Submodule.subset_span` intro i hi refine Set.Subset.trans ?_ Submodule.subset_span refine @Set.subset_iUnion₂ _ _ _ (fun i => fun _ => ↑((single R i) '' ((N F i) : Set M))) i ?_ exact hi induction' i with j hj · exact this _ (zero_le _) by_cases hj' : j.succ ≤ n₀ · exact this _ hj' simp only [not_le, Nat.lt_succ_iff] at hj' rw [← hF _ hj'] rintro _ ⟨m, hm, rfl⟩ refine Submodule.smul_induction_on hm (fun r hr m' hm' => ?_) (fun x y hx hy => ?_) · rw [add_comm, ← monomial_smul_single] exact F'.smul_mem ⟨_, reesAlgebra.monomial_mem.mpr (by rwa [pow_one])⟩ (hj <| Set.mem_image_of_mem _ hm') · rw [map_add] exact F'.add_mem hx hy /-- If the components of a filtration are finitely generated, then the filtration is stable iff its associated submodule of is finitely generated. -/ theorem submodule_fg_iff_stable (hF' : ∀ i, (F.N i).FG) : F.submodule.FG ↔ F.Stable := by classical delta Ideal.Filtration.Stable simp_rw [← F.submodule_eq_span_le_iff_stable_ge] constructor · rintro H refine H.stabilizes_of_iSup_eq ⟨fun n₀ => Submodule.span _ (⋃ (i : ℕ) (_ : i ≤ n₀), single R i '' ↑(F.N i)), ?_⟩ ?_ · intro n m e rw [Submodule.span_le, Set.iUnion₂_subset_iff] intro i hi refine Set.Subset.trans ?_ Submodule.subset_span refine @Set.subset_iUnion₂ _ _ _ (fun i => fun _ => ↑((single R i) '' ((N F i) : Set M))) i ?_ exact hi.trans e · dsimp rw [← Submodule.span_iUnion, ← submodule_span_single] congr 1 ext simp only [Set.mem_iUnion, Set.mem_image, SetLike.mem_coe, exists_prop] constructor · rintro ⟨-, i, -, e⟩; exact ⟨i, e⟩ · rintro ⟨i, e⟩; exact ⟨i, i, le_refl i, e⟩ · rintro ⟨n, hn⟩ rw [hn] simp_rw [Submodule.span_iUnion₂, ← Finset.mem_range_succ_iff, iSup_subtype'] apply Submodule.fg_iSup rintro ⟨i, hi⟩ obtain ⟨s, hs⟩ := hF' i have : Submodule.span (reesAlgebra I) (s.image (lsingle R i) : Set (PolynomialModule R M)) = Submodule.span _ (single R i '' (F.N i : Set M)) := by rw [Finset.coe_image, ← Submodule.span_span_of_tower R, ← Submodule.map_span, hs]; rfl rw [Subtype.coe_mk, ← this] exact ⟨_, rfl⟩ variable {F} theorem Stable.of_le [IsNoetherianRing R] [Module.Finite R M] (hF : F.Stable) {F' : I.Filtration M} (hf : F' ≤ F) : F'.Stable := by rw [← submodule_fg_iff_stable] at hF ⊢ any_goals intro i; exact IsNoetherian.noetherian _ have := isNoetherian_of_fg_of_noetherian _ hF rw [isNoetherian_submodule] at this exact this _ (OrderHomClass.mono (submoduleInfHom M I) hf) theorem Stable.inter_right [IsNoetherianRing R] [Module.Finite R M] (hF : F.Stable) : (F ⊓ F').Stable := hF.of_le inf_le_left theorem Stable.inter_left [IsNoetherianRing R] [Module.Finite R M] (hF : F.Stable) : (F' ⊓ F).Stable := hF.of_le inf_le_right end Ideal.Filtration variable (I) /-- **Artin-Rees lemma** -/ theorem Ideal.exists_pow_inf_eq_pow_smul [IsNoetherianRing R] [Module.Finite R M] (N : Submodule R M) : ∃ k : ℕ, ∀ n ≥ k, I ^ n • ⊤ ⊓ N = I ^ (n - k) • (I ^ k • ⊤ ⊓ N) := ((I.stableFiltration_stable ⊤).inter_right (I.trivialFiltration N)).exists_pow_smul_eq_of_ge theorem Ideal.mem_iInf_smul_pow_eq_bot_iff [IsNoetherianRing R] [Module.Finite R M] (x : M) : x ∈ (⨅ i : ℕ, I ^ i • ⊤ : Submodule R M) ↔ ∃ r : I, (r : R) • x = x := by let N := (⨅ i : ℕ, I ^ i • ⊤ : Submodule R M) have hN : ∀ k, (I.stableFiltration ⊤ ⊓ I.trivialFiltration N).N k = N := fun k => inf_eq_right.mpr ((iInf_le _ k).trans <| le_of_eq <| by simp) constructor · obtain ⟨r, hr₁, hr₂⟩ := Submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I N (IsNoetherian.noetherian N) (by obtain ⟨k, hk⟩ := (I.stableFiltration_stable ⊤).inter_right (I.trivialFiltration N) have := hk k (le_refl _) rw [hN, hN] at this exact le_of_eq this.symm) intro H exact ⟨⟨r, hr₁⟩, hr₂ _ H⟩ · rintro ⟨r, eq⟩ rw [Submodule.mem_iInf] intro i induction' i with i hi · simp · rw [add_comm, pow_add, ← smul_smul, pow_one, ← eq] exact Submodule.smul_mem_smul r.prop hi theorem Ideal.iInf_pow_smul_eq_bot_of_localRing [IsNoetherianRing R] [LocalRing R] [Module.Finite R M] (h : I ≠ ⊤) : (⨅ i : ℕ, I ^ i • ⊤ : Submodule R M) = ⊥ := by rw [eq_bot_iff] intro x hx obtain ⟨r, hr⟩ := (I.mem_iInf_smul_pow_eq_bot_iff x).mp hx have := LocalRing.isUnit_one_sub_self_of_mem_nonunits _ (LocalRing.le_maximalIdeal h r.prop) apply this.smul_left_cancel.mp simp [sub_smul, hr] /-- **Krull's intersection theorem** for noetherian local rings. -/ theorem Ideal.iInf_pow_eq_bot_of_localRing [IsNoetherianRing R] [LocalRing R] (h : I ≠ ⊤) : ⨅ i : ℕ, I ^ i = ⊥ := by convert I.iInf_pow_smul_eq_bot_of_localRing (M := R) h ext i rw [smul_eq_mul, ← Ideal.one_eq_top, mul_one] /-- Also see `Ideal.isIdempotentElem_iff_eq_bot_or_top` for integral domains. -/ theorem Ideal.isIdempotentElem_iff_eq_bot_or_top_of_localRing {R} [CommRing R] [IsNoetherianRing R] [LocalRing R] (I : Ideal R) : IsIdempotentElem I ↔ I = ⊥ ∨ I = ⊤ := by constructor · intro H by_cases I = ⊤; · exact Or.inr ‹_› refine Or.inl (eq_bot_iff.mpr ?_) rw [← Ideal.iInf_pow_eq_bot_of_localRing I ‹_›] apply le_iInf rintro (_|n) <;> simp [H.pow_succ_eq] · rintro (rfl | rfl) <;> simp [IsIdempotentElem] /-- **Krull's intersection theorem** for noetherian domains. -/ theorem Ideal.iInf_pow_eq_bot_of_isDomain [IsNoetherianRing R] [IsDomain R] (h : I ≠ ⊤) : ⨅ i : ℕ, I ^ i = ⊥ := by rw [eq_bot_iff] intro x hx by_contra hx' have := Ideal.mem_iInf_smul_pow_eq_bot_iff I x simp_rw [smul_eq_mul, ← Ideal.one_eq_top, mul_one] at this obtain ⟨r, hr⟩ := this.mp hx have := mul_right_cancel₀ hx' (hr.trans (one_mul x).symm) exact I.eq_top_iff_one.not.mp h (this ▸ r.prop)
RingTheory\Finiteness.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Algebra.RestrictScalars import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.LinearAlgebra.Quotient import Mathlib.LinearAlgebra.StdBasis import Mathlib.GroupTheory.Finiteness import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Nilpotent.Defs /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Submodule.FG`, `Ideal.FG` These express that some object is finitely generated as *submodule* over some base ring. - `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite` all of these express that some object is finitely generated *as module* over some base ring. ## Main results * `exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul` is Nakayama's lemma, in the following form: if N is a finitely generated submodule of an ambient R-module M and I is an ideal of R such that N ⊆ IN, then there exists r ∈ 1 + I such that rN = 0. -/ open Function (Surjective) namespace Submodule variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] open Set /-- A submodule of `M` is finitely generated if it is the span of a finite subset of `M`. -/ def FG (N : Submodule R M) : Prop := ∃ S : Finset M, Submodule.span R ↑S = N theorem fg_def {N : Submodule R M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ span R 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_addSubmonoid_fg (P : Submodule ℕ M) : P.FG ↔ P.toAddSubmonoid.FG := ⟨fun ⟨S, hS⟩ => ⟨S, by simpa [← span_nat_eq_addSubmonoid_closure] using hS⟩, fun ⟨S, hS⟩ => ⟨S, by simpa [← span_nat_eq_addSubmonoid_closure] using hS⟩⟩ theorem fg_iff_add_subgroup_fg {G : Type*} [AddCommGroup G] (P : Submodule ℤ G) : P.FG ↔ P.toAddSubgroup.FG := ⟨fun ⟨S, hS⟩ => ⟨S, by simpa [← span_int_eq_addSubgroup_closure] using hS⟩, fun ⟨S, hS⟩ => ⟨S, by simpa [← span_int_eq_addSubgroup_closure] using hS⟩⟩ theorem fg_iff_exists_fin_generating_family {N : Submodule R M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), span R (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⟩ /-- **Nakayama's Lemma**. Atiyah-Macdonald 2.5, Eisenbud 4.7, Matsumura 2.2, [Stacks 00DV](https://stacks.math.columbia.edu/tag/00DV) -/ theorem exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] (I : Ideal R) (N : Submodule R M) (hn : N.FG) (hin : N ≤ I • N) : ∃ r : R, r - 1 ∈ I ∧ ∀ n ∈ N, r • n = (0 : M) := by rw [fg_def] at hn rcases hn with ⟨s, hfs, hs⟩ have : ∃ r : R, r - 1 ∈ I ∧ N ≤ (I • span R s).comap (LinearMap.lsmul R M r) ∧ s ⊆ N := by refine ⟨1, ?_, ?_, ?_⟩ · rw [sub_self] exact I.zero_mem · rw [hs] intro n hn rw [mem_comap] change (1 : R) • n ∈ I • N rw [one_smul] exact hin hn · rw [← span_le, hs] clear hin hs revert this refine Set.Finite.dinduction_on _ hfs (fun H => ?_) @fun i s _ _ ih H => ?_ · rcases H with ⟨r, hr1, hrn, _⟩ refine ⟨r, hr1, fun n hn => ?_⟩ specialize hrn hn rwa [mem_comap, span_empty, smul_bot, mem_bot] at hrn apply ih rcases H with ⟨r, hr1, hrn, hs⟩ rw [← Set.singleton_union, span_union, smul_sup] at hrn rw [Set.insert_subset_iff] at hs have : ∃ c : R, c - 1 ∈ I ∧ c • i ∈ I • span R s := by specialize hrn hs.1 rw [mem_comap, mem_sup] at hrn rcases hrn with ⟨y, hy, z, hz, hyz⟩ dsimp at hyz rw [mem_smul_span_singleton] at hy rcases hy with ⟨c, hci, rfl⟩ use r - c constructor · rw [sub_right_comm] exact I.sub_mem hr1 hci · rw [sub_smul, ← hyz, add_sub_cancel_left] exact hz rcases this with ⟨c, hc1, hci⟩ refine ⟨c * r, ?_, ?_, hs.2⟩ · simpa only [mul_sub, mul_one, sub_add_sub_cancel] using I.add_mem (I.mul_mem_left c hr1) hc1 · intro n hn specialize hrn hn rw [mem_comap, mem_sup] at hrn rcases hrn with ⟨y, hy, z, hz, hyz⟩ dsimp at hyz rw [mem_smul_span_singleton] at hy rcases hy with ⟨d, _, rfl⟩ simp only [mem_comap, LinearMap.lsmul_apply] rw [mul_smul, ← hyz, smul_add, smul_smul, mul_comm, mul_smul] exact add_mem (smul_mem _ _ hci) (smul_mem _ _ hz) theorem exists_mem_and_smul_eq_self_of_fg_of_le_smul {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] (I : Ideal R) (N : Submodule R M) (hn : N.FG) (hin : N ≤ I • N) : ∃ r ∈ I, ∀ n ∈ N, r • n = n := by obtain ⟨r, hr, hr'⟩ := exists_sub_one_mem_and_smul_eq_zero_of_fg_of_le_smul I N hn hin exact ⟨-(r - 1), I.neg_mem hr, fun n hn => by simpa [sub_smul] using hr' n hn⟩ theorem fg_bot : (⊥ : Submodule R M).FG := ⟨∅, by rw [Finset.coe_empty, span_empty]⟩ theorem _root_.Subalgebra.fg_bot_toSubmodule {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : (⊥ : Subalgebra R A).toSubmodule.FG := ⟨{1}, by simp [Algebra.toSubmodule_bot, one_eq_span]⟩ theorem fg_unit {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (I : (Submodule R A)ˣ) : (I : Submodule R A).FG := by have : (1 : A) ∈ (I * ↑I⁻¹ : Submodule R A) := by rw [I.mul_inv] exact one_le.mp le_rfl obtain ⟨T, T', hT, hT', one_mem⟩ := mem_span_mul_finite_of_mem_mul this refine ⟨T, span_eq_of_le _ hT ?_⟩ rw [← one_mul I, ← mul_one (span R (T : Set A))] conv_rhs => rw [← I.inv_mul, ← mul_assoc] refine mul_le_mul_left (le_trans ?_ <| mul_le_mul_right <| span_le.mpr hT') simp only [Units.val_one, span_mul_span] rwa [one_le] theorem fg_of_isUnit {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] {I : Submodule R A} (hI : IsUnit I) : I.FG := fg_unit hI.unit theorem fg_span {s : Set M} (hs : s.Finite) : FG (span R s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ theorem fg_span_singleton (x : M) : FG (R ∙ x) := fg_span (finite_singleton x) theorem FG.sup {N₁ N₂ : Submodule R 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 [span_union, ht₁.2, ht₂.2]⟩ theorem fg_finset_sup {ι : Type*} (s : Finset ι) (N : ι → Submodule R M) (h : ∀ i ∈ s, (N i).FG) : (s.sup N).FG := Finset.sup_induction fg_bot (fun _ ha _ hb => ha.sup hb) h theorem fg_biSup {ι : Type*} (s : Finset ι) (N : ι → Submodule R M) (h : ∀ i ∈ s, (N i).FG) : (⨆ i ∈ s, N i).FG := by simpa only [Finset.sup_eq_iSup] using fg_finset_sup s N h theorem fg_iSup {ι : Sort*} [Finite ι] (N : ι → Submodule R M) (h : ∀ i, (N i).FG) : (iSup N).FG := by cases nonempty_fintype (PLift ι) simpa [iSup_plift_down] using fg_biSup Finset.univ (N ∘ PLift.down) fun i _ => h i.down variable {P : Type*} [AddCommMonoid P] [Module R P] variable (f : M →ₗ[R] P) theorem FG.map {N : Submodule R M} (hs : N.FG) : (N.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [span_image, ht.2]⟩ variable {f} theorem fg_of_fg_map_injective (f : M →ₗ[R] P) (hf : Function.Injective f) {N : Submodule R M} (hfn : (N.map f).FG) : N.FG := let ⟨t, ht⟩ := hfn ⟨t.preimage f fun x _ y _ h => hf h, Submodule.map_injective_of_injective hf <| by rw [map_span, Finset.coe_preimage, Set.image_preimage_eq_inter_range, Set.inter_eq_self_of_subset_left, ht] rw [← LinearMap.range_coe, ← span_le, ht, ← map_top] exact map_mono le_top⟩ theorem fg_of_fg_map {R M P : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] (f : M →ₗ[R] P) (hf : LinearMap.ker f = ⊥) {N : Submodule R M} (hfn : (N.map f).FG) : N.FG := fg_of_fg_map_injective f (LinearMap.ker_eq_bot.1 hf) hfn theorem fg_top (N : Submodule R M) : (⊤ : Submodule R N).FG ↔ N.FG := ⟨fun h => N.range_subtype ▸ map_top N.subtype ▸ h.map _, fun h => fg_of_fg_map_injective N.subtype Subtype.val_injective <| by rwa [map_top, range_subtype]⟩ theorem fg_of_linearEquiv (e : M ≃ₗ[R] P) (h : (⊤ : Submodule R P).FG) : (⊤ : Submodule R M).FG := e.symm.range ▸ map_top (e.symm : P →ₗ[R] M) ▸ h.map _ theorem FG.prod {sb : Submodule R M} {sc : Submodule R P} (hsb : sb.FG) (hsc : sc.FG) : (sb.prod sc).FG := let ⟨tb, htb⟩ := fg_def.1 hsb let ⟨tc, htc⟩ := fg_def.1 hsc fg_def.2 ⟨LinearMap.inl R M P '' tb ∪ LinearMap.inr R M P '' tc, (htb.1.image _).union (htc.1.image _), by rw [LinearMap.span_inl_union_inr, htb.2, htc.2]⟩ theorem fg_pi {ι : Type*} {M : ι → Type*} [Finite ι] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] {p : ∀ i, Submodule R (M i)} (hsb : ∀ i, (p i).FG) : (Submodule.pi Set.univ p).FG := by classical simp_rw [fg_def] at hsb ⊢ choose t htf hts using hsb refine ⟨⋃ i, (LinearMap.single i : _ →ₗ[R] _) '' t i, Set.finite_iUnion fun i => (htf i).image _, ?_⟩ -- Note: #8386 changed `span_image` into `span_image _` simp_rw [span_iUnion, span_image _, hts, Submodule.iSup_map_single] /-- If 0 → M' → M → M'' → 0 is exact and M' and M'' are finitely generated then so is M. -/ theorem fg_of_fg_map_of_fg_inf_ker {R M P : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] (f : M →ₗ[R] P) {s : Submodule R M} (hs1 : (s.map f).FG) (hs2 : (s ⊓ LinearMap.ker f).FG) : s.FG := by haveI := Classical.decEq R haveI := Classical.decEq M haveI := Classical.decEq P cases' hs1 with t1 ht1 cases' hs2 with t2 ht2 have : ∀ y ∈ t1, ∃ x ∈ s, f x = y := by intro y hy have : y ∈ s.map f := by rw [← ht1] exact subset_span hy rcases mem_map.1 this with ⟨x, hx1, hx2⟩ exact ⟨x, hx1, hx2⟩ have : ∃ g : P → M, ∀ y ∈ t1, g y ∈ s ∧ f (g y) = y := by choose g hg1 hg2 using this exists fun y => if H : y ∈ t1 then g y H else 0 intro y H constructor · simp only [dif_pos H] apply hg1 · simp only [dif_pos H] apply hg2 cases' this with g hg clear this exists t1.image g ∪ t2 rw [Finset.coe_union, span_union, Finset.coe_image] apply le_antisymm · refine sup_le (span_le.2 <| image_subset_iff.2 ?_) (span_le.2 ?_) · intro y hy exact (hg y hy).1 · intro x hx have : x ∈ span R t2 := subset_span hx rw [ht2] at this exact this.1 intro x hx have : f x ∈ s.map f := by rw [mem_map] exact ⟨x, hx, rfl⟩ rw [← ht1, ← Set.image_id (t1 : Set P), Finsupp.mem_span_image_iff_total] at this rcases this with ⟨l, hl1, hl2⟩ refine mem_sup.2 ⟨(Finsupp.total M M R id).toFun ((Finsupp.lmapDomain R R g : (P →₀ R) → M →₀ R) l), ?_, x - Finsupp.total M M R id ((Finsupp.lmapDomain R R g : (P →₀ R) → M →₀ R) l), ?_, add_sub_cancel _ _⟩ · rw [← Set.image_id (g '' ↑t1), Finsupp.mem_span_image_iff_total] refine ⟨_, ?_, rfl⟩ haveI : Inhabited P := ⟨0⟩ rw [← Finsupp.lmapDomain_supported _ _ g, mem_map] refine ⟨l, hl1, ?_⟩ rfl rw [ht2, mem_inf] constructor · apply s.sub_mem hx rw [Finsupp.total_apply, Finsupp.lmapDomain_apply, Finsupp.sum_mapDomain_index] · refine s.sum_mem ?_ intro y hy exact s.smul_mem _ (hg y (hl1 hy)).1 · exact zero_smul _ · exact fun _ _ _ => add_smul _ _ _ · rw [LinearMap.mem_ker, f.map_sub, ← hl2] rw [Finsupp.total_apply, Finsupp.total_apply, Finsupp.lmapDomain_apply] rw [Finsupp.sum_mapDomain_index, Finsupp.sum, Finsupp.sum, map_sum] · rw [sub_eq_zero] refine Finset.sum_congr rfl fun y hy => ?_ unfold id rw [f.map_smul, (hg y (hl1 hy)).2] · exact zero_smul _ · exact fun _ _ _ => add_smul _ _ _ theorem fg_induction (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] (P : Submodule R M → Prop) (h₁ : ∀ x, P (Submodule.span R {x})) (h₂ : ∀ M₁ M₂, P M₁ → P M₂ → P (M₁ ⊔ M₂)) (N : Submodule R M) (hN : N.FG) : P N := by classical obtain ⟨s, rfl⟩ := hN induction s using Finset.induction · rw [Finset.coe_empty, Submodule.span_empty, ← Submodule.span_zero_singleton] apply h₁ · rw [Finset.coe_insert, Submodule.span_insert] apply h₂ <;> apply_assumption /-- The kernel of the composition of two linear maps is finitely generated if both kernels are and the first morphism is surjective. -/ theorem fg_ker_comp {R M N P : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] (f : M →ₗ[R] N) (g : N →ₗ[R] P) (hf1 : (LinearMap.ker f).FG) (hf2 : (LinearMap.ker g).FG) (hsur : Function.Surjective f) : (g.comp f).ker.FG := by rw [LinearMap.ker_comp] apply fg_of_fg_map_of_fg_inf_ker f · rwa [Submodule.map_comap_eq, LinearMap.range_eq_top.2 hsur, top_inf_eq] · rwa [inf_of_le_right (show (LinearMap.ker f) ≤ (LinearMap.ker g).comap f from comap_mono bot_le)] theorem fg_restrictScalars {R S M : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommGroup M] [Module S M] [Module R M] [IsScalarTower R S M] (N : Submodule S M) (hfin : N.FG) (h : Function.Surjective (algebraMap R S)) : (Submodule.restrictScalars R N).FG := by obtain ⟨X, rfl⟩ := hfin use X exact (Submodule.restrictScalars_span R S h (X : Set M)).symm theorem FG.stabilizes_of_iSup_eq {M' : Submodule R M} (hM' : M'.FG) (N : ℕ →o Submodule R M) (H : iSup N = M') : ∃ n, M' = N n := by obtain ⟨S, hS⟩ := hM' have : ∀ s : S, ∃ n, (s : M) ∈ N n := fun s => (Submodule.mem_iSup_of_chain N s).mp (by rw [H, ← hS] exact Submodule.subset_span s.2) choose f hf using this use S.attach.sup f apply le_antisymm · conv_lhs => rw [← hS] rw [Submodule.span_le] intro s hs exact N.2 (Finset.le_sup <| S.mem_attach ⟨s, hs⟩) (hf _) · rw [← H] exact le_iSup _ _ /-- Finitely generated submodules are precisely compact elements in the submodule lattice. -/ theorem fg_iff_compact (s : Submodule R M) : s.FG ↔ CompleteLattice.IsCompactElement s := by classical -- Introduce shorthand for span of an element let sp : M → Submodule R M := fun a => span R {a} -- Trivial rewrite lemma; a small hack since simp (only) & rw can't accomplish this smoothly. have supr_rw : ∀ t : Finset M, ⨆ x ∈ t, sp x = ⨆ x ∈ (↑t : Set M), sp x := fun t => by rfl constructor · rintro ⟨t, rfl⟩ rw [span_eq_iSup_of_singleton_spans, ← supr_rw, ← Finset.sup_eq_iSup t sp] apply CompleteLattice.isCompactElement_finsetSup exact fun n _ => singleton_span_isCompactElement n · intro h -- s is the Sup of the spans of its elements. have sSup' : s = sSup (sp '' ↑s) := by rw [sSup_eq_iSup, iSup_image, ← span_eq_iSup_of_singleton_spans, eq_comm, span_eq] -- by h, s is then below (and equal to) the sup of the spans of finitely many elements. obtain ⟨u, ⟨huspan, husup⟩⟩ := h (sp '' ↑s) (le_of_eq sSup') have ssup : s = u.sup id := by suffices u.sup id ≤ s from le_antisymm husup this rw [sSup', Finset.sup_id_eq_sSup] exact sSup_le_sSup huspan -- Porting note: had to split this out of the `obtain` have := Finset.subset_image_iff.mp huspan obtain ⟨t, ⟨-, rfl⟩⟩ := this rw [Finset.sup_image, Function.id_comp, Finset.sup_eq_iSup, supr_rw, ← span_eq_iSup_of_singleton_spans, eq_comm] at ssup exact ⟨t, ssup⟩ open TensorProduct LinearMap in /-- Every `x : I ⊗ M` is the image of some `y : J ⊗ M`, where `J ≤ I` is finitely generated, under the tensor product of `J.inclusion ‹J ≤ I› : J → I` and the identity `M → M`. -/ theorem exists_fg_le_eq_rTensor_inclusion {R M N : Type*} [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {I : Submodule R N} (x : I ⊗ M) : ∃ (J : Submodule R N) (_ : J.FG) (hle : J ≤ I) (y : J ⊗ M), x = rTensor M (J.inclusion hle) y := by induction x with | zero => exact ⟨⊥, fg_bot, zero_le _, 0, rfl⟩ | tmul i m => exact ⟨R ∙ i.val, fg_span_singleton i.val, (span_singleton_le_iff_mem _ _).mpr i.property, ⟨i.val, mem_span_singleton_self _⟩ ⊗ₜ[R] m, rfl⟩ | add x₁ x₂ ihx₁ ihx₂ => obtain ⟨J₁, hfg₁, hle₁, y₁, rfl⟩ := ihx₁ obtain ⟨J₂, hfg₂, hle₂, y₂, rfl⟩ := ihx₂ refine ⟨J₁ ⊔ J₂, hfg₁.sup hfg₂, sup_le hle₁ hle₂, rTensor M (J₁.inclusion (le_sup_left : J₁ ≤ J₁ ⊔ J₂)) y₁ + rTensor M (J₂.inclusion (le_sup_right : J₂ ≤ J₁ ⊔ J₂)) y₂, ?_⟩ rewrite [map_add, ← rTensor_comp_apply, ← rTensor_comp_apply] rfl end Submodule namespace Submodule section Map₂ variable {R M N P : Type*} variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [Module R M] [Module R N] [Module R P] theorem FG.map₂ (f : M →ₗ[R] N →ₗ[R] P) {p : Submodule R M} {q : Submodule R N} (hp : p.FG) (hq : q.FG) : (map₂ f p q).FG := let ⟨sm, hfm, hm⟩ := fg_def.1 hp let ⟨sn, hfn, hn⟩ := fg_def.1 hq fg_def.2 ⟨Set.image2 (fun m n => f m n) sm sn, hfm.image2 _ hfn, map₂_span_span R f sm sn ▸ hm ▸ hn ▸ rfl⟩ end Map₂ section Mul variable {R : Type*} {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable {M N : Submodule R A} theorem FG.mul (hm : M.FG) (hn : N.FG) : (M * N).FG := hm.map₂ _ hn theorem FG.pow (h : M.FG) (n : ℕ) : (M ^ n).FG := Nat.recOn n ⟨{1}, by simp [one_eq_span]⟩ fun n ih => by simpa [pow_succ] using ih.mul h end Mul end Submodule namespace Ideal variable {R : Type*} {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- An ideal of `R` is finitely generated if it is the span of a finite subset of `R`. This is defeq to `Submodule.FG`, but unfolds more nicely. -/ def FG (I : Ideal R) : Prop := ∃ S : Finset R, Ideal.span ↑S = I /-- The image of a finitely generated ideal is finitely generated. This is the `Ideal` version of `Submodule.FG.map`. -/ theorem FG.map {R S : Type*} [Semiring R] [Semiring S] {I : Ideal R} (h : I.FG) (f : R →+* S) : (I.map f).FG := by classical obtain ⟨s, hs⟩ := h refine ⟨s.image f, ?_⟩ rw [Finset.coe_image, ← Ideal.map_span, hs] theorem fg_ker_comp {R S A : Type*} [CommRing R] [CommRing S] [CommRing A] (f : R →+* S) (g : S →+* A) (hf : f.ker.FG) (hg : g.ker.FG) (hsur : Function.Surjective f) : (g.comp f).ker.FG := by letI : Algebra R S := RingHom.toAlgebra f letI : Algebra R A := RingHom.toAlgebra (g.comp f) letI : Algebra S A := RingHom.toAlgebra g letI : IsScalarTower R S A := IsScalarTower.of_algebraMap_eq fun _ => rfl let f₁ := Algebra.linearMap R S let g₁ := (IsScalarTower.toAlgHom R S A).toLinearMap exact Submodule.fg_ker_comp f₁ g₁ hf (Submodule.fg_restrictScalars (RingHom.ker g) hg hsur) hsur theorem exists_radical_pow_le_of_fg {R : Type*} [CommSemiring R] (I : Ideal R) (h : I.radical.FG) : ∃ n : ℕ, I.radical ^ n ≤ I := by have := le_refl I.radical; revert this refine Submodule.fg_induction _ _ (fun J => J ≤ I.radical → ∃ n : ℕ, J ^ n ≤ I) ?_ ?_ _ h · intro x hx obtain ⟨n, hn⟩ := hx (subset_span (Set.mem_singleton x)) exact ⟨n, by rwa [← Ideal.span, span_singleton_pow, span_le, Set.singleton_subset_iff]⟩ · intro J K hJ hK hJK obtain ⟨n, hn⟩ := hJ fun x hx => hJK <| Ideal.mem_sup_left hx obtain ⟨m, hm⟩ := hK fun x hx => hJK <| Ideal.mem_sup_right hx use n + m rw [← Ideal.add_eq_sup, add_pow, Ideal.sum_eq_sup, Finset.sup_le_iff] refine fun i _ => Ideal.mul_le_right.trans ?_ obtain h | h := le_or_lt n i · apply Ideal.mul_le_right.trans ((Ideal.pow_le_pow_right h).trans hn) · apply Ideal.mul_le_left.trans refine (Ideal.pow_le_pow_right ?_).trans hm rw [add_comm, Nat.add_sub_assoc h.le] apply Nat.le_add_right end Ideal section ModuleAndAlgebra variable (R A B M N : Type*) /-- A module over a semiring is `Finite` if it is finitely generated as a module. -/ class Module.Finite [Semiring R] [AddCommMonoid M] [Module R M] : Prop where out : (⊤ : Submodule R M).FG attribute [inherit_doc Module.Finite] Module.Finite.out namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] theorem finite_def {R M} [Semiring R] [AddCommMonoid M] [Module R M] : Finite R M ↔ (⊤ : Submodule R M).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ namespace Finite open Submodule Set theorem iff_addMonoid_fg {M : Type*} [AddCommMonoid M] : Module.Finite ℕ M ↔ AddMonoid.FG M := ⟨fun h => AddMonoid.fg_def.2 <| (Submodule.fg_iff_addSubmonoid_fg ⊤).1 (finite_def.1 h), fun h => finite_def.2 <| (Submodule.fg_iff_addSubmonoid_fg ⊤).2 (AddMonoid.fg_def.1 h)⟩ theorem iff_addGroup_fg {G : Type*} [AddCommGroup G] : Module.Finite ℤ G ↔ AddGroup.FG G := ⟨fun h => AddGroup.fg_def.2 <| (Submodule.fg_iff_add_subgroup_fg ⊤).1 (finite_def.1 h), fun h => finite_def.2 <| (Submodule.fg_iff_add_subgroup_fg ⊤).2 (AddGroup.fg_def.1 h)⟩ variable {R M N} /-- See also `Module.Finite.exists_fin'`. -/ theorem exists_fin [Finite R M] : ∃ (n : ℕ) (s : Fin n → M), Submodule.span R (range s) = ⊤ := Submodule.fg_iff_exists_fin_generating_family.mp out variable (R M) in lemma exists_fin' [Finite R M] : ∃ (n : ℕ) (f : (Fin n → R) →ₗ[R] M), Surjective f := by have ⟨n, s, hs⟩ := exists_fin (R := R) (M := M) refine ⟨n, Basis.constr (Pi.basisFun R _) ℕ s, ?_⟩ rw [← LinearMap.range_eq_top, Basis.constr_range, hs] theorem of_surjective [hM : Finite R M] (f : M →ₗ[R] N) (hf : Surjective f) : Finite R N := ⟨by rw [← LinearMap.range_eq_top.2 hf, ← Submodule.map_top] exact hM.1.map f⟩ instance quotient (R) {A M} [Semiring R] [AddCommGroup M] [Ring A] [Module A M] [Module R M] [SMul R A] [IsScalarTower R A M] [Finite R M] (N : Submodule A M) : Finite R (M ⧸ N) := Module.Finite.of_surjective (N.mkQ.restrictScalars R) N.mkQ_surjective /-- The range of a linear map from a finite module is finite. -/ instance range {F : Type*} [FunLike F M N] [SemilinearMapClass F (RingHom.id R) M N] [Finite R M] (f : F) : Finite R (LinearMap.range f) := of_surjective (SemilinearMapClass.semilinearMap f).rangeRestrict fun ⟨_, y, hy⟩ => ⟨y, Subtype.ext hy⟩ /-- Pushforwards of finite submodules are finite. -/ instance map (p : Submodule R M) [Finite R p] (f : M →ₗ[R] N) : Finite R (p.map f) := of_surjective (f.restrict fun _ => Submodule.mem_map_of_mem) fun ⟨_, _, hy, hy'⟩ => ⟨⟨_, hy⟩, Subtype.ext hy'⟩ variable (R) instance self : Finite R R := ⟨⟨{1}, by simpa only [Finset.coe_singleton] using Ideal.span_singleton_one⟩⟩ variable (M) theorem of_restrictScalars_finite (R A M : Type*) [CommSemiring R] [Semiring A] [AddCommMonoid M] [Module R M] [Module A M] [Algebra R A] [IsScalarTower R A M] [hM : Finite R M] : Finite A M := by rw [finite_def, Submodule.fg_def] at hM ⊢ obtain ⟨S, hSfin, hSgen⟩ := hM refine ⟨S, hSfin, eq_top_iff.2 ?_⟩ have := Submodule.span_le_restrictScalars R A S rw [hSgen] at this exact this variable {R M} instance prod [hM : Finite R M] [hN : Finite R N] : Finite R (M × N) := ⟨by rw [← Submodule.prod_top] exact hM.1.prod hN.1⟩ instance pi {ι : Type*} {M : ι → Type*} [_root_.Finite ι] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [h : ∀ i, Finite R (M i)] : Finite R (∀ i, M i) := ⟨by rw [← Submodule.pi_top] exact Submodule.fg_pi fun i => (h i).1⟩ theorem equiv [Finite R M] (e : M ≃ₗ[R] N) : Finite R N := of_surjective (e : M →ₗ[R] N) e.surjective theorem equiv_iff (e : M ≃ₗ[R] N) : Finite R M ↔ Finite R N := ⟨fun _ ↦ equiv e, fun _ ↦ equiv e.symm⟩ instance ulift [Finite R M] : Finite R (ULift M) := equiv ULift.moduleEquiv.symm theorem iff_fg {N : Submodule R M} : Module.Finite R N ↔ N.FG := Module.finite_def.trans (fg_top _) variable (R M) instance bot : Module.Finite R (⊥ : Submodule R M) := iff_fg.mpr fg_bot instance top [Finite R M] : Module.Finite R (⊤ : Submodule R M) := iff_fg.mpr out variable {M} /-- The submodule generated by a finite set is `R`-finite. -/ theorem span_of_finite {A : Set M} (hA : Set.Finite A) : Module.Finite R (Submodule.span R A) := ⟨(Submodule.fg_top _).mpr ⟨hA.toFinset, hA.coe_toFinset.symm ▸ rfl⟩⟩ /-- The submodule generated by a single element is `R`-finite. -/ instance span_singleton (x : M) : Module.Finite R (R ∙ x) := Module.Finite.span_of_finite R <| Set.finite_singleton _ /-- The submodule generated by a finset is `R`-finite. -/ instance span_finset (s : Finset M) : Module.Finite R (span R (s : Set M)) := ⟨(Submodule.fg_top _).mpr ⟨s, rfl⟩⟩ theorem Module.End.isNilpotent_iff_of_finite {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] [Module.Finite R M] {f : End R M} : IsNilpotent f ↔ ∀ m : M, ∃ n : ℕ, (f ^ n) m = 0 := by refine ⟨fun ⟨n, hn⟩ m ↦ ⟨n, by simp [hn]⟩, fun h ↦ ?_⟩ rcases Module.Finite.out (R := R) (M := M) with ⟨S, hS⟩ choose g hg using h use Finset.sup S g ext m have hm : m ∈ Submodule.span R S := by simp [hS] induction hm using Submodule.span_induction' with | mem x hx => exact LinearMap.pow_map_zero_of_le (Finset.le_sup hx) (hg x) | zero => simp | add => simp_all | smul => simp_all variable {R} section Algebra theorem trans {R : Type*} (A M : Type*) [Semiring R] [Semiring A] [Module R A] [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] : ∀ [Finite R A] [Finite A M], Finite R M | ⟨⟨s, hs⟩⟩, ⟨⟨t, ht⟩⟩ => ⟨Submodule.fg_def.2 ⟨Set.image2 (· • ·) (↑s : Set A) (↑t : Set M), Set.Finite.image2 _ s.finite_toSet t.finite_toSet, by erw [Set.image2_smul, Submodule.span_smul_of_span_eq_top hs (↑t : Set M), ht, Submodule.restrictScalars_top]⟩⟩ lemma of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommRing A₁] [CommRing B₁] [CommRing A₂] [CommRing B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂) (he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁)) [Module.Finite A₁ B₁] : Module.Finite A₂ B₂ := by letI := e₁.toRingHom.toAlgebra letI := ((algebraMap A₁ B₁).comp e₁.symm.toRingHom).toAlgebra haveI : IsScalarTower A₁ A₂ B₁ := IsScalarTower.of_algebraMap_eq (fun x ↦ by simp [RingHom.algebraMap_toAlgebra]) let e : B₁ ≃ₐ[A₂] B₂ := { e₂ with commutes' := fun r ↦ by simpa [RingHom.algebraMap_toAlgebra] using DFunLike.congr_fun he.symm (e₁.symm r) } haveI := Module.Finite.of_restrictScalars_finite A₁ A₂ B₁ exact Module.Finite.equiv e.toLinearEquiv end Algebra end Finite end Module /-- Porting note: reminding Lean about this instance for Module.Finite.base_change -/ noncomputable local instance [CommSemiring R] [Semiring A] [Algebra R A] [AddCommMonoid M] [Module R M] : Module A (TensorProduct R A M) := haveI : SMulCommClass R A A := IsScalarTower.to_smulCommClass TensorProduct.leftModule instance Module.Finite.base_change [CommSemiring R] [Semiring A] [Algebra R A] [AddCommMonoid M] [Module R M] [h : Module.Finite R M] : Module.Finite A (TensorProduct R A M) := by classical obtain ⟨s, hs⟩ := h.out refine ⟨⟨s.image (TensorProduct.mk R A M 1), eq_top_iff.mpr ?_⟩⟩ rintro x - induction x with | zero => exact zero_mem _ | tmul x y => -- Porting note: new TC reminder haveI : IsScalarTower R A (TensorProduct R A M) := TensorProduct.isScalarTower_left rw [Finset.coe_image, ← Submodule.span_span_of_tower R, Submodule.span_image, hs, Submodule.map_top, LinearMap.range_coe] change _ ∈ Submodule.span A (Set.range <| TensorProduct.mk R A M 1) rw [← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul'] exact Submodule.smul_mem _ x (Submodule.subset_span <| Set.mem_range_self y) | add x y hx hy => exact Submodule.add_mem _ hx hy instance Module.Finite.tensorProduct [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] [hM : Module.Finite R M] [hN : Module.Finite R N] : Module.Finite R (TensorProduct R M N) where out := (TensorProduct.map₂_mk_top_top_eq_top R M N).subst (hM.out.map₂ _ hN.out) /-- If a free module is finite, then any arbitrary basis is finite. -/ lemma Module.Finite.finite_basis {R M} [Ring R] [Nontrivial R] [AddCommGroup M] [Module R M] {ι} [Module.Finite R M] (b : Basis ι R M) : _root_.Finite ι := let ⟨s, hs⟩ := ‹Module.Finite R M› basis_finite_of_finite_spans (↑s) s.finite_toSet hs b end ModuleAndAlgebra namespace Submodule open Module variable {R V} [Ring R] [AddCommGroup V] [Module R V] /-- The sup of two fg submodules is finite. Also see `Submodule.FG.sup`. -/ instance finite_sup (S₁ S₂ : Submodule R V) [h₁ : Module.Finite R S₁] [h₂ : Module.Finite R S₂] : Module.Finite R (S₁ ⊔ S₂ : Submodule R V) := by rw [finite_def] at * exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂)) /-- The submodule generated by a finite supremum of finite dimensional submodules is finite-dimensional. Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but that doesn't work well with typeclass search. -/ instance finite_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule R V) [∀ i, Module.Finite R (S i)] : Module.Finite R (s.sup S : Submodule R V) := by refine @Finset.sup_induction _ _ _ _ s S (fun i => Module.Finite R ↑i) (Module.Finite.bot R V) ?_ fun i _ => by infer_instance intro S₁ hS₁ S₂ hS₂ exact Submodule.finite_sup S₁ S₂ /-- The submodule generated by a supremum of finite dimensional submodules, indexed by a finite sort is finite-dimensional. -/ instance finite_iSup {ι : Sort*} [Finite ι] (S : ι → Submodule R V) [∀ i, Module.Finite R (S i)] : Module.Finite R ↑(⨆ i, S i) := by cases nonempty_fintype (PLift ι) rw [← iSup_plift_down, ← Finset.sup_univ_eq_iSup] exact Submodule.finite_finset_sup _ _ end Submodule section variable {R V} [Ring R] [AddCommGroup V] [Module R V] instance Module.Finite.finsupp {ι : Type*} [_root_.Finite ι] [Module.Finite R V] : Module.Finite R (ι →₀ V) := Module.Finite.equiv (Finsupp.linearEquivFunOnFinite R V ι).symm end namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is `Finite` if `B` is finitely generated as `A`-module. -/ def Finite (f : A →+* B) : Prop := letI : Algebra A B := f.toAlgebra Module.Finite A B namespace Finite variable (A) theorem id : Finite (RingHom.id A) := Module.Finite.self A variable {A} theorem of_surjective (f : A →+* B) (hf : Surjective f) : f.Finite := letI := f.toAlgebra Module.Finite.of_surjective (Algebra.linearMap A B) hf theorem comp {g : B →+* C} {f : A →+* B} (hg : g.Finite) (hf : f.Finite) : (g.comp f).Finite := by letI := f.toAlgebra letI := g.toAlgebra letI := (g.comp f).toAlgebra letI : IsScalarTower A B C := RestrictScalars.isScalarTower A B C letI : Module.Finite A B := hf letI : Module.Finite B C := hg exact Module.Finite.trans B C theorem of_comp_finite {f : A →+* B} {g : B →+* C} (h : (g.comp f).Finite) : g.Finite := by letI := f.toAlgebra letI := g.toAlgebra letI := (g.comp f).toAlgebra letI : IsScalarTower A B C := RestrictScalars.isScalarTower A B C letI : Module.Finite A C := h exact Module.Finite.of_restrictScalars_finite A B C end Finite end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is finite if it is finite as ring morphism. In other words, if `B` is finitely generated as `A`-module. -/ def Finite (f : A →ₐ[R] B) : Prop := f.toRingHom.Finite namespace Finite variable (R A) theorem id : Finite (AlgHom.id R A) := RingHom.Finite.id A variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.Finite) (hf : f.Finite) : (g.comp f).Finite := RingHom.Finite.comp hg hf theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) : f.Finite := RingHom.Finite.of_surjective f.toRingHom hf theorem of_comp_finite {f : A →ₐ[R] B} {g : B →ₐ[R] C} (h : (g.comp f).Finite) : g.Finite := RingHom.Finite.of_comp_finite h end Finite end AlgHom instance Subalgebra.finite_bot {F E : Type*} [CommSemiring F] [Semiring E] [Algebra F E] : Module.Finite F (⊥ : Subalgebra F E) := Module.Finite.range (Algebra.linearMap F E)
RingTheory\FinitePresentation.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.MvPolynomial.Tower import Mathlib.RingTheory.Ideal.QuotientOperations /-! # Finiteness conditions in commutative algebra In this file we define several notions of finiteness that are common in commutative algebra. ## Main declarations - `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite` all of these express that some object is finitely generated *as module* over some base ring. - `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType` all of these express that some object is finitely generated *as algebra* over some base ring. - `Algebra.FinitePresentation`, `RingHom.FinitePresentation`, `AlgHom.FinitePresentation` all of these express that some object is finitely presented *as algebra* over some base ring. -/ open Function (Surjective) open Polynomial section ModuleAndAlgebra universe w₁ w₂ w₃ -- Porting note: `M, N` is never used variable (R : Type w₁) (A : Type w₂) (B : Type w₃) /-- An algebra over a commutative semiring is `Algebra.FinitePresentation` if it is the quotient of a polynomial ring in `n` variables by a finitely generated ideal. -/ class Algebra.FinitePresentation [CommSemiring R] [Semiring A] [Algebra R A] : Prop where out : ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] A), Surjective f ∧ f.toRingHom.ker.FG namespace Algebra variable [CommRing R] [CommRing A] [Algebra R A] [CommRing B] [Algebra R B] namespace FiniteType variable {R A B} /-- A finitely presented algebra is of finite type. -/ instance of_finitePresentation [FinitePresentation R A] : FiniteType R A := by obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A) apply FiniteType.iff_quotient_mvPolynomial''.2 exact ⟨n, f, hf.1⟩ end FiniteType namespace FinitePresentation variable {R A B} /-- An algebra over a Noetherian ring is finitely generated if and only if it is finitely presented. -/ theorem of_finiteType [IsNoetherianRing R] : FiniteType R A ↔ FinitePresentation R A := by refine ⟨fun h => ?_, fun hfp => Algebra.FiniteType.of_finitePresentation⟩ obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.1 h refine ⟨n, f, hf, ?_⟩ have hnoet : IsNoetherianRing (MvPolynomial (Fin n) R) := by infer_instance -- Porting note: rewrote code to help typeclass inference rw [isNoetherianRing_iff] at hnoet letI : Module (MvPolynomial (Fin n) R) (MvPolynomial (Fin n) R) := Semiring.toModule have := hnoet.noetherian (RingHom.ker f.toRingHom) convert this /-- If `e : A ≃ₐ[R] B` and `A` is finitely presented, then so is `B`. -/ theorem equiv [FinitePresentation R A] (e : A ≃ₐ[R] B) : FinitePresentation R B := by obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A) use n, AlgHom.comp (↑e) f constructor · rw [AlgHom.coe_comp] exact Function.Surjective.comp e.surjective hf.1 suffices (RingHom.ker (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom) = RingHom.ker f.toRingHom by rw [this] exact hf.2 have hco : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = RingHom.comp (e.toRingEquiv : A ≃+* B) f.toRingHom := by have h : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = e.toAlgHom.toRingHom.comp f.toRingHom := rfl have h1 : ↑e.toRingEquiv = e.toAlgHom.toRingHom := rfl rw [h, h1] rw [RingHom.ker_eq_comap_bot, hco, ← Ideal.comap_comap, ← RingHom.ker_eq_comap_bot, RingHom.ker_coe_equiv (AlgEquiv.toRingEquiv e), RingHom.ker_eq_comap_bot] variable (R) /-- The ring of polynomials in finitely many variables is finitely presented. -/ protected instance mvPolynomial (ι : Type*) [Finite ι] : FinitePresentation R (MvPolynomial ι R) where out := by cases nonempty_fintype ι let eqv := (MvPolynomial.renameEquiv R <| Fintype.equivFin ι).symm exact ⟨Fintype.card ι, eqv, eqv.surjective, ((RingHom.injective_iff_ker_eq_bot _).1 eqv.injective).symm ▸ Submodule.fg_bot⟩ /-- `R` is finitely presented as `R`-algebra. -/ instance self : FinitePresentation R R := -- Porting note: replaced `PEmpty` with `Empty` equiv (MvPolynomial.isEmptyAlgEquiv R Empty) /-- `R[X]` is finitely presented as `R`-algebra. -/ instance polynomial : FinitePresentation R R[X] := -- Porting note: replaced `PUnit` with `Unit` letI := FinitePresentation.mvPolynomial R Unit equiv (MvPolynomial.pUnitAlgEquiv R) variable {R} /-- The quotient of a finitely presented algebra by a finitely generated ideal is finitely presented. -/ protected theorem quotient {I : Ideal A} (h : I.FG) [FinitePresentation R A] : FinitePresentation R (A ⧸ I) where out := by obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A) refine ⟨n, (Ideal.Quotient.mkₐ R I).comp f, ?_, ?_⟩ · exact (Ideal.Quotient.mkₐ_surjective R I).comp hf.1 · refine Ideal.fg_ker_comp _ _ hf.2 ?_ hf.1 simp [h] /-- If `f : A →ₐ[R] B` is surjective with finitely generated kernel and `A` is finitely presented, then so is `B`. -/ theorem of_surjective {f : A →ₐ[R] B} (hf : Function.Surjective f) (hker : f.toRingHom.ker.FG) [FinitePresentation R A] : FinitePresentation R B := letI : FinitePresentation R (A ⧸ RingHom.ker f) := FinitePresentation.quotient hker equiv (Ideal.quotientKerAlgEquivOfSurjective hf) theorem iff : FinitePresentation R A ↔ ∃ (n : _) (I : Ideal (MvPolynomial (Fin n) R)) (_ : (_ ⧸ I) ≃ₐ[R] A), I.FG := by constructor · rintro ⟨n, f, hf⟩ exact ⟨n, RingHom.ker f.toRingHom, Ideal.quotientKerAlgEquivOfSurjective hf.1, hf.2⟩ · rintro ⟨n, I, e, hfg⟩ letI := (FinitePresentation.mvPolynomial R _).quotient hfg exact equiv e /-- An algebra is finitely presented if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype by a finitely generated ideal. -/ theorem iff_quotient_mvPolynomial' : FinitePresentation R A ↔ ∃ (ι : Type*) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] A), Surjective f ∧ f.toRingHom.ker.FG := by constructor · rintro ⟨n, f, hfs, hfk⟩ set ulift_var := MvPolynomial.renameEquiv R Equiv.ulift refine ⟨ULift (Fin n), inferInstance, f.comp ulift_var.toAlgHom, hfs.comp ulift_var.surjective, Ideal.fg_ker_comp _ _ ?_ hfk ulift_var.surjective⟩ erw [RingHom.ker_coe_equiv ulift_var.toRingEquiv] exact Submodule.fg_bot -- Porting note: was -- convert Submodule.fg_bot -- exact RingHom.ker_coe_equiv ulift_var.toRingEquiv · rintro ⟨ι, hfintype, f, hf⟩ have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι) use Fintype.card ι, f.comp equiv.symm, hf.1.comp (AlgEquiv.symm equiv).surjective refine Ideal.fg_ker_comp (S := MvPolynomial ι R) (A := A) _ f ?_ hf.2 equiv.symm.surjective erw [RingHom.ker_coe_equiv equiv.symm.toRingEquiv] exact Submodule.fg_bot -- Porting note: was -- convert Submodule.fg_bot -- exact RingHom.ker_coe_equiv equiv.symm.toRingEquiv universe v in -- Porting note: make universe level explicit to ensure `ι, ι'` has the same universe level /-- If `A` is a finitely presented `R`-algebra, then `MvPolynomial (Fin n) A` is finitely presented as `R`-algebra. -/ theorem mvPolynomial_of_finitePresentation [FinitePresentation.{w₁, w₂} R A] (ι : Type v) [Finite ι] : FinitePresentation.{w₁, max v w₂} R (MvPolynomial ι A) := by have hfp : FinitePresentation.{w₁, w₂} R A := inferInstance rw [iff_quotient_mvPolynomial'] at hfp ⊢ classical -- Porting note: use the same universe level obtain ⟨(ι' : Type v), _, f, hf_surj, hf_ker⟩ := hfp let g := (MvPolynomial.mapAlgHom f).comp (MvPolynomial.sumAlgEquiv R ι ι').toAlgHom cases nonempty_fintype (ι ⊕ ι') refine ⟨ι ⊕ ι', by infer_instance, g, (MvPolynomial.map_surjective f.toRingHom hf_surj).comp (AlgEquiv.surjective _), Ideal.fg_ker_comp _ _ ?_ ?_ (AlgEquiv.surjective _)⟩ · erw [RingHom.ker_coe_equiv (MvPolynomial.sumAlgEquiv R ι ι').toRingEquiv] exact Submodule.fg_bot -- Porting note: was -- convert Submodule.fg_bot -- exact RingHom.ker_coe_equiv (MvPolynomial.sumAlgEquiv R ι ι').toRingEquiv · rw [AlgHom.toRingHom_eq_coe, MvPolynomial.mapAlgHom_coe_ringHom, MvPolynomial.ker_map] exact hf_ker.map MvPolynomial.C variable (R A B) /-- If `A` is an `R`-algebra and `S` is an `A`-algebra, both finitely presented, then `S` is finitely presented as `R`-algebra. -/ theorem trans [Algebra A B] [IsScalarTower R A B] [FinitePresentation R A] [FinitePresentation A B] : FinitePresentation R B := by have hfpB : FinitePresentation A B := inferInstance obtain ⟨n, I, e, hfg⟩ := iff.1 hfpB letI : FinitePresentation R (MvPolynomial (Fin n) A ⧸ I) := (mvPolynomial_of_finitePresentation _).quotient hfg exact equiv (e.restrictScalars R) open MvPolynomial -- We follow the proof of https://stacks.math.columbia.edu/tag/0561 -- TODO: extract out helper lemmas and tidy proof. theorem of_restrict_scalars_finitePresentation [Algebra A B] [IsScalarTower R A B] [FinitePresentation.{w₁, w₃} R B] [FiniteType R A] : FinitePresentation.{w₂, w₃} A B := by classical obtain ⟨n, f, hf, s, hs⟩ := FinitePresentation.out (R := R) (A := B) letI RX := MvPolynomial (Fin n) R letI AX := MvPolynomial (Fin n) A refine ⟨n, MvPolynomial.aeval (f ∘ X), ?_, ?_⟩ · rw [← Algebra.range_top_iff_surjective, ← Algebra.adjoin_range_eq_range_aeval, Set.range_comp f MvPolynomial.X, eq_top_iff, ← @adjoin_adjoin_of_tower R A B, adjoin_image, adjoin_range_X, Algebra.map_top, (Algebra.range_top_iff_surjective _).mpr hf] exact fun {x} => subset_adjoin ⟨⟩ · obtain ⟨t, ht⟩ := FiniteType.out (R := R) (A := A) have := fun i : t => hf (algebraMap A B i) choose t' ht' using this have ht'' : Algebra.adjoin R (algebraMap A AX '' t ∪ Set.range (X : _ → AX)) = ⊤ := by rw [adjoin_union_eq_adjoin_adjoin, ← Subalgebra.restrictScalars_top R (A := AX) (S := { x // x ∈ adjoin R ((algebraMap A AX) '' t) })] refine congrArg (Subalgebra.restrictScalars R) ?_ rw [adjoin_algebraMap, ht] apply Subalgebra.restrictScalars_injective R rw [← adjoin_restrictScalars, adjoin_range_X, Subalgebra.restrictScalars_top, Subalgebra.restrictScalars_top] letI g : t → AX := fun x => MvPolynomial.C (x : A) - map (algebraMap R A) (t' x) refine ⟨s.image (map (algebraMap R A)) ∪ t.attach.image g, ?_⟩ rw [Finset.coe_union, Finset.coe_image, Finset.coe_image, Finset.attach_eq_univ, Finset.coe_univ, Set.image_univ] let s₀ := (MvPolynomial.map (algebraMap R A)) '' s ∪ Set.range g let I := RingHom.ker (MvPolynomial.aeval (R := A) (f ∘ MvPolynomial.X)) change Ideal.span s₀ = I have leI : Ideal.span ((MvPolynomial.map (algebraMap R A)) '' s ∪ Set.range g) ≤ RingHom.ker (MvPolynomial.aeval (R := A) (f ∘ MvPolynomial.X)) := by rw [Ideal.span_le] rintro _ (⟨x, hx, rfl⟩ | ⟨⟨x, hx⟩, rfl⟩) <;> erw [RingHom.mem_ker] · rw [MvPolynomial.aeval_map_algebraMap (R := R) (A := A), ← aeval_unique] have := Ideal.subset_span hx rwa [hs] at this · rw [map_sub, MvPolynomial.aeval_map_algebraMap, ← aeval_unique, MvPolynomial.aeval_C, ht', Subtype.coe_mk, sub_self] apply leI.antisymm intro x hx rw [RingHom.mem_ker] at hx let s₀ := (MvPolynomial.map (algebraMap R A)) '' ↑s ∪ Set.range g change x ∈ Ideal.span s₀ have : x ∈ (MvPolynomial.map (algebraMap R A) : _ →+* AX).range.toAddSubmonoid ⊔ (Ideal.span s₀).toAddSubmonoid := by have : x ∈ (⊤ : Subalgebra R AX) := trivial rw [← ht''] at this refine adjoin_induction this ?_ ?_ ?_ ?_ · rintro _ (⟨x, hx, rfl⟩ | ⟨i, rfl⟩) · rw [MvPolynomial.algebraMap_eq, ← sub_add_cancel (MvPolynomial.C x) (map (algebraMap R A) (t' ⟨x, hx⟩)), add_comm] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · apply Ideal.subset_span apply Set.mem_union_right exact Set.mem_range_self _ · apply AddSubmonoid.mem_sup_left exact ⟨X i, map_X _ _⟩ · intro r apply AddSubmonoid.mem_sup_left exact ⟨C r, map_C _ _⟩ · intro _ _ h₁ h₂ exact add_mem h₁ h₂ · intro x₁ x₂ h₁ h₂ obtain ⟨_, ⟨p₁, rfl⟩, q₁, hq₁, rfl⟩ := AddSubmonoid.mem_sup.mp h₁ obtain ⟨_, ⟨p₂, rfl⟩, q₂, hq₂, rfl⟩ := AddSubmonoid.mem_sup.mp h₂ rw [add_mul, mul_add, add_assoc, ← map_mul] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · refine add_mem (Ideal.mul_mem_left _ _ hq₂) (Ideal.mul_mem_right _ _ hq₁) obtain ⟨_, ⟨p, rfl⟩, q, hq, rfl⟩ := AddSubmonoid.mem_sup.mp this rw [map_add, aeval_map_algebraMap, ← aeval_unique, show MvPolynomial.aeval (f ∘ X) q = 0 from leI hq, add_zero] at hx suffices Ideal.span (s : Set RX) ≤ (Ideal.span s₀).comap (MvPolynomial.map <| algebraMap R A) by refine add_mem ?_ hq rw [hs] at this exact this hx rw [Ideal.span_le] intro x hx apply Ideal.subset_span apply Set.mem_union_left exact Set.mem_image_of_mem _ hx variable {R A B} -- TODO: extract out helper lemmas and tidy proof. /-- This is used to prove the strictly stronger `ker_fg_of_surjective`. Use it instead. -/ theorem ker_fg_of_mvPolynomial {n : ℕ} (f : MvPolynomial (Fin n) R →ₐ[R] A) (hf : Function.Surjective f) [FinitePresentation R A] : f.toRingHom.ker.FG := by classical obtain ⟨m, f', hf', s, hs⟩ := FinitePresentation.out (R := R) (A := A) let RXn := MvPolynomial (Fin n) R let RXm := MvPolynomial (Fin m) R have := fun i : Fin n => hf' (f <| X i) choose g hg using this have := fun i : Fin m => hf (f' <| X i) choose h hh using this let aeval_h : RXm →ₐ[R] RXn := aeval h let g' : Fin n → RXn := fun i => X i - aeval_h (g i) refine ⟨Finset.univ.image g' ∪ s.image aeval_h, ?_⟩ simp only [Finset.coe_image, Finset.coe_union, Finset.coe_univ, Set.image_univ] have hh' : ∀ x, f (aeval_h x) = f' x := by intro x rw [← f.coe_toRingHom, map_aeval] simp_rw [AlgHom.coe_toRingHom, hh] rw [AlgHom.comp_algebraMap, ← aeval_eq_eval₂Hom, -- Porting note: added line below ← funext fun i => Function.comp_apply (f := ↑f') (g := MvPolynomial.X), ← aeval_unique] let s' := Set.range g' ∪ aeval_h '' s have leI : Ideal.span s' ≤ RingHom.ker f.toRingHom := by rw [Ideal.span_le] rintro _ (⟨i, rfl⟩ | ⟨x, hx, rfl⟩) · change f (g' i) = 0 rw [map_sub, ← hg, hh', sub_self] · change f (aeval_h x) = 0 rw [hh'] change x ∈ RingHom.ker f'.toRingHom rw [← hs] exact Ideal.subset_span hx apply leI.antisymm intro x hx have : x ∈ aeval_h.range.toAddSubmonoid ⊔ (Ideal.span s').toAddSubmonoid := by have : x ∈ adjoin R (Set.range X : Set RXn) := by rw [adjoin_range_X] trivial refine adjoin_induction this ?_ ?_ ?_ ?_ · rintro _ ⟨i, rfl⟩ rw [← sub_add_cancel (X i) (aeval h (g i)), add_comm] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · apply Submodule.subset_span apply Set.mem_union_left exact Set.mem_range_self _ · intro r apply AddSubmonoid.mem_sup_left exact ⟨C r, aeval_C _ _⟩ · intro _ _ h₁ h₂ exact add_mem h₁ h₂ · intro p₁ p₂ h₁ h₂ obtain ⟨_, ⟨x₁, rfl⟩, y₁, hy₁, rfl⟩ := AddSubmonoid.mem_sup.mp h₁ obtain ⟨_, ⟨x₂, rfl⟩, y₂, hy₂, rfl⟩ := AddSubmonoid.mem_sup.mp h₂ rw [mul_add, add_mul, add_assoc, ← map_mul] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · exact add_mem (Ideal.mul_mem_right _ _ hy₁) (Ideal.mul_mem_left _ _ hy₂) obtain ⟨_, ⟨x, rfl⟩, y, hy, rfl⟩ := AddSubmonoid.mem_sup.mp this refine add_mem ?_ hy simp only [RingHom.mem_ker, AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom, map_add, show f y = 0 from leI hy, add_zero, hh'] at hx suffices Ideal.span (s : Set RXm) ≤ (Ideal.span s').comap aeval_h by apply this rwa [hs] rw [Ideal.span_le] intro x hx apply Submodule.subset_span apply Set.mem_union_right exact Set.mem_image_of_mem _ hx /-- If `f : A →ₐ[R] B` is a surjection between finitely-presented `R`-algebras, then the kernel of `f` is finitely generated. -/ theorem ker_fG_of_surjective (f : A →ₐ[R] B) (hf : Function.Surjective f) [FinitePresentation R A] [FinitePresentation R B] : f.toRingHom.ker.FG := by obtain ⟨n, g, hg, _⟩ := FinitePresentation.out (R := R) (A := A) convert (ker_fg_of_mvPolynomial (f.comp g) (hf.comp hg)).map g.toRingHom simp_rw [RingHom.ker_eq_comap_bot, AlgHom.toRingHom_eq_coe, AlgHom.comp_toRingHom] rw [← Ideal.comap_comap, Ideal.map_comap_of_surjective (g : MvPolynomial (Fin n) R →+* A) hg] end FinitePresentation end Algebra end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is of `RingHom.FinitePresentation` if `B` is finitely presented as `A`-algebra. -/ def FinitePresentation (f : A →+* B) : Prop := @Algebra.FinitePresentation A B _ _ f.toAlgebra namespace FiniteType theorem of_finitePresentation {f : A →+* B} (hf : f.FinitePresentation) : f.FiniteType := @Algebra.FiniteType.of_finitePresentation A B _ _ f.toAlgebra hf end FiniteType namespace FinitePresentation variable (A) theorem id : FinitePresentation (RingHom.id A) := Algebra.FinitePresentation.self A variable {A} theorem comp_surjective {f : A →+* B} {g : B →+* C} (hf : f.FinitePresentation) (hg : Surjective g) (hker : g.ker.FG) : (g.comp f).FinitePresentation := letI := f.toAlgebra letI := (g.comp f).toAlgebra letI : Algebra.FinitePresentation A B := hf Algebra.FinitePresentation.of_surjective (f := { g with toFun := g commutes' := fun _ => rfl }) hg hker theorem of_surjective (f : A →+* B) (hf : Surjective f) (hker : f.ker.FG) : f.FinitePresentation := by rw [← f.comp_id] exact (id A).comp_surjective hf hker theorem of_finiteType [IsNoetherianRing A] {f : A →+* B} : f.FiniteType ↔ f.FinitePresentation := @Algebra.FinitePresentation.of_finiteType A B _ _ f.toAlgebra _ theorem comp {g : B →+* C} {f : A →+* B} (hg : g.FinitePresentation) (hf : f.FinitePresentation) : (g.comp f).FinitePresentation := -- Porting note: specify `Algebra` instances to get `SMul` letI ins1 := RingHom.toAlgebra f letI ins2 := RingHom.toAlgebra g letI ins3 := RingHom.toAlgebra (g.comp f) letI ins4 : IsScalarTower A B C := { smul_assoc := fun a b c => by simp [Algebra.smul_def, mul_assoc]; rfl } letI : Algebra.FinitePresentation A B := hf letI : Algebra.FinitePresentation B C := hg Algebra.FinitePresentation.trans A B C theorem of_comp_finiteType (f : A →+* B) {g : B →+* C} (hg : (g.comp f).FinitePresentation) (hf : f.FiniteType) : g.FinitePresentation := -- Porting note: need to specify some instances letI ins1 := RingHom.toAlgebra f letI ins2 := RingHom.toAlgebra g letI ins3 := RingHom.toAlgebra (g.comp f) letI ins4 : IsScalarTower A B C := { smul_assoc := fun a b c => by simp [Algebra.smul_def, mul_assoc]; rfl } letI : Algebra.FinitePresentation A C := hg letI : Algebra.FiniteType A B := hf Algebra.FinitePresentation.of_restrict_scalars_finitePresentation A B C end FinitePresentation end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is of `AlgHom.FinitePresentation` if it is of finite presentation as ring morphism. In other words, if `B` is finitely presented as `A`-algebra. -/ def FinitePresentation (f : A →ₐ[R] B) : Prop := f.toRingHom.FinitePresentation namespace FiniteType theorem of_finitePresentation {f : A →ₐ[R] B} (hf : f.FinitePresentation) : f.FiniteType := RingHom.FiniteType.of_finitePresentation hf end FiniteType namespace FinitePresentation variable (R A) theorem id : FinitePresentation (AlgHom.id R A) := RingHom.FinitePresentation.id A variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.FinitePresentation) (hf : f.FinitePresentation) : (g.comp f).FinitePresentation := RingHom.FinitePresentation.comp hg hf theorem comp_surjective {f : A →ₐ[R] B} {g : B →ₐ[R] C} (hf : f.FinitePresentation) (hg : Surjective g) (hker : g.toRingHom.ker.FG) : (g.comp f).FinitePresentation := RingHom.FinitePresentation.comp_surjective hf hg hker theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) (hker : f.toRingHom.ker.FG) : f.FinitePresentation := by -- Porting note: added `convert` convert RingHom.FinitePresentation.of_surjective f hf hker theorem of_finiteType [IsNoetherianRing A] {f : A →ₐ[R] B} : f.FiniteType ↔ f.FinitePresentation := RingHom.FinitePresentation.of_finiteType nonrec theorem of_comp_finiteType (f : A →ₐ[R] B) {g : B →ₐ[R] C} (h : (g.comp f).FinitePresentation) (h' : f.FiniteType) : g.FinitePresentation := h.of_comp_finiteType _ h' end FinitePresentation end AlgHom
RingTheory\FiniteStability.lean
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.LinearAlgebra.TensorProduct.RightExactness import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.TensorProduct.MvPolynomial /-! # Stability of finiteness conditions in commutative algebra In this file we show that `Algebra.FiniteType` and `Algebra.FinitePresentation` are stable under base change. -/ open scoped TensorProduct universe w₁ w₂ w₃ variable {R : Type w₁} [CommRing R] variable {A : Type w₂} [CommRing A] [Algebra R A] variable (B : Type w₃) [CommRing B] [Algebra R B] namespace Algebra namespace FiniteType theorem baseChangeAux_surj {σ : Type*} {f : MvPolynomial σ R →ₐ[R] A} (hf : Function.Surjective f) : Function.Surjective (Algebra.TensorProduct.map (AlgHom.id B B) f) := by show Function.Surjective (TensorProduct.map (AlgHom.id R B) f) apply TensorProduct.map_surjective · exact Function.RightInverse.surjective (congrFun rfl) · exact hf instance baseChange [hfa : FiniteType R A] : Algebra.FiniteType B (B ⊗[R] A) := by rw [iff_quotient_mvPolynomial''] at * obtain ⟨n, f, hf⟩ := hfa let g : B ⊗[R] MvPolynomial (Fin n) R →ₐ[B] B ⊗[R] A := Algebra.TensorProduct.map (AlgHom.id B B) f have : Function.Surjective g := baseChangeAux_surj B hf use n, AlgHom.comp g (MvPolynomial.algebraTensorAlgEquiv R B).symm.toAlgHom simpa end FiniteType namespace FinitePresentation instance baseChange [FinitePresentation R A] : FinitePresentation B (B ⊗[R] A) := by obtain ⟨n, f, hsurj, hfg⟩ := ‹FinitePresentation R A› let g : B ⊗[R] MvPolynomial (Fin n) R →ₐ[B] B ⊗[R] A := Algebra.TensorProduct.map (AlgHom.id B B) f have hgsurj : Function.Surjective g := Algebra.FiniteType.baseChangeAux_surj B hsurj have hker_eq : RingHom.ker g = Ideal.map Algebra.TensorProduct.includeRight (RingHom.ker f) := Algebra.TensorProduct.lTensor_ker f hsurj have hfgg : Ideal.FG (RingHom.ker g) := by rw [hker_eq] exact Ideal.FG.map hfg _ let g' : MvPolynomial (Fin n) B →ₐ[B] B ⊗[R] A := AlgHom.comp g (MvPolynomial.algebraTensorAlgEquiv R B).symm.toAlgHom refine ⟨n, g', ?_, Ideal.fg_ker_comp _ _ ?_ hfgg ?_⟩ · simp_all [g, g'] · show Ideal.FG (RingHom.ker (AlgEquiv.symm (MvPolynomial.algebraTensorAlgEquiv R B))) simp only [RingHom.ker_equiv] exact Submodule.fg_bot · simpa using EquivLike.surjective _ end FinitePresentation end Algebra
RingTheory\FiniteType.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.RingTheory.Adjoin.Tower /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType` all of these express that some object is finitely generated *as algebra* over some base ring. -/ open Function (Surjective) open Polynomial section ModuleAndAlgebra universe uR uS uA uB uM uN variable (R : Type uR) (S : Type uS) (A : Type uA) (B : Type uB) (M : Type uM) (N : Type uN) /-- An algebra over a commutative semiring is of `FiniteType` if it is finitely generated over the base ring as algebra. -/ class Algebra.FiniteType [CommSemiring R] [Semiring A] [Algebra R A] : Prop where out : (⊤ : Subalgebra R A).FG namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] namespace Finite open Submodule Set variable {R S M N} section Algebra -- see Note [lower instance priority] instance (priority := 100) finiteType {R : Type*} (A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [hRA : Finite R A] : Algebra.FiniteType R A := ⟨Subalgebra.fg_of_submodule_fg hRA.1⟩ end Algebra end Finite end Module namespace Algebra variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] namespace FiniteType theorem self : FiniteType R R := ⟨⟨{1}, Subsingleton.elim _ _⟩⟩ protected theorem polynomial : FiniteType R R[X] := ⟨⟨{Polynomial.X}, by rw [Finset.coe_singleton] exact Polynomial.adjoin_X⟩⟩ open scoped Classical protected theorem freeAlgebra (ι : Type*) [Finite ι] : FiniteType R (FreeAlgebra R ι) := by cases nonempty_fintype ι exact ⟨⟨Finset.univ.image (FreeAlgebra.ι R), by rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact FreeAlgebra.adjoin_range_ι R ι⟩⟩ protected theorem mvPolynomial (ι : Type*) [Finite ι] : FiniteType R (MvPolynomial ι R) := by cases nonempty_fintype ι exact ⟨⟨Finset.univ.image MvPolynomial.X, by rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact MvPolynomial.adjoin_range_X⟩⟩ theorem of_restrictScalars_finiteType [Algebra S A] [IsScalarTower R S A] [hA : FiniteType R A] : FiniteType S A := by obtain ⟨s, hS⟩ := hA.out refine ⟨⟨s, eq_top_iff.2 fun b => ?_⟩⟩ have le : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S s) := by apply (Algebra.adjoin_le _ : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S ↑s)) simp only [Subalgebra.coe_restrictScalars] exact Algebra.subset_adjoin exact le (eq_top_iff.1 hS b) variable {R S A B} theorem of_surjective (hRA : FiniteType R A) (f : A →ₐ[R] B) (hf : Surjective f) : FiniteType R B := ⟨by convert hRA.1.map f simpa only [map_top f, @eq_comm _ ⊤, eq_top_iff, AlgHom.mem_range] using hf⟩ theorem equiv (hRA : FiniteType R A) (e : A ≃ₐ[R] B) : FiniteType R B := hRA.of_surjective e e.surjective theorem trans [Algebra S A] [IsScalarTower R S A] (hRS : FiniteType R S) (hSA : FiniteType S A) : FiniteType R A := ⟨fg_trans' hRS.1 hSA.1⟩ /-- An algebra is finitely generated if and only if it is a quotient of a free algebra whose variables are indexed by a finset. -/ theorem iff_quotient_freeAlgebra : FiniteType R A ↔ ∃ (s : Finset A) (f : FreeAlgebra R s →ₐ[R] A), Surjective f := by constructor · rintro ⟨s, hs⟩ refine ⟨s, FreeAlgebra.lift _ (↑), ?_⟩ intro x have hrw : (↑s : Set A) = fun x : A => x ∈ s.val := rfl rw [← Set.mem_range, ← AlgHom.coe_range] erw [← adjoin_eq_range_freeAlgebra_lift, ← hrw, hs] exact Set.mem_univ x · rintro ⟨s, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.freeAlgebra R s) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a finset. -/ theorem iff_quotient_mvPolynomial : FiniteType R S ↔ ∃ (s : Finset S) (f : MvPolynomial { x // x ∈ s } R →ₐ[R] S), Surjective f := by constructor · rintro ⟨s, hs⟩ use s, MvPolynomial.aeval (↑) intro x have hrw : (↑s : Set S) = fun x : S => x ∈ s.val := rfl rw [← Set.mem_range, ← AlgHom.coe_range, ← adjoin_eq_range, ← hrw, hs] exact Set.mem_univ x · rintro ⟨s, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.mvPolynomial R { x // x ∈ s }) f hsur /-- An algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_freeAlgebra' : FiniteType R A ↔ ∃ (ι : Type uA) (_ : Fintype ι) (f : FreeAlgebra R ι →ₐ[R] A), Surjective f := by constructor · rw [iff_quotient_freeAlgebra] rintro ⟨s, ⟨f, hsur⟩⟩ use { x : A // x ∈ s }, inferInstance, f · rintro ⟨ι, ⟨hfintype, ⟨f, hsur⟩⟩⟩ letI : Fintype ι := hfintype exact FiniteType.of_surjective (FiniteType.freeAlgebra R ι) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_mvPolynomial' : FiniteType R S ↔ ∃ (ι : Type uS) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial] rintro ⟨s, ⟨f, hsur⟩⟩ use { x : S // x ∈ s }, inferInstance, f · rintro ⟨ι, ⟨hfintype, ⟨f, hsur⟩⟩⟩ letI : Fintype ι := hfintype exact FiniteType.of_surjective (FiniteType.mvPolynomial R ι) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring in `n` variables. -/ theorem iff_quotient_mvPolynomial'' : FiniteType R S ↔ ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial'] rintro ⟨ι, hfintype, ⟨f, hsur⟩⟩ have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι) exact ⟨Fintype.card ι, AlgHom.comp f equiv.symm.toAlgHom, by simpa using hsur⟩ · rintro ⟨n, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.mvPolynomial R (Fin n)) f hsur instance prod [hA : FiniteType R A] [hB : FiniteType R B] : FiniteType R (A × B) := ⟨by rw [← Subalgebra.prod_top]; exact hA.1.prod hB.1⟩ theorem isNoetherianRing (R S : Type*) [CommRing R] [CommRing S] [Algebra R S] [h : Algebra.FiniteType R S] [IsNoetherianRing R] : IsNoetherianRing S := by obtain ⟨s, hs⟩ := h.1 apply isNoetherianRing_of_surjective (MvPolynomial s R) S (MvPolynomial.aeval (↑) : MvPolynomial s R →ₐ[R] S).toRingHom erw [← Set.range_iff_surjective, ← AlgHom.coe_range, ← Algebra.adjoin_range_eq_range_aeval, Subtype.range_coe_subtype, Finset.setOf_mem, hs] rfl theorem _root_.Subalgebra.fg_iff_finiteType (S : Subalgebra R A) : S.FG ↔ Algebra.FiniteType R S := S.fg_top.symm.trans ⟨fun h => ⟨h⟩, fun h => h.out⟩ end FiniteType end Algebra end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is of `FiniteType` if `B` is finitely generated as `A`-algebra. -/ def FiniteType (f : A →+* B) : Prop := @Algebra.FiniteType A B _ _ f.toAlgebra namespace Finite theorem finiteType {f : A →+* B} (hf : f.Finite) : FiniteType f := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf end Finite namespace FiniteType variable (A) theorem id : FiniteType (RingHom.id A) := Algebra.FiniteType.self A variable {A} theorem comp_surjective {f : A →+* B} {g : B →+* C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := by let _ : Algebra A B := f.toAlgebra let _ : Algebra A C := (g.comp f).toAlgebra exact Algebra.FiniteType.of_surjective hf { g with toFun := g commutes' := fun a => rfl } hg theorem of_surjective (f : A →+* B) (hf : Surjective f) : f.FiniteType := by rw [← f.comp_id] exact (id A).comp_surjective hf theorem comp {g : B →+* C} {f : A →+* B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := by let _ : Algebra A B := f.toAlgebra let _ : Algebra A C := (g.comp f).toAlgebra let _ : Algebra B C := g.toAlgebra exact @Algebra.FiniteType.trans A B C _ _ _ f.toAlgebra (g.comp f).toAlgebra g.toAlgebra ⟨by intro a b c simp [Algebra.smul_def, RingHom.map_mul, mul_assoc] rfl⟩ hf hg theorem of_finite {f : A →+* B} (hf : f.Finite) : f.FiniteType := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf alias _root_.RingHom.Finite.to_finiteType := of_finite theorem of_comp_finiteType {f : A →+* B} {g : B →+* C} (h : (g.comp f).FiniteType) : g.FiniteType := by let _ := f.toAlgebra let _ := g.toAlgebra let _ := (g.comp f).toAlgebra let _ : IsScalarTower A B C := RestrictScalars.isScalarTower A B C let _ : Algebra.FiniteType A C := h exact Algebra.FiniteType.of_restrictScalars_finiteType A B C end FiniteType end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is of `FiniteType` if it is of finite type as ring morphism. In other words, if `B` is finitely generated as `A`-algebra. -/ def FiniteType (f : A →ₐ[R] B) : Prop := f.toRingHom.FiniteType namespace Finite theorem finiteType {f : A →ₐ[R] B} (hf : f.Finite) : FiniteType f := RingHom.Finite.finiteType hf end Finite namespace FiniteType variable (R A) theorem id : FiniteType (AlgHom.id R A) := RingHom.FiniteType.id A variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := RingHom.FiniteType.comp hg hf theorem comp_surjective {f : A →ₐ[R] B} {g : B →ₐ[R] C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := RingHom.FiniteType.comp_surjective hf hg theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) : f.FiniteType := RingHom.FiniteType.of_surjective f.toRingHom hf theorem of_comp_finiteType {f : A →ₐ[R] B} {g : B →ₐ[R] C} (h : (g.comp f).FiniteType) : g.FiniteType := RingHom.FiniteType.of_comp_finiteType h end FiniteType end AlgHom section MonoidAlgebra variable {R : Type*} {M : Type*} namespace AddMonoidAlgebra open Algebra AddSubmonoid Submodule section Span section Semiring variable [CommSemiring R] [AddMonoid M] /-- An element of `R[M]` is in the subalgebra generated by its support. -/ theorem mem_adjoin_support (f : R[M]) : f ∈ adjoin R (of' R M '' f.support) := by suffices span R (of' R M '' f.support) ≤ Subalgebra.toSubmodule (adjoin R (of' R M '' f.support)) by exact this (mem_span_support f) rw [Submodule.span_le] exact subset_adjoin /-- If a set `S` generates, as algebra, `R[M]`, then the set of supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (⋃ f ∈ S, of' R M '' (f.support : Set M)) = ⊤ := by refine le_antisymm le_top ?_ rw [← hS, adjoin_le_iff] intro f hf have hincl : of' R M '' f.support ⊆ ⋃ (g : R[M]) (_ : g ∈ S), of' R M '' g.support := by intro s hs exact Set.mem_iUnion₂.2 ⟨f, ⟨hf, hs⟩⟩ exact adjoin_mono hincl (mem_adjoin_support f) /-- If a set `S` generates, as algebra, `R[M]`, then the image of the union of the supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen' {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⊤ := by suffices (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⋃ f ∈ S, of' R M '' (f.support : Set M) by rw [this] exact support_gen_of_gen hS simp only [Set.image_iUnion] end Semiring section Ring variable [CommRing R] [AddMonoid M] /-- If `R[M]` is of finite type, then there is a `G : Finset M` such that its image generates, as algebra, `R[M]`. -/ theorem exists_finset_adjoin_eq_top [h : FiniteType R R[M]] : ∃ G : Finset M, Algebra.adjoin R (of' R M '' G) = ⊤ := by obtain ⟨S, hS⟩ := h letI : DecidableEq M := Classical.decEq M use Finset.biUnion S fun f => f.support have : (Finset.biUnion S fun f => f.support : Set M) = ⋃ f ∈ S, (f.support : Set M) := by simp only [Finset.set_biUnion_coe, Finset.coe_biUnion] rw [this] exact support_gen_of_gen' hS /-- The image of an element `m : M` in `R[M]` belongs the submodule generated by `S : Set M` if and only if `m ∈ S`. -/ theorem of'_mem_span [Nontrivial R] {m : M} {S : Set M} : of' R M m ∈ span R (of' R M '' S) ↔ m ∈ S := by refine ⟨fun h => ?_, fun h => Submodule.subset_span <| Set.mem_image_of_mem (of R M) h⟩ erw [of', ← Finsupp.supported_eq_span_single, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ (one_ne_zero' R)] at h simpa using h /-- If the image of an element `m : M` in `R[M]` belongs the submodule generated by the closure of some `S : Set M` then `m ∈ closure S`. -/ theorem mem_closure_of_mem_span_closure [Nontrivial R] {m : M} {S : Set M} (h : of' R M m ∈ span R (Submonoid.closure (of' R M '' S) : Set R[M])) : m ∈ closure S := by suffices Multiplicative.ofAdd m ∈ Submonoid.closure (Multiplicative.toAdd ⁻¹' S) by simpa [← toSubmonoid_closure] let S' := @Submonoid.closure (Multiplicative M) Multiplicative.mulOneClass S have h' : Submonoid.map (of R M) S' = Submonoid.closure ((fun x : M => (of R M) x) '' S) := MonoidHom.map_mclosure _ _ rw [Set.image_congr' (show ∀ x, of' R M x = of R M x from fun x => of'_eq_of x), ← h'] at h simpa using of'_mem_span.1 h end Ring end Span /-- If a set `S` generates an additive monoid `M`, then the image of `M` generates, as algebra, `R[M]`. -/ theorem mvPolynomial_aeval_of_surjective_of_closure [AddCommMonoid M] [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (MvPolynomial.aeval fun s : S => of' R M ↑s : MvPolynomial S R → R[M]) := by intro f induction' f using induction_on with m f g ihf ihg r f ih · have : m ∈ closure S := hS.symm ▸ mem_top _ refine AddSubmonoid.closure_induction this (fun m hm => ?_) ?_ ?_ · exact ⟨MvPolynomial.X ⟨m, hm⟩, MvPolynomial.aeval_X _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]; rfl⟩ · rcases ihf with ⟨P, rfl⟩ rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ · rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ variable [AddMonoid M] /-- If a set `S` generates an additive monoid `M`, then the image of `M` generates, as algebra, `R[M]`. -/ theorem freeAlgebra_lift_of_surjective_of_closure [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (FreeAlgebra.lift R fun s : S => of' R M ↑s : FreeAlgebra R S → R[M]) := by intro f induction' f using induction_on with m f g ihf ihg r f ih · have : m ∈ closure S := hS.symm ▸ mem_top _ refine AddSubmonoid.closure_induction this (fun m hm => ?_) ?_ ?_ · exact ⟨FreeAlgebra.ι R ⟨m, hm⟩, FreeAlgebra.lift_ι_apply _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]; rfl⟩ · rcases ihf with ⟨P, rfl⟩ rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ · rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ variable (R M) /-- If an additive monoid `M` is finitely generated then `R[M]` is of finite type. -/ instance finiteType_of_fg [CommRing R] [h : AddMonoid.FG M] : FiniteType R R[M] := by obtain ⟨S, hS⟩ := h.out exact (FiniteType.freeAlgebra R (S : Set M)).of_surjective (FreeAlgebra.lift R fun s : (S : Set M) => of' R M ↑s) (freeAlgebra_lift_of_surjective_of_closure hS) variable {R M} /-- An additive monoid `M` is finitely generated if and only if `R[M]` is of finite type. -/ theorem finiteType_iff_fg [CommRing R] [Nontrivial R] : FiniteType R R[M] ↔ AddMonoid.FG M := by refine ⟨fun h => ?_, fun h => @AddMonoidAlgebra.finiteType_of_fg _ _ _ _ h⟩ obtain ⟨S, hS⟩ := @exists_finset_adjoin_eq_top R M _ _ h refine AddMonoid.fg_def.2 ⟨S, (eq_top_iff' _).2 fun m => ?_⟩ have hm : of' R M m ∈ Subalgebra.toSubmodule (adjoin R (of' R M '' ↑S)) := by simp only [hS, top_toSubmodule, Submodule.mem_top] rw [adjoin_eq_span] at hm exact mem_closure_of_mem_span_closure hm /-- If `R[M]` is of finite type then `M` is finitely generated. -/ theorem fg_of_finiteType [CommRing R] [Nontrivial R] [h : FiniteType R R[M]] : AddMonoid.FG M := finiteType_iff_fg.1 h /-- An additive group `G` is finitely generated if and only if `R[G]` is of finite type. -/ theorem finiteType_iff_group_fg {G : Type*} [AddCommGroup G] [CommRing R] [Nontrivial R] : FiniteType R R[G] ↔ AddGroup.FG G := by simpa [AddGroup.fg_iff_addMonoid_fg] using finiteType_iff_fg end AddMonoidAlgebra namespace MonoidAlgebra open Algebra Submonoid Submodule section Span section Semiring variable [CommSemiring R] [Monoid M] /-- An element of `MonoidAlgebra R M` is in the subalgebra generated by its support. -/ theorem mem_adjoin_support (f : MonoidAlgebra R M) : f ∈ adjoin R (of R M '' f.support) := by suffices span R (of R M '' f.support) ≤ Subalgebra.toSubmodule (adjoin R (of R M '' f.support)) by exact this (mem_span_support f) rw [Submodule.span_le] exact subset_adjoin /-- If a set `S` generates, as algebra, `MonoidAlgebra R M`, then the set of supports of elements of `S` generates `MonoidAlgebra R M`. -/ theorem support_gen_of_gen {S : Set (MonoidAlgebra R M)} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (⋃ f ∈ S, of R M '' (f.support : Set M)) = ⊤ := by refine le_antisymm le_top ?_ rw [← hS, adjoin_le_iff] intro f hf -- Porting note: ⋃ notation did not work here. Was -- ⋃ (g : MonoidAlgebra R M) (H : g ∈ S), (of R M '' g.support) have hincl : (of R M '' f.support) ⊆ Set.iUnion fun (g : MonoidAlgebra R M) => Set.iUnion fun (_ : g ∈ S) => (of R M '' g.support) := by intro s hs exact Set.mem_iUnion₂.2 ⟨f, ⟨hf, hs⟩⟩ exact adjoin_mono hincl (mem_adjoin_support f) /-- If a set `S` generates, as algebra, `MonoidAlgebra R M`, then the image of the union of the supports of elements of `S` generates `MonoidAlgebra R M`. -/ theorem support_gen_of_gen' {S : Set (MonoidAlgebra R M)} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (of R M '' ⋃ f ∈ S, (f.support : Set M)) = ⊤ := by suffices (of R M '' ⋃ f ∈ S, (f.support : Set M)) = ⋃ f ∈ S, of R M '' (f.support : Set M) by rw [this] exact support_gen_of_gen hS simp only [Set.image_iUnion] end Semiring section Ring variable [CommRing R] [Monoid M] /-- If `MonoidAlgebra R M` is of finite type, then there is a `G : Finset M` such that its image generates, as algebra, `MonoidAlgebra R M`. -/ theorem exists_finset_adjoin_eq_top [h : FiniteType R (MonoidAlgebra R M)] : ∃ G : Finset M, Algebra.adjoin R (of R M '' G) = ⊤ := by obtain ⟨S, hS⟩ := h letI : DecidableEq M := Classical.decEq M use Finset.biUnion S fun f => f.support have : (Finset.biUnion S fun f => f.support : Set M) = ⋃ f ∈ S, (f.support : Set M) := by simp only [Finset.set_biUnion_coe, Finset.coe_biUnion] rw [this] exact support_gen_of_gen' hS /-- The image of an element `m : M` in `MonoidAlgebra R M` belongs the submodule generated by `S : Set M` if and only if `m ∈ S`. -/ theorem of_mem_span_of_iff [Nontrivial R] {m : M} {S : Set M} : of R M m ∈ span R (of R M '' S) ↔ m ∈ S := by refine ⟨fun h => ?_, fun h => Submodule.subset_span <| Set.mem_image_of_mem (of R M) h⟩ erw [of, MonoidHom.coe_mk, ← Finsupp.supported_eq_span_single, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ (one_ne_zero' R)] at h simpa using h /-- If the image of an element `m : M` in `MonoidAlgebra R M` belongs the submodule generated by the closure of some `S : Set M` then `m ∈ closure S`. -/ theorem mem_closure_of_mem_span_closure [Nontrivial R] {m : M} {S : Set M} (h : of R M m ∈ span R (Submonoid.closure (of R M '' S) : Set (MonoidAlgebra R M))) : m ∈ closure S := by rw [← MonoidHom.map_mclosure] at h simpa using of_mem_span_of_iff.1 h end Ring end Span /-- If a set `S` generates a monoid `M`, then the image of `M` generates, as algebra, `MonoidAlgebra R M`. -/ theorem mvPolynomial_aeval_of_surjective_of_closure [CommMonoid M] [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (MvPolynomial.aeval fun s : S => of R M ↑s : MvPolynomial S R → MonoidAlgebra R M) := by intro f induction' f using induction_on with m f g ihf ihg r f ih · have : m ∈ closure S := hS.symm ▸ mem_top _ refine Submonoid.closure_induction this (fun m hm => ?_) ?_ ?_ · exact ⟨MvPolynomial.X ⟨m, hm⟩, MvPolynomial.aeval_X _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]⟩ · rcases ihf with ⟨P, rfl⟩; rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ · rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ variable [Monoid M] /-- If a set `S` generates an additive monoid `M`, then the image of `M` generates, as algebra, `R[M]`. -/ theorem freeAlgebra_lift_of_surjective_of_closure [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (FreeAlgebra.lift R fun s : S => of R M ↑s : FreeAlgebra R S → MonoidAlgebra R M) := by intro f induction' f using induction_on with m f g ihf ihg r f ih · have : m ∈ closure S := hS.symm ▸ mem_top _ refine Submonoid.closure_induction this (fun m hm => ?_) ?_ ?_ · exact ⟨FreeAlgebra.ι R ⟨m, hm⟩, FreeAlgebra.lift_ι_apply _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]⟩ · rcases ihf with ⟨P, rfl⟩ rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ · rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ /-- If a monoid `M` is finitely generated then `MonoidAlgebra R M` is of finite type. -/ instance finiteType_of_fg [CommRing R] [Monoid.FG M] : FiniteType R (MonoidAlgebra R M) := (AddMonoidAlgebra.finiteType_of_fg R (Additive M)).equiv (toAdditiveAlgEquiv R M).symm /-- A monoid `M` is finitely generated if and only if `MonoidAlgebra R M` is of finite type. -/ theorem finiteType_iff_fg [CommRing R] [Nontrivial R] : FiniteType R (MonoidAlgebra R M) ↔ Monoid.FG M := ⟨fun h => Monoid.fg_iff_add_fg.2 <| AddMonoidAlgebra.finiteType_iff_fg.1 <| h.equiv <| toAdditiveAlgEquiv R M, fun h => @MonoidAlgebra.finiteType_of_fg _ _ _ _ h⟩ /-- If `MonoidAlgebra R M` is of finite type then `M` is finitely generated. -/ theorem fg_of_finiteType [CommRing R] [Nontrivial R] [h : FiniteType R (MonoidAlgebra R M)] : Monoid.FG M := finiteType_iff_fg.1 h /-- A group `G` is finitely generated if and only if `R[G]` is of finite type. -/ theorem finiteType_iff_group_fg {G : Type*} [Group G] [CommRing R] [Nontrivial R] : FiniteType R (MonoidAlgebra R G) ↔ Group.FG G := by simpa [Group.fg_iff_monoid_fg] using finiteType_iff_fg end MonoidAlgebra end MonoidAlgebra section Orzech open Submodule Module Module.Finite in /-- Any commutative ring `R` satisfies the `OrzechProperty`, that is, for any finitely generated `R`-module `M`, any surjective homomorphism `f : N →ₗ[R] M` from a submodule `N` of `M` to `M` is injective. This is a consequence of Noetherian case (`IsNoetherian.injective_of_surjective_of_injective`), which requires that `M` is a Noetherian module, but allows `R` to be non-commutative. The reduction of this result to Noetherian case is adapted from <https://math.stackexchange.com/a/1066110>: suppose `{ m_j }` is a finite set of generator of `M`, for any `n : N` one can write `i n = ∑ j, b_j * m_j` for `{ b_j }` in `R`, here `i : N →ₗ[R] M` is the standard inclusion. We can choose `{ n_j }` which are preimages of `{ m_j }` under `f`, and can choose `{ c_jl }` in `R` such that `i n_j = ∑ l, c_jl * m_l` for each `j`. Now let `A` be the subring of `R` generated by `{ b_j }` and `{ c_jl }`, then it is Noetherian. Let `N'` be the `A`-submodule of `N` generated by `n` and `{ n_j }`, `M'` be the `A`-submodule of `M` generated by `{ m_j }`, then it's easy to see that `i` and `f` restrict to `N' →ₗ[A] M'`, and the restricted version of `f` is surjective, hence by Noetherian case, it is also injective, in particular, if `f n = 0`, then `n = 0`. See also Orzech's original paper: *Onto endomorphisms are isomorphisms* [orzech1971]. -/ instance (priority := 100) CommRing.orzechProperty (R : Type*) [CommRing R] : OrzechProperty R := by refine ⟨fun {M} _ _ _ {N} f hf ↦ ?_⟩ letI := addCommMonoidToAddCommGroup R (M := M) letI := addCommMonoidToAddCommGroup R (M := N) let i := N.subtype let hi : Function.Injective i := N.injective_subtype refine LinearMap.ker_eq_bot.1 <| LinearMap.ker_eq_bot'.2 fun n hn ↦ ?_ obtain ⟨k, mj, hmj⟩ := exists_fin (R := R) (M := M) rw [← surjective_piEquiv_apply_iff] at hmj obtain ⟨b, hb⟩ := hmj (i n) choose nj hnj using fun j ↦ hf (mj j) choose c hc using fun j ↦ hmj (i (nj j)) let A := Subring.closure (Set.range b ∪ Set.range c.uncurry) let N' := span A ({n} ∪ Set.range nj) let M' := span A (Set.range mj) haveI : IsNoetherianRing A := is_noetherian_subring_closure _ (.union (Set.finite_range _) (Set.finite_range _)) haveI : Module.Finite A M' := span_of_finite A (Set.finite_range _) refine congr($((LinearMap.ker_eq_bot'.1 <| LinearMap.ker_eq_bot.2 <| IsNoetherian.injective_of_surjective_of_injective ((i.restrictScalars A).restrict fun x hx ↦ ?_ : N' →ₗ[A] M') ((f.restrictScalars A).restrict fun x hx ↦ ?_ : N' →ₗ[A] M') (fun _ _ h ↦ injective_subtype _ (hi congr(($h).1))) fun ⟨x, hx⟩ ↦ ?_) ⟨n, (subset_span (by simp))⟩ (Subtype.val_injective hn)).1) · induction hx using span_induction' with | mem x hx => change i x ∈ M' simp only [Set.singleton_union, Set.mem_insert_iff, Set.mem_range] at hx rcases hx with hx | ⟨j, rfl⟩ · rw [hx, ← hb, piEquiv_apply_apply] refine Submodule.sum_mem _ fun j _ ↦ ?_ let b' : A := ⟨b j, Subring.subset_closure (by simp)⟩ rw [show b j • mj j = b' • mj j from rfl] exact smul_mem _ _ (subset_span (by simp)) · rw [← hc, piEquiv_apply_apply] refine Submodule.sum_mem _ fun j' _ ↦ ?_ let c' : A := ⟨c j j', Subring.subset_closure (by simp [show ∃ a b, c a b = c j j' from ⟨j, j', rfl⟩])⟩ rw [show c j j' • mj j' = c' • mj j' from rfl] exact smul_mem _ _ (subset_span (by simp)) | zero => simp | add x _ y _ hx hy => rw [map_add]; exact add_mem hx hy | smul a x _ hx => rw [map_smul]; exact smul_mem _ _ hx · induction hx using span_induction' with | mem x hx => change f x ∈ M' simp only [Set.singleton_union, Set.mem_insert_iff, Set.mem_range] at hx rcases hx with hx | ⟨j, rfl⟩ · rw [hx, hn]; exact zero_mem _ · exact subset_span (by simp [hnj]) | zero => simp | add x _ y _ hx hy => rw [map_add]; exact add_mem hx hy | smul a x _ hx => rw [map_smul]; exact smul_mem _ _ hx suffices x ∈ LinearMap.range ((f.restrictScalars A).domRestrict N') by obtain ⟨a, ha⟩ := this exact ⟨a, Subtype.val_injective ha⟩ induction hx using span_induction' with | mem x hx => obtain ⟨j, rfl⟩ := hx exact ⟨⟨nj j, subset_span (by simp)⟩, hnj j⟩ | zero => exact zero_mem _ | add x _ y _ hx hy => exact add_mem hx hy | smul a x _ hx => exact smul_mem _ a hx end Orzech section Vasconcelos /-- A theorem by Vasconcelos, given a finite module `M` over a commutative ring, any surjective endomorphism of `M` is also injective. It is a consequence of the fact `CommRing.orzechProperty` that any commutative ring `R` satisfies the `OrzechProperty`; please use `OrzechProperty.injective_of_surjective_endomorphism` instead. This is similar to `IsNoetherian.injective_of_surjective_endomorphism` but only applies in the commutative case, but does not use a Noetherian hypothesis. -/ @[deprecated OrzechProperty.injective_of_surjective_endomorphism (since := "2024-05-30")] theorem Module.Finite.injective_of_surjective_endomorphism {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] [Finite R M] (f : M →ₗ[R] M) (f_surj : Function.Surjective f) : Function.Injective f := OrzechProperty.injective_of_surjective_endomorphism f f_surj end Vasconcelos
RingTheory\Fintype.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Data.Fintype.Units import Mathlib.Data.ZMod.Basic /-! # Some facts about finite rings -/ open Finset ZMod variable {R : Type*} [Ring R] [Fintype R] [DecidableEq R] lemma Finset.univ_of_card_le_two (h : Fintype.card R ≤ 2) : (univ : Finset R) = {0, 1} := by rcases subsingleton_or_nontrivial R · exact le_antisymm (fun a _ ↦ by simp [Subsingleton.elim a 0]) (Finset.subset_univ _) · refine (eq_of_subset_of_card_le (subset_univ _) ?_).symm convert h simp lemma Finset.univ_of_card_le_three (h : Fintype.card R ≤ 3) : (univ : Finset R) = {0, 1, -1} := by refine (eq_of_subset_of_card_le (subset_univ _) ?_).symm rcases lt_or_eq_of_le h with h | h · apply card_le_card rw [Finset.univ_of_card_le_two (Nat.lt_succ_iff.1 h)] intro a ha simp only [mem_insert, mem_singleton] at ha rcases ha with rfl | rfl <;> simp · have : Nontrivial R := by refine Fintype.one_lt_card_iff_nontrivial.1 ?_ rw [h] norm_num rw [card_univ, h, card_insert_of_not_mem, card_insert_of_not_mem, card_singleton] · rw [mem_singleton] intro H rw [← add_eq_zero_iff_eq_neg, one_add_one_eq_two] at H apply_fun (ringEquivOfPrime R Nat.prime_three h).symm at H simp only [map_ofNat, map_zero] at H replace H : ((2 : ℕ) : ZMod 3) = 0 := H rw [natCast_zmod_eq_zero_iff_dvd] at H norm_num at H · intro h simp only [mem_insert, mem_singleton, zero_eq_neg] at h rcases h with (h | h) · exact zero_ne_one h · exact zero_ne_one h.symm open scoped Classical theorem card_units_lt (M₀ : Type*) [MonoidWithZero M₀] [Nontrivial M₀] [Fintype M₀] : Fintype.card M₀ˣ < Fintype.card M₀ := Fintype.card_lt_of_injective_of_not_mem Units.val Units.ext not_isUnit_zero
RingTheory\FreeCommRing.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Logic.Equiv.Functor import Mathlib.RingTheory.FreeRing /-! # Free commutative rings The theory of the free commutative ring generated by a type `α`. It is isomorphic to the polynomial ring over ℤ with variables in `α` ## Main definitions * `FreeCommRing α` : the free commutative ring on a type α * `lift (f : α → R)` : the ring hom `FreeCommRing α →+* R` induced by functoriality from `f`. * `map (f : α → β)` : the ring hom `FreeCommRing α →*+ FreeCommRing β` induced by functoriality from f. ## Main results `FreeCommRing` has functorial properties (it is an adjoint to the forgetful functor). In this file we have: * `of : α → FreeCommRing α` * `lift (f : α → R) : FreeCommRing α →+* R` * `map (f : α → β) : FreeCommRing α →+* FreeCommRing β` * `freeCommRingEquivMvPolynomialInt : FreeCommRing α ≃+* MvPolynomial α ℤ` : `FreeCommRing α` is isomorphic to a polynomial ring. ## Implementation notes `FreeCommRing α` is implemented not using `MvPolynomial` but directly as the free abelian group on `Multiset α`, the type of monomials in this free commutative ring. ## Tags free commutative ring, free ring -/ noncomputable section open scoped Classical open Polynomial universe u v variable (α : Type u) /-- `FreeCommRing α` is the free commutative ring on the type `α`. -/ def FreeCommRing (α : Type u) : Type u := FreeAbelianGroup <| Multiplicative <| Multiset α -- Porting note: two instances below couldn't be derived instance FreeCommRing.instCommRing : CommRing (FreeCommRing α) := by delta FreeCommRing; infer_instance instance FreeCommRing.instInhabited : Inhabited (FreeCommRing α) := by delta FreeCommRing; infer_instance namespace FreeCommRing variable {α} /-- The canonical map from `α` to the free commutative ring on `α`. -/ def of (x : α) : FreeCommRing α := FreeAbelianGroup.of <| Multiplicative.ofAdd ({x} : Multiset α) theorem of_injective : Function.Injective (of : α → FreeCommRing α) := FreeAbelianGroup.of_injective.comp fun _ _ => (Multiset.coe_eq_coe.trans List.singleton_perm_singleton).mp -- Porting note: added to ease a proof in `Algebra.DirectLimit` lemma of_cons (a : α) (m : Multiset α) : (FreeAbelianGroup.of (Multiplicative.ofAdd (a ::ₘ m))) = @HMul.hMul _ (FreeCommRing α) (FreeCommRing α) _ (of a) (FreeAbelianGroup.of (Multiplicative.ofAdd m)) := by dsimp [FreeCommRing] rw [← Multiset.singleton_add, ofAdd_add, of, FreeAbelianGroup.of_mul_of] @[elab_as_elim, induction_eliminator] protected theorem induction_on {C : FreeCommRing α → Prop} (z : FreeCommRing α) (hn1 : C (-1)) (hb : ∀ b, C (of b)) (ha : ∀ x y, C x → C y → C (x + y)) (hm : ∀ x y, C x → C y → C (x * y)) : C z := have hn : ∀ x, C x → C (-x) := fun x ih => neg_one_mul x ▸ hm _ _ hn1 ih have h1 : C 1 := neg_neg (1 : FreeCommRing α) ▸ hn _ hn1 FreeAbelianGroup.induction_on z (add_left_neg (1 : FreeCommRing α) ▸ ha _ _ hn1 h1) (fun m => Multiset.induction_on m h1 fun a m ih => by convert hm (of a) _ (hb a) ih apply of_cons) (fun m ih => hn _ ih) ha section lift variable {R : Type v} [CommRing R] (f : α → R) /-- A helper to implement `lift`. This is essentially `FreeCommMonoid.lift`, but this does not currently exist. -/ private def liftToMultiset : (α → R) ≃ (Multiplicative (Multiset α) →* R) where toFun f := { toFun := fun s => (s.toAdd.map f).prod map_mul' := fun x y => calc _ = Multiset.prod (Multiset.map f x + Multiset.map f y) := by rw [← Multiset.map_add] rfl _ = _ := Multiset.prod_add _ _ map_one' := rfl } invFun F x := F (Multiplicative.ofAdd ({x} : Multiset α)) left_inv f := funext fun x => show (Multiset.map f {x}).prod = _ by simp right_inv F := MonoidHom.ext fun x => let F' := MonoidHom.toAdditive'' F let x' := Multiplicative.toAdd x show (Multiset.map (fun a => F' {a}) x').sum = F' x' by erw [← Multiset.map_map (fun x => F' x) (fun x => {x}), ← AddMonoidHom.map_multiset_sum] exact DFunLike.congr_arg F (Multiset.sum_map_singleton x') /-- Lift a map `α → R` to an additive group homomorphism `FreeCommRing α → R`. -/ def lift : (α → R) ≃ (FreeCommRing α →+* R) := Equiv.trans liftToMultiset FreeAbelianGroup.liftMonoid @[simp] theorem lift_of (x : α) : lift f (of x) = f x := (FreeAbelianGroup.lift.of _ _).trans <| mul_one _ @[simp] theorem lift_comp_of (f : FreeCommRing α →+* R) : lift (f ∘ of) = f := RingHom.ext fun x => FreeCommRing.induction_on x (by rw [RingHom.map_neg, RingHom.map_one, f.map_neg, f.map_one]) (lift_of _) (fun x y ihx ihy => by rw [RingHom.map_add, f.map_add, ihx, ihy]) fun x y ihx ihy => by rw [RingHom.map_mul, f.map_mul, ihx, ihy] @[ext 1100] theorem hom_ext ⦃f g : FreeCommRing α →+* R⦄ (h : ∀ x, f (of x) = g (of x)) : f = g := lift.symm.injective (funext h) end lift variable {β : Type v} (f : α → β) /-- A map `f : α → β` produces a ring homomorphism `FreeCommRing α →+* FreeCommRing β`. -/ def map : FreeCommRing α →+* FreeCommRing β := lift <| of ∘ f @[simp] theorem map_of (x : α) : map f (of x) = of (f x) := lift_of _ _ /-- `is_supported x s` means that all monomials showing up in `x` have variables in `s`. -/ def IsSupported (x : FreeCommRing α) (s : Set α) : Prop := x ∈ Subring.closure (of '' s) section IsSupported variable {x y : FreeCommRing α} {s t : Set α} theorem isSupported_upwards (hs : IsSupported x s) (hst : s ⊆ t) : IsSupported x t := Subring.closure_mono (Set.monotone_image hst) hs theorem isSupported_add (hxs : IsSupported x s) (hys : IsSupported y s) : IsSupported (x + y) s := Subring.add_mem _ hxs hys theorem isSupported_neg (hxs : IsSupported x s) : IsSupported (-x) s := Subring.neg_mem _ hxs theorem isSupported_sub (hxs : IsSupported x s) (hys : IsSupported y s) : IsSupported (x - y) s := Subring.sub_mem _ hxs hys theorem isSupported_mul (hxs : IsSupported x s) (hys : IsSupported y s) : IsSupported (x * y) s := Subring.mul_mem _ hxs hys theorem isSupported_zero : IsSupported 0 s := Subring.zero_mem _ theorem isSupported_one : IsSupported 1 s := Subring.one_mem _ theorem isSupported_int {i : ℤ} {s : Set α} : IsSupported (↑i) s := Int.induction_on i isSupported_zero (fun i hi => by rw [Int.cast_add, Int.cast_one]; exact isSupported_add hi isSupported_one) fun i hi => by rw [Int.cast_sub, Int.cast_one]; exact isSupported_sub hi isSupported_one end IsSupported /-- The restriction map from `FreeCommRing α` to `FreeCommRing s` where `s : Set α`, defined by sending all variables not in `s` to zero. -/ def restriction (s : Set α) [DecidablePred (· ∈ s)] : FreeCommRing α →+* FreeCommRing s := lift (fun a => if H : a ∈ s then of ⟨a, H⟩ else 0) section Restriction variable (s : Set α) [DecidablePred (· ∈ s)] (x y : FreeCommRing α) @[simp] theorem restriction_of (p) : restriction s (of p) = if H : p ∈ s then of ⟨p, H⟩ else 0 := lift_of _ _ end Restriction theorem isSupported_of {p} {s : Set α} : IsSupported (of p) s ↔ p ∈ s := suffices IsSupported (of p) s → p ∈ s from ⟨this, fun hps => Subring.subset_closure ⟨p, hps, rfl⟩⟩ fun hps : IsSupported (of p) s => by haveI := Classical.decPred s have : ∀ x, IsSupported x s → ∃ n : ℤ, lift (fun a => if a ∈ s then (0 : ℤ[X]) else Polynomial.X) x = n := by intro x hx refine Subring.InClosure.recOn hx ?_ ?_ ?_ ?_ · use 1 rw [RingHom.map_one] norm_cast · use -1 rw [RingHom.map_neg, RingHom.map_one, Int.cast_neg, Int.cast_one] · rintro _ ⟨z, hzs, rfl⟩ _ _ use 0 rw [RingHom.map_mul, lift_of, if_pos hzs, zero_mul] norm_cast · rintro x y ⟨q, hq⟩ ⟨r, hr⟩ refine ⟨q + r, ?_⟩ rw [RingHom.map_add, hq, hr] norm_cast specialize this (of p) hps rw [lift_of] at this split_ifs at this with h · exact h exfalso apply Ne.symm Int.zero_ne_one rcases this with ⟨w, H⟩ rw [← Polynomial.C_eq_intCast] at H have : Polynomial.X.coeff 1 = (Polynomial.C ↑w).coeff 1 := by rw [H]; rfl rwa [Polynomial.coeff_C, if_neg (one_ne_zero : 1 ≠ 0), Polynomial.coeff_X, if_pos rfl] at this -- Porting note: Changed `(Subtype.val : s → α)` to `(↑)` in the type theorem map_subtype_val_restriction {x} (s : Set α) [DecidablePred (· ∈ s)] (hxs : IsSupported x s) : map (↑) (restriction s x) = x := by refine Subring.InClosure.recOn hxs ?_ ?_ ?_ ?_ · rw [RingHom.map_one] rfl · rw [map_neg, map_one] rfl · rintro _ ⟨p, hps, rfl⟩ n ih rw [RingHom.map_mul, restriction_of, dif_pos hps, RingHom.map_mul, map_of, ih] · intro x y ihx ihy rw [RingHom.map_add, RingHom.map_add, ihx, ihy] theorem exists_finite_support (x : FreeCommRing α) : ∃ s : Set α, Set.Finite s ∧ IsSupported x s := FreeCommRing.induction_on x ⟨∅, Set.finite_empty, isSupported_neg isSupported_one⟩ (fun p => ⟨{p}, Set.finite_singleton p, isSupported_of.2 <| Set.mem_singleton _⟩) (fun _ _ ⟨s, hfs, hxs⟩ ⟨t, hft, hxt⟩ => ⟨s ∪ t, hfs.union hft, isSupported_add (isSupported_upwards hxs Set.subset_union_left) (isSupported_upwards hxt Set.subset_union_right)⟩) fun _ _ ⟨s, hfs, hxs⟩ ⟨t, hft, hxt⟩ => ⟨s ∪ t, hfs.union hft, isSupported_mul (isSupported_upwards hxs Set.subset_union_left) (isSupported_upwards hxt Set.subset_union_right)⟩ theorem exists_finset_support (x : FreeCommRing α) : ∃ s : Finset α, IsSupported x ↑s := let ⟨s, hfs, hxs⟩ := exists_finite_support x ⟨hfs.toFinset, by rwa [Set.Finite.coe_toFinset]⟩ end FreeCommRing namespace FreeRing open Function /-- The canonical ring homomorphism from the free ring generated by `α` to the free commutative ring generated by `α`. -/ def toFreeCommRing {α} : FreeRing α →+* FreeCommRing α := FreeRing.lift FreeCommRing.of /-- The coercion defined by the canonical ring homomorphism from the free ring generated by `α` to the free commutative ring generated by `α`. -/ @[coe] def castFreeCommRing {α} : FreeRing α → FreeCommRing α := toFreeCommRing instance FreeCommRing.instCoe : Coe (FreeRing α) (FreeCommRing α) := ⟨castFreeCommRing⟩ /-- The natural map `FreeRing α → FreeCommRing α`, as a `RingHom`. -/ def coeRingHom : FreeRing α →+* FreeCommRing α := toFreeCommRing @[simp, norm_cast] protected theorem coe_zero : ↑(0 : FreeRing α) = (0 : FreeCommRing α) := rfl @[simp, norm_cast] protected theorem coe_one : ↑(1 : FreeRing α) = (1 : FreeCommRing α) := rfl variable {α} @[simp] protected theorem coe_of (a : α) : ↑(FreeRing.of a) = FreeCommRing.of a := FreeRing.lift_of _ _ @[simp, norm_cast] protected theorem coe_neg (x : FreeRing α) : ↑(-x) = -(x : FreeCommRing α) := by rw [castFreeCommRing, map_neg] @[simp, norm_cast] protected theorem coe_add (x y : FreeRing α) : ↑(x + y) = (x : FreeCommRing α) + y := (FreeRing.lift _).map_add _ _ @[simp, norm_cast] protected theorem coe_sub (x y : FreeRing α) : ↑(x - y) = (x : FreeCommRing α) - y := by rw [castFreeCommRing, map_sub] @[simp, norm_cast] protected theorem coe_mul (x y : FreeRing α) : ↑(x * y) = (x : FreeCommRing α) * y := (FreeRing.lift _).map_mul _ _ variable (α) protected theorem coe_surjective : Surjective ((↑) : FreeRing α → FreeCommRing α) := fun x => by induction x with | hn1 => use -1 rfl | hb b => exact ⟨FreeRing.of b, rfl⟩ | ha _ _ hx hy => rcases hx with ⟨x, rfl⟩; rcases hy with ⟨y, rfl⟩ exact ⟨x + y, (FreeRing.lift _).map_add _ _⟩ | hm _ _ hx hy => rcases hx with ⟨x, rfl⟩; rcases hy with ⟨y, rfl⟩ exact ⟨x * y, (FreeRing.lift _).map_mul _ _⟩ theorem coe_eq : ((↑) : FreeRing α → FreeCommRing α) = @Functor.map FreeAbelianGroup _ _ _ fun l : List α => (l : Multiset α) := by funext x erw [castFreeCommRing, toFreeCommRing, FreeRing.lift, Equiv.coe_trans, Function.comp, FreeAbelianGroup.liftMonoid_coe (FreeMonoid.lift FreeCommRing.of)] dsimp [Functor.map] rw [← AddMonoidHom.coe_coe] apply FreeAbelianGroup.lift.unique; intro L erw [FreeAbelianGroup.lift.of, Function.comp] exact FreeMonoid.recOn L rfl fun hd tl ih => by rw [(FreeMonoid.lift _).map_mul, FreeMonoid.lift_eval_of, ih] conv_lhs => reduce rfl /-- If α has size at most 1 then the natural map from the free ring on `α` to the free commutative ring on `α` is an isomorphism of rings. -/ def subsingletonEquivFreeCommRing [Subsingleton α] : FreeRing α ≃+* FreeCommRing α := RingEquiv.ofBijective (coeRingHom _) (by have : (coeRingHom _ : FreeRing α → FreeCommRing α) = Functor.mapEquiv FreeAbelianGroup (Multiset.subsingletonEquiv α) := coe_eq α rw [this] apply Equiv.bijective) instance instCommRing [Subsingleton α] : CommRing (FreeRing α) := { inferInstanceAs (Ring (FreeRing α)) with mul_comm := fun x y => by rw [← (subsingletonEquivFreeCommRing α).symm_apply_apply (y * x), (subsingletonEquivFreeCommRing α).map_mul, mul_comm, ← (subsingletonEquivFreeCommRing α).map_mul, (subsingletonEquivFreeCommRing α).symm_apply_apply] } end FreeRing /-- The free commutative ring on `α` is isomorphic to the polynomial ring over ℤ with variables in `α` -/ def freeCommRingEquivMvPolynomialInt : FreeCommRing α ≃+* MvPolynomial α ℤ := RingEquiv.ofHomInv (FreeCommRing.lift <| (fun a => MvPolynomial.X a : α → MvPolynomial α ℤ)) (MvPolynomial.eval₂Hom (Int.castRingHom (FreeCommRing α)) FreeCommRing.of) (by ext; simp) (by ext <;> simp) /-- The free commutative ring on the empty type is isomorphic to `ℤ`. -/ def freeCommRingPemptyEquivInt : FreeCommRing PEmpty.{u + 1} ≃+* ℤ := RingEquiv.trans (freeCommRingEquivMvPolynomialInt _) (MvPolynomial.isEmptyRingEquiv _ PEmpty) /-- The free commutative ring on a type with one term is isomorphic to `ℤ[X]`. -/ def freeCommRingPunitEquivPolynomialInt : FreeCommRing PUnit.{u + 1} ≃+* ℤ[X] := (freeCommRingEquivMvPolynomialInt _).trans (MvPolynomial.pUnitAlgEquiv ℤ).toRingEquiv open FreeRing /-- The free ring on the empty type is isomorphic to `ℤ`. -/ def freeRingPemptyEquivInt : FreeRing PEmpty.{u + 1} ≃+* ℤ := RingEquiv.trans (subsingletonEquivFreeCommRing _) freeCommRingPemptyEquivInt /-- The free ring on a type with one term is isomorphic to `ℤ[X]`. -/ def freeRingPunitEquivPolynomialInt : FreeRing PUnit.{u + 1} ≃+* ℤ[X] := RingEquiv.trans (subsingletonEquivFreeCommRing _) freeCommRingPunitEquivPolynomialInt