source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Union.lean
import Mathlib.Data.Finset.Range import Mathlib.Data.Set.Lattice import Mathlib.Order.Interval.Set.LinearOrder /-! # Extra lemmas about unions of intervals This file contains lemmas about finite unions of intervals which can't be included with the lemmas concerning infinite unions in `Mathlib/Order/Interval/Set/Disjoint.lean` because we use `Finset.range`. -/ open Set /-- Union of consecutive intervals contains the interval defined by the initial and final points. -/ theorem Ioc_subset_biUnion_Ioc {X : Type*} [LinearOrder X] (N : ℕ) (a : ℕ → X) : Ioc (a 0) (a N) ⊆ ⋃ i ∈ Finset.range N, Ioc (a i) (a (i + 1)) := by induction N with | zero => simp | succ N ih => calc _ ⊆ Ioc (a 0) (a N) ∪ Ioc (a N) (a (N + 1)) := Ioc_subset_Ioc_union_Ioc _ ⊆ _ := by simpa [Finset.range_add_one] using union_subset_union_right (Ioc (a N) (a (N + 1))) ih /-- Union of consecutive intervals contains the interval defined by the initial and final points. -/ theorem Ico_subset_biUnion_Ico {X : Type*} [LinearOrder X] (N : ℕ) (a : ℕ → X) : Ico (a 0) (a N) ⊆ ⋃ i ∈ Finset.range N, Ico (a i) (a (i + 1)) := by induction N with | zero => simp | succ N ih => calc _ ⊆ Ico (a 0) (a N) ∪ Ico (a N) (a (N + 1)) := Ico_subset_Ico_union_Ico _ ⊆ _ := by simpa [Finset.range_add_one] using union_subset_union_right (Ico (a N) (a (N + 1))) ih
.lake/packages/mathlib/Mathlib/Order/Interval/Set/WithBotTop.lean
import Mathlib.Data.Set.Image import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.WithBot /-! # Intervals in `WithTop α` and `WithBot α` In this file we prove various lemmas about `Set.image`s and `Set.preimage`s of intervals under `some : α → WithTop α` and `some : α → WithBot α`. -/ open Set variable {α : Type*} /-! ### `WithTop` -/ namespace WithTop @[simp] theorem preimage_coe_top : (some : α → WithTop α) ⁻¹' {⊤} = (∅ : Set α) := eq_empty_of_subset_empty fun _ => coe_ne_top variable [Preorder α] {a b : α} theorem range_coe : range (some : α → WithTop α) = Iio ⊤ := by ext; simp [mem_range, WithTop.lt_top_iff_ne_top, ne_top_iff_exists] @[simp] theorem preimage_coe_Ioi : (some : α → WithTop α) ⁻¹' Ioi a = Ioi a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Ici : (some : α → WithTop α) ⁻¹' Ici a = Ici a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Iio : (some : α → WithTop α) ⁻¹' Iio a = Iio a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Iic : (some : α → WithTop α) ⁻¹' Iic a = Iic a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Icc : (some : α → WithTop α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic] @[simp] theorem preimage_coe_Ico : (some : α → WithTop α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioc : (some : α → WithTop α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo : (some : α → WithTop α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio] @[simp] theorem preimage_coe_Iio_top : (some : α → WithTop α) ⁻¹' Iio ⊤ = univ := by rw [← range_coe, preimage_range] @[simp] theorem preimage_coe_Ico_top : (some : α → WithTop α) ⁻¹' Ico a ⊤ = Ici a := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioo_top : (some : α → WithTop α) ⁻¹' Ioo a ⊤ = Ioi a := by simp [← Ioi_inter_Iio] theorem image_coe_Ioi : (some : α → WithTop α) '' Ioi a = Ioo (a : WithTop α) ⊤ := by rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, Ioi_inter_Iio] theorem image_coe_Ici : (some : α → WithTop α) '' Ici a = Ico (a : WithTop α) ⊤ := by rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, Ici_inter_Iio] theorem image_coe_Iio : (some : α → WithTop α) '' Iio a = Iio (a : WithTop α) := by rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Iio_subset_Iio le_top)] theorem image_coe_Iic : (some : α → WithTop α) '' Iic a = Iic (a : WithTop α) := by rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Iic_subset_Iio.2 <| coe_lt_top a)] theorem image_coe_Icc : (some : α → WithTop α) '' Icc a b = Icc (a : WithTop α) b := by rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Icc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)] theorem image_coe_Ico : (some : α → WithTop α) '' Ico a b = Ico (a : WithTop α) b := by rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ico_subset_Iio_self <| Iio_subset_Iio le_top)] theorem image_coe_Ioc : (some : α → WithTop α) '' Ioc a b = Ioc (a : WithTop α) b := by rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)] theorem image_coe_Ioo : (some : α → WithTop α) '' Ioo a b = Ioo (a : WithTop α) b := by rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Iio_self <| Iio_subset_Iio le_top)] theorem Ioi_coe : Ioi (a : WithTop α) = (↑) '' (Ioi a) ∪ {⊤} := by ext x; induction x <;> simp theorem Ici_coe : Ici (a : WithTop α) = (↑) '' (Ici a) ∪ {⊤} := by ext x; induction x <;> simp theorem Iio_coe : Iio (a : WithTop α) = (↑) '' (Iio a) := image_coe_Iio.symm theorem Iic_coe : Iic (a : WithTop α) = (↑) '' (Iic a) := image_coe_Iic.symm theorem Icc_coe : Icc (a : WithTop α) b = (↑) '' (Icc a b) := image_coe_Icc.symm theorem Ico_coe : Ico (a : WithTop α) b = (↑) '' (Ico a b) := image_coe_Ico.symm theorem Ioc_coe : Ioc (a : WithTop α) b = (↑) '' (Ioc a b) := image_coe_Ioc.symm theorem Ioo_coe : Ioo (a : WithTop α) b = (↑) '' (Ioo a b) := image_coe_Ioo.symm end WithTop /-! ### `WithBot` -/ namespace WithBot @[simp] theorem preimage_coe_bot : (some : α → WithBot α) ⁻¹' {⊥} = (∅ : Set α) := @WithTop.preimage_coe_top αᵒᵈ variable [Preorder α] {a b : α} theorem range_coe : range (some : α → WithBot α) = Ioi ⊥ := by ext; simp [mem_range, WithBot.bot_lt_iff_ne_bot, ne_bot_iff_exists] @[simp] theorem preimage_coe_Ioi : (some : α → WithBot α) ⁻¹' Ioi a = Ioi a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Ici : (some : α → WithBot α) ⁻¹' Ici a = Ici a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Iio : (some : α → WithBot α) ⁻¹' Iio a = Iio a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Iic : (some : α → WithBot α) ⁻¹' Iic a = Iic a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Icc : (some : α → WithBot α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic] @[simp] theorem preimage_coe_Ico : (some : α → WithBot α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioc : (some : α → WithBot α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo : (some : α → WithBot α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio] @[simp] theorem preimage_coe_Ioi_bot : (some : α → WithBot α) ⁻¹' Ioi ⊥ = univ := by rw [← range_coe, preimage_range] @[simp] theorem preimage_coe_Ioc_bot : (some : α → WithBot α) ⁻¹' Ioc ⊥ a = Iic a := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo_bot : (some : α → WithBot α) ⁻¹' Ioo ⊥ a = Iio a := by simp [← Ioi_inter_Iio] theorem image_coe_Iio : (some : α → WithBot α) '' Iio a = Ioo (⊥ : WithBot α) a := by rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iio] theorem image_coe_Iic : (some : α → WithBot α) '' Iic a = Ioc (⊥ : WithBot α) a := by rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iic] theorem image_coe_Ioi : (some : α → WithBot α) '' Ioi a = Ioi (a : WithBot α) := by rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Ioi_subset_Ioi bot_le)] theorem image_coe_Ici : (some : α → WithBot α) '' Ici a = Ici (a : WithBot α) := by rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Ici_subset_Ioi.2 <| bot_lt_coe a)] theorem image_coe_Icc : (some : α → WithBot α) '' Icc a b = Icc (a : WithBot α) b := by rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Icc_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)] theorem image_coe_Ioc : (some : α → WithBot α) '' Ioc a b = Ioc (a : WithBot α) b := by rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Ioi_self <| Ioi_subset_Ioi bot_le)] theorem image_coe_Ico : (some : α → WithBot α) '' Ico a b = Ico (a : WithBot α) b := by rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ico_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)] theorem image_coe_Ioo : (some : α → WithBot α) '' Ioo a b = Ioo (a : WithBot α) b := by rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Ioi_self <| Ioi_subset_Ioi bot_le)] theorem Ioi_coe : Ioi (a : WithBot α) = (↑) '' (Ioi a) := image_coe_Ioi.symm theorem Ici_coe : Ici (a : WithBot α) = (↑) '' (Ici a) := image_coe_Ici.symm theorem Iio_coe : Iio (a : WithBot α) = (↑) '' (Iio a) ∪ {⊥} := by ext x; induction x <;> simp theorem Iic_coe : Iic (a : WithBot α) = (↑) '' (Iic a) ∪ {⊥} := by ext x; induction x <;> simp theorem Icc_coe : Icc (a : WithBot α) b = (↑) '' (Icc a b) := image_coe_Icc.symm theorem Ico_coe : Ico (a : WithBot α) b = (↑) '' (Ico a b) := image_coe_Ico.symm theorem Ioc_coe : Ioc (a : WithBot α) b = (↑) '' (Ioc a b) := image_coe_Ioc.symm theorem Ioo_coe : Ioo (a : WithBot α) b = (↑) '' (Ioo a b) := image_coe_Ioo.symm end WithBot
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Pi.lean
import Mathlib.Algebra.Notation.Pi.Basic import Mathlib.Data.Set.BooleanAlgebra import Mathlib.Data.Set.Piecewise import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.Interval.Set.UnorderedInterval /-! # Intervals in `pi`-space In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`, `Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals usually include the corresponding products as proper subsets. -/ -- Porting note: Added, since dot notation no longer works on `Function.update` open Function variable {ι : Type*} {α : ι → Type*} namespace Set section PiPreorder variable [∀ i, Preorder (α i)] (x y : ∀ i, α i) @[simp] theorem pi_univ_Ici : (pi univ fun i ↦ Ici (x i)) = Ici x := ext fun y ↦ by simp [Pi.le_def] @[simp] theorem pi_univ_Iic : (pi univ fun i ↦ Iic (x i)) = Iic x := ext fun y ↦ by simp [Pi.le_def] @[simp] theorem pi_univ_Icc : (pi univ fun i ↦ Icc (x i) (y i)) = Icc x y := ext fun y ↦ by simp [Pi.le_def, forall_and] theorem piecewise_mem_Icc {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i} (h₁ : ∀ i ∈ s, f₁ i ∈ Icc (g₁ i) (g₂ i)) (h₂ : ∀ i ∉ s, f₂ i ∈ Icc (g₁ i) (g₂ i)) : s.piecewise f₁ f₂ ∈ Icc g₁ g₂ := ⟨le_piecewise (fun i hi ↦ (h₁ i hi).1) fun i hi ↦ (h₂ i hi).1, piecewise_le (fun i hi ↦ (h₁ i hi).2) fun i hi ↦ (h₂ i hi).2⟩ theorem piecewise_mem_Icc' {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i} (h₁ : f₁ ∈ Icc g₁ g₂) (h₂ : f₂ ∈ Icc g₁ g₂) : s.piecewise f₁ f₂ ∈ Icc g₁ g₂ := piecewise_mem_Icc (fun _ _ ↦ ⟨h₁.1 _, h₁.2 _⟩) fun _ _ ↦ ⟨h₂.1 _, h₂.2 _⟩ section Nonempty theorem pi_univ_Ioi_subset [Nonempty ι] : (pi univ fun i ↦ Ioi (x i)) ⊆ Ioi x := fun _ hz ↦ ⟨fun i ↦ le_of_lt <| hz i trivial, fun h ↦ (‹Nonempty ι›.elim) fun i ↦ not_lt_of_ge (h i) (hz i trivial)⟩ theorem pi_univ_Iio_subset [Nonempty ι] : (pi univ fun i ↦ Iio (x i)) ⊆ Iio x := pi_univ_Ioi_subset (α := fun i ↦ (α i)ᵒᵈ) x theorem pi_univ_Ioo_subset [Nonempty ι] : (pi univ fun i ↦ Ioo (x i) (y i)) ⊆ Ioo x y := fun _ hx ↦ ⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩ theorem pi_univ_Ioc_subset [Nonempty ι] : (pi univ fun i ↦ Ioc (x i) (y i)) ⊆ Ioc x y := fun _ hx ↦ ⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, fun i ↦ (hx i trivial).2⟩ theorem pi_univ_Ico_subset [Nonempty ι] : (pi univ fun i ↦ Ico (x i) (y i)) ⊆ Ico x y := fun _ hx ↦ ⟨fun i ↦ (hx i trivial).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩ end Nonempty variable [DecidableEq ι] open Function (update) theorem pi_univ_Ioc_update_left {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) : (pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) = { z | m < z i₀ } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by have : Ioc m (y i₀) = Ioi m ∩ Ioc (x i₀) (y i₀) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, ← inter_assoc, inter_eq_self_of_subset_left (Ioi_subset_Ioi hm)] simp_rw [univ_pi_update i₀ _ _ fun i z ↦ Ioc z (y i), ← pi_inter_compl ({i₀} : Set ι), singleton_pi', ← inter_assoc, this] rfl theorem pi_univ_Ioc_update_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) : (pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) = { z | z i₀ ≤ m } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by have : Ioc (x i₀) m = Iic m ∩ Ioc (x i₀) (y i₀) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_left_comm, inter_eq_self_of_subset_left (Iic_subset_Iic.2 hm)] simp_rw [univ_pi_update i₀ y m fun i z ↦ Ioc (x i) z, ← pi_inter_compl ({i₀} : Set ι), singleton_pi', ← inter_assoc, this] rfl theorem disjoint_pi_univ_Ioc_update_left_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} : Disjoint (pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) (pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) := by rw [disjoint_left] rintro z h₁ h₂ refine (h₁ i₀ (mem_univ _)).2.not_gt ?_ simpa only [Function.update_self] using (h₂ i₀ (mem_univ _)).1 end PiPreorder section PiPartialOrder variable [DecidableEq ι] [∀ i, PartialOrder (α i)] -- Porting note: Dot notation on `Function.update` broke theorem image_update_Icc (f : ∀ i, α i) (i : ι) (a b : α i) : update f i '' Icc a b = Icc (update f i a) (update f i b) := by ext x rw [← Set.pi_univ_Icc] refine ⟨?_, fun h => ⟨x i, ?_, ?_⟩⟩ · rintro ⟨c, hc, rfl⟩ simpa [update_le_update_iff] · simpa only [Function.update_self] using h i (mem_univ i) · ext j obtain rfl | hij := eq_or_ne i j · exact Function.update_self .. · simpa only [Function.update_of_ne hij.symm, le_antisymm_iff] using h j (mem_univ j) theorem image_update_Ico (f : ∀ i, α i) (i : ι) (a b : α i) : update f i '' Ico a b = Ico (update f i a) (update f i b) := by rw [← Icc_diff_right, ← Icc_diff_right, image_diff (update_injective _ _), image_singleton, image_update_Icc] theorem image_update_Ioc (f : ∀ i, α i) (i : ι) (a b : α i) : update f i '' Ioc a b = Ioc (update f i a) (update f i b) := by rw [← Icc_diff_left, ← Icc_diff_left, image_diff (update_injective _ _), image_singleton, image_update_Icc] theorem image_update_Ioo (f : ∀ i, α i) (i : ι) (a b : α i) : update f i '' Ioo a b = Ioo (update f i a) (update f i b) := by rw [← Ico_diff_left, ← Ico_diff_left, image_diff (update_injective _ _), image_singleton, image_update_Ico] theorem image_update_Icc_left (f : ∀ i, α i) (i : ι) (a : α i) : update f i '' Icc a (f i) = Icc (update f i a) f := by simpa using image_update_Icc f i a (f i) theorem image_update_Ico_left (f : ∀ i, α i) (i : ι) (a : α i) : update f i '' Ico a (f i) = Ico (update f i a) f := by simpa using image_update_Ico f i a (f i) theorem image_update_Ioc_left (f : ∀ i, α i) (i : ι) (a : α i) : update f i '' Ioc a (f i) = Ioc (update f i a) f := by simpa using image_update_Ioc f i a (f i) theorem image_update_Ioo_left (f : ∀ i, α i) (i : ι) (a : α i) : update f i '' Ioo a (f i) = Ioo (update f i a) f := by simpa using image_update_Ioo f i a (f i) theorem image_update_Icc_right (f : ∀ i, α i) (i : ι) (b : α i) : update f i '' Icc (f i) b = Icc f (update f i b) := by simpa using image_update_Icc f i (f i) b theorem image_update_Ico_right (f : ∀ i, α i) (i : ι) (b : α i) : update f i '' Ico (f i) b = Ico f (update f i b) := by simpa using image_update_Ico f i (f i) b theorem image_update_Ioc_right (f : ∀ i, α i) (i : ι) (b : α i) : update f i '' Ioc (f i) b = Ioc f (update f i b) := by simpa using image_update_Ioc f i (f i) b theorem image_update_Ioo_right (f : ∀ i, α i) (i : ι) (b : α i) : update f i '' Ioo (f i) b = Ioo f (update f i b) := by simpa using image_update_Ioo f i (f i) b variable [∀ i, One (α i)] @[to_additive] theorem image_mulSingle_Icc (i : ι) (a b : α i) : Pi.mulSingle i '' Icc a b = Icc (Pi.mulSingle i a) (Pi.mulSingle i b) := image_update_Icc _ _ _ _ @[to_additive] theorem image_mulSingle_Ico (i : ι) (a b : α i) : Pi.mulSingle i '' Ico a b = Ico (Pi.mulSingle i a) (Pi.mulSingle i b) := image_update_Ico _ _ _ _ @[to_additive] theorem image_mulSingle_Ioc (i : ι) (a b : α i) : Pi.mulSingle i '' Ioc a b = Ioc (Pi.mulSingle i a) (Pi.mulSingle i b) := image_update_Ioc _ _ _ _ @[to_additive] theorem image_mulSingle_Ioo (i : ι) (a b : α i) : Pi.mulSingle i '' Ioo a b = Ioo (Pi.mulSingle i a) (Pi.mulSingle i b) := image_update_Ioo _ _ _ _ @[to_additive] theorem image_mulSingle_Icc_left (i : ι) (a : α i) : Pi.mulSingle i '' Icc a 1 = Icc (Pi.mulSingle i a) 1 := image_update_Icc_left _ _ _ @[to_additive] theorem image_mulSingle_Ico_left (i : ι) (a : α i) : Pi.mulSingle i '' Ico a 1 = Ico (Pi.mulSingle i a) 1 := image_update_Ico_left _ _ _ @[to_additive] theorem image_mulSingle_Ioc_left (i : ι) (a : α i) : Pi.mulSingle i '' Ioc a 1 = Ioc (Pi.mulSingle i a) 1 := image_update_Ioc_left _ _ _ @[to_additive] theorem image_mulSingle_Ioo_left (i : ι) (a : α i) : Pi.mulSingle i '' Ioo a 1 = Ioo (Pi.mulSingle i a) 1 := image_update_Ioo_left _ _ _ @[to_additive] theorem image_mulSingle_Icc_right (i : ι) (b : α i) : Pi.mulSingle i '' Icc 1 b = Icc 1 (Pi.mulSingle i b) := image_update_Icc_right _ _ _ @[to_additive] theorem image_mulSingle_Ico_right (i : ι) (b : α i) : Pi.mulSingle i '' Ico 1 b = Ico 1 (Pi.mulSingle i b) := image_update_Ico_right _ _ _ @[to_additive] theorem image_mulSingle_Ioc_right (i : ι) (b : α i) : Pi.mulSingle i '' Ioc 1 b = Ioc 1 (Pi.mulSingle i b) := image_update_Ioc_right _ _ _ @[to_additive] theorem image_mulSingle_Ioo_right (i : ι) (b : α i) : Pi.mulSingle i '' Ioo 1 b = Ioo 1 (Pi.mulSingle i b) := image_update_Ioo_right _ _ _ end PiPartialOrder section PiLattice variable [∀ i, Lattice (α i)] @[simp] theorem pi_univ_uIcc (a b : ∀ i, α i) : (pi univ fun i => uIcc (a i) (b i)) = uIcc a b := pi_univ_Icc _ _ variable [DecidableEq ι] theorem image_update_uIcc (f : ∀ i, α i) (i : ι) (a b : α i) : update f i '' uIcc a b = uIcc (update f i a) (update f i b) := (image_update_Icc _ _ _ _).trans <| by simp_rw [uIcc, update_sup, update_inf] theorem image_update_uIcc_left (f : ∀ i, α i) (i : ι) (a : α i) : update f i '' uIcc a (f i) = uIcc (update f i a) f := by simpa using image_update_uIcc f i a (f i) theorem image_update_uIcc_right (f : ∀ i, α i) (i : ι) (b : α i) : update f i '' uIcc (f i) b = uIcc f (update f i b) := by simpa using image_update_uIcc f i (f i) b variable [∀ i, One (α i)] @[to_additive] theorem image_mulSingle_uIcc (i : ι) (a b : α i) : Pi.mulSingle i '' uIcc a b = uIcc (Pi.mulSingle i a) (Pi.mulSingle i b) := image_update_uIcc _ _ _ _ @[to_additive] theorem image_mulSingle_uIcc_left (i : ι) (a : α i) : Pi.mulSingle i '' uIcc a 1 = uIcc (Pi.mulSingle i a) 1 := image_update_uIcc_left _ _ _ @[to_additive] theorem image_mulSingle_uIcc_right (i : ι) (b : α i) : Pi.mulSingle i '' uIcc 1 b = uIcc 1 (Pi.mulSingle i b) := image_update_uIcc_right _ _ _ end PiLattice variable [DecidableEq ι] [∀ i, LinearOrder (α i)] open Function (update) theorem pi_univ_Ioc_update_union (x y : ∀ i, α i) (i₀ : ι) (m : α i₀) (hm : m ∈ Icc (x i₀) (y i₀)) : ((pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) ∪ pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) = pi univ fun i ↦ Ioc (x i) (y i) := by simp_rw [pi_univ_Ioc_update_left hm.1, pi_univ_Ioc_update_right hm.2, ← union_inter_distrib_right, ← setOf_or, le_or_gt, setOf_true, univ_inter] /-- If `x`, `y`, `x'`, and `y'` are functions `Π i : ι, α i`, then the set difference between the box `[x, y]` and the product of the open intervals `(x' i, y' i)` is covered by the union of the following boxes: for each `i : ι`, we take `[x, update y i (x' i)]` and `[update x i (y' i), y]`. E.g., if `x' = x` and `y' = y`, then this lemma states that the difference between a closed box `[x, y]` and the corresponding open box `{z | ∀ i, x i < z i < y i}` is covered by the union of the faces of `[x, y]`. -/ theorem Icc_diff_pi_univ_Ioo_subset (x y x' y' : ∀ i, α i) : (Icc x y \ pi univ fun i ↦ Ioo (x' i) (y' i)) ⊆ (⋃ i : ι, Icc x (update y i (x' i))) ∪ ⋃ i : ι, Icc (update x i (y' i)) y := by rintro a ⟨⟨hxa, hay⟩, ha'⟩ simp only [mem_pi, mem_univ, mem_Ioo, true_implies, not_forall] at ha' simp only [le_update_iff, update_le_iff, mem_union, mem_iUnion, mem_Icc, hxa, hay _, hxa _, hay, ← exists_or] rcases ha' with ⟨w, hw⟩ apply Exists.intro w cases lt_or_ge (x' w) (a w) <;> simp_all /-- If `x`, `y`, `z` are functions `Π i : ι, α i`, then the set difference between the box `[x, z]` and the product of the intervals `(y i, z i]` is covered by the union of the boxes `[x, update z i (y i)]`. E.g., if `x = y`, then this lemma states that the difference between a closed box `[x, y]` and the product of half-open intervals `{z | ∀ i, x i < z i ≤ y i}` is covered by the union of the faces of `[x, y]` adjacent to `x`. -/ theorem Icc_diff_pi_univ_Ioc_subset (x y z : ∀ i, α i) : (Icc x z \ pi univ fun i ↦ Ioc (y i) (z i)) ⊆ ⋃ i : ι, Icc x (update z i (y i)) := by rintro a ⟨⟨hax, haz⟩, hay⟩ simpa [not_and_or, hax, le_update_iff, haz _] using hay end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Image.lean
import Mathlib.Order.Interval.Set.Basic import Mathlib.Data.Set.Function import Mathlib.Order.Directed /-! # Monotone functions on intervals This file shows many variants of the fact that a monotone function `f` sends an interval with endpoints `a` and `b` to the interval with endpoints `f a` and `f b`. -/ variable {α β : Type*} {f : α → β} open Set section Preorder variable [Preorder α] [Preorder β] {a b : α} lemma MonotoneOn.mapsTo_Ici (h : MonotoneOn f (Ici a)) : MapsTo f (Ici a) (Ici (f a)) := fun _ _ ↦ by aesop lemma MonotoneOn.mapsTo_Iic (h : MonotoneOn f (Iic b)) : MapsTo f (Iic b) (Iic (f b)) := fun _ _ ↦ by aesop lemma MonotoneOn.mapsTo_Icc (h : MonotoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f a) (f b)) := fun _c hc ↦ ⟨h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1, h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2⟩ lemma AntitoneOn.mapsTo_Ici (h : AntitoneOn f (Ici a)) : MapsTo f (Ici a) (Iic (f a)) := fun _ _ ↦ by aesop lemma AntitoneOn.mapsTo_Iic (h : AntitoneOn f (Iic b)) : MapsTo f (Iic b) (Ici (f b)) := fun _ _ ↦ by aesop lemma AntitoneOn.mapsTo_Icc (h : AntitoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f b) (f a)) := fun _c hc ↦ ⟨h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2, h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1⟩ lemma StrictMonoOn.mapsTo_Ioi (h : StrictMonoOn f (Ici a)) : MapsTo f (Ioi a) (Ioi (f a)) := fun _c hc ↦ h le_rfl hc.le hc lemma StrictMonoOn.mapsTo_Iio (h : StrictMonoOn f (Iic b)) : MapsTo f (Iio b) (Iio (f b)) := fun _c hc ↦ h hc.le le_rfl hc lemma StrictMonoOn.mapsTo_Ioo (h : StrictMonoOn f (Icc a b)) : MapsTo f (Ioo a b) (Ioo (f a) (f b)) := fun _c hc ↦ ⟨h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1, h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2⟩ lemma StrictAntiOn.mapsTo_Ioi (h : StrictAntiOn f (Ici a)) : MapsTo f (Ioi a) (Iio (f a)) := fun _c hc ↦ h le_rfl hc.le hc lemma StrictAntiOn.mapsTo_Iio (h : StrictAntiOn f (Iic b)) : MapsTo f (Iio b) (Ioi (f b)) := fun _c hc ↦ h hc.le le_rfl hc lemma StrictAntiOn.mapsTo_Ioo (h : StrictAntiOn f (Icc a b)) : MapsTo f (Ioo a b) (Ioo (f b) (f a)) := fun _c hc ↦ ⟨h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2, h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1⟩ lemma Monotone.mapsTo_Ici (h : Monotone f) : MapsTo f (Ici a) (Ici (f a)) := (h.monotoneOn _).mapsTo_Ici lemma Monotone.mapsTo_Iic (h : Monotone f) : MapsTo f (Iic b) (Iic (f b)) := (h.monotoneOn _).mapsTo_Iic lemma Monotone.mapsTo_Icc (h : Monotone f) : MapsTo f (Icc a b) (Icc (f a) (f b)) := (h.monotoneOn _).mapsTo_Icc lemma Antitone.mapsTo_Ici (h : Antitone f) : MapsTo f (Ici a) (Iic (f a)) := (h.antitoneOn _).mapsTo_Ici lemma Antitone.mapsTo_Iic (h : Antitone f) : MapsTo f (Iic b) (Ici (f b)) := (h.antitoneOn _).mapsTo_Iic lemma Antitone.mapsTo_Icc (h : Antitone f) : MapsTo f (Icc a b) (Icc (f b) (f a)) := (h.antitoneOn _).mapsTo_Icc lemma StrictMono.mapsTo_Ioi (h : StrictMono f) : MapsTo f (Ioi a) (Ioi (f a)) := (h.strictMonoOn _).mapsTo_Ioi lemma StrictMono.mapsTo_Iio (h : StrictMono f) : MapsTo f (Iio b) (Iio (f b)) := (h.strictMonoOn _).mapsTo_Iio lemma StrictMono.mapsTo_Ioo (h : StrictMono f) : MapsTo f (Ioo a b) (Ioo (f a) (f b)) := (h.strictMonoOn _).mapsTo_Ioo lemma StrictAnti.mapsTo_Ioi (h : StrictAnti f) : MapsTo f (Ioi a) (Iio (f a)) := (h.strictAntiOn _).mapsTo_Ioi lemma StrictAnti.mapsTo_Iio (h : StrictAnti f) : MapsTo f (Iio b) (Ioi (f b)) := (h.strictAntiOn _).mapsTo_Iio lemma StrictAnti.mapsTo_Ioo (h : StrictAnti f) : MapsTo f (Ioo a b) (Ioo (f b) (f a)) := (h.strictAntiOn _).mapsTo_Ioo lemma MonotoneOn.image_Ici_subset (h : MonotoneOn f (Ici a)) : f '' Ici a ⊆ Ici (f a) := h.mapsTo_Ici.image_subset lemma MonotoneOn.image_Iic_subset (h : MonotoneOn f (Iic b)) : f '' Iic b ⊆ Iic (f b) := h.mapsTo_Iic.image_subset lemma MonotoneOn.image_Icc_subset (h : MonotoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f a) (f b) := h.mapsTo_Icc.image_subset lemma AntitoneOn.image_Ici_subset (h : AntitoneOn f (Ici a)) : f '' Ici a ⊆ Iic (f a) := h.mapsTo_Ici.image_subset lemma AntitoneOn.image_Iic_subset (h : AntitoneOn f (Iic b)) : f '' Iic b ⊆ Ici (f b) := h.mapsTo_Iic.image_subset lemma AntitoneOn.image_Icc_subset (h : AntitoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f b) (f a) := h.mapsTo_Icc.image_subset lemma StrictMonoOn.image_Ioi_subset (h : StrictMonoOn f (Ici a)) : f '' Ioi a ⊆ Ioi (f a) := h.mapsTo_Ioi.image_subset lemma StrictMonoOn.image_Iio_subset (h : StrictMonoOn f (Iic b)) : f '' Iio b ⊆ Iio (f b) := h.mapsTo_Iio.image_subset lemma StrictMonoOn.image_Ioo_subset (h : StrictMonoOn f (Icc a b)) : f '' Ioo a b ⊆ Ioo (f a) (f b) := h.mapsTo_Ioo.image_subset lemma StrictAntiOn.image_Ioi_subset (h : StrictAntiOn f (Ici a)) : f '' Ioi a ⊆ Iio (f a) := h.mapsTo_Ioi.image_subset lemma StrictAntiOn.image_Iio_subset (h : StrictAntiOn f (Iic b)) : f '' Iio b ⊆ Ioi (f b) := h.mapsTo_Iio.image_subset lemma StrictAntiOn.image_Ioo_subset (h : StrictAntiOn f (Icc a b)) : f '' Ioo a b ⊆ Ioo (f b) (f a) := h.mapsTo_Ioo.image_subset lemma Monotone.image_Ici_subset (h : Monotone f) : f '' Ici a ⊆ Ici (f a) := (h.monotoneOn _).image_Ici_subset lemma Monotone.image_Iic_subset (h : Monotone f) : f '' Iic b ⊆ Iic (f b) := (h.monotoneOn _).image_Iic_subset lemma Monotone.image_Icc_subset (h : Monotone f) : f '' Icc a b ⊆ Icc (f a) (f b) := (h.monotoneOn _).image_Icc_subset lemma Antitone.image_Ici_subset (h : Antitone f) : f '' Ici a ⊆ Iic (f a) := (h.antitoneOn _).image_Ici_subset lemma Antitone.image_Iic_subset (h : Antitone f) : f '' Iic b ⊆ Ici (f b) := (h.antitoneOn _).image_Iic_subset lemma Antitone.image_Icc_subset (h : Antitone f) : f '' Icc a b ⊆ Icc (f b) (f a) := (h.antitoneOn _).image_Icc_subset lemma StrictMono.image_Ioi_subset (h : StrictMono f) : f '' Ioi a ⊆ Ioi (f a) := (h.strictMonoOn _).image_Ioi_subset lemma StrictMono.image_Iio_subset (h : StrictMono f) : f '' Iio b ⊆ Iio (f b) := (h.strictMonoOn _).image_Iio_subset lemma StrictMono.image_Ioo_subset (h : StrictMono f) : f '' Ioo a b ⊆ Ioo (f a) (f b) := (h.strictMonoOn _).image_Ioo_subset lemma StrictAnti.image_Ioi_subset (h : StrictAnti f) : f '' Ioi a ⊆ Iio (f a) := (h.strictAntiOn _).image_Ioi_subset lemma StrictAnti.image_Iio_subset (h : StrictAnti f) : f '' Iio b ⊆ Ioi (f b) := (h.strictAntiOn _).image_Iio_subset lemma StrictAnti.image_Ioo_subset (h : StrictAnti f) : f '' Ioo a b ⊆ Ioo (f b) (f a) := (h.strictAntiOn _).image_Ioo_subset end Preorder section PartialOrder variable [PartialOrder α] [Preorder β] {a b : α} lemma StrictMonoOn.mapsTo_Ico (h : StrictMonoOn f (Icc a b)) : MapsTo f (Ico a b) (Ico (f a) (f b)) := fun _c hc ↦ ⟨h.monotoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1, h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2⟩ lemma StrictMonoOn.mapsTo_Ioc (h : StrictMonoOn f (Icc a b)) : MapsTo f (Ioc a b) (Ioc (f a) (f b)) := fun _c hc ↦ ⟨h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1, h.monotoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2⟩ lemma StrictAntiOn.mapsTo_Ico (h : StrictAntiOn f (Icc a b)) : MapsTo f (Ico a b) (Ioc (f b) (f a)) := fun _c hc ↦ ⟨h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2, h.antitoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1⟩ lemma StrictAntiOn.mapsTo_Ioc (h : StrictAntiOn f (Icc a b)) : MapsTo f (Ioc a b) (Ico (f b) (f a)) := fun _c hc ↦ ⟨h.antitoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2, h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1⟩ lemma StrictMono.mapsTo_Ico (h : StrictMono f) : MapsTo f (Ico a b) (Ico (f a) (f b)) := (h.strictMonoOn _).mapsTo_Ico lemma StrictMono.mapsTo_Ioc (h : StrictMono f) : MapsTo f (Ioc a b) (Ioc (f a) (f b)) := (h.strictMonoOn _).mapsTo_Ioc lemma StrictAnti.mapsTo_Ico (h : StrictAnti f) : MapsTo f (Ico a b) (Ioc (f b) (f a)) := (h.strictAntiOn _).mapsTo_Ico lemma StrictAnti.mapsTo_Ioc (h : StrictAnti f) : MapsTo f (Ioc a b) (Ico (f b) (f a)) := (h.strictAntiOn _).mapsTo_Ioc lemma StrictMonoOn.image_Ico_subset (h : StrictMonoOn f (Icc a b)) : f '' Ico a b ⊆ Ico (f a) (f b) := h.mapsTo_Ico.image_subset lemma StrictMonoOn.image_Ioc_subset (h : StrictMonoOn f (Icc a b)) : f '' Ioc a b ⊆ Ioc (f a) (f b) := h.mapsTo_Ioc.image_subset lemma StrictAntiOn.image_Ico_subset (h : StrictAntiOn f (Icc a b)) : f '' Ico a b ⊆ Ioc (f b) (f a) := h.mapsTo_Ico.image_subset lemma StrictAntiOn.image_Ioc_subset (h : StrictAntiOn f (Icc a b)) : f '' Ioc a b ⊆ Ico (f b) (f a) := h.mapsTo_Ioc.image_subset lemma StrictMono.image_Ico_subset (h : StrictMono f) : f '' Ico a b ⊆ Ico (f a) (f b) := (h.strictMonoOn _).image_Ico_subset lemma StrictMono.image_Ioc_subset (h : StrictMono f) : f '' Ioc a b ⊆ Ioc (f a) (f b) := (h.strictMonoOn _).image_Ioc_subset lemma StrictAnti.image_Ico_subset (h : StrictAnti f) : f '' Ico a b ⊆ Ioc (f b) (f a) := (h.strictAntiOn _).image_Ico_subset lemma StrictAnti.image_Ioc_subset (h : StrictAnti f) : f '' Ioc a b ⊆ Ico (f b) (f a) := (h.strictAntiOn _).image_Ioc_subset end PartialOrder namespace Set private lemma image_subtype_val_Ixx_Ixi {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b}) (h : ∀ {x}, r c x → p a x) : Subtype.val '' {y : {x // p a x ∧ q x b} | r c.1 y.1} = {y : α | r c.1 y ∧ q y b} := (Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r c.1 y}).trans <| by ext; simp +contextual [@and_comm (r _ _), h] private lemma image_subtype_val_Ixx_Iix {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b}) (h : ∀ {x}, r x c → q x b) : Subtype.val '' {y : {x // p a x ∧ q x b} | r y.1 c.1} = {y : α | p a y ∧ r y c.1} := (Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r y c.1}).trans <| by ext; simp +contextual [h] variable [Preorder α] {p : α → Prop} @[simp] lemma preimage_subtype_val_Ici (a : {x // p x}) : (↑) ⁻¹' (Ici a.1) = Ici a := rfl @[simp] lemma preimage_subtype_val_Iic (a : {x // p x}) : (↑) ⁻¹' (Iic a.1) = Iic a := rfl @[simp] lemma preimage_subtype_val_Ioi (a : {x // p x}) : (↑) ⁻¹' (Ioi a.1) = Ioi a := rfl @[simp] lemma preimage_subtype_val_Iio (a : {x // p x}) : (↑) ⁻¹' (Iio a.1) = Iio a := rfl @[simp] lemma preimage_subtype_val_Icc (a b : {x // p x}) : (↑) ⁻¹' (Icc a.1 b) = Icc a b := rfl @[simp] lemma preimage_subtype_val_Ico (a b : {x // p x}) : (↑) ⁻¹' (Ico a.1 b) = Ico a b := rfl @[simp] lemma preimage_subtype_val_Ioc (a b : {x // p x}) : (↑) ⁻¹' (Ioc a.1 b) = Ioc a b := rfl @[simp] lemma preimage_subtype_val_Ioo (a b : {x // p x}) : (↑) ⁻¹' (Ioo a.1 b) = Ioo a b := rfl theorem image_subtype_val_Icc_subset (a b : {x // p x}) : Subtype.val '' Icc a b ⊆ Icc a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ico_subset (a b : {x // p x}) : Subtype.val '' Ico a b ⊆ Ico a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ioc_subset (a b : {x // p x}) : Subtype.val '' Ioc a b ⊆ Ioc a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ioo_subset (a b : {x // p x}) : Subtype.val '' Ioo a b ⊆ Ioo a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Iic_subset (a : {x // p x}) : Subtype.val '' Iic a ⊆ Iic a.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Iio_subset (a : {x // p x}) : Subtype.val '' Iio a ⊆ Iio a.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ici_subset (a : {x // p x}) : Subtype.val '' Ici a ⊆ Ici a.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ioi_subset (a : {x // p x}) : Subtype.val '' Ioi a ⊆ Ioi a.val := image_subset_iff.mpr fun _ m => m @[simp] lemma image_subtype_val_Ici_Iic {a : α} (b : Ici a) : Subtype.val '' Iic b = Icc a b := (Subtype.image_preimage_val (Ici a) (Iic b.1)).trans Ici_inter_Iic @[simp] lemma image_subtype_val_Ici_Iio {a : α} (b : Ici a) : Subtype.val '' Iio b = Ico a b := (Subtype.image_preimage_val (Ici a) (Iio b.1)).trans Ici_inter_Iio @[simp] lemma image_subtype_val_Ici_Ici {a : α} (b : Ici a) : Subtype.val '' Ici b = Ici b.1 := (Subtype.image_preimage_val (Ici a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ici.2 b.2 @[simp] lemma image_subtype_val_Ici_Ioi {a : α} (b : Ici a) : Subtype.val '' Ioi b = Ioi b.1 := (Subtype.image_preimage_val (Ici a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ici b.2 @[simp] lemma image_subtype_val_Iic_Ici {a : α} (b : Iic a) : Subtype.val '' Ici b = Icc b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iic_Ioi {a : α} (b : Iic a) : Subtype.val '' Ioi b = Ioc b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iic_Iic {a : α} (b : Iic a) : Subtype.val '' Iic b = Iic b.1 := image_subtype_val_Ici_Ici (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Iic_Iio {a : α} (b : Iic a) : Subtype.val '' Iio b = Iio b.1 := image_subtype_val_Ici_Ioi (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Ioi_Ici {a : α} (b : Ioi a) : Subtype.val '' Ici b = Ici b.1 := (Subtype.image_preimage_val (Ioi a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ioi.2 b.2 @[simp] lemma image_subtype_val_Ioi_Iic {a : α} (b : Ioi a) : Subtype.val '' Iic b = Ioc a b := (Subtype.image_preimage_val (Ioi a) (Iic b.1)).trans Ioi_inter_Iic @[simp] lemma image_subtype_val_Ioi_Ioi {a : α} (b : Ioi a) : Subtype.val '' Ioi b = Ioi b.1 := (Subtype.image_preimage_val (Ioi a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ioi b.2.le @[simp] lemma image_subtype_val_Ioi_Iio {a : α} (b : Ioi a) : Subtype.val '' Iio b = Ioo a b := (Subtype.image_preimage_val (Ioi a) (Iio b.1)).trans Ioi_inter_Iio @[simp] lemma image_subtype_val_Iio_Ici {a : α} (b : Iio a) : Subtype.val '' Ici b = Ico b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iio_Iic {a : α} (b : Iio a) : Subtype.val '' Iic b = Iic b.1 := image_subtype_val_Ioi_Ici (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Iio_Ioi {a : α} (b : Iio a) : Subtype.val '' Ioi b = Ioo b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iio_Iio {a : α} (b : Iio a) : Subtype.val '' Iio b = Iio b.1 := image_subtype_val_Ioi_Ioi (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Icc_Ici {a b : α} (c : Icc a b) : Subtype.val '' Ici c = Icc c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Icc_Iic {a b : α} (c : Icc a b) : Subtype.val '' Iic c = Icc a c := image_subtype_val_Ixx_Iix c (le_trans · c.2.2) @[simp] lemma image_subtype_val_Icc_Ioi {a b : α} (c : Icc a b) : Subtype.val '' Ioi c = Ioc c.1 b := image_subtype_val_Ixx_Ixi c (c.2.1.trans <| le_of_lt ·) @[simp] lemma image_subtype_val_Icc_Iio {a b : α} (c : Icc a b) : Subtype.val '' Iio c = Ico a c := image_subtype_val_Ixx_Iix c fun h ↦ (le_of_lt h).trans c.2.2 @[simp] lemma image_subtype_val_Ico_Ici {a b : α} (c : Ico a b) : Subtype.val '' Ici c = Ico c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Ico_Iic {a b : α} (c : Ico a b) : Subtype.val '' Iic c = Icc a c := image_subtype_val_Ixx_Iix c (lt_of_le_of_lt · c.2.2) @[simp] lemma image_subtype_val_Ico_Ioi {a b : α} (c : Ico a b) : Subtype.val '' Ioi c = Ioo c.1 b := image_subtype_val_Ixx_Ixi c (c.2.1.trans <| le_of_lt ·) @[simp] lemma image_subtype_val_Ico_Iio {a b : α} (c : Ico a b) : Subtype.val '' Iio c = Ico a c := image_subtype_val_Ixx_Iix c (lt_trans · c.2.2) @[simp] lemma image_subtype_val_Ioc_Ici {a b : α} (c : Ioc a b) : Subtype.val '' Ici c = Icc c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans_le @[simp] lemma image_subtype_val_Ioc_Iic {a b : α} (c : Ioc a b) : Subtype.val '' Iic c = Ioc a c := image_subtype_val_Ixx_Iix c (le_trans · c.2.2) @[simp] lemma image_subtype_val_Ioc_Ioi {a b : α} (c : Ioc a b) : Subtype.val '' Ioi c = Ioc c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Ioc_Iio {a b : α} (c : Ioc a b) : Subtype.val '' Iio c = Ioo a c := image_subtype_val_Ixx_Iix c fun h ↦ (le_of_lt h).trans c.2.2 @[simp] lemma image_subtype_val_Ioo_Ici {a b : α} (c : Ioo a b) : Subtype.val '' Ici c = Ico c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans_le @[simp] lemma image_subtype_val_Ioo_Iic {a b : α} (c : Ioo a b) : Subtype.val '' Iic c = Ioc a c := image_subtype_val_Ixx_Iix c (lt_of_le_of_lt · c.2.2) @[simp] lemma image_subtype_val_Ioo_Ioi {a b : α} (c : Ioo a b) : Subtype.val '' Ioi c = Ioo c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Ioo_Iio {a b : α} (c : Ioo a b) : Subtype.val '' Iio c = Ioo a c := image_subtype_val_Ixx_Iix c (lt_trans · c.2.2) end Set section Preorder variable [Preorder α] lemma directedOn_le_Iic (b : α) : DirectedOn (· ≤ ·) (Iic b) := fun _x hx _y hy ↦ ⟨b, le_rfl, hx, hy⟩ lemma directedOn_le_Icc (a b : α) : DirectedOn (· ≤ ·) (Icc a b) := fun _x hx _y hy ↦ ⟨b, right_mem_Icc.2 <| hx.1.trans hx.2, hx.2, hy.2⟩ lemma directedOn_le_Ioc (a b : α) : DirectedOn (· ≤ ·) (Ioc a b) := fun _x hx _y hy ↦ ⟨b, right_mem_Ioc.2 <| hx.1.trans_le hx.2, hx.2, hy.2⟩ lemma directedOn_ge_Ici (a : α) : DirectedOn (· ≥ ·) (Ici a) := fun _x hx _y hy ↦ ⟨a, le_rfl, hx, hy⟩ lemma directedOn_ge_Icc (a b : α) : DirectedOn (· ≥ ·) (Icc a b) := fun _x hx _y hy ↦ ⟨a, left_mem_Icc.2 <| hx.1.trans hx.2, hx.1, hy.1⟩ lemma directedOn_ge_Ico (a b : α) : DirectedOn (· ≥ ·) (Ico a b) := fun _x hx _y hy ↦ ⟨a, left_mem_Ico.2 <| hx.1.trans_lt hx.2, hx.1, hy.1⟩ end Preorder
.lake/packages/mathlib/Mathlib/Order/Interval/Set/OrdConnectedLinear.lean
import Mathlib.Data.Nat.Lattice import Mathlib.Data.Int.ConditionallyCompleteOrder import Mathlib.Data.Int.Interval import Mathlib.Data.Int.SuccPred /-! # Order-connected subsets of linear orders In this file we provide some results about order-connected subsets of linear orders, together with some convenience lemmas for characterising closed intervals in certain concrete types such as `ℤ`, `ℕ`, and `Fin n`. ## Main results: * `Set.ordConnected_iff_disjoint_Ioo_empty`: a characterisation of `Set.OrdConnected` for locally-finite linear orders. * `Set.Nonempty.ordConnected_iff_of_bdd`: a characterisation of closed intervals for locally-finite conditionally complete linear orders. * `Set.Nonempty.ordConnected_iff_of_bdd'`: a characterisation of closed intervals for locally-finite complete linear orders (convenient for `Fin n`). * `Set.Nonempty.eq_Icc_iff_nat`: characterisation of closed intervals for `ℕ`. * `Set.Nonempty.eq_Icc_iff_int`: characterisation of closed intervals for `ℤ`. -/ variable {α : Type*} {I : Set α} lemma Set.Nonempty.ordConnected_iff_of_bdd [ConditionallyCompleteLinearOrder α] [LocallyFiniteOrder α] (h₀ : I.Nonempty) (h₁ : BddBelow I) (h₂ : BddAbove I) : I.OrdConnected ↔ I = Icc (sInf I) (sSup I) := have h₄ : I.Finite := h₁.finite_of_bddAbove h₂ ⟨fun _ ↦ le_antisymm (subset_Icc_csInf_csSup h₁ h₂) (I.Icc_subset (h₀.csInf_mem h₄) (h₀.csSup_mem h₄)), fun h₃ ↦ h₃ ▸ ordConnected_Icc⟩ /-- A version of `Set.Nonempty.ordConnected_iff_of_bdd` for complete linear orders, such as `Fin n`, in which the explicit boundedness hypotheses are not necessary. -/ lemma Set.Nonempty.ordConnected_iff_of_bdd' [ConditionallyCompleteLinearOrder α] [OrderTop α] [OrderBot α] [LocallyFiniteOrder α] (h₀ : I.Nonempty) : I.OrdConnected ↔ I = Icc (sInf I) (sSup I) := h₀.ordConnected_iff_of_bdd (OrderBot.bddBelow I) (OrderTop.bddAbove I) /- TODO The `LocallyFiniteOrder` assumption here is probably too strong (e.g., it rules out `ℝ` for which this result holds). However at the time of writing it is not clear what weaker assumption(s) should replace it. -/ lemma Set.ordConnected_iff_disjoint_Ioo_empty [LinearOrder α] [LocallyFiniteOrder α] : I.OrdConnected ↔ ∀ᵉ (x ∈ I) (y ∈ I), Disjoint (Ioo x y) I → Ioo x y = ∅ := by simp_rw [← Set.subset_compl_iff_disjoint_right] refine ⟨fun h' x hx y hy hxy ↦ ?_, fun h' ↦ ordConnected_of_Ioo fun x hx y hy hxy z hz ↦ ?_⟩ · suffices ∀ z, x < z → y ≤ z by ext z; simpa using this z intro z hz suffices z ∉ Ioo x y by simp_all exact fun contra ↦ hxy contra <| h'.out hx hy <| mem_Icc_of_Ioo contra · by_contra hz' obtain ⟨x', hx', hx''⟩ := ((finite_Icc x z).inter_of_right I).exists_le_maximal ⟨hx, le_refl _, hz.1.le⟩ have hxz : x' < z := lt_of_le_of_ne hx''.1.2.2 (ne_of_mem_of_not_mem hx''.1.1 hz') obtain ⟨y', hy', hy''⟩ := ((finite_Icc z y).inter_of_right I).exists_le_minimal ⟨hy, hz.2.le, le_refl _⟩ have hzy : z < y' := lt_of_le_of_ne' hy''.1.2.1 (ne_of_mem_of_not_mem hy''.1.1 hz') have h₃ : Ioc x' z ⊆ Iᶜ := fun t ht ht' ↦ hx''.not_gt (⟨ht', le_trans hx' ht.1.le, ht.2⟩) ht.1 have h₄ : Ico z y' ⊆ Iᶜ := fun t ht ht' ↦ hy''.not_lt (⟨ht', ht.1, le_trans ht.2.le hy'⟩) ht.2 have h₅ : Ioo x' y' ⊆ Iᶜ := by simp only [← Ioc_union_Ico_eq_Ioo hxz hzy, union_subset_iff, and_true, h₃, h₄] exact eq_empty_iff_forall_notMem.1 (h' x' hx''.prop.1 y' hy''.prop.1 h₅) z ⟨hxz, hzy⟩ lemma Set.Nonempty.eq_Icc_iff_nat {I : Set ℕ} (h₀ : I.Nonempty) (h₂ : BddAbove I) : I = Icc (sInf I) (sSup I) ↔ ∀ᵉ (x ∈ I) (y ∈ I), Disjoint (Ioo x y) I → y ≤ x + 1 := by simp [← h₀.ordConnected_iff_of_bdd (OrderBot.bddBelow I) h₂, ordConnected_iff_disjoint_Ioo_empty] lemma Set.Nonempty.eq_Icc_iff_int {I : Set ℤ} (h₀ : I.Nonempty) (h₁ : BddBelow I) (h₂ : BddAbove I) : I = Icc (sInf I) (sSup I) ↔ ∀ᵉ (x ∈ I) (y ∈ I), Disjoint (Ioo x y) I → y ≤ x + 1 := by simp [← h₀.ordConnected_iff_of_bdd h₁ h₂, ordConnected_iff_disjoint_Ioo_empty, Int.succ]
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Basic.lean
import Mathlib.Data.Set.Subsingleton import Mathlib.Order.BooleanAlgebra.Set import Mathlib.Order.Interval.Set.Defs /-! # Intervals In any preorder, we define intervals (which on each side can be either infinite, open or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. The definitions can be found in `Mathlib/Order/Interval/Set/Defs.lean`. This file contains basic facts on inclusion of and set operations on intervals (where the precise statements depend on the order's properties; statements requiring `LinearOrder` are in `Mathlib/Order/Interval/Set/LinearOrder.lean`). A conscious decision was made not to list all possible inclusion relations. Monotonicity results and "self" results *are* included. Most use cases can suffice with a transitive combination of those, for example: ``` theorem Ico_subset_Ici (h : a₂ ≤ a₁) : Ico a₁ b₁ ⊆ Ici a₂ := (Ico_subset_Ico_left h).trans Ico_subset_Ici_self ``` Logical equivalences, such as `Icc_subset_Ici_iff`, are however stated. -/ assert_not_exists RelIso open Function open OrderDual (toDual ofDual) variable {α : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp theorem left_mem_Ici : a ∈ Ici a := by simp theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] theorem right_mem_Iic : a ∈ Iic a := by simp @[simp] theorem Ici_toDual : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl @[simp] theorem Iic_toDual : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl @[simp] theorem Ioi_toDual : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl @[simp] theorem Iio_toDual : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl @[simp] theorem Icc_toDual : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm @[simp] theorem Ioc_toDual : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm @[simp] theorem Ico_toDual : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm @[simp] theorem Ioo_toDual : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm @[simp] theorem Ici_ofDual {x : αᵒᵈ} : Ici (ofDual x) = toDual ⁻¹' Iic x := rfl @[simp] theorem Iic_ofDual {x : αᵒᵈ} : Iic (ofDual x) = toDual ⁻¹' Ici x := rfl @[simp] theorem Ioi_ofDual {x : αᵒᵈ} : Ioi (ofDual x) = toDual ⁻¹' Iio x := rfl @[simp] theorem Iio_ofDual {x : αᵒᵈ} : Iio (ofDual x) = toDual ⁻¹' Ioi x := rfl @[simp] theorem Icc_ofDual {x y : αᵒᵈ} : Icc (ofDual y) (ofDual x) = toDual ⁻¹' Icc x y := Set.ext fun _ => and_comm @[simp] theorem Ico_ofDual {x y : αᵒᵈ} : Ico (ofDual y) (ofDual x) = toDual ⁻¹' Ioc x y := Set.ext fun _ => and_comm @[simp] theorem Ioc_ofDual {x y : αᵒᵈ} : Ioc (ofDual y) (ofDual x) = toDual ⁻¹' Ico x y := Set.ext fun _ => and_comm @[simp] theorem Ioo_ofDual {x y : αᵒᵈ} : Ioo (ofDual y) (ofDual x) = toDual ⁻¹' Ioo x y := Set.ext fun _ => and_comm @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_notMem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_notMem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_notMem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_notMem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_ge @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_gt @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_gt @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_gt theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a where mp h := by obtain ⟨ab, c, cb, ac⟩ := ssubset_iff_exists.mp h exact lt_of_le_not_ge (Ici_subset_Ici.mp ab) (fun h' ↦ ac (h'.trans cb)) mpr h := (ssubset_iff_of_subset (Ici_subset_Ici.mpr h.le)).mpr ⟨b, right_mem_Iic, fun h' => h.not_ge h'⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_ssubset_Ici_of_le⟩ := Ici_ssubset_Ici @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := @Ici_ssubset_Ici αᵒᵈ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_ssubset_Iic_of_le⟩ := Iic_ssubset_Iic @[simp] theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ @[simp] theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx /-- If `a < b`, then `(b, +∞) ⊂ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_ssubset_Ioi_iff`. -/ @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := (ssubset_iff_of_subset (Ioi_subset_Ioi h.le)).mpr ⟨b, h, lt_irrefl b⟩ /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h /-- If `a < b`, then `(-∞, a) ⊂ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_ssubset_Iio_iff`. -/ @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := (ssubset_iff_of_subset (Iio_subset_Iio h.le)).mpr ⟨a, h, lt_irrefl a⟩ /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h @[simp] theorem Ioi_eq_empty_iff : Ioi a = ∅ ↔ IsMax a := by simp only [isMax_iff_forall_not_lt, eq_empty_iff_forall_notMem, mem_Ioi] @[simp] theorem Iio_eq_empty_iff : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty_iff (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMax.Ioi_eq⟩ := Ioi_eq_empty_iff @[simp] alias ⟨_, _root_.IsMin.Iio_eq⟩ := Iio_eq_empty_iff @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ theorem notMem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_ge h.1 @[deprecated (since := "2025-05-23")] alias not_mem_Icc_of_lt := notMem_Icc_of_lt theorem notMem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_ge h.2 @[deprecated (since := "2025-05-23")] alias not_mem_Icc_of_gt := notMem_Icc_of_gt theorem notMem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_ge h.1 @[deprecated (since := "2025-05-23")] alias not_mem_Ico_of_lt := notMem_Ico_of_lt theorem notMem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_ge h.2 @[deprecated (since := "2025-05-23")] alias not_mem_Ioc_of_gt := notMem_Ioc_of_gt theorem notMem_Ioi_self : a ∉ Ioi a := lt_irrefl _ @[deprecated (since := "2025-05-23")] alias not_mem_Ioi_self := notMem_Ioi_self theorem notMem_Iio_self : b ∉ Iio b := lt_irrefl _ @[deprecated (since := "2025-05-23")] alias not_mem_Iio_self := notMem_Iio_self theorem notMem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha @[deprecated (since := "2025-05-23")] alias not_mem_Ioc_of_le := notMem_Ioc_of_le theorem notMem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb @[deprecated (since := "2025-05-23")] alias not_mem_Ico_of_ge := notMem_Ico_of_ge theorem notMem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha @[deprecated (since := "2025-05-23")] alias not_mem_Ioo_of_le := notMem_Ioo_of_le theorem notMem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb @[deprecated (since := "2025-05-23")] alias not_mem_Ioo_of_ge := notMem_Ioo_of_ge section matched_intervals @[simp] theorem Icc_eq_Ioc_same_iff : Icc a b = Ioc a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Icc_eq_empty h, Ioc_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ico_same_iff : Icc a b = Ico a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ico_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ioo_same_iff : Icc a b = Ioo a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ioo_eq_empty (mt le_of_lt h)] @[simp] theorem Ioc_eq_Ico_same_iff : Ioc a b = Ico a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioc_eq_empty h, Ico_eq_empty h] @[simp] theorem Ioo_eq_Ioc_same_iff : Ioo a b = Ioc a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Ioo_eq_empty h, Ioc_eq_empty h] @[simp] theorem Ioo_eq_Ico_same_iff : Ioo a b = Ico a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioo_eq_empty h, Ico_eq_empty h] -- Mirrored versions of the above for `simp`. @[simp] theorem Ioc_eq_Icc_same_iff : Ioc a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ioc_same_iff @[simp] theorem Ico_eq_Icc_same_iff : Ico a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ico_same_iff @[simp] theorem Ioo_eq_Icc_same_iff : Ioo a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ioo_same_iff @[simp] theorem Ico_eq_Ioc_same_iff : Ico a b = Ioc a b ↔ ¬a < b := eq_comm.trans Ioc_eq_Ico_same_iff @[simp] theorem Ioc_eq_Ioo_same_iff : Ioc a b = Ioo a b ↔ ¬a < b := eq_comm.trans Ioo_eq_Ioc_same_iff @[simp] theorem Ico_eq_Ioo_same_iff : Ico a b = Ioo a b ↔ ¬a < b := eq_comm.trans Ioo_eq_Ico_same_iff end matched_intervals end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h ▸ left_mem_Icc.2 hab, eq_of_mem_singleton <| h ▸ right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_imp_le_of_le_of_le hxb hay hba) (le_imp_le_of_le_of_le hyb hax hba) @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] @[simp] theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] theorem Ioi_union_left : Ioi a ∪ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] theorem Iio_union_right : Iio a ∪ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by simpa only [Ioo_toDual, Ico_toDual] using Ioo_union_left hab.dual theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by simpa only [Ioc_toDual, Icc_toDual] using Ioc_union_left hab.dual @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set α)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun _ hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) : s ∈ ({Iic a, Iio a} : Set (Set α)) := @mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s · refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_right] exact subset_diff_singleton hc hb · rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho · refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_left] exact subset_diff_singleton hc ha · rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_lt'.imp_right fun h => ⟨h, hmem.2⟩ theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_lt'.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff @[simp] theorem Icc_inter_Icc_eq_singleton (hab : a ≤ b) (hbc : b ≤ c) : Icc a b ∩ Icc b c = {b} := by rw [← Ici_inter_Iic, ← Iic_inter_Ici, inter_inter_inter_comm, Iic_inter_Ici] simp [hab, hbc] lemma Icc_eq_Icc_iff {d : α} (h : a ≤ b) : Icc a b = Icc c d ↔ a = c ∧ b = d := by refine ⟨fun heq ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ have h' : c ≤ d := by by_contra contra; rw [Icc_eq_empty_iff.mpr contra, Icc_eq_empty_iff] at heq; contradiction simp only [Set.ext_iff, mem_Icc] at heq obtain ⟨-, h₁⟩ := (heq b).mp ⟨h, le_refl _⟩ obtain ⟨h₂, -⟩ := (heq a).mp ⟨le_refl _, h⟩ obtain ⟨h₃, -⟩ := (heq c).mpr ⟨le_refl _, h'⟩ obtain ⟨-, h₄⟩ := (heq d).mpr ⟨h', le_refl _⟩ exact ⟨le_antisymm h₃ h₂, le_antisymm h₁ h₄⟩ end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} := isMax_top.Ici_eq variable [Preorder α] [OrderTop α] {a : α} theorem Ioi_top : Ioi (⊤ : α) = ∅ := isMax_top.Ioi_eq @[simp] theorem Iic_top : Iic (⊤ : α) = univ := isTop_top.Iic_eq @[simp] theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic] @[simp] theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic] end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} := isMin_bot.Iic_eq variable [Preorder α] [OrderBot α] {a : α} theorem Iio_bot : Iio (⊥ : α) = ∅ := isMin_bot.Iio_eq @[simp] theorem Ici_bot : Ici (⊥ : α) = univ := isBot_bot.Ici_eq @[simp] theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic] @[simp] theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio] end OrderBot theorem Icc_bot_top [Preorder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp section Lattice section Inf variable [SemilatticeInf α] @[simp] theorem Iic_inter_Iic {a b : α} : Iic a ∩ Iic b = Iic (a ⊓ b) := by ext x simp [Iic] @[simp] theorem Ioc_inter_Iic (a b c : α) : Ioc a b ∩ Iic c = Ioc a (b ⊓ c) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_assoc, Iic_inter_Iic] end Inf section Sup variable [SemilatticeSup α] @[simp] theorem Ici_inter_Ici {a b : α} : Ici a ∩ Ici b = Ici (a ⊔ b) := by ext x simp [Ici] @[simp] theorem Ico_inter_Ici (a b c : α) : Ico a b ∩ Ici c = Ico (a ⊔ c) b := by rw [← Ici_inter_Iio, ← Ici_inter_Iio, ← Ici_inter_Ici, inter_right_comm] end Sup section Both variable [Lattice α] {a b c a₁ a₂ b₁ b₂ : α} theorem Icc_inter_Icc : Icc a₁ b₁ ∩ Icc a₂ b₂ = Icc (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_rfl end Both end Lattice /-! ### Closed intervals in `α × β` -/ section Prod variable {β : Type*} [Preorder α] [Preorder β] @[simp] theorem Iic_prod_Iic (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) := rfl @[simp] theorem Ici_prod_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) := rfl theorem Ici_prod_eq (a : α × β) : Ici a = Ici a.1 ×ˢ Ici a.2 := rfl theorem Iic_prod_eq (a : α × β) : Iic a = Iic a.1 ×ˢ Iic a.2 := rfl @[simp] theorem Icc_prod_Icc (a₁ a₂ : α) (b₁ b₂ : β) : Icc a₁ a₂ ×ˢ Icc b₁ b₂ = Icc (a₁, b₁) (a₂, b₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] theorem Icc_prod_eq (a b : α × β) : Icc a b = Icc a.1 b.1 ×ˢ Icc a.2 b.2 := by simp end Prod end Set /-! ### Lemmas about intervals in dense orders -/ section Dense variable (α) [Preorder α] [DenselyOrdered α] {x y : α} instance : NoMinOrder (Set.Ioo x y) := ⟨fun ⟨a, ha₁, ha₂⟩ => by rcases exists_between ha₁ with ⟨b, hb₁, hb₂⟩ exact ⟨⟨b, hb₁, hb₂.trans ha₂⟩, hb₂⟩⟩ instance : NoMinOrder (Set.Ioc x y) := ⟨fun ⟨a, ha₁, ha₂⟩ => by rcases exists_between ha₁ with ⟨b, hb₁, hb₂⟩ exact ⟨⟨b, hb₁, hb₂.le.trans ha₂⟩, hb₂⟩⟩ instance : NoMinOrder (Set.Ioi x) := ⟨fun ⟨a, ha⟩ => by rcases exists_between ha with ⟨b, hb₁, hb₂⟩ exact ⟨⟨b, hb₁⟩, hb₂⟩⟩ instance : NoMaxOrder (Set.Ioo x y) := ⟨fun ⟨a, ha₁, ha₂⟩ => by rcases exists_between ha₂ with ⟨b, hb₁, hb₂⟩ exact ⟨⟨b, ha₁.trans hb₁, hb₂⟩, hb₁⟩⟩ instance : NoMaxOrder (Set.Ico x y) := ⟨fun ⟨a, ha₁, ha₂⟩ => by rcases exists_between ha₂ with ⟨b, hb₁, hb₂⟩ exact ⟨⟨b, ha₁.trans hb₁.le, hb₂⟩, hb₁⟩⟩ instance : NoMaxOrder (Set.Iio x) := ⟨fun ⟨a, ha⟩ => by rcases exists_between ha with ⟨b, hb₁, hb₂⟩ exact ⟨⟨b, hb₂⟩, hb₁⟩⟩ end Dense /-! ### Intervals in `Prop` -/ namespace Set @[simp] lemma Iic_False : Iic False = {False} := by aesop @[simp] lemma Iic_True : Iic True = univ := by aesop @[simp] lemma Ici_False : Ici False = univ := by aesop @[simp] lemma Ici_True : Ici True = {True} := by aesop lemma Iio_False : Iio False = ∅ := by aesop @[simp] lemma Iio_True : Iio True = {False} := by aesop (add simp [Ioi, lt_iff_le_not_ge]) @[simp] lemma Ioi_False : Ioi False = {True} := by aesop (add simp [Ioi, lt_iff_le_not_ge]) lemma Ioi_True : Ioi True = ∅ := by aesop end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/ProjIcc.lean
import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.OrdConnected /-! # Projection of a line onto a closed interval Given a linearly ordered type `α`, in this file we define * `Set.projIci (a : α)` to be the map `α → [a, ∞)` sending `(-∞, a]` to `a`, and each point `x ∈ [a, ∞)` to itself; * `Set.projIic (b : α)` to be the map `α → (-∞, b[` sending `[b, ∞)` to `b`, and each point `x ∈ (-∞, b]` to itself; * `Set.projIcc (a b : α) (h : a ≤ b)` to be the map `α → [a, b]` sending `(-∞, a]` to `a`, `[b, ∞)` to `b`, and each point `x ∈ [a, b]` to itself; * `Set.IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β)` to be the extension of `f` to `α` defined as `f ∘ projIcc a b h`. * `Set.IciExtend {a : α} (f : Ici a → β)` to be the extension of `f` to `α` defined as `f ∘ projIci a`. * `Set.IicExtend {b : α} (f : Iic b → β)` to be the extension of `f` to `α` defined as `f ∘ projIic b`. We also prove some trivial properties of these maps. -/ variable {α β : Type*} [LinearOrder α] open Function namespace Set /-- Projection of `α` to the closed interval `[a, ∞)`. -/ def projIci (a x : α) : Ici a := ⟨max a x, le_max_left _ _⟩ /-- Projection of `α` to the closed interval `(-∞, b]`. -/ def projIic (b x : α) : Iic b := ⟨min b x, min_le_left _ _⟩ /-- Projection of `α` to the closed interval `[a, b]`. -/ def projIcc (a b : α) (h : a ≤ b) (x : α) : Icc a b := ⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩ variable {a b : α} (h : a ≤ b) {x : α} @[norm_cast] theorem coe_projIci (a x : α) : (projIci a x : α) = max a x := rfl @[norm_cast] theorem coe_projIic (b x : α) : (projIic b x : α) = min b x := rfl @[norm_cast] theorem coe_projIcc (a b : α) (h : a ≤ b) (x : α) : (projIcc a b h x : α) = max a (min b x) := rfl theorem projIci_of_le (hx : x ≤ a) : projIci a x = ⟨a, le_rfl⟩ := Subtype.ext <| max_eq_left hx theorem projIic_of_le (hx : b ≤ x) : projIic b x = ⟨b, le_rfl⟩ := Subtype.ext <| min_eq_left hx theorem projIcc_of_le_left (hx : x ≤ a) : projIcc a b h x = ⟨a, left_mem_Icc.2 h⟩ := by simp [projIcc, hx, hx.trans h] theorem projIcc_of_right_le (hx : b ≤ x) : projIcc a b h x = ⟨b, right_mem_Icc.2 h⟩ := by simp [projIcc, hx, h] @[simp] theorem projIci_self (a : α) : projIci a a = ⟨a, le_rfl⟩ := projIci_of_le le_rfl @[simp] theorem projIic_self (b : α) : projIic b b = ⟨b, le_rfl⟩ := projIic_of_le le_rfl @[simp] theorem projIcc_left : projIcc a b h a = ⟨a, left_mem_Icc.2 h⟩ := projIcc_of_le_left h le_rfl @[simp] theorem projIcc_right : projIcc a b h b = ⟨b, right_mem_Icc.2 h⟩ := projIcc_of_right_le h le_rfl theorem projIci_eq_self : projIci a x = ⟨a, le_rfl⟩ ↔ x ≤ a := by simp [projIci, Subtype.ext_iff] theorem projIic_eq_self : projIic b x = ⟨b, le_rfl⟩ ↔ b ≤ x := by simp [projIic, Subtype.ext_iff] theorem projIcc_eq_left (h : a < b) : projIcc a b h.le x = ⟨a, left_mem_Icc.mpr h.le⟩ ↔ x ≤ a := by simp [projIcc, Subtype.ext_iff, h.not_ge] theorem projIcc_eq_right (h : a < b) : projIcc a b h.le x = ⟨b, right_mem_Icc.2 h.le⟩ ↔ b ≤ x := by simp [projIcc, Subtype.ext_iff, max_min_distrib_left, h.le, h.not_ge] theorem projIci_of_mem (hx : x ∈ Ici a) : projIci a x = ⟨x, hx⟩ := by simpa [projIci] theorem projIic_of_mem (hx : x ∈ Iic b) : projIic b x = ⟨x, hx⟩ := by simpa [projIic] theorem projIcc_of_mem (hx : x ∈ Icc a b) : projIcc a b h x = ⟨x, hx⟩ := by simp [projIcc, hx.1, hx.2] @[simp] theorem projIci_coe (x : Ici a) : projIci a x = x := by cases x; apply projIci_of_mem @[simp] theorem projIic_coe (x : Iic b) : projIic b x = x := by cases x; apply projIic_of_mem @[simp] theorem projIcc_val (x : Icc a b) : projIcc a b h x = x := by cases x apply projIcc_of_mem theorem projIci_surjOn : SurjOn (projIci a) (Ici a) univ := fun x _ => ⟨x, x.2, projIci_coe x⟩ theorem projIic_surjOn : SurjOn (projIic b) (Iic b) univ := fun x _ => ⟨x, x.2, projIic_coe x⟩ theorem projIcc_surjOn : SurjOn (projIcc a b h) (Icc a b) univ := fun x _ => ⟨x, x.2, projIcc_val h x⟩ theorem projIci_surjective : Surjective (projIci a) := fun x => ⟨x, projIci_coe x⟩ theorem projIic_surjective : Surjective (projIic b) := fun x => ⟨x, projIic_coe x⟩ theorem projIcc_surjective : Surjective (projIcc a b h) := fun x => ⟨x, projIcc_val h x⟩ @[simp] theorem range_projIci : range (projIci a) = univ := projIci_surjective.range_eq @[simp] theorem range_projIic : range (projIic a) = univ := projIic_surjective.range_eq @[simp] theorem range_projIcc : range (projIcc a b h) = univ := (projIcc_surjective h).range_eq theorem monotone_projIci : Monotone (projIci a) := fun _ _ => max_le_max le_rfl theorem monotone_projIic : Monotone (projIic a) := fun _ _ => min_le_min le_rfl theorem monotone_projIcc : Monotone (projIcc a b h) := fun _ _ hxy => max_le_max le_rfl <| min_le_min le_rfl hxy theorem strictMonoOn_projIci : StrictMonoOn (projIci a) (Ici a) := fun x hx y hy hxy => by simpa only [projIci_of_mem, hx, hy] theorem strictMonoOn_projIic : StrictMonoOn (projIic b) (Iic b) := fun x hx y hy hxy => by simpa only [projIic_of_mem, hx, hy] theorem strictMonoOn_projIcc : StrictMonoOn (projIcc a b h) (Icc a b) := fun x hx y hy hxy => by simpa only [projIcc_of_mem, hx, hy] /-- Extend a function `[a, ∞) → β` to a map `α → β`. -/ def IciExtend (f : Ici a → β) : α → β := f ∘ projIci a /-- Extend a function `(-∞, b] → β` to a map `α → β`. -/ def IicExtend (f : Iic b → β) : α → β := f ∘ projIic b /-- Extend a function `[a, b] → β` to a map `α → β`. -/ def IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β) : α → β := f ∘ projIcc a b h theorem IciExtend_apply (f : Ici a → β) (x : α) : IciExtend f x = f ⟨max a x, le_max_left _ _⟩ := rfl theorem IicExtend_apply (f : Iic b → β) (x : α) : IicExtend f x = f ⟨min b x, min_le_left _ _⟩ := rfl theorem IccExtend_apply (h : a ≤ b) (f : Icc a b → β) (x : α) : IccExtend h f x = f ⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩ := rfl @[simp] theorem range_IciExtend (f : Ici a → β) : range (IciExtend f) = range f := by simp only [IciExtend, range_comp f, range_projIci, image_univ] @[simp] theorem range_IicExtend (f : Iic b → β) : range (IicExtend f) = range f := by simp only [IicExtend, range_comp f, range_projIic, image_univ] @[simp] theorem IccExtend_range (f : Icc a b → β) : range (IccExtend h f) = range f := by simp only [IccExtend, range_comp f, range_projIcc, image_univ] theorem IciExtend_of_le (f : Ici a → β) (hx : x ≤ a) : IciExtend f x = f ⟨a, le_rfl⟩ := congr_arg f <| projIci_of_le hx theorem IicExtend_of_le (f : Iic b → β) (hx : b ≤ x) : IicExtend f x = f ⟨b, le_rfl⟩ := congr_arg f <| projIic_of_le hx theorem IccExtend_of_le_left (f : Icc a b → β) (hx : x ≤ a) : IccExtend h f x = f ⟨a, left_mem_Icc.2 h⟩ := congr_arg f <| projIcc_of_le_left h hx theorem IccExtend_of_right_le (f : Icc a b → β) (hx : b ≤ x) : IccExtend h f x = f ⟨b, right_mem_Icc.2 h⟩ := congr_arg f <| projIcc_of_right_le h hx @[simp] theorem IciExtend_self (f : Ici a → β) : IciExtend f a = f ⟨a, le_rfl⟩ := IciExtend_of_le f le_rfl @[simp] theorem IicExtend_self (f : Iic b → β) : IicExtend f b = f ⟨b, le_rfl⟩ := IicExtend_of_le f le_rfl @[simp] theorem IccExtend_left (f : Icc a b → β) : IccExtend h f a = f ⟨a, left_mem_Icc.2 h⟩ := IccExtend_of_le_left h f le_rfl @[simp] theorem IccExtend_right (f : Icc a b → β) : IccExtend h f b = f ⟨b, right_mem_Icc.2 h⟩ := IccExtend_of_right_le h f le_rfl theorem IciExtend_of_mem (f : Ici a → β) (hx : x ∈ Ici a) : IciExtend f x = f ⟨x, hx⟩ := congr_arg f <| projIci_of_mem hx theorem IicExtend_of_mem (f : Iic b → β) (hx : x ∈ Iic b) : IicExtend f x = f ⟨x, hx⟩ := congr_arg f <| projIic_of_mem hx theorem IccExtend_of_mem (f : Icc a b → β) (hx : x ∈ Icc a b) : IccExtend h f x = f ⟨x, hx⟩ := congr_arg f <| projIcc_of_mem h hx @[simp] theorem IciExtend_coe (f : Ici a → β) (x : Ici a) : IciExtend f x = f x := congr_arg f <| projIci_coe x @[simp] theorem IicExtend_coe (f : Iic b → β) (x : Iic b) : IicExtend f x = f x := congr_arg f <| projIic_coe x @[simp] theorem IccExtend_val (f : Icc a b → β) (x : Icc a b) : IccExtend h f x = f x := congr_arg f <| projIcc_val h x /-- If `f : α → β` is a constant both on $(-∞, a]$ and on $[b, +∞)$, then the extension of this function from $[a, b]$ to the whole line is equal to the original function. -/ theorem IccExtend_eq_self (f : α → β) (ha : ∀ x < a, f x = f a) (hb : ∀ x, b < x → f x = f b) : IccExtend h (f ∘ (↑)) = f := by ext x rcases lt_or_ge x a with hxa | hax · simp [IccExtend_of_le_left _ _ hxa.le, ha x hxa] · rcases le_or_gt x b with hxb | hbx · lift x to Icc a b using ⟨hax, hxb⟩ rw [IccExtend_val, comp_apply] · simp [IccExtend_of_right_le _ _ hbx.le, hb x hbx] end Set open Set variable [Preorder β] {s t : Set α} {a b : α} (h : a ≤ b) {f : Icc a b → β} protected theorem Monotone.IciExtend {f : Ici a → β} (hf : Monotone f) : Monotone (IciExtend f) := hf.comp monotone_projIci protected theorem Monotone.IicExtend {f : Iic b → β} (hf : Monotone f) : Monotone (IicExtend f) := hf.comp monotone_projIic protected theorem Monotone.IccExtend (hf : Monotone f) : Monotone (IccExtend h f) := hf.comp <| monotone_projIcc h theorem StrictMono.strictMonoOn_IciExtend {f : Ici a → β} (hf : StrictMono f) : StrictMonoOn (IciExtend f) (Ici a) := hf.comp_strictMonoOn strictMonoOn_projIci theorem StrictMono.strictMonoOn_IicExtend {f : Iic b → β} (hf : StrictMono f) : StrictMonoOn (IicExtend f) (Iic b) := hf.comp_strictMonoOn strictMonoOn_projIic theorem StrictMono.strictMonoOn_IccExtend (hf : StrictMono f) : StrictMonoOn (IccExtend h f) (Icc a b) := hf.comp_strictMonoOn (strictMonoOn_projIcc h) protected theorem Set.OrdConnected.IciExtend {s : Set (Ici a)} (hs : s.OrdConnected) : {x | IciExtend (· ∈ s) x}.OrdConnected := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨max_le_max le_rfl hz.1, max_le_max le_rfl hz.2⟩⟩ protected theorem Set.OrdConnected.IicExtend {s : Set (Iic b)} (hs : s.OrdConnected) : {x | IicExtend (· ∈ s) x}.OrdConnected := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨min_le_min le_rfl hz.1, min_le_min le_rfl hz.2⟩⟩ protected theorem Set.OrdConnected.restrict (hs : s.OrdConnected) : {x | restrict t (· ∈ s) x}.OrdConnected := ⟨fun _ hx _ hy _ hz => hs.out hx hy hz⟩
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Disjoint.lean
import Mathlib.Data.Set.Lattice.Image import Mathlib.Order.Interval.Set.LinearOrder import Mathlib.Order.MinMax /-! # Extra lemmas about intervals This file contains lemmas about intervals that cannot be included into `Order.Interval.Set.Basic` because this would create an `import` cycle. Namely, lemmas in this file can use definitions from `Data.Set.Lattice`, including `Disjoint`. We consider various intersections and unions of half infinite intervals. -/ universe u v w variable {ι : Sort u} {α : Type v} {β : Type w} open Set open OrderDual (toDual) namespace Set section Preorder variable [Preorder α] {a b c : α} @[simp] theorem Iic_disjoint_Ioi (h : a ≤ b) : Disjoint (Iic a) (Ioi b) := disjoint_left.mpr fun _ ha hb => (h.trans_lt hb).not_ge ha @[simp] theorem Iio_disjoint_Ici (h : a ≤ b) : Disjoint (Iio a) (Ici b) := disjoint_left.mpr fun _ ha hb => (h.trans_lt' ha).not_ge hb @[simp] theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := (Iic_disjoint_Ioi h).mono le_rfl Ioc_subset_Ioi_self @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (h : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := (Iic_disjoint_Ioc h).mono Ioc_subset_Iic_self le_rfl @[simp] theorem Ico_disjoint_Ico_same : Disjoint (Ico a b) (Ico b c) := disjoint_left.mpr fun _ hab hbc => hab.2.not_ge hbc.1 @[simp] theorem Ici_disjoint_Iic : Disjoint (Ici a) (Iic b) ↔ ¬a ≤ b := by rw [Set.disjoint_iff_inter_eq_empty, Ici_inter_Iic, Icc_eq_empty_iff] @[simp] theorem Iic_disjoint_Ici : Disjoint (Iic a) (Ici b) ↔ ¬b ≤ a := disjoint_comm.trans Ici_disjoint_Iic @[simp] theorem Ioc_disjoint_Ioi (h : b ≤ c) : Disjoint (Ioc a b) (Ioi c) := disjoint_left.mpr (fun _ hx hy ↦ (hx.2.trans h).not_gt hy) theorem Ioc_disjoint_Ioi_same : Disjoint (Ioc a b) (Ioi b) := Ioc_disjoint_Ioi le_rfl theorem Ioi_disjoint_Iio_of_not_lt (h : ¬a < b) : Disjoint (Ioi a) (Iio b) := disjoint_left.mpr fun _ hx hy ↦ h (hx.trans hy) theorem Ioi_disjoint_Iio_of_le (h : a ≤ b) : Disjoint (Ioi b) (Iio a) := Ioi_disjoint_Iio_of_not_lt (not_lt_of_ge h) @[simp] theorem Ioi_disjoint_Iio_same : Disjoint (Ioi a) (Iio a) := Ioi_disjoint_Iio_of_le le_rfl @[simp] theorem Ioi_disjoint_Iio_iff [DenselyOrdered α] : Disjoint (Ioi a) (Iio b) ↔ ¬a < b := ⟨fun h hab ↦ (exists_between hab).elim fun _ hc ↦ h.notMem_of_mem_left hc.left hc.right, Ioi_disjoint_Iio_of_not_lt⟩ theorem Iio_disjoint_Ioi_of_not_lt (h : ¬a < b) : Disjoint (Iio b) (Ioi a) := disjoint_comm.mp (Ioi_disjoint_Iio_of_not_lt h) theorem Iio_disjoint_Ioi_of_le (h : a ≤ b) : Disjoint (Iio a) (Ioi b) := disjoint_comm.mp (Ioi_disjoint_Iio_of_le h) @[simp] theorem Iio_disjoint_Ioi_same : Disjoint (Iio a) (Ioi a) := Iio_disjoint_Ioi_of_le le_rfl @[simp] theorem Iio_disjoint_Ioi_iff [DenselyOrdered α] : Disjoint (Iio a) (Ioi b) ↔ ¬b < a := disjoint_comm.trans Ioi_disjoint_Iio_iff @[simp] theorem iUnion_Iic : ⋃ a : α, Iic a = univ := iUnion_eq_univ_iff.2 fun x => ⟨x, right_mem_Iic⟩ @[simp] theorem iUnion_Ici : ⋃ a : α, Ici a = univ := iUnion_eq_univ_iff.2 fun x => ⟨x, left_mem_Ici⟩ @[simp] theorem iUnion_Icc_right (a : α) : ⋃ b, Icc a b = Ici a := by simp only [← Ici_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ] @[simp] theorem iUnion_Ioc_right (a : α) : ⋃ b, Ioc a b = Ioi a := by simp only [← Ioi_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ] @[simp] theorem iUnion_Icc_left (b : α) : ⋃ a, Icc a b = Iic b := by simp only [← Ici_inter_Iic, ← iUnion_inter, iUnion_Ici, univ_inter] @[simp] theorem iUnion_Ico_left (b : α) : ⋃ a, Ico a b = Iio b := by simp only [← Ici_inter_Iio, ← iUnion_inter, iUnion_Ici, univ_inter] @[simp] theorem iUnion_Iio [NoMaxOrder α] : ⋃ a : α, Iio a = univ := iUnion_eq_univ_iff.2 exists_gt @[simp] theorem iUnion_Ioi [NoMinOrder α] : ⋃ a : α, Ioi a = univ := iUnion_eq_univ_iff.2 exists_lt @[simp] theorem iUnion_Ico_right [NoMaxOrder α] (a : α) : ⋃ b, Ico a b = Ici a := by simp only [← Ici_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ] @[simp] theorem iUnion_Ioo_right [NoMaxOrder α] (a : α) : ⋃ b, Ioo a b = Ioi a := by simp only [← Ioi_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ] @[simp] theorem iUnion_Ioc_left [NoMinOrder α] (b : α) : ⋃ a, Ioc a b = Iic b := by simp only [← Ioi_inter_Iic, ← iUnion_inter, iUnion_Ioi, univ_inter] @[simp] theorem iUnion_Ioo_left [NoMinOrder α] (b : α) : ⋃ a, Ioo a b = Iio b := by simp only [← Ioi_inter_Iio, ← iUnion_inter, iUnion_Ioi, univ_inter] end Preorder section LinearOrder variable [LinearOrder α] {a₁ a₂ b₁ b₂ : α} @[simp] theorem Ico_disjoint_Ico : Disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [Set.disjoint_iff_inter_eq_empty, Ico_inter_Ico, Ico_eq_empty_iff, not_lt] @[simp] theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by have h : _ ↔ min (toDual a₁) (toDual b₁) ≤ max (toDual a₂) (toDual b₂) := Ico_disjoint_Ico simpa only [Ico_toDual] using h @[simp] theorem Ioo_disjoint_Ioo [DenselyOrdered α] : Disjoint (Set.Ioo a₁ a₂) (Set.Ioo b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [Set.disjoint_iff_inter_eq_empty, Ioo_inter_Ioo, Ioo_eq_empty_iff, not_lt] /-- If two half-open intervals are disjoint and the endpoint of one lies in the other, then it must be equal to the endpoint of the other. -/ theorem eq_of_Ico_disjoint {x₁ x₂ y₁ y₂ : α} (h : Disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) : y₁ = x₂ := by rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h apply le_antisymm h2.1 exact h.elim (fun h => absurd hx (not_lt_of_ge h)) id @[simp] theorem iUnion_Ico_eq_Iio_self_iff {f : ι → α} {a : α} : ⋃ i, Ico (f i) a = Iio a ↔ ∀ x < a, ∃ i, f i ≤ x := by simp [← Ici_inter_Iio, ← iUnion_inter, subset_def] @[simp] theorem iUnion_Ioc_eq_Ioi_self_iff {f : ι → α} {a : α} : ⋃ i, Ioc a (f i) = Ioi a ↔ ∀ x, a < x → ∃ i, x ≤ f i := by simp [← Ioi_inter_Iic, ← inter_iUnion, subset_def] @[simp] theorem biUnion_Ico_eq_Iio_self_iff {p : ι → Prop} {f : ∀ i, p i → α} {a : α} : ⋃ (i) (hi : p i), Ico (f i hi) a = Iio a ↔ ∀ x < a, ∃ i hi, f i hi ≤ x := by simp [← Ici_inter_Iio, ← iUnion_inter, subset_def] @[simp] theorem biUnion_Ioc_eq_Ioi_self_iff {p : ι → Prop} {f : ∀ i, p i → α} {a : α} : ⋃ (i) (hi : p i), Ioc a (f i hi) = Ioi a ↔ ∀ x, a < x → ∃ i hi, x ≤ f i hi := by simp [← Ioi_inter_Iic, ← inter_iUnion, subset_def] end LinearOrder end Set section UnionIxx variable [LinearOrder α] {s : Set α} {a : α} {f : ι → α} theorem IsGLB.biUnion_Ioi_eq (h : IsGLB s a) : ⋃ x ∈ s, Ioi x = Ioi a := by refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_ · exact Ioi_subset_Ioi (h.1 hx) · rcases h.exists_between hx with ⟨y, hys, _, hyx⟩ exact mem_biUnion hys hyx theorem IsGLB.iUnion_Ioi_eq (h : IsGLB (range f) a) : ⋃ x, Ioi (f x) = Ioi a := biUnion_range.symm.trans h.biUnion_Ioi_eq theorem IsLUB.biUnion_Iio_eq (h : IsLUB s a) : ⋃ x ∈ s, Iio x = Iio a := h.dual.biUnion_Ioi_eq theorem IsLUB.iUnion_Iio_eq (h : IsLUB (range f) a) : ⋃ x, Iio (f x) = Iio a := h.dual.iUnion_Ioi_eq theorem IsGLB.biUnion_Ici_eq_Ioi (a_glb : IsGLB s a) (a_notMem : a ∉ s) : ⋃ x ∈ s, Ici x = Ioi a := by refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_ · exact Ici_subset_Ioi.mpr (lt_of_le_of_ne (a_glb.1 hx) fun h => (h ▸ a_notMem) hx) · rcases a_glb.exists_between hx with ⟨y, hys, _, hyx⟩ rw [mem_iUnion₂] exact ⟨y, hys, hyx.le⟩ theorem IsGLB.biUnion_Ici_eq_Ici (a_glb : IsGLB s a) (a_mem : a ∈ s) : ⋃ x ∈ s, Ici x = Ici a := by refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_ · exact Ici_subset_Ici.mpr (mem_lowerBounds.mp a_glb.1 x hx) · exact mem_iUnion₂.mpr ⟨a, a_mem, hx⟩ theorem IsLUB.biUnion_Iic_eq_Iio (a_lub : IsLUB s a) (a_notMem : a ∉ s) : ⋃ x ∈ s, Iic x = Iio a := a_lub.dual.biUnion_Ici_eq_Ioi a_notMem theorem IsLUB.biUnion_Iic_eq_Iic (a_lub : IsLUB s a) (a_mem : a ∈ s) : ⋃ x ∈ s, Iic x = Iic a := a_lub.dual.biUnion_Ici_eq_Ici a_mem theorem iUnion_Ici_eq_Ioi_iInf {R : Type*} [CompleteLinearOrder R] {f : ι → R} (no_least_elem : ⨅ i, f i ∉ range f) : ⋃ i : ι, Ici (f i) = Ioi (⨅ i, f i) := by simp only [← IsGLB.biUnion_Ici_eq_Ioi (@isGLB_iInf _ _ _ f) no_least_elem, mem_range, iUnion_exists, iUnion_iUnion_eq'] theorem iUnion_Iic_eq_Iio_iSup {R : Type*} [CompleteLinearOrder R] {f : ι → R} (no_greatest_elem : (⨆ i, f i) ∉ range f) : ⋃ i : ι, Iic (f i) = Iio (⨆ i, f i) := @iUnion_Ici_eq_Ioi_iInf ι (OrderDual R) _ f no_greatest_elem theorem iUnion_Ici_eq_Ici_iInf {R : Type*} [CompleteLinearOrder R] {f : ι → R} (has_least_elem : (⨅ i, f i) ∈ range f) : ⋃ i : ι, Ici (f i) = Ici (⨅ i, f i) := by simp only [← IsGLB.biUnion_Ici_eq_Ici (@isGLB_iInf _ _ _ f) has_least_elem, mem_range, iUnion_exists, iUnion_iUnion_eq'] theorem iUnion_Iic_eq_Iic_iSup {R : Type*} [CompleteLinearOrder R] {f : ι → R} (has_greatest_elem : (⨆ i, f i) ∈ range f) : ⋃ i : ι, Iic (f i) = Iic (⨆ i, f i) := @iUnion_Ici_eq_Ici_iInf ι (OrderDual R) _ f has_greatest_elem theorem iUnion_Iio_eq_univ_iff : ⋃ i, Iio (f i) = univ ↔ (¬ BddAbove (range f)) := by simp [not_bddAbove_iff, Set.eq_univ_iff_forall] theorem iUnion_Iic_of_not_bddAbove_range (hf : ¬ BddAbove (range f)) : ⋃ i, Iic (f i) = univ := by refine Set.eq_univ_of_subset ?_ (iUnion_Iio_eq_univ_iff.mpr hf) gcongr exact Iio_subset_Iic_self theorem iInter_Iic_eq_empty_iff : ⋂ i, Iic (f i) = ∅ ↔ ¬ BddBelow (range f) := by simp [not_bddBelow_iff, Set.eq_empty_iff_forall_notMem] theorem iInter_Iio_of_not_bddBelow_range (hf : ¬ BddBelow (range f)) : ⋂ i, Iio (f i) = ∅ := by refine eq_empty_of_subset_empty ?_ rw [← iInter_Iic_eq_empty_iff.mpr hf] gcongr exact Iio_subset_Iic_self end UnionIxx
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Defs.lean
import Mathlib.Data.Set.Defs import Mathlib.Order.Defs.PartialOrder /-! # Intervals In any preorder `α`, we define intervals (which on each side can be either infinite, open, or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. We also define a typeclass `Set.OrdConnected` saying that a set includes `Set.Icc a b` whenever it contains both `a` and `b`. -/ namespace Set variable {α : Type*} [Preorder α] {a b x : α} /-- `Ioo a b` is the left-open right-open interval $(a, b)$. -/ def Ioo (a b : α) := { x | a < x ∧ x < b } @[simp, grind =] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl /-- `Ico a b` is the left-closed right-open interval $[a, b)$. -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } @[simp, grind =] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl /-- `Iio b` is the left-infinite right-open interval $(-∞, b)$. -/ def Iio (b : α) := { x | x < b } @[simp, grind =] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl /-- `Icc a b` is the left-closed right-closed interval $[a, b]$. -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } @[simp, grind =] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl /-- `Iic b` is the left-infinite right-closed interval $(-∞, b]$. -/ def Iic (b : α) := { x | x ≤ b } @[simp, grind =] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl /-- `Ioc a b` is the left-open right-closed interval $(a, b]$. -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } @[simp, grind =] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl /-- `Ici a` is the left-closed right-infinite interval $[a, ∞)$. -/ def Ici (a : α) := { x | a ≤ x } @[simp, grind =] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl /-- `Ioi a` is the left-open right-infinite interval $(a, ∞)$. -/ def Ioi (a : α) := { x | a < x } @[simp, grind =] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl /-- We say that a set `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. If `α` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `α` is a `LinearOrderedField`, then this condition is also equivalent to `Convex α s`. -/ class OrdConnected (s : Set α) : Prop where /-- `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. -/ out' ⦃x : α⦄ (hx : x ∈ s) ⦃y : α⦄ (hy : y ∈ s) : Icc x y ⊆ s end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/InitialSeg.lean
import Mathlib.Order.InitialSeg /-! # Intervals as initial segments We show that `Set.Iic` and `Set.Iio` are respectively initial and principal segments, and that any principal segment `f` is order isomorphic to `Set.Iio f.top`. -/ namespace Set variable {α : Type*} [Preorder α] /-- `Set.Iic j` is an initial segment. -/ @[simps] def initialSegIic (j : α) : Set.Iic j ≤i α where toFun := fun ⟨j, hj⟩ ↦ j inj' _ _ _ := by aesop map_rel_iff' := by aesop mem_range_of_rel' x k h := by simpa using h.le.trans x.2 /-- `Set.Iio j` is a principal segment. -/ @[simps] def principalSegIio (j : α) : Set.Iio j <i α where top := j toFun := fun ⟨j, hj⟩ ↦ j inj' _ _ _ := by aesop map_rel_iff' := by aesop mem_range_iff_rel' := by aesop @[simp] lemma principalSegIio_toRelEmbedding {j : α} (k : Iio j) : (Set.principalSegIio j).toRelEmbedding k = k.1 := rfl /-- If `i ≤ j`, then `Set.Iic i` is an initial segment of `Set.Iic j`. -/ @[simps] def initialSegIicIicOfLE {i j : α} (h : i ≤ j) : Set.Iic i ≤i Set.Iic j where toFun := fun ⟨k, hk⟩ ↦ ⟨k, hk.trans h⟩ inj' _ _ _ := by aesop map_rel_iff' := by aesop mem_range_of_rel' x k h := ⟨⟨k.1, (Subtype.coe_le_coe.2 h.le).trans x.2⟩, rfl⟩ /-- If `i ≤ j`, then `Set.Iio i` is a principal segment of `Set.Iic j`. -/ @[simps top] def principalSegIioIicOfLE {i j : α} (h : i ≤ j) : Set.Iio i <i Set.Iic j where top := ⟨i, h⟩ toFun := fun ⟨k, hk⟩ ↦ ⟨k, hk.le.trans h⟩ inj' _ _ _ := by aesop map_rel_iff' := by aesop mem_range_iff_rel' := by aesop @[simp] lemma principalSegIioIicOfLE_toRelEmbedding {i j : α} (h : i ≤ j) (k : Iio i) : (Set.principalSegIioIicOfLE h).toRelEmbedding k = ⟨k, k.2.le.trans h⟩ := rfl end Set /-- If `f : α <i β` is a principal segment, this is the induced order isomorphism `α ≃o Set.Iio f.top`. -/ @[simps! apply_coe] noncomputable def PrincipalSeg.orderIsoIio {α β : Type*} [PartialOrder α] [PartialOrder β] (f : α <i β) : α ≃o Set.Iio f.top where toEquiv := Equiv.ofBijective (f := fun a ↦ ⟨f a, f.lt_top a⟩) (by constructor · intro x y hxy exact f.injective (by simpa using hxy) · rintro ⟨z, hz⟩ obtain ⟨x, hx⟩ := f.mem_range_of_rel_top hz exact ⟨x, by simpa using hx⟩) map_rel_iff' := by simp
.lake/packages/mathlib/Mathlib/Order/Interval/Set/LinearOrder.lean
import Mathlib.Order.Interval.Set.Basic /-! # Interval properties in linear orders Since every pair of elements are comparable in a linear order, intervals over them are better behaved. This file collects their properties under this assumption. -/ assert_not_exists RelIso open Function namespace Set variable {α : Type*} [LinearOrder α] {a a₁ a₂ b b₁ b₂ c d : α} theorem notMem_Ici : c ∉ Ici a ↔ c < a := not_le @[deprecated (since := "2025-05-23")] alias not_mem_Ici := notMem_Ici theorem notMem_Iic : c ∉ Iic b ↔ b < c := not_le @[deprecated (since := "2025-05-23")] alias not_mem_Iic := notMem_Iic theorem notMem_Ioi : c ∉ Ioi a ↔ c ≤ a := not_lt @[deprecated (since := "2025-05-23")] alias not_mem_Ioi := notMem_Ioi theorem notMem_Iio : c ∉ Iio b ↔ b ≤ c := not_lt @[deprecated (since := "2025-05-23")] alias not_mem_Iio := notMem_Iio @[simp] theorem compl_Iic : (Iic a)ᶜ = Ioi a := ext fun _ => not_le @[simp] theorem compl_Ici : (Ici a)ᶜ = Iio a := ext fun _ => not_le @[simp] theorem compl_Iio : (Iio a)ᶜ = Ici a := ext fun _ => not_lt @[simp] theorem compl_Ioi : (Ioi a)ᶜ = Iic a := ext fun _ => not_lt @[simp] theorem Ici_diff_Ici : Ici a \ Ici b = Ico a b := by rw [diff_eq, compl_Ici, Ici_inter_Iio] @[simp] theorem Ici_diff_Ioi : Ici a \ Ioi b = Icc a b := by rw [diff_eq, compl_Ioi, Ici_inter_Iic] @[simp] theorem Ioi_diff_Ioi : Ioi a \ Ioi b = Ioc a b := by rw [diff_eq, compl_Ioi, Ioi_inter_Iic] @[simp] theorem Ioi_diff_Ici : Ioi a \ Ici b = Ioo a b := by rw [diff_eq, compl_Ici, Ioi_inter_Iio] @[simp] theorem Iic_diff_Iic : Iic b \ Iic a = Ioc a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic] @[simp] theorem Iio_diff_Iic : Iio b \ Iic a = Ioo a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio] @[simp] theorem Iic_diff_Iio : Iic b \ Iio a = Icc a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic] @[simp] theorem Iio_diff_Iio : Iio b \ Iio a = Ico a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio] theorem Ioi_injective : Injective (Ioi : α → Set α) := fun _ _ => eq_of_forall_gt_iff ∘ Set.ext_iff.1 theorem Iio_injective : Injective (Iio : α → Set α) := fun _ _ => eq_of_forall_lt_iff ∘ Set.ext_iff.1 theorem Ioi_inj : Ioi a = Ioi b ↔ a = b := Ioi_injective.eq_iff theorem Iio_inj : Iio a = Iio b ↔ a = b := Iio_injective.eq_iff theorem Ico_subset_Ico_iff (h₁ : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => have : a₂ ≤ a₁ ∧ a₁ < b₂ := h ⟨le_rfl, h₁⟩ ⟨this.1, le_of_not_gt fun h' => lt_irrefl b₂ (h ⟨this.2.le, h'⟩).2⟩, fun ⟨h₁, h₂⟩ => Ico_subset_Ico h₁ h₂⟩ theorem Ioc_subset_Ioc_iff (h₁ : a₁ < b₁) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ b₁ ≤ b₂ ∧ a₂ ≤ a₁ := by convert @Ico_subset_Ico_iff αᵒᵈ _ b₁ b₂ a₁ a₂ h₁ using 2 <;> exact (@Ico_toDual α _ _ _).symm theorem Ioo_subset_Ioo_iff [DenselyOrdered α] (h₁ : a₁ < b₁) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => by rcases exists_between h₁ with ⟨x, xa, xb⟩ constructor <;> refine le_of_not_gt fun h' => ?_ · have ab := (h ⟨xa, xb⟩).1.trans xb exact lt_irrefl _ (h ⟨h', ab⟩).1 · have ab := xa.trans (h ⟨xa, xb⟩).2 exact lt_irrefl _ (h ⟨ab, h'⟩).2, fun ⟨h₁, h₂⟩ => Ioo_subset_Ioo h₁ h₂⟩ theorem Ico_eq_Ico_iff (h : a₁ < b₁ ∨ a₂ < b₂) : Ico a₁ b₁ = Ico a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := ⟨fun e => by simp only [Subset.antisymm_iff] at e simp only [le_antisymm_iff] rcases h with h | h <;> simp only [Ico_subset_Ico_iff h] at e <;> [ rcases e with ⟨⟨h₁, h₂⟩, e'⟩; rcases e with ⟨e', ⟨h₁, h₂⟩⟩ ] <;> have hab := (Ico_subset_Ico_iff <| h₁.trans_lt <| h.trans_le h₂).1 e' <;> tauto, fun ⟨h₁, h₂⟩ => by rw [h₁, h₂]⟩ lemma Ici_eq_singleton_iff_isTop {x : α} : (Ici x = {x}) ↔ IsTop x := by refine ⟨fun h y ↦ ?_, fun h ↦ by ext y; simp [(h y).ge_iff_eq]⟩ by_contra! H have : y ∈ Ici x := H.le rw [h, mem_singleton_iff] at this exact lt_irrefl y (this.le.trans_lt H) @[simp] theorem Ioi_subset_Ioi_iff : Ioi b ⊆ Ioi a ↔ a ≤ b := by refine ⟨fun h => ?_, Ioi_subset_Ioi⟩ by_contra ba exact lt_irrefl _ (h (not_le.mp ba)) @[simp] theorem Ioi_ssubset_Ioi_iff : Ioi b ⊂ Ioi a ↔ a < b := by refine ⟨fun h => ?_, Ioi_ssubset_Ioi⟩ obtain ⟨_, c, ac, cb⟩ := ssubset_iff_exists.mp h exact ac.trans_le (le_of_not_gt cb) @[simp] theorem Ioi_subset_Ici_iff [DenselyOrdered α] : Ioi b ⊆ Ici a ↔ a ≤ b := by refine ⟨fun h => ?_, Ioi_subset_Ici⟩ by_contra ba obtain ⟨c, bc, ca⟩ : ∃ c, b < c ∧ c < a := exists_between (not_le.mp ba) exact lt_irrefl _ (ca.trans_le (h bc)) @[simp] theorem Iio_subset_Iio_iff : Iio a ⊆ Iio b ↔ a ≤ b := by refine ⟨fun h => ?_, Iio_subset_Iio⟩ by_contra ab exact lt_irrefl _ (h (not_le.mp ab)) @[simp] theorem Iio_ssubset_Iio_iff : Iio a ⊂ Iio b ↔ a < b := by refine ⟨fun h => ?_, Iio_ssubset_Iio⟩ obtain ⟨_, c, cb, ac⟩ := ssubset_iff_exists.mp h exact (le_of_not_gt ac).trans_lt cb @[simp] theorem Iio_subset_Iic_iff [DenselyOrdered α] : Iio a ⊆ Iic b ↔ a ≤ b := by rw [← diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt] /-! ### Two infinite intervals -/ theorem Iic_union_Ioi_of_le (h : a ≤ b) : Iic b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.gt_or_le x).symm theorem Iio_union_Ici_of_le (h : a ≤ b) : Iio b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.ge_or_lt x).symm theorem Iic_union_Ici_of_le (h : a ≤ b) : Iic b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.ge_or_le x).symm theorem Iio_union_Ioi_of_lt (h : a < b) : Iio b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.gt_or_lt x).symm @[simp] theorem Iic_union_Ici : Iic a ∪ Ici a = univ := Iic_union_Ici_of_le le_rfl @[simp] theorem Iio_union_Ici : Iio a ∪ Ici a = univ := Iio_union_Ici_of_le le_rfl @[simp] theorem Iic_union_Ioi : Iic a ∪ Ioi a = univ := Iic_union_Ioi_of_le le_rfl @[simp] theorem Iio_union_Ioi : Iio a ∪ Ioi a = {a}ᶜ := ext fun _ => lt_or_lt_iff_ne /-! ### A finite and an infinite interval -/ theorem Ioo_union_Ioi' (h₁ : c < b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by grind theorem Ioo_union_Ioi (h : c < max a b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by grind theorem Ioi_subset_Ioo_union_Ici : Ioi a ⊆ Ioo a b ∪ Ici b := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb @[simp] theorem Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioo_union_Ici theorem Ici_subset_Ico_union_Ici : Ici a ⊆ Ico a b ∪ Ici b := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb @[simp] theorem Ico_union_Ici_eq_Ici (h : a ≤ b) : Ico a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Ico_union_Ici theorem Ico_union_Ici' (h₁ : c ≤ b) : Ico a b ∪ Ici c = Ici (min a c) := by grind theorem Ico_union_Ici (h : c ≤ max a b) : Ico a b ∪ Ici c = Ici (min a c) := by grind theorem Ioi_subset_Ioc_union_Ioi : Ioi a ⊆ Ioc a b ∪ Ioi b := fun x hx => (le_or_gt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb @[simp] theorem Ioc_union_Ioi_eq_Ioi (h : a ≤ b) : Ioc a b ∪ Ioi b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_lt) Ioi_subset_Ioc_union_Ioi theorem Ioc_union_Ioi' (h₁ : c ≤ b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by grind theorem Ioc_union_Ioi (h : c ≤ max a b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by grind theorem Ici_subset_Icc_union_Ioi : Ici a ⊆ Icc a b ∪ Ioi b := fun x hx => (le_or_gt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb @[simp] theorem Icc_union_Ioi_eq_Ici (h : a ≤ b) : Icc a b ∪ Ioi b = Ici a := Subset.antisymm (fun _ hx => (hx.elim And.left) fun hx' => h.trans <| le_of_lt hx') Ici_subset_Icc_union_Ioi theorem Ioi_subset_Ioc_union_Ici : Ioi a ⊆ Ioc a b ∪ Ici b := Subset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self) @[simp] theorem Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioc_union_Ici theorem Ici_subset_Icc_union_Ici : Ici a ⊆ Icc a b ∪ Ici b := Subset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self) @[simp] theorem Icc_union_Ici_eq_Ici (h : a ≤ b) : Icc a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Icc_union_Ici theorem Icc_union_Ici' (h₁ : c ≤ b) : Icc a b ∪ Ici c = Ici (min a c) := by grind theorem Icc_union_Ici (h : c ≤ max a b) : Icc a b ∪ Ici c = Ici (min a c) := by grind /-! ### An infinite and a finite interval -/ theorem Iic_subset_Iio_union_Icc : Iic b ⊆ Iio a ∪ Icc a b := fun x hx => (lt_or_ge x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ @[simp] theorem Iio_union_Icc_eq_Iic (h : a ≤ b) : Iio a ∪ Icc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx => (le_of_lt hx).trans h) And.right) Iic_subset_Iio_union_Icc theorem Iio_subset_Iio_union_Ico : Iio b ⊆ Iio a ∪ Ico a b := fun x hx => (lt_or_ge x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ @[simp] theorem Iio_union_Ico_eq_Iio (h : a ≤ b) : Iio a ∪ Ico a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_lt_of_le hx' h) And.right) Iio_subset_Iio_union_Ico theorem Iio_union_Ico' (h₁ : c ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by grind theorem Iio_union_Ico (h : min c d ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by grind theorem Iic_subset_Iic_union_Ioc : Iic b ⊆ Iic a ∪ Ioc a b := fun x hx => (le_or_gt x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ @[simp] theorem Iic_union_Ioc_eq_Iic (h : a ≤ b) : Iic a ∪ Ioc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => le_trans hx' h) And.right) Iic_subset_Iic_union_Ioc theorem Iic_union_Ioc' (h₁ : c < b) : Iic b ∪ Ioc c d = Iic (max b d) := by grind theorem Iic_union_Ioc (h : min c d < b) : Iic b ∪ Ioc c d = Iic (max b d) := by grind theorem Iio_subset_Iic_union_Ioo : Iio b ⊆ Iic a ∪ Ioo a b := fun x hx => (le_or_gt x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ @[simp] theorem Iic_union_Ioo_eq_Iio (h : a < b) : Iic a ∪ Ioo a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_le_of_lt hx' h) And.right) Iio_subset_Iic_union_Ioo theorem Iio_union_Ioo' (h₁ : c < b) : Iio b ∪ Ioo c d = Iio (max b d) := by grind theorem Iio_union_Ioo (h : min c d < b) : Iio b ∪ Ioo c d = Iio (max b d) := by grind theorem Iic_subset_Iic_union_Icc : Iic b ⊆ Iic a ∪ Icc a b := Subset.trans Iic_subset_Iic_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self) @[simp] theorem Iic_union_Icc_eq_Iic (h : a ≤ b) : Iic a ∪ Icc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => le_trans hx' h) And.right) Iic_subset_Iic_union_Icc theorem Iic_union_Icc' (h₁ : c ≤ b) : Iic b ∪ Icc c d = Iic (max b d) := by grind theorem Iic_union_Icc (h : min c d ≤ b) : Iic b ∪ Icc c d = Iic (max b d) := by grind theorem Iio_subset_Iic_union_Ico : Iio b ⊆ Iic a ∪ Ico a b := Subset.trans Iio_subset_Iic_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self) @[simp] theorem Iic_union_Ico_eq_Iio (h : a < b) : Iic a ∪ Ico a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_le_of_lt hx' h) And.right) Iio_subset_Iic_union_Ico /-! ### Two finite intervals, `I?o` and `Ic?` -/ theorem Ioo_subset_Ioo_union_Ico : Ioo a c ⊆ Ioo a b ∪ Ico b c := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Ioo_union_Ico_eq_Ioo (h₁ : a < b) (h₂ : b ≤ c) : Ioo a b ∪ Ico b c = Ioo a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_le h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩) Ioo_subset_Ioo_union_Ico theorem Ico_subset_Ico_union_Ico : Ico a c ⊆ Ico a b ∪ Ico b c := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Ico_union_Ico_eq_Ico (h₁ : a ≤ b) (h₂ : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_le h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Ico_subset_Ico_union_Ico theorem Ico_union_Ico' (h₁ : c ≤ b) (h₂ : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by grind theorem Ico_union_Ico (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by grind theorem Icc_subset_Ico_union_Icc : Icc a c ⊆ Ico a b ∪ Icc b c := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Ico_union_Icc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Ico a b ∪ Icc b c = Icc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.le.trans h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Icc_subset_Ico_union_Icc theorem Ioc_subset_Ioo_union_Icc : Ioc a c ⊆ Ioo a b ∪ Icc b c := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Ioo_union_Icc_eq_Ioc (h₁ : a < b) (h₂ : b ≤ c) : Ioo a b ∪ Icc b c = Ioc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.le.trans h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩) Ioc_subset_Ioo_union_Icc /-! ### Two finite intervals, `I?c` and `Io?` -/ theorem Ioo_subset_Ioc_union_Ioo : Ioo a c ⊆ Ioc a b ∪ Ioo b c := fun x hx => (le_or_gt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Ioc_union_Ioo_eq_Ioo (h₁ : a ≤ b) (h₂ : b < c) : Ioc a b ∪ Ioo b c = Ioo a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans_lt hx.1, hx.2⟩) Ioo_subset_Ioc_union_Ioo theorem Ico_subset_Icc_union_Ioo : Ico a c ⊆ Icc a b ∪ Ioo b c := fun x hx => (le_or_gt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Icc_union_Ioo_eq_Ico (h₁ : a ≤ b) (h₂ : b < c) : Icc a b ∪ Ioo b c = Ico a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans hx.1.le, hx.2⟩) Ico_subset_Icc_union_Ioo theorem Icc_subset_Icc_union_Ioc : Icc a c ⊆ Icc a b ∪ Ioc b c := fun x hx => (le_or_gt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Icc_union_Ioc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Icc a b ∪ Ioc b c = Icc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans hx.1.le, hx.2⟩) Icc_subset_Icc_union_Ioc theorem Ioc_subset_Ioc_union_Ioc : Ioc a c ⊆ Ioc a b ∪ Ioc b c := fun x hx => (le_or_gt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ @[simp] theorem Ioc_union_Ioc_eq_Ioc (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans_lt hx.1, hx.2⟩) Ioc_subset_Ioc_union_Ioc theorem Ioc_union_Ioc' (h₁ : c ≤ b) (h₂ : a ≤ d) : Ioc a b ∪ Ioc c d = Ioc (min a c) (max b d) := by grind theorem Ioc_union_Ioc (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ioc a b ∪ Ioc c d = Ioc (min a c) (max b d) := by grind /-! ### Two finite intervals with a common point -/ theorem Ioo_subset_Ioc_union_Ico : Ioo a c ⊆ Ioc a b ∪ Ico b c := Subset.trans Ioo_subset_Ioc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self) @[simp] theorem Ioc_union_Ico_eq_Ioo (h₁ : a < b) (h₂ : b < c) : Ioc a b ∪ Ico b c = Ioo a c := Subset.antisymm (fun _ hx => hx.elim (fun hx' => ⟨hx'.1, hx'.2.trans_lt h₂⟩) fun hx' => ⟨h₁.trans_le hx'.1, hx'.2⟩) Ioo_subset_Ioc_union_Ico theorem Ico_subset_Icc_union_Ico : Ico a c ⊆ Icc a b ∪ Ico b c := Subset.trans Ico_subset_Icc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self) @[simp] theorem Icc_union_Ico_eq_Ico (h₁ : a ≤ b) (h₂ : b < c) : Icc a b ∪ Ico b c = Ico a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Ico_subset_Icc_union_Ico theorem Icc_subset_Icc_union_Icc : Icc a c ⊆ Icc a b ∪ Icc b c := Subset.trans Icc_subset_Icc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self) @[simp] theorem Icc_union_Icc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Icc a b ∪ Icc b c = Icc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Icc_subset_Icc_union_Icc theorem Icc_union_Icc' (h₁ : c ≤ b) (h₂ : a ≤ d) : Icc a b ∪ Icc c d = Icc (min a c) (max b d) := by grind /-- We cannot replace `<` by `≤` in the hypotheses. Otherwise for `b < a = d < c` the l.h.s. is `∅` and the r.h.s. is `{a}`. -/ theorem Icc_union_Icc (h₁ : min a b < max c d) (h₂ : min c d < max a b) : Icc a b ∪ Icc c d = Icc (min a c) (max b d) := by grind theorem Ioc_subset_Ioc_union_Icc : Ioc a c ⊆ Ioc a b ∪ Icc b c := Subset.trans Ioc_subset_Ioc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self) @[simp] theorem Ioc_union_Icc_eq_Ioc (h₁ : a < b) (h₂ : b ≤ c) : Ioc a b ∪ Icc b c = Ioc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩) Ioc_subset_Ioc_union_Icc theorem Ioo_union_Ioo' (h₁ : c < b) (h₂ : a < d) : Ioo a b ∪ Ioo c d = Ioo (min a c) (max b d) := by grind theorem Ioo_union_Ioo (h₁ : min a b < max c d) (h₂ : min c d < max a b) : Ioo a b ∪ Ioo c d = Ioo (min a c) (max b d) := by grind theorem Ioo_subset_Ioo_union_Ioo (h₁ : a ≤ a₁) (h₂ : c < b) (h₃ : b₁ ≤ d) : Ioo a₁ b₁ ⊆ Ioo a b ∪ Ioo c d := fun x hx => (lt_or_ge x b).elim (fun hxb => Or.inl ⟨lt_of_le_of_lt h₁ hx.1, hxb⟩) fun hxb => Or.inr ⟨lt_of_lt_of_le h₂ hxb, lt_of_lt_of_le hx.2 h₃⟩ /-! ### Intersection, difference, complement -/ @[simp] theorem Ioi_inter_Ioi : Ioi a ∩ Ioi b = Ioi (a ⊔ b) := ext fun _ => sup_lt_iff.symm @[simp] theorem Iio_inter_Iio : Iio a ∩ Iio b = Iio (a ⊓ b) := ext fun _ => lt_inf_iff.symm theorem Ico_inter_Ico : Ico a₁ b₁ ∩ Ico a₂ b₂ = Ico (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by grind theorem Ioc_inter_Ioc : Ioc a₁ b₁ ∩ Ioc a₂ b₂ = Ioc (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by grind theorem Ioo_inter_Ioo : Ioo a₁ b₁ ∩ Ioo a₂ b₂ = Ioo (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by grind theorem Ioo_inter_Iio : Ioo a b ∩ Iio c = Ioo a (min b c) := by grind theorem Iio_inter_Ioo : Iio a ∩ Ioo b c = Ioo b (min a c) := by grind theorem Ioo_inter_Ioi : Ioo a b ∩ Ioi c = Ioo (max a c) b := by grind theorem Ioi_inter_Ioo : Set.Ioi a ∩ Set.Ioo b c = Set.Ioo (max a b) c := by grind theorem Ioc_inter_Ioo_of_left_lt (h : b₁ < b₂) : Ioc a₁ b₁ ∩ Ioo a₂ b₂ = Ioc (max a₁ a₂) b₁ := by grind theorem Ioc_inter_Ioo_of_right_le (h : b₂ ≤ b₁) : Ioc a₁ b₁ ∩ Ioo a₂ b₂ = Ioo (max a₁ a₂) b₂ := by grind theorem Ioo_inter_Ioc_of_left_le (h : b₁ ≤ b₂) : Ioo a₁ b₁ ∩ Ioc a₂ b₂ = Ioo (max a₁ a₂) b₁ := by grind theorem Ioo_inter_Ioc_of_right_lt (h : b₂ < b₁) : Ioo a₁ b₁ ∩ Ioc a₂ b₂ = Ioc (max a₁ a₂) b₂ := by grind @[simp] theorem Ico_diff_Iio : Ico a b \ Iio c = Ico (max a c) b := by grind @[simp] theorem Ioc_diff_Ioi : Ioc a b \ Ioi c = Ioc a (min b c) := by grind @[simp] theorem Ioc_inter_Ioi : Ioc a b ∩ Ioi c = Ioc (a ⊔ c) b := by grind @[simp] theorem Ico_inter_Iio : Ico a b ∩ Iio c = Ico a (min b c) := by grind @[simp] theorem Ioc_diff_Iic : Ioc a b \ Iic c = Ioc (max a c) b := by grind theorem compl_Ioc : (Ioc a b)ᶜ = Iic a ∪ Ioi b := by grind theorem Iic_diff_Ioc : Iic b \ Ioc a b = Iic (a ⊓ b) := by grind theorem Iic_diff_Ioc_self_of_le (hab : a ≤ b) : Iic b \ Ioc a b = Iic a := by grind @[simp] theorem Ioc_union_Ioc_right : Ioc a b ∪ Ioc a c = Ioc a (max b c) := by grind @[simp] theorem Ioc_union_Ioc_left : Ioc a c ∪ Ioc b c = Ioc (min a b) c := by grind @[simp] theorem Ioc_union_Ioc_symm : Ioc a b ∪ Ioc b a = Ioc (min a b) (max a b) := by grind @[simp] theorem Ioc_union_Ioc_union_Ioc_cycle : Ioc a b ∪ Ioc b c ∪ Ioc c a = Ioc (min a (min b c)) (max a (max b c)) := by grind end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/OrdConnectedComponent.lean
import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Data.Set.Lattice.Image /-! # Order connected components of a set In this file we define `Set.ordConnectedComponent s x` to be the set of `y` such that `Set.uIcc x y ⊆ s` and prove some basic facts about this definition. At the moment of writing, this construction is used only to prove that any linear order with order topology is a T₅ space, so we only add API needed for this lemma. -/ open Interval Function OrderDual namespace Set variable {α : Type*} [LinearOrder α] {s t : Set α} {x y z : α} /-- Order-connected component of a point `x` in a set `s`. It is defined as the set of `y` such that `Set.uIcc x y ⊆ s`. Note that it is empty if and only if `x ∉ s`. -/ def ordConnectedComponent (s : Set α) (x : α) : Set α := { y | [[x, y]] ⊆ s } theorem mem_ordConnectedComponent : y ∈ ordConnectedComponent s x ↔ [[x, y]] ⊆ s := Iff.rfl theorem dual_ordConnectedComponent : ordConnectedComponent (ofDual ⁻¹' s) (toDual x) = ofDual ⁻¹' ordConnectedComponent s x := ext <| (Surjective.forall toDual.surjective).2 fun x => by simp [mem_ordConnectedComponent] theorem ordConnectedComponent_subset : ordConnectedComponent s x ⊆ s := fun _ hy => hy right_mem_uIcc theorem subset_ordConnectedComponent {t} [h : OrdConnected s] (hs : x ∈ s) (ht : s ⊆ t) : s ⊆ ordConnectedComponent t x := fun _ hy => (h.uIcc_subset hs hy).trans ht @[simp] theorem self_mem_ordConnectedComponent : x ∈ ordConnectedComponent s x ↔ x ∈ s := by rw [mem_ordConnectedComponent, uIcc_self, singleton_subset_iff] @[simp] theorem nonempty_ordConnectedComponent : (ordConnectedComponent s x).Nonempty ↔ x ∈ s := ⟨fun ⟨_, hy⟩ => hy <| left_mem_uIcc, fun h => ⟨x, self_mem_ordConnectedComponent.2 h⟩⟩ @[simp] theorem ordConnectedComponent_eq_empty : ordConnectedComponent s x = ∅ ↔ x ∉ s := by rw [← not_nonempty_iff_eq_empty, nonempty_ordConnectedComponent] @[simp] theorem ordConnectedComponent_empty : ordConnectedComponent ∅ x = ∅ := ordConnectedComponent_eq_empty.2 (notMem_empty x) @[simp] theorem ordConnectedComponent_univ : ordConnectedComponent univ x = univ := by simp [ordConnectedComponent] theorem ordConnectedComponent_inter (s t : Set α) (x : α) : ordConnectedComponent (s ∩ t) x = ordConnectedComponent s x ∩ ordConnectedComponent t x := by simp [ordConnectedComponent, setOf_and] theorem mem_ordConnectedComponent_comm : y ∈ ordConnectedComponent s x ↔ x ∈ ordConnectedComponent s y := by rw [mem_ordConnectedComponent, mem_ordConnectedComponent, uIcc_comm] theorem mem_ordConnectedComponent_trans (hxy : y ∈ ordConnectedComponent s x) (hyz : z ∈ ordConnectedComponent s y) : z ∈ ordConnectedComponent s x := calc [[x, z]] ⊆ [[x, y]] ∪ [[y, z]] := uIcc_subset_uIcc_union_uIcc _ ⊆ s := union_subset hxy hyz theorem ordConnectedComponent_eq (h : [[x, y]] ⊆ s) : ordConnectedComponent s x = ordConnectedComponent s y := ext fun _ => ⟨mem_ordConnectedComponent_trans (mem_ordConnectedComponent_comm.2 h), mem_ordConnectedComponent_trans h⟩ instance : OrdConnected (ordConnectedComponent s x) := ordConnected_of_uIcc_subset_left fun _ hy _ hz => (uIcc_subset_uIcc_left hz).trans hy /-- Projection from `s : Set α` to `α` sending each order connected component of `s` to a single point of this component. -/ noncomputable def ordConnectedProj (s : Set α) : s → α := fun x : s => (nonempty_ordConnectedComponent.2 x.2).some theorem ordConnectedProj_mem_ordConnectedComponent (s : Set α) (x : s) : ordConnectedProj s x ∈ ordConnectedComponent s x := Nonempty.some_mem _ theorem mem_ordConnectedComponent_ordConnectedProj (s : Set α) (x : s) : ↑x ∈ ordConnectedComponent s (ordConnectedProj s x) := mem_ordConnectedComponent_comm.2 <| ordConnectedProj_mem_ordConnectedComponent s x @[simp] theorem ordConnectedComponent_ordConnectedProj (s : Set α) (x : s) : ordConnectedComponent s (ordConnectedProj s x) = ordConnectedComponent s x := ordConnectedComponent_eq <| mem_ordConnectedComponent_ordConnectedProj _ _ @[simp] theorem ordConnectedProj_eq {x y : s} : ordConnectedProj s x = ordConnectedProj s y ↔ [[(x : α), y]] ⊆ s := by constructor <;> intro h · rw [← mem_ordConnectedComponent, ← ordConnectedComponent_ordConnectedProj, h, ordConnectedComponent_ordConnectedProj, self_mem_ordConnectedComponent] exact y.2 · simp only [ordConnectedProj, ordConnectedComponent_eq h] /-- A set that intersects each order connected component of a set by a single point. Defined as the range of `Set.ordConnectedProj s`. -/ def ordConnectedSection (s : Set α) : Set α := range <| ordConnectedProj s theorem dual_ordConnectedSection (s : Set α) : ordConnectedSection (ofDual ⁻¹' s) = ofDual ⁻¹' ordConnectedSection s := by simp only [ordConnectedSection] simp +unfoldPartialApp only [ordConnectedProj] ext x simp only [mem_range, Subtype.exists, mem_preimage, OrderDual.exists, dual_ordConnectedComponent, ofDual_toDual] tauto theorem ordConnectedSection_subset : ordConnectedSection s ⊆ s := range_subset_iff.2 fun _ => ordConnectedComponent_subset <| Nonempty.some_mem _ theorem eq_of_mem_ordConnectedSection_of_uIcc_subset (hx : x ∈ ordConnectedSection s) (hy : y ∈ ordConnectedSection s) (h : [[x, y]] ⊆ s) : x = y := by rcases hx with ⟨x, rfl⟩; rcases hy with ⟨y, rfl⟩ exact ordConnectedProj_eq.2 (mem_ordConnectedComponent_trans (mem_ordConnectedComponent_trans (ordConnectedProj_mem_ordConnectedComponent _ _) h) (mem_ordConnectedComponent_ordConnectedProj _ _)) /-- Given two sets `s t : Set α`, the set `Set.orderSeparatingSet s t` is the set of points that belong both to some `Set.ordConnectedComponent tᶜ x`, `x ∈ s`, and to some `Set.ordConnectedComponent sᶜ x`, `x ∈ t`. In the case of two disjoint closed sets, this is the union of all open intervals $(a, b)$ such that their endpoints belong to different sets. -/ def ordSeparatingSet (s t : Set α) : Set α := (⋃ x ∈ s, ordConnectedComponent tᶜ x) ∩ ⋃ x ∈ t, ordConnectedComponent sᶜ x theorem ordSeparatingSet_comm (s t : Set α) : ordSeparatingSet s t = ordSeparatingSet t s := inter_comm _ _ theorem disjoint_left_ordSeparatingSet : Disjoint s (ordSeparatingSet s t) := Disjoint.inter_right' _ <| disjoint_iUnion₂_right.2 fun _ _ => disjoint_compl_right.mono_right <| ordConnectedComponent_subset theorem disjoint_right_ordSeparatingSet : Disjoint t (ordSeparatingSet s t) := ordSeparatingSet_comm t s ▸ disjoint_left_ordSeparatingSet theorem dual_ordSeparatingSet : ordSeparatingSet (ofDual ⁻¹' s) (ofDual ⁻¹' t) = ofDual ⁻¹' ordSeparatingSet s t := by simp only [ordSeparatingSet, mem_preimage, ← toDual.surjective.iUnion_comp, ofDual_toDual, dual_ordConnectedComponent, ← preimage_compl, preimage_inter, preimage_iUnion] /-- An auxiliary neighborhood that will be used in the proof of `OrderTopology.CompletelyNormalSpace`. -/ def ordT5Nhd (s t : Set α) : Set α := ⋃ x ∈ s, ordConnectedComponent (tᶜ ∩ (ordConnectedSection <| ordSeparatingSet s t)ᶜ) x theorem disjoint_ordT5Nhd : Disjoint (ordT5Nhd s t) (ordT5Nhd t s) := by rw [disjoint_iff_inf_le] rintro x ⟨hx₁, hx₂⟩ rcases mem_iUnion₂.1 hx₁ with ⟨a, has, ha⟩ clear hx₁ rcases mem_iUnion₂.1 hx₂ with ⟨b, hbt, hb⟩ clear hx₂ rw [mem_ordConnectedComponent, subset_inter_iff] at ha hb wlog hab : a ≤ b with H · exact H b hbt hb a has ha (le_of_not_ge hab) obtain ⟨ha, ha'⟩ := ha obtain ⟨hb, hb'⟩ := hb have hsub : [[a, b]] ⊆ (ordSeparatingSet s t).ordConnectedSectionᶜ := by rw [ordSeparatingSet_comm, uIcc_comm] at hb' calc [[a, b]] ⊆ [[a, x]] ∪ [[x, b]] := uIcc_subset_uIcc_union_uIcc _ ⊆ (ordSeparatingSet s t).ordConnectedSectionᶜ := union_subset ha' hb' clear ha' hb' rcases le_total x a with hxa | hax · exact hb (Icc_subset_uIcc' ⟨hxa, hab⟩) has rcases le_total b x with hbx | hxb · exact ha (Icc_subset_uIcc ⟨hab, hbx⟩) hbt have h' : x ∈ ordSeparatingSet s t := ⟨mem_iUnion₂.2 ⟨a, has, ha⟩, mem_iUnion₂.2 ⟨b, hbt, hb⟩⟩ lift x to ordSeparatingSet s t using h' suffices ordConnectedComponent (ordSeparatingSet s t) x ⊆ [[a, b]] from hsub (this <| ordConnectedProj_mem_ordConnectedComponent _ x) (mem_range_self _) rintro y hy rw [uIcc_of_le hab, mem_Icc, ← not_lt, ← not_lt] have sol1 := fun (hya : y < a) => (disjoint_left (t := ordSeparatingSet s t)).1 disjoint_left_ordSeparatingSet has (hy <| Icc_subset_uIcc' ⟨hya.le, hax⟩) have sol2 := fun (hby : b < y) => (disjoint_left (t := ordSeparatingSet s t)).1 disjoint_right_ordSeparatingSet hbt (hy <| Icc_subset_uIcc ⟨hxb, hby.le⟩) exact ⟨sol1, sol2⟩ end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/OrdConnected.lean
import Mathlib.Order.Interval.Set.OrderEmbedding import Mathlib.Order.Antichain import Mathlib.Order.SetNotation /-! # Order-connected sets We say that a set `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. If `α` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `α` is a `LinearOrderedField`, then this condition is also equivalent to `Convex α s`. In this file we prove that intersection of a family of `OrdConnected` sets is `OrdConnected` and that all standard intervals are `OrdConnected`. -/ open scoped Interval open Set open OrderDual (toDual ofDual) namespace Set section Preorder variable {α β : Type*} [Preorder α] [Preorder β] {s : Set α} theorem OrdConnected.out (h : OrdConnected s) : ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y ⊆ s := h.1 theorem ordConnected_def : OrdConnected s ↔ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y ⊆ s := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- It suffices to prove `[[x, y]] ⊆ s` for `x y ∈ s`, `x ≤ y`. -/ theorem ordConnected_iff : OrdConnected s ↔ ∀ x ∈ s, ∀ y ∈ s, x ≤ y → Icc x y ⊆ s := ordConnected_def.trans ⟨fun hs _ hx _ hy _ => hs hx hy, fun H x hx y hy _ hz => H x hx y hy (le_trans hz.1 hz.2) hz⟩ theorem ordConnected_of_Ioo {α : Type*} [PartialOrder α] {s : Set α} (hs : ∀ x ∈ s, ∀ y ∈ s, x < y → Ioo x y ⊆ s) : OrdConnected s := by rw [ordConnected_iff] intro x hx y hy hxy rcases eq_or_lt_of_le hxy with (rfl | hxy'); · simpa rw [← Ioc_insert_left hxy, ← Ioo_insert_right hxy'] exact insert_subset_iff.2 ⟨hx, insert_subset_iff.2 ⟨hy, hs x hx y hy hxy'⟩⟩ theorem OrdConnected.preimage_mono {f : β → α} (hs : OrdConnected s) (hf : Monotone f) : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨hf hz.1, hf hz.2⟩⟩ theorem OrdConnected.preimage_anti {f : β → α} (hs : OrdConnected s) (hf : Antitone f) : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hf hz.2, hf hz.1⟩⟩ protected theorem Icc_subset (s : Set α) [hs : OrdConnected s] {x y} (hx : x ∈ s) (hy : y ∈ s) : Icc x y ⊆ s := hs.out hx hy end Preorder end Set namespace OrderEmbedding variable {α β : Type*} [Preorder α] [Preorder β] theorem image_Icc (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Icc x y = Icc (e x) (e y) := by rw [← e.preimage_Icc, image_preimage_eq_inter_range, inter_eq_left.2 (he.out ⟨_, rfl⟩ ⟨_, rfl⟩)] theorem image_Ico (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Ico x y = Ico (e x) (e y) := by rw [← e.preimage_Ico, image_preimage_eq_inter_range, inter_eq_left.2 <| Ico_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] theorem image_Ioc (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Ioc x y = Ioc (e x) (e y) := by rw [← e.preimage_Ioc, image_preimage_eq_inter_range, inter_eq_left.2 <| Ioc_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] theorem image_Ioo (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Ioo x y = Ioo (e x) (e y) := by rw [← e.preimage_Ioo, image_preimage_eq_inter_range, inter_eq_left.2 <| Ioo_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] end OrderEmbedding namespace Set section Preorder variable {α β : Type*} [Preorder α] [Preorder β] @[simp] lemma image_subtype_val_Icc {s : Set α} [OrdConnected s] (x y : s) : Subtype.val '' Icc x y = Icc x.1 y := (OrderEmbedding.subtype (· ∈ s)).image_Icc (by simpa) x y @[simp] lemma image_subtype_val_Ico {s : Set α} [OrdConnected s] (x y : s) : Subtype.val '' Ico x y = Ico x.1 y := (OrderEmbedding.subtype (· ∈ s)).image_Ico (by simpa) x y @[simp] lemma image_subtype_val_Ioc {s : Set α} [OrdConnected s] (x y : s) : Subtype.val '' Ioc x y = Ioc x.1 y := (OrderEmbedding.subtype (· ∈ s)).image_Ioc (by simpa) x y @[simp] lemma image_subtype_val_Ioo {s : Set α} [OrdConnected s] (x y : s) : Subtype.val '' Ioo x y = Ioo x.1 y := (OrderEmbedding.subtype (· ∈ s)).image_Ioo (by simpa) x y theorem OrdConnected.inter {s t : Set α} (hs : OrdConnected s) (ht : OrdConnected t) : OrdConnected (s ∩ t) := ⟨fun _ hx _ hy => subset_inter (hs.out hx.1 hy.1) (ht.out hx.2 hy.2)⟩ instance OrdConnected.inter' {s t : Set α} [OrdConnected s] [OrdConnected t] : OrdConnected (s ∩ t) := OrdConnected.inter ‹_› ‹_› theorem OrdConnected.dual {s : Set α} (hs : OrdConnected s) : OrdConnected (OrderDual.ofDual ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hz.2, hz.1⟩⟩ @[instance] theorem dual_ordConnected {s : Set α} [OrdConnected s] : OrdConnected (ofDual ⁻¹' s) := .dual ‹OrdConnected s› @[simp] theorem ordConnected_dual {s : Set α} : OrdConnected (OrderDual.ofDual ⁻¹' s) ↔ OrdConnected s := ⟨fun h => by simpa only [ordConnected_def] using h.dual, fun h => h.dual⟩ @[deprecated (since := "2025-10-28")] alias dual_ordConnected_iff := ordConnected_dual theorem ordConnected_sInter {S : Set (Set α)} (hS : ∀ s ∈ S, OrdConnected s) : OrdConnected (⋂₀ S) := ⟨fun _x hx _y hy _z hz s hs => (hS s hs).out (hx s hs) (hy s hs) hz⟩ theorem ordConnected_iInter {ι : Sort*} {s : ι → Set α} (hs : ∀ i, OrdConnected (s i)) : OrdConnected (⋂ i, s i) := ordConnected_sInter <| forall_mem_range.2 hs instance ordConnected_iInter' {ι : Sort*} {s : ι → Set α} [∀ i, OrdConnected (s i)] : OrdConnected (⋂ i, s i) := ordConnected_iInter ‹_› theorem ordConnected_biInter {ι : Sort*} {p : ι → Prop} {s : ∀ i, p i → Set α} (hs : ∀ i hi, OrdConnected (s i hi)) : OrdConnected (⋂ (i) (hi), s i hi) := ordConnected_iInter fun i => ordConnected_iInter <| hs i theorem ordConnected_pi {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] {s : Set ι} {t : ∀ i, Set (α i)} (h : ∀ i ∈ s, OrdConnected (t i)) : OrdConnected (s.pi t) := ⟨fun _ hx _ hy _ hz i hi => (h i hi).out (hx i hi) (hy i hi) ⟨hz.1 i, hz.2 i⟩⟩ instance ordConnected_pi' {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] {s : Set ι} {t : ∀ i, Set (α i)} [h : ∀ i, OrdConnected (t i)] : OrdConnected (s.pi t) := ordConnected_pi fun i _ => h i @[instance] theorem ordConnected_Ici {a : α} : OrdConnected (Ici a) := ⟨fun _ hx _ _ _ hz => le_trans hx hz.1⟩ @[instance] theorem ordConnected_Iic {a : α} : OrdConnected (Iic a) := ⟨fun _ _ _ hy _ hz => le_trans hz.2 hy⟩ @[instance] theorem ordConnected_Ioi {a : α} : OrdConnected (Ioi a) := ⟨fun _ hx _ _ _ hz => lt_of_lt_of_le hx hz.1⟩ @[instance] theorem ordConnected_Iio {a : α} : OrdConnected (Iio a) := ⟨fun _ _ _ hy _ hz => lt_of_le_of_lt hz.2 hy⟩ @[instance] theorem ordConnected_Icc {a b : α} : OrdConnected (Icc a b) := ordConnected_Ici.inter ordConnected_Iic @[instance] theorem ordConnected_Ico {a b : α} : OrdConnected (Ico a b) := ordConnected_Ici.inter ordConnected_Iio @[instance] theorem ordConnected_Ioc {a b : α} : OrdConnected (Ioc a b) := ordConnected_Ioi.inter ordConnected_Iic @[instance] theorem ordConnected_Ioo {a b : α} : OrdConnected (Ioo a b) := ordConnected_Ioi.inter ordConnected_Iio @[instance] theorem ordConnected_singleton {α : Type*} [PartialOrder α] {a : α} : OrdConnected ({a} : Set α) := by rw [← Icc_self] exact ordConnected_Icc @[instance] theorem ordConnected_empty : OrdConnected (∅ : Set α) := ⟨fun _ => False.elim⟩ @[instance] theorem ordConnected_univ : OrdConnected (univ : Set α) := ⟨fun _ _ _ _ => subset_univ _⟩ /-- In a dense order `α`, the subtype from an `OrdConnected` set is also densely ordered. -/ instance instDenselyOrdered [DenselyOrdered α] {s : Set α} [hs : OrdConnected s] : DenselyOrdered s := ⟨fun a b (h : (a : α) < b) => let ⟨x, H⟩ := exists_between h ⟨⟨x, (hs.out a.2 b.2) (Ioo_subset_Icc_self H)⟩, H⟩⟩ @[instance] theorem ordConnected_preimage {F : Type*} [FunLike F α β] [OrderHomClass F α β] (f : F) {s : Set β} [hs : OrdConnected s] : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨OrderHomClass.mono _ hz.1, OrderHomClass.mono _ hz.2⟩⟩ @[instance] theorem ordConnected_image {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) {s : Set α} [hs : OrdConnected s] : OrdConnected (e '' s) := by erw [(e : α ≃o β).image_eq_preimage_symm] apply ordConnected_preimage (e : α ≃o β).symm @[instance] theorem ordConnected_range {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) : OrdConnected (range e) := by simp_rw [← image_univ] exact ordConnected_image (e : α ≃o β) /-- The preimage of an `OrdConnected` set under a map which is monotone on a set `t`, when intersected with `t`, is `OrdConnected`. More precisely, it is the intersection with `t` of an `OrdConnected` set. -/ theorem OrdConnected.preimage_monotoneOn {f : β → α} {t : Set β} {s : Set α} (hs : OrdConnected s) (hf : MonotoneOn f t) : ∃ u, OrdConnected u ∧ t ∩ f ⁻¹' s = t ∩ u := by let u := {x | (∃ y ∈ t, y ≤ x ∧ f y ∈ s) ∧ (∃ z ∈ t, x ≤ z ∧ f z ∈ s)} refine ⟨u, ⟨?_⟩, Subset.antisymm ?_ ?_⟩ · rintro x ⟨⟨y, yt, yx, ys⟩, -⟩ x' ⟨-, ⟨z, zt, x'z, zs⟩⟩ a ha exact ⟨⟨y, yt, yx.trans ha.1, ys⟩, ⟨z, zt, ha.2.trans x'z, zs⟩⟩ · rintro x ⟨xt, xs⟩ exact ⟨xt, ⟨x, xt, le_rfl, xs⟩, ⟨x, xt, le_rfl, xs⟩⟩ · rintro x ⟨xt, ⟨y, yt, yx, ys⟩, ⟨z, zt, xz, zs⟩⟩ refine ⟨xt, ?_⟩ apply hs.out ys zs exact ⟨hf yt xt yx, hf xt zt xz⟩ /-- The preimage of an `OrdConnected` set under a map which is antitone on a set `t`, when intersected with `t`, is `OrdConnected`. More precisely, it is the intersection with `t` of an `OrdConnected` set. -/ theorem OrdConnected.preimage_antitoneOn {f : β → α} {t : Set β} {s : Set α} (hs : OrdConnected s) (hf : AntitoneOn f t) : ∃ u, OrdConnected u ∧ t ∩ f ⁻¹' s = t ∩ u := (OrdConnected.preimage_monotoneOn hs.dual hf.dual_right :) end Preorder section PartialOrder variable {α : Type*} [PartialOrder α] {s : Set α} {x y : α} protected theorem _root_.IsAntichain.ordConnected (hs : IsAntichain (· ≤ ·) s) : s.OrdConnected := ⟨fun x hx y hy z hz => by obtain rfl := hs.eq hx hy (hz.1.trans hz.2) rw [Icc_self, mem_singleton_iff] at hz rwa [hz]⟩ lemma ordConnected_inter_Icc_of_subset (h : Ioo x y ⊆ s) : OrdConnected (s ∩ Icc x y) := ordConnected_of_Ioo fun _u ⟨_, hu, _⟩ _v ⟨_, _, hv⟩ _ ↦ Ioo_subset_Ioo hu hv |>.trans <| subset_inter h Ioo_subset_Icc_self lemma ordConnected_inter_Icc_iff (hx : x ∈ s) (hy : y ∈ s) : OrdConnected (s ∩ Icc x y) ↔ Ioo x y ⊆ s := by refine ⟨fun h ↦ Ioo_subset_Icc_self.trans fun z hz ↦ ?_, ordConnected_inter_Icc_of_subset⟩ have hxy : x ≤ y := hz.1.trans hz.2 exact h.out ⟨hx, left_mem_Icc.2 hxy⟩ ⟨hy, right_mem_Icc.2 hxy⟩ hz |>.1 lemma not_ordConnected_inter_Icc_iff (hx : x ∈ s) (hy : y ∈ s) : ¬ OrdConnected (s ∩ Icc x y) ↔ ∃ z ∉ s, z ∈ Ioo x y := by simp_rw [ordConnected_inter_Icc_iff hx hy, subset_def, not_forall, exists_prop, and_comm] end PartialOrder section LinearOrder open scoped Interval variable {α : Type*} [LinearOrder α] {s : Set α} {x : α} @[instance] theorem ordConnected_uIcc {a b : α} : OrdConnected [[a, b]] := ordConnected_Icc @[instance] theorem ordConnected_uIoc {a b : α} : OrdConnected (Ι a b) := ordConnected_Ioc theorem OrdConnected.uIcc_subset (hs : OrdConnected s) ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) : [[x, y]] ⊆ s := hs.out (min_rec' (· ∈ s) hx hy) (max_rec' (· ∈ s) hx hy) theorem OrdConnected.uIoc_subset (hs : OrdConnected s) ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) : Ι x y ⊆ s := Ioc_subset_Icc_self.trans <| hs.uIcc_subset hx hy theorem ordConnected_iff_uIcc_subset : OrdConnected s ↔ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), [[x, y]] ⊆ s := ⟨fun h => h.uIcc_subset, fun H => ⟨fun _ hx _ hy => Icc_subset_uIcc.trans <| H hx hy⟩⟩ theorem ordConnected_of_uIcc_subset_left (h : ∀ y ∈ s, [[x, y]] ⊆ s) : OrdConnected s := ordConnected_iff_uIcc_subset.2 fun y hy z hz => calc [[y, z]] ⊆ [[y, x]] ∪ [[x, z]] := uIcc_subset_uIcc_union_uIcc _ = [[x, y]] ∪ [[x, z]] := by rw [uIcc_comm] _ ⊆ s := union_subset (h y hy) (h z hz) theorem ordConnected_iff_uIcc_subset_left (hx : x ∈ s) : OrdConnected s ↔ ∀ ⦃y⦄, y ∈ s → [[x, y]] ⊆ s := ⟨fun hs => hs.uIcc_subset hx, ordConnected_of_uIcc_subset_left⟩ theorem ordConnected_iff_uIcc_subset_right (hx : x ∈ s) : OrdConnected s ↔ ∀ ⦃y⦄, y ∈ s → [[y, x]] ⊆ s := by simp_rw [ordConnected_iff_uIcc_subset_left hx, uIcc_comm] end LinearOrder end Set
.lake/packages/mathlib/Mathlib/Order/Interval/Set/OrderEmbedding.lean
import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Order.Hom.Basic /-! # Preimages of intervals under order embeddings In this file we prove that the preimage of an interval in the codomain under an `OrderEmbedding` is an interval in the domain. Note that similar statements about images require the range to be order-connected. -/ open Set namespace OrderEmbedding variable {α β : Type*} section Preorder variable [Preorder α] [Preorder β] (e : α ↪o β) (x y : α) @[simp] theorem preimage_Ici : e ⁻¹' Ici (e x) = Ici x := ext fun _ ↦ e.le_iff_le @[simp] theorem preimage_Iic : e ⁻¹' Iic (e x) = Iic x := ext fun _ ↦ e.le_iff_le @[simp] theorem preimage_Ioi : e ⁻¹' Ioi (e x) = Ioi x := ext fun _ ↦ e.lt_iff_lt @[simp] theorem preimage_Iio : e ⁻¹' Iio (e x) = Iio x := ext fun _ ↦ e.lt_iff_lt @[simp] theorem preimage_Icc : e ⁻¹' Icc (e x) (e y) = Icc x y := by ext; simp @[simp] theorem preimage_Ico : e ⁻¹' Ico (e x) (e y) = Ico x y := by ext; simp @[simp] theorem preimage_Ioc : e ⁻¹' Ioc (e x) (e y) = Ioc x y := by ext; simp @[simp] theorem preimage_Ioo : e ⁻¹' Ioo (e x) (e y) = Ioo x y := by ext; simp end Preorder variable [LinearOrder α] @[simp] theorem preimage_uIcc [Lattice β] (e : α ↪o β) (x y : α) : e ⁻¹' (uIcc (e x) (e y)) = uIcc x y := by cases le_total x y <;> simp [*] @[simp] theorem preimage_uIoc [LinearOrder β] (e : α ↪o β) (x y : α) : e ⁻¹' (uIoc (e x) (e y)) = uIoc x y := by cases le_total x y <;> simp [*] end OrderEmbedding
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Monotone.lean
import Mathlib.Data.Set.Monotone import Mathlib.Order.Interval.Set.Disjoint import Mathlib.Order.SuccPred.Archimedean /-! # Monotonicity on intervals In this file we prove that `Set.Ici` etc. are monotone/antitone functions. We also prove some lemmas about functions monotone on intervals in `SuccOrder`s. -/ open Set section Ixx variable {α β : Type*} [Preorder α] [Preorder β] {f g : α → β} {s : Set α} theorem antitone_Ici : Antitone (Ici : α → Set α) := fun _ _ => Ici_subset_Ici.2 theorem monotone_Iic : Monotone (Iic : α → Set α) := fun _ _ => Iic_subset_Iic.2 theorem antitone_Ioi : Antitone (Ioi : α → Set α) := fun _ _ => Ioi_subset_Ioi theorem monotone_Iio : Monotone (Iio : α → Set α) := fun _ _ => Iio_subset_Iio protected theorem Monotone.Ici (hf : Monotone f) : Antitone fun x => Ici (f x) := antitone_Ici.comp_monotone hf protected theorem MonotoneOn.Ici (hf : MonotoneOn f s) : AntitoneOn (fun x => Ici (f x)) s := antitone_Ici.comp_monotoneOn hf protected theorem Antitone.Ici (hf : Antitone f) : Monotone fun x => Ici (f x) := antitone_Ici.comp hf protected theorem AntitoneOn.Ici (hf : AntitoneOn f s) : MonotoneOn (fun x => Ici (f x)) s := antitone_Ici.comp_antitoneOn hf protected theorem Monotone.Iic (hf : Monotone f) : Monotone fun x => Iic (f x) := monotone_Iic.comp hf protected theorem MonotoneOn.Iic (hf : MonotoneOn f s) : MonotoneOn (fun x => Iic (f x)) s := monotone_Iic.comp_monotoneOn hf protected theorem Antitone.Iic (hf : Antitone f) : Antitone fun x => Iic (f x) := monotone_Iic.comp_antitone hf protected theorem AntitoneOn.Iic (hf : AntitoneOn f s) : AntitoneOn (fun x => Iic (f x)) s := monotone_Iic.comp_antitoneOn hf protected theorem Monotone.Ioi (hf : Monotone f) : Antitone fun x => Ioi (f x) := antitone_Ioi.comp_monotone hf protected theorem MonotoneOn.Ioi (hf : MonotoneOn f s) : AntitoneOn (fun x => Ioi (f x)) s := antitone_Ioi.comp_monotoneOn hf protected theorem Antitone.Ioi (hf : Antitone f) : Monotone fun x => Ioi (f x) := antitone_Ioi.comp hf protected theorem AntitoneOn.Ioi (hf : AntitoneOn f s) : MonotoneOn (fun x => Ioi (f x)) s := antitone_Ioi.comp_antitoneOn hf protected theorem Monotone.Iio (hf : Monotone f) : Monotone fun x => Iio (f x) := monotone_Iio.comp hf protected theorem MonotoneOn.Iio (hf : MonotoneOn f s) : MonotoneOn (fun x => Iio (f x)) s := monotone_Iio.comp_monotoneOn hf protected theorem Antitone.Iio (hf : Antitone f) : Antitone fun x => Iio (f x) := monotone_Iio.comp_antitone hf protected theorem AntitoneOn.Iio (hf : AntitoneOn f s) : AntitoneOn (fun x => Iio (f x)) s := monotone_Iio.comp_antitoneOn hf protected theorem Monotone.Icc (hf : Monotone f) (hg : Antitone g) : Antitone fun x => Icc (f x) (g x) := hf.Ici.inter hg.Iic protected theorem MonotoneOn.Icc (hf : MonotoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => Icc (f x) (g x)) s := hf.Ici.inter hg.Iic protected theorem Antitone.Icc (hf : Antitone f) (hg : Monotone g) : Monotone fun x => Icc (f x) (g x) := hf.Ici.inter hg.Iic protected theorem AntitoneOn.Icc (hf : AntitoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => Icc (f x) (g x)) s := hf.Ici.inter hg.Iic protected theorem Monotone.Ico (hf : Monotone f) (hg : Antitone g) : Antitone fun x => Ico (f x) (g x) := hf.Ici.inter hg.Iio protected theorem MonotoneOn.Ico (hf : MonotoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => Ico (f x) (g x)) s := hf.Ici.inter hg.Iio protected theorem Antitone.Ico (hf : Antitone f) (hg : Monotone g) : Monotone fun x => Ico (f x) (g x) := hf.Ici.inter hg.Iio protected theorem AntitoneOn.Ico (hf : AntitoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => Ico (f x) (g x)) s := hf.Ici.inter hg.Iio protected theorem Monotone.Ioc (hf : Monotone f) (hg : Antitone g) : Antitone fun x => Ioc (f x) (g x) := hf.Ioi.inter hg.Iic protected theorem MonotoneOn.Ioc (hf : MonotoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => Ioc (f x) (g x)) s := hf.Ioi.inter hg.Iic protected theorem Antitone.Ioc (hf : Antitone f) (hg : Monotone g) : Monotone fun x => Ioc (f x) (g x) := hf.Ioi.inter hg.Iic protected theorem AntitoneOn.Ioc (hf : AntitoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => Ioc (f x) (g x)) s := hf.Ioi.inter hg.Iic protected theorem Monotone.Ioo (hf : Monotone f) (hg : Antitone g) : Antitone fun x => Ioo (f x) (g x) := hf.Ioi.inter hg.Iio protected theorem MonotoneOn.Ioo (hf : MonotoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => Ioo (f x) (g x)) s := hf.Ioi.inter hg.Iio protected theorem Antitone.Ioo (hf : Antitone f) (hg : Monotone g) : Monotone fun x => Ioo (f x) (g x) := hf.Ioi.inter hg.Iio protected theorem AntitoneOn.Ioo (hf : AntitoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => Ioo (f x) (g x)) s := hf.Ioi.inter hg.Iio end Ixx section iUnion variable {α β : Type*} [SemilatticeSup α] [LinearOrder β] {f g : α → β} {a b : β} theorem iUnion_Ioo_of_mono_of_isGLB_of_isLUB (hf : Antitone f) (hg : Monotone g) (ha : IsGLB (range f) a) (hb : IsLUB (range g) b) : ⋃ x, Ioo (f x) (g x) = Ioo a b := calc ⋃ x, Ioo (f x) (g x) = (⋃ x, Ioi (f x)) ∩ ⋃ x, Iio (g x) := iUnion_inter_of_monotone hf.Ioi hg.Iio _ = Ioi a ∩ Iio b := congr_arg₂ (· ∩ ·) ha.iUnion_Ioi_eq hb.iUnion_Iio_eq end iUnion section SuccOrder open Order variable {α β : Type*} [PartialOrder α] [Preorder β] {ψ : α → β} /-- A function `ψ` on a `SuccOrder` is strictly monotone before some `n` if for all `m` such that `m < n`, we have `ψ m < ψ (succ m)`. -/ theorem strictMonoOn_Iic_of_lt_succ [SuccOrder α] [IsSuccArchimedean α] {n : α} (hψ : ∀ m, m < n → ψ m < ψ (succ m)) : StrictMonoOn ψ (Set.Iic n) := strictMonoOn_of_lt_succ ordConnected_Iic fun _a ha' _ ha ↦ hψ _ <| (succ_le_iff_of_not_isMax ha').1 ha theorem strictAntiOn_Iic_of_succ_lt [SuccOrder α] [IsSuccArchimedean α] {n : α} (hψ : ∀ m, m < n → ψ (succ m) < ψ m) : StrictAntiOn ψ (Set.Iic n) := fun i hi j hj hij => @strictMonoOn_Iic_of_lt_succ α βᵒᵈ _ _ ψ _ _ n hψ i hi j hj hij theorem strictMonoOn_Ici_of_pred_lt [PredOrder α] [IsPredArchimedean α] {n : α} (hψ : ∀ m, n < m → ψ (pred m) < ψ m) : StrictMonoOn ψ (Set.Ici n) := fun i hi j hj hij => @strictMonoOn_Iic_of_lt_succ αᵒᵈ βᵒᵈ _ _ ψ _ _ n hψ j hj i hi hij theorem strictAntiOn_Ici_of_lt_pred [PredOrder α] [IsPredArchimedean α] {n : α} (hψ : ∀ m, n < m → ψ m < ψ (pred m)) : StrictAntiOn ψ (Set.Ici n) := fun i hi j hj hij => @strictAntiOn_Iic_of_succ_lt αᵒᵈ βᵒᵈ _ _ ψ _ _ n hψ j hj i hi hij end SuccOrder section LinearOrder open Order variable {α : Type*} [LinearOrder α] theorem StrictMonoOn.Iic_id_le [SuccOrder α] [IsSuccArchimedean α] [OrderBot α] {n : α} {φ : α → α} (hφ : StrictMonoOn φ (Set.Iic n)) : ∀ m ≤ n, m ≤ φ m := by revert hφ refine Succ.rec_bot (fun n => StrictMonoOn φ (Set.Iic n) → ∀ m ≤ n, m ≤ φ m) (fun _ _ hm => hm.trans bot_le) ?_ _ rintro k ih hφ m hm by_cases hk : IsMax k · rw [succ_eq_iff_isMax.2 hk] at hm exact ih (hφ.mono <| Iic_subset_Iic.2 (le_succ _)) _ hm obtain rfl | h := le_succ_iff_eq_or_le.1 hm · specialize ih (StrictMonoOn.mono hφ fun x hx => le_trans hx (le_succ _)) k le_rfl nth_grw 1 [ih] refine succ_le_of_lt (hφ (le_succ _) le_rfl ?_) exact lt_succ_of_not_isMax hk · exact ih (StrictMonoOn.mono hφ fun x hx => le_trans hx (le_succ _)) _ h theorem StrictMonoOn.Ici_le_id [PredOrder α] [IsPredArchimedean α] [OrderTop α] {n : α} {φ : α → α} (hφ : StrictMonoOn φ (Set.Ici n)) : ∀ m, n ≤ m → φ m ≤ m := StrictMonoOn.Iic_id_le (α := αᵒᵈ) fun _ hi _ hj hij => hφ hj hi hij end LinearOrder
.lake/packages/mathlib/Mathlib/Order/Interval/Set/Infinite.lean
import Mathlib.Data.Set.Finite.Basic import Mathlib.Order.Interval.Set.Basic /-! # Infinitude of intervals Bounded intervals in dense orders are infinite, as are unbounded intervals in orders that are unbounded on the appropriate side. We also prove that an unbounded preorder is an infinite type. -/ variable {α : Type*} [Preorder α] /-- A nonempty preorder with no maximal element is infinite. -/ instance NoMaxOrder.infinite [Nonempty α] [NoMaxOrder α] : Infinite α := let ⟨f, hf⟩ := Nat.exists_strictMono α Infinite.of_injective f hf.injective /-- A nonempty preorder with no minimal element is infinite. -/ instance NoMinOrder.infinite [Nonempty α] [NoMinOrder α] : Infinite α := @NoMaxOrder.infinite αᵒᵈ _ _ _ namespace Set section DenselyOrdered variable [DenselyOrdered α] {a b : α} (h : a < b) include h theorem Ioo.infinite : Infinite (Ioo a b) := @NoMaxOrder.infinite _ _ (nonempty_Ioo_subtype h) _ theorem Ioo_infinite : (Ioo a b).Infinite := infinite_coe_iff.1 <| Ioo.infinite h theorem Ico_infinite : (Ico a b).Infinite := (Ioo_infinite h).mono Ioo_subset_Ico_self theorem Ico.infinite : Infinite (Ico a b) := infinite_coe_iff.2 <| Ico_infinite h theorem Ioc_infinite : (Ioc a b).Infinite := (Ioo_infinite h).mono Ioo_subset_Ioc_self theorem Ioc.infinite : Infinite (Ioc a b) := infinite_coe_iff.2 <| Ioc_infinite h theorem Icc_infinite : (Icc a b).Infinite := (Ioo_infinite h).mono Ioo_subset_Icc_self theorem Icc.infinite : Infinite (Icc a b) := infinite_coe_iff.2 <| Icc_infinite h end DenselyOrdered instance [NoMinOrder α] {a : α} : Infinite (Iio a) := NoMinOrder.infinite theorem Iio_infinite [NoMinOrder α] (a : α) : (Iio a).Infinite := infinite_coe_iff.1 inferInstance instance [NoMinOrder α] {a : α} : Infinite (Iic a) := NoMinOrder.infinite theorem Iic_infinite [NoMinOrder α] (a : α) : (Iic a).Infinite := infinite_coe_iff.1 inferInstance instance [NoMaxOrder α] {a : α} : Infinite (Ioi a) := NoMaxOrder.infinite theorem Ioi_infinite [NoMaxOrder α] (a : α) : (Ioi a).Infinite := infinite_coe_iff.1 inferInstance instance [NoMaxOrder α] {a : α} : Infinite (Ici a) := NoMaxOrder.infinite theorem Ici_infinite [NoMaxOrder α] (a : α) : (Ici a).Infinite := infinite_coe_iff.1 inferInstance end Set
.lake/packages/mathlib/Mathlib/Order/Lattice/Congruence.lean
import Mathlib.Data.Setoid.Basic import Mathlib.Order.Lattice import Mathlib.Order.Hom.Lattice /-! # Lattice Congruences ## Main definitions - `LatticeCon`: An equivalence relation is a congruence relation for the lattice structure if it is compatible with the `inf` and `sup` operations. - `LatticeCon.ker`: The kernel of a lattice homomorphism as a lattice congruence. ## Main statements - `LatticeCon.mk'`: Alternative conditions for a relation to be a lattice congruence. ## References * [Grätzer et al, *General lattice theory*][Graetzer2003] ## Tags Lattice, Congruence -/ variable {F α β : Type*} [Lattice α] [Lattice β] variable (α) in /-- An equivalence relation is a congruence relation for the latice structure if it is compatible with the `inf` and `sup` operations. -/ structure LatticeCon extends Setoid α where inf : ∀ {w x y z}, r w x → r y z → r (w ⊓ y) (x ⊓ z) sup : ∀ {w x y z}, r w x → r y z → r (w ⊔ y) (x ⊔ z) namespace LatticeCon @[simp] lemma r_inf_sup_iff (c : LatticeCon α) {x y : α} : c.r (x ⊓ y) (x ⊔ y) ↔ c.r x y where mp h := c.trans (by simpa using c.inf (c.refl x) (c.symm h)) (by simpa using c.inf h (c.refl y)) mpr h := c.trans (by simpa using c.inf h (c.refl y)) (by simpa using c.sup (c.symm h) (c.refl y)) private lemma closed_interval {r : α → α → Prop} (h₂ : ∀ ⦃x y : α⦄, r x y ↔ r (x ⊓ y) (x ⊔ y)) (h₄ : ∀ ⦃x y t : α⦄, x ≤ y → r x y → r (x ⊓ t) (y ⊓ t) ∧ r (x ⊔ t) (y ⊔ t)) (a b c d : α) (hab : a ≤ b) (hbd : b ≤ d) (hac : a ≤ c) (hcd : c ≤ d) (had : r a d) : r b c := by suffices r (b ⊓ c ⊓ (b ⊔ c)) (d ⊓ (b ⊔ c)) by simpa [h₂, inf_eq_right.mpr (sup_le hbd hcd)] using this apply (h₄ (inf_le_of_left_le hbd) _).1 simpa [sup_eq_right.mpr (le_inf hab hac), sup_eq_left.mpr (inf_le_of_left_le hbd)] using ((h₄ (le_trans hab hbd) had).2 : r (a ⊔ b ⊓ c) (d ⊔ b ⊓ c)) private lemma transitive {r : α → α → Prop} (h₂ : ∀ ⦃x y : α⦄, r x y ↔ r (x ⊓ y) (x ⊔ y)) (h₃ : ∀ ⦃x y z : α⦄, x ≤ y → y ≤ z → r x y → r y z → r x z) (h₄ : ∀ ⦃x y t : α⦄, x ≤ y → r x y → r (x ⊓ t) (y ⊓ t) ∧ r (x ⊔ t) (y ⊔ t)) : ∀ {x y z : α}, r x y → r y z → r x z := by intro x y z hxy hyz exact closed_interval h₂ h₄ (x ⊓ y ⊓ z) _ _ (x ⊔ y ⊔ z) (by simp [inf_assoc, inf_le_left]) (by simp [sup_assoc, le_sup_left]) inf_le_right le_sup_right (h₃ (by simpa [inf_assoc] using inf_le_of_right_le inf_le_sup) (by simp [sup_assoc, le_sup_right]) (h₃ (by simpa [inf_assoc] using inf_le_right (b := y ⊓ z)) inf_le_sup (by suffices r (x ⊓ y ⊓ (y ⊓ z)) ((x ⊔ y) ⊓ (y ⊓ z)) by rw [inf_comm x, inf_assoc] simpa [inf_comm x, ← inf_inf_distrib_left] using this exact (h₄ inf_le_sup (h₂.mp hxy)).1) (h₂.mp hyz)) (by simpa [sup_comm y x, sup_sup_distrib_left y x z, sup_assoc] using ((h₄ inf_le_sup (h₂.mp hxy)).2 : r (x ⊓ y ⊔ (y ⊔ z)) (x ⊔ y ⊔ (y ⊔ z))))) /-- Alternative conditions for a lattice congruence. -/ def mk' [Lattice α] (r : α → α → Prop) [h₁ : IsRefl α r] (h₂ : ∀ ⦃x y : α⦄, r x y ↔ r (x ⊓ y) (x ⊔ y)) (h₃ : ∀ ⦃x y z : α⦄, x ≤ y → y ≤ z → r x y → r y z → r x z) (h₄ : ∀ ⦃x y t : α⦄, x ≤ y → r x y → r (x ⊓ t) (y ⊓ t) ∧ r (x ⊔ t) (y ⊔ t)) : LatticeCon α where r := r iseqv.refl := h₁.refl iseqv.symm h := by simpa [h₂, inf_comm, sup_comm, ← h₂] using h iseqv.trans hxy hxz := transitive h₂ h₃ h₄ hxy hxz inf := by intro w _ _ _ h1 h2 have compatible_left_inf {x y t : α} (hh : r x y) : r (x ⊓ t) (y ⊓ t) := closed_interval h₂ h₄ ((x ⊓ y) ⊓ t) _ _ ((x ⊔ y) ⊓ t) (inf_le_inf_right _ inf_le_left) (inf_le_inf_right _ le_sup_left) (inf_le_inf_right _ inf_le_right) (inf_le_inf_right _ le_sup_right) (h₄ inf_le_sup (h₂.mp hh)).1 exact transitive h₂ h₃ h₄ (by simpa [inf_comm w] using compatible_left_inf h2) (compatible_left_inf h1) sup := by intro w _ _ _ h1 h2 have compatible_left_sup {x y t : α} (hh : r x y) : r (x ⊔ t) (y ⊔ t) := closed_interval h₂ h₄ ((x ⊓ y) ⊔ t) _ _ ((x ⊔ y) ⊔ t) (sup_le_sup_right inf_le_left _) (sup_le_sup_right le_sup_left _) (sup_le_sup_right inf_le_right _) (sup_le_sup_right le_sup_right _) (h₄ inf_le_sup (h₂.mp hh)).2 exact transitive h₂ h₃ h₄ (by simpa [sup_comm w] using compatible_left_sup h2) (compatible_left_sup h1) variable [FunLike F α β] open Function /-- The kernel of a lattice homomorphism as a lattice congruence. -/ @[simps!] def ker [Lattice α] [Lattice β] [LatticeHomClass F α β] (f : F) : LatticeCon α where toSetoid := Setoid.ker f inf _ _ := by simp_all only [Setoid.ker, onFun, map_inf] sup _ _ := by simp_all only [Setoid.ker, onFun, map_sup] end LatticeCon
.lake/packages/mathlib/Mathlib/Order/Rel/GaloisConnection.lean
import Mathlib.Data.Rel /-! # The Galois Connection Induced by a Relation In this file, we show that an arbitrary relation `R` between a pair of types `α` and `β` defines a pair `toDual ∘ R.leftDual` and `R.rightDual ∘ ofDual` of adjoint order-preserving maps between the corresponding posets `Set α` and `(Set β)ᵒᵈ`. We define `R.leftFixedPoints` (resp. `R.rightFixedPoints`) as the set of fixed points `J` (resp. `I`) of `Set α` (resp. `Set β`) such that `rightDual (leftDual J) = J` (resp. `leftDual (rightDual I) = I`). ## Main Results ⋆ `Rel.gc_leftDual_rightDual`: we prove that the maps `toDual ∘ R.leftDual` and `R.rightDual ∘ ofDual` form a Galois connection. ⋆ `Rel.equivFixedPoints`: we prove that the maps `R.leftDual` and `R.rightDual` induce inverse bijections between the sets of fixed points. ## References ⋆ Engendrement de topologies, démontrabilité et opérations sur les sous-topos, Olivia Caramello and Laurent Lafforgue (in preparation) ## Tags relation, Galois connection, induced bijection, fixed points -/ variable {α β : Type*} (R : SetRel α β) namespace SetRel /-! ### Pairs of adjoint maps defined by relations -/ open OrderDual /-- `leftDual` maps any set `J` of elements of type `α` to the set `{b : β | ∀ a ∈ J, a ~[R] b}` of elements `b` of type `β` such that `a ~[R] b` for every element `a` of `J`. -/ def leftDual (J : Set α) : Set β := {b : β | ∀ ⦃a⦄, a ∈ J → a ~[R] b} /-- `rightDual` maps any set `I` of elements of type `β` to the set `{a : α | ∀ b ∈ I, a ~[R] b}` of elements `a` of type `α` such that `a ~[R] b` for every element `b` of `I`. -/ def rightDual (I : Set β) : Set α := {a : α | ∀ ⦃b⦄, b ∈ I → a ~[R] b} /-- The pair of functions `toDual ∘ leftDual` and `rightDual ∘ ofDual` forms a Galois connection. -/ theorem gc_leftDual_rightDual : GaloisConnection (toDual ∘ R.leftDual) (R.rightDual ∘ ofDual) := fun _ _ ↦ ⟨fun h _ ha _ hb ↦ h (by simpa) ha, fun h _ hb _ ha ↦ h (by simpa) hb⟩ /-! ### Induced equivalences between fixed points -/ /-- `leftFixedPoints` is the set of elements `J : Set α` satisfying `rightDual (leftDual J) = J`. -/ def leftFixedPoints := {J : Set α | R.rightDual (R.leftDual J) = J} /-- `rightFixedPoints` is the set of elements `I : Set β` satisfying `leftDual (rightDual I) = I`. -/ def rightFixedPoints := {I : Set β | R.leftDual (R.rightDual I) = I} open GaloisConnection /-- `leftDual` maps every element `J` to `rightFixedPoints`. -/ theorem leftDual_mem_rightFixedPoint (J : Set α) : R.leftDual J ∈ R.rightFixedPoints := by apply le_antisymm · apply R.gc_leftDual_rightDual.monotone_l; exact R.gc_leftDual_rightDual.le_u_l J · exact R.gc_leftDual_rightDual.l_u_le (R.leftDual J) /-- `rightDual` maps every element `I` to `leftFixedPoints`. -/ theorem rightDual_mem_leftFixedPoint (I : Set β) : R.rightDual I ∈ R.leftFixedPoints := by apply le_antisymm · apply R.gc_leftDual_rightDual.monotone_u; exact R.gc_leftDual_rightDual.l_u_le I · exact R.gc_leftDual_rightDual.le_u_l (R.rightDual I) /-- The maps `leftDual` and `rightDual` induce inverse bijections between the sets of fixed points. -/ def equivFixedPoints : R.leftFixedPoints ≃ R.rightFixedPoints where toFun := fun ⟨J, _⟩ => ⟨R.leftDual J, R.leftDual_mem_rightFixedPoint J⟩ invFun := fun ⟨I, _⟩ => ⟨R.rightDual I, R.rightDual_mem_leftFixedPoint I⟩ left_inv J := by obtain ⟨J, hJ⟩ := J; rw [Subtype.mk.injEq, hJ] right_inv I := by obtain ⟨I, hI⟩ := I; rw [Subtype.mk.injEq, hI] theorem rightDual_leftDual_le_of_le {J J' : Set α} (h : J' ∈ R.leftFixedPoints) (h₁ : J ≤ J') : R.rightDual (R.leftDual J) ≤ J' := by rw [← h] apply R.gc_leftDual_rightDual.monotone_u apply R.gc_leftDual_rightDual.monotone_l exact h₁ theorem leftDual_rightDual_le_of_le {I I' : Set β} (h : I' ∈ R.rightFixedPoints) (h₁ : I ≤ I') : R.leftDual (R.rightDual I) ≤ I' := by rw [← h] apply R.gc_leftDual_rightDual.monotone_l apply R.gc_leftDual_rightDual.monotone_u exact h₁ end SetRel
.lake/packages/mathlib/Mathlib/Order/ScottContinuity/Complete.lean
import Mathlib.Order.ScottContinuity.Prod /-! # Scott continuity on complete lattices ## Main results - `scottContinuous_iff_map_sSup`: A function is Scott continuous if and only if it commutes with `sSup` on directed sets. -/ variable {α β : Type*} section CompleteLattice variable [CompleteLattice α] [CompleteLattice β] /- `f` is Scott continuous if and only if it commutes with `sSup` on directed sets -/ lemma scottContinuous_iff_map_sSup {f : α → β} : ScottContinuous f ↔ ∀ ⦃d : Set α⦄, d.Nonempty → DirectedOn (· ≤ ·) d → f (sSup d) = sSup (f '' d) where mp h _ d₁ d₂ := by rw [IsLUB.sSup_eq (h d₁ d₂ (isLUB_iff_sSup_eq.mpr rfl))] mpr h _ d₁ d₂ _ hda := by rw [isLUB_iff_sSup_eq, ← (h d₁ d₂), IsLUB.sSup_eq hda] alias ⟨ScottContinuous.map_sSup, ScottContinuous.of_map_sSup⟩ := scottContinuous_iff_map_sSup end CompleteLattice /-! In a complete linear order, the Scott Topology coincides with the Upper topology, see `Topology.IsScott.scott_eq_upper_of_completeLinearOrder` -/ section CompleteLinearOrder variable [CompleteLinearOrder β] lemma scottContinuous_inf_right (a : β) : ScottContinuous fun b ↦ a ⊓ b := .of_map_sSup (fun d _ _ ↦ by rw [inf_sSup_eq, sSup_image]) lemma scottContinuous_inf_left (b : β) : ScottContinuous fun a ↦ a ⊓ b := .of_map_sSup (fun d _ _ ↦ by rw [sSup_inf_eq, sSup_image]) /- The meet operation is Scott continuous -/ lemma ScottContinuous.inf₂ : ScottContinuous fun (a, b) => (a ⊓ b : β) := ScottContinuous.fromProd (fun a => scottContinuous_inf_right a) scottContinuous_inf_left end CompleteLinearOrder
.lake/packages/mathlib/Mathlib/Order/ScottContinuity/Prod.lean
import Mathlib.Order.ScottContinuity import Mathlib.Order.Bounds.Lattice /-! # Scott continuity on product spaces ## Main result - `ScottContinuous_prod_of_ScottContinuous`: A function is Scott continuous on a product space if it is Scott continuous in each variable. - `ScottContinuousOn.inf₂`: For complete linear orders, the meet operation is Scott continuous. -/ open Set variable {α β γ : Type*} /-- If is Scott continuous on a product space if it is Scott continuous and monotone in each variable -/ lemma ScottContinuousOn.fromProd [Preorder α] [Preorder β] [Preorder γ] {f : α × β → γ} {D : Set (Set (α × β))} (h₁ : ∀ a, ScottContinuousOn ((fun d => Prod.snd '' d) '' D) (fun b => f (a, b))) (h₂ : ∀ b, ScottContinuousOn ((fun d => Prod.fst '' d) '' D) (fun a => f (a, b))) (h₁' : ∀ a, Monotone (fun b => f (a, b))) (h₂' : ∀ b, Monotone (fun a => f (a, b))) : ScottContinuousOn D f := fun d hX hd₁ hd₂ ⟨p1, p2⟩ hdp => by rw [isLUB_congr ((monotone_prod_iff.mpr ⟨h₁', h₂'⟩).upperBounds_image_of_directedOn_prod hd₂), ← iUnion_of_singleton_coe (Prod.fst '' d), iUnion_prod_const, image_iUnion, ← isLUB_iUnion_iff_of_isLUB (fun a => by rw [singleton_prod, image_image f (fun b ↦ (a, b))] exact h₁ _ (mem_image_of_mem (fun d ↦ Prod.snd '' d) hX) (Nonempty.image Prod.snd hd₁) (DirectedOn.snd hd₂) ((isLUB_prod (_, _)).mp hdp).2) _, Set.range] convert (h₂ _ (mem_image_of_mem (fun d ↦ Prod.fst '' d) hX) (Nonempty.image Prod.fst hd₁) (DirectedOn.fst hd₂) ((isLUB_prod (p1, p2)).mp hdp).1) ext : 1 simp_all only [Subtype.exists, mem_image, Prod.exists, exists_and_right, exists_eq_right, exists_prop, mem_setOf_eq] lemma ScottContinuous.fromProd {γ : Type*} [Preorder α] [Preorder β] [Preorder γ] {f : α × β → γ} (h₁ : ∀ a, ScottContinuous (fun b => f (a, b))) (h₂ : ∀ b, ScottContinuous (fun a => f (a, b))) : ScottContinuous f := by simp_rw [← scottContinuousOn_univ] at ⊢ exact .fromProd (fun a ↦ (h₁ a).scottContinuousOn) (fun b ↦ (h₂ b).scottContinuousOn) (fun a ↦ (h₁ a).monotone) (fun b ↦ (h₂ b).monotone) lemma ScottContinuous.prod {α' β' : Type*} [Preorder α] [Preorder β] [Preorder α'] [Preorder β'] {f : α → α'} {g : β → β'} (hf : ScottContinuous f) (hg : ScottContinuous g) : ScottContinuous (Prod.map f g) := by refine .fromProd (fun a d hd₁ hd₂ c hdc ↦ ?_) (fun b d hd₁ hd₂ c hdc ↦ ?_) · have e1 : (fun b ↦ (f a, g b)) '' d = {f a} ×ˢ (g '' d) := by aesop simp_rw [Prod.map_apply, e1] exact .prod (singleton_nonempty _) (hd₁.image _) isLUB_singleton (hg hd₁ hd₂ hdc) · have e2 : ((fun a ↦ (f a, g b)) '' d) = (f '' d) ×ˢ {g b} := by aesop simp_rw [Prod.map_apply, e2] exact .prod (hd₁.image _) (singleton_nonempty _) (hf hd₁ hd₂ hdc) isLUB_singleton
.lake/packages/mathlib/Mathlib/Order/RelIso/Basic.lean
import Mathlib.Logic.Embedding.Basic import Mathlib.Order.RelClasses /-! # Relation homomorphisms, embeddings, isomorphisms This file defines relation homomorphisms, embeddings, isomorphisms and order embeddings and isomorphisms. ## Main declarations * `RelHom`: Relation homomorphism. A `RelHom r s` is a function `f : α → β` such that `r a b → s (f a) (f b)`. * `RelEmbedding`: Relation embedding. A `RelEmbedding r s` is an embedding `f : α ↪ β` such that `r a b ↔ s (f a) (f b)`. * `RelIso`: Relation isomorphism. A `RelIso r s` is an equivalence `f : α ≃ β` such that `r a b ↔ s (f a) (f b)`. * `sumLexCongr`, `prodLexCongr`: Creates a relation homomorphism between two `Sum.Lex` or two `Prod.Lex` from relation homomorphisms between their arguments. ## Notation * `→r`: `RelHom` * `↪r`: `RelEmbedding` * `≃r`: `RelIso` -/ open Function universe u v w variable {α β γ δ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} {u : δ → δ → Prop} /-- A relation homomorphism with respect to a given pair of relations `r` and `s` is a function `f : α → β` such that `r a b → s (f a) (f b)`. -/ structure RelHom {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) where /-- The underlying function of a `RelHom` -/ toFun : α → β /-- A `RelHom` sends related elements to related elements -/ map_rel' : ∀ {a b}, r a b → s (toFun a) (toFun b) /-- A relation homomorphism with respect to a given pair of relations `r` and `s` is a function `f : α → β` such that `r a b → s (f a) (f b)`. -/ infixl:25 " →r " => RelHom section /-- `RelHomClass F r s` asserts that `F` is a type of functions such that all `f : F` satisfy `r a b → s (f a) (f b)`. The relations `r` and `s` are `outParam`s since figuring them out from a goal is a higher-order matching problem that Lean usually can't do unaided. -/ class RelHomClass (F : Type*) {α β : outParam Type*} (r : outParam <| α → α → Prop) (s : outParam <| β → β → Prop) [FunLike F α β] : Prop where /-- A `RelHomClass` sends related elements to related elements -/ map_rel : ∀ (f : F) {a b}, r a b → s (f a) (f b) export RelHomClass (map_rel) end namespace RelHomClass variable {F : Type*} [FunLike F α β] protected theorem isIrrefl [RelHomClass F r s] (f : F) : ∀ [IsIrrefl β s], IsIrrefl α r | ⟨H⟩ => ⟨fun _ h => H _ (map_rel f h)⟩ protected theorem isAsymm [RelHomClass F r s] (f : F) : ∀ [IsAsymm β s], IsAsymm α r | ⟨H⟩ => ⟨fun _ _ h₁ h₂ => H _ _ (map_rel f h₁) (map_rel f h₂)⟩ protected theorem acc [RelHomClass F r s] (f : F) (a : α) : Acc s (f a) → Acc r a := by generalize h : f a = b intro ac induction ac generalizing a with | intro _ H IH => ?_ subst h exact ⟨_, fun a' h => IH (f a') (map_rel f h) _ rfl⟩ protected theorem wellFounded [RelHomClass F r s] (f : F) : WellFounded s → WellFounded r | ⟨H⟩ => ⟨fun _ => RelHomClass.acc f _ (H _)⟩ protected theorem isWellFounded [RelHomClass F r s] (f : F) [IsWellFounded β s] : IsWellFounded α r := ⟨RelHomClass.wellFounded f IsWellFounded.wf⟩ end RelHomClass namespace RelHom instance : FunLike (r →r s) α β where coe o := o.toFun coe_injective' f g h := by cases f cases g congr instance : RelHomClass (r →r s) r s where map_rel := map_rel' initialize_simps_projections RelHom (toFun → apply) protected theorem map_rel (f : r →r s) {a b} : r a b → s (f a) (f b) := f.map_rel' @[simp] theorem coe_fn_toFun (f : r →r s) : f.toFun = (f : α → β) := rfl @[simp] theorem coeFn_mk (f : α → β) (h : ∀ {a b}, r a b → s (f a) (f b)) : RelHom.mk f @h = f := rfl /-- The map `coe_fn : (r →r s) → (α → β)` is injective. -/ theorem coe_fn_injective : Injective fun (f : r →r s) => (f : α → β) := DFunLike.coe_injective @[ext] theorem ext ⦃f g : r →r s⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Identity map is a relation homomorphism. -/ @[refl, simps] protected def id (r : α → α → Prop) : r →r r := ⟨fun x => x, fun x => x⟩ /-- Composition of two relation homomorphisms is a relation homomorphism. -/ @[simps] protected def comp (g : s →r t) (f : r →r s) : r →r t := ⟨fun x => g (f x), fun h => g.2 (f.2 h)⟩ /-- A relation homomorphism is also a relation homomorphism between dual relations. -/ @[simps] protected def swap (f : r →r s) : swap r →r swap s := ⟨f, f.map_rel⟩ /-- A function is a relation homomorphism from the preimage relation of `s` to `s`. -/ @[simps] def preimage (f : α → β) (s : β → β → Prop) : f ⁻¹'o s →r s := ⟨f, id⟩ end RelHom /-- An increasing function is injective -/ theorem injective_of_increasing (r : α → α → Prop) (s : β → β → Prop) [IsTrichotomous α r] [IsIrrefl β s] (f : α → β) (hf : ∀ {x y}, r x y → s (f x) (f y)) : Injective f := by intro x y hxy rcases trichotomous_of r x y with (h | h | h) · have := hf h rw [hxy] at this exfalso exact irrefl_of s (f y) this · exact h · have := hf h rw [hxy] at this exfalso exact irrefl_of s (f y) this /-- An increasing function is injective -/ theorem RelHom.injective_of_increasing [IsTrichotomous α r] [IsIrrefl β s] (f : r →r s) : Injective f := _root_.injective_of_increasing r s f f.map_rel theorem Function.Surjective.wellFounded_iff {f : α → β} (hf : Surjective f) (o : ∀ {a b}, r a b ↔ s (f a) (f b)) : WellFounded r ↔ WellFounded s := Iff.intro (RelHomClass.wellFounded (⟨surjInv hf, fun h => by simpa only [o, surjInv_eq hf] using h⟩ : s →r r)) (RelHomClass.wellFounded (⟨f, o.1⟩ : r →r s)) /-- A relation embedding with respect to a given pair of relations `r` and `s` is an embedding `f : α ↪ β` such that `r a b ↔ s (f a) (f b)`. -/ structure RelEmbedding {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ↪ β where /-- Elements are related iff they are related after apply a `RelEmbedding` -/ map_rel_iff' : ∀ {a b}, s (toEmbedding a) (toEmbedding b) ↔ r a b /-- A relation embedding with respect to a given pair of relations `r` and `s` is an embedding `f : α ↪ β` such that `r a b ↔ s (f a) (f b)`. -/ infixl:25 " ↪r " => RelEmbedding theorem preimage_equivalence {α β} (f : α → β) {s : β → β → Prop} (hs : Equivalence s) : Equivalence (f ⁻¹'o s) := ⟨fun _ => hs.1 _, fun h => hs.2 h, fun h₁ h₂ => hs.3 h₁ h₂⟩ namespace RelEmbedding /-- A relation embedding is also a relation homomorphism -/ def toRelHom (f : r ↪r s) : r →r s where toFun := f.toEmbedding.toFun map_rel' := (map_rel_iff' f).mpr instance : Coe (r ↪r s) (r →r s) := ⟨toRelHom⟩ -- TODO: define and instantiate a `RelEmbeddingClass` when `EmbeddingLike` is defined instance : FunLike (r ↪r s) α β where coe x := x.toFun coe_injective' f g h := by rcases f with ⟨⟨⟩⟩ rcases g with ⟨⟨⟩⟩ congr -- TODO: define and instantiate a `RelEmbeddingClass` when `EmbeddingLike` is defined instance : RelHomClass (r ↪r s) r s where map_rel f _ _ := Iff.mpr (map_rel_iff' f) initialize_simps_projections RelEmbedding (toFun → apply) instance : EmbeddingLike (r ↪r s) α β where injective' f := f.inj' @[simp] theorem coe_toEmbedding {f : r ↪r s} : ((f : r ↪r s).toEmbedding : α → β) = f := rfl @[simp] theorem coe_toRelHom {f : r ↪r s} : ((f : r ↪r s).toRelHom : α → β) = f := rfl theorem toEmbedding_injective : Injective (toEmbedding : r ↪r s → (α ↪ β)) := by rintro ⟨f, -⟩ ⟨g, -⟩; simp @[simp] theorem toEmbedding_inj {f g : r ↪r s} : f.toEmbedding = g.toEmbedding ↔ f = g := toEmbedding_injective.eq_iff theorem injective (f : r ↪r s) : Injective f := f.inj' theorem inj (f : r ↪r s) {a b} : f a = f b ↔ a = b := f.injective.eq_iff theorem map_rel_iff (f : r ↪r s) {a b} : s (f a) (f b) ↔ r a b := f.map_rel_iff' @[simp] theorem coe_mk {f} {h} : ⇑(⟨f, h⟩ : r ↪r s) = f := rfl /-- The map `coe_fn : (r ↪r s) → (α → β)` is injective. -/ theorem coe_fn_injective : Injective fun f : r ↪r s => (f : α → β) := DFunLike.coe_injective @[ext] theorem ext ⦃f g : r ↪r s⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h /-- Identity map is a relation embedding. -/ @[refl, simps!] protected def refl (r : α → α → Prop) : r ↪r r := ⟨Embedding.refl _, Iff.rfl⟩ /-- Composition of two relation embeddings is a relation embedding. -/ protected def trans (f : r ↪r s) (g : s ↪r t) : r ↪r t := ⟨f.1.trans g.1, by simp [f.map_rel_iff, g.map_rel_iff]⟩ instance (r : α → α → Prop) : Inhabited (r ↪r r) := ⟨RelEmbedding.refl _⟩ theorem trans_apply (f : r ↪r s) (g : s ↪r t) (a : α) : (f.trans g) a = g (f a) := rfl @[simp] theorem coe_trans (f : r ↪r s) (g : s ↪r t) : (f.trans g) = g ∘ f := rfl /-- A relation embedding is also a relation embedding between dual relations. -/ protected def swap (f : r ↪r s) : swap r ↪r swap s := ⟨f.toEmbedding, f.map_rel_iff⟩ @[simp] theorem swap_apply (f : r ↪r s) (a : α) : f.swap a = f a := rfl /-- If `f` is injective, then it is a relation embedding from the preimage relation of `s` to `s`. -/ def preimage (f : α ↪ β) (s : β → β → Prop) : f ⁻¹'o s ↪r s := ⟨f, Iff.rfl⟩ @[simp] theorem preimage_apply (f : α ↪ β) (s : β → β → Prop) (a : α) : preimage f s a = f a := rfl theorem eq_preimage (f : r ↪r s) : r = f ⁻¹'o s := by ext a b exact f.map_rel_iff.symm protected theorem isIrrefl (f : r ↪r s) [IsIrrefl β s] : IsIrrefl α r := ⟨fun a => mt f.map_rel_iff.2 (irrefl (f a))⟩ protected theorem isRefl (f : r ↪r s) [IsRefl β s] : IsRefl α r := ⟨fun _ => f.map_rel_iff.1 <| refl _⟩ protected theorem isSymm (f : r ↪r s) [IsSymm β s] : IsSymm α r := ⟨fun _ _ => imp_imp_imp f.map_rel_iff.2 f.map_rel_iff.1 symm⟩ protected theorem isAsymm (f : r ↪r s) [IsAsymm β s] : IsAsymm α r := ⟨fun _ _ h₁ h₂ => asymm (f.map_rel_iff.2 h₁) (f.map_rel_iff.2 h₂)⟩ protected theorem isAntisymm : ∀ (_ : r ↪r s) [IsAntisymm β s], IsAntisymm α r | ⟨f, o⟩, ⟨H⟩ => ⟨fun _ _ h₁ h₂ => f.inj' (H _ _ (o.2 h₁) (o.2 h₂))⟩ protected theorem isTrans : ∀ (_ : r ↪r s) [IsTrans β s], IsTrans α r | ⟨_, o⟩, ⟨H⟩ => ⟨fun _ _ _ h₁ h₂ => o.1 (H _ _ _ (o.2 h₁) (o.2 h₂))⟩ protected theorem isTotal : ∀ (_ : r ↪r s) [IsTotal β s], IsTotal α r | ⟨_, o⟩, ⟨H⟩ => ⟨fun _ _ => (or_congr o o).1 (H _ _)⟩ protected theorem isPreorder : ∀ (_ : r ↪r s) [IsPreorder β s], IsPreorder α r | f, _ => { f.isRefl, f.isTrans with } protected theorem isPartialOrder : ∀ (_ : r ↪r s) [IsPartialOrder β s], IsPartialOrder α r | f, _ => { f.isPreorder, f.isAntisymm with } protected theorem isLinearOrder : ∀ (_ : r ↪r s) [IsLinearOrder β s], IsLinearOrder α r | f, _ => { f.isPartialOrder, f.isTotal with } protected theorem isStrictOrder : ∀ (_ : r ↪r s) [IsStrictOrder β s], IsStrictOrder α r | f, _ => { f.isIrrefl, f.isTrans with } protected theorem isTrichotomous : ∀ (_ : r ↪r s) [IsTrichotomous β s], IsTrichotomous α r | ⟨f, o⟩, ⟨H⟩ => ⟨fun _ _ => (or_congr o (or_congr f.inj'.eq_iff o)).1 (H _ _)⟩ protected theorem isStrictTotalOrder : ∀ (_ : r ↪r s) [IsStrictTotalOrder β s], IsStrictTotalOrder α r | f, _ => { f.isTrichotomous, f.isStrictOrder with } protected theorem acc (f : r ↪r s) (a : α) : Acc s (f a) → Acc r a := by generalize h : f a = b intro ac induction ac generalizing a with | intro _ H IH => ?_ subst h exact ⟨_, fun a' h => IH (f a') (f.map_rel_iff.2 h) _ rfl⟩ protected theorem wellFounded : ∀ (_ : r ↪r s) (_ : WellFounded s), WellFounded r | f, ⟨H⟩ => ⟨fun _ => f.acc _ (H _)⟩ protected theorem isWellFounded (f : r ↪r s) [IsWellFounded β s] : IsWellFounded α r := ⟨f.wellFounded IsWellFounded.wf⟩ protected theorem isWellOrder : ∀ (_ : r ↪r s) [IsWellOrder β s], IsWellOrder α r | f, H => { f.isStrictTotalOrder with wf := f.wellFounded H.wf } end RelEmbedding /-- The induced relation on a subtype is an embedding under the natural inclusion. -/ @[simps!] def Subtype.relEmbedding {X : Type*} (r : X → X → Prop) (p : X → Prop) : (Subtype.val : Subtype p → X) ⁻¹'o r ↪r r := ⟨Embedding.subtype p, Iff.rfl⟩ instance Subtype.wellFoundedLT [LT α] [WellFoundedLT α] (p : α → Prop) : WellFoundedLT (Subtype p) := (Subtype.relEmbedding (· < ·) p).isWellFounded instance Subtype.wellFoundedGT [LT α] [WellFoundedGT α] (p : α → Prop) : WellFoundedGT (Subtype p) := (Subtype.relEmbedding (· > ·) p).isWellFounded /-- `Quotient.mk` as a relation homomorphism between the relation and the lift of a relation. -/ @[simps] def Quotient.mkRelHom {_ : Setoid α} {r : α → α → Prop} (H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂) : r →r Quotient.lift₂ r H := ⟨Quotient.mk _, id⟩ /-- `Quotient.out` as a relation embedding between the lift of a relation and the relation. -/ @[simps!] noncomputable def Quotient.outRelEmbedding {_ : Setoid α} {r : α → α → Prop} (H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂) : Quotient.lift₂ r H ↪r r := ⟨Embedding.quotientOut α, by refine @fun x y => Quotient.inductionOn₂ x y fun a b => ?_ apply iff_iff_eq.2 (H _ _ _ _ _ _) <;> apply Quotient.mk_out⟩ @[simp] theorem acc_lift₂_iff {_ : Setoid α} {r : α → α → Prop} {H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂} {a} : Acc (Quotient.lift₂ r H) ⟦a⟧ ↔ Acc r a := by constructor · exact RelHomClass.acc (Quotient.mkRelHom H) a · intro ac induction ac with | intro _ _ IH => ?_ refine ⟨_, fun q h => ?_⟩ obtain ⟨a', rfl⟩ := q.exists_rep exact IH a' h @[simp] theorem acc_liftOn₂'_iff {s : Setoid α} {r : α → α → Prop} {H} {a} : Acc (fun x y => Quotient.liftOn₂' x y r H) (Quotient.mk'' a : Quotient s) ↔ Acc r a := acc_lift₂_iff (H := H) /-- A relation is well founded iff its lift to a quotient is. -/ @[simp] theorem wellFounded_lift₂_iff {_ : Setoid α} {r : α → α → Prop} {H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂} : WellFounded (Quotient.lift₂ r H) ↔ WellFounded r := by constructor · exact RelHomClass.wellFounded (Quotient.mkRelHom H) · refine fun wf => ⟨fun q => ?_⟩ obtain ⟨a, rfl⟩ := q.exists_rep exact acc_lift₂_iff.2 (wf.apply a) alias ⟨WellFounded.of_quotient_lift₂, WellFounded.quotient_lift₂⟩ := wellFounded_lift₂_iff @[simp] theorem wellFounded_liftOn₂'_iff {s : Setoid α} {r : α → α → Prop} {H} : (WellFounded fun x y : Quotient s => Quotient.liftOn₂' x y r H) ↔ WellFounded r := wellFounded_lift₂_iff (H := H) alias ⟨WellFounded.of_quotient_liftOn₂', WellFounded.quotient_liftOn₂'⟩ := wellFounded_liftOn₂'_iff namespace RelEmbedding /-- To define a relation embedding from an antisymmetric relation `r` to a reflexive relation `s` it suffices to give a function together with a proof that it satisfies `s (f a) (f b) ↔ r a b`. -/ def ofMapRelIff (f : α → β) [IsAntisymm α r] [IsRefl β s] (hf : ∀ a b, s (f a) (f b) ↔ r a b) : r ↪r s where toFun := f inj' _ _ h := antisymm ((hf _ _).1 (h ▸ refl _)) ((hf _ _).1 (h ▸ refl _)) map_rel_iff' := hf _ _ @[simp] theorem ofMapRelIff_coe (f : α → β) [IsAntisymm α r] [IsRefl β s] (hf : ∀ a b, s (f a) (f b) ↔ r a b) : (ofMapRelIff f hf : r ↪r s) = f := rfl /-- It suffices to prove `f` is monotone between strict relations to show it is a relation embedding. -/ def ofMonotone [IsTrichotomous α r] [IsAsymm β s] (f : α → β) (H : ∀ a b, r a b → s (f a) (f b)) : r ↪r s := by haveI := @IsAsymm.isIrrefl β s _ refine ⟨⟨f, fun a b e => ?_⟩, @fun a b => ⟨fun h => ?_, H _ _⟩⟩ · refine ((@trichotomous _ r _ a b).resolve_left ?_).resolve_right ?_ · exact fun h => irrefl (r := s) (f a) (by simpa [e] using H _ _ h) · exact fun h => irrefl (r := s) (f b) (by simpa [e] using H _ _ h) · refine (@trichotomous _ r _ a b).resolve_right (Or.rec (fun e => ?_) fun h' => ?_) · subst e exact irrefl _ h · exact asymm (H _ _ h') h @[simp] theorem ofMonotone_coe [IsTrichotomous α r] [IsAsymm β s] (f : α → β) (H) : (@ofMonotone _ _ r s _ _ f H : α → β) = f := rfl /-- A relation embedding from an empty type. -/ def ofIsEmpty (r : α → α → Prop) (s : β → β → Prop) [IsEmpty α] : r ↪r s := ⟨Embedding.ofIsEmpty, @fun a => isEmptyElim a⟩ /-- `Sum.inl` as a relation embedding into `Sum.LiftRel r s`. -/ @[simps] def sumLiftRelInl (r : α → α → Prop) (s : β → β → Prop) : r ↪r Sum.LiftRel r s where toFun := Sum.inl inj' := Sum.inl_injective map_rel_iff' := Sum.liftRel_inl_inl /-- `Sum.inr` as a relation embedding into `Sum.LiftRel r s`. -/ @[simps] def sumLiftRelInr (r : α → α → Prop) (s : β → β → Prop) : s ↪r Sum.LiftRel r s where toFun := Sum.inr inj' := Sum.inr_injective map_rel_iff' := Sum.liftRel_inr_inr /-- `Sum.map` as a relation embedding between `Sum.LiftRel` relations. -/ @[simps] def sumLiftRelMap (f : r ↪r s) (g : t ↪r u) : Sum.LiftRel r t ↪r Sum.LiftRel s u where toFun := Sum.map f g inj' := f.injective.sumMap g.injective map_rel_iff' := by rintro (a | b) (c | d) <;> simp [f.map_rel_iff, g.map_rel_iff] /-- `Sum.inl` as a relation embedding into `Sum.Lex r s`. -/ @[simps] def sumLexInl (r : α → α → Prop) (s : β → β → Prop) : r ↪r Sum.Lex r s where toFun := Sum.inl inj' := Sum.inl_injective map_rel_iff' := Sum.lex_inl_inl /-- `Sum.inr` as a relation embedding into `Sum.Lex r s`. -/ @[simps] def sumLexInr (r : α → α → Prop) (s : β → β → Prop) : s ↪r Sum.Lex r s where toFun := Sum.inr inj' := Sum.inr_injective map_rel_iff' := Sum.lex_inr_inr /-- `Sum.map` as a relation embedding between `Sum.Lex` relations. -/ @[simps] def sumLexMap (f : r ↪r s) (g : t ↪r u) : Sum.Lex r t ↪r Sum.Lex s u where toFun := Sum.map f g inj' := f.injective.sumMap g.injective map_rel_iff' := by rintro (a | b) (c | d) <;> simp [f.map_rel_iff, g.map_rel_iff] /-- `fun b ↦ Prod.mk a b` as a relation embedding. -/ @[simps] def prodLexMkLeft (s : β → β → Prop) {a : α} (h : ¬r a a) : s ↪r Prod.Lex r s where toFun := Prod.mk a inj' := Prod.mk_right_injective a map_rel_iff' := by simp [Prod.lex_def, h] /-- `fun a ↦ Prod.mk a b` as a relation embedding. -/ @[simps] def prodLexMkRight (r : α → α → Prop) {b : β} (h : ¬s b b) : r ↪r Prod.Lex r s where toFun a := (a, b) inj' := Prod.mk_left_injective b map_rel_iff' := by simp [Prod.lex_def, h] /-- `Prod.map` as a relation embedding. -/ @[simps] def prodLexMap (f : r ↪r s) (g : t ↪r u) : Prod.Lex r t ↪r Prod.Lex s u where toFun := Prod.map f g inj' := f.injective.prodMap g.injective map_rel_iff' := by simp [Prod.lex_def, f.map_rel_iff, g.map_rel_iff, f.inj] end RelEmbedding /-- A relation isomorphism is an equivalence that is also a relation embedding. -/ structure RelIso {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ≃ β where /-- Elements are related iff they are related after apply a `RelIso` -/ map_rel_iff' : ∀ {a b}, s (toEquiv a) (toEquiv b) ↔ r a b /-- A relation isomorphism is an equivalence that is also a relation embedding. -/ infixl:25 " ≃r " => RelIso namespace RelIso /-- Convert a `RelIso` to a `RelEmbedding`. This function is also available as a coercion but often it is easier to write `f.toRelEmbedding` than to write explicitly `r` and `s` in the target type. -/ def toRelEmbedding (f : r ≃r s) : r ↪r s := ⟨f.toEquiv.toEmbedding, f.map_rel_iff'⟩ theorem toEquiv_injective : Injective (toEquiv : r ≃r s → α ≃ β) | ⟨e₁, o₁⟩, ⟨e₂, _⟩, h => by congr instance : CoeOut (r ≃r s) (r ↪r s) := ⟨toRelEmbedding⟩ -- TODO: define and instantiate a `RelIsoClass` when `EquivLike` is defined instance : FunLike (r ≃r s) α β where coe x := x coe_injective' := Equiv.coe_fn_injective.comp toEquiv_injective -- TODO: define and instantiate a `RelIsoClass` when `EquivLike` is defined instance : RelHomClass (r ≃r s) r s where map_rel f _ _ := Iff.mpr (map_rel_iff' f) instance : EquivLike (r ≃r s) α β where coe f := f inv f := f.toEquiv.symm left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' _ _ hf _ := DFunLike.ext' hf @[simp] theorem coe_toRelEmbedding (f : r ≃r s) : (f.toRelEmbedding : α → β) = f := rfl @[simp] theorem coe_toEmbedding (f : r ≃r s) : (f.toEmbedding : α → β) = f := rfl theorem map_rel_iff (f : r ≃r s) {a b} : s (f a) (f b) ↔ r a b := f.map_rel_iff' @[simp] theorem coe_fn_mk (f : α ≃ β) (o : ∀ ⦃a b⦄, s (f a) (f b) ↔ r a b) : (RelIso.mk f @o : α → β) = f := rfl @[simp] theorem coe_fn_toEquiv (f : r ≃r s) : (f.toEquiv : α → β) = f := rfl /-- The map `DFunLike.coe : (r ≃r s) → (α → β)` is injective. -/ theorem coe_fn_injective : Injective fun f : r ≃r s => (f : α → β) := DFunLike.coe_injective @[ext] theorem ext ⦃f g : r ≃r s⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Inverse map of a relation isomorphism is a relation isomorphism. -/ protected def symm (f : r ≃r s) : s ≃r r := ⟨f.toEquiv.symm, @fun a b => by erw [← f.map_rel_iff, f.1.apply_symm_apply, f.1.apply_symm_apply]⟩ /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because `RelIso` defines custom coercions other than the ones given by `DFunLike`. -/ def Simps.apply (h : r ≃r s) : α → β := h /-- See Note [custom simps projection]. -/ def Simps.symm_apply (h : r ≃r s) : β → α := h.symm initialize_simps_projections RelIso (toFun → apply, invFun → symm_apply) /-- Identity map is a relation isomorphism. -/ @[refl, simps! apply] protected def refl (r : α → α → Prop) : r ≃r r := ⟨Equiv.refl _, Iff.rfl⟩ /-- Composition of two relation isomorphisms is a relation isomorphism. -/ @[simps! apply] protected def trans (f₁ : r ≃r s) (f₂ : s ≃r t) : r ≃r t := ⟨f₁.toEquiv.trans f₂.toEquiv, f₂.map_rel_iff.trans f₁.map_rel_iff⟩ instance (r : α → α → Prop) : Inhabited (r ≃r r) := ⟨RelIso.refl _⟩ @[simp] theorem default_def (r : α → α → Prop) : default = RelIso.refl r := rfl @[simp] lemma apply_symm_apply (e : r ≃r s) (x : β) : e (e.symm x) = x := e.right_inv x @[simp] lemma symm_apply_apply (e : r ≃r s) (x : α) : e.symm (e x) = x := e.left_inv x @[simp] lemma symm_comp_self (e : r ≃r s) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] lemma self_comp_symm (e : r ≃r s) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp] lemma symm_trans_apply (f : r ≃r s) (g : s ≃r t) (a : γ) : (f.trans g).symm a = f.symm (g.symm a) := rfl lemma symm_symm_apply (f : r ≃r s) (b : α) : f.symm.symm b = f b := rfl lemma apply_eq_iff_eq (f : r ≃r s) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f lemma apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : r ≃r s) : f x = y ↔ x = f.symm y := by conv_lhs => rw [← apply_symm_apply f y] rw [apply_eq_iff_eq] lemma symm_apply_eq (e : r ≃r s) {x y} : e.symm x = y ↔ x = e y := e.toEquiv.symm_apply_eq lemma eq_symm_apply (e : r ≃r s) {x y} : y = e.symm x ↔ e y = x := e.toEquiv.eq_symm_apply @[simp] lemma symm_symm (e : r ≃r s) : e.symm.symm = e := rfl lemma symm_bijective : Bijective (.symm : (r ≃r s) → s ≃r r) := bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] lemma refl_symm : (RelIso.refl r).symm = .refl _ := rfl @[simp] lemma trans_refl (e : r ≃r s) : e.trans (.refl _) = e := rfl @[simp] lemma refl_trans (e : r ≃r s) : .trans (.refl _) e = e := rfl @[simp] lemma symm_trans_self (e : r ≃r s) : e.symm.trans e = .refl _ := ext <| by simp @[simp] lemma self_trans_symm (e : r ≃r s) : e.trans e.symm = .refl _ := ext <| by simp lemma trans_assoc {δ : Type*} {u : δ → δ → Prop} (ab : r ≃r s) (bc : s ≃r t) (cd : t ≃r u) : (ab.trans bc).trans cd = ab.trans (bc.trans cd) := rfl /-- A relation isomorphism between equal relations on equal types. -/ @[simps! toEquiv apply] protected def cast {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} (h₁ : α = β) (h₂ : r ≍ s) : r ≃r s := ⟨Equiv.cast h₁, @fun a b => by subst h₁ rw [eq_of_heq h₂] rfl⟩ @[simp] protected theorem cast_symm {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} (h₁ : α = β) (h₂ : r ≍ s) : (RelIso.cast h₁ h₂).symm = RelIso.cast h₁.symm h₂.symm := rfl @[simp] protected theorem cast_refl {α : Type u} {r : α → α → Prop} (h₁ : α = α := rfl) (h₂ : r ≍ r := HEq.rfl) : RelIso.cast h₁ h₂ = RelIso.refl r := rfl @[simp] protected theorem cast_trans {α β γ : Type u} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} (h₁ : α = β) (h₁' : β = γ) (h₂ : r ≍ s) (h₂' : s ≍ t) : (RelIso.cast h₁ h₂).trans (RelIso.cast h₁' h₂') = RelIso.cast (h₁.trans h₁') (h₂.trans h₂') := ext fun x => by subst h₁; rfl /-- A relation isomorphism is also a relation isomorphism between dual relations. -/ protected def swap (f : r ≃r s) : swap r ≃r swap s := ⟨f, f.map_rel_iff⟩ /-- A relation isomorphism is also a relation isomorphism between complemented relations. -/ @[simps!] protected def compl (f : r ≃r s) : rᶜ ≃r sᶜ := ⟨f, f.map_rel_iff.not⟩ @[simp] theorem coe_fn_symm_mk (f o) : ((@RelIso.mk _ _ r s f @o).symm : β → α) = f.symm := rfl theorem rel_symm_apply (e : r ≃r s) {x y} : r x (e.symm y) ↔ s (e x) y := by rw [← e.map_rel_iff, e.apply_symm_apply] theorem symm_apply_rel (e : r ≃r s) {x y} : r (e.symm x) y ↔ s x (e y) := by rw [← e.map_rel_iff, e.apply_symm_apply] protected theorem bijective (e : r ≃r s) : Bijective e := e.toEquiv.bijective protected theorem injective (e : r ≃r s) : Injective e := e.toEquiv.injective protected theorem surjective (e : r ≃r s) : Surjective e := e.toEquiv.surjective theorem eq_iff_eq (f : r ≃r s) {a b} : f a = f b ↔ a = b := f.injective.eq_iff /-- Copy of a `RelIso` with a new `toFun` and `invFun` equal to the old ones. Useful to fix definitional equalities. -/ def copy (e : r ≃r s) (f : α → β) (g : β → α) (hf : f = e) (hg : g = e.symm) : r ≃r s where toFun := f invFun := g left_inv _ := by simp [hf, hg] right_inv _ := by simp [hf, hg] map_rel_iff' := by simp [hf, e.map_rel_iff] @[simp, norm_cast] lemma coe_copy (e : r ≃r s) (f : α → β) (g : β → α) (hf hg) : e.copy f g hf hg = f := rfl lemma copy_eq (e : r ≃r s) (f : α → β) (g : β → α) (hf hg) : e.copy f g hf hg = e := DFunLike.coe_injective hf /-- Any equivalence lifts to a relation isomorphism between `s` and its preimage. -/ protected def preimage (f : α ≃ β) (s : β → β → Prop) : f ⁻¹'o s ≃r s := ⟨f, Iff.rfl⟩ -- `simps` crashes if asked to generate these @[simp] theorem preimage_apply (f : α ≃ β) (s : β → β → Prop) (a : α) : RelIso.preimage f s a = f a := rfl @[simp] theorem preimage_symm_apply (f : α ≃ β) (s : β → β → Prop) (a : β) : (RelIso.preimage f s).symm a = f.symm a := rfl instance IsWellOrder.preimage {α : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : IsWellOrder β (f ⁻¹'o r) := @RelEmbedding.isWellOrder _ _ (f ⁻¹'o r) r (RelIso.preimage f r) _ instance IsWellOrder.ulift {α : Type u} (r : α → α → Prop) [IsWellOrder α r] : IsWellOrder (ULift α) (ULift.down ⁻¹'o r) := IsWellOrder.preimage r Equiv.ulift /-- A surjective relation embedding is a relation isomorphism. -/ @[simps! apply] noncomputable def ofSurjective (f : r ↪r s) (H : Surjective f) : r ≃r s := ⟨Equiv.ofBijective f ⟨f.injective, H⟩, f.map_rel_iff⟩ /-- Transport a `RelHom` across a pair of `RelIso`s, by pre- and post-composition. This is `Equiv.arrowCongr` for `RelHom`. -/ @[simps] def relHomCongr {α₁ β₁ α₂ β₂} {r₁ : α₁ → α₁ → Prop} {s₁ : β₁ → β₁ → Prop} {r₂ : α₂ → α₂ → Prop} {s₂ : β₂ → β₂ → Prop} (e₁ : r₁ ≃r r₂) (e₂ : s₁ ≃r s₂) : (r₁ →r s₁) ≃ (r₂ →r s₂) where toFun f₁ := e₂.toRelEmbedding.toRelHom.comp <| f₁.comp e₁.symm.toRelEmbedding.toRelHom invFun f₂ := e₂.symm.toRelEmbedding.toRelHom.comp <| f₂.comp e₁.toRelEmbedding.toRelHom left_inv f₁ := by ext; simp right_inv f₂ := by ext; simp /-- Given relation isomorphisms `r₁ ≃r s₁` and `r₂ ≃r s₂`, construct a relation isomorphism for the lexicographic orders on the sum. -/ def sumLexCongr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂} (e₁ : @RelIso α₁ β₁ r₁ s₁) (e₂ : @RelIso α₂ β₂ r₂ s₂) : Sum.Lex r₁ r₂ ≃r Sum.Lex s₁ s₂ := ⟨Equiv.sumCongr e₁.toEquiv e₂.toEquiv, @fun a b => by obtain ⟨f, hf⟩ := e₁; obtain ⟨g, hg⟩ := e₂; cases a <;> cases b <;> simp [hf, hg]⟩ /-- Given relation isomorphisms `r₁ ≃r s₁` and `r₂ ≃r s₂`, construct a relation isomorphism for the lexicographic orders on the product. -/ def prodLexCongr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂} (e₁ : @RelIso α₁ β₁ r₁ s₁) (e₂ : @RelIso α₂ β₂ r₂ s₂) : Prod.Lex r₁ r₂ ≃r Prod.Lex s₁ s₂ := ⟨Equiv.prodCongr e₁.toEquiv e₂.toEquiv, by simp [Prod.lex_def, e₁.map_rel_iff, e₂.map_rel_iff, e₁.injective.eq_iff]⟩ /-- Two relations on empty types are isomorphic. -/ def relIsoOfIsEmpty (r : α → α → Prop) (s : β → β → Prop) [IsEmpty α] [IsEmpty β] : r ≃r s := ⟨Equiv.equivOfIsEmpty α β, @fun a => isEmptyElim a⟩ /-- The lexicographic sum of `r` plus an empty relation is isomorphic to `r`. -/ @[simps!] def sumLexEmpty (r : α → α → Prop) (s : β → β → Prop) [IsEmpty β] : Sum.Lex r s ≃r r := ⟨Equiv.sumEmpty _ _, by simp⟩ /-- The lexicographic sum of an empty relation plus `s` is isomorphic to `s`. -/ @[simps!] def emptySumLex (r : α → α → Prop) (s : β → β → Prop) [IsEmpty α] : Sum.Lex r s ≃r s := ⟨Equiv.emptySum _ _, by simp⟩ /-- Two irreflexive relations on a unique type are isomorphic. -/ def ofUniqueOfIrrefl (r : α → α → Prop) (s : β → β → Prop) [IsIrrefl α r] [IsIrrefl β s] [Unique α] [Unique β] : r ≃r s := ⟨Equiv.ofUnique α β, iff_of_false (not_rel_of_subsingleton s _ _) (not_rel_of_subsingleton r _ _) ⟩ /-- Two reflexive relations on a unique type are isomorphic. -/ def ofUniqueOfRefl (r : α → α → Prop) (s : β → β → Prop) [IsRefl α r] [IsRefl β s] [Unique α] [Unique β] : r ≃r s := ⟨Equiv.ofUnique α β, iff_of_true (rel_of_subsingleton s _ _) (rel_of_subsingleton r _ _)⟩ end RelIso
.lake/packages/mathlib/Mathlib/Order/RelIso/Set.lean
import Mathlib.Order.Directed import Mathlib.Order.RelIso.Basic import Mathlib.Logic.Embedding.Set import Mathlib.Logic.Equiv.Set /-! # Interactions between relation homomorphisms and sets It is likely that there are better homes for many of these statement, in files further down the import graph. -/ open Function universe u v w variable {α β : Type*} {r : α → α → Prop} {s : β → β → Prop} namespace RelHomClass variable {F : Type*} theorem map_inf [SemilatticeInf α] [LinearOrder β] [FunLike F β α] [RelHomClass F (· < ·) (· < ·)] (a : F) (m n : β) : a (m ⊓ n) = a m ⊓ a n := (StrictMono.monotone fun _ _ => map_rel a).map_inf m n theorem map_sup [SemilatticeSup α] [LinearOrder β] [FunLike F β α] [RelHomClass F (· > ·) (· > ·)] (a : F) (m n : β) : a (m ⊔ n) = a m ⊔ a n := map_inf (α := αᵒᵈ) (β := βᵒᵈ) _ _ _ theorem directed [FunLike F α β] [RelHomClass F r s] {ι : Sort*} {a : ι → α} {f : F} (ha : Directed r a) : Directed s (f ∘ a) := ha.mono_comp _ fun _ _ h ↦ map_rel f h theorem directedOn [FunLike F α β] [RelHomClass F r s] {f : F} {t : Set α} (hs : DirectedOn r t) : DirectedOn s (f '' t) := hs.mono_comp fun _ _ h ↦ map_rel f h end RelHomClass namespace RelIso theorem range_eq (e : r ≃r s) : Set.range e = Set.univ := by simp end RelIso /-- `Subrel r p` is the inherited relation on a subtype. We could also consider a Set.Subrel r s variant for dot notation, but this ends up interacting poorly with `simpNF`. -/ def Subrel (r : α → α → Prop) (p : α → Prop) : Subtype p → Subtype p → Prop := Subtype.val ⁻¹'o r @[simp] theorem subrel_val (r : α → α → Prop) (p : α → Prop) {a b} : Subrel r p a b ↔ r a.1 b.1 := Iff.rfl namespace Subrel /-- The relation embedding from the inherited relation on a subset. -/ protected def relEmbedding (r : α → α → Prop) (p : α → Prop) : Subrel r p ↪r r := ⟨Embedding.subtype _, Iff.rfl⟩ @[simp] theorem relEmbedding_apply (r : α → α → Prop) (p a) : Subrel.relEmbedding r p a = a.1 := rfl /-- `Set.inclusion` as a relation embedding. -/ protected def inclusionEmbedding (r : α → α → Prop) {s t : Set α} (h : s ⊆ t) : Subrel r (· ∈ s) ↪r Subrel r (· ∈ t) where toFun := Set.inclusion h inj' _ _ h := (Set.inclusion_inj _).mp h map_rel_iff' := Iff.rfl @[simp] theorem coe_inclusionEmbedding (r : α → α → Prop) {s t : Set α} (h : s ⊆ t) : (Subrel.inclusionEmbedding r h : s → t) = Set.inclusion h := rfl instance (r : α → α → Prop) [IsRefl α r] (p : α → Prop) : IsRefl _ (Subrel r p) := ⟨fun x => @IsRefl.refl α r _ x⟩ instance (r : α → α → Prop) [IsSymm α r] (p : α → Prop) : IsSymm _ (Subrel r p) := ⟨fun x y => @IsSymm.symm α r _ x y⟩ instance (r : α → α → Prop) [IsAsymm α r] (p : α → Prop) : IsAsymm _ (Subrel r p) := ⟨fun x y => @IsAsymm.asymm α r _ x y⟩ instance (r : α → α → Prop) [IsTrans α r] (p : α → Prop) : IsTrans _ (Subrel r p) := ⟨fun x y z => @IsTrans.trans α r _ x y z⟩ instance (r : α → α → Prop) [IsIrrefl α r] (p : α → Prop) : IsIrrefl _ (Subrel r p) := ⟨fun x => @IsIrrefl.irrefl α r _ x⟩ instance (r : α → α → Prop) [IsTrichotomous α r] (p : α → Prop) : IsTrichotomous _ (Subrel r p) := ⟨fun x y => by rw [Subtype.eq_iff]; exact @IsTrichotomous.trichotomous α r _ x y⟩ instance (r : α → α → Prop) [IsWellFounded α r] (p : α → Prop) : IsWellFounded _ (Subrel r p) := (Subrel.relEmbedding r p).isWellFounded instance (r : α → α → Prop) [IsPreorder α r] (p : α → Prop) : IsPreorder _ (Subrel r p) where instance (r : α → α → Prop) [IsStrictOrder α r] (p : α → Prop) : IsStrictOrder _ (Subrel r p) where instance (r : α → α → Prop) [IsWellOrder α r] (p : α → Prop) : IsWellOrder _ (Subrel r p) where end Subrel /-- If a proposition holds for all elements, then the `Subrel` is equivalent to the original relation. -/ @[simps! apply symm_apply] def RelIso.subrelUnivIso {p : α → Prop} (h : ∀ x, p x) : Subrel r p ≃r r where toEquiv := Equiv.subtypeUnivEquiv h map_rel_iff' := by simp /-- Restrict the codomain of a relation embedding. -/ def RelEmbedding.codRestrict (p : Set β) (f : r ↪r s) (H : ∀ a, f a ∈ p) : r ↪r Subrel s (· ∈ p) := ⟨f.toEmbedding.codRestrict p H, f.map_rel_iff'⟩ @[simp] theorem RelEmbedding.codRestrict_apply (p) (f : r ↪r s) (H a) : RelEmbedding.codRestrict p f H a = ⟨f a, H a⟩ := rfl section image theorem RelIso.image_eq_preimage_symm (e : r ≃r s) (t : Set α) : e '' t = e.symm ⁻¹' t := e.toEquiv.image_eq_preimage_symm t theorem RelIso.preimage_eq_image_symm (e : r ≃r s) (t : Set β) : e ⁻¹' t = e.symm '' t := by rw [e.symm.image_eq_preimage_symm]; rfl end image theorem Acc.of_subrel {r : α → α → Prop} [IsTrans α r] {b : α} (a : { a // r a b }) (h : Acc (Subrel r (r · b)) a) : Acc r a.1 := h.recOn fun a _ IH ↦ ⟨_, fun _ hb ↦ IH ⟨_, _root_.trans hb a.2⟩ hb⟩ /-- A relation `r` is well-founded iff every downward-interval `{ a | r a b }` of it is well-founded. -/ theorem wellFounded_iff_wellFounded_subrel {r : α → α → Prop} [IsTrans α r] : WellFounded r ↔ ∀ b, WellFounded (Subrel r (r · b)) where mp h _ := InvImage.wf Subtype.val h mpr h := ⟨fun a ↦ ⟨_, fun b hr ↦ ((h a).apply _).of_subrel ⟨b, hr⟩⟩⟩
.lake/packages/mathlib/Mathlib/Order/BoundedOrder/Basic.lean
import Mathlib.Order.Max import Mathlib.Order.ULift import Mathlib.Tactic.ByCases import Mathlib.Tactic.Finiteness.Attr import Mathlib.Util.AssertExists /-! # ⊤ and ⊥, bounded lattices and variants This file defines top and bottom elements (greatest and least elements) of a type, the bounded variants of different kinds of lattices, sets up the typeclass hierarchy between them and provides instances for `Prop` and `fun`. ## Main declarations * `<Top/Bot> α`: Typeclasses to declare the `⊤`/`⊥` notation. * `Order<Top/Bot> α`: Order with a top/bottom element. * `BoundedOrder α`: Order with a top and bottom element. -/ assert_not_exists Monotone universe u v variable {α : Type u} {β : Type v} /-! ### Top, bottom element -/ /-- An order is an `OrderTop` if it has a greatest element. We state this using a data mixin, holding the value of `⊤` and the greatest element constraint. -/ class OrderTop (α : Type u) [LE α] extends Top α where /-- `⊤` is the greatest element -/ le_top : ∀ a : α, a ≤ ⊤ section OrderTop /-- An order is (noncomputably) either an `OrderTop` or a `NoTopOrder`. Use as `casesI topOrderOrNoTopOrder α`. -/ noncomputable def topOrderOrNoTopOrder (α : Type*) [LE α] : OrderTop α ⊕' NoTopOrder α := by by_cases! H : ∀ a : α, ∃ b, ¬b ≤ a · exact PSum.inr ⟨H⟩ · letI : Top α := ⟨Classical.choose H⟩ exact PSum.inl ⟨Classical.choose_spec H⟩ section LE variable [LE α] [OrderTop α] {a : α} @[simp] theorem le_top : a ≤ ⊤ := OrderTop.le_top a @[simp] theorem isTop_top : IsTop (⊤ : α) := fun _ => le_top end LE /-- A top element can be replaced with `⊤`. Prefer `IsTop.eq_top` if `α` already has a top element. -/ @[elab_as_elim] protected def IsTop.rec [LE α] {P : (x : α) → IsTop x → Sort*} (h : ∀ [OrderTop α], P ⊤ isTop_top) (x : α) (hx : IsTop x) : P x hx := by letI : OrderTop α := { top := x, le_top := hx } apply h section Preorder variable [Preorder α] [OrderTop α] {a b : α} @[simp] theorem isMax_top : IsMax (⊤ : α) := isTop_top.isMax @[simp] theorem not_top_lt : ¬⊤ < a := isMax_top.not_lt theorem ne_top_of_lt (h : a < b) : a ≠ ⊤ := (h.trans_le le_top).ne alias LT.lt.ne_top := ne_top_of_lt theorem lt_top_of_lt (h : a < b) : a < ⊤ := lt_of_lt_of_le h le_top alias LT.lt.lt_top := lt_top_of_lt attribute [aesop (rule_sets := [finiteness]) unsafe 20%] ne_top_of_lt -- would have been better to implement this as a "safe" "forward" rule, why doesn't this work? -- attribute [aesop (rule_sets := [finiteness]) safe forward] ne_top_of_lt end Preorder variable [PartialOrder α] [OrderTop α] [Preorder β] {f : α → β} {a b : α} @[simp] theorem isMax_iff_eq_top : IsMax a ↔ a = ⊤ := ⟨fun h => h.eq_of_le le_top, fun h _ _ => h.symm ▸ le_top⟩ @[simp] theorem isTop_iff_eq_top : IsTop a ↔ a = ⊤ := ⟨fun h => h.isMax.eq_of_le le_top, fun h _ => h.symm ▸ le_top⟩ theorem not_isMax_iff_ne_top : ¬IsMax a ↔ a ≠ ⊤ := isMax_iff_eq_top.not theorem not_isTop_iff_ne_top : ¬IsTop a ↔ a ≠ ⊤ := isTop_iff_eq_top.not alias ⟨IsMax.eq_top, _⟩ := isMax_iff_eq_top alias ⟨IsTop.eq_top, _⟩ := isTop_iff_eq_top @[simp] theorem top_le_iff : ⊤ ≤ a ↔ a = ⊤ := le_top.ge_iff_eq theorem top_unique (h : ⊤ ≤ a) : a = ⊤ := le_top.antisymm h theorem eq_top_iff : a = ⊤ ↔ ⊤ ≤ a := top_le_iff.symm theorem eq_top_mono (h : a ≤ b) (h₂ : a = ⊤) : b = ⊤ := top_unique <| h₂ ▸ h theorem lt_top_iff_ne_top : a < ⊤ ↔ a ≠ ⊤ := le_top.lt_iff_ne @[simp] theorem not_lt_top_iff : ¬a < ⊤ ↔ a = ⊤ := lt_top_iff_ne_top.not_left theorem eq_top_or_lt_top (a : α) : a = ⊤ ∨ a < ⊤ := le_top.eq_or_lt @[aesop (rule_sets := [finiteness]) safe apply] theorem Ne.lt_top (h : a ≠ ⊤) : a < ⊤ := lt_top_iff_ne_top.mpr h theorem Ne.lt_top' (h : ⊤ ≠ a) : a < ⊤ := h.symm.lt_top theorem ne_top_of_le_ne_top (hb : b ≠ ⊤) (hab : a ≤ b) : a ≠ ⊤ := (hab.trans_lt hb.lt_top).ne lemma top_notMem_iff {s : Set α} : ⊤ ∉ s ↔ ∀ x ∈ s, x < ⊤ := ⟨fun h x hx ↦ Ne.lt_top (fun hx' : x = ⊤ ↦ h (hx' ▸ hx)), fun h h₀ ↦ (h ⊤ h₀).false⟩ @[deprecated (since := "2025-05-23")] alias top_not_mem_iff := top_notMem_iff variable [Nontrivial α] theorem not_isMin_top : ¬IsMin (⊤ : α) := fun h => let ⟨_, ha⟩ := exists_ne (⊤ : α) ha <| top_le_iff.1 <| h le_top end OrderTop theorem OrderTop.ext_top {α} {hA : PartialOrder α} (A : OrderTop α) {hB : PartialOrder α} (B : OrderTop α) (H : ∀ x y : α, (haveI := hA; x ≤ y) ↔ x ≤ y) : (@Top.top α (@OrderTop.toTop α hA.toLE A)) = (@Top.top α (@OrderTop.toTop α hB.toLE B)) := by cases PartialOrder.ext H apply top_unique exact @le_top _ _ A _ /-- An order is an `OrderBot` if it has a least element. We state this using a data mixin, holding the value of `⊥` and the least element constraint. -/ class OrderBot (α : Type u) [LE α] extends Bot α where /-- `⊥` is the least element -/ bot_le : ∀ a : α, ⊥ ≤ a section OrderBot /-- An order is (noncomputably) either an `OrderBot` or a `NoBotOrder`. Use as `casesI botOrderOrNoBotOrder α`. -/ noncomputable def botOrderOrNoBotOrder (α : Type*) [LE α] : OrderBot α ⊕' NoBotOrder α := by by_cases! H : ∀ a : α, ∃ b, ¬a ≤ b · exact PSum.inr ⟨H⟩ · letI : Bot α := ⟨Classical.choose H⟩ exact PSum.inl ⟨Classical.choose_spec H⟩ section LE variable [LE α] [OrderBot α] {a : α} @[simp] theorem bot_le : ⊥ ≤ a := OrderBot.bot_le a @[simp] theorem isBot_bot : IsBot (⊥ : α) := fun _ => bot_le end LE /-- A bottom element can be replaced with `⊥`. Prefer `IsBot.eq_bot` if `α` already has a bottom element. -/ @[elab_as_elim] protected def IsBot.rec [LE α] {P : (x : α) → IsBot x → Sort*} (h : ∀ [OrderBot α], P ⊥ isBot_bot) (x : α) (hx : IsBot x) : P x hx := by letI : OrderBot α := { bot := x, bot_le := hx } apply h namespace OrderDual variable (α) instance instTop [Bot α] : Top αᵒᵈ := ⟨(⊥ : α)⟩ instance instBot [Top α] : Bot αᵒᵈ := ⟨(⊤ : α)⟩ instance instOrderTop [LE α] [OrderBot α] : OrderTop αᵒᵈ where __ := inferInstanceAs (Top αᵒᵈ) le_top := @bot_le α _ _ instance instOrderBot [LE α] [OrderTop α] : OrderBot αᵒᵈ where __ := inferInstanceAs (Bot αᵒᵈ) bot_le := @le_top α _ _ @[simp] theorem ofDual_bot [Top α] : ofDual ⊥ = (⊤ : α) := rfl @[simp] theorem ofDual_top [Bot α] : ofDual ⊤ = (⊥ : α) := rfl @[simp] theorem toDual_bot [Bot α] : toDual (⊥ : α) = ⊤ := rfl @[simp] theorem toDual_top [Top α] : toDual (⊤ : α) = ⊥ := rfl end OrderDual section Preorder variable [Preorder α] [OrderBot α] {a b : α} @[simp] theorem isMin_bot : IsMin (⊥ : α) := isBot_bot.isMin @[simp] theorem not_lt_bot : ¬a < ⊥ := isMin_bot.not_lt theorem ne_bot_of_gt (h : a < b) : b ≠ ⊥ := (bot_le.trans_lt h).ne' alias LT.lt.ne_bot := ne_bot_of_gt theorem bot_lt_of_lt (h : a < b) : ⊥ < b := lt_of_le_of_lt bot_le h alias LT.lt.bot_lt := bot_lt_of_lt end Preorder variable [PartialOrder α] [OrderBot α] [Preorder β] {f : α → β} {a b : α} @[simp] theorem isMin_iff_eq_bot : IsMin a ↔ a = ⊥ := ⟨fun h => h.eq_of_ge bot_le, fun h _ _ => h.symm ▸ bot_le⟩ @[simp] theorem isBot_iff_eq_bot : IsBot a ↔ a = ⊥ := ⟨fun h => h.isMin.eq_of_ge bot_le, fun h _ => h.symm ▸ bot_le⟩ theorem not_isMin_iff_ne_bot : ¬IsMin a ↔ a ≠ ⊥ := isMin_iff_eq_bot.not theorem not_isBot_iff_ne_bot : ¬IsBot a ↔ a ≠ ⊥ := isBot_iff_eq_bot.not alias ⟨IsMin.eq_bot, _⟩ := isMin_iff_eq_bot alias ⟨IsBot.eq_bot, _⟩ := isBot_iff_eq_bot @[simp] theorem le_bot_iff : a ≤ ⊥ ↔ a = ⊥ := bot_le.ge_iff_eq' theorem bot_unique (h : a ≤ ⊥) : a = ⊥ := h.antisymm bot_le theorem eq_bot_iff : a = ⊥ ↔ a ≤ ⊥ := le_bot_iff.symm theorem eq_bot_mono (h : a ≤ b) (h₂ : b = ⊥) : a = ⊥ := bot_unique <| h₂ ▸ h theorem bot_lt_iff_ne_bot : ⊥ < a ↔ a ≠ ⊥ := bot_le.lt_iff_ne.trans ne_comm @[simp] theorem not_bot_lt_iff : ¬⊥ < a ↔ a = ⊥ := bot_lt_iff_ne_bot.not_left theorem eq_bot_or_bot_lt (a : α) : a = ⊥ ∨ ⊥ < a := bot_le.eq_or_lt' theorem eq_bot_of_minimal (h : ∀ b, ¬b < a) : a = ⊥ := (eq_bot_or_bot_lt a).resolve_right (h ⊥) theorem Ne.bot_lt (h : a ≠ ⊥) : ⊥ < a := bot_lt_iff_ne_bot.mpr h theorem Ne.bot_lt' (h : ⊥ ≠ a) : ⊥ < a := h.symm.bot_lt theorem ne_bot_of_le_ne_bot (hb : b ≠ ⊥) (hab : b ≤ a) : a ≠ ⊥ := (hb.bot_lt.trans_le hab).ne' lemma bot_notMem_iff {s : Set α} : ⊥ ∉ s ↔ ∀ x ∈ s, ⊥ < x := top_notMem_iff (α := αᵒᵈ) @[deprecated (since := "2025-05-23")] alias bot_not_mem_iff := bot_notMem_iff variable [Nontrivial α] theorem not_isMax_bot : ¬IsMax (⊥ : α) := @not_isMin_top αᵒᵈ _ _ _ end OrderBot theorem OrderBot.ext_bot {α} {hA : PartialOrder α} (A : OrderBot α) {hB : PartialOrder α} (B : OrderBot α) (H : ∀ x y : α, (haveI := hA; x ≤ y) ↔ x ≤ y) : (@Bot.bot α (@OrderBot.toBot α hA.toLE A)) = (@Bot.bot α (@OrderBot.toBot α hB.toLE B)) := by cases PartialOrder.ext H apply bot_unique exact @bot_le _ _ A _ /-! ### Bounded order -/ /-- A bounded order describes an order `(≤)` with a top and bottom element, denoted `⊤` and `⊥` respectively. -/ class BoundedOrder (α : Type u) [LE α] extends OrderTop α, OrderBot α instance OrderDual.instBoundedOrder (α : Type u) [LE α] [BoundedOrder α] : BoundedOrder αᵒᵈ where __ := inferInstanceAs (OrderTop αᵒᵈ) __ := inferInstanceAs (OrderBot αᵒᵈ) section PartialOrder variable [PartialOrder α] instance OrderBot.instSubsingleton : Subsingleton (OrderBot α) where allEq := by rintro @⟨⟨a⟩, ha⟩ @⟨⟨b⟩, hb⟩; congr; exact le_antisymm (ha _) (hb _) instance OrderTop.instSubsingleton : Subsingleton (OrderTop α) where allEq := by rintro @⟨⟨a⟩, ha⟩ @⟨⟨b⟩, hb⟩; congr; exact le_antisymm (hb _) (ha _) instance BoundedOrder.instSubsingleton : Subsingleton (BoundedOrder α) where allEq := by rintro ⟨⟩ ⟨⟩; congr <;> exact Subsingleton.elim _ _ end PartialOrder /-! ### Function lattices -/ namespace Pi variable {ι : Type*} {α' : ι → Type*} instance [∀ i, Bot (α' i)] : Bot (∀ i, α' i) := ⟨fun _ => ⊥⟩ @[simp] theorem bot_apply [∀ i, Bot (α' i)] (i : ι) : (⊥ : ∀ i, α' i) i = ⊥ := rfl @[push ←] theorem bot_def [∀ i, Bot (α' i)] : (⊥ : ∀ i, α' i) = fun _ => ⊥ := rfl @[simp] theorem bot_comp {α β γ : Type*} [Bot γ] (x : α → β) : (⊥ : β → γ) ∘ x = ⊥ := by rfl instance [∀ i, Top (α' i)] : Top (∀ i, α' i) := ⟨fun _ => ⊤⟩ @[simp] theorem top_apply [∀ i, Top (α' i)] (i : ι) : (⊤ : ∀ i, α' i) i = ⊤ := rfl @[push ←] theorem top_def [∀ i, Top (α' i)] : (⊤ : ∀ i, α' i) = fun _ => ⊤ := rfl @[simp] theorem top_comp {α β γ : Type*} [Top γ] (x : α → β) : (⊤ : β → γ) ∘ x = ⊤ := by rfl instance instOrderTop [∀ i, LE (α' i)] [∀ i, OrderTop (α' i)] : OrderTop (∀ i, α' i) where le_top _ := fun _ => le_top instance instOrderBot [∀ i, LE (α' i)] [∀ i, OrderBot (α' i)] : OrderBot (∀ i, α' i) where bot_le _ := fun _ => bot_le instance instBoundedOrder [∀ i, LE (α' i)] [∀ i, BoundedOrder (α' i)] : BoundedOrder (∀ i, α' i) where __ := inferInstanceAs (OrderTop (∀ i, α' i)) __ := inferInstanceAs (OrderBot (∀ i, α' i)) end Pi section Subsingleton variable [PartialOrder α] [BoundedOrder α] theorem eq_bot_of_bot_eq_top (hα : (⊥ : α) = ⊤) (x : α) : x = (⊥ : α) := eq_bot_mono le_top (Eq.symm hα) theorem eq_top_of_bot_eq_top (hα : (⊥ : α) = ⊤) (x : α) : x = (⊤ : α) := eq_top_mono bot_le hα theorem subsingleton_of_top_le_bot (h : (⊤ : α) ≤ (⊥ : α)) : Subsingleton α := ⟨fun _ _ => le_antisymm (le_trans le_top <| le_trans h bot_le) (le_trans le_top <| le_trans h bot_le)⟩ theorem subsingleton_of_bot_eq_top (hα : (⊥ : α) = (⊤ : α)) : Subsingleton α := subsingleton_of_top_le_bot (ge_of_eq hα) theorem subsingleton_iff_bot_eq_top : (⊥ : α) = (⊤ : α) ↔ Subsingleton α := ⟨subsingleton_of_bot_eq_top, fun _ => Subsingleton.elim ⊥ ⊤⟩ end Subsingleton section lift -- See note [reducible non-instances] /-- Pullback an `OrderTop`. -/ abbrev OrderTop.lift [LE α] [Top α] [LE β] [OrderTop β] (f : α → β) (map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_top : f ⊤ = ⊤) : OrderTop α := ⟨fun a => map_le _ _ <| by rw [map_top] exact le_top _⟩ -- See note [reducible non-instances] /-- Pullback an `OrderBot`. -/ abbrev OrderBot.lift [LE α] [Bot α] [LE β] [OrderBot β] (f : α → β) (map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_bot : f ⊥ = ⊥) : OrderBot α := ⟨fun a => map_le _ _ <| by rw [map_bot] exact bot_le _⟩ -- See note [reducible non-instances] /-- Pullback a `BoundedOrder`. -/ abbrev BoundedOrder.lift [LE α] [Top α] [Bot α] [LE β] [BoundedOrder β] (f : α → β) (map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) : BoundedOrder α where __ := OrderTop.lift f map_le map_top __ := OrderBot.lift f map_le map_bot end lift /-! ### Subtype, order dual, product lattices -/ namespace Subtype variable {p : α → Prop} -- See note [reducible non-instances] /-- A subtype remains a `⊥`-order if the property holds at `⊥`. -/ protected abbrev orderBot [LE α] [OrderBot α] (hbot : p ⊥) : OrderBot { x : α // p x } where bot := ⟨⊥, hbot⟩ bot_le _ := bot_le -- See note [reducible non-instances] /-- A subtype remains a `⊤`-order if the property holds at `⊤`. -/ protected abbrev orderTop [LE α] [OrderTop α] (htop : p ⊤) : OrderTop { x : α // p x } where top := ⟨⊤, htop⟩ le_top _ := le_top -- See note [reducible non-instances] /-- A subtype remains a bounded order if the property holds at `⊥` and `⊤`. -/ protected abbrev boundedOrder [LE α] [BoundedOrder α] (hbot : p ⊥) (htop : p ⊤) : BoundedOrder (Subtype p) where __ := Subtype.orderTop htop __ := Subtype.orderBot hbot variable [PartialOrder α] @[simp] theorem mk_bot [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) : mk ⊥ hbot = ⊥ := le_bot_iff.1 <| coe_le_coe.1 bot_le @[simp] theorem mk_top [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) : mk ⊤ htop = ⊤ := top_le_iff.1 <| coe_le_coe.1 le_top theorem coe_bot [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) : ((⊥ : Subtype p) : α) = ⊥ := congr_arg Subtype.val (mk_bot hbot).symm theorem coe_top [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) : ((⊤ : Subtype p) : α) = ⊤ := congr_arg Subtype.val (mk_top htop).symm @[simp] theorem coe_eq_bot_iff [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) {x : { x // p x }} : (x : α) = ⊥ ↔ x = ⊥ := by rw [← coe_bot hbot, Subtype.ext_iff] @[simp] theorem coe_eq_top_iff [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) {x : { x // p x }} : (x : α) = ⊤ ↔ x = ⊤ := by rw [← coe_top htop, Subtype.ext_iff] @[simp] theorem mk_eq_bot_iff [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) {x : α} (hx : p x) : (⟨x, hx⟩ : Subtype p) = ⊥ ↔ x = ⊥ := (coe_eq_bot_iff hbot).symm @[simp] theorem mk_eq_top_iff [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) {x : α} (hx : p x) : (⟨x, hx⟩ : Subtype p) = ⊤ ↔ x = ⊤ := (coe_eq_top_iff htop).symm end Subtype namespace Prod variable (α β) instance instTop [Top α] [Top β] : Top (α × β) := ⟨⟨⊤, ⊤⟩⟩ instance instBot [Bot α] [Bot β] : Bot (α × β) := ⟨⟨⊥, ⊥⟩⟩ @[simp] lemma fst_top [Top α] [Top β] : (⊤ : α × β).fst = ⊤ := rfl @[simp] lemma snd_top [Top α] [Top β] : (⊤ : α × β).snd = ⊤ := rfl @[simp] lemma fst_bot [Bot α] [Bot β] : (⊥ : α × β).fst = ⊥ := rfl @[simp] lemma snd_bot [Bot α] [Bot β] : (⊥ : α × β).snd = ⊥ := rfl instance instOrderTop [LE α] [LE β] [OrderTop α] [OrderTop β] : OrderTop (α × β) where __ := inferInstanceAs (Top (α × β)) le_top _ := ⟨le_top, le_top⟩ instance instOrderBot [LE α] [LE β] [OrderBot α] [OrderBot β] : OrderBot (α × β) where __ := inferInstanceAs (Bot (α × β)) bot_le _ := ⟨bot_le, bot_le⟩ instance instBoundedOrder [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] : BoundedOrder (α × β) where __ := inferInstanceAs (OrderTop (α × β)) __ := inferInstanceAs (OrderBot (α × β)) end Prod namespace ULift instance [Top α] : Top (ULift.{v} α) where top := up ⊤ @[simp] theorem up_top [Top α] : up (⊤ : α) = ⊤ := rfl @[simp] theorem down_top [Top α] : down (⊤ : ULift α) = ⊤ := rfl instance [Bot α] : Bot (ULift.{v} α) where bot := up ⊥ @[simp] theorem up_bot [Bot α] : up (⊥ : α) = ⊥ := rfl @[simp] theorem down_bot [Bot α] : down (⊥ : ULift α) = ⊥ := rfl instance [LE α] [OrderBot α] : OrderBot (ULift.{v} α) := OrderBot.lift ULift.down (fun _ _ => down_le.mp) down_bot instance [LE α] [OrderTop α] : OrderTop (ULift.{v} α) := OrderTop.lift ULift.down (fun _ _ => down_le.mp) down_top instance [LE α] [BoundedOrder α] : BoundedOrder (ULift.{v} α) where end ULift section Nontrivial variable [PartialOrder α] [BoundedOrder α] [Nontrivial α] @[simp] theorem bot_ne_top : (⊥ : α) ≠ ⊤ := fun h => not_subsingleton _ <| subsingleton_of_bot_eq_top h @[simp] theorem top_ne_bot : (⊤ : α) ≠ ⊥ := bot_ne_top.symm @[simp] theorem bot_lt_top : (⊥ : α) < ⊤ := lt_top_iff_ne_top.2 bot_ne_top end Nontrivial section Bool open Bool instance Bool.instBoundedOrder : BoundedOrder Bool where top := true le_top := Bool.le_true bot := false bot_le := Bool.false_le @[simp] theorem top_eq_true : ⊤ = true := rfl @[simp] theorem bot_eq_false : ⊥ = false := rfl end Bool
.lake/packages/mathlib/Mathlib/Order/BoundedOrder/Monotone.lean
import Mathlib.Order.BoundedOrder.Basic import Mathlib.Order.Monotone.Basic /-! # Monotone functions on bounded orders -/ assert_not_exists SemilatticeSup open Function OrderDual universe u v variable {α : Type u} {β : Type v} /-! ### Top, bottom element -/ section OrderTop variable [PartialOrder α] [OrderTop α] [Preorder β] {f : α → β} {a b : α} theorem StrictMono.apply_eq_top_iff (hf : StrictMono f) : f a = f ⊤ ↔ a = ⊤ := ⟨fun h => not_lt_top_iff.1 fun ha => (hf ha).ne h, congr_arg _⟩ theorem StrictAnti.apply_eq_top_iff (hf : StrictAnti f) : f a = f ⊤ ↔ a = ⊤ := ⟨fun h => not_lt_top_iff.1 fun ha => (hf ha).ne' h, congr_arg _⟩ end OrderTop theorem StrictMono.maximal_preimage_top [LinearOrder α] [Preorder β] [OrderTop β] {f : α → β} (H : StrictMono f) {a} (h_top : f a = ⊤) (x : α) : x ≤ a := H.maximal_of_maximal_image (fun p => by rw [h_top] exact le_top) x section OrderBot variable [PartialOrder α] [OrderBot α] [Preorder β] {f : α → β} {a b : α} theorem StrictMono.apply_eq_bot_iff (hf : StrictMono f) : f a = f ⊥ ↔ a = ⊥ := hf.dual.apply_eq_top_iff theorem StrictAnti.apply_eq_bot_iff (hf : StrictAnti f) : f a = f ⊥ ↔ a = ⊥ := hf.dual.apply_eq_top_iff end OrderBot theorem StrictMono.minimal_preimage_bot [LinearOrder α] [Preorder β] [OrderBot β] {f : α → β} (H : StrictMono f) {a} (h_bot : f a = ⊥) (x : α) : a ≤ x := H.minimal_of_minimal_image (fun p => by rw [h_bot] exact bot_le) x section Logic /-! #### In this section we prove some properties about monotone and antitone operations on `Prop` -/ section Preorder variable [Preorder α] theorem monotone_and {p q : α → Prop} (m_p : Monotone p) (m_q : Monotone q) : Monotone fun x => p x ∧ q x := fun _ _ h => And.imp (m_p h) (m_q h) -- Note: by finish [monotone] doesn't work theorem monotone_or {p q : α → Prop} (m_p : Monotone p) (m_q : Monotone q) : Monotone fun x => p x ∨ q x := fun _ _ h => Or.imp (m_p h) (m_q h) theorem monotone_le {x : α} : Monotone (x ≤ ·) := fun _ _ h' h => h.trans h' theorem monotone_lt {x : α} : Monotone (x < ·) := fun _ _ h' h => h.trans_le h' theorem antitone_le {x : α} : Antitone (· ≤ x) := fun _ _ h' h => h'.trans h theorem antitone_lt {x : α} : Antitone (· < x) := fun _ _ h' h => h'.trans_lt h theorem Monotone.forall {P : β → α → Prop} (hP : ∀ x, Monotone (P x)) : Monotone fun y => ∀ x, P x y := fun _ _ hy h x => hP x hy <| h x theorem Antitone.forall {P : β → α → Prop} (hP : ∀ x, Antitone (P x)) : Antitone fun y => ∀ x, P x y := fun _ _ hy h x => hP x hy (h x) theorem Monotone.ball {P : β → α → Prop} {s : Set β} (hP : ∀ x ∈ s, Monotone (P x)) : Monotone fun y => ∀ x ∈ s, P x y := fun _ _ hy h x hx => hP x hx hy (h x hx) theorem Antitone.ball {P : β → α → Prop} {s : Set β} (hP : ∀ x ∈ s, Antitone (P x)) : Antitone fun y => ∀ x ∈ s, P x y := fun _ _ hy h x hx => hP x hx hy (h x hx) theorem Monotone.exists {P : β → α → Prop} (hP : ∀ x, Monotone (P x)) : Monotone fun y => ∃ x, P x y := fun _ _ hy ⟨x, hx⟩ ↦ ⟨x, hP x hy hx⟩ theorem Antitone.exists {P : β → α → Prop} (hP : ∀ x, Antitone (P x)) : Antitone fun y => ∃ x, P x y := fun _ _ hy ⟨x, hx⟩ ↦ ⟨x, hP x hy hx⟩ theorem forall_ge_iff {P : α → Prop} {x₀ : α} (hP : Monotone P) : (∀ x ≥ x₀, P x) ↔ P x₀ := ⟨fun H ↦ H x₀ le_rfl, fun H _ hx ↦ hP hx H⟩ theorem forall_le_iff {P : α → Prop} {x₀ : α} (hP : Antitone P) : (∀ x ≤ x₀, P x) ↔ P x₀ := ⟨fun H ↦ H x₀ le_rfl, fun H _ hx ↦ hP hx H⟩ end Preorder end Logic
.lake/packages/mathlib/Mathlib/Order/BoundedOrder/Lattice.lean
import Mathlib.Order.BoundedOrder.Basic import Mathlib.Order.Lattice /-! # Bounded lattices This file defines top and bottom elements (greatest and least elements) of a type, the bounded variants of different kinds of lattices, sets up the typeclass hierarchy between them, and provides instances for `Prop` and `fun`. ## Common lattices * Distributive lattices with a bottom element. Notated by `[DistribLattice α] [OrderBot α]`. It captures the properties of `Disjoint` that are common to `GeneralizedBooleanAlgebra` and `DistribLattice` when `OrderBot`. * Bounded and distributive lattice. Notated by `[DistribLattice α] [BoundedOrder α]`. Typical examples include `Prop` and `Set α`. -/ open Function OrderDual universe u v variable {α : Type u} {β : Type v} /-! ### Top, bottom element -/ section SemilatticeSupTop variable [SemilatticeSup α] [OrderTop α] theorem top_sup_eq (a : α) : ⊤ ⊔ a = ⊤ := sup_of_le_left le_top theorem sup_top_eq (a : α) : a ⊔ ⊤ = ⊤ := sup_of_le_right le_top end SemilatticeSupTop section SemilatticeSupBot variable [SemilatticeSup α] [OrderBot α] {a b : α} theorem bot_sup_eq (a : α) : ⊥ ⊔ a = a := sup_of_le_right bot_le theorem sup_bot_eq (a : α) : a ⊔ ⊥ = a := sup_of_le_left bot_le @[simp] theorem sup_eq_bot_iff : a ⊔ b = ⊥ ↔ a = ⊥ ∧ b = ⊥ := by rw [eq_bot_iff, sup_le_iff]; simp end SemilatticeSupBot section SemilatticeInfTop variable [SemilatticeInf α] [OrderTop α] {a b : α} lemma top_inf_eq (a : α) : ⊤ ⊓ a = a := inf_of_le_right le_top lemma inf_top_eq (a : α) : a ⊓ ⊤ = a := inf_of_le_left le_top @[simp] theorem inf_eq_top_iff : a ⊓ b = ⊤ ↔ a = ⊤ ∧ b = ⊤ := @sup_eq_bot_iff αᵒᵈ _ _ _ _ end SemilatticeInfTop section SemilatticeInfBot variable [SemilatticeInf α] [OrderBot α] lemma bot_inf_eq (a : α) : ⊥ ⊓ a = ⊥ := inf_of_le_left bot_le lemma inf_bot_eq (a : α) : a ⊓ ⊥ = ⊥ := inf_of_le_right bot_le end SemilatticeInfBot section Logic /-! #### In this section we prove some properties about monotone and antitone operations on `Prop` -/ section SemilatticeSup variable [SemilatticeSup α] theorem exists_ge_and_iff_exists {P : α → Prop} {x₀ : α} (hP : Monotone P) : (∃ x, x₀ ≤ x ∧ P x) ↔ ∃ x, P x := ⟨fun h => h.imp fun _ h => h.2, fun ⟨x, hx⟩ => ⟨x ⊔ x₀, le_sup_right, hP le_sup_left hx⟩⟩ lemma exists_and_iff_of_monotone {P Q : α → Prop} (hP : Monotone P) (hQ : Monotone Q) : ((∃ x, P x) ∧ ∃ x, Q x) ↔ (∃ x, P x ∧ Q x) := ⟨fun ⟨⟨x, hPx⟩, ⟨y, hQx⟩⟩ ↦ ⟨x ⊔ y, ⟨hP le_sup_left hPx, hQ le_sup_right hQx⟩⟩, fun ⟨x, hPx, hQx⟩ ↦ ⟨⟨x, hPx⟩, ⟨x, hQx⟩⟩⟩ end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] theorem exists_le_and_iff_exists {P : α → Prop} {x₀ : α} (hP : Antitone P) : (∃ x, x ≤ x₀ ∧ P x) ↔ ∃ x, P x := exists_ge_and_iff_exists <| hP.dual_left lemma exists_and_iff_of_antitone {P Q : α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ x, P x) ∧ ∃ x, Q x) ↔ (∃ x, P x ∧ Q x) := ⟨fun ⟨⟨x, hPx⟩, ⟨y, hQx⟩⟩ ↦ ⟨x ⊓ y, ⟨hP inf_le_left hPx, hQ inf_le_right hQx⟩⟩, fun ⟨x, hPx, hQx⟩ ↦ ⟨⟨x, hPx⟩, ⟨x, hQx⟩⟩⟩ end SemilatticeInf end Logic section LinearOrder variable [LinearOrder α] -- `simp` can prove these, so they shouldn't be simp-lemmas. theorem min_bot_left [OrderBot α] (a : α) : min ⊥ a = ⊥ := bot_inf_eq _ theorem max_top_left [OrderTop α] (a : α) : max ⊤ a = ⊤ := top_sup_eq _ theorem min_top_left [OrderTop α] (a : α) : min ⊤ a = a := top_inf_eq _ theorem max_bot_left [OrderBot α] (a : α) : max ⊥ a = a := bot_sup_eq _ theorem min_top_right [OrderTop α] (a : α) : min a ⊤ = a := inf_top_eq _ theorem max_bot_right [OrderBot α] (a : α) : max a ⊥ = a := sup_bot_eq _ theorem min_bot_right [OrderBot α] (a : α) : min a ⊥ = ⊥ := inf_bot_eq _ theorem max_top_right [OrderTop α] (a : α) : max a ⊤ = ⊤ := sup_top_eq _ theorem max_eq_bot [OrderBot α] {a b : α} : max a b = ⊥ ↔ a = ⊥ ∧ b = ⊥ := sup_eq_bot_iff theorem min_eq_top [OrderTop α] {a b : α} : min a b = ⊤ ↔ a = ⊤ ∧ b = ⊤ := inf_eq_top_iff @[simp] theorem min_eq_bot [OrderBot α] {a b : α} : min a b = ⊥ ↔ a = ⊥ ∨ b = ⊥ := by simp_rw [← le_bot_iff, inf_le_iff] @[simp] theorem max_eq_top [OrderTop α] {a b : α} : max a b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := @min_eq_bot αᵒᵈ _ _ a b @[aesop (rule_sets := [finiteness]) safe apply] lemma max_ne_top [OrderTop α] {a b : α} (ha : a ≠ ⊤) (hb : b ≠ ⊤) : max a b ≠ ⊤ := by grind [max_eq_top] end LinearOrder /-! ### Induction on `WellFoundedGT` and `WellFoundedLT` -/ section WellFounded @[elab_as_elim] theorem WellFoundedGT.induction_top [Preorder α] [WellFoundedGT α] [OrderTop α] {P : α → Prop} (hexists : ∃ M, P M) (hind : ∀ N ≠ ⊤, P N → ∃ M > N, P M) : P ⊤ := by contrapose! hexists intro M induction M using WellFoundedGT.induction with | ind x IH => by_cases hx : x = ⊤ · exact hx ▸ hexists · intro hx' obtain ⟨M, hM, hM'⟩ := hind x hx hx' exact IH _ hM hM' @[elab_as_elim] theorem WellFoundedLT.induction_bot [Preorder α] [WellFoundedLT α] [OrderBot α] {P : α → Prop} (hexists : ∃ M, P M) (hind : ∀ N ≠ ⊥, P N → ∃ M < N, P M) : P ⊥ := by contrapose! hexists intro M induction M using WellFoundedLT.induction with | ind x IH => by_cases hx : x = ⊥ · exact hx ▸ hexists · intro hx' obtain ⟨M, hM, hM'⟩ := hind x hx hx' exact IH _ hM hM' end WellFounded
.lake/packages/mathlib/Mathlib/Order/BooleanAlgebra/Basic.lean
import Mathlib.Order.BooleanAlgebra.Defs /-! # Basic properties of Boolean algebras This file provides some basic definitions, functions as well as lemmas for functions and type classes related to Boolean algebras as defined in `Mathlib/Order/BooleanAlgebra/Defs.lean`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ universe u v variable {α : Type u} {β : Type*} {x y z : α} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] @[simp] theorem sup_inf_sdiff (x y : α) : x ⊓ y ⊔ x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ @[simp] theorem inf_inf_sdiff (x y : α) : x ⊓ y ⊓ x \ y = ⊥ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ @[simp] theorem sup_sdiff_inf (x y : α) : x \ y ⊔ x ⊓ y = x := by rw [sup_comm, sup_inf_sdiff] @[simp] theorem inf_sdiff_inf (x y : α) : x \ y ⊓ (x ⊓ y) = ⊥ := by rw [inf_comm, inf_inf_sdiff] -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot α where __ := GeneralizedBooleanAlgebra.toBot bot_le a := by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left theorem disjoint_inf_sdiff : Disjoint (x ⊓ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x ⊓ y ⊔ z = x) (i : x ⊓ y ⊓ z = ⊥) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≤ x := calc x \ y ≤ x ⊓ y ⊔ x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x ⊔ x = y ⊔ x := calc y \ x ⊔ x = y \ x ⊔ (x ⊔ x ⊓ y) := by rw [sup_inf_self] _ = y ⊓ x ⊔ y \ x ⊔ x := by ac_rfl _ = y ⊔ x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y ⊓ y \ x = ⊥ := Eq.symm <| calc ⊥ = x ⊓ (y ⊓ x ⊔ y \ x) ⊓ x \ y := by rw [← inf_inf_sdiff, sup_inf_sdiff] _ = (x ⊓ (y ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_sup_left] _ = (y ⊓ (x ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by ac_rfl _ = x ⊓ y \ x ⊓ x \ y := by rw [inf_idem, inf_sup_right, ← inf_comm x y, inf_inf_sdiff, bot_sup_eq] _ = x ⊓ x \ y ⊓ y \ x := by ac_rfl _ = x \ y ⊓ y \ x := by rw [inf_of_le_right sdiff_le'] theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le @[simp] theorem inf_sdiff_self_right : x ⊓ y \ x = ⊥ := calc x ⊓ y \ x = (x ⊓ y ⊔ x \ y) ⊓ y \ x := by rw [sup_inf_sdiff] _ = ⊥ := by rw [inf_sup_right, inf_comm x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] @[simp] theorem inf_sdiff_self_left : y \ x ⊓ x = ⊥ := by rw [inf_comm, inf_sdiff_self_right] -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra α where __ := ‹GeneralizedBooleanAlgebra α› __ := GeneralizedBooleanAlgebra.toOrderBot sdiff := (· \ ·) sdiff_le_iff y x z := ⟨fun h => le_of_inf_le_sup_le (le_of_eq (by grind [sdiff_le', inf_of_le_right, inf_eq_right, inf_sdiff_self_right, bot_sup_eq, inf_sup_right])) (calc y ⊔ y \ x ≤ y \ x ⊔ x ⊔ z := by grind [sup_of_le_left, sdiff_le', le_sup_left, sup_assoc, sdiff_sup_self'] _ = x ⊔ z ⊔ y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (inf_sdiff_self_left.trans_le bot_le) (calc y \ x ⊔ x = y ⊔ x := sdiff_sup_self' _ ≤ x ⊔ z ⊔ x := sup_le_sup_right h x _ ≤ z ⊔ x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le lemma le_sdiff : x ≤ y \ z ↔ x ≤ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x ⊔ (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x ⊔ z = y) : y \ x = z := have h : y ⊓ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≤ y) (hs : y ≤ x ⊔ z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, sup_comm x, inf_sup_self, inf_comm, sup_comm z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≤ y) (hx : x ≤ y) : Disjoint z (y \ x) ↔ z ≤ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] grw [sdiff_le] rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≤ y) (hx : x ≤ y) : z ≤ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≤ y) (hx : x ≤ y) : z ⊓ y \ x = ⊥ ↔ z ≤ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≤ y) (hx : x ≤ y) : x ≤ z ↔ y = z ⊔ y \ x := ⟨fun H => by apply le_antisymm · conv_lhs => rw [← sup_inf_sdiff y x] gcongr rwa [inf_eq_right.2 hx] · grw [hz] rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine le_of_inf_le_sup_le ?_ H.le rw [inf_sdiff_self_right] exact bot_le⟩ -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x ⊔ z) = y \ x ⊓ y \ z := sdiff_unique (calc y ⊓ (x ⊔ z) ⊔ y \ x ⊓ y \ z = (y ⊓ x ⊔ y ⊓ z ⊔ y \ x) ⊓ (y ⊓ x ⊔ y ⊓ z ⊔ y \ z) := by rw [sup_inf_left, inf_sup_left y] _ = (y ⊓ z ⊔ (y ⊓ x ⊔ y \ x)) ⊓ (y ⊓ x ⊔ (y ⊓ z ⊔ y \ z)) := by ac_rfl _ = (y ⊓ z ⊔ y) ⊓ (y ⊓ x ⊔ y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y ⊔ y ⊓ z) ⊓ (y ⊔ y ⊓ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y ⊓ (x ⊔ z) ⊓ (y \ x ⊓ y \ z) = y ⊓ x ⊓ (y \ x ⊓ y \ z) ⊔ y ⊓ z ⊓ (y \ x ⊓ y \ z) := by rw [inf_sup_left, inf_sup_right] _ = y ⊓ x ⊓ y \ x ⊓ y \ z ⊔ y \ x ⊓ (y \ z ⊓ (y ⊓ z)) := by ac_rfl _ = ⊥ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, inf_comm (y \ z), inf_inf_sdiff, inf_bot_eq]) theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y ⊓ x = y ⊓ z := ⟨fun h => eq_of_inf_eq_sup_eq (a := y \ x) (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := sdiff_eq_left.trans disjoint_comm @[deprecated (since := "2025-10-12")] alias sdiff_eq_self_iff_disjoint' := sdiff_eq_left theorem sdiff_lt (hx : y ≤ x) (hy : y ≠ ⊥) : x \ y < x := by refine sdiff_le.lt_of_ne fun h => hy ?_ rw [sdiff_eq_left, disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] theorem sdiff_lt_left : x \ y < x ↔ ¬ Disjoint y x := by rw [lt_iff_le_and_ne, Ne, sdiff_eq_self_iff_disjoint, and_iff_right sdiff_le] @[simp] theorem le_sdiff_right : x ≤ y \ x ↔ x = ⊥ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ @[simp] lemma sdiff_eq_right : x \ y = y ↔ x = ⊥ ∧ y = ⊥ := by rw [disjoint_sdiff_self_left.eq_iff]; simp_all lemma sdiff_ne_right : x \ y ≠ y ↔ x ≠ ⊥ ∨ y ≠ ⊥ := sdiff_eq_right.not.trans not_and_or theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≤ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_ge fun h' => h.not_ge <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz theorem sup_inf_inf_sdiff : x ⊓ y ⊓ z ⊔ y \ z = x ⊓ y ⊔ y \ z := by rw [inf_assoc, sup_inf_right, sup_inf_sdiff, inf_sup_right, inf_sdiff_left] theorem sdiff_sdiff_right : x \ (y \ z) = x \ y ⊔ x ⊓ y ⊓ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique · calc x ⊓ y \ z ⊔ (z ⊓ x ⊔ x \ y) = (x ⊔ (z ⊓ x ⊔ x \ y)) ⊓ (y \ z ⊔ (z ⊓ x ⊔ x \ y)) := by rw [sup_inf_right] _ = (x ⊔ x ⊓ z ⊔ x \ y) ⊓ (y \ z ⊔ (x ⊓ z ⊔ x \ y)) := by ac_rfl _ = x ⊓ (y \ z ⊔ (x ⊓ z ⊔ x ⊓ y) ⊔ x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc, sup_inf_left, sdiff_sup_self', inf_sup_right, sup_comm y, inf_sdiff_sup_right, inf_sup_left x z y] _ = x ⊓ (y \ z ⊔ (x ⊓ z ⊔ (x ⊓ y ⊔ x \ y))) := by ac_rfl _ = x := by rw [sup_inf_sdiff, sup_comm (x ⊓ z), sup_inf_self, sup_comm, inf_sup_self] · calc x ⊓ y \ z ⊓ (z ⊓ x ⊔ x \ y) = x ⊓ y \ z ⊓ (z ⊓ x) ⊔ x ⊓ y \ z ⊓ x \ y := by rw [inf_sup_left] _ = x ⊓ (y \ z ⊓ z ⊓ x) ⊔ x ⊓ y \ z ⊓ x \ y := by ac_rfl _ = x ⊓ y \ z ⊓ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x ⊓ (y \ z ⊓ y) ⊓ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x ⊓ (y \ z ⊓ (y ⊓ x \ y)) := by ac_rfl _ = ⊥ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y ⊔ x ⊓ z := calc x \ (y \ z) = x \ y ⊔ x ⊓ y ⊓ z := sdiff_sdiff_right _ = z ⊓ x ⊓ y ⊔ x \ y := by ac_rfl _ = x \ y ⊔ x ⊓ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm] theorem sdiff_sdiff_eq_sdiff_sup (h : z ≤ x) : x \ (y \ z) = x \ y ⊔ z := by rw [sdiff_sdiff_right', inf_eq_right.2 h] @[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x ⊓ y := by rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq] theorem sdiff_sdiff_eq_self (h : y ≤ x) : x \ (x \ y) = y := by rw [sdiff_sdiff_right_self, inf_of_le_right h] theorem sdiff_eq_symm (hy : y ≤ x) (h : x \ y = z) : x \ z = y := by rw [← h, sdiff_sdiff_eq_self hy] theorem sdiff_eq_comm (hy : y ≤ x) (hz : z ≤ x) : x \ y = z ↔ x \ z = y := ⟨sdiff_eq_symm hy, sdiff_eq_symm hz⟩ theorem eq_of_sdiff_eq_sdiff (hxz : x ≤ z) (hyz : y ≤ z) (h : z \ x = z \ y) : x = y := by rw [← sdiff_sdiff_eq_self hxz, h, sdiff_sdiff_eq_self hyz] theorem sdiff_le_sdiff_iff_le (hx : x ≤ z) (hy : y ≤ z) : z \ x ≤ z \ y ↔ y ≤ x := by refine ⟨fun h ↦ ?_, sdiff_le_sdiff_left⟩ rw [← sdiff_sdiff_eq_self hx, ← sdiff_sdiff_eq_self hy] exact sdiff_le_sdiff_left h theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y ⊓ x \ z := by rw [sdiff_sdiff_left, sdiff_sup] theorem sdiff_sdiff_sup_sdiff : z \ (x \ y ⊔ y \ x) = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) := calc z \ (x \ y ⊔ y \ x) = z ⊓ (z \ x ⊔ y) ⊓ (z ⊓ (z \ y ⊔ x)) := by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right, sup_inf_left, sup_comm, sup_inf_sdiff, sup_inf_left, sup_comm (z \ y), sup_inf_sdiff] _ = z ⊓ z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) := by ac_rfl _ = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) := by rw [inf_idem] theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y ⊔ y \ x) = z ⊓ x ⊓ y ⊔ z \ x ⊓ z \ y := calc z \ (x \ y ⊔ y \ x) = z \ (x \ y) ⊓ z \ (y \ x) := sdiff_sup _ = (z \ x ⊔ z ⊓ x ⊓ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right] _ = (z \ x ⊔ z ⊓ y ⊓ x) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) := by ac_rfl _ = z \ x ⊓ z \ y ⊔ z ⊓ y ⊓ x := by rw [← sup_inf_right] _ = z ⊓ x ⊓ y ⊔ z \ x ⊓ z \ y := by ac_rfl lemma sdiff_sdiff_sdiff_cancel_left (hca : z ≤ x) : (x \ y) \ (x \ z) = z \ y := sdiff_sdiff_sdiff_le_sdiff.antisymm <| (disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca lemma sdiff_sdiff_sdiff_cancel_right (hcb : z ≤ y) : (x \ z) \ (y \ z) = x \ y := by rw [le_antisymm_iff, sdiff_le_comm] exact ⟨sdiff_sdiff_sdiff_le_sdiff, (disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcb⟩ theorem inf_sdiff : (x ⊓ y) \ z = x \ z ⊓ y \ z := sdiff_unique (calc _ = (x ⊓ y ⊓ (z ⊔ x) ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) := by rw [sup_inf_left, sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right] _ = (y ⊓ (x ⊓ (x ⊔ z)) ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) := by ac_rfl _ = x ⊓ y ⊔ x \ z ⊓ y \ z := by rw [inf_sup_self, sup_inf_inf_sdiff, inf_comm y, sup_inf_left] _ = x ⊓ y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le)) (calc x ⊓ y ⊓ z ⊓ (x \ z ⊓ y \ z) = x ⊓ y ⊓ (z ⊓ x \ z) ⊓ y \ z := by ac_rfl _ = ⊥ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq]) /-- See also `sdiff_inf_right_comm`. -/ theorem inf_sdiff_assoc (x y z : α) : (x ⊓ y) \ z = x ⊓ y \ z := sdiff_unique (by rw [inf_assoc, ← inf_sup_left, sup_inf_sdiff]) <| calc x ⊓ y ⊓ z ⊓ (x ⊓ y \ z) = x ⊓ x ⊓ (y ⊓ z ⊓ y \ z) := by ac_rfl _ = ⊥ := by rw [inf_inf_sdiff, inf_bot_eq] /-- See also `inf_sdiff_assoc`. -/ theorem sdiff_inf_right_comm (x y z : α) : x \ z ⊓ y = (x ⊓ y) \ z := by rw [inf_comm x, inf_comm, inf_sdiff_assoc] lemma inf_sdiff_left_comm (a b c : α) : a ⊓ (b \ c) = b ⊓ (a \ c) := by simp_rw [← inf_sdiff_assoc, inf_comm] theorem inf_sdiff_distrib_left (a b c : α) : a ⊓ b \ c = (a ⊓ b) \ (a ⊓ c) := by rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc] theorem inf_sdiff_distrib_right (a b c : α) : a \ b ⊓ c = (a ⊓ c) \ (b ⊓ c) := by simp_rw [inf_comm _ c, inf_sdiff_distrib_left] theorem disjoint_sdiff_comm : Disjoint (x \ z) y ↔ Disjoint x (y \ z) := by simp_rw [disjoint_iff, sdiff_inf_right_comm, inf_sdiff_assoc] theorem sup_eq_sdiff_sup_sdiff_sup_inf : x ⊔ y = x \ y ⊔ y \ x ⊔ x ⊓ y := Eq.symm <| calc x \ y ⊔ y \ x ⊔ x ⊓ y = (x \ y ⊔ y \ x ⊔ x) ⊓ (x \ y ⊔ y \ x ⊔ y) := by rw [sup_inf_left] _ = (x \ y ⊔ x ⊔ y \ x) ⊓ (x \ y ⊔ (y \ x ⊔ y)) := by ac_rfl _ = x ⊔ y := by simp theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x ≤ z) : x ⊔ y < z := by rw [← sup_sdiff_cancel_right hxz] refine (sup_le_sup_left h.le _).lt_of_not_ge fun h' => h.not_ge ?_ rw [← sdiff_idem] exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y ≤ z) : x ⊔ y < z := by rw [← sdiff_sup_cancel hyz] refine lt_of_le_not_ge (by grw [h]) fun h' => h.not_ge ?_ rw [← sdiff_idem] exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra β] : GeneralizedBooleanAlgebra (α × β) where sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _) inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _) -- Porting note: Once `pi_instance` has been ported, this is just `by pi_instance`. instance Pi.instGeneralizedBooleanAlgebra {ι : Type*} {α : ι → Type*} [∀ i, GeneralizedBooleanAlgebra (α i)] : GeneralizedBooleanAlgebra (∀ i, α i) where sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a) inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a) end GeneralizedBooleanAlgebra /-! ### Boolean algebras -/ -- See note [reducible non-instances] /-- A bounded generalized Boolean algebra is a Boolean algebra. -/ abbrev GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra α] [OrderTop α] : BooleanAlgebra α where __ := ‹GeneralizedBooleanAlgebra α› __ := GeneralizedBooleanAlgebra.toOrderBot __ := ‹OrderTop α› compl a := ⊤ \ a inf_compl_le_bot _ := disjoint_sdiff_self_right.le_bot top_le_sup_compl _ := le_sup_sdiff sdiff_eq a b := by change _ = a ⊓ (⊤ \ b) rw [← inf_sdiff_assoc, inf_top_eq] section BooleanAlgebra variable [BooleanAlgebra α] theorem inf_compl_eq_bot' : x ⊓ xᶜ = ⊥ := bot_unique <| BooleanAlgebra.inf_compl_le_bot x @[simp] theorem sup_compl_eq_top : x ⊔ xᶜ = ⊤ := top_unique <| BooleanAlgebra.top_le_sup_compl x @[simp] theorem compl_sup_eq_top : xᶜ ⊔ x = ⊤ := by rw [sup_comm, sup_compl_eq_top] theorem isCompl_compl : IsCompl x xᶜ := IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top theorem sdiff_eq : x \ y = x ⊓ yᶜ := BooleanAlgebra.sdiff_eq x y theorem himp_eq : x ⇨ y = y ⊔ xᶜ := BooleanAlgebra.himp_eq x y instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice α := ⟨fun x => ⟨xᶜ, isCompl_compl⟩⟩ -- see Note [lower instance priority] instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra : GeneralizedBooleanAlgebra α where __ := ‹BooleanAlgebra α› sup_inf_sdiff a b := by rw [sdiff_eq, ← inf_sup_left, sup_compl_eq_top, inf_top_eq] inf_inf_sdiff a b := by rw [sdiff_eq, ← inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] -- See note [lower instance priority] instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra α where __ := ‹BooleanAlgebra α› __ := GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra hnot := compl le_himp_iff a b c := by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le] himp_bot _ := _root_.himp_eq.trans (bot_sup_eq _) top_sdiff a := by rw [sdiff_eq, top_inf_eq] @[simp] theorem hnot_eq_compl : ¬x = xᶜ := rfl /- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/ theorem top_sdiff : ⊤ \ x = xᶜ := top_sdiff' x theorem eq_compl_iff_isCompl : x = yᶜ ↔ IsCompl x y := ⟨fun h => by rw [h] exact isCompl_compl.symm, IsCompl.eq_compl⟩ theorem compl_eq_iff_isCompl : xᶜ = y ↔ IsCompl x y := ⟨fun h => by rw [← h] exact isCompl_compl, IsCompl.compl_eq⟩ theorem compl_eq_comm : xᶜ = y ↔ yᶜ = x := by rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl] theorem eq_compl_comm : x = yᶜ ↔ y = xᶜ := by rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl] @[simp] theorem compl_compl (x : α) : xᶜᶜ = x := (@isCompl_compl _ x _).symm.compl_eq theorem compl_comp_compl : compl ∘ compl = @id α := funext compl_compl @[simp] theorem compl_involutive : Function.Involutive (compl : α → α) := compl_compl theorem compl_bijective : Function.Bijective (compl : α → α) := compl_involutive.bijective theorem compl_surjective : Function.Surjective (compl : α → α) := compl_involutive.surjective theorem compl_injective : Function.Injective (compl : α → α) := compl_involutive.injective @[simp] theorem compl_inj_iff : xᶜ = yᶜ ↔ x = y := compl_injective.eq_iff theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zᶜ = y ↔ z = x := h.compl_eq ▸ compl_inj_iff @[simp] theorem compl_eq_top : xᶜ = ⊤ ↔ x = ⊥ := isCompl_bot_top.compl_eq_iff @[simp] theorem compl_eq_bot : xᶜ = ⊥ ↔ x = ⊤ := isCompl_top_bot.compl_eq_iff @[simp] theorem compl_inf : (x ⊓ y)ᶜ = xᶜ ⊔ yᶜ := hnot_inf_distrib _ _ @[simp] theorem compl_le_compl_iff_le : yᶜ ≤ xᶜ ↔ x ≤ y := ⟨fun h => by have h := compl_le_compl h; simpa using h, compl_le_compl⟩ @[simp] lemma compl_lt_compl_iff_lt : yᶜ < xᶜ ↔ x < y := lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le theorem compl_le_of_compl_le (h : yᶜ ≤ x) : xᶜ ≤ y := by simpa only [compl_compl] using compl_le_compl h theorem compl_le_iff_compl_le : xᶜ ≤ y ↔ yᶜ ≤ x := ⟨compl_le_of_compl_le, compl_le_of_compl_le⟩ @[simp] theorem compl_le_self : xᶜ ≤ x ↔ x = ⊤ := by simpa using le_compl_self (a := xᶜ) @[simp] theorem compl_lt_self [Nontrivial α] : xᶜ < x ↔ x = ⊤ := by simpa using lt_compl_self (a := xᶜ) @[simp] theorem sdiff_compl : x \ yᶜ = x ⊓ y := by rw [sdiff_eq, compl_compl] instance OrderDual.instBooleanAlgebra : BooleanAlgebra αᵒᵈ where __ := instDistribLattice α __ := instHeytingAlgebra sdiff_eq _ _ := @himp_eq α _ _ _ himp_eq _ _ := @sdiff_eq α _ _ _ inf_compl_le_bot a := (@codisjoint_hnot_right _ _ (ofDual a)).top_le top_le_sup_compl a := (@disjoint_compl_right _ _ (ofDual a)).le_bot @[simp] theorem sup_inf_inf_compl : x ⊓ y ⊔ x ⊓ yᶜ = x := by rw [← sdiff_eq, sup_inf_sdiff _ _] theorem compl_sdiff : (x \ y)ᶜ = x ⇨ y := by rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm] @[simp] theorem compl_himp : (x ⇨ y)ᶜ = x \ y := @compl_sdiff αᵒᵈ _ _ _ theorem compl_sdiff_compl : xᶜ \ yᶜ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm] @[simp] theorem compl_himp_compl : xᶜ ⇨ yᶜ = y ⇨ x := @compl_sdiff_compl αᵒᵈ _ _ _ theorem disjoint_compl_left_iff : Disjoint xᶜ y ↔ y ≤ x := by rw [← le_compl_iff_disjoint_left, compl_compl] theorem disjoint_compl_right_iff : Disjoint x yᶜ ↔ x ≤ y := by rw [← le_compl_iff_disjoint_right, compl_compl] theorem codisjoint_himp_self_left : Codisjoint (x ⇨ y) x := @disjoint_sdiff_self_left αᵒᵈ _ _ _ theorem codisjoint_himp_self_right : Codisjoint x (x ⇨ y) := @disjoint_sdiff_self_right αᵒᵈ _ _ _ theorem himp_le : x ⇨ y ≤ z ↔ y ≤ z ∧ Codisjoint x z := (@le_sdiff αᵒᵈ _ _ _ _).trans <| and_congr_right' <| @codisjoint_comm _ (_) _ _ _ @[simp] lemma himp_le_left : x ⇨ y ≤ x ↔ x = ⊤ := ⟨fun h ↦ codisjoint_self.1 <| codisjoint_himp_self_right.mono_right h, fun h ↦ le_top.trans h.ge⟩ @[simp] lemma himp_eq_left : x ⇨ y = x ↔ x = ⊤ ∧ y = ⊤ := by rw [codisjoint_himp_self_left.eq_iff]; aesop lemma himp_ne_right : x ⇨ y ≠ x ↔ x ≠ ⊤ ∨ y ≠ ⊤ := himp_eq_left.not.trans not_and_or lemma codisjoint_iff_compl_le_left : Codisjoint x y ↔ yᶜ ≤ x := hnot_le_iff_codisjoint_left.symm lemma codisjoint_iff_compl_le_right : Codisjoint x y ↔ xᶜ ≤ y := hnot_le_iff_codisjoint_right.symm end BooleanAlgebra instance Prod.instBooleanAlgebra [BooleanAlgebra α] [BooleanAlgebra β] : BooleanAlgebra (α × β) where __ := instDistribLattice α β __ := instHeytingAlgebra himp_eq x y := by ext <;> simp [himp_eq] sdiff_eq x y := by ext <;> simp [sdiff_eq] inf_compl_le_bot x := by constructor <;> simp top_le_sup_compl x := by constructor <;> simp instance Pi.instBooleanAlgebra {ι : Type u} {α : ι → Type v} [∀ i, BooleanAlgebra (α i)] : BooleanAlgebra (∀ i, α i) where __ := instDistribLattice __ := instHeytingAlgebra sdiff_eq _ _ := funext fun _ => sdiff_eq himp_eq _ _ := funext fun _ => himp_eq inf_compl_le_bot _ _ := BooleanAlgebra.inf_compl_le_bot _ top_le_sup_compl _ _ := BooleanAlgebra.top_le_sup_compl _ section lift -- See note [reducible non-instances] /-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/ protected abbrev Function.Injective.generalizedBooleanAlgebra [Max α] [Min α] [Bot α] [SDiff α] [GeneralizedBooleanAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_bot : f ⊥ = ⊥) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : GeneralizedBooleanAlgebra α where __ := hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff __ := hf.distribLattice f map_sup map_inf sup_inf_sdiff a b := hf <| by rw [map_sup, map_sdiff, map_inf, sup_inf_sdiff] inf_inf_sdiff a b := hf <| by rw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] -- See note [reducible non-instances] /-- Pullback a `BooleanAlgebra` along an injection. -/ protected abbrev Function.Injective.booleanAlgebra [Max α] [Min α] [Top α] [Bot α] [HasCompl α] [SDiff α] [HImp α] [BooleanAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : BooleanAlgebra α where __ := hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff le_top _ := (@le_top β _ _ _).trans map_top.ge bot_le _ := map_bot.le.trans bot_le inf_compl_le_bot a := ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le top_le_sup_compl a := ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge sdiff_eq a b := hf <| (map_sdiff _ _).trans <| sdiff_eq.trans <| by rw [map_inf, map_compl] himp_eq a b := hf <| (map_himp _ _).trans <| himp_eq.trans <| by rw [map_sup, map_compl] end lift
.lake/packages/mathlib/Mathlib/Order/BooleanAlgebra/Defs.lean
import Mathlib.Order.Heyting.Basic /-! # (Generalized) Boolean algebras This file sets up the theory of (generalized) Boolean algebras. A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊤`) (and hence not all elements may have complements). One example in mathlib is `Finset α`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `α`. `GeneralizedBooleanAlgebra α` is defined to be a distributive lattice with bottom (`⊥`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[⊥, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : α` where `a ≤ b`, the equations `x ⊔ a = b` and `x ⊓ a = ⊥` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ assert_not_exists RelIso open Function OrderDual universe u v variable {α : Type u} {β : Type*} {x y z : α} /-! ### Generalized Boolean algebras -/ /-- A generalized Boolean algebra is a distributive lattice with `⊥` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a ⊓ b) ⊔ (a \ b) = a` and `(a ⊓ b) ⊓ (a \ b) = ⊥`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset α` for arbitrary (not-necessarily-`Fintype`) `α`. -/ class GeneralizedBooleanAlgebra (α : Type u) extends DistribLattice α, SDiff α, Bot α where /-- For any `a`, `b`, `(a ⊓ b) ⊔ (a / b) = a` -/ sup_inf_sdiff : ∀ a b : α, a ⊓ b ⊔ a \ b = a /-- For any `a`, `b`, `(a ⊓ b) ⊓ (a / b) = ⊥` -/ inf_inf_sdiff : ∀ a b : α, a ⊓ b ⊓ a \ b = ⊥ /-! ### Boolean algebras -/ /-- A Boolean algebra is a bounded distributive lattice with a complement operator `ᶜ` such that `x ⊓ xᶜ = ⊥` and `x ⊔ xᶜ = ⊤`. For convenience, it must also provide a set difference operation `\` and a Heyting implication `⇨` satisfying `x \ y = x ⊓ yᶜ` and `x ⇨ y = y ⊔ xᶜ`. This is a generalization of (classical) logic of propositions, or the powerset lattice. Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE` to be present at define-time, the `extends` mechanism does not work with them. Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided. -/ class BooleanAlgebra (α : Type u) extends DistribLattice α, HasCompl α, SDiff α, HImp α, Top α, Bot α where /-- The infimum of `x` and `xᶜ` is at most `⊥` -/ inf_compl_le_bot : ∀ x : α, x ⊓ xᶜ ≤ ⊥ /-- The supremum of `x` and `xᶜ` is at least `⊤` -/ top_le_sup_compl : ∀ x : α, ⊤ ≤ x ⊔ xᶜ /-- `⊤` is the greatest element -/ le_top : ∀ a : α, a ≤ ⊤ /-- `⊥` is the least element -/ bot_le : ∀ a : α, ⊥ ≤ a /-- `x \ y` is equal to `x ⊓ yᶜ` -/ sdiff := fun x y => x ⊓ yᶜ /-- `x ⇨ y` is equal to `y ⊔ xᶜ` -/ himp := fun x y => y ⊔ xᶜ /-- `x \ y` is equal to `x ⊓ yᶜ` -/ sdiff_eq : ∀ x y : α, x \ y = x ⊓ yᶜ := by aesop /-- `x ⇨ y` is equal to `y ⊔ xᶜ` -/ himp_eq : ∀ x y : α, x ⇨ y = y ⊔ xᶜ := by aesop -- see Note [lower instance priority] instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra α] : BoundedOrder α := { h with } instance Prop.instBooleanAlgebra : BooleanAlgebra Prop where __ := Prop.instHeytingAlgebra __ := GeneralizedHeytingAlgebra.toDistribLattice compl := Not himp_eq _ _ := propext imp_iff_or_not inf_compl_le_bot _ H := H.2 H.1 top_le_sup_compl p _ := Classical.em p instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where __ := instBoundedOrder compl := not inf_compl_le_bot a := a.and_not_self.le top_le_sup_compl a := a.or_not_self.ge theorem Bool.sup_eq_bor : (· ⊔ ·) = or := by dsimp theorem Bool.inf_eq_band : (· ⊓ ·) = and := by dsimp @[simp] theorem Bool.compl_eq_bnot : HasCompl.compl = not := rfl instance PUnit.instBooleanAlgebra : BooleanAlgebra PUnit where __ := PUnit.instBiheytingAlgebra le_sup_inf := by simp inf_compl_le_bot _ := trivial top_le_sup_compl _ := trivial namespace DistribLattice variable (α) [DistribLattice α] /-- An alternative constructor for Boolean algebras: a distributive lattice that is complemented is a Boolean algebra. This is not an instance, because it creates data using choice. -/ noncomputable def booleanAlgebraOfComplemented [BoundedOrder α] [ComplementedLattice α] : BooleanAlgebra α where __ := (inferInstanceAs (BoundedOrder α)) compl a := Classical.choose <| exists_isCompl a inf_compl_le_bot a := (Classical.choose_spec (exists_isCompl a)).disjoint.le_bot top_le_sup_compl a := (Classical.choose_spec (exists_isCompl a)).codisjoint.top_le end DistribLattice
.lake/packages/mathlib/Mathlib/Order/BooleanAlgebra/Set.lean
import Mathlib.Data.Set.Insert import Mathlib.Order.BooleanAlgebra.Basic /-! # Boolean algebra of sets This file proves that `Set α` is a Boolean algebra, and proves results about set difference and complement. ## Notation * `sᶜ` for the complement of `s` ## Tags set, sets, subset, subsets, complement -/ assert_not_exists RelIso open Function namespace Set variable {α β : Type*} {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α} instance instBooleanAlgebra : BooleanAlgebra (Set α) where __ : DistribLattice (Set α) := inferInstance __ : BooleanAlgebra (α → Prop) := inferInstance compl := (·ᶜ) sdiff := (· \ ·) /-- See also `Set.sdiff_inter_right_comm`. -/ lemma inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc .. /-- See also `Set.inter_diff_assoc`. -/ lemma sdiff_inter_right_comm (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm .. lemma inter_sdiff_left_comm (s t u : Set α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm .. theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut /-- A version of `diff_union_diff_cancel` with more general hypotheses. -/ theorem diff_union_diff_cancel' (hi : s ∩ u ⊆ t) (hu : t ⊆ s ∪ u) : (s \ t) ∪ (t \ u) = s \ u := sdiff_sup_sdiff_cancel' hi hu theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ theorem inter_diff_distrib_right (s t u : Set α) : (s \ t) ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ theorem diff_inter_distrib_right (s t r : Set α) : (t ∩ r) \ s = (t \ s) ∩ (r \ s) := inf_sdiff /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl theorem notMem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h @[deprecated (since := "2025-05-23")] alias not_mem_of_mem_compl := notMem_of_mem_compl theorem notMem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not @[deprecated (since := "2025-05-23")] alias not_mem_compl_iff := notMem_compl_iff @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm lemma inl_compl_union_inr_compl {s : Set α} {t : Set β} : Sum.inl '' sᶜ ∪ Sum.inr '' tᶜ = (Sum.inl '' s ∪ Sum.inr '' t)ᶜ := by rw [compl_union] aesop theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_notMem s).symm theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp).symm lemma subset_compl_iff_disjoint_left : s ⊆ tᶜ ↔ Disjoint t s := le_compl_iff_disjoint_left lemma subset_compl_iff_disjoint_right : s ⊆ tᶜ ↔ Disjoint s t := le_compl_iff_disjoint_right lemma disjoint_compl_left_iff_subset : Disjoint sᶜ t ↔ t ⊆ s := disjoint_compl_left_iff lemma disjoint_compl_right_iff_subset : Disjoint s tᶜ ↔ s ⊆ t := disjoint_compl_right_iff alias ⟨_, _root_.Disjoint.subset_compl_right⟩ := subset_compl_iff_disjoint_right alias ⟨_, _root_.Disjoint.subset_compl_left⟩ := subset_compl_iff_disjoint_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_left⟩ := disjoint_compl_left_iff_subset alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_right⟩ := disjoint_compl_right_iff_subset @[simp] lemma nonempty_compl_of_nontrivial [Nontrivial α] (x : α) : Set.Nonempty {x}ᶜ := exists_ne x lemma mem_compl_singleton_iff : a ∈ ({b} : Set α)ᶜ ↔ a ≠ b := .rfl lemma compl_singleton_eq (a : α) : {a}ᶜ = {x | x ≠ a} := rfl @[simp] lemma compl_ne_eq_singleton (a : α) : {x | x ≠ a}ᶜ = {a} := compl_compl _ @[simp] lemma subset_compl_singleton_iff : s ⊆ {a}ᶜ ↔ a ∉ s := subset_compl_comm.trans singleton_subset_iff /-! ### Lemmas about set difference -/ theorem notMem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx @[deprecated (since := "2025-05-23")] alias not_mem_diff_of_mem := notMem_diff_of_mem theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left theorem notMem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right @[deprecated (since := "2025-05-23")] alias not_mem_of_mem_diff := notMem_of_mem_diff theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] theorem diff_nonempty {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ theorem subset_inter_union_compl_left (s t : Set α) : t ⊆ s ∩ t ∪ sᶜ := by simp [inter_union_distrib_right] theorem subset_inter_union_compl_right (s t : Set α) : s ⊆ s ∩ t ∪ tᶜ := by simp [inter_union_distrib_right] theorem union_inter_compl_left_subset (s t : Set α) : (s ∪ t) ∩ sᶜ ⊆ t := by simp [union_inter_distrib_right] theorem union_inter_compl_right_subset (s t : Set α) : (s ∪ t) ∩ tᶜ ⊆ s := by simp [union_inter_distrib_right] @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› theorem diff_subset_diff_iff_subset {r : Set α} (hs : s ⊆ r) (ht : t ⊆ r) : r \ s ⊆ r \ t ↔ t ⊆ s := sdiff_le_sdiff_iff_le hs ht theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf theorem diff_inter_diff : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl theorem compl_diff : (t \ s)ᶜ = s ∪ tᶜ := Eq.trans compl_sdiff himp_eq theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' theorem inter_diff_right_comm : (s ∩ t) \ u = s \ u ∩ t := by rw [diff_eq, diff_eq, inter_right_comm] theorem diff_inter_right_comm : (s \ u) ∩ t = (s ∩ t) \ u := by rw [diff_eq, diff_eq, inter_right_comm] @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf @[simp] lemma sdiff_sep_self (s : Set α) (p : α → Prop) : s \ {a ∈ s | p a} = {a ∈ s | ¬ p a} := diff_self_inter lemma disjoint_sdiff_left : Disjoint (t \ s) s := disjoint_sdiff_self_left lemma disjoint_sdiff_right : Disjoint s (t \ s) := disjoint_sdiff_self_right -- TODO: prove this in terms of a Boolean algebra lemma lemma disjoint_sdiff_inter : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right disjoint_sdiff_left lemma subset_diff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff lemma disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) : Disjoint s t ↔ s = ∅ := disjoint_of_le_iff_left_eq_bot h @[simp] lemma diff_ssubset_left_iff : s \ t ⊂ s ↔ (s ∩ t).Nonempty := sdiff_lt_left.trans <| by rw [not_disjoint_iff_nonempty_inter, inter_comm] lemma _root_.HasSubset.Subset.diff_ssubset_of_nonempty (hst : s ⊆ t) (hs : s.Nonempty) : t \ s ⊂ t := by simpa [inter_eq_self_of_subset_right hst] lemma ssubset_iff_sdiff_singleton : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t \ {a} := by simp [ssubset_iff_insert, subset_diff, insert_subset_iff]; aesop @[simp] lemma diff_singleton_subset_iff : s \ {a} ⊆ t ↔ s ⊆ insert a t := by rw [← union_singleton, union_comm] apply diff_subset_iff lemma subset_diff_singleton (h : s ⊆ t) (ha : a ∉ s) : s ⊆ t \ {a} := subset_inter h <| subset_compl_comm.1 <| singleton_subset_iff.2 ha lemma subset_insert_diff_singleton (x : α) (s : Set α) : s ⊆ insert x (s \ {x}) := by rw [← diff_singleton_subset_iff] lemma diff_insert_of_notMem (h : a ∉ s) : s \ insert a t = s \ t := by grind @[deprecated (since := "2025-05-23")] alias diff_insert_of_not_mem := diff_insert_of_notMem @[simp] lemma insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t := by grind lemma insert_diff_of_notMem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) := by grind @[deprecated (since := "2025-05-23")] alias insert_diff_of_not_mem := insert_diff_of_notMem lemma insert_diff_self_of_notMem (h : a ∉ s) : insert a s \ {a} = s := by ext x; simp [and_iff_left_of_imp (ne_of_mem_of_not_mem · h)] @[deprecated (since := "2025-05-23")] alias insert_diff_self_of_not_mem := insert_diff_self_of_notMem @[simp] lemma insert_diff_self_of_mem (ha : a ∈ s) : insert a (s \ {a}) = s := by ext; simp +contextual [or_and_left, em, ha] lemma insert_diff_subset : insert a s \ t ⊆ insert a (s \ t) := by rintro b ⟨rfl | hbs, hbt⟩ <;> simp [*] lemma insert_erase_invOn : InvOn (insert a) (fun s ↦ s \ {a}) {s : Set α | a ∈ s} {s : Set α | a ∉ s} := ⟨fun _s ha ↦ insert_diff_self_of_mem ha, fun _s ↦ insert_diff_self_of_notMem⟩ @[simp] lemma diff_singleton_eq_self (h : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [h] lemma diff_singleton_ssubset : s \ {a} ⊂ s ↔ a ∈ s := by simp @[simp] lemma insert_diff_singleton : insert a (s \ {a}) = insert a s := by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union] lemma insert_diff_singleton_comm (hab : a ≠ b) (s : Set α) : insert a (s \ {b}) = insert a s \ {b} := by simp_rw [← union_singleton, union_diff_distrib, diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)] @[simp] lemma insert_diff_insert : insert a (s \ insert a t) = insert a (s \ t) := by rw [← union_singleton (s := t), ← diff_diff, insert_diff_singleton] lemma mem_diff_singleton : a ∈ s \ {b} ↔ a ∈ s ∧ a ≠ b := .rfl lemma mem_diff_singleton_empty {t : Set (Set α)} : s ∈ t \ {∅} ↔ s ∈ t ∧ s.Nonempty := mem_diff_singleton.trans <| and_congr_right' nonempty_iff_ne_empty.symm lemma subset_insert_iff : s ⊆ insert a t ↔ s ⊆ t ∨ (a ∈ s ∧ s \ {a} ⊆ t) := by grind lemma pair_diff_left (hab : a ≠ b) : ({a, b} : Set α) \ {a} = {b} := by rw [insert_diff_of_mem _ (mem_singleton a), diff_singleton_eq_self (by simpa)] lemma pair_diff_right (hab : a ≠ b) : ({a, b} : Set α) \ {b} = {a} := by rw [pair_comm, pair_diff_left hab.symm] /-! ### If-then-else for sets -/ /-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`. Defined as `s ∩ t ∪ s' \ t`. -/ protected def ite (t s s' : Set α) : Set α := s ∩ t ∪ s' \ t @[simp] theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty] @[simp] theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq] @[simp] theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by rw [← ite_compl, ite_inter_self] @[simp] theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t := ite_inter_compl_self t s s' @[simp] theorem ite_same (t s : Set α) : t.ite s s = s := inter_union_diff _ _ @[simp] theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite] @[simp] theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite] @[simp] theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite] @[simp] theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite] @[simp] theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite] @[simp] theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite] theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') : t.ite s₁ s₁' ⊆ t.ite s₂ s₂' := union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h') theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' := union_subset_union inter_subset_left diff_subset theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' := ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) : t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by ext x simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union] tauto theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by rw [ite_inter_inter, ite_same] theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) : t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same] theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by simp only [subset_def, ← forall_and] refine forall_congr' fun x => ?_ by_cases hx : x ∈ t <;> simp [*, Set.ite] theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) : t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by ext x by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)] theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) : t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by ext x by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)] end Set
.lake/packages/mathlib/Mathlib/Order/ConditionallyCompleteLattice/Group.lean
import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Algebra.Order.Group.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual /-! # Conditionally complete lattices and groups. -/ open Set section Mul variable {α : Type*} {ι : Sort*} [Nonempty ι] [ConditionallyCompleteLattice α] [Mul α] @[to_additive] lemma ciSup_mul_le_ciSup_mul_ciSup [MulLeftMono α] [MulRightMono α] {f g : ι → α} (hf : BddAbove (range f)) (hg : BddAbove (range g)) : ⨆ i, f i * g i ≤ (⨆ i, f i) * ⨆ i, g i := ciSup_le fun i ↦ mul_le_mul' (le_ciSup hf i) (le_ciSup hg i) @[to_additive] lemma ciInf_mul_ciInf_le_ciInf_mul [MulLeftMono α] [MulRightMono α] {f g : ι → α} (hf : BddBelow (range f)) (hg : BddBelow (range g)) : (⨅ i, f i) * ⨅ i, g i ≤ ⨅ i, f i * g i := le_ciInf fun i ↦ mul_le_mul' (ciInf_le hf i) (ciInf_le hg i) end Mul section Group variable {α : Type*} {ι : Sort*} {ι' : Sort*} [Nonempty ι] [Nonempty ι'] [ConditionallyCompleteLattice α] [Group α] @[to_additive] theorem le_mul_ciInf [MulLeftMono α] {a : α} {g : α} {h : ι → α} (H : ∀ j, a ≤ g * h j) : a ≤ g * iInf h := inv_mul_le_iff_le_mul.mp <| le_ciInf fun _ => inv_mul_le_iff_le_mul.mpr <| H _ @[to_additive] theorem mul_ciSup_le [MulLeftMono α] {a : α} {g : α} {h : ι → α} (H : ∀ j, g * h j ≤ a) : g * iSup h ≤ a := le_mul_ciInf (α := αᵒᵈ) H @[to_additive] theorem le_ciInf_mul [MulRightMono α] {a : α} {g : ι → α} {h : α} (H : ∀ i, a ≤ g i * h) : a ≤ iInf g * h := mul_inv_le_iff_le_mul.mp <| le_ciInf fun _ => mul_inv_le_iff_le_mul.mpr <| H _ @[to_additive] theorem ciSup_mul_le [MulRightMono α] {a : α} {g : ι → α} {h : α} (H : ∀ i, g i * h ≤ a) : iSup g * h ≤ a := le_ciInf_mul (α := αᵒᵈ) H @[to_additive] theorem le_ciInf_mul_ciInf [MulLeftMono α] [MulRightMono α] {a : α} {g : ι → α} {h : ι' → α} (H : ∀ i j, a ≤ g i * h j) : a ≤ iInf g * iInf h := le_ciInf_mul fun _ => le_mul_ciInf <| H _ @[to_additive] theorem ciSup_mul_ciSup_le [MulLeftMono α] [MulRightMono α] {a : α} {g : ι → α} {h : ι' → α} (H : ∀ i j, g i * h j ≤ a) : iSup g * iSup h ≤ a := ciSup_mul_le fun _ => mul_ciSup_le <| H _ end Group
.lake/packages/mathlib/Mathlib/Order/ConditionallyCompleteLattice/Finset.lean
import Mathlib.Data.Finset.Max import Mathlib.Data.Set.Finite.Lattice import Mathlib.Order.ConditionallyCompleteLattice.Indexed /-! # Conditionally complete lattices and finite sets. -/ open Set variable {ι α β γ : Type*} section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] {s t : Set α} {a b : α} theorem Finset.Nonempty.csSup_eq_max' {s : Finset α} (h : s.Nonempty) : sSup ↑s = s.max' h := eq_of_forall_ge_iff fun _ => (csSup_le_iff s.bddAbove h.to_set).trans (s.max'_le_iff h).symm theorem Finset.Nonempty.csInf_eq_min' {s : Finset α} (h : s.Nonempty) : sInf ↑s = s.min' h := @Finset.Nonempty.csSup_eq_max' αᵒᵈ _ s h theorem Finset.Nonempty.csSup_mem {s : Finset α} (h : s.Nonempty) : sSup (s : Set α) ∈ s := by rw [h.csSup_eq_max'] exact s.max'_mem _ theorem Finset.Nonempty.csInf_mem {s : Finset α} (h : s.Nonempty) : sInf (s : Set α) ∈ s := @Finset.Nonempty.csSup_mem αᵒᵈ _ _ h theorem Set.Nonempty.csSup_mem (h : s.Nonempty) (hs : s.Finite) : sSup s ∈ s := by lift s to Finset α using hs exact Finset.Nonempty.csSup_mem h theorem Set.Nonempty.csInf_mem (h : s.Nonempty) (hs : s.Finite) : sInf s ∈ s := @Set.Nonempty.csSup_mem αᵒᵈ _ _ h hs theorem Set.Finite.csSup_lt_iff (hs : s.Finite) (h : s.Nonempty) : sSup s < a ↔ ∀ x ∈ s, x < a := ⟨fun h _ hx => (le_csSup hs.bddAbove hx).trans_lt h, fun H => H _ <| h.csSup_mem hs⟩ theorem Set.Finite.lt_csInf_iff (hs : s.Finite) (h : s.Nonempty) : a < sInf s ↔ ∀ x ∈ s, a < x := @Set.Finite.csSup_lt_iff αᵒᵈ _ _ _ hs h variable (f : ι → α) theorem Finset.ciSup_eq_max'_image {s : Finset ι} (h : ∃ x ∈ s, sSup ∅ ≤ f x) (h' : (s.image f).Nonempty := by classical exact image_nonempty.mpr (h.imp fun _ ↦ And.left)) : ⨆ i ∈ s, f i = (s.image f).max' h' := by classical rw [iSup, ← h'.csSup_eq_max', coe_image] refine csSup_eq_csSup_of_forall_exists_le ?_ ?_ · simp only [ciSup_eq_ite, dite_eq_ite, Set.mem_range, Set.mem_image, mem_coe, exists_exists_and_eq_and, forall_exists_index, forall_apply_eq_imp_iff] intro i split_ifs · exact ⟨_, by assumption, le_rfl⟩ · assumption · simp only [Set.mem_image, mem_coe, ciSup_eq_ite, dite_eq_ite, Set.mem_range, exists_exists_eq_and, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro i hi refine ⟨i, ?_⟩ simp [hi] theorem Finset.ciInf_eq_min'_image {s : Finset ι} (h : ∃ x ∈ s, f x ≤ sInf ∅) (h' : (s.image f).Nonempty := by classical exact image_nonempty.mpr (h.imp fun _ ↦ And.left)) : ⨅ i ∈ s, f i = (s.image f).min' h' := by classical rw [← OrderDual.toDual_inj, toDual_min', toDual_iInf] simp only [toDual_iInf] rw [ciSup_eq_max'_image _ h] simp only [image_image] congr theorem Finset.ciSup_mem_image {s : Finset ι} (h : ∃ x ∈ s, sSup ∅ ≤ f x) : ⨆ i ∈ s, f i ∈ s.image f := by rw [ciSup_eq_max'_image _ h] exact max'_mem (image f s) _ theorem Finset.ciInf_mem_image {s : Finset ι} (h : ∃ x ∈ s, f x ≤ sInf ∅) : ⨅ i ∈ s, f i ∈ s.image f := by rw [ciInf_eq_min'_image _ h] exact min'_mem (image f s) _ theorem Set.Finite.ciSup_mem_image {s : Set ι} (hs : s.Finite) (h : ∃ x ∈ s, sSup ∅ ≤ f x) : ⨆ i ∈ s, f i ∈ f '' s := by lift s to Finset ι using hs simp only [Finset.mem_coe] at h simpa using Finset.ciSup_mem_image f h theorem Set.Finite.ciInf_mem_image {s : Set ι} (hs : s.Finite) (h : ∃ x ∈ s, f x ≤ sInf ∅) : ⨅ i ∈ s, f i ∈ f '' s := by lift s to Finset ι using hs simp only [Finset.mem_coe] at h simpa using Finset.ciInf_mem_image f h theorem Set.Finite.ciSup_lt_iff {s : Set ι} {f : ι → α} (hs : s.Finite) (h : ∃ x ∈ s, sSup ∅ ≤ f x) : ⨆ i ∈ s, f i < a ↔ ∀ x ∈ s, f x < a := by constructor · intro h x hx refine h.trans_le' (le_csSup ?_ ?_) · classical refine (((hs.image f).union (finite_singleton (sSup ∅))).subset ?_).bddAbove intro simp only [ciSup_eq_ite, dite_eq_ite, mem_range, union_singleton, mem_insert_iff, mem_image, forall_exists_index] grind · simp only [mem_range] refine ⟨x, ?_⟩ simp [hx] · have := hs.ciSup_mem_image _ h grind theorem Set.Finite.lt_ciInf_iff {s : Set ι} {f : ι → α} (hs : s.Finite) (h : ∃ x ∈ s, f x ≤ sInf ∅) : a < ⨅ i ∈ s, f i ↔ ∀ x ∈ s, a < f x := by constructor · intro h x hx refine h.trans_le (csInf_le ?_ ?_) · classical refine (((hs.image f).union (finite_singleton (sInf ∅))).subset ?_).bddBelow intro simp only [ciInf_eq_ite, dite_eq_ite, mem_range, union_singleton, mem_insert_iff, mem_image, forall_exists_index] grind · simp only [mem_range] refine ⟨x, ?_⟩ simp [hx] · intro H have := hs.ciInf_mem_image _ h simp only [mem_image] at this obtain ⟨_, hmem, hx⟩ := this rw [← hx] exact H _ hmem section ListMultiset lemma List.iSup_mem_map_of_exists_sSup_empty_le {l : List ι} (f : ι → α) (h : ∃ x ∈ l, sSup ∅ ≤ f x) : ⨆ x ∈ l, f x ∈ l.map f := by classical simpa using l.toFinset.ciSup_mem_image f (by simpa using h) lemma List.iInf_mem_map_of_exists_le_sInf_empty {l : List ι} (f : ι → α) (h : ∃ x ∈ l, f x ≤ sInf ∅) : ⨅ x ∈ l, f x ∈ l.map f := by classical simpa using l.toFinset.ciInf_mem_image f (by simpa using h) lemma Multiset.iSup_mem_map_of_exists_sSup_empty_le {s : Multiset ι} (f : ι → α) (h : ∃ x ∈ s, sSup ∅ ≤ f x) : ⨆ x ∈ s, f x ∈ s.map f := by classical simpa using s.toFinset.ciSup_mem_image f (by simpa using h) lemma Multiset.iInf_mem_map_of_exists_le_sInf_empty {s : Multiset ι} (f : ι → α) (h : ∃ x ∈ s, f x ≤ sInf ∅) : ⨅ x ∈ s, f x ∈ s.map f := by classical simpa using s.toFinset.ciInf_mem_image f (by simpa using h) theorem exists_eq_ciSup_of_finite [Nonempty ι] [Finite ι] {f : ι → α} : ∃ i, f i = ⨆ i, f i := Nonempty.csSup_mem (range_nonempty f) (finite_range f) theorem exists_eq_ciInf_of_finite [Nonempty ι] [Finite ι] {f : ι → α} : ∃ i, f i = ⨅ i, f i := Nonempty.csInf_mem (range_nonempty f) (finite_range f) end ListMultiset end ConditionallyCompleteLinearOrder namespace Finite variable [Finite ι] [ConditionallyCompleteLattice α] (f : ι → α) lemma le_ciSup (i : ι) : f i ≤ ⨆ j, f j := by suffices BddAbove (range f) from _root_.le_ciSup this i let : Fintype ι := Fintype.ofFinite ι use Finset.sup' Finset.univ ⟨i, Finset.mem_univ i⟩ f simp only [mem_upperBounds, mem_range, forall_exists_index, forall_apply_eq_imp_iff] exact fun j ↦ Finset.le_sup' f <| Finset.mem_univ j lemma ciInf_le (i : ι) : ⨅ j, f j ≤ f i := le_ciSup (α := αᵒᵈ) f i end Finite /-! ### Relation between `sSup` / `sInf` and `Finset.sup'` / `Finset.inf'` Like the `Sup` of a `ConditionallyCompleteLattice`, `Finset.sup'` also requires the set to be non-empty. As a result, we can translate between the two. -/ namespace Finset section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] theorem sup'_eq_csSup_image (s : Finset ι) (H : s.Nonempty) (f : ι → α) : s.sup' H f = sSup (f '' s) := eq_of_forall_ge_iff fun a => by simp [csSup_le_iff (s.finite_toSet.image f).bddAbove (H.to_set.image f)] theorem inf'_eq_csInf_image (s : Finset ι) (H : s.Nonempty) (f : ι → α) : s.inf' H f = sInf (f '' s) := sup'_eq_csSup_image (α := αᵒᵈ) _ H _ theorem sup'_id_eq_csSup (s : Finset α) (hs) : s.sup' hs id = sSup s := by rw [sup'_eq_csSup_image s hs, Set.image_id] theorem inf'_id_eq_csInf (s : Finset α) (hs) : s.inf' hs id = sInf s := sup'_id_eq_csSup (α := αᵒᵈ) _ hs variable [Fintype ι] [Nonempty ι] lemma sup'_univ_eq_ciSup (f : ι → α) : univ.sup' univ_nonempty f = ⨆ i, f i := by simp [sup'_eq_csSup_image, iSup] lemma inf'_univ_eq_ciInf (f : ι → α) : univ.inf' univ_nonempty f = ⨅ i, f i := by simp [inf'_eq_csInf_image, iInf] end ConditionallyCompleteLattice section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot α] lemma sup_univ_eq_ciSup [Fintype ι] (f : ι → α) : univ.sup f = ⨆ i, f i := le_antisymm (Finset.sup_le fun _ _ => le_ciSup (finite_range _).bddAbove _) (ciSup_le' fun _ => Finset.le_sup (mem_univ _)) end ConditionallyCompleteLinearOrderBot end Finset section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot α] (f : ι → α) theorem Finset.Nonempty.ciSup_eq_max'_image {s : Finset ι} (h : s.Nonempty) (h' : (s.image f).Nonempty := h.image f) : ⨆ i ∈ s, f i = (s.image f).max' h' := s.ciSup_eq_max'_image _ (h.imp (by simp)) _ theorem Finset.Nonempty.ciSup_mem_image {s : Finset ι} (h : s.Nonempty) : ⨆ i ∈ s, f i ∈ s.image f := s.ciSup_mem_image _ (h.imp (by simp)) theorem Set.Nonempty.ciSup_mem_image {s : Set ι} (h : s.Nonempty) (hs : s.Finite) : ⨆ i ∈ s, f i ∈ f '' s := hs.ciSup_mem_image _ (h.imp (by simp)) theorem Set.Nonempty.ciSup_lt_iff {s : Set ι} {a : α} {f : ι → α} (h : s.Nonempty) (hs : s.Finite) : ⨆ i ∈ s, f i < a ↔ ∀ x ∈ s, f x < a := hs.ciSup_lt_iff (h.imp (by simp)) section ListMultiset lemma List.iSup_mem_map_of_ne_nil {l : List ι} (f : ι → α) (h : l ≠ []) : ⨆ x ∈ l, f x ∈ l.map f := l.iSup_mem_map_of_exists_sSup_empty_le _ (by simpa using exists_mem_of_ne_nil _ h) lemma Multiset.iSup_mem_map_of_ne_zero {s : Multiset ι} (f : ι → α) (h : s ≠ 0) : ⨆ x ∈ s, f x ∈ s.map f := s.iSup_mem_map_of_exists_sSup_empty_le _ (by simpa using exists_mem_of_ne_zero h) end ListMultiset end ConditionallyCompleteLinearOrderBot
.lake/packages/mathlib/Mathlib/Order/ConditionallyCompleteLattice/Basic.lean
import Mathlib.Data.Set.Lattice import Mathlib.Order.ConditionallyCompleteLattice.Defs /-! # Theory of conditionally complete lattices A conditionally complete lattice is a lattice in which every non-empty bounded subset `s` has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`. Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders. The theory is very comparable to the theory of complete lattices, except that suitable boundedness and nonemptiness assumptions have to be added to most statements. We express these using the `BddAbove` and `BddBelow` predicates, which we use to prove most useful properties of `sSup` and `sInf` in conditionally complete lattices. To differentiate the statements between complete lattices and conditionally complete lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`. For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`, while `csInf_le` is the same statement in conditionally complete lattices with an additional assumption that `s` is bounded below. -/ -- Guard against import creep assert_not_exists Multiset open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} section /-! Extension of `sSup` and `sInf` from a preorder `α` to `WithTop α` and `WithBot α` -/ variable [Preorder α] open Classical in noncomputable instance WithTop.instSupSet [SupSet α] : SupSet (WithTop α) := ⟨fun S => if ⊤ ∈ S then ⊤ else if BddAbove ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α) then ↑(sSup ((fun (a : α) ↦ (a : WithTop α)) ⁻¹' S : Set α)) else ⊤⟩ open Classical in noncomputable instance WithTop.instInfSet [InfSet α] : InfSet (WithTop α) := ⟨fun S => if S ⊆ {⊤} ∨ ¬BddBelow S then ⊤ else ↑(sInf ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α))⟩ noncomputable instance WithBot.instSupSet [SupSet α] : SupSet (WithBot α) := ⟨(WithTop.instInfSet (α := αᵒᵈ)).sInf⟩ noncomputable instance WithBot.instInfSet [InfSet α] : InfSet (WithBot α) := ⟨(WithTop.instSupSet (α := αᵒᵈ)).sSup⟩ theorem WithTop.sSup_eq [SupSet α] {s : Set (WithTop α)} (hs : ⊤ ∉ s) (hs' : BddAbove ((↑) ⁻¹' s : Set α)) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) := (if_neg hs).trans <| if_pos hs' theorem WithTop.sInf_eq [InfSet α] {s : Set (WithTop α)} (hs : ¬s ⊆ {⊤}) (h's : BddBelow s) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) := if_neg <| by simp [hs, h's] theorem WithBot.sInf_eq [InfSet α] {s : Set (WithBot α)} (hs : ⊥ ∉ s) (hs' : BddBelow ((↑) ⁻¹' s : Set α)) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) := (if_neg hs).trans <| if_pos hs' theorem WithBot.sSup_eq [SupSet α] {s : Set (WithBot α)} (hs : ¬s ⊆ {⊥}) (h's : BddAbove s) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) := WithTop.sInf_eq (α := αᵒᵈ) hs h's @[simp] theorem WithTop.sInf_empty [InfSet α] : sInf (∅ : Set (WithTop α)) = ⊤ := if_pos <| by simp theorem WithTop.coe_sInf' [InfSet α] {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) : ↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by classical obtain ⟨x, hx⟩ := hs change _ = ite _ _ _ split_ifs with h · rcases h with h1 | h2 · cases h1 (mem_image_of_mem _ hx) · exact (h2 (Monotone.map_bddBelow coe_mono h's)).elim · rw [preimage_image_eq] exact Option.some_injective _ theorem WithTop.coe_sSup' [SupSet α] {s : Set α} (hs : BddAbove s) : ↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by classical change _ = ite _ _ _ rw [if_neg, preimage_image_eq, if_pos hs] · exact Option.some_injective _ · rintro ⟨x, _, ⟨⟩⟩ @[simp] theorem WithBot.sSup_empty [SupSet α] : sSup (∅ : Set (WithBot α)) = ⊥ := WithTop.sInf_empty (α := αᵒᵈ) @[norm_cast] theorem WithBot.coe_sSup' [SupSet α] {s : Set α} (hs : s.Nonempty) (h's : BddAbove s) : ↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithBot α) := WithTop.coe_sInf' (α := αᵒᵈ) hs h's @[norm_cast] theorem WithBot.coe_sInf' [InfSet α] {s : Set α} (hs : BddBelow s) : ↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithBot α) := WithTop.coe_sSup' (α := αᵒᵈ) hs end instance ConditionallyCompleteLinearOrder.toLinearOrder [ConditionallyCompleteLinearOrder α] : LinearOrder α := { ‹ConditionallyCompleteLinearOrder α› with min_def := fun a b ↦ by by_cases hab : a = b · simp [hab] · rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂) · simp [h₁] · simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] max_def := fun a b ↦ by by_cases hab : a = b · simp [hab] · rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂) · simp [h₁] · simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] } -- see Note [lower instance priority] attribute [instance 100] ConditionallyCompleteLinearOrderBot.toOrderBot -- see Note [lower instance priority] /-- A complete lattice is a conditionally complete lattice, as there are no restrictions on the properties of sInf and sSup in a complete lattice. -/ instance (priority := 100) CompleteLattice.toConditionallyCompleteLattice [CompleteLattice α] : ConditionallyCompleteLattice α := { ‹CompleteLattice α› with le_csSup := by intros; apply le_sSup; assumption csSup_le := by intros; apply sSup_le; assumption csInf_le := by intros; apply sInf_le; assumption le_csInf := by intros; apply le_sInf; assumption } -- see Note [lower instance priority] instance (priority := 100) CompleteLinearOrder.toConditionallyCompleteLinearOrderBot {α : Type*} [h : CompleteLinearOrder α] : ConditionallyCompleteLinearOrderBot α := { CompleteLattice.toConditionallyCompleteLattice, h with csSup_empty := sSup_empty csSup_of_not_bddAbove := fun s H ↦ (H (OrderTop.bddAbove s)).elim csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim } namespace OrderDual instance instConditionallyCompleteLattice (α : Type*) [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice αᵒᵈ := { OrderDual.instInf α, OrderDual.instSup α, OrderDual.instLattice α with le_csSup := ConditionallyCompleteLattice.csInf_le (α := α) csSup_le := ConditionallyCompleteLattice.le_csInf (α := α) le_csInf := ConditionallyCompleteLattice.csSup_le (α := α) csInf_le := ConditionallyCompleteLattice.le_csSup (α := α) } instance (α : Type*) [ConditionallyCompleteLinearOrder α] : ConditionallyCompleteLinearOrder αᵒᵈ := { OrderDual.instConditionallyCompleteLattice α, OrderDual.instLinearOrder α with csSup_of_not_bddAbove := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow (α := α) csInf_of_not_bddBelow := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove (α := α) } end OrderDual section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s t : Set α} {a b : α} theorem le_csSup (h₁ : BddAbove s) (h₂ : a ∈ s) : a ≤ sSup s := ConditionallyCompleteLattice.le_csSup s a h₁ h₂ theorem csSup_le (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, b ≤ a) : sSup s ≤ a := ConditionallyCompleteLattice.csSup_le s a h₁ h₂ theorem csInf_le (h₁ : BddBelow s) (h₂ : a ∈ s) : sInf s ≤ a := ConditionallyCompleteLattice.csInf_le s a h₁ h₂ theorem le_csInf (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, a ≤ b) : a ≤ sInf s := ConditionallyCompleteLattice.le_csInf s a h₁ h₂ theorem le_csSup_of_le (hs : BddAbove s) (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s := le_trans h (le_csSup hs hb) theorem csInf_le_of_le (hs : BddBelow s) (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a := le_trans (csInf_le hs hb) h @[gcongr low] theorem csSup_le_csSup (ht : BddAbove t) (hs : s.Nonempty) (h : s ⊆ t) : sSup s ≤ sSup t := csSup_le hs fun _ ha => le_csSup ht (h ha) @[gcongr low] theorem csInf_le_csInf (ht : BddBelow t) (hs : s.Nonempty) (h : s ⊆ t) : sInf t ≤ sInf s := le_csInf hs fun _ ha => csInf_le ht (h ha) theorem le_csSup_iff (h : BddAbove s) (hs : s.Nonempty) : a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b := ⟨fun h _ hb => le_trans h (csSup_le hs hb), fun hb => hb _ fun _ => le_csSup h⟩ theorem csInf_le_iff (h : BddBelow s) (hs : s.Nonempty) : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a := ⟨fun h _ hb => le_trans (le_csInf hs hb) h, fun hb => hb _ fun _ => csInf_le h⟩ theorem isLUB_csSup (ne : s.Nonempty) (H : BddAbove s) : IsLUB s (sSup s) := ⟨fun _ => le_csSup H, fun _ => csSup_le ne⟩ theorem isGLB_csInf (ne : s.Nonempty) (H : BddBelow s) : IsGLB s (sInf s) := ⟨fun _ => csInf_le H, fun _ => le_csInf ne⟩ theorem IsLUB.csSup_eq (H : IsLUB s a) (ne : s.Nonempty) : sSup s = a := (isLUB_csSup ne ⟨a, H.1⟩).unique H /-- A greatest element of a set is the supremum of this set. -/ theorem IsGreatest.csSup_eq (H : IsGreatest s a) : sSup s = a := H.isLUB.csSup_eq H.nonempty theorem IsGreatest.csSup_mem (H : IsGreatest s a) : sSup s ∈ s := H.csSup_eq.symm ▸ H.1 theorem IsGLB.csInf_eq (H : IsGLB s a) (ne : s.Nonempty) : sInf s = a := (isGLB_csInf ne ⟨a, H.1⟩).unique H /-- A least element of a set is the infimum of this set. -/ theorem IsLeast.csInf_eq (H : IsLeast s a) : sInf s = a := H.isGLB.csInf_eq H.nonempty theorem IsLeast.csInf_mem (H : IsLeast s a) : sInf s ∈ s := H.csInf_eq.symm ▸ H.1 theorem subset_Icc_csInf_csSup (hb : BddBelow s) (ha : BddAbove s) : s ⊆ Icc (sInf s) (sSup s) := fun _ hx => ⟨csInf_le hb hx, le_csSup ha hx⟩ theorem csSup_le_iff (hb : BddAbove s) (hs : s.Nonempty) : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a := isLUB_le_iff (isLUB_csSup hs hb) theorem le_csInf_iff (hb : BddBelow s) (hs : s.Nonempty) : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b := le_isGLB_iff (isGLB_csInf hs hb) theorem csSup_lowerBounds_eq_csInf {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : sSup (lowerBounds s) = sInf s := (isLUB_csSup h <| hs.mono fun _ hx _ hy => hy hx).unique (isGLB_csInf hs h).isLUB theorem csInf_upperBounds_eq_csSup {s : Set α} (h : BddAbove s) (hs : s.Nonempty) : sInf (upperBounds s) = sSup s := (isGLB_csInf h <| hs.mono fun _ hx _ hy => hy hx).unique (isLUB_csSup hs h).isGLB theorem csSup_lowerBounds_range [Nonempty β] {f : β → α} (hf : BddBelow (range f)) : sSup (lowerBounds (range f)) = ⨅ i, f i := csSup_lowerBounds_eq_csInf hf <| range_nonempty _ theorem csInf_upperBounds_range [Nonempty β] {f : β → α} (hf : BddAbove (range f)) : sInf (upperBounds (range f)) = ⨆ i, f i := csInf_upperBounds_eq_csSup hf <| range_nonempty _ theorem notMem_of_lt_csInf {x : α} {s : Set α} (h : x < sInf s) (hs : BddBelow s) : x ∉ s := fun hx => lt_irrefl _ (h.trans_le (csInf_le hs hx)) @[deprecated (since := "2025-05-23")] alias not_mem_of_lt_csInf := notMem_of_lt_csInf theorem notMem_of_csSup_lt {x : α} {s : Set α} (h : sSup s < x) (hs : BddAbove s) : x ∉ s := notMem_of_lt_csInf (α := αᵒᵈ) h hs @[deprecated (since := "2025-05-23")] alias not_mem_of_csSup_lt := notMem_of_csSup_lt /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w<b`. See `sSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/ theorem csSup_eq_of_forall_le_of_forall_lt_exists_gt (hs : s.Nonempty) (H : ∀ a ∈ s, a ≤ b) (H' : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b := (eq_of_le_of_not_lt (csSup_le hs H)) fun hb => let ⟨_, ha, ha'⟩ := H' _ hb lt_irrefl _ <| ha'.trans_le <| le_csSup ⟨b, H⟩ ha /-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w>b`. See `sInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/ theorem csInf_eq_of_forall_ge_of_forall_gt_exists_lt : s.Nonempty → (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b := csSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ) /-- `b < sSup s` when there is an element `a` in `s` with `b < a`, when `s` is bounded above. This is essentially an iff, except that the assumptions for the two implications are slightly different (one needs boundedness above for one direction, nonemptiness and linear order for the other one), so we formulate separately the two implications, contrary to the `CompleteLattice` case. -/ theorem lt_csSup_of_lt (hs : BddAbove s) (ha : a ∈ s) (h : b < a) : b < sSup s := lt_of_lt_of_le h (le_csSup hs ha) /-- `sInf s < b` when there is an element `a` in `s` with `a < b`, when `s` is bounded below. This is essentially an iff, except that the assumptions for the two implications are slightly different (one needs boundedness below for one direction, nonemptiness and linear order for the other one), so we formulate separately the two implications, contrary to the `CompleteLattice` case. -/ theorem csInf_lt_of_lt : BddBelow s → a ∈ s → a < b → sInf s < b := lt_csSup_of_lt (α := αᵒᵈ) /-- If all elements of a nonempty set `s` are less than or equal to all elements of a nonempty set `t`, then there exists an element between these sets. -/ theorem exists_between_of_forall_le (sne : s.Nonempty) (tne : t.Nonempty) (hst : ∀ x ∈ s, ∀ y ∈ t, x ≤ y) : (upperBounds s ∩ lowerBounds t).Nonempty := ⟨sInf t, fun x hx => le_csInf tne <| hst x hx, fun _ hy => csInf_le (sne.mono hst) hy⟩ /-- The supremum of a singleton is the element of the singleton -/ @[simp] theorem csSup_singleton (a : α) : sSup {a} = a := isGreatest_singleton.csSup_eq /-- The infimum of a singleton is the element of the singleton -/ @[simp] theorem csInf_singleton (a : α) : sInf {a} = a := isLeast_singleton.csInf_eq theorem csSup_pair (a b : α) : sSup {a, b} = a ⊔ b := (@isLUB_pair _ _ a b).csSup_eq (insert_nonempty _ _) theorem csInf_pair (a b : α) : sInf {a, b} = a ⊓ b := (@isGLB_pair _ _ a b).csInf_eq (insert_nonempty _ _) /-- If a set is bounded below and above, and nonempty, its infimum is less than or equal to its supremum. -/ theorem csInf_le_csSup (hb : BddBelow s) (ha : BddAbove s) (ne : s.Nonempty) : sInf s ≤ sSup s := isGLB_le_isLUB (isGLB_csInf ne hb) (isLUB_csSup ne ha) ne /-- The `sSup` of a union of two sets is the max of the suprema of each subset, under the assumptions that all sets are bounded above and nonempty. -/ theorem csSup_union (hs : BddAbove s) (sne : s.Nonempty) (ht : BddAbove t) (tne : t.Nonempty) : sSup (s ∪ t) = sSup s ⊔ sSup t := ((isLUB_csSup sne hs).union (isLUB_csSup tne ht)).csSup_eq sne.inl /-- The `sInf` of a union of two sets is the min of the infima of each subset, under the assumptions that all sets are bounded below and nonempty. -/ theorem csInf_union (hs : BddBelow s) (sne : s.Nonempty) (ht : BddBelow t) (tne : t.Nonempty) : sInf (s ∪ t) = sInf s ⊓ sInf t := csSup_union (α := αᵒᵈ) hs sne ht tne /-- The supremum of an intersection of two sets is bounded by the minimum of the suprema of each set, if all sets are bounded above and nonempty. -/ theorem csSup_inter_le (hs : BddAbove s) (ht : BddAbove t) (hst : (s ∩ t).Nonempty) : sSup (s ∩ t) ≤ sSup s ⊓ sSup t := (csSup_le hst) fun _ hx => le_inf (le_csSup hs hx.1) (le_csSup ht hx.2) /-- The infimum of an intersection of two sets is bounded below by the maximum of the infima of each set, if all sets are bounded below and nonempty. -/ theorem le_csInf_inter : BddBelow s → BddBelow t → (s ∩ t).Nonempty → sInf s ⊔ sInf t ≤ sInf (s ∩ t) := csSup_inter_le (α := αᵒᵈ) /-- The supremum of `insert a s` is the maximum of `a` and the supremum of `s`, if `s` is nonempty and bounded above. -/ @[simp] theorem csSup_insert (hs : BddAbove s) (sne : s.Nonempty) : sSup (insert a s) = a ⊔ sSup s := ((isLUB_csSup sne hs).insert a).csSup_eq (insert_nonempty a s) /-- The infimum of `insert a s` is the minimum of `a` and the infimum of `s`, if `s` is nonempty and bounded below. -/ @[simp] theorem csInf_insert (hs : BddBelow s) (sne : s.Nonempty) : sInf (insert a s) = a ⊓ sInf s := csSup_insert (α := αᵒᵈ) hs sne @[simp] theorem csInf_Icc (h : a ≤ b) : sInf (Icc a b) = a := (isGLB_Icc h).csInf_eq (nonempty_Icc.2 h) @[simp] theorem csInf_Ici : sInf (Ici a) = a := isLeast_Ici.csInf_eq @[simp] theorem csInf_Ico (h : a < b) : sInf (Ico a b) = a := (isGLB_Ico h).csInf_eq (nonempty_Ico.2 h) @[simp] theorem csInf_Ioc [DenselyOrdered α] (h : a < b) : sInf (Ioc a b) = a := (isGLB_Ioc h).csInf_eq (nonempty_Ioc.2 h) @[simp] theorem csInf_Ioi [NoMaxOrder α] [DenselyOrdered α] : sInf (Ioi a) = a := csInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (fun _ => le_of_lt) fun w hw => by simpa using exists_between hw @[simp] theorem csInf_Ioo [DenselyOrdered α] (h : a < b) : sInf (Ioo a b) = a := (isGLB_Ioo h).csInf_eq (nonempty_Ioo.2 h) @[simp] theorem csSup_Icc (h : a ≤ b) : sSup (Icc a b) = b := (isLUB_Icc h).csSup_eq (nonempty_Icc.2 h) @[simp] theorem csSup_Ico [DenselyOrdered α] (h : a < b) : sSup (Ico a b) = b := (isLUB_Ico h).csSup_eq (nonempty_Ico.2 h) @[simp] theorem csSup_Iic : sSup (Iic a) = a := isGreatest_Iic.csSup_eq @[simp] theorem csSup_Iio [NoMinOrder α] [DenselyOrdered α] : sSup (Iio a) = a := csSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (fun _ => le_of_lt) fun w hw => by simpa [and_comm] using exists_between hw @[simp] theorem csSup_Ioc (h : a < b) : sSup (Ioc a b) = b := (isLUB_Ioc h).csSup_eq (nonempty_Ioc.2 h) @[simp] theorem csSup_Ioo [DenselyOrdered α] (h : a < b) : sSup (Ioo a b) = b := (isLUB_Ioo h).csSup_eq (nonempty_Ioo.2 h) /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that 1) `b` is an upper bound 2) every other upper bound `b'` satisfies `b ≤ b'`. -/ theorem csSup_eq_of_is_forall_le_of_forall_le_imp_ge (hs : s.Nonempty) (h_is_ub : ∀ a ∈ s, a ≤ b) (h_b_le_ub : ∀ ub, (∀ a ∈ s, a ≤ ub) → b ≤ ub) : sSup s = b := (csSup_le hs h_is_ub).antisymm ((h_b_le_ub _) fun _ => le_csSup ⟨b, h_is_ub⟩) lemma sup_eq_top_of_top_mem [OrderTop α] (h : ⊤ ∈ s) : sSup s = ⊤ := top_unique <| le_csSup (OrderTop.bddAbove s) h lemma inf_eq_bot_of_bot_mem [OrderBot α] (h : ⊥ ∈ s) : sInf s = ⊥ := bot_unique <| csInf_le (OrderBot.bddBelow s) h end ConditionallyCompleteLattice instance Pi.conditionallyCompleteLattice {ι : Type*} {α : ι → Type*} [∀ i, ConditionallyCompleteLattice (α i)] : ConditionallyCompleteLattice (∀ i, α i) := { Pi.instLattice, Pi.supSet, Pi.infSet with le_csSup := fun _ f ⟨g, hg⟩ hf i => le_csSup ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩ csSup_le := fun s _ hs hf i => (csSup_le (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ => hb ▸ hf hg i csInf_le := fun _ f ⟨g, hg⟩ hf i => csInf_le ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩ le_csInf := fun s _ hs hf i => (le_csInf (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ => hb ▸ hf hg i } section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] {f : ι → α} {s : Set α} {a b : α} /-- When `b < sSup s`, there is an element `a` in `s` with `b < a`, if `s` is nonempty and the order is a linear order. -/ theorem exists_lt_of_lt_csSup (hs : s.Nonempty) (hb : b < sSup s) : ∃ a ∈ s, b < a := by contrapose! hb exact csSup_le hs hb /-- When `sInf s < b`, there is an element `a` in `s` with `a < b`, if `s` is nonempty and the order is a linear order. -/ theorem exists_lt_of_csInf_lt (hs : s.Nonempty) (hb : sInf s < b) : ∃ a ∈ s, a < b := exists_lt_of_lt_csSup (α := αᵒᵈ) hs hb theorem lt_csSup_iff (hb : BddAbove s) (hs : s.Nonempty) : a < sSup s ↔ ∃ b ∈ s, a < b := lt_isLUB_iff <| isLUB_csSup hs hb theorem csInf_lt_iff (hb : BddBelow s) (hs : s.Nonempty) : sInf s < a ↔ ∃ b ∈ s, b < a := isGLB_lt_iff <| isGLB_csInf hs hb @[simp] lemma csSup_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup ∅ := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove s hs @[simp] lemma ciSup_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup ∅ := csSup_of_not_bddAbove hf lemma csSup_eq_univ_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup univ := by rw [csSup_of_not_bddAbove hs, csSup_of_not_bddAbove (s := univ)] contrapose! hs exact hs.mono (subset_univ _) lemma ciSup_eq_univ_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup univ := csSup_eq_univ_of_not_bddAbove hf @[simp] lemma csInf_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf ∅ := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow s hs @[simp] lemma ciInf_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf ∅ := csInf_of_not_bddBelow hf lemma csInf_eq_univ_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf univ := csSup_eq_univ_of_not_bddAbove (α := αᵒᵈ) hs lemma ciInf_eq_univ_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf univ := csInf_eq_univ_of_not_bddBelow hf /-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then `s` and `t` have the same supremum. This holds even when the sets may be empty or unbounded. -/ theorem csSup_eq_csSup_of_forall_exists_le {s t : Set α} (hs : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) (ht : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) : sSup s = sSup t := by rcases eq_empty_or_nonempty s with rfl | s_ne · have : t = ∅ := eq_empty_of_forall_notMem (fun y yt ↦ by simpa using ht y yt) rw [this] rcases eq_empty_or_nonempty t with rfl | t_ne · have : s = ∅ := eq_empty_of_forall_notMem (fun x xs ↦ by simpa using hs x xs) rw [this] by_cases B : BddAbove s ∨ BddAbove t · have Bs : BddAbove s := by rcases B with hB | ⟨b, hb⟩ · exact hB · refine ⟨b, fun x hx ↦ ?_⟩ rcases hs x hx with ⟨y, hy, hxy⟩ exact hxy.trans (hb hy) have Bt : BddAbove t := by rcases B with ⟨b, hb⟩ | hB · refine ⟨b, fun y hy ↦ ?_⟩ rcases ht y hy with ⟨x, hx, hyx⟩ exact hyx.trans (hb hx) · exact hB apply le_antisymm · apply csSup_le s_ne (fun x hx ↦ ?_) rcases hs x hx with ⟨y, yt, hxy⟩ exact hxy.trans (le_csSup Bt yt) · apply csSup_le t_ne (fun y hy ↦ ?_) rcases ht y hy with ⟨x, xs, hyx⟩ exact hyx.trans (le_csSup Bs xs) · simp [csSup_of_not_bddAbove, (not_or.1 B).1, (not_or.1 B).2] /-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then `s` and `t` have the same infimum. This holds even when the sets may be empty or unbounded. -/ theorem csInf_eq_csInf_of_forall_exists_le {s t : Set α} (hs : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) (ht : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) : sInf s = sInf t := csSup_eq_csSup_of_forall_exists_le (α := αᵒᵈ) hs ht lemma sSup_iUnion_Iic (f : ι → α) : sSup (⋃ (i : ι), Iic (f i)) = ⨆ i, f i := by apply csSup_eq_csSup_of_forall_exists_le · rintro x ⟨-, ⟨i, rfl⟩, hi⟩ exact ⟨f i, mem_range_self _, hi⟩ · rintro x ⟨i, rfl⟩ exact ⟨f i, mem_iUnion_of_mem i le_rfl, le_rfl⟩ lemma sInf_iUnion_Ici (f : ι → α) : sInf (⋃ (i : ι), Ici (f i)) = ⨅ i, f i := sSup_iUnion_Iic (α := αᵒᵈ) f theorem csInf_eq_bot_of_bot_mem [OrderBot α] {s : Set α} (hs : ⊥ ∈ s) : sInf s = ⊥ := eq_bot_iff.2 <| csInf_le (OrderBot.bddBelow s) hs theorem csSup_eq_top_of_top_mem [OrderTop α] {s : Set α} (hs : ⊤ ∈ s) : sSup s = ⊤ := csInf_eq_bot_of_bot_mem (α := αᵒᵈ) hs open Function variable [WellFoundedLT α] theorem sInf_eq_argmin_on (hs : s.Nonempty) : sInf s = argminOn id s hs := IsLeast.csInf_eq ⟨argminOn_mem _ _ _, fun _ ha => argminOn_le id _ ha⟩ theorem isLeast_csInf (hs : s.Nonempty) : IsLeast s (sInf s) := by rw [sInf_eq_argmin_on hs] exact ⟨argminOn_mem _ _ _, fun a ha => argminOn_le id _ ha⟩ theorem le_csInf_iff' (hs : s.Nonempty) : b ≤ sInf s ↔ b ∈ lowerBounds s := le_isGLB_iff (isLeast_csInf hs).isGLB theorem csInf_mem (hs : s.Nonempty) : sInf s ∈ s := (isLeast_csInf hs).1 theorem MonotoneOn.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β} (hf : MonotoneOn f s) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) := (hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm theorem Monotone.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β} (hf : Monotone f) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) := (hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm end ConditionallyCompleteLinearOrder /-! ### Lemmas about a conditionally complete linear order with bottom element In this case we have `Sup ∅ = ⊥`, so we can drop some `Nonempty`/`Set.Nonempty` assumptions. -/ section ConditionallyCompleteLinearOrderBot @[simp] theorem csInf_univ [ConditionallyCompleteLattice α] [OrderBot α] : sInf (univ : Set α) = ⊥ := isLeast_univ.csInf_eq variable [ConditionallyCompleteLinearOrderBot α] {s : Set α} {a : α} @[simp] theorem csSup_empty : (sSup ∅ : α) = ⊥ := ConditionallyCompleteLinearOrderBot.csSup_empty theorem isLUB_csSup' {s : Set α} (hs : BddAbove s) : IsLUB s (sSup s) := by rcases eq_empty_or_nonempty s with (rfl | hne) · simp only [csSup_empty, isLUB_empty] · exact isLUB_csSup hne hs /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `csSup_le_iff`. -/ theorem csSup_le_iff' {s : Set α} (hs : BddAbove s) {a : α} : sSup s ≤ a ↔ ∀ x ∈ s, x ≤ a := isLUB_le_iff (isLUB_csSup' hs) theorem csSup_le' {s : Set α} {a : α} (h : a ∈ upperBounds s) : sSup s ≤ a := (csSup_le_iff' ⟨a, h⟩).2 h /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `lt_csSup_iff`. -/ theorem lt_csSup_iff' (hb : BddAbove s) : a < sSup s ↔ ∃ b ∈ s, a < b := by simpa only [not_le, not_forall₂, exists_prop] using (csSup_le_iff' hb).not theorem le_csSup_iff' {s : Set α} {a : α} (h : BddAbove s) : a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b := ⟨fun h _ hb => le_trans h (csSup_le' hb), fun hb => hb _ fun _ => le_csSup h⟩ theorem le_csInf_iff'' {s : Set α} {a : α} (ne : s.Nonempty) : a ≤ sInf s ↔ ∀ b : α, b ∈ s → a ≤ b := le_csInf_iff (OrderBot.bddBelow _) ne theorem csInf_le' (h : a ∈ s) : sInf s ≤ a := csInf_le (OrderBot.bddBelow _) h theorem exists_lt_of_lt_csSup' {s : Set α} {a : α} (h : a < sSup s) : ∃ b ∈ s, a < b := by contrapose! h exact csSup_le' h theorem notMem_of_lt_csInf' {x : α} {s : Set α} (h : x < sInf s) : x ∉ s := notMem_of_lt_csInf h (OrderBot.bddBelow s) @[deprecated (since := "2025-05-23")] alias not_mem_of_lt_csInf' := notMem_of_lt_csInf' @[gcongr mid] theorem csInf_le_csInf' {s t : Set α} (h₁ : t.Nonempty) (h₂ : t ⊆ s) : sInf s ≤ sInf t := csInf_le_csInf (OrderBot.bddBelow s) h₁ h₂ @[gcongr mid] theorem csSup_le_csSup' {s t : Set α} (h₁ : BddAbove t) (h₂ : s ⊆ t) : sSup s ≤ sSup t := by rcases eq_empty_or_nonempty s with rfl | h · rw [csSup_empty] exact bot_le · exact csSup_le_csSup h₁ h h₂ end ConditionallyCompleteLinearOrderBot namespace WithTop variable [ConditionallyCompleteLinearOrderBot α] /-- The `sSup` of a non-empty set is its least upper bound for a conditionally complete lattice with a top. -/ theorem isLUB_sSup' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)} (hs : s.Nonempty) : IsLUB s (sSup s) := by classical constructor · change ite _ _ _ ∈ _ split_ifs with h₁ h₂ · intro _ _ exact le_top · rintro (⟨⟩ | a) ha · contradiction apply coe_le_coe.2 exact le_csSup h₂ ha · intro _ _ exact le_top · change ite _ _ _ ∈ _ split_ifs with h₁ h₂ · rintro (⟨⟩ | a) ha · exact le_rfl · exact False.elim (not_top_le_coe a (ha h₁)) · rintro (⟨⟩ | b) hb · exact le_top refine coe_le_coe.2 (csSup_le ?_ ?_) · rcases hs with ⟨⟨⟩ | b, hb⟩ · exact absurd hb h₁ · exact ⟨b, hb⟩ · intro a ha exact coe_le_coe.1 (hb ha) · rintro (⟨⟩ | b) hb · exact le_rfl · exfalso apply h₂ use b intro a ha exact coe_le_coe.1 (hb ha) theorem isLUB_sSup (s : Set (WithTop α)) : IsLUB s (sSup s) := by rcases s.eq_empty_or_nonempty with rfl | hs · simp [sSup] · exact isLUB_sSup' hs /-- The `sInf` of a bounded-below set is its greatest lower bound for a conditionally complete lattice with a top. -/ theorem isGLB_sInf' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)} (hs : BddBelow s) : IsGLB s (sInf s) := by classical constructor · change ite _ _ _ ∈ _ simp only [hs, not_true_eq_false, or_false] split_ifs with h · intro a ha exact top_le_iff.2 (Set.mem_singleton_iff.1 (h ha)) · rintro (⟨⟩ | a) ha · exact le_top refine coe_le_coe.2 (csInf_le ?_ ha) rcases hs with ⟨⟨⟩ | b, hb⟩ · exfalso apply h intro c hc rw [mem_singleton_iff, ← top_le_iff] exact hb hc use b intro c hc exact coe_le_coe.1 (hb hc) · change ite _ _ _ ∈ _ simp only [hs, not_true_eq_false, or_false] split_ifs with h · intro _ _ exact le_top · rintro (⟨⟩ | a) ha · exfalso apply h intro b hb exact Set.mem_singleton_iff.2 (top_le_iff.1 (ha hb)) · refine coe_le_coe.2 (le_csInf ?_ ?_) · classical contrapose! h rintro (⟨⟩ | a) ha · exact mem_singleton ⊤ · exact (not_nonempty_iff_eq_empty.2 h ⟨a, ha⟩).elim · intro b hb rw [← coe_le_coe] exact ha hb theorem isGLB_sInf (s : Set (WithTop α)) : IsGLB s (sInf s) := by by_cases hs : BddBelow s · exact isGLB_sInf' hs · exfalso apply hs use ⊥ intro _ _ exact bot_le noncomputable instance : CompleteLinearOrder (WithTop α) where __ := linearOrder __ := linearOrder.toBiheytingAlgebra le_sSup s := (isLUB_sSup s).1 sSup_le s := (isLUB_sSup s).2 le_sInf s := (isGLB_sInf s).2 sInf_le s := (isGLB_sInf s).1 /-- A version of `WithTop.coe_sSup'` with a more convenient but less general statement. -/ @[norm_cast] theorem coe_sSup {s : Set α} (hb : BddAbove s) : ↑(sSup s) = (⨆ a ∈ s, ↑a : WithTop α) := by rw [coe_sSup' hb, sSup_image] /-- A version of `WithTop.coe_sInf'` with a more convenient but less general statement. -/ @[norm_cast] theorem coe_sInf {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) : ↑(sInf s) = (⨅ a ∈ s, ↑a : WithTop α) := by rw [coe_sInf' hs h's, sInf_image] end WithTop namespace Monotone variable [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} (h_mono : Monotone f) include h_mono /-! A monotone function into a conditionally complete lattice preserves the ordering properties of `sSup` and `sInf`. -/ theorem le_csSup_image {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddAbove s) : f c ≤ sSup (f '' s) := le_csSup (map_bddAbove h_mono h_bdd) (mem_image_of_mem f hcs) theorem csSup_image_le {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ upperBounds s) : sSup (f '' s) ≤ f B := csSup_le (Nonempty.image f hs) (h_mono.mem_upperBounds_image hB) -- Porting note: in mathlib3 `f'` is not needed theorem csInf_image_le {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddBelow s) : sInf (f '' s) ≤ f c := by let f' : αᵒᵈ → βᵒᵈ := f exact le_csSup_image (α := αᵒᵈ) (β := βᵒᵈ) (show Monotone f' from fun x y hxy => h_mono hxy) hcs h_bdd -- Porting note: in mathlib3 `f'` is not needed theorem le_csInf_image {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ lowerBounds s) : f B ≤ sInf (f '' s) := by let f' : αᵒᵈ → βᵒᵈ := f exact csSup_image_le (α := αᵒᵈ) (β := βᵒᵈ) (show Monotone f' from fun x y hxy => h_mono hxy) hs hB end Monotone lemma MonotoneOn.csInf_eq_of_subset_of_forall_exists_le [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {s t : Set α} (ht : BddBelow (f '' t)) (hf : MonotoneOn f t) (hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) : sInf (f '' s) = sInf (f '' t) := by obtain rfl | hs := Set.eq_empty_or_nonempty s · obtain rfl : t = ∅ := by simpa [Set.eq_empty_iff_forall_notMem] using h rfl refine le_antisymm ?_ (by gcongr; exacts [ht, hs.image f]) refine le_csInf ((hs.mono hst).image f) ?_ simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro a ha obtain ⟨x, hxs, hxa⟩ := h a ha exact csInf_le_of_le (ht.mono (image_mono hst)) ⟨x, hxs, rfl⟩ (hf (hst hxs) ha hxa) lemma MonotoneOn.csSup_eq_of_subset_of_forall_exists_le [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {s t : Set α} (ht : BddAbove (f '' t)) (hf : MonotoneOn f t) (hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) : sSup (f '' s) = sSup (f '' t) := MonotoneOn.csInf_eq_of_subset_of_forall_exists_le (α := αᵒᵈ) (β := βᵒᵈ) ht hf.dual hst h theorem MonotoneOn.sInf_image_Icc [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {a b : α} (hab : a ≤ b) (h' : MonotoneOn f (Icc a b)) : sInf (f '' Icc a b) = f a := by refine IsGLB.csInf_eq ?_ ((nonempty_Icc.mpr hab).image f) refine isGLB_iff_le_iff.mpr (fun b' ↦ ⟨?_, ?_⟩) · intro hb' rintro _ ⟨x, hx, rfl⟩ exact hb'.trans <| h' (left_mem_Icc.mpr hab) hx hx.1 · exact fun hb' ↦ hb' ⟨a, by simp [hab]⟩ theorem MonotoneOn.sSup_image_Icc [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {a b : α} (hab : a ≤ b) (h' : MonotoneOn f (Icc a b)) : sSup (f '' Icc a b) = f b := by have : Icc a b = Icc (α := αᵒᵈ) (toDual b) (toDual a) := by rw [Icc_toDual]; rfl rw [this] at h' ⊢ exact h'.dual_right.dual_left.sInf_image_Icc (β := βᵒᵈ) (α := αᵒᵈ) hab theorem AntitoneOn.sInf_image_Icc [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {a b : α} (hab : a ≤ b) (h' : AntitoneOn f (Icc a b)) : sInf (f '' Icc a b) = f b := by have : Icc a b = Icc (α := αᵒᵈ) (toDual b) (toDual a) := by rw [Icc_toDual]; rfl rw [this] at h' ⊢ exact h'.dual_left.sInf_image_Icc (α := αᵒᵈ) hab theorem AntitoneOn.sSup_image_Icc [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {a b : α} (hab : a ≤ b) (h' : AntitoneOn f (Icc a b)) : sSup (f '' Icc a b) = f a := h'.dual_right.sInf_image_Icc hab /-! ### Supremum/infimum of `Set.image2` A collection of lemmas showing what happens to the suprema/infima of `s` and `t` when mapped under a binary function whose partial evaluations are lower/upper adjoints of Galois connections. -/ section variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {s : Set α} {t : Set β} variable {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β} theorem csSup_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddAbove t) : sSup (image2 l s t) = l (sSup s) (sSup t) := by refine eq_of_forall_ge_iff fun c => ?_ rw [csSup_le_iff (hs₁.image2 (fun _ => (h₁ _).monotone_l) (fun _ => (h₂ _).monotone_l) ht₁) (hs₀.image2 ht₀), forall_mem_image2, forall₂_swap, (h₂ _).le_iff_le, csSup_le_iff ht₁ ht₀] simp_rw [← (h₂ _).le_iff_le, (h₁ _).le_iff_le, csSup_le_iff hs₁ hs₀] theorem csSup_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sSup s) (sInf t) := csSup_image2_eq_csSup_csSup (β := βᵒᵈ) h₁ h₂ theorem csSup_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sSup (image2 l s t) = l (sInf s) (sSup t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) h₁ h₂ theorem csSup_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sInf s) (sInf t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sInf s) (sInf t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) (γ := γᵒᵈ) (u₁ := l₁) (u₂ := l₂) (fun _ => (h₁ _).dual) fun _ => (h₂ _).dual theorem csInf_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) : s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sInf s) (sSup t) := csInf_image2_eq_csInf_csInf (β := βᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sSup s) (sInf t) := csInf_image2_eq_csInf_csInf (α := αᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual)) (h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) : s.Nonempty → BddAbove s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sSup s) (sSup t) := csInf_image2_eq_csInf_csInf (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ end section WithTopBot /-! ### Complete lattice structure on `WithTop (WithBot α)` If `α` is a `ConditionallyCompleteLattice`, then we show that `WithTop α` and `WithBot α` also inherit the structure of conditionally complete lattices. Furthermore, we show that `WithTop (WithBot α)` and `WithBot (WithTop α)` naturally inherit the structure of a complete lattice. Note that for `α` a conditionally complete lattice, `sSup` and `sInf` both return junk values for sets which are empty or unbounded. The extension of `sSup` to `WithTop α` fixes the unboundedness problem and the extension to `WithBot α` fixes the problem with the empty set. This result can be used to show that the extended reals `[-∞, ∞]` are a complete linear order. -/ /-- Adding a top element to a conditionally complete lattice gives a conditionally complete lattice -/ noncomputable instance WithTop.conditionallyCompleteLattice {α : Type*} [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithTop α) := { lattice, instSupSet, instInfSet with le_csSup := fun _ a _ haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS csSup_le := fun _ _ hS haS => (WithTop.isLUB_sSup' hS).2 haS csInf_le := fun _ _ hS haS => (WithTop.isGLB_sInf' hS).1 haS le_csInf := fun _ a _ haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS } /-- Adding a bottom element to a conditionally complete lattice gives a conditionally complete lattice -/ noncomputable instance WithBot.conditionallyCompleteLattice {α : Type*} [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithBot α) := { WithBot.lattice with le_csSup := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csInf_le csSup_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csInf csInf_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csSup le_csInf := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csSup_le } open Classical in noncomputable instance WithTop.WithBot.completeLattice {α : Type*} [ConditionallyCompleteLattice α] : CompleteLattice (WithTop (WithBot α)) := { instInfSet, instSupSet, boundedOrder, lattice with le_sSup := fun _ a haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS sSup_le := fun S a ha => by rcases S.eq_empty_or_nonempty with h | h · change ite _ _ _ ≤ a simp [h] · exact (WithTop.isLUB_sSup' h).2 ha sInf_le := fun S a haS => show ite _ _ _ ≤ a by simp only [OrderBot.bddBelow, not_true_eq_false, or_false] split_ifs with h₁ · cases a · exact le_rfl cases h₁ haS · cases a · exact le_top · apply WithTop.coe_le_coe.2 refine csInf_le ?_ haS use ⊥ intro b _ exact bot_le le_sInf := fun _ a haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS } noncomputable instance WithTop.WithBot.completeLinearOrder {α : Type*} [ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithTop (WithBot α)) where __ := completeLattice __ := linearOrder __ := linearOrder.toBiheytingAlgebra noncomputable instance WithBot.WithTop.completeLattice {α : Type*} [ConditionallyCompleteLattice α] : CompleteLattice (WithBot (WithTop α)) := { instInfSet, instSupSet, instBoundedOrder, lattice with le_sSup := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sInf_le sSup_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sInf sInf_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sSup le_sInf := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sSup_le } noncomputable instance WithBot.WithTop.completeLinearOrder {α : Type*} [ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithBot (WithTop α)) where __ := completeLattice __ := linearOrder __ := linearOrder.toBiheytingAlgebra end WithTopBot
.lake/packages/mathlib/Mathlib/Order/ConditionallyCompleteLattice/Defs.lean
import Mathlib.Order.Bounds.Basic import Mathlib.Order.SetNotation import Mathlib.Order.WellFounded /-! # Definitions of conditionally complete lattices A conditionally complete lattice is a lattice in which every non-empty bounded subset `s` has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`. Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders. The theory is very comparable to the theory of complete lattices, except that suitable boundedness and nonemptiness assumptions have to be added to most statements. We express these using the `BddAbove` and `BddBelow` predicates, which we use to prove most useful properties of `sSup` and `sInf` in conditionally complete lattices. To differentiate the statements between complete lattices and conditionally complete lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`. For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`, while `csInf_le` is the same statement in conditionally complete lattices with an additional assumption that `s` is bounded below. -/ open Set variable {α β γ : Type*} {ι : Sort*} /-- A conditionally complete lattice is a lattice in which every nonempty subset which is bounded above has a supremum, and every nonempty subset which is bounded below has an infimum. Typical examples are real numbers or natural numbers. To differentiate the statements from the corresponding statements in (unconditional) complete lattices, we prefix `sInf` and `sSup` by a `c` everywhere. The same statements should hold in both worlds, sometimes with additional assumptions of nonemptiness or boundedness. -/ class ConditionallyCompleteLattice (α : Type*) extends Lattice α, SupSet α, InfSet α where /-- `a ≤ sSup s` for all `a ∈ s`. -/ le_csSup : ∀ s a, BddAbove s → a ∈ s → a ≤ sSup s /-- `sSup s ≤ a` for all `a ∈ upperBounds s`. -/ csSup_le : ∀ s a, Set.Nonempty s → a ∈ upperBounds s → sSup s ≤ a /-- `sInf s ≤ a` for all `a ∈ s`. -/ csInf_le : ∀ s a, BddBelow s → a ∈ s → sInf s ≤ a /-- `a ≤ sInf s` for all `a ∈ lowerBounds s`. -/ le_csInf : ∀ s a, Set.Nonempty s → a ∈ lowerBounds s → a ≤ sInf s /-- A conditionally complete linear order is a linear order in which every nonempty subset which is bounded above has a supremum, and every nonempty subset which is bounded below has an infimum. Typical examples are real numbers or natural numbers. To differentiate the statements from the corresponding statements in (unconditional) complete linear orders, we prefix `sInf` and `sSup` by a `c` everywhere. The same statements should hold in both worlds, sometimes with additional assumptions of nonemptiness or boundedness. -/ class ConditionallyCompleteLinearOrder (α : Type*) extends ConditionallyCompleteLattice α, Ord α where /-- A `ConditionallyCompleteLinearOrder` is total. -/ le_total (a b : α) : a ≤ b ∨ b ≤ a /-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/ toDecidableLE : DecidableLE α /-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/ toDecidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ toDecidableLE /-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/ toDecidableLT : DecidableLT α := @decidableLTOfDecidableLE _ _ toDecidableLE /-- If a set is not bounded above, its supremum is by convention `sSup ∅`. -/ csSup_of_not_bddAbove : ∀ s, ¬BddAbove s → sSup s = sSup (∅ : Set α) /-- If a set is not bounded below, its infimum is by convention `sInf ∅`. -/ csInf_of_not_bddBelow : ∀ s, ¬BddBelow s → sInf s = sInf (∅ : Set α) compare a b := compareOfLessAndEq a b /-- Comparison via `compare` is equal to the canonical comparison given decidable `<` and `=`. -/ compare_eq_compareOfLessAndEq : ∀ a b, compare a b = compareOfLessAndEq a b := by compareOfLessAndEq_rfl /-- A conditionally complete linear order with `Bot` is a linear order with least element, in which every nonempty subset which is bounded above has a supremum, and every nonempty subset (necessarily bounded below) has an infimum. A typical example is the natural numbers. To differentiate the statements from the corresponding statements in (unconditional) complete linear orders, we prefix `sInf` and `sSup` by a `c` everywhere. The same statements should hold in both worlds, sometimes with additional assumptions of nonemptiness or boundedness. -/ class ConditionallyCompleteLinearOrderBot (α : Type*) extends ConditionallyCompleteLinearOrder α, OrderBot α where /-- The supremum of the empty set is special-cased to `⊥` -/ csSup_empty : sSup ∅ = ⊥ -- see Note [lower instance priority] attribute [instance 100] ConditionallyCompleteLinearOrderBot.toOrderBot open scoped Classical in /-- A well-founded linear order is conditionally complete, with a bottom element. -/ noncomputable abbrev WellFoundedLT.conditionallyCompleteLinearOrderBot (α : Type*) [i₁ : LinearOrder α] [i₂ : OrderBot α] [h : WellFoundedLT α] : ConditionallyCompleteLinearOrderBot α := { i₁, i₂, LinearOrder.toLattice with sInf := fun s => if hs : s.Nonempty then h.wf.min s hs else ⊥ csInf_le := fun s a _ has => by have s_ne : s.Nonempty := ⟨a, has⟩ simpa [s_ne] using not_lt.1 (h.wf.not_lt_min s s_ne has) le_csInf := fun s a hs has => by simp only [hs, dif_pos] exact has (h.wf.min_mem s hs) sSup := fun s => if hs : (upperBounds s).Nonempty then h.wf.min _ hs else ⊥ le_csSup := fun s a hs has => by have h's : (upperBounds s).Nonempty := hs simp only [h's, dif_pos] exact h.wf.min_mem _ h's has csSup_le := fun s a _ has => by have h's : (upperBounds s).Nonempty := ⟨a, has⟩ simp only [h's, dif_pos] simpa using h.wf.not_lt_min _ h's has csSup_empty := by simpa using eq_bot_iff.2 (not_lt.1 <| h.wf.not_lt_min _ _ <| mem_univ ⊥) csSup_of_not_bddAbove := by intro s H have B : ¬((upperBounds s).Nonempty) := H simp only [B, dite_false, upperBounds_empty, univ_nonempty, dite_true] exact le_antisymm bot_le (WellFounded.min_le _ (mem_univ _)) csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim } /-- Create a `ConditionallyCompleteLattice` from a `PartialOrder` and `sup` function that returns the least upper bound of a nonempty set which is bounded above. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `ConditionallyCompleteLattice` instance as ``` instance : ConditionallyCompleteLattice my_T := { inf := better_inf, le_inf := ..., inf_le_right := ..., inf_le_left := ... -- don't care to fix sup, sInf ..conditionallyCompleteLatticeOfsSup my_T _ } ``` -/ def conditionallyCompleteLatticeOfsSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α] (bddAbove_pair : ∀ a b : α, BddAbove ({a, b} : Set α)) (bddBelow_pair : ∀ a b : α, BddBelow ({a, b} : Set α)) (isLUB_sSup : ∀ s : Set α, BddAbove s → s.Nonempty → IsLUB s (sSup s)) : ConditionallyCompleteLattice α := { H1, H2 with sup := fun a b => sSup {a, b} le_sup_left := fun a b => (isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).1 (mem_insert _ _) le_sup_right := fun a b => (isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).1 (mem_insert_of_mem _ (mem_singleton _)) sup_le := fun a b _ hac hbc => (isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).2 (forall_insert_of_forall (forall_eq.mpr hbc) hac) inf := fun a b => sSup (lowerBounds {a, b}) inf_le_left := fun a b => (isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩) (bddBelow_pair a b)).2 fun _ hc => hc <| mem_insert _ _ inf_le_right := fun a b => (isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩) (bddBelow_pair a b)).2 fun _ hc => hc <| mem_insert_of_mem _ (mem_singleton _) le_inf := fun c a b hca hcb => (isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩) ⟨c, forall_insert_of_forall (forall_eq.mpr hcb) hca⟩).1 (forall_insert_of_forall (forall_eq.mpr hcb) hca) sInf := fun s => sSup (lowerBounds s) csSup_le := fun s a hs ha => (isLUB_sSup s ⟨a, ha⟩ hs).2 ha le_csSup := fun s a hs ha => (isLUB_sSup s hs ⟨a, ha⟩).1 ha csInf_le := fun s a hs ha => (isLUB_sSup (lowerBounds s) (Nonempty.bddAbove_lowerBounds ⟨a, ha⟩) hs).2 fun _ hb => hb ha le_csInf := fun s a hs ha => (isLUB_sSup (lowerBounds s) hs.bddAbove_lowerBounds ⟨a, ha⟩).1 ha } /-- Create a `ConditionallyCompleteLattice` from a `PartialOrder` and `inf` function that returns the greatest lower bound of a nonempty set which is bounded below. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `ConditionallyCompleteLattice` instance as ``` instance : ConditionallyCompleteLattice my_T := { inf := better_inf, le_inf := ..., inf_le_right := ..., inf_le_left := ... -- don't care to fix sup, sSup ..conditionallyCompleteLatticeOfsInf my_T _ } ``` -/ def conditionallyCompleteLatticeOfsInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α] (bddAbove_pair : ∀ a b : α, BddAbove ({a, b} : Set α)) (bddBelow_pair : ∀ a b : α, BddBelow ({a, b} : Set α)) (isGLB_sInf : ∀ s : Set α, BddBelow s → s.Nonempty → IsGLB s (sInf s)) : ConditionallyCompleteLattice α := { H1, H2 with inf := fun a b => sInf {a, b} inf_le_left := fun a b => (isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).1 (mem_insert _ _) inf_le_right := fun a b => (isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).1 (mem_insert_of_mem _ (mem_singleton _)) le_inf := fun _ a b hca hcb => (isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).2 (forall_insert_of_forall (forall_eq.mpr hcb) hca) sup := fun a b => sInf (upperBounds {a, b}) le_sup_left := fun a b => (isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩) (bddAbove_pair a b)).2 fun _ hc => hc <| mem_insert _ _ le_sup_right := fun a b => (isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩) (bddAbove_pair a b)).2 fun _ hc => hc <| mem_insert_of_mem _ (mem_singleton _) sup_le := fun a b c hac hbc => (isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩) ⟨c, forall_insert_of_forall (forall_eq.mpr hbc) hac⟩).1 (forall_insert_of_forall (forall_eq.mpr hbc) hac) sSup := fun s => sInf (upperBounds s) le_csInf := fun s a hs ha => (isGLB_sInf s ⟨a, ha⟩ hs).2 ha csInf_le := fun s a hs ha => (isGLB_sInf s hs ⟨a, ha⟩).1 ha le_csSup := fun s a hs ha => (isGLB_sInf (upperBounds s) (Nonempty.bddBelow_upperBounds ⟨a, ha⟩) hs).2 fun _ hb => hb ha csSup_le := fun s a hs ha => (isGLB_sInf (upperBounds s) hs.bddBelow_upperBounds ⟨a, ha⟩).1 ha } /-- A version of `conditionallyCompleteLatticeOfsSup` when we already know that `α` is a lattice. This should only be used when it is both hard and unnecessary to provide `inf` explicitly. -/ def conditionallyCompleteLatticeOfLatticeOfsSup (α : Type*) [H1 : Lattice α] [SupSet α] (isLUB_sSup : ∀ s : Set α, BddAbove s → s.Nonempty → IsLUB s (sSup s)) : ConditionallyCompleteLattice α := { H1, conditionallyCompleteLatticeOfsSup α (fun a b => ⟨a ⊔ b, forall_insert_of_forall (forall_eq.mpr le_sup_right) le_sup_left⟩) (fun a b => ⟨a ⊓ b, forall_insert_of_forall (forall_eq.mpr inf_le_right) inf_le_left⟩) isLUB_sSup with } /-- A version of `conditionallyCompleteLatticeOfsInf` when we already know that `α` is a lattice. This should only be used when it is both hard and unnecessary to provide `sup` explicitly. -/ def conditionallyCompleteLatticeOfLatticeOfsInf (α : Type*) [H1 : Lattice α] [InfSet α] (isGLB_sInf : ∀ s : Set α, BddBelow s → s.Nonempty → IsGLB s (sInf s)) : ConditionallyCompleteLattice α := { H1, conditionallyCompleteLatticeOfsInf α (fun a b => ⟨a ⊔ b, forall_insert_of_forall (forall_eq.mpr le_sup_right) le_sup_left⟩) (fun a b => ⟨a ⊓ b, forall_insert_of_forall (forall_eq.mpr inf_le_right) inf_le_left⟩) isGLB_sInf with }
.lake/packages/mathlib/Mathlib/Order/ConditionallyCompleteLattice/Indexed.lean
import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # Indexed sup / inf in conditionally complete lattices This file proves lemmas about `iSup` and `iInf` for functions valued in a conditionally complete, rather than complete, lattice. We add a prefix `c` to distinguish them from the versions for complete lattices, giving names `ciSup_xxx` or `ciInf_xxx`. -/ -- Guard against import creep assert_not_exists Multiset open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} section /-! Extension of `iSup` and `iInf` from a preorder `α` to `WithTop α` and `WithBot α` -/ variable [Preorder α] @[simp] theorem WithTop.iInf_empty [IsEmpty ι] [InfSet α] (f : ι → WithTop α) : ⨅ i, f i = ⊤ := by rw [iInf, range_eq_empty, WithTop.sInf_empty] @[norm_cast] theorem WithTop.coe_iInf [Nonempty ι] [InfSet α] {f : ι → α} (hf : BddBelow (range f)) : ↑(⨅ i, f i) = (⨅ i, f i : WithTop α) := by rw [iInf, iInf, WithTop.coe_sInf' (range_nonempty f) hf, ← range_comp, Function.comp_def] @[norm_cast] theorem WithTop.coe_iSup [SupSet α] (f : ι → α) (h : BddAbove (Set.range f)) : ↑(⨆ i, f i) = (⨆ i, f i : WithTop α) := by rw [iSup, iSup, WithTop.coe_sSup' h, ← range_comp, Function.comp_def] @[simp] theorem WithBot.ciSup_empty [IsEmpty ι] [SupSet α] (f : ι → WithBot α) : ⨆ i, f i = ⊥ := WithTop.iInf_empty (α := αᵒᵈ) _ @[norm_cast] theorem WithBot.coe_iSup [Nonempty ι] [SupSet α] {f : ι → α} (hf : BddAbove (range f)) : ↑(⨆ i, f i) = (⨆ i, f i : WithBot α) := WithTop.coe_iInf (α := αᵒᵈ) hf @[norm_cast] theorem WithBot.coe_iInf [InfSet α] (f : ι → α) (h : BddBelow (Set.range f)) : ↑(⨅ i, f i) = (⨅ i, f i : WithBot α) := WithTop.coe_iSup (α := αᵒᵈ) _ h end section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {a b : α} theorem isLUB_ciSup [Nonempty ι] {f : ι → α} (H : BddAbove (range f)) : IsLUB (range f) (⨆ i, f i) := isLUB_csSup (range_nonempty f) H theorem isLUB_ciSup_set {f : β → α} {s : Set β} (H : BddAbove (f '' s)) (Hne : s.Nonempty) : IsLUB (f '' s) (⨆ i : s, f i) := by rw [← sSup_image'] exact isLUB_csSup (Hne.image _) H theorem isGLB_ciInf [Nonempty ι] {f : ι → α} (H : BddBelow (range f)) : IsGLB (range f) (⨅ i, f i) := isGLB_csInf (range_nonempty f) H theorem isGLB_ciInf_set {f : β → α} {s : Set β} (H : BddBelow (f '' s)) (Hne : s.Nonempty) : IsGLB (f '' s) (⨅ i : s, f i) := isLUB_ciSup_set (α := αᵒᵈ) H Hne theorem ciSup_le_iff [Nonempty ι] {f : ι → α} {a : α} (hf : BddAbove (range f)) : iSup f ≤ a ↔ ∀ i, f i ≤ a := (isLUB_le_iff <| isLUB_ciSup hf).trans forall_mem_range theorem le_ciInf_iff [Nonempty ι] {f : ι → α} {a : α} (hf : BddBelow (range f)) : a ≤ iInf f ↔ ∀ i, a ≤ f i := (le_isGLB_iff <| isGLB_ciInf hf).trans forall_mem_range theorem ciSup_set_le_iff {ι : Type*} {s : Set ι} {f : ι → α} {a : α} (hs : s.Nonempty) (hf : BddAbove (f '' s)) : ⨆ i : s, f i ≤ a ↔ ∀ i ∈ s, f i ≤ a := (isLUB_le_iff <| isLUB_ciSup_set hf hs).trans forall_mem_image theorem le_ciInf_set_iff {ι : Type*} {s : Set ι} {f : ι → α} {a : α} (hs : s.Nonempty) (hf : BddBelow (f '' s)) : (a ≤ ⨅ i : s, f i) ↔ ∀ i ∈ s, a ≤ f i := (le_isGLB_iff <| isGLB_ciInf_set hf hs).trans forall_mem_image theorem IsLUB.ciSup_eq [Nonempty ι] {f : ι → α} (H : IsLUB (range f) a) : ⨆ i, f i = a := H.csSup_eq (range_nonempty f) theorem IsLUB.ciSup_set_eq {s : Set β} {f : β → α} (H : IsLUB (f '' s) a) (Hne : s.Nonempty) : ⨆ i : s, f i = a := IsLUB.csSup_eq (image_eq_range f s ▸ H) (image_eq_range f s ▸ Hne.image f) theorem IsGLB.ciInf_eq [Nonempty ι] {f : ι → α} (H : IsGLB (range f) a) : ⨅ i, f i = a := H.csInf_eq (range_nonempty f) theorem IsGLB.ciInf_set_eq {s : Set β} {f : β → α} (H : IsGLB (f '' s) a) (Hne : s.Nonempty) : ⨅ i : s, f i = a := IsGLB.csInf_eq (image_eq_range f s ▸ H) (image_eq_range f s ▸ Hne.image f) /-- The indexed supremum of a function is bounded above by a uniform bound -/ theorem ciSup_le [Nonempty ι] {f : ι → α} {c : α} (H : ∀ x, f x ≤ c) : iSup f ≤ c := csSup_le (range_nonempty f) (by rwa [forall_mem_range]) /-- The indexed supremum of a function is bounded below by the value taken at one point -/ theorem le_ciSup {f : ι → α} (H : BddAbove (range f)) (c : ι) : f c ≤ iSup f := le_csSup H (mem_range_self _) theorem le_ciSup_of_le {f : ι → α} (H : BddAbove (range f)) (c : ι) (h : a ≤ f c) : a ≤ iSup f := le_trans h (le_ciSup H c) /-- The indexed suprema of two functions are comparable if the functions are pointwise comparable -/ @[gcongr low] theorem ciSup_mono {f g : ι → α} (B : BddAbove (range g)) (H : ∀ x, f x ≤ g x) : iSup f ≤ iSup g := by cases isEmpty_or_nonempty ι · rw [iSup_of_empty', iSup_of_empty'] · exact ciSup_le fun x => le_ciSup_of_le B x (H x) theorem le_ciSup_set {f : β → α} {s : Set β} (H : BddAbove (f '' s)) {c : β} (hc : c ∈ s) : f c ≤ ⨆ i : s, f i := (le_csSup H <| mem_image_of_mem f hc).trans_eq sSup_image' /-- The indexed infimum of two functions are comparable if the functions are pointwise comparable -/ @[gcongr low] theorem ciInf_mono {f g : ι → α} (B : BddBelow (range f)) (H : ∀ x, f x ≤ g x) : iInf f ≤ iInf g := ciSup_mono (α := αᵒᵈ) B H /-- The indexed minimum of a function is bounded below by a uniform lower bound -/ theorem le_ciInf [Nonempty ι] {f : ι → α} {c : α} (H : ∀ x, c ≤ f x) : c ≤ iInf f := ciSup_le (α := αᵒᵈ) H /-- The indexed infimum of a function is bounded above by the value taken at one point -/ theorem ciInf_le {f : ι → α} (H : BddBelow (range f)) (c : ι) : iInf f ≤ f c := le_ciSup (α := αᵒᵈ) H c theorem ciInf_le_of_le {f : ι → α} (H : BddBelow (range f)) (c : ι) (h : f c ≤ a) : iInf f ≤ a := le_ciSup_of_le (α := αᵒᵈ) H c h theorem ciInf_set_le {f : β → α} {s : Set β} (H : BddBelow (f '' s)) {c : β} (hc : c ∈ s) : ⨅ i : s, f i ≤ f c := le_ciSup_set (α := αᵒᵈ) H hc lemma ciInf_le_ciSup [Nonempty ι] {f : ι → α} (hf : BddBelow (range f)) (hf' : BddAbove (range f)) : ⨅ i, f i ≤ ⨆ i, f i := (ciInf_le hf (Classical.arbitrary _)).trans <| le_ciSup hf' (Classical.arbitrary _) @[simp] theorem ciSup_const [hι : Nonempty ι] {a : α} : ⨆ _ : ι, a = a := by rw [iSup, range_const, csSup_singleton] @[simp] theorem ciInf_const [Nonempty ι] {a : α} : ⨅ _ : ι, a = a := ciSup_const (α := αᵒᵈ) @[simp] theorem ciSup_unique [Unique ι] {s : ι → α} : ⨆ i, s i = s default := by have : ∀ i, s i = s default := fun i => congr_arg s (Unique.eq_default i) simp only [this, ciSup_const] @[simp] theorem ciInf_unique [Unique ι] {s : ι → α} : ⨅ i, s i = s default := ciSup_unique (α := αᵒᵈ) theorem ciSup_subsingleton [Subsingleton ι] (i : ι) (s : ι → α) : ⨆ i, s i = s i := @ciSup_unique α ι _ ⟨⟨i⟩, fun j => Subsingleton.elim j i⟩ _ theorem ciInf_subsingleton [Subsingleton ι] (i : ι) (s : ι → α) : ⨅ i, s i = s i := @ciInf_unique α ι _ ⟨⟨i⟩, fun j => Subsingleton.elim j i⟩ _ theorem ciSup_pos {p : Prop} {f : p → α} (hp : p) : ⨆ h : p, f h = f hp := by simp [hp] theorem ciInf_pos {p : Prop} {f : p → α} (hp : p) : ⨅ h : p, f h = f hp := by simp [hp] lemma ciSup_neg {p : Prop} {f : p → α} (hp : ¬ p) : ⨆ (h : p), f h = sSup (∅ : Set α) := by rw [iSup] congr rwa [range_eq_empty_iff, isEmpty_Prop] lemma ciInf_neg {p : Prop} {f : p → α} (hp : ¬ p) : ⨅ (h : p), f h = sInf (∅ : Set α) := ciSup_neg (α := αᵒᵈ) hp lemma ciSup_eq_ite {p : Prop} [Decidable p] {f : p → α} : (⨆ h : p, f h) = if h : p then f h else sSup (∅ : Set α) := by by_cases H : p <;> simp [ciSup_neg, H] lemma ciInf_eq_ite {p : Prop} [Decidable p] {f : p → α} : (⨅ h : p, f h) = if h : p then f h else sInf (∅ : Set α) := ciSup_eq_ite (α := αᵒᵈ) theorem cbiSup_eq_of_forall {p : ι → Prop} {f : Subtype p → α} (hp : ∀ i, p i) : ⨆ (i) (h : p i), f ⟨i, h⟩ = iSup f := by simp only [hp, ciSup_unique] simp only [iSup] congr apply Subset.antisymm · rintro - ⟨i, rfl⟩ simp · rintro - ⟨i, rfl⟩ simp theorem cbiInf_eq_of_forall {p : ι → Prop} {f : Subtype p → α} (hp : ∀ i, p i) : ⨅ (i) (h : p i), f ⟨i, h⟩ = iInf f := cbiSup_eq_of_forall (α := αᵒᵈ) hp /-- Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b` is larger than `f i` for all `i`, and that this is not the case of any `w<b`. See `iSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/ theorem ciSup_eq_of_forall_le_of_forall_lt_exists_gt [Nonempty ι] {f : ι → α} (h₁ : ∀ i, f i ≤ b) (h₂ : ∀ w, w < b → ∃ i, w < f i) : ⨆ i : ι, f i = b := csSup_eq_of_forall_le_of_forall_lt_exists_gt (range_nonempty f) (forall_mem_range.mpr h₁) fun w hw => exists_range_iff.mpr <| h₂ w hw /-- Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b` is smaller than `f i` for all `i`, and that this is not the case of any `w>b`. See `iInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/ theorem ciInf_eq_of_forall_ge_of_forall_gt_exists_lt [Nonempty ι] {f : ι → α} (h₁ : ∀ i, b ≤ f i) (h₂ : ∀ w, b < w → ∃ i, f i < w) : ⨅ i : ι, f i = b := ciSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ) h₁ h₂ /-- **Nested intervals lemma**: if `f` is a monotone sequence, `g` is an antitone sequence, and `f n ≤ g n` for all `n`, then `⨆ n, f n` belongs to all the intervals `[f n, g n]`. -/ theorem Monotone.ciSup_mem_iInter_Icc_of_antitone [SemilatticeSup β] {f g : β → α} (hf : Monotone f) (hg : Antitone g) (h : f ≤ g) : (⨆ n, f n) ∈ ⋂ n, Icc (f n) (g n) := by refine mem_iInter.2 fun n => ?_ haveI : Nonempty β := ⟨n⟩ have : ∀ m, f m ≤ g n := fun m => hf.forall_le_of_antitone hg h m n exact ⟨le_ciSup ⟨g <| n, forall_mem_range.2 this⟩ _, ciSup_le this⟩ /-- Nested intervals lemma: if `[f n, g n]` is an antitone sequence of nonempty closed intervals, then `⨆ n, f n` belongs to all the intervals `[f n, g n]`. -/ theorem ciSup_mem_iInter_Icc_of_antitone_Icc [SemilatticeSup β] {f g : β → α} (h : Antitone fun n => Icc (f n) (g n)) (h' : ∀ n, f n ≤ g n) : (⨆ n, f n) ∈ ⋂ n, Icc (f n) (g n) := Monotone.ciSup_mem_iInter_Icc_of_antitone (fun _ n hmn => ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).1) (fun _ n hmn => ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).2) h' lemma Set.Iic_ciInf [Nonempty ι] {f : ι → α} (hf : BddBelow (range f)) : Iic (⨅ i, f i) = ⋂ i, Iic (f i) := by apply Subset.antisymm · rintro x hx - ⟨i, rfl⟩ exact hx.trans (ciInf_le hf _) · rintro x hx apply le_ciInf simpa using hx lemma Set.Ici_ciSup [Nonempty ι] {f : ι → α} (hf : BddAbove (range f)) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) := Iic_ciInf (α := αᵒᵈ) hf theorem ciSup_Iic [Preorder β] {f : β → α} (a : β) (hf : Monotone f) : ⨆ x : Iic a, f x = f a := by have H : BddAbove (range fun x : Iic a ↦ f x) := ⟨f a, fun _ ↦ by aesop⟩ apply (le_ciSup H (⟨a, le_refl a⟩ : Iic a)).antisymm' rw [ciSup_le_iff H] rintro ⟨a, h⟩ exact hf h theorem ciInf_Ici [Preorder β] {f : β → α} (a : β) (hf : Monotone f) : ⨅ x : Ici a, f x = f a := by have H : BddBelow (range fun x : Ici a ↦ f x) := ⟨f a, fun _ ↦ by aesop⟩ apply (ciInf_le H (⟨a, le_refl a⟩ : Ici a)).antisymm rw [le_ciInf_iff H] rintro ⟨a, h⟩ exact hf h theorem ciSup_subtype [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : Subtype p → α} (hf : BddAbove (Set.range f)) (hf' : sSup ∅ ≤ iSup f) : iSup f = ⨆ (i) (h : p i), f ⟨i, h⟩ := by classical refine le_antisymm (ciSup_le ?_) ?_ · intro ⟨i, h⟩ have : f ⟨i, h⟩ = (fun i : ι ↦ ⨆ (h : p i), f ⟨i, h⟩) i := by simp [h] rw [this] refine le_ciSup (f := (fun i : ι ↦ ⨆ (h : p i), f ⟨i, h⟩)) ?_ i simp_rw [ciSup_eq_ite] refine (hf.union (bddAbove_singleton (a := sSup ∅))).mono ?_ intro simp only [Set.mem_range, Set.union_singleton, Set.mem_insert_iff, Subtype.exists, forall_exists_index] intro b hb split_ifs at hb · exact Or.inr ⟨_, _, hb⟩ · simp_all · refine ciSup_le fun i ↦ ?_ simp_rw [ciSup_eq_ite] split_ifs · exact le_ciSup hf ?_ · exact hf' theorem ciInf_subtype [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : Subtype p → α} (hf : BddBelow (Set.range f)) (hf' : iInf f ≤ sInf ∅) : iInf f = ⨅ (i) (h : p i), f ⟨i, h⟩ := ciSup_subtype (α := αᵒᵈ) hf hf' theorem ciSup_subtype' [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : ∀ i, p i → α} (hf : BddAbove (Set.range (fun i : Subtype p ↦ f i i.prop))) (hf' : sSup ∅ ≤ ⨆ (i : Subtype p), f i i.prop) : ⨆ (i) (h), f i h = ⨆ x : Subtype p, f x x.property := (ciSup_subtype (f := fun x => f x.val x.property) hf hf').symm theorem ciInf_subtype' [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : ∀ i, p i → α} (hf : BddBelow (Set.range (fun i : Subtype p ↦ f i i.prop))) (hf' : ⨅ (i : Subtype p), f i i.prop ≤ sInf ∅) : ⨅ (i) (h), f i h = ⨅ x : Subtype p, f x x.property := (ciInf_subtype (f := fun x => f x.val x.property) hf hf').symm theorem ciSup_subtype'' {ι} [Nonempty ι] {s : Set ι} (hs : s.Nonempty) {f : ι → α} (hf : BddAbove (Set.range fun i : s ↦ f i)) (hf' : sSup ∅ ≤ ⨆ i : s, f i) : ⨆ i : s, f i = ⨆ (t : ι) (_ : t ∈ s), f t := haveI : Nonempty s := Set.Nonempty.to_subtype hs ciSup_subtype hf hf' theorem ciInf_subtype'' {ι} [Nonempty ι] {s : Set ι} (hs : s.Nonempty) {f : ι → α} (hf : BddBelow (Set.range fun i : s ↦ f i)) (hf' : ⨅ i : s, f i ≤ sInf ∅) : ⨅ i : s, f i = ⨅ (t : ι) (_ : t ∈ s), f t := haveI : Nonempty s := Set.Nonempty.to_subtype hs ciInf_subtype hf hf' theorem csSup_image [Nonempty β] {s : Set β} (hs : s.Nonempty) {f : β → α} (hf : BddAbove (Set.range fun i : s ↦ f i)) (hf' : sSup ∅ ≤ ⨆ i : s, f i) : sSup (f '' s) = ⨆ a ∈ s, f a := by rw [← ciSup_subtype'' hs hf hf', iSup, Set.image_eq_range] theorem csInf_image [Nonempty β] {s : Set β} (hs : s.Nonempty) {f : β → α} (hf : BddBelow (Set.range fun i : s ↦ f i)) (hf' : ⨅ i : s, f i ≤ sInf ∅) : sInf (f '' s) = ⨅ a ∈ s, f a := csSup_image (α := αᵒᵈ) hs hf hf' lemma ciSup_image {α ι ι' : Type*} [ConditionallyCompleteLattice α] [Nonempty ι] [Nonempty ι'] {s : Set ι} (hs : s.Nonempty) {f : ι → ι'} {g : ι' → α} (hf : BddAbove (Set.range fun i : s ↦ g (f i))) (hg' : sSup ∅ ≤ ⨆ i : s, g (f i)) : ⨆ i ∈ (f '' s), g i = ⨆ x ∈ s, g (f x) := by have hg : BddAbove (Set.range fun i : f '' s ↦ g i) := by simpa [bddAbove_def] using hf have hf' : sSup ∅ ≤ ⨆ i : f '' s, g i := by refine hg'.trans ?_ have : Nonempty s := Set.Nonempty.to_subtype hs refine ciSup_le ?_ intro ⟨i, h⟩ obtain ⟨t, ht⟩ : ∃ t : f '' s, g t = g (f (Subtype.mk i h)) := by have : f i ∈ f '' s := Set.mem_image_of_mem _ h exact ⟨⟨f i, this⟩, by simp⟩ rw [← ht] refine le_ciSup_set ?_ t.prop simpa [bddAbove_def] using hf rw [← csSup_image (by simpa using hs) hg hf', ← csSup_image hs hf hg', ← Set.image_comp, comp_def] lemma ciInf_image {α ι ι' : Type*} [ConditionallyCompleteLattice α] [Nonempty ι] [Nonempty ι'] {s : Set ι} (hs : s.Nonempty) {f : ι → ι'} {g : ι' → α} (hf : BddBelow (Set.range fun i : s ↦ g (f i))) (hg' : ⨅ i : s, g (f i) ≤ sInf ∅) : ⨅ i ∈ (f '' s), g i = ⨅ x ∈ s, g (f x) := ciSup_image (α := αᵒᵈ) hs hf hg' end ConditionallyCompleteLattice section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] {a b : α} /-- Indexed version of `exists_lt_of_lt_csSup`. When `b < iSup f`, there is an element `i` such that `b < f i`. -/ theorem exists_lt_of_lt_ciSup [Nonempty ι] {f : ι → α} (h : b < iSup f) : ∃ i, b < f i := let ⟨_, ⟨i, rfl⟩, h⟩ := exists_lt_of_lt_csSup (range_nonempty f) h ⟨i, h⟩ /-- Indexed version of `exists_lt_of_csInf_lt`. When `iInf f < a`, there is an element `i` such that `f i < a`. -/ theorem exists_lt_of_ciInf_lt [Nonempty ι] {f : ι → α} (h : iInf f < a) : ∃ i, f i < a := exists_lt_of_lt_ciSup (α := αᵒᵈ) h theorem lt_ciSup_iff [Nonempty ι] {f : ι → α} (hb : BddAbove (range f)) : a < iSup f ↔ ∃ i, a < f i := by simpa only [mem_range, exists_exists_eq_and] using lt_csSup_iff hb (range_nonempty _) theorem ciInf_lt_iff [Nonempty ι] {f : ι → α} (hb : BddBelow (range f)) : iInf f < a ↔ ∃ i, f i < a := by simpa only [mem_range, exists_exists_eq_and] using csInf_lt_iff hb (range_nonempty _) theorem cbiSup_eq_of_not_forall {p : ι → Prop} {f : Subtype p → α} (hp : ¬ (∀ i, p i)) : ⨆ (i) (h : p i), f ⟨i, h⟩ = iSup f ⊔ sSup ∅ := by classical rcases not_forall.1 hp with ⟨i₀, hi₀⟩ have : Nonempty ι := ⟨i₀⟩ simp only [ciSup_eq_ite] by_cases H : BddAbove (range f) · have B : BddAbove (range fun i ↦ if h : p i then f ⟨i, h⟩ else sSup ∅) := by rcases H with ⟨c, hc⟩ refine ⟨c ⊔ sSup ∅, ?_⟩ rintro - ⟨i, rfl⟩ by_cases hi : p i · simp only [hi, dite_true, le_sup_iff, hc (mem_range_self _), true_or] · simp only [hi, dite_false, le_sup_right] apply le_antisymm · apply ciSup_le (fun i ↦ ?_) by_cases hi : p i · simp only [hi, dite_true, le_sup_iff] left exact le_ciSup H _ · simp [hi] · apply sup_le · rcases isEmpty_or_nonempty (Subtype p) with hp | hp · rw [iSup_of_empty'] convert le_ciSup B i₀ simp [hi₀] · apply ciSup_le rintro ⟨i, hi⟩ convert le_ciSup B i simp [hi] · convert le_ciSup B i₀ simp [hi₀] · have : iSup f = sSup (∅ : Set α) := csSup_of_not_bddAbove H simp only [this, le_refl, sup_of_le_left] apply csSup_of_not_bddAbove contrapose! H apply H.mono rintro - ⟨i, rfl⟩ convert mem_range_self i.1 simp [i.2] theorem cbiInf_eq_of_not_forall {p : ι → Prop} {f : Subtype p → α} (hp : ¬ (∀ i, p i)) : ⨅ (i) (h : p i), f ⟨i, h⟩ = iInf f ⊓ sInf ∅ := cbiSup_eq_of_not_forall (α := αᵒᵈ) hp theorem ciInf_eq_bot_of_bot_mem [OrderBot α] {f : ι → α} (hs : ⊥ ∈ range f) : iInf f = ⊥ := csInf_eq_bot_of_bot_mem hs theorem ciInf_eq_top_of_top_mem [OrderTop α] {f : ι → α} (hs : ⊤ ∈ range f) : iSup f = ⊤ := csSup_eq_top_of_top_mem hs variable [WellFoundedLT α] theorem ciInf_mem [Nonempty ι] (f : ι → α) : iInf f ∈ range f := csInf_mem (range_nonempty f) end ConditionallyCompleteLinearOrder /-! ### Lemmas about a conditionally complete linear order with bottom element In this case we have `Sup ∅ = ⊥`, so we can drop some `Nonempty`/`Set.Nonempty` assumptions. -/ section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot α] {f : ι → α} {a : α} @[simp] theorem ciSup_of_empty [IsEmpty ι] (f : ι → α) : ⨆ i, f i = ⊥ := by rw [iSup_of_empty', csSup_empty] theorem ciSup_false (f : False → α) : ⨆ i, f i = ⊥ := ciSup_of_empty f theorem le_ciSup_iff' {s : ι → α} {a : α} (h : BddAbove (range s)) : a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by simp [iSup, h, le_csSup_iff', upperBounds] theorem le_ciInf_iff' [Nonempty ι] {f : ι → α} {a : α} : a ≤ iInf f ↔ ∀ i, a ≤ f i := le_ciInf_iff (OrderBot.bddBelow _) theorem ciInf_le' (f : ι → α) (i : ι) : iInf f ≤ f i := ciInf_le (OrderBot.bddBelow _) _ lemma ciInf_le_of_le' (c : ι) : f c ≤ a → iInf f ≤ a := ciInf_le_of_le (OrderBot.bddBelow _) _ /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `ciSup_le_iff`. -/ theorem ciSup_le_iff' {f : ι → α} (h : BddAbove (range f)) {a : α} : ⨆ i, f i ≤ a ↔ ∀ i, f i ≤ a := (csSup_le_iff' h).trans forall_mem_range theorem ciSup_le' {f : ι → α} {a : α} (h : ∀ i, f i ≤ a) : ⨆ i, f i ≤ a := csSup_le' <| forall_mem_range.2 h /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `lt_ciSup_iff`. -/ theorem lt_ciSup_iff' {f : ι → α} (h : BddAbove (range f)) : a < iSup f ↔ ∃ i, a < f i := by simpa only [not_le, not_forall] using (ciSup_le_iff' h).not theorem exists_lt_of_lt_ciSup' {f : ι → α} {a : α} (h : a < ⨆ i, f i) : ∃ i, a < f i := by contrapose! h exact ciSup_le' h theorem ciSup_mono' {ι'} {f : ι → α} {g : ι' → α} (hg : BddAbove (range g)) (h : ∀ i, ∃ i', f i ≤ g i') : iSup f ≤ iSup g := ciSup_le' fun i => Exists.elim (h i) (le_ciSup_of_le hg) lemma ciSup_or' (p q : Prop) (f : p ∨ q → α) : ⨆ (h : p ∨ q), f h = (⨆ h : p, f (.inl h)) ⊔ ⨆ h : q, f (.inr h) := by by_cases hp : p <;> by_cases hq : q <;> simp [hp, hq] end ConditionallyCompleteLinearOrderBot namespace GaloisConnection variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι] {l : α → β} {u : β → α} theorem l_csSup (gc : GaloisConnection l u) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) : l (sSup s) = ⨆ x : s, l x := Eq.symm <| IsLUB.ciSup_set_eq (gc.isLUB_l_image <| isLUB_csSup hne hbdd) hne theorem l_csSup' (gc : GaloisConnection l u) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) : l (sSup s) = sSup (l '' s) := by rw [gc.l_csSup hne hbdd, sSup_image'] theorem l_ciSup (gc : GaloisConnection l u) {f : ι → α} (hf : BddAbove (range f)) : l (⨆ i, f i) = ⨆ i, l (f i) := by rw [iSup, gc.l_csSup (range_nonempty _) hf, iSup_range'] theorem l_ciSup_set (gc : GaloisConnection l u) {s : Set γ} {f : γ → α} (hf : BddAbove (f '' s)) (hne : s.Nonempty) : l (⨆ i : s, f i) = ⨆ i : s, l (f i) := by haveI := hne.to_subtype rw [image_eq_range] at hf exact gc.l_ciSup hf theorem u_csInf (gc : GaloisConnection l u) {s : Set β} (hne : s.Nonempty) (hbdd : BddBelow s) : u (sInf s) = ⨅ x : s, u x := gc.dual.l_csSup hne hbdd theorem u_csInf' (gc : GaloisConnection l u) {s : Set β} (hne : s.Nonempty) (hbdd : BddBelow s) : u (sInf s) = sInf (u '' s) := gc.dual.l_csSup' hne hbdd theorem u_ciInf (gc : GaloisConnection l u) {f : ι → β} (hf : BddBelow (range f)) : u (⨅ i, f i) = ⨅ i, u (f i) := gc.dual.l_ciSup hf theorem u_ciInf_set (gc : GaloisConnection l u) {s : Set γ} {f : γ → β} (hf : BddBelow (f '' s)) (hne : s.Nonempty) : u (⨅ i : s, f i) = ⨅ i : s, u (f i) := gc.dual.l_ciSup_set hf hne end GaloisConnection namespace OrderIso section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι] theorem map_csSup (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) : e (sSup s) = ⨆ x : s, e x := e.to_galoisConnection.l_csSup hne hbdd theorem map_csSup' (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) : e (sSup s) = sSup (e '' s) := e.to_galoisConnection.l_csSup' hne hbdd theorem map_ciSup (e : α ≃o β) {f : ι → α} (hf : BddAbove (range f)) : e (⨆ i, f i) = ⨆ i, e (f i) := e.to_galoisConnection.l_ciSup hf theorem map_ciSup_set (e : α ≃o β) {s : Set γ} {f : γ → α} (hf : BddAbove (f '' s)) (hne : s.Nonempty) : e (⨆ i : s, f i) = ⨆ i : s, e (f i) := e.to_galoisConnection.l_ciSup_set hf hne theorem map_csInf (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddBelow s) : e (sInf s) = ⨅ x : s, e x := e.dual.map_csSup hne hbdd theorem map_csInf' (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddBelow s) : e (sInf s) = sInf (e '' s) := e.dual.map_csSup' hne hbdd theorem map_ciInf (e : α ≃o β) {f : ι → α} (hf : BddBelow (range f)) : e (⨅ i, f i) = ⨅ i, e (f i) := e.dual.map_ciSup hf theorem map_ciInf_set (e : α ≃o β) {s : Set γ} {f : γ → α} (hf : BddBelow (f '' s)) (hne : s.Nonempty) : e (⨅ i : s, f i) = ⨅ i : s, e (f i) := e.dual.map_ciSup_set hf hne end ConditionallyCompleteLattice section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot α] [ConditionallyCompleteLinearOrderBot β] @[simp] lemma map_ciSup' (e : α ≃o β) (f : ι → α) : e (⨆ i, f i) = ⨆ i, e (f i) := by cases isEmpty_or_nonempty ι · simp [map_bot] by_cases hf : BddAbove (range f) · exact e.map_ciSup hf · have hfe : ¬ BddAbove (range fun i ↦ e (f i)) := by simpa [Set.Nonempty, BddAbove, upperBounds, e.surjective.forall] using hf simp [map_bot, hf, hfe] end ConditionallyCompleteLinearOrderBot end OrderIso section WithTopBot namespace WithTop variable [ConditionallyCompleteLinearOrderBot α] {f : ι → α} lemma iSup_coe_eq_top : ⨆ x, (f x : WithTop α) = ⊤ ↔ ¬BddAbove (range f) := by rw [iSup_eq_top, not_bddAbove_iff] refine ⟨fun hf r => ?_, fun hf a ha => ?_⟩ · rcases hf r (WithTop.coe_lt_top r) with ⟨i, hi⟩ exact ⟨f i, ⟨i, rfl⟩, WithTop.coe_lt_coe.mp hi⟩ · rcases hf (a.untop ha.ne) with ⟨-, ⟨i, rfl⟩, hi⟩ exact ⟨i, by simpa only [WithTop.coe_untop _ ha.ne] using WithTop.coe_lt_coe.mpr hi⟩ lemma iSup_coe_lt_top : ⨆ x, (f x : WithTop α) < ⊤ ↔ BddAbove (range f) := lt_top_iff_ne_top.trans iSup_coe_eq_top.not_left lemma iInf_coe_eq_top : ⨅ x, (f x : WithTop α) = ⊤ ↔ IsEmpty ι := by simp [isEmpty_iff] lemma iInf_coe_lt_top : ⨅ i, (f i : WithTop α) < ⊤ ↔ Nonempty ι := by rw [lt_top_iff_ne_top, Ne, iInf_coe_eq_top, not_isEmpty_iff] end WithTop end WithTopBot
.lake/packages/mathlib/Mathlib/Order/Filter/Finite.lean
import Mathlib.Data.Set.Finite.Lattice import Mathlib.Order.CompleteLattice.Finset import Mathlib.Order.Filter.Basic /-! # Results relating filters to finiteness This file proves that finitely many conditions eventually hold if each of them eventually holds. -/ open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} @[simp] theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by induction is, hf using Set.Finite.induction_on with | empty => simp | insert _ _ hs => simp [hs] @[simp] theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := biInter_mem is.finite_toSet protected alias _root_.Finset.iInter_mem_sets := biInter_finset_mem @[simp] theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by rw [sInter_eq_biInter, biInter_mem hfin] @[simp] theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := (sInter_mem (finite_range _)).trans forall_mem_range end Filter namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} section Lattice variable {f g : Filter α} {s t : Set α} theorem mem_generate_iff {s : Set <| Set α} {U : Set α} : U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by constructor <;> intro h · induction h with | @basic V V_in => exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩ | univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩ | superset _ hVW hV => rcases hV with ⟨t, hts, ht, htV⟩ exact ⟨t, hts, ht, htV.trans hVW⟩ | inter _ _ hV hW => rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩ exact ⟨t ∪ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩ · rcases h with ⟨t, hts, tfin, h⟩ exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite) {V : I → Set α} (hV : ∀ (i : I), V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by haveI := I_fin.fintype refine mem_of_superset (iInter_mem.2 fun i => ?_) hU exact mem_iInf_of_mem (i : ι) (hV _) theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ (i : I), V i ∈ s i) ∧ U = ⋂ i, V i := by constructor · rw [iInf_eq_generate, mem_generate_iff] rintro ⟨t, tsub, tfin, tinter⟩ rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩ rw [sInter_iUnion] at tinter set V := fun i => U ∪ ⋂₀ σ i with hV have V_in : ∀ (i : I), V i ∈ s i := by rintro i have : ⋂₀ σ i ∈ s i := by rw [sInter_mem (σfin _)] apply σsub exact mem_of_superset this subset_union_right refine ⟨I, Ifin, V, V_in, ?_⟩ rwa [hV, ← union_iInter, union_eq_self_of_subset_right] · rintro ⟨I, Ifin, V, V_in, rfl⟩ exact mem_iInf_of_iInter Ifin V_in Subset.rfl theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧ (∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by classical simp only [mem_iInf, biInter_eq_iInter] refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩ rintro ⟨I, If, V, hV, rfl⟩ refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩ · dsimp only split_ifs exacts [hV ⟨i,_⟩, univ_mem] · exact dif_neg hi · simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta, iInter_univ, inter_univ, true_and] theorem exists_iInter_of_mem_iInf {ι : Sort*} {α : Type*} {f : ι → Filter α} {s} (hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by rw [← iInf_range' (g := (·))] at hs let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs use V ∘ rangeFactorization f, fun i ↦ hVs (rangeFactorization f i) rw [hVU', ← rangeFactorization_surjective.iInter_comp, comp_def] theorem mem_iInf_of_finite {ι : Sort*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) : (s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by refine ⟨exists_iInter_of_mem_iInf, ?_⟩ rintro ⟨t, ht, rfl⟩ exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i) theorem mem_biInf_principal {ι : Type*} {p : ι → Prop} {s : ι → Set α} {t : Set α} : t ∈ ⨅ (i : ι) (_ : p i), 𝓟 (s i) ↔ ∃ I : Set ι, I.Finite ∧ (∀ i ∈ I, p i) ∧ ⋂ i ∈ I, s i ⊆ t := by constructor · simp only [mem_iInf (ι := ι), mem_iInf_of_finite, mem_principal] rintro ⟨I, hIf, V, hV₁, hV₂, rfl⟩ choose! t ht₁ ht₂ using hV₁ refine ⟨I ∩ {i | p i}, hIf.inter_of_left _, fun i ↦ And.right, ?_⟩ simp only [mem_inter_iff, iInter_and, biInter_eq_iInter, ht₂, mem_setOf_eq] gcongr with i hpi exact ht₁ i hpi · rintro ⟨I, hIf, hpI, hst⟩ rw [biInter_eq_iInter] at hst refine mem_iInf_of_iInter hIf (fun i ↦ ?_) hst simp [hpI i i.2] /-! ### Lattice equations -/ theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α} (hd : Pairwise (Disjoint on l)) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd choose! s t hst using this refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩ exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2, (hst hij).mono ((iInter_subset _ j).trans inter_subset_left) ((iInter_subset _ i).trans inter_subset_right)] theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι} (hd : t.PairwiseDisjoint l) (ht : t.Finite) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by haveI := ht.to_subtype rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩ lift s to (i : t) → {s // s ∈ l i} using hsl rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩ exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩ theorem iInf_sets_eq_finite {ι : Type*} (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset ι, (⨅ i ∈ t, f i).sets := by rw [iInf_eq_iInf_finset, iInf_sets_eq] exact directed_of_isDirected_le fun _ _ => biInf_mono theorem iInf_sets_eq_finite' (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset (PLift ι), (⨅ i ∈ t, f (PLift.down i)).sets := by rw [← iInf_sets_eq_finite, ← Equiv.plift.surjective.iInf_comp, Equiv.plift_apply] theorem mem_iInf_finite {ι : Type*} {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset ι, s ∈ ⨅ i ∈ t, f i := (Set.ext_iff.1 (iInf_sets_eq_finite f) s).trans mem_iUnion theorem mem_iInf_finite' {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset (PLift ι), s ∈ ⨅ i ∈ t, f (PLift.down i) := (Set.ext_iff.1 (iInf_sets_eq_finite' f) s).trans mem_iUnion /-- The dual version does not hold! `Filter α` is not a `CompleteDistribLattice`. -/ -- See note [reducible non-instances] abbrev coframeMinimalAxioms : Coframe.MinimalAxioms (Filter α) := { Filter.instCompleteLatticeFilter with iInf_sup_le_sup_sInf := fun f s t ⟨h₁, h₂⟩ => by classical rw [iInf_subtype'] rw [sInf_eq_iInf', ← Filter.mem_sets, iInf_sets_eq_finite, mem_iUnion] at h₂ obtain ⟨u, hu⟩ := h₂ rw [← Finset.inf_eq_iInf] at hu suffices ⨅ i : s, f ⊔ ↑i ≤ f ⊔ u.inf fun i => ↑i from this ⟨h₁, hu⟩ refine Finset.induction_on u (le_sup_of_le_right le_top) ?_ rintro ⟨i⟩ u _ ih rw [Finset.inf_insert, sup_inf_left] exact le_inf (iInf_le _ _) ih } instance instCoframe : Coframe (Filter α) := .ofMinimalAxioms coframeMinimalAxioms theorem mem_iInf_finset {s : Finset α} {f : α → Filter β} {t : Set β} : (t ∈ ⨅ a ∈ s, f a) ↔ ∃ p : α → Set β, (∀ a ∈ s, p a ∈ f a) ∧ t = ⋂ a ∈ s, p a := by classical simp only [← Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype'] refine ⟨fun h => ?_, ?_⟩ · rcases (mem_iInf_of_finite _).1 h with ⟨p, hp, rfl⟩ refine ⟨fun a => if h : a ∈ s then p ⟨a, h⟩ else univ, fun a ha => by simpa [ha] using hp ⟨a, ha⟩, ?_⟩ refine iInter_congr_of_surjective id surjective_id ?_ rintro ⟨a, ha⟩ simp [ha] · rintro ⟨p, hpf, rfl⟩ exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2) @[elab_as_elim] theorem iInf_sets_induct {f : ι → Filter α} {s : Set α} (hs : s ∈ iInf f) {p : Set α → Prop} (uni : p univ) (ins : ∀ {i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂)) : p s := by classical rw [mem_iInf_finite'] at hs simp only [← Finset.inf_eq_iInf] at hs rcases hs with ⟨is, his⟩ induction is using Finset.induction_on generalizing s with | empty => rwa [mem_top.1 his] | insert _ _ _ ih => rw [Finset.inf_insert, mem_inf_iff] at his rcases his with ⟨s₁, hs₁, s₂, hs₂, rfl⟩ exact ins hs₁ (ih hs₂) /-! #### `principal` equations -/ @[simp] theorem iInf_principal_finset {ι : Type w} (s : Finset ι) (f : ι → Set α) : ⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by classical induction s using Finset.induction_on with | empty => simp | insert i s _ hs => rw [Finset.iInf_insert, Finset.set_biInter_insert, hs, inf_principal] theorem iInf_principal {ι : Sort w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := by cases nonempty_fintype (PLift ι) rw [← iInf_plift_down, ← iInter_plift_down] simpa using iInf_principal_finset Finset.univ (f <| PLift.down ·) /-- A special case of `iInf_principal` that is safe to mark `simp`. -/ @[simp] theorem iInf_principal' {ι : Type w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := iInf_principal _ theorem iInf_principal_finite {ι : Type w} {s : Set ι} (hs : s.Finite) (f : ι → Set α) : ⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by lift s to Finset ι using hs exact mod_cast iInf_principal_finset s f end Lattice /-! ### Eventually and Frequently -/ @[simp] theorem eventually_all {ι : Sort*} [Finite ι] {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i, p i x) ↔ ∀ i, ∀ᶠ x in l, p i x := by simpa only [Filter.Eventually, setOf_forall] using iInter_mem @[simp] theorem eventually_all_finite {ι} {I : Set ι} (hI : I.Finite) {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := by simpa only [Filter.Eventually, setOf_forall] using biInter_mem hI protected alias _root_.Set.Finite.eventually_all := eventually_all_finite @[simp] theorem eventually_all_finset {ι} (I : Finset ι) {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := I.finite_toSet.eventually_all protected alias _root_.Finset.eventually_all := eventually_all_finset @[simp] theorem frequently_exists {ι : Sort*} [Finite ι] {l} {p : ι → α → Prop} : (∃ᶠ x in l, ∃ i, p i x) ↔ ∃ i, ∃ᶠ x in l, p i x := by rw [← not_iff_not] simp @[simp] theorem frequently_exists_finite {ι} {I : Set ι} (hI : I.Finite) {l} {p : ι → α → Prop} : (∃ᶠ x in l, ∃ i ∈ I, p i x) ↔ ∃ i ∈ I, ∃ᶠ x in l, p i x := by rw [← not_iff_not] simp [hI] protected alias _root_.Set.Finite.frequently_exists := frequently_exists_finite @[simp] theorem frequently_exists_finset {ι} (I : Finset ι) {l} {p : ι → α → Prop} : (∃ᶠ x in l, ∃ i ∈ I, p i x) ↔ ∃ i ∈ I, ∃ᶠ x in l, p i x := I.finite_toSet.frequently_exists protected alias _root_.Finset.frequently_exists := frequently_exists_finset lemma eventually_subset_of_finite {ι : Type*} {f : Filter ι} {s : ι → Set α} {t : Set α} (ht : t.Finite) (hs : ∀ a ∈ t, ∀ᶠ i in f, a ∈ s i) : ∀ᶠ i in f, t ⊆ s i := by simpa [Set.subset_def, eventually_all_finite ht] using hs /-! ### Relation “eventually equal” -/ section EventuallyEq variable {l : Filter α} {f g : α → β} variable {l : Filter α} protected lemma EventuallyLE.iUnion [Finite ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : (⋃ i, s i) ≤ᶠ[l] ⋃ i, t i := (eventually_all.2 h).mono fun _x hx hx' ↦ let ⟨i, hi⟩ := mem_iUnion.1 hx'; mem_iUnion.2 ⟨i, hx i hi⟩ protected lemma EventuallyEq.iUnion [Finite ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : (⋃ i, s i) =ᶠ[l] ⋃ i, t i := (EventuallyLE.iUnion fun i ↦ (h i).le).antisymm <| .iUnion fun i ↦ (h i).symm.le protected lemma EventuallyLE.iInter [Finite ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : (⋂ i, s i) ≤ᶠ[l] ⋂ i, t i := (eventually_all.2 h).mono fun _x hx hx' ↦ mem_iInter.2 fun i ↦ hx i (mem_iInter.1 hx' i) protected lemma EventuallyEq.iInter [Finite ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : (⋂ i, s i) =ᶠ[l] ⋂ i, t i := (EventuallyLE.iInter fun i ↦ (h i).le).antisymm <| .iInter fun i ↦ (h i).symm.le lemma _root_.Set.Finite.eventuallyLE_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) := by have := hs.to_subtype rw [biUnion_eq_iUnion, biUnion_eq_iUnion] exact .iUnion fun i ↦ hle i.1 i.2 alias EventuallyLE.biUnion := Set.Finite.eventuallyLE_iUnion lemma _root_.Set.Finite.eventuallyEq_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) := (EventuallyLE.biUnion hs fun i hi ↦ (heq i hi).le).antisymm <| .biUnion hs fun i hi ↦ (heq i hi).symm.le alias EventuallyEq.biUnion := Set.Finite.eventuallyEq_iUnion lemma _root_.Set.Finite.eventuallyLE_iInter {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) := by have := hs.to_subtype rw [biInter_eq_iInter, biInter_eq_iInter] exact .iInter fun i ↦ hle i.1 i.2 alias EventuallyLE.biInter := Set.Finite.eventuallyLE_iInter lemma _root_.Set.Finite.eventuallyEq_iInter {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) := (EventuallyLE.biInter hs fun i hi ↦ (heq i hi).le).antisymm <| .biInter hs fun i hi ↦ (heq i hi).symm.le alias EventuallyEq.biInter := Set.Finite.eventuallyEq_iInter lemma _root_.Finset.eventuallyLE_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) := .biUnion s.finite_toSet hle lemma _root_.Finset.eventuallyEq_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) := .biUnion s.finite_toSet heq lemma _root_.Finset.eventuallyLE_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) := .biInter s.finite_toSet hle lemma _root_.Finset.eventuallyEq_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) := .biInter s.finite_toSet heq end EventuallyEq end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/CountableSeparatingOn.lean
import Mathlib.Order.Filter.CountableInter /-! # Filters with countable intersections and countable separating families In this file we prove some facts about a filter with countable intersections property on a type with a countable family of sets that separates points of the space. The main use case is the `MeasureTheory.ae` filter and a space with countably generated σ-algebra but lemmas apply, e.g., to the `residual` filter and a T₀ topological space with second countable topology. To avoid repetition of lemmas for different families of separating sets (measurable sets, open sets, closed sets), all theorems in this file take a predicate `p : Set α → Prop` as an argument and prove existence of a countable separating family satisfying this predicate by searching for a `HasCountableSeparatingOn` typeclass instance. ## Main definitions - `HasCountableSeparatingOn α p t`: a typeclass saying that there exists a countable set family `S : Set (Set α)` such that all `s ∈ S` satisfy the predicate `p` and any two distinct points `x y ∈ t`, `x ≠ y`, can be separated by a set `s ∈ S`. For technical reasons, we formulate the latter property as "for all `x y ∈ t`, if `x ∈ s ↔ y ∈ s` for all `s ∈ S`, then `x = y`". This typeclass is used in all lemmas in this file to avoid repeating them for open sets, closed sets, and measurable sets. ### Main results #### Filters supported on a (sub)singleton Let `l : Filter α` be a filter with countable intersections property. Let `p : Set α → Prop` be a property such that there exists a countable family of sets satisfying `p` and separating points of `α`. Then `l` is supported on a subsingleton: there exists a subsingleton `t` such that `t ∈ l`. We formalize various versions of this theorem in `Filter.exists_subset_subsingleton_mem_of_forall_separating`, `Filter.exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating`, `Filter.exists_singleton_mem_of_mem_of_forall_separating`, `Filter.exists_subsingleton_mem_of_forall_separating`, and `Filter.exists_singleton_mem_of_forall_separating`. #### Eventually constant functions Consider a function `f : α → β`, a filter `l` with countable intersections property, and a countable separating family of sets of `β`. Suppose that for every `U` from the family, either `∀ᶠ x in l, f x ∈ U` or `∀ᶠ x in l, f x ∉ U`. Then `f` is eventually constant along `l`. We formalize three versions of this theorem in `Filter.exists_mem_eventuallyEq_const_of_eventually_mem_of_forall_separating`, `Filter.exists_eventuallyEq_const_of_eventually_mem_of_forall_separating`, and `Filer.exists_eventuallyEq_const_of_forall_separating`. #### Eventually equal functions Two functions are equal along a filter with countable intersections property if the preimages of all sets from a countable separating family of sets are equal along the filter. We formalize several versions of this theorem in `Filter.of_eventually_mem_of_forall_separating_mem_iff`, `Filter.of_forall_separating_mem_iff`, `Filter.of_eventually_mem_of_forall_separating_preimage`, and `Filter.of_forall_separating_preimage`. ## Keywords filter, countable -/ open Function Set Filter /-- We say that a type `α` has a *countable separating family of sets* satisfying a predicate `p : Set α → Prop` on a set `t` if there exists a countable family of sets `S : Set (Set α)` such that all sets `s ∈ S` satisfy `p` and any two distinct points `x y ∈ t`, `x ≠ y`, can be separated by `s ∈ S`: there exists `s ∈ S` such that exactly one of `x` and `y` belongs to `s`. E.g., if `α` is a `T₀` topological space with second countable topology, then it has a countable separating family of open sets and a countable separating family of closed sets. -/ class HasCountableSeparatingOn (α : Type*) (p : Set α → Prop) (t : Set α) : Prop where exists_countable_separating : ∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧ ∀ x ∈ t, ∀ y ∈ t, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y theorem exists_countable_separating (α : Type*) (p : Set α → Prop) (t : Set α) [h : HasCountableSeparatingOn α p t] : ∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧ ∀ x ∈ t, ∀ y ∈ t, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y := h.1 theorem exists_nonempty_countable_separating (α : Type*) {p : Set α → Prop} {s₀} (hp : p s₀) (t : Set α) [HasCountableSeparatingOn α p t] : ∃ S : Set (Set α), S.Nonempty ∧ S.Countable ∧ (∀ s ∈ S, p s) ∧ ∀ x ∈ t, ∀ y ∈ t, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y := let ⟨S, hSc, hSp, hSt⟩ := exists_countable_separating α p t ⟨insert s₀ S, insert_nonempty _ _, hSc.insert _, forall_insert_of_forall hSp hp, fun x hx y hy hxy ↦ hSt x hx y hy <| forall_of_forall_insert hxy⟩ theorem exists_seq_separating (α : Type*) {p : Set α → Prop} {s₀} (hp : p s₀) (t : Set α) [HasCountableSeparatingOn α p t] : ∃ S : ℕ → Set α, (∀ n, p (S n)) ∧ ∀ x ∈ t, ∀ y ∈ t, (∀ n, x ∈ S n ↔ y ∈ S n) → x = y := by rcases exists_nonempty_countable_separating α hp t with ⟨S, hSne, hSc, hS⟩ rcases hSc.exists_eq_range hSne with ⟨S, rfl⟩ use S simpa only [forall_mem_range] using hS theorem HasCountableSeparatingOn.mono {α} {p₁ p₂ : Set α → Prop} {t₁ t₂ : Set α} [h : HasCountableSeparatingOn α p₁ t₁] (hp : ∀ s, p₁ s → p₂ s) (ht : t₂ ⊆ t₁) : HasCountableSeparatingOn α p₂ t₂ where exists_countable_separating := let ⟨S, hSc, hSp, hSt⟩ := h.1 ⟨S, hSc, fun s hs ↦ hp s (hSp s hs), fun x hx y hy ↦ hSt x (ht hx) y (ht hy)⟩ theorem HasCountableSeparatingOn.of_subtype {α : Type*} {p : Set α → Prop} {t : Set α} {q : Set t → Prop} [h : HasCountableSeparatingOn t q univ] (hpq : ∀ U, q U → ∃ V, p V ∧ (↑) ⁻¹' V = U) : HasCountableSeparatingOn α p t := by rcases h.1 with ⟨S, hSc, hSq, hS⟩ choose! V hpV hV using fun s hs ↦ hpq s (hSq s hs) refine ⟨⟨V '' S, hSc.image _, forall_mem_image.2 hpV, fun x hx y hy h ↦ ?_⟩⟩ refine congr_arg Subtype.val (hS ⟨x, hx⟩ trivial ⟨y, hy⟩ trivial fun U hU ↦ ?_) rw [← hV U hU] exact h _ (mem_image_of_mem _ hU) theorem HasCountableSeparatingOn.subtype_iff {α : Type*} {p : Set α → Prop} {t : Set α} : HasCountableSeparatingOn t (fun u ↦ ∃ v, p v ∧ (↑) ⁻¹' v = u) univ ↔ HasCountableSeparatingOn α p t := by constructor <;> intro h · exact h.of_subtype <| fun s ↦ id rcases h with ⟨S, Sct, Sp, hS⟩ use {Subtype.val ⁻¹' s | s ∈ S}, Sct.image _, ?_, ?_ · rintro u ⟨t, tS, rfl⟩ exact ⟨t, Sp _ tS, rfl⟩ rintro x - y - hxy exact Subtype.val_injective <| hS _ (Subtype.coe_prop _) _ (Subtype.coe_prop _) fun s hs ↦ hxy (Subtype.val ⁻¹' s) ⟨s, hs, rfl⟩ namespace Filter variable {α β : Type*} {l : Filter α} [CountableInterFilter l] {f g : α → β} /-! ### Filters supported on a (sub)singleton In this section we prove several versions of the following theorem. Let `l : Filter α` be a filter with countable intersections property. Let `p : Set α → Prop` be a property such that there exists a countable family of sets satisfying `p` and separating points of `α`. Then `l` is supported on a subsingleton: there exists a subsingleton `t` such that `t ∈ l`. With extra `Nonempty`/`Set.Nonempty` assumptions one can ensure that `t` is a singleton `{x}`. If `s ∈ l`, then it suffices to assume that the countable family separates only points of `s`. -/ theorem exists_subset_subsingleton_mem_of_forall_separating (p : Set α → Prop) {s : Set α} [h : HasCountableSeparatingOn α p s] (hs : s ∈ l) (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ t, t ⊆ s ∧ t.Subsingleton ∧ t ∈ l := by rcases h.1 with ⟨S, hSc, hSp, hS⟩ refine ⟨s ∩ ⋂₀ (S ∩ l.sets) ∩ ⋂ (U ∈ S) (_ : Uᶜ ∈ l), Uᶜ, ?_, ?_, ?_⟩ · exact fun _ h ↦ h.1.1 · intro x hx y hy simp only [mem_sInter, mem_inter_iff, mem_iInter, mem_compl_iff] at hx hy refine hS x hx.1.1 y hy.1.1 (fun s hsS ↦ ?_) cases hl s (hSp s hsS) with | inl hsl => simp only [hx.1.2 s ⟨hsS, hsl⟩, hy.1.2 s ⟨hsS, hsl⟩] | inr hsl => simp only [hx.2 s hsS hsl, hy.2 s hsS hsl] · exact inter_mem (inter_mem hs ((countable_sInter_mem (hSc.mono inter_subset_left)).2 fun _ h ↦ h.2)) ((countable_bInter_mem hSc).2 fun U hU ↦ iInter_mem'.2 id) theorem exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating (p : Set α → Prop) {s : Set α} [HasCountableSeparatingOn α p s] (hs : s ∈ l) (hne : s.Nonempty) (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ a ∈ s, {a} ∈ l := by rcases exists_subset_subsingleton_mem_of_forall_separating p hs hl with ⟨t, hts, ht, htl⟩ rcases ht.eq_empty_or_singleton with rfl | ⟨x, rfl⟩ · exact hne.imp fun a ha ↦ ⟨ha, mem_of_superset htl (empty_subset _)⟩ · exact ⟨x, hts rfl, htl⟩ theorem exists_singleton_mem_of_mem_of_forall_separating [Nonempty α] (p : Set α → Prop) {s : Set α} [HasCountableSeparatingOn α p s] (hs : s ∈ l) (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ a, {a} ∈ l := by rcases s.eq_empty_or_nonempty with rfl | hne · exact ‹Nonempty α›.elim fun a ↦ ⟨a, mem_of_superset hs (empty_subset _)⟩ · exact (exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating p hs hne hl).imp fun _ ↦ And.right theorem exists_subsingleton_mem_of_forall_separating (p : Set α → Prop) [HasCountableSeparatingOn α p univ] (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ s : Set α, s.Subsingleton ∧ s ∈ l := let ⟨t, _, hts, htl⟩ := exists_subset_subsingleton_mem_of_forall_separating p univ_mem hl ⟨t, hts, htl⟩ theorem exists_singleton_mem_of_forall_separating [Nonempty α] (p : Set α → Prop) [HasCountableSeparatingOn α p univ] (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ x : α, {x} ∈ l := exists_singleton_mem_of_mem_of_forall_separating p univ_mem hl /-! ### Eventually constant functions In this section we apply theorems from the previous section to the filter `Filter.map f l` to show that `f : α → β` is eventually constant along `l` if for every `U` from the separating family, either `∀ᶠ x in l, f x ∈ U` or `∀ᶠ x in l, f x ∉ U`. -/ theorem exists_mem_eventuallyEq_const_of_eventually_mem_of_forall_separating (p : Set β → Prop) {s : Set β} [HasCountableSeparatingOn β p s] (hs : ∀ᶠ x in l, f x ∈ s) (hne : s.Nonempty) (h : ∀ U, p U → (∀ᶠ x in l, f x ∈ U) ∨ (∀ᶠ x in l, f x ∉ U)) : ∃ a ∈ s, f =ᶠ[l] const α a := exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating p (l := map f l) hs hne h theorem exists_eventuallyEq_const_of_eventually_mem_of_forall_separating [Nonempty β] (p : Set β → Prop) {s : Set β} [HasCountableSeparatingOn β p s] (hs : ∀ᶠ x in l, f x ∈ s) (h : ∀ U, p U → (∀ᶠ x in l, f x ∈ U) ∨ (∀ᶠ x in l, f x ∉ U)) : ∃ a, f =ᶠ[l] const α a := exists_singleton_mem_of_mem_of_forall_separating (l := map f l) p hs h theorem exists_eventuallyEq_const_of_forall_separating [Nonempty β] (p : Set β → Prop) [HasCountableSeparatingOn β p univ] (h : ∀ U, p U → (∀ᶠ x in l, f x ∈ U) ∨ (∀ᶠ x in l, f x ∉ U)) : ∃ a, f =ᶠ[l] const α a := exists_singleton_mem_of_forall_separating (l := map f l) p h namespace EventuallyEq /-! ### Eventually equal functions In this section we show that two functions are equal along a filter with countable intersections property if the preimages of all sets from a countable separating family of sets are equal along the filter. -/ theorem of_eventually_mem_of_forall_separating_mem_iff (p : Set β → Prop) {s : Set β} [h' : HasCountableSeparatingOn β p s] (hf : ∀ᶠ x in l, f x ∈ s) (hg : ∀ᶠ x in l, g x ∈ s) (h : ∀ U : Set β, p U → ∀ᶠ x in l, f x ∈ U ↔ g x ∈ U) : f =ᶠ[l] g := by rcases h'.1 with ⟨S, hSc, hSp, hS⟩ have H : ∀ᶠ x in l, ∀ s ∈ S, f x ∈ s ↔ g x ∈ s := (eventually_countable_ball hSc).2 fun s hs ↦ (h _ (hSp _ hs)) filter_upwards [H, hf, hg] with x hx hxf hxg using hS _ hxf _ hxg hx theorem of_forall_separating_mem_iff (p : Set β → Prop) [HasCountableSeparatingOn β p univ] (h : ∀ U : Set β, p U → ∀ᶠ x in l, f x ∈ U ↔ g x ∈ U) : f =ᶠ[l] g := of_eventually_mem_of_forall_separating_mem_iff p (s := univ) univ_mem univ_mem h theorem of_eventually_mem_of_forall_separating_preimage (p : Set β → Prop) {s : Set β} [HasCountableSeparatingOn β p s] (hf : ∀ᶠ x in l, f x ∈ s) (hg : ∀ᶠ x in l, g x ∈ s) (h : ∀ U : Set β, p U → f ⁻¹' U =ᶠ[l] g ⁻¹' U) : f =ᶠ[l] g := of_eventually_mem_of_forall_separating_mem_iff p hf hg fun U hU ↦ (h U hU).mem_iff theorem of_forall_separating_preimage (p : Set β → Prop) [HasCountableSeparatingOn β p univ] (h : ∀ U : Set β, p U → f ⁻¹' U =ᶠ[l] g ⁻¹' U) : f =ᶠ[l] g := of_eventually_mem_of_forall_separating_preimage p (s := univ) univ_mem univ_mem h end EventuallyEq end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Cofinite.lean
import Mathlib.Data.Finite.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.Set.Finite.Lemmas import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.CountablyGenerated import Mathlib.Order.Filter.Ker import Mathlib.Order.Filter.Pi import Mathlib.Order.Filter.Prod import Mathlib.Order.Filter.AtTopBot.Basic /-! # The cofinite filter In this file we define `Filter.cofinite`: the filter of sets with finite complement and prove its basic properties. In particular, we prove that for `ℕ` it is equal to `Filter.atTop`. ## TODO Define filters for other cardinalities of the complement. -/ open Set Function variable {ι α β : Type*} {l : Filter α} namespace Filter /-- The cofinite filter is the filter of subsets whose complements are finite. -/ def cofinite : Filter α := comk Set.Finite finite_empty (fun _t ht _s hsub ↦ ht.subset hsub) fun _ h _ ↦ h.union @[simp] theorem mem_cofinite {s : Set α} : s ∈ @cofinite α ↔ sᶜ.Finite := Iff.rfl @[simp] theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in cofinite, p x) ↔ { x | ¬p x }.Finite := Iff.rfl theorem hasBasis_cofinite : HasBasis cofinite (fun s : Set α => s.Finite) compl := ⟨fun s => ⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ => htf.subset <| compl_subset_comm.2 hts⟩⟩ instance cofinite_neBot [Infinite α] : NeBot (@cofinite α) := hasBasis_cofinite.neBot_iff.2 fun hs => hs.infinite_compl.nonempty @[simp] theorem cofinite_eq_bot_iff : @cofinite α = ⊥ ↔ Finite α := by simp [← empty_mem_iff_bot, finite_univ_iff] @[simp] theorem cofinite_eq_bot [Finite α] : @cofinite α = ⊥ := cofinite_eq_bot_iff.2 ‹_› theorem frequently_cofinite_iff_infinite {p : α → Prop} : (∃ᶠ x in cofinite, p x) ↔ Set.Infinite { x | p x } := by simp only [Filter.Frequently, eventually_cofinite, not_not, Set.Infinite] lemma frequently_cofinite_mem_iff_infinite {s : Set α} : (∃ᶠ x in cofinite, x ∈ s) ↔ s.Infinite := frequently_cofinite_iff_infinite alias ⟨_, _root_.Set.Infinite.frequently_cofinite⟩ := frequently_cofinite_mem_iff_infinite @[simp] lemma cofinite_inf_principal_neBot_iff {s : Set α} : (cofinite ⊓ 𝓟 s).NeBot ↔ s.Infinite := frequently_mem_iff_neBot.symm.trans frequently_cofinite_mem_iff_infinite alias ⟨_, _root_.Set.Infinite.cofinite_inf_principal_neBot⟩ := cofinite_inf_principal_neBot_iff theorem _root_.Set.Finite.compl_mem_cofinite {s : Set α} (hs : s.Finite) : sᶜ ∈ @cofinite α := mem_cofinite.2 <| (compl_compl s).symm ▸ hs theorem _root_.Set.Finite.eventually_cofinite_notMem {s : Set α} (hs : s.Finite) : ∀ᶠ x in cofinite, x ∉ s := hs.compl_mem_cofinite @[deprecated (since := "2025-05-24")] alias _root_.Set.Finite.eventually_cofinite_nmem := _root_.Set.Finite.eventually_cofinite_notMem theorem _root_.Finset.eventually_cofinite_notMem (s : Finset α) : ∀ᶠ x in cofinite, x ∉ s := s.finite_toSet.eventually_cofinite_notMem @[deprecated (since := "2025-05-24")] alias _root_.Finset.eventually_cofinite_nmem := _root_.Finset.eventually_cofinite_notMem theorem _root_.Set.infinite_iff_frequently_cofinite {s : Set α} : Set.Infinite s ↔ ∃ᶠ x in cofinite, x ∈ s := frequently_cofinite_iff_infinite.symm theorem eventually_cofinite_ne (x : α) : ∀ᶠ a in cofinite, a ≠ x := (Set.finite_singleton x).eventually_cofinite_notMem theorem le_cofinite_iff_compl_singleton_mem : l ≤ cofinite ↔ ∀ x, {x}ᶜ ∈ l := by refine ⟨fun h x => h (finite_singleton x).compl_mem_cofinite, fun h s (hs : sᶜ.Finite) => ?_⟩ rw [← compl_compl s, ← biUnion_of_singleton sᶜ, compl_iUnion₂, Filter.biInter_mem hs] exact fun x _ => h x theorem le_cofinite_iff_eventually_ne : l ≤ cofinite ↔ ∀ x, ∀ᶠ y in l, y ≠ x := le_cofinite_iff_compl_singleton_mem /-- If `α` is a preorder with no top element, then `atTop ≤ cofinite`. -/ theorem atTop_le_cofinite [Preorder α] [NoTopOrder α] : (atTop : Filter α) ≤ cofinite := le_cofinite_iff_eventually_ne.mpr eventually_ne_atTop /-- If `α` is a preorder with no bottom element, then `atBot ≤ cofinite`. -/ theorem atBot_le_cofinite [Preorder α] [NoBotOrder α] : (atBot : Filter α) ≤ cofinite := le_cofinite_iff_eventually_ne.mpr eventually_ne_atBot theorem comap_cofinite_le (f : α → β) : comap f cofinite ≤ cofinite := le_cofinite_iff_eventually_ne.mpr fun x => mem_comap.2 ⟨{f x}ᶜ, (finite_singleton _).compl_mem_cofinite, fun _ => ne_of_apply_ne f⟩ /-- The coproduct of the cofinite filters on two types is the cofinite filter on their product. -/ theorem coprod_cofinite : (cofinite : Filter α).coprod (cofinite : Filter β) = cofinite := Filter.coext fun s => by simp only [compl_mem_coprod, mem_cofinite, compl_compl, finite_image_fst_and_snd_iff] theorem coprodᵢ_cofinite {α : ι → Type*} [Finite ι] : (Filter.coprodᵢ fun i => (cofinite : Filter (α i))) = cofinite := Filter.coext fun s => by simp only [compl_mem_coprodᵢ, mem_cofinite, compl_compl, forall_finite_image_eval_iff] theorem disjoint_cofinite_left : Disjoint cofinite l ↔ ∃ s ∈ l, Set.Finite s := by simp [l.basis_sets.disjoint_iff_right] theorem disjoint_cofinite_right : Disjoint l cofinite ↔ ∃ s ∈ l, Set.Finite s := disjoint_comm.trans disjoint_cofinite_left /-- If `l ≥ Filter.cofinite` is a countably generated filter, then `l.ker` is cocountable. -/ theorem countable_compl_ker [l.IsCountablyGenerated] (h : cofinite ≤ l) : Set.Countable l.kerᶜ := by rcases exists_antitone_basis l with ⟨s, hs⟩ simp only [hs.ker, iInter_true, compl_iInter] exact countable_iUnion fun n ↦ Set.Finite.countable <| h <| hs.mem _ /-- If `f` tends to a countably generated filter `l` along `Filter.cofinite`, then for all but countably many elements, `f x ∈ l.ker`. -/ theorem Tendsto.countable_compl_preimage_ker {f : α → β} {l : Filter β} [l.IsCountablyGenerated] (h : Tendsto f cofinite l) : Set.Countable (f ⁻¹' l.ker)ᶜ := by rw [← ker_comap]; exact countable_compl_ker h.le_comap /-- Given a collection of filters `l i : Filter (α i)` and sets `s i ∈ l i`, if all but finitely many of `s i` are the whole space, then their indexed product `Set.pi Set.univ s` belongs to the filter `Filter.pi l`. -/ theorem univ_pi_mem_pi {α : ι → Type*} {s : ∀ i, Set (α i)} {l : ∀ i, Filter (α i)} (h : ∀ i, s i ∈ l i) (hfin : ∀ᶠ i in cofinite, s i = univ) : univ.pi s ∈ pi l := by filter_upwards [pi_mem_pi hfin fun i _ ↦ h i] with a ha i _ if hi : s i = univ then simp [hi] else exact ha i hi /-- Given a family of maps `f i : α i → β i` and a family of filters `l i : Filter (α i)`, if all but finitely many of `f i` are surjective, then the indexed product of `f i`s maps the indexed product of the filters `l i` to the indexed products of their pushforwards under individual `f i`s. See also `map_piMap_pi_finite` for the case of a finite index type. -/ theorem map_piMap_pi {α β : ι → Type*} {f : ∀ i, α i → β i} (hf : ∀ᶠ i in cofinite, Surjective (f i)) (l : ∀ i, Filter (α i)) : map (Pi.map f) (pi l) = pi fun i ↦ map (f i) (l i) := by refine le_antisymm (tendsto_piMap_pi fun _ ↦ tendsto_map) ?_ refine ((hasBasis_pi fun i ↦ (l i).basis_sets).map _).ge_iff.2 ?_ rintro ⟨I, s⟩ ⟨hI : I.Finite, hs : ∀ i ∈ I, s i ∈ l i⟩ classical rw [← univ_pi_piecewise_univ, piMap_image_univ_pi] refine univ_pi_mem_pi (fun i ↦ ?_) ?_ · by_cases hi : i ∈ I · simpa [hi] using image_mem_map (hs i hi) · simp [hi] · filter_upwards [hf, hI.compl_mem_cofinite] with i hsurj (hiI : i ∉ I) simp [hiI, hsurj.range_eq] /-- Given finite families of maps `f i : α i → β i` and of filters `l i : Filter (α i)`, the indexed product of `f i`s maps the indexed product of the filters `l i` to the indexed products of their pushforwards under individual `f i`s. See also `map_piMap_pi` for a more general case. -/ theorem map_piMap_pi_finite {α β : ι → Type*} [Finite ι] (f : ∀ i, α i → β i) (l : ∀ i, Filter (α i)) : map (Pi.map f) (pi l) = pi fun i ↦ map (f i) (l i) := map_piMap_pi (by simp) l end Filter open Filter lemma Set.Finite.cofinite_inf_principal_compl {s : Set α} (hs : s.Finite) : cofinite ⊓ 𝓟 sᶜ = cofinite := by simpa using hs.compl_mem_cofinite lemma Set.Finite.cofinite_inf_principal_diff {s t : Set α} (ht : t.Finite) : cofinite ⊓ 𝓟 (s \ t) = cofinite ⊓ 𝓟 s := by rw [diff_eq, ← inf_principal, ← inf_assoc, inf_right_comm, ht.cofinite_inf_principal_compl] /-- For natural numbers the filters `Filter.cofinite` and `Filter.atTop` coincide. -/ theorem Nat.cofinite_eq_atTop : @cofinite ℕ = atTop := by refine le_antisymm ?_ atTop_le_cofinite refine atTop_basis.ge_iff.2 fun N _ => ?_ simpa only [mem_cofinite, compl_Ici] using finite_lt_nat N theorem Nat.frequently_atTop_iff_infinite {p : ℕ → Prop} : (∃ᶠ n in atTop, p n) ↔ Set.Infinite { n | p n } := by rw [← Nat.cofinite_eq_atTop, frequently_cofinite_iff_infinite] lemma Nat.eventually_pos : ∀ᶠ (k : ℕ) in Filter.atTop, 0 < k := Filter.eventually_of_mem (Filter.mem_atTop_sets.mpr ⟨1, fun _ hx ↦ hx⟩) (fun _ hx ↦ hx) theorem Filter.Tendsto.exists_within_forall_le {α β : Type*} [LinearOrder β] {s : Set α} (hs : s.Nonempty) {f : α → β} (hf : Filter.Tendsto f Filter.cofinite Filter.atTop) : ∃ a₀ ∈ s, ∀ a ∈ s, f a₀ ≤ f a := by by_cases! all_top : ∃ y ∈ s, ∃ x, f y < x · -- the set of points `{y | f y < x}` is nonempty and finite, so we take `min` over this set rcases all_top with ⟨y, hys, x, hx⟩ have : { y | ¬x ≤ f y }.Finite := Filter.eventually_cofinite.mp (tendsto_atTop.1 hf x) simp only [not_le] at this obtain ⟨a₀, ⟨ha₀ : f a₀ < x, ha₀s⟩, others_bigger⟩ := exists_min_image _ f (this.inter_of_left s) ⟨y, hx, hys⟩ refine ⟨a₀, ha₀s, fun a has => (lt_or_ge (f a) x).elim ?_ (le_trans ha₀.le)⟩ exact fun h => others_bigger a ⟨h, has⟩ · -- in this case, f is constant because all values are at top obtain ⟨a₀, ha₀s⟩ := hs exact ⟨a₀, ha₀s, fun a ha => all_top a ha (f a₀)⟩ theorem Filter.Tendsto.exists_forall_le [Nonempty α] [LinearOrder β] {f : α → β} (hf : Tendsto f cofinite atTop) : ∃ a₀, ∀ a, f a₀ ≤ f a := let ⟨a₀, _, ha₀⟩ := hf.exists_within_forall_le univ_nonempty ⟨a₀, fun a => ha₀ a (mem_univ _)⟩ theorem Filter.Tendsto.exists_within_forall_ge [LinearOrder β] {s : Set α} (hs : s.Nonempty) {f : α → β} (hf : Filter.Tendsto f Filter.cofinite Filter.atBot) : ∃ a₀ ∈ s, ∀ a ∈ s, f a ≤ f a₀ := @Filter.Tendsto.exists_within_forall_le _ βᵒᵈ _ _ hs _ hf theorem Filter.Tendsto.exists_forall_ge [Nonempty α] [LinearOrder β] {f : α → β} (hf : Tendsto f cofinite atBot) : ∃ a₀, ∀ a, f a ≤ f a₀ := @Filter.Tendsto.exists_forall_le _ βᵒᵈ _ _ _ hf theorem Function.Surjective.le_map_cofinite {f : α → β} (hf : Surjective f) : cofinite ≤ map f cofinite := fun _ h => .of_preimage h hf /-- For an injective function `f`, inverse images of finite sets are finite. See also `Filter.comap_cofinite_le` and `Function.Injective.comap_cofinite_eq`. -/ theorem Function.Injective.tendsto_cofinite {f : α → β} (hf : Injective f) : Tendsto f cofinite cofinite := fun _ h => h.preimage hf.injOn /-- For a function with finite fibres, inverse images of finite sets are finite. -/ theorem Filter.Tendsto.cofinite_of_finite_preimage_singleton {f : α → β} (hf : ∀ b, Finite (f ⁻¹' {b})) : Tendsto f cofinite cofinite := fun _ h => h.preimage' fun b _ ↦ hf b /-- The pullback of the `Filter.cofinite` under an injective function is equal to `Filter.cofinite`. See also `Filter.comap_cofinite_le` and `Function.Injective.tendsto_cofinite`. -/ theorem Function.Injective.comap_cofinite_eq {f : α → β} (hf : Injective f) : comap f cofinite = cofinite := (comap_cofinite_le f).antisymm hf.tendsto_cofinite.le_comap /-- An injective sequence `f : ℕ → ℕ` tends to infinity at infinity. -/ theorem Function.Injective.nat_tendsto_atTop {f : ℕ → ℕ} (hf : Injective f) : Tendsto f atTop atTop := Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite lemma Function.update_eventuallyEq [DecidableEq α] (f : α → β) (a : α) (b : β) : Function.update f a b =ᶠ[𝓟 {a}ᶜ] f := by filter_upwards [mem_principal_self _] with u hu using Function.update_of_ne hu _ _ lemma Function.update_eventuallyEq_cofinite [DecidableEq α] (f : α → β) (a : α) (b : β) : Function.update f a b =ᶠ[cofinite] f := (Function.update_eventuallyEq f a b).filter_mono (by simp)
.lake/packages/mathlib/Mathlib/Order/Filter/FilterProduct.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Order.Group.Unbundled.Abs import Mathlib.Order.Filter.Ring import Mathlib.Order.Filter.Ultrafilter.Defs /-! # Ultraproducts If `φ` is an ultrafilter, then the space of germs of functions `f : α → β` at `φ` is called the *ultraproduct*. In this file we prove properties of ultraproducts that rely on `φ` being an ultrafilter. Definitions and properties that work for any filter should go to `Order.Filter.Germ`. ## Tags ultrafilter, ultraproduct -/ universe u v variable {α : Type u} {β : Type v} {φ : Ultrafilter α} namespace Filter local notation3 "∀* "(...)", "r:(scoped p => Filter.Eventually p (Ultrafilter.toFilter φ)) => r namespace Germ open Ultrafilter local notation "β*" => Germ (φ : Filter α) β instance instGroupWithZero [GroupWithZero β] : GroupWithZero β* where __ := instDivInvMonoid __ := instMonoidWithZero mul_inv_cancel f := inductionOn f fun f hf ↦ coe_eq.2 <| (φ.em fun y ↦ f y = 0).elim (fun H ↦ (hf <| coe_eq.2 H).elim) fun H ↦ H.mono fun _ ↦ mul_inv_cancel₀ inv_zero := coe_eq.2 <| by simp only [Function.comp_def, inv_zero, EventuallyEq.rfl] instance instDivisionSemiring [DivisionSemiring β] : DivisionSemiring β* where toSemiring := instSemiring __ := instGroupWithZero nnqsmul := _ nnqsmul_def := fun _ _ => rfl instance instDivisionRing [DivisionRing β] : DivisionRing β* where __ := instRing __ := instDivisionSemiring qsmul := _ qsmul_def := fun _ _ => rfl instance instSemifield [Semifield β] : Semifield β* where __ := instCommSemiring __ := instDivisionSemiring instance instField [Field β] : Field β* where __ := instCommRing __ := instDivisionRing theorem coe_lt [Preorder β] {f g : α → β} : (f : β*) < g ↔ ∀* x, f x < g x := by simp only [lt_iff_le_not_ge, eventually_and, coe_le, eventually_not, EventuallyLE] theorem coe_pos [Preorder β] [Zero β] {f : α → β} : 0 < (f : β*) ↔ ∀* x, 0 < f x := coe_lt theorem const_lt [Preorder β] {x y : β} : x < y → (↑x : β*) < ↑y := coe_lt.mpr ∘ liftRel_const @[simp, norm_cast] theorem const_lt_iff [Preorder β] {x y : β} : (↑x : β*) < ↑y ↔ x < y := coe_lt.trans liftRel_const_iff theorem lt_def [Preorder β] : ((· < ·) : β* → β* → Prop) = LiftRel (· < ·) := by ext ⟨f⟩ ⟨g⟩ exact coe_lt instance isTotal [LE β] [IsTotal β (· ≤ ·)] : IsTotal β* (· ≤ ·) := ⟨fun f g => inductionOn₂ f g fun _f _g => eventually_or.1 <| Eventually.of_forall fun _x => total_of _ _ _⟩ open Classical in /-- If `φ` is an ultrafilter then the ultraproduct is a linear order. -/ noncomputable instance instLinearOrder [LinearOrder β] : LinearOrder β* := Lattice.toLinearOrder _ instance instIsStrictOrderedRing [Semiring β] [PartialOrder β] [IsStrictOrderedRing β] : IsStrictOrderedRing β* where mul_lt_mul_of_pos_left x := inductionOn x fun _f hf y z ↦ inductionOn₂ y z fun _g _h hgh ↦ coe_lt.2 <| (coe_lt.1 hf).mp <| (coe_lt.1 hgh).mono fun _a ↦ mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right x := inductionOn x fun _f hf y z ↦ inductionOn₂ y z fun _g _h hgh ↦ coe_lt.2 <| (coe_lt.1 hf).mp <| (coe_lt.1 hgh).mono fun _a ↦ mul_lt_mul_of_pos_right theorem max_def [LinearOrder β] (x y : β*) : max x y = map₂ max x y := inductionOn₂ x y fun a b => by rcases le_total (a : β*) b with h | h · rw [max_eq_right h, map₂_coe, coe_eq] exact h.mono fun i hi => (max_eq_right hi).symm · rw [max_eq_left h, map₂_coe, coe_eq] exact h.mono fun i hi => (max_eq_left hi).symm theorem min_def [K : LinearOrder β] (x y : β*) : min x y = map₂ min x y := inductionOn₂ x y fun a b => by rcases le_total (a : β*) b with h | h · rw [min_eq_left h, map₂_coe, coe_eq] exact h.mono fun i hi => (min_eq_left hi).symm · rw [min_eq_right h, map₂_coe, coe_eq] exact h.mono fun i hi => (min_eq_right hi).symm theorem abs_def [AddCommGroup β] [LinearOrder β] (x : β*) : |x| = map abs x := inductionOn x fun _a => rfl @[simp] theorem const_max [LinearOrder β] (x y : β) : (↑(max x y : β) : β*) = max ↑x ↑y := by rw [max_def, map₂_const] @[simp] theorem const_min [LinearOrder β] (x y : β) : (↑(min x y : β) : β*) = min ↑x ↑y := by rw [min_def, map₂_const] @[simp] theorem const_abs [AddCommGroup β] [LinearOrder β] (x : β) : (↑|x| : β*) = |↑x| := by rw [abs_def, map_const] end Germ end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Cocardinal.lean
import Mathlib.Order.Filter.Cofinite import Mathlib.Order.Filter.CountableInter import Mathlib.Order.Filter.CardinalInter import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Cardinal.Cofinality /-! # The cocardinal filter In this file we define `Filter.cocardinal hc`: the filter of sets with cardinality less than a regular cardinal `c` that satisfies `Cardinal.aleph0 < c`. Such filters are `CardinalInterFilter` with cardinality `c`. -/ open Set Filter Cardinal universe u variable {α : Type u} {c : Cardinal.{u}} {hreg : c.IsRegular} namespace Filter variable (α) in /-- The filter defined by all sets that have a complement with at most cardinality `c`. For a union of `c` sets of `c` elements to have `c` elements, we need that `c` is a regular cardinal. -/ def cocardinal (hreg : c.IsRegular) : Filter α := by apply ofCardinalUnion {s | Cardinal.mk s < c} (lt_of_lt_of_le (nat_lt_aleph0 2) hreg.aleph0_le) · refine fun s hS hSc ↦ lt_of_le_of_lt (mk_sUnion_le _) <| mul_lt_of_lt hreg.aleph0_le hS ?_ exact iSup_lt_of_isRegular hreg hS fun i ↦ hSc i i.property · exact fun _ hSc _ ht ↦ lt_of_le_of_lt (mk_le_mk_of_subset ht) hSc @[simp] theorem mem_cocardinal {s : Set α} : s ∈ cocardinal α hreg ↔ Cardinal.mk (sᶜ : Set α) < c := Iff.rfl @[simp] lemma cocardinal_aleph0_eq_cofinite : cocardinal (α := α) isRegular_aleph0 = cofinite := by aesop instance instCardinalInterFilter_cocardinal : CardinalInterFilter (cocardinal (α := α) hreg) c where cardinal_sInter_mem S hS hSs := by rw [mem_cocardinal, Set.compl_sInter] apply lt_of_le_of_lt (mk_sUnion_le _) apply mul_lt_of_lt hreg.aleph0_le (lt_of_le_of_lt mk_image_le hS) apply iSup_lt_of_isRegular hreg <| lt_of_le_of_lt mk_image_le hS aesop @[simp] theorem eventually_cocardinal {p : α → Prop} : (∀ᶠ x in cocardinal α hreg, p x) ↔ #{ x | ¬p x } < c := Iff.rfl theorem hasBasis_cocardinal : HasBasis (cocardinal α hreg) {s : Set α | #s < c} compl := ⟨fun s => ⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ => by have : #↑sᶜ < c := by apply lt_of_le_of_lt _ htf rw [compl_subset_comm] at hts apply Cardinal.mk_le_mk_of_subset hts simp_all only [mem_cocardinal] ⟩⟩ theorem frequently_cocardinal {p : α → Prop} : (∃ᶠ x in cocardinal α hreg, p x) ↔ c ≤ #{ x | p x } := by simp only [Filter.Frequently, eventually_cocardinal, not_not, coe_setOf, not_lt] lemma frequently_cocardinal_mem {s : Set α} : (∃ᶠ x in cocardinal α hreg, x ∈ s) ↔ c ≤ #s := frequently_cocardinal @[simp] lemma cocardinal_inf_principal_neBot_iff {s : Set α} : (cocardinal α hreg ⊓ 𝓟 s).NeBot ↔ c ≤ #s := frequently_mem_iff_neBot.symm.trans frequently_cocardinal theorem compl_mem_cocardinal_of_card_lt {s : Set α} (hs : #s < c) : sᶜ ∈ cocardinal α hreg := mem_cocardinal.2 <| (compl_compl s).symm ▸ hs theorem _root_.Set.Finite.compl_mem_cocardinal {s : Set α} (hs : s.Finite) : sᶜ ∈ cocardinal α hreg := compl_mem_cocardinal_of_card_lt <| lt_of_lt_of_le (Finite.lt_aleph0 hs) (hreg.aleph0_le) theorem eventually_cocardinal_notMem_of_card_lt {s : Set α} (hs : #s < c) : ∀ᶠ x in cocardinal α hreg, x ∉ s := compl_mem_cocardinal_of_card_lt hs @[deprecated (since := "2025-05-24")] alias eventually_cocardinal_nmem_of_card_lt := eventually_cocardinal_notMem_of_card_lt theorem _root_.Finset.eventually_cocardinal_notMem (s : Finset α) : ∀ᶠ x in cocardinal α hreg, x ∉ s := eventually_cocardinal_notMem_of_card_lt <| (finset_card_lt_aleph0 s).trans_le (hreg.aleph0_le) @[deprecated (since := "2025-05-24")] alias _root_.Finset.eventually_cocardinal_nmem := _root_.Finset.eventually_cocardinal_notMem theorem eventually_cocardinal_ne (x : α) : ∀ᶠ a in cocardinal α hreg, a ≠ x := by simpa [Set.finite_singleton x] using hreg.nat_lt 1 /-- The filter defined by all sets that have countable complements. -/ abbrev cocountable : Filter α := cocardinal α Cardinal.isRegular_aleph_one theorem mem_cocountable {s : Set α} : s ∈ cocountable ↔ (sᶜ : Set α).Countable := by rw [Cardinal.countable_iff_lt_aleph_one, mem_cocardinal] end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/ENNReal.lean
import Mathlib.Topology.Order.LiminfLimsup import Mathlib.Topology.Metrizable.Real /-! # Limsup and liminf of reals This file compiles filter-related results about `ℝ`, `ℝ≥0` and `ℝ≥0∞`. -/ open Filter ENNReal namespace Real variable {ι : Type*} {f : Filter ι} {u : ι → ℝ} @[simp] lemma limsSup_of_not_isCobounded {f : Filter ℝ} (hf : ¬ f.IsCobounded (· ≤ ·)) : limsSup f = 0 := by rwa [limsSup, sInf_of_not_bddBelow] @[simp] lemma limsSup_of_not_isBounded {f : Filter ℝ} (hf : ¬ f.IsBounded (· ≤ ·)) : limsSup f = 0 := by rw [limsSup] convert sInf_empty simpa [Set.eq_empty_iff_forall_notMem, IsBounded] using hf @[simp] lemma limsInf_of_not_isCobounded {f : Filter ℝ} (hf : ¬ f.IsCobounded (· ≥ ·)) : limsInf f = 0 := by rwa [limsInf, sSup_of_not_bddAbove] @[simp] lemma limsInf_of_not_isBounded {f : Filter ℝ} (hf : ¬ f.IsBounded (· ≥ ·)) : limsInf f = 0 := by rw [limsInf] convert sSup_empty simpa [Set.eq_empty_iff_forall_notMem, IsBounded] using hf @[simp] lemma limsup_of_not_isCoboundedUnder (hf : ¬ f.IsCoboundedUnder (· ≤ ·) u) : limsup u f = 0 := limsSup_of_not_isCobounded hf @[simp] lemma limsup_of_not_isBoundedUnder (hf : ¬ f.IsBoundedUnder (· ≤ ·) u) : limsup u f = 0 := limsSup_of_not_isBounded hf @[simp] lemma liminf_of_not_isCoboundedUnder (hf : ¬ f.IsCoboundedUnder (· ≥ ·) u) : liminf u f = 0 := limsInf_of_not_isCobounded hf @[simp] lemma liminf_of_not_isBoundedUnder (hf : ¬ f.IsBoundedUnder (· ≥ ·) u) : liminf u f = 0 := limsInf_of_not_isBounded hf end Real namespace NNReal variable {ι : Type*} {f : Filter ι} {u : ι → ℝ≥0} @[simp, norm_cast] lemma isBoundedUnder_le_toReal : IsBoundedUnder (· ≤ ·) f (fun i ↦ (u i : ℝ)) ↔ IsBoundedUnder (· ≤ ·) f u := by simp only [IsBoundedUnder, IsBounded, eventually_map, ← coe_le_coe, NNReal.exists, coe_mk] constructor · rintro ⟨b, hb⟩ exact ⟨b.toNNReal, by simp, by filter_upwards [hb]; simp +contextual⟩ · rintro ⟨b, -, hb⟩ exact ⟨b, hb⟩ @[simp, norm_cast] lemma isBoundedUnder_ge_toReal : IsBoundedUnder (· ≥ ·) f (fun i ↦ (u i : ℝ)) ↔ IsBoundedUnder (· ≥ ·) f u := by simp only [IsBoundedUnder, IsBounded, eventually_map, ← coe_le_coe, NNReal.exists, coe_mk] constructor · rintro ⟨b, hb⟩ exact ⟨b.toNNReal, by simp, by simpa⟩ · rintro ⟨b, -, hb⟩ exact ⟨b, hb⟩ @[simp, norm_cast] lemma isCoboundedUnder_le_toReal [f.NeBot] : IsCoboundedUnder (· ≤ ·) f (fun i ↦ (u i : ℝ)) ↔ IsCoboundedUnder (· ≤ ·) f u := by simp only [IsCoboundedUnder, IsCobounded, eventually_map, ← coe_le_coe, NNReal.forall, NNReal.exists] constructor · rintro ⟨b, hb⟩ exact ⟨b.toNNReal, by simp, fun x _ ↦ by simpa [*] using hb _⟩ · rintro ⟨b, hb₀, hb⟩ exact ⟨b, fun x hx ↦ hb _ (hx.exists.choose_spec.trans' (by simp)) hx⟩ @[simp, norm_cast] lemma isCoboundedUnder_ge_toReal : IsCoboundedUnder (· ≥ ·) f (fun i ↦ (u i : ℝ)) ↔ IsCoboundedUnder (· ≥ ·) f u := by simp only [IsCoboundedUnder, IsCobounded, eventually_map, ← coe_le_coe, NNReal.forall, NNReal.exists] constructor · rintro ⟨b, hb⟩ exact ⟨b, hb _ (by simp), fun x _ ↦ hb _⟩ · rintro ⟨b, hb₀, hb⟩ refine ⟨b, fun x hx ↦ ?_⟩ obtain hx₀ | hx₀ := le_total x 0 · exact hx₀.trans hb₀ · exact hb _ hx₀ hx @[simp] lemma limsSup_of_not_isBounded {f : Filter ℝ≥0} (hf : ¬ f.IsBounded (· ≤ ·)) : limsSup f = 0 := by rw [limsSup, ← bot_eq_zero] convert sInf_empty simpa [Set.eq_empty_iff_forall_notMem, IsBounded] using hf @[simp] lemma limsInf_of_not_isCobounded {f : Filter ℝ≥0} (hf : ¬ f.IsCobounded (· ≥ ·)) : limsInf f = 0 := by rwa [limsInf, sSup_of_not_bddAbove] @[simp] lemma limsup_of_not_isBoundedUnder (hf : ¬ f.IsBoundedUnder (· ≤ ·) u) : limsup u f = 0 := limsSup_of_not_isBounded hf @[simp] lemma liminf_of_not_isCoboundedUnder (hf : ¬ f.IsCoboundedUnder (· ≥ ·) u) : liminf u f = 0 := limsInf_of_not_isCobounded hf @[simp, norm_cast] lemma toReal_liminf : liminf (fun i ↦ (u i : ℝ)) f = liminf u f := by by_cases hf : f.IsCoboundedUnder (· ≥ ·) u; swap · simp [*] refine eq_of_forall_le_iff fun c ↦ ?_ rw [← Real.toNNReal_le_iff_le_coe, le_liminf_iff (by simpa) ⟨0, by simp⟩, le_liminf_iff] simp only [← coe_lt_coe, Real.coe_toNNReal', lt_sup_iff, or_imp, isEmpty_Prop, not_lt, zero_le_coe, IsEmpty.forall_iff, and_true, NNReal.forall, coe_mk, forall_swap (α := _ ≤ _)] refine forall₂_congr fun r hr ↦ ?_ simpa using (le_or_gt 0 r).imp_right fun hr ↦ .of_forall fun i ↦ hr.trans_le (by simp) @[simp, norm_cast] lemma toReal_limsup : limsup (fun i ↦ (u i : ℝ)) f = limsup u f := by obtain rfl | hf := f.eq_or_neBot · simp [limsup, limsSup] by_cases hf : f.IsBoundedUnder (· ≤ ·) u; swap · simp [*] have : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault refine eq_of_forall_le_iff fun c ↦ ?_ rw [← Real.toNNReal_le_iff_le_coe, le_limsup_iff (by simpa) (by simpa), le_limsup_iff ‹_›] simp only [← coe_lt_coe, Real.coe_toNNReal', lt_sup_iff, or_imp, isEmpty_Prop, not_lt, zero_le_coe, IsEmpty.forall_iff, and_true, NNReal.forall, coe_mk, forall_swap (α := _ ≤ _)] refine forall₂_congr fun r hr ↦ ?_ simpa using (le_or_gt 0 r).imp_right fun hr ↦ .of_forall fun i ↦ hr.trans_le (by simp) end NNReal namespace ENNReal variable {α : Type*} {f : Filter α} theorem eventually_le_limsup [CountableInterFilter f] (u : α → ℝ≥0∞) : ∀ᶠ y in f, u y ≤ f.limsup u := _root_.eventually_le_limsup theorem limsup_eq_zero_iff [CountableInterFilter f] {u : α → ℝ≥0∞} : f.limsup u = 0 ↔ u =ᶠ[f] 0 := limsup_eq_bot theorem limsup_const_mul_of_ne_top {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha_top : a ≠ ⊤) : (f.limsup fun x : α => a * u x) = a * f.limsup u := by by_cases ha_zero : a = 0 · simp_rw [ha_zero, zero_mul, ← ENNReal.bot_eq_zero] exact limsup_const_bot let g := fun x : ℝ≥0∞ => a * x have hg_bij : Function.Bijective g := Function.bijective_iff_has_inverse.mpr ⟨fun x => a⁻¹ * x, ⟨fun x => by simp [g, ← mul_assoc, ENNReal.inv_mul_cancel ha_zero ha_top], fun x => by simp [g, ← mul_assoc, ENNReal.mul_inv_cancel ha_zero ha_top]⟩⟩ have hg_mono : StrictMono g := Monotone.strictMono_of_injective (fun _ _ _ => by rwa [mul_le_mul_left ha_zero ha_top]) hg_bij.1 let g_iso := StrictMono.orderIsoOfSurjective g hg_mono hg_bij.2 exact (OrderIso.limsup_apply g_iso).symm theorem limsup_const_mul [CountableInterFilter f] {u : α → ℝ≥0∞} {a : ℝ≥0∞} : f.limsup (a * u ·) = a * f.limsup u := by by_cases! ha_top : a ≠ ⊤ · exact limsup_const_mul_of_ne_top ha_top by_cases hu : u =ᶠ[f] 0 · have hau : (a * u ·) =ᶠ[f] 0 := hu.mono fun x hx => by simp [hx] simp only [limsup_congr hu, limsup_congr hau, Pi.zero_def, ← ENNReal.bot_eq_zero, limsup_const_bot] simp · have hu_mul : ∃ᶠ x : α in f, ⊤ ≤ ite (u x = 0) (0 : ℝ≥0∞) ⊤ := by rw [EventuallyEq, not_eventually] at hu refine hu.mono fun x hx => ?_ rw [Pi.zero_apply] at hx simp [hx] have h_top_le : (f.limsup fun x : α => ite (u x = 0) (0 : ℝ≥0∞) ⊤) = ⊤ := eq_top_iff.mpr (le_limsup_of_frequently_le hu_mul) have hfu : f.limsup u ≠ 0 := mt limsup_eq_zero_iff.1 hu simp only [ha_top, top_mul', h_top_le, hfu, ite_false] /-- See also `limsup_mul_le'` -/ theorem limsup_mul_le [CountableInterFilter f] (u v : α → ℝ≥0∞) : f.limsup (u * v) ≤ f.limsup u * f.limsup v := calc f.limsup (u * v) ≤ f.limsup fun x => f.limsup u * v x := by refine limsup_le_limsup ?_ filter_upwards [@eventually_le_limsup _ f _ u] with x hx using mul_le_mul' hx le_rfl _ = f.limsup u * f.limsup v := limsup_const_mul theorem limsup_add_le [CountableInterFilter f] (u v : α → ℝ≥0∞) : f.limsup (u + v) ≤ f.limsup u + f.limsup v := sInf_le ((eventually_le_limsup u).mp ((eventually_le_limsup v).mono fun _ hxg hxf => add_le_add hxf hxg)) theorem limsup_liminf_le_liminf_limsup {β} [Countable β] {f : Filter α} [CountableInterFilter f] {g : Filter β} (u : α → β → ℝ≥0∞) : (f.limsup fun a : α => g.liminf fun b : β => u a b) ≤ g.liminf fun b => f.limsup fun a => u a b := have h1 : ∀ᶠ a in f, ∀ b, u a b ≤ f.limsup fun a' => u a' b := by rw [eventually_countable_forall] exact fun b => ENNReal.eventually_le_limsup fun a => u a b sInf_le <| h1.mono fun x hx => Filter.liminf_le_liminf (Filter.Eventually.of_forall hx) end ENNReal
.lake/packages/mathlib/Mathlib/Order/Filter/Ring.lean
import Mathlib.Order.Filter.Germ.OrderedMonoid import Mathlib.Algebra.Order.Ring.Defs /-! # Lemmas about filters and ordered rings. -/ namespace Filter open Function Filter universe u v variable {α : Type u} {β : Type v} theorem EventuallyLE.mul_le_mul [MulZeroClass β] [Preorder β] [PosMulMono β] [MulPosMono β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) (hg₀ : 0 ≤ᶠ[l] g₁) (hf₀ : 0 ≤ᶠ[l] f₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by filter_upwards [hf, hg, hg₀, hf₀] with x using _root_.mul_le_mul @[to_additive EventuallyLE.add_le_add] theorem EventuallyLE.mul_le_mul' [Mul β] [Preorder β] [MulLeftMono β] [MulRightMono β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by filter_upwards [hf, hg] with x hfx hgx using _root_.mul_le_mul' hfx hgx theorem EventuallyLE.mul_nonneg [Semiring β] [PartialOrder β] [IsOrderedRing β] {l : Filter α} {f g : α → β} (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) : 0 ≤ᶠ[l] f * g := by filter_upwards [hf, hg] with x using _root_.mul_nonneg theorem eventually_sub_nonneg [AddGroup β] [LE β] [AddRightMono β] {l : Filter α} {f g : α → β} : 0 ≤ᶠ[l] g - f ↔ f ≤ᶠ[l] g := eventually_congr <| Eventually.of_forall fun _ => sub_nonneg namespace Germ variable {l : Filter α} instance instIsOrderedRing [Semiring β] [PartialOrder β] [IsOrderedRing β] : IsOrderedRing (Germ l β) where zero_le_one := const_le zero_le_one mul_le_mul_of_nonneg_left x := inductionOn x fun _f hx y z ↦ inductionOn₂ y z fun _g _h hfg ↦ hx.mp <| hfg.mono fun _a ↦ mul_le_mul_of_nonneg_left mul_le_mul_of_nonneg_right x := inductionOn x fun _f hx y z ↦ inductionOn₂ y z fun _g _h hfg ↦ hx.mp <| hfg.mono fun _a ↦ mul_le_mul_of_nonneg_right end Germ end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Curry.lean
import Mathlib.Order.Filter.Prod /-! # Curried Filters This file provides an operation (`Filter.curry`) on filters which provides the equivalence `∀ᶠ a in l, ∀ᶠ b in l', p (a, b) ↔ ∀ᶠ c in (l.curry l'), p c` (see `Filter.eventually_curry_iff`). To understand when this operation might arise, it is helpful to think of `∀ᶠ` as a combination of the quantifiers `∃ ∀`. For instance, `∀ᶠ n in atTop, p n ↔ ∃ N, ∀ n ≥ N, p n`. A curried filter yields the quantifier order `∃ ∀ ∃ ∀`. For instance, `∀ᶠ n in atTop.curry atTop, p n ↔ ∃ M, ∀ m ≥ M, ∃ N, ∀ n ≥ N, p (m, n)`. This is different from a product filter, which instead yields a quantifier order `∃ ∃ ∀ ∀`. For instance, `∀ᶠ n in atTop ×ˢ atTop, p n ↔ ∃ M, ∃ N, ∀ m ≥ M, ∀ n ≥ N, p (m, n)`. This makes it clear that if something eventually occurs on the product filter, it eventually occurs on the curried filter (see `Filter.curry_le_prod` and `Filter.Eventually.curry`), but the converse is not true. Another way to think about the curried versus the product filter is that tending to some limit on the product filter is a version of uniform convergence (see `tendsto_prod_filter_iff`) whereas tending to some limit on a curried filter is just iterated limits (see `Filter.Tendsto.curry`). In the "generalized set" intuition, `Filter.prod` and `Filter.curry` correspond to two ways of describing the product of two sets, namely `s ×ˢ t = fst ⁻¹' s ∩ snd ⁻¹' t` and `s ×ˢ t = ⋃ x ∈ s, (x, ·) '' t`. ## Main definitions * `Filter.curry`: A binary operation on filters which represents iterated limits ## Main statements * `Filter.eventually_curry_iff`: An alternative definition of a curried filter * `Filter.curry_le_prod`: Something that is eventually true on the a product filter is eventually true on the curried filter ## Tags uniform convergence, curried filters, product filters -/ namespace Filter variable {α β γ : Type*} {l : Filter α} {m : Filter β} {s : Set α} {t : Set β} theorem eventually_curry_iff {p : α × β → Prop} : (∀ᶠ x : α × β in l.curry m, p x) ↔ ∀ᶠ x : α in l, ∀ᶠ y : β in m, p (x, y) := Iff.rfl theorem frequently_curry_iff (p : (α × β) → Prop) : (∃ᶠ x in l.curry m, p x) ↔ ∃ᶠ x in l, ∃ᶠ y in m, p (x, y) := by simp_rw [Filter.Frequently, not_iff_not, not_not, eventually_curry_iff] theorem mem_curry_iff {s : Set (α × β)} : s ∈ l.curry m ↔ ∀ᶠ x : α in l, ∀ᶠ y : β in m, (x, y) ∈ s := Iff.rfl theorem curry_le_prod : l.curry m ≤ l ×ˢ m := fun _ => Eventually.curry theorem Tendsto.curry {f : α → β → γ} {la : Filter α} {lb : Filter β} {lc : Filter γ} (h : ∀ᶠ a in la, Tendsto (fun b : β => f a b) lb lc) : Tendsto ↿f (la.curry lb) lc := fun _s hs => h.mono fun _a ha => ha hs theorem frequently_curry_prod_iff : (∃ᶠ x in l.curry m, x ∈ s ×ˢ t) ↔ (∃ᶠ x in l, x ∈ s) ∧ ∃ᶠ y in m, y ∈ t := by simp [frequently_curry_iff] theorem eventually_curry_prod_iff [NeBot l] [NeBot m] : (∀ᶠ x in l.curry m, x ∈ s ×ˢ t) ↔ s ∈ l ∧ t ∈ m := by simp [eventually_curry_iff] theorem prod_mem_curry (hs : s ∈ l) (ht : t ∈ m) : s ×ˢ t ∈ l.curry m := curry_le_prod <| prod_mem_prod hs ht end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/CountablyGenerated.lean
import Mathlib.Data.Set.Countable import Mathlib.Order.Filter.Bases.Finite /-! # Countably generated filters In this file we define a typeclass `Filter.IsCountablyGenerated` saying that a filter is generated by a countable family of sets. We also define predicates `Filter.IsCountableBasis` and `Filter.HasCountableBasis` saying that a specific family of sets is a countable basis. -/ open Set namespace Filter variable {α β γ ι : Type*} {ι' : Sort*} /-- `IsCountablyGenerated f` means `f = generate s` for some countable `s`. -/ class IsCountablyGenerated (f : Filter α) : Prop where /-- There exists a countable set that generates the filter. -/ out : ∃ s : Set (Set α), s.Countable ∧ f = generate s /-- `IsCountableBasis p s` means the image of `s` bounded by `p` is a countable filter basis. -/ structure IsCountableBasis (p : ι → Prop) (s : ι → Set α) : Prop extends IsBasis p s where /-- The set of `i` that satisfy the predicate `p` is countable. -/ countable : (setOf p).Countable /-- We say that a filter `l` has a countable basis `s : ι → Set α` bounded by `p : ι → Prop`, if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`, and the set defined by `p` is countable. -/ structure HasCountableBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop extends HasBasis l p s where /-- The set of `i` that satisfy the predicate `p` is countable. -/ countable : (setOf p).Countable /-- A countable filter basis `B` on a type `α` is a nonempty countable collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ structure CountableFilterBasis (α : Type*) extends FilterBasis α where /-- The set of sets of the filter basis is countable. -/ countable : sets.Countable -- For illustration purposes, the countable filter basis defining `(atTop : Filter ℕ)` instance Nat.inhabitedCountableFilterBasis : Inhabited (CountableFilterBasis ℕ) := ⟨⟨default, countable_range fun n => Ici n⟩⟩ theorem HasCountableBasis.isCountablyGenerated {f : Filter α} {p : ι → Prop} {s : ι → Set α} (h : f.HasCountableBasis p s) : f.IsCountablyGenerated := ⟨⟨{ t | ∃ i, p i ∧ s i = t }, h.countable.image s, h.toHasBasis.eq_generate⟩⟩ theorem HasBasis.isCountablyGenerated [Countable ι] {f : Filter α} {p : ι → Prop} {s : ι → Set α} (h : f.HasBasis p s) : f.IsCountablyGenerated := HasCountableBasis.isCountablyGenerated ⟨h, to_countable _⟩ theorem antitone_seq_of_seq (s : ℕ → Set α) : ∃ t : ℕ → Set α, Antitone t ∧ ⨅ i, 𝓟 (s i) = ⨅ i, 𝓟 (t i) := by use fun n => ⋂ m ≤ n, s m; constructor · exact fun i j hij => biInter_mono (Iic_subset_Iic.2 hij) fun n _ => Subset.rfl apply le_antisymm <;> rw [le_iInf_iff] <;> intro i · rw [le_principal_iff] refine (biInter_mem (finite_le_nat _)).2 fun j _ => ?_ exact mem_iInf_of_mem j (mem_principal_self _) · refine iInf_le_of_le i (principal_mono.2 <| iInter₂_subset i ?_) rfl theorem countable_biInf_eq_iInf_seq [CompleteLattice α] {B : Set ι} (Bcbl : B.Countable) (Bne : B.Nonempty) (f : ι → α) : ∃ x : ℕ → ι, ⨅ t ∈ B, f t = ⨅ i, f (x i) := let ⟨g, hg⟩ := Bcbl.exists_eq_range Bne ⟨g, hg.symm ▸ iInf_range⟩ theorem countable_biInf_eq_iInf_seq' [CompleteLattice α] {B : Set ι} (Bcbl : B.Countable) (f : ι → α) {i₀ : ι} (h : f i₀ = ⊤) : ∃ x : ℕ → ι, ⨅ t ∈ B, f t = ⨅ i, f (x i) := by rcases B.eq_empty_or_nonempty with hB | Bnonempty · rw [hB, iInf_emptyset] use fun _ => i₀ simp [h] · exact countable_biInf_eq_iInf_seq Bcbl Bnonempty f theorem countable_biInf_principal_eq_seq_iInf {B : Set (Set α)} (Bcbl : B.Countable) : ∃ x : ℕ → Set α, ⨅ t ∈ B, 𝓟 t = ⨅ i, 𝓟 (x i) := countable_biInf_eq_iInf_seq' Bcbl 𝓟 principal_univ section IsCountablyGenerated protected theorem HasAntitoneBasis.mem_iff [Preorder ι] {l : Filter α} {s : ι → Set α} (hs : l.HasAntitoneBasis s) {t : Set α} : t ∈ l ↔ ∃ i, s i ⊆ t := hs.toHasBasis.mem_iff.trans <| by simp only [true_and] protected theorem HasAntitoneBasis.mem [Preorder ι] {l : Filter α} {s : ι → Set α} (hs : l.HasAntitoneBasis s) (i : ι) : s i ∈ l := hs.toHasBasis.mem_of_mem trivial theorem HasAntitoneBasis.hasBasis_ge [Preorder ι] [IsDirected ι (· ≤ ·)] {l : Filter α} {s : ι → Set α} (hs : l.HasAntitoneBasis s) (i : ι) : l.HasBasis (fun j => i ≤ j) s := hs.1.to_hasBasis (fun j _ => (exists_ge_ge i j).imp fun _k hk => ⟨hk.1, hs.2 hk.2⟩) fun j _ => ⟨j, trivial, Subset.rfl⟩ /-- If `f` is countably generated and `f.HasBasis p s`, then `f` admits a decreasing basis enumerated by natural numbers such that all sets have the form `s i`. More precisely, there is a sequence `i n` such that `p (i n)` for all `n` and `s (i n)` is a decreasing sequence of sets which forms a basis of `f`. -/ theorem HasBasis.exists_antitone_subbasis {f : Filter α} [h : f.IsCountablyGenerated] {p : ι' → Prop} {s : ι' → Set α} (hs : f.HasBasis p s) : ∃ x : ℕ → ι', (∀ i, p (x i)) ∧ f.HasAntitoneBasis fun i => s (x i) := by obtain ⟨x', hx'⟩ : ∃ x : ℕ → Set α, f = ⨅ i, 𝓟 (x i) := by rcases h with ⟨s, hsc, rfl⟩ rw [generate_eq_biInf] exact countable_biInf_principal_eq_seq_iInf hsc have : ∀ i, x' i ∈ f := fun i => hx'.symm ▸ (iInf_le (fun i => 𝓟 (x' i)) i) (mem_principal_self _) let x : ℕ → { i : ι' // p i } := fun n => Nat.recOn n (hs.index _ <| this 0) fun n xn => hs.index _ <| inter_mem (this <| n + 1) (hs.mem_of_mem xn.2) have x_anti : Antitone fun i => s (x i).1 := antitone_nat_of_succ_le fun i => (hs.set_index_subset _).trans inter_subset_right have x_subset : ∀ i, s (x i).1 ⊆ x' i := by rintro (_ | i) exacts [hs.set_index_subset _, (hs.set_index_subset _).trans inter_subset_left] refine ⟨fun i => (x i).1, fun i => (x i).2, ?_⟩ have : (⨅ i, 𝓟 (s (x i).1)).HasAntitoneBasis fun i => s (x i).1 := .iInf_principal x_anti convert this exact le_antisymm (le_iInf fun i => le_principal_iff.2 <| by cases i <;> apply hs.set_index_mem) (hx'.symm ▸ le_iInf fun i => le_principal_iff.2 <| this.1.mem_iff.2 ⟨i, trivial, x_subset i⟩) /-- A countably generated filter admits a basis formed by an antitone sequence of sets. -/ theorem exists_antitone_basis (f : Filter α) [f.IsCountablyGenerated] : ∃ x : ℕ → Set α, f.HasAntitoneBasis x := let ⟨x, _, hx⟩ := f.basis_sets.exists_antitone_subbasis ⟨x, hx⟩ theorem exists_antitone_seq (f : Filter α) [f.IsCountablyGenerated] : ∃ x : ℕ → Set α, Antitone x ∧ ∀ {s}, s ∈ f ↔ ∃ i, x i ⊆ s := let ⟨x, hx⟩ := f.exists_antitone_basis ⟨x, hx.antitone, by simp [hx.1.mem_iff]⟩ instance Inf.isCountablyGenerated (f g : Filter α) [IsCountablyGenerated f] [IsCountablyGenerated g] : IsCountablyGenerated (f ⊓ g) := by rcases f.exists_antitone_basis with ⟨s, hs⟩ rcases g.exists_antitone_basis with ⟨t, ht⟩ exact HasCountableBasis.isCountablyGenerated ⟨hs.1.inf ht.1, Set.to_countable _⟩ instance map.isCountablyGenerated (l : Filter α) [l.IsCountablyGenerated] (f : α → β) : (map f l).IsCountablyGenerated := let ⟨_x, hxl⟩ := l.exists_antitone_basis (hxl.map _).isCountablyGenerated instance comap.isCountablyGenerated (l : Filter β) [l.IsCountablyGenerated] (f : α → β) : (comap f l).IsCountablyGenerated := let ⟨_x, hxl⟩ := l.exists_antitone_basis (hxl.comap _).isCountablyGenerated instance Sup.isCountablyGenerated (f g : Filter α) [IsCountablyGenerated f] [IsCountablyGenerated g] : IsCountablyGenerated (f ⊔ g) := by rcases f.exists_antitone_basis with ⟨s, hs⟩ rcases g.exists_antitone_basis with ⟨t, ht⟩ exact HasCountableBasis.isCountablyGenerated ⟨hs.1.sup ht.1, Set.to_countable _⟩ instance prod.isCountablyGenerated (la : Filter α) (lb : Filter β) [IsCountablyGenerated la] [IsCountablyGenerated lb] : IsCountablyGenerated (la ×ˢ lb) := Filter.Inf.isCountablyGenerated _ _ instance coprod.isCountablyGenerated (la : Filter α) (lb : Filter β) [IsCountablyGenerated la] [IsCountablyGenerated lb] : IsCountablyGenerated (la.coprod lb) := Filter.Sup.isCountablyGenerated _ _ end IsCountablyGenerated theorem isCountablyGenerated_seq [Countable ι'] (x : ι' → Set α) : IsCountablyGenerated (⨅ i, 𝓟 (x i)) := by use range x, countable_range x rw [generate_eq_biInf, iInf_range] theorem isCountablyGenerated_of_seq {f : Filter α} (h : ∃ x : ℕ → Set α, f = ⨅ i, 𝓟 (x i)) : f.IsCountablyGenerated := by rcases h with ⟨x, rfl⟩ apply isCountablyGenerated_seq theorem isCountablyGenerated_biInf_principal {B : Set (Set α)} (h : B.Countable) : IsCountablyGenerated (⨅ s ∈ B, 𝓟 s) := isCountablyGenerated_of_seq (countable_biInf_principal_eq_seq_iInf h) theorem isCountablyGenerated_iff_exists_antitone_basis {f : Filter α} : IsCountablyGenerated f ↔ ∃ x : ℕ → Set α, f.HasAntitoneBasis x := by constructor · intro h exact f.exists_antitone_basis · rintro ⟨x, h⟩ rw [h.1.eq_iInf] exact isCountablyGenerated_seq x @[instance] theorem isCountablyGenerated_principal (s : Set α) : IsCountablyGenerated (𝓟 s) := isCountablyGenerated_of_seq ⟨fun _ => s, iInf_const.symm⟩ @[instance] theorem isCountablyGenerated_pure (a : α) : IsCountablyGenerated (pure a) := by rw [← principal_singleton] exact isCountablyGenerated_principal _ @[instance] theorem isCountablyGenerated_bot : IsCountablyGenerated (⊥ : Filter α) := @principal_empty α ▸ isCountablyGenerated_principal _ @[instance] theorem isCountablyGenerated_top : IsCountablyGenerated (⊤ : Filter α) := @principal_univ α ▸ isCountablyGenerated_principal _ instance iInf.isCountablyGenerated {ι : Sort*} {α : Type*} [Countable ι] (f : ι → Filter α) [∀ i, IsCountablyGenerated (f i)] : IsCountablyGenerated (⨅ i, f i) := by choose s hs using fun i => exists_antitone_basis (f i) rw [← PLift.down_surjective.iInf_comp] refine HasCountableBasis.isCountablyGenerated ⟨.iInf fun n => (hs _).1, ?_⟩ refine (countable_range <| Sigma.map ((↑) : Finset (PLift ι) → Set (PLift ι)) fun _ => id).mono ?_ rintro ⟨I, f⟩ ⟨hI, -⟩ lift I to Finset (PLift ι) using hI exact ⟨⟨I, f⟩, rfl⟩ instance pi.isCountablyGenerated {ι : Type*} {α : ι → Type*} [Countable ι] (f : ∀ i, Filter (α i)) [∀ i, IsCountablyGenerated (f i)] : IsCountablyGenerated (pi f) := iInf.isCountablyGenerated _ end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Tendsto.lean
import Mathlib.Order.Filter.Basic import Mathlib.Order.Filter.Map /-! # Convergence in terms of filters The general notion of limit of a map with respect to filters on the source and target types is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation. For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of `M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`, which is a special case of `mem_closure_of_tendsto` from `Topology/Basic`. -/ open Set Filter variable {α β γ : Type*} {ι : Sort*} namespace Filter theorem tendsto_def {f : α → β} {l₁ : Filter α} {l₂ : Filter β} : Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f ⁻¹' s ∈ l₁ := Iff.rfl theorem tendsto_iff_eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} : Tendsto f l₁ l₂ ↔ ∀ ⦃p : β → Prop⦄, (∀ᶠ y in l₂, p y) → ∀ᶠ x in l₁, p (f x) := Iff.rfl theorem tendsto_iff_forall_eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} : Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, ∀ᶠ x in l₁, f x ∈ s := Iff.rfl lemma Tendsto.eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {s : Set β} (hf : Tendsto f l₁ l₂) (h : s ∈ l₂) : ∀ᶠ x in l₁, f x ∈ s := hf h theorem Tendsto.eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop} (hf : Tendsto f l₁ l₂) (h : ∀ᶠ y in l₂, p y) : ∀ᶠ x in l₁, p (f x) := hf h theorem not_tendsto_iff_exists_frequently_notMem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} : ¬Tendsto f l₁ l₂ ↔ ∃ s ∈ l₂, ∃ᶠ x in l₁, f x ∉ s := by simp only [tendsto_iff_forall_eventually_mem, not_forall, exists_prop, not_eventually] @[deprecated (since := "2025-05-24")] alias not_tendsto_iff_exists_frequently_nmem := not_tendsto_iff_exists_frequently_notMem theorem Tendsto.frequently {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop} (hf : Tendsto f l₁ l₂) (h : ∃ᶠ x in l₁, p (f x)) : ∃ᶠ y in l₂, p y := mt hf.eventually h theorem Tendsto.frequently_map {l₁ : Filter α} {l₂ : Filter β} {p : α → Prop} {q : β → Prop} (f : α → β) (c : Filter.Tendsto f l₁ l₂) (w : ∀ x, p x → q (f x)) (h : ∃ᶠ x in l₁, p x) : ∃ᶠ y in l₂, q y := c.frequently (h.mono w) @[simp] theorem tendsto_bot {f : α → β} {l : Filter β} : Tendsto f ⊥ l := by simp [Tendsto] theorem Tendsto.of_neBot_imp {f : α → β} {la : Filter α} {lb : Filter β} (h : NeBot la → Tendsto f la lb) : Tendsto f la lb := by rcases eq_or_neBot la with rfl | hla · exact tendsto_bot · exact h hla @[simp] theorem tendsto_top {f : α → β} {l : Filter α} : Tendsto f l ⊤ := le_top theorem le_map_of_right_inverse {mab : α → β} {mba : β → α} {f : Filter α} {g : Filter β} (h₁ : mab ∘ mba =ᶠ[g] id) (h₂ : Tendsto mba g f) : g ≤ map mab f := by rw [← @map_id _ g, ← map_congr h₁, ← map_map] exact map_mono h₂ theorem tendsto_of_isEmpty [IsEmpty α] {f : α → β} {la : Filter α} {lb : Filter β} : Tendsto f la lb := by simp only [filter_eq_bot_of_isEmpty la, tendsto_bot] theorem eventuallyEq_of_left_inv_of_right_inv {f : α → β} {g₁ g₂ : β → α} {fa : Filter α} {fb : Filter β} (hleft : ∀ᶠ x in fa, g₁ (f x) = x) (hright : ∀ᶠ y in fb, f (g₂ y) = y) (htendsto : Tendsto g₂ fb fa) : g₁ =ᶠ[fb] g₂ := (htendsto.eventually hleft).mp <| hright.mono fun _ hr hl => (congr_arg g₁ hr.symm).trans hl theorem tendsto_iff_comap {f : α → β} {l₁ : Filter α} {l₂ : Filter β} : Tendsto f l₁ l₂ ↔ l₁ ≤ l₂.comap f := map_le_iff_le_comap alias ⟨Tendsto.le_comap, _⟩ := tendsto_iff_comap protected theorem Tendsto.disjoint {f : α → β} {la₁ la₂ : Filter α} {lb₁ lb₂ : Filter β} (h₁ : Tendsto f la₁ lb₁) (hd : Disjoint lb₁ lb₂) (h₂ : Tendsto f la₂ lb₂) : Disjoint la₁ la₂ := (disjoint_comap hd).mono h₁.le_comap h₂.le_comap theorem tendsto_congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂) : Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ := by rw [Tendsto, Tendsto, map_congr hl] theorem Tendsto.congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂) (h : Tendsto f₁ l₁ l₂) : Tendsto f₂ l₁ l₂ := (tendsto_congr' hl).1 h theorem tendsto_congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) : Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ := tendsto_congr' (univ_mem' h) theorem Tendsto.congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) : Tendsto f₁ l₁ l₂ → Tendsto f₂ l₁ l₂ := (tendsto_congr h).1 theorem tendsto_id' {x y : Filter α} : Tendsto id x y ↔ x ≤ y := Iff.rfl theorem tendsto_id {x : Filter α} : Tendsto id x x := le_refl x theorem Tendsto.comp {f : α → β} {g : β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} (hg : Tendsto g y z) (hf : Tendsto f x y) : Tendsto (g ∘ f) x z := fun _ hs => hf (hg hs) protected theorem Tendsto.iterate {f : α → α} {l : Filter α} (h : Tendsto f l l) : ∀ n, Tendsto (f^[n]) l l | 0 => tendsto_id | (n + 1) => (h.iterate n).comp h theorem Tendsto.mono_left {f : α → β} {x y : Filter α} {z : Filter β} (hx : Tendsto f x z) (h : y ≤ x) : Tendsto f y z := (map_mono h).trans hx theorem Tendsto.mono_right {f : α → β} {x : Filter α} {y z : Filter β} (hy : Tendsto f x y) (hz : y ≤ z) : Tendsto f x z := le_trans hy hz theorem Tendsto.neBot {f : α → β} {x : Filter α} {y : Filter β} (h : Tendsto f x y) [hx : NeBot x] : NeBot y := (hx.map _).mono h theorem tendsto_map {f : α → β} {x : Filter α} : Tendsto f x (map f x) := le_refl (map f x) @[simp] theorem tendsto_map'_iff {f : β → γ} {g : α → β} {x : Filter α} {y : Filter γ} : Tendsto f (map g x) y ↔ Tendsto (f ∘ g) x y := by rw [Tendsto, Tendsto, map_map] alias ⟨_, tendsto_map'⟩ := tendsto_map'_iff theorem tendsto_comap {f : α → β} {x : Filter β} : Tendsto f (comap f x) x := map_comap_le @[simp] theorem tendsto_comap_iff {f : α → β} {g : β → γ} {a : Filter α} {c : Filter γ} : Tendsto f a (c.comap g) ↔ Tendsto (g ∘ f) a c := ⟨fun h => tendsto_comap.comp h, fun h => map_le_iff_le_comap.mp <| by rwa [map_map]⟩ theorem tendsto_comap'_iff {m : α → β} {f : Filter α} {g : Filter β} {i : γ → α} (h : range i ∈ f) : Tendsto (m ∘ i) (comap i f) g ↔ Tendsto m f g := by rw [Tendsto, ← map_compose] simp only [(· ∘ ·), map_comap_of_mem h, Tendsto] theorem Tendsto.of_tendsto_comp {f : α → β} {g : β → γ} {a : Filter α} {b : Filter β} {c : Filter γ} (hfg : Tendsto (g ∘ f) a c) (hg : comap g c ≤ b) : Tendsto f a b := by rw [tendsto_iff_comap] at hfg ⊢ calc a ≤ comap (g ∘ f) c := hfg _ ≤ comap f b := by simpa [comap_comap] using comap_mono hg theorem comap_eq_of_inverse {f : Filter α} {g : Filter β} {φ : α → β} (ψ : β → α) (eq : ψ ∘ φ = id) (hφ : Tendsto φ f g) (hψ : Tendsto ψ g f) : comap φ g = f := by refine ((comap_mono <| map_le_iff_le_comap.1 hψ).trans ?_).antisymm (map_le_iff_le_comap.1 hφ) rw [comap_comap, eq, comap_id] theorem map_eq_of_inverse {f : Filter α} {g : Filter β} {φ : α → β} (ψ : β → α) (eq : φ ∘ ψ = id) (hφ : Tendsto φ f g) (hψ : Tendsto ψ g f) : map φ f = g := by refine le_antisymm hφ (le_trans ?_ (map_mono hψ)) rw [map_map, eq, map_id] theorem tendsto_inf {f : α → β} {x : Filter α} {y₁ y₂ : Filter β} : Tendsto f x (y₁ ⊓ y₂) ↔ Tendsto f x y₁ ∧ Tendsto f x y₂ := by simp only [Tendsto, le_inf_iff] theorem tendsto_inf_left {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} (h : Tendsto f x₁ y) : Tendsto f (x₁ ⊓ x₂) y := le_trans (map_mono inf_le_left) h theorem tendsto_inf_right {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} (h : Tendsto f x₂ y) : Tendsto f (x₁ ⊓ x₂) y := le_trans (map_mono inf_le_right) h theorem Tendsto.inf {f : α → β} {x₁ x₂ : Filter α} {y₁ y₂ : Filter β} (h₁ : Tendsto f x₁ y₁) (h₂ : Tendsto f x₂ y₂) : Tendsto f (x₁ ⊓ x₂) (y₁ ⊓ y₂) := tendsto_inf.2 ⟨tendsto_inf_left h₁, tendsto_inf_right h₂⟩ @[simp] theorem tendsto_iInf {f : α → β} {x : Filter α} {y : ι → Filter β} : Tendsto f x (⨅ i, y i) ↔ ∀ i, Tendsto f x (y i) := by simp only [Tendsto, le_iInf_iff] theorem tendsto_iInf' {f : α → β} {x : ι → Filter α} {y : Filter β} (i : ι) (hi : Tendsto f (x i) y) : Tendsto f (⨅ i, x i) y := hi.mono_left <| iInf_le _ _ theorem tendsto_iInf_iInf {f : α → β} {x : ι → Filter α} {y : ι → Filter β} (h : ∀ i, Tendsto f (x i) (y i)) : Tendsto f (iInf x) (iInf y) := tendsto_iInf.2 fun i => tendsto_iInf' i (h i) @[simp] theorem tendsto_sup {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} : Tendsto f (x₁ ⊔ x₂) y ↔ Tendsto f x₁ y ∧ Tendsto f x₂ y := by simp only [Tendsto, map_sup, sup_le_iff] theorem Tendsto.sup {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} : Tendsto f x₁ y → Tendsto f x₂ y → Tendsto f (x₁ ⊔ x₂) y := fun h₁ h₂ => tendsto_sup.mpr ⟨h₁, h₂⟩ theorem Tendsto.sup_sup {f : α → β} {x₁ x₂ : Filter α} {y₁ y₂ : Filter β} (h₁ : Tendsto f x₁ y₁) (h₂ : Tendsto f x₂ y₂) : Tendsto f (x₁ ⊔ x₂) (y₁ ⊔ y₂) := tendsto_sup.mpr ⟨h₁.mono_right le_sup_left, h₂.mono_right le_sup_right⟩ @[simp] theorem tendsto_iSup {f : α → β} {x : ι → Filter α} {y : Filter β} : Tendsto f (⨆ i, x i) y ↔ ∀ i, Tendsto f (x i) y := by simp only [Tendsto, map_iSup, iSup_le_iff] theorem tendsto_iSup_iSup {f : α → β} {x : ι → Filter α} {y : ι → Filter β} (h : ∀ i, Tendsto f (x i) (y i)) : Tendsto f (iSup x) (iSup y) := tendsto_iSup.2 fun i => (h i).mono_right <| le_iSup _ _ @[simp] theorem tendsto_principal {f : α → β} {l : Filter α} {s : Set β} : Tendsto f l (𝓟 s) ↔ ∀ᶠ a in l, f a ∈ s := by simp only [Tendsto, le_principal_iff, mem_map', Filter.Eventually] theorem tendsto_principal_principal {f : α → β} {s : Set α} {t : Set β} : Tendsto f (𝓟 s) (𝓟 t) ↔ ∀ a ∈ s, f a ∈ t := by simp @[simp] theorem tendsto_pure {f : α → β} {a : Filter α} {b : β} : Tendsto f a (pure b) ↔ ∀ᶠ x in a, f x = b := by simp only [Tendsto, le_pure_iff, mem_map', mem_singleton_iff, Filter.Eventually] theorem tendsto_pure_pure (f : α → β) (a : α) : Tendsto f (pure a) (pure (f a)) := tendsto_pure.2 rfl theorem tendsto_const_pure {a : Filter α} {b : β} : Tendsto (fun _ => b) a (pure b) := tendsto_pure.2 <| univ_mem' fun _ => rfl theorem pure_le_iff {a : α} {l : Filter α} : pure a ≤ l ↔ ∀ s ∈ l, a ∈ s := Iff.rfl theorem tendsto_pure_left {f : α → β} {a : α} {l : Filter β} : Tendsto f (pure a) l ↔ ∀ s ∈ l, f a ∈ s := Iff.rfl @[simp] theorem map_inf_principal_preimage {f : α → β} {s : Set β} {l : Filter α} : map f (l ⊓ 𝓟 (f ⁻¹' s)) = map f l ⊓ 𝓟 s := Filter.ext fun t => by simp only [mem_map', mem_inf_principal, mem_setOf_eq, mem_preimage] /-- If two filters are disjoint, then a function cannot tend to both of them along a non-trivial filter. -/ theorem Tendsto.not_tendsto {f : α → β} {a : Filter α} {b₁ b₂ : Filter β} (hf : Tendsto f a b₁) [NeBot a] (hb : Disjoint b₁ b₂) : ¬Tendsto f a b₂ := fun hf' => (tendsto_inf.2 ⟨hf, hf'⟩).neBot.ne hb.eq_bot protected theorem Tendsto.if {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {p : α → Prop} [∀ x, Decidable (p x)] (h₀ : Tendsto f (l₁ ⊓ 𝓟 { x | p x }) l₂) (h₁ : Tendsto g (l₁ ⊓ 𝓟 { x | ¬p x }) l₂) : Tendsto (fun x => if p x then f x else g x) l₁ l₂ := by simp only [tendsto_def, mem_inf_principal] at * intro s hs filter_upwards [h₀ s hs, h₁ s hs] with x hp₀ hp₁ rw [mem_preimage] split_ifs with h exacts [hp₀ h, hp₁ h] protected theorem Tendsto.if' {α β : Type*} {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {p : α → Prop} [DecidablePred p] (hf : Tendsto f l₁ l₂) (hg : Tendsto g l₁ l₂) : Tendsto (fun a => if p a then f a else g a) l₁ l₂ := (tendsto_inf_left hf).if (tendsto_inf_left hg) protected theorem Tendsto.piecewise {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {s : Set α} [∀ x, Decidable (x ∈ s)] (h₀ : Tendsto f (l₁ ⊓ 𝓟 s) l₂) (h₁ : Tendsto g (l₁ ⊓ 𝓟 sᶜ) l₂) : Tendsto (piecewise s f g) l₁ l₂ := Tendsto.if h₀ h₁ end Filter theorem Set.MapsTo.tendsto {s : Set α} {t : Set β} {f : α → β} (h : MapsTo f s t) : Filter.Tendsto f (𝓟 s) (𝓟 t) := Filter.tendsto_principal_principal.2 h theorem Filter.EventuallyEq.comp_tendsto {l : Filter α} {f : α → β} {f' : α → β} (H : f =ᶠ[l] f') {g : γ → α} {lc : Filter γ} (hg : Tendsto g lc l) : f ∘ g =ᶠ[lc] f' ∘ g := hg.eventually H variable {F : Filter α} {G : Filter β} theorem Filter.map_mapsTo_Iic_iff_tendsto {m : α → β} : MapsTo (map m) (Iic F) (Iic G) ↔ Tendsto m F G := ⟨fun hm ↦ hm right_mem_Iic, fun hm _ ↦ hm.mono_left⟩ alias ⟨_, Filter.Tendsto.map_mapsTo_Iic⟩ := Filter.map_mapsTo_Iic_iff_tendsto theorem Filter.map_mapsTo_Iic_iff_mapsTo {s : Set α} {t : Set β} {m : α → β} : MapsTo (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 t) ↔ MapsTo m s t := by rw [map_mapsTo_Iic_iff_tendsto, tendsto_principal_principal, MapsTo] alias ⟨_, Set.MapsTo.filter_map_Iic⟩ := Filter.map_mapsTo_Iic_iff_mapsTo
.lake/packages/mathlib/Mathlib/Order/Filter/ZeroAndBoundedAtFilter.lean
import Mathlib.Algebra.Module.Submodule.Basic import Mathlib.Analysis.Asymptotics.Lemmas import Mathlib.Algebra.Algebra.Pi /-! # Zero and Bounded at filter Given a filter `l` we define the notion of a function being `ZeroAtFilter` as well as being `BoundedAtFilter`. Alongside this we construct the `Submodule`, `AddSubmonoid` of functions that are `ZeroAtFilter`. Similarly, we construct the `Submodule` and `Subalgebra` of functions that are `BoundedAtFilter`. -/ namespace Filter variable {𝕜 α β : Type*} open Topology /-- If `l` is a filter on `α`, then a function `f : α → β` is `ZeroAtFilter l` if it tends to zero along `l`. -/ def ZeroAtFilter [Zero β] [TopologicalSpace β] (l : Filter α) (f : α → β) : Prop := Filter.Tendsto f l (𝓝 0) theorem zero_zeroAtFilter [Zero β] [TopologicalSpace β] (l : Filter α) : ZeroAtFilter l (0 : α → β) := tendsto_const_nhds nonrec theorem ZeroAtFilter.add [TopologicalSpace β] [AddZeroClass β] [ContinuousAdd β] {l : Filter α} {f g : α → β} (hf : ZeroAtFilter l f) (hg : ZeroAtFilter l g) : ZeroAtFilter l (f + g) := by simpa using hf.add hg nonrec theorem ZeroAtFilter.neg [TopologicalSpace β] [SubtractionMonoid β] [ContinuousNeg β] {l : Filter α} {f : α → β} (hf : ZeroAtFilter l f) : ZeroAtFilter l (-f) := by simpa using hf.neg theorem ZeroAtFilter.smul [TopologicalSpace β] [Zero β] [SMulZeroClass 𝕜 β] [ContinuousConstSMul 𝕜 β] {l : Filter α} {f : α → β} (c : 𝕜) (hf : ZeroAtFilter l f) : ZeroAtFilter l (c • f) := by simpa using hf.const_smul c variable (𝕜) in /-- `zeroAtFilterSubmodule l` is the submodule of `f : α → β` which tend to zero along `l`. -/ def zeroAtFilterSubmodule [TopologicalSpace β] [Semiring 𝕜] [AddCommMonoid β] [Module 𝕜 β] [ContinuousAdd β] [ContinuousConstSMul 𝕜 β] (l : Filter α) : Submodule 𝕜 (α → β) where carrier := ZeroAtFilter l zero_mem' := zero_zeroAtFilter l add_mem' ha hb := ha.add hb smul_mem' c _ hf := hf.smul c /-- `zeroAtFilterAddSubmonoid l` is the additive submonoid of `f : α → β` which tend to zero along `l`. -/ def zeroAtFilterAddSubmonoid [TopologicalSpace β] [AddZeroClass β] [ContinuousAdd β] (l : Filter α) : AddSubmonoid (α → β) where carrier := ZeroAtFilter l add_mem' ha hb := ha.add hb zero_mem' := zero_zeroAtFilter l /-- If `l` is a filter on `α`, then a function `f: α → β` is `BoundedAtFilter l` if `f =O[l] 1`. -/ def BoundedAtFilter [Norm β] (l : Filter α) (f : α → β) : Prop := Asymptotics.IsBigO l f (1 : α → ℝ) theorem ZeroAtFilter.boundedAtFilter [SeminormedAddGroup β] {l : Filter α} {f : α → β} (hf : ZeroAtFilter l f) : BoundedAtFilter l f := ((Asymptotics.isLittleO_one_iff _).mpr hf).isBigO theorem const_boundedAtFilter [Norm β] (l : Filter α) (c : β) : BoundedAtFilter l (Function.const α c : α → β) := Asymptotics.isBigO_const_const c one_ne_zero l -- TODO(https://github.com/leanprover-community/mathlib4/issues/19288): Remove all Comm in the next -- three lemmas. This would require modifying the corresponding general asymptotics lemma. nonrec theorem BoundedAtFilter.add [SeminormedAddCommGroup β] {l : Filter α} {f g : α → β} (hf : BoundedAtFilter l f) (hg : BoundedAtFilter l g) : BoundedAtFilter l (f + g) := by simpa using hf.add hg theorem BoundedAtFilter.neg [SeminormedAddCommGroup β] {l : Filter α} {f : α → β} (hf : BoundedAtFilter l f) : BoundedAtFilter l (-f) := hf.neg_left theorem BoundedAtFilter.smul [SeminormedRing 𝕜] [SeminormedAddCommGroup β] [Module 𝕜 β] [IsBoundedSMul 𝕜 β] {l : Filter α} {f : α → β} (c : 𝕜) (hf : BoundedAtFilter l f) : BoundedAtFilter l (c • f) := hf.const_smul_left c nonrec theorem BoundedAtFilter.mul [SeminormedRing β] {l : Filter α} {f g : α → β} (hf : BoundedAtFilter l f) (hg : BoundedAtFilter l g) : BoundedAtFilter l (f * g) := by refine (hf.mul hg).trans ?_ convert Asymptotics.isBigO_refl (E := ℝ) _ l simp variable (𝕜) in /-- The submodule of functions that are bounded along a filter `l`. -/ def boundedFilterSubmodule [SeminormedRing 𝕜] [SeminormedAddCommGroup β] [Module 𝕜 β] [IsBoundedSMul 𝕜 β] (l : Filter α) : Submodule 𝕜 (α → β) where carrier := BoundedAtFilter l zero_mem' := const_boundedAtFilter l 0 add_mem' hf hg := hf.add hg smul_mem' c _ hf := hf.smul c variable (𝕜) in /-- The subalgebra of functions that are bounded along a filter `l`. -/ def boundedFilterSubalgebra [SeminormedCommRing 𝕜] [SeminormedRing β] [Algebra 𝕜 β] [IsBoundedSMul 𝕜 β] (l : Filter α) : Subalgebra 𝕜 (α → β) := Submodule.toSubalgebra (boundedFilterSubmodule 𝕜 l) (const_boundedAtFilter l (1 : β)) (fun f g hf hg ↦ by simpa only [Pi.one_apply, mul_one, norm_mul] using hf.mul hg) end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Interval.lean
import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Filter.SmallSets import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.Bases.Finite /-! # Convergence of intervals ## Motivation If a function tends to infinity somewhere, then its derivative is not integrable around this place. One should be careful about this statement: "somewhere" could mean a point, but also convergence from the left or from the right, or it could also be infinity, and "around this place" will refer to these directed neighborhoods. Therefore, the above theorem has many variants. Instead of stating all these variants, one can look for the common abstraction and have a single version. One has to be careful: if one considers convergence along a sequence, then the function may tend to infinity but have a derivative which is small along the sequence (with big jumps in between), so in the end the derivative may be integrable on a neighborhood of the sequence. What really matters for such calculus issues in terms of derivatives is that whole intervals are included in the sets we consider. The right common abstraction is provided in this file, as the `TendstoIxxClass` typeclass. It takes as parameters a class of bounded intervals and two real filters `l₁` and `l₂`. An instance `TendstoIxxClass Icc l₁ l₂` registers that, if `aₙ` and `bₙ` are converging towards the filter `l₁`, then the intervals `Icc aₙ bₙ` are eventually contained in any given set belonging to `l₂`. For instance, for `l₁ = 𝓝[>] x` and `l₂ = 𝓝[≥] x`, the strict and large right neighborhoods of `x` respectively, then given any large right neighborhood `s ∈ 𝓝[≥] x` and any two sequences `xₙ` and `yₙ` converging strictly to the right of `x`, then the interval `[xₙ, yₙ]` is eventually contained in `s`. Therefore, the instance `TendstoIxxClass Icc (𝓝[>] x) (𝓝[≥] x)` holds. Note that one could have taken as well `l₂ = 𝓝[>] x`, but that `l₁ = 𝓝[≥] x` and `l₂ = 𝓝[>] x` wouldn't work. With this formalism, the above theorem would read: if `TendstoIxxClass Icc l l` and `f` tends to infinity along `l`, then its derivative is not integrable on any element of `l`. Beyond this simple example, this typeclass plays a prominent role in generic formulations of the fundamental theorem of calculus. ## Main definition If both `a` and `b` tend to some filter `l₁`, sometimes this implies that `Ixx a b` tends to `l₂.smallSets`, i.e., for any `s ∈ l₂` eventually `Ixx a b` becomes a subset of `s`. Here and below `Ixx` is one of `Set.Icc`, `Set.Ico`, `Set.Ioc`, and `Set.Ioo`. We define `Filter.TendstoIxxClass Ixx l₁ l₂` to be a typeclass representing this property. The instances provide the best `l₂` for a given `l₁`. In many cases `l₁ = l₂` but sometimes we can drop an endpoint from an interval: e.g., we prove `Filter.TendstoIxxClass Set.Ico (𝓟 (Set.Iic a)) (𝓟 (Set.Iio a))`, i.e., if `u₁ n` and `u₂ n` belong eventually to `Set.Iic a`, then the interval `Set.Ico (u₁ n) (u₂ n)` is eventually included in `Set.Iio a`. The next table shows “output” filters `l₂` for different values of `Ixx` and `l₁`. The instances that need topology are defined in `Mathlib/Topology/Algebra/Ordered`. | Input filter | `Ixx = Set.Icc` | `Ixx = Set.Ico` | `Ixx = Set.Ioc` | `Ixx = Set.Ioo` | |-----------------:|:----------------:|:----------------:|:----------------:|:----------------:| | `Filter.atTop` | `Filter.atTop` | `Filter.atTop` | `Filter.atTop` | `Filter.atTop` | | `Filter.atBot` | `Filter.atBot` | `Filter.atBot` | `Filter.atBot` | `Filter.atBot` | | `pure a` | `pure a` | `⊥` | `⊥` | `⊥` | | `𝓟 (Set.Iic a)` | `𝓟 (Set.Iic a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iic a)` | `𝓟 (Set.Iio a)` | | `𝓟 (Set.Ici a)` | `𝓟 (Set.Ici a)` | `𝓟 (Set.Ici a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | | `𝓝 a` | `𝓝 a` | `𝓝 a` | `𝓝 a` | `𝓝 a` | | `𝓝[Set.Iic a] b` | `𝓝[Set.Iic a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iic a] b` | `𝓝[Set.Iio a] b` | | `𝓝[Set.Ici a] b` | `𝓝[Set.Ici a] b` | `𝓝[Set.Ici a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | -/ variable {α β : Type*} open Filter Set Function namespace Filter section Preorder /-- A pair of filters `l₁`, `l₂` has `TendstoIxxClass Ixx` property if `Ixx a b` tends to `l₂.small_sets` as `a` and `b` tend to `l₁`. In all instances `Ixx` is one of `Set.Icc`, `Set.Ico`, `Set.Ioc`, or `Set.Ioo`. The instances provide the best `l₂` for a given `l₁`. In many cases `l₁ = l₂` but sometimes we can drop an endpoint from an interval: e.g., we prove `TendstoIxxClass Set.Ico (𝓟 (Set.Iic a)) (𝓟 (Set.Iio a))`, i.e., if `u₁ n` and `u₂ n` belong eventually to `Set.Iic a`, then the interval `Set.Ico (u₁ n) (u₂ n)` is eventually included in `Set.Iio a`. We mark `l₂` as an `outParam` so that Lean can automatically find an appropriate `l₂` based on `Ixx` and `l₁`. This way, e.g., `tendsto.Ico h₁ h₂` works without specifying explicitly `l₂`. -/ class TendstoIxxClass (Ixx : α → α → Set α) (l₁ : Filter α) (l₂ : outParam <| Filter α) : Prop where /-- `Function.uncurry Ixx` tends to `l₂.smallSets` along `l₁ ×ˢ l₁`. In other words, for any `s ∈ l₂` there exists `t ∈ l₁` such that `Ixx x y ⊆ s` whenever `x ∈ t` and `y ∈ t`. Use lemmas like `Filter.Tendsto.Icc` instead. -/ tendsto_Ixx : Tendsto (fun p : α × α => Ixx p.1 p.2) (l₁ ×ˢ l₁) l₂.smallSets theorem tendstoIxxClass_principal {s t : Set α} {Ixx : α → α → Set α} : TendstoIxxClass Ixx (𝓟 s) (𝓟 t) ↔ ∀ᵉ (x ∈ s) (y ∈ s), Ixx x y ⊆ t := Iff.trans ⟨fun h => h.1, fun h => ⟨h⟩⟩ <| by simp only [smallSets_principal, prod_principal_principal, tendsto_principal_principal, forall_prod_set, mem_powerset_iff] theorem tendstoIxxClass_inf {l₁ l₁' l₂ l₂' : Filter α} {Ixx} [h : TendstoIxxClass Ixx l₁ l₂] [h' : TendstoIxxClass Ixx l₁' l₂'] : TendstoIxxClass Ixx (l₁ ⊓ l₁') (l₂ ⊓ l₂') := ⟨by simpa only [prod_inf_prod, smallSets_inf] using h.1.inf h'.1⟩ theorem tendstoIxxClass_of_subset {l₁ l₂ : Filter α} {Ixx Ixx' : α → α → Set α} (h : ∀ a b, Ixx a b ⊆ Ixx' a b) [h' : TendstoIxxClass Ixx' l₁ l₂] : TendstoIxxClass Ixx l₁ l₂ := ⟨h'.1.smallSets_mono <| Eventually.of_forall <| Prod.forall.2 h⟩ theorem HasBasis.tendstoIxxClass {ι : Type*} {p : ι → Prop} {s} {l : Filter α} (hl : l.HasBasis p s) {Ixx : α → α → Set α} (H : ∀ i, p i → ∀ x ∈ s i, ∀ y ∈ s i, Ixx x y ⊆ s i) : TendstoIxxClass Ixx l l := ⟨(hl.prod_self.tendsto_iff hl.smallSets).2 fun i hi => ⟨i, hi, fun _ h => H i hi _ h.1 _ h.2⟩⟩ variable [Preorder α] protected theorem Tendsto.Icc {l₁ l₂ : Filter α} [TendstoIxxClass Icc l₁ l₂] {lb : Filter β} {u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) : Tendsto (fun x => Icc (u₁ x) (u₂ x)) lb l₂.smallSets := (@TendstoIxxClass.tendsto_Ixx α Set.Icc _ _ _).comp <| h₁.prodMk h₂ protected theorem Tendsto.Ioc {l₁ l₂ : Filter α} [TendstoIxxClass Ioc l₁ l₂] {lb : Filter β} {u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) : Tendsto (fun x => Ioc (u₁ x) (u₂ x)) lb l₂.smallSets := (@TendstoIxxClass.tendsto_Ixx α Set.Ioc _ _ _).comp <| h₁.prodMk h₂ protected theorem Tendsto.Ico {l₁ l₂ : Filter α} [TendstoIxxClass Ico l₁ l₂] {lb : Filter β} {u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) : Tendsto (fun x => Ico (u₁ x) (u₂ x)) lb l₂.smallSets := (@TendstoIxxClass.tendsto_Ixx α Set.Ico _ _ _).comp <| h₁.prodMk h₂ protected theorem Tendsto.Ioo {l₁ l₂ : Filter α} [TendstoIxxClass Ioo l₁ l₂] {lb : Filter β} {u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) : Tendsto (fun x => Ioo (u₁ x) (u₂ x)) lb l₂.smallSets := (@TendstoIxxClass.tendsto_Ixx α Set.Ioo _ _ _).comp <| h₁.prodMk h₂ instance tendsto_Icc_atTop_atTop : TendstoIxxClass Icc (atTop : Filter α) atTop := (hasBasis_iInf_principal_finite _).tendstoIxxClass fun _ _ => Set.OrdConnected.out <| ordConnected_biInter fun _ _ => ordConnected_Ici instance tendsto_Ico_atTop_atTop : TendstoIxxClass Ico (atTop : Filter α) atTop := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendsto_Ioc_atTop_atTop : TendstoIxxClass Ioc (atTop : Filter α) atTop := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendsto_Ioo_atTop_atTop : TendstoIxxClass Ioo (atTop : Filter α) atTop := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self instance tendsto_Icc_atBot_atBot : TendstoIxxClass Icc (atBot : Filter α) atBot := (hasBasis_iInf_principal_finite _).tendstoIxxClass fun _ _ => Set.OrdConnected.out <| ordConnected_biInter fun _ _ => ordConnected_Iic instance tendsto_Ico_atBot_atBot : TendstoIxxClass Ico (atBot : Filter α) atBot := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendsto_Ioc_atBot_atBot : TendstoIxxClass Ioc (atBot : Filter α) atBot := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendsto_Ioo_atBot_atBot : TendstoIxxClass Ioo (atBot : Filter α) atBot := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self instance OrdConnected.tendsto_Icc {s : Set α} [hs : OrdConnected s] : TendstoIxxClass Icc (𝓟 s) (𝓟 s) := tendstoIxxClass_principal.2 hs.out instance tendsto_Ico_Ici_Ici {a : α} : TendstoIxxClass Ico (𝓟 (Ici a)) (𝓟 (Ici a)) := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendsto_Ico_Ioi_Ioi {a : α} : TendstoIxxClass Ico (𝓟 (Ioi a)) (𝓟 (Ioi a)) := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendsto_Ico_Iic_Iio {a : α} : TendstoIxxClass Ico (𝓟 (Iic a)) (𝓟 (Iio a)) := tendstoIxxClass_principal.2 fun _ _ _ h₁ _ h₂ => lt_of_lt_of_le h₂.2 h₁ instance tendsto_Ico_Iio_Iio {a : α} : TendstoIxxClass Ico (𝓟 (Iio a)) (𝓟 (Iio a)) := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendsto_Ioc_Ici_Ioi {a : α} : TendstoIxxClass Ioc (𝓟 (Ici a)) (𝓟 (Ioi a)) := tendstoIxxClass_principal.2 fun _ h₁ _ _ _ h₂ => lt_of_le_of_lt h₁ h₂.1 instance tendsto_Ioc_Iic_Iic {a : α} : TendstoIxxClass Ioc (𝓟 (Iic a)) (𝓟 (Iic a)) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendsto_Ioc_Iio_Iio {a : α} : TendstoIxxClass Ioc (𝓟 (Iio a)) (𝓟 (Iio a)) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendsto_Ioc_Ioi_Ioi {a : α} : TendstoIxxClass Ioc (𝓟 (Ioi a)) (𝓟 (Ioi a)) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendsto_Ioo_Ici_Ioi {a : α} : TendstoIxxClass Ioo (𝓟 (Ici a)) (𝓟 (Ioi a)) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ioc_self instance tendsto_Ioo_Iic_Iio {a : α} : TendstoIxxClass Ioo (𝓟 (Iic a)) (𝓟 (Iio a)) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ico_self instance tendsto_Ioo_Ioi_Ioi {a : α} : TendstoIxxClass Ioo (𝓟 (Ioi a)) (𝓟 (Ioi a)) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ioc_self instance tendsto_Ioo_Iio_Iio {a : α} : TendstoIxxClass Ioo (𝓟 (Iio a)) (𝓟 (Iio a)) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ioc_self instance tendsto_Icc_Icc_Icc {a b : α} : TendstoIxxClass Icc (𝓟 (Icc a b)) (𝓟 (Icc a b)) := tendstoIxxClass_principal.mpr fun _x hx _y hy => Icc_subset_Icc hx.1 hy.2 instance tendsto_Ioc_Icc_Icc {a b : α} : TendstoIxxClass Ioc (𝓟 (Icc a b)) (𝓟 (Icc a b)) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self end Preorder section PartialOrder variable [PartialOrder α] instance tendsto_Icc_pure_pure {a : α} : TendstoIxxClass Icc (pure a) (pure a : Filter α) := by rw [← principal_singleton] exact tendstoIxxClass_principal.2 ordConnected_singleton.out instance tendsto_Ico_pure_bot {a : α} : TendstoIxxClass Ico (pure a) ⊥ := ⟨by simp⟩ instance tendsto_Ioc_pure_bot {a : α} : TendstoIxxClass Ioc (pure a) ⊥ := ⟨by simp⟩ instance tendsto_Ioo_pure_bot {a : α} : TendstoIxxClass Ioo (pure a) ⊥ := ⟨by simp⟩ end PartialOrder section LinearOrder open Interval variable [LinearOrder α] instance tendsto_Icc_uIcc_uIcc {a b : α} : TendstoIxxClass Icc (𝓟 [[a, b]]) (𝓟 [[a, b]]) := Filter.tendsto_Icc_Icc_Icc instance tendsto_Ioc_uIcc_uIcc {a b : α} : TendstoIxxClass Ioc (𝓟 [[a, b]]) (𝓟 [[a, b]]) := Filter.tendsto_Ioc_Icc_Icc instance tendsto_uIcc_of_Icc {l : Filter α} [TendstoIxxClass Icc l l] : TendstoIxxClass uIcc l l := by refine ⟨fun s hs => mem_map.2 <| mem_prod_self_iff.2 ?_⟩ obtain ⟨t, htl, hts⟩ : ∃ t ∈ l, ∀ p ∈ (t : Set α) ×ˢ t, Icc (p : α × α).1 p.2 ∈ s := mem_prod_self_iff.1 (mem_map.1 (tendsto_fst.Icc tendsto_snd hs)) refine ⟨t, htl, fun p hp => ?_⟩ rcases le_total p.1 p.2 with h | h · rw [mem_preimage, uIcc_of_le h] exact hts p hp · rw [mem_preimage, uIcc_of_ge h] exact hts ⟨p.2, p.1⟩ ⟨hp.2, hp.1⟩ protected theorem Tendsto.uIcc {l : Filter α} [TendstoIxxClass Icc l l] {f g : β → α} {lb : Filter β} (hf : Tendsto f lb l) (hg : Tendsto g lb l) : Tendsto (fun x => [[f x, g x]]) lb l.smallSets := (@TendstoIxxClass.tendsto_Ixx α Set.uIcc _ _ _).comp <| hf.prodMk hg end LinearOrder end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/NAry.lean
import Mathlib.Order.Filter.Bases.Basic import Mathlib.Order.Filter.Prod /-! # N-ary maps of filter This file defines the binary and ternary maps of filters. This is mostly useful to define pointwise operations on filters. ## Main declarations * `Filter.map₂`: Binary map of filters. ## Notes This file is very similar to `Data.Set.NAry`, `Data.Finset.NAry` and `Data.Option.NAry`. Please keep them in sync. -/ open Function Set open Filter namespace Filter variable {α α' β β' γ γ' δ δ' ε ε' : Type*} {m : α → β → γ} {f f₁ f₂ : Filter α} {g g₁ g₂ : Filter β} {h : Filter γ} {s : Set α} {t : Set β} {u : Set γ} {a : α} {b : β} /-- The image of a binary function `m : α → β → γ` as a function `Filter α → Filter β → Filter γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def map₂ (m : α → β → γ) (f : Filter α) (g : Filter β) : Filter γ := ((f ×ˢ g).map (uncurry m)).copy { s | ∃ u ∈ f, ∃ v ∈ g, image2 m u v ⊆ s } fun _ ↦ by simp only [mem_map, mem_prod_iff, image2_subset_iff, prod_subset_iff]; rfl @[simp 900] theorem mem_map₂_iff : u ∈ map₂ m f g ↔ ∃ s ∈ f, ∃ t ∈ g, image2 m s t ⊆ u := Iff.rfl theorem image2_mem_map₂ (hs : s ∈ f) (ht : t ∈ g) : image2 m s t ∈ map₂ m f g := ⟨_, hs, _, ht, Subset.rfl⟩ theorem map_prod_eq_map₂ (m : α → β → γ) (f : Filter α) (g : Filter β) : Filter.map (fun p : α × β => m p.1 p.2) (f ×ˢ g) = map₂ m f g := by rw [map₂, copy_eq, uncurry_def] theorem map_prod_eq_map₂' (m : α × β → γ) (f : Filter α) (g : Filter β) : Filter.map m (f ×ˢ g) = map₂ (fun a b => m (a, b)) f g := map_prod_eq_map₂ m.curry f g @[simp] theorem map₂_mk_eq_prod (f : Filter α) (g : Filter β) : map₂ Prod.mk f g = f ×ˢ g := by simp only [← map_prod_eq_map₂, map_id'] protected lemma HasBasis.map₂ {ι ι' : Type*} {p : ι → Prop} {q : ι' → Prop} {s t} (m : α → β → γ) (hf : f.HasBasis p s) (hg : g.HasBasis q t) : (map₂ m f g).HasBasis (fun i : ι × ι' ↦ p i.1 ∧ q i.2) fun i ↦ image2 m (s i.1) (t i.2) := by simpa only [← map_prod_eq_map₂, ← image_prod] using (hf.prod hg).map _ -- lemma image2_mem_map₂_iff (hm : injective2 m) : image2 m s t ∈ map₂ m f g ↔ s ∈ f ∧ t ∈ g := -- ⟨by { rintro ⟨u, v, hu, hv, h⟩, rw image2_subset_image2_iff hm at h, -- exact ⟨mem_of_superset hu h.1, mem_of_superset hv h.2⟩ }, fun h ↦ image2_mem_map₂ h.1 h.2⟩ @[gcongr] theorem map₂_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : map₂ m f₁ g₁ ≤ map₂ m f₂ g₂ := fun _ ⟨s, hs, t, ht, hst⟩ => ⟨s, hf hs, t, hg ht, hst⟩ theorem map₂_mono_left (h : g₁ ≤ g₂) : map₂ m f g₁ ≤ map₂ m f g₂ := map₂_mono Subset.rfl h theorem map₂_mono_right (h : f₁ ≤ f₂) : map₂ m f₁ g ≤ map₂ m f₂ g := map₂_mono h Subset.rfl @[simp] theorem le_map₂_iff {h : Filter γ} : h ≤ map₂ m f g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → image2 m s t ∈ h := ⟨fun H _ hs _ ht => H <| image2_mem_map₂ hs ht, fun H _ ⟨_, hs, _, ht, hu⟩ => mem_of_superset (H hs ht) hu⟩ @[simp] theorem map₂_eq_bot_iff : map₂ m f g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by simp [← map_prod_eq_map₂] @[simp] theorem map₂_bot_left : map₂ m ⊥ g = ⊥ := map₂_eq_bot_iff.2 <| .inl rfl @[simp] theorem map₂_bot_right : map₂ m f ⊥ = ⊥ := map₂_eq_bot_iff.2 <| .inr rfl @[simp] theorem map₂_neBot_iff : (map₂ m f g).NeBot ↔ f.NeBot ∧ g.NeBot := by simp [neBot_iff, not_or] protected theorem NeBot.map₂ (hf : f.NeBot) (hg : g.NeBot) : (map₂ m f g).NeBot := map₂_neBot_iff.2 ⟨hf, hg⟩ instance map₂.neBot [NeBot f] [NeBot g] : NeBot (map₂ m f g) := .map₂ ‹_› ‹_› theorem NeBot.of_map₂_left (h : (map₂ m f g).NeBot) : f.NeBot := (map₂_neBot_iff.1 h).1 theorem NeBot.of_map₂_right (h : (map₂ m f g).NeBot) : g.NeBot := (map₂_neBot_iff.1 h).2 theorem map₂_sup_left : map₂ m (f₁ ⊔ f₂) g = map₂ m f₁ g ⊔ map₂ m f₂ g := by simp_rw [← map_prod_eq_map₂, sup_prod, map_sup] theorem map₂_sup_right : map₂ m f (g₁ ⊔ g₂) = map₂ m f g₁ ⊔ map₂ m f g₂ := by simp_rw [← map_prod_eq_map₂, prod_sup, map_sup] theorem map₂_inf_subset_left : map₂ m (f₁ ⊓ f₂) g ≤ map₂ m f₁ g ⊓ map₂ m f₂ g := Monotone.map_inf_le (fun _ _ ↦ map₂_mono_right) f₁ f₂ theorem map₂_inf_subset_right : map₂ m f (g₁ ⊓ g₂) ≤ map₂ m f g₁ ⊓ map₂ m f g₂ := Monotone.map_inf_le (fun _ _ ↦ map₂_mono_left) g₁ g₂ @[simp] theorem map₂_pure_left : map₂ m (pure a) g = g.map (m a) := by rw [← map_prod_eq_map₂, pure_prod, map_map]; rfl @[simp] theorem map₂_pure_right : map₂ m f (pure b) = f.map (m · b) := by rw [← map_prod_eq_map₂, prod_pure, map_map]; rfl theorem map₂_pure : map₂ m (pure a) (pure b) = pure (m a b) := by rw [map₂_pure_right, map_pure] theorem map₂_swap (m : α → β → γ) (f : Filter α) (g : Filter β) : map₂ m f g = map₂ (fun a b => m b a) g f := by rw [← map_prod_eq_map₂, prod_comm, map_map, ← map_prod_eq_map₂, Function.comp_def] simp @[simp] theorem map₂_left [NeBot g] : map₂ (fun x _ => x) f g = f := by rw [← map_prod_eq_map₂, map_fst_prod] @[simp] theorem map₂_right [NeBot f] : map₂ (fun _ y => y) f g = g := by rw [map₂_swap, map₂_left] theorem map_map₂ (m : α → β → γ) (n : γ → δ) : (map₂ m f g).map n = map₂ (fun a b => n (m a b)) f g := by rw [← map_prod_eq_map₂, ← map_prod_eq_map₂, map_map]; rfl theorem map₂_map_left (m : γ → β → δ) (n : α → γ) : map₂ m (f.map n) g = map₂ (fun a b => m (n a) b) f g := by rw [← map_prod_eq_map₂, ← map_prod_eq_map₂, ← @map_id _ g, prod_map_map_eq, map_map, map_id]; rfl theorem map₂_map_right (m : α → γ → δ) (n : β → γ) : map₂ m f (g.map n) = map₂ (fun a b => m a (n b)) f g := by rw [map₂_swap, map₂_map_left, map₂_swap] @[simp] theorem map₂_curry (m : α × β → γ) (f : Filter α) (g : Filter β) : map₂ m.curry f g = (f ×ˢ g).map m := (map_prod_eq_map₂' _ _ _).symm @[simp] theorem map_uncurry_prod (m : α → β → γ) (f : Filter α) (g : Filter β) : (f ×ˢ g).map (uncurry m) = map₂ m f g := (map₂_curry (uncurry m) f g).symm /-! ### Algebraic replacement rules A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations to the associativity, commutativity, distributivity, ... of `Filter.map₂` of those operations. The proof pattern is `map₂_lemma operation_lemma`. For example, `map₂_comm mul_comm` proves that `map₂ (*) f g = map₂ (*) g f` in a `CommSemigroup`. -/ theorem map₂_assoc {m : δ → γ → ε} {n : α → β → δ} {m' : α → ε' → ε} {n' : β → γ → ε'} {h : Filter γ} (h_assoc : ∀ a b c, m (n a b) c = m' a (n' b c)) : map₂ m (map₂ n f g) h = map₂ m' f (map₂ n' g h) := by rw [← map_prod_eq_map₂ n, ← map_prod_eq_map₂ n', map₂_map_left, map₂_map_right, ← map_prod_eq_map₂, ← map_prod_eq_map₂, ← prod_assoc, map_map] simp only [h_assoc, Function.comp_def, Equiv.prodAssoc_apply] theorem map₂_comm {n : β → α → γ} (h_comm : ∀ a b, m a b = n b a) : map₂ m f g = map₂ n g f := (map₂_swap _ _ _).trans <| by simp_rw [h_comm] theorem map₂_left_comm {m : α → δ → ε} {n : β → γ → δ} {m' : α → γ → δ'} {n' : β → δ' → ε} (h_left_comm : ∀ a b c, m a (n b c) = n' b (m' a c)) : map₂ m f (map₂ n g h) = map₂ n' g (map₂ m' f h) := by rw [map₂_swap m', map₂_swap m] exact map₂_assoc fun _ _ _ => h_left_comm _ _ _ theorem map₂_right_comm {m : δ → γ → ε} {n : α → β → δ} {m' : α → γ → δ'} {n' : δ' → β → ε} (h_right_comm : ∀ a b c, m (n a b) c = n' (m' a c) b) : map₂ m (map₂ n f g) h = map₂ n' (map₂ m' f h) g := by rw [map₂_swap n, map₂_swap n'] exact map₂_assoc fun _ _ _ => h_right_comm _ _ _ theorem map_map₂_distrib {n : γ → δ} {m' : α' → β' → δ} {n₁ : α → α'} {n₂ : β → β'} (h_distrib : ∀ a b, n (m a b) = m' (n₁ a) (n₂ b)) : (map₂ m f g).map n = map₂ m' (f.map n₁) (g.map n₂) := by simp_rw [map_map₂, map₂_map_left, map₂_map_right, h_distrib] /-- Symmetric statement to `Filter.map₂_map_left_comm`. -/ theorem map_map₂_distrib_left {n : γ → δ} {m' : α' → β → δ} {n' : α → α'} (h_distrib : ∀ a b, n (m a b) = m' (n' a) b) : (map₂ m f g).map n = map₂ m' (f.map n') g := map_map₂_distrib h_distrib /-- Symmetric statement to `Filter.map_map₂_right_comm`. -/ theorem map_map₂_distrib_right {n : γ → δ} {m' : α → β' → δ} {n' : β → β'} (h_distrib : ∀ a b, n (m a b) = m' a (n' b)) : (map₂ m f g).map n = map₂ m' f (g.map n') := map_map₂_distrib h_distrib /-- Symmetric statement to `Filter.map_map₂_distrib_left`. -/ theorem map₂_map_left_comm {m : α' → β → γ} {n : α → α'} {m' : α → β → δ} {n' : δ → γ} (h_left_comm : ∀ a b, m (n a) b = n' (m' a b)) : map₂ m (f.map n) g = (map₂ m' f g).map n' := (map_map₂_distrib_left fun a b => (h_left_comm a b).symm).symm /-- Symmetric statement to `Filter.map_map₂_distrib_right`. -/ theorem map_map₂_right_comm {m : α → β' → γ} {n : β → β'} {m' : α → β → δ} {n' : δ → γ} (h_right_comm : ∀ a b, m a (n b) = n' (m' a b)) : map₂ m f (g.map n) = (map₂ m' f g).map n' := (map_map₂_distrib_right fun a b => (h_right_comm a b).symm).symm /-- The other direction does not hold because of the `f-f` cross terms on the RHS. -/ theorem map₂_distrib_le_left {m : α → δ → ε} {n : β → γ → δ} {m₁ : α → β → β'} {m₂ : α → γ → γ'} {n' : β' → γ' → ε} (h_distrib : ∀ a b c, m a (n b c) = n' (m₁ a b) (m₂ a c)) : map₂ m f (map₂ n g h) ≤ map₂ n' (map₂ m₁ f g) (map₂ m₂ f h) := by rintro s ⟨t₁, ⟨u₁, hu₁, v, hv, ht₁⟩, t₂, ⟨u₂, hu₂, w, hw, ht₂⟩, hs⟩ refine ⟨u₁ ∩ u₂, inter_mem hu₁ hu₂, _, image2_mem_map₂ hv hw, ?_⟩ refine (image2_distrib_subset_left h_distrib).trans ((image2_subset ?_ ?_).trans hs) · exact (image2_subset_right inter_subset_left).trans ht₁ · exact (image2_subset_right inter_subset_right).trans ht₂ /-- The other direction does not hold because of the `h`-`h` cross terms on the RHS. -/ theorem map₂_distrib_le_right {m : δ → γ → ε} {n : α → β → δ} {m₁ : α → γ → α'} {m₂ : β → γ → β'} {n' : α' → β' → ε} (h_distrib : ∀ a b c, m (n a b) c = n' (m₁ a c) (m₂ b c)) : map₂ m (map₂ n f g) h ≤ map₂ n' (map₂ m₁ f h) (map₂ m₂ g h) := by rintro s ⟨t₁, ⟨u, hu, w₁, hw₁, ht₁⟩, t₂, ⟨v, hv, w₂, hw₂, ht₂⟩, hs⟩ refine ⟨_, image2_mem_map₂ hu hv, w₁ ∩ w₂, inter_mem hw₁ hw₂, ?_⟩ refine (image2_distrib_subset_right h_distrib).trans ((image2_subset ?_ ?_).trans hs) · exact (image2_subset_left inter_subset_left).trans ht₁ · exact (image2_subset_left inter_subset_right).trans ht₂ theorem map_map₂_antidistrib {n : γ → δ} {m' : β' → α' → δ} {n₁ : β → β'} {n₂ : α → α'} (h_antidistrib : ∀ a b, n (m a b) = m' (n₁ b) (n₂ a)) : (map₂ m f g).map n = map₂ m' (g.map n₁) (f.map n₂) := by rw [map₂_swap m] exact map_map₂_distrib fun _ _ => h_antidistrib _ _ /-- Symmetric statement to `Filter.map₂_map_left_anticomm`. -/ theorem map_map₂_antidistrib_left {n : γ → δ} {m' : β' → α → δ} {n' : β → β'} (h_antidistrib : ∀ a b, n (m a b) = m' (n' b) a) : (map₂ m f g).map n = map₂ m' (g.map n') f := map_map₂_antidistrib h_antidistrib /-- Symmetric statement to `Filter.map_map₂_right_anticomm`. -/ theorem map_map₂_antidistrib_right {n : γ → δ} {m' : β → α' → δ} {n' : α → α'} (h_antidistrib : ∀ a b, n (m a b) = m' b (n' a)) : (map₂ m f g).map n = map₂ m' g (f.map n') := map_map₂_antidistrib h_antidistrib /-- Symmetric statement to `Filter.map_map₂_antidistrib_left`. -/ theorem map₂_map_left_anticomm {m : α' → β → γ} {n : α → α'} {m' : β → α → δ} {n' : δ → γ} (h_left_anticomm : ∀ a b, m (n a) b = n' (m' b a)) : map₂ m (f.map n) g = (map₂ m' g f).map n' := (map_map₂_antidistrib_left fun a b => (h_left_anticomm b a).symm).symm /-- Symmetric statement to `Filter.map_map₂_antidistrib_right`. -/ theorem map_map₂_right_anticomm {m : α → β' → γ} {n : β → β'} {m' : β → α → δ} {n' : δ → γ} (h_right_anticomm : ∀ a b, m a (n b) = n' (m' b a)) : map₂ m f (g.map n) = (map₂ m' g f).map n' := (map_map₂_antidistrib_right fun a b => (h_right_anticomm b a).symm).symm /-- If `a` is a left identity for `f : α → β → β`, then `pure a` is a left identity for `Filter.map₂ f`. -/ theorem map₂_left_identity {f : α → β → β} {a : α} (h : ∀ b, f a b = b) (l : Filter β) : map₂ f (pure a) l = l := by rw [map₂_pure_left, show f a = id from funext h, map_id] /-- If `b` is a right identity for `f : α → β → α`, then `pure b` is a right identity for `Filter.map₂ f`. -/ theorem map₂_right_identity {f : α → β → α} {b : β} (h : ∀ a, f a b = a) (l : Filter α) : map₂ f l (pure b) = l := by rw [map₂_pure_right, funext h, map_id'] end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/EventuallyConst.lean
import Mathlib.Algebra.Notation.Indicator import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.Subsingleton /-! # Functions that are eventually constant along a filter In this file we define a predicate `Filter.EventuallyConst f l` saying that a function `f : α → β` is eventually equal to a constant along a filter `l`. We also prove some basic properties of these functions. ## Implementation notes A naive definition of `Filter.EventuallyConst f l` is `∃ y, ∀ᶠ x in l, f x = y`. However, this proposition is false for empty `α`, `β`. Instead, we say that `Filter.map f l` is supported on a subsingleton. This allows us to drop `[Nonempty _]` assumptions here and there. -/ open Set variable {α β γ δ : Type*} {l : Filter α} {f : α → β} namespace Filter /-- The proposition that a function is eventually constant along a filter on the domain. -/ def EventuallyConst (f : α → β) (l : Filter α) : Prop := (map f l).Subsingleton theorem HasBasis.eventuallyConst_iff {ι : Sort*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) : EventuallyConst f l ↔ ∃ i, p i ∧ ∀ x ∈ s i, ∀ y ∈ s i, f x = f y := (h.map f).subsingleton_iff.trans <| by simp only [Set.Subsingleton, forall_mem_image] theorem HasBasis.eventuallyConst_iff' {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {x : ι → α} (h : l.HasBasis p s) (hx : ∀ i, p i → x i ∈ s i) : EventuallyConst f l ↔ ∃ i, p i ∧ ∀ y ∈ s i, f y = f (x i) := h.eventuallyConst_iff.trans <| exists_congr fun i ↦ and_congr_right fun hi ↦ ⟨fun h ↦ (h · · (x i) (hx i hi)), fun h a ha b hb ↦ h a ha ▸ (h b hb).symm⟩ lemma eventuallyConst_iff_tendsto [Nonempty β] : EventuallyConst f l ↔ ∃ x, Tendsto f l (pure x) := subsingleton_iff_exists_le_pure alias ⟨EventuallyConst.exists_tendsto, _⟩ := eventuallyConst_iff_tendsto theorem EventuallyConst.of_tendsto {x : β} (h : Tendsto f l (pure x)) : EventuallyConst f l := have : Nonempty β := ⟨x⟩; eventuallyConst_iff_tendsto.2 ⟨x, h⟩ theorem eventuallyConst_iff_exists_eventuallyEq [Nonempty β] : EventuallyConst f l ↔ ∃ c, f =ᶠ[l] fun _ ↦ c := subsingleton_iff_exists_singleton_mem alias ⟨EventuallyConst.eventuallyEq_const, _⟩ := eventuallyConst_iff_exists_eventuallyEq theorem eventuallyConst_pred' {p : α → Prop} : EventuallyConst p l ↔ (p =ᶠ[l] fun _ ↦ False) ∨ (p =ᶠ[l] fun _ ↦ True) := by simp only [eventuallyConst_iff_exists_eventuallyEq, Prop.exists_iff] theorem eventuallyConst_pred {p : α → Prop} : EventuallyConst p l ↔ (∀ᶠ x in l, p x) ∨ (∀ᶠ x in l, ¬p x) := by simp [eventuallyConst_pred', or_comm, EventuallyEq] theorem eventuallyConst_set' {s : Set α} : EventuallyConst s l ↔ (s =ᶠ[l] (∅ : Set α)) ∨ s =ᶠ[l] univ := eventuallyConst_pred' theorem eventuallyConst_set {s : Set α} : EventuallyConst s l ↔ (∀ᶠ x in l, x ∈ s) ∨ (∀ᶠ x in l, x ∉ s) := eventuallyConst_pred theorem eventuallyConst_preimage {s : Set β} {f : α → β} : EventuallyConst (f ⁻¹' s) l ↔ EventuallyConst s (map f l) := .rfl theorem EventuallyEq.eventuallyConst_iff {g : α → β} (h : f =ᶠ[l] g) : EventuallyConst f l ↔ EventuallyConst g l := by simp only [EventuallyConst, map_congr h] @[simp] theorem eventuallyConst_id : EventuallyConst id l ↔ l.Subsingleton := Iff.rfl namespace EventuallyConst @[simp] protected lemma bot : EventuallyConst f ⊥ := subsingleton_bot @[simp] protected lemma const (c : β) : EventuallyConst (fun _ ↦ c) l := .of_tendsto tendsto_const_pure protected lemma congr {g} (h : EventuallyConst f l) (hg : f =ᶠ[l] g) : EventuallyConst g l := hg.eventuallyConst_iff.1 h @[nontriviality] lemma of_subsingleton_right [Subsingleton β] : EventuallyConst f l := .of_subsingleton nonrec lemma anti {l'} (h : EventuallyConst f l) (hl' : l' ≤ l) : EventuallyConst f l' := h.anti (map_mono hl') @[nontriviality] lemma of_subsingleton_left [Subsingleton α] : EventuallyConst f l := .map .of_subsingleton f lemma comp (h : EventuallyConst f l) (g : β → γ) : EventuallyConst (g ∘ f) l := h.map g @[to_additive] protected lemma inv [Inv β] (h : EventuallyConst f l) : EventuallyConst (f⁻¹) l := h.comp Inv.inv lemma comp_tendsto {lb : Filter β} {g : β → γ} (hg : EventuallyConst g lb) (hf : Tendsto f l lb) : EventuallyConst (g ∘ f) l := hg.anti hf lemma apply {ι : Type*} {p : ι → Type*} {g : α → ∀ x, p x} (h : EventuallyConst g l) (i : ι) : EventuallyConst (g · i) l := h.comp <| Function.eval i lemma comp₂ {g : α → γ} (hf : EventuallyConst f l) (op : β → γ → δ) (hg : EventuallyConst g l) : EventuallyConst (fun x ↦ op (f x) (g x)) l := ((hf.prod hg).map op.uncurry).anti <| (tendsto_map (f := op.uncurry)).comp (tendsto_map.prodMk tendsto_map) lemma prodMk {g : α → γ} (hf : EventuallyConst f l) (hg : EventuallyConst g l) : EventuallyConst (fun x ↦ (f x, g x)) l := hf.comp₂ Prod.mk hg @[to_additive] lemma mul [Mul β] {g : α → β} (hf : EventuallyConst f l) (hg : EventuallyConst g l) : EventuallyConst (f * g) l := hf.comp₂ (· * ·) hg variable [One β] {s : Set α} {c : β} @[to_additive] lemma of_mulIndicator_const (h : EventuallyConst (s.mulIndicator fun _ ↦ c) l) (hc : c ≠ 1) : EventuallyConst s l := by simpa [Function.comp_def, hc, imp_false] using h.comp (· = c) @[to_additive] theorem mulIndicator_const (h : EventuallyConst s l) (c : β) : EventuallyConst (s.mulIndicator fun _ ↦ c) l := by classical exact h.comp (if · then c else 1) @[to_additive] theorem mulIndicator_const_iff_of_ne (hc : c ≠ 1) : EventuallyConst (s.mulIndicator fun _ ↦ c) l ↔ EventuallyConst s l := ⟨(of_mulIndicator_const · hc), (mulIndicator_const · c)⟩ @[to_additive (attr := simp)] theorem mulIndicator_const_iff : EventuallyConst (s.mulIndicator fun _ ↦ c) l ↔ c = 1 ∨ EventuallyConst s l := by rcases eq_or_ne c 1 with rfl | hc <;> simp [mulIndicator_const_iff_of_ne, *] end EventuallyConst lemma eventuallyConst_atTop [SemilatticeSup α] [Nonempty α] : EventuallyConst f atTop ↔ (∃ i, ∀ j, i ≤ j → f j = f i) := (atTop_basis.eventuallyConst_iff' fun _ _ ↦ left_mem_Ici).trans <| by simp only [true_and, mem_Ici] lemma eventuallyConst_atTop_nat {f : ℕ → α} : EventuallyConst f atTop ↔ ∃ n, ∀ m, n ≤ m → f (m + 1) = f m := by rw [eventuallyConst_atTop] refine exists_congr fun n ↦ ⟨fun h m hm ↦ ?_, fun h m hm ↦ ?_⟩ · exact (h (m + 1) (hm.trans m.le_succ)).trans (h m hm).symm · induction m, hm using Nat.le_induction with | base => rfl | succ m hm ihm => exact (h m hm).trans ihm end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Prod.lean
import Mathlib.Order.Filter.Tendsto /-! # Product and coproduct filters In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and `Filter.Tendsto Prod.snd l g`. ## Implementation details The product filter cannot be defined using the monad structure on filters. For example: ```lean F := do {x ← seq, y ← top, return (x, y)} G := do {y ← top, x ← seq, return (x, y)} ``` hence: ```lean s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s ``` Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`. As product filter we want to have `F` as result. ## Notation * `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`. -/ open Set open Filter namespace Filter variable {α β γ δ : Type*} {ι : Sort*} section Prod variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β} theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g := inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht) theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by constructor · rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩ exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩ · rintro ⟨t₁, ht₁, t₂, ht₂, h⟩ exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h @[simp] theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint] @[simp] theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g := ⟨fun h => let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h (prod_subset_prod_iff.1 H).elim (fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h => h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e => absurd ht'e (nonempty_of_mem ht').ne_empty, fun h => prod_mem_prod h.1 h.2⟩ theorem mem_prod_principal {s : Set (α × β)} : s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by rw [← @exists_mem_subset_iff _ f, mem_prod_iff] refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩ · rintro ⟨v, v_in, hv⟩ a a_in b b_in exact hv (mk_mem_prod a_in <| v_in b_in) · rintro ⟨x, y⟩ ⟨hx, hy⟩ exact h hx y hy theorem mem_prod_top {s : Set (α × β)} : s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by rw [← principal_univ, mem_prod_principal] simp only [mem_univ, forall_true_left] theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} : (∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by rw [eventually_iff, eventually_iff, mem_prod_principal] simp only [mem_setOf_eq] theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) : comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by rw [prod_eq_inf, comap_inf, Filter.comap_comap, Filter.comap_comap] theorem comap_prodMap_prod (f : α → β) (g : γ → δ) (lb : Filter β) (ld : Filter δ) : comap (Prod.map f g) (lb ×ˢ ld) = comap f lb ×ˢ comap g ld := by simp [prod_eq_inf, comap_comap, Function.comp_def] theorem prod_top : f ×ˢ (⊤ : Filter β) = f.comap Prod.fst := by rw [prod_eq_inf, comap_top, inf_top_eq] theorem top_prod : (⊤ : Filter α) ×ˢ g = g.comap Prod.snd := by rw [prod_eq_inf, comap_top, top_inf_eq] theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by simp only [prod_eq_inf, comap_sup, inf_sup_right] theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by simp only [prod_eq_inf, comap_sup, inf_sup_left] theorem eventually_prod_iff {p : α × β → Prop} : (∀ᶠ x in f ×ˢ g, p x) ↔ ∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧ ∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f := tendsto_inf_left tendsto_comap theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g := tendsto_inf_right tendsto_comap /-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to `g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↦ (m a).1) f g := tendsto_fst.comp H /-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to `h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↦ (m a).2) f h := tendsto_snd.comp H theorem Tendsto.prodMk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ} (h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) := tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) := tendsto_snd.prodMk tendsto_fst theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).1 := tendsto_fst.eventually h theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).2 := tendsto_snd.eventually h theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β} {pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 := (ha.prod_inl lb).and (hb.prod_inr la) theorem EventuallyEq.prodMap {δ} {la : Filter α} {fa ga : α → γ} (ha : fa =ᶠ[la] ga) {lb : Filter β} {fb gb : β → δ} (hb : fb =ᶠ[lb] gb) : Prod.map fa fb =ᶠ[la ×ˢ lb] Prod.map ga gb := (Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2 theorem EventuallyLE.prodMap {δ} [LE γ] [LE δ] {la : Filter α} {fa ga : α → γ} (ha : fa ≤ᶠ[la] ga) {lb : Filter β} {fb gb : β → δ} (hb : fb ≤ᶠ[lb] gb) : Prod.map fa fb ≤ᶠ[la ×ˢ lb] Prod.map ga gb := Eventually.prod_mk ha hb theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by rcases eventually_prod_iff.1 h with ⟨pa, ha, pb, hb, h⟩ exact ha.mono fun a ha => hb.mono fun b hb => h ha hb protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 := mt (fun h ↦ by simpa only [not_frequently] using h.curry) h lemma Frequently.of_curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p (x, y)) : ∃ᶠ xy in la ×ˢ lb, p xy := h.uncurry theorem Eventually.image_of_prod {y : α → β} {r : α → β → Prop} (hy : Tendsto y f g) (hr : ∀ᶠ p in f ×ˢ g, r p.1 p.2) : ∀ᶠ x in f, r x (y x) := by obtain ⟨p, hp, q, hq, hr⟩ := eventually_prod_iff.mp hr filter_upwards [hp, hy.eventually hq] with _ hp hq using hr hp hq /-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about all diagonal pairs `(i, i)` -/ theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) : ∀ᶠ i in f, p (i, i) := h.image_of_prod (r := p.curry) tendsto_id theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} : (∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by intro h obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2] theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} : (∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by intro h obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2] theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) := tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} : (⨅ i, f i) ×ˢ g = ⨅ i, f i ×ˢ g := by simp only [prod_eq_inf, comap_iInf, iInf_inf] theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} : (f ×ˢ ⨅ i, g i) = ⨅ i, f ×ˢ g i := by simp only [prod_eq_inf, comap_iInf, inf_iInf] @[mono, gcongr] theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ := inf_le_inf (comap_mono hf) (comap_mono hg) theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≤ f₂) : f₁ ×ˢ g ≤ f₂ ×ˢ g := Filter.prod_mono hf rfl.le theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≤ g₂) : f ×ˢ g₁ ≤ f ×ˢ g₂ := Filter.prod_mono rfl.le hf theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} : comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by simp only [prod_eq_inf, comap_comap, comap_inf, Function.comp_def] theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by simp only [prod_eq_inf, comap_comap, Function.comp_def, inf_comm, Prod.swap, comap_inf] theorem prod_comm : f ×ˢ g = map Prod.swap (g ×ˢ f) := by rw [prod_comm', ← map_swap_eq_comap_swap] theorem mem_prod_iff_left {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by simp only [mem_prod_iff, prod_subset_iff] refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff exact exists_congr fun _ => Iff.rfl.and forall₂_swap theorem mem_prod_iff_right {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by rw [prod_comm, mem_map, mem_prod_iff_left]; rfl @[simp] theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by ext s simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def, exists_mem_subset_iff] @[simp] theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by rw [prod_comm, map_map]; apply map_fst_prod @[simp] theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ ↔ f₁ ≤ f₂ ∧ g₁ ≤ g₂ := ⟨fun h => ⟨map_fst_prod f₁ g₁ ▸ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▸ tendsto_snd.mono_left h⟩, fun h => prod_mono h.1 h.2⟩ @[simp] theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by refine ⟨fun h => ?_, fun h => h.1 ▸ h.2 ▸ rfl⟩ have hle : f₁ ≤ f₂ ∧ g₁ ≤ g₂ := prod_le_prod.1 h.le haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2 exact ⟨hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩ theorem eventually_swap_iff {p : α × β → Prop} : (∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by rw [prod_comm]; rfl /-- A technical lemma which is a generalization of `Filter.Eventually.trans_prod`. -/ lemma Eventually.eventually_prod_of_eventually_swap {h : Filter γ} [NeBot g] {p : α → β → Prop} {q : β → γ → Prop} {r : α → γ → Prop} (hp : ∀ᶠ x in f, ∀ᶠ y in g, p x y) (hq : ∀ᶠ z in h, ∀ᶠ y in g, q y z) (hpqr : ∀ x y z, p x y → q y z → r x z) : ∀ᶠ xz in f ×ˢ h, r xz.1 xz.2 := by refine eventually_prod_iff.mpr ⟨_, hp, _, hq, fun {x} hx {z} hz ↦ ?_⟩ rcases (hx.and hz).exists with ⟨y, hpy, hqy⟩ exact hpqr x y z hpy hqy lemma Eventually.trans_prod {h : Filter γ} [NeBot g] {p : α → β → Prop} {q : β → γ → Prop} {r : α → γ → Prop} (hp : ∀ᶠ xy in f ×ˢ g, p xy.1 xy.2) (hq : ∀ᶠ yz in g ×ˢ h, q yz.1 yz.2) (hpqr : ∀ x y z, p x y → q y z → r x z) : ∀ᶠ xz in f ×ˢ h, r xz.1 xz.2 := hp.curry.eventually_prod_of_eventually_swap (eventually_swap_iff.mp hq |>.curry) hpqr theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by simp_rw [← comap_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_symm_apply] theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by simp_rw [map_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_apply] theorem tendsto_prodAssoc {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) := (prod_assoc f g h).le theorem tendsto_prodAssoc_symm {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) := (prod_assoc_symm f g h).le /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_prod {h : Filter γ} {k : Filter δ} : map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) = (f ×ˢ h) ×ˢ (g ×ˢ k) := by simp_rw [map_swap4_eq_comap, prod_eq_inf, comap_inf, comap_comap]; ac_rfl theorem tendsto_swap4_prod {h : Filter γ} {k : Filter δ} : Tendsto (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) ((f ×ˢ h) ×ˢ (g ×ˢ k)) := map_swap4_prod.le theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map m₁ f₁ ×ˢ map m₂ f₂ = map (fun p : α₁ × α₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := le_antisymm (fun s hs => let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs mem_of_superset (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) <| by rwa [prod_image_image_eq, image_subset_iff]) ((tendsto_map.comp tendsto_fst).prodMk (tendsto_map.comp tendsto_snd)) theorem prod_map_map_eq' {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} (f : α₁ → α₂) (g : β₁ → β₂) (F : Filter α₁) (G : Filter β₁) : map f F ×ˢ map g G = map (Prod.map f g) (F ×ˢ G) := prod_map_map_eq theorem prod_map_left (f : α → β) (F : Filter α) (G : Filter γ) : map f F ×ˢ G = map (Prod.map f id) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem prod_map_right (f : β → γ) (F : Filter α) (G : Filter β) : F ×ˢ map f G = map (Prod.map id f) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem le_prod_map_fst_snd {f : Filter (α × β)} : f ≤ map Prod.fst f ×ˢ map Prod.snd f := le_inf le_comap_map le_comap_map theorem Tendsto.prodMap {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a ×ˢ b) (c ×ˢ d) := by rw [Tendsto, Prod.map_def, ← prod_map_map_eq] exact Filter.prod_mono hf hg protected theorem map_prod (m : α × β → γ) (f : Filter α) (g : Filter β) : map m (f ×ˢ g) = (f.map fun a b => m (a, b)).seq g := by simp only [Filter.ext_iff, mem_map, mem_prod_iff, mem_map_seq_iff, exists_and_left] intro s constructor · exact fun ⟨t, ht, s, hs, h⟩ => ⟨s, hs, t, ht, fun x hx y hy => @h ⟨x, y⟩ ⟨hx, hy⟩⟩ · exact fun ⟨s, hs, t, ht, h⟩ => ⟨t, ht, s, hs, fun ⟨x, y⟩ ⟨hx, hy⟩ => h x hx y hy⟩ theorem prod_eq : f ×ˢ g = (f.map Prod.mk).seq g := f.map_prod id g theorem prod_inf_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} : (f₁ ×ˢ g₁) ⊓ (f₂ ×ˢ g₂) = (f₁ ⊓ f₂) ×ˢ (g₁ ⊓ g₂) := by simp only [prod_eq_inf, comap_inf, inf_comm, inf_assoc, inf_left_comm] theorem inf_prod {f₁ f₂ : Filter α} : (f₁ ⊓ f₂) ×ˢ g = (f₁ ×ˢ g) ⊓ (f₂ ×ˢ g) := by rw [prod_inf_prod, inf_idem] theorem prod_inf {g₁ g₂ : Filter β} : f ×ˢ (g₁ ⊓ g₂) = (f ×ˢ g₁) ⊓ (f ×ˢ g₂) := by rw [prod_inf_prod, inf_idem] @[simp] theorem prod_principal_principal {s : Set α} {t : Set β} : 𝓟 s ×ˢ 𝓟 t = 𝓟 (s ×ˢ t) := by simp only [prod_eq_inf, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; rfl @[simp] theorem pure_prod {a : α} {f : Filter β} : pure a ×ˢ f = map (Prod.mk a) f := by rw [prod_eq, map_pure, pure_seq_eq_map] theorem map_pure_prod (f : α → β → γ) (a : α) (B : Filter β) : map (Function.uncurry f) (pure a ×ˢ B) = map (f a) B := by rw [Filter.pure_prod]; rfl @[simp] theorem prod_pure {b : β} : f ×ˢ pure b = map (fun a => (a, b)) f := by rw [prod_eq, seq_pure, map_map]; rfl theorem prod_pure_pure {a : α} {b : β} : (pure a : Filter α) ×ˢ (pure b : Filter β) = pure (a, b) := by simp @[simp] theorem prod_eq_bot : f ×ˢ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by simp_rw [← empty_mem_iff_bot, mem_prod_iff, subset_empty_iff, prod_eq_empty_iff, ← exists_prop, Subtype.exists', exists_or, exists_const, Subtype.exists, exists_prop, exists_eq_right] @[simp] theorem prod_bot : f ×ˢ (⊥ : Filter β) = ⊥ := prod_eq_bot.2 <| Or.inr rfl @[simp] theorem bot_prod : (⊥ : Filter α) ×ˢ g = ⊥ := prod_eq_bot.2 <| Or.inl rfl theorem prod_neBot : NeBot (f ×ˢ g) ↔ NeBot f ∧ NeBot g := by simp only [neBot_iff, Ne, prod_eq_bot, not_or] protected theorem NeBot.prod (hf : NeBot f) (hg : NeBot g) : NeBot (f ×ˢ g) := prod_neBot.2 ⟨hf, hg⟩ instance prod.instNeBot [hf : NeBot f] [hg : NeBot g] : NeBot (f ×ˢ g) := hf.prod hg @[simp] lemma disjoint_prod {f' : Filter α} {g' : Filter β} : Disjoint (f ×ˢ g) (f' ×ˢ g') ↔ Disjoint f f' ∨ Disjoint g g' := by simp only [disjoint_iff, prod_inf_prod, prod_eq_bot] /-- `p ∧ q` occurs frequently along the product of two filters iff both `p` and `q` occur frequently along the corresponding filters. -/ theorem frequently_prod_and {p : α → Prop} {q : β → Prop} : (∃ᶠ x in f ×ˢ g, p x.1 ∧ q x.2) ↔ (∃ᶠ a in f, p a) ∧ ∃ᶠ b in g, q b := by simp only [frequently_iff_neBot, ← prod_neBot, ← prod_inf_prod, prod_principal_principal] rfl theorem tendsto_prod_iff {f : α × β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} : Tendsto f (x ×ˢ y) z ↔ ∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff] theorem tendsto_prod_iff' {g' : Filter γ} {s : α → β × γ} : Tendsto s f (g ×ˢ g') ↔ Tendsto (fun n => (s n).1) f g ∧ Tendsto (fun n => (s n).2) f g' := by simp only [prod_eq_inf, tendsto_inf, tendsto_comap_iff, Function.comp_def] theorem le_prod {f : Filter (α × β)} {g : Filter α} {g' : Filter β} : (f ≤ g ×ˢ g') ↔ Tendsto Prod.fst f g ∧ Tendsto Prod.snd f g' := tendsto_prod_iff' end Prod /-! ### Coproducts of filters -/ section Coprod variable {f : Filter α} {g : Filter β} theorem coprod_eq_prod_top_sup_top_prod (f : Filter α) (g : Filter β) : Filter.coprod f g = f ×ˢ ⊤ ⊔ ⊤ ×ˢ g := by rw [prod_top, top_prod] rfl theorem mem_coprod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f.coprod g ↔ (∃ t₁ ∈ f, Prod.fst ⁻¹' t₁ ⊆ s) ∧ ∃ t₂ ∈ g, Prod.snd ⁻¹' t₂ ⊆ s := by simp [Filter.coprod] @[simp] theorem bot_coprod (l : Filter β) : (⊥ : Filter α).coprod l = comap Prod.snd l := by simp [Filter.coprod] @[simp] theorem coprod_bot (l : Filter α) : l.coprod (⊥ : Filter β) = comap Prod.fst l := by simp [Filter.coprod] theorem bot_coprod_bot : (⊥ : Filter α).coprod (⊥ : Filter β) = ⊥ := by simp theorem compl_mem_coprod {s : Set (α × β)} {la : Filter α} {lb : Filter β} : sᶜ ∈ la.coprod lb ↔ (Prod.fst '' s)ᶜ ∈ la ∧ (Prod.snd '' s)ᶜ ∈ lb := by simp only [Filter.coprod, mem_sup, compl_mem_comap] @[mono] theorem coprod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.coprod g₁ ≤ f₂.coprod g₂ := sup_le_sup (comap_mono hf) (comap_mono hg) theorem coprod_neBot_iff : (f.coprod g).NeBot ↔ f.NeBot ∧ Nonempty β ∨ Nonempty α ∧ g.NeBot := by simp [Filter.coprod] @[instance] theorem coprod_neBot_left [NeBot f] [Nonempty β] : (f.coprod g).NeBot := coprod_neBot_iff.2 (Or.inl ⟨‹_›, ‹_›⟩) @[instance] theorem coprod_neBot_right [NeBot g] [Nonempty α] : (f.coprod g).NeBot := coprod_neBot_iff.2 (Or.inr ⟨‹_›, ‹_›⟩) theorem coprod_inf_prod_le (f₁ f₂ : Filter α) (g₁ g₂ : Filter β) : f₁.coprod g₁ ⊓ f₂ ×ˢ g₂ ≤ f₁ ×ˢ g₂ ⊔ f₂ ×ˢ g₁ := calc f₁.coprod g₁ ⊓ f₂ ×ˢ g₂ _ = (f₁ ×ˢ ⊤ ⊔ ⊤ ×ˢ g₁) ⊓ f₂ ×ˢ g₂ := by rw [coprod_eq_prod_top_sup_top_prod] _ = f₁ ×ˢ ⊤ ⊓ f₂ ×ˢ g₂ ⊔ ⊤ ×ˢ g₁ ⊓ f₂ ×ˢ g₂ := inf_sup_right _ _ _ _ = (f₁ ⊓ f₂) ×ˢ g₂ ⊔ f₂ ×ˢ (g₁ ⊓ g₂) := by simp [prod_inf_prod] _ ≤ f₁ ×ˢ g₂ ⊔ f₂ ×ˢ g₁ := sup_le_sup (prod_mono inf_le_left le_rfl) (prod_mono le_rfl inf_le_left) theorem principal_coprod_principal (s : Set α) (t : Set β) : (𝓟 s).coprod (𝓟 t) = 𝓟 (sᶜ ×ˢ tᶜ)ᶜ := by rw [Filter.coprod, comap_principal, comap_principal, sup_principal, Set.prod_eq, compl_inter, preimage_compl, preimage_compl, compl_compl, compl_compl] -- this inequality can be strict; see `map_const_principal_coprod_map_id_principal` and -- `map_prodMap_const_id_principal_coprod_principal` below. theorem map_prodMap_coprod_le.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map (Prod.map m₁ m₂) (f₁.coprod f₂) ≤ (map m₁ f₁).coprod (map m₂ f₂) := by intro s simp only [mem_map, mem_coprod_iff] rintro ⟨⟨u₁, hu₁, h₁⟩, u₂, hu₂, h₂⟩ refine ⟨⟨m₁ ⁻¹' u₁, hu₁, fun _ hx => h₁ ?_⟩, ⟨m₂ ⁻¹' u₂, hu₂, fun _ hx => h₂ ?_⟩⟩ <;> convert hx /-- Characterization of the coproduct of the `Filter.map`s of two principal filters `𝓟 {a}` and `𝓟 {i}`, the first under the constant function `fun a => b` and the second under the identity function. Together with the next lemma, `map_prodMap_const_id_principal_coprod_principal`, this provides an example showing that the inequality in the lemma `map_prodMap_coprod_le` can be strict. -/ theorem map_const_principal_coprod_map_id_principal {α β ι : Type*} (a : α) (b : β) (i : ι) : (map (fun _ => b) (𝓟 {a})).coprod (map id (𝓟 {i})) = 𝓟 ((({b} : Set β) ×ˢ univ) ∪ (univ ×ˢ ({i} : Set ι))) := by simp only [map_principal, Filter.coprod, comap_principal, sup_principal, image_singleton, prod_univ, univ_prod, id] /-- Characterization of the `Filter.map` of the coproduct of two principal filters `𝓟 {a}` and `𝓟 {i}`, under the `Prod.map` of two functions, respectively the constant function `fun a => b` and the identity function. Together with the previous lemma, `map_const_principal_coprod_map_id_principal`, this provides an example showing that the inequality in the lemma `map_prodMap_coprod_le` can be strict. -/ theorem map_prodMap_const_id_principal_coprod_principal {α β ι : Type*} (a : α) (b : β) (i : ι) : map (Prod.map (fun _ : α => b) id) ((𝓟 {a}).coprod (𝓟 {i})) = 𝓟 (({b} : Set β) ×ˢ (univ : Set ι)) := by rw [principal_coprod_principal, map_principal] congr ext ⟨b', i'⟩ constructor · rintro ⟨⟨a'', i''⟩, _, h₂, h₃⟩ simp · rintro ⟨h₁, _⟩ use (a, i') simpa using h₁.symm theorem Tendsto.prodMap_coprod {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a.coprod b) (c.coprod d) := map_prodMap_coprod_le.trans (coprod_mono hf hg) lemma Tendsto.coprod_of_prod_top_right {f : α × β → γ} {la : Filter α} {lb : Filter β} {lc : Filter γ} (h₁ : ∀ s : Set α, s ∈ la → Tendsto f (𝓟 sᶜ ×ˢ lb) lc) (h₂ : Tendsto f (la ×ˢ ⊤) lc) : Tendsto f (la.coprod lb) lc := by simp_all [tendsto_prod_iff, coprod_eq_prod_top_sup_top_prod] grind lemma Tendsto.coprod_of_prod_top_left {f : α × β → γ} {la : Filter α} {lb : Filter β} {lc : Filter γ} (h₁ : ∀ s : Set β, s ∈ lb → Tendsto f (la ×ˢ 𝓟 sᶜ) lc) (h₂ : Tendsto f (⊤ ×ˢ lb) lc) : Tendsto f (la.coprod lb) lc := by simp_all [tendsto_prod_iff, coprod_eq_prod_top_sup_top_prod] grind end Coprod end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Partial.lean
import Mathlib.Order.Filter.Tendsto import Mathlib.Data.PFun /-! # `Tendsto` for relations and partial functions This file generalizes `Filter` definitions from functions to partial functions and relations. ## Considering functions and partial functions as relations A function `f : α → β` can be considered as the relation `Rel α β` which relates `x` and `f x` for all `x`, and nothing else. This relation is called `Function.Graph f`. A partial function `f : α →. β` can be considered as the relation `Rel α β` which relates `x` and `f x` for all `x` for which `f x` exists, and nothing else. This relation is called `PFun.Graph' f`. In this regard, a function is a relation for which every element in `α` is related to exactly one element in `β` and a partial function is a relation for which every element in `α` is related to at most one element in `β`. This file leverages this analogy to generalize `Filter` definitions from functions to partial functions and relations. ## Notes `Set.preimage` can be generalized to relations in two ways: * `Rel.preimage` returns the image of the set under the inverse relation. * `Rel.core` returns the set of elements that are only related to those in the set. Both generalizations are sensible in the context of filters, so `Filter.comap` and `Filter.Tendsto` get two generalizations each. We first take care of relations. Then the definitions for partial functions are taken as special cases of the definitions for relations. -/ universe u v w namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} open Filter /-! ### Relations -/ /-- The forward map of a filter under a relation. Generalization of `Filter.map` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/ def rmap (r : SetRel α β) (l : Filter α) : Filter β where sets := { s | r.core s ∈ l } univ_sets := by simp sets_of_superset hs st := mem_of_superset hs (SetRel.core_mono st) inter_sets hs ht := by simp only [Set.mem_setOf_eq] convert inter_mem hs ht rw [← SetRel.core_inter] theorem rmap_sets (r : SetRel α β) (l : Filter α) : (l.rmap r).sets = r.core ⁻¹' l.sets := rfl @[simp] theorem mem_rmap (r : SetRel α β) (l : Filter α) (s : Set β) : s ∈ l.rmap r ↔ r.core s ∈ l := Iff.rfl @[simp] theorem rmap_rmap (r : SetRel α β) (s : SetRel β γ) (l : Filter α) : rmap s (rmap r l) = rmap (r.comp s) l := filter_eq <| by simp [rmap_sets, Set.preimage, SetRel.core_comp] @[simp] theorem rmap_compose (r : SetRel α β) (s : SetRel β γ) : rmap s ∘ rmap r = rmap (r.comp s) := funext <| rmap_rmap _ _ /-- Generic "limit of a relation" predicate. `RTendsto r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `r`-core of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to relations. -/ def RTendsto (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) := l₁.rmap r ≤ l₂ theorem rtendsto_def (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) : RTendsto r l₁ l₂ ↔ ∀ s ∈ l₂, r.core s ∈ l₁ := Iff.rfl /-- One way of taking the inverse map of a filter under a relation. One generalization of `Filter.comap` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/ def rcomap (r : SetRel α β) (f : Filter β) : Filter α where sets := SetRel.image {(s, t) : _ × _ | r.core s ⊆ t} f.sets univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ => ⟨a' ∩ b', inter_mem ha₁ hb₁, (r.core_inter a' b').subset.trans (Set.inter_subset_inter ha₂ hb₂)⟩ theorem rcomap_sets (r : SetRel α β) (f : Filter β) : (rcomap r f).sets = SetRel.image {(s, t) : _ × _ | r.core s ⊆ t} f.sets := rfl theorem rcomap_rcomap (r : SetRel α β) (s : SetRel β γ) (l : Filter γ) : rcomap r (rcomap s l) = rcomap (r.comp s) l := filter_eq <| by ext t simp only [rcomap_sets, SetRel.image, Filter.mem_sets, Set.mem_setOf_eq, SetRel.core_comp] constructor · rintro ⟨u, ⟨v, vsets, hv⟩, h⟩ exact ⟨v, vsets, Set.Subset.trans (SetRel.core_mono hv) h⟩ rintro ⟨t, tsets, ht⟩ exact ⟨SetRel.core s t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩ @[simp] theorem rcomap_compose (r : SetRel α β) (s : SetRel β γ) : rcomap r ∘ rcomap s = rcomap (r.comp s) := funext <| rcomap_rcomap _ _ theorem rtendsto_iff_le_rcomap (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) : RTendsto r l₁ l₂ ↔ l₁ ≤ l₂.rcomap r := by rw [rtendsto_def] simp_rw [← l₂.mem_sets] constructor · simpa [Filter.le_def, rcomap, SetRel.mem_image] using fun h s t tl₂ => mem_of_superset (h t tl₂) · simpa [Filter.le_def, rcomap, SetRel.mem_image] using fun h t tl₂ => h _ t tl₂ Set.Subset.rfl -- Interestingly, there does not seem to be a way to express this relation using a forward map. -- Given a filter `f` on `α`, we want a filter `f'` on `β` such that `r.preimage s ∈ f` if -- and only if `s ∈ f'`. But the intersection of two sets satisfying the lhs may be empty. /-- One way of taking the inverse map of a filter under a relation. Generalization of `Filter.comap` to relations. -/ def rcomap' (r : SetRel α β) (f : Filter β) : Filter α where sets := SetRel.image {(s, t) : _ × _ | r.preimage s ⊆ t} f.sets univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ => ⟨a' ∩ b', inter_mem ha₁ hb₁, r.preimage_inter_subset.trans (Set.inter_subset_inter ha₂ hb₂)⟩ @[simp] theorem mem_rcomap' (r : SetRel α β) (l : Filter β) (s : Set α) : s ∈ l.rcomap' r ↔ ∃ t ∈ l, r.preimage t ⊆ s := Iff.rfl theorem rcomap'_sets (r : SetRel α β) (f : Filter β) : (rcomap' r f).sets = SetRel.image {(s, t) | r.preimage s ⊆ t} f.sets := rfl @[simp] theorem rcomap'_rcomap' (r : SetRel α β) (s : SetRel β γ) (l : Filter γ) : rcomap' r (rcomap' s l) = rcomap' (r.comp s) l := Filter.ext fun t => by simp only [mem_rcomap', SetRel.preimage_comp] constructor · rintro ⟨u, ⟨v, vsets, hv⟩, h⟩ exact ⟨v, vsets, (SetRel.preimage_mono hv).trans h⟩ rintro ⟨t, tsets, ht⟩ exact ⟨s.preimage t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩ @[simp] theorem rcomap'_compose (r : SetRel α β) (s : SetRel β γ) : rcomap' r ∘ rcomap' s = rcomap' (r.comp s) := funext <| rcomap'_rcomap' _ _ /-- Generic "limit of a relation" predicate. `RTendsto' r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `r`-preimage of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to relations. -/ def RTendsto' (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) := l₁ ≤ l₂.rcomap' r theorem rtendsto'_def (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) : RTendsto' r l₁ l₂ ↔ ∀ s ∈ l₂, r.preimage s ∈ l₁ := by unfold RTendsto' rcomap'; constructor · simpa [le_def, SetRel.mem_image] using fun h s hs => h _ _ hs Set.Subset.rfl · simpa [le_def, SetRel.mem_image] using fun h s t ht => mem_of_superset (h t ht) theorem tendsto_iff_rtendsto (l₁ : Filter α) (l₂ : Filter β) (f : α → β) : Tendsto f l₁ l₂ ↔ RTendsto (Function.graph f) l₁ l₂ := by simp [tendsto_def, Function.graph, rtendsto_def, SetRel.core, Set.preimage] theorem tendsto_iff_rtendsto' (l₁ : Filter α) (l₂ : Filter β) (f : α → β) : Tendsto f l₁ l₂ ↔ RTendsto' (Function.graph f) l₁ l₂ := by simp [tendsto_def, Function.graph, rtendsto'_def, SetRel.preimage, Set.preimage] /-! ### Partial functions -/ /-- The forward map of a filter under a partial function. Generalization of `Filter.map` to partial functions. -/ def pmap (f : α →. β) (l : Filter α) : Filter β := Filter.rmap f.graph' l @[simp] theorem mem_pmap (f : α →. β) (l : Filter α) (s : Set β) : s ∈ l.pmap f ↔ f.core s ∈ l := Iff.rfl /-- Generic "limit of a partial function" predicate. `PTendsto r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `p`-core of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to partial function. -/ def PTendsto (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) := l₁.pmap f ≤ l₂ theorem ptendsto_def (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) : PTendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f.core s ∈ l₁ := Iff.rfl theorem ptendsto_iff_rtendsto (l₁ : Filter α) (l₂ : Filter β) (f : α →. β) : PTendsto f l₁ l₂ ↔ RTendsto f.graph' l₁ l₂ := Iff.rfl theorem pmap_res (l : Filter α) (s : Set α) (f : α → β) : pmap (PFun.res f s) l = map f (l ⊓ 𝓟 s) := by ext t simp only [PFun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or] rfl theorem tendsto_iff_ptendsto (l₁ : Filter α) (l₂ : Filter β) (s : Set α) (f : α → β) : Tendsto f (l₁ ⊓ 𝓟 s) l₂ ↔ PTendsto (PFun.res f s) l₁ l₂ := by simp only [Tendsto, PTendsto, pmap_res] theorem tendsto_iff_ptendsto_univ (l₁ : Filter α) (l₂ : Filter β) (f : α → β) : Tendsto f l₁ l₂ ↔ PTendsto (PFun.res f Set.univ) l₁ l₂ := by rw [← tendsto_iff_ptendsto] simp [principal_univ] /-- Inverse map of a filter under a partial function. One generalization of `Filter.comap` to partial functions. -/ def pcomap' (f : α →. β) (l : Filter β) : Filter α := Filter.rcomap' f.graph' l /-- Generic "limit of a partial function" predicate. `PTendsto' r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `p`-preimage of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to partial functions. -/ def PTendsto' (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) := l₁ ≤ l₂.rcomap' f.graph' theorem ptendsto'_def (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) : PTendsto' f l₁ l₂ ↔ ∀ s ∈ l₂, f.preimage s ∈ l₁ := rtendsto'_def _ _ _ theorem ptendsto_of_ptendsto' {f : α →. β} {l₁ : Filter α} {l₂ : Filter β} : PTendsto' f l₁ l₂ → PTendsto f l₁ l₂ := by rw [ptendsto_def, ptendsto'_def] exact fun h s sl₂ => mem_of_superset (h s sl₂) (PFun.preimage_subset_core _ _) theorem ptendsto'_of_ptendsto {f : α →. β} {l₁ : Filter α} {l₂ : Filter β} (h : f.Dom ∈ l₁) : PTendsto f l₁ l₂ → PTendsto' f l₁ l₂ := by rw [ptendsto_def, ptendsto'_def] intro h' s sl₂ rw [PFun.preimage_eq] exact inter_mem (h' s sl₂) h end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Pointwise.lean
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Order.Group.OrderIso import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Ring.Defs import Mathlib.Order.Filter.AtTopBot.Map import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.NAry import Mathlib.Order.Filter.Ultrafilter.Defs /-! # Pointwise operations on filters This file defines pointwise operations on filters. This is useful because usual algebraic operations distribute over pointwise operations. For example, * `(f₁ * f₂).map m = f₁.map m * f₂.map m` * `𝓝 (x * y) = 𝓝 x * 𝓝 y` ## Main declarations * `0` (`Filter.instZero`): Pure filter at `0 : α`, or alternatively principal filter at `0 : Set α`. * `1` (`Filter.instOne`): Pure filter at `1 : α`, or alternatively principal filter at `1 : Set α`. * `f + g` (`Filter.instAdd`): Addition, filter generated by all `s + t` where `s ∈ f` and `t ∈ g`. * `f * g` (`Filter.instMul`): Multiplication, filter generated by all `s * t` where `s ∈ f` and `t ∈ g`. * `-f` (`Filter.instNeg`): Negation, filter of all `-s` where `s ∈ f`. * `f⁻¹` (`Filter.instInv`): Inversion, filter of all `s⁻¹` where `s ∈ f`. * `f - g` (`Filter.instSub`): Subtraction, filter generated by all `s - t` where `s ∈ f` and `t ∈ g`. * `f / g` (`Filter.instDiv`): Division, filter generated by all `s / t` where `s ∈ f` and `t ∈ g`. * `f +ᵥ g` (`Filter.instVAdd`): Scalar addition, filter generated by all `s +ᵥ t` where `s ∈ f` and `t ∈ g`. * `f -ᵥ g` (`Filter.instVSub`): Scalar subtraction, filter generated by all `s -ᵥ t` where `s ∈ f` and `t ∈ g`. * `f • g` (`Filter.instSMul`): Scalar multiplication, filter generated by all `s • t` where `s ∈ f` and `t ∈ g`. * `a +ᵥ f` (`Filter.instVAddFilter`): Translation, filter of all `a +ᵥ s` where `s ∈ f`. * `a • f` (`Filter.instSMulFilter`): Scaling, filter of all `a • s` where `s ∈ f`. For `α` a semigroup/monoid, `Filter α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • f`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition. See note [pointwise nat action]. ## Implementation notes We put all instances in the scope `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the scope to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`). ## Tags filter multiplication, filter addition, pointwise addition, pointwise multiplication, -/ open Function Set Filter Pointwise variable {F α β γ δ ε : Type*} namespace Filter /-! ### `0`/`1` as filters -/ section One variable [One α] {f : Filter α} {s : Set α} /-- `1 : Filter α` is defined as the filter of sets containing `1 : α` in scope `Pointwise`. -/ @[to_additive /-- `0 : Filter α` is defined as the filter of sets containing `0 : α` in scope `Pointwise`. -/] protected def instOne : One (Filter α) := ⟨pure 1⟩ scoped[Pointwise] attribute [instance] Filter.instOne Filter.instZero @[to_additive (attr := simp)] theorem mem_one : s ∈ (1 : Filter α) ↔ (1 : α) ∈ s := mem_pure @[to_additive] theorem one_mem_one : (1 : Set α) ∈ (1 : Filter α) := mem_pure.2 Set.one_mem_one @[to_additive (attr := simp)] theorem pure_one : pure 1 = (1 : Filter α) := rfl @[to_additive (attr := simp) zero_prod] theorem one_prod {l : Filter β} : (1 : Filter α) ×ˢ l = map (1, ·) l := pure_prod @[to_additive (attr := simp) prod_zero] theorem prod_one {l : Filter β} : l ×ˢ (1 : Filter α) = map (·, 1) l := prod_pure @[to_additive (attr := simp)] theorem principal_one : 𝓟 1 = (1 : Filter α) := principal_singleton _ @[to_additive] theorem one_neBot : (1 : Filter α).NeBot := Filter.pure_neBot scoped[Pointwise] attribute [instance] one_neBot zero_neBot @[to_additive (attr := simp)] protected theorem map_one' (f : α → β) : (1 : Filter α).map f = pure (f 1) := rfl @[to_additive (attr := simp)] theorem le_one_iff : f ≤ 1 ↔ (1 : Set α) ∈ f := le_pure_iff @[to_additive] protected theorem NeBot.le_one_iff (h : f.NeBot) : f ≤ 1 ↔ f = 1 := h.le_pure_iff @[to_additive (attr := simp)] theorem eventually_one {p : α → Prop} : (∀ᶠ x in 1, p x) ↔ p 1 := eventually_pure @[to_additive (attr := simp)] theorem tendsto_one {a : Filter β} {f : β → α} : Tendsto f a 1 ↔ ∀ᶠ x in a, f x = 1 := tendsto_pure @[to_additive zero_prod_zero] theorem one_prod_one [One β] : (1 : Filter α) ×ˢ (1 : Filter β) = 1 := prod_pure_pure /-- `pure` as a `OneHom`. -/ @[to_additive /-- `pure` as a `ZeroHom`. -/] def pureOneHom : OneHom α (Filter α) where toFun := pure; map_one' := pure_one @[to_additive (attr := simp)] theorem coe_pureOneHom : (pureOneHom : α → Filter α) = pure := rfl @[to_additive (attr := simp)] theorem pureOneHom_apply (a : α) : pureOneHom a = pure a := rfl variable [One β] @[to_additive] protected theorem map_one [FunLike F α β] [OneHomClass F α β] (φ : F) : map φ 1 = 1 := by simp end One /-! ### Filter negation/inversion -/ section Inv variable [Inv α] {f g : Filter α} {s : Set α} {a : α} /-- The inverse of a filter is the pointwise preimage under `⁻¹` of its sets. -/ @[to_additive /-- The negation of a filter is the pointwise preimage under `-` of its sets. -/] def instInv : Inv (Filter α) := ⟨map Inv.inv⟩ scoped[Pointwise] attribute [instance] instInv instNeg @[to_additive (attr := simp)] protected theorem map_inv : f.map Inv.inv = f⁻¹ := rfl @[to_additive] theorem mem_inv : s ∈ f⁻¹ ↔ Inv.inv ⁻¹' s ∈ f := Iff.rfl @[to_additive] protected theorem inv_le_inv (hf : f ≤ g) : f⁻¹ ≤ g⁻¹ := map_mono hf @[to_additive (attr := simp)] theorem inv_pure : (pure a : Filter α)⁻¹ = pure a⁻¹ := rfl @[to_additive (attr := simp)] theorem inv_eq_bot_iff : f⁻¹ = ⊥ ↔ f = ⊥ := map_eq_bot_iff @[to_additive (attr := simp)] theorem neBot_inv_iff : f⁻¹.NeBot ↔ NeBot f := map_neBot_iff _ @[to_additive] protected theorem NeBot.inv : f.NeBot → f⁻¹.NeBot := fun h => h.map _ @[to_additive neg.instNeBot] lemma inv.instNeBot [NeBot f] : NeBot f⁻¹ := .inv ‹_› scoped[Pointwise] attribute [instance] inv.instNeBot neg.instNeBot end Inv section InvolutiveInv variable [InvolutiveInv α] {f g : Filter α} {s : Set α} @[to_additive (attr := simp)] protected lemma comap_inv : comap Inv.inv f = f⁻¹ := .symm <| map_eq_comap_of_inverse (inv_comp_inv _) (inv_comp_inv _) @[to_additive] theorem inv_mem_inv (hs : s ∈ f) : s⁻¹ ∈ f⁻¹ := by rwa [mem_inv, inv_preimage, inv_inv] @[to_additive] protected theorem HasBasis.inv {ι : Sort*} {p : ι → Prop} {s : ι → Set α} (h : f.HasBasis p s) : f⁻¹.HasBasis p fun i ↦ (s i)⁻¹ := by simpa using h.map Inv.inv /-- Inversion is involutive on `Filter α` if it is on `α`. -/ @[to_additive /-- Negation is involutive on `Filter α` if it is on `α`. -/] protected def instInvolutiveInv : InvolutiveInv (Filter α) := { Filter.instInv with inv_inv := fun f => map_map.trans <| by rw [inv_involutive.comp_self, map_id] } scoped[Pointwise] attribute [instance] Filter.instInvolutiveInv Filter.instInvolutiveNeg @[to_additive (attr := simp)] protected theorem inv_le_inv_iff : f⁻¹ ≤ g⁻¹ ↔ f ≤ g := ⟨fun h => inv_inv f ▸ inv_inv g ▸ Filter.inv_le_inv h, Filter.inv_le_inv⟩ @[to_additive] theorem inv_le_iff_le_inv : f⁻¹ ≤ g ↔ f ≤ g⁻¹ := by rw [← Filter.inv_le_inv_iff, inv_inv] @[to_additive (attr := simp)] theorem inv_le_self : f⁻¹ ≤ f ↔ f⁻¹ = f := ⟨fun h => h.antisymm <| inv_le_iff_le_inv.1 h, Eq.le⟩ end InvolutiveInv @[to_additive (attr := simp)] lemma inv_atTop {G : Type*} [CommGroup G] [PartialOrder G] [IsOrderedMonoid G] : (atTop : Filter G)⁻¹ = atBot := (OrderIso.inv G).map_atTop /-! ### Filter addition/multiplication -/ section Mul variable [Mul α] [Mul β] {f f₁ f₂ g g₁ g₂ h : Filter α} {s t : Set α} {a b : α} /-- The filter `f * g` is generated by `{s * t | s ∈ f, t ∈ g}` in scope `Pointwise`. -/ @[to_additive /-- The filter `f + g` is generated by `{s + t | s ∈ f, t ∈ g}` in scope `Pointwise`. -/] protected def instMul : Mul (Filter α) := ⟨/- This is defeq to `map₂ (· * ·) f g`, but the hypothesis unfolds to `t₁ * t₂ ⊆ s` rather than all the way to `Set.image2 (· * ·) t₁ t₂ ⊆ s`. -/ fun f g => { map₂ (· * ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ * t₂ ⊆ s } }⟩ scoped[Pointwise] attribute [instance] Filter.instMul Filter.instAdd @[to_additive] theorem HasBasis.mul {ιf ιg : Type*} {pf : ιf → Prop} {sf : ιf → Set α} {pg : ιg → Prop} {sg : ιg → Set α} (hf : f.HasBasis pf sf) (hg : g.HasBasis pg sg) : (f * g).HasBasis (fun i : ιf × ιg ↦ pf i.1 ∧ pg i.2) fun i ↦ sf i.1 * sg i.2 := hf.map₂ (· * ·) hg @[to_additive (attr := simp)] theorem map₂_mul : map₂ (· * ·) f g = f * g := rfl @[to_additive] theorem mem_mul : s ∈ f * g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ * t₂ ⊆ s := Iff.rfl @[to_additive] theorem mul_mem_mul : s ∈ f → t ∈ g → s * t ∈ f * g := image2_mem_map₂ @[to_additive (attr := simp)] theorem bot_mul : ⊥ * g = ⊥ := map₂_bot_left @[to_additive (attr := simp)] theorem mul_bot : f * ⊥ = ⊥ := map₂_bot_right @[to_additive (attr := simp)] theorem mul_eq_bot_iff : f * g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := map₂_eq_bot_iff @[to_additive (attr := simp)] -- TODO: make this a scoped instance in the `Pointwise` namespace lemma mul_neBot_iff : (f * g).NeBot ↔ f.NeBot ∧ g.NeBot := map₂_neBot_iff @[to_additive] protected theorem NeBot.mul : NeBot f → NeBot g → NeBot (f * g) := NeBot.map₂ @[to_additive] theorem NeBot.of_mul_left : (f * g).NeBot → f.NeBot := NeBot.of_map₂_left @[to_additive] theorem NeBot.of_mul_right : (f * g).NeBot → g.NeBot := NeBot.of_map₂_right @[to_additive add.instNeBot] protected lemma mul.instNeBot [NeBot f] [NeBot g] : NeBot (f * g) := .mul ‹_› ‹_› scoped[Pointwise] attribute [instance] mul.instNeBot add.instNeBot @[to_additive (attr := simp)] theorem pure_mul : pure a * g = g.map (a * ·) := map₂_pure_left @[to_additive (attr := simp)] theorem mul_pure : f * pure b = f.map (· * b) := map₂_pure_right @[to_additive] theorem pure_mul_pure : (pure a : Filter α) * pure b = pure (a * b) := by simp @[to_additive (attr := simp)] theorem le_mul_iff : h ≤ f * g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s * t ∈ h := le_map₂_iff @[to_additive] instance mulLeftMono : MulLeftMono (Filter α) := ⟨fun _ _ _ => map₂_mono_left⟩ @[to_additive] instance mulRightMono : MulRightMono (Filter α) := ⟨fun _ _ _ => map₂_mono_right⟩ @[to_additive] protected theorem map_mul [FunLike F α β] [MulHomClass F α β] (m : F) : (f₁ * f₂).map m = f₁.map m * f₂.map m := map_map₂_distrib <| map_mul m /-- `pure` operation as a `MulHom`. -/ @[to_additive /-- The singleton operation as an `AddHom`. -/] def pureMulHom : α →ₙ* Filter α where toFun := pure; map_mul' _ _ := pure_mul_pure.symm @[to_additive (attr := simp)] theorem coe_pureMulHom : (pureMulHom : α → Filter α) = pure := rfl @[to_additive (attr := simp)] theorem pureMulHom_apply (a : α) : pureMulHom a = pure a := rfl end Mul /-! ### Filter subtraction/division -/ section Div variable [Div α] {f f₁ f₂ g g₁ g₂ h : Filter α} {s t : Set α} {a b : α} /-- The filter `f / g` is generated by `{s / t | s ∈ f, t ∈ g}` in scope `Pointwise`. -/ @[to_additive /-- The filter `f - g` is generated by `{s - t | s ∈ f, t ∈ g}` in scope `Pointwise`. -/] protected def instDiv : Div (Filter α) := ⟨/- This is defeq to `map₂ (· / ·) f g`, but the hypothesis unfolds to `t₁ / t₂ ⊆ s` rather than all the way to `Set.image2 (· / ·) t₁ t₂ ⊆ s`. -/ fun f g => { map₂ (· / ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ / t₂ ⊆ s } }⟩ scoped[Pointwise] attribute [instance] Filter.instDiv Filter.instSub @[to_additive] theorem HasBasis.div {ιf ιg : Type*} {pf : ιf → Prop} {sf : ιf → Set α} {pg : ιg → Prop} {sg : ιg → Set α} (hf : f.HasBasis pf sf) (hg : g.HasBasis pg sg) : (f / g).HasBasis (fun i : ιf × ιg ↦ pf i.1 ∧ pg i.2) fun i ↦ sf i.1 / sg i.2 := hf.map₂ (· / ·) hg @[to_additive (attr := simp)] theorem map₂_div : map₂ (· / ·) f g = f / g := rfl @[to_additive] theorem mem_div : s ∈ f / g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ / t₂ ⊆ s := Iff.rfl @[to_additive] theorem div_mem_div : s ∈ f → t ∈ g → s / t ∈ f / g := image2_mem_map₂ @[to_additive (attr := simp)] theorem bot_div : ⊥ / g = ⊥ := map₂_bot_left @[to_additive (attr := simp)] theorem div_bot : f / ⊥ = ⊥ := map₂_bot_right @[to_additive (attr := simp)] theorem div_eq_bot_iff : f / g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := map₂_eq_bot_iff @[to_additive (attr := simp)] theorem div_neBot_iff : (f / g).NeBot ↔ f.NeBot ∧ g.NeBot := map₂_neBot_iff @[to_additive] protected theorem NeBot.div : NeBot f → NeBot g → NeBot (f / g) := NeBot.map₂ @[to_additive] theorem NeBot.of_div_left : (f / g).NeBot → f.NeBot := NeBot.of_map₂_left @[to_additive] theorem NeBot.of_div_right : (f / g).NeBot → g.NeBot := NeBot.of_map₂_right @[to_additive sub.instNeBot] lemma div.instNeBot [NeBot f] [NeBot g] : NeBot (f / g) := .div ‹_› ‹_› scoped[Pointwise] attribute [instance] div.instNeBot sub.instNeBot @[to_additive (attr := simp)] theorem pure_div : pure a / g = g.map (a / ·) := map₂_pure_left @[to_additive (attr := simp)] theorem div_pure : f / pure b = f.map (· / b) := map₂_pure_right @[to_additive] theorem pure_div_pure : (pure a : Filter α) / pure b = pure (a / b) := by simp @[to_additive] protected theorem div_le_div : f₁ ≤ f₂ → g₁ ≤ g₂ → f₁ / g₁ ≤ f₂ / g₂ := map₂_mono @[to_additive] protected theorem div_le_div_left : g₁ ≤ g₂ → f / g₁ ≤ f / g₂ := map₂_mono_left @[to_additive] protected theorem div_le_div_right : f₁ ≤ f₂ → f₁ / g ≤ f₂ / g := map₂_mono_right @[to_additive (attr := simp)] protected theorem le_div_iff : h ≤ f / g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s / t ∈ h := le_map₂_iff @[to_additive] instance covariant_div : CovariantClass (Filter α) (Filter α) (· / ·) (· ≤ ·) := ⟨fun _ _ _ => map₂_mono_left⟩ @[to_additive] instance covariant_swap_div : CovariantClass (Filter α) (Filter α) (swap (· / ·)) (· ≤ ·) := ⟨fun _ _ _ => map₂_mono_right⟩ end Div /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Filter`. See Note [pointwise nat action]. -/ protected def instNSMul [Zero α] [Add α] : SMul ℕ (Filter α) := ⟨nsmulRec⟩ /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Filter`. See Note [pointwise nat action]. -/ @[to_additive existing] protected def instNPow [One α] [Mul α] : Pow (Filter α) ℕ := ⟨fun s n => npowRec n s⟩ /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Filter`. See Note [pointwise nat action]. -/ protected def instZSMul [Zero α] [Add α] [Neg α] : SMul ℤ (Filter α) := ⟨zsmulRec⟩ /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Filter`. See Note [pointwise nat action]. -/ @[to_additive existing] protected def instZPow [One α] [Mul α] [Inv α] : Pow (Filter α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ scoped[Pointwise] attribute [instance] Filter.instNSMul Filter.instNPow Filter.instZSMul Filter.instZPow /-- `Filter α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive /-- `Filter α` is an `AddSemigroup` under pointwise operations if `α` is. -/] protected def semigroup [Semigroup α] : Semigroup (Filter α) where mul_assoc _ _ _ := map₂_assoc mul_assoc /-- `Filter α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive /-- `Filter α` is an `AddCommSemigroup` under pointwise operations if `α` is. -/] protected def commSemigroup [CommSemigroup α] : CommSemigroup (Filter α) := { Filter.semigroup with mul_comm := fun _ _ => map₂_comm mul_comm } section MulOneClass variable [MulOneClass α] [MulOneClass β] /-- `Filter α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive /-- `Filter α` is an `AddZeroClass` under pointwise operations if `α` is. -/] protected def mulOneClass : MulOneClass (Filter α) where one_mul := map₂_left_identity one_mul mul_one := map₂_right_identity mul_one scoped[Pointwise] attribute [instance] Filter.semigroup Filter.addSemigroup Filter.commSemigroup Filter.addCommSemigroup Filter.mulOneClass Filter.addZeroClass variable [FunLike F α β] /-- If `φ : α →* β` then `mapMonoidHom φ` is the monoid homomorphism `Filter α →* Filter β` induced by `map φ`. -/ @[to_additive /-- If `φ : α →+ β` then `mapAddMonoidHom φ` is the monoid homomorphism `Filter α →+ Filter β` induced by `map φ`. -/] def mapMonoidHom [MonoidHomClass F α β] (φ : F) : Filter α →* Filter β where toFun := map φ map_one' := Filter.map_one φ map_mul' _ _ := Filter.map_mul φ -- The other direction does not hold in general @[to_additive] theorem comap_mul_comap_le [MulHomClass F α β] (m : F) {f g : Filter β} : f.comap m * g.comap m ≤ (f * g).comap m := fun _ ⟨_, ⟨t₁, ht₁, t₂, ht₂, t₁t₂⟩, mt⟩ => ⟨m ⁻¹' t₁, ⟨t₁, ht₁, Subset.rfl⟩, m ⁻¹' t₂, ⟨t₂, ht₂, Subset.rfl⟩, (preimage_mul_preimage_subset _).trans <| (preimage_mono t₁t₂).trans mt⟩ @[to_additive] theorem Tendsto.mul_mul [MulHomClass F α β] (m : F) {f₁ g₁ : Filter α} {f₂ g₂ : Filter β} : Tendsto m f₁ f₂ → Tendsto m g₁ g₂ → Tendsto m (f₁ * g₁) (f₂ * g₂) := fun hf hg => (Filter.map_mul m).trans_le <| mul_le_mul' hf hg /-- `pure` as a `MonoidHom`. -/ @[to_additive /-- `pure` as an `AddMonoidHom`. -/] def pureMonoidHom : α →* Filter α := { pureMulHom, pureOneHom with } @[to_additive (attr := simp)] theorem coe_pureMonoidHom : (pureMonoidHom : α → Filter α) = pure := rfl @[to_additive (attr := simp)] theorem pureMonoidHom_apply (a : α) : pureMonoidHom a = pure a := rfl end MulOneClass section Monoid variable [Monoid α] {f g : Filter α} {s : Set α} {a : α} {m n : ℕ} /-- `Filter α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive /-- `Filter α` is an `AddMonoid` under pointwise operations if `α` is. -/] protected def monoid : Monoid (Filter α) := { Filter.mulOneClass, Filter.semigroup, @Filter.instNPow α _ _ with } scoped[Pointwise] attribute [instance] Filter.monoid Filter.addMonoid @[to_additive] theorem pow_mem_pow (hs : s ∈ f) : ∀ n : ℕ, s ^ n ∈ f ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow hs n) hs @[to_additive (attr := simp) nsmul_bot] theorem bot_pow {n : ℕ} (hn : n ≠ 0) : (⊥ : Filter α) ^ n = ⊥ := by rw [← Nat.sub_one_add_one hn, pow_succ', bot_mul] @[to_additive] theorem mul_top_of_one_le (hf : 1 ≤ f) : f * ⊤ = ⊤ := by refine top_le_iff.1 fun s => ?_ simp only [mem_mul, mem_top, exists_eq_left] rintro ⟨t, ht, hs⟩ rwa [mul_univ_of_one_mem (mem_one.1 <| hf ht), univ_subset_iff] at hs @[to_additive] theorem top_mul_of_one_le (hf : 1 ≤ f) : ⊤ * f = ⊤ := by refine top_le_iff.1 fun s => ?_ simp only [mem_mul, mem_top, exists_eq_left] rintro ⟨t, ht, hs⟩ rwa [univ_mul_of_one_mem (mem_one.1 <| hf ht), univ_subset_iff] at hs @[to_additive (attr := simp)] theorem top_mul_top : (⊤ : Filter α) * ⊤ = ⊤ := mul_top_of_one_le le_top @[to_additive nsmul_top] theorem top_pow : ∀ {n : ℕ}, n ≠ 0 → (⊤ : Filter α) ^ n = ⊤ | 0 => fun h => (h rfl).elim | 1 => fun _ => pow_one _ | n + 2 => fun _ => by rw [pow_succ, top_pow n.succ_ne_zero, top_mul_top] @[to_additive] protected theorem _root_.IsUnit.filter : IsUnit a → IsUnit (pure a : Filter α) := IsUnit.map (pureMonoidHom : α →* Filter α) end Monoid /-- `Filter α` is a `CommMonoid` under pointwise operations if `α` is. -/ @[to_additive /-- `Filter α` is an `AddCommMonoid` under pointwise operations if `α` is. -/] protected def commMonoid [CommMonoid α] : CommMonoid (Filter α) := { Filter.mulOneClass, Filter.commSemigroup with } section DivisionMonoid variable [DivisionMonoid α] {f g : Filter α} @[to_additive] protected theorem mul_eq_one_iff : f * g = 1 ↔ ∃ a b, f = pure a ∧ g = pure b ∧ a * b = 1 := by refine ⟨fun hfg => ?_, ?_⟩ · obtain ⟨t₁, h₁, t₂, h₂, h⟩ : (1 : Set α) ∈ f * g := hfg.symm ▸ one_mem_one have hfg : (f * g).NeBot := hfg.symm.subst one_neBot rw [(hfg.nonempty_of_mem <| mul_mem_mul h₁ h₂).subset_one_iff, Set.mul_eq_one_iff] at h obtain ⟨a, b, rfl, rfl, h⟩ := h refine ⟨a, b, ?_, ?_, h⟩ · rwa [← hfg.of_mul_left.le_pure_iff, le_pure_iff] · rwa [← hfg.of_mul_right.le_pure_iff, le_pure_iff] · rintro ⟨a, b, rfl, rfl, h⟩ rw [pure_mul_pure, h, pure_one] /-- `Filter α` is a division monoid under pointwise operations if `α` is. -/ @[to_additive /-- `Filter α` is a subtraction monoid under pointwise operations if `α` is. -/] protected def divisionMonoid : DivisionMonoid (Filter α) := { Filter.monoid, Filter.instInvolutiveInv, Filter.instDiv, Filter.instZPow (α := α) with mul_inv_rev := fun _ _ => map_map₂_antidistrib mul_inv_rev inv_eq_of_mul := fun s t h => by obtain ⟨a, b, rfl, rfl, hab⟩ := Filter.mul_eq_one_iff.1 h rw [inv_pure, inv_eq_of_mul_eq_one_right hab] div_eq_mul_inv := fun _ _ => map_map₂_distrib_right div_eq_mul_inv } @[to_additive] theorem isUnit_iff : IsUnit f ↔ ∃ a, f = pure a ∧ IsUnit a := by constructor · rintro ⟨u, rfl⟩ obtain ⟨a, b, ha, hb, h⟩ := Filter.mul_eq_one_iff.1 u.mul_inv refine ⟨a, ha, ⟨a, b, h, pure_injective ?_⟩, rfl⟩ rw [← pure_mul_pure, ← ha, ← hb] exact u.inv_mul · rintro ⟨a, rfl, ha⟩ exact ha.filter end DivisionMonoid /-- `Filter α` is a commutative division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionCommMonoid /-- `Filter α` is a commutative subtraction monoid under pointwise operations if `α` is. -/] protected def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Filter α) := { Filter.divisionMonoid, Filter.commSemigroup with } /-- `Filter α` has distributive negation if `α` has. -/ protected def instDistribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Filter α) := { Filter.instInvolutiveNeg with neg_mul := fun _ _ => map₂_map_left_comm neg_mul mul_neg := fun _ _ => map_map₂_right_comm mul_neg } scoped[Pointwise] attribute [instance] Filter.commMonoid Filter.addCommMonoid Filter.divisionMonoid Filter.subtractionMonoid Filter.divisionCommMonoid Filter.subtractionCommMonoid Filter.instDistribNeg section Distrib variable [Distrib α] {f g h : Filter α} /-! Note that `Filter α` is not a `Distrib` because `f * g + f * h` has cross terms that `f * (g + h)` lacks. -/ theorem mul_add_subset : f * (g + h) ≤ f * g + f * h := map₂_distrib_le_left mul_add theorem add_mul_subset : (f + g) * h ≤ f * h + g * h := map₂_distrib_le_right add_mul end Distrib section MulZeroClass variable [MulZeroClass α] {f g : Filter α} /-! Note that `Filter` is not a `MulZeroClass` because `0 * ⊥ ≠ 0`. -/ theorem NeBot.mul_zero_nonneg (hf : f.NeBot) : 0 ≤ f * 0 := le_mul_iff.2 fun _ h₁ _ h₂ => let ⟨_, ha⟩ := hf.nonempty_of_mem h₁ ⟨_, ha, _, h₂, mul_zero _⟩ theorem NeBot.zero_mul_nonneg (hg : g.NeBot) : 0 ≤ 0 * g := le_mul_iff.2 fun _ h₁ _ h₂ => let ⟨_, hb⟩ := hg.nonempty_of_mem h₂ ⟨_, h₁, _, hb, zero_mul _⟩ end MulZeroClass section Group variable [Group α] [DivisionMonoid β] [FunLike F α β] [MonoidHomClass F α β] (m : F) {f g f₁ g₁ : Filter α} {f₂ g₂ : Filter β} /-! Note that `Filter α` is not a group because `f / f ≠ 1` in general -/ @[to_additive (attr := simp high)] -- Ensure this fires before `le_div_iff`. protected theorem one_le_div_iff : 1 ≤ f / g ↔ ¬Disjoint f g := by refine ⟨fun h hfg => ?_, ?_⟩ · obtain ⟨s, hs, t, ht, hst⟩ := hfg.le_bot (mem_bot : ∅ ∈ ⊥) exact Set.one_mem_div_iff.1 (h <| div_mem_div hs ht) (disjoint_iff.2 hst.symm) · rintro h s ⟨t₁, h₁, t₂, h₂, hs⟩ exact hs (Set.one_mem_div_iff.2 fun ht => h <| disjoint_of_disjoint_of_mem ht h₁ h₂) @[to_additive] theorem not_one_le_div_iff : ¬1 ≤ f / g ↔ Disjoint f g := Filter.one_le_div_iff.not_left @[to_additive] theorem NeBot.one_le_div (h : f.NeBot) : 1 ≤ f / f := by rintro s ⟨t₁, h₁, t₂, h₂, hs⟩ obtain ⟨a, ha₁, ha₂⟩ := Set.not_disjoint_iff.1 (h.not_disjoint h₁ h₂) rw [mem_one, ← div_self' a] exact hs (Set.div_mem_div ha₁ ha₂) @[to_additive] theorem isUnit_pure (a : α) : IsUnit (pure a : Filter α) := (Group.isUnit a).filter @[simp] theorem isUnit_iff_singleton : IsUnit f ↔ ∃ a, f = pure a := by simp only [isUnit_iff, Group.isUnit, and_true] @[to_additive] theorem map_inv' : f⁻¹.map m = (f.map m)⁻¹ := Semiconj.filter_map (map_inv m) f @[to_additive] protected theorem Tendsto.inv_inv : Tendsto m f₁ f₂ → Tendsto m f₁⁻¹ f₂⁻¹ := fun hf => (Filter.map_inv' m).trans_le <| Filter.inv_le_inv hf @[to_additive] protected theorem map_div : (f / g).map m = f.map m / g.map m := map_map₂_distrib <| map_div m @[to_additive] protected theorem Tendsto.div_div (hf : Tendsto m f₁ f₂) (hg : Tendsto m g₁ g₂) : Tendsto m (f₁ / g₁) (f₂ / g₂) := (Filter.map_div m).trans_le <| Filter.div_le_div hf hg end Group section GroupWithZero variable [GroupWithZero α] {f g : Filter α} theorem NeBot.div_zero_nonneg (hf : f.NeBot) : 0 ≤ f / 0 := Filter.le_div_iff.2 fun _ h₁ _ h₂ => let ⟨_, ha⟩ := hf.nonempty_of_mem h₁ ⟨_, ha, _, h₂, div_zero _⟩ theorem NeBot.zero_div_nonneg (hg : g.NeBot) : 0 ≤ 0 / g := Filter.le_div_iff.2 fun _ h₁ _ h₂ => let ⟨_, hb⟩ := hg.nonempty_of_mem h₂ ⟨_, h₁, _, hb, zero_div _⟩ end GroupWithZero /-! ### Scalar addition/multiplication of filters -/ section SMul variable [SMul α β] {f f₁ f₂ : Filter α} {g g₁ g₂ h : Filter β} {s : Set α} {t : Set β} {a : α} {b : β} /-- The filter `f • g` is generated by `{s • t | s ∈ f, t ∈ g}` in scope `Pointwise`. -/ @[to_additive /-- The filter `f +ᵥ g` is generated by `{s +ᵥ t | s ∈ f, t ∈ g}` in locale `Pointwise`. -/] protected def instSMul : SMul (Filter α) (Filter β) := ⟨/- This is defeq to `map₂ (· • ·) f g`, but the hypothesis unfolds to `t₁ • t₂ ⊆ s` rather than all the way to `Set.image2 (· • ·) t₁ t₂ ⊆ s`. -/ fun f g => { map₂ (· • ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ • t₂ ⊆ s } }⟩ scoped[Pointwise] attribute [instance] Filter.instSMul Filter.instVAdd @[to_additive] theorem HasBasis.smul {ιf ιg : Type*} {pf : ιf → Prop} {sf : ιf → Set α} {pg : ιg → Prop} {sg : ιg → Set β} (hf : f.HasBasis pf sf) (hg : g.HasBasis pg sg) : (f • g).HasBasis (fun i : ιf × ιg ↦ pf i.1 ∧ pg i.2) fun i ↦ sf i.1 • sg i.2 := hf.map₂ (· • ·) hg @[to_additive (attr := simp)] theorem map₂_smul : map₂ (· • ·) f g = f • g := rfl @[to_additive] theorem mem_smul : t ∈ f • g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ • t₂ ⊆ t := Iff.rfl @[to_additive] theorem smul_mem_smul : s ∈ f → t ∈ g → s • t ∈ f • g := image2_mem_map₂ @[to_additive (attr := simp)] theorem bot_smul : (⊥ : Filter α) • g = ⊥ := map₂_bot_left @[to_additive (attr := simp)] theorem smul_bot : f • (⊥ : Filter β) = ⊥ := map₂_bot_right @[to_additive (attr := simp)] theorem smul_eq_bot_iff : f • g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := map₂_eq_bot_iff @[to_additive (attr := simp)] theorem smul_neBot_iff : (f • g).NeBot ↔ f.NeBot ∧ g.NeBot := map₂_neBot_iff @[to_additive] protected theorem NeBot.smul : NeBot f → NeBot g → NeBot (f • g) := NeBot.map₂ @[to_additive] theorem NeBot.of_smul_left : (f • g).NeBot → f.NeBot := NeBot.of_map₂_left @[to_additive] theorem NeBot.of_smul_right : (f • g).NeBot → g.NeBot := NeBot.of_map₂_right @[to_additive vadd.instNeBot] lemma smul.instNeBot [NeBot f] [NeBot g] : NeBot (f • g) := .smul ‹_› ‹_› scoped[Pointwise] attribute [instance] smul.instNeBot vadd.instNeBot @[to_additive (attr := simp)] theorem pure_smul : (pure a : Filter α) • g = g.map (a • ·) := map₂_pure_left @[to_additive (attr := simp)] theorem smul_pure : f • pure b = f.map (· • b) := map₂_pure_right @[to_additive] theorem pure_smul_pure : (pure a : Filter α) • (pure b : Filter β) = pure (a • b) := by simp @[to_additive] theorem smul_le_smul : f₁ ≤ f₂ → g₁ ≤ g₂ → f₁ • g₁ ≤ f₂ • g₂ := map₂_mono @[to_additive] theorem smul_le_smul_left : g₁ ≤ g₂ → f • g₁ ≤ f • g₂ := map₂_mono_left @[to_additive] theorem smul_le_smul_right : f₁ ≤ f₂ → f₁ • g ≤ f₂ • g := map₂_mono_right @[to_additive (attr := simp)] theorem le_smul_iff : h ≤ f • g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s • t ∈ h := le_map₂_iff @[to_additive] instance covariant_smul : CovariantClass (Filter α) (Filter β) (· • ·) (· ≤ ·) := ⟨fun _ _ _ => map₂_mono_left⟩ end SMul /-! ### Scalar subtraction of filters -/ section Vsub variable [VSub α β] {f f₁ f₂ g g₁ g₂ : Filter β} {h : Filter α} {s t : Set β} {a b : β} /-- The filter `f -ᵥ g` is generated by `{s -ᵥ t | s ∈ f, t ∈ g}` in scope `Pointwise`. -/ protected def instVSub : VSub (Filter α) (Filter β) := ⟨/- This is defeq to `map₂ (-ᵥ) f g`, but the hypothesis unfolds to `t₁ -ᵥ t₂ ⊆ s` rather than all the way to `Set.image2 (-ᵥ) t₁ t₂ ⊆ s`. -/ fun f g => { map₂ (· -ᵥ ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ -ᵥ t₂ ⊆ s } }⟩ scoped[Pointwise] attribute [instance] Filter.instVSub @[simp] theorem map₂_vsub : map₂ (· -ᵥ ·) f g = f -ᵥ g := rfl theorem mem_vsub {s : Set α} : s ∈ f -ᵥ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ -ᵥ t₂ ⊆ s := Iff.rfl theorem vsub_mem_vsub : s ∈ f → t ∈ g → s -ᵥ t ∈ f -ᵥ g := image2_mem_map₂ @[simp] theorem bot_vsub : (⊥ : Filter β) -ᵥ g = ⊥ := map₂_bot_left @[simp] theorem vsub_bot : f -ᵥ (⊥ : Filter β) = ⊥ := map₂_bot_right @[simp] theorem vsub_eq_bot_iff : f -ᵥ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := map₂_eq_bot_iff @[simp] theorem vsub_neBot_iff : (f -ᵥ g : Filter α).NeBot ↔ f.NeBot ∧ g.NeBot := map₂_neBot_iff protected theorem NeBot.vsub : NeBot f → NeBot g → NeBot (f -ᵥ g) := NeBot.map₂ theorem NeBot.of_vsub_left : (f -ᵥ g : Filter α).NeBot → f.NeBot := NeBot.of_map₂_left theorem NeBot.of_vsub_right : (f -ᵥ g : Filter α).NeBot → g.NeBot := NeBot.of_map₂_right lemma vsub.instNeBot [NeBot f] [NeBot g] : NeBot (f -ᵥ g) := .vsub ‹_› ‹_› scoped[Pointwise] attribute [instance] vsub.instNeBot @[simp] theorem pure_vsub : (pure a : Filter β) -ᵥ g = g.map (a -ᵥ ·) := map₂_pure_left @[simp] theorem vsub_pure : f -ᵥ pure b = f.map (· -ᵥ b) := map₂_pure_right theorem pure_vsub_pure : (pure a : Filter β) -ᵥ pure b = (pure (a -ᵥ b) : Filter α) := by simp theorem vsub_le_vsub : f₁ ≤ f₂ → g₁ ≤ g₂ → f₁ -ᵥ g₁ ≤ f₂ -ᵥ g₂ := map₂_mono theorem vsub_le_vsub_left : g₁ ≤ g₂ → f -ᵥ g₁ ≤ f -ᵥ g₂ := map₂_mono_left theorem vsub_le_vsub_right : f₁ ≤ f₂ → f₁ -ᵥ g ≤ f₂ -ᵥ g := map₂_mono_right @[simp] theorem le_vsub_iff : h ≤ f -ᵥ g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s -ᵥ t ∈ h := le_map₂_iff end Vsub /-! ### Translation/scaling of filters -/ section SMul variable [SMul α β] {f f₁ f₂ : Filter β} {s : Set β} {a : α} /-- `a • f` is the map of `f` under `a •` in scope `Pointwise`. -/ @[to_additive /-- `a +ᵥ f` is the map of `f` under `a +ᵥ` in scope `Pointwise`. -/] protected def instSMulFilter : SMul α (Filter β) := ⟨fun a => map (a • ·)⟩ scoped[Pointwise] attribute [instance] Filter.instSMulFilter Filter.instVAddFilter @[to_additive (attr := simp)] protected theorem map_smul : map (fun b => a • b) f = a • f := rfl @[to_additive] theorem mem_smul_filter : s ∈ a • f ↔ (a • ·) ⁻¹' s ∈ f := Iff.rfl @[to_additive] theorem smul_set_mem_smul_filter : s ∈ f → a • s ∈ a • f := image_mem_map @[to_additive (attr := simp)] theorem smul_filter_bot : a • (⊥ : Filter β) = ⊥ := map_bot @[to_additive (attr := simp)] theorem smul_filter_eq_bot_iff : a • f = ⊥ ↔ f = ⊥ := map_eq_bot_iff @[to_additive (attr := simp)] theorem smul_filter_neBot_iff : (a • f).NeBot ↔ f.NeBot := map_neBot_iff _ @[to_additive] theorem NeBot.smul_filter : f.NeBot → (a • f).NeBot := fun h => h.map _ @[to_additive] theorem NeBot.of_smul_filter : (a • f).NeBot → f.NeBot := NeBot.of_map @[to_additive vadd_filter.instNeBot] lemma smul_filter.instNeBot [NeBot f] : NeBot (a • f) := .smul_filter ‹_› scoped[Pointwise] attribute [instance] smul_filter.instNeBot vadd_filter.instNeBot @[to_additive] theorem smul_filter_le_smul_filter (hf : f₁ ≤ f₂) : a • f₁ ≤ a • f₂ := map_mono hf @[to_additive] instance covariant_smul_filter : CovariantClass α (Filter β) (· • ·) (· ≤ ·) := ⟨fun _ => @map_mono β β _⟩ end SMul @[to_additive] instance smulCommClass_filter [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α β (Filter γ) := ⟨fun _ _ _ => map_comm (funext <| smul_comm _ _) _⟩ @[to_additive] instance smulCommClass_filter' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α (Filter β) (Filter γ) := ⟨fun a _ _ => map_map₂_distrib_right <| smul_comm a⟩ @[to_additive] instance smulCommClass_filter'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Filter α) β (Filter γ) := haveI := SMulCommClass.symm α β γ SMulCommClass.symm _ _ _ @[to_additive] instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Filter α) (Filter β) (Filter γ) := ⟨fun _ _ _ => map₂_left_comm smul_comm⟩ @[to_additive] instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α β (Filter γ) := ⟨fun a b f => by simp only [← Filter.map_smul, map_map, smul_assoc]; rfl⟩ @[to_additive] instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α (Filter β) (Filter γ) := ⟨fun a f g => by refine (map_map₂_distrib_left fun _ _ => ?_).symm exact (smul_assoc a _ _).symm⟩ @[to_additive] instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower (Filter α) (Filter β) (Filter γ) := ⟨fun _ _ _ => map₂_assoc smul_assoc⟩ @[to_additive] instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] : IsCentralScalar α (Filter β) := ⟨fun _ f => (congr_arg fun m => map m f) <| funext fun _ => op_smul_eq_smul _ _⟩ /-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `Filter α` on `Filter β`. -/ @[to_additive /-- An additive action of an additive monoid `α` on a type `β` gives an additive action of `Filter α` on `Filter β`. -/] protected def mulAction [Monoid α] [MulAction α β] : MulAction (Filter α) (Filter β) where one_smul f := map₂_pure_left.trans <| by simp_rw [one_smul, map_id'] mul_smul _ _ _ := map₂_assoc mul_smul /-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Filter β`. -/ @[to_additive /-- An additive action of an additive monoid on a type `β` gives an additive action on `Filter β`. -/] protected def mulActionFilter [Monoid α] [MulAction α β] : MulAction α (Filter β) where mul_smul a b f := by simp only [← Filter.map_smul, map_map, Function.comp_def, ← mul_smul] one_smul f := by simp only [← Filter.map_smul, one_smul, map_id'] scoped[Pointwise] attribute [instance] Filter.mulAction Filter.addAction Filter.mulActionFilter Filter.addActionFilter /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `Filter β`. -/ protected def distribMulActionFilter [Monoid α] [AddMonoid β] [DistribMulAction α β] : DistribMulAction α (Filter β) where smul_add _ _ _ := map_map₂_distrib <| smul_add _ smul_zero _ := (map_pure _ _).trans <| by rw [smul_zero, pure_zero] /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/ protected noncomputable def mulDistribMulActionFilter [Monoid α] [Monoid β] [MulDistribMulAction α β] : MulDistribMulAction α (Set β) where smul_mul _ _ _ := image_image2_distrib <| smul_mul' _ smul_one _ := image_singleton.trans <| by rw [smul_one, singleton_one] scoped[Pointwise] attribute [instance] Filter.distribMulActionFilter Filter.mulDistribMulActionFilter section SMulWithZero variable [Zero α] [Zero β] [SMulWithZero α β] {f : Filter α} {g : Filter β} /-! Note that we have neither `SMulWithZero α (Filter β)` nor `SMulWithZero (Filter α) (Filter β)` because `0 * ⊥ ≠ 0`. -/ theorem NeBot.smul_zero_nonneg (hf : f.NeBot) : 0 ≤ f • (0 : Filter β) := le_smul_iff.2 fun _ h₁ _ h₂ => let ⟨_, ha⟩ := hf.nonempty_of_mem h₁ ⟨_, ha, _, h₂, smul_zero _⟩ theorem NeBot.zero_smul_nonneg (hg : g.NeBot) : 0 ≤ (0 : Filter α) • g := le_smul_iff.2 fun _ h₁ _ h₂ => let ⟨_, hb⟩ := hg.nonempty_of_mem h₂ ⟨_, h₁, _, hb, zero_smul _ _⟩ theorem zero_smul_filter_nonpos : (0 : α) • g ≤ 0 := by refine fun s hs => mem_smul_filter.2 ?_ convert @univ_mem _ g refine eq_univ_iff_forall.2 fun a => ?_ rwa [mem_preimage, zero_smul] theorem zero_smul_filter (hg : g.NeBot) : (0 : α) • g = 0 := zero_smul_filter_nonpos.antisymm <| le_map_iff.2 fun s hs => by simp_rw [zero_smul, (hg.nonempty_of_mem hs).image_const] exact zero_mem_zero end SMulWithZero section Cancel @[to_additive] theorem _root_.IsUnit.smul_tendsto_smul_iff [Monoid γ] [MulAction γ β] {m : α → β} {c : γ} {f : Filter α} {g : Filter β} (hc : IsUnit c) : Tendsto (c • m) f (c • g) ↔ Tendsto m f g := by rcases hc.exists_left_inv with ⟨d, hd⟩ refine ⟨fun H ↦ ?_, fun H ↦ tendsto_map.comp H⟩ simpa [Function.comp_def, smul_smul, hd] using (tendsto_map (f := (d • ·))).comp H @[to_additive (attr := simp)] theorem smul_tendsto_smul_iff [Group γ] [MulAction γ β] {m : α → β} {c : γ} {f : Filter α} {g : Filter β} : Tendsto (c • m) f (c • g) ↔ Tendsto m f g := Group.isUnit _ |>.smul_tendsto_smul_iff theorem smul_tendsto_smul_iff₀ [GroupWithZero γ] [MulAction γ β] {m : α → β} {c : γ} {f : Filter α} {g : Filter β} (hc : c ≠ 0) : Tendsto (c • m) f (c • g) ↔ Tendsto m f g := hc.isUnit.smul_tendsto_smul_iff end Cancel end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Map.lean
import Mathlib.Control.Basic import Mathlib.Data.Set.Lattice.Image import Mathlib.Order.Filter.Basic /-! # Theorems about map and comap on filters. -/ assert_not_exists IsOrderedRing Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α β γ δ : Type*} {ι : Sort*} {F : Filter α} {G : Filter β} /-! ### Push-forwards, pull-backs, and the monad structure -/ section Map @[simp] theorem map_principal {s : Set α} {f : α → β} : map f (𝓟 s) = 𝓟 (Set.image f s) := Filter.ext fun _ => image_subset_iff.symm variable {f : Filter α} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β} @[simp] theorem eventually_map {P : β → Prop} : (∀ᶠ b in map m f, P b) ↔ ∀ᶠ a in f, P (m a) := Iff.rfl @[simp] theorem frequently_map {P : β → Prop} : (∃ᶠ b in map m f, P b) ↔ ∃ᶠ a in f, P (m a) := Iff.rfl @[simp] theorem eventuallyEq_map {f₁ f₂ : β → γ} : f₁ =ᶠ[map m f] f₂ ↔ f₁ ∘ m =ᶠ[f] f₂ ∘ m := .rfl @[simp] theorem eventuallyLE_map [LE γ] {f₁ f₂ : β → γ} : f₁ ≤ᶠ[map m f] f₂ ↔ f₁ ∘ m ≤ᶠ[f] f₂ ∘ m := .rfl @[simp] theorem mem_map : t ∈ map m f ↔ m ⁻¹' t ∈ f := Iff.rfl theorem mem_map' : t ∈ map m f ↔ { x | m x ∈ t } ∈ f := Iff.rfl theorem image_mem_map (hs : s ∈ f) : m '' s ∈ map m f := f.sets_of_superset hs <| subset_preimage_image m s -- The simpNF linter says that the LHS can be simplified via `Filter.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem image_mem_map_iff (hf : Injective m) : m '' s ∈ map m f ↔ s ∈ f := ⟨fun h => by rwa [← preimage_image_eq s hf], image_mem_map⟩ theorem range_mem_map : range m ∈ map m f := by rw [← image_univ] exact image_mem_map univ_mem theorem mem_map_iff_exists_image : t ∈ map m f ↔ ∃ s ∈ f, m '' s ⊆ t := ⟨fun ht => ⟨m ⁻¹' t, ht, image_preimage_subset _ _⟩, fun ⟨_, hs, ht⟩ => mem_of_superset (image_mem_map hs) ht⟩ @[simp] theorem map_id : Filter.map id f = f := filter_eq <| rfl @[simp] theorem map_id' : Filter.map (fun x => x) f = f := map_id @[simp] theorem map_compose : Filter.map m' ∘ Filter.map m = Filter.map (m' ∘ m) := funext fun _ => filter_eq <| rfl @[simp] theorem map_map : Filter.map m' (Filter.map m f) = Filter.map (m' ∘ m) f := congr_fun Filter.map_compose f /-- If functions `m₁` and `m₂` are eventually equal at a filter `f`, then they map this filter to the same filter. -/ theorem map_congr {m₁ m₂ : α → β} {f : Filter α} (h : m₁ =ᶠ[f] m₂) : map m₁ f = map m₂ f := Filter.ext' fun _ => eventually_congr (h.mono fun _ hx => hx ▸ Iff.rfl) end Map section Comap variable {f : α → β} {l : Filter β} {p : α → Prop} {s : Set α} theorem mem_comap' : s ∈ comap f l ↔ { y | ∀ ⦃x⦄, f x = y → x ∈ s } ∈ l := ⟨fun ⟨t, ht, hts⟩ => mem_of_superset ht fun y hy x hx => hts <| mem_preimage.2 <| by rwa [hx], fun h => ⟨_, h, fun _ hx => hx rfl⟩⟩ -- TODO: it would be nice to use `kernImage` much more to take advantage of common name and API, -- and then this would become `mem_comap'` theorem mem_comap'' : s ∈ comap f l ↔ kernImage f s ∈ l := mem_comap' /-- RHS form is used, e.g., in the definition of `UniformSpace`. -/ lemma mem_comap_prodMk {x : α} {s : Set β} {F : Filter (α × β)} : s ∈ comap (Prod.mk x) F ↔ {p : α × β | p.fst = x → p.snd ∈ s} ∈ F := by simp_rw [mem_comap', Prod.ext_iff, and_imp, @forall_swap β (_ = _), forall_eq, eq_comm] @[simp] theorem eventually_comap : (∀ᶠ a in comap f l, p a) ↔ ∀ᶠ b in l, ∀ a, f a = b → p a := mem_comap' @[simp] theorem frequently_comap : (∃ᶠ a in comap f l, p a) ↔ ∃ᶠ b in l, ∃ a, f a = b ∧ p a := by simp only [Filter.Frequently, eventually_comap, not_exists, _root_.not_and] theorem mem_comap_iff_compl : s ∈ comap f l ↔ (f '' sᶜ)ᶜ ∈ l := by simp only [mem_comap'', kernImage_eq_compl] theorem compl_mem_comap : sᶜ ∈ comap f l ↔ (f '' s)ᶜ ∈ l := by rw [mem_comap_iff_compl, compl_compl] end Comap instance : LawfulFunctor (Filter : Type u → Type u) where id_map _ := map_id comp_map _ _ _ := map_map.symm map_const := rfl theorem pure_sets (a : α) : (pure a : Filter α).sets = { s | a ∈ s } := rfl @[simp] theorem eventually_pure {a : α} {p : α → Prop} : (∀ᶠ x in pure a, p x) ↔ p a := Iff.rfl @[simp] theorem principal_singleton (a : α) : 𝓟 {a} = pure a := Filter.ext fun s => by simp only [mem_pure, mem_principal, singleton_subset_iff] @[simp] theorem biSup_pure_eq_principal (s : Set α) : ⨆ a ∈ s, pure a = 𝓟 s := Filter.ext fun s => by simp [Set.subset_def] @[simp] theorem iSup_pure_eq_top : ⨆ a, pure a = (⊤ : Filter α) := by rw [← principal_univ, ← biSup_pure_eq_principal, iSup_univ] @[simp] theorem map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) := rfl theorem pure_le_principal {s : Set α} (a : α) : pure a ≤ 𝓟 s ↔ a ∈ s := by simp @[simp] theorem join_pure (f : Filter α) : join (pure f) = f := rfl @[simp] theorem pure_bind (a : α) (m : α → Filter β) : bind (pure a) m = m a := by simp only [bind, map_pure, join_pure] theorem map_bind {α β} (m : β → γ) (f : Filter α) (g : α → Filter β) : map m (bind f g) = bind f (map m ∘ g) := rfl theorem bind_map {α β} (m : α → β) (f : Filter α) (g : β → Filter γ) : (bind (map m f) g) = bind f (g ∘ m) := rfl /-! ### `Filter` as a `Monad` In this section we define `Filter.monad`, a `Monad` structure on `Filter`s. This definition is not an instance because its `Seq` projection is not equal to the `Filter.seq` function we use in the `Applicative` instance on `Filter`. -/ section /-- The monad structure on filters. -/ protected def monad : Monad Filter where map := @Filter.map attribute [local instance] Filter.monad protected theorem lawfulMonad : LawfulMonad Filter where map_const := rfl id_map _ := rfl seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl pure_seq _ _ := rfl bind_pure_comp _ _ := rfl bind_map _ _ := rfl pure_bind _ _ := rfl bind_assoc _ _ _ := rfl end instance : Alternative Filter where seq := fun x y => x.seq (y ()) failure := ⊥ orElse x y := x ⊔ y () @[simp] theorem map_def {α β} (m : α → β) (f : Filter α) : m <$> f = map m f := rfl @[simp] theorem bind_def {α β} (f : Filter α) (m : α → Filter β) : f >>= m = bind f m := rfl /-! #### `map` and `comap` equations -/ section Map variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Filter β} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β} @[simp] theorem mem_comap : s ∈ comap m g ↔ ∃ t ∈ g, m ⁻¹' t ⊆ s := Iff.rfl theorem preimage_mem_comap (ht : t ∈ g) : m ⁻¹' t ∈ comap m g := ⟨t, ht, Subset.rfl⟩ theorem Eventually.comap {p : β → Prop} (hf : ∀ᶠ b in g, p b) (f : α → β) : ∀ᶠ a in comap f g, p (f a) := preimage_mem_comap hf theorem comap_id : comap id f = f := le_antisymm (fun _ => preimage_mem_comap) fun _ ⟨_, ht, hst⟩ => mem_of_superset ht hst theorem comap_id' : comap (fun x => x) f = f := comap_id theorem comap_const_of_notMem {x : β} (ht : t ∈ g) (hx : x ∉ t) : comap (fun _ : α => x) g = ⊥ := empty_mem_iff_bot.1 <| mem_comap'.2 <| mem_of_superset ht fun _ hx' _ h => hx <| h.symm ▸ hx' @[deprecated (since := "2025-05-23")] alias comap_const_of_not_mem := comap_const_of_notMem theorem comap_const_of_mem {x : β} (h : ∀ t ∈ g, x ∈ t) : comap (fun _ : α => x) g = ⊤ := top_unique fun _ hs => univ_mem' fun _ => h _ (mem_comap'.1 hs) rfl theorem map_const [NeBot f] {c : β} : (f.map fun _ => c) = pure c := by ext s by_cases h : c ∈ s <;> simp [h] theorem comap_comap {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f := Filter.coext fun s => by simp only [compl_mem_comap, image_image, (· ∘ ·)] section comm /-! The variables in the following lemmas are used as in this diagram: ``` φ α → β θ ↓ ↓ ψ γ → δ ρ ``` -/ variable {φ : α → β} {θ : α → γ} {ψ : β → δ} {ρ : γ → δ} theorem map_comm (H : ψ ∘ φ = ρ ∘ θ) (F : Filter α) : map ψ (map φ F) = map ρ (map θ F) := by rw [Filter.map_map, H, ← Filter.map_map] theorem comap_comm (H : ψ ∘ φ = ρ ∘ θ) (G : Filter δ) : comap φ (comap ψ G) = comap θ (comap ρ G) := by rw [Filter.comap_comap, H, ← Filter.comap_comap] end comm theorem _root_.Function.Semiconj.filter_map {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := map_comm h.comp_eq theorem _root_.Function.Commute.filter_map {f g : α → α} (h : Function.Commute f g) : Function.Commute (map f) (map g) := h.semiconj.filter_map theorem _root_.Function.Semiconj.filter_comap {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (comap f) (comap gb) (comap ga) := comap_comm h.comp_eq.symm theorem _root_.Function.Commute.filter_comap {f g : α → α} (h : Function.Commute f g) : Function.Commute (comap f) (comap g) := h.semiconj.filter_comap section open Filter theorem _root_.Function.LeftInverse.filter_map {f : α → β} {g : β → α} (hfg : LeftInverse g f) : LeftInverse (map g) (map f) := fun F ↦ by rw [map_map, hfg.comp_eq_id, map_id] theorem _root_.Function.LeftInverse.filter_comap {f : α → β} {g : β → α} (hfg : LeftInverse g f) : RightInverse (comap g) (comap f) := fun F ↦ by rw [comap_comap, hfg.comp_eq_id, comap_id] nonrec theorem _root_.Function.RightInverse.filter_map {f : α → β} {g : β → α} (hfg : RightInverse g f) : RightInverse (map g) (map f) := hfg.filter_map nonrec theorem _root_.Function.RightInverse.filter_comap {f : α → β} {g : β → α} (hfg : RightInverse g f) : LeftInverse (comap g) (comap f) := hfg.filter_comap theorem _root_.Set.LeftInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : LeftInvOn g f s) : LeftInvOn (map g) (map f) (Iic <| 𝓟 s) := fun F (hF : F ≤ 𝓟 s) ↦ by have : (g ∘ f) =ᶠ[𝓟 s] id := by simpa only [eventuallyEq_principal] using hfg rw [map_map, map_congr (this.filter_mono hF), map_id] nonrec theorem _root_.Set.RightInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : RightInvOn g f t) : RightInvOn (map g) (map f) (Iic <| 𝓟 t) := hfg.filter_map_Iic end section KernMap /-- The analog of `Set.kernImage` for filters. A set `s` belongs to `Filter.kernMap m f` if either of the following equivalent conditions hold. 1. There exists a set `t ∈ f` such that `s = Set.kernImage m t`. This is used as a definition. 2. There exists a set `t` such that `tᶜ ∈ f` and `sᶜ = m '' t`, see `Filter.mem_kernMap_iff_compl` and `Filter.compl_mem_kernMap`. This definition is useful because it gives a right adjoint to `Filter.comap`, and because it has a nice interpretation when working with `co-` filters (`Filter.cocompact`, `Filter.cofinite`, ...). For example, `kernMap m (cocompact α)` is the filter generated by the complements of the sets `m '' K` where `K` is a compact subset of `α`. -/ def kernMap (m : α → β) (f : Filter α) : Filter β where sets := (kernImage m) '' f.sets univ_sets := ⟨univ, f.univ_sets, by simp [kernImage_eq_compl]⟩ sets_of_superset := by rintro _ t ⟨s, hs, rfl⟩ hst refine ⟨s ∪ m ⁻¹' t, mem_of_superset hs subset_union_left, ?_⟩ rw [kernImage_union_preimage, union_eq_right.mpr hst] inter_sets := by rintro _ _ ⟨s₁, h₁, rfl⟩ ⟨s₂, h₂, rfl⟩ exact ⟨s₁ ∩ s₂, f.inter_sets h₁ h₂, Set.preimage_kernImage.u_inf⟩ variable {m : α → β} {f : Filter α} theorem mem_kernMap {s : Set β} : s ∈ kernMap m f ↔ ∃ t ∈ f, kernImage m t = s := Iff.rfl theorem mem_kernMap_iff_compl {s : Set β} : s ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = sᶜ := by rw [mem_kernMap, compl_surjective.exists] refine exists_congr (fun x ↦ and_congr_right fun _ ↦ ?_) rw [kernImage_compl, compl_eq_comm, eq_comm] theorem compl_mem_kernMap {s : Set β} : sᶜ ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = s := by simp_rw [mem_kernMap_iff_compl, compl_compl] theorem comap_le_iff_le_kernMap : comap m g ≤ f ↔ g ≤ kernMap m f := by simp [Filter.le_def, mem_comap'', mem_kernMap, -mem_comap] theorem gc_comap_kernMap (m : α → β) : GaloisConnection (comap m) (kernMap m) := fun _ _ ↦ comap_le_iff_le_kernMap theorem kernMap_principal {s : Set α} : kernMap m (𝓟 s) = 𝓟 (kernImage m s) := by refine eq_of_forall_le_iff (fun g ↦ ?_) rw [← comap_le_iff_le_kernMap, le_principal_iff, le_principal_iff, mem_comap''] end KernMap @[simp] theorem comap_principal {t : Set β} : comap m (𝓟 t) = 𝓟 (m ⁻¹' t) := Filter.ext fun _ => ⟨fun ⟨_u, hu, b⟩ => (preimage_mono hu).trans b, fun h => ⟨t, Subset.rfl, h⟩⟩ theorem principal_subtype {α : Type*} (s : Set α) (t : Set s) : 𝓟 t = comap (↑) (𝓟 (((↑) : s → α) '' t)) := by rw [comap_principal, preimage_image_eq _ Subtype.coe_injective] @[simp] theorem comap_pure {b : β} : comap m (pure b) = 𝓟 (m ⁻¹' {b}) := by rw [← principal_singleton, comap_principal] theorem map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g := ⟨fun h _ ⟨_, ht, hts⟩ => mem_of_superset (h ht) hts, fun h _ ht => h ⟨_, ht, Subset.rfl⟩⟩ theorem gc_map_comap (m : α → β) : GaloisConnection (map m) (comap m) := fun _ _ => map_le_iff_le_comap @[gcongr, mono] theorem map_mono : Monotone (map m) := (gc_map_comap m).monotone_l @[gcongr, mono] theorem comap_mono : Monotone (comap m) := (gc_map_comap m).monotone_u @[simp] theorem map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot @[simp] theorem map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup @[simp] theorem map_iSup {f : ι → Filter α} : map m (⨆ i, f i) = ⨆ i, map m (f i) := (gc_map_comap m).l_iSup @[simp] theorem map_top (f : α → β) : map f ⊤ = 𝓟 (range f) := by rw [← principal_univ, map_principal, image_univ] @[simp] theorem comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top @[simp] theorem comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf @[simp] theorem comap_iInf {f : ι → Filter β} : comap m (⨅ i, f i) = ⨅ i, comap m (f i) := (gc_map_comap m).u_iInf theorem le_comap_top (f : α → β) (l : Filter α) : l ≤ comap f ⊤ := by rw [comap_top] exact le_top theorem map_comap_le : map m (comap m g) ≤ g := (gc_map_comap m).l_u_le _ theorem le_comap_map : f ≤ comap m (map m f) := (gc_map_comap m).le_u_l _ @[simp] theorem comap_bot : comap m ⊥ = ⊥ := bot_unique fun s _ => ⟨∅, mem_bot, by simp only [empty_subset, preimage_empty]⟩ theorem neBot_of_comap (h : (comap m g).NeBot) : g.NeBot := by rw [neBot_iff] at * contrapose! h rw [h] exact comap_bot theorem comap_inf_principal_range : comap m (g ⊓ 𝓟 (range m)) = comap m g := by simp theorem disjoint_comap (h : Disjoint g₁ g₂) : Disjoint (comap m g₁) (comap m g₂) := by simp only [disjoint_iff, ← comap_inf, h.eq_bot, comap_bot] theorem comap_iSup {ι} {f : ι → Filter β} {m : α → β} : comap m (iSup f) = ⨆ i, comap m (f i) := (gc_comap_kernMap m).l_iSup theorem comap_sSup {s : Set (Filter β)} {m : α → β} : comap m (sSup s) = ⨆ f ∈ s, comap m f := by simp only [sSup_eq_iSup, comap_iSup] theorem comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ := by rw [sup_eq_iSup, comap_iSup, iSup_bool_eq, Bool.cond_true, Bool.cond_false] theorem map_comap (f : Filter β) (m : α → β) : (f.comap m).map m = f ⊓ 𝓟 (range m) := by refine le_antisymm (le_inf map_comap_le <| le_principal_iff.2 range_mem_map) ?_ rintro t' ⟨t, ht, sub⟩ refine mem_inf_principal.2 (mem_of_superset ht ?_) rintro _ hxt ⟨x, rfl⟩ exact sub hxt theorem map_comap_setCoe_val (f : Filter β) (s : Set β) : (f.comap ((↑) : s → β)).map (↑) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_val] theorem map_comap_of_mem {f : Filter β} {m : α → β} (hf : range m ∈ f) : (f.comap m).map m = f := by rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)] instance canLift (c) (p) [CanLift α β c p] : CanLift (Filter α) (Filter β) (map c) fun f => ∀ᶠ x : α in f, p x where prf f hf := ⟨comap c f, map_comap_of_mem <| hf.mono CanLift.prf⟩ theorem comap_le_comap_iff {f g : Filter β} {m : α → β} (hf : range m ∈ f) : comap m f ≤ comap m g ↔ f ≤ g := ⟨fun h => map_comap_of_mem hf ▸ (map_mono h).trans map_comap_le, fun h => comap_mono h⟩ theorem map_comap_of_surjective {f : α → β} (hf : Surjective f) (l : Filter β) : map f (comap f l) = l := map_comap_of_mem <| by simp only [hf.range_eq, univ_mem] theorem comap_injective {f : α → β} (hf : Surjective f) : Injective (comap f) := LeftInverse.injective <| map_comap_of_surjective hf theorem _root_.Function.Surjective.filter_map_top {f : α → β} (hf : Surjective f) : map f ⊤ = ⊤ := (congr_arg _ comap_top).symm.trans <| map_comap_of_surjective hf ⊤ theorem subtype_coe_map_comap (s : Set α) (f : Filter α) : map ((↑) : s → α) (comap ((↑) : s → α) f) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_coe] theorem image_mem_of_mem_comap {f : Filter α} {c : β → α} (h : range c ∈ f) {W : Set β} (W_in : W ∈ comap c f) : c '' W ∈ f := by rw [← map_comap_of_mem h] exact image_mem_map W_in theorem image_coe_mem_of_mem_comap {f : Filter α} {U : Set α} (h : U ∈ f) {W : Set U} (W_in : W ∈ comap ((↑) : U → α) f) : (↑) '' W ∈ f := image_mem_of_mem_comap (by simp [h]) W_in theorem comap_map {f : Filter α} {m : α → β} (h : Injective m) : comap m (map m f) = f := le_antisymm (fun s hs => mem_of_superset (preimage_mem_comap <| image_mem_map hs) <| by simp only [preimage_image_eq s h, Subset.rfl]) le_comap_map theorem mem_comap_iff {f : Filter β} {m : α → β} (inj : Injective m) (large : Set.range m ∈ f) {S : Set α} : S ∈ comap m f ↔ m '' S ∈ f := by rw [← image_mem_map_iff inj, map_comap_of_mem large] theorem map_le_map_iff_of_injOn {l₁ l₂ : Filter α} {f : α → β} {s : Set α} (h₁ : s ∈ l₁) (h₂ : s ∈ l₂) (hinj : InjOn f s) : map f l₁ ≤ map f l₂ ↔ l₁ ≤ l₂ := ⟨fun h _t ht => mp_mem h₁ <| mem_of_superset (h <| image_mem_map (inter_mem h₂ ht)) fun _y ⟨_x, ⟨hxs, hxt⟩, hxy⟩ hys => hinj hxs hys hxy ▸ hxt, fun h => map_mono h⟩ theorem map_le_map_iff {f g : Filter α} {m : α → β} (hm : Injective m) : map m f ≤ map m g ↔ f ≤ g := by rw [map_le_iff_le_comap, comap_map hm] theorem map_eq_map_iff_of_injOn {f g : Filter α} {m : α → β} {s : Set α} (hsf : s ∈ f) (hsg : s ∈ g) (hm : InjOn m s) : map m f = map m g ↔ f = g := by simp only [le_antisymm_iff, map_le_map_iff_of_injOn hsf hsg hm, map_le_map_iff_of_injOn hsg hsf hm] theorem map_inj {f g : Filter α} {m : α → β} (hm : Injective m) : map m f = map m g ↔ f = g := map_eq_map_iff_of_injOn univ_mem univ_mem hm.injOn theorem map_injective {m : α → β} (hm : Injective m) : Injective (map m) := fun _ _ => (map_inj hm).1 theorem comap_neBot_iff {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∀ t ∈ f, ∃ a, m a ∈ t := by simp only [← forall_mem_nonempty_iff_neBot, mem_comap, forall_exists_index, and_imp] exact ⟨fun h t t_in => h (m ⁻¹' t) t t_in Subset.rfl, fun h s t ht hst => (h t ht).imp hst⟩ theorem comap_neBot {f : Filter β} {m : α → β} (hm : ∀ t ∈ f, ∃ a, m a ∈ t) : NeBot (comap m f) := comap_neBot_iff.mpr hm theorem comap_neBot_iff_frequently {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∃ᶠ y in f, y ∈ range m := by simp only [comap_neBot_iff, frequently_iff, mem_range, @and_comm (_ ∈ _), exists_exists_eq_and] theorem comap_neBot_iff_compl_range {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ (range m)ᶜ ∉ f := comap_neBot_iff_frequently theorem comap_eq_bot_iff_compl_range {f : Filter β} {m : α → β} : comap m f = ⊥ ↔ (range m)ᶜ ∈ f := not_iff_not.mp <| neBot_iff.symm.trans comap_neBot_iff_compl_range theorem comap_surjective_eq_bot {f : Filter β} {m : α → β} (hm : Surjective m) : comap m f = ⊥ ↔ f = ⊥ := by rw [comap_eq_bot_iff_compl_range, hm.range_eq, compl_univ, empty_mem_iff_bot] theorem disjoint_comap_iff (h : Surjective m) : Disjoint (comap m g₁) (comap m g₂) ↔ Disjoint g₁ g₂ := by rw [disjoint_iff, disjoint_iff, ← comap_inf, comap_surjective_eq_bot h] theorem NeBot.comap_of_range_mem {f : Filter β} {m : α → β} (_ : NeBot f) (hm : range m ∈ f) : NeBot (comap m f) := comap_neBot_iff_frequently.2 <| Eventually.frequently hm section Sum open Sum @[simp] theorem comap_inl_map_inr : comap inl (map (@inr α β) g) = ⊥ := by ext rw [mem_comap_iff_compl] simp @[simp] theorem comap_inr_map_inl : comap inr (map (@inl α β) f) = ⊥ := by ext rw [mem_comap_iff_compl] simp @[simp] theorem map_inl_inf_map_inr : map inl f ⊓ map inr g = ⊥ := by apply le_bot_iff.mp trans map inl ⊤ ⊓ map inr ⊤ · apply inf_le_inf <;> simp · simp @[simp] theorem map_inr_inf_map_inl : map inr f ⊓ map inl g = ⊥ := by rw [inf_comm, map_inl_inf_map_inr] theorem comap_sumElim_eq (l : Filter γ) (m₁ : α → γ) (m₂ : β → γ) : comap (Sum.elim m₁ m₂) l = map inl (comap m₁ l) ⊔ map inr (comap m₂ l) := by ext s simp_rw [mem_sup, mem_map, mem_comap_iff_compl] simp [image_sumElim] theorem map_comap_inl_sup_map_comap_inr (l : Filter (α ⊕ β)) : map inl (comap inl l) ⊔ map inr (comap inr l) = l := by rw [← comap_sumElim_eq, Sum.elim_inl_inr, comap_id] theorem map_sumElim_eq (l : Filter (α ⊕ β)) (m₁ : α → γ) (m₂ : β → γ) : map (Sum.elim m₁ m₂) l = map m₁ (comap inl l) ⊔ map m₂ (comap inr l) := by rw [← map_comap_inl_sup_map_comap_inr l] simp [map_sup, map_map, comap_sup, (gc_map_comap _).u_l_u_eq_u] end Sum @[simp] theorem comap_fst_neBot_iff {f : Filter α} : (f.comap (Prod.fst : α × β → α)).NeBot ↔ f.NeBot ∧ Nonempty β := by cases isEmpty_or_nonempty β · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp [*] · simp [comap_neBot_iff_frequently, *] @[instance] theorem comap_fst_neBot [Nonempty β] {f : Filter α} [NeBot f] : (f.comap (Prod.fst : α × β → α)).NeBot := comap_fst_neBot_iff.2 ⟨‹_›, ‹_›⟩ @[simp] theorem comap_snd_neBot_iff {f : Filter β} : (f.comap (Prod.snd : α × β → β)).NeBot ↔ Nonempty α ∧ f.NeBot := by rcases isEmpty_or_nonempty α with hα | hα · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp · simp [comap_neBot_iff_frequently, hα] @[instance] theorem comap_snd_neBot [Nonempty α] {f : Filter β} [NeBot f] : (f.comap (Prod.snd : α × β → β)).NeBot := comap_snd_neBot_iff.2 ⟨‹_›, ‹_›⟩ theorem comap_eval_neBot_iff' {ι : Type*} {α : ι → Type*} {i : ι} {f : Filter (α i)} : (comap (eval i) f).NeBot ↔ (∀ j, Nonempty (α j)) ∧ NeBot f := by rcases isEmpty_or_nonempty (∀ j, α j) with H | H · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not] simp [← Classical.nonempty_pi] · have : ∀ j, Nonempty (α j) := Classical.nonempty_pi.1 H simp [comap_neBot_iff_frequently, *] @[simp] theorem comap_eval_neBot_iff {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] {i : ι} {f : Filter (α i)} : (comap (eval i) f).NeBot ↔ NeBot f := by simp [comap_eval_neBot_iff', *] @[instance] theorem comap_eval_neBot {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] (i : ι) (f : Filter (α i)) [NeBot f] : (comap (eval i) f).NeBot := comap_eval_neBot_iff.2 ‹_› theorem comap_coe_neBot_of_le_principal {s : Set γ} {l : Filter γ} [h : NeBot l] (h' : l ≤ 𝓟 s) : NeBot (comap ((↑) : s → γ) l) := h.comap_of_range_mem <| (@Subtype.range_coe γ s).symm ▸ h' (mem_principal_self s) theorem NeBot.comap_of_surj {f : Filter β} {m : α → β} (hf : NeBot f) (hm : Surjective m) : NeBot (comap m f) := hf.comap_of_range_mem <| univ_mem' hm theorem NeBot.comap_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α} (hs : m '' s ∈ f) : NeBot (comap m f) := hf.comap_of_range_mem <| mem_of_superset hs (image_subset_range _ _) @[simp] theorem map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ := ⟨by rw [← empty_mem_iff_bot, ← empty_mem_iff_bot] exact id, fun h => by simp only [h, map_bot]⟩ theorem map_neBot_iff (f : α → β) {F : Filter α} : NeBot (map f F) ↔ NeBot F := by simp only [neBot_iff, Ne, map_eq_bot_iff] theorem NeBot.map (hf : NeBot f) (m : α → β) : NeBot (map m f) := (map_neBot_iff m).2 hf theorem NeBot.of_map : NeBot (f.map m) → NeBot f := (map_neBot_iff m).1 instance map_neBot [hf : NeBot f] : NeBot (f.map m) := hf.map m theorem sInter_comap_sets (f : α → β) (F : Filter β) : ⋂₀ (comap f F).sets = ⋂ U ∈ F, f ⁻¹' U := by ext x suffices (∀ (A : Set α) (B : Set β), B ∈ F → f ⁻¹' B ⊆ A → x ∈ A) ↔ ∀ B : Set β, B ∈ F → f x ∈ B by simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, mem_preimage, exists_imp] constructor · intro h U U_in simpa only [Subset.rfl, forall_prop_of_true, mem_preimage] using h (f ⁻¹' U) U U_in · intro h V U U_in f_U_V exact f_U_V (h U U_in) end Map -- this is a generic rule for monotone functions: theorem map_iInf_le {f : ι → Filter α} {m : α → β} : map m (iInf f) ≤ ⨅ i, map m (f i) := le_iInf fun _ => map_mono <| iInf_le _ _ theorem map_iInf_eq {f : ι → Filter α} {m : α → β} (hf : Directed (· ≥ ·) f) [Nonempty ι] : map m (iInf f) = ⨅ i, map m (f i) := map_iInf_le.antisymm fun s (hs : m ⁻¹' s ∈ iInf f) => let ⟨i, hi⟩ := (mem_iInf_of_directed hf _).1 hs have : ⨅ i, map m (f i) ≤ 𝓟 s := iInf_le_of_le i <| by simpa only [le_principal_iff, mem_map] Filter.le_principal_iff.1 this theorem map_biInf_eq {ι : Type w} {f : ι → Filter α} {m : α → β} {p : ι → Prop} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) { x | p x }) (ne : ∃ i, p i) : map m (⨅ (i) (_ : p i), f i) = ⨅ (i) (_ : p i), map m (f i) := by haveI := nonempty_subtype.2 ne simp only [iInf_subtype'] exact map_iInf_eq h.directed_val theorem map_inf_le {f g : Filter α} {m : α → β} : map m (f ⊓ g) ≤ map m f ⊓ map m g := (@map_mono _ _ m).map_inf_le f g theorem map_inf {f g : Filter α} {m : α → β} (h : Injective m) : map m (f ⊓ g) = map m f ⊓ map m g := by refine map_inf_le.antisymm ?_ rintro t ⟨s₁, hs₁, s₂, hs₂, ht : m ⁻¹' t = s₁ ∩ s₂⟩ refine mem_inf_of_inter (image_mem_map hs₁) (image_mem_map hs₂) ?_ rw [← image_inter h, image_subset_iff, ht] theorem map_inf' {f g : Filter α} {m : α → β} {t : Set α} (htf : t ∈ f) (htg : t ∈ g) (h : InjOn m t) : map m (f ⊓ g) = map m f ⊓ map m g := by lift f to Filter t using htf; lift g to Filter t using htg replace h : Injective (m ∘ ((↑) : t → α)) := h.injective simp only [map_map, ← map_inf Subtype.coe_injective, map_inf h] lemma disjoint_of_map {α β : Type*} {F G : Filter α} {f : α → β} (h : Disjoint (map f F) (map f G)) : Disjoint F G := disjoint_iff.mpr <| map_eq_bot_iff.mp <| le_bot_iff.mp <| trans map_inf_le (disjoint_iff.mp h) theorem disjoint_map {m : α → β} (hm : Injective m) {f₁ f₂ : Filter α} : Disjoint (map m f₁) (map m f₂) ↔ Disjoint f₁ f₂ := by simp only [disjoint_iff, ← map_inf hm, map_eq_bot_iff] theorem map_equiv_symm (e : α ≃ β) (f : Filter β) : map e.symm f = comap e f := map_injective e.injective <| by rw [map_map, e.self_comp_symm, map_id, map_comap_of_surjective e.surjective] theorem map_eq_comap_of_inverse {f : Filter α} {m : α → β} {n : β → α} (h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = comap n f := map_equiv_symm ⟨n, m, congr_fun h₁, congr_fun h₂⟩ f theorem comap_equiv_symm (e : α ≃ β) (f : Filter α) : comap e.symm f = map e f := (map_eq_comap_of_inverse e.self_comp_symm e.symm_comp_self).symm theorem map_swap_eq_comap_swap {f : Filter (α × β)} : map Prod.swap f = comap Prod.swap f := map_eq_comap_of_inverse Prod.swap_swap_eq Prod.swap_swap_eq /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_eq_comap {f : Filter ((α × β) × γ × δ)} : map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f = comap (fun p : (α × γ) × β × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f := map_eq_comap_of_inverse (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) theorem le_map {f : Filter α} {m : α → β} {g : Filter β} (h : ∀ s ∈ f, m '' s ∈ g) : g ≤ f.map m := fun _ hs => mem_of_superset (h _ hs) <| image_preimage_subset _ _ theorem le_map_iff {f : Filter α} {m : α → β} {g : Filter β} : g ≤ f.map m ↔ ∀ s ∈ f, m '' s ∈ g := ⟨fun h _ hs => h (image_mem_map hs), le_map⟩ protected theorem push_pull (f : α → β) (F : Filter α) (G : Filter β) : map f (F ⊓ comap f G) = map f F ⊓ G := by apply le_antisymm · calc map f (F ⊓ comap f G) ≤ map f F ⊓ (map f <| comap f G) := map_inf_le _ ≤ map f F ⊓ G := inf_le_inf_left (map f F) map_comap_le · rintro U ⟨V, V_in, W, ⟨Z, Z_in, hZ⟩, h⟩ apply mem_inf_of_inter (image_mem_map V_in) Z_in calc f '' V ∩ Z = f '' (V ∩ f ⁻¹' Z) := by rw [image_inter_preimage] _ ⊆ f '' (V ∩ W) := by gcongr _ = f '' (f ⁻¹' U) := by rw [h] _ ⊆ U := image_preimage_subset f U protected theorem push_pull' (f : α → β) (F : Filter α) (G : Filter β) : map f (comap f G ⊓ F) = G ⊓ map f F := by simp only [Filter.push_pull, inf_comm] theorem disjoint_comap_iff_map {f : α → β} {F : Filter α} {G : Filter β} : Disjoint F (comap f G) ↔ Disjoint (map f F) G := by simp only [disjoint_iff, ← Filter.push_pull, map_eq_bot_iff] theorem disjoint_comap_iff_map' {f : α → β} {F : Filter α} {G : Filter β} : Disjoint (comap f G) F ↔ Disjoint G (map f F) := by simp only [disjoint_iff, ← Filter.push_pull', map_eq_bot_iff] theorem neBot_inf_comap_iff_map {f : α → β} {F : Filter α} {G : Filter β} : NeBot (F ⊓ comap f G) ↔ NeBot (map f F ⊓ G) := by rw [← map_neBot_iff, Filter.push_pull] theorem neBot_inf_comap_iff_map' {f : α → β} {F : Filter α} {G : Filter β} : NeBot (comap f G ⊓ F) ↔ NeBot (G ⊓ map f F) := by rw [← map_neBot_iff, Filter.push_pull'] theorem comap_inf_principal_neBot_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α} (hs : m '' s ∈ f) : NeBot (comap m f ⊓ 𝓟 s) := by rw [neBot_inf_comap_iff_map', map_principal, ← frequently_mem_iff_neBot] exact Eventually.frequently hs theorem principal_eq_map_coe_top (s : Set α) : 𝓟 s = map ((↑) : s → α) ⊤ := by simp theorem inf_principal_eq_bot_iff_comap {F : Filter α} {s : Set α} : F ⊓ 𝓟 s = ⊥ ↔ comap ((↑) : s → α) F = ⊥ := by rw [principal_eq_map_coe_top s, ← Filter.push_pull', inf_top_eq, map_eq_bot_iff] lemma map_generate_le_generate_preimage_preimage (U : Set (Set β)) (f : β → α) : map f (generate U) ≤ generate ((f ⁻¹' ·) ⁻¹' U) := by rw [le_generate_iff] exact fun u hu ↦ mem_generate_of_mem hu lemma generate_image_preimage_le_comap (U : Set (Set α)) (f : β → α) : generate ((f ⁻¹' ·) '' U) ≤ comap f (generate U) := by rw [← map_le_iff_le_comap, le_generate_iff] exact fun u hu ↦ mem_generate_of_mem ⟨u, hu, rfl⟩ section Applicative theorem singleton_mem_pure {a : α} : {a} ∈ (pure a : Filter α) := mem_singleton a theorem pure_injective : Injective (pure : α → Filter α) := fun a _ hab => (Filter.ext_iff.1 hab { x | a = x }).1 rfl instance pure_neBot {α : Type u} {a : α} : NeBot (pure a) := ⟨mt empty_mem_iff_bot.2 <| notMem_empty a⟩ @[simp] theorem le_pure_iff {f : Filter α} {a : α} : f ≤ pure a ↔ {a} ∈ f := by rw [← principal_singleton, le_principal_iff] theorem mem_seq_def {f : Filter (α → β)} {g : Filter α} {s : Set β} : s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, ∀ x ∈ u, ∀ y ∈ t, (x : α → β) y ∈ s := Iff.rfl theorem mem_seq_iff {f : Filter (α → β)} {g : Filter α} {s : Set β} : s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, Set.seq u t ⊆ s := by simp only [mem_seq_def, seq_subset] theorem mem_map_seq_iff {f : Filter α} {g : Filter β} {m : α → β → γ} {s : Set γ} : s ∈ (f.map m).seq g ↔ ∃ t u, t ∈ g ∧ u ∈ f ∧ ∀ x ∈ u, ∀ y ∈ t, m x y ∈ s := Iff.intro (fun ⟨t, ht, s, hs, hts⟩ => ⟨s, m ⁻¹' t, hs, ht, fun _ => hts _⟩) fun ⟨t, s, ht, hs, hts⟩ => ⟨m '' s, image_mem_map hs, t, ht, fun _ ⟨_, has, Eq⟩ => Eq ▸ hts _ has⟩ theorem seq_mem_seq {f : Filter (α → β)} {g : Filter α} {s : Set (α → β)} {t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s.seq t ∈ f.seq g := ⟨s, hs, t, ht, fun f hf a ha => ⟨f, hf, a, ha, rfl⟩⟩ theorem le_seq {f : Filter (α → β)} {g : Filter α} {h : Filter β} (hh : ∀ t ∈ f, ∀ u ∈ g, Set.seq t u ∈ h) : h ≤ seq f g := fun _ ⟨_, ht, _, hu, hs⟩ => mem_of_superset (hh _ ht _ hu) fun _ ⟨_, hm, _, ha, eq⟩ => eq ▸ hs _ hm _ ha @[mono] theorem seq_mono {f₁ f₂ : Filter (α → β)} {g₁ g₂ : Filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.seq g₁ ≤ f₂.seq g₂ := le_seq fun _ hs _ ht => seq_mem_seq (hf hs) (hg ht) @[simp] theorem pure_seq_eq_map (g : α → β) (f : Filter α) : seq (pure g) f = f.map g := by refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_) · rw [← singleton_seq] apply seq_mem_seq _ hs exact singleton_mem_pure · refine sets_of_superset (map g f) (image_mem_map ht) ?_ rintro b ⟨a, ha, rfl⟩ exact ⟨g, hs, a, ha, rfl⟩ @[simp] theorem seq_pure (f : Filter (α → β)) (a : α) : seq f (pure a) = map (fun g : α → β => g a) f := by refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_) · rw [← seq_singleton] exact seq_mem_seq hs singleton_mem_pure · refine sets_of_superset (map (fun g : α → β => g a) f) (image_mem_map hs) ?_ rintro b ⟨g, hg, rfl⟩ exact ⟨g, hg, a, ht, rfl⟩ @[simp] theorem seq_assoc (x : Filter α) (g : Filter (α → β)) (h : Filter (β → γ)) : seq h (seq g x) = seq (seq (map (· ∘ ·) h) g) x := by refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_) · rcases mem_seq_iff.1 hs with ⟨u, hu, v, hv, hs⟩ rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hu⟩ refine mem_of_superset ?_ (Set.seq_mono ((Set.seq_mono hu Subset.rfl).trans hs) Subset.rfl) rw [← Set.seq_seq] exact seq_mem_seq hw (seq_mem_seq hv ht) · rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩ refine mem_of_superset ?_ (Set.seq_mono Subset.rfl ht) rw [Set.seq_seq] exact seq_mem_seq (seq_mem_seq (image_mem_map hs) hu) hv theorem prod_map_seq_comm (f : Filter α) (g : Filter β) : (map Prod.mk f).seq g = seq (map (fun b a => (a, b)) g) f := by refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_) · rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩ refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl) rw [← Set.prod_image_seq_comm] exact seq_mem_seq (image_mem_map ht) hu · rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩ refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl) rw [Set.prod_image_seq_comm] exact seq_mem_seq (image_mem_map ht) hu theorem seq_eq_filter_seq {α β : Type u} (f : Filter (α → β)) (g : Filter α) : f <*> g = seq f g := rfl instance : LawfulApplicative (Filter : Type u → Type u) where map_pure := map_pure seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl seq_pure := seq_pure pure_seq := pure_seq_eq_map seq_assoc := seq_assoc instance : CommApplicative (Filter : Type u → Type u) := ⟨fun f g => prod_map_seq_comm f g⟩ end Applicative /-! #### `bind` equations -/ section Bind @[simp] theorem eventually_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} : (∀ᶠ y in bind f m, p y) ↔ ∀ᶠ x in f, ∀ᶠ y in m x, p y := Iff.rfl @[simp] theorem frequently_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} : (∃ᶠ y in bind f m, p y) ↔ ∃ᶠ x in f, ∃ᶠ y in m x, p y := by rw [← not_iff_not] simp only [not_frequently, eventually_bind] @[simp] theorem eventuallyEq_bind {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} : g₁ =ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ =ᶠ[m x] g₂ := Iff.rfl @[simp] theorem eventuallyLE_bind [LE γ] {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} : g₁ ≤ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ ≤ᶠ[m x] g₂ := Iff.rfl theorem mem_bind' {s : Set β} {f : Filter α} {m : α → Filter β} : s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl @[simp] theorem mem_bind {s : Set β} {f : Filter α} {m : α → Filter β} : s ∈ bind f m ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := calc s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl _ ↔ ∃ t ∈ f, t ⊆ { a | s ∈ m a } := exists_mem_subset_iff.symm _ ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := Iff.rfl theorem bind_le {f : Filter α} {g : α → Filter β} {l : Filter β} (h : ∀ᶠ x in f, g x ≤ l) : f.bind g ≤ l := join_le <| eventually_map.2 h @[mono] theorem bind_mono {f₁ f₂ : Filter α} {g₁ g₂ : α → Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ᶠ[f₁] g₂) : bind f₁ g₁ ≤ bind f₂ g₂ := by refine le_trans (fun s hs => ?_) (join_mono <| map_mono hf) simp only [mem_join, mem_bind', mem_map] at hs ⊢ filter_upwards [hg, hs] with _ hx hs using hx hs theorem bind_inf_principal {f : Filter α} {g : α → Filter β} {s : Set β} : (f.bind fun x => g x ⊓ 𝓟 s) = f.bind g ⊓ 𝓟 s := Filter.ext fun s => by simp only [mem_bind, mem_inf_principal] theorem sup_bind {f g : Filter α} {h : α → Filter β} : bind (f ⊔ g) h = bind f h ⊔ bind g h := rfl theorem principal_bind {s : Set α} {f : α → Filter β} : bind (𝓟 s) f = ⨆ x ∈ s, f x := show join (map f (𝓟 s)) = ⨆ x ∈ s, f x by simp only [sSup_image, join_principal_eq_sSup, map_principal] end Bind end Filter open Filter variable {α β : Type*} {F : Filter α} {G : Filter β} -- TODO(Anatole): unify with the global case theorem Filter.map_surjOn_Iic_iff_le_map {m : α → β} : SurjOn (map m) (Iic F) (Iic G) ↔ G ≤ map m F := by refine ⟨fun hm ↦ ?_, fun hm ↦ ?_⟩ · rcases hm right_mem_Iic with ⟨H, (hHF : H ≤ F), rfl⟩ exact map_mono hHF · have : RightInvOn (F ⊓ comap m ·) (map m) (Iic G) := fun H (hHG : H ≤ G) ↦ by simpa [Filter.push_pull] using hHG.trans hm exact this.surjOn fun H _ ↦ mem_Iic.mpr inf_le_left theorem Filter.map_surjOn_Iic_iff_surjOn {s : Set α} {t : Set β} {m : α → β} : SurjOn (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 t) ↔ SurjOn m s t := by rw [map_surjOn_Iic_iff_le_map, map_principal, principal_mono, SurjOn] alias ⟨_, Set.SurjOn.filter_map_Iic⟩ := Filter.map_surjOn_Iic_iff_surjOn theorem Filter.filter_injOn_Iic_iff_injOn {s : Set α} {m : α → β} : InjOn (map m) (Iic <| 𝓟 s) ↔ InjOn m s := by refine ⟨fun hm x hx y hy hxy ↦ ?_, fun hm F hF G hG ↦ ?_⟩ · rwa [← pure_injective.eq_iff, ← map_pure, ← map_pure, hm.eq_iff, pure_injective.eq_iff] at hxy <;> rwa [mem_Iic, pure_le_principal] · simp [map_eq_map_iff_of_injOn (le_principal_iff.mp hF) (le_principal_iff.mp hG) hm] alias ⟨_, Set.InjOn.filter_map_Iic⟩ := Filter.filter_injOn_Iic_iff_injOn
.lake/packages/mathlib/Mathlib/Order/Filter/Pi.lean
import Mathlib.Data.Set.Piecewise import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Filter.Bases.Finite /-! # (Co)product of a family of filters In this file we define two filters on `Π i, α i` and prove some basic properties of these filters. * `Filter.pi (f : Π i, Filter (α i))` to be the maximal filter on `Π i, α i` such that `∀ i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as `Π i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed products. * `Filter.coprodᵢ (f : Π i, Filter (α i))`: a generalization of `Filter.coprod`; it is the supremum of `comap (eval i) (f i)`. -/ open Set Function Filter namespace Filter variable {ι : Type*} {α : ι → Type*} {f f₁ f₂ : (i : ι) → Filter (α i)} {s : (i : ι) → Set (α i)} {p : ∀ i, α i → Prop} section Pi theorem tendsto_eval_pi (f : ∀ i, Filter (α i)) (i : ι) : Tendsto (eval i) (pi f) (f i) := tendsto_iInf' i tendsto_comap theorem tendsto_pi {β : Type*} {m : β → ∀ i, α i} {l : Filter β} : Tendsto m l (pi f) ↔ ∀ i, Tendsto (fun x => m x i) l (f i) := by simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl /-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to `f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a product of topological spaces. -/ alias ⟨Tendsto.apply, _⟩ := tendsto_pi theorem le_pi {g : Filter (∀ i, α i)} : g ≤ pi f ↔ ∀ i, Tendsto (eval i) g (f i) := tendsto_pi @[mono] theorem pi_mono (h : ∀ i, f₁ i ≤ f₂ i) : pi f₁ ≤ pi f₂ := iInf_mono fun i => comap_mono <| h i theorem mem_pi_of_mem (i : ι) {s : Set (α i)} (hs : s ∈ f i) : eval i ⁻¹' s ∈ pi f := mem_iInf_of_mem i <| preimage_mem_comap hs theorem pi_mem_pi {I : Set ι} (hI : I.Finite) (h : ∀ i ∈ I, s i ∈ f i) : I.pi s ∈ pi f := by rw [pi_def, biInter_eq_iInter] refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl exact preimage_mem_comap (h i i.2) theorem mem_pi {s : Set (∀ i, α i)} : s ∈ pi f ↔ ∃ I : Set ι, I.Finite ∧ ∃ t : ∀ i, Set (α i), (∀ i, t i ∈ f i) ∧ I.pi t ⊆ s := by constructor · simp only [pi, mem_iInf', mem_comap, pi_def] rintro ⟨I, If, V, hVf, -, rfl, -⟩ choose t htf htV using hVf exact ⟨I, If, t, htf, iInter₂_mono fun i _ => htV i⟩ · rintro ⟨I, If, t, htf, hts⟩ exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts theorem mem_pi' {s : Set (∀ i, α i)} : s ∈ pi f ↔ ∃ I : Finset ι, ∃ t : ∀ i, Set (α i), (∀ i, t i ∈ f i) ∧ Set.pi (↑I) t ⊆ s := mem_pi.trans exists_finite_iff_finset theorem mem_of_pi_mem_pi [∀ i, NeBot (f i)] {I : Set ι} (h : I.pi s ∈ pi f) {i : ι} (hi : i ∈ I) : s i ∈ f i := by classical rcases mem_pi.1 h with ⟨I', -, t, htf, hts⟩ refine mem_of_superset (htf i) fun x hx => ?_ have : ∀ i, (t i).Nonempty := fun i => nonempty_of_mem (htf i) choose g hg using this have : update g i x ∈ I'.pi t := fun j _ => by rcases eq_or_ne j i with (rfl | hne) <;> simp [*] simpa using hts this i hi @[simp] theorem pi_mem_pi_iff [∀ i, NeBot (f i)] {I : Set ι} (hI : I.Finite) : I.pi s ∈ pi f ↔ ∀ i ∈ I, s i ∈ f i := ⟨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hI⟩ theorem Eventually.eval_pi {i : ι} (hf : ∀ᶠ x : α i in f i, p i x) : ∀ᶠ x : ∀ i : ι, α i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf theorem eventually_pi [Finite ι] (hf : ∀ i, ∀ᶠ x in f i, p i x) : ∀ᶠ x : ∀ i, α i in pi f, ∀ i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi theorem hasBasis_pi {ι' : ι → Type*} {s : ∀ i, ι' i → Set (α i)} {p : ∀ i, ι' i → Prop} (h : ∀ i, (f i).HasBasis (p i) (s i)) : (pi f).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i)) fun If : Set ι × ∀ i, ι' i => If.1.pi fun i => s i <| If.2 i := by simpa [Set.pi_def] using HasBasis.iInf' fun i => (h i).comap (eval i : (∀ j, α j) → α i) theorem hasBasis_pi_same_index {κ : Type*} {p : κ → Prop} {s : Π i : ι, κ → Set (α i)} (h : ∀ i : ι, (f i).HasBasis p (s i)) (h_dir : ∀ I : Set ι, ∀ k : ι → κ, I.Finite → (∀ i ∈ I, p (k i)) → ∃ k₀, p k₀ ∧ ∀ i ∈ I, s i k₀ ⊆ s i (k i)) : (pi f).HasBasis (fun Ik : Set ι × κ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun i ↦ s i Ik.2)) := by refine hasBasis_pi h |>.to_hasBasis ?_ ?_ · rintro ⟨I, k⟩ ⟨hI, hk⟩ rcases h_dir I k hI hk with ⟨k₀, hk₀, hk₀'⟩ exact ⟨⟨I, k₀⟩, ⟨hI, hk₀⟩, Set.pi_mono hk₀'⟩ · rintro ⟨I, k⟩ ⟨hI, hk⟩ exact ⟨⟨I, fun _ ↦ k⟩, ⟨hI, fun _ _ ↦ hk⟩, subset_rfl⟩ theorem HasBasis.pi_self {α : Type*} {κ : Type*} {f : Filter α} {p : κ → Prop} {s : κ → Set α} (h : f.HasBasis p s) : (pi fun _ ↦ f).HasBasis (fun Ik : Set ι × κ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun _ ↦ s Ik.2)) := by refine hasBasis_pi_same_index (fun _ ↦ h) (fun I k hI hk ↦ ?_) rcases h.mem_iff.mp (biInter_mem hI |>.mpr fun i hi ↦ h.mem_of_mem (hk i hi)) with ⟨k₀, hk₀, hk₀'⟩ exact ⟨k₀, hk₀, fun i hi ↦ hk₀'.trans (biInter_subset_of_mem hi)⟩ theorem le_pi_principal (s : (i : ι) → Set (α i)) : 𝓟 (univ.pi s) ≤ pi fun i ↦ 𝓟 (s i) := le_pi.2 fun i ↦ tendsto_principal_principal.2 fun _f hf ↦ hf i trivial /-- The indexed product of finitely many principal filters is the principal filter corresponding to the cylinder `Set.univ.pi s`. If the index type is infinite, then `mem_pi_principal` and `hasBasis_pi_principal` may be useful. -/ @[simp] theorem pi_principal [Finite ι] (s : (i : ι) → Set (α i)) : pi (fun i ↦ 𝓟 (s i)) = 𝓟 (univ.pi s) := by simp [Filter.pi, Set.pi_def] /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a principal filter, see `pi_principal`. -/ theorem mem_pi_principal {t : Set ((i : ι) → α i)} : t ∈ pi (fun i ↦ 𝓟 (s i)) ↔ ∃ I : Set ι, I.Finite ∧ I.pi s ⊆ t := (hasBasis_pi (fun i ↦ hasBasis_principal _)).mem_iff.trans <| by simp /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a principal filter, see `pi_principal`. -/ theorem hasBasis_pi_principal (s : (i : ι) → Set (α i)) : HasBasis (pi fun i ↦ 𝓟 (s i)) Set.Finite (Set.pi · s) := ⟨fun _ ↦ mem_pi_principal⟩ /-- The indexed product of finitely many pure filters `pure (f i)` is the pure filter `pure f`. If the index type is infinite, then `mem_pi_pure` and `hasBasis_pi_pure` below may be useful. -/ @[simp] theorem pi_pure [Finite ι] (f : (i : ι) → α i) : pi (pure <| f ·) = pure f := by simp only [← principal_singleton, pi_principal, univ_pi_singleton] /-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)` is generated by the sets of functions that are equal to `f` on a finite set. If the index type is finite, then the indexed product of pure filters is a pure filter, see `pi_pure`. -/ theorem mem_pi_pure {f : (i : ι) → α i} {s : Set ((i : ι) → α i)} : s ∈ pi (fun i ↦ pure (f i)) ↔ ∃ I : Set ι, I.Finite ∧ ∀ g, (∀ i ∈ I, g i = f i) → g ∈ s := by simp only [← principal_singleton, mem_pi_principal] simp [subset_def] /-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)` is generated by the sets of functions that are equal to `f` on a finite set. If the index type is finite, then the indexed product of pure filters is a pure filter, see `pi_pure`. -/ theorem hasBasis_pi_pure (f : (i : ι) → α i) : HasBasis (pi fun i ↦ pure (f i)) Set.Finite (fun I ↦ {g | ∀ i ∈ I, g i = f i}) := ⟨fun _ ↦ mem_pi_pure⟩ @[simp] theorem pi_inf_principal_univ_pi_eq_bot : pi f ⊓ 𝓟 (Set.pi univ s) = ⊥ ↔ ∃ i, f i ⊓ 𝓟 (s i) = ⊥ := by constructor · simp only [inf_principal_eq_bot, mem_pi] contrapose! rintro (hsf : ∀ i, ∃ᶠ x in f i, x ∈ s i) I - t htf hts have : ∀ i, (s i ∩ t i).Nonempty := fun i => ((hsf i).and_eventually (htf i)).exists choose x hxs hxt using this exact hts (fun i _ => hxt i) (mem_univ_pi.2 hxs) · simp only [inf_principal_eq_bot] rintro ⟨i, hi⟩ filter_upwards [mem_pi_of_mem i hi] with x using mt fun h => h i trivial @[simp] theorem pi_inf_principal_pi_eq_bot [∀ i, NeBot (f i)] {I : Set ι} : pi f ⊓ 𝓟 (Set.pi I s) = ⊥ ↔ ∃ i ∈ I, f i ⊓ 𝓟 (s i) = ⊥ := by classical rw [← univ_pi_piecewise_univ I, pi_inf_principal_univ_pi_eq_bot] refine exists_congr fun i => ?_ by_cases hi : i ∈ I <;> simp [hi, NeBot.ne'] @[simp] theorem pi_inf_principal_univ_pi_neBot : NeBot (pi f ⊓ 𝓟 (Set.pi univ s)) ↔ ∀ i, NeBot (f i ⊓ 𝓟 (s i)) := by simp [neBot_iff] @[simp] theorem pi_inf_principal_pi_neBot [∀ i, NeBot (f i)] {I : Set ι} : NeBot (pi f ⊓ 𝓟 (I.pi s)) ↔ ∀ i ∈ I, NeBot (f i ⊓ 𝓟 (s i)) := by simp [neBot_iff] instance PiInfPrincipalPi.neBot [h : ∀ i, NeBot (f i ⊓ 𝓟 (s i))] {I : Set ι} : NeBot (pi f ⊓ 𝓟 (I.pi s)) := (pi_inf_principal_univ_pi_neBot.2 ‹_›).mono <| inf_le_inf_left _ <| principal_mono.2 fun _ hx i _ => hx i trivial @[simp] theorem pi_eq_bot : pi f = ⊥ ↔ ∃ i, f i = ⊥ := by simpa using @pi_inf_principal_univ_pi_eq_bot ι α f fun _ => univ @[simp] theorem pi_neBot : NeBot (pi f) ↔ ∀ i, NeBot (f i) := by simp [neBot_iff] instance [∀ i, NeBot (f i)] : NeBot (pi f) := pi_neBot.2 ‹_› @[simp] theorem map_eval_pi (f : ∀ i, Filter (α i)) [∀ i, NeBot (f i)] (i : ι) : map (eval i) (pi f) = f i := by refine le_antisymm (tendsto_eval_pi f i) fun s hs => ?_ rcases mem_pi.1 (mem_map.1 hs) with ⟨I, hIf, t, htf, hI⟩ rw [← image_subset_iff] at hI refine mem_of_superset (htf i) ((subset_eval_image_pi ?_ _).trans hI) exact nonempty_of_mem (pi_mem_pi hIf fun i _ => htf i) @[simp] theorem pi_le_pi [∀ i, NeBot (f₁ i)] : pi f₁ ≤ pi f₂ ↔ ∀ i, f₁ i ≤ f₂ i := ⟨fun h i => map_eval_pi f₁ i ▸ (tendsto_eval_pi _ _).mono_left h, pi_mono⟩ @[simp] theorem pi_inj [∀ i, NeBot (f₁ i)] : pi f₁ = pi f₂ ↔ f₁ = f₂ := by refine ⟨fun h => ?_, congr_arg pi⟩ have hle : f₁ ≤ f₂ := pi_le_pi.1 h.le haveI : ∀ i, NeBot (f₂ i) := fun i => neBot_of_le (hle i) exact hle.antisymm (pi_le_pi.1 h.ge) theorem tendsto_piMap_pi {β : ι → Type*} {f : ∀ i, α i → β i} {l : ∀ i, Filter (α i)} {l' : ∀ i, Filter (β i)} (h : ∀ i, Tendsto (f i) (l i) (l' i)) : Tendsto (Pi.map f) (pi l) (pi l') := tendsto_pi.2 fun i ↦ (h i).comp (tendsto_eval_pi _ _) theorem pi_comap {β : ι → Type*} {f : ∀ i, α i → β i} {l : ∀ i, Filter (β i)} : pi (fun i ↦ comap (f i) (l i)) = comap (Pi.map f) (pi l) := by simp [Filter.pi, Filter.comap_comap, Function.comp_def] end Pi /-! ### `n`-ary coproducts of filters -/ section CoprodCat -- for "Coprod" /-- Coproduct of filters. -/ protected def coprodᵢ (f : ∀ i, Filter (α i)) : Filter (∀ i, α i) := ⨆ i : ι, comap (eval i) (f i) theorem mem_coprodᵢ_iff {s : Set (∀ i, α i)} : s ∈ Filter.coprodᵢ f ↔ ∀ i : ι, ∃ t₁ ∈ f i, eval i ⁻¹' t₁ ⊆ s := by simp [Filter.coprodᵢ] theorem compl_mem_coprodᵢ {s : Set (∀ i, α i)} : sᶜ ∈ Filter.coprodᵢ f ↔ ∀ i, (eval i '' s)ᶜ ∈ f i := by simp only [Filter.coprodᵢ, mem_iSup, compl_mem_comap] theorem coprodᵢ_neBot_iff' : NeBot (Filter.coprodᵢ f) ↔ (∀ i, Nonempty (α i)) ∧ ∃ d, NeBot (f d) := by simp only [Filter.coprodᵢ, iSup_neBot, ← exists_and_left, ← comap_eval_neBot_iff'] @[simp] theorem coprodᵢ_neBot_iff [∀ i, Nonempty (α i)] : NeBot (Filter.coprodᵢ f) ↔ ∃ d, NeBot (f d) := by simp [coprodᵢ_neBot_iff', *] theorem coprodᵢ_eq_bot_iff' : Filter.coprodᵢ f = ⊥ ↔ (∃ i, IsEmpty (α i)) ∨ f = ⊥ := by simpa only [not_neBot, not_and_or, funext_iff, not_forall, not_exists, not_nonempty_iff] using coprodᵢ_neBot_iff'.not @[simp] theorem coprodᵢ_eq_bot_iff [∀ i, Nonempty (α i)] : Filter.coprodᵢ f = ⊥ ↔ f = ⊥ := by simpa [funext_iff] using coprodᵢ_neBot_iff.not @[simp] theorem coprodᵢ_bot' : Filter.coprodᵢ (⊥ : ∀ i, Filter (α i)) = ⊥ := coprodᵢ_eq_bot_iff'.2 (Or.inr rfl) @[simp] theorem coprodᵢ_bot : Filter.coprodᵢ (fun _ => ⊥ : ∀ i, Filter (α i)) = ⊥ := coprodᵢ_bot' theorem NeBot.coprodᵢ [∀ i, Nonempty (α i)] {i : ι} (h : NeBot (f i)) : NeBot (Filter.coprodᵢ f) := coprodᵢ_neBot_iff.2 ⟨i, h⟩ @[instance] theorem coprodᵢ_neBot [∀ i, Nonempty (α i)] [Nonempty ι] (f : ∀ i, Filter (α i)) [H : ∀ i, NeBot (f i)] : NeBot (Filter.coprodᵢ f) := (H (Classical.arbitrary ι)).coprodᵢ @[mono] theorem coprodᵢ_mono (hf : ∀ i, f₁ i ≤ f₂ i) : Filter.coprodᵢ f₁ ≤ Filter.coprodᵢ f₂ := iSup_mono fun i => comap_mono (hf i) variable {β : ι → Type*} {m : ∀ i, α i → β i} theorem map_pi_map_coprodᵢ_le : map (fun k : ∀ i, α i => fun i => m i (k i)) (Filter.coprodᵢ f) ≤ Filter.coprodᵢ fun i => map (m i) (f i) := by simp only [le_def, mem_map, mem_coprodᵢ_iff] intro s h i obtain ⟨t, H, hH⟩ := h i exact ⟨{ x : α i | m i x ∈ t }, H, fun x hx => hH hx⟩ theorem Tendsto.pi_map_coprodᵢ {g : ∀ i, Filter (β i)} (h : ∀ i, Tendsto (m i) (f i) (g i)) : Tendsto (fun k : ∀ i, α i => fun i => m i (k i)) (Filter.coprodᵢ f) (Filter.coprodᵢ g) := map_pi_map_coprodᵢ_le.trans (coprodᵢ_mono h) end CoprodCat end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Basic.lean
import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Data.Set.Lattice import Mathlib.Order.Filter.Defs /-! # Theory of filters on sets A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... ## Main definitions In this file, we endow `Filter α` it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). ## Notation * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ assert_not_exists IsOrderedRing Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ @[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl @[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where trans h₁ h₂ := mem_of_superset h₁ h₂ @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem /-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by apply Subsingleton.induction_on hf <;> simp /-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range] theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ @[deprecated forall_swap (since := "2025-06-10")] theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := by tauto end Filter namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl theorem eventually_mem_principal (s : Set α) : ∀ᶠ x in 𝓟 s, x ∈ s := mem_principal_self s section Lattice variable {f g : Filter α} {s t : Set α} protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ section CompleteLattice /-- Complete lattice structure on `Filter α`. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) where inf a b := min a b sup a b := max a b le_sup_left _ _ _ h := h.1 le_sup_right _ _ _ h := h.2 sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩ inf_le_left _ _ _ := mem_inf_of_left inf_le_right _ _ _ := mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) le_sSup _ _ h₁ _ h₂ := h₂ h₁ sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂ sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂ le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁ le_top _ _ := univ_mem' bot_le _ _ _ := trivial instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter] @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff] theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, mem_principal] @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top] @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs @[simp] theorem empty_notMem (f : Filter α) [NeBot f] : ∅ ∉ f := fun h => (nonempty_of_mem h).ne_empty rfl @[deprecated (since := "2025-05-23")] alias empty_not_mem := empty_notMem theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := Exists.nonempty <| nonempty_of_mem (univ_mem : univ ∈ f) theorem compl_notMem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s @[deprecated (since := "2025-05-23")] alias compl_not_mem := compl_notMem theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) := forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty] instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion congr_arg Filter.sets this.symm theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs /-! ### Eventually -/ theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (Eventually.of_forall hq) @[gcongr] theorem GCongr.eventually_mono {p q : α → Prop} {f : Filter α} (h : ∀ x, p x → q x) : (∀ᶠ x in f, p x) → ∀ᶠ x in f, q x := (·.mono h) theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or_distrib_left] @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} : (∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where mp h _ := by filter_upwards [h] with _ pa _ using pa mpr h := by filter_upwards [h univ] with _ pa using pa (by simp) /-! ### Frequently -/ theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_notMem h theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (Eventually.of_forall h) theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) : (∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x := ⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩ theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (Eventually.of_forall hpq) @[gcongr] theorem GCongr.frequently_mono {p q : α → Prop} {f : Filter α} (h : ∀ x, p x → q x) : (∃ᶠ x in f, p x) → ∃ᶠ x in f, q x := (·.mono h) theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H) exact hp H theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl @[simp] theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by simp [Filter.Frequently] @[simp] theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by simp only [Filter.Frequently, not_not] @[simp] theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by simp [frequently_iff_neBot] @[simp] theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp @[simp] theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by by_cases p <;> simp [*] @[simp] theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and] theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by simp [imp_iff_not_or] theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib] theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by simp only [frequently_imp_distrib, frequently_const] theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently] @[simp] theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp] @[simp] theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by simp only [@and_comm _ q, frequently_and_distrib_left] @[simp] theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp @[simp] theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently] @[simp] theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by simp [Filter.Frequently, not_forall] theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} : (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by simp only [Filter.Frequently, eventually_inf_principal, not_and] alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal theorem frequently_sup {p : α → Prop} {f g : Filter α} : (∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by simp only [Filter.Frequently, eventually_sup, not_and_or] @[simp] theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} : (∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop] @[simp] theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} : (∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by simp only [Filter.Frequently, eventually_iSup, not_forall] theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) := by haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty choose! f hf using fun x (hx : ∃ y, r x y) => hx exact ⟨f, h.mono hf⟩ lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)] {P : ∀ i : ι, α i → Prop} {F : Filter ι} : (∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by classical refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩ refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩ filter_upwards [H] with i hi exact dif_pos hi ▸ hi.choose_spec /-! ### Relation “eventually equal” -/ section EventuallyEq variable {l : Filter α} {f g : α → β} theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h @[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff] theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop) (hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) := hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t := eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set @[simp] theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by simp [eventuallyEq_set] theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∃ s ∈ l, EqOn f g s := Eventually.exists_mem h theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) : f =ᶠ[l] g := eventually_of_mem hs h theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s := eventually_iff_exists_mem theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) : f =ᶠ[l'] g := h₂ h₁ @[refl, simp] theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f := Eventually.of_forall fun _ => rfl protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f := EventuallyEq.refl l f theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq @[symm] theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f := H.mono fun _ => Eq.symm lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩ @[trans] theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f =ᶠ[l] h := H₂.rw (fun x y => f x = y) H₁ theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) : f =ᶠ[l] h ↔ g =ᶠ[l] h := ⟨H.symm.trans, H.trans⟩ theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) : f =ᶠ[l] g ↔ f =ᶠ[l] h := ⟨(·.trans H), (·.trans H.symm)⟩ instance {l : Filter α} : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where trans := EventuallyEq.trans theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') : (fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) := hf.mp <| hg.mono <| by intros simp only [*] -- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t. -- composition on the right. theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) : h ∘ f =ᶠ[l] h ∘ g := H.mono fun _ hx => congr_arg h hx theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ) (Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) := (Hf.prodMk Hg).fun_comp (uncurry h) @[to_additive (attr := gcongr)] theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : f * f' =ᶠ[l] g * g' := h.comp₂ (· * ·) h' @[to_additive] theorem EventuallyEq.fun_mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x := h.mul h' @[to_additive] lemma EventuallyEq.mul_left [Mul β] {f₁ f₂ f₃ : α → β} (h : f₁ =ᶠ[l] f₂) : f₃ * f₁ =ᶠ[l] f₃ * f₂ := EventuallyEq.mul (by rfl) h @[to_additive] lemma EventuallyEq.mul_right [Mul β] {f₁ f₂ f₃ : α → β} (h : f₁ =ᶠ[l] f₂) : f₁ * f₃ =ᶠ[l] f₂ * f₃ := EventuallyEq.mul h (by rfl) @[to_additive (attr := gcongr, to_additive) const_smul] theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) : f ^ c =ᶠ[l] g ^ c := h.fun_comp (· ^ c) @[to_additive (attr := to_additive) fun_const_smul] theorem EventuallyEq.fun_pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) : (fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c := h.pow_const c @[to_additive (attr := gcongr)] theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : f⁻¹ =ᶠ[l] g⁻¹ := h.fun_comp Inv.inv @[to_additive] theorem EventuallyEq.fun_inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : (fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ := h.inv @[to_additive (attr := gcongr)] theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : f / f' =ᶠ[l] g / g' := h.comp₂ (· / ·) h' @[to_additive] theorem EventuallyEq.fun_div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x := h.div h' @[to_additive] theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x := hf.comp₂ (· • ·) hg protected theorem EventuallyEq.fun_star {R : Type*} [Star R] {f g : α → R} {l : Filter α} (h : f =ᶠ[l] g) : (fun x ↦ star (f x)) =ᶠ[l] fun x ↦ star (g x) := h.fun_comp Star.star @[gcongr] protected theorem EventuallyEq.star {R : Type*} [Star R] {f g : α → R} {l : Filter α} (h : f =ᶠ[l] g) : star f =ᶠ[l] star g := h.fun_comp Star.star @[gcongr] theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ⊔ g =ᶠ[l] f' ⊔ g' := hf.comp₂ (· ⊔ ·) hg @[gcongr] theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ⊓ g =ᶠ[l] f' ⊓ g' := hf.comp₂ (· ⊓ ·) hg @[gcongr] theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) : f ⁻¹' s =ᶠ[l] g ⁻¹' s := h.fun_comp s @[gcongr] theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) := h.comp₂ (· ∧ ·) h' @[gcongr] theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) := h.comp₂ (· ∨ ·) h' @[gcongr] theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) : (sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) := h.fun_comp Not @[gcongr] theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) := h.inter h'.compl @[gcongr] protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) := (h.diff h').union (h'.diff h) theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s := eventuallyEq_set.trans <| by simp theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp] theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by rw [inter_comm, inter_eventuallyEq_left] @[simp] theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s := Iff.rfl theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} : f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x := eventually_inf_principal theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 := ⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩ theorem eventuallyEq_iff_all_subsets {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x = g x := eventually_iff_all_subsets section LE variable [LE β] {l : Filter α} theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f' ≤ᶠ[l] g' := H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' := ⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩ theorem eventuallyLE_iff_all_subsets {f g : α → β} {l : Filter α} : f ≤ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x ≤ g x := eventually_iff_all_subsets end LE section Preorder variable [Preorder β] {l : Filter α} {f g h : α → β} theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g := h.mono fun _ => le_of_eq @[refl] theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f := EventuallyEq.rfl.le theorem EventuallyLE.rfl : f ≤ᶠ[l] f := EventuallyLE.refl l f @[trans] theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₂.mp <| H₁.mono fun _ => le_trans instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans @[trans] theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₁.le.trans H₂ instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyEq.trans_le @[trans] theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h := H₁.trans H₂.le instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans_eq end Preorder variable {l : Filter α} theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g) (h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g := h₂.mp <| h₁.mono fun _ => le_antisymm theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and] theorem EventuallyLE.ge_iff_eq' [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) : g ≤ᶠ[l] f ↔ g =ᶠ[l] f := ⟨fun h' => h'.antisymm h, EventuallyEq.le⟩ @[deprecated (since := "2025-07-10")] alias EventuallyLE.le_iff_eq := EventuallyLE.ge_iff_eq' theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ g x := h.mono fun _ hx => hx.ne theorem Eventually.ne_top_of_lt [Preorder β] [OrderTop β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ := h.mono fun _ hx => hx.ne_top theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} (h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ := h.mono fun _ hx => hx.lt_top theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} : (∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ := ⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩ @[mono] theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) := h'.mp <| h.mono fun _ => And.imp @[mono] theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) := h'.mp <| h.mono fun _ => Or.imp @[mono] theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) : (tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) := h.mono fun _ => mt @[mono] theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') : (s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) := h.inter h'.compl theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s := eventually_inf_principal.symm theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t := set_eventuallyLE_iff_mem_inf_principal.trans <| by simp only [le_inf_iff, inf_le_left, true_and, le_principal_iff] theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le] theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h) (hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g := hf.mono fun _ => _root_.le_sup_of_le_left theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g := hg.mono fun _ => _root_.le_sup_of_le_right theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l := fun _ hs => h.mono fun _ hm => hm hs end EventuallyEq end Filter open Filter theorem Set.EqOn.eventuallyEq {α β} {s : Set α} {f g : α → β} (h : EqOn f g s) : f =ᶠ[𝓟 s] g := h theorem Set.EqOn.eventuallyEq_of_mem {α β} {s : Set α} {l : Filter α} {f g : α → β} (h : EqOn f g s) (hl : s ∈ l) : f =ᶠ[l] g := h.eventuallyEq.filter_mono <| Filter.le_principal_iff.2 hl theorem HasSubset.Subset.eventuallyLE {α} {l : Filter α} {s t : Set α} (h : s ⊆ t) : s ≤ᶠ[l] t := Filter.Eventually.of_forall h variable {α β : Type*} {F : Filter α} {G : Filter β} namespace Filter lemma compl_mem_comk {p : Set α → Prop} {he hmono hunion s} : sᶜ ∈ comk p he hmono hunion ↔ p s := by simp end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/IsBounded.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Basic import Mathlib.Algebra.Order.Group.Unbundled.Abs import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Defs import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Order.Filter.Cofinite /-! # Lemmas about `Is(Co)Bounded(Under)` This file proves several lemmas about `IsBounded`, `IsBoundedUnder`, `IsCobounded` and `IsCoboundedUnder`. -/ open Set Function variable {α β γ ι : Type*} namespace Filter section Relation variable {r : α → α → Prop} {f g : Filter α} /-- `f` is eventually bounded if and only if, there exists an admissible set on which it is bounded. -/ theorem isBounded_iff : f.IsBounded r ↔ ∃ s ∈ f.sets, ∃ b, s ⊆ { x | r x b } := Iff.intro (fun ⟨b, hb⟩ => ⟨{ a | r a b }, hb, b, Subset.refl _⟩) fun ⟨_, hs, b, hb⟩ => ⟨b, mem_of_superset hs hb⟩ /-- A bounded function `u` is in particular eventually bounded. -/ theorem isBoundedUnder_of {f : Filter β} {u : β → α} : (∃ b, ∀ x, r (u x) b) → f.IsBoundedUnder r u | ⟨b, hb⟩ => ⟨b, show ∀ᶠ x in f, r (u x) b from Eventually.of_forall hb⟩ theorem isBounded_bot : IsBounded r ⊥ ↔ Nonempty α := by simp [IsBounded, exists_true_iff_nonempty] theorem isBounded_top : IsBounded r ⊤ ↔ ∃ t, ∀ x, r x t := by simp [IsBounded] theorem isBounded_principal (s : Set α) : IsBounded r (𝓟 s) ↔ ∃ t, ∀ x ∈ s, r x t := by simp [IsBounded] theorem isBounded_sup [IsTrans α r] [IsDirected α r] : IsBounded r f → IsBounded r g → IsBounded r (f ⊔ g) | ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ => let ⟨b, rb₁b, rb₂b⟩ := directed_of r b₁ b₂ ⟨b, eventually_sup.mpr ⟨h₁.mono fun _ h => _root_.trans h rb₁b, h₂.mono fun _ h => _root_.trans h rb₂b⟩⟩ theorem IsBounded.mono (h : f ≤ g) : IsBounded r g → IsBounded r f | ⟨b, hb⟩ => ⟨b, h hb⟩ theorem IsBoundedUnder.mono {f g : Filter β} {u : β → α} (h : f ≤ g) : g.IsBoundedUnder r u → f.IsBoundedUnder r u := fun hg => IsBounded.mono (map_mono h) hg theorem IsBoundedUnder.mono_le [Preorder β] {l : Filter α} {u v : α → β} (hu : IsBoundedUnder (· ≤ ·) l u) (hv : v ≤ᶠ[l] u) : IsBoundedUnder (· ≤ ·) l v := by apply hu.imp exact fun b hb => (eventually_map.1 hb).mp <| hv.mono fun x => le_trans theorem IsBoundedUnder.mono_ge [Preorder β] {l : Filter α} {u v : α → β} (hu : IsBoundedUnder (· ≥ ·) l u) (hv : u ≤ᶠ[l] v) : IsBoundedUnder (· ≥ ·) l v := IsBoundedUnder.mono_le (β := βᵒᵈ) hu hv theorem isBoundedUnder_const [IsRefl α r] {l : Filter β} {a : α} : IsBoundedUnder r l fun _ => a := ⟨a, eventually_map.2 <| Eventually.of_forall fun _ => refl _⟩ theorem IsBounded.isBoundedUnder {q : β → β → Prop} {u : α → β} (hu : ∀ a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.IsBounded r → f.IsBoundedUnder q u | ⟨b, h⟩ => ⟨u b, show ∀ᶠ x in f, q (u x) (u b) from h.mono fun x => hu x b⟩ theorem IsBoundedUnder.comp {l : Filter γ} {q : β → β → Prop} {u : γ → α} {v : α → β} (hv : ∀ a₀ a₁, r a₀ a₁ → q (v a₀) (v a₁)) : l.IsBoundedUnder r u → l.IsBoundedUnder q (v ∘ u) | ⟨a, h⟩ => ⟨v a, show ∀ᶠ x in map u l, q (v x) (v a) from h.mono fun x => hv x a⟩ lemma isBoundedUnder_map_iff {ι κ X : Type*} {r : X → X → Prop} {f : ι → X} {φ : κ → ι} {𝓕 : Filter κ} : (map φ 𝓕).IsBoundedUnder r f ↔ 𝓕.IsBoundedUnder r (f ∘ φ) := Iff.rfl lemma Tendsto.isBoundedUnder_comp {ι κ X : Type*} {r : X → X → Prop} {f : ι → X} {φ : κ → ι} {𝓕 : Filter ι} {𝓖 : Filter κ} (φ_tendsto : Tendsto φ 𝓖 𝓕) (𝓕_bounded : 𝓕.IsBoundedUnder r f) : 𝓖.IsBoundedUnder r (f ∘ φ) := isBoundedUnder_map_iff.mp (𝓕_bounded.mono φ_tendsto) section Preorder variable [Preorder α] {f : Filter β} {u : β → α} {s : Set β} lemma IsBoundedUnder.eventually_le (h : IsBoundedUnder (· ≤ ·) f u) : ∃ a, ∀ᶠ x in f, u x ≤ a := by tauto lemma IsBoundedUnder.eventually_ge (h : IsBoundedUnder (· ≥ ·) f u) : ∃ a, ∀ᶠ x in f, a ≤ u x := IsBoundedUnder.eventually_le (α := αᵒᵈ) h lemma isBoundedUnder_of_eventually_le {a : α} (h : ∀ᶠ x in f, u x ≤ a) : IsBoundedUnder (· ≤ ·) f u := ⟨a, h⟩ lemma isBoundedUnder_of_eventually_ge {a : α} (h : ∀ᶠ x in f, a ≤ u x) : IsBoundedUnder (· ≥ ·) f u := ⟨a, h⟩ lemma isBoundedUnder_iff_eventually_bddAbove : f.IsBoundedUnder (· ≤ ·) u ↔ ∃ s, BddAbove (u '' s) ∧ ∀ᶠ x in f, x ∈ s := by constructor · rintro ⟨b, hb⟩ exact ⟨{a | u a ≤ b}, ⟨b, by rintro _ ⟨a, ha, rfl⟩; exact ha⟩, hb⟩ · rintro ⟨s, ⟨b, hb⟩, hs⟩ exact ⟨b, hs.mono <| by simpa [upperBounds] using hb⟩ lemma isBoundedUnder_iff_eventually_bddBelow : f.IsBoundedUnder (· ≥ ·) u ↔ ∃ s, BddBelow (u '' s) ∧ ∀ᶠ x in f, x ∈ s := isBoundedUnder_iff_eventually_bddAbove (α := αᵒᵈ) lemma _root_.BddAbove.isBoundedUnder (hs : s ∈ f) (hu : BddAbove (u '' s)) : f.IsBoundedUnder (· ≤ ·) u := isBoundedUnder_iff_eventually_bddAbove.2 ⟨_, hu, hs⟩ /-- A bounded above function `u` is in particular eventually bounded above. -/ lemma _root_.BddAbove.isBoundedUnder_of_range (hu : BddAbove (Set.range u)) : f.IsBoundedUnder (· ≤ ·) u := BddAbove.isBoundedUnder (s := univ) f.univ_mem (by simpa) lemma _root_.BddBelow.isBoundedUnder (hs : s ∈ f) (hu : BddBelow (u '' s)) : f.IsBoundedUnder (· ≥ ·) u := isBoundedUnder_iff_eventually_bddBelow.2 ⟨_, hu, hs⟩ /-- A bounded below function `u` is in particular eventually bounded below. -/ lemma _root_.BddBelow.isBoundedUnder_of_range (hu : BddBelow (Set.range u)) : f.IsBoundedUnder (· ≥ ·) u := BddBelow.isBoundedUnder (s := univ) f.univ_mem (by simpa) lemma IsBoundedUnder.le_of_finite [Nonempty α] [IsDirected α (· ≤ ·)] [Finite β] {f : Filter β} {u : β → α} : IsBoundedUnder (· ≤ ·) f u := (Set.toFinite _).bddAbove.isBoundedUnder_of_range lemma IsBoundedUnder.ge_of_finite [Nonempty α] [IsDirected α (· ≥ ·)] [Finite β] {f : Filter β} {u : β → α} : IsBoundedUnder (· ≥ ·) f u := (Set.toFinite _).bddBelow.isBoundedUnder_of_range end Preorder theorem _root_.Monotone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≤ ·) u) : l.IsBoundedUnder (· ≤ ·) (v ∘ u) := hl.comp hv theorem _root_.Monotone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≥ ·) u) : l.IsBoundedUnder (· ≥ ·) (v ∘ u) := hl.comp (swap hv) theorem _root_.Antitone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≥ ·) u) : l.IsBoundedUnder (· ≤ ·) (v ∘ u) := hl.comp (swap hv) theorem _root_.Antitone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≤ ·) u) : l.IsBoundedUnder (· ≥ ·) (v ∘ u) := hl.comp hv theorem not_isBoundedUnder_of_tendsto_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} [l.NeBot] (hf : Tendsto f l atTop) : ¬IsBoundedUnder (· ≤ ·) l f := by rintro ⟨b, hb⟩ rw [eventually_map] at hb obtain ⟨b', h⟩ := exists_gt b have hb' := (tendsto_atTop.mp hf) b' have : { x : α | f x ≤ b } ∩ { x : α | b' ≤ f x } = ∅ := eq_empty_of_subset_empty fun x hx => (not_le_of_gt h) (le_trans hx.2 hx.1) exact (nonempty_of_mem (hb.and hb')).ne_empty this theorem not_isBoundedUnder_of_tendsto_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α} [l.NeBot] (hf : Tendsto f l atBot) : ¬IsBoundedUnder (· ≥ ·) l f := not_isBoundedUnder_of_tendsto_atTop (β := βᵒᵈ) hf theorem IsBoundedUnder.bddAbove_range_of_cofinite [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β} (hf : IsBoundedUnder (· ≤ ·) cofinite f) : BddAbove (range f) := by rcases hf with ⟨b, hb⟩ haveI : Nonempty β := ⟨b⟩ rw [← image_univ, ← union_compl_self { x | f x ≤ b }, image_union, bddAbove_union] exact ⟨⟨b, forall_mem_image.2 fun x => id⟩, (hb.image f).bddAbove⟩ theorem IsBoundedUnder.bddBelow_range_of_cofinite [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β} (hf : IsBoundedUnder (· ≥ ·) cofinite f) : BddBelow (range f) := IsBoundedUnder.bddAbove_range_of_cofinite (β := βᵒᵈ) hf theorem IsBoundedUnder.bddAbove_range [Preorder β] [IsDirected β (· ≤ ·)] {f : ℕ → β} (hf : IsBoundedUnder (· ≤ ·) atTop f) : BddAbove (range f) := by rw [← Nat.cofinite_eq_atTop] at hf exact hf.bddAbove_range_of_cofinite theorem IsBoundedUnder.bddBelow_range [Preorder β] [IsDirected β (· ≥ ·)] {f : ℕ → β} (hf : IsBoundedUnder (· ≥ ·) atTop f) : BddBelow (range f) := IsBoundedUnder.bddAbove_range (β := βᵒᵈ) hf /-- To check that a filter is frequently bounded, it suffices to have a witness which bounds `f` at some point for every admissible set. This is only an implication, as the other direction is wrong for the trivial filter. -/ theorem IsCobounded.mk [IsTrans α r] (a : α) (h : ∀ s ∈ f, ∃ x ∈ s, r a x) : f.IsCobounded r := ⟨a, fun _ s => let ⟨_, h₁, h₂⟩ := h _ s _root_.trans h₂ h₁⟩ /-- A filter which is eventually bounded is in particular frequently bounded (in the opposite direction). At least if the filter is not trivial. -/ theorem IsBounded.isCobounded_flip [IsTrans α r] [NeBot f] : f.IsBounded r → f.IsCobounded (flip r) | ⟨a, ha⟩ => ⟨a, fun b hb => let ⟨_, rxa, rbx⟩ := (ha.and hb).exists show r b a from _root_.trans rbx rxa⟩ theorem IsBounded.isCobounded_ge [Preorder α] [NeBot f] (h : f.IsBounded (· ≤ ·)) : f.IsCobounded (· ≥ ·) := h.isCobounded_flip theorem IsBounded.isCobounded_le [Preorder α] [NeBot f] (h : f.IsBounded (· ≥ ·)) : f.IsCobounded (· ≤ ·) := h.isCobounded_flip theorem IsBoundedUnder.isCoboundedUnder_flip {u : γ → α} {l : Filter γ} [IsTrans α r] [NeBot l] (h : l.IsBoundedUnder r u) : l.IsCoboundedUnder (flip r) u := h.isCobounded_flip theorem IsBoundedUnder.isCoboundedUnder_le {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l] (h : l.IsBoundedUnder (· ≥ ·) u) : l.IsCoboundedUnder (· ≤ ·) u := h.isCoboundedUnder_flip theorem IsBoundedUnder.isCoboundedUnder_ge {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l] (h : l.IsBoundedUnder (· ≤ ·) u) : l.IsCoboundedUnder (· ≥ ·) u := h.isCoboundedUnder_flip lemma isCoboundedUnder_le_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ᶠ i in l, x ≤ f i) : IsCoboundedUnder (· ≤ ·) l f := IsBoundedUnder.isCoboundedUnder_le ⟨x, hf⟩ lemma isCoboundedUnder_ge_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ᶠ i in l, f i ≤ x) : IsCoboundedUnder (· ≥ ·) l f := IsBoundedUnder.isCoboundedUnder_ge ⟨x, hf⟩ lemma isCoboundedUnder_le_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ i, x ≤ f i) : IsCoboundedUnder (· ≤ ·) l f := isCoboundedUnder_le_of_eventually_le l (Eventually.of_forall hf) lemma isCoboundedUnder_ge_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ i, f i ≤ x) : IsCoboundedUnder (· ≥ ·) l f := isCoboundedUnder_ge_of_eventually_le l (Eventually.of_forall hf) theorem isCobounded_bot : IsCobounded r ⊥ ↔ ∃ b, ∀ x, r b x := by simp [IsCobounded] theorem isCobounded_top : IsCobounded r ⊤ ↔ Nonempty α := by simp +contextual [IsCobounded, exists_true_iff_nonempty] theorem isCobounded_principal (s : Set α) : (𝓟 s).IsCobounded r ↔ ∃ b, ∀ a, (∀ x ∈ s, r x a) → r b a := by simp [IsCobounded] theorem IsCobounded.mono (h : f ≤ g) : f.IsCobounded r → g.IsCobounded r | ⟨b, hb⟩ => ⟨b, fun a ha => hb a (h ha)⟩ /-- For nontrivial filters in linear orders, coboundedness for `≤` implies frequent boundedness from below. -/ lemma IsCobounded.frequently_ge [LinearOrder α] [NeBot f] (cobdd : IsCobounded (· ≤ ·) f) : ∃ l, ∃ᶠ x in f, l ≤ x := by obtain ⟨t, ht⟩ := cobdd rcases isBot_or_exists_lt t with tbot | ⟨t', ht'⟩ · exact ⟨t, .of_forall fun r ↦ tbot r⟩ refine ⟨t', fun ev ↦ ?_⟩ specialize ht t' (by filter_upwards [ev] with _ h using (not_le.mp h).le) exact not_lt_of_ge ht ht' /-- For nontrivial filters in linear orders, coboundedness for `≥` implies frequent boundedness from above. -/ lemma IsCobounded.frequently_le [LinearOrder α] [NeBot f] (cobdd : IsCobounded (· ≥ ·) f) : ∃ u, ∃ᶠ x in f, x ≤ u := cobdd.frequently_ge (α := αᵒᵈ) /-- In linear orders, frequent boundedness from below implies coboundedness for `≤`. -/ lemma IsCobounded.of_frequently_ge [LinearOrder α] {l : α} (freq_ge : ∃ᶠ x in f, l ≤ x) : IsCobounded (· ≤ ·) f := by rcases isBot_or_exists_lt l with lbot | ⟨l', hl'⟩ · exact ⟨l, fun x _ ↦ lbot x⟩ refine ⟨l', fun u hu ↦ ?_⟩ obtain ⟨w, l_le_w, w_le_u⟩ := (freq_ge.and_eventually hu).exists exact hl'.le.trans (l_le_w.trans w_le_u) /-- In linear orders, frequent boundedness from above implies coboundedness for `≥`. -/ lemma IsCobounded.of_frequently_le [LinearOrder α] {u : α} (freq_le : ∃ᶠ r in f, r ≤ u) : IsCobounded (· ≥ ·) f := IsCobounded.of_frequently_ge (α := αᵒᵈ) freq_le lemma IsCoboundedUnder.frequently_ge [LinearOrder α] {f : Filter ι} [NeBot f] {u : ι → α} (h : IsCoboundedUnder (· ≤ ·) f u) : ∃ a, ∃ᶠ x in f, a ≤ u x := IsCobounded.frequently_ge h lemma IsCoboundedUnder.frequently_le [LinearOrder α] {f : Filter ι} [NeBot f] {u : ι → α} (h : IsCoboundedUnder (· ≥ ·) f u) : ∃ a, ∃ᶠ x in f, u x ≤ a := IsCobounded.frequently_le h lemma IsCoboundedUnder.of_frequently_ge [LinearOrder α] {f : Filter ι} {u : ι → α} {a : α} (freq_ge : ∃ᶠ x in f, a ≤ u x) : IsCoboundedUnder (· ≤ ·) f u := IsCobounded.of_frequently_ge freq_ge lemma IsCoboundedUnder.of_frequently_le [LinearOrder α] {f : Filter ι} {u : ι → α} {a : α} (freq_le : ∃ᶠ x in f, u x ≤ a) : IsCoboundedUnder (· ≥ ·) f u := IsCobounded.of_frequently_le freq_le end Relation section add_and_sum open Filter Set variable {α : Type*} {f : Filter α} variable {R : Type*} lemma isBoundedUnder_sum {κ : Type*} [AddCommMonoid R] {r : R → R → Prop} (hr : ∀ (v₁ v₂ : α → R), f.IsBoundedUnder r v₁ → f.IsBoundedUnder r v₂ → f.IsBoundedUnder r (v₁ + v₂)) (hr₀ : r 0 0) {u : κ → α → R} (s : Finset κ) (h : ∀ k ∈ s, f.IsBoundedUnder r (u k)) : f.IsBoundedUnder r (∑ k ∈ s, u k) := by induction s using Finset.cons_induction case empty => rw [Finset.sum_empty] exact ⟨0, by simp_all only [eventually_map, Pi.zero_apply, eventually_true]⟩ case cons k₀ s k₀_notin_s ih => simp only [Finset.forall_mem_cons] at * simpa only [Finset.sum_cons] using hr _ _ h.1 (ih h.2) variable [Preorder R] lemma isBoundedUnder_ge_add [Add R] [AddLeftMono R] [AddRightMono R] {u v : α → R} (u_bdd_ge : f.IsBoundedUnder (· ≥ ·) u) (v_bdd_ge : f.IsBoundedUnder (· ≥ ·) v) : f.IsBoundedUnder (· ≥ ·) (u + v) := by obtain ⟨U, hU⟩ := u_bdd_ge obtain ⟨V, hV⟩ := v_bdd_ge use U + V simp only [eventually_map, Pi.add_apply] at hU hV ⊢ filter_upwards [hU, hV] with a hu hv using add_le_add hu hv lemma isBoundedUnder_le_add [Add R] [AddLeftMono R] [AddRightMono R] {u v : α → R} (u_bdd_le : f.IsBoundedUnder (· ≤ ·) u) (v_bdd_le : f.IsBoundedUnder (· ≤ ·) v) : f.IsBoundedUnder (· ≤ ·) (u + v) := by obtain ⟨U, hU⟩ := u_bdd_le obtain ⟨V, hV⟩ := v_bdd_le use U + V simp only [eventually_map, Pi.add_apply] at hU hV ⊢ filter_upwards [hU, hV] with a hu hv using add_le_add hu hv lemma isBoundedUnder_le_sum {κ : Type*} [AddCommMonoid R] [AddLeftMono R] [AddRightMono R] {u : κ → α → R} (s : Finset κ) : (∀ k ∈ s, f.IsBoundedUnder (· ≤ ·) (u k)) → f.IsBoundedUnder (· ≤ ·) (∑ k ∈ s, u k) := fun h ↦ isBoundedUnder_sum (fun _ _ ↦ isBoundedUnder_le_add) le_rfl s h lemma isBoundedUnder_ge_sum {κ : Type*} [AddCommMonoid R] [AddLeftMono R] [AddRightMono R] {u : κ → α → R} (s : Finset κ) : (∀ k ∈ s, f.IsBoundedUnder (· ≥ ·) (u k)) → f.IsBoundedUnder (· ≥ ·) (∑ k ∈ s, u k) := fun h ↦ isBoundedUnder_sum (fun _ _ ↦ isBoundedUnder_ge_add) le_rfl s h end add_and_sum section add_and_sum variable {α : Type*} {R : Type*} [LinearOrder R] [Add R] {f : Filter α} [f.NeBot] [AddLeftMono R] [AddRightMono R] {u v : α → R} lemma isCoboundedUnder_ge_add (hu : f.IsBoundedUnder (· ≤ ·) u) (hv : f.IsCoboundedUnder (· ≥ ·) v) : f.IsCoboundedUnder (· ≥ ·) (u + v) := by obtain ⟨U, hU⟩ := hu.eventually_le obtain ⟨V, hV⟩ := hv.frequently_le apply IsCoboundedUnder.of_frequently_le (a := U + V) exact (hV.and_eventually hU).mono fun x hx ↦ add_le_add hx.2 hx.1 lemma isCoboundedUnder_le_add (hu : f.IsBoundedUnder (· ≥ ·) u) (hv : f.IsCoboundedUnder (· ≤ ·) v) : f.IsCoboundedUnder (· ≤ ·) (u + v) := by obtain ⟨U, hU⟩ := hu.eventually_ge obtain ⟨V, hV⟩ := hv.frequently_ge apply IsCoboundedUnder.of_frequently_ge (a := U + V) exact (hV.and_eventually hU).mono fun x hx ↦ add_le_add hx.2 hx.1 end add_and_sum section mul lemma isBoundedUnder_le_mul_of_nonneg [Preorder α] [Mul α] [Zero α] [PosMulMono α] [MulPosMono α] {f : Filter ι} {u v : ι → α} (h₁ : ∃ᶠ x in f, 0 ≤ u x) (h₂ : IsBoundedUnder (fun x1 x2 ↦ x1 ≤ x2) f u) (h₃ : 0 ≤ᶠ[f] v) (h₄ : IsBoundedUnder (fun x1 x2 ↦ x1 ≤ x2) f v) : IsBoundedUnder (fun x1 x2 ↦ x1 ≤ x2) f (u * v) := by obtain ⟨U, hU⟩ := h₂.eventually_le obtain ⟨V, hV⟩ := h₄.eventually_le refine isBoundedUnder_of_eventually_le (a := U * V) ?_ filter_upwards [hU, hV, h₃] with x x_U x_V v_0 have U_0 : 0 ≤ U := by obtain ⟨y, y_0, y_U⟩ := (h₁.and_eventually hU).exists exact y_0.trans y_U exact (mul_le_mul_of_nonneg_right x_U v_0).trans (mul_le_mul_of_nonneg_left x_V U_0) lemma isCoboundedUnder_ge_mul_of_nonneg [LinearOrder α] [Mul α] [Zero α] [PosMulMono α] [MulPosMono α] {f : Filter ι} [f.NeBot] {u v : ι → α} (h₁ : 0 ≤ᶠ[f] u) (h₂ : IsBoundedUnder (fun x1 x2 ↦ x1 ≤ x2) f u) (h₃ : 0 ≤ᶠ[f] v) (h₄ : IsCoboundedUnder (fun x1 x2 ↦ x1 ≥ x2) f v) : IsCoboundedUnder (fun x1 x2 ↦ x1 ≥ x2) f (u * v) := by obtain ⟨U, hU⟩ := h₂.eventually_le obtain ⟨V, hV⟩ := h₄.frequently_le refine IsCoboundedUnder.of_frequently_le (a := U * V) ?_ apply (hV.and_eventually (hU.and (h₁.and h₃))).mono intro x ⟨x_V, x_U, u_0, v_0⟩ exact (mul_le_mul_of_nonneg_right x_U v_0).trans (mul_le_mul_of_nonneg_left x_V (u_0.trans x_U)) end mul section Nonempty variable [Preorder α] [Nonempty α] {f : Filter β} {u : β → α} theorem isBounded_le_atBot : (atBot : Filter α).IsBounded (· ≤ ·) := ‹Nonempty α›.elim fun a => ⟨a, eventually_le_atBot _⟩ theorem isBounded_ge_atTop : (atTop : Filter α).IsBounded (· ≥ ·) := ‹Nonempty α›.elim fun a => ⟨a, eventually_ge_atTop _⟩ theorem Tendsto.isBoundedUnder_le_atBot (h : Tendsto u f atBot) : f.IsBoundedUnder (· ≤ ·) u := isBounded_le_atBot.mono h theorem Tendsto.isBoundedUnder_ge_atTop (h : Tendsto u f atTop) : f.IsBoundedUnder (· ≥ ·) u := isBounded_ge_atTop.mono h theorem bddAbove_range_of_tendsto_atTop_atBot [IsDirected α (· ≤ ·)] {u : ℕ → α} (hx : Tendsto u atTop atBot) : BddAbove (Set.range u) := hx.isBoundedUnder_le_atBot.bddAbove_range theorem bddBelow_range_of_tendsto_atTop_atTop [IsDirected α (· ≥ ·)] {u : ℕ → α} (hx : Tendsto u atTop atTop) : BddBelow (Set.range u) := hx.isBoundedUnder_ge_atTop.bddBelow_range end Nonempty theorem isCobounded_le_of_bot [LE α] [OrderBot α] {f : Filter α} : f.IsCobounded (· ≤ ·) := ⟨⊥, fun _ _ => bot_le⟩ theorem isCobounded_ge_of_top [LE α] [OrderTop α] {f : Filter α} : f.IsCobounded (· ≥ ·) := ⟨⊤, fun _ _ => le_top⟩ theorem isBounded_le_of_top [LE α] [OrderTop α] {f : Filter α} : f.IsBounded (· ≤ ·) := ⟨⊤, Eventually.of_forall fun _ => le_top⟩ theorem isBounded_ge_of_bot [LE α] [OrderBot α] {f : Filter α} : f.IsBounded (· ≥ ·) := ⟨⊥, Eventually.of_forall fun _ => bot_le⟩ @[simp] theorem _root_.OrderIso.isBoundedUnder_le_comp [LE α] [LE β] (e : α ≃o β) {l : Filter γ} {u : γ → α} : (IsBoundedUnder (· ≤ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≤ ·) l u := (Function.Surjective.exists e.surjective).trans <| exists_congr fun a => by simp only [eventually_map, e.le_iff_le] @[simp] theorem _root_.OrderIso.isBoundedUnder_ge_comp [LE α] [LE β] (e : α ≃o β) {l : Filter γ} {u : γ → α} : (IsBoundedUnder (· ≥ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≥ ·) l u := OrderIso.isBoundedUnder_le_comp e.dual @[to_additive (attr := simp)] theorem isBoundedUnder_le_inv [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {l : Filter β} {u : β → α} : (IsBoundedUnder (· ≤ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≥ ·) l u := (OrderIso.inv α).isBoundedUnder_ge_comp @[to_additive (attr := simp)] theorem isBoundedUnder_ge_inv [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {l : Filter β} {u : β → α} : (IsBoundedUnder (· ≥ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≤ ·) l u := (OrderIso.inv α).isBoundedUnder_le_comp theorem IsBoundedUnder.sup [SemilatticeSup α] {f : Filter β} {u v : β → α} : f.IsBoundedUnder (· ≤ ·) u → f.IsBoundedUnder (· ≤ ·) v → f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a | ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩, ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ => ⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv by filter_upwards [hu, hv] with _ using sup_le_sup⟩ @[simp] theorem isBoundedUnder_le_sup [SemilatticeSup α] {f : Filter β} {u v : β → α} : (f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a) ↔ f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≤ ·) v := ⟨fun h => ⟨h.mono_le <| Eventually.of_forall fun _ => le_sup_left, h.mono_le <| Eventually.of_forall fun _ => le_sup_right⟩, fun h => h.1.sup h.2⟩ theorem IsBoundedUnder.inf [SemilatticeInf α] {f : Filter β} {u v : β → α} : f.IsBoundedUnder (· ≥ ·) u → f.IsBoundedUnder (· ≥ ·) v → f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a := IsBoundedUnder.sup (α := αᵒᵈ) @[simp] theorem isBoundedUnder_ge_inf [SemilatticeInf α] {f : Filter β} {u v : β → α} : (f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a) ↔ f.IsBoundedUnder (· ≥ ·) u ∧ f.IsBoundedUnder (· ≥ ·) v := isBoundedUnder_le_sup (α := αᵒᵈ) theorem isBoundedUnder_le_abs [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] {f : Filter β} {u : β → α} : (f.IsBoundedUnder (· ≤ ·) fun a => |u a|) ↔ f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≥ ·) u := isBoundedUnder_le_sup.trans <| and_congr Iff.rfl isBoundedUnder_le_neg /-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements in complete and conditionally complete lattices but let automation fill automatically the boundedness proofs in complete lattices, we use the tactic `isBoundedDefault` in the statements, in the form `(hf : f.IsBounded (≥) := by isBoundedDefault)`. -/ macro "isBoundedDefault" : tactic => `(tactic| first | apply isCobounded_le_of_bot | apply isCobounded_ge_of_top | apply isBounded_le_of_top | apply isBounded_ge_of_bot | assumption) end Filter open Filter section Order theorem Monotone.isBoundedUnder_le_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMaxOrder γ] {g : β → γ} {f : α → β} {l : Filter α} (hg : Monotone g) (hg' : Tendsto g atTop atTop) : IsBoundedUnder (· ≤ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≤ ·) l f := by refine ⟨?_, fun h => h.isBoundedUnder (α := β) hg⟩ rintro ⟨c, hc⟩; rw [eventually_map] at hc obtain ⟨b, hb⟩ : ∃ b, ∀ a ≥ b, c < g a := eventually_atTop.1 (hg'.eventually_gt_atTop c) exact ⟨b, hc.mono fun x hx => not_lt.1 fun h => (hb _ h.le).not_ge hx⟩ theorem Monotone.isBoundedUnder_ge_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMinOrder γ] {g : β → γ} {f : α → β} {l : Filter α} (hg : Monotone g) (hg' : Tendsto g atBot atBot) : IsBoundedUnder (· ≥ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≥ ·) l f := hg.dual.isBoundedUnder_le_comp_iff hg' theorem Antitone.isBoundedUnder_le_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMaxOrder γ] {g : β → γ} {f : α → β} {l : Filter α} (hg : Antitone g) (hg' : Tendsto g atBot atTop) : IsBoundedUnder (· ≤ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≥ ·) l f := hg.dual_right.isBoundedUnder_ge_comp_iff hg' theorem Antitone.isBoundedUnder_ge_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMinOrder γ] {g : β → γ} {f : α → β} {l : Filter α} (hg : Antitone g) (hg' : Tendsto g atTop atBot) : IsBoundedUnder (· ≥ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≤ ·) l f := hg.dual_right.isBoundedUnder_le_comp_iff hg' end Order section MinMax theorem isCoboundedUnder_le_max [LinearOrder β] {f : Filter α} {u v : α → β} (h : f.IsCoboundedUnder (· ≤ ·) u ∨ f.IsCoboundedUnder (· ≤ ·) v) : f.IsCoboundedUnder (· ≤ ·) (fun a ↦ max (u a) (v a)) := by rcases h with (h' | h') <;> · rcases h' with ⟨b, hb⟩ use b intro c hc apply hb c rw [eventually_map] at hc ⊢ refine hc.mono (fun _ ↦ ?_) simp +contextual only [implies_true, max_le_iff] open Finset theorem isBoundedUnder_le_finset_sup' [LinearOrder β] [Nonempty β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i)) : f.IsBoundedUnder (· ≤ ·) (fun a ↦ sup' s hs (fun i ↦ F i a)) := by choose! m hm using h use sup' s hs m simp only [eventually_map] at hm ⊢ rw [← eventually_all_finset s] at hm refine hm.mono fun a h ↦ ?_ simp only [sup'_le_iff] exact fun i i_s ↦ le_trans (h i i_s) (le_sup' m i_s) theorem isCoboundedUnder_le_finset_sup' [LinearOrder β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h : ∃ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i)) : f.IsCoboundedUnder (· ≤ ·) (fun a ↦ sup' s hs (fun i ↦ F i a)) := by rcases h with ⟨i, i_s, b, hb⟩ use b refine fun c hc ↦ hb c ?_ rw [eventually_map] at hc ⊢ refine hc.mono fun a h ↦ ?_ simp only [sup'_le_iff] at h ⊢ exact h i i_s theorem isBoundedUnder_le_finset_sup [LinearOrder β] [OrderBot β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (h : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i)) : f.IsBoundedUnder (· ≤ ·) (fun a ↦ sup s (fun i ↦ F i a)) := by choose! m hm using h use sup s m simp only [eventually_map] at hm ⊢ rw [← eventually_all_finset s] at hm exact hm.mono fun _ h ↦ sup_mono_fun h theorem isBoundedUnder_ge_finset_inf' [LinearOrder β] [Nonempty β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i)) : f.IsBoundedUnder (· ≥ ·) (fun a ↦ inf' s hs (fun i ↦ F i a)) := isBoundedUnder_le_finset_sup' (β := βᵒᵈ) hs h theorem isCoboundedUnder_ge_finset_inf' [LinearOrder β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h : ∃ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i)) : f.IsCoboundedUnder (· ≥ ·) (fun a ↦ inf' s hs (fun i ↦ F i a)) := isCoboundedUnder_le_finset_sup' (β := βᵒᵈ) hs h theorem isBoundedUnder_ge_finset_inf [LinearOrder β] [OrderTop β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (h : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i)) : f.IsBoundedUnder (· ≥ ·) (fun a ↦ inf s (fun i ↦ F i a)) := isBoundedUnder_le_finset_sup (β := βᵒᵈ) h end MinMax section FrequentlyBounded variable {R S : Type*} {F : Filter R} [LinearOrder R] [LinearOrder S] lemma Monotone.frequently_ge_map_of_frequently_ge {f : R → S} (f_incr : Monotone f) {l : R} (freq_ge : ∃ᶠ x in F, l ≤ x) : ∃ᶠ x' in F.map f, f l ≤ x' := by refine fun ev ↦ freq_ge ?_ simp only [not_le] at ev freq_ge ⊢ filter_upwards [ev] with z hz by_contra con exact lt_irrefl (f l) <| lt_of_le_of_lt (f_incr <| not_lt.mp con) hz lemma Monotone.frequently_le_map_of_frequently_le {f : R → S} (f_incr : Monotone f) {u : R} (freq_le : ∃ᶠ x in F, x ≤ u) : ∃ᶠ y in F.map f, y ≤ f u := by refine fun ev ↦ freq_le ?_ simp only [not_le] at ev freq_le ⊢ filter_upwards [ev] with z hz by_contra con apply lt_irrefl (f u) <| lt_of_lt_of_le hz <| f_incr (not_lt.mp con) lemma Antitone.frequently_le_map_of_frequently_ge {f : R → S} (f_decr : Antitone f) {l : R} (frbdd : ∃ᶠ x in F, l ≤ x) : ∃ᶠ y in F.map f, y ≤ f l := Monotone.frequently_ge_map_of_frequently_ge (S := Sᵒᵈ) f_decr frbdd lemma Antitone.frequently_ge_map_of_frequently_le {f : R → S} (f_decr : Antitone f) {u : R} (frbdd : ∃ᶠ x in F, x ≤ u) : ∃ᶠ y in F.map f, f u ≤ y := Monotone.frequently_le_map_of_frequently_le (S := Sᵒᵈ) f_decr frbdd lemma Monotone.isCoboundedUnder_le_of_isCobounded {f : R → S} (f_incr : Monotone f) [NeBot F] (cobdd : IsCobounded (· ≤ ·) F) : F.IsCoboundedUnder (· ≤ ·) f := by obtain ⟨l, hl⟩ := IsCobounded.frequently_ge cobdd exact IsCobounded.of_frequently_ge <| f_incr.frequently_ge_map_of_frequently_ge hl lemma Monotone.isCoboundedUnder_ge_of_isCobounded {f : R → S} (f_incr : Monotone f) [NeBot F] (cobdd : IsCobounded (· ≥ ·) F) : F.IsCoboundedUnder (· ≥ ·) f := Monotone.isCoboundedUnder_le_of_isCobounded (R := Rᵒᵈ) (S := Sᵒᵈ) f_incr.dual cobdd lemma Antitone.isCoboundedUnder_le_of_isCobounded {f : R → S} (f_decr : Antitone f) [NeBot F] (cobdd : IsCobounded (· ≥ ·) F) : F.IsCoboundedUnder (· ≤ ·) f := Monotone.isCoboundedUnder_le_of_isCobounded (R := Rᵒᵈ) f_decr.dual cobdd lemma Antitone.isCoboundedUnder_ge_of_isCobounded {f : R → S} (f_decr : Antitone f) [NeBot F] (cobdd : IsCobounded (· ≤ ·) F) : F.IsCoboundedUnder (· ≥ ·) f := Monotone.isCoboundedUnder_le_of_isCobounded (S := Sᵒᵈ) f_decr cobdd end FrequentlyBounded
.lake/packages/mathlib/Mathlib/Order/Filter/Defs.lean
import Mathlib.Data.Set.Insert import Mathlib.Order.SetNotation import Mathlib.Order.BooleanAlgebra.Set import Mathlib.Order.Bounds.Defs /-! # Definitions about filters A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. Filters are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... ## Main definitions * `Filter` : filters on a set; * `Filter.principal`, `𝓟 s` : filter of all sets containing a given set; * `Filter.map`, `Filter.comap` : operations on filters; * `Filter.Tendsto` : limit with respect to filters; * `Filter.Eventually` : `f.Eventually p` means `{x | p x} ∈ f`; * `Filter.Frequently` : `f.Frequently p` means `{x | ¬p x} ∉ f`; * `filter_upwards [h₁, ..., hₙ]` : a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`, and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`; * `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter. * `Filter.IsBounded r f`: the filter `f` is eventually bounded w.r.t. the relation `r`, i.e. eventually, it is bounded by some uniform bound. `r` will be usually instantiated with `(· ≤ ·)` or `(· ≥ ·)`. * `Filter.IsCobounded r f` states that the filter `f` does not tend to infinity w.r.t. `r`. This is also called frequently bounded. Will be usually instantiated with `(· ≤ ·)` or `(· ≥ ·)`. ## Notation * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## Implementation Notes Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] -/ assert_not_exists RelIso open Set /-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. We do not forbid this collection to be all sets of `α`. -/ structure Filter (α : Type*) where /-- The set of sets that belong to the filter. -/ sets : Set (Set α) /-- The set `Set.univ` belongs to any filter. -/ univ_sets : Set.univ ∈ sets /-- If a set belongs to a filter, then its superset belongs to the filter as well. -/ sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets /-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets namespace Filter variable {α β : Type*} {f g : Filter α} {s t : Set α} theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl /-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/ instance instMembership : Membership (Set α) (Filter α) := ⟨fun F U => U ∈ F.sets⟩ @[ext] protected theorem ext (h : ∀ s, s ∈ f ↔ s ∈ g) : f = g := filter_eq <| Set.ext h @[simp] protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t := Iff.rfl @[simp] protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f := Iff.rfl @[simp] theorem univ_mem : univ ∈ f := f.univ_sets theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f := f.sets_of_superset hx hxy theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f := mem_of_superset univ_mem fun x _ => h x theorem inter_mem (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f := f.inter_sets hs ht theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f := mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁ /-- Override `sets` field of a filter to provide better definitional equality. -/ protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where sets := S univ_sets := (hmem _).2 univ_mem sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂) @[simp] theorem mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl /-- Construct a filter from a property that is stable under finite unions. A set `s` belongs to `Filter.comk p _ _ _` iff its complement satisfies the predicate `p`. This constructor is useful to define filters like `Filter.cofinite`. -/ def comk (p : Set α → Prop) (he : p ∅) (hmono : ∀ t, p t → ∀ s ⊆ t, p s) (hunion : ∀ s, p s → ∀ t, p t → p (s ∪ t)) : Filter α where sets := {t | p tᶜ} univ_sets := by simpa sets_of_superset := fun ht₁ ht => hmono _ ht₁ _ (compl_subset_compl.2 ht) inter_sets := fun ht₁ ht₂ => by simp [compl_inter, hunion _ ht₁ _ ht₂] @[simp] lemma mem_comk {p : Set α → Prop} {he hmono hunion s} : s ∈ comk p he hmono hunion ↔ p sᶜ := .rfl /-- The principal filter of `s` is the collection of all supersets of `s`. -/ def principal (s : Set α) : Filter α where sets := { t | s ⊆ t } univ_sets := subset_univ s sets_of_superset hx := Subset.trans hx inter_sets := subset_inter @[inherit_doc] scoped notation "𝓟" => Filter.principal @[simp] theorem mem_principal : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl /-- `pure x` is the set of sets that contain `x`. It is equal to `𝓟 {x}` but with this definition we have `s ∈ pure a` defeq `a ∈ s`. -/ instance : Pure Filter where pure x := .copy (𝓟 {x}) {s | x ∈ s} fun _ ↦ by simp @[simp] theorem mem_pure {a : α} {s : Set α} : s ∈ (pure a : Filter α) ↔ a ∈ s := Iff.rfl /-- The *kernel* of a filter is the intersection of all its sets. -/ def ker (f : Filter α) : Set α := ⋂₀ f.sets /-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/ def join (f : Filter (Filter α)) : Filter α where sets := { s | { t : Filter α | s ∈ t } ∈ f } univ_sets := by simp only [mem_setOf_eq, univ_mem, setOf_true] sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂ @[simp] theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f := Iff.rfl instance : PartialOrder (Filter α) where le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁ le_refl a := Subset.rfl le_trans a b c h₁ h₂ := Subset.trans h₂ h₁ theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f := Iff.rfl instance instSupSet : SupSet (Filter α) where sSup S := join (𝓟 S) @[simp] theorem mem_sSup {S : Set (Filter α)} : s ∈ sSup S ↔ ∀ f ∈ S, s ∈ f := .rfl /-- Infimum of a set of filters. This definition is marked as irreducible so that Lean doesn't try to unfold it when unifying expressions. -/ @[irreducible] protected def sInf (s : Set (Filter α)) : Filter α := sSup (lowerBounds s) instance instInfSet : InfSet (Filter α) where sInf := Filter.sInf protected theorem sSup_lowerBounds (s : Set (Filter α)) : sSup (lowerBounds s) = sInf s := by simp [sInf, Filter.sInf] instance : Top (Filter α) where top := .copy (sSup (Set.range pure)) {s | ∀ x, x ∈ s} <| by simp theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s := Iff.rfl @[simp] theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by rw [mem_top_iff_forall, eq_univ_iff_forall] instance : Bot (Filter α) where bot := .copy (sSup ∅) univ <| by simp @[simp] theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) := trivial /-- The infimum of filters is the filter generated by intersections of elements of the two filters. -/ instance instInf : Min (Filter α) := ⟨fun f g : Filter α => { sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b } univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩ sets_of_superset := by rintro x y ⟨a, ha, b, hb, rfl⟩ xy refine ⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y, mem_of_superset hb subset_union_left, ?_⟩ rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy] inter_sets := by rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩ refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩ ac_rfl }⟩ /-- The supremum of two filters is the filter that contains sets that belong to both filters. -/ instance instSup : Max (Filter α) where max f g := .copy (sSup {f, g}) {s | s ∈ f ∧ s ∈ g} <| by simp /-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a `CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/ class NeBot (f : Filter α) : Prop where /-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/ ne' : f ≠ ⊥ theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- `f.Eventually p` or `∀ᶠ x in f, p x` mean that `{x | p x} ∈ f`. E.g., `∀ᶠ x in atTop, p x` means that `p` holds true for sufficiently large `x`. -/ protected def Eventually (p : α → Prop) (f : Filter α) : Prop := { x | p x } ∈ f @[inherit_doc Filter.Eventually] notation3 "∀ᶠ "(...)" in "f", "r:(scoped p => Filter.Eventually p f) => r /-- `f.Frequently p` or `∃ᶠ x in f, p x` mean that `{x | ¬p x} ∉ f`. E.g., `∃ᶠ x in atTop, p x` means that there exist arbitrarily large `x` for which `p` holds true. -/ protected def Frequently (p : α → Prop) (f : Filter α) : Prop := ¬∀ᶠ x in f, ¬p x @[inherit_doc Filter.Frequently] notation3 "∃ᶠ "(...)" in "f", "r:(scoped p => Filter.Frequently p f) => r /-- Two functions `f` and `g` are *eventually equal* along a filter `l` if the set of `x` such that `f x = g x` belongs to `l`. -/ def EventuallyEq (l : Filter α) (f g : α → β) : Prop := ∀ᶠ x in l, f x = g x @[inherit_doc] notation:50 f " =ᶠ[" l:50 "] " g:50 => EventuallyEq l f g /-- A function `f` is eventually less than or equal to a function `g` at a filter `l`. -/ def EventuallyLE [LE β] (l : Filter α) (f g : α → β) : Prop := ∀ᶠ x in l, f x ≤ g x @[inherit_doc] notation:50 f " ≤ᶠ[" l:50 "] " g:50 => EventuallyLE l f g /-- The forward map of a filter -/ def map (m : α → β) (f : Filter α) : Filter β where sets := preimage m ⁻¹' f.sets univ_sets := univ_mem sets_of_superset hs st := mem_of_superset hs fun _x hx ↦ st hx inter_sets hs ht := inter_mem hs ht /-- `Filter.Tendsto` is the generic "limit of a function" predicate. `Tendsto f l₁ l₂` asserts that for every `l₂` neighborhood `a`, the `f`-preimage of `a` is an `l₁` neighborhood. -/ def Tendsto (f : α → β) (l₁ : Filter α) (l₂ : Filter β) := l₁.map f ≤ l₂ /-- The inverse map of a filter. A set `s` belongs to `Filter.comap m f` if either of the following equivalent conditions hold. 1. There exists a set `t ∈ f` such that `m ⁻¹' t ⊆ s`. This is used as a definition. 2. The set `kernImage m s = {y | ∀ x, m x = y → x ∈ s}` belongs to `f`, see `Filter.mem_comap'`. 3. The set `(m '' sᶜ)ᶜ` belongs to `f`, see `Filter.mem_comap_iff_compl` and `Filter.compl_mem_comap`. -/ def comap (m : α → β) (f : Filter β) : Filter α where sets := { s | ∃ t ∈ f, m ⁻¹' t ⊆ s } univ_sets := ⟨univ, univ_mem, subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ => ⟨a' ∩ b', inter_mem ha₁ hb₁, inter_subset_inter ha₂ hb₂⟩ /-- Coproduct of filters. -/ protected def coprod (f : Filter α) (g : Filter β) : Filter (α × β) := f.comap Prod.fst ⊔ g.comap Prod.snd /-- Product of filters. This is the filter generated by Cartesian products of elements of the component filters. -/ instance instSProd : SProd (Filter α) (Filter β) (Filter (α × β)) where sprod f g := f.comap Prod.fst ⊓ g.comap Prod.snd theorem prod_eq_inf (f : Filter α) (g : Filter β) : f ×ˢ g = f.comap Prod.fst ⊓ g.comap Prod.snd := rfl /-- The product of an indexed family of filters. -/ def pi {ι : Type*} {α : ι → Type*} (f : ∀ i, Filter (α i)) : Filter (∀ i, α i) := ⨅ i, comap (Function.eval i) (f i) /-- The monadic bind operation on filter is defined the usual way in terms of `map` and `join`. Unfortunately, this `bind` does not result in the expected applicative. See `Filter.seq` for the applicative instance. -/ def bind (f : Filter α) (m : α → Filter β) : Filter β := join (map m f) /-- The applicative sequentiation operation. This is not induced by the bind operation. -/ def seq (f : Filter (α → β)) (g : Filter α) : Filter β where sets := { s | ∃ u ∈ f, ∃ t ∈ g, ∀ m ∈ u, ∀ x ∈ t, (m : α → β) x ∈ s } univ_sets := ⟨univ, univ_mem, univ, univ_mem, fun _ _ _ _ => trivial⟩ sets_of_superset := fun ⟨t₀, t₁, h₀, h₁, h⟩ hst => ⟨t₀, t₁, h₀, h₁, fun _ hx _ hy => hst <| h _ hx _ hy⟩ inter_sets := fun ⟨t₀, ht₀, t₁, ht₁, ht⟩ ⟨u₀, hu₀, u₁, hu₁, hu⟩ => ⟨t₀ ∩ u₀, inter_mem ht₀ hu₀, t₁ ∩ u₁, inter_mem ht₁ hu₁, fun _ ⟨hx₀, hx₁⟩ _ ⟨hy₀, hy₁⟩ => ⟨ht _ hx₀ _ hy₀, hu _ hx₁ _ hy₁⟩⟩ /-- This filter is characterized by `Filter.eventually_curry_iff`: `(∀ᶠ (x : α × β) in f.curry g, p x) ↔ ∀ᶠ (x : α) in f, ∀ᶠ (y : β) in g, p (x, y)`. Useful in adding quantifiers to the middle of `Tendsto`s. See `hasFDerivAt_of_tendstoUniformlyOnFilter`. -/ def curry (f : Filter α) (g : Filter β) : Filter (α × β) := bind f fun a ↦ map (a, ·) g instance : Bind Filter := ⟨@Filter.bind⟩ instance : Functor Filter where map := @Filter.map /-- A variant on `bind` using a function `g` taking a set instead of a member of `α`. This is essentially a push-forward along a function mapping each set to a filter. -/ protected def lift (f : Filter α) (g : Set α → Filter β) := ⨅ s ∈ f, g s /-- Specialize `lift` to functions `Set α → Set β`. This can be viewed as a generalization of `map`. This is essentially a push-forward along a function mapping each set to a set. -/ protected def lift' (f : Filter α) (h : Set α → Set β) := f.lift (𝓟 ∘ h) /-- `f.IsBounded r`: the filter `f` is eventually bounded w.r.t. the relation `r`, i.e. eventually, it is bounded by some uniform bound. `r` will be usually instantiated with `(· ≤ ·)` or `(· ≥ ·)`. -/ def IsBounded (r : α → α → Prop) (f : Filter α) := ∃ b, ∀ᶠ x in f, r x b /-- `f.IsBoundedUnder (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t. the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/ def IsBoundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) := (map u f).IsBounded r /-- `IsCobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated with `≤` or `≥`. There is a subtlety in this definition: we want `f.IsCobounded` to hold for any `f` in the case of complete lattices. This will be relevant to deduce theorems on complete lattices from their versions on conditionally complete lattices with additional assumptions. We have to be careful in the edge case of the trivial filter containing the empty set: the other natural definition `¬ ∀ a, ∀ᶠ n in f, a ≤ n` would not work as well in this case. -/ def IsCobounded (r : α → α → Prop) (f : Filter α) := ∃ b, ∀ a, (∀ᶠ x in f, r x a) → r b a /-- `IsCoboundedUnder (≺) f u` states that the image of the filter `f` under the map `u` does not tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated with `≤` or `≥`. -/ def IsCoboundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) := (map u f).IsCobounded r end Filter namespace Mathlib.Tactic open Lean Meta Elab Tactic /-- `filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms `h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`. The list is an optional parameter, `[]` being its default value. `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for `{ filter_upwards [h₁, ⋯, hₙ], intro a₁ a₂ ⋯ aₖ }`. `filter_upwards [h₁, ⋯, hₙ] using e` is a short form for `{ filter_upwards [h1, ⋯, hn], exact e }`. Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`. Note that in this case, the `aᵢ` terms can be used in `e`. -/ syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")? (" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic elab_rules : tactic | `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do focus do let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly} for e in args.getD #[] |>.reverse do let goal ← getMainGoal replaceMainGoal <| ← goal.withContext <| runTermElab do let m ← mkFreshExprMVar none let lem ← Term.elabTermEnsuringType (← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType) goal.assign lem return [m.mvarId!] liftMetaTactic fun goal => do goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config evalTactic <|← `(tactic| dsimp -zeta only [Set.mem_setOf_eq]) if let some l := wth then evalTactic <|← `(tactic| intro $[$l]*) if let some e := usingArg then evalTactic <|← `(tactic| exact $e) end Mathlib.Tactic
.lake/packages/mathlib/Mathlib/Order/Filter/CountableInter.lean
import Mathlib.Order.Filter.Curry import Mathlib.Data.Set.Countable /-! # Filters with countable intersection property In this file we define `CountableInterFilter` to be the class of filters with the following property: for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well. Two main examples are the `residual` filter defined in `Mathlib/Topology/GDelta.lean` and the `MeasureTheory.ae` filter defined in `Mathlib/MeasureTheory.OuterMeasure/AE`. We reformulate the definition in terms of indexed intersection and in terms of `Filter.Eventually` and provide instances for some basic constructions (`⊥`, `⊤`, `Filter.principal`, `Filter.map`, `Filter.comap`, `Inf.inf`). We also provide a custom constructor `Filter.ofCountableInter` that deduces two axioms of a `Filter` from the countable intersection property. Note that there also exists a typeclass `CardinalInterFilter`, and thus an alternative spelling of `CountableInterFilter` as `CardinalInterFilter l ℵ₁`. The former (defined here) is the preferred spelling; it has the advantage of not requiring the user to import the theory of ordinals. ## Tags filter, countable -/ open Set Filter variable {ι : Sort*} {α β : Type*} /-- A filter `l` has the countable intersection property if for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well. -/ class CountableInterFilter (l : Filter α) : Prop where /-- For a countable collection of sets `s ∈ l`, their intersection belongs to `l` as well. -/ countable_sInter_mem : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l variable {l : Filter α} [CountableInterFilter l] theorem countable_sInter_mem {S : Set (Set α)} (hSc : S.Countable) : ⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l := ⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs), CountableInterFilter.countable_sInter_mem _ hSc⟩ theorem countable_iInter_mem [Countable ι] {s : ι → Set α} : (⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l := sInter_range s ▸ (countable_sInter_mem (countable_range _)).trans forall_mem_range theorem countable_bInter_mem {ι : Type*} {S : Set ι} (hS : S.Countable) {s : ∀ i ∈ S, Set α} : (⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by rw [biInter_eq_iInter] haveI := hS.toEncodable exact countable_iInter_mem.trans Subtype.forall theorem eventually_countable_forall [Countable ι] {p : α → ι → Prop} : (∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by simpa only [Filter.Eventually, setOf_forall] using @countable_iInter_mem _ _ l _ _ fun i => { x | p x i } theorem eventually_countable_ball {ι : Type*} {S : Set ι} (hS : S.Countable) {p : α → ∀ i ∈ S, Prop} : (∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by simpa only [Filter.Eventually, setOf_forall] using @countable_bInter_mem _ l _ _ _ hS fun i hi => { x | p x i hi } theorem EventuallyLE.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : ⋃ i, s i ≤ᶠ[l] ⋃ i, t i := (eventually_countable_forall.2 h).mono fun _ hst hs => mem_iUnion.2 <| (mem_iUnion.1 hs).imp hst theorem EventuallyEq.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : ⋃ i, s i =ᶠ[l] ⋃ i, t i := (EventuallyLE.countable_iUnion fun i => (h i).le).antisymm (EventuallyLE.countable_iUnion fun i => (h i).symm.le) theorem EventuallyLE.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by simp only [biUnion_eq_iUnion] haveI := hS.toEncodable exact EventuallyLE.countable_iUnion fun i => h i i.2 theorem EventuallyEq.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› := (EventuallyLE.countable_bUnion hS fun i hi => (h i hi).le).antisymm (EventuallyLE.countable_bUnion hS fun i hi => (h i hi).symm.le) theorem EventuallyLE.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : ⋂ i, s i ≤ᶠ[l] ⋂ i, t i := (eventually_countable_forall.2 h).mono fun _ hst hs => mem_iInter.2 fun i => hst _ (mem_iInter.1 hs i) theorem EventuallyEq.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : ⋂ i, s i =ᶠ[l] ⋂ i, t i := (EventuallyLE.countable_iInter fun i => (h i).le).antisymm (EventuallyLE.countable_iInter fun i => (h i).symm.le) theorem EventuallyLE.countable_bInter {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› ≤ᶠ[l] ⋂ i ∈ S, t i ‹_› := by simp only [biInter_eq_iInter] haveI := hS.toEncodable exact EventuallyLE.countable_iInter fun i => h i i.2 theorem EventuallyEq.countable_bInter {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› =ᶠ[l] ⋂ i ∈ S, t i ‹_› := (EventuallyLE.countable_bInter hS fun i hi => (h i hi).le).antisymm (EventuallyLE.countable_bInter hS fun i hi => (h i hi).symm.le) /-- Construct a filter with countable intersection property. This constructor deduces `Filter.univ_sets` and `Filter.inter_sets` from the countable intersection property. -/ def Filter.ofCountableInter (l : Set (Set α)) (hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : Filter α where sets := l univ_sets := @sInter_empty α ▸ hl _ countable_empty (empty_subset _) sets_of_superset := h_mono _ _ inter_sets {s t} hs ht := sInter_pair s t ▸ hl _ ((countable_singleton _).insert _) (insert_subset_iff.2 ⟨hs, singleton_subset_iff.2 ht⟩) instance Filter.countableInter_ofCountableInter (l : Set (Set α)) (hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : CountableInterFilter (Filter.ofCountableInter l hl h_mono) := ⟨hl⟩ @[simp] theorem Filter.mem_ofCountableInter {l : Set (Set α)} (hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) {s : Set α} : s ∈ Filter.ofCountableInter l hl h_mono ↔ s ∈ l := Iff.rfl /-- Construct a filter with countable intersection property. Similarly to `Filter.comk`, a set belongs to this filter if its complement satisfies the property. Similarly to `Filter.ofCountableInter`, this constructor deduces some properties from the countable intersection property which becomes the countable union property because we take complements of all sets. -/ def Filter.ofCountableUnion (l : Set (Set α)) (hUnion : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋃₀ S ∈ l) (hmono : ∀ t ∈ l, ∀ s ⊆ t, s ∈ l) : Filter α := by refine .ofCountableInter {s | sᶜ ∈ l} (fun S hSc hSp ↦ ?_) fun s t ht hsub ↦ ?_ · rw [mem_setOf_eq, compl_sInter] apply hUnion (compl '' S) (hSc.image _) intro s hs rw [mem_image] at hs rcases hs with ⟨t, ht, rfl⟩ apply hSp ht · rw [mem_setOf_eq] rw [← compl_subset_compl] at hsub exact hmono sᶜ ht tᶜ hsub instance Filter.countableInter_ofCountableUnion (l : Set (Set α)) (h₁ h₂) : CountableInterFilter (Filter.ofCountableUnion l h₁ h₂) := countableInter_ofCountableInter .. @[simp] theorem Filter.mem_ofCountableUnion {l : Set (Set α)} {hunion hmono s} : s ∈ ofCountableUnion l hunion hmono ↔ l sᶜ := Iff.rfl instance countableInterFilter_principal (s : Set α) : CountableInterFilter (𝓟 s) := ⟨fun _ _ hS => subset_sInter hS⟩ instance countableInterFilter_bot : CountableInterFilter (⊥ : Filter α) := by rw [← principal_empty] apply countableInterFilter_principal instance countableInterFilter_top : CountableInterFilter (⊤ : Filter α) := by rw [← principal_univ] apply countableInterFilter_principal instance (l : Filter β) [CountableInterFilter l] (f : α → β) : CountableInterFilter (comap f l) := by refine ⟨fun S hSc hS => ?_⟩ choose! t htl ht using hS have : (⋂ s ∈ S, t s) ∈ l := (countable_bInter_mem hSc).2 htl refine ⟨_, this, ?_⟩ simpa [preimage_iInter] using iInter₂_mono ht instance (l : Filter α) [CountableInterFilter l] (f : α → β) : CountableInterFilter (map f l) := by refine ⟨fun S hSc hS => ?_⟩ simp only [mem_map, sInter_eq_biInter, preimage_iInter₂] at hS ⊢ exact (countable_bInter_mem hSc).2 hS /-- Infimum of two `CountableInterFilter`s is a `CountableInterFilter`. This is useful, e.g., to automatically get an instance for `residual α ⊓ 𝓟 s`. -/ instance countableInterFilter_inf (l₁ l₂ : Filter α) [CountableInterFilter l₁] [CountableInterFilter l₂] : CountableInterFilter (l₁ ⊓ l₂) := by refine ⟨fun S hSc hS => ?_⟩ choose s hs t ht hst using hS replace hs : (⋂ i ∈ S, s i ‹_›) ∈ l₁ := (countable_bInter_mem hSc).2 hs replace ht : (⋂ i ∈ S, t i ‹_›) ∈ l₂ := (countable_bInter_mem hSc).2 ht refine mem_of_superset (inter_mem_inf hs ht) (subset_sInter fun i hi => ?_) rw [hst i hi] apply inter_subset_inter <;> exact iInter_subset_of_subset i (iInter_subset _ _) /-- Supremum of two `CountableInterFilter`s is a `CountableInterFilter`. -/ instance countableInterFilter_sup (l₁ l₂ : Filter α) [CountableInterFilter l₁] [CountableInterFilter l₂] : CountableInterFilter (l₁ ⊔ l₂) := by refine ⟨fun S hSc hS => ⟨?_, ?_⟩⟩ <;> refine (countable_sInter_mem hSc).2 fun s hs => ?_ exacts [(hS s hs).1, (hS s hs).2] instance CountableInterFilter.curry {α β : Type*} {l : Filter α} {m : Filter β} [CountableInterFilter l] [CountableInterFilter m] : CountableInterFilter (l.curry m) := ⟨by intro S Sct hS simp_rw [mem_curry_iff, mem_sInter, eventually_countable_ball (p := fun _ _ _ => (_, _) ∈ _) Sct, eventually_countable_ball (p := fun _ _ _ => ∀ᶠ (_ : β) in m, _) Sct, ← mem_curry_iff] exact hS⟩ namespace Filter variable (g : Set (Set α)) /-- `Filter.CountableGenerateSets g` is the (sets of the) greatest `countableInterFilter` containing `g`. -/ inductive CountableGenerateSets : Set α → Prop | basic {s : Set α} : s ∈ g → CountableGenerateSets s | univ : CountableGenerateSets univ | superset {s t : Set α} : CountableGenerateSets s → s ⊆ t → CountableGenerateSets t | sInter {S : Set (Set α)} : S.Countable → (∀ s ∈ S, CountableGenerateSets s) → CountableGenerateSets (⋂₀ S) /-- `Filter.countableGenerate g` is the greatest `countableInterFilter` containing `g`. -/ def countableGenerate : Filter α := ofCountableInter (CountableGenerateSets g) (fun _ => CountableGenerateSets.sInter) fun _ _ => CountableGenerateSets.superset deriving CountableInterFilter variable {g} /-- A set is in the `countableInterFilter` generated by `g` if and only if it contains a countable intersection of elements of `g`. -/ theorem mem_countableGenerate_iff {s : Set α} : s ∈ countableGenerate g ↔ ∃ S : Set (Set α), S ⊆ g ∧ S.Countable ∧ ⋂₀ S ⊆ s := by constructor <;> intro h · induction h with | @basic s hs => exact ⟨{s}, by simp [hs, subset_refl]⟩ | univ => exact ⟨∅, by simp⟩ | superset _ _ ih => refine Exists.imp (fun S => ?_) ih; tauto | @sInter S Sct _ ih => choose T Tg Tct hT using ih refine ⟨⋃ (s) (H : s ∈ S), T s H, by simpa, Sct.biUnion Tct, ?_⟩ apply subset_sInter intro s H exact subset_trans (sInter_subset_sInter (subset_iUnion₂ s H)) (hT s H) rcases h with ⟨S, Sg, Sct, hS⟩ refine mem_of_superset ((countable_sInter_mem Sct).mpr ?_) hS intro s H exact CountableGenerateSets.basic (Sg H) theorem le_countableGenerate_iff_of_countableInterFilter {f : Filter α} [CountableInterFilter f] : f ≤ countableGenerate g ↔ g ⊆ f.sets := by constructor <;> intro h · exact subset_trans (fun s => CountableGenerateSets.basic) h intro s hs induction hs with | basic hs => exact h hs | univ => exact univ_mem | superset _ st ih => exact mem_of_superset ih st | sInter Sct _ ih => exact (countable_sInter_mem Sct).mpr ih variable (g) /-- `countableGenerate g` is the greatest `countableInterFilter` containing `g`. -/ theorem countableGenerate_isGreatest : IsGreatest { f : Filter α | CountableInterFilter f ∧ g ⊆ f.sets } (countableGenerate g) := by refine ⟨⟨inferInstance, fun s => CountableGenerateSets.basic⟩, ?_⟩ rintro f ⟨fct, hf⟩ rwa [@le_countableGenerate_iff_of_countableInterFilter _ _ _ fct] end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/IndicatorFunction.lean
import Mathlib.Algebra.Group.Indicator import Mathlib.Order.CompleteLattice.Finset import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.AtTopBot.Defs import Mathlib.Order.Filter.Tendsto /-! # Indicator function and filters Properties of additive and multiplicative indicator functions involving `=ᶠ` and `≤ᶠ`. ## Tags indicator, characteristic, filter -/ variable {α β M E : Type*} open Set Filter section One variable [One M] {s t : Set α} {f g : α → M} {a : α} {l : Filter α} @[to_additive] theorem mulIndicator_eventuallyEq (hf : f =ᶠ[l ⊓ 𝓟 s] g) (hs : s =ᶠ[l] t) : mulIndicator s f =ᶠ[l] mulIndicator t g := (eventually_inf_principal.1 hf).mp <| hs.mem_iff.mono fun x hst hfg => by_cases (fun hxs : x ∈ s => by simp only [*, hst.1 hxs, mulIndicator_of_mem]) (fun hxs => by simp only [mulIndicator_of_notMem, hxs, mt hst.2 hxs, not_false_eq_true]) end One section Monoid variable [Monoid M] {s t : Set α} {f g : α → M} {a : α} {l : Filter α} @[to_additive] theorem mulIndicator_union_eventuallyEq (h : ∀ᶠ a in l, a ∉ s ∩ t) : mulIndicator (s ∪ t) f =ᶠ[l] mulIndicator s f * mulIndicator t f := h.mono fun _a ha => mulIndicator_union_of_notMem_inter ha _ end Monoid section Order variable [One β] [Preorder β] {s t : Set α} {f g : α → β} {a : α} {l : Filter α} @[to_additive] theorem mulIndicator_eventuallyLE_mulIndicator (h : f ≤ᶠ[l ⊓ 𝓟 s] g) : mulIndicator s f ≤ᶠ[l] mulIndicator s g := (eventually_inf_principal.1 h).mono fun _ => mulIndicator_rel_mulIndicator le_rfl end Order @[to_additive] theorem Monotone.mulIndicator_eventuallyEq_iUnion {ι} [Preorder ι] [One β] (s : ι → Set α) (hs : Monotone s) (f : α → β) (a : α) : (fun i => mulIndicator (s i) f a) =ᶠ[atTop] fun _ ↦ mulIndicator (⋃ i, s i) f a := by classical exact hs.piecewise_eventually_eq_iUnion f 1 a @[to_additive] theorem Monotone.tendsto_mulIndicator {ι} [Preorder ι] [One β] (s : ι → Set α) (hs : Monotone s) (f : α → β) (a : α) : Tendsto (fun i => mulIndicator (s i) f a) atTop (pure <| mulIndicator (⋃ i, s i) f a) := tendsto_pure.2 <| hs.mulIndicator_eventuallyEq_iUnion s f a @[to_additive] theorem Antitone.mulIndicator_eventuallyEq_iInter {ι} [Preorder ι] [One β] (s : ι → Set α) (hs : Antitone s) (f : α → β) (a : α) : (fun i => mulIndicator (s i) f a) =ᶠ[atTop] fun _ ↦ mulIndicator (⋂ i, s i) f a := by classical exact hs.piecewise_eventually_eq_iInter f 1 a @[to_additive] theorem Antitone.tendsto_mulIndicator {ι} [Preorder ι] [One β] (s : ι → Set α) (hs : Antitone s) (f : α → β) (a : α) : Tendsto (fun i => mulIndicator (s i) f a) atTop (pure <| mulIndicator (⋂ i, s i) f a) := tendsto_pure.2 <| hs.mulIndicator_eventuallyEq_iInter s f a @[to_additive] theorem mulIndicator_biUnion_finset_eventuallyEq {ι} [One β] (s : ι → Set α) (f : α → β) (a : α) : (fun n : Finset ι => mulIndicator (⋃ i ∈ n, s i) f a) =ᶠ[atTop] fun _ ↦ mulIndicator (iUnion s) f a := by rw [iUnion_eq_iUnion_finset s] apply Monotone.mulIndicator_eventuallyEq_iUnion exact fun _ _ ↦ biUnion_subset_biUnion_left @[to_additive] theorem tendsto_mulIndicator_biUnion_finset {ι} [One β] (s : ι → Set α) (f : α → β) (a : α) : Tendsto (fun n : Finset ι => mulIndicator (⋃ i ∈ n, s i) f a) atTop (pure <| mulIndicator (iUnion s) f a) := tendsto_pure.2 <| mulIndicator_biUnion_finset_eventuallyEq s f a @[to_additive] protected theorem Filter.EventuallyEq.mulSupport [One β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : Function.mulSupport f =ᶠ[l] Function.mulSupport g := h.preimage ({1}ᶜ : Set β) @[to_additive] protected theorem Filter.EventuallyEq.mulIndicator [One β] {l : Filter α} {f g : α → β} {s : Set α} (hfg : f =ᶠ[l] g) : s.mulIndicator f =ᶠ[l] s.mulIndicator g := mulIndicator_eventuallyEq (hfg.filter_mono inf_le_left) EventuallyEq.rfl @[to_additive] theorem Filter.EventuallyEq.mulIndicator_one [One β] {l : Filter α} {f : α → β} {s : Set α} (hf : f =ᶠ[l] 1) : s.mulIndicator f =ᶠ[l] 1 := hf.mulIndicator.trans <| by rw [mulIndicator_one'] @[to_additive] theorem Filter.EventuallyEq.of_mulIndicator [One β] {l : Filter α} {f : α → β} (hf : ∀ᶠ x in l, f x ≠ 1) {s t : Set α} (h : s.mulIndicator f =ᶠ[l] t.mulIndicator f) : s =ᶠ[l] t := by have : ∀ {s : Set α}, Function.mulSupport (s.mulIndicator f) =ᶠ[l] s := fun {s} ↦ by rw [mulSupport_mulIndicator] exact (hf.mono fun x hx ↦ and_iff_left hx).set_eq exact this.symm.trans <| h.mulSupport.trans this @[to_additive] theorem Filter.EventuallyEq.of_mulIndicator_const [One β] {l : Filter α} {c : β} (hc : c ≠ 1) {s t : Set α} (h : s.mulIndicator (fun _ ↦ c) =ᶠ[l] t.mulIndicator fun _ ↦ c) : s =ᶠ[l] t := .of_mulIndicator (Eventually.of_forall fun _ ↦ hc) h @[to_additive] theorem Filter.mulIndicator_const_eventuallyEq [One β] {l : Filter α} {c : β} (hc : c ≠ 1) {s t : Set α} : s.mulIndicator (fun _ ↦ c) =ᶠ[l] t.mulIndicator (fun _ ↦ c) ↔ s =ᶠ[l] t := ⟨.of_mulIndicator_const hc, mulIndicator_eventuallyEq .rfl⟩
.lake/packages/mathlib/Mathlib/Order/Filter/CardinalInter.lean
import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.CountableInter import Mathlib.SetTheory.Cardinal.Regular import Mathlib.Tactic.Linarith /-! # Filters with a cardinal intersection property In this file we define `CardinalInterFilter l c` to be the class of filters with the following property: for any collection of sets `s ∈ l` with cardinality strictly less than `c`, their intersection belongs to `l` as well. # Main results * `Filter.cardinalInterFilter_aleph0` establishes that every filter `l` is a `CardinalInterFilter l ℵ₀` * `CardinalInterFilter.toCountableInterFilter` establishes that every `CardinalInterFilter l c` with `c > ℵ₀` is a `CountableInterFilter`. * `CountableInterFilter.toCardinalInterFilter` establishes that every `CountableInterFilter l` is a `CardinalInterFilter l ℵ₁`. * `CardinalInterFilter.of_CardinalInterFilter_of_lt` establishes that we have `CardinalInterFilter l c` → `CardinalInterFilter l a` for all `a < c`. ## Tags filter, cardinal -/ open Set Filter Cardinal universe u variable {ι : Type u} {α β : Type u} {c : Cardinal.{u}} /-- A filter `l` has the cardinal `c` intersection property if for any collection of less than `c` sets `s ∈ l`, their intersection belongs to `l` as well. -/ class CardinalInterFilter (l : Filter α) (c : Cardinal.{u}) : Prop where /-- For a collection of sets `s ∈ l` with cardinality below c, their intersection belongs to `l` as well. -/ cardinal_sInter_mem : ∀ S : Set (Set α), (#S < c) → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l variable {l : Filter α} theorem cardinal_sInter_mem {S : Set (Set α)} [CardinalInterFilter l c] (hSc : #S < c) : ⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l := ⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs), CardinalInterFilter.cardinal_sInter_mem _ hSc⟩ /-- Every filter is a CardinalInterFilter with c = ℵ₀ -/ theorem _root_.Filter.cardinalInterFilter_aleph0 (l : Filter α) : CardinalInterFilter l ℵ₀ where cardinal_sInter_mem := by simp_all only [lt_aleph0_iff_subtype_finite, setOf_mem_eq, sInter_mem, implies_true] /-- Every CardinalInterFilter with c > ℵ₀ is a CountableInterFilter -/ theorem CardinalInterFilter.toCountableInterFilter (l : Filter α) [CardinalInterFilter l c] (hc : ℵ₀ < c) : CountableInterFilter l where countable_sInter_mem S hS a := CardinalInterFilter.cardinal_sInter_mem S (lt_of_le_of_lt (Set.Countable.le_aleph0 hS) hc) a /-- Every CountableInterFilter is a CardinalInterFilter with c = ℵ₁ -/ instance CountableInterFilter.toCardinalInterFilter (l : Filter α) [CountableInterFilter l] : CardinalInterFilter l ℵ₁ where cardinal_sInter_mem S hS a := CountableInterFilter.countable_sInter_mem S ((countable_iff_lt_aleph_one S).mpr hS) a theorem cardinalInterFilter_aleph_one_iff : CardinalInterFilter l ℵ₁ ↔ CountableInterFilter l := ⟨fun _ ↦ ⟨fun S h a ↦ CardinalInterFilter.cardinal_sInter_mem S ((countable_iff_lt_aleph_one S).1 h) a⟩, fun _ ↦ CountableInterFilter.toCardinalInterFilter l⟩ /-- Every CardinalInterFilter for some c also is a CardinalInterFilter for some a ≤ c -/ theorem CardinalInterFilter.of_cardinalInterFilter_of_le (l : Filter α) [CardinalInterFilter l c] {a : Cardinal.{u}} (hac : a ≤ c) : CardinalInterFilter l a where cardinal_sInter_mem S hS a := CardinalInterFilter.cardinal_sInter_mem S (lt_of_lt_of_le hS hac) a theorem CardinalInterFilter.of_cardinalInterFilter_of_lt (l : Filter α) [CardinalInterFilter l c] {a : Cardinal.{u}} (hac : a < c) : CardinalInterFilter l a := CardinalInterFilter.of_cardinalInterFilter_of_le l (hac.le) namespace Filter variable [CardinalInterFilter l c] theorem cardinal_iInter_mem {s : ι → Set α} (hic : #ι < c) : (⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l := by rw [← sInter_range _] apply (cardinal_sInter_mem (lt_of_le_of_lt Cardinal.mk_range_le hic)).trans exact forall_mem_range theorem cardinal_bInter_mem {S : Set ι} (hS : #S < c) {s : ∀ i ∈ S, Set α} : (⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by rw [biInter_eq_iInter] exact (cardinal_iInter_mem hS).trans Subtype.forall theorem eventually_cardinal_forall {p : α → ι → Prop} (hic : #ι < c) : (∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by simp only [Filter.Eventually, setOf_forall] exact cardinal_iInter_mem hic theorem eventually_cardinal_ball {S : Set ι} (hS : #S < c) {p : α → ∀ i ∈ S, Prop} : (∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by simp only [Filter.Eventually, setOf_forall] exact cardinal_bInter_mem hS theorem EventuallyLE.cardinal_iUnion {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i ≤ᶠ[l] t i) : ⋃ i, s i ≤ᶠ[l] ⋃ i, t i := ((eventually_cardinal_forall hic).2 h).mono fun _ hst hs => mem_iUnion.2 <| (mem_iUnion.1 hs).imp hst theorem EventuallyEq.cardinal_iUnion {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i =ᶠ[l] t i) : ⋃ i, s i =ᶠ[l] ⋃ i, t i := (EventuallyLE.cardinal_iUnion hic fun i => (h i).le).antisymm (EventuallyLE.cardinal_iUnion hic fun i => (h i).symm.le) theorem EventuallyLE.cardinal_bUnion {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by simp only [biUnion_eq_iUnion] exact EventuallyLE.cardinal_iUnion hS fun i => h i i.2 theorem EventuallyEq.cardinal_bUnion {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› := (EventuallyLE.cardinal_bUnion hS fun i hi => (h i hi).le).antisymm (EventuallyLE.cardinal_bUnion hS fun i hi => (h i hi).symm.le) theorem EventuallyLE.cardinal_iInter {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i ≤ᶠ[l] t i) : ⋂ i, s i ≤ᶠ[l] ⋂ i, t i := ((eventually_cardinal_forall hic).2 h).mono fun _ hst hs => mem_iInter.2 fun i => hst _ (mem_iInter.1 hs i) theorem EventuallyEq.cardinal_iInter {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i =ᶠ[l] t i) : ⋂ i, s i =ᶠ[l] ⋂ i, t i := (EventuallyLE.cardinal_iInter hic fun i => (h i).le).antisymm (EventuallyLE.cardinal_iInter hic fun i => (h i).symm.le) theorem EventuallyLE.cardinal_bInter {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› ≤ᶠ[l] ⋂ i ∈ S, t i ‹_› := by simp only [biInter_eq_iInter] exact EventuallyLE.cardinal_iInter hS fun i => h i i.2 theorem EventuallyEq.cardinal_bInter {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› =ᶠ[l] ⋂ i ∈ S, t i ‹_› := (EventuallyLE.cardinal_bInter hS fun i hi => (h i hi).le).antisymm (EventuallyLE.cardinal_bInter hS fun i hi => (h i hi).symm.le) /-- Construct a filter with cardinal `c` intersection property. This constructor deduces `Filter.univ_sets` and `Filter.inter_sets` from the cardinal `c` intersection property. -/ def ofCardinalInter (l : Set (Set α)) (hc : 2 < c) (hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : Filter α where sets := l univ_sets := sInter_empty ▸ hl ∅ (mk_eq_zero (∅ : Set (Set α)) ▸ lt_trans zero_lt_two hc) (empty_subset _) sets_of_superset := h_mono _ _ inter_sets {s t} hs ht := sInter_pair s t ▸ by apply hl _ (?_) (insert_subset_iff.2 ⟨hs, singleton_subset_iff.2 ht⟩) have : #({s, t} : Set (Set α)) ≤ 2 := by calc _ ≤ #({t} : Set (Set α)) + 1 := Cardinal.mk_insert_le _ = 2 := by norm_num exact lt_of_le_of_lt this hc instance cardinalInter_ofCardinalInter (l : Set (Set α)) (hc : 2 < c) (hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : CardinalInterFilter (Filter.ofCardinalInter l hc hl h_mono) c := ⟨hl⟩ @[simp] theorem mem_ofCardinalInter {l : Set (Set α)} (hc : 2 < c) (hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) {s : Set α} : s ∈ Filter.ofCardinalInter l hc hl h_mono ↔ s ∈ l := Iff.rfl /-- Construct a filter with cardinal `c` intersection property. Similarly to `Filter.comk`, a set belongs to this filter if its complement satisfies the property. Similarly to `Filter.ofCardinalInter`, this constructor deduces some properties from the cardinal `c` intersection property which becomes the cardinal `c` union property because we take complements of all sets. -/ def ofCardinalUnion (l : Set (Set α)) (hc : 2 < c) (hUnion : ∀ S : Set (Set α), (#S < c) → (∀ s ∈ S, s ∈ l) → ⋃₀ S ∈ l) (hmono : ∀ t ∈ l, ∀ s ⊆ t, s ∈ l) : Filter α := by refine .ofCardinalInter {s | sᶜ ∈ l} hc (fun S hSc hSp ↦ ?_) fun s t ht hsub ↦ ?_ · rw [mem_setOf_eq, compl_sInter] apply hUnion (compl '' S) (lt_of_le_of_lt mk_image_le hSc) intro s hs rw [mem_image] at hs rcases hs with ⟨t, ht, rfl⟩ apply hSp ht · rw [mem_setOf_eq] rw [← compl_subset_compl] at hsub exact hmono sᶜ ht tᶜ hsub instance cardinalInter_ofCardinalUnion (l : Set (Set α)) (hc : 2 < c) (h₁ h₂) : CardinalInterFilter (Filter.ofCardinalUnion l hc h₁ h₂) c := cardinalInter_ofCardinalInter .. @[simp] theorem mem_ofCardinalUnion {l : Set (Set α)} (hc : 2 < c) {hunion hmono s} : s ∈ ofCardinalUnion l hc hunion hmono ↔ l sᶜ := Iff.rfl instance cardinalInterFilter_principal (s : Set α) : CardinalInterFilter (𝓟 s) c := ⟨fun _ _ hS => subset_sInter hS⟩ instance cardinalInterFilter_bot : CardinalInterFilter (⊥ : Filter α) c := by rw [← principal_empty] apply cardinalInterFilter_principal instance cardinalInterFilter_top : CardinalInterFilter (⊤ : Filter α) c := by rw [← principal_univ] apply cardinalInterFilter_principal instance (l : Filter β) [CardinalInterFilter l c] (f : α → β) : CardinalInterFilter (comap f l) c := by refine ⟨fun S hSc hS => ?_⟩ choose! t htl ht using hS refine ⟨_, (cardinal_bInter_mem hSc).2 htl, ?_⟩ simpa [preimage_iInter] using iInter₂_mono ht instance (l : Filter α) [CardinalInterFilter l c] (f : α → β) : CardinalInterFilter (map f l) c := by refine ⟨fun S hSc hS => ?_⟩ simp only [mem_map, sInter_eq_biInter, preimage_iInter₂] at hS ⊢ exact (cardinal_bInter_mem hSc).2 hS /-- Infimum of two `CardinalInterFilter`s is a `CardinalInterFilter`. This is useful, e.g., to automatically get an instance for `residual α ⊓ 𝓟 s`. -/ instance cardinalInterFilter_inf_eq (l₁ l₂ : Filter α) [CardinalInterFilter l₁ c] [CardinalInterFilter l₂ c] : CardinalInterFilter (l₁ ⊓ l₂) c := by refine ⟨fun S hSc hS => ?_⟩ choose s hs t ht hst using hS replace hs : (⋂ i ∈ S, s i ‹_›) ∈ l₁ := (cardinal_bInter_mem hSc).2 hs replace ht : (⋂ i ∈ S, t i ‹_›) ∈ l₂ := (cardinal_bInter_mem hSc).2 ht refine mem_of_superset (inter_mem_inf hs ht) (subset_sInter fun i hi => ?_) rw [hst i hi] apply inter_subset_inter <;> exact iInter_subset_of_subset i (iInter_subset _ _) instance cardinalInterFilter_inf (l₁ l₂ : Filter α) {c₁ c₂ : Cardinal.{u}} [CardinalInterFilter l₁ c₁] [CardinalInterFilter l₂ c₂] : CardinalInterFilter (l₁ ⊓ l₂) (c₁ ⊓ c₂) := by have : CardinalInterFilter l₁ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₁ inf_le_left have : CardinalInterFilter l₂ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₂ inf_le_right exact cardinalInterFilter_inf_eq _ _ /-- Supremum of two `CardinalInterFilter`s is a `CardinalInterFilter`. -/ instance cardinalInterFilter_sup_eq (l₁ l₂ : Filter α) [CardinalInterFilter l₁ c] [CardinalInterFilter l₂ c] : CardinalInterFilter (l₁ ⊔ l₂) c := by refine ⟨fun S hSc hS => ⟨?_, ?_⟩⟩ <;> refine (cardinal_sInter_mem hSc).2 fun s hs => ?_ exacts [(hS s hs).1, (hS s hs).2] instance cardinalInterFilter_sup (l₁ l₂ : Filter α) {c₁ c₂ : Cardinal.{u}} [CardinalInterFilter l₁ c₁] [CardinalInterFilter l₂ c₂] : CardinalInterFilter (l₁ ⊔ l₂) (c₁ ⊓ c₂) := by have : CardinalInterFilter l₁ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₁ inf_le_left have : CardinalInterFilter l₂ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₂ inf_le_right exact cardinalInterFilter_sup_eq _ _ variable (g : Set (Set α)) /-- `Filter.CardinalGenerateSets c g` is the (sets of the) greatest `cardinalInterFilter c` containing `g`. -/ inductive CardinalGenerateSets : Set α → Prop | basic {s : Set α} : s ∈ g → CardinalGenerateSets s | univ : CardinalGenerateSets univ | superset {s t : Set α} : CardinalGenerateSets s → s ⊆ t → CardinalGenerateSets t | sInter {S : Set (Set α)} : (#S < c) → (∀ s ∈ S, CardinalGenerateSets s) → CardinalGenerateSets (⋂₀ S) /-- `Filter.cardinalGenerate c g` is the greatest `cardinalInterFilter c` containing `g`. -/ def cardinalGenerate (hc : 2 < c) : Filter α := ofCardinalInter (CardinalGenerateSets g) hc (fun _ => CardinalGenerateSets.sInter) fun _ _ => CardinalGenerateSets.superset lemma cardinalInter_ofCardinalGenerate (hc : 2 < c) : CardinalInterFilter (cardinalGenerate g hc) c := by delta cardinalGenerate apply cardinalInter_ofCardinalInter _ _ _ variable {g} /-- A set is in the `cardinalInterFilter` generated by `g` if and only if it contains an intersection of `c` elements of `g`. -/ theorem mem_cardinaleGenerate_iff {s : Set α} {hreg : c.IsRegular} : s ∈ cardinalGenerate g (IsRegular.nat_lt hreg 2) ↔ ∃ S : Set (Set α), S ⊆ g ∧ (#S < c) ∧ ⋂₀ S ⊆ s := by constructor <;> intro h · induction h with | @basic s hs => refine ⟨{s}, singleton_subset_iff.mpr hs, ?_⟩ simpa [subset_refl] using IsRegular.nat_lt hreg 1 | univ => exact ⟨∅, ⟨empty_subset g, mk_eq_zero (∅ : Set <| Set α) ▸ IsRegular.nat_lt hreg 0, by simp⟩⟩ | superset _ _ ih => exact Exists.imp (by tauto) ih | @sInter S Sct _ ih => choose T Tg Tct hT using ih refine ⟨⋃ (s) (H : s ∈ S), T s H, by simpa, (Cardinal.card_biUnion_lt_iff_forall_of_isRegular hreg Sct).2 Tct, ?_⟩ apply subset_sInter apply fun s H => subset_trans (sInter_subset_sInter (subset_iUnion₂ s H)) (hT s H) rcases h with ⟨S, Sg, Sct, hS⟩ have : CardinalInterFilter (cardinalGenerate g (IsRegular.nat_lt hreg 2)) c := cardinalInter_ofCardinalGenerate _ _ exact mem_of_superset ((cardinal_sInter_mem Sct).mpr (fun s H => CardinalGenerateSets.basic (Sg H))) hS theorem le_cardinalGenerate_iff_of_cardinalInterFilter {f : Filter α} [CardinalInterFilter f c] (hc : 2 < c) : f ≤ cardinalGenerate g hc ↔ g ⊆ f.sets := by constructor <;> intro h · exact subset_trans (fun s => CardinalGenerateSets.basic) h intro s hs induction hs with | basic hs => exact h hs | univ => exact univ_mem | superset _ st ih => exact mem_of_superset ih st | sInter Sct _ ih => exact (cardinal_sInter_mem Sct).mpr ih /-- `cardinalGenerate g hc` is the greatest `cardinalInterFilter c` containing `g`. -/ theorem cardinalGenerate_isGreatest (hc : 2 < c) : IsGreatest { f : Filter α | CardinalInterFilter f c ∧ g ⊆ f.sets } (cardinalGenerate g hc) := by refine ⟨⟨cardinalInter_ofCardinalGenerate _ _, fun s => CardinalGenerateSets.basic⟩, ?_⟩ rintro f ⟨fct, hf⟩ rwa [le_cardinalGenerate_iff_of_cardinalInterFilter] end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Ker.lean
import Mathlib.Order.Filter.Map /-! # Kernel of a filter In this file we define the *kernel* `Filter.ker f` of a filter `f` to be the intersection of all its sets. We also prove that `Filter.principal` and `Filter.ker` form a Galois coinsertion and prove other basic theorems about `Filter.ker`. -/ open Function Set namespace Filter variable {ι : Sort*} {α β : Type*} {f g : Filter α} {s : Set α} {a : α} lemma ker_def (f : Filter α) : f.ker = ⋂ s ∈ f, s := sInter_eq_biInter @[simp] lemma mem_ker : a ∈ f.ker ↔ ∀ s ∈ f, a ∈ s := mem_sInter @[simp] lemma subset_ker : s ⊆ f.ker ↔ ∀ t ∈ f, s ⊆ t := subset_sInter_iff /-- `Filter.principal` forms a Galois coinsertion with `Filter.ker`. -/ def gi_principal_ker : GaloisCoinsertion (𝓟 : Set α → Filter α) ker := GaloisConnection.toGaloisCoinsertion (fun s f ↦ by simp [principal_le_iff]) <| by simp only [le_iff_subset, subset_def, mem_ker, mem_principal]; aesop lemma ker_mono : Monotone (ker : Filter α → Set α) := gi_principal_ker.gc.monotone_u lemma ker_surjective : Surjective (ker : Filter α → Set α) := gi_principal_ker.u_surjective @[simp] lemma ker_bot : ker (⊥ : Filter α) = ∅ := sInter_eq_empty_iff.2 fun _ ↦ ⟨∅, trivial, id⟩ @[simp] lemma ker_top : ker (⊤ : Filter α) = univ := gi_principal_ker.gc.u_top @[simp] lemma ker_eq_univ : ker f = univ ↔ f = ⊤ := gi_principal_ker.gc.u_eq_top.trans <| by simp @[simp] lemma ker_inf (f g : Filter α) : ker (f ⊓ g) = ker f ∩ ker g := gi_principal_ker.gc.u_inf @[simp] lemma ker_iInf (f : ι → Filter α) : ker (⨅ i, f i) = ⋂ i, ker (f i) := gi_principal_ker.gc.u_iInf @[simp] lemma ker_sInf (S : Set (Filter α)) : ker (sInf S) = ⋂ f ∈ S, ker f := gi_principal_ker.gc.u_sInf @[simp] lemma ker_principal (s : Set α) : ker (𝓟 s) = s := gi_principal_ker.u_l_eq _ @[simp] lemma ker_pure (a : α) : ker (pure a) = {a} := by rw [← principal_singleton, ker_principal] @[simp] lemma ker_comap (m : α → β) (f : Filter β) : ker (comap m f) = m ⁻¹' ker f := by ext a simp only [mem_ker, mem_comap, forall_exists_index, and_imp, @forall_swap (Set α), mem_preimage] exact forall₂_congr fun s _ ↦ ⟨fun h ↦ h _ Subset.rfl, fun ha t ht ↦ ht ha⟩ @[simp] theorem ker_iSup (f : ι → Filter α) : ker (⨆ i, f i) = ⋃ i, ker (f i) := by refine subset_antisymm (fun x hx ↦ ?_) ker_mono.le_map_iSup simp only [mem_iUnion, mem_ker] at hx ⊢ contrapose! hx choose s hsf hxs using hx refine ⟨⋃ i, s i, ?_, by simpa⟩ exact mem_iSup.2 fun i ↦ mem_of_superset (hsf i) (subset_iUnion s i) @[simp] theorem ker_sSup (S : Set (Filter α)) : ker (sSup S) = ⋃ f ∈ S, ker f := by simp [sSup_eq_iSup] @[simp] theorem ker_sup (f g : Filter α) : ker (f ⊔ g) = ker f ∪ ker g := by rw [← sSup_pair, ker_sSup, biUnion_pair] @[simp] lemma ker_prod (f : Filter α) (g : Filter β) : ker (f ×ˢ g) = ker f ×ˢ ker g := by simp [Set.prod_eq, Filter.prod_eq_inf] @[simp] lemma ker_pi {ι : Type*} {α : ι → Type*} (f : (i : ι) → Filter (α i)) : ker (Filter.pi f) = univ.pi (fun i => ker (f i)) := by simp [Set.pi_def, Filter.pi] end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/ListTraverse.lean
import Mathlib.Control.Traversable.Instances import Mathlib.Order.Filter.Map /-! # Properties of `Traversable.traverse` on `List`s and `Filter`s In this file we prove basic properties (monotonicity, membership) for `Traversable.traverse f l`, where `f : β → Filter α` and `l : List β`. -/ open Set List namespace Filter universe u variable {α β γ : Type u} {f : β → Filter α} {s : γ → Set α} theorem sequence_mono : ∀ as bs : List (Filter α), Forall₂ (· ≤ ·) as bs → sequence as ≤ sequence bs | [], [], Forall₂.nil => le_rfl | _::as, _::bs, Forall₂.cons h hs => seq_mono (map_mono h) (sequence_mono as bs hs) theorem mem_traverse : ∀ (fs : List β) (us : List γ), Forall₂ (fun b c => s c ∈ f b) fs us → traverse s us ∈ traverse f fs | [], [], Forall₂.nil => mem_pure.2 <| mem_singleton _ | _::fs, _::us, Forall₂.cons h hs => seq_mem_seq (image_mem_map h) (mem_traverse fs us hs) -- TODO: add a `Filter.HasBasis` statement theorem mem_traverse_iff (fs : List β) (t : Set (List α)) : t ∈ traverse f fs ↔ ∃ us : List (Set α), Forall₂ (fun b (s : Set α) => s ∈ f b) fs us ∧ sequence us ⊆ t := by constructor · induction fs generalizing t with | nil => simp only [sequence, mem_pure, imp_self, forall₂_nil_left_iff, exists_eq_left, Set.pure_def, singleton_subset_iff, traverse_nil] | cons b fs ih => intro ht rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩ rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hwu⟩ rcases ih v hv with ⟨us, hus, hu⟩ exact ⟨w::us, Forall₂.cons hw hus, (Set.seq_mono hwu hu).trans ht⟩ · rintro ⟨us, hus, hs⟩ exact mem_of_superset (mem_traverse _ _ hus) hs end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Subsingleton.lean
import Mathlib.Order.Filter.CountablyGenerated import Mathlib.Order.Filter.Prod import Mathlib.Order.Filter.Ultrafilter.Defs /-! # Subsingleton filters We say that a filter `l` is a *subsingleton* if there exists a subsingleton set `s ∈ l`. Equivalently, `l` is either `⊥` or `pure a` for some `a`. -/ open Set variable {α β : Type*} {l : Filter α} namespace Filter /-- We say that a filter is a *subsingleton* if there exists a subsingleton set that belongs to the filter. -/ protected def Subsingleton (l : Filter α) : Prop := ∃ s ∈ l, Set.Subsingleton s theorem HasBasis.subsingleton_iff {ι : Sort*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) : l.Subsingleton ↔ ∃ i, p i ∧ (s i).Subsingleton := h.exists_iff fun _ _ hsub h ↦ h.anti hsub theorem Subsingleton.anti {l'} (hl : l.Subsingleton) (hl' : l' ≤ l) : l'.Subsingleton := let ⟨s, hsl, hs⟩ := hl; ⟨s, hl' hsl, hs⟩ @[nontriviality] theorem Subsingleton.of_subsingleton [Subsingleton α] : l.Subsingleton := ⟨univ, univ_mem, subsingleton_univ⟩ theorem Subsingleton.map (hl : l.Subsingleton) (f : α → β) : (map f l).Subsingleton := let ⟨s, hsl, hs⟩ := hl; ⟨f '' s, image_mem_map hsl, hs.image f⟩ theorem Subsingleton.prod (hl : l.Subsingleton) {l' : Filter β} (hl' : l'.Subsingleton) : (l ×ˢ l').Subsingleton := let ⟨s, hsl, hs⟩ := hl; let ⟨t, htl', ht⟩ := hl'; ⟨s ×ˢ t, prod_mem_prod hsl htl', hs.prod ht⟩ @[simp] theorem subsingleton_pure {a : α} : Filter.Subsingleton (pure a) := ⟨{a}, rfl, subsingleton_singleton⟩ @[simp] theorem subsingleton_bot : Filter.Subsingleton (⊥ : Filter α) := ⟨∅, trivial, subsingleton_empty⟩ /-- A nontrivial subsingleton filter is equal to `pure a` for some `a`. -/ theorem Subsingleton.exists_eq_pure [l.NeBot] (hl : l.Subsingleton) : ∃ a, l = pure a := by rcases hl with ⟨s, hsl, hs⟩ rcases exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨nonempty_of_mem hsl, hs⟩ with ⟨a, rfl⟩ refine ⟨a, (NeBot.le_pure_iff ‹_›).1 ?_⟩ rwa [le_pure_iff] /-- A filter is a subsingleton iff it is equal to `⊥` or to `pure a` for some `a`. -/ theorem subsingleton_iff_bot_or_pure : l.Subsingleton ↔ l = ⊥ ∨ ∃ a, l = pure a := by refine ⟨fun hl ↦ ?_, ?_⟩ · exact (eq_or_neBot l).imp_right (@Subsingleton.exists_eq_pure _ _ · hl) · rintro (rfl | ⟨a, rfl⟩) <;> simp /-- In a nonempty type, a filter is a subsingleton iff it is less than or equal to a pure filter. -/ theorem subsingleton_iff_exists_le_pure [Nonempty α] : l.Subsingleton ↔ ∃ a, l ≤ pure a := by rcases eq_or_neBot l with rfl | hbot · simp · simp [subsingleton_iff_bot_or_pure, ← hbot.le_pure_iff, hbot.ne] theorem subsingleton_iff_exists_singleton_mem [Nonempty α] : l.Subsingleton ↔ ∃ a, {a} ∈ l := by simp only [subsingleton_iff_exists_le_pure, le_pure_iff] /-- A subsingleton filter on a nonempty type is less than or equal to `pure a` for some `a`. -/ alias ⟨Subsingleton.exists_le_pure, _⟩ := subsingleton_iff_exists_le_pure lemma Subsingleton.isCountablyGenerated (hl : l.Subsingleton) : IsCountablyGenerated l := by rcases subsingleton_iff_bot_or_pure.1 hl with rfl | ⟨x, rfl⟩ · exact isCountablyGenerated_bot · exact isCountablyGenerated_pure x end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Lift.lean
import Mathlib.Order.Filter.Prod import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.Bases.Basic /-! # Lift filters along filter and set functions -/ open Set Filter Function namespace Filter variable {α β γ : Type*} {ι : Sort*} section lift variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Set α → Filter β} @[simp] theorem lift_top (g : Set α → Filter β) : (⊤ : Filter α).lift g = g univ := by simp [Filter.lift] /-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function `Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis of the filter `g (s i)`, then `(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis of the filter `f.lift g`. This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using `Filter.HasBasis` one has to use `Σ i, β i` as the index type, see `Filter.HasBasis.lift`. This lemma states the corresponding `mem_iff` statement without using a sigma type. -/ theorem HasBasis.mem_lift_iff {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ} (hg : ∀ i, (g <| s i).HasBasis (pg i) (sg i)) (gm : Monotone g) {s : Set γ} : s ∈ f.lift g ↔ ∃ i, p i ∧ ∃ x, pg i x ∧ sg i x ⊆ s := by refine (mem_biInf_of_directed ?_ ⟨univ, univ_sets _⟩).trans ?_ · intro t₁ ht₁ t₂ ht₂ exact ⟨t₁ ∩ t₂, inter_mem ht₁ ht₂, gm inter_subset_left, gm inter_subset_right⟩ · simp only [← (hg _).mem_iff] exact hf.exists_iff fun t₁ t₂ ht H => gm ht H /-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function `Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis of the filter `g (s i)`, then `(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis of the filter `f.lift g`. This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using `has_basis` one has to use `Σ i, β i` as the index type. See also `Filter.HasBasis.mem_lift_iff` for the corresponding `mem_iff` statement formulated without using a sigma type. -/ theorem HasBasis.lift {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ} (hg : ∀ i, (g (s i)).HasBasis (pg i) (sg i)) (gm : Monotone g) : (f.lift g).HasBasis (fun i : Σ i, β i => p i.1 ∧ pg i.1 i.2) fun i : Σ i, β i => sg i.1 i.2 := by refine ⟨fun t => (hf.mem_lift_iff hg gm).trans ?_⟩ simp [Sigma.exists, and_assoc, exists_and_left] theorem mem_lift_sets (hg : Monotone g) {s : Set β} : s ∈ f.lift g ↔ ∃ t ∈ f, s ∈ g t := (f.basis_sets.mem_lift_iff (fun s => (g s).basis_sets) hg).trans <| by simp only [id, exists_mem_subset_iff] theorem sInter_lift_sets (hg : Monotone g) : ⋂₀ { s | s ∈ f.lift g } = ⋂ s ∈ f, ⋂₀ { t | t ∈ g s } := by simp only [sInter_eq_biInter, mem_setOf_eq, mem_lift_sets hg, iInter_exists, iInter_and, @iInter_comm _ (Set β)] theorem mem_lift {s : Set β} {t : Set α} (ht : t ∈ f) (hs : s ∈ g t) : s ∈ f.lift g := le_principal_iff.mp <| show f.lift g ≤ 𝓟 s from iInf_le_of_le t <| iInf_le_of_le ht <| le_principal_iff.mpr hs theorem lift_le {f : Filter α} {g : Set α → Filter β} {h : Filter β} {s : Set α} (hs : s ∈ f) (hg : g s ≤ h) : f.lift g ≤ h := iInf₂_le_of_le s hs hg theorem le_lift {f : Filter α} {g : Set α → Filter β} {h : Filter β} : h ≤ f.lift g ↔ ∀ s ∈ f, h ≤ g s := le_iInf₂_iff theorem lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ := iInf_mono fun s => iInf_mono' fun hs => ⟨hf hs, hg s⟩ theorem lift_mono' (hg : ∀ s ∈ f, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ := iInf₂_mono hg theorem tendsto_lift {m : γ → β} {l : Filter γ} : Tendsto m l (f.lift g) ↔ ∀ s ∈ f, Tendsto m l (g s) := by simp only [Filter.lift, tendsto_iInf] theorem map_lift_eq {m : β → γ} (hg : Monotone g) : map m (f.lift g) = f.lift (map m ∘ g) := have : Monotone (map m ∘ g) := map_mono.comp hg Filter.ext fun s => by simp only [mem_lift_sets hg, mem_lift_sets this, mem_map, Function.comp_apply] theorem comap_lift_eq {m : γ → β} : comap m (f.lift g) = f.lift (comap m ∘ g) := by simp only [Filter.lift, comap_iInf]; rfl theorem comap_lift_eq2 {m : β → α} {g : Set β → Filter γ} (hg : Monotone g) : (comap m f).lift g = f.lift (g ∘ preimage m) := le_antisymm (le_iInf₂ fun s hs => iInf₂_le (m ⁻¹' s) ⟨s, hs, Subset.rfl⟩) (le_iInf₂ fun _s ⟨s', hs', h_sub⟩ => iInf₂_le_of_le s' hs' <| hg h_sub) theorem lift_map_le {g : Set β → Filter γ} {m : α → β} : (map m f).lift g ≤ f.lift (g ∘ image m) := le_lift.2 fun _s hs => lift_le (image_mem_map hs) le_rfl theorem map_lift_eq2 {g : Set β → Filter γ} {m : α → β} (hg : Monotone g) : (map m f).lift g = f.lift (g ∘ image m) := lift_map_le.antisymm <| le_lift.2 fun _s hs => lift_le hs <| hg <| image_preimage_subset _ _ theorem lift_comm {g : Filter β} {h : Set α → Set β → Filter γ} : (f.lift fun s => g.lift (h s)) = g.lift fun t => f.lift fun s => h s t := le_antisymm (le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj => iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi) (le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj => iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi) theorem lift_assoc {h : Set β → Filter γ} (hg : Monotone g) : (f.lift g).lift h = f.lift fun s => (g s).lift h := le_antisymm (le_iInf₂ fun _s hs => le_iInf₂ fun t ht => iInf_le_of_le t <| iInf_le _ <| (mem_lift_sets hg).mpr ⟨_, hs, ht⟩) (le_iInf₂ fun t ht => let ⟨s, hs, h'⟩ := (mem_lift_sets hg).mp ht iInf_le_of_le s <| iInf_le_of_le hs <| iInf_le_of_le t <| iInf_le _ h') theorem lift_lift_same_le_lift {g : Set α → Set α → Filter β} : (f.lift fun s => f.lift (g s)) ≤ f.lift fun s => g s s := le_lift.2 fun _s hs => lift_le hs <| lift_le hs le_rfl theorem lift_lift_same_eq_lift {g : Set α → Set α → Filter β} (hg₁ : ∀ s, Monotone fun t => g s t) (hg₂ : ∀ t, Monotone fun s => g s t) : (f.lift fun s => f.lift (g s)) = f.lift fun s => g s s := lift_lift_same_le_lift.antisymm <| le_lift.2 fun s hs => le_lift.2 fun t ht => lift_le (inter_mem hs ht) <| calc g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) := hg₂ (s ∩ t) inter_subset_left _ ≤ g s t := hg₁ s inter_subset_right theorem lift_principal {s : Set α} (hg : Monotone g) : (𝓟 s).lift g = g s := (lift_le (mem_principal_self _) le_rfl).antisymm (le_lift.2 fun _t ht => hg ht) theorem monotone_lift [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Filter β} (hf : Monotone f) (hg : Monotone g) : Monotone fun c => (f c).lift (g c) := fun _ _ h => lift_mono (hf h) (hg h) theorem lift_neBot_iff (hm : Monotone g) : (NeBot (f.lift g)) ↔ ∀ s ∈ f, NeBot (g s) := by simp only [neBot_iff, Ne, ← empty_mem_iff_bot, mem_lift_sets hm, not_exists, not_and] @[simp] theorem lift_const {f : Filter α} {g : Filter β} : (f.lift fun _ => g) = g := iInf_subtype'.trans iInf_const @[simp] theorem lift_inf {f : Filter α} {g h : Set α → Filter β} : (f.lift fun x => g x ⊓ h x) = f.lift g ⊓ f.lift h := by simp only [Filter.lift, iInf_inf_eq] @[simp] theorem lift_principal2 {f : Filter α} : f.lift 𝓟 = f := le_antisymm (fun s hs => mem_lift hs (mem_principal_self s)) (le_iInf fun s => le_iInf fun hs => by simp only [hs, le_principal_iff]) theorem lift_iInf_le {f : ι → Filter α} {g : Set α → Filter β} : (iInf f).lift g ≤ ⨅ i, (f i).lift g := le_iInf fun _ => lift_mono (iInf_le _ _) le_rfl theorem lift_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β} (hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) : (iInf f).lift g = ⨅ i, (f i).lift g := by refine lift_iInf_le.antisymm fun s => ?_ have H : ∀ t ∈ iInf f, ⨅ i, (f i).lift g ≤ g t := by intro t ht refine iInf_sets_induct ht ?_ fun hs ht => ?_ · inhabit ι exact iInf₂_le_of_le default univ (iInf_le _ univ_mem) · rw [hg] exact le_inf (iInf₂_le_of_le _ _ <| iInf_le _ hs) ht simp only [mem_lift_sets (Monotone.of_map_inf hg), exists_imp, and_imp] exact fun t ht hs => H t ht hs theorem lift_iInf_of_directed [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β} (hf : Directed (· ≥ ·) f) (hg : Monotone g) : (iInf f).lift g = ⨅ i, (f i).lift g := lift_iInf_le.antisymm fun s => by simp only [mem_lift_sets hg, exists_imp, and_imp, mem_iInf_of_directed hf] exact fun t i ht hs => mem_iInf_of_mem i <| mem_lift ht hs theorem lift_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Filter β} (hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) (hg' : g univ = ⊤) : (iInf f).lift g = ⨅ i, (f i).lift g := by cases isEmpty_or_nonempty ι · simp [iInf_of_empty, hg'] · exact lift_iInf hg end lift section Lift' variable {f f₁ f₂ : Filter α} {h h₁ h₂ : Set α → Set β} @[simp] theorem lift'_top (h : Set α → Set β) : (⊤ : Filter α).lift' h = 𝓟 (h univ) := lift_top _ theorem mem_lift' {t : Set α} (ht : t ∈ f) : h t ∈ f.lift' h := le_principal_iff.mp <| show f.lift' h ≤ 𝓟 (h t) from iInf_le_of_le t <| iInf_le_of_le ht <| le_rfl theorem tendsto_lift' {m : γ → β} {l : Filter γ} : Tendsto m l (f.lift' h) ↔ ∀ s ∈ f, ∀ᶠ a in l, m a ∈ h s := by simp only [Filter.lift', tendsto_lift, tendsto_principal, comp] theorem HasBasis.lift' {ι} {p : ι → Prop} {s} (hf : f.HasBasis p s) (hh : Monotone h) : (f.lift' h).HasBasis p (h ∘ s) := ⟨fun t => (hf.mem_lift_iff (fun i => hasBasis_principal (h (s i))) (monotone_principal.comp hh)).trans <| by simp only [exists_const, true_and, comp]⟩ theorem mem_lift'_sets (hh : Monotone h) {s : Set β} : s ∈ f.lift' h ↔ ∃ t ∈ f, h t ⊆ s := mem_lift_sets <| monotone_principal.comp hh theorem eventually_lift'_iff (hh : Monotone h) {p : β → Prop} : (∀ᶠ y in f.lift' h, p y) ↔ ∃ t ∈ f, ∀ y ∈ h t, p y := mem_lift'_sets hh theorem sInter_lift'_sets (hh : Monotone h) : ⋂₀ { s | s ∈ f.lift' h } = ⋂ s ∈ f, h s := (sInter_lift_sets (monotone_principal.comp hh)).trans <| iInter₂_congr fun _ _ => csInf_Ici theorem lift'_le {f : Filter α} {g : Set α → Set β} {h : Filter β} {s : Set α} (hs : s ∈ f) (hg : 𝓟 (g s) ≤ h) : f.lift' g ≤ h := lift_le hs hg theorem lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁.lift' h₁ ≤ f₂.lift' h₂ := lift_mono hf fun s => principal_mono.mpr <| hh s theorem lift'_mono' (hh : ∀ s ∈ f, h₁ s ⊆ h₂ s) : f.lift' h₁ ≤ f.lift' h₂ := iInf₂_mono fun s hs => principal_mono.mpr <| hh s hs theorem lift'_cong (hh : ∀ s ∈ f, h₁ s = h₂ s) : f.lift' h₁ = f.lift' h₂ := le_antisymm (lift'_mono' fun s hs => le_of_eq <| hh s hs) (lift'_mono' fun s hs => le_of_eq <| (hh s hs).symm) theorem map_lift'_eq {m : β → γ} (hh : Monotone h) : map m (f.lift' h) = f.lift' (image m ∘ h) := calc map m (f.lift' h) = f.lift (map m ∘ 𝓟 ∘ h) := map_lift_eq <| monotone_principal.comp hh _ = f.lift' (image m ∘ h) := by simp only [comp_def, Filter.lift', map_principal] theorem lift'_map_le {g : Set β → Set γ} {m : α → β} : (map m f).lift' g ≤ f.lift' (g ∘ image m) := lift_map_le theorem map_lift'_eq2 {g : Set β → Set γ} {m : α → β} (hg : Monotone g) : (map m f).lift' g = f.lift' (g ∘ image m) := map_lift_eq2 <| monotone_principal.comp hg theorem comap_lift'_eq {m : γ → β} : comap m (f.lift' h) = f.lift' (preimage m ∘ h) := by simp only [Filter.lift', comap_lift_eq, comp_def, comap_principal] theorem comap_lift'_eq2 {m : β → α} {g : Set β → Set γ} (hg : Monotone g) : (comap m f).lift' g = f.lift' (g ∘ preimage m) := comap_lift_eq2 <| monotone_principal.comp hg theorem lift'_principal {s : Set α} (hh : Monotone h) : (𝓟 s).lift' h = 𝓟 (h s) := lift_principal <| monotone_principal.comp hh theorem lift'_pure {a : α} (hh : Monotone h) : (pure a : Filter α).lift' h = 𝓟 (h {a}) := by rw [← principal_singleton, lift'_principal hh] theorem lift'_bot (hh : Monotone h) : (⊥ : Filter α).lift' h = 𝓟 (h ∅) := by rw [← principal_empty, lift'_principal hh] theorem le_lift' {f : Filter α} {h : Set α → Set β} {g : Filter β} : g ≤ f.lift' h ↔ ∀ s ∈ f, h s ∈ g := le_lift.trans <| forall₂_congr fun _ _ => le_principal_iff theorem principal_le_lift' {t : Set β} : 𝓟 t ≤ f.lift' h ↔ ∀ s ∈ f, t ⊆ h s := le_lift' theorem monotone_lift' [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Set β} (hf : Monotone f) (hg : Monotone g) : Monotone fun c => (f c).lift' (g c) := fun _ _ h => lift'_mono (hf h) (hg h) theorem lift_lift'_assoc {g : Set α → Set β} {h : Set β → Filter γ} (hg : Monotone g) (hh : Monotone h) : (f.lift' g).lift h = f.lift fun s => h (g s) := calc (f.lift' g).lift h = f.lift fun s => (𝓟 (g s)).lift h := lift_assoc (monotone_principal.comp hg) _ = f.lift fun s => h (g s) := by simp only [lift_principal, hh] theorem lift'_lift'_assoc {g : Set α → Set β} {h : Set β → Set γ} (hg : Monotone g) (hh : Monotone h) : (f.lift' g).lift' h = f.lift' fun s => h (g s) := lift_lift'_assoc hg (monotone_principal.comp hh) theorem lift'_lift_assoc {g : Set α → Filter β} {h : Set β → Set γ} (hg : Monotone g) : (f.lift g).lift' h = f.lift fun s => (g s).lift' h := lift_assoc hg theorem lift_lift'_same_le_lift' {g : Set α → Set α → Set β} : (f.lift fun s => f.lift' (g s)) ≤ f.lift' fun s => g s s := lift_lift_same_le_lift theorem lift_lift'_same_eq_lift' {g : Set α → Set α → Set β} (hg₁ : ∀ s, Monotone fun t => g s t) (hg₂ : ∀ t, Monotone fun s => g s t) : (f.lift fun s => f.lift' (g s)) = f.lift' fun s => g s s := lift_lift_same_eq_lift (fun s => monotone_principal.comp (hg₁ s)) fun t => monotone_principal.comp (hg₂ t) theorem lift'_inf_principal_eq {h : Set α → Set β} {s : Set β} : f.lift' h ⊓ 𝓟 s = f.lift' fun t => h t ∩ s := by simp only [Filter.lift', Filter.lift, (· ∘ ·), ← inf_principal, iInf_subtype', ← iInf_inf] theorem lift'_neBot_iff (hh : Monotone h) : NeBot (f.lift' h) ↔ ∀ s ∈ f, (h s).Nonempty := calc NeBot (f.lift' h) ↔ ∀ s ∈ f, NeBot (𝓟 (h s)) := lift_neBot_iff (monotone_principal.comp hh) _ ↔ ∀ s ∈ f, (h s).Nonempty := by simp only [principal_neBot_iff] @[simp] theorem lift'_id {f : Filter α} : f.lift' id = f := lift_principal2 theorem lift'_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Set β} (hg : ∀ s t, g (s ∩ t) = g s ∩ g t) : (iInf f).lift' g = ⨅ i, (f i).lift' g := lift_iInf fun s t => by simp only [inf_principal, comp, hg] theorem lift'_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Set β} (hg : ∀ {s t}, g (s ∩ t) = g s ∩ g t) (hg' : g univ = univ) : (iInf f).lift' g = ⨅ i, (f i).lift' g := lift_iInf_of_map_univ (fun s t => by simp only [inf_principal, comp, hg]) (by rw [Function.comp_apply, hg', principal_univ]) theorem lift'_inf (f g : Filter α) {s : Set α → Set β} (hs : ∀ t₁ t₂, s (t₁ ∩ t₂) = s t₁ ∩ s t₂) : (f ⊓ g).lift' s = f.lift' s ⊓ g.lift' s := by rw [inf_eq_iInf, inf_eq_iInf, lift'_iInf hs] refine iInf_congr ?_ rintro (_ | _) <;> rfl theorem lift'_inf_le (f g : Filter α) (s : Set α → Set β) : (f ⊓ g).lift' s ≤ f.lift' s ⊓ g.lift' s := le_inf (lift'_mono inf_le_left le_rfl) (lift'_mono inf_le_right le_rfl) theorem comap_eq_lift' {f : Filter β} {m : α → β} : comap m f = f.lift' (preimage m) := Filter.ext fun _ => (mem_lift'_sets monotone_preimage).symm end Lift' section Prod variable {f : Filter α} theorem prod_def {f : Filter α} {g : Filter β} : f ×ˢ g = f.lift fun s => g.lift' fun t => s ×ˢ t := by simpa only [Filter.lift', Filter.lift, (f.basis_sets.prod g.basis_sets).eq_biInf, iInf_prod, iInf_and] using iInf_congr fun i => iInf_comm alias mem_prod_same_iff := mem_prod_self_iff theorem prod_same_eq : f ×ˢ f = f.lift' fun t : Set α => t ×ˢ t := f.basis_sets.prod_self.eq_biInf theorem tendsto_prod_self_iff {f : α × α → β} {x : Filter α} {y : Filter β} : Filter.Tendsto f (x ×ˢ x) y ↔ ∀ W ∈ y, ∃ U ∈ x, ∀ x x' : α, x ∈ U → x' ∈ U → f (x, x') ∈ W := by simp only [tendsto_def, mem_prod_same_iff, prod_sub_preimage_iff] variable {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} theorem prod_lift_lift {f₁ : Filter α₁} {f₂ : Filter α₂} {g₁ : Set α₁ → Filter β₁} {g₂ : Set α₂ → Filter β₂} (hg₁ : Monotone g₁) (hg₂ : Monotone g₂) : f₁.lift g₁ ×ˢ f₂.lift g₂ = f₁.lift fun s => f₂.lift fun t => g₁ s ×ˢ g₂ t := by simp only [prod_def, lift_assoc hg₁] apply congr_arg; funext x rw [lift_comm] apply congr_arg; funext y apply lift'_lift_assoc hg₂ theorem prod_lift'_lift' {f₁ : Filter α₁} {f₂ : Filter α₂} {g₁ : Set α₁ → Set β₁} {g₂ : Set α₂ → Set β₂} (hg₁ : Monotone g₁) (hg₂ : Monotone g₂) : f₁.lift' g₁ ×ˢ f₂.lift' g₂ = f₁.lift fun s => f₂.lift' fun t => g₁ s ×ˢ g₂ t := calc f₁.lift' g₁ ×ˢ f₂.lift' g₂ = f₁.lift fun s => f₂.lift fun t => 𝓟 (g₁ s) ×ˢ 𝓟 (g₂ t) := prod_lift_lift (monotone_principal.comp hg₁) (monotone_principal.comp hg₂) _ = f₁.lift fun s => f₂.lift fun t => 𝓟 (g₁ s ×ˢ g₂ t) := by { simp only [prod_principal_principal] } end Prod end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/SmallSets.lean
import Mathlib.Order.Filter.Lift import Mathlib.Order.Filter.AtTopBot.Basic /-! # The filter of small sets This file defines the filter of small sets w.r.t. a filter `f`, which is the largest filter containing all powersets of members of `f`. `g` converges to `f.smallSets` if for all `s ∈ f`, eventually we have `g x ⊆ s`. An example usage is that if `f : ι → E → ℝ` is a family of nonnegative functions with integral 1, then saying that `fun i ↦ support (f i)` tendsto `(𝓝 0).smallSets` is a way of saying that `f` tends to the Dirac delta distribution. -/ open Filter open Set variable {α β : Type*} {ι : Sort*} namespace Filter variable {l l' la : Filter α} {lb : Filter β} /-- The filter `l.smallSets` is the largest filter containing all powersets of members of `l`. -/ def smallSets (l : Filter α) : Filter (Set α) := l.lift' powerset theorem smallSets_eq_generate {f : Filter α} : f.smallSets = generate (powerset '' f.sets) := by simp_rw [generate_eq_biInf, smallSets, iInf_image, Filter.lift', Filter.lift, Function.comp_apply, Filter.mem_sets] -- TODO: get more properties from the adjunction? -- TODO: is there a general way to get a lower adjoint for the lift of an upper adjoint? theorem bind_smallSets_gc : GaloisConnection (fun L : Filter (Set α) ↦ L.bind principal) smallSets := by intro L l simp_rw [smallSets_eq_generate, le_generate_iff, image_subset_iff] rfl protected theorem HasBasis.smallSets {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis l.smallSets p fun i => 𝒫 s i := h.lift' monotone_powerset theorem hasBasis_smallSets (l : Filter α) : HasBasis l.smallSets (fun t : Set α => t ∈ l) powerset := l.basis_sets.smallSets theorem Eventually.exists_mem_basis_of_smallSets {p : ι → Prop} {s : ι → Set α} {P : Set α → Prop} (h₁ : ∀ᶠ t in l.smallSets, P t) (h₂ : HasBasis l p s) : ∃ i, p i ∧ P (s i) := (h₂.smallSets.eventually_iff.mp h₁).imp fun _i ⟨hpi, hi⟩ ↦ ⟨hpi, hi Subset.rfl⟩ theorem Frequently.smallSets_of_forall_mem_basis {p : ι → Prop} {s : ι → Set α} {P : Set α → Prop} (h₁ : ∀ i, p i → P (s i)) (h₂ : HasBasis l p s) : ∃ᶠ t in l.smallSets, P t := h₂.smallSets.frequently_iff.mpr fun _ hi => ⟨_, Subset.rfl, h₁ _ hi⟩ theorem Eventually.exists_mem_of_smallSets {p : Set α → Prop} (h : ∀ᶠ t in l.smallSets, p t) : ∃ s ∈ l, p s := h.exists_mem_basis_of_smallSets l.basis_sets /-! No `Frequently.smallSets_of_forall_mem (h : ∀ s ∈ l, p s) : ∃ᶠ t in l.smallSets, p t` as `Filter.frequently_smallSets_mem : ∃ᶠ t in l.smallSets, t ∈ l` is preferred. -/ /-- `g` converges to `f.smallSets` if for all `s ∈ f`, eventually we have `g x ⊆ s`. -/ theorem tendsto_smallSets_iff {f : α → Set β} : Tendsto f la lb.smallSets ↔ ∀ t ∈ lb, ∀ᶠ x in la, f x ⊆ t := (hasBasis_smallSets lb).tendsto_right_iff theorem eventually_smallSets {p : Set α → Prop} : (∀ᶠ s in l.smallSets, p s) ↔ ∃ s ∈ l, ∀ t, t ⊆ s → p t := eventually_lift'_iff monotone_powerset theorem eventually_smallSets' {p : Set α → Prop} (hp : ∀ ⦃s t⦄, s ⊆ t → p t → p s) : (∀ᶠ s in l.smallSets, p s) ↔ ∃ s ∈ l, p s := eventually_smallSets.trans <| exists_congr fun s => Iff.rfl.and ⟨fun H => H s Subset.rfl, fun hs _t ht => hp ht hs⟩ theorem HasBasis.eventually_smallSets {α : Type*} {ι : Sort*} {p : ι → Prop} {l : Filter α} {s : ι → Set α} {q : Set α → Prop} {hl : l.HasBasis p s} (hq : ∀ ⦃s t : Set α⦄, s ⊆ t → q t → q s) : (∀ᶠ s in l.smallSets, q s) ↔ ∃ i, p i ∧ q (s i) := by rw [l.eventually_smallSets' hq, hl.exists_iff hq] theorem frequently_smallSets {p : Set α → Prop} : (∃ᶠ s in l.smallSets, p s) ↔ ∀ t ∈ l, ∃ s, s ⊆ t ∧ p s := l.hasBasis_smallSets.frequently_iff theorem frequently_smallSets_mem (l : Filter α) : ∃ᶠ s in l.smallSets, s ∈ l := frequently_smallSets.2 fun t ht => ⟨t, Subset.rfl, ht⟩ theorem frequently_smallSets' {α : Type*} {l : Filter α} {p : Set α → Prop} (hp : ∀ ⦃s t : Set α⦄, s ⊆ t → p s → p t) : (∃ᶠ s in l.smallSets, p s) ↔ ∀ t ∈ l, p t := by convert not_iff_not.mpr <| l.eventually_smallSets' (p := (¬ p ·)) (by tauto) simp theorem HasBasis.frequently_smallSets {α : Type*} {ι : Sort*} {p : ι → Prop} {l : Filter α} {s : ι → Set α} {q : Set α → Prop} {hl : l.HasBasis p s} (hq : ∀ ⦃s t : Set α⦄, s ⊆ t → q s → q t) : (∃ᶠ s in l.smallSets, q s) ↔ ∀ i, p i → q (s i) := by rw [Filter.frequently_smallSets' hq, hl.forall_iff hq] @[simp] lemma tendsto_image_smallSets {f : α → β} : Tendsto (f '' ·) la.smallSets lb.smallSets ↔ Tendsto f la lb := by rw [tendsto_smallSets_iff] refine forall₂_congr fun u hu ↦ ?_ rw [eventually_smallSets' fun s t hst ht ↦ (image_mono hst).trans ht] simp only [image_subset_iff, exists_mem_subset_iff, mem_map] alias ⟨_, Tendsto.image_smallSets⟩ := tendsto_image_smallSets theorem HasAntitoneBasis.tendsto_smallSets {ι} [Preorder ι] {s : ι → Set α} (hl : l.HasAntitoneBasis s) : Tendsto s atTop l.smallSets := tendsto_smallSets_iff.2 fun _t ht => hl.eventually_subset ht @[mono] theorem monotone_smallSets : Monotone (@smallSets α) := monotone_lift' monotone_id monotone_const @[simp] theorem smallSets_bot : (⊥ : Filter α).smallSets = pure ∅ := by rw [smallSets, lift'_bot, powerset_empty, principal_singleton] exact monotone_powerset @[simp] theorem smallSets_top : (⊤ : Filter α).smallSets = ⊤ := by rw [smallSets, lift'_top, powerset_univ, principal_univ] @[simp] theorem smallSets_principal (s : Set α) : (𝓟 s).smallSets = 𝓟 (𝒫 s) := lift'_principal monotone_powerset theorem smallSets_comap_eq_comap_image (l : Filter β) (f : α → β) : (comap f l).smallSets = comap (image f) l.smallSets := by refine (gc_map_comap _).u_comm_of_l_comm (gc_map_comap _) bind_smallSets_gc bind_smallSets_gc ?_ simp [Function.comp_def, map_bind, bind_map] theorem smallSets_comap (l : Filter β) (f : α → β) : (comap f l).smallSets = l.lift' (powerset ∘ preimage f) := comap_lift'_eq2 monotone_powerset theorem comap_smallSets (l : Filter β) (f : α → Set β) : comap f l.smallSets = l.lift' (preimage f ∘ powerset) := comap_lift'_eq theorem smallSets_iInf {f : ι → Filter α} : (iInf f).smallSets = ⨅ i, (f i).smallSets := lift'_iInf_of_map_univ (powerset_inter _ _) powerset_univ theorem smallSets_inf (l₁ l₂ : Filter α) : (l₁ ⊓ l₂).smallSets = l₁.smallSets ⊓ l₂.smallSets := lift'_inf _ _ powerset_inter instance smallSets_neBot (l : Filter α) : NeBot l.smallSets := by refine (lift'_neBot_iff ?_).2 fun _ _ => powerset_nonempty exact monotone_powerset theorem Tendsto.smallSets_mono {s t : α → Set β} (ht : Tendsto t la lb.smallSets) (hst : ∀ᶠ x in la, s x ⊆ t x) : Tendsto s la lb.smallSets := by rw [tendsto_smallSets_iff] at ht ⊢ exact fun u hu => (ht u hu).mp (hst.mono fun _ hst ht => hst.trans ht) /-- Generalized **squeeze theorem** (also known as **sandwich theorem**). If `s : α → Set β` is a family of sets that tends to `Filter.smallSets lb` along `la` and `f : α → β` is a function such that `f x ∈ s x` eventually along `la`, then `f` tends to `lb` along `la`. If `s x` is the closed interval `[g x, h x]` for some functions `g`, `h` that tend to the same limit `𝓝 y`, then we obtain the standard squeeze theorem, see `tendsto_of_tendsto_of_tendsto_of_le_of_le'`. -/ theorem Tendsto.of_smallSets {s : α → Set β} {f : α → β} (hs : Tendsto s la lb.smallSets) (hf : ∀ᶠ x in la, f x ∈ s x) : Tendsto f la lb := fun t ht => hf.mp <| (tendsto_smallSets_iff.mp hs t ht).mono fun _ h₁ h₂ => h₁ h₂ @[simp] theorem eventually_smallSets_eventually {p : α → Prop} : (∀ᶠ s in l.smallSets, ∀ᶠ x in l', x ∈ s → p x) ↔ ∀ᶠ x in l ⊓ l', p x := calc _ ↔ ∃ s ∈ l, ∀ᶠ x in l', x ∈ s → p x := eventually_smallSets' fun _ _ hst ht => ht.mono fun _ hx hs => hx (hst hs) _ ↔ ∃ s ∈ l, ∃ t ∈ l', ∀ x, x ∈ t → x ∈ s → p x := by simp only [eventually_iff_exists_mem] _ ↔ ∀ᶠ x in l ⊓ l', p x := by simp only [eventually_inf, and_comm, mem_inter_iff, ← and_imp] @[simp] theorem eventually_smallSets_forall {p : α → Prop} : (∀ᶠ s in l.smallSets, ∀ x ∈ s, p x) ↔ ∀ᶠ x in l, p x := by simpa only [inf_top_eq, eventually_top] using @eventually_smallSets_eventually α l ⊤ p alias ⟨Eventually.of_smallSets, Eventually.smallSets⟩ := eventually_smallSets_forall @[simp] theorem eventually_smallSets_subset {s : Set α} : (∀ᶠ t in l.smallSets, t ⊆ s) ↔ s ∈ l := eventually_smallSets_forall end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Extr.lean
import Mathlib.Order.Filter.Tendsto import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Algebra.Order.Group.Defs import Mathlib.Data.Finset.Lattice.Fold /-! # Minimum and maximum w.r.t. a filter and on a set ## Main Definitions This file defines six predicates of the form `isAB`, where `A` is `Min`, `Max`, or `Extr`, and `B` is `Filter` or `On`. * `isMinFilter f l a` means that `f a ≤ f x` in some `l`-neighborhood of `a`; * `isMaxFilter f l a` means that `f x ≤ f a` in some `l`-neighborhood of `a`; * `isExtrFilter f l a` means `isMinFilter f l a` or `isMaxFilter f l a`. Similar predicates with `on` suffix are particular cases for `l = 𝓟 s`. ## Main statements ### Change of the filter (set) argument * `is*Filter.filter_mono` : replace the filter with a smaller one; * `is*Filter.filter_inf` : replace a filter `l` with `l ⊓ l'`; * `is*On.on_subset` : restrict to a smaller set; * `is*Pn.inter` : replace a set `s` with `s ∩ t`. ### Composition * `is**.comp_mono` : if `x` is an extremum for `f` and `g` is a monotone function, then `x` is an extremum for `g ∘ f`; * `is**.comp_antitone` : similarly for the case of antitone `g`; * `is**.bicomp_mono` : if `x` is an extremum of the same type for `f` and `g` and a binary operation `op` is monotone in both arguments, then `x` is an extremum of the same type for `fun x => op (f x) (g x)`. * `is*Filter.comp_tendsto` : if `g x` is an extremum for `f` w.r.t. `l'` and `Tendsto g l l'`, then `x` is an extremum for `f ∘ g` w.r.t. `l`. * `is*On.on_preimage` : if `g x` is an extremum for `f` on `s`, then `x` is an extremum for `f ∘ g` on `g ⁻¹' s`. ### Algebraic operations * `is**.add` : if `x` is an extremum of the same type for two functions, then it is an extremum of the same type for their sum; * `is**.neg` : if `x` is an extremum for `f`, then it is an extremum of the opposite type for `-f`; * `is**.sub` : if `x` is a minimum for `f` and a maximum for `g`, then it is a minimum for `f - g` and a maximum for `g - f`; * `is**.max`, `is**.min`, `is**.sup`, `is**.inf` : similarly for `is**.add` for pointwise `max`, `min`, `sup`, `inf`, respectively. ### Miscellaneous definitions * `is**_const` : any point is both a minimum and maximum for a constant function; * `isMin/Max*.isExt` : any minimum/maximum point is an extremum; * `is**.dual`, `is**.undual`: conversion between codomains `α` and `dual α`; ## Missing features (TODO) * Multiplication and division; * `is**.bicompl` : if `x` is a minimum for `f`, `y` is a minimum for `g`, and `op` is a monotone binary operation, then `(x, y)` is a minimum for `uncurry (bicompl op f g)`. From this point of view, `is**.bicomp` is a composition * It would be nice to have a tactic that specializes `comp_(anti)mono` or `bicomp_mono` based on a proof of monotonicity of a given (binary) function. The tactic should maintain a `meta` list of known (anti)monotone (binary) functions with their names, as well as a list of special types of filters, and define the missing lemmas once one of these two lists grows. -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} open Set Filter Relator section Preorder variable [Preorder β] [Preorder γ] variable (f : α → β) (s : Set α) (l : Filter α) (a : α) /-! ### Definitions -/ /-- `IsMinFilter f l a` means that `f a ≤ f x` for all `x` in some `l`-neighborhood of `a` -/ def IsMinFilter : Prop := ∀ᶠ x in l, f a ≤ f x /-- `is_maxFilter f l a` means that `f x ≤ f a` for all `x` in some `l`-neighborhood of `a` -/ def IsMaxFilter : Prop := ∀ᶠ x in l, f x ≤ f a /-- `IsExtrFilter f l a` means `IsMinFilter f l a` or `IsMaxFilter f l a` -/ def IsExtrFilter : Prop := IsMinFilter f l a ∨ IsMaxFilter f l a /-- `IsMinOn f s a` means that `f a ≤ f x` for all `x ∈ s`. Note that we do not assume `a ∈ s`. -/ def IsMinOn := IsMinFilter f (𝓟 s) a /-- `IsMaxOn f s a` means that `f x ≤ f a` for all `x ∈ s`. Note that we do not assume `a ∈ s`. -/ def IsMaxOn := IsMaxFilter f (𝓟 s) a /-- `IsExtrOn f s a` means `IsMinOn f s a` or `IsMaxOn f s a` -/ def IsExtrOn : Prop := IsExtrFilter f (𝓟 s) a variable {f s a l} {t : Set α} {l' : Filter α} theorem IsExtrOn.elim {p : Prop} : IsExtrOn f s a → (IsMinOn f s a → p) → (IsMaxOn f s a → p) → p := Or.elim theorem isMinOn_iff : IsMinOn f s a ↔ ∀ x ∈ s, f a ≤ f x := Iff.rfl theorem isMaxOn_iff : IsMaxOn f s a ↔ ∀ x ∈ s, f x ≤ f a := Iff.rfl theorem isMinOn_univ_iff : IsMinOn f univ a ↔ ∀ x, f a ≤ f x := univ_subset_iff.trans eq_univ_iff_forall theorem isMaxOn_univ_iff : IsMaxOn f univ a ↔ ∀ x, f x ≤ f a := univ_subset_iff.trans eq_univ_iff_forall theorem IsMinOn.bddBelow (h : IsMinOn f s a) : BddBelow (f '' s) := ⟨f a, by simpa [mem_lowerBounds] using h⟩ theorem IsMinOn.isGLB (ha : a ∈ s) (hfsa : IsMinOn f s a) : IsGLB {f x | x ∈ s} (f a) := by rw [isGLB_iff_le_iff] intro b simp only [mem_lowerBounds, mem_setOf_eq, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] exact ⟨fun hba x hx ↦ le_trans hba (hfsa hx), fun hb ↦ hb a ha⟩ theorem IsMaxOn.isLUB (ha : a ∈ s) (hfsa : IsMaxOn f s a) : IsLUB {f x | x ∈ s} (f a) := IsMinOn.isGLB (α := αᵒᵈ) (β := βᵒᵈ) ha hfsa theorem IsMaxOn.bddAbove (h : IsMaxOn f s a) : BddAbove (f '' s) := ⟨f a, by simpa [mem_upperBounds] using h⟩ theorem IsMinFilter.tendsto_principal_Ici (h : IsMinFilter f l a) : Tendsto f l (𝓟 <| Ici (f a)) := tendsto_principal.2 h theorem IsMaxFilter.tendsto_principal_Iic (h : IsMaxFilter f l a) : Tendsto f l (𝓟 <| Iic (f a)) := tendsto_principal.2 h /-! ### Conversion to `IsExtr*` -/ theorem IsMinFilter.isExtr : IsMinFilter f l a → IsExtrFilter f l a := Or.inl theorem IsMaxFilter.isExtr : IsMaxFilter f l a → IsExtrFilter f l a := Or.inr theorem IsMinOn.isExtr (h : IsMinOn f s a) : IsExtrOn f s a := IsMinFilter.isExtr h theorem IsMaxOn.isExtr (h : IsMaxOn f s a) : IsExtrOn f s a := IsMaxFilter.isExtr h /-! ### Constant function -/ theorem isMinFilter_const {b : β} : IsMinFilter (fun _ => b) l a := univ_mem' fun _ => le_rfl theorem isMaxFilter_const {b : β} : IsMaxFilter (fun _ => b) l a := univ_mem' fun _ => le_rfl theorem isExtrFilter_const {b : β} : IsExtrFilter (fun _ => b) l a := isMinFilter_const.isExtr theorem isMinOn_const {b : β} : IsMinOn (fun _ => b) s a := isMinFilter_const theorem isMaxOn_const {b : β} : IsMaxOn (fun _ => b) s a := isMaxFilter_const theorem isExtrOn_const {b : β} : IsExtrOn (fun _ => b) s a := isExtrFilter_const /-! ### Order dual -/ open OrderDual (toDual) theorem isMinFilter_dual_iff : IsMinFilter (toDual ∘ f) l a ↔ IsMaxFilter f l a := Iff.rfl theorem isMaxFilter_dual_iff : IsMaxFilter (toDual ∘ f) l a ↔ IsMinFilter f l a := Iff.rfl theorem isExtrFilter_dual_iff : IsExtrFilter (toDual ∘ f) l a ↔ IsExtrFilter f l a := or_comm alias ⟨IsMinFilter.undual, IsMaxFilter.dual⟩ := isMinFilter_dual_iff alias ⟨IsMaxFilter.undual, IsMinFilter.dual⟩ := isMaxFilter_dual_iff alias ⟨IsExtrFilter.undual, IsExtrFilter.dual⟩ := isExtrFilter_dual_iff theorem isMinOn_dual_iff : IsMinOn (toDual ∘ f) s a ↔ IsMaxOn f s a := Iff.rfl theorem isMaxOn_dual_iff : IsMaxOn (toDual ∘ f) s a ↔ IsMinOn f s a := Iff.rfl theorem isExtrOn_dual_iff : IsExtrOn (toDual ∘ f) s a ↔ IsExtrOn f s a := or_comm alias ⟨IsMinOn.undual, IsMaxOn.dual⟩ := isMinOn_dual_iff alias ⟨IsMaxOn.undual, IsMinOn.dual⟩ := isMaxOn_dual_iff alias ⟨IsExtrOn.undual, IsExtrOn.dual⟩ := isExtrOn_dual_iff /-! ### Operations on the filter/set -/ theorem IsMinFilter.filter_mono (h : IsMinFilter f l a) (hl : l' ≤ l) : IsMinFilter f l' a := hl h theorem IsMaxFilter.filter_mono (h : IsMaxFilter f l a) (hl : l' ≤ l) : IsMaxFilter f l' a := hl h theorem IsExtrFilter.filter_mono (h : IsExtrFilter f l a) (hl : l' ≤ l) : IsExtrFilter f l' a := h.elim (fun h => (h.filter_mono hl).isExtr) fun h => (h.filter_mono hl).isExtr theorem IsMinFilter.filter_inf (h : IsMinFilter f l a) (l') : IsMinFilter f (l ⊓ l') a := h.filter_mono inf_le_left theorem IsMaxFilter.filter_inf (h : IsMaxFilter f l a) (l') : IsMaxFilter f (l ⊓ l') a := h.filter_mono inf_le_left theorem IsExtrFilter.filter_inf (h : IsExtrFilter f l a) (l') : IsExtrFilter f (l ⊓ l') a := h.filter_mono inf_le_left theorem IsMinOn.on_subset (hf : IsMinOn f t a) (h : s ⊆ t) : IsMinOn f s a := hf.filter_mono <| principal_mono.2 h theorem IsMaxOn.on_subset (hf : IsMaxOn f t a) (h : s ⊆ t) : IsMaxOn f s a := hf.filter_mono <| principal_mono.2 h theorem IsExtrOn.on_subset (hf : IsExtrOn f t a) (h : s ⊆ t) : IsExtrOn f s a := hf.filter_mono <| principal_mono.2 h theorem IsMinOn.inter (hf : IsMinOn f s a) (t) : IsMinOn f (s ∩ t) a := hf.on_subset inter_subset_left theorem IsMaxOn.inter (hf : IsMaxOn f s a) (t) : IsMaxOn f (s ∩ t) a := hf.on_subset inter_subset_left theorem IsExtrOn.inter (hf : IsExtrOn f s a) (t) : IsExtrOn f (s ∩ t) a := hf.on_subset inter_subset_left /-! ### Composition with (anti)monotone functions -/ theorem IsMinFilter.comp_mono (hf : IsMinFilter f l a) {g : β → γ} (hg : Monotone g) : IsMinFilter (g ∘ f) l a := mem_of_superset hf fun _x hx => hg hx theorem IsMaxFilter.comp_mono (hf : IsMaxFilter f l a) {g : β → γ} (hg : Monotone g) : IsMaxFilter (g ∘ f) l a := mem_of_superset hf fun _x hx => hg hx theorem IsExtrFilter.comp_mono (hf : IsExtrFilter f l a) {g : β → γ} (hg : Monotone g) : IsExtrFilter (g ∘ f) l a := hf.elim (fun hf => (hf.comp_mono hg).isExtr) fun hf => (hf.comp_mono hg).isExtr theorem IsMinFilter.comp_antitone (hf : IsMinFilter f l a) {g : β → γ} (hg : Antitone g) : IsMaxFilter (g ∘ f) l a := hf.dual.comp_mono fun _ _ h => hg h theorem IsMaxFilter.comp_antitone (hf : IsMaxFilter f l a) {g : β → γ} (hg : Antitone g) : IsMinFilter (g ∘ f) l a := hf.dual.comp_mono fun _ _ h => hg h theorem IsExtrFilter.comp_antitone (hf : IsExtrFilter f l a) {g : β → γ} (hg : Antitone g) : IsExtrFilter (g ∘ f) l a := hf.dual.comp_mono fun _ _ h => hg h theorem IsMinOn.comp_mono (hf : IsMinOn f s a) {g : β → γ} (hg : Monotone g) : IsMinOn (g ∘ f) s a := IsMinFilter.comp_mono hf hg theorem IsMaxOn.comp_mono (hf : IsMaxOn f s a) {g : β → γ} (hg : Monotone g) : IsMaxOn (g ∘ f) s a := IsMaxFilter.comp_mono hf hg theorem IsExtrOn.comp_mono (hf : IsExtrOn f s a) {g : β → γ} (hg : Monotone g) : IsExtrOn (g ∘ f) s a := IsExtrFilter.comp_mono hf hg theorem IsMinOn.comp_antitone (hf : IsMinOn f s a) {g : β → γ} (hg : Antitone g) : IsMaxOn (g ∘ f) s a := IsMinFilter.comp_antitone hf hg theorem IsMaxOn.comp_antitone (hf : IsMaxOn f s a) {g : β → γ} (hg : Antitone g) : IsMinOn (g ∘ f) s a := IsMaxFilter.comp_antitone hf hg theorem IsExtrOn.comp_antitone (hf : IsExtrOn f s a) {g : β → γ} (hg : Antitone g) : IsExtrOn (g ∘ f) s a := IsExtrFilter.comp_antitone hf hg theorem IsMinFilter.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMinFilter f l a) {g : α → γ} (hg : IsMinFilter g l a) : IsMinFilter (fun x => op (f x) (g x)) l a := mem_of_superset (inter_mem hf hg) fun _x ⟨hfx, hgx⟩ => hop hfx hgx theorem IsMaxFilter.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMaxFilter f l a) {g : α → γ} (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => op (f x) (g x)) l a := mem_of_superset (inter_mem hf hg) fun _x ⟨hfx, hgx⟩ => hop hfx hgx -- No `Extr` version because we need `hf` and `hg` to be of the same kind theorem IsMinOn.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMinOn f s a) {g : α → γ} (hg : IsMinOn g s a) : IsMinOn (fun x => op (f x) (g x)) s a := IsMinFilter.bicomp_mono hop hf hg theorem IsMaxOn.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMaxOn f s a) {g : α → γ} (hg : IsMaxOn g s a) : IsMaxOn (fun x => op (f x) (g x)) s a := IsMaxFilter.bicomp_mono hop hf hg /-! ### Composition with `Tendsto` -/ theorem IsMinFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsMinFilter f l (g b)) (hg : Tendsto g l' l) : IsMinFilter (f ∘ g) l' b := hg hf theorem IsMaxFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsMaxFilter f l (g b)) (hg : Tendsto g l' l) : IsMaxFilter (f ∘ g) l' b := hg hf theorem IsExtrFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsExtrFilter f l (g b)) (hg : Tendsto g l' l) : IsExtrFilter (f ∘ g) l' b := hf.elim (fun hf => (hf.comp_tendsto hg).isExtr) fun hf => (hf.comp_tendsto hg).isExtr theorem IsMinOn.on_preimage (g : δ → α) {b : δ} (hf : IsMinOn f s (g b)) : IsMinOn (f ∘ g) (g ⁻¹' s) b := hf.comp_tendsto (tendsto_principal_principal.mpr <| Subset.refl _) theorem IsMaxOn.on_preimage (g : δ → α) {b : δ} (hf : IsMaxOn f s (g b)) : IsMaxOn (f ∘ g) (g ⁻¹' s) b := hf.comp_tendsto (tendsto_principal_principal.mpr <| Subset.refl _) theorem IsExtrOn.on_preimage (g : δ → α) {b : δ} (hf : IsExtrOn f s (g b)) : IsExtrOn (f ∘ g) (g ⁻¹' s) b := hf.elim (fun hf => (hf.on_preimage g).isExtr) fun hf => (hf.on_preimage g).isExtr theorem IsMinOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsMinOn f s a) (hg : MapsTo g t s) (ha : g b = a) : IsMinOn (f ∘ g) t b := fun y hy => by simpa only [ha, (· ∘ ·)] using hf (hg hy) theorem IsMaxOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsMaxOn f s a) (hg : MapsTo g t s) (ha : g b = a) : IsMaxOn (f ∘ g) t b := hf.dual.comp_mapsTo hg ha theorem IsExtrOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsExtrOn f s a) (hg : MapsTo g t s) (ha : g b = a) : IsExtrOn (f ∘ g) t b := hf.elim (fun h => Or.inl <| h.comp_mapsTo hg ha) fun h => Or.inr <| h.comp_mapsTo hg ha end Preorder /-! ### Pointwise addition -/ section OrderedAddCommMonoid variable [AddCommMonoid β] [PartialOrder β] [IsOrderedAddMonoid β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.add (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) : IsMinFilter (fun x => f x + g x) l a := show IsMinFilter (fun x => f x + g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => add_le_add hx hy) hg theorem IsMaxFilter.add (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => f x + g x) l a := show IsMaxFilter (fun x => f x + g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => add_le_add hx hy) hg theorem IsMinOn.add (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x + g x) s a := IsMinFilter.add hf hg theorem IsMaxOn.add (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x + g x) s a := IsMaxFilter.add hf hg end OrderedAddCommMonoid /-! ### Pointwise negation and subtraction -/ section OrderedAddCommGroup variable [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.neg (hf : IsMinFilter f l a) : IsMaxFilter (fun x => -f x) l a := hf.comp_antitone fun _x _y hx => neg_le_neg hx theorem IsMaxFilter.neg (hf : IsMaxFilter f l a) : IsMinFilter (fun x => -f x) l a := hf.comp_antitone fun _x _y hx => neg_le_neg hx theorem IsExtrFilter.neg (hf : IsExtrFilter f l a) : IsExtrFilter (fun x => -f x) l a := hf.elim (fun hf => hf.neg.isExtr) fun hf => hf.neg.isExtr theorem IsMinOn.neg (hf : IsMinOn f s a) : IsMaxOn (fun x => -f x) s a := hf.comp_antitone fun _x _y hx => neg_le_neg hx theorem IsMaxOn.neg (hf : IsMaxOn f s a) : IsMinOn (fun x => -f x) s a := hf.comp_antitone fun _x _y hx => neg_le_neg hx theorem IsExtrOn.neg (hf : IsExtrOn f s a) : IsExtrOn (fun x => -f x) s a := hf.elim (fun hf => hf.neg.isExtr) fun hf => hf.neg.isExtr theorem IsMinFilter.sub (hf : IsMinFilter f l a) (hg : IsMaxFilter g l a) : IsMinFilter (fun x => f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem IsMaxFilter.sub (hf : IsMaxFilter f l a) (hg : IsMinFilter g l a) : IsMaxFilter (fun x => f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem IsMinOn.sub (hf : IsMinOn f s a) (hg : IsMaxOn g s a) : IsMinOn (fun x => f x - g x) s a := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem IsMaxOn.sub (hf : IsMaxOn f s a) (hg : IsMinOn g s a) : IsMaxOn (fun x => f x - g x) s a := by simpa only [sub_eq_add_neg] using hf.add hg.neg end OrderedAddCommGroup /-! ### Pointwise `sup`/`inf` -/ section SemilatticeSup variable [SemilatticeSup β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.sup (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) : IsMinFilter (fun x => f x ⊔ g x) l a := show IsMinFilter (fun x => f x ⊔ g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => sup_le_sup hx hy) hg theorem IsMaxFilter.sup (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => f x ⊔ g x) l a := show IsMaxFilter (fun x => f x ⊔ g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => sup_le_sup hx hy) hg theorem IsMinOn.sup (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x ⊔ g x) s a := IsMinFilter.sup hf hg theorem IsMaxOn.sup (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x ⊔ g x) s a := IsMaxFilter.sup hf hg end SemilatticeSup section SemilatticeInf variable [SemilatticeInf β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.inf (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) : IsMinFilter (fun x => f x ⊓ g x) l a := show IsMinFilter (fun x => f x ⊓ g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => inf_le_inf hx hy) hg theorem IsMaxFilter.inf (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => f x ⊓ g x) l a := show IsMaxFilter (fun x => f x ⊓ g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => inf_le_inf hx hy) hg theorem IsMinOn.inf (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x ⊓ g x) s a := IsMinFilter.inf hf hg theorem IsMaxOn.inf (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x ⊓ g x) s a := IsMaxFilter.inf hf hg end SemilatticeInf /-! ### Pointwise `min`/`max` -/ section LinearOrder variable [LinearOrder β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.min (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) : IsMinFilter (fun x => min (f x) (g x)) l a := show IsMinFilter (fun x => Min.min (f x) (g x)) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => min_le_min hx hy) hg theorem IsMaxFilter.min (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => min (f x) (g x)) l a := show IsMaxFilter (fun x => Min.min (f x) (g x)) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => min_le_min hx hy) hg theorem IsMinOn.min (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => min (f x) (g x)) s a := IsMinFilter.min hf hg theorem IsMaxOn.min (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => min (f x) (g x)) s a := IsMaxFilter.min hf hg theorem IsMinFilter.max (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) : IsMinFilter (fun x => max (f x) (g x)) l a := show IsMinFilter (fun x => Max.max (f x) (g x)) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => max_le_max hx hy) hg theorem IsMaxFilter.max (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => max (f x) (g x)) l a := show IsMaxFilter (fun x => Max.max (f x) (g x)) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => max_le_max hx hy) hg theorem IsMinOn.max (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => max (f x) (g x)) s a := IsMinFilter.max hf hg theorem IsMaxOn.max (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => max (f x) (g x)) s a := IsMaxFilter.max hf hg end LinearOrder section Eventually /-! ### Relation with `eventually` comparisons of two functions -/ theorem Filter.EventuallyLE.isMaxFilter {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (hle : g ≤ᶠ[l] f) (hfga : f a = g a) (h : IsMaxFilter f l a) : IsMaxFilter g l a := by refine hle.mp (h.mono fun x hf hgf => ?_) rw [← hfga] exact le_trans hgf hf theorem IsMaxFilter.congr {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (h : IsMaxFilter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMaxFilter g l a := heq.symm.le.isMaxFilter hfga h theorem Filter.EventuallyEq.isMaxFilter_iff {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMaxFilter f l a ↔ IsMaxFilter g l a := ⟨fun h => h.congr heq hfga, fun h => h.congr heq.symm hfga.symm⟩ theorem Filter.EventuallyLE.isMinFilter {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (hle : f ≤ᶠ[l] g) (hfga : f a = g a) (h : IsMinFilter f l a) : IsMinFilter g l a := @Filter.EventuallyLE.isMaxFilter _ βᵒᵈ _ _ _ _ _ hle hfga h theorem IsMinFilter.congr {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (h : IsMinFilter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMinFilter g l a := heq.le.isMinFilter hfga h theorem Filter.EventuallyEq.isMinFilter_iff {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMinFilter f l a ↔ IsMinFilter g l a := ⟨fun h => h.congr heq hfga, fun h => h.congr heq.symm hfga.symm⟩ theorem IsExtrFilter.congr {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (h : IsExtrFilter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsExtrFilter g l a := by rw [IsExtrFilter] at * rwa [← heq.isMaxFilter_iff hfga, ← heq.isMinFilter_iff hfga] theorem Filter.EventuallyEq.isExtrFilter_iff {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsExtrFilter f l a ↔ IsExtrFilter g l a := ⟨fun h => h.congr heq hfga, fun h => h.congr heq.symm hfga.symm⟩ end Eventually /-! ### `isMaxOn`/`isMinOn` imply `ciSup`/`ciInf` -/ section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] {f : β → α} {s : Set β} {x₀ : β} theorem IsMaxOn.iSup_eq (hx₀ : x₀ ∈ s) (h : IsMaxOn f s x₀) : ⨆ x : s, f x = f x₀ := haveI : Nonempty s := ⟨⟨x₀, hx₀⟩⟩ ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun x => h x.2) fun _w hw => ⟨⟨x₀, hx₀⟩, hw⟩ theorem IsMinOn.iInf_eq (hx₀ : x₀ ∈ s) (h : IsMinOn f s x₀) : ⨅ x : s, f x = f x₀ := @IsMaxOn.iSup_eq αᵒᵈ β _ _ _ _ hx₀ h end ConditionallyCompleteLinearOrder /-! ### Value of `Finset.sup` / `Finset.inf` -/ section SemilatticeSup variable [SemilatticeSup β] [OrderBot β] {D : α → β} {s : Finset α} theorem sup_eq_of_isMaxOn {a : α} (hmem : a ∈ s) (hmax : IsMaxOn D s a) : s.sup D = D a := (Finset.sup_le hmax).antisymm (Finset.le_sup hmem) theorem sup_eq_of_max [Nonempty α] {b : β} (hb : b ∈ Set.range D) (hmem : D.invFun b ∈ s) (hmax : ∀ a ∈ s, D a ≤ b) : s.sup D = b := by obtain ⟨a, rfl⟩ := hb rw [← Function.apply_invFun_apply (f := D)] apply sup_eq_of_isMaxOn hmem; intro rw [Function.apply_invFun_apply (f := D)]; apply hmax end SemilatticeSup section SemilatticeInf variable [SemilatticeInf β] [OrderTop β] {D : α → β} {s : Finset α} theorem inf_eq_of_isMinOn {a : α} (hmem : a ∈ s) (hmax : IsMinOn D s a) : s.inf D = D a := sup_eq_of_isMaxOn (α := αᵒᵈ) (β := βᵒᵈ) hmem hmax.dual theorem inf_eq_of_min [Nonempty α] {b : β} (hb : b ∈ Set.range D) (hmem : D.invFun b ∈ s) (hmin : ∀ a ∈ s, b ≤ D a) : s.inf D = b := sup_eq_of_max (α := αᵒᵈ) (β := βᵒᵈ) hb hmem hmin end SemilatticeInf
.lake/packages/mathlib/Mathlib/Order/Filter/Germ/Basic.lean
import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE import Mathlib.Data.Int.Cast.Basic import Mathlib.Data.Int.Cast.Pi import Mathlib.Data.Nat.Cast.Basic import Mathlib.Order.Filter.Tendsto /-! # Germ of a function at a filter The germ of a function `f : α → β` at a filter `l : Filter α` is the equivalence class of `f` with respect to the equivalence relation `EventuallyEq l`: `f ≈ g` means `∀ᶠ x in l, f x = g x`. ## Main definitions We define * `Filter.Germ l β` to be the space of germs of functions `α → β` at a filter `l : Filter α`; * coercion from `α → β` to `Germ l β`: `(f : Germ l β)` is the germ of `f : α → β` at `l : Filter α`; this coercion is declared as `CoeTC`; * `(const l c : Germ l β)` is the germ of the constant function `fun x : α ↦ c` at a filter `l`; * coercion from `β` to `Germ l β`: `(↑c : Germ l β)` is the germ of the constant function `fun x : α ↦ c` at a filter `l`; this coercion is declared as `CoeTC`; * `map (F : β → γ) (f : Germ l β)` to be the composition of a function `F` and a germ `f`; * `map₂ (F : β → γ → δ) (f : Germ l β) (g : Germ l γ)` to be the germ of `fun x ↦ F (f x) (g x)` at `l`; * `f.Tendsto lb`: we say that a germ `f : Germ l β` tends to a filter `lb` if its representatives tend to `lb` along `l`; * `f.compTendsto g hg` and `f.compTendsto' g hg`: given `f : Germ l β` and a function `g : γ → α` (resp., a germ `g : Germ lc α`), if `g` tends to `l` along `lc`, then the composition `f ∘ g` is a well-defined germ at `lc`; * `Germ.liftPred`, `Germ.liftRel`: lift a predicate or a relation to the space of germs: `(f : Germ l β).liftPred p` means `∀ᶠ x in l, p (f x)`, and similarly for a relation. We also define `map (F : β → γ) : Germ l β → Germ l γ` sending each germ `f` to `F ∘ f`. For each of the following structures we prove that if `β` has this structure, then so does `Germ l β`: * one-operation algebraic structures up to `CommGroup`; * `MulZeroClass`, `Distrib`, `Semiring`, `CommSemiring`, `Ring`, `CommRing`; * `MulAction`, `DistribMulAction`, `Module`; * `Preorder`, `PartialOrder`, and `Lattice` structures, as well as `BoundedOrder`; ## Tags filter, germ -/ assert_not_exists IsOrderedRing open scoped Relator namespace Filter variable {α β γ δ : Type*} {l : Filter α} {f g h : α → β} theorem const_eventuallyEq' [NeBot l] {a b : β} : (∀ᶠ _ in l, a = b) ↔ a = b := eventually_const theorem const_eventuallyEq [NeBot l] {a b : β} : ((fun _ => a) =ᶠ[l] fun _ => b) ↔ a = b := @const_eventuallyEq' _ _ _ _ a b /-- Setoid used to define the space of germs. -/ def germSetoid (l : Filter α) (β : Type*) : Setoid (α → β) where r := EventuallyEq l iseqv := ⟨EventuallyEq.refl _, EventuallyEq.symm, EventuallyEq.trans⟩ /-- The space of germs of functions `α → β` at a filter `l`. -/ def Germ (l : Filter α) (β : Type*) : Type _ := Quotient (germSetoid l β) /-- Setoid used to define the filter product. This is a dependent version of `Filter.germSetoid`. -/ def productSetoid (l : Filter α) (ε : α → Type*) : Setoid ((a : _) → ε a) where r f g := ∀ᶠ a in l, f a = g a iseqv := ⟨fun _ => Eventually.of_forall fun _ => rfl, fun h => h.mono fun _ => Eq.symm, fun h1 h2 => h1.congr (h2.mono fun _ hx => hx ▸ Iff.rfl)⟩ /-- The filter product `(a : α) → ε a` at a filter `l`. This is a dependent version of `Filter.Germ`. -/ def Product (l : Filter α) (ε : α → Type*) : Type _ := Quotient (productSetoid l ε) namespace Product variable {ε : α → Type*} instance coeTC : CoeTC ((a : _) → ε a) (l.Product ε) := ⟨@Quotient.mk' _ (productSetoid _ ε)⟩ instance instInhabited [(a : _) → Inhabited (ε a)] : Inhabited (l.Product ε) := ⟨(↑fun a => (default : ε a) : l.Product ε)⟩ end Product namespace Germ /-- The germ corresponding to a global function. -/ @[coe] def ofFun : (α → β) → Germ l β := @Quotient.mk' _ (germSetoid _ _) instance : CoeTC (α → β) (Germ l β) := ⟨ofFun⟩ /-- Germ of the constant function `fun x : α ↦ c` at a filter `l`. -/ @[coe] def const {l : Filter α} (b : β) : (Germ l β) := ofFun fun _ => b instance coeTail : CoeTail β (Germ l β) := ⟨const⟩ @[deprecated (since := "2025-08-28")] alias coeTC := coeTail /-- A germ `P` of functions `α → β` is constant w.r.t. `l`. -/ def IsConstant {l : Filter α} (P : Germ l β) : Prop := P.liftOn (fun f ↦ ∃ b : β, f =ᶠ[l] (fun _ ↦ b)) <| by suffices ∀ f g : α → β, ∀ b : β, f =ᶠ[l] g → (f =ᶠ[l] fun _ ↦ b) → (g =ᶠ[l] fun _ ↦ b) from fun f g h ↦ propext ⟨fun ⟨b, hb⟩ ↦ ⟨b, this f g b h hb⟩, fun ⟨b, hb⟩ ↦ ⟨b, h.trans hb⟩⟩ exact fun f g b hfg hf ↦ (hfg.symm).trans hf theorem isConstant_coe {l : Filter α} {b} (h : ∀ x', f x' = b) : (↑f : Germ l β).IsConstant := ⟨b, Eventually.of_forall h⟩ @[simp] theorem isConstant_coe_const {l : Filter α} {b : β} : (fun _ : α ↦ b : Germ l β).IsConstant := by use b /-- If `f : α → β` is constant w.r.t. `l` and `g : β → γ`, then `g ∘ f : α → γ` also is. -/ lemma isConstant_comp {l : Filter α} {f : α → β} {g : β → γ} (h : (f : Germ l β).IsConstant) : ((g ∘ f) : Germ l γ).IsConstant := by obtain ⟨b, hb⟩ := h exact ⟨g b, hb.fun_comp g⟩ @[simp] theorem quot_mk_eq_coe (l : Filter α) (f : α → β) : Quot.mk _ f = (f : Germ l β) := rfl @[simp] theorem mk'_eq_coe (l : Filter α) (f : α → β) : @Quotient.mk' _ (germSetoid _ _) f = (f : Germ l β) := rfl @[elab_as_elim] theorem inductionOn (f : Germ l β) {p : Germ l β → Prop} (h : ∀ f : α → β, p f) : p f := Quotient.inductionOn' f h @[elab_as_elim] theorem inductionOn₂ (f : Germ l β) (g : Germ l γ) {p : Germ l β → Germ l γ → Prop} (h : ∀ (f : α → β) (g : α → γ), p f g) : p f g := Quotient.inductionOn₂' f g h @[elab_as_elim] theorem inductionOn₃ (f : Germ l β) (g : Germ l γ) (h : Germ l δ) {p : Germ l β → Germ l γ → Germ l δ → Prop} (H : ∀ (f : α → β) (g : α → γ) (h : α → δ), p f g h) : p f g h := Quotient.inductionOn₃' f g h H /-- Given a map `F : (α → β) → (γ → δ)` that sends functions eventually equal at `l` to functions eventually equal at `lc`, returns a map from `Germ l β` to `Germ lc δ`. -/ def map' {lc : Filter γ} (F : (α → β) → γ → δ) (hF : (l.EventuallyEq ⇒ lc.EventuallyEq) F F) : Germ l β → Germ lc δ := Quotient.map' F hF /-- Given a germ `f : Germ l β` and a function `F : (α → β) → γ` sending eventually equal functions to the same value, returns the value `F` takes on functions having germ `f` at `l`. -/ def liftOn {γ : Sort*} (f : Germ l β) (F : (α → β) → γ) (hF : (l.EventuallyEq ⇒ (· = ·)) F F) : γ := Quotient.liftOn' f F hF @[simp] theorem map'_coe {lc : Filter γ} (F : (α → β) → γ → δ) (hF : (l.EventuallyEq ⇒ lc.EventuallyEq) F F) (f : α → β) : map' F hF f = F f := rfl @[simp, norm_cast] theorem coe_eq : (f : Germ l β) = g ↔ f =ᶠ[l] g := Quotient.eq'' alias ⟨_, _root_.Filter.EventuallyEq.germ_eq⟩ := coe_eq /-- Lift a function `β → γ` to a function `Germ l β → Germ l γ`. -/ def map (op : β → γ) : Germ l β → Germ l γ := map' (op ∘ ·) fun _ _ H => H.mono fun _ H => congr_arg op H @[simp] theorem map_coe (op : β → γ) (f : α → β) : map op (f : Germ l β) = op ∘ f := rfl @[simp] theorem map_id : map id = (id : Germ l β → Germ l β) := by ext ⟨f⟩ rfl theorem map_map (op₁ : γ → δ) (op₂ : β → γ) (f : Germ l β) : map op₁ (map op₂ f) = map (op₁ ∘ op₂) f := inductionOn f fun _ => rfl /-- Lift a binary function `β → γ → δ` to a function `Germ l β → Germ l γ → Germ l δ`. -/ def map₂ (op : β → γ → δ) : Germ l β → Germ l γ → Germ l δ := Quotient.map₂ (fun f g x => op (f x) (g x)) fun f f' Hf g g' Hg => Hg.mp <| Hf.mono fun x Hf Hg => by simp only [Hf, Hg] @[simp] theorem map₂_coe (op : β → γ → δ) (f : α → β) (g : α → γ) : map₂ op (f : Germ l β) g = fun x => op (f x) (g x) := rfl /-- A germ at `l` of maps from `α` to `β` tends to `lb : Filter β` if it is represented by a map which tends to `lb` along `l`. -/ protected def Tendsto (f : Germ l β) (lb : Filter β) : Prop := liftOn f (fun f => Tendsto f l lb) fun _f _g H => propext (tendsto_congr' H) @[simp, norm_cast] theorem coe_tendsto {f : α → β} {lb : Filter β} : (f : Germ l β).Tendsto lb ↔ Tendsto f l lb := Iff.rfl alias ⟨_, _root_.Filter.Tendsto.germ_tendsto⟩ := coe_tendsto /-- Given two germs `f : Germ l β`, and `g : Germ lc α`, where `l : Filter α`, if `g` tends to `l`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/ def compTendsto' (f : Germ l β) {lc : Filter γ} (g : Germ lc α) (hg : g.Tendsto l) : Germ lc β := liftOn f (fun f => g.map f) fun _f₁ _f₂ hF => inductionOn g (fun _g hg => coe_eq.2 <| hg.eventually hF) hg @[simp] theorem coe_compTendsto' (f : α → β) {lc : Filter γ} {g : Germ lc α} (hg : g.Tendsto l) : (f : Germ l β).compTendsto' g hg = g.map f := rfl /-- Given a germ `f : Germ l β` and a function `g : γ → α`, where `l : Filter α`, if `g` tends to `l` along `lc : Filter γ`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/ def compTendsto (f : Germ l β) {lc : Filter γ} (g : γ → α) (hg : Tendsto g lc l) : Germ lc β := f.compTendsto' _ hg.germ_tendsto @[simp] theorem coe_compTendsto (f : α → β) {lc : Filter γ} {g : γ → α} (hg : Tendsto g lc l) : (f : Germ l β).compTendsto g hg = f ∘ g := rfl @[simp] theorem compTendsto'_coe (f : Germ l β) {lc : Filter γ} {g : γ → α} (hg : Tendsto g lc l) : f.compTendsto' _ hg.germ_tendsto = f.compTendsto g hg := rfl theorem Filter.Tendsto.congr_germ {f g : β → γ} {l : Filter α} {l' : Filter β} (h : f =ᶠ[l'] g) {φ : α → β} (hφ : Tendsto φ l l') : (f ∘ φ : Germ l γ) = g ∘ φ := EventuallyEq.germ_eq (h.comp_tendsto hφ) lemma isConstant_comp_tendsto {lc : Filter γ} {g : γ → α} (hf : (f : Germ l β).IsConstant) (hg : Tendsto g lc l) : IsConstant (f ∘ g : Germ lc β) := by rcases hf with ⟨b, hb⟩ exact ⟨b, hb.comp_tendsto hg⟩ /-- If a germ `f : Germ l β` is constant, where `l : Filter α`, and a function `g : γ → α` tends to `l` along `lc : Filter γ`, the germ of the composition `f ∘ g` is also constant. -/ lemma isConstant_compTendsto {f : Germ l β} {lc : Filter γ} {g : γ → α} (hf : f.IsConstant) (hg : Tendsto g lc l) : (f.compTendsto g hg).IsConstant := by induction f using Quotient.inductionOn with | _ f => ?_ exact isConstant_comp_tendsto hf hg @[simp, norm_cast] theorem const_inj [NeBot l] {a b : β} : (↑a : Germ l β) = ↑b ↔ a = b := coe_eq.trans const_eventuallyEq @[simp] theorem map_const (l : Filter α) (a : β) (f : β → γ) : (↑a : Germ l β).map f = ↑(f a) := rfl @[simp] theorem map₂_const (l : Filter α) (b : β) (c : γ) (f : β → γ → δ) : map₂ f (↑b : Germ l β) ↑c = ↑(f b c) := rfl @[simp] theorem const_compTendsto {l : Filter α} (b : β) {lc : Filter γ} {g : γ → α} (hg : Tendsto g lc l) : (↑b : Germ l β).compTendsto g hg = ↑b := rfl @[simp] theorem const_compTendsto' {l : Filter α} (b : β) {lc : Filter γ} {g : Germ lc α} (hg : g.Tendsto l) : (↑b : Germ l β).compTendsto' g hg = ↑b := inductionOn g (fun _ _ => rfl) hg /-- Lift a predicate on `β` to `Germ l β`. -/ def LiftPred (p : β → Prop) (f : Germ l β) : Prop := liftOn f (fun f => ∀ᶠ x in l, p (f x)) fun _f _g H => propext <| eventually_congr <| H.mono fun _x hx => hx ▸ Iff.rfl @[simp] theorem liftPred_coe {p : β → Prop} {f : α → β} : LiftPred p (f : Germ l β) ↔ ∀ᶠ x in l, p (f x) := Iff.rfl theorem liftPred_const {p : β → Prop} {x : β} (hx : p x) : LiftPred p (↑x : Germ l β) := Eventually.of_forall fun _y => hx @[simp] theorem liftPred_const_iff [NeBot l] {p : β → Prop} {x : β} : LiftPred p (↑x : Germ l β) ↔ p x := @eventually_const _ _ _ (p x) /-- Lift a relation `r : β → γ → Prop` to `Germ l β → Germ l γ → Prop`. -/ def LiftRel (r : β → γ → Prop) (f : Germ l β) (g : Germ l γ) : Prop := Quotient.liftOn₂' f g (fun f g => ∀ᶠ x in l, r (f x) (g x)) fun _f _g _f' _g' Hf Hg => propext <| eventually_congr <| Hg.mp <| Hf.mono fun _x hf hg => hf ▸ hg ▸ Iff.rfl @[simp] theorem liftRel_coe {r : β → γ → Prop} {f : α → β} {g : α → γ} : LiftRel r (f : Germ l β) g ↔ ∀ᶠ x in l, r (f x) (g x) := Iff.rfl theorem liftRel_const {r : β → γ → Prop} {x : β} {y : γ} (h : r x y) : LiftRel r (↑x : Germ l β) ↑y := Eventually.of_forall fun _ => h @[simp] theorem liftRel_const_iff [NeBot l] {r : β → γ → Prop} {x : β} {y : γ} : LiftRel r (↑x : Germ l β) ↑y ↔ r x y := @eventually_const _ _ _ (r x y) instance instInhabited [Inhabited β] : Inhabited (Germ l β) := ⟨↑(default : β)⟩ section Monoid variable {M : Type*} {G : Type*} @[to_additive] instance instMul [Mul M] : Mul (Germ l M) := ⟨map₂ (· * ·)⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_mul [Mul M] (f g : α → M) : ↑(f * g) = (f * g : Germ l M) := rfl @[to_additive] instance instOne [One M] : One (Germ l M) := ⟨↑(1 : M)⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_one [One M] : ↑(1 : α → M) = (1 : Germ l M) := rfl @[to_additive] instance instSemigroup [Semigroup M] : Semigroup (Germ l M) := { mul_assoc := fun a b c => Quotient.inductionOn₃' a b c fun _ _ _ => congrArg ofFun <| mul_assoc .. } @[to_additive] instance instCommSemigroup [CommSemigroup M] : CommSemigroup (Germ l M) := { mul_comm := Quotient.ind₂' fun _ _ => congrArg ofFun <| mul_comm .. } @[to_additive] instance instIsLeftCancelMul [Mul M] [IsLeftCancelMul M] : IsLeftCancelMul (Germ l M) where mul_left_cancel f₁ f₂ f₃ := inductionOn₃ f₁ f₂ f₃ fun _f₁ _f₂ _f₃ H => coe_eq.2 ((coe_eq.1 H).mono fun _x => mul_left_cancel) @[to_additive] instance instIsRightCancelMul [Mul M] [IsRightCancelMul M] : IsRightCancelMul (Germ l M) where mul_right_cancel f₁ f₂ f₃ := inductionOn₃ f₁ f₂ f₃ fun _f₁ _f₂ _f₃ H => coe_eq.2 <| (coe_eq.1 H).mono fun _x => mul_right_cancel @[to_additive] instance instIsCancelMul [Mul M] [IsCancelMul M] : IsCancelMul (Germ l M) where @[to_additive] instance instLeftCancelSemigroup [LeftCancelSemigroup M] : LeftCancelSemigroup (Germ l M) where mul_left_cancel _ _ _ := mul_left_cancel @[to_additive] instance instRightCancelSemigroup [RightCancelSemigroup M] : RightCancelSemigroup (Germ l M) where mul_right_cancel _ _ _ := mul_right_cancel @[to_additive] instance instMulOneClass [MulOneClass M] : MulOneClass (Germ l M) := { one_mul := Quotient.ind' fun _ => congrArg ofFun <| one_mul _ mul_one := Quotient.ind' fun _ => congrArg ofFun <| mul_one _ } @[to_additive] instance instSMul [SMul M G] : SMul M (Germ l G) where smul n := map (n • ·) @[to_additive existing instSMul] instance instPow [Pow G M] : Pow (Germ l G) M where pow f n := map (· ^ n) f @[to_additive (attr := simp, norm_cast)] theorem coe_smul [SMul M G] (n : M) (f : α → G) : ↑(n • f) = n • (f : Germ l G) := rfl @[to_additive (attr := simp, norm_cast)] theorem const_smul [SMul M G] (n : M) (a : G) : (↑(n • a) : Germ l G) = n • (↑a : Germ l G) := rfl @[to_additive (attr := simp, norm_cast)] theorem coe_pow [Pow G M] (f : α → G) (n : M) : ↑(f ^ n) = (f : Germ l G) ^ n := rfl @[to_additive (attr := simp, norm_cast)] theorem const_pow [Pow G M] (a : G) (n : M) : (↑(a ^ n) : Germ l G) = (↑a : Germ l G) ^ n := rfl -- TODO: https://github.com/leanprover-community/mathlib4/pull/7432 @[to_additive] instance instMonoid [Monoid M] : Monoid (Germ l M) := { Function.Surjective.monoid ofFun Quot.mk_surjective (by rfl) (fun _ _ => by rfl) fun _ _ => by rfl with toSemigroup := instSemigroup toOne := instOne npow := fun n a => a ^ n } /-- Coercion from functions to germs as a monoid homomorphism. -/ @[to_additive /-- Coercion from functions to germs as an additive monoid homomorphism. -/] def coeMulHom [Monoid M] (l : Filter α) : (α → M) →* Germ l M where toFun := ofFun; map_one' := rfl; map_mul' _ _ := rfl @[to_additive (attr := simp)] theorem coe_coeMulHom [Monoid M] : (coeMulHom l : (α → M) → Germ l M) = ofFun := rfl @[to_additive] instance instCommMonoid [CommMonoid M] : CommMonoid (Germ l M) := { mul_comm := mul_comm } instance instNatCast [NatCast M] : NatCast (Germ l M) where natCast n := (n : α → M) @[simp] theorem natCast_def [NatCast M] (n : ℕ) : ((fun _ ↦ n : α → M) : Germ l M) = n := rfl @[simp, norm_cast] theorem const_nat [NatCast M] (n : ℕ) : ((n : M) : Germ l M) = n := rfl @[simp, norm_cast] theorem coe_ofNat [NatCast M] (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : α → M) : Germ l M) = OfNat.ofNat n := rfl @[simp, norm_cast] theorem const_ofNat [NatCast M] (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : M) : Germ l M) = OfNat.ofNat n := rfl instance instIntCast [IntCast M] : IntCast (Germ l M) where intCast n := (n : α → M) @[simp] theorem intCast_def [IntCast M] (n : ℤ) : ((fun _ ↦ n : α → M) : Germ l M) = n := rfl instance instAddMonoidWithOne [AddMonoidWithOne M] : AddMonoidWithOne (Germ l M) where natCast_zero := congrArg ofFun <| by simp; rfl natCast_succ _ := congrArg ofFun <| by simp; rfl instance instAddCommMonoidWithOne [AddCommMonoidWithOne M] : AddCommMonoidWithOne (Germ l M) := { add_comm := add_comm } @[to_additive] instance instInv [Inv G] : Inv (Germ l G) := ⟨map Inv.inv⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_inv [Inv G] (f : α → G) : ↑f⁻¹ = (f⁻¹ : Germ l G) := rfl @[to_additive (attr := simp, norm_cast)] theorem const_inv [Inv G] (a : G) : (↑(a⁻¹) : Germ l G) = (↑a)⁻¹ := rfl @[to_additive] instance instDiv [Div M] : Div (Germ l M) := ⟨map₂ (· / ·)⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_div [Div M] (f g : α → M) : ↑(f / g) = (f / g : Germ l M) := rfl @[to_additive (attr := simp, norm_cast)] theorem const_div [Div M] (a b : M) : (↑(a / b) : Germ l M) = ↑a / ↑b := rfl @[to_additive] instance instInvolutiveInv [InvolutiveInv G] : InvolutiveInv (Germ l G) := { inv_inv := Quotient.ind' fun _ => congrArg ofFun<| inv_inv _ } instance instHasDistribNeg [Mul G] [HasDistribNeg G] : HasDistribNeg (Germ l G) := { neg_mul := Quotient.ind₂' fun _ _ => congrArg ofFun <| neg_mul .. mul_neg := Quotient.ind₂' fun _ _ => congrArg ofFun <| mul_neg .. } @[to_additive] instance instInvOneClass [InvOneClass G] : InvOneClass (Germ l G) := ⟨congr_arg ofFun inv_one⟩ @[to_additive subNegMonoid] instance instDivInvMonoid [DivInvMonoid G] : DivInvMonoid (Germ l G) where zpow z f := f ^ z zpow_zero' := Quotient.ind' fun _ => congrArg ofFun <| funext fun _ => DivInvMonoid.zpow_zero' _ zpow_succ' _ := Quotient.ind' fun _ => congrArg ofFun <| funext fun _ => DivInvMonoid.zpow_succ' .. zpow_neg' _ := Quotient.ind' fun _ => congrArg ofFun <| funext fun _ => DivInvMonoid.zpow_neg' .. div_eq_mul_inv := Quotient.ind₂' fun _ _ ↦ congrArg ofFun <| div_eq_mul_inv .. @[to_additive] instance instDivisionMonoid [DivisionMonoid G] : DivisionMonoid (Germ l G) where inv_inv := inv_inv mul_inv_rev x y := inductionOn₂ x y fun _ _ ↦ congr_arg ofFun <| mul_inv_rev _ _ inv_eq_of_mul x y := inductionOn₂ x y fun _ _ h ↦ coe_eq.2 <| (coe_eq.1 h).mono fun _ ↦ DivisionMonoid.inv_eq_of_mul _ _ @[to_additive] instance instGroup [Group G] : Group (Germ l G) := { inv_mul_cancel := Quotient.ind' fun _ => congrArg ofFun <| inv_mul_cancel _ } @[to_additive] instance instCommGroup [CommGroup G] : CommGroup (Germ l G) := { mul_comm := mul_comm } instance instAddGroupWithOne [AddGroupWithOne G] : AddGroupWithOne (Germ l G) where __ := instAddMonoidWithOne __ := instAddGroup intCast_ofNat _ := congrArg ofFun <| by simp intCast_negSucc _ := congrArg ofFun <| by simp [Function.comp_def]; rfl end Monoid section Ring variable {R : Type*} instance instNontrivial [Nontrivial R] [NeBot l] : Nontrivial (Germ l R) := let ⟨x, y, h⟩ := exists_pair_ne R ⟨⟨↑x, ↑y, mt const_inj.1 h⟩⟩ instance instMulZeroClass [MulZeroClass R] : MulZeroClass (Germ l R) := { zero_mul := Quotient.ind' fun _ => congrArg ofFun <| zero_mul _ mul_zero := Quotient.ind' fun _ => congrArg ofFun <| mul_zero _ } instance instMulZeroOneClass [MulZeroOneClass R] : MulZeroOneClass (Germ l R) where __ := instMulZeroClass __ := instMulOneClass instance instMonoidWithZero [MonoidWithZero R] : MonoidWithZero (Germ l R) where __ := instMonoid __ := instMulZeroClass instance instDistrib [Distrib R] : Distrib (Germ l R) where left_distrib a b c := Quotient.inductionOn₃' a b c fun _ _ _ ↦ congrArg ofFun <| left_distrib .. right_distrib a b c := Quotient.inductionOn₃' a b c fun _ _ _ ↦ congrArg ofFun <| right_distrib .. instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring (Germ l R) where __ := instAddCommMonoid __ := instDistrib __ := instMulZeroClass instance instNonUnitalSemiring [NonUnitalSemiring R] : NonUnitalSemiring (Germ l R) := { mul_assoc := mul_assoc } instance instNonAssocSemiring [NonAssocSemiring R] : NonAssocSemiring (Germ l R) where __ := instNonUnitalNonAssocSemiring __ := instMulZeroOneClass __ := instAddMonoidWithOne instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing R] : NonUnitalNonAssocRing (Germ l R) where __ := instAddCommGroup __ := instNonUnitalNonAssocSemiring instance instNonUnitalRing [NonUnitalRing R] : NonUnitalRing (Germ l R) := { mul_assoc := mul_assoc } instance instNonAssocRing [NonAssocRing R] : NonAssocRing (Germ l R) where __ := instNonUnitalNonAssocRing __ := instNonAssocSemiring __ := instAddGroupWithOne instance instSemiring [Semiring R] : Semiring (Germ l R) where __ := instNonUnitalSemiring __ := instNonAssocSemiring __ := instMonoidWithZero instance instRing [Ring R] : Ring (Germ l R) where __ := instSemiring __ := instAddCommGroup __ := instNonAssocRing instance instNonUnitalCommSemiring [NonUnitalCommSemiring R] : NonUnitalCommSemiring (Germ l R) := { mul_comm := mul_comm } instance instCommSemiring [CommSemiring R] : CommSemiring (Germ l R) := { mul_comm := mul_comm } instance instNonUnitalCommRing [NonUnitalCommRing R] : NonUnitalCommRing (Germ l R) where __ := instNonUnitalRing __ := instCommSemigroup instance instCommRing [CommRing R] : CommRing (Germ l R) := { mul_comm := mul_comm } /-- Coercion `(α → R) → Germ l R` as a `RingHom`. -/ def coeRingHom [Semiring R] (l : Filter α) : (α → R) →+* Germ l R := { (coeMulHom l : _ →* Germ l R), (coeAddHom l : _ →+ Germ l R) with toFun := ofFun } @[simp] theorem coe_coeRingHom [Semiring R] : (coeRingHom l : (α → R) → Germ l R) = ofFun := rfl end Ring section Module variable {M N R : Type*} @[to_additive] instance instSMul' [SMul M β] : SMul (Germ l M) (Germ l β) := ⟨map₂ (· • ·)⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_smul' [SMul M β] (c : α → M) (f : α → β) : ↑(c • f) = (c : Germ l M) • (f : Germ l β) := rfl @[to_additive] instance instMulAction [Monoid M] [MulAction M β] : MulAction M (Germ l β) where one_smul f := inductionOn f fun f => by norm_cast simp [one_smul] mul_smul c₁ c₂ f := inductionOn f fun f => by norm_cast simp [mul_smul] @[to_additive] instance instMulAction' [Monoid M] [MulAction M β] : MulAction (Germ l M) (Germ l β) where one_smul f := inductionOn f fun f => by simp only [← coe_one, ← coe_smul', one_smul] mul_smul c₁ c₂ f := inductionOn₃ c₁ c₂ f fun c₁ c₂ f => by norm_cast simp [mul_smul] instance instDistribMulAction [Monoid M] [AddMonoid N] [DistribMulAction M N] : DistribMulAction M (Germ l N) where smul_add c f g := inductionOn₂ f g fun f g => by norm_cast simp [smul_add] smul_zero c := by simp only [← coe_zero, ← coe_smul, smul_zero] instance instDistribMulAction' [Monoid M] [AddMonoid N] [DistribMulAction M N] : DistribMulAction (Germ l M) (Germ l N) where smul_add c f g := inductionOn₃ c f g fun c f g => by norm_cast simp [smul_add] smul_zero c := inductionOn c fun c => by simp only [← coe_zero, ← coe_smul', smul_zero] instance instModule [Semiring R] [AddCommMonoid M] [Module R M] : Module R (Germ l M) where add_smul c₁ c₂ f := inductionOn f fun f => by norm_cast simp [add_smul] zero_smul f := inductionOn f fun f => by norm_cast simp [zero_smul] instance instModule' [Semiring R] [AddCommMonoid M] [Module R M] : Module (Germ l R) (Germ l M) where add_smul c₁ c₂ f := inductionOn₃ c₁ c₂ f fun c₁ c₂ f => by norm_cast simp [add_smul] zero_smul f := inductionOn f fun f => by simp only [← coe_zero, ← coe_smul', zero_smul] end Module instance instLE [LE β] : LE (Germ l β) := ⟨LiftRel (· ≤ ·)⟩ theorem le_def [LE β] : ((· ≤ ·) : Germ l β → Germ l β → Prop) = LiftRel (· ≤ ·) := rfl @[simp] theorem coe_le [LE β] : (f : Germ l β) ≤ g ↔ f ≤ᶠ[l] g := Iff.rfl theorem coe_nonneg [LE β] [Zero β] {f : α → β} : 0 ≤ (f : Germ l β) ↔ ∀ᶠ x in l, 0 ≤ f x := Iff.rfl theorem const_le [LE β] {x y : β} : x ≤ y → (↑x : Germ l β) ≤ ↑y := liftRel_const @[simp, norm_cast] theorem const_le_iff [LE β] [NeBot l] {x y : β} : (↑x : Germ l β) ≤ ↑y ↔ x ≤ y := liftRel_const_iff instance instPreorder [Preorder β] : Preorder (Germ l β) where le_refl f := inductionOn f <| EventuallyLE.refl l le_trans f₁ f₂ f₃ := inductionOn₃ f₁ f₂ f₃ fun _ _ _ => EventuallyLE.trans instance instPartialOrder [PartialOrder β] : PartialOrder (Germ l β) where le_antisymm f g := inductionOn₂ f g fun _ _ h₁ h₂ ↦ (EventuallyLE.antisymm h₁ h₂).germ_eq instance instBot [Bot β] : Bot (Germ l β) := ⟨↑(⊥ : β)⟩ instance instTop [Top β] : Top (Germ l β) := ⟨↑(⊤ : β)⟩ @[simp, norm_cast] theorem const_bot [Bot β] : (↑(⊥ : β) : Germ l β) = ⊥ := rfl @[simp, norm_cast] theorem const_top [Top β] : (↑(⊤ : β) : Germ l β) = ⊤ := rfl instance instOrderBot [LE β] [OrderBot β] : OrderBot (Germ l β) where bot_le f := inductionOn f fun _ => Eventually.of_forall fun _ => bot_le instance instOrderTop [LE β] [OrderTop β] : OrderTop (Germ l β) where le_top f := inductionOn f fun _ => Eventually.of_forall fun _ => le_top instance instBoundedOrder [LE β] [BoundedOrder β] : BoundedOrder (Germ l β) where __ := instOrderBot __ := instOrderTop instance instSup [Max β] : Max (Germ l β) := ⟨map₂ (· ⊔ ·)⟩ instance instInf [Min β] : Min (Germ l β) := ⟨map₂ (· ⊓ ·)⟩ @[simp, norm_cast] theorem const_sup [Max β] (a b : β) : ↑(a ⊔ b) = (↑a ⊔ ↑b : Germ l β) := rfl @[simp, norm_cast] theorem const_inf [Min β] (a b : β) : ↑(a ⊓ b) = (↑a ⊓ ↑b : Germ l β) := rfl instance instSemilatticeSup [SemilatticeSup β] : SemilatticeSup (Germ l β) where sup := max le_sup_left f g := inductionOn₂ f g fun _f _g => Eventually.of_forall fun _x ↦ le_sup_left le_sup_right f g := inductionOn₂ f g fun _f _g ↦ Eventually.of_forall fun _x ↦ le_sup_right sup_le f₁ f₂ g := inductionOn₃ f₁ f₂ g fun _f₁ _f₂ _g h₁ h₂ ↦ h₂.mp <| h₁.mono fun _x ↦ sup_le instance instSemilatticeInf [SemilatticeInf β] : SemilatticeInf (Germ l β) where inf := min inf_le_left f g := inductionOn₂ f g fun _f _g ↦ Eventually.of_forall fun _x ↦ inf_le_left inf_le_right f g := inductionOn₂ f g fun _f _g ↦ Eventually.of_forall fun _x ↦ inf_le_right le_inf f₁ f₂ g := inductionOn₃ f₁ f₂ g fun _f₁ _f₂ _g h₁ h₂ ↦ h₂.mp <| h₁.mono fun _x ↦ le_inf instance instLattice [Lattice β] : Lattice (Germ l β) where __ := instSemilatticeSup __ := instSemilatticeInf instance instDistribLattice [DistribLattice β] : DistribLattice (Germ l β) where le_sup_inf f g h := inductionOn₃ f g h fun _f _g _h ↦ Eventually.of_forall fun _ ↦ le_sup_inf @[to_additive] instance instExistsMulOfLE [Mul β] [LE β] [ExistsMulOfLE β] : ExistsMulOfLE (Germ l β) where exists_mul_of_le {x y} := inductionOn₂ x y fun f g (h : f ≤ᶠ[l] g) ↦ by classical choose c hc using fun x (hx : f x ≤ g x) ↦ exists_mul_of_le hx refine ⟨ofFun fun x ↦ if hx : f x ≤ g x then c x hx else f x, coe_eq.2 ?_⟩ filter_upwards [h] with x hx rw [dif_pos hx, hc] end Germ end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Germ/OrderedMonoid.lean
import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Order.Filter.Germ.Basic /-! # Ordered monoid instances on the space of germs of a function at a filter For each of the following structures we prove that if `β` has this structure, then so does `Germ l β`: * `OrderedCancelCommMonoid` and `OrderedCancelAddCommMonoid`. ## Tags filter, germ -/ namespace Filter.Germ variable {α : Type*} {β : Type*} {l : Filter α} @[to_additive] instance instIsOrderedMonoid [CommMonoid β] [PartialOrder β] [IsOrderedMonoid β] : IsOrderedMonoid (Germ l β) where mul_le_mul_left f g := inductionOn₂ f g fun _ _ H h ↦ inductionOn h fun _ ↦ H.mono fun _ H ↦ by dsimp; gcongr @[to_additive] instance instIsOrderedCancelMonoid [CommMonoid β] [PartialOrder β] [IsOrderedCancelMonoid β] : IsOrderedCancelMonoid (Germ l β) where le_of_mul_le_mul_left f g h := inductionOn₃ f g h fun _ _ _ H ↦ H.mono fun _ ↦ le_of_mul_le_mul_left' @[to_additive] instance instCanonicallyOrderedMul [Mul β] [LE β] [CanonicallyOrderedMul β] : CanonicallyOrderedMul (Germ l β) where le_mul_self x y := inductionOn₂ x y fun _ _ ↦ Eventually.of_forall fun _ ↦ le_mul_self le_self_mul x y := inductionOn₂ x y fun _ _ ↦ Eventually.of_forall fun _ ↦ le_self_mul end Filter.Germ
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/ModEq.lean
import Mathlib.Algebra.Order.Group.Nat import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.ModEq import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.AtTopBot.Monoid /-! # Numbers are frequently ModEq to fixed numbers In this file we prove that `m ≡ d [MOD n]` frequently as `m → ∞`. -/ open Filter namespace Nat /-- Infinitely many natural numbers are equal to `d` mod `n`. -/ theorem frequently_modEq {n : ℕ} (h : n ≠ 0) (d : ℕ) : ∃ᶠ m in atTop, m ≡ d [MOD n] := ((tendsto_add_atTop_nat d).comp (tendsto_id.nsmul_atTop h.bot_lt)).frequently <| Frequently.of_forall fun m => by simp [Nat.modEq_iff_dvd] theorem frequently_mod_eq {d n : ℕ} (h : d < n) : ∃ᶠ m in atTop, m % n = d := by simpa only [Nat.ModEq, mod_eq_of_lt h] using frequently_modEq h.ne_bot d theorem frequently_even : ∃ᶠ m : ℕ in atTop, Even m := by simpa only [even_iff] using frequently_mod_eq zero_lt_two theorem frequently_odd : ∃ᶠ m : ℕ in atTop, Odd m := by simpa only [odd_iff] using frequently_mod_eq one_lt_two end Nat theorem Filter.nonneg_of_eventually_pow_nonneg {α : Type*} [Ring α] [LinearOrder α] [IsStrictOrderedRing α] {a : α} (h : ∀ᶠ n in atTop, 0 ≤ a ^ (n : ℕ)) : 0 ≤ a := let ⟨_n, ho, hn⟩ := (Nat.frequently_odd.and_eventually h).exists ho.pow_nonneg_iff.1 hn
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Finite.lean
import Mathlib.Data.Set.Finite.Lemmas import Mathlib.Order.Filter.Bases.Finite import Mathlib.Order.Filter.AtTopBot.Basic /-! # Finiteness and `Filter.atTop` and `Filter.atBot` filters This file contains results on `Filter.atTop` and `Filter.atBot` that depend on the finiteness theory developed in Mathlib. -/ variable {ι ι' α β γ : Type*} open Set namespace Filter theorem eventually_forall_ge_atTop [Preorder α] {p : α → Prop} : (∀ᶠ x in atTop, ∀ y, x ≤ y → p y) ↔ ∀ᶠ x in atTop, p x := by refine ⟨fun h ↦ h.mono fun x hx ↦ hx x le_rfl, fun h ↦ ?_⟩ rcases (hasBasis_iInf_principal_finite _).eventually_iff.1 h with ⟨S, hSf, hS⟩ refine mem_iInf_of_iInter hSf (V := fun x ↦ Ici x.1) (fun _ ↦ Subset.rfl) fun x hx y hy ↦ ?_ simp only [mem_iInter] at hS hx exact hS fun z hz ↦ le_trans (hx ⟨z, hz⟩) hy theorem eventually_forall_le_atBot [Preorder α] {p : α → Prop} : (∀ᶠ x in atBot, ∀ y, y ≤ x → p y) ↔ ∀ᶠ x in atBot, p x := eventually_forall_ge_atTop (α := αᵒᵈ) theorem Tendsto.eventually_forall_ge_atTop [Preorder β] {l : Filter α} {p : β → Prop} {f : α → β} (hf : Tendsto f l atTop) (h_evtl : ∀ᶠ x in atTop, p x) : ∀ᶠ x in l, ∀ y, f x ≤ y → p y := by rw [← Filter.eventually_forall_ge_atTop] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap theorem Tendsto.eventually_forall_le_atBot [Preorder β] {l : Filter α} {p : β → Prop} {f : α → β} (hf : Tendsto f l atBot) (h_evtl : ∀ᶠ x in atBot, p x) : ∀ᶠ x in l, ∀ y, y ≤ f x → p y := by rw [← Filter.eventually_forall_le_atBot] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap /-! ### Sequences -/ /-- If `u` is a sequence which is unbounded above, then after any point, it reaches a value strictly greater than all previous values. -/ theorem high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) : ∀ N, ∃ n ≥ N, ∀ k < n, u k < u n := by intro N obtain ⟨k : ℕ, - : k ≤ N, hku : ∀ l ≤ N, u l ≤ u k⟩ : ∃ k ≤ N, ∀ l ≤ N, u l ≤ u k := exists_max_image _ u (finite_le_nat N) ⟨N, le_refl N⟩ have ex : ∃ n ≥ N, u k < u n := exists_lt_of_tendsto_atTop hu _ _ obtain ⟨n : ℕ, hnN : n ≥ N, hnk : u k < u n, hn_min : ∀ m, m < n → N ≤ m → u m ≤ u k⟩ : ∃ n ≥ N, u k < u n ∧ ∀ m, m < n → N ≤ m → u m ≤ u k := by rcases Nat.findX ex with ⟨n, ⟨hnN, hnk⟩, hn_min⟩ push_neg at hn_min exact ⟨n, hnN, hnk, hn_min⟩ use n, hnN rintro (l : ℕ) (hl : l < n) have hlk : u l ≤ u k := by rcases (le_total l N : l ≤ N ∨ N ≤ l) with H | H · exact hku l H · exact hn_min l hl H calc u l ≤ u k := hlk _ < u n := hnk -- see Note [nolint_ge] /-- If `u` is a sequence which is unbounded below, then after any point, it reaches a value strictly smaller than all previous values. -/ theorem low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β} (hu : Tendsto u atTop atBot) : ∀ N, ∃ n ≥ N, ∀ k < n, u n < u k := @high_scores βᵒᵈ _ _ _ hu /-- If `u` is a sequence which is unbounded above, then it `Frequently` reaches a value strictly greater than all previous values. -/ theorem frequently_high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) : ∃ᶠ n in atTop, ∀ k < n, u k < u n := by simpa [frequently_atTop] using high_scores hu /-- If `u` is a sequence which is unbounded below, then it `Frequently` reaches a value strictly smaller than all previous values. -/ theorem frequently_low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β} (hu : Tendsto u atTop atBot) : ∃ᶠ n in atTop, ∀ k < n, u n < u k := @frequently_high_scores βᵒᵈ _ _ _ hu theorem strictMono_subseq_of_tendsto_atTop [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) := let ⟨φ, h, h'⟩ := extraction_of_frequently_atTop (frequently_high_scores hu) ⟨φ, h, fun _ m hnm => h' m _ (h hnm)⟩ theorem strictMono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) := strictMono_subseq_of_tendsto_atTop (tendsto_atTop_mono hu tendsto_id) theorem Eventually.atTop_of_arithmetic {p : ℕ → Prop} {n : ℕ} (hn : n ≠ 0) (hp : ∀ k < n, ∀ᶠ a in atTop, p (n * a + k)) : ∀ᶠ a in atTop, p a := by simp only [eventually_atTop] at hp ⊢ choose! N hN using hp refine ⟨(Finset.range n).sup (n * N ·), fun b hb => ?_⟩ rw [← Nat.div_add_mod b n] have hlt := Nat.mod_lt b hn.bot_lt refine hN _ hlt _ ?_ rw [ge_iff_le, Nat.le_div_iff_mul_le hn.bot_lt, mul_comm] exact (Finset.le_sup (f := (n * N ·)) (Finset.mem_range.2 hlt)).trans hb /-- Given an antitone basis `s : ℕ → Set α` of a filter, extract an antitone subbasis `s ∘ φ`, `φ : ℕ → ℕ`, such that `m < n` implies `r (φ m) (φ n)`. This lemma can be used to extract an antitone basis with basis sets decreasing "sufficiently fast". -/ theorem HasAntitoneBasis.subbasis_with_rel {f : Filter α} {s : ℕ → Set α} (hs : f.HasAntitoneBasis s) {r : ℕ → ℕ → Prop} (hr : ∀ m, ∀ᶠ n in atTop, r m n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (∀ ⦃m n⦄, m < n → r (φ m) (φ n)) ∧ f.HasAntitoneBasis (s ∘ φ) := by rsuffices ⟨φ, hφ, hrφ⟩ : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ m n, m < n → r (φ m) (φ n) · exact ⟨φ, hφ, hrφ, hs.comp_strictMono hφ⟩ have : ∀ t : Set ℕ, t.Finite → ∀ᶠ n in atTop, ∀ m ∈ t, m < n ∧ r m n := fun t ht => (eventually_all_finite ht).2 fun m _ => (eventually_gt_atTop m).and (hr _) rcases seq_of_forall_finite_exists fun t ht => (this t ht).exists with ⟨φ, hφ⟩ simp only [forall_mem_image, forall_and, mem_Iio] at hφ exact ⟨φ, forall_swap.2 hφ.1, forall_swap.2 hφ.2⟩ end Filter open Filter Finset namespace Nat theorem eventually_pow_lt_factorial_sub (c d : ℕ) : ∀ᶠ n in atTop, c ^ n < (n - d)! := by rw [eventually_atTop] refine ⟨2 * (c ^ 2 + d + 1), ?_⟩ intro n hn obtain ⟨d', rfl⟩ := Nat.exists_eq_add_of_le hn obtain (rfl | c0) := c.eq_zero_or_pos · simp [Nat.two_mul, ← Nat.add_assoc, Nat.add_right_comm _ 1, Nat.factorial_pos] refine (Nat.le_mul_of_pos_right _ (Nat.pow_pos (n := d') c0)).trans_lt ?_ convert_to (c ^ 2) ^ (c ^ 2 + d' + d + 1) < (c ^ 2 + (c ^ 2 + d' + d + 1) + 1)! · rw [← pow_mul, ← pow_add] congr 1 cutsat · congr 1 cutsat refine (lt_of_lt_of_le ?_ Nat.factorial_mul_pow_le_factorial).trans_le <| (factorial_le (Nat.le_succ _)) rw [← one_mul (_ ^ _ : ℕ)] apply Nat.mul_lt_mul_of_le_of_lt · exact Nat.one_le_of_lt (Nat.factorial_pos _) · exact Nat.pow_lt_pow_left (Nat.lt_succ_self _) (Nat.succ_ne_zero _) · exact (Nat.factorial_pos _) theorem eventually_mul_pow_lt_factorial_sub (a c d : ℕ) : ∀ᶠ n in atTop, a * c ^ n < (n - d)! := by filter_upwards [Nat.eventually_pow_lt_factorial_sub (a * c) d, Filter.eventually_gt_atTop 0] with n hn hn0 rw [mul_pow] at hn exact (Nat.mul_le_mul_right _ (Nat.le_self_pow hn0.ne' _)).trans_lt hn end Nat
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Monoid.lean
import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Order.Filter.AtTopBot.Tendsto /-! # Convergence to ±infinity in ordered commutative monoids -/ variable {α M : Type*} namespace Filter section OrderedCommMonoid variable [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M] {l : Filter α} {f g : α → M} @[to_additive] theorem Tendsto.one_eventuallyLE_mul_atTop (hf : 1 ≤ᶠ[l] f) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := tendsto_atTop_mono' l (hf.mono fun _ ↦ le_mul_of_one_le_left') hg @[to_additive] theorem Tendsto.eventuallyLE_one_mul_atBot (hf : f ≤ᶠ[l] 1) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := hg.one_eventuallyLE_mul_atTop (M := Mᵒᵈ) hf @[to_additive] theorem Tendsto.one_le_mul_atTop (hf : ∀ x, 1 ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := hg.one_eventuallyLE_mul_atTop (.of_forall hf) @[to_additive] theorem Tendsto.le_one_mul_atBot (hf : ∀ x, f x ≤ 1) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := hg.eventuallyLE_one_mul_atBot (.of_forall hf) @[to_additive] theorem Tendsto.atTop_mul_one_eventuallyLE (hf : Tendsto f l atTop) (hg : 1 ≤ᶠ[l] g) : Tendsto (fun x => f x * g x) l atTop := tendsto_atTop_mono' l (hg.mono fun _ => le_mul_of_one_le_right') hf @[to_additive] theorem Tendsto.atBot_mul_eventuallyLE_one (hf : Tendsto f l atBot) (hg : g ≤ᶠ[l] 1) : Tendsto (fun x => f x * g x) l atBot := hf.atTop_mul_one_eventuallyLE (M := Mᵒᵈ) hg @[to_additive] theorem Tendsto.atTop_mul_one_le (hf : Tendsto f l atTop) (hg : ∀ x, 1 ≤ g x) : Tendsto (fun x => f x * g x) l atTop := hf.atTop_mul_one_eventuallyLE <| .of_forall hg @[to_additive] theorem Tendsto.atBot_mul_le_one (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ 1) : Tendsto (fun x => f x * g x) l atBot := hf.atBot_mul_eventuallyLE_one (.of_forall hg) /-- In an ordered multiplicative monoid, if `f` and `g` tend to `+∞`, then so does `f * g`. Earlier, this name was used for a similar lemma about semirings, which is now called `Filter.Tendsto.atTop_mul_atTop₀`. -/ @[to_additive] theorem Tendsto.atTop_mul_atTop (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := hf.atTop_mul_one_eventuallyLE <| hg.eventually_ge_atTop 1 /-- In an ordered multiplicative monoid, if `f` and `g` tend to `-∞`, then so does `f * g`. Earlier, this name was used for a similar lemma about rings (with conclusion `f * g → +∞`), which is now called `Filter.Tendsto.atBot_mul_atBot₀`. -/ @[to_additive] theorem Tendsto.atBot_mul_atBot (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := hf.atTop_mul_atTop (M := Mᵒᵈ) hg @[to_additive nsmul_atTop] theorem Tendsto.atTop_pow (hf : Tendsto f l atTop) {n : ℕ} (hn : 0 < n) : Tendsto (fun x => f x ^ n) l atTop := by refine tendsto_atTop_mono' _ ((hf.eventually_ge_atTop 1).mono fun x hx ↦ ?_) hf simpa only [pow_one] using pow_le_pow_right' hx hn @[to_additive nsmul_atBot] theorem Tendsto.atBot_pow (hf : Tendsto f l atBot) {n : ℕ} (hn : 0 < n) : Tendsto (fun x => f x ^ n) l atBot := Tendsto.atTop_pow (M := Mᵒᵈ) hf hn end OrderedCommMonoid section OrderedCancelCommMonoid variable [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M] {l : Filter α} {f g : α → M} /-- In an ordered cancellative multiplicative monoid, if `C * f x → +∞`, then `f x → +∞`. Earlier, this name was used for a similar lemma about ordered rings, which is now called `Filter.Tendsto.atTop_of_const_mul₀`. -/ @[to_additive] theorem Tendsto.atTop_of_const_mul (C : M) (hf : Tendsto (C * f ·) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b ↦ (tendsto_atTop.1 hf (C * b)).mono fun _ ↦ le_of_mul_le_mul_left' @[to_additive] theorem Tendsto.atBot_of_const_mul (C : M) (hf : Tendsto (C * f ·) l atBot) : Tendsto f l atBot := hf.atTop_of_const_mul (M := Mᵒᵈ) /-- In an ordered cancellative multiplicative monoid, if `f x * C → +∞`, then `f x → +∞`. Earlier, this name was used for a similar lemma about ordered rings, which is now called `Filter.Tendsto.atTop_of_mul_const₀`. -/ @[to_additive] theorem Tendsto.atTop_of_mul_const (C : M) (hf : Tendsto (f · * C) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b * C)).mono fun _ => le_of_mul_le_mul_right' @[to_additive] theorem Tendsto.atBot_of_mul_const (C : M) (hf : Tendsto (f · * C) l atBot) : Tendsto f l atBot := hf.atTop_of_mul_const (M := Mᵒᵈ) /-- If `f` is eventually bounded from above along `l` and `f * g` tends to `+∞`, then `g` tends to `+∞`. -/ @[to_additive /-- If `f` is eventually bounded from above along `l` and `f + g` tends to `+∞`, then `g` tends to `+∞`. -/] theorem Tendsto.atTop_of_isBoundedUnder_le_mul (hf : IsBoundedUnder (· ≤ ·) l f) (hfg : Tendsto (fun x => f x * g x) l atTop) : Tendsto g l atTop := by obtain ⟨C, hC⟩ := hf refine .atTop_of_const_mul C <| tendsto_atTop_mono' l ?_ hfg exact (eventually_map.mp hC).mono fun _ _ ↦ by dsimp; gcongr @[to_additive] theorem Tendsto.atBot_of_isBoundedUnder_ge_mul (hf : IsBoundedUnder (· ≥ ·) l f) (h : Tendsto (fun x => f x * g x) l atBot) : Tendsto g l atBot := h.atTop_of_isBoundedUnder_le_mul (M := Mᵒᵈ) hf @[to_additive] theorem Tendsto.atTop_of_le_const_mul (hf : ∃ C, ∀ x, f x ≤ C) (hfg : Tendsto (fun x ↦ f x * g x) l atTop) : Tendsto g l atTop := hfg.atTop_of_isBoundedUnder_le_mul <| hf.imp fun _C hC ↦ eventually_map.mpr <| .of_forall hC @[to_additive] theorem Tendsto.atBot_of_const_le_mul (hf : ∃ C, ∀ x, C ≤ f x) (hfg : Tendsto (fun x ↦ f x * g x) l atBot) : Tendsto g l atBot := Tendsto.atTop_of_le_const_mul (M := Mᵒᵈ) hf hfg @[to_additive] theorem Tendsto.atTop_of_mul_isBoundedUnder_le (hg : IsBoundedUnder (· ≤ ·) l g) (h : Tendsto (fun x => f x * g x) l atTop) : Tendsto f l atTop := by obtain ⟨C, hC⟩ := hg refine .atTop_of_mul_const C <| tendsto_atTop_mono' l ?_ h exact (eventually_map.mp hC).mono fun _ _ ↦ by dsimp; gcongr @[to_additive] theorem Tendsto.atBot_of_mul_isBoundedUnder_ge (hg : IsBoundedUnder (· ≥ ·) l g) (h : Tendsto (fun x => f x * g x) l atBot) : Tendsto f l atBot := h.atTop_of_mul_isBoundedUnder_le (M := Mᵒᵈ) hg @[to_additive] theorem Tendsto.atTop_of_mul_le_const (hg : ∃ C, ∀ x, g x ≤ C) (hfg : Tendsto (fun x ↦ f x * g x) l atTop) : Tendsto f l atTop := hfg.atTop_of_mul_isBoundedUnder_le <| hg.imp fun _C hC ↦ eventually_map.mpr <| .of_forall hC @[to_additive] theorem Tendsto.atBot_of_mul_const_le (hg : ∃ C, ∀ x, C ≤ g x) (hfg : Tendsto (fun x ↦ f x * g x) l atBot) : Tendsto f l atBot := Tendsto.atTop_of_mul_le_const (M := Mᵒᵈ) hg hfg end OrderedCancelCommMonoid section OrderedCancelAddCommMonoid variable [AddCommMonoid M] [PartialOrder M] [IsOrderedCancelAddMonoid M] {l : Filter α} {f g : α → M} end OrderedCancelAddCommMonoid end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Ring.lean
import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Order.Filter.AtTopBot.Group /-! # Convergence to ±infinity in ordered rings -/ variable {α β : Type*} namespace Filter section OrderedSemiring variable [Semiring α] [PartialOrder α] [IsOrderedRing α] {l : Filter β} {f g : β → α} theorem Tendsto.atTop_mul_atTop₀ (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := by refine tendsto_atTop_mono' _ ?_ hg filter_upwards [hg.eventually (eventually_ge_atTop 0), hf.eventually (eventually_ge_atTop 1)] with _ using le_mul_of_one_le_left theorem tendsto_mul_self_atTop : Tendsto (fun x : α => x * x) atTop atTop := tendsto_id.atTop_mul_atTop₀ tendsto_id /-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`. A version for positive real powers exists as `tendsto_rpow_atTop`. -/ theorem tendsto_pow_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (fun x : α => x ^ n) atTop atTop := tendsto_atTop_mono' _ ((eventually_ge_atTop 1).mono fun _x hx => le_self_pow₀ hx hn) tendsto_id end OrderedSemiring theorem zero_pow_eventuallyEq [MonoidWithZero α] : (fun n : ℕ => (0 : α) ^ n) =ᶠ[atTop] fun _ => 0 := eventually_atTop.2 ⟨1, fun _n hn ↦ zero_pow <| Nat.one_le_iff_ne_zero.1 hn⟩ section OrderedRing variable [Ring α] [PartialOrder α] [IsOrderedRing α] {l : Filter β} {f g : β → α} theorem Tendsto.atTop_mul_atBot₀ (hf : Tendsto f l atTop) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := by have := hf.atTop_mul_atTop₀ <| tendsto_neg_atBot_atTop.comp hg simpa only [Function.comp_def, neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_atTop_atBot.comp this theorem Tendsto.atBot_mul_atTop₀ (hf : Tendsto f l atBot) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atBot := by have : Tendsto (fun x => -f x * g x) l atTop := (tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop₀ hg simpa only [Function.comp_def, neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_atTop_atBot.comp this theorem Tendsto.atBot_mul_atBot₀ (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atTop := by have : Tendsto (fun x => -f x * -g x) l atTop := (tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop₀ (tendsto_neg_atBot_atTop.comp hg) simpa only [neg_mul_neg] using this end OrderedRing section LinearOrderedSemiring variable [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {l : Filter β} {f : β → α} theorem Tendsto.atTop_of_const_mul₀ {c : α} (hc : 0 < c) (hf : Tendsto (fun x => c * f x) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (c * b)).mono fun _x hx => le_of_mul_le_mul_left hx hc theorem Tendsto.atTop_of_mul_const₀ {c : α} (hc : 0 < c) (hf : Tendsto (fun x => f x * c) l atTop) : Tendsto f l atTop := tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b * c)).mono fun _x hx => le_of_mul_le_mul_right hx hc @[simp] theorem tendsto_pow_atTop_iff {n : ℕ} : Tendsto (fun x : α => x ^ n) atTop atTop ↔ n ≠ 0 := ⟨fun h hn => by simp only [hn, pow_zero, not_tendsto_const_atTop] at h, tendsto_pow_atTop⟩ end LinearOrderedSemiring theorem not_tendsto_pow_atTop_atBot [Ring α] [LinearOrder α] [IsStrictOrderedRing α] : ∀ {n : ℕ}, ¬Tendsto (fun x : α => x ^ n) atTop atBot | 0 => by simp [not_tendsto_const_atBot] | n + 1 => (tendsto_pow_atTop n.succ_ne_zero).not_tendsto disjoint_atTop_atBot end Filter open Filter variable {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] theorem exists_lt_mul_self (a : R) : ∃ x ≥ 0, a < x * x := ((eventually_ge_atTop 0).and (tendsto_mul_self_atTop.eventually (eventually_gt_atTop a))).exists theorem exists_le_mul_self (a : R) : ∃ x ≥ 0, a ≤ x * x := let ⟨x, hx0, hxa⟩ := exists_lt_mul_self a ⟨x, hx0, hxa.le⟩
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/CountablyGenerated.lean
import Mathlib.Order.Filter.AtTopBot.Finite import Mathlib.Order.Filter.AtTopBot.Prod import Mathlib.Order.Filter.CountablyGenerated /-! # Convergence to infinity and countably generated filters In this file we prove that - `Filter.atTop` and `Filter.atBot` filters on a countable type are countably generated; - `Filter.exists_seq_tendsto`: if `f` is a nontrivial countably generated filter, then there exists a sequence that converges. to `f`; - `Filter.tendsto_iff_seq_tendsto`: convergence along a countably generated filter is equivalent to convergence along all sequences that converge to this filter. -/ open Set namespace Filter variable {α β : Type*} instance (priority := 200) atTop.isCountablyGenerated [Preorder α] [Countable α] : (atTop : Filter <| α).IsCountablyGenerated := isCountablyGenerated_seq _ instance (priority := 200) atBot.isCountablyGenerated [Preorder α] [Countable α] : (atBot : Filter <| α).IsCountablyGenerated := isCountablyGenerated_seq _ instance instIsCountablyGeneratedAtTopProd [Preorder α] [IsCountablyGenerated (atTop : Filter α)] [Preorder β] [IsCountablyGenerated (atTop : Filter β)] : IsCountablyGenerated (atTop : Filter (α × β)) := by rw [← prod_atTop_atTop_eq] infer_instance instance instIsCountablyGeneratedAtBotProd [Preorder α] [IsCountablyGenerated (atBot : Filter α)] [Preorder β] [IsCountablyGenerated (atBot : Filter β)] : IsCountablyGenerated (atBot : Filter (α × β)) := by rw [← prod_atBot_atBot_eq] infer_instance instance _root_.OrderDual.instIsCountablyGeneratedAtTop [Preorder α] [IsCountablyGenerated (atBot : Filter α)] : IsCountablyGenerated (atTop : Filter αᵒᵈ) := ‹_› instance _root_.OrderDual.instIsCountablyGeneratedAtBot [Preorder α] [IsCountablyGenerated (atTop : Filter α)] : IsCountablyGenerated (atBot : Filter αᵒᵈ) := ‹_› lemma atTop_countable_basis [Preorder α] [IsDirected α (· ≤ ·)] [Nonempty α] [Countable α] : HasCountableBasis (atTop : Filter α) (fun _ => True) Ici := { atTop_basis with countable := to_countable _ } lemma atBot_countable_basis [Preorder α] [IsDirected α (· ≥ ·)] [Nonempty α] [Countable α] : HasCountableBasis (atBot : Filter α) (fun _ => True) Iic := { atBot_basis with countable := to_countable _ } /-- If `f` is a nontrivial countably generated filter, then there exists a sequence that converges to `f`. -/ theorem exists_seq_tendsto (f : Filter α) [IsCountablyGenerated f] [NeBot f] : ∃ x : ℕ → α, Tendsto x atTop f := by obtain ⟨B, h⟩ := f.exists_antitone_basis choose x hx using fun n => Filter.nonempty_of_mem (h.mem n) exact ⟨x, h.tendsto hx⟩ theorem exists_seq_monotone_tendsto_atTop_atTop (α : Type*) [Preorder α] [Nonempty α] [IsDirected α (· ≤ ·)] [(atTop : Filter α).IsCountablyGenerated] : ∃ xs : ℕ → α, Monotone xs ∧ Tendsto xs atTop atTop := by obtain ⟨ys, h⟩ := exists_seq_tendsto (atTop : Filter α) choose c hleft hright using exists_ge_ge (α := α) set xs : ℕ → α := fun n => (List.range n).foldl (fun x n ↦ c x (ys n)) (ys 0) have hsucc (n : ℕ) : xs (n + 1) = c (xs n) (ys n) := by simp [xs, List.range_succ] refine ⟨xs, ?_, ?_⟩ · refine monotone_nat_of_le_succ fun n ↦ ?_ rw [hsucc] apply hleft · refine (tendsto_add_atTop_iff_nat 1).1 <| tendsto_atTop_mono (fun n ↦ ?_) h rw [hsucc] apply hright theorem exists_seq_antitone_tendsto_atTop_atBot (α : Type*) [Preorder α] [Nonempty α] [IsDirected α (· ≥ ·)] [(atBot : Filter α).IsCountablyGenerated] : ∃ xs : ℕ → α, Antitone xs ∧ Tendsto xs atTop atBot := exists_seq_monotone_tendsto_atTop_atTop αᵒᵈ /-- An abstract version of continuity of sequentially continuous functions on metric spaces: if a filter `k` is countably generated then `Tendsto f k l` iff for every sequence `u` converging to `k`, `f ∘ u` tends to `l`. -/ theorem tendsto_iff_seq_tendsto {f : α → β} {k : Filter α} {l : Filter β} [k.IsCountablyGenerated] : Tendsto f k l ↔ ∀ x : ℕ → α, Tendsto x atTop k → Tendsto (f ∘ x) atTop l := by refine ⟨fun h x hx => h.comp hx, fun H s hs => ?_⟩ contrapose! H have : NeBot (k ⊓ 𝓟 (f ⁻¹' sᶜ)) := by simpa [neBot_iff, inf_principal_eq_bot] rcases (k ⊓ 𝓟 (f ⁻¹' sᶜ)).exists_seq_tendsto with ⟨x, hx⟩ rw [tendsto_inf, tendsto_principal] at hx refine ⟨x, hx.1, fun h => ?_⟩ rcases (hx.2.and (h hs)).exists with ⟨N, hnotMem, hmem⟩ exact hnotMem hmem theorem tendsto_of_seq_tendsto {f : α → β} {k : Filter α} {l : Filter β} [k.IsCountablyGenerated] : (∀ x : ℕ → α, Tendsto x atTop k → Tendsto (f ∘ x) atTop l) → Tendsto f k l := tendsto_iff_seq_tendsto.2 theorem eventually_iff_seq_eventually {ι : Type*} {l : Filter ι} {p : ι → Prop} [l.IsCountablyGenerated] : (∀ᶠ n in l, p n) ↔ ∀ x : ℕ → ι, Tendsto x atTop l → ∀ᶠ n : ℕ in atTop, p (x n) := by simpa using tendsto_iff_seq_tendsto (f := id) (l := 𝓟 {x | p x}) theorem frequently_iff_seq_frequently {ι : Type*} {l : Filter ι} {p : ι → Prop} [l.IsCountablyGenerated] : (∃ᶠ n in l, p n) ↔ ∃ x : ℕ → ι, Tendsto x atTop l ∧ ∃ᶠ n : ℕ in atTop, p (x n) := by simp only [Filter.Frequently, eventually_iff_seq_eventually (l := l)] push_neg; rfl theorem exists_seq_forall_of_frequently {ι : Type*} {l : Filter ι} {p : ι → Prop} [l.IsCountablyGenerated] (h : ∃ᶠ n in l, p n) : ∃ ns : ℕ → ι, Tendsto ns atTop l ∧ ∀ n, p (ns n) := by rw [frequently_iff_seq_frequently] at h obtain ⟨x, hx_tendsto, hx_freq⟩ := h obtain ⟨n_to_n, h_tendsto, h_freq⟩ := subseq_forall_of_frequently hx_tendsto hx_freq exact ⟨x ∘ n_to_n, h_tendsto, h_freq⟩ lemma frequently_iff_seq_forall {ι : Type*} {l : Filter ι} {p : ι → Prop} [l.IsCountablyGenerated] : (∃ᶠ n in l, p n) ↔ ∃ ns : ℕ → ι, Tendsto ns atTop l ∧ ∀ n, p (ns n) := ⟨exists_seq_forall_of_frequently, fun ⟨_ns, hnsl, hpns⟩ ↦ hnsl.frequently <| Frequently.of_forall hpns⟩ /-- A sequence converges if every subsequence has a convergent subsequence. -/ theorem tendsto_of_subseq_tendsto {ι : Type*} {x : ι → α} {f : Filter α} {l : Filter ι} [l.IsCountablyGenerated] (hxy : ∀ ns : ℕ → ι, Tendsto ns atTop l → ∃ ms : ℕ → ℕ, Tendsto (fun n => x (ns <| ms n)) atTop f) : Tendsto x l f := by contrapose! hxy obtain ⟨s, hs, hfreq⟩ : ∃ s ∈ f, ∃ᶠ n in l, x n ∉ s := by rwa [not_tendsto_iff_exists_frequently_notMem] at hxy obtain ⟨y, hy_tendsto, hy_freq⟩ := exists_seq_forall_of_frequently hfreq refine ⟨y, hy_tendsto, fun ms hms_tendsto ↦ ?_⟩ rcases (hms_tendsto.eventually_mem hs).exists with ⟨n, hn⟩ exact absurd hn <| hy_freq _ theorem subseq_tendsto_of_neBot {f : Filter α} [IsCountablyGenerated f] {u : ℕ → α} (hx : NeBot (f ⊓ map u atTop)) : ∃ θ : ℕ → ℕ, StrictMono θ ∧ Tendsto (u ∘ θ) atTop f := by rw [← Filter.push_pull', map_neBot_iff] at hx rcases exists_seq_tendsto (comap u f ⊓ atTop) with ⟨φ, hφ⟩ rw [tendsto_inf, tendsto_comap_iff] at hφ obtain ⟨ψ, hψ, hψφ⟩ : ∃ ψ : ℕ → ℕ, StrictMono ψ ∧ StrictMono (φ ∘ ψ) := strictMono_subseq_of_tendsto_atTop hφ.2 exact ⟨φ ∘ ψ, hψφ, hφ.1.comp hψ.tendsto_atTop⟩ end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Tendsto.lean
import Mathlib.Order.Filter.AtTopBot.Disjoint import Mathlib.Order.Filter.Tendsto /-! # Limits of `Filter.atTop` and `Filter.atBot` In this file we prove many lemmas on the combination of `Filter.atTop` and `Filter.atBot` and `Tendsto`. -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace Filter theorem not_tendsto_const_atTop [Preorder α] [NoTopOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atTop := tendsto_const_pure.not_tendsto (disjoint_pure_atTop x) theorem not_tendsto_const_atBot [Preorder α] [NoBotOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atBot := tendsto_const_pure.not_tendsto (disjoint_pure_atBot x) protected theorem Tendsto.eventually_gt_atTop [Preorder β] [NoTopOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c < f x := hf.eventually (eventually_gt_atTop c) protected theorem Tendsto.eventually_ge_atTop [Preorder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c ≤ f x := hf.eventually (eventually_ge_atTop c) protected theorem Tendsto.eventually_ne_atTop [Preorder β] [NoTopOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, f x ≠ c := hf.eventually (eventually_ne_atTop c) protected theorem Tendsto.eventually_ne_atTop' [Preorder β] [NoTopOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : α) : ∀ᶠ x in l, x ≠ c := (hf.eventually_ne_atTop (f c)).mono fun _ => ne_of_apply_ne f protected theorem Tendsto.eventually_lt_atBot [Preorder β] [NoBotOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x < c := hf.eventually (eventually_lt_atBot c) protected theorem Tendsto.eventually_le_atBot [Preorder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≤ c := hf.eventually (eventually_le_atBot c) protected theorem Tendsto.eventually_ne_atBot [Preorder β] [NoBotOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≠ c := hf.eventually (eventually_ne_atBot c) theorem OrderTop.atTop_eq (α) [PartialOrder α] [OrderTop α] : (atTop : Filter α) = pure ⊤ := by rw [isTop_top.atTop_eq, Ici_top, principal_singleton] theorem OrderBot.atBot_eq (α) [PartialOrder α] [OrderBot α] : (atBot : Filter α) = pure ⊥ := @OrderTop.atTop_eq αᵒᵈ _ _ theorem tendsto_atTop_pure [PartialOrder α] [OrderTop α] (f : α → β) : Tendsto f atTop (pure <| f ⊤) := (OrderTop.atTop_eq α).symm ▸ tendsto_pure_pure _ _ theorem tendsto_atBot_pure [PartialOrder α] [OrderBot α] (f : α → β) : Tendsto f atBot (pure <| f ⊥) := @tendsto_atTop_pure αᵒᵈ _ _ _ _ theorem tendsto_atTop [Preorder β] {m : α → β} {f : Filter α} : Tendsto m f atTop ↔ ∀ b, ∀ᶠ a in f, b ≤ m a := by simp only [atTop, tendsto_iInf, tendsto_principal, mem_Ici] theorem tendsto_atBot [Preorder β] {m : α → β} {f : Filter α} : Tendsto m f atBot ↔ ∀ b, ∀ᶠ a in f, m a ≤ b := @tendsto_atTop α βᵒᵈ _ m f theorem tendsto_atTop_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) (h₁ : Tendsto f₁ l atTop) : Tendsto f₂ l atTop := tendsto_atTop.2 fun b => by filter_upwards [tendsto_atTop.1 h₁ b, h] with x using le_trans theorem tendsto_atBot_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) : Tendsto f₂ l atBot → Tendsto f₁ l atBot := @tendsto_atTop_mono' _ βᵒᵈ _ _ _ _ h theorem tendsto_atTop_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) : Tendsto f l atTop → Tendsto g l atTop := tendsto_atTop_mono' l <| Eventually.of_forall h theorem tendsto_atBot_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) : Tendsto g l atBot → Tendsto f l atBot := @tendsto_atTop_mono _ βᵒᵈ _ _ _ _ h end Filter namespace Filter /-! ### Sequences -/ theorem _root_.StrictMono.tendsto_atTop {φ : ℕ → ℕ} (h : StrictMono φ) : Tendsto φ atTop atTop := tendsto_atTop_mono h.id_le tendsto_id /-- If `f` is a monotone function and `g` tends to `atTop` along a nontrivial filter. then the upper bounds of the range of `f ∘ g` are the same as the upper bounds of the range of `f`. This lemma together with `exists_seq_monotone_tendsto_atTop_atTop` below is useful to reduce a statement about a monotone family indexed by a type with countably generated `atTop` (e.g., `ℝ`) to the case of a family indexed by natural numbers. -/ theorem _root_.Monotone.upperBounds_range_comp_tendsto_atTop [Preorder β] [Preorder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) {g : α → β} (hg : Tendsto g l atTop) : upperBounds (range (f ∘ g)) = upperBounds (range f) := by refine Subset.antisymm ?_ (upperBounds_mono_set <| range_comp_subset_range _ _) rintro c hc _ ⟨b, rfl⟩ obtain ⟨a, ha⟩ : ∃ a, b ≤ g a := (hg.eventually_ge_atTop b).exists exact (hf ha).trans <| hc <| mem_range_self _ /-- If `f` is a monotone function and `g` tends to `atBot` along a nontrivial filter. then the lower bounds of the range of `f ∘ g` are the same as the lower bounds of the range of `f`. -/ theorem _root_.Monotone.lowerBounds_range_comp_tendsto_atBot [Preorder β] [Preorder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) {g : α → β} (hg : Tendsto g l atBot) : lowerBounds (range (f ∘ g)) = lowerBounds (range f) := hf.dual.upperBounds_range_comp_tendsto_atTop hg /-- If `f` is an antitone function and `g` tends to `atTop` along a nontrivial filter. then the upper bounds of the range of `f ∘ g` are the same as the upper bounds of the range of `f`. -/ theorem _root_.Antitone.lowerBounds_range_comp_tendsto_atTop [Preorder β] [Preorder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) {g : α → β} (hg : Tendsto g l atTop) : lowerBounds (range (f ∘ g)) = lowerBounds (range f) := hf.dual_left.lowerBounds_range_comp_tendsto_atBot hg /-- If `f` is an antitone function and `g` tends to `atBot` along a nontrivial filter. then the upper bounds of the range of `f ∘ g` are the same as the upper bounds of the range of `f`. -/ theorem _root_.Antitone.upperBounds_range_comp_tendsto_atBot [Preorder β] [Preorder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) {g : α → β} (hg : Tendsto g l atBot) : upperBounds (range (f ∘ g)) = upperBounds (range f) := hf.dual.lowerBounds_range_comp_tendsto_atTop hg theorem tendsto_atTop_atTop_of_monotone [Preorder α] [Preorder β] {f : α → β} (hf : Monotone f) (h : ∀ b, ∃ a, b ≤ f a) : Tendsto f atTop atTop := tendsto_iInf.2 fun b => tendsto_principal.2 <| let ⟨a, ha⟩ := h b mem_of_superset (mem_atTop a) fun _a' ha' => le_trans ha (hf ha') theorem tendsto_atTop_atBot_of_antitone [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f) (h : ∀ b, ∃ a, f a ≤ b) : Tendsto f atTop atBot := @tendsto_atTop_atTop_of_monotone _ βᵒᵈ _ _ _ hf h theorem tendsto_atBot_atBot_of_monotone [Preorder α] [Preorder β] {f : α → β} (hf : Monotone f) (h : ∀ b, ∃ a, f a ≤ b) : Tendsto f atBot atBot := tendsto_iInf.2 fun b => tendsto_principal.2 <| let ⟨a, ha⟩ := h b; mem_of_superset (mem_atBot a) fun _a' ha' => le_trans (hf ha') ha theorem tendsto_atBot_atTop_of_antitone [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f) (h : ∀ b, ∃ a, b ≤ f a) : Tendsto f atBot atTop := @tendsto_atBot_atBot_of_monotone _ βᵒᵈ _ _ _ hf h alias _root_.Monotone.tendsto_atTop_atTop := tendsto_atTop_atTop_of_monotone alias _root_.Monotone.tendsto_atBot_atBot := tendsto_atBot_atBot_of_monotone theorem comap_embedding_atTop [Preorder β] [Preorder γ] {e : β → γ} (hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, c ≤ e b) : comap e atTop = atTop := le_antisymm (le_iInf fun b => le_principal_iff.2 <| mem_comap.2 ⟨Ici (e b), mem_atTop _, fun _ => (hm _ _).1⟩) (tendsto_atTop_atTop_of_monotone (fun _ _ => (hm _ _).2) hu).le_comap theorem comap_embedding_atBot [Preorder β] [Preorder γ] {e : β → γ} (hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, e b ≤ c) : comap e atBot = atBot := @comap_embedding_atTop βᵒᵈ γᵒᵈ _ _ e (Function.swap hm) hu theorem tendsto_atTop_embedding [Preorder β] [Preorder γ] {f : α → β} {e : β → γ} {l : Filter α} (hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, c ≤ e b) : Tendsto (e ∘ f) l atTop ↔ Tendsto f l atTop := by rw [← comap_embedding_atTop hm hu, tendsto_comap_iff] /-- A function `f` goes to `-∞` independent of an order-preserving embedding `e`. -/ theorem tendsto_atBot_embedding [Preorder β] [Preorder γ] {f : α → β} {e : β → γ} {l : Filter α} (hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, e b ≤ c) : Tendsto (e ∘ f) l atBot ↔ Tendsto f l atBot := @tendsto_atTop_embedding α βᵒᵈ γᵒᵈ _ _ f e l (Function.swap hm) hu /-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded above, then `Tendsto u atTop atTop`. -/ theorem tendsto_atTop_atTop_of_monotone' [Preorder ι] [LinearOrder α] {u : ι → α} (h : Monotone u) (H : ¬BddAbove (range u)) : Tendsto u atTop atTop := by apply h.tendsto_atTop_atTop intro b rcases not_bddAbove_iff.1 H b with ⟨_, ⟨N, rfl⟩, hN⟩ exact ⟨N, le_of_lt hN⟩ /-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded below, then `Tendsto u atBot atBot`. -/ theorem tendsto_atBot_atBot_of_monotone' [Preorder ι] [LinearOrder α] {u : ι → α} (h : Monotone u) (H : ¬BddBelow (range u)) : Tendsto u atBot atBot := @tendsto_atTop_atTop_of_monotone' ιᵒᵈ αᵒᵈ _ _ _ h.dual H /-- If a monotone function `u : ι → α` tends to `atTop` along *some* non-trivial filter `l`, then it tends to `atTop` along `atTop`. -/ theorem tendsto_atTop_of_monotone_of_filter [Preorder ι] [Preorder α] {l : Filter ι} {u : ι → α} (h : Monotone u) [NeBot l] (hu : Tendsto u l atTop) : Tendsto u atTop atTop := h.tendsto_atTop_atTop fun b => (hu.eventually (mem_atTop b)).exists /-- If a monotone function `u : ι → α` tends to `atBot` along *some* non-trivial filter `l`, then it tends to `atBot` along `atBot`. -/ theorem tendsto_atBot_of_monotone_of_filter [Preorder ι] [Preorder α] {l : Filter ι} {u : ι → α} (h : Monotone u) [NeBot l] (hu : Tendsto u l atBot) : Tendsto u atBot atBot := @tendsto_atTop_of_monotone_of_filter ιᵒᵈ αᵒᵈ _ _ _ _ h.dual _ hu theorem tendsto_atTop_of_monotone_of_subseq [Preorder ι] [Preorder α] {u : ι → α} {φ : ι' → ι} (h : Monotone u) {l : Filter ι'} [NeBot l] (H : Tendsto (u ∘ φ) l atTop) : Tendsto u atTop atTop := tendsto_atTop_of_monotone_of_filter h (tendsto_map' H) theorem tendsto_atBot_of_monotone_of_subseq [Preorder ι] [Preorder α] {u : ι → α} {φ : ι' → ι} (h : Monotone u) {l : Filter ι'} [NeBot l] (H : Tendsto (u ∘ φ) l atBot) : Tendsto u atBot atBot := tendsto_atBot_of_monotone_of_filter h (tendsto_map' H) end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Group.lean
import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.AtTopBot.Map import Mathlib.Order.Filter.AtTopBot.Monoid /-! # Convergence to ±infinity in ordered commutative groups -/ variable {α G : Type*} open Set namespace Filter section OrderedCommGroup variable [CommGroup G] [PartialOrder G] [IsOrderedMonoid G] (l : Filter α) {f g : α → G} @[to_additive] theorem tendsto_atTop_mul_left_of_le' (C : G) (hf : ∀ᶠ x in l, C ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := .atTop_of_isBoundedUnder_le_mul (f := f⁻¹) ⟨C⁻¹, by simpa⟩ (by simpa) @[to_additive] theorem tendsto_atBot_mul_left_of_ge' (C : G) (hf : ∀ᶠ x in l, f x ≤ C) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_left_of_le' (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_left_of_le (C : G) (hf : ∀ x, C ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := tendsto_atTop_mul_left_of_le' l C (univ_mem' hf) hg @[to_additive] theorem tendsto_atBot_mul_left_of_ge (C : G) (hf : ∀ x, f x ≤ C) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_left_of_le (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_right_of_le' (C : G) (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, C ≤ g x) : Tendsto (fun x => f x * g x) l atTop := .atTop_of_mul_isBoundedUnder_le (g := g⁻¹) ⟨C⁻¹, by simpa⟩ (by simpa) @[to_additive] theorem tendsto_atBot_mul_right_of_ge' (C : G) (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ C) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_right_of_le' (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_right_of_le (C : G) (hf : Tendsto f l atTop) (hg : ∀ x, C ≤ g x) : Tendsto (fun x => f x * g x) l atTop := tendsto_atTop_mul_right_of_le' l C hf (univ_mem' hg) @[to_additive] theorem tendsto_atBot_mul_right_of_ge (C : G) (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ C) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_right_of_le (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_const_left (C : G) (hf : Tendsto f l atTop) : Tendsto (fun x => C * f x) l atTop := tendsto_atTop_mul_left_of_le' l C (univ_mem' fun _ => le_refl C) hf @[to_additive] theorem tendsto_atBot_mul_const_left (C : G) (hf : Tendsto f l atBot) : Tendsto (fun x => C * f x) l atBot := tendsto_atTop_mul_const_left (G := Gᵒᵈ) _ C hf @[to_additive] theorem tendsto_atTop_mul_const_right (C : G) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * C) l atTop := tendsto_atTop_mul_right_of_le' l C hf (univ_mem' fun _ => le_refl C) @[to_additive] theorem tendsto_atBot_mul_const_right (C : G) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * C) l atBot := tendsto_atTop_mul_const_right (G := Gᵒᵈ) _ C hf @[to_additive] theorem map_inv_atBot : map (Inv.inv : G → G) atBot = atTop := (OrderIso.inv G).map_atBot @[to_additive] theorem map_inv_atTop : map (Inv.inv : G → G) atTop = atBot := (OrderIso.inv G).map_atTop @[to_additive] theorem comap_inv_atBot : comap (Inv.inv : G → G) atBot = atTop := (OrderIso.inv G).comap_atTop @[to_additive] theorem comap_inv_atTop : comap (Inv.inv : G → G) atTop = atBot := (OrderIso.inv G).comap_atBot @[to_additive] theorem tendsto_inv_atTop_atBot : Tendsto (Inv.inv : G → G) atTop atBot := (OrderIso.inv G).tendsto_atTop @[to_additive] theorem tendsto_inv_atBot_atTop : Tendsto (Inv.inv : G → G) atBot atTop := tendsto_inv_atTop_atBot (G := Gᵒᵈ) variable {l} @[to_additive (attr := simp)] theorem tendsto_inv_atTop_iff : Tendsto (fun x => (f x)⁻¹) l atTop ↔ Tendsto f l atBot := (OrderIso.inv G).tendsto_atBot_iff @[to_additive (attr := simp)] theorem tendsto_inv_atBot_iff : Tendsto (fun x => (f x)⁻¹) l atBot ↔ Tendsto f l atTop := (OrderIso.inv G).tendsto_atTop_iff end OrderedCommGroup section LinearOrderedCommGroup variable [CommGroup G] [LinearOrder G] /-- $\lim_{x\to+\infty}|x|_m=+\infty$ -/ @[to_additive /-- $\lim_{x\to+\infty}|x|=+\infty$ -/] theorem tendsto_mabs_atTop_atTop : Tendsto (mabs : G → G) atTop atTop := tendsto_atTop_mono le_mabs_self tendsto_id /-- $\lim_{x\to\infty^{-1}|x|_m=+\infty$ -/ @[to_additive /-- $\lim_{x\to-\infty}|x|=+\infty$ -/] theorem tendsto_mabs_atBot_atTop [IsOrderedMonoid G] : Tendsto (mabs : G → G) atBot atTop := tendsto_atTop_mono inv_le_mabs tendsto_inv_atBot_atTop @[to_additive (attr := simp)] theorem comap_mabs_atTop [IsOrderedMonoid G] : comap (mabs : G → G) atTop = atBot ⊔ atTop := by refine le_antisymm (((atTop_basis.comap _).le_basis_iff (atBot_basis.sup atTop_basis)).2 ?_) (sup_le tendsto_mabs_atBot_atTop.le_comap tendsto_mabs_atTop_atTop.le_comap) rintro ⟨a, b⟩ - refine ⟨max (a⁻¹) b, trivial, fun x hx => ?_⟩ rw [mem_preimage, mem_Ici, le_mabs', max_le_iff, ← min_inv_inv', le_min_iff, inv_inv] at hx exact hx.imp And.left And.right end LinearOrderedCommGroup end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Interval.lean
import Mathlib.Order.Filter.AtTopBot.Archimedean import Mathlib.Order.Filter.Prod import Mathlib.Order.Interval.Finset.Defs /-! # Limits of intervals along filters This file contains some lemmas about how filters `Ixx` behave as the endpoints tend to `±∞`. -/ namespace Finset open Filter section Asymmetric variable {α : Type*} [Preorder α] [LocallyFiniteOrder α] lemma tendsto_Icc_atBot_prod_atTop : Tendsto (fun p : α × α ↦ Icc p.1 p.2) (atBot ×ˢ atTop) atTop := by simpa [tendsto_atTop, ← coe_subset, Set.subset_def, -eventually_and] using fun b i _ ↦ (eventually_le_atBot i).prod_mk (eventually_ge_atTop i) lemma tendsto_Ioc_atBot_prod_atTop [NoBotOrder α] : Tendsto (fun p : α × α ↦ Ioc p.1 p.2) (atBot ×ˢ atTop) atTop := by simpa [tendsto_atTop, ← coe_subset, Set.subset_def, -eventually_and] using fun b i _ ↦ (eventually_lt_atBot i).prod_mk (eventually_ge_atTop i) lemma tendsto_Ico_atBot_prod_atTop [NoTopOrder α] : Tendsto (fun p : α × α ↦ Finset.Ico p.1 p.2) (atBot ×ˢ atTop) atTop := by simpa [tendsto_atTop, ← coe_subset, Set.subset_def, -eventually_and] using fun b i _ ↦ (eventually_le_atBot i).prod_mk (eventually_gt_atTop i) lemma tendsto_Ioo_atBot_prod_atTop [NoBotOrder α] [NoTopOrder α] : Tendsto (fun p : α × α ↦ Finset.Ioo p.1 p.2) (atBot ×ˢ atTop) atTop := by simpa [tendsto_atTop, ← coe_subset, Set.subset_def, -eventually_and] using fun b i _ ↦ (eventually_lt_atBot i).prod_mk (eventually_gt_atTop i) end Asymmetric section Symmetric variable {α : Type*} [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] [LocallyFiniteOrder α] lemma tendsto_Icc_neg_atTop_atTop : Tendsto (fun a : α ↦ Icc (-a) a) atTop atTop := tendsto_Icc_atBot_prod_atTop.comp (tendsto_neg_atTop_atBot.prodMk tendsto_id) lemma tendsto_Ioc_neg_atTop_atTop [NoBotOrder α] : Tendsto (fun a : α ↦ Ioc (-a) a) atTop atTop := tendsto_Ioc_atBot_prod_atTop.comp (tendsto_neg_atTop_atBot.prodMk tendsto_id) lemma tendsto_Ico_neg_atTop_atTop [NoTopOrder α] : Tendsto (fun a : α ↦ Ico (-a) a) atTop atTop := tendsto_Ico_atBot_prod_atTop.comp (tendsto_neg_atTop_atBot.prodMk tendsto_id) lemma tendsto_Ioo_neg_atTop_atTop [NoBotOrder α] [NoTopOrder α] : Tendsto (fun a : α ↦ Ioo (-a) a) atTop atTop := tendsto_Ioo_atBot_prod_atTop.comp (tendsto_neg_atTop_atBot.prodMk tendsto_id) end Symmetric section NatCast variable {R : Type*} [Ring R] [PartialOrder R] [IsOrderedRing R] [LocallyFiniteOrder R] [Archimedean R] lemma tendsto_Icc_neg : Tendsto (fun n : ℕ ↦ Icc (-n : R) n) atTop atTop := tendsto_Icc_neg_atTop_atTop.comp tendsto_natCast_atTop_atTop variable [Nontrivial R] lemma tendsto_Ioc_neg : Tendsto (fun n : ℕ ↦ Ioc (-n : R) n) atTop atTop := tendsto_Ioc_neg_atTop_atTop.comp tendsto_natCast_atTop_atTop lemma tendsto_Ico_neg : Tendsto (fun n : ℕ ↦ Ico (-n : R) n) atTop atTop := tendsto_Ico_neg_atTop_atTop.comp tendsto_natCast_atTop_atTop lemma tendsto_Ioo_neg : Tendsto (fun n : ℕ ↦ Ioo (-n : R) n) atTop atTop := tendsto_Ioo_neg_atTop_atTop.comp tendsto_natCast_atTop_atTop end NatCast end Finset
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Prod.lean
import Mathlib.Data.Finset.Prod import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.Prod /-! # `Filter.atTop` and `Filter.atBot` filters on products -/ variable {ι ι' α β γ : Type*} open Set namespace Filter theorem prod_atTop_atTop_eq [Preorder α] [Preorder β] : (atTop : Filter α) ×ˢ (atTop : Filter β) = (atTop : Filter (α × β)) := by cases isEmpty_or_nonempty α · subsingleton cases isEmpty_or_nonempty β · subsingleton simpa [atTop, prod_iInf_left, prod_iInf_right, iInf_prod] using iInf_comm lemma tendsto_finset_prod_atTop : Tendsto (fun (p : Finset ι × Finset ι') ↦ p.1 ×ˢ p.2) atTop atTop := by classical apply Monotone.tendsto_atTop_atTop · intro p q hpq simpa using Finset.product_subset_product hpq.1 hpq.2 · intro b use (Finset.image Prod.fst b, Finset.image Prod.snd b) exact Finset.subset_product theorem prod_atBot_atBot_eq [Preorder α] [Preorder β] : (atBot : Filter α) ×ˢ (atBot : Filter β) = (atBot : Filter (α × β)) := @prod_atTop_atTop_eq αᵒᵈ βᵒᵈ _ _ theorem prod_map_atTop_eq {α₁ α₂ β₁ β₂ : Type*} [Preorder β₁] [Preorder β₂] (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : map u₁ atTop ×ˢ map u₂ atTop = map (Prod.map u₁ u₂) atTop := by rw [prod_map_map_eq, prod_atTop_atTop_eq, Prod.map_def] theorem prod_map_atBot_eq {α₁ α₂ β₁ β₂ : Type*} [Preorder β₁] [Preorder β₂] (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : map u₁ atBot ×ˢ map u₂ atBot = map (Prod.map u₁ u₂) atBot := @prod_map_atTop_eq _ _ β₁ᵒᵈ β₂ᵒᵈ _ _ _ _ theorem tendsto_atBot_diagonal [Preorder α] : Tendsto (fun a : α => (a, a)) atBot atBot := by rw [← prod_atBot_atBot_eq] exact tendsto_id.prodMk tendsto_id theorem tendsto_atTop_diagonal [Preorder α] : Tendsto (fun a : α => (a, a)) atTop atTop := by rw [← prod_atTop_atTop_eq] exact tendsto_id.prodMk tendsto_id theorem Tendsto.prod_map_prod_atBot [Preorder γ] {F : Filter α} {G : Filter β} {f : α → γ} {g : β → γ} (hf : Tendsto f F atBot) (hg : Tendsto g G atBot) : Tendsto (Prod.map f g) (F ×ˢ G) atBot := by rw [← prod_atBot_atBot_eq] exact hf.prodMap hg theorem Tendsto.prod_map_prod_atTop [Preorder γ] {F : Filter α} {G : Filter β} {f : α → γ} {g : β → γ} (hf : Tendsto f F atTop) (hg : Tendsto g G atTop) : Tendsto (Prod.map f g) (F ×ˢ G) atTop := by rw [← prod_atTop_atTop_eq] exact hf.prodMap hg theorem Tendsto.prod_atBot [Preorder α] [Preorder γ] {f g : α → γ} (hf : Tendsto f atBot atBot) (hg : Tendsto g atBot atBot) : Tendsto (Prod.map f g) atBot atBot := by rw [← prod_atBot_atBot_eq] exact hf.prod_map_prod_atBot hg theorem Tendsto.prod_atTop [Preorder α] [Preorder γ] {f g : α → γ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : Tendsto (Prod.map f g) atTop atTop := by rw [← prod_atTop_atTop_eq] exact hf.prod_map_prod_atTop hg theorem eventually_atBot_prod_self [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {p : α × α → Prop} : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ k l, k ≤ a → l ≤ a → p (k, l) := by simp [← prod_atBot_atBot_eq, (@atBot_basis α _ _).prod_self.eventually_iff] theorem eventually_atTop_prod_self [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] {p : α × α → Prop} : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ k l, a ≤ k → a ≤ l → p (k, l) := eventually_atBot_prod_self (α := αᵒᵈ) theorem eventually_atBot_prod_self' [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {p : α × α → Prop} : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ k ≤ a, ∀ l ≤ a, p (k, l) := by simp only [eventually_atBot_prod_self, forall_cond_comm] theorem eventually_atTop_prod_self' [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] {p : α × α → Prop} : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ k ≥ a, ∀ l ≥ a, p (k, l) := by simp only [eventually_atTop_prod_self, forall_cond_comm] theorem eventually_atTop_curry [Preorder α] [Preorder β] {p : α × β → Prop} (hp : ∀ᶠ x : α × β in Filter.atTop, p x) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, p (k, l) := by rw [← prod_atTop_atTop_eq] at hp exact hp.curry theorem eventually_atBot_curry [Preorder α] [Preorder β] {p : α × β → Prop} (hp : ∀ᶠ x : α × β in Filter.atBot, p x) : ∀ᶠ k in atBot, ∀ᶠ l in atBot, p (k, l) := @eventually_atTop_curry αᵒᵈ βᵒᵈ _ _ _ hp end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Archimedean.lean
import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Order.Filter.AtTopBot.Group import Mathlib.Order.Filter.CountablyGenerated import Mathlib.Tactic.GCongr /-! # `Filter.atTop` filter and archimedean (semi)rings/fields In this file we prove that for a linear ordered archimedean semiring `R` and a function `f : α → ℕ`, the function `Nat.cast ∘ f : α → R` tends to `Filter.atTop` along a filter `l` if and only if so does `f`. We also prove that `Nat.cast : ℕ → R` tends to `Filter.atTop` along `Filter.atTop`, as well as version of these two results for `ℤ` (and a ring `R`) and `ℚ` (and a field `R`). -/ variable {α R : Type*} open Filter Set Function @[simp] theorem Nat.comap_cast_atTop [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] : comap ((↑) : ℕ → R) atTop = atTop := comap_embedding_atTop (fun _ _ => Nat.cast_le) exists_nat_ge theorem tendsto_natCast_atTop_iff [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] {f : α → ℕ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := tendsto_atTop_embedding (fun _ _ => Nat.cast_le) exists_nat_ge theorem tendsto_natCast_atTop_atTop [Semiring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] : Tendsto ((↑) : ℕ → R) atTop atTop := Nat.mono_cast.tendsto_atTop_atTop exists_nat_ge theorem Filter.Eventually.natCast_atTop [Semiring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x : R) in atTop, p x) : ∀ᶠ (n : ℕ) in atTop, p n := tendsto_natCast_atTop_atTop.eventually h @[simp] theorem Int.comap_cast_atTop [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] : comap ((↑) : ℤ → R) atTop = atTop := comap_embedding_atTop (fun _ _ => Int.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge r; ⟨n, mod_cast hn⟩ @[simp] theorem Int.comap_cast_atBot [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] : comap ((↑) : ℤ → R) atBot = atBot := comap_embedding_atBot (fun _ _ => Int.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge (-r) ⟨-n, by simpa [neg_le] using hn⟩ theorem tendsto_intCast_atTop_iff [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] {f : α → ℤ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := by rw [← @Int.comap_cast_atTop R, tendsto_comap_iff]; rfl theorem tendsto_intCast_atBot_iff [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] {f : α → ℤ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atBot ↔ Tendsto f l atBot := by rw [← @Int.comap_cast_atBot R, tendsto_comap_iff]; rfl theorem tendsto_intCast_atTop_atTop [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] : Tendsto ((↑) : ℤ → R) atTop atTop := tendsto_intCast_atTop_iff.2 tendsto_id theorem Filter.Eventually.intCast_atTop [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x : R) in atTop, p x) : ∀ᶠ (n : ℤ) in atTop, p n := by rw [← Int.comap_cast_atTop (R := R)]; exact h.comap _ theorem Filter.Eventually.intCast_atBot [Ring R] [PartialOrder R] [IsStrictOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x : R) in atBot, p x) : ∀ᶠ (n : ℤ) in atBot, p n := by rw [← Int.comap_cast_atBot (R := R)]; exact h.comap _ @[simp] theorem Rat.comap_cast_atTop [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] : comap ((↑) : ℚ → R) atTop = atTop := comap_embedding_atTop (fun _ _ => Rat.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge r; ⟨n, by simpa⟩ @[simp] theorem Rat.comap_cast_atBot [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] : comap ((↑) : ℚ → R) atBot = atBot := comap_embedding_atBot (fun _ _ => Rat.cast_le) fun r => let ⟨n, hn⟩ := exists_nat_ge (-r) ⟨-n, by simpa [neg_le]⟩ theorem tendsto_ratCast_atTop_iff [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] {f : α → ℚ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := by rw [← @Rat.comap_cast_atTop R, tendsto_comap_iff]; rfl theorem tendsto_ratCast_atBot_iff [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] {f : α → ℚ} {l : Filter α} : Tendsto (fun n => (f n : R)) l atBot ↔ Tendsto f l atBot := by rw [← @Rat.comap_cast_atBot R, tendsto_comap_iff]; rfl theorem Filter.Eventually.ratCast_atTop [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x : R) in atTop, p x) : ∀ᶠ (n : ℚ) in atTop, p n := by rw [← Rat.comap_cast_atTop (R := R)]; exact h.comap _ theorem Filter.Eventually.ratCast_atBot [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] {p : R → Prop} (h : ∀ᶠ (x : R) in atBot, p x) : ∀ᶠ (n : ℚ) in atBot, p n := by rw [← Rat.comap_cast_atBot (R := R)]; exact h.comap _ theorem atTop_hasAntitoneBasis_of_archimedean [Semiring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] : (atTop : Filter R).HasAntitoneBasis fun n : ℕ => Ici n := hasAntitoneBasis_atTop.comp_mono Nat.mono_cast tendsto_natCast_atTop_atTop theorem atTop_hasCountableBasis_of_archimedean [Semiring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] : (atTop : Filter R).HasCountableBasis (fun _ : ℕ => True) fun n => Ici n := ⟨atTop_hasAntitoneBasis_of_archimedean.1, to_countable _⟩ theorem atBot_hasCountableBasis_of_archimedean [Ring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] : (atBot : Filter R).HasCountableBasis (fun _ : ℤ => True) fun m => Iic m where countable := to_countable _ toHasBasis := atBot_basis.to_hasBasis (fun x _ => let ⟨m, hm⟩ := exists_int_le x; ⟨m, trivial, Iic_subset_Iic.2 hm⟩) fun m _ => ⟨m, trivial, Subset.rfl⟩ instance (priority := 100) atTop_isCountablyGenerated_of_archimedean [Semiring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] : (atTop : Filter R).IsCountablyGenerated := atTop_hasCountableBasis_of_archimedean.isCountablyGenerated instance (priority := 100) atBot_isCountablyGenerated_of_archimedean [Ring R] [PartialOrder R] [IsOrderedRing R] [Archimedean R] : (atBot : Filter R).IsCountablyGenerated := atBot_hasCountableBasis_of_archimedean.isCountablyGenerated namespace Filter variable {l : Filter α} {f : α → R} {r : R} theorem map_add_atTop_eq [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] [IsDirected α (· ≤ ·)] (k : α) : map (fun a => a + k) atTop = atTop := map_atTop_eq_of_gc (fun a => a - k) 0 add_left_mono (by simp [le_sub_iff_add_le]) (by simp) theorem map_sub_atTop_eq [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] [IsDirected α (· ≤ ·)] (k : α) : map (fun a => a - k) atTop = atTop := by simp_rw [sub_eq_add_neg] apply map_add_atTop_eq section LinearOrderedSemiring variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] /-- If a function tends to infinity along a filter, then this function multiplied by a positive constant (on the left) also tends to infinity. The archimedean assumption is convenient to get a statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is given in `Filter.Tendsto.const_mul_atTop`). -/ theorem Tendsto.const_mul_atTop' (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atTop := by refine tendsto_atTop.2 fun b => ?_ obtain ⟨n : ℕ, hn : 1 ≤ n • r⟩ := Archimedean.arch 1 hr rw [nsmul_eq_mul'] at hn filter_upwards [tendsto_atTop.1 hf (n * max b 0)] with x hx calc b ≤ 1 * max b 0 := by { rw [one_mul] exact le_max_left _ _ } _ ≤ r * n * max b 0 := by gcongr _ = r * (n * max b 0) := by rw [mul_assoc] _ ≤ r * f x := by gcongr /-- If a function tends to infinity along a filter, then this function multiplied by a positive constant (on the right) also tends to infinity. The archimedean assumption is convenient to get a statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is given in `Filter.Tendsto.atTop_mul_const`). -/ theorem Tendsto.atTop_mul_const' (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atTop := by refine tendsto_atTop.2 fun b => ?_ obtain ⟨n : ℕ, hn : 1 ≤ n • r⟩ := Archimedean.arch 1 hr have hn' : 1 ≤ (n : R) * r := by rwa [nsmul_eq_mul] at hn filter_upwards [tendsto_atTop.1 hf (max b 0 * n)] with x hx calc b ≤ max b 0 * 1 := by { rw [mul_one] exact le_max_left _ _ } _ ≤ max b 0 * (n * r) := by gcongr _ = max b 0 * n * r := by rw [mul_assoc] _ ≤ f x * r := by gcongr end LinearOrderedSemiring section LinearOrderedRing variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] [Archimedean R] /-- See also `Filter.Tendsto.atTop_mul_const_of_neg` for a version of this lemma for `LinearOrderedField`s which does not require the `Archimedean` assumption. -/ theorem Tendsto.atTop_mul_const_of_neg' (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atBot := by simpa only [tendsto_neg_atTop_iff, mul_neg] using hf.atTop_mul_const' (neg_pos.mpr hr) /-- See also `Filter.Tendsto.atBot_mul_const` for a version of this lemma for `LinearOrderedField`s which does not require the `Archimedean` assumption. -/ theorem Tendsto.atBot_mul_const' (hr : 0 < r) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atBot := by simp only [← tendsto_neg_atTop_iff, ← neg_mul] at hf ⊢ exact hf.atTop_mul_const' hr /-- See also `Filter.Tendsto.atBot_mul_const_of_neg` for a version of this lemma for `LinearOrderedField`s which does not require the `Archimedean` assumption. -/ theorem Tendsto.atBot_mul_const_of_neg' (hr : r < 0) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atTop := by simpa only [mul_neg, tendsto_neg_atBot_iff] using hf.atBot_mul_const' (neg_pos.2 hr) end LinearOrderedRing section LinearOrderedCancelAddCommMonoid variable [AddCommMonoid R] [LinearOrder R] [IsOrderedCancelAddMonoid R] [Archimedean R] theorem Tendsto.atTop_nsmul_const {f : α → ℕ} (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x • r) l atTop := by refine tendsto_atTop.mpr fun s => ?_ obtain ⟨n : ℕ, hn : s ≤ n • r⟩ := Archimedean.arch s hr exact (tendsto_atTop.mp hf n).mono fun a ha => hn.trans (nsmul_le_nsmul_left hr.le ha) end LinearOrderedCancelAddCommMonoid section LinearOrderedAddCommGroup variable [AddCommGroup R] [LinearOrder R] [IsOrderedAddMonoid R] [Archimedean R] theorem Tendsto.atTop_nsmul_neg_const {f : α → ℕ} (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x => f x • r) l atBot := by simpa using hf.atTop_nsmul_const (neg_pos.2 hr) theorem Tendsto.atTop_zsmul_const {f : α → ℤ} (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x • r) l atTop := by refine tendsto_atTop.mpr fun s => ?_ obtain ⟨n : ℕ, hn : s ≤ n • r⟩ := Archimedean.arch s hr replace hn : s ≤ (n : ℤ) • r := by simpa exact (tendsto_atTop.mp hf n).mono fun a ha => hn.trans (zsmul_le_zsmul_left hr.le ha) theorem Tendsto.atTop_zsmul_neg_const {f : α → ℤ} (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x => f x • r) l atBot := by simpa using hf.atTop_zsmul_const (neg_pos.2 hr) theorem Tendsto.atBot_zsmul_const {f : α → ℤ} (hr : 0 < r) (hf : Tendsto f l atBot) : Tendsto (fun x => f x • r) l atBot := by simp only [← tendsto_neg_atTop_iff, ← neg_zsmul] at hf ⊢ exact hf.atTop_zsmul_const hr theorem Tendsto.atBot_zsmul_neg_const {f : α → ℤ} (hr : r < 0) (hf : Tendsto f l atBot) : Tendsto (fun x => f x • r) l atTop := by simpa using hf.atBot_zsmul_const (neg_pos.2 hr) end LinearOrderedAddCommGroup end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Map.lean
import Mathlib.Order.Filter.AtTopBot.Defs import Mathlib.Order.Filter.Map import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Interval.Set.OrderIso /-! # Map and comap of `Filter.atTop` and `Filter.atBot` -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace OrderIso open Filter variable [Preorder α] [Preorder β] @[simp] theorem comap_atTop (e : α ≃o β) : comap e atTop = atTop := by simp [atTop, ← e.surjective.iInf_comp] @[simp] theorem comap_atBot (e : α ≃o β) : comap e atBot = atBot := e.dual.comap_atTop @[simp] theorem map_atTop (e : α ≃o β) : map (e : α → β) atTop = atTop := by rw [← e.comap_atTop, map_comap_of_surjective e.surjective] @[simp] theorem map_atBot (e : α ≃o β) : map (e : α → β) atBot = atBot := e.dual.map_atTop theorem tendsto_atTop (e : α ≃o β) : Tendsto e atTop atTop := e.map_atTop.le theorem tendsto_atBot (e : α ≃o β) : Tendsto e atBot atBot := e.map_atBot.le @[simp] theorem tendsto_atTop_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) : Tendsto (fun x => e (f x)) l atTop ↔ Tendsto f l atTop := by rw [← e.comap_atTop, tendsto_comap_iff, Function.comp_def] @[simp] theorem tendsto_atBot_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) : Tendsto (fun x => e (f x)) l atBot ↔ Tendsto f l atBot := e.dual.tendsto_atTop_iff end OrderIso
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Finset.lean
import Mathlib.Data.Finset.Order import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.Finite import Mathlib.Order.Interval.Finset.Defs /-! # `Filter.atTop` and `Filter.atBot` filters and finite sets. -/ variable {ι ι' α β γ : Type*} open Set namespace Filter theorem tendsto_finset_range : Tendsto Finset.range atTop atTop := Finset.range_mono.tendsto_atTop_atTop Finset.exists_nat_subset_range theorem atTop_finset_eq_iInf : (atTop : Filter (Finset α)) = ⨅ x : α, 𝓟 (Ici {x}) := by refine le_antisymm (le_iInf fun i => le_principal_iff.2 <| mem_atTop ({i} : Finset α)) ?_ refine le_iInf fun s => le_principal_iff.2 <| mem_iInf_of_iInter s.finite_toSet (fun i => mem_principal_self _) ?_ simp only [subset_def, mem_iInter, SetCoe.forall, mem_Ici, Finset.le_iff_subset, Finset.mem_singleton, Finset.subset_iff, forall_eq] exact fun t => id /-- If `f` is a monotone sequence of `Finset`s and each `x` belongs to one of `f n`, then `Tendsto f atTop atTop`. -/ theorem tendsto_atTop_finset_of_monotone [Preorder β] {f : β → Finset α} (h : Monotone f) (h' : ∀ x : α, ∃ n, x ∈ f n) : Tendsto f atTop atTop := by simp only [atTop_finset_eq_iInf, tendsto_iInf, tendsto_principal] intro a rcases h' a with ⟨b, hb⟩ exact (eventually_ge_atTop b).mono fun b' hb' => (Finset.singleton_subset_iff.2 hb).trans (h hb') alias _root_.Monotone.tendsto_atTop_finset := tendsto_atTop_finset_of_monotone theorem tendsto_finset_image_atTop_atTop [DecidableEq β] {i : β → γ} {j : γ → β} (h : Function.LeftInverse j i) : Tendsto (Finset.image j) atTop atTop := (Finset.image_mono j).tendsto_atTop_finset fun a => ⟨{i a}, by simp only [Finset.image_singleton, h a, Finset.mem_singleton]⟩ theorem tendsto_finset_preimage_atTop_atTop {f : α → β} (hf : Function.Injective f) : Tendsto (fun s : Finset β => s.preimage f (hf.injOn)) atTop atTop := (Finset.monotone_preimage hf).tendsto_atTop_finset fun x => ⟨{f x}, Finset.mem_preimage.2 <| Finset.mem_singleton_self _⟩ lemma tendsto_toLeft_atTop : Tendsto (Finset.toLeft (α := α) (β := β)) atTop atTop := by intro s hs simp only [mem_atTop_sets, Filter.mem_map, Set.mem_preimage] at hs ⊢ obtain ⟨t, H⟩ := hs exact ⟨t.disjSum ∅, fun b hb ↦ H _ (by simpa [← Finset.coe_subset, Set.subset_def] using hb)⟩ lemma tendsto_toRight_atTop : Tendsto (Finset.toRight (α := α) (β := β)) atTop atTop := by intro s hs simp only [mem_atTop_sets, Filter.mem_map, Set.mem_preimage] at hs ⊢ obtain ⟨t, H⟩ := hs exact ⟨.disjSum ∅ t, fun b hb ↦ H _ (by simpa [← Finset.coe_subset, Set.subset_def] using hb)⟩ theorem tendsto_finset_powerset_atTop_atTop : Tendsto (Finset.powerset (α := α)) atTop atTop := by classical refine tendsto_atTop_atTop.mpr fun t ↦ ⟨t.sup id, fun _ hu _ hv ↦ ?_⟩ exact Finset.mem_powerset.mpr <| (Finset.le_sup_of_le hv fun _ h ↦ h).trans hu theorem tendsto_finset_Iic_atTop_atTop [Preorder α] [LocallyFiniteOrderBot α] : Tendsto (Finset.Iic (α := α)) atTop atTop := by rcases isEmpty_or_nonempty α with _ | _ · exact tendsto_of_isEmpty by_cases h : IsDirected α (· ≤ ·) · refine tendsto_atTop_atTop.mpr fun s ↦ ?_ obtain ⟨a, ha⟩ := Finset.exists_le s exact ⟨a, fun b hb c hc ↦ by simpa using (ha c hc).trans hb⟩ · obtain h := Filter.atTop_neBot_iff.not.mpr (fun h' ↦ h h'.2) simp [not_ne_iff.mp <| Filter.neBot_iff.not.mp h] theorem tendsto_finset_Ici_atBot_atTop [Preorder α] [LocallyFiniteOrderTop α] : Tendsto (Finset.Ici (α := α)) atBot atTop := tendsto_finset_Iic_atTop_atTop (α := αᵒᵈ) end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Basic.lean
import Mathlib.Order.Filter.Bases.Basic import Mathlib.Order.Filter.AtTopBot.Tendsto import Mathlib.Order.Nat import Mathlib.Tactic.Subsingleton /-! # Basic results on `Filter.atTop` and `Filter.atBot` filters In this file we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”. -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace Filter section IsDirected variable [Preorder α] [IsDirected α (· ≤ ·)] {p : α → Prop} theorem hasAntitoneBasis_atTop [Nonempty α] : (@atTop α _).HasAntitoneBasis Ici := .iInf_principal fun _ _ ↦ Ici_subset_Ici.2 theorem atTop_basis [Nonempty α] : (@atTop α _).HasBasis (fun _ => True) Ici := hasAntitoneBasis_atTop.1 lemma atTop_basis_Ioi [Nonempty α] [NoMaxOrder α] : (@atTop α _).HasBasis (fun _ => True) Ioi := atTop_basis.to_hasBasis (fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩) fun a ha => (exists_gt a).imp fun _b hb => ⟨ha, Ici_subset_Ioi.2 hb⟩ lemma atTop_basis_Ioi' [NoMaxOrder α] (a : α) : atTop.HasBasis (a < ·) Ioi := by have : Nonempty α := ⟨a⟩ refine atTop_basis_Ioi.to_hasBasis (fun b _ ↦ ?_) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩ obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b obtain ⟨d, hcd⟩ := exists_gt c exact ⟨d, hac.trans_lt hcd, Ioi_subset_Ioi (hbc.trans hcd.le)⟩ theorem atTop_basis' (a : α) : atTop.HasBasis (a ≤ ·) Ici := by have : Nonempty α := ⟨a⟩ refine atTop_basis.to_hasBasis (fun b _ ↦ ?_) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩ obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b exact ⟨c, hac, Ici_subset_Ici.2 hbc⟩ variable [Nonempty α] @[instance] lemma atTop_neBot : NeBot (atTop : Filter α) := atTop_basis.neBot_iff.2 fun _ => nonempty_Ici theorem atTop_neBot_iff {α : Type*} [Preorder α] : (atTop : Filter α).NeBot ↔ Nonempty α ∧ IsDirected α (· ≤ ·) := by refine ⟨fun h ↦ ⟨nonempty_of_neBot atTop, ⟨fun x y ↦ ?_⟩⟩, fun ⟨h₁, h₂⟩ ↦ atTop_neBot⟩ exact ((eventually_ge_atTop x).and (eventually_ge_atTop y)).exists theorem atBot_neBot_iff {α : Type*} [Preorder α] : (atBot : Filter α).NeBot ↔ Nonempty α ∧ IsDirected α (· ≥ ·) := atTop_neBot_iff (α := αᵒᵈ) @[simp] lemma mem_atTop_sets {s : Set α} : s ∈ (atTop : Filter α) ↔ ∃ a : α, ∀ b ≥ a, b ∈ s := atTop_basis.mem_iff.trans <| exists_congr fun _ => iff_of_eq (true_and _) @[simp] lemma eventually_atTop : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ b ≥ a, p b := mem_atTop_sets theorem frequently_atTop : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b ≥ a, p b := atTop_basis.frequently_iff.trans <| by simp alias ⟨Eventually.exists_forall_of_atTop, _⟩ := eventually_atTop lemma exists_eventually_atTop {r : α → β → Prop} : (∃ b, ∀ᶠ a in atTop, r a b) ↔ ∀ᶠ a₀ in atTop, ∃ b, ∀ a ≥ a₀, r a b := by simp_rw [eventually_atTop, ← exists_swap (α := α)] exact exists_congr fun a ↦ .symm <| forall_ge_iff <| Monotone.exists fun _ _ _ hb H n hn ↦ H n (hb.trans hn) theorem map_atTop_eq {f : α → β} : atTop.map f = ⨅ a, 𝓟 (f '' { a' | a ≤ a' }) := (atTop_basis.map f).eq_iInf theorem frequently_atTop' [NoMaxOrder α] : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b > a, p b := atTop_basis_Ioi.frequently_iff.trans <| by simp end IsDirected section IsCodirected variable [Preorder α] [IsDirected α (· ≥ ·)] {p : α → Prop} lemma atBot_basis_Iio [Nonempty α] [NoMinOrder α] : (@atBot α _).HasBasis (fun _ => True) Iio := atTop_basis_Ioi (α := αᵒᵈ) lemma atBot_basis_Iio' [NoMinOrder α] (a : α) : atBot.HasBasis (· < a) Iio := atTop_basis_Ioi' (α := αᵒᵈ) a lemma atBot_basis' (a : α) : (@atBot α _).HasBasis (fun x => x ≤ a) Iic := atTop_basis' (α := αᵒᵈ) _ variable [Nonempty α] lemma atBot_basis : (@atBot α _).HasBasis (fun _ => True) Iic := atTop_basis (α := αᵒᵈ) @[instance] lemma atBot_neBot : NeBot (atBot : Filter α) := atTop_neBot (α := αᵒᵈ) @[simp] lemma mem_atBot_sets {s : Set α} : s ∈ (atBot : Filter α) ↔ ∃ a : α, ∀ b ≤ a, b ∈ s := mem_atTop_sets (α := αᵒᵈ) @[simp] lemma eventually_atBot : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ b ≤ a, p b := mem_atBot_sets theorem frequently_atBot : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b ≤ a, p b := frequently_atTop (α := αᵒᵈ) alias ⟨Eventually.exists_forall_of_atBot, _⟩ := eventually_atBot lemma exists_eventually_atBot {r : α → β → Prop} : (∃ b, ∀ᶠ a in atBot, r a b) ↔ ∀ᶠ a₀ in atBot, ∃ b, ∀ a ≤ a₀, r a b := exists_eventually_atTop (α := αᵒᵈ) theorem map_atBot_eq {f : α → β} : atBot.map f = ⨅ a, 𝓟 (f '' { a' | a' ≤ a }) := map_atTop_eq (α := αᵒᵈ) theorem frequently_atBot' [NoMinOrder α] : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b < a, p b := frequently_atTop' (α := αᵒᵈ) end IsCodirected /-! ### Sequences -/ theorem extraction_of_frequently_atTop {P : ℕ → Prop} (h : ∃ᶠ n in atTop, P n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by rw [frequently_atTop'] at h exact Nat.exists_strictMono_subsequence h theorem extraction_of_eventually_atTop {P : ℕ → Prop} (h : ∀ᶠ n in atTop, P n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := extraction_of_frequently_atTop h.frequently theorem extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in atTop, P n k) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := by simp only [frequently_atTop'] at h choose u hu hu' using h use (fun n => Nat.recOn n (u 0 0) fun n v => u (n + 1) v : ℕ → ℕ) constructor · apply strictMono_nat_of_lt_succ intro n apply hu · intro n cases n <;> simp [hu'] theorem extraction_forall_of_eventually {P : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in atTop, P n k) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := extraction_forall_of_frequently fun n => (h n).frequently theorem extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := extraction_forall_of_eventually (by simp [eventually_atTop, h]) section IsDirected variable [Preorder α] [IsDirected α (· ≤ ·)] {F : Filter β} {u : α → β} theorem inf_map_atTop_neBot_iff [Nonempty α] : NeBot (F ⊓ map u atTop) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U := by simp_rw [inf_neBot_iff_frequently_left, frequently_map, frequently_atTop]; rfl variable [Preorder β] lemma exists_le_of_tendsto_atTop (h : Tendsto u atTop atTop) (a : α) (b : β) : ∃ a' ≥ a, b ≤ u a' := by have : Nonempty α := ⟨a⟩ have : ∀ᶠ x in atTop, a ≤ x ∧ b ≤ u x := (eventually_ge_atTop a).and (h.eventually <| eventually_ge_atTop b) exact this.exists theorem exists_le_of_tendsto_atBot (h : Tendsto u atTop atBot) : ∀ a b, ∃ a' ≥ a, u a' ≤ b := exists_le_of_tendsto_atTop (β := βᵒᵈ) h theorem exists_lt_of_tendsto_atTop [NoMaxOrder β] (h : Tendsto u atTop atTop) (a : α) (b : β) : ∃ a' ≥ a, b < u a' := by obtain ⟨b', hb'⟩ := exists_gt b rcases exists_le_of_tendsto_atTop h a b' with ⟨a', ha', ha''⟩ exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩ theorem exists_lt_of_tendsto_atBot [NoMinOrder β] (h : Tendsto u atTop atBot) : ∀ a b, ∃ a' ≥ a, u a' < b := exists_lt_of_tendsto_atTop (β := βᵒᵈ) h end IsDirected section IsCodirected variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {F : Filter β} {u : α → β} theorem inf_map_atBot_neBot_iff : NeBot (F ⊓ map u atBot) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U := inf_map_atTop_neBot_iff (α := αᵒᵈ) end IsCodirected section IsDirected variable [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] {f : α → β} {l : Filter β} theorem tendsto_atTop' : Tendsto f atTop l ↔ ∀ s ∈ l, ∃ a, ∀ b ≥ a, f b ∈ s := by simp only [tendsto_def, mem_atTop_sets, mem_preimage] theorem tendsto_atTop_principal {s : Set β} : Tendsto f atTop (𝓟 s) ↔ ∃ N, ∀ n ≥ N, f n ∈ s := by simp_rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_atTop_sets, mem_preimage] variable [Preorder β] /-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/ theorem tendsto_atTop_atTop : Tendsto f atTop atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a := tendsto_iInf.trans <| forall_congr' fun _ => tendsto_atTop_principal theorem tendsto_atTop_atBot : Tendsto f atTop atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → f a ≤ b := tendsto_atTop_atTop (β := βᵒᵈ) theorem tendsto_atTop_atTop_iff_of_monotone (hf : Monotone f) : Tendsto f atTop atTop ↔ ∀ b : β, ∃ a, b ≤ f a := tendsto_atTop_atTop.trans <| forall_congr' fun _ => exists_congr fun a => ⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans h <| hf ha'⟩ theorem tendsto_atTop_atBot_iff_of_antitone (hf : Antitone f) : Tendsto f atTop atBot ↔ ∀ b : β, ∃ a, f a ≤ b := tendsto_atTop_atTop_iff_of_monotone (β := βᵒᵈ) hf end IsDirected section IsCodirected variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {f : α → β} {l : Filter β} theorem tendsto_atBot' : Tendsto f atBot l ↔ ∀ s ∈ l, ∃ a, ∀ b ≤ a, f b ∈ s := tendsto_atTop' (α := αᵒᵈ) theorem tendsto_atBot_principal {s : Set β} : Tendsto f atBot (𝓟 s) ↔ ∃ N, ∀ n ≤ N, f n ∈ s := tendsto_atTop_principal (α := αᵒᵈ) (β := βᵒᵈ) variable [Preorder β] theorem tendsto_atBot_atTop : Tendsto f atBot atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → b ≤ f a := tendsto_atTop_atTop (α := αᵒᵈ) theorem tendsto_atBot_atBot : Tendsto f atBot atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → f a ≤ b := tendsto_atTop_atTop (α := αᵒᵈ) (β := βᵒᵈ) theorem tendsto_atBot_atBot_iff_of_monotone (hf : Monotone f) : Tendsto f atBot atBot ↔ ∀ b : β, ∃ a, f a ≤ b := tendsto_atBot_atBot.trans <| forall_congr' fun _ => exists_congr fun a => ⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans (hf ha') h⟩ theorem tendsto_atBot_atTop_iff_of_antitone (hf : Antitone f) : Tendsto f atBot atTop ↔ ∀ b : β, ∃ a, b ≤ f a := tendsto_atBot_atBot_iff_of_monotone (β := βᵒᵈ) hf end IsCodirected alias _root_.Monotone.tendsto_atTop_atTop_iff := tendsto_atTop_atTop_iff_of_monotone alias _root_.Monotone.tendsto_atBot_atBot_iff := tendsto_atBot_atBot_iff_of_monotone theorem Tendsto.subseq_mem {F : Filter α} {V : ℕ → Set α} (h : ∀ n, V n ∈ F) {u : ℕ → α} (hu : Tendsto u atTop F) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, u (φ n) ∈ V n := extraction_forall_of_eventually' (fun n => tendsto_atTop'.mp hu _ (h n) : ∀ n, ∃ N, ∀ k ≥ N, u k ∈ V n) /-- A function `f` maps upwards closed sets (atTop sets) to upwards closed sets when it is a Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an insertion and a connection above `b`. -/ theorem map_atTop_eq_of_gc_preorder [Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β} (hf : Monotone f) (b : β) (hgi : ∀ c ≥ b, ∃ x, f x = c ∧ ∀ a, f a ≤ c ↔ a ≤ x) : map f atTop = atTop := by have : Nonempty α := (hgi b le_rfl).nonempty choose! g hfg hgle using hgi refine le_antisymm (hf.tendsto_atTop_atTop fun c ↦ ?_) ?_ · rcases exists_ge_ge c b with ⟨d, hcd, hbd⟩ exact ⟨g d, hcd.trans (hfg d hbd).ge⟩ · have : Nonempty α := ⟨g b⟩ rw [(atTop_basis.map f).ge_iff] intro a _ filter_upwards [eventually_ge_atTop (f a), eventually_ge_atTop b] with c hac hbc exact ⟨g c, (hgle _ hbc _).1 hac, hfg _ hbc⟩ /-- A function `f` maps upwards closed sets (atTop sets) to upwards closed sets when it is a Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an insertion and a connection above `b`. -/ theorem map_atTop_eq_of_gc [Preorder α] [IsDirected α (· ≤ ·)] [PartialOrder β] [IsDirected β (· ≤ ·)] {f : α → β} (g : β → α) (b : β) (hf : Monotone f) (gc : ∀ a, ∀ c ≥ b, f a ≤ c ↔ a ≤ g c) (hgi : ∀ c ≥ b, c ≤ f (g c)) : map f atTop = atTop := map_atTop_eq_of_gc_preorder hf b fun c hc ↦ ⟨g c, le_antisymm ((gc _ _ hc).2 le_rfl) (hgi c hc), (gc · c hc)⟩ theorem map_atBot_eq_of_gc_preorder [Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β} (hf : Monotone f) (b : β) (hgi : ∀ c ≤ b, ∃ x, f x = c ∧ ∀ a, c ≤ f a ↔ x ≤ a) : map f atBot = atBot := map_atTop_eq_of_gc_preorder (α := αᵒᵈ) (β := βᵒᵈ) hf.dual _ hgi theorem map_atBot_eq_of_gc [Preorder α] [IsDirected α (· ≥ ·)] [PartialOrder β] [IsDirected β (· ≥ ·)] {f : α → β} (g : β → α) (b' : β) (hf : Monotone f) (gc : ∀ a, ∀ b ≤ b', b ≤ f a ↔ g b ≤ a) (hgi : ∀ b ≤ b', f (g b) ≤ b) : map f atBot = atBot := map_atTop_eq_of_gc (α := αᵒᵈ) (β := βᵒᵈ) _ _ hf.dual gc hgi theorem map_val_atTop_of_Ici_subset [Preorder α] [IsDirected α (· ≤ ·)] {a : α} {s : Set α} (h : Ici a ⊆ s) : map ((↑) : s → α) atTop = atTop := by choose f hl hr using exists_ge_ge (α := α) have : DirectedOn (· ≤ ·) s := fun x _ y _ ↦ ⟨f a (f x y), h <| hl _ _, (hl x y).trans (hr _ _), (hr x y).trans (hr _ _)⟩ have : IsDirected s (· ≤ ·) := by rw [directedOn_iff_directed] at this rwa [← directed_id_iff] refine map_atTop_eq_of_gc_preorder (Subtype.mono_coe _) a fun c hc ↦ ?_ exact ⟨⟨c, h hc⟩, rfl, fun _ ↦ .rfl⟩ @[simp] theorem _root_.Nat.map_cast_int_atTop : map ((↑) : ℕ → ℤ) atTop = atTop := by refine map_atTop_eq_of_gc_preorder (fun _ _ ↦ Int.ofNat_le.2) 0 fun n hn ↦ ?_ lift n to ℕ using hn exact ⟨n, rfl, fun _ ↦ Int.ofNat_le⟩ /-- The image of the filter `atTop` on `Ici a` under the coercion equals `atTop`. -/ @[simp] theorem map_val_Ici_atTop [Preorder α] [IsDirected α (· ≤ ·)] (a : α) : map ((↑) : Ici a → α) atTop = atTop := map_val_atTop_of_Ici_subset Subset.rfl /-- The image of the filter `atTop` on `Ioi a` under the coercion equals `atTop`. -/ @[simp] theorem map_val_Ioi_atTop [Preorder α] [IsDirected α (· ≤ ·)] [NoMaxOrder α] (a : α) : map ((↑) : Ioi a → α) atTop = atTop := let ⟨_b, hb⟩ := exists_gt a map_val_atTop_of_Ici_subset <| Ici_subset_Ioi.2 hb /-- The `atTop` filter for an open interval `Ioi a` comes from the `atTop` filter in the ambient order. -/ theorem atTop_Ioi_eq [Preorder α] [IsDirected α (· ≤ ·)] (a : α) : atTop = comap ((↑) : Ioi a → α) atTop := by rcases isEmpty_or_nonempty (Ioi a) with h|⟨⟨b, hb⟩⟩ · subsingleton · rw [← map_val_atTop_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map Subtype.coe_injective] /-- The `atTop` filter for an open interval `Ici a` comes from the `atTop` filter in the ambient order. -/ theorem atTop_Ici_eq [Preorder α] [IsDirected α (· ≤ ·)] (a : α) : atTop = comap ((↑) : Ici a → α) atTop := by rw [← map_val_Ici_atTop a, comap_map Subtype.coe_injective] /-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient order. -/ @[simp] theorem map_val_Iio_atBot [Preorder α] [IsDirected α (· ≥ ·)] [NoMinOrder α] (a : α) : map ((↑) : Iio a → α) atBot = atBot := map_val_Ioi_atTop (OrderDual.toDual a) /-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient order. -/ theorem atBot_Iio_eq [Preorder α] [IsDirected α (· ≥ ·)] (a : α) : atBot = comap ((↑) : Iio a → α) atBot := atTop_Ioi_eq (OrderDual.toDual a) /-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient order. -/ @[simp] theorem map_val_Iic_atBot [Preorder α] [IsDirected α (· ≥ ·)] (a : α) : map ((↑) : Iic a → α) atBot = atBot := map_val_Ici_atTop (OrderDual.toDual a) /-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient order. -/ theorem atBot_Iic_eq [Preorder α] [IsDirected α (· ≥ ·)] (a : α) : atBot = comap ((↑) : Iic a → α) atBot := atTop_Ici_eq (OrderDual.toDual a) theorem tendsto_Ioi_atTop [Preorder α] [IsDirected α (· ≤ ·)] {a : α} {f : β → Ioi a} {l : Filter β} : Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by rw [atTop_Ioi_eq, tendsto_comap_iff, Function.comp_def] theorem tendsto_Iio_atBot [Preorder α] [IsDirected α (· ≥ ·)] {a : α} {f : β → Iio a} {l : Filter β} : Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot := tendsto_Ioi_atTop (α := αᵒᵈ) theorem tendsto_Ici_atTop [Preorder α] [IsDirected α (· ≤ ·)] {a : α} {f : β → Ici a} {l : Filter β} : Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by rw [atTop_Ici_eq, tendsto_comap_iff, Function.comp_def] theorem tendsto_Iic_atBot [Preorder α] [IsDirected α (· ≥ ·)] {a : α} {f : β → Iic a} {l : Filter β} : Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot := tendsto_Ici_atTop (α := αᵒᵈ) @[simp] theorem tendsto_comp_val_Ioi_atTop [Preorder α] [IsDirected α (· ≤ ·)] [NoMaxOrder α] {a : α} {f : α → β} {l : Filter β} : Tendsto (fun x : Ioi a => f x) atTop l ↔ Tendsto f atTop l := by rw [← map_val_Ioi_atTop a, tendsto_map'_iff, Function.comp_def] @[simp] theorem tendsto_comp_val_Ici_atTop [Preorder α] [IsDirected α (· ≤ ·)] {a : α} {f : α → β} {l : Filter β} : Tendsto (fun x : Ici a => f x) atTop l ↔ Tendsto f atTop l := by rw [← map_val_Ici_atTop a, tendsto_map'_iff, Function.comp_def] @[simp] theorem tendsto_comp_val_Iio_atBot [Preorder α] [IsDirected α (· ≥ ·)] [NoMinOrder α] {a : α} {f : α → β} {l : Filter β} : Tendsto (fun x : Iio a => f x) atBot l ↔ Tendsto f atBot l := tendsto_comp_val_Ioi_atTop (α := αᵒᵈ) @[simp] theorem tendsto_comp_val_Iic_atBot [Preorder α] [IsDirected α (· ≥ ·)] {a : α} {f : α → β} {l : Filter β} : Tendsto (fun x : Iic a => f x) atBot l ↔ Tendsto f atBot l := tendsto_comp_val_Ici_atTop (α := αᵒᵈ) theorem map_add_atTop_eq_nat (k : ℕ) : map (fun a => a + k) atTop = atTop := map_atTop_eq_of_gc (· - k) k (fun _ _ h => Nat.add_le_add_right h k) (fun _ _ h => (Nat.le_sub_iff_add_le h).symm) fun a h => by rw [Nat.sub_add_cancel h] theorem map_sub_atTop_eq_nat (k : ℕ) : map (fun a => a - k) atTop = atTop := map_atTop_eq_of_gc (· + k) 0 (fun _ _ h => Nat.sub_le_sub_right h _) (fun _ _ _ => Nat.sub_le_iff_le_add) fun b _ => by rw [Nat.add_sub_cancel_right] theorem tendsto_add_atTop_nat (k : ℕ) : Tendsto (fun a => a + k) atTop atTop := le_of_eq (map_add_atTop_eq_nat k) theorem tendsto_sub_atTop_nat (k : ℕ) : Tendsto (fun a => a - k) atTop atTop := le_of_eq (map_sub_atTop_eq_nat k) theorem tendsto_add_atTop_iff_nat {f : ℕ → α} {l : Filter α} (k : ℕ) : Tendsto (fun n => f (n + k)) atTop l ↔ Tendsto f atTop l := show Tendsto (f ∘ fun n => n + k) atTop l ↔ Tendsto f atTop l by rw [← tendsto_map'_iff, map_add_atTop_eq_nat] theorem map_div_atTop_eq_nat (k : ℕ) (hk : 0 < k) : map (fun a => a / k) atTop = atTop := map_atTop_eq_of_gc (fun b => k * b + (k - 1)) 1 (fun _ _ h => Nat.div_le_div_right h) (fun a b _ => by rw [Nat.div_le_iff_le_mul_add_pred hk]) fun b _ => by rw [Nat.mul_add_div hk, Nat.div_eq_of_lt, Nat.add_zero]; cutsat section NeBot variable [Preorder β] {l : Filter α} [NeBot l] {f : α → β} theorem not_bddAbove_of_tendsto_atTop [NoMaxOrder β] (h : Tendsto f l atTop) : ¬BddAbove (range f) := by rintro ⟨M, hM⟩ have : ∀ x, f x ≤ M := by aesop have : ∅ = f ⁻¹' Ioi M := by aesop (add forward safe not_le_of_gt) apply Filter.empty_notMem l aesop (add safe Ioi_mem_atTop) theorem not_bddBelow_of_tendsto_atBot [NoMinOrder β] (h : Tendsto f l atBot) : ¬BddBelow (range f) := not_bddAbove_of_tendsto_atTop (β := βᵒᵈ) h @[deprecated (since := "2025-04-28")] alias unbounded_of_tendsto_atTop := not_bddAbove_of_tendsto_atTop @[deprecated (since := "2025-04-28")] alias unbounded_of_tendsto_atBot := not_bddBelow_of_tendsto_atBot @[deprecated (since := "2025-04-28")] alias unbounded_of_tendsto_atTop' := not_bddAbove_of_tendsto_atTop @[deprecated (since := "2025-04-28")] alias unbounded_of_tendsto_atBot' := not_bddBelow_of_tendsto_atBot end NeBot theorem HasAntitoneBasis.eventually_subset [Preorder ι] {l : Filter α} {s : ι → Set α} (hl : l.HasAntitoneBasis s) {t : Set α} (ht : t ∈ l) : ∀ᶠ i in atTop, s i ⊆ t := let ⟨i, _, hi⟩ := hl.1.mem_iff.1 ht (eventually_ge_atTop i).mono fun _j hj => (hl.antitone hj).trans hi protected theorem HasAntitoneBasis.tendsto [Preorder ι] {l : Filter α} {s : ι → Set α} (hl : l.HasAntitoneBasis s) {φ : ι → α} (h : ∀ i : ι, φ i ∈ s i) : Tendsto φ atTop l := fun _t ht => mem_map.2 <| (hl.eventually_subset ht).mono fun i hi => hi (h i) theorem HasAntitoneBasis.comp_mono [Nonempty ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Preorder ι'] {l : Filter α} {s : ι' → Set α} (hs : l.HasAntitoneBasis s) {φ : ι → ι'} (φ_mono : Monotone φ) (hφ : Tendsto φ atTop atTop) : l.HasAntitoneBasis (s ∘ φ) := ⟨hs.1.to_hasBasis (fun n _ => (hφ.eventually_ge_atTop n).exists.imp fun _m hm => ⟨trivial, hs.antitone hm⟩) fun n _ => ⟨φ n, trivial, Subset.rfl⟩, hs.antitone.comp_monotone φ_mono⟩ theorem HasAntitoneBasis.comp_strictMono {l : Filter α} {s : ℕ → Set α} (hs : l.HasAntitoneBasis s) {φ : ℕ → ℕ} (hφ : StrictMono φ) : l.HasAntitoneBasis (s ∘ φ) := hs.comp_mono hφ.monotone hφ.tendsto_atTop theorem subseq_forall_of_frequently {ι : Type*} {x : ℕ → ι} {p : ι → Prop} {l : Filter ι} (h_tendsto : Tendsto x atTop l) (h : ∃ᶠ n in atTop, p (x n)) : ∃ ns : ℕ → ℕ, Tendsto (fun n => x (ns n)) atTop l ∧ ∀ n, p (x (ns n)) := by choose ns hge hns using frequently_atTop.1 h exact ⟨ns, h_tendsto.comp (tendsto_atTop_mono hge tendsto_id), hns⟩ end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Disjoint.lean
import Mathlib.Order.Filter.AtTopBot.Defs import Mathlib.Order.Interval.Set.Disjoint /-! # Disjointness of `Filter.atTop` and `Filter.atBot` -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace Filter theorem disjoint_atBot_principal_Ioi [Preorder α] (x : α) : Disjoint atBot (𝓟 (Ioi x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_atBot x) (mem_principal_self _) theorem disjoint_atTop_principal_Iio [Preorder α] (x : α) : Disjoint atTop (𝓟 (Iio x)) := @disjoint_atBot_principal_Ioi αᵒᵈ _ _ theorem disjoint_atTop_principal_Iic [Preorder α] [NoTopOrder α] (x : α) : Disjoint atTop (𝓟 (Iic x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_atTop x) (mem_principal_self _) theorem disjoint_atBot_principal_Ici [Preorder α] [NoBotOrder α] (x : α) : Disjoint atBot (𝓟 (Ici x)) := @disjoint_atTop_principal_Iic αᵒᵈ _ _ _ theorem disjoint_pure_atTop [Preorder α] [NoTopOrder α] (x : α) : Disjoint (pure x) atTop := Disjoint.symm <| (disjoint_atTop_principal_Iic x).mono_right <| le_principal_iff.2 <| mem_pure.2 right_mem_Iic theorem disjoint_pure_atBot [Preorder α] [NoBotOrder α] (x : α) : Disjoint (pure x) atBot := @disjoint_pure_atTop αᵒᵈ _ _ _ theorem disjoint_atBot_atTop [PartialOrder α] [Nontrivial α] : Disjoint (atBot : Filter α) atTop := by rcases exists_pair_ne α with ⟨x, y, hne⟩ by_cases hle : x ≤ y · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot x) (Ici_mem_atTop y) exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_ge · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot y) (Ici_mem_atTop x) exact Iic_disjoint_Ici.2 hle theorem disjoint_atTop_atBot [PartialOrder α] [Nontrivial α] : Disjoint (atTop : Filter α) atBot := disjoint_atBot_atTop.symm end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Defs.lean
import Mathlib.Data.Set.Piecewise import Mathlib.Order.Filter.Basic /-! # Definition of `Filter.atTop` and `Filter.atBot` filters In this file we define the filters * `Filter.atTop`: corresponds to `n → +∞`; * `Filter.atBot`: corresponds to `n → -∞`. -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace Filter /-- `atTop` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def atTop [Preorder α] : Filter α := ⨅ a, 𝓟 (Ici a) /-- `atBot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def atBot [Preorder α] : Filter α := ⨅ a, 𝓟 (Iic a) theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ := mem_iInf_of_mem a <| Subset.refl _ theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) := mem_atTop a theorem Ioi_mem_atTop [Preorder α] [NoTopOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) := let ⟨z, hz⟩ := exists_not_le x mem_of_superset (inter_mem (mem_atTop x) (mem_atTop z)) fun _ ⟨hxy, hzy⟩ => lt_of_le_not_ge hxy fun hyx => hz (hzy.trans hyx) theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ := mem_iInf_of_mem a <| Subset.refl _ theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) := mem_atBot a theorem Iio_mem_atBot [Preorder α] [NoBotOrder α] (x : α) : Iio x ∈ (atBot : Filter α) := let ⟨z, hz⟩ := exists_not_ge x mem_of_superset (inter_mem (mem_atBot x) (mem_atBot z)) fun _ ⟨hyx, hyz⟩ => lt_of_le_not_ge hyx fun hxy => hz (hxy.trans hyz) theorem eventually_ge_atTop [Preorder α] (a : α) : ∀ᶠ x in atTop, a ≤ x := mem_atTop a theorem eventually_le_atBot [Preorder α] (a : α) : ∀ᶠ x in atBot, x ≤ a := mem_atBot a theorem eventually_gt_atTop [Preorder α] [NoTopOrder α] (a : α) : ∀ᶠ x in atTop, a < x := Ioi_mem_atTop a theorem eventually_ne_atTop [Preorder α] [NoTopOrder α] (a : α) : ∀ᶠ x in atTop, x ≠ a := (eventually_gt_atTop a).mono fun _ => ne_of_gt theorem eventually_lt_atBot [Preorder α] [NoBotOrder α] (a : α) : ∀ᶠ x in atBot, x < a := Iio_mem_atBot a theorem eventually_ne_atBot [Preorder α] [NoBotOrder α] (a : α) : ∀ᶠ x in atBot, x ≠ a := (eventually_lt_atBot a).mono fun _ => ne_of_lt theorem _root_.IsTop.atTop_eq [Preorder α] {a : α} (ha : IsTop a) : atTop = 𝓟 (Ici a) := (iInf_le _ _).antisymm <| le_iInf fun b ↦ principal_mono.2 <| Ici_subset_Ici.2 <| ha b theorem _root_.IsBot.atBot_eq [Preorder α] {a : α} (ha : IsBot a) : atBot = 𝓟 (Iic a) := ha.toDual.atTop_eq theorem atTop_eq_generate_Ici [Preorder α] : atTop = generate (range (Ici (α := α))) := by simp only [generate_eq_biInf, atTop, iInf_range] theorem Frequently.forall_exists_of_atTop [Preorder α] {p : α → Prop} (h : ∃ᶠ x in atTop, p x) (a : α) : ∃ b ≥ a, p b := by rw [Filter.Frequently] at h contrapose! h exact (eventually_ge_atTop a).mono h theorem Frequently.forall_exists_of_atBot [Preorder α] {p : α → Prop} (h : ∃ᶠ x in atBot, p x) (a : α) : ∃ b ≤ a, p b := Frequently.forall_exists_of_atTop (α := αᵒᵈ) h _ lemma atTop_eq_generate_of_forall_exists_le [Preorder α] {s : Set α} (hs : ∀ x, ∃ y ∈ s, x ≤ y) : (atTop : Filter α) = generate (Ici '' s) := by rw [atTop_eq_generate_Ici] apply le_antisymm · rw [le_generate_iff] rintro - ⟨y, -, rfl⟩ exact mem_generate_of_mem ⟨y, rfl⟩ · rw [le_generate_iff] rintro - ⟨x, -, -, rfl⟩ rcases hs x with ⟨y, ys, hy⟩ have A : Ici y ∈ generate (Ici '' s) := mem_generate_of_mem (mem_image_of_mem _ ys) have B : Ici y ⊆ Ici x := Ici_subset_Ici.2 hy exact sets_of_superset (generate (Ici '' s)) A B lemma atTop_eq_generate_of_not_bddAbove [LinearOrder α] {s : Set α} (hs : ¬ BddAbove s) : (atTop : Filter α) = generate (Ici '' s) := by refine atTop_eq_generate_of_forall_exists_le fun x ↦ ?_ obtain ⟨y, hy, hy'⟩ := not_bddAbove_iff.mp hs x exact ⟨y, hy, hy'.le⟩ end Filter open Filter theorem Monotone.piecewise_eventually_eq_iUnion {β : α → Type*} [Preorder ι] {s : ι → Set α} [∀ i, DecidablePred (· ∈ s i)] [DecidablePred (· ∈ ⋃ i, s i)] (hs : Monotone s) (f g : (a : α) → β a) (a : α) : ∀ᶠ i in atTop, (s i).piecewise f g a = (⋃ i, s i).piecewise f g a := by rcases em (∃ i, a ∈ s i) with ⟨i, hi⟩ | ha · refine (eventually_ge_atTop i).mono fun j hij ↦ ?_ simp only [Set.piecewise_eq_of_mem, hs hij hi, subset_iUnion _ _ hi] · filter_upwards with i simp only [Set.piecewise_eq_of_notMem, not_exists.1 ha i, mt mem_iUnion.1 ha, not_false_eq_true] theorem Antitone.piecewise_eventually_eq_iInter {β : α → Type*} [Preorder ι] {s : ι → Set α} [∀ i, DecidablePred (· ∈ s i)] [DecidablePred (· ∈ ⋂ i, s i)] (hs : Antitone s) (f g : (a : α) → β a) (a : α) : ∀ᶠ i in atTop, (s i).piecewise f g a = (⋂ i, s i).piecewise f g a := by classical convert ← (compl_anti.comp hs).piecewise_eventually_eq_iUnion g f a using 3 · convert congr_fun (Set.piecewise_compl (s _) g f) a · simp only [(· ∘ ·), ← compl_iInter, Set.piecewise_compl]
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Floor.lean
import Mathlib.Algebra.Order.Floor.Semiring import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Filter.AtTopBot.Finite import Mathlib.Tactic.Positivity.Basic /-! # `a * c ^ n < (n - d)!` holds true for sufficiently large `n`. -/ open Filter open scoped Nat variable {K : Type*} [Ring K] [LinearOrder K] [IsStrictOrderedRing K] [FloorSemiring K] theorem FloorSemiring.eventually_mul_pow_lt_factorial_sub (a c : K) (d : ℕ) : ∀ᶠ n in atTop, a * c ^ n < (n - d)! := by filter_upwards [Nat.eventually_mul_pow_lt_factorial_sub ⌈|a|⌉₊ ⌈|c|⌉₊ d] with n h calc a * c ^ n _ ≤ |a * c ^ n| := le_abs_self _ _ ≤ ⌈|a|⌉₊ * (⌈|c|⌉₊ : K) ^ n := ?_ _ = ↑(⌈|a|⌉₊ * ⌈|c|⌉₊ ^ n) := ?_ _ < (n - d)! := Nat.cast_lt.mpr h · rw [abs_mul, abs_pow] gcongr <;> try first | positivity | apply Nat.le_ceil · simp_rw [Nat.cast_mul, Nat.cast_pow]
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/BigOperators.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Preimage import Mathlib.Order.Filter.AtTopBot.Basic /-! # Two lemmas about limit of `Π b ∈ s, f b` along In this file we prove two auxiliary lemmas about `Filter.atTop : Filter (Finset _)` and `∏ b ∈ s, f b`. These lemmas are useful to build the theory of absolutely convergent series. -/ open Filter Finset variable {α β M : Type*} [CommMonoid M] /-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient condition for comparison of the filter `atTop.map (fun s ↦ ∏ b ∈ s, f b)` with `atTop.map (fun s ↦ ∏ b ∈ s, g b)`. This is useful to compare the set of limit points of `Π b in s, f b` as `s → atTop` with the similar set for `g`. -/ @[to_additive /-- Let `f` and `g` be two maps to the same commutative additive monoid. This lemma gives a sufficient condition for comparison of the filter `atTop.map (fun s ↦ ∑ b ∈ s, f b)` with `atTop.map (fun s ↦ ∑ b ∈ s, g b)`. This is useful to compare the set of limit points of `∑ b ∈ s, f b` as `s → atTop` with the similar set for `g`. -/] theorem Filter.map_atTop_finset_prod_le_of_prod_eq {f : α → M} {g : β → M} (h_eq : ∀ u : Finset β, ∃ v : Finset α, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) : (atTop.map fun s : Finset α => ∏ b ∈ s, f b) ≤ atTop.map fun s : Finset β => ∏ x ∈ s, g x := by classical refine ((atTop_basis.map _).le_basis_iff (atTop_basis.map _)).2 fun b _ => ?_ let ⟨v, hv⟩ := h_eq b refine ⟨v, trivial, ?_⟩ simpa [Finset.image_subset_iff] using hv /-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g` to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters `atTop.map (fun s ↦ ∏ i ∈ s, f (g i))` and `atTop.map (fun s ↦ ∏ i ∈ s, f i)` coincide. The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under the same assumptions. -/ @[to_additive] theorem Function.Injective.map_atTop_finset_prod_eq {g : α → β} (hg : Function.Injective g) {f : β → M} (hf : ∀ x, x ∉ Set.range g → f x = 1) : map (fun s => ∏ i ∈ s, f (g i)) atTop = map (fun s => ∏ i ∈ s, f i) atTop := by haveI := Classical.decEq β apply le_antisymm <;> refine map_atTop_finset_prod_le_of_prod_eq fun s => ?_ · refine ⟨s.preimage g hg.injOn, fun t ht => ?_⟩ refine ⟨t.image g ∪ s, Finset.subset_union_right, ?_⟩ rw [← Finset.prod_image hg.injOn] refine (prod_subset subset_union_left ?_).symm simp only [Finset.mem_union, Finset.mem_image] refine fun y hy hyt => hf y (mt ?_ hyt) rintro ⟨x, rfl⟩ exact ⟨x, ht (Finset.mem_preimage.2 <| hy.resolve_left hyt), rfl⟩ · refine ⟨s.image g, fun t ht => ?_⟩ simp only [← prod_preimage _ _ hg.injOn _ fun x _ => hf x] exact ⟨_, (image_subset_iff_subset_preimage _).1 ht, rfl⟩ /-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g` to an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the filters `atTop.map (fun s ↦ ∑ i ∈ s, f (g i))` and `atTop.map (fun s ↦ ∑ i ∈ s, f i)` coincide. This lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under the same assumptions. -/ add_decl_doc Function.Injective.map_atTop_finset_sum_eq
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/Field.lean
import Mathlib.Algebra.Field.Defs import Mathlib.Order.Filter.AtTopBot.Ring /-! # Convergence to ±infinity in linear ordered (semi)fields -/ namespace Filter variable {α β : Type*} section LinearOrderedSemifield variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {l : Filter β} {f : β → α} {r c : α} {n : ℕ} /-! ### Multiplication by constant: iff lemmas -/ /-- If `r` is a positive constant, `fun x ↦ r * f x` tends to infinity along a filter if and only if `f` tends to infinity along the same filter. -/ theorem tendsto_const_mul_atTop_of_pos (hr : 0 < r) : Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atTop := ⟨fun h => h.atTop_of_const_mul₀ hr, fun h => Tendsto.atTop_of_const_mul₀ (inv_pos.2 hr) <| by simpa only [inv_mul_cancel_left₀ hr.ne'] ⟩ /-- If `r` is a positive constant, `fun x ↦ f x * r` tends to infinity along a filter if and only if `f` tends to infinity along the same filter. -/ theorem tendsto_mul_const_atTop_of_pos (hr : 0 < r) : Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atTop := by simpa only [mul_comm] using tendsto_const_mul_atTop_of_pos hr /-- If `r` is a positive constant, `x ↦ f x / r` tends to infinity along a filter if and only if `f` tends to infinity along the same filter. -/ lemma tendsto_div_const_atTop_of_pos (hr : 0 < r) : Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atTop := by simpa only [div_eq_mul_inv] using tendsto_mul_const_atTop_of_pos (inv_pos.2 hr) /-- If `f` tends to infinity along a nontrivial filter `l`, then `fun x ↦ r * f x` tends to infinity if and only if `0 < r`. -/ theorem tendsto_const_mul_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atTop ↔ 0 < r := by refine ⟨fun hrf => not_le.mp fun hr => ?_, fun hr => (tendsto_const_mul_atTop_of_pos hr).mpr h⟩ rcases ((h.eventually_ge_atTop 0).and (hrf.eventually_gt_atTop 0)).exists with ⟨x, hx, hrx⟩ exact (mul_nonpos_of_nonpos_of_nonneg hr hx).not_gt hrx /-- If `f` tends to infinity along a nontrivial filter `l`, then `fun x ↦ f x * r` tends to infinity if and only if `0 < r`. -/ theorem tendsto_mul_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atTop ↔ 0 < r := by simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_pos h] /-- If `f` tends to infinity along a nontrivial filter `l`, then `x ↦ f x * r` tends to infinity if and only if `0 < r`. -/ lemma tendsto_div_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r := by simp only [div_eq_mul_inv, tendsto_mul_const_atTop_iff_pos h, inv_pos] /-- If `f` tends to infinity along a filter, then `f` multiplied by a positive constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use `Filter.Tendsto.const_mul_atTop'` instead. -/ theorem Tendsto.const_mul_atTop (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atTop := (tendsto_const_mul_atTop_of_pos hr).2 hf /-- If a function `f` tends to infinity along a filter, then `f` multiplied by a positive constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use `Filter.Tendsto.atTop_mul_const'` instead. -/ theorem Tendsto.atTop_mul_const (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atTop := (tendsto_mul_const_atTop_of_pos hr).2 hf /-- If a function `f` tends to infinity along a filter, then `f` divided by a positive constant also tends to infinity. -/ theorem Tendsto.atTop_div_const (hr : 0 < r) (hf : Tendsto f l atTop) : Tendsto (fun x => f x / r) l atTop := by simpa only [div_eq_mul_inv] using hf.atTop_mul_const (inv_pos.2 hr) theorem tendsto_const_mul_pow_atTop (hn : n ≠ 0) (hc : 0 < c) : Tendsto (fun x => c * x ^ n) atTop atTop := Tendsto.const_mul_atTop hc (tendsto_pow_atTop hn) theorem tendsto_const_mul_pow_atTop_iff : Tendsto (fun x => c * x ^ n) atTop atTop ↔ n ≠ 0 ∧ 0 < c := by refine ⟨fun h => ⟨?_, ?_⟩, fun h => tendsto_const_mul_pow_atTop h.1 h.2⟩ · rintro rfl simp only [pow_zero, not_tendsto_const_atTop] at h · rcases ((h.eventually_gt_atTop 0).and (eventually_ge_atTop 0)).exists with ⟨k, hck, hk⟩ exact pos_of_mul_pos_left hck (pow_nonneg hk _) lemma tendsto_zpow_atTop_atTop {n : ℤ} (hn : 0 < n) : Tendsto (fun x : α ↦ x ^ n) atTop atTop := by lift n to ℕ using hn.le; simp [(Int.natCast_pos.mp hn).ne'] theorem map_div_atTop_eq (k : α) (hk : 0 < k) : map (fun a => a / k) atTop = atTop := map_atTop_eq_of_gc (fun b => k * b) 1 (fun _ _ h => div_le_div_of_nonneg_right h (le_of_lt hk)) (fun a b _ => (by rw [div_le_iff₀' hk])) fun b _ => (by rw [mul_div_assoc, mul_div_cancel₀]; exact ne_of_gt hk) end LinearOrderedSemifield section LinearOrderedField variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {l : Filter β} {f : β → α} {r : α} /-- If `r` is a positive constant, `fun x ↦ r * f x` tends to negative infinity along a filter if and only if `f` tends to negative infinity along the same filter. -/ theorem tendsto_const_mul_atBot_of_pos (hr : 0 < r) : Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atBot := by simpa only [← mul_neg, ← tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos hr /-- If `r` is a positive constant, `fun x ↦ f x * r` tends to negative infinity along a filter if and only if `f` tends to negative infinity along the same filter. -/ theorem tendsto_mul_const_atBot_of_pos (hr : 0 < r) : Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atBot := by simpa only [mul_comm] using tendsto_const_mul_atBot_of_pos hr /-- If `r` is a positive constant, `fun x ↦ f x / r` tends to negative infinity along a filter if and only if `f` tends to negative infinity along the same filter. -/ lemma tendsto_div_const_atBot_of_pos (hr : 0 < r) : Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atBot := by simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_pos, hr] /-- If `r` is a negative constant, `fun x ↦ r * f x` tends to infinity along a filter `l` if and only if `f` tends to negative infinity along `l`. -/ theorem tendsto_const_mul_atTop_of_neg (hr : r < 0) : Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atBot := by simpa only [neg_mul, tendsto_neg_atBot_iff] using tendsto_const_mul_atBot_of_pos (neg_pos.2 hr) /-- If `r` is a negative constant, `fun x ↦ f x * r` tends to infinity along a filter `l` if and only if `f` tends to negative infinity along `l`. -/ theorem tendsto_mul_const_atTop_of_neg (hr : r < 0) : Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atBot := by simpa only [mul_comm] using tendsto_const_mul_atTop_of_neg hr /-- If `r` is a negative constant, `fun x ↦ f x / r` tends to infinity along a filter `l` if and only if `f` tends to negative infinity along `l`. -/ lemma tendsto_div_const_atTop_of_neg (hr : r < 0) : Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atBot := by simp [div_eq_mul_inv, tendsto_mul_const_atTop_of_neg, hr] /-- If `r` is a negative constant, `fun x ↦ r * f x` tends to negative infinity along a filter `l` if and only if `f` tends to infinity along `l`. -/ theorem tendsto_const_mul_atBot_of_neg (hr : r < 0) : Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atTop := by simpa only [neg_mul, tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos (neg_pos.2 hr) /-- If `r` is a negative constant, `fun x ↦ f x * r` tends to negative infinity along a filter `l` if and only if `f` tends to infinity along `l`. -/ theorem tendsto_mul_const_atBot_of_neg (hr : r < 0) : Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atTop := by simpa only [mul_comm] using tendsto_const_mul_atBot_of_neg hr /-- If `r` is a negative constant, `fun x ↦ f x / r` tends to negative infinity along a filter `l` if and only if `f` tends to infinity along `l`. -/ lemma tendsto_div_const_atBot_of_neg (hr : r < 0) : Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atTop := by simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_neg, hr] /-- The function `fun x ↦ r * f x` tends to infinity along a nontrivial filter if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/ theorem tendsto_const_mul_atTop_iff [NeBot l] : Tendsto (fun x => r * f x) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by rcases lt_trichotomy r 0 with (hr | rfl | hr) · simp [hr, hr.not_gt, tendsto_const_mul_atTop_of_neg] · simp [not_tendsto_const_atTop] · simp [hr, hr.not_gt, tendsto_const_mul_atTop_of_pos] /-- The function `fun x ↦ f x * r` tends to infinity along a nontrivial filter if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/ theorem tendsto_mul_const_atTop_iff [NeBot l] : Tendsto (fun x => f x * r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by simp only [mul_comm _ r, tendsto_const_mul_atTop_iff] /-- The function `fun x ↦ f x / r` tends to infinity along a nontrivial filter if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/ lemma tendsto_div_const_atTop_iff [NeBot l] : Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff] /-- The function `fun x ↦ r * f x` tends to negative infinity along a nontrivial filter if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/ theorem tendsto_const_mul_atBot_iff [NeBot l] : Tendsto (fun x => r * f x) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by simp only [← tendsto_neg_atTop_iff, ← mul_neg, tendsto_const_mul_atTop_iff, neg_neg] /-- The function `fun x ↦ f x * r` tends to negative infinity along a nontrivial filter if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/ theorem tendsto_mul_const_atBot_iff [NeBot l] : Tendsto (fun x => f x * r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by simp only [mul_comm _ r, tendsto_const_mul_atBot_iff] /-- The function `fun x ↦ f x / r` tends to negative infinity along a nontrivial filter if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/ lemma tendsto_div_const_atBot_iff [NeBot l] : Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff] /-- If `f` tends to negative infinity along a nontrivial filter `l`, then `fun x ↦ r * f x` tends to infinity if and only if `r < 0`. -/ theorem tendsto_const_mul_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) : Tendsto (fun x => r * f x) l atTop ↔ r < 0 := by simp [tendsto_const_mul_atTop_iff, h, h.not_tendsto disjoint_atBot_atTop] /-- If `f` tends to negative infinity along a nontrivial filter `l`, then `fun x ↦ f x * r` tends to infinity if and only if `r < 0`. -/ theorem tendsto_mul_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atTop ↔ r < 0 := by simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_neg h] /-- If `f` tends to negative infinity along a nontrivial filter `l`, then `fun x ↦ f x / r` tends to infinity if and only if `r < 0`. -/ lemma tendsto_div_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) : Tendsto (fun x ↦ f x / r) l atTop ↔ r < 0 := by simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff_neg h] /-- If `f` tends to negative infinity along a nontrivial filter `l`, then `fun x ↦ r * f x` tends to negative infinity if and only if `0 < r`. -/ theorem tendsto_const_mul_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) : Tendsto (fun x => r * f x) l atBot ↔ 0 < r := by simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atBot_atTop] /-- If `f` tends to negative infinity along a nontrivial filter `l`, then `fun x ↦ f x * r` tends to negative infinity if and only if `0 < r`. -/ theorem tendsto_mul_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atBot ↔ 0 < r := by simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_pos h] /-- If `f` tends to negative infinity along a nontrivial filter `l`, then `fun x ↦ f x / r` tends to negative infinity if and only if `0 < r`. -/ lemma tendsto_div_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) : Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r := by simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_pos h] /-- If `f` tends to infinity along a nontrivial filter, `fun x ↦ r * f x` tends to negative infinity if and only if `r < 0`. -/ theorem tendsto_const_mul_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atBot ↔ r < 0 := by simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atTop_atBot] /-- If `f` tends to infinity along a nontrivial filter, `fun x ↦ f x * r` tends to negative infinity if and only if `r < 0`. -/ theorem tendsto_mul_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atBot ↔ r < 0 := by simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_neg h] /-- If `f` tends to infinity along a nontrivial filter, `fun x ↦ f x / r` tends to negative infinity if and only if `r < 0`. -/ lemma tendsto_div_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) : Tendsto (fun x ↦ f x / r) l atBot ↔ r < 0 := by simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_neg h] /-- If a function `f` tends to infinity along a filter, then `f` multiplied by a negative constant (on the left) tends to negative infinity. -/ theorem Tendsto.const_mul_atTop_of_neg (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x => r * f x) l atBot := (tendsto_const_mul_atBot_of_neg hr).2 hf /-- If a function `f` tends to infinity along a filter, then `f` multiplied by a negative constant (on the right) tends to negative infinity. -/ theorem Tendsto.atTop_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * r) l atBot := (tendsto_mul_const_atBot_of_neg hr).2 hf /-- If a function `f` tends to infinity along a filter, then `f` divided by a negative constant tends to negative infinity. -/ lemma Tendsto.atTop_div_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) : Tendsto (fun x ↦ f x / r) l atBot := (tendsto_div_const_atBot_of_neg hr).2 hf /-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by a positive constant (on the left) also tends to negative infinity. -/ theorem Tendsto.const_mul_atBot (hr : 0 < r) (hf : Tendsto f l atBot) : Tendsto (fun x => r * f x) l atBot := (tendsto_const_mul_atBot_of_pos hr).2 hf /-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by a positive constant (on the right) also tends to negative infinity. -/ theorem Tendsto.atBot_mul_const (hr : 0 < r) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atBot := (tendsto_mul_const_atBot_of_pos hr).2 hf /-- If a function `f` tends to negative infinity along a filter, then `f` divided by a positive constant also tends to negative infinity. -/ theorem Tendsto.atBot_div_const (hr : 0 < r) (hf : Tendsto f l atBot) : Tendsto (fun x => f x / r) l atBot := (tendsto_div_const_atBot_of_pos hr).2 hf /-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by a negative constant (on the left) tends to positive infinity. -/ theorem Tendsto.const_mul_atBot_of_neg (hr : r < 0) (hf : Tendsto f l atBot) : Tendsto (fun x => r * f x) l atTop := (tendsto_const_mul_atTop_of_neg hr).2 hf /-- If a function tends to negative infinity along a filter, then `f` multiplied by a negative constant (on the right) tends to positive infinity. -/ theorem Tendsto.atBot_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * r) l atTop := (tendsto_mul_const_atTop_of_neg hr).2 hf theorem tendsto_neg_const_mul_pow_atTop {c : α} {n : ℕ} (hn : n ≠ 0) (hc : c < 0) : Tendsto (fun x => c * x ^ n) atTop atBot := (tendsto_pow_atTop hn).const_mul_atTop_of_neg hc theorem tendsto_const_mul_pow_atBot_iff {c : α} {n : ℕ} : Tendsto (fun x => c * x ^ n) atTop atBot ↔ n ≠ 0 ∧ c < 0 := by simp only [← tendsto_neg_atTop_iff, ← neg_mul, tendsto_const_mul_pow_atTop_iff, neg_pos] end LinearOrderedField end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/AtTopBot/CompleteLattice.lean
import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.AtTopBot.Tendsto /-! # `Filter.atTop` and `Filter.atBot` in (conditionally) complete lattices -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace Filter @[nontriviality] theorem Subsingleton.atTop_eq (α) [Subsingleton α] [Preorder α] : (atTop : Filter α) = ⊤ := by refine top_unique fun s hs x => ?_ rw [atTop, ciInf_subsingleton x, mem_principal] at hs exact hs left_mem_Ici @[nontriviality] theorem Subsingleton.atBot_eq (α) [Subsingleton α] [Preorder α] : (atBot : Filter α) = ⊤ := @Subsingleton.atTop_eq αᵒᵈ _ _ /-- If `f` is a monotone function with bounded range and `g` tends to `atTop` along a nontrivial filter, then the indexed supremum of `f ∘ g` is equal to the indexed supremum of `f`. The assumption `BddAbove (range f)` can be omitted, if the codomain of `f` is a conditionally complete linear order or a complete lattice, see below. -/ theorem _root_.Monotone.ciSup_comp_tendsto_atTop [Preorder β] [ConditionallyCompleteLattice γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) (hb : BddAbove (range f)) {g : α → β} (hg : Tendsto g l atTop) : ⨆ a, f (g a) = ⨆ b, f b := by have : Nonempty α := nonempty_of_neBot l have : Nonempty β := .map g ‹_› rw [← csInf_upperBounds_range, ← csInf_upperBounds_range, ← hf.upperBounds_range_comp_tendsto_atTop hg, Function.comp_def] exacts [hb, hb.mono <| range_comp_subset_range _ _] /-- If `f` is a monotone function with bounded range and `g` tends to `atBot` along a nontrivial filter, then the indexed infimum of `f ∘ g` is equal to the indexed infimum of `f`. The assumption `BddBelow (range f)` can be omitted, if the codomain of `f` is a conditionally complete linear order or a complete lattice, see below. -/ theorem _root_.Monotone.ciInf_comp_tendsto_atBot [Preorder β] [ConditionallyCompleteLattice γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) (hb : BddBelow (range f)) {g : α → β} (hg : Tendsto g l atBot) : ⨅ a, f (g a) = ⨅ b, f b := hf.dual.ciSup_comp_tendsto_atTop hb hg /-- If `f` is an antitone function with bounded range and `g` tends to `atBot` along a nontrivial filter, then the indexed supremum of `f ∘ g` is equal to the indexed supremum of `f`. The assumption `BddAbove (range f)` can be omitted, if the codomain of `f` is a conditionally complete linear order or a complete lattice, see below. -/ theorem _root_.Antitone.ciSup_comp_tendsto_atBot [Preorder β] [ConditionallyCompleteLattice γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) (hb : BddAbove (range f)) {g : α → β} (hg : Tendsto g l atBot) : ⨆ a, f (g a) = ⨆ b, f b := hf.dual_left.ciSup_comp_tendsto_atTop hb hg /-- If `f` is an antitone function with bounded range and `g` tends to `atTop` along a nontrivial filter, then the indexed infimum of `f ∘ g` is equal to the indexed infimum of `f`. The assumption `BddBelow (range f)` can be omitted, if the codomain of `f` is a conditionally complete linear order or a complete lattice, see below. -/ theorem _root_.Antitone.ciInf_comp_tendsto_atTop [Preorder β] [ConditionallyCompleteLattice γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) (hb : BddBelow (range f)) {g : α → β} (hg : Tendsto g l atTop) : ⨅ a, f (g a) = ⨅ b, f b := hf.dual.ciSup_comp_tendsto_atBot hb hg /-- If `f` is a monotone function taking values in a conditionally complete linear order and `g` tends to `atTop` along a nontrivial filter, then the indexed supremum of `f ∘ g` is equal to the indexed supremum of `f`. -/ theorem _root_.Monotone.ciSup_comp_tendsto_atTop_of_linearOrder [Preorder β] [ConditionallyCompleteLinearOrder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) {g : α → β} (hg : Tendsto g l atTop) : ⨆ a, f (g a) = ⨆ b, f b := by if hb : BddAbove (range f) then exact hf.ciSup_comp_tendsto_atTop hb hg else rw [iSup, iSup, csSup_of_not_bddAbove, csSup_of_not_bddAbove hb] rwa [BddAbove, ← Function.comp_def f g, hf.upperBounds_range_comp_tendsto_atTop hg] /-- If `f` is a monotone function taking values in a conditionally complete linear order and `g` tends to `atBot` along a nontrivial filter, then the indexed infimum of `f ∘ g` is equal to the indexed infimum of `f`. -/ theorem _root_.Monotone.ciInf_comp_tendsto_atBot_of_linearOrder [Preorder β] [ConditionallyCompleteLinearOrder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) {g : α → β} (hg : Tendsto g l atBot) : ⨅ a, f (g a) = ⨅ b, f b := hf.dual.ciSup_comp_tendsto_atTop_of_linearOrder hg /-- If `f` is an antitone function taking values in a conditionally complete linear order and `g` tends to `atTop` along a nontrivial filter, then the indexed infimum of `f ∘ g` is equal to the indexed infimum of `f`. -/ theorem _root_.Antitone.ciInf_comp_tendsto_atTop_of_linearOrder [Preorder β] [ConditionallyCompleteLinearOrder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) {g : α → β} (hg : Tendsto g l atTop) : ⨅ a, f (g a) = ⨅ b, f b := hf.dual_left.ciInf_comp_tendsto_atBot_of_linearOrder hg /-- If `f` is an antitone function taking values in a conditionally complete linear order and `g` tends to `atBot` along a nontrivial filter, then the indexed supremum of `f ∘ g` is equal to the indexed supremum of `f`. -/ theorem _root_.Antitone.ciSup_comp_tendsto_atBot_of_linearOrder [Preorder β] [ConditionallyCompleteLinearOrder γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) {g : α → β} (hg : Tendsto g l atBot) : ⨆ a, f (g a) = ⨆ b, f b := hf.dual_left.ciSup_comp_tendsto_atTop_of_linearOrder hg /-- If `f` is a monotone function taking values in a complete lattice and `g` tends to `atTop` along a nontrivial filter, then the indexed supremum of `f ∘ g` is equal to the indexed supremum of `f`. -/ theorem _root_.Monotone.iSup_comp_tendsto_atTop [Preorder β] [ConditionallyCompleteLattice γ] [OrderTop γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) {g : α → β} (hg : Tendsto g l atTop) : ⨆ a, f (g a) = ⨆ b, f b := hf.ciSup_comp_tendsto_atTop (OrderTop.bddAbove _) hg /-- If `f` is a monotone function taking values in a complete lattice and `g` tends to `atBot` along a nontrivial filter, then the indexed infimum of `f ∘ g` is equal to the indexed infimum of `f`. -/ theorem _root_.Monotone.iInf_comp_tendsto_atBot [Preorder β] [ConditionallyCompleteLattice γ] [OrderBot γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Monotone f) {g : α → β} (hg : Tendsto g l atBot) : ⨅ a, f (g a) = ⨅ b, f b := hf.ciInf_comp_tendsto_atBot (OrderBot.bddBelow _) hg /-- If `f` is an antitone function taking values in a complete lattice and `g` tends to `atBot` along a nontrivial filter, then the indexed supremum of `f ∘ g` is equal to the indexed supremum of `f`. -/ theorem _root_.Antitone.iSup_comp_tendsto_atBot [Preorder β] [ConditionallyCompleteLattice γ] [OrderTop γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) {g : α → β} (hg : Tendsto g l atBot) : ⨆ a, f (g a) = ⨆ b, f b := hf.ciSup_comp_tendsto_atBot (OrderTop.bddAbove _) hg /-- If `f` is an antitone function taking values in a complete lattice and `g` tends to `atTop` along a nontrivial filter, then the indexed infimum of `f ∘ g` is equal to the indexed infimum of `f`. -/ theorem _root_.Antitone.iInf_comp_tendsto_atTop [Preorder β] [ConditionallyCompleteLattice γ] [OrderBot γ] {l : Filter α} [l.NeBot] {f : β → γ} (hf : Antitone f) {g : α → β} (hg : Tendsto g l atTop) : ⨅ a, f (g a) = ⨅ b, f b := hf.ciInf_comp_tendsto_atTop (OrderBot.bddBelow _) hg /-- If `s` is a monotone family of sets and `f` tends to `atTop` along a nontrivial filter, then the indexed union of `s ∘ f` is equal to the indexed union of `s`. -/ theorem _root_.Monotone.iUnion_comp_tendsto_atTop [Preorder β] {l : Filter α} [l.NeBot] {s : β → Set γ} (hs : Monotone s) {f : α → β} (hf : Tendsto f l atTop) : ⋃ a, s (f a) = ⋃ b, s b := hs.iSup_comp_tendsto_atTop hf /-- If `s` is a monotone family of sets and `f` tends to `atBot` along a nontrivial filter, then the indexed intersection of `s ∘ f` is equal to the indexed intersection of `s`. -/ theorem _root_.Monotone.iInter_comp_tendsto_atBot [Preorder β] {l : Filter α} [l.NeBot] {s : β → Set γ} (hs : Monotone s) {f : α → β} (hf : Tendsto f l atBot) : ⋂ a, s (f a) = ⋂ b, s b := hs.iInf_comp_tendsto_atBot hf /-- If `s` is an antitone family of sets and `f` tends to `atTop` along a nontrivial filter, then the indexed intersection of `s ∘ f` is equal to the indexed intersection of `s`. -/ theorem _root_.Antitone.iInter_comp_tendsto_atTop [Preorder β] {l : Filter α} [l.NeBot] {s : β → Set γ} (hs : Antitone s) {f : α → β} (hf : Tendsto f l atTop) : ⋂ a, s (f a) = ⋂ b, s b := hs.iInf_comp_tendsto_atTop hf /-- If `s` is a monotone family of sets and `f` tends to `atBot` along a nontrivial filter, then the indexed union of `s ∘ f` is equal to the indexed union of `s`. -/ theorem _root_.Antitone.iUnion_comp_tendsto_atBot [Preorder β] {l : Filter α} [l.NeBot] {s : β → Set γ} (hs : Antitone s) {f : α → β} (hf : Tendsto f l atBot) : ⋃ a, s (f a) = ⋃ b, s b := hs.iSup_comp_tendsto_atBot hf end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Bases/Finite.lean
import Mathlib.Order.Filter.Bases.Basic import Mathlib.Order.Filter.Finite /-! # Finiteness results on filter bases A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ open Set Filter variable {α β γ : Type*} {ι ι' : Sort*} namespace Filter section SameType variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop} {s' : ι' → Set α} {i' : ι'} theorem hasBasis_generate (s : Set (Set α)) : (generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t := ⟨fun U => by simp only [mem_generate_iff, and_assoc, and_left_comm]⟩ /-- The smallest filter basis containing a given collection of sets. -/ def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where sets := sInter '' { t | Set.Finite t ∧ t ⊆ s } nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩ inter_sets := by rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩ exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩, (sInter_union _ _).subset⟩ lemma FilterBasis.ofSets_sets (s : Set (Set α)) : (FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } := rfl theorem generate_eq_generate_inter (s : Set (Set α)) : generate s = generate (sInter '' { t | Set.Finite t ∧ t ⊆ s }) := by rw [← FilterBasis.ofSets_sets, FilterBasis.generate, ← (hasBasis_generate s).filter_eq]; rfl theorem ofSets_filter_eq_generate (s : Set (Set α)) : (FilterBasis.ofSets s).filter = generate s := by rw [← (FilterBasis.ofSets s).generate, FilterBasis.ofSets_sets, ← generate_eq_generate_inter] theorem generate_neBot_iff {s : Set (Set α)} : NeBot (generate s) ↔ ∀ t, t ⊆ s → t.Finite → (⋂₀ t).Nonempty := (hasBasis_generate s).neBot_iff.trans <| by simp only [← and_imp, and_comm] protected theorem HasBasis.iInf' {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨅ i, l i).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i)) fun If : Set ι × ∀ i, ι' i => ⋂ i ∈ If.1, s i (If.2 i) := ⟨by intro t constructor · simp only [mem_iInf', (hl _).mem_iff] rintro ⟨I, hI, V, hV, -, rfl, -⟩ choose u hu using hV exact ⟨⟨I, u⟩, ⟨hI, fun i _ => (hu i).1⟩, iInter₂_mono fun i _ => (hu i).2⟩ · rintro ⟨⟨I, f⟩, ⟨hI₁, hI₂⟩, hsub⟩ refine mem_of_superset ?_ hsub exact (biInter_mem hI₁).mpr fun i hi => mem_iInf_of_mem i <| (hl i).mem_of_mem <| hI₂ _ hi⟩ @[deprecated (since := "2025-05-05")] alias hasBasis_iInf' := HasBasis.iInf' protected theorem HasBasis.iInf {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨅ i, l i).HasBasis (fun If : Σ I : Set ι, ∀ i : I, ι' i => If.1.Finite ∧ ∀ i : If.1, p i (If.2 i)) fun If => ⋂ i : If.1, s i (If.2 i) := by refine ⟨fun t => ⟨fun ht => ?_, ?_⟩⟩ · rcases (HasBasis.iInf' hl).mem_iff.mp ht with ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩ exact ⟨⟨I, fun i => f i⟩, ⟨hI, Subtype.forall.mpr hf⟩, trans (iInter_subtype _ _) hsub⟩ · rintro ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩ refine mem_of_superset ?_ hsub cases hI.nonempty_fintype exact iInter_mem.2 fun i => mem_iInf_of_mem ↑i <| (hl i).mem_of_mem <| hf _ @[deprecated (since := "2025-05-05")] alias hasBasis_iInf := HasBasis.iInf open scoped Function in -- required for scoped `on` notation theorem _root_.Pairwise.exists_mem_filter_basis_of_disjoint {I} [Finite I] {l : I → Filter α} {ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} (hd : Pairwise (Disjoint on l)) (h : ∀ i, (l i).HasBasis (p i) (s i)) : ∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ Pairwise (Disjoint on fun i => s i (ind i)) := by rcases hd.exists_mem_filter_of_disjoint with ⟨t, htl, hd⟩ choose ind hp ht using fun i => (h i).mem_iff.1 (htl i) exact ⟨ind, hp, hd.mono fun i j hij => hij.mono (ht _) (ht _)⟩ theorem _root_.Set.PairwiseDisjoint.exists_mem_filter_basis {I : Type*} {l : I → Filter α} {ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} {S : Set I} (hd : S.PairwiseDisjoint l) (hS : S.Finite) (h : ∀ i, (l i).HasBasis (p i) (s i)) : ∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ S.PairwiseDisjoint fun i => s i (ind i) := by rcases hd.exists_mem_filter hS with ⟨t, htl, hd⟩ choose ind hp ht using fun i => (h i).mem_iff.1 (htl i) exact ⟨ind, hp, hd.mono ht⟩ /-- If `s : ι → Set α` is an indexed family of sets, then finite intersections of `s i` form a basis of `⨅ i, 𝓟 (s i)`. -/ theorem hasBasis_iInf_principal_finite {ι : Type*} (s : ι → Set α) : (⨅ i, 𝓟 (s i)).HasBasis (fun t : Set ι => t.Finite) fun t => ⋂ i ∈ t, s i := by refine ⟨fun U => (mem_iInf_finite _).trans ?_⟩ simp only [iInf_principal_finset, mem_principal, exists_finite_iff_finset, Finset.set_biInter_coe] end SameType end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Bases/Basic.lean
import Mathlib.Data.Set.Sigma import Mathlib.Order.Filter.Defs import Mathlib.Order.Filter.Map import Mathlib.Order.Interval.Set.Basic /-! # Basic results on filter bases A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. Compared to filters, filter bases do not require that any set containing an element of `B` belongs to `B`. A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs to `B.filter` if and only if it contains an element of `B`. Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`, the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p` (i.e. `s '' setOf p`) defines a filter basis `h.filterBasis`. If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop` and `s : ι → Set α` as above) means that a set belongs to `l` if and only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and `l = h.filterBasis.filter`. The point of this definition is that checking statements involving elements of `l` often reduces to checking them on the basis elements. We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual destruction of `h.mem_iff.mpr ht` using `cases` or `let`. ## Main statements * `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in terms of a basis; * `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate `l ≤ l'` in terms of bases. * `Filter.basis_sets` : all sets of a filter form a basis; * `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`, `Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f` respectively; * `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`, `Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases. ## Implementation notes As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases: * `Filter.HasBasis l s`, `s : Set (Set α)`; * `Filter.HasBasis l s`, `s : ι → Set α`; * `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`. We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`. With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis` machinery, e.g., `simp only [true_and_iff]` or `simp only [forall_const]` can help with the case `p = fun _ ↦ True`. ## Main statements -/ assert_not_exists Finset open Set Filter variable {α β γ : Type*} {ι ι' : Sort*} /-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ structure FilterBasis (α : Type*) where /-- Sets of a filter basis. -/ sets : Set (Set α) /-- The set of filter basis sets is nonempty. -/ nonempty : sets.Nonempty /-- The set of filter basis sets is directed downwards. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets := B.nonempty.to_subtype /-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as on paper. -/ instance {α : Type*} : Membership (Set α) (FilterBasis α) := ⟨fun B U => U ∈ B.sets⟩ @[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl -- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)` instance : Inhabited (FilterBasis ℕ) := ⟨{ sets := range Ici nonempty := ⟨Ici 0, mem_range_self 0⟩ inter_sets := by rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩ /-- View a filter as a filter basis. -/ def Filter.asBasis (f : Filter α) : FilterBasis α := ⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩ -- TODO: consider adding `protected`? /-- `IsBasis p s` means the image of `s` bounded by `p` is a filter basis. -/ structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where /-- There exists at least one `i` that satisfies `p`. -/ nonempty : ∃ i, p i /-- `s` is directed downwards on `i` such that `p i`. -/ inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j namespace Filter namespace IsBasis /-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/ protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where sets := { t | ∃ i, p i ∧ s i = t } nonempty := let ⟨i, hi⟩ := h.nonempty ⟨s i, ⟨i, hi, rfl⟩⟩ inter_sets := by rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩ rcases h.inter hi hj with ⟨k, hk, hk'⟩ exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩ variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U := Iff.rfl end IsBasis end Filter namespace FilterBasis /-- The filter associated to a filter basis. -/ protected def filter (B : FilterBasis α) : Filter α where sets := { s | ∃ t ∈ B, t ⊆ s } univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩ sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩ inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ => let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in ⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩ theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U := Iff.rfl theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in => ⟨U, U_in, Subset.refl _⟩ theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by rintro ⟨U, U_in⟩ ⟨V, V_in⟩ rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩ use ⟨W, W_in⟩ simp only [le_principal_iff, mem_principal] exact subset_inter_iff.mp W_sub ext U simp [mem_filter_iff, mem_iInf_of_directed this] protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by apply le_antisymm · intro U U_in rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩ exact GenerateSets.superset (GenerateSets.basic V_in) h · rw [le_generate_iff] apply mem_filter_of_mem lemma ker_filter (F : FilterBasis α) : F.filter.ker = ⋂₀ F.sets := by aesop (add simp [ker, FilterBasis.filter]) end FilterBasis namespace Filter namespace IsBasis variable {p : ι → Prop} {s : ι → Set α} /-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/ protected def filter (h : IsBasis p s) : Filter α := h.filterBasis.filter protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} : U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff, exists_exists_and_eq_and] theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by rw [IsBasis.filter, ← h.filterBasis.generate, IsBasis.filterBasis] end IsBasis -- TODO: consider adding `protected`? /-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`, if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/ structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where /-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/ mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t section SameType variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop} {s' : ι' → Set α} {i' : ι'} /-- Definition of `HasBasis` unfolded with implicit set argument. -/ theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := hl.mem_iff' t theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by ext t rw [hl.mem_iff, hl'.mem_iff] theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i := (h.mem_iff.mp univ_mem).imp fun _ => And.left protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι := h.ex_mem.nonempty protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s := ⟨fun t => by simp only [h.mem_filter_iff]⟩ protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) : t ∈ l := hl.mem_iff.2 ⟨i, hi, ht⟩ theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l := hl.mem_of_superset hi Subset.rfl /-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/ noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } := ⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩ theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) := (h.index t ht).2 theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l := h.mem_of_mem <| h.property_index _ theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t := (h.mem_iff.1 ht).choose_spec.2 theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where nonempty := h.ex_mem inter hi hj := by simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj) theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by ext U simp [h.mem_iff, IsBasis.mem_filter_iff] theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by rw [← h.isBasis.filter_eq_generate, h.filter_eq] protected theorem _root_.FilterBasis.hasBasis (B : FilterBasis α) : HasBasis B.filter (fun s : Set α => s ∈ B) id := ⟨fun _ => B.mem_filter_iff⟩ theorem HasBasis.to_hasBasis' (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → s' i' ∈ l) : l.HasBasis p' s' := by refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i', hi', ht⟩ => mem_of_superset (h' i' hi') ht⟩⟩ rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩ rcases h i hi with ⟨i', hi', hs's⟩ exact ⟨i', hi', hs's.trans ht⟩ theorem HasBasis.to_hasBasis (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.HasBasis p' s' := hl.to_hasBasis' h fun i' hi' => let ⟨i, hi, hss'⟩ := h' i' hi' hl.mem_iff.2 ⟨i, hi, hss'⟩ protected lemma HasBasis.congr (hl : l.HasBasis p s) {p' s'} (hp : ∀ i, p i ↔ p' i) (hs : ∀ i, p i → s i = s' i) : l.HasBasis p' s' := ⟨fun t ↦ by simp only [hl.mem_iff, ← hp]; exact exists_congr fun i ↦ and_congr_right fun hi ↦ hs i hi ▸ Iff.rfl⟩ theorem HasBasis.to_subset (hl : l.HasBasis p s) {t : ι → Set α} (h : ∀ i, p i → t i ⊆ s i) (ht : ∀ i, p i → t i ∈ l) : l.HasBasis p t := hl.to_hasBasis' (fun i hi => ⟨i, hi, h i hi⟩) ht theorem HasBasis.eventually_iff (hl : l.HasBasis p s) {q : α → Prop} : (∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x := by simpa using hl.mem_iff theorem HasBasis.frequently_iff (hl : l.HasBasis p s) {q : α → Prop} : (∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x := by simp only [Filter.Frequently, hl.eventually_iff]; push_neg; rfl theorem HasBasis.exists_iff (hl : l.HasBasis p s) {P : Set α → Prop} (mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) : (∃ s ∈ l, P s) ↔ ∃ i, p i ∧ P (s i) := ⟨fun ⟨_s, hs, hP⟩ => let ⟨i, hi, his⟩ := hl.mem_iff.1 hs ⟨i, hi, mono his hP⟩, fun ⟨i, hi, hP⟩ => ⟨s i, hl.mem_of_mem hi, hP⟩⟩ theorem HasBasis.forall_iff (hl : l.HasBasis p s) {P : Set α → Prop} (mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) : (∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) := ⟨fun H i hi => H (s i) <| hl.mem_of_mem hi, fun H _s hs => let ⟨i, hi, his⟩ := hl.mem_iff.1 hs mono his (H i hi)⟩ protected theorem HasBasis.neBot_iff (hl : l.HasBasis p s) : NeBot l ↔ ∀ {i}, p i → (s i).Nonempty := forall_mem_nonempty_iff_neBot.symm.trans <| hl.forall_iff fun _ _ => Nonempty.mono theorem HasBasis.eq_bot_iff (hl : l.HasBasis p s) : l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ := not_iff_not.1 <| neBot_iff.symm.trans <| hl.neBot_iff.trans <| by simp only [not_exists, not_and, nonempty_iff_ne_empty] theorem basis_sets (l : Filter α) : l.HasBasis (fun s : Set α => s ∈ l) id := ⟨fun _ => exists_mem_subset_iff.symm⟩ theorem asBasis_filter (f : Filter α) : f.asBasis.filter = f := Filter.ext fun _ => exists_mem_subset_iff theorem hasBasis_self {l : Filter α} {P : Set α → Prop} : HasBasis l (fun s => s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t := by simp only [hasBasis_iff, id, and_assoc] exact forall_congr' fun s => ⟨fun h => h.1, fun h => ⟨h, fun ⟨t, hl, _, hts⟩ => mem_of_superset hl hts⟩⟩ theorem HasBasis.comp_surjective (h : l.HasBasis p s) {g : ι' → ι} (hg : Function.Surjective g) : l.HasBasis (p ∘ g) (s ∘ g) := ⟨fun _ => h.mem_iff.trans hg.exists⟩ theorem HasBasis.comp_equiv (h : l.HasBasis p s) (e : ι' ≃ ι) : l.HasBasis (p ∘ e) (s ∘ e) := h.comp_surjective e.surjective theorem HasBasis.to_image_id' (h : l.HasBasis p s) : l.HasBasis (fun t ↦ ∃ i, p i ∧ s i = t) id := ⟨fun _ ↦ by simp [h.mem_iff]⟩ theorem HasBasis.to_image_id {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) : l.HasBasis (· ∈ s '' {i | p i}) id := h.to_image_id' /-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that `p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/ theorem HasBasis.restrict (h : l.HasBasis p s) {q : ι → Prop} (hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) : l.HasBasis (fun i => p i ∧ q i) s := by refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i, hpi, hti⟩ => h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩ rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩ rcases hq i hpi with ⟨j, hpj, hqj, hji⟩ exact ⟨j, ⟨hpj, hqj⟩, hji.trans hti⟩ /-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}` is a basis of `l`. -/ theorem HasBasis.restrict_subset (h : l.HasBasis p s) {V : Set α} (hV : V ∈ l) : l.HasBasis (fun i => p i ∧ s i ⊆ V) s := h.restrict fun _i hi => (h.mem_iff.1 (inter_mem hV (h.mem_of_mem hi))).imp fun _j hj => ⟨hj.1, subset_inter_iff.1 hj.2⟩ theorem HasBasis.hasBasis_self_subset {p : Set α → Prop} (h : l.HasBasis (fun s => s ∈ l ∧ p s) id) {V : Set α} (hV : V ∈ l) : l.HasBasis (fun s => s ∈ l ∧ p s ∧ s ⊆ V) id := by simpa only [and_assoc] using h.restrict_subset hV theorem HasBasis.ge_iff (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l := ⟨fun h _i' hi' => h <| hl'.mem_of_mem hi', fun h _s hs => let ⟨_i', hi', hs⟩ := hl'.mem_iff.1 hs mem_of_superset (h _ hi') hs⟩ theorem HasBasis.le_iff (hl : l.HasBasis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i, p i ∧ s i ⊆ t := by simp only [le_def, hl.mem_iff] theorem HasBasis.le_basis_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i' := by simp only [hl'.ge_iff, hl.mem_iff] theorem HasBasis.ext (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l = l' := by apply le_antisymm · rw [hl.le_basis_iff hl'] simpa using h' · rw [hl'.le_basis_iff hl] simpa using h theorem HasBasis.inf' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊓ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 := ⟨by intro t constructor · simp only [mem_inf_iff, hl.mem_iff, hl'.mem_iff] rintro ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, rfl⟩ exact ⟨⟨i, i'⟩, ⟨hi, hi'⟩, inter_subset_inter ht ht'⟩ · rintro ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩ exact mem_inf_of_inter (hl.mem_of_mem hi) (hl'.mem_of_mem hi') H⟩ theorem HasBasis.inf {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop} {s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊓ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 := (hl.inf' hl').comp_equiv Equiv.pprodEquivProd.symm theorem hasBasis_iInf_of_directed' {ι : Type*} {ι' : ι → Sort _} [Nonempty ι] {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i)) (h : Directed (· ≥ ·) l) : (⨅ i, l i).HasBasis (fun ii' : Σ i, ι' i => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_iInf_of_directed h, Sigma.exists] exact exists_congr fun i => (hl i).mem_iff theorem hasBasis_iInf_of_directed {ι : Type*} {ι' : Sort _} [Nonempty ι] {l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i)) (h : Directed (· ≥ ·) l) : (⨅ i, l i).HasBasis (fun ii' : ι × ι' => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_iInf_of_directed h, Prod.exists] exact exists_congr fun i => (hl i).mem_iff theorem hasBasis_biInf_of_directed' {ι : Type*} {ι' : ι → Sort _} {dom : Set ι} (hdom : dom.Nonempty) {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) : (⨅ i ∈ dom, l i).HasBasis (fun ii' : Σ i, ι' i => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_biInf_of_directed h hdom, Sigma.exists] refine exists_congr fun i => ⟨?_, ?_⟩ · rintro ⟨hi, hti⟩ rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩ exact ⟨b, ⟨hi, hb⟩, hbt⟩ · rintro ⟨b, ⟨hi, hb⟩, hibt⟩ exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩ theorem hasBasis_biInf_of_directed {ι : Type*} {ι' : Sort _} {dom : Set ι} (hdom : dom.Nonempty) {l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) : (⨅ i ∈ dom, l i).HasBasis (fun ii' : ι × ι' => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_biInf_of_directed h hdom, Prod.exists] refine exists_congr fun i => ⟨?_, ?_⟩ · rintro ⟨hi, hti⟩ rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩ exact ⟨b, ⟨hi, hb⟩, hbt⟩ · rintro ⟨b, ⟨hi, hb⟩, hibt⟩ exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩ lemma hasBasis_top : (⊤ : Filter α).HasBasis (fun _ : Unit ↦ True) (fun _ ↦ Set.univ) := ⟨fun U => by simp⟩ theorem hasBasis_principal (t : Set α) : (𝓟 t).HasBasis (fun _ : Unit => True) fun _ => t := ⟨fun U => by simp⟩ theorem hasBasis_pure (x : α) : (pure x : Filter α).HasBasis (fun _ : Unit => True) fun _ => {x} := by simp only [← principal_singleton, hasBasis_principal] theorem HasBasis.sup' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊔ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 := ⟨by intro t simp_rw [mem_sup, hl.mem_iff, hl'.mem_iff, PProd.exists, union_subset_iff, ← exists_and_right, ← exists_and_left] simp only [and_assoc, and_left_comm]⟩ theorem HasBasis.sup {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop} {s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊔ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 := (hl.sup' hl').comp_equiv Equiv.pprodEquivProd.symm theorem hasBasis_iSup {ι : Sort*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨆ i, l i).HasBasis (fun f : ∀ i, ι' i => ∀ i, p i (f i)) fun f : ∀ i, ι' i => ⋃ i, s i (f i) := hasBasis_iff.mpr fun t => by simp only [(hl _).mem_iff, Classical.skolem, forall_and, iUnion_subset_iff, mem_iSup] theorem HasBasis.sup_principal (hl : l.HasBasis p s) (t : Set α) : (l ⊔ 𝓟 t).HasBasis p fun i => s i ∪ t := ⟨fun u => by simp only [(hl.sup' (hasBasis_principal t)).mem_iff, PProd.exists, and_true, Unique.exists_iff]⟩ theorem HasBasis.sup_pure (hl : l.HasBasis p s) (x : α) : (l ⊔ pure x).HasBasis p fun i => s i ∪ {x} := by simp only [← principal_singleton, hl.sup_principal] theorem HasBasis.inf_principal (hl : l.HasBasis p s) (s' : Set α) : (l ⊓ 𝓟 s').HasBasis p fun i => s i ∩ s' := ⟨fun t => by simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_setOf_eq, mem_inter_iff, and_imp]⟩ theorem HasBasis.principal_inf (hl : l.HasBasis p s) (s' : Set α) : (𝓟 s' ⊓ l).HasBasis p fun i => s' ∩ s i := by simpa only [inf_comm, inter_comm] using hl.inf_principal s' theorem HasBasis.inf_basis_neBot_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃i'⦄, p' i' → (s i ∩ s' i').Nonempty := (hl.inf' hl').neBot_iff.trans <| by simp [@forall_swap _ ι'] theorem HasBasis.inf_neBot_iff (hl : l.HasBasis p s) : NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃s'⦄, s' ∈ l' → (s i ∩ s').Nonempty := hl.inf_basis_neBot_iff l'.basis_sets theorem HasBasis.inf_principal_neBot_iff (hl : l.HasBasis p s) {t : Set α} : NeBot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄, p i → (s i ∩ t).Nonempty := (hl.inf_principal t).neBot_iff theorem HasBasis.disjoint_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : Disjoint l l' ↔ ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') := not_iff_not.mp <| by simp only [_root_.disjoint_iff, ← Ne.eq_def, ← neBot_iff, inf_eq_inter, hl.inf_basis_neBot_iff hl', not_exists, not_and, bot_eq_empty, ← nonempty_iff_ne_empty] theorem _root_.Disjoint.exists_mem_filter_basis (h : Disjoint l l') (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') := (hl.disjoint_iff hl').1 h theorem inf_neBot_iff : NeBot (l ⊓ l') ↔ ∀ ⦃s : Set α⦄, s ∈ l → ∀ ⦃s'⦄, s' ∈ l' → (s ∩ s').Nonempty := l.basis_sets.inf_neBot_iff theorem inf_principal_neBot_iff {s : Set α} : NeBot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).Nonempty := l.basis_sets.inf_principal_neBot_iff theorem mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ := by refine not_iff_not.1 ((inf_principal_neBot_iff.trans ?_).symm.trans neBot_iff) exact ⟨fun h hs => by simpa [Set.not_nonempty_empty] using h s hs, fun hs t ht => inter_compl_nonempty_iff.2 fun hts => hs <| mem_of_superset ht hts⟩ theorem notMem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∉ f ↔ NeBot (f ⊓ 𝓟 sᶜ) := (not_congr mem_iff_inf_principal_compl).trans neBot_iff.symm @[deprecated (since := "2025-05-23")] alias not_mem_iff_inf_principal_compl := notMem_iff_inf_principal_compl @[simp] theorem disjoint_principal_right {f : Filter α} {s : Set α} : Disjoint f (𝓟 s) ↔ sᶜ ∈ f := by rw [mem_iff_inf_principal_compl, compl_compl, disjoint_iff] @[simp] theorem disjoint_principal_left {f : Filter α} {s : Set α} : Disjoint (𝓟 s) f ↔ sᶜ ∈ f := by rw [disjoint_comm, disjoint_principal_right] @[simp high] -- This should fire before `disjoint_principal_left` and `disjoint_principal_right`. theorem disjoint_principal_principal {s t : Set α} : Disjoint (𝓟 s) (𝓟 t) ↔ Disjoint s t := by rw [← subset_compl_iff_disjoint_left, disjoint_principal_left, mem_principal] alias ⟨_, _root_.Disjoint.filter_principal⟩ := disjoint_principal_principal @[simp] theorem disjoint_pure_pure {x y : α} : Disjoint (pure x : Filter α) (pure y) ↔ x ≠ y := by simp only [← principal_singleton, disjoint_principal_principal, disjoint_singleton] theorem HasBasis.disjoint_iff_left (h : l.HasBasis p s) : Disjoint l l' ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := by simp only [h.disjoint_iff l'.basis_sets, id, ← disjoint_principal_left, (hasBasis_principal _).disjoint_iff l'.basis_sets, true_and, Unique.exists_iff] theorem HasBasis.disjoint_iff_right (h : l.HasBasis p s) : Disjoint l' l ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := disjoint_comm.trans h.disjoint_iff_left theorem le_iff_forall_inf_principal_compl {f g : Filter α} : f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ := forall₂_congr fun _ _ => mem_iff_inf_principal_compl theorem inf_neBot_iff_frequently_left {f g : Filter α} : NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x := by simp only [inf_neBot_iff, frequently_iff, and_comm]; rfl theorem inf_neBot_iff_frequently_right {f g : Filter α} : NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x := by rw [inf_comm] exact inf_neBot_iff_frequently_left theorem HasBasis.eq_biInf (h : l.HasBasis p s) : l = ⨅ (i) (_ : p i), 𝓟 (s i) := eq_biInf_of_mem_iff_exists_mem fun {_} => by simp only [h.mem_iff, mem_principal] theorem HasBasis.eq_iInf (h : l.HasBasis (fun _ => True) s) : l = ⨅ i, 𝓟 (s i) := by simpa only [iInf_true] using h.eq_biInf theorem hasBasis_iInf_principal {s : ι → Set α} (h : Directed (· ≥ ·) s) [Nonempty ι] : (⨅ i, 𝓟 (s i)).HasBasis (fun _ => True) s := ⟨fun t => by simpa only [true_and] using mem_iInf_of_directed (h.mono_comp _ monotone_principal.dual) t⟩ theorem hasBasis_biInf_principal {s : β → Set α} {S : Set β} (h : DirectedOn (s ⁻¹'o (· ≥ ·)) S) (ne : S.Nonempty) : (⨅ i ∈ S, 𝓟 (s i)).HasBasis (fun i => i ∈ S) s := ⟨fun t => by refine mem_biInf_of_directed ?_ ne rw [directedOn_iff_directed, ← directed_comp] at h ⊢ refine h.mono_comp _ ?_ exact fun _ _ => principal_mono.2⟩ theorem hasBasis_biInf_principal' {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : ∀ i, p i → ∀ j, p j → ∃ k, p k ∧ s k ⊆ s i ∧ s k ⊆ s j) (ne : ∃ i, p i) : (⨅ (i) (_ : p i), 𝓟 (s i)).HasBasis p s := Filter.hasBasis_biInf_principal h ne theorem HasBasis.map (f : α → β) (hl : l.HasBasis p s) : (l.map f).HasBasis p fun i => f '' s i := ⟨fun t => by simp only [mem_map, image_subset_iff, hl.mem_iff, preimage]⟩ theorem HasBasis.comap (f : β → α) (hl : l.HasBasis p s) : (l.comap f).HasBasis p fun i => f ⁻¹' s i := ⟨fun t => by simp only [mem_comap', hl.mem_iff] refine exists_congr (fun i => Iff.rfl.and ?_) exact ⟨fun h x hx => h hx rfl, fun h y hy x hx => h <| by rwa [mem_preimage, hx]⟩⟩ theorem comap_hasBasis (f : α → β) (l : Filter β) : HasBasis (comap f l) (fun s : Set β => s ∈ l) fun s => f ⁻¹' s := ⟨fun _ => mem_comap⟩ theorem HasBasis.forall_mem_mem (h : HasBasis l p s) {x : α} : (∀ t ∈ l, x ∈ t) ↔ ∀ i, p i → x ∈ s i := by simp only [h.mem_iff, exists_imp, and_imp] exact ⟨fun h i hi => h (s i) i hi Subset.rfl, fun h t i hi ht => ht (h i hi)⟩ protected theorem HasBasis.biInf_mem [CompleteLattice β] {f : Set α → β} (h : HasBasis l p s) (hf : Monotone f) : ⨅ t ∈ l, f t = ⨅ (i) (_ : p i), f (s i) := le_antisymm (le_iInf₂ fun i hi => iInf₂_le (s i) (h.mem_of_mem hi)) <| le_iInf₂ fun _t ht => let ⟨i, hpi, hi⟩ := h.mem_iff.1 ht iInf₂_le_of_le i hpi (hf hi) protected theorem HasBasis.biInter_mem {f : Set α → Set β} (h : HasBasis l p s) (hf : Monotone f) : ⋂ t ∈ l, f t = ⋂ (i) (_ : p i), f (s i) := h.biInf_mem hf protected theorem HasBasis.ker (h : HasBasis l p s) : l.ker = ⋂ (i) (_ : p i), s i := sInter_eq_biInter.trans <| h.biInter_mem monotone_id variable {ι'' : Type*} [Preorder ι''] (l) (s'' : ι'' → Set α) /-- `IsAntitoneBasis s` means the image of `s` is a filter basis such that `s` is decreasing. -/ structure IsAntitoneBasis : Prop extends IsBasis (fun _ => True) s'' where /-- The sequence of sets is antitone. -/ protected antitone : Antitone s'' /-- We say that a filter `l` has an antitone basis `s : ι → Set α`, if `t ∈ l` if and only if `t` includes `s i` for some `i`, and `s` is decreasing. -/ structure HasAntitoneBasis (l : Filter α) (s : ι'' → Set α) : Prop extends HasBasis l (fun _ => True) s where /-- The sequence of sets is antitone. -/ protected antitone : Antitone s protected theorem HasAntitoneBasis.map {l : Filter α} {s : ι'' → Set α} (hf : HasAntitoneBasis l s) (m : α → β) : HasAntitoneBasis (map m l) (m '' s ·) := ⟨HasBasis.map _ hf.toHasBasis, fun _ _ h => image_mono <| hf.2 h⟩ protected theorem HasAntitoneBasis.comap {l : Filter α} {s : ι'' → Set α} (hf : HasAntitoneBasis l s) (m : β → α) : HasAntitoneBasis (comap m l) (m ⁻¹' s ·) := ⟨hf.1.comap _, fun _ _ h ↦ preimage_mono (hf.2 h)⟩ lemma HasAntitoneBasis.iInf_principal {ι : Type*} [Preorder ι] [Nonempty ι] [IsDirected ι (· ≤ ·)] {s : ι → Set α} (hs : Antitone s) : (⨅ i, 𝓟 (s i)).HasAntitoneBasis s := ⟨hasBasis_iInf_principal hs.directed_ge, hs⟩ end SameType section TwoTypes variable {la : Filter α} {pa : ι → Prop} {sa : ι → Set α} {lb : Filter β} {pb : ι' → Prop} {sb : ι' → Set β} {f : α → β} theorem HasBasis.tendsto_left_iff (hla : la.HasBasis pa sa) : Tendsto f la lb ↔ ∀ t ∈ lb, ∃ i, pa i ∧ MapsTo f (sa i) t := by simp only [Tendsto, (hla.map f).le_iff, image_subset_iff] rfl theorem HasBasis.tendsto_right_iff (hlb : lb.HasBasis pb sb) : Tendsto f la lb ↔ ∀ i, pb i → ∀ᶠ x in la, f x ∈ sb i := by simp only [Tendsto, hlb.ge_iff, mem_map', Filter.Eventually] theorem HasBasis.tendsto_iff (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) : Tendsto f la lb ↔ ∀ ib, pb ib → ∃ ia, pa ia ∧ ∀ x ∈ sa ia, f x ∈ sb ib := by simp [hlb.tendsto_right_iff, hla.eventually_iff] theorem Tendsto.basis_left (H : Tendsto f la lb) (hla : la.HasBasis pa sa) : ∀ t ∈ lb, ∃ i, pa i ∧ MapsTo f (sa i) t := hla.tendsto_left_iff.1 H theorem Tendsto.basis_right (H : Tendsto f la lb) (hlb : lb.HasBasis pb sb) : ∀ i, pb i → ∀ᶠ x in la, f x ∈ sb i := hlb.tendsto_right_iff.1 H theorem Tendsto.basis_both (H : Tendsto f la lb) (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) : ∀ ib, pb ib → ∃ ia, pa ia ∧ MapsTo f (sa ia) (sb ib) := (hla.tendsto_iff hlb).1 H theorem HasBasis.prod_pprod (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) : (la ×ˢ lb).HasBasis (fun i : PProd ι ι' => pa i.1 ∧ pb i.2) fun i => sa i.1 ×ˢ sb i.2 := (hla.comap Prod.fst).inf' (hlb.comap Prod.snd) theorem HasBasis.prod {ι ι' : Type*} {pa : ι → Prop} {sa : ι → Set α} {pb : ι' → Prop} {sb : ι' → Set β} (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) : (la ×ˢ lb).HasBasis (fun i : ι × ι' => pa i.1 ∧ pb i.2) fun i => sa i.1 ×ˢ sb i.2 := (hla.comap Prod.fst).inf (hlb.comap Prod.snd) protected theorem HasBasis.principal_prod (sa : Set α) (h : lb.HasBasis pb sb) : (𝓟 sa ×ˢ lb).HasBasis pb (sa ×ˢ sb ·) := by simpa only [prod_eq_inf, comap_principal, prod_eq] using (h.comap Prod.snd).principal_inf _ protected theorem HasBasis.prod_principal (h : la.HasBasis pa sa) (sb : Set β) : (la ×ˢ 𝓟 sb).HasBasis pa (sa · ×ˢ sb) := by simpa only [prod_eq_inf, comap_principal, prod_eq] using (h.comap Prod.fst).inf_principal _ protected theorem HasBasis.top_prod (h : lb.HasBasis pb sb) : (⊤ ×ˢ lb : Filter (α × β)).HasBasis pb (univ ×ˢ sb ·) := by simpa only [principal_univ] using h.principal_prod univ protected theorem HasBasis.prod_top (h : la.HasBasis pa sa) : (la ×ˢ ⊤ : Filter (α × β)).HasBasis pa (sa · ×ˢ univ) := by simpa only [principal_univ] using h.prod_principal univ theorem HasBasis.prod_same_index {p : ι → Prop} {sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb) (h_dir : ∀ {i j}, p i → p j → ∃ k, p k ∧ sa k ⊆ sa i ∧ sb k ⊆ sb j) : (la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i := by simp only [hasBasis_iff, (hla.prod_pprod hlb).mem_iff] refine fun t => ⟨?_, ?_⟩ · rintro ⟨⟨i, j⟩, ⟨hi, hj⟩, hsub : sa i ×ˢ sb j ⊆ t⟩ rcases h_dir hi hj with ⟨k, hk, ki, kj⟩ exact ⟨k, hk, (Set.prod_mono ki kj).trans hsub⟩ · rintro ⟨i, hi, h⟩ exact ⟨⟨i, i⟩, ⟨hi, hi⟩, h⟩ theorem HasBasis.prod_same_index_mono {ι : Type*} [LinearOrder ι] {p : ι → Prop} {sa : ι → Set α} {sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb) (hsa : MonotoneOn sa { i | p i }) (hsb : MonotoneOn sb { i | p i }) : (la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i := hla.prod_same_index hlb fun {i j} hi hj => have : p (min i j) := min_rec' _ hi hj ⟨min i j, this, hsa this hi <| min_le_left _ _, hsb this hj <| min_le_right _ _⟩ theorem HasBasis.prod_same_index_anti {ι : Type*} [LinearOrder ι] {p : ι → Prop} {sa : ι → Set α} {sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb) (hsa : AntitoneOn sa { i | p i }) (hsb : AntitoneOn sb { i | p i }) : (la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i := @HasBasis.prod_same_index_mono _ _ _ _ ιᵒᵈ _ _ _ _ hla hlb hsa.dual_left hsb.dual_left theorem HasBasis.prod_self (hl : la.HasBasis pa sa) : (la ×ˢ la).HasBasis pa fun i => sa i ×ˢ sa i := hl.prod_same_index hl fun {i j} hi hj => by simpa only [exists_prop, subset_inter_iff] using hl.mem_iff.1 (inter_mem (hl.mem_of_mem hi) (hl.mem_of_mem hj)) theorem mem_prod_self_iff {s} : s ∈ la ×ˢ la ↔ ∃ t ∈ la, t ×ˢ t ⊆ s := la.basis_sets.prod_self.mem_iff lemma eventually_prod_self_iff {r : α → α → Prop} : (∀ᶠ x in la ×ˢ la, r x.1 x.2) ↔ ∃ t ∈ la, ∀ x ∈ t, ∀ y ∈ t, r x y := mem_prod_self_iff.trans <| by simp only [prod_subset_iff, mem_setOf_eq] /-- A version of `eventually_prod_self_iff` that is more suitable for forward rewriting. -/ lemma eventually_prod_self_iff' {r : α × α → Prop} : (∀ᶠ x in la ×ˢ la, r x) ↔ ∃ t ∈ la, ∀ x ∈ t, ∀ y ∈ t, r (x, y) := Iff.symm eventually_prod_self_iff.symm theorem HasAntitoneBasis.prod {ι : Type*} [LinearOrder ι] {f : Filter α} {g : Filter β} {s : ι → Set α} {t : ι → Set β} (hf : HasAntitoneBasis f s) (hg : HasAntitoneBasis g t) : HasAntitoneBasis (f ×ˢ g) fun n => s n ×ˢ t n := ⟨hf.1.prod_same_index_anti hg.1 (hf.2.antitoneOn _) (hg.2.antitoneOn _), hf.2.set_prod hg.2⟩ theorem HasBasis.coprod {ι ι' : Type*} {pa : ι → Prop} {sa : ι → Set α} {pb : ι' → Prop} {sb : ι' → Set β} (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) : (la.coprod lb).HasBasis (fun i : ι × ι' => pa i.1 ∧ pb i.2) fun i => Prod.fst ⁻¹' sa i.1 ∪ Prod.snd ⁻¹' sb i.2 := (hla.comap Prod.fst).sup (hlb.comap Prod.snd) end TwoTypes theorem map_sigma_mk_comap {π : α → Type*} {π' : β → Type*} {f : α → β} (hf : Function.Injective f) (g : ∀ a, π a → π' (f a)) (a : α) (l : Filter (π' (f a))) : map (Sigma.mk a) (comap (g a) l) = comap (Sigma.map f g) (map (Sigma.mk (f a)) l) := by refine (((basis_sets _).comap _).map _).eq_of_same_basis ?_ convert ((basis_sets l).map (Sigma.mk (f a))).comap (Sigma.map f g) apply image_sigmaMk_preimage_sigmaMap hf end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Ultrafilter/Basic.lean
import Mathlib.Order.Filter.Ultrafilter.Defs import Mathlib.Order.Filter.Cofinite import Mathlib.Order.ZornAtoms /-! # Ultrafilters An ultrafilter is a minimal (maximal in the set order) proper filter. In this file we define * `hyperfilter`: the ultrafilter extending the cofinite filter. -/ universe u v variable {α : Type u} {β : Type v} open Set Filter namespace Ultrafilter variable {f : Ultrafilter α} {s : Set α} theorem finite_sUnion_mem_iff {s : Set (Set α)} (hs : s.Finite) : ⋃₀ s ∈ f ↔ ∃ t ∈ s, t ∈ f := by induction s, hs using Set.Finite.induction_on with | empty => simp | insert _ _ his => simp [union_mem_iff, his, or_and_right, exists_or] theorem finite_biUnion_mem_iff {is : Set β} {s : β → Set α} (his : is.Finite) : (⋃ i ∈ is, s i) ∈ f ↔ ∃ i ∈ is, s i ∈ f := by simp only [← sUnion_image, finite_sUnion_mem_iff (his.image s), exists_mem_image] lemma eventually_exists_mem_iff {is : Set β} {P : β → α → Prop} (his : is.Finite) : (∀ᶠ i in f, ∃ a ∈ is, P a i) ↔ ∃ a ∈ is, ∀ᶠ i in f, P a i := by simp only [Filter.Eventually, Ultrafilter.mem_coe] convert f.finite_biUnion_mem_iff his (s := P) with i aesop lemma eventually_exists_iff [Finite β] {P : β → α → Prop} : (∀ᶠ i in f, ∃ a, P a i) ↔ ∃ a, ∀ᶠ i in f, P a i := by simpa using eventually_exists_mem_iff (f := f) (P := P) Set.finite_univ theorem eq_pure_of_finite_mem (h : s.Finite) (h' : s ∈ f) : ∃ x ∈ s, f = pure x := by rw [← biUnion_of_singleton s] at h' rcases (Ultrafilter.finite_biUnion_mem_iff h).mp h' with ⟨a, has, haf⟩ exact ⟨a, has, eq_of_le (Filter.le_pure_iff.2 haf)⟩ theorem eq_pure_of_finite [Finite α] (f : Ultrafilter α) : ∃ a, f = pure a := (eq_pure_of_finite_mem finite_univ univ_mem).imp fun _ ⟨_, ha⟩ => ha theorem le_cofinite_or_eq_pure (f : Ultrafilter α) : (f : Filter α) ≤ cofinite ∨ ∃ a, f = pure a := or_iff_not_imp_left.2 fun h => let ⟨_, hs, hfin⟩ := Filter.disjoint_cofinite_right.1 (disjoint_iff_not_le.2 h) let ⟨a, _, hf⟩ := eq_pure_of_finite_mem hfin hs ⟨a, hf⟩ theorem exists_ultrafilter_of_finite_inter_nonempty (S : Set (Set α)) (cond : ∀ T : Finset (Set α), (↑T : Set (Set α)) ⊆ S → (⋂₀ (↑T : Set (Set α))).Nonempty) : ∃ F : Ultrafilter α, S ⊆ F.sets := haveI : NeBot (generate S) := generate_neBot_iff.2 fun _ hts ht => ht.coe_toFinset ▸ cond ht.toFinset (ht.coe_toFinset.symm ▸ hts) ⟨of (generate S), fun _ ht => (of_le <| generate S) <| GenerateSets.basic ht⟩ end Ultrafilter namespace Filter open Ultrafilter lemma atTop_eq_pure_of_isTop [PartialOrder α] {x : α} (hx : IsTop x) : (atTop : Filter α) = pure x := {top := x, le_top := hx : OrderTop α}.atTop_eq lemma atBot_eq_pure_of_isBot [PartialOrder α] {x : α} (hx : IsBot x) : (atBot : Filter α) = pure x := @atTop_eq_pure_of_isTop αᵒᵈ _ _ hx /-- The `tendsto` relation can be checked on ultrafilters. -/ theorem tendsto_iff_ultrafilter (f : α → β) (l₁ : Filter α) (l₂ : Filter β) : Tendsto f l₁ l₂ ↔ ∀ g : Ultrafilter α, ↑g ≤ l₁ → Tendsto f g l₂ := by simpa only [tendsto_iff_comap] using le_iff_ultrafilter section Hyperfilter variable (α) [Infinite α] /-- The ultrafilter extending the cofinite filter. -/ noncomputable def hyperfilter : Ultrafilter α := Ultrafilter.of cofinite variable {α} theorem hyperfilter_le_cofinite : ↑(hyperfilter α) ≤ @cofinite α := Ultrafilter.of_le cofinite theorem _root_.Nat.hyperfilter_le_atTop : (hyperfilter ℕ).toFilter ≤ atTop := hyperfilter_le_cofinite.trans_eq Nat.cofinite_eq_atTop @[simp] theorem bot_ne_hyperfilter : (⊥ : Filter α) ≠ hyperfilter α := (NeBot.ne inferInstance).symm theorem notMem_hyperfilter_of_finite {s : Set α} (hf : s.Finite) : s ∉ hyperfilter α := fun hy => compl_notMem hy <| hyperfilter_le_cofinite hf.compl_mem_cofinite @[deprecated (since := "2025-05-24")] alias nmem_hyperfilter_of_finite := notMem_hyperfilter_of_finite alias _root_.Set.Finite.notMem_hyperfilter := notMem_hyperfilter_of_finite @[deprecated (since := "2025-05-24")] alias _root_.Set.Finite.nmem_hyperfilter := _root_.Set.Finite.notMem_hyperfilter theorem compl_mem_hyperfilter_of_finite {s : Set α} (hf : Set.Finite s) : sᶜ ∈ hyperfilter α := compl_mem_iff_notMem.2 hf.notMem_hyperfilter alias _root_.Set.Finite.compl_mem_hyperfilter := compl_mem_hyperfilter_of_finite theorem mem_hyperfilter_of_finite_compl {s : Set α} (hf : Set.Finite sᶜ) : s ∈ hyperfilter α := compl_compl s ▸ hf.compl_mem_hyperfilter end Hyperfilter end Filter
.lake/packages/mathlib/Mathlib/Order/Filter/Ultrafilter/Defs.lean
import Mathlib.Order.Filter.Map import Mathlib.Order.ZornAtoms /-! # Ultrafilters An ultrafilter is a minimal (maximal in the set order) proper filter. In this file we define * `Ultrafilter.of`: an ultrafilter that is less than or equal to a given filter; * `Ultrafilter`: subtype of ultrafilters; * `pure x : Ultrafilter α`: `pure x` as an `Ultrafilter`; * `Ultrafilter.map`, `Ultrafilter.bind`, `Ultrafilter.comap` : operations on ultrafilters; -/ assert_not_exists Set.Finite universe u v variable {α : Type u} {β : Type v} {γ : Type*} open Set Filter Function /-- `Filter α` is an atomic type: for every filter there exists an ultrafilter that is less than or equal to this filter. -/ instance : IsAtomic (Filter α) := IsAtomic.of_isChain_bounded fun c hc hne hb => ⟨sInf c, (sInf_neBot_of_directed' hne (show IsChain (· ≥ ·) c from hc.symm).directedOn hb).ne, fun _ hx => sInf_le hx⟩ /-- An ultrafilter is a minimal (maximal in the set order) proper filter. -/ structure Ultrafilter (α : Type*) extends Filter α where /-- An ultrafilter is nontrivial. -/ protected neBot' : NeBot toFilter /-- If `g` is a nontrivial filter that is less than or equal to an ultrafilter, then it is greater than or equal to the ultrafilter. -/ protected le_of_le : ∀ g, Filter.NeBot g → g ≤ toFilter → toFilter ≤ g namespace Ultrafilter variable {f g : Ultrafilter α} {s t : Set α} {p q : α → Prop} attribute [coe] Ultrafilter.toFilter instance : CoeTC (Ultrafilter α) (Filter α) := ⟨Ultrafilter.toFilter⟩ instance : Membership (Set α) (Ultrafilter α) := ⟨fun f s => s ∈ (f : Filter α)⟩ theorem unique (f : Ultrafilter α) {g : Filter α} (h : g ≤ f) (hne : NeBot g := by infer_instance) : g = f := le_antisymm h <| f.le_of_le g hne h instance neBot (f : Ultrafilter α) : NeBot (f : Filter α) := f.neBot' protected theorem isAtom (f : Ultrafilter α) : IsAtom (f : Filter α) := ⟨f.neBot.ne, fun _ hgf => by_contra fun hg => hgf.ne <| f.unique hgf.le ⟨hg⟩⟩ @[simp, norm_cast] theorem mem_coe : s ∈ (f : Filter α) ↔ s ∈ f := Iff.rfl theorem coe_injective : Injective ((↑) : Ultrafilter α → Filter α) | ⟨f, h₁, h₂⟩, ⟨g, _, _⟩, _ => by congr theorem eq_of_le {f g : Ultrafilter α} (h : (f : Filter α) ≤ g) : f = g := coe_injective (g.unique h) @[simp, norm_cast] theorem coe_le_coe {f g : Ultrafilter α} : (f : Filter α) ≤ g ↔ f = g := ⟨fun h => eq_of_le h, fun h => h ▸ le_rfl⟩ @[simp, norm_cast] theorem coe_inj : (f : Filter α) = g ↔ f = g := coe_injective.eq_iff @[ext] theorem ext ⦃f g : Ultrafilter α⦄ (h : ∀ s, s ∈ f ↔ s ∈ g) : f = g := coe_injective <| Filter.ext h theorem le_of_inf_neBot (f : Ultrafilter α) {g : Filter α} (hg : NeBot (↑f ⊓ g)) : ↑f ≤ g := le_of_inf_eq (f.unique inf_le_left hg) theorem le_of_inf_neBot' (f : Ultrafilter α) {g : Filter α} (hg : NeBot (g ⊓ f)) : ↑f ≤ g := f.le_of_inf_neBot <| by rwa [inf_comm] theorem inf_neBot_iff {f : Ultrafilter α} {g : Filter α} : NeBot (↑f ⊓ g) ↔ ↑f ≤ g := ⟨le_of_inf_neBot f, fun h => (inf_of_le_left h).symm ▸ f.neBot⟩ theorem disjoint_iff_not_le {f : Ultrafilter α} {g : Filter α} : Disjoint (↑f) g ↔ ¬↑f ≤ g := by rw [← inf_neBot_iff, neBot_iff, Ne, not_not, disjoint_iff] @[simp] theorem compl_notMem_iff : sᶜ ∉ f ↔ s ∈ f := ⟨fun hsc => le_principal_iff.1 <| f.le_of_inf_neBot ⟨fun h => hsc <| mem_of_eq_bot <| by rwa [compl_compl]⟩, compl_notMem⟩ @[deprecated (since := "2025-05-23")] alias compl_not_mem_iff := compl_notMem_iff @[simp] theorem frequently_iff_eventually : (∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, p x := compl_notMem_iff alias ⟨_root_.Filter.Frequently.eventually, _⟩ := frequently_iff_eventually theorem compl_mem_iff_notMem : sᶜ ∈ f ↔ s ∉ f := by rw [← compl_notMem_iff, compl_compl] @[deprecated (since := "2025-05-23")] alias compl_mem_iff_not_mem := compl_mem_iff_notMem theorem diff_mem_iff (f : Ultrafilter α) : s \ t ∈ f ↔ s ∈ f ∧ t ∉ f := inter_mem_iff.trans <| and_congr Iff.rfl compl_mem_iff_notMem /-- If `sᶜ ∉ f ↔ s ∈ f`, then `f` is an ultrafilter. The other implication is given by `Ultrafilter.compl_notMem_iff`. -/ def ofComplNotMemIff (f : Filter α) (h : ∀ s, sᶜ ∉ f ↔ s ∈ f) : Ultrafilter α where toFilter := f neBot' := ⟨fun hf => by simp [hf] at h⟩ le_of_le _ _ hgf s hs := (h s).1 fun hsc => compl_notMem hs (hgf hsc) /-- If `f : Filter α` is an atom, then it is an ultrafilter. -/ def ofAtom (f : Filter α) (hf : IsAtom f) : Ultrafilter α where toFilter := f neBot' := ⟨hf.1⟩ le_of_le g hg := (isAtom_iff_le_of_ge.1 hf).2 g hg.ne theorem nonempty_of_mem (hs : s ∈ f) : s.Nonempty := Filter.nonempty_of_mem hs theorem ne_empty_of_mem (hs : s ∈ f) : s ≠ ∅ := (nonempty_of_mem hs).ne_empty @[simp] theorem empty_notMem : ∅ ∉ f := Filter.empty_notMem (f : Filter α) @[deprecated (since := "2025-05-23")] alias empty_not_mem := empty_notMem @[simp] theorem le_sup_iff {u : Ultrafilter α} {f g : Filter α} : ↑u ≤ f ⊔ g ↔ ↑u ≤ f ∨ ↑u ≤ g := not_iff_not.1 <| by simp only [← disjoint_iff_not_le, not_or, disjoint_sup_right] @[simp] theorem union_mem_iff : s ∪ t ∈ f ↔ s ∈ f ∨ t ∈ f := by simp only [← mem_coe, ← le_principal_iff, ← sup_principal, le_sup_iff] theorem mem_or_compl_mem (f : Ultrafilter α) (s : Set α) : s ∈ f ∨ sᶜ ∈ f := or_iff_not_imp_left.2 compl_mem_iff_notMem.2 protected theorem em (f : Ultrafilter α) (p : α → Prop) : (∀ᶠ x in f, p x) ∨ ∀ᶠ x in f, ¬p x := f.mem_or_compl_mem { x | p x } theorem eventually_or : (∀ᶠ x in f, p x ∨ q x) ↔ (∀ᶠ x in f, p x) ∨ ∀ᶠ x in f, q x := union_mem_iff theorem eventually_not : (∀ᶠ x in f, ¬p x) ↔ ¬∀ᶠ x in f, p x := compl_mem_iff_notMem theorem eventually_imp : (∀ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or, eventually_not] /-- Pushforward for ultrafilters. -/ nonrec def map (m : α → β) (f : Ultrafilter α) : Ultrafilter β := ofComplNotMemIff (map m f) fun s => @compl_notMem_iff _ f (m ⁻¹' s) @[simp, norm_cast] theorem coe_map (m : α → β) (f : Ultrafilter α) : (map m f : Filter β) = Filter.map m ↑f := rfl @[simp] theorem mem_map {m : α → β} {f : Ultrafilter α} {s : Set β} : s ∈ map m f ↔ m ⁻¹' s ∈ f := Iff.rfl @[simp] nonrec theorem map_id (f : Ultrafilter α) : f.map id = f := coe_injective map_id @[simp] theorem map_id' (f : Ultrafilter α) : (f.map fun x => x) = f := map_id _ @[simp] nonrec theorem map_map (f : Ultrafilter α) (m : α → β) (n : β → γ) : (f.map m).map n = f.map (n ∘ m) := coe_injective map_map /-- The pullback of an ultrafilter along an injection whose range is large with respect to the given ultrafilter. -/ nonrec def comap {m : α → β} (u : Ultrafilter β) (inj : Injective m) (large : Set.range m ∈ u) : Ultrafilter α where toFilter := comap m u neBot' := u.neBot'.comap_of_range_mem large le_of_le g hg hgu := by simp only [← u.unique (map_le_iff_le_comap.2 hgu), comap_map inj, le_rfl] @[simp] theorem mem_comap {m : α → β} (u : Ultrafilter β) (inj : Injective m) (large : Set.range m ∈ u) {s : Set α} : s ∈ u.comap inj large ↔ m '' s ∈ u := mem_comap_iff inj large @[simp, norm_cast] theorem coe_comap {m : α → β} (u : Ultrafilter β) (inj : Injective m) (large : Set.range m ∈ u) : (u.comap inj large : Filter α) = Filter.comap m u := rfl @[simp] nonrec theorem comap_id (f : Ultrafilter α) (h₀ : Injective (id : α → α) := injective_id) (h₁ : range id ∈ f := (by rw [range_id]; exact univ_mem)) : f.comap h₀ h₁ = f := coe_injective comap_id @[simp] nonrec theorem comap_comap (f : Ultrafilter γ) {m : α → β} {n : β → γ} (inj₀ : Injective n) (large₀ : range n ∈ f) (inj₁ : Injective m) (large₁ : range m ∈ f.comap inj₀ large₀) (inj₂ : Injective (n ∘ m) := inj₀.comp inj₁) (large₂ : range (n ∘ m) ∈ f := (by rw [range_comp]; exact image_mem_of_mem_comap large₀ large₁)) : (f.comap inj₀ large₀).comap inj₁ large₁ = f.comap inj₂ large₂ := coe_injective comap_comap /-- The principal ultrafilter associated to a point `x`. -/ instance : Pure Ultrafilter := ⟨fun a => ofComplNotMemIff (pure a) fun s => by simp⟩ @[simp] theorem mem_pure {a : α} {s : Set α} : s ∈ (pure a : Ultrafilter α) ↔ a ∈ s := Iff.rfl @[simp] theorem coe_pure (a : α) : ↑(pure a : Ultrafilter α) = (pure a : Filter α) := rfl @[simp] theorem map_pure (m : α → β) (a : α) : map m (pure a) = pure (m a) := rfl @[simp] theorem comap_pure {m : α → β} (a : α) (inj : Injective m) (large) : comap (pure <| m a) inj large = pure a := coe_injective <| Filter.comap_pure.trans <| by rw [coe_pure, ← principal_singleton, ← image_singleton, preimage_image_eq _ inj] theorem pure_injective : Injective (pure : α → Ultrafilter α) := fun _ _ h => Filter.pure_injective (congr_arg Ultrafilter.toFilter h :) instance [Inhabited α] : Inhabited (Ultrafilter α) := ⟨pure default⟩ instance [Nonempty α] : Nonempty (Ultrafilter α) := Nonempty.map pure inferInstance /-- Monadic bind for ultrafilters, coming from the one on filters defined in terms of map and join. -/ def bind (f : Ultrafilter α) (m : α → Ultrafilter β) : Ultrafilter β := ofComplNotMemIff (Filter.bind ↑f fun x => ↑(m x)) fun s => by simp only [mem_bind', mem_coe, ← compl_mem_iff_notMem, compl_setOf, compl_compl] instance instBind : Bind Ultrafilter := ⟨@Ultrafilter.bind⟩ instance functor : Functor Ultrafilter where map := @Ultrafilter.map instance monad : Monad Ultrafilter where map := @Ultrafilter.map section attribute [local instance] Filter.monad Filter.lawfulMonad instance lawfulMonad : LawfulMonad Ultrafilter where id_map f := coe_injective (id_map f.toFilter) pure_bind a f := coe_injective (Filter.pure_bind a ((Ultrafilter.toFilter) ∘ f)) bind_assoc _ _ _ := coe_injective (filter_eq rfl) bind_pure_comp f x := coe_injective (bind_pure_comp f x.1) map_const := rfl seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl pure_seq _ _ := rfl bind_map _ _ := rfl end /-- The ultrafilter lemma: Any proper filter is contained in an ultrafilter. -/ theorem exists_le (f : Filter α) [h : NeBot f] : ∃ u : Ultrafilter α, ↑u ≤ f := let ⟨u, hu, huf⟩ := (eq_bot_or_exists_atom_le f).resolve_left h.ne ⟨ofAtom u hu, huf⟩ alias _root_.Filter.exists_ultrafilter_le := exists_le /-- Construct an ultrafilter extending a given filter. The ultrafilter lemma is the assertion that such a filter exists; we use the axiom of choice to pick one. -/ noncomputable def of (f : Filter α) [NeBot f] : Ultrafilter α := Classical.choose (exists_le f) theorem of_le (f : Filter α) [NeBot f] : ↑(of f) ≤ f := Classical.choose_spec (exists_le f) theorem of_coe (f : Ultrafilter α) : of ↑f = f := coe_inj.1 <| f.unique (of_le f.toFilter) end Ultrafilter namespace Filter variable {f : Filter α} {s : Set α} {a : α} open Ultrafilter theorem isAtom_pure : IsAtom (pure a : Filter α) := (pure a : Ultrafilter α).isAtom protected theorem NeBot.le_pure_iff (hf : f.NeBot) : f ≤ pure a ↔ f = pure a := ⟨Ultrafilter.unique (pure a), le_of_eq⟩ protected theorem NeBot.eq_pure_iff (hf : f.NeBot) {x : α} : f = pure x ↔ {x} ∈ f := by rw [← hf.le_pure_iff, le_pure_iff] @[simp] theorem lt_pure_iff : f < pure a ↔ f = ⊥ := isAtom_pure.lt_iff theorem le_pure_iff' : f ≤ pure a ↔ f = ⊥ ∨ f = pure a := isAtom_pure.le_iff @[simp] theorem Iic_pure (a : α) : Iic (pure a : Filter α) = {⊥, pure a} := isAtom_pure.Iic_eq theorem mem_iff_ultrafilter : s ∈ f ↔ ∀ g : Ultrafilter α, ↑g ≤ f → s ∈ g := by refine ⟨fun hf g hg => hg hf, fun H => by_contra fun hf => ?_⟩ set g : Filter (sᶜ : Set α) := comap (↑) f haveI : NeBot g := comap_neBot_iff_compl_range.2 (by simpa [compl_setOf] ) simpa using H ((of g).map (↑)) (map_le_iff_le_comap.mpr (of_le g)) theorem le_iff_ultrafilter {f₁ f₂ : Filter α} : f₁ ≤ f₂ ↔ ∀ g : Ultrafilter α, ↑g ≤ f₁ → ↑g ≤ f₂ := ⟨fun h _ h₁ => h₁.trans h, fun h _ hs => mem_iff_ultrafilter.2 fun g hg => h g hg hs⟩ /-- A filter equals the intersection of all the ultrafilters which contain it. -/ theorem iSup_ultrafilter_le_eq (f : Filter α) : ⨆ (g : Ultrafilter α) (_ : g ≤ f), (g : Filter α) = f := eq_of_forall_ge_iff fun f' => by simp only [iSup_le_iff, ← le_iff_ultrafilter] theorem exists_ultrafilter_iff {f : Filter α} : (∃ u : Ultrafilter α, ↑u ≤ f) ↔ NeBot f := ⟨fun ⟨_, uf⟩ => neBot_of_le uf, fun h => @exists_ultrafilter_le _ _ h⟩ theorem forall_neBot_le_iff {g : Filter α} {p : Filter α → Prop} (hp : Monotone p) : (∀ f : Filter α, NeBot f → f ≤ g → p f) ↔ ∀ f : Ultrafilter α, ↑f ≤ g → p f := by refine ⟨fun H f hf => H f f.neBot hf, ?_⟩ intro H f hf hfg exact hp (of_le f) (H _ ((of_le f).trans hfg)) end Filter namespace Ultrafilter variable {m : α → β} {s : Set α} {g : Ultrafilter β} theorem comap_inf_principal_neBot_of_image_mem (h : m '' s ∈ g) : (Filter.comap m g ⊓ 𝓟 s).NeBot := Filter.comap_inf_principal_neBot_of_image_mem g.neBot h /-- Ultrafilter extending the inf of a comapped ultrafilter and a principal ultrafilter. -/ noncomputable def ofComapInfPrincipal (h : m '' s ∈ g) : Ultrafilter α := @of _ (Filter.comap m g ⊓ 𝓟 s) (comap_inf_principal_neBot_of_image_mem h) theorem ofComapInfPrincipal_mem (h : m '' s ∈ g) : s ∈ ofComapInfPrincipal h := by let f := Filter.comap m g ⊓ 𝓟 s haveI : f.NeBot := comap_inf_principal_neBot_of_image_mem h have : s ∈ f := mem_inf_of_right (mem_principal_self s) exact le_def.mp (of_le _) s this theorem ofComapInfPrincipal_eq_of_map (h : m '' s ∈ g) : (ofComapInfPrincipal h).map m = g := by let f := Filter.comap m g ⊓ 𝓟 s haveI : f.NeBot := comap_inf_principal_neBot_of_image_mem h apply eq_of_le calc Filter.map m (of f) ≤ Filter.map m f := map_mono (of_le _) _ ≤ (Filter.map m <| Filter.comap m g) ⊓ Filter.map m (𝓟 s) := map_inf_le _ = (Filter.map m <| Filter.comap m g) ⊓ (𝓟 <| m '' s) := by rw [map_principal] _ ≤ ↑g ⊓ (𝓟 <| m '' s) := inf_le_inf_right _ map_comap_le _ = ↑g := inf_of_le_left (le_principal_iff.mpr h) theorem eq_of_le_pure {X : Type _} {α : Filter X} (hα : α.NeBot) {x y : X} (hx : α ≤ pure x) (hy : α ≤ pure y) : x = y := Filter.pure_injective (hα.le_pure_iff.mp hx ▸ hα.le_pure_iff.mp hy) end Ultrafilter
.lake/packages/mathlib/Mathlib/Order/Partition/Finpartition.lean
import Mathlib.Data.Finset.Lattice.Prod import Mathlib.Data.Finset.Pairwise import Mathlib.Data.Fintype.Powerset import Mathlib.Data.Setoid.Basic import Mathlib.Order.Atoms import Mathlib.Order.SupIndep import Mathlib.Data.Set.Finite.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Finite partitions In this file, we define finite partitions. A finpartition of `a : α` is a finite set of pairwise disjoint parts `parts : Finset α` which does not contain `⊥` and whose supremum is `a`. Finpartitions of a finset are at the heart of Szemerédi's regularity lemma. They are also studied purely order theoretically in Sperner theory. ## Constructions We provide many ways to build finpartitions: * `Finpartition.ofErase`: Builds a finpartition by erasing `⊥` for you. * `Finpartition.ofSubset`: Builds a finpartition from a subset of the parts of a previous finpartition. * `Finpartition.empty`: The empty finpartition of `⊥`. * `Finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single part. * `Finpartition.discrete`: The discrete finpartition of `s : Finset α` made of singletons. * `Finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new finpartition. * `Finpartition.ofExistsUnique`: Builds a finpartition from a collection of parts such that each element is in exactly one part. * `Finpartition.ofSetoid`: With `Fintype α`, constructs the finpartition of `univ : Finset α` induced by the equivalence classes of `s : Setoid α`. * `Finpartition.atomise`: Makes a finpartition of `s : Finset α` by breaking `s` along all finsets in `F : Finset (Finset α)`. Two elements of `s` belong to the same part iff they belong to the same elements of `F`. `Finpartition.indiscrete` and `Finpartition.bind` together form the monadic structure of `Finpartition`. ## Implementation notes Forbidding `⊥` as a part follows mathematical tradition and is a pragmatic choice concerning operations on `Finpartition`. Not caring about `⊥` being a part or not breaks extensionality (it's not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing `⊥` to be a part makes `Finpartition.bind` uglier and doesn't rid us of the need of `Finpartition.ofErase`. ## TODO The order is the wrong way around to make `Finpartition a` a graded order. Is it bad to depart from the literature and turn the order around? The specialisation to `Finset α` could be generalised to atomistic orders. -/ open Finset Function variable {α : Type*} /-- A finite partition of `a : α` is a pairwise disjoint finite set of elements whose supremum is `a`. We forbid `⊥` as a part. -/ @[ext] structure Finpartition [Lattice α] [OrderBot α] (a : α) where /-- The elements of the finite partition of `a` -/ parts : Finset α /-- The partition is supremum-independent -/ protected supIndep : parts.SupIndep id /-- The supremum of the partition is `a` -/ sup_parts : parts.sup id = a /-- No element of the partition is bottom -/ bot_notMem : ⊥ ∉ parts deriving DecidableEq namespace Finpartition section Lattice variable [Lattice α] [OrderBot α] @[deprecated (since := "2025-05-23")] alias not_bot_mem := bot_notMem /-- A `Finpartition` constructor which does not insist on `⊥` not being a part. -/ @[simps] def ofErase [DecidableEq α] {a : α} (parts : Finset α) (sup_indep : parts.SupIndep id) (sup_parts : parts.sup id = a) : Finpartition a where parts := parts.erase ⊥ supIndep := sup_indep.subset (erase_subset _ _) sup_parts := (sup_erase_bot _).trans sup_parts bot_notMem := notMem_erase _ _ /-- A `Finpartition` constructor from a bigger existing finpartition. -/ @[simps] def ofSubset {a b : α} (P : Finpartition a) {parts : Finset α} (subset : parts ⊆ P.parts) (sup_parts : parts.sup id = b) : Finpartition b := { parts := parts supIndep := P.supIndep.subset subset sup_parts := sup_parts bot_notMem := fun h ↦ P.bot_notMem (subset h) } /-- Changes the type of a finpartition to an equal one. -/ @[simps] def copy {a b : α} (P : Finpartition a) (h : a = b) : Finpartition b where parts := P.parts supIndep := P.supIndep sup_parts := h ▸ P.sup_parts bot_notMem := P.bot_notMem /-- Transfer a finpartition over an order isomorphism. -/ def map {β : Type*} [Lattice β] [OrderBot β] {a : α} (e : α ≃o β) (P : Finpartition a) : Finpartition (e a) where parts := P.parts.map e supIndep u hu _ hb hbu _ hx hxu := by rw [← map_symm_subset] at hu simp only [mem_map_equiv] at hb have := P.supIndep hu hb (by simp [hbu]) (map_rel e.symm hx) ?_ · rw [← e.symm.map_bot] at this exact e.symm.map_rel_iff.mp this · convert e.symm.map_rel_iff.mpr hxu rw [map_finset_sup, sup_map] rfl sup_parts := by simp [← P.sup_parts] bot_notMem := by rw [mem_map_equiv] convert P.bot_notMem exact e.symm.map_bot @[simp] theorem parts_map {β : Type*} [Lattice β] [OrderBot β] {a : α} {e : α ≃o β} {P : Finpartition a} : (P.map e).parts = P.parts.map e := rfl variable (α) /-- The empty finpartition. -/ @[simps] protected def empty : Finpartition (⊥ : α) where parts := ∅ supIndep := supIndep_empty _ sup_parts := Finset.sup_empty bot_notMem := notMem_empty ⊥ instance : Inhabited (Finpartition (⊥ : α)) := ⟨Finpartition.empty α⟩ @[simp] theorem default_eq_empty : (default : Finpartition (⊥ : α)) = Finpartition.empty α := rfl variable {α} {a : α} /-- The finpartition in one part, aka indiscrete finpartition. -/ @[simps] def indiscrete (ha : a ≠ ⊥) : Finpartition a where parts := {a} supIndep := supIndep_singleton _ _ sup_parts := Finset.sup_singleton bot_notMem h := ha (mem_singleton.1 h).symm variable (P : Finpartition a) protected theorem le {b : α} (hb : b ∈ P.parts) : b ≤ a := (le_sup hb).trans P.sup_parts.le theorem ne_bot {b : α} (hb : b ∈ P.parts) : b ≠ ⊥ := by intro h refine P.bot_notMem (?_) rw [h] at hb exact hb protected theorem disjoint : (P.parts : Set α).PairwiseDisjoint id := P.supIndep.pairwiseDisjoint variable {P} @[simp] theorem parts_eq_empty_iff : P.parts = ∅ ↔ a = ⊥ := by simp_rw [← P.sup_parts] refine ⟨fun h ↦ ?_, fun h ↦ eq_empty_iff_forall_notMem.2 fun b hb ↦ P.bot_notMem ?_⟩ · rw [h] exact Finset.sup_empty · rwa [← le_bot_iff.1 ((le_sup hb).trans h.le)] @[simp] theorem parts_nonempty_iff : P.parts.Nonempty ↔ a ≠ ⊥ := by rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff] theorem parts_nonempty (P : Finpartition a) (ha : a ≠ ⊥) : P.parts.Nonempty := parts_nonempty_iff.2 ha instance : Unique (Finpartition (⊥ : α)) := { (inferInstance : Inhabited (Finpartition (⊥ : α))) with uniq := fun P ↦ by ext a exact iff_of_false (fun h ↦ P.ne_bot h <| le_bot_iff.1 <| P.le h) (notMem_empty a) } -- See note [reducible non-instances] /-- There's a unique partition of an atom. -/ abbrev _root_.IsAtom.uniqueFinpartition (ha : IsAtom a) : Unique (Finpartition a) where default := indiscrete ha.1 uniq P := by have h : ∀ b ∈ P.parts, b = a := fun _ hb ↦ (ha.le_iff.mp <| P.le hb).resolve_left (P.ne_bot hb) ext b refine Iff.trans ⟨h b, ?_⟩ mem_singleton.symm rintro rfl obtain ⟨c, hc⟩ := P.parts_nonempty ha.1 simp_rw [← h c hc] exact hc instance [Fintype α] [DecidableEq α] (a : α) : Fintype (Finpartition a) := @Fintype.ofSurjective { p : Finset α // p.SupIndep id ∧ p.sup id = a ∧ ⊥ ∉ p } (Finpartition a) _ (Subtype.fintype _) (fun i ↦ ⟨i.1, i.2.1, i.2.2.1, i.2.2.2⟩) fun ⟨_, y, z, w⟩ ↦ ⟨⟨_, y, z, w⟩, rfl⟩ /-! ### Refinement order -/ section Order /-- We say that `P ≤ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/ instance : LE (Finpartition a) := ⟨fun P Q ↦ ∀ ⦃b⦄, b ∈ P.parts → ∃ c ∈ Q.parts, b ≤ c⟩ instance : PartialOrder (Finpartition a) := { (inferInstance : LE (Finpartition a)) with le_refl := fun _ b hb ↦ ⟨b, hb, le_rfl⟩ le_trans := fun _ Q R hPQ hQR b hb ↦ by obtain ⟨c, hc, hbc⟩ := hPQ hb obtain ⟨d, hd, hcd⟩ := hQR hc exact ⟨d, hd, hbc.trans hcd⟩ le_antisymm := fun P Q hPQ hQP ↦ by ext b refine ⟨fun hb ↦ ?_, fun hb ↦ ?_⟩ · obtain ⟨c, hc, hbc⟩ := hPQ hb obtain ⟨d, hd, hcd⟩ := hQP hc rwa [hbc.antisymm] rwa [P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd)] · obtain ⟨c, hc, hbc⟩ := hQP hb obtain ⟨d, hd, hcd⟩ := hPQ hc rwa [hbc.antisymm] rwa [Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd)] } instance [Decidable (a = ⊥)] : OrderTop (Finpartition a) where top := if ha : a = ⊥ then (Finpartition.empty α).copy ha.symm else indiscrete ha le_top P := by split_ifs with h · intro x hx simpa [h, P.ne_bot hx] using P.le hx · exact fun b hb ↦ ⟨a, mem_singleton_self _, P.le hb⟩ theorem parts_top_subset (a : α) [Decidable (a = ⊥)] : (⊤ : Finpartition a).parts ⊆ {a} := by intro b hb have hb : b ∈ Finpartition.parts (dite _ _ _) := hb split_ifs at hb · simp only [copy_parts, empty_parts, notMem_empty] at hb · exact hb theorem parts_top_subsingleton (a : α) [Decidable (a = ⊥)] : ((⊤ : Finpartition a).parts : Set α).Subsingleton := Set.subsingleton_of_subset_singleton fun _ hb ↦ mem_singleton.1 <| parts_top_subset _ hb -- TODO: this instance takes double-exponential time to generate all partitions, find a faster way instance [DecidableEq α] {s : Finset α} : Fintype (Finpartition s) where elems := s.powerset.powerset.image fun ps ↦ if h : ps.sup id = s ∧ ⊥ ∉ ps ∧ ps.SupIndep id then ⟨ps, h.2.2, h.1, h.2.1⟩ else ⊤ complete P := by refine mem_image.mpr ⟨P.parts, ?_, ?_⟩ · rw [mem_powerset]; intro p hp; rw [mem_powerset]; exact P.le hp · simp [P.supIndep, P.sup_parts, P.bot_notMem, -bot_eq_empty] end Order end Lattice section DistribLattice variable [DistribLattice α] [OrderBot α] section Inf variable [DecidableEq α] {a b c : α} instance : Min (Finpartition a) := ⟨fun P Q ↦ ofErase ((P.parts ×ˢ Q.parts).image fun bc ↦ bc.1 ⊓ bc.2) (by rw [supIndep_iff_disjoint_erase] simp only [mem_image, and_imp, forall_exists_index, id, Prod.exists, mem_product, Finset.disjoint_sup_right, mem_erase, Ne] rintro _ x₁ y₁ hx₁ hy₁ rfl _ h x₂ y₂ hx₂ hy₂ rfl rcases eq_or_ne x₁ x₂ with (rfl | xdiff) · refine Disjoint.mono inf_le_right inf_le_right (Q.disjoint hy₁ hy₂ ?_) intro t simp [t] at h exact Disjoint.mono inf_le_left inf_le_left (P.disjoint hx₁ hx₂ xdiff)) (by rw [sup_image, id_comp, sup_product_left] trans P.parts.sup id ⊓ Q.parts.sup id · simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left] rfl · rw [P.sup_parts, Q.sup_parts, inf_idem])⟩ @[simp] theorem parts_inf (P Q : Finpartition a) : (P ⊓ Q).parts = ((P.parts ×ˢ Q.parts).image fun bc : α × α ↦ bc.1 ⊓ bc.2).erase ⊥ := rfl instance : SemilatticeInf (Finpartition a) := { inf := Min.min inf_le_left := fun P Q b hb ↦ by obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb) rw [mem_product] at hc exact ⟨c.1, hc.1, inf_le_left⟩ inf_le_right := fun P Q b hb ↦ by obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb) rw [mem_product] at hc exact ⟨c.2, hc.2, inf_le_right⟩ le_inf := fun P Q R hPQ hPR b hb ↦ by obtain ⟨c, hc, hbc⟩ := hPQ hb obtain ⟨d, hd, hbd⟩ := hPR hb have h := _root_.le_inf hbc hbd refine ⟨c ⊓ d, mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h) (mem_image.2 ⟨(c, d), mem_product.2 ⟨hc, hd⟩, rfl⟩), h⟩ } end Inf theorem exists_le_of_le {a b : α} {P Q : Finpartition a} (h : P ≤ Q) (hb : b ∈ Q.parts) : ∃ c ∈ P.parts, c ≤ b := by by_contra H refine Q.ne_bot hb (disjoint_self.1 <| Disjoint.mono_right (Q.le hb) ?_) rw [← P.sup_parts, Finset.disjoint_sup_right] rintro c hc obtain ⟨d, hd, hcd⟩ := h hc refine (Q.disjoint hb hd ?_).mono_right hcd rintro rfl simp only [not_exists, not_and] at H exact H _ hc hcd theorem card_mono {a : α} {P Q : Finpartition a} (h : P ≤ Q) : #Q.parts ≤ #P.parts := by classical have : ∀ b ∈ Q.parts, ∃ c ∈ P.parts, c ≤ b := fun b ↦ exists_le_of_le h choose f hP hf using this rw [← card_attach] refine card_le_card_of_injOn (fun b ↦ f _ b.2) (fun b _ ↦ hP _ b.2) fun b _ c _ h ↦ ?_ exact Subtype.coe_injective (Q.disjoint.elim b.2 c.2 fun H ↦ P.ne_bot (hP _ b.2) <| disjoint_self.1 <| H.mono (hf _ b.2) <| h.le.trans <| hf _ c.2) variable [DecidableEq α] {a b c : α} section Bind variable {P : Finpartition a} {Q : ∀ i ∈ P.parts, Finpartition i} /-- Given a finpartition `P` of `a` and finpartitions of each part of `P`, this yields the finpartition of `a` obtained by juxtaposing all the subpartitions. -/ @[simps] def bind (P : Finpartition a) (Q : ∀ i ∈ P.parts, Finpartition i) : Finpartition a where parts := P.parts.attach.biUnion fun i ↦ (Q i.1 i.2).parts supIndep := by rw [supIndep_iff_pairwiseDisjoint] rintro a ha b hb h rw [Finset.mem_coe, Finset.mem_biUnion] at ha hb obtain ⟨⟨A, hA⟩, -, ha⟩ := ha obtain ⟨⟨B, hB⟩, -, hb⟩ := hb obtain rfl | hAB := eq_or_ne A B · exact (Q A hA).disjoint ha hb h · exact (P.disjoint hA hB hAB).mono ((Q A hA).le ha) ((Q B hB).le hb) sup_parts := by simp_rw [sup_biUnion] trans (sup P.parts id) · rw [eq_comm, ← Finset.sup_attach] exact sup_congr rfl fun b _hb ↦ (Q b.1 b.2).sup_parts.symm · exact P.sup_parts bot_notMem h := by rw [Finset.mem_biUnion] at h obtain ⟨⟨A, hA⟩, -, h⟩ := h exact (Q A hA).bot_notMem h theorem mem_bind : b ∈ (P.bind Q).parts ↔ ∃ A hA, b ∈ (Q A hA).parts := by rw [bind, mem_biUnion] constructor · rintro ⟨⟨A, hA⟩, -, h⟩ exact ⟨A, hA, h⟩ · rintro ⟨A, hA, h⟩ exact ⟨⟨A, hA⟩, mem_attach _ ⟨A, hA⟩, h⟩ theorem card_bind (Q : ∀ i ∈ P.parts, Finpartition i) : #(P.bind Q).parts = ∑ A ∈ P.parts.attach, #(Q _ A.2).parts := by apply card_biUnion rintro ⟨b, hb⟩ - ⟨c, hc⟩ - hbc rw [Function.onFun, Finset.disjoint_left] rintro d hdb hdc rw [Ne, Subtype.mk_eq_mk] at hbc exact (Q b hb).ne_bot hdb (eq_bot_iff.2 <| (le_inf ((Q b hb).le hdb) <| (Q c hc).le hdc).trans <| (P.disjoint hb hc hbc).le_bot) end Bind /-- Adds `b` to a finpartition of `a` to make a finpartition of `a ⊔ b`. -/ @[simps] def extend (P : Finpartition a) (hb : b ≠ ⊥) (hab : Disjoint a b) (hc : a ⊔ b = c) : Finpartition c where parts := insert b P.parts supIndep := by rw [supIndep_iff_pairwiseDisjoint, coe_insert] exact P.disjoint.insert fun d hd _ ↦ hab.symm.mono_right <| P.le hd sup_parts := by rwa [sup_insert, P.sup_parts, id, _root_.sup_comm] bot_notMem h := (mem_insert.1 h).elim hb.symm P.bot_notMem theorem card_extend (P : Finpartition a) (b c : α) {hb : b ≠ ⊥} {hab : Disjoint a b} {hc : a ⊔ b = c} : #(P.extend hb hab hc).parts = #P.parts + 1 := card_insert_of_notMem fun h ↦ hb <| hab.symm.eq_bot_of_le <| P.le h end DistribLattice section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] [DecidableEq α] {a b c : α} (P : Finpartition a) /-- Restricts a finpartition to avoid a given element. -/ @[simps!] def avoid (b : α) : Finpartition (a \ b) := ofErase (P.parts.image (· \ b)) (P.disjoint.image_finset_of_le fun _ ↦ sdiff_le).supIndep (by rw [sup_image, id_comp, Finset.sup_sdiff_right, ← Function.id_def, P.sup_parts]) @[simp] theorem mem_avoid : c ∈ (P.avoid b).parts ↔ ∃ d ∈ P.parts, ¬d ≤ b ∧ d \ b = c := by simp only [avoid, ofErase, mem_erase, Ne, mem_image, ← exists_and_left, @and_left_comm (c ≠ ⊥)] refine exists_congr fun d ↦ and_congr_right' <| and_congr_left ?_ rintro rfl rw [sdiff_eq_bot_iff] end GeneralizedBooleanAlgebra end Finpartition /-! ### Finite partitions of finsets -/ namespace Finpartition variable [DecidableEq α] {s t u : Finset α} (P : Finpartition s) {a : α} lemma subset {a : Finset α} (ha : a ∈ P.parts) : a ⊆ s := P.le ha theorem nonempty_of_mem_parts {a : Finset α} (ha : a ∈ P.parts) : a.Nonempty := nonempty_iff_ne_empty.2 <| P.ne_bot ha @[simp] theorem empty_notMem_parts : ∅ ∉ P.parts := P.bot_notMem @[deprecated (since := "2025-05-23")] alias not_empty_mem_parts := empty_notMem_parts theorem ne_empty (h : t ∈ P.parts) : t ≠ ∅ := P.ne_bot h lemma eq_of_mem_parts (ht : t ∈ P.parts) (hu : u ∈ P.parts) (hat : a ∈ t) (hau : a ∈ u) : t = u := P.disjoint.elim ht hu <| not_disjoint_iff.2 ⟨a, hat, hau⟩ theorem exists_mem (ha : a ∈ s) : ∃ t ∈ P.parts, a ∈ t := by simp_rw [← P.sup_parts] at ha exact mem_sup.1 ha theorem biUnion_parts : P.parts.biUnion id = s := (sup_eq_biUnion _ _).symm.trans P.sup_parts theorem existsUnique_mem (ha : a ∈ s) : ∃! t, t ∈ P.parts ∧ a ∈ t := by obtain ⟨t, ht, ht'⟩ := P.exists_mem ha refine ⟨t, ⟨ht, ht'⟩, ?_⟩ rintro u ⟨hu, hu'⟩ exact P.eq_of_mem_parts hu ht hu' ht' /-- Construct a `Finpartition s` from a finset of finsets `parts` such that each element of `s` is in exactly one member of `parts`. This provides a converse to `Finpartition.subset`, `Finpartition.not_empty_mem_parts` and `Finpartition.existsUnique_mem`. -/ @[simps] def ofExistsUnique (parts : Finset (Finset α)) (h : ∀ p ∈ parts, p ⊆ s) (h' : ∀ a ∈ s, ∃! t ∈ parts, a ∈ t) (h'' : ∅ ∉ parts) : Finpartition s where parts := parts supIndep := by simp only [supIndep_iff_pairwiseDisjoint] intro a ha b hb hab rw [Function.onFun, Finset.disjoint_left] intro x hx hx' exact hab ((h' x (h _ ha hx)).unique ⟨ha, hx⟩ ⟨hb, hx'⟩) sup_parts := by ext i simp only [mem_sup, id_eq] constructor · rintro ⟨j, hj, hj'⟩ exact h j hj hj' · rintro hi exact (h' i hi).exists bot_notMem := h'' /-- The part of the finpartition that `a` lies in. -/ def part (a : α) : Finset α := if ha : a ∈ s then choose (hp := P.existsUnique_mem ha) else ∅ @[simp] lemma part_mem : P.part a ∈ P.parts ↔ a ∈ s := by by_cases ha : a ∈ s <;> simp [part, ha, choose_mem] @[simp] lemma part_eq_empty : P.part a = ∅ ↔ a ∉ s := ⟨fun h has ↦ P.ne_empty (P.part_mem.2 has) h, fun h ↦ by simp [part, h]⟩ @[simp] lemma part_nonempty : (P.part a).Nonempty ↔ a ∈ s := by simpa only [nonempty_iff_ne_empty] using P.part_eq_empty.not_left @[simp] lemma part_subset (a : α) : P.part a ⊆ s := by by_cases ha : a ∈ s · exact P.le <| P.part_mem.2 ha · simp [P.part_eq_empty.2 ha] @[simp] lemma mem_part_self : a ∈ P.part a ↔ a ∈ s := by by_cases ha : a ∈ s · simp [part, ha, choose_property (p := fun s => a ∈ s) P.parts (P.existsUnique_mem ha)] · simp [P.part_eq_empty.2, ha] alias ⟨_, mem_part⟩ := mem_part_self lemma part_eq_iff_mem (ht : t ∈ P.parts) : P.part a = t ↔ a ∈ t := by constructor · rintro rfl simp_all · intro hat apply P.eq_of_mem_parts (a := a) <;> simp [*, P.le ht hat] lemma part_eq_of_mem (ht : t ∈ P.parts) (hat : a ∈ t) : P.part a = t := (P.part_eq_iff_mem ht).2 hat lemma mem_part_iff_part_eq_part {b : α} (ha : a ∈ s) (hb : b ∈ s) : a ∈ P.part b ↔ P.part a = P.part b := ⟨fun c ↦ (P.part_eq_of_mem (P.part_mem.2 hb) c), fun c ↦ c ▸ P.mem_part ha⟩ theorem part_surjOn : Set.SurjOn P.part s P.parts := fun p hp ↦ by obtain ⟨x, hx⟩ := P.nonempty_of_mem_parts hp have hx' := mem_of_subset (P.le hp) hx use x, hx', (P.existsUnique_mem hx').unique ⟨P.part_mem.2 hx', P.mem_part hx'⟩ ⟨hp, hx⟩ theorem exists_subset_part_bijOn : ∃ r ⊆ s, Set.BijOn P.part r P.parts := by obtain ⟨r, hrs, hr⟩ := P.part_surjOn.exists_bijOn_subset lift r to Finset α using s.finite_toSet.subset hrs exact ⟨r, mod_cast hrs, hr⟩ theorem mem_part_iff_exists {b} : a ∈ P.part b ↔ ∃ p ∈ P.parts, a ∈ p ∧ b ∈ p := by constructor · intro h have : b ∈ s := P.part_nonempty.1 ⟨a, h⟩ refine ⟨_, ?_, h, ?_⟩ <;> simp [this] · rintro ⟨p, hp, hap, hbp⟩ obtain rfl : P.part b = p := P.part_eq_of_mem hp hbp exact hap /-- Equivalence between a finpartition's parts as a dependent sum and the partitioned set. -/ def equivSigmaParts : s ≃ Σ t : P.parts, t.1 where toFun x := ⟨⟨P.part x.1, P.part_mem.2 x.2⟩, ⟨x, P.mem_part x.2⟩⟩ invFun x := ⟨x.2, mem_of_subset (P.le x.1.2) x.2.2⟩ left_inv x := by simp right_inv x := by ext e · obtain ⟨⟨p, mp⟩, ⟨f, mf⟩⟩ := x dsimp only at mf ⊢ rw [P.part_eq_of_mem mp mf] · simp lemma exists_enumeration : ∃ f : s ≃ Σ t : P.parts, Fin #t.1, ∀ a b : s, P.part a = P.part b ↔ (f a).1 = (f b).1 := by use P.equivSigmaParts.trans ((Equiv.refl _).sigmaCongr (fun t ↦ t.1.equivFin)) simp [equivSigmaParts, Equiv.sigmaCongr, Equiv.sigmaCongrLeft] theorem sum_card_parts : ∑ i ∈ P.parts, #i = #s := by convert congr_arg Finset.card P.biUnion_parts rw [card_biUnion P.supIndep.pairwiseDisjoint] rfl /-- `⊥` is the partition in singletons, aka discrete partition. -/ instance (s : Finset α) : Bot (Finpartition s) := ⟨{ parts := s.map ⟨singleton, singleton_injective⟩ supIndep := Set.PairwiseDisjoint.supIndep <| by rw [Finset.coe_map] exact Finset.pairwiseDisjoint_range_singleton.subset (Set.image_subset_range _ _) sup_parts := by rw [sup_map, id_comp, Embedding.coeFn_mk, Finset.sup_singleton_eq_self] bot_notMem := by simp }⟩ @[simp] theorem parts_bot (s : Finset α) : (⊥ : Finpartition s).parts = s.map ⟨singleton, singleton_injective⟩ := rfl theorem card_bot (s : Finset α) : #(⊥ : Finpartition s).parts = #s := Finset.card_map _ theorem mem_bot_iff : t ∈ (⊥ : Finpartition s).parts ↔ ∃ a ∈ s, {a} = t := mem_map instance (s : Finset α) : OrderBot (Finpartition s) := { (inferInstance : Bot (Finpartition s)) with bot_le := fun P t ht ↦ by rw [mem_bot_iff] at ht obtain ⟨a, ha, rfl⟩ := ht obtain ⟨t, ht, hat⟩ := P.exists_mem ha exact ⟨t, ht, singleton_subset_iff.2 hat⟩ } theorem card_parts_le_card : #P.parts ≤ #s := by rw [← card_bot s] exact card_mono bot_le lemma card_mod_card_parts_le : #s % #P.parts ≤ #P.parts := by obtain h | h := (#P.parts).eq_zero_or_pos · rw [h] rw [Finset.card_eq_zero, parts_eq_empty_iff, bot_eq_empty, ← Finset.card_eq_zero] at h rw [h] · exact (Nat.mod_lt _ h).le section SetSetoid /-- A setoid over a finite type induces a finpartition of the type's elements, where the parts are the setoid's equivalence classes. -/ @[simps -isSimp] def ofSetSetoid (s : Setoid α) (x : Finset α) [DecidableRel s.r] : Finpartition x where parts := x.image fun a ↦ {b ∈ x | s.r a b} supIndep := by suffices ∀ (a b c d : α), s a d → s b d → (s a c ↔ s b c) by simp only [supIndep_iff_pairwiseDisjoint, Set.PairwiseDisjoint, Set.Pairwise, coe_image, Set.mem_image, mem_coe, ne_eq, onFun, id_eq, disjoint_iff_ne, forall_mem_not_eq, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, mem_filter, not_and, filter_inj', not_forall, @not_imp_comm (_ ↔ _), Decidable.not_not] intro _ _ _ _ _ _ _ _ ha _ hb exact ⟨(s.trans' hb <| s.trans' (s.symm' ha) ·), (s.trans' ha <| s.trans' (s.symm' hb) ·)⟩ simp +contextual [← Quotient.eq] sup_parts := by ext a simp_rw [sup_image, id_comp, mem_sup, mem_filter] refine ⟨(·.choose_spec.2.1), fun _ ↦ by use a⟩ bot_notMem := by suffices ∀ x₁ ∈ x, ∃ x₂ ∈ x, s x₁ x₂ by simpa [filter_eq_empty_iff] intro x _ use x theorem mem_part_ofSetSetoid_iff_rel {s : Setoid α} (x : Finset α) [DecidableRel s.r] {b : α} : b ∈ (ofSetSetoid s x).part a ↔ a ∈ x ∧ b ∈ x ∧ s a b := by suffices (∃ a₁ ∈ x, (b ∈ x ∧ s a₁ b) ∧ a ∈ x ∧ s a₁ a) ↔ a ∈ x ∧ b ∈ x ∧ s a b by simpa [mem_part_iff_exists, ofSetSetoid_parts] exact ⟨ fun ⟨c, _, ⟨hb, hcb⟩, ⟨ha, hca⟩⟩ ↦ ⟨ha, hb, s.trans' (s.symm' hca) hcb⟩, fun h ↦ ⟨a, ⟨h.1, ⟨⟨h.2.1, h.2.2⟩, ⟨h.1, s.refl _⟩⟩⟩⟩ ⟩ end SetSetoid section Setoid variable [Fintype α] /-- A setoid over a finite type induces a finpartition of the type's elements, where the parts are the setoid's equivalence classes. -/ @[simps! -isSimp] def ofSetoid (s : Setoid α) [DecidableRel s.r] : Finpartition (univ : Finset α) := ofSetSetoid s univ theorem mem_part_ofSetoid_iff_rel {s : Setoid α} [DecidableRel s.r] {b : α} : b ∈ (ofSetoid s).part a ↔ s a b := by suffices b ∈ (ofSetSetoid s univ).part a ↔ a ∈ univ ∧ b ∈ univ ∧ s a b by simpa exact mem_part_ofSetSetoid_iff_rel univ end Setoid section Atomise /-- Cuts `s` along the finsets in `F`: Two elements of `s` will be in the same part if they are in the same finsets of `F`. -/ def atomise (s : Finset α) (F : Finset (Finset α)) : Finpartition s := ofErase (F.powerset.image fun Q ↦ {i ∈ s | ∀ t ∈ F, t ∈ Q ↔ i ∈ t}) (Set.PairwiseDisjoint.supIndep fun x hx y hy h ↦ disjoint_left.mpr fun z hz1 hz2 ↦ h (by rw [mem_coe, mem_image] at hx hy obtain ⟨Q, hQ, rfl⟩ := hx obtain ⟨R, hR, rfl⟩ := hy suffices h' : Q = R by subst h' exact of_eq_true (eq_self {i ∈ s | ∀ t ∈ F, t ∈ Q ↔ i ∈ t}) rw [id, mem_filter] at hz1 hz2 rw [mem_powerset] at hQ hR ext i refine ⟨fun hi ↦ ?_, fun hi ↦ ?_⟩ · rwa [hz2.2 _ (hQ hi), ← hz1.2 _ (hQ hi)] · rwa [hz1.2 _ (hR hi), ← hz2.2 _ (hR hi)])) (by refine (Finset.sup_le fun t ht ↦ ?_).antisymm fun a ha ↦ ?_ · rw [mem_image] at ht obtain ⟨A, _, rfl⟩ := ht exact s.filter_subset _ · rw [mem_sup] refine ⟨{i ∈ s | ∀ t ∈ F, t ∈ {u ∈ F | a ∈ u} ↔ i ∈ t}, mem_image_of_mem _ (mem_powerset.2 <| filter_subset _ _), mem_filter.2 ⟨ha, fun t ht ↦ ?_⟩⟩ rw [mem_filter] exact and_iff_right ht) variable {F : Finset (Finset α)} theorem mem_atomise : t ∈ (atomise s F).parts ↔ t.Nonempty ∧ ∃ Q ⊆ F, {i ∈ s | ∀ u ∈ F, u ∈ Q ↔ i ∈ u} = t := by simp only [atomise, ofErase, bot_eq_empty, mem_erase, mem_image, nonempty_iff_ne_empty, mem_powerset] theorem atomise_empty (hs : s.Nonempty) : (atomise s ∅).parts = {s} := by simp only [atomise, powerset_empty, image_singleton, notMem_empty, IsEmpty.forall_iff, imp_true_iff, filter_true] exact erase_eq_of_notMem (notMem_singleton.2 hs.ne_empty.symm) theorem card_atomise_le : #(atomise s F).parts ≤ 2 ^ #F := (card_le_card <| erase_subset _ _).trans <| Finset.card_image_le.trans (card_powerset _).le theorem biUnion_filter_atomise (ht : t ∈ F) (hts : t ⊆ s) : {u ∈ (atomise s F).parts | u ⊆ t ∧ u.Nonempty}.biUnion id = t := by ext a refine mem_biUnion.trans ⟨fun ⟨u, hu, ha⟩ ↦ (mem_filter.1 hu).2.1 ha, fun ha ↦ ?_⟩ obtain ⟨u, hu, hau⟩ := (atomise s F).exists_mem (hts ha) refine ⟨u, mem_filter.2 ⟨hu, fun b hb ↦ ?_, _, hau⟩, hau⟩ obtain ⟨Q, _hQ, rfl⟩ := (mem_atomise.1 hu).2 rw [mem_filter] at hau hb rwa [← hb.2 _ ht, hau.2 _ ht] theorem card_filter_atomise_le_two_pow (ht : t ∈ F) : #{u ∈ (atomise s F).parts | u ⊆ t ∧ u.Nonempty} ≤ 2 ^ (#F - 1) := by suffices h : {u ∈ (atomise s F).parts | u ⊆ t ∧ u.Nonempty} ⊆ (F.erase t).powerset.image fun P ↦ {i ∈ s | ∀ x ∈ F, x ∈ insert t P ↔ i ∈ x} by refine (card_le_card h).trans (card_image_le.trans ?_) rw [card_powerset, card_erase_of_mem ht] rw [subset_iff] simp_rw [mem_image, mem_powerset, mem_filter, and_imp, Finset.Nonempty, exists_imp, mem_atomise, and_imp, Finset.Nonempty, exists_imp, and_imp] rintro P' i hi P PQ rfl hy₂ j _hj refine ⟨P.erase t, erase_subset_erase _ PQ, ?_⟩ simp only [insert_erase (((mem_filter.1 hi).2 _ ht).2 <| hy₂ hi)] end Atomise end Finpartition
.lake/packages/mathlib/Mathlib/Order/Partition/Basic.lean
import Mathlib.Data.SetLike.Basic import Mathlib.Order.SupIndep /-! # Partitions A `Partition` of an element `a` in a complete lattice is an independent family of nontrivial elements whose supremum is `a`. An important special case is where `s : Set α`, where a `Partition s` corresponds to a partition of the elements of `s` into a family of nonempty sets. This is equivalent to a transitive and symmetric binary relation `r : α → α → Prop` where `s` is the set of all `x` for which `r x x`. ## Main definitions * For `[CompleteLattice α]` and `s : α`, a `Set.Partition s` is an independent collection of nontrivial elements whose supremum is `s`. ## TODO * Link this to `Finpartition`. * Give API lemmas for the specialization to the `Set` case. -/ variable {α : Type*} {s x y : α} open Set /-- A `Partition` of an element `s` of a `CompleteLattice` is a collection of independent nontrivial elements whose supremum is `s`. -/ structure Partition [CompleteLattice α] (s : α) where /-- The collection of parts -/ parts : Set α /-- The parts are `sSupIndep`. -/ sSupIndep' : sSupIndep parts /-- The bottom element is not a part. -/ bot_notMem' : ⊥ ∉ parts /-- The supremum of all parts is `s`. -/ sSup_eq' : sSup parts = s namespace Partition @[deprecated (since := "2025-05-23")] alias bot_not_mem' := bot_notMem' section Basic variable [CompleteLattice α] {P : Partition s} instance {s : α} : SetLike (Partition s) α where coe := Partition.parts coe_injective' p p' h := by cases p; cases p'; simpa using h /-- See Note [custom simps projection]. -/ def Simps.coe {s : α} (P : Partition s) : Set α := P initialize_simps_projections Partition (parts → coe, as_prefix coe) @[simp] lemma coe_parts : P.parts = P := rfl @[ext] lemma ext {P Q : Partition s} (hP : ∀ x, x ∈ P ↔ x ∈ Q) : P = Q := SetLike.ext hP @[simp] lemma sSupIndep (P : Partition s) : sSupIndep (P : Set α) := P.sSupIndep' lemma disjoint (hx : x ∈ P) (hy : y ∈ P) (hxy : x ≠ y) : Disjoint x y := P.sSupIndep.pairwiseDisjoint hx hy hxy lemma pairwiseDisjoint : Set.PairwiseDisjoint (P : Set α) id := P.sSupIndep'.pairwiseDisjoint @[simp] lemma sSup_eq (P : Partition s) : sSup P = s := P.sSup_eq' @[simp] lemma iSup_eq (P : Partition s) : ⨆ x ∈ P, x = s := by simp_rw [← P.sSup_eq, sSup_eq_iSup] rfl lemma le_of_mem (P : Partition s) (hx : x ∈ P) : x ≤ s := (le_sSup hx).trans_eq P.sSup_eq lemma parts_nonempty (P : Partition s) (hs : s ≠ ⊥) : (P : Set α).Nonempty := nonempty_iff_ne_empty.2 fun hP ↦ by simp [← P.sSup_eq, hP, sSup_empty] at hs @[simp] lemma bot_notMem (P : Partition s) : ⊥ ∉ P := P.bot_notMem' @[deprecated (since := "2025-05-23")] alias bot_not_mem := bot_notMem lemma ne_bot_of_mem (hx : x ∈ P) : x ≠ ⊥ := fun h ↦ P.bot_notMem <| h ▸ hx lemma bot_lt_of_mem (hx : x ∈ P) : ⊥ < x := bot_lt_iff_ne_bot.2 <| P.ne_bot_of_mem hx /-- Convert a `Partition s` into a `Partition t` via an equality `s = t`. -/ @[simps] protected def copy {t : α} (P : Partition s) (hst : s = t) : Partition t where parts := P sSupIndep' := P.sSupIndep bot_notMem' := P.bot_notMem sSup_eq' := hst ▸ P.sSup_eq @[simp] lemma mem_copy_iff {t x : α} {P : Partition s} (hst : s = t) : x ∈ P.copy hst ↔ x ∈ P := Iff.rfl /-- The natural equivalence between the subtype of parts and the subtype of parts of a copy. -/ @[simps!] def partscopyEquiv {t : α} (P : Partition s) (hst : s = t) : ↥(P.copy hst) ≃ ↥P := Equiv.setCongr rfl /-- A constructor for `Partition s` that removes `⊥` from the set of parts. -/ @[simps] def removeBot (P : Set α) (indep : _root_.sSupIndep P) (sSup_eq : sSup P = s) : Partition s where parts := P \ {⊥} sSupIndep' := indep.mono diff_subset bot_notMem' := by simp sSup_eq' := by simp [← sSup_eq] end Basic end Partition
.lake/packages/mathlib/Mathlib/Order/Partition/Equipartition.lean
import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Equitable import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Order.Partition.Finpartition import Mathlib.Tactic.ApplyFun /-! # Finite equipartitions This file defines finite equipartitions, the partitions whose parts all are the same size up to a difference of `1`. ## Main declarations * `Finpartition.IsEquipartition`: Predicate for a `Finpartition` to be an equipartition. * `Finpartition.IsEquipartition.exists_partPreservingEquiv`: part-preserving enumeration of a finset equipped with an equipartition. Indices of elements in the same part are congruent modulo the number of parts. -/ open Finset Fintype namespace Finpartition variable {α : Type*} [DecidableEq α] {s t : Finset α} (P : Finpartition s) /-- An equipartition is a partition whose parts are all the same size, up to a difference of `1`. -/ def IsEquipartition : Prop := (P.parts : Set (Finset α)).EquitableOn card theorem isEquipartition_iff_card_parts_eq_average : P.IsEquipartition ↔ ∀ a : Finset α, a ∈ P.parts → #a = #s / #P.parts ∨ #a = #s / #P.parts + 1 := by simp_rw [IsEquipartition, Finset.equitableOn_iff, P.sum_card_parts] variable {P} lemma not_isEquipartition : ¬P.IsEquipartition ↔ ∃ a ∈ P.parts, ∃ b ∈ P.parts, #b + 1 < #a := Set.not_equitableOn theorem _root_.Set.Subsingleton.isEquipartition (h : (P.parts : Set (Finset α)).Subsingleton) : P.IsEquipartition := Set.Subsingleton.equitableOn h _ theorem IsEquipartition.card_parts_eq_average (hP : P.IsEquipartition) (ht : t ∈ P.parts) : #t = #s / #P.parts ∨ #t = #s / #P.parts + 1 := P.isEquipartition_iff_card_parts_eq_average.1 hP _ ht theorem IsEquipartition.card_part_eq_average_iff (hP : P.IsEquipartition) (ht : t ∈ P.parts) : #t = #s / #P.parts ↔ #t ≠ #s / #P.parts + 1 := by have a := hP.card_parts_eq_average ht cutsat theorem IsEquipartition.average_le_card_part (hP : P.IsEquipartition) (ht : t ∈ P.parts) : #s / #P.parts ≤ #t := by rw [← P.sum_card_parts] exact Finset.EquitableOn.le hP ht theorem IsEquipartition.card_part_le_average_add_one (hP : P.IsEquipartition) (ht : t ∈ P.parts) : #t ≤ #s / #P.parts + 1 := by rw [← P.sum_card_parts] exact Finset.EquitableOn.le_add_one hP ht theorem IsEquipartition.filter_ne_average_add_one_eq_average (hP : P.IsEquipartition) : {p ∈ P.parts | ¬#p = #s / #P.parts + 1} = {p ∈ P.parts | #p = #s / #P.parts} := by ext p simp only [mem_filter, and_congr_right_iff] exact fun hp ↦ (hP.card_part_eq_average_iff hp).symm /-- An equipartition of a finset with `n` elements into `k` parts has `n % k` parts of size `n / k + 1`. -/ theorem IsEquipartition.card_large_parts_eq_mod (hP : P.IsEquipartition) : #{p ∈ P.parts | #p = #s / #P.parts + 1} = #s % #P.parts := by have z := P.sum_card_parts rw [← sum_filter_add_sum_filter_not (s := P.parts) (p := fun x ↦ #x = #s / #P.parts + 1), hP.filter_ne_average_add_one_eq_average, sum_const_nat (m := #s / #P.parts + 1) (by simp), sum_const_nat (m := #s / #P.parts) (by simp), ← hP.filter_ne_average_add_one_eq_average, mul_add, add_comm, ← add_assoc, ← add_mul, mul_one, add_comm #_, filter_card_add_filter_neg_card_eq_card, add_comm] at z rw [← add_left_inj, Nat.mod_add_div, z] /-- An equipartition of a finset with `n` elements into `k` parts has `n - n % k` parts of size `n / k`. -/ theorem IsEquipartition.card_small_parts_eq_mod (hP : P.IsEquipartition) : #{p ∈ P.parts | #p = #s / #P.parts} = #P.parts - #s % #P.parts := by conv_rhs => arg 1 rw [← filter_card_add_filter_neg_card_eq_card (p := fun p ↦ #p = #s / #P.parts + 1)] rw [hP.card_large_parts_eq_mod, add_tsub_cancel_left, hP.filter_ne_average_add_one_eq_average] /-- There exists an enumeration of an equipartition's parts where larger parts map to smaller numbers and vice versa. -/ theorem IsEquipartition.exists_partsEquiv (hP : P.IsEquipartition) : ∃ f : P.parts ≃ Fin #P.parts, ∀ t, #t.1 = #s / #P.parts + 1 ↔ f t < #s % #P.parts := by let el := {p ∈ P.parts | #p = #s / #P.parts + 1}.equivFin let es := {p ∈ P.parts | #p = #s / #P.parts}.equivFin simp_rw [mem_filter, hP.card_large_parts_eq_mod] at el simp_rw [mem_filter, hP.card_small_parts_eq_mod] at es let sneg : {x // x ∈ P.parts ∧ ¬#x = #s / #P.parts + 1} ≃ {x // x ∈ P.parts ∧ #x = #s / #P.parts} := by apply (Equiv.refl _).subtypeEquiv simp only [Equiv.refl_apply, and_congr_right_iff] exact fun _ ha ↦ by rw [hP.card_part_eq_average_iff ha, ne_eq] replace el : { x : P.parts // #x.1 = #s / #P.parts + 1 } ≃ Fin (#s % #P.parts) := (Equiv.Set.sep ..).symm.trans el replace es : { x : P.parts // ¬#x.1 = #s / #P.parts + 1 } ≃ Fin (#P.parts - #s % #P.parts) := (Equiv.Set.sep ..).symm.trans (sneg.trans es) let f := (Equiv.sumCompl _).symm.trans ((el.sumCongr es).trans finSumFinEquiv) use f.trans (finCongr (Nat.add_sub_of_le P.card_mod_card_parts_le)) intro ⟨p, _⟩ simp_rw [f, Equiv.trans_apply, Equiv.sumCongr_apply, finCongr_apply, Fin.coe_cast] by_cases hc : #p = #s / #P.parts + 1 <;> simp [hc] /-- Given a finset equipartitioned into `k` parts, its elements can be enumerated such that elements in the same part have congruent indices modulo `k`. -/ theorem IsEquipartition.exists_partPreservingEquiv (hP : P.IsEquipartition) : ∃ f : s ≃ Fin #s, ∀ a b : s, P.part a = P.part b ↔ f a % #P.parts = f b % #P.parts := by obtain ⟨f, hf⟩ := P.exists_enumeration obtain ⟨g, hg⟩ := hP.exists_partsEquiv let z := fun a ↦ #P.parts * (f a).2 + g (f a).1 have gl := fun a ↦ (g (f a).1).2 have less : ∀ a, z a < #s := fun a ↦ by rcases hP.card_parts_eq_average (f a).1.2 with (c | c) · calc _ < #P.parts * ((f a).2 + 1) := add_lt_add_left (gl a) _ _ ≤ #P.parts * (#s / #P.parts) := mul_le_mul_left' (c ▸ (f a).2.2) _ _ ≤ #P.parts * (#s / #P.parts) + #s % #P.parts := Nat.le_add_right .. _ = _ := Nat.div_add_mod .. · rw [← Nat.div_add_mod #s #P.parts] exact add_lt_add_of_le_of_lt (mul_le_mul_left' (by cutsat) _) ((hg (f a).1).mp c) let z' : s → Fin #s := fun a ↦ ⟨z a, less a⟩ have bij : z'.Bijective := by refine (bijective_iff_injective_and_card z').mpr ⟨fun a b e ↦ ?_, by simp⟩ simp_rw [z', z, Fin.mk.injEq, mul_comm #P.parts] at e haveI : NeZero #P.parts := ⟨((Nat.zero_le _).trans_lt (gl a)).ne'⟩ change (#P.parts).divModEquiv.symm (_, _) = (#P.parts).divModEquiv.symm (_, _) at e simp only [Equiv.apply_eq_iff_eq, Prod.mk.injEq] at e apply_fun f exact Sigma.ext e.2 <| (Fin.heq_ext_iff (by rw [e.2])).mpr e.1 use Equiv.ofBijective _ bij intro a b simp_rw [z', z, Equiv.ofBijective_apply, hf a b, Nat.mul_add_mod, Nat.mod_eq_of_lt (gl a), Nat.mod_eq_of_lt (gl b), Fin.val_eq_val, g.apply_eq_iff_eq] /-! ### Discrete and indiscrete finpartitions -/ variable (s) -- [Decidable (a = ⊥)] theorem bot_isEquipartition : (⊥ : Finpartition s).IsEquipartition := Set.equitableOn_iff_exists_eq_eq_add_one.2 ⟨1, by simp⟩ theorem top_isEquipartition [Decidable (s = ⊥)] : (⊤ : Finpartition s).IsEquipartition := Set.Subsingleton.isEquipartition (parts_top_subsingleton _) theorem indiscrete_isEquipartition {hs : s ≠ ∅} : (indiscrete hs).IsEquipartition := by rw [IsEquipartition, indiscrete_parts, coe_singleton] exact Set.equitableOn_singleton s _ end Finpartition
.lake/packages/mathlib/Mathlib/Order/Circular/ZMod.lean
import Mathlib.Order.Circular import Mathlib.Order.Fin.Basic import Mathlib.Data.ZMod.Defs /-! # The circular order on `ZMod n` This file defines the circular order on `ZMod n`. -/ instance : CircularOrder ℤ := LinearOrder.toCircularOrder _ variable {a b c : ℤ} lemma Int.btw_iff : btw a b c ↔ a ≤ b ∧ b ≤ c ∨ b ≤ c ∧ c ≤ a ∨ c ≤ a ∧ a ≤ b := .rfl lemma Int.sbtw_iff : sbtw a b c ↔ a < b ∧ b < c ∨ b < c ∧ c < a ∨ c < a ∧ a < b := .rfl instance (n : ℕ) : CircularOrder (Fin n) := LinearOrder.toCircularOrder _ variable {n : ℕ} {a b c : Fin n} lemma Fin.btw_iff : btw a b c ↔ a ≤ b ∧ b ≤ c ∨ b ≤ c ∧ c ≤ a ∨ c ≤ a ∧ a ≤ b := .rfl lemma Fin.sbtw_iff : sbtw a b c ↔ a < b ∧ b < c ∨ b < c ∧ c < a ∨ c < a ∧ a < b := .rfl instance : ∀ (n : ℕ), CircularOrder (ZMod n) | 0 => inferInstanceAs <| CircularOrder ℤ | n + 1 => inferInstanceAs <| CircularOrder <| Fin <| n + 1
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/Chain.lean
import Mathlib.Data.Set.Lattice import Mathlib.Order.Preorder.Chain /-! # Hausdorff's maximality principle This file proves Hausdorff's maximality principle. ## Main declarations * `maxChain_spec`: Hausdorff's Maximality Principle. ## Notes Originally ported from Isabelle/HOL. The [original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D. Fleuriot, Tobias Nipkow, Christian Sternagel. -/ open Set variable {α : Type*} {r : α → α → Prop} {c c₁ c₂ s t : Set α} {a b x y : α} /-- Predicate for whether a set is reachable from `∅` using `SuccChain` and `⋃₀`. -/ inductive ChainClosure (r : α → α → Prop) : Set α → Prop | succ : ∀ {s}, ChainClosure r s → ChainClosure r (SuccChain r s) | union : ∀ {s}, (∀ a ∈ s, ChainClosure r a) → ChainClosure r (⋃₀ s) /-- An explicit maximal chain. `maxChain` is taken to be the union of all sets in `ChainClosure`. -/ def maxChain (r : α → α → Prop) : Set α := ⋃₀ setOf (ChainClosure r) lemma chainClosure_empty : ChainClosure r ∅ := by have : ChainClosure r (⋃₀ ∅) := ChainClosure.union fun a h => (notMem_empty _ h).elim simpa using this lemma chainClosure_maxChain : ChainClosure r (maxChain r) := ChainClosure.union fun _ => id private lemma chainClosure_succ_total_aux (hc₁ : ChainClosure r c₁) (h : ∀ ⦃c₃⦄, ChainClosure r c₃ → c₃ ⊆ c₂ → c₂ = c₃ ∨ SuccChain r c₃ ⊆ c₂) : SuccChain r c₂ ⊆ c₁ ∨ c₁ ⊆ c₂ := by induction hc₁ with | @succ c₃ hc₃ ih => obtain ih | ih := ih · exact Or.inl (ih.trans subset_succChain) · exact (h hc₃ ih).imp_left fun (h : c₂ = c₃) => h ▸ Subset.rfl | union _ ih => refine or_iff_not_imp_left.2 fun hn => sUnion_subset fun a ha => ?_ exact (ih a ha).resolve_left fun h => hn <| h.trans <| subset_sUnion_of_mem ha private lemma chainClosure_succ_total (hc₁ : ChainClosure r c₁) (hc₂ : ChainClosure r c₂) (h : c₁ ⊆ c₂) : c₂ = c₁ ∨ SuccChain r c₁ ⊆ c₂ := by induction hc₂ generalizing c₁ hc₁ with | succ _ ih => refine ((chainClosure_succ_total_aux hc₁) fun c₁ => ih).imp h.antisymm' fun h₁ => ?_ obtain rfl | h₂ := ih hc₁ h₁ · exact Subset.rfl · exact h₂.trans subset_succChain | union _ ih => apply Or.imp_left h.antisymm' apply by_contradiction simp only [sUnion_subset_iff, not_or, not_forall, exists_prop, and_imp, forall_exists_index] intro c₃ hc₃ h₁ h₂ obtain h | h := chainClosure_succ_total_aux hc₁ fun c₄ => ih _ hc₃ · exact h₁ (subset_succChain.trans h) obtain h' | h' := ih c₃ hc₃ hc₁ h · exact h₁ h'.subset · exact h₂ (h'.trans <| subset_sUnion_of_mem hc₃) lemma ChainClosure.total (hc₁ : ChainClosure r c₁) (hc₂ : ChainClosure r c₂) : c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ := ((chainClosure_succ_total_aux hc₂) fun _ hc₃ => chainClosure_succ_total hc₃ hc₁).imp_left subset_succChain.trans lemma ChainClosure.succ_fixpoint (hc₁ : ChainClosure r c₁) (hc₂ : ChainClosure r c₂) (hc : SuccChain r c₂ = c₂) : c₁ ⊆ c₂ := by induction hc₁ with | succ hc₁ h => exact (chainClosure_succ_total hc₁ hc₂ h).elim (fun h => h ▸ hc.subset) id | union _ ih => exact sUnion_subset ih lemma ChainClosure.succ_fixpoint_iff (hc : ChainClosure r c) : SuccChain r c = c ↔ c = maxChain r := ⟨fun h => (subset_sUnion_of_mem hc).antisymm <| chainClosure_maxChain.succ_fixpoint hc h, fun h => subset_succChain.antisymm' <| (subset_sUnion_of_mem hc.succ).trans h.symm.subset⟩ lemma ChainClosure.isChain (hc : ChainClosure r c) : IsChain r c := by induction hc with | succ _ h => exact h.succ | union hs h => exact fun c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq => ((hs _ ht₁).total <| hs _ ht₂).elim (fun ht => h t₂ ht₂ (ht hc₁) hc₂ hneq) fun ht => h t₁ ht₁ hc₁ (ht hc₂) hneq /-- **Hausdorff's maximality principle** There exists a maximal totally ordered set of `α`. Note that we do not require `α` to be partially ordered by `r`. -/ theorem maxChain_spec : IsMaxChain r (maxChain r) := by_contradiction fun h => let ⟨_, H⟩ := chainClosure_maxChain.isChain.superChain_succChain h H.ne (chainClosure_maxChain.succ_fixpoint_iff.mpr rfl).symm
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/Lemmas.lean
import Mathlib.Data.Bool.Set import Mathlib.Data.Nat.Set import Mathlib.Order.CompleteLattice.Basic /-! # Theory of complete lattices This file contains results on complete lattices that need more theory to develop. ## Naming conventions In lemma names, * `sSup` is called `sSup` * `sInf` is called `sInf` * `⨆ i, s i` is called `iSup` * `⨅ i, s i` is called `iInf` * `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`. * `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`. * `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂` where `j : i ∈ s`. * `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂` where `j : i ∈ s`. ## Notation * `⨆ i, f i` : `iSup f`, the supremum of the range of `f`; * `⨅ i, f i` : `iInf f`, the infimum of the range of `f`. -/ open Function OrderDual Set variable {α β γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*} open OrderDual section variable [CompleteLattice α] {f g s : ι → α} {a b : α} /-! ### `iSup` and `iInf` under `Type` -/ theorem iSup_bool_eq {f : Bool → α} : ⨆ b : Bool, f b = f true ⊔ f false := by rw [iSup, Bool.range_eq, sSup_pair, sup_comm] theorem iInf_bool_eq {f : Bool → α} : ⨅ b : Bool, f b = f true ⊓ f false := @iSup_bool_eq αᵒᵈ _ _ theorem sup_eq_iSup (x y : α) : x ⊔ y = ⨆ b : Bool, cond b x y := by rw [iSup_bool_eq, Bool.cond_true, Bool.cond_false] theorem inf_eq_iInf (x y : α) : x ⊓ y = ⨅ b : Bool, cond b x y := @sup_eq_iSup αᵒᵈ _ _ _ /-! ### `iSup` and `iInf` under `ℕ` -/ theorem iSup_ge_eq_iSup_nat_add (u : ℕ → α) (n : ℕ) : ⨆ i ≥ n, u i = ⨆ i, u (i + n) := by apply le_antisymm <;> simp only [iSup_le_iff] · refine fun i hi => le_sSup ⟨i - n, ?_⟩ dsimp only rw [Nat.sub_add_cancel hi] · exact fun i => le_sSup ⟨i + n, iSup_pos (Nat.le_add_left _ _)⟩ theorem iInf_ge_eq_iInf_nat_add (u : ℕ → α) (n : ℕ) : ⨅ i ≥ n, u i = ⨅ i, u (i + n) := @iSup_ge_eq_iSup_nat_add αᵒᵈ _ _ _ theorem Monotone.iSup_nat_add {f : ℕ → α} (hf : Monotone f) (k : ℕ) : ⨆ n, f (n + k) = ⨆ n, f n := le_antisymm (iSup_le fun i => le_iSup _ (i + k)) <| iSup_mono fun i => hf <| Nat.le_add_right i k theorem Antitone.iInf_nat_add {f : ℕ → α} (hf : Antitone f) (k : ℕ) : ⨅ n, f (n + k) = ⨅ n, f n := hf.dual_right.iSup_nat_add k -- Not `@[simp]` since the subterm `?f (i + ?k)` produces an ugly higher-order unification problem. -- (Although the `simpNF` linter does not complain.) -- See: https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/complete_lattice.20and.20has_sup/near/316497982 theorem iSup_iInf_ge_nat_add (f : ℕ → α) (k : ℕ) : ⨆ n, ⨅ i ≥ n, f (i + k) = ⨆ n, ⨅ i ≥ n, f i := by have hf : Monotone fun n => ⨅ i ≥ n, f i := fun n m h => biInf_mono fun i => h.trans rw [← Monotone.iSup_nat_add hf k] · simp_rw [iInf_ge_eq_iInf_nat_add, ← Nat.add_assoc] -- Not `@[simp]` since the subterm `?f (i + ?k)` produces an ugly higher-order unification problem. -- (Although the `simpNF` linter does not complain.) -- See: https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/complete_lattice.20and.20has_sup/near/316497982 theorem iInf_iSup_ge_nat_add : ∀ (f : ℕ → α) (k : ℕ), ⨅ n, ⨆ i ≥ n, f (i + k) = ⨅ n, ⨆ i ≥ n, f i := @iSup_iInf_ge_nat_add αᵒᵈ _ theorem sup_iSup_nat_succ (u : ℕ → α) : (u 0 ⊔ ⨆ i, u (i + 1)) = ⨆ i, u i := calc (u 0 ⊔ ⨆ i, u (i + 1)) = ⨆ x ∈ {0} ∪ range Nat.succ, u x := by { rw [iSup_union, iSup_singleton, iSup_range] } _ = ⨆ i, u i := by rw [Nat.zero_union_range_succ, iSup_univ] theorem inf_iInf_nat_succ (u : ℕ → α) : (u 0 ⊓ ⨅ i, u (i + 1)) = ⨅ i, u i := @sup_iSup_nat_succ αᵒᵈ _ u theorem iInf_nat_gt_zero_eq (f : ℕ → α) : ⨅ i > 0, f i = ⨅ i, f (i + 1) := by rw [← iInf_range, Nat.range_succ] simp theorem iSup_nat_gt_zero_eq (f : ℕ → α) : ⨆ i > 0, f i = ⨆ i, f (i + 1) := @iInf_nat_gt_zero_eq αᵒᵈ _ f end /-! ### Instances -/ section CompleteLattice variable [CompleteLattice α] {a : α} {s : Set α} /-- This is a weaker version of `sup_sInf_eq` -/ theorem sup_sInf_le_iInf_sup : a ⊔ sInf s ≤ ⨅ b ∈ s, a ⊔ b := le_iInf₂ fun _ h => sup_le_sup_left (sInf_le h) _ /-- This is a weaker version of `inf_sSup_eq` -/ theorem iSup_inf_le_inf_sSup : ⨆ b ∈ s, a ⊓ b ≤ a ⊓ sSup s := @sup_sInf_le_iInf_sup αᵒᵈ _ _ _ /-- This is a weaker version of `sInf_sup_eq` -/ theorem sInf_sup_le_iInf_sup : sInf s ⊔ a ≤ ⨅ b ∈ s, b ⊔ a := le_iInf₂ fun _ h => sup_le_sup_right (sInf_le h) _ /-- This is a weaker version of `sSup_inf_eq` -/ theorem iSup_inf_le_sSup_inf : ⨆ b ∈ s, b ⊓ a ≤ sSup s ⊓ a := @sInf_sup_le_iInf_sup αᵒᵈ _ _ _ theorem le_iSup_inf_iSup (f g : ι → α) : ⨆ i, f i ⊓ g i ≤ (⨆ i, f i) ⊓ ⨆ i, g i := le_inf (iSup_mono fun _ => inf_le_left) (iSup_mono fun _ => inf_le_right) theorem iInf_sup_iInf_le (f g : ι → α) : (⨅ i, f i) ⊔ ⨅ i, g i ≤ ⨅ i, f i ⊔ g i := @le_iSup_inf_iSup αᵒᵈ ι _ f g theorem disjoint_sSup_left {a : Set α} {b : α} (d : Disjoint (sSup a) b) {i} (hi : i ∈ a) : Disjoint i b := disjoint_iff_inf_le.mpr (iSup₂_le_iff.1 (iSup_inf_le_sSup_inf.trans d.le_bot) i hi :) theorem disjoint_sSup_right {a : Set α} {b : α} (d : Disjoint b (sSup a)) {i} (hi : i ∈ a) : Disjoint b i := disjoint_iff_inf_le.mpr (iSup₂_le_iff.mp (iSup_inf_le_inf_sSup.trans d.le_bot) i hi :) lemma disjoint_of_sSup_disjoint_of_le_of_le {a b : α} {c d : Set α} (hs : ∀ e ∈ c, e ≤ a) (ht : ∀ e ∈ d, e ≤ b) (hd : Disjoint a b) (he : ⊥ ∉ c ∨ ⊥ ∉ d) : Disjoint c d := by rw [disjoint_iff_forall_ne] intro x hx y hy rw [Disjoint.ne_iff] · aesop · exact Disjoint.mono (hs x hx) (ht y hy) hd lemma disjoint_of_sSup_disjoint {a b : Set α} (hd : Disjoint (sSup a) (sSup b)) (he : ⊥ ∉ a ∨ ⊥ ∉ b) : Disjoint a b := disjoint_of_sSup_disjoint_of_le_of_le (fun _ hc ↦ le_sSup hc) (fun _ hc ↦ le_sSup hc) hd he end CompleteLattice namespace ULift universe v instance supSet [SupSet α] : SupSet (ULift.{v} α) where sSup s := ULift.up (sSup <| ULift.up ⁻¹' s) theorem down_sSup [SupSet α] (s : Set (ULift.{v} α)) : (sSup s).down = sSup (ULift.up ⁻¹' s) := rfl theorem up_sSup [SupSet α] (s : Set α) : up (sSup s) = sSup (ULift.down ⁻¹' s) := rfl instance infSet [InfSet α] : InfSet (ULift.{v} α) where sInf s := ULift.up (sInf <| ULift.up ⁻¹' s) theorem down_sInf [InfSet α] (s : Set (ULift.{v} α)) : (sInf s).down = sInf (ULift.up ⁻¹' s) := rfl theorem up_sInf [InfSet α] (s : Set α) : up (sInf s) = sInf (ULift.down ⁻¹' s) := rfl theorem down_iSup [SupSet α] (f : ι → ULift.{v} α) : (⨆ i, f i).down = ⨆ i, (f i).down := congr_arg sSup <| (preimage_eq_iff_eq_image ULift.up_bijective).mpr <| Eq.symm (range_comp _ _).symm theorem up_iSup [SupSet α] (f : ι → α) : up (⨆ i, f i) = ⨆ i, up (f i) := congr_arg ULift.up <| (down_iSup _).symm theorem down_iInf [InfSet α] (f : ι → ULift.{v} α) : (⨅ i, f i).down = ⨅ i, (f i).down := congr_arg sInf <| (preimage_eq_iff_eq_image ULift.up_bijective).mpr <| Eq.symm (range_comp _ _).symm theorem up_iInf [InfSet α] (f : ι → α) : up (⨅ i, f i) = ⨅ i, up (f i) := congr_arg ULift.up <| (down_iInf _).symm instance instCompleteLattice [CompleteLattice α] : CompleteLattice (ULift.{v} α) := ULift.down_injective.completeLattice _ down_sup down_inf (fun s => by rw [sSup_eq_iSup', down_iSup, iSup_subtype'']) (fun s => by rw [sInf_eq_iInf', down_iInf, iInf_subtype'']) down_top down_bot end ULift namespace PUnit instance instCompleteLinearOrder : CompleteLinearOrder PUnit where __ := instBooleanAlgebra __ := instLinearOrder sSup := fun _ => unit sInf := fun _ => unit le_sSup := by intros; trivial sSup_le := by intros; trivial sInf_le := by intros; trivial le_sInf := by intros; trivial le_himp_iff := by intros; trivial himp_bot := by intros; trivial sdiff_le_iff := by intros; trivial top_sdiff := by intros; trivial end PUnit
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/Group.lean
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual import Mathlib.Order.CompleteLattice.Basic /-! # Complete lattices and groups -/ variable {α : Type*} {ι : Sort*} {κ : ι → Sort*} [CompleteLattice α] [Mul α] [MulLeftMono α] [MulRightMono α] @[to_additive] lemma iSup_mul_le (u v : ι → α) : ⨆ i, u i * v i ≤ (⨆ i, u i) * ⨆ i, v i := iSup_le fun _ ↦ mul_le_mul' (le_iSup ..) (le_iSup ..) @[to_additive] lemma le_iInf_mul (u v : ι → α) : (⨅ i, u i) * ⨅ i, v i ≤ ⨅ i, u i * v i := iSup_mul_le (α := αᵒᵈ) .. @[to_additive] lemma iSup₂_mul_le (u v : (i : ι) → κ i → α) : ⨆ (i) (j), u i j * v i j ≤ (⨆ (i) (j), u i j) * ⨆ (i) (j), v i j := by refine le_trans ?_ (iSup_mul_le ..) gcongr exact iSup_mul_le .. @[to_additive] lemma le_iInf₂_mul (u v : (i : ι) → κ i → α) : (⨅ (i) (j), u i j) * ⨅ (i) (j), v i j ≤ ⨅ (i) (j), u i j * v i j := iSup₂_mul_le (α := αᵒᵈ) ..
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/Finset.lean
import Mathlib.Data.Finset.Option import Mathlib.Data.Set.Lattice.Image /-! # Lattice operations on finsets This file is concerned with how big lattice or set operations behave when indexed by a finset. See also `Mathlib/Data/Finset/Lattice.lean`, which is concerned with folding binary lattice operations over a finset. -/ assert_not_exists IsOrderedMonoid MonoidWithZero open Function Multiset OrderDual variable {F α β γ ι κ : Type*} section Lattice variable {ι' : Sort*} [CompleteLattice α] /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : Finset ι` of suprema `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `iSup_eq_iSup_finset'` for a version that works for `ι : Sort*`. -/ theorem iSup_eq_iSup_finset (s : ι → α) : ⨆ i, s i = ⨆ t : Finset ι, ⨆ i ∈ t, s i := by classical refine le_antisymm ?_ ?_ · exact iSup_le fun b => le_iSup_of_le {b} <| le_iSup_of_le b <| le_iSup_of_le (by simp) <| le_rfl · exact iSup_le fun t => iSup_le fun b => iSup_le fun _ => le_iSup _ _ /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : Finset ι` of suprema `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `iSup_eq_iSup_finset` for a version that assumes `ι : Type*` but has no `PLift`s. -/ theorem iSup_eq_iSup_finset' (s : ι' → α) : ⨆ i, s i = ⨆ t : Finset (PLift ι'), ⨆ i ∈ t, s (PLift.down i) := by rw [← iSup_eq_iSup_finset, ← Equiv.plift.surjective.iSup_comp]; rfl /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : Finset ι` of infima `⨅ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `iInf_eq_iInf_finset'` for a version that works for `ι : Sort*`. -/ theorem iInf_eq_iInf_finset (s : ι → α) : ⨅ i, s i = ⨅ (t : Finset ι) (i ∈ t), s i := @iSup_eq_iSup_finset αᵒᵈ _ _ _ /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : Finset ι` of infima `⨅ i ∈ t, s i`. This version works for `ι : Sort*`. See `iInf_eq_iInf_finset` for a version that assumes `ι : Type*` but has no `PLift`s. -/ theorem iInf_eq_iInf_finset' (s : ι' → α) : ⨅ i, s i = ⨅ t : Finset (PLift ι'), ⨅ i ∈ t, s (PLift.down i) := @iSup_eq_iSup_finset' αᵒᵈ _ _ _ end Lattice namespace Set variable {ι' : Sort*} /-- Union of an indexed family of sets `s : ι → Set α` is equal to the union of the unions of finite subfamilies. This version assumes `ι : Type*`. See also `iUnion_eq_iUnion_finset'` for a version that works for `ι : Sort*`. -/ theorem iUnion_eq_iUnion_finset (s : ι → Set α) : ⋃ i, s i = ⋃ t : Finset ι, ⋃ i ∈ t, s i := iSup_eq_iSup_finset s /-- Union of an indexed family of sets `s : ι → Set α` is equal to the union of the unions of finite subfamilies. This version works for `ι : Sort*`. See also `iUnion_eq_iUnion_finset` for a version that assumes `ι : Type*` but avoids `PLift`s in the right-hand side. -/ theorem iUnion_eq_iUnion_finset' (s : ι' → Set α) : ⋃ i, s i = ⋃ t : Finset (PLift ι'), ⋃ i ∈ t, s (PLift.down i) := iSup_eq_iSup_finset' s /-- Intersection of an indexed family of sets `s : ι → Set α` is equal to the intersection of the intersections of finite subfamilies. This version assumes `ι : Type*`. See also `iInter_eq_iInter_finset'` for a version that works for `ι : Sort*`. -/ theorem iInter_eq_iInter_finset (s : ι → Set α) : ⋂ i, s i = ⋂ t : Finset ι, ⋂ i ∈ t, s i := iInf_eq_iInf_finset s /-- Intersection of an indexed family of sets `s : ι → Set α` is equal to the intersection of the intersections of finite subfamilies. This version works for `ι : Sort*`. See also `iInter_eq_iInter_finset` for a version that assumes `ι : Type*` but avoids `PLift`s in the right-hand side. -/ theorem iInter_eq_iInter_finset' (s : ι' → Set α) : ⋂ i, s i = ⋂ t : Finset (PLift ι'), ⋂ i ∈ t, s (PLift.down i) := iInf_eq_iInf_finset' s end Set namespace Finset section minimal variable [DecidableEq α] {P : Finset α → Prop} {s : Finset α} theorem maximal_iff_forall_insert (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) : Maximal P s ↔ P s ∧ ∀ x ∉ s, ¬ P (insert x s) := by simp only [Maximal, and_congr_right_iff] exact fun _ ↦ ⟨fun h x hxs hx ↦ hxs <| h hx (subset_insert _ _) (mem_insert_self x s), fun h t ht hst x hxt ↦ by_contra fun hxs ↦ h x hxs (hP ht (insert_subset hxt hst))⟩ theorem minimal_iff_forall_diff_singleton (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) : Minimal P s ↔ P s ∧ ∀ x ∈ s, ¬ P (s.erase x) where mp h := ⟨h.prop, fun x hxs hx ↦ by simpa using h.le_of_le hx (erase_subset _ _) hxs⟩ mpr h := ⟨h.1, fun t ht hts x hxs ↦ by_contra fun hxt ↦ h.2 x hxs <| hP ht (subset_erase.2 ⟨hts, hxt⟩)⟩ end minimal /-! ### Interaction with big lattice/set operations -/ section Lattice theorem iSup_coe [SupSet β] (f : α → β) (s : Finset α) : ⨆ x ∈ (↑s : Set α), f x = ⨆ x ∈ s, f x := rfl theorem iInf_coe [InfSet β] (f : α → β) (s : Finset α) : ⨅ x ∈ (↑s : Set α), f x = ⨅ x ∈ s, f x := rfl variable [CompleteLattice β] theorem iSup_singleton (a : α) (s : α → β) : ⨆ x ∈ ({a} : Finset α), s x = s a := by simp theorem iInf_singleton (a : α) (s : α → β) : ⨅ x ∈ ({a} : Finset α), s x = s a := by simp theorem iSup_option_toFinset (o : Option α) (f : α → β) : ⨆ x ∈ o.toFinset, f x = ⨆ x ∈ o, f x := by simp theorem iInf_option_toFinset (o : Option α) (f : α → β) : ⨅ x ∈ o.toFinset, f x = ⨅ x ∈ o, f x := @iSup_option_toFinset _ βᵒᵈ _ _ _ variable [DecidableEq α] theorem iSup_union {f : α → β} {s t : Finset α} : ⨆ x ∈ s ∪ t, f x = (⨆ x ∈ s, f x) ⊔ ⨆ x ∈ t, f x := by simp [iSup_or, iSup_sup_eq] theorem iInf_union {f : α → β} {s t : Finset α} : ⨅ x ∈ s ∪ t, f x = (⨅ x ∈ s, f x) ⊓ ⨅ x ∈ t, f x := @iSup_union α βᵒᵈ _ _ _ _ _ theorem iSup_insert (a : α) (s : Finset α) (t : α → β) : ⨆ x ∈ insert a s, t x = t a ⊔ ⨆ x ∈ s, t x := by rw [insert_eq] simp only [iSup_union, Finset.iSup_singleton] theorem iInf_insert (a : α) (s : Finset α) (t : α → β) : ⨅ x ∈ insert a s, t x = t a ⊓ ⨅ x ∈ s, t x := @iSup_insert α βᵒᵈ _ _ _ _ _ theorem iSup_finset_image {f : γ → α} {g : α → β} {s : Finset γ} : ⨆ x ∈ s.image f, g x = ⨆ y ∈ s, g (f y) := by rw [← iSup_coe, coe_image, iSup_image, iSup_coe] theorem iInf_finset_image {f : γ → α} {g : α → β} {s : Finset γ} : ⨅ x ∈ s.image f, g x = ⨅ y ∈ s, g (f y) := by rw [← iInf_coe, coe_image, iInf_image, iInf_coe] theorem iSup_insert_update {x : α} {t : Finset α} (f : α → β) {s : β} (hx : x ∉ t) : ⨆ i ∈ insert x t, Function.update f x s i = s ⊔ ⨆ i ∈ t, f i := by simp only [Finset.iSup_insert, update_self] rcongr (i hi); apply update_of_ne; rintro rfl; exact hx hi theorem iInf_insert_update {x : α} {t : Finset α} (f : α → β) {s : β} (hx : x ∉ t) : ⨅ i ∈ insert x t, update f x s i = s ⊓ ⨅ i ∈ t, f i := @iSup_insert_update α βᵒᵈ _ _ _ _ f _ hx theorem iSup_biUnion (s : Finset γ) (t : γ → Finset α) (f : α → β) : ⨆ y ∈ s.biUnion t, f y = ⨆ (x ∈ s) (y ∈ t x), f y := by simp [@iSup_comm _ α, iSup_and] theorem iInf_biUnion (s : Finset γ) (t : γ → Finset α) (f : α → β) : ⨅ y ∈ s.biUnion t, f y = ⨅ (x ∈ s) (y ∈ t x), f y := @iSup_biUnion _ βᵒᵈ _ _ _ _ _ _ end Lattice theorem set_biUnion_coe (s : Finset α) (t : α → Set β) : ⋃ x ∈ (↑s : Set α), t x = ⋃ x ∈ s, t x := rfl theorem set_biInter_coe (s : Finset α) (t : α → Set β) : ⋂ x ∈ (↑s : Set α), t x = ⋂ x ∈ s, t x := rfl theorem set_biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Finset α), s x = s a := iSup_singleton a s theorem set_biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Finset α), s x = s a := iInf_singleton a s @[simp] theorem set_biUnion_preimage_singleton (f : α → β) (s : Finset β) : ⋃ y ∈ s, f ⁻¹' {y} = f ⁻¹' s := Set.biUnion_preimage_singleton f s theorem set_biUnion_option_toFinset (o : Option α) (f : α → Set β) : ⋃ x ∈ o.toFinset, f x = ⋃ x ∈ o, f x := iSup_option_toFinset o f theorem set_biInter_option_toFinset (o : Option α) (f : α → Set β) : ⋂ x ∈ o.toFinset, f x = ⋂ x ∈ o, f x := iInf_option_toFinset o f theorem subset_set_biUnion_of_mem {s : Finset α} {f : α → Set β} {x : α} (h : x ∈ s) : f x ⊆ ⋃ y ∈ s, f y := show f x ≤ ⨆ y ∈ s, f y from le_iSup_of_le x <| by simp only [h, iSup_pos, le_refl] variable [DecidableEq α] theorem set_biUnion_union (s t : Finset α) (u : α → Set β) : ⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x := iSup_union theorem set_biInter_inter (s t : Finset α) (u : α → Set β) : ⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x := iInf_union theorem set_biUnion_insert (a : α) (s : Finset α) (t : α → Set β) : ⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := iSup_insert a s t theorem set_biInter_insert (a : α) (s : Finset α) (t : α → Set β) : ⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := iInf_insert a s t theorem set_biUnion_finset_image {f : γ → α} {g : α → Set β} {s : Finset γ} : ⋃ x ∈ s.image f, g x = ⋃ y ∈ s, g (f y) := iSup_finset_image theorem set_biInter_finset_image {f : γ → α} {g : α → Set β} {s : Finset γ} : ⋂ x ∈ s.image f, g x = ⋂ y ∈ s, g (f y) := iInf_finset_image theorem set_biUnion_insert_update {x : α} {t : Finset α} (f : α → Set β) {s : Set β} (hx : x ∉ t) : ⋃ i ∈ insert x t, @update _ _ _ f x s i = s ∪ ⋃ i ∈ t, f i := iSup_insert_update f hx theorem set_biInter_insert_update {x : α} {t : Finset α} (f : α → Set β) {s : Set β} (hx : x ∉ t) : ⋂ i ∈ insert x t, @update _ _ _ f x s i = s ∩ ⋂ i ∈ t, f i := iInf_insert_update f hx theorem set_biUnion_biUnion (s : Finset γ) (t : γ → Finset α) (f : α → Set β) : ⋃ y ∈ s.biUnion t, f y = ⋃ (x ∈ s) (y ∈ t x), f y := iSup_biUnion s t f theorem set_biInter_biUnion (s : Finset γ) (t : γ → Finset α) (f : α → Set β) : ⋂ y ∈ s.biUnion t, f y = ⋂ (x ∈ s) (y ∈ t x), f y := iInf_biUnion s t f end Finset
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/Basic.lean
import Mathlib.Data.Set.NAry import Mathlib.Data.ULift import Mathlib.Order.CompleteLattice.Defs import Mathlib.Order.Hom.Set /-! # Theory of complete lattices This file contains basic results on complete lattices. ## Naming conventions In lemma names, * `sSup` is called `sSup` * `sInf` is called `sInf` * `⨆ i, s i` is called `iSup` * `⨅ i, s i` is called `iInf` * `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`. * `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`. * `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂` where `j : i ∈ s`. * `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂` where `j : i ∈ s`. ## Notation * `⨆ i, f i` : `iSup f`, the supremum of the range of `f`; * `⨅ i, f i` : `iInf f`, the infimum of the range of `f`. -/ open Function OrderDual Set variable {α β γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*} @[simp] lemma iSup_ulift {ι : Type*} [SupSet α] (f : ULift ι → α) : ⨆ i : ULift ι, f i = ⨆ i, f (.up i) := by simp only [iSup]; congr with x; simp @[simp] lemma iInf_ulift {ι : Type*} [InfSet α] (f : ULift ι → α) : ⨅ i : ULift ι, f i = ⨅ i, f (.up i) := by simp only [iInf]; congr with x; simp section variable [CompleteSemilatticeSup α] {s t : Set α} {a b : α} theorem sSup_le_sSup_of_isCofinalFor (h : IsCofinalFor s t) : sSup s ≤ sSup t := IsLeast.mono (isLUB_sSup t) (isLUB_sSup s) <| upperBounds_mono_of_isCofinalFor h @[deprecated "use `sSup_le_sSup_of_isCofinalFor` instead" (since := "2025-07-14")] theorem sSup_le_sSup_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) : sSup s ≤ sSup t := sSup_le_sSup_of_isCofinalFor h -- We will generalize this to conditionally complete lattices in `csSup_singleton`. @[simp] theorem sSup_singleton {a : α} : sSup {a} = a := isLUB_singleton.sSup_eq end section variable [CompleteSemilatticeInf α] {s t : Set α} {a b : α} theorem sInf_le_sInf_of_isCoinitialFor (h : IsCoinitialFor s t) : sInf t ≤ sInf s := IsGreatest.mono (isGLB_sInf t) (isGLB_sInf s) <| lowerBounds_mono_of_isCoinitialFor h @[deprecated "use `sInf_le_sInf_of_isCoinitialFor` instead" (since := "2025-07-14")] theorem sInf_le_sInf_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) : sInf t ≤ sInf s := sInf_le_sInf_of_isCoinitialFor h -- We will generalize this to conditionally complete lattices in `csInf_singleton`. @[simp] theorem sInf_singleton {a : α} : sInf {a} = a := isGLB_singleton.sInf_eq end open OrderDual section variable [CompleteLattice α] {s t : Set α} {b : α} theorem sInf_le_sSup (hs : s.Nonempty) : sInf s ≤ sSup s := isGLB_le_isLUB (isGLB_sInf s) (isLUB_sSup s) hs theorem sSup_union {s t : Set α} : sSup (s ∪ t) = sSup s ⊔ sSup t := ((isLUB_sSup s).union (isLUB_sSup t)).sSup_eq theorem sInf_union {s t : Set α} : sInf (s ∪ t) = sInf s ⊓ sInf t := ((isGLB_sInf s).union (isGLB_sInf t)).sInf_eq theorem sSup_inter_le {s t : Set α} : sSup (s ∩ t) ≤ sSup s ⊓ sSup t := sSup_le fun _ hb => le_inf (le_sSup hb.1) (le_sSup hb.2) theorem le_sInf_inter {s t : Set α} : sInf s ⊔ sInf t ≤ sInf (s ∩ t) := @sSup_inter_le αᵒᵈ _ _ _ @[simp] theorem sSup_empty : sSup ∅ = (⊥ : α) := (@isLUB_empty α _ _).sSup_eq @[simp] theorem sInf_empty : sInf ∅ = (⊤ : α) := (@isGLB_empty α _ _).sInf_eq @[simp] theorem sSup_univ : sSup univ = (⊤ : α) := (@isLUB_univ α _ _).sSup_eq @[simp] theorem sInf_univ : sInf univ = (⊥ : α) := (@isGLB_univ α _ _).sInf_eq -- TODO(Jeremy): get this automatically @[simp] theorem sSup_insert {a : α} {s : Set α} : sSup (insert a s) = a ⊔ sSup s := ((isLUB_sSup s).insert a).sSup_eq @[simp] theorem sInf_insert {a : α} {s : Set α} : sInf (insert a s) = a ⊓ sInf s := ((isGLB_sInf s).insert a).sInf_eq theorem sSup_le_sSup_of_subset_insert_bot (h : s ⊆ insert ⊥ t) : sSup s ≤ sSup t := (sSup_le_sSup h).trans_eq (sSup_insert.trans (bot_sup_eq _)) theorem sInf_le_sInf_of_subset_insert_top (h : s ⊆ insert ⊤ t) : sInf t ≤ sInf s := (sInf_le_sInf h).trans_eq' (sInf_insert.trans (top_inf_eq _)).symm @[simp] theorem sSup_diff_singleton_bot (s : Set α) : sSup (s \ {⊥}) = sSup s := (sSup_le_sSup diff_subset).antisymm <| sSup_le_sSup_of_subset_insert_bot <| subset_insert_diff_singleton _ _ @[simp] theorem sInf_diff_singleton_top (s : Set α) : sInf (s \ {⊤}) = sInf s := @sSup_diff_singleton_bot αᵒᵈ _ s theorem sSup_pair {a b : α} : sSup {a, b} = a ⊔ b := (@isLUB_pair α _ a b).sSup_eq theorem sInf_pair {a b : α} : sInf {a, b} = a ⊓ b := (@isGLB_pair α _ a b).sInf_eq @[simp] theorem sSup_eq_bot : sSup s = ⊥ ↔ ∀ a ∈ s, a = ⊥ := ⟨fun h _ ha => bot_unique <| h ▸ le_sSup ha, fun h => bot_unique <| sSup_le fun a ha => le_bot_iff.2 <| h a ha⟩ @[simp] theorem sInf_eq_top : sInf s = ⊤ ↔ ∀ a ∈ s, a = ⊤ := @sSup_eq_bot αᵒᵈ _ _ lemma sSup_eq_bot' {s : Set α} : sSup s = ⊥ ↔ s = ∅ ∨ s = {⊥} := by rw [sSup_eq_bot, ← subset_singleton_iff_eq, subset_singleton_iff] theorem eq_singleton_bot_of_sSup_eq_bot_of_nonempty {s : Set α} (h_sup : sSup s = ⊥) (hne : s.Nonempty) : s = {⊥} := by rw [Set.eq_singleton_iff_nonempty_unique_mem] rw [sSup_eq_bot] at h_sup exact ⟨hne, h_sup⟩ theorem eq_singleton_top_of_sInf_eq_top_of_nonempty : sInf s = ⊤ → s.Nonempty → s = {⊤} := @eq_singleton_bot_of_sSup_eq_bot_of_nonempty αᵒᵈ _ _ /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w < b`. See `csSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem sSup_eq_of_forall_le_of_forall_lt_exists_gt (h₁ : ∀ a ∈ s, a ≤ b) (h₂ : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b := (sSup_le h₁).eq_of_not_lt fun h => let ⟨_, ha, ha'⟩ := h₂ _ h ((le_sSup ha).trans_lt ha').false /-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w > b`. See `csInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem sInf_eq_of_forall_ge_of_forall_gt_exists_lt : (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b := @sSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _ end /- ### iSup & iInf -/ section SupSet variable [SupSet α] {f g : ι → α} theorem sSup_range : sSup (range f) = iSup f := rfl theorem sSup_eq_iSup' (s : Set α) : sSup s = ⨆ a : s, (a : α) := by rw [iSup, Subtype.range_coe] theorem iSup_congr (h : ∀ i, f i = g i) : ⨆ i, f i = ⨆ i, g i := congr_arg _ <| funext h theorem biSup_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) : ⨆ (i) (_ : p i), f i = ⨆ (i) (_ : p i), g i := iSup_congr fun i ↦ iSup_congr (h i) theorem biSup_congr' {p : ι → Prop} {f g : (i : ι) → p i → α} (h : ∀ i (hi : p i), f i hi = g i hi) : ⨆ i, ⨆ (hi : p i), f i hi = ⨆ i, ⨆ (hi : p i), g i hi := by grind theorem Function.Surjective.iSup_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : ⨆ x, g (f x) = ⨆ y, g y := by simp only [iSup.eq_1] congr exact hf.range_comp g theorem Equiv.iSup_comp {g : ι' → α} (e : ι ≃ ι') : ⨆ x, g (e x) = ⨆ y, g y := e.surjective.iSup_comp _ protected theorem Function.Surjective.iSup_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⨆ x, f x = ⨆ y, g y := by convert h1.iSup_comp g exact (h2 _).symm protected theorem Equiv.iSup_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) : ⨆ x, f x = ⨆ y, g y := e.surjective.iSup_congr _ h @[congr] theorem iSup_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iSup f₁ = iSup f₂ := by obtain rfl := propext pq congr with x apply f theorem iSup_plift_up (f : PLift ι → α) : ⨆ i, f (PLift.up i) = ⨆ i, f i := (PLift.up_surjective.iSup_congr _) fun _ => rfl theorem iSup_plift_down (f : ι → α) : ⨆ i, f (PLift.down i) = ⨆ i, f i := (PLift.down_surjective.iSup_congr _) fun _ => rfl theorem iSup_range' (g : β → α) (f : ι → β) : ⨆ b : range f, g b = ⨆ i, g (f i) := by rw [iSup, iSup, ← image_eq_range, ← range_comp'] theorem sSup_image' {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a : s, f a := by rw [iSup, image_eq_range] end SupSet section InfSet variable [InfSet α] {f g : ι → α} theorem sInf_range : sInf (range f) = iInf f := rfl theorem sInf_eq_iInf' (s : Set α) : sInf s = ⨅ a : s, (a : α) := @sSup_eq_iSup' αᵒᵈ _ _ theorem iInf_congr (h : ∀ i, f i = g i) : ⨅ i, f i = ⨅ i, g i := congr_arg _ <| funext h theorem biInf_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) : ⨅ (i) (_ : p i), f i = ⨅ (i) (_ : p i), g i := biSup_congr (α := αᵒᵈ) h theorem biInf_congr' {p : ι → Prop} {f g : (i : ι) → p i → α} (h : ∀ i (hi : p i), f i hi = g i hi) : ⨅ i, ⨅ (hi : p i), f i hi = ⨅ i, ⨅ (hi : p i), g i hi := by grind theorem Function.Surjective.iInf_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : ⨅ x, g (f x) = ⨅ y, g y := @Function.Surjective.iSup_comp αᵒᵈ _ _ _ f hf g theorem Equiv.iInf_comp {g : ι' → α} (e : ι ≃ ι') : ⨅ x, g (e x) = ⨅ y, g y := @Equiv.iSup_comp αᵒᵈ _ _ _ _ e protected theorem Function.Surjective.iInf_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⨅ x, f x = ⨅ y, g y := @Function.Surjective.iSup_congr αᵒᵈ _ _ _ _ _ h h1 h2 protected theorem Equiv.iInf_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) : ⨅ x, f x = ⨅ y, g y := @Equiv.iSup_congr αᵒᵈ _ _ _ _ _ e h @[congr] theorem iInf_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInf f₁ = iInf f₂ := @iSup_congr_Prop αᵒᵈ _ p q f₁ f₂ pq f theorem iInf_plift_up (f : PLift ι → α) : ⨅ i, f (PLift.up i) = ⨅ i, f i := (PLift.up_surjective.iInf_congr _) fun _ => rfl theorem iInf_plift_down (f : ι → α) : ⨅ i, f (PLift.down i) = ⨅ i, f i := (PLift.down_surjective.iInf_congr _) fun _ => rfl theorem iInf_range' (g : β → α) (f : ι → β) : ⨅ b : range f, g b = ⨅ i, g (f i) := @iSup_range' αᵒᵈ _ _ _ _ _ theorem sInf_image' {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a : s, f a := @sSup_image' αᵒᵈ _ _ _ _ end InfSet section variable [CompleteLattice α] {f g s : ι → α} {a b : α} theorem le_iSup (f : ι → α) (i : ι) : f i ≤ iSup f := le_sSup ⟨i, rfl⟩ theorem iInf_le (f : ι → α) (i : ι) : iInf f ≤ f i := sInf_le ⟨i, rfl⟩ lemma iInf_le_iSup [Nonempty ι] : ⨅ i, f i ≤ ⨆ i, f i := (iInf_le _ (Classical.arbitrary _)).trans <| le_iSup _ (Classical.arbitrary _) theorem isLUB_iSup : IsLUB (range f) (⨆ j, f j) := isLUB_sSup _ theorem isGLB_iInf : IsGLB (range f) (⨅ j, f j) := isGLB_sInf _ theorem IsLUB.iSup_eq (h : IsLUB (range f) a) : ⨆ j, f j = a := h.sSup_eq theorem IsGLB.iInf_eq (h : IsGLB (range f) a) : ⨅ j, f j = a := h.sInf_eq theorem le_iSup_of_le (i : ι) (h : a ≤ f i) : a ≤ iSup f := h.trans <| le_iSup _ i theorem iInf_le_of_le (i : ι) (h : f i ≤ a) : iInf f ≤ a := (iInf_le _ i).trans h theorem le_iSup₂ {f : ∀ i, κ i → α} (i : ι) (j : κ i) : f i j ≤ ⨆ (i) (j), f i j := le_iSup_of_le i <| le_iSup (f i) j theorem iInf₂_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) : ⨅ (i) (j), f i j ≤ f i j := iInf_le_of_le i <| iInf_le (f i) j theorem le_iSup₂_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : a ≤ f i j) : a ≤ ⨆ (i) (j), f i j := h.trans <| le_iSup₂ i j theorem iInf₂_le_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : f i j ≤ a) : ⨅ (i) (j), f i j ≤ a := (iInf₂_le i j).trans h theorem iSup_le (h : ∀ i, f i ≤ a) : iSup f ≤ a := sSup_le fun _ ⟨i, Eq⟩ => Eq ▸ h i theorem le_iInf (h : ∀ i, a ≤ f i) : a ≤ iInf f := le_sInf fun _ ⟨i, Eq⟩ => Eq ▸ h i theorem iSup₂_le {f : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ a) : ⨆ (i) (j), f i j ≤ a := iSup_le fun i => iSup_le <| h i theorem le_iInf₂ {f : ∀ i, κ i → α} (h : ∀ i j, a ≤ f i j) : a ≤ ⨅ (i) (j), f i j := le_iInf fun i => le_iInf <| h i theorem iSup₂_le_iSup (κ : ι → Sort*) (f : ι → α) : ⨆ (i) (_ : κ i), f i ≤ ⨆ i, f i := iSup₂_le fun i _ => le_iSup f i theorem iInf_le_iInf₂ (κ : ι → Sort*) (f : ι → α) : ⨅ i, f i ≤ ⨅ (i) (_ : κ i), f i := le_iInf₂ fun i _ => iInf_le f i @[gcongr] theorem iSup_mono (h : ∀ i, f i ≤ g i) : iSup f ≤ iSup g := iSup_le fun i => le_iSup_of_le i <| h i @[gcongr] theorem iInf_mono (h : ∀ i, f i ≤ g i) : iInf f ≤ iInf g := le_iInf fun i => iInf_le_of_le i <| h i theorem iSup₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) : ⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j := iSup_mono fun i => iSup_mono <| h i theorem iInf₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) : ⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j := iInf_mono fun i => iInf_mono <| h i theorem iSup_mono' {g : ι' → α} (h : ∀ i, ∃ i', f i ≤ g i') : iSup f ≤ iSup g := iSup_le fun i => Exists.elim (h i) le_iSup_of_le theorem iInf_mono' {g : ι' → α} (h : ∀ i', ∃ i, f i ≤ g i') : iInf f ≤ iInf g := le_iInf fun i' => Exists.elim (h i') iInf_le_of_le theorem iSup₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i j ≤ g i' j') : ⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j := iSup₂_le fun i j => let ⟨i', j', h⟩ := h i j le_iSup₂_of_le i' j' h theorem iInf₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i' j' ≤ g i j) : ⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j := le_iInf₂ fun i j => let ⟨i', j', h⟩ := h i j iInf₂_le_of_le i' j' h theorem iSup_const_mono (h : ι → ι') : ⨆ _ : ι, a ≤ ⨆ _ : ι', a := iSup_le <| le_iSup _ ∘ h theorem iInf_const_mono (h : ι' → ι) : ⨅ _ : ι, a ≤ ⨅ _ : ι', a := le_iInf <| iInf_le _ ∘ h theorem iSup_iInf_le_iInf_iSup (f : ι → ι' → α) : ⨆ i, ⨅ j, f i j ≤ ⨅ j, ⨆ i, f i j := iSup_le fun i => iInf_mono fun j => le_iSup (fun i => f i j) i theorem biSup_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) : ⨆ (i) (_ : p i), f i ≤ ⨆ (i) (_ : q i), f i := iSup_mono fun i => iSup_const_mono (hpq i) theorem biInf_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) : ⨅ (i) (_ : q i), f i ≤ ⨅ (i) (_ : p i), f i := iInf_mono fun i => iInf_const_mono (hpq i) @[simp] theorem iSup_le_iff : iSup f ≤ a ↔ ∀ i, f i ≤ a := (isLUB_le_iff isLUB_iSup).trans forall_mem_range @[simp] theorem le_iInf_iff : a ≤ iInf f ↔ ∀ i, a ≤ f i := (le_isGLB_iff isGLB_iInf).trans forall_mem_range theorem iSup₂_le_iff {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j ≤ a ↔ ∀ i j, f i j ≤ a := by simp_rw [iSup_le_iff] theorem le_iInf₂_iff {f : ∀ i, κ i → α} : (a ≤ ⨅ (i) (j), f i j) ↔ ∀ i j, a ≤ f i j := by simp_rw [le_iInf_iff] theorem iSup_lt_iff : iSup f < a ↔ ∃ b, b < a ∧ ∀ i, f i ≤ b := ⟨fun h => ⟨iSup f, h, le_iSup f⟩, fun ⟨_, h, hb⟩ => (iSup_le hb).trans_lt h⟩ theorem lt_iInf_iff : a < iInf f ↔ ∃ b, a < b ∧ ∀ i, b ≤ f i := ⟨fun h => ⟨iInf f, h, iInf_le f⟩, fun ⟨_, h, hb⟩ => h.trans_le <| le_iInf hb⟩ theorem sSup_eq_iSup {s : Set α} : sSup s = ⨆ a ∈ s, a := le_antisymm (sSup_le le_iSup₂) (iSup₂_le fun _ => le_sSup) theorem sInf_eq_iInf {s : Set α} : sInf s = ⨅ a ∈ s, a := @sSup_eq_iSup αᵒᵈ _ _ lemma sSup_lowerBounds_eq_sInf (s : Set α) : sSup (lowerBounds s) = sInf s := (isLUB_sSup _).unique (isGLB_sInf _).isLUB lemma sInf_upperBounds_eq_csSup (s : Set α) : sInf (upperBounds s) = sSup s := (isGLB_sInf _).unique (isLUB_sSup _).isGLB theorem Monotone.le_map_iSup [CompleteLattice β] {f : α → β} (hf : Monotone f) : ⨆ i, f (s i) ≤ f (iSup s) := iSup_le fun _ => hf <| le_iSup _ _ theorem Antitone.le_map_iInf [CompleteLattice β] {f : α → β} (hf : Antitone f) : ⨆ i, f (s i) ≤ f (iInf s) := hf.dual_left.le_map_iSup theorem Monotone.le_map_iSup₂ [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) : ⨆ (i) (j), f (s i j) ≤ f (⨆ (i) (j), s i j) := iSup₂_le fun _ _ => hf <| le_iSup₂ _ _ theorem Antitone.le_map_iInf₂ [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) : ⨆ (i) (j), f (s i j) ≤ f (⨅ (i) (j), s i j) := hf.dual_left.le_map_iSup₂ _ theorem Monotone.le_map_sSup [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) : ⨆ a ∈ s, f a ≤ f (sSup s) := by rw [sSup_eq_iSup]; exact hf.le_map_iSup₂ _ theorem Antitone.le_map_sInf [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) : ⨆ a ∈ s, f a ≤ f (sInf s) := hf.dual_left.le_map_sSup theorem OrderIso.map_iSup [CompleteLattice β] (f : α ≃o β) (x : ι → α) : f (⨆ i, x i) = ⨆ i, f (x i) := eq_of_forall_ge_iff <| f.surjective.forall.2 fun x => by simp only [f.le_iff_le, iSup_le_iff] lemma OrderIso.map_iSup₂ [CompleteLattice β] (f : α ≃o β) (x : ∀ i, κ i → α) : f (⨆ i, ⨆ j, x i j) = ⨆ i, ⨆ j, f (x i j) := eq_of_forall_ge_iff <| f.surjective.forall.2 fun x => by simp only [f.le_iff_le, iSup_le_iff] theorem OrderIso.map_iInf [CompleteLattice β] (f : α ≃o β) (x : ι → α) : f (⨅ i, x i) = ⨅ i, f (x i) := OrderIso.map_iSup f.dual _ theorem OrderIso.map_iInf₂ [CompleteLattice β] (f : α ≃o β) (x : ∀ i, κ i → α) : f (⨅ i, ⨅ j, x i j) = ⨅ i, ⨅ j, f (x i j) := OrderIso.map_iSup₂ f.dual _ theorem OrderIso.map_sSup [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sSup s) = ⨆ a ∈ s, f a := by simp only [sSup_eq_iSup, OrderIso.map_iSup] theorem OrderIso.map_sInf [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sInf s) = ⨅ a ∈ s, f a := OrderIso.map_sSup f.dual _ theorem iSup_comp_le {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨆ x, f (g x) ≤ ⨆ y, f y := iSup_mono' fun _ => ⟨_, le_rfl⟩ theorem le_iInf_comp {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨅ y, f y ≤ ⨅ x, f (g x) := iInf_mono' fun _ => ⟨_, le_rfl⟩ theorem Monotone.iSup_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β} (hs : ∀ x, ∃ i, x ≤ s i) : ⨆ x, f (s x) = ⨆ y, f y := le_antisymm (iSup_comp_le _ _) (iSup_mono' fun x => (hs x).imp fun _ hi => hf hi) theorem Monotone.iInf_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β} (hs : ∀ x, ∃ i, s i ≤ x) : ⨅ x, f (s x) = ⨅ y, f y := le_antisymm (iInf_mono' fun x => (hs x).imp fun _ hi => hf hi) (le_iInf_comp _ _) theorem Antitone.map_iSup_le [CompleteLattice β] {f : α → β} (hf : Antitone f) : f (iSup s) ≤ ⨅ i, f (s i) := le_iInf fun _ => hf <| le_iSup _ _ theorem Monotone.map_iInf_le [CompleteLattice β] {f : α → β} (hf : Monotone f) : f (iInf s) ≤ ⨅ i, f (s i) := hf.dual_left.map_iSup_le theorem Antitone.map_iSup₂_le [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) : f (⨆ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) := hf.dual.le_map_iInf₂ _ theorem Monotone.map_iInf₂_le [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) : f (⨅ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) := hf.dual.le_map_iSup₂ _ theorem Antitone.map_sSup_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) : f (sSup s) ≤ ⨅ a ∈ s, f a := by rw [sSup_eq_iSup] exact hf.map_iSup₂_le _ theorem Monotone.map_sInf_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) : f (sInf s) ≤ ⨅ a ∈ s, f a := hf.dual_left.map_sSup_le theorem iSup_const_le : ⨆ _ : ι, a ≤ a := iSup_le fun _ => le_rfl theorem le_iInf_const : a ≤ ⨅ _ : ι, a := le_iInf fun _ => le_rfl -- We generalize this to conditionally complete lattices in `ciSup_const` and `ciInf_const`. theorem iSup_const [Nonempty ι] : ⨆ _ : ι, a = a := by rw [iSup, range_const, sSup_singleton] theorem iInf_const [Nonempty ι] : ⨅ _ : ι, a = a := @iSup_const αᵒᵈ _ _ a _ lemma iSup_unique [Unique ι] (f : ι → α) : ⨆ i, f i = f default := by simp only [congr_arg f (Unique.eq_default _), iSup_const] lemma iInf_unique [Unique ι] (f : ι → α) : ⨅ i, f i = f default := by simp only [congr_arg f (Unique.eq_default _), iInf_const] @[simp] theorem iSup_bot : (⨆ _ : ι, ⊥ : α) = ⊥ := bot_unique iSup_const_le @[simp] theorem iInf_top : (⨅ _ : ι, ⊤ : α) = ⊤ := top_unique le_iInf_const @[simp] theorem iSup_eq_bot : iSup s = ⊥ ↔ ∀ i, s i = ⊥ := sSup_eq_bot.trans forall_mem_range @[simp] theorem iInf_eq_top : iInf s = ⊤ ↔ ∀ i, s i = ⊤ := sInf_eq_top.trans forall_mem_range @[simp] lemma bot_lt_iSup : ⊥ < ⨆ i, s i ↔ ∃ i, ⊥ < s i := by simp [bot_lt_iff_ne_bot] @[simp] lemma iInf_lt_top : ⨅ i, s i < ⊤ ↔ ∃ i, s i < ⊤ := by simp [lt_top_iff_ne_top] theorem iSup₂_eq_bot {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j = ⊥ ↔ ∀ i j, f i j = ⊥ := by simp theorem iInf₂_eq_top {f : ∀ i, κ i → α} : ⨅ (i) (j), f i j = ⊤ ↔ ∀ i j, f i j = ⊤ := by simp @[simp] theorem iSup_pos {p : Prop} {f : p → α} (hp : p) : ⨆ h : p, f h = f hp := le_antisymm (iSup_le fun _ => le_rfl) (le_iSup _ _) @[simp] theorem iInf_pos {p : Prop} {f : p → α} (hp : p) : ⨅ h : p, f h = f hp := le_antisymm (iInf_le _ _) (le_iInf fun _ => le_rfl) @[simp] theorem iSup_neg {p : Prop} {f : p → α} (hp : ¬p) : ⨆ h : p, f h = ⊥ := le_antisymm (iSup_le fun h => (hp h).elim) bot_le @[simp] theorem iInf_neg {p : Prop} {f : p → α} (hp : ¬p) : ⨅ h : p, f h = ⊤ := le_antisymm le_top <| le_iInf fun h => (hp h).elim /-- Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b` is larger than `f i` for all `i`, and that this is not the case of any `w<b`. See `ciSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem iSup_eq_of_forall_le_of_forall_lt_exists_gt {f : ι → α} (h₁ : ∀ i, f i ≤ b) (h₂ : ∀ w, w < b → ∃ i, w < f i) : ⨆ i : ι, f i = b := sSup_eq_of_forall_le_of_forall_lt_exists_gt (forall_mem_range.mpr h₁) fun w hw => exists_range_iff.mpr <| h₂ w hw /-- Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b` is smaller than `f i` for all `i`, and that this is not the case of any `w>b`. See `ciInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem iInf_eq_of_forall_ge_of_forall_gt_exists_lt : (∀ i, b ≤ f i) → (∀ w, b < w → ∃ i, f i < w) → ⨅ i, f i = b := @iSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _ _ theorem iSup_eq_dif {p : Prop} [Decidable p] (a : p → α) : ⨆ h : p, a h = if h : p then a h else ⊥ := by by_cases h : p <;> simp [h] theorem iSup_eq_if {p : Prop} [Decidable p] (a : α) : ⨆ _ : p, a = if p then a else ⊥ := iSup_eq_dif fun _ => a theorem iInf_eq_dif {p : Prop} [Decidable p] (a : p → α) : ⨅ h : p, a h = if h : p then a h else ⊤ := @iSup_eq_dif αᵒᵈ _ _ _ _ theorem iInf_eq_if {p : Prop} [Decidable p] (a : α) : ⨅ _ : p, a = if p then a else ⊤ := iInf_eq_dif fun _ => a theorem iSup_comm {f : ι → ι' → α} : ⨆ (i) (j), f i j = ⨆ (j) (i), f i j := le_antisymm (iSup_le fun i => iSup_mono fun j => le_iSup (fun i => f i j) i) (iSup_le fun _ => iSup_mono fun _ => le_iSup _ _) theorem iInf_comm {f : ι → ι' → α} : ⨅ (i) (j), f i j = ⨅ (j) (i), f i j := @iSup_comm αᵒᵈ _ _ _ _ theorem iSup₂_comm {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} (f : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → α) : ⨆ (i₁) (j₁) (i₂) (j₂), f i₁ j₁ i₂ j₂ = ⨆ (i₂) (j₂) (i₁) (j₁), f i₁ j₁ i₂ j₂ := by simp only [@iSup_comm _ (κ₁ _), @iSup_comm _ ι₁] theorem iInf₂_comm {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} (f : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → α) : ⨅ (i₁) (j₁) (i₂) (j₂), f i₁ j₁ i₂ j₂ = ⨅ (i₂) (j₂) (i₁) (j₁), f i₁ j₁ i₂ j₂ := by simp only [@iInf_comm _ (κ₁ _), @iInf_comm _ ι₁] /- TODO: this is strange. In the proof below, we get exactly the desired among the equalities, but close does not get it. begin apply @le_antisymm, simp, intros, begin [smt] ematch, ematch, ematch, trace_state, have := le_refl (f i_1 i), trace_state, close end end -/ @[simp] theorem iSup_iSup_eq_left {b : β} {f : ∀ x : β, x = b → α} : ⨆ x, ⨆ h : x = b, f x h = f b rfl := (@le_iSup₂ _ _ _ _ f b rfl).antisymm' (iSup_le fun c => iSup_le <| by rintro rfl rfl) @[simp] theorem iInf_iInf_eq_left {b : β} {f : ∀ x : β, x = b → α} : ⨅ x, ⨅ h : x = b, f x h = f b rfl := @iSup_iSup_eq_left αᵒᵈ _ _ _ _ @[simp] theorem iSup_iSup_eq_right {b : β} {f : ∀ x : β, b = x → α} : ⨆ x, ⨆ h : b = x, f x h = f b rfl := (le_iSup₂ b rfl).antisymm' (iSup₂_le fun c => by rintro rfl rfl) @[simp] theorem iInf_iInf_eq_right {b : β} {f : ∀ x : β, b = x → α} : ⨅ x, ⨅ h : b = x, f x h = f b rfl := @iSup_iSup_eq_right αᵒᵈ _ _ _ _ theorem iSup_subtype {p : ι → Prop} {f : Subtype p → α} : iSup f = ⨆ (i) (h : p i), f ⟨i, h⟩ := le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ p _ (fun i h => f ⟨i, h⟩) i h) (iSup₂_le fun _ _ => le_iSup _ _) theorem iInf_subtype : ∀ {p : ι → Prop} {f : Subtype p → α}, iInf f = ⨅ (i) (h : p i), f ⟨i, h⟩ := @iSup_subtype αᵒᵈ _ _ theorem iSup_subtype' {p : ι → Prop} {f : ∀ i, p i → α} : ⨆ (i) (h), f i h = ⨆ x : Subtype p, f x x.property := (@iSup_subtype _ _ _ p fun x => f x.val x.property).symm theorem iInf_subtype' {p : ι → Prop} {f : ∀ i, p i → α} : ⨅ (i) (h : p i), f i h = ⨅ x : Subtype p, f x x.property := (@iInf_subtype _ _ _ p fun x => f x.val x.property).symm theorem iSup_subtype'' {ι} (s : Set ι) (f : ι → α) : ⨆ i : s, f i = ⨆ (t : ι) (_ : t ∈ s), f t := iSup_subtype theorem iInf_subtype'' {ι} (s : Set ι) (f : ι → α) : ⨅ i : s, f i = ⨅ (t : ι) (_ : t ∈ s), f t := iInf_subtype theorem biSup_const {a : α} {s : Set β} (hs : s.Nonempty) : ⨆ i ∈ s, a = a := by haveI : Nonempty s := Set.nonempty_coe_sort.mpr hs rw [← iSup_subtype'', iSup_const] theorem biInf_const {a : α} {s : Set β} (hs : s.Nonempty) : ⨅ i ∈ s, a = a := biSup_const (α := αᵒᵈ) hs theorem iSup_sup_eq : ⨆ x, f x ⊔ g x = (⨆ x, f x) ⊔ ⨆ x, g x := le_antisymm (iSup_le fun _ => sup_le_sup (le_iSup _ _) <| le_iSup _ _) (sup_le (iSup_mono fun _ => le_sup_left) <| iSup_mono fun _ => le_sup_right) theorem iInf_inf_eq : ⨅ x, f x ⊓ g x = (⨅ x, f x) ⊓ ⨅ x, g x := @iSup_sup_eq αᵒᵈ _ _ _ _ lemma Equiv.biSup_comp {ι ι' : Type*} {g : ι' → α} (e : ι ≃ ι') (s : Set ι') : ⨆ i ∈ e.symm '' s, g (e i) = ⨆ i ∈ s, g i := by simpa only [iSup_subtype'] using (image e.symm s).symm.iSup_comp (g := g ∘ (↑)) lemma Equiv.biInf_comp {ι ι' : Type*} {g : ι' → α} (e : ι ≃ ι') (s : Set ι') : ⨅ i ∈ e.symm '' s, g (e i) = ⨅ i ∈ s, g i := e.biSup_comp s (α := αᵒᵈ) lemma biInf_le {ι : Type*} {s : Set ι} (f : ι → α) {i : ι} (hi : i ∈ s) : ⨅ i ∈ s, f i ≤ f i := iInf₂_le i hi lemma le_biSup {ι : Type*} {s : Set ι} (f : ι → α) {i : ι} (hi : i ∈ s) : f i ≤ ⨆ i ∈ s, f i := biInf_le (α := αᵒᵈ) f hi lemma biInf_le_biSup {ι : Type*} {s : Set ι} (hs : s.Nonempty) {f : ι → α} : ⨅ i ∈ s, f i ≤ ⨆ i ∈ s, f i := (biInf_le _ hs.choose_spec).trans <| le_biSup _ hs.choose_spec /- TODO: here is another example where more flexible pattern matching might help. begin apply @le_antisymm, safe, pose h := f a ⊓ g a, begin [smt] ematch, ematch end end -/ theorem iSup_sup [Nonempty ι] {f : ι → α} {a : α} : (⨆ x, f x) ⊔ a = ⨆ x, f x ⊔ a := by rw [iSup_sup_eq, iSup_const] theorem iInf_inf [Nonempty ι] {f : ι → α} {a : α} : (⨅ x, f x) ⊓ a = ⨅ x, f x ⊓ a := by rw [iInf_inf_eq, iInf_const] theorem sup_iSup [Nonempty ι] {f : ι → α} {a : α} : (a ⊔ ⨆ x, f x) = ⨆ x, a ⊔ f x := by rw [iSup_sup_eq, iSup_const] theorem inf_iInf [Nonempty ι] {f : ι → α} {a : α} : (a ⊓ ⨅ x, f x) = ⨅ x, a ⊓ f x := by rw [iInf_inf_eq, iInf_const] theorem biSup_sup {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (⨆ (i) (h : p i), f i h) ⊔ a = ⨆ (i) (h : p i), f i h ⊔ a := by haveI : Nonempty { i // p i } := let ⟨i, hi⟩ := h ⟨⟨i, hi⟩⟩ rw [iSup_subtype', iSup_subtype', iSup_sup] theorem sup_biSup {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (a ⊔ ⨆ (i) (h : p i), f i h) = ⨆ (i) (h : p i), a ⊔ f i h := by simpa only [sup_comm] using @biSup_sup α _ _ p _ _ h theorem biInf_inf {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (⨅ (i) (h : p i), f i h) ⊓ a = ⨅ (i) (h : p i), f i h ⊓ a := @biSup_sup αᵒᵈ ι _ p f _ h theorem inf_biInf {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) : (a ⊓ ⨅ (i) (h : p i), f i h) = ⨅ (i) (h : p i), a ⊓ f i h := @sup_biSup αᵒᵈ ι _ p f _ h lemma biSup_lt_eq_iSup {ι : Type*} [LT ι] [NoMaxOrder ι] {f : ι → α} : ⨆ (i) (j < i), f j = ⨆ i, f i := by apply le_antisymm · exact iSup_le fun _ ↦ iSup₂_le fun _ _ ↦ le_iSup _ _ · refine iSup_le fun j ↦ ?_ obtain ⟨i, jlt⟩ := exists_gt j exact le_iSup_of_le i (le_iSup₂_of_le j jlt le_rfl) lemma biSup_le_eq_iSup {ι : Type*} [Preorder ι] {f : ι → α} : ⨆ (i) (j ≤ i), f j = ⨆ i, f i := by apply le_antisymm · exact iSup_le fun _ ↦ iSup₂_le fun _ _ ↦ le_iSup _ _ · exact iSup_le fun j ↦ le_iSup_of_le j (le_iSup₂_of_le j le_rfl le_rfl) lemma biInf_lt_eq_iInf {ι : Type*} [LT ι] [NoMaxOrder ι] {f : ι → α} : ⨅ (i) (j < i), f j = ⨅ i, f i := biSup_lt_eq_iSup (α := αᵒᵈ) lemma biInf_le_eq_iInf {ι : Type*} [Preorder ι] {f : ι → α} : ⨅ (i) (j ≤ i), f j = ⨅ i, f i := biSup_le_eq_iSup (α := αᵒᵈ) lemma biSup_gt_eq_iSup {ι : Type*} [LT ι] [NoMinOrder ι] {f : ι → α} : ⨆ (i) (j > i), f j = ⨆ i, f i := biSup_lt_eq_iSup (ι := ιᵒᵈ) lemma biSup_ge_eq_iSup {ι : Type*} [Preorder ι] {f : ι → α} : ⨆ (i) (j ≥ i), f j = ⨆ i, f i := biSup_le_eq_iSup (ι := ιᵒᵈ) lemma biInf_gt_eq_iInf {ι : Type*} [LT ι] [NoMinOrder ι] {f : ι → α} : ⨅ (i) (j > i), f j = ⨅ i, f i := biInf_lt_eq_iInf (ι := ιᵒᵈ) lemma biInf_ge_eq_iInf {ι : Type*} [Preorder ι] {f : ι → α} : ⨅ (i) (j ≥ i), f j = ⨅ i, f i := biInf_le_eq_iInf (ι := ιᵒᵈ) lemma biSup_le_eq_of_monotone [Preorder β] {f : β → α} (hf : Monotone f) (b : β) : ⨆ (b' ≤ b), f b' = f b := le_antisymm (iSup₂_le_iff.2 (fun _ hji ↦ hf hji)) (le_iSup_of_le b (ge_of_eq (iSup_pos le_rfl))) lemma biInf_le_eq_of_antitone [Preorder β] {f : β → α} (hf : Antitone f) (b : β) : ⨅ (b' ≤ b), f b' = f b := biSup_le_eq_of_monotone (α := αᵒᵈ) hf.dual_right b lemma biSup_ge_eq_of_antitone [Preorder β] {f : β → α} (hf : Antitone f) (b : β) : ⨆ (b' ≥ b), f b' = f b := biSup_le_eq_of_monotone (β := βᵒᵈ) hf.dual_left b lemma biInf_ge_eq_of_monotone [Preorder β] {f : β → α} (hf : Monotone f) (b : β) : ⨅ (b' ≥ b), f b' = f b := biInf_le_eq_of_antitone (β := βᵒᵈ) hf.dual_left b /-! ### `iSup` and `iInf` under `Prop` -/ theorem iSup_false {s : False → α} : iSup s = ⊥ := by simp theorem iInf_false {s : False → α} : iInf s = ⊤ := by simp theorem iSup_true {s : True → α} : iSup s = s trivial := iSup_pos trivial theorem iInf_true {s : True → α} : iInf s = s trivial := iInf_pos trivial @[simp] theorem iSup_exists {p : ι → Prop} {f : Exists p → α} : ⨆ x, f x = ⨆ (i) (h), f ⟨i, h⟩ := le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ _ _ (fun _ _ => _) i h) (iSup₂_le fun _ _ => le_iSup _ _) @[simp] theorem iInf_exists {p : ι → Prop} {f : Exists p → α} : ⨅ x, f x = ⨅ (i) (h), f ⟨i, h⟩ := @iSup_exists αᵒᵈ _ _ _ _ theorem iSup_and {p q : Prop} {s : p ∧ q → α} : iSup s = ⨆ (h₁) (h₂), s ⟨h₁, h₂⟩ := le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ _ _ (fun _ _ => _) i h) (iSup₂_le fun _ _ => le_iSup _ _) theorem iInf_and {p q : Prop} {s : p ∧ q → α} : iInf s = ⨅ (h₁) (h₂), s ⟨h₁, h₂⟩ := @iSup_and αᵒᵈ _ _ _ _ /-- The symmetric case of `iSup_and`, useful for rewriting into a supremum over a conjunction -/ theorem iSup_and' {p q : Prop} {s : p → q → α} : ⨆ (h₁ : p) (h₂ : q), s h₁ h₂ = ⨆ h : p ∧ q, s h.1 h.2 := Eq.symm iSup_and /-- The symmetric case of `iInf_and`, useful for rewriting into an infimum over a conjunction -/ theorem iInf_and' {p q : Prop} {s : p → q → α} : ⨅ (h₁ : p) (h₂ : q), s h₁ h₂ = ⨅ h : p ∧ q, s h.1 h.2 := Eq.symm iInf_and theorem iSup_or {p q : Prop} {s : p ∨ q → α} : ⨆ x, s x = (⨆ i, s (Or.inl i)) ⊔ ⨆ j, s (Or.inr j) := le_antisymm (iSup_le fun i => match i with | Or.inl _ => le_sup_of_le_left <| le_iSup (fun _ => s _) _ | Or.inr _ => le_sup_of_le_right <| le_iSup (fun _ => s _) _) (sup_le (iSup_comp_le _ _) (iSup_comp_le _ _)) theorem iInf_or {p q : Prop} {s : p ∨ q → α} : ⨅ x, s x = (⨅ i, s (Or.inl i)) ⊓ ⨅ j, s (Or.inr j) := @iSup_or αᵒᵈ _ _ _ _ section variable (p : ι → Prop) [DecidablePred p] theorem iSup_dite (f : ∀ i, p i → α) (g : ∀ i, ¬p i → α) : ⨆ i, (if h : p i then f i h else g i h) = (⨆ (i) (h : p i), f i h) ⊔ ⨆ (i) (h : ¬p i), g i h := by rw [← iSup_sup_eq] congr 1 with i split_ifs with h <;> simp [h] theorem iInf_dite (f : ∀ i, p i → α) (g : ∀ i, ¬p i → α) : ⨅ i, (if h : p i then f i h else g i h) = (⨅ (i) (h : p i), f i h) ⊓ ⨅ (i) (h : ¬p i), g i h := iSup_dite p (show ∀ i, p i → αᵒᵈ from f) g theorem iSup_ite (f g : ι → α) : ⨆ i, (if p i then f i else g i) = (⨆ (i) (_ : p i), f i) ⊔ ⨆ (i) (_ : ¬p i), g i := iSup_dite _ _ _ theorem iInf_ite (f g : ι → α) : ⨅ i, (if p i then f i else g i) = (⨅ (i) (_ : p i), f i) ⊓ ⨅ (i) (_ : ¬p i), g i := iInf_dite _ _ _ end theorem iSup_range {g : β → α} {f : ι → β} : ⨆ b ∈ range f, g b = ⨆ i, g (f i) := by rw [← iSup_subtype'', iSup_range'] theorem iInf_range : ∀ {g : β → α} {f : ι → β}, ⨅ b ∈ range f, g b = ⨅ i, g (f i) := @iSup_range αᵒᵈ _ _ _ theorem sSup_image {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a ∈ s, f a := by rw [← iSup_subtype'', sSup_image'] theorem sInf_image {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a ∈ s, f a := @sSup_image αᵒᵈ _ _ _ _ theorem OrderIso.map_sSup_eq_sSup_symm_preimage [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sSup s) = sSup (f.symm ⁻¹' s) := by rw [map_sSup, ← sSup_image, f.image_eq_preimage_symm] theorem OrderIso.map_sInf_eq_sInf_symm_preimage [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sInf s) = sInf (f.symm ⁻¹' s) := by rw [map_sInf, ← sInf_image, f.image_eq_preimage_symm] /- ### iSup and iInf under set constructions -/ theorem iSup_emptyset {f : β → α} : ⨆ x ∈ (∅ : Set β), f x = ⊥ := by simp theorem iInf_emptyset {f : β → α} : ⨅ x ∈ (∅ : Set β), f x = ⊤ := by simp theorem iSup_univ {f : β → α} : ⨆ x ∈ (univ : Set β), f x = ⨆ x, f x := by simp theorem iInf_univ {f : β → α} : ⨅ x ∈ (univ : Set β), f x = ⨅ x, f x := by simp theorem iSup_union {f : β → α} {s t : Set β} : ⨆ x ∈ s ∪ t, f x = (⨆ x ∈ s, f x) ⊔ ⨆ x ∈ t, f x := by simp_rw [mem_union, iSup_or, iSup_sup_eq] theorem iInf_union {f : β → α} {s t : Set β} : ⨅ x ∈ s ∪ t, f x = (⨅ x ∈ s, f x) ⊓ ⨅ x ∈ t, f x := @iSup_union αᵒᵈ _ _ _ _ _ theorem iSup_split (f : β → α) (p : β → Prop) : ⨆ i, f i = (⨆ (i) (_ : p i), f i) ⊔ ⨆ (i) (_ : ¬p i), f i := by simpa [Classical.em] using @iSup_union _ _ _ f { i | p i } { i | ¬p i } theorem iInf_split : ∀ (f : β → α) (p : β → Prop), ⨅ i, f i = (⨅ (i) (_ : p i), f i) ⊓ ⨅ (i) (_ : ¬p i), f i := @iSup_split αᵒᵈ _ _ theorem iSup_split_single (f : β → α) (i₀ : β) : ⨆ i, f i = f i₀ ⊔ ⨆ (i) (_ : i ≠ i₀), f i := by convert iSup_split f (fun i => i = i₀) simp theorem iInf_split_single (f : β → α) (i₀ : β) : ⨅ i, f i = f i₀ ⊓ ⨅ (i) (_ : i ≠ i₀), f i := @iSup_split_single αᵒᵈ _ _ _ _ theorem iSup_le_iSup_of_subset {f : β → α} {s t : Set β} : s ⊆ t → ⨆ x ∈ s, f x ≤ ⨆ x ∈ t, f x := biSup_mono theorem iInf_le_iInf_of_subset {f : β → α} {s t : Set β} : s ⊆ t → ⨅ x ∈ t, f x ≤ ⨅ x ∈ s, f x := biInf_mono theorem iSup_insert {f : β → α} {s : Set β} {b : β} : ⨆ x ∈ insert b s, f x = f b ⊔ ⨆ x ∈ s, f x := Eq.trans iSup_union <| congr_arg (fun x => x ⊔ ⨆ x ∈ s, f x) iSup_iSup_eq_left theorem iInf_insert {f : β → α} {s : Set β} {b : β} : ⨅ x ∈ insert b s, f x = f b ⊓ ⨅ x ∈ s, f x := Eq.trans iInf_union <| congr_arg (fun x => x ⊓ ⨅ x ∈ s, f x) iInf_iInf_eq_left theorem iSup_singleton {f : β → α} {b : β} : ⨆ x ∈ (singleton b : Set β), f x = f b := by simp theorem iInf_singleton {f : β → α} {b : β} : ⨅ x ∈ (singleton b : Set β), f x = f b := by simp theorem iSup_pair {f : β → α} {a b : β} : ⨆ x ∈ ({a, b} : Set β), f x = f a ⊔ f b := by rw [iSup_insert, iSup_singleton] theorem iInf_pair {f : β → α} {a b : β} : ⨅ x ∈ ({a, b} : Set β), f x = f a ⊓ f b := by rw [iInf_insert, iInf_singleton] theorem iSup_image {γ} {f : β → γ} {g : γ → α} {t : Set β} : ⨆ c ∈ f '' t, g c = ⨆ b ∈ t, g (f b) := by rw [← sSup_image, ← sSup_image, ← image_comp, comp_def] theorem iInf_image : ∀ {γ} {f : β → γ} {g : γ → α} {t : Set β}, ⨅ c ∈ f '' t, g c = ⨅ b ∈ t, g (f b) := @iSup_image αᵒᵈ _ _ theorem iSup_extend_bot {e : ι → β} (he : Injective e) (f : ι → α) : ⨆ j, extend e f ⊥ j = ⨆ i, f i := by rw [iSup_split _ fun j => ∃ i, e i = j] simp +contextual [he.extend_apply, extend_apply', @iSup_comm _ β ι] theorem iInf_extend_top {e : ι → β} (he : Injective e) (f : ι → α) : ⨅ j, extend e f ⊤ j = iInf f := @iSup_extend_bot αᵒᵈ _ _ _ _ he _ section le variable {ι : Type*} [PartialOrder ι] (f : ι → α) (i : ι) theorem biSup_le_eq_sup : (⨆ j ≤ i, f j) = (⨆ j < i, f j) ⊔ f i := by rw [iSup_split_single _ i] -- Squeezed for a ~10x speedup, though it's still reasonably fast unsqueezed. simp only [le_refl, iSup_pos, iSup_and', lt_iff_le_and_ne, and_comm, sup_comm] theorem biInf_le_eq_inf : (⨅ j ≤ i, f j) = (⨅ j < i, f j) ⊓ f i := biSup_le_eq_sup (α := αᵒᵈ) f i theorem biSup_ge_eq_sup : (⨆ j ≥ i, f j) = f i ⊔ (⨆ j > i, f j) := by rw [iSup_split_single _ i] -- Squeezed for a ~10x speedup, though it's still reasonably fast unsqueezed. simp only [ge_iff_le, le_refl, iSup_pos, ne_comm, iSup_and', gt_iff_lt, lt_iff_le_and_ne, and_comm] theorem biInf_ge_eq_inf : (⨅ j ≥ i, f j) = f i ⊓ (⨅ j > i, f j) := biSup_ge_eq_sup (α := αᵒᵈ) f i end le /-! ### `iSup` and `iInf` under `Type` -/ theorem iSup_of_empty' {α ι} [SupSet α] [IsEmpty ι] (f : ι → α) : iSup f = sSup (∅ : Set α) := congr_arg sSup (range_eq_empty f) theorem iInf_of_isEmpty {α ι} [InfSet α] [IsEmpty ι] (f : ι → α) : iInf f = sInf (∅ : Set α) := congr_arg sInf (range_eq_empty f) theorem iSup_of_empty [IsEmpty ι] (f : ι → α) : iSup f = ⊥ := (iSup_of_empty' f).trans sSup_empty theorem iInf_of_empty [IsEmpty ι] (f : ι → α) : iInf f = ⊤ := @iSup_of_empty αᵒᵈ _ _ _ f theorem isGLB_biInf {s : Set β} {f : β → α} : IsGLB (f '' s) (⨅ x ∈ s, f x) := by simpa only [range_comp, Subtype.range_coe, iInf_subtype'] using @isGLB_iInf α s _ (f ∘ fun x => (x : β)) theorem isLUB_biSup {s : Set β} {f : β → α} : IsLUB (f '' s) (⨆ x ∈ s, f x) := by simpa only [range_comp, Subtype.range_coe, iSup_subtype'] using @isLUB_iSup α s _ (f ∘ fun x => (x : β)) theorem iSup_sigma {p : β → Type*} {f : Sigma p → α} : ⨆ x, f x = ⨆ (i) (j), f ⟨i, j⟩ := eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, Sigma.forall] theorem iInf_sigma {p : β → Type*} {f : Sigma p → α} : ⨅ x, f x = ⨅ (i) (j), f ⟨i, j⟩ := @iSup_sigma αᵒᵈ _ _ _ _ lemma iSup_sigma' {κ : β → Type*} (f : ∀ i, κ i → α) : (⨆ i, ⨆ j, f i j) = ⨆ x : Σ i, κ i, f x.1 x.2 := (iSup_sigma (f := fun x ↦ f x.1 x.2)).symm lemma iInf_sigma' {κ : β → Type*} (f : ∀ i, κ i → α) : (⨅ i, ⨅ j, f i j) = ⨅ x : Σ i, κ i, f x.1 x.2 := (iInf_sigma (f := fun x ↦ f x.1 x.2)).symm lemma iSup_psigma {ι : Sort*} {κ : ι → Sort*} (f : (Σ' i, κ i) → α) : ⨆ ij, f ij = ⨆ i, ⨆ j, f ⟨i, j⟩ := eq_of_forall_ge_iff fun c ↦ by simp only [iSup_le_iff, PSigma.forall] lemma iInf_psigma {ι : Sort*} {κ : ι → Sort*} (f : (Σ' i, κ i) → α) : ⨅ ij, f ij = ⨅ i, ⨅ j, f ⟨i, j⟩ := eq_of_forall_le_iff fun c ↦ by simp only [le_iInf_iff, PSigma.forall] lemma iSup_psigma' {ι : Sort*} {κ : ι → Sort*} (f : ∀ i, κ i → α) : (⨆ i, ⨆ j, f i j) = ⨆ ij : Σ' i, κ i, f ij.1 ij.2 := (iSup_psigma fun x ↦ f x.1 x.2).symm lemma iInf_psigma' {ι : Sort*} {κ : ι → Sort*} (f : ∀ i, κ i → α) : (⨅ i, ⨅ j, f i j) = ⨅ ij : Σ' i, κ i, f ij.1 ij.2 := (iInf_psigma fun x ↦ f x.1 x.2).symm theorem iSup_prod {f : β × γ → α} : ⨆ x, f x = ⨆ (i) (j), f (i, j) := eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, Prod.forall] theorem iInf_prod {f : β × γ → α} : ⨅ x, f x = ⨅ (i) (j), f (i, j) := @iSup_prod αᵒᵈ _ _ _ _ lemma iSup_prod' (f : β → γ → α) : (⨆ i, ⨆ j, f i j) = ⨆ x : β × γ, f x.1 x.2 := (iSup_prod (f := fun x ↦ f x.1 x.2)).symm lemma iInf_prod' (f : β → γ → α) : (⨅ i, ⨅ j, f i j) = ⨅ x : β × γ, f x.1 x.2 := (iInf_prod (f := fun x ↦ f x.1 x.2)).symm theorem biSup_prod {f : β × γ → α} {s : Set β} {t : Set γ} : ⨆ x ∈ s ×ˢ t, f x = ⨆ (a ∈ s) (b ∈ t), f (a, b) := by simp_rw [iSup_prod, mem_prod, iSup_and] exact iSup_congr fun _ => iSup_comm theorem biSup_prod' {f : β → γ → α} {s : Set β} {t : Set γ} : ⨆ x ∈ s ×ˢ t, f x.1 x.2 = ⨆ (a ∈ s) (b ∈ t), f a b := biSup_prod theorem biInf_prod {f : β × γ → α} {s : Set β} {t : Set γ} : ⨅ x ∈ s ×ˢ t, f x = ⨅ (a ∈ s) (b ∈ t), f (a, b) := @biSup_prod αᵒᵈ _ _ _ _ _ _ theorem biInf_prod' {f : β → γ → α} {s : Set β} {t : Set γ} : ⨅ x ∈ s ×ˢ t, f x.1 x.2 = ⨅ (a ∈ s) (b ∈ t), f a b := biInf_prod theorem iSup_image2 {γ δ} (f : β → γ → δ) (s : Set β) (t : Set γ) (g : δ → α) : ⨆ d ∈ image2 f s t, g d = ⨆ b ∈ s, ⨆ c ∈ t, g (f b c) := by rw [← image_prod, iSup_image, biSup_prod] theorem iInf_image2 {γ δ} (f : β → γ → δ) (s : Set β) (t : Set γ) (g : δ → α) : ⨅ d ∈ image2 f s t, g d = ⨅ b ∈ s, ⨅ c ∈ t, g (f b c) := iSup_image2 f s t (toDual ∘ g) theorem iSup_sum {f : β ⊕ γ → α} : ⨆ x, f x = (⨆ i, f (Sum.inl i)) ⊔ ⨆ j, f (Sum.inr j) := eq_of_forall_ge_iff fun c => by simp only [sup_le_iff, iSup_le_iff, Sum.forall] theorem iInf_sum {f : β ⊕ γ → α} : ⨅ x, f x = (⨅ i, f (Sum.inl i)) ⊓ ⨅ j, f (Sum.inr j) := @iSup_sum αᵒᵈ _ _ _ _ theorem iSup_option (f : Option β → α) : ⨆ o, f o = f none ⊔ ⨆ b, f (Option.some b) := eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, sup_le_iff, Option.forall] theorem iInf_option (f : Option β → α) : ⨅ o, f o = f none ⊓ ⨅ b, f (Option.some b) := @iSup_option αᵒᵈ _ _ _ /-- A version of `iSup_option` useful for rewriting right-to-left. -/ theorem iSup_option_elim (a : α) (f : β → α) : ⨆ o : Option β, o.elim a f = a ⊔ ⨆ b, f b := by simp [iSup_option] /-- A version of `iInf_option` useful for rewriting right-to-left. -/ theorem iInf_option_elim (a : α) (f : β → α) : ⨅ o : Option β, o.elim a f = a ⊓ ⨅ b, f b := @iSup_option_elim αᵒᵈ _ _ _ _ /-- When taking the supremum of `f : ι → α`, the elements of `ι` on which `f` gives `⊥` can be dropped, without changing the result. -/ @[simp] theorem iSup_ne_bot_subtype (f : ι → α) : ⨆ i : { i // f i ≠ ⊥ }, f i = ⨆ i, f i := by by_cases! htriv : ∀ i, f i = ⊥ · simp only [iSup_bot, (funext htriv : f = _)] refine (iSup_comp_le f _).antisymm (iSup_mono' fun i => ?_) by_cases hi : f i = ⊥ · rw [hi] obtain ⟨i₀, hi₀⟩ := htriv exact ⟨⟨i₀, hi₀⟩, bot_le⟩ · exact ⟨⟨i, hi⟩, rfl.le⟩ /-- When taking the infimum of `f : ι → α`, the elements of `ι` on which `f` gives `⊤` can be dropped, without changing the result. -/ theorem iInf_ne_top_subtype (f : ι → α) : ⨅ i : { i // f i ≠ ⊤ }, f i = ⨅ i, f i := @iSup_ne_bot_subtype αᵒᵈ ι _ f theorem sSup_image2 {f : β → γ → α} {s : Set β} {t : Set γ} : sSup (image2 f s t) = ⨆ (a ∈ s) (b ∈ t), f a b := by rw [← image_prod, sSup_image, biSup_prod] theorem sInf_image2 {f : β → γ → α} {s : Set β} {t : Set γ} : sInf (image2 f s t) = ⨅ (a ∈ s) (b ∈ t), f a b := by rw [← image_prod, sInf_image, biInf_prod] end section CompleteLinearOrder variable [CompleteLinearOrder α] theorem iSup_eq_top (f : ι → α) : iSup f = ⊤ ↔ ∀ b < ⊤, ∃ i, b < f i := by simp only [← sSup_range, sSup_eq_top, Set.exists_range_iff] theorem iInf_eq_bot (f : ι → α) : iInf f = ⊥ ↔ ∀ b > ⊥, ∃ i, f i < b := by simp only [← sInf_range, sInf_eq_bot, Set.exists_range_iff] lemma iSup₂_eq_top (f : ∀ i, κ i → α) : ⨆ i, ⨆ j, f i j = ⊤ ↔ ∀ b < ⊤, ∃ i j, b < f i j := by simp_rw [iSup_psigma', iSup_eq_top, PSigma.exists] lemma iInf₂_eq_bot (f : ∀ i, κ i → α) : ⨅ i, ⨅ j, f i j = ⊥ ↔ ∀ b > ⊥, ∃ i j, f i j < b := by simp_rw [iInf_psigma', iInf_eq_bot, PSigma.exists] end CompleteLinearOrder /-! ### Instances -/ instance Prop.instCompleteLattice : CompleteLattice Prop where __ := Prop.instBoundedOrder __ := Prop.instDistribLattice sSup s := ∃ a ∈ s, a le_sSup _ a h p := ⟨a, h, p⟩ sSup_le _ _ h := fun ⟨b, h', p⟩ => h b h' p sInf s := ∀ a, a ∈ s → a sInf_le _ a h p := p a h le_sInf _ _ h p b hb := h b hb p noncomputable instance Prop.instCompleteLinearOrder : CompleteLinearOrder Prop where __ := Prop.instCompleteLattice __ := Prop.linearOrder __ := BooleanAlgebra.toBiheytingAlgebra @[simp] theorem sSup_Prop_eq {s : Set Prop} : sSup s = ∃ p ∈ s, p := rfl @[simp] theorem sInf_Prop_eq {s : Set Prop} : sInf s = ∀ p ∈ s, p := rfl @[simp] theorem iSup_Prop_eq {p : ι → Prop} : ⨆ i, p i = ∃ i, p i := le_antisymm (fun ⟨_, ⟨i, (eq : p i = _)⟩, hq⟩ => ⟨i, eq.symm ▸ hq⟩) fun ⟨i, hi⟩ => ⟨p i, ⟨i, rfl⟩, hi⟩ @[simp] theorem iInf_Prop_eq {p : ι → Prop} : ⨅ i, p i = ∀ i, p i := le_antisymm (fun h i => h _ ⟨i, rfl⟩) fun h _ ⟨i, Eq⟩ => Eq ▸ h i instance Pi.supSet {α : Type*} {β : α → Type*} [∀ i, SupSet (β i)] : SupSet (∀ i, β i) := ⟨fun s i => ⨆ f : s, (f : ∀ i, β i) i⟩ instance Pi.infSet {α : Type*} {β : α → Type*} [∀ i, InfSet (β i)] : InfSet (∀ i, β i) := ⟨fun s i => ⨅ f : s, (f : ∀ i, β i) i⟩ instance Pi.instCompleteLattice {α : Type*} {β : α → Type*} [∀ i, CompleteLattice (β i)] : CompleteLattice (∀ i, β i) where __ := instBoundedOrder le_sSup s f hf := fun i => le_iSup (fun f : s => (f : ∀ i, β i) i) ⟨f, hf⟩ sInf_le s f hf := fun i => iInf_le (fun f : s => (f : ∀ i, β i) i) ⟨f, hf⟩ sSup_le _ _ hf := fun i => iSup_le fun g => hf g g.2 i le_sInf _ _ hf := fun i => le_iInf fun g => hf g g.2 i @[simp] theorem sSup_apply {α : Type*} {β : α → Type*} [∀ i, SupSet (β i)] {s : Set (∀ a, β a)} {a : α} : (sSup s) a = ⨆ f : s, (f : ∀ a, β a) a := rfl @[simp] theorem sInf_apply {α : Type*} {β : α → Type*} [∀ i, InfSet (β i)] {s : Set (∀ a, β a)} {a : α} : sInf s a = ⨅ f : s, (f : ∀ a, β a) a := rfl @[simp] theorem iSup_apply {α : Type*} {β : α → Type*} {ι : Sort*} [∀ i, SupSet (β i)] {f : ι → ∀ a, β a} {a : α} : (⨆ i, f i) a = ⨆ i, f i a := by rw [iSup, sSup_apply, iSup, iSup, ← image_eq_range (fun f : ∀ i, β i => f a) (range f), ← range_comp]; rfl @[simp] theorem iInf_apply {α : Type*} {β : α → Type*} {ι : Sort*} [∀ i, InfSet (β i)] {f : ι → ∀ a, β a} {a : α} : (⨅ i, f i) a = ⨅ i, f i a := @iSup_apply α (fun i => (β i)ᵒᵈ) _ _ _ _ theorem unary_relation_sSup_iff {α : Type*} (s : Set (α → Prop)) {a : α} : sSup s a ↔ ∃ r : α → Prop, r ∈ s ∧ r a := by simp theorem unary_relation_sInf_iff {α : Type*} (s : Set (α → Prop)) {a : α} : sInf s a ↔ ∀ r : α → Prop, r ∈ s → r a := by simp theorem binary_relation_sSup_iff {α β : Type*} (s : Set (α → β → Prop)) {a : α} {b : β} : sSup s a b ↔ ∃ r : α → β → Prop, r ∈ s ∧ r a b := by simp theorem binary_relation_sInf_iff {α β : Type*} (s : Set (α → β → Prop)) {a : α} {b : β} : sInf s a b ↔ ∀ r : α → β → Prop, r ∈ s → r a b := by simp section CompleteLattice variable [Preorder α] [CompleteLattice β] {s : Set (α → β)} {f : ι → α → β} protected lemma Monotone.sSup (hs : ∀ f ∈ s, Monotone f) : Monotone (sSup s) := fun _ _ h ↦ iSup_mono fun f ↦ hs f f.2 h protected lemma Monotone.sInf (hs : ∀ f ∈ s, Monotone f) : Monotone (sInf s) := fun _ _ h ↦ iInf_mono fun f ↦ hs f f.2 h protected lemma Antitone.sSup (hs : ∀ f ∈ s, Antitone f) : Antitone (sSup s) := fun _ _ h ↦ iSup_mono fun f ↦ hs f f.2 h protected lemma Antitone.sInf (hs : ∀ f ∈ s, Antitone f) : Antitone (sInf s) := fun _ _ h ↦ iInf_mono fun f ↦ hs f f.2 h protected lemma Monotone.iSup (hf : ∀ i, Monotone (f i)) : Monotone (⨆ i, f i) := Monotone.sSup (by simpa) protected lemma Monotone.iInf (hf : ∀ i, Monotone (f i)) : Monotone (⨅ i, f i) := Monotone.sInf (by simpa) protected lemma Antitone.iSup (hf : ∀ i, Antitone (f i)) : Antitone (⨆ i, f i) := Antitone.sSup (by simpa) protected lemma Antitone.iInf (hf : ∀ i, Antitone (f i)) : Antitone (⨅ i, f i) := Antitone.sInf (by simpa) end CompleteLattice namespace Prod variable (α β) instance supSet [SupSet α] [SupSet β] : SupSet (α × β) := ⟨fun s => (sSup (Prod.fst '' s), sSup (Prod.snd '' s))⟩ instance infSet [InfSet α] [InfSet β] : InfSet (α × β) := ⟨fun s => (sInf (Prod.fst '' s), sInf (Prod.snd '' s))⟩ variable {α β} theorem fst_sInf [InfSet α] [InfSet β] (s : Set (α × β)) : (sInf s).fst = sInf (Prod.fst '' s) := rfl theorem snd_sInf [InfSet α] [InfSet β] (s : Set (α × β)) : (sInf s).snd = sInf (Prod.snd '' s) := rfl theorem swap_sInf [InfSet α] [InfSet β] (s : Set (α × β)) : (sInf s).swap = sInf (Prod.swap '' s) := Prod.ext (congr_arg sInf <| image_comp Prod.fst swap s) (congr_arg sInf <| image_comp Prod.snd swap s) theorem fst_sSup [SupSet α] [SupSet β] (s : Set (α × β)) : (sSup s).fst = sSup (Prod.fst '' s) := rfl theorem snd_sSup [SupSet α] [SupSet β] (s : Set (α × β)) : (sSup s).snd = sSup (Prod.snd '' s) := rfl theorem swap_sSup [SupSet α] [SupSet β] (s : Set (α × β)) : (sSup s).swap = sSup (Prod.swap '' s) := Prod.ext (congr_arg sSup <| image_comp Prod.fst swap s) (congr_arg sSup <| image_comp Prod.snd swap s) theorem fst_iInf [InfSet α] [InfSet β] (f : ι → α × β) : (iInf f).fst = ⨅ i, (f i).fst := congr_arg sInf (range_comp _ _).symm theorem snd_iInf [InfSet α] [InfSet β] (f : ι → α × β) : (iInf f).snd = ⨅ i, (f i).snd := congr_arg sInf (range_comp _ _).symm theorem swap_iInf [InfSet α] [InfSet β] (f : ι → α × β) : (iInf f).swap = ⨅ i, (f i).swap := by simp_rw [iInf, swap_sInf, ← range_comp, comp_def] theorem iInf_mk [InfSet α] [InfSet β] (f : ι → α) (g : ι → β) : ⨅ i, (f i, g i) = (⨅ i, f i, ⨅ i, g i) := congr_arg₂ Prod.mk (fst_iInf _) (snd_iInf _) theorem fst_iSup [SupSet α] [SupSet β] (f : ι → α × β) : (iSup f).fst = ⨆ i, (f i).fst := congr_arg sSup (range_comp _ _).symm theorem snd_iSup [SupSet α] [SupSet β] (f : ι → α × β) : (iSup f).snd = ⨆ i, (f i).snd := congr_arg sSup (range_comp _ _).symm theorem swap_iSup [SupSet α] [SupSet β] (f : ι → α × β) : (iSup f).swap = ⨆ i, (f i).swap := by simp_rw [iSup, swap_sSup, ← range_comp, comp_def] theorem iSup_mk [SupSet α] [SupSet β] (f : ι → α) (g : ι → β) : ⨆ i, (f i, g i) = (⨆ i, f i, ⨆ i, g i) := congr_arg₂ Prod.mk (fst_iSup _) (snd_iSup _) instance instCompleteLattice [CompleteLattice α] [CompleteLattice β] : CompleteLattice (α × β) where __ := instBoundedOrder α β le_sSup _ _ hab := ⟨le_sSup <| mem_image_of_mem _ hab, le_sSup <| mem_image_of_mem _ hab⟩ sSup_le _ _ h := ⟨sSup_le <| forall_mem_image.2 fun p hp => (h p hp).1, sSup_le <| forall_mem_image.2 fun p hp => (h p hp).2⟩ sInf_le _ _ hab := ⟨sInf_le <| mem_image_of_mem _ hab, sInf_le <| mem_image_of_mem _ hab⟩ le_sInf _ _ h := ⟨le_sInf <| forall_mem_image.2 fun p hp => (h p hp).1, le_sInf <| forall_mem_image.2 fun p hp => (h p hp).2⟩ end Prod lemma sInf_prod [InfSet α] [InfSet β] {s : Set α} {t : Set β} (hs : s.Nonempty) (ht : t.Nonempty) : sInf (s ×ˢ t) = (sInf s, sInf t) := congr_arg₂ Prod.mk (congr_arg sInf <| fst_image_prod _ ht) (congr_arg sInf <| snd_image_prod hs _) lemma sSup_prod [SupSet α] [SupSet β] {s : Set α} {t : Set β} (hs : s.Nonempty) (ht : t.Nonempty) : sSup (s ×ˢ t) = (sSup s, sSup t) := congr_arg₂ Prod.mk (congr_arg sSup <| fst_image_prod _ ht) (congr_arg sSup <| snd_image_prod hs _) -- See note [reducible non-instances] /-- Pullback a `CompleteLattice` along an injection. -/ protected abbrev Function.Injective.completeLattice [Max α] [Min α] [SupSet α] [InfSet α] [Top α] [Bot α] [CompleteLattice β] (f : α → β) (hf : Function.Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) : CompleteLattice α where -- we cannot use BoundedOrder.lift here as the `LE` instance doesn't exist yet __ := hf.lattice f map_sup map_inf le_sSup _ a h := (le_iSup₂ a h).trans (map_sSup _).ge sSup_le _ _ h := (map_sSup _).trans_le <| iSup₂_le h sInf_le _ a h := (map_sInf _).trans_le <| iInf₂_le a h le_sInf _ _ h := (le_iInf₂ h).trans (map_sInf _).ge le_top _ := (@le_top β _ _ _).trans map_top.ge bot_le _ := map_bot.le.trans bot_le
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/Defs.lean
import Mathlib.Order.Bounds.Basic import Mathlib.Order.SetNotation /-! # Definition of complete lattices This file contains the definition of complete lattices with suprema/infima of arbitrary sets. ## Main definitions * `sSup` and `sInf` are the supremum and the infimum of a set; * `iSup (f : ι → α)` and `iInf (f : ι → α)` are indexed supremum and infimum of a function, defined as `sSup` and `sInf` of the range of this function; * class `CompleteLattice`: a bounded lattice such that `sSup s` is always the least upper boundary of `s` and `sInf s` is always the greatest lower boundary of `s`; * class `CompleteLinearOrder`: a linear ordered complete lattice. ## Naming conventions In lemma names, * `sSup` is called `sSup` * `sInf` is called `sInf` * `⨆ i, s i` is called `iSup` * `⨅ i, s i` is called `iInf` * `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`. * `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`. * `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂` where `j : i ∈ s`. * `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂` where `j : i ∈ s`. ## Notation * `⨆ i, f i` : `iSup f`, the supremum of the range of `f`; * `⨅ i, f i` : `iInf f`, the infimum of the range of `f`. -/ open Function OrderDual Set variable {α β γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*} instance OrderDual.supSet (α) [InfSet α] : SupSet αᵒᵈ := ⟨(sInf : Set α → α)⟩ instance OrderDual.infSet (α) [SupSet α] : InfSet αᵒᵈ := ⟨(sSup : Set α → α)⟩ /-- Note that we rarely use `CompleteSemilatticeSup` (in fact, any such object is always a `CompleteLattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class CompleteSemilatticeSup (α : Type*) extends PartialOrder α, SupSet α where /-- Any element of a set is less than the set supremum. -/ le_sSup : ∀ s, ∀ a ∈ s, a ≤ sSup s /-- Any upper bound is more than the set supremum. -/ sSup_le : ∀ s a, (∀ b ∈ s, b ≤ a) → sSup s ≤ a section variable [CompleteSemilatticeSup α] {s t : Set α} {a b : α} theorem le_sSup : a ∈ s → a ≤ sSup s := CompleteSemilatticeSup.le_sSup s a theorem sSup_le : (∀ b ∈ s, b ≤ a) → sSup s ≤ a := CompleteSemilatticeSup.sSup_le s a theorem isLUB_sSup (s : Set α) : IsLUB s (sSup s) := ⟨fun _ ↦ le_sSup, fun _ ↦ sSup_le⟩ lemma isLUB_iff_sSup_eq : IsLUB s a ↔ sSup s = a := ⟨(isLUB_sSup s).unique, by rintro rfl; exact isLUB_sSup _⟩ alias ⟨IsLUB.sSup_eq, _⟩ := isLUB_iff_sSup_eq theorem le_sSup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s := le_trans h (le_sSup hb) @[gcongr] theorem sSup_le_sSup (h : s ⊆ t) : sSup s ≤ sSup t := (isLUB_sSup s).mono (isLUB_sSup t) h @[simp] theorem sSup_le_iff : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a := isLUB_le_iff (isLUB_sSup s) theorem le_sSup_iff : a ≤ sSup s ↔ ∀ b ∈ upperBounds s, a ≤ b := ⟨fun h _ hb => le_trans h (sSup_le hb), fun hb => hb _ fun _ => le_sSup⟩ theorem le_iSup_iff {s : ι → α} : a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by simp [iSup, le_sSup_iff, upperBounds] end /-- Note that we rarely use `CompleteSemilatticeInf` (in fact, any such object is always a `CompleteLattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class CompleteSemilatticeInf (α : Type*) extends PartialOrder α, InfSet α where /-- Any element of a set is more than the set infimum. -/ sInf_le : ∀ s, ∀ a ∈ s, sInf s ≤ a /-- Any lower bound is less than the set infimum. -/ le_sInf : ∀ s a, (∀ b ∈ s, a ≤ b) → a ≤ sInf s section variable [CompleteSemilatticeInf α] {s t : Set α} {a b : α} theorem sInf_le : a ∈ s → sInf s ≤ a := CompleteSemilatticeInf.sInf_le s a theorem le_sInf : (∀ b ∈ s, a ≤ b) → a ≤ sInf s := CompleteSemilatticeInf.le_sInf s a theorem isGLB_sInf (s : Set α) : IsGLB s (sInf s) := ⟨fun _ => sInf_le, fun _ => le_sInf⟩ lemma isGLB_iff_sInf_eq : IsGLB s a ↔ sInf s = a := ⟨(isGLB_sInf s).unique, by rintro rfl; exact isGLB_sInf _⟩ alias ⟨IsGLB.sInf_eq, _⟩ := isGLB_iff_sInf_eq theorem sInf_le_of_le (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a := le_trans (sInf_le hb) h @[gcongr] theorem sInf_le_sInf (h : s ⊆ t) : sInf t ≤ sInf s := (isGLB_sInf s).mono (isGLB_sInf t) h @[simp] theorem le_sInf_iff : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b := le_isGLB_iff (isGLB_sInf s) theorem sInf_le_iff : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a := ⟨fun h _ hb => le_trans (le_sInf hb) h, fun hb => hb _ fun _ => sInf_le⟩ theorem iInf_le_iff {s : ι → α} : iInf s ≤ a ↔ ∀ b, (∀ i, b ≤ s i) → b ≤ a := by simp [iInf, sInf_le_iff, lowerBounds] end instance {α : Type*} [CompleteSemilatticeInf α] : CompleteSemilatticeSup αᵒᵈ where le_sSup := @CompleteSemilatticeInf.sInf_le α _ sSup_le := @CompleteSemilatticeInf.le_sInf α _ instance {α : Type*} [CompleteSemilatticeSup α] : CompleteSemilatticeInf αᵒᵈ where le_sInf := @CompleteSemilatticeSup.sSup_le α _ sInf_le := @CompleteSemilatticeSup.le_sSup α _ /-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/ class CompleteLattice (α : Type*) extends Lattice α, CompleteSemilatticeSup α, CompleteSemilatticeInf α, BoundedOrder α -- Shortcut instance to ensure that the path -- `CompleteLattice α → CompletePartialOrder α → PartialOrder α` isn't taken, -- as it tricks `#min_imports` into believing `Order.CompletePartialOrder` is a necessary import. -- See note [lower instance priority] instance (priority := 100) CompleteLattice.toPartialOrder' [CompleteLattice α] : PartialOrder α := inferInstance /-- Create a `CompleteLattice` from a `PartialOrder` and `InfSet` that returns the greatest lower bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `CompleteLattice` instance as ``` instance : CompleteLattice my_T where inf := better_inf le_inf := ... inf_le_right := ... inf_le_left := ... -- don't care to fix sup, sSup, bot, top __ := completeLatticeOfInf my_T _ ``` -/ def completeLatticeOfInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α] (isGLB_sInf : ∀ s : Set α, IsGLB s (sInf s)) : CompleteLattice α where __ := H1; __ := H2 bot := sInf univ bot_le _ := (isGLB_sInf univ).1 trivial top := sInf ∅ le_top a := (isGLB_sInf ∅).2 <| by simp sup a b := sInf { x : α | a ≤ x ∧ b ≤ x } inf a b := sInf {a, b} le_inf a b c hab hac := by apply (isGLB_sInf _).2 simp [*] inf_le_right _ _ := (isGLB_sInf _).1 <| mem_insert_of_mem _ <| mem_singleton _ inf_le_left _ _ := (isGLB_sInf _).1 <| mem_insert _ _ sup_le a b c hac hbc := (isGLB_sInf _).1 <| by simp [*] le_sup_left _ _ := (isGLB_sInf _).2 fun _ => And.left le_sup_right _ _ := (isGLB_sInf _).2 fun _ => And.right le_sInf s _ ha := (isGLB_sInf s).2 ha sInf_le s _ ha := (isGLB_sInf s).1 ha sSup s := sInf (upperBounds s) le_sSup s _ ha := (isGLB_sInf (upperBounds s)).2 fun _ hb => hb ha sSup_le s _ ha := (isGLB_sInf (upperBounds s)).1 ha /-- Any `CompleteSemilatticeInf` is in fact a `CompleteLattice`. Note that this construction has bad definitional properties: see the doc-string on `completeLatticeOfInf`. -/ def completeLatticeOfCompleteSemilatticeInf (α : Type*) [CompleteSemilatticeInf α] : CompleteLattice α := completeLatticeOfInf α fun s => isGLB_sInf s /-- Create a `CompleteLattice` from a `PartialOrder` and `SupSet` that returns the least upper bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `CompleteLattice` instance as ``` instance : CompleteLattice my_T where inf := better_inf le_inf := ... inf_le_right := ... inf_le_left := ... -- don't care to fix sup, sInf, bot, top __ := completeLatticeOfSup my_T _ ``` -/ def completeLatticeOfSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α] (isLUB_sSup : ∀ s : Set α, IsLUB s (sSup s)) : CompleteLattice α where __ := H1; __ := H2 top := sSup univ le_top _ := (isLUB_sSup univ).1 trivial bot := sSup ∅ bot_le x := (isLUB_sSup ∅).2 <| by simp sup a b := sSup {a, b} sup_le a b c hac hbc := (isLUB_sSup _).2 (by simp [*]) le_sup_left _ _ := (isLUB_sSup _).1 <| mem_insert _ _ le_sup_right _ _ := (isLUB_sSup _).1 <| mem_insert_of_mem _ <| mem_singleton _ inf a b := sSup { x | x ≤ a ∧ x ≤ b } le_inf a b c hab hac := (isLUB_sSup _).1 <| by simp [*] inf_le_left _ _ := (isLUB_sSup _).2 fun _ => And.left inf_le_right _ _ := (isLUB_sSup _).2 fun _ => And.right sInf s := sSup (lowerBounds s) sSup_le s _ ha := (isLUB_sSup s).2 ha le_sSup s _ ha := (isLUB_sSup s).1 ha sInf_le s _ ha := (isLUB_sSup (lowerBounds s)).2 fun _ hb => hb ha le_sInf s _ ha := (isLUB_sSup (lowerBounds s)).1 ha /-- Any `CompleteSemilatticeSup` is in fact a `CompleteLattice`. Note that this construction has bad definitional properties: see the doc-string on `completeLatticeOfSup`. -/ def completeLatticeOfCompleteSemilatticeSup (α : Type*) [CompleteSemilatticeSup α] : CompleteLattice α := completeLatticeOfSup α fun s => isLUB_sSup s /-- A complete linear order is a linear order whose lattice structure is complete. -/ -- Note that we do not use `extends LinearOrder α`, -- and instead construct the forgetful instance manually. class CompleteLinearOrder (α : Type*) extends CompleteLattice α, BiheytingAlgebra α, Ord α where /-- A linear order is total. -/ le_total (a b : α) : a ≤ b ∨ b ≤ a /-- In a linearly ordered type, we assume the order relations are all decidable. -/ toDecidableLE : DecidableLE α /-- In a linearly ordered type, we assume the order relations are all decidable. -/ toDecidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ toDecidableLE /-- In a linearly ordered type, we assume the order relations are all decidable. -/ toDecidableLT : DecidableLT α := @decidableLTOfDecidableLE _ _ toDecidableLE compare a b := compareOfLessAndEq a b /-- Comparison via `compare` is equal to the canonical comparison given decidable `<` and `=`. -/ compare_eq_compareOfLessAndEq : ∀ a b, compare a b = compareOfLessAndEq a b := by compareOfLessAndEq_rfl instance CompleteLinearOrder.toLinearOrder [i : CompleteLinearOrder α] : LinearOrder α where __ := i min_def a b := by split_ifs with h · simp [h] · simp [(CompleteLinearOrder.le_total a b).resolve_left h] max_def a b := by split_ifs with h · simp [h] · simp [(CompleteLinearOrder.le_total a b).resolve_left h] namespace OrderDual instance instCompleteLattice [CompleteLattice α] : CompleteLattice αᵒᵈ where __ := instBoundedOrder α le_sSup := @CompleteLattice.sInf_le α _ sSup_le := @CompleteLattice.le_sInf α _ sInf_le := @CompleteLattice.le_sSup α _ le_sInf := @CompleteLattice.sSup_le α _ instance instCompleteLinearOrder [CompleteLinearOrder α] : CompleteLinearOrder αᵒᵈ where __ := instCompleteLattice __ := instBiheytingAlgebra __ := instLinearOrder α end OrderDual open OrderDual section section OrderDual @[simp] theorem toDual_sSup [SupSet α] (s : Set α) : toDual (sSup s) = sInf (ofDual ⁻¹' s) := rfl @[simp] theorem toDual_sInf [InfSet α] (s : Set α) : toDual (sInf s) = sSup (ofDual ⁻¹' s) := rfl @[simp] theorem ofDual_sSup [InfSet α] (s : Set αᵒᵈ) : ofDual (sSup s) = sInf (toDual ⁻¹' s) := rfl @[simp] theorem ofDual_sInf [SupSet α] (s : Set αᵒᵈ) : ofDual (sInf s) = sSup (toDual ⁻¹' s) := rfl @[simp] theorem toDual_iSup [SupSet α] (f : ι → α) : toDual (⨆ i, f i) = ⨅ i, toDual (f i) := rfl @[simp] theorem toDual_iInf [InfSet α] (f : ι → α) : toDual (⨅ i, f i) = ⨆ i, toDual (f i) := rfl @[simp] theorem ofDual_iSup [InfSet α] (f : ι → αᵒᵈ) : ofDual (⨆ i, f i) = ⨅ i, ofDual (f i) := rfl @[simp] theorem ofDual_iInf [SupSet α] (f : ι → αᵒᵈ) : ofDual (⨅ i, f i) = ⨆ i, ofDual (f i) := rfl end OrderDual section CompleteLinearOrder variable [CompleteLinearOrder α] {s : Set α} {a b : α} theorem lt_sSup_iff : b < sSup s ↔ ∃ a ∈ s, b < a := lt_isLUB_iff <| isLUB_sSup s theorem sInf_lt_iff : sInf s < b ↔ ∃ a ∈ s, a < b := isGLB_lt_iff <| isGLB_sInf s theorem sSup_eq_top : sSup s = ⊤ ↔ ∀ b < ⊤, ∃ a ∈ s, b < a := ⟨fun h _ hb => lt_sSup_iff.1 <| hb.trans_eq h.symm, fun h => top_unique <| le_of_not_gt fun h' => let ⟨_, ha, h⟩ := h _ h' (h.trans_le <| le_sSup ha).false⟩ theorem sInf_eq_bot : sInf s = ⊥ ↔ ∀ b > ⊥, ∃ a ∈ s, a < b := @sSup_eq_top αᵒᵈ _ _ theorem lt_iSup_iff {f : ι → α} : a < iSup f ↔ ∃ i, a < f i := lt_sSup_iff.trans exists_range_iff theorem iInf_lt_iff {f : ι → α} : iInf f < a ↔ ∃ i, f i < a := sInf_lt_iff.trans exists_range_iff theorem lt_biSup_iff {s : Set β} {f : β → α} : a < ⨆ i ∈ s, f i ↔ ∃ i ∈ s, a < f i := by simp [lt_iSup_iff] theorem biInf_lt_iff {s : Set β} {f : β → α} : ⨅ i ∈ s, f i < a ↔ ∃ i ∈ s, f i < a := by simp [iInf_lt_iff] end CompleteLinearOrder end
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/MulticoequalizerDiagram.lean
import Mathlib.Order.CompleteLattice.Lemmas import Mathlib.CategoryTheory.Category.Preorder import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.CommSq import Mathlib.Tactic.FinCases /-! # Multicoequalizer diagrams in complete lattices We introduce the notion of bi-Cartesian square (`Lattice.BicartSq`) in a lattice `T`. This consists of elements `x₁`, `x₂`, `x₃` and `x₄` such that `x₂ ⊔ x₃ = x₄` and `x₂ ⊓ x₃ = x₁`. It shall be shown (TODO) that if `T := Set X`, then the image of the associated commutative square in the category `Type _` is a bi-Cartesian square in a categorical sense (both pushout and pullback). More generally, if `T` is a complete lattice, `x : T`, `u : ι → T`, `v : ι → ι → T`, we introduce a property `MulticoequalizerDiagram x u v` which says that `x` is the supremum of `u`, and that for all `i` and `j`, `v i j` is the minimum of `u i` and `u j`. Again, when `T := Set X`, we shall show (TODO) that we obtain a multicoequalizer diagram in the category of types. -/ universe u open CategoryTheory Limits local grind_pattern inf_le_left => a ⊓ b local grind_pattern inf_le_right => a ⊓ b local grind_pattern le_sup_left => a ⊔ b local grind_pattern le_sup_right => a ⊔ b namespace Lattice variable {T : Type u} (x₁ x₂ x₃ x₄ : T) [Lattice T] /-- A bi-Cartesian square in a lattice consists of elements `x₁`, `x₂`, `x₃` and `x₄` such that `x₂ ⊔ x₃ = x₄` and `x₂ ⊓ x₃ = x₁`. -/ structure BicartSq : Prop where max_eq : x₂ ⊔ x₃ = x₄ min_eq : x₂ ⊓ x₃ = x₁ attribute [grind cases] BicartSq namespace BicartSq variable {x₁ x₂ x₃ x₄} (sq : BicartSq x₁ x₂ x₃ x₄) include sq lemma le₁₂ : x₁ ≤ x₂ := by grind lemma le₁₃ : x₁ ≤ x₃ := by grind lemma le₂₄ : x₂ ≤ x₄ := by grind lemma le₃₄ : x₃ ≤ x₄ := by grind /-- The commutative square associated to a bi-Cartesian square in a lattice. -/ lemma commSq : CommSq (homOfLE sq.le₁₂) (homOfLE sq.le₁₃) (homOfLE sq.le₂₄) (homOfLE sq.le₃₄) := ⟨rfl⟩ end BicartSq end Lattice namespace CompleteLattice variable {T : Type u} [CompleteLattice T] {ι : Type*} (x : T) (u : ι → T) (v : ι → ι → T) /-- A multicoequalizer diagram in a complete lattice `T` consists of families of elements `u : ι → T`, `v : ι → ι → T`, and an element `x : T` such that `x` is the supremum of `u`, and for any `i` and `j`, `v i j` is the minimum of `u i` and `u j`. -/ structure MulticoequalizerDiagram : Prop where iSup_eq : ⨆ (i : ι), u i = x min_eq (i j : ι) : v i j = u i ⊓ u j namespace MulticoequalizerDiagram attribute [local grind] MulticoequalizerDiagram attribute [local grind =] MultispanShape.prod_fst MultispanShape.prod_snd variable {x u v} (d : MulticoequalizerDiagram x u v) /-- The multispan index in the category associated to the complete lattice `T` given by the objects `u i` and the minima `v i j = u i ⊓ u j`, when `d : MulticoequalizerDiagram x u v`. -/ @[simps] def multispanIndex : MultispanIndex (.prod ι) T where left := fun ⟨i, j⟩ ↦ v i j right := u fst _ := homOfLE (by grind) snd _ := homOfLE (by grind) /-- The multicofork in the category associated to the complete lattice `T` associated to `d : MulticoequalizerDiagram x u v` with `x : T`. (In the case `T := Set X`, this multicofork becomes colimit after the application of the obvious functor `Set X ⥤ Type _`.) -/ @[simps! pt] def multicofork : Multicofork d.multispanIndex := Multicofork.ofπ _ x (fun i ↦ homOfLE (by grind [multispanIndex_right, le_iSup_iff])) (fun _ ↦ rfl) end MulticoequalizerDiagram end CompleteLattice lemma Lattice.BicartSq.multicoequalizerDiagram {T : Type u} [CompleteLattice T] {x₁ x₂ x₃ x₄} (sq : BicartSq x₁ x₂ x₃ x₄) : CompleteLattice.MulticoequalizerDiagram (T := T) x₄ (fun i ↦ bif i then x₃ else x₂) (fun i j ↦ bif i then bif j then x₃ else x₁ else bif j then x₁ else x₂) where iSup_eq := by rw [← sq.max_eq, sup_comm, sup_eq_iSup] min_eq i j := by grind [inf_idem, inf_comm]