source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Order/CompleteLattice/SetLike.lean
import Mathlib.Order.CompleteSublattice /-! # `SetLike` instance for elements of `CompleteSublattice (Set X)` This file provides lemmas for the `SetLike` instance for elements of `CompleteSublattice (Set X)` -/ attribute [local instance] SetLike.instSubtypeSet namespace Sublattice variable {X : Type*} {L : Sublattice (Set X)} variable {S T : L} {x : X} @[ext] lemma ext_mem (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h lemma mem_subtype : x ∈ L.subtype T ↔ x ∈ T := Iff.rfl @[simp] lemma setLike_mem_inf : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := by simp [← mem_subtype] @[simp] lemma setLike_mem_sup : x ∈ S ⊔ T ↔ x ∈ S ∨ x ∈ T := by simp [← mem_subtype] @[simp] lemma setLike_mem_coe : x ∈ T.val ↔ x ∈ T := Iff.rfl end Sublattice namespace CompleteSublattice variable {X : Type*} {L : CompleteSublattice (Set X)} variable {S T : L} {𝒮 : Set L} {I : Sort*} {f : I → L} {x : X} @[ext] lemma ext (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h lemma mem_subtype : x ∈ L.subtype T ↔ x ∈ T := Iff.rfl @[simp] lemma mem_inf : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := by simp [← mem_subtype] @[simp] lemma mem_sInf : x ∈ sInf 𝒮 ↔ ∀ T ∈ 𝒮, x ∈ T := by simp [← mem_subtype] @[simp] lemma mem_iInf : x ∈ ⨅ i : I, f i ↔ ∀ i : I, x ∈ f i := by simp [← mem_subtype] @[simp] lemma mem_top : x ∈ (⊤ : L) := by simp [← mem_subtype] @[simp] lemma mem_sup : x ∈ S ⊔ T ↔ x ∈ S ∨ x ∈ T := by simp [← mem_subtype] @[simp] lemma mem_sSup : x ∈ sSup 𝒮 ↔ ∃ T ∈ 𝒮, x ∈ T := by simp [← mem_subtype] @[simp] lemma mem_iSup : x ∈ ⨆ i : I, f i ↔ ∃ i : I, x ∈ f i := by simp [← mem_subtype] @[simp] lemma notMem_bot : x ∉ (⊥ : L) := by simp [← mem_subtype] @[deprecated (since := "2025-05-23")] alias not_mem_bot := notMem_bot end CompleteSublattice
.lake/packages/mathlib/Mathlib/Order/GaloisConnection/Basic.lean
import Mathlib.Order.Bounds.Image import Mathlib.Order.CompleteLattice.Basic import Mathlib.Order.WithBot /-! # Galois connections, insertions and coinsertions This file contains basic results on Galois connections, insertions and coinsertions in various order structures, and provides constructions that lift order structures from one type to another. ## Implementation details Galois insertions can be used to lift order structures from one type to another. For example, if `α` is a complete lattice, and `l : α → β` and `u : β → α` form a Galois insertion, then `β` is also a complete lattice. `l` is the lower adjoint and `u` is the upper adjoint. An example of a Galois insertion is in group theory. If `G` is a group, then there is a Galois insertion between the set of subsets of `G`, `Set G`, and the set of subgroups of `G`, `Subgroup G`. The lower adjoint is `Subgroup.closure`, taking the `Subgroup` generated by a `Set`, and the upper adjoint is the coercion from `Subgroup G` to `Set G`, taking the underlying set of a subgroup. Naively lifting a lattice structure along this Galois insertion would mean that the definition of `inf` on subgroups would be `Subgroup.closure (↑S ∩ ↑T)`. This is an undesirable definition because the intersection of subgroups is already a subgroup, so there is no need to take the closure. For this reason a `choice` function is added as a field to the `GaloisInsertion` structure. It has type `Π S : Set G, ↑(closure S) ≤ S → Subgroup G`. When `↑(closure S) ≤ S`, then `S` is already a subgroup, so this function can be defined using `Subgroup.mk` and not `closure`. This means the infimum of subgroups will be defined to be the intersection of sets, paired with a proof that intersection of subgroups is a subgroup, rather than the closure of the intersection. -/ open Function OrderDual Set universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {κ : ι → Sort*} {a₁ a₂ : α} {b₁ b₂ : β} namespace GaloisConnection section variable [Preorder α] [Preorder β] {l : α → β} {u : β → α} variable (gc : GaloisConnection l u) include gc theorem upperBounds_l_image (s : Set α) : upperBounds (l '' s) = u ⁻¹' upperBounds s := Set.ext fun b => by simp [upperBounds, gc _ _] theorem lowerBounds_u_image (s : Set β) : lowerBounds (u '' s) = l ⁻¹' lowerBounds s := gc.dual.upperBounds_l_image s theorem bddAbove_l_image {s : Set α} : BddAbove (l '' s) ↔ BddAbove s := ⟨fun ⟨x, hx⟩ => ⟨u x, by rwa [gc.upperBounds_l_image] at hx⟩, gc.monotone_l.map_bddAbove⟩ theorem bddBelow_u_image {s : Set β} : BddBelow (u '' s) ↔ BddBelow s := gc.dual.bddAbove_l_image theorem isLUB_l_image {s : Set α} {a : α} (h : IsLUB s a) : IsLUB (l '' s) (l a) := ⟨gc.monotone_l.mem_upperBounds_image h.left, fun b hb => gc.l_le <| h.right <| by rwa [gc.upperBounds_l_image] at hb⟩ theorem isGLB_u_image {s : Set β} {b : β} (h : IsGLB s b) : IsGLB (u '' s) (u b) := gc.dual.isLUB_l_image h theorem isLeast_l {a : α} : IsLeast { b | a ≤ u b } (l a) := ⟨gc.le_u_l _, fun _ hb => gc.l_le hb⟩ theorem isGreatest_u {b : β} : IsGreatest { a | l a ≤ b } (u b) := gc.dual.isLeast_l theorem isGLB_l {a : α} : IsGLB { b | a ≤ u b } (l a) := gc.isLeast_l.isGLB theorem isLUB_u {b : β} : IsLUB { a | l a ≤ b } (u b) := gc.isGreatest_u.isLUB end section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] {l : α → β} {u : β → α} theorem l_sup (gc : GaloisConnection l u) : l (a₁ ⊔ a₂) = l a₁ ⊔ l a₂ := (gc.isLUB_l_image isLUB_pair).unique <| by simp only [image_pair, isLUB_pair] end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [SemilatticeInf β] {l : α → β} {u : β → α} theorem u_inf (gc : GaloisConnection l u) : u (b₁ ⊓ b₂) = u b₁ ⊓ u b₂ := gc.dual.l_sup end SemilatticeInf section CompleteLattice variable [CompleteLattice α] [CompleteLattice β] {l : α → β} {u : β → α} theorem l_iSup (gc : GaloisConnection l u) {f : ι → α} : l (iSup f) = ⨆ i, l (f i) := Eq.symm <| IsLUB.iSup_eq <| show IsLUB (range (l ∘ f)) (l (iSup f)) by rw [range_comp, ← sSup_range]; exact gc.isLUB_l_image (isLUB_sSup _) theorem l_iSup₂ (gc : GaloisConnection l u) {f : ∀ i, κ i → α} : l (⨆ (i) (j), f i j) = ⨆ (i) (j), l (f i j) := by simp_rw [gc.l_iSup] variable (gc : GaloisConnection l u) include gc theorem u_iInf {f : ι → β} : u (iInf f) = ⨅ i, u (f i) := gc.dual.l_iSup theorem u_iInf₂ {f : ∀ i, κ i → β} : u (⨅ (i) (j), f i j) = ⨅ (i) (j), u (f i j) := gc.dual.l_iSup₂ theorem l_sSup {s : Set α} : l (sSup s) = ⨆ a ∈ s, l a := by simp only [sSup_eq_iSup, gc.l_iSup] theorem u_sInf {s : Set β} : u (sInf s) = ⨅ a ∈ s, u a := gc.dual.l_sSup end CompleteLattice -- Constructing Galois connections section Constructions protected theorem compl [BooleanAlgebra α] [BooleanAlgebra β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : GaloisConnection (compl ∘ u ∘ compl) (compl ∘ l ∘ compl) := fun a b ↦ by dsimp rw [le_compl_iff_le_compl, gc, compl_le_iff_compl_le] end Constructions end GaloisConnection section /-- `sSup` and `Iic` form a Galois connection. -/ theorem gc_sSup_Iic [CompleteSemilatticeSup α] : GaloisConnection (sSup : Set α → α) (Iic : α → Set α) := fun _ _ ↦ sSup_le_iff /-- `toDual ∘ Ici` and `sInf ∘ ofDual` form a Galois connection. -/ theorem gc_Ici_sInf [CompleteSemilatticeInf α] : GaloisConnection (toDual ∘ Ici : α → (Set α)ᵒᵈ) (sInf ∘ ofDual : (Set α)ᵒᵈ → α) := fun _ _ ↦ le_sInf_iff.symm variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] {s : Set α} {t : Set β} {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β} theorem sSup_image2_eq_sSup_sSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : sSup (image2 l s t) = l (sSup s) (sSup t) := by simp_rw [sSup_image2, ← (h₂ _).l_sSup, ← (h₁ _).l_sSup] theorem sSup_image2_eq_sSup_sInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : sSup (image2 l s t) = l (sSup s) (sInf t) := sSup_image2_eq_sSup_sSup (β := βᵒᵈ) h₁ h₂ theorem sSup_image2_eq_sInf_sSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : sSup (image2 l s t) = l (sInf s) (sSup t) := sSup_image2_eq_sSup_sSup (α := αᵒᵈ) h₁ h₂ theorem sSup_image2_eq_sInf_sInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : sSup (image2 l s t) = l (sInf s) (sInf t) := sSup_image2_eq_sSup_sSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ theorem sInf_image2_eq_sInf_sInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : sInf (image2 u s t) = u (sInf s) (sInf t) := by simp_rw [sInf_image2, ← (h₂ _).u_sInf, ← (h₁ _).u_sInf] theorem sInf_image2_eq_sInf_sSup (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) : sInf (image2 u s t) = u (sInf s) (sSup t) := sInf_image2_eq_sInf_sInf (β := βᵒᵈ) h₁ h₂ theorem sInf_image2_eq_sSup_sInf (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : sInf (image2 u s t) = u (sSup s) (sInf t) := sInf_image2_eq_sInf_sInf (α := αᵒᵈ) h₁ h₂ theorem sInf_image2_eq_sSup_sSup (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual)) (h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) : sInf (image2 u s t) = u (sSup s) (sSup t) := sInf_image2_eq_sInf_sInf (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ end namespace OrderIso variable [Preorder α] [Preorder β] /-- Makes a Galois connection from an order-preserving bijection. -/ lemma to_galoisConnection (e : α ≃o β) : GaloisConnection e e.symm := fun _ _ => e.rel_symm_apply.symm /-- Makes a Galois insertion from an order-preserving bijection. -/ protected def toGaloisInsertion (e : α ≃o β) : GaloisInsertion e e.symm where choice b _ := e b gc := e.to_galoisConnection le_l_u g := le_of_eq (e.right_inv g).symm choice_eq _ _ := rfl /-- Makes a Galois coinsertion from an order-preserving bijection. -/ protected def toGaloisCoinsertion (e : α ≃o β) : GaloisCoinsertion e e.symm where choice b _ := e.symm b gc := e.to_galoisConnection u_l_le g := le_of_eq (e.left_inv g) choice_eq _ _ := rfl @[simp] theorem bddAbove_image (e : α ≃o β) {s : Set α} : BddAbove (e '' s) ↔ BddAbove s := e.to_galoisConnection.bddAbove_l_image @[simp] theorem bddBelow_image (e : α ≃o β) {s : Set α} : BddBelow (e '' s) ↔ BddBelow s := e.dual.bddAbove_image @[simp] theorem bddAbove_preimage (e : α ≃o β) {s : Set β} : BddAbove (e ⁻¹' s) ↔ BddAbove s := by rw [← e.bddAbove_image, e.image_preimage] @[simp] theorem bddBelow_preimage (e : α ≃o β) {s : Set β} : BddBelow (e ⁻¹' s) ↔ BddBelow s := by rw [← e.bddBelow_image, e.image_preimage] end OrderIso namespace Nat theorem galoisConnection_mul_div {k : ℕ} (h : 0 < k) : GaloisConnection (fun n => n * k) fun n => n / k := fun _ _ => (le_div_iff_mul_le h).symm end Nat namespace GaloisInsertion variable {l : α → β} {u : β → α} theorem l_sup_u [SemilatticeSup α] [SemilatticeSup β] (gi : GaloisInsertion l u) (a b : β) : l (u a ⊔ u b) = a ⊔ b := calc l (u a ⊔ u b) = l (u a) ⊔ l (u b) := gi.gc.l_sup _ = a ⊔ b := by simp only [gi.l_u_eq] theorem l_iSup_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x} (f : ι → β) : l (⨆ i, u (f i)) = ⨆ i, f i := calc l (⨆ i : ι, u (f i)) = ⨆ i : ι, l (u (f i)) := gi.gc.l_iSup _ = ⨆ i : ι, f i := congr_arg _ <| funext fun i => gi.l_u_eq (f i) theorem l_biSup_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x} {p : ι → Prop} (f : ∀ i, p i → β) : l (⨆ (i) (hi), u (f i hi)) = ⨆ (i) (hi), f i hi := by simp only [iSup_subtype', gi.l_iSup_u] theorem l_sSup_u_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) (s : Set β) : l (sSup (u '' s)) = sSup s := by rw [sSup_image, gi.l_biSup_u, sSup_eq_iSup] theorem l_inf_u [SemilatticeInf α] [SemilatticeInf β] (gi : GaloisInsertion l u) (a b : β) : l (u a ⊓ u b) = a ⊓ b := calc l (u a ⊓ u b) = l (u (a ⊓ b)) := congr_arg l gi.gc.u_inf.symm _ = a ⊓ b := by simp only [gi.l_u_eq] theorem l_iInf_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x} (f : ι → β) : l (⨅ i, u (f i)) = ⨅ i, f i := calc l (⨅ i : ι, u (f i)) = l (u (⨅ i : ι, f i)) := congr_arg l gi.gc.u_iInf.symm _ = ⨅ i : ι, f i := gi.l_u_eq _ theorem l_biInf_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x} {p : ι → Prop} (f : ∀ (i) (_ : p i), β) : l (⨅ (i) (hi), u (f i hi)) = ⨅ (i) (hi), f i hi := by simp only [iInf_subtype', gi.l_iInf_u] theorem l_sInf_u_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) (s : Set β) : l (sInf (u '' s)) = sInf s := by rw [sInf_image, gi.l_biInf_u, sInf_eq_iInf] theorem l_iInf_of_ul_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x} (f : ι → α) (hf : ∀ i, u (l (f i)) = f i) : l (⨅ i, f i) = ⨅ i, l (f i) := calc l (⨅ i, f i) = l (⨅ i : ι, u (l (f i))) := by simp [hf] _ = ⨅ i, l (f i) := gi.l_iInf_u _ theorem l_biInf_of_ul_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x} {p : ι → Prop} (f : ∀ (i) (_ : p i), α) (hf : ∀ i hi, u (l (f i hi)) = f i hi) : l (⨅ (i) (hi), f i hi) = ⨅ (i) (hi), l (f i hi) := by rw [iInf_subtype', iInf_subtype'] exact gi.l_iInf_of_ul_eq_self _ fun _ => hf _ _ theorem isLUB_of_u_image [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {s : Set β} {a : α} (hs : IsLUB (u '' s) a) : IsLUB s (l a) := ⟨fun x hx => (gi.le_l_u x).trans <| gi.gc.monotone_l <| hs.1 <| mem_image_of_mem _ hx, fun _ hx => gi.gc.l_le <| hs.2 <| gi.gc.monotone_u.mem_upperBounds_image hx⟩ theorem isGLB_of_u_image [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {s : Set β} {a : α} (hs : IsGLB (u '' s) a) : IsGLB s (l a) := ⟨fun _ hx => gi.gc.l_le <| hs.1 <| mem_image_of_mem _ hx, fun x hx => (gi.le_l_u x).trans <| gi.gc.monotone_l <| hs.2 <| gi.gc.monotone_u.mem_lowerBounds_image hx⟩ section lift variable [PartialOrder β] -- See note [reducible non-instances] /-- Lift the suprema along a Galois insertion -/ abbrev liftSemilatticeSup [SemilatticeSup α] (gi : GaloisInsertion l u) : SemilatticeSup β := { ‹PartialOrder β› with sup := fun a b => l (u a ⊔ u b) le_sup_left := fun a _ => (gi.le_l_u a).trans <| gi.gc.monotone_l <| le_sup_left le_sup_right := fun _ b => (gi.le_l_u b).trans <| gi.gc.monotone_l <| le_sup_right sup_le := fun _ _ _ hac hbc => gi.gc.l_le <| sup_le (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc) } -- See note [reducible non-instances] /-- Lift the infima along a Galois insertion -/ abbrev liftSemilatticeInf [SemilatticeInf α] (gi : GaloisInsertion l u) : SemilatticeInf β := { ‹PartialOrder β› with inf := fun a b => gi.choice (u a ⊓ u b) <| le_inf (gi.gc.monotone_u <| gi.gc.l_le <| inf_le_left) (gi.gc.monotone_u <| gi.gc.l_le <| inf_le_right) inf_le_left := by simp only [gi.choice_eq]; exact fun a b => gi.gc.l_le inf_le_left inf_le_right := by simp only [gi.choice_eq]; exact fun a b => gi.gc.l_le inf_le_right le_inf := by simp only [gi.choice_eq] exact fun a b c hac hbc => (gi.le_l_u a).trans <| gi.gc.monotone_l <| le_inf (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc) } -- See note [reducible non-instances] /-- Lift the suprema and infima along a Galois insertion -/ abbrev liftLattice [Lattice α] (gi : GaloisInsertion l u) : Lattice β := { gi.liftSemilatticeSup, gi.liftSemilatticeInf with } -- See note [reducible non-instances] /-- Lift the top along a Galois insertion -/ abbrev liftOrderTop [Preorder α] [OrderTop α] (gi : GaloisInsertion l u) : OrderTop β where top := gi.choice ⊤ <| le_top le_top := by simp only [gi.choice_eq]; exact fun b => (gi.le_l_u b).trans (gi.gc.monotone_l le_top) -- See note [reducible non-instances] /-- Lift the top, bottom, suprema, and infima along a Galois insertion -/ abbrev liftBoundedOrder [Preorder α] [BoundedOrder α] (gi : GaloisInsertion l u) : BoundedOrder β := { gi.liftOrderTop, gi.gc.liftOrderBot with } -- See note [reducible non-instances] /-- Lift all suprema and infima along a Galois insertion -/ abbrev liftCompleteLattice [CompleteLattice α] (gi : GaloisInsertion l u) : CompleteLattice β := { gi.liftBoundedOrder, gi.liftLattice with sSup := fun s => l (sSup (u '' s)) sSup_le := fun _ => (gi.isLUB_of_u_image (isLUB_sSup _)).2 le_sSup := fun _ => (gi.isLUB_of_u_image (isLUB_sSup _)).1 sInf := fun s => gi.choice (sInf (u '' s)) <| (isGLB_sInf _).2 <| gi.gc.monotone_u.mem_lowerBounds_image (gi.isGLB_of_u_image <| isGLB_sInf _).1 sInf_le := fun s => by rw [gi.choice_eq]; exact (gi.isGLB_of_u_image (isGLB_sInf _)).1 le_sInf := fun s => by rw [gi.choice_eq]; exact (gi.isGLB_of_u_image (isGLB_sInf _)).2 } end lift end GaloisInsertion namespace GaloisCoinsertion variable {l : α → β} {u : β → α} theorem u_inf_l [SemilatticeInf α] [SemilatticeInf β] (gi : GaloisCoinsertion l u) (a b : α) : u (l a ⊓ l b) = a ⊓ b := gi.dual.l_sup_u a b theorem u_iInf_l [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x} (f : ι → α) : u (⨅ i, l (f i)) = ⨅ i, f i := gi.dual.l_iSup_u _ theorem u_sInf_l_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) (s : Set α) : u (sInf (l '' s)) = sInf s := gi.dual.l_sSup_u_image _ theorem u_sup_l [SemilatticeSup α] [SemilatticeSup β] (gi : GaloisCoinsertion l u) (a b : α) : u (l a ⊔ l b) = a ⊔ b := gi.dual.l_inf_u _ _ theorem u_iSup_l [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x} (f : ι → α) : u (⨆ i, l (f i)) = ⨆ i, f i := gi.dual.l_iInf_u _ theorem u_biSup_l [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x} {p : ι → Prop} (f : ∀ (i) (_ : p i), α) : u (⨆ (i) (hi), l (f i hi)) = ⨆ (i) (hi), f i hi := gi.dual.l_biInf_u _ theorem u_sSup_l_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) (s : Set α) : u (sSup (l '' s)) = sSup s := gi.dual.l_sInf_u_image _ theorem u_iSup_of_lu_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x} (f : ι → β) (hf : ∀ i, l (u (f i)) = f i) : u (⨆ i, f i) = ⨆ i, u (f i) := gi.dual.l_iInf_of_ul_eq_self _ hf theorem u_biSup_of_lu_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x} {p : ι → Prop} (f : ∀ (i) (_ : p i), β) (hf : ∀ i hi, l (u (f i hi)) = f i hi) : u (⨆ (i) (hi), f i hi) = ⨆ (i) (hi), u (f i hi) := gi.dual.l_biInf_of_ul_eq_self _ hf theorem isGLB_of_l_image [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {s : Set α} {a : β} (hs : IsGLB (l '' s) a) : IsGLB s (u a) := gi.dual.isLUB_of_u_image hs theorem isLUB_of_l_image [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {s : Set α} {a : β} (hs : IsLUB (l '' s) a) : IsLUB s (u a) := gi.dual.isGLB_of_u_image hs section lift variable [PartialOrder α] -- See note [reducible non-instances] /-- Lift the infima along a Galois coinsertion -/ abbrev liftSemilatticeInf [SemilatticeInf β] (gi : GaloisCoinsertion l u) : SemilatticeInf α := { ‹PartialOrder α› with inf_le_left := fun a b => (@OrderDual.instSemilatticeInf αᵒᵈ gi.dual.liftSemilatticeSup).inf_le_left a b inf_le_right := fun a b => (@OrderDual.instSemilatticeInf αᵒᵈ gi.dual.liftSemilatticeSup).inf_le_right a b le_inf := fun a b c => (@OrderDual.instSemilatticeInf αᵒᵈ gi.dual.liftSemilatticeSup).le_inf a b c inf := fun a b => u (l a ⊓ l b) } -- See note [reducible non-instances] /-- Lift the suprema along a Galois coinsertion -/ abbrev liftSemilatticeSup [SemilatticeSup β] (gi : GaloisCoinsertion l u) : SemilatticeSup α := { ‹PartialOrder α› with sup := fun a b => gi.choice (l a ⊔ l b) <| sup_le (gi.gc.monotone_l <| gi.gc.le_u <| le_sup_left) (gi.gc.monotone_l <| gi.gc.le_u <| le_sup_right) le_sup_left := fun a b => (@OrderDual.instSemilatticeSup αᵒᵈ gi.dual.liftSemilatticeInf).le_sup_left a b le_sup_right := fun a b => (@OrderDual.instSemilatticeSup αᵒᵈ gi.dual.liftSemilatticeInf).le_sup_right a b sup_le := fun a b c => (@OrderDual.instSemilatticeSup αᵒᵈ gi.dual.liftSemilatticeInf).sup_le a b c } -- See note [reducible non-instances] /-- Lift the suprema and infima along a Galois coinsertion -/ abbrev liftLattice [Lattice β] (gi : GaloisCoinsertion l u) : Lattice α := { gi.liftSemilatticeSup, gi.liftSemilatticeInf with } -- See note [reducible non-instances] /-- Lift the bot along a Galois coinsertion -/ abbrev liftOrderBot [Preorder β] [OrderBot β] (gi : GaloisCoinsertion l u) : OrderBot α := { @OrderDual.instOrderBot _ _ gi.dual.liftOrderTop with bot := gi.choice ⊥ <| bot_le } -- See note [reducible non-instances] /-- Lift the top, bottom, suprema, and infima along a Galois coinsertion -/ abbrev liftBoundedOrder [Preorder β] [BoundedOrder β] (gi : GaloisCoinsertion l u) : BoundedOrder α := { gi.liftOrderBot, gi.gc.liftOrderTop with } -- See note [reducible non-instances] /-- Lift all suprema and infima along a Galois coinsertion -/ abbrev liftCompleteLattice [CompleteLattice β] (gi : GaloisCoinsertion l u) : CompleteLattice α := { @OrderDual.instCompleteLattice αᵒᵈ gi.dual.liftCompleteLattice with sInf := fun s => u (sInf (l '' s)) sSup := fun s => gi.choice (sSup (l '' s)) _ } end lift end GaloisCoinsertion /-- `sSup` and `Iic` form a Galois insertion. -/ def gi_sSup_Iic [CompleteSemilatticeSup α] : GaloisInsertion (sSup : Set α → α) (Iic : α → Set α) := gc_sSup_Iic.toGaloisInsertion fun _ ↦ le_sSup le_rfl /-- `toDual ∘ Ici` and `sInf ∘ ofDual` form a Galois coinsertion. -/ def gci_Ici_sInf [CompleteSemilatticeInf α] : GaloisCoinsertion (toDual ∘ Ici : α → (Set α)ᵒᵈ) (sInf ∘ ofDual : (Set α)ᵒᵈ → α) := gc_Ici_sInf.toGaloisCoinsertion fun _ ↦ sInf_le le_rfl /-- If `α` is a partial order with bottom element (e.g., `ℕ`, `ℝ≥0`), then `WithBot.unbot' ⊥` and coercion form a Galois insertion. -/ def WithBot.giUnbotDBot [Preorder α] [OrderBot α] : GaloisInsertion (WithBot.unbotD ⊥) (some : α → WithBot α) where gc _ _ := WithBot.unbotD_le_iff (fun _ ↦ bot_le) le_l_u _ := le_rfl choice o _ := o.unbotD ⊥ choice_eq _ _ := rfl
.lake/packages/mathlib/Mathlib/Order/GaloisConnection/Defs.lean
import Mathlib.Order.BoundedOrder.Basic import Mathlib.Order.Monotone.Basic import Mathlib.Tactic.Monotonicity.Attr import Mathlib.Util.AssertExists /-! # Galois connections, insertions and coinsertions Galois connections are order-theoretic adjoints, i.e. a pair of functions `u` and `l`, such that `∀ a b, l a ≤ b ↔ a ≤ u b`. ## Main definitions * `GaloisConnection`: A Galois connection is a pair of functions `l` and `u` satisfying `l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory, but do not depend on the category theory library in mathlib. * `GaloisInsertion`: A Galois insertion is a Galois connection where `l ∘ u = id` * `GaloisCoinsertion`: A Galois coinsertion is a Galois connection where `u ∘ l = id` -/ assert_not_exists CompleteLattice RelIso open Function OrderDual Set universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {κ : ι → Sort*} {a₁ a₂ : α} {b₁ b₂ : β} /-- A Galois connection is a pair of functions `l` and `u` satisfying `l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory, but do not depend on the category theory library in mathlib. -/ def GaloisConnection [Preorder α] [Preorder β] (l : α → β) (u : β → α) := ∀ a b, l a ≤ b ↔ a ≤ u b namespace GaloisConnection section variable [Preorder α] [Preorder β] {l : α → β} {u : β → α} theorem monotone_intro (hu : Monotone u) (hl : Monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ a, l (u a) ≤ a) : GaloisConnection l u := fun _ _ => ⟨fun h => (hul _).trans (hu h), fun h => (hl h).trans (hlu _)⟩ protected theorem dual {l : α → β} {u : β → α} (gc : GaloisConnection l u) : GaloisConnection (OrderDual.toDual ∘ u ∘ OrderDual.ofDual) (OrderDual.toDual ∘ l ∘ OrderDual.ofDual) := fun a b => (gc b a).symm variable (gc : GaloisConnection l u) include gc theorem le_iff_le {a : α} {b : β} : l a ≤ b ↔ a ≤ u b := gc _ _ theorem l_le {a : α} {b : β} : a ≤ u b → l a ≤ b := (gc _ _).mpr theorem le_u {a : α} {b : β} : l a ≤ b → a ≤ u b := (gc _ _).mp theorem le_u_l (a) : a ≤ u (l a) := gc.le_u <| le_rfl theorem l_u_le (a) : l (u a) ≤ a := gc.l_le <| le_rfl theorem monotone_u : Monotone u := fun a _ H => gc.le_u ((gc.l_u_le a).trans H) theorem monotone_l : Monotone l := gc.dual.monotone_u.dual /-- If `(l, u)` is a Galois connection, then the relation `x ≤ u (l y)` is a transitive relation. If `l` is a closure operator (`Submodule.span`, `Subgroup.closure`, ...) and `u` is the coercion to `Set`, this reads as "if `U` is in the closure of `V` and `V` is in the closure of `W` then `U` is in the closure of `W`". -/ theorem le_u_l_trans {x y z : α} (hxy : x ≤ u (l y)) (hyz : y ≤ u (l z)) : x ≤ u (l z) := hxy.trans (gc.monotone_u <| gc.l_le hyz) theorem l_u_le_trans {x y z : β} (hxy : l (u x) ≤ y) (hyz : l (u y) ≤ z) : l (u x) ≤ z := (gc.monotone_l <| gc.le_u hxy).trans hyz end section PartialOrder variable [PartialOrder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) include gc theorem u_l_u_eq_u (b : β) : u (l (u b)) = u b := (gc.monotone_u (gc.l_u_le _)).antisymm (gc.le_u_l _) theorem u_l_u_eq_u' : u ∘ l ∘ u = u := funext gc.u_l_u_eq_u theorem u_unique {l' : α → β} {u' : β → α} (gc' : GaloisConnection l' u') (hl : ∀ a, l a = l' a) {b : β} : u b = u' b := le_antisymm (gc'.le_u <| hl (u b) ▸ gc.l_u_le _) (gc.le_u <| (hl (u' b)).symm ▸ gc'.l_u_le _) /-- If there exists a `b` such that `a = u a`, then `b = l a` is one such element. -/ theorem exists_eq_u (a : α) : (∃ b : β, a = u b) ↔ a = u (l a) := ⟨fun ⟨_, hS⟩ => hS.symm ▸ (gc.u_l_u_eq_u _).symm, fun HI => ⟨_, HI⟩⟩ theorem u_eq {z : α} {y : β} : u y = z ↔ ∀ x, x ≤ z ↔ l x ≤ y := by constructor · rintro rfl x exact (gc x y).symm · intro H exact ((H <| u y).mpr (gc.l_u_le y)).antisymm ((gc _ _).mp <| (H z).mp le_rfl) end PartialOrder section PartialOrder variable [Preorder α] [PartialOrder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) include gc theorem l_u_l_eq_l (a : α) : l (u (l a)) = l a := gc.dual.u_l_u_eq_u _ theorem l_u_l_eq_l' : l ∘ u ∘ l = l := funext gc.l_u_l_eq_l theorem l_unique {l' : α → β} {u' : β → α} (gc' : GaloisConnection l' u') (hu : ∀ b, u b = u' b) {a : α} : l a = l' a := gc.dual.u_unique gc'.dual hu /-- If there exists an `a` such that `b = l a`, then `a = u b` is one such element. -/ theorem exists_eq_l (b : β) : (∃ a : α, b = l a) ↔ b = l (u b) := gc.dual.exists_eq_u _ theorem l_eq {x : α} {z : β} : l x = z ↔ ∀ y, z ≤ y ↔ x ≤ u y := gc.dual.u_eq end PartialOrder section OrderTop variable [PartialOrder α] [Preorder β] [OrderTop α] theorem u_eq_top {l : α → β} {u : β → α} (gc : GaloisConnection l u) {x} : u x = ⊤ ↔ l ⊤ ≤ x := top_le_iff.symm.trans gc.le_iff_le.symm theorem u_top [OrderTop β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : u ⊤ = ⊤ := gc.u_eq_top.2 le_top theorem u_l_top {l : α → β} {u : β → α} (gc : GaloisConnection l u) : u (l ⊤) = ⊤ := gc.u_eq_top.mpr le_rfl end OrderTop section OrderBot variable [Preorder α] [PartialOrder β] [OrderBot β] theorem l_eq_bot {l : α → β} {u : β → α} (gc : GaloisConnection l u) {x} : l x = ⊥ ↔ x ≤ u ⊥ := gc.dual.u_eq_top theorem l_bot [OrderBot α] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : l ⊥ = ⊥ := gc.dual.u_top theorem l_u_bot {l : α → β} {u : β → α} (gc : GaloisConnection l u) : l (u ⊥) = ⊥ := gc.l_eq_bot.mpr le_rfl end OrderBot section LinearOrder variable [LinearOrder α] [LinearOrder β] {l : α → β} {u : β → α} theorem lt_iff_lt (gc : GaloisConnection l u) {a : α} {b : β} : b < l a ↔ u b < a := lt_iff_lt_of_le_iff_le (gc a b) end LinearOrder -- Constructing Galois connections section Constructions protected theorem id [pα : Preorder α] : @GaloisConnection α α pα pα id id := fun _ _ => Iff.intro (fun x => x) fun x => x protected theorem compose [Preorder α] [Preorder β] [Preorder γ] {l1 : α → β} {u1 : β → α} {l2 : β → γ} {u2 : γ → β} (gc1 : GaloisConnection l1 u1) (gc2 : GaloisConnection l2 u2) : GaloisConnection (l2 ∘ l1) (u1 ∘ u2) := fun _ _ ↦ (gc2 _ _).trans (gc1 _ _) protected theorem dfun {ι : Type u} {α : ι → Type v} {β : ι → Type w} [∀ i, Preorder (α i)] [∀ i, Preorder (β i)] (l : ∀ i, α i → β i) (u : ∀ i, β i → α i) (gc : ∀ i, GaloisConnection (l i) (u i)) : GaloisConnection (fun (a : ∀ i, α i) i => l i (a i)) fun b i => u i (b i) := fun a b => forall_congr' fun i => gc i (a i) (b i) end Constructions theorem l_comm_of_u_comm {X : Type*} [Preorder X] {Y : Type*} [Preorder Y] {Z : Type*} [Preorder Z] {W : Type*} [PartialOrder W] {lYX : X → Y} {uXY : Y → X} (hXY : GaloisConnection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : GaloisConnection lWZ uZW) {lWY : Y → W} {uYW : W → Y} (hWY : GaloisConnection lWY uYW) {lZX : X → Z} {uXZ : Z → X} (hXZ : GaloisConnection lZX uXZ) (h : ∀ w, uXZ (uZW w) = uXY (uYW w)) {x : X} : lWZ (lZX x) = lWY (lYX x) := (hXZ.compose hZW).l_unique (hXY.compose hWY) h theorem u_comm_of_l_comm {X : Type*} [PartialOrder X] {Y : Type*} [Preorder Y] {Z : Type*} [Preorder Z] {W : Type*} [Preorder W] {lYX : X → Y} {uXY : Y → X} (hXY : GaloisConnection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : GaloisConnection lWZ uZW) {lWY : Y → W} {uYW : W → Y} (hWY : GaloisConnection lWY uYW) {lZX : X → Z} {uXZ : Z → X} (hXZ : GaloisConnection lZX uXZ) (h : ∀ x, lWZ (lZX x) = lWY (lYX x)) {w : W} : uXZ (uZW w) = uXY (uYW w) := (hXZ.compose hZW).u_unique (hXY.compose hWY) h theorem l_comm_iff_u_comm {X : Type*} [PartialOrder X] {Y : Type*} [Preorder Y] {Z : Type*} [Preorder Z] {W : Type*} [PartialOrder W] {lYX : X → Y} {uXY : Y → X} (hXY : GaloisConnection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : GaloisConnection lWZ uZW) {lWY : Y → W} {uYW : W → Y} (hWY : GaloisConnection lWY uYW) {lZX : X → Z} {uXZ : Z → X} (hXZ : GaloisConnection lZX uXZ) : (∀ w : W, uXZ (uZW w) = uXY (uYW w)) ↔ ∀ x : X, lWZ (lZX x) = lWY (lYX x) := ⟨hXY.l_comm_of_u_comm hZW hWY hXZ, hXY.u_comm_of_l_comm hZW hWY hXZ⟩ end GaloisConnection /-- A Galois insertion is a Galois connection where `l ∘ u = id`. It also contains a constructive choice function, to give better definitional equalities when lifting order structures. Dual to `GaloisCoinsertion` -/ structure GaloisInsertion {α β : Type*} [Preorder α] [Preorder β] (l : α → β) (u : β → α) where /-- A constructive choice function for images of `l`. -/ choice : ∀ x : α, u (l x) ≤ x → β /-- The Galois connection associated to a Galois insertion. -/ gc : GaloisConnection l u /-- Main property of a Galois insertion. -/ le_l_u : ∀ x, x ≤ l (u x) /-- Property of the choice function. -/ choice_eq : ∀ a h, choice a h = l a /-- A constructor for a Galois insertion with the trivial `choice` function. -/ def GaloisInsertion.monotoneIntro {α β : Type*} [Preorder α] [Preorder β] {l : α → β} {u : β → α} (hu : Monotone u) (hl : Monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ b, l (u b) = b) : GaloisInsertion l u where choice x _ := l x gc := GaloisConnection.monotone_intro hu hl hul fun b => le_of_eq (hlu b) le_l_u b := le_of_eq <| (hlu b).symm choice_eq _ _ := rfl /-- Make a `GaloisInsertion l u` from a `GaloisConnection l u` such that `∀ b, b ≤ l (u b)` -/ def GaloisConnection.toGaloisInsertion {α β : Type*} [Preorder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) (h : ∀ b, b ≤ l (u b)) : GaloisInsertion l u := { choice := fun x _ => l x gc le_l_u := h choice_eq := fun _ _ => rfl } /-- Lift the bottom along a Galois connection -/ def GaloisConnection.liftOrderBot {α β : Type*} [Preorder α] [OrderBot α] [PartialOrder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : OrderBot β where bot := l ⊥ bot_le _ := gc.l_le <| bot_le namespace GaloisInsertion variable {l : α → β} {u : β → α} theorem l_u_eq [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) (b : β) : l (u b) = b := (gi.gc.l_u_le _).antisymm (gi.le_l_u _) theorem leftInverse_l_u [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : LeftInverse l u := gi.l_u_eq theorem l_top [Preorder α] [PartialOrder β] [OrderTop α] [OrderTop β] (gi : GaloisInsertion l u) : l ⊤ = ⊤ := top_unique <| (gi.le_l_u _).trans <| gi.gc.monotone_l le_top theorem l_surjective [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : Surjective l := gi.leftInverse_l_u.surjective theorem u_injective [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : Injective u := gi.leftInverse_l_u.injective theorem u_le_u_iff [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {a b} : u a ≤ u b ↔ a ≤ b := ⟨fun h => (gi.le_l_u _).trans (gi.gc.l_le h), fun h => gi.gc.monotone_u h⟩ theorem strictMono_u [Preorder α] [Preorder β] (gi : GaloisInsertion l u) : StrictMono u := strictMono_of_le_iff_le fun _ _ => gi.u_le_u_iff.symm end GaloisInsertion /-- A Galois coinsertion is a Galois connection where `u ∘ l = id`. It also contains a constructive choice function, to give better definitional equalities when lifting order structures. Dual to `GaloisInsertion` -/ structure GaloisCoinsertion [Preorder α] [Preorder β] (l : α → β) (u : β → α) where /-- A constructive choice function for images of `u`. -/ choice : ∀ x : β, x ≤ l (u x) → α /-- The Galois connection associated to a Galois coinsertion. -/ gc : GaloisConnection l u /-- Main property of a Galois coinsertion. -/ u_l_le : ∀ x, u (l x) ≤ x /-- Property of the choice function. -/ choice_eq : ∀ a h, choice a h = u a /-- Make a `GaloisInsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisCoinsertion` between `α` and `β`. -/ def GaloisCoinsertion.dual [Preorder α] [Preorder β] {l : α → β} {u : β → α} : GaloisCoinsertion l u → GaloisInsertion (toDual ∘ u ∘ ofDual) (toDual ∘ l ∘ ofDual) := fun x => ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Make a `GaloisCoinsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisInsertion` between `α` and `β`. -/ def GaloisInsertion.dual [Preorder α] [Preorder β] {l : α → β} {u : β → α} : GaloisInsertion l u → GaloisCoinsertion (toDual ∘ u ∘ ofDual) (toDual ∘ l ∘ ofDual) := fun x => ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Make a `GaloisInsertion` between `α` and `β` from a `GaloisCoinsertion` between `αᵒᵈ` and `βᵒᵈ`. -/ def GaloisCoinsertion.ofDual [Preorder α] [Preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} : GaloisCoinsertion l u → GaloisInsertion (ofDual ∘ u ∘ toDual) (ofDual ∘ l ∘ toDual) := fun x => ⟨x.1, x.2.dual, x.3, x.4⟩ /-- Make a `GaloisCoinsertion` between `α` and `β` from a `GaloisInsertion` between `αᵒᵈ` and `βᵒᵈ`. -/ def GaloisInsertion.ofDual [Preorder α] [Preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} : GaloisInsertion l u → GaloisCoinsertion (ofDual ∘ u ∘ toDual) (ofDual ∘ l ∘ toDual) := fun x => ⟨x.1, x.2.dual, x.3, x.4⟩ /-- A constructor for a Galois coinsertion with the trivial `choice` function. -/ def GaloisCoinsertion.monotoneIntro [Preorder α] [Preorder β] {l : α → β} {u : β → α} (hu : Monotone u) (hl : Monotone l) (hlu : ∀ b, l (u b) ≤ b) (hul : ∀ a, u (l a) = a) : GaloisCoinsertion l u := (GaloisInsertion.monotoneIntro hl.dual hu.dual hlu hul).ofDual /-- Make a `GaloisCoinsertion l u` from a `GaloisConnection l u` such that `∀ a, u (l a) ≤ a` -/ def GaloisConnection.toGaloisCoinsertion {α β : Type*} [Preorder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) (h : ∀ a, u (l a) ≤ a) : GaloisCoinsertion l u := { choice := fun x _ => u x gc u_l_le := h choice_eq := fun _ _ => rfl } /-- Lift the top along a Galois connection -/ def GaloisConnection.liftOrderTop {α β : Type*} [PartialOrder α] [Preorder β] [OrderTop β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : OrderTop α where top := u ⊤ le_top _ := gc.le_u <| le_top namespace GaloisCoinsertion variable {l : α → β} {u : β → α} theorem u_l_eq [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) (a : α) : u (l a) = a := gi.dual.l_u_eq a theorem u_l_leftInverse [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : LeftInverse u l := gi.u_l_eq theorem u_bot [PartialOrder α] [Preorder β] [OrderBot α] [OrderBot β] (gi : GaloisCoinsertion l u) : u ⊥ = ⊥ := gi.dual.l_top theorem u_surjective [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : Surjective u := gi.dual.l_surjective theorem l_injective [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : Injective l := gi.dual.u_injective theorem l_le_l_iff [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {a b} : l a ≤ l b ↔ a ≤ b := gi.dual.u_le_u_iff theorem strictMono_l [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) : StrictMono l := fun _ _ h => gi.dual.strictMono_u h end GaloisCoinsertion
.lake/packages/mathlib/Mathlib/Order/CompactlyGenerated/Basic.lean
import Mathlib.Order.Atoms import Mathlib.Order.OrderIsoNat import Mathlib.Order.RelIso.Set import Mathlib.Order.SupClosed import Mathlib.Order.SupIndep import Mathlib.Order.Zorn import Mathlib.Data.Finset.Order import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Data.Finite.Set import Mathlib.Tactic.TFAE /-! # Compactness properties for complete lattices For complete lattices, there are numerous equivalent ways to express the fact that the relation `>` is well-founded. In this file we define three especially-useful characterisations and provide proofs that they are indeed equivalent to well-foundedness. ## Main definitions * `CompleteLattice.IsSupClosedCompact` * `CompleteLattice.IsSupFiniteCompact` * `CompleteLattice.IsCompactElement` * `IsCompactlyGenerated` ## Main results The main result is that the following four conditions are equivalent for a complete lattice: * `well_founded (>)` * `CompleteLattice.IsSupClosedCompact` * `CompleteLattice.IsSupFiniteCompact` * `∀ k, CompleteLattice.IsCompactElement k` This is demonstrated by means of the following four lemmas: * `CompleteLattice.WellFounded.isSupFiniteCompact` * `CompleteLattice.IsSupFiniteCompact.isSupClosedCompact` * `CompleteLattice.IsSupClosedCompact.wellFounded` * `CompleteLattice.isSupFiniteCompact_iff_all_elements_compact` We also show well-founded lattices are compactly generated (`CompleteLattice.isCompactlyGenerated_of_wellFounded`). ## References - [G. Călugăreanu, *Lattice Concepts of Module Theory*][calugareanu] ## Tags complete lattice, well-founded, compact -/ open Set variable {ι : Sort*} {α : Type*} [CompleteLattice α] {f : ι → α} namespace CompleteLattice variable (α) /-- A compactness property for a complete lattice is that any `sup`-closed non-empty subset contains its `sSup`. -/ def IsSupClosedCompact : Prop := ∀ (s : Set α) (_ : s.Nonempty), SupClosed s → sSup s ∈ s /-- A compactness property for a complete lattice is that any subset has a finite subset with the same `sSup`. -/ def IsSupFiniteCompact : Prop := ∀ s : Set α, ∃ t : Finset α, ↑t ⊆ s ∧ sSup s = t.sup id /-- An element `k` of a complete lattice is said to be compact if any set with `sSup` above `k` has a finite subset with `sSup` above `k`. Such an element is also called "finite" or "S-compact". -/ def IsCompactElement {α : Type*} [CompleteLattice α] (k : α) := ∀ s : Set α, k ≤ sSup s → ∃ t : Finset α, ↑t ⊆ s ∧ k ≤ t.sup id theorem isCompactElement_iff.{u} {α : Type u} [CompleteLattice α] (k : α) : CompleteLattice.IsCompactElement k ↔ ∀ (ι : Type u) (s : ι → α), k ≤ iSup s → ∃ t : Finset ι, k ≤ t.sup s := by classical constructor · intro H ι s hs obtain ⟨t, ht, ht'⟩ := H (Set.range s) hs have : ∀ x : t, ∃ i, s i = x := fun x => ht x.prop choose f hf using this refine ⟨Finset.univ.image f, ht'.trans ?_⟩ rw [Finset.sup_le_iff] intro b hb rw [← show s (f ⟨b, hb⟩) = id b from hf _] exact Finset.le_sup (Finset.mem_image_of_mem f <| Finset.mem_univ (Subtype.mk b hb)) · intro H s hs obtain ⟨t, ht⟩ := H s Subtype.val (by delta iSup rwa [Subtype.range_coe]) refine ⟨t.image Subtype.val, by simp, ht.trans ?_⟩ rw [Finset.sup_le_iff] exact fun x hx => @Finset.le_sup _ _ _ _ _ id _ (Finset.mem_image_of_mem Subtype.val hx) /-- An element `k` is compact if and only if any directed set with `sSup` above `k` already got above `k` at some point in the set. -/ theorem isCompactElement_iff_le_of_directed_sSup_le (k : α) : IsCompactElement k ↔ ∀ s : Set α, s.Nonempty → DirectedOn (· ≤ ·) s → k ≤ sSup s → ∃ x : α, x ∈ s ∧ k ≤ x := by classical constructor · intro hk s hne hdir hsup obtain ⟨t, ht⟩ := hk s hsup -- certainly every element of t is below something in s, since ↑t ⊆ s. have t_below_s : ∀ x ∈ t, ∃ y ∈ s, x ≤ y := fun x hxt => ⟨x, ht.left hxt, le_rfl⟩ obtain ⟨x, ⟨hxs, hsupx⟩⟩ := Finset.sup_le_of_le_directed s hne hdir t t_below_s exact ⟨x, ⟨hxs, le_trans ht.right hsupx⟩⟩ · intro hk s hsup -- Consider the set of finite joins of elements of the (plain) set s. let S : Set α := { x | ∃ t : Finset α, ↑t ⊆ s ∧ x = t.sup id } -- S is directed, nonempty, and still has sup above k. have dir_US : DirectedOn (· ≤ ·) S := by rintro x ⟨c, hc⟩ y ⟨d, hd⟩ use x ⊔ y constructor · use c ∪ d constructor · simp only [hc.left, hd.left, Set.union_subset_iff, Finset.coe_union, and_self_iff] · simp only [hc.right, hd.right, Finset.sup_union] simp only [and_self_iff, le_sup_left, le_sup_right] have sup_S : sSup s ≤ sSup S := by apply sSup_le_sSup intro x hx use {x} simpa only [and_true, id, Finset.coe_singleton, eq_self_iff_true, Finset.sup_singleton, Set.singleton_subset_iff] have Sne : S.Nonempty := by suffices ⊥ ∈ S from Set.nonempty_of_mem this use ∅ simp only [Set.empty_subset, Finset.coe_empty, Finset.sup_empty, and_self_iff] -- Now apply the defn of compact and finish. obtain ⟨j, ⟨hjS, hjk⟩⟩ := hk S Sne dir_US (le_trans hsup sup_S) obtain ⟨t, ⟨htS, htsup⟩⟩ := hjS use t exact ⟨htS, by rwa [← htsup]⟩ theorem IsCompactElement.exists_finset_of_le_iSup {k : α} (hk : IsCompactElement k) {ι : Type*} (f : ι → α) (h : k ≤ ⨆ i, f i) : ∃ s : Finset ι, k ≤ ⨆ i ∈ s, f i := by classical let g : Finset ι → α := fun s => ⨆ i ∈ s, f i have h1 : DirectedOn (· ≤ ·) (Set.range g) := by rintro - ⟨s, rfl⟩ - ⟨t, rfl⟩ exact ⟨g (s ∪ t), ⟨s ∪ t, rfl⟩, iSup_le_iSup_of_subset Finset.subset_union_left, iSup_le_iSup_of_subset Finset.subset_union_right⟩ have h2 : k ≤ sSup (Set.range g) := h.trans (iSup_le fun i => le_sSup_of_le ⟨{i}, rfl⟩ (le_iSup_of_le i (le_iSup_of_le (Finset.mem_singleton_self i) le_rfl))) obtain ⟨-, ⟨s, rfl⟩, hs⟩ := (isCompactElement_iff_le_of_directed_sSup_le α k).mp hk (Set.range g) (Set.range_nonempty g) h1 h2 exact ⟨s, hs⟩ /-- A compact element `k` has the property that any directed set lying strictly below `k` has its `sSup` strictly below `k`. -/ theorem IsCompactElement.directed_sSup_lt_of_lt {α : Type*} [CompleteLattice α] {k : α} (hk : IsCompactElement k) {s : Set α} (hemp : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) (hbelow : ∀ x ∈ s, x < k) : sSup s < k := by rw [isCompactElement_iff_le_of_directed_sSup_le] at hk by_contra h have sSup' : sSup s ≤ k := sSup_le s k fun s hs => (hbelow s hs).le replace sSup : sSup s = k := eq_iff_le_not_lt.mpr ⟨sSup', h⟩ obtain ⟨x, hxs, hkx⟩ := hk s hemp hdir sSup.symm.le obtain hxk := hbelow x hxs exact hxk.ne (hxk.le.antisymm hkx) theorem isCompactElement_finsetSup {α β : Type*} [CompleteLattice α] {f : β → α} (s : Finset β) (h : ∀ x ∈ s, IsCompactElement (f x)) : IsCompactElement (s.sup f) := by classical rw [isCompactElement_iff_le_of_directed_sSup_le] intro d hemp hdir hsup rw [← Function.id_comp f] rw [← Finset.sup_image] apply Finset.sup_le_of_le_directed d hemp hdir rintro x hx obtain ⟨p, ⟨hps, rfl⟩⟩ := Finset.mem_image.mp hx specialize h p hps rw [isCompactElement_iff_le_of_directed_sSup_le] at h specialize h d hemp hdir (le_trans (Finset.le_sup hps) hsup) simpa only [exists_prop] theorem WellFoundedGT.isSupFiniteCompact [WellFoundedGT α] : IsSupFiniteCompact α := fun s => by let S := { x | ∃ t : Finset α, ↑t ⊆ s ∧ t.sup id = x } obtain ⟨m, ⟨t, ⟨ht₁, rfl⟩⟩, hm⟩ := wellFounded_gt.has_min S ⟨⊥, ∅, by simp⟩ refine ⟨t, ht₁, (sSup_le _ _ fun y hy => ?_).antisymm ?_⟩ · classical rw [eq_of_le_of_not_lt (Finset.sup_mono (t.subset_insert y)) (hm _ ⟨insert y t, by simp [Set.insert_subset_iff, hy, ht₁]⟩)] simp · rw [Finset.sup_id_eq_sSup] exact sSup_le_sSup ht₁ theorem IsSupFiniteCompact.isSupClosedCompact (h : IsSupFiniteCompact α) : IsSupClosedCompact α := by intro s hne hsc; obtain ⟨t, ht₁, ht₂⟩ := h s; clear h rcases t.eq_empty_or_nonempty with h | h · subst h rw [Finset.sup_empty] at ht₂ rw [ht₂] simp [eq_singleton_bot_of_sSup_eq_bot_of_nonempty ht₂ hne] · rw [ht₂] exact hsc.finsetSup_mem h ht₁ theorem IsSupClosedCompact.wellFoundedGT (h : IsSupClosedCompact α) : WellFoundedGT α where wf := by refine RelEmbedding.wellFounded_iff_isEmpty.mpr ⟨fun a => ?_⟩ suffices sSup (Set.range a) ∈ Set.range a by obtain ⟨n, hn⟩ := Set.mem_range.mp this have h' : sSup (Set.range a) < a (n + 1) := by change _ > _ simp [← hn, a.map_rel_iff] apply lt_irrefl (a (n + 1)) apply lt_of_le_of_lt _ h' apply le_sSup apply Set.mem_range_self apply h (Set.range a) · use a 37 apply Set.mem_range_self · rintro x ⟨m, hm⟩ y ⟨n, hn⟩ use m ⊔ n rw [← hm, ← hn] apply RelHomClass.map_sup a theorem isSupFiniteCompact_iff_all_elements_compact : IsSupFiniteCompact α ↔ ∀ k : α, IsCompactElement k := by refine ⟨fun h k s hs => ?_, fun h s => ?_⟩ · obtain ⟨t, ⟨hts, htsup⟩⟩ := h s use t, hts rwa [← htsup] · obtain ⟨t, ⟨hts, htsup⟩⟩ := h (sSup s) s (by rfl) have : sSup s = t.sup id := by suffices t.sup id ≤ sSup s by apply le_antisymm <;> assumption simp only [id, Finset.sup_le_iff] intro x hx exact le_sSup _ _ (hts hx) exact ⟨t, hts, this⟩ open List in theorem wellFoundedGT_characterisations : List.TFAE [WellFoundedGT α, IsSupFiniteCompact α, IsSupClosedCompact α, ∀ k : α, IsCompactElement k] := by tfae_have 1 → 2 := @WellFoundedGT.isSupFiniteCompact α _ tfae_have 2 → 3 := IsSupFiniteCompact.isSupClosedCompact α tfae_have 3 → 1 := IsSupClosedCompact.wellFoundedGT α tfae_have 2 ↔ 4 := isSupFiniteCompact_iff_all_elements_compact α tfae_finish theorem wellFoundedGT_iff_isSupFiniteCompact : WellFoundedGT α ↔ IsSupFiniteCompact α := (wellFoundedGT_characterisations α).out 0 1 theorem isSupFiniteCompact_iff_isSupClosedCompact : IsSupFiniteCompact α ↔ IsSupClosedCompact α := (wellFoundedGT_characterisations α).out 1 2 theorem isSupClosedCompact_iff_wellFoundedGT : IsSupClosedCompact α ↔ WellFoundedGT α := (wellFoundedGT_characterisations α).out 2 0 alias ⟨_, IsSupFiniteCompact.wellFoundedGT⟩ := wellFoundedGT_iff_isSupFiniteCompact alias ⟨_, IsSupClosedCompact.isSupFiniteCompact⟩ := isSupFiniteCompact_iff_isSupClosedCompact alias ⟨_, WellFoundedGT.isSupClosedCompact⟩ := isSupClosedCompact_iff_wellFoundedGT end CompleteLattice theorem WellFoundedGT.finite_of_sSupIndep [WellFoundedGT α] {s : Set α} (hs : sSupIndep s) : s.Finite := by classical refine Set.not_infinite.mp fun contra => ?_ obtain ⟨t, ht₁, ht₂⟩ := CompleteLattice.WellFoundedGT.isSupFiniteCompact α s replace contra : ∃ x : α, x ∈ s ∧ x ≠ ⊥ ∧ x ∉ t := by have : (s \ (insert ⊥ t : Finset α)).Infinite := contra.diff (Finset.finite_toSet _) obtain ⟨x, hx₁, hx₂⟩ := this.nonempty exact ⟨x, hx₁, by simpa [not_or] using hx₂⟩ obtain ⟨x, hx₀, hx₁, hx₂⟩ := contra replace hs : x ⊓ sSup s = ⊥ := by have := hs.mono (by simp [ht₁, hx₀, -Set.union_singleton] : ↑t ∪ {x} ≤ s) (by simp : x ∈ _) simpa [Disjoint, hx₂, ← t.sup_id_eq_sSup, ← ht₂] using this.eq_bot apply hx₁ rw [← hs, eq_comm, inf_eq_left] exact le_sSup hx₀ theorem WellFoundedGT.finite_ne_bot_of_iSupIndep [WellFoundedGT α] {ι : Type*} {t : ι → α} (ht : iSupIndep t) : Set.Finite {i | t i ≠ ⊥} := by refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn exact WellFoundedGT.finite_of_sSupIndep ht.sSupIndep_range theorem WellFoundedGT.finite_of_iSupIndep [WellFoundedGT α] {ι : Type*} {t : ι → α} (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι := haveI := (WellFoundedGT.finite_of_sSupIndep ht.sSupIndep_range).to_subtype Finite.of_injective_finite_range (ht.injective h_ne_bot) theorem WellFoundedLT.finite_of_sSupIndep [WellFoundedLT α] {s : Set α} (hs : sSupIndep s) : s.Finite := by by_contra inf let e := (Infinite.diff inf <| finite_singleton ⊥).to_subtype.natEmbedding let a n := ⨆ i ≥ n, (e i).1 have sup_le n : (e n).1 ⊔ a (n + 1) ≤ a n := sup_le_iff.mpr ⟨le_iSup₂_of_le n le_rfl le_rfl, iSup₂_le fun i hi ↦ le_iSup₂_of_le i (n.le_succ.trans hi) le_rfl⟩ have lt n : a (n + 1) < a n := (Disjoint.right_lt_sup_of_left_ne_bot ((hs (e n).2.1).mono_right <| iSup₂_le fun i hi ↦ le_sSup ?_) (e n).2.2).trans_le (sup_le n) · exact (RelEmbedding.natGT a lt).not_wellFounded wellFounded_lt exact ⟨(e i).2.1, fun h ↦ n.lt_succ_self.not_ge <| hi.trans_eq <| e.2 <| Subtype.val_injective h⟩ theorem WellFoundedLT.finite_ne_bot_of_iSupIndep [WellFoundedLT α] {ι : Type*} {t : ι → α} (ht : iSupIndep t) : Set.Finite {i | t i ≠ ⊥} := by refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn exact WellFoundedLT.finite_of_sSupIndep ht.sSupIndep_range theorem WellFoundedLT.finite_of_iSupIndep [WellFoundedLT α] {ι : Type*} {t : ι → α} (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι := haveI := (WellFoundedLT.finite_of_sSupIndep ht.sSupIndep_range).to_subtype Finite.of_injective_finite_range (ht.injective h_ne_bot) /-- A complete lattice is said to be compactly generated if any element is the `sSup` of compact elements. -/ class IsCompactlyGenerated (α : Type*) [CompleteLattice α] : Prop where /-- In a compactly generated complete lattice, every element is the `sSup` of some set of compact elements. -/ exists_sSup_eq : ∀ x : α, ∃ s : Set α, (∀ x ∈ s, CompleteLattice.IsCompactElement x) ∧ sSup s = x section variable [IsCompactlyGenerated α] {a : α} {s : Set α} @[simp] theorem sSup_compact_le_eq (b) : sSup { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } = b := by rcases IsCompactlyGenerated.exists_sSup_eq b with ⟨s, hs, rfl⟩ exact le_antisymm (sSup_le fun c hc => hc.2) (sSup_le_sSup fun c cs => ⟨hs c cs, le_sSup cs⟩) @[simp] theorem sSup_compact_eq_top : sSup { a : α | CompleteLattice.IsCompactElement a } = ⊤ := by refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_compact_le_eq ⊤) exact (and_iff_left le_top).symm theorem le_iff_compact_le_imp {a b : α} : a ≤ b ↔ ∀ c : α, CompleteLattice.IsCompactElement c → c ≤ a → c ≤ b := ⟨fun ab _ _ ca => le_trans ca ab, fun h => by rw [← sSup_compact_le_eq a, ← sSup_compact_le_eq b] exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩ /-- This property is sometimes referred to as `α` being upper continuous. -/ theorem DirectedOn.inf_sSup_eq (h : DirectedOn (· ≤ ·) s) : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b := le_antisymm (by rw [le_iff_compact_le_imp] by_cases hs : s.Nonempty · intro c hc hcinf rw [le_inf_iff] at hcinf rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] at hc rcases hc s hs h hcinf.2 with ⟨d, ds, cd⟩ refine (le_inf hcinf.1 cd).trans (le_trans ?_ (le_iSup₂ d ds)) rfl · rw [Set.not_nonempty_iff_eq_empty] at hs simp [hs]) iSup_inf_le_inf_sSup /-- This property is sometimes referred to as `α` being upper continuous. -/ protected theorem DirectedOn.sSup_inf_eq (h : DirectedOn (· ≤ ·) s) : sSup s ⊓ a = ⨆ b ∈ s, b ⊓ a := by simp_rw [inf_comm _ a, h.inf_sSup_eq] protected theorem Directed.inf_iSup_eq (h : Directed (· ≤ ·) f) : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by rw [iSup, h.directedOn_range.inf_sSup_eq, iSup_range] protected theorem Directed.iSup_inf_eq (h : Directed (· ≤ ·) f) : (⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by rw [iSup, h.directedOn_range.sSup_inf_eq, iSup_range] protected theorem DirectedOn.disjoint_sSup_right (h : DirectedOn (· ≤ ·) s) : Disjoint a (sSup s) ↔ ∀ ⦃b⦄, b ∈ s → Disjoint a b := by simp_rw [disjoint_iff, h.inf_sSup_eq, iSup_eq_bot] protected theorem DirectedOn.disjoint_sSup_left (h : DirectedOn (· ≤ ·) s) : Disjoint (sSup s) a ↔ ∀ ⦃b⦄, b ∈ s → Disjoint b a := by simp_rw [disjoint_iff, h.sSup_inf_eq, iSup_eq_bot] protected theorem Directed.disjoint_iSup_right (h : Directed (· ≤ ·) f) : Disjoint a (⨆ i, f i) ↔ ∀ i, Disjoint a (f i) := by simp_rw [disjoint_iff, h.inf_iSup_eq, iSup_eq_bot] protected theorem Directed.disjoint_iSup_left (h : Directed (· ≤ ·) f) : Disjoint (⨆ i, f i) a ↔ ∀ i, Disjoint (f i) a := by simp_rw [disjoint_iff, h.iSup_inf_eq, iSup_eq_bot] /-- This property is equivalent to `α` being upper continuous. -/ theorem inf_sSup_eq_iSup_inf_sup_finset : a ⊓ sSup s = ⨆ (t : Finset α) (_ : ↑t ⊆ s), a ⊓ t.sup id := le_antisymm (by rw [le_iff_compact_le_imp] intro c hc hcinf rw [le_inf_iff] at hcinf rcases hc s hcinf.2 with ⟨t, ht1, ht2⟩ refine (le_inf hcinf.1 ht2).trans (le_trans ?_ (le_iSup₂ t ht1)) rfl) (iSup_le fun t => iSup_le fun h => inf_le_inf_left _ ((Finset.sup_id_eq_sSup t).symm ▸ sSup_le_sSup h)) theorem sSupIndep_iff_finite {s : Set α} : sSupIndep s ↔ ∀ t : Finset α, ↑t ⊆ s → sSupIndep (↑t : Set α) := ⟨fun hs _ ht => hs.mono ht, fun h a ha => by rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot] intro t rw [iSup_eq_bot, Finset.sup_id_eq_sSup] intro ht classical have h' := (h (insert a t) ?_ (t.mem_insert_self a)).eq_bot · rwa [Finset.coe_insert, Set.insert_diff_self_of_notMem] at h' exact fun con => ((Set.mem_diff a).1 (ht con)).2 (Set.mem_singleton a) · rw [Finset.coe_insert, Set.insert_subset_iff] exact ⟨ha, Set.Subset.trans ht diff_subset⟩⟩ lemma iSupIndep_iff_supIndep_of_injOn {ι : Type*} {f : ι → α} (hf : InjOn f {i | f i ≠ ⊥}) : iSupIndep f ↔ ∀ (s : Finset ι), s.SupIndep f := by refine ⟨fun h ↦ h.supIndep', fun h ↦ iSupIndep_def'.mpr fun i ↦ ?_⟩ simp_rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot, ← disjoint_iff] intro s hs classical rw [← Finset.sup_erase_bot] set t := s.erase ⊥ replace hf : InjOn f (f ⁻¹' t) := fun i hi j _ hij ↦ by refine hf ?_ ?_ hij <;> aesop (add norm simp [t]) have : (Finset.erase (insert i (t.preimage _ hf)) i).image f = t := by ext a simp only [Finset.mem_preimage, Finset.mem_erase, ne_eq, Finset.erase_insert_eq_erase, Finset.mem_image, t] refine ⟨by aesop, fun ⟨ha, has⟩ ↦ ?_⟩ obtain ⟨j, hj, rfl⟩ := hs has exact ⟨j, ⟨hj, ha, has⟩, rfl⟩ rw [← this, Finset.sup_image] specialize h (insert i (t.preimage _ hf)) rw [Finset.supIndep_iff_disjoint_erase] at h exact h i (Finset.mem_insert_self i _) theorem sSupIndep_iUnion_of_directed {η : Type*} {s : η → Set α} (hs : Directed (· ⊆ ·) s) (h : ∀ i, sSupIndep (s i)) : sSupIndep (⋃ i, s i) := by by_cases hη : Nonempty η · rw [sSupIndep_iff_finite] intro t ht obtain ⟨I, fi, hI⟩ := Set.finite_subset_iUnion t.finite_toSet ht obtain ⟨i, hi⟩ := hs.finset_le fi.toFinset exact (h i).mono (Set.Subset.trans hI <| Set.iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) · rintro a ⟨_, ⟨i, _⟩, _⟩ exfalso exact hη ⟨i⟩ theorem iSupIndep_sUnion_of_directed {s : Set (Set α)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, sSupIndep a) : sSupIndep (⋃₀ s) := by rw [Set.sUnion_eq_iUnion] exact sSupIndep_iUnion_of_directed hs.directed_val (by simpa using h) end namespace CompleteLattice theorem isCompactlyGenerated_of_wellFoundedGT [h : WellFoundedGT α] : IsCompactlyGenerated α := by rw [wellFoundedGT_iff_isSupFiniteCompact, isSupFiniteCompact_iff_all_elements_compact] at h -- x is the join of the set of compact elements {x} exact ⟨fun x => ⟨{x}, ⟨fun x _ => h x, sSup_singleton⟩⟩⟩ /-- A compact element `k` has the property that any `b < k` lies below a "maximal element below `k`", which is to say `[⊥, k]` is coatomic. -/ theorem Iic_coatomic_of_compact_element {k : α} (h : IsCompactElement k) : IsCoatomic (Set.Iic k) := by constructor rintro ⟨b, hbk⟩ obtain rfl | H := eq_or_ne b k · left; ext; simp only [Set.Iic.coe_top] right have ⟨a, ba, h⟩ := zorn_le_nonempty₀ (Set.Iio k) ?_ b (lt_of_le_of_ne hbk H) · refine ⟨⟨a, le_of_lt h.prop⟩, ⟨ne_of_lt h.prop, fun c hck => by_contradiction fun c₀ => ?_⟩, ba⟩ cases h.eq_of_le (y := c.1) (lt_of_le_of_ne c.2 fun con ↦ c₀ (Subtype.ext con)) hck.le exact lt_irrefl _ hck · intro S SC cC I _ by_cases hS : S.Nonempty · refine ⟨sSup S, h.directed_sSup_lt_of_lt hS cC.directedOn SC, ?_⟩ intro; apply le_sSup exact ⟨b, lt_of_le_of_ne hbk H, by simp only [Set.not_nonempty_iff_eq_empty.mp hS, Set.mem_empty_iff_false, forall_const, forall_prop_of_false, not_false_iff]⟩ theorem coatomic_of_top_compact (h : IsCompactElement (⊤ : α)) : IsCoatomic α := (@OrderIso.IicTop α _ _).isCoatomic_iff.mp (Iic_coatomic_of_compact_element h) end CompleteLattice section variable [IsModularLattice α] [IsCompactlyGenerated α] /-- If each family `f i` is `iSupIndep`, then the family of pointwise infima `k ↦ ⨅ i, f i (k i)` is also `iSupIndep`. -/ theorem iSupIndep.iInf {ι : Type*} {κ : ι → Type*} (f : (i : ι) → κ i → α) (h_indep : ∀ i : ι, iSupIndep (f i)) : iSupIndep (fun k : (i : ι) → κ i ↦ ⨅ i, f i (k i)) := by rw [iSupIndep_iff_supIndep_of_injOn (iSupIndep.injOn_iInf _ h_indep)] intro s induction s using Finset.strongInduction with | H s ih => by_cases hs : 1 < s.card; swap · by_cases hcard0 : s.card = 0 <;> grind [Finset.card_eq_zero, Finset.card_eq_one] · obtain ⟨k₁, k₂, _, _, h⟩ := Finset.one_lt_card_iff.mp hs obtain ⟨i, hi⟩ : ∃ i : ι, k₁ i ≠ k₂ i := Function.ne_iff.mp h classical rw [← Finset.image_biUnion_filter_eq s (· i)] refine Finset.SupIndep.biUnion ?_ (by grind) apply ((h_indep i).supIndep' _).mono simp_rw [Finset.sup_le_iff, Finset.mem_filter, and_imp] rintro _ _ _ _ rfl exact iInf_le _ _ instance (priority := 100) isAtomic_of_complementedLattice [ComplementedLattice α] : IsAtomic α := ⟨fun b => by by_cases h : { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } ⊆ {⊥} · left rw [← sSup_compact_le_eq b, sSup_eq_bot] exact h · rcases Set.not_subset.1 h with ⟨c, ⟨hc, hcb⟩, hcbot⟩ right have hc' := CompleteLattice.Iic_coatomic_of_compact_element hc rw [← isAtomic_iff_isCoatomic] at hc' obtain con | ⟨a, ha, hac⟩ := eq_bot_or_exists_atom_le (⟨c, le_refl c⟩ : Set.Iic c) · exfalso apply hcbot simp only [Subtype.ext_iff, Set.Iic.coe_bot] at con exact con rw [← Subtype.coe_le_coe, Subtype.coe_mk] at hac exact ⟨a, ha.of_isAtom_coe_Iic, hac.trans hcb⟩⟩ /-- See [Lemma 5.1][calugareanu]. -/ instance (priority := 100) isAtomistic_of_complementedLattice [ComplementedLattice α] : IsAtomistic α := CompleteLattice.isAtomistic_iff.2 fun b => ⟨{ a | IsAtom a ∧ a ≤ b }, by symm have hle : sSup { a : α | IsAtom a ∧ a ≤ b } ≤ b := sSup_le fun _ => And.right apply (lt_or_eq_of_le hle).resolve_left _ intro con obtain ⟨c, hc⟩ := exists_isCompl (⟨sSup { a : α | IsAtom a ∧ a ≤ b }, hle⟩ : Set.Iic b) obtain rfl | ⟨a, ha, hac⟩ := eq_bot_or_exists_atom_le c · exact ne_of_lt con (Subtype.ext_iff.1 (eq_top_of_isCompl_bot hc)) · apply ha.1 rw [eq_bot_iff] apply le_trans (le_inf _ hac) hc.disjoint.le_bot rw [← Subtype.coe_le_coe, Subtype.coe_mk] exact le_sSup ⟨ha.of_isAtom_coe_Iic, a.2⟩, fun _ => And.left⟩ /-! Now we will prove that a compactly generated modular atomistic lattice is a complemented lattice. Most explicitly, every element is the complement of a supremum of independent atoms. -/ /-- In an atomic lattice, every element `b` has a complement of the form `sSup s` relative to a given element `c`, where each element of `s` is an atom. See also `complementedLattice_of_sSup_atoms_eq_top`. -/ theorem exists_sSupIndep_disjoint_sSup_atoms (b c : α) (hbc : b ≤ c) (h : sSup {a ≤ c | IsAtom a} = c) : ∃ s : Set α, sSupIndep s ∧ Disjoint b (sSup s) ∧ b ⊔ sSup s = c ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a := by -- porting note(https://github.com/leanprover-community/mathlib4/issues/5732): -- `obtain` chokes on the placeholder. have zorn := zorn_subset (S := {s : Set α | sSupIndep s ∧ Disjoint b (sSup s) ∧ ∀ a ∈ s, IsAtom a ∧ a ≤ c}) fun c hc1 hc2 => ⟨⋃₀ c, ⟨iSupIndep_sUnion_of_directed hc2.directedOn fun s hs => (hc1 hs).1, ?_, fun a ⟨s, sc, as⟩ => (hc1 sc).2.2 a as⟩, fun _ => Set.subset_sUnion_of_mem⟩ swap · rw [sSup_sUnion, ← sSup_image, DirectedOn.disjoint_sSup_right] · rintro _ ⟨s, hs, rfl⟩ exact (hc1 hs).2.1 · rw [directedOn_image] exact hc2.directedOn.mono @fun s t => sSup_le_sSup simp_rw [maximal_subset_iff] at zorn obtain ⟨s, ⟨s_ind, b_inf_Sup_s, s_atoms⟩, s_max⟩ := zorn refine ⟨s, s_ind, b_inf_Sup_s, le_antisymm ?_ ?_, fun a ha ↦ (s_atoms a ha).1⟩ · simp_all rw [← h, sSup_le_iff] intro a ha rw [← inf_eq_left] refine (ha.2.le_iff.mp inf_le_left).resolve_left fun con => ha.2.1 ?_ rw [← con, eq_comm, inf_eq_left] refine (le_sSup ?_).trans le_sup_right rw [← disjoint_iff] at con have a_dis_Sup_s : Disjoint a (sSup s) := con.mono_right le_sup_right rw [s_max ⟨fun x hx => ?_, ?_, fun x hx => ?_⟩ Set.subset_union_left] · exact Set.mem_union_right _ (Set.mem_singleton _) · rw [sSup_union, sSup_singleton] exact b_inf_Sup_s.disjoint_sup_right_of_disjoint_sup_left con.symm · rw [Set.mem_union, Set.mem_singleton_iff] at hx obtain rfl | xa := eq_or_ne x a · simp only [Set.mem_singleton, Set.insert_diff_of_mem, Set.union_singleton] exact con.mono_right ((sSup_le_sSup Set.diff_subset).trans le_sup_right) · have h : (s ∪ {a}) \ {x} = s \ {x} ∪ {a} := by simp only [Set.union_singleton] rw [Set.insert_diff_of_notMem] rw [Set.mem_singleton_iff] exact Ne.symm xa rw [h, sSup_union, sSup_singleton] apply (s_ind (hx.resolve_right xa)).disjoint_sup_right_of_disjoint_sup_left (a_dis_Sup_s.mono_right _).symm rw [← sSup_insert, Set.insert_diff_singleton, Set.insert_eq_of_mem (hx.resolve_right xa)] · rw [Set.mem_union, Set.mem_singleton_iff] at hx obtain hx | rfl := hx · exact s_atoms x hx · exact ha.symm /-- In an atomic lattice, every element `b` has a complement of the form `sSup s`, where each element of `s` is an atom. See also `complementedLattice_of_sSup_atoms_eq_top`. -/ theorem exists_sSupIndep_isCompl_sSup_atoms (h : sSup { a : α | IsAtom a } = ⊤) (b : α) : ∃ s : Set α, sSupIndep s ∧ IsCompl b (sSup s) ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a := by simpa [isCompl_iff, codisjoint_iff, and_assoc] using exists_sSupIndep_disjoint_sSup_atoms b ⊤ le_top <| by simpa using h theorem exists_sSupIndep_of_sSup_atoms (b : α) (h : sSup {a ≤ b | IsAtom a} = b) : ∃ s : Set α, sSupIndep s ∧ sSup s = b ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a := let ⟨s, s_ind, _, s_atoms⟩ := exists_sSupIndep_disjoint_sSup_atoms ⊥ b bot_le h ⟨s, s_ind, by simpa using s_atoms⟩ theorem exists_sSupIndep_of_sSup_atoms_eq_top (h : sSup {a : α | IsAtom a} = ⊤) : ∃ s : Set α, sSupIndep s ∧ sSup s = ⊤ ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a := exists_sSupIndep_of_sSup_atoms ⊤ (by simpa) /-- See [Theorem 6.6][calugareanu]. -/ theorem complementedLattice_of_sSup_atoms_eq_top (h : sSup { a : α | IsAtom a } = ⊤) : ComplementedLattice α where exists_isCompl b := let ⟨s, _, hcompl, _⟩ := exists_sSupIndep_isCompl_sSup_atoms (by simpa) b ⟨sSup s, hcompl⟩ /-- See [Theorem 6.6][calugareanu]. -/ theorem complementedLattice_of_isAtomistic [IsAtomistic α] : ComplementedLattice α := complementedLattice_of_sSup_atoms_eq_top sSup_atoms_eq_top theorem complementedLattice_iff_isAtomistic : ComplementedLattice α ↔ IsAtomistic α := by constructor <;> intros · exact isAtomistic_of_complementedLattice · exact complementedLattice_of_isAtomistic end
.lake/packages/mathlib/Mathlib/Order/CompactlyGenerated/Intervals.lean
import Mathlib.Order.CompleteLatticeIntervals import Mathlib.Order.CompactlyGenerated.Basic /-! # Results about compactness properties for intervals in complete lattices -/ variable {ι α : Type*} [CompleteLattice α] namespace Set.Iic theorem isCompactElement {a : α} {b : Iic a} (h : CompleteLattice.IsCompactElement (b : α)) : CompleteLattice.IsCompactElement b := by simp only [CompleteLattice.isCompactElement_iff, Finset.sup_eq_iSup] at h ⊢ intro ι s hb replace hb : (b : α) ≤ iSup ((↑) ∘ s) := le_trans hb <| (coe_iSup s) ▸ le_refl _ obtain ⟨t, ht⟩ := h ι ((↑) ∘ s) hb exact ⟨t, (by simpa using ht : (b : α) ≤ _)⟩ instance instIsCompactlyGenerated [IsCompactlyGenerated α] {a : α} : IsCompactlyGenerated (Iic a) := by refine ⟨fun ⟨x, (hx : x ≤ a)⟩ ↦ ?_⟩ obtain ⟨s, hs, rfl⟩ := IsCompactlyGenerated.exists_sSup_eq x rw [sSup_le_iff] at hx let f : s → Iic a := fun y ↦ ⟨y, hx _ y.property⟩ refine ⟨range f, ?_, ?_⟩ · rintro - ⟨⟨y, hy⟩, hy', rfl⟩ exact isCompactElement (hs _ hy) · rw [Subtype.ext_iff] change sSup (((↑) : Iic a → α) '' (range f)) = sSup s congr ext b simpa [f] using hx b end Set.Iic open Set (Iic) theorem complementedLattice_of_complementedLattice_Iic [IsModularLattice α] [IsCompactlyGenerated α] {s : Set ι} {f : ι → α} (h : ∀ i ∈ s, ComplementedLattice <| Iic (f i)) (h' : ⨆ i ∈ s, f i = ⊤) : ComplementedLattice α := by apply complementedLattice_of_sSup_atoms_eq_top have : ∀ i ∈ s, ∃ t : Set α, f i = sSup t ∧ ∀ a ∈ t, IsAtom a := fun i hi ↦ by replace h := complementedLattice_iff_isAtomistic.mp (h i hi) obtain ⟨u, hu, hu'⟩ := eq_sSup_atoms (⊤ : Iic (f i)) refine ⟨(↑) '' u, ?_, ?_⟩ · replace hu : f i = ↑(sSup u) := Subtype.ext_iff.mp hu simp_rw [hu, Iic.coe_sSup] · rintro b ⟨⟨a, ha'⟩, ha, rfl⟩ exact IsAtom.of_isAtom_coe_Iic (hu' _ ha) choose t ht ht' using this let u : Set α := ⋃ i, ⋃ hi : i ∈ s, t i hi have hu₁ : u ⊆ {a | IsAtom a} := by rintro a ⟨-, ⟨i, rfl⟩, ⟨-, ⟨hi, rfl⟩, ha : a ∈ t i hi⟩⟩ exact ht' i hi a ha have hu₂ : sSup u = ⨆ i ∈ s, f i := by simp_rw [u, sSup_iUnion, biSup_congr' ht] rw [eq_top_iff, ← h', ← hu₂] exact sSup_le_sSup hu₁
.lake/packages/mathlib/Mathlib/Order/Monotone/Odd.lean
import Mathlib.Algebra.Order.Group.Defs import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Order.Monotone.Union /-! # Monotonicity of odd functions An odd function on a linear ordered additive commutative group `G` is monotone on the whole group provided that it is monotone on `Set.Ici 0`, see `monotone_of_odd_of_monotoneOn_nonneg`. We also prove versions of this lemma for `Antitone`, `StrictMono`, and `StrictAnti`. -/ open Set variable {G H : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] [AddCommGroup H] [PartialOrder H] [IsOrderedAddMonoid H] /-- An odd function on a linear ordered additive commutative group is strictly monotone on the whole group provided that it is strictly monotone on `Set.Ici 0`. -/ theorem strictMono_of_odd_strictMonoOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x) (h₂ : StrictMonoOn f (Ici 0)) : StrictMono f := by refine StrictMonoOn.Iic_union_Ici (fun x hx y hy hxy => neg_lt_neg_iff.1 ?_) h₂ rw [← h₁, ← h₁] exact h₂ (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_lt_neg hxy) /-- An odd function on a linear ordered additive commutative group is strictly antitone on the whole group provided that it is strictly antitone on `Set.Ici 0`. -/ theorem strictAnti_of_odd_strictAntiOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x) (h₂ : StrictAntiOn f (Ici 0)) : StrictAnti f := strictMono_of_odd_strictMonoOn_nonneg (H := Hᵒᵈ) h₁ h₂ /-- An odd function on a linear ordered additive commutative group is monotone on the whole group provided that it is monotone on `Set.Ici 0`. -/ theorem monotone_of_odd_of_monotoneOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x) (h₂ : MonotoneOn f (Ici 0)) : Monotone f := by refine MonotoneOn.Iic_union_Ici (fun x hx y hy hxy => neg_le_neg_iff.1 ?_) h₂ rw [← h₁, ← h₁] exact h₂ (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_le_neg hxy) /-- An odd function on a linear ordered additive commutative group is antitone on the whole group provided that it is monotone on `Set.Ici 0`. -/ theorem antitone_of_odd_of_monotoneOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x) (h₂ : AntitoneOn f (Ici 0)) : Antitone f := monotone_of_odd_of_monotoneOn_nonneg (H := Hᵒᵈ) h₁ h₂
.lake/packages/mathlib/Mathlib/Order/Monotone/Monovary.lean
import Mathlib.Data.Set.Operations import Mathlib.Order.Lattice /-! # Monovariance of functions Two functions *vary together* if a strict change in the first implies a change in the second. This is in some sense a way to say that two functions `f : ι → α`, `g : ι → β` are "monotone together", without actually having an order on `ι`. This condition comes up in the rearrangement inequality. See `Algebra.Order.Rearrangement`. ## Main declarations * `Monovary f g`: `f` monovaries with `g`. If `g i < g j`, then `f i ≤ f j`. * `Antivary f g`: `f` antivaries with `g`. If `g i < g j`, then `f j ≤ f i`. * `MonovaryOn f g s`: `f` monovaries with `g` on `s`. * `AntivaryOn f g s`: `f` antivaries with `g` on `s`. -/ open Function Set variable {ι ι' α β γ : Type*} section Preorder variable [Preorder α] [Preorder β] [Preorder γ] {f : ι → α} {f' : α → γ} {g : ι → β} {s t : Set ι} /-- `f` monovaries with `g` if `g i < g j` implies `f i ≤ f j`. -/ def Monovary (f : ι → α) (g : ι → β) : Prop := ∀ ⦃i j⦄, g i < g j → f i ≤ f j /-- `f` antivaries with `g` if `g i < g j` implies `f j ≤ f i`. -/ def Antivary (f : ι → α) (g : ι → β) : Prop := ∀ ⦃i j⦄, g i < g j → f j ≤ f i /-- `f` monovaries with `g` on `s` if `g i < g j` implies `f i ≤ f j` for all `i, j ∈ s`. -/ def MonovaryOn (f : ι → α) (g : ι → β) (s : Set ι) : Prop := ∀ ⦃i⦄ (_ : i ∈ s) ⦃j⦄ (_ : j ∈ s), g i < g j → f i ≤ f j /-- `f` antivaries with `g` on `s` if `g i < g j` implies `f j ≤ f i` for all `i, j ∈ s`. -/ def AntivaryOn (f : ι → α) (g : ι → β) (s : Set ι) : Prop := ∀ ⦃i⦄ (_ : i ∈ s) ⦃j⦄ (_ : j ∈ s), g i < g j → f j ≤ f i protected theorem Monovary.monovaryOn (h : Monovary f g) (s : Set ι) : MonovaryOn f g s := fun _ _ _ _ hij => h hij protected theorem Antivary.antivaryOn (h : Antivary f g) (s : Set ι) : AntivaryOn f g s := fun _ _ _ _ hij => h hij @[simp] theorem MonovaryOn.empty : MonovaryOn f g ∅ := fun _ => False.elim @[simp] theorem AntivaryOn.empty : AntivaryOn f g ∅ := fun _ => False.elim @[simp] theorem monovaryOn_univ : MonovaryOn f g univ ↔ Monovary f g := ⟨fun h _ _ => h trivial trivial, fun h _ _ _ _ hij => h hij⟩ @[simp] theorem antivaryOn_univ : AntivaryOn f g univ ↔ Antivary f g := ⟨fun h _ _ => h trivial trivial, fun h _ _ _ _ hij => h hij⟩ lemma monovaryOn_iff_monovary : MonovaryOn f g s ↔ Monovary (fun i : s ↦ f i) fun i ↦ g i := by simp [Monovary, MonovaryOn] lemma antivaryOn_iff_antivary : AntivaryOn f g s ↔ Antivary (fun i : s ↦ f i) fun i ↦ g i := by simp [Antivary, AntivaryOn] protected theorem MonovaryOn.subset (hst : s ⊆ t) (h : MonovaryOn f g t) : MonovaryOn f g s := fun _ hi _ hj => h (hst hi) (hst hj) protected theorem AntivaryOn.subset (hst : s ⊆ t) (h : AntivaryOn f g t) : AntivaryOn f g s := fun _ hi _ hj => h (hst hi) (hst hj) theorem monovary_const_left (g : ι → β) (a : α) : Monovary (const ι a) g := fun _ _ _ => le_rfl theorem antivary_const_left (g : ι → β) (a : α) : Antivary (const ι a) g := fun _ _ _ => le_rfl theorem monovary_const_right (f : ι → α) (b : β) : Monovary f (const ι b) := fun _ _ h => (h.ne rfl).elim theorem antivary_const_right (f : ι → α) (b : β) : Antivary f (const ι b) := fun _ _ h => (h.ne rfl).elim theorem monovary_self (f : ι → α) : Monovary f f := fun _ _ => le_of_lt theorem monovaryOn_self (f : ι → α) (s : Set ι) : MonovaryOn f f s := fun _ _ _ _ => le_of_lt protected theorem Subsingleton.monovary [Subsingleton ι] (f : ι → α) (g : ι → β) : Monovary f g := fun _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim protected theorem Subsingleton.antivary [Subsingleton ι] (f : ι → α) (g : ι → β) : Antivary f g := fun _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim protected theorem Subsingleton.monovaryOn [Subsingleton ι] (f : ι → α) (g : ι → β) (s : Set ι) : MonovaryOn f g s := fun _ _ _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim protected theorem Subsingleton.antivaryOn [Subsingleton ι] (f : ι → α) (g : ι → β) (s : Set ι) : AntivaryOn f g s := fun _ _ _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim theorem monovaryOn_const_left (g : ι → β) (a : α) (s : Set ι) : MonovaryOn (const ι a) g s := fun _ _ _ _ _ => le_rfl theorem antivaryOn_const_left (g : ι → β) (a : α) (s : Set ι) : AntivaryOn (const ι a) g s := fun _ _ _ _ _ => le_rfl theorem monovaryOn_const_right (f : ι → α) (b : β) (s : Set ι) : MonovaryOn f (const ι b) s := fun _ _ _ _ h => (h.ne rfl).elim theorem antivaryOn_const_right (f : ι → α) (b : β) (s : Set ι) : AntivaryOn f (const ι b) s := fun _ _ _ _ h => (h.ne rfl).elim theorem Monovary.comp_right (h : Monovary f g) (k : ι' → ι) : Monovary (f ∘ k) (g ∘ k) := fun _ _ hij => h hij theorem Antivary.comp_right (h : Antivary f g) (k : ι' → ι) : Antivary (f ∘ k) (g ∘ k) := fun _ _ hij => h hij theorem MonovaryOn.comp_right (h : MonovaryOn f g s) (k : ι' → ι) : MonovaryOn (f ∘ k) (g ∘ k) (k ⁻¹' s) := fun _ hi _ hj => h hi hj theorem AntivaryOn.comp_right (h : AntivaryOn f g s) (k : ι' → ι) : AntivaryOn (f ∘ k) (g ∘ k) (k ⁻¹' s) := fun _ hi _ hj => h hi hj theorem Monovary.comp_monotone_left (h : Monovary f g) (hf : Monotone f') : Monovary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem Monovary.comp_antitone_left (h : Monovary f g) (hf : Antitone f') : Antivary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem Antivary.comp_monotone_left (h : Antivary f g) (hf : Monotone f') : Antivary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem Antivary.comp_antitone_left (h : Antivary f g) (hf : Antitone f') : Monovary (f' ∘ f) g := fun _ _ hij => hf <| h hij theorem MonovaryOn.comp_monotone_on_left (h : MonovaryOn f g s) (hf : Monotone f') : MonovaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij theorem MonovaryOn.comp_antitone_on_left (h : MonovaryOn f g s) (hf : Antitone f') : AntivaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij theorem AntivaryOn.comp_monotone_on_left (h : AntivaryOn f g s) (hf : Monotone f') : AntivaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij theorem AntivaryOn.comp_antitone_on_left (h : AntivaryOn f g s) (hf : Antitone f') : MonovaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij section OrderDual open OrderDual theorem Monovary.dual : Monovary f g → Monovary (toDual ∘ f) (toDual ∘ g) := swap theorem Antivary.dual : Antivary f g → Antivary (toDual ∘ f) (toDual ∘ g) := swap theorem Monovary.dual_left : Monovary f g → Antivary (toDual ∘ f) g := id theorem Antivary.dual_left : Antivary f g → Monovary (toDual ∘ f) g := id theorem Monovary.dual_right : Monovary f g → Antivary f (toDual ∘ g) := swap theorem Antivary.dual_right : Antivary f g → Monovary f (toDual ∘ g) := swap theorem MonovaryOn.dual : MonovaryOn f g s → MonovaryOn (toDual ∘ f) (toDual ∘ g) s := swap₂ theorem AntivaryOn.dual : AntivaryOn f g s → AntivaryOn (toDual ∘ f) (toDual ∘ g) s := swap₂ theorem MonovaryOn.dual_left : MonovaryOn f g s → AntivaryOn (toDual ∘ f) g s := id theorem AntivaryOn.dual_left : AntivaryOn f g s → MonovaryOn (toDual ∘ f) g s := id theorem MonovaryOn.dual_right : MonovaryOn f g s → AntivaryOn f (toDual ∘ g) s := swap₂ theorem AntivaryOn.dual_right : AntivaryOn f g s → MonovaryOn f (toDual ∘ g) s := swap₂ @[simp] theorem monovary_toDual_left : Monovary (toDual ∘ f) g ↔ Antivary f g := Iff.rfl @[simp] theorem monovary_toDual_right : Monovary f (toDual ∘ g) ↔ Antivary f g := forall_swap @[simp] theorem antivary_toDual_left : Antivary (toDual ∘ f) g ↔ Monovary f g := Iff.rfl @[simp] theorem antivary_toDual_right : Antivary f (toDual ∘ g) ↔ Monovary f g := forall_swap @[simp] theorem monovaryOn_toDual_left : MonovaryOn (toDual ∘ f) g s ↔ AntivaryOn f g s := Iff.rfl @[simp] theorem monovaryOn_toDual_right : MonovaryOn f (toDual ∘ g) s ↔ AntivaryOn f g s := forall₂_swap @[simp] theorem antivaryOn_toDual_left : AntivaryOn (toDual ∘ f) g s ↔ MonovaryOn f g s := Iff.rfl @[simp] theorem antivaryOn_toDual_right : AntivaryOn f (toDual ∘ g) s ↔ MonovaryOn f g s := forall₂_swap end OrderDual section PartialOrder variable [PartialOrder ι] @[simp] theorem monovary_id_iff : Monovary f id ↔ Monotone f := monotone_iff_forall_lt.symm @[simp] theorem antivary_id_iff : Antivary f id ↔ Antitone f := antitone_iff_forall_lt.symm @[simp] theorem monovaryOn_id_iff : MonovaryOn f id s ↔ MonotoneOn f s := monotoneOn_iff_forall_lt.symm @[simp] theorem antivaryOn_id_iff : AntivaryOn f id s ↔ AntitoneOn f s := antitoneOn_iff_forall_lt.symm lemma StrictMono.trans_monovary (hf : StrictMono f) (h : Monovary g f) : Monotone g := monotone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictMono.trans_antivary (hf : StrictMono f) (h : Antivary g f) : Antitone g := antitone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictAnti.trans_monovary (hf : StrictAnti f) (h : Monovary g f) : Antitone g := antitone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictAnti.trans_antivary (hf : StrictAnti f) (h : Antivary g f) : Monotone g := monotone_iff_forall_lt.2 fun _a _b hab ↦ h <| hf hab lemma StrictMonoOn.trans_monovaryOn (hf : StrictMonoOn f s) (h : MonovaryOn g f s) : MonotoneOn g s := monotoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h ha hb <| hf ha hb hab lemma StrictMonoOn.trans_antivaryOn (hf : StrictMonoOn f s) (h : AntivaryOn g f s) : AntitoneOn g s := antitoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h ha hb <| hf ha hb hab lemma StrictAntiOn.trans_monovaryOn (hf : StrictAntiOn f s) (h : MonovaryOn g f s) : AntitoneOn g s := antitoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h hb ha <| hf ha hb hab lemma StrictAntiOn.trans_antivaryOn (hf : StrictAntiOn f s) (h : AntivaryOn g f s) : MonotoneOn g s := monotoneOn_iff_forall_lt.2 fun _a ha _b hb hab ↦ h hb ha <| hf ha hb hab end PartialOrder variable [LinearOrder ι] protected theorem Monotone.monovary (hf : Monotone f) (hg : Monotone g) : Monovary f g := fun _ _ hij => hf (hg.reflect_lt hij).le protected theorem Monotone.antivary (hf : Monotone f) (hg : Antitone g) : Antivary f g := (hf.monovary hg.dual_right).dual_right protected theorem Antitone.monovary (hf : Antitone f) (hg : Antitone g) : Monovary f g := (hf.dual_right.antivary hg).dual_left protected theorem Antitone.antivary (hf : Antitone f) (hg : Monotone g) : Antivary f g := (hf.monovary hg.dual_right).dual_right protected theorem MonotoneOn.monovaryOn (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonovaryOn f g s := fun _ hi _ hj hij => hf hi hj (hg.reflect_lt hi hj hij).le protected theorem MonotoneOn.antivaryOn (hf : MonotoneOn f s) (hg : AntitoneOn g s) : AntivaryOn f g s := (hf.monovaryOn hg.dual_right).dual_right protected theorem AntitoneOn.monovaryOn (hf : AntitoneOn f s) (hg : AntitoneOn g s) : MonovaryOn f g s := (hf.dual_right.antivaryOn hg).dual_left protected theorem AntitoneOn.antivaryOn (hf : AntitoneOn f s) (hg : MonotoneOn g s) : AntivaryOn f g s := (hf.monovaryOn hg.dual_right).dual_right end Preorder section LinearOrder variable [Preorder α] [LinearOrder β] [Preorder γ] {f : ι → α} {g : ι → β} {g' : β → γ} {s : Set ι} theorem MonovaryOn.comp_monotoneOn_right (h : MonovaryOn f g s) (hg : MonotoneOn g' (g '' s)) : MonovaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hi hj <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij theorem MonovaryOn.comp_antitoneOn_right (h : MonovaryOn f g s) (hg : AntitoneOn g' (g '' s)) : AntivaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hj hi <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij theorem AntivaryOn.comp_monotoneOn_right (h : AntivaryOn f g s) (hg : MonotoneOn g' (g '' s)) : AntivaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hi hj <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij theorem AntivaryOn.comp_antitoneOn_right (h : AntivaryOn f g s) (hg : AntitoneOn g' (g '' s)) : MonovaryOn f (g' ∘ g) s := fun _ hi _ hj hij => h hj hi <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij @[symm] protected theorem Monovary.symm (h : Monovary f g) : Monovary g f := fun _ _ hf => le_of_not_gt fun hg => hf.not_ge <| h hg @[symm] protected theorem Antivary.symm (h : Antivary f g) : Antivary g f := fun _ _ hf => le_of_not_gt fun hg => hf.not_ge <| h hg @[symm] protected theorem MonovaryOn.symm (h : MonovaryOn f g s) : MonovaryOn g f s := fun _ hi _ hj hf => le_of_not_gt fun hg => hf.not_ge <| h hj hi hg @[symm] protected theorem AntivaryOn.symm (h : AntivaryOn f g s) : AntivaryOn g f s := fun _ hi _ hj hf => le_of_not_gt fun hg => hf.not_ge <| h hi hj hg end LinearOrder section LinearOrder variable [LinearOrder α] [LinearOrder β] {f : ι → α} {g : ι → β} {s : Set ι} theorem monovary_comm : Monovary f g ↔ Monovary g f := ⟨Monovary.symm, Monovary.symm⟩ theorem antivary_comm : Antivary f g ↔ Antivary g f := ⟨Antivary.symm, Antivary.symm⟩ theorem monovaryOn_comm : MonovaryOn f g s ↔ MonovaryOn g f s := ⟨MonovaryOn.symm, MonovaryOn.symm⟩ theorem antivaryOn_comm : AntivaryOn f g s ↔ AntivaryOn g f s := ⟨AntivaryOn.symm, AntivaryOn.symm⟩ end LinearOrder
.lake/packages/mathlib/Mathlib/Order/Monotone/Union.lean
import Mathlib.Order.Bounds.Basic import Mathlib.Order.Interval.Set.LinearOrder /-! # Monotonicity on intervals In this file we prove that a function is (strictly) monotone (or antitone) on a linear order `α` provided that it is (strictly) monotone on `(-∞, a]` and on `[a, +∞)`. This is a special case of a more general statement where one deduces monotonicity on a union from monotonicity on each set. -/ open Set variable {α β : Type*} [LinearOrder α] [Preorder β] {a : α} {f : α → β} /-- If `f` is strictly monotone both on `s` and `t`, with `s` to the left of `t` and the center point belonging to both `s` and `t`, then `f` is strictly monotone on `s ∪ t` -/ protected theorem StrictMonoOn.union {s t : Set α} {c : α} (h₁ : StrictMonoOn f s) (h₂ : StrictMonoOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : StrictMonoOn f (s ∪ t) := by have A : ∀ x, x ∈ s ∪ t → x ≤ c → x ∈ s := by intro x hx hxc cases hx · assumption rcases eq_or_lt_of_le hxc with (rfl | h'x) · exact hs.1 exact (lt_irrefl _ (h'x.trans_le (ht.2 (by assumption)))).elim have B : ∀ x, x ∈ s ∪ t → c ≤ x → x ∈ t := by intro x hx hxc match hx with | Or.inr hx => exact hx | Or.inl hx => rcases eq_or_lt_of_le hxc with (rfl | h'x) · exact ht.1 exact (lt_irrefl _ (h'x.trans_le (hs.2 hx))).elim intro x hx y hy hxy rcases lt_or_ge x c with (hxc | hcx) · have xs : x ∈ s := A _ hx hxc.le rcases lt_or_ge y c with (hyc | hcy) · exact h₁ xs (A _ hy hyc.le) hxy · exact (h₁ xs hs.1 hxc).trans_le (h₂.monotoneOn ht.1 (B _ hy hcy) hcy) · have xt : x ∈ t := B _ hx hcx have yt : y ∈ t := B _ hy (hcx.trans hxy.le) exact h₂ xt yt hxy /-- If `f` is strictly monotone both on `(-∞, a]` and `[a, ∞)`, then it is strictly monotone on the whole line. -/ protected theorem StrictMonoOn.Iic_union_Ici (h₁ : StrictMonoOn f (Iic a)) (h₂ : StrictMonoOn f (Ici a)) : StrictMono f := by rw [← strictMonoOn_univ, ← @Iic_union_Ici _ _ a] exact StrictMonoOn.union h₁ h₂ isGreatest_Iic isLeast_Ici /-- If `f` is strictly antitone both on `s` and `t`, with `s` to the left of `t` and the center point belonging to both `s` and `t`, then `f` is strictly antitone on `s ∪ t` -/ protected theorem StrictAntiOn.union {s t : Set α} {c : α} (h₁ : StrictAntiOn f s) (h₂ : StrictAntiOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : StrictAntiOn f (s ∪ t) := (h₁.dual_right.union h₂.dual_right hs ht).dual_right /-- If `f` is strictly antitone both on `(-∞, a]` and `[a, ∞)`, then it is strictly antitone on the whole line. -/ protected theorem StrictAntiOn.Iic_union_Ici (h₁ : StrictAntiOn f (Iic a)) (h₂ : StrictAntiOn f (Ici a)) : StrictAnti f := (h₁.dual_right.Iic_union_Ici h₂.dual_right).dual_right /-- If `f` is monotone both on `s` and `t`, with `s` to the left of `t` and the center point belonging to both `s` and `t`, then `f` is monotone on `s ∪ t` -/ protected theorem MonotoneOn.union_right {s t : Set α} {c : α} (h₁ : MonotoneOn f s) (h₂ : MonotoneOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : MonotoneOn f (s ∪ t) := by have A : ∀ x, x ∈ s ∪ t → x ≤ c → x ∈ s := by intro x hx hxc cases hx · assumption rcases eq_or_lt_of_le hxc with (rfl | h'x) · exact hs.1 exact (lt_irrefl _ (h'x.trans_le (ht.2 (by assumption)))).elim have B : ∀ x, x ∈ s ∪ t → c ≤ x → x ∈ t := by intro x hx hxc match hx with | Or.inr hx => exact hx | Or.inl hx => rcases eq_or_lt_of_le hxc with (rfl | h'x) · exact ht.1 exact (lt_irrefl _ (h'x.trans_le (hs.2 hx))).elim intro x hx y hy hxy rcases lt_or_ge x c with (hxc | hcx) · have xs : x ∈ s := A _ hx hxc.le rcases lt_or_ge y c with (hyc | hcy) · exact h₁ xs (A _ hy hyc.le) hxy · exact (h₁ xs hs.1 hxc.le).trans (h₂ ht.1 (B _ hy hcy) hcy) · have xt : x ∈ t := B _ hx hcx have yt : y ∈ t := B _ hy (hcx.trans hxy) exact h₂ xt yt hxy /-- If `f` is monotone both on `(-∞, a]` and `[a, ∞)`, then it is monotone on the whole line. -/ protected theorem MonotoneOn.Iic_union_Ici (h₁ : MonotoneOn f (Iic a)) (h₂ : MonotoneOn f (Ici a)) : Monotone f := by rw [← monotoneOn_univ, ← @Iic_union_Ici _ _ a] exact MonotoneOn.union_right h₁ h₂ isGreatest_Iic isLeast_Ici /-- If `f` is antitone both on `s` and `t`, with `s` to the left of `t` and the center point belonging to both `s` and `t`, then `f` is antitone on `s ∪ t` -/ protected theorem AntitoneOn.union_right {s t : Set α} {c : α} (h₁ : AntitoneOn f s) (h₂ : AntitoneOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : AntitoneOn f (s ∪ t) := (h₁.dual_right.union_right h₂.dual_right hs ht).dual_right /-- If `f` is antitone both on `(-∞, a]` and `[a, ∞)`, then it is antitone on the whole line. -/ protected theorem AntitoneOn.Iic_union_Ici (h₁ : AntitoneOn f (Iic a)) (h₂ : AntitoneOn f (Ici a)) : Antitone f := (h₁.dual_right.Iic_union_Ici h₂.dual_right).dual_right
.lake/packages/mathlib/Mathlib/Order/Monotone/Extension.lean
import Mathlib.Data.Set.Monotone import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # Extension of a monotone function from a set to the whole space In this file we prove that if a function is monotone and is bounded on a set `s`, then it admits a monotone extension to the whole space. -/ open Set variable {α β : Type*} [LinearOrder α] [ConditionallyCompleteLinearOrder β] {f : α → β} {s : Set α} /-- If a function is monotone and is bounded on a set `s`, then it admits a monotone extension to the whole space. -/ theorem MonotoneOn.exists_monotone_extension (h : MonotoneOn f s) (hl : BddBelow (f '' s)) (hu : BddAbove (f '' s)) : ∃ g : α → β, Monotone g ∧ EqOn f g s := by classical /- The extension is defined by `f x = f a` for `x ≤ a`, and `f x` is the supremum of the values of `f` to the left of `x` for `x ≥ a`. -/ rcases hl with ⟨a, ha⟩ have hu' : ∀ x, BddAbove (f '' (Iic x ∩ s)) := fun x => hu.mono (image_mono inter_subset_right) let g : α → β := fun x => if Disjoint (Iic x) s then a else sSup (f '' (Iic x ∩ s)) have hgs : EqOn f g s := by intro x hx simp only [g] have : IsGreatest (Iic x ∩ s) x := ⟨⟨right_mem_Iic, hx⟩, fun y hy => hy.1⟩ rw [if_neg this.nonempty.not_disjoint, ((h.mono inter_subset_right).map_isGreatest this).csSup_eq] refine ⟨g, fun x y hxy => ?_, hgs⟩ by_cases hx : Disjoint (Iic x) s <;> by_cases hy : Disjoint (Iic y) s <;> simp only [g, if_pos, if_neg, not_false_iff, *, refl] · rcases not_disjoint_iff_nonempty_inter.1 hy with ⟨z, hz⟩ exact le_csSup_of_le (hu' _) (mem_image_of_mem _ hz) (ha <| mem_image_of_mem _ hz.2) · exact (hx <| hy.mono_left <| Iic_subset_Iic.2 hxy).elim · rw [not_disjoint_iff_nonempty_inter] at hx gcongr; exacts [hu' _, hx.image _] /-- If a function is antitone and is bounded on a set `s`, then it admits an antitone extension to the whole space. -/ theorem AntitoneOn.exists_antitone_extension (h : AntitoneOn f s) (hl : BddBelow (f '' s)) (hu : BddAbove (f '' s)) : ∃ g : α → β, Antitone g ∧ EqOn f g s := h.dual_right.exists_monotone_extension hu hl
.lake/packages/mathlib/Mathlib/Order/Monotone/Basic.lean
import Mathlib.Data.Nat.Basic import Mathlib.Data.Int.Order.Basic import Mathlib.Logic.Function.Iterate import Mathlib.Order.Compare import Mathlib.Order.Max import Mathlib.Order.Monotone.Defs import Mathlib.Order.RelClasses import Mathlib.Tactic.Choose import Mathlib.Tactic.Contrapose /-! # Monotonicity This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage, "monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti" to mean "decreasing". ## Main theorems * `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : ℕ → α` or `f : ℤ → α` and `f n ≤ f (n + 1)` for all `n`, then `f` is monotone. * `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : ℕ → α` or `f : ℤ → α` and `f (n + 1) ≤ f n` for all `n`, then `f` is antitone. * `strictMono_nat_of_lt_succ`, `strictMono_int_of_lt_succ`: If `f : ℕ → α` or `f : ℤ → α` and `f n < f (n + 1)` for all `n`, then `f` is strictly monotone. * `strictAnti_nat_of_succ_lt`, `strictAnti_int_of_succ_lt`: If `f : ℕ → α` or `f : ℤ → α` and `f (n + 1) < f n` for all `n`, then `f` is strictly antitone. ## Implementation notes Some of these definitions used to only require `LE α` or `LT α`. The advantage of this is unclear and it led to slight elaboration issues. Now, everything requires `Preorder α` and seems to work fine. Related Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352. ## TODO The above theorems are also true in `ℕ+`, `Fin n`... To make that work, we need `SuccOrder α` and `IsSuccArchimedean α`. ## Tags monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing, decreasing, strictly decreasing -/ open Function OrderDual universe u v variable {ι : Type*} {α : Type u} {β : Type v} /-! ### Monotonicity on the dual order Strictly, many of the `*On.dual` lemmas in this section should use `ofDual ⁻¹' s` instead of `s`, but right now this is not possible as `Set.preimage` is not defined yet, and importing it creates an import cycle. Often, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`, `.dual_left` or `.dual_right` to your `Monotone`/`Antitone` hypothesis. -/ section OrderDual variable [Preorder α] [Preorder β] {f : α → β} {s : Set α} @[simp] theorem monotone_comp_ofDual_iff : Monotone (f ∘ ofDual) ↔ Antitone f := forall_swap @[simp] theorem antitone_comp_ofDual_iff : Antitone (f ∘ ofDual) ↔ Monotone f := forall_swap @[simp] theorem monotone_toDual_comp_iff : Monotone (toDual ∘ f) ↔ Antitone f := Iff.rfl @[simp] theorem antitone_toDual_comp_iff : Antitone (toDual ∘ f) ↔ Monotone f := Iff.rfl @[simp] theorem monotoneOn_comp_ofDual_iff : MonotoneOn (f ∘ ofDual) s ↔ AntitoneOn f s := forall₂_swap @[simp] theorem antitoneOn_comp_ofDual_iff : AntitoneOn (f ∘ ofDual) s ↔ MonotoneOn f s := forall₂_swap @[simp] theorem monotoneOn_toDual_comp_iff : MonotoneOn (toDual ∘ f) s ↔ AntitoneOn f s := Iff.rfl @[simp] theorem antitoneOn_toDual_comp_iff : AntitoneOn (toDual ∘ f) s ↔ MonotoneOn f s := Iff.rfl @[simp] theorem strictMono_comp_ofDual_iff : StrictMono (f ∘ ofDual) ↔ StrictAnti f := forall_swap @[simp] theorem strictAnti_comp_ofDual_iff : StrictAnti (f ∘ ofDual) ↔ StrictMono f := forall_swap @[simp] theorem strictMono_toDual_comp_iff : StrictMono (toDual ∘ f : α → βᵒᵈ) ↔ StrictAnti f := Iff.rfl @[simp] theorem strictAnti_toDual_comp_iff : StrictAnti (toDual ∘ f : α → βᵒᵈ) ↔ StrictMono f := Iff.rfl @[simp] theorem strictMonoOn_comp_ofDual_iff : StrictMonoOn (f ∘ ofDual) s ↔ StrictAntiOn f s := forall₂_swap @[simp] theorem strictAntiOn_comp_ofDual_iff : StrictAntiOn (f ∘ ofDual) s ↔ StrictMonoOn f s := forall₂_swap @[simp] theorem strictMonoOn_toDual_comp_iff : StrictMonoOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictAntiOn f s := Iff.rfl @[simp] theorem strictAntiOn_toDual_comp_iff : StrictAntiOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictMonoOn f s := Iff.rfl theorem monotone_dual_iff : Monotone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Monotone f := by rw [monotone_toDual_comp_iff, antitone_comp_ofDual_iff] theorem antitone_dual_iff : Antitone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Antitone f := by rw [antitone_toDual_comp_iff, monotone_comp_ofDual_iff] theorem monotoneOn_dual_iff : MonotoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ MonotoneOn f s := by rw [monotoneOn_toDual_comp_iff, antitoneOn_comp_ofDual_iff] theorem antitoneOn_dual_iff : AntitoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ AntitoneOn f s := by rw [antitoneOn_toDual_comp_iff, monotoneOn_comp_ofDual_iff] theorem strictMono_dual_iff : StrictMono (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictMono f := by rw [strictMono_toDual_comp_iff, strictAnti_comp_ofDual_iff] theorem strictAnti_dual_iff : StrictAnti (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictAnti f := by rw [strictAnti_toDual_comp_iff, strictMono_comp_ofDual_iff] theorem strictMonoOn_dual_iff : StrictMonoOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictMonoOn f s := by rw [strictMonoOn_toDual_comp_iff, strictAntiOn_comp_ofDual_iff] theorem strictAntiOn_dual_iff : StrictAntiOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictAntiOn f s := by rw [strictAntiOn_toDual_comp_iff, strictMonoOn_comp_ofDual_iff] alias ⟨_, Monotone.dual_left⟩ := antitone_comp_ofDual_iff alias ⟨_, Antitone.dual_left⟩ := monotone_comp_ofDual_iff alias ⟨_, Monotone.dual_right⟩ := antitone_toDual_comp_iff alias ⟨_, Antitone.dual_right⟩ := monotone_toDual_comp_iff alias ⟨_, MonotoneOn.dual_left⟩ := antitoneOn_comp_ofDual_iff alias ⟨_, AntitoneOn.dual_left⟩ := monotoneOn_comp_ofDual_iff alias ⟨_, MonotoneOn.dual_right⟩ := antitoneOn_toDual_comp_iff alias ⟨_, AntitoneOn.dual_right⟩ := monotoneOn_toDual_comp_iff alias ⟨_, StrictMono.dual_left⟩ := strictAnti_comp_ofDual_iff alias ⟨_, StrictAnti.dual_left⟩ := strictMono_comp_ofDual_iff alias ⟨_, StrictMono.dual_right⟩ := strictAnti_toDual_comp_iff alias ⟨_, StrictAnti.dual_right⟩ := strictMono_toDual_comp_iff alias ⟨_, StrictMonoOn.dual_left⟩ := strictAntiOn_comp_ofDual_iff alias ⟨_, StrictAntiOn.dual_left⟩ := strictMonoOn_comp_ofDual_iff alias ⟨_, StrictMonoOn.dual_right⟩ := strictAntiOn_toDual_comp_iff alias ⟨_, StrictAntiOn.dual_right⟩ := strictMonoOn_toDual_comp_iff alias ⟨_, Monotone.dual⟩ := monotone_dual_iff alias ⟨_, Antitone.dual⟩ := antitone_dual_iff alias ⟨_, MonotoneOn.dual⟩ := monotoneOn_dual_iff alias ⟨_, AntitoneOn.dual⟩ := antitoneOn_dual_iff alias ⟨_, StrictMono.dual⟩ := strictMono_dual_iff alias ⟨_, StrictAnti.dual⟩ := strictAnti_dual_iff alias ⟨_, StrictMonoOn.dual⟩ := strictMonoOn_dual_iff alias ⟨_, StrictAntiOn.dual⟩ := strictAntiOn_dual_iff end OrderDual section WellFounded variable [Preorder α] [Preorder β] {f : α → β} theorem StrictMono.wellFoundedLT [WellFoundedLT β] (hf : StrictMono f) : WellFoundedLT α := Subrelation.isWellFounded (InvImage (· < ·) f) @hf theorem StrictAnti.wellFoundedLT [WellFoundedGT β] (hf : StrictAnti f) : WellFoundedLT α := StrictMono.wellFoundedLT (β := βᵒᵈ) hf theorem StrictMono.wellFoundedGT [WellFoundedGT β] (hf : StrictMono f) : WellFoundedGT α := StrictMono.wellFoundedLT (α := αᵒᵈ) (β := βᵒᵈ) (fun _ _ h ↦ hf h) theorem StrictAnti.wellFoundedGT [WellFoundedLT β] (hf : StrictAnti f) : WellFoundedGT α := StrictMono.wellFoundedLT (α := αᵒᵈ) (fun _ _ h ↦ hf h) end WellFounded /-! ### Miscellaneous monotonicity results -/ section Preorder variable [Preorder α] [Preorder β] {f g : α → β} {a : α} theorem StrictMono.isMax_of_apply (hf : StrictMono f) (ha : IsMax (f a)) : IsMax a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMax_iff.1 h (hf hb).not_isMax ha theorem StrictMono.isMin_of_apply (hf : StrictMono f) (ha : IsMin (f a)) : IsMin a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMin_iff.1 h (hf hb).not_isMin ha theorem StrictAnti.isMax_of_apply (hf : StrictAnti f) (ha : IsMin (f a)) : IsMax a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMax_iff.1 h (hf hb).not_isMin ha theorem StrictAnti.isMin_of_apply (hf : StrictAnti f) (ha : IsMax (f a)) : IsMin a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMin_iff.1 h (hf hb).not_isMax ha lemma StrictMono.add_le_nat {f : ℕ → ℕ} (hf : StrictMono f) (m n : ℕ) : m + f n ≤ f (m + n) := by rw [Nat.add_comm m, Nat.add_comm m] induction m with | zero => rw [Nat.add_zero, Nat.add_zero] | succ m ih => rw [← Nat.add_assoc, ← Nat.add_assoc, Nat.succ_le] exact ih.trans_lt (hf (n + m).lt_succ_self) protected theorem StrictMono.ite' (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → f x < g y) : StrictMono fun x ↦ if p x then f x else g x := by intro x y h by_cases hy : p y · have hx : p x := hp h hy simpa [hx, hy] using hf h by_cases hx : p x · simpa [hx, hy] using hfg hx hy h · simpa [hx, hy] using hg h protected theorem StrictMono.ite (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, f x ≤ g x) : StrictMono fun x ↦ if p x then f x else g x := (hf.ite' hg hp) fun _ y _ _ h ↦ (hf h).trans_le (hfg y) protected theorem StrictAnti.ite' (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → g y < f x) : StrictAnti fun x ↦ if p x then f x else g x := StrictMono.ite' hf.dual_right hg.dual_right hp hfg protected theorem StrictAnti.ite (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, g x ≤ f x) : StrictAnti fun x ↦ if p x then f x else g x := (hf.ite' hg hp) fun _ y _ _ h ↦ (hfg y).trans_lt (hf h) end Preorder namespace List section Fold theorem foldl_monotone [Preorder α] {f : α → β → α} (H : ∀ b, Monotone fun a ↦ f a b) (l : List β) : Monotone fun a ↦ l.foldl f a := List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h) theorem foldr_monotone [Preorder β] {f : α → β → β} (H : ∀ a, Monotone (f a)) (l : List α) : Monotone fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl theorem foldl_strictMono [Preorder α] {f : α → β → α} (H : ∀ b, StrictMono fun a ↦ f a b) (l : List β) : StrictMono fun a ↦ l.foldl f a := List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h) theorem foldr_strictMono [Preorder β] {f : α → β → β} (H : ∀ a, StrictMono (f a)) (l : List α) : StrictMono fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl end Fold end List /-! ### Monotonicity in linear orders -/ section LinearOrder variable [LinearOrder α] section Preorder variable [Preorder β] {f : α → β} {s : Set α} open Ordering theorem StrictMonoOn.le_iff_le (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a ≤ f b ↔ a ≤ b := ⟨fun h ↦ le_of_not_gt fun h' ↦ (hf hb ha h').not_ge h, fun h ↦ h.lt_or_eq_dec.elim (fun h' ↦ (hf ha hb h').le) fun h' ↦ h' ▸ le_rfl⟩ theorem StrictAntiOn.le_iff_ge (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a ≤ f b ↔ b ≤ a := hf.dual_right.le_iff_le hb ha @[deprecated (since := "2025-08-12")] alias StrictAntiOn.le_iff_le := StrictAntiOn.le_iff_ge theorem StrictMonoOn.eq_iff_eq (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a = f b ↔ a = b := ⟨fun h ↦ le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge), by rintro rfl rfl⟩ theorem StrictAntiOn.eq_iff_eq (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a = f b ↔ b = a := (hf.dual_right.eq_iff_eq ha hb).trans eq_comm theorem StrictMonoOn.lt_iff_lt (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a < f b ↔ a < b := by rw [lt_iff_le_not_ge, lt_iff_le_not_ge, hf.le_iff_le ha hb, hf.le_iff_le hb ha] theorem StrictAntiOn.lt_iff_gt (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a < f b ↔ b < a := hf.dual_right.lt_iff_lt hb ha @[deprecated (since := "2025-08-12")] alias StrictAntiOn.lt_iff_lt := StrictAntiOn.lt_iff_gt theorem StrictMono.le_iff_le (hf : StrictMono f) {a b : α} : f a ≤ f b ↔ a ≤ b := (hf.strictMonoOn Set.univ).le_iff_le trivial trivial theorem StrictAnti.le_iff_ge (hf : StrictAnti f) {a b : α} : f a ≤ f b ↔ b ≤ a := (hf.strictAntiOn Set.univ).le_iff_ge trivial trivial @[deprecated (since := "2025-08-12")] alias StrictAnti.le_iff_le := StrictAnti.le_iff_ge theorem StrictMono.lt_iff_lt (hf : StrictMono f) {a b : α} : f a < f b ↔ a < b := (hf.strictMonoOn Set.univ).lt_iff_lt trivial trivial theorem StrictAnti.lt_iff_gt (hf : StrictAnti f) {a b : α} : f a < f b ↔ b < a := (hf.strictAntiOn Set.univ).lt_iff_gt trivial trivial @[deprecated (since := "2025-08-12")] alias StrictAnti.lt_iff_lt := StrictAnti.lt_iff_gt protected theorem StrictMonoOn.compares (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : ∀ {o : Ordering}, o.Compares (f a) (f b) ↔ o.Compares a b | Ordering.lt => hf.lt_iff_lt ha hb | Ordering.eq => ⟨fun h ↦ ((hf.le_iff_le ha hb).1 h.le).antisymm ((hf.le_iff_le hb ha).1 h.symm.le), congr_arg _⟩ | Ordering.gt => hf.lt_iff_lt hb ha protected theorem StrictAntiOn.compares (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a := toDual_compares_toDual.trans <| hf.dual_right.compares hb ha protected theorem StrictMono.compares (hf : StrictMono f) {a b : α} {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares a b := (hf.strictMonoOn Set.univ).compares trivial trivial protected theorem StrictAnti.compares (hf : StrictAnti f) {a b : α} {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a := (hf.strictAntiOn Set.univ).compares trivial trivial theorem StrictMono.injective (hf : StrictMono f) : Injective f := fun x y h ↦ show Compares eq x y from hf.compares.1 h theorem StrictAnti.injective (hf : StrictAnti f) : Injective f := fun x y h ↦ show Compares eq x y from hf.compares.1 h.symm lemma StrictMonoOn.injOn (hf : StrictMonoOn f s) : s.InjOn f := fun x hx y hy hxy ↦ show Ordering.eq.Compares x y from (hf.compares hx hy).1 hxy lemma StrictAntiOn.injOn (hf : StrictAntiOn f s) : s.InjOn f := hf.dual_left.injOn theorem StrictMono.maximal_of_maximal_image (hf : StrictMono f) {a} (hmax : ∀ p, p ≤ f a) (x : α) : x ≤ a := hf.le_iff_le.mp (hmax (f x)) theorem StrictMono.minimal_of_minimal_image (hf : StrictMono f) {a} (hmin : ∀ p, f a ≤ p) (x : α) : a ≤ x := hf.le_iff_le.mp (hmin (f x)) theorem StrictAnti.minimal_of_maximal_image (hf : StrictAnti f) {a} (hmax : ∀ p, p ≤ f a) (x : α) : a ≤ x := hf.le_iff_ge.mp (hmax (f x)) theorem StrictAnti.maximal_of_minimal_image (hf : StrictAnti f) {a} (hmin : ∀ p, f a ≤ p) (x : α) : x ≤ a := hf.le_iff_ge.mp (hmin (f x)) end Preorder section PartialOrder variable [PartialOrder β] {f : α → β} theorem Monotone.strictMono_iff_injective (hf : Monotone f) : StrictMono f ↔ Injective f := ⟨fun h ↦ h.injective, hf.strictMono_of_injective⟩ theorem Antitone.strictAnti_iff_injective (hf : Antitone f) : StrictAnti f ↔ Injective f := ⟨fun h ↦ h.injective, hf.strictAnti_of_injective⟩ /-- If a monotone function is equal at two points, it is equal between all of them -/ theorem Monotone.eq_of_ge_of_le {a₁ a₂ : α} (h_mon : Monotone f) (h_fa : f a₁ = f a₂) {i : α} (h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by apply le_antisymm · rw [h_fa]; exact h_mon h₂ · exact h_mon h₁ @[deprecated (since := "2025-07-18")] alias Monotone.eq_of_le_of_le := Monotone.eq_of_ge_of_le /-- If an antitone function is equal at two points, it is equal between all of them -/ theorem Antitone.eq_of_ge_of_le {a₁ a₂ : α} (h_anti : Antitone f) (h_fa : f a₁ = f a₂) {i : α} (h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by apply le_antisymm · exact h_anti h₁ · rw [h_fa]; exact h_anti h₂ @[deprecated (since := "2025-07-18")] alias Antitone.eq_of_le_of_le := Antitone.eq_of_ge_of_le end PartialOrder variable [LinearOrder β] {f : α → β} {s : Set α} {x y : α} /-- A function between linear orders which is neither monotone nor antitone makes a dent upright or downright. -/ lemma not_monotone_not_antitone_iff_exists_le_le : ¬ Monotone f ∧ ¬ Antitone f ↔ ∃ a b c, a ≤ b ∧ b ≤ c ∧ ((f a < f b ∧ f c < f b) ∨ (f b < f a ∧ f b < f c)) := by simp_rw [Monotone, Antitone, not_forall, not_le] refine Iff.symm ⟨?_, ?_⟩ · rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩ exacts [⟨⟨_, _, hbc, hfcb⟩, _, _, hab, hfab⟩, ⟨⟨_, _, hab, hfba⟩, _, _, hbc, hfbc⟩] rintro ⟨⟨a, b, hab, hfba⟩, c, d, hcd, hfcd⟩ obtain hda | had := le_total d a · obtain hfad | hfda := le_total (f a) (f d) · exact ⟨c, d, b, hcd, hda.trans hab, Or.inl ⟨hfcd, hfba.trans_le hfad⟩⟩ · exact ⟨c, a, b, hcd.trans hda, hab, Or.inl ⟨hfcd.trans_le hfda, hfba⟩⟩ obtain hac | hca := le_total a c · obtain hfdb | hfbd := le_or_gt (f d) (f b) · exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfcd.trans <| hfdb.trans_lt hfba, hfcd⟩⟩ obtain hfca | hfac := lt_or_ge (f c) (f a) · exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfca, hfcd⟩⟩ obtain hbd | hdb := le_total b d · exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩ · exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩ · obtain hfdb | hfbd := le_or_gt (f d) (f b) · exact ⟨c, a, b, hca, hab, Or.inl ⟨hfcd.trans <| hfdb.trans_lt hfba, hfba⟩⟩ obtain hfca | hfac := lt_or_ge (f c) (f a) · exact ⟨c, a, b, hca, hab, Or.inl ⟨hfca, hfba⟩⟩ obtain hbd | hdb := le_total b d · exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩ · exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩ /-- A function between linear orders which is neither monotone nor antitone makes a dent upright or downright. -/ lemma not_monotone_not_antitone_iff_exists_lt_lt : ¬ Monotone f ∧ ¬ Antitone f ↔ ∃ a b c, a < b ∧ b < c ∧ (f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by simp_rw [not_monotone_not_antitone_iff_exists_le_le, ← and_assoc] refine exists₃_congr (fun a b c ↦ and_congr_left <| fun h ↦ (Ne.le_iff_lt ?_).and <| Ne.le_iff_lt ?_) <;> (rintro rfl; simp at h) /-! ### Strictly monotone functions and `cmp` -/ theorem StrictMonoOn.cmp_map_eq (hf : StrictMonoOn f s) (hx : x ∈ s) (hy : y ∈ s) : cmp (f x) (f y) = cmp x y := ((hf.compares hx hy).2 (cmp_compares x y)).cmp_eq theorem StrictMono.cmp_map_eq (hf : StrictMono f) (x y : α) : cmp (f x) (f y) = cmp x y := (hf.strictMonoOn Set.univ).cmp_map_eq trivial trivial theorem StrictAntiOn.cmp_map_eq (hf : StrictAntiOn f s) (hx : x ∈ s) (hy : y ∈ s) : cmp (f x) (f y) = cmp y x := hf.dual_right.cmp_map_eq hy hx theorem StrictAnti.cmp_map_eq (hf : StrictAnti f) (x y : α) : cmp (f x) (f y) = cmp y x := (hf.strictAntiOn Set.univ).cmp_map_eq trivial trivial end LinearOrder /-! ### Monotonicity in `ℕ` and `ℤ` -/ section Preorder variable [Preorder α] theorem Nat.rel_of_forall_rel_succ_of_le_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b < c) : r (f b) (f c) := by induction hbc with | refl => exact h _ hab | step b_lt_k r_b_k => exact _root_.trans r_b_k (h _ (hab.trans_lt b_lt_k).le) theorem Nat.rel_of_forall_rel_succ_of_le_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b ≤ c) : r (f b) (f c) := hbc.eq_or_lt.elim (fun h ↦ h ▸ refl _) (Nat.rel_of_forall_rel_succ_of_le_of_lt r h hab) theorem Nat.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a < b) : r (f a) (f b) := Nat.rel_of_forall_rel_succ_of_le_of_lt r (fun n _ ↦ h n) le_rfl hab theorem Nat.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℕ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a ≤ b) : r (f a) (f b) := Nat.rel_of_forall_rel_succ_of_le_of_le r (fun n _ ↦ h n) le_rfl hab theorem monotone_nat_of_le_succ {f : ℕ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f := Nat.rel_of_forall_rel_succ_of_le (· ≤ ·) hf theorem monotone_add_nat_of_le_succ {f : ℕ → α} {k : ℕ} (hf : ∀ n ≥ k, f n ≤ f (n + 1)) : Monotone (fun n ↦ f (n + k)) := fun _ _ hle ↦ Nat.rel_of_forall_rel_succ_of_le_of_le (· ≤ ·) hf (Nat.le_add_left k _) (Nat.add_le_add_iff_right.mpr hle) -- TODO replace `{ x | k ≤ x }` with `Set.Ici k` theorem monotoneOn_nat_Ici_of_le_succ {f : ℕ → α} {k : ℕ} (hf : ∀ n ≥ k, f n ≤ f (n + 1)) : MonotoneOn f { x | k ≤ x } := fun _ hab _ _ hle ↦ Nat.rel_of_forall_rel_succ_of_le_of_le (· ≤ ·) hf hab hle -- TODO replace `{ x | k ≤ x }` with `Set.Ici k` theorem monotone_add_nat_iff_monotoneOn_nat_Ici {f : ℕ → α} {k : ℕ} : Monotone (fun n ↦ f (n + k)) ↔ MonotoneOn f { x | k ≤ x } := by refine ⟨fun h x hx y hy hle ↦ ?_, fun h x y hle ↦ ?_⟩ · rw [← Nat.sub_add_cancel hx, ← Nat.sub_add_cancel hy] rw [← Nat.sub_le_sub_iff_right hy] at hle exact h hle · rw [← Nat.add_le_add_iff_right] at hle exact h (Nat.le_add_left k x) (Nat.le_add_left k y) hle theorem antitone_nat_of_succ_le {f : ℕ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f := @monotone_nat_of_le_succ αᵒᵈ _ _ hf theorem antitone_add_nat_of_succ_le {f : ℕ → α} {k : ℕ} (hf : ∀ n ≥ k, f (n + 1) ≤ f n) : Antitone (fun n ↦ f (n + k)) := @monotone_add_nat_of_le_succ αᵒᵈ _ f k hf -- TODO replace `{ x | k ≤ x }` with `Set.Ici k` theorem antitoneOn_nat_Ici_of_succ_le {f : ℕ → α} {k : ℕ} (hf : ∀ n ≥ k, f (n + 1) ≤ f n) : AntitoneOn f { x | k ≤ x } := @monotoneOn_nat_Ici_of_le_succ αᵒᵈ _ f k hf -- TODO replace `{ x | k ≤ x }` with `Set.Ici k` theorem antitone_add_nat_iff_antitoneOn_nat_Ici {f : ℕ → α} {k : ℕ} : Antitone (fun n ↦ f (n + k)) ↔ AntitoneOn f { x | k ≤ x } := @monotone_add_nat_iff_monotoneOn_nat_Ici αᵒᵈ _ f k theorem strictMono_nat_of_lt_succ {f : ℕ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f := Nat.rel_of_forall_rel_succ_of_lt (· < ·) hf theorem strictAnti_nat_of_succ_lt {f : ℕ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f := @strictMono_nat_of_lt_succ αᵒᵈ _ f hf namespace Nat /-- If `α` is a preorder with no maximal elements, then there exists a strictly monotone function `ℕ → α` with any prescribed value of `f 0`. -/ theorem exists_strictMono' [NoMaxOrder α] (a : α) : ∃ f : ℕ → α, StrictMono f ∧ f 0 = a := by choose g hg using fun x : α ↦ exists_gt x exact ⟨fun n ↦ Nat.recOn n a fun _ ↦ g, strictMono_nat_of_lt_succ fun n ↦ hg _, rfl⟩ /-- If `α` is a preorder with no maximal elements, then there exists a strictly antitone function `ℕ → α` with any prescribed value of `f 0`. -/ theorem exists_strictAnti' [NoMinOrder α] (a : α) : ∃ f : ℕ → α, StrictAnti f ∧ f 0 = a := exists_strictMono' (OrderDual.toDual a) theorem exists_strictMono_subsequence {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by have : NoMaxOrder {n // P n} := ⟨fun n ↦ Exists.intro ⟨(h n.1).choose, (h n.1).choose_spec.2⟩ (h n.1).choose_spec.1⟩ obtain ⟨f, hf, _⟩ := Nat.exists_strictMono' (⟨(h 0).choose, (h 0).choose_spec.2⟩ : {n // P n}) exact Exists.intro (fun n ↦ (f n).1) ⟨hf, fun n ↦ (f n).2⟩ variable (α) /-- If `α` is a nonempty preorder with no maximal elements, then there exists a strictly monotone function `ℕ → α`. -/ theorem exists_strictMono [Nonempty α] [NoMaxOrder α] : ∃ f : ℕ → α, StrictMono f := let ⟨a⟩ := ‹Nonempty α› let ⟨f, hf, _⟩ := exists_strictMono' a ⟨f, hf⟩ /-- If `α` is a nonempty preorder with no minimal elements, then there exists a strictly antitone function `ℕ → α`. -/ theorem exists_strictAnti [Nonempty α] [NoMinOrder α] : ∃ f : ℕ → α, StrictAnti f := exists_strictMono αᵒᵈ lemma pow_self_mono : Monotone fun n : ℕ ↦ n ^ n := by refine monotone_nat_of_le_succ fun n ↦ ?_ rw [Nat.pow_succ] exact (Nat.pow_le_pow_left n.le_succ _).trans (Nat.le_mul_of_pos_right _ n.succ_pos) lemma pow_monotoneOn : MonotoneOn (fun p : ℕ × ℕ ↦ p.1 ^ p.2) {p | p.1 ≠ 0} := fun _p _ _q hq hpq ↦ (Nat.pow_le_pow_left hpq.1 _).trans (Nat.pow_le_pow_right (Nat.pos_iff_ne_zero.2 hq) hpq.2) lemma pow_self_strictMonoOn : StrictMonoOn (fun n : ℕ ↦ n ^ n) {n : ℕ | n ≠ 0} := fun _m hm _n hn hmn ↦ (Nat.pow_lt_pow_left hmn hm).trans_le (Nat.pow_le_pow_right (Nat.pos_iff_ne_zero.2 hn) hmn.le) end Nat theorem Int.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℤ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a < b) : r (f a) (f b) := by rcases lt.dest hab with ⟨n, rfl⟩ clear hab induction n with | zero => rw [Int.ofNat_one]; apply h | succ n ihn => rw [Int.natCast_succ, ← Int.add_assoc]; exact _root_.trans ihn (h _) theorem Int.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℤ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a ≤ b) : r (f a) (f b) := hab.eq_or_lt.elim (fun h ↦ h ▸ refl _) fun h' ↦ Int.rel_of_forall_rel_succ_of_lt r h h' theorem monotone_int_of_le_succ {f : ℤ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f := Int.rel_of_forall_rel_succ_of_le (· ≤ ·) hf theorem antitone_int_of_succ_le {f : ℤ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f := Int.rel_of_forall_rel_succ_of_le (· ≥ ·) hf theorem strictMono_int_of_lt_succ {f : ℤ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f := Int.rel_of_forall_rel_succ_of_lt (· < ·) hf theorem strictAnti_int_of_succ_lt {f : ℤ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f := Int.rel_of_forall_rel_succ_of_lt (· > ·) hf namespace Int variable (α) variable [Nonempty α] [NoMinOrder α] [NoMaxOrder α] /-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly monotone function `f : ℤ → α`. -/ theorem exists_strictMono : ∃ f : ℤ → α, StrictMono f := by inhabit α rcases Nat.exists_strictMono' (default : α) with ⟨f, hf, hf₀⟩ rcases Nat.exists_strictAnti' (default : α) with ⟨g, hg, hg₀⟩ refine ⟨fun n ↦ Int.casesOn n f fun n ↦ g (n + 1), strictMono_int_of_lt_succ ?_⟩ rintro (n | _ | n) · exact hf n.lt_succ_self · change g 1 < f 0 rw [hf₀, ← hg₀] exact hg Nat.zero_lt_one · exact hg (Nat.lt_succ_self _) /-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly antitone function `f : ℤ → α`. -/ theorem exists_strictAnti : ∃ f : ℤ → α, StrictAnti f := exists_strictMono αᵒᵈ end Int -- TODO@Yael: Generalize the following four to succ orders /-- If `f` is a monotone function from `ℕ` to a preorder such that `x` lies between `f n` and `f (n + 1)`, then `x` doesn't lie in the range of `f`. -/ theorem Monotone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : Monotone f) (n : ℕ) {x : α} (h1 : f n < x) (h2 : x < f (n + 1)) (a : ℕ) : f a ≠ x := by rintro rfl exact (hf.reflect_lt h1).not_ge (Nat.le_of_lt_succ <| hf.reflect_lt h2) /-- If `f` is an antitone function from `ℕ` to a preorder such that `x` lies between `f (n + 1)` and `f n`, then `x` doesn't lie in the range of `f`. -/ theorem Antitone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : Antitone f) (n : ℕ) {x : α} (h1 : f (n + 1) < x) (h2 : x < f n) (a : ℕ) : f a ≠ x := by rintro rfl exact (hf.reflect_lt h2).not_ge (Nat.le_of_lt_succ <| hf.reflect_lt h1) /-- If `f` is a monotone function from `ℤ` to a preorder and `x` lies between `f n` and `f (n + 1)`, then `x` doesn't lie in the range of `f`. -/ theorem Monotone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : Monotone f) (n : ℤ) {x : α} (h1 : f n < x) (h2 : x < f (n + 1)) (a : ℤ) : f a ≠ x := by rintro rfl exact (hf.reflect_lt h1).not_ge (Int.le_of_lt_add_one <| hf.reflect_lt h2) /-- If `f` is an antitone function from `ℤ` to a preorder and `x` lies between `f (n + 1)` and `f n`, then `x` doesn't lie in the range of `f`. -/ theorem Antitone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : Antitone f) (n : ℤ) {x : α} (h1 : f (n + 1) < x) (h2 : x < f n) (a : ℤ) : f a ≠ x := by rintro rfl exact (hf.reflect_lt h2).not_ge (Int.le_of_lt_add_one <| hf.reflect_lt h1) end Preorder /-- A monotone function `f : ℕ → ℕ` bounded by `b`, which is constant after stabilising for the first time, stabilises in at most `b` steps. -/ lemma Nat.stabilises_of_monotone {f : ℕ → ℕ} {b n : ℕ} (hfmono : Monotone f) (hfb : ∀ m, f m ≤ b) (hfstab : ∀ m, f m = f (m + 1) → f (m + 1) = f (m + 2)) (hbn : b ≤ n) : f n = f b := by obtain ⟨m, hmb, hm⟩ : ∃ m ≤ b, f m = f (m + 1) := by contrapose! hfb let rec strictMono : ∀ m ≤ b + 1, m ≤ f m | 0, _ => Nat.zero_le _ | m + 1, hmb => (strictMono _ <| m.le_succ.trans hmb).trans_lt <| (hfmono m.le_succ).lt_of_ne <| hfb _ <| Nat.le_of_succ_le_succ hmb exact ⟨b + 1, strictMono _ le_rfl⟩ replace key : ∀ k : ℕ, f (m + k) = f (m + k + 1) ∧ f (m + k) = f m := fun k => Nat.rec ⟨hm, rfl⟩ (fun k ih => ⟨hfstab _ ih.1, ih.1.symm.trans ih.2⟩) k replace key : ∀ k ≥ m, f k = f m := fun k hk => (congr_arg f (Nat.add_sub_of_le hk)).symm.trans (key (k - m)).2 exact (key n (hmb.trans hbn)).trans (key b hmb).symm /-- A bounded monotone function `ℕ → ℕ` converges. -/ lemma converges_of_monotone_of_bounded {f : ℕ → ℕ} (mono_f : Monotone f) {c : ℕ} (hc : ∀ n, f n ≤ c) : ∃ b N, ∀ n ≥ N, f n = b := by induction c with | zero => use 0, 0, fun n _ ↦ Nat.eq_zero_of_le_zero (hc n) | succ c ih => by_cases! h : ∀ n, f n ≤ c · exact ih h · obtain ⟨N, hN⟩ := h replace hN : f N = c + 1 := by specialize hc N; omega use c + 1, N; intro n hn specialize mono_f hn; specialize hc n; cutsat
.lake/packages/mathlib/Mathlib/Order/Monotone/MonovaryOrder.lean
import Mathlib.Order.Monotone.Monovary import Mathlib.SetTheory.Cardinal.Order /-! # Interpreting monovarying functions as monotone functions This file proves that monovarying functions to linear orders can be made simultaneously monotone by setting the correct order on their shared indexing type. -/ open Function Set variable {ι ι' α β γ : Type*} section variable [LinearOrder α] [LinearOrder β] (f : ι → α) (g : ι → β) {s : Set ι} /-- If `f : ι → α` and `g : ι → β` are monovarying, then `MonovaryOrder f g` is a linear order on `ι` that makes `f` and `g` simultaneously monotone. We define `i < j` if `f i < f j`, or if `f i = f j` and `g i < g j`, breaking ties arbitrarily. -/ def MonovaryOrder (i j : ι) : Prop := Prod.Lex (· < ·) (Prod.Lex (· < ·) WellOrderingRel) (f i, g i, i) (f j, g j, j) instance : IsStrictTotalOrder ι (MonovaryOrder f g) where trichotomous i j := by convert trichotomous_of (Prod.Lex (· < ·) <| Prod.Lex (· < ·) WellOrderingRel) _ _ · simp only [Prod.ext_iff, ← and_assoc, imp_and, iff_and_self] exact ⟨congr_arg _, congr_arg _⟩ · infer_instance irrefl i := by rw [MonovaryOrder]; exact irrefl _ trans i j k := by rw [MonovaryOrder]; exact _root_.trans variable {f g} lemma monovaryOn_iff_exists_monotoneOn : MonovaryOn f g s ↔ ∃ (_ : LinearOrder ι), MonotoneOn f s ∧ MonotoneOn g s := by classical letI := linearOrderOfSTO (MonovaryOrder f g) refine ⟨fun hfg => ⟨‹_›, monotoneOn_iff_forall_lt.2 fun i hi j hj hij => ?_, monotoneOn_iff_forall_lt.2 fun i hi j hj hij => ?_⟩, ?_⟩ · obtain h | ⟨h, -⟩ := Prod.lex_iff.1 hij <;> exact h.le · obtain h | ⟨-, h⟩ := Prod.lex_iff.1 hij · exact hfg.symm hi hj h obtain h | ⟨h, -⟩ := Prod.lex_iff.1 h <;> exact h.le · rintro ⟨_, hf, hg⟩ exact hf.monovaryOn hg lemma antivaryOn_iff_exists_monotoneOn_antitoneOn : AntivaryOn f g s ↔ ∃ (_ : LinearOrder ι), MonotoneOn f s ∧ AntitoneOn g s := by simp_rw [← monovaryOn_toDual_right, monovaryOn_iff_exists_monotoneOn, monotoneOn_toDual_comp_iff] lemma monovaryOn_iff_exists_antitoneOn : MonovaryOn f g s ↔ ∃ (_ : LinearOrder ι), AntitoneOn f s ∧ AntitoneOn g s := by simp_rw [← antivaryOn_toDual_left, antivaryOn_iff_exists_monotoneOn_antitoneOn, monotoneOn_toDual_comp_iff] lemma antivaryOn_iff_exists_antitoneOn_monotoneOn : AntivaryOn f g s ↔ ∃ (_ : LinearOrder ι), AntitoneOn f s ∧ MonotoneOn g s := by simp_rw [← monovaryOn_toDual_left, monovaryOn_iff_exists_monotoneOn, monotoneOn_toDual_comp_iff] lemma monovary_iff_exists_monotone : Monovary f g ↔ ∃ (_ : LinearOrder ι), Monotone f ∧ Monotone g := by simp [← monovaryOn_univ, monovaryOn_iff_exists_monotoneOn] lemma monovary_iff_exists_antitone : Monovary f g ↔ ∃ (_ : LinearOrder ι), Antitone f ∧ Antitone g := by simp [← monovaryOn_univ, monovaryOn_iff_exists_antitoneOn] lemma antivary_iff_exists_monotone_antitone : Antivary f g ↔ ∃ (_ : LinearOrder ι), Monotone f ∧ Antitone g := by simp [← antivaryOn_univ, antivaryOn_iff_exists_monotoneOn_antitoneOn] lemma antivary_iff_exists_antitone_monotone : Antivary f g ↔ ∃ (_ : LinearOrder ι), Antitone f ∧ Monotone g := by simp [← antivaryOn_univ, antivaryOn_iff_exists_antitoneOn_monotoneOn] alias ⟨MonovaryOn.exists_monotoneOn, _⟩ := monovaryOn_iff_exists_monotoneOn alias ⟨MonovaryOn.exists_antitoneOn, _⟩ := monovaryOn_iff_exists_antitoneOn alias ⟨AntivaryOn.exists_monotoneOn_antitoneOn, _⟩ := antivaryOn_iff_exists_monotoneOn_antitoneOn alias ⟨AntivaryOn.exists_antitoneOn_monotoneOn, _⟩ := antivaryOn_iff_exists_antitoneOn_monotoneOn alias ⟨Monovary.exists_monotone, _⟩ := monovary_iff_exists_monotone alias ⟨Monovary.exists_antitone, _⟩ := monovary_iff_exists_antitone alias ⟨Antivary.exists_monotone_antitone, _⟩ := antivary_iff_exists_monotone_antitone alias ⟨Antivary.exists_antitone_monotone, _⟩ := antivary_iff_exists_antitone_monotone end
.lake/packages/mathlib/Mathlib/Order/Monotone/Defs.lean
import Mathlib.Data.Set.Operations import Mathlib.Logic.Function.Iterate import Mathlib.Order.Basic import Mathlib.Tactic.Coe import Mathlib.Util.AssertExists /-! # Monotonicity This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage, "monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti" to mean "decreasing". ## Definitions * `Monotone f`: A function `f` between two preorders is monotone if `a ≤ b` implies `f a ≤ f b`. * `Antitone f`: A function `f` between two preorders is antitone if `a ≤ b` implies `f b ≤ f a`. * `MonotoneOn f s`: Same as `Monotone f`, but for all `a, b ∈ s`. * `AntitoneOn f s`: Same as `Antitone f`, but for all `a, b ∈ s`. * `StrictMono f` : A function `f` between two preorders is strictly monotone if `a < b` implies `f a < f b`. * `StrictAnti f` : A function `f` between two preorders is strictly antitone if `a < b` implies `f b < f a`. * `StrictMonoOn f s`: Same as `StrictMono f`, but for all `a, b ∈ s`. * `StrictAntiOn f s`: Same as `StrictAnti f`, but for all `a, b ∈ s`. ## Implementation notes Some of these definitions used to only require `LE α` or `LT α`. The advantage of this is unclear and it led to slight elaboration issues. Now, everything requires `Preorder α` and seems to work fine. Related Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352. ## Tags monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing, decreasing, strictly decreasing -/ assert_not_exists Nat.instLinearOrder Int.instLinearOrder open Function OrderDual universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {π : ι → Type*} section MonotoneDef variable [Preorder α] [Preorder β] /-- A function `f` is monotone if `a ≤ b` implies `f a ≤ f b`. -/ def Monotone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f a ≤ f b /-- A function `f` is antitone if `a ≤ b` implies `f b ≤ f a`. -/ def Antitone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f b ≤ f a /-- A function `f` is monotone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f a ≤ f b`. -/ def MonotoneOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f a ≤ f b /-- A function `f` is antitone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f b ≤ f a`. -/ def AntitoneOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f b ≤ f a /-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/ def StrictMono (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f a < f b /-- A function `f` is strictly antitone if `a < b` implies `f b < f a`. -/ def StrictAnti (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f b < f a /-- A function `f` is strictly monotone on `s` if, for all `a, b ∈ s`, `a < b` implies `f a < f b`. -/ def StrictMonoOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a < f b /-- A function `f` is strictly antitone on `s` if, for all `a, b ∈ s`, `a < b` implies `f b < f a`. -/ def StrictAntiOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b < f a end MonotoneDef section Decidable variable [Preorder α] [Preorder β] {f : α → β} {s : Set α} instance [i : Decidable (∀ a b, a ≤ b → f a ≤ f b)] : Decidable (Monotone f) := i instance [i : Decidable (∀ a b, a ≤ b → f b ≤ f a)] : Decidable (Antitone f) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f a ≤ f b)] : Decidable (MonotoneOn f s) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f b ≤ f a)] : Decidable (AntitoneOn f s) := i instance [i : Decidable (∀ a b, a < b → f a < f b)] : Decidable (StrictMono f) := i instance [i : Decidable (∀ a b, a < b → f b < f a)] : Decidable (StrictAnti f) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f a < f b)] : Decidable (StrictMonoOn f s) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f b < f a)] : Decidable (StrictAntiOn f s) := i end Decidable /-! ### Monotonicity in function spaces -/ section Preorder variable [Preorder α] theorem Monotone.comp_le_comp_left [Preorder β] {f : β → α} {g h : γ → β} (hf : Monotone f) (le_gh : g ≤ h) : LE.le.{max w u} (f ∘ g) (f ∘ h) := fun x ↦ hf (le_gh x) variable [Preorder γ] theorem monotone_lam {f : α → β → γ} (hf : ∀ b, Monotone fun a ↦ f a b) : Monotone f := fun _ _ h b ↦ hf b h theorem monotone_app (f : β → α → γ) (b : β) (hf : Monotone fun a b ↦ f b a) : Monotone (f b) := fun _ _ h ↦ hf h b theorem antitone_lam {f : α → β → γ} (hf : ∀ b, Antitone fun a ↦ f a b) : Antitone f := fun _ _ h b ↦ hf b h theorem antitone_app (f : β → α → γ) (b : β) (hf : Antitone fun a b ↦ f b a) : Antitone (f b) := fun _ _ h ↦ hf h b end Preorder theorem Function.monotone_eval {ι : Type u} {α : ι → Type v} [∀ i, Preorder (α i)] (i : ι) : Monotone (Function.eval i : (∀ i, α i) → α i) := fun _ _ H ↦ H i /-! ### Monotonicity hierarchy -/ section Preorder variable [Preorder α] section Preorder variable [Preorder β] {f : α → β} {a b : α} /-! These four lemmas are there to strip off the semi-implicit arguments `⦃a b : α⦄`. This is useful when you do not want to apply a `Monotone` assumption (i.e. your goal is `a ≤ b → f a ≤ f b`). However if you find yourself writing `hf.imp h`, then you should have written `hf h` instead. -/ theorem Monotone.imp (hf : Monotone f) (h : a ≤ b) : f a ≤ f b := hf h theorem Antitone.imp (hf : Antitone f) (h : a ≤ b) : f b ≤ f a := hf h theorem StrictMono.imp (hf : StrictMono f) (h : a < b) : f a < f b := hf h theorem StrictAnti.imp (hf : StrictAnti f) (h : a < b) : f b < f a := hf h protected theorem Monotone.monotoneOn (hf : Monotone f) (s : Set α) : MonotoneOn f s := fun _ _ _ _ ↦ hf.imp protected theorem Antitone.antitoneOn (hf : Antitone f) (s : Set α) : AntitoneOn f s := fun _ _ _ _ ↦ hf.imp @[simp] theorem monotoneOn_univ : MonotoneOn f Set.univ ↔ Monotone f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.monotoneOn _⟩ @[simp] theorem antitoneOn_univ : AntitoneOn f Set.univ ↔ Antitone f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.antitoneOn _⟩ protected theorem StrictMono.strictMonoOn (hf : StrictMono f) (s : Set α) : StrictMonoOn f s := fun _ _ _ _ ↦ hf.imp protected theorem StrictAnti.strictAntiOn (hf : StrictAnti f) (s : Set α) : StrictAntiOn f s := fun _ _ _ _ ↦ hf.imp @[simp] theorem strictMonoOn_univ : StrictMonoOn f Set.univ ↔ StrictMono f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictMonoOn _⟩ @[simp] theorem strictAntiOn_univ : StrictAntiOn f Set.univ ↔ StrictAnti f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictAntiOn _⟩ end Preorder section PartialOrder variable [PartialOrder β] {f : α → β} theorem Monotone.strictMono_of_injective (h₁ : Monotone f) (h₂ : Injective f) : StrictMono f := fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H theorem Antitone.strictAnti_of_injective (h₁ : Antitone f) (h₂ : Injective f) : StrictAnti f := fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H.symm end PartialOrder end Preorder section PartialOrder variable [PartialOrder α] [Preorder β] {f : α → β} {s : Set α} theorem monotone_iff_forall_lt : Monotone f ↔ ∀ ⦃a b⦄, a < b → f a ≤ f b := forall₂_congr fun _ _ ↦ ⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) hf⟩ theorem antitone_iff_forall_lt : Antitone f ↔ ∀ ⦃a b⦄, a < b → f b ≤ f a := forall₂_congr fun _ _ ↦ ⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) hf⟩ theorem monotoneOn_iff_forall_lt : MonotoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a ≤ f b := ⟨fun hf _ ha _ hb h ↦ hf ha hb h.le, fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) (hf ha hb)⟩ theorem antitoneOn_iff_forall_lt : AntitoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b ≤ f a := ⟨fun hf _ ha _ hb h ↦ hf ha hb h.le, fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) (hf ha hb)⟩ -- `Preorder α` isn't strong enough: if the preorder on `α` is an equivalence relation, -- then `StrictMono f` is vacuously true. protected theorem StrictMonoOn.monotoneOn (hf : StrictMonoOn f s) : MonotoneOn f s := monotoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le protected theorem StrictAntiOn.antitoneOn (hf : StrictAntiOn f s) : AntitoneOn f s := antitoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le protected theorem StrictMono.monotone (hf : StrictMono f) : Monotone f := monotone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le protected theorem StrictAnti.antitone (hf : StrictAnti f) : Antitone f := antitone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le end PartialOrder /-! ### Monotonicity from and to subsingletons -/ namespace Subsingleton variable [Preorder α] [Preorder β] protected theorem monotone [Subsingleton α] (f : α → β) : Monotone f := fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le protected theorem antitone [Subsingleton α] (f : α → β) : Antitone f := fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le theorem monotone' [Subsingleton β] (f : α → β) : Monotone f := fun _ _ _ ↦ (Subsingleton.elim _ _).le theorem antitone' [Subsingleton β] (f : α → β) : Antitone f := fun _ _ _ ↦ (Subsingleton.elim _ _).le protected theorem strictMono [Subsingleton α] (f : α → β) : StrictMono f := fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim protected theorem strictAnti [Subsingleton α] (f : α → β) : StrictAnti f := fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim end Subsingleton /-! ### Miscellaneous monotonicity results -/ theorem monotone_id [Preorder α] : Monotone (id : α → α) := fun _ _ ↦ id theorem monotoneOn_id [Preorder α] {s : Set α} : MonotoneOn id s := fun _ _ _ _ ↦ id theorem strictMono_id [Preorder α] : StrictMono (id : α → α) := fun _ _ ↦ id theorem strictMonoOn_id [Preorder α] {s : Set α} : StrictMonoOn id s := fun _ _ _ _ ↦ id theorem monotone_const [Preorder α] [Preorder β] {c : β} : Monotone fun _ : α ↦ c := fun _ _ _ ↦ le_rfl theorem monotoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} : MonotoneOn (fun _ : α ↦ c) s := fun _ _ _ _ _ ↦ le_rfl theorem antitone_const [Preorder α] [Preorder β] {c : β} : Antitone fun _ : α ↦ c := fun _ _ _ ↦ le_refl c theorem antitoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} : AntitoneOn (fun _ : α ↦ c) s := fun _ _ _ _ _ ↦ le_rfl theorem strictMono_of_le_iff_le [Preorder α] [Preorder β] {f : α → β} (h : ∀ x y, x ≤ y ↔ f x ≤ f y) : StrictMono f := fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1 theorem strictAnti_of_le_iff_le [Preorder α] [Preorder β] {f : α → β} (h : ∀ x y, x ≤ y ↔ f y ≤ f x) : StrictAnti f := fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1 theorem injective_of_lt_imp_ne [LinearOrder α] {f : α → β} (h : ∀ x y, x < y → f x ≠ f y) : Injective f := by intro x y hf rcases lt_trichotomy x y with (hxy | rfl | hxy) · exact absurd hf <| h _ _ hxy · rfl · exact absurd hf.symm <| h _ _ hxy theorem injective_of_le_imp_le [PartialOrder α] [Preorder β] (f : α → β) (h : ∀ {x y}, f x ≤ f y → x ≤ y) : Injective f := fun _ _ hxy ↦ (h hxy.le).antisymm (h hxy.ge) /-! ### Monotonicity under composition -/ section Composition variable [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β} {s : Set α} {t : Set β} protected theorem Monotone.comp (hg : Monotone g) (hf : Monotone f) : Monotone (g ∘ f) := fun _ _ h ↦ hg (hf h) theorem Monotone.comp_antitone (hg : Monotone g) (hf : Antitone f) : Antitone (g ∘ f) := fun _ _ h ↦ hg (hf h) protected theorem Antitone.comp (hg : Antitone g) (hf : Antitone f) : Monotone (g ∘ f) := fun _ _ h ↦ hg (hf h) theorem Antitone.comp_monotone (hg : Antitone g) (hf : Monotone f) : Antitone (g ∘ f) := fun _ _ h ↦ hg (hf h) protected theorem Monotone.iterate {f : α → α} (hf : Monotone f) (n : ℕ) : Monotone f^[n] := Nat.recOn n monotone_id fun _ h ↦ h.comp hf protected theorem Monotone.comp_monotoneOn (hg : Monotone g) (hf : MonotoneOn f s) : MonotoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) theorem Monotone.comp_antitoneOn (hg : Monotone g) (hf : AntitoneOn f s) : AntitoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) protected theorem Antitone.comp_antitoneOn (hg : Antitone g) (hf : AntitoneOn f s) : MonotoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) theorem Antitone.comp_monotoneOn (hg : Antitone g) (hf : MonotoneOn f s) : AntitoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) protected theorem StrictMono.comp (hg : StrictMono g) (hf : StrictMono f) : StrictMono (g ∘ f) := fun _ _ h ↦ hg (hf h) theorem StrictMono.comp_strictAnti (hg : StrictMono g) (hf : StrictAnti f) : StrictAnti (g ∘ f) := fun _ _ h ↦ hg (hf h) protected theorem StrictAnti.comp (hg : StrictAnti g) (hf : StrictAnti f) : StrictMono (g ∘ f) := fun _ _ h ↦ hg (hf h) theorem StrictAnti.comp_strictMono (hg : StrictAnti g) (hf : StrictMono f) : StrictAnti (g ∘ f) := fun _ _ h ↦ hg (hf h) protected theorem StrictMono.iterate {f : α → α} (hf : StrictMono f) (n : ℕ) : StrictMono f^[n] := Nat.recOn n strictMono_id fun _ h ↦ h.comp hf protected theorem StrictMono.comp_strictMonoOn (hg : StrictMono g) (hf : StrictMonoOn f s) : StrictMonoOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) theorem StrictMono.comp_strictAntiOn (hg : StrictMono g) (hf : StrictAntiOn f s) : StrictAntiOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) protected theorem StrictAnti.comp_strictAntiOn (hg : StrictAnti g) (hf : StrictAntiOn f s) : StrictMonoOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) theorem StrictAnti.comp_strictMonoOn (hg : StrictAnti g) (hf : StrictMonoOn f s) : StrictAntiOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) lemma MonotoneOn.comp (hg : MonotoneOn g t) (hf : MonotoneOn f s) (hs : Set.MapsTo f s t) : MonotoneOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hx) (hs hy) <| hf hx hy hxy lemma MonotoneOn.comp_AntitoneOn (hg : MonotoneOn g t) (hf : AntitoneOn f s) (hs : Set.MapsTo f s t) : AntitoneOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hy) (hs hx) <| hf hx hy hxy lemma AntitoneOn.comp (hg : AntitoneOn g t) (hf : AntitoneOn f s) (hs : Set.MapsTo f s t) : MonotoneOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hy) (hs hx) <| hf hx hy hxy lemma AntitoneOn.comp_MonotoneOn (hg : AntitoneOn g t) (hf : MonotoneOn f s) (hs : Set.MapsTo f s t) : AntitoneOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hx) (hs hy) <| hf hx hy hxy lemma StrictMonoOn.comp (hg : StrictMonoOn g t) (hf : StrictMonoOn f s) (hs : Set.MapsTo f s t) : StrictMonoOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hx) (hs hy) <| hf hx hy hxy lemma StrictMonoOn.comp_strictAntiOn (hg : StrictMonoOn g t) (hf : StrictAntiOn f s) (hs : Set.MapsTo f s t) : StrictAntiOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hy) (hs hx) <| hf hx hy hxy lemma StrictAntiOn.comp (hg : StrictAntiOn g t) (hf : StrictAntiOn f s) (hs : Set.MapsTo f s t) : StrictMonoOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hy) (hs hx) <| hf hx hy hxy lemma StrictAntiOn.comp_strictMonoOn (hg : StrictAntiOn g t) (hf : StrictMonoOn f s) (hs : Set.MapsTo f s t) : StrictAntiOn (g ∘ f) s := fun _x hx _y hy hxy ↦ hg (hs hx) (hs hy) <| hf hx hy hxy end Composition /-! ### Monotonicity in linear orders -/ section LinearOrder variable [LinearOrder α] section Preorder variable [Preorder β] {f : α → β} {s : Set α} open Ordering theorem Monotone.reflect_lt (hf : Monotone f) {a b : α} (h : f a < f b) : a < b := lt_of_not_ge fun h' ↦ h.not_ge (hf h') theorem Antitone.reflect_lt (hf : Antitone f) {a b : α} (h : f a < f b) : b < a := lt_of_not_ge fun h' ↦ h.not_ge (hf h') theorem MonotoneOn.reflect_lt (hf : MonotoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : f a < f b) : a < b := lt_of_not_ge fun h' ↦ h.not_ge <| hf hb ha h' theorem AntitoneOn.reflect_lt (hf : AntitoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : f a < f b) : b < a := lt_of_not_ge fun h' ↦ h.not_ge <| hf ha hb h' end Preorder end LinearOrder theorem Subtype.mono_coe [Preorder α] (t : Set α) : Monotone ((↑) : Subtype t → α) := fun _ _ ↦ id theorem Subtype.strictMono_coe [Preorder α] (t : Set α) : StrictMono ((↑) : Subtype t → α) := fun _ _ ↦ id section Preorder variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] {f : α → γ} {g : β → δ} theorem monotone_fst : Monotone (@Prod.fst α β) := fun _ _ ↦ And.left theorem monotone_snd : Monotone (@Prod.snd α β) := fun _ _ ↦ And.right theorem monotone_prodMk_iff {f : γ → α} {g : γ → β} : Monotone (fun x => (f x, g x)) ↔ Monotone f ∧ Monotone g := by simp_rw [Monotone, Prod.mk_le_mk, forall_and] theorem Monotone.prodMk {f : γ → α} {g : γ → β} (hf : Monotone f) (hg : Monotone g) : Monotone (fun x => (f x, g x)) := monotone_prodMk_iff.2 ⟨hf, hg⟩ theorem Monotone.prodMap (hf : Monotone f) (hg : Monotone g) : Monotone (Prod.map f g) := fun _ _ h ↦ ⟨hf h.1, hg h.2⟩ theorem Antitone.prodMap (hf : Antitone f) (hg : Antitone g) : Antitone (Prod.map f g) := fun _ _ h ↦ ⟨hf h.1, hg h.2⟩ lemma monotone_prod_iff {h : α × β → γ} : Monotone h ↔ (∀ a, Monotone (fun b => h (a, b))) ∧ (∀ b, Monotone (fun a => h (a, b))) where mp h := ⟨fun _ _ _ hab => h (Prod.mk_le_mk_iff_right.mpr hab), fun _ _ _ hab => h (Prod.mk_le_mk_iff_left.mpr hab)⟩ mpr h _ _ hab := le_trans (h.1 _ (Prod.mk_le_mk.mp hab).2) (h.2 _ (Prod.mk_le_mk.mp hab).1) lemma antitone_prod_iff {h : α × β → γ} : Antitone h ↔ (∀ a, Antitone (fun b => h (a, b))) ∧ (∀ b, Antitone (fun a => h (a, b))) where mp h := ⟨fun _ _ _ hab => h (Prod.mk_le_mk_iff_right.mpr hab), fun _ _ _ hab => h (Prod.mk_le_mk_iff_left.mpr hab)⟩ mpr h _ _ hab := le_trans (h.1 _ (Prod.mk_le_mk.mp hab).2) (h.2 _ (Prod.mk_le_mk.mp hab).1) end Preorder section PartialOrder variable [PartialOrder α] [PartialOrder β] [Preorder γ] [Preorder δ] {f : α → γ} {g : β → δ} theorem StrictMono.prodMap (hf : StrictMono f) (hg : StrictMono g) : StrictMono (Prod.map f g) := fun a b ↦ by simp only [Prod.lt_iff] exact Or.imp (And.imp hf.imp hg.monotone.imp) (And.imp hf.monotone.imp hg.imp) theorem StrictAnti.prodMap (hf : StrictAnti f) (hg : StrictAnti g) : StrictAnti (Prod.map f g) := fun a b ↦ by simp only [Prod.lt_iff] exact Or.imp (And.imp hf.imp hg.antitone.imp) (And.imp hf.antitone.imp hg.imp) end PartialOrder /-! ### Pi types -/ namespace Function variable [Preorder α] [DecidableEq ι] [∀ i, Preorder (π i)] {f : ∀ i, π i} {i : ι} -- Porting note: Dot notation breaks in `f.update i` theorem update_mono : Monotone (update f i) := fun _ _ => update_le_update_iff'.2 theorem update_strictMono : StrictMono (update f i) := fun _ _ => update_lt_update_iff.2 theorem const_mono : Monotone (const β : α → β → α) := fun _ _ h _ ↦ h theorem const_strictMono [Nonempty β] : StrictMono (const β : α → β → α) := fun _ _ ↦ const_lt_const.2 end Function section apply variable {β : ι → Type*} [∀ i, Preorder (β i)] [Preorder α] {f : α → ∀ i, β i} lemma monotone_iff_apply₂ : Monotone f ↔ ∀ i, Monotone (f · i) := by simp [Monotone, Pi.le_def, @forall_swap ι] lemma antitone_iff_apply₂ : Antitone f ↔ ∀ i, Antitone (f · i) := by simp [Antitone, Pi.le_def, @forall_swap ι] alias ⟨Monotone.apply₂, Monotone.of_apply₂⟩ := monotone_iff_apply₂ alias ⟨Antitone.apply₂, Antitone.of_apply₂⟩ := antitone_iff_apply₂ end apply
.lake/packages/mathlib/Mathlib/Order/Defs/Unbundled.lean
import Mathlib.Data.Set.Defs import Mathlib.Tactic.ExtendDoc import Mathlib.Tactic.Lemma import Mathlib.Tactic.SplitIfs import Mathlib.Tactic.TypeStar /-! # Orders Defines classes for preorders, partial orders, and linear orders and proves some basic lemmas about them. -/ /-! ### Unbundled classes -/ /-- An empty relation does not relate any elements. -/ @[nolint unusedArguments] def EmptyRelation {α : Sort*} := fun _ _ : α ↦ False /-- `IsIrrefl X r` means the binary relation `r` on `X` is irreflexive (that is, `r x x` never holds). -/ class IsIrrefl (α : Sort*) (r : α → α → Prop) : Prop where irrefl : ∀ a, ¬r a a /-- `IsRefl X r` means the binary relation `r` on `X` is reflexive. -/ class IsRefl (α : Sort*) (r : α → α → Prop) : Prop where refl : ∀ a, r a a /-- `IsSymm X r` means the binary relation `r` on `X` is symmetric. -/ class IsSymm (α : Sort*) (r : α → α → Prop) : Prop where symm : ∀ a b, r a b → r b a /-- `IsAsymm X r` means that the binary relation `r` on `X` is asymmetric, that is, `r a b → ¬ r b a`. -/ class IsAsymm (α : Sort*) (r : α → α → Prop) : Prop where asymm : ∀ a b, r a b → ¬r b a /-- `IsAntisymm X r` means the binary relation `r` on `X` is antisymmetric. -/ class IsAntisymm (α : Sort*) (r : α → α → Prop) : Prop where antisymm : ∀ a b, r a b → r b a → a = b instance (priority := 100) IsAsymm.toIsAntisymm {α : Sort*} (r : α → α → Prop) [IsAsymm α r] : IsAntisymm α r where antisymm _ _ hx hy := (IsAsymm.asymm _ _ hx hy).elim /-- `IsTrans X r` means the binary relation `r` on `X` is transitive. -/ class IsTrans (α : Sort*) (r : α → α → Prop) : Prop where trans : ∀ a b c, r a b → r b c → r a c instance {α : Sort*} {r : α → α → Prop} [IsTrans α r] : Trans r r r := ⟨IsTrans.trans _ _ _⟩ instance (priority := 100) {α : Sort*} {r : α → α → Prop} [Trans r r r] : IsTrans α r := ⟨fun _ _ _ => Trans.trans⟩ /-- `IsTotal X r` means that the binary relation `r` on `X` is total, that is, that for any `x y : X` we have `r x y` or `r y x`. -/ class IsTotal (α : Sort*) (r : α → α → Prop) : Prop where total : ∀ a b, r a b ∨ r b a /-- `IsPreorder X r` means that the binary relation `r` on `X` is a pre-order, that is, reflexive and transitive. -/ class IsPreorder (α : Sort*) (r : α → α → Prop) : Prop extends IsRefl α r, IsTrans α r /-- `IsPartialOrder X r` means that the binary relation `r` on `X` is a partial order, that is, `IsPreorder X r` and `IsAntisymm X r`. -/ class IsPartialOrder (α : Sort*) (r : α → α → Prop) : Prop extends IsPreorder α r, IsAntisymm α r /-- `IsLinearOrder X r` means that the binary relation `r` on `X` is a linear order, that is, `IsPartialOrder X r` and `IsTotal X r`. -/ class IsLinearOrder (α : Sort*) (r : α → α → Prop) : Prop extends IsPartialOrder α r, IsTotal α r /-- `IsEquiv X r` means that the binary relation `r` on `X` is an equivalence relation, that is, `IsPreorder X r` and `IsSymm X r`. -/ class IsEquiv (α : Sort*) (r : α → α → Prop) : Prop extends IsPreorder α r, IsSymm α r /-- `IsStrictOrder X r` means that the binary relation `r` on `X` is a strict order, that is, `IsIrrefl X r` and `IsTrans X r`. -/ class IsStrictOrder (α : Sort*) (r : α → α → Prop) : Prop extends IsIrrefl α r, IsTrans α r /-- `IsStrictWeakOrder X lt` means that the binary relation `lt` on `X` is a strict weak order, that is, `IsStrictOrder X lt` and `¬lt a b ∧ ¬lt b a → ¬lt b c ∧ ¬lt c b → ¬lt a c ∧ ¬lt c a`. -/ class IsStrictWeakOrder (α : Sort*) (lt : α → α → Prop) : Prop extends IsStrictOrder α lt where incomp_trans : ∀ a b c, ¬lt a b ∧ ¬lt b a → ¬lt b c ∧ ¬lt c b → ¬lt a c ∧ ¬lt c a /-- `IsTrichotomous X lt` means that the binary relation `lt` on `X` is trichotomous, that is, either `lt a b` or `a = b` or `lt b a` for any `a` and `b`. -/ class IsTrichotomous (α : Sort*) (lt : α → α → Prop) : Prop where trichotomous : ∀ a b, lt a b ∨ a = b ∨ lt b a /-- `IsStrictTotalOrder X lt` means that the binary relation `lt` on `X` is a strict total order, that is, `IsTrichotomous X lt` and `IsStrictOrder X lt`. -/ class IsStrictTotalOrder (α : Sort*) (lt : α → α → Prop) : Prop extends IsTrichotomous α lt, IsStrictOrder α lt /-- Equality is an equivalence relation. -/ instance eq_isEquiv (α : Sort*) : IsEquiv α (· = ·) where symm := @Eq.symm _ trans := @Eq.trans _ refl := Eq.refl /-- `Iff` is an equivalence relation. -/ instance iff_isEquiv : IsEquiv Prop Iff where symm := @Iff.symm trans := @Iff.trans refl := @Iff.refl section variable {α : Sort*} {r : α → α → Prop} {a b c : α} /-- Local notation for an arbitrary binary relation `r`. -/ local infixl:50 " ≺ " => r lemma irrefl [IsIrrefl α r] (a : α) : ¬a ≺ a := IsIrrefl.irrefl a lemma refl [IsRefl α r] (a : α) : a ≺ a := IsRefl.refl a lemma trans [IsTrans α r] : a ≺ b → b ≺ c → a ≺ c := IsTrans.trans _ _ _ lemma symm [IsSymm α r] : a ≺ b → b ≺ a := IsSymm.symm _ _ lemma antisymm [IsAntisymm α r] : a ≺ b → b ≺ a → a = b := IsAntisymm.antisymm _ _ lemma asymm [IsAsymm α r] : a ≺ b → ¬b ≺ a := IsAsymm.asymm _ _ lemma trichotomous [IsTrichotomous α r] : ∀ a b : α, a ≺ b ∨ a = b ∨ b ≺ a := IsTrichotomous.trichotomous instance (priority := 90) isAsymm_of_isTrans_of_isIrrefl [IsTrans α r] [IsIrrefl α r] : IsAsymm α r := ⟨fun a _b h₁ h₂ => absurd (_root_.trans h₁ h₂) (irrefl a)⟩ instance IsIrrefl.decide [DecidableRel r] [IsIrrefl α r] : IsIrrefl α (fun a b => decide (r a b) = true) where irrefl := fun a => by simpa using irrefl a instance IsRefl.decide [DecidableRel r] [IsRefl α r] : IsRefl α (fun a b => decide (r a b) = true) where refl := fun a => by simpa using refl a instance IsTrans.decide [DecidableRel r] [IsTrans α r] : IsTrans α (fun a b => decide (r a b) = true) where trans := fun a b c => by simpa using trans a b c instance IsSymm.decide [DecidableRel r] [IsSymm α r] : IsSymm α (fun a b => decide (r a b) = true) where symm := fun a b => by simpa using symm a b instance IsAntisymm.decide [DecidableRel r] [IsAntisymm α r] : IsAntisymm α (fun a b => decide (r a b) = true) where antisymm a b h₁ h₂ := antisymm (r := r) _ _ (by simpa using h₁) (by simpa using h₂) instance IsAsymm.decide [DecidableRel r] [IsAsymm α r] : IsAsymm α (fun a b => decide (r a b) = true) where asymm := fun a b => by simpa using asymm a b instance IsTotal.decide [DecidableRel r] [IsTotal α r] : IsTotal α (fun a b => decide (r a b) = true) where total := fun a b => by simpa using total a b instance IsTrichotomous.decide [DecidableRel r] [IsTrichotomous α r] : IsTrichotomous α (fun a b => decide (r a b) = true) where trichotomous := fun a b => by simpa using trichotomous a b variable (r) @[elab_without_expected_type] lemma irrefl_of [IsIrrefl α r] (a : α) : ¬a ≺ a := irrefl a @[elab_without_expected_type] lemma refl_of [IsRefl α r] (a : α) : a ≺ a := refl a @[elab_without_expected_type] lemma trans_of [IsTrans α r] : a ≺ b → b ≺ c → a ≺ c := _root_.trans @[elab_without_expected_type] lemma symm_of [IsSymm α r] : a ≺ b → b ≺ a := symm @[elab_without_expected_type] lemma asymm_of [IsAsymm α r] : a ≺ b → ¬b ≺ a := asymm @[elab_without_expected_type] lemma total_of [IsTotal α r] (a b : α) : a ≺ b ∨ b ≺ a := IsTotal.total _ _ @[elab_without_expected_type] lemma trichotomous_of [IsTrichotomous α r] : ∀ a b : α, a ≺ b ∨ a = b ∨ b ≺ a := trichotomous section /-- `IsRefl` as a definition, suitable for use in proofs. -/ def Reflexive := ∀ x, x ≺ x /-- `IsSymm` as a definition, suitable for use in proofs. -/ def Symmetric := ∀ ⦃x y⦄, x ≺ y → y ≺ x /-- `IsTrans` as a definition, suitable for use in proofs. -/ def Transitive := ∀ ⦃x y z⦄, x ≺ y → y ≺ z → x ≺ z /-- `IsIrrefl` as a definition, suitable for use in proofs. -/ def Irreflexive := ∀ x, ¬x ≺ x /-- `IsAntisymm` as a definition, suitable for use in proofs. -/ def AntiSymmetric := ∀ ⦃x y⦄, x ≺ y → y ≺ x → x = y /-- `IsTotal` as a definition, suitable for use in proofs. -/ def Total := ∀ x y, x ≺ y ∨ y ≺ x theorem Equivalence.reflexive (h : Equivalence r) : Reflexive r := h.refl theorem Equivalence.symmetric (h : Equivalence r) : Symmetric r := fun _ _ ↦ h.symm theorem Equivalence.transitive (h : Equivalence r) : Transitive r := fun _ _ _ ↦ h.trans variable {β : Sort*} (r : β → β → Prop) (f : α → β) theorem InvImage.trans (h : Transitive r) : Transitive (InvImage r f) := fun (a₁ a₂ a₃ : α) (h₁ : InvImage r f a₁ a₂) (h₂ : InvImage r f a₂ a₃) ↦ h h₁ h₂ theorem InvImage.irreflexive (h : Irreflexive r) : Irreflexive (InvImage r f) := fun (a : α) (h₁ : InvImage r f a a) ↦ h (f a) h₁ end end /-! ### Minimal and maximal -/ section LE variable {α : Type*} [LE α] {P : α → Prop} {x y : α} /-- `Minimal P x` means that `x` is a minimal element satisfying `P`. -/ def Minimal (P : α → Prop) (x : α) : Prop := P x ∧ ∀ ⦃y⦄, P y → y ≤ x → x ≤ y /-- `Maximal P x` means that `x` is a maximal element satisfying `P`. -/ def Maximal (P : α → Prop) (x : α) : Prop := P x ∧ ∀ ⦃y⦄, P y → x ≤ y → y ≤ x lemma Minimal.prop (h : Minimal P x) : P x := h.1 lemma Maximal.prop (h : Maximal P x) : P x := h.1 lemma Minimal.le_of_le (h : Minimal P x) (hy : P y) (hle : y ≤ x) : x ≤ y := h.2 hy hle lemma Maximal.le_of_ge (h : Maximal P x) (hy : P y) (hge : x ≤ y) : y ≤ x := h.2 hy hge end LE section LE variable {ι : Sort*} {α : Type*} [LE α] {P : ι → Prop} {f : ι → α} {i j : ι} /-- `MinimalFor P f i` means that `f i` is minimal over all `i` satisfying `P`. -/ def MinimalFor (P : ι → Prop) (f : ι → α) (i : ι) : Prop := P i ∧ ∀ ⦃j⦄, P j → f j ≤ f i → f i ≤ f j /-- `MaximalFor P f i` means that `f i` is maximal over all `i` satisfying `P`. -/ def MaximalFor (P : ι → Prop) (f : ι → α) (i : ι) : Prop := P i ∧ ∀ ⦃j⦄, P j → f i ≤ f j → f j ≤ f i lemma MinimalFor.prop (h : MinimalFor P f i) : P i := h.1 lemma MaximalFor.prop (h : MaximalFor P f i) : P i := h.1 lemma MinimalFor.le_of_le (h : MinimalFor P f i) (hj : P j) (hji : f j ≤ f i) : f i ≤ f j := h.2 hj hji lemma MaximalFor.le_of_le (h : MaximalFor P f i) (hj : P j) (hij : f i ≤ f j) : f j ≤ f i := h.2 hj hij end LE /-! ### Upper and lower sets -/ /-- An upper set in an order `α` is a set such that any element greater than one of its members is also a member. Also called up-set, upward-closed set. -/ def IsUpperSet {α : Type*} [LE α] (s : Set α) : Prop := ∀ ⦃a b : α⦄, a ≤ b → a ∈ s → b ∈ s /-- A lower set in an order `α` is a set such that any element less than one of its members is also a member. Also called down-set, downward-closed set. -/ def IsLowerSet {α : Type*} [LE α] (s : Set α) : Prop := ∀ ⦃a b : α⦄, b ≤ a → a ∈ s → b ∈ s @[inherit_doc IsUpperSet] structure UpperSet (α : Type*) [LE α] where /-- The carrier of an `UpperSet`. -/ carrier : Set α /-- The carrier of an `UpperSet` is an upper set. -/ upper' : IsUpperSet carrier extend_docs UpperSet before "The type of upper sets of an order." @[inherit_doc IsLowerSet] structure LowerSet (α : Type*) [LE α] where /-- The carrier of a `LowerSet`. -/ carrier : Set α /-- The carrier of a `LowerSet` is a lower set. -/ lower' : IsLowerSet carrier extend_docs LowerSet before "The type of lower sets of an order." /-- An upper set relative to a predicate `P` is a set such that all elements satisfy `P` and any element greater than one of its members and satisfying `P` is also a member. -/ def IsRelUpperSet {α : Type*} [LE α] (s : Set α) (P : α → Prop) : Prop := ∀ ⦃a : α⦄, a ∈ s → P a ∧ ∀ ⦃b : α⦄, a ≤ b → P b → b ∈ s /-- A lower set relative to a predicate `P` is a set such that all elements satisfy `P` and any element less than one of its members and satisfying `P` is also a member. -/ def IsRelLowerSet {α : Type*} [LE α] (s : Set α) (P : α → Prop) : Prop := ∀ ⦃a : α⦄, a ∈ s → P a ∧ ∀ ⦃b : α⦄, b ≤ a → P b → b ∈ s @[inherit_doc IsRelUpperSet] structure RelUpperSet {α : Type*} [LE α] (P : α → Prop) where /-- The carrier of a `RelUpperSet`. -/ carrier : Set α /-- The carrier of a `RelUpperSet` is an upper set relative to `P`. Do NOT use directly. Please use `RelUpperSet.isRelUpperSet` instead. -/ isRelUpperSet' : IsRelUpperSet carrier P extend_docs RelUpperSet before "The type of upper sets of an order relative to `P`." @[inherit_doc IsRelLowerSet] structure RelLowerSet {α : Type*} [LE α] (P : α → Prop) where /-- The carrier of a `RelLowerSet`. -/ carrier : Set α /-- The carrier of a `RelLowerSet` is a lower set relative to `P`. Do NOT use directly. Please use `RelLowerSet.isRelLowerSet` instead. -/ isRelLowerSet' : IsRelLowerSet carrier P extend_docs RelLowerSet before "The type of lower sets of an order relative to `P`." variable {α β : Type*} {r : α → α → Prop} {s : β → β → Prop} theorem of_eq [IsRefl α r] : ∀ {a b}, a = b → r a b | _, _, .refl _ => refl _ theorem comm [IsSymm α r] {a b : α} : r a b ↔ r b a := ⟨symm, symm⟩ theorem antisymm' [IsAntisymm α r] {a b : α} : r a b → r b a → b = a := fun h h' => antisymm h' h theorem antisymm_iff [IsRefl α r] [IsAntisymm α r] {a b : α} : r a b ∧ r b a ↔ a = b := ⟨fun h => antisymm h.1 h.2, by rintro rfl exact ⟨refl _, refl _⟩⟩ /-- A version of `antisymm` with `r` explicit. This lemma matches the lemmas from lean core in `Init.Algebra.Classes`, but is missing there. -/ @[elab_without_expected_type] theorem antisymm_of (r : α → α → Prop) [IsAntisymm α r] {a b : α} : r a b → r b a → a = b := antisymm /-- A version of `antisymm'` with `r` explicit. This lemma matches the lemmas from lean core in `Init.Algebra.Classes`, but is missing there. -/ @[elab_without_expected_type] theorem antisymm_of' (r : α → α → Prop) [IsAntisymm α r] {a b : α} : r a b → r b a → b = a := antisymm' /-- A version of `comm` with `r` explicit. This lemma matches the lemmas from lean core in `Init.Algebra.Classes`, but is missing there. -/ theorem comm_of (r : α → α → Prop) [IsSymm α r] {a b : α} : r a b ↔ r b a := comm protected theorem IsAsymm.isAntisymm (r) [IsAsymm α r] : IsAntisymm α r := ⟨fun _ _ h₁ h₂ => (_root_.asymm h₁ h₂).elim⟩ protected theorem IsAsymm.isIrrefl [IsAsymm α r] : IsIrrefl α r := ⟨fun _ h => _root_.asymm h h⟩ protected theorem IsTotal.isTrichotomous (r) [IsTotal α r] : IsTrichotomous α r := ⟨fun a b => or_left_comm.1 (Or.inr <| total_of r a b)⟩ -- see Note [lower instance priority] instance (priority := 100) IsTotal.to_isRefl (r) [IsTotal α r] : IsRefl α r := ⟨fun a => or_self_iff.1 <| total_of r a a⟩ theorem ne_of_irrefl {r} [IsIrrefl α r] : ∀ {x y : α}, r x y → x ≠ y | _, _, h, rfl => irrefl _ h theorem ne_of_irrefl' {r} [IsIrrefl α r] : ∀ {x y : α}, r x y → y ≠ x | _, _, h, rfl => irrefl _ h theorem not_rel_of_subsingleton (r) [IsIrrefl α r] [Subsingleton α] (x y) : ¬r x y := Subsingleton.elim x y ▸ irrefl x theorem rel_of_subsingleton (r) [IsRefl α r] [Subsingleton α] (x y) : r x y := Subsingleton.elim x y ▸ refl x @[simp] theorem empty_relation_apply (a b : α) : EmptyRelation a b ↔ False := Iff.rfl instance : IsIrrefl α EmptyRelation := ⟨fun _ => id⟩ theorem rel_congr_left [IsSymm α r] [IsTrans α r] {a b c : α} (h : r a b) : r a c ↔ r b c := ⟨trans_of r (symm_of r h), trans_of r h⟩ theorem rel_congr_right [IsSymm α r] [IsTrans α r] {a b c : α} (h : r b c) : r a b ↔ r a c := ⟨(trans_of r · h), (trans_of r · (symm_of r h))⟩ theorem rel_congr [IsSymm α r] [IsTrans α r] {a b c d : α} (h₁ : r a b) (h₂ : r c d) : r a c ↔ r b d := by rw [rel_congr_left h₁, rel_congr_right h₂] theorem trans_trichotomous_left [IsTrans α r] [IsTrichotomous α r] {a b c : α} (h₁ : ¬r b a) (h₂ : r b c) : r a c := by rcases trichotomous_of r a b with (h₃ | rfl | h₃) · exact _root_.trans h₃ h₂ · exact h₂ · exact absurd h₃ h₁ theorem trans_trichotomous_right [IsTrans α r] [IsTrichotomous α r] {a b c : α} (h₁ : r a b) (h₂ : ¬r c b) : r a c := by rcases trichotomous_of r b c with (h₃ | rfl | h₃) · exact _root_.trans h₁ h₃ · exact h₁ · exact absurd h₃ h₂ theorem transitive_of_trans (r : α → α → Prop) [IsTrans α r] : Transitive r := IsTrans.trans /-- In a trichotomous irreflexive order, every element is determined by the set of predecessors. -/ theorem extensional_of_trichotomous_of_irrefl (r : α → α → Prop) [IsTrichotomous α r] [IsIrrefl α r] {a b : α} (H : ∀ x, r x a ↔ r x b) : a = b := ((@trichotomous _ r _ a b).resolve_left <| mt (H _).2 <| irrefl a).resolve_right <| mt (H _).1 <| irrefl b
.lake/packages/mathlib/Mathlib/Order/Defs/LinearOrder.lean
import Batteries.Classes.Order import Batteries.Tactic.Trans import Mathlib.Data.Ordering.Basic import Mathlib.Tactic.ExtendDoc import Mathlib.Tactic.Lemma import Mathlib.Tactic.Push.Attr import Mathlib.Tactic.SplitIfs import Mathlib.Tactic.TypeStar import Mathlib.Order.Defs.PartialOrder /-! # Orders Defines classes for linear orders and proves some basic lemmas about them. -/ variable {α : Type*} section LinearOrder /-! ### Definition of `LinearOrder` and lemmas about types with a linear order -/ /-- Default definition of `max`. -/ def maxDefault [LE α] [DecidableLE α] (a b : α) := if a ≤ b then b else a /-- Default definition of `min`. -/ def minDefault [LE α] [DecidableLE α] (a b : α) := if a ≤ b then a else b /-- This attempts to prove that a given instance of `compare` is equal to `compareOfLessAndEq` by introducing the arguments and trying the following approaches in order: 1. seeing if `rfl` works 2. seeing if the `compare` at hand is nonetheless essentially `compareOfLessAndEq`, but, because of implicit arguments, requires us to unfold the defs and split the `if`s in the definition of `compareOfLessAndEq` 3. seeing if we can split by cases on the arguments, then see if the defs work themselves out (useful when `compare` is defined via a `match` statement, as it is for `Bool`) -/ macro "compareOfLessAndEq_rfl" : tactic => `(tactic| (intro a b; first | rfl | (simp only [compare, compareOfLessAndEq]; split_ifs <;> rfl) | (induction a <;> induction b <;> simp +decide only))) /-- A linear order is reflexive, transitive, antisymmetric and total relation `≤`. We assume that every linear ordered type has decidable `(≤)`, `(<)`, and `(=)`. -/ class LinearOrder (α : Type*) extends PartialOrder α, Min α, Max α, 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 min := fun a b => if a ≤ b then a else b max := fun a b => if a ≤ b then b else a /-- The minimum function is equivalent to the one you get from `minOfLe`. -/ min_def : ∀ a b, min a b = if a ≤ b then a else b := by intros; rfl /-- The minimum function is equivalent to the one you get from `maxOfLe`. -/ max_def : ∀ a b, max a b = if a ≤ b then b else a := by intros; rfl 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 variable [LinearOrder α] {a b c : α} attribute [instance 900] LinearOrder.toDecidableLT attribute [instance 900] LinearOrder.toDecidableLE attribute [instance 900] LinearOrder.toDecidableEq instance : Std.IsLinearOrder α where le_total := LinearOrder.le_total lemma le_total : ∀ a b : α, a ≤ b ∨ b ≤ a := LinearOrder.le_total lemma le_of_not_ge : ¬a ≤ b → b ≤ a := (le_total a b).resolve_left lemma lt_of_not_ge (h : ¬b ≤ a) : a < b := lt_of_le_not_ge (le_of_not_ge h) h @[deprecated (since := "2025-05-11")] alias le_of_not_le := le_of_not_ge lemma lt_trichotomy (a b : α) : a < b ∨ a = b ∨ b < a := by grind lemma le_of_not_gt (h : ¬b < a) : a ≤ b := match lt_trichotomy a b with | Or.inl hlt => le_of_lt hlt | Or.inr (Or.inl HEq) => HEq ▸ le_refl a | Or.inr (Or.inr hgt) => absurd hgt h @[deprecated (since := "2025-05-11")] alias le_of_not_lt := le_of_not_gt lemma lt_or_ge (a b : α) : a < b ∨ b ≤ a := if hba : b ≤ a then Or.inr hba else Or.inl <| lt_of_not_ge hba @[deprecated (since := "2025-05-11")] alias lt_or_le := lt_or_ge lemma le_or_gt (a b : α) : a ≤ b ∨ b < a := (lt_or_ge b a).symm @[deprecated (since := "2025-05-11")] alias le_or_lt := le_or_gt lemma lt_or_gt_of_ne (h : a ≠ b) : a < b ∨ b < a := by grind lemma ne_iff_lt_or_gt : a ≠ b ↔ a < b ∨ b < a := ⟨lt_or_gt_of_ne, (Or.elim · ne_of_lt ne_of_gt)⟩ lemma lt_iff_not_ge : a < b ↔ ¬b ≤ a := ⟨not_le_of_gt, lt_of_not_ge⟩ @[simp, push] lemma not_lt : ¬a < b ↔ b ≤ a := ⟨le_of_not_gt, not_lt_of_ge⟩ @[simp, push] lemma not_le : ¬a ≤ b ↔ b < a := lt_iff_not_ge.symm lemma eq_or_gt_of_not_lt (h : ¬a < b) : a = b ∨ b < a := if h₁ : a = b then Or.inl h₁ else Or.inr (lt_of_not_ge fun hge => h (lt_of_le_of_ne hge h₁)) @[deprecated (since := "2025-07-27")] alias eq_or_lt_of_not_gt := eq_or_gt_of_not_lt @[deprecated (since := "2025-05-11")] alias eq_or_lt_of_not_lt := eq_or_gt_of_not_lt theorem le_imp_le_of_lt_imp_lt {α β} [Preorder α] [LinearOrder β] {a b : α} {c d : β} (H : d < c → b < a) (h : a ≤ b) : c ≤ d := le_of_not_gt fun h' => not_le_of_gt (H h') h @[grind =] lemma min_def (a b : α) : min a b = if a ≤ b then a else b := LinearOrder.min_def a b @[grind =] lemma max_def (a b : α) : max a b = if a ≤ b then b else a := LinearOrder.max_def a b lemma min_le_left (a b : α) : min a b ≤ a := by grind lemma min_le_right (a b : α) : min a b ≤ b := by grind lemma le_min (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b := by grind lemma le_max_left (a b : α) : a ≤ max a b := by grind lemma le_max_right (a b : α) : b ≤ max a b := by grind lemma max_le (h₁ : a ≤ c) (h₂ : b ≤ c) : max a b ≤ c := by grind lemma eq_min (h₁ : c ≤ a) (h₂ : c ≤ b) (h₃ : ∀ {d}, d ≤ a → d ≤ b → d ≤ c) : c = min a b := le_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b)) lemma min_comm (a b : α) : min a b = min b a := eq_min (min_le_right a b) (min_le_left a b) fun h₁ h₂ => le_min h₂ h₁ lemma min_assoc (a b c : α) : min (min a b) c = min a (min b c) := by grind lemma min_left_comm (a b c : α) : min a (min b c) = min b (min a c) := by grind @[simp] lemma min_self (a : α) : min a a = a := by grind lemma min_eq_left (h : a ≤ b) : min a b = a := by grind lemma min_eq_right (h : b ≤ a) : min a b = b := min_comm b a ▸ min_eq_left h lemma eq_max (h₁ : a ≤ c) (h₂ : b ≤ c) (h₃ : ∀ {d}, a ≤ d → b ≤ d → c ≤ d) : c = max a b := le_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂) lemma max_comm (a b : α) : max a b = max b a := eq_max (le_max_right a b) (le_max_left a b) fun h₁ h₂ => max_le h₂ h₁ lemma max_assoc (a b c : α) : max (max a b) c = max a (max b c) := by grind lemma max_left_comm (a b c : α) : max a (max b c) = max b (max a c) := by grind @[simp] lemma max_self (a : α) : max a a = a := by grind lemma max_eq_left (h : b ≤ a) : max a b = a := by grind lemma max_eq_right (h : a ≤ b) : max a b = b := max_comm b a ▸ max_eq_left h lemma min_eq_left_of_lt (h : a < b) : min a b = a := min_eq_left (le_of_lt h) lemma min_eq_right_of_lt (h : b < a) : min a b = b := min_eq_right (le_of_lt h) lemma max_eq_left_of_lt (h : b < a) : max a b = a := max_eq_left (le_of_lt h) lemma max_eq_right_of_lt (h : a < b) : max a b = b := max_eq_right (le_of_lt h) lemma lt_min (h₁ : a < b) (h₂ : a < c) : a < min b c := by cases le_total b c <;> simp [min_eq_left, min_eq_right, *] lemma max_lt (h₁ : a < c) (h₂ : b < c) : max a b < c := by cases le_total a b <;> simp [max_eq_left, max_eq_right, *] section Ord lemma compare_lt_iff_lt : compare a b = .lt ↔ a < b := by rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq] grind lemma compare_gt_iff_gt : compare a b = .gt ↔ b < a := by rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq] grind lemma compare_eq_iff_eq : compare a b = .eq ↔ a = b := by rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq] grind lemma compare_le_iff_le : compare a b ≠ .gt ↔ a ≤ b := by cases h : compare a b · simpa using le_of_lt <| compare_lt_iff_lt.1 h · simpa using le_of_eq <| compare_eq_iff_eq.1 h · simpa using compare_gt_iff_gt.1 h lemma compare_ge_iff_ge : compare a b ≠ .lt ↔ b ≤ a := by cases h : compare a b · simpa using compare_lt_iff_lt.1 h · simpa using le_of_eq <| (·.symm) <| compare_eq_iff_eq.1 h · simpa using le_of_lt <| compare_gt_iff_gt.1 h lemma compare_iff (a b : α) {o : Ordering} : compare a b = o ↔ o.Compares a b := by cases o <;> simp only [Ordering.Compares] · exact compare_lt_iff_lt · exact compare_eq_iff_eq · exact compare_gt_iff_gt theorem cmp_eq_compare (a b : α) : cmp a b = compare a b := by refine ((compare_iff ..).2 ?_).symm unfold cmp cmpUsing; split_ifs with h1 h2 · exact h1 · exact h2 · exact le_antisymm (not_lt.1 h2) (not_lt.1 h1) theorem cmp_eq_compareOfLessAndEq (a b : α) : cmp a b = compareOfLessAndEq a b := (cmp_eq_compare ..).trans (LinearOrder.compare_eq_compareOfLessAndEq ..) instance : Std.LawfulBCmp (compare (α := α)) where eq_swap {a b} := by cases _ : compare b a <;> simp_all [Ordering.swap, compare_eq_iff_eq, compare_lt_iff_lt, compare_gt_iff_gt] isLE_trans h₁ h₂ := by simp only [← Ordering.ne_gt_iff_isLE, compare_le_iff_le] at * exact le_trans h₁ h₂ compare_eq_iff_beq := by simp [compare_eq_iff_eq] eq_lt_iff_lt := by simp [compare_lt_iff_lt] isLE_iff_le := by simp [← Ordering.ne_gt_iff_isLE, compare_le_iff_le] end Ord end LinearOrder
.lake/packages/mathlib/Mathlib/Order/Defs/PartialOrder.lean
import Batteries.Tactic.Alias import Batteries.Tactic.Trans import Mathlib.Tactic.ExtendDoc import Mathlib.Tactic.Lemma import Mathlib.Tactic.SplitIfs import Mathlib.Tactic.TypeStar import Mathlib.Tactic.ToDual /-! # Orders Defines classes for preorders and partial orders and proves some basic lemmas about them. We also define covering relations on a preorder. We say that `b` *covers* `a` if `a < b` and there is no element in between. We say that `b` *weakly covers* `a` if `a ≤ b` and there is no element between `a` and `b`. In a partial order this is equivalent to `a ⋖ b ∨ a = b`, in a preorder this is equivalent to `a ⋖ b ∨ (a ≤ b ∧ b ≤ a)` ## Notation * `a ⋖ b` means that `b` covers `a`. * `a ⩿ b` means that `b` weakly covers `a`. -/ variable {α : Type*} section Preorder /-! ### Definition of `Preorder` and lemmas about types with a `Preorder` -/ /-- A preorder is a reflexive, transitive relation `≤` with `a < b` defined in the obvious way. -/ class Preorder (α : Type*) extends LE α, LT α where le_refl : ∀ a : α, a ≤ a le_trans : ∀ a b c : α, a ≤ b → b ≤ c → a ≤ c lt := fun a b => a ≤ b ∧ ¬b ≤ a lt_iff_le_not_ge : ∀ a b : α, a < b ↔ a ≤ b ∧ ¬b ≤ a := by intros; rfl attribute [to_dual self (reorder := 3 5, 6 7)] Preorder.le_trans attribute [to_dual self (reorder := 3 4)] Preorder.lt_iff_le_not_ge instance [Preorder α] : Std.LawfulOrderLT α where lt_iff := Preorder.lt_iff_le_not_ge instance [Preorder α] : Std.IsPreorder α where le_refl := Preorder.le_refl le_trans := Preorder.le_trans @[deprecated (since := "2025-05-11")] alias Preorder.lt_iff_le_not_le := Preorder.lt_iff_le_not_ge variable [Preorder α] {a b c : α} /-- The relation `≤` on a preorder is reflexive. -/ @[refl, simp] lemma le_refl : ∀ a : α, a ≤ a := Preorder.le_refl /-- A version of `le_refl` where the argument is implicit -/ lemma le_rfl : a ≤ a := le_refl a /-- The relation `≤` on a preorder is transitive. -/ @[to_dual ge_trans] lemma le_trans : a ≤ b → b ≤ c → a ≤ c := Preorder.le_trans _ _ _ @[to_dual self (reorder := 3 4)] lemma lt_iff_le_not_ge : a < b ↔ a ≤ b ∧ ¬b ≤ a := Preorder.lt_iff_le_not_ge _ _ @[deprecated (since := "2025-05-11")] alias lt_iff_le_not_le := lt_iff_le_not_ge @[to_dual self (reorder := 3 4)] lemma lt_of_le_not_ge (hab : a ≤ b) (hba : ¬ b ≤ a) : a < b := lt_iff_le_not_ge.2 ⟨hab, hba⟩ @[deprecated (since := "2025-05-11")] alias lt_of_le_not_le := lt_of_le_not_ge @[to_dual ge_of_eq] lemma le_of_eq (hab : a = b) : a ≤ b := by rw [hab] @[to_dual self (reorder := 3 4)] lemma le_of_lt (hab : a < b) : a ≤ b := (lt_iff_le_not_ge.1 hab).1 @[to_dual self (reorder := 3 4)] lemma not_le_of_gt (hab : a < b) : ¬ b ≤ a := (lt_iff_le_not_ge.1 hab).2 @[to_dual self (reorder := 3 4)] lemma not_lt_of_ge (hab : a ≤ b) : ¬ b < a := imp_not_comm.1 not_le_of_gt hab @[deprecated (since := "2025-05-11")] alias not_le_of_lt := not_le_of_gt @[deprecated (since := "2025-05-11")] alias not_lt_of_le := not_lt_of_ge @[to_dual self (reorder := 3 4)] alias LT.lt.not_ge := not_le_of_gt @[to_dual self (reorder := 3 4)] alias LE.le.not_gt := not_lt_of_ge @[deprecated (since := "2025-06-07")] alias LT.lt.not_le := LT.lt.not_ge @[deprecated (since := "2025-06-07")] alias LE.le.not_lt := LE.le.not_gt @[to_dual self] lemma lt_irrefl (a : α) : ¬a < a := fun h ↦ not_le_of_gt h le_rfl @[deprecated (since := "2025-06-07")] alias gt_irrefl := lt_irrefl @[to_dual lt_of_lt_of_le'] lemma lt_of_lt_of_le (hab : a < b) (hbc : b ≤ c) : a < c := lt_of_le_not_ge (le_trans (le_of_lt hab) hbc) fun hca ↦ not_le_of_gt hab (le_trans hbc hca) @[to_dual lt_of_le_of_lt'] lemma lt_of_le_of_lt (hab : a ≤ b) (hbc : b < c) : a < c := lt_of_le_not_ge (le_trans hab (le_of_lt hbc)) fun hca ↦ not_le_of_gt hbc (le_trans hca hab) @[deprecated (since := "2025-06-07")] alias gt_of_gt_of_ge := lt_of_lt_of_le' @[deprecated (since := "2025-06-07")] alias gt_of_ge_of_gt := lt_of_le_of_lt' @[to_dual gt_trans] lemma lt_trans : a < b → b < c → a < c := fun h₁ h₂ => lt_of_lt_of_le h₁ (le_of_lt h₂) @[to_dual ne_of_gt] lemma ne_of_lt (h : a < b) : a ≠ b := fun he => absurd h (he ▸ lt_irrefl a) @[to_dual self (reorder := 3 4)] lemma lt_asymm (h : a < b) : ¬b < a := fun h1 : b < a => lt_irrefl a (lt_trans h h1) @[to_dual self (reorder := 3 4)] alias not_lt_of_gt := lt_asymm @[deprecated (since := "2025-05-11")] alias not_lt_of_lt := not_lt_of_gt @[to_dual le_of_lt_or_eq'] lemma le_of_lt_or_eq (h : a < b ∨ a = b) : a ≤ b := h.elim le_of_lt le_of_eq @[to_dual le_of_eq_or_lt'] lemma le_of_eq_or_lt (h : a = b ∨ a < b) : a ≤ b := h.elim le_of_eq le_of_lt instance instTransLE : @Trans α α α LE.le LE.le LE.le := ⟨le_trans⟩ instance instTransLT : @Trans α α α LT.lt LT.lt LT.lt := ⟨lt_trans⟩ instance instTransLTLE : @Trans α α α LT.lt LE.le LT.lt := ⟨lt_of_lt_of_le⟩ instance instTransLELT : @Trans α α α LE.le LT.lt LT.lt := ⟨lt_of_le_of_lt⟩ -- we have to express the following 4 instances in terms of `≥` instead of flipping the arguments -- to `≤`, because otherwise `calc` gets confused. @[to_dual existing instTransLE] instance instTransGE : @Trans α α α GE.ge GE.ge GE.ge := ⟨ge_trans⟩ @[to_dual existing instTransLT] instance instTransGT : @Trans α α α GT.gt GT.gt GT.gt := ⟨gt_trans⟩ @[to_dual existing instTransLTLE] instance instTransGTGE : @Trans α α α GT.gt GE.ge GT.gt := ⟨lt_of_lt_of_le'⟩ @[to_dual existing instTransLELT] instance instTransGEGT : @Trans α α α GE.ge GT.gt GT.gt := ⟨lt_of_le_of_lt'⟩ /-- `<` is decidable if `≤` is. -/ @[to_dual decidableGTOfDecidableGE /-- `<` is decidable if `≤` is. -/] def decidableLTOfDecidableLE [DecidableLE α] : DecidableLT α := fun _ _ => decidable_of_iff _ lt_iff_le_not_ge.symm /-- `WCovBy a b` means that `a = b` or `b` covers `a`. This means that `a ≤ b` and there is no element in between. This is denoted `a ⩿ b`. -/ @[to_dual self (reorder := 3 4)] def WCovBy (a b : α) : Prop := a ≤ b ∧ ∀ ⦃c⦄, a < c → ¬c < b @[inherit_doc] infixl:50 " ⩿ " => WCovBy /-- `CovBy a b` means that `b` covers `a`. This means that `a < b` and there is no element in between. This is denoted `a ⋖ b`. -/ @[to_dual self (reorder := 3 4)] def CovBy {α : Type*} [LT α] (a b : α) : Prop := a < b ∧ ∀ ⦃c⦄, a < c → ¬c < b @[inherit_doc] infixl:50 " ⋖ " => CovBy end Preorder section PartialOrder /-! ### Definition of `PartialOrder` and lemmas about types with a partial order -/ /-- A partial order is a reflexive, transitive, antisymmetric relation `≤`. -/ class PartialOrder (α : Type*) extends Preorder α where le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b attribute [to_dual self (reorder := 5 6)] PartialOrder.le_antisymm instance [PartialOrder α] : Std.IsPartialOrder α where le_antisymm := PartialOrder.le_antisymm variable [PartialOrder α] {a b : α} @[to_dual ge_antisymm] lemma le_antisymm : a ≤ b → b ≤ a → a = b := PartialOrder.le_antisymm _ _ @[to_dual eq_of_ge_of_le] alias eq_of_le_of_ge := le_antisymm @[deprecated (since := "2025-06-07")] alias eq_of_le_of_le := eq_of_le_of_ge @[to_dual ge_antisymm_iff] lemma le_antisymm_iff : a = b ↔ a ≤ b ∧ b ≤ a := ⟨fun e => ⟨le_of_eq e, le_of_eq e.symm⟩, fun ⟨h1, h2⟩ => le_antisymm h1 h2⟩ @[to_dual lt_of_le_of_ne'] lemma lt_of_le_of_ne : a ≤ b → a ≠ b → a < b := fun h₁ h₂ => lt_of_le_not_ge h₁ <| mt (le_antisymm h₁) h₂ /-- Equality is decidable if `≤` is. -/ @[to_dual decidableEqofDecidableGE /-- Equality is decidable if `≤` is. -/] def decidableEqOfDecidableLE [DecidableLE α] : DecidableEq α | a, b => if hab : a ≤ b then if hba : b ≤ a then isTrue (le_antisymm hab hba) else isFalse fun heq => hba (heq ▸ le_refl _) else isFalse fun heq => hab (heq ▸ le_refl _) -- See Note [decidable namespace] @[to_dual Decidable.lt_or_eq_of_le'] protected lemma Decidable.lt_or_eq_of_le [DecidableLE α] (hab : a ≤ b) : a < b ∨ a = b := if hba : b ≤ a then Or.inr (le_antisymm hab hba) else Or.inl (lt_of_le_not_ge hab hba) @[to_dual Decidable.le_iff_lt_or_eq'] protected lemma Decidable.le_iff_lt_or_eq [DecidableLE α] : a ≤ b ↔ a < b ∨ a = b := ⟨Decidable.lt_or_eq_of_le, le_of_lt_or_eq⟩ @[to_dual lt_or_eq_of_le'] lemma lt_or_eq_of_le : a ≤ b → a < b ∨ a = b := open scoped Classical in Decidable.lt_or_eq_of_le @[to_dual le_iff_lt_or_eq'] lemma le_iff_lt_or_eq : a ≤ b ↔ a < b ∨ a = b := open scoped Classical in Decidable.le_iff_lt_or_eq end PartialOrder
.lake/packages/mathlib/Mathlib/ModelTheory/PartialEquiv.lean
import Mathlib.ModelTheory.DirectLimit import Mathlib.Order.Ideal /-! # Partial Isomorphisms This file defines partial isomorphisms between first-order structures. ## Main Definitions - `FirstOrder.Language.PartialEquiv` is defined so that `L.PartialEquiv M N`, annotated `M ≃ₚ[L] N`, is the type of equivalences between substructures of `M` and `N`. These can be ordered, with an order that is defined here in terms of a commutative square, but could also be defined as the order on the graphs of the partial equivalences under inclusion as subsets of `M × N`. - `FirstOrder.Language.FGEquiv` is the type of partial equivalences `M ≃ₚ[L] N` with finitely-generated domain (or equivalently, codomain). - `FirstOrder.Language.IsExtensionPair` is defined so that `L.IsExtensionPair M N` indicates that any finitely-generated partial equivalence from `M` to `N` can be extended to include an arbitrary element `m : M` in its domain. ## Main Results - `FirstOrder.Language.embedding_from_cg` shows that if structures `M` and `N` form an equivalence pair with `M` countably-generated, then any finite-generated partial equivalence between them can be extended to an embedding `M ↪[L] N`. - `FirstOrder.Language.equiv_from_cg` shows that if countably-generated structures `M` and `N` form an equivalence pair in both directions, then any finite-generated partial equivalence between them can be extended to an isomorphism `M ↪[L] N`. - The proofs of these results are adapted in part from David Wärn's approach to countable dense linear orders, a special case of this phenomenon in the case where `L = Language.order`. -/ universe u v w w' namespace FirstOrder namespace Language variable (L : Language.{u, v}) (M : Type w) (N : Type w') variable [L.Structure M] [L.Structure N] open FirstOrder Structure Substructure /-- A partial `L`-equivalence, implemented as an equivalence between substructures. -/ structure PartialEquiv where /-- The substructure which is the domain of the equivalence. -/ dom : L.Substructure M /-- The substructure which is the codomain of the equivalence. -/ cod : L.Substructure N /-- The equivalence between the two subdomains. -/ toEquiv : dom ≃[L] cod @[inherit_doc] scoped[FirstOrder] notation:25 M " ≃ₚ[" L "] " N => FirstOrder.Language.PartialEquiv L M N variable {L M N} namespace PartialEquiv noncomputable instance instInhabited_self : Inhabited (M ≃ₚ[L] M) := ⟨⊤, ⊤, Equiv.refl L (⊤ : L.Substructure M)⟩ /-- Maps to the symmetric partial equivalence. -/ def symm (f : M ≃ₚ[L] N) : N ≃ₚ[L] M where dom := f.cod cod := f.dom toEquiv := f.toEquiv.symm @[simp] theorem symm_symm (f : M ≃ₚ[L] N) : f.symm.symm = f := rfl theorem symm_bijective : Function.Bijective (symm : (M ≃ₚ[L] N) → _) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem symm_apply (f : M ≃ₚ[L] N) (x : f.cod) : f.symm.toEquiv x = f.toEquiv.symm x := rfl instance : LE (M ≃ₚ[L] N) := ⟨fun f g ↦ ∃ h : f.dom ≤ g.dom, (subtype _).comp (g.toEquiv.toEmbedding.comp (Substructure.inclusion h)) = (subtype _).comp f.toEquiv.toEmbedding⟩ theorem le_def (f g : M ≃ₚ[L] N) : f ≤ g ↔ ∃ h : f.dom ≤ g.dom, (subtype _).comp (g.toEquiv.toEmbedding.comp (Substructure.inclusion h)) = (subtype _).comp f.toEquiv.toEmbedding := Iff.rfl @[gcongr] theorem dom_le_dom {f g : M ≃ₚ[L] N} : f ≤ g → f.dom ≤ g.dom := fun ⟨le, _⟩ ↦ le @[gcongr] theorem cod_le_cod {f g : M ≃ₚ[L] N} : f ≤ g → f.cod ≤ g.cod := by rintro ⟨_, eq_fun⟩ n hn let m := f.toEquiv.symm ⟨n, hn⟩ have : ((subtype _).comp f.toEquiv.toEmbedding) m = n := by simp only [m, Embedding.comp_apply, Equiv.coe_toEmbedding, Equiv.apply_symm_apply, coe_subtype] rw [← this, ← eq_fun] simp only [Embedding.comp_apply, coe_inclusion, Equiv.coe_toEmbedding, coe_subtype, SetLike.coe_mem] theorem subtype_toEquiv_inclusion {f g : M ≃ₚ[L] N} (h : f ≤ g) : (subtype _).comp (g.toEquiv.toEmbedding.comp (Substructure.inclusion (dom_le_dom h))) = (subtype _).comp f.toEquiv.toEmbedding := by let ⟨_, eq⟩ := h; exact eq theorem toEquiv_inclusion {f g : M ≃ₚ[L] N} (h : f ≤ g) : g.toEquiv.toEmbedding.comp (Substructure.inclusion (dom_le_dom h)) = (Substructure.inclusion (cod_le_cod h)).comp f.toEquiv.toEmbedding := by rw [← (subtype _).comp_inj, subtype_toEquiv_inclusion h] ext simp theorem toEquiv_inclusion_apply {f g : M ≃ₚ[L] N} (h : f ≤ g) (x : f.dom) : g.toEquiv (Substructure.inclusion (dom_le_dom h) x) = Substructure.inclusion (cod_le_cod h) (f.toEquiv x) := by apply (subtype _).injective change (subtype _).comp (g.toEquiv.toEmbedding.comp (inclusion _)) x = _ rw [subtype_toEquiv_inclusion h] simp theorem le_iff {f g : M ≃ₚ[L] N} : f ≤ g ↔ ∃ dom_le_dom : f.dom ≤ g.dom, ∃ cod_le_cod : f.cod ≤ g.cod, ∀ x, inclusion cod_le_cod (f.toEquiv x) = g.toEquiv (inclusion dom_le_dom x) := by constructor · exact fun h ↦ ⟨dom_le_dom h, cod_le_cod h, by intro x; apply (subtype _).inj'; rwa [toEquiv_inclusion_apply]⟩ · rintro ⟨dom_le_dom, le_cod, h_eq⟩ rw [le_def] exact ⟨dom_le_dom, by ext; change subtype _ (g.toEquiv _) = _; rw [← h_eq]; rfl⟩ theorem le_trans (f g h : M ≃ₚ[L] N) : f ≤ g → g ≤ h → f ≤ h := by rintro ⟨le_fg, eq_fg⟩ ⟨le_gh, eq_gh⟩ refine ⟨le_fg.trans le_gh, ?_⟩ rw [← eq_fg, ← Embedding.comp_assoc (g := g.toEquiv.toEmbedding), ← eq_gh] ext simp private theorem le_refl (f : M ≃ₚ[L] N) : f ≤ f := ⟨le_rfl, rfl⟩ private theorem le_antisymm (f g : M ≃ₚ[L] N) (le_fg : f ≤ g) (le_gf : g ≤ f) : f = g := by let ⟨dom_f, cod_f, equiv_f⟩ := f cases _root_.le_antisymm (dom_le_dom le_fg) (dom_le_dom le_gf) cases _root_.le_antisymm (cod_le_cod le_fg) (cod_le_cod le_gf) convert rfl exact Equiv.injective_toEmbedding ((subtype _).comp_injective (subtype_toEquiv_inclusion le_fg)) instance : PartialOrder (M ≃ₚ[L] N) where le_refl := le_refl le_trans := le_trans le_antisymm := le_antisymm @[gcongr] lemma symm_le_symm {f g : M ≃ₚ[L] N} (hfg : f ≤ g) : f.symm ≤ g.symm := by rw [le_iff] refine ⟨cod_le_cod hfg, dom_le_dom hfg, ?_⟩ intro x apply g.toEquiv.injective change g.toEquiv (inclusion _ (f.toEquiv.symm x)) = g.toEquiv (g.toEquiv.symm _) rw [g.toEquiv.apply_symm_apply, (Equiv.apply_symm_apply f.toEquiv x).symm, f.toEquiv.symm_apply_apply] exact toEquiv_inclusion_apply hfg _ theorem monotone_symm : Monotone (fun (f : M ≃ₚ[L] N) ↦ f.symm) := fun _ _ => symm_le_symm theorem symm_le_iff {f : M ≃ₚ[L] N} {g : N ≃ₚ[L] M} : f.symm ≤ g ↔ f ≤ g.symm := ⟨by intro h; rw [← f.symm_symm]; exact monotone_symm h, by intro h; rw [← g.symm_symm]; exact monotone_symm h⟩ theorem ext {f g : M ≃ₚ[L] N} (h_dom : f.dom = g.dom) : (∀ x : M, ∀ h : x ∈ f.dom, subtype _ (f.toEquiv ⟨x, h⟩) = subtype _ (g.toEquiv ⟨x, (h_dom ▸ h)⟩)) → f = g := by intro h rcases f with ⟨dom_f, cod_f, equiv_f⟩ cases h_dom apply le_antisymm <;> (rw [le_def]; use le_rfl; ext ⟨x, hx⟩) · exact (h x hx).symm · exact h x hx theorem ext_iff {f g : M ≃ₚ[L] N} : f = g ↔ ∃ h_dom : f.dom = g.dom, ∀ x : M, ∀ h : x ∈ f.dom, subtype _ (f.toEquiv ⟨x, h⟩) = subtype _ (g.toEquiv ⟨x, (h_dom ▸ h)⟩) := by constructor · intro h_eq rcases f with ⟨dom_f, cod_f, equiv_f⟩ cases h_eq exact ⟨rfl, fun _ _ ↦ rfl⟩ · rintro ⟨h, H⟩; exact ext h H theorem monotone_dom : Monotone (fun f : M ≃ₚ[L] N ↦ f.dom) := fun _ _ ↦ dom_le_dom theorem monotone_cod : Monotone (fun f : M ≃ₚ[L] N ↦ f.cod) := fun _ _ ↦ cod_le_cod /-- Restriction of a partial equivalence to a substructure of the domain. -/ noncomputable def domRestrict (f : M ≃ₚ[L] N) {A : L.Substructure M} (h : A ≤ f.dom) : M ≃ₚ[L] N := by let g := (subtype _).comp (f.toEquiv.toEmbedding.comp (A.inclusion h)) exact { dom := A cod := g.toHom.range toEquiv := g.equivRange } theorem domRestrict_le (f : M ≃ₚ[L] N) {A : L.Substructure M} (h : A ≤ f.dom) : f.domRestrict h ≤ f := ⟨h, rfl⟩ theorem le_domRestrict (f g : M ≃ₚ[L] N) {A : L.Substructure M} (hf : f.dom ≤ A) (hg : A ≤ g.dom) (hfg : f ≤ g) : f ≤ g.domRestrict hg := ⟨hf, by rw [← (subtype_toEquiv_inclusion hfg)]; rfl⟩ /-- Restriction of a partial equivalence to a substructure of the codomain. -/ noncomputable def codRestrict (f : M ≃ₚ[L] N) {A : L.Substructure N} (h : A ≤ f.cod) : M ≃ₚ[L] N := (f.symm.domRestrict h).symm theorem codRestrict_le (f : M ≃ₚ[L] N) {A : L.Substructure N} (h : A ≤ f.cod) : codRestrict f h ≤ f := symm_le_iff.2 (f.symm.domRestrict_le h) theorem le_codRestrict (f g : M ≃ₚ[L] N) {A : L.Substructure N} (hf : f.cod ≤ A) (hg : A ≤ g.cod) (hfg : f ≤ g) : f ≤ g.codRestrict hg := symm_le_iff.1 (le_domRestrict f.symm g.symm hf hg (monotone_symm hfg)) /-- A partial equivalence as an embedding from its domain. -/ def toEmbedding (f : M ≃ₚ[L] N) : f.dom ↪[L] N := (subtype _).comp f.toEquiv.toEmbedding @[simp] theorem toEmbedding_apply {f : M ≃ₚ[L] N} (m : f.dom) : f.toEmbedding m = f.toEquiv m := rfl /-- Given a partial equivalence which has the whole structure as domain, returns the corresponding embedding. -/ def toEmbeddingOfEqTop {f : M ≃ₚ[L] N} (h : f.dom = ⊤) : M ↪[L] N := (h ▸ f.toEmbedding).comp topEquiv.symm.toEmbedding @[simp] theorem toEmbeddingOfEqTop_apply {f : M ≃ₚ[L] N} (h : f.dom = ⊤) (m : M) : toEmbeddingOfEqTop h m = f.toEquiv ⟨m, h.symm ▸ mem_top m⟩ := by rcases f with ⟨dom, cod, g⟩ cases h rfl set_option linter.style.nameCheck false in /-- Given a partial equivalence which has the whole structure as domain and as codomain, returns the corresponding equivalence. -/ def toEquivOfEqTop {f : M ≃ₚ[L] N} (h_dom : f.dom = ⊤) (h_cod : f.cod = ⊤) : M ≃[L] N := (topEquiv (M := N)).comp ((h_dom ▸ h_cod ▸ f.toEquiv).comp (topEquiv (M := M)).symm) @[simp] theorem toEquivOfEqTop_toEmbedding {f : M ≃ₚ[L] N} (h_dom : f.dom = ⊤) (h_cod : f.cod = ⊤) : (toEquivOfEqTop h_dom h_cod).toEmbedding = toEmbeddingOfEqTop h_dom := by rcases f with ⟨dom, cod, g⟩ cases h_dom cases h_cod rfl theorem dom_fg_iff_cod_fg {N : Type*} [L.Structure N] (f : M ≃ₚ[L] N) : f.dom.FG ↔ f.cod.FG := by rw [Substructure.fg_iff_structure_fg, f.toEquiv.fg_iff, Substructure.fg_iff_structure_fg] end PartialEquiv namespace Embedding /-- Given an embedding, returns the corresponding partial equivalence with `⊤` as domain. -/ noncomputable def toPartialEquiv (f : M ↪[L] N) : M ≃ₚ[L] N := ⟨⊤, f.toHom.range, f.equivRange.comp (Substructure.topEquiv)⟩ theorem toPartialEquiv_injective : Function.Injective (fun f : M ↪[L] N ↦ f.toPartialEquiv) := by intro _ _ h ext rw [PartialEquiv.ext_iff] at h rcases h with ⟨_, H⟩ exact H _ (Substructure.mem_top _) @[simp] theorem toEmbedding_toPartialEquiv (f : M ↪[L] N) : PartialEquiv.toEmbeddingOfEqTop (f := f.toPartialEquiv) rfl = f := rfl @[simp] theorem toPartialEquiv_toEmbedding {f : M ≃ₚ[L] N} (h : f.dom = ⊤) : (PartialEquiv.toEmbeddingOfEqTop h).toPartialEquiv = f := by rcases f with ⟨_, _, _⟩ cases h apply PartialEquiv.ext · intro _ _ rfl · rfl end Embedding namespace DirectLimit open PartialEquiv variable {ι : Type*} [Preorder ι] [Nonempty ι] [IsDirected ι (· ≤ ·)] variable (S : ι →o M ≃ₚ[L] N) instance : DirectedSystem (fun i ↦ (S i).dom) (fun _ _ h ↦ Substructure.inclusion (dom_le_dom (S.monotone h))) where map_self _ _ := rfl map_map _ _ _ _ _ _ := rfl instance : DirectedSystem (fun i ↦ (S i).cod) (fun _ _ h ↦ Substructure.inclusion (cod_le_cod (S.monotone h))) where map_self _ _ := rfl map_map _ _ _ _ _ _ := rfl /-- The limit of a directed system of PartialEquivs. -/ noncomputable def partialEquivLimit : M ≃ₚ[L] N where dom := iSup (fun i ↦ (S i).dom) cod := iSup (fun i ↦ (S i).cod) toEquiv := (Equiv_iSup { toFun := (fun i ↦ (S i).cod) monotone' := monotone_cod.comp S.monotone} ).comp ((DirectLimit.equiv_lift L ι (fun i ↦ (S i).dom) (fun _ _ hij ↦ Substructure.inclusion (dom_le_dom (S.monotone hij))) (fun i ↦ (S i).cod) (fun _ _ hij ↦ Substructure.inclusion (cod_le_cod (S.monotone hij))) (fun i ↦ (S i).toEquiv) (fun _ _ hij _ ↦ toEquiv_inclusion_apply (S.monotone hij) _) ).comp (Equiv_iSup { toFun := (fun i ↦ (S i).dom) monotone' := monotone_dom.comp S.monotone}).symm) @[simp] theorem dom_partialEquivLimit : (partialEquivLimit S).dom = iSup (fun x ↦ (S x).dom) := rfl @[simp] theorem cod_partialEquivLimit : (partialEquivLimit S).cod = iSup (fun x ↦ (S x).cod) := rfl @[simp] lemma partialEquivLimit_comp_inclusion {i : ι} : (partialEquivLimit S).toEquiv.toEmbedding.comp (Substructure.inclusion (le_iSup _ i)) = (Substructure.inclusion (le_iSup _ i)).comp (S i).toEquiv.toEmbedding := by simp only [partialEquivLimit, Equiv.comp_toEmbedding, Embedding.comp_assoc] rw [Equiv_isup_symm_inclusion] congr theorem le_partialEquivLimit (i : ι) : S i ≤ partialEquivLimit S := ⟨le_iSup (f := fun i ↦ (S i).dom) _, by #adaptation_note /-- https://github.com/leanprover/lean4/pull/5020 these two `simp` calls cannot be combined. -/ simp only [partialEquivLimit_comp_inclusion] simp only [cod_partialEquivLimit, ← Embedding.comp_assoc, subtype_comp_inclusion]⟩ end DirectLimit section FGEquiv open PartialEquiv Set DirectLimit variable (M) (N) (L) /-- The type of equivalences between finitely generated substructures. -/ abbrev FGEquiv := {f : M ≃ₚ[L] N // f.dom.FG} /-- Two structures `M` and `N` form an extension pair if the domain of any finitely-generated map from `M` to `N` can be extended to include any element of `M`. -/ def IsExtensionPair : Prop := ∀ (f : L.FGEquiv M N) (m : M), ∃ g, m ∈ g.1.dom ∧ f ≤ g variable {M N L} theorem countable_self_fgequiv_of_countable [Countable M] : Countable (L.FGEquiv M M) := by let g : L.FGEquiv M M → Σ U : { S : L.Substructure M // S.FG }, U.val →[L] M := fun f ↦ ⟨⟨f.val.dom, f.prop⟩, (subtype _).toHom.comp f.val.toEquiv.toHom⟩ have g_inj : Function.Injective g := by intro f f' h ext let ⟨⟨dom_f, cod_f, equiv_f⟩, f_fin⟩ := f cases congr_arg (·.1) h apply PartialEquiv.ext (by rfl) simp only [g, Sigma.mk.inj_iff, heq_eq_eq, true_and] at h exact fun x hx ↦ congr_fun (congr_arg (↑) h) ⟨x, hx⟩ have : ∀ U : { S : L.Substructure M // S.FG }, Structure.FG L U.val := fun U ↦ (U.val.fg_iff_structure_fg.1 U.prop) exact Function.Embedding.countable ⟨g, g_inj⟩ instance inhabited_self_FGEquiv : Inhabited (L.FGEquiv M M) := ⟨⟨⟨⊥, ⊥, Equiv.refl L (⊥ : L.Substructure M)⟩, fg_bot⟩⟩ instance inhabited_FGEquiv_of_IsEmpty_Constants_and_Relations [IsEmpty L.Constants] [IsEmpty (L.Relations 0)] [L.Structure N] : Inhabited (L.FGEquiv M N) := ⟨⟨⟨⊥, ⊥, { toFun := isEmptyElim invFun := isEmptyElim left_inv := isEmptyElim right_inv := isEmptyElim map_fun' := fun {n} f x => by subsingleton map_rel' := fun {n} r x => by cases n · exact isEmptyElim r · exact isEmptyElim (x 0) }⟩, fg_bot⟩⟩ /-- Maps to the symmetric finitely-generated partial equivalence. -/ @[simps] def FGEquiv.symm (f : L.FGEquiv M N) : L.FGEquiv N M := ⟨f.1.symm, f.1.dom_fg_iff_cod_fg.1 f.2⟩ lemma isExtensionPair_iff_cod : L.IsExtensionPair M N ↔ ∀ (f : L.FGEquiv N M) (m : M), ∃ g, m ∈ g.1.cod ∧ f ≤ g := by refine Iff.intro ?_ ?_ <;> · intro h f m obtain ⟨g, h1, h2⟩ := h f.symm m exact ⟨g.symm, h1, monotone_symm h2⟩ /-- An alternate characterization of an extension pair is that every finitely generated partial isomorphism can be extended to include any particular element of the domain. -/ theorem isExtensionPair_iff_exists_embedding_closure_singleton_sup : L.IsExtensionPair M N ↔ ∀ (S : L.Substructure M) (_ : S.FG) (f : S ↪[L] N) (m : M), ∃ g : (closure L {m} ⊔ S : L.Substructure M) ↪[L] N, f = g.comp (Substructure.inclusion le_sup_right) := by refine ⟨fun h S S_FG f m => ?_, fun h ⟨f, f_FG⟩ m => ?_⟩ · obtain ⟨⟨f', hf'⟩, mf', ff'1, ff'2⟩ := h ⟨⟨S, _, f.equivRange⟩, S_FG⟩ m refine ⟨f'.toEmbedding.comp (Substructure.inclusion ?_), ?_⟩ · simp only [sup_le_iff, ff'1, closure_le, singleton_subset_iff, SetLike.mem_coe, mf', and_self] · ext ⟨x, hx⟩ rw [Embedding.subtype_equivRange] at ff'2 simp only [← ff'2, Embedding.comp_apply, Substructure.coe_inclusion, inclusion_mk, Equiv.coe_toEmbedding, coe_subtype, PartialEquiv.toEmbedding_apply] · obtain ⟨f', eq_f'⟩ := h f.dom f_FG f.toEmbedding m refine ⟨⟨⟨closure L {m} ⊔ f.dom, f'.toHom.range, f'.equivRange⟩, (fg_closure_singleton _).sup f_FG⟩, subset_closure.trans (le_sup_left : (closure L) {m} ≤ _) (mem_singleton m), ⟨le_sup_right, Embedding.ext (fun _ => ?_)⟩⟩ rw [PartialEquiv.toEmbedding] at eq_f' simp only [Embedding.comp_apply, Substructure.coe_inclusion, Equiv.coe_toEmbedding, coe_subtype, Embedding.equivRange_apply, eq_f'] namespace IsExtensionPair protected alias ⟨cod, _⟩ := isExtensionPair_iff_cod /-- The cofinal set of finite equivalences with a given element in their domain. -/ def definedAtLeft (h : L.IsExtensionPair M N) (m : M) : Order.Cofinal (FGEquiv L M N) where carrier := {f | m ∈ f.val.dom} isCofinal := fun f => h f m /-- The cofinal set of finite equivalences with a given element in their codomain. -/ def definedAtRight (h : L.IsExtensionPair N M) (n : N) : Order.Cofinal (FGEquiv L M N) where carrier := {f | n ∈ f.val.cod} isCofinal := fun f => h.cod f n end IsExtensionPair /-- For a countably generated structure `M` and a structure `N`, if any partial equivalence between finitely generated substructures can be extended to any element in the domain, then there exists an embedding of `M` in `N`. -/ theorem embedding_from_cg (M_cg : Structure.CG L M) (g : L.FGEquiv M N) (H : L.IsExtensionPair M N) : ∃ f : M ↪[L] N, g ≤ f.toPartialEquiv := by rcases M_cg with ⟨X, _, X_gen⟩ have _ : Countable (↑X : Type _) := by simpa only [countable_coe_iff] have _ : Encodable (↑X : Type _) := Encodable.ofCountable _ let D : X → Order.Cofinal (FGEquiv L M N) := fun x ↦ H.definedAtLeft x let S : ℕ →o M ≃ₚ[L] N := ⟨Subtype.val ∘ (Order.sequenceOfCofinals g D), (Subtype.mono_coe _).comp (Order.sequenceOfCofinals.monotone _ _)⟩ let F := DirectLimit.partialEquivLimit S have _ : X ⊆ F.dom := by intro x hx have := Order.sequenceOfCofinals.encode_mem g D ⟨x, hx⟩ exact dom_le_dom (le_partialEquivLimit S (Encodable.encode (⟨x, hx⟩ : X) + 1)) this have isTop : F.dom = ⊤ := by rwa [← top_le_iff, ← X_gen, Substructure.closure_le] exact ⟨toEmbeddingOfEqTop isTop, by convert (le_partialEquivLimit S 0); apply Embedding.toPartialEquiv_toEmbedding⟩ /-- For two countably generated structure `M` and `N`, if any PartialEquiv between finitely generated substructures can be extended to any element in the domain and to any element in the codomain, then there exists an equivalence between `M` and `N`. -/ theorem equiv_between_cg (M_cg : Structure.CG L M) (N_cg : Structure.CG L N) (g : L.FGEquiv M N) (ext_dom : L.IsExtensionPair M N) (ext_cod : L.IsExtensionPair N M) : ∃ f : M ≃[L] N, g ≤ f.toEmbedding.toPartialEquiv := by rcases M_cg with ⟨X, X_count, X_gen⟩ rcases N_cg with ⟨Y, Y_count, Y_gen⟩ have _ : Countable (↑X : Type _) := by simpa only [countable_coe_iff] have _ : Encodable (↑X : Type _) := Encodable.ofCountable _ have _ : Countable (↑Y : Type _) := by simpa only [countable_coe_iff] have _ : Encodable (↑Y : Type _) := Encodable.ofCountable _ let D : Sum X Y → Order.Cofinal (FGEquiv L M N) := fun p ↦ Sum.recOn p (fun x ↦ ext_dom.definedAtLeft x) (fun y ↦ ext_cod.definedAtRight y) let S : ℕ →o M ≃ₚ[L] N := ⟨Subtype.val ∘ (Order.sequenceOfCofinals g D), (Subtype.mono_coe _).comp (Order.sequenceOfCofinals.monotone _ _)⟩ let F := @DirectLimit.partialEquivLimit L M N _ _ ℕ _ _ _ S have _ : X ⊆ F.dom := by intro x hx have := Order.sequenceOfCofinals.encode_mem g D (Sum.inl ⟨x, hx⟩) exact dom_le_dom (le_partialEquivLimit S (Encodable.encode (Sum.inl (⟨x, hx⟩ : X)) + 1)) this have _ : Y ⊆ F.cod := by intro y hy have := Order.sequenceOfCofinals.encode_mem g D (Sum.inr ⟨y, hy⟩) exact cod_le_cod (le_partialEquivLimit S (Encodable.encode (Sum.inr (⟨y, hy⟩ : Y)) + 1)) this have dom_top : F.dom = ⊤ := by rwa [← top_le_iff, ← X_gen, Substructure.closure_le] have cod_top : F.cod = ⊤ := by rwa [← top_le_iff, ← Y_gen, Substructure.closure_le] refine ⟨toEquivOfEqTop dom_top cod_top, ?_⟩ convert le_partialEquivLimit S 0 rw [toEquivOfEqTop_toEmbedding] apply Embedding.toPartialEquiv_toEmbedding end FGEquiv end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Skolem.lean
import Mathlib.ModelTheory.ElementarySubstructures /-! # Skolem Functions and Downward Löwenheim–Skolem ## Main Definitions - `FirstOrder.Language.skolem₁` is a language consisting of Skolem functions for another language. ## Main Results - `FirstOrder.Language.exists_elementarySubstructure_card_eq` is the Downward Löwenheim–Skolem theorem: If `s` is a set in an `L`-structure `M` and `κ` an infinite cardinal such that `max (#s, L.card) ≤ κ` and `κ ≤ # M`, then `M` has an elementary substructure containing `s` of cardinality `κ`. ## TODO - Use `skolem₁` recursively to construct an actual Skolemization of a language. -/ universe u v w w' namespace FirstOrder namespace Language open Structure Cardinal variable (L : Language.{u, v}) {M : Type w} [Nonempty M] [L.Structure M] /-- A language consisting of Skolem functions for another language. Called `skolem₁` because it is the first step in building a Skolemization of a language. -/ @[simps] def skolem₁ : Language := ⟨fun n => L.BoundedFormula Empty (n + 1), fun _ => Empty⟩ variable {L} theorem card_functions_sum_skolem₁ : #(Σ n, (L.sum L.skolem₁).Functions n) = #(Σ n, L.BoundedFormula Empty (n + 1)) := by simp only [card_functions_sum, skolem₁_Functions, mk_sigma, sum_add_distrib'] conv_lhs => enter [2, 1, i]; rw [lift_id'.{u, v}] rw [add_comm, add_eq_max, max_eq_left] · gcongr with n rw [← lift_le.{_, max u v}, lift_lift, lift_mk_le.{v}] refine ⟨⟨fun f => (func f default).bdEqual (func f default), fun f g h => ?_⟩⟩ rcases h with ⟨rfl, ⟨rfl⟩⟩ rfl · rw [← mk_sigma] exact infinite_iff.1 (Infinite.of_injective (fun n => ⟨n, ⊥⟩) fun x y xy => (Sigma.mk.inj_iff.1 xy).1) theorem card_functions_sum_skolem₁_le : #(Σ n, (L.sum L.skolem₁).Functions n) ≤ max ℵ₀ L.card := by rw [card_functions_sum_skolem₁] trans #(Σ n, L.BoundedFormula Empty n) · exact ⟨⟨Sigma.map Nat.succ fun _ => id, Nat.succ_injective.sigma_map fun _ => Function.injective_id⟩⟩ · refine _root_.trans BoundedFormula.card_le (lift_le.{max u v}.1 ?_) simp only [mk_empty, lift_zero, lift_uzero, zero_add] rfl /-- The structure assigning each function symbol of `L.skolem₁` to a skolem function generated with choice. -/ noncomputable instance skolem₁Structure : L.skolem₁.Structure M := ⟨fun {_} φ x => Classical.epsilon fun a => φ.Realize default (Fin.snoc x a : _ → M), fun {_} r => Empty.elim r⟩ namespace Substructure theorem skolem₁_reduct_isElementary (S : (L.sum L.skolem₁).Substructure M) : (LHom.sumInl.substructureReduct S).IsElementary := by apply (LHom.sumInl.substructureReduct S).isElementary_of_exists intro n φ x a h let φ' : (L.sum L.skolem₁).Functions n := LHom.sumInr.onFunction φ use ⟨funMap φ' ((↑) ∘ x), ?_⟩ · exact Classical.epsilon_spec (p := fun a => BoundedFormula.Realize φ default (Fin.snoc (Subtype.val ∘ x) a)) ⟨a, h⟩ · exact S.fun_mem (LHom.sumInr.onFunction φ) ((↑) ∘ x) (by exact fun i => (x i).2) /-- Any `L.sum L.skolem₁`-substructure is an elementary `L`-substructure. -/ noncomputable def elementarySkolem₁Reduct (S : (L.sum L.skolem₁).Substructure M) : L.ElementarySubstructure M := ⟨LHom.sumInl.substructureReduct S, S.skolem₁_reduct_isElementary⟩ theorem coeSort_elementarySkolem₁Reduct (S : (L.sum L.skolem₁).Substructure M) : (S.elementarySkolem₁Reduct : Type w) = S := rfl end Substructure open Substructure variable (L) (M) instance Substructure.elementarySkolem₁Reduct.instSmall : Small.{max u v} (⊥ : (L.sum L.skolem₁).Substructure M).elementarySkolem₁Reduct := by rw [coeSort_elementarySkolem₁Reduct] infer_instance theorem exists_small_elementarySubstructure : ∃ S : L.ElementarySubstructure M, Small.{max u v} S := ⟨Substructure.elementarySkolem₁Reduct ⊥, inferInstance⟩ variable {M} /-- The **Downward Löwenheim–Skolem theorem** : If `s` is a set in an `L`-structure `M` and `κ` an infinite cardinal such that `max (#s, L.card) ≤ κ` and `κ ≤ # M`, then `M` has an elementary substructure containing `s` of cardinality `κ`. -/ theorem exists_elementarySubstructure_card_eq (s : Set M) (κ : Cardinal.{w'}) (h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} κ) (h3 : Cardinal.lift.{w'} L.card ≤ Cardinal.lift.{max u v} κ) (h4 : Cardinal.lift.{w} κ ≤ Cardinal.lift.{w'} #M) : ∃ S : L.ElementarySubstructure M, s ⊆ S ∧ Cardinal.lift.{w'} #S = Cardinal.lift.{w} κ := by obtain ⟨s', hs'⟩ := Cardinal.le_mk_iff_exists_set.1 h4 rw [← aleph0_le_lift.{_, w}] at h1 rw [← hs'] at h1 h2 ⊢ refine ⟨elementarySkolem₁Reduct (closure (L.sum L.skolem₁) (s ∪ Equiv.ulift '' s')), (s.subset_union_left).trans subset_closure, ?_⟩ have h := mk_image_eq_lift _ s' Equiv.ulift.injective rw [lift_umax.{w, w'}, lift_id'.{w, w'}] at h rw [coeSort_elementarySkolem₁Reduct, ← h, lift_inj] refine le_antisymm (lift_le.1 (lift_card_closure_le.trans ?_)) (mk_le_mk_of_subset ((s.subset_union_right).trans subset_closure)) rw [max_le_iff, aleph0_le_lift, ← aleph0_le_lift.{_, w'}, h, add_eq_max, max_le_iff, lift_le] · refine ⟨h1, (mk_union_le _ _).trans ?_, (lift_le.2 card_functions_sum_skolem₁_le).trans ?_⟩ · rw [← lift_le, lift_add, h, add_comm, add_eq_max h1] exact max_le le_rfl h2 · rw [lift_max, lift_aleph0, max_le_iff, aleph0_le_lift, and_comm, ← lift_le.{w'}, lift_lift, lift_lift, ← aleph0_le_lift, h] refine ⟨?_, h1⟩ rw [← lift_lift.{w', w}] refine _root_.trans (lift_le.{w}.2 h3) ?_ rw [lift_lift, ← lift_lift.{w, max u v}, ← hs', ← h, lift_lift] · refine _root_.trans ?_ (lift_le.2 (mk_le_mk_of_subset Set.subset_union_right)) rw [aleph0_le_lift, ← aleph0_le_lift, h] exact h1 end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Fraisse.lean
import Mathlib.ModelTheory.FinitelyGenerated import Mathlib.ModelTheory.PartialEquiv import Mathlib.ModelTheory.Bundled import Mathlib.Algebra.Order.Archimedean.Basic /-! # Fraïssé Classes and Fraïssé Limits This file pertains to the ages of countable first-order structures. The age of a structure is the class of all finitely-generated structures that embed into it. Of particular interest are Fraïssé classes, which are exactly the ages of countable ultrahomogeneous structures. To each is associated a unique (up to nonunique isomorphism) Fraïssé limit - the countable ultrahomogeneous structure with that age. ## Main Definitions - `FirstOrder.Language.age` is the class of finitely-generated structures that embed into a particular structure. - A class `K` is `FirstOrder.Language.Hereditary` when all finitely-generated structures that embed into structures in `K` are also in `K`. - A class `K` has `FirstOrder.Language.JointEmbedding` when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. - A class `K` has `FirstOrder.Language.Amalgamation` when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. - `FirstOrder.Language.IsFraisse` indicates that a class is nonempty, essentially countable, and satisfies the hereditary, joint embedding, and amalgamation properties. - `FirstOrder.Language.IsFraisseLimit` indicates that a structure is a Fraïssé limit for a given class. ## Main Results - We show that the age of any structure is isomorphism-invariant and satisfies the hereditary and joint-embedding properties. - `FirstOrder.Language.age.countable_quotient` shows that the age of any countable structure is essentially countable. - `FirstOrder.Language.exists_countable_is_age_of_iff` gives necessary and sufficient conditions for a class to be the age of a countable structure in a language with countably many functions. - `FirstOrder.Language.IsFraisseLimit.nonempty_equiv` shows that any class which is Fraïssé has at most one Fraïssé limit up to equivalence. - `FirstOrder.Language.empty.isFraisseLimit_of_countable_infinite` shows that any countably infinite structure in the empty language is a Fraïssé limit of the class of finite structures. - `FirstOrder.Language.empty.isFraisse_finite` shows that the class of finite structures in the empty language is Fraïssé. ## Implementation Notes - Classes of structures are formalized with `Set (Bundled L.Structure)`. - Some results pertain to countable limit structures, others to countably-generated limit structures. In the case of a language with countably many function symbols, these are equivalent. ## References - [W. Hodges, *A Shorter Model Theory*][Hodges97] - [K. Tent, M. Ziegler, *A Course in Model Theory*][Tent_Ziegler] ## TODO - Show existence of Fraïssé limits -/ universe u v w w' open scoped FirstOrder open Set CategoryTheory namespace FirstOrder namespace Language open Structure Substructure variable (L : Language.{u, v}) /-! ### The Age of a Structure and Fraïssé Classes -/ /-- The age of a structure `M` is the class of finitely-generated structures that embed into it. -/ def age (M : Type w) [L.Structure M] : Set (Bundled.{w} L.Structure) := {N | Structure.FG L N ∧ Nonempty (N ↪[L] M)} variable {L} variable (K : Set (Bundled.{w} L.Structure)) /-- A class `K` has the hereditary property when all finitely-generated structures that embed into structures in `K` are also in `K`. -/ def Hereditary : Prop := ∀ M : Bundled.{w} L.Structure, M ∈ K → L.age M ⊆ K /-- A class `K` has the joint embedding property when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. -/ def JointEmbedding : Prop := DirectedOn (fun M N : Bundled.{w} L.Structure => Nonempty (M ↪[L] N)) K /-- A class `K` has the amalgamation property when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. -/ def Amalgamation : Prop := ∀ (M N P : Bundled.{w} L.Structure) (MN : M ↪[L] N) (MP : M ↪[L] P), M ∈ K → N ∈ K → P ∈ K → ∃ (Q : Bundled.{w} L.Structure) (NQ : N ↪[L] Q) (PQ : P ↪[L] Q), Q ∈ K ∧ NQ.comp MN = PQ.comp MP /-- A Fraïssé class is a nonempty, essentially countable class of structures satisfying the hereditary, joint embedding, and amalgamation properties. -/ class IsFraisse : Prop where is_nonempty : K.Nonempty FG : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M is_essentially_countable : (Quotient.mk' '' K).Countable hereditary : Hereditary K jointEmbedding : JointEmbedding K amalgamation : Amalgamation K variable {K} (L) (M : Type w) [Structure L M] theorem age.is_equiv_invariant (N P : Bundled.{w} L.Structure) (h : Nonempty (N ≃[L] P)) : N ∈ L.age M ↔ P ∈ L.age M := and_congr h.some.fg_iff ⟨Nonempty.map fun x => Embedding.comp x h.some.symm.toEmbedding, Nonempty.map fun x => Embedding.comp x h.some.toEmbedding⟩ variable {L} {M} {N : Type w} [Structure L N] theorem Embedding.age_subset_age (MN : M ↪[L] N) : L.age M ⊆ L.age N := fun _ => And.imp_right (Nonempty.map MN.comp) theorem Equiv.age_eq_age (MN : M ≃[L] N) : L.age M = L.age N := le_antisymm MN.toEmbedding.age_subset_age MN.symm.toEmbedding.age_subset_age theorem Structure.FG.mem_age_of_equiv {M N : Bundled L.Structure} (h : Structure.FG L M) (MN : Nonempty (M ≃[L] N)) : N ∈ L.age M := ⟨MN.some.fg_iff.1 h, ⟨MN.some.symm.toEmbedding⟩⟩ theorem Hereditary.is_equiv_invariant_of_fg (h : Hereditary K) (fg : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) (M N : Bundled.{w} L.Structure) (hn : Nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K := ⟨fun MK => h M MK ((fg M MK).mem_age_of_equiv hn), fun NK => h N NK ((fg N NK).mem_age_of_equiv ⟨hn.some.symm⟩)⟩ theorem IsFraisse.is_equiv_invariant [h : IsFraisse K] {M N : Bundled.{w} L.Structure} (hn : Nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K := h.hereditary.is_equiv_invariant_of_fg h.FG M N hn variable (M) theorem age.nonempty : (L.age M).Nonempty := ⟨Bundled.of (Substructure.closure L (∅ : Set M)), (fg_iff_structure_fg _).1 (fg_closure Set.finite_empty), ⟨Substructure.subtype _⟩⟩ theorem age.hereditary : Hereditary (L.age M) := fun _ hN _ hP => hN.2.some.age_subset_age hP theorem age.jointEmbedding : JointEmbedding (L.age M) := fun _ hN _ hP => ⟨Bundled.of (↥(hN.2.some.toHom.range ⊔ hP.2.some.toHom.range)), ⟨(fg_iff_structure_fg _).1 ((hN.1.range hN.2.some.toHom).sup (hP.1.range hP.2.some.toHom)), ⟨Substructure.subtype _⟩⟩, ⟨Embedding.comp (inclusion le_sup_left) hN.2.some.equivRange.toEmbedding⟩, ⟨Embedding.comp (inclusion le_sup_right) hP.2.some.equivRange.toEmbedding⟩⟩ variable {M} in theorem age.fg_substructure {S : L.Substructure M} (fg : S.FG) : Bundled.mk S ∈ L.age M := by exact ⟨(Substructure.fg_iff_structure_fg _).1 fg, ⟨subtype _⟩⟩ /-- Any class in the age of a structure has a representative which is a finitely generated substructure. -/ theorem age.has_representative_as_substructure : ∀ C ∈ Quotient.mk' '' L.age M, ∃ V : {V : L.Substructure M // FG V}, ⟦Bundled.mk V⟧ = C := by rintro _ ⟨N, ⟨N_fg, ⟨N_incl⟩⟩, N_eq⟩ refine N_eq.symm ▸ ⟨⟨N_incl.toHom.range, ?_⟩, Quotient.sound ⟨N_incl.equivRange.symm⟩⟩ exact FG.range N_fg (Embedding.toHom N_incl) /-- The age of a countable structure is essentially countable (has countably many isomorphism classes). -/ theorem age.countable_quotient [h : Countable M] : (Quotient.mk' '' L.age M).Countable := by classical refine (congr_arg _ (Set.ext <| Quotient.forall.2 fun N => ?_)).mp (countable_range fun s : Finset M => ⟦⟨closure L (s : Set M), inferInstance⟩⟧) constructor · rintro ⟨s, hs⟩ use Bundled.of (closure L (s : Set M)) exact ⟨⟨(fg_iff_structure_fg _).1 (fg_closure s.finite_toSet), ⟨Substructure.subtype _⟩⟩, hs⟩ · simp only [mem_range, Quotient.eq] rintro ⟨P, ⟨⟨s, hs⟩, ⟨PM⟩⟩, hP2⟩ refine ⟨s.image PM, Setoid.trans (b := P) ?_ <| Quotient.exact hP2⟩ rw [← Embedding.coe_toHom, Finset.coe_image, closure_image PM.toHom, hs, ← Hom.range_eq_map] exact ⟨PM.equivRange.symm⟩ -- This is not a simp-lemma because it does not apply to itself. /-- The age of a direct limit of structures is the union of the ages of the structures. -/ theorem age_directLimit {ι : Type w} [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι] (G : ι → Type max w w') [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j) [DirectedSystem G fun i j h => f i j h] : L.age (DirectLimit G f) = ⋃ i : ι, L.age (G i) := by classical ext M simp only [mem_iUnion] constructor · rintro ⟨Mfg, ⟨e⟩⟩ obtain ⟨s, hs⟩ := Mfg.range e.toHom let out := @Quotient.out _ (DirectLimit.setoid G f) obtain ⟨i, hi⟩ := Finset.exists_le (s.image (Sigma.fst ∘ out)) have e' := (DirectLimit.of L ι G f i).equivRange.symm.toEmbedding refine ⟨i, Mfg, ⟨e'.comp ((Substructure.inclusion ?_).comp e.equivRange.toEmbedding)⟩⟩ rw [← hs, closure_le] intro x hx refine ⟨f (out x).1 i (hi (out x).1 (Finset.mem_image_of_mem _ hx)) (out x).2, ?_⟩ rw [Embedding.coe_toHom, DirectLimit.of_apply, @Quotient.mk_eq_iff_out _ (_), DirectLimit.equiv_iff G f (le_refl _) (hi (out x).1 (Finset.mem_image_of_mem _ hx)), DirectedSystem.map_self] · rintro ⟨i, Mfg, ⟨e⟩⟩ exact ⟨Mfg, ⟨Embedding.comp (DirectLimit.of L ι G f i) e⟩⟩ /-- Sufficient conditions for a class to be the age of a countably-generated structure. -/ theorem exists_cg_is_age_of (hn : K.Nonempty) (hc : (Quotient.mk' '' K).Countable) (fg : ∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) (hp : Hereditary K) (jep : JointEmbedding K) : ∃ M : Bundled.{w} L.Structure, Structure.CG L M ∧ L.age M = K := by obtain ⟨F, hF⟩ := hc.exists_eq_range (hn.image _) simp only [Set.ext_iff, Quotient.forall, mem_image, mem_range] at hF simp_rw [Quotient.eq_mk_iff_out] at hF have hF' : ∀ n : ℕ, (F n).out ∈ K := by intro n obtain ⟨P, hP1, hP2⟩ := (hF (F n).out).2 ⟨n, Setoid.refl _⟩ -- Porting note: fix hP2 because `Quotient.out (Quotient.mk' x) ≈ a` was not simplified -- to `x ≈ a` in hF replace hP2 := Setoid.trans (Setoid.symm (Quotient.mk_out P)) hP2 exact (hp.is_equiv_invariant_of_fg fg _ _ hP2).1 hP1 choose P hPK hP hFP using fun (N : K) (n : ℕ) => jep N N.2 (F (n + 1)).out (hF' _) let G : ℕ → K := @Nat.rec (fun _ => K) ⟨(F 0).out, hF' 0⟩ fun n N => ⟨P N n, hPK N n⟩ -- Porting note: was -- let f : ∀ i j, i ≤ j → G i ↪[L] G j := DirectedSystem.natLeRec fun n => (hP _ n).some let f : ∀ (i j : ℕ), i ≤ j → (G i).val ↪[L] (G j).val := by refine DirectedSystem.natLERec (G' := fun i => (G i).val) (L := L) ?_ dsimp only [G] exact fun n => (hP _ n).some have : DirectedSystem (fun n ↦ (G n).val) fun i j h ↦ ↑(f i j h) := by dsimp [f, G]; infer_instance refine ⟨Bundled.of (@DirectLimit L _ _ (fun n ↦ (G n).val) _ f _ _), ?_, ?_⟩ · exact DirectLimit.cg _ (fun n => (fg _ (G n).2).cg) · refine (age_directLimit (fun n ↦ (G n).val) f).trans (subset_antisymm (iUnion_subset fun n N hN => hp (G n).val (G n).2 hN) fun N KN => ?_) have : Quotient.out (Quotient.mk' N) ≈ N := Quotient.eq_mk_iff_out.mp rfl obtain ⟨n, ⟨e⟩⟩ := (hF N).1 ⟨N, KN, this⟩ refine mem_iUnion_of_mem n ⟨fg _ KN, ⟨Embedding.comp ?_ e.symm.toEmbedding⟩⟩ rcases n with - | n · dsimp [G]; exact Embedding.refl _ _ · dsimp [G]; exact (hFP _ n).some theorem exists_countable_is_age_of_iff [Countable (Σ l, L.Functions l)] : (∃ M : Bundled.{w} L.Structure, Countable M ∧ L.age M = K) ↔ K.Nonempty ∧ (∀ M N : Bundled.{w} L.Structure, Nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) ∧ (Quotient.mk' '' K).Countable ∧ (∀ M : Bundled.{w} L.Structure, M ∈ K → Structure.FG L M) ∧ Hereditary K ∧ JointEmbedding K := by constructor · rintro ⟨M, h1, h2, rfl⟩ refine ⟨age.nonempty M, age.is_equiv_invariant L M, age.countable_quotient M, fun N hN => hN.1, age.hereditary M, age.jointEmbedding M⟩ · rintro ⟨Kn, _, cq, hfg, hp, jep⟩ obtain ⟨M, hM, rfl⟩ := exists_cg_is_age_of Kn cq hfg hp jep exact ⟨M, Structure.cg_iff_countable.1 hM, rfl⟩ variable (L) /-- A structure `M` is ultrahomogeneous if every embedding of a finitely generated substructure into `M` extends to an automorphism of `M`. -/ def IsUltrahomogeneous : Prop := ∀ (S : L.Substructure M) (_ : S.FG) (f : S ↪[L] M), ∃ g : M ≃[L] M, f = g.toEmbedding.comp S.subtype variable {L} (K) /-- A structure `M` is a Fraïssé limit for a class `K` if it is countably generated, ultrahomogeneous, and has age `K`. -/ structure IsFraisseLimit [Countable (Σ l, L.Functions l)] [Countable M] : Prop where protected ultrahomogeneous : IsUltrahomogeneous L M protected age : L.age M = K variable {M} /-- Any embedding from a finitely generated `S` to an ultrahomogeneous structure `M` can be extended to an embedding from any structure with an embedding to `M`. -/ theorem IsUltrahomogeneous.extend_embedding (M_homog : L.IsUltrahomogeneous M) {S : Type*} [L.Structure S] (S_FG : FG L S) {T : Type*} [L.Structure T] [h : Nonempty (T ↪[L] M)] (f : S ↪[L] M) (g : S ↪[L] T) : ∃ f' : T ↪[L] M, f = f'.comp g := by let ⟨r⟩ := h let s := r.comp g let ⟨t, eq⟩ := M_homog s.toHom.range (S_FG.range s.toHom) (f.comp s.equivRange.symm.toEmbedding) use t.toEmbedding.comp r change _ = t.toEmbedding.comp s ext x have eq' := congr_fun (congr_arg DFunLike.coe eq) ⟨s x, Hom.mem_range.2 ⟨x, rfl⟩⟩ simp only [Embedding.comp_apply, coe_subtype] at eq' simp only [Embedding.comp_apply, ← eq', Equiv.coe_toEmbedding, EmbeddingLike.apply_eq_iff_eq] apply (Embedding.equivRange (Embedding.comp r g)).injective ext simp only [Equiv.apply_symm_apply, Embedding.equivRange_apply, s] /-- A countably generated structure is ultrahomogeneous if and only if any equivalence between finitely generated substructures can be extended to any element in the domain. -/ theorem isUltrahomogeneous_iff_IsExtensionPair (M_CG : CG L M) : L.IsUltrahomogeneous M ↔ L.IsExtensionPair M M := by constructor · intro M_homog ⟨f, f_FG⟩ m let S := f.dom ⊔ closure L {m} have dom_le_S : f.dom ≤ S := le_sup_left let ⟨f', eq_f'⟩ := M_homog.extend_embedding (f.dom.fg_iff_structure_fg.1 f_FG) ((subtype _).comp f.toEquiv.toEmbedding) (inclusion dom_le_S) (h := ⟨subtype _⟩) refine ⟨⟨⟨S, f'.toHom.range, f'.equivRange⟩, f_FG.sup (fg_closure_singleton _)⟩, subset_closure.trans (le_sup_right : _ ≤ S) (mem_singleton m), ⟨dom_le_S, ?_⟩⟩ ext simp only [Embedding.comp_apply, Equiv.coe_toEmbedding, coe_subtype, eq_f', Embedding.equivRange_apply, Substructure.coe_inclusion] · intro h S S_FG f let ⟨g, ⟨dom_le_dom, eq⟩⟩ := equiv_between_cg M_CG M_CG ⟨⟨S, f.toHom.range, f.equivRange⟩, S_FG⟩ h h use g simp only [Embedding.subtype_equivRange] at eq rw [← eq] ext rfl theorem IsUltrahomogeneous.amalgamation_age (h : L.IsUltrahomogeneous M) : Amalgamation (L.age M) := by rintro N P Q NP NQ ⟨Nfg, ⟨-⟩⟩ ⟨Pfg, ⟨PM⟩⟩ ⟨Qfg, ⟨QM⟩⟩ obtain ⟨g, hg⟩ := h (PM.comp NP).toHom.range (Nfg.range _) ((QM.comp NQ).comp (PM.comp NP).equivRange.symm.toEmbedding) let s := (g.toHom.comp PM.toHom).range ⊔ QM.toHom.range refine ⟨Bundled.of s, Embedding.comp (Substructure.inclusion le_sup_left) (g.toEmbedding.comp PM).equivRange.toEmbedding, Embedding.comp (Substructure.inclusion le_sup_right) QM.equivRange.toEmbedding, ⟨(fg_iff_structure_fg _).1 (FG.sup (Pfg.range _) (Qfg.range _)), ⟨Substructure.subtype _⟩⟩, ?_⟩ ext n apply Subtype.ext have hgn := (Embedding.ext_iff.1 hg) ((PM.comp NP).equivRange n) simp only [Embedding.comp_apply, Equiv.coe_toEmbedding, Equiv.symm_apply_apply, Substructure.coe_subtype, Embedding.equivRange_apply] at hgn simp only [Embedding.comp_apply, Equiv.coe_toEmbedding] erw [Substructure.coe_inclusion, Substructure.coe_inclusion] simp only [Embedding.equivRange_apply, hgn] -- This used to be `simp only [...]` before https://github.com/leanprover/lean4/pull/2644 erw [Embedding.comp_apply, Equiv.coe_toEmbedding, Embedding.equivRange_apply] simp theorem IsUltrahomogeneous.age_isFraisse [Countable M] (h : L.IsUltrahomogeneous M) : IsFraisse (L.age M) := ⟨age.nonempty M, fun _ hN => hN.1, age.countable_quotient M, age.hereditary M, age.jointEmbedding M, h.amalgamation_age⟩ namespace IsFraisseLimit /-- If a class has a Fraïssé limit, it must be Fraïssé. -/ theorem isFraisse [Countable (Σ l, L.Functions l)] [Countable M] (h : IsFraisseLimit K M) : IsFraisse K := (congr rfl h.age).mp h.ultrahomogeneous.age_isFraisse variable {K} {N : Type w} [L.Structure N] variable [Countable (Σ l, L.Functions l)] [Countable M] [Countable N] variable (hM : IsFraisseLimit K M) (hN : IsFraisseLimit K N) include hM hN protected theorem isExtensionPair : L.IsExtensionPair M N := by intro ⟨f, f_FG⟩ m let S := f.dom ⊔ closure L {m} have S_FG : S.FG := f_FG.sup (Substructure.fg_closure_singleton _) have S_in_age_N : ⟨S, inferInstance⟩ ∈ L.age N := by rw [hN.age, ← hM.age] exact ⟨(fg_iff_structure_fg S).1 S_FG, ⟨subtype _⟩⟩ haveI nonempty_S_N : Nonempty (S ↪[L] N) := S_in_age_N.2 let ⟨g, g_eq⟩ := hN.ultrahomogeneous.extend_embedding (f.dom.fg_iff_structure_fg.1 f_FG) ((subtype f.cod).comp f.toEquiv.toEmbedding) (inclusion (le_sup_left : _ ≤ S)) refine ⟨⟨⟨S, g.toHom.range, g.equivRange⟩, S_FG⟩, subset_closure.trans (le_sup_right : _ ≤ S) (mem_singleton m), ⟨le_sup_left, ?_⟩⟩ ext simp [S, g_eq] /-- The Fraïssé limit of a class is unique, in that any two Fraïssé limits are isomorphic. -/ theorem nonempty_equiv : Nonempty (M ≃[L] N) := by let S : L.Substructure M := ⊥ have S_fg : FG L S := (fg_iff_structure_fg _).1 Substructure.fg_bot obtain ⟨_, ⟨emb_S : S ↪[L] N⟩⟩ : ⟨S, inferInstance⟩ ∈ L.age N := by rw [hN.age, ← hM.age] exact ⟨S_fg, ⟨subtype _⟩⟩ let v : M ≃ₚ[L] N := { dom := S cod := emb_S.toHom.range toEquiv := emb_S.equivRange } exact ⟨Exists.choose (equiv_between_cg cg_of_countable cg_of_countable ⟨v, ((Substructure.fg_iff_structure_fg _).2 S_fg)⟩ (hM.isExtensionPair hN) (hN.isExtensionPair hM))⟩ end IsFraisseLimit namespace empty /-- Any countable infinite structure in the empty language is a Fraïssé limit of the class of finite structures. -/ theorem isFraisseLimit_of_countable_infinite (M : Type*) [Countable M] [Infinite M] [Language.empty.Structure M] : IsFraisseLimit { S : Bundled Language.empty.Structure | Finite S } M where age := by ext S simp only [age, Structure.fg_iff_finite, mem_setOf_eq, and_iff_left_iff_imp] intro hS simp ultrahomogeneous S hS f := by classical have : Finite S := hS.finite have : Infinite { x // x ∉ S } := ((Set.toFinite _).infinite_compl).to_subtype have : Finite f.toHom.range := (((Substructure.fg_iff_structure_fg S).1 hS).range _).finite have : Infinite { x // x ∉ f.toHom.range } := ((Set.toFinite _).infinite_compl ).to_subtype refine ⟨StrongHomClass.toEquiv (f.equivRange.subtypeCongr nonempty_equiv_of_countable.some), ?_⟩ ext x simp [Equiv.subtypeCongr] /-- The class of finite structures in the empty language is Fraïssé. -/ theorem isFraisse_finite : IsFraisse { S : Bundled.{w} Language.empty.Structure | Finite S } := by have : Language.empty.Structure (ULift ℕ : Type w) := emptyStructure exact (isFraisseLimit_of_countable_infinite (ULift ℕ)).isFraisse end empty end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Semantics.lean
import Mathlib.Data.Finset.Basic import Mathlib.ModelTheory.Syntax import Mathlib.Data.List.ProdSigma /-! # Basics on First-Order Semantics This file defines the interpretations of first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions - `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at variables `v`. - `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded formula `φ` evaluated at tuples of variables `v` and `xs`. - `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ` evaluated at variables `v`. - `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ` evaluated in the structure `M`. Also denoted `M ⊨ φ`. - `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`. ## Main Results - Several results in this file show that syntactic constructions such as `relabel`, `castLE`, `liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas, sentences, and theories. ## Implementation Notes - `BoundedFormula` uses a locally nameless representation with bound variables as well-scoped de Bruijn levels. See the implementation note in `Syntax.lean` for details. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {L' : Language} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder Cardinal open Structure Fin namespace Term /-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/ def realize (v : α → M) : ∀ _t : L.Term α, M | var k => v k | func f ts => funMap f fun i => (ts i).realize v @[simp] theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl @[simp] theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) : realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl @[simp] theorem realize_function_term {n} (v : Fin n → M) (f : L.Functions n) : f.term.realize v = funMap f v := by rfl @[simp] theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} : (t.relabel g).realize v = t.realize (v ∘ g) := by induction t with | var => rfl | func f ts ih => simp [ih] @[simp] theorem realize_liftAt {n n' m : ℕ} {t : L.Term (α ⊕ (Fin n))} {v : α ⊕ (Fin (n + n')) → M} : (t.liftAt n' m).realize v = t.realize (v ∘ Sum.map id fun i : Fin _ => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := realize_relabel @[simp] theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c := funMap_eq_coe_constants @[simp] theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} : (f.apply₁ t).realize v = funMap f ![t.realize v] := by rw [Functions.apply₁, Term.realize] refine congr rfl (funext fun i => ?_) simp only [Matrix.cons_val_fin_one] @[simp] theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} : (f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by rw [Functions.apply₂, Term.realize] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a := rfl @[simp] theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} : (t.subst tf).realize v = t.realize fun a => (tf a).realize v := by induction t with | var => rfl | func _ _ ih => simp [ih] theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {f : t.varFinset → β} {v : β → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) : (t.restrictVar f).realize v = t.realize v' := by induction t with | var => simp [restrictVar, hv'] | func _ _ ih => exact congr rfl (funext fun i => ih i ((by simp [Function.comp_apply, hv']))) /-- A special case of `realize_restrictVar`, included because we can add the `simp` attribute to it -/ @[simp] theorem realize_restrictVar' [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s) {v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := realize_restrictVar _ (by simp) theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {f : t.varFinsetLeft → β} {xs : β ⊕ γ → M} (xs' : α → M) (hxs' : ∀ a, xs (Sum.inl (f a)) = xs' a) : (t.restrictVarLeft f).realize xs = t.realize (Sum.elim xs' (xs ∘ Sum.inr)) := by induction t with | var a => cases a <;> simp [restrictVarLeft, hxs'] | func _ _ ih => exact congr rfl (funext fun i => ih i (by simp [hxs'])) /-- A special case of `realize_restrictVarLeft`, included because we can add the `simp` attribute to it -/ @[simp] theorem realize_restrictVarLeft' [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {s : Set α} (h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} : (t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) = t.realize (Sum.elim v xs) := realize_restrictVarLeft _ (by simp) @[simp] theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L[[α]].Term β} {v : β → M} : t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by induction t with | var => simp | @func n f ts ih => cases n · cases f · simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sumInl] · simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants] rfl · obtain - | f := f · simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sumInl] · exact isEmptyElim f @[simp] theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L.Term (α ⊕ β)} {v : β → M} : t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by induction t with | var ab => rcases ab with a | b <;> simp [Language.con] | func f ts ih => simp only [realize, constantsOn, constantsOnFunc, ih, varsToConstants] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sumInl] theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (β ⊕ (Fin n))} {v : β → M} {xs : Fin n → M} : (constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) = t.realize (Sum.elim v xs) := by simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply, constantsVarsEquiv_apply, relabelEquiv_symm_apply] refine _root_.trans ?_ realize_constantsToVars congr 1; funext x -- Note: was previously rcongr x rcases x with (a | (b | i)) <;> simp end Term namespace LHom @[simp] theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α) (v : α → M) : (φ.onTerm t).realize v = t.realize v := by induction t with | var => rfl | func f ts ih => simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih] end LHom @[simp] theorem HomClass.realize_term {F : Type*} [FunLike F M N] [HomClass L F M N] (g : F) {t : L.Term α} {v : α → M} : t.realize (g ∘ v) = g (t.realize v) := by induction t · rfl · rw [Term.realize, Term.realize, HomClass.map_fun] refine congr rfl ?_ ext x simp [*] variable {n : ℕ} namespace BoundedFormula open Term /-- A bounded formula can be evaluated as true or false by giving values to each free and bound variable. -/ def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop | _, falsum, _v, _xs => False | _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) | _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs) | _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs | _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x) variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ} variable {v : α → M} {xs : Fin l → M} @[simp] theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False := Iff.rfl @[simp] theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs := Iff.rfl @[simp] theorem realize_bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin l))) : (t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) := Iff.rfl @[simp] theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top] @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by simp [Realize] @[simp] theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by induction l with | nil => simp | cons φ l ih => simp [ih] @[simp] theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by simp only [Realize] /-- List.foldr on BoundedFormula.imp gives a big "And" of input conditions. -/ theorem realize_foldr_imp {k : ℕ} (l : List (L.BoundedFormula α k)) (f : L.BoundedFormula α k) : ∀ (v : α → M) xs, (l.foldr BoundedFormula.imp f).Realize v xs = ((∀ i ∈ l, i.Realize v xs) → f.Realize v xs) := by intro v xs induction l next => simp next f' _ _ => by_cases f'.Realize v xs <;> simp [*] @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} : (R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) := Iff.rfl @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.boundedFormula₂ t₁ t₂).Realize v xs ↔ RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by simp only [max] tauto @[simp] theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by induction l with | nil => simp | cons φ l ih => simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or, exists_eq_left] @[simp] theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) := Iff.rfl @[simp] theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by rw [BoundedFormula.ex, realize_not, realize_all, not_forall] simp_rw [realize_not, Classical.not_not] @[simp] theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by simp only [BoundedFormula.iff, realize_inf, realize_imp, ← iff_def] theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m} {v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ Fin.cast h) := by subst h simp only [castLE_rfl, cast_refl, Function.comp_id] theorem realize_mapTermRel_id [L'.Structure M] {ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M} {v' : β → M} {xs : Fin n → M} (h1 : ∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs : Fin n → M), (ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs)) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) : (φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by induction φ with | falsum => rfl | equal => simp [mapTermRel, Realize, h1] | rel => simp [mapTermRel, Realize, h1, h2] | imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2] | all _ ih => simp only [mapTermRel, Realize, ih, id] theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ} {ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (k + n)))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} (v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M) (h1 : ∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs' : Fin (k + n) → M), (ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _))) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) (hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) : (φ.mapTermRel ft fr fun _ => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔ φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by induction φ with | falsum => rfl | equal => simp [mapTermRel, Realize, h1] | rel => simp [mapTermRel, Realize, h1, h2] | imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2] | all _ ih => simp [mapTermRel, Realize, ih, hv] @[simp] theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → β ⊕ (Fin m)} {v : β → M} {xs : Fin (m + n) → M} : (φ.relabel g).Realize v xs ↔ φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by apply realize_mapTermRel_add_castLe <;> simp theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M} (hmn : m + n' ≤ n + 1) : (φ.liftAt n' m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by rw [liftAt] induction φ with | falsum => simp [mapTermRel, Realize] | equal => simp [mapTermRel, Realize, Sum.elim_comp_map] | rel => simp [mapTermRel, Realize, Sum.elim_comp_map] | imp _ _ ih1 ih2 => simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn] | @all k _ ih3 => have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc] simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)] refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_))) · simp only [Function.comp_apply, val_last, snoc_last] refine (congr rfl (Fin.ext ?_)).trans (snoc_last _ _) split_ifs <;> dsimp; cutsat · simp only [Function.comp_apply, Fin.snoc_castSucc] refine (congr rfl (Fin.ext ?_)).trans (snoc_castSucc _ _ _) simp only [coe_castSucc, coe_cast] split_ifs <;> simp theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} (hmn : m ≤ n) : (φ.liftAt 1 m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by simp [realize_liftAt, hmn, castSucc] @[simp] theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by rw [realize_liftAt_one (refl n), iff_eq_eq] refine congr rfl (congr rfl (funext fun i => ?_)) rw [if_pos i.is_lt] @[simp] theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} : (φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs := realize_mapTermRel_id (fun n t x => by rw [Term.realize_subst] rcongr a cases a · simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl] · rfl) (by simp) theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {f : φ.freeVarFinset → β} {v : β → M} {xs : Fin n → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) : (φ.restrictFreeVar f).Realize v xs ↔ φ.Realize v' xs := by induction φ with | falsum => rfl | equal => simp only [Realize, restrictFreeVar, freeVarFinset.eq_2] rw [realize_restrictVarLeft v' (by simp [hv']), realize_restrictVarLeft v' (by simp [hv'])] simp | rel => simp only [Realize, freeVarFinset.eq_3, restrictFreeVar] congr! rw [realize_restrictVarLeft v' (by simp [hv'])] simp | imp _ _ ih1 ih2 => simp only [Realize, restrictFreeVar, freeVarFinset.eq_4] rw [ih1, ih2] <;> simp [hv'] | all _ ih3 => simp only [restrictFreeVar, Realize] refine forall_congr' (fun _ => ?_) rw [ih3]; simp [hv'] /-- A special case of `realize_restrictFreeVar`, included because we can add the `simp` attribute to it -/ @[simp] theorem realize_restrictFreeVar' [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α} (h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} : (φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs := realize_restrictFreeVar _ (by simp) theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} : (constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_ -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [← (lhomWithConstants L α).map_onRelation (Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs] rcongr obtain - | R := R · simp · exact isEmptyElim R @[simp] theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M} {xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl] refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl simp only [relabelEquiv_apply, Term.realize_relabel] refine congr (congr rfl ?_) rfl ext (i | i) <;> rfl variable [Nonempty M] theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by simp end BoundedFormula namespace LHom open BoundedFormula @[simp] theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ} (ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} : (φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by induction ψ with | falsum => rfl | equal => simp only [onBoundedFormula, realize_bdEqual, realize_onTerm]; rfl | rel => simp only [onBoundedFormula, realize_rel, LHom.map_onRelation, Function.comp_apply, realize_onTerm] rfl | imp _ _ ih1 ih2 => simp only [onBoundedFormula, ih1, ih2, realize_imp] | all _ ih3 => simp only [onBoundedFormula, ih3, realize_all] end LHom namespace Formula /-- A formula can be evaluated as true or false by giving values to each free variable. -/ nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop := φ.Realize v default variable {φ ψ : L.Formula α} {v : α → M} @[simp] theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v := Iff.rfl @[simp] theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False := Iff.rfl @[simp] theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True := BoundedFormula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v := BoundedFormula.realize_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v := BoundedFormula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} : (R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v := BoundedFormula.realize_rel.trans (by simp) @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by rw [Relations.formula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by rw [Relations.formula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v := BoundedFormula.realize_sup @[simp] theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) := BoundedFormula.realize_iff @[simp] theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} : (φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero] exact congr rfl (funext finZeroElim) theorem realize_relabel_sumInr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} : (BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero, cast_refl, Function.comp_id, Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default] @[simp] theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} : (t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize] @[simp] theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} : (Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ] rw [eq_comm] theorem boundedFormula_realize_eq_realize (φ : L.Formula α) (x : α → M) (y : Fin 0 → M) : BoundedFormula.Realize φ x y ↔ φ.Realize x := by rw [Formula.Realize, iff_iff_eq] congr ext i; exact Fin.elim0 i end Formula @[simp] theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) {v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v := φ.realize_onBoundedFormula ψ @[simp] theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by ext simp variable (M) /-- A sentence can be evaluated as true or false in a structure. -/ nonrec def Sentence.Realize (φ : L.Sentence) : Prop := φ.Realize (default : _ → M) -- input using \|= or \vDash, but not using \models @[inherit_doc Sentence.Realize] infixl:51 " ⊨ " => Sentence.Realize @[simp] theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ := Iff.rfl namespace Formula @[simp] theorem realize_equivSentence_symm_con [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) : ((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize, BoundedFormula.realize_relabelEquiv, Function.comp] refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv rw [iff_iff_eq] congr 1 with (_ | a) · simp · cases a @[simp] theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply] theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) : (equivSentence.symm φ).Realize v ↔ @Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v)) φ := letI := constantsOn.structure v realize_equivSentence_symm_con M φ end Formula @[simp] theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ := φ.realize_onFormula ψ variable (L) /-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/ def completeTheory : L.Theory := { φ | M ⊨ φ } variable (N) /-- Two structures are elementarily equivalent when they satisfy the same sentences. -/ def ElementarilyEquivalent : Prop := L.completeTheory M = L.completeTheory N @[inherit_doc FirstOrder.Language.ElementarilyEquivalent] scoped[FirstOrder] notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B variable {L} {M} {N} @[simp] theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ := Iff.rfl theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq] variable (M) /-- A model of a theory is a structure in which every sentence is realized as true. -/ class Theory.Model (T : L.Theory) : Prop where realize_of_mem : ∀ φ ∈ T, M ⊨ φ -- input using \|= or \vDash, but not using \models @[inherit_doc Theory.Model] infixl:51 " ⊨ " => Theory.Model variable {M} (T : L.Theory) @[simp default - 10] theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ := ⟨fun h => h.realize_of_mem, fun h => ⟨h⟩⟩ theorem Theory.realize_sentence_of_mem [M ⊨ T] {φ : L.Sentence} (h : φ ∈ T) : M ⊨ φ := Theory.Model.realize_of_mem φ h @[simp] theorem LHom.onTheory_model [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (T : L.Theory) : M ⊨ φ.onTheory T ↔ M ⊨ T := by simp [Theory.model_iff, LHom.onTheory] variable {T} instance model_empty : M ⊨ (∅ : L.Theory) := ⟨fun φ hφ => (Set.notMem_empty φ hφ).elim⟩ namespace Theory theorem Model.mono {T' : L.Theory} (_h : M ⊨ T') (hs : T ⊆ T') : M ⊨ T := ⟨fun _φ hφ => T'.realize_sentence_of_mem (hs hφ)⟩ theorem Model.union {T' : L.Theory} (h : M ⊨ T) (h' : M ⊨ T') : M ⊨ T ∪ T' := by simp only [model_iff, Set.mem_union] at * exact fun φ hφ => hφ.elim (h _) (h' _) @[simp] theorem model_union_iff {T' : L.Theory} : M ⊨ T ∪ T' ↔ M ⊨ T ∧ M ⊨ T' := ⟨fun h => ⟨h.mono Set.subset_union_left, h.mono Set.subset_union_right⟩, fun h => h.1.union h.2⟩ @[simp] theorem model_singleton_iff {φ : L.Sentence} : M ⊨ ({φ} : L.Theory) ↔ M ⊨ φ := by simp theorem model_insert_iff {φ : L.Sentence} : M ⊨ insert φ T ↔ M ⊨ φ ∧ M ⊨ T := by rw [Set.insert_eq, model_union_iff, model_singleton_iff] theorem model_iff_subset_completeTheory : M ⊨ T ↔ T ⊆ L.completeTheory M := T.model_iff theorem completeTheory.subset [MT : M ⊨ T] : T ⊆ L.completeTheory M := model_iff_subset_completeTheory.1 MT end Theory instance model_completeTheory : M ⊨ L.completeTheory M := Theory.model_iff_subset_completeTheory.2 subset_rfl variable (M N) theorem realize_iff_of_model_completeTheory [N ⊨ L.completeTheory M] (φ : L.Sentence) : N ⊨ φ ↔ M ⊨ φ := by refine ⟨fun h => ?_, (L.completeTheory M).realize_sentence_of_mem⟩ contrapose! h rw [← Sentence.realize_not] at * exact (L.completeTheory M).realize_sentence_of_mem (mem_completeTheory.2 h) variable {M N} namespace BoundedFormula @[simp] theorem realize_alls {φ : L.BoundedFormula α n} {v : α → M} : φ.alls.Realize v ↔ ∀ xs : Fin n → M, φ.Realize v xs := by induction n with | zero => exact Unique.forall_iff.symm | succ n ih => simp only [alls, ih, Realize] exact ⟨fun h xs => Fin.snoc_init_self xs ▸ h _ _, fun h xs x => h (Fin.snoc xs x)⟩ @[simp] theorem realize_exs {φ : L.BoundedFormula α n} {v : α → M} : φ.exs.Realize v ↔ ∃ xs : Fin n → M, φ.Realize v xs := by induction n with | zero => exact Unique.exists_iff.symm | succ n ih => simp only [BoundedFormula.exs, ih, realize_ex] constructor · rintro ⟨xs, x, h⟩ exact ⟨_, h⟩ · rintro ⟨xs, h⟩ rw [← Fin.snoc_init_self xs] at h exact ⟨_, _, h⟩ @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iAlls [Finite β] {φ : L.Formula (α ⊕ β)} {v : α → M} : (φ.iAlls β).Realize v ↔ ∀ (i : β → M), φ.Realize (fun a => Sum.elim v i a) := by let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin β)) rw [Formula.iAlls] simp only [Nat.add_zero, realize_alls, realize_relabel, Function.comp_def, castAdd_zero, Sum.elim_map, id_eq] refine Equiv.forall_congr ?_ ?_ · exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm, fun _ => by simp [Function.comp_def], fun _ => by simp [Function.comp_def]⟩ · intro x rw [Formula.Realize, iff_iff_eq] congr funext i exact i.elim0 @[simp] theorem realize_iAlls [Finite β] {φ : L.Formula (α ⊕ β)} {v : α → M} {v' : Fin 0 → M} : BoundedFormula.Realize (φ.iAlls β) v v' ↔ ∀ (i : β → M), φ.Realize (fun a => Sum.elim v i a) := by rw [← Formula.realize_iAlls, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton] @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iExs [Finite γ] {φ : L.Formula (α ⊕ γ)} {v : α → M} : (φ.iExs γ).Realize v ↔ ∃ (i : γ → M), φ.Realize (Sum.elim v i) := by let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ)) rw [Formula.iExs] simp only [Nat.add_zero, realize_exs, realize_relabel, Function.comp_def, castAdd_zero, Sum.elim_map, id_eq] refine Equiv.exists_congr ?_ ?_ · exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm, fun _ => by simp [Function.comp_def], fun _ => by simp [Function.comp_def]⟩ · intro x rw [Formula.Realize, iff_iff_eq] congr funext i exact i.elim0 @[simp] theorem realize_iExs [Finite γ] {φ : L.Formula (α ⊕ γ)} {v : α → M} {v' : Fin 0 → M} : BoundedFormula.Realize (φ.iExs γ) v v' ↔ ∃ (i : γ → M), φ.Realize (Sum.elim v i) := by rw [← Formula.realize_iExs, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton] @[simp] theorem realize_toFormula (φ : L.BoundedFormula α n) (v : α ⊕ (Fin n) → M) : φ.toFormula.Realize v ↔ φ.Realize (v ∘ Sum.inl) (v ∘ Sum.inr) := by induction φ with | falsum => rfl | equal => simp [BoundedFormula.Realize] | rel => simp [BoundedFormula.Realize] | imp _ _ ih1 ih2 => rw [toFormula, Formula.Realize, realize_imp, ← Formula.Realize, ih1, ← Formula.Realize, ih2, realize_imp] | all _ ih3 => rw [toFormula, Formula.Realize, realize_all, realize_all] refine forall_congr' fun a => ?_ have h := ih3 (Sum.elim (v ∘ Sum.inl) (snoc (v ∘ Sum.inr) a)) simp only [Sum.elim_comp_inl, Sum.elim_comp_inr] at h rw [← h, realize_relabel, Formula.Realize, iff_iff_eq] simp only [Function.comp_def] congr with x · rcases x with _ | x · simp · refine Fin.lastCases ?_ ?_ x · simp [Fin.snoc] · simp only [castSucc, Sum.elim_inr, finSumFinEquiv_symm_apply_castAdd, Sum.map_inl, Sum.elim_inl] rw [← castSucc] simp · exact Fin.elim0 x @[simp] theorem realize_iSup [Finite β] {f : β → L.BoundedFormula α n} {v : α → M} {v' : Fin n → M} : (iSup f).Realize v v' ↔ ∃ b, (f b).Realize v v' := by simp only [iSup, realize_foldr_sup, List.mem_map, Finset.mem_toList, Finset.mem_univ, true_and, exists_exists_eq_and] @[simp] theorem realize_iInf [Finite β] {f : β → L.BoundedFormula α n} {v : α → M} {v' : Fin n → M} : (iInf f).Realize v v' ↔ ∀ b, (f b).Realize v v' := by simp only [iInf, realize_foldr_inf, List.mem_map, Finset.mem_toList, Finset.mem_univ, true_and, forall_exists_index, forall_apply_eq_imp_iff] @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iSup [Finite β] {f : β → L.Formula α} {v : α → M} : (Formula.iSup f).Realize v ↔ ∃ b, (f b).Realize v := by simp [Formula.iSup, Formula.Realize] @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iInf [Finite β] {f : β → L.Formula α} {v : α → M} : (Formula.iInf f).Realize v ↔ ∀ b, (f b).Realize v := by simp [Formula.iInf, Formula.Realize] theorem _root_.FirstOrder.Language.Formula.realize_iExsUnique [Finite γ] {φ : L.Formula (α ⊕ γ)} {v : α → M} : (φ.iExsUnique γ).Realize v ↔ ∃! (i : γ → M), φ.Realize (Sum.elim v i) := by rw [Formula.iExsUnique, ExistsUnique] simp only [Formula.realize_iExs, Formula.realize_inf, Formula.realize_iAlls, Formula.realize_imp, Formula.realize_relabel] simp only [Formula.Realize, Function.comp_def, Term.equal, Term.relabel, realize_iInf, realize_bdEqual, Term.realize_var, Sum.elim_inl, Sum.elim_inr, funext_iff] refine exists_congr (fun i => and_congr_right' (forall_congr' (fun y => ?_))) rw [iff_iff_eq]; congr with x cases x <;> simp @[simp] theorem realize_iExsUnique [Finite γ] {φ : L.Formula (α ⊕ γ)} {v : α → M} {v' : Fin 0 → M} : BoundedFormula.Realize (φ.iExsUnique γ) v v' ↔ ∃! (i : γ → M), φ.Realize (Sum.elim v i) := by rw [← Formula.realize_iExsUnique, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton] end BoundedFormula namespace StrongHomClass variable {F : Type*} [EquivLike F M N] [StrongHomClass L F M N] (g : F) @[simp] theorem realize_boundedFormula (φ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} : φ.Realize (g ∘ v) (g ∘ xs) ↔ φ.Realize v xs := by induction φ with | falsum => rfl | equal => simp only [BoundedFormula.Realize, ← Sum.comp_elim, HomClass.realize_term, EmbeddingLike.apply_eq_iff_eq g] | rel => simp only [BoundedFormula.Realize, ← Sum.comp_elim, HomClass.realize_term] exact StrongHomClass.map_rel g _ _ | imp _ _ ih1 ih2 => rw [BoundedFormula.Realize, ih1, ih2, BoundedFormula.Realize] | all _ ih3 => rw [BoundedFormula.Realize, BoundedFormula.Realize] constructor · intro h a have h' := h (g a) rw [← Fin.comp_snoc, ih3] at h' exact h' · intro h a have h' := h (EquivLike.inv g a) rw [← ih3, Fin.comp_snoc, EquivLike.apply_inv_apply g] at h' exact h' @[simp] theorem realize_formula (φ : L.Formula α) {v : α → M} : φ.Realize (g ∘ v) ↔ φ.Realize v := by rw [Formula.Realize, Formula.Realize, ← realize_boundedFormula g φ, iff_eq_eq, Unique.eq_default (g ∘ default)] include g theorem realize_sentence (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ := by rw [Sentence.Realize, Sentence.Realize, ← realize_formula g, Unique.eq_default (g ∘ default)] theorem theory_model [M ⊨ T] : N ⊨ T := ⟨fun φ hφ => (realize_sentence g φ).1 (Theory.realize_sentence_of_mem T hφ)⟩ theorem elementarilyEquivalent : M ≅[L] N := elementarilyEquivalent_iff.2 (realize_sentence g) end StrongHomClass namespace Relations open BoundedFormula variable {r : L.Relations 2} @[simp] theorem realize_reflexive : M ⊨ r.reflexive ↔ Reflexive fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => realize_rel₂ @[simp] theorem realize_irreflexive : M ⊨ r.irreflexive ↔ Irreflexive fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => not_congr realize_rel₂ @[simp] theorem realize_symmetric : M ⊨ r.symmetric ↔ Symmetric fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ realize_rel₂ @[simp] theorem realize_antisymmetric : M ⊨ r.antisymmetric ↔ AntiSymmetric fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ (imp_congr realize_rel₂ Iff.rfl) @[simp] theorem realize_transitive : M ⊨ r.transitive ↔ Transitive fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => forall_congr' fun _ => imp_congr realize_rel₂ (imp_congr realize_rel₂ realize_rel₂) @[simp] theorem realize_total : M ⊨ r.total ↔ Total fun x y : M => RelMap r ![x, y] := forall_congr' fun _ => forall_congr' fun _ => realize_sup.trans (or_congr realize_rel₂ realize_rel₂) end Relations section Cardinality variable (L) @[simp] theorem Sentence.realize_cardGe (n) : M ⊨ Sentence.cardGe L n ↔ ↑n ≤ #M := by rw [← lift_mk_fin, ← lift_le.{0}, lift_lift, lift_mk_le, Sentence.cardGe, Sentence.Realize, BoundedFormula.realize_exs] simp_rw [BoundedFormula.realize_foldr_inf] simp only [Function.comp_apply, List.mem_map, Prod.exists, Ne, List.mem_product, List.mem_finRange, forall_exists_index, and_imp, List.mem_filter, true_and] refine ⟨?_, fun xs => ⟨xs.some, ?_⟩⟩ · rintro ⟨xs, h⟩ refine ⟨⟨xs, fun i j ij => ?_⟩⟩ contrapose! ij have hij := h _ i j (by simpa using ij) rfl simp only [BoundedFormula.realize_not, Term.realize, BoundedFormula.realize_bdEqual, Sum.elim_inr] at hij exact hij · rintro _ i j ij rfl simpa using ij @[simp] theorem model_infiniteTheory_iff : M ⊨ L.infiniteTheory ↔ Infinite M := by simp [infiniteTheory, infinite_iff, aleph0_le] instance model_infiniteTheory [h : Infinite M] : M ⊨ L.infiniteTheory := L.model_infiniteTheory_iff.2 h @[simp] theorem model_nonemptyTheory_iff : M ⊨ L.nonemptyTheory ↔ Nonempty M := by simp only [nonemptyTheory, Theory.model_iff, Set.mem_singleton_iff, forall_eq, Sentence.realize_cardGe, Nat.cast_one, one_le_iff_ne_zero, mk_ne_zero_iff] instance model_nonempty [h : Nonempty M] : M ⊨ L.nonemptyTheory := L.model_nonemptyTheory_iff.2 h theorem model_distinctConstantsTheory {M : Type w} [L[[α]].Structure M] (s : Set α) : M ⊨ L.distinctConstantsTheory s ↔ Set.InjOn (fun i : α => (L.con i : M)) s := by simp only [distinctConstantsTheory, Theory.model_iff, Set.mem_image, Prod.exists, forall_exists_index, and_imp] refine ⟨fun h a as b bs ab => ?_, ?_⟩ · contrapose! ab have h' := h _ a b ⟨⟨as, bs⟩, ab⟩ rfl simp only [Sentence.Realize, Formula.realize_not, Formula.realize_equal, Term.realize_constants] at h' exact h' · rintro h φ a b ⟨⟨as, bs⟩, ab⟩ rfl simp only [Sentence.Realize, Formula.realize_not, Formula.realize_equal, Term.realize_constants] exact fun contra => ab (h as bs contra) theorem card_le_of_model_distinctConstantsTheory (s : Set α) (M : Type w) [L[[α]].Structure M] [h : M ⊨ L.distinctConstantsTheory s] : Cardinal.lift.{w} #s ≤ Cardinal.lift.{u'} #M := lift_mk_le'.2 ⟨⟨_, Set.injOn_iff_injective.1 ((L.model_distinctConstantsTheory s).1 h)⟩⟩ end Cardinality namespace ElementarilyEquivalent @[symm] nonrec theorem symm (h : M ≅[L] N) : N ≅[L] M := h.symm @[trans] nonrec theorem trans (MN : M ≅[L] N) (NP : N ≅[L] P) : M ≅[L] P := MN.trans NP theorem completeTheory_eq (h : M ≅[L] N) : L.completeTheory M = L.completeTheory N := h theorem realize_sentence (h : M ≅[L] N) (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ := (elementarilyEquivalent_iff.1 h) φ theorem theory_model_iff (h : M ≅[L] N) : M ⊨ T ↔ N ⊨ T := by rw [Theory.model_iff_subset_completeTheory, Theory.model_iff_subset_completeTheory, h.completeTheory_eq] theorem theory_model [MT : M ⊨ T] (h : M ≅[L] N) : N ⊨ T := h.theory_model_iff.1 MT theorem nonempty_iff (h : M ≅[L] N) : Nonempty M ↔ Nonempty N := (model_nonemptyTheory_iff L).symm.trans (h.theory_model_iff.trans (model_nonemptyTheory_iff L)) theorem nonempty [Mn : Nonempty M] (h : M ≅[L] N) : Nonempty N := h.nonempty_iff.1 Mn theorem infinite_iff (h : M ≅[L] N) : Infinite M ↔ Infinite N := (model_infiniteTheory_iff L).symm.trans (h.theory_model_iff.trans (model_infiniteTheory_iff L)) theorem infinite [Mi : Infinite M] (h : M ≅[L] N) : Infinite N := h.infinite_iff.1 Mi end ElementarilyEquivalent end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Graph.lean
import Mathlib.ModelTheory.Satisfiability import Mathlib.Combinatorics.SimpleGraph.Basic /-! # First-Order Structures in Graph Theory This file defines first-order languages, structures, and theories in graph theory. ## Main Definitions - `FirstOrder.Language.graph` is the language consisting of a single relation representing adjacency. - `SimpleGraph.structure` is the first-order structure corresponding to a given simple graph. - `FirstOrder.Language.Theory.simpleGraph` is the theory of simple graphs. - `FirstOrder.Language.simpleGraphOfStructure` gives the simple graph corresponding to a model of the theory of simple graphs. -/ universe u namespace FirstOrder namespace Language open FirstOrder open Structure variable {V : Type u} {n : ℕ} /-! ### Simple Graphs -/ /-- The type of relations for the language of graphs, consisting of a single binary relation `adj`. -/ inductive graphRel : ℕ → Type | adj : graphRel 2 deriving DecidableEq /-- The language consisting of a single relation representing adjacency. -/ protected def graph : Language := ⟨fun _ => Empty, graphRel⟩ deriving IsRelational /-- The symbol representing the adjacency relation. -/ abbrev adj : Language.graph.Relations 2 := .adj /-- Any simple graph can be thought of as a structure in the language of graphs. -/ def _root_.SimpleGraph.structure (G : SimpleGraph V) : Language.graph.Structure V where RelMap | .adj => (fun x => G.Adj (x 0) (x 1)) namespace graph instance instSubsingleton : Subsingleton (Language.graph.Relations n) := ⟨by rintro ⟨⟩ ⟨⟩; rfl⟩ end graph /-- The theory of simple graphs. -/ protected def Theory.simpleGraph : Language.graph.Theory := {adj.irreflexive, adj.symmetric} @[simp] theorem Theory.simpleGraph_model_iff [Language.graph.Structure V] : V ⊨ Theory.simpleGraph ↔ (Irreflexive fun x y : V => RelMap adj ![x, y]) ∧ Symmetric fun x y : V => RelMap adj ![x, y] := by simp [Theory.simpleGraph] instance simpleGraph_model (G : SimpleGraph V) : @Theory.Model _ V G.structure Theory.simpleGraph := by letI := G.structure rw [Theory.simpleGraph_model_iff] exact ⟨G.loopless, G.symm⟩ variable (V) in /-- Any model of the theory of simple graphs represents a simple graph. -/ @[simps] def simpleGraphOfStructure [Language.graph.Structure V] [V ⊨ Theory.simpleGraph] : SimpleGraph V where Adj x y := RelMap adj ![x, y] symm := Relations.realize_symmetric.1 (Theory.realize_sentence_of_mem Theory.simpleGraph (Set.mem_insert_of_mem _ (Set.mem_singleton _))) loopless := Relations.realize_irreflexive.1 (Theory.realize_sentence_of_mem Theory.simpleGraph (Set.mem_insert _ _)) @[simp] theorem _root_.SimpleGraph.simpleGraphOfStructure (G : SimpleGraph V) : @simpleGraphOfStructure V G.structure _ = G := by ext rfl @[simp] theorem structure_simpleGraphOfStructure [S : Language.graph.Structure V] [V ⊨ Theory.simpleGraph] : (simpleGraphOfStructure V).structure = S := by ext case funMap n f xs => exact isEmptyElim f case RelMap n r xs => match n, r with | 2, .adj => rw [iff_eq_eq] change RelMap adj ![xs 0, xs 1] = _ refine congr rfl (funext ?_) simp [Fin.forall_fin_two] theorem Theory.simpleGraph_isSatisfiable : Theory.IsSatisfiable Theory.simpleGraph := ⟨@Theory.ModelType.of _ _ Unit (SimpleGraph.structure ⊥) _ _⟩ end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Complexity.lean
import Mathlib.ModelTheory.Equivalence /-! # Quantifier Complexity This file defines quantifier complexity of first-order formulas, and constructs prenex normal forms. ## Main Definitions - `FirstOrder.Language.BoundedFormula.IsAtomic` defines atomic formulas - those which are constructed only from terms and relations. - `FirstOrder.Language.BoundedFormula.IsQF` defines quantifier-free formulas - those which are constructed only from atomic formulas and Boolean operations. - `FirstOrder.Language.BoundedFormula.IsPrenex` defines when a formula is in prenex normal form - when it consists of a series of quantifiers applied to a quantifier-free formula. - `FirstOrder.Language.BoundedFormula.toPrenex` constructs a prenex normal form of a given formula. ## Main Results - `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a formula has the same realization as the original formula. -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {M : Type w} [L.Structure M] {α : Type u'} {β : Type v'} variable {n l : ℕ} {φ : L.BoundedFormula α l} open FirstOrder Structure Fin namespace BoundedFormula /-- An atomic formula is either equality or a relation symbol applied to terms. Note that `⊥` and `⊤` are not considered atomic in this convention. -/ inductive IsAtomic : L.BoundedFormula α n → Prop | equal (t₁ t₂ : L.Term (α ⊕ (Fin n))) : IsAtomic (t₁.bdEqual t₂) | rel {l : ℕ} (R : L.Relations l) (ts : Fin l → L.Term (α ⊕ (Fin n))) : IsAtomic (R.boundedFormula ts) theorem not_all_isAtomic (φ : L.BoundedFormula α (n + 1)) : ¬φ.all.IsAtomic := fun con => by cases con theorem not_ex_isAtomic (φ : L.BoundedFormula α (n + 1)) : ¬φ.ex.IsAtomic := fun con => by cases con theorem IsAtomic.relabel {m : ℕ} {φ : L.BoundedFormula α m} (h : φ.IsAtomic) (f : α → β ⊕ (Fin n)) : (φ.relabel f).IsAtomic := IsAtomic.recOn h (fun _ _ => IsAtomic.equal _ _) fun _ _ => IsAtomic.rel _ _ theorem IsAtomic.liftAt {k m : ℕ} (h : IsAtomic φ) : (φ.liftAt k m).IsAtomic := IsAtomic.recOn h (fun _ _ => IsAtomic.equal _ _) fun _ _ => IsAtomic.rel _ _ theorem IsAtomic.castLE {h : l ≤ n} (hφ : IsAtomic φ) : (φ.castLE h).IsAtomic := IsAtomic.recOn hφ (fun _ _ => IsAtomic.equal _ _) fun _ _ => IsAtomic.rel _ _ /-- A quantifier-free formula is a formula defined without quantifiers. These are all equivalent to Boolean combinations of atomic formulas. -/ inductive IsQF : L.BoundedFormula α n → Prop | falsum : IsQF falsum | of_isAtomic {φ} (h : IsAtomic φ) : IsQF φ | imp {φ₁ φ₂} (h₁ : IsQF φ₁) (h₂ : IsQF φ₂) : IsQF (φ₁.imp φ₂) theorem IsAtomic.isQF {φ : L.BoundedFormula α n} : IsAtomic φ → IsQF φ := IsQF.of_isAtomic theorem isQF_bot : IsQF (⊥ : L.BoundedFormula α n) := IsQF.falsum namespace IsQF theorem not {φ : L.BoundedFormula α n} (h : IsQF φ) : IsQF φ.not := h.imp isQF_bot theorem top : IsQF (⊤ : L.BoundedFormula α n) := isQF_bot.not theorem sup {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsQF ψ) : IsQF (φ ⊔ ψ) := hφ.not.imp hψ theorem inf {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsQF ψ) : IsQF (φ ⊓ ψ) := (hφ.imp hψ.not).not protected theorem relabel {m : ℕ} {φ : L.BoundedFormula α m} (h : φ.IsQF) (f : α → β ⊕ (Fin n)) : (φ.relabel f).IsQF := IsQF.recOn h isQF_bot (fun h => (h.relabel f).isQF) fun _ _ h1 h2 => h1.imp h2 protected theorem liftAt {k m : ℕ} (h : IsQF φ) : (φ.liftAt k m).IsQF := IsQF.recOn h isQF_bot (fun ih => ih.liftAt.isQF) fun _ _ ih1 ih2 => ih1.imp ih2 protected theorem castLE {h : l ≤ n} (hφ : IsQF φ) : (φ.castLE h).IsQF := IsQF.recOn hφ isQF_bot (fun ih => ih.castLE.isQF) fun _ _ ih1 ih2 => ih1.imp ih2 end IsQF theorem not_all_isQF (φ : L.BoundedFormula α (n + 1)) : ¬φ.all.IsQF := fun con => by obtain - | con := con exact φ.not_all_isAtomic con theorem not_ex_isQF (φ : L.BoundedFormula α (n + 1)) : ¬φ.ex.IsQF := fun con => by obtain - | con | con := con · exact φ.not_ex_isAtomic con · exact not_all_isQF _ con /-- Indicates that a bounded formula is in prenex normal form - that is, it consists of quantifiers applied to a quantifier-free formula. -/ inductive IsPrenex : ∀ {n}, L.BoundedFormula α n → Prop | of_isQF {n} {φ : L.BoundedFormula α n} (h : IsQF φ) : IsPrenex φ | all {n} {φ : L.BoundedFormula α (n + 1)} (h : IsPrenex φ) : IsPrenex φ.all | ex {n} {φ : L.BoundedFormula α (n + 1)} (h : IsPrenex φ) : IsPrenex φ.ex theorem IsQF.isPrenex {φ : L.BoundedFormula α n} : IsQF φ → IsPrenex φ := IsPrenex.of_isQF theorem IsAtomic.isPrenex {φ : L.BoundedFormula α n} (h : IsAtomic φ) : IsPrenex φ := h.isQF.isPrenex theorem IsPrenex.induction_on_all_not {P : ∀ {n}, L.BoundedFormula α n → Prop} {φ : L.BoundedFormula α n} (h : IsPrenex φ) (hq : ∀ {m} {ψ : L.BoundedFormula α m}, ψ.IsQF → P ψ) (ha : ∀ {m} {ψ : L.BoundedFormula α (m + 1)}, P ψ → P ψ.all) (hn : ∀ {m} {ψ : L.BoundedFormula α m}, P ψ → P ψ.not) : P φ := IsPrenex.recOn h hq (fun _ => ha) fun _ ih => hn (ha (hn ih)) theorem IsPrenex.relabel {m : ℕ} {φ : L.BoundedFormula α m} (h : φ.IsPrenex) (f : α → β ⊕ (Fin n)) : (φ.relabel f).IsPrenex := IsPrenex.recOn h (fun h => (h.relabel f).isPrenex) (fun _ h => by simp [h.all]) fun _ h => by simp [h.ex] theorem IsPrenex.castLE (hφ : IsPrenex φ) : ∀ {n} {h : l ≤ n}, (φ.castLE h).IsPrenex := IsPrenex.recOn (motive := @fun l φ _ => ∀ (n : ℕ) (h : l ≤ n), (φ.castLE h).IsPrenex) hφ (@fun _ _ ih _ _ => ih.castLE.isPrenex) (@fun _ _ _ ih _ _ => (ih _ _).all) (@fun _ _ _ ih _ _ => (ih _ _).ex) _ _ theorem IsPrenex.liftAt {k m : ℕ} (h : IsPrenex φ) : (φ.liftAt k m).IsPrenex := IsPrenex.recOn h (fun ih => ih.liftAt.isPrenex) (fun _ ih => ih.castLE.all) fun _ ih => ih.castLE.ex /-- An auxiliary operation to `FirstOrder.Language.BoundedFormula.toPrenex`. If `φ` is quantifier-free and `ψ` is in prenex normal form, then `φ.toPrenexImpRight ψ` is a prenex normal form for `φ.imp ψ`. -/ def toPrenexImpRight : ∀ {n}, L.BoundedFormula α n → L.BoundedFormula α n → L.BoundedFormula α n | n, φ, BoundedFormula.ex ψ => ((φ.liftAt 1 n).toPrenexImpRight ψ).ex | n, φ, all ψ => ((φ.liftAt 1 n).toPrenexImpRight ψ).all | _n, φ, ψ => φ.imp ψ theorem IsQF.toPrenexImpRight {φ : L.BoundedFormula α n} : ∀ {ψ : L.BoundedFormula α n}, IsQF ψ → φ.toPrenexImpRight ψ = φ.imp ψ | _, IsQF.falsum => rfl | _, IsQF.of_isAtomic (IsAtomic.equal _ _) => rfl | _, IsQF.of_isAtomic (IsAtomic.rel _ _) => rfl | _, IsQF.imp IsQF.falsum _ => rfl | _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.equal _ _)) _ => rfl | _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.rel _ _)) _ => rfl | _, IsQF.imp (IsQF.imp _ _) _ => rfl theorem isPrenex_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ) : IsPrenex (φ.toPrenexImpRight ψ) := by induction hψ with | of_isQF hψ => rw [hψ.toPrenexImpRight]; exact (hφ.imp hψ).isPrenex | all _ ih1 => exact (ih1 hφ.liftAt).all | ex _ ih2 => exact (ih2 hφ.liftAt).ex /-- An auxiliary operation to `FirstOrder.Language.BoundedFormula.toPrenex`. If `φ` and `ψ` are in prenex normal form, then `φ.toPrenexImp ψ` is a prenex normal form for `φ.imp ψ`. -/ def toPrenexImp : ∀ {n}, L.BoundedFormula α n → L.BoundedFormula α n → L.BoundedFormula α n | n, BoundedFormula.ex φ, ψ => (φ.toPrenexImp (ψ.liftAt 1 n)).all | n, all φ, ψ => (φ.toPrenexImp (ψ.liftAt 1 n)).ex | _, φ, ψ => φ.toPrenexImpRight ψ theorem IsQF.toPrenexImp : ∀ {φ ψ : L.BoundedFormula α n}, φ.IsQF → φ.toPrenexImp ψ = φ.toPrenexImpRight ψ | _, _, IsQF.falsum => rfl | _, _, IsQF.of_isAtomic (IsAtomic.equal _ _) => rfl | _, _, IsQF.of_isAtomic (IsAtomic.rel _ _) => rfl | _, _, IsQF.imp IsQF.falsum _ => rfl | _, _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.equal _ _)) _ => rfl | _, _, IsQF.imp (IsQF.of_isAtomic (IsAtomic.rel _ _)) _ => rfl | _, _, IsQF.imp (IsQF.imp _ _) _ => rfl theorem isPrenex_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ) : IsPrenex (φ.toPrenexImp ψ) := by induction hφ with | of_isQF hφ => rw [hφ.toPrenexImp]; exact isPrenex_toPrenexImpRight hφ hψ | all _ ih1 => exact (ih1 hψ.liftAt).ex | ex _ ih2 => exact (ih2 hψ.liftAt).all /-- For any bounded formula `φ`, `φ.toPrenex` is a semantically-equivalent formula in prenex normal form. -/ def toPrenex : ∀ {n}, L.BoundedFormula α n → L.BoundedFormula α n | _, falsum => ⊥ | _, equal t₁ t₂ => t₁.bdEqual t₂ | _, rel R ts => rel R ts | _, imp f₁ f₂ => f₁.toPrenex.toPrenexImp f₂.toPrenex | _, all f => f.toPrenex.all theorem toPrenex_isPrenex (φ : L.BoundedFormula α n) : φ.toPrenex.IsPrenex := BoundedFormula.recOn φ isQF_bot.isPrenex (fun _ _ => (IsAtomic.equal _ _).isPrenex) (fun _ _ => (IsAtomic.rel _ _).isPrenex) (fun _ _ h1 h2 => isPrenex_toPrenexImp h1 h2) fun _ => IsPrenex.all variable [Nonempty M] theorem realize_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ) {v : α → M} {xs : Fin n → M} : (φ.toPrenexImpRight ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by induction hψ with | of_isQF hψ => rw [hψ.toPrenexImpRight] | all _ ih => refine _root_.trans (forall_congr' fun _ => ih hφ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all] exact ⟨fun h1 a h2 => h1 h2 a, fun h1 h2 a => h1 a h2⟩ | ex _ ih => unfold toPrenexImpRight rw [realize_ex] refine _root_.trans (exists_congr fun _ => ih hφ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_ex] refine ⟨?_, fun h' => ?_⟩ · rintro ⟨a, ha⟩ h exact ⟨a, ha h⟩ · by_cases h : φ.Realize v xs · obtain ⟨a, ha⟩ := h' h exact ⟨a, fun _ => ha⟩ · inhabit M exact ⟨default, fun h'' => (h h'').elim⟩ theorem realize_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ) {v : α → M} {xs : Fin n → M} : (φ.toPrenexImp ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by revert ψ induction hφ with | of_isQF hφ => intro ψ hψ rw [hφ.toPrenexImp] exact realize_toPrenexImpRight hφ hψ | all _ ih => intro ψ hψ unfold toPrenexImp rw [realize_ex] refine _root_.trans (exists_congr fun _ => ih hψ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all] exact Iff.symm forall_imp_iff_exists_imp | ex _ ih => intro ψ hψ refine _root_.trans (forall_congr' fun _ => ih hψ.liftAt) ?_ simp @[simp] theorem realize_toPrenex (φ : L.BoundedFormula α n) {v : α → M} : ∀ {xs : Fin n → M}, φ.toPrenex.Realize v xs ↔ φ.Realize v xs := by induction φ with | falsum => exact Iff.rfl | equal => exact Iff.rfl | rel => exact Iff.rfl | imp f1 f2 h1 h2 => intros rw [toPrenex, realize_toPrenexImp f1.toPrenex_isPrenex f2.toPrenex_isPrenex, realize_imp, realize_imp, h1, h2] | all _ h => intros rw [realize_all, toPrenex, realize_all] exact forall_congr' fun a => h theorem IsQF.induction_on_sup_not {P : L.BoundedFormula α n → Prop} {φ : L.BoundedFormula α n} (h : IsQF φ) (hf : P (⊥ : L.BoundedFormula α n)) (ha : ∀ ψ : L.BoundedFormula α n, IsAtomic ψ → P ψ) (hsup : ∀ {φ₁ φ₂}, P φ₁ → P φ₂ → P (φ₁ ⊔ φ₂)) (hnot : ∀ {φ}, P φ → P φ.not) (hse : ∀ {φ₁ φ₂ : L.BoundedFormula α n}, (φ₁ ⇔[∅] φ₂) → (P φ₁ ↔ P φ₂)) : P φ := IsQF.recOn h hf @(ha) fun {φ₁ φ₂} _ _ h1 h2 => (hse (φ₁.imp_iff_not_sup φ₂)).2 (hsup (hnot h1) h2) theorem IsQF.induction_on_inf_not {P : L.BoundedFormula α n → Prop} {φ : L.BoundedFormula α n} (h : IsQF φ) (hf : P (⊥ : L.BoundedFormula α n)) (ha : ∀ ψ : L.BoundedFormula α n, IsAtomic ψ → P ψ) (hinf : ∀ {φ₁ φ₂}, P φ₁ → P φ₂ → P (φ₁ ⊓ φ₂)) (hnot : ∀ {φ}, P φ → P φ.not) (hse : ∀ {φ₁ φ₂ : L.BoundedFormula α n}, (φ₁ ⇔[∅] φ₂) → (P φ₁ ↔ P φ₂)) : P φ := h.induction_on_sup_not hf ha (fun {φ₁ φ₂} h1 h2 => (hse (φ₁.sup_iff_not_inf_not φ₂)).2 (hnot (hinf (hnot h1) (hnot h2)))) (fun {_} => hnot) fun {_ _} => hse theorem iff_toPrenex (φ : L.BoundedFormula α n) : φ ⇔[∅] φ.toPrenex := fun M v xs => by rw [realize_iff, realize_toPrenex] theorem induction_on_all_ex {P : ∀ {m}, L.BoundedFormula α m → Prop} (φ : L.BoundedFormula α n) (hqf : ∀ {m} {ψ : L.BoundedFormula α m}, IsQF ψ → P ψ) (hall : ∀ {m} {ψ : L.BoundedFormula α (m + 1)}, P ψ → P ψ.all) (hex : ∀ {m} {φ : L.BoundedFormula α (m + 1)}, P φ → P φ.ex) (hse : ∀ {m} {φ₁ φ₂ : L.BoundedFormula α m}, (φ₁ ⇔[∅] φ₂) → (P φ₁ ↔ P φ₂)) : P φ := by suffices h' : ∀ {m} {φ : L.BoundedFormula α m}, φ.IsPrenex → P φ from (hse φ.iff_toPrenex).2 (h' φ.toPrenex_isPrenex) intro m φ hφ induction hφ with | of_isQF hφ => exact hqf hφ | all _ hφ => exact hall hφ | ex _ hφ => exact hex hφ theorem induction_on_exists_not {P : ∀ {m}, L.BoundedFormula α m → Prop} (φ : L.BoundedFormula α n) (hqf : ∀ {m} {ψ : L.BoundedFormula α m}, IsQF ψ → P ψ) (hnot : ∀ {m} {φ : L.BoundedFormula α m}, P φ → P φ.not) (hex : ∀ {m} {φ : L.BoundedFormula α (m + 1)}, P φ → P φ.ex) (hse : ∀ {m} {φ₁ φ₂ : L.BoundedFormula α m}, (φ₁ ⇔[∅] φ₂) → (P φ₁ ↔ P φ₂)) : P φ := φ.induction_on_all_ex (fun {_ _} => hqf) (fun {_ φ} hφ => (hse φ.all_iff_not_ex_not).2 (hnot (hex (hnot hφ)))) (fun {_ _} => hex) fun {_ _ _} => hse /-- A universal formula is a formula defined by applying only universal quantifiers to a quantifier-free formula. -/ inductive IsUniversal : ∀ {n}, L.BoundedFormula α n → Prop | of_isQF {n} {φ : L.BoundedFormula α n} (h : IsQF φ) : IsUniversal φ | all {n} {φ : L.BoundedFormula α (n + 1)} (h : IsUniversal φ) : IsUniversal φ.all lemma IsQF.isUniversal {φ : L.BoundedFormula α n} : IsQF φ → IsUniversal φ := IsUniversal.of_isQF lemma IsAtomic.isUniversal {φ : L.BoundedFormula α n} (h : IsAtomic φ) : IsUniversal φ := h.isQF.isUniversal /-- An existential formula is a formula defined by applying only existential quantifiers to a quantifier-free formula. -/ inductive IsExistential : ∀ {n}, L.BoundedFormula α n → Prop | of_isQF {n} {φ : L.BoundedFormula α n} (h : IsQF φ) : IsExistential φ | ex {n} {φ : L.BoundedFormula α (n + 1)} (h : IsExistential φ) : IsExistential φ.ex lemma IsQF.isExistential {φ : L.BoundedFormula α n} : IsQF φ → IsExistential φ := IsExistential.of_isQF lemma IsAtomic.isExistential {φ : L.BoundedFormula α n} (h : IsAtomic φ) : IsExistential φ := h.isQF.isExistential section Preservation variable {M : Type*} [L.Structure M] {N : Type*} [L.Structure N] variable {F : Type*} [FunLike F M N] lemma IsAtomic.realize_comp_of_injective {φ : L.BoundedFormula α n} (hA : φ.IsAtomic) [L.HomClass F M N] {f : F} (hInj : Function.Injective f) {v : α → M} {xs : Fin n → M} : φ.Realize v xs → φ.Realize (f ∘ v) (f ∘ xs) := by induction hA with | equal t₁ t₂ => simp only [realize_bdEqual, ← Sum.comp_elim, HomClass.realize_term, hInj.eq_iff, imp_self] | rel R ts => simp only [realize_rel, ← Sum.comp_elim, HomClass.realize_term] exact HomClass.map_rel f R (fun i => Term.realize (Sum.elim v xs) (ts i)) lemma IsAtomic.realize_comp {φ : L.BoundedFormula α n} (hA : φ.IsAtomic) [EmbeddingLike F M N] [L.HomClass F M N] (f : F) {v : α → M} {xs : Fin n → M} : φ.Realize v xs → φ.Realize (f ∘ v) (f ∘ xs) := hA.realize_comp_of_injective (EmbeddingLike.injective f) variable [EmbeddingLike F M N] [L.StrongHomClass F M N] lemma IsQF.realize_embedding {φ : L.BoundedFormula α n} (hQF : φ.IsQF) (f : F) {v : α → M} {xs : Fin n → M} : φ.Realize (f ∘ v) (f ∘ xs) ↔ φ.Realize v xs := by induction hQF with | falsum => rfl | of_isAtomic hA => induction hA with | equal t₁ t₂ => simp only [realize_bdEqual, ← Sum.comp_elim, HomClass.realize_term, (EmbeddingLike.injective f).eq_iff] | rel R ts => simp only [realize_rel, ← Sum.comp_elim, HomClass.realize_term] exact StrongHomClass.map_rel f R (fun i => Term.realize (Sum.elim v xs) (ts i)) | imp _ _ ihφ ihψ => simp only [realize_imp, ihφ, ihψ] lemma IsUniversal.realize_embedding {φ : L.BoundedFormula α n} (hU : φ.IsUniversal) (f : F) {v : α → M} {xs : Fin n → M} : φ.Realize (f ∘ v) (f ∘ xs) → φ.Realize v xs := by induction hU with | of_isQF hQF => simp [hQF.realize_embedding] | all _ ih => simp only [realize_all, Nat.succ_eq_add_one] refine fun h a => ih ?_ rw [Fin.comp_snoc] exact h (f a) lemma IsExistential.realize_embedding {φ : L.BoundedFormula α n} (hE : φ.IsExistential) (f : F) {v : α → M} {xs : Fin n → M} : φ.Realize v xs → φ.Realize (f ∘ v) (f ∘ xs) := by induction hE with | of_isQF hQF => simp [hQF.realize_embedding] | ex _ ih => simp only [realize_ex, Nat.succ_eq_add_one] refine fun ⟨a, ha⟩ => ⟨f a, ?_⟩ rw [← Fin.comp_snoc] exact ih ha end Preservation end BoundedFormula /-- A theory is universal when it is comprised only of universal sentences - these theories apply also to substructures. -/ class Theory.IsUniversal (T : L.Theory) : Prop where isUniversal_of_mem : ∀ ⦃φ⦄, φ ∈ T → φ.IsUniversal lemma Theory.IsUniversal.models_of_embedding {T : L.Theory} [hT : T.IsUniversal] {N : Type*} [L.Structure N] [N ⊨ T] (f : M ↪[L] N) : M ⊨ T := by simp only [model_iff] refine fun φ hφ => (hT.isUniversal_of_mem hφ).realize_embedding f (?_) rw [Subsingleton.elim (f ∘ default) default, Subsingleton.elim (f ∘ default) default] exact Theory.realize_sentence_of_mem T hφ instance Substructure.models_of_isUniversal (S : L.Substructure M) (T : L.Theory) [T.IsUniversal] [M ⊨ T] : S ⊨ T := Theory.IsUniversal.models_of_embedding (Substructure.subtype S) lemma Theory.IsUniversal.insert {T : L.Theory} [hT : T.IsUniversal] {φ : L.Sentence} (hφ : φ.IsUniversal) : (insert φ T).IsUniversal := ⟨by simp only [Set.mem_insert_iff, forall_eq_or_imp, hφ, true_and] exact hT.isUniversal_of_mem⟩ namespace Relations open BoundedFormula lemma isAtomic (r : L.Relations l) (ts : Fin l → L.Term (α ⊕ (Fin n))) : IsAtomic (r.boundedFormula ts) := IsAtomic.rel r ts lemma isQF (r : L.Relations l) (ts : Fin l → L.Term (α ⊕ (Fin n))) : IsQF (r.boundedFormula ts) := (r.isAtomic ts).isQF variable (r : L.Relations 2) protected lemma isUniversal_reflexive : r.reflexive.IsUniversal := (r.isQF _).isUniversal.all protected lemma isUniversal_irreflexive : r.irreflexive.IsUniversal := (r.isAtomic _).isQF.not.isUniversal.all protected lemma isUniversal_symmetric : r.symmetric.IsUniversal := ((r.isQF _).imp (r.isQF _)).isUniversal.all.all protected lemma isUniversal_antisymmetric : r.antisymmetric.IsUniversal := ((r.isQF _).imp ((r.isQF _).imp (IsAtomic.equal _ _).isQF)).isUniversal.all.all protected lemma isUniversal_transitive : r.transitive.IsUniversal := ((r.isQF _).imp ((r.isQF _).imp (r.isQF _))).isUniversal.all.all.all protected lemma isUniversal_total : r.total.IsUniversal := ((r.isQF _).sup (r.isQF _)).isUniversal.all.all end Relations theorem Formula.isAtomic_graph (f : L.Functions n) : (Formula.graph f).IsAtomic := BoundedFormula.IsAtomic.equal _ _ end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/ElementarySubstructures.lean
import Mathlib.ModelTheory.ElementaryMaps /-! # Elementary Substructures ## Main Definitions - A `FirstOrder.Language.ElementarySubstructure` is a substructure where the realization of each formula agrees with the realization in the larger model. ## Main Results - The Tarski-Vaught Test for substructures: `FirstOrder.Language.Substructure.isElementary_of_exists` gives a simple criterion for a substructure to be elementary. -/ open FirstOrder namespace FirstOrder namespace Language open Structure variable {L : Language} {M : Type*} [L.Structure M] /-- A substructure is elementary when every formula applied to a tuple in the substructure agrees with its value in the overall structure. -/ def Substructure.IsElementary (S : L.Substructure M) : Prop := ∀ ⦃n⦄ (φ : L.Formula (Fin n)) (x : Fin n → S), φ.Realize (((↑) : _ → M) ∘ x) ↔ φ.Realize x variable (L M) /-- An elementary substructure is one in which every formula applied to a tuple in the substructure agrees with its value in the overall structure. -/ structure ElementarySubstructure where /-- The underlying substructure -/ toSubstructure : L.Substructure M isElementary' : toSubstructure.IsElementary variable {L M} namespace ElementarySubstructure attribute [coe] toSubstructure instance instCoe : Coe (L.ElementarySubstructure M) (L.Substructure M) := ⟨ElementarySubstructure.toSubstructure⟩ instance instSetLike : SetLike (L.ElementarySubstructure M) M := ⟨fun x => x.toSubstructure.carrier, fun ⟨⟨s, hs1⟩, hs2⟩ ⟨⟨t, ht1⟩, _⟩ _ => by congr⟩ instance inducedStructure (S : L.ElementarySubstructure M) : L.Structure S := Substructure.inducedStructure @[simp] theorem isElementary (S : L.ElementarySubstructure M) : (S : L.Substructure M).IsElementary := S.isElementary' /-- The natural embedding of an `L.Substructure` of `M` into `M`. -/ def subtype (S : L.ElementarySubstructure M) : S ↪ₑ[L] M where toFun := (↑) map_formula' := S.isElementary @[simp] theorem subtype_apply {S : L.ElementarySubstructure M} {x : S} : subtype S x = x := rfl theorem subtype_injective (S : L.ElementarySubstructure M) : Function.Injective (subtype S) := Subtype.coe_injective @[simp] theorem coe_subtype (S : L.ElementarySubstructure M) : ⇑S.subtype = Subtype.val := rfl /-- The substructure `M` of the structure `M` is elementary. -/ instance instTop : Top (L.ElementarySubstructure M) := ⟨⟨⊤, fun _ _ _ => Substructure.realize_formula_top.symm⟩⟩ instance instInhabited : Inhabited (L.ElementarySubstructure M) := ⟨⊤⟩ @[simp] theorem mem_top (x : M) : x ∈ (⊤ : L.ElementarySubstructure M) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : L.ElementarySubstructure M) : Set M) = Set.univ := rfl @[simp] theorem realize_sentence (S : L.ElementarySubstructure M) (φ : L.Sentence) : S ⊨ φ ↔ M ⊨ φ := S.subtype.map_sentence φ @[simp] theorem theory_model_iff (S : L.ElementarySubstructure M) (T : L.Theory) : S ⊨ T ↔ M ⊨ T := by simp only [Theory.model_iff, realize_sentence] instance theory_model {T : L.Theory} [h : M ⊨ T] {S : L.ElementarySubstructure M} : S ⊨ T := (theory_model_iff S T).2 h instance instNonempty [Nonempty M] {S : L.ElementarySubstructure M} : Nonempty S := (model_nonemptyTheory_iff L).1 inferInstance theorem elementarilyEquivalent (S : L.ElementarySubstructure M) : S ≅[L] M := S.subtype.elementarilyEquivalent end ElementarySubstructure namespace Substructure /-- The Tarski-Vaught test for elementarity of a substructure. -/ theorem isElementary_of_exists (S : L.Substructure M) (htv : ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → S) (a : M), φ.Realize default (Fin.snoc ((↑) ∘ x) a : _ → M) → ∃ b : S, φ.Realize default (Fin.snoc ((↑) ∘ x) b : _ → M)) : S.IsElementary := fun _ => S.subtype.isElementary_of_exists htv /-- Bundles a substructure satisfying the Tarski-Vaught test as an elementary substructure. -/ @[simps] def toElementarySubstructure (S : L.Substructure M) (htv : ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → S) (a : M), φ.Realize default (Fin.snoc ((↑) ∘ x) a : _ → M) → ∃ b : S, φ.Realize default (Fin.snoc ((↑) ∘ x) b : _ → M)) : L.ElementarySubstructure M := ⟨S, S.isElementary_of_exists htv⟩ end Substructure end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Quotients.lean
import Mathlib.Data.Fintype.Quotient import Mathlib.ModelTheory.Semantics /-! # Quotients of First-Order Structures This file defines prestructures and quotients of first-order structures. ## Main Definitions - If `s` is a setoid (equivalence relation) on `M`, a `FirstOrder.Language.Prestructure s` is the data for a first-order structure on `M` that will still be a structure when modded out by `s`. - The structure `FirstOrder.Language.quotientStructure s` is the resulting structure on `Quotient s`. -/ namespace FirstOrder namespace Language variable (L : Language) {M : Type*} open FirstOrder open Structure /-- A prestructure is a first-order structure with a `Setoid` equivalence relation on it, such that quotienting by that equivalence relation is still a structure. -/ class Prestructure (s : Setoid M) where /-- The underlying first-order structure -/ toStructure : L.Structure M fun_equiv : ∀ {n} {f : L.Functions n} (x y : Fin n → M), x ≈ y → funMap f x ≈ funMap f y rel_equiv : ∀ {n} {r : L.Relations n} (x y : Fin n → M) (_ : x ≈ y), RelMap r x = RelMap r y variable {L} {s : Setoid M} variable [ps : L.Prestructure s] instance quotientStructure : L.Structure (Quotient s) where funMap {n} f x := Quotient.map (@funMap L M ps.toStructure n f) Prestructure.fun_equiv (Quotient.finChoice x) RelMap {n} r x := Quotient.lift (@RelMap L M ps.toStructure n r) Prestructure.rel_equiv (Quotient.finChoice x) variable (s) theorem funMap_quotient_mk' {n : ℕ} (f : L.Functions n) (x : Fin n → M) : (funMap f fun i => (⟦x i⟧ : Quotient s)) = ⟦@funMap _ _ ps.toStructure _ f x⟧ := by change Quotient.map (@funMap L M ps.toStructure n f) Prestructure.fun_equiv (Quotient.finChoice _) = _ rw [Quotient.finChoice_eq, Quotient.map_mk] theorem relMap_quotient_mk' {n : ℕ} (r : L.Relations n) (x : Fin n → M) : (RelMap r fun i => (⟦x i⟧ : Quotient s)) ↔ @RelMap _ _ ps.toStructure _ r x := by change Quotient.lift (@RelMap L M ps.toStructure n r) Prestructure.rel_equiv (Quotient.finChoice _) ↔ _ rw [Quotient.finChoice_eq, Quotient.lift_mk] theorem Term.realize_quotient_mk' {β : Type*} (t : L.Term β) (x : β → M) : (t.realize fun i => (⟦x i⟧ : Quotient s)) = ⟦@Term.realize _ _ ps.toStructure _ x t⟧ := by induction t with | var => rfl | func _ _ ih => simp only [ih, funMap_quotient_mk', Term.realize] end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/LanguageMap.lean
import Mathlib.ModelTheory.Basic /-! # Language Maps Maps between first-order languages in the style of the [Flypitch project](https://flypitch.github.io/), as well as several important maps between structures. ## Main Definitions - A `FirstOrder.Language.LHom`, denoted `L →ᴸ L'`, is a map between languages, sending the symbols of one to symbols of the same kind and arity in the other. - A `FirstOrder.Language.LEquiv`, denoted `L ≃ᴸ L'`, is an invertible language homomorphism. - `FirstOrder.Language.withConstants` is defined so that if `M` is an `L.Structure` and `A : Set M`, `L.withConstants A`, denoted `L[[A]]`, is a language which adds constant symbols for elements of `A` to `L`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v u' v' w w' namespace FirstOrder namespace Language open Structure Cardinal variable (L : Language.{u, v}) (L' : Language.{u', v'}) {M : Type w} [L.Structure M] /-- A language homomorphism maps the symbols of one language to symbols of another. -/ structure LHom where /-- The mapping of functions -/ onFunction : ∀ ⦃n⦄, L.Functions n → L'.Functions n := by exact fun {n} => isEmptyElim /-- The mapping of relations -/ onRelation : ∀ ⦃n⦄, L.Relations n → L'.Relations n :=by exact fun {n} => isEmptyElim @[inherit_doc FirstOrder.Language.LHom] infixl:10 " →ᴸ " => LHom -- \^L variable {L L'} namespace LHom variable (ϕ : L →ᴸ L') /-- Pulls a structure back along a language map. -/ def reduct (M : Type*) [L'.Structure M] : L.Structure M where funMap f xs := funMap (ϕ.onFunction f) xs RelMap r xs := RelMap (ϕ.onRelation r) xs /-- The identity language homomorphism. -/ @[simps] protected def id (L : Language) : L →ᴸ L := ⟨fun _n => id, fun _n => id⟩ instance : Inhabited (L →ᴸ L) := ⟨LHom.id L⟩ /-- The inclusion of the left factor into the sum of two languages. -/ @[simps] protected def sumInl : L →ᴸ L.sum L' := ⟨fun _n => Sum.inl, fun _n => Sum.inl⟩ /-- The inclusion of the right factor into the sum of two languages. -/ @[simps] protected def sumInr : L' →ᴸ L.sum L' := ⟨fun _n => Sum.inr, fun _n => Sum.inr⟩ variable (L L') /-- The inclusion of an empty language into any other language. -/ @[simps] protected def ofIsEmpty [L.IsAlgebraic] [L.IsRelational] : L →ᴸ L' where variable {L L'} {L'' : Language} @[ext] protected theorem funext {F G : L →ᴸ L'} (h_fun : F.onFunction = G.onFunction) (h_rel : F.onRelation = G.onRelation) : F = G := by obtain ⟨Ff, Fr⟩ := F obtain ⟨Gf, Gr⟩ := G simp only [mk.injEq] exact And.intro h_fun h_rel instance [L.IsAlgebraic] [L.IsRelational] : Unique (L →ᴸ L') := ⟨⟨LHom.ofIsEmpty L L'⟩, fun _ => LHom.funext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩ /-- The composition of two language homomorphisms. -/ @[simps] def comp (g : L' →ᴸ L'') (f : L →ᴸ L') : L →ᴸ L'' := ⟨fun _n F => g.1 (f.1 F), fun _ R => g.2 (f.2 R)⟩ -- added ᴸ to avoid clash with function composition @[inherit_doc] local infixl:60 " ∘ᴸ " => LHom.comp @[simp] theorem id_comp (F : L →ᴸ L') : LHom.id L' ∘ᴸ F = F := by cases F rfl @[simp] theorem comp_id (F : L →ᴸ L') : F ∘ᴸ LHom.id L = F := by cases F rfl theorem comp_assoc {L3 : Language} (F : L'' →ᴸ L3) (G : L' →ᴸ L'') (H : L →ᴸ L') : F ∘ᴸ G ∘ᴸ H = F ∘ᴸ (G ∘ᴸ H) := rfl section SumElim variable (ψ : L'' →ᴸ L') /-- A language map defined on two factors of a sum. -/ @[simps] protected def sumElim : L.sum L'' →ᴸ L' where onFunction _n := Sum.elim (fun f => ϕ.onFunction f) fun f => ψ.onFunction f onRelation _n := Sum.elim (fun f => ϕ.onRelation f) fun f => ψ.onRelation f theorem sumElim_comp_inl (ψ : L'' →ᴸ L') : ϕ.sumElim ψ ∘ᴸ LHom.sumInl = ϕ := LHom.funext (funext fun _ => rfl) (funext fun _ => rfl) theorem sumElim_comp_inr (ψ : L'' →ᴸ L') : ϕ.sumElim ψ ∘ᴸ LHom.sumInr = ψ := LHom.funext (funext fun _ => rfl) (funext fun _ => rfl) theorem sumElim_inl_inr : LHom.sumInl.sumElim LHom.sumInr = LHom.id (L.sum L') := LHom.funext (funext fun _ => Sum.elim_inl_inr) (funext fun _ => Sum.elim_inl_inr) theorem comp_sumElim {L3 : Language} (θ : L' →ᴸ L3) : θ ∘ᴸ ϕ.sumElim ψ = (θ ∘ᴸ ϕ).sumElim (θ ∘ᴸ ψ) := LHom.funext (funext fun _n => Sum.comp_elim _ _ _) (funext fun _n => Sum.comp_elim _ _ _) end SumElim section SumMap variable {L₁ L₂ : Language} (ψ : L₁ →ᴸ L₂) /-- The map between two sum-languages induced by maps on the two factors. -/ @[simps] def sumMap : L.sum L₁ →ᴸ L'.sum L₂ where onFunction _n := Sum.map (fun f => ϕ.onFunction f) fun f => ψ.onFunction f onRelation _n := Sum.map (fun f => ϕ.onRelation f) fun f => ψ.onRelation f @[simp] theorem sumMap_comp_inl : ϕ.sumMap ψ ∘ᴸ LHom.sumInl = LHom.sumInl ∘ᴸ ϕ := LHom.funext (funext fun _ => rfl) (funext fun _ => rfl) @[simp] theorem sumMap_comp_inr : ϕ.sumMap ψ ∘ᴸ LHom.sumInr = LHom.sumInr ∘ᴸ ψ := LHom.funext (funext fun _ => rfl) (funext fun _ => rfl) end SumMap /-- A language homomorphism is injective when all the maps between symbol types are. -/ protected structure Injective : Prop where onFunction {n} : Function.Injective fun f : L.Functions n => onFunction ϕ f onRelation {n} : Function.Injective fun R : L.Relations n => onRelation ϕ R /-- Pulls an `L`-structure along a language map `ϕ : L →ᴸ L'`, and then expands it to an `L'`-structure arbitrarily. -/ noncomputable def defaultExpansion (ϕ : L →ᴸ L') [∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => onFunction ϕ f)] [∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => onRelation ϕ r)] (M : Type*) [Inhabited M] [L.Structure M] : L'.Structure M where funMap {n} f xs := if h' : f ∈ Set.range fun f : L.Functions n => onFunction ϕ f then funMap h'.choose xs else default RelMap {n} r xs := if h' : r ∈ Set.range fun r : L.Relations n => onRelation ϕ r then RelMap h'.choose xs else default /-- A language homomorphism is an expansion on a structure if it commutes with the interpretation of all symbols on that structure. -/ class IsExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] : Prop where map_onFunction : ∀ {n} (f : L.Functions n) (x : Fin n → M), funMap (ϕ.onFunction f) x = funMap f x := by exact fun {n} => isEmptyElim map_onRelation : ∀ {n} (R : L.Relations n) (x : Fin n → M), RelMap (ϕ.onRelation R) x = RelMap R x := by exact fun {n} => isEmptyElim @[simp] theorem map_onFunction {M : Type*} [L.Structure M] [L'.Structure M] [ϕ.IsExpansionOn M] {n} (f : L.Functions n) (x : Fin n → M) : funMap (ϕ.onFunction f) x = funMap f x := IsExpansionOn.map_onFunction f x @[simp] theorem map_onRelation {M : Type*} [L.Structure M] [L'.Structure M] [ϕ.IsExpansionOn M] {n} (R : L.Relations n) (x : Fin n → M) : RelMap (ϕ.onRelation R) x = RelMap R x := IsExpansionOn.map_onRelation R x instance id_isExpansionOn (M : Type*) [L.Structure M] : IsExpansionOn (LHom.id L) M := ⟨fun _ _ => rfl, fun _ _ => rfl⟩ instance ofIsEmpty_isExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] [L.IsAlgebraic] [L.IsRelational] : IsExpansionOn (LHom.ofIsEmpty L L') M where instance sumElim_isExpansionOn {L'' : Language} (ψ : L'' →ᴸ L') (M : Type*) [L.Structure M] [L'.Structure M] [L''.Structure M] [ϕ.IsExpansionOn M] [ψ.IsExpansionOn M] : (ϕ.sumElim ψ).IsExpansionOn M := ⟨fun f _ => Sum.casesOn f (by simp) (by simp), fun R _ => Sum.casesOn R (by simp) (by simp)⟩ instance sumMap_isExpansionOn {L₁ L₂ : Language} (ψ : L₁ →ᴸ L₂) (M : Type*) [L.Structure M] [L'.Structure M] [L₁.Structure M] [L₂.Structure M] [ϕ.IsExpansionOn M] [ψ.IsExpansionOn M] : (ϕ.sumMap ψ).IsExpansionOn M := ⟨fun f _ => Sum.casesOn f (by simp) (by simp), fun R _ => Sum.casesOn R (by simp) (by simp)⟩ instance sumInl_isExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] : (LHom.sumInl : L →ᴸ L.sum L').IsExpansionOn M := ⟨fun _f _ => rfl, fun _R _ => rfl⟩ instance sumInr_isExpansionOn (M : Type*) [L.Structure M] [L'.Structure M] : (LHom.sumInr : L' →ᴸ L.sum L').IsExpansionOn M := ⟨fun _f _ => rfl, fun _R _ => rfl⟩ @[simp] theorem funMap_sumInl [(L.sum L').Structure M] [(LHom.sumInl : L →ᴸ L.sum L').IsExpansionOn M] {n} {f : L.Functions n} {x : Fin n → M} : @funMap (L.sum L') M _ n (Sum.inl f) x = funMap f x := (LHom.sumInl : L →ᴸ L.sum L').map_onFunction f x @[simp] theorem funMap_sumInr [(L'.sum L).Structure M] [(LHom.sumInr : L →ᴸ L'.sum L).IsExpansionOn M] {n} {f : L.Functions n} {x : Fin n → M} : @funMap (L'.sum L) M _ n (Sum.inr f) x = funMap f x := (LHom.sumInr : L →ᴸ L'.sum L).map_onFunction f x theorem sumInl_injective : (LHom.sumInl : L →ᴸ L.sum L').Injective := ⟨fun h => Sum.inl_injective h, fun h => Sum.inl_injective h⟩ theorem sumInr_injective : (LHom.sumInr : L' →ᴸ L.sum L').Injective := ⟨fun h => Sum.inr_injective h, fun h => Sum.inr_injective h⟩ instance (priority := 100) isExpansionOn_reduct (ϕ : L →ᴸ L') (M : Type*) [L'.Structure M] : @IsExpansionOn L L' ϕ M (ϕ.reduct M) _ := letI := ϕ.reduct M ⟨fun _f _ => rfl, fun _R _ => rfl⟩ theorem Injective.isExpansionOn_default {ϕ : L →ᴸ L'} [∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => ϕ.onFunction f)] [∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => ϕ.onRelation r)] (h : ϕ.Injective) (M : Type*) [Inhabited M] [L.Structure M] : @IsExpansionOn L L' ϕ M _ (ϕ.defaultExpansion M) := by letI := ϕ.defaultExpansion M refine ⟨fun {n} f xs => ?_, fun {n} r xs => ?_⟩ · have hf : ϕ.onFunction f ∈ Set.range fun f : L.Functions n => ϕ.onFunction f := ⟨f, rfl⟩ refine (dif_pos hf).trans ?_ rw [h.onFunction hf.choose_spec] · have hr : ϕ.onRelation r ∈ Set.range fun r : L.Relations n => ϕ.onRelation r := ⟨r, rfl⟩ refine (dif_pos hr).trans ?_ rw [h.onRelation hr.choose_spec] end LHom /-- A language equivalence maps the symbols of one language to symbols of another bijectively. -/ structure LEquiv (L L' : Language) where /-- The forward language homomorphism -/ toLHom : L →ᴸ L' /-- The inverse language homomorphism -/ invLHom : L' →ᴸ L left_inv : invLHom.comp toLHom = LHom.id L right_inv : toLHom.comp invLHom = LHom.id L' @[inherit_doc] infixl:10 " ≃ᴸ " => LEquiv -- \^L namespace LEquiv variable (L) in /-- The identity equivalence from a first-order language to itself. -/ @[simps] protected def refl : L ≃ᴸ L := ⟨LHom.id L, LHom.id L, LHom.comp_id _, LHom.comp_id _⟩ instance : Inhabited (L ≃ᴸ L) := ⟨LEquiv.refl L⟩ variable {L'' : Language} (e' : L' ≃ᴸ L'') (e : L ≃ᴸ L') /-- The inverse of an equivalence of first-order languages. -/ @[simps] protected def symm : L' ≃ᴸ L := ⟨e.invLHom, e.toLHom, e.right_inv, e.left_inv⟩ /-- The composition of equivalences of first-order languages. -/ @[simps, trans] protected def trans (e : L ≃ᴸ L') (e' : L' ≃ᴸ L'') : L ≃ᴸ L'' := ⟨e'.toLHom.comp e.toLHom, e.invLHom.comp e'.invLHom, by rw [LHom.comp_assoc, ← LHom.comp_assoc e'.invLHom, e'.left_inv, LHom.id_comp, e.left_inv], by rw [LHom.comp_assoc, ← LHom.comp_assoc e.toLHom, e.right_inv, LHom.id_comp, e'.right_inv]⟩ end LEquiv section ConstantsOn variable (α : Type u') /-- The type of functions for a language consisting only of constant symbols. -/ @[simp] def constantsOnFunc : ℕ → Type u' | 0 => α | (_ + 1) => PEmpty /-- A language with constants indexed by a type. -/ @[simps] def constantsOn : Language.{u', 0} := ⟨constantsOnFunc α, fun _ => Empty⟩ variable {α} theorem constantsOn_constants : (constantsOn α).Constants = α := rfl instance isAlgebraic_constantsOn : IsAlgebraic (constantsOn α) := by unfold constantsOn infer_instance instance isEmpty_functions_constantsOn_succ {n : ℕ} : IsEmpty ((constantsOn α).Functions (n + 1)) := inferInstanceAs (IsEmpty PEmpty) instance isRelational_constantsOn [_ie : IsEmpty α] : IsRelational (constantsOn α) := fun n => Nat.casesOn n _ie inferInstance theorem card_constantsOn : (constantsOn α).card = #α := by simp [card_eq_card_functions_add_card_relations, sum_nat_eq_add_sum_succ] /-- Gives a `constantsOn α` structure to a type by assigning each constant a value. -/ def constantsOn.structure (f : α → M) : (constantsOn α).Structure M where funMap := fun {n} c _ => match n, c with | 0, c => f c variable {β : Type v'} /-- A map between index types induces a map between constant languages. -/ def LHom.constantsOnMap (f : α → β) : constantsOn α →ᴸ constantsOn β where onFunction := fun {n} c => match n, c with | 0, c => f c theorem constantsOnMap_isExpansionOn {f : α → β} {fα : α → M} {fβ : β → M} (h : fβ ∘ f = fα) : @LHom.IsExpansionOn _ _ (LHom.constantsOnMap f) M (constantsOn.structure fα) (constantsOn.structure fβ) := by letI := constantsOn.structure fα letI := constantsOn.structure fβ exact ⟨fun {n} => Nat.casesOn n (fun F _x => (congr_fun h F :)) fun n F => isEmptyElim F, fun R => isEmptyElim R⟩ end ConstantsOn section WithConstants variable (L) section variable (α : Type w') /-- Extends a language with a constant for each element of a parameter set in `M`. -/ def withConstants : Language.{max u w', v} := L.sum (constantsOn α) @[inherit_doc FirstOrder.Language.withConstants] scoped[FirstOrder] notation:95 L "[[" α "]]" => Language.withConstants L α @[simp] theorem card_withConstants : L[[α]].card = Cardinal.lift.{w'} L.card + Cardinal.lift.{max u v} #α := by rw [withConstants, card_sum, card_constantsOn] /-- The language map adding constants. -/ @[simps!] def lhomWithConstants : L →ᴸ L[[α]] := LHom.sumInl theorem lhomWithConstants_injective : (L.lhomWithConstants α).Injective := LHom.sumInl_injective variable {α} /-- The constant symbol indexed by a particular element. -/ protected def con (a : α) : L[[α]].Constants := Sum.inr a variable {L} (α) /-- Adds constants to a language map. -/ def LHom.addConstants {L' : Language} (φ : L →ᴸ L') : L[[α]] →ᴸ L'[[α]] := φ.sumMap (LHom.id _) instance paramsStructure (A : Set α) : (constantsOn A).Structure α := constantsOn.structure (↑) variable (L) /-- The language map removing an empty constant set. -/ @[simps] def LEquiv.addEmptyConstants [ie : IsEmpty α] : L ≃ᴸ L[[α]] where toLHom := lhomWithConstants L α invLHom := LHom.sumElim (LHom.id L) (LHom.ofIsEmpty (constantsOn α) L) left_inv := by rw [lhomWithConstants, LHom.sumElim_comp_inl] right_inv := by simp only [LHom.comp_sumElim, lhomWithConstants, LHom.comp_id] exact _root_.trans (congr rfl (Subsingleton.elim _ _)) LHom.sumElim_inl_inr variable {α} {β : Type*} @[simp] theorem withConstants_funMap_sumInl [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {f : L.Functions n} {x : Fin n → M} : @funMap (L[[α]]) M _ n (Sum.inl f) x = funMap f x := (lhomWithConstants L α).map_onFunction f x @[simp] theorem withConstants_relMap_sumInl [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {R : L.Relations n} {x : Fin n → M} : @RelMap (L[[α]]) M _ n (Sum.inl R) x = RelMap R x := (lhomWithConstants L α).map_onRelation R x /-- The language map extending the constant set. -/ def lhomWithConstantsMap (f : α → β) : L[[α]] →ᴸ L[[β]] := LHom.sumMap (LHom.id L) (LHom.constantsOnMap f) @[simp] theorem LHom.map_constants_comp_sumInl {f : α → β} : (L.lhomWithConstantsMap f).comp LHom.sumInl = L.lhomWithConstants β := by ext <;> rfl end open FirstOrder instance constantsOnSelfStructure : (constantsOn M).Structure M := constantsOn.structure id instance withConstantsSelfStructure : L[[M]].Structure M := Language.sumStructure _ _ M instance withConstants_self_expansion : (lhomWithConstants L M).IsExpansionOn M := ⟨fun _ _ => rfl, fun _ _ => rfl⟩ variable (α : Type*) [(constantsOn α).Structure M] instance withConstantsStructure : L[[α]].Structure M := Language.sumStructure _ _ _ instance withConstants_expansion : (L.lhomWithConstants α).IsExpansionOn M := ⟨fun _ _ => rfl, fun _ _ => rfl⟩ instance addEmptyConstants_is_expansion_on' : (LEquiv.addEmptyConstants L (∅ : Set M)).toLHom.IsExpansionOn M := L.withConstants_expansion _ instance addEmptyConstants_symm_isExpansionOn : (LEquiv.addEmptyConstants L (∅ : Set M)).symm.toLHom.IsExpansionOn M := LHom.sumElim_isExpansionOn _ _ _ instance addConstants_expansion {L' : Language} [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] : (φ.addConstants α).IsExpansionOn M := LHom.sumMap_isExpansionOn _ _ M @[simp] theorem withConstants_funMap_sumInr {a : α} {x : Fin 0 → M} : @funMap (L[[α]]) M _ 0 (Sum.inr a : L[[α]].Functions 0) x = L.con a := by rw [Unique.eq_default x] exact (LHom.sumInr : constantsOn α →ᴸ L.sum _).map_onFunction _ _ variable {α} (A : Set M) @[simp] theorem coe_con {a : A} : (L.con a : M) = a := rfl variable {A} {B : Set M} (h : A ⊆ B) instance constantsOnMap_inclusion_isExpansionOn : (LHom.constantsOnMap (Set.inclusion h)).IsExpansionOn M := constantsOnMap_isExpansionOn rfl instance map_constants_inclusion_isExpansionOn : (L.lhomWithConstantsMap (Set.inclusion h)).IsExpansionOn M := LHom.sumMap_isExpansionOn _ _ _ end WithConstants end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/FinitelyGenerated.lean
import Mathlib.Data.Set.Finite.Lemmas import Mathlib.ModelTheory.Substructures /-! # Finitely Generated First-Order Structures This file defines what it means for a first-order (sub)structure to be finitely or countably generated, similarly to other finitely-generated objects in the algebra library. ## Main Definitions - `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated. - `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated. - `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated. - `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated. ## TODO Develop a more unified definition of finite generation using the theory of closure operators, or use this definition of finite generation to define the others. -/ open FirstOrder Set namespace FirstOrder namespace Language open Structure variable {L : Language} {M : Type*} [L.Structure M] namespace Substructure /-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ def FG (N : L.Substructure M) : Prop := ∃ S : Finset M, closure L S = N theorem fg_def {N : L.Substructure M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ closure L S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), closure L (range s) = N := by rw [fg_def] constructor · rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ · rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ theorem fg_bot : (⊥ : L.Substructure M).FG := ⟨∅, by rw [Finset.coe_empty, closure_empty]⟩ instance instInhabited_fg : Inhabited { S : L.Substructure M // S.FG } := ⟨⊥, fg_bot⟩ theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) := fg_closure (finite_singleton x) theorem FG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG := let ⟨t₁, ht₁⟩ := fg_def.1 hN₁ let ⟨t₂, ht₂⟩ := fg_def.1 hN₂ fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩ theorem FG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.FG) : (s.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).FG) : s.FG := by rcases hs with ⟨t, h⟩ rw [fg_def] refine ⟨f ⁻¹' t, t.finite_toSet.preimage f.injective.injOn, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h] at h' exact Hom.map_le_range h' theorem FG.of_finite {s : L.Substructure M} [h : Finite s] : s.FG := ⟨Set.Finite.toFinset h, by simp only [Finite.coe_toFinset, closure_eq]⟩ theorem FG.finite [L.IsRelational] {S : L.Substructure M} (h : S.FG) : Finite S := by obtain ⟨s, rfl⟩ := h have hs := s.finite_toSet rw [← closure_eq_of_isRelational L (s : Set M)] at hs exact hs theorem fg_iff_finite [L.IsRelational] {S : L.Substructure M} : S.FG ↔ Finite S := ⟨FG.finite, fun _ => FG.of_finite⟩ /-- A substructure of `M` is countably generated if it is the closure of a countable subset of `M`. -/ def CG (N : L.Substructure M) : Prop := ∃ S : Set M, S.Countable ∧ closure L S = N theorem cg_def {N : L.Substructure M} : N.CG ↔ ∃ S : Set M, S.Countable ∧ closure L S = N := Iff.refl _ theorem FG.cg {N : L.Substructure M} (h : N.FG) : N.CG := by obtain ⟨s, hf, rfl⟩ := fg_def.1 h exact ⟨s, hf.countable, rfl⟩ theorem cg_iff_empty_or_exists_nat_generating_family {N : L.Substructure M} : N.CG ↔ N = (∅ : Set M) ∨ ∃ s : ℕ → M, closure L (range s) = N := by rw [cg_def] constructor · rintro ⟨S, Scount, hS⟩ rcases eq_empty_or_nonempty (N : Set M) with h | h · exact Or.intro_left _ h obtain ⟨f, h'⟩ := (Scount.union (Set.countable_singleton h.some)).exists_eq_range (singleton_nonempty h.some).inr refine Or.intro_right _ ⟨f, ?_⟩ rw [← h', closure_union, hS, sup_eq_left, closure_le] exact singleton_subset_iff.2 h.some_mem · intro h rcases h with h | h · refine ⟨∅, countable_empty, closure_eq_of_le (empty_subset _) ?_⟩ rw [← SetLike.coe_subset_coe, h] exact empty_subset _ · obtain ⟨f, rfl⟩ := h exact ⟨range f, countable_range _, rfl⟩ theorem cg_bot : (⊥ : L.Substructure M).CG := fg_bot.cg theorem cg_closure {s : Set M} (hs : s.Countable) : CG (closure L s) := ⟨s, hs, rfl⟩ theorem cg_closure_singleton (x : M) : CG (closure L ({x} : Set M)) := (fg_closure_singleton x).cg theorem CG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.CG) (hN₂ : N₂.CG) : (N₁ ⊔ N₂).CG := let ⟨t₁, ht₁⟩ := cg_def.1 hN₁ let ⟨t₂, ht₂⟩ := cg_def.1 hN₂ cg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩ theorem CG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.CG) : (s.map f).CG := let ⟨t, ht⟩ := cg_def.1 hs cg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ theorem CG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).CG) : s.CG := by rcases hs with ⟨t, h1, h2⟩ rw [cg_def] refine ⟨f ⁻¹' t, h1.preimage f.injective, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h2, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h2] at h' exact Hom.map_le_range h' theorem cg_iff_countable [Countable (Σ l, L.Functions l)] {s : L.Substructure M} : s.CG ↔ Countable s := by refine ⟨?_, fun h => ⟨s, h.to_set, s.closure_eq⟩⟩ rintro ⟨s, h, rfl⟩ exact h.substructure_closure L theorem cg_of_countable {s : L.Substructure M} [h : Countable s] : s.CG := ⟨s, h.to_set, s.closure_eq⟩ end Substructure open Substructure namespace Structure variable (L) (M) /-- A structure is finitely generated if it is the closure of a finite subset. -/ class FG : Prop where out : (⊤ : L.Substructure M).FG /-- A structure is countably generated if it is the closure of a countable subset. -/ class CG : Prop where out : (⊤ : L.Substructure M).CG variable {L M} theorem fg_def : FG L M ↔ (⊤ : L.Substructure M).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- An equivalent expression of `Structure.FG` in terms of `Set.Finite` instead of `Finset`. -/ theorem fg_iff : FG L M ↔ ∃ S : Set M, S.Finite ∧ closure L S = (⊤ : L.Substructure M) := by rw [fg_def, Substructure.fg_def] theorem FG.range {N : Type*} [L.Structure N] (h : FG L M) (f : M →[L] N) : f.range.FG := by rw [Hom.range_eq_map] exact (fg_def.1 h).map f theorem FG.map_of_surjective {N : Type*} [L.Structure N] (h : FG L M) (f : M →[L] N) (hs : Function.Surjective f) : FG L N := by rw [← Hom.range_eq_top] at hs rw [fg_def, ← hs] exact h.range f theorem FG.countable_hom (N : Type*) [L.Structure N] [Countable N] (h : FG L M) : Countable (M →[L] N) := by let ⟨S, finite_S, closure_S⟩ := fg_iff.1 h let g : (M →[L] N) → (S → N) := fun f ↦ f ∘ (↑) have g_inj : Function.Injective g := by intro f f' h apply Hom.eq_of_eqOn_dense closure_S intro x x_in_S exact congr_fun h ⟨x, x_in_S⟩ have : Finite ↑S := (S.finite_coe_iff).2 finite_S exact Function.Embedding.countable ⟨g, g_inj⟩ instance FG.instCountable_hom (N : Type*) [L.Structure N] [Countable N] [h : FG L M] : Countable (M →[L] N) := FG.countable_hom N h theorem FG.countable_embedding (N : Type*) [L.Structure N] [Countable N] (_ : FG L M) : Countable (M ↪[L] N) := Function.Embedding.countable ⟨Embedding.toHom, Embedding.toHom_injective⟩ instance Fg.instCountable_embedding (N : Type*) [L.Structure N] [Countable N] [h : FG L M] : Countable (M ↪[L] N) := FG.countable_embedding N h theorem FG.of_finite [Finite M] : FG L M := by simp only [fg_def, Substructure.FG.of_finite] theorem FG.finite [L.IsRelational] (h : FG L M) : Finite M := Finite.of_finite_univ (Substructure.FG.finite (fg_def.1 h)) theorem fg_iff_finite [L.IsRelational] : FG L M ↔ Finite M := ⟨FG.finite, fun _ => FG.of_finite⟩ theorem cg_def : CG L M ↔ (⊤ : L.Substructure M).CG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- An equivalent expression of `Structure.cg`. -/ theorem cg_iff : CG L M ↔ ∃ S : Set M, S.Countable ∧ closure L S = (⊤ : L.Substructure M) := by rw [cg_def, Substructure.cg_def] theorem CG.range {N : Type*} [L.Structure N] (h : CG L M) (f : M →[L] N) : f.range.CG := by rw [Hom.range_eq_map] exact (cg_def.1 h).map f theorem CG.map_of_surjective {N : Type*} [L.Structure N] (h : CG L M) (f : M →[L] N) (hs : Function.Surjective f) : CG L N := by rw [← Hom.range_eq_top] at hs rw [cg_def, ← hs] exact h.range f theorem cg_iff_countable [Countable (Σ l, L.Functions l)] : CG L M ↔ Countable M := by rw [cg_def, Substructure.cg_iff_countable, topEquiv.toEquiv.countable_iff] theorem cg_of_countable [Countable M] : CG L M := by simp only [cg_def, Substructure.cg_of_countable] theorem FG.cg (h : FG L M) : CG L M := cg_def.2 (fg_def.1 h).cg instance (priority := 100) cg_of_fg [h : FG L M] : CG L M := h.cg end Structure theorem Equiv.fg_iff {N : Type*} [L.Structure N] (f : M ≃[L] N) : Structure.FG L M ↔ Structure.FG L N := ⟨fun h => h.map_of_surjective f.toHom f.toEquiv.surjective, fun h => h.map_of_surjective f.symm.toHom f.toEquiv.symm.surjective⟩ theorem Substructure.fg_iff_structure_fg (S : L.Substructure M) : S.FG ↔ Structure.FG L S := by rw [Structure.fg_def] refine ⟨fun h => FG.of_map_embedding S.subtype ?_, fun h => ?_⟩ · rw [← Hom.range_eq_map, range_subtype] exact h · have h := h.map S.subtype.toHom rw [← Hom.range_eq_map, range_subtype] at h exact h theorem Equiv.cg_iff {N : Type*} [L.Structure N] (f : M ≃[L] N) : Structure.CG L M ↔ Structure.CG L N := ⟨fun h => h.map_of_surjective f.toHom f.toEquiv.surjective, fun h => h.map_of_surjective f.symm.toHom f.toEquiv.symm.surjective⟩ theorem Substructure.cg_iff_structure_cg (S : L.Substructure M) : S.CG ↔ Structure.CG L S := by rw [Structure.cg_def] refine ⟨fun h => CG.of_map_embedding S.subtype ?_, fun h => ?_⟩ · rw [← Hom.range_eq_map, range_subtype] exact h · have h := h.map S.subtype.toHom rw [← Hom.range_eq_map, range_subtype] at h exact h theorem Substructure.countable_fg_substructures_of_countable [Countable M] : Countable { S : L.Substructure M // S.FG } := by let g : { S : L.Substructure M // S.FG } → Finset M := fun S ↦ Exists.choose S.prop have g_inj : Function.Injective g := by intro S S' h apply Subtype.eq rw [(Exists.choose_spec S.prop).symm, (Exists.choose_spec S'.prop).symm] exact congr_arg (closure L ∘ SetLike.coe) h exact Function.Embedding.countable ⟨g, g_inj⟩ instance Substructure.instCountable_fg_substructures_of_countable [Countable M] : Countable { S : L.Substructure M // S.FG } := countable_fg_substructures_of_countable end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Order.lean
import Mathlib.Algebra.CharZero.Infinite import Mathlib.Data.Rat.Encodable import Mathlib.Data.Finset.Sort import Mathlib.ModelTheory.Complexity import Mathlib.ModelTheory.Fraisse import Mathlib.Order.CountableDenseLinearOrder /-! # Ordered First-Ordered Structures This file defines ordered first-order languages and structures, as well as their theories. ## Main Definitions - `FirstOrder.Language.order` is the language consisting of a single relation representing `≤`. - `FirstOrder.Language.IsOrdered` points out a specific symbol in a language as representing `≤`. - `FirstOrder.Language.OrderedStructure` indicates that the `≤` symbol in an ordered language is interpreted as the actual relation `≤` in a particular structure. - `FirstOrder.Language.linearOrderTheory` and similar define the theories of preorders, partial orders, and linear orders. - `FirstOrder.Language.dlo` defines the theory of dense linear orders without endpoints, a particularly useful example in model theory. - `FirstOrder.Language.orderStructure` is the structure on an ordered type, assigning the symbol representing `≤` to the actual relation `≤`. - Conversely, `FirstOrder.Language.LEOfStructure`, `FirstOrder.Language.preorderOfModels`, `FirstOrder.Language.partialOrderOfModels`, and `FirstOrder.Language.linearOrderOfModels` are the orders induced by first-order structures modelling the relevant theory. ## Main Results - `PartialOrder`s model the theory of partial orders, `LinearOrder`s model the theory of linear orders, and dense linear orders without endpoints model `Language.dlo`. - Under `L.orderedStructure` assumptions, elements of any `L.HomClass M N` are monotone, and strictly monotone if injective. - Under `Language.order.orderedStructure` assumptions, any `OrderHomClass` has an instance of `L.HomClass M N`, while `M ↪o N` and any `OrderIsoClass` have an instance of `L.StrongHomClass M N`. - `FirstOrder.Language.isFraisseLimit_of_countable_nonempty_dlo` shows that any countable nonempty model of the theory of linear orders is a Fraïssé limit of the class of finite models of the theory of linear orders. - `FirstOrder.Language.isFraisse_finite_linear_order` shows that the class of finite models of the theory of linear orders is Fraïssé. - `FirstOrder.Language.aleph0_categorical_dlo` shows that the theory of dense linear orders is `ℵ₀`-categorical, and thus complete. -/ universe u v w w' namespace FirstOrder namespace Language open FirstOrder Structure variable {L : Language.{u, v}} {α : Type w} {M : Type w'} {n : ℕ} /-- The type of relations for the language of orders, consisting of a single binary relation `le`. -/ inductive orderRel : ℕ → Type | le : orderRel 2 deriving DecidableEq /-- The relational language consisting of a single relation representing `≤`. -/ protected def order : Language := ⟨fun _ => Empty, orderRel⟩ deriving IsRelational namespace order @[simp] lemma forall_relations {P : ∀ (n) (_ : Language.order.Relations n), Prop} : (∀ {n} (R), P n R) ↔ P 2 .le := ⟨fun h => h _, fun h n R => match n, R with | 2, .le => h⟩ instance instSubsingleton : Subsingleton (Language.order.Relations n) := ⟨by rintro ⟨⟩ ⟨⟩; rfl⟩ instance : IsEmpty (Language.order.Relations 0) := ⟨fun x => by cases x⟩ instance : Unique (Σ n, Language.order.Relations n) := ⟨⟨⟨2, .le⟩⟩, fun ⟨n, R⟩ => match n, R with | 2, .le => rfl⟩ instance : Unique Language.order.Symbols := ⟨⟨Sum.inr default⟩, by have : IsEmpty (Σ n, Language.order.Functions n) := isEmpty_sigma.2 inferInstance simp only [Symbols, Sum.forall, reduceCtorEq, Sum.inr.injEq, IsEmpty.forall_iff, true_and] exact Unique.eq_default⟩ @[simp] lemma card_eq_one : Language.order.card = 1 := by simp [card] end order /-- A language is ordered if it has a symbol representing `≤`. -/ class IsOrdered (L : Language.{u, v}) where /-- The relation symbol representing `≤`. -/ leSymb : L.Relations 2 export IsOrdered (leSymb) instance : IsOrdered Language.order := ⟨.le⟩ lemma order.relation_eq_leSymb : (R : Language.order.Relations 2) → R = leSymb | .le => rfl section IsOrdered variable [IsOrdered L] /-- Joins two terms `t₁, t₂` in a formula representing `t₁ ≤ t₂`. -/ def Term.le (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n := leSymb.boundedFormula₂ t₁ t₂ /-- Joins two terms `t₁, t₂` in a formula representing `t₁ < t₂`. -/ def Term.lt (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n := t₁.le t₂ ⊓ ∼(t₂.le t₁) variable (L) /-- The language homomorphism sending the unique symbol `≤` of `Language.order` to `≤` in an ordered language. -/ @[simps] def orderLHom : Language.order →ᴸ L where onRelation | _, .le => leSymb @[simp] theorem orderLHom_leSymb : (orderLHom L).onRelation leSymb = (leSymb : L.Relations 2) := rfl @[simp] theorem orderLHom_order : orderLHom Language.order = LHom.id Language.order := LHom.funext (Subsingleton.elim _ _) (Subsingleton.elim _ _) /-- The theory of preorders. -/ def preorderTheory : L.Theory := {leSymb.reflexive, leSymb.transitive} instance : Theory.IsUniversal L.preorderTheory := ⟨by simp only [preorderTheory, Set.mem_insert_iff, Set.mem_singleton_iff, forall_eq_or_imp, forall_eq] exact ⟨leSymb.isUniversal_reflexive, leSymb.isUniversal_transitive⟩⟩ /-- The theory of partial orders. -/ def partialOrderTheory : L.Theory := insert leSymb.antisymmetric L.preorderTheory instance : Theory.IsUniversal L.partialOrderTheory := Theory.IsUniversal.insert leSymb.isUniversal_antisymmetric /-- The theory of linear orders. -/ def linearOrderTheory : L.Theory := insert leSymb.total L.partialOrderTheory instance : Theory.IsUniversal L.linearOrderTheory := Theory.IsUniversal.insert leSymb.isUniversal_total example [L.Structure M] [M ⊨ L.linearOrderTheory] (S : L.Substructure M) : S ⊨ L.linearOrderTheory := inferInstance /-- A sentence indicating that an order has no top element: $\forall x, \exists y, \neg y \le x$. -/ def noTopOrderSentence : L.Sentence := ∀' ∃' ∼((&1).le &0) /-- A sentence indicating that an order has no bottom element: $\forall x, \exists y, \neg x \le y$. -/ def noBotOrderSentence : L.Sentence := ∀' ∃' ∼((&0).le &1) /-- A sentence indicating that an order is dense: $\forall x, \forall y, x < y \to \exists z, x < z \wedge z < y$. -/ def denselyOrderedSentence : L.Sentence := ∀' ∀' ((&0).lt &1 ⟹ ∃' ((&0).lt &2 ⊓ (&2).lt &1)) /-- The theory of dense linear orders without endpoints. -/ def dlo : L.Theory := L.linearOrderTheory ∪ {L.noTopOrderSentence, L.noBotOrderSentence, L.denselyOrderedSentence} variable [L.Structure M] instance [h : M ⊨ L.dlo] : M ⊨ L.linearOrderTheory := h.mono Set.subset_union_left instance [h : M ⊨ L.linearOrderTheory] : M ⊨ L.partialOrderTheory := h.mono (Set.subset_insert _ _) instance [h : M ⊨ L.partialOrderTheory] : M ⊨ L.preorderTheory := h.mono (Set.subset_insert _ _) end IsOrdered instance sum.instIsOrdered : IsOrdered (L.sum Language.order) := ⟨Sum.inr IsOrdered.leSymb⟩ variable (L M) /-- Any linearly-ordered type is naturally a structure in the language `Language.order`. This is not an instance, because sometimes the `Language.order.Structure` is defined first. -/ def orderStructure [LE M] : Language.order.Structure M where RelMap | .le => (fun x => x 0 ≤ x 1) /-- A structure is ordered if its language has a `≤` symbol whose interpretation is `≤`. -/ class OrderedStructure [L.IsOrdered] [LE M] [L.Structure M] : Prop where relMap_leSymb : ∀ (x : Fin 2 → M), RelMap (leSymb : L.Relations 2) x ↔ (x 0 ≤ x 1) export OrderedStructure (relMap_leSymb) attribute [simp] relMap_leSymb variable {L M} section order_to_structure variable [IsOrdered L] [L.Structure M] section LE variable [LE M] instance [Language.order.Structure M] [Language.order.OrderedStructure M] [(orderLHom L).IsExpansionOn M] : L.OrderedStructure M where relMap_leSymb x := by rw [← orderLHom_leSymb L, LHom.IsExpansionOn.map_onRelation, relMap_leSymb] variable [L.OrderedStructure M] instance [Language.order.Structure M] [Language.order.OrderedStructure M] : LHom.IsExpansionOn (orderLHom L) M where map_onRelation := by simp [order.relation_eq_leSymb] instance (S : L.Substructure M) : L.OrderedStructure S := ⟨fun x => relMap_leSymb (S.subtype ∘ x)⟩ @[simp] theorem Term.realize_le {t₁ t₂ : L.Term (α ⊕ (Fin n))} {v : α → M} {xs : Fin n → M} : (t₁.le t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) ≤ t₂.realize (Sum.elim v xs) := by simp [Term.le] theorem realize_noTopOrder_iff : M ⊨ L.noTopOrderSentence ↔ NoTopOrder M := by simp only [noTopOrderSentence, Sentence.Realize, Formula.Realize, BoundedFormula.realize_all, BoundedFormula.realize_ex, BoundedFormula.realize_not, Term.realize_le] refine ⟨fun h => ⟨fun a => h a⟩, ?_⟩ intro h a exact exists_not_le a theorem realize_noBotOrder_iff : M ⊨ L.noBotOrderSentence ↔ NoBotOrder M := by simp only [noBotOrderSentence, Sentence.Realize, Formula.Realize, BoundedFormula.realize_all, BoundedFormula.realize_ex, BoundedFormula.realize_not, Term.realize_le] refine ⟨fun h => ⟨fun a => h a⟩, ?_⟩ intro h a exact exists_not_ge a variable (L M) @[simp] theorem realize_noTopOrder [h : NoTopOrder M] : M ⊨ L.noTopOrderSentence := realize_noTopOrder_iff.2 h @[simp] theorem realize_noBotOrder [h : NoBotOrder M] : M ⊨ L.noBotOrderSentence := realize_noBotOrder_iff.2 h theorem noTopOrder_of_dlo [M ⊨ L.dlo] : NoTopOrder M := realize_noTopOrder_iff.1 (L.dlo.realize_sentence_of_mem (by simp only [dlo, Set.union_insert, Set.union_singleton, Set.mem_insert_iff, true_or])) theorem noBotOrder_of_dlo [M ⊨ L.dlo] : NoBotOrder M := realize_noBotOrder_iff.1 (L.dlo.realize_sentence_of_mem (by simp only [dlo, Set.union_insert, Set.union_singleton, Set.mem_insert_iff, true_or, or_true])) end LE @[simp] theorem orderedStructure_iff [LE M] [Language.order.Structure M] [Language.order.OrderedStructure M] : L.OrderedStructure M ↔ LHom.IsExpansionOn (orderLHom L) M := ⟨fun _ => inferInstance, fun _ => inferInstance⟩ section Preorder variable [Preorder M] [L.OrderedStructure M] instance model_preorder : M ⊨ L.preorderTheory := by simp only [preorderTheory, Theory.model_insert_iff, Relations.realize_reflexive, relMap_leSymb, Theory.model_singleton_iff, Relations.realize_transitive] exact ⟨le_refl, fun _ _ _ => le_trans⟩ @[simp] theorem Term.realize_lt {t₁ t₂ : L.Term (α ⊕ (Fin n))} {v : α → M} {xs : Fin n → M} : (t₁.lt t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) < t₂.realize (Sum.elim v xs) := by simp [Term.lt, lt_iff_le_not_ge] theorem realize_denselyOrdered_iff : M ⊨ L.denselyOrderedSentence ↔ DenselyOrdered M := by simp only [denselyOrderedSentence, Sentence.Realize, Formula.Realize, BoundedFormula.realize_imp, BoundedFormula.realize_all, Term.realize_lt, BoundedFormula.realize_ex, BoundedFormula.realize_inf] refine ⟨fun h => ⟨fun a b ab => h a b ab⟩, ?_⟩ intro h a b ab exact exists_between ab @[simp] theorem realize_denselyOrdered [h : DenselyOrdered M] : M ⊨ L.denselyOrderedSentence := realize_denselyOrdered_iff.2 h variable (L) (M) theorem denselyOrdered_of_dlo [M ⊨ L.dlo] : DenselyOrdered M := realize_denselyOrdered_iff.1 (L.dlo.realize_sentence_of_mem (by simp only [dlo, Set.union_insert, Set.union_singleton, Set.mem_insert_iff, true_or, or_true])) end Preorder instance model_partialOrder [PartialOrder M] [L.OrderedStructure M] : M ⊨ L.partialOrderTheory := by simp only [partialOrderTheory, Theory.model_insert_iff, Relations.realize_antisymmetric, relMap_leSymb, Fin.isValue, Matrix.cons_val_zero, Matrix.cons_val_one, model_preorder, and_true] exact fun _ _ => le_antisymm section LinearOrder variable [LinearOrder M] [L.OrderedStructure M] instance model_linearOrder : M ⊨ L.linearOrderTheory := by simp only [linearOrderTheory, Theory.model_insert_iff, Relations.realize_total, relMap_leSymb, Fin.isValue, Matrix.cons_val_zero, Matrix.cons_val_one, model_partialOrder, and_true] exact le_total instance model_dlo [DenselyOrdered M] [NoTopOrder M] [NoBotOrder M] : M ⊨ L.dlo := by simp [dlo, model_linearOrder, Theory.model_insert_iff] end LinearOrder end order_to_structure section structure_to_order variable (L) [IsOrdered L] (M) [L.Structure M] /-- Any structure in an ordered language can be ordered correspondingly. -/ def leOfStructure : LE M where le a b := Structure.RelMap (leSymb : L.Relations 2) ![a,b] instance : @OrderedStructure L M _ (L.leOfStructure M) _ := by letI := L.leOfStructure M constructor simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi] intros rfl /-- The order structure on an ordered language is decidable. -/ -- This should not be a global instance, -- because it will match with any `LE` typeclass search @[local instance] def decidableLEOfStructure [h : DecidableRel (fun (a b : M) => Structure.RelMap (leSymb : L.Relations 2) ![a, b])] : letI := L.leOfStructure M DecidableLE M := h /-- Any model of a theory of preorders is a preorder. -/ def preorderOfModels [h : M ⊨ L.preorderTheory] : Preorder M where __ := L.leOfStructure M le_refl := Relations.realize_reflexive.1 ((Theory.model_iff _).1 h _ (by simp only [preorderTheory, Set.mem_insert_iff, Set.mem_singleton_iff, true_or])) le_trans := Relations.realize_transitive.1 ((Theory.model_iff _).1 h _ (by simp only [preorderTheory, Set.mem_insert_iff, Set.mem_singleton_iff, or_true])) /-- Any model of a theory of partial orders is a partial order. -/ def partialOrderOfModels [h : M ⊨ L.partialOrderTheory] : PartialOrder M where __ := L.preorderOfModels M le_antisymm := Relations.realize_antisymmetric.1 ((Theory.model_iff _).1 h _ (by simp only [partialOrderTheory, Set.mem_insert_iff, true_or])) /-- Any model of a theory of linear orders is a linear order. -/ def linearOrderOfModels [h : M ⊨ L.linearOrderTheory] [DecidableRel (fun (a b : M) => Structure.RelMap (leSymb : L.Relations 2) ![a, b])] : LinearOrder M where __ := L.partialOrderOfModels M le_total := Relations.realize_total.1 ((Theory.model_iff _).1 h _ (by simp only [linearOrderTheory, Set.mem_insert_iff, true_or])) toDecidableLE := inferInstance end structure_to_order namespace order variable [Language.order.Structure M] [LE M] [Language.order.OrderedStructure M] {N : Type*} [Language.order.Structure N] [LE N] [Language.order.OrderedStructure N] {F : Type*} instance [FunLike F M N] [OrderHomClass F M N] : Language.order.HomClass F M N := ⟨fun _ => isEmptyElim, by simp only [forall_relations, relation_eq_leSymb, relMap_leSymb, Fin.isValue, Function.comp_apply] exact fun φ x => map_rel φ⟩ -- If `OrderEmbeddingClass` or `RelEmbeddingClass` is defined, this should be generalized. instance : Language.order.StrongHomClass (M ↪o N) M N := ⟨fun _ => isEmptyElim, by simp only [order.forall_relations, order.relation_eq_leSymb, relMap_leSymb, Fin.isValue, Function.comp_apply, RelEmbedding.map_rel_iff, implies_true]⟩ instance [EquivLike F M N] [OrderIsoClass F M N] : Language.order.StrongHomClass F M N := ⟨fun _ => isEmptyElim, by simp only [order.forall_relations, order.relation_eq_leSymb, relMap_leSymb, Fin.isValue, Function.comp_apply, map_le_map_iff, implies_true]⟩ end order namespace HomClass variable [L.IsOrdered] [L.Structure M] {N : Type*} [L.Structure N] {F : Type*} [FunLike F M N] [L.HomClass F M N] lemma monotone [Preorder M] [L.OrderedStructure M] [Preorder N] [L.OrderedStructure N] (f : F) : Monotone f := fun a b => by have h := HomClass.map_rel f leSymb ![a, b] simp only [relMap_leSymb, Fin.isValue, Matrix.cons_val_zero, Matrix.cons_val_one, Function.comp_apply] at h exact h lemma strictMono [EmbeddingLike F M N] [PartialOrder M] [L.OrderedStructure M] [PartialOrder N] [L.OrderedStructure N] (f : F) : StrictMono f := (HomClass.monotone f).strictMono_of_injective (EmbeddingLike.injective f) end HomClass /-- This is not an instance because it would form a loop with `FirstOrder.Language.order.instStrongHomClassOfOrderIsoClass`. As both types are `Prop`s, it would only cause a slowdown. -/ lemma StrongHomClass.toOrderIsoClass (L : Language) [L.IsOrdered] (M : Type*) [L.Structure M] [LE M] [L.OrderedStructure M] (N : Type*) [L.Structure N] [LE N] [L.OrderedStructure N] (F : Type*) [EquivLike F M N] [L.StrongHomClass F M N] : OrderIsoClass F M N where map_le_map_iff f a b := by have h := StrongHomClass.map_rel f leSymb ![a,b] simp only [relMap_leSymb, Fin.isValue, Function.comp_apply, Matrix.cons_val_zero, Matrix.cons_val_one] at h exact h section Fraisse variable (M) lemma dlo_isExtensionPair (M : Type w) [Language.order.Structure M] [M ⊨ Language.order.linearOrderTheory] (N : Type w') [Language.order.Structure N] [N ⊨ Language.order.dlo] [Nonempty N] : Language.order.IsExtensionPair M N := by classical rw [isExtensionPair_iff_exists_embedding_closure_singleton_sup] intro S S_fg f m letI := Language.order.linearOrderOfModels M letI := Language.order.linearOrderOfModels N have := Language.order.denselyOrdered_of_dlo N have := Language.order.noBotOrder_of_dlo N have := Language.order.noTopOrder_of_dlo N have := NoBotOrder.to_noMinOrder N have := NoTopOrder.to_noMaxOrder N have hS : Set.Finite (S : Set M) := (S.fg_iff_structure_fg.1 S_fg).finite obtain ⟨g, hg⟩ := Order.exists_orderEmbedding_insert hS.toFinset ((OrderIso.setCongr hS.toFinset (S : Set M) hS.coe_toFinset).toOrderEmbedding.trans (OrderEmbedding.ofStrictMono f (HomClass.strictMono f))) m let g' : ((Substructure.closure Language.order).toFun {m} ⊔ S : Language.order.Substructure M) ↪o N := ((OrderIso.setCongr _ _ (by convert LowerAdjoint.closure_eq_self_of_mem_closed _ (Substructure.mem_closed_of_isRelational Language.order ((insert m hS.toFinset : Finset M) : Set M)) simp only [Finset.coe_insert, Set.Finite.coe_toFinset, Substructure.closure_insert, Substructure.closure_eq])).toOrderEmbedding.trans g) use StrongHomClass.toEmbedding g' ext ⟨x, xS⟩ refine congr_fun hg.symm ⟨x, (?_ : x ∈ hS.toFinset)⟩ simp only [Set.Finite.mem_toFinset, SetLike.mem_coe, xS] instance (M : Type w) [Language.order.Structure M] [M ⊨ Language.order.dlo] [Nonempty M] : Infinite M := by letI := orderStructure ℚ obtain ⟨f, _⟩ := embedding_from_cg cg_of_countable default (dlo_isExtensionPair ℚ M) exact Infinite.of_injective f f.injective lemma dlo_age [Language.order.Structure M] [Mdlo : M ⊨ Language.order.dlo] [Nonempty M] : Language.order.age M = {M : CategoryTheory.Bundled.{w'} Language.order.Structure | Finite M ∧ M ⊨ Language.order.linearOrderTheory} := by classical rw [age] ext N refine ⟨fun ⟨hF, h⟩ => ⟨hF.finite, Theory.IsUniversal.models_of_embedding h.some⟩, fun ⟨hF, h⟩ => ⟨FG.of_finite, ?_⟩⟩ letI := Language.order.linearOrderOfModels M letI := Language.order.linearOrderOfModels N exact ⟨StrongHomClass.toEmbedding (nonempty_orderEmbedding_of_finite_infinite N M).some⟩ /-- Any countable nonempty model of the theory of dense linear orders is a Fraïssé limit of the class of finite models of the theory of linear orders. -/ theorem isFraisseLimit_of_countable_nonempty_dlo (M : Type w) [Language.order.Structure M] [Countable M] [Nonempty M] [M ⊨ Language.order.dlo] : IsFraisseLimit {M : CategoryTheory.Bundled.{w} Language.order.Structure | Finite M ∧ M ⊨ Language.order.linearOrderTheory} M := ⟨(isUltrahomogeneous_iff_IsExtensionPair cg_of_countable).2 (dlo_isExtensionPair M M), dlo_age M⟩ /-- The class of finite models of the theory of linear orders is Fraïssé. -/ theorem isFraisse_finite_linear_order : IsFraisse {M : CategoryTheory.Bundled.{0} Language.order.Structure | Finite M ∧ M ⊨ Language.order.linearOrderTheory} := by letI : Language.order.Structure ℚ := orderStructure _ exact (isFraisseLimit_of_countable_nonempty_dlo ℚ).isFraisse open Cardinal /-- The theory of dense linear orders is `ℵ₀`-categorical. -/ theorem aleph0_categorical_dlo : (ℵ₀).Categorical Language.order.dlo := fun M₁ M₂ h₁ h₂ => by obtain ⟨_⟩ := denumerable_iff.2 h₁ obtain ⟨_⟩ := denumerable_iff.2 h₂ exact (isFraisseLimit_of_countable_nonempty_dlo M₁).nonempty_equiv (isFraisseLimit_of_countable_nonempty_dlo M₂) /-- The theory of dense linear orders is `ℵ₀`-complete. -/ theorem dlo_isComplete : Language.order.dlo.IsComplete := aleph0_categorical_dlo.{0}.isComplete ℵ₀ _ le_rfl (by simp [one_le_aleph0]) ⟨by letI : Language.order.Structure ℚ := orderStructure ℚ exact Theory.ModelType.of _ ℚ⟩ fun _ => inferInstance end Fraisse end Language end FirstOrder namespace Order open FirstOrder FirstOrder.Language /-- A model-theoretic adaptation of the proof of `Order.iso_of_countable_dense`: two countable, dense, nonempty linear orders without endpoints are order isomorphic. -/ example (α β : Type w') [LinearOrder α] [LinearOrder β] [Countable α] [DenselyOrdered α] [NoMinOrder α] [NoMaxOrder α] [Nonempty α] [Countable β] [DenselyOrdered β] [NoMinOrder β] [NoMaxOrder β] [Nonempty β] : Nonempty (α ≃o β) := by letI := orderStructure α letI := orderStructure β letI := StrongHomClass.toOrderIsoClass Language.order α β (α ≃[Language.order] β) exact ⟨(IsFraisseLimit.nonempty_equiv (isFraisseLimit_of_countable_nonempty_dlo α) (isFraisseLimit_of_countable_nonempty_dlo β)).some⟩ end Order
.lake/packages/mathlib/Mathlib/ModelTheory/ElementaryMaps.lean
import Mathlib.Data.Fintype.Basic import Mathlib.ModelTheory.Substructures /-! # Elementary Maps Between First-Order Structures ## Main Definitions - A `FirstOrder.Language.ElementaryEmbedding` is an embedding that commutes with the realizations of formulas. - The `FirstOrder.Language.elementaryDiagram` of a structure is the set of all sentences with parameters that the structure satisfies. - `FirstOrder.Language.ElementaryEmbedding.ofModelsElementaryDiagram` is the canonical elementary embedding of any structure into a model of its elementary diagram. ## Main Results - The Tarski-Vaught Test for embeddings: `FirstOrder.Language.Embedding.isElementary_of_exists` gives a simple criterion for an embedding to be elementary. -/ open FirstOrder namespace FirstOrder namespace Language open Structure variable (L : Language) (M : Type*) (N : Type*) {P : Type*} {Q : Type*} variable [L.Structure M] [L.Structure N] [L.Structure P] [L.Structure Q] /-- An elementary embedding of first-order structures is an embedding that commutes with the realizations of formulas. -/ structure ElementaryEmbedding where /-- The underlying embedding -/ toFun : M → N -- Porting note: -- The autoparam here used to be `obviously`. -- We have replaced it with `aesop` but that isn't currently sufficient. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases -- If that can be improved, we should remove the proofs below. map_formula' : ∀ ⦃n⦄ (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (toFun ∘ x) ↔ φ.Realize x := by aesop @[inherit_doc FirstOrder.Language.ElementaryEmbedding] scoped[FirstOrder] notation:25 A " ↪ₑ[" L "] " B => FirstOrder.Language.ElementaryEmbedding L A B variable {L} {M} {N} namespace ElementaryEmbedding attribute [coe] toFun instance instFunLike : FunLike (M ↪ₑ[L] N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g simpa only [ElementaryEmbedding.mk.injEq] @[simp] theorem map_boundedFormula (f : M ↪ₑ[L] N) {α : Type*} {n : ℕ} (φ : L.BoundedFormula α n) (v : α → M) (xs : Fin n → M) : φ.Realize (f ∘ v) (f ∘ xs) ↔ φ.Realize v xs := by classical rw [← BoundedFormula.realize_restrictFreeVar' Set.Subset.rfl, Set.inclusion_eq_id, iff_eq_eq] have h := f.map_formula' ((φ.restrictFreeVar id).toFormula.relabel (Fintype.equivFin _)) (Sum.elim (v ∘ (↑)) xs ∘ (Fintype.equivFin _).symm) simp only [Formula.realize_relabel, BoundedFormula.realize_toFormula, iff_eq_eq] at h rw [← Function.comp_assoc _ _ (Fintype.equivFin _).symm, Function.comp_assoc _ (Fintype.equivFin _).symm (Fintype.equivFin _), _root_.Equiv.symm_comp_self, Function.comp_id, Function.comp_assoc, Sum.elim_comp_inl, Function.comp_assoc _ _ Sum.inr, Sum.elim_comp_inr, ← Function.comp_assoc] at h refine h.trans ?_ erw [Function.comp_assoc _ _ (Fintype.equivFin _), _root_.Equiv.symm_comp_self, Function.comp_id, Sum.elim_comp_inl, Sum.elim_comp_inr (v ∘ Subtype.val) xs, ← Set.inclusion_eq_id (s := (BoundedFormula.freeVarFinset φ : Set α)) Set.Subset.rfl, BoundedFormula.realize_restrictFreeVar' Set.Subset.rfl] @[simp] theorem map_formula (f : M ↪ₑ[L] N) {α : Type*} (φ : L.Formula α) (x : α → M) : φ.Realize (f ∘ x) ↔ φ.Realize x := by rw [Formula.Realize, Formula.Realize, ← f.map_boundedFormula, Unique.eq_default (f ∘ default)] theorem map_sentence (f : M ↪ₑ[L] N) (φ : L.Sentence) : M ⊨ φ ↔ N ⊨ φ := by rw [Sentence.Realize, Sentence.Realize, ← f.map_formula, Unique.eq_default (f ∘ default)] theorem theory_model_iff (f : M ↪ₑ[L] N) (T : L.Theory) : M ⊨ T ↔ N ⊨ T := by simp only [Theory.model_iff, f.map_sentence] theorem elementarilyEquivalent (f : M ↪ₑ[L] N) : M ≅[L] N := elementarilyEquivalent_iff.2 f.map_sentence @[simp] theorem injective (φ : M ↪ₑ[L] N) : Function.Injective φ := by intro x y have h := φ.map_formula ((var 0).equal (var 1) : L.Formula (Fin 2)) fun i => if i = 0 then x else y rw [Formula.realize_equal, Formula.realize_equal] at h simp only [Term.realize, Fin.one_eq_zero_iff, if_true, Function.comp_apply] at h exact h.1 instance embeddingLike : EmbeddingLike (M ↪ₑ[L] N) M N := { show FunLike (M ↪ₑ[L] N) M N from inferInstance with injective' := injective } @[simp] theorem map_fun (φ : M ↪ₑ[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := by have h := φ.map_formula (Formula.graph f) (Fin.cons (funMap f x) x) rw [Formula.realize_graph, Fin.comp_cons, Formula.realize_graph] at h rw [eq_comm, h] @[simp] theorem map_rel (φ : M ↪ₑ[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := haveI h := φ.map_formula (r.formula var) x h instance strongHomClass : StrongHomClass L (M ↪ₑ[L] N) M N where map_fun := map_fun map_rel := map_rel @[simp] theorem map_constants (φ : M ↪ₑ[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c /-- An elementary embedding is also a first-order embedding. -/ def toEmbedding (f : M ↪ₑ[L] N) : M ↪[L] N where toFun := f inj' := f.injective map_fun' {_} f x := by simp map_rel' {_} R x := by simp /-- An elementary embedding is also a first-order homomorphism. -/ def toHom (f : M ↪ₑ[L] N) : M →[L] N where toFun := f map_fun' {_} f x := by simp map_rel' {_} R x := by simp @[simp] theorem toEmbedding_toHom (f : M ↪ₑ[L] N) : f.toEmbedding.toHom = f.toHom := rfl @[simp] theorem coe_toHom {f : M ↪ₑ[L] N} : (f.toHom : M → N) = (f : M → N) := rfl @[simp] theorem coe_toEmbedding (f : M ↪ₑ[L] N) : (f.toEmbedding : M → N) = (f : M → N) := rfl theorem coe_injective : @Function.Injective (M ↪ₑ[L] N) (M → N) (↑) := DFunLike.coe_injective @[ext] theorem ext ⦃f g : M ↪ₑ[L] N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h variable (L) (M) /-- The identity elementary embedding from a structure to itself -/ @[refl] def refl : M ↪ₑ[L] M where toFun := id variable {L} {M} instance : Inhabited (M ↪ₑ[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := rfl /-- Composition of elementary embeddings -/ @[trans] def comp (hnp : N ↪ₑ[L] P) (hmn : M ↪ₑ[L] N) : M ↪ₑ[L] P where toFun := hnp ∘ hmn map_formula' n φ x := by obtain ⟨_, hhnp⟩ := hnp obtain ⟨_, hhmn⟩ := hmn erw [hhnp, hhmn] @[simp] theorem comp_apply (g : N ↪ₑ[L] P) (f : M ↪ₑ[L] N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of elementary embeddings is associative. -/ theorem comp_assoc (f : M ↪ₑ[L] N) (g : N ↪ₑ[L] P) (h : P ↪ₑ[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl end ElementaryEmbedding variable (L) (M) /-- The elementary diagram of an `L`-structure is the set of all sentences with parameters it satisfies. -/ abbrev elementaryDiagram : L[[M]].Theory := L[[M]].completeTheory M /-- The canonical elementary embedding of an `L`-structure into any model of its elementary diagram -/ @[simps] def ElementaryEmbedding.ofModelsElementaryDiagram (N : Type*) [L.Structure N] [L[[M]].Structure N] [(lhomWithConstants L M).IsExpansionOn N] [N ⊨ L.elementaryDiagram M] : M ↪ₑ[L] N := ⟨((↑) : L[[M]].Constants → N) ∘ Sum.inr, fun n φ x => by refine _root_.trans ?_ ((realize_iff_of_model_completeTheory M N (((L.lhomWithConstants M).onBoundedFormula φ).subst (Constants.term ∘ Sum.inr ∘ x)).alls).trans ?_) · simp_rw [Sentence.Realize, BoundedFormula.realize_alls, BoundedFormula.realize_subst, LHom.realize_onBoundedFormula, Formula.Realize, Unique.forall_iff, Function.comp_def, Term.realize_constants] · simp_rw [Sentence.Realize, BoundedFormula.realize_alls, BoundedFormula.realize_subst, LHom.realize_onBoundedFormula, Formula.Realize, Unique.forall_iff] rfl⟩ variable {L M} namespace Embedding /-- The **Tarski-Vaught test** for elementarity of an embedding. -/ theorem isElementary_of_exists (f : M ↪[L] N) (htv : ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N), φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) → ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) : ∀ {n} (φ : L.Formula (Fin n)) (x : Fin n → M), φ.Realize (f ∘ x) ↔ φ.Realize x := by suffices h : ∀ (n : ℕ) (φ : L.BoundedFormula Empty n) (xs : Fin n → M), φ.Realize (f ∘ default) (f ∘ xs) ↔ φ.Realize default xs by intro n φ x exact φ.realize_relabel_sumInr.symm.trans (_root_.trans (h n _ _) φ.realize_relabel_sumInr) refine fun n φ => φ.recOn ?_ ?_ ?_ ?_ ?_ · exact fun {_} _ => Iff.rfl · intros simp [BoundedFormula.Realize, ← Sum.comp_elim, HomClass.realize_term] · intros simp only [BoundedFormula.Realize, ← Sum.comp_elim, HomClass.realize_term] erw [map_rel f] · intro _ _ _ ih1 ih2 _ simp [ih1, ih2] · intro n φ ih xs simp only [BoundedFormula.realize_all] refine ⟨fun h a => ?_, ?_⟩ · rw [← ih, Fin.comp_snoc] exact h (f a) · contrapose! rintro ⟨a, ha⟩ obtain ⟨b, hb⟩ := htv n φ.not xs a (by rw [BoundedFormula.realize_not, ← Unique.eq_default (f ∘ default)] exact ha) refine ⟨b, fun h => hb (Eq.mp ?_ ((ih _).2 h))⟩ rw [Unique.eq_default (f ∘ default), Fin.comp_snoc] /-- Bundles an embedding satisfying the Tarski-Vaught test as an elementary embedding. -/ @[simps] def toElementaryEmbedding (f : M ↪[L] N) (htv : ∀ (n : ℕ) (φ : L.BoundedFormula Empty (n + 1)) (x : Fin n → M) (a : N), φ.Realize default (Fin.snoc (f ∘ x) a : _ → N) → ∃ b : M, φ.Realize default (Fin.snoc (f ∘ x) (f b) : _ → N)) : M ↪ₑ[L] N := ⟨f, fun _ => f.isElementary_of_exists htv⟩ end Embedding namespace Equiv /-- A first-order equivalence is also an elementary embedding. -/ def toElementaryEmbedding (f : M ≃[L] N) : M ↪ₑ[L] N where toFun := f @[simp] theorem toElementaryEmbedding_toEmbedding (f : M ≃[L] N) : f.toElementaryEmbedding.toEmbedding = f.toEmbedding := rfl @[simp] theorem coe_toElementaryEmbedding (f : M ≃[L] N) : (f.toElementaryEmbedding : M → N) = (f : M → N) := rfl end Equiv @[simp] theorem realize_term_substructure {α : Type*} {S : L.Substructure M} (v : α → S) (t : L.Term α) : t.realize ((↑) ∘ v) = (↑(t.realize v) : M) := HomClass.realize_term S.subtype end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/DirectLimit.lean
import Mathlib.Data.Finite.Sum import Mathlib.Data.Fintype.Order import Mathlib.ModelTheory.FinitelyGenerated import Mathlib.ModelTheory.Quotients import Mathlib.Order.DirectedInverseSystem /-! # Direct Limits of First-Order Structures This file constructs the direct limit of a directed system of first-order embeddings. ## Main Definitions - `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of first-order embeddings between the structures indexed by `G`. - `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps from the components to another module that respect the directed system structure give rise to a unique map out of the direct limit. - `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of isomorphic direct systems. -/ universe v w w' u₁ u₂ open FirstOrder namespace FirstOrder namespace Language open Structure Set variable {L : Language} {ι : Type v} [Preorder ι] variable {G : ι → Type w} [∀ i, L.Structure (G i)] variable (f : ∀ i j, i ≤ j → G i ↪[L] G j) namespace DirectedSystem alias map_self := DirectedSystem.map_self' alias map_map := DirectedSystem.map_map' variable {G' : ℕ → Type w} [∀ i, L.Structure (G' i)] (f' : ∀ n : ℕ, G' n ↪[L] G' (n + 1)) /-- Given a chain of embeddings of structures indexed by `ℕ`, defines a `DirectedSystem` by composing them. -/ def natLERec (m n : ℕ) (h : m ≤ n) : G' m ↪[L] G' n := Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _) @[simp] theorem coe_natLERec (m n : ℕ) (h : m ≤ n) : (natLERec f' m n h : G' m → G' n) = Nat.leRecOn h (@fun k => f' k) := by obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h ext x induction k with | zero => simp [natLERec, Nat.leRecOn_self] | succ k ih => -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, ← natLERec, Embedding.comp_apply, ih] instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h := ⟨fun _ _ => congr (congr rfl (Nat.leRecOn_self _)) rfl, fun _ _ _ hij hjk => by simp [Nat.leRecOn_trans hij hjk]⟩ end DirectedSystem set_option linter.unusedVariables false in /-- Alias for `Σ i, G i`. Instead of `Σ i, G i`, we use the alias `Language.Structure.Sigma` which depends on `f`. This way, Lean can infer what `L` and `f` are in the `Setoid` instance. Otherwise we have a "cannot find synthesization order" error. See also the discussion at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting -/ @[nolint unusedArguments] protected abbrev Structure.Sigma (f : ∀ i j, i ≤ j → G i ↪[L] G j) := Σ i, G i local notation "Σˣ" => Structure.Sigma /-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/ abbrev Structure.Sigma.mk (i : ι) (x : G i) : Σˣ f := ⟨i, x⟩ namespace DirectLimit /-- Raises a family of elements in the `Σ`-type to the same level along the embeddings. -/ def unify {α : Type*} (x : α → Σˣ f) (i : ι) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) (a : α) : G i := f (x a).1 i (h (mem_range_self a)) (x a).2 variable [DirectedSystem G fun i j h => f i j h] @[simp] theorem unify_sigma_mk_self {α : Type*} {i : ι} {x : α → G i} : (unify f (fun a => .mk f i (x a)) i fun _ ⟨_, hj⟩ => _root_.trans (le_of_eq hj.symm) (refl _)) = x := by ext a rw [unify] apply DirectedSystem.map_self theorem comp_unify {α : Type*} {x : α → Σˣ f} {i j : ι} (ij : i ≤ j) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) : f i j ij ∘ unify f x i h = unify f x j fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by ext a simp [unify, DirectedSystem.map_map] end DirectLimit variable (G) namespace DirectLimit /-- The directed limit glues together the structures along the embeddings. -/ def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] : Setoid (Σˣ f) where r := fun ⟨i, x⟩ ⟨j, y⟩ => ∃ (k : ι) (ik : i ≤ k) (jk : j ≤ k), f i k ik x = f j k jk y iseqv := ⟨fun ⟨i, _⟩ => ⟨i, refl i, refl i, rfl⟩, @fun ⟨_, _⟩ ⟨_, _⟩ ⟨k, ik, jk, h⟩ => ⟨k, jk, ik, h.symm⟩, @fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, z⟩ ⟨ij, hiij, hjij, hij⟩ ⟨jk, hjjk, hkjk, hjk⟩ => by obtain ⟨ijk, hijijk, hjkijk⟩ := directed_of (· ≤ ·) ij jk refine ⟨ijk, le_trans hiij hijijk, le_trans hkjk hjkijk, ?_⟩ rw [← DirectedSystem.map_map _ hiij hijijk, hij, DirectedSystem.map_map] rw [← DirectedSystem.map_map _ hkjk hjkijk, ← hjk, DirectedSystem.map_map]⟩ /-- The structure on the `Σ`-type which becomes the structure on the direct limit after quotienting. -/ noncomputable def sigmaStructure [IsDirected ι (· ≤ ·)] [Nonempty ι] : L.Structure (Σˣ f) where funMap F x := ⟨_, funMap F (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))⟩ RelMap R x := RelMap R (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1))) end DirectLimit /-- The direct limit of a directed system is the structures glued together along the embeddings. -/ def DirectLimit [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] := Quotient (DirectLimit.setoid G f) attribute [local instance] DirectLimit.setoid DirectLimit.sigmaStructure instance [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] [Inhabited ι] [Inhabited (G default)] : Inhabited (DirectLimit G f) := ⟨⟦⟨default, default⟩⟧⟩ namespace DirectLimit variable [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h => f i j h] theorem equiv_iff {x y : Σˣ f} {i : ι} (hx : x.1 ≤ i) (hy : y.1 ≤ i) : x ≈ y ↔ (f x.1 i hx) x.2 = (f y.1 i hy) y.2 := by cases x cases y refine ⟨fun xy => ?_, fun xy => ⟨i, hx, hy, xy⟩⟩ obtain ⟨j, _, _, h⟩ := xy obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j have h := congr_arg (f j k jk) h apply (f i k ik).injective rw [DirectedSystem.map_map, DirectedSystem.map_map] at * exact h theorem funMap_unify_equiv {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i j : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : Structure.Sigma.mk f i (funMap F (unify f x i hi)) ≈ .mk f j (funMap F (unify f x j hj)) := by obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j refine ⟨k, ik, jk, ?_⟩ rw [(f i k ik).map_fun, (f j k jk).map_fun, comp_unify, comp_unify] theorem relMap_unify_equiv {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i j : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R (unify f x i hi) = RelMap R (unify f x j hj) := by obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j rw [← (f i k ik).map_rel, comp_unify, ← (f j k jk).map_rel, comp_unify] variable [Nonempty ι] theorem exists_unify_eq {α : Type*} [Finite α] {x y : α → Σˣ f} (xy : x ≈ y) : ∃ (i : ι) (hx : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hy : i ∈ upperBounds (range (Sigma.fst ∘ y))), unify f x i hx = unify f y i hy := by obtain ⟨i, hi⟩ := Finite.bddAbove_range (Sum.elim (fun a => (x a).1) fun a => (y a).1) rw [Sum.elim_range, upperBounds_union] at hi simp_rw [← Function.comp_apply (f := Sigma.fst)] at hi exact ⟨i, hi.1, hi.2, funext fun a => (equiv_iff G f _ _).1 (xy a)⟩ theorem funMap_equiv_unify {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : funMap F x ≈ .mk f _ (funMap F (unify f x i hi)) := funMap_unify_equiv G f F x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi theorem relMap_equiv_unify {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R x = RelMap R (unify f x i hi) := relMap_unify_equiv G f R x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi /-- The direct limit `setoid` respects the structure `sigmaStructure`, so quotienting by it gives rise to a valid structure. -/ noncomputable instance prestructure : L.Prestructure (DirectLimit.setoid G f) where toStructure := sigmaStructure G f fun_equiv {n} {F} x y xy := by obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy refine Setoid.trans (funMap_equiv_unify G f F x i hx) (Setoid.trans ?_ (Setoid.symm (funMap_equiv_unify G f F y i hy))) rw [h] rel_equiv {n} {R} x y xy := by obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy refine _root_.trans (relMap_equiv_unify G f R x i hx) (_root_.trans ?_ (symm (relMap_equiv_unify G f R y i hy))) rw [h] /-- The `L.Structure` on a direct limit of `L.Structure`s. -/ noncomputable instance instStructureDirectLimit : L.Structure (DirectLimit G f) := Language.quotientStructure @[simp] theorem funMap_quotient_mk'_sigma_mk' {n : ℕ} {F : L.Functions n} {i : ι} {x : Fin n → G i} : funMap F (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = ⟦.mk f i (funMap F x)⟧ := by simp only [funMap_quotient_mk', Quotient.eq] obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i)) refine ⟨k, jk, ik, ?_⟩ simp only [Embedding.map_fun, comp_unify] rfl @[simp] theorem relMap_quotient_mk'_sigma_mk' {n : ℕ} {R : L.Relations n} {i : ι} {x : Fin n → G i} : RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = RelMap R x := by rw [relMap_quotient_mk'] obtain ⟨k, _, _⟩ := directed_of (· ≤ ·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i)) rw [relMap_equiv_unify G f R (fun a => .mk f i (x a)) i (fun _ ⟨_, hj⟩ => le_of_eq hj.symm)] rw [unify_sigma_mk_self] theorem exists_quotient_mk'_sigma_mk'_eq {α : Type*} [Finite α] (x : α → DirectLimit G f) : ∃ (i : ι) (y : α → G i), x = fun a => ⟦.mk f i (y a)⟧ := by obtain ⟨i, hi⟩ := Finite.bddAbove_range fun a => (x a).out.1 refine ⟨i, unify f (Quotient.out ∘ x) i hi, ?_⟩ ext a rw [Quotient.eq_mk_iff_out, unify] generalize_proofs r change _ ≈ Structure.Sigma.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) have : (.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) : Σˣ f).fst ≤ i := le_rfl rw [equiv_iff G f (i := i) (hi _) this] · simp only [DirectedSystem.map_self] exact ⟨a, rfl⟩ variable (L ι) /-- The canonical map from a component to the direct limit. -/ noncomputable def of (i : ι) : G i ↪[L] DirectLimit G f where toFun := fun a => ⟦.mk f i a⟧ inj' x y h := by rw [Quotient.eq] at h obtain ⟨j, h1, _, h3⟩ := h exact (f i j h1).injective h3 map_fun' F x := by rw [← funMap_quotient_mk'_sigma_mk'] rfl map_rel' := by intro n R x change RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) ↔ _ simp only [relMap_quotient_mk'_sigma_mk'] variable {L ι G f} @[simp] theorem of_apply {i : ι} {x : G i} : of L ι G f i x = ⟦.mk f i x⟧ := rfl -- This is not a simp-lemma because it is not in simp-normal form, -- but the simp-normal version of this theorem would not be useful. theorem of_f {i j : ι} {hij : i ≤ j} {x : G i} : of L ι G f j (f i j hij x) = of L ι G f i x := by rw [of_apply, of_apply, Quotient.eq] refine Setoid.symm ⟨j, hij, refl j, ?_⟩ simp only [DirectedSystem.map_self] /-- Every element of the direct limit corresponds to some element in some component of the directed system. -/ theorem exists_of (z : DirectLimit G f) : ∃ i x, of L ι G f i x = z := ⟨z.out.1, z.out.2, by simp⟩ @[elab_as_elim] protected theorem inductionOn {C : DirectLimit G f → Prop} (z : DirectLimit G f) (ih : ∀ i x, C (of L ι G f i x)) : C z := let ⟨i, x, h⟩ := exists_of z h ▸ ih i x theorem iSup_range_of_eq_top : ⨆ i, (of L ι G f i).toHom.range = ⊤ := eq_top_iff.2 (fun x _ ↦ DirectLimit.inductionOn x (fun i _ ↦ le_iSup (fun i ↦ Hom.range (Embedding.toHom (of L ι G f i))) i (mem_range_self _))) /-- Every finitely generated substructure of the direct limit corresponds to some substructure in some component of the directed system. -/ theorem exists_fg_substructure_in_Sigma (S : L.Substructure (DirectLimit G f)) (S_fg : S.FG) : ∃ i, ∃ T : L.Substructure (G i), T.map (of L ι G f i).toHom = S := by let ⟨A, A_closure⟩ := S_fg let ⟨i, y, eq_y⟩ := exists_quotient_mk'_sigma_mk'_eq G _ (fun a : A ↦ a.1) use i use Substructure.closure L (range y) rw [Substructure.map_closure] simp only [Embedding.coe_toHom, of_apply] rw [← image_univ, image_image, image_univ, ← eq_y, Subtype.range_coe_subtype, Finset.setOf_mem, A_closure] variable {P : Type u₁} [L.Structure P] variable (L ι G f) in /-- The universal property of the direct limit: maps from the components to another module that respect the directed system structure (i.e. make some diagram commute) give rise to a unique map out of the direct limit. -/ noncomputable def lift (g : ∀ i, G i ↪[L] P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) : DirectLimit G f ↪[L] P where toFun := Quotient.lift (fun x : Σˣ f => (g x.1) x.2) fun x y xy => by simp only obtain ⟨i, hx, hy⟩ := directed_of (· ≤ ·) x.1 y.1 rw [← Hg x.1 i hx, ← Hg y.1 i hy] exact congr_arg _ ((equiv_iff ..).1 xy) inj' x y xy := by rw [← Quotient.out_eq x, ← Quotient.out_eq y, Quotient.lift_mk, Quotient.lift_mk] at xy obtain ⟨i, hx, hy⟩ := directed_of (· ≤ ·) x.out.1 y.out.1 rw [← Hg x.out.1 i hx, ← Hg y.out.1 i hy] at xy rw [← Quotient.out_eq x, ← Quotient.out_eq y, Quotient.eq_iff_equiv, equiv_iff G f hx hy] exact (g i).injective xy map_fun' F x := by obtain ⟨i, y, rfl⟩ := exists_quotient_mk'_sigma_mk'_eq G f x change _ = funMap F (Quotient.lift _ _ ∘ Quotient.mk _ ∘ Structure.Sigma.mk f i ∘ y) rw [funMap_quotient_mk'_sigma_mk', ← Function.comp_assoc, Quotient.lift_comp_mk] simp only [Quotient.lift_mk, Embedding.map_fun] rfl map_rel' R x := by obtain ⟨i, y, rfl⟩ := exists_quotient_mk'_sigma_mk'_eq G f x change RelMap R (Quotient.lift _ _ ∘ Quotient.mk _ ∘ Structure.Sigma.mk f i ∘ y) ↔ _ rw [relMap_quotient_mk'_sigma_mk' G f, ← (g i).map_rel R y, ← Function.comp_assoc, Quotient.lift_comp_mk] rfl variable (g : ∀ i, G i ↪[L] P) (Hg : ∀ i j hij x, g j (f i j hij x) = g i x) @[simp] theorem lift_quotient_mk'_sigma_mk' {i} (x : G i) : lift L ι G f g Hg ⟦.mk f i x⟧ = (g i) x := by change (lift L ι G f g Hg).toFun ⟦.mk f i x⟧ = _ simp only [lift, Quotient.lift_mk] theorem lift_of {i} (x : G i) : lift L ι G f g Hg (of L ι G f i x) = g i x := by simp theorem lift_unique (F : DirectLimit G f ↪[L] P) (x) : F x = lift L ι G f (fun i => F.comp <| of L ι G f i) (fun i j hij x => by rw [F.comp_apply, F.comp_apply, of_f]) x := DirectLimit.inductionOn x fun i x => by rw [lift_of]; rfl lemma range_lift : (lift L ι G f g Hg).toHom.range = ⨆ i, (g i).toHom.range := by simp_rw [Hom.range_eq_map] rw [← iSup_range_of_eq_top, Substructure.map_iSup] simp_rw [Hom.range_eq_map, Substructure.map_map] rfl variable (L ι G f) variable (G' : ι → Type w') [∀ i, L.Structure (G' i)] variable (f' : ∀ i j, i ≤ j → G' i ↪[L] G' j) variable (g : ∀ i, G i ≃[L] G' i) variable [DirectedSystem G' fun i j h => f' i j h] /-- The isomorphism between limits of isomorphic systems. -/ noncomputable def equiv_lift (H_commuting : ∀ i j hij x, g j (f i j hij x) = f' i j hij (g i x)) : DirectLimit G f ≃[L] DirectLimit G' f' := by let U i : G i ↪[L] DirectLimit G' f' := (of L _ G' f' i).comp (g i).toEmbedding let F : DirectLimit G f ↪[L] DirectLimit G' f' := lift L _ G f U <| by intro _ _ _ _ simp only [U, Embedding.comp_apply, Equiv.coe_toEmbedding, H_commuting, of_f] have surj_f : Function.Surjective F := by intro x rcases x with ⟨i, pre_x⟩ use of L _ G f i ((g i).symm pre_x) simp only [F, U, lift_of, Embedding.comp_apply, Equiv.coe_toEmbedding, Equiv.apply_symm_apply] rfl exact ⟨Equiv.ofBijective F ⟨F.injective, surj_f⟩, F.map_fun', F.map_rel'⟩ variable (H_commuting : ∀ i j hij x, g j (f i j hij x) = f' i j hij (g i x)) theorem equiv_lift_of {i : ι} (x : G i) : equiv_lift L ι G f G' f' g H_commuting (of L ι G f i x) = of L ι G' f' i (g i x) := rfl variable {L ι G f} /-- The direct limit of countably many countably generated structures is countably generated. -/ theorem cg {ι : Type*} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι] {G : ι → Type w} [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j) (h : ∀ i, Structure.CG L (G i)) [DirectedSystem G fun i j h => f i j h] : Structure.CG L (DirectLimit G f) := by refine ⟨⟨⋃ i, DirectLimit.of L ι G f i '' Classical.choose (h i).out, ?_, ?_⟩⟩ · exact Set.countable_iUnion fun i => Set.Countable.image (Classical.choose_spec (h i).out).1 _ · rw [eq_top_iff, Substructure.closure_iUnion] simp_rw [← Embedding.coe_toHom, Substructure.closure_image] rw [le_iSup_iff] intro S hS x _ let out := Quotient.out (s := DirectLimit.setoid G f) refine hS (out x).1 ⟨(out x).2, ?_, ?_⟩ · rw [(Classical.choose_spec (h (out x).1).out).2] trivial · simp only [out, Embedding.coe_toHom, DirectLimit.of_apply, Sigma.eta, Quotient.out_eq] instance cg' {ι : Type*} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Nonempty ι] {G : ι → Type w} [∀ i, L.Structure (G i)] (f : ∀ i j, i ≤ j → G i ↪[L] G j) [h : ∀ i, Structure.CG L (G i)] [DirectedSystem G fun i j h => f i j h] : Structure.CG L (DirectLimit G f) := cg f h end DirectLimit section Substructure variable [Nonempty ι] [IsDirected ι (· ≤ ·)] variable {M : Type*} [L.Structure M] (S : ι →o L.Substructure M) instance : DirectedSystem (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) where map_self _ _ := rfl map_map _ _ _ _ _ _ := rfl namespace DirectLimit /-- The map from a direct limit of a system of substructures of `M` into `M`. -/ noncomputable def liftInclusion : DirectLimit (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) ↪[L] M := DirectLimit.lift L ι (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) (fun _ ↦ Substructure.subtype _) (fun _ _ _ _ ↦ rfl) theorem liftInclusion_of {i : ι} (x : S i) : (liftInclusion S) (of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i x) = Substructure.subtype (S i) x := rfl lemma rangeLiftInclusion : (liftInclusion S).toHom.range = ⨆ i, S i := by simp_rw [liftInclusion, range_lift, Substructure.range_subtype] /-- The isomorphism between a direct limit of a system of substructures and their union. -/ noncomputable def Equiv_iSup : DirectLimit (fun i ↦ S i) (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) ≃[L] (iSup S : L.Substructure M) := by have liftInclusion_in_sup : ∀ x, liftInclusion S x ∈ (⨆ i, S i) := by simp only [← rangeLiftInclusion, Hom.mem_range, Embedding.coe_toHom] intro x; use x let F := Embedding.codRestrict (⨆ i, S i) _ liftInclusion_in_sup have F_surj : Function.Surjective F := by rintro ⟨m, hm⟩ rw [← rangeLiftInclusion, Hom.mem_range] at hm rcases hm with ⟨a, _⟩; use a simpa only [F, Embedding.codRestrict_apply', Subtype.mk.injEq] exact ⟨Equiv.ofBijective F ⟨F.injective, F_surj⟩, F.map_fun', F.map_rel'⟩ theorem Equiv_isup_of_apply {i : ι} (x : S i) : Equiv_iSup S (of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i x) = Substructure.inclusion (le_iSup _ _) x := rfl theorem Equiv_isup_symm_inclusion_apply {i : ι} (x : S i) : (Equiv_iSup S).symm (Substructure.inclusion (le_iSup _ _) x) = of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i x := by apply (Equiv_iSup S).injective simp only [Equiv.apply_symm_apply] rfl @[simp] theorem Equiv_isup_symm_inclusion (i : ι) : (Equiv_iSup S).symm.toEmbedding.comp (Substructure.inclusion (le_iSup _ _)) = of L ι _ (fun _ _ h ↦ Substructure.inclusion (S.monotone h)) i := by ext x; exact Equiv_isup_symm_inclusion_apply _ x end DirectLimit end Substructure end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Syntax.lean
import Mathlib.Data.Set.Prod import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.ModelTheory.LanguageMap import Mathlib.Algebra.Order.Group.Nat /-! # Basics on First-Order Syntax This file defines first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions - A `FirstOrder.Language.Term` is defined so that `L.Term α` is the type of `L`-terms with free variables indexed by `α`. - A `FirstOrder.Language.Formula` is defined so that `L.Formula α` is the type of `L`-formulas with free variables indexed by `α`. - A `FirstOrder.Language.Sentence` is a formula with no free variables. - A `FirstOrder.Language.Theory` is a set of sentences. - The variables of terms and formulas can be relabelled with `FirstOrder.Language.Term.relabel`, `FirstOrder.Language.BoundedFormula.relabel`, and `FirstOrder.Language.Formula.relabel`. - Given an operation on terms and an operation on relations, `FirstOrder.Language.BoundedFormula.mapTermRel` gives an operation on formulas. - `FirstOrder.Language.BoundedFormula.castLE` adds more bound variables. - `FirstOrder.Language.BoundedFormula.liftAt` raises the indexes of the bound variables above a particular index. - `FirstOrder.Language.Term.subst` and `FirstOrder.Language.BoundedFormula.subst` substitute variables with given terms. - `FirstOrder.Language.Term.substFunc` instead substitutes function definitions with given terms. - Language maps can act on syntactic objects with functions such as `FirstOrder.Language.LHom.onFormula`. - `FirstOrder.Language.Term.constantsVarsEquiv` and `FirstOrder.Language.BoundedFormula.constantsVarsEquiv` switch terms and formulas between having constants in the language and having extra free variables indexed by the same type. ## Implementation Notes - `BoundedFormula` uses a locally nameless representation with bound variables as well-scoped de Bruijn levels (the variable bounded by the outermost quantifier is indexed by `0`). Specifically, a `L.BoundedFormula α n` is a formula with free variables indexed by a type `α`, which cannot be quantified over, and bound variables indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula `∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by `n : Fin (n + 1)`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable (L : Language.{u, v}) {L' : Language} variable {M : Type w} {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder open Structure Fin /-- A term on `α` is either a variable indexed by an element of `α` or a function symbol applied to simpler terms. -/ inductive Term (α : Type u') : Type max u u' | var : α → Term α | func : ∀ {l : ℕ} (_f : L.Functions l) (_ts : Fin l → Term α), Term α export Term (var func) variable {L} namespace Term instance instDecidableEq [DecidableEq α] [∀ n, DecidableEq (L.Functions n)] : DecidableEq (L.Term α) | .var a, .var b => decidable_of_iff (a = b) <| by simp | @Term.func _ _ m f xs, @Term.func _ _ n g ys => if h : m = n then letI : DecidableEq (L.Term α) := instDecidableEq decidable_of_iff (f = h ▸ g ∧ ∀ i : Fin m, xs i = ys (Fin.cast h i)) <| by subst h simp [funext_iff] else .isFalse <| by simp [h] | .var _, .func _ _ | .func _ _, .var _ => .isFalse <| by simp open Finset /-- The `Finset` of variables used in a given term. -/ @[simp] def varFinset [DecidableEq α] : L.Term α → Finset α | var i => {i} | func _f ts => univ.biUnion fun i => (ts i).varFinset /-- The `Finset` of variables from the left side of a sum used in a given term. -/ @[simp] def varFinsetLeft [DecidableEq α] : L.Term (α ⊕ β) → Finset α | var (Sum.inl i) => {i} | var (Sum.inr _i) => ∅ | func _f ts => univ.biUnion fun i => (ts i).varFinsetLeft /-- Relabels a term's variables along a particular function. -/ @[simp] def relabel (g : α → β) : L.Term α → L.Term β | var i => var (g i) | func f ts => func f fun {i} => (ts i).relabel g theorem relabel_id (t : L.Term α) : t.relabel id = t := by induction t with | var => rfl | func _ _ ih => simp [ih] @[simp] theorem relabel_id_eq_id : (Term.relabel id : L.Term α → L.Term α) = id := funext relabel_id @[simp] theorem relabel_relabel (f : α → β) (g : β → γ) (t : L.Term α) : (t.relabel f).relabel g = t.relabel (g ∘ f) := by induction t with | var => rfl | func _ _ ih => simp [ih] @[simp] theorem relabel_comp_relabel (f : α → β) (g : β → γ) : (Term.relabel g ∘ Term.relabel f : L.Term α → L.Term γ) = Term.relabel (g ∘ f) := funext (relabel_relabel f g) /-- Relabels a term's variables along a bijection. -/ @[simps] def relabelEquiv (g : α ≃ β) : L.Term α ≃ L.Term β := ⟨relabel g, relabel g.symm, fun t => by simp, fun t => by simp⟩ /-- Restricts a term to use only a set of the given variables. -/ def restrictVar [DecidableEq α] : ∀ (t : L.Term α) (_f : t.varFinset → β), L.Term β | var a, f => var (f ⟨a, mem_singleton_self a⟩) | func F ts, f => func F fun i => (ts i).restrictVar (f ∘ Set.inclusion (subset_biUnion_of_mem (fun i => varFinset (ts i)) (mem_univ i))) /-- Restricts a term to use only a set of the given variables on the left side of a sum. -/ def restrictVarLeft [DecidableEq α] {γ : Type*} : ∀ (t : L.Term (α ⊕ γ)) (_f : t.varFinsetLeft → β), L.Term (β ⊕ γ) | var (Sum.inl a), f => var (Sum.inl (f ⟨a, mem_singleton_self a⟩)) | var (Sum.inr a), _f => var (Sum.inr a) | func F ts, f => func F fun i => (ts i).restrictVarLeft (f ∘ Set.inclusion (subset_biUnion_of_mem (fun i => varFinsetLeft (ts i)) (mem_univ i))) end Term /-- The representation of a constant symbol as a term. -/ def Constants.term (c : L.Constants) : L.Term α := func c default /-- Applies a unary function to a term. -/ def Functions.apply₁ (f : L.Functions 1) (t : L.Term α) : L.Term α := func f ![t] /-- Applies a binary function to two terms. -/ def Functions.apply₂ (f : L.Functions 2) (t₁ t₂ : L.Term α) : L.Term α := func f ![t₁, t₂] /-- The representation of a function symbol as a term, on fresh variables indexed by Fin. -/ def Functions.term {n : ℕ} (f : L.Functions n) : L.Term (Fin n) := func f Term.var namespace Term /-- Sends a term with constants to a term with extra variables. -/ @[simp] def constantsToVars : L[[γ]].Term α → L.Term (γ ⊕ α) | var a => var (Sum.inr a) | @func _ _ 0 f ts => Sum.casesOn f (fun f => func f fun i => (ts i).constantsToVars) fun c => var (Sum.inl c) | @func _ _ (_n + 1) f ts => Sum.casesOn f (fun f => func f fun i => (ts i).constantsToVars) fun c => isEmptyElim c /-- Sends a term with extra variables to a term with constants. -/ @[simp] def varsToConstants : L.Term (γ ⊕ α) → L[[γ]].Term α | var (Sum.inr a) => var a | var (Sum.inl c) => Constants.term (Sum.inr c) | func f ts => func (Sum.inl f) fun i => (ts i).varsToConstants /-- A bijection between terms with constants and terms with extra variables. -/ @[simps] def constantsVarsEquiv : L[[γ]].Term α ≃ L.Term (γ ⊕ α) := ⟨constantsToVars, varsToConstants, by intro t induction t with | var => rfl | @func n f _ ih => cases n · cases f · simp [constantsToVars, varsToConstants, ih] · simp [constantsToVars, varsToConstants, Constants.term, eq_iff_true_of_subsingleton] · obtain - | f := f · simp [constantsToVars, varsToConstants, ih] · exact isEmptyElim f, by intro t induction t with | var x => cases x <;> rfl | @func n f _ ih => cases n <;> · simp [varsToConstants, constantsToVars, ih]⟩ /-- A bijection between terms with constants and terms with extra variables. -/ def constantsVarsEquivLeft : L[[γ]].Term (α ⊕ β) ≃ L.Term ((γ ⊕ α) ⊕ β) := constantsVarsEquiv.trans (relabelEquiv (Equiv.sumAssoc _ _ _)).symm @[simp] theorem constantsVarsEquivLeft_apply (t : L[[γ]].Term (α ⊕ β)) : constantsVarsEquivLeft t = (constantsToVars t).relabel (Equiv.sumAssoc _ _ _).symm := rfl @[simp] theorem constantsVarsEquivLeft_symm_apply (t : L.Term ((γ ⊕ α) ⊕ β)) : constantsVarsEquivLeft.symm t = varsToConstants (t.relabel (Equiv.sumAssoc _ _ _)) := rfl instance inhabitedOfVar [Inhabited α] : Inhabited (L.Term α) := ⟨var default⟩ instance inhabitedOfConstant [Inhabited L.Constants] : Inhabited (L.Term α) := ⟨(default : L.Constants).term⟩ /-- Raises all of the `Fin`-indexed variables of a term greater than or equal to `m` by `n'`. -/ def liftAt {n : ℕ} (n' m : ℕ) : L.Term (α ⊕ (Fin n)) → L.Term (α ⊕ (Fin (n + n'))) := relabel (Sum.map id fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') /-- Substitutes the variables in a given term with terms. -/ @[simp] def subst : L.Term α → (α → L.Term β) → L.Term β | var a, tf => tf a | func f ts, tf => func f fun i => (ts i).subst tf /-- Substitutes the functions in a given term with expressions. -/ @[simp] def substFunc : L.Term α → (∀ {n : ℕ}, L.Functions n → L'.Term (Fin n)) → L'.Term α | var a, _ => var a | func f ts, tf => (tf f).subst fun i ↦ (ts i).substFunc tf @[simp] theorem substFunc_term (t : L.Term α) : t.substFunc Functions.term = t := by induction t · rfl · simp only [substFunc, Functions.term, subst, ‹∀ _, _›] end Term /-- `&n` is notation for the bound variable indexed by `n` in a bounded formula. -/ scoped[FirstOrder] prefix:arg "&" => FirstOrder.Language.Term.var ∘ Sum.inr namespace LHom open Term /-- Maps a term's symbols along a language map. -/ @[simp] def onTerm (φ : L →ᴸ L') : L.Term α → L'.Term α | var i => var i | func f ts => func (φ.onFunction f) fun i => onTerm φ (ts i) @[simp] theorem id_onTerm : ((LHom.id L).onTerm : L.Term α → L.Term α) = id := by ext t induction t with | var => rfl | func _ _ ih => simp_rw [onTerm, ih]; rfl @[simp] theorem comp_onTerm {L'' : Language} (φ : L' →ᴸ L'') (ψ : L →ᴸ L') : ((φ.comp ψ).onTerm : L.Term α → L''.Term α) = φ.onTerm ∘ ψ.onTerm := by ext t induction t with | var => rfl | func _ _ ih => simp_rw [onTerm, ih]; rfl end LHom /-- Maps a term's symbols along a language equivalence. -/ @[simps] def LEquiv.onTerm (φ : L ≃ᴸ L') : L.Term α ≃ L'.Term α where toFun := φ.toLHom.onTerm invFun := φ.invLHom.onTerm left_inv := by rw [Function.leftInverse_iff_comp, ← LHom.comp_onTerm, φ.left_inv, LHom.id_onTerm] right_inv := by rw [Function.rightInverse_iff_comp, ← LHom.comp_onTerm, φ.right_inv, LHom.id_onTerm] variable (L) (α) /-- `BoundedFormula α n` is the type of formulas with free variables indexed by `α` and `n` in-scope bound variables indexed by `Fin n`. -/ inductive BoundedFormula : ℕ → Type max u v u' | falsum {n} : BoundedFormula n | equal {n} (t₁ t₂ : L.Term (α ⊕ (Fin n))) : BoundedFormula n | rel {n l : ℕ} (R : L.Relations l) (ts : Fin l → L.Term (α ⊕ (Fin n))) : BoundedFormula n /-- The implication between two bounded formulas. -/ | imp {n} (f₁ f₂ : BoundedFormula n) : BoundedFormula n /-- The universal quantifier over bounded formulas. -/ | all {n} (f : BoundedFormula (n + 1)) : BoundedFormula n /-- `Formula α` is the type of formulas with free variables indexed by `α` and no bound variables in scope. -/ abbrev Formula := L.BoundedFormula α 0 /-- A sentence is a formula with no free variables. -/ abbrev Sentence := L.Formula Empty /-- A theory is a set of sentences. -/ abbrev Theory := Set L.Sentence variable {L} {α} {n : ℕ} /-- Applies a relation to terms as a bounded formula. -/ def Relations.boundedFormula {l : ℕ} (R : L.Relations n) (ts : Fin n → L.Term (α ⊕ (Fin l))) : L.BoundedFormula α l := BoundedFormula.rel R ts /-- Applies a unary relation to a term as a bounded formula. -/ def Relations.boundedFormula₁ (r : L.Relations 1) (t : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n := r.boundedFormula ![t] /-- Applies a binary relation to two terms as a bounded formula. -/ def Relations.boundedFormula₂ (r : L.Relations 2) (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n := r.boundedFormula ![t₁, t₂] /-- The equality of two terms as a bounded formula. -/ def Term.bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin n))) : L.BoundedFormula α n := BoundedFormula.equal t₁ t₂ /-- Applies a relation to terms as a formula. -/ def Relations.formula (R : L.Relations n) (ts : Fin n → L.Term α) : L.Formula α := R.boundedFormula fun i => (ts i).relabel Sum.inl /-- Applies a unary relation to a term as a formula. -/ def Relations.formula₁ (r : L.Relations 1) (t : L.Term α) : L.Formula α := r.formula ![t] /-- Applies a binary relation to two terms as a formula. -/ def Relations.formula₂ (r : L.Relations 2) (t₁ t₂ : L.Term α) : L.Formula α := r.formula ![t₁, t₂] /-- The equality of two terms as a first-order formula. -/ def Term.equal (t₁ t₂ : L.Term α) : L.Formula α := (t₁.relabel Sum.inl).bdEqual (t₂.relabel Sum.inl) namespace BoundedFormula instance : Inhabited (L.BoundedFormula α n) := ⟨falsum⟩ instance : Bot (L.BoundedFormula α n) := ⟨falsum⟩ /-- The negation of a bounded formula is also a bounded formula. -/ @[match_pattern] protected def not (φ : L.BoundedFormula α n) : L.BoundedFormula α n := φ.imp ⊥ /-- Puts an `∃` quantifier on a bounded formula. -/ @[match_pattern] protected def ex (φ : L.BoundedFormula α (n + 1)) : L.BoundedFormula α n := φ.not.all.not instance : Top (L.BoundedFormula α n) := ⟨BoundedFormula.not ⊥⟩ instance : Min (L.BoundedFormula α n) := ⟨fun f g => (f.imp g.not).not⟩ instance : Max (L.BoundedFormula α n) := ⟨fun f g => f.not.imp g⟩ /-- The biimplication between two bounded formulas. -/ protected def iff (φ ψ : L.BoundedFormula α n) := φ.imp ψ ⊓ ψ.imp φ open Finset /-- The `Finset` of free variables used in a given formula. -/ @[simp] def freeVarFinset [DecidableEq α] : ∀ {n}, L.BoundedFormula α n → Finset α | _n, falsum => ∅ | _n, equal t₁ t₂ => t₁.varFinsetLeft ∪ t₂.varFinsetLeft | _n, rel _R ts => univ.biUnion fun i => (ts i).varFinsetLeft | _n, imp f₁ f₂ => f₁.freeVarFinset ∪ f₂.freeVarFinset | _n, all f => f.freeVarFinset /-- Casts `L.BoundedFormula α m` as `L.BoundedFormula α n`, where `m ≤ n`. -/ @[simp] def castLE : ∀ {m n : ℕ} (_h : m ≤ n), L.BoundedFormula α m → L.BoundedFormula α n | _m, _n, _h, falsum => falsum | _m, _n, h, equal t₁ t₂ => equal (t₁.relabel (Sum.map id (Fin.castLE h))) (t₂.relabel (Sum.map id (Fin.castLE h))) | _m, _n, h, rel R ts => rel R (Term.relabel (Sum.map id (Fin.castLE h)) ∘ ts) | _m, _n, h, imp f₁ f₂ => (f₁.castLE h).imp (f₂.castLE h) | _m, _n, h, all f => (f.castLE (by gcongr)).all @[simp] theorem castLE_rfl {n} (h : n ≤ n) (φ : L.BoundedFormula α n) : φ.castLE h = φ := by induction φ with | falsum => rfl | equal => simp | rel => simp | imp _ _ ih1 ih2 => simp [ih1, ih2] | all _ ih3 => simp [ih3] @[simp] theorem castLE_castLE {k m n} (km : k ≤ m) (mn : m ≤ n) (φ : L.BoundedFormula α k) : (φ.castLE km).castLE mn = φ.castLE (km.trans mn) := by revert m n induction φ with | falsum => intros; rfl | equal => simp | rel => intros simp only [castLE] rw [← Function.comp_assoc, Term.relabel_comp_relabel] simp | imp _ _ ih1 ih2 => simp [ih1, ih2] | all _ ih3 => intros; simp only [castLE, ih3] @[simp] theorem castLE_comp_castLE {k m n} (km : k ≤ m) (mn : m ≤ n) : (BoundedFormula.castLE mn ∘ BoundedFormula.castLE km : L.BoundedFormula α k → L.BoundedFormula α n) = BoundedFormula.castLE (km.trans mn) := funext (castLE_castLE km mn) /-- Restricts a bounded formula to only use a particular set of free variables. -/ def restrictFreeVar [DecidableEq α] : ∀ {n : ℕ} (φ : L.BoundedFormula α n) (_f : φ.freeVarFinset → β), L.BoundedFormula β n | _n, falsum, _f => falsum | _n, equal t₁ t₂, f => equal (t₁.restrictVarLeft (f ∘ Set.inclusion subset_union_left)) (t₂.restrictVarLeft (f ∘ Set.inclusion subset_union_right)) | _n, rel R ts, f => rel R fun i => (ts i).restrictVarLeft (f ∘ Set.inclusion (subset_biUnion_of_mem (fun i => Term.varFinsetLeft (ts i)) (mem_univ i))) | _n, imp φ₁ φ₂, f => (φ₁.restrictFreeVar (f ∘ Set.inclusion subset_union_left)).imp (φ₂.restrictFreeVar (f ∘ Set.inclusion subset_union_right)) | _n, all φ, f => (φ.restrictFreeVar f).all /-- Places universal quantifiers on all in-scope bound variables of a bounded formula. -/ def alls : ∀ {n}, L.BoundedFormula α n → L.Formula α | 0, φ => φ | _n + 1, φ => φ.all.alls /-- Places existential quantifiers on all in-scope bound variables of a bounded formula. -/ def exs : ∀ {n}, L.BoundedFormula α n → L.Formula α | 0, φ => φ | _n + 1, φ => φ.ex.exs /-- Maps bounded formulas along a map of terms and a map of relations. -/ def mapTermRel {g : ℕ → ℕ} (ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (g n)))) (fr : ∀ n, L.Relations n → L'.Relations n) (h : ∀ n, L'.BoundedFormula β (g (n + 1)) → L'.BoundedFormula β (g n + 1)) : ∀ {n}, L.BoundedFormula α n → L'.BoundedFormula β (g n) | _n, falsum => falsum | _n, equal t₁ t₂ => equal (ft _ t₁) (ft _ t₂) | _n, rel R ts => rel (fr _ R) fun i => ft _ (ts i) | _n, imp φ₁ φ₂ => (φ₁.mapTermRel ft fr h).imp (φ₂.mapTermRel ft fr h) | n, all φ => (h n (φ.mapTermRel ft fr h)).all /-- Raises all of the bound variables of a formula greater than or equal to `m` by `n'`. -/ def liftAt : ∀ {n : ℕ} (n' _m : ℕ), L.BoundedFormula α n → L.BoundedFormula α (n + n') := fun {_} n' m φ => φ.mapTermRel (fun _ t => t.liftAt n' m) (fun _ => id) fun _ => castLE (by rw [add_assoc, add_comm 1, add_assoc]) @[simp] theorem mapTermRel_mapTermRel {L'' : Language} (ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n))) (fr : ∀ n, L.Relations n → L'.Relations n) (ft' : ∀ n, L'.Term (β ⊕ Fin n) → L''.Term (γ ⊕ (Fin n))) (fr' : ∀ n, L'.Relations n → L''.Relations n) {n} (φ : L.BoundedFormula α n) : ((φ.mapTermRel ft fr fun _ => id).mapTermRel ft' fr' fun _ => id) = φ.mapTermRel (fun _ => ft' _ ∘ ft _) (fun _ => fr' _ ∘ fr _) fun _ => id := by induction φ with | falsum => rfl | equal => simp [mapTermRel] | rel => simp [mapTermRel] | imp _ _ ih1 ih2 => simp [mapTermRel, ih1, ih2] | all _ ih3 => simp [mapTermRel, ih3] @[simp] theorem mapTermRel_id_id_id {n} (φ : L.BoundedFormula α n) : (φ.mapTermRel (fun _ => id) (fun _ => id) fun _ => id) = φ := by induction φ with | falsum => rfl | equal => simp [mapTermRel] | rel => simp [mapTermRel] | imp _ _ ih1 ih2 => simp [mapTermRel, ih1, ih2] | all _ ih3 => simp [mapTermRel, ih3] /-- An equivalence of bounded formulas given by an equivalence of terms and an equivalence of relations. -/ @[simps] def mapTermRelEquiv (ft : ∀ n, L.Term (α ⊕ (Fin n)) ≃ L'.Term (β ⊕ (Fin n))) (fr : ∀ n, L.Relations n ≃ L'.Relations n) {n} : L.BoundedFormula α n ≃ L'.BoundedFormula β n := ⟨mapTermRel (fun n => ft n) (fun n => fr n) fun _ => id, mapTermRel (fun n => (ft n).symm) (fun n => (fr n).symm) fun _ => id, fun φ => by simp, fun φ => by simp⟩ /-- A function to help relabel the variables in bounded formulas. -/ def relabelAux (g : α → β ⊕ (Fin n)) (k : ℕ) : α ⊕ (Fin k) → β ⊕ (Fin (n + k)) := Sum.map id finSumFinEquiv ∘ Equiv.sumAssoc _ _ _ ∘ Sum.map g id @[simp] theorem sumElim_comp_relabelAux {m : ℕ} {g : α → β ⊕ (Fin n)} {v : β → M} {xs : Fin (n + m) → M} : Sum.elim v xs ∘ relabelAux g m = Sum.elim (Sum.elim v (xs ∘ castAdd m) ∘ g) (xs ∘ natAdd n) := by ext x rcases x with x | x · simp only [BoundedFormula.relabelAux, Function.comp_apply, Sum.map_inl, Sum.elim_inl] rcases g x with l | r <;> simp · simp [BoundedFormula.relabelAux] @[simp] theorem relabelAux_sumInl (k : ℕ) : relabelAux (Sum.inl : α → α ⊕ (Fin n)) k = Sum.map id (natAdd n) := by ext x cases x <;> · simp [relabelAux] /-- Relabels a bounded formula's variables along a particular function. -/ def relabel (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α k) : L.BoundedFormula β (n + k) := φ.mapTermRel (fun _ t => t.relabel (relabelAux g _)) (fun _ => id) fun _ => castLE (ge_of_eq (add_assoc _ _ _)) /-- Relabels a bounded formula's free variables along a bijection. -/ def relabelEquiv (g : α ≃ β) {k} : L.BoundedFormula α k ≃ L.BoundedFormula β k := mapTermRelEquiv (fun _n => Term.relabelEquiv (g.sumCongr (_root_.Equiv.refl _))) fun _n => _root_.Equiv.refl _ @[simp] theorem relabel_falsum (g : α → β ⊕ (Fin n)) {k} : (falsum : L.BoundedFormula α k).relabel g = falsum := rfl @[simp] theorem relabel_bot (g : α → β ⊕ (Fin n)) {k} : (⊥ : L.BoundedFormula α k).relabel g = ⊥ := rfl @[simp] theorem relabel_imp (g : α → β ⊕ (Fin n)) {k} (φ ψ : L.BoundedFormula α k) : (φ.imp ψ).relabel g = (φ.relabel g).imp (ψ.relabel g) := rfl @[simp] theorem relabel_not (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α k) : φ.not.relabel g = (φ.relabel g).not := by simp [BoundedFormula.not] @[simp] theorem relabel_all (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α (k + 1)) : φ.all.relabel g = (φ.relabel g).all := by rw [relabel, mapTermRel, relabel] simp @[simp] theorem relabel_ex (g : α → β ⊕ (Fin n)) {k} (φ : L.BoundedFormula α (k + 1)) : φ.ex.relabel g = (φ.relabel g).ex := by simp [BoundedFormula.ex] @[simp] theorem relabel_sumInl (φ : L.BoundedFormula α n) : (φ.relabel Sum.inl : L.BoundedFormula α (0 + n)) = φ.castLE (ge_of_eq (zero_add n)) := by simp only [relabel, relabelAux_sumInl] induction φ with | falsum => rfl | equal => simp [Fin.natAdd_zero, castLE_of_eq, mapTermRel] | rel => simp [Fin.natAdd_zero, castLE_of_eq, mapTermRel]; rfl | imp _ _ ih1 ih2 => simp_all [mapTermRel] | all _ ih3 => simp_all [mapTermRel] /-- Substitutes the free variables in a bounded formula with terms, leaving bound variables unchanged. -/ def subst {n : ℕ} (φ : L.BoundedFormula α n) (f : α → L.Term β) : L.BoundedFormula β n := φ.mapTermRel (fun _ t => t.subst (Sum.elim (Term.relabel Sum.inl ∘ f) (var ∘ Sum.inr))) (fun _ => id) fun _ => id /-- A bijection sending formulas with constants to formulas with extra free variables. -/ def constantsVarsEquiv : L[[γ]].BoundedFormula α n ≃ L.BoundedFormula (γ ⊕ α) n := mapTermRelEquiv (fun _ => Term.constantsVarsEquivLeft) fun _ => Equiv.sumEmpty _ _ /-- Turns all the in-scope bound variables into free variables. -/ @[simp] def toFormula : ∀ {n : ℕ}, L.BoundedFormula α n → L.Formula (α ⊕ (Fin n)) | _n, falsum => falsum | _n, equal t₁ t₂ => t₁.equal t₂ | _n, rel R ts => R.formula ts | _n, imp φ₁ φ₂ => φ₁.toFormula.imp φ₂.toFormula | _n, all φ => (φ.toFormula.relabel (Sum.elim (Sum.inl ∘ Sum.inl) (Sum.map Sum.inr id ∘ finSumFinEquiv.symm))).all /-- Take the disjunction of a finite set of formulas. Note that this is an arbitrary formula defined using the axiom of choice. It is only well-defined up to equivalence of formulas. -/ noncomputable def iSup [Finite β] (f : β → L.BoundedFormula α n) : L.BoundedFormula α n := let _ := Fintype.ofFinite β ((Finset.univ : Finset β).toList.map f).foldr (· ⊔ ·) ⊥ /-- Take the conjunction of a finite set of formulas. Note that this is an arbitrary formula defined using the axiom of choice. It is only well-defined up to equivalence of formulas. -/ noncomputable def iInf [Finite β] (f : β → L.BoundedFormula α n) : L.BoundedFormula α n := let _ := Fintype.ofFinite β ((Finset.univ : Finset β).toList.map f).foldr (· ⊓ ·) ⊤ end BoundedFormula namespace LHom open BoundedFormula /-- Maps a bounded formula's symbols along a language map. -/ @[simp] def onBoundedFormula (g : L →ᴸ L') : ∀ {k : ℕ}, L.BoundedFormula α k → L'.BoundedFormula α k | _k, falsum => falsum | _k, equal t₁ t₂ => (g.onTerm t₁).bdEqual (g.onTerm t₂) | _k, rel R ts => (g.onRelation R).boundedFormula (g.onTerm ∘ ts) | _k, imp f₁ f₂ => (onBoundedFormula g f₁).imp (onBoundedFormula g f₂) | _k, all f => (onBoundedFormula g f).all @[simp] theorem id_onBoundedFormula : ((LHom.id L).onBoundedFormula : L.BoundedFormula α n → L.BoundedFormula α n) = id := by ext f induction f with | falsum => rfl | equal => rw [onBoundedFormula, LHom.id_onTerm, id, id, id, Term.bdEqual] | rel => rw [onBoundedFormula, LHom.id_onTerm]; rfl | imp _ _ ih1 ih2 => rw [onBoundedFormula, ih1, ih2, id, id, id] | all _ ih3 => rw [onBoundedFormula, ih3, id, id] @[simp] theorem comp_onBoundedFormula {L'' : Language} (φ : L' →ᴸ L'') (ψ : L →ᴸ L') : ((φ.comp ψ).onBoundedFormula : L.BoundedFormula α n → L''.BoundedFormula α n) = φ.onBoundedFormula ∘ ψ.onBoundedFormula := by ext f induction f with | falsum => rfl | equal => simp [Term.bdEqual] | rel => simp only [onBoundedFormula, comp_onRelation, comp_onTerm, Function.comp_apply]; rfl | imp _ _ ih1 ih2 => simp only [onBoundedFormula, Function.comp_apply, ih1, ih2] | all _ ih3 => simp only [ih3, onBoundedFormula, Function.comp_apply] /-- Maps a formula's symbols along a language map. -/ def onFormula (g : L →ᴸ L') : L.Formula α → L'.Formula α := g.onBoundedFormula /-- Maps a sentence's symbols along a language map. -/ def onSentence (g : L →ᴸ L') : L.Sentence → L'.Sentence := g.onFormula /-- Maps a theory's symbols along a language map. -/ def onTheory (g : L →ᴸ L') (T : L.Theory) : L'.Theory := g.onSentence '' T @[simp] theorem mem_onTheory {g : L →ᴸ L'} {T : L.Theory} {φ : L'.Sentence} : φ ∈ g.onTheory T ↔ ∃ φ₀, φ₀ ∈ T ∧ g.onSentence φ₀ = φ := Set.mem_image _ _ _ end LHom namespace LEquiv /-- Maps a bounded formula's symbols along a language equivalence. -/ @[simps] def onBoundedFormula (φ : L ≃ᴸ L') : L.BoundedFormula α n ≃ L'.BoundedFormula α n where toFun := φ.toLHom.onBoundedFormula invFun := φ.invLHom.onBoundedFormula left_inv := by rw [Function.leftInverse_iff_comp, ← LHom.comp_onBoundedFormula, φ.left_inv, LHom.id_onBoundedFormula] right_inv := by rw [Function.rightInverse_iff_comp, ← LHom.comp_onBoundedFormula, φ.right_inv, LHom.id_onBoundedFormula] theorem onBoundedFormula_symm (φ : L ≃ᴸ L') : (φ.onBoundedFormula.symm : L'.BoundedFormula α n ≃ L.BoundedFormula α n) = φ.symm.onBoundedFormula := rfl /-- Maps a formula's symbols along a language equivalence. -/ def onFormula (φ : L ≃ᴸ L') : L.Formula α ≃ L'.Formula α := φ.onBoundedFormula @[simp] theorem onFormula_apply (φ : L ≃ᴸ L') : (φ.onFormula : L.Formula α → L'.Formula α) = φ.toLHom.onFormula := rfl @[simp] theorem onFormula_symm (φ : L ≃ᴸ L') : (φ.onFormula.symm : L'.Formula α ≃ L.Formula α) = φ.symm.onFormula := rfl /-- Maps a sentence's symbols along a language equivalence. -/ @[simps!] def onSentence (φ : L ≃ᴸ L') : L.Sentence ≃ L'.Sentence := φ.onFormula end LEquiv @[inherit_doc] scoped[FirstOrder] infixl:88 " =' " => FirstOrder.Language.Term.bdEqual -- input \~- or \simeq @[inherit_doc] scoped[FirstOrder] infixr:62 " ⟹ " => FirstOrder.Language.BoundedFormula.imp -- input \==> @[inherit_doc] scoped[FirstOrder] prefix:110 "∀' " => FirstOrder.Language.BoundedFormula.all @[inherit_doc] scoped[FirstOrder] prefix:arg "∼" => FirstOrder.Language.BoundedFormula.not -- input \~, the ASCII character ~ has too low precedence @[inherit_doc] scoped[FirstOrder] infixl:61 " ⇔ " => FirstOrder.Language.BoundedFormula.iff -- input \<=> @[inherit_doc] scoped[FirstOrder] prefix:110 "∃' " => FirstOrder.Language.BoundedFormula.ex -- input \ex namespace Formula /-- Relabels a formula's variables along a particular function. -/ def relabel (g : α → β) : L.Formula α → L.Formula β := @BoundedFormula.relabel _ _ _ 0 (Sum.inl ∘ g) 0 /-- The graph of a function as a first-order formula. -/ def graph (f : L.Functions n) : L.Formula (Fin (n + 1)) := Term.equal (var 0) (func f fun i => var i.succ) /-- The negation of a formula. -/ protected nonrec abbrev not (φ : L.Formula α) : L.Formula α := φ.not /-- The implication between formulas, as a formula. -/ protected abbrev imp : L.Formula α → L.Formula α → L.Formula α := BoundedFormula.imp variable (β) in /-- `iAlls f φ` transforms a `L.Formula (α ⊕ β)` into a `L.Formula α` by universally quantifying over all variables `Sum.inr _`. -/ noncomputable def iAlls [Finite β] (φ : L.Formula (α ⊕ β)) : L.Formula α := let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin β)) (BoundedFormula.relabel (fun a => Sum.map id e a) φ).alls variable (β) in /-- `iExs f φ` transforms a `L.Formula (α ⊕ β)` into a `L.Formula α` by existentially quantifying over all variables `Sum.inr _`. -/ noncomputable def iExs [Finite β] (φ : L.Formula (α ⊕ β)) : L.Formula α := let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin β)) (BoundedFormula.relabel (fun a => Sum.map id e a) φ).exs variable (β) in /-- `iExsUnique f φ` transforms a `L.Formula (α ⊕ β)` into a `L.Formula α` by existentially quantifying over all variables `Sum.inr _` and asserting that the solution should be unique -/ noncomputable def iExsUnique [Finite β] (φ : L.Formula (α ⊕ β)) : L.Formula α := iExs β <| φ ⊓ iAlls β ((φ.relabel (fun a => Sum.elim (.inl ∘ .inl) .inr a)).imp <| .iInf fun g => Term.equal (var (.inr g)) (var (.inl (.inr g)))) /-- The biimplication between formulas, as a formula. -/ protected nonrec abbrev iff (φ ψ : L.Formula α) : L.Formula α := φ.iff ψ /-- Take the disjunction of finitely many formulas. Note that this is an arbitrary formula defined using the axiom of choice. It is only well-defined up to equivalence of formulas. -/ noncomputable def iSup [Finite α] (f : α → L.Formula β) : L.Formula β := BoundedFormula.iSup f /-- Take the conjunction of finitely many formulas. Note that this is an arbitrary formula defined using the axiom of choice. It is only well-defined up to equivalence of formulas. -/ noncomputable def iInf [Finite α] (f : α → L.Formula β) : L.Formula β := BoundedFormula.iInf f /-- A bijection sending formulas to sentences with constants. -/ def equivSentence : L.Formula α ≃ L[[α]].Sentence := (BoundedFormula.constantsVarsEquiv.trans (BoundedFormula.relabelEquiv (Equiv.sumEmpty _ _))).symm theorem equivSentence_not (φ : L.Formula α) : equivSentence φ.not = (equivSentence φ).not := rfl theorem equivSentence_inf (φ ψ : L.Formula α) : equivSentence (φ ⊓ ψ) = equivSentence φ ⊓ equivSentence ψ := rfl end Formula namespace Relations variable (r : L.Relations 2) /-- The sentence indicating that a basic relation symbol is reflexive. -/ protected def reflexive : L.Sentence := ∀' r.boundedFormula₂ (&0) &0 /-- The sentence indicating that a basic relation symbol is irreflexive. -/ protected def irreflexive : L.Sentence := ∀' ∼(r.boundedFormula₂ (&0) &0) /-- The sentence indicating that a basic relation symbol is symmetric. -/ protected def symmetric : L.Sentence := ∀' ∀' (r.boundedFormula₂ (&0) &1 ⟹ r.boundedFormula₂ (&1) &0) /-- The sentence indicating that a basic relation symbol is antisymmetric. -/ protected def antisymmetric : L.Sentence := ∀' ∀' (r.boundedFormula₂ (&0) &1 ⟹ r.boundedFormula₂ (&1) &0 ⟹ Term.bdEqual (&0) &1) /-- The sentence indicating that a basic relation symbol is transitive. -/ protected def transitive : L.Sentence := ∀' ∀' ∀' (r.boundedFormula₂ (&0) &1 ⟹ r.boundedFormula₂ (&1) &2 ⟹ r.boundedFormula₂ (&0) &2) /-- The sentence indicating that a basic relation symbol is total. -/ protected def total : L.Sentence := ∀' ∀' (r.boundedFormula₂ (&0) &1 ⊔ r.boundedFormula₂ (&1) &0) end Relations section Cardinality variable (L) /-- A sentence indicating that a structure has `n` distinct elements. -/ protected def Sentence.cardGe (n : ℕ) : L.Sentence := ((((List.finRange n ×ˢ List.finRange n).filter fun ij : _ × _ => ij.1 ≠ ij.2).map fun ij : _ × _ => ∼((&ij.1).bdEqual &ij.2)).foldr (· ⊓ ·) ⊤).exs /-- A theory indicating that a structure is infinite. -/ def infiniteTheory : L.Theory := Set.range (Sentence.cardGe L) /-- A theory that indicates a structure is nonempty. -/ def nonemptyTheory : L.Theory := {Sentence.cardGe L 1} /-- A theory indicating that each of a set of constants is distinct. -/ def distinctConstantsTheory (s : Set α) : L[[α]].Theory := (fun ab : α × α => ((L.con ab.1).term.equal (L.con ab.2).term).not) '' (s ×ˢ s ∩ (Set.diagonal α)ᶜ) variable {L} open Set theorem distinctConstantsTheory_mono {s t : Set α} (h : s ⊆ t) : L.distinctConstantsTheory s ⊆ L.distinctConstantsTheory t := by unfold distinctConstantsTheory; gcongr theorem monotone_distinctConstantsTheory : Monotone (L.distinctConstantsTheory : Set α → L[[α]].Theory) := fun _s _t st => L.distinctConstantsTheory_mono st theorem directed_distinctConstantsTheory : Directed (· ⊆ ·) (L.distinctConstantsTheory : Set α → L[[α]].Theory) := Monotone.directed_le monotone_distinctConstantsTheory theorem distinctConstantsTheory_eq_iUnion (s : Set α) : L.distinctConstantsTheory s = ⋃ t : Finset s, L.distinctConstantsTheory (t.map (Function.Embedding.subtype fun x => x ∈ s)) := by classical simp only [distinctConstantsTheory] rw [← image_iUnion, ← iUnion_inter] refine congr(_ '' ($(?_) ∩ _)) ext ⟨i, j⟩ simp only [prodMk_mem_set_prod_eq, Finset.coe_map, Function.Embedding.coe_subtype, mem_iUnion, mem_image, Finset.mem_coe, Subtype.exists, exists_and_right, exists_eq_right] refine ⟨fun h => ⟨{⟨i, h.1⟩, ⟨j, h.2⟩}, ⟨h.1, ?_⟩, ⟨h.2, ?_⟩⟩, ?_⟩ · simp · simp · rintro ⟨t, ⟨is, _⟩, ⟨js, _⟩⟩ exact ⟨is, js⟩ end Cardinality end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Basic.lean
import Mathlib.SetTheory.Cardinal.Basic /-! # Basics on First-Order Structures This file defines first-order languages and structures in the style of the [Flypitch project](https://flypitch.github.io/), as well as several important maps between structures. ## Main Definitions - A `FirstOrder.Language` defines a language as a pair of functions from the natural numbers to `Type l`. One sends `n` to the type of `n`-ary functions, and the other sends `n` to the type of `n`-ary relations. - A `FirstOrder.Language.Structure` interprets the symbols of a given `FirstOrder.Language` in the context of a given type. - A `FirstOrder.Language.Hom`, denoted `M →[L] N`, is a map from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations (although only in the forward direction). - A `FirstOrder.Language.Embedding`, denoted `M ↪[L] N`, is an embedding from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations in both directions. - A `FirstOrder.Language.Equiv`, denoted `M ≃[L] N`, is an equivalence from the `L`-structure `M` to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves the interpretations of relations in both directions. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v u' v' w w' open Cardinal namespace FirstOrder /-! ### Languages and Structures -/ -- intended to be used with explicit universe parameters /-- A first-order language consists of a type of functions of every natural-number arity and a type of relations of every natural-number arity. -/ @[nolint checkUnivs] structure Language where /-- For every arity, a `Type*` of functions of that arity -/ Functions : ℕ → Type u /-- For every arity, a `Type*` of relations of that arity -/ Relations : ℕ → Type v namespace Language variable (L : Language.{u, v}) /-- A language is relational when it has no function symbols. -/ abbrev IsRelational : Prop := ∀ n, IsEmpty (L.Functions n) /-- A language is algebraic when it has no relation symbols. -/ abbrev IsAlgebraic : Prop := ∀ n, IsEmpty (L.Relations n) /-- The empty language has no symbols. -/ protected def empty : Language := ⟨fun _ => Empty, fun _ => Empty⟩ deriving IsAlgebraic, IsRelational instance : Inhabited Language := ⟨Language.empty⟩ /-- The sum of two languages consists of the disjoint union of their symbols. -/ protected def sum (L' : Language.{u', v'}) : Language := ⟨fun n => L.Functions n ⊕ L'.Functions n, fun n => L.Relations n ⊕ L'.Relations n⟩ /-- The type of constants in a given language. -/ protected abbrev Constants := L.Functions 0 /-- The type of symbols in a given language. -/ abbrev Symbols := (Σ l, L.Functions l) ⊕ (Σ l, L.Relations l) /-- The cardinality of a language is the cardinality of its type of symbols. -/ def card : Cardinal := #L.Symbols variable {L} {L' : Language.{u', v'}} theorem card_eq_card_functions_add_card_relations : L.card = (Cardinal.sum fun l => Cardinal.lift.{v} #(L.Functions l)) + Cardinal.sum fun l => Cardinal.lift.{u} #(L.Relations l) := by simp only [card, mk_sum, mk_sigma, lift_sum] instance isRelational_sum [L.IsRelational] [L'.IsRelational] : IsRelational (L.sum L') := fun _ => instIsEmptySum instance isAlgebraic_sum [L.IsAlgebraic] [L'.IsAlgebraic] : IsAlgebraic (L.sum L') := fun _ => instIsEmptySum @[simp] theorem card_empty : Language.empty.card = 0 := by simp only [card, mk_sum, mk_sigma, mk_eq_zero, sum_const, mk_eq_aleph0, lift_id', mul_zero, add_zero] instance isEmpty_empty : IsEmpty Language.empty.Symbols := by simp only [Language.Symbols, isEmpty_sum, isEmpty_sigma] exact ⟨fun _ => inferInstance, fun _ => inferInstance⟩ instance Countable.countable_functions [h : Countable L.Symbols] : Countable (Σ l, L.Functions l) := @Function.Injective.countable _ _ h _ Sum.inl_injective @[simp] theorem card_functions_sum (i : ℕ) : #((L.sum L').Functions i) = (Cardinal.lift.{u'} #(L.Functions i) + Cardinal.lift.{u} #(L'.Functions i) : Cardinal) := by simp [Language.sum] @[simp] theorem card_relations_sum (i : ℕ) : #((L.sum L').Relations i) = Cardinal.lift.{v'} #(L.Relations i) + Cardinal.lift.{v} #(L'.Relations i) := by simp [Language.sum] theorem card_sum : (L.sum L').card = Cardinal.lift.{max u' v'} L.card + Cardinal.lift.{max u v} L'.card := by simp only [card, mk_sum, mk_sigma, card_functions_sum, sum_add_distrib', lift_add, lift_sum, lift_lift, card_relations_sum, add_assoc, add_comm (Cardinal.sum fun i => (#(L'.Functions i)).lift)] /-- Passes a `DecidableEq` instance on a type of function symbols through the `Language` constructor. Despite the fact that this is proven by `inferInstance`, it is still needed - see the `example`s in `ModelTheory/Ring/Basic`. -/ instance instDecidableEqFunctions {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (f n)] : DecidableEq ((⟨f, R⟩ : Language).Functions n) := inferInstance /-- Passes a `DecidableEq` instance on a type of relation symbols through the `Language` constructor. Despite the fact that this is proven by `inferInstance`, it is still needed - see the `example`s in `ModelTheory/Ring/Basic`. -/ instance instDecidableEqRelations {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (R n)] : DecidableEq ((⟨f, R⟩ : Language).Relations n) := inferInstance variable (L) (M : Type w) /-- A first-order structure on a type `M` consists of interpretations of all the symbols in a given language. Each function of arity `n` is interpreted as a function sending tuples of length `n` (modeled as `(Fin n → M)`) to `M`, and a relation of arity `n` is a function from tuples of length `n` to `Prop`. -/ @[ext] class Structure where /-- Interpretation of the function symbols -/ funMap : ∀ {n}, L.Functions n → (Fin n → M) → M := by exact fun {n} => isEmptyElim /-- Interpretation of the relation symbols -/ RelMap : ∀ {n}, L.Relations n → (Fin n → M) → Prop := by exact fun {n} => isEmptyElim variable (N : Type w') [L.Structure M] [L.Structure N] open Structure /-- Used for defining `FirstOrder.Language.Theory.ModelType.instInhabited`. -/ def Inhabited.trivialStructure {α : Type*} [Inhabited α] : L.Structure α := ⟨default, default⟩ /-! ### Maps -/ /-- A homomorphism between first-order structures is a function that commutes with the interpretations of functions and maps tuples in one structure where a given relation is true to tuples in the second structure where that relation is still true. -/ structure Hom where /-- The underlying function of a homomorphism of structures -/ toFun : M → N /-- The homomorphism commutes with the interpretations of the function symbols -/ -- Porting note: -- The autoparam here used to be `obviously`. We would like to replace it with `aesop` -- but that isn't currently sufficient. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases -- If that can be improved, we should change this to `by aesop` and remove the proofs below. map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by intros; trivial /-- The homomorphism sends related elements to related elements -/ map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r x → RelMap r (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial @[inherit_doc] scoped[FirstOrder] notation:25 A " →[" L "] " B => FirstOrder.Language.Hom L A B /-- An embedding of first-order structures is an embedding that commutes with the interpretations of functions and relations. -/ structure Embedding extends M ↪ N where map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial @[inherit_doc] scoped[FirstOrder] notation:25 A " ↪[" L "] " B => FirstOrder.Language.Embedding L A B /-- An equivalence of first-order structures is an equivalence that commutes with the interpretations of functions and relations. -/ structure Equiv extends M ≃ N where map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by -- Porting note: see porting note on `Hom.map_fun'` intros; trivial @[inherit_doc] scoped[FirstOrder] notation:25 A " ≃[" L "] " B => FirstOrder.Language.Equiv L A B variable {L M N} {P : Type*} [L.Structure P] {Q : Type*} [L.Structure Q] /-- Interpretation of a constant symbol -/ @[coe] def constantMap (c : L.Constants) : M := funMap c default instance : CoeTC L.Constants M := ⟨constantMap⟩ theorem funMap_eq_coe_constants {c : L.Constants} {x : Fin 0 → M} : funMap c x = c := congr rfl (funext finZeroElim) /-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot be a global instance, because `L` becomes a metavariable. -/ theorem nonempty_of_nonempty_constants [h : Nonempty L.Constants] : Nonempty M := h.map (↑) /-- `HomClass L F M N` states that `F` is a type of `L`-homomorphisms. You should extend this typeclass when you extend `FirstOrder.Language.Hom`. -/ class HomClass (L : outParam Language) (F : Type*) (M N : outParam Type*) [FunLike F M N] [L.Structure M] [L.Structure N] : Prop where map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x) map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r x → RelMap r (φ ∘ x) /-- `StrongHomClass L F M N` states that `F` is a type of `L`-homomorphisms which preserve relations in both directions. -/ class StrongHomClass (L : outParam Language) (F : Type*) (M N : outParam Type*) [FunLike F M N] [L.Structure M] [L.Structure N] : Prop where map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x) map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r (φ ∘ x) ↔ RelMap r x instance (priority := 100) StrongHomClass.homClass {F : Type*} [L.Structure M] [L.Structure N] [FunLike F M N] [StrongHomClass L F M N] : HomClass L F M N where map_fun := StrongHomClass.map_fun map_rel φ _ R x := (StrongHomClass.map_rel φ R x).2 /-- Not an instance to avoid a loop. -/ theorem HomClass.strongHomClassOfIsAlgebraic [L.IsAlgebraic] {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] : StrongHomClass L F M N where map_fun := HomClass.map_fun map_rel _ _ := isEmptyElim theorem HomClass.map_constants {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] (φ : F) (c : L.Constants) : φ c = c := (HomClass.map_fun φ c default).trans (congr rfl (funext default)) attribute [inherit_doc FirstOrder.Language.Hom.map_fun'] FirstOrder.Language.Embedding.map_fun' FirstOrder.Language.HomClass.map_fun FirstOrder.Language.StrongHomClass.map_fun FirstOrder.Language.Equiv.map_fun' attribute [inherit_doc FirstOrder.Language.Hom.map_rel'] FirstOrder.Language.Embedding.map_rel' FirstOrder.Language.HomClass.map_rel FirstOrder.Language.StrongHomClass.map_rel FirstOrder.Language.Equiv.map_rel' namespace Hom instance instFunLike : FunLike (M →[L] N) M N where coe := Hom.toFun coe_injective' f g h := by cases f; cases g; cases h; rfl instance homClass : HomClass L (M →[L] N) M N where map_fun := map_fun' map_rel := map_rel' instance [L.IsAlgebraic] : StrongHomClass L (M →[L] N) M N := HomClass.strongHomClassOfIsAlgebraic @[simp] theorem toFun_eq_coe {f : M →[L] N} : f.toFun = (f : M → N) := rfl @[ext] theorem ext ⦃f g : M →[L] N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[simp] theorem map_fun (φ : M →[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x @[simp] theorem map_constants (φ : M →[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c @[simp] theorem map_rel (φ : M →[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r x → RelMap r (φ ∘ x) := HomClass.map_rel φ r x variable (L) (M) /-- The identity map from a structure to itself. -/ @[refl] def id : M →[L] M where toFun m := m variable {L} {M} instance : Inhabited (M →[L] M) := ⟨id L M⟩ @[simp] theorem id_apply (x : M) : id L M x = x := rfl /-- Composition of first-order homomorphisms. -/ @[trans] def comp (hnp : N →[L] P) (hmn : M →[L] N) : M →[L] P where toFun := hnp ∘ hmn -- Porting note: should be done by autoparam? map_fun' _ _ := by simp; rfl -- Porting note: should be done by autoparam? map_rel' _ _ h := map_rel _ _ _ (map_rel _ _ _ h) @[simp] theorem comp_apply (g : N →[L] P) (f : M →[L] N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of first-order homomorphisms is associative. -/ theorem comp_assoc (f : M →[L] N) (g : N →[L] P) (h : P →[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem comp_id (f : M →[L] N) : f.comp (id L M) = f := rfl @[simp] theorem id_comp (f : M →[L] N) : (id L N).comp f = f := rfl end Hom /-- Any element of a `HomClass` can be realized as a first_order homomorphism. -/ @[simps] def HomClass.toHom {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [HomClass L F M N] : F → M →[L] N := fun φ => ⟨φ, HomClass.map_fun φ, HomClass.map_rel φ⟩ namespace Embedding instance funLike : FunLike (M ↪[L] N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g congr ext x exact funext_iff.1 h x instance embeddingLike : EmbeddingLike (M ↪[L] N) M N where injective' f := f.toEmbedding.injective instance strongHomClass : StrongHomClass L (M ↪[L] N) M N where map_fun := map_fun' map_rel := map_rel' @[simp] theorem map_fun (φ : M ↪[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x @[simp] theorem map_constants (φ : M ↪[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c @[simp] theorem map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := StrongHomClass.map_rel φ r x /-- A first-order embedding is also a first-order homomorphism. -/ def toHom : (M ↪[L] N) → M →[L] N := HomClass.toHom @[simp] theorem coe_toHom {f : M ↪[L] N} : (f.toHom : M → N) = f := rfl theorem coe_injective : @Function.Injective (M ↪[L] N) (M → N) (↑) | f, g, h => by cases f cases g congr ext x exact funext_iff.1 h x @[ext] theorem ext ⦃f g : M ↪[L] N⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) theorem toHom_injective : @Function.Injective (M ↪[L] N) (M →[L] N) (·.toHom) := by intro f f' h ext exact congr_fun (congr_arg (↑) h) _ @[simp] theorem toHom_inj {f g : M ↪[L] N} : f.toHom = g.toHom ↔ f = g := ⟨fun h ↦ toHom_injective h, fun h ↦ congr_arg (·.toHom) h⟩ theorem injective (f : M ↪[L] N) : Function.Injective f := f.toEmbedding.injective /-- In an algebraic language, any injective homomorphism is an embedding. -/ @[simps!] def ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : M ↪[L] N := { f with inj' := hf map_rel' := fun {_} r x => StrongHomClass.map_rel f r x } @[simp] theorem coeFn_ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : (ofInjective hf : M → N) = f := rfl @[simp] theorem ofInjective_toHom [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : (ofInjective hf).toHom = f := by ext; simp variable (L) (M) /-- The identity embedding from a structure to itself. -/ @[refl] def refl : M ↪[L] M where toEmbedding := Function.Embedding.refl M variable {L} {M} instance : Inhabited (M ↪[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := rfl /-- Composition of first-order embeddings. -/ @[trans] def comp (hnp : N ↪[L] P) (hmn : M ↪[L] N) : M ↪[L] P where toFun := hnp ∘ hmn inj' := hnp.injective.comp hmn.injective -- Porting note: should be done by autoparam? map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial -- Porting note: should be done by autoparam? map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel] @[simp] theorem comp_apply (g : N ↪[L] P) (f : M ↪[L] N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of first-order embeddings is associative. -/ theorem comp_assoc (f : M ↪[L] N) (g : N ↪[L] P) (h : P ↪[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl theorem comp_injective (h : N ↪[L] P) : Function.Injective (h.comp : (M ↪[L] N) → (M ↪[L] P)) := by intro f g hfg ext x; exact h.injective (DFunLike.congr_fun hfg x) @[simp] theorem comp_inj (h : N ↪[L] P) (f g : M ↪[L] N) : h.comp f = h.comp g ↔ f = g := ⟨fun eq ↦ h.comp_injective eq, congr_arg h.comp⟩ theorem toHom_comp_injective (h : N ↪[L] P) : Function.Injective (h.toHom.comp : (M →[L] N) → (M →[L] P)) := by intro f g hfg ext x; exact h.injective (DFunLike.congr_fun hfg x) @[simp] theorem toHom_comp_inj (h : N ↪[L] P) (f g : M →[L] N) : h.toHom.comp f = h.toHom.comp g ↔ f = g := ⟨fun eq ↦ h.toHom_comp_injective eq, congr_arg h.toHom.comp⟩ @[simp] theorem comp_toHom (hnp : N ↪[L] P) (hmn : M ↪[L] N) : (hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom := rfl @[simp] theorem comp_refl (f : M ↪[L] N) : f.comp (refl L M) = f := DFunLike.coe_injective rfl @[simp] theorem refl_comp (f : M ↪[L] N) : (refl L N).comp f = f := DFunLike.coe_injective rfl @[simp] theorem refl_toHom : (refl L M).toHom = Hom.id L M := rfl end Embedding /-- Any element of an injective `StrongHomClass` can be realized as a first_order embedding. -/ @[simps] def StrongHomClass.toEmbedding {F M N} [L.Structure M] [L.Structure N] [FunLike F M N] [EmbeddingLike F M N] [StrongHomClass L F M N] : F → M ↪[L] N := fun φ => ⟨⟨φ, EmbeddingLike.injective φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩ namespace Equiv instance : EquivLike (M ≃[L] N) M N where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by cases f cases g simp only [mk.injEq] ext x exact funext_iff.1 h₁ x instance : StrongHomClass L (M ≃[L] N) M N where map_fun := map_fun' map_rel := map_rel' /-- The inverse of a first-order equivalence is a first-order equivalence. -/ @[symm] def symm (f : M ≃[L] N) : N ≃[L] M := { f.toEquiv.symm with map_fun' := fun n f' {x} => by simp only [Equiv.toFun_as_coe] rw [Equiv.symm_apply_eq] refine Eq.trans ?_ (f.map_fun' f' (f.toEquiv.symm ∘ x)).symm rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] map_rel' := fun n r {x} => by simp only [Equiv.toFun_as_coe] refine (f.map_rel' r (f.toEquiv.symm ∘ x)).symm.trans ?_ rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] } @[simp] theorem symm_symm (f : M ≃[L] N) : f.symm.symm = f := rfl theorem symm_bijective : Function.Bijective (symm : (M ≃[L] N) → _) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (f : M ≃[L] N) (a : N) : f (f.symm a) = a := f.toEquiv.apply_symm_apply a @[simp] theorem symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a := f.toEquiv.symm_apply_apply a @[simp] theorem map_fun (φ : M ≃[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) : φ (funMap f x) = funMap f (φ ∘ x) := HomClass.map_fun φ f x @[simp] theorem map_constants (φ : M ≃[L] N) (c : L.Constants) : φ c = c := HomClass.map_constants φ c @[simp] theorem map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) : RelMap r (φ ∘ x) ↔ RelMap r x := StrongHomClass.map_rel φ r x /-- A first-order equivalence is also a first-order embedding. -/ def toEmbedding : (M ≃[L] N) → M ↪[L] N := StrongHomClass.toEmbedding /-- A first-order equivalence is also a first-order homomorphism. -/ def toHom : (M ≃[L] N) → M →[L] N := HomClass.toHom @[simp] theorem toEmbedding_toHom (f : M ≃[L] N) : f.toEmbedding.toHom = f.toHom := rfl @[simp] theorem coe_toHom {f : M ≃[L] N} : (f.toHom : M → N) = (f : M → N) := rfl @[simp] theorem coe_toEmbedding (f : M ≃[L] N) : (f.toEmbedding : M → N) = (f : M → N) := rfl theorem injective_toEmbedding : Function.Injective (toEmbedding : (M ≃[L] N) → M ↪[L] N) := by intro _ _ h; apply DFunLike.coe_injective; exact congr_arg (DFunLike.coe ∘ Embedding.toHom) h theorem coe_injective : @Function.Injective (M ≃[L] N) (M → N) (↑) := DFunLike.coe_injective @[ext] theorem ext ⦃f g : M ≃[L] N⦄ (h : ∀ x, f x = g x) : f = g := coe_injective (funext h) theorem bijective (f : M ≃[L] N) : Function.Bijective f := EquivLike.bijective f theorem injective (f : M ≃[L] N) : Function.Injective f := EquivLike.injective f theorem surjective (f : M ≃[L] N) : Function.Surjective f := EquivLike.surjective f variable (L) (M) /-- The identity equivalence from a structure to itself. -/ @[refl] def refl : M ≃[L] M where toEquiv := _root_.Equiv.refl M variable {L} {M} instance : Inhabited (M ≃[L] M) := ⟨refl L M⟩ @[simp] theorem refl_apply (x : M) : refl L M x = x := by simp [refl]; rfl /-- Composition of first-order equivalences. -/ @[trans] def comp (hnp : N ≃[L] P) (hmn : M ≃[L] N) : M ≃[L] P := { hmn.toEquiv.trans hnp.toEquiv with toFun := hnp ∘ hmn -- Porting note: should be done by autoparam? map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial -- Porting note: should be done by autoparam? map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel] } @[simp] theorem comp_apply (g : N ≃[L] P) (f : M ≃[L] N) (x : M) : g.comp f x = g (f x) := rfl @[simp] theorem comp_refl (g : M ≃[L] N) : g.comp (refl L M) = g := rfl @[simp] theorem refl_comp (g : M ≃[L] N) : (refl L N).comp g = g := rfl @[simp] theorem refl_toEmbedding : (refl L M).toEmbedding = Embedding.refl L M := rfl @[simp] theorem refl_toHom : (refl L M).toHom = Hom.id L M := rfl /-- Composition of first-order homomorphisms is associative. -/ theorem comp_assoc (f : M ≃[L] N) (g : N ≃[L] P) (h : P ≃[L] Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl theorem injective_comp (h : N ≃[L] P) : Function.Injective (h.comp : (M ≃[L] N) → (M ≃[L] P)) := by intro f g hfg ext x; exact h.injective (congr_fun (congr_arg DFunLike.coe hfg) x) @[simp] theorem comp_toHom (hnp : N ≃[L] P) (hmn : M ≃[L] N) : (hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom := rfl @[simp] theorem comp_toEmbedding (hnp : N ≃[L] P) (hmn : M ≃[L] N) : (hnp.comp hmn).toEmbedding = hnp.toEmbedding.comp hmn.toEmbedding := rfl @[simp] theorem self_comp_symm (f : M ≃[L] N) : f.comp f.symm = refl L N := by ext; rw [comp_apply, apply_symm_apply, refl_apply] @[simp] theorem symm_comp_self (f : M ≃[L] N) : f.symm.comp f = refl L M := by ext; rw [comp_apply, symm_apply_apply, refl_apply] @[simp] theorem symm_comp_self_toEmbedding (f : M ≃[L] N) : f.symm.toEmbedding.comp f.toEmbedding = Embedding.refl L M := by rw [← comp_toEmbedding, symm_comp_self, refl_toEmbedding] @[simp] theorem self_comp_symm_toEmbedding (f : M ≃[L] N) : f.toEmbedding.comp f.symm.toEmbedding = Embedding.refl L N := by rw [← comp_toEmbedding, self_comp_symm, refl_toEmbedding] @[simp] theorem symm_comp_self_toHom (f : M ≃[L] N) : f.symm.toHom.comp f.toHom = Hom.id L M := by rw [← comp_toHom, symm_comp_self, refl_toHom] @[simp] theorem self_comp_symm_toHom (f : M ≃[L] N) : f.toHom.comp f.symm.toHom = Hom.id L N := by rw [← comp_toHom, self_comp_symm, refl_toHom] @[simp] theorem comp_symm (f : M ≃[L] N) (g : N ≃[L] P) : (g.comp f).symm = f.symm.comp g.symm := rfl theorem comp_right_injective (h : M ≃[L] N) : Function.Injective (fun f ↦ f.comp h : (N ≃[L] P) → (M ≃[L] P)) := by intro f g hfg convert (congr_arg (fun r : (M ≃[L] P) ↦ r.comp h.symm) hfg) <;> rw [comp_assoc, self_comp_symm, comp_refl] @[simp] theorem comp_right_inj (h : M ≃[L] N) (f g : N ≃[L] P) : f.comp h = g.comp h ↔ f = g := ⟨fun eq ↦ h.comp_right_injective eq, congr_arg (fun (r : N ≃[L] P) ↦ r.comp h)⟩ end Equiv /-- Any element of a bijective `StrongHomClass` can be realized as a first_order isomorphism. -/ @[simps] def StrongHomClass.toEquiv {F M N} [L.Structure M] [L.Structure N] [EquivLike F M N] [StrongHomClass L F M N] : F → M ≃[L] N := fun φ => ⟨⟨φ, EquivLike.inv φ, EquivLike.left_inv φ, EquivLike.right_inv φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩ section SumStructure variable (L₁ L₂ : Language) (S : Type*) [L₁.Structure S] [L₂.Structure S] instance sumStructure : (L₁.sum L₂).Structure S where funMap := Sum.elim funMap funMap RelMap := Sum.elim RelMap RelMap variable {L₁ L₂ S} @[simp] theorem funMap_sumInl {n : ℕ} (f : L₁.Functions n) : @funMap (L₁.sum L₂) S _ n (Sum.inl f) = funMap f := rfl @[simp] theorem funMap_sumInr {n : ℕ} (f : L₂.Functions n) : @funMap (L₁.sum L₂) S _ n (Sum.inr f) = funMap f := rfl @[simp] theorem relMap_sumInl {n : ℕ} (R : L₁.Relations n) : @RelMap (L₁.sum L₂) S _ n (Sum.inl R) = RelMap R := rfl @[simp] theorem relMap_sumInr {n : ℕ} (R : L₂.Relations n) : @RelMap (L₁.sum L₂) S _ n (Sum.inr R) = RelMap R := rfl end SumStructure section Empty /-- Any type can be made uniquely into a structure over the empty language. -/ def emptyStructure : Language.empty.Structure M where instance : Unique (Language.empty.Structure M) := ⟨⟨Language.emptyStructure⟩, fun a => by ext _ f <;> exact Empty.elim f⟩ variable [Language.empty.Structure M] [Language.empty.Structure N] instance (priority := 100) strongHomClassEmpty {F} [FunLike F M N] : StrongHomClass Language.empty F M N := ⟨fun _ _ f => Empty.elim f, fun _ _ r => Empty.elim r⟩ @[simp] theorem empty.nonempty_embedding_iff : Nonempty (M ↪[Language.empty] N) ↔ Cardinal.lift.{w'} #M ≤ Cardinal.lift.{w} #N := _root_.trans ⟨Nonempty.map fun f => f.toEmbedding, Nonempty.map StrongHomClass.toEmbedding⟩ Cardinal.lift_mk_le'.symm @[simp] theorem empty.nonempty_equiv_iff : Nonempty (M ≃[Language.empty] N) ↔ Cardinal.lift.{w'} #M = Cardinal.lift.{w} #N := _root_.trans ⟨Nonempty.map fun f => f.toEquiv, Nonempty.map fun f => { toEquiv := f }⟩ Cardinal.lift_mk_eq'.symm /-- Makes a `Language.empty.Hom` out of any function. This is only needed because there is no instance of `FunLike (M → N) M N`, and thus no instance of `Language.empty.HomClass M N`. -/ @[simps] def _root_.Function.emptyHom (f : M → N) : M →[Language.empty] N where toFun := f end Empty end Language end FirstOrder namespace Equiv open FirstOrder FirstOrder.Language FirstOrder.Language.Structure variable {L : Language} {M : Type*} {N : Type*} [L.Structure M] /-- A structure induced by a bijection. -/ @[simps!] def inducedStructure (e : M ≃ N) : L.Structure N := ⟨fun f x => e (funMap f (e.symm ∘ x)), fun r x => RelMap r (e.symm ∘ x)⟩ /-- A bijection as a first-order isomorphism with the induced structure on the codomain. -/ def inducedStructureEquiv (e : M ≃ N) : @Language.Equiv L M N _ (inducedStructure e) := by letI : L.Structure N := inducedStructure e exact { e with map_fun' := @fun n f x => by simp [← Function.comp_assoc e.symm e x] map_rel' := @fun n r x => by simp [← Function.comp_assoc e.symm e x] } @[simp] theorem toEquiv_inducedStructureEquiv (e : M ≃ N) : @Language.Equiv.toEquiv L M N _ (inducedStructure e) (inducedStructureEquiv e) = e := rfl @[simp] theorem toFun_inducedStructureEquiv (e : M ≃ N) : DFunLike.coe (@inducedStructureEquiv L M N _ e) = e := rfl @[simp] theorem toFun_inducedStructureEquiv_Symm (e : M ≃ N) : (by letI : L.Structure N := inducedStructure e exact DFunLike.coe (@inducedStructureEquiv L M N _ e).symm) = (e.symm : N → M) := rfl end Equiv
.lake/packages/mathlib/Mathlib/ModelTheory/Satisfiability.lean
import Mathlib.ModelTheory.Ultraproducts import Mathlib.ModelTheory.Bundled import Mathlib.ModelTheory.Skolem import Mathlib.Order.Filter.AtTopBot.Basic /-! # First-Order Satisfiability This file deals with the satisfiability of first-order theories, as well as equivalence over them. ## Main Definitions - `FirstOrder.Language.Theory.IsSatisfiable`: `T.IsSatisfiable` indicates that `T` has a nonempty model. - `FirstOrder.Language.Theory.IsFinitelySatisfiable`: `T.IsFinitelySatisfiable` indicates that every finite subset of `T` is satisfiable. - `FirstOrder.Language.Theory.IsComplete`: `T.IsComplete` indicates that `T` is satisfiable and models each sentence or its negation. - `Cardinal.Categorical`: A theory is `κ`-categorical if all models of size `κ` are isomorphic. ## Main Results - The Compactness Theorem, `FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable`, shows that a theory is satisfiable iff it is finitely satisfiable. - `FirstOrder.Language.completeTheory.isComplete`: The complete theory of a structure is complete. - `FirstOrder.Language.Theory.exists_large_model_of_infinite_model` shows that any theory with an infinite model has arbitrarily large models. - `FirstOrder.Language.Theory.exists_elementaryEmbedding_card_eq`: The Upward Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. ## Implementation Details - Satisfiability of an `L.Theory` `T` is defined in the minimal universe containing all the symbols of `L`. By Löwenheim-Skolem, this is equivalent to satisfiability in any universe. -/ universe u v w w' open Cardinal CategoryTheory namespace FirstOrder namespace Language variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ} namespace Theory variable (T) /-- A theory is satisfiable if a structure models it. -/ def IsSatisfiable : Prop := Nonempty (ModelType.{u, v, max u v} T) /-- A theory is finitely satisfiable if all of its finite subtheories are satisfiable. -/ def IsFinitelySatisfiable : Prop := ∀ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T → IsSatisfiable (T0 : L.Theory) variable {T} {T' : L.Theory} theorem Model.isSatisfiable (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] : T.IsSatisfiable := ⟨((⊥ : Substructure _ (ModelType.of T M)).elementarySkolem₁Reduct.toModel T).shrink⟩ theorem IsSatisfiable.mono (h : T'.IsSatisfiable) (hs : T ⊆ T') : T.IsSatisfiable := ⟨(Theory.Model.mono (ModelType.is_model h.some) hs).bundled⟩ theorem isSatisfiable_empty (L : Language.{u, v}) : IsSatisfiable (∅ : L.Theory) := ⟨default⟩ theorem isSatisfiable_of_isSatisfiable_onTheory {L' : Language.{w, w'}} (φ : L →ᴸ L') (h : (φ.onTheory T).IsSatisfiable) : T.IsSatisfiable := Model.isSatisfiable (h.some.reduct φ) theorem isSatisfiable_onTheory_iff {L' : Language.{w, w'}} {φ : L →ᴸ L'} (h : φ.Injective) : (φ.onTheory T).IsSatisfiable ↔ T.IsSatisfiable := by classical refine ⟨isSatisfiable_of_isSatisfiable_onTheory φ, fun h' => ?_⟩ haveI : Inhabited h'.some := Classical.inhabited_of_nonempty' exact Model.isSatisfiable (h'.some.defaultExpansion h) theorem IsSatisfiable.isFinitelySatisfiable (h : T.IsSatisfiable) : T.IsFinitelySatisfiable := fun _ => h.mono /-- The **Compactness Theorem of first-order logic**: A theory is satisfiable if and only if it is finitely satisfiable. -/ theorem isSatisfiable_iff_isFinitelySatisfiable {T : L.Theory} : T.IsSatisfiable ↔ T.IsFinitelySatisfiable := ⟨Theory.IsSatisfiable.isFinitelySatisfiable, fun h => by classical set M : Finset T → Type max u v := fun T0 : Finset T => (h (T0.map (Function.Embedding.subtype fun x => x ∈ T)) T0.map_subtype_subset).some.Carrier let M' := Filter.Product (Ultrafilter.of (Filter.atTop : Filter (Finset T))) M have h' : M' ⊨ T := by refine ⟨fun φ hφ => ?_⟩ rw [Ultraproduct.sentence_realize] refine Filter.Eventually.filter_mono (Ultrafilter.of_le _) (Filter.eventually_atTop.2 ⟨{⟨φ, hφ⟩}, fun s h' => Theory.realize_sentence_of_mem (s.map (Function.Embedding.subtype fun x => x ∈ T)) ?_⟩) simp only [Finset.coe_map, Function.Embedding.coe_subtype, Set.mem_image, Finset.mem_coe, Subtype.exists, exists_and_right, exists_eq_right] exact ⟨hφ, h' (Finset.mem_singleton_self _)⟩ exact ⟨ModelType.of T M'⟩⟩ theorem isSatisfiable_directed_union_iff {ι : Type*} [Nonempty ι] {T : ι → L.Theory} (h : Directed (· ⊆ ·) T) : Theory.IsSatisfiable (⋃ i, T i) ↔ ∀ i, (T i).IsSatisfiable := by refine ⟨fun h' i => h'.mono (Set.subset_iUnion _ _), fun h' => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable] intro T0 hT0 obtain ⟨i, hi⟩ := h.exists_mem_subset_of_finset_subset_biUnion hT0 exact (h' i).mono hi theorem isSatisfiable_union_distinctConstantsTheory_of_card_le (T : L.Theory) (s : Set α) (M : Type w') [Nonempty M] [L.Structure M] [M ⊨ T] (h : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} #M) : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance rw [Cardinal.lift_mk_le'] at h letI : (constantsOn α).Structure M := constantsOn.structure (Function.extend (↑) h.some default) have : M ⊨ (L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s := by refine ((LHom.onTheory_model _ _).2 inferInstance).union ?_ rw [model_distinctConstantsTheory] refine fun a as b bs ab => ?_ rw [← Subtype.coe_mk a as, ← Subtype.coe_mk b bs, ← Subtype.ext_iff] exact h.some.injective ((Subtype.coe_injective.extend_apply h.some default ⟨a, as⟩).symm.trans (ab.trans (Subtype.coe_injective.extend_apply h.some default ⟨b, bs⟩))) exact Model.isSatisfiable M theorem isSatisfiable_union_distinctConstantsTheory_of_infinite (T : L.Theory) (s : Set α) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by classical rw [distinctConstantsTheory_eq_iUnion, Set.union_iUnion, isSatisfiable_directed_union_iff] · exact fun t => isSatisfiable_union_distinctConstantsTheory_of_card_le T _ M ((lift_le_aleph0.2 (finset_card_lt_aleph0 _).le).trans (aleph0_le_lift.2 (aleph0_le_mk M))) · apply Monotone.directed_le refine monotone_const.union (monotone_distinctConstantsTheory.comp ?_) simp only [Finset.coe_map, Function.Embedding.coe_subtype] exact Monotone.comp (g := Set.image ((↑) : s → α)) (f := ((↑) : Finset s → Set s)) Set.monotone_image fun _ _ => Finset.coe_subset.2 /-- Any theory with an infinite model has arbitrarily large models. -/ theorem exists_large_model_of_infinite_model (T : L.Theory) (κ : Cardinal.{w}) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ∃ N : ModelType.{_, _, max u v w} T, Cardinal.lift.{max u v w} κ ≤ #N := by obtain ⟨N⟩ := isSatisfiable_union_distinctConstantsTheory_of_infinite T (Set.univ : Set κ.out) M refine ⟨(N.is_model.mono Set.subset_union_left).bundled.reduct _, ?_⟩ haveI : N ⊨ distinctConstantsTheory _ _ := N.is_model.mono Set.subset_union_right rw [ModelType.reduct_Carrier, coe_of] refine _root_.trans (lift_le.2 (le_of_eq (Cardinal.mk_out κ).symm)) ?_ rw [← mk_univ] refine (card_le_of_model_distinctConstantsTheory L Set.univ N).trans (lift_le.{max u v w}.1 ?_) rw [lift_lift] theorem isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset {ι : Type*} (T : ι → L.Theory) : IsSatisfiable (⋃ i, T i) ↔ ∀ s : Finset ι, IsSatisfiable (⋃ i ∈ s, T i) := by classical refine ⟨fun h s => h.mono (Set.iUnion_mono fun _ => Set.iUnion_subset_iff.2 fun _ => refl _), fun h => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable] intro s hs rw [Set.iUnion_eq_iUnion_finset] at hs obtain ⟨t, ht⟩ := Directed.exists_mem_subset_of_finset_subset_biUnion (by exact Monotone.directed_le fun t1 t2 (h : ∀ ⦃x⦄, x ∈ t1 → x ∈ t2) => Set.iUnion_mono fun _ => Set.iUnion_mono' fun h1 => ⟨h h1, refl _⟩) hs exact (h t).mono ht end Theory variable (L) /-- A version of The Downward Löwenheim–Skolem theorem where the structure `N` elementarily embeds into `M`, but is not by type a substructure of `M`, and thus can be chosen to belong to the universe of the cardinal `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_le (M : Type w') [L.Structure M] [Nonempty M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h3 : lift.{w'} κ ≤ Cardinal.lift.{w} #M) : ∃ N : Bundled L.Structure, Nonempty (N ↪ₑ[L] M) ∧ #N = κ := by obtain ⟨S, _, hS⟩ := exists_elementarySubstructure_card_eq L ∅ κ h1 (by simp) h2 h3 have : Small.{w} S := by rw [← lift_inj.{_, w + 1}, lift_lift, lift_lift] at hS exact small_iff_lift_mk_lt_univ.2 (lt_of_eq_of_lt hS κ.lift_lt_univ') refine ⟨(equivShrink S).bundledInduced L, ⟨S.subtype.comp (Equiv.bundledInducedEquiv L _).symm.toElementaryEmbedding⟩, lift_inj.1 (_root_.trans ?_ hS)⟩ simp only [Equiv.bundledInduced_α, lift_mk_shrink'] section /-- The **Upward Löwenheim–Skolem Theorem**: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_ge (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h2 : Cardinal.lift.{w} #M ≤ Cardinal.lift.{w'} κ) : ∃ N : Bundled L.Structure, Nonempty (M ↪ₑ[L] N) ∧ #N = κ := by obtain ⟨N0, hN0⟩ := (L.elementaryDiagram M).exists_large_model_of_infinite_model κ M rw [← lift_le.{max u v}, lift_lift, lift_lift] at h2 obtain ⟨N, ⟨NN0⟩, hN⟩ := exists_elementaryEmbedding_card_eq_of_le (L[[M]]) N0 κ (aleph0_le_lift.1 ((aleph0_le_lift.2 (aleph0_le_mk M)).trans h2)) (by simp only [card_withConstants, lift_add, lift_lift] rw [add_comm, add_eq_max (aleph0_le_lift.2 (infinite_iff.1 iM)), max_le_iff] rw [← lift_le.{w'}, lift_lift, lift_lift] at h1 exact ⟨h2, h1⟩) (hN0.trans (by rw [← lift_umax, lift_id])) letI := (lhomWithConstants L M).reduct N haveI h : N ⊨ L.elementaryDiagram M := (NN0.theory_model_iff (L.elementaryDiagram M)).2 inferInstance refine ⟨Bundled.of N, ⟨?_⟩, hN⟩ apply ElementaryEmbedding.ofModelsElementaryDiagram L M N end /-- The Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is an elementary embedding in the appropriate direction between then `M` and a structure of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : Bundled L.Structure, (Nonempty (N ↪ₑ[L] M) ∨ Nonempty (M ↪ₑ[L] N)) ∧ #N = κ := by cases le_or_gt (lift.{w'} κ) (Cardinal.lift.{w} #M) with | inl h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_le L M κ h1 h2 h exact ⟨N, Or.inl hN1, hN2⟩ | inr h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_ge L M κ h2 (le_of_lt h) exact ⟨N, Or.inr hN1, hN2⟩ /-- A consequence of the Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is a structure of cardinality `κ` elementarily equivalent to `M`. -/ theorem exists_elementarilyEquivalent_card_eq (M : Type w') [L.Structure M] [Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : CategoryTheory.Bundled L.Structure, (M ≅[L] N) ∧ #N = κ := by obtain ⟨N, NM | MN, hNκ⟩ := exists_elementaryEmbedding_card_eq L M κ h1 h2 · exact ⟨N, NM.some.elementarilyEquivalent.symm, hNκ⟩ · exact ⟨N, MN.some.elementarilyEquivalent, hNκ⟩ variable {L} namespace Theory theorem exists_model_card_eq (h : ∃ M : ModelType.{u, v, max u v} T, Infinite M) (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : ModelType.{u, v, w} T, #N = κ := by cases h with | intro M MI => obtain ⟨N, hN, rfl⟩ := exists_elementarilyEquivalent_card_eq L M κ h1 h2 haveI : Nonempty N := hN.nonempty exact ⟨hN.theory_model.bundled, rfl⟩ variable (T) /-- A theory models a (bounded) formula when any of its nonempty models realizes that formula on all inputs. -/ def ModelsBoundedFormula (φ : L.BoundedFormula α n) : Prop := ∀ (M : ModelType.{u, v, max u v w} T) (v : α → M) (xs : Fin n → M), φ.Realize v xs @[inherit_doc FirstOrder.Language.Theory.ModelsBoundedFormula] infixl:51 " ⊨ᵇ " => ModelsBoundedFormula -- input using \|= or \vDash, but not using \models variable {T} theorem models_formula_iff {φ : L.Formula α} : T ⊨ᵇ φ ↔ ∀ (M : ModelType.{u, v, max u v w} T) (v : α → M), φ.Realize v := forall_congr' fun _ => forall_congr' fun _ => Unique.forall_iff theorem models_sentence_iff {φ : L.Sentence} : T ⊨ᵇ φ ↔ ∀ M : ModelType.{u, v, max u v} T, M ⊨ φ := models_formula_iff.trans (forall_congr' fun _ => Unique.forall_iff) theorem models_sentence_of_mem {φ : L.Sentence} (h : φ ∈ T) : T ⊨ᵇ φ := models_sentence_iff.2 fun _ => realize_sentence_of_mem T h theorem models_iff_not_satisfiable (φ : L.Sentence) : T ⊨ᵇ φ ↔ ¬IsSatisfiable (T ∪ {φ.not}) := by rw [models_sentence_iff, IsSatisfiable] refine ⟨fun h1 h2 => (Sentence.realize_not _).1 (realize_sentence_of_mem (T ∪ {Formula.not φ}) (Set.subset_union_right (Set.mem_singleton _))) (h1 (h2.some.subtheoryModel Set.subset_union_left)), fun h M => ?_⟩ contrapose! h rw [← Sentence.realize_not] at h refine ⟨{ Carrier := M is_model := ⟨fun ψ hψ => hψ.elim (realize_sentence_of_mem _) fun h' => ?_⟩ }⟩ rw [Set.mem_singleton_iff.1 h'] exact h theorem ModelsBoundedFormula.realize_sentence {φ : L.Sentence} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] : M ⊨ φ := by rw [models_iff_not_satisfiable] at h contrapose! h have : M ⊨ T ∪ {Formula.not φ} := by simp only [Set.union_singleton, model_iff, Set.mem_insert_iff, forall_eq_or_imp, Sentence.realize_not] rw [← model_iff] exact ⟨h, inferInstance⟩ exact Model.isSatisfiable M theorem models_formula_iff_onTheory_models_equivSentence {φ : L.Formula α} : T ⊨ᵇ φ ↔ (L.lhomWithConstants α).onTheory T ⊨ᵇ Formula.equivSentence φ := by refine ⟨fun h => models_sentence_iff.2 (fun M => ?_), fun h => models_formula_iff.2 (fun M v => ?_)⟩ · letI := (L.lhomWithConstants α).reduct M have : (L.lhomWithConstants α).IsExpansionOn M := LHom.isExpansionOn_reduct _ _ -- why doesn't that instance just work? rw [Formula.realize_equivSentence] have : M ⊨ T := (LHom.onTheory_model _ _).1 M.is_model -- why isn't M.is_model inferInstance? let M' := Theory.ModelType.of T M exact h M' (fun a => (L.con a : M)) _ · letI : (constantsOn α).Structure M := constantsOn.structure v have : M ⊨ (L.lhomWithConstants α).onTheory T := (LHom.onTheory_model _ _).2 inferInstance exact (Formula.realize_equivSentence _ _).1 (h.realize_sentence M) theorem ModelsBoundedFormula.realize_formula {φ : L.Formula α} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] {v : α → M} : φ.Realize v := by rw [models_formula_iff_onTheory_models_equivSentence] at h letI : (constantsOn α).Structure M := constantsOn.structure v have : M ⊨ (L.lhomWithConstants α).onTheory T := (LHom.onTheory_model _ _).2 inferInstance exact (Formula.realize_equivSentence _ _).1 (h.realize_sentence M) theorem models_toFormula_iff {φ : L.BoundedFormula α n} : T ⊨ᵇ φ.toFormula ↔ T ⊨ᵇ φ := by refine ⟨fun h M v xs => ?_, ?_⟩ · have h' : φ.toFormula.Realize (Sum.elim v xs) := h.realize_formula M simp only [BoundedFormula.realize_toFormula, Sum.elim_comp_inl, Sum.elim_comp_inr] at h' exact h' · simp only [models_formula_iff, BoundedFormula.realize_toFormula] exact fun h M v => h M _ _ theorem ModelsBoundedFormula.realize_boundedFormula {φ : L.BoundedFormula α n} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] {v : α → M} {xs : Fin n → M} : φ.Realize v xs := by have h' : φ.toFormula.Realize (Sum.elim v xs) := (models_toFormula_iff.2 h).realize_formula M simp only [BoundedFormula.realize_toFormula, Sum.elim_comp_inl, Sum.elim_comp_inr] at h' exact h' theorem models_of_models_theory {T' : L.Theory} (h : ∀ φ : L.Sentence, φ ∈ T' → T ⊨ᵇ φ) {φ : L.Formula α} (hφ : T' ⊨ᵇ φ) : T ⊨ᵇ φ := fun M => by have hM : M ⊨ T' := T'.model_iff.2 (fun ψ hψ => (h ψ hψ).realize_sentence M) let M' : ModelType T' := ⟨M⟩ exact hφ M' /-- An alternative statement of the Compactness Theorem. A formula `φ` is modeled by a theory iff there is a finite subset `T0` of the theory such that `φ` is modeled by `T0` -/ theorem models_iff_finset_models {φ : L.Sentence} : T ⊨ᵇ φ ↔ ∃ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T ∧ (T0 : L.Theory) ⊨ᵇ φ := by simp only [models_iff_not_satisfiable] rw [← not_iff_not, not_not, isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable] push_neg letI := Classical.decEq (Sentence L) constructor · intro h T0 hT0 simpa using h (T0 ∪ {Formula.not φ}) (by simp only [Finset.coe_union, Finset.coe_singleton] exact Set.union_subset_union hT0 (Set.Subset.refl _)) · intro h T0 hT0 exact IsSatisfiable.mono (h (T0.erase (Formula.not φ)) (by simpa using hT0)) (by simp) /-- A theory is complete when it is satisfiable and models each sentence or its negation. -/ def IsComplete (T : L.Theory) : Prop := T.IsSatisfiable ∧ ∀ φ : L.Sentence, T ⊨ᵇ φ ∨ T ⊨ᵇ φ.not namespace IsComplete theorem models_not_iff (h : T.IsComplete) (φ : L.Sentence) : T ⊨ᵇ φ.not ↔ ¬T ⊨ᵇ φ := by rcases h.2 φ with hφ | hφn · simp only [hφ, not_true, iff_false] rw [models_sentence_iff, not_forall] refine ⟨h.1.some, ?_⟩ simp only [Sentence.realize_not, Classical.not_not] exact models_sentence_iff.1 hφ _ · simp only [hφn, true_iff] intro hφ rw [models_sentence_iff] at * exact hφn h.1.some (hφ _) theorem realize_sentence_iff (h : T.IsComplete) (φ : L.Sentence) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] : M ⊨ φ ↔ T ⊨ᵇ φ := by rcases h.2 φ with hφ | hφn · exact iff_of_true (hφ.realize_sentence M) hφ · exact iff_of_false ((Sentence.realize_not M).1 (hφn.realize_sentence M)) ((h.models_not_iff φ).1 hφn) end IsComplete /-- A theory is maximal when it is satisfiable and contains each sentence or its negation. Maximal theories are complete. -/ def IsMaximal (T : L.Theory) : Prop := T.IsSatisfiable ∧ ∀ φ : L.Sentence, φ ∈ T ∨ φ.not ∈ T theorem IsMaximal.isComplete (h : T.IsMaximal) : T.IsComplete := h.imp_right (forall_imp fun _ => Or.imp models_sentence_of_mem models_sentence_of_mem) theorem IsMaximal.mem_or_not_mem (h : T.IsMaximal) (φ : L.Sentence) : φ ∈ T ∨ φ.not ∈ T := h.2 φ theorem IsMaximal.mem_of_models (h : T.IsMaximal) {φ : L.Sentence} (hφ : T ⊨ᵇ φ) : φ ∈ T := by refine (h.mem_or_not_mem φ).resolve_right fun con => ?_ rw [models_iff_not_satisfiable, Set.union_singleton, Set.insert_eq_of_mem con] at hφ exact hφ h.1 theorem IsMaximal.mem_iff_models (h : T.IsMaximal) (φ : L.Sentence) : φ ∈ T ↔ T ⊨ᵇ φ := ⟨models_sentence_of_mem, h.mem_of_models⟩ end Theory namespace completeTheory variable (L) (M : Type w) variable [L.Structure M] theorem isSatisfiable [Nonempty M] : (L.completeTheory M).IsSatisfiable := Theory.Model.isSatisfiable M theorem mem_or_not_mem (φ : L.Sentence) : φ ∈ L.completeTheory M ∨ φ.not ∈ L.completeTheory M := by simp_rw [completeTheory, Set.mem_setOf_eq, Sentence.Realize, Formula.realize_not, or_not] theorem isMaximal [Nonempty M] : (L.completeTheory M).IsMaximal := ⟨isSatisfiable L M, mem_or_not_mem L M⟩ theorem isComplete [Nonempty M] : (L.completeTheory M).IsComplete := (completeTheory.isMaximal L M).isComplete end completeTheory end Language end FirstOrder namespace Cardinal open FirstOrder FirstOrder.Language variable {L : Language.{u, v}} (κ : Cardinal.{w}) (T : L.Theory) /-- A theory is `κ`-categorical if all models of size `κ` are isomorphic. -/ def Categorical : Prop := ∀ M N : T.ModelType, #M = κ → #N = κ → Nonempty (M ≃[L] N) /-- The Łoś–Vaught Test : a criterion for categorical theories to be complete. -/ theorem Categorical.isComplete (h : κ.Categorical T) (h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (hS : T.IsSatisfiable) (hT : ∀ M : Theory.ModelType.{u, v, max u v} T, Infinite M) : T.IsComplete := ⟨hS, fun φ => by obtain ⟨_, _⟩ := Theory.exists_model_card_eq ⟨hS.some, hT hS.some⟩ κ h1 h2 rw [Theory.models_sentence_iff, Theory.models_sentence_iff] by_contra! con obtain ⟨⟨MF, hMF⟩, MT, hMT⟩ := con rw [Sentence.realize_not, Classical.not_not] at hMT refine hMF ?_ haveI := hT MT haveI := hT MF obtain ⟨NT, MNT, hNT⟩ := exists_elementarilyEquivalent_card_eq L MT κ h1 h2 obtain ⟨NF, MNF, hNF⟩ := exists_elementarilyEquivalent_card_eq L MF κ h1 h2 obtain ⟨TF⟩ := h (MNT.toModel T) (MNF.toModel T) hNT hNF exact ((MNT.realize_sentence φ).trans ((StrongHomClass.realize_sentence TF φ).trans (MNF.realize_sentence φ).symm)).1 hMT⟩ theorem empty_theory_categorical (T : Language.empty.Theory) : κ.Categorical T := fun M N hM hN => by rw [empty.nonempty_equiv_iff, hM, hN] theorem empty_infinite_Theory_isComplete : Language.empty.infiniteTheory.IsComplete := (empty_theory_categorical.{0} ℵ₀ _).isComplete ℵ₀ _ le_rfl (by simp) ⟨by haveI : Language.empty.Structure ℕ := emptyStructure exact ((model_infiniteTheory_iff Language.empty).2 (inferInstanceAs (Infinite ℕ))).bundled⟩ fun M => (model_infiniteTheory_iff Language.empty).1 M.is_model end Cardinal
.lake/packages/mathlib/Mathlib/ModelTheory/Bundled.lean
import Mathlib.ModelTheory.ElementarySubstructures import Mathlib.CategoryTheory.ConcreteCategory.Bundled /-! # Bundled First-Order Structures This file bundles types together with their first-order structure. ## Main Definitions - `FirstOrder.Language.Theory.ModelType` is the type of nonempty models of a particular theory. - `FirstOrder.Language.equivSetoid` is the isomorphism equivalence relation on bundled structures. ## TODO - Define category structures on bundled structures and models. -/ universe u v w w' x variable {L : FirstOrder.Language.{u, v}} protected instance CategoryTheory.Bundled.structure {L : FirstOrder.Language.{u, v}} (M : CategoryTheory.Bundled.{w} L.Structure) : L.Structure M := M.str open FirstOrder Cardinal namespace Equiv variable (L) {M : Type w} variable [L.Structure M] {N : Type w'} (g : M ≃ N) /-- A type bundled with the structure induced by an equivalence. -/ @[simps] def bundledInduced : CategoryTheory.Bundled.{w'} L.Structure := ⟨N, g.inducedStructure⟩ /-- An equivalence of types as a first-order equivalence to the bundled structure on the codomain. -/ @[simp] def bundledInducedEquiv : M ≃[L] g.bundledInduced L := g.inducedStructureEquiv end Equiv namespace FirstOrder namespace Language /-- The equivalence relation on bundled `L.Structure`s indicating that they are isomorphic. -/ instance equivSetoid : Setoid (CategoryTheory.Bundled L.Structure) where r M N := Nonempty (M ≃[L] N) iseqv := ⟨fun M => ⟨Equiv.refl L M⟩, fun {_ _} => Nonempty.map Equiv.symm, fun {_ _} _ => Nonempty.map2 fun MN NP => NP.comp MN⟩ variable (T : L.Theory) namespace Theory /-- The type of nonempty models of a first-order theory. -/ structure ModelType where /-- The underlying type for the models -/ Carrier : Type w [struc : L.Structure Carrier] [is_model : T.Model Carrier] [nonempty' : Nonempty Carrier] -- Porting note: In Lean4, other instances precedes `FirstOrder.Language.Theory.ModelType.struc`, -- it's issues in `ModelTheory.Satisfiability`. So, we increase these priorities. attribute [instance 2000] ModelType.struc ModelType.is_model ModelType.nonempty' namespace ModelType attribute [coe] ModelType.Carrier instance instCoeSort : CoeSort T.ModelType (Type w) := ⟨ModelType.Carrier⟩ /-- The object in the category of R-algebras associated to a type equipped with the appropriate typeclasses. -/ def of (M : Type w) [L.Structure M] [M ⊨ T] [Nonempty M] : T.ModelType := ⟨M⟩ @[simp] theorem coe_of (M : Type w) [L.Structure M] [M ⊨ T] [Nonempty M] : (of T M : Type w) = M := rfl instance instNonempty (M : T.ModelType) : Nonempty M := inferInstance section Inhabited attribute [local instance] Inhabited.trivialStructure instance instInhabited : Inhabited (ModelType.{u, v, w} (∅ : L.Theory)) := ⟨ModelType.of _ PUnit⟩ end Inhabited variable {T} /-- Maps a bundled model along a bijection. -/ def equivInduced {M : ModelType.{u, v, w} T} {N : Type w'} (e : M ≃ N) : ModelType.{u, v, w'} T where Carrier := N struc := e.inducedStructure is_model := @StrongHomClass.theory_model L M N _ e.inducedStructure T _ _ _ e.inducedStructureEquiv _ nonempty' := e.symm.nonempty instance of_small (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] [h : Small.{w'} M] : Small.{w'} (ModelType.of T M) := h /-- Shrinks a small model to a particular universe. -/ noncomputable def shrink (M : ModelType.{u, v, w} T) [Small.{w'} M] : ModelType.{u, v, w'} T := equivInduced (equivShrink M) /-- Lifts a model to a particular universe. -/ def ulift (M : ModelType.{u, v, w} T) : ModelType.{u, v, max w w'} T := equivInduced (Equiv.ulift.{w', w}.symm : M ≃ _) /-- The reduct of any model of `φ.onTheory T` is a model of `T`. -/ @[simps] def reduct {L' : Language} (φ : L →ᴸ L') (M : (φ.onTheory T).ModelType) : T.ModelType where Carrier := M struc := φ.reduct M nonempty' := M.nonempty' is_model := (@LHom.onTheory_model L L' M (φ.reduct M) _ φ _ T).1 M.is_model /-- When `φ` is injective, `defaultExpansion` expands a model of `T` to a model of `φ.onTheory T` arbitrarily. -/ @[simps] noncomputable def defaultExpansion {L' : Language} {φ : L →ᴸ L'} (h : φ.Injective) [∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => φ.onFunction f)] [∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => φ.onRelation r)] (M : T.ModelType) [Inhabited M] : (φ.onTheory T).ModelType where Carrier := M struc := φ.defaultExpansion M nonempty' := M.nonempty' is_model := (@LHom.onTheory_model L L' M _ (φ.defaultExpansion M) φ (h.isExpansionOn_default M) T).2 M.is_model instance leftStructure {L' : Language} {T : (L.sum L').Theory} (M : T.ModelType) : L.Structure M := (LHom.sumInl : L →ᴸ L.sum L').reduct M instance rightStructure {L' : Language} {T : (L.sum L').Theory} (M : T.ModelType) : L'.Structure M := (LHom.sumInr : L' →ᴸ L.sum L').reduct M /-- A model of a theory is also a model of any subtheory. -/ @[simps] def subtheoryModel (M : T.ModelType) {T' : L.Theory} (h : T' ⊆ T) : T'.ModelType where Carrier := M is_model := ⟨fun _φ hφ => realize_sentence_of_mem T (h hφ)⟩ instance subtheoryModel_models (M : T.ModelType) {T' : L.Theory} (h : T' ⊆ T) : M.subtheoryModel h ⊨ T := M.is_model end ModelType variable {T} /-- Bundles `M ⊨ T` as a `T.ModelType`. -/ def Model.bundled {M : Type w} [LM : L.Structure M] [ne : Nonempty M] (h : M ⊨ T) : T.ModelType := @ModelType.of L T M LM h ne @[simp] theorem coe_of {M : Type w} [L.Structure M] [Nonempty M] (h : M ⊨ T) : (h.bundled : Type w) = M := rfl end Theory /-- A structure that is elementarily equivalent to a model, bundled as a model. -/ def ElementarilyEquivalent.toModel {M : T.ModelType} {N : Type*} [LN : L.Structure N] (h : M ≅[L] N) : T.ModelType where Carrier := N struc := LN nonempty' := h.nonempty is_model := h.theory_model /-- An elementary substructure of a bundled model as a bundled model. -/ def ElementarySubstructure.toModel {M : T.ModelType} (S : L.ElementarySubstructure M) : T.ModelType := S.elementarilyEquivalent.symm.toModel T instance ElementarySubstructure.toModel.instSmall {M : T.ModelType} (S : L.ElementarySubstructure M) [h : Small.{w, x} S] : Small.{w, x} (S.toModel T) := h end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Substructures.lean
import Mathlib.Data.Fintype.Order import Mathlib.Order.Closure import Mathlib.ModelTheory.Semantics import Mathlib.ModelTheory.Encoding /-! # First-Order Substructures This file defines substructures of first-order structures in a similar manner to the various substructures appearing in the algebra library. ## Main Definitions - A `FirstOrder.Language.Substructure` is defined so that `L.Substructure M` is the type of all substructures of the `L`-structure `M`. - `FirstOrder.Language.Substructure.closure` is defined so that if `s : Set M`, `closure L s` is the least substructure of `M` containing `s`. - `FirstOrder.Language.Substructure.comap` is defined so that `s.comap f` is the preimage of the substructure `s` under the homomorphism `f`, as a substructure. - `FirstOrder.Language.Substructure.map` is defined so that `s.map f` is the image of the substructure `s` under the homomorphism `f`, as a substructure. - `FirstOrder.Language.Hom.range` is defined so that `f.range` is the range of the homomorphism `f`, as a substructure. - `FirstOrder.Language.Hom.domRestrict` and `FirstOrder.Language.Hom.codRestrict` restrict the domain and codomain respectively of first-order homomorphisms to substructures. - `FirstOrder.Language.Embedding.domRestrict` and `FirstOrder.Language.Embedding.codRestrict` restrict the domain and codomain respectively of first-order embeddings to substructures. - `FirstOrder.Language.Substructure.inclusion` is the inclusion embedding between substructures. - `FirstOrder.Language.Substructure.PartialEquiv` is defined so that `PartialEquiv L M N` is the type of equivalences between substructures of `M` and `N`. ## Main Results - `L.Substructure M` forms a `CompleteLattice`. -/ universe u v w namespace FirstOrder namespace Language variable {L : Language.{u, v}} {M : Type w} {N P : Type*} variable [L.Structure M] [L.Structure N] [L.Structure P] open FirstOrder Cardinal open Structure section ClosedUnder open Set variable {n : ℕ} (f : L.Functions n) (s : Set M) /-- Indicates that a set in a given structure is a closed under a function symbol. -/ def ClosedUnder : Prop := ∀ x : Fin n → M, (∀ i : Fin n, x i ∈ s) → funMap f x ∈ s variable (L) @[simp] theorem closedUnder_univ : ClosedUnder f (univ : Set M) := fun _ _ => mem_univ _ variable {L f s} {t : Set M} namespace ClosedUnder theorem inter (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ∩ t) := fun x h => mem_inter (hs x fun i => mem_of_mem_inter_left (h i)) (ht x fun i => mem_of_mem_inter_right (h i)) theorem inf (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ⊓ t) := hs.inter ht variable {S : Set (Set M)} theorem sInf (hS : ∀ s, s ∈ S → ClosedUnder f s) : ClosedUnder f (sInf S) := fun x h s hs => hS s hs x fun i => h i s hs end ClosedUnder end ClosedUnder variable (L) (M) /-- A substructure of a structure `M` is a set closed under application of function symbols. -/ structure Substructure where /-- The underlying set of this substructure -/ carrier : Set M fun_mem : ∀ {n}, ∀ f : L.Functions n, ClosedUnder f carrier variable {L} {M} namespace Substructure attribute [coe] Substructure.carrier instance instSetLike : SetLike (L.Substructure M) M := ⟨Substructure.carrier, fun p q h => by cases p; cases q; congr⟩ /-- See Note [custom simps projection] -/ def Simps.coe (S : L.Substructure M) : Set M := S initialize_simps_projections Substructure (carrier → coe, as_prefix coe) @[simp] theorem mem_carrier {s : L.Substructure M} {x : M} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl /-- Two substructures are equal if they have the same elements. -/ @[ext] theorem ext {S T : L.Substructure M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy a substructure replacing `carrier` with a set that is equal to it. -/ protected def copy (S : L.Substructure M) (s : Set M) (hs : s = S) : L.Substructure M where carrier := s fun_mem _ f := hs.symm ▸ S.fun_mem _ f end Substructure variable {S : L.Substructure M} theorem Term.realize_mem {α : Type*} (t : L.Term α) (xs : α → M) (h : ∀ a, xs a ∈ S) : t.realize xs ∈ S := by induction t with | var a => exact h a | func f ts ih => exact Substructure.fun_mem _ _ _ ih namespace Substructure @[simp] theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s := rfl theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S := SetLike.coe_injective hs theorem constants_mem (c : L.Constants) : (c : M) ∈ S := mem_carrier.2 (S.fun_mem c _ finZeroElim) /-- The substructure `M` of the structure `M`. -/ instance instTop : Top (L.Substructure M) := ⟨{ carrier := Set.univ fun_mem := fun {_} _ _ _ => Set.mem_univ _ }⟩ instance instInhabited : Inhabited (L.Substructure M) := ⟨⊤⟩ @[simp] theorem mem_top (x : M) : x ∈ (⊤ : L.Substructure M) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : L.Substructure M) : Set M) = Set.univ := rfl /-- The inf of two substructures is their intersection. -/ instance instInf : Min (L.Substructure M) := ⟨fun S₁ S₂ => { carrier := (S₁ : Set M) ∩ (S₂ : Set M) fun_mem := fun {_} f => (S₁.fun_mem f).inf (S₂.fun_mem f) }⟩ @[simp] theorem coe_inf (p p' : L.Substructure M) : ((p ⊓ p' : L.Substructure M) : Set M) = (p : Set M) ∩ (p' : Set M) := rfl @[simp] theorem mem_inf {p p' : L.Substructure M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance instInfSet : InfSet (L.Substructure M) := ⟨fun s => { carrier := ⋂ t ∈ s, (t : Set M) fun_mem := fun {n} f => ClosedUnder.sInf (by rintro _ ⟨t, rfl⟩ by_cases h : t ∈ s · simpa [h] using t.fun_mem f · simp [h]) }⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (L.Substructure M)) : ((sInf S : L.Substructure M) : Set M) = ⋂ s ∈ S, (s : Set M) := rfl theorem mem_sInf {S : Set (L.Substructure M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ theorem mem_iInf {ι : Sort*} {S : ι → L.Substructure M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → L.Substructure M} : ((⨅ i, S i : L.Substructure M) : Set M) = ⋂ i, (S i : Set M) := by simp only [iInf, coe_sInf, Set.biInter_range] /-- Substructures of a structure form a complete lattice. -/ instance instCompleteLattice : CompleteLattice (L.Substructure M) := { completeLatticeOfInf (L.Substructure M) fun _ => IsGLB.of_image (fun {S T : L.Substructure M} => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe) isGLB_biInf with le := (· ≤ ·) lt := (· < ·) top := ⊤ le_top := fun _ x _ => mem_top x inf := (· ⊓ ·) sInf := InfSet.sInf le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right } variable (L) /-- The `L.Substructure` generated by a set. -/ def closure : LowerAdjoint ((↑) : L.Substructure M → Set M) := ⟨fun s => sInf { S | s ⊆ S }, fun _ _ => ⟨Set.Subset.trans fun _x hx => mem_sInf.2 fun _S hS => hS hx, fun h => sInf_le h⟩⟩ variable {L} {s : Set M} theorem mem_closure {x : M} : x ∈ closure L s ↔ ∀ S : L.Substructure M, s ⊆ S → x ∈ S := mem_sInf /-- The substructure generated by a set includes the set. -/ @[simp] theorem subset_closure : s ⊆ closure L s := (closure L).le_closure s theorem notMem_of_notMem_closure {P : M} (hP : P ∉ closure L s) : P ∉ s := fun h => hP (subset_closure h) @[deprecated (since := "2025-05-23")] alias not_mem_of_not_mem_closure := notMem_of_notMem_closure @[simp] theorem closed (S : L.Substructure M) : (closure L).closed (S : Set M) := congr rfl ((closure L).eq_of_le Set.Subset.rfl fun _x xS => mem_closure.2 fun _T hT => hT xS) open Set /-- A substructure `S` includes `closure L s` if and only if it includes `s`. -/ @[simp] theorem closure_le : closure L s ≤ S ↔ s ⊆ S := (closure L).closure_le_closed_iff_le s S.closed /-- Substructure closure of a set is monotone in its argument: if `s ⊆ t`, then `closure L s ≤ closure L t`. -/ @[gcongr] theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure L s ≤ closure L t := (closure L).monotone h theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure L s) : closure L s = S := (closure L).eq_of_le h₁ h₂ theorem coe_closure_eq_range_term_realize : (closure L s : Set M) = range (@Term.realize L _ _ _ ((↑) : s → M)) := by let S : L.Substructure M := ⟨range (Term.realize (L := L) ((↑) : s → M)), fun {n} f x hx => by simp only [mem_range] at * refine ⟨func f fun i => Classical.choose (hx i), ?_⟩ simp only [Term.realize, fun i => Classical.choose_spec (hx i)]⟩ change _ = (S : Set M) rw [← SetLike.ext'_iff] refine closure_eq_of_le (fun x hx => ⟨var ⟨x, hx⟩, rfl⟩) (le_sInf fun S' hS' => ?_) rintro _ ⟨t, rfl⟩ exact t.realize_mem _ fun i => hS' i.2 instance small_closure [Small.{u} s] : Small.{u} (closure L s) := by rw [← SetLike.coe_sort_coe, Substructure.coe_closure_eq_range_term_realize] exact small_range _ theorem mem_closure_iff_exists_term {x : M} : x ∈ closure L s ↔ ∃ t : L.Term s, t.realize ((↑) : s → M) = x := by rw [← SetLike.mem_coe, coe_closure_eq_range_term_realize, mem_range] theorem lift_card_closure_le_card_term : Cardinal.lift.{max u w} #(closure L s) ≤ #(L.Term s) := by rw [← SetLike.coe_sort_coe, coe_closure_eq_range_term_realize] rw [← Cardinal.lift_id'.{w, max u w} #(L.Term s)] exact Cardinal.mk_range_le_lift theorem lift_card_closure_le : Cardinal.lift.{u, w} #(closure L s) ≤ max ℵ₀ (Cardinal.lift.{u, w} #s + Cardinal.lift.{w, u} #(Σ i, L.Functions i)) := by rw [← lift_umax] refine lift_card_closure_le_card_term.trans (Term.card_le.trans ?_) rw [mk_sum, lift_umax.{w, u}] lemma mem_closed_iff (s : Set M) : s ∈ (closure L).closed ↔ ∀ {n}, ∀ f : L.Functions n, ClosedUnder f s := by refine ⟨fun h n f => ?_, fun h => ?_⟩ · rw [← h] exact Substructure.fun_mem _ _ · have h' : closure L s = ⟨s, h⟩ := closure_eq_of_le (refl _) subset_closure exact congr_arg _ h' variable (L) lemma mem_closed_of_isRelational [L.IsRelational] (s : Set M) : s ∈ (closure L).closed := (mem_closed_iff s).2 isEmptyElim @[simp] lemma closure_eq_of_isRelational [L.IsRelational] (s : Set M) : closure L s = s := LowerAdjoint.closure_eq_self_of_mem_closed _ (mem_closed_of_isRelational L s) @[simp] lemma mem_closure_iff_of_isRelational [L.IsRelational] (s : Set M) (m : M) : m ∈ closure L s ↔ m ∈ s := by rw [← SetLike.mem_coe, closure_eq_of_isRelational] theorem _root_.Set.Countable.substructure_closure [Countable (Σ l, L.Functions l)] (h : s.Countable) : Countable.{w + 1} (closure L s) := by haveI : Countable s := h.to_subtype rw [← mk_le_aleph0_iff, ← lift_le_aleph0] exact lift_card_closure_le_card_term.trans mk_le_aleph0 variable {L} (S) /-- An induction principle for closure membership. If `p` holds for all elements of `s`, and is preserved under function symbols, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure L s) (Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := (@closure_le L M _ ⟨setOf p, fun {_} => Hfun⟩ _).2 Hs h /-- If `s` is a dense set in a structure `M`, `Substructure.closure L s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify that `p` is preserved under function symbols. -/ @[elab_as_elim] theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure L s = ⊤) (Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := by have : ∀ x ∈ closure L s, p x := fun x hx => closure_induction hx Hs fun {n} => Hfun simpa [hs] using this x variable (L) (M) /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure L M _) (↑) where choice s _ := closure L s gc := (closure L).gc le_l_u _ := subset_closure choice_eq _ _ := rfl variable {L} {M} /-- Closure of a substructure `S` equals `S`. -/ @[simp] theorem closure_eq : closure L (S : Set M) = S := (Substructure.gi L M).l_u_eq S @[simp] theorem closure_empty : closure L (∅ : Set M) = ⊥ := (Substructure.gi L M).gc.l_bot @[simp] theorem closure_univ : closure L (univ : Set M) = ⊤ := @coe_top L M _ ▸ closure_eq ⊤ theorem closure_union (s t : Set M) : closure L (s ∪ t) = closure L s ⊔ closure L t := (Substructure.gi L M).gc.l_sup theorem closure_iUnion {ι} (s : ι → Set M) : closure L (⋃ i, s i) = ⨆ i, closure L (s i) := (Substructure.gi L M).gc.l_iSup theorem closure_insert (s : Set M) (m : M) : closure L (insert m s) = closure L {m} ⊔ closure L s := closure_union {m} s instance small_bot : Small.{u} (⊥ : L.Substructure M) := by rw [← closure_empty] haveI : Small.{u} (∅ : Set M) := small_subsingleton _ exact Substructure.small_closure theorem iSup_eq_closure {ι : Sort*} (S : ι → L.Substructure M) : ⨆ i, S i = closure L (⋃ i, (S i : Set M)) := by simp_rw [closure_iUnion, closure_eq] -- This proof uses the fact that `Substructure.closure` is finitary. theorem mem_iSup_of_directed {ι : Type*} [hι : Nonempty ι] {S : ι → L.Substructure M} (hS : Directed (· ≤ ·) S) {x : M} : x ∈ ⨆ i, S i ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ suffices x ∈ closure L (⋃ i, (S i : Set M)) → ∃ i, x ∈ S i by simpa only [closure_iUnion, closure_eq (S _)] using this refine fun hx ↦ closure_induction hx (fun _ ↦ mem_iUnion.1) (fun f v hC ↦ ?_) simp_rw [Set.mem_setOf] at * have ⟨i, hi⟩ := hS.finite_le (fun i ↦ Classical.choose (hC i)) refine ⟨i, (S i).fun_mem f v (fun j ↦ hi j (Classical.choose_spec (hC j)))⟩ -- This proof uses the fact that `Substructure.closure` is finitary. theorem mem_sSup_of_directedOn {S : Set (L.Substructure M)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : M} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, Subtype.exists, exists_prop] variable (L) (M) instance [IsEmpty L.Constants] : IsEmpty (⊥ : L.Substructure M) := by refine (isEmpty_subtype _).2 (fun x => ?_) have h : (∅ : Set M) ∈ (closure L).closed := by rw [mem_closed_iff] intro n f cases n · exact isEmptyElim f · intro x hx simp only [mem_empty_iff_false, forall_const] at hx rw [← closure_empty, ← SetLike.mem_coe, h] exact Set.notMem_empty _ variable {L} {M} /-! ### `comap` and `map` -/ /-- The preimage of a substructure along a homomorphism is a substructure. -/ @[simps] def comap (φ : M →[L] N) (S : L.Substructure N) : L.Substructure M where carrier := φ ⁻¹' S fun_mem {n} f x hx := by rw [mem_preimage, φ.map_fun] exact S.fun_mem f (φ ∘ x) hx @[simp] theorem mem_comap {S : L.Substructure N} {f : M →[L] N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl theorem comap_comap (S : L.Substructure P) (g : N →[L] P) (f : M →[L] N) : (S.comap g).comap f = S.comap (g.comp f) := rfl @[simp] theorem comap_id (S : L.Substructure P) : S.comap (Hom.id _ _) = S := ext (by simp) /-- The image of a substructure along a homomorphism is a substructure. -/ @[simps] def map (φ : M →[L] N) (S : L.Substructure M) : L.Substructure N where carrier := φ '' S fun_mem {n} f x hx := (mem_image _ _ _).1 ⟨funMap f fun i => Classical.choose (hx i), S.fun_mem f _ fun i => (Classical.choose_spec (hx i)).1, by simp only [Hom.map_fun, SetLike.mem_coe] exact congr rfl (funext fun i => (Classical.choose_spec (hx i)).2)⟩ @[simp] theorem mem_map {f : M →[L] N} {S : L.Substructure M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl theorem mem_map_of_mem (f : M →[L] N) {S : L.Substructure M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx theorem apply_coe_mem_map (f : M →[L] N) (S : L.Substructure M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.prop theorem map_map (g : N →[L] P) (f : M →[L] N) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ theorem map_le_iff_le_comap {f : M →[L] N} {S : L.Substructure M} {T : L.Substructure N} : S.map f ≤ T ↔ S ≤ T.comap f := image_subset_iff theorem gc_map_comap (f : M →[L] N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap theorem map_le_of_le_comap {T : L.Substructure N} {f : M →[L] N} : S ≤ T.comap f → S.map f ≤ T := (gc_map_comap f).l_le theorem le_comap_of_map_le {T : L.Substructure N} {f : M →[L] N} : S.map f ≤ T → S ≤ T.comap f := (gc_map_comap f).le_u theorem le_comap_map {f : M →[L] N} : S ≤ (S.map f).comap f := (gc_map_comap f).le_u_l _ theorem map_comap_le {S : L.Substructure N} {f : M →[L] N} : (S.comap f).map f ≤ S := (gc_map_comap f).l_u_le _ theorem monotone_map {f : M →[L] N} : Monotone (map f) := (gc_map_comap f).monotone_l theorem monotone_comap {f : M →[L] N} : Monotone (comap f) := (gc_map_comap f).monotone_u @[simp] theorem map_comap_map {f : M →[L] N} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ @[simp] theorem comap_map_comap {S : L.Substructure N} {f : M →[L] N} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ theorem map_sup (S T : L.Substructure M) (f : M →[L] N) : (S ⊔ T).map f = S.map f ⊔ T.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure M) : (⨆ i, s i).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem comap_inf (S T : L.Substructure N) (f : M →[L] N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f := (gc_map_comap f).u_inf theorem comap_iInf {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure N) : (⨅ i, s i).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem map_bot (f : M →[L] N) : (⊥ : L.Substructure M).map f = ⊥ := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : M →[L] N) : (⊤ : L.Substructure N).comap f = ⊤ := (gc_map_comap f).u_top @[simp] theorem map_id (S : L.Substructure M) : S.map (Hom.id L M) = S := SetLike.coe_injective <| Set.image_id _ theorem map_closure (f : M →[L] N) (s : Set M) : (closure L s).map f = closure L (f '' s) := Eq.symm <| closure_eq_of_le (Set.image_mono subset_closure) <| map_le_iff_le_comap.2 <| closure_le.2 fun x hx => subset_closure ⟨x, hx, rfl⟩ @[simp] theorem closure_image (f : M →[L] N) : closure L (f '' s) = map f (closure L s) := (map_closure f s).symm section GaloisCoinsertion variable {ι : Type*} {f : M →[L] N} /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff] variable (hf : Function.Injective f) include hf theorem comap_map_eq_of_injective (S : L.Substructure M) : (S.map f).comap f = S := (gciMapComap hf).u_l_eq _ theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective theorem comap_inf_map_of_injective (S T : L.Substructure M) : (S.map f ⊓ T.map f).comap f = S ⊓ T := (gciMapComap hf).u_inf_l _ _ theorem comap_iInf_map_of_injective (S : ι → L.Substructure M) : (⨅ i, (S i).map f).comap f = ⨅ i, S i := (gciMapComap hf).u_iInf_l _ theorem comap_sup_map_of_injective (S T : L.Substructure M) : (S.map f ⊔ T.map f).comap f = S ⊔ T := (gciMapComap hf).u_sup_l _ _ theorem comap_iSup_map_of_injective (S : ι → L.Substructure M) : (⨆ i, (S i).map f).comap f = ⨆ i, S i := (gciMapComap hf).u_iSup_l _ theorem map_le_map_iff_of_injective {S T : L.Substructure M} : S.map f ≤ T.map f ↔ S ≤ T := (gciMapComap hf).l_le_l_iff theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l end GaloisCoinsertion section GaloisInsertion variable {ι : Type*} {f : M →[L] N} (hf : Function.Surjective f) include hf /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ def giMapComap : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x h => let ⟨y, hy⟩ := hf x mem_map.2 ⟨y, by simp [hy, h]⟩ theorem map_comap_eq_of_surjective (S : L.Substructure N) : (S.comap f).map f = S := (giMapComap hf).l_u_eq _ theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective theorem map_inf_comap_of_surjective (S T : L.Substructure N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T := (giMapComap hf).l_inf_u _ _ theorem map_iInf_comap_of_surjective (S : ι → L.Substructure N) : (⨅ i, (S i).comap f).map f = ⨅ i, S i := (giMapComap hf).l_iInf_u _ theorem map_sup_comap_of_surjective (S T : L.Substructure N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T := (giMapComap hf).l_sup_u _ _ theorem map_iSup_comap_of_surjective (S : ι → L.Substructure N) : (⨆ i, (S i).comap f).map f = ⨆ i, S i := (giMapComap hf).l_iSup_u _ theorem comap_le_comap_iff_of_surjective {S T : L.Substructure N} : S.comap f ≤ T.comap f ↔ S ≤ T := (giMapComap hf).u_le_u_iff theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u end GaloisInsertion instance inducedStructure {S : L.Substructure M} : L.Structure S where funMap {_} f x := ⟨funMap f fun i => x i, S.fun_mem f (fun i => x i) fun i => (x i).2⟩ RelMap {_} r x := RelMap r fun i => (x i : M) /-- The natural embedding of an `L.Substructure` of `M` into `M`. -/ def subtype (S : L.Substructure M) : S ↪[L] M where toFun := (↑) inj' := Subtype.coe_injective @[simp] theorem subtype_apply {S : L.Substructure M} {x : S} : subtype S x = x := rfl theorem subtype_injective (S : L.Substructure M) : Function.Injective (subtype S) := Subtype.coe_injective @[simp] theorem coe_subtype : ⇑S.subtype = ((↑) : S → M) := rfl /-- The equivalence between the maximal substructure of a structure and the structure itself. -/ def topEquiv : (⊤ : L.Substructure M) ≃[L] M where toFun := subtype ⊤ invFun m := ⟨m, mem_top m⟩ left_inv m := by simp @[simp] theorem coe_topEquiv : ⇑(topEquiv : (⊤ : L.Substructure M) ≃[L] M) = ((↑) : (⊤ : L.Substructure M) → M) := rfl @[simp] theorem realize_boundedFormula_top {α : Type*} {n : ℕ} {φ : L.BoundedFormula α n} {v : α → (⊤ : L.Substructure M)} {xs : Fin n → (⊤ : L.Substructure M)} : φ.Realize v xs ↔ φ.Realize (((↑) : _ → M) ∘ v) ((↑) ∘ xs) := by rw [← StrongHomClass.realize_boundedFormula Substructure.topEquiv φ] simp @[simp] theorem realize_formula_top {α : Type*} {φ : L.Formula α} {v : α → (⊤ : L.Substructure M)} : φ.Realize v ↔ φ.Realize (((↑) : (⊤ : L.Substructure M) → M) ∘ v) := by rw [← StrongHomClass.realize_formula Substructure.topEquiv φ] simp /-- A dependent version of `Substructure.closure_induction`. -/ @[elab_as_elim] theorem closure_induction' (s : Set M) {p : ∀ x, x ∈ closure L s → Prop} (Hs : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f { x | ∃ hx, p x hx }) {x} (hx : x ∈ closure L s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure L s) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨subset_closure hx, Hs x hx⟩) @Hfun end Substructure open Substructure namespace LHom variable {L' : Language} [L'.Structure M] /-- Reduces the language of a substructure along a language hom. -/ def substructureReduct (φ : L →ᴸ L') [φ.IsExpansionOn M] : L'.Substructure M ↪o L.Substructure M where toFun S := { carrier := S fun_mem := fun {n} f x hx => by have h := S.fun_mem (φ.onFunction f) x hx simp only [LHom.map_onFunction, Substructure.mem_carrier] at h exact h } inj' S T h := by simp only [SetLike.coe_set_eq, Substructure.mk.injEq] at h exact h map_rel_iff' {_ _} := Iff.rfl variable (φ : L →ᴸ L') [φ.IsExpansionOn M] @[simp] theorem mem_substructureReduct {x : M} {S : L'.Substructure M} : x ∈ φ.substructureReduct S ↔ x ∈ S := Iff.rfl @[simp] theorem coe_substructureReduct {S : L'.Substructure M} : (φ.substructureReduct S : Set M) = ↑S := rfl end LHom namespace Substructure /-- Turns any substructure containing a constant set `A` into a `L[[A]]`-substructure. -/ def withConstants (S : L.Substructure M) {A : Set M} (h : A ⊆ S) : L[[A]].Substructure M where carrier := S fun_mem {n} f := by obtain f | f := f · exact S.fun_mem f · cases n · exact fun _ _ => h f.2 · exact isEmptyElim f variable {A : Set M} {s : Set M} (h : A ⊆ S) @[simp] theorem mem_withConstants {x : M} : x ∈ S.withConstants h ↔ x ∈ S := Iff.rfl @[simp] theorem coe_withConstants : (S.withConstants h : Set M) = ↑S := rfl @[simp] theorem reduct_withConstants : (L.lhomWithConstants A).substructureReduct (S.withConstants h) = S := by ext simp theorem subset_closure_withConstants : A ⊆ closure (L[[A]]) s := by intro a ha simp only [SetLike.mem_coe] let a' : L[[A]].Constants := Sum.inr ⟨a, ha⟩ exact constants_mem a' theorem closure_withConstants_eq : closure (L[[A]]) s = (closure L (A ∪ s)).withConstants ((A.subset_union_left).trans subset_closure) := by refine closure_eq_of_le ((A.subset_union_right).trans subset_closure) ?_ rw [← (L.lhomWithConstants A).substructureReduct.le_iff_le] simp only [subset_closure, reduct_withConstants, closure_le, LHom.coe_substructureReduct, Set.union_subset_iff, and_true] exact subset_closure_withConstants end Substructure namespace Hom /-- The restriction of a first-order hom to a substructure `s ⊆ M` gives a hom `s → N`. -/ @[simps!] def domRestrict (f : M →[L] N) (p : L.Substructure M) : p →[L] N := f.comp p.subtype.toHom /-- A first-order hom `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to a hom `M → p`. -/ @[simps] def codRestrict (p : L.Substructure N) (f : M →[L] N) (h : ∀ c, f c ∈ p) : M →[L] p where toFun c := ⟨f c, h c⟩ map_fun' {n} f x := by aesop map_rel' {_} R x h := f.map_rel R x h @[simp] theorem comp_codRestrict (f : M →[L] N) (g : N →[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) : ((codRestrict p g h).comp f : M →[L] p) = codRestrict p (g.comp f) fun _ => h _ := ext fun _ => rfl @[simp] theorem subtype_comp_codRestrict (f : M →[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) : p.subtype.toHom.comp (codRestrict p f h) = f := ext fun _ => rfl /-- The range of a first-order hom `f : M → N` is a submodule of `N`. See Note [range copy pattern]. -/ def range (f : M →[L] N) : L.Substructure N := (map f ⊤).copy (Set.range f) Set.image_univ.symm theorem range_coe (f : M →[L] N) : (range f : Set N) = Set.range f := rfl @[simp] theorem mem_range {f : M →[L] N} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl theorem range_eq_map (f : M →[L] N) : f.range = map f ⊤ := by ext simp theorem mem_range_self (f : M →[L] N) (x : M) : f x ∈ f.range := ⟨x, rfl⟩ @[simp] theorem range_id : range (id L M) = ⊤ := SetLike.coe_injective Set.range_id theorem range_comp (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) theorem range_eq_top {f : M →[L] N} : range f = ⊤ ↔ Function.Surjective f := by rw [SetLike.ext'_iff, range_coe, coe_top, Set.range_eq_univ] theorem range_le_iff_comap {f : M →[L] N} {p : L.Substructure N} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] theorem map_le_range {f : M →[L] N} {p : L.Substructure M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) /-- The substructure of elements `x : M` such that `f x = g x` -/ def eqLocus (f g : M →[L] N) : Substructure L M where carrier := { x : M | f x = g x } fun_mem {n} fn x hx := by have h : f ∘ x = g ∘ x := by ext repeat' rw [Function.comp_apply] apply hx simp [h] @[simp] theorem mem_eqLocus {f g : M →[L] N} {x : M} : x ∈ f.eqLocus g ↔ f x = g x := Iff.rfl /-- If two `L.Hom`s are equal on a set, then they are equal on its substructure closure. -/ theorem eqOn_closure {f g : M →[L] N} {s : Set M} (h : Set.EqOn f g s) : Set.EqOn f g (closure L s) := show closure L s ≤ f.eqLocus g from closure_le.2 h theorem eq_of_eqOn_top {f g : M →[L] N} (h : Set.EqOn f g (⊤ : Substructure L M)) : f = g := ext fun _ => h trivial variable {s : Set M} theorem eq_of_eqOn_dense (hs : closure L s = ⊤) {f g : M →[L] N} (h : s.EqOn f g) : f = g := eq_of_eqOn_top <| hs ▸ eqOn_closure h end Hom namespace Embedding /-- The restriction of a first-order embedding to a substructure `s ⊆ M` gives an embedding `s → N`. -/ def domRestrict (f : M ↪[L] N) (p : L.Substructure M) : p ↪[L] N := f.comp p.subtype @[simp] theorem domRestrict_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) : f.domRestrict p x = f x := rfl /-- A first-order embedding `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to an embedding `M → p`. -/ def codRestrict (p : L.Substructure N) (f : M ↪[L] N) (h : ∀ c, f c ∈ p) : M ↪[L] p where toFun := f.toHom.codRestrict p h inj' _ _ ab := f.injective (Subtype.mk_eq_mk.1 ab) map_fun' {_} F x := (f.toHom.codRestrict p h).map_fun' F x map_rel' {n} r x := by rw [← p.subtype.map_rel] change RelMap r (Hom.comp p.subtype.toHom (f.toHom.codRestrict p h) ∘ x) ↔ _ rw [Hom.subtype_comp_codRestrict, ← f.map_rel] rfl @[simp] theorem codRestrict_apply (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) : (codRestrict p f h x : N) = f x := rfl @[simp] theorem codRestrict_apply' (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) : codRestrict p f h x = ⟨f x, h x⟩ := rfl @[simp] theorem comp_codRestrict (f : M ↪[L] N) (g : N ↪[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) : ((codRestrict p g h).comp f : M ↪[L] p) = codRestrict p (g.comp f) fun _ => h _ := ext fun _ => rfl @[simp] theorem subtype_comp_codRestrict (f : M ↪[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) : p.subtype.comp (codRestrict p f h) = f := ext fun _ => rfl /-- The equivalence between a substructure `s` and its image `s.map f.toHom`, where `f` is an embedding. -/ noncomputable def substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) : s ≃[L] s.map f.toHom where toFun := codRestrict (s.map f.toHom) (f.domRestrict s) fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩ invFun n := ⟨Classical.choose n.2, (Classical.choose_spec n.2).1⟩ left_inv := fun ⟨m, hm⟩ => Subtype.mk_eq_mk.2 (f.injective (Classical.choose_spec (codRestrict (s.map f.toHom) (f.domRestrict s) (fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩) ⟨m, hm⟩).2).2) right_inv := fun ⟨_, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn).2 map_fun' {n} f x := by simp map_rel' {n} R x := by simp @[simp] theorem substructureEquivMap_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) : (f.substructureEquivMap p x : N) = f x := rfl @[simp] theorem subtype_substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) : (subtype _).comp (f.substructureEquivMap s).toEmbedding = f.comp (subtype _) := by ext; rfl /-- The equivalence between the domain and the range of an embedding `f`. -/ @[simps toEquiv_apply] noncomputable def equivRange (f : M ↪[L] N) : M ≃[L] f.toHom.range where toFun := codRestrict f.toHom.range f f.toHom.mem_range_self invFun n := Classical.choose n.2 left_inv m := f.injective (Classical.choose_spec (codRestrict f.toHom.range f f.toHom.mem_range_self m).2) right_inv := fun ⟨_, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn) map_fun' {n} f x := by simp map_rel' {n} R x := by simp @[simp] theorem equivRange_apply (f : M ↪[L] N) (x : M) : (f.equivRange x : N) = f x := rfl @[simp] theorem subtype_equivRange (f : M ↪[L] N) : (subtype _).comp f.equivRange.toEmbedding = f := by ext; rfl end Embedding namespace Equiv theorem toHom_range (f : M ≃[L] N) : f.toHom.range = ⊤ := by ext n simp only [Hom.mem_range, coe_toHom, Substructure.mem_top, iff_true] exact ⟨f.symm n, apply_symm_apply _ _⟩ end Equiv namespace Substructure /-- The embedding associated to an inclusion of substructures. -/ def inclusion {S T : L.Substructure M} (h : S ≤ T) : S ↪[L] T := S.subtype.codRestrict _ fun x => h x.2 @[simp] theorem inclusion_self (S : L.Substructure M) : inclusion (le_refl S) = Embedding.refl L S := rfl @[simp] theorem coe_inclusion {S T : L.Substructure M} (h : S ≤ T) : (inclusion h : S → T) = Set.inclusion h := rfl theorem range_subtype (S : L.Substructure M) : S.subtype.toHom.range = S := by ext x simp only [Hom.mem_range, Embedding.coe_toHom, coe_subtype] refine ⟨?_, fun h => ⟨⟨x, h⟩, rfl⟩⟩ rintro ⟨⟨y, hy⟩, rfl⟩ exact hy @[simp] lemma subtype_comp_inclusion {S T : L.Substructure M} (h : S ≤ T) : T.subtype.comp (inclusion h) = S.subtype := rfl end Substructure end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Encoding.lean
import Mathlib.Computability.Encoding import Mathlib.Logic.Small.List import Mathlib.ModelTheory.Syntax import Mathlib.SetTheory.Cardinal.Arithmetic /-! # Encodings and Cardinality of First-Order Syntax ## Main Definitions - `FirstOrder.Language.Term.encoding` encodes terms as lists. - `FirstOrder.Language.BoundedFormula.encoding` encodes bounded formulas as lists. ## Main Results - `FirstOrder.Language.Term.card_le` shows that the number of terms in `L.Term α` is at most `max ℵ₀ # (α ⊕ Σ i, L.Functions i)`. - `FirstOrder.Language.BoundedFormula.card_le` shows that the number of bounded formulas in `Σ n, L.BoundedFormula α n` is at most `max ℵ₀ (Cardinal.lift.{max u v} #α + Cardinal.lift.{u'} L.card)`. ## TODO - `Primcodable` instances for terms and formulas, based on the `encoding`s - Computability facts about term and formula operations, to set up a computability approach to incompleteness -/ universe u v w u' namespace FirstOrder namespace Language variable {L : Language.{u, v}} variable {α : Type u'} open FirstOrder Cardinal open Computability List Structure Fin namespace Term /-- Encodes a term as a list of variables and function symbols. -/ def listEncode : L.Term α → List (α ⊕ (Σ i, L.Functions i)) | var i => [Sum.inl i] | func f ts => Sum.inr (⟨_, f⟩ : Σ i, L.Functions i)::(List.finRange _).flatMap fun i => (ts i).listEncode /-- Decodes a list of variables and function symbols as a list of terms. -/ def listDecode : List (α ⊕ (Σ i, L.Functions i)) → List (L.Term α) | [] => [] | Sum.inl a::l => (var a)::listDecode l | Sum.inr ⟨n, f⟩::l => if h : n ≤ (listDecode l).length then (func f (fun i => (listDecode l)[i])) :: (listDecode l).drop n else [] theorem listDecode_encode_list (l : List (L.Term α)) : listDecode (l.flatMap listEncode) = l := by suffices h : ∀ (t : L.Term α) (l : List (α ⊕ (Σ i, L.Functions i))), listDecode (t.listEncode ++ l) = t::listDecode l by induction l with | nil => rfl | cons t l lih => rw [flatMap_cons, h t (l.flatMap listEncode), lih] intro t l induction t generalizing l with | var => rw [listEncode, singleton_append, listDecode] | @func n f ts ih => rw [listEncode, cons_append, listDecode] have h : listDecode (((finRange n).flatMap fun i : Fin n => (ts i).listEncode) ++ l) = (finRange n).map ts ++ listDecode l := by induction finRange n with | nil => rfl | cons i l' l'ih => rw [flatMap_cons, List.append_assoc, ih, map_cons, l'ih, cons_append] simp only [h, length_append, length_map, length_finRange, le_add_iff_nonneg_right, _root_.zero_le, ↓reduceDIte, getElem_fin, cons.injEq, func.injEq, heq_eq_eq, true_and] refine ⟨funext (fun i => ?_), ?_⟩ · simp only [length_map, length_finRange, is_lt, getElem_append_left, getElem_map, getElem_finRange, cast_mk, Fin.eta] · simp only [length_map, length_finRange, drop_left'] /-- An encoding of terms as lists. -/ @[simps] protected def encoding : Encoding (L.Term α) where Γ := α ⊕ (Σ i, L.Functions i) encode := listEncode decode l := (listDecode l).head?.join decode_encode t := by have h := listDecode_encode_list [t] rw [flatMap_singleton] at h simp only [Option.join, h, head?_cons, Option.pure_def, Option.bind_eq_bind, Option.bind_some, id_eq] theorem listEncode_injective : Function.Injective (listEncode : L.Term α → List (α ⊕ (Σ i, L.Functions i))) := Term.encoding.encode_injective theorem card_le : #(L.Term α) ≤ max ℵ₀ #(α ⊕ (Σ i, L.Functions i)) := lift_le.1 (_root_.trans Term.encoding.card_le_card_list (lift_le.2 (mk_list_le_max _))) theorem card_sigma : #(Σ n, L.Term (α ⊕ (Fin n))) = max ℵ₀ #(α ⊕ (Σ i, L.Functions i)) := by refine le_antisymm ?_ ?_ · rw [mk_sigma] refine (sum_le_lift_mk_mul_iSup _).trans ?_ rw [mk_nat, lift_aleph0, mul_eq_max_of_aleph0_le_left le_rfl, max_le_iff, ciSup_le_iff' (bddAbove_range _)] · refine ⟨le_max_left _ _, fun i => card_le.trans ?_⟩ refine max_le (le_max_left _ _) ?_ grw [← add_eq_max le_rfl, mk_sum, mk_sum, mk_sum, add_comm (Cardinal.lift #α), lift_add, add_assoc, lift_lift, lift_lift, mk_fin, lift_natCast, nat_lt_aleph0] · rw [← one_le_iff_ne_zero] refine _root_.trans ?_ (le_ciSup (bddAbove_range _) 1) rw [one_le_iff_ne_zero, mk_ne_zero_iff] exact ⟨var (Sum.inr 0)⟩ · rw [max_le_iff, ← infinite_iff] refine ⟨Infinite.of_injective (fun i => ⟨i + 1, var (Sum.inr (last i))⟩) fun i j ij => ?_, ?_⟩ · cases ij rfl · rw [Cardinal.le_def] refine ⟨⟨Sum.elim (fun i => ⟨0, var (Sum.inl i)⟩) fun F => ⟨1, func F.2 fun _ => var (Sum.inr 0)⟩, ?_⟩⟩ rintro (a | a) (b | b) h · simp only [Sum.elim_inl, Sigma.mk.inj_iff, heq_eq_eq, var.injEq, Sum.inl.injEq, true_and] at h rw [h] · simp only [Sum.elim_inl, Sum.elim_inr, Sigma.mk.inj_iff, false_and, reduceCtorEq] at h · simp only [Sum.elim_inr, Sum.elim_inl, Sigma.mk.inj_iff, false_and, reduceCtorEq] at h · simp only [Sum.elim_inr, Sigma.mk.inj_iff, heq_eq_eq, func.injEq, true_and] at h rw [Sigma.ext_iff.2 ⟨h.1, h.2.1⟩] instance [Encodable α] [Encodable (Σ i, L.Functions i)] : Encodable (L.Term α) := Encodable.ofLeftInjection listEncode (fun l => (listDecode l).head?.join) fun t => by simp only rw [← flatMap_singleton listEncode, listDecode_encode_list] simp only [Option.join, head?_cons, Option.pure_def, Option.bind_eq_bind, Option.bind_some, id_eq] instance [h1 : Countable α] [h2 : Countable (Σ l, L.Functions l)] : Countable (L.Term α) := by refine mk_le_aleph0_iff.1 (card_le.trans (max_le_iff.2 ?_)) simp only [le_refl, mk_sum, add_le_aleph0, lift_le_aleph0, true_and] exact ⟨Cardinal.mk_le_aleph0, Cardinal.mk_le_aleph0⟩ instance small [Small.{u} α] : Small.{u} (L.Term α) := small_of_injective listEncode_injective end Term namespace BoundedFormula /-- Encodes a bounded formula as a list of symbols. -/ def listEncode : ∀ {n : ℕ}, L.BoundedFormula α n → List ((Σ k, L.Term (α ⊕ Fin k)) ⊕ ((Σ n, L.Relations n) ⊕ ℕ)) | n, falsum => [Sum.inr (Sum.inr (n + 2))] | _, equal t₁ t₂ => [Sum.inl ⟨_, t₁⟩, Sum.inl ⟨_, t₂⟩] | n, rel R ts => [Sum.inr (Sum.inl ⟨_, R⟩), Sum.inr (Sum.inr n)] ++ (List.finRange _).map fun i => Sum.inl ⟨n, ts i⟩ | _, imp φ₁ φ₂ => (Sum.inr (Sum.inr 0)::φ₁.listEncode) ++ φ₂.listEncode | _, all φ => Sum.inr (Sum.inr 1)::φ.listEncode /-- Applies the `forall` quantifier to an element of `(Σ n, L.BoundedFormula α n)`, or returns `default` if not possible. -/ def sigmaAll : (Σ n, L.BoundedFormula α n) → Σ n, L.BoundedFormula α n | ⟨n + 1, φ⟩ => ⟨n, φ.all⟩ | _ => default @[simp] lemma sigmaAll_apply {n} {φ : L.BoundedFormula α (n + 1)} : sigmaAll ⟨n + 1, φ⟩ = ⟨n, φ.all⟩ := rfl /-- Applies `imp` to two elements of `(Σ n, L.BoundedFormula α n)`, or returns `default` if not possible. -/ def sigmaImp : (Σ n, L.BoundedFormula α n) → (Σ n, L.BoundedFormula α n) → Σ n, L.BoundedFormula α n | ⟨m, φ⟩, ⟨n, ψ⟩ => if h : m = n then ⟨m, φ.imp (Eq.mp (by rw [h]) ψ)⟩ else default /-- Decodes a list of symbols as a list of formulas. -/ @[simp] lemma sigmaImp_apply {n} {φ ψ : L.BoundedFormula α n} : sigmaImp ⟨n, φ⟩ ⟨n, ψ⟩ = ⟨n, φ.imp ψ⟩ := by simp only [sigmaImp, ↓reduceDIte, eq_mp_eq_cast, cast_eq] /-- Decodes a list of symbols as a list of formulas. -/ def listDecode : List ((Σ k, L.Term (α ⊕ Fin k)) ⊕ ((Σ n, L.Relations n) ⊕ ℕ)) → List (Σ n, L.BoundedFormula α n) | Sum.inr (Sum.inr (n + 2))::l => ⟨n, falsum⟩::(listDecode l) | Sum.inl ⟨n₁, t₁⟩::Sum.inl ⟨n₂, t₂⟩::l => (if h : n₁ = n₂ then ⟨n₁, equal t₁ (Eq.mp (by rw [h]) t₂)⟩ else default)::(listDecode l) | Sum.inr (Sum.inl ⟨n, R⟩)::Sum.inr (Sum.inr k)::l => ( if h : ∀ i : Fin n, (l.map Sum.getLeft?)[i]?.join.isSome then if h' : ∀ i, (Option.get _ (h i)).1 = k then ⟨k, BoundedFormula.rel R fun i => Eq.mp (by rw [h' i]) (Option.get _ (h i)).2⟩ else default else default)::(listDecode (l.drop n)) | Sum.inr (Sum.inr 0)::l => if h : 2 ≤ (listDecode l).length then (sigmaImp (listDecode l)[0] (listDecode l)[1])::(drop 2 (listDecode l)) else [] | Sum.inr (Sum.inr 1)::l => if h : 1 ≤ (listDecode l).length then (sigmaAll (listDecode l)[0])::(drop 1 (listDecode l)) else [] | _ => [] termination_by l => l.length @[simp] theorem listDecode_encode_list (l : List (Σ n, L.BoundedFormula α n)) : listDecode (l.flatMap (fun φ => φ.2.listEncode)) = l := by suffices h : ∀ (φ : Σ n, L.BoundedFormula α n) (l' : List ((Σ k, L.Term (α ⊕ Fin k)) ⊕ ((Σ n, L.Relations n) ⊕ ℕ))), (listDecode (listEncode φ.2 ++ l')) = φ::(listDecode l') by induction l with | nil => simp [listDecode] | cons φ l ih => rw [flatMap_cons, h φ _, ih] rintro ⟨n, φ⟩ induction φ with | falsum => intro l; rw [listEncode, singleton_append, listDecode] | equal => intro l rw [listEncode, cons_append, cons_append, listDecode, dif_pos] · simp only [eq_mp_eq_cast, cast_eq, nil_append] · simp only | @rel φ_n φ_l φ_R ts => intro l rw [listEncode, cons_append, cons_append, singleton_append, cons_append, listDecode] have h : ∀ i : Fin φ_l, ((List.map Sum.getLeft? (List.map (fun i : Fin φ_l => Sum.inl (⟨(⟨φ_n, rel φ_R ts⟩ : Σ n, L.BoundedFormula α n).fst, ts i⟩ : Σ n, L.Term (α ⊕ (Fin n)))) (finRange φ_l) ++ l))[↑i]?).join = some ⟨_, ts i⟩ := by intro i simp only [Option.join, map_append, map_map, getElem?_fin, id, Option.bind_eq_some_iff, getElem?_eq_some_iff, length_append, length_map, length_finRange, exists_eq_right] refine ⟨lt_of_lt_of_le i.2 le_self_add, ?_⟩ rw [getElem_append_left, getElem_map] · simp only [getElem_finRange, cast_mk, Fin.eta, Function.comp_apply, Sum.getLeft?_inl] · simp only [length_map, length_finRange, is_lt] rw [dif_pos] swap · exact fun i => Option.isSome_iff_exists.2 ⟨⟨_, ts i⟩, h i⟩ rw [dif_pos] swap · intro i obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i) rw [h2] simp only [Option.join, eq_mp_eq_cast, cons.injEq, Sigma.mk.inj_iff, heq_eq_eq, rel.injEq, true_and] refine ⟨funext fun i => ?_, ?_⟩ · obtain ⟨h1, h2⟩ := Option.eq_some_iff_get_eq.1 (h i) rw [cast_eq_iff_heq] exact (Sigma.ext_iff.1 ((Sigma.eta (Option.get _ h1)).trans h2)).2 rw [List.drop_append, length_map, length_finRange, Nat.sub_self, drop, drop_eq_nil_of_le, nil_append] rw [length_map, length_finRange] | imp _ _ ih1 ih2 => intro l simp only [] at * rw [listEncode, List.append_assoc, cons_append, listDecode] simp only [ih1, ih2, length_cons, le_add_iff_nonneg_left, _root_.zero_le, ↓reduceDIte, getElem_cons_zero, getElem_cons_succ, sigmaImp_apply, drop_succ_cons, drop_zero] | all _ ih => intro l simp only [] at * rw [listEncode, cons_append, listDecode] simp only [ih, length_cons, le_add_iff_nonneg_left, _root_.zero_le, ↓reduceDIte, getElem_cons_zero, sigmaAll_apply, drop_succ_cons, drop_zero] /-- An encoding of bounded formulas as lists. -/ @[simps] protected def encoding : Encoding (Σ n, L.BoundedFormula α n) where Γ := (Σ k, L.Term (α ⊕ Fin k)) ⊕ ((Σ n, L.Relations n) ⊕ ℕ) encode φ := φ.2.listEncode decode l := (listDecode l)[0]? decode_encode φ := by have h := listDecode_encode_list [φ] rw [flatMap_singleton] at h rw [h] rfl theorem listEncode_sigma_injective : Function.Injective fun φ : Σ n, L.BoundedFormula α n => φ.2.listEncode := BoundedFormula.encoding.encode_injective theorem card_le : #(Σ n, L.BoundedFormula α n) ≤ max ℵ₀ (Cardinal.lift.{max u v} #α + Cardinal.lift.{u'} L.card) := by refine lift_le.1 (BoundedFormula.encoding.card_le_card_list.trans ?_) rw [encoding_Γ, mk_list_eq_max_mk_aleph0, lift_max, lift_aleph0, lift_max, lift_aleph0, max_le_iff] refine ⟨?_, le_max_left _ _⟩ rw [mk_sum, Term.card_sigma, mk_sum, ← add_eq_max le_rfl, mk_sum, mk_nat] simp only [lift_add, lift_lift, lift_aleph0] rw [← add_assoc, add_comm, ← add_assoc, ← add_assoc, aleph0_add_aleph0, add_assoc, add_eq_max le_rfl, add_assoc, card, Symbols, mk_sum, lift_add, lift_lift, lift_lift] end BoundedFormula end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Ultraproducts.lean
import Mathlib.ModelTheory.Quotients import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.Germ.Basic import Mathlib.Order.Filter.Ultrafilter.Defs /-! # Ultraproducts and Łoś's Theorem ## Main Definitions - `FirstOrder.Language.Ultraproduct.Structure` is the ultraproduct structure on `Filter.Product`. ## Main Results - Łoś's Theorem: `FirstOrder.Language.Ultraproduct.sentence_realize`. An ultraproduct models a sentence `φ` if and only if the set of structures in the product that model `φ` is in the ultrafilter. ## Tags ultraproduct, Los's theorem -/ universe u v variable {α : Type*} (M : α → Type*) (u : Ultrafilter α) open FirstOrder Filter namespace FirstOrder namespace Language open Structure variable {L : Language.{u, v}} [∀ a, L.Structure (M a)] namespace Ultraproduct instance setoidPrestructure : L.Prestructure ((u : Filter α).productSetoid M) := { (u : Filter α).productSetoid M with toStructure := { funMap := fun {_} f x a => funMap f fun i => x i a RelMap := fun {_} r x => ∀ᶠ a : α in u, RelMap r fun i => x i a } fun_equiv := fun {n} f x y xy => by refine mem_of_superset (iInter_mem.2 xy) fun a ha => ?_ simp only [Set.mem_iInter, Set.mem_setOf_eq] at ha simp only [Set.mem_setOf_eq, ha] rel_equiv := fun {n} r x y xy => by rw [← iff_eq_eq] refine ⟨fun hx => ?_, fun hy => ?_⟩ · refine mem_of_superset (inter_mem hx (iInter_mem.2 xy)) ?_ rintro a ⟨ha1, ha2⟩ simp only [Set.mem_iInter, Set.mem_setOf_eq] at * rw [← funext ha2] exact ha1 · refine mem_of_superset (inter_mem hy (iInter_mem.2 xy)) ?_ rintro a ⟨ha1, ha2⟩ simp only [Set.mem_iInter, Set.mem_setOf_eq] at * rw [funext ha2] exact ha1 } variable {M} {u} instance «structure» : L.Structure ((u : Filter α).Product M) := Language.quotientStructure theorem funMap_cast {n : ℕ} (f : L.Functions n) (x : Fin n → ∀ a, M a) : (funMap f fun i => (x i : (u : Filter α).Product M)) = (fun a => funMap f fun i => x i a : (u : Filter α).Product M) := by apply funMap_quotient_mk' theorem term_realize_cast {β : Type*} (x : β → ∀ a, M a) (t : L.Term β) : (t.realize fun i => (x i : (u : Filter α).Product M)) = (fun a => t.realize fun i => x i a : (u : Filter α).Product M) := by convert @Term.realize_quotient_mk' L _ ((u : Filter α).productSetoid M) (Ultraproduct.setoidPrestructure M u) _ t x using 2 ext a induction t with | var => rfl | func _ _ t_ih => simp only [Term.realize, t_ih]; rfl variable [∀ a : α, Nonempty (M a)] theorem boundedFormula_realize_cast {β : Type*} {n : ℕ} (φ : L.BoundedFormula β n) (x : β → ∀ a, M a) (v : Fin n → ∀ a, M a) : (φ.Realize (fun i : β => (x i : (u : Filter α).Product M)) (fun i => (v i : (u : Filter α).Product M))) ↔ ∀ᶠ a : α in u, φ.Realize (fun i : β => x i a) fun i => v i a := by letI := (u : Filter α).productSetoid M induction φ with | falsum => simp only [BoundedFormula.Realize, eventually_const] | equal => have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a := fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl simp only [BoundedFormula.Realize, h2] erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm, term_realize_cast, term_realize_cast] exact Quotient.eq'' | rel => have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a := fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl simp only [BoundedFormula.Realize, h2] erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm] conv_lhs => enter [2, i]; erw [term_realize_cast] apply relMap_quotient_mk' | imp _ _ ih ih' => simp only [BoundedFormula.Realize, ih v, ih' v] rw [Ultrafilter.eventually_imp] | @all k φ ih => simp only [BoundedFormula.Realize] apply Iff.trans (b := ∀ m : ∀ a : α, M a, φ.Realize (fun i : β => (x i : (u : Filter α).Product M)) (Fin.snoc (((↑) : (∀ a, M a) → (u : Filter α).Product M) ∘ v) (m : (u : Filter α).Product M))) · exact Quotient.forall have h' : ∀ (m : ∀ a, M a) (a : α), (fun i : Fin (k + 1) => (Fin.snoc v m : _ → ∀ a, M a) i a) = Fin.snoc (fun i : Fin k => v i a) (m a) := by refine fun m a => funext (Fin.reverseInduction ?_ fun i _ => ?_) · simp only [Fin.snoc_last] · simp only [Fin.snoc_castSucc] simp only [← Fin.comp_snoc] simp only [Function.comp_def, ih, h'] refine ⟨fun h => ?_, fun h m => ?_⟩ · contrapose! h simp_rw [← Ultrafilter.eventually_not, not_forall] at h refine ⟨fun a : α => Classical.epsilon fun m : M a => ¬φ.Realize (fun i => x i a) (Fin.snoc (fun i => v i a) m), ?_⟩ rw [← Ultrafilter.eventually_not] exact Filter.mem_of_superset h fun a ha => Classical.epsilon_spec ha · rw [Filter.eventually_iff] at * exact Filter.mem_of_superset h fun a ha => ha (m a) theorem realize_formula_cast {β : Type*} (φ : L.Formula β) (x : β → ∀ a, M a) : (φ.Realize fun i => (x i : (u : Filter α).Product M)) ↔ ∀ᶠ a : α in u, φ.Realize fun i => x i a := by simp_rw [Formula.Realize, ← boundedFormula_realize_cast φ x, iff_eq_eq] exact congr rfl (Subsingleton.elim _ _) /-- **Łoś's Theorem**: A sentence is true in an ultraproduct if and only if the set of structures it is true in is in the ultrafilter. -/ theorem sentence_realize (φ : L.Sentence) : (u : Filter α).Product M ⊨ φ ↔ ∀ᶠ a : α in u, M a ⊨ φ := by simp_rw [Sentence.Realize] rw [← realize_formula_cast φ, iff_eq_eq] exact congr rfl (Subsingleton.elim _ _) nonrec instance Product.instNonempty : Nonempty ((u : Filter α).Product M) := letI : ∀ a, Inhabited (M a) := fun _ => Classical.inhabited_of_nonempty' inferInstance end Ultraproduct end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Types.lean
import Mathlib.ModelTheory.Satisfiability /-! # Type Spaces This file defines the space of complete types over a first-order theory. (Note that types in model theory are different from types in type theory.) ## Main Definitions - `FirstOrder.Language.Theory.CompleteType`: `T.CompleteType α` consists of complete types over the theory `T` with variables `α`. - `FirstOrder.Language.Theory.typeOf` is the type of a given tuple. - `FirstOrder.Language.Theory.realizedTypes`: `T.realizedTypes M α` is the set of types in `T.CompleteType α` that are realized in `M` - that is, the type of some tuple in `M`. ## Main Results - `FirstOrder.Language.Theory.CompleteType.nonempty_iff`: The space `T.CompleteType α` is nonempty exactly when `T` is satisfiable. - `FirstOrder.Language.Theory.CompleteType.exists_modelType_is_realized_in`: Every type is realized in some model. ## Implementation Notes - Complete types are implemented as maximal consistent theories in an expanded language. More frequently they are described as maximal consistent sets of formulas, but this is equivalent. ## TODO - Connect `T.CompleteType α` to sets of formulas `L.Formula α`. -/ universe u v w w' open Cardinal Set FirstOrder namespace FirstOrder namespace Language namespace Theory variable {L : Language.{u, v}} (T : L.Theory) (α : Type w) /-- A complete type over a given theory in a certain type of variables is a maximally consistent (with the theory) set of formulas in that type. -/ structure CompleteType where /-- The underlying theory -/ toTheory : L[[α]].Theory subset' : (L.lhomWithConstants α).onTheory T ⊆ toTheory isMaximal' : toTheory.IsMaximal variable {T α} namespace CompleteType attribute [coe] CompleteType.toTheory instance Sentence.instSetLike : SetLike (T.CompleteType α) (L[[α]].Sentence) := ⟨fun p => p.toTheory, fun p q h => by cases p cases q congr ⟩ theorem isMaximal (p : T.CompleteType α) : IsMaximal (p : L[[α]].Theory) := p.isMaximal' theorem subset (p : T.CompleteType α) : (L.lhomWithConstants α).onTheory T ⊆ (p : L[[α]].Theory) := p.subset' theorem mem_or_not_mem (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ ∈ p ∨ φ.not ∈ p := p.isMaximal.mem_or_not_mem φ theorem mem_of_models (p : T.CompleteType α) {φ : L[[α]].Sentence} (h : (L.lhomWithConstants α).onTheory T ⊨ᵇ φ) : φ ∈ p := (p.mem_or_not_mem φ).resolve_right fun con => ((models_iff_not_satisfiable _).1 h) (p.isMaximal.1.mono (union_subset p.subset (singleton_subset_iff.2 con))) theorem not_mem_iff (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ.not ∈ p ↔ φ ∉ p := ⟨fun hf ht => by have h : ¬IsSatisfiable ({φ, φ.not} : L[[α]].Theory) := by rintro ⟨@⟨_, _, h, _⟩⟩ simp only [model_iff, mem_insert_iff, mem_singleton_iff, forall_eq_or_imp, forall_eq] at h exact h.2 h.1 refine h (p.isMaximal.1.mono ?_) rw [insert_subset_iff, singleton_subset_iff] exact ⟨ht, hf⟩, (p.mem_or_not_mem φ).resolve_left⟩ @[simp] theorem compl_setOf_mem {φ : L[[α]].Sentence} : { p : T.CompleteType α | φ ∈ p }ᶜ = { p : T.CompleteType α | φ.not ∈ p } := ext fun _ => (not_mem_iff _ _).symm theorem setOf_subset_eq_empty_iff (S : L[[α]].Theory) : { p : T.CompleteType α | S ⊆ ↑p } = ∅ ↔ ¬((L.lhomWithConstants α).onTheory T ∪ S).IsSatisfiable := by rw [iff_not_comm, ← not_nonempty_iff_eq_empty, Classical.not_not, Set.Nonempty] refine ⟨fun h => ⟨⟨L[[α]].completeTheory h.some, (subset_union_left (t := S)).trans completeTheory.subset, completeTheory.isMaximal (L[[α]]) h.some⟩, (((L.lhomWithConstants α).onTheory T).subset_union_right).trans completeTheory.subset⟩, ?_⟩ rintro ⟨p, hp⟩ exact p.isMaximal.1.mono (union_subset p.subset hp) theorem setOf_mem_eq_univ_iff (φ : L[[α]].Sentence) : { p : T.CompleteType α | φ ∈ p } = Set.univ ↔ (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by rw [models_iff_not_satisfiable, ← compl_empty_iff, compl_setOf_mem, ← setOf_subset_eq_empty_iff] simp theorem setOf_subset_eq_univ_iff (S : L[[α]].Theory) : { p : T.CompleteType α | S ⊆ ↑p } = Set.univ ↔ ∀ φ, φ ∈ S → (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by have h : { p : T.CompleteType α | S ⊆ ↑p } = ⋂₀ ((fun φ => { p | φ ∈ p }) '' S) := by ext simp [subset_def] simp_rw [h, sInter_eq_univ, ← setOf_mem_eq_univ_iff] refine ⟨fun h φ φS => h _ ⟨_, φS, rfl⟩, ?_⟩ rintro h _ ⟨φ, h1, rfl⟩ exact h _ h1 theorem nonempty_iff : Nonempty (T.CompleteType α) ↔ T.IsSatisfiable := by rw [← isSatisfiable_onTheory_iff (lhomWithConstants_injective L α)] rw [nonempty_iff_univ_nonempty, nonempty_iff_ne_empty, Ne, not_iff_comm, ← union_empty ((L.lhomWithConstants α).onTheory T), ← setOf_subset_eq_empty_iff] simp instance instNonempty : Nonempty (CompleteType (∅ : L.Theory) α) := nonempty_iff.2 (isSatisfiable_empty L) theorem iInter_setOf_subset {ι : Type*} (S : ι → L[[α]].Theory) : ⋂ i : ι, { p : T.CompleteType α | S i ⊆ p } = { p : T.CompleteType α | ⋃ i : ι, S i ⊆ p } := by ext simp only [mem_iInter, mem_setOf_eq, iUnion_subset_iff] theorem toList_foldr_inf_mem {p : T.CompleteType α} {t : Finset (L[[α]]).Sentence} : t.toList.foldr (· ⊓ ·) ⊤ ∈ p ↔ (t : L[[α]].Theory) ⊆ ↑p := by simp_rw [subset_def, ← SetLike.mem_coe, p.isMaximal.mem_iff_models, models_sentence_iff, Sentence.Realize, Formula.Realize, BoundedFormula.realize_foldr_inf, Finset.mem_toList] exact ⟨fun h φ hφ M => h _ _ hφ, fun h M φ hφ => h _ hφ _⟩ end CompleteType variable {M : Type w'} [L.Structure M] [Nonempty M] [M ⊨ T] (T) /-- The set of all formulas true at a tuple in a structure forms a complete type. -/ def typeOf (v : α → M) : T.CompleteType α := haveI : (constantsOn α).Structure M := constantsOn.structure v { toTheory := L[[α]].completeTheory M subset' := model_iff_subset_completeTheory.1 ((LHom.onTheory_model _ T).2 inferInstance) isMaximal' := completeTheory.isMaximal _ _ } namespace CompleteType variable {T} {v : α → M} @[simp] theorem mem_typeOf {φ : L[[α]].Sentence} : φ ∈ T.typeOf v ↔ (Formula.equivSentence.symm φ).Realize v := letI : (constantsOn α).Structure M := constantsOn.structure v mem_completeTheory.trans (Formula.realize_equivSentence_symm _ _ _).symm theorem formula_mem_typeOf {φ : L.Formula α} : Formula.equivSentence φ ∈ T.typeOf v ↔ φ.Realize v := by simp end CompleteType variable (M) /-- A complete type `p` is realized in a particular structure when there is some tuple `v` whose type is `p`. -/ @[simp] def realizedTypes (α : Type w) : Set (T.CompleteType α) := Set.range (T.typeOf : (α → M) → T.CompleteType α) section theorem exists_modelType_is_realized_in (p : T.CompleteType α) : ∃ M : Theory.ModelType.{u, v, max u v w} T, p ∈ T.realizedTypes M α := by obtain ⟨M⟩ := p.isMaximal.1 refine ⟨(M.subtheoryModel p.subset).reduct (L.lhomWithConstants α), fun a => (L.con a : M), ?_⟩ refine SetLike.ext fun φ => ?_ simp only [CompleteType.mem_typeOf] refine (@Formula.realize_equivSentence_symm_con _ ((M.subtheoryModel p.subset).reduct (L.lhomWithConstants α)) _ _ M.struc _ φ).trans (_root_.trans (_root_.trans ?_ (p.isMaximal.isComplete.realize_sentence_iff φ M)) (p.isMaximal.mem_iff_models φ).symm) rfl end end Theory end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Equivalence.lean
import Mathlib.ModelTheory.Satisfiability /-! # Equivalence of Formulas ## Main Definitions - `FirstOrder.Language.Theory.Imp`: `φ ⟹[T] ψ` indicates that `φ` implies `ψ` in models of `T`. - `FirstOrder.Language.Theory.Iff`: `φ ⇔[T] ψ` indicates that `φ` and `ψ` are equivalent formulas or sentences in models of `T`. ## TODO - Define the quotient of `L.Formula α` modulo `⇔[T]` and its Boolean Algebra structure. -/ universe u v w w' open Cardinal CategoryTheory open FirstOrder namespace FirstOrder namespace Language variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ} variable {M : Type*} [Nonempty M] [L.Structure M] [M ⊨ T] namespace Theory /-- `φ ⟹[T] ψ` indicates that `φ` implies `ψ` in models of `T`. -/ protected def Imp (T : L.Theory) (φ ψ : L.BoundedFormula α n) : Prop := T ⊨ᵇ φ.imp ψ @[inherit_doc FirstOrder.Language.Theory.Imp] scoped[FirstOrder] notation:51 φ:50 " ⟹[" T "] " ψ:51 => Language.Theory.Imp T φ ψ namespace Imp @[refl] protected theorem refl (φ : L.BoundedFormula α n) : φ ⟹[T] φ := fun _ _ _ => id instance : IsRefl (L.BoundedFormula α n) T.Imp := ⟨Imp.refl⟩ @[trans] protected theorem trans {φ ψ θ : L.BoundedFormula α n} (h1 : φ ⟹[T] ψ) (h2 : ψ ⟹[T] θ) : φ ⟹[T] θ := fun M v xs => (h2 M v xs) ∘ (h1 M v xs) instance : IsTrans (L.BoundedFormula α n) T.Imp := ⟨fun _ _ _ => Imp.trans⟩ end Imp section Imp lemma bot_imp (φ : L.BoundedFormula α n) : ⊥ ⟹[T] φ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_bot, false_implies] lemma imp_top (φ : L.BoundedFormula α n) : φ ⟹[T] ⊤ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_top, implies_true] lemma imp_sup_left (φ ψ : L.BoundedFormula α n) : φ ⟹[T] φ ⊔ ψ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_sup] exact Or.inl lemma imp_sup_right (φ ψ : L.BoundedFormula α n) : ψ ⟹[T] φ ⊔ ψ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_sup] exact Or.inr lemma sup_imp {φ ψ θ : L.BoundedFormula α n} (h₁ : φ ⟹[T] θ) (h₂ : ψ ⟹[T] θ) : φ ⊔ ψ ⟹[T] θ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_sup] exact fun h => h.elim (h₁ M v xs) (h₂ M v xs) lemma sup_imp_iff {φ ψ θ : L.BoundedFormula α n} : (φ ⊔ ψ ⟹[T] θ) ↔ (φ ⟹[T] θ) ∧ (ψ ⟹[T] θ) := ⟨fun h => ⟨(imp_sup_left _ _).trans h, (imp_sup_right _ _).trans h⟩, fun ⟨h₁, h₂⟩ => sup_imp h₁ h₂⟩ lemma inf_imp_left (φ ψ : L.BoundedFormula α n) : φ ⊓ ψ ⟹[T] φ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_inf] exact And.left lemma inf_imp_right (φ ψ : L.BoundedFormula α n) : φ ⊓ ψ ⟹[T] ψ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_inf] exact And.right lemma imp_inf {φ ψ θ : L.BoundedFormula α n} (h₁ : φ ⟹[T] ψ) (h₂ : φ ⟹[T] θ) : φ ⟹[T] ψ ⊓ θ := fun M v xs => by simp only [BoundedFormula.realize_imp, BoundedFormula.realize_inf] exact fun h => ⟨h₁ M v xs h, h₂ M v xs h⟩ lemma imp_inf_iff {φ ψ θ : L.BoundedFormula α n} : (φ ⟹[T] ψ ⊓ θ) ↔ (φ ⟹[T] ψ) ∧ (φ ⟹[T] θ) := ⟨fun h => ⟨h.trans (inf_imp_left _ _), h.trans (inf_imp_right _ _)⟩, fun ⟨h₁, h₂⟩ => imp_inf h₁ h₂⟩ end Imp /-- Two (bounded) formulas are semantically equivalent over a theory `T` when they have the same interpretation in every model of `T`. (This is also known as logical equivalence, which also has a proof-theoretic definition.) -/ protected def Iff (T : L.Theory) (φ ψ : L.BoundedFormula α n) : Prop := T ⊨ᵇ φ.iff ψ @[inherit_doc FirstOrder.Language.Theory.Iff] scoped[FirstOrder] notation:51 φ:50 " ⇔[" T "] " ψ:51 => Language.Theory.Iff T φ ψ theorem iff_iff_imp_and_imp {φ ψ : L.BoundedFormula α n} : (φ ⇔[T] ψ) ↔ (φ ⟹[T] ψ) ∧ (ψ ⟹[T] φ) := by simp only [Theory.Imp, ModelsBoundedFormula, BoundedFormula.realize_imp, ← forall_and, Theory.Iff, BoundedFormula.realize_iff, iff_iff_implies_and_implies] theorem imp_antisymm {φ ψ : L.BoundedFormula α n} (h₁ : φ ⟹[T] ψ) (h₂ : ψ ⟹[T] φ) : φ ⇔[T] ψ := iff_iff_imp_and_imp.2 ⟨h₁, h₂⟩ namespace Iff protected theorem mp {φ ψ : L.BoundedFormula α n} (h : φ ⇔[T] ψ) : φ ⟹[T] ψ := (iff_iff_imp_and_imp.1 h).1 protected theorem mpr {φ ψ : L.BoundedFormula α n} (h : φ ⇔[T] ψ) : ψ ⟹[T] φ := (iff_iff_imp_and_imp.1 h).2 @[refl] protected theorem refl (φ : L.BoundedFormula α n) : φ ⇔[T] φ := fun M v xs => by rw [BoundedFormula.realize_iff] instance : IsRefl (L.BoundedFormula α n) T.Iff := ⟨Iff.refl⟩ @[symm] protected theorem symm {φ ψ : L.BoundedFormula α n} (h : φ ⇔[T] ψ) : ψ ⇔[T] φ := fun M v xs => by rw [BoundedFormula.realize_iff, Iff.comm, ← BoundedFormula.realize_iff] exact h M v xs instance : IsSymm (L.BoundedFormula α n) T.Iff := ⟨fun _ _ => Iff.symm⟩ @[trans] protected theorem trans {φ ψ θ : L.BoundedFormula α n} (h1 : φ ⇔[T] ψ) (h2 : ψ ⇔[T] θ) : φ ⇔[T] θ := fun M v xs => by have h1' := h1 M v xs have h2' := h2 M v xs rw [BoundedFormula.realize_iff] at * exact ⟨h2'.1 ∘ h1'.1, h1'.2 ∘ h2'.2⟩ instance : IsTrans (L.BoundedFormula α n) T.Iff := ⟨fun _ _ _ => Iff.trans⟩ theorem realize_bd_iff {φ ψ : L.BoundedFormula α n} (h : φ ⇔[T] ψ) {v : α → M} {xs : Fin n → M} : φ.Realize v xs ↔ ψ.Realize v xs := BoundedFormula.realize_iff.1 (h.realize_boundedFormula M) theorem realize_iff {φ ψ : L.Formula α} {M : Type*} [Nonempty M] [L.Structure M] [M ⊨ T] (h : φ ⇔[T] ψ) {v : α → M} : φ.Realize v ↔ ψ.Realize v := h.realize_bd_iff theorem models_sentence_iff {φ ψ : L.Sentence} {M : Type*} [Nonempty M] [L.Structure M] [M ⊨ T] (h : φ ⇔[T] ψ) : M ⊨ φ ↔ M ⊨ ψ := h.realize_iff protected theorem all {φ ψ : L.BoundedFormula α (n + 1)} (h : φ ⇔[T] ψ) : φ.all ⇔[T] ψ.all := by simp_rw [Theory.Iff, ModelsBoundedFormula, BoundedFormula.realize_iff, BoundedFormula.realize_all] exact fun M v xs => forall_congr' fun a => h.realize_bd_iff protected theorem ex {φ ψ : L.BoundedFormula α (n + 1)} (h : φ ⇔[T] ψ) : φ.ex ⇔[T] ψ.ex := by simp_rw [Theory.Iff, ModelsBoundedFormula, BoundedFormula.realize_iff, BoundedFormula.realize_ex] exact fun M v xs => exists_congr fun a => h.realize_bd_iff protected theorem not {φ ψ : L.BoundedFormula α n} (h : φ ⇔[T] ψ) : φ.not ⇔[T] ψ.not := by simp_rw [Theory.Iff, ModelsBoundedFormula, BoundedFormula.realize_iff, BoundedFormula.realize_not] exact fun M v xs => not_congr h.realize_bd_iff protected theorem imp {φ ψ φ' ψ' : L.BoundedFormula α n} (h : φ ⇔[T] ψ) (h' : φ' ⇔[T] ψ') : (φ.imp φ') ⇔[T] (ψ.imp ψ') := by simp_rw [Theory.Iff, ModelsBoundedFormula, BoundedFormula.realize_iff, BoundedFormula.realize_imp] exact fun M v xs => imp_congr h.realize_bd_iff h'.realize_bd_iff end Iff /-- Semantic equivalence forms an equivalence relation on formulas. -/ def iffSetoid (T : L.Theory) : Setoid (L.BoundedFormula α n) where r := T.Iff iseqv := ⟨fun _ => refl _, fun {_ _} h => h.symm, fun {_ _ _} h1 h2 => h1.trans h2⟩ end Theory namespace BoundedFormula variable (φ ψ : L.BoundedFormula α n) theorem iff_not_not : φ ⇔[T] φ.not.not := fun M v xs => by simp theorem imp_iff_not_sup : (φ.imp ψ) ⇔[T] (φ.not ⊔ ψ) := fun M v xs => by simp [imp_iff_not_or] theorem sup_iff_not_inf_not : (φ ⊔ ψ) ⇔[T] (φ.not ⊓ ψ.not).not := fun M v xs => by simp [imp_iff_not_or] theorem inf_iff_not_sup_not : (φ ⊓ ψ) ⇔[T] (φ.not ⊔ ψ.not).not := fun M v xs => by simp theorem all_iff_not_ex_not (φ : L.BoundedFormula α (n + 1)) : φ.all ⇔[T] φ.not.ex.not := fun M v xs => by simp theorem ex_iff_not_all_not (φ : L.BoundedFormula α (n + 1)) : φ.ex ⇔[T] φ.not.all.not := fun M v xs => by simp theorem iff_all_liftAt : φ ⇔[T] (φ.liftAt 1 n).all := fun M v xs => by rw [realize_iff, realize_all_liftAt_one_self] lemma inf_not_iff_bot : φ ⊓ ∼φ ⇔[T] ⊥ := fun M v xs => by simp only [realize_iff, realize_inf, realize_not, and_not_self, realize_bot] lemma sup_not_iff_top : φ ⊔ ∼φ ⇔[T] ⊤ := fun M v xs => by simp only [realize_iff, realize_sup, realize_not, realize_top, or_not] end BoundedFormula namespace Formula variable (φ ψ : L.Formula α) theorem iff_not_not : φ ⇔[T] φ.not.not := BoundedFormula.iff_not_not φ theorem imp_iff_not_sup : (φ.imp ψ) ⇔[T] (φ.not ⊔ ψ) := BoundedFormula.imp_iff_not_sup φ ψ theorem sup_iff_not_inf_not : (φ ⊔ ψ) ⇔[T] (φ.not ⊓ ψ.not).not := BoundedFormula.sup_iff_not_inf_not φ ψ theorem inf_iff_not_sup_not : (φ ⊓ ψ) ⇔[T] (φ.not ⊔ ψ.not).not := BoundedFormula.inf_iff_not_sup_not φ ψ end Formula end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Definability.lean
import Mathlib.Data.SetLike.Basic import Mathlib.ModelTheory.Semantics /-! # Definable Sets This file defines what it means for a set over a first-order structure to be definable. ## Main Definitions - `Set.Definable` is defined so that `A.Definable L s` indicates that the set `s` of a finite Cartesian power of `M` is definable with parameters in `A`. - `Set.Definable₁` is defined so that `A.Definable₁ L s` indicates that `(s : Set M)` is definable with parameters in `A`. - `Set.Definable₂` is defined so that `A.Definable₂ L s` indicates that `(s : Set (M × M))` is definable with parameters in `A`. - A `FirstOrder.Language.DefinableSet` is defined so that `L.DefinableSet A α` is the Boolean algebra of subsets of `α → M` defined by formulas with parameters in `A`. ## Main Results - `L.DefinableSet A α` forms a `BooleanAlgebra` - `Set.Definable.image_comp` shows that definability is closed under projections in finite dimensions. -/ universe u v w u₁ namespace Set variable {M : Type w} (A : Set M) (L : FirstOrder.Language.{u, v}) [L.Structure M] open FirstOrder FirstOrder.Language FirstOrder.Language.Structure variable {α : Type u₁} {β : Type*} /-- A subset of a finite Cartesian product of a structure is definable over a set `A` when membership in the set is given by a first-order formula with parameters from `A`. -/ def Definable (s : Set (α → M)) : Prop := ∃ φ : L[[A]].Formula α, s = setOf φ.Realize variable {L} {A} {B : Set M} {s : Set (α → M)} theorem Definable.map_expansion {L' : FirstOrder.Language} [L'.Structure M] (h : A.Definable L s) (φ : L →ᴸ L') [φ.IsExpansionOn M] : A.Definable L' s := by obtain ⟨ψ, rfl⟩ := h refine ⟨(φ.addConstants A).onFormula ψ, ?_⟩ ext x simp only [mem_setOf_eq, LHom.realize_onFormula] theorem definable_iff_exists_formula_sum : A.Definable L s ↔ ∃ φ : L.Formula (A ⊕ α), s = {v | φ.Realize (Sum.elim (↑) v)} := by rw [Definable, Equiv.exists_congr_left (BoundedFormula.constantsVarsEquiv)] refine exists_congr (fun φ => iff_iff_eq.2 (congr_arg (s = ·) ?_)) ext simp only [BoundedFormula.constantsVarsEquiv, constantsOn, BoundedFormula.mapTermRelEquiv_symm_apply, mem_setOf_eq, Formula.Realize] refine BoundedFormula.realize_mapTermRel_id ?_ (fun _ _ _ => rfl) intros simp only [Term.constantsVarsEquivLeft_symm_apply, Term.realize_varsToConstants, coe_con, Term.realize_relabel] congr 1 with a rcases a with (_ | _) | _ <;> rfl theorem empty_definable_iff : (∅ : Set M).Definable L s ↔ ∃ φ : L.Formula α, s = setOf φ.Realize := by rw [Definable, Equiv.exists_congr_left (LEquiv.addEmptyConstants L (∅ : Set M)).onFormula] simp theorem definable_iff_empty_definable_with_params : A.Definable L s ↔ (∅ : Set M).Definable (L[[A]]) s := empty_definable_iff.symm theorem Definable.mono (hAs : A.Definable L s) (hAB : A ⊆ B) : B.Definable L s := by rw [definable_iff_empty_definable_with_params] at * exact hAs.map_expansion (L.lhomWithConstantsMap (Set.inclusion hAB)) @[simp] theorem definable_empty : A.Definable L (∅ : Set (α → M)) := ⟨⊥, by ext simp⟩ @[simp] theorem definable_univ : A.Definable L (univ : Set (α → M)) := ⟨⊤, by ext simp⟩ @[simp] theorem Definable.inter {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) : A.Definable L (f ∩ g) := by rcases hf with ⟨φ, rfl⟩ rcases hg with ⟨θ, rfl⟩ refine ⟨φ ⊓ θ, ?_⟩ ext simp @[simp] theorem Definable.union {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) : A.Definable L (f ∪ g) := by rcases hf with ⟨φ, hφ⟩ rcases hg with ⟨θ, hθ⟩ refine ⟨φ ⊔ θ, ?_⟩ ext rw [hφ, hθ, mem_setOf_eq, Formula.realize_sup, mem_union, mem_setOf_eq, mem_setOf_eq] theorem definable_finset_inf {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (s.inf f) := by classical refine Finset.induction definable_univ (fun i s _ h => ?_) s rw [Finset.inf_insert] exact (hf i).inter h theorem definable_finset_sup {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (s.sup f) := by classical refine Finset.induction definable_empty (fun i s _ h => ?_) s rw [Finset.sup_insert] exact (hf i).union h theorem definable_biInter_finset {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋂ i ∈ s, f i) := by rw [← Finset.inf_set_eq_iInter] exact definable_finset_inf hf s @[deprecated (since := "2025-08-28")] alias definable_finset_biInter := definable_biInter_finset theorem definable_biUnion_finset {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋃ i ∈ s, f i) := by rw [← Finset.sup_set_eq_biUnion] exact definable_finset_sup hf s @[deprecated (since := "2025-08-28")] alias definable_finset_biUnion := definable_biUnion_finset @[simp] theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by rcases hf with ⟨φ, hφ⟩ refine ⟨φ.not, ?_⟩ ext v rw [hφ, compl_setOf, mem_setOf, mem_setOf, Formula.realize_not] @[simp] theorem Definable.sdiff {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) : A.Definable L (s \ t) := hs.inter ht.compl @[simp] lemma Definable.himp {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) : A.Definable L (s ⇨ t) := by rw [himp_eq]; exact ht.union hs.compl theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) : A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by obtain ⟨φ, rfl⟩ := h refine ⟨φ.relabel f, ?_⟩ ext simp only [Set.preimage_setOf_eq, mem_setOf_eq, Formula.realize_relabel] theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by refine (congr rfl ?_).mp (h.preimage_comp f.symm) rw [image_eq_preimage_of_inverse] · intro i ext b simp only [Function.comp_apply, Equiv.apply_symm_apply] · intro i ext a simp theorem definable_iff_finitely_definable : A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧ (A0 : Set M).Definable L s := by classical constructor · simp only [definable_iff_exists_formula_sum] rintro ⟨φ, rfl⟩ let A0 := (φ.freeVarFinset.toLeft).image Subtype.val refine ⟨A0, by simp [A0], (φ.restrictFreeVar <| fun x => Sum.casesOn x.1 (fun x hx => Sum.inl ⟨x, by simp [A0, hx]⟩) (fun x _ => Sum.inr x) x.2), ?_⟩ ext simp only [Formula.Realize, mem_setOf_eq, Finset.coe_sort_coe] exact iff_comm.1 <| BoundedFormula.realize_restrictFreeVar _ (by simp) · rintro ⟨A0, hA0, hd⟩ exact Definable.mono hd hA0 /-- This lemma is only intended as a helper for `Definable.image_comp`. -/ theorem Definable.image_comp_sumInl_fin (m : ℕ) {s : Set (Sum α (Fin m) → M)} (h : A.Definable L s) : A.Definable L ((fun g : Sum α (Fin m) → M => g ∘ Sum.inl) '' s) := by obtain ⟨φ, rfl⟩ := h refine ⟨(BoundedFormula.relabel id φ).exs, ?_⟩ ext x simp only [Set.mem_image, mem_setOf_eq, BoundedFormula.realize_exs, BoundedFormula.realize_relabel, Function.comp_id, Fin.castAdd_zero, Fin.cast_refl] constructor · rintro ⟨y, hy, rfl⟩ exact ⟨y ∘ Sum.inr, (congr (congr rfl (Sum.elim_comp_inl_inr y).symm) (funext finZeroElim)).mp hy⟩ · rintro ⟨y, hy⟩ exact ⟨Sum.elim x y, (congr rfl (funext finZeroElim)).mp hy, Sum.elim_comp_inl _ _⟩ /-- Shows that definability is closed under finite projections. -/ theorem Definable.image_comp_embedding {s : Set (β → M)} (h : A.Definable L s) (f : α ↪ β) [Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by classical cases nonempty_fintype β refine (congr rfl (ext fun x => ?_)).mp (((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv (Equiv.sumCongr (Equiv.ofInjective f f.injective) (Fintype.equivFin (↥(range f)ᶜ)).symm)).image_comp_sumInl_fin _) simp only [mem_image, exists_exists_and_eq_and] refine exists_congr fun y => and_congr_right fun _ => Eq.congr_left (funext fun a => ?_) simp /-- Shows that definability is closed under finite projections. -/ theorem Definable.image_comp {s : Set (β → M)} (h : A.Definable L s) (f : α → β) [Finite α] [Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by classical cases nonempty_fintype α cases nonempty_fintype β have h := (((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv (Equiv.sumCongr (_root_.Equiv.refl _) (Fintype.equivFin _).symm)).image_comp_sumInl_fin _).preimage_comp (rangeSplitting f) have h' : A.Definable L { x : α → M | ∀ a, x a = x (rangeSplitting f (rangeFactorization f a)) } := by have h' : ∀ a, A.Definable L { x : α → M | x a = x (rangeSplitting f (rangeFactorization f a)) } := by refine fun a => ⟨(var a).equal (var (rangeSplitting f (rangeFactorization f a))), ext ?_⟩ simp refine (congr rfl (ext ?_)).mp (definable_biInter_finset h' Finset.univ) simp refine (congr rfl (ext fun x => ?_)).mp (h.inter h') simp only [mem_inter_iff, mem_preimage, mem_image, exists_exists_and_eq_and, mem_setOf_eq] constructor · rintro ⟨⟨y, ys, hy⟩, hx⟩ refine ⟨y, ys, ?_⟩ ext a rw [hx a, ← Function.comp_apply (f := x), ← hy] simp · rintro ⟨y, ys, rfl⟩ refine ⟨⟨y, ys, ?_⟩, fun a => ?_⟩ · ext simp [Set.apply_rangeSplitting f] · rw [Function.comp_apply, Function.comp_apply, apply_rangeSplitting f, rangeFactorization_coe] variable (L A) /-- A 1-dimensional version of `Definable`, for `Set M`. -/ def Definable₁ (s : Set M) : Prop := A.Definable L { x : Fin 1 → M | x 0 ∈ s } /-- A 2-dimensional version of `Definable`, for `Set (M × M)`. -/ def Definable₂ (s : Set (M × M)) : Prop := A.Definable L { x : Fin 2 → M | (x 0, x 1) ∈ s } end Set namespace FirstOrder namespace Language open Set variable (L : FirstOrder.Language.{u, v}) {M : Type w} [L.Structure M] (A : Set M) (α : Type u₁) /-- Definable sets are subsets of finite Cartesian products of a structure such that membership is given by a first-order formula. -/ def DefinableSet := { s : Set (α → M) // A.Definable L s } namespace DefinableSet variable {L A α} variable {s t : L.DefinableSet A α} {x : α → M} instance instSetLike : SetLike (L.DefinableSet A α) (α → M) where coe := Subtype.val coe_injective' := Subtype.val_injective instance instTop : Top (L.DefinableSet A α) := ⟨⟨⊤, definable_univ⟩⟩ instance instBot : Bot (L.DefinableSet A α) := ⟨⟨⊥, definable_empty⟩⟩ instance instSup : Max (L.DefinableSet A α) := ⟨fun s t => ⟨s ∪ t, s.2.union t.2⟩⟩ instance instInf : Min (L.DefinableSet A α) := ⟨fun s t => ⟨s ∩ t, s.2.inter t.2⟩⟩ instance instHasCompl : HasCompl (L.DefinableSet A α) := ⟨fun s => ⟨sᶜ, s.2.compl⟩⟩ instance instSDiff : SDiff (L.DefinableSet A α) := ⟨fun s t => ⟨s \ t, s.2.sdiff t.2⟩⟩ -- Why does it complain that `s ⇨ t` is noncomputable? noncomputable instance instHImp : HImp (L.DefinableSet A α) where himp s t := ⟨s ⇨ t, s.2.himp t.2⟩ instance instInhabited : Inhabited (L.DefinableSet A α) := ⟨⊥⟩ theorem le_iff : s ≤ t ↔ (s : Set (α → M)) ≤ (t : Set (α → M)) := Iff.rfl @[simp] theorem mem_top : x ∈ (⊤ : L.DefinableSet A α) := mem_univ x @[simp] theorem notMem_bot {x : α → M} : x ∉ (⊥ : L.DefinableSet A α) := notMem_empty x @[deprecated (since := "2025-05-23")] alias not_mem_bot := notMem_bot @[simp] theorem mem_sup : x ∈ s ⊔ t ↔ x ∈ s ∨ x ∈ t := Iff.rfl @[simp] theorem mem_inf : x ∈ s ⊓ t ↔ x ∈ s ∧ x ∈ t := Iff.rfl @[simp] theorem mem_compl : x ∈ sᶜ ↔ x ∉ s := Iff.rfl @[simp] theorem mem_sdiff : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : L.DefinableSet A α) : Set (α → M)) = univ := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : L.DefinableSet A α) : Set (α → M)) = ∅ := rfl @[simp, norm_cast] theorem coe_sup (s t : L.DefinableSet A α) : ((s ⊔ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) ∪ (t : Set (α → M)) := rfl @[simp, norm_cast] theorem coe_inf (s t : L.DefinableSet A α) : ((s ⊓ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) ∩ (t : Set (α → M)) := rfl @[simp, norm_cast] theorem coe_compl (s : L.DefinableSet A α) : ((sᶜ : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M))ᶜ := rfl @[simp, norm_cast] theorem coe_sdiff (s t : L.DefinableSet A α) : ((s \ t : L.DefinableSet A α) : Set (α → M)) = (s : Set (α → M)) \ (t : Set (α → M)) := rfl @[simp, norm_cast] lemma coe_himp (s t : L.DefinableSet A α) : ↑(s ⇨ t) = (s ⇨ t : Set (α → M)) := rfl noncomputable instance instBooleanAlgebra : BooleanAlgebra (L.DefinableSet A α) := Function.Injective.booleanAlgebra (α := L.DefinableSet A α) _ Subtype.coe_injective coe_sup coe_inf coe_top coe_bot coe_compl coe_sdiff coe_himp end DefinableSet end Language end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Arithmetic/Presburger/Basic.lean
import Mathlib.Algebra.Group.Basic import Mathlib.ModelTheory.Semantics /-! # Presburger arithmetic This file defines the first-order language of Presburger arithmetic as (0,1,+). ## Main Definitions - `FirstOrder.Language.presburger`: the language of Presburger arithmetic. ## TODO - Generalize `presburger.sum` (maybe also `NatCast` and `SMul`) for classes like `FirstOrder.Language.IsOrdered`. - Define the theory of Presburger arithmetic and prove its properties (quantifier elimination, completeness, etc). -/ variable {α : Type*} namespace FirstOrder /-- The type of Presburger arithmetic functions, defined as (0, 1, +). -/ inductive presburgerFunc : ℕ → Type | zero : presburgerFunc 0 | one : presburgerFunc 0 | add : presburgerFunc 2 deriving DecidableEq /-- The language of Presburger arithmetic, defined as (0, 1, +). -/ def Language.presburger : Language := { Functions := presburgerFunc Relations := fun _ => Empty } deriving IsAlgebraic namespace Language.presburger variable {t t₁ t₂ : presburger.Term α} instance : Zero (presburger.Term α) where zero := Constants.term .zero instance : One (presburger.Term α) where one := Constants.term .one instance : Add (presburger.Term α) where add := Functions.apply₂ .add instance : NatCast (presburger.Term α) where natCast := Nat.unaryCast @[simp, norm_cast] theorem natCast_zero : (0 : ℕ) = (0 : presburger.Term α) := rfl @[simp, norm_cast] theorem natCast_succ (n : ℕ) : (n + 1 : ℕ) = (n : presburger.Term α) + 1 := rfl instance : SMul ℕ (presburger.Term α) where smul := nsmulRec @[simp] theorem zero_nsmul : 0 • t = 0 := rfl @[simp] theorem succ_nsmul {n : ℕ} : (n + 1) • t = n • t + t := rfl /-- Summation over a finite set of terms in Presburger arithmetic. It is defined via choice, so the result only makes sense when the structure satisfies commutativity (see `realize_sum`). -/ noncomputable def sum {β : Type*} (s : Finset β) (f : β → presburger.Term α) : presburger.Term α := (s.toList.map f).sum variable {M : Type*} {v : α → M} section variable [Zero M] [One M] [Add M] instance : presburger.Structure M where funMap | .zero, _ => 0 | .one, v => 1 | .add, v => v 0 + v 1 @[simp] theorem funMap_zero {v} : Structure.funMap (L := presburger) (M := M) presburgerFunc.zero v = 0 := rfl @[simp] theorem funMap_one {v} : Structure.funMap (L := presburger) (M := M) presburgerFunc.one v = 1 := rfl @[simp] theorem funMap_add {v} : Structure.funMap (L := presburger) (M := M) presburgerFunc.add v = v 0 + v 1 := rfl @[simp] theorem realize_zero : Term.realize v (0 : presburger.Term α) = 0 := rfl @[simp] theorem realize_one : Term.realize v (1 : presburger.Term α) = 1 := rfl @[simp] theorem realize_add : Term.realize v (t₁ + t₂) = Term.realize v t₁ + Term.realize v t₂ := rfl end @[simp] theorem realize_natCast [AddMonoidWithOne M] {n : ℕ} : Term.realize v (n : presburger.Term α) = n := by induction n with simp [*] @[simp] theorem realize_nsmul [AddMonoidWithOne M] {n : ℕ} : Term.realize v (n • t) = n • Term.realize v t := by induction n with simp [*, add_nsmul] @[simp] theorem realize_sum [AddCommMonoidWithOne M] {β : Type*} {s : Finset β} {f : β → presburger.Term α} : Term.realize v (sum s f) = ∑ i ∈ s, Term.realize v (f i) := by classical simp only [sum] conv => rhs; rw [← s.toList_toFinset, List.sum_toFinset _ s.nodup_toList] generalize s.toList = l induction l with simp [*] end FirstOrder.Language.presburger
.lake/packages/mathlib/Mathlib/ModelTheory/Arithmetic/Presburger/Semilinear/Defs.lean
import Mathlib.GroupTheory.Finiteness import Mathlib.LinearAlgebra.LinearIndependent.Defs /-! # Linear and semilinear sets This file defines linear and semilinear sets. In an `AddCommMonoid`, a linear set is a coset of a finitely generated additive submonoid, and a semilinear set is a finite union of linear sets. We prove that semilinear sets are closed under union, projection, set addition and additive closure. We also prove that any semilinear set can be decomposed into a finite union of proper linear sets, which are linear sets with linearly independent submonoid generators (periods). ## Main Definitions - `IsLinearSet`: a set is linear if it is a coset of a finitely generated additive submonoid. - `IsSemilinearSet`: a set is semilinear if it is a finite union of linear sets. - `IsProperLinearSet`: a linear set is proper if its submonoid generators (periods) are linearly independent. - `IsProperSemilinearSet`: a semilinear set is proper if it is a finite union of proper linear sets. ## Main Results - `IsSemilinearSet` is closed under union, projection, set addition and additive closure. - `IsSemilinearSet.isProperSemilinearSet`: every semilinear set is a finite union of proper linear sets. ## Naming convention `IsSemilinearSet.proj` projects a semilinear set of `ι ⊕ κ → M` to `ι → M` by taking `Sum.inl` on the index. It is a special case of `IsSemilinearSet.image`, and is useful in proving semilinearity of sets in form `{ x | ∃ y, p x y }`. ## References * [Seymour Ginsburg and Edwin H. Spanier, *Bounded ALGOL-Like Languages*][ginsburg1964] * [Samuel Eilenberg and M. P. Schützenberger, *Rational Sets in Commutative Monoids*][eilenberg1969] -/ variable {M N ι κ F : Type*} [AddCommMonoid M] [AddCommMonoid N] [FunLike F M N] [AddMonoidHomClass F M N] {a : M} {s s₁ s₂ : Set M} open Set Pointwise AddSubmonoid /-- A set is linear if it is a coset of a finitely generated additive submonoid. -/ def IsLinearSet (s : Set M) : Prop := ∃ (a : M) (t : Set M), t.Finite ∧ s = a +ᵥ (closure t : Set M) /-- An equivalent expression of `IsLinearSet` in terms of `Finset` instead of `Set.Finite`. -/ theorem isLinearSet_iff : IsLinearSet s ↔ ∃ (a : M) (t : Finset M), s = a +ᵥ (closure (t : Set M) : Set M) := by simp [IsLinearSet, Finset.exists] @[simp] theorem IsLinearSet.singleton (a : M) : IsLinearSet {a} := ⟨a, ∅, by simp⟩ theorem IsLinearSet.closure_finset (s : Finset M) : IsLinearSet (closure (s : Set M) : Set M) := ⟨0, s, by simp⟩ theorem IsLinearSet.closure_of_finite (hs : s.Finite) : IsLinearSet (closure s : Set M) := ⟨0, s, hs, by simp⟩ theorem isLinearSet_iff_exists_fg_eq_vadd : IsLinearSet s ↔ ∃ (a : M) (P : AddSubmonoid M), P.FG ∧ s = a +ᵥ (P : Set M) := isLinearSet_iff.trans (exists_congr fun a => ⟨fun ⟨t, hs⟩ => ⟨_, ⟨t, rfl⟩, hs⟩, fun ⟨P, ⟨t, hP⟩, hs⟩ => ⟨t, by rwa [hP]⟩⟩) theorem IsLinearSet.of_fg {P : AddSubmonoid M} (hP : P.FG) : IsLinearSet (P : Set M) := by rw [isLinearSet_iff_exists_fg_eq_vadd] exact ⟨0, P, hP, by simp⟩ @[simp] protected theorem IsLinearSet.univ [AddMonoid.FG M] : IsLinearSet (univ : Set M) := of_fg AddMonoid.FG.fg_top theorem IsLinearSet.vadd (a : M) (hs : IsLinearSet s) : IsLinearSet (a +ᵥ s) := by rcases hs with ⟨b, t, ht, rfl⟩ exact ⟨a + b, t, ht, by rw [vadd_vadd]⟩ theorem IsLinearSet.add (hs₁ : IsLinearSet s₁) (hs₂ : IsLinearSet s₂) : IsLinearSet (s₁ + s₂) := by rcases hs₁ with ⟨a, t₁, ht₁, rfl⟩ rcases hs₂ with ⟨b, t₂, ht₂, rfl⟩ exact ⟨a + b, t₁ ∪ t₂, ht₁.union ht₂, by simp [vadd_add_vadd, closure_union, coe_sup]⟩ theorem IsLinearSet.image (hs : IsLinearSet s) (f : F) : IsLinearSet (f '' s) := by rcases hs with ⟨a, t, ht, rfl⟩ refine ⟨f a, f '' t, ht.image f, ?_⟩ simp [image_vadd_distrib, ← AddMonoidHom.map_mclosure] /-- A set is semilinear if it is a finite union of linear sets. -/ def IsSemilinearSet (s : Set M) : Prop := ∃ (S : Set (Set M)), S.Finite ∧ (∀ t ∈ S, IsLinearSet t) ∧ s = ⋃₀ S theorem IsLinearSet.isSemilinearSet (h : IsLinearSet s) : IsSemilinearSet s := ⟨{s}, by simpa⟩ @[simp] theorem IsSemilinearSet.empty : IsSemilinearSet (∅ : Set M) := ⟨∅, by simp⟩ @[simp] theorem IsSemilinearSet.singleton (a : M) : IsSemilinearSet {a} := (IsLinearSet.singleton a).isSemilinearSet theorem IsSemilinearSet.closure_finset (s : Finset M) : IsSemilinearSet (closure (s : Set M) : Set M) := (IsLinearSet.closure_finset s).isSemilinearSet theorem IsSemilinearSet.closure_of_finite (hs : s.Finite) : IsSemilinearSet (closure s : Set M) := (IsLinearSet.closure_of_finite hs).isSemilinearSet theorem IsSemilinearSet.of_fg {P : AddSubmonoid M} (hP : P.FG) : IsSemilinearSet (P : Set M) := (IsLinearSet.of_fg hP).isSemilinearSet @[simp] protected theorem IsSemilinearSet.univ [AddMonoid.FG M] : IsSemilinearSet (univ : Set M) := IsLinearSet.univ.isSemilinearSet /-- Semilinear sets are closed under union. -/ theorem IsSemilinearSet.union (hs₁ : IsSemilinearSet s₁) (hs₂ : IsSemilinearSet s₂) : IsSemilinearSet (s₁ ∪ s₂) := by rcases hs₁ with ⟨S₁, hS₁, hS₁', rfl⟩ rcases hs₂ with ⟨S₂, hS₂, hS₂', rfl⟩ rw [← sUnion_union] refine ⟨S₁ ∪ S₂, hS₁.union hS₂, fun s hs => ?_, rfl⟩ rw [mem_union] at hs exact hs.elim (hS₁' s) (hS₂' s) theorem IsSemilinearSet.sUnion {S : Set (Set M)} (hS : S.Finite) (hS' : ∀ s ∈ S, IsSemilinearSet s) : IsSemilinearSet (⋃₀ S) := by induction S, hS using Finite.induction_on with | empty => simp | insert S _ ih => simp_rw [mem_insert_iff, forall_eq_or_imp] at hS' simpa using hS'.1.union (ih hS'.2) theorem IsSemilinearSet.iUnion [Finite ι] {s : ι → Set M} (hs : ∀ i, IsSemilinearSet (s i)) : IsSemilinearSet (⋃ i, s i) := by rw [← sUnion_range] apply sUnion (finite_range s) simpa theorem IsSemilinearSet.biUnion {s : Set ι} {t : ι → Set M} (hs : s.Finite) (ht : ∀ i ∈ s, IsSemilinearSet (t i)) : IsSemilinearSet (⋃ i ∈ s, t i) := by rw [← sUnion_image] apply sUnion (hs.image t) simpa theorem IsSemilinearSet.biUnion_finset {s : Finset ι} {t : ι → Set M} (ht : ∀ i ∈ s, IsSemilinearSet (t i)) : IsSemilinearSet (⋃ i ∈ s, t i) := biUnion s.finite_toSet ht theorem IsSemilinearSet.of_finite (hs : s.Finite) : IsSemilinearSet s := by rw [← biUnion_of_singleton s] apply biUnion hs simp theorem IsSemilinearSet.vadd (a : M) (hs : IsSemilinearSet s) : IsSemilinearSet (a +ᵥ s) := by rcases hs with ⟨S, hS, hS', rfl⟩ rw [vadd_set_sUnion] exact biUnion hS fun s hs => ((hS' s hs).vadd a).isSemilinearSet /-- Semilinear sets are closed under set addition. -/ theorem IsSemilinearSet.add (hs₁ : IsSemilinearSet s₁) (hs₂ : IsSemilinearSet s₂) : IsSemilinearSet (s₁ + s₂) := by rcases hs₁ with ⟨S₁, hS₁, hS₁', rfl⟩ rcases hs₂ with ⟨S₂, hS₂, hS₂', rfl⟩ simp_rw [sUnion_add, add_sUnion] exact biUnion hS₁ fun s₁ hs₁ => biUnion hS₂ fun s₂ hs₂ => ((hS₁' s₁ hs₁).add (hS₂' s₂ hs₂)).isSemilinearSet theorem IsSemilinearSet.image (hs : IsSemilinearSet s) (f : F) : IsSemilinearSet (f '' s) := by rcases hs with ⟨S, hS, hS', rfl⟩ simp_rw [sUnion_eq_biUnion, image_iUnion] exact biUnion hS fun s hs => ((hS' s hs).image f).isSemilinearSet theorem isSemilinearSet_image_iff {F : Type*} [EquivLike F M N] [AddEquivClass F M N] (f : F) : IsSemilinearSet (f '' s) ↔ IsSemilinearSet s := by constructor <;> intro h · convert h.image (f : M ≃+ N).symm simp [image_image] · exact h.image f /-- Semilinear sets are closed under projection (from `ι ⊕ κ → M` to `ι → M` by taking `Sum.inl` on the index). It is a special case of `IsSemilinearSet.image`. -/ theorem IsSemilinearSet.proj {s : Set (ι ⊕ κ → M)} (hs : IsSemilinearSet s) : IsSemilinearSet { x | ∃ y, Sum.elim x y ∈ s } := by convert hs.image (LinearMap.funLeft ℕ M Sum.inl) ext x constructor · intro ⟨y, hy⟩ exact ⟨Sum.elim x y, hy, rfl⟩ · rintro ⟨y, hy, rfl⟩ refine ⟨y ∘ Sum.inr, ?_⟩ simpa [LinearMap.funLeft] /-- A variant of `Semilinear.proj` for backward reasoning. -/ theorem IsSemilinearSet.proj' {p : (ι → M) → (κ → M) → Prop} : IsSemilinearSet { x | p (x ∘ Sum.inl) (x ∘ Sum.inr) } → IsSemilinearSet { x | ∃ y, p x y } := proj protected lemma IsLinearSet.closure (hs : IsLinearSet s) : IsSemilinearSet (closure s : Set M) := by rcases hs with ⟨a, t, ht, rfl⟩ convert (IsSemilinearSet.singleton 0).union (isSemilinearSet ⟨a, {a} ∪ t, by simp [ht], rfl⟩) ext x simp only [SetLike.mem_coe, singleton_union, mem_insert_iff, mem_vadd_set, vadd_eq_add] constructor · intro hx induction hx using closure_induction with | mem x hx => rcases hx with ⟨x, hx, rfl⟩ exact Or.inr ⟨x, closure_mono (subset_insert _ _) hx, rfl⟩ | zero => exact Or.inl rfl | add x y _ _ ih₁ ih₂ => rcases ih₁ with rfl | ⟨x, hx, rfl⟩ · simpa · rcases ih₂ with rfl | ⟨y, hy, rfl⟩ · exact Or.inr ⟨x, hx, by simp⟩ · refine Or.inr ⟨_, add_mem (mem_closure_of_mem (mem_insert _ _)) (add_mem hx hy), ?_⟩ simp_rw [← add_assoc, add_right_comm a a x] · rintro (rfl | ⟨x, hx, rfl⟩) · simp · simp_rw [insert_eq, closure_union, mem_sup, mem_closure_singleton] at hx rcases hx with ⟨_, ⟨n, rfl⟩, ⟨x, hx, rfl⟩⟩ rw [add_left_comm] refine add_mem (nsmul_mem (mem_closure_of_mem ?_) _) (mem_closure_of_mem (vadd_mem_vadd_set hx)) nth_rw 2 [← add_zero a] exact vadd_mem_vadd_set (zero_mem _) /-- Semilinear sets are closed under additive closure. -/ protected theorem IsSemilinearSet.closure (hs : IsSemilinearSet s) : IsSemilinearSet (closure s : Set M) := by rcases hs with ⟨S, hS, hS', rfl⟩ induction S, hS using Finite.induction_on with | empty => simp | insert S _ ih => simp_rw [mem_insert_iff, forall_eq_or_imp] at hS' simpa [closure_union, coe_sup] using hS'.1.closure.add (ih hS'.2) /-- A linear set is proper if its submonoid generators (periods) are linearly independent. -/ def IsProperLinearSet (s : Set M) : Prop := ∃ (a : M) (t : Set M), t.Finite ∧ LinearIndepOn ℕ id t ∧ s = a +ᵥ (closure t : Set M) theorem isProperLinearSet_iff : IsProperLinearSet s ↔ ∃ (a : M) (t : Finset M), LinearIndepOn ℕ id (t : Set M) ∧ s = a +ᵥ (closure (t : Set M) : Set M) := exists_congr fun a => ⟨fun ⟨t, ht, hs⟩ => ⟨ht.toFinset, by simpa⟩, fun ⟨t, hs⟩ => ⟨t, t.finite_toSet, hs⟩⟩ theorem IsProperLinearSet.isLinearSet (hs : IsProperLinearSet s) : IsLinearSet s := by rcases hs with ⟨a, t, ht, _, rfl⟩ exact ⟨a, t, ht, rfl⟩ @[simp] theorem IsProperLinearSet.singleton (a : M) : IsProperLinearSet {a} := ⟨a, ∅, by simp⟩ /-- A semilinear set is proper if it is a finite union of proper linear sets. -/ def IsProperSemilinearSet (s : Set M) : Prop := ∃ (S : Set (Set M)), S.Finite ∧ (∀ t ∈ S, IsProperLinearSet t) ∧ s = ⋃₀ S theorem IsProperSemilinearSet.isSemilinearSet (hs : IsProperSemilinearSet s) : IsSemilinearSet s := by rcases hs with ⟨S, hS, hS', rfl⟩ exact ⟨S, hS, fun s hs => (hS' s hs).isLinearSet, rfl⟩ theorem IsProperLinearSet.isProperSemilinearSet (hs : IsProperLinearSet s) : IsProperSemilinearSet s := ⟨{s}, by simpa⟩ @[simp] theorem IsProperSemilinearSet.empty : IsProperSemilinearSet (∅ : Set M) := ⟨∅, by simp⟩ theorem IsProperSemilinearSet.union (hs₁ : IsProperSemilinearSet s₁) (hs₂ : IsProperSemilinearSet s₂) : IsProperSemilinearSet (s₁ ∪ s₂) := by rcases hs₁ with ⟨S₁, hS₁, hS₁', rfl⟩ rcases hs₂ with ⟨S₂, hS₂, hS₂', rfl⟩ rw [← sUnion_union] refine ⟨S₁ ∪ S₂, hS₁.union hS₂, fun s hs => ?_, rfl⟩ rw [mem_union] at hs exact hs.elim (hS₁' s) (hS₂' s) theorem IsProperSemilinearSet.sUnion {S : Set (Set M)} (hS : S.Finite) (hS' : ∀ s ∈ S, IsProperSemilinearSet s) : IsProperSemilinearSet (⋃₀ S) := by induction S, hS using Finite.induction_on with | empty => simp | insert S _ ih => simp_rw [mem_insert_iff, forall_eq_or_imp] at hS' simpa using hS'.1.union (ih hS'.2) theorem IsProperSemilinearSet.biUnion {s : Set ι} {t : ι → Set M} (hs : s.Finite) (ht : ∀ i ∈ s, IsProperSemilinearSet (t i)) : IsProperSemilinearSet (⋃ i ∈ s, t i) := by rw [← sUnion_image] apply sUnion (hs.image t) simpa theorem IsProperSemilinearSet.biUnion_finset {s : Finset ι} {t : ι → Set M} (ht : ∀ i ∈ s, IsProperSemilinearSet (t i)) : IsProperSemilinearSet (⋃ i ∈ s, t i) := biUnion s.finite_toSet ht lemma IsLinearSet.isProperSemilinearSet [IsCancelAdd M] (hs : IsLinearSet s) : IsProperSemilinearSet s := by classical rw [isLinearSet_iff] at hs rcases hs with ⟨a, t, rfl⟩ induction hn : t.card using Nat.strong_induction_on generalizing a t with | _ n ih subst hn by_cases hindep : LinearIndepOn ℕ id (t : Set M) · exact IsProperLinearSet.isProperSemilinearSet ⟨a, t, by simpa⟩ rw [not_linearIndepOn_finset_iffₒₛ] at hindep rcases hindep with ⟨t', ht', f, heq, i, hi, hfi⟩ simp only [Function.id_def] at heq convert_to IsProperSemilinearSet (⋃ j ∈ t', ⋃ k ∈ Finset.range (f j), (a + k • j) +ᵥ (closure (t.erase j : Set M) : Set M)) · ext x simp only [mem_vadd_set, SetLike.mem_coe] constructor · rintro ⟨y, hy, rfl⟩ rw [mem_closure_finset] at hy rcases hy with ⟨g, -, rfl⟩ induction hn : g i using Nat.strong_induction_on generalizing g with | _ n ih' subst hn by_cases! hfg : ∀ j ∈ t', f j ≤ g j · convert ih' (g i - f i) (Nat.sub_lt_self hfi (hfg i hi)) (fun j => if j ∈ t' then g j - f j else g j + f j) (by simp [hi]) using 1 conv_lhs => rw [← Finset.union_sdiff_of_subset ht'] simp_rw [vadd_eq_add, add_left_cancel_iff, Finset.sum_union Finset.sdiff_disjoint.symm, ite_smul, Finset.sum_ite, Finset.filter_mem_eq_inter, Finset.inter_eq_right.2 ht', Finset.filter_notMem_eq_sdiff, add_smul, Finset.sum_add_distrib, ← heq, ← add_assoc, add_right_comm, ← Finset.sum_add_distrib] congr! 2 with j hj rw [← add_smul, tsub_add_cancel_of_le (hfg j hj)] · rcases hfg with ⟨j, hj, hgj⟩ simp only [mem_iUnion, Finset.mem_range, mem_vadd_set, SetLike.mem_coe, vadd_eq_add] refine ⟨j, hj, g j, hgj, ∑ k ∈ t.erase j, g k • k, sum_mem fun x hx => (nsmul_mem (mem_closure_of_mem hx) _), ?_⟩ rw [← Finset.sum_erase_add _ _ (ht' hj), ← add_assoc, add_right_comm] · simp only [mem_iUnion, Finset.mem_range, mem_vadd_set, SetLike.mem_coe, vadd_eq_add] rintro ⟨j, hj, k, hk, y, hy, rfl⟩ refine ⟨k • j + y, add_mem (nsmul_mem (mem_closure_of_mem (ht' hj)) _) ((closure_mono (t.erase_subset j)) hy), ?_⟩ rw [add_assoc] · exact .biUnion_finset fun j hj => .biUnion_finset fun k hk => ih _ (Finset.card_lt_card (Finset.erase_ssubset (ht' hj))) _ _ rfl /-- The **proper decomposition** of semilinear sets: every semilinear set is a finite union of proper linear sets. -/ theorem IsSemilinearSet.isProperSemilinearSet [IsCancelAdd M] (hs : IsSemilinearSet s) : IsProperSemilinearSet s := by rcases hs with ⟨S, hS, hS', rfl⟩ simp_rw [sUnion_eq_biUnion] exact IsProperSemilinearSet.biUnion hS fun s hs => (hS' s hs).isProperSemilinearSet
.lake/packages/mathlib/Mathlib/ModelTheory/Algebra/Field/IsAlgClosed.lean
import Mathlib.Data.Nat.PrimeFin import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.IsAlgClosed.Classification import Mathlib.ModelTheory.Algebra.Field.CharP import Mathlib.ModelTheory.Satisfiability /-! # The First-Order Theory of Algebraically Closed Fields This file defines the theory of algebraically closed fields of characteristic `p`, as well as proving completeness of the theory and the Lefschetz Principle. ## Main definitions * `FirstOrder.Language.Theory.ACF p` : the theory of algebraically closed fields of characteristic `p` as a theory over the language of rings. * `FirstOrder.Field.ACF_isComplete` : the theory of algebraically closed fields of characteristic `p` is complete whenever `p` is prime or zero. * `FirstOrder.Field.ACF_zero_realize_iff_infinite_ACF_prime_realize` : the Lefschetz principle. ## Implementation details To apply a theorem about the model theory of algebraically closed fields to a specific algebraically closed field `K` which does not have a `Language.ring.Structure` instance, you must introduce the local instance `compatibleRingOfRing K`. Theorems whose statement requires both a `Language.ring.Structure` instance and a `Field` instance will all be stated with the assumption `Field K`, `CharP K p`, `IsAlgClosed K` and `CompatibleRing K` and there are instances defined saying that these assumptions imply `Theory.field.Model K` and `(Theory.ACF p).Model K` ## References The first-order theory of algebraically closed fields, along with the Lefschetz Principle and the Ax-Grothendieck Theorem were first formalized in Lean 3 by Joseph Hua [here](https://github.com/Jlh18/ModelTheoryInLean8) with the master's thesis [here](https://github.com/Jlh18/ModelTheory8Report) -/ variable {K : Type*} namespace FirstOrder namespace Field open Ring FreeCommRing Polynomial Language /-- A generic monic polynomial of degree `n` as an element of the free commutative ring in `n + 1` variables, with a variable for each of the `n` non-leading coefficients of the polynomial and one variable (`Fin.last n`) for `X`. -/ def genericMonicPoly (n : ℕ) : FreeCommRing (Fin (n + 1)) := of (Fin.last _) ^ n + ∑ i : Fin n, of i.castSucc * of (Fin.last _) ^ (i : ℕ) theorem lift_genericMonicPoly [CommRing K] [Nontrivial K] {n : ℕ} (v : Fin (n + 1) → K) : FreeCommRing.lift v (genericMonicPoly n) = (((monicEquivDegreeLT n).trans (degreeLTEquiv K n).toEquiv).symm (v ∘ Fin.castSucc)).1.eval (v (Fin.last _)) := by simp [genericMonicPoly, monicEquivDegreeLT, degreeLTEquiv, eval_finset_sum] /-- A sentence saying every monic polynomial of degree `n` has a root. -/ noncomputable def genericMonicPolyHasRoot (n : ℕ) : Language.ring.Sentence := (∃' ((termOfFreeCommRing (genericMonicPoly n)).relabel Sum.inr =' 0)).alls theorem realize_genericMonicPolyHasRoot [Field K] [CompatibleRing K] (n : ℕ) : K ⊨ genericMonicPolyHasRoot n ↔ ∀ p : { p : K[X] // p.Monic ∧ p.natDegree = n }, ∃ x, p.1.eval x = 0 := by let _ := Classical.decEq K rw [Equiv.forall_congr_left ((monicEquivDegreeLT n).trans (degreeLTEquiv K n).toEquiv)] simp [Sentence.Realize, genericMonicPolyHasRoot, lift_genericMonicPoly] /-- The theory of algebraically closed fields of characteristic `p` as a theory over the language of rings -/ def _root_.FirstOrder.Language.Theory.ACF (p : ℕ) : Theory .ring := Theory.fieldOfChar p ∪ genericMonicPolyHasRoot '' {n | 0 < n} instance [Language.ring.Structure K] (p : ℕ) [h : (Theory.ACF p).Model K] : (Theory.fieldOfChar p).Model K := Theory.Model.mono h Set.subset_union_left instance [Field K] [CompatibleRing K] {p : ℕ} [CharP K p] [IsAlgClosed K] : (Theory.ACF p).Model K := by refine Theory.model_union_iff.2 ⟨inferInstance, ?_⟩ simp only [Theory.model_iff, Set.mem_image, forall_exists_index, and_imp] rintro _ n hn0 rfl simp only [realize_genericMonicPolyHasRoot] rintro ⟨p, _, rfl⟩ exact IsAlgClosed.exists_root p (ne_of_gt (natDegree_pos_iff_degree_pos.1 hn0)) theorem modelField_of_modelACF (p : ℕ) (K : Type*) [Language.ring.Structure K] [h : (Theory.ACF p).Model K] : Theory.field.Model K := Theory.Model.mono h (Set.subset_union_of_subset_left Set.subset_union_left _) /-- A model for the Theory of algebraically closed fields is a Field. After introducing this as a local instance on a particular Type, you should usually also introduce `modelField_of_modelACF p M`, `compatibleRingOfModelField` and `isAlgClosed_of_model_ACF` -/ @[reducible] noncomputable def fieldOfModelACF (p : ℕ) (K : Type*) [Language.ring.Structure K] [h : (Theory.ACF p).Model K] : Field K := by have := modelField_of_modelACF p K exact fieldOfModelField K theorem isAlgClosed_of_model_ACF (p : ℕ) (K : Type*) [Field K] [CompatibleRing K] [h : (Theory.ACF p).Model K] : IsAlgClosed K := by refine IsAlgClosed.of_exists_root _ ?_ intro p hpm hpi have h : K ⊨ genericMonicPolyHasRoot '' {n | 0 < n} := Theory.Model.mono h (by simp [Theory.ACF]) simp only [Theory.model_iff, Set.mem_image, forall_exists_index, and_imp] at h have := h _ p.natDegree (natDegree_pos_iff_degree_pos.2 (degree_pos_of_irreducible hpi)) rfl rw [realize_genericMonicPolyHasRoot] at this exact this ⟨_, hpm, rfl⟩ theorem ACF_isSatisfiable {p : ℕ} (hp : p.Prime ∨ p = 0) : (Theory.ACF p).IsSatisfiable := by cases hp with | inl hp => have : Fact p.Prime := ⟨hp⟩ let _ := compatibleRingOfRing (AlgebraicClosure (ZMod p)) have : CharP (AlgebraicClosure (ZMod p)) p := charP_of_injective_algebraMap (RingHom.injective (algebraMap (ZMod p) (AlgebraicClosure (ZMod p)))) p exact ⟨⟨AlgebraicClosure (ZMod p)⟩⟩ | inr hp => subst hp let _ := compatibleRingOfRing (AlgebraicClosure ℚ) have : CharP (AlgebraicClosure ℚ) 0 := charP_of_injective_algebraMap (RingHom.injective (algebraMap ℚ (AlgebraicClosure ℚ))) 0 exact ⟨⟨AlgebraicClosure ℚ⟩⟩ open Cardinal /-- The Theory `Theory.ACF p` is `κ`-categorical whenever `κ` is an uncountable cardinal. -/ theorem ACF_categorical {p : ℕ} (κ : Cardinal) (hκ : ℵ₀ < κ) : Categorical κ (Theory.ACF p) := by rintro ⟨M⟩ ⟨N⟩ hM hN let _ := fieldOfModelACF p M have := modelField_of_modelACF p M let _ := compatibleRingOfModelField M have := isAlgClosed_of_model_ACF p M have := charP_of_model_fieldOfChar p M let _ := fieldOfModelACF p N have := modelField_of_modelACF p N let _ := compatibleRingOfModelField N have := isAlgClosed_of_model_ACF p N have := charP_of_model_fieldOfChar p N constructor refine languageEquivEquivRingEquiv.symm ?_ apply Classical.choice refine IsAlgClosed.ringEquiv_of_equiv_of_char_eq p ?_ ?_ · rw [hM]; exact hκ · rw [← Cardinal.eq, hM, hN] theorem ACF_isComplete {p : ℕ} (hp : p.Prime ∨ p = 0) : (Theory.ACF p).IsComplete := by apply Categorical.isComplete.{0, 0, 0} (Order.succ ℵ₀) _ (ACF_categorical _ (Order.lt_succ _)) (Order.le_succ ℵ₀) · simp only [card_ring, lift_id'] exact le_trans (le_of_lt (lt_aleph0_of_finite _)) (Order.le_succ _) · exact ACF_isSatisfiable hp · rintro ⟨M⟩ let _ := fieldOfModelACF p M have := modelField_of_modelACF p M let _ := compatibleRingOfModelField M have := isAlgClosed_of_model_ACF p M infer_instance theorem finite_ACF_prime_not_realize_of_ACF_zero_realize (φ : Language.ring.Sentence) (h : Theory.ACF 0 ⊨ᵇ φ) : Set.Finite { p : Nat.Primes | ¬ Theory.ACF p ⊨ᵇ φ } := by rw [Theory.models_iff_finset_models] at h rcases h with ⟨T0, hT0, h⟩ have f : ∀ ψ ∈ Theory.ACF 0, { s : Finset Nat.Primes // ∀ q : Nat.Primes, q ∉ s → Theory.ACF q ⊨ᵇ ψ } := by intro ψ hψ rw [Theory.ACF, Theory.fieldOfChar, Set.union_right_comm, Set.mem_union, if_pos rfl, Set.mem_image] at hψ apply Classical.choice rcases hψ with h | ⟨p, hp, rfl⟩ · refine ⟨⟨∅, ?_⟩⟩ intro q _ exact Theory.models_sentence_of_mem (by rw [Theory.ACF, Theory.fieldOfChar, Set.union_right_comm]; exact Set.mem_union_left _ h) · refine ⟨⟨{⟨p, hp⟩}, ?_⟩⟩ rintro ⟨q, _⟩ hq ⟨K⟩ _ _ have hqp : q ≠ p := by simpa [← Nat.Primes.coe_nat_inj] using hq let _ := fieldOfModelACF q K have := modelField_of_modelACF q K let _ := compatibleRingOfModelField K have := charP_of_model_fieldOfChar q K simp only [eqZero, Term.equal, BoundedFormula.realize_not, BoundedFormula.realize_bdEqual, Term.realize_relabel, Sum.elim_comp_inl, realize_termOfFreeCommRing, map_natCast, realize_zero, ← CharP.charP_iff_prime_eq_zero hp] intro _ exact hqp <| CharP.eq K this inferInstance let s : Finset Nat.Primes := T0.attach.biUnion (fun φ => f φ.1 (hT0 φ.2)) have hs : ∀ (p : Nat.Primes) ψ, ψ ∈ T0 → p ∉ s → Theory.ACF p ⊨ᵇ ψ := by intro p ψ hψ hpψ simp only [s, Finset.mem_biUnion, Finset.mem_attach, true_and, Subtype.exists, not_exists] at hpψ exact (f ψ (hT0 hψ)).2 p (hpψ _ hψ) refine Set.Finite.subset (Finset.finite_toSet s) (Set.compl_subset_comm.2 ?_) intro p hp exact Theory.models_of_models_theory (fun ψ hψ => hs p ψ hψ hp) h /-- The **Lefschetz principle**. A first-order sentence is modeled by the theory of algebraically closed fields of characteristic zero if and only if it is modeled by the theory of algebraically closed fields of characteristic `p` for infinitely many `p`. -/ theorem ACF_zero_realize_iff_infinite_ACF_prime_realize {φ : Language.ring.Sentence} : Theory.ACF 0 ⊨ᵇ φ ↔ Set.Infinite { p : Nat.Primes | Theory.ACF p ⊨ᵇ φ } := by refine ⟨fun h => Set.infinite_of_finite_compl (finite_ACF_prime_not_realize_of_ACF_zero_realize φ h), not_imp_not.1 ?_⟩ simpa [(ACF_isComplete (Or.inr rfl)).models_not_iff, fun p : Nat.Primes => (ACF_isComplete (Or.inl p.2)).models_not_iff] using finite_ACF_prime_not_realize_of_ACF_zero_realize φ.not /-- Another statement of the **Lefschetz principle**. A first-order sentence is modeled by the theory of algebraically closed fields of characteristic zero if and only if it is modeled by the theory of algebraically closed fields of characteristic `p` for all but finitely many primes `p`. -/ theorem ACF_zero_realize_iff_finite_ACF_prime_not_realize {φ : Language.ring.Sentence} : Theory.ACF 0 ⊨ᵇ φ ↔ Set.Finite { p : Nat.Primes | Theory.ACF p ⊨ᵇ φ }ᶜ := ⟨fun h => finite_ACF_prime_not_realize_of_ACF_zero_realize φ h, fun h => ACF_zero_realize_iff_infinite_ACF_prime_realize.2 (Set.infinite_of_finite_compl h)⟩ end Field end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Algebra/Field/CharP.lean
import Mathlib.Algebra.CharP.Basic import Mathlib.ModelTheory.Algebra.Ring.FreeCommRing import Mathlib.ModelTheory.Algebra.Field.Basic /-! # First-order theory of fields This file defines the first-order theory of fields of characteristic `p` as a theory over the language of rings ## Main definitions - `FirstOrder.Language.Theory.fieldOfChar` : the first-order theory of fields of characteristic `p` as a theory over the language of rings -/ variable {p : ℕ} {K : Type*} namespace FirstOrder namespace Field open Language Ring /-- For a given natural number `n`, `eqZero n` is the sentence in the language of rings saying that `n` is zero. -/ noncomputable def eqZero (n : ℕ) : Language.ring.Sentence := Term.equal (termOfFreeCommRing n) 0 @[simp] theorem realize_eqZero [CommRing K] [CompatibleRing K] (n : ℕ) (v : Empty → K) : (Formula.Realize (eqZero n) v) ↔ ((n : K) = 0) := by simp [eqZero] /-- The first-order theory of fields of characteristic `p` as a theory over the language of rings -/ def _root_.FirstOrder.Language.Theory.fieldOfChar (p : ℕ) : Language.ring.Theory := Theory.field ∪ if p = 0 then (fun q => ∼(eqZero q)) '' {q : ℕ | q.Prime} else if p.Prime then {eqZero p} else {⊥} instance model_hasChar_of_charP [Field K] [CompatibleRing K] [CharP K p] : (Theory.fieldOfChar p).Model K := by refine Language.Theory.model_union_iff.2 ⟨inferInstance, ?_⟩ cases CharP.char_is_prime_or_zero K p with | inl hp => simp [hp.ne_zero, hp, Sentence.Realize] | inr hp => subst hp simp only [ite_true, Theory.model_iff, Set.mem_image, Set.mem_setOf_eq, Sentence.Realize, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Formula.realize_not, realize_eqZero, ← CharZero.charZero_iff_forall_prime_ne_zero] exact CharP.charP_to_charZero K theorem charP_iff_model_fieldOfChar [Field K] [CompatibleRing K] : (Theory.fieldOfChar p).Model K ↔ CharP K p := by simp only [Theory.fieldOfChar, Theory.model_union_iff, (show (Theory.field.Model K) by infer_instance), true_and] split_ifs with hp0 hp · subst hp0 simp only [Theory.model_iff, Set.mem_image, Set.mem_setOf_eq, Sentence.Realize, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Formula.realize_not, realize_eqZero, ← CharZero.charZero_iff_forall_prime_ne_zero] exact ⟨fun _ => CharP.ofCharZero _, fun _ => CharP.charP_to_charZero K⟩ · simp only [Theory.model_iff, Set.mem_singleton_iff, Sentence.Realize, forall_eq, realize_eqZero, ← CharP.charP_iff_prime_eq_zero hp] · simp only [Theory.model_iff, Set.mem_singleton_iff, Sentence.Realize, forall_eq, Formula.realize_bot, false_iff] intro H cases (CharP.char_is_prime_or_zero K p) <;> simp_all instance model_fieldOfChar_of_charP [Field K] [CompatibleRing K] [CharP K p] : (Theory.fieldOfChar p).Model K := charP_iff_model_fieldOfChar.2 inferInstance variable (p) (K) /- Not an instance because it caused performance problems in a different file. -/ theorem charP_of_model_fieldOfChar [Field K] [CompatibleRing K] [h : (Theory.fieldOfChar p).Model K] : CharP K p := charP_iff_model_fieldOfChar.1 h end Field end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Algebra/Field/Basic.lean
import Mathlib.ModelTheory.Syntax import Mathlib.ModelTheory.Semantics import Mathlib.ModelTheory.Algebra.Ring.Basic import Mathlib.Algebra.Field.MinimalAxioms import Mathlib.Data.Nat.Cast.Order.Ring /-! # The First-Order Theory of Fields This file defines the first-order theory of fields as a theory over the language of rings. ## Main definitions - `FirstOrder.Language.Theory.field` : the theory of fields - `FirstOrder.Model.fieldOfModelField` : a model of the theory of fields on a type `K` that already has ring operations. - `FirstOrder.Model.compatibleRingOfModelField` : shows that the ring operations on `K` given by `fieldOfModelField` are compatible with the ring operations on `K` given by the `Language.ring.Structure` instance. -/ variable {K : Type*} namespace FirstOrder namespace Field open Language Ring Structure BoundedFormula /-- An indexing type to name each of the field axioms. The theory of fields is defined as the range of a function `FieldAxiom -> Language.ring.Sentence` -/ inductive FieldAxiom : Type | addAssoc : FieldAxiom | zeroAdd : FieldAxiom | negAddCancel : FieldAxiom | mulAssoc : FieldAxiom | mulComm : FieldAxiom | oneMul : FieldAxiom | existsInv : FieldAxiom | leftDistrib : FieldAxiom | existsPairNE : FieldAxiom /-- The first-order sentence corresponding to each field axiom -/ @[simp] def FieldAxiom.toSentence : FieldAxiom → Language.ring.Sentence | .addAssoc => ∀' ∀' ∀' (((&0 + &1) + &2) =' (&0 + (&1 + &2))) | .zeroAdd => ∀' (((0 : Language.ring.Term _) + &0) =' &0) | .negAddCancel => ∀' ∀' ((-&0 + &0) =' 0) | .mulAssoc => ∀' ∀' ∀' (((&0 * &1) * &2) =' (&0 * (&1 * &2))) | .mulComm => ∀' ∀' ((&0 * &1) =' (&1 * &0)) | .oneMul => ∀' (((1 : Language.ring.Term _) * &0) =' &0) | .existsInv => ∀' (∼(&0 =' 0) ⟹ ∃' ((&0 * &1) =' 1)) | .leftDistrib => ∀' ∀' ∀' ((&0 * (&1 + &2)) =' ((&0 * &1) + (&0 * &2))) | .existsPairNE => ∃' ∃' (∼(&0 =' &1)) /-- The Proposition corresponding to each field axiom -/ @[simp] def FieldAxiom.toProp (K : Type*) [Add K] [Mul K] [Neg K] [Zero K] [One K] : FieldAxiom → Prop | .addAssoc => ∀ x y z : K, (x + y) + z = x + (y + z) | .zeroAdd => ∀ x : K, 0 + x = x | .negAddCancel => ∀ x : K, -x + x = 0 | .mulAssoc => ∀ x y z : K, (x * y) * z = x * (y * z) | .mulComm => ∀ x y : K, x * y = y * x | .oneMul => ∀ x : K, 1 * x = x | .existsInv => ∀ x : K, x ≠ 0 → ∃ y, x * y = 1 | .leftDistrib => ∀ x y z : K, x * (y + z) = x * y + x * z | .existsPairNE => ∃ x y : K, x ≠ y /-- The first-order theory of fields, as a theory over the language of rings -/ def _root_.FirstOrder.Language.Theory.field : Language.ring.Theory := Set.range FieldAxiom.toSentence theorem FieldAxiom.realize_toSentence_iff_toProp {K : Type*} [Add K] [Mul K] [Neg K] [Zero K] [One K] [CompatibleRing K] (ax : FieldAxiom) : (K ⊨ (ax.toSentence : Sentence Language.ring)) ↔ ax.toProp K := by cases ax <;> simp [Sentence.Realize, Formula.Realize, Fin.snoc] theorem FieldAxiom.toProp_of_model {K : Type*} [Add K] [Mul K] [Neg K] [Zero K] [One K] [CompatibleRing K] [Theory.field.Model K] (ax : FieldAxiom) : ax.toProp K := (FieldAxiom.realize_toSentence_iff_toProp ax).1 (Theory.realize_sentence_of_mem Theory.field (Set.mem_range_self ax)) open FieldAxiom /-- A model for the theory of fields is a field. To introduced locally on Types that don't already have instances for ring operations. When this is used, it is almost always useful to also add locally the instance `compatibleFieldOfModelField` afterwards. -/ noncomputable abbrev fieldOfModelField (K : Type*) [Language.ring.Structure K] [Theory.field.Model K] : Field K := letI : DecidableEq K := Classical.decEq K letI := addOfRingStructure K letI := mulOfRingStructure K letI := negOfRingStructure K letI := zeroOfRingStructure K letI := oneOfRingStructure K letI := compatibleRingOfRingStructure K have exists_inv : ∀ x : K, x ≠ 0 → ∃ y : K, x * y = 1 := existsInv.toProp_of_model letI : Inv K := ⟨fun x => if hx0 : x = 0 then 0 else Classical.choose (exists_inv x hx0)⟩ Field.ofMinimalAxioms K addAssoc.toProp_of_model zeroAdd.toProp_of_model negAddCancel.toProp_of_model mulAssoc.toProp_of_model mulComm.toProp_of_model oneMul.toProp_of_model (fun x hx0 => show x * (dite _ _ _) = _ from (dif_neg hx0).symm ▸ Classical.choose_spec (existsInv.toProp_of_model x hx0)) (dif_pos rfl) leftDistrib.toProp_of_model existsPairNE.toProp_of_model section attribute [local instance] fieldOfModelField /-- The instances given by `fieldOfModelField` are compatible with the `Language.ring.Structure` instance on `K`. This instance is to be used on models for the language of fields that do not already have the ring operations on the Type. Always add `fieldOfModelField` as a local instance first before using this instance. -/ noncomputable abbrev compatibleRingOfModelField (K : Type*) [Language.ring.Structure K] [Theory.field.Model K] : CompatibleRing K := compatibleRingOfRingStructure K end instance [Field K] [CompatibleRing K] : Theory.field.Model K := { realize_of_mem := by simp only [Theory.field, Set.mem_range, exists_imp] rintro φ a rfl rw [a.realize_toSentence_iff_toProp (K := K)] cases a with | existsPairNE => exact exists_pair_ne K | existsInv => exact fun x hx0 => ⟨x⁻¹, mul_inv_cancel₀ hx0⟩ | addAssoc => exact add_assoc | zeroAdd => exact zero_add | negAddCancel => exact neg_add_cancel | mulAssoc => exact mul_assoc | mulComm => exact mul_comm | oneMul => exact one_mul | leftDistrib => exact mul_add } end Field end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Algebra/Ring/Basic.lean
import Mathlib.ModelTheory.Syntax import Mathlib.ModelTheory.Semantics import Mathlib.Algebra.Ring.Equiv /-! # First-Order Language of Rings This file defines the first-order language of rings, as well as defining instance of `Add`, `Mul`, etc. on terms in the language. ## Main Definitions - `FirstOrder.Language.ring` : the language of rings, with function symbols `+`, `*`, `-`, `0`, `1` - `FirstOrder.Ring.CompatibleRing` : A class stating that a type is a `Language.ring.Structure`, and that this structure is the same as the structure given by the classes `Add`, `Mul`, etc. already on `R`. - `FirstOrder.Ring.compatibleRingOfRing` : Given a type `R` with instances for each of the `Ring` operations, make a `compatibleRing` instance. ## Implementation Notes There are implementation difficulties with the model theory of rings caused by the fact that there are two different ways to say that `R` is a `Ring`. We can say `Ring R` or `Language.ring.Structure R` and `Theory.ring.Model R` (The theory of rings is not implemented yet). The recommended way to use this library is to use the hypotheses `CompatibleRing R` and `Ring R` on any theorem that requires both a `Ring` instance and a `Language.ring.Structure` instance in order to state the theorem. To apply such a theorem to a ring `R` with a `Ring` instance, use the tactic `let _ := compatibleRingOfRing R`. To apply the theorem to `K` a `Language.ring.Structure K` instance and for example an instance of `Theory.field.Model K`, you must add local instances with definitions like `ModelTheory.Field.fieldOfModelField K` and `FirstOrder.Ring.compatibleRingOfModelField K`. (in `Mathlib/ModelTheory/Algebra/Field/Basic.lean`), depending on the Theory. -/ variable {α : Type*} namespace FirstOrder /-- The type of Ring functions, to be used in the definition of the language of rings. It contains the operations (+,*,-,0,1) -/ inductive ringFunc : ℕ → Type | add : ringFunc 2 | mul : ringFunc 2 | neg : ringFunc 1 | zero : ringFunc 0 | one : ringFunc 0 deriving DecidableEq /-- The language of rings contains the operations (+,*,-,0,1) -/ def Language.ring : Language := { Functions := ringFunc Relations := fun _ => Empty } deriving IsAlgebraic namespace Ring open ringFunc Language /-- This instance does not get inferred without `instDecidableEqFunctions` in `ModelTheory/Basic`. -/ example (n : ℕ) : DecidableEq (Language.ring.Functions n) := inferInstance /-- This instance does not get inferred without `instDecidableEqRelations` in `ModelTheory/Basic`. -/ example (n : ℕ) : DecidableEq (Language.ring.Relations n) := inferInstance /-- `RingFunc.add`, but with the defeq type `Language.ring.Functions 2` instead of `RingFunc 2` -/ abbrev addFunc : Language.ring.Functions 2 := add /-- `RingFunc.mul`, but with the defeq type `Language.ring.Functions 2` instead of `RingFunc 2` -/ abbrev mulFunc : Language.ring.Functions 2 := mul /-- `RingFunc.neg`, but with the defeq type `Language.ring.Functions 1` instead of `RingFunc 1` -/ abbrev negFunc : Language.ring.Functions 1 := neg /-- `RingFunc.zero`, but with the defeq type `Language.ring.Functions 0` instead of `RingFunc 0` -/ abbrev zeroFunc : Language.ring.Functions 0 := zero /-- `RingFunc.one`, but with the defeq type `Language.ring.Functions 0` instead of `RingFunc 0` -/ abbrev oneFunc : Language.ring.Functions 0 := one instance (α : Type*) : Zero (Language.ring.Term α) := { zero := Constants.term zeroFunc } theorem zero_def (α : Type*) : (0 : Language.ring.Term α) = Constants.term zeroFunc := rfl instance (α : Type*) : One (Language.ring.Term α) := { one := Constants.term oneFunc } theorem one_def (α : Type*) : (1 : Language.ring.Term α) = Constants.term oneFunc := rfl instance (α : Type*) : Add (Language.ring.Term α) := { add := addFunc.apply₂ } theorem add_def (α : Type*) (t₁ t₂ : Language.ring.Term α) : t₁ + t₂ = addFunc.apply₂ t₁ t₂ := rfl instance (α : Type*) : Mul (Language.ring.Term α) := { mul := mulFunc.apply₂ } theorem mul_def (α : Type*) (t₁ t₂ : Language.ring.Term α) : t₁ * t₂ = mulFunc.apply₂ t₁ t₂ := rfl instance (α : Type*) : Neg (Language.ring.Term α) := { neg := negFunc.apply₁ } theorem neg_def (α : Type*) (t : Language.ring.Term α) : -t = negFunc.apply₁ t := rfl instance : Fintype Language.ring.Symbols := ⟨⟨Multiset.ofList [Sum.inl ⟨2, .add⟩, Sum.inl ⟨2, .mul⟩, Sum.inl ⟨1, .neg⟩, Sum.inl ⟨0, .zero⟩, Sum.inl ⟨0, .one⟩], by dsimp [Language.Symbols]; decide⟩, by intro x dsimp [Language.Symbols] rcases x with ⟨_, f⟩ | ⟨_, f⟩ · cases f <;> decide · cases f ⟩ @[simp] theorem card_ring : card Language.ring = 5 := by have : Fintype.card Language.ring.Symbols = 5 := rfl simp [Language.card, this] open Structure /-- A Type `R` is a `CompatibleRing` if it is a structure for the language of rings and this structure is the same as the structure already given on `R` by the classes `Add`, `Mul` etc. It is recommended to use this type class as a hypothesis to any theorem whose statement requires a type to have be both a `Ring` (or `Field` etc.) and a `Language.ring.Structure` -/ /- This class does not extend `Add` etc, because this way it can be used in combination with a `Ring`, or `Field` instance without having multiple different `Add` structures on the Type. -/ class CompatibleRing (R : Type*) [Add R] [Mul R] [Neg R] [One R] [Zero R] extends Language.ring.Structure R where /-- Addition in the `Language.ring.Structure` is the same as the addition given by the `Add` instance -/ funMap_add : ∀ x, funMap addFunc x = x 0 + x 1 /-- Multiplication in the `Language.ring.Structure` is the same as the multiplication given by the `Mul` instance -/ funMap_mul : ∀ x, funMap mulFunc x = x 0 * x 1 /-- Negation in the `Language.ring.Structure` is the same as the negation given by the `Neg` instance -/ funMap_neg : ∀ x, funMap negFunc x = -x 0 /-- The constant `0` in the `Language.ring.Structure` is the same as the constant given by the `Zero` instance -/ funMap_zero : ∀ x, funMap (zeroFunc : Language.ring.Constants) x = 0 /-- The constant `1` in the `Language.ring.Structure` is the same as the constant given by the `One` instance -/ funMap_one : ∀ x, funMap (oneFunc : Language.ring.Constants) x = 1 open CompatibleRing attribute [simp] funMap_add funMap_mul funMap_neg funMap_zero funMap_one section variable {R : Type*} [Add R] [Mul R] [Neg R] [One R] [Zero R] [CompatibleRing R] @[simp] theorem realize_add (x y : ring.Term α) (v : α → R) : Term.realize v (x + y) = Term.realize v x + Term.realize v y := by simp [add_def, funMap_add] @[simp] theorem realize_mul (x y : ring.Term α) (v : α → R) : Term.realize v (x * y) = Term.realize v x * Term.realize v y := by simp [mul_def, funMap_mul] @[simp] theorem realize_neg (x : ring.Term α) (v : α → R) : Term.realize v (-x) = -Term.realize v x := by simp [neg_def, funMap_neg] @[simp] theorem realize_zero (v : α → R) : Term.realize v (0 : ring.Term α) = 0 := by simp [zero_def, funMap_zero, constantMap] @[simp] theorem realize_one (v : α → R) : Term.realize v (1 : ring.Term α) = 1 := by simp [one_def, funMap_one, constantMap] end /-- Given a Type `R` with instances for each of the `Ring` operations, make a `Language.ring.Structure R` instance, along with a proof that the operations given by the `Language.ring.Structure` are the same as those given by the `Add` or `Mul` etc. instances. This definition can be used when applying a theorem about the model theory of rings to a literal ring `R`, by writing `let _ := compatibleRingOfRing R`. After this, if, for example, `R` is a field, then Lean will be able to find the instance for `Theory.field.Model R`, and it will be possible to apply theorems about the model theory of fields. This is a `def` and not an `instance`, because the path `Ring` => `Language.ring.Structure` => `Ring` cannot be made to commute by definition -/ def compatibleRingOfRing (R : Type*) [Add R] [Mul R] [Neg R] [One R] [Zero R] : CompatibleRing R := { funMap := fun {n} f => match n, f with | _, .add => fun x => x 0 + x 1 | _, .mul => fun x => x 0 * x 1 | _, .neg => fun x => -x 0 | _, .zero => fun _ => 0 | _, .one => fun _ => 1 funMap_add := fun _ => rfl, funMap_mul := fun _ => rfl, funMap_neg := fun _ => rfl, funMap_zero := fun _ => rfl, funMap_one := fun _ => rfl } /-- An isomorphism in the language of rings is a ring isomorphism -/ def languageEquivEquivRingEquiv {R S : Type*} [NonAssocRing R] [NonAssocRing S] [CompatibleRing R] [CompatibleRing S] : (Language.ring.Equiv R S) ≃ (R ≃+* S) := { toFun f := { f with map_add' := by intro x y simpa using f.map_fun addFunc ![x, y] map_mul' := by intro x y simpa using f.map_fun mulFunc ![x, y] } invFun f := { f with map_fun' := fun {n} f => by cases f <;> simp map_rel' := fun {n} f => by cases f } } variable (R : Type*) [Language.ring.Structure R] /-- A def to put an `Add` instance on a type with a `Language.ring.Structure` instance. To be used sparingly, usually only when defining a more useful definition like, `[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/ abbrev addOfRingStructure : Add R := { add := fun x y => funMap addFunc ![x, y] } /-- A def to put an `Mul` instance on a type with a `Language.ring.Structure` instance. To be used sparingly, usually only when defining a more useful definition like, `[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/ abbrev mulOfRingStructure : Mul R := { mul := fun x y => funMap mulFunc ![x, y] } /-- A def to put an `Neg` instance on a type with a `Language.ring.Structure` instance. To be used sparingly, usually only when defining a more useful definition like, `[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/ abbrev negOfRingStructure : Neg R := { neg := fun x => funMap negFunc ![x] } /-- A def to put an `Zero` instance on a type with a `Language.ring.Structure` instance. To be used sparingly, usually only when defining a more useful definition like, `[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/ abbrev zeroOfRingStructure : Zero R := { zero := funMap zeroFunc ![] } /-- A def to put an `One` instance on a type with a `Language.ring.Structure` instance. To be used sparingly, usually only when defining a more useful definition like, `[Language.ring.Structure K] -> [Theory.field.Model K] -> Field K` -/ abbrev oneOfRingStructure : One R := { one := funMap oneFunc ![] } attribute [local instance] addOfRingStructure mulOfRingStructure negOfRingStructure zeroOfRingStructure oneOfRingStructure /-- Given a Type `R` with a `Language.ring.Structure R`, the instance given by `addOfRingStructure` etc. are compatible with the `Language.ring.Structure` instance on `R`. This definition is only to be used when `addOfRingStructure`, `mulOfRingStructure` etc are local instances. -/ abbrev compatibleRingOfRingStructure : CompatibleRing R := { funMap_add := by simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi] intros; rfl funMap_mul := by simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi] intros; rfl funMap_neg := by simp only [Fin.forall_fin_succ_pi, Fin.cons_zero, Fin.forall_fin_zero_pi] intros; rfl funMap_zero := by simp only [Fin.forall_fin_zero_pi] rfl funMap_one := by simp only [Fin.forall_fin_zero_pi] rfl } end Ring end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Algebra/Ring/FreeCommRing.lean
import Mathlib.ModelTheory.Algebra.Ring.Basic import Mathlib.RingTheory.FreeCommRing /-! # Making a term in the language of rings from an element of the FreeCommRing This file defines the function `FirstOrder.Ring.termOfFreeCommRing` which constructs a `Language.ring.Term α` from an element of `FreeCommRing α`. The theorem `FirstOrder.Ring.realize_termOfFreeCommRing` shows that the term constructed when realized in a ring `R` is equal to the lift of the element of `FreeCommRing α` to `R`. -/ namespace FirstOrder namespace Ring open Language variable {α : Type*} section attribute [local instance] compatibleRingOfRing private theorem exists_term_realize_eq_freeCommRing (p : FreeCommRing α) : ∃ t : Language.ring.Term α, (t.realize FreeCommRing.of : FreeCommRing α) = p := FreeCommRing.induction_on p ⟨-1, by simp⟩ (fun a => ⟨Term.var a, by simp [Term.realize]⟩) (fun x y ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ => ⟨t₁ + t₂, by simp_all⟩) (fun x y ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ => ⟨t₁ * t₂, by simp_all⟩) end /-- Make a `Language.ring.Term α` from an element of `FreeCommRing α` -/ noncomputable def termOfFreeCommRing (p : FreeCommRing α) : Language.ring.Term α := Classical.choose (exists_term_realize_eq_freeCommRing p) variable {R : Type*} [CommRing R] [CompatibleRing R] @[simp] theorem realize_termOfFreeCommRing (p : FreeCommRing α) (v : α → R) : (termOfFreeCommRing p).realize v = FreeCommRing.lift v p := by rw [termOfFreeCommRing] conv_rhs => rw [← Classical.choose_spec (exists_term_realize_eq_freeCommRing p)] induction Classical.choose (exists_term_realize_eq_freeCommRing p) with | var _ => simp | func f a ih => cases f <;> simp [ih] end Ring end FirstOrder
.lake/packages/mathlib/Mathlib/ModelTheory/Algebra/Ring/Definability.lean
import Mathlib.ModelTheory.Definability import Mathlib.RingTheory.MvPolynomial.FreeCommRing import Mathlib.RingTheory.Nullstellensatz import Mathlib.ModelTheory.Algebra.Ring.FreeCommRing /-! # Definable Subsets in the language of rings This file proves that the set of zeros of a multivariable polynomial is a definable subset. -/ namespace FirstOrder namespace Ring open MvPolynomial Language BoundedFormula theorem mvPolynomial_zeroLocus_definable {ι K : Type*} [Field K] [CompatibleRing K] (S : Finset (MvPolynomial ι K)) : Set.Definable (⋃ p ∈ S, p.coeff '' p.support : Set K) Language.ring (zeroLocus K (Ideal.span (S : Set (MvPolynomial ι K)))) := by rw [Set.definable_iff_exists_formula_sum] let p' := genericPolyMap (fun p : S => p.1.support) letI := Classical.decEq ι letI := Classical.decEq K rw [MvPolynomial.zeroLocus_span] refine ⟨BoundedFormula.iInf (fun i : S => Term.equal ((termOfFreeCommRing (p' i)).relabel (Sum.map (fun p => ⟨p.1.1.coeff p.2.1, by simp only [Set.mem_iUnion] exact ⟨p.1.1, p.1.2, Set.mem_image_of_mem _ p.2.2⟩⟩) id)) 0), ?_⟩ simp [Formula.Realize, Term.equal, Function.comp_def, p', MvPolynomial.aeval_eq_eval₂Hom] end Ring end FirstOrder
.lake/packages/mathlib/Mathlib/Topology/Germ.lean
import Mathlib.Algebra.BigOperators.Group.Finset.Defs import Mathlib.Algebra.Module.LinearMap.Defs import Mathlib.Algebra.Order.Hom.Ring import Mathlib.Order.Filter.Germ.Basic import Mathlib.Topology.LocallyConstant.Basic /-! # Germs of functions between topological spaces In this file, we prove basic properties of germs of functions between topological spaces, with respect to the neighbourhood filter `𝓝 x`. ## Main definitions and results * `Filter.Germ.value φ f`: value associated to the germ `φ` at a point `x`, w.r.t. the neighbourhood filter at `x`. This is the common value of all representatives of `φ` at `x`. * `Filter.Germ.valueOrderRingHom` and friends: the map `Germ (𝓝 x) E → E` is a monoid homomorphism, 𝕜-linear map, ring homomorphism, monotone ring homomorphism * `RestrictGermPredicate`: given a predicate on germs `P : Π x : X, germ (𝓝 x) Y → Prop` and `A : set X`, build a new predicate on germs `restrictGermPredicate P A` such that `(∀ x, RestrictGermPredicate P A x f) ↔ ∀ᶠ x near A, P x f`; `forall_restrictRermPredicate_iff` is this equivalence. * `Filter.Germ.sliceLeft, sliceRight`: map the germ of functions `X × Y → Z` at `p = (x,y) ∈ X × Y` to the corresponding germ of functions `X → Z` at `x ∈ X` resp. `Y → Z` at `y ∈ Y`. * `eq_of_germ_isConstant`: if each germ of `f : X → Y` is constant and `X` is pre-connected, `f` is constant. -/ open scoped Topology open Filter Set variable {X Y Z : Type*} [TopologicalSpace X] {f g : X → Y} {A : Set X} {x : X} namespace Filter.Germ /-- The value associated to a germ at a point. This is the common value shared by all representatives at the given point. -/ def value {X α : Type*} [TopologicalSpace X] {x : X} (φ : Germ (𝓝 x) α) : α := Quotient.liftOn' φ (fun f ↦ f x) fun f g h ↦ by dsimp only; rw [Eventually.self_of_nhds h] theorem value_smul {α β : Type*} [SMul α β] (φ : Germ (𝓝 x) α) (ψ : Germ (𝓝 x) β) : (φ • ψ).value = φ.value • ψ.value := Germ.inductionOn φ fun _ ↦ Germ.inductionOn ψ fun _ ↦ rfl /-- The map `Germ (𝓝 x) E → E` into a monoid `E` as a monoid homomorphism -/ @[to_additive /-- The map `Germ (𝓝 x) E → E` as an additive monoid homomorphism -/] def valueMulHom {X E : Type*} [Monoid E] [TopologicalSpace X] {x : X} : Germ (𝓝 x) E →* E where toFun := Filter.Germ.value map_one' := rfl map_mul' φ ψ := Germ.inductionOn φ fun _ ↦ Germ.inductionOn ψ fun _ ↦ rfl /-- The map `Germ (𝓝 x) E → E` into a `𝕜`-module `E` as a `𝕜`-linear map -/ def valueₗ {X 𝕜 E : Type*} [Semiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace X] {x : X} : Germ (𝓝 x) E →ₗ[𝕜] E where __ := Filter.Germ.valueAddHom map_smul' := fun _ φ ↦ Germ.inductionOn φ fun _ ↦ rfl /-- The map `Germ (𝓝 x) E → E` as a ring homomorphism -/ def valueRingHom {X E : Type*} [Semiring E] [TopologicalSpace X] {x : X} : Germ (𝓝 x) E →+* E := { Filter.Germ.valueMulHom, Filter.Germ.valueAddHom with } /-- The map `Germ (𝓝 x) E → E` as a monotone ring homomorphism -/ def valueOrderRingHom {X E : Type*} [Semiring E] [PartialOrder E] [TopologicalSpace X] {x : X} : Germ (𝓝 x) E →+*o E where __ := Filter.Germ.valueRingHom monotone' := fun φ ψ ↦ Germ.inductionOn φ fun _ ↦ Germ.inductionOn ψ fun _ h ↦ h.self_of_nhds end Filter.Germ section RestrictGermPredicate /-- Given a predicate on germs `P : Π x : X, germ (𝓝 x) Y → Prop` and `A : set X`, build a new predicate on germs `RestrictGermPredicate P A` such that `(∀ x, RestrictGermPredicate P A x f) ↔ ∀ᶠ x near A, P x f`, see `forall_restrictGermPredicate_iff` for this equivalence. -/ def RestrictGermPredicate (P : ∀ x : X, Germ (𝓝 x) Y → Prop) (A : Set X) : ∀ x : X, Germ (𝓝 x) Y → Prop := fun x φ ↦ Germ.liftOn φ (fun f ↦ x ∈ A → ∀ᶠ y in 𝓝 x, P y f) haveI : ∀ f f' : X → Y, f =ᶠ[𝓝 x] f' → (∀ᶠ y in 𝓝 x, P y f) → ∀ᶠ y in 𝓝 x, P y f' := by intro f f' hff' hf apply (hf.and <| Eventually.eventually_nhds hff').mono rintro y ⟨hy, hy'⟩ rwa [Germ.coe_eq.mpr (EventuallyEq.symm hy')] fun f f' hff' ↦ propext <| forall_congr' fun _ ↦ ⟨this f f' hff', this f' f hff'.symm⟩ theorem Filter.Eventually.germ_congr_set {P : ∀ x : X, Germ (𝓝 x) Y → Prop} (hf : ∀ᶠ x in 𝓝ˢ A, P x f) (h : ∀ᶠ z in 𝓝ˢ A, g z = f z) : ∀ᶠ x in 𝓝ˢ A, P x g := by rw [eventually_nhdsSet_iff_forall] at * intro x hx apply ((hf x hx).and (h x hx).eventually_nhds).mono intro y hy convert hy.1 using 1 exact Germ.coe_eq.mpr hy.2 theorem restrictGermPredicate_congr {P : ∀ x : X, Germ (𝓝 x) Y → Prop} (hf : RestrictGermPredicate P A x f) (h : ∀ᶠ z in 𝓝ˢ A, g z = f z) : RestrictGermPredicate P A x g := by intro hx apply ((hf hx).and <| (eventually_nhdsSet_iff_forall.mp h x hx).eventually_nhds).mono rintro y ⟨hy, h'y⟩ rwa [Germ.coe_eq.mpr h'y] theorem forall_restrictGermPredicate_iff {P : ∀ x : X, Germ (𝓝 x) Y → Prop} : (∀ x, RestrictGermPredicate P A x f) ↔ ∀ᶠ x in 𝓝ˢ A, P x f := by rw [eventually_nhdsSet_iff_forall] rfl theorem forall_restrictGermPredicate_of_forall {P : ∀ x : X, Germ (𝓝 x) Y → Prop} (h : ∀ x, P x f) : ∀ x, RestrictGermPredicate P A x f := forall_restrictGermPredicate_iff.mpr (Eventually.of_forall h) end RestrictGermPredicate namespace Filter.Germ /-- Map the germ of functions `X × Y → Z` at `p = (x,y) ∈ X × Y` to the corresponding germ of functions `X → Z` at `x ∈ X` -/ def sliceLeft [TopologicalSpace Y] {p : X × Y} (P : Germ (𝓝 p) Z) : Germ (𝓝 p.1) Z := P.compTendsto (Prod.mk · p.2) (Continuous.prodMk_left p.2).continuousAt @[simp] theorem sliceLeft_coe [TopologicalSpace Y] {y : Y} (f : X × Y → Z) : (↑f : Germ (𝓝 (x, y)) Z).sliceLeft = fun x' ↦ f (x', y) := rfl /-- Map the germ of functions `X × Y → Z` at `p = (x,y) ∈ X × Y` to the corresponding germ of functions `Y → Z` at `y ∈ Y` -/ def sliceRight [TopologicalSpace Y] {p : X × Y} (P : Germ (𝓝 p) Z) : Germ (𝓝 p.2) Z := P.compTendsto (Prod.mk p.1) (Continuous.prodMk_right p.1).continuousAt @[simp] theorem sliceRight_coe [TopologicalSpace Y] {y : Y} (f : X × Y → Z) : (↑f : Germ (𝓝 (x, y)) Z).sliceRight = fun y' ↦ f (x, y') := rfl lemma isConstant_comp_subtype {s : Set X} {f : X → Y} {x : s} (hf : (f : Germ (𝓝 (x : X)) Y).IsConstant) : ((f ∘ Subtype.val : s → Y) : Germ (𝓝 x) Y).IsConstant := isConstant_comp_tendsto hf continuousAt_subtype_val end Filter.Germ /-- If the germ of `f` w.r.t. each `𝓝 x` is constant, `f` is locally constant. -/ lemma IsLocallyConstant.of_germ_isConstant (h : ∀ x : X, (f : Germ (𝓝 x) Y).IsConstant) : IsLocallyConstant f := by intro s rw [isOpen_iff_mem_nhds] intro a ha obtain ⟨b, hb⟩ := h a apply mem_of_superset hb intro x hx have : f x = f a := (mem_of_mem_nhds hb) ▸ hx rw [mem_preimage, this] exact ha theorem eq_of_germ_isConstant [i : PreconnectedSpace X] (h : ∀ x : X, (f : Germ (𝓝 x) Y).IsConstant) (x x' : X) : f x = f x' := (IsLocallyConstant.of_germ_isConstant h).apply_eq_of_isPreconnected (preconnectedSpace_iff_univ.mp i) (by trivial) (by trivial) lemma eq_of_germ_isConstant_on {s : Set X} (h : ∀ x ∈ s, (f : Germ (𝓝 x) Y).IsConstant) (hs : IsPreconnected s) {x' : X} (x_in : x ∈ s) (x'_in : x' ∈ s) : f x = f x' := by let i : s → X := fun x ↦ x change (f ∘ i) (⟨x, x_in⟩ : s) = (f ∘ i) (⟨x', x'_in⟩ : s) have : PreconnectedSpace s := Subtype.preconnectedSpace hs exact eq_of_germ_isConstant (fun y ↦ Germ.isConstant_comp_subtype (h y y.2)) _ _ @[to_additive (attr := simp)] theorem Germ.coe_prod {α : Type*} (l : Filter α) (R : Type*) [CommMonoid R] {ι} (f : ι → α → R) (s : Finset ι) : ((∏ i ∈ s, f i : α → R) : Germ l R) = ∏ i ∈ s, (f i : Germ l R) := map_prod (Germ.coeMulHom l : (α → R) →* Germ l R) f s
.lake/packages/mathlib/Mathlib/Topology/Covering.lean
import Mathlib.Topology.IsLocalHomeomorph import Mathlib.Topology.FiberBundle.Basic /-! # Covering Maps This file defines covering maps. ## Main definitions * `IsEvenlyCovered f x I`: A point `x` is evenly covered by `f : E → X` with fiber `I` if `I` is discrete and there is a homeomorphism `f ⁻¹' U ≃ₜ U × I` for some open set `U` containing `x` with `f ⁻¹' U` open, such that the induced map `f ⁻¹' U → U` coincides with `f`. * `IsCoveringMap f`: A function `f : E → X` is a covering map if every point `x` is evenly covered by `f` with fiber `f ⁻¹' {x}`. The fibers `f ⁻¹' {x}` must be discrete, but if `X` is not connected, then the fibers `f ⁻¹' {x}` are not necessarily isomorphic. Also, `f` is not assumed to be surjective, so the fibers are even allowed to be empty. -/ open Bundle Topology variable {E X : Type*} [TopologicalSpace E] [TopologicalSpace X] (f : E → X) (s : Set X) /-- A point `x : X` is evenly covered by `f : E → X` if `x` has an evenly covered neighborhood. **Remark**: `DiscreteTopology I ∧ ∃ Trivialization I f, x ∈ t.baseSet` would be a simpler definition, but unfortunately it does not work if `E` is nonempty but nonetheless `f` has empty fibers over `s`. If `OpenPartialHomeomorph` could be refactored to work with an empty space and a nonempty space while preserving the APIs, we could switch back to the definition. -/ def IsEvenlyCovered (x : X) (I : Type*) [TopologicalSpace I] := DiscreteTopology I ∧ ∃ U : Set X, x ∈ U ∧ IsOpen U ∧ IsOpen (f ⁻¹' U) ∧ ∃ H : f ⁻¹' U ≃ₜ U × I, ∀ x, (H x).1.1 = f x namespace IsEvenlyCovered variable {f} {I : Type*} [TopologicalSpace I] /-- If `x : X` is evenly covered by `f` with fiber `I`, then `I` is homeomorphic to `f ⁻¹' {x}`. -/ noncomputable def fiberHomeomorph {x : X} (h : IsEvenlyCovered f x I) : I ≃ₜ f ⁻¹' {x} := by choose _ U hxU hU hfU H hH using h exact { toFun i := ⟨H.symm (⟨x, hxU⟩, i), by simp [← hH]⟩ invFun e := (H ⟨e, by rwa [Set.mem_preimage, (e.2 : f e = x)]⟩).2 left_inv _ := by simp right_inv e := Set.inclusion_injective (Set.preimage_mono (Set.singleton_subset_iff.mpr hxU)) <| H.injective <| Prod.ext (Subtype.ext <| by simpa [hH] using e.2.symm) (by simp) continuous_toFun := by fun_prop continuous_invFun := by fun_prop } theorem discreteTopology_fiber {x : X} (h : IsEvenlyCovered f x I) : DiscreteTopology (f ⁻¹' {x}) := have := h.1; h.fiberHomeomorph.discreteTopology /-- If `x` is evenly covered by `f` with nonempty fiber `I`, then we can construct a trivialization of `f` at `x` with fiber `I`. -/ noncomputable def toTrivialization' {x : X} [Nonempty I] (h : IsEvenlyCovered f x I) : Trivialization I f := by choose _ U hxU hU hfU H hH using h classical exact { toFun e := if he : f e ∈ U then ⟨(H ⟨e, he⟩).1, (H ⟨e, he⟩).2⟩ else ⟨x, Classical.arbitrary I⟩ invFun xi := H.symm (if hx : xi.1 ∈ U then ⟨xi.1, hx⟩ else ⟨x, hxU⟩, xi.2) source := f ⁻¹' U target := U ×ˢ Set.univ map_source' e (he : f e ∈ U) := by simp [he] map_target' _ _ := Subtype.coe_prop _ left_inv' e (he : f e ∈ U) := by simp [he] right_inv' xi := by rintro ⟨hx, -⟩; simpa [hx] using fun h ↦ (h (H.symm _).2).elim open_source := hfU open_target := hU.prod isOpen_univ continuousOn_toFun := continuousOn_iff_continuous_restrict.mpr <| ((continuous_subtype_val.prodMap continuous_id).comp H.continuous).congr fun ⟨e, (he : f e ∈ U)⟩ ↦ by simp [Prod.map, he] continuousOn_invFun := continuousOn_iff_continuous_restrict.mpr <| ((continuous_subtype_val.comp H.symm.continuous).comp (by fun_prop : Continuous fun ui ↦ ⟨⟨_, ui.2.1⟩, ui.1.2⟩)).congr fun ⟨⟨x, i⟩, ⟨hx, _⟩⟩ ↦ by simp [hx] baseSet := U open_baseSet := hU source_eq := rfl target_eq := rfl proj_toFun e (he : f e ∈ U) := by simp [he, hH] } /-- If `x` is evenly covered by `f`, then we can construct a trivialization of `f` at `x`. -/ noncomputable def toTrivialization {x : X} [Nonempty I] (h : IsEvenlyCovered f x I) : Trivialization (f ⁻¹' {x}) f := h.toTrivialization'.transFiberHomeomorph h.fiberHomeomorph theorem mem_toTrivialization_baseSet {x : X} [Nonempty I] (h : IsEvenlyCovered f x I) : x ∈ h.toTrivialization.baseSet := h.2.choose_spec.1 theorem toTrivialization_apply {x : E} [Nonempty I] (h : IsEvenlyCovered f (f x) I) : (h.toTrivialization x).2 = ⟨x, rfl⟩ := h.fiberHomeomorph.symm.injective <| by simp [toTrivialization, toTrivialization', dif_pos h.2.choose_spec.1, fiberHomeomorph] protected theorem continuousAt {x : E} (h : IsEvenlyCovered f (f x) I) : ContinuousAt f x := have ⟨_, _, hxU, _, _, H, _⟩ := h have : Nonempty I := ⟨(H ⟨x, hxU⟩).2⟩ let e := h.toTrivialization e.continuousAt_proj (e.mem_source.mpr (mem_toTrivialization_baseSet h)) theorem of_fiber_homeomorph {J} [TopologicalSpace J] (g : I ≃ₜ J) {x : X} (h : IsEvenlyCovered f x I) : IsEvenlyCovered f x J := have ⟨inst, U, hxU, hU, hfU, H, hH⟩ := h ⟨g.discreteTopology, U, hxU, hU, hfU, H.trans (.prodCongr (.refl U) g), fun _ ↦ by simp [hH]⟩ theorem to_isEvenlyCovered_preimage {x : X} (h : IsEvenlyCovered f x I) : IsEvenlyCovered f x (f ⁻¹' {x}) := h.of_fiber_homeomorph h.fiberHomeomorph theorem of_trivialization [DiscreteTopology I] {x : X} {t : Trivialization I f} (hx : x ∈ t.baseSet) : IsEvenlyCovered f x I := ⟨‹_›, _, hx, t.open_baseSet, t.source_eq ▸ t.open_source, { toFun e := ⟨⟨f e, e.2⟩, (t e).2⟩ invFun xi := ⟨t.invFun (xi.1, xi.2), by rw [Set.mem_preimage, ← t.mem_source]; exact t.map_target (t.target_eq ▸ ⟨xi.1.2, ⟨⟩⟩)⟩ left_inv e := Subtype.ext <| t.symm_apply_mk_proj (t.mem_source.mpr e.2) right_inv xi := by simp [t.proj_symm_apply', t.apply_symm_apply'] continuous_toFun := (Topology.IsInducing.subtypeVal.prodMap .id).continuous_iff.mpr <| (continuousOn_iff_continuous_restrict.mp <| t.continuousOn_toFun.mono t.source_eq.ge).congr fun e ↦ by simp [t.mk_proj_snd' e.2] continuous_invFun := Topology.IsInducing.subtypeVal.continuous_iff.mpr <| t.continuousOn_invFun.comp_continuous (continuous_subtype_val.prodMap continuous_id) fun ⟨x, _⟩ ↦ t.target_eq ▸ ⟨x.2, ⟨⟩⟩ }, fun _ ↦ by simp⟩ variable (I) in theorem of_preimage_eq_empty [IsEmpty I] {x : X} {U : Set X} (hUx : U ∈ 𝓝 x) (hfU : f ⁻¹' U = ∅) : IsEvenlyCovered f x I := have ⟨V, hVU, hV, hxV⟩ := mem_nhds_iff.mp hUx have hfV : f ⁻¹' V = ∅ := Set.eq_empty_of_subset_empty ((Set.preimage_mono hVU).trans hfU.le) have := Set.isEmpty_coe_sort.mpr hfV ⟨inferInstance, _, hxV, hV, hfV ▸ isOpen_empty, .empty, isEmptyElim⟩ end IsEvenlyCovered /-- A covering map is a continuous function `f : E → X` with discrete fibers such that each point of `X` has an evenly covered neighborhood. -/ def IsCoveringMapOn := ∀ x ∈ s, IsEvenlyCovered f x (f ⁻¹' {x}) namespace IsCoveringMapOn theorem of_isEmpty [IsEmpty E] : IsCoveringMapOn f s := fun _ _ ↦ .to_isEvenlyCovered_preimage (.of_preimage_eq_empty Empty Filter.univ_mem <| Set.eq_empty_of_isEmpty _) /-- A constructor for `IsCoveringMapOn` when there are both empty and nonempty fibers. -/ theorem mk' (F : s → Type*) [∀ x : s, TopologicalSpace (F x)] [hF : ∀ x : s, DiscreteTopology (F x)] (t : ∀ x : s, x.1 ∈ Set.range f → {t : Trivialization (F x) f // x.1 ∈ t.baseSet}) (h : ∀ x : s, x.1 ∉ Set.range f → ∃ U ∈ 𝓝 x.1, f ⁻¹' U = ∅) : IsCoveringMapOn f s := fun x hx ↦ by lift x to s using hx by_cases hxf : x.1 ∈ Set.range f · exact .to_isEvenlyCovered_preimage (.of_trivialization (t x hxf).2) · have ⟨U, hUx, hfU⟩ := h x hxf exact .to_isEvenlyCovered_preimage (.of_preimage_eq_empty Empty hUx hfU) theorem mk (F : s → Type*) [∀ x, TopologicalSpace (F x)] [hF : ∀ x, DiscreteTopology (F x)] (e : ∀ x, Trivialization (F x) f) (h : ∀ x, x.1 ∈ (e x).baseSet) : IsCoveringMapOn f s := by cases isEmpty_or_nonempty E · exact .of_isEmpty _ _ refine .mk' _ _ _ (fun x _ ↦ ⟨e x, h x⟩) fun x hx ↦ (hx ?_).elim exact ⟨(e x).invFun (x, (e x <| Classical.arbitrary E).2), (e x).proj_symm_apply' (h x)⟩ variable {f s} protected theorem continuousAt (hf : IsCoveringMapOn f s) {x : E} (hx : f x ∈ s) : ContinuousAt f x := (hf (f x) hx).continuousAt protected theorem continuousOn (hf : IsCoveringMapOn f s) : ContinuousOn f (f ⁻¹' s) := continuousOn_of_forall_continuousAt fun _ ↦ hf.continuousAt protected theorem isLocalHomeomorphOn (hf : IsCoveringMapOn f s) : IsLocalHomeomorphOn f (f ⁻¹' s) := by refine IsLocalHomeomorphOn.mk f (f ⁻¹' s) fun x hx ↦ ?_ have : Nonempty (f ⁻¹' {f x}) := ⟨⟨x, rfl⟩⟩ let e := (hf (f x) hx).toTrivialization have h := (hf (f x) hx).mem_toTrivialization_baseSet let he := e.mem_source.2 h refine ⟨e.toOpenPartialHomeomorph.trans { toFun := fun p => p.1 invFun := fun p => ⟨p, x, rfl⟩ source := e.baseSet ×ˢ ({⟨x, rfl⟩} : Set (f ⁻¹' {f x})) target := e.baseSet open_source := e.open_baseSet.prod (discreteTopology_iff_isOpen_singleton.1 (hf (f x) hx).1 ⟨x, rfl⟩) open_target := e.open_baseSet map_source' := fun p => And.left map_target' := fun p hp => ⟨hp, rfl⟩ left_inv' := fun p hp => Prod.ext rfl hp.2.symm right_inv' := fun p _ => rfl continuousOn_toFun := continuousOn_fst continuousOn_invFun := by fun_prop }, ⟨he, by rwa [e.toOpenPartialHomeomorph.symm_symm, e.proj_toFun x he], (hf (f x) hx).toTrivialization_apply⟩, fun p h => (e.proj_toFun p h.1).symm⟩ end IsCoveringMapOn /-- A covering map is a continuous function `f : E → X` with discrete fibers such that each point of `X` has an evenly covered neighborhood. -/ def IsCoveringMap := ∀ x, IsEvenlyCovered f x (f ⁻¹' {x}) variable {f} theorem isCoveringMap_iff_isCoveringMapOn_univ : IsCoveringMap f ↔ IsCoveringMapOn f Set.univ := by simp only [IsCoveringMap, IsCoveringMapOn, Set.mem_univ, forall_true_left] protected theorem IsCoveringMap.isCoveringMapOn (hf : IsCoveringMap f) : IsCoveringMapOn f Set.univ := isCoveringMap_iff_isCoveringMapOn_univ.mp hf variable (f) namespace IsCoveringMap theorem of_isEmpty [IsEmpty E] : IsCoveringMap f := isCoveringMap_iff_isCoveringMapOn_univ.mpr <| .of_isEmpty _ _ theorem of_discreteTopology [DiscreteTopology E] [DiscreteTopology X] : IsCoveringMap f := fun x ↦ ⟨inferInstance, {x}, rfl, isOpen_discrete _, isOpen_discrete _, { toFun e := ⟨⟨x, rfl⟩, e⟩ invFun xi := xi.2 left_inv _ := rfl right_inv _ := Prod.ext (Subsingleton.elim ..) rfl }, (·.2.symm)⟩ /-- A constructor for `IsCoveringMap` when there are both empty and nonempty fibers. -/ theorem mk' (F : X → Type*) [∀ x, TopologicalSpace (F x)] [∀ x, DiscreteTopology (F x)] (t : ∀ x, x ∈ Set.range f → {t : Trivialization (F x) f // x ∈ t.baseSet}) (h : IsClosed (Set.range f)) : IsCoveringMap f := isCoveringMap_iff_isCoveringMapOn_univ.mpr <| .mk' f _ _ (fun x h ↦ t x h) fun _x hx ↦ ⟨_, h.isOpen_compl.mem_nhds hx, Set.eq_empty_of_forall_notMem fun x h ↦ h ⟨x, rfl⟩⟩ theorem mk (F : X → Type*) [∀ x, TopologicalSpace (F x)] [∀ x, DiscreteTopology (F x)] (e : ∀ x, Trivialization (F x) f) (h : ∀ x, x ∈ (e x).baseSet) : IsCoveringMap f := isCoveringMap_iff_isCoveringMapOn_univ.mpr <| .mk _ _ _ _ fun x ↦ h x variable {f} variable (hf : IsCoveringMap f) include hf protected theorem continuous : Continuous f := continuousOn_univ.mp hf.isCoveringMapOn.continuousOn protected theorem isLocalHomeomorph : IsLocalHomeomorph f := isLocalHomeomorph_iff_isLocalHomeomorphOn_univ.mpr hf.isCoveringMapOn.isLocalHomeomorphOn protected theorem isOpenMap : IsOpenMap f := hf.isLocalHomeomorph.isOpenMap theorem isQuotientMap (hf' : Function.Surjective f) : IsQuotientMap f := hf.isOpenMap.isQuotientMap hf.continuous hf' protected theorem isSeparatedMap : IsSeparatedMap f := fun e₁ e₂ he hne ↦ by have : Nonempty (f ⁻¹' {f e₁}) := ⟨⟨e₁, rfl⟩⟩ specialize hf (f e₁) let t := hf.toTrivialization have := hf.discreteTopology_fiber have he₁ := hf.mem_toTrivialization_baseSet have he₂ := he₁; simp_rw [he] at he₂; rw [← t.mem_source] at he₁ he₂ refine ⟨t.source ∩ (Prod.snd ∘ t) ⁻¹' {(t e₁).2}, t.source ∩ (Prod.snd ∘ t) ⁻¹' {(t e₂).2}, ?_, ?_, ⟨he₁, rfl⟩, ⟨he₂, rfl⟩, Set.disjoint_left.mpr fun x h₁ h₂ ↦ hne (t.injOn he₁ he₂ ?_)⟩ iterate 2 exact t.continuousOn_toFun.isOpen_inter_preimage t.open_source (continuous_snd.isOpen_preimage _ <| isOpen_discrete _) refine Prod.ext ?_ (h₁.2.symm.trans h₂.2) rwa [t.proj_toFun e₁ he₁, t.proj_toFun e₂ he₂] variable {A} [TopologicalSpace A] {s : Set A} {g g₁ g₂ : A → E} /-- Proposition 1.34 of [hatcher02]. -/ theorem eq_of_comp_eq [PreconnectedSpace A] (h₁ : Continuous g₁) (h₂ : Continuous g₂) (he : f ∘ g₁ = f ∘ g₂) (a : A) (ha : g₁ a = g₂ a) : g₁ = g₂ := hf.isSeparatedMap.eq_of_comp_eq hf.isLocalHomeomorph.isLocallyInjective h₁ h₂ he a ha theorem const_of_comp [PreconnectedSpace A] (cont : Continuous g) (he : ∀ a a', f (g a) = f (g a')) (a a') : g a = g a' := hf.isSeparatedMap.const_of_comp hf.isLocalHomeomorph.isLocallyInjective cont he a a' theorem eqOn_of_comp_eqOn (hs : IsPreconnected s) (h₁ : ContinuousOn g₁ s) (h₂ : ContinuousOn g₂ s) (he : s.EqOn (f ∘ g₁) (f ∘ g₂)) {a : A} (has : a ∈ s) (ha : g₁ a = g₂ a) : s.EqOn g₁ g₂ := hf.isSeparatedMap.eqOn_of_comp_eqOn hf.isLocalHomeomorph.isLocallyInjective hs h₁ h₂ he has ha theorem constOn_of_comp (hs : IsPreconnected s) (cont : ContinuousOn g s) (he : ∀ a ∈ s, ∀ a' ∈ s, f (g a) = f (g a')) {a a'} (ha : a ∈ s) (ha' : a' ∈ s) : g a = g a' := hf.isSeparatedMap.constOn_of_comp hf.isLocalHomeomorph.isLocallyInjective hs cont he ha ha' end IsCoveringMap variable {f} protected theorem IsFiberBundle.isCoveringMap {F : Type*} [TopologicalSpace F] [DiscreteTopology F] (hf : ∀ x : X, ∃ e : Trivialization F f, x ∈ e.baseSet) : IsCoveringMap f := IsCoveringMap.mk f (fun _ => F) (fun x => Classical.choose (hf x)) fun x => Classical.choose_spec (hf x) protected theorem FiberBundle.isCoveringMap {F : Type*} {E : X → Type*} [TopologicalSpace F] [DiscreteTopology F] [TopologicalSpace (Bundle.TotalSpace F E)] [∀ x, TopologicalSpace (E x)] [FiberBundle F E] : IsCoveringMap (π F E) := IsFiberBundle.isCoveringMap fun x => ⟨trivializationAt F E x, mem_baseSet_trivializationAt F E x⟩
.lake/packages/mathlib/Mathlib/Topology/UrysohnsBounded.lean
import Mathlib.Topology.UrysohnsLemma import Mathlib.Topology.ContinuousMap.Bounded.Basic /-! # Urysohn's lemma for bounded continuous functions In this file we reformulate Urysohn's lemma `exists_continuous_zero_one_of_isClosed` in terms of bounded continuous functions `X →ᵇ ℝ`. These lemmas live in a separate file because `Topology.ContinuousMap.Bounded` imports too many other files. ## Tags Urysohn's lemma, normal topological space -/ open BoundedContinuousFunction open Set Function /-- **Urysohn's lemma**: if `s` and `t` are two disjoint closed sets in a normal topological space `X`, then there exists a continuous function `f : X → ℝ` such that * `f` equals zero on `s`; * `f` equals one on `t`; * `0 ≤ f x ≤ 1` for all `x`. -/ theorem exists_bounded_zero_one_of_closed {X : Type*} [TopologicalSpace X] [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : X →ᵇ ℝ, EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := let ⟨f, hfs, hft, hf⟩ := exists_continuous_zero_one_of_isClosed hs ht hd ⟨⟨f, 1, fun _ _ => Real.dist_le_of_mem_Icc_01 (hf _) (hf _)⟩, hfs, hft, hf⟩ /-- Urysohn's lemma: if `s` and `t` are two disjoint closed sets in a normal topological space `X`, and `a ≤ b` are two real numbers, then there exists a continuous function `f : X → ℝ` such that * `f` equals `a` on `s`; * `f` equals `b` on `t`; * `a ≤ f x ≤ b` for all `x`. -/ theorem exists_bounded_mem_Icc_of_closed_of_le {X : Type*} [TopologicalSpace X] [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) {a b : ℝ} (hle : a ≤ b) : ∃ f : X →ᵇ ℝ, EqOn f (Function.const X a) s ∧ EqOn f (Function.const X b) t ∧ ∀ x, f x ∈ Icc a b := let ⟨f, hfs, hft, hf01⟩ := exists_bounded_zero_one_of_closed hs ht hd ⟨BoundedContinuousFunction.const X a + (b - a) • f, fun x hx => by simp [hfs hx], fun x hx => by simp [hft hx], fun x => ⟨by dsimp; nlinarith [(hf01 x).1], by dsimp; nlinarith [(hf01 x).2]⟩⟩
.lake/packages/mathlib/Mathlib/Topology/UnitInterval.lean
import Mathlib.Algebra.Order.Interval.Set.Instances import Mathlib.Order.Interval.Set.ProjIcc import Mathlib.Topology.Algebra.Ring.Real /-! # The unit interval, as a topological space Use `open unitInterval` to turn on the notation `I := Set.Icc (0 : ℝ) (1 : ℝ)`. We provide basic instances, as well as a custom tactic for discharging `0 ≤ ↑x`, `0 ≤ 1 - ↑x`, `↑x ≤ 1`, and `1 - ↑x ≤ 1` when `x : I`. -/ noncomputable section open Topology Filter Set Int Set.Icc /-! ### The unit interval -/ /-- The unit interval `[0,1]` in ℝ. -/ abbrev unitInterval : Set ℝ := Set.Icc 0 1 @[inherit_doc] scoped[unitInterval] notation "I" => unitInterval namespace unitInterval theorem zero_mem : (0 : ℝ) ∈ I := ⟨le_rfl, zero_le_one⟩ theorem one_mem : (1 : ℝ) ∈ I := ⟨zero_le_one, le_rfl⟩ theorem mul_mem {x y : ℝ} (hx : x ∈ I) (hy : y ∈ I) : x * y ∈ I := ⟨mul_nonneg hx.1 hy.1, mul_le_one₀ hx.2 hy.1 hy.2⟩ theorem div_mem {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) (hxy : x ≤ y) : x / y ∈ I := ⟨div_nonneg hx hy, div_le_one_of_le₀ hxy hy⟩ theorem fract_mem (x : ℝ) : fract x ∈ I := ⟨fract_nonneg _, (fract_lt_one _).le⟩ @[deprecated (since := "2025-08-14")] alias mem_iff_one_sub_mem := Icc.mem_iff_one_sub_mem lemma univ_eq_Icc : (univ : Set I) = Icc (0 : I) (1 : I) := Icc_bot_top.symm @[norm_cast] theorem coe_ne_zero {x : I} : (x : ℝ) ≠ 0 ↔ x ≠ 0 := coe_eq_zero.not @[norm_cast] theorem coe_ne_one {x : I} : (x : ℝ) ≠ 1 ↔ x ≠ 1 := coe_eq_one.not @[simp, norm_cast] theorem coe_pos {x : I} : (0 : ℝ) < x ↔ 0 < x := Iff.rfl @[simp, norm_cast] theorem coe_lt_one {x : I} : (x : ℝ) < 1 ↔ x < 1 := Iff.rfl theorem mul_le_left {x y : I} : x * y ≤ x := Subtype.coe_le_coe.mp <| mul_le_of_le_one_right x.2.1 y.2.2 theorem mul_le_right {x y : I} : x * y ≤ y := Subtype.coe_le_coe.mp <| mul_le_of_le_one_left y.2.1 x.2.2 /-- Unit interval central symmetry. -/ def symm : I → I := fun t => ⟨1 - t, Icc.mem_iff_one_sub_mem.mp t.prop⟩ @[inherit_doc] scoped notation "σ" => unitInterval.symm @[simp] theorem symm_zero : σ 0 = 1 := Subtype.ext <| by simp [symm] @[simp] theorem symm_one : σ 1 = 0 := Subtype.ext <| by simp [symm] @[simp] theorem symm_symm (x : I) : σ (σ x) = x := Subtype.ext <| by simp [symm] theorem symm_involutive : Function.Involutive (symm : I → I) := symm_symm theorem symm_bijective : Function.Bijective (symm : I → I) := symm_involutive.bijective @[simp] theorem coe_symm_eq (x : I) : (σ x : ℝ) = 1 - x := rfl lemma image_coe_preimage_symm {s : Set I} : Subtype.val '' (σ ⁻¹' s) = (1 - ·) ⁻¹' (Subtype.val '' s) := by simp [symm_involutive, ← Function.Involutive.image_eq_preimage_symm, image_image] @[simp] theorem symm_projIcc (x : ℝ) : symm (projIcc 0 1 zero_le_one x) = projIcc 0 1 zero_le_one (1 - x) := by ext rcases le_total x 0 with h₀ | h₀ · simp [projIcc_of_le_left, projIcc_of_right_le, h₀] · rcases le_total x 1 with h₁ | h₁ · lift x to I using ⟨h₀, h₁⟩ simp_rw [← coe_symm_eq, projIcc_val] · simp [projIcc_of_le_left, projIcc_of_right_le, h₁] @[continuity, fun_prop] theorem continuous_symm : Continuous σ := Continuous.subtype_mk (by fun_prop) _ /-- `unitInterval.symm` as a `Homeomorph`. -/ @[simps] def symmHomeomorph : I ≃ₜ I where toFun := symm invFun := symm left_inv := symm_symm right_inv := symm_symm theorem strictAnti_symm : StrictAnti σ := fun _ _ h ↦ sub_lt_sub_left (α := ℝ) h _ @[simp] theorem symm_inj {i j : I} : σ i = σ j ↔ i = j := symm_bijective.injective.eq_iff theorem half_le_symm_iff (t : I) : 1 / 2 ≤ (σ t : ℝ) ↔ (t : ℝ) ≤ 1 / 2 := by rw [coe_symm_eq, le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le, sub_half] @[simp] lemma symm_eq_one {i : I} : σ i = 1 ↔ i = 0 := by rw [← symm_zero, symm_inj] @[simp] lemma symm_eq_zero {i : I} : σ i = 0 ↔ i = 1 := by rw [← symm_one, symm_inj] @[simp] theorem symm_le_symm {i j : I} : σ i ≤ σ j ↔ j ≤ i := by simp only [symm, Subtype.mk_le_mk, sub_le_sub_iff, add_le_add_iff_left, Subtype.coe_le_coe] theorem le_symm_comm {i j : I} : i ≤ σ j ↔ j ≤ σ i := by rw [← symm_le_symm, symm_symm] theorem symm_le_comm {i j : I} : σ i ≤ j ↔ σ j ≤ i := by rw [← symm_le_symm, symm_symm] @[simp] theorem symm_lt_symm {i j : I} : σ i < σ j ↔ j < i := by simp only [symm, Subtype.mk_lt_mk, sub_lt_sub_iff_left, Subtype.coe_lt_coe] theorem lt_symm_comm {i j : I} : i < σ j ↔ j < σ i := by rw [← symm_lt_symm, symm_symm] theorem symm_lt_comm {i j : I} : σ i < j ↔ σ j < i := by rw [← symm_lt_symm, symm_symm] instance : ConnectedSpace I := Subtype.connectedSpace ⟨nonempty_Icc.mpr zero_le_one, isPreconnected_Icc⟩ /-- Verify there is an instance for `CompactSpace I`. -/ example : CompactSpace I := by infer_instance theorem nonneg (x : I) : 0 ≤ (x : ℝ) := x.2.1 theorem one_minus_nonneg (x : I) : 0 ≤ 1 - (x : ℝ) := by simpa using x.2.2 theorem le_one (x : I) : (x : ℝ) ≤ 1 := x.2.2 theorem one_minus_le_one (x : I) : 1 - (x : ℝ) ≤ 1 := by simpa using x.2.1 theorem add_pos {t : I} {x : ℝ} (hx : 0 < x) : 0 < (x + t : ℝ) := add_pos_of_pos_of_nonneg hx <| nonneg _ /-- like `unitInterval.nonneg`, but with the inequality in `I`. -/ theorem nonneg' {t : I} : 0 ≤ t := t.2.1 /-- like `unitInterval.le_one`, but with the inequality in `I`. -/ theorem le_one' {t : I} : t ≤ 1 := t.2.2 protected lemma pos_iff_ne_zero {x : I} : 0 < x ↔ x ≠ 0 := bot_lt_iff_ne_bot protected lemma lt_one_iff_ne_one {x : I} : x < 1 ↔ x ≠ 1 := lt_top_iff_ne_top lemma eq_one_or_eq_zero_of_le_mul {i j : I} (h : i ≤ j * i) : i = 0 ∨ j = 1 := by contrapose! h rw [← unitInterval.lt_one_iff_ne_one, ← coe_lt_one, ← unitInterval.pos_iff_ne_zero, ← coe_pos] at h rw [← Subtype.coe_lt_coe, coe_mul] simpa using mul_lt_mul_of_pos_right h.right h.left instance : Nontrivial I := ⟨⟨1, 0, (one_ne_zero <| congrArg Subtype.val ·)⟩⟩ theorem mul_pos_mem_iff {a t : ℝ} (ha : 0 < a) : a * t ∈ I ↔ t ∈ Set.Icc (0 : ℝ) (1 / a) := by constructor <;> rintro ⟨h₁, h₂⟩ <;> constructor · exact nonneg_of_mul_nonneg_right h₁ ha · rwa [le_div_iff₀ ha, mul_comm] · exact mul_nonneg ha.le h₁ · rwa [le_div_iff₀ ha, mul_comm] at h₂ theorem two_mul_sub_one_mem_iff {t : ℝ} : 2 * t - 1 ∈ I ↔ t ∈ Set.Icc (1 / 2 : ℝ) 1 := by constructor <;> rintro ⟨h₁, h₂⟩ <;> constructor <;> linarith /-- The unit interval as a submonoid of ℝ. -/ def submonoid : Submonoid ℝ where carrier := unitInterval one_mem' := unitInterval.one_mem mul_mem' := unitInterval.mul_mem @[simp] theorem coe_unitIntervalSubmonoid : submonoid = unitInterval := rfl @[simp] theorem mem_unitIntervalSubmonoid {x} : x ∈ submonoid ↔ x ∈ unitInterval := Iff.rfl protected theorem prod_mem {ι : Type*} {t : Finset ι} {f : ι → ℝ} (h : ∀ c ∈ t, f c ∈ unitInterval) : ∏ c ∈ t, f c ∈ unitInterval := _root_.prod_mem (S := unitInterval.submonoid) h instance : LinearOrderedCommMonoidWithZero I where zero_mul i := zero_mul i mul_zero i := mul_zero i zero_le_one := nonneg' mul_le_mul_left i j h_ij k := by simp only [← Subtype.coe_le_coe, coe_mul]; gcongr; exact nonneg k lemma subtype_Iic_eq_Icc (x : I) : Subtype.val⁻¹' (Iic ↑x) = Icc 0 x := by rw [preimage_subtype_val_Iic] exact Icc_bot.symm lemma subtype_Iio_eq_Ico (x : I) : Subtype.val⁻¹' (Iio ↑x) = Ico 0 x := by rw [preimage_subtype_val_Iio] exact Ico_bot.symm lemma subtype_Ici_eq_Icc (x : I) : Subtype.val⁻¹' (Ici ↑x) = Icc x 1 := by rw [preimage_subtype_val_Ici] exact Icc_top.symm lemma subtype_Ioi_eq_Ioc (x : I) : Subtype.val⁻¹' (Ioi ↑x) = Ioc x 1 := by rw [preimage_subtype_val_Ioi] exact Ioc_top.symm end unitInterval section partition namespace Set.Icc variable {α} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] {a b c d : α} (h : a ≤ b) {δ : α} -- TODO: Set.projIci, Set.projIic /-- `Set.projIcc` is a contraction. -/ lemma _root_.Set.abs_projIcc_sub_projIcc : (|projIcc a b h c - projIcc a b h d| : α) ≤ |c - d| := by wlog hdc : d ≤ c generalizing c d · rw [abs_sub_comm, abs_sub_comm c]; exact this (le_of_not_ge hdc) rw [abs_eq_self.2 (sub_nonneg.2 hdc), abs_eq_self.2 (sub_nonneg.2 <| mod_cast monotone_projIcc h hdc)] rw [← sub_nonneg] at hdc refine (max_sub_max_le_max _ _ _ _).trans (max_le (by rwa [sub_self]) ?_) refine ((le_abs_self _).trans <| abs_min_sub_min_le_max _ _ _ _).trans (max_le ?_ ?_) · rwa [sub_self, abs_zero] · exact (abs_eq_self.mpr hdc).le /-- When `h : a ≤ b` and `δ > 0`, `addNSMul h δ` is a sequence of points in the closed interval `[a,b]`, which is initially equally spaced but eventually stays at the right endpoint `b`. -/ def addNSMul (δ : α) (n : ℕ) : Icc a b := projIcc a b h (a + n • δ) omit [IsOrderedAddMonoid α] in lemma addNSMul_zero : addNSMul h δ 0 = a := by rw [addNSMul, zero_smul, add_zero, projIcc_left] lemma addNSMul_eq_right [Archimedean α] (hδ : 0 < δ) : ∃ m, ∀ n ≥ m, addNSMul h δ n = b := by obtain ⟨m, hm⟩ := Archimedean.arch (b - a) hδ refine ⟨m, fun n hn ↦ ?_⟩ rw [addNSMul, coe_projIcc, add_comm, min_eq_left_iff.mpr, max_eq_right h] exact sub_le_iff_le_add.mp (hm.trans <| nsmul_le_nsmul_left hδ.le hn) lemma monotone_addNSMul (hδ : 0 ≤ δ) : Monotone (addNSMul h δ) := fun _ _ hnm ↦ monotone_projIcc h <| (add_le_add_iff_left _).mpr (nsmul_le_nsmul_left hδ hnm) lemma abs_sub_addNSMul_le (hδ : 0 ≤ δ) {t : Icc a b} (n : ℕ) (ht : t ∈ Icc (addNSMul h δ n) (addNSMul h δ (n + 1))) : (|t - addNSMul h δ n| : α) ≤ δ := calc (|t - addNSMul h δ n| : α) = t - addNSMul h δ n := abs_eq_self.2 <| sub_nonneg.2 ht.1 _ ≤ projIcc a b h (a + (n + 1) • δ) - addNSMul h δ n := by apply sub_le_sub_right; exact ht.2 _ ≤ (|projIcc a b h (a + (n + 1) • δ) - addNSMul h δ n| : α) := le_abs_self _ _ ≤ |a + (n + 1) • δ - (a + n • δ)| := abs_projIcc_sub_projIcc h _ ≤ δ := by rw [add_sub_add_comm, sub_self, zero_add, succ_nsmul', add_sub_cancel_right] exact (abs_eq_self.mpr hδ).le end Set.Icc open scoped unitInterval /-- Any open cover `c` of a closed interval `[a, b]` in ℝ can be refined to a finite partition into subintervals. -/ lemma exists_monotone_Icc_subset_open_cover_Icc {ι} {a b : ℝ} (h : a ≤ b) {c : ι → Set (Icc a b)} (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : univ ⊆ ⋃ i, c i) : ∃ t : ℕ → Icc a b, t 0 = a ∧ Monotone t ∧ (∃ m, ∀ n ≥ m, t n = b) ∧ ∀ n, ∃ i, Icc (t n) (t (n + 1)) ⊆ c i := by obtain ⟨δ, δ_pos, ball_subset⟩ := lebesgue_number_lemma_of_metric isCompact_univ hc₁ hc₂ have hδ := half_pos δ_pos refine ⟨addNSMul h (δ/2), addNSMul_zero h, monotone_addNSMul h hδ.le, addNSMul_eq_right h hδ, fun n ↦ ?_⟩ obtain ⟨i, hsub⟩ := ball_subset (addNSMul h (δ/2) n) trivial exact ⟨i, fun t ht ↦ hsub ((abs_sub_addNSMul_le h hδ.le n ht).trans_lt <| half_lt_self δ_pos)⟩ /-- Any open cover of the unit interval can be refined to a finite partition into subintervals. -/ lemma exists_monotone_Icc_subset_open_cover_unitInterval {ι} {c : ι → Set I} (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : univ ⊆ ⋃ i, c i) : ∃ t : ℕ → I, t 0 = 0 ∧ Monotone t ∧ (∃ n, ∀ m ≥ n, t m = 1) ∧ ∀ n, ∃ i, Icc (t n) (t (n + 1)) ⊆ c i := by simp_rw [← Subtype.coe_inj] exact exists_monotone_Icc_subset_open_cover_Icc zero_le_one hc₁ hc₂ lemma exists_monotone_Icc_subset_open_cover_unitInterval_prod_self {ι} {c : ι → Set (I × I)} (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : univ ⊆ ⋃ i, c i) : ∃ t : ℕ → I, t 0 = 0 ∧ Monotone t ∧ (∃ n, ∀ m ≥ n, t m = 1) ∧ ∀ n m, ∃ i, Icc (t n) (t (n + 1)) ×ˢ Icc (t m) (t (m + 1)) ⊆ c i := by obtain ⟨δ, δ_pos, ball_subset⟩ := lebesgue_number_lemma_of_metric isCompact_univ hc₁ hc₂ have hδ := half_pos δ_pos simp_rw [Subtype.ext_iff] have h : (0 : ℝ) ≤ 1 := zero_le_one refine ⟨addNSMul h (δ/2), addNSMul_zero h, monotone_addNSMul h hδ.le, addNSMul_eq_right h hδ, fun n m ↦ ?_⟩ obtain ⟨i, hsub⟩ := ball_subset (addNSMul h (δ/2) n, addNSMul h (δ/2) m) trivial exact ⟨i, fun t ht ↦ hsub (Metric.mem_ball.mpr <| (max_le (abs_sub_addNSMul_le h hδ.le n ht.1) <| abs_sub_addNSMul_le h hδ.le m ht.2).trans_lt <| half_lt_self δ_pos)⟩ end partition @[simp] theorem projIcc_eq_zero {x : ℝ} : projIcc (0 : ℝ) 1 zero_le_one x = 0 ↔ x ≤ 0 := projIcc_eq_left zero_lt_one @[simp] theorem projIcc_eq_one {x : ℝ} : projIcc (0 : ℝ) 1 zero_le_one x = 1 ↔ 1 ≤ x := projIcc_eq_right zero_lt_one namespace Tactic.Interactive /-- A tactic that solves `0 ≤ ↑x`, `0 ≤ 1 - ↑x`, `↑x ≤ 1`, and `1 - ↑x ≤ 1` for `x : I`. -/ macro "unit_interval" : tactic => `(tactic| (first | apply unitInterval.nonneg | apply unitInterval.one_minus_nonneg | apply unitInterval.le_one | apply unitInterval.one_minus_le_one)) example (x : unitInterval) : 0 ≤ (x : ℝ) := by unit_interval end Tactic.Interactive section variable {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [TopologicalSpace 𝕜] [IsTopologicalRing 𝕜] -- We only need the ordering on `𝕜` here to avoid talking about flipping the interval over. -- At the end of the day I only care about `ℝ`, so I'm hesitant to put work into generalizing. /-- The image of `[0,1]` under the homeomorphism `fun x ↦ a * x + b` is `[b, a+b]`. -/ theorem affineHomeomorph_image_I (a b : 𝕜) (h : 0 < a) : affineHomeomorph a b h.ne.symm '' Set.Icc 0 1 = Set.Icc b (a + b) := by simp [h] /-- The affine homeomorphism from a nontrivial interval `[a,b]` to `[0,1]`. -/ def iccHomeoI (a b : 𝕜) (h : a < b) : Set.Icc a b ≃ₜ Set.Icc (0 : 𝕜) (1 : 𝕜) := by let e := Homeomorph.image (affineHomeomorph (b - a) a (sub_pos.mpr h).ne.symm) (Set.Icc 0 1) refine (e.trans ?_).symm apply Homeomorph.setCongr rw [affineHomeomorph_image_I _ _ (sub_pos.2 h)] simp @[simp] theorem iccHomeoI_apply_coe (a b : 𝕜) (h : a < b) (x : Set.Icc a b) : ((iccHomeoI a b h) x : 𝕜) = (x - a) / (b - a) := rfl @[simp] theorem iccHomeoI_symm_apply_coe (a b : 𝕜) (h : a < b) (x : Set.Icc (0 : 𝕜) (1 : 𝕜)) : ((iccHomeoI a b h).symm x : 𝕜) = (b - a) * x + a := rfl end namespace unitInterval open NNReal /-- The coercion from `I` to `ℝ≥0`. -/ def toNNReal : I → ℝ≥0 := fun i ↦ ⟨i.1, i.2.1⟩ @[simp] lemma toNNReal_zero : toNNReal 0 = 0 := rfl @[simp] lemma toNNReal_one : toNNReal 1 = 1 := rfl @[fun_prop] lemma toNNReal_continuous : Continuous toNNReal := by delta toNNReal; fun_prop @[simp] lemma coe_toNNReal (x : I) : ((toNNReal x) : ℝ) = x := rfl @[simp] lemma toNNReal_add_toNNReal_symm (x : I) : toNNReal x + toNNReal (σ x) = 1 := by ext; simp @[simp] lemma toNNReal_symm_add_toNNReal (x : I) : toNNReal (σ x) + toNNReal x = 1 := by ext; simp end unitInterval
.lake/packages/mathlib/Mathlib/Topology/CompactOpen.lean
import Mathlib.Topology.Hom.ContinuousEval import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Topology.Separation.Regular /-! # The compact-open topology In this file, we define the compact-open topology on the set of continuous maps between two topological spaces. ## Main definitions * `ContinuousMap.compactOpen` is the compact-open topology on `C(X, Y)`. It is declared as an instance. * `ContinuousMap.coev` is the coevaluation map `Y → C(X, Y × X)`. It is always continuous. * `ContinuousMap.curry` is the currying map `C(X × Y, Z) → C(X, C(Y, Z))`. This map always exists and it is continuous as long as `X × Y` is locally compact. * `ContinuousMap.uncurry` is the uncurrying map `C(X, C(Y, Z)) → C(X × Y, Z)`. For this map to exist, we need `Y` to be locally compact. If `X` is also locally compact, then this map is continuous. * `Homeomorph.curry` combines the currying and uncurrying operations into a homeomorphism `C(X × Y, Z) ≃ₜ C(X, C(Y, Z))`. This homeomorphism exists if `X` and `Y` are locally compact. ## Tags compact-open, curry, function space -/ open Set Filter TopologicalSpace Topology namespace ContinuousMap section CompactOpen variable {α X Y Z T : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace T] variable {K : Set X} {U : Set Y} /-- The compact-open topology on the space of continuous maps `C(X, Y)`. -/ instance compactOpen : TopologicalSpace C(X, Y) := .generateFrom <| image2 (fun K U ↦ {f | MapsTo f K U}) {K | IsCompact K} {U | IsOpen U} /-- Definition of `ContinuousMap.compactOpen`. -/ theorem compactOpen_eq : @compactOpen X Y _ _ = .generateFrom (image2 (fun K U ↦ {f | MapsTo f K U}) {K | IsCompact K} {t | IsOpen t}) := rfl theorem isOpen_setOf_mapsTo (hK : IsCompact K) (hU : IsOpen U) : IsOpen {f : C(X, Y) | MapsTo f K U} := isOpen_generateFrom_of_mem <| mem_image2_of_mem hK hU lemma eventually_mapsTo {f : C(X, Y)} (hK : IsCompact K) (hU : IsOpen U) (h : MapsTo f K U) : ∀ᶠ g : C(X, Y) in 𝓝 f, MapsTo g K U := (isOpen_setOf_mapsTo hK hU).mem_nhds h lemma nhds_compactOpen (f : C(X, Y)) : 𝓝 f = ⨅ (K : Set X) (_ : IsCompact K) (U : Set Y) (_ : IsOpen U) (_ : MapsTo f K U), 𝓟 {g : C(X, Y) | MapsTo g K U} := by simp_rw [compactOpen_eq, nhds_generateFrom, mem_setOf_eq, @and_comm (f ∈ _), iInf_and, ← image_prod, iInf_image, biInf_prod, mem_setOf_eq] lemma tendsto_nhds_compactOpen {l : Filter α} {f : α → C(Y, Z)} {g : C(Y, Z)} : Tendsto f l (𝓝 g) ↔ ∀ K, IsCompact K → ∀ U, IsOpen U → MapsTo g K U → ∀ᶠ a in l, MapsTo (f a) K U := by simp [nhds_compactOpen] lemma continuous_compactOpen {f : X → C(Y, Z)} : Continuous f ↔ ∀ K, IsCompact K → ∀ U, IsOpen U → IsOpen {x | MapsTo (f x) K U} := continuous_generateFrom_iff.trans forall_mem_image2 protected lemma hasBasis_nhds (f : C(X, Y)) : (𝓝 f).HasBasis (fun S : Set (Set X × Set Y) ↦ S.Finite ∧ ∀ K U, (K, U) ∈ S → IsCompact K ∧ IsOpen U ∧ MapsTo f K U) (⋂ KU ∈ ·, {g : C(X, Y) | MapsTo g KU.1 KU.2}) := by refine ⟨fun s ↦ ?_⟩ simp_rw [nhds_compactOpen, iInf_comm.{_, 0, _ + 1}, iInf_prod', iInf_and'] simp [mem_biInf_principal, and_assoc] protected lemma mem_nhds_iff {f : C(X, Y)} {s : Set C(X, Y)} : s ∈ 𝓝 f ↔ ∃ S : Set (Set X × Set Y), S.Finite ∧ (∀ K U, (K, U) ∈ S → IsCompact K ∧ IsOpen U ∧ MapsTo f K U) ∧ {g : C(X, Y) | ∀ K U, (K, U) ∈ S → MapsTo g K U} ⊆ s := by simp [f.hasBasis_nhds.mem_iff, ← setOf_forall, and_assoc] lemma _root_.Filter.HasBasis.nhds_continuousMapConst {ι : Type*} {c : Y} {p : ι → Prop} {U : ι → Set Y} (h : (𝓝 c).HasBasis p U) : (𝓝 (const X c)).HasBasis (fun Ki : Set X × ι ↦ IsCompact Ki.1 ∧ p Ki.2) fun Ki ↦ {f : C(X, Y) | MapsTo f Ki.1 (U Ki.2)} := by refine ⟨fun s ↦ ⟨fun hs ↦ ?_, fun hs ↦ ?_⟩⟩ · rcases ContinuousMap.mem_nhds_iff.mp hs with ⟨S, hSf, hS, hSsub⟩ choose hScompact hSopen hSmaps using hS have : ⋂ KU ∈ S, ⋂ (_ : KU.1.Nonempty), KU.2 ∈ 𝓝 c := by simp only [biInter_mem hSf, Prod.forall, iInter_mem] rintro K U hKU ⟨x, hx⟩ exact (hSopen K U hKU).mem_nhds <| hSmaps K U hKU hx rcases h.mem_iff.mp this with ⟨i, hpi, hi⟩ refine ⟨(⋃ KU ∈ S, KU.1, i), ⟨hSf.isCompact_biUnion <| Prod.forall.2 hScompact, hpi⟩, Subset.trans ?_ hSsub⟩ intro f hf K V hKV rcases K.eq_empty_or_nonempty with rfl | hKne · exact mapsTo_empty _ _ · refine hf.out.mono (subset_biUnion_of_mem (u := Prod.fst) hKV) (hi.trans ?_) exact (biInter_subset_of_mem hKV).trans <| iInter_subset _ hKne · rcases hs with ⟨⟨K, i⟩, ⟨hK, hpi⟩, hi⟩ filter_upwards [eventually_mapsTo hK isOpen_interior fun x _ ↦ mem_interior_iff_mem_nhds.mpr <| h.mem_of_mem hpi] with f hf exact hi <| hf.mono_right interior_subset section Functorial /-- `C(X, ·)` is a functor. -/ theorem continuous_postcomp (g : C(Y, Z)) : Continuous (ContinuousMap.comp g : C(X, Y) → C(X, Z)) := continuous_compactOpen.2 fun _K hK _U hU ↦ isOpen_setOf_mapsTo hK (hU.preimage g.2) /-- If `g : C(Y, Z)` is a topology inducing map, then the composition `ContinuousMap.comp g : C(X, Y) → C(X, Z)` is a topology inducing map too. -/ theorem isInducing_postcomp (g : C(Y, Z)) (hg : IsInducing g) : IsInducing (g.comp : C(X, Y) → C(X, Z)) where eq_induced := by simp only [compactOpen_eq, induced_generateFrom_eq, image_image2, hg.setOf_isOpen, image2_image_right, MapsTo, mem_preimage, preimage_setOf_eq, comp_apply] /-- If `g : C(Y, Z)` is a topological embedding, then the composition `ContinuousMap.comp g : C(X, Y) → C(X, Z)` is an embedding too. -/ theorem isEmbedding_postcomp (g : C(Y, Z)) (hg : IsEmbedding g) : IsEmbedding (g.comp : C(X, Y) → C(X, Z)) := ⟨isInducing_postcomp g hg.1, fun _ _ ↦ (cancel_left hg.2).1⟩ /-- `C(·, Z)` is a functor. -/ @[continuity, fun_prop] theorem continuous_precomp (f : C(X, Y)) : Continuous (fun g => g.comp f : C(Y, Z) → C(X, Z)) := continuous_compactOpen.2 fun K hK U hU ↦ by simpa only [mapsTo_image_iff] using isOpen_setOf_mapsTo (hK.image f.2) hU variable (Z) in /-- Precomposition by a continuous map is itself a continuous map between spaces of continuous maps. -/ @[simps apply] def compRightContinuousMap (f : C(X, Y)) : C(C(Y, Z), C(X, Z)) where toFun g := g.comp f /-- Any pair of homeomorphisms `X ≃ₜ Z` and `Y ≃ₜ T` gives rise to a homeomorphism `C(X, Y) ≃ₜ C(Z, T)`. -/ protected def _root_.Homeomorph.arrowCongr (φ : X ≃ₜ Z) (ψ : Y ≃ₜ T) : C(X, Y) ≃ₜ C(Z, T) where toFun f := .comp ψ <| f.comp φ.symm invFun f := .comp ψ.symm <| f.comp φ left_inv f := ext fun _ ↦ ψ.left_inv (f _) |>.trans <| congrArg f <| φ.left_inv _ right_inv f := ext fun _ ↦ ψ.right_inv (f _) |>.trans <| congrArg f <| φ.right_inv _ continuous_toFun := continuous_postcomp _ |>.comp <| continuous_precomp _ continuous_invFun := continuous_postcomp _ |>.comp <| continuous_precomp _ /-- The map from `X × C(Y, Z)` to `C(Y, X × Z)` is continuous. -/ lemma continuous_prodMk_const : Continuous fun p : X × C(Y, Z) ↦ prodMk (const Y p.1) p.2 := by simp_rw [continuous_iff_continuousAt, ContinuousAt, ContinuousMap.tendsto_nhds_compactOpen] rintro ⟨r, f⟩ K hK U hU H obtain ⟨V, W, hV, hW, hrV, hKW, hVW⟩ := generalized_tube_lemma (isCompact_singleton (x := r)) (hK.image f.continuous) hU (by simpa [Set.subset_def, forall_comm (α := X)]) refine Filter.eventually_of_mem (prod_mem_nhds (hV.mem_nhds (by simpa using hrV)) (ContinuousMap.eventually_mapsTo hK hW (Set.mapsTo_iff_image_subset.mpr hKW))) ?_ rintro ⟨r', f'⟩ ⟨hr'V, hf'⟩ x hxK exact hVW (Set.mk_mem_prod hr'V (hf' hxK)) variable [LocallyCompactPair Y Z] /-- Composition is a continuous map from `C(X, Y) × C(Y, Z)` to `C(X, Z)`, provided that `Y` is locally compact. This is Prop. 9 of Chap. X, §3, №. 4 of Bourbaki's *Topologie Générale*. -/ theorem continuous_comp' : Continuous fun x : C(X, Y) × C(Y, Z) => x.2.comp x.1 := by simp_rw [continuous_iff_continuousAt, ContinuousAt, tendsto_nhds_compactOpen] intro ⟨f, g⟩ K hK U hU (hKU : MapsTo (g ∘ f) K U) obtain ⟨L, hKL, hLc, hLU⟩ : ∃ L ∈ 𝓝ˢ (f '' K), IsCompact L ∧ MapsTo g L U := exists_mem_nhdsSet_isCompact_mapsTo g.continuous (hK.image f.continuous) hU (mapsTo_image_iff.2 hKU) rw [← subset_interior_iff_mem_nhdsSet, ← mapsTo_iff_image_subset] at hKL exact ((eventually_mapsTo hK isOpen_interior hKL).prod_nhds (eventually_mapsTo hLc hU hLU)).mono fun ⟨f', g'⟩ ⟨hf', hg'⟩ ↦ hg'.comp <| hf'.mono_right interior_subset lemma _root_.Filter.Tendsto.compCM {α : Type*} {l : Filter α} {g : α → C(Y, Z)} {g₀ : C(Y, Z)} {f : α → C(X, Y)} {f₀ : C(X, Y)} (hg : Tendsto g l (𝓝 g₀)) (hf : Tendsto f l (𝓝 f₀)) : Tendsto (fun a ↦ (g a).comp (f a)) l (𝓝 (g₀.comp f₀)) := (continuous_comp'.tendsto (f₀, g₀)).comp (hf.prodMk_nhds hg) variable {X' : Type*} [TopologicalSpace X'] {a : X'} {g : X' → C(Y, Z)} {f : X' → C(X, Y)} {s : Set X'} nonrec lemma _root_.ContinuousAt.compCM (hg : ContinuousAt g a) (hf : ContinuousAt f a) : ContinuousAt (fun x ↦ (g x).comp (f x)) a := hg.compCM hf nonrec lemma _root_.ContinuousWithinAt.compCM (hg : ContinuousWithinAt g s a) (hf : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x ↦ (g x).comp (f x)) s a := hg.compCM hf lemma _root_.ContinuousOn.compCM (hg : ContinuousOn g s) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ (g x).comp (f x)) s := fun a ha ↦ (hg a ha).compCM (hf a ha) lemma _root_.Continuous.compCM (hg : Continuous g) (hf : Continuous f) : Continuous fun x => (g x).comp (f x) := continuous_comp'.comp (hf.prodMk hg) end Functorial section Ev /-- The evaluation map `C(X, Y) × X → Y` is continuous if `X, Y` is a locally compact pair of spaces. -/ instance [LocallyCompactPair X Y] : ContinuousEval C(X, Y) X Y where continuous_eval := by simp_rw [continuous_iff_continuousAt, ContinuousAt, (nhds_basis_opens _).tendsto_right_iff] rintro ⟨f, x⟩ U ⟨hx : f x ∈ U, hU : IsOpen U⟩ rcases exists_mem_nhds_isCompact_mapsTo f.continuous (hU.mem_nhds hx) with ⟨K, hxK, hK, hKU⟩ filter_upwards [prod_mem_nhds (eventually_mapsTo hK hU hKU) hxK] using fun _ h ↦ h.1 h.2 instance : ContinuousEvalConst C(X, Y) X Y where continuous_eval_const x := continuous_def.2 fun U hU ↦ by simpa using isOpen_setOf_mapsTo isCompact_singleton hU lemma isClosed_setOf_mapsTo {t : Set Y} (ht : IsClosed t) (s : Set X) : IsClosed {f : C(X, Y) | MapsTo f s t} := ht.setOf_mapsTo fun _ _ ↦ continuous_eval_const _ lemma isClopen_setOf_mapsTo (hK : IsCompact K) (hU : IsClopen U) : IsClopen {f : C(X, Y) | MapsTo f K U} := ⟨isClosed_setOf_mapsTo hU.isClosed K, isOpen_setOf_mapsTo hK hU.isOpen⟩ @[norm_cast] lemma specializes_coe {f g : C(X, Y)} : ⇑f ⤳ ⇑g ↔ f ⤳ g := by refine ⟨fun h ↦ ?_, fun h ↦ h.map continuous_coeFun⟩ suffices ∀ K, IsCompact K → ∀ U, IsOpen U → MapsTo g K U → MapsTo f K U by simpa [specializes_iff_pure, nhds_compactOpen] exact fun K _ U hU hg x hx ↦ (h.map (continuous_apply x)).mem_open hU (hg hx) @[norm_cast] lemma inseparable_coe {f g : C(X, Y)} : Inseparable (f : X → Y) g ↔ Inseparable f g := by simp only [inseparable_iff_specializes_and, specializes_coe] instance [T0Space Y] : T0Space C(X, Y) := t0Space_of_injective_of_continuous DFunLike.coe_injective continuous_coeFun instance [R0Space Y] : R0Space C(X, Y) where specializes_symmetric f g h := by rw [← specializes_coe] at h ⊢ exact h.symm instance [T1Space Y] : T1Space C(X, Y) := t1Space_of_injective_of_continuous DFunLike.coe_injective continuous_coeFun instance [R1Space Y] : R1Space C(X, Y) := .of_continuous_specializes_imp continuous_coeFun fun _ _ ↦ specializes_coe.1 instance [T2Space Y] : T2Space C(X, Y) := inferInstance instance [RegularSpace Y] : RegularSpace C(X, Y) := .of_lift'_closure_le fun f ↦ by rw [← tendsto_id', tendsto_nhds_compactOpen] intro K hK U hU hf rcases (hK.image f.continuous).exists_isOpen_closure_subset (hU.mem_nhdsSet.2 hf.image_subset) with ⟨V, hVo, hKV, hVU⟩ filter_upwards [mem_lift' (eventually_mapsTo hK hVo (mapsTo_iff_image_subset.2 hKV))] with g hg refine ((isClosed_setOf_mapsTo isClosed_closure K).closure_subset ?_).mono_right hVU exact closure_mono (fun _ h ↦ h.mono_right subset_closure) hg instance [T3Space Y] : T3Space C(X, Y) := inferInstance end Ev section DiscreteTopology variable [DiscreteTopology X] /-- The continuous functions from `X` to `Y` are the same as the plain functions when `X` is discrete. -/ @[simps toEquiv] def homeoFnOfDiscrete : C(X, Y) ≃ₜ (X → Y) where __ := equivFnOfDiscrete continuous_invFun := continuous_compactOpen.2 fun K hK U hU ↦ isOpen_set_pi hK.finite_of_discrete fun _ _ ↦ hU attribute [simps! -isSimp] homeoFnOfDiscrete @[simp] lemma coe_homeoFnOfDiscrete : ⇑homeoFnOfDiscrete = (DFunLike.coe : C(X, Y) → X → Y) := rfl @[simp] lemma homeoFnOfDiscrete_symm_apply (f : X → Y) : homeoFnOfDiscrete.symm f = f := rfl lemma isHomeomorph_coe : IsHomeomorph ((⇑) : C(X, Y) → X → Y) := homeoFnOfDiscrete.isHomeomorph end DiscreteTopology section InfInduced /-- For any subset `s` of `X`, the restriction of continuous functions to `s` is continuous as a function from `C(X, Y)` to `C(s, Y)` with their respective compact-open topologies. -/ theorem continuous_restrict (s : Set X) : Continuous fun F : C(X, Y) => F.restrict s := continuous_precomp <| restrict s <| .id X theorem compactOpen_le_induced (s : Set X) : (ContinuousMap.compactOpen : TopologicalSpace C(X, Y)) ≤ .induced (restrict s) ContinuousMap.compactOpen := (continuous_restrict s).le_induced /-- The compact-open topology on `C(X, Y)` is equal to the infimum of the compact-open topologies on `C(s, Y)` for `s` a compact subset of `X`. The key point of the proof is that for every compact set `K`, the universal set `Set.univ : Set K` is a compact set as well. -/ theorem compactOpen_eq_iInf_induced : (ContinuousMap.compactOpen : TopologicalSpace C(X, Y)) = ⨅ (K : Set X) (_ : IsCompact K), .induced (.restrict K) ContinuousMap.compactOpen := by refine le_antisymm (le_iInf₂ fun s _ ↦ compactOpen_le_induced s) ?_ refine le_generateFrom <| forall_mem_image2.2 fun K (hK : IsCompact K) U hU ↦ ?_ refine TopologicalSpace.le_def.1 (iInf₂_le K hK) _ ?_ convert isOpen_induced (isOpen_setOf_mapsTo (isCompact_iff_isCompact_univ.1 hK) hU) simp [Subtype.forall, MapsTo] theorem nhds_compactOpen_eq_iInf_nhds_induced (f : C(X, Y)) : 𝓝 f = ⨅ (s) (_ : IsCompact s), (𝓝 (f.restrict s)).comap (ContinuousMap.restrict s) := by rw [compactOpen_eq_iInf_induced] simp only [nhds_iInf, nhds_induced] theorem tendsto_compactOpen_restrict {ι : Type*} {l : Filter ι} {F : ι → C(X, Y)} {f : C(X, Y)} (hFf : Filter.Tendsto F l (𝓝 f)) (s : Set X) : Tendsto (fun i => (F i).restrict s) l (𝓝 (f.restrict s)) := (continuous_restrict s).continuousAt.tendsto.comp hFf theorem tendsto_compactOpen_iff_forall {ι : Type*} {l : Filter ι} (F : ι → C(X, Y)) (f : C(X, Y)) : Tendsto F l (𝓝 f) ↔ ∀ K, IsCompact K → Tendsto (fun i => (F i).restrict K) l (𝓝 (f.restrict K)) := by rw [compactOpen_eq_iInf_induced] simp [nhds_iInf, nhds_induced, Filter.tendsto_comap_iff, Function.comp_def] /-- A family `F` of functions in `C(X, Y)` converges in the compact-open topology, if and only if it converges in the compact-open topology on each compact subset of `X`. -/ theorem exists_tendsto_compactOpen_iff_forall [WeaklyLocallyCompactSpace X] [T2Space Y] {ι : Type*} {l : Filter ι} [Filter.NeBot l] (F : ι → C(X, Y)) : (∃ f, Filter.Tendsto F l (𝓝 f)) ↔ ∀ s : Set X, IsCompact s → ∃ f, Filter.Tendsto (fun i => (F i).restrict s) l (𝓝 f) := by constructor · rintro ⟨f, hf⟩ s _ exact ⟨f.restrict s, tendsto_compactOpen_restrict hf s⟩ · intro h choose f hf using h -- By uniqueness of limits in a `T2Space`, since `fun i ↦ F i x` tends to both `f s₁ hs₁ x` and -- `f s₂ hs₂ x`, we have `f s₁ hs₁ x = f s₂ hs₂ x` have h : ∀ (s₁) (hs₁ : IsCompact s₁) (s₂) (hs₂ : IsCompact s₂) (x : X) (hxs₁ : x ∈ s₁) (hxs₂ : x ∈ s₂), f s₁ hs₁ ⟨x, hxs₁⟩ = f s₂ hs₂ ⟨x, hxs₂⟩ := by rintro s₁ hs₁ s₂ hs₂ x hxs₁ hxs₂ haveI := isCompact_iff_compactSpace.mp hs₁ haveI := isCompact_iff_compactSpace.mp hs₂ have h₁ := (continuous_eval_const (⟨x, hxs₁⟩ : s₁)).continuousAt.tendsto.comp (hf s₁ hs₁) have h₂ := (continuous_eval_const (⟨x, hxs₂⟩ : s₂)).continuousAt.tendsto.comp (hf s₂ hs₂) exact tendsto_nhds_unique h₁ h₂ -- So glue the `f s hs` together and prove that this glued function `f₀` is a limit on each -- compact set `s` refine ⟨liftCover' _ _ h exists_compact_mem_nhds, ?_⟩ rw [tendsto_compactOpen_iff_forall] intro s hs rw [liftCover_restrict'] exact hf s hs end InfInduced section Coev variable (X Y) /-- The coevaluation map `Y → C(X, Y × X)` sending a point `x : Y` to the continuous function on `X` sending `y` to `(x, y)`. -/ @[simps -fullyApplied] def coev (b : Y) : C(X, Y × X) := { toFun := Prod.mk b } variable {X Y} theorem image_coev {y : Y} (s : Set X) : coev X Y y '' s = {y} ×ˢ s := by simp [singleton_prod] /-- The coevaluation map `Y → C(X, Y × X)` is continuous (always). -/ theorem continuous_coev : Continuous (coev X Y) := ((continuous_prodMk_const (X := Y) (Y := X) (Z := X)).comp (.prodMk continuous_id (continuous_const (y := ContinuousMap.id _))):) end Coev section Curry /-- The curried form of a continuous map `α × β → γ` as a continuous map `α → C(β, γ)`. If `a × β` is locally compact, this is continuous. If `α` and `β` are both locally compact, then this is a homeomorphism, see `Homeomorph.curry`. -/ def curry (f : C(X × Y, Z)) : C(X, C(Y, Z)) where toFun a := ⟨Function.curry f a, f.continuous.comp <| by fun_prop⟩ continuous_toFun := (continuous_postcomp f).comp continuous_coev @[simp] theorem curry_apply (f : C(X × Y, Z)) (a : X) (b : Y) : f.curry a b = f (a, b) := rfl /-- To show continuity of a map `α → C(β, γ)`, it suffices to show that its uncurried form α × β → γ` is continuous. -/ theorem continuous_of_continuous_uncurry (f : X → C(Y, Z)) (h : Continuous (Function.uncurry fun x y => f x y)) : Continuous f := (curry ⟨_, h⟩).2 theorem continuousOn_of_continuousOn_uncurry {s : Set X} (f : X → C(Y, Z)) (h : ContinuousOn (Function.uncurry fun x y => f x y) (s ×ˢ univ)) : ContinuousOn f s := continuousOn_iff_continuous_restrict.mpr <| continuous_of_continuous_uncurry _ <| h.comp_continuous (continuous_subtype_val.prodMap continuous_id) (fun x ↦ ⟨x.1.2, trivial⟩) /-- The currying process is a continuous map between function spaces. -/ theorem continuous_curry [LocallyCompactSpace (X × Y)] : Continuous (curry : C(X × Y, Z) → C(X, C(Y, Z))) := by apply continuous_of_continuous_uncurry apply continuous_of_continuous_uncurry rw [← (Homeomorph.prodAssoc _ _ _).symm.comp_continuous_iff'] exact continuous_eval /-- The uncurried form of a continuous map `X → C(Y, Z)` is a continuous map `X × Y → Z`. -/ theorem continuous_uncurry_of_continuous [LocallyCompactSpace Y] (f : C(X, C(Y, Z))) : Continuous (Function.uncurry fun x y => f x y) := continuous_eval.comp <| f.continuous.prodMap continuous_id /-- The uncurried form of a continuous map `X → C(Y, Z)` as a continuous map `X × Y → Z` (if `Y` is locally compact). If `X` is also locally compact, then this is a homeomorphism between the two function spaces, see `Homeomorph.curry`. -/ @[simps] def uncurry [LocallyCompactSpace Y] (f : C(X, C(Y, Z))) : C(X × Y, Z) := ⟨_, continuous_uncurry_of_continuous f⟩ /-- The uncurrying process is a continuous map between function spaces. -/ theorem continuous_uncurry [LocallyCompactSpace X] [LocallyCompactSpace Y] : Continuous (uncurry : C(X, C(Y, Z)) → C(X × Y, Z)) := by apply continuous_of_continuous_uncurry rw [← (Homeomorph.prodAssoc _ _ _).comp_continuous_iff'] dsimp [Function.comp_def] exact (continuous_fst.fst.eval continuous_fst.snd).eval continuous_snd /-- The family of constant maps: `Y → C(X, Y)` as a continuous map. -/ def const' : C(Y, C(X, Y)) := curry ContinuousMap.fst @[simp] theorem coe_const' : (const' : Y → C(X, Y)) = const X := rfl theorem continuous_const' : Continuous (const X : Y → C(X, Y)) := const'.continuous section mkD /-- A variant of `ContinuousMap.continuous_of_continuous_uncurry` in terms of `ContinuousMap.mkD`. Of course, in this particular setting, `fun x ↦ mkD (f x) g` is just `f`, but the `mkD` spelling appears naturally in the context of `C(α, β)`-valued integration. -/ lemma continuous_mkD_of_uncurry (f : T → X → Y) (g : C(X, Y)) (f_cont : Continuous (Function.uncurry f)) : Continuous (fun x ↦ mkD (f x) g) := by have (x : _) : Continuous (f x) := f_cont.comp (Continuous.prodMk_right x) refine continuous_of_continuous_uncurry _ ?_ conv in mkD _ _ => rw [mkD_of_continuous (this x)] exact f_cont open Set in lemma continuousOn_mkD_of_uncurry {s : Set T} (f : T → X → Y) (g : C(X, Y)) (f_cont : ContinuousOn (Function.uncurry f) (s ×ˢ univ)) : ContinuousOn (fun x ↦ mkD (f x) g) s := by have (x) (hx : x ∈ s) : Continuous (f x) := f_cont.comp_continuous (Continuous.prodMk_right x) fun _ ↦ ⟨hx, trivial⟩ simp_rw [continuousOn_iff_continuous_restrict, s.restrict_def] refine continuous_of_continuous_uncurry _ ?_ conv in mkD _ _ => rw [mkD_of_continuous (this x x.2)] exact f_cont.comp_continuous (.prodMap continuous_subtype_val continuous_id) fun xz ↦ ⟨xz.1.2, trivial⟩ open Set in lemma continuous_mkD_restrict_of_uncurry {t : Set X} (f : T → X → Y) (g : C(t, Y)) (f_cont : ContinuousOn (Function.uncurry f) (univ ×ˢ t)) : Continuous (fun x ↦ mkD (t.restrict (f x)) g) := by have (x : _) : ContinuousOn (f x) t := f_cont.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨trivial, hz⟩ refine continuous_of_continuous_uncurry _ ?_ conv in mkD _ _ => rw [mkD_of_continuousOn (this x)] exact f_cont.comp_continuous (.prodMap continuous_id continuous_subtype_val) fun xz ↦ ⟨trivial, xz.2.2⟩ open Set in lemma continuousOn_mkD_restrict_of_uncurry {s : Set T} {t : Set X} (f : T → X → Y) (g : C(t, Y)) (f_cont : ContinuousOn (Function.uncurry f) (s ×ˢ t)) : ContinuousOn (fun x ↦ mkD (t.restrict (f x)) g) s := by have (x) (hx : x ∈ s) : ContinuousOn (f x) t := f_cont.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨hx, hz⟩ simp_rw [continuousOn_iff_continuous_restrict, s.restrict_def] refine continuous_of_continuous_uncurry _ ?_ conv in mkD _ _ => rw [mkD_of_continuousOn (this x x.2)] exact f_cont.comp_continuous (.prodMap continuous_subtype_val continuous_subtype_val) fun xz ↦ ⟨xz.1.2, xz.2.2⟩ end mkD end Curry end CompactOpen end ContinuousMap open ContinuousMap namespace Homeomorph variable {X : Type*} {Y : Type*} {Z : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] /-- Currying as a homeomorphism between the function spaces `C(X × Y, Z)` and `C(X, C(Y, Z))`. -/ def curry [LocallyCompactSpace X] [LocallyCompactSpace Y] : C(X × Y, Z) ≃ₜ C(X, C(Y, Z)) := ⟨⟨ContinuousMap.curry, uncurry, by intro; ext; rfl, by intro; ext; rfl⟩, continuous_curry, continuous_uncurry⟩ /-- If `X` has a single element, then `Y` is homeomorphic to `C(X, Y)`. -/ def continuousMapOfUnique [Unique X] : Y ≃ₜ C(X, Y) where toFun := const X invFun f := f default right_inv f := by ext x rw [Unique.eq_default x] rfl continuous_toFun := continuous_const' continuous_invFun := continuous_eval_const _ @[simp] theorem continuousMapOfUnique_apply [Unique X] (y : Y) (x : X) : continuousMapOfUnique y x = y := rfl @[simp] theorem continuousMapOfUnique_symm_apply [Unique X] (f : C(X, Y)) : continuousMapOfUnique.symm f = f default := rfl end Homeomorph section IsQuotientMap variable {X₀ X Y Z : Type*} [TopologicalSpace X₀] [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [LocallyCompactSpace Y] {f : X₀ → X} theorem Topology.IsQuotientMap.continuous_lift_prod_left (hf : IsQuotientMap f) {g : X × Y → Z} (hg : Continuous fun p : X₀ × Y => g (f p.1, p.2)) : Continuous g := by let Gf : C(X₀, C(Y, Z)) := ContinuousMap.curry ⟨_, hg⟩ have h : ∀ x : X, Continuous fun y => g (x, y) := by intro x obtain ⟨x₀, rfl⟩ := hf.surjective x exact (Gf x₀).continuous let G : X → C(Y, Z) := fun x => ⟨_, h x⟩ have : Continuous G := by rw [hf.continuous_iff] exact Gf.continuous exact ContinuousMap.continuous_uncurry_of_continuous ⟨G, this⟩ theorem Topology.IsQuotientMap.continuous_lift_prod_right (hf : IsQuotientMap f) {g : Y × X → Z} (hg : Continuous fun p : Y × X₀ => g (p.1, f p.2)) : Continuous g := by have : Continuous fun p : X₀ × Y => g ((Prod.swap p).1, f (Prod.swap p).2) := hg.comp continuous_swap have : Continuous fun p : X₀ × Y => (g ∘ Prod.swap) (f p.1, p.2) := this exact (hf.continuous_lift_prod_left this).comp continuous_swap end IsQuotientMap
.lake/packages/mathlib/Mathlib/Topology/PartialHomeomorph.lean
import Mathlib.Topology.OpenPartialHomeomorph deprecated_module (since := "2025-10-03")
.lake/packages/mathlib/Mathlib/Topology/Exterior.lean
import Mathlib.Topology.NhdsKer deprecated_module (since := "2025-07-09")
.lake/packages/mathlib/Mathlib/Topology/UrysohnsLemma.lean
import Mathlib.Algebra.Order.Group.Indicator import Mathlib.Analysis.Normed.Affine.AddTorsor import Mathlib.Analysis.Normed.Group.FunctionSeries import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.LinearAlgebra.AffineSpace.Ordered import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.ContinuousMap.Algebra import Mathlib.Topology.GDelta.Basic /-! # Urysohn's lemma In this file we prove Urysohn's lemma `exists_continuous_zero_one_of_isClosed`: for any two disjoint closed sets `s` and `t` in a normal topological space `X` there exists a continuous function `f : X → ℝ` such that * `f` equals zero on `s`; * `f` equals one on `t`; * `0 ≤ f x ≤ 1` for all `x`. We also give versions in a regular locally compact space where one assumes that `s` is compact and `t` is closed, in `exists_continuous_zero_one_of_isCompact` and `exists_continuous_one_zero_of_isCompact` (the latter providing additionally a function with compact support). We write a generic proof so that it applies both to normal spaces and to regular locally compact spaces. ## Implementation notes Most paper sources prove Urysohn's lemma using a family of open sets indexed by dyadic rational numbers on `[0, 1]`. There are many technical difficulties with formalizing this proof (e.g., one needs to formalize the "dyadic induction", then prove that the resulting family of open sets is monotone). So, we formalize a slightly different proof. Let `Urysohns.CU` be the type of pairs `(C, U)` of a closed set `C` and an open set `U` such that `C ⊆ U`. Since `X` is a normal topological space, for each `c : CU` there exists an open set `u` such that `c.C ⊆ u ∧ closure u ⊆ c.U`. We define `c.left` and `c.right` to be `(c.C, u)` and `(closure u, c.U)`, respectively. Then we define a family of functions `Urysohns.CU.approx (c : Urysohns.CU) (n : ℕ) : X → ℝ` by recursion on `n`: * `c.approx 0` is the indicator of `c.Uᶜ`; * `c.approx (n + 1) x = (c.left.approx n x + c.right.approx n x) / 2`. For each `x` this is a monotone family of functions that are equal to zero on `c.C` and are equal to one outside of `c.U`. We also have `c.approx n x ∈ [0, 1]` for all `c`, `n`, and `x`. Let `Urysohns.CU.lim c` be the supremum (or equivalently, the limit) of `c.approx n`. Then properties of `Urysohns.CU.approx` immediately imply that * `c.lim x ∈ [0, 1]` for all `x`; * `c.lim` equals zero on `c.C` and equals one outside of `c.U`; * `c.lim x = (c.left.lim x + c.right.lim x) / 2`. In order to prove that `c.lim` is continuous at `x`, we prove by induction on `n : ℕ` that for `y` in a small neighborhood of `x` we have `|c.lim y - c.lim x| ≤ (3 / 4) ^ n`. Induction base follows from `c.lim x ∈ [0, 1]`, `c.lim y ∈ [0, 1]`. For the induction step, consider two cases: * `x ∈ c.left.U`; then for `y` in a small neighborhood of `x` we have `y ∈ c.left.U ⊆ c.right.C` (hence `c.right.lim x = c.right.lim y = 0`) and `|c.left.lim y - c.left.lim x| ≤ (3 / 4) ^ n`. Then `|c.lim y - c.lim x| = |c.left.lim y - c.left.lim x| / 2 ≤ (3 / 4) ^ n / 2 < (3 / 4) ^ (n + 1)`. * otherwise, `x ∉ c.left.right.C`; then for `y` in a small neighborhood of `x` we have `y ∉ c.left.right.C ⊇ c.left.left.U` (hence `c.left.left.lim x = c.left.left.lim y = 1`), `|c.left.right.lim y - c.left.right.lim x| ≤ (3 / 4) ^ n`, and `|c.right.lim y - c.right.lim x| ≤ (3 / 4) ^ n`. Combining these inequalities, the triangle inequality, and the recurrence formula for `c.lim`, we get `|c.lim x - c.lim y| ≤ (3 / 4) ^ (n + 1)`. The actual formalization uses `midpoint ℝ x y` instead of `(x + y) / 2` because we have more API lemmas about `midpoint`. ## Tags Urysohn's lemma, normal topological space, locally compact topological space -/ variable {X : Type*} [TopologicalSpace X] open Set Filter TopologicalSpace Topology Filter open scoped Pointwise namespace Urysohns /-- An auxiliary type for the proof of Urysohn's lemma: a pair of a closed set `C` and its open neighborhood `U`, together with the assumption that `C` and `U` satisfy the property `P C U`. The latter assumption will make it possible to prove simultaneously both versions of Urysohn's lemma, in normal spaces (with `P` always true) and in locally compact spaces (with `P C U = IsCompact C`). We put also in the structure the assumption that, for any such pair, one may find an intermediate pair in between satisfying `P`, to avoid carrying it around in the argument. -/ structure CU {X : Type*} [TopologicalSpace X] (P : Set X → Set X → Prop) where /-- The inner set in the inductive construction towards Urysohn's lemma -/ protected C : Set X /-- The outer set in the inductive construction towards Urysohn's lemma -/ protected U : Set X /-- The proof that `C` and `U` satisfy the property `P C U` -/ protected P_C_U : P C U protected closed_C : IsClosed C protected open_U : IsOpen U protected subset : C ⊆ U /-- The proof that we can divide `CU` pairs in half -/ protected hP : ∀ {c u : Set X}, IsClosed c → P c u → IsOpen u → c ⊆ u → ∃ (v : Set X), IsOpen v ∧ c ⊆ v ∧ closure v ⊆ u ∧ P c v ∧ P (closure v) u namespace CU variable {P : Set X → Set X → Prop} /-- By assumption, for each `c : CU P` there exists an open set `u` such that `c.C ⊆ u` and `closure u ⊆ c.U`. `c.left` is the pair `(c.C, u)`. -/ @[simps C] def left (c : CU P) : CU P where C := c.C U := (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose closed_C := c.closed_C P_C_U := (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose_spec.2.2.2.1 open_U := (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose_spec.1 subset := (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose_spec.2.1 hP := c.hP /-- By assumption, for each `c : CU P` there exists an open set `u` such that `c.C ⊆ u` and `closure u ⊆ c.U`. `c.right` is the pair `(closure u, c.U)`. -/ @[simps U] def right (c : CU P) : CU P where C := closure (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose U := c.U closed_C := isClosed_closure P_C_U := (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose_spec.2.2.2.2 open_U := c.open_U subset := (c.hP c.closed_C c.P_C_U c.open_U c.subset).choose_spec.2.2.1 hP := c.hP theorem left_U_subset_right_C (c : CU P) : c.left.U ⊆ c.right.C := subset_closure theorem left_U_subset (c : CU P) : c.left.U ⊆ c.U := Subset.trans c.left_U_subset_right_C c.right.subset theorem subset_right_C (c : CU P) : c.C ⊆ c.right.C := Subset.trans c.left.subset c.left_U_subset_right_C /-- `n`-th approximation to a continuous function `f : X → ℝ` such that `f = 0` on `c.C` and `f = 1` outside of `c.U`. -/ noncomputable def approx : ℕ → CU P → X → ℝ | 0, c, x => indicator c.Uᶜ 1 x | n + 1, c, x => midpoint ℝ (approx n c.left x) (approx n c.right x) theorem approx_of_mem_C (c : CU P) (n : ℕ) {x : X} (hx : x ∈ c.C) : c.approx n x = 0 := by induction n generalizing c with | zero => exact indicator_of_notMem (fun (hU : x ∈ c.Uᶜ) => hU <| c.subset hx) _ | succ n ihn => simp only [approx] rw [ihn, ihn, midpoint_self] exacts [c.subset_right_C hx, hx] theorem approx_of_notMem_U (c : CU P) (n : ℕ) {x : X} (hx : x ∉ c.U) : c.approx n x = 1 := by induction n generalizing c with | zero => rw [← mem_compl_iff] at hx exact indicator_of_mem hx _ | succ n ihn => simp only [approx] rw [ihn, ihn, midpoint_self] exacts [hx, fun hU => hx <| c.left_U_subset hU] @[deprecated (since := "2025-05-24")] alias approx_of_nmem_U := approx_of_notMem_U theorem approx_nonneg (c : CU P) (n : ℕ) (x : X) : 0 ≤ c.approx n x := by induction n generalizing c with | zero => exact indicator_nonneg (fun _ _ => zero_le_one) _ | succ n ihn => simp only [approx, midpoint_eq_smul_add, invOf_eq_inv] refine mul_nonneg (inv_nonneg.2 zero_le_two) (add_nonneg ?_ ?_) <;> apply ihn theorem approx_le_one (c : CU P) (n : ℕ) (x : X) : c.approx n x ≤ 1 := by induction n generalizing c with | zero => exact indicator_apply_le' (fun _ => le_rfl) fun _ => zero_le_one | succ n ihn => simp only [approx, midpoint_eq_smul_add, invOf_eq_inv, smul_eq_mul, ← div_eq_inv_mul] have := add_le_add (ihn (left c)) (ihn (right c)) norm_num at this exact Iff.mpr (div_le_one zero_lt_two) this theorem bddAbove_range_approx (c : CU P) (x : X) : BddAbove (range fun n => c.approx n x) := ⟨1, fun _ ⟨n, hn⟩ => hn ▸ c.approx_le_one n x⟩ theorem approx_le_approx_of_U_sub_C {c₁ c₂ : CU P} (h : c₁.U ⊆ c₂.C) (n₁ n₂ : ℕ) (x : X) : c₂.approx n₂ x ≤ c₁.approx n₁ x := by by_cases hx : x ∈ c₁.U · calc approx n₂ c₂ x = 0 := approx_of_mem_C _ _ (h hx) _ ≤ approx n₁ c₁ x := approx_nonneg _ _ _ · calc approx n₂ c₂ x ≤ 1 := approx_le_one _ _ _ _ = approx n₁ c₁ x := (approx_of_notMem_U _ _ hx).symm theorem approx_mem_Icc_right_left (c : CU P) (n : ℕ) (x : X) : c.approx n x ∈ Icc (c.right.approx n x) (c.left.approx n x) := by induction n generalizing c with | zero => exact ⟨le_rfl, indicator_le_indicator_of_subset (compl_subset_compl.2 c.left_U_subset) (fun _ => zero_le_one) _⟩ | succ n ihn => simp only [approx, mem_Icc] refine ⟨midpoint_le_midpoint ?_ (ihn _).1, midpoint_le_midpoint (ihn _).2 ?_⟩ <;> apply approx_le_approx_of_U_sub_C exacts [subset_closure, subset_closure] theorem approx_le_succ (c : CU P) (n : ℕ) (x : X) : c.approx n x ≤ c.approx (n + 1) x := by induction n generalizing c with | zero => simp only [approx, right_U, right_le_midpoint] exact (approx_mem_Icc_right_left c 0 x).2 | succ n ihn => rw [approx, approx] exact midpoint_le_midpoint (ihn _) (ihn _) theorem approx_mono (c : CU P) (x : X) : Monotone fun n => c.approx n x := monotone_nat_of_le_succ fun n => c.approx_le_succ n x /-- A continuous function `f : X → ℝ` such that * `0 ≤ f x ≤ 1` for all `x`; * `f` equals zero on `c.C` and equals one outside of `c.U`; -/ protected noncomputable def lim (c : CU P) (x : X) : ℝ := ⨆ n, c.approx n x theorem tendsto_approx_atTop (c : CU P) (x : X) : Tendsto (fun n => c.approx n x) atTop (𝓝 <| c.lim x) := tendsto_atTop_ciSup (c.approx_mono x) ⟨1, fun _ ⟨_, hn⟩ => hn ▸ c.approx_le_one _ _⟩ theorem lim_of_mem_C (c : CU P) (x : X) (h : x ∈ c.C) : c.lim x = 0 := by simp only [CU.lim, approx_of_mem_C, h, ciSup_const] theorem disjoint_C_support_lim (c : CU P) : Disjoint c.C (Function.support c.lim) := Function.disjoint_support_iff.mpr (fun x hx => lim_of_mem_C c x hx) theorem lim_of_notMem_U (c : CU P) (x : X) (h : x ∉ c.U) : c.lim x = 1 := by simp only [CU.lim, approx_of_notMem_U c _ h, ciSup_const] @[deprecated (since := "2025-05-24")] alias lim_of_nmem_U := lim_of_notMem_U theorem lim_eq_midpoint (c : CU P) (x : X) : c.lim x = midpoint ℝ (c.left.lim x) (c.right.lim x) := by refine tendsto_nhds_unique (c.tendsto_approx_atTop x) ((tendsto_add_atTop_iff_nat 1).1 ?_) simp only [approx] exact (c.left.tendsto_approx_atTop x).midpoint (c.right.tendsto_approx_atTop x) theorem approx_le_lim (c : CU P) (x : X) (n : ℕ) : c.approx n x ≤ c.lim x := le_ciSup (c.bddAbove_range_approx x) _ theorem lim_nonneg (c : CU P) (x : X) : 0 ≤ c.lim x := (c.approx_nonneg 0 x).trans (c.approx_le_lim x 0) theorem lim_le_one (c : CU P) (x : X) : c.lim x ≤ 1 := ciSup_le fun _ => c.approx_le_one _ _ theorem lim_mem_Icc (c : CU P) (x : X) : c.lim x ∈ Icc (0 : ℝ) 1 := ⟨c.lim_nonneg x, c.lim_le_one x⟩ /-- Continuity of `Urysohns.CU.lim`. See module docstring for a sketch of the proofs. -/ theorem continuous_lim (c : CU P) : Continuous c.lim := by obtain ⟨h0, h1234, h1⟩ : 0 < (2⁻¹ : ℝ) ∧ (2⁻¹ : ℝ) < 3 / 4 ∧ (3 / 4 : ℝ) < 1 := by norm_num refine continuous_iff_continuousAt.2 fun x => (Metric.nhds_basis_closedBall_pow (h0.trans h1234) h1).tendsto_right_iff.2 fun n _ => ?_ simp only [Metric.mem_closedBall] induction n generalizing c with | zero => filter_upwards with y rw [pow_zero] exact Real.dist_le_of_mem_Icc_01 (c.lim_mem_Icc _) (c.lim_mem_Icc _) | succ n ihn => by_cases hxl : x ∈ c.left.U · filter_upwards [IsOpen.mem_nhds c.left.open_U hxl, ihn c.left] with _ hyl hyd rw [pow_succ', c.lim_eq_midpoint, c.lim_eq_midpoint, c.right.lim_of_mem_C _ (c.left_U_subset_right_C hyl), c.right.lim_of_mem_C _ (c.left_U_subset_right_C hxl)] refine (dist_midpoint_midpoint_le _ _ _ _).trans ?_ rw [dist_self, add_zero, div_eq_inv_mul] gcongr · replace hxl : x ∈ c.left.right.Cᶜ := compl_subset_compl.2 c.left.right.subset hxl filter_upwards [IsOpen.mem_nhds (isOpen_compl_iff.2 c.left.right.closed_C) hxl, ihn c.left.right, ihn c.right] with y hyl hydl hydr replace hxl : x ∉ c.left.left.U := compl_subset_compl.2 c.left.left_U_subset_right_C hxl replace hyl : y ∉ c.left.left.U := compl_subset_compl.2 c.left.left_U_subset_right_C hyl simp only [pow_succ, c.lim_eq_midpoint, c.left.lim_eq_midpoint, c.left.left.lim_of_notMem_U _ hxl, c.left.left.lim_of_notMem_U _ hyl] grw [dist_midpoint_midpoint_le, dist_midpoint_midpoint_le, dist_self, zero_add] set r := (3 / 4 : ℝ) ^ n calc _ ≤ (r / 2 + r) / 2 := by gcongr _ = _ := by ring end CU end Urysohns /-- Urysohn's lemma: if `s` and `t` are two disjoint closed sets in a normal topological space `X`, then there exists a continuous function `f : X → ℝ` such that * `f` equals zero on `s`; * `f` equals one on `t`; * `0 ≤ f x ≤ 1` for all `x`. -/ theorem exists_continuous_zero_one_of_isClosed [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C(X, ℝ), EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by -- The actual proof is in the code above. Here we just repack it into the expected format. let P : Set X → Set X → Prop := fun _ _ ↦ True set c : Urysohns.CU P := { C := s U := tᶜ P_C_U := trivial closed_C := hs open_U := ht.isOpen_compl subset := disjoint_left.1 hd hP := by rintro c u c_closed - u_open cu rcases normal_exists_closure_subset c_closed u_open cu with ⟨v, v_open, cv, hv⟩ exact ⟨v, v_open, cv, hv, trivial, trivial⟩ } exact ⟨⟨c.lim, c.continuous_lim⟩, c.lim_of_mem_C, fun x hx => c.lim_of_notMem_U _ fun h => h hx, c.lim_mem_Icc⟩ /-- Urysohn's lemma: if `s` and `t` are two disjoint sets in a regular locally compact topological space `X`, with `s` compact and `t` closed, then there exists a continuous function `f : X → ℝ` such that * `f` equals zero on `s`; * `f` equals one on `t`; * `0 ≤ f x ≤ 1` for all `x`. -/ theorem exists_continuous_zero_one_of_isCompact [RegularSpace X] [LocallyCompactSpace X] {s t : Set X} (hs : IsCompact s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C(X, ℝ), EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by obtain ⟨k, k_comp, k_closed, sk, kt⟩ : ∃ k, IsCompact k ∧ IsClosed k ∧ s ⊆ interior k ∧ k ⊆ tᶜ := exists_compact_closed_between hs ht.isOpen_compl hd.symm.subset_compl_left let P : Set X → Set X → Prop := fun C _ => IsCompact C set c : Urysohns.CU P := { C := k U := tᶜ P_C_U := k_comp closed_C := k_closed open_U := ht.isOpen_compl subset := kt hP := by rintro c u - c_comp u_open cu rcases exists_compact_closed_between c_comp u_open cu with ⟨k, k_comp, k_closed, ck, ku⟩ have A : closure (interior k) ⊆ k := (IsClosed.closure_subset_iff k_closed).2 interior_subset refine ⟨interior k, isOpen_interior, ck, A.trans ku, c_comp, k_comp.of_isClosed_subset isClosed_closure A⟩ } exact ⟨⟨c.lim, c.continuous_lim⟩, fun x hx ↦ c.lim_of_mem_C _ (sk.trans interior_subset hx), fun x hx => c.lim_of_notMem_U _ fun h => h hx, c.lim_mem_Icc⟩ /-- Urysohn's lemma: if `s` and `t` are two disjoint sets in a regular locally compact topological space `X`, with `s` compact and `t` closed, then there exists a continuous function `f : X → ℝ` such that * `f` equals zero on `t`; * `f` equals one on `s`; * `0 ≤ f x ≤ 1` for all `x`. -/ theorem exists_continuous_zero_one_of_isCompact' [RegularSpace X] [LocallyCompactSpace X] {s t : Set X} (hs : IsCompact s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C(X, ℝ), EqOn f 0 t ∧ EqOn f 1 s ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by obtain ⟨g, hgs, hgt, (hicc : ∀ x, 0 ≤ g x ∧ g x ≤ 1)⟩ := exists_continuous_zero_one_of_isCompact hs ht hd use 1 - g refine ⟨?_, ?_, ?_⟩ · intro x hx simp only [ContinuousMap.sub_apply, ContinuousMap.one_apply, Pi.zero_apply] exact sub_eq_zero_of_eq (hgt.symm hx) · intro x hx simp only [ContinuousMap.sub_apply, ContinuousMap.one_apply, Pi.one_apply, sub_eq_self] exact hgs hx · intro x simpa [and_comm] using hicc x /-- Urysohn's lemma: if `s` and `t` are two disjoint sets in a regular locally compact topological space `X`, with `s` compact and `t` closed, then there exists a continuous compactly supported function `f : X → ℝ` such that * `f` equals one on `s`; * `f` equals zero on `t`; * `0 ≤ f x ≤ 1` for all `x`. -/ theorem exists_continuous_one_zero_of_isCompact [RegularSpace X] [LocallyCompactSpace X] {s t : Set X} (hs : IsCompact s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C(X, ℝ), EqOn f 1 s ∧ EqOn f 0 t ∧ HasCompactSupport f ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by obtain ⟨k, k_comp, k_closed, sk, kt⟩ : ∃ k, IsCompact k ∧ IsClosed k ∧ s ⊆ interior k ∧ k ⊆ tᶜ := exists_compact_closed_between hs ht.isOpen_compl hd.symm.subset_compl_left rcases exists_continuous_zero_one_of_isCompact hs isOpen_interior.isClosed_compl (disjoint_compl_right_iff_subset.mpr sk) with ⟨⟨f, hf⟩, hfs, hft, h'f⟩ have A : t ⊆ (interior k)ᶜ := subset_compl_comm.mpr (interior_subset.trans kt) refine ⟨⟨fun x ↦ 1 - f x, continuous_const.sub hf⟩, fun x hx ↦ by simpa using hfs hx, fun x hx ↦ by simpa [sub_eq_zero] using (hft (A hx)).symm, ?_, fun x ↦ ?_⟩ · apply HasCompactSupport.intro' k_comp k_closed (fun x hx ↦ ?_) simp only [ContinuousMap.coe_mk, sub_eq_zero] apply (hft _).symm contrapose! hx simp only [mem_compl_iff, not_not] at hx exact interior_subset hx · have : 0 ≤ f x ∧ f x ≤ 1 := by simpa using h'f x simp [this] /-- Urysohn's lemma: if `s` and `t` are two disjoint sets in a regular locally compact topological space `X`, with `s` compact and `t` closed, then there exists a continuous compactly supported function `f : X → ℝ` such that * `f` equals one on `s`; * `f` equals zero on `t`; * `0 ≤ f x ≤ 1` for all `x`. Moreover, if `s` is Gδ, one can ensure that `f ⁻¹ {1}` is exactly `s`. -/ theorem exists_continuous_one_zero_of_isCompact_of_isGδ [RegularSpace X] [LocallyCompactSpace X] {s t : Set X} (hs : IsCompact s) (h's : IsGδ s) (ht : IsClosed t) (hd : Disjoint s t) : ∃ f : C(X, ℝ), s = f ⁻¹' {1} ∧ EqOn f 0 t ∧ HasCompactSupport f ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by rcases h's.eq_iInter_nat with ⟨U, U_open, hU⟩ obtain ⟨m, m_comp, -, sm, mt⟩ : ∃ m, IsCompact m ∧ IsClosed m ∧ s ⊆ interior m ∧ m ⊆ tᶜ := exists_compact_closed_between hs ht.isOpen_compl hd.symm.subset_compl_left have A n : ∃ f : C(X, ℝ), EqOn f 1 s ∧ EqOn f 0 (U n ∩ interior m)ᶜ ∧ HasCompactSupport f ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by apply exists_continuous_one_zero_of_isCompact hs ((U_open n).inter isOpen_interior).isClosed_compl rw [disjoint_compl_right_iff_subset] exact subset_inter ((hU.subset.trans (iInter_subset U n))) sm choose f fs fm _hf f_range using A obtain ⟨u, u_pos, u_sum, hu⟩ : ∃ (u : ℕ → ℝ), (∀ i, 0 < u i) ∧ Summable u ∧ ∑' i, u i = 1 := ⟨fun n ↦ 1/2/2^n, fun n ↦ by positivity, summable_geometric_two' 1, tsum_geometric_two' 1⟩ let g : X → ℝ := fun x ↦ ∑' n, u n * f n x have hgmc : EqOn g 0 mᶜ := by intro x hx have B n : f n x = 0 := by have : mᶜ ⊆ (U n ∩ interior m)ᶜ := by simpa using inter_subset_right.trans interior_subset exact fm n (this hx) simp [g, B] have I n x : u n * f n x ≤ u n := mul_le_of_le_one_right (u_pos n).le (f_range n x).2 have S x : Summable (fun n ↦ u n * f n x) := Summable.of_nonneg_of_le (fun n ↦ mul_nonneg (u_pos n).le (f_range n x).1) (fun n ↦ I n x) u_sum refine ⟨⟨g, ?_⟩, ?_, hgmc.mono (subset_compl_comm.mp mt), ?_, fun x ↦ ⟨?_, ?_⟩⟩ · apply continuous_tsum (fun n ↦ by fun_prop) u_sum (fun n x ↦ ?_) simpa [abs_of_nonneg, (u_pos n).le, (f_range n x).1] using I n x · apply Subset.antisymm (fun x hx ↦ by simp [g, fs _ hx, hu]) ?_ apply compl_subset_compl.1 intro x hx obtain ⟨n, hn⟩ : ∃ n, x ∉ U n := by simpa [hU] using hx have fnx : f n x = 0 := fm _ (by simp [hn]) have : g x < 1 := by apply lt_of_lt_of_le ?_ hu.le exact (S x).tsum_lt_tsum (i := n) (fun i ↦ I i x) (by simp [fnx, u_pos n]) u_sum simpa using this.ne · exact HasCompactSupport.of_support_subset_isCompact m_comp (Function.support_subset_iff'.mpr hgmc) · exact tsum_nonneg (fun n ↦ mul_nonneg (u_pos n).le (f_range n x).1) · apply le_trans _ hu.le exact (S x).tsum_le_tsum (fun n ↦ I n x) u_sum /-- A variation of Urysohn's lemma. In a `T2Space X`, for a closed set `t` and a relatively compact open set `s` such that `t ⊆ s`, there is a continuous function `f` supported in `s`, `f x = 1` on `t` and `0 ≤ f x ≤ 1`. -/ lemma exists_tsupport_one_of_isOpen_isClosed [T2Space X] {s t : Set X} (hs : IsOpen s) (hscp : IsCompact (closure s)) (ht : IsClosed t) (hst : t ⊆ s) : ∃ f : C(X, ℝ), tsupport f ⊆ s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 := by -- separate `sᶜ` and `t` by `u` and `v`. rw [← compl_compl s] at hscp obtain ⟨u, v, huIsOpen, hvIsOpen, hscompl_subset_u, ht_subset_v, hDisjointuv⟩ := SeparatedNhds.of_isClosed_isCompact_closure_compl_isClosed (isClosed_compl_iff.mpr hs) hscp ht (HasSubset.Subset.disjoint_compl_left hst) rw [← subset_compl_iff_disjoint_right] at hDisjointuv have huvc : closure u ⊆ vᶜ := closure_minimal hDisjointuv hvIsOpen.isClosed_compl -- although `sᶜ` is not compact, `closure s` is compact and we can apply -- `SeparatedNhds.of_isClosed_isCompact_closure_compl_isClosed`. To apply the condition -- recursively, we need to make sure that `sᶜ ⊆ C`. let P : Set X → Set X → Prop := fun C _ => sᶜ ⊆ C set c : Urysohns.CU P := { C := closure u U := tᶜ P_C_U := hscompl_subset_u.trans subset_closure closed_C := isClosed_closure open_U := ht.isOpen_compl subset := subset_compl_comm.mp (Subset.trans ht_subset_v (subset_compl_comm.mp huvc)) hP := by intro c u0 cIsClosed Pc u0IsOpen csubu0 obtain ⟨u1, hu1⟩ := SeparatedNhds.of_isClosed_isCompact_closure_compl_isClosed cIsClosed (IsCompact.of_isClosed_subset hscp isClosed_closure (closure_mono (compl_subset_compl.mpr Pc))) (isClosed_compl_iff.mpr u0IsOpen) (HasSubset.Subset.disjoint_compl_right csubu0) simp_rw [← subset_compl_iff_disjoint_right, compl_subset_comm (s := u0)] at hu1 obtain ⟨v1, hu1, hv1, hcu1, hv1u, hu1v1⟩ := hu1 refine ⟨u1, hu1, hcu1, ?_, Pc, (Pc.trans hcu1).trans subset_closure⟩ exact closure_minimal hu1v1 hv1.isClosed_compl |>.trans hv1u } -- `c.lim = 0` on `closure u` and `c.lim = 1` on `t`, so that `tsupport c.lim ⊆ s`. use ⟨c.lim, c.continuous_lim⟩ simp only [ContinuousMap.coe_mk] refine ⟨?_, ?_, Urysohns.CU.lim_mem_Icc c⟩ · apply Subset.trans _ (compl_subset_comm.mp hscompl_subset_u) rw [← IsClosed.closure_eq (isClosed_compl_iff.mpr huIsOpen)] apply closure_mono exact Disjoint.subset_compl_right (disjoint_of_subset_right subset_closure (Disjoint.symm (Urysohns.CU.disjoint_C_support_lim c))) · intro x hx apply Urysohns.CU.lim_of_notMem_U exact notMem_compl_iff.mpr hx /-- A variation of **Urysohn's lemma**. In a Hausdorff locally compact space, for a compact set `K` contained in an open set `V`, there exists a compactly supported continuous function `f` such that `0 ≤ f ≤ 1`, `f = 1` on K and the support of `f` is contained in `V`. -/ lemma exists_continuousMap_one_of_isCompact_subset_isOpen [T2Space X] [LocallyCompactSpace X] {K V : Set X} (hK : IsCompact K) (hV : IsOpen V) (hKV : K ⊆ V) : ∃ f : C(X, ℝ), Set.EqOn f 1 K ∧ IsCompact (tsupport f) ∧ tsupport f ⊆ V ∧ ∀ x, f x ∈ Set.Icc 0 1 := by obtain ⟨U, hU1, hU2, hU3, hU4⟩ := exists_open_between_and_isCompact_closure hK hV hKV obtain ⟨f, hf1, hf2, hf3⟩ := exists_tsupport_one_of_isOpen_isClosed hU1 hU4 hK.isClosed hU2 have : tsupport f ⊆ closure U := hf1.trans subset_closure exact ⟨f, hf2, hU4.of_isClosed_subset isClosed_closure this, this.trans hU3, hf3⟩ theorem exists_continuous_nonneg_pos [RegularSpace X] [LocallyCompactSpace X] (x : X) : ∃ f : C(X, ℝ), HasCompactSupport f ∧ 0 ≤ (f : X → ℝ) ∧ f x ≠ 0 := by rcases exists_compact_mem_nhds x with ⟨k, hk, k_mem⟩ rcases exists_continuous_one_zero_of_isCompact hk isClosed_empty (disjoint_empty k) with ⟨f, fk, -, f_comp, hf⟩ refine ⟨f, f_comp, fun x ↦ (hf x).1, ?_⟩ have := fk (mem_of_mem_nhds k_mem) simp only [Pi.one_apply] at this simp [this]
.lake/packages/mathlib/Mathlib/Topology/DenseEmbedding.lean
import Mathlib.Topology.Bases import Mathlib.Topology.Separation.Regular /-! # Dense embeddings This file defines three properties of functions: * `DenseRange f` means `f` has dense image; * `IsDenseInducing i` means `i` is also inducing, namely it induces the topology on its codomain; * `IsDenseEmbedding e` means `e` is further an embedding, namely it is injective and `Inducing`. The main theorem `continuous_extend` gives a criterion for a function `f : X → Z` to a T₃ space Z to extend along a dense embedding `i : X → Y` to a continuous function `g : Y → Z`. Actually `i` only has to be `IsDenseInducing` (not necessarily injective). -/ noncomputable section open Filter Set Topology variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} /-- `i : α → β` is "dense inducing" if it has dense range and the topology on `α` is the one induced by `i` from the topology on `β`. -/ structure IsDenseInducing [TopologicalSpace α] [TopologicalSpace β] (i : α → β) : Prop extends IsInducing i where /-- The range of a dense inducing map is a dense set. -/ protected dense : DenseRange i namespace IsDenseInducing variable [TopologicalSpace α] [TopologicalSpace β] theorem _root_.Dense.isDenseInducing_val {s : Set α} (hs : Dense s) : IsDenseInducing (@Subtype.val α s) := ⟨IsInducing.subtypeVal, hs.denseRange_val⟩ variable {i : α → β} lemma isInducing (di : IsDenseInducing i) : IsInducing i := di.toIsInducing theorem nhds_eq_comap (di : IsDenseInducing i) : ∀ a : α, 𝓝 a = comap i (𝓝 <| i a) := di.isInducing.nhds_eq_comap protected theorem continuous (di : IsDenseInducing i) : Continuous i := di.isInducing.continuous theorem closure_range (di : IsDenseInducing i) : closure (range i) = univ := di.dense.closure_range protected theorem preconnectedSpace [PreconnectedSpace α] (di : IsDenseInducing i) : PreconnectedSpace β := di.dense.preconnectedSpace di.continuous theorem closure_image_mem_nhds {s : Set α} {a : α} (di : IsDenseInducing i) (hs : s ∈ 𝓝 a) : closure (i '' s) ∈ 𝓝 (i a) := by rw [di.nhds_eq_comap a, ((nhds_basis_opens _).comap _).mem_iff] at hs rcases hs with ⟨U, ⟨haU, hUo⟩, sub : i ⁻¹' U ⊆ s⟩ refine mem_of_superset (hUo.mem_nhds haU) ?_ calc U ⊆ closure (i '' (i ⁻¹' U)) := di.dense.subset_closure_image_preimage_of_isOpen hUo _ ⊆ closure (i '' s) := closure_mono (image_mono sub) theorem dense_image (di : IsDenseInducing i) {s : Set α} : Dense (i '' s) ↔ Dense s := by refine ⟨fun H x => ?_, di.dense.dense_image di.continuous⟩ rw [di.isInducing.closure_eq_preimage_closure_image, H.closure_eq, preimage_univ] trivial /-- If `i : α → β` is a dense embedding with dense complement of the range, then any compact set in `α` has empty interior. -/ theorem interior_compact_eq_empty [T2Space β] (di : IsDenseInducing i) (hd : Dense (range i)ᶜ) {s : Set α} (hs : IsCompact s) : interior s = ∅ := by refine eq_empty_iff_forall_notMem.2 fun x hx => ?_ rw [mem_interior_iff_mem_nhds] at hx have := di.closure_image_mem_nhds hx rw [(hs.image di.continuous).isClosed.closure_eq] at this rcases hd.inter_nhds_nonempty this with ⟨y, hyi, hys⟩ exact hyi (image_subset_range _ _ hys) /-- The product of two dense inducings is a dense inducing -/ protected theorem prodMap [TopologicalSpace γ] [TopologicalSpace δ] {e₁ : α → β} {e₂ : γ → δ} (de₁ : IsDenseInducing e₁) (de₂ : IsDenseInducing e₂) : IsDenseInducing (Prod.map e₁ e₂) where toIsInducing := de₁.isInducing.prodMap de₂.isInducing dense := de₁.dense.prodMap de₂.dense open TopologicalSpace /-- If the domain of a `IsDenseInducing` map is a separable space, then so is the codomain. -/ protected theorem separableSpace [SeparableSpace α] (di : IsDenseInducing i) : SeparableSpace β := di.dense.separableSpace di.continuous variable [TopologicalSpace δ] {f : γ → α} {g : γ → δ} {h : δ → β} /-- ``` γ -f→ α g↓ ↓e δ -h→ β ``` -/ theorem tendsto_comap_nhds_nhds {d : δ} {a : α} (di : IsDenseInducing i) (H : Tendsto h (𝓝 d) (𝓝 (i a))) (comm : h ∘ g = i ∘ f) : Tendsto f (comap g (𝓝 d)) (𝓝 a) := by have lim1 : map g (comap g (𝓝 d)) ≤ 𝓝 d := map_comap_le replace lim1 : map h (map g (comap g (𝓝 d))) ≤ map h (𝓝 d) := map_mono lim1 rw [Filter.map_map, comm, ← Filter.map_map, map_le_iff_le_comap] at lim1 have lim2 : comap i (map h (𝓝 d)) ≤ comap i (𝓝 (i a)) := comap_mono H rw [← di.nhds_eq_comap] at lim2 exact le_trans lim1 lim2 protected theorem nhdsWithin_neBot (di : IsDenseInducing i) (b : β) : NeBot (𝓝[range i] b) := di.dense.nhdsWithin_neBot b theorem comap_nhds_neBot (di : IsDenseInducing i) (b : β) : NeBot (comap i (𝓝 b)) := comap_neBot fun s hs => by rcases mem_closure_iff_nhds.1 (di.dense b) s hs with ⟨_, ⟨ha, a, rfl⟩⟩ exact ⟨a, ha⟩ theorem _root_.Dense.comap_val_nhds_neBot {s : Set α} (hs : Dense s) (a : α) : ((𝓝 a).comap ((↑) : s → α)).NeBot := hs.isDenseInducing_val.comap_nhds_neBot _ variable [TopologicalSpace γ] /-- If `i : α → β` is a dense inducing, then any function `f : α → γ` "extends" to a function `g = IsDenseInducing.extend di f : β → γ`. If `γ` is Hausdorff and `f` has a continuous extension, then `g` is the unique such extension. In general, `g` might not be continuous or even extend `f`. -/ def extend (di : IsDenseInducing i) (f : α → γ) (b : β) : γ := @limUnder _ _ _ ⟨f (di.dense.some b)⟩ (comap i (𝓝 b)) f theorem tendsto_extend (di : IsDenseInducing i) {f : α → γ} {a : α} (hf : ContinuousAt f a) : Tendsto f (𝓝 a) (𝓝 (di.extend f (i a))) := by rw [IsDenseInducing.extend, ← di.nhds_eq_comap] exact tendsto_nhds_limUnder ⟨_, hf⟩ theorem inseparable_extend [R1Space γ] (di : IsDenseInducing i) {f : α → γ} {a : α} (hf : ContinuousAt f a) : Inseparable (di.extend f (i a)) (f a) := tendsto_nhds_unique_inseparable (di.tendsto_extend hf) hf theorem extend_eq_of_tendsto [T2Space γ] (di : IsDenseInducing i) {b : β} {c : γ} {f : α → γ} (hf : Tendsto f (comap i (𝓝 b)) (𝓝 c)) : di.extend f b = c := haveI := di.comap_nhds_neBot hf.limUnder_eq theorem extend_eq_at [T2Space γ] (di : IsDenseInducing i) {f : α → γ} {a : α} (hf : ContinuousAt f a) : di.extend f (i a) = f a := extend_eq_of_tendsto _ <| di.nhds_eq_comap a ▸ hf theorem extend_eq_at' [T2Space γ] (di : IsDenseInducing i) {f : α → γ} {a : α} (c : γ) (hf : Tendsto f (𝓝 a) (𝓝 c)) : di.extend f (i a) = f a := di.extend_eq_at (continuousAt_of_tendsto_nhds hf) theorem extend_eq [T2Space γ] (di : IsDenseInducing i) {f : α → γ} (hf : Continuous f) (a : α) : di.extend f (i a) = f a := di.extend_eq_at hf.continuousAt /-- Variation of `extend_eq` where we ask that `f` has a limit along `comap i (𝓝 b)` for each `b : β`. This is a strictly stronger assumption than continuity of `f`, but in a lot of cases you'd have to prove it anyway to use `continuous_extend`, so this avoids doing the work twice. -/ theorem extend_eq' [T2Space γ] {f : α → γ} (di : IsDenseInducing i) (hf : ∀ b, ∃ c, Tendsto f (comap i (𝓝 b)) (𝓝 c)) (a : α) : di.extend f (i a) = f a := by rcases hf (i a) with ⟨b, hb⟩ refine di.extend_eq_at' b ?_ rwa [← di.isInducing.nhds_eq_comap] at hb theorem extend_unique_at [T2Space γ] {b : β} {f : α → γ} {g : β → γ} (di : IsDenseInducing i) (hf : ∀ᶠ x in comap i (𝓝 b), g (i x) = f x) (hg : ContinuousAt g b) : di.extend f b = g b := by refine di.extend_eq_of_tendsto fun s hs => mem_map.2 ?_ suffices ∀ᶠ x : α in comap i (𝓝 b), g (i x) ∈ s from hf.mp (this.mono fun x hgx hfx => hfx ▸ hgx) clear hf f refine eventually_comap.2 ((hg.eventually hs).mono ?_) rintro _ hxs x rfl exact hxs theorem extend_unique [T2Space γ] {f : α → γ} {g : β → γ} (di : IsDenseInducing i) (hf : ∀ x, g (i x) = f x) (hg : Continuous g) : di.extend f = g := funext fun _ => extend_unique_at di (Eventually.of_forall hf) hg.continuousAt theorem continuousAt_extend [T3Space γ] {b : β} {f : α → γ} (di : IsDenseInducing i) (hf : ∀ᶠ x in 𝓝 b, ∃ c, Tendsto f (comap i <| 𝓝 x) (𝓝 c)) : ContinuousAt (di.extend f) b := by set φ := di.extend f haveI := di.comap_nhds_neBot suffices ∀ V' ∈ 𝓝 (φ b), IsClosed V' → φ ⁻¹' V' ∈ 𝓝 b by simpa [ContinuousAt, (closed_nhds_basis (φ b)).tendsto_right_iff] intro V' V'_in V'_closed set V₁ := { x | Tendsto f (comap i <| 𝓝 x) (𝓝 <| φ x) } have V₁_in : V₁ ∈ 𝓝 b := by filter_upwards [hf] rintro x ⟨c, hc⟩ rwa [← di.extend_eq_of_tendsto hc] at hc obtain ⟨V₂, V₂_in, V₂_op, hV₂⟩ : ∃ V₂ ∈ 𝓝 b, IsOpen V₂ ∧ ∀ x ∈ i ⁻¹' V₂, f x ∈ V' := by simpa [and_assoc] using ((nhds_basis_opens' b).comap i).tendsto_left_iff.mp (mem_of_mem_nhds V₁_in : b ∈ V₁) V' V'_in suffices ∀ x ∈ V₁ ∩ V₂, φ x ∈ V' by filter_upwards [inter_mem V₁_in V₂_in] using this rintro x ⟨x_in₁, x_in₂⟩ have hV₂x : V₂ ∈ 𝓝 x := IsOpen.mem_nhds V₂_op x_in₂ apply V'_closed.mem_of_tendsto x_in₁ use V₂ tauto theorem continuous_extend [T3Space γ] {f : α → γ} (di : IsDenseInducing i) (hf : ∀ b, ∃ c, Tendsto f (comap i (𝓝 b)) (𝓝 c)) : Continuous (di.extend f) := continuous_iff_continuousAt.mpr fun _ => di.continuousAt_extend <| univ_mem' hf theorem mk' (i : α → β) (c : Continuous i) (dense : ∀ x, x ∈ closure (range i)) (H : ∀ (a : α), ∀ s ∈ 𝓝 a, ∃ t ∈ 𝓝 (i a), ∀ b, i b ∈ t → b ∈ s) : IsDenseInducing i where toIsInducing := isInducing_iff_nhds.2 fun a => le_antisymm (c.tendsto _).le_comap (by simpa [Filter.le_def] using H a) dense := dense end IsDenseInducing namespace Dense variable [TopologicalSpace α] [TopologicalSpace β] {s : Set α} /-- This is a shortcut for `hs.isDenseInducing_val.extend f`. It is useful because if `s : Set α` is dense then the coercion `(↑) : s → α` automatically satisfies `IsUniformInducing` and `IsDenseInducing` so this gives access to the theorems satisfied by a uniform extension by simply mentioning the density hypothesis. -/ noncomputable def extend (hs : Dense s) (f : s → β) : α → β := hs.isDenseInducing_val.extend f variable {f : s → β} theorem extend_eq_of_tendsto [T2Space β] (hs : Dense s) {a : α} {b : β} (hf : Tendsto f (comap (↑) (𝓝 a)) (𝓝 b)) : hs.extend f a = b := hs.isDenseInducing_val.extend_eq_of_tendsto hf theorem extend_eq_at [T2Space β] (hs : Dense s) {f : s → β} {x : s} (hf : ContinuousAt f x) : hs.extend f x = f x := hs.isDenseInducing_val.extend_eq_at hf theorem extend_eq [T2Space β] (hs : Dense s) (hf : Continuous f) (x : s) : hs.extend f x = f x := hs.extend_eq_at hf.continuousAt theorem extend_unique_at [T2Space β] {a : α} {g : α → β} (hs : Dense s) (hf : ∀ᶠ x : s in comap (↑) (𝓝 a), g x = f x) (hg : ContinuousAt g a) : hs.extend f a = g a := hs.isDenseInducing_val.extend_unique_at hf hg theorem extend_unique [T2Space β] {g : α → β} (hs : Dense s) (hf : ∀ x : s, g x = f x) (hg : Continuous g) : hs.extend f = g := hs.isDenseInducing_val.extend_unique hf hg theorem continuousAt_extend [T3Space β] {a : α} (hs : Dense s) (hf : ∀ᶠ x in 𝓝 a, ∃ b, Tendsto f (comap (↑) <| 𝓝 x) (𝓝 b)) : ContinuousAt (hs.extend f) a := hs.isDenseInducing_val.continuousAt_extend hf theorem continuous_extend [T3Space β] (hs : Dense s) (hf : ∀ a : α, ∃ b, Tendsto f (comap (↑) (𝓝 a)) (𝓝 b)) : Continuous (hs.extend f) := hs.isDenseInducing_val.continuous_extend hf end Dense /-- A dense embedding is an embedding with dense image. -/ structure IsDenseEmbedding [TopologicalSpace α] [TopologicalSpace β] (e : α → β) : Prop extends IsDenseInducing e where /-- A dense embedding is injective. -/ injective : Function.Injective e lemma IsDenseEmbedding.mk' [TopologicalSpace α] [TopologicalSpace β] (e : α → β) (c : Continuous e) (dense : DenseRange e) (injective : Function.Injective e) (H : ∀ (a : α), ∀ s ∈ 𝓝 a, ∃ t ∈ 𝓝 (e a), ∀ b, e b ∈ t → b ∈ s) : IsDenseEmbedding e := { IsDenseInducing.mk' e c dense H with injective } namespace IsDenseEmbedding open TopologicalSpace variable [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] variable {e : α → β} lemma isDenseInducing (de : IsDenseEmbedding e) : IsDenseInducing e := de.toIsDenseInducing theorem inj_iff (de : IsDenseEmbedding e) {x y} : e x = e y ↔ x = y := de.injective.eq_iff theorem isEmbedding (de : IsDenseEmbedding e) : IsEmbedding e where __ := de /-- If the domain of a `IsDenseEmbedding` is a separable space, then so is its codomain. -/ protected theorem separableSpace [SeparableSpace α] (de : IsDenseEmbedding e) : SeparableSpace β := de.isDenseInducing.separableSpace /-- The product of two dense embeddings is a dense embedding. -/ protected theorem prodMap {e₁ : α → β} {e₂ : γ → δ} (de₁ : IsDenseEmbedding e₁) (de₂ : IsDenseEmbedding e₂) : IsDenseEmbedding fun p : α × γ => (e₁ p.1, e₂ p.2) where toIsDenseInducing := de₁.isDenseInducing.prodMap de₂.isDenseInducing injective := de₁.injective.prodMap de₂.injective /-- The dense embedding of a subtype inside its closure. -/ @[simps] def subtypeEmb {α : Type*} (p : α → Prop) (e : α → β) (x : { x // p x }) : { x // x ∈ closure (e '' { x | p x }) } := ⟨e x, subset_closure <| mem_image_of_mem e x.prop⟩ protected theorem subtype (de : IsDenseEmbedding e) (p : α → Prop) : IsDenseEmbedding (subtypeEmb p e) where dense := dense_iff_closure_eq.2 <| by ext ⟨x, hx⟩ rw [image_eq_range] at hx simpa [closure_subtype, ← range_comp, (· ∘ ·)] injective := (de.injective.comp Subtype.coe_injective).codRestrict _ eq_induced := (induced_iff_nhds_eq _).2 fun ⟨x, hx⟩ => by simp [subtypeEmb, nhds_subtype_eq_comap, de.isInducing.nhds_eq_comap, comap_comap, Function.comp_def] theorem dense_image (de : IsDenseEmbedding e) {s : Set α} : Dense (e '' s) ↔ Dense s := de.isDenseInducing.dense_image protected lemma id {α : Type*} [TopologicalSpace α] : IsDenseEmbedding (id : α → α) := { IsEmbedding.id with dense := denseRange_id } end IsDenseEmbedding theorem Dense.isDenseEmbedding_val [TopologicalSpace α] {s : Set α} (hs : Dense s) : IsDenseEmbedding ((↑) : s → α) := { IsEmbedding.subtypeVal with dense := hs.denseRange_val } theorem isClosed_property [TopologicalSpace β] {e : α → β} {p : β → Prop} (he : DenseRange e) (hp : IsClosed { x | p x }) (h : ∀ a, p (e a)) : ∀ b, p b := by have : univ ⊆ { b | p b } := calc univ = closure (range e) := he.closure_range.symm _ ⊆ closure { b | p b } := closure_mono <| range_subset_iff.mpr h _ = _ := hp.closure_eq simpa only [univ_subset_iff, eq_univ_iff_forall, mem_setOf] theorem isClosed_property2 [TopologicalSpace β] {e : α → β} {p : β → β → Prop} (he : DenseRange e) (hp : IsClosed { q : β × β | p q.1 q.2 }) (h : ∀ a₁ a₂, p (e a₁) (e a₂)) : ∀ b₁ b₂, p b₁ b₂ := have : ∀ q : β × β, p q.1 q.2 := isClosed_property (he.prodMap he) hp fun _ => h _ _ fun b₁ b₂ => this ⟨b₁, b₂⟩ theorem isClosed_property3 [TopologicalSpace β] {e : α → β} {p : β → β → β → Prop} (he : DenseRange e) (hp : IsClosed { q : β × β × β | p q.1 q.2.1 q.2.2 }) (h : ∀ a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) : ∀ b₁ b₂ b₃, p b₁ b₂ b₃ := have : ∀ q : β × β × β, p q.1 q.2.1 q.2.2 := isClosed_property (he.prodMap <| he.prodMap he) hp fun _ => h _ _ _ fun b₁ b₂ b₃ => this ⟨b₁, b₂, b₃⟩ @[elab_as_elim] theorem DenseRange.induction_on [TopologicalSpace β] {e : α → β} (he : DenseRange e) {p : β → Prop} (b₀ : β) (hp : IsClosed { b | p b }) (ih : ∀ a : α, p <| e a) : p b₀ := isClosed_property he hp ih b₀ @[elab_as_elim] theorem DenseRange.induction_on₂ [TopologicalSpace β] {e : α → β} {p : β → β → Prop} (he : DenseRange e) (hp : IsClosed { q : β × β | p q.1 q.2 }) (h : ∀ a₁ a₂, p (e a₁) (e a₂)) (b₁ b₂ : β) : p b₁ b₂ := isClosed_property2 he hp h _ _ @[elab_as_elim] theorem DenseRange.induction_on₃ [TopologicalSpace β] {e : α → β} {p : β → β → β → Prop} (he : DenseRange e) (hp : IsClosed { q : β × β × β | p q.1 q.2.1 q.2.2 }) (h : ∀ a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) (b₁ b₂ b₃ : β) : p b₁ b₂ b₃ := isClosed_property3 he hp h _ _ _ section variable [TopologicalSpace β] [TopologicalSpace γ] [T2Space γ] variable {f : α → β} /-- Two continuous functions to a t2-space that agree on the dense range of a function are equal. -/ theorem DenseRange.equalizer (hfd : DenseRange f) {g h : β → γ} (hg : Continuous g) (hh : Continuous h) (H : g ∘ f = h ∘ f) : g = h := funext fun y => hfd.induction_on y (isClosed_eq hg hh) <| congr_fun H end -- Bourbaki GT III §3 no.4 Proposition 7 (generalised to any dense-inducing map to a regular space) theorem Filter.HasBasis.hasBasis_of_isDenseInducing [TopologicalSpace α] [TopologicalSpace β] [RegularSpace β] {ι : Type*} {s : ι → Set α} {p : ι → Prop} {x : α} (h : (𝓝 x).HasBasis p s) {f : α → β} (hf : IsDenseInducing f) : (𝓝 (f x)).HasBasis p fun i => closure <| f '' s i := by rw [Filter.hasBasis_iff] at h ⊢ intro T refine ⟨fun hT => ?_, fun hT => ?_⟩ · obtain ⟨T', hT₁, hT₂, hT₃⟩ := exists_mem_nhds_isClosed_subset hT have hT₄ : f ⁻¹' T' ∈ 𝓝 x := by rw [hf.isInducing.nhds_eq_comap x] exact ⟨T', hT₁, Subset.rfl⟩ obtain ⟨i, hi, hi'⟩ := (h _).mp hT₄ exact ⟨i, hi, (closure_mono (image_mono hi')).trans (Subset.trans (closure_minimal (image_preimage_subset _ _) hT₂) hT₃)⟩ · obtain ⟨i, hi, hi'⟩ := hT suffices closure (f '' s i) ∈ 𝓝 (f x) by filter_upwards [this] using hi' replace h := (h (s i)).mpr ⟨i, hi, Subset.rfl⟩ exact hf.closure_image_mem_nhds h
.lake/packages/mathlib/Mathlib/Topology/LocallyClosed.lean
import Mathlib.Topology.Constructions import Mathlib.Tactic.TFAE /-! # Locally closed sets ## Main definitions * `IsLocallyClosed`: Predicate saying that a set is locally closed ## Main results * `isLocallyClosed_tfae`: A set `s` is locally closed if one of the equivalent conditions below hold 1. It is the intersection of some open set and some closed set. 2. The coborder `(closure s \ s)ᶜ` is open. 3. `s` is closed in some neighborhood of `x` for all `x ∈ s`. 4. Every `x ∈ s` has some open neighborhood `U` such that `U ∩ closure s ⊆ s`. 5. `s` is open in the closure of `s`. -/ open Set Topology open scoped Set.Notation variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} {f : X → Y} lemma subset_coborder : s ⊆ coborder s := by rw [coborder, subset_compl_iff_disjoint_right] exact disjoint_sdiff_self_right lemma coborder_inter_closure : coborder s ∩ closure s = s := by rw [coborder, ← diff_eq_compl_inter, diff_diff_right_self, inter_eq_right] exact subset_closure lemma closure_inter_coborder : closure s ∩ coborder s = s := by rw [inter_comm, coborder_inter_closure] lemma coborder_eq_union_frontier_compl : coborder s = s ∪ (frontier s)ᶜ := by rw [coborder, compl_eq_comm, compl_union, compl_compl, ← diff_eq_compl_inter, ← union_diff_right, union_comm, ← closure_eq_self_union_frontier] lemma coborder_eq_univ_iff : coborder s = univ ↔ IsClosed s := by simp [coborder, diff_eq_empty, closure_subset_iff_isClosed] alias ⟨_, IsClosed.coborder_eq⟩ := coborder_eq_univ_iff lemma coborder_eq_compl_frontier_iff : coborder s = (frontier s)ᶜ ↔ IsOpen s := by simp_rw [coborder_eq_union_frontier_compl, union_eq_right, subset_compl_iff_disjoint_left, disjoint_frontier_iff_isOpen] theorem coborder_eq_union_closure_compl {s : Set X} : coborder s = s ∪ (closure s)ᶜ := by rw [coborder, compl_eq_comm, compl_union, compl_compl, inter_comm] rfl /-- The coborder of any set is dense -/ theorem dense_coborder {s : Set X} : Dense (coborder s) := by rw [dense_iff_closure_eq, coborder_eq_union_closure_compl, closure_union, ← univ_subset_iff] refine _root_.subset_trans ?_ (union_subset_union_right _ (subset_closure)) simp alias ⟨_, IsOpen.coborder_eq⟩ := coborder_eq_compl_frontier_iff lemma IsOpenMap.coborder_preimage_subset (hf : IsOpenMap f) (s : Set Y) : coborder (f ⁻¹' s) ⊆ f ⁻¹' (coborder s) := by rw [coborder, coborder, preimage_compl, preimage_diff, compl_subset_compl] apply diff_subset_diff_left exact hf.preimage_closure_subset_closure_preimage lemma Continuous.preimage_coborder_subset (hf : Continuous f) (s : Set Y) : f ⁻¹' (coborder s) ⊆ coborder (f ⁻¹' s) := by rw [coborder, coborder, preimage_compl, preimage_diff, compl_subset_compl] apply diff_subset_diff_left exact hf.closure_preimage_subset s lemma coborder_preimage (hf : IsOpenMap f) (hf' : Continuous f) (s : Set Y) : coborder (f ⁻¹' s) = f ⁻¹' (coborder s) := (hf.coborder_preimage_subset s).antisymm (hf'.preimage_coborder_subset s) protected lemma Topology.IsOpenEmbedding.coborder_preimage (hf : IsOpenEmbedding f) (s : Set Y) : coborder (f ⁻¹' s) = f ⁻¹' coborder s := coborder_preimage hf.isOpenMap hf.continuous s lemma isClosed_preimage_val_coborder : IsClosed (coborder s ↓∩ s) := by rw [isClosed_preimage_val, inter_eq_right.mpr subset_coborder, coborder_inter_closure] lemma IsLocallyClosed.inter (hs : IsLocallyClosed s) (ht : IsLocallyClosed t) : IsLocallyClosed (s ∩ t) := by obtain ⟨U₁, Z₁, hU₁, hZ₁, rfl⟩ := hs obtain ⟨U₂, Z₂, hU₂, hZ₂, rfl⟩ := ht refine ⟨_, _, hU₁.inter hU₂, hZ₁.inter hZ₂, inter_inter_inter_comm U₁ Z₁ U₂ Z₂⟩ lemma IsLocallyClosed.preimage {s : Set Y} (hs : IsLocallyClosed s) {f : X → Y} (hf : Continuous f) : IsLocallyClosed (f ⁻¹' s) := by obtain ⟨U, Z, hU, hZ, rfl⟩ := hs exact ⟨_, _, hU.preimage hf, hZ.preimage hf, preimage_inter⟩ nonrec lemma Topology.IsInducing.isLocallyClosed_iff {s : Set X} {f : X → Y} (hf : IsInducing f) : IsLocallyClosed s ↔ ∃ s' : Set Y, IsLocallyClosed s' ∧ f ⁻¹' s' = s := by simp_rw [IsLocallyClosed, hf.isOpen_iff, hf.isClosed_iff] constructor · rintro ⟨_, _, ⟨U, hU, rfl⟩, ⟨Z, hZ, rfl⟩, rfl⟩ exact ⟨_, ⟨U, Z, hU, hZ, rfl⟩, rfl⟩ · rintro ⟨_, ⟨U, Z, hU, hZ, rfl⟩, rfl⟩ exact ⟨_, _, ⟨U, hU, rfl⟩, ⟨Z, hZ, rfl⟩, rfl⟩ lemma Topology.IsEmbedding.isLocallyClosed_iff {s : Set X} {f : X → Y} (hf : IsEmbedding f) : IsLocallyClosed s ↔ ∃ s' : Set Y, IsLocallyClosed s' ∧ s' ∩ range f = f '' s := by simp_rw [hf.isInducing.isLocallyClosed_iff, ← (image_injective.mpr hf.injective).eq_iff, image_preimage_eq_inter_range] lemma IsLocallyClosed.image {s : Set X} (hs : IsLocallyClosed s) {f : X → Y} (hf : IsInducing f) (hf' : IsLocallyClosed (range f)) : IsLocallyClosed (f '' s) := by obtain ⟨t, ht, rfl⟩ := hf.isLocallyClosed_iff.mp hs rw [image_preimage_eq_inter_range] exact ht.inter hf' /-- A set `s` is locally closed if one of the equivalent conditions below hold 1. It is the intersection of some open set and some closed set. 2. The coborder `(closure s \ s)ᶜ` is open. 3. `s` is closed in some neighborhood of `x` for all `x ∈ s`. 4. Every `x ∈ s` has some open neighborhood `U` such that `U ∩ closure s ⊆ s`. 5. `s` is open in the closure of `s`. -/ lemma isLocallyClosed_tfae (s : Set X) : List.TFAE [ IsLocallyClosed s, IsOpen (coborder s), ∀ x ∈ s, ∃ U ∈ 𝓝 x, IsClosed (U ↓∩ s), ∀ x ∈ s, ∃ U, x ∈ U ∧ IsOpen U ∧ U ∩ closure s ⊆ s, IsOpen (closure s ↓∩ s)] := by tfae_have 1 → 2 := by rintro ⟨U, Z, hU, hZ, rfl⟩ have : Z ∪ (frontier (U ∩ Z))ᶜ = univ := by nth_rw 1 [← hZ.closure_eq] rw [← compl_subset_iff_union, compl_subset_compl] refine frontier_subset_closure.trans (closure_mono inter_subset_right) rw [coborder_eq_union_frontier_compl, inter_union_distrib_right, this, inter_univ] exact hU.union isClosed_frontier.isOpen_compl tfae_have 2 → 3 | h, x => (⟨coborder s, h.mem_nhds <| subset_coborder ·, isClosed_preimage_val_coborder⟩) tfae_have 3 → 4 | h, x, hx => by obtain ⟨t, ht, ht'⟩ := h x hx obtain ⟨U, hUt, hU, hxU⟩ := mem_nhds_iff.mp ht rw [isClosed_preimage_val] at ht' exact ⟨U, hxU, hU, (subset_inter (inter_subset_left.trans hUt) (hU.inter_closure.trans (closure_mono <| inter_subset_inter hUt subset_rfl))).trans ht'⟩ tfae_have 4 → 5 | H => by choose U hxU hU e using H refine ⟨⋃ x ∈ s, U x ‹_›, isOpen_iUnion (isOpen_iUnion <| hU ·), ext fun x ↦ ⟨?_, ?_⟩⟩ · rintro ⟨_, ⟨⟨y, rfl⟩, ⟨_, ⟨hy, rfl⟩, hxU⟩⟩⟩ exact e y hy ⟨hxU, x.2⟩ · exact (subset_iUnion₂ _ _ <| hxU x ·) tfae_have 5 → 1 | H => by convert H.isLocallyClosed.image IsInducing.subtypeVal (by simpa using isClosed_closure.isLocallyClosed) simpa using subset_closure tfae_finish lemma isLocallyClosed_iff_isOpen_coborder : IsLocallyClosed s ↔ IsOpen (coborder s) := (isLocallyClosed_tfae s).out 0 1 alias ⟨IsLocallyClosed.isOpen_coborder, _⟩ := isLocallyClosed_iff_isOpen_coborder lemma IsLocallyClosed.isOpen_preimage_val_closure (hs : IsLocallyClosed s) : IsOpen (closure s ↓∩ s) := ((isLocallyClosed_tfae s).out 0 4).mp hs
.lake/packages/mathlib/Mathlib/Topology/Specialization.lean
import Mathlib.Order.Category.Preord import Mathlib.Topology.Category.TopCat.Basic import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Topology.Order.UpperLowerSetTopology /-! # Specialization order This file defines a type synonym for a topological space considered with its specialisation order. -/ open CategoryTheory Topology /-- Type synonym for a topological space considered with its specialisation order. -/ def Specialization (α : Type*) := α namespace Specialization variable {α β γ : Type*} /-- `toEquiv` is the "identity" function to the `Specialization` of a type. -/ @[match_pattern] def toEquiv : α ≃ Specialization α := Equiv.refl _ /-- `ofEquiv` is the identity function from the `Specialization` of a type. -/ @[match_pattern] def ofEquiv : Specialization α ≃ α := Equiv.refl _ @[simp] lemma toEquiv_symm : (@toEquiv α).symm = ofEquiv := rfl @[simp] lemma ofEquiv_symm : (@ofEquiv α).symm = toEquiv := rfl @[simp] lemma toEquiv_ofEquiv (a : Specialization α) : toEquiv (ofEquiv a) = a := rfl @[simp] lemma ofEquiv_toEquiv (a : α) : ofEquiv (toEquiv a) = a := rfl -- In Lean 3, `dsimp` would use theorems proved by `Iff.rfl`. -- If that were still the case, this would useful as a `@[simp]` lemma, -- despite the fact that it is provable by `simp` (but not `dsimp`). @[simp, nolint simpNF] -- See https://github.com/leanprover-community/mathlib4/issues/10675 lemma toEquiv_inj {a b : α} : toEquiv a = toEquiv b ↔ a = b := Iff.rfl -- In Lean 3, `dsimp` would use theorems proved by `Iff.rfl`. -- If that were still the case, this would useful as a `@[simp]` lemma, -- despite the fact that it is provable by `simp` (but not `dsimp`). @[simp, nolint simpNF] -- See https://github.com/leanprover-community/mathlib4/issues/10675 lemma ofEquiv_inj {a b : Specialization α} : ofEquiv a = ofEquiv b ↔ a = b := Iff.rfl /-- A recursor for `Specialization`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {β : Specialization α → Sort*} (h : ∀ a, β (toEquiv a)) (a : Specialization α) : β a := h (ofEquiv a) variable [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] instance instPreorder : Preorder (Specialization α) := specializationPreorder α instance instPartialOrder [T0Space α] : PartialOrder (Specialization α) := specializationOrder α @[simp] lemma toEquiv_le_toEquiv {a b : α} : toEquiv a ≤ toEquiv b ↔ b ⤳ a := Iff.rfl @[simp] lemma ofEquiv_specializes_ofEquiv {a b : Specialization α} : ofEquiv a ⤳ ofEquiv b ↔ b ≤ a := Iff.rfl @[simp] lemma isOpen_toEquiv_preimage [AlexandrovDiscrete α] {s : Set (Specialization α)} : IsOpen (toEquiv ⁻¹' s) ↔ IsUpperSet s := isOpen_iff_forall_specializes.trans forall_swap @[simp] lemma isUpperSet_ofEquiv_preimage [AlexandrovDiscrete α] {s : Set α} : IsUpperSet (ofEquiv ⁻¹' s) ↔ IsOpen s := isOpen_toEquiv_preimage.symm /-- A continuous map between topological spaces induces a monotone map between their specialization orders. -/ def map (f : C(α, β)) : Specialization α →o Specialization β where toFun := toEquiv ∘ f ∘ ofEquiv monotone' := (map_continuous f).specialization_monotone @[simp] lemma map_id : map (ContinuousMap.id α) = OrderHom.id := rfl @[simp] lemma map_comp (g : C(β, γ)) (f : C(α, β)) : map (g.comp f) = (map g).comp (map f) := rfl end Specialization open Set Specialization WithUpperSet /-- A preorder is isomorphic to the specialisation order of its upper set topology. -/ def orderIsoSpecializationWithUpperSetTopology (α : Type*) [Preorder α] : α ≃o Specialization (WithUpperSet α) where toEquiv := toUpperSet.trans toEquiv map_rel_iff' := by simp /-- An Alexandrov-discrete space is isomorphic to the upper set topology of its specialisation order. -/ def homeoWithUpperSetTopologyorderIso (α : Type*) [TopologicalSpace α] [AlexandrovDiscrete α] : α ≃ₜ WithUpperSet (Specialization α) := (toEquiv.trans toUpperSet).toHomeomorph fun s ↦ by simp [Set.preimage_comp] /-- Sends a topological space to its specialisation order. -/ @[simps] def topToPreord : TopCat ⥤ Preord where obj X := .of <| Specialization X map f := Preord.ofHom <| Specialization.map f.hom
.lake/packages/mathlib/Mathlib/Topology/Bases.lean
import Mathlib.Data.Set.Constructions import Mathlib.Order.Filter.AtTopBot.CountablyGenerated import Mathlib.Topology.Constructions import Mathlib.Topology.NhdsWithin /-! # Bases of topologies. Countability axioms. A topological basis on a topological space `t` is a collection of sets, such that all open sets can be generated as unions of these sets, without the need to take finite intersections of them. This file introduces a framework for dealing with these collections, and also what more we can say under certain countability conditions on bases, which are referred to as first- and second-countable. We also briefly cover the theory of separable spaces, which are those with a countable, dense subset. If a space is second-countable, and also has a countably generated uniformity filter (for example, if `t` is a metric space), it will automatically be separable (and indeed, these conditions are equivalent in this case). ## Main definitions * `TopologicalSpace.IsTopologicalBasis s`: The topological space `t` has basis `s`. * `TopologicalSpace.SeparableSpace α`: The topological space `t` has a countable, dense subset. * `TopologicalSpace.IsSeparable s`: The set `s` is contained in the closure of a countable set. * `FirstCountableTopology α`: A topology in which `𝓝 x` is countably generated for every `x`. * `SecondCountableTopology α`: A topology which has a topological basis which is countable. ## Main results * `TopologicalSpace.FirstCountableTopology.tendsto_subseq`: In a first-countable space, cluster points are limits of subsequences. * `TopologicalSpace.SecondCountableTopology.isOpen_iUnion_countable`: In a second-countable space, the union of arbitrarily-many open sets is equal to a sub-union of only countably many of these sets. * `TopologicalSpace.SecondCountableTopology.countable_cover_nhds`: Consider `f : α → Set α` with the property that `f x ∈ 𝓝 x` for all `x`. Then there is some countable set `s` whose image covers the space. ## Implementation Notes For our applications we are interested that there exists a countable basis, but we do not need the concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins. ## TODO More fine grained instances for `FirstCountableTopology`, `TopologicalSpace.SeparableSpace`, and more. -/ open Set Filter Function Topology noncomputable section namespace TopologicalSpace universe u variable {α : Type u} {β : Type*} [t : TopologicalSpace α] {B : Set (Set α)} {s : Set α} /-- A topological basis is one that satisfies the necessary conditions so that it suffices to take unions of the basis sets to get a topology (without taking finite intersections as well). -/ structure IsTopologicalBasis (s : Set (Set α)) : Prop where /-- For every point `x`, the set of `t ∈ s` such that `x ∈ t` is directed downwards. -/ exists_subset_inter : ∀ t₁ ∈ s, ∀ t₂ ∈ s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃ ∈ s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂ /-- The sets from `s` cover the whole space. -/ sUnion_eq : ⋃₀ s = univ /-- The topology is generated by sets from `s`. -/ eq_generateFrom : t = generateFrom s /-- If a family of sets `s` generates the topology, then intersections of finite subcollections of `s` form a topological basis. -/ theorem isTopologicalBasis_of_subbasis {s : Set (Set α)} (hs : t = generateFrom s) : IsTopologicalBasis ((fun f => ⋂₀ f) '' { f : Set (Set α) | f.Finite ∧ f ⊆ s }) := by subst t; letI := generateFrom s refine ⟨?_, ?_, le_antisymm (le_generateFrom ?_) <| generateFrom_anti fun t ht => ?_⟩ · rintro _ ⟨t₁, ⟨hft₁, ht₁b⟩, rfl⟩ _ ⟨t₂, ⟨hft₂, ht₂b⟩, rfl⟩ x h exact ⟨_, ⟨_, ⟨hft₁.union hft₂, union_subset ht₁b ht₂b⟩, sInter_union t₁ t₂⟩, h, Subset.rfl⟩ · rw [sUnion_image, iUnion₂_eq_univ_iff] exact fun x => ⟨∅, ⟨finite_empty, empty_subset _⟩, sInter_empty.substr <| mem_univ x⟩ · rintro _ ⟨t, ⟨hft, htb⟩, rfl⟩ exact hft.isOpen_sInter fun s hs ↦ GenerateOpen.basic _ <| htb hs · rw [← sInter_singleton t] exact ⟨{t}, ⟨finite_singleton t, singleton_subset_iff.2 ht⟩, rfl⟩ theorem isTopologicalBasis_of_subbasis_of_finiteInter {s : Set (Set α)} (hsg : t = generateFrom s) (hsi : FiniteInter s) : IsTopologicalBasis s := by convert isTopologicalBasis_of_subbasis hsg refine le_antisymm (fun t ht ↦ ⟨{t}, by simpa using ht⟩) ?_ rintro _ ⟨g, ⟨hg, hgs⟩, rfl⟩ lift g to Finset (Set α) using hg exact hsi.finiteInter_mem g hgs theorem isTopologicalBasis_of_subbasis_of_inter {r : Set (Set α)} (hsg : t = generateFrom r) (hsi : ∀ ⦃s⦄, s ∈ r → ∀ ⦃t⦄, t ∈ r → s ∩ t ∈ r) : IsTopologicalBasis (insert univ r) := isTopologicalBasis_of_subbasis_of_finiteInter (by simpa using hsg) (FiniteInter.mk₂ hsi) theorem IsTopologicalBasis.of_hasBasis_nhds {s : Set (Set α)} (h_nhds : ∀ a, (𝓝 a).HasBasis (fun t ↦ t ∈ s ∧ a ∈ t) id) : IsTopologicalBasis s where exists_subset_inter t₁ ht₁ t₂ ht₂ x hx := by simpa only [and_assoc, (h_nhds x).mem_iff] using (inter_mem ((h_nhds _).mem_of_mem ⟨ht₁, hx.1⟩) ((h_nhds _).mem_of_mem ⟨ht₂, hx.2⟩)) sUnion_eq := sUnion_eq_univ_iff.2 fun x ↦ (h_nhds x).ex_mem eq_generateFrom := ext_nhds fun x ↦ by simpa only [nhds_generateFrom, and_comm] using (h_nhds x).eq_biInf /-- If a family of open sets `s` is such that every open neighbourhood contains some member of `s`, then `s` is a topological basis. -/ theorem isTopologicalBasis_of_isOpen_of_nhds {s : Set (Set α)} (h_open : ∀ u ∈ s, IsOpen u) (h_nhds : ∀ (a : α) (u : Set α), a ∈ u → IsOpen u → ∃ v ∈ s, a ∈ v ∧ v ⊆ u) : IsTopologicalBasis s := .of_hasBasis_nhds <| fun a ↦ (nhds_basis_opens a).to_hasBasis' (by simpa [and_assoc] using h_nhds a) fun _ ⟨hts, hat⟩ ↦ (h_open _ hts).mem_nhds hat /-- A set `s` is in the neighbourhood of `a` iff there is some basis set `t`, which contains `a` and is itself contained in `s`. -/ theorem IsTopologicalBasis.mem_nhds_iff {a : α} {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) : s ∈ 𝓝 a ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by change s ∈ (𝓝 a).sets ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s rw [hb.eq_generateFrom, nhds_generateFrom, biInf_sets_eq] · simp [and_assoc, and_left_comm] · rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩ let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ ⟨hs₁, ht₁⟩ exact ⟨u, ⟨hu₂, hu₁⟩, le_principal_iff.2 (hu₃.trans inter_subset_left), le_principal_iff.2 (hu₃.trans inter_subset_right)⟩ · rcases eq_univ_iff_forall.1 hb.sUnion_eq a with ⟨i, h1, h2⟩ exact ⟨i, h2, h1⟩ theorem IsTopologicalBasis.isOpen_iff {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) : IsOpen s ↔ ∀ a ∈ s, ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by simp [isOpen_iff_mem_nhds, hb.mem_nhds_iff] theorem IsTopologicalBasis.of_isOpen_of_subset {s s' : Set (Set α)} (h_open : ∀ u ∈ s', IsOpen u) (hs : IsTopologicalBasis s) (hss' : s ⊆ s') : IsTopologicalBasis s' := isTopologicalBasis_of_isOpen_of_nhds h_open fun a _ ha u_open ↦ have ⟨t, hts, ht⟩ := hs.isOpen_iff.mp u_open a ha; ⟨t, hss' hts, ht⟩ theorem IsTopologicalBasis.nhds_hasBasis {b : Set (Set α)} (hb : IsTopologicalBasis b) {a : α} : (𝓝 a).HasBasis (fun t : Set α => t ∈ b ∧ a ∈ t) fun t => t := ⟨fun s => hb.mem_nhds_iff.trans <| by simp only [and_assoc]⟩ protected theorem IsTopologicalBasis.isOpen {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) (hs : s ∈ b) : IsOpen s := by rw [hb.eq_generateFrom] exact .basic s hs theorem IsTopologicalBasis.insert_empty {s : Set (Set α)} (h : IsTopologicalBasis s) : IsTopologicalBasis (insert ∅ s) := h.of_isOpen_of_subset (by rintro _ (rfl | hu); exacts [isOpen_empty, h.isOpen hu]) (subset_insert ..) theorem IsTopologicalBasis.diff_empty {s : Set (Set α)} (h : IsTopologicalBasis s) : IsTopologicalBasis (s \ {∅}) := isTopologicalBasis_of_isOpen_of_nhds (fun _ hu ↦ h.isOpen hu.1) fun a _ ha hu ↦ have ⟨t, hts, ht⟩ := h.isOpen_iff.mp hu a ha ⟨t, ⟨hts, ne_of_mem_of_not_mem' ht.1 <| notMem_empty _⟩, ht⟩ protected theorem IsTopologicalBasis.mem_nhds {a : α} {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) (hs : s ∈ b) (ha : a ∈ s) : s ∈ 𝓝 a := (hb.isOpen hs).mem_nhds ha theorem IsTopologicalBasis.exists_subset_of_mem_open {b : Set (Set α)} (hb : IsTopologicalBasis b) {a : α} {u : Set α} (au : a ∈ u) (ou : IsOpen u) : ∃ v ∈ b, a ∈ v ∧ v ⊆ u := hb.mem_nhds_iff.1 <| IsOpen.mem_nhds ou au /-- Any open set is the union of the basis sets contained in it. -/ theorem IsTopologicalBasis.open_eq_sUnion' {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} (ou : IsOpen u) : u = ⋃₀ { s ∈ B | s ⊆ u } := ext fun _a => ⟨fun ha => let ⟨b, hb, ab, bu⟩ := hB.exists_subset_of_mem_open ha ou ⟨b, ⟨hb, bu⟩, ab⟩, fun ⟨_b, ⟨_, bu⟩, ab⟩ => bu ab⟩ theorem IsTopologicalBasis.open_eq_sUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} (ou : IsOpen u) : ∃ S ⊆ B, u = ⋃₀ S := ⟨{ s ∈ B | s ⊆ u }, fun _ h => h.1, hB.open_eq_sUnion' ou⟩ theorem IsTopologicalBasis.open_iff_eq_sUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} : IsOpen u ↔ ∃ S ⊆ B, u = ⋃₀ S := ⟨hB.open_eq_sUnion, fun ⟨_S, hSB, hu⟩ => hu.symm ▸ isOpen_sUnion fun _s hs => hB.isOpen (hSB hs)⟩ theorem IsTopologicalBasis.open_eq_iUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α} (ou : IsOpen u) : ∃ (β : Type u) (f : β → Set α), (u = ⋃ i, f i) ∧ ∀ i, f i ∈ B := ⟨↥({ s ∈ B | s ⊆ u }), (↑), by rw [← sUnion_eq_iUnion] apply hB.open_eq_sUnion' ou, fun s => And.left s.2⟩ @[elab_as_elim] lemma IsTopologicalBasis.isOpen_induction {P : Set α → Prop} (hB : IsTopologicalBasis B) (basis : ∀ b ∈ B, P b) (sUnion : ∀ S, (∀ s ∈ S, P s) → P (⋃₀ S)) {s : Set α} (hs : IsOpen s) : P s := by obtain ⟨S, hS, rfl⟩ := hB.open_eq_sUnion hs; exact sUnion _ fun b hb ↦ basis _ <| hS hb lemma IsTopologicalBasis.subset_of_forall_subset {t : Set α} (hB : IsTopologicalBasis B) (hs : IsOpen s) (h : ∀ U ∈ B, U ⊆ s → U ⊆ t) : s ⊆ t := by rw [hB.open_eq_sUnion' hs]; simpa [sUnion_subset_iff] lemma IsTopologicalBasis.eq_of_forall_subset_iff {t : Set α} (hB : IsTopologicalBasis B) (hs : IsOpen s) (ht : IsOpen t) (h : ∀ U ∈ B, U ⊆ s ↔ U ⊆ t) : s = t := by rw [hB.open_eq_sUnion' hs, hB.open_eq_sUnion' ht] exact congr_arg _ (Set.ext fun U ↦ and_congr_right <| h _) /-- A point `a` is in the closure of `s` iff all basis sets containing `a` intersect `s`. -/ theorem IsTopologicalBasis.mem_closure_iff {b : Set (Set α)} (hb : IsTopologicalBasis b) {s : Set α} {a : α} : a ∈ closure s ↔ ∀ o ∈ b, a ∈ o → (o ∩ s).Nonempty := (mem_closure_iff_nhds_basis' hb.nhds_hasBasis).trans <| by simp only [and_imp] /-- A set is dense iff it has non-trivial intersection with all basis sets. -/ theorem IsTopologicalBasis.dense_iff {b : Set (Set α)} (hb : IsTopologicalBasis b) {s : Set α} : Dense s ↔ ∀ o ∈ b, Set.Nonempty o → (o ∩ s).Nonempty := by simp only [Dense, hb.mem_closure_iff] exact ⟨fun h o hb ⟨a, ha⟩ => h a o hb ha, fun h a o hb ha => h o hb ⟨a, ha⟩⟩ theorem IsTopologicalBasis.isOpenMap_iff {β} [TopologicalSpace β] {B : Set (Set α)} (hB : IsTopologicalBasis B) {f : α → β} : IsOpenMap f ↔ ∀ s ∈ B, IsOpen (f '' s) := by refine ⟨fun H o ho => H _ (hB.isOpen ho), fun hf o ho => ?_⟩ rw [hB.open_eq_sUnion' ho, sUnion_eq_iUnion, image_iUnion] exact isOpen_iUnion fun s => hf s s.2.1 theorem IsTopologicalBasis.exists_nonempty_subset {B : Set (Set α)} (hb : IsTopologicalBasis B) {u : Set α} (hu : u.Nonempty) (ou : IsOpen u) : ∃ v ∈ B, Set.Nonempty v ∧ v ⊆ u := let ⟨x, hx⟩ := hu let ⟨v, vB, xv, vu⟩ := hb.exists_subset_of_mem_open hx ou ⟨v, vB, ⟨x, xv⟩, vu⟩ theorem isTopologicalBasis_opens : IsTopologicalBasis { U : Set α | IsOpen U } := isTopologicalBasis_of_isOpen_of_nhds (by tauto) (by tauto) protected lemma IsTopologicalBasis.isInducing {β} [TopologicalSpace β] {f : α → β} {T : Set (Set β)} (hf : IsInducing f) (h : IsTopologicalBasis T) : IsTopologicalBasis ((preimage f) '' T) := .of_hasBasis_nhds fun a ↦ by convert (hf.basis_nhds (h.nhds_hasBasis (a := f a))).to_image_id with s aesop protected theorem IsTopologicalBasis.induced {α} [s : TopologicalSpace β] (f : α → β) {T : Set (Set β)} (h : IsTopologicalBasis T) : IsTopologicalBasis (t := induced f s) ((preimage f) '' T) := h.isInducing (t := induced f s) (.induced f) protected theorem IsTopologicalBasis.inf {t₁ t₂ : TopologicalSpace β} {B₁ B₂ : Set (Set β)} (h₁ : IsTopologicalBasis (t := t₁) B₁) (h₂ : IsTopologicalBasis (t := t₂) B₂) : IsTopologicalBasis (t := t₁ ⊓ t₂) (image2 (· ∩ ·) B₁ B₂) := by refine .of_hasBasis_nhds (t := ?_) fun a ↦ ?_ rw [nhds_inf (t₁ := t₁)] convert ((h₁.nhds_hasBasis (t := t₁)).inf (h₂.nhds_hasBasis (t := t₂))).to_image_id aesop theorem IsTopologicalBasis.inf_induced {γ} [s : TopologicalSpace β] {B₁ : Set (Set α)} {B₂ : Set (Set β)} (h₁ : IsTopologicalBasis B₁) (h₂ : IsTopologicalBasis B₂) (f₁ : γ → α) (f₂ : γ → β) : IsTopologicalBasis (t := induced f₁ t ⊓ induced f₂ s) (image2 (f₁ ⁻¹' · ∩ f₂ ⁻¹' ·) B₁ B₂) := by simpa only [image2_image_left, image2_image_right] using (h₁.induced f₁).inf (h₂.induced f₂) protected theorem IsTopologicalBasis.prod {β} [TopologicalSpace β] {B₁ : Set (Set α)} {B₂ : Set (Set β)} (h₁ : IsTopologicalBasis B₁) (h₂ : IsTopologicalBasis B₂) : IsTopologicalBasis (image2 (· ×ˢ ·) B₁ B₂) := h₁.inf_induced h₂ Prod.fst Prod.snd theorem isTopologicalBasis_of_cover {ι} {U : ι → Set α} (Uo : ∀ i, IsOpen (U i)) (Uc : ⋃ i, U i = univ) {b : ∀ i, Set (Set (U i))} (hb : ∀ i, IsTopologicalBasis (b i)) : IsTopologicalBasis (⋃ i : ι, image ((↑) : U i → α) '' b i) := by refine isTopologicalBasis_of_isOpen_of_nhds (fun u hu => ?_) ?_ · simp only [mem_iUnion, mem_image] at hu rcases hu with ⟨i, s, sb, rfl⟩ exact (Uo i).isOpenMap_subtype_val _ ((hb i).isOpen sb) · intro a u ha uo rcases iUnion_eq_univ_iff.1 Uc a with ⟨i, hi⟩ lift a to ↥(U i) using hi rcases (hb i).exists_subset_of_mem_open ha (uo.preimage continuous_subtype_val) with ⟨v, hvb, hav, hvu⟩ exact ⟨(↑) '' v, mem_iUnion.2 ⟨i, mem_image_of_mem _ hvb⟩, mem_image_of_mem _ hav, image_subset_iff.2 hvu⟩ protected theorem IsTopologicalBasis.continuous_iff {β : Type*} [TopologicalSpace β] {B : Set (Set β)} (hB : IsTopologicalBasis B) {f : α → β} : Continuous f ↔ ∀ s ∈ B, IsOpen (f ⁻¹' s) := by rw [hB.eq_generateFrom, continuous_generateFrom_iff] @[simp] lemma isTopologicalBasis_empty : IsTopologicalBasis (∅ : Set (Set α)) ↔ IsEmpty α where mp h := by simpa using h.sUnion_eq.symm mpr h := ⟨by simp, by simp [Set.univ_eq_empty_iff.2], Subsingleton.elim ..⟩ variable (α) /-- A separable space is one with a countable dense subset, available through `TopologicalSpace.exists_countable_dense`. If `α` is also known to be nonempty, then `TopologicalSpace.denseSeq` provides a sequence `ℕ → α` with dense range, see `TopologicalSpace.denseRange_denseSeq`. If `α` is a uniform space with countably generated uniformity filter (e.g., an `EMetricSpace`), then this condition is equivalent to `SecondCountableTopology α`. In this case the latter should be used as a typeclass argument in theorems because Lean can automatically deduce `TopologicalSpace.SeparableSpace` from `SecondCountableTopology` using `TopologicalSpace.SecondCountableTopology.to_separableSpace`, but deducing `SecondCountableTopology` from `TopologicalSpace.SeparableSpace` requires more assumptions. -/ @[mk_iff] class SeparableSpace : Prop where /-- There exists a countable dense set. -/ exists_countable_dense : ∃ s : Set α, s.Countable ∧ Dense s theorem exists_countable_dense [SeparableSpace α] : ∃ s : Set α, s.Countable ∧ Dense s := SeparableSpace.exists_countable_dense /-- A nonempty separable space admits a sequence with dense range. Instead of running `cases` on the conclusion of this lemma, you might want to use `TopologicalSpace.denseSeq` and `TopologicalSpace.denseRange_denseSeq`. If `α` might be empty, then `TopologicalSpace.exists_countable_dense` is the main way to use separability of `α`. -/ theorem exists_dense_seq [SeparableSpace α] [Nonempty α] : ∃ u : ℕ → α, DenseRange u := by obtain ⟨s : Set α, hs, s_dense⟩ := exists_countable_dense α obtain ⟨u, hu⟩ := Set.countable_iff_exists_subset_range.mp hs exact ⟨u, s_dense.mono hu⟩ /-- A dense sequence in a non-empty separable topological space. If `α` might be empty, then `TopologicalSpace.exists_countable_dense` is the main way to use separability of `α`. -/ def denseSeq [SeparableSpace α] [Nonempty α] : ℕ → α := Classical.choose (exists_dense_seq α) /-- The sequence `TopologicalSpace.denseSeq α` has dense range. -/ @[simp] theorem denseRange_denseSeq [SeparableSpace α] [Nonempty α] : DenseRange (denseSeq α) := Classical.choose_spec (exists_dense_seq α) variable {α} instance (priority := 100) Countable.to_separableSpace [Countable α] : SeparableSpace α where exists_countable_dense := ⟨Set.univ, Set.countable_univ, dense_univ⟩ /-- If `f` has a dense range and its domain is countable, then its codomain is a separable space. See also `DenseRange.separableSpace`. -/ theorem SeparableSpace.of_denseRange {ι : Sort _} [Countable ι] (u : ι → α) (hu : DenseRange u) : SeparableSpace α := ⟨⟨range u, countable_range u, hu⟩⟩ alias _root_.DenseRange.separableSpace' := SeparableSpace.of_denseRange /-- If `α` is a separable space and `f : α → β` is a continuous map with dense range, then `β` is a separable space as well. E.g., the completion of a separable uniform space is separable. -/ protected theorem _root_.DenseRange.separableSpace [SeparableSpace α] [TopologicalSpace β] {f : α → β} (h : DenseRange f) (h' : Continuous f) : SeparableSpace β := let ⟨s, s_cnt, s_dense⟩ := exists_countable_dense α ⟨⟨f '' s, Countable.image s_cnt f, h.dense_image h' s_dense⟩⟩ theorem _root_.Topology.IsQuotientMap.separableSpace [SeparableSpace α] [TopologicalSpace β] {f : α → β} (hf : IsQuotientMap f) : SeparableSpace β := hf.surjective.denseRange.separableSpace hf.continuous /-- The product of two separable spaces is a separable space. -/ instance [TopologicalSpace β] [SeparableSpace α] [SeparableSpace β] : SeparableSpace (α × β) := by rcases exists_countable_dense α with ⟨s, hsc, hsd⟩ rcases exists_countable_dense β with ⟨t, htc, htd⟩ exact ⟨⟨s ×ˢ t, hsc.prod htc, hsd.prod htd⟩⟩ /-- The product of a countable family of separable spaces is a separable space. -/ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, SeparableSpace (X i)] [Countable ι] : SeparableSpace (∀ i, X i) := by choose t htc htd using (exists_countable_dense <| X ·) haveI := fun i ↦ (htc i).to_subtype nontriviality ∀ i, X i; inhabit ∀ i, X i classical set f : (Σ I : Finset ι, ∀ i : I, t i) → ∀ i, X i := fun ⟨I, g⟩ i ↦ if hi : i ∈ I then g ⟨i, hi⟩ else (default : ∀ i, X i) i refine ⟨⟨range f, countable_range f, dense_iff_inter_open.2 fun U hU ⟨g, hg⟩ ↦ ?_⟩⟩ rcases isOpen_pi_iff.1 hU g hg with ⟨I, u, huo, huU⟩ have : ∀ i : I, ∃ y ∈ t i, y ∈ u i := fun i ↦ (htd i).exists_mem_open (huo i i.2).1 ⟨_, (huo i i.2).2⟩ choose y hyt hyu using this lift y to ∀ i : I, t i using hyt refine ⟨f ⟨I, y⟩, huU fun i (hi : i ∈ I) ↦ ?_, mem_range_self (f := f) ⟨I, y⟩⟩ simp only [f, dif_pos hi] exact hyu ⟨i, _⟩ instance [SeparableSpace α] {r : α → α → Prop} : SeparableSpace (Quot r) := isQuotientMap_quot_mk.separableSpace instance [SeparableSpace α] {s : Setoid α} : SeparableSpace (Quotient s) := isQuotientMap_quot_mk.separableSpace /-- A topological space with discrete topology is separable iff it is countable. -/ theorem separableSpace_iff_countable [DiscreteTopology α] : SeparableSpace α ↔ Countable α := by simp [separableSpace_iff, countable_univ_iff] /-- In a separable space, a family of nonempty disjoint open sets is countable. -/ theorem _root_.Pairwise.countable_of_isOpen_disjoint [SeparableSpace α] {ι : Type*} {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (ho : ∀ i, IsOpen (s i)) (hne : ∀ i, (s i).Nonempty) : Countable ι := by rcases exists_countable_dense α with ⟨u, u_countable, u_dense⟩ choose f hfu hfs using fun i ↦ u_dense.exists_mem_open (ho i) (hne i) have f_inj : Injective f := fun i j hij ↦ hd.eq <| not_disjoint_iff.2 ⟨f i, hfs i, hij.symm ▸ hfs j⟩ have := u_countable.to_subtype exact (f_inj.codRestrict hfu).countable /-- In a separable space, a family of nonempty disjoint open sets is countable. -/ theorem _root_.Set.PairwiseDisjoint.countable_of_isOpen [SeparableSpace α] {ι : Type*} {s : ι → Set α} {a : Set ι} (h : a.PairwiseDisjoint s) (ho : ∀ i ∈ a, IsOpen (s i)) (hne : ∀ i ∈ a, (s i).Nonempty) : a.Countable := (h.subtype _ _).countable_of_isOpen_disjoint (Subtype.forall.2 ho) (Subtype.forall.2 hne) /-- In a separable space, a family of disjoint sets with nonempty interiors is countable. -/ theorem _root_.Set.PairwiseDisjoint.countable_of_nonempty_interior [SeparableSpace α] {ι : Type*} {s : ι → Set α} {a : Set ι} (h : a.PairwiseDisjoint s) (ha : ∀ i ∈ a, (interior (s i)).Nonempty) : a.Countable := (h.mono fun _ => interior_subset).countable_of_isOpen (fun _ _ => isOpen_interior) ha /-- A set `s` in a topological space is separable if it is contained in the closure of a countable set `c`. Beware that this definition does not require that `c` is contained in `s` (to express the latter, use `TopologicalSpace.SeparableSpace s` or `TopologicalSpace.IsSeparable (univ : Set s))`. In metric spaces, the two definitions are equivalent, see `TopologicalSpace.IsSeparable.separableSpace`. -/ def IsSeparable (s : Set α) := ∃ c : Set α, c.Countable ∧ s ⊆ closure c theorem IsSeparable.mono {s u : Set α} (hs : IsSeparable s) (hu : u ⊆ s) : IsSeparable u := by rcases hs with ⟨c, c_count, hs⟩ exact ⟨c, c_count, hu.trans hs⟩ theorem IsSeparable.iUnion {ι : Sort*} [Countable ι] {s : ι → Set α} (hs : ∀ i, IsSeparable (s i)) : IsSeparable (⋃ i, s i) := by choose c hc h'c using hs refine ⟨⋃ i, c i, countable_iUnion hc, iUnion_subset_iff.2 fun i => ?_⟩ exact (h'c i).trans (closure_mono (subset_iUnion _ i)) @[simp] theorem isSeparable_iUnion {ι : Sort*} [Countable ι] {s : ι → Set α} : IsSeparable (⋃ i, s i) ↔ ∀ i, IsSeparable (s i) := ⟨fun h i ↦ h.mono <| subset_iUnion s i, .iUnion⟩ @[simp] theorem isSeparable_union {s t : Set α} : IsSeparable (s ∪ t) ↔ IsSeparable s ∧ IsSeparable t := by simp [union_eq_iUnion, and_comm] theorem IsSeparable.union {s u : Set α} (hs : IsSeparable s) (hu : IsSeparable u) : IsSeparable (s ∪ u) := isSeparable_union.2 ⟨hs, hu⟩ @[simp] theorem isSeparable_closure : IsSeparable (closure s) ↔ IsSeparable s := by simp only [IsSeparable, isClosed_closure.closure_subset_iff] protected alias ⟨_, IsSeparable.closure⟩ := isSeparable_closure theorem _root_.Set.Countable.isSeparable {s : Set α} (hs : s.Countable) : IsSeparable s := ⟨s, hs, subset_closure⟩ theorem _root_.Set.Finite.isSeparable {s : Set α} (hs : s.Finite) : IsSeparable s := hs.countable.isSeparable theorem IsSeparable.univ_pi {ι : Type*} [Countable ι] {X : ι → Type*} {s : ∀ i, Set (X i)} [∀ i, TopologicalSpace (X i)] (h : ∀ i, IsSeparable (s i)) : IsSeparable (univ.pi s) := by classical rcases eq_empty_or_nonempty (univ.pi s) with he | ⟨f₀, -⟩ · rw [he] exact countable_empty.isSeparable · choose c c_count hc using h haveI := fun i ↦ (c_count i).to_subtype set g : (I : Finset ι) × ((i : I) → c i) → (i : ι) → X i := fun ⟨I, f⟩ i ↦ if hi : i ∈ I then f ⟨i, hi⟩ else f₀ i refine ⟨range g, countable_range g, fun f hf ↦ mem_closure_iff.2 fun o ho hfo ↦ ?_⟩ rcases isOpen_pi_iff.1 ho f hfo with ⟨I, u, huo, hI⟩ rsuffices ⟨f, hf⟩ : ∃ f : (i : I) → c i, g ⟨I, f⟩ ∈ Set.pi I u · exact ⟨g ⟨I, f⟩, hI hf, mem_range_self (f := g) ⟨I, f⟩⟩ suffices H : ∀ i ∈ I, (u i ∩ c i).Nonempty by choose f hfu hfc using H refine ⟨fun i ↦ ⟨f i i.2, hfc i i.2⟩, fun i (hi : i ∈ I) ↦ ?_⟩ simpa only [g, dif_pos hi] using hfu i hi intro i hi exact mem_closure_iff.1 (hc i <| hf _ trivial) _ (huo i hi).1 (huo i hi).2 lemma isSeparable_pi {ι : Type*} [Countable ι] {α : ι → Type*} {s : ∀ i, Set (α i)} [∀ i, TopologicalSpace (α i)] (h : ∀ i, IsSeparable (s i)) : IsSeparable {f : ∀ i, α i | ∀ i, f i ∈ s i} := by simpa only [← mem_univ_pi] using IsSeparable.univ_pi h lemma IsSeparable.prod {β : Type*} [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsSeparable s) (ht : IsSeparable t) : IsSeparable (s ×ˢ t) := by rcases hs with ⟨cs, cs_count, hcs⟩ rcases ht with ⟨ct, ct_count, hct⟩ refine ⟨cs ×ˢ ct, cs_count.prod ct_count, ?_⟩ rw [closure_prod_eq] gcongr theorem IsSeparable.image {β : Type*} [TopologicalSpace β] {s : Set α} (hs : IsSeparable s) {f : α → β} (hf : Continuous f) : IsSeparable (f '' s) := by rcases hs with ⟨c, c_count, hc⟩ refine ⟨f '' c, c_count.image _, ?_⟩ rw [image_subset_iff] exact hc.trans (closure_subset_preimage_closure_image hf) theorem _root_.Dense.isSeparable_iff (hs : Dense s) : IsSeparable s ↔ SeparableSpace α := by simp_rw [IsSeparable, separableSpace_iff, dense_iff_closure_eq, ← univ_subset_iff, ← hs.closure_eq, isClosed_closure.closure_subset_iff] theorem isSeparable_univ_iff : IsSeparable (univ : Set α) ↔ SeparableSpace α := dense_univ.isSeparable_iff theorem isSeparable_range [TopologicalSpace β] [SeparableSpace α] {f : α → β} (hf : Continuous f) : IsSeparable (range f) := image_univ (f := f) ▸ (isSeparable_univ_iff.2 ‹_›).image hf theorem IsSeparable.of_subtype (s : Set α) [SeparableSpace s] : IsSeparable s := by simpa using isSeparable_range (continuous_subtype_val (p := (· ∈ s))) theorem IsSeparable.of_separableSpace [h : SeparableSpace α] (s : Set α) : IsSeparable s := IsSeparable.mono (isSeparable_univ_iff.2 h) (subset_univ _) end TopologicalSpace open TopologicalSpace protected theorem IsTopologicalBasis.iInf {β : Type*} {ι : Type*} {t : ι → TopologicalSpace β} {T : ι → Set (Set β)} (h_basis : ∀ i, IsTopologicalBasis (t := t i) (T i)) : IsTopologicalBasis (t := ⨅ i, t i) { S | ∃ (U : ι → Set β) (F : Finset ι), (∀ i, i ∈ F → U i ∈ T i) ∧ S = ⋂ i ∈ F, U i } := by let _ := ⨅ i, t i refine isTopologicalBasis_of_isOpen_of_nhds ?_ ?_ · rintro - ⟨U, F, hU, rfl⟩ refine isOpen_biInter_finset fun i hi ↦ (h_basis i).isOpen (t := t i) (hU i hi) |>.mono (iInf_le _ _) · intro a u ha hu rcases (nhds_iInf (t := t) (a := a)).symm ▸ HasBasis.iInf' (fun i ↦ (h_basis i).nhds_hasBasis (t := t i)) |>.mem_iff.1 (hu.mem_nhds ha) with ⟨⟨F, U⟩, ⟨hF, hU⟩, hUu⟩ refine ⟨_, ⟨U, hF.toFinset, ?_, rfl⟩, ?_, ?_⟩ <;> simp only [Finite.mem_toFinset, mem_iInter] · exact fun i hi ↦ (hU i hi).1 · exact fun i hi ↦ (hU i hi).2 · exact hUu theorem IsTopologicalBasis.iInf_induced {β : Type*} {ι : Type*} {X : ι → Type*} [t : Π i, TopologicalSpace (X i)] {T : Π i, Set (Set (X i))} (cond : ∀ i, IsTopologicalBasis (T i)) (f : Π i, β → X i) : IsTopologicalBasis (t := ⨅ i, induced (f i) (t i)) { S | ∃ (U : ∀ i, Set (X i)) (F : Finset ι), (∀ i, i ∈ F → U i ∈ T i) ∧ S = ⋂ (i) (_ : i ∈ F), f i ⁻¹' U i } := by convert IsTopologicalBasis.iInf (fun i ↦ (cond i).induced (f i)) with S constructor <;> rintro ⟨U, F, hUT, hSU⟩ · exact ⟨fun i ↦ (f i) ⁻¹' (U i), F, fun i hi ↦ mem_image_of_mem _ (hUT i hi), hSU⟩ · choose! U' hU' hUU' using hUT exact ⟨U', F, hU', hSU ▸ (.symm <| iInter₂_congr hUU')⟩ theorem isTopologicalBasis_pi {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {T : ∀ i, Set (Set (X i))} (cond : ∀ i, IsTopologicalBasis (T i)) : IsTopologicalBasis { S | ∃ (U : ∀ i, Set (X i)) (F : Finset ι), (∀ i, i ∈ F → U i ∈ T i) ∧ S = (F : Set ι).pi U } := by simpa only [Set.pi_def] using IsTopologicalBasis.iInf_induced cond eval theorem isTopologicalBasis_singletons (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : IsTopologicalBasis { s | ∃ x : α, (s : Set α) = {x} } := isTopologicalBasis_of_isOpen_of_nhds (fun _ _ => isOpen_discrete _) fun x _ hx _ => ⟨{x}, ⟨x, rfl⟩, mem_singleton x, singleton_subset_iff.2 hx⟩ theorem isTopologicalBasis_subtype {α : Type*} [TopologicalSpace α] {B : Set (Set α)} (h : TopologicalSpace.IsTopologicalBasis B) (p : α → Prop) : IsTopologicalBasis (Set.preimage (Subtype.val (p := p)) '' B) := h.isInducing ⟨rfl⟩ section variable {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] lemma isOpenMap_eval (i : ι) : IsOpenMap (Function.eval i : (∀ i, X i) → X i) := by classical refine (isTopologicalBasis_pi fun _ ↦ isTopologicalBasis_opens).isOpenMap_iff.2 ?_ rintro _ ⟨U, s, hU, rfl⟩ obtain h | h := ((s : Set ι).pi U).eq_empty_or_nonempty · simp [h] by_cases hi : i ∈ s · rw [eval_image_pi (mod_cast hi) h] exact hU _ hi · rw [eval_image_pi_of_notMem (mod_cast hi), if_pos h] exact isOpen_univ end theorem Dense.exists_countable_dense_subset {α : Type*} [TopologicalSpace α] {s : Set α} [SeparableSpace s] (hs : Dense s) : ∃ t ⊆ s, t.Countable ∧ Dense t := let ⟨t, htc, htd⟩ := exists_countable_dense s ⟨(↑) '' t, Subtype.coe_image_subset s t, htc.image Subtype.val, hs.denseRange_val.dense_image continuous_subtype_val htd⟩ /-- Let `s` be a dense set in a topological space `α` with partial order structure. If `s` is a separable space (e.g., if `α` has a second countable topology), then there exists a countable dense subset `t ⊆ s` such that `t` contains bottom/top element of `α` when they exist and belong to `s`. For a dense subset containing neither bot nor top elements, see `Dense.exists_countable_dense_subset_no_bot_top`. -/ theorem Dense.exists_countable_dense_subset_bot_top {α : Type*} [TopologicalSpace α] [PartialOrder α] {s : Set α} [SeparableSpace s] (hs : Dense s) : ∃ t ⊆ s, t.Countable ∧ Dense t ∧ (∀ x, IsBot x → x ∈ s → x ∈ t) ∧ ∀ x, IsTop x → x ∈ s → x ∈ t := by rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, htd⟩ refine ⟨(t ∪ ({ x | IsBot x } ∪ { x | IsTop x })) ∩ s, ?_, ?_, ?_, ?_, ?_⟩ exacts [inter_subset_right, (htc.union ((countable_isBot α).union (countable_isTop α))).mono inter_subset_left, htd.mono (subset_inter subset_union_left hts), fun x hx hxs => ⟨Or.inr <| Or.inl hx, hxs⟩, fun x hx hxs => ⟨Or.inr <| Or.inr hx, hxs⟩] instance separableSpace_univ {α : Type*} [TopologicalSpace α] [SeparableSpace α] : SeparableSpace (univ : Set α) := (Equiv.Set.univ α).symm.surjective.denseRange.separableSpace (continuous_id.subtype_mk _) /-- If `α` is a separable topological space with a partial order, then there exists a countable dense set `s : Set α` that contains those of both bottom and top elements of `α` that actually exist. For a dense set containing neither bot nor top elements, see `exists_countable_dense_no_bot_top`. -/ theorem exists_countable_dense_bot_top (α : Type*) [TopologicalSpace α] [SeparableSpace α] [PartialOrder α] : ∃ s : Set α, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∈ s) ∧ ∀ x, IsTop x → x ∈ s := by simpa using dense_univ.exists_countable_dense_subset_bot_top namespace TopologicalSpace universe u variable (α : Type u) [t : TopologicalSpace α] /-- A first-countable space is one in which every point has a countable neighborhood basis. -/ class _root_.FirstCountableTopology : Prop where /-- The filter `𝓝 a` is countably generated for all points `a`. -/ nhds_generated_countable : ∀ a : α, (𝓝 a).IsCountablyGenerated attribute [instance] FirstCountableTopology.nhds_generated_countable /-- If `β` is a first-countable space, then its induced topology via `f` on `α` is also first-countable. -/ theorem firstCountableTopology_induced (α β : Type*) [t : TopologicalSpace β] [FirstCountableTopology β] (f : α → β) : @FirstCountableTopology α (t.induced f) := let _ := t.induced f ⟨fun x ↦ nhds_induced f x ▸ inferInstance⟩ variable {α} instance Subtype.firstCountableTopology (s : Set α) [FirstCountableTopology α] : FirstCountableTopology s := firstCountableTopology_induced s α (↑) protected theorem _root_.Topology.IsInducing.firstCountableTopology {β : Type*} [TopologicalSpace β] [FirstCountableTopology β] {f : α → β} (hf : IsInducing f) : FirstCountableTopology α := by rw [hf.1] exact firstCountableTopology_induced α β f protected theorem _root_.Topology.IsEmbedding.firstCountableTopology {β : Type*} [TopologicalSpace β] [FirstCountableTopology β] {f : α → β} (hf : IsEmbedding f) : FirstCountableTopology α := hf.1.firstCountableTopology namespace FirstCountableTopology /-- In a first-countable space, a cluster point `x` of a sequence is the limit of some subsequence. -/ theorem tendsto_subseq [FirstCountableTopology α] {u : ℕ → α} {x : α} (hx : MapClusterPt x atTop u) : ∃ ψ : ℕ → ℕ, StrictMono ψ ∧ Tendsto (u ∘ ψ) atTop (𝓝 x) := subseq_tendsto_of_neBot hx end FirstCountableTopology instance {β} [TopologicalSpace β] [FirstCountableTopology α] [FirstCountableTopology β] : FirstCountableTopology (α × β) := ⟨fun ⟨x, y⟩ => by rw [nhds_prod_eq]; infer_instance⟩ section Pi instance {ι : Type*} {X : ι → Type*} [Countable ι] [∀ i, TopologicalSpace (X i)] [∀ i, FirstCountableTopology (X i)] : FirstCountableTopology (∀ i, X i) := ⟨fun f => by rw [nhds_pi]; infer_instance⟩ end Pi instance isCountablyGenerated_nhdsWithin (x : α) [IsCountablyGenerated (𝓝 x)] (s : Set α) : IsCountablyGenerated (𝓝[s] x) := Inf.isCountablyGenerated _ _ variable (α) in /-- A second-countable space is one with a countable basis. -/ class _root_.SecondCountableTopology : Prop where /-- There exists a countable set of sets that generates the topology. -/ is_open_generated_countable : ∃ b : Set (Set α), b.Countable ∧ t = TopologicalSpace.generateFrom b protected theorem IsTopologicalBasis.secondCountableTopology {b : Set (Set α)} (hb : IsTopologicalBasis b) (hc : b.Countable) : SecondCountableTopology α := ⟨⟨b, hc, hb.eq_generateFrom⟩⟩ lemma SecondCountableTopology.mk' {α} {b : Set (Set α)} (hc : b.Countable) : @SecondCountableTopology α (generateFrom b) := @SecondCountableTopology.mk α (generateFrom b) ⟨b, hc, rfl⟩ instance _root_.Finite.toSecondCountableTopology [Finite α] : SecondCountableTopology α where is_open_generated_countable := ⟨_, {U | IsOpen U}.to_countable, TopologicalSpace.isTopologicalBasis_opens.eq_generateFrom⟩ variable (α) theorem exists_countable_basis [SecondCountableTopology α] : ∃ b : Set (Set α), b.Countable ∧ ∅ ∉ b ∧ IsTopologicalBasis b := by obtain ⟨b, hb₁, hb₂⟩ := @SecondCountableTopology.is_open_generated_countable α _ _ refine ⟨_, ?_, notMem_diff_of_mem ?_, (isTopologicalBasis_of_subbasis hb₂).diff_empty⟩ exacts [((countable_setOf_finite_subset hb₁).image _).mono diff_subset, rfl] /-- A countable topological basis of `α`. -/ def countableBasis [SecondCountableTopology α] : Set (Set α) := (exists_countable_basis α).choose theorem countable_countableBasis [SecondCountableTopology α] : (countableBasis α).Countable := (exists_countable_basis α).choose_spec.1 instance encodableCountableBasis [SecondCountableTopology α] : Encodable (countableBasis α) := (countable_countableBasis α).toEncodable theorem empty_notMem_countableBasis [SecondCountableTopology α] : ∅ ∉ countableBasis α := (exists_countable_basis α).choose_spec.2.1 @[deprecated (since := "2025-05-24")] alias empty_nmem_countableBasis := empty_notMem_countableBasis theorem isBasis_countableBasis [SecondCountableTopology α] : IsTopologicalBasis (countableBasis α) := (exists_countable_basis α).choose_spec.2.2 theorem eq_generateFrom_countableBasis [SecondCountableTopology α] : ‹TopologicalSpace α› = generateFrom (countableBasis α) := (isBasis_countableBasis α).eq_generateFrom variable {α} theorem isOpen_of_mem_countableBasis [SecondCountableTopology α] {s : Set α} (hs : s ∈ countableBasis α) : IsOpen s := (isBasis_countableBasis α).isOpen hs theorem nonempty_of_mem_countableBasis [SecondCountableTopology α] {s : Set α} (hs : s ∈ countableBasis α) : s.Nonempty := nonempty_iff_ne_empty.2 <| ne_of_mem_of_not_mem hs <| empty_notMem_countableBasis α variable (α) -- see Note [lower instance priority] instance (priority := 100) SecondCountableTopology.to_firstCountableTopology [SecondCountableTopology α] : FirstCountableTopology α := ⟨fun _ => HasCountableBasis.isCountablyGenerated <| ⟨(isBasis_countableBasis α).nhds_hasBasis, (countable_countableBasis α).mono inter_subset_left⟩⟩ -- see Note [lower instance priority] instance (priority := 100) [Countable α] [FirstCountableTopology α] : SecondCountableTopology α where is_open_generated_countable := by -- The countable union of the countable neighborhood bases at each point is a countable basis. choose b hxb hbb using fun x : α => (nhds_basis_opens x).exists_antitone_subbasis use range b.uncurry, countable_range b.uncurry apply le_antisymm · rw [le_generateFrom_iff_subset_isOpen] rintro _ ⟨⟨x, n⟩, rfl⟩ exact (hxb x n).right · rw [le_iff_nhds] intro x rw [(hbb x).ge_iff] intro n _ refine @IsOpen.mem_nhds α (generateFrom (range b.uncurry)) x (b x n) ?_ (hxb x n).left exact isOpen_generateFrom_of_mem ⟨⟨x, n⟩, rfl⟩ /-- If `β` is a second-countable space, then its induced topology via `f` on `α` is also second-countable. -/ theorem secondCountableTopology_induced (α β) [t : TopologicalSpace β] [SecondCountableTopology β] (f : α → β) : @SecondCountableTopology α (t.induced f) := by rcases @SecondCountableTopology.is_open_generated_countable β _ _ with ⟨b, hb, eq⟩ letI := t.induced f refine { is_open_generated_countable := ⟨preimage f '' b, hb.image _, ?_⟩ } rw [eq, induced_generateFrom_eq] variable {α} instance Subtype.secondCountableTopology (s : Set α) [SecondCountableTopology α] : SecondCountableTopology s := secondCountableTopology_induced s α (↑) lemma secondCountableTopology_iInf {α ι} [Countable ι] {t : ι → TopologicalSpace α} (ht : ∀ i, @SecondCountableTopology α (t i)) : @SecondCountableTopology α (⨅ i, t i) := by rw [funext fun i => @eq_generateFrom_countableBasis α (t i) (ht i), ← generateFrom_iUnion] exact SecondCountableTopology.mk' <| countable_iUnion fun i => @countable_countableBasis _ (t i) (ht i) -- TODO: more fine grained instances for `FirstCountableTopology`, `SeparableSpace`, `T2Space`, ... instance {β : Type*} [TopologicalSpace β] [SecondCountableTopology α] [SecondCountableTopology β] : SecondCountableTopology (α × β) := ((isBasis_countableBasis α).prod (isBasis_countableBasis β)).secondCountableTopology <| (countable_countableBasis α).image2 (countable_countableBasis β) _ instance {ι : Type*} {X : ι → Type*} [Countable ι] [∀ a, TopologicalSpace (X a)] [∀ a, SecondCountableTopology (X a)] : SecondCountableTopology (∀ a, X a) := secondCountableTopology_iInf fun _ => secondCountableTopology_induced _ _ _ -- see Note [lower instance priority] instance (priority := 100) SecondCountableTopology.to_separableSpace [SecondCountableTopology α] : SeparableSpace α := by choose p hp using fun s : countableBasis α => nonempty_of_mem_countableBasis s.2 exact ⟨⟨range p, countable_range _, (isBasis_countableBasis α).dense_iff.2 fun o ho _ => ⟨p ⟨o, ho⟩, hp ⟨o, _⟩, mem_range_self _⟩⟩⟩ /-- A countable open cover induces a second-countable topology if all open covers are themselves second countable. -/ theorem secondCountableTopology_of_countable_cover {ι} [Countable ι] {U : ι → Set α} [∀ i, SecondCountableTopology (U i)] (Uo : ∀ i, IsOpen (U i)) (hc : ⋃ i, U i = univ) : SecondCountableTopology α := haveI : IsTopologicalBasis (⋃ i, image ((↑) : U i → α) '' countableBasis (U i)) := isTopologicalBasis_of_cover Uo hc fun i => isBasis_countableBasis (U i) this.secondCountableTopology (countable_iUnion fun _ => (countable_countableBasis _).image _) /-- In a second-countable space, an open set, given as a union of open sets, is equal to the union of countably many of those sets. In particular, any open covering of `α` has a countable subcover: α is a Lindelöf space. -/ theorem isOpen_iUnion_countable [SecondCountableTopology α] {ι} (s : ι → Set α) (H : ∀ i, IsOpen (s i)) : ∃ T : Set ι, T.Countable ∧ ⋃ i ∈ T, s i = ⋃ i, s i := by let B := { b ∈ countableBasis α | ∃ i, b ⊆ s i } choose f hf using fun b : B => b.2.2 haveI : Countable B := ((countable_countableBasis α).mono (sep_subset _ _)).to_subtype refine ⟨_, countable_range f, (iUnion₂_subset_iUnion _ _).antisymm (sUnion_subset ?_)⟩ rintro _ ⟨i, rfl⟩ x xs rcases (isBasis_countableBasis α).exists_subset_of_mem_open xs (H _) with ⟨b, hb, xb, bs⟩ exact ⟨_, ⟨_, rfl⟩, _, ⟨⟨⟨_, hb, _, bs⟩, rfl⟩, rfl⟩, hf _ xb⟩ theorem isOpen_biUnion_countable [SecondCountableTopology α] {ι : Type*} (I : Set ι) (s : ι → Set α) (H : ∀ i ∈ I, IsOpen (s i)) : ∃ T ⊆ I, T.Countable ∧ ⋃ i ∈ T, s i = ⋃ i ∈ I, s i := by simp_rw [← Subtype.exists_set_subtype, biUnion_image] rcases isOpen_iUnion_countable (fun i : I ↦ s i) fun i ↦ H i i.2 with ⟨T, hTc, hU⟩ exact ⟨T, hTc.image _, hU.trans <| iUnion_subtype ..⟩ theorem isOpen_sUnion_countable [SecondCountableTopology α] (S : Set (Set α)) (H : ∀ s ∈ S, IsOpen s) : ∃ T : Set (Set α), T.Countable ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S := by simpa only [and_left_comm, sUnion_eq_biUnion] using isOpen_biUnion_countable S id H /-- In a topological space with second countable topology, if `f` is a function that sends each point `x` to a neighborhood of `x`, then for some countable set `s`, the neighborhoods `f x`, `x ∈ s`, cover the whole space. -/ theorem countable_cover_nhds [SecondCountableTopology α] {f : α → Set α} (hf : ∀ x, f x ∈ 𝓝 x) : ∃ s : Set α, s.Countable ∧ ⋃ x ∈ s, f x = univ := by rcases isOpen_iUnion_countable (fun x => interior (f x)) fun x => isOpen_interior with ⟨s, hsc, hsU⟩ suffices ⋃ x ∈ s, interior (f x) = univ from ⟨s, hsc, flip eq_univ_of_subset this <| iUnion₂_mono fun _ _ => interior_subset⟩ simp only [hsU, eq_univ_iff_forall, mem_iUnion] exact fun x => ⟨x, mem_interior_iff_mem_nhds.2 (hf x)⟩ theorem countable_cover_nhdsWithin [SecondCountableTopology α] {f : α → Set α} {s : Set α} (hf : ∀ x ∈ s, f x ∈ 𝓝[s] x) : ∃ t ⊆ s, t.Countable ∧ s ⊆ ⋃ x ∈ t, f x := by have : ∀ x : s, (↑) ⁻¹' f x ∈ 𝓝 x := fun x => preimage_coe_mem_nhds_subtype.2 (hf x x.2) rcases countable_cover_nhds this with ⟨t, htc, htU⟩ refine ⟨(↑) '' t, Subtype.coe_image_subset _ _, htc.image _, fun x hx => ?_⟩ simp only [biUnion_image, eq_univ_iff_forall, ← preimage_iUnion, mem_preimage] at htU ⊢ exact htU ⟨x, hx⟩ /-- In a second countable topological space, any open set is a countable union of elements in a given topological basis. -/ lemma IsTopologicalBasis.exists_countable_biUnion_of_isOpen [SecondCountableTopology α] {t : Set (Set α)} (ht : IsTopologicalBasis t) {u : Set α} (hu : IsOpen u) : ∃ s ⊆ t, s.Countable ∧ u = ⋃ a ∈ s, a := by have A : ∀ x ∈ u, ∃ a ∈ t, x ∈ a ∧ a ⊆ u := fun x hx ↦ ht.exists_subset_of_mem_open hx hu choose! a hat xa au using A obtain ⟨T, T_count, hT⟩ : ∃ T : Set u, T.Countable ∧ ⋃ i ∈ T, a i = ⋃ (i : u), a i := by apply isOpen_iUnion_countable _ rintro ⟨x, hx⟩ exact ht.isOpen (hat x hx) refine ⟨(fun (x : u) ↦ a x) '' T, ?_, T_count.image _, ?_⟩ · simp only [image_subset_iff] rintro ⟨x, xu⟩ - exact hat x xu rw [biUnion_image, hT] apply Subset.antisymm · intro x hx simp grind · simp grind /-- In a second countable topological space, any topological basis contains a countable subset which is also a topological basis. -/ lemma IsTopologicalBasis.exists_countable [SecondCountableTopology α] {t : Set (Set α)} (ht : IsTopologicalBasis t) : ∃ s ⊆ t, s.Countable ∧ IsTopologicalBasis s := by have A : ∀ u ∈ countableBasis α, ∃ s ⊆ t, s.Countable ∧ u = ⋃ a ∈ s, a := fun u hu ↦ ht.exists_countable_biUnion_of_isOpen ((isBasis_countableBasis α).isOpen hu) choose! s hst s_count hs using A refine ⟨⋃ u ∈ countableBasis α, s u, by simpa using hst, (countable_countableBasis α).biUnion s_count, ?_⟩ apply isTopologicalBasis_of_isOpen_of_nhds · simp only [mem_iUnion, exists_prop, forall_exists_index, and_imp] have := @ht.isOpen grind · intro x v hx hv simp only [mem_iUnion, exists_prop] obtain ⟨u, u_mem, xu, uv⟩ : ∃ u ∈ countableBasis α, x ∈ u ∧ u ⊆ v := (isBasis_countableBasis α).isOpen_iff.1 hv _ hx have : x ∈ ⋃ a ∈ s u, a := by convert xu exact (hs u u_mem).symm obtain ⟨w, ws, xw⟩ : ∃ w ∈ s u, x ∈ w := by simpa using this refine ⟨w, ⟨u, u_mem, ws⟩, xw, ?_⟩ apply Subset.trans (Subset.trans _ (hs u u_mem).symm.subset) uv exact subset_iUnion₂_of_subset w ws (Subset.refl _) /-- In a second countable topological space, any family generating the topology admits a countable generating subfamily. -/ lemma exists_countable_of_generateFrom {α : Type*} [ts : TopologicalSpace α] [SecondCountableTopology α] {t : Set (Set α)} (ht : ts = generateFrom t) : ∃ s ⊆ t, s.Countable ∧ ts = generateFrom s := by let t' := (fun f => ⋂₀ f) '' { f : Set (Set α) | f.Finite ∧ f ⊆ t } have : IsTopologicalBasis t' := TopologicalSpace.isTopologicalBasis_of_subbasis ht obtain ⟨s', s't', s'_count, hs'⟩ : ∃ s' ⊆ t', s'.Countable ∧ IsTopologicalBasis s' := this.exists_countable have A : ∀ u ∈ s', ∃ (f : Set (Set α)), f.Finite ∧ f ⊆ t ∧ ⋂₀ f = u := fun u hu ↦ by simpa [t', and_assoc] using s't' hu choose! f f_fin ft hf using A refine ⟨⋃ u ∈ s', f u, by simpa using ft, ?_, ?_⟩ · apply s'_count.biUnion intro u hu exact Finite.countable (f_fin u hu) · apply le_antisymm · apply le_generateFrom_iff_subset_isOpen.2 simp only [iUnion_subset_iff] intro u hu v hv rw [ht] apply isOpen_generateFrom_of_mem exact ft u hu hv · rw [hs'.eq_generateFrom] apply le_generateFrom_iff_subset_isOpen.2 intro u hu rw [← hf u hu, sInter_eq_biInter] change IsOpen[generateFrom _] (⋂ i ∈ f u, i) apply @Finite.isOpen_biInter _ _ (generateFrom (⋃ u ∈ s', f u)) _ _ · apply f_fin u hu · intro i hi apply isOpen_generateFrom_of_mem simp grind section Sigma variable {ι : Type*} {E : ι → Type*} [∀ i, TopologicalSpace (E i)] /-- In a disjoint union space `Σ i, E i`, one can form a topological basis by taking the union of topological bases on each of the parts of the space. -/ theorem IsTopologicalBasis.sigma {s : ∀ i : ι, Set (Set (E i))} (hs : ∀ i, IsTopologicalBasis (s i)) : IsTopologicalBasis (⋃ i : ι, (fun u => (Sigma.mk i '' u : Set (Σ i, E i))) '' s i) := by refine .of_hasBasis_nhds fun a ↦ ?_ rw [Sigma.nhds_eq] convert (((hs a.1).nhds_hasBasis).map _).to_image_id aesop /-- A countable disjoint union of second countable spaces is second countable. -/ instance [Countable ι] [∀ i, SecondCountableTopology (E i)] : SecondCountableTopology (Σ i, E i) := by let b := ⋃ i : ι, (fun u => (Sigma.mk i '' u : Set (Σ i, E i))) '' countableBasis (E i) have A : IsTopologicalBasis b := IsTopologicalBasis.sigma fun i => isBasis_countableBasis _ have B : b.Countable := countable_iUnion fun i => (countable_countableBasis _).image _ exact A.secondCountableTopology B end Sigma section Sum variable {β : Type*} [TopologicalSpace β] /-- In a sum space `α ⊕ β`, one can form a topological basis by taking the union of topological bases on each of the two components. -/ theorem IsTopologicalBasis.sum {s : Set (Set α)} (hs : IsTopologicalBasis s) {t : Set (Set β)} (ht : IsTopologicalBasis t) : IsTopologicalBasis ((fun u => Sum.inl '' u) '' s ∪ (fun u => Sum.inr '' u) '' t) := by apply isTopologicalBasis_of_isOpen_of_nhds · rintro u (⟨w, hw, rfl⟩ | ⟨w, hw, rfl⟩) · exact IsOpenEmbedding.inl.isOpenMap w (hs.isOpen hw) · exact IsOpenEmbedding.inr.isOpenMap w (ht.isOpen hw) · rintro (x | x) u hxu u_open · obtain ⟨v, vs, xv, vu⟩ : ∃ v ∈ s, x ∈ v ∧ v ⊆ Sum.inl ⁻¹' u := hs.exists_subset_of_mem_open hxu (isOpen_sum_iff.1 u_open).1 exact ⟨Sum.inl '' v, mem_union_left _ (mem_image_of_mem _ vs), mem_image_of_mem _ xv, image_subset_iff.2 vu⟩ · obtain ⟨v, vs, xv, vu⟩ : ∃ v ∈ t, x ∈ v ∧ v ⊆ Sum.inr ⁻¹' u := ht.exists_subset_of_mem_open hxu (isOpen_sum_iff.1 u_open).2 exact ⟨Sum.inr '' v, mem_union_right _ (mem_image_of_mem _ vs), mem_image_of_mem _ xv, image_subset_iff.2 vu⟩ /-- A sum type of two second countable spaces is second countable. -/ instance [SecondCountableTopology α] [SecondCountableTopology β] : SecondCountableTopology (α ⊕ β) := by let b := (fun u => Sum.inl '' u) '' countableBasis α ∪ (fun u => Sum.inr '' u) '' countableBasis β have A : IsTopologicalBasis b := (isBasis_countableBasis α).sum (isBasis_countableBasis β) have B : b.Countable := (Countable.image (countable_countableBasis _) _).union (Countable.image (countable_countableBasis _) _) exact A.secondCountableTopology B end Sum section Quotient variable {X : Type*} [TopologicalSpace X] {Y : Type*} [TopologicalSpace Y] {π : X → Y} /-- The image of a topological basis under an open quotient map is a topological basis. -/ theorem IsTopologicalBasis.isQuotientMap {V : Set (Set X)} (hV : IsTopologicalBasis V) (h' : IsQuotientMap π) (h : IsOpenMap π) : IsTopologicalBasis (Set.image π '' V) := by apply isTopologicalBasis_of_isOpen_of_nhds · rintro - ⟨U, U_in_V, rfl⟩ apply h U (hV.isOpen U_in_V) · intro y U y_in_U U_open obtain ⟨x, rfl⟩ := h'.surjective y let W := π ⁻¹' U have x_in_W : x ∈ W := y_in_U have W_open : IsOpen W := U_open.preimage h'.continuous obtain ⟨Z, Z_in_V, x_in_Z, Z_in_W⟩ := hV.exists_subset_of_mem_open x_in_W W_open have XZ_in_U : π '' Z ⊆ U := (Set.image_mono Z_in_W).trans (image_preimage_subset π U) exact ⟨π '' Z, ⟨Z, Z_in_V, rfl⟩, ⟨x, x_in_Z, rfl⟩, XZ_in_U⟩ /-- A second countable space is mapped by an open quotient map to a second countable space. -/ theorem _root_.Topology.IsQuotientMap.secondCountableTopology [SecondCountableTopology X] (h' : IsQuotientMap π) (h : IsOpenMap π) : SecondCountableTopology Y where is_open_generated_countable := by obtain ⟨V, V_countable, -, V_generates⟩ := exists_countable_basis X exact ⟨Set.image π '' V, V_countable.image (Set.image π), (V_generates.isQuotientMap h' h).eq_generateFrom⟩ variable {S : Setoid X} /-- The image of a topological basis "downstairs" in an open quotient is a topological basis. -/ theorem IsTopologicalBasis.quotient {V : Set (Set X)} (hV : IsTopologicalBasis V) (h : IsOpenMap (Quotient.mk' : X → Quotient S)) : IsTopologicalBasis (Set.image (Quotient.mk' : X → Quotient S) '' V) := hV.isQuotientMap isQuotientMap_quotient_mk' h /-- An open quotient of a second countable space is second countable. -/ theorem Quotient.secondCountableTopology [SecondCountableTopology X] (h : IsOpenMap (Quotient.mk' : X → Quotient S)) : SecondCountableTopology (Quotient S) := isQuotientMap_quotient_mk'.secondCountableTopology h end Quotient end TopologicalSpace open TopologicalSpace variable {α β : Type*} [TopologicalSpace α] {f : α → β} protected theorem Topology.IsInducing.secondCountableTopology [TopologicalSpace β] [SecondCountableTopology β] (hf : IsInducing f) : SecondCountableTopology α := by rw [hf.1] exact secondCountableTopology_induced α β f protected theorem Topology.IsEmbedding.secondCountableTopology [TopologicalSpace β] [SecondCountableTopology β] (hf : IsEmbedding f) : SecondCountableTopology α := hf.1.secondCountableTopology protected theorem Topology.IsEmbedding.separableSpace [TopologicalSpace β] [SecondCountableTopology β] {f : α → β} (hf : IsEmbedding f) : TopologicalSpace.SeparableSpace α := by have := hf.secondCountableTopology exact SecondCountableTopology.to_separableSpace
.lake/packages/mathlib/Mathlib/Topology/FiberPartition.lean
import Mathlib.Topology.LocallyConstant.Basic import Mathlib.Logic.Function.FiberPartition /-! This file provides some API surrounding `Function.Fiber` (see `Mathlib/Logic/Function/FiberPartition.lean`) in the presence of a topology on the domain of the function. Note: this API is designed to be useful when defining the counit of the adjunction between the functor which takes a set to the condensed set corresponding to locally constant maps to that set, and the forgetful functor from the category of condensed sets to the category of sets (see PR https://github.com/leanprover-community/mathlib4/pull/14027). -/ open Function variable {S Y : Type*} (f : S → Y) namespace TopologicalSpace.Fiber variable [TopologicalSpace S] /-- The canonical map from the disjoint union induced by `f` to `S`. -/ @[simps apply] def sigmaIsoHom : C((x : Fiber f) × x.val, S) where toFun | ⟨a, x⟩ => x.val lemma sigmaIsoHom_inj : Function.Injective (sigmaIsoHom f) := by rintro ⟨⟨_, _, rfl⟩, ⟨_, hx⟩⟩ ⟨⟨_, _, rfl⟩, ⟨_, hy⟩⟩ h refine Sigma.subtype_ext ?_ h simp only [sigmaIsoHom_apply] at h rw [Set.mem_preimage, Set.mem_singleton_iff] at hx hy simp [← hx, ← hy, h] lemma sigmaIsoHom_surj : Function.Surjective (sigmaIsoHom f) := fun _ ↦ ⟨⟨⟨_, ⟨⟨_, Set.mem_range_self _⟩, rfl⟩⟩, ⟨_, rfl⟩⟩, rfl⟩ /-- The inclusion map from a component of the disjoint union induced by `f` into `S`. -/ def sigmaIncl (a : Fiber f) : C(a.val, S) where toFun x := x.val /-- The inclusion map from a fiber of a composition into the intermediate fiber. -/ def sigmaInclIncl {X : Type*} (g : Y → X) (a : Fiber (g ∘ f)) (b : Fiber (f ∘ (sigmaIncl (g ∘ f) a))) : C(b.val, (Fiber.mk f (b.preimage).val).val) where toFun x := ⟨x.val.val, by have := x.prop simp only [sigmaIncl, ContinuousMap.coe_mk, Fiber.mem_iff_eq_image, comp_apply] at this rw [Fiber.mem_iff_eq_image, Fiber.mk_image, this, ← Fiber.map_preimage_eq_image] simp [sigmaIncl]⟩ variable (l : LocallyConstant S Y) [CompactSpace S] instance (x : Fiber l) : CompactSpace x.val := by obtain ⟨y, hy⟩ := x.prop rw [← isCompact_iff_compactSpace, ← hy] exact (l.2.isClosed_fiber _).isCompact instance : Finite (Fiber l) := have : Finite (Set.range l) := l.range_finite Finite.Set.finite_range _ end TopologicalSpace.Fiber
.lake/packages/mathlib/Mathlib/Topology/Clopen.lean
import Mathlib.Data.Set.BoolIndicator import Mathlib.Topology.ContinuousOn /-! # Clopen sets A clopen set is a set that is both closed and open. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Clopen protected theorem IsClopen.isOpen (hs : IsClopen s) : IsOpen s := hs.2 protected theorem IsClopen.isClosed (hs : IsClopen s) : IsClosed s := hs.1 theorem isClopen_iff_frontier_eq_empty : IsClopen s ↔ frontier s = ∅ := by rw [IsClopen, ← closure_eq_iff_isClosed, ← interior_eq_iff_isOpen, frontier, diff_eq_empty] refine ⟨fun h => (h.1.trans h.2.symm).subset, fun h => ?_⟩ exact ⟨(h.trans interior_subset).antisymm subset_closure, interior_subset.antisymm (subset_closure.trans h)⟩ @[simp] alias ⟨IsClopen.frontier_eq, _⟩ := isClopen_iff_frontier_eq_empty theorem IsClopen.union (hs : IsClopen s) (ht : IsClopen t) : IsClopen (s ∪ t) := ⟨hs.1.union ht.1, hs.2.union ht.2⟩ theorem IsClopen.inter (hs : IsClopen s) (ht : IsClopen t) : IsClopen (s ∩ t) := ⟨hs.1.inter ht.1, hs.2.inter ht.2⟩ theorem isClopen_empty : IsClopen (∅ : Set X) := ⟨isClosed_empty, isOpen_empty⟩ theorem isClopen_univ : IsClopen (univ : Set X) := ⟨isClosed_univ, isOpen_univ⟩ theorem IsClopen.compl (hs : IsClopen s) : IsClopen sᶜ := ⟨hs.2.isClosed_compl, hs.1.isOpen_compl⟩ @[simp] theorem isClopen_compl_iff : IsClopen sᶜ ↔ IsClopen s := ⟨fun h => compl_compl s ▸ IsClopen.compl h, IsClopen.compl⟩ theorem IsClopen.diff (hs : IsClopen s) (ht : IsClopen t) : IsClopen (s \ t) := hs.inter ht.compl lemma IsClopen.himp (hs : IsClopen s) (ht : IsClopen t) : IsClopen (s ⇨ t) := by simpa [himp_eq] using ht.union hs.compl theorem IsClopen.prod {t : Set Y} (hs : IsClopen s) (ht : IsClopen t) : IsClopen (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem isClopen_iUnion_of_finite {Y} [Finite Y] {s : Y → Set X} (h : ∀ i, IsClopen (s i)) : IsClopen (⋃ i, s i) := ⟨isClosed_iUnion_of_finite (forall_and.1 h).1, isOpen_iUnion (forall_and.1 h).2⟩ theorem Set.Finite.isClopen_biUnion {Y} {s : Set Y} {f : Y → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClopen <| f i) : IsClopen (⋃ i ∈ s, f i) := ⟨hs.isClosed_biUnion fun i hi => (h i hi).1, isOpen_biUnion fun i hi => (h i hi).2⟩ theorem isClopen_biUnion_finset {Y} {s : Finset Y} {f : Y → Set X} (h : ∀ i ∈ s, IsClopen <| f i) : IsClopen (⋃ i ∈ s, f i) := s.finite_toSet.isClopen_biUnion h theorem isClopen_iInter_of_finite {Y} [Finite Y] {s : Y → Set X} (h : ∀ i, IsClopen (s i)) : IsClopen (⋂ i, s i) := ⟨isClosed_iInter (forall_and.1 h).1, isOpen_iInter_of_finite (forall_and.1 h).2⟩ theorem Set.Finite.isClopen_biInter {Y} {s : Set Y} (hs : s.Finite) {f : Y → Set X} (h : ∀ i ∈ s, IsClopen (f i)) : IsClopen (⋂ i ∈ s, f i) := ⟨isClosed_biInter fun i hi => (h i hi).1, hs.isOpen_biInter fun i hi => (h i hi).2⟩ theorem isClopen_biInter_finset {Y} {s : Finset Y} {f : Y → Set X} (h : ∀ i ∈ s, IsClopen (f i)) : IsClopen (⋂ i ∈ s, f i) := s.finite_toSet.isClopen_biInter h theorem IsClopen.preimage {s : Set Y} (h : IsClopen s) {f : X → Y} (hf : Continuous f) : IsClopen (f ⁻¹' s) := ⟨h.1.preimage hf, h.2.preimage hf⟩ theorem ContinuousOn.preimage_isClopen_of_isClopen {f : X → Y} {s : Set X} {t : Set Y} (hf : ContinuousOn f s) (hs : IsClopen s) (ht : IsClopen t) : IsClopen (s ∩ f ⁻¹' t) := ⟨ContinuousOn.preimage_isClosed_of_isClosed hf hs.1 ht.1, ContinuousOn.isOpen_inter_preimage hf hs.2 ht.2⟩ /-- The intersection of a disjoint covering by two open sets of a clopen set will be clopen. -/ theorem isClopen_inter_of_disjoint_cover_clopen {s a b : Set X} (h : IsClopen s) (cover : s ⊆ a ∪ b) (ha : IsOpen a) (hb : IsOpen b) (hab : Disjoint a b) : IsClopen (s ∩ a) := by refine ⟨?_, IsOpen.inter h.2 ha⟩ have : IsClosed (s ∩ bᶜ) := IsClosed.inter h.1 (isClosed_compl_iff.2 hb) convert this using 1 refine (inter_subset_inter_right s hab.subset_compl_right).antisymm ?_ rintro x ⟨hx₁, hx₂⟩ exact ⟨hx₁, by simpa [notMem_of_mem_compl hx₂] using cover hx₁⟩ theorem isClopen_of_disjoint_cover_open {a b : Set X} (cover : univ ⊆ a ∪ b) (ha : IsOpen a) (hb : IsOpen b) (hab : Disjoint a b) : IsClopen a := univ_inter a ▸ isClopen_inter_of_disjoint_cover_clopen isClopen_univ cover ha hb hab @[simp] theorem isClopen_discrete [DiscreteTopology X] (s : Set X) : IsClopen s := ⟨isClosed_discrete _, isOpen_discrete _⟩ theorem isClopen_range_inl : IsClopen (range (Sum.inl : X → X ⊕ Y)) := ⟨isClosed_range_inl, isOpen_range_inl⟩ theorem isClopen_range_inr : IsClopen (range (Sum.inr : Y → X ⊕ Y)) := ⟨isClosed_range_inr, isOpen_range_inr⟩ theorem isClopen_range_sigmaMk {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {i : ι} : IsClopen (Set.range (@Sigma.mk ι X i)) := ⟨IsClosedEmbedding.sigmaMk.isClosed_range, IsOpenEmbedding.sigmaMk.isOpen_range⟩ protected theorem Topology.IsQuotientMap.isClopen_preimage {f : X → Y} (hf : IsQuotientMap f) {s : Set Y} : IsClopen (f ⁻¹' s) ↔ IsClopen s := and_congr hf.isClosed_preimage hf.isOpen_preimage theorem continuous_boolIndicator_iff_isClopen (U : Set X) : Continuous U.boolIndicator ↔ IsClopen U := by rw [continuous_bool_rng true, preimage_boolIndicator_true] theorem continuousOn_boolIndicator_iff_isClopen (s U : Set X) : ContinuousOn U.boolIndicator s ↔ IsClopen (((↑) : s → X) ⁻¹' U) := by rw [continuousOn_iff_continuous_restrict, ← continuous_boolIndicator_iff_isClopen] rfl end Clopen
.lake/packages/mathlib/Mathlib/Topology/ClusterPt.lean
import Mathlib.Topology.Neighborhoods /-! # Lemmas on cluster and accumulation points In this file we prove various lemmas on [cluster points](https://en.wikipedia.org/wiki/Limit_point) (also known as limit points and accumulation points) of a filter and of a sequence. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. -/ open Set Filter Topology universe u v w variable {X : Type u} [TopologicalSpace X] {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} theorem clusterPt_sup {F G : Filter X} : ClusterPt x (F ⊔ G) ↔ ClusterPt x F ∨ ClusterPt x G := by simp only [ClusterPt, inf_sup_left, sup_neBot] theorem ClusterPt.neBot {F : Filter X} (h : ClusterPt x F) : NeBot (𝓝 x ⊓ F) := h theorem Filter.HasBasis.clusterPt_iff {ιX ιF} {pX : ιX → Prop} {sX : ιX → Set X} {pF : ιF → Prop} {sF : ιF → Set X} {F : Filter X} (hX : (𝓝 x).HasBasis pX sX) (hF : F.HasBasis pF sF) : ClusterPt x F ↔ ∀ ⦃i⦄, pX i → ∀ ⦃j⦄, pF j → (sX i ∩ sF j).Nonempty := hX.inf_basis_neBot_iff hF theorem Filter.HasBasis.clusterPt_iff_frequently {ι} {p : ι → Prop} {s : ι → Set X} {F : Filter X} (hx : (𝓝 x).HasBasis p s) : ClusterPt x F ↔ ∀ i, p i → ∃ᶠ x in F, x ∈ s i := by simp only [hx.clusterPt_iff F.basis_sets, Filter.frequently_iff, inter_comm (s _), Set.Nonempty, id, mem_inter_iff] theorem clusterPt_iff_frequently {F : Filter X} : ClusterPt x F ↔ ∀ s ∈ 𝓝 x, ∃ᶠ y in F, y ∈ s := (𝓝 x).basis_sets.clusterPt_iff_frequently theorem ClusterPt.frequently {F : Filter X} {p : X → Prop} (hx : ClusterPt x F) (hp : ∀ᶠ y in 𝓝 x, p y) : ∃ᶠ y in F, p y := clusterPt_iff_frequently.mp hx {y | p y} hp theorem Filter.HasBasis.clusterPt_iff_frequently' {ι} {p : ι → Prop} {s : ι → Set X} {F : Filter X} (hx : F.HasBasis p s) : ClusterPt x F ↔ ∀ i, p i → ∃ᶠ x in 𝓝 x, x ∈ s i := by simp only [(𝓝 x).basis_sets.clusterPt_iff hx, Filter.frequently_iff] exact ⟨fun h a b c d ↦ h d b, fun h a b c d ↦ h c d b⟩ theorem clusterPt_iff_frequently' {F : Filter X} : ClusterPt x F ↔ ∀ s ∈ F, ∃ᶠ y in 𝓝 x, y ∈ s := F.basis_sets.clusterPt_iff_frequently' theorem ClusterPt.frequently' {F : Filter X} {p : X → Prop} (hx : ClusterPt x F) (hp : ∀ᶠ y in F, p y) : ∃ᶠ y in 𝓝 x, p y := clusterPt_iff_frequently'.mp hx {y | p y} hp theorem clusterPt_iff_nonempty {F : Filter X} : ClusterPt x F ↔ ∀ ⦃U : Set X⦄, U ∈ 𝓝 x → ∀ ⦃V⦄, V ∈ F → (U ∩ V).Nonempty := inf_neBot_iff theorem clusterPt_iff_not_disjoint {F : Filter X} : ClusterPt x F ↔ ¬Disjoint (𝓝 x) F := by rw [disjoint_iff, ClusterPt, neBot_iff] protected theorem Filter.HasBasis.clusterPt_iff_forall_mem_closure {ι} {p : ι → Prop} {s : ι → Set X} {F : Filter X} (hF : F.HasBasis p s) : ClusterPt x F ↔ ∀ i, p i → x ∈ closure (s i) := by simp only [(nhds_basis_opens _).clusterPt_iff hF, mem_closure_iff] tauto theorem clusterPt_iff_forall_mem_closure {F : Filter X} : ClusterPt x F ↔ ∀ s ∈ F, x ∈ closure s := F.basis_sets.clusterPt_iff_forall_mem_closure alias ⟨ClusterPt.mem_closure_of_mem, _⟩ := clusterPt_iff_forall_mem_closure /-- `x` is a cluster point of a set `s` if every neighbourhood of `x` meets `s` on a nonempty set. See also `mem_closure_iff_clusterPt`. -/ theorem clusterPt_principal_iff : ClusterPt x (𝓟 s) ↔ ∀ U ∈ 𝓝 x, (U ∩ s).Nonempty := inf_principal_neBot_iff theorem clusterPt_principal_iff_frequently : ClusterPt x (𝓟 s) ↔ ∃ᶠ y in 𝓝 x, y ∈ s := by simp only [clusterPt_principal_iff, frequently_iff, Set.Nonempty, mem_inter_iff] theorem ClusterPt.of_le_nhds {f : Filter X} (H : f ≤ 𝓝 x) [NeBot f] : ClusterPt x f := by rwa [ClusterPt, inf_eq_right.mpr H] theorem ClusterPt.of_le_nhds' {f : Filter X} (H : f ≤ 𝓝 x) (_hf : NeBot f) : ClusterPt x f := ClusterPt.of_le_nhds H theorem ClusterPt.of_nhds_le {f : Filter X} (H : 𝓝 x ≤ f) : ClusterPt x f := by simp only [ClusterPt, inf_eq_left.mpr H, nhds_neBot] theorem ClusterPt.mono {f g : Filter X} (H : ClusterPt x f) (h : f ≤ g) : ClusterPt x g := NeBot.mono H <| inf_le_inf_left _ h theorem ClusterPt.of_inf_left {f g : Filter X} (H : ClusterPt x <| f ⊓ g) : ClusterPt x f := H.mono inf_le_left theorem ClusterPt.of_inf_right {f g : Filter X} (H : ClusterPt x <| f ⊓ g) : ClusterPt x g := H.mono inf_le_right section MapClusterPt variable {F : Filter α} {u : α → X} {x : X} theorem mapClusterPt_def : MapClusterPt x F u ↔ ClusterPt x (map u F) := Iff.rfl alias ⟨MapClusterPt.clusterPt, _⟩ := mapClusterPt_def theorem Filter.EventuallyEq.mapClusterPt_iff {v : α → X} (h : u =ᶠ[F] v) : MapClusterPt x F u ↔ MapClusterPt x F v := by simp only [mapClusterPt_def, map_congr h] alias ⟨MapClusterPt.congrFun, _⟩ := Filter.EventuallyEq.mapClusterPt_iff theorem MapClusterPt.mono {G : Filter α} (h : MapClusterPt x F u) (hle : F ≤ G) : MapClusterPt x G u := h.clusterPt.mono (map_mono hle) theorem MapClusterPt.tendsto_comp' [TopologicalSpace Y] {f : X → Y} {y : Y} (hf : Tendsto f (𝓝 x ⊓ map u F) (𝓝 y)) (hu : MapClusterPt x F u) : MapClusterPt y F (f ∘ u) := (tendsto_inf.2 ⟨hf, tendsto_map.mono_left inf_le_right⟩).neBot (hx := hu) theorem MapClusterPt.tendsto_comp [TopologicalSpace Y] {f : X → Y} {y : Y} (hf : Tendsto f (𝓝 x) (𝓝 y)) (hu : MapClusterPt x F u) : MapClusterPt y F (f ∘ u) := hu.tendsto_comp' (hf.mono_left inf_le_left) theorem MapClusterPt.continuousAt_comp [TopologicalSpace Y] {f : X → Y} (hf : ContinuousAt f x) (hu : MapClusterPt x F u) : MapClusterPt (f x) F (f ∘ u) := hu.tendsto_comp hf theorem Filter.HasBasis.mapClusterPt_iff_frequently {ι : Sort*} {p : ι → Prop} {s : ι → Set X} (hx : (𝓝 x).HasBasis p s) : MapClusterPt x F u ↔ ∀ i, p i → ∃ᶠ a in F, u a ∈ s i := by simp_rw [MapClusterPt, hx.clusterPt_iff_frequently, frequently_map] theorem mapClusterPt_iff_frequently : MapClusterPt x F u ↔ ∀ s ∈ 𝓝 x, ∃ᶠ a in F, u a ∈ s := (𝓝 x).basis_sets.mapClusterPt_iff_frequently theorem MapClusterPt.frequently (h : MapClusterPt x F u) {p : X → Prop} (hp : ∀ᶠ y in 𝓝 x, p y) : ∃ᶠ a in F, p (u a) := h.clusterPt.frequently hp theorem mapClusterPt_comp {φ : α → β} {u : β → X} : MapClusterPt x F (u ∘ φ) ↔ MapClusterPt x (map φ F) u := Iff.rfl theorem Filter.Tendsto.mapClusterPt [NeBot F] (h : Tendsto u F (𝓝 x)) : MapClusterPt x F u := .of_le_nhds h theorem MapClusterPt.of_comp {φ : β → α} {p : Filter β} (h : Tendsto φ p F) (H : MapClusterPt x p (u ∘ φ)) : MapClusterPt x F u := H.clusterPt.mono <| map_mono h end MapClusterPt theorem accPt_sup {x : X} {F G : Filter X} : AccPt x (F ⊔ G) ↔ AccPt x F ∨ AccPt x G := by simp only [AccPt, inf_sup_left, sup_neBot] theorem accPt_iff_clusterPt {x : X} {F : Filter X} : AccPt x F ↔ ClusterPt x (𝓟 {x}ᶜ ⊓ F) := by rw [AccPt, nhdsWithin, ClusterPt, inf_assoc] /-- `x` is an accumulation point of a set `C` iff it is a cluster point of `C ∖ {x}`. -/ theorem accPt_principal_iff_clusterPt {x : X} {C : Set X} : AccPt x (𝓟 C) ↔ ClusterPt x (𝓟 (C \ { x })) := by rw [accPt_iff_clusterPt, inf_principal, inter_comm, diff_eq] /-- `x` is an accumulation point of a set `C` iff every neighborhood of `x` contains a point of `C` other than `x`. -/ theorem accPt_iff_nhds {x : X} {C : Set X} : AccPt x (𝓟 C) ↔ ∀ U ∈ 𝓝 x, ∃ y ∈ U ∩ C, y ≠ x := by simp [accPt_principal_iff_clusterPt, clusterPt_principal_iff, Set.Nonempty, and_assoc] /-- `x` is an accumulation point of a set `C` iff there are points near `x` in `C` and different from `x`. -/ theorem accPt_iff_frequently {x : X} {C : Set X} : AccPt x (𝓟 C) ↔ ∃ᶠ y in 𝓝 x, y ≠ x ∧ y ∈ C := by simp [accPt_principal_iff_clusterPt, clusterPt_principal_iff_frequently, and_comm] /-- Variant of `accPt_iff_frequently`: A point `x` is an accumulation point of a set `C` iff points in punctured neighborhoods are frequently contained in `C`. -/ theorem accPt_iff_frequently_nhdsNE {X : Type*} [TopologicalSpace X] {x : X} {C : Set X} : AccPt x (𝓟 C) ↔ ∃ᶠ (y : X) in 𝓝[≠] x, y ∈ C := by have : (∃ᶠ z in 𝓝[≠] x, z ∈ C) ↔ ∃ᶠ z in 𝓝 x, z ∈ C ∧ z ∈ ({x} : Set X)ᶜ := frequently_inf_principal.trans <| by simp only [and_comm] rw [accPt_iff_frequently, this] congr! 2 tauto theorem accPt_principal_iff_nhdsWithin : AccPt x (𝓟 s) ↔ (𝓝[s \ {x}] x).NeBot := by rw [accPt_principal_iff_clusterPt, ClusterPt, nhdsWithin] /-- If `x` is an accumulation point of `F` and `F ≤ G`, then `x` is an accumulation point of `G`. -/ theorem AccPt.mono {F G : Filter X} (h : AccPt x F) (hFG : F ≤ G) : AccPt x G := NeBot.mono h (inf_le_inf_left _ hFG) theorem AccPt.clusterPt {x : X} {F : Filter X} (h : AccPt x F) : ClusterPt x F := (accPt_iff_clusterPt.mp h).mono inf_le_right theorem clusterPt_principal {x : X} {C : Set X} : ClusterPt x (𝓟 C) ↔ x ∈ C ∨ AccPt x (𝓟 C) := by constructor · intro h by_contra! hc rw [accPt_principal_iff_clusterPt] at hc simp_all only [not_false_eq_true, diff_singleton_eq_self, not_true_eq_false, hc.1] · rintro (h | h) · exact clusterPt_principal_iff.mpr fun _ mem ↦ ⟨x, ⟨mem_of_mem_nhds mem, h⟩⟩ · exact h.clusterPt /-- The set of cluster points of a filter is closed. In particular, the set of limit points of a sequence is closed. -/ theorem isClosed_setOf_clusterPt {f : Filter X} : IsClosed { x | ClusterPt x f } := by simp only [clusterPt_iff_forall_mem_closure, setOf_forall] exact isClosed_biInter fun _ _ ↦ isClosed_closure theorem mem_closure_iff_clusterPt : x ∈ closure s ↔ ClusterPt x (𝓟 s) := mem_closure_iff_frequently.trans clusterPt_principal_iff_frequently.symm alias ⟨_, ClusterPt.mem_closure⟩ := mem_closure_iff_clusterPt theorem mem_closure_iff_nhds_ne_bot : x ∈ closure s ↔ 𝓝 x ⊓ 𝓟 s ≠ ⊥ := mem_closure_iff_clusterPt.trans neBot_iff theorem mem_closure_iff_nhdsWithin_neBot : x ∈ closure s ↔ NeBot (𝓝[s] x) := mem_closure_iff_clusterPt lemma notMem_closure_iff_nhdsWithin_eq_bot : x ∉ closure s ↔ 𝓝[s] x = ⊥ := by rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] @[deprecated (since := "2025-05-23")] alias not_mem_closure_iff_nhdsWithin_eq_bot := notMem_closure_iff_nhdsWithin_eq_bot theorem mem_interior_iff_not_clusterPt_compl : x ∈ interior s ↔ ¬ClusterPt x (𝓟 sᶜ) := by rw [← mem_closure_iff_clusterPt, closure_compl, mem_compl_iff, not_not] /-- If `x` is not an isolated point of a topological space, then `{x}ᶜ` is dense in the whole space. -/ theorem dense_compl_singleton (x : X) [NeBot (𝓝[≠] x)] : Dense ({x}ᶜ : Set X) := by intro y rcases eq_or_ne y x with (rfl | hne) · rwa [mem_closure_iff_nhdsWithin_neBot] · exact subset_closure hne /-- If `x` is not an isolated point of a topological space, then the closure of `{x}ᶜ` is the whole space. -/ theorem closure_compl_singleton (x : X) [NeBot (𝓝[≠] x)] : closure {x}ᶜ = (univ : Set X) := (dense_compl_singleton x).closure_eq /-- If `x` is not an isolated point of a topological space, then the interior of `{x}` is empty. -/ @[simp] theorem interior_singleton (x : X) [NeBot (𝓝[≠] x)] : interior {x} = (∅ : Set X) := interior_eq_empty_iff_dense_compl.2 (dense_compl_singleton x) theorem not_isOpen_singleton (x : X) [NeBot (𝓝[≠] x)] : ¬IsOpen ({x} : Set X) := dense_compl_singleton_iff_not_open.1 (dense_compl_singleton x) theorem closure_eq_cluster_pts : closure s = { a | ClusterPt a (𝓟 s) } := Set.ext fun _ => mem_closure_iff_clusterPt theorem mem_closure_iff_nhds : x ∈ closure s ↔ ∀ t ∈ 𝓝 x, (t ∩ s).Nonempty := mem_closure_iff_clusterPt.trans clusterPt_principal_iff theorem mem_closure_iff_nhds' : x ∈ closure s ↔ ∀ t ∈ 𝓝 x, ∃ y : s, ↑y ∈ t := by simp only [mem_closure_iff_nhds, Set.inter_nonempty_iff_exists_right, SetCoe.exists, exists_prop] theorem mem_closure_iff_comap_neBot : x ∈ closure s ↔ NeBot (comap ((↑) : s → X) (𝓝 x)) := by simp_rw [mem_closure_iff_nhds, comap_neBot_iff, Set.inter_nonempty_iff_exists_right, SetCoe.exists, exists_prop] theorem mem_closure_iff_nhds_basis' {p : ι → Prop} {s : ι → Set X} (h : (𝓝 x).HasBasis p s) : x ∈ closure t ↔ ∀ i, p i → (s i ∩ t).Nonempty := mem_closure_iff_clusterPt.trans <| (h.clusterPt_iff (hasBasis_principal _)).trans <| by simp only [forall_const] theorem mem_closure_iff_nhds_basis {p : ι → Prop} {s : ι → Set X} (h : (𝓝 x).HasBasis p s) : x ∈ closure t ↔ ∀ i, p i → ∃ y ∈ t, y ∈ s i := (mem_closure_iff_nhds_basis' h).trans <| by simp only [Set.Nonempty, mem_inter_iff, and_comm] theorem clusterPt_iff_lift'_closure {F : Filter X} : ClusterPt x F ↔ pure x ≤ (F.lift' closure) := by simp_rw [clusterPt_iff_forall_mem_closure, (hasBasis_pure _).le_basis_iff F.basis_sets.lift'_closure, id, singleton_subset_iff, true_and, exists_const] theorem clusterPt_iff_lift'_closure' {F : Filter X} : ClusterPt x F ↔ (F.lift' closure ⊓ pure x).NeBot := by rw [clusterPt_iff_lift'_closure, inf_comm] constructor · intro h simp [h, pure_neBot] · intro h U hU simp_rw [← forall_mem_nonempty_iff_neBot, mem_inf_iff] at h simpa using h ({x} ∩ U) ⟨{x}, by simp, U, hU, rfl⟩ @[simp] theorem clusterPt_lift'_closure_iff {F : Filter X} : ClusterPt x (F.lift' closure) ↔ ClusterPt x F := by simp [clusterPt_iff_lift'_closure, lift'_lift'_assoc (monotone_closure X) (monotone_closure X)] theorem isClosed_iff_clusterPt : IsClosed s ↔ ∀ a, ClusterPt a (𝓟 s) → a ∈ s := calc IsClosed s ↔ closure s ⊆ s := closure_subset_iff_isClosed.symm _ ↔ ∀ a, ClusterPt a (𝓟 s) → a ∈ s := by simp only [subset_def, mem_closure_iff_clusterPt] theorem isClosed_iff_nhds : IsClosed s ↔ ∀ x, (∀ U ∈ 𝓝 x, (U ∩ s).Nonempty) → x ∈ s := by simp_rw [isClosed_iff_clusterPt, ClusterPt, inf_principal_neBot_iff] lemma isClosed_iff_forall_filter : IsClosed s ↔ ∀ x, ∀ F : Filter X, F.NeBot → F ≤ 𝓟 s → F ≤ 𝓝 x → x ∈ s := by simp_rw [isClosed_iff_clusterPt] exact ⟨fun hs x F F_ne FS Fx ↦ hs _ <| NeBot.mono F_ne (le_inf Fx FS), fun hs x hx ↦ hs x (𝓝 x ⊓ 𝓟 s) hx inf_le_right inf_le_left⟩ theorem mem_closure_of_mem_closure_union (h : x ∈ closure (s₁ ∪ s₂)) (h₁ : s₁ᶜ ∈ 𝓝 x) : x ∈ closure s₂ := by rw [mem_closure_iff_nhds_ne_bot] at * rwa [← sup_principal, inf_sup_left, inf_principal_eq_bot.mpr h₁, bot_sup_eq] at h
.lake/packages/mathlib/Mathlib/Topology/DerivedSet.lean
import Mathlib.Topology.Perfect import Mathlib.Tactic.Peel /-! # Derived set This file defines the derived set of a set, the set of all `AccPt`s of its principal filter, and proves some properties of it. -/ open Filter Topology variable {X : Type*} [TopologicalSpace X] theorem AccPt.map {β : Type*} [TopologicalSpace β] {F : Filter X} {x : X} (h : AccPt x F) {f : X → β} (hf1 : ContinuousAt f x) (hf2 : Function.Injective f) : AccPt (f x) (map f F) := by apply map_neBot (m := f) (hf := h) |>.mono rw [Filter.map_inf hf2] gcongr apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ hf1.continuousWithinAt simpa [hf2.eq_iff] using eventually_mem_nhdsWithin /-- The derived set of a set is the set of all accumulation points of it. -/ def derivedSet (A : Set X) : Set X := {x | AccPt x (𝓟 A)} @[simp] lemma mem_derivedSet {A : Set X} {x : X} : x ∈ derivedSet A ↔ AccPt x (𝓟 A) := Iff.rfl lemma derivedSet_union (A B : Set X) : derivedSet (A ∪ B) = derivedSet A ∪ derivedSet B := by ext x simp [derivedSet, ← sup_principal, accPt_sup] lemma derivedSet_mono (A B : Set X) (h : A ⊆ B) : derivedSet A ⊆ derivedSet B := fun _ hx ↦ hx.mono <| le_principal_iff.mpr <| mem_principal.mpr h theorem Continuous.image_derivedSet {β : Type*} [TopologicalSpace β] {A : Set X} {f : X → β} (hf1 : Continuous f) (hf2 : Function.Injective f) : f '' derivedSet A ⊆ derivedSet (f '' A) := by intro x hx simp only [Set.mem_image, mem_derivedSet] at hx obtain ⟨y, hy1, rfl⟩ := hx convert hy1.map hf1.continuousAt hf2 simp lemma derivedSet_subset_closure (A : Set X) : derivedSet A ⊆ closure A := fun _ hx ↦ mem_closure_iff_clusterPt.mpr hx.clusterPt lemma isClosed_iff_derivedSet_subset (A : Set X) : IsClosed A ↔ derivedSet A ⊆ A where mp h := derivedSet_subset_closure A |>.trans h.closure_subset mpr h := by rw [isClosed_iff_clusterPt] intro a ha by_contra! nh have : A = A \ {a} := by simp [nh] rw [this, ← accPt_principal_iff_clusterPt] at ha exact nh (h ha) lemma closure_eq_self_union_derivedSet (A : Set X) : closure A = A ∪ derivedSet A := by ext simp [closure_eq_cluster_pts, clusterPt_principal] /-- In a `T1Space`, the `derivedSet` of the closure of a set is equal to the derived set of the set itself. Note: this doesn't hold in a space with the indiscrete topology. For example, if `X` is a type with two elements, `x` and `y`, and `A := {x}`, then `closure A = Set.univ` and `derivedSet A = {y}`, but `derivedSet Set.univ = Set.univ`. -/ lemma derivedSet_closure [T1Space X] (A : Set X) : derivedSet (closure A) = derivedSet A := by refine le_antisymm (fun x hx => ?_) (derivedSet_mono _ _ subset_closure) rw [mem_derivedSet, AccPt, (nhdsWithin_basis_open x {x}ᶜ).inf_principal_neBot_iff] at hx ⊢ peel hx with u hu _ obtain ⟨-, hu_open⟩ := hu exact mem_closure_iff.mp this.some_mem.2 (u ∩ {x}ᶜ) (hu_open.inter isOpen_compl_singleton) this.some_mem.1 @[simp] lemma isClosed_derivedSet [T1Space X] (A : Set X) : IsClosed (derivedSet A) := by rw [← derivedSet_closure, isClosed_iff_derivedSet_subset] apply derivedSet_mono simp [← isClosed_iff_derivedSet_subset] lemma preperfect_iff_subset_derivedSet {U : Set X} : Preperfect U ↔ U ⊆ derivedSet U := Iff.rfl lemma perfect_iff_eq_derivedSet {U : Set X} : Perfect U ↔ U = derivedSet U := by rw [perfect_def, isClosed_iff_derivedSet_subset, preperfect_iff_subset_derivedSet, ← subset_antisymm_iff, eq_comm] lemma IsPreconnected.inter_derivedSet_nonempty [T1Space X] {U : Set X} (hs : IsPreconnected U) (a b : Set X) (h : U ⊆ a ∪ b) (ha : (U ∩ derivedSet a).Nonempty) (hb : (U ∩ derivedSet b).Nonempty) : (U ∩ (derivedSet a ∩ derivedSet b)).Nonempty := by by_cases hu : U.Nontrivial · apply isPreconnected_closed_iff.mp hs · simp · simp · trans derivedSet U · apply hs.preperfect_of_nontrivial hu · rw [← derivedSet_union] exact derivedSet_mono _ _ h · exact ha · exact hb · obtain ⟨x, hx⟩ := ha.left.exists_eq_singleton_or_nontrivial.resolve_right hu simp_all
.lake/packages/mathlib/Mathlib/Topology/List.lean
import Mathlib.Topology.Constructions import Mathlib.Order.Filter.ListTraverse import Mathlib.Tactic.AdaptationNote import Mathlib.Topology.Algebra.Monoid.Defs /-! # Topology on lists and vectors -/ open TopologicalSpace Set Filter open Topology variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] instance : TopologicalSpace (List α) := TopologicalSpace.mkOfNhds (traverse nhds) theorem nhds_list (as : List α) : 𝓝 as = traverse 𝓝 as := by refine nhds_mkOfNhds _ _ ?_ ?_ · intro l induction l with | nil => exact le_rfl | cons a l ih => suffices List.cons <$> pure a <*> pure l ≤ List.cons <$> 𝓝 a <*> traverse 𝓝 l by simpa only [functor_norm] using this exact Filter.seq_mono (Filter.map_mono <| pure_le_nhds a) ih · intro l s hs rcases (mem_traverse_iff _ _).1 hs with ⟨u, hu, hus⟩ clear as hs have : ∃ v : List (Set α), l.Forall₂ (fun a s => IsOpen s ∧ a ∈ s) v ∧ sequence v ⊆ s := by induction hu generalizing s with | nil => exists [] simp only [List.forall₂_nil_left_iff] exact ⟨trivial, hus⟩ | cons ht _ ih => rcases mem_nhds_iff.1 ht with ⟨u, hut, hu⟩ rcases ih _ Subset.rfl with ⟨v, hv, hvss⟩ exact ⟨u::v, List.Forall₂.cons hu hv, Subset.trans (Set.seq_mono (Set.image_mono hut) hvss) hus⟩ rcases this with ⟨v, hv, hvs⟩ have : sequence v ∈ traverse 𝓝 l := mem_traverse _ _ <| hv.imp fun a s ⟨hs, ha⟩ => IsOpen.mem_nhds hs ha refine mem_of_superset this fun u hu ↦ ?_ have hu := (List.mem_traverse _ _).1 hu have : List.Forall₂ (fun a s => IsOpen s ∧ a ∈ s) u v := by refine List.Forall₂.flip ?_ replace hv := hv.flip simp only [List.forall₂_and_left, Function.flip_def] at hv ⊢ exact ⟨hv.1, hu.flip⟩ refine mem_of_superset ?_ hvs exact mem_traverse _ _ (this.imp fun a s ⟨hs, ha⟩ => IsOpen.mem_nhds hs ha) @[simp] theorem nhds_nil : 𝓝 ([] : List α) = pure [] := by rw [nhds_list, List.traverse_nil _] theorem nhds_cons (a : α) (l : List α) : 𝓝 (a::l) = List.cons <$> 𝓝 a <*> 𝓝 l := by rw [nhds_list, List.traverse_cons _, ← nhds_list] theorem List.tendsto_cons {a : α} {l : List α} : Tendsto (fun p : α × List α => List.cons p.1 p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (a::l)) := by rw [nhds_cons, Tendsto, Filter.map_prod]; exact le_rfl theorem Filter.Tendsto.cons {α : Type*} {f : α → β} {g : α → List β} {a : Filter α} {b : β} {l : List β} (hf : Tendsto f a (𝓝 b)) (hg : Tendsto g a (𝓝 l)) : Tendsto (fun a => List.cons (f a) (g a)) a (𝓝 (b::l)) := List.tendsto_cons.comp (Tendsto.prodMk hf hg) namespace List theorem tendsto_cons_iff {β : Type*} {f : List α → β} {b : Filter β} {a : α} {l : List α} : Tendsto f (𝓝 (a::l)) b ↔ Tendsto (fun p : α × List α => f (p.1::p.2)) (𝓝 a ×ˢ 𝓝 l) b := by have : 𝓝 (a::l) = (𝓝 a ×ˢ 𝓝 l).map fun p : α × List α => p.1::p.2 := by simp only [nhds_cons, Filter.prod_eq, (Filter.map_def _ _).symm, (Filter.seq_eq_filter_seq _ _).symm] simp [-Filter.map_def, Function.comp_def, functor_norm] rw [this, Filter.tendsto_map'_iff]; rfl theorem continuous_cons : Continuous fun x : α × List α => (x.1::x.2 : List α) := continuous_iff_continuousAt.mpr fun ⟨_x, _y⟩ => continuousAt_fst.cons continuousAt_snd theorem tendsto_nhds {β : Type*} {f : List α → β} {r : List α → Filter β} (h_nil : Tendsto f (pure []) (r [])) (h_cons : ∀ l a, Tendsto f (𝓝 l) (r l) → Tendsto (fun p : α × List α => f (p.1::p.2)) (𝓝 a ×ˢ 𝓝 l) (r (a::l))) : ∀ l, Tendsto f (𝓝 l) (r l) | [] => by rwa [nhds_nil] | a::l => by rw [tendsto_cons_iff]; exact h_cons l a (@tendsto_nhds _ _ _ h_nil h_cons l) instance [DiscreteTopology α] : DiscreteTopology (List α) := by rw [discreteTopology_iff_nhds]; intro l; induction l <;> simp [*, nhds_cons] theorem continuousAt_length : ∀ l : List α, ContinuousAt List.length l := by simp only [ContinuousAt, nhds_discrete] refine tendsto_nhds ?_ ?_ · exact tendsto_pure_pure _ _ · intro l a ih dsimp only [List.length] refine Tendsto.comp (tendsto_pure_pure (fun x => x + 1) _) ?_ exact Tendsto.comp ih tendsto_snd /-- Continuity of `insertIdx` in terms of `Tendsto`. -/ theorem tendsto_insertIdx' {a : α} : ∀ {n : ℕ} {l : List α}, Tendsto (fun p : α × List α => p.2.insertIdx n p.1) (𝓝 a ×ˢ 𝓝 l) (𝓝 (l.insertIdx n a)) | 0, _ => tendsto_cons | n + 1, [] => by simp | n + 1, a'::l => by have : 𝓝 a ×ˢ 𝓝 (a'::l) = (𝓝 a ×ˢ (𝓝 a' ×ˢ 𝓝 l)).map fun p : α × α × List α => (p.1, p.2.1::p.2.2) := by simp only [nhds_cons, Filter.prod_eq, ← Filter.map_def, ← Filter.seq_eq_filter_seq] simp [-Filter.map_def, Function.comp_def, functor_norm] rw [this, tendsto_map'_iff] exact (tendsto_fst.comp tendsto_snd).cons ((@tendsto_insertIdx' _ n l).comp <| tendsto_fst.prodMk <| tendsto_snd.comp tendsto_snd) theorem tendsto_insertIdx {β} {n : ℕ} {a : α} {l : List α} {f : β → α} {g : β → List α} {b : Filter β} (hf : Tendsto f b (𝓝 a)) (hg : Tendsto g b (𝓝 l)) : Tendsto (fun b : β => (g b).insertIdx n (f b)) b (𝓝 (l.insertIdx n a)) := tendsto_insertIdx'.comp (hf.prodMk hg) theorem continuous_insertIdx {n : ℕ} : Continuous fun p : α × List α => p.2.insertIdx n p.1 := continuous_iff_continuousAt.mpr fun ⟨a, l⟩ => by rw [ContinuousAt, nhds_prod_eq]; exact tendsto_insertIdx' theorem tendsto_eraseIdx : ∀ {n : ℕ} {l : List α}, Tendsto (eraseIdx · n) (𝓝 l) (𝓝 (eraseIdx l n)) | _, [] => by rw [nhds_nil]; exact tendsto_pure_nhds _ _ | 0, a::l => by rw [tendsto_cons_iff]; exact tendsto_snd | n + 1, a::l => by rw [tendsto_cons_iff] dsimp [eraseIdx] exact tendsto_fst.cons ((@tendsto_eraseIdx n l).comp tendsto_snd) theorem continuous_eraseIdx {n : ℕ} : Continuous fun l : List α => eraseIdx l n := continuous_iff_continuousAt.mpr fun _a => tendsto_eraseIdx @[to_additive] theorem tendsto_prod [MulOneClass α] [ContinuousMul α] {l : List α} : Tendsto List.prod (𝓝 l) (𝓝 l.prod) := by induction l with | nil => simp +contextual [nhds_nil, mem_of_mem_nhds, tendsto_pure_left] | cons x l ih => simp_rw [tendsto_cons_iff, prod_cons] have := continuous_iff_continuousAt.mp continuous_mul (x, l.prod) rw [ContinuousAt, nhds_prod_eq] at this exact this.comp (tendsto_id.prodMap ih) @[to_additive] theorem continuous_prod [MulOneClass α] [ContinuousMul α] : Continuous (prod : List α → α) := continuous_iff_continuousAt.mpr fun _l => tendsto_prod end List namespace List.Vector instance (n : ℕ) : TopologicalSpace (Vector α n) := by unfold Vector; infer_instance theorem tendsto_cons {n : ℕ} {a : α} {l : Vector α n} : Tendsto (fun p : α × Vector α n => p.1 ::ᵥ p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (a ::ᵥ l)) := by rw [tendsto_subtype_rng, Vector.cons_val] exact tendsto_fst.cons (Tendsto.comp continuousAt_subtype_val tendsto_snd) theorem tendsto_insertIdx {n : ℕ} {i : Fin (n + 1)} {a : α} : ∀ {l : Vector α n}, Tendsto (fun p : α × Vector α n => insertIdx p.1 i p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (insertIdx a i l)) | ⟨l, hl⟩ => by rw [insertIdx, tendsto_subtype_rng] simp only [insertIdx_val] exact List.tendsto_insertIdx tendsto_fst (Tendsto.comp continuousAt_subtype_val tendsto_snd : _) /-- Continuity of `Vector.insertIdx`. -/ theorem continuous_insertIdx' {n : ℕ} {i : Fin (n + 1)} : Continuous fun p : α × Vector α n => Vector.insertIdx p.1 i p.2 := continuous_iff_continuousAt.mpr fun ⟨a, l⟩ => by rw [ContinuousAt, nhds_prod_eq]; exact tendsto_insertIdx theorem continuous_insertIdx {n : ℕ} {i : Fin (n + 1)} {f : β → α} {g : β → Vector α n} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => Vector.insertIdx (f b) i (g b) := continuous_insertIdx'.comp (hf.prodMk hg) theorem continuousAt_eraseIdx {n : ℕ} {i : Fin (n + 1)} : ∀ {l : Vector α (n + 1)}, ContinuousAt (Vector.eraseIdx i) l | ⟨l, hl⟩ => by rw [ContinuousAt, Vector.eraseIdx, tendsto_subtype_rng] simp only [Vector.eraseIdx_val] exact Tendsto.comp List.tendsto_eraseIdx continuousAt_subtype_val theorem continuous_eraseIdx {n : ℕ} {i : Fin (n + 1)} : Continuous (Vector.eraseIdx i : Vector α (n + 1) → Vector α n) := continuous_iff_continuousAt.mpr fun ⟨_a, _l⟩ => continuousAt_eraseIdx end List.Vector
.lake/packages/mathlib/Mathlib/Topology/JacobsonSpace.lean
import Mathlib.Topology.LocalAtTarget import Mathlib.Topology.Separation.Regular import Mathlib.Tactic.StacksAttribute /-! # Jacobson spaces ## Main results - `JacobsonSpace`: The class of Jacobson spaces, i.e. spaces such that the set of closed points are dense in every closed subspace. - `jacobsonSpace_iff_locallyClosed`: `X` is a Jacobson space iff every locally closed subset contains a closed point of `X`. - `JacobsonSpace.discreteTopology`: If `X` only has finitely many closed points, then the topology on `X` is discrete. ## References - https://stacks.math.columbia.edu/tag/005T -/ open Topology TopologicalSpace variable (X) {Y} [TopologicalSpace X] [TopologicalSpace Y] {f : X → Y} section closedPoints /-- The set of closed points. -/ def closedPoints : Set X := setOf (IsClosed {·}) variable {X} @[simp] lemma mem_closedPoints_iff {x} : x ∈ closedPoints X ↔ IsClosed {x} := Iff.rfl lemma preimage_closedPoints_subset (hf : Function.Injective f) (hf' : Continuous f) : f ⁻¹' closedPoints Y ⊆ closedPoints X := by intro x hx rw [mem_closedPoints_iff] convert continuous_iff_isClosed.mp hf' _ hx rw [← Set.image_singleton, Set.preimage_image_eq _ hf] lemma Topology.IsClosedEmbedding.preimage_closedPoints (hf : IsClosedEmbedding f) : f ⁻¹' closedPoints Y = closedPoints X := by ext x simp [mem_closedPoints_iff, ← Set.image_singleton, hf.isClosed_iff_image_isClosed] lemma closedPoints_eq_univ [T1Space X] : closedPoints X = Set.univ := Set.eq_univ_iff_forall.mpr fun _ ↦ isClosed_singleton end closedPoints /-- The class of Jacobson spaces, i.e. spaces such that the set of closed points are dense in every closed subspace. -/ @[mk_iff, stacks 005U] class JacobsonSpace : Prop where closure_inter_closedPoints : ∀ {Z}, IsClosed Z → closure (Z ∩ closedPoints X) = Z export JacobsonSpace (closure_inter_closedPoints) variable {X} lemma closure_closedPoints [JacobsonSpace X] : closure (closedPoints X) = Set.univ := by simpa using closure_inter_closedPoints isClosed_univ lemma jacobsonSpace_iff_locallyClosed : JacobsonSpace X ↔ ∀ Z, Z.Nonempty → IsLocallyClosed Z → (Z ∩ closedPoints X).Nonempty := by rw [jacobsonSpace_iff] constructor · simp_rw [isLocallyClosed_iff_isOpen_coborder, coborder, isOpen_compl_iff, Set.nonempty_iff_ne_empty] intro H Z hZ hZ' e have : Z ⊆ closure Z \ Z := by refine subset_closure.trans ?_ nth_rw 1 [← H isClosed_closure] rw [hZ'.closure_subset_iff, Set.subset_diff, Set.disjoint_iff, Set.inter_assoc, Set.inter_comm _ Z, e] exact ⟨Set.inter_subset_left, Set.inter_subset_right⟩ rw [Set.subset_diff, disjoint_self, Set.bot_eq_empty] at this exact hZ this.2 · intro H Z hZ refine subset_antisymm (hZ.closure_subset_iff.mpr Set.inter_subset_left) ?_ rw [← Set.disjoint_compl_left_iff_subset, Set.disjoint_iff_inter_eq_empty, ← Set.not_nonempty_iff_eq_empty] intro H' have := H _ H' (isClosed_closure.isOpen_compl.isLocallyClosed.inter hZ.isLocallyClosed) rw [Set.nonempty_iff_ne_empty, Set.inter_assoc, ne_eq, ← Set.disjoint_iff_inter_eq_empty, Set.disjoint_compl_left_iff_subset] at this exact this subset_closure lemma nonempty_inter_closedPoints [JacobsonSpace X] {Z : Set X} (hZ : Z.Nonempty) (hZ' : IsLocallyClosed Z) : (Z ∩ closedPoints X).Nonempty := jacobsonSpace_iff_locallyClosed.mp inferInstance Z hZ hZ' lemma isClosed_singleton_of_isLocallyClosed_singleton [JacobsonSpace X] {x : X} (hx : IsLocallyClosed {x}) : IsClosed {x} := by obtain ⟨_, ⟨y, rfl : y = x, rfl⟩, hy'⟩ := nonempty_inter_closedPoints (Set.singleton_nonempty x) hx exact hy' lemma Topology.IsOpenEmbedding.preimage_closedPoints (hf : IsOpenEmbedding f) [JacobsonSpace Y] : f ⁻¹' closedPoints Y = closedPoints X := by apply subset_antisymm (preimage_closedPoints_subset hf.injective hf.continuous) intro x hx apply isClosed_singleton_of_isLocallyClosed_singleton rw [← Set.image_singleton] exact (hx.isLocallyClosed.image hf.isInducing hf.isOpen_range.isLocallyClosed) lemma JacobsonSpace.of_isOpenEmbedding [JacobsonSpace Y] (hf : IsOpenEmbedding f) : JacobsonSpace X := by rw [jacobsonSpace_iff_locallyClosed, ← hf.preimage_closedPoints] intro Z hZ hZ' obtain ⟨_, ⟨x, hx, rfl⟩, hx'⟩ := nonempty_inter_closedPoints (hZ.image f) (hZ'.image hf.isInducing hf.isOpen_range.isLocallyClosed) exact ⟨_, hx, hx'⟩ lemma JacobsonSpace.of_isClosedEmbedding [JacobsonSpace Y] (hf : IsClosedEmbedding f) : JacobsonSpace X := by rw [jacobsonSpace_iff_locallyClosed, ← hf.preimage_closedPoints] intro Z hZ hZ' obtain ⟨_, ⟨x, hx, rfl⟩, hx'⟩ := nonempty_inter_closedPoints (hZ.image f) (hZ'.image hf.isInducing hf.isClosed_range.isLocallyClosed) exact ⟨_, hx, hx'⟩ lemma JacobsonSpace.discreteTopology [JacobsonSpace X] (h : (closedPoints X).Finite) : DiscreteTopology X := by have : closedPoints X = Set.univ := by rw [← Set.univ_subset_iff, ← closure_closedPoints, closure_subset_iff_isClosed, ← (closedPoints X).biUnion_of_singleton] exact h.isClosed_biUnion fun _ ↦ id have inst : Finite X := Set.finite_univ_iff.mp (this ▸ h) rw [discreteTopology_iff_forall_isOpen] intro s rw [← isClosed_compl_iff, ← sᶜ.biUnion_of_singleton] refine sᶜ.toFinite.isClosed_biUnion fun x _ ↦ ?_ rw [← mem_closedPoints_iff, this] trivial instance (priority := 100) [Finite X] [JacobsonSpace X] : DiscreteTopology X := JacobsonSpace.discreteTopology (Set.toFinite _) instance (priority := 100) [T1Space X] : JacobsonSpace X := ⟨by simp [closedPoints_eq_univ, closure_eq_iff_isClosed]⟩ lemma TopologicalSpace.IsOpenCover.jacobsonSpace_iff {ι : Type*} {U : ι → Opens X} (hU : IsOpenCover U) : JacobsonSpace X ↔ ∀ i, JacobsonSpace (U i) := by refine ⟨fun H i ↦ .of_isOpenEmbedding (U i).2.isOpenEmbedding_subtypeVal, fun H ↦ ?_⟩ rw [jacobsonSpace_iff_locallyClosed] intro Z hZ hZ' rw [← hU.iUnion_inter Z, Set.nonempty_iUnion] at hZ obtain ⟨i, x, hx, hx'⟩ := hZ obtain ⟨y, hy, hy'⟩ := (jacobsonSpace_iff_locallyClosed.mp (H i)) _ ⟨⟨x, hx'⟩, hx⟩ (hZ'.preimage continuous_subtype_val) refine ⟨y, hy, hU.isClosed_iff_coe_preimage.mpr fun j ↦ ?_⟩ by_cases h : (y : X) ∈ U j · convert_to IsClosed {(⟨y, h⟩ : U j)} · ext; simp [← Subtype.coe_inj] apply isClosed_singleton_of_isLocallyClosed_singleton convert (hy'.isLocallyClosed.image IsEmbedding.subtypeVal.isInducing (U i).2.isOpenEmbedding_subtypeVal.isOpen_range.isLocallyClosed).preimage continuous_subtype_val ext simp [← Subtype.coe_inj] · convert isClosed_empty rw [Set.eq_empty_iff_forall_notMem] intro z (hz : z.1 = y.1) exact h (hz ▸ z.2)
.lake/packages/mathlib/Mathlib/Topology/Piecewise.lean
import Mathlib.Topology.ContinuousOn /-! ### Continuity of piecewise defined functions -/ open Set Filter Function Topology Filter variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {f g : α → β} {s s' t : Set α} {x : α} @[simp] theorem continuousWithinAt_update_same [DecidableEq α] {y : β} : ContinuousWithinAt (update f x y) s x ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := calc ContinuousWithinAt (update f x y) s x ↔ Tendsto (update f x y) (𝓝[s \ {x}] x) (𝓝 y) := by { rw [← continuousWithinAt_diff_self, ContinuousWithinAt, update_self] } _ ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := tendsto_congr' <| eventually_nhdsWithin_iff.2 <| Eventually.of_forall fun _ hz => update_of_ne hz.2 .. @[simp] theorem continuousAt_update_same [DecidableEq α] {y : β} : ContinuousAt (Function.update f x y) x ↔ Tendsto f (𝓝[≠] x) (𝓝 y) := by rw [← continuousWithinAt_univ, continuousWithinAt_update_same, compl_eq_univ_diff] theorem ContinuousOn.if' {s : Set α} {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hpf : ∀ a ∈ s ∩ frontier { a | p a }, Tendsto f (𝓝[s ∩ { a | p a }] a) (𝓝 <| if p a then f a else g a)) (hpg : ∀ a ∈ s ∩ frontier { a | p a }, Tendsto g (𝓝[s ∩ { a | ¬p a }] a) (𝓝 <| if p a then f a else g a)) (hf : ContinuousOn f <| s ∩ { a | p a }) (hg : ContinuousOn g <| s ∩ { a | ¬p a }) : ContinuousOn (fun a => if p a then f a else g a) s := by intro x hx by_cases hx' : x ∈ frontier { a | p a } · exact (hpf x ⟨hx, hx'⟩).piecewise_nhdsWithin (hpg x ⟨hx, hx'⟩) · rw [← inter_univ s, ← union_compl_self { a | p a }, inter_union_distrib_left] at hx ⊢ rcases hx with hx | hx · apply ContinuousWithinAt.union · exact (hf x hx).congr (fun y hy => if_pos hy.2) (if_pos hx.2) · have : x ∉ closure { a | p a }ᶜ := fun h => hx' ⟨subset_closure hx.2, by rwa [closure_compl] at h⟩ exact continuousWithinAt_of_notMem_closure fun h => this (closure_inter_subset_inter_closure _ _ h).2 · apply ContinuousWithinAt.union · have : x ∉ closure { a | p a } := fun h => hx' ⟨h, fun h' : x ∈ interior { a | p a } => hx.2 (interior_subset h')⟩ exact continuousWithinAt_of_notMem_closure fun h => this (closure_inter_subset_inter_closure _ _ h).2 · exact (hg x hx).congr (fun y hy => if_neg hy.2) (if_neg hx.2) theorem ContinuousOn.piecewise' [∀ a, Decidable (a ∈ t)] (hpf : ∀ a ∈ s ∩ frontier t, Tendsto f (𝓝[s ∩ t] a) (𝓝 (piecewise t f g a))) (hpg : ∀ a ∈ s ∩ frontier t, Tendsto g (𝓝[s ∩ tᶜ] a) (𝓝 (piecewise t f g a))) (hf : ContinuousOn f <| s ∩ t) (hg : ContinuousOn g <| s ∩ tᶜ) : ContinuousOn (piecewise t f g) s := hf.if' hpf hpg hg theorem ContinuousOn.if {p : α → Prop} [∀ a, Decidable (p a)] (hp : ∀ a ∈ s ∩ frontier { a | p a }, f a = g a) (hf : ContinuousOn f <| s ∩ closure { a | p a }) (hg : ContinuousOn g <| s ∩ closure { a | ¬p a }) : ContinuousOn (fun a => if p a then f a else g a) s := by apply ContinuousOn.if' · rintro a ha simp only [← hp a ha, ite_self] apply tendsto_nhdsWithin_mono_left (inter_subset_inter_right s subset_closure) exact hf a ⟨ha.1, ha.2.1⟩ · rintro a ha simp only [hp a ha, ite_self] apply tendsto_nhdsWithin_mono_left (inter_subset_inter_right s subset_closure) rcases ha with ⟨has, ⟨_, ha⟩⟩ rw [← mem_compl_iff, ← closure_compl] at ha apply hg a ⟨has, ha⟩ · exact hf.mono (inter_subset_inter_right s subset_closure) · exact hg.mono (inter_subset_inter_right s subset_closure) theorem ContinuousOn.piecewise [∀ a, Decidable (a ∈ t)] (ht : ∀ a ∈ s ∩ frontier t, f a = g a) (hf : ContinuousOn f <| s ∩ closure t) (hg : ContinuousOn g <| s ∩ closure tᶜ) : ContinuousOn (piecewise t f g) s := hf.if ht hg theorem continuous_if' {p : α → Prop} [∀ a, Decidable (p a)] (hpf : ∀ a ∈ frontier { x | p x }, Tendsto f (𝓝[{ x | p x }] a) (𝓝 <| ite (p a) (f a) (g a))) (hpg : ∀ a ∈ frontier { x | p x }, Tendsto g (𝓝[{ x | ¬p x }] a) (𝓝 <| ite (p a) (f a) (g a))) (hf : ContinuousOn f { x | p x }) (hg : ContinuousOn g { x | ¬p x }) : Continuous fun a => ite (p a) (f a) (g a) := by rw [← continuousOn_univ] apply ContinuousOn.if' <;> simp [*] <;> assumption theorem continuous_if {p : α → Prop} [∀ a, Decidable (p a)] (hp : ∀ a ∈ frontier { x | p x }, f a = g a) (hf : ContinuousOn f (closure { x | p x })) (hg : ContinuousOn g (closure { x | ¬p x })) : Continuous fun a => if p a then f a else g a := by rw [← continuousOn_univ] apply ContinuousOn.if <;> simpa theorem Continuous.if {p : α → Prop} [∀ a, Decidable (p a)] (hp : ∀ a ∈ frontier { x | p x }, f a = g a) (hf : Continuous f) (hg : Continuous g) : Continuous fun a => if p a then f a else g a := continuous_if hp hf.continuousOn hg.continuousOn theorem continuous_if_const (p : Prop) [Decidable p] (hf : p → Continuous f) (hg : ¬p → Continuous g) : Continuous fun a => if p then f a else g a := by split_ifs with h exacts [hf h, hg h] theorem Continuous.if_const (p : Prop) [Decidable p] (hf : Continuous f) (hg : Continuous g) : Continuous fun a => if p then f a else g a := continuous_if_const p (fun _ => hf) fun _ => hg theorem continuous_piecewise [∀ a, Decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : ContinuousOn f (closure s)) (hg : ContinuousOn g (closure sᶜ)) : Continuous (piecewise s f g) := continuous_if hs hf hg theorem Continuous.piecewise [∀ a, Decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : Continuous f) (hg : Continuous g) : Continuous (piecewise s f g) := hf.if hs hg theorem IsOpen.ite' (hs : IsOpen s) (hs' : IsOpen s') (ht : ∀ x ∈ frontier t, x ∈ s ↔ x ∈ s') : IsOpen (t.ite s s') := by classical simp only [isOpen_iff_continuous_mem, Set.ite] at * convert continuous_piecewise (fun x hx => propext (ht x hx)) hs.continuousOn hs'.continuousOn using 2 rename_i x by_cases hx : x ∈ t <;> simp [hx] theorem IsOpen.ite (hs : IsOpen s) (hs' : IsOpen s') (ht : s ∩ frontier t = s' ∩ frontier t) : IsOpen (t.ite s s') := hs.ite' hs' fun x hx => by simpa [hx] using Set.ext_iff.1 ht x theorem ite_inter_closure_eq_of_inter_frontier_eq (ht : s ∩ frontier t = s' ∩ frontier t) : t.ite s s' ∩ closure t = s ∩ closure t := by rw [closure_eq_self_union_frontier, inter_union_distrib_left, inter_union_distrib_left, ite_inter_self, ite_inter_of_inter_eq _ ht] theorem ite_inter_closure_compl_eq_of_inter_frontier_eq (ht : s ∩ frontier t = s' ∩ frontier t) : t.ite s s' ∩ closure tᶜ = s' ∩ closure tᶜ := by rw [← ite_compl, ite_inter_closure_eq_of_inter_frontier_eq] rwa [frontier_compl, eq_comm] theorem continuousOn_piecewise_ite' [∀ x, Decidable (x ∈ t)] (h : ContinuousOn f (s ∩ closure t)) (h' : ContinuousOn g (s' ∩ closure tᶜ)) (H : s ∩ frontier t = s' ∩ frontier t) (Heq : EqOn f g (s ∩ frontier t)) : ContinuousOn (t.piecewise f g) (t.ite s s') := by apply ContinuousOn.piecewise · rwa [ite_inter_of_inter_eq _ H] · rwa [ite_inter_closure_eq_of_inter_frontier_eq H] · rwa [ite_inter_closure_compl_eq_of_inter_frontier_eq H] theorem continuousOn_piecewise_ite [∀ x, Decidable (x ∈ t)] (h : ContinuousOn f s) (h' : ContinuousOn g s') (H : s ∩ frontier t = s' ∩ frontier t) (Heq : EqOn f g (s ∩ frontier t)) : ContinuousOn (t.piecewise f g) (t.ite s s') := continuousOn_piecewise_ite' (h.mono inter_subset_left) (h'.mono inter_subset_left) H Heq
.lake/packages/mathlib/Mathlib/Topology/Inseparable.lean
import Mathlib.Order.UpperLower.Closure import Mathlib.Order.UpperLower.Fibration import Mathlib.Tactic.TFAE import Mathlib.Topology.ContinuousOn import Mathlib.Topology.Maps.OpenQuotient /-! # Inseparable points in a topological space In this file we prove basic properties of the following notions defined elsewhere. * `Specializes` (notation: `x ⤳ y`) : a relation saying that `𝓝 x ≤ 𝓝 y`; * `Inseparable`: a relation saying that two points in a topological space have the same neighbourhoods; equivalently, they can't be separated by an open set; * `InseparableSetoid X`: same relation, as a `Setoid`; * `SeparationQuotient X`: the quotient of `X` by its `InseparableSetoid`. We also prove various basic properties of the relation `Inseparable`. ## Notation - `x ⤳ y`: notation for `Specializes x y`; - `x ~ᵢ y` is used as a local notation for `Inseparable x y`; - `𝓝 x` is the neighbourhoods filter `nhds x` of a point `x`, defined elsewhere. ## Tags topological space, separation setoid -/ open Set Filter Function Topology variable {X Y Z α ι : Type*} {A : ι → Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [∀ i, TopologicalSpace (A i)] {x y z : X} {s : Set X} {f g : X → Y} /-! ### `Specializes` relation -/ /-- A collection of equivalent definitions of `x ⤳ y`. The public API is given by `iff` lemmas below. -/ theorem specializes_TFAE (x y : X) : List.TFAE [x ⤳ y, pure x ≤ 𝓝 y, ∀ s : Set X, IsOpen s → y ∈ s → x ∈ s, ∀ s : Set X, IsClosed s → x ∈ s → y ∈ s, y ∈ closure ({ x } : Set X), closure ({ y } : Set X) ⊆ closure { x }, ClusterPt y (pure x)] := by tfae_have 1 → 2 := (pure_le_nhds _).trans tfae_have 2 → 3 := fun h s hso hy => h (hso.mem_nhds hy) tfae_have 3 → 4 := fun h s hsc hx => of_not_not fun hy => h sᶜ hsc.isOpen_compl hy hx tfae_have 4 → 5 := fun h => h _ isClosed_closure (subset_closure <| mem_singleton _) tfae_have 6 ↔ 5 := isClosed_closure.closure_subset_iff.trans singleton_subset_iff tfae_have 5 ↔ 7 := by rw [mem_closure_iff_clusterPt, principal_singleton] tfae_have 5 → 1 := by refine fun h => (nhds_basis_opens _).ge_iff.2 ?_ rintro s ⟨hy, ho⟩ rcases mem_closure_iff.1 h s ho hy with ⟨z, hxs, rfl : z = x⟩ exact ho.mem_nhds hxs tfae_finish theorem specializes_iff_nhds : x ⤳ y ↔ 𝓝 x ≤ 𝓝 y := Iff.rfl theorem Specializes.not_disjoint (h : x ⤳ y) : ¬Disjoint (𝓝 x) (𝓝 y) := fun hd ↦ absurd (hd.mono_right h) <| by simp [NeBot.ne'] theorem specializes_iff_pure : x ⤳ y ↔ pure x ≤ 𝓝 y := (specializes_TFAE x y).out 0 1 alias ⟨Specializes.nhds_le_nhds, _⟩ := specializes_iff_nhds alias ⟨Specializes.pure_le_nhds, _⟩ := specializes_iff_pure theorem ker_nhds_eq_specializes : (𝓝 x).ker = {y | y ⤳ x} := by ext; simp [specializes_iff_pure, le_def] theorem specializes_iff_forall_open : x ⤳ y ↔ ∀ s : Set X, IsOpen s → y ∈ s → x ∈ s := (specializes_TFAE x y).out 0 2 theorem Specializes.mem_open (h : x ⤳ y) (hs : IsOpen s) (hy : y ∈ s) : x ∈ s := specializes_iff_forall_open.1 h s hs hy theorem IsOpen.not_specializes (hs : IsOpen s) (hx : x ∉ s) (hy : y ∈ s) : ¬x ⤳ y := fun h => hx <| h.mem_open hs hy theorem specializes_iff_forall_closed : x ⤳ y ↔ ∀ s : Set X, IsClosed s → x ∈ s → y ∈ s := (specializes_TFAE x y).out 0 3 theorem Specializes.mem_closed (h : x ⤳ y) (hs : IsClosed s) (hx : x ∈ s) : y ∈ s := specializes_iff_forall_closed.1 h s hs hx theorem IsClosed.not_specializes (hs : IsClosed s) (hx : x ∈ s) (hy : y ∉ s) : ¬x ⤳ y := fun h => hy <| h.mem_closed hs hx theorem specializes_iff_mem_closure : x ⤳ y ↔ y ∈ closure ({x} : Set X) := (specializes_TFAE x y).out 0 4 alias ⟨Specializes.mem_closure, _⟩ := specializes_iff_mem_closure theorem specializes_iff_closure_subset : x ⤳ y ↔ closure ({y} : Set X) ⊆ closure {x} := (specializes_TFAE x y).out 0 5 alias ⟨Specializes.closure_subset, _⟩ := specializes_iff_closure_subset theorem specializes_iff_clusterPt : x ⤳ y ↔ ClusterPt y (pure x) := (specializes_TFAE x y).out 0 6 theorem Filter.HasBasis.specializes_iff {ι} {p : ι → Prop} {s : ι → Set X} (h : (𝓝 y).HasBasis p s) : x ⤳ y ↔ ∀ i, p i → x ∈ s i := specializes_iff_pure.trans h.ge_iff theorem specializes_rfl : x ⤳ x := le_rfl @[refl] theorem specializes_refl (x : X) : x ⤳ x := specializes_rfl @[trans] theorem Specializes.trans : x ⤳ y → y ⤳ z → x ⤳ z := le_trans theorem specializes_of_eq (e : x = y) : x ⤳ y := e ▸ specializes_refl x alias Specializes.of_eq := specializes_of_eq theorem specializes_of_nhdsWithin (h₁ : 𝓝[s] x ≤ 𝓝[s] y) (h₂ : x ∈ s) : x ⤳ y := specializes_iff_pure.2 <| calc pure x ≤ 𝓝[s] x := le_inf (pure_le_nhds _) (le_principal_iff.2 h₂) _ ≤ 𝓝[s] y := h₁ _ ≤ 𝓝 y := inf_le_left theorem Specializes.map_of_continuousWithinAt {s : Set X} (h : x ⤳ y) (hf : ContinuousWithinAt f s y) (hx : x ∈ s) : f x ⤳ f y := by rw [specializes_iff_pure] at h ⊢ calc pure (f x) _ = map f (pure x) := (map_pure f x).symm _ ≤ map f (𝓝 y ⊓ 𝓟 s) := map_mono (le_inf h ((pure_le_principal x).mpr hx)) _ = map f (𝓝[s] y) := rfl _ ≤ _ := hf.tendsto theorem Specializes.map_of_continuousOn {s : Set X} (h : x ⤳ y) (hf : ContinuousOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ⤳ f y := h.map_of_continuousWithinAt (hf.continuousWithinAt hy) hx theorem Specializes.map_of_continuousAt (h : x ⤳ y) (hf : ContinuousAt f y) : f x ⤳ f y := h.map_of_continuousWithinAt hf.continuousWithinAt (mem_univ x) theorem Specializes.map (h : x ⤳ y) (hf : Continuous f) : f x ⤳ f y := h.map_of_continuousAt hf.continuousAt theorem Topology.IsInducing.specializes_iff (hf : IsInducing f) : f x ⤳ f y ↔ x ⤳ y := by simp only [specializes_iff_mem_closure, hf.closure_eq_preimage_closure_image, image_singleton, mem_preimage] theorem subtype_specializes_iff {p : X → Prop} (x y : Subtype p) : x ⤳ y ↔ (x : X) ⤳ y := IsInducing.subtypeVal.specializes_iff.symm @[simp] theorem specializes_prod {x₁ x₂ : X} {y₁ y₂ : Y} : (x₁, y₁) ⤳ (x₂, y₂) ↔ x₁ ⤳ x₂ ∧ y₁ ⤳ y₂ := by simp only [Specializes, nhds_prod_eq, prod_le_prod] theorem Specializes.prod {x₁ x₂ : X} {y₁ y₂ : Y} (hx : x₁ ⤳ x₂) (hy : y₁ ⤳ y₂) : (x₁, y₁) ⤳ (x₂, y₂) := specializes_prod.2 ⟨hx, hy⟩ theorem Specializes.fst {a b : X × Y} (h : a ⤳ b) : a.1 ⤳ b.1 := (specializes_prod.1 h).1 theorem Specializes.snd {a b : X × Y} (h : a ⤳ b) : a.2 ⤳ b.2 := (specializes_prod.1 h).2 @[simp] theorem specializes_pi {f g : ∀ i, A i} : f ⤳ g ↔ ∀ i, f i ⤳ g i := by simp only [Specializes, nhds_pi, pi_le_pi] theorem not_specializes_iff_exists_open : ¬x ⤳ y ↔ ∃ S : Set X, IsOpen S ∧ y ∈ S ∧ x ∉ S := by rw [specializes_iff_forall_open] push_neg rfl theorem not_specializes_iff_exists_closed : ¬x ⤳ y ↔ ∃ S : Set X, IsClosed S ∧ x ∈ S ∧ y ∉ S := by rw [specializes_iff_forall_closed] push_neg rfl theorem IsOpen.continuous_piecewise_of_specializes [DecidablePred (· ∈ s)] (hs : IsOpen s) (hf : Continuous f) (hg : Continuous g) (hspec : ∀ x, f x ⤳ g x) : Continuous (s.piecewise f g) := by have : ∀ U, IsOpen U → g ⁻¹' U ⊆ f ⁻¹' U := fun U hU x hx ↦ (hspec x).mem_open hU hx rw [continuous_def] intro U hU rw [piecewise_preimage, ite_eq_of_subset_right _ (this U hU)] exact hU.preimage hf |>.inter hs |>.union (hU.preimage hg) theorem IsClosed.continuous_piecewise_of_specializes [DecidablePred (· ∈ s)] (hs : IsClosed s) (hf : Continuous f) (hg : Continuous g) (hspec : ∀ x, g x ⤳ f x) : Continuous (s.piecewise f g) := by simpa only [piecewise_compl] using hs.isOpen_compl.continuous_piecewise_of_specializes hg hf hspec attribute [local instance] specializationPreorder /-- A continuous function is monotone with respect to the specialization preorders on the domain and the codomain. -/ theorem Continuous.specialization_monotone (hf : Continuous f) : Monotone f := fun _ _ h => h.map hf lemma closure_singleton_eq_Iic (x : X) : closure {x} = Iic x := Set.ext fun _ ↦ specializes_iff_mem_closure.symm /-- A subset `S` of a topological space is stable under specialization if `x ∈ S → y ∈ S` for all `x ⤳ y`. -/ def StableUnderSpecialization (s : Set X) : Prop := ∀ ⦃x y⦄, x ⤳ y → x ∈ s → y ∈ s /-- A subset `S` of a topological space is stable under specialization if `x ∈ S → y ∈ S` for all `y ⤳ x`. -/ def StableUnderGeneralization (s : Set X) : Prop := ∀ ⦃x y⦄, y ⤳ x → x ∈ s → y ∈ s example {s : Set X} : StableUnderSpecialization s ↔ IsLowerSet s := Iff.rfl example {s : Set X} : StableUnderGeneralization s ↔ IsUpperSet s := Iff.rfl lemma IsClosed.stableUnderSpecialization {s : Set X} (hs : IsClosed s) : StableUnderSpecialization s := fun _ _ e ↦ e.mem_closed hs lemma IsOpen.stableUnderGeneralization {s : Set X} (hs : IsOpen s) : StableUnderGeneralization s := fun _ _ e ↦ e.mem_open hs @[simp] lemma stableUnderSpecialization_compl_iff {s : Set X} : StableUnderSpecialization sᶜ ↔ StableUnderGeneralization s := isLowerSet_compl @[simp] lemma stableUnderGeneralization_compl_iff {s : Set X} : StableUnderGeneralization sᶜ ↔ StableUnderSpecialization s := isUpperSet_compl alias ⟨_, StableUnderGeneralization.compl⟩ := stableUnderSpecialization_compl_iff alias ⟨_, StableUnderSpecialization.compl⟩ := stableUnderGeneralization_compl_iff lemma stableUnderSpecialization_univ : StableUnderSpecialization (univ : Set X) := isLowerSet_univ lemma stableUnderSpecialization_empty : StableUnderSpecialization (∅ : Set X) := isLowerSet_empty lemma stableUnderGeneralization_univ : StableUnderGeneralization (univ : Set X) := isUpperSet_univ lemma stableUnderGeneralization_empty : StableUnderGeneralization (∅ : Set X) := isUpperSet_empty lemma stableUnderSpecialization_sUnion (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋃₀ S) := isLowerSet_sUnion H lemma stableUnderSpecialization_sInter (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋂₀ S) := isLowerSet_sInter H lemma stableUnderGeneralization_sUnion (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋃₀ S) := isUpperSet_sUnion H lemma stableUnderGeneralization_sInter (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋂₀ S) := isUpperSet_sInter H lemma stableUnderSpecialization_iUnion {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋃ i, S i) := isLowerSet_iUnion H lemma stableUnderSpecialization_iInter {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋂ i, S i) := isLowerSet_iInter H lemma stableUnderGeneralization_iUnion {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋃ i, S i) := isUpperSet_iUnion H lemma stableUnderGeneralization_iInter {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋂ i, S i) := isUpperSet_iInter H lemma Union_closure_singleton_eq_iff {s : Set X} : (⋃ x ∈ s, closure {x}) = s ↔ StableUnderSpecialization s := show _ ↔ IsLowerSet s by simp only [closure_singleton_eq_Iic, ← lowerClosure_eq, coe_lowerClosure] lemma stableUnderSpecialization_iff_Union_eq {s : Set X} : StableUnderSpecialization s ↔ (⋃ x ∈ s, closure {x}) = s := Union_closure_singleton_eq_iff.symm alias ⟨StableUnderSpecialization.Union_eq, _⟩ := stableUnderSpecialization_iff_Union_eq /-- A set is stable under specialization iff it is a union of closed sets. -/ lemma stableUnderSpecialization_iff_exists_sUnion_eq {s : Set X} : StableUnderSpecialization s ↔ ∃ (S : Set (Set X)), (∀ s ∈ S, IsClosed s) ∧ ⋃₀ S = s := by refine ⟨fun H ↦ ⟨(fun x : X ↦ closure {x}) '' s, ?_, ?_⟩, fun ⟨S, hS, e⟩ ↦ e ▸ stableUnderSpecialization_sUnion S (fun x hx ↦ (hS x hx).stableUnderSpecialization)⟩ · rintro _ ⟨_, _, rfl⟩; exact isClosed_closure · conv_rhs => rw [← H.Union_eq] simp /-- A set is stable under generalization iff it is an intersection of open sets. -/ lemma stableUnderGeneralization_iff_exists_sInter_eq {s : Set X} : StableUnderGeneralization s ↔ ∃ (S : Set (Set X)), (∀ s ∈ S, IsOpen s) ∧ ⋂₀ S = s := by refine ⟨?_, fun ⟨S, hS, e⟩ ↦ e ▸ stableUnderGeneralization_sInter S (fun x hx ↦ (hS x hx).stableUnderGeneralization)⟩ rw [← stableUnderSpecialization_compl_iff, stableUnderSpecialization_iff_exists_sUnion_eq] exact fun ⟨S, h₁, h₂⟩ ↦ ⟨(·ᶜ) '' S, fun s ⟨t, ht, e⟩ ↦ e ▸ (h₁ t ht).isOpen_compl, compl_injective ((sUnion_eq_compl_sInter_compl S).symm.trans h₂)⟩ lemma StableUnderSpecialization.preimage {s : Set Y} (hs : StableUnderSpecialization s) (hf : Continuous f) : StableUnderSpecialization (f ⁻¹' s) := IsLowerSet.preimage hs hf.specialization_monotone lemma StableUnderGeneralization.preimage {s : Set Y} (hs : StableUnderGeneralization s) (hf : Continuous f) : StableUnderGeneralization (f ⁻¹' s) := IsUpperSet.preimage hs hf.specialization_monotone /-- A map `f` between topological spaces is specializing if specializations lifts along `f`, i.e. for each `f x' ⤳ y` there is some `x` with `x' ⤳ x` whose image is `y`. -/ def SpecializingMap (f : X → Y) : Prop := Relation.Fibration (flip (· ⤳ ·)) (flip (· ⤳ ·)) f /-- A map `f` between topological spaces is generalizing if generalizations lifts along `f`, i.e. for each `y ⤳ f x'` there is some `x ⤳ x'` whose image is `y`. -/ def GeneralizingMap (f : X → Y) : Prop := Relation.Fibration (· ⤳ ·) (· ⤳ ·) f lemma specializingMap_iff_closure_singleton_subset : SpecializingMap f ↔ ∀ x, closure {f x} ⊆ f '' closure {x} := by simp only [SpecializingMap, Relation.Fibration, flip, specializes_iff_mem_closure]; rfl alias ⟨SpecializingMap.closure_singleton_subset, _⟩ := specializingMap_iff_closure_singleton_subset lemma SpecializingMap.stableUnderSpecialization_image (hf : SpecializingMap f) {s : Set X} (hs : StableUnderSpecialization s) : StableUnderSpecialization (f '' s) := IsLowerSet.image_fibration hf hs alias StableUnderSpecialization.image := SpecializingMap.stableUnderSpecialization_image lemma specializingMap_iff_stableUnderSpecialization_image_singleton : SpecializingMap f ↔ ∀ x, StableUnderSpecialization (f '' closure {x}) := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_isLowerSet_image_Iic lemma specializingMap_iff_stableUnderSpecialization_image : SpecializingMap f ↔ ∀ s, StableUnderSpecialization s → StableUnderSpecialization (f '' s) := Relation.fibration_iff_isLowerSet_image lemma specializingMap_iff_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ ∀ x, f '' closure {x} = closure {f x} := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_image_Iic hf.specialization_monotone lemma specializingMap_iff_isClosed_image_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ ∀ x, IsClosed (f '' closure {x}) := by refine ⟨fun h x ↦ ?_, fun h ↦ specializingMap_iff_stableUnderSpecialization_image_singleton.mpr (fun x ↦ (h x).stableUnderSpecialization)⟩ rw [(specializingMap_iff_closure_singleton hf).mp h x] exact isClosed_closure lemma SpecializingMap.comp {f : X → Y} {g : Y → Z} (hf : SpecializingMap f) (hg : SpecializingMap g) : SpecializingMap (g ∘ f) := by simp only [specializingMap_iff_stableUnderSpecialization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) lemma IsClosedMap.specializingMap (hf : IsClosedMap f) : SpecializingMap f := specializingMap_iff_stableUnderSpecialization_image_singleton.mpr <| fun _ ↦ (hf _ isClosed_closure).stableUnderSpecialization lemma Topology.IsInducing.specializingMap (hf : IsInducing f) (h : StableUnderSpecialization (range f)) : SpecializingMap f := by intro x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ lemma Topology.IsInducing.generalizingMap (hf : IsInducing f) (h : StableUnderGeneralization (range f)) : GeneralizingMap f := by intro x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ lemma IsOpenEmbedding.generalizingMap (hf : IsOpenEmbedding f) : GeneralizingMap f := hf.isInducing.generalizingMap hf.isOpen_range.stableUnderGeneralization lemma SpecializingMap.stableUnderSpecialization_range (h : SpecializingMap f) : StableUnderSpecialization (range f) := @image_univ _ _ f ▸ stableUnderSpecialization_univ.image h lemma GeneralizingMap.stableUnderGeneralization_image (hf : GeneralizingMap f) {s : Set X} (hs : StableUnderGeneralization s) : StableUnderGeneralization (f '' s) := IsUpperSet.image_fibration hf hs lemma GeneralizingMap_iff_stableUnderGeneralization_image : GeneralizingMap f ↔ ∀ s, StableUnderGeneralization s → StableUnderGeneralization (f '' s) := Relation.fibration_iff_isUpperSet_image alias StableUnderGeneralization.image := GeneralizingMap.stableUnderGeneralization_image lemma GeneralizingMap.stableUnderGeneralization_range (h : GeneralizingMap f) : StableUnderGeneralization (range f) := @image_univ _ _ f ▸ stableUnderGeneralization_univ.image h lemma GeneralizingMap.comp {f : X → Y} {g : Y → Z} (hf : GeneralizingMap f) (hg : GeneralizingMap g) : GeneralizingMap (g ∘ f) := by simp only [GeneralizingMap_iff_stableUnderGeneralization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) /-! ### `Inseparable` relation -/ local infixl:0 " ~ᵢ " => Inseparable theorem inseparable_def : (x ~ᵢ y) ↔ 𝓝 x = 𝓝 y := Iff.rfl theorem inseparable_iff_specializes_and : (x ~ᵢ y) ↔ x ⤳ y ∧ y ⤳ x := le_antisymm_iff theorem Inseparable.specializes (h : x ~ᵢ y) : x ⤳ y := h.le theorem Inseparable.specializes' (h : x ~ᵢ y) : y ⤳ x := h.ge theorem Specializes.antisymm (h₁ : x ⤳ y) (h₂ : y ⤳ x) : x ~ᵢ y := le_antisymm h₁ h₂ theorem inseparable_iff_forall_isOpen : (x ~ᵢ y) ↔ ∀ s : Set X, IsOpen s → (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_open, ← forall_and, ← iff_def, Iff.comm] theorem not_inseparable_iff_exists_open : ¬(x ~ᵢ y) ↔ ∃ s : Set X, IsOpen s ∧ Xor' (x ∈ s) (y ∈ s) := by simp [inseparable_iff_forall_isOpen, ← xor_iff_not_iff] theorem inseparable_iff_forall_isClosed : (x ~ᵢ y) ↔ ∀ s : Set X, IsClosed s → (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_closed, ← forall_and, ← iff_def] theorem inseparable_iff_mem_closure : (x ~ᵢ y) ↔ x ∈ closure ({y} : Set X) ∧ y ∈ closure ({x} : Set X) := inseparable_iff_specializes_and.trans <| by simp only [specializes_iff_mem_closure, and_comm] theorem inseparable_iff_closure_eq : (x ~ᵢ y) ↔ closure ({x} : Set X) = closure {y} := by simp only [inseparable_iff_specializes_and, specializes_iff_closure_subset, ← subset_antisymm_iff, eq_comm] theorem inseparable_of_nhdsWithin_eq (hx : x ∈ s) (hy : y ∈ s) (h : 𝓝[s] x = 𝓝[s] y) : x ~ᵢ y := (specializes_of_nhdsWithin h.le hx).antisymm (specializes_of_nhdsWithin h.ge hy) theorem Topology.IsInducing.inseparable_iff (hf : IsInducing f) : (f x ~ᵢ f y) ↔ (x ~ᵢ y) := by simp only [inseparable_iff_specializes_and, hf.specializes_iff] theorem subtype_inseparable_iff {p : X → Prop} (x y : Subtype p) : (x ~ᵢ y) ↔ ((x : X) ~ᵢ y) := IsInducing.subtypeVal.inseparable_iff.symm @[simp] theorem inseparable_prod {x₁ x₂ : X} {y₁ y₂ : Y} : ((x₁, y₁) ~ᵢ (x₂, y₂)) ↔ (x₁ ~ᵢ x₂) ∧ (y₁ ~ᵢ y₂) := by simp only [Inseparable, nhds_prod_eq, prod_inj] theorem Inseparable.prod {x₁ x₂ : X} {y₁ y₂ : Y} (hx : x₁ ~ᵢ x₂) (hy : y₁ ~ᵢ y₂) : (x₁, y₁) ~ᵢ (x₂, y₂) := inseparable_prod.2 ⟨hx, hy⟩ @[simp] theorem inseparable_pi {f g : ∀ i, A i} : (f ~ᵢ g) ↔ ∀ i, f i ~ᵢ g i := by simp only [Inseparable, nhds_pi, funext_iff, pi_inj] namespace Inseparable @[refl] theorem refl (x : X) : x ~ᵢ x := Eq.refl (𝓝 x) theorem rfl : x ~ᵢ x := refl x theorem of_eq (e : x = y) : Inseparable x y := e ▸ refl x @[symm] nonrec theorem symm (h : x ~ᵢ y) : y ~ᵢ x := h.symm @[trans] nonrec theorem trans (h₁ : x ~ᵢ y) (h₂ : y ~ᵢ z) : x ~ᵢ z := h₁.trans h₂ theorem nhds_eq (h : x ~ᵢ y) : 𝓝 x = 𝓝 y := h theorem mem_open_iff (h : x ~ᵢ y) (hs : IsOpen s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isOpen.1 h s hs theorem mem_closed_iff (h : x ~ᵢ y) (hs : IsClosed s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isClosed.1 h s hs theorem map_of_continuousWithinAt {s t : Set X} (h : x ~ᵢ y) (hfx : ContinuousWithinAt f s x) (hfy : ContinuousWithinAt f t y) (hx : x ∈ t) (hy : y ∈ s) : f x ~ᵢ f y := (h.specializes.map_of_continuousWithinAt hfy hx).antisymm (h.specializes'.map_of_continuousWithinAt hfx hy) theorem map_of_continuousOn {s : Set X} (h : x ~ᵢ y) (hf : ContinuousOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ~ᵢ f y := h.map_of_continuousWithinAt (hf.continuousWithinAt hx) (hf.continuousWithinAt hy) hx hy theorem map_of_continuousAt (h : x ~ᵢ y) (hx : ContinuousAt f x) (hy : ContinuousAt f y) : f x ~ᵢ f y := h.map_of_continuousWithinAt hx.continuousWithinAt hy.continuousWithinAt (mem_univ x) (mem_univ y) theorem map (h : x ~ᵢ y) (hf : Continuous f) : f x ~ᵢ f y := h.map_of_continuousAt hf.continuousAt hf.continuousAt end Inseparable theorem IsClosed.not_inseparable (hs : IsClosed s) (hx : x ∈ s) (hy : y ∉ s) : ¬(x ~ᵢ y) := fun h => hy <| (h.mem_closed_iff hs).1 hx theorem IsOpen.not_inseparable (hs : IsOpen s) (hx : x ∈ s) (hy : y ∉ s) : ¬(x ~ᵢ y) := fun h => hy <| (h.mem_open_iff hs).1 hx /-! ### Separation quotient In this section we define the quotient of a topological space by the `Inseparable` relation. -/ variable (X) in instance : TopologicalSpace (SeparationQuotient X) := instTopologicalSpaceQuotient variable {t : Set (SeparationQuotient X)} namespace SeparationQuotient /-- The natural map from a topological space to its separation quotient. -/ def mk : X → SeparationQuotient X := Quotient.mk'' theorem isQuotientMap_mk : IsQuotientMap (mk : X → SeparationQuotient X) := isQuotientMap_quot_mk @[fun_prop, continuity] theorem continuous_mk : Continuous (mk : X → SeparationQuotient X) := continuous_quot_mk @[simp] theorem mk_eq_mk : mk x = mk y ↔ (x ~ᵢ y) := Quotient.eq'' protected theorem «forall» {P : SeparationQuotient X → Prop} : (∀ x, P x) ↔ ∀ x, P (.mk x) := Quotient.forall protected theorem «exists» {P : SeparationQuotient X → Prop} : (∃ x, P x) ↔ ∃ x, P (.mk x) := Quotient.exists theorem surjective_mk : Surjective (mk : X → SeparationQuotient X) := Quot.mk_surjective @[simp] theorem range_mk : range (mk : X → SeparationQuotient X) = univ := surjective_mk.range_eq instance [Nonempty X] : Nonempty (SeparationQuotient X) := Nonempty.map mk ‹_› instance [Inhabited X] : Inhabited (SeparationQuotient X) := ⟨mk default⟩ instance [Subsingleton X] : Subsingleton (SeparationQuotient X) := surjective_mk.subsingleton @[simp] theorem inseparableSetoid_eq_top_iff {t : TopologicalSpace α} : inseparableSetoid α = ⊤ ↔ t = ⊤ := Setoid.eq_top_iff.trans TopologicalSpace.eq_top_iff_forall_inseparable.symm theorem subsingleton_iff {t : TopologicalSpace α} : Subsingleton (SeparationQuotient α) ↔ t = ⊤ := Quotient.subsingleton_iff.trans inseparableSetoid_eq_top_iff theorem nontrivial_iff {t : TopologicalSpace α} : Nontrivial (SeparationQuotient α) ↔ t ≠ ⊤ := by simpa only [not_subsingleton_iff_nontrivial] using subsingleton_iff.not @[to_additive] instance [One X] : One (SeparationQuotient X) := ⟨mk 1⟩ @[to_additive (attr := simp)] theorem mk_one [One X] : mk (1 : X) = 1 := rfl theorem preimage_image_mk_open (hs : IsOpen s) : mk ⁻¹' (mk '' s) = s := by refine Subset.antisymm ?_ (subset_preimage_image _ _) rintro x ⟨y, hys, hxy⟩ exact ((mk_eq_mk.1 hxy).mem_open_iff hs).1 hys theorem isOpenMap_mk : IsOpenMap (mk : X → SeparationQuotient X) := fun s hs => isQuotientMap_mk.isOpen_preimage.1 <| by rwa [preimage_image_mk_open hs] theorem isOpenQuotientMap_mk : IsOpenQuotientMap (mk : X → SeparationQuotient X) := ⟨surjective_mk, continuous_mk, isOpenMap_mk⟩ theorem preimage_image_mk_closed (hs : IsClosed s) : mk ⁻¹' (mk '' s) = s := by refine Subset.antisymm ?_ (subset_preimage_image _ _) rintro x ⟨y, hys, hxy⟩ exact ((mk_eq_mk.1 hxy).mem_closed_iff hs).1 hys theorem isInducing_mk : IsInducing (mk : X → SeparationQuotient X) := ⟨le_antisymm (continuous_iff_le_induced.1 continuous_mk) fun s hs => ⟨mk '' s, isOpenMap_mk s hs, preimage_image_mk_open hs⟩⟩ theorem isClosedMap_mk : IsClosedMap (mk : X → SeparationQuotient X) := isInducing_mk.isClosedMap <| by rw [range_mk]; exact isClosed_univ @[simp] theorem comap_mk_nhds_mk : comap mk (𝓝 (mk x)) = 𝓝 x := (isInducing_mk.nhds_eq_comap _).symm @[simp] theorem comap_mk_nhdsSet_image : comap mk (𝓝ˢ (mk '' s)) = 𝓝ˢ s := (isInducing_mk.nhdsSet_eq_comap _).symm /-- Push-forward of the neighborhood of a point along the projection to the separation quotient is the neighborhood of its equivalence class. -/ theorem map_mk_nhds : map mk (𝓝 x) = 𝓝 (mk x) := by rw [← comap_mk_nhds_mk, map_comap_of_surjective surjective_mk] theorem map_mk_nhdsSet : map mk (𝓝ˢ s) = 𝓝ˢ (mk '' s) := by rw [← comap_mk_nhdsSet_image, map_comap_of_surjective surjective_mk] theorem comap_mk_nhdsSet : comap mk (𝓝ˢ t) = 𝓝ˢ (mk ⁻¹' t) := by conv_lhs => rw [← image_preimage_eq t surjective_mk, comap_mk_nhdsSet_image] theorem preimage_mk_closure : mk ⁻¹' closure t = closure (mk ⁻¹' t) := isOpenMap_mk.preimage_closure_eq_closure_preimage continuous_mk t theorem preimage_mk_interior : mk ⁻¹' interior t = interior (mk ⁻¹' t) := isOpenMap_mk.preimage_interior_eq_interior_preimage continuous_mk t theorem preimage_mk_frontier : mk ⁻¹' frontier t = frontier (mk ⁻¹' t) := isOpenMap_mk.preimage_frontier_eq_frontier_preimage continuous_mk t theorem image_mk_closure : mk '' closure s = closure (mk '' s) := (image_closure_subset_closure_image continuous_mk).antisymm <| isClosedMap_mk.closure_image_subset _ theorem map_prod_map_mk_nhds (x : X) (y : Y) : map (Prod.map mk mk) (𝓝 (x, y)) = 𝓝 (mk x, mk y) := by rw [nhds_prod_eq, ← prod_map_map_eq', map_mk_nhds, map_mk_nhds, nhds_prod_eq] theorem map_mk_nhdsWithin_preimage (s : Set (SeparationQuotient X)) (x : X) : map mk (𝓝[mk ⁻¹' s] x) = 𝓝[s] mk x := by rw [nhdsWithin, ← comap_principal, Filter.push_pull, nhdsWithin, map_mk_nhds] /-- The map `(x, y) ↦ (mk x, mk y)` is a quotient map. -/ theorem isQuotientMap_prodMap_mk : IsQuotientMap (Prod.map mk mk : X × Y → _) := (isOpenQuotientMap_mk.prodMap isOpenQuotientMap_mk).isQuotientMap /-- Lift a map `f : X → α` such that `Inseparable x y → f x = f y` to a map `SeparationQuotient X → α`. -/ def lift (f : X → α) (hf : ∀ x y, (x ~ᵢ y) → f x = f y) : SeparationQuotient X → α := fun x => Quotient.liftOn' x f hf @[simp] theorem lift_mk {f : X → α} (hf : ∀ x y, (x ~ᵢ y) → f x = f y) (x : X) : lift f hf (mk x) = f x := rfl @[simp] theorem lift_comp_mk {f : X → α} (hf : ∀ x y, (x ~ᵢ y) → f x = f y) : lift f hf ∘ mk = f := rfl @[simp] theorem tendsto_lift_nhds_mk {f : X → α} {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {l : Filter α} : Tendsto (lift f hf) (𝓝 <| mk x) l ↔ Tendsto f (𝓝 x) l := by simp only [← map_mk_nhds, tendsto_map'_iff, lift_comp_mk] @[simp] theorem tendsto_lift_nhdsWithin_mk {f : X → α} {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {s : Set (SeparationQuotient X)} {l : Filter α} : Tendsto (lift f hf) (𝓝[s] mk x) l ↔ Tendsto f (𝓝[mk ⁻¹' s] x) l := by simp only [← map_mk_nhdsWithin_preimage, tendsto_map'_iff, lift_comp_mk] @[simp] theorem continuousAt_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} : ContinuousAt (lift f hf) (mk x) ↔ ContinuousAt f x := tendsto_lift_nhds_mk @[simp] theorem continuousWithinAt_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {s : Set (SeparationQuotient X)} : ContinuousWithinAt (lift f hf) s (mk x) ↔ ContinuousWithinAt f (mk ⁻¹' s) x := tendsto_lift_nhdsWithin_mk @[simp] theorem continuousOn_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} {s : Set (SeparationQuotient X)} : ContinuousOn (lift f hf) s ↔ ContinuousOn f (mk ⁻¹' s) := by simp only [ContinuousOn, surjective_mk.forall, continuousWithinAt_lift, mem_preimage] @[simp] theorem continuous_lift {hf : ∀ x y, (x ~ᵢ y) → f x = f y} : Continuous (lift f hf) ↔ Continuous f := by simp only [← continuousOn_univ, continuousOn_lift, preimage_univ] /-- Lift a map `f : X → Y → α` such that `Inseparable a b → Inseparable c d → f a c = f b d` to a map `SeparationQuotient X → SeparationQuotient Y → α`. -/ def lift₂ (f : X → Y → α) (hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d) : SeparationQuotient X → SeparationQuotient Y → α := fun x y => Quotient.liftOn₂' x y f hf @[simp] theorem lift₂_mk {f : X → Y → α} (hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d) (x : X) (y : Y) : lift₂ f hf (mk x) (mk y) = f x y := rfl @[simp] theorem tendsto_lift₂_nhds {f : X → Y → α} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {x : X} {y : Y} {l : Filter α} : Tendsto (uncurry <| lift₂ f hf) (𝓝 (mk x, mk y)) l ↔ Tendsto (uncurry f) (𝓝 (x, y)) l := by rw [← map_prod_map_mk_nhds, tendsto_map'_iff] rfl @[simp] theorem tendsto_lift₂_nhdsWithin {f : X → Y → α} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {x : X} {y : Y} {s : Set (SeparationQuotient X × SeparationQuotient Y)} {l : Filter α} : Tendsto (uncurry <| lift₂ f hf) (𝓝[s] (mk x, mk y)) l ↔ Tendsto (uncurry f) (𝓝[Prod.map mk mk ⁻¹' s] (x, y)) l := by rw [nhdsWithin, ← map_prod_map_mk_nhds, ← Filter.push_pull, comap_principal] rfl @[simp] theorem continuousAt_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {x : X} {y : Y} : ContinuousAt (uncurry <| lift₂ f hf) (mk x, mk y) ↔ ContinuousAt (uncurry f) (x, y) := tendsto_lift₂_nhds @[simp] theorem continuousWithinAt_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {s : Set (SeparationQuotient X × SeparationQuotient Y)} {x : X} {y : Y} : ContinuousWithinAt (uncurry <| lift₂ f hf) s (mk x, mk y) ↔ ContinuousWithinAt (uncurry f) (Prod.map mk mk ⁻¹' s) (x, y) := tendsto_lift₂_nhdsWithin @[simp] theorem continuousOn_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} {s : Set (SeparationQuotient X × SeparationQuotient Y)} : ContinuousOn (uncurry <| lift₂ f hf) s ↔ ContinuousOn (uncurry f) (Prod.map mk mk ⁻¹' s) := by simp_rw [ContinuousOn, (surjective_mk.prodMap surjective_mk).forall, Prod.forall, Prod.map, continuousWithinAt_lift₂] rfl @[simp] theorem continuous_lift₂ {f : X → Y → Z} {hf : ∀ a b c d, (a ~ᵢ c) → (b ~ᵢ d) → f a b = f c d} : Continuous (uncurry <| lift₂ f hf) ↔ Continuous (uncurry f) := by simp only [← continuousOn_univ, continuousOn_lift₂, preimage_univ] end SeparationQuotient theorem continuous_congr_of_inseparable (h : ∀ x, f x ~ᵢ g x) : Continuous f ↔ Continuous g := by simp_rw [SeparationQuotient.isInducing_mk.continuous_iff (Y := Y)] exact continuous_congr fun x ↦ SeparationQuotient.mk_eq_mk.mpr (h x)
.lake/packages/mathlib/Mathlib/Topology/Partial.lean
import Mathlib.Order.Filter.Partial import Mathlib.Topology.Neighborhoods /-! # Partial functions and topological spaces In this file we prove properties of `Filter.PTendsto` etc. in topological spaces. We also introduce `PContinuous`, a version of `Continuous` for partially defined functions. -/ open Filter open Topology variable {X Y : Type*} [TopologicalSpace X] theorem rtendsto_nhds {r : SetRel Y X} {l : Filter Y} {x : X} : RTendsto r l (𝓝 x) ↔ ∀ s, IsOpen s → x ∈ s → r.core s ∈ l := all_mem_nhds_filter _ _ (fun _s _t => id) _ theorem rtendsto'_nhds {r : SetRel Y X} {l : Filter Y} {x : X} : RTendsto' r l (𝓝 x) ↔ ∀ s, IsOpen s → x ∈ s → r.preimage s ∈ l := by rw [rtendsto'_def] apply all_mem_nhds_filter apply SetRel.preimage_mono theorem ptendsto_nhds {f : Y →. X} {l : Filter Y} {x : X} : PTendsto f l (𝓝 x) ↔ ∀ s, IsOpen s → x ∈ s → f.core s ∈ l := rtendsto_nhds theorem ptendsto'_nhds {f : Y →. X} {l : Filter Y} {x : X} : PTendsto' f l (𝓝 x) ↔ ∀ s, IsOpen s → x ∈ s → f.preimage s ∈ l := rtendsto'_nhds /-! ### Continuity and partial functions -/ variable [TopologicalSpace Y] /-- Continuity of a partial function -/ def PContinuous (f : X →. Y) := ∀ s, IsOpen s → IsOpen (f.preimage s) theorem open_dom_of_pcontinuous {f : X →. Y} (h : PContinuous f) : IsOpen f.Dom := by rw [← PFun.preimage_univ]; exact h _ isOpen_univ theorem pcontinuous_iff' {f : X →. Y} : PContinuous f ↔ ∀ {x y} (_ : y ∈ f x), PTendsto' f (𝓝 x) (𝓝 y) := by constructor · intro h x y h' simp only [ptendsto'_def, mem_nhds_iff] rintro s ⟨t, tsubs, opent, yt⟩ exact ⟨f.preimage t, PFun.preimage_mono _ tsubs, h _ opent, ⟨y, yt, h'⟩⟩ intro hf s os rw [isOpen_iff_nhds] rintro x ⟨y, ys, fxy⟩ t rw [mem_principal] intro (h : f.preimage s ⊆ t) apply mem_of_superset _ h have h' : ∀ s ∈ 𝓝 y, f.preimage s ∈ 𝓝 x := by intro s hs have : PTendsto' f (𝓝 x) (𝓝 y) := hf fxy rw [ptendsto'_def] at this exact this s hs change f.preimage s ∈ 𝓝 x apply h' rw [mem_nhds_iff] exact ⟨s, Set.Subset.refl _, os, ys⟩ theorem continuousWithinAt_iff_ptendsto_res (f : X → Y) {x : X} {s : Set X} : ContinuousWithinAt f s x ↔ PTendsto (PFun.res f s) (𝓝 x) (𝓝 (f x)) := tendsto_iff_ptendsto _ _ _ _
.lake/packages/mathlib/Mathlib/Topology/SeparatedMap.lean
import Mathlib.Topology.Connected.Basic import Mathlib.Topology.Separation.Hausdorff import Mathlib.Topology.Connected.Clopen /-! # Separated maps and locally injective maps out of a topological space. This module introduces a pair of dual notions `IsSeparatedMap` and `IsLocallyInjective`. A function from a topological space `X` to a type `Y` is a separated map if any two distinct points in `X` with the same image in `Y` can be separated by open neighborhoods. A constant function is a separated map if and only if `X` is a `T2Space`. A function from a topological space `X` is locally injective if every point of `X` has a neighborhood on which `f` is injective. A constant function is locally injective if and only if `X` is discrete. Given `f : X → Y` we can form the pullback $X \times_Y X$; the diagonal map $\Delta: X \to X \times_Y X$ is always an embedding. It is a closed embedding iff `f` is a separated map, iff the equal locus of any two continuous maps coequalized by `f` is closed. It is an open embedding iff `f` is locally injective, iff any such equal locus is open. Therefore, if `f` is a locally injective separated map, the equal locus of two continuous maps coequalized by `f` is clopen, so if the two maps agree on a point, then they agree on the whole connected component. The analogue of separated maps and locally injective maps in algebraic geometry are separated morphisms and unramified morphisms, respectively. ## Reference https://stacks.math.columbia.edu/tag/0CY0 -/ open Topology variable {X Y A} [TopologicalSpace X] [TopologicalSpace A] protected lemma Topology.IsEmbedding.toPullbackDiag (f : X → Y) : IsEmbedding (toPullbackDiag f) := .mk' _ (injective_toPullbackDiag f) fun x ↦ by simp [nhds_induced, Filter.comap_comap, nhds_prod_eq, Filter.comap_prod, Function.comp_def, Filter.comap_id'] lemma Continuous.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} [TopologicalSpace X₁] [TopologicalSpace X₂] [TopologicalSpace Z₁] [TopologicalSpace Z₂] {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} {mapX : X₁ → X₂} (contX : Continuous mapX) {mapY : Y₁ → Y₂} {mapZ : Z₁ → Z₂} (contZ : Continuous mapZ) {commX : f₂ ∘ mapX = mapY ∘ f₁} {commZ : g₂ ∘ mapZ = mapY ∘ g₁} : Continuous (Function.mapPullback mapX mapY mapZ commX commZ) := by refine continuous_induced_rng.mpr (.prodMk ?_ ?_) <;> apply_rules [continuous_fst, continuous_snd, continuous_subtype_val, Continuous.comp] /-- A function from a topological space `X` to a type `Y` is a separated map if any two distinct points in `X` with the same image in `Y` can be separated by open neighborhoods. -/ def IsSeparatedMap (f : X → Y) : Prop := ∀ x₁ x₂, f x₁ = f x₂ → x₁ ≠ x₂ → ∃ s₁ s₂, IsOpen s₁ ∧ IsOpen s₂ ∧ x₁ ∈ s₁ ∧ x₂ ∈ s₂ ∧ Disjoint s₁ s₂ lemma t2space_iff_isSeparatedMap (y : Y) : T2Space X ↔ IsSeparatedMap fun _ : X ↦ y := ⟨fun ⟨t2⟩ _ _ _ hne ↦ t2 hne, fun sep ↦ ⟨fun x₁ x₂ hne ↦ sep x₁ x₂ rfl hne⟩⟩ lemma T2Space.isSeparatedMap [T2Space X] (f : X → Y) : IsSeparatedMap f := fun _ _ _ ↦ t2_separation lemma Function.Injective.isSeparatedMap {f : X → Y} (inj : f.Injective) : IsSeparatedMap f := fun _ _ he hne ↦ (hne (inj he)).elim lemma isSeparatedMap_iff_disjoint_nhds {f : X → Y} : IsSeparatedMap f ↔ ∀ x₁ x₂, f x₁ = f x₂ → x₁ ≠ x₂ → Disjoint (𝓝 x₁) (𝓝 x₂) := forall₃_congr fun x x' _ ↦ by simp only [(nhds_basis_opens x).disjoint_iff (nhds_basis_opens x'), ← exists_and_left, and_assoc, and_comm, and_left_comm] lemma isSeparatedMap_iff_nhds {f : X → Y} : IsSeparatedMap f ↔ ∀ x₁ x₂, f x₁ = f x₂ → x₁ ≠ x₂ → ∃ s₁ ∈ 𝓝 x₁, ∃ s₂ ∈ 𝓝 x₂, Disjoint s₁ s₂ := by simp_rw [isSeparatedMap_iff_disjoint_nhds, Filter.disjoint_iff] open Set Filter in theorem isSeparatedMap_iff_isClosed_diagonal {f : X → Y} : IsSeparatedMap f ↔ IsClosed f.pullbackDiagonal := by simp_rw [isSeparatedMap_iff_nhds, ← isOpen_compl_iff, isOpen_iff_mem_nhds, Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq] refine forall₄_congr fun x₁ x₂ _ _ ↦ ⟨fun h ↦ ?_, fun ⟨t, ht, t_sub⟩ ↦ ?_⟩ · simp_rw [← Filter.disjoint_iff, ← compl_diagonal_mem_prod] at h exact ⟨_, h, subset_rfl⟩ · obtain ⟨s₁, h₁, s₂, h₂, s_sub⟩ := mem_prod_iff.mp ht exact ⟨s₁, h₁, s₂, h₂, disjoint_left.2 fun x h₁ h₂ ↦ @t_sub ⟨(x, x), rfl⟩ (s_sub ⟨h₁, h₂⟩) rfl⟩ theorem isSeparatedMap_iff_isClosedEmbedding {f : X → Y} : IsSeparatedMap f ↔ IsClosedEmbedding (toPullbackDiag f) := by rw [isSeparatedMap_iff_isClosed_diagonal, ← range_toPullbackDiag] exact ⟨fun h ↦ ⟨.toPullbackDiag f, h⟩, fun h ↦ h.isClosed_range⟩ theorem isSeparatedMap_iff_isClosedMap {f : X → Y} : IsSeparatedMap f ↔ IsClosedMap (toPullbackDiag f) := isSeparatedMap_iff_isClosedEmbedding.trans ⟨IsClosedEmbedding.isClosedMap, .of_continuous_injective_isClosedMap (IsEmbedding.toPullbackDiag f).continuous (injective_toPullbackDiag f)⟩ open Function.Pullback in theorem IsSeparatedMap.pullback {f : X → Y} (sep : IsSeparatedMap f) (g : A → Y) : IsSeparatedMap (@snd X Y A f g) := by rw [isSeparatedMap_iff_isClosed_diagonal] at sep ⊢ rw [← preimage_map_fst_pullbackDiagonal] refine sep.preimage (Continuous.mapPullback ?_ ?_) <;> apply_rules [continuous_fst, continuous_subtype_val, Continuous.comp] theorem IsSeparatedMap.comp_left {A} {f : X → Y} (sep : IsSeparatedMap f) {g : Y → A} (inj : g.Injective) : IsSeparatedMap (g ∘ f) := fun x₁ x₂ he ↦ sep x₁ x₂ (inj he) theorem IsSeparatedMap.comp_right {f : X → Y} (sep : IsSeparatedMap f) {g : A → X} (cont : Continuous g) (inj : g.Injective) : IsSeparatedMap (f ∘ g) := by rw [isSeparatedMap_iff_isClosed_diagonal] at sep ⊢ rw [← inj.preimage_pullbackDiagonal] exact sep.preimage (cont.mapPullback cont) /-- A function from a topological space `X` is locally injective if every point of `X` has a neighborhood on which `f` is injective. -/ def IsLocallyInjective (f : X → Y) : Prop := ∀ x : X, ∃ U, IsOpen U ∧ x ∈ U ∧ U.InjOn f lemma Function.Injective.IsLocallyInjective {f : X → Y} (inj : f.Injective) : IsLocallyInjective f := fun _ ↦ ⟨_, isOpen_univ, trivial, fun _ _ _ _ ↦ @inj _ _⟩ lemma isLocallyInjective_iff_nhds {f : X → Y} : IsLocallyInjective f ↔ ∀ x : X, ∃ U ∈ 𝓝 x, U.InjOn f := by constructor <;> intro h x · obtain ⟨U, ho, hm, hi⟩ := h x; exact ⟨U, ho.mem_nhds hm, hi⟩ · obtain ⟨U, hn, hi⟩ := h x exact ⟨interior U, isOpen_interior, mem_interior_iff_mem_nhds.mpr hn, hi.mono interior_subset⟩ theorem isLocallyInjective_iff_isOpen_diagonal {f : X → Y} : IsLocallyInjective f ↔ IsOpen f.pullbackDiagonal := by simp_rw [isLocallyInjective_iff_nhds, isOpen_iff_mem_nhds, Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq, Filter.mem_comap] refine ⟨?_, fun h x ↦ ?_⟩ · rintro h x x' hx (rfl : x = x') obtain ⟨U, hn, hi⟩ := h x exact ⟨_, Filter.prod_mem_prod hn hn, fun {p} hp ↦ hi hp.1 hp.2 p.2⟩ · obtain ⟨t, ht, t_sub⟩ := h x x rfl rfl obtain ⟨t₁, h₁, t₂, h₂, prod_sub⟩ := Filter.mem_prod_iff.mp ht exact ⟨t₁ ∩ t₂, Filter.inter_mem h₁ h₂, fun x₁ h₁ x₂ h₂ he ↦ @t_sub ⟨(x₁, x₂), he⟩ (prod_sub ⟨h₁.1, h₂.2⟩)⟩ theorem IsLocallyInjective_iff_isOpenEmbedding {f : X → Y} : IsLocallyInjective f ↔ IsOpenEmbedding (toPullbackDiag f) := by rw [isLocallyInjective_iff_isOpen_diagonal, ← range_toPullbackDiag] exact ⟨fun h ↦ ⟨.toPullbackDiag f, h⟩, fun h ↦ h.isOpen_range⟩ theorem isLocallyInjective_iff_isOpenMap {f : X → Y} : IsLocallyInjective f ↔ IsOpenMap (toPullbackDiag f) := IsLocallyInjective_iff_isOpenEmbedding.trans ⟨IsOpenEmbedding.isOpenMap, .of_continuous_injective_isOpenMap (IsEmbedding.toPullbackDiag f).continuous (injective_toPullbackDiag f)⟩ theorem discreteTopology_iff_locallyInjective (y : Y) : DiscreteTopology X ↔ IsLocallyInjective fun _ : X ↦ y := by rw [discreteTopology_iff_singleton_mem_nhds, isLocallyInjective_iff_nhds] refine forall_congr' fun x ↦ ⟨fun h ↦ ⟨{x}, h, Set.injOn_singleton _ _⟩, fun ⟨U, hU, inj⟩ ↦ ?_⟩ convert hU; ext x'; refine ⟨?_, fun h ↦ inj h (mem_of_mem_nhds hU) rfl⟩ rintro rfl; exact mem_of_mem_nhds hU theorem IsLocallyInjective.comp_left {A} {f : X → Y} (hf : IsLocallyInjective f) {g : Y → A} (hg : g.Injective) : IsLocallyInjective (g ∘ f) := fun x ↦ let ⟨U, hU, hx, inj⟩ := hf x; ⟨U, hU, hx, hg.comp_injOn inj⟩ theorem IsLocallyInjective.comp_right {f : X → Y} (hf : IsLocallyInjective f) {g : A → X} (cont : Continuous g) (hg : g.Injective) : IsLocallyInjective (f ∘ g) := by rw [isLocallyInjective_iff_isOpen_diagonal] at hf ⊢ rw [← hg.preimage_pullbackDiagonal] apply hf.preimage (cont.mapPullback cont) section eqLocus variable {f : X → Y} {g₁ g₂ : A → X} (h₁ : Continuous g₁) (h₂ : Continuous g₂) include h₁ h₂ theorem IsSeparatedMap.isClosed_eqLocus (sep : IsSeparatedMap f) (he : f ∘ g₁ = f ∘ g₂) : IsClosed {a | g₁ a = g₂ a} := let g : A → f.Pullback f := fun a ↦ ⟨⟨g₁ a, g₂ a⟩, congr_fun he a⟩ (isSeparatedMap_iff_isClosed_diagonal.mp sep).preimage (by fun_prop : Continuous g) theorem IsLocallyInjective.isOpen_eqLocus (inj : IsLocallyInjective f) (he : f ∘ g₁ = f ∘ g₂) : IsOpen {a | g₁ a = g₂ a} := let g : A → f.Pullback f := fun a ↦ ⟨⟨g₁ a, g₂ a⟩, congr_fun he a⟩ (isLocallyInjective_iff_isOpen_diagonal.mp inj).preimage (by fun_prop : Continuous g) end eqLocus variable {X E A : Type*} [TopologicalSpace E] [TopologicalSpace A] {p : E → X} namespace IsSeparatedMap variable {s : Set A} {g g₁ g₂ : A → E} (sep : IsSeparatedMap p) (inj : IsLocallyInjective p) include sep inj /-- If `p` is a locally injective separated map, and `A` is a connected space, then two lifts `g₁, g₂ : A → E` of a map `f : A → X` are equal if they agree at one point. -/ theorem eq_of_comp_eq [PreconnectedSpace A] (h₁ : Continuous g₁) (h₂ : Continuous g₂) (he : p ∘ g₁ = p ∘ g₂) (a : A) (ha : g₁ a = g₂ a) : g₁ = g₂ := funext fun a' ↦ by apply (IsClopen.eq_univ ⟨sep.isClosed_eqLocus h₁ h₂ he, inj.isOpen_eqLocus h₁ h₂ he⟩ ⟨a, ha⟩).symm ▸ Set.mem_univ a' theorem eqOn_of_comp_eqOn (hs : IsPreconnected s) (h₁ : ContinuousOn g₁ s) (h₂ : ContinuousOn g₂ s) (he : s.EqOn (p ∘ g₁) (p ∘ g₂)) {a : A} (has : a ∈ s) (ha : g₁ a = g₂ a) : s.EqOn g₁ g₂ := by rw [← Set.restrict_eq_restrict_iff] at he ⊢ rw [continuousOn_iff_continuous_restrict] at h₁ h₂ rw [isPreconnected_iff_preconnectedSpace] at hs exact sep.eq_of_comp_eq inj h₁ h₂ he ⟨a, has⟩ ha theorem const_of_comp [PreconnectedSpace A] (cont : Continuous g) (he : ∀ a a', p (g a) = p (g a')) (a a') : g a = g a' := congr_fun (sep.eq_of_comp_eq inj cont continuous_const (funext fun a ↦ he a a') a' rfl) a theorem constOn_of_comp (hs : IsPreconnected s) (cont : ContinuousOn g s) (he : ∀ a ∈ s, ∀ a' ∈ s, p (g a) = p (g a')) {a a'} (ha : a ∈ s) (ha' : a' ∈ s) : g a = g a' := sep.eqOn_of_comp_eqOn inj hs cont continuous_const.continuousOn (fun a ha ↦ he a ha a' ha') ha' rfl ha end IsSeparatedMap
.lake/packages/mathlib/Mathlib/Topology/Perfect.lean
import Mathlib.Topology.Separation.Regular /-! # Perfect Sets In this file we define perfect subsets of a topological space, and prove some basic properties, including a version of the Cantor-Bendixson Theorem. ## Main Definitions * `Preperfect C`: A set `C` is preperfect if every point of `C` is an accumulation point of `C`. Equivalently, if it has no isolated points in the induced topology. This property is also called dense-in-itself. * `Perfect C`: A set `C` is perfect, meaning it is closed and every point of it is an accumulation point of itself. * `PerfectSpace X`: A topological space `X` is perfect if its universe is a perfect set. ## Main Statements * `preperfect_iff_perfect_closure`: In a T1 space, a set is preperfect iff its closure is perfect. * `Perfect.splitting`: A perfect nonempty set contains two disjoint perfect nonempty subsets. The main inductive step in the construction of an embedding from the Cantor space to a perfect nonempty complete metric space. * `exists_countable_union_perfect_of_isClosed`: One version of the **Cantor-Bendixson Theorem**: A closed set in a second countable space can be written as the union of a countable set and a perfect set. ## Implementation Notes We do not require perfect sets to be nonempty. ## See also `Mathlib/Topology/MetricSpace/Perfect.lean`, for properties of perfect sets in metric spaces, namely Polish spaces. ## References * [kechris1995] (Chapters 6-7) ## Tags accumulation point, perfect set, dense-in-itself, cantor-bendixson. -/ open Topology Filter Set TopologicalSpace section Basic variable {α : Type*} [TopologicalSpace α] {C : Set α} /-- If `x` is an accumulation point of a set `C` and `U` is a neighborhood of `x`, then `x` is an accumulation point of `U ∩ C`. -/ theorem AccPt.nhds_inter {x : α} {U : Set α} (h_acc : AccPt x (𝓟 C)) (hU : U ∈ 𝓝 x) : AccPt x (𝓟 (U ∩ C)) := by have : 𝓝[≠] x ≤ 𝓟 U := by rw [le_principal_iff] exact mem_nhdsWithin_of_mem_nhds hU rw [AccPt, ← inf_principal, ← inf_assoc, inf_of_le_left this] exact h_acc /-- A set `C` is preperfect if all of its points are accumulation points of itself. If `α` is a T1 space, this is equivalent to the closure of `C` being perfect, see `preperfect_iff_perfect_closure`. This property is also called dense-in-itself. -/ def Preperfect (C : Set α) : Prop := ∀ x ∈ C, AccPt x (𝓟 C) /-- A set `C` is called perfect if it is closed and all of its points are accumulation points of itself. Note that we do not require `C` to be nonempty. -/ @[mk_iff perfect_def] structure Perfect (C : Set α) : Prop where closed : IsClosed C acc : Preperfect C theorem preperfect_iff_nhds : Preperfect C ↔ ∀ x ∈ C, ∀ U ∈ 𝓝 x, ∃ y ∈ U ∩ C, y ≠ x := by simp only [Preperfect, accPt_iff_nhds] section PerfectSpace variable (α) /-- A topological space `X` is said to be perfect if its universe is a perfect set. Equivalently, this means that `𝓝[≠] x ≠ ⊥` for every point `x : X`. -/ @[mk_iff perfectSpace_def] class PerfectSpace : Prop where univ_preperfect : Preperfect (Set.univ : Set α) theorem PerfectSpace.univ_perfect [PerfectSpace α] : Perfect (Set.univ : Set α) := ⟨isClosed_univ, PerfectSpace.univ_preperfect⟩ end PerfectSpace section Preperfect /-- The intersection of a preperfect set and an open set is preperfect. -/ theorem Preperfect.open_inter {U : Set α} (hC : Preperfect C) (hU : IsOpen U) : Preperfect (U ∩ C) := by rintro x ⟨xU, xC⟩ apply (hC _ xC).nhds_inter exact hU.mem_nhds xU /-- The closure of a preperfect set is perfect. For a converse, see `preperfect_iff_perfect_closure`. -/ theorem Preperfect.perfect_closure (hC : Preperfect C) : Perfect (closure C) := by constructor; · exact isClosed_closure intro x hx by_cases h : x ∈ C <;> apply AccPt.mono _ (principal_mono.mpr subset_closure) · exact hC _ h have : {x}ᶜ ∩ C = C := by simp [h] rw [AccPt, nhdsWithin, inf_assoc, inf_principal, this] rw [closure_eq_cluster_pts] at hx exact hx /-- In a T1 space, being preperfect is equivalent to having perfect closure. -/ theorem preperfect_iff_perfect_closure [T1Space α] : Preperfect C ↔ Perfect (closure C) := by constructor <;> intro h · exact h.perfect_closure intro x xC have H : AccPt x (𝓟 (closure C)) := h.acc _ (subset_closure xC) rw [accPt_iff_frequently] at * have : ∀ y, y ≠ x ∧ y ∈ closure C → ∃ᶠ z in 𝓝 y, z ≠ x ∧ z ∈ C := by rintro y ⟨hyx, yC⟩ simp only [← mem_compl_singleton_iff, and_comm, ← frequently_nhdsWithin_iff, hyx.nhdsWithin_compl_singleton, ← mem_closure_iff_frequently] exact yC rw [← frequently_frequently_nhds] exact H.mono this theorem Perfect.closure_nhds_inter {U : Set α} (hC : Perfect C) (x : α) (xC : x ∈ C) (xU : x ∈ U) (Uop : IsOpen U) : Perfect (closure (U ∩ C)) ∧ (closure (U ∩ C)).Nonempty := by constructor · apply Preperfect.perfect_closure exact hC.acc.open_inter Uop apply Nonempty.closure exact ⟨x, ⟨xU, xC⟩⟩ /-- Given a perfect nonempty set in a T2.5 space, we can find two disjoint perfect subsets. This is the main inductive step in the proof of the Cantor-Bendixson Theorem. -/ theorem Perfect.splitting [T25Space α] (hC : Perfect C) (hnonempty : C.Nonempty) : ∃ C₀ C₁ : Set α, (Perfect C₀ ∧ C₀.Nonempty ∧ C₀ ⊆ C) ∧ (Perfect C₁ ∧ C₁.Nonempty ∧ C₁ ⊆ C) ∧ Disjoint C₀ C₁ := by obtain ⟨y, yC⟩ := hnonempty obtain ⟨x, xC, hxy⟩ : ∃ x ∈ C, x ≠ y := by have := hC.acc _ yC rw [accPt_iff_nhds] at this rcases this univ univ_mem with ⟨x, xC, hxy⟩ exact ⟨x, xC.2, hxy⟩ obtain ⟨U, xU, Uop, V, yV, Vop, hUV⟩ := exists_open_nhds_disjoint_closure hxy use closure (U ∩ C), closure (V ∩ C) constructor <;> rw [← and_assoc] · refine ⟨hC.closure_nhds_inter x xC xU Uop, ?_⟩ rw [hC.closed.closure_subset_iff] exact inter_subset_right constructor · refine ⟨hC.closure_nhds_inter y yC yV Vop, ?_⟩ rw [hC.closed.closure_subset_iff] exact inter_subset_right apply Disjoint.mono _ _ hUV <;> apply closure_mono <;> exact inter_subset_left lemma IsPreconnected.preperfect_of_nontrivial [T1Space α] {U : Set α} (hu : U.Nontrivial) (h : IsPreconnected U) : Preperfect U := by intro x hx rw [isPreconnected_closed_iff] at h specialize h {x} (closure (U \ {x})) isClosed_singleton isClosed_closure ?_ ?_ ?_ · trans {x} ∪ (U \ {x}) · simp apply Set.union_subset_union_right exact subset_closure · exact Set.inter_singleton_nonempty.mpr hx · obtain ⟨y, hy⟩ := Set.Nontrivial.exists_ne hu x use y simp only [Set.mem_inter_iff, hy, true_and] apply subset_closure simp [hy] · apply Set.Nonempty.right at h rw [Set.singleton_inter_nonempty, mem_closure_iff_clusterPt, ← accPt_principal_iff_clusterPt] at h exact h end Preperfect section Kernel /-- The **Cantor-Bendixson Theorem**: Any closed subset of a second countable space can be written as the union of a countable set and a perfect set. -/ theorem exists_countable_union_perfect_of_isClosed [SecondCountableTopology α] (hclosed : IsClosed C) : ∃ V D : Set α, V.Countable ∧ Perfect D ∧ C = V ∪ D := by obtain ⟨b, bct, _, bbasis⟩ := TopologicalSpace.exists_countable_basis α let v := { U ∈ b | (U ∩ C).Countable } let V := ⋃ U ∈ v, U let D := C \ V have Vct : (V ∩ C).Countable := by simp only [V, iUnion_inter] apply Countable.biUnion · exact Countable.mono inter_subset_left bct · exact inter_subset_right refine ⟨V ∩ C, D, Vct, ⟨?_, ?_⟩, ?_⟩ · refine hclosed.sdiff (isOpen_biUnion fun _ ↦ ?_) exact fun ⟨Ub, _⟩ ↦ IsTopologicalBasis.isOpen bbasis Ub · rw [preperfect_iff_nhds] intro x xD E xE have : ¬(E ∩ D).Countable := by intro h obtain ⟨U, hUb, xU, hU⟩ : ∃ U ∈ b, x ∈ U ∧ U ⊆ E := (IsTopologicalBasis.mem_nhds_iff bbasis).mp xE have hU_cnt : (U ∩ C).Countable := by apply @Countable.mono _ _ (E ∩ D ∪ V ∩ C) · rintro y ⟨yU, yC⟩ by_cases h : y ∈ V · exact mem_union_right _ (mem_inter h yC) · exact mem_union_left _ (mem_inter (hU yU) ⟨yC, h⟩) exact Countable.union h Vct have : U ∈ v := ⟨hUb, hU_cnt⟩ apply xD.2 exact mem_biUnion this xU by_contra! h exact absurd (Countable.mono h (Set.countable_singleton _)) this · rw [inter_comm, inter_union_diff] /-- Any uncountable closed set in a second countable space contains a nonempty perfect subset. -/ theorem exists_perfect_nonempty_of_isClosed_of_not_countable [SecondCountableTopology α] (hclosed : IsClosed C) (hunc : ¬C.Countable) : ∃ D : Set α, Perfect D ∧ D.Nonempty ∧ D ⊆ C := by rcases exists_countable_union_perfect_of_isClosed hclosed with ⟨V, D, Vct, Dperf, VD⟩ refine ⟨D, ⟨Dperf, ?_⟩⟩ constructor · rw [nonempty_iff_ne_empty] by_contra h rw [h, union_empty] at VD rw [VD] at hunc contradiction rw [VD] exact subset_union_right end Kernel end Basic section PerfectSpace variable {X : Type*} [TopologicalSpace X] theorem perfectSpace_iff_forall_not_isolated : PerfectSpace X ↔ ∀ x : X, Filter.NeBot (𝓝[≠] x) := by simp [perfectSpace_def, Preperfect, AccPt] instance PerfectSpace.not_isolated [PerfectSpace X] (x : X) : Filter.NeBot (𝓝[≠] x) := perfectSpace_iff_forall_not_isolated.mp ‹_› x end PerfectSpace
.lake/packages/mathlib/Mathlib/Topology/IndicatorConstPointwise.lean
import Mathlib.Algebra.Notation.Indicator import Mathlib.Topology.Separation.Basic /-! # Pointwise convergence of indicator functions In this file, we prove the equivalence of three different ways to phrase that the indicator functions of sets converge pointwise. ## Main results For `A` a set, `(Asᵢ)` an indexed collection of sets, under mild conditions, the following are equivalent: (a) the indicator functions of `Asᵢ` tend to the indicator function of `A` pointwise; (b) for every `x`, we eventually have that `x ∈ Asᵢ` holds iff `x ∈ A` holds; (c) `Tendsto As _ <| Filter.pi (pure <| · ∈ A)`. The results stating these in the case when the indicators take values in a Fréchet space are: * `tendsto_indicator_const_iff_forall_eventually` is the equivalence (a) ↔ (b); * `tendsto_indicator_const_iff_tendsto_pi_pure` is the equivalence (a) ↔ (c). -/ open Filter Topology variable {α : Type*} {A : Set α} variable {β : Type*} [Zero β] [TopologicalSpace β] variable {ι : Type*} (L : Filter ι) {As : ι → Set α} lemma tendsto_ite {β : Type*} {p : ι → Prop} [DecidablePred p] {q : Prop} [Decidable q] {a b : β} {F G : Filter β} (haG : {a}ᶜ ∈ G) (hbF : {b}ᶜ ∈ F) (haF : principal {a} ≤ F) (hbG : principal {b} ≤ G) : Tendsto (fun i ↦ if p i then a else b) L (if q then F else G) ↔ ∀ᶠ i in L, p i ↔ q := by constructor <;> intro h · by_cases hq : q · simp only [hq, ite_true] at h filter_upwards [mem_map.mp (h hbF)] with i hi simp only [Set.preimage_compl, Set.mem_compl_iff, Set.mem_preimage, Set.mem_singleton_iff, ite_eq_right_iff, not_forall, exists_prop] at hi tauto · simp only [hq, ite_false] at h filter_upwards [mem_map.mp (h haG)] with i hi simp only [Set.preimage_compl, Set.mem_compl_iff, Set.mem_preimage, Set.mem_singleton_iff, ite_eq_left_iff, not_forall, exists_prop] at hi tauto · have obs : (fun _ ↦ if q then a else b) =ᶠ[L] (fun i ↦ if p i then a else b) := by filter_upwards [h] with i hi simp only [hi] apply Tendsto.congr' obs by_cases hq : q · simp only [hq, ite_true] apply le_trans _ haF simp only [principal_singleton, le_pure_iff, mem_map, Set.mem_singleton_iff, Set.preimage_const_of_mem, univ_mem] · simp only [hq, ite_false] apply le_trans _ hbG simp only [principal_singleton, le_pure_iff, mem_map, Set.mem_singleton_iff, Set.preimage_const_of_mem, univ_mem] lemma tendsto_indicator_const_apply_iff_eventually' (b : β) (nhds_b : {0}ᶜ ∈ 𝓝 b) (nhds_o : {b}ᶜ ∈ 𝓝 0) (x : α) : Tendsto (fun i ↦ (As i).indicator (fun (_ : α) ↦ b) x) L (𝓝 (A.indicator (fun (_ : α) ↦ b) x)) ↔ ∀ᶠ i in L, (x ∈ As i ↔ x ∈ A) := by classical have heart := @tendsto_ite ι L β (fun i ↦ x ∈ As i) _ (x ∈ A) _ b 0 (𝓝 b) (𝓝 (0 : β)) nhds_o nhds_b ?_ ?_ · convert heart by_cases hxA : x ∈ A <;> simp [hxA] · simp only [principal_singleton, le_def, mem_pure] exact fun s s_nhds ↦ mem_of_mem_nhds s_nhds · simp only [principal_singleton, le_def, mem_pure] exact fun s s_nhds ↦ mem_of_mem_nhds s_nhds lemma tendsto_indicator_const_iff_forall_eventually' (b : β) (nhds_b : {0}ᶜ ∈ 𝓝 b) (nhds_o : {b}ᶜ ∈ 𝓝 0) : Tendsto (fun i ↦ (As i).indicator (fun (_ : α) ↦ b)) L (𝓝 (A.indicator (fun (_ : α) ↦ b))) ↔ ∀ x, ∀ᶠ i in L, (x ∈ As i ↔ x ∈ A) := by simp_rw [tendsto_pi_nhds] apply forall_congr' exact tendsto_indicator_const_apply_iff_eventually' L b nhds_b nhds_o /-- The indicator functions of `Asᵢ` evaluated at `x` tend to the indicator function of `A` evaluated at `x` if and only if we eventually have the equivalence `x ∈ Asᵢ ↔ x ∈ A`. -/ @[simp] lemma tendsto_indicator_const_apply_iff_eventually [T1Space β] (b : β) [NeZero b] (x : α) : Tendsto (fun i ↦ (As i).indicator (fun (_ : α) ↦ b) x) L (𝓝 (A.indicator (fun (_ : α) ↦ b) x)) ↔ ∀ᶠ i in L, (x ∈ As i ↔ x ∈ A) := by apply tendsto_indicator_const_apply_iff_eventually' _ b · simp only [compl_singleton_mem_nhds_iff, ne_eq, NeZero.ne, not_false_eq_true] · simp only [compl_singleton_mem_nhds_iff, ne_eq, (NeZero.ne b).symm, not_false_eq_true] /-- The indicator functions of `Asᵢ` tend to the indicator function of `A` pointwise if and only if for every `x`, we eventually have the equivalence `x ∈ Asᵢ ↔ x ∈ A`. -/ @[simp] lemma tendsto_indicator_const_iff_forall_eventually [T1Space β] (b : β) [NeZero b] : Tendsto (fun i ↦ (As i).indicator (fun (_ : α) ↦ b)) L (𝓝 (A.indicator (fun (_ : α) ↦ b))) ↔ ∀ x, ∀ᶠ i in L, (x ∈ As i ↔ x ∈ A) := by apply tendsto_indicator_const_iff_forall_eventually' _ b · simp only [compl_singleton_mem_nhds_iff, ne_eq, NeZero.ne, not_false_eq_true] · simp only [compl_singleton_mem_nhds_iff, ne_eq, (NeZero.ne b).symm, not_false_eq_true] lemma tendsto_indicator_const_iff_tendsto_pi_pure' (b : β) (nhds_b : {0}ᶜ ∈ 𝓝 b) (nhds_o : {b}ᶜ ∈ 𝓝 0) : Tendsto (fun i ↦ (As i).indicator (fun (_ : α) ↦ b)) L (𝓝 (A.indicator (fun (_ : α) ↦ b))) ↔ (Tendsto As L <| Filter.pi (pure <| · ∈ A)) := by rw [tendsto_indicator_const_iff_forall_eventually' _ b nhds_b nhds_o, tendsto_pi] simp_rw [tendsto_pure] aesop lemma tendsto_indicator_const_iff_tendsto_pi_pure [T1Space β] (b : β) [NeZero b] : Tendsto (fun i ↦ (As i).indicator (fun (_ : α) ↦ b)) L (𝓝 (A.indicator (fun (_ : α) ↦ b))) ↔ (Tendsto As L <| Filter.pi (pure <| · ∈ A)) := by rw [tendsto_indicator_const_iff_forall_eventually _ b, tendsto_pi] simp_rw [tendsto_pure] aesop
.lake/packages/mathlib/Mathlib/Topology/Closure.lean
import Mathlib.Order.Filter.Lift import Mathlib.Topology.Basic /-! # Interior, closure and frontier of a set This file provides lemmas relating to the functions `interior`, `closure` and `frontier` of a set endowed with a topology. ## Notation * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Tags interior, closure, frontier -/ open Set universe u v variable {X : Type u} [TopologicalSpace X] {ι : Sort v} {x : X} {s s₁ s₂ t : Set X} section Interior theorem mem_interior : x ∈ interior s ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := by simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm] @[simp] theorem isOpen_interior : IsOpen (interior s) := isOpen_sUnion fun _ => And.left theorem interior_subset : interior s ⊆ s := sUnion_subset fun _ => And.right theorem interior_maximal (h₁ : t ⊆ s) (h₂ : IsOpen t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ @[grind =] theorem IsOpen.interior_eq (h : IsOpen s) : interior s = s := interior_subset.antisymm (interior_maximal (Subset.refl s) h) theorem interior_eq_iff_isOpen : interior s = s ↔ IsOpen s := ⟨fun h => h ▸ isOpen_interior, IsOpen.interior_eq⟩ theorem subset_interior_iff_isOpen : s ⊆ interior s ↔ IsOpen s := by simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and] theorem IsOpen.subset_interior_iff (h₁ : IsOpen s) : s ⊆ interior t ↔ s ⊆ t := ⟨fun h => Subset.trans h interior_subset, fun h₂ => interior_maximal h₂ h₁⟩ theorem subset_interior_iff : t ⊆ interior s ↔ ∃ U, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := ⟨fun h => ⟨interior s, isOpen_interior, h, interior_subset⟩, fun ⟨_U, hU, htU, hUs⟩ => htU.trans (interior_maximal hUs hU)⟩ lemma interior_subset_iff : interior s ⊆ t ↔ ∀ U, IsOpen U → U ⊆ s → U ⊆ t := by simp [interior] @[mono, gcongr] theorem interior_mono (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (Subset.trans interior_subset h) isOpen_interior theorem subset_interior_union : interior s ∪ interior t ⊆ interior (s ∪ t) := union_subset (interior_mono subset_union_left) (interior_mono subset_union_right) @[simp] theorem interior_empty : interior (∅ : Set X) = ∅ := isOpen_empty.interior_eq @[simp] theorem interior_univ : interior (univ : Set X) = univ := isOpen_univ.interior_eq @[simp] theorem interior_eq_univ : interior s = univ ↔ s = univ := ⟨fun h => univ_subset_iff.mp <| h.symm.trans_le interior_subset, fun h => h.symm ▸ interior_univ⟩ @[simp] theorem interior_interior : interior (interior s) = interior s := isOpen_interior.interior_eq @[simp] theorem interior_inter : interior (s ∩ t) = interior s ∩ interior t := (Monotone.map_inf_le (fun _ _ ↦ interior_mono) s t).antisymm <| interior_maximal (inter_subset_inter interior_subset interior_subset) <| isOpen_interior.inter isOpen_interior theorem Set.Finite.interior_biInter {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := by induction s, hs using Set.Finite.induction_on with | empty => simp | insert _ _ _ => simp [*] theorem Set.Finite.interior_sInter {S : Set (Set X)} (hS : S.Finite) : interior (⋂₀ S) = ⋂ s ∈ S, interior s := by rw [sInter_eq_biInter, hS.interior_biInter] @[simp] theorem Finset.interior_iInter {ι : Type*} (s : Finset ι) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := s.finite_toSet.interior_biInter f @[simp] theorem interior_iInter_of_finite [Finite ι] (f : ι → Set X) : interior (⋂ i, f i) = ⋂ i, interior (f i) := by rw [← sInter_range, (finite_range f).interior_sInter, biInter_range] @[simp] theorem interior_iInter₂_lt_nat {n : ℕ} (f : ℕ → Set X) : interior (⋂ m < n, f m) = ⋂ m < n, interior (f m) := (finite_lt_nat n).interior_biInter f @[simp] theorem interior_iInter₂_le_nat {n : ℕ} (f : ℕ → Set X) : interior (⋂ m ≤ n, f m) = ⋂ m ≤ n, interior (f m) := (finite_le_nat n).interior_biInter f theorem interior_union_inter_interior_compl_left_subset : interior (s ∪ t) ∩ interior sᶜ ⊆ interior t := interior_inter.symm.trans_subset <| interior_mono (union_inter_compl_left_subset ..) theorem interior_union_inter_interior_compl_right_subset : interior (s ∪ t) ∩ interior tᶜ ⊆ interior s := interior_inter.symm.trans_subset <| interior_mono (union_inter_compl_right_subset ..) theorem interior_union_isClosed_of_interior_empty (h₁ : IsClosed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have : interior (s ∪ t) ⊆ s := fun x ⟨u, ⟨(hu₁ : IsOpen u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩ => by_contradiction fun hx₂ : x ∉ s => have : u \ s ⊆ t := fun _ ⟨h₁, h₂⟩ => Or.resolve_left (hu₂ h₁) h₂ have : u \ s ⊆ interior t := by rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff] have : u \ s ⊆ ∅ := by rwa [h₂] at this this ⟨hx₁, hx₂⟩ Subset.antisymm (interior_maximal this isOpen_interior) (interior_mono subset_union_left) theorem isOpen_iff_forall_mem_open : IsOpen s ↔ ∀ x ∈ s, ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := by rw [← subset_interior_iff_isOpen] simp only [subset_def, mem_interior] theorem interior_iInter_subset (s : ι → Set X) : interior (⋂ i, s i) ⊆ ⋂ i, interior (s i) := subset_iInter fun _ => interior_mono <| iInter_subset _ _ theorem interior_iInter₂_subset (p : ι → Sort*) (s : ∀ i, p i → Set X) : interior (⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), interior (s i j) := (interior_iInter_subset _).trans <| iInter_mono fun _ => interior_iInter_subset _ theorem interior_sInter_subset (S : Set (Set X)) : interior (⋂₀ S) ⊆ ⋂ s ∈ S, interior s := calc interior (⋂₀ S) = interior (⋂ s ∈ S, s) := by rw [sInter_eq_biInter] _ ⊆ ⋂ s ∈ S, interior s := interior_iInter₂_subset _ _ theorem Filter.HasBasis.lift'_interior {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' interior).HasBasis p fun i => interior (s i) := h.lift' fun _ _ ↦ interior_mono theorem Filter.lift'_interior_le (l : Filter X) : l.lift' interior ≤ l := fun _s hs ↦ mem_of_superset (mem_lift' hs) interior_subset theorem Filter.HasBasis.lift'_interior_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (ho : ∀ i, p i → IsOpen (s i)) : l.lift' interior = l := le_antisymm l.lift'_interior_le <| h.lift'_interior.ge_iff.2 fun i hi ↦ by simpa only [(ho i hi).interior_eq] using h.mem_of_mem hi end Interior section Closure @[simp] theorem isClosed_closure : IsClosed (closure s) := isClosed_sInter fun _ => And.left theorem subset_closure : s ⊆ closure s := subset_sInter fun _ => And.right theorem notMem_of_notMem_closure {P : X} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) @[deprecated (since := "2025-05-23")] alias not_mem_of_not_mem_closure := notMem_of_notMem_closure theorem closure_minimal (h₁ : s ⊆ t) (h₂ : IsClosed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ theorem Disjoint.closure_left (hd : Disjoint s t) (ht : IsOpen t) : Disjoint (closure s) t := disjoint_compl_left.mono_left <| closure_minimal hd.subset_compl_right ht.isClosed_compl theorem Disjoint.closure_right (hd : Disjoint s t) (hs : IsOpen s) : Disjoint s (closure t) := (hd.symm.closure_left hs).symm @[simp] theorem IsClosed.closure_eq (h : IsClosed s) : closure s = s := Subset.antisymm (closure_minimal (Subset.refl s) h) subset_closure theorem IsClosed.closure_subset (hs : IsClosed s) : closure s ⊆ s := closure_minimal (Subset.refl _) hs theorem IsClosed.closure_subset_iff (h₁ : IsClosed t) : closure s ⊆ t ↔ s ⊆ t := ⟨Subset.trans subset_closure, fun h => closure_minimal h h₁⟩ theorem IsClosed.mem_iff_closure_subset (hs : IsClosed s) : x ∈ s ↔ closure ({x} : Set X) ⊆ s := (hs.closure_subset_iff.trans Set.singleton_subset_iff).symm @[mono, gcongr] theorem closure_mono (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (Subset.trans h subset_closure) isClosed_closure theorem monotone_closure (X : Type*) [TopologicalSpace X] : Monotone (@closure X _) := fun _ _ => closure_mono theorem closure_inter_subset : closure (s ∩ t) ⊆ closure s ∩ closure t := subset_inter (closure_mono inter_subset_left) (closure_mono inter_subset_right) theorem diff_subset_closure_iff : s \ t ⊆ closure t ↔ s ⊆ closure t := by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure] theorem closure_inter_subset_inter_closure (s t : Set X) : closure (s ∩ t) ⊆ closure s ∩ closure t := (monotone_closure X).map_inf_le s t theorem isClosed_of_closure_subset (h : closure s ⊆ s) : IsClosed s := by rw [subset_closure.antisymm h]; exact isClosed_closure theorem closure_eq_iff_isClosed : closure s = s ↔ IsClosed s := ⟨fun h => h ▸ isClosed_closure, IsClosed.closure_eq⟩ theorem closure_subset_iff_isClosed : closure s ⊆ s ↔ IsClosed s := ⟨isClosed_of_closure_subset, IsClosed.closure_subset⟩ theorem closure_empty : closure (∅ : Set X) = ∅ := isClosed_empty.closure_eq @[simp] theorem closure_empty_iff (s : Set X) : closure s = ∅ ↔ s = ∅ := ⟨subset_eq_empty subset_closure, fun h => h.symm ▸ closure_empty⟩ @[simp] theorem closure_nonempty_iff : (closure s).Nonempty ↔ s.Nonempty := by simp only [nonempty_iff_ne_empty, Ne, closure_empty_iff] alias ⟨Set.Nonempty.of_closure, Set.Nonempty.closure⟩ := closure_nonempty_iff theorem closure_univ : closure (univ : Set X) = univ := isClosed_univ.closure_eq theorem closure_closure : closure (closure s) = closure s := isClosed_closure.closure_eq theorem closure_eq_compl_interior_compl : closure s = (interior sᶜ)ᶜ := by rw [interior, closure, compl_sUnion, compl_image_set_of] simp only [compl_subset_compl, isOpen_compl_iff] @[simp] theorem closure_union : closure (s ∪ t) = closure s ∪ closure t := by simp [closure_eq_compl_interior_compl, compl_inter] theorem Set.Finite.closure_biUnion {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := by simp [closure_eq_compl_interior_compl, hs.interior_biInter] theorem Set.Finite.closure_sUnion {S : Set (Set X)} (hS : S.Finite) : closure (⋃₀ S) = ⋃ s ∈ S, closure s := by rw [sUnion_eq_biUnion, hS.closure_biUnion] @[simp] theorem Finset.closure_biUnion {ι : Type*} (s : Finset ι) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := s.finite_toSet.closure_biUnion f @[simp] theorem closure_iUnion_of_finite [Finite ι] (f : ι → Set X) : closure (⋃ i, f i) = ⋃ i, closure (f i) := by rw [← sUnion_range, (finite_range _).closure_sUnion, biUnion_range] @[simp] theorem closure_iUnion₂_lt_nat {n : ℕ} (f : ℕ → Set X) : closure (⋃ m < n, f m) = ⋃ m < n, closure (f m) := (finite_lt_nat n).closure_biUnion f @[simp] theorem closure_iUnion₂_le_nat {n : ℕ} (f : ℕ → Set X) : closure (⋃ m ≤ n, f m) = ⋃ m ≤ n, closure (f m) := (finite_le_nat n).closure_biUnion f theorem subset_closure_inter_union_closure_compl_left : closure t ⊆ closure (s ∩ t) ∪ closure sᶜ := (closure_mono <| subset_inter_union_compl_left ..).trans_eq closure_union theorem subset_closure_inter_union_closure_compl_right : closure s ⊆ closure (s ∩ t) ∪ closure tᶜ := (closure_mono <| subset_inter_union_compl_right ..).trans_eq closure_union theorem interior_subset_closure : interior s ⊆ closure s := Subset.trans interior_subset subset_closure @[simp] theorem interior_compl : interior sᶜ = (closure s)ᶜ := by simp [closure_eq_compl_interior_compl] @[simp] theorem closure_compl : closure sᶜ = (interior s)ᶜ := by simp [closure_eq_compl_interior_compl] theorem interior_eq_compl_closure_compl : interior s = (closure sᶜ)ᶜ := by simp theorem interior_union_of_disjoint_closure (h : Disjoint (closure s) (closure t)) : interior (s ∪ t) = interior s ∪ interior t := by have full : interior sᶜ ∪ interior tᶜ = univ := by simpa [disjoint_iff, ← compl_inter] using h refine subset_antisymm ?_ subset_interior_union rw [← (interior _).inter_univ, ← full, inter_union_distrib_left] exact union_subset (interior_union_inter_interior_compl_left_subset.trans subset_union_right) (interior_union_inter_interior_compl_right_subset.trans subset_union_left) theorem closure_inter_of_codisjoint_interior (h : Codisjoint (interior s) (interior t)) : closure (s ∩ t) = closure s ∩ closure t := by rw [← compl_inj_iff] simp only [← interior_compl, compl_inter] apply interior_union_of_disjoint_closure simpa only [closure_compl, disjoint_compl_left_iff, ← codisjoint_iff_compl_le_left] theorem mem_closure_iff : x ∈ closure s ↔ ∀ o, IsOpen o → x ∈ o → (o ∩ s).Nonempty := ⟨fun h o oo ao => by_contradiction fun os => have : s ⊆ oᶜ := fun x xs xo => os ⟨x, xo, xs⟩ closure_minimal this (isClosed_compl_iff.2 oo) h ao, fun H _ ⟨h₁, h₂⟩ => by_contradiction fun nc => let ⟨_, hc, hs⟩ := H _ h₁.isOpen_compl nc hc (h₂ hs)⟩ theorem closure_inter_open_nonempty_iff (h : IsOpen t) : (closure s ∩ t).Nonempty ↔ (s ∩ t).Nonempty := ⟨fun ⟨_x, hxcs, hxt⟩ => inter_comm t s ▸ mem_closure_iff.1 hxcs t h hxt, fun h => h.mono <| inf_le_inf_right t subset_closure⟩ theorem Filter.le_lift'_closure (l : Filter X) : l ≤ l.lift' closure := le_lift'.2 fun _ h => mem_of_superset h subset_closure theorem Filter.HasBasis.lift'_closure {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' closure).HasBasis p fun i => closure (s i) := h.lift' (monotone_closure X) theorem Filter.HasBasis.lift'_closure_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (hc : ∀ i, p i → IsClosed (s i)) : l.lift' closure = l := le_antisymm (h.ge_iff.2 fun i hi => (hc i hi).closure_eq ▸ mem_lift' (h.mem_of_mem hi)) l.le_lift'_closure @[simp] theorem Filter.lift'_closure_eq_bot {l : Filter X} : l.lift' closure = ⊥ ↔ l = ⊥ := ⟨fun h => bot_unique <| h ▸ l.le_lift'_closure, fun h => h.symm ▸ by rw [lift'_bot (monotone_closure _), closure_empty, principal_empty]⟩ theorem dense_iff_closure_eq : Dense s ↔ closure s = univ := eq_univ_iff_forall.symm alias ⟨Dense.closure_eq, _⟩ := dense_iff_closure_eq theorem interior_eq_empty_iff_dense_compl : interior s = ∅ ↔ Dense sᶜ := by rw [dense_iff_closure_eq, closure_compl, compl_univ_iff] theorem Dense.interior_compl (h : Dense s) : interior sᶜ = ∅ := interior_eq_empty_iff_dense_compl.2 <| by rwa [compl_compl] /-- The closure of a set `s` is dense if and only if `s` is dense. -/ @[simp] theorem dense_closure : Dense (closure s) ↔ Dense s := by rw [Dense, Dense, closure_closure] protected alias ⟨_, Dense.closure⟩ := dense_closure alias ⟨Dense.of_closure, _⟩ := dense_closure @[simp] theorem dense_univ : Dense (univ : Set X) := fun _ => subset_closure trivial /-- A set is dense if and only if it has a nonempty intersection with each nonempty open set. -/ theorem dense_iff_inter_open : Dense s ↔ ∀ U, IsOpen U → U.Nonempty → (U ∩ s).Nonempty := by constructor <;> intro h · rintro U U_op ⟨x, x_in⟩ exact mem_closure_iff.1 (h _) U U_op x_in · intro x rw [mem_closure_iff] intro U U_op x_in exact h U U_op ⟨_, x_in⟩ alias ⟨Dense.inter_open_nonempty, _⟩ := dense_iff_inter_open theorem Dense.exists_mem_open (hs : Dense s) {U : Set X} (ho : IsOpen U) (hne : U.Nonempty) : ∃ x ∈ s, x ∈ U := let ⟨x, hx⟩ := hs.inter_open_nonempty U ho hne ⟨x, hx.2, hx.1⟩ theorem Dense.nonempty_iff (hs : Dense s) : s.Nonempty ↔ Nonempty X := ⟨fun ⟨x, _⟩ => ⟨x⟩, fun ⟨x⟩ => let ⟨y, hy⟩ := hs.inter_open_nonempty _ isOpen_univ ⟨x, trivial⟩ ⟨y, hy.2⟩⟩ theorem Dense.nonempty [h : Nonempty X] (hs : Dense s) : s.Nonempty := hs.nonempty_iff.2 h @[mono] theorem Dense.mono (h : s₁ ⊆ s₂) (hd : Dense s₁) : Dense s₂ := fun x => closure_mono h (hd x) lemma DenseRange.of_comp {α β : Type*} {f : α → X} {g : β → α} (h : DenseRange (f ∘ g)) : DenseRange f := Dense.mono (range_comp_subset_range g f) h /-- Complement to a singleton is dense if and only if the singleton is not an open set. -/ theorem dense_compl_singleton_iff_not_open : Dense ({x}ᶜ : Set X) ↔ ¬IsOpen ({x} : Set X) := by constructor · intro hd ho exact (hd.inter_open_nonempty _ ho (singleton_nonempty _)).ne_empty (inter_compl_self _) · refine fun ho => dense_iff_inter_open.2 fun U hU hne => inter_compl_nonempty_iff.2 fun hUx => ?_ obtain rfl : U = {x} := eq_singleton_iff_nonempty_unique_mem.2 ⟨hne, hUx⟩ exact ho hU /-- If a closed property holds for a dense subset, it holds for the whole space. -/ @[elab_as_elim] lemma Dense.induction (hs : Dense s) {P : X → Prop} (mem : ∀ x ∈ s, P x) (isClosed : IsClosed { x | P x }) (x : X) : P x := hs.closure_eq.symm.subset.trans (isClosed.closure_subset_iff.mpr mem) (Set.mem_univ _) theorem IsOpen.subset_interior_closure {s : Set X} (s_open : IsOpen s) : s ⊆ interior (closure s) := s_open.subset_interior_iff.mpr subset_closure theorem IsClosed.closure_interior_subset {s : Set X} (s_closed : IsClosed s) : closure (interior s) ⊆ s := s_closed.closure_subset_iff.mpr interior_subset @[simp] theorem closure_interior_idem : closure (interior (closure (interior s))) = closure (interior s) := isClosed_closure.closure_interior_subset.antisymm (closure_mono isOpen_interior.subset_interior_closure) @[simp] theorem interior_closure_idem : interior (closure (interior (closure s))) = interior (closure s) := (interior_mono isClosed_closure.closure_interior_subset).antisymm isOpen_interior.subset_interior_closure end Closure section Frontier @[simp] theorem closure_diff_interior (s : Set X) : closure s \ interior s = frontier s := rfl /-- Interior and frontier are disjoint. -/ lemma disjoint_interior_frontier : Disjoint (interior s) (frontier s) := by rw [disjoint_iff_inter_eq_empty, ← closure_diff_interior, diff_eq, ← inter_assoc, inter_comm, ← inter_assoc, compl_inter_self, empty_inter] @[simp] theorem closure_diff_frontier (s : Set X) : closure s \ frontier s = interior s := by rw [frontier, diff_diff_right_self, inter_eq_self_of_subset_right interior_subset_closure] @[simp] theorem self_diff_frontier (s : Set X) : s \ frontier s = interior s := by rw [frontier, diff_diff_right, diff_eq_empty.2 subset_closure, inter_eq_self_of_subset_right interior_subset, empty_union] theorem frontier_eq_closure_inter_closure : frontier s = closure s ∩ closure sᶜ := by rw [closure_compl, frontier, diff_eq] theorem frontier_subset_closure : frontier s ⊆ closure s := diff_subset theorem frontier_subset_iff_isClosed : frontier s ⊆ s ↔ IsClosed s := by rw [frontier, diff_subset_iff, union_eq_right.mpr interior_subset, closure_subset_iff_isClosed] alias ⟨_, IsClosed.frontier_subset⟩ := frontier_subset_iff_isClosed theorem frontier_closure_subset : frontier (closure s) ⊆ frontier s := diff_subset_diff closure_closure.subset <| interior_mono subset_closure theorem frontier_interior_subset : frontier (interior s) ⊆ frontier s := diff_subset_diff (closure_mono interior_subset) interior_interior.symm.subset /-- The complement of a set has the same frontier as the original set. -/ @[simp] theorem frontier_compl (s : Set X) : frontier sᶜ = frontier s := by simp only [frontier_eq_closure_inter_closure, compl_compl, inter_comm] @[simp] theorem frontier_univ : frontier (univ : Set X) = ∅ := by simp [frontier] @[simp] theorem frontier_empty : frontier (∅ : Set X) = ∅ := by simp [frontier] theorem frontier_inter_subset (s t : Set X) : frontier (s ∩ t) ⊆ frontier s ∩ closure t ∪ closure s ∩ frontier t := by simp only [frontier_eq_closure_inter_closure, compl_inter, closure_union] refine (inter_subset_inter_left _ (closure_inter_subset_inter_closure s t)).trans_eq ?_ simp only [inter_union_distrib_left, inter_assoc, inter_comm (closure t)] theorem frontier_union_subset (s t : Set X) : frontier (s ∪ t) ⊆ frontier s ∩ closure tᶜ ∪ closure sᶜ ∩ frontier t := by simpa only [frontier_compl, ← compl_union] using frontier_inter_subset sᶜ tᶜ theorem IsClosed.frontier_eq (hs : IsClosed s) : frontier s = s \ interior s := by rw [frontier, hs.closure_eq] theorem IsOpen.frontier_eq (hs : IsOpen s) : frontier s = closure s \ s := by rw [frontier, hs.interior_eq] theorem IsOpen.inter_frontier_eq (hs : IsOpen s) : s ∩ frontier s = ∅ := by rw [hs.frontier_eq, inter_diff_self] theorem disjoint_frontier_iff_isOpen : Disjoint (frontier s) s ↔ IsOpen s := by rw [← isClosed_compl_iff, ← frontier_subset_iff_isClosed, frontier_compl, subset_compl_iff_disjoint_right] /-- The frontier of a set is closed. -/ theorem isClosed_frontier : IsClosed (frontier s) := by rw [frontier_eq_closure_inter_closure]; exact IsClosed.inter isClosed_closure isClosed_closure /-- The frontier of a closed set has no interior point. -/ theorem interior_frontier (h : IsClosed s) : interior (frontier s) = ∅ := by have A : frontier s = s \ interior s := h.frontier_eq have B : interior (frontier s) ⊆ interior s := by rw [A]; exact interior_mono diff_subset have C : interior (frontier s) ⊆ frontier s := interior_subset have : interior (frontier s) ⊆ interior s ∩ (s \ interior s) := subset_inter B (by simpa [A] using C) rwa [inter_diff_self, subset_empty_iff] at this theorem closure_eq_interior_union_frontier (s : Set X) : closure s = interior s ∪ frontier s := (union_diff_cancel interior_subset_closure).symm theorem closure_eq_self_union_frontier (s : Set X) : closure s = s ∪ frontier s := (union_diff_cancel' interior_subset subset_closure).symm theorem Disjoint.frontier_left (ht : IsOpen t) (hd : Disjoint s t) : Disjoint (frontier s) t := subset_compl_iff_disjoint_right.1 <| frontier_subset_closure.trans <| closure_minimal (disjoint_left.1 hd) <| isClosed_compl_iff.2 ht theorem Disjoint.frontier_right (hs : IsOpen s) (hd : Disjoint s t) : Disjoint s (frontier t) := (hd.symm.frontier_left hs).symm theorem frontier_eq_inter_compl_interior : frontier s = (interior s)ᶜ ∩ (interior sᶜ)ᶜ := by rw [← frontier_compl, ← closure_compl, ← diff_eq, closure_diff_interior] theorem compl_frontier_eq_union_interior : (frontier s)ᶜ = interior s ∪ interior sᶜ := by rw [frontier_eq_inter_compl_interior] simp only [compl_inter, compl_compl] end Frontier
.lake/packages/mathlib/Mathlib/Topology/Order.lean
import Mathlib.Topology.Continuous import Mathlib.Topology.Defs.Induced /-! # Ordering on topologies and (co)induced topologies Topologies on a fixed type `α` are ordered, by reverse inclusion. That is, for topologies `t₁` and `t₂` on `α`, we write `t₁ ≤ t₂` if every set open in `t₂` is also open in `t₁`. (One also calls `t₁` *finer* than `t₂`, and `t₂` *coarser* than `t₁`.) Any function `f : α → β` induces * `TopologicalSpace.induced f : TopologicalSpace β → TopologicalSpace α`; * `TopologicalSpace.coinduced f : TopologicalSpace α → TopologicalSpace β`. Continuity, the ordering on topologies and (co)induced topologies are related as follows: * The identity map `(α, t₁) → (α, t₂)` is continuous iff `t₁ ≤ t₂`. * A map `f : (α, t) → (β, u)` is continuous * iff `t ≤ TopologicalSpace.induced f u` (`continuous_iff_le_induced`) * iff `TopologicalSpace.coinduced f t ≤ u` (`continuous_iff_coinduced_le`). Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. For a function `f : α → β`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois connection between topologies on `α` and topologies on `β`. ## Implementation notes There is a Galois insertion between topologies on `α` (with the inclusion ordering) and all collections of sets in `α`. The complete lattice structure on topologies on `α` is defined as the reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding Galois coinsertion between topologies on `α` (with the reversed inclusion ordering) and collections of sets in `α` (with the reversed inclusion ordering). ## Tags finer, coarser, induced topology, coinduced topology -/ open Function Set Filter Topology universe u v w namespace TopologicalSpace variable {α : Type u} /-- The open sets of the least topology containing a collection of basic sets. -/ inductive GenerateOpen (g : Set (Set α)) : Set α → Prop | basic : ∀ s ∈ g, GenerateOpen g s | univ : GenerateOpen g univ | inter : ∀ s t, GenerateOpen g s → GenerateOpen g t → GenerateOpen g (s ∩ t) | sUnion : ∀ S : Set (Set α), (∀ s ∈ S, GenerateOpen g s) → GenerateOpen g (⋃₀ S) /-- The smallest topological space containing the collection `g` of basic sets -/ def generateFrom (g : Set (Set α)) : TopologicalSpace α where IsOpen := GenerateOpen g isOpen_univ := GenerateOpen.univ isOpen_inter := GenerateOpen.inter isOpen_sUnion := GenerateOpen.sUnion theorem isOpen_generateFrom_of_mem {g : Set (Set α)} {s : Set α} (hs : s ∈ g) : IsOpen[generateFrom g] s := GenerateOpen.basic s hs theorem nhds_generateFrom {g : Set (Set α)} {a : α} : @nhds α (generateFrom g) a = ⨅ s ∈ { s | a ∈ s ∧ s ∈ g }, 𝓟 s := by letI := generateFrom g rw [nhds_def] refine le_antisymm (biInf_mono fun s ⟨as, sg⟩ => ⟨as, .basic _ sg⟩) <| le_iInf₂ ?_ rintro s ⟨ha, hs⟩ induction hs with | basic _ hs => exact iInf₂_le _ ⟨ha, hs⟩ | univ => exact le_top.trans_eq principal_univ.symm | inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal | sUnion _ _ hS => let ⟨t, htS, hat⟩ := ha exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS) lemma tendsto_nhds_generateFrom_iff {β : Type*} {m : α → β} {f : Filter α} {g : Set (Set β)} {b : β} : Tendsto m f (@nhds β (generateFrom g) b) ↔ ∀ s ∈ g, b ∈ s → m ⁻¹' s ∈ f := by simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp, tendsto_principal]; rfl /-- Construct a topology on α given the filter of neighborhoods of each point of α. -/ protected def mkOfNhds (n : α → Filter α) : TopologicalSpace α where IsOpen s := ∀ a ∈ s, s ∈ n a isOpen_univ _ _ := univ_mem isOpen_inter := fun _s _t hs ht x ⟨hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt) isOpen_sUnion := fun _s hs _a ⟨x, hx, hxa⟩ => mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx) theorem nhds_mkOfNhds_of_hasBasis {n : α → Filter α} {ι : α → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set α} (hb : ∀ a, (n a).HasBasis (p a) (s a)) (hpure : ∀ a i, p a i → a ∈ s a i) (hopen : ∀ a i, p a i → ∀ᶠ x in n a, s a i ∈ n x) (a : α) : @nhds α (.mkOfNhds n) a = n a := by let t : TopologicalSpace α := .mkOfNhds n apply le_antisymm · intro U hU replace hpure : pure ≤ n := fun x ↦ (hb x).ge_iff.2 (hpure x) refine mem_nhds_iff.2 ⟨{x | U ∈ n x}, fun x hx ↦ hpure x hx, fun x hx ↦ ?_, hU⟩ rcases (hb x).mem_iff.1 hx with ⟨i, hpi, hi⟩ exact (hopen x i hpi).mono fun y hy ↦ mem_of_superset hy hi · exact (nhds_basis_opens a).ge_iff.2 fun U ⟨haU, hUo⟩ ↦ hUo a haU theorem nhds_mkOfNhds (n : α → Filter α) (a : α) (h₀ : pure ≤ n) (h₁ : ∀ a, ∀ s ∈ n a, ∀ᶠ y in n a, s ∈ n y) : @nhds α (TopologicalSpace.mkOfNhds n) a = n a := nhds_mkOfNhds_of_hasBasis (fun a ↦ (n a).basis_sets) h₀ h₁ _ theorem nhds_mkOfNhds_single [DecidableEq α] {a₀ : α} {l : Filter α} (h : pure a₀ ≤ l) (b : α) : @nhds α (TopologicalSpace.mkOfNhds (update pure a₀ l)) b = (update pure a₀ l : α → Filter α) b := by refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟨h, fun _ _ => le_rfl⟩) fun a s hs => ?_ rcases eq_or_ne a a₀ with (rfl | ha) · filter_upwards [hs] with b hb rcases eq_or_ne b a with (rfl | hb) · exact hs · rwa [update_of_ne hb] · simpa only [update_of_ne ha, mem_pure, eventually_pure] using hs theorem nhds_mkOfNhds_filterBasis (B : α → FilterBasis α) (a : α) (h₀ : ∀ x, ∀ n ∈ B x, x ∈ n) (h₁ : ∀ x, ∀ n ∈ B x, ∃ n₁ ∈ B x, ∀ x' ∈ n₁, ∃ n₂ ∈ B x', n₂ ⊆ n) : @nhds α (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter := nhds_mkOfNhds_of_hasBasis (fun a ↦ (B a).hasBasis) h₀ h₁ a section Lattice variable {α : Type u} {β : Type v} /-- The ordering on topologies on the type `α`. `t ≤ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/ instance : PartialOrder (TopologicalSpace α) := { PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with le := fun s t => ∀ U, IsOpen[t] U → IsOpen[s] U } protected theorem le_def {α} {t s : TopologicalSpace α} : t ≤ s ↔ IsOpen[s] ≤ IsOpen[t] := Iff.rfl theorem le_generateFrom_iff_subset_isOpen {g : Set (Set α)} {t : TopologicalSpace α} : t ≤ generateFrom g ↔ g ⊆ { s | IsOpen[t] s } := ⟨fun ht s hs => ht _ <| .basic s hs, fun hg _s hs => hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩ /-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a topology. -/ protected def mkOfClosure (s : Set (Set α)) (hs : { u | GenerateOpen s u } = s) : TopologicalSpace α where IsOpen u := u ∈ s isOpen_univ := hs ▸ TopologicalSpace.GenerateOpen.univ isOpen_inter := hs ▸ TopologicalSpace.GenerateOpen.inter isOpen_sUnion := hs ▸ TopologicalSpace.GenerateOpen.sUnion theorem mkOfClosure_sets {s : Set (Set α)} {hs : { u | GenerateOpen s u } = s} : TopologicalSpace.mkOfClosure s hs = generateFrom s := TopologicalSpace.ext hs.symm theorem gc_generateFrom (α) : GaloisConnection (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) := fun _ _ => le_generateFrom_iff_subset_isOpen.symm /-- The Galois coinsertion between `TopologicalSpace α` and `(Set (Set α))ᵒᵈ` whose lower part sends a topology to its collection of open subsets, and whose upper part sends a collection of subsets of `α` to the topology they generate. -/ def gciGenerateFrom (α : Type*) : GaloisCoinsertion (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) where gc := gc_generateFrom α u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs choice g hg := TopologicalSpace.mkOfClosure g (Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets /-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. The infimum of a collection of topologies is the topology generated by all their open sets, while the supremum is the topology whose open sets are those sets open in every member of the collection. -/ instance : CompleteLattice (TopologicalSpace α) := (gciGenerateFrom α).liftCompleteLattice @[mono, gcongr] theorem generateFrom_anti {α} {g₁ g₂ : Set (Set α)} (h : g₁ ⊆ g₂) : generateFrom g₂ ≤ generateFrom g₁ := (gc_generateFrom _).monotone_u h theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) : generateFrom { s | IsOpen[t] s } = t := (gciGenerateFrom α).u_l_eq t theorem leftInverse_generateFrom : LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).u_l_leftInverse theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) := (gciGenerateFrom α).u_surjective theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).l_injective end Lattice end TopologicalSpace section Lattice variable {α : Type*} {t t₁ t₂ : TopologicalSpace α} {s : Set α} theorem IsOpen.mono (hs : IsOpen[t₂] s) (h : t₁ ≤ t₂) : IsOpen[t₁] s := h s hs theorem IsClosed.mono (hs : IsClosed[t₂] s) (h : t₁ ≤ t₂) : IsClosed[t₁] s := (@isOpen_compl_iff α s t₁).mp <| hs.isOpen_compl.mono h theorem closure.mono (h : t₁ ≤ t₂) : closure[t₁] s ⊆ closure[t₂] s := @closure_minimal _ t₁ s (@closure _ t₂ s) subset_closure (IsClosed.mono isClosed_closure h) theorem isOpen_implies_isOpen_iff : (∀ s, IsOpen[t₁] s → IsOpen[t₂] s) ↔ t₂ ≤ t₁ := Iff.rfl /-- The only open sets in the indiscrete topology are the empty set and the whole space. -/ theorem TopologicalSpace.isOpen_top_iff {α} (U : Set α) : IsOpen[⊤] U ↔ U = ∅ ∨ U = univ := ⟨fun h => by induction h with | basic _ h => exact False.elim h | univ => exact .inr rfl | inter _ _ _ _ h₁ h₂ => rcases h₁ with (rfl | rfl) <;> rcases h₂ with (rfl | rfl) <;> simp | sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by rintro (rfl | rfl) exacts [@isOpen_empty _ ⊤, @isOpen_univ _ ⊤]⟩ /-- A topological space is discrete if every set is open, that is, its topology equals the discrete topology `⊥`. -/ class DiscreteTopology (α : Type*) [t : TopologicalSpace α] : Prop where /-- The `TopologicalSpace` structure on a type with discrete topology is equal to `⊥`. -/ eq_bot : t = ⊥ theorem discreteTopology_bot (α : Type*) : @DiscreteTopology α ⊥ := @DiscreteTopology.mk α ⊥ rfl section DiscreteTopology variable [TopologicalSpace α] [DiscreteTopology α] {β : Type*} @[simp] theorem isOpen_discrete (s : Set α) : IsOpen s := (@DiscreteTopology.eq_bot α _).symm ▸ trivial @[simp] theorem isClosed_discrete (s : Set α) : IsClosed s := ⟨isOpen_discrete _⟩ theorem closure_discrete (s : Set α) : closure s = s := (isClosed_discrete _).closure_eq @[simp] theorem dense_discrete {s : Set α} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq] @[simp] theorem denseRange_discrete {ι : Type*} {f : ι → α} : DenseRange f ↔ Surjective f := by rw [DenseRange, dense_discrete, range_eq_univ] @[nontriviality, continuity, fun_prop] theorem continuous_of_discreteTopology [TopologicalSpace β] {f : α → β} : Continuous f := continuous_def.2 fun _ _ => isOpen_discrete _ /-- A function to a discrete topological space is continuous if and only if the preimage of every singleton is open. -/ theorem continuous_discrete_rng {α} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β} : Continuous f ↔ ∀ b : β, IsOpen (f ⁻¹' {b}) := ⟨fun h _ => (isOpen_discrete _).preimage h, fun h => ⟨fun s _ => by rw [← biUnion_of_singleton s, preimage_iUnion₂] exact isOpen_biUnion fun _ _ => h _⟩⟩ @[simp] theorem nhds_discrete (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : @nhds α _ = pure := le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds theorem mem_nhds_discrete {x : α} {s : Set α} : s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure] end DiscreteTopology theorem le_of_nhds_le_nhds (h : ∀ x, @nhds α t₁ x ≤ @nhds α t₂ x) : t₁ ≤ t₂ := fun s => by rw [@isOpen_iff_mem_nhds _ t₁, @isOpen_iff_mem_nhds _ t₂] exact fun hs a ha => h _ (hs _ ha) theorem eq_bot_of_singletons_open {t : TopologicalSpace α} (h : ∀ x, IsOpen[t] {x}) : t = ⊥ := bot_unique fun s _ => biUnion_of_singleton s ▸ isOpen_biUnion fun x _ => h x theorem discreteTopology_iff_forall_isOpen [TopologicalSpace α] : DiscreteTopology α ↔ ∀ s : Set α, IsOpen s := ⟨@isOpen_discrete _ _, fun h ↦ ⟨eq_bot_of_singletons_open fun _ ↦ h _⟩⟩ @[deprecated discreteTopology_iff_forall_isOpen (since := "2025-10-10")] theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ s : Set X, IsOpen s) ↔ DiscreteTopology X := discreteTopology_iff_forall_isOpen.symm theorem discreteTopology_iff_forall_isClosed [TopologicalSpace α] : DiscreteTopology α ↔ ∀ s : Set α, IsClosed s := discreteTopology_iff_forall_isOpen.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↦ isOpen_compl_iff theorem discreteTopology_iff_isOpen_singleton [TopologicalSpace α] : DiscreteTopology α ↔ (∀ a : α, IsOpen ({a} : Set α)):= ⟨fun _ _ ↦ isOpen_discrete _, fun h ↦ ⟨eq_bot_of_singletons_open h⟩⟩ @[deprecated discreteTopology_iff_isOpen_singleton (since := "2025-10-10")] theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X := discreteTopology_iff_isOpen_singleton.symm theorem DiscreteTopology.of_finite_of_isClosed_singleton [TopologicalSpace α] [Finite α] (h : ∀ a : α, IsClosed {a}) : DiscreteTopology α := discreteTopology_iff_forall_isClosed.mpr fun s ↦ s.iUnion_of_singleton_coe ▸ isClosed_iUnion_of_finite fun _ ↦ h _ theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, {x} ∈ 𝓝 x := by simp only [discreteTopology_iff_isOpen_singleton, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq] /-- This lemma characterizes discrete topological spaces as those whose singletons are neighbourhoods. -/ theorem discreteTopology_iff_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝 x = pure x := by simp only [discreteTopology_iff_singleton_mem_nhds] apply forall_congr' (fun x ↦ ?_) simp [le_antisymm_iff, pure_le_nhds x] theorem discreteTopology_iff_nhds_ne [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝[≠] x = ⊥ := by simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl] /-- If the codomain of a continuous injective function has discrete topology, then so does the domain. See also `Embedding.discreteTopology` for an important special case. -/ theorem DiscreteTopology.of_continuous_injective {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β} (hc : Continuous f) (hinj : Injective f) : DiscreteTopology α := discreteTopology_iff_forall_isOpen.2 fun s ↦ hinj.preimage_image s ▸ (isOpen_discrete _).preimage hc end Lattice section GaloisConnection variable {α β γ : Type*} theorem isOpen_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsOpen[t.induced f] s ↔ ∃ t, IsOpen t ∧ f ⁻¹' t = s := Iff.rfl theorem isClosed_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsClosed[t.induced f] s ↔ ∃ t, IsClosed t ∧ f ⁻¹' t = s := by letI := t.induced f simp only [← isOpen_compl_iff, isOpen_induced_iff] exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff]) theorem isOpen_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} : IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) := Iff.rfl theorem isClosed_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} : IsClosed[t.coinduced f] s ↔ IsClosed (f ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_coinduced (f := f), preimage_compl] theorem preimage_nhds_coinduced [TopologicalSpace α] {π : α → β} {s : Set β} {a : α} (hs : s ∈ @nhds β (TopologicalSpace.coinduced π ‹_›) (π a)) : π ⁻¹' s ∈ 𝓝 a := by letI := TopologicalSpace.coinduced π ‹_› rcases mem_nhds_iff.mp hs with ⟨V, hVs, V_op, mem_V⟩ exact mem_nhds_iff.mpr ⟨π ⁻¹' V, Set.preimage_mono hVs, V_op, mem_V⟩ variable {t t₁ t₂ : TopologicalSpace α} {t' : TopologicalSpace β} {f : α → β} {g : β → α} theorem Continuous.coinduced_le (h : Continuous[t, t'] f) : t.coinduced f ≤ t' := (@continuous_def α β t t').1 h theorem coinduced_le_iff_le_induced {f : α → β} {tα : TopologicalSpace α} {tβ : TopologicalSpace β} : tα.coinduced f ≤ tβ ↔ tα ≤ tβ.induced f := ⟨fun h _s ⟨_t, ht, hst⟩ => hst ▸ h _ ht, fun h s hs => h _ ⟨s, hs, rfl⟩⟩ theorem Continuous.le_induced (h : Continuous[t, t'] f) : t ≤ t'.induced f := coinduced_le_iff_le_induced.1 h.coinduced_le theorem gc_coinduced_induced (f : α → β) : GaloisConnection (TopologicalSpace.coinduced f) (TopologicalSpace.induced f) := fun _ _ => coinduced_le_iff_le_induced @[gcongr] theorem induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g := (gc_coinduced_induced g).monotone_u h @[gcongr] theorem coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f := (gc_coinduced_induced f).monotone_l h @[simp] theorem induced_top : (⊤ : TopologicalSpace α).induced g = ⊤ := (gc_coinduced_induced g).u_top @[simp] theorem induced_inf : (t₁ ⊓ t₂).induced g = t₁.induced g ⊓ t₂.induced g := (gc_coinduced_induced g).u_inf @[simp] theorem induced_iInf {ι : Sort w} {t : ι → TopologicalSpace α} : (⨅ i, t i).induced g = ⨅ i, (t i).induced g := (gc_coinduced_induced g).u_iInf @[simp] theorem induced_sInf {s : Set (TopologicalSpace α)} : TopologicalSpace.induced g (sInf s) = sInf (TopologicalSpace.induced g '' s) := by rw [sInf_eq_iInf', sInf_image', induced_iInf] @[simp] theorem coinduced_bot : (⊥ : TopologicalSpace α).coinduced f = ⊥ := (gc_coinduced_induced f).l_bot @[simp] theorem coinduced_sup : (t₁ ⊔ t₂).coinduced f = t₁.coinduced f ⊔ t₂.coinduced f := (gc_coinduced_induced f).l_sup @[simp] theorem coinduced_iSup {ι : Sort w} {t : ι → TopologicalSpace α} : (⨆ i, t i).coinduced f = ⨆ i, (t i).coinduced f := (gc_coinduced_induced f).l_iSup @[simp] theorem coinduced_sSup {s : Set (TopologicalSpace α)} : TopologicalSpace.coinduced f (sSup s) = sSup ((TopologicalSpace.coinduced f) '' s) := by rw [sSup_eq_iSup', sSup_image', coinduced_iSup] theorem induced_id [t : TopologicalSpace α] : t.induced id = t := TopologicalSpace.ext <| funext fun s => propext <| ⟨fun ⟨_, hs, h⟩ => h ▸ hs, fun hs => ⟨s, hs, rfl⟩⟩ theorem induced_compose {tγ : TopologicalSpace γ} {f : α → β} {g : β → γ} : (tγ.induced g).induced f = tγ.induced (g ∘ f) := TopologicalSpace.ext <| funext fun _ => propext ⟨fun ⟨_, ⟨s, hs, h₂⟩, h₁⟩ => h₁ ▸ h₂ ▸ ⟨s, hs, rfl⟩, fun ⟨s, hs, h⟩ => ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩ theorem induced_const [t : TopologicalSpace α] {x : α} : (t.induced fun _ : β => x) = ⊤ := le_antisymm le_top (@continuous_const β α ⊤ t x).le_induced theorem coinduced_id [t : TopologicalSpace α] : t.coinduced id = t := TopologicalSpace.ext rfl theorem coinduced_compose [tα : TopologicalSpace α] {f : α → β} {g : β → γ} : (tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) := TopologicalSpace.ext rfl theorem Equiv.induced_symm {α β : Type*} (e : α ≃ β) : TopologicalSpace.induced e.symm = TopologicalSpace.coinduced e := by ext t U rw [isOpen_induced_iff, isOpen_coinduced] simp only [e.symm.preimage_eq_iff_eq_image, exists_eq_right, Equiv.image_symm_eq_preimage] theorem Equiv.coinduced_symm {α β : Type*} (e : α ≃ β) : TopologicalSpace.coinduced e.symm = TopologicalSpace.induced e := e.symm.induced_symm.symm end GaloisConnection -- constructions using the complete lattice structure section Constructions open TopologicalSpace variable {α : Type u} {β : Type v} instance inhabitedTopologicalSpace {α : Type u} : Inhabited (TopologicalSpace α) := ⟨⊥⟩ instance (priority := 100) Subsingleton.uniqueTopologicalSpace [Subsingleton α] : Unique (TopologicalSpace α) where default := ⊥ uniq t := eq_bot_of_singletons_open fun x => Subsingleton.set_cases (@isOpen_empty _ t) (@isOpen_univ _ t) ({x} : Set α) instance (priority := 100) Subsingleton.discreteTopology [t : TopologicalSpace α] [Subsingleton α] : DiscreteTopology α := ⟨Unique.eq_default t⟩ instance : TopologicalSpace Empty := ⊥ instance : DiscreteTopology Empty := ⟨rfl⟩ instance : TopologicalSpace PEmpty := ⊥ instance : DiscreteTopology PEmpty := ⟨rfl⟩ instance : TopologicalSpace PUnit := ⊥ instance : DiscreteTopology PUnit := ⟨rfl⟩ instance : TopologicalSpace Bool := ⊥ instance : DiscreteTopology Bool := ⟨rfl⟩ instance : TopologicalSpace ℕ := ⊥ instance : DiscreteTopology ℕ := ⟨rfl⟩ instance : TopologicalSpace ℤ := ⊥ instance : DiscreteTopology ℤ := ⟨rfl⟩ instance {n} : TopologicalSpace (Fin n) := ⊥ instance {n} : DiscreteTopology (Fin n) := ⟨rfl⟩ lemma Nat.cast_continuous {R : Type*} [NatCast R] [TopologicalSpace R] : Continuous (Nat.cast (R := R)) := continuous_of_discreteTopology lemma Int.cast_continuous {R : Type*} [IntCast R] [TopologicalSpace R] : Continuous (Int.cast (R := R)) := continuous_of_discreteTopology instance sierpinskiSpace : TopologicalSpace Prop := generateFrom {{True}} /-- See also `continuous_of_discreteTopology`, which works for `IsEmpty α`. -/ theorem continuous_empty_function [TopologicalSpace α] [TopologicalSpace β] [IsEmpty β] (f : α → β) : Continuous f := letI := Function.isEmpty f continuous_of_discreteTopology theorem le_generateFrom {t : TopologicalSpace α} {g : Set (Set α)} (h : ∀ s ∈ g, IsOpen s) : t ≤ generateFrom g := le_generateFrom_iff_subset_isOpen.2 h theorem induced_generateFrom_eq {α β} {b : Set (Set β)} {f : α → β} : (generateFrom b).induced f = generateFrom (preimage f '' b) := le_antisymm (le_generateFrom <| forall_mem_image.2 fun s hs => ⟨s, GenerateOpen.basic _ hs, rfl⟩) (coinduced_le_iff_le_induced.1 <| le_generateFrom fun _s hs => .basic _ (mem_image_of_mem _ hs)) theorem le_induced_generateFrom {α β} [t : TopologicalSpace α] {b : Set (Set β)} {f : α → β} (h : ∀ a : Set β, a ∈ b → IsOpen (f ⁻¹' a)) : t ≤ induced f (generateFrom b) := by rw [induced_generateFrom_eq] apply le_generateFrom simp only [mem_image, and_imp, forall_apply_eq_imp_iff₂, exists_imp] exact h lemma generateFrom_insert_of_generateOpen {α : Type*} {s : Set (Set α)} {t : Set α} (ht : GenerateOpen s t) : generateFrom (insert t s) = generateFrom s := by refine le_antisymm (generateFrom_anti <| subset_insert t s) (le_generateFrom ?_) rintro t (rfl | h) · exact ht · exact isOpen_generateFrom_of_mem h @[simp] lemma generateFrom_insert_univ {α : Type*} {s : Set (Set α)} : generateFrom (insert univ s) = generateFrom s := generateFrom_insert_of_generateOpen .univ @[simp] lemma generateFrom_insert_empty {α : Type*} {s : Set (Set α)} : generateFrom (insert ∅ s) = generateFrom s := by rw [← sUnion_empty] exact generateFrom_insert_of_generateOpen (.sUnion ∅ (fun s_1 a ↦ False.elim a)) /-- This construction is left adjoint to the operation sending a topology on `α` to its neighborhood filter at a fixed point `a : α`. -/ def nhdsAdjoint (a : α) (f : Filter α) : TopologicalSpace α where IsOpen s := a ∈ s → s ∈ f isOpen_univ _ := univ_mem isOpen_inter := fun _s _t hs ht ⟨has, hat⟩ => inter_mem (hs has) (ht hat) isOpen_sUnion := fun _k hk ⟨u, hu, hau⟩ => mem_of_superset (hk u hu hau) (subset_sUnion_of_mem hu) theorem gc_nhds (a : α) : GaloisConnection (nhdsAdjoint a) fun t => @nhds α t a := fun f t => by rw [le_nhds_iff] exact ⟨fun H s hs has => H _ has hs, fun H s has hs => H _ hs has⟩ theorem nhds_mono {t₁ t₂ : TopologicalSpace α} {a : α} (h : t₁ ≤ t₂) : @nhds α t₁ a ≤ @nhds α t₂ a := (gc_nhds a).monotone_u h theorem le_iff_nhds {α : Type*} (t t' : TopologicalSpace α) : t ≤ t' ↔ ∀ x, @nhds α t x ≤ @nhds α t' x := ⟨fun h _ => nhds_mono h, le_of_nhds_le_nhds⟩ theorem isOpen_singleton_nhdsAdjoint {α : Type*} {a b : α} (f : Filter α) (hb : b ≠ a) : IsOpen[nhdsAdjoint a f] {b} := fun h ↦ absurd h hb.symm theorem nhds_nhdsAdjoint_same (a : α) (f : Filter α) : @nhds α (nhdsAdjoint a f) a = pure a ⊔ f := by let _ := nhdsAdjoint a f apply le_antisymm · rintro t ⟨hat : a ∈ t, htf : t ∈ f⟩ exact IsOpen.mem_nhds (fun _ ↦ htf) hat · exact sup_le (pure_le_nhds _) ((gc_nhds a).le_u_l f) theorem nhds_nhdsAdjoint_of_ne {a b : α} (f : Filter α) (h : b ≠ a) : @nhds α (nhdsAdjoint a f) b = pure b := let _ := nhdsAdjoint a f (isOpen_singleton_iff_nhds_eq_pure _).1 <| isOpen_singleton_nhdsAdjoint f h theorem nhds_nhdsAdjoint [DecidableEq α] (a : α) (f : Filter α) : @nhds α (nhdsAdjoint a f) = update pure a (pure a ⊔ f) := eq_update_iff.2 ⟨nhds_nhdsAdjoint_same .., fun _ ↦ nhds_nhdsAdjoint_of_ne _⟩ theorem le_nhdsAdjoint_iff' {a : α} {f : Filter α} {t : TopologicalSpace α} : t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, @nhds α t b = pure b := by classical simp_rw [le_iff_nhds, nhds_nhdsAdjoint, forall_update_iff, (pure_le_nhds _).ge_iff_eq'] theorem le_nhdsAdjoint_iff {α : Type*} (a : α) (f : Filter α) (t : TopologicalSpace α) : t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, IsOpen[t] {b} := by simp only [le_nhdsAdjoint_iff', @isOpen_singleton_iff_nhds_eq_pure α t] theorem nhds_iInf {ι : Sort*} {t : ι → TopologicalSpace α} {a : α} : @nhds α (iInf t) a = ⨅ i, @nhds α (t i) a := (gc_nhds a).u_iInf theorem nhds_sInf {s : Set (TopologicalSpace α)} {a : α} : @nhds α (sInf s) a = ⨅ t ∈ s, @nhds α t a := (gc_nhds a).u_sInf -- Porting note: type error without `b₁ := t₁` theorem nhds_inf {t₁ t₂ : TopologicalSpace α} {a : α} : @nhds α (t₁ ⊓ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a := (gc_nhds a).u_inf (b₁ := t₁) theorem nhds_top {a : α} : @nhds α ⊤ a = ⊤ := (gc_nhds a).u_top theorem isOpen_sup {t₁ t₂ : TopologicalSpace α} {s : Set α} : IsOpen[t₁ ⊔ t₂] s ↔ IsOpen[t₁] s ∧ IsOpen[t₂] s := Iff.rfl /-- In the trivial topology no points are separable. The corresponding `bot` lemma is handled more generally by `inseparable_iff_eq`. -/ @[simp] theorem inseparable_top (x y : α) : @Inseparable α ⊤ x y := nhds_top.trans nhds_top.symm theorem TopologicalSpace.eq_top_iff_forall_inseparable {t : TopologicalSpace α} : t = ⊤ ↔ (∀ x y : α, Inseparable x y) where mp h := h ▸ inseparable_top mpr h := ext_nhds fun x => nhds_top ▸ top_unique fun _ hs a => mem_of_mem_nhds <| h x a ▸ hs theorem TopologicalSpace.ne_top_iff_exists_not_inseparable {t : TopologicalSpace α} : t ≠ ⊤ ↔ ∃ x y : α, ¬Inseparable x y := by simpa using eq_top_iff_forall_inseparable.not open TopologicalSpace variable {γ : Type*} {f : α → β} {ι : Sort*} theorem continuous_iff_coinduced_le {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} : Continuous[t₁, t₂] f ↔ coinduced f t₁ ≤ t₂ := continuous_def theorem continuous_iff_le_induced {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} : Continuous[t₁, t₂] f ↔ t₁ ≤ induced f t₂ := Iff.trans continuous_iff_coinduced_le (gc_coinduced_induced f _ _) lemma continuous_generateFrom_iff {t : TopologicalSpace α} {b : Set (Set β)} : Continuous[t, generateFrom b] f ↔ ∀ s ∈ b, IsOpen (f ⁻¹' s) := by rw [continuous_iff_coinduced_le, le_generateFrom_iff_subset_isOpen] simp only [isOpen_coinduced, preimage_id', subset_def, mem_setOf] @[continuity, fun_prop] theorem continuous_induced_dom {t : TopologicalSpace β} : Continuous[induced f t, t] f := continuous_iff_le_induced.2 le_rfl theorem continuous_induced_rng {g : γ → α} {t₂ : TopologicalSpace β} {t₁ : TopologicalSpace γ} : Continuous[t₁, induced f t₂] g ↔ Continuous[t₁, t₂] (f ∘ g) := by simp only [continuous_iff_le_induced, induced_compose] theorem continuous_coinduced_rng {t : TopologicalSpace α} : Continuous[t, coinduced f t] f := continuous_iff_coinduced_le.2 le_rfl theorem continuous_coinduced_dom {g : β → γ} {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace γ} : Continuous[coinduced f t₁, t₂] g ↔ Continuous[t₁, t₂] (g ∘ f) := by simp only [continuous_iff_coinduced_le, coinduced_compose] theorem continuous_le_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) (h₂ : Continuous[t₁, t₃] f) : Continuous[t₂, t₃] f := by rw [continuous_iff_le_induced] at h₂ ⊢ exact le_trans h₁ h₂ theorem continuous_le_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) (h₂ : Continuous[t₁, t₂] f) : Continuous[t₁, t₃] f := by rw [continuous_iff_coinduced_le] at h₂ ⊢ exact le_trans h₂ h₁ theorem continuous_sup_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} : Continuous[t₁ ⊔ t₂, t₃] f ↔ Continuous[t₁, t₃] f ∧ Continuous[t₂, t₃] f := by simp only [continuous_iff_le_induced, sup_le_iff] theorem continuous_sup_rng_left {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} : Continuous[t₁, t₂] f → Continuous[t₁, t₂ ⊔ t₃] f := continuous_le_rng le_sup_left theorem continuous_sup_rng_right {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} : Continuous[t₁, t₃] f → Continuous[t₁, t₂ ⊔ t₃] f := continuous_le_rng le_sup_right theorem continuous_sSup_dom {T : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β} : Continuous[sSup T, t₂] f ↔ ∀ t ∈ T, Continuous[t, t₂] f := by simp only [continuous_iff_le_induced, sSup_le_iff] theorem continuous_sSup_rng {t₁ : TopologicalSpace α} {t₂ : Set (TopologicalSpace β)} {t : TopologicalSpace β} (h₁ : t ∈ t₂) (hf : Continuous[t₁, t] f) : Continuous[t₁, sSup t₂] f := continuous_iff_coinduced_le.2 <| le_sSup_of_le h₁ <| continuous_iff_coinduced_le.1 hf theorem continuous_iSup_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} : Continuous[iSup t₁, t₂] f ↔ ∀ i, Continuous[t₁ i, t₂] f := by simp only [continuous_iff_le_induced, iSup_le_iff] theorem continuous_iSup_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} {i : ι} (h : Continuous[t₁, t₂ i] f) : Continuous[t₁, iSup t₂] f := continuous_sSup_rng ⟨i, rfl⟩ h theorem continuous_inf_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} : Continuous[t₁, t₂ ⊓ t₃] f ↔ Continuous[t₁, t₂] f ∧ Continuous[t₁, t₃] f := by simp only [continuous_iff_coinduced_le, le_inf_iff] theorem continuous_inf_dom_left {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} : Continuous[t₁, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f := continuous_le_dom inf_le_left theorem continuous_inf_dom_right {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} : Continuous[t₂, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f := continuous_le_dom inf_le_right theorem continuous_sInf_dom {t₁ : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β} {t : TopologicalSpace α} (h₁ : t ∈ t₁) : Continuous[t, t₂] f → Continuous[sInf t₁, t₂] f := continuous_le_dom <| sInf_le h₁ theorem continuous_sInf_rng {t₁ : TopologicalSpace α} {T : Set (TopologicalSpace β)} : Continuous[t₁, sInf T] f ↔ ∀ t ∈ T, Continuous[t₁, t] f := by simp only [continuous_iff_coinduced_le, le_sInf_iff] theorem continuous_iInf_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} {i : ι} : Continuous[t₁ i, t₂] f → Continuous[iInf t₁, t₂] f := continuous_le_dom <| iInf_le _ _ theorem continuous_iInf_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} : Continuous[t₁, iInf t₂] f ↔ ∀ i, Continuous[t₁, t₂ i] f := by simp only [continuous_iff_coinduced_le, le_iInf_iff] @[continuity, fun_prop] theorem continuous_bot {t : TopologicalSpace β} : Continuous[⊥, t] f := continuous_iff_le_induced.2 bot_le @[continuity, fun_prop] theorem continuous_top {t : TopologicalSpace α} : Continuous[t, ⊤] f := continuous_iff_coinduced_le.2 le_top theorem continuous_id_iff_le {t t' : TopologicalSpace α} : Continuous[t, t'] id ↔ t ≤ t' := @continuous_def _ _ t t' id theorem continuous_id_of_le {t t' : TopologicalSpace α} (h : t ≤ t') : Continuous[t, t'] id := continuous_id_iff_le.2 h -- 𝓝 in the induced topology theorem mem_nhds_induced [T : TopologicalSpace α] (f : β → α) (a : β) (s : Set β) : s ∈ @nhds β (TopologicalSpace.induced f T) a ↔ ∃ u ∈ 𝓝 (f a), f ⁻¹' u ⊆ s := by letI := T.induced f simp_rw [mem_nhds_iff, isOpen_induced_iff] constructor · rintro ⟨u, usub, ⟨v, openv, rfl⟩, au⟩ exact ⟨v, ⟨v, Subset.rfl, openv, au⟩, usub⟩ · rintro ⟨u, ⟨v, vsubu, openv, amem⟩, finvsub⟩ exact ⟨f ⁻¹' v, (Set.preimage_mono vsubu).trans finvsub, ⟨⟨v, openv, rfl⟩, amem⟩⟩ theorem nhds_induced [T : TopologicalSpace α] (f : β → α) (a : β) : @nhds β (TopologicalSpace.induced f T) a = comap f (𝓝 (f a)) := by ext s rw [mem_nhds_induced, mem_comap] theorem induced_iff_nhds_eq [tα : TopologicalSpace α] [tβ : TopologicalSpace β] (f : β → α) : tβ = tα.induced f ↔ ∀ b, 𝓝 b = comap f (𝓝 <| f b) := by simp only [ext_iff_nhds, nhds_induced] theorem map_nhds_induced_of_surjective [T : TopologicalSpace α] {f : β → α} (hf : Surjective f) (a : β) : map f (@nhds β (TopologicalSpace.induced f T) a) = 𝓝 (f a) := by rw [nhds_induced, map_comap_of_surjective hf] theorem continuous_nhdsAdjoint_dom [TopologicalSpace β] {f : α → β} {a : α} {l : Filter α} : Continuous[nhdsAdjoint a l, _] f ↔ Tendsto f l (𝓝 (f a)) := by simp_rw [continuous_iff_le_induced, gc_nhds _ _, nhds_induced, tendsto_iff_comap] theorem coinduced_nhdsAdjoint (f : α → β) (a : α) (l : Filter α) : coinduced f (nhdsAdjoint a l) = nhdsAdjoint (f a) (map f l) := eq_of_forall_ge_iff fun _ ↦ by rw [gc_nhds, ← continuous_iff_coinduced_le, continuous_nhdsAdjoint_dom, Tendsto] end Constructions section Induced open TopologicalSpace variable {α : Type*} {β : Type*} variable [t : TopologicalSpace β] {f : α → β} theorem isOpen_induced_eq {s : Set α} : IsOpen[induced f t] s ↔ s ∈ preimage f '' { s | IsOpen s } := Iff.rfl theorem isOpen_induced {s : Set β} (h : IsOpen s) : IsOpen[induced f t] (f ⁻¹' s) := ⟨s, h, rfl⟩ theorem map_nhds_induced_eq (a : α) : map f (@nhds α (induced f t) a) = 𝓝[range f] f a := by rw [nhds_induced, Filter.map_comap, nhdsWithin] theorem map_nhds_induced_of_mem {a : α} (h : range f ∈ 𝓝 (f a)) : map f (@nhds α (induced f t) a) = 𝓝 (f a) := by rw [nhds_induced, Filter.map_comap_of_mem h] theorem closure_induced {f : α → β} {a : α} {s : Set α} : a ∈ @closure α (t.induced f) s ↔ f a ∈ closure (f '' s) := by simp only [mem_closure_iff_frequently, nhds_induced, frequently_comap, mem_image, and_comm] theorem isClosed_induced_iff' {f : α → β} {s : Set α} : IsClosed[t.induced f] s ↔ ∀ a, f a ∈ closure (f '' s) → a ∈ s := by simp only [← closure_subset_iff_isClosed, subset_def, closure_induced] end Induced section Sierpinski variable {α : Type*} @[simp] theorem isOpen_singleton_true : IsOpen ({True} : Set Prop) := TopologicalSpace.GenerateOpen.basic _ (mem_singleton _) @[simp] theorem nhds_true : 𝓝 True = pure True := le_antisymm (le_pure_iff.2 <| isOpen_singleton_true.mem_nhds <| mem_singleton _) (pure_le_nhds _) @[simp] theorem nhds_false : 𝓝 False = ⊤ := TopologicalSpace.nhds_generateFrom.trans <| by simp [@and_comm (_ ∈ _)] theorem tendsto_nhds_true {l : Filter α} {p : α → Prop} : Tendsto p l (𝓝 True) ↔ ∀ᶠ x in l, p x := by simp theorem tendsto_nhds_Prop {l : Filter α} {p : α → Prop} {q : Prop} : Tendsto p l (𝓝 q) ↔ (q → ∀ᶠ x in l, p x) := by by_cases q <;> simp [*] variable [TopologicalSpace α] theorem continuous_Prop {p : α → Prop} : Continuous p ↔ IsOpen { x | p x } := by simp only [continuous_iff_continuousAt, ContinuousAt, tendsto_nhds_Prop, isOpen_iff_mem_nhds]; rfl theorem isOpen_iff_continuous_mem {s : Set α} : IsOpen s ↔ Continuous (· ∈ s) := continuous_Prop.symm end Sierpinski section iInf open TopologicalSpace variable {α : Type u} {ι : Sort v} theorem generateFrom_union (a₁ a₂ : Set (Set α)) : generateFrom (a₁ ∪ a₂) = generateFrom a₁ ⊓ generateFrom a₂ := (gc_generateFrom α).u_inf theorem setOf_isOpen_sup (t₁ t₂ : TopologicalSpace α) : { s | IsOpen[t₁ ⊔ t₂] s } = { s | IsOpen[t₁] s } ∩ { s | IsOpen[t₂] s } := rfl theorem generateFrom_iUnion {f : ι → Set (Set α)} : generateFrom (⋃ i, f i) = ⨅ i, generateFrom (f i) := (gc_generateFrom α).u_iInf theorem setOf_isOpen_iSup {t : ι → TopologicalSpace α} : { s | IsOpen[⨆ i, t i] s } = ⋂ i, { s | IsOpen[t i] s } := (gc_generateFrom α).l_iSup theorem generateFrom_sUnion {S : Set (Set (Set α))} : generateFrom (⋃₀ S) = ⨅ s ∈ S, generateFrom s := (gc_generateFrom α).u_sInf theorem setOf_isOpen_sSup {T : Set (TopologicalSpace α)} : { s | IsOpen[sSup T] s } = ⋂ t ∈ T, { s | IsOpen[t] s } := (gc_generateFrom α).l_sSup theorem generateFrom_union_isOpen (a b : TopologicalSpace α) : generateFrom ({ s | IsOpen[a] s } ∪ { s | IsOpen[b] s }) = a ⊓ b := (gciGenerateFrom α).u_inf_l _ _ theorem generateFrom_iUnion_isOpen (f : ι → TopologicalSpace α) : generateFrom (⋃ i, { s | IsOpen[f i] s }) = ⨅ i, f i := (gciGenerateFrom α).u_iInf_l _ theorem generateFrom_inter (a b : TopologicalSpace α) : generateFrom ({ s | IsOpen[a] s } ∩ { s | IsOpen[b] s }) = a ⊔ b := (gciGenerateFrom α).u_sup_l _ _ theorem generateFrom_iInter (f : ι → TopologicalSpace α) : generateFrom (⋂ i, { s | IsOpen[f i] s }) = ⨆ i, f i := (gciGenerateFrom α).u_iSup_l _ theorem generateFrom_iInter_of_generateFrom_eq_self (f : ι → Set (Set α)) (hf : ∀ i, { s | IsOpen[generateFrom (f i)] s } = f i) : generateFrom (⋂ i, f i) = ⨆ i, generateFrom (f i) := (gciGenerateFrom α).u_iSup_of_lu_eq_self f hf variable {t : ι → TopologicalSpace α} theorem isOpen_iSup_iff {s : Set α} : IsOpen[⨆ i, t i] s ↔ ∀ i, IsOpen[t i] s := show s ∈ {s | IsOpen[iSup t] s} ↔ s ∈ { x : Set α | ∀ i : ι, IsOpen[t i] x } by simp [setOf_isOpen_iSup] theorem isOpen_sSup_iff {s : Set α} {T : Set (TopologicalSpace α)} : IsOpen[sSup T] s ↔ ∀ t ∈ T, IsOpen[t] s := by simp only [sSup_eq_iSup, isOpen_iSup_iff] theorem isClosed_iSup_iff {s : Set α} : IsClosed[⨆ i, t i] s ↔ ∀ i, IsClosed[t i] s := by simp only [← @isOpen_compl_iff _ _ (⨆ i, t i), ← @isOpen_compl_iff _ _ (t _), isOpen_iSup_iff] theorem isClosed_sSup_iff {s : Set α} {T : Set (TopologicalSpace α)} : IsClosed[sSup T] s ↔ ∀ t ∈ T, IsClosed[t] s := by simp only [sSup_eq_iSup, isClosed_iSup_iff] end iInf
.lake/packages/mathlib/Mathlib/Topology/IsLocalHomeomorph.lean
import Mathlib.Topology.OpenPartialHomeomorph import Mathlib.Topology.SeparatedMap /-! # Local homeomorphisms This file defines local homeomorphisms. ## Main definitions For a function `f : X → Y ` between topological spaces, we say * `IsLocalHomeomorphOn f s` if `f` is a local homeomorphism around each point of `s`: for each `x : X`, the restriction of `f` to some open neighborhood `U` of `x` gives a homeomorphism between `U` and an open subset of `Y`. * `IsLocalHomeomorph f`: `f` is a local homeomorphism, i.e. it's a local homeomorphism on `univ`. Note that `IsLocalHomeomorph` is a global condition. This is in contrast to `OpenPartialHomeomorph`, which is a homeomorphism between specific open subsets. ## Main results * local homeomorphisms are locally injective open maps * more! -/ open Topology variable {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] (g : Y → Z) (f : X → Y) (s : Set X) (t : Set Y) /-- A function `f : X → Y` satisfies `IsLocalHomeomorphOn f s` if each `x ∈ s` is contained in the source of some `e : OpenPartialHomeomorph X Y` with `f = e`. -/ def IsLocalHomeomorphOn := ∀ x ∈ s, ∃ e : OpenPartialHomeomorph X Y, x ∈ e.source ∧ f = e theorem isLocalHomeomorphOn_iff_isOpenEmbedding_restrict {f : X → Y} : IsLocalHomeomorphOn f s ↔ ∀ x ∈ s, ∃ U ∈ 𝓝 x, IsOpenEmbedding (U.restrict f) := by refine ⟨fun h x hx ↦ ?_, fun h x hx ↦ ?_⟩ · obtain ⟨e, hxe, rfl⟩ := h x hx exact ⟨e.source, e.open_source.mem_nhds hxe, e.isOpenEmbedding_restrict⟩ · obtain ⟨U, hU, emb⟩ := h x hx have : IsOpenEmbedding ((interior U).restrict f) := by refine emb.comp ⟨.inclusion interior_subset, ?_⟩ rw [Set.range_inclusion]; exact isOpen_induced isOpen_interior obtain ⟨cont, inj, openMap⟩ := isOpenEmbedding_iff_continuous_injective_isOpenMap.mp this haveI : Nonempty X := ⟨x⟩ exact ⟨OpenPartialHomeomorph.ofContinuousOpenRestrict (Set.injOn_iff_injective.mpr inj).toPartialEquiv (continuousOn_iff_continuous_restrict.mpr cont) openMap isOpen_interior, mem_interior_iff_mem_nhds.mpr hU, rfl⟩ namespace IsLocalHomeomorphOn variable {f s} theorem discreteTopology_of_image (h : IsLocalHomeomorphOn f s) [DiscreteTopology (f '' s)] : DiscreteTopology s := discreteTopology_iff_isOpen_singleton.mpr fun x ↦ by obtain ⟨e, hx, rfl⟩ := h x x.2 have ⟨U, hU, eq⟩ := isOpen_discrete {(⟨_, _, x.2, rfl⟩ : e '' s)} refine ⟨e.source ∩ e ⁻¹' U, e.continuousOn_toFun.isOpen_inter_preimage e.open_source hU, subset_antisymm (fun x' mem ↦ Subtype.ext <| e.injOn mem.1 hx ?_) ?_⟩ · exact Subtype.ext_iff.mp (eq.subset (a := ⟨_, x', x'.2, rfl⟩) mem.2) · rintro x rfl; exact ⟨hx, eq.superset rfl⟩ theorem discreteTopology_image_iff (h : IsLocalHomeomorphOn f s) (hs : IsOpen s) : DiscreteTopology (f '' s) ↔ DiscreteTopology s := by refine ⟨fun _ ↦ h.discreteTopology_of_image, ?_⟩ simp_rw [discreteTopology_iff_isOpen_singleton] rintro hX ⟨_, x, hx, rfl⟩ obtain ⟨e, hxe, rfl⟩ := h x hx refine ⟨e '' {x}, e.isOpen_image_of_subset_source ?_ (Set.singleton_subset_iff.mpr hxe), ?_⟩ · simpa using hs.isOpenMap_subtype_val _ (hX ⟨x, hx⟩) · ext; simp [Subtype.ext_iff] variable (f s) in /-- Proves that `f` satisfies `IsLocalHomeomorphOn f s`. The condition `h` is weaker than the definition of `IsLocalHomeomorphOn f s`, since it only requires `e : OpenPartialHomeomorph X Y` to agree with `f` on its source `e.source`, as opposed to on the whole space `X`. -/ theorem mk (h : ∀ x ∈ s, ∃ e : OpenPartialHomeomorph X Y, x ∈ e.source ∧ Set.EqOn f e e.source) : IsLocalHomeomorphOn f s := by intro x hx obtain ⟨e, hx, he⟩ := h x hx exact ⟨{ e with toFun := f map_source' := fun _x hx ↦ by rw [he hx]; exact e.map_source' hx left_inv' := fun _x hx ↦ by rw [he hx]; exact e.left_inv' hx right_inv' := fun _y hy ↦ by rw [he (e.map_target' hy)]; exact e.right_inv' hy continuousOn_toFun := (continuousOn_congr he).mpr e.continuousOn_toFun }, hx, rfl⟩ /-- A `OpenPartialHomeomorph` is a local homeomorphism on its source. -/ lemma OpenPartialHomeomorph.isLocalHomeomorphOn (e : OpenPartialHomeomorph X Y) : IsLocalHomeomorphOn e e.source := fun _ hx ↦ ⟨e, hx, rfl⟩ variable {g t} theorem mono {t : Set X} (hf : IsLocalHomeomorphOn f t) (hst : s ⊆ t) : IsLocalHomeomorphOn f s := fun x hx ↦ hf x (hst hx) theorem of_comp_left (hgf : IsLocalHomeomorphOn (g ∘ f) s) (hg : IsLocalHomeomorphOn g (f '' s)) (cont : ∀ x ∈ s, ContinuousAt f x) : IsLocalHomeomorphOn f s := mk f s fun x hx ↦ by obtain ⟨g, hxg, rfl⟩ := hg (f x) ⟨x, hx, rfl⟩ obtain ⟨gf, hgf, he⟩ := hgf x hx refine ⟨(gf.restr <| f ⁻¹' g.source).trans g.symm, ⟨⟨hgf, mem_interior_iff_mem_nhds.mpr ((cont x hx).preimage_mem_nhds <| g.open_source.mem_nhds hxg)⟩, he ▸ g.map_source hxg⟩, fun y hy ↦ ?_⟩ change f y = g.symm (gf y) have : f y ∈ g.source := by apply interior_subset hy.1.2 rw [← he, g.eq_symm_apply this (by apply g.map_source this), Function.comp_apply] theorem of_comp_right (hgf : IsLocalHomeomorphOn (g ∘ f) s) (hf : IsLocalHomeomorphOn f s) : IsLocalHomeomorphOn g (f '' s) := mk g _ <| by rintro _ ⟨x, hx, rfl⟩ obtain ⟨f, hxf, rfl⟩ := hf x hx obtain ⟨gf, hgf, he⟩ := hgf x hx refine ⟨f.symm.trans gf, ⟨f.map_source hxf, ?_⟩, fun y hy ↦ ?_⟩ · apply (f.left_inv hxf).symm ▸ hgf · change g y = gf (f.symm y) rw [← he, Function.comp_apply, f.right_inv hy.1] theorem map_nhds_eq (hf : IsLocalHomeomorphOn f s) {x : X} (hx : x ∈ s) : (𝓝 x).map f = 𝓝 (f x) := let ⟨e, hx, he⟩ := hf x hx he.symm ▸ e.map_nhds_eq hx protected theorem continuousAt (hf : IsLocalHomeomorphOn f s) {x : X} (hx : x ∈ s) : ContinuousAt f x := (hf.map_nhds_eq hx).le protected theorem continuousOn (hf : IsLocalHomeomorphOn f s) : ContinuousOn f s := continuousOn_of_forall_continuousAt fun _x ↦ hf.continuousAt protected theorem comp (hg : IsLocalHomeomorphOn g t) (hf : IsLocalHomeomorphOn f s) (h : Set.MapsTo f s t) : IsLocalHomeomorphOn (g ∘ f) s := by intro x hx obtain ⟨eg, hxg, rfl⟩ := hg (f x) (h hx) obtain ⟨ef, hxf, rfl⟩ := hf x hx exact ⟨ef.trans eg, ⟨hxf, hxg⟩, rfl⟩ end IsLocalHomeomorphOn /-- A function `f : X → Y` satisfies `IsLocalHomeomorph f` if each `x : x` is contained in the source of some `e : OpenPartialHomeomorph X Y` with `f = e`. -/ def IsLocalHomeomorph := ∀ x : X, ∃ e : OpenPartialHomeomorph X Y, x ∈ e.source ∧ f = e theorem Homeomorph.isLocalHomeomorph (f : X ≃ₜ Y) : IsLocalHomeomorph f := fun _ ↦ ⟨f.toOpenPartialHomeomorph, trivial, rfl⟩ variable {f s} theorem isLocalHomeomorph_iff_isLocalHomeomorphOn_univ : IsLocalHomeomorph f ↔ IsLocalHomeomorphOn f Set.univ := ⟨fun h x _ ↦ h x, fun h x ↦ h x trivial⟩ protected theorem IsLocalHomeomorph.isLocalHomeomorphOn (hf : IsLocalHomeomorph f) : IsLocalHomeomorphOn f s := fun x _ ↦ hf x theorem isLocalHomeomorph_iff_isOpenEmbedding_restrict {f : X → Y} : IsLocalHomeomorph f ↔ ∀ x : X, ∃ U ∈ 𝓝 x, IsOpenEmbedding (U.restrict f) := by simp_rw [isLocalHomeomorph_iff_isLocalHomeomorphOn_univ, isLocalHomeomorphOn_iff_isOpenEmbedding_restrict, imp_iff_right (Set.mem_univ _)] theorem Topology.IsOpenEmbedding.isLocalHomeomorph (hf : IsOpenEmbedding f) : IsLocalHomeomorph f := isLocalHomeomorph_iff_isOpenEmbedding_restrict.mpr fun _ ↦ ⟨_, Filter.univ_mem, hf.comp (Homeomorph.Set.univ X).isOpenEmbedding⟩ namespace IsLocalHomeomorph /-- A space that admits a local homeomorphism to a discrete space is itself discrete. -/ theorem comap_discreteTopology (h : IsLocalHomeomorph f) [DiscreteTopology Y] : DiscreteTopology X := (Homeomorph.Set.univ X).discreteTopology_iff.mp h.isLocalHomeomorphOn.discreteTopology_of_image theorem discreteTopology_range_iff (h : IsLocalHomeomorph f) : DiscreteTopology (Set.range f) ↔ DiscreteTopology X := by rw [← Set.image_univ, ← (Homeomorph.Set.univ X).discreteTopology_iff] exact h.isLocalHomeomorphOn.discreteTopology_image_iff isOpen_univ /-- If there is a surjective local homeomorphism between two spaces and one of them is discrete, then both spaces are discrete. -/ theorem discreteTopology_iff_of_surjective (h : IsLocalHomeomorph f) (hs : Function.Surjective f) : DiscreteTopology X ↔ DiscreteTopology Y := by rw [← (Homeomorph.Set.univ Y).discreteTopology_iff, ← hs.range_eq, h.discreteTopology_range_iff] variable (f) /-- Proves that `f` satisfies `IsLocalHomeomorph f`. The condition `h` is weaker than the definition of `IsLocalHomeomorph f`, since it only requires `e : OpenPartialHomeomorph X Y` to agree with `f` on its source `e.source`, as opposed to on the whole space `X`. -/ theorem mk (h : ∀ x : X, ∃ e : OpenPartialHomeomorph X Y, x ∈ e.source ∧ Set.EqOn f e e.source) : IsLocalHomeomorph f := isLocalHomeomorph_iff_isLocalHomeomorphOn_univ.mpr (IsLocalHomeomorphOn.mk f Set.univ fun x _hx ↦ h x) /-- A homeomorphism is a local homeomorphism. -/ lemma Homeomorph.isLocalHomeomorph (h : X ≃ₜ Y) : IsLocalHomeomorph h := fun _ ↦ ⟨h.toOpenPartialHomeomorph, trivial, rfl⟩ variable {g f} lemma isLocallyInjective (hf : IsLocalHomeomorph f) : IsLocallyInjective f := fun x ↦ by obtain ⟨f, hx, rfl⟩ := hf x; exact ⟨f.source, f.open_source, hx, f.injOn⟩ theorem of_comp (hgf : IsLocalHomeomorph (g ∘ f)) (hg : IsLocalHomeomorph g) (cont : Continuous f) : IsLocalHomeomorph f := isLocalHomeomorph_iff_isLocalHomeomorphOn_univ.mpr <| hgf.isLocalHomeomorphOn.of_comp_left hg.isLocalHomeomorphOn fun _ _ ↦ cont.continuousAt theorem map_nhds_eq (hf : IsLocalHomeomorph f) (x : X) : (𝓝 x).map f = 𝓝 (f x) := hf.isLocalHomeomorphOn.map_nhds_eq (Set.mem_univ x) /-- A local homeomorphism is continuous. -/ protected theorem continuous (hf : IsLocalHomeomorph f) : Continuous f := continuousOn_univ.mp hf.isLocalHomeomorphOn.continuousOn /-- A local homeomorphism is an open map. -/ protected theorem isOpenMap (hf : IsLocalHomeomorph f) : IsOpenMap f := IsOpenMap.of_nhds_le fun x ↦ ge_of_eq (hf.map_nhds_eq x) /-- The composition of local homeomorphisms is a local homeomorphism. -/ protected theorem comp (hg : IsLocalHomeomorph g) (hf : IsLocalHomeomorph f) : IsLocalHomeomorph (g ∘ f) := isLocalHomeomorph_iff_isLocalHomeomorphOn_univ.mpr (hg.isLocalHomeomorphOn.comp hf.isLocalHomeomorphOn (Set.univ.mapsTo_univ f)) /-- An injective local homeomorphism is an open embedding. -/ theorem isOpenEmbedding_of_injective (hf : IsLocalHomeomorph f) (hi : f.Injective) : IsOpenEmbedding f := .of_continuous_injective_isOpenMap hf.continuous hi hf.isOpenMap /-- A bijective local homeomorphism is a homeomorphism. -/ noncomputable def toHomeomorph_of_bijective (hf : IsLocalHomeomorph f) (hb : f.Bijective) : X ≃ₜ Y := (Equiv.ofBijective f hb).toHomeomorphOfContinuousOpen hf.continuous hf.isOpenMap /-- Continuous local sections of a local homeomorphism are open embeddings. -/ theorem isOpenEmbedding_of_comp (hf : IsLocalHomeomorph g) (hgf : IsOpenEmbedding (g ∘ f)) (cont : Continuous f) : IsOpenEmbedding f := (hgf.isLocalHomeomorph.of_comp hf cont).isOpenEmbedding_of_injective hgf.injective.of_comp open TopologicalSpace in /-- Ranges of continuous local sections of a local homeomorphism form a basis of the source space. -/ theorem isTopologicalBasis (hf : IsLocalHomeomorph f) : IsTopologicalBasis {U : Set X | ∃ V : Set Y, IsOpen V ∧ ∃ s : C(V,X), f ∘ s = (↑) ∧ Set.range s = U} := by refine isTopologicalBasis_of_isOpen_of_nhds ?_ fun x U hx hU ↦ ?_ · rintro _ ⟨U, hU, s, hs, rfl⟩ refine (isOpenEmbedding_of_comp hf (hs ▸ ⟨IsEmbedding.subtypeVal, ?_⟩) s.continuous).isOpen_range rwa [Subtype.range_val] · obtain ⟨f, hxf, rfl⟩ := hf x refine ⟨f.source ∩ U, ⟨f.target ∩ f.symm ⁻¹' U, f.symm.isOpen_inter_preimage hU, ⟨_, continuousOn_iff_continuous_restrict.mp (f.continuousOn_invFun.mono fun _ h ↦ h.1)⟩, ?_, (Set.range_restrict _ _).trans ?_⟩, ⟨hxf, hx⟩, fun _ h ↦ h.2⟩ · ext y; exact f.right_inv y.2.1 · apply (f.symm_image_target_inter_eq _).trans rw [Set.preimage_inter, ← Set.inter_assoc, Set.inter_eq_self_of_subset_left f.source_preimage_target, f.source_inter_preimage_inv_preimage] end IsLocalHomeomorph
.lake/packages/mathlib/Mathlib/Topology/Coherent.lean
import Mathlib.Topology.Defs.Sequences import Mathlib.Topology.ContinuousOn /-! # Topology generated by its restrictions to subsets We say that restrictions of the topology on `X` to sets from a family `S` generates the original topology, if either of the following equivalent conditions hold: - a set which is relatively open in each `s ∈ S` is open; - a set which is relatively closed in each `s ∈ S` is closed; - for any topological space `Y`, a function `f : X → Y` is continuous provided that it is continuous on each `s ∈ S`. We use the first condition as the definition (see `IsCoherentWith` in `Mathlib/Topology/Defs/Induced.lean`), and provide the others as corollaries. ## Main results - `IsCoherentWith.of_seq`: if `X` is a sequential space and `S` contains all sets of the form `insert x (Set.range u)`, where `u : ℕ → X` is a sequence that converges to `x`, then we have `IsCoherentWith S`; -/ open Filter Set variable {X : Type*} [TopologicalSpace X] {S : Set (Set X)} {t : Set X} {x : X} namespace Topology.IsCoherentWith protected theorem isOpen_iff (hS : IsCoherentWith S) : IsOpen t ↔ ∀ s ∈ S, IsOpen ((↑) ⁻¹' t : Set s) := ⟨fun ht _ _ ↦ ht.preimage continuous_subtype_val, hS.1 t⟩ protected theorem isClosed_iff (hS : IsCoherentWith S) : IsClosed t ↔ ∀ s ∈ S, IsClosed ((↑) ⁻¹' t : Set s) := by simp only [← isOpen_compl_iff, hS.isOpen_iff, preimage_compl] protected theorem continuous_iff {Y : Type*} [TopologicalSpace Y] {f : X → Y} (hS : IsCoherentWith S) : Continuous f ↔ ∀ s ∈ S, ContinuousOn f s := ⟨fun h _ _ ↦ h.continuousOn, fun h ↦ continuous_def.2 fun _u hu ↦ hS.isOpen_iff.2 fun s hs ↦ hu.preimage <| (h s hs).restrict⟩ theorem of_continuous_prop (h : ∀ f : X → Prop, (∀ s ∈ S, ContinuousOn f s) → Continuous f) : IsCoherentWith S where isOpen_of_forall_induced u hu := by simp only [continuousOn_iff_continuous_restrict, continuous_Prop] at * exact h _ hu theorem of_isClosed (h : ∀ t : Set X, (∀ s ∈ S, IsClosed ((↑) ⁻¹' t : Set s)) → IsClosed t) : IsCoherentWith S := ⟨fun _t ht ↦ isClosed_compl_iff.1 <| h _ fun s hs ↦ (ht s hs).isClosed_compl⟩ protected theorem enlarge {T} (hS : IsCoherentWith S) (hT : ∀ s ∈ S, ∃ t ∈ T, s ⊆ t) : IsCoherentWith T := of_continuous_prop fun _f hf ↦ hS.continuous_iff.2 fun s hs ↦ let ⟨t, htT, hst⟩ := hT s hs; (hf t htT).mono hst protected theorem mono {T} (hS : IsCoherentWith S) (hT : S ⊆ T) : IsCoherentWith T := hS.enlarge fun s hs ↦ ⟨s, hT hs, Subset.rfl⟩ /-- If `X` is a sequential space and `S` contains each set of the form `insert x (Set.range u)` where `u : ℕ → X` is a sequence and `x` is its limit, then topology on `X` is generated by its restrictions to the sets of `S`. -/ lemma of_seq [SequentialSpace X] (h : ∀ ⦃u : ℕ → X⦄ ⦃x : X⦄, Tendsto u atTop (𝓝 x) → insert x (range u) ∈ S) : IsCoherentWith S := by refine of_isClosed fun t ht ↦ IsSeqClosed.isClosed fun u x hut hux ↦ ?_ rcases isClosed_induced_iff.1 (ht _ (h hux)) with ⟨s, hsc, hst⟩ rw [Subtype.preimage_val_eq_preimage_val_iff, Set.ext_iff] at hst suffices x ∈ s by specialize hst x; simp_all refine hsc.mem_of_tendsto hux <| Eventually.of_forall fun k ↦ ?_ specialize hst (u k) simp_all /-- If each point of the space has a neighborhood from the family `S`, then the topology is generated by its restrictions to the sets of `S`. -/ lemma of_nhds (h : ∀ x, ∃ s ∈ S, s ∈ 𝓝 x) : IsCoherentWith S := of_continuous_prop fun _f hf ↦ continuous_iff_continuousAt.2 fun x ↦ let ⟨s, hsS, hsx⟩ := h x (hf s hsS).continuousAt hsx end Topology.IsCoherentWith
.lake/packages/mathlib/Mathlib/Topology/Neighborhoods.lean
import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Topology.Closure /-! # Neighborhoods in topological spaces Each point `x` of `X` gets a neighborhood filter `𝓝 x`. ## Tags neighborhood -/ open Set Filter Topology universe u v variable {X : Type u} [TopologicalSpace X] {ι : Sort v} {α : Type*} {x : X} {s t : Set X} theorem nhds_def' (x : X) : 𝓝 x = ⨅ (s : Set X) (_ : IsOpen s) (_ : x ∈ s), 𝓟 s := by simp only [nhds_def, mem_setOf_eq, @and_comm (x ∈ _), iInf_and] /-- The open sets containing `x` are a basis for the neighborhood filter. See `nhds_basis_opens'` for a variant using open neighborhoods instead. -/ theorem nhds_basis_opens (x : X) : (𝓝 x).HasBasis (fun s : Set X => x ∈ s ∧ IsOpen s) fun s => s := by rw [nhds_def] exact hasBasis_biInf_principal (fun s ⟨has, hs⟩ t ⟨hat, ht⟩ => ⟨s ∩ t, ⟨⟨has, hat⟩, IsOpen.inter hs ht⟩, ⟨inter_subset_left, inter_subset_right⟩⟩) ⟨univ, ⟨mem_univ x, isOpen_univ⟩⟩ theorem nhds_basis_closeds (x : X) : (𝓝 x).HasBasis (fun s : Set X => x ∉ s ∧ IsClosed s) compl := ⟨fun t => (nhds_basis_opens x).mem_iff.trans <| compl_surjective.exists.trans <| by simp only [isOpen_compl_iff, mem_compl_iff]⟩ @[simp] theorem lift'_nhds_interior (x : X) : (𝓝 x).lift' interior = 𝓝 x := (nhds_basis_opens x).lift'_interior_eq_self fun _ ↦ And.right theorem Filter.HasBasis.nhds_interior {x : X} {p : ι → Prop} {s : ι → Set X} (h : (𝓝 x).HasBasis p s) : (𝓝 x).HasBasis p (interior <| s ·) := lift'_nhds_interior x ▸ h.lift'_interior /-- A filter lies below the neighborhood filter at `x` iff it contains every open set around `x`. -/ theorem le_nhds_iff {f} : f ≤ 𝓝 x ↔ ∀ s : Set X, x ∈ s → IsOpen s → s ∈ f := by simp [nhds_def] /-- To show a filter is above the neighborhood filter at `x`, it suffices to show that it is above the principal filter of some open set `s` containing `x`. -/ theorem nhds_le_of_le {f} (h : x ∈ s) (o : IsOpen s) (sf : 𝓟 s ≤ f) : 𝓝 x ≤ f := by rw [nhds_def]; exact iInf₂_le_of_le s ⟨h, o⟩ sf theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := (nhds_basis_opens x).mem_iff.trans <| exists_congr fun _ => ⟨fun h => ⟨h.2, h.1.2, h.1.1⟩, fun h => ⟨⟨h.2.2, h.2.1⟩, h.1⟩⟩ /-- A predicate is true in a neighborhood of `x` iff it is true for all the points in an open set containing `x`. -/ theorem eventually_nhds_iff {p : X → Prop} : (∀ᶠ y in 𝓝 x, p y) ↔ ∃ t : Set X, (∀ y ∈ t, p y) ∧ IsOpen t ∧ x ∈ t := mem_nhds_iff.trans <| by simp only [subset_def, mem_setOf_eq] theorem frequently_nhds_iff {p : X → Prop} : (∃ᶠ y in 𝓝 x, p y) ↔ ∀ U : Set X, x ∈ U → IsOpen U → ∃ y ∈ U, p y := (nhds_basis_opens x).frequently_iff.trans <| by simp theorem mem_interior_iff_mem_nhds : x ∈ interior s ↔ s ∈ 𝓝 x := mem_interior.trans mem_nhds_iff.symm theorem map_nhds {f : X → α} : map f (𝓝 x) = ⨅ s ∈ { s : Set X | x ∈ s ∧ IsOpen s }, 𝓟 (f '' s) := ((nhds_basis_opens x).map f).eq_biInf theorem mem_of_mem_nhds : s ∈ 𝓝 x → x ∈ s := fun H => let ⟨_t, ht, _, hs⟩ := mem_nhds_iff.1 H; ht hs /-- If a predicate is true in a neighborhood of `x`, then it is true for `x`. -/ theorem Filter.Eventually.self_of_nhds {p : X → Prop} (h : ∀ᶠ y in 𝓝 x, p y) : p x := mem_of_mem_nhds h theorem IsOpen.mem_nhds (hs : IsOpen s) (hx : x ∈ s) : s ∈ 𝓝 x := mem_nhds_iff.2 ⟨s, Subset.refl _, hs, hx⟩ protected theorem IsOpen.mem_nhds_iff (hs : IsOpen s) : s ∈ 𝓝 x ↔ x ∈ s := ⟨mem_of_mem_nhds, fun hx => mem_nhds_iff.2 ⟨s, Subset.rfl, hs, hx⟩⟩ theorem IsClosed.compl_mem_nhds (hs : IsClosed s) (hx : x ∉ s) : sᶜ ∈ 𝓝 x := hs.isOpen_compl.mem_nhds (mem_compl hx) theorem IsOpen.eventually_mem (hs : IsOpen s) (hx : x ∈ s) : ∀ᶠ x in 𝓝 x, x ∈ s := IsOpen.mem_nhds hs hx /-- The open neighborhoods of `x` are a basis for the neighborhood filter. See `nhds_basis_opens` for a variant using open sets around `x` instead. -/ theorem nhds_basis_opens' (x : X) : (𝓝 x).HasBasis (fun s : Set X => s ∈ 𝓝 x ∧ IsOpen s) fun x => x := by convert nhds_basis_opens x using 2 exact and_congr_left_iff.2 IsOpen.mem_nhds_iff /-- If `U` is a neighborhood of each point of a set `s` then it is a neighborhood of `s`: it contains an open set containing `s`. -/ theorem exists_open_set_nhds {U : Set X} (h : ∀ x ∈ s, U ∈ 𝓝 x) : ∃ V : Set X, s ⊆ V ∧ IsOpen V ∧ V ⊆ U := ⟨interior U, fun x hx => mem_interior_iff_mem_nhds.2 <| h x hx, isOpen_interior, interior_subset⟩ /-- If `U` is a neighborhood of each point of a set `s` then it is a neighborhood of s: it contains an open set containing `s`. -/ theorem exists_open_set_nhds' {U : Set X} (h : U ∈ ⨆ x ∈ s, 𝓝 x) : ∃ V : Set X, s ⊆ V ∧ IsOpen V ∧ V ⊆ U := exists_open_set_nhds (by simpa using h) /-- If a predicate is true in a neighbourhood of `x`, then for `y` sufficiently close to `x` this predicate is true in a neighbourhood of `y`. -/ theorem Filter.Eventually.eventually_nhds {p : X → Prop} (h : ∀ᶠ y in 𝓝 x, p y) : ∀ᶠ y in 𝓝 x, ∀ᶠ x in 𝓝 y, p x := let ⟨t, htp, hto, ha⟩ := eventually_nhds_iff.1 h eventually_nhds_iff.2 ⟨t, fun _x hx => eventually_nhds_iff.2 ⟨t, htp, hto, hx⟩, hto, ha⟩ @[simp] theorem eventually_eventually_nhds {p : X → Prop} : (∀ᶠ y in 𝓝 x, ∀ᶠ x in 𝓝 y, p x) ↔ ∀ᶠ x in 𝓝 x, p x := ⟨fun h => h.self_of_nhds, fun h => h.eventually_nhds⟩ @[simp] theorem frequently_frequently_nhds {p : X → Prop} : (∃ᶠ x' in 𝓝 x, ∃ᶠ x'' in 𝓝 x', p x'') ↔ ∃ᶠ x in 𝓝 x, p x := by rw [← not_iff_not] simp only [not_frequently, eventually_eventually_nhds] @[simp] theorem eventually_mem_nhds_iff : (∀ᶠ x' in 𝓝 x, s ∈ 𝓝 x') ↔ s ∈ 𝓝 x := eventually_eventually_nhds @[simp] theorem nhds_bind_nhds : (𝓝 x).bind 𝓝 = 𝓝 x := Filter.ext fun _ => eventually_eventually_nhds @[simp] theorem eventually_eventuallyEq_nhds {f g : X → α} : (∀ᶠ y in 𝓝 x, f =ᶠ[𝓝 y] g) ↔ f =ᶠ[𝓝 x] g := eventually_eventually_nhds theorem Filter.EventuallyEq.eq_of_nhds {f g : X → α} (h : f =ᶠ[𝓝 x] g) : f x = g x := h.self_of_nhds @[simp] theorem eventually_eventuallyLE_nhds [LE α] {f g : X → α} : (∀ᶠ y in 𝓝 x, f ≤ᶠ[𝓝 y] g) ↔ f ≤ᶠ[𝓝 x] g := eventually_eventually_nhds /-- If two functions are equal in a neighbourhood of `x`, then for `y` sufficiently close to `x` these functions are equal in a neighbourhood of `y`. -/ theorem Filter.EventuallyEq.eventuallyEq_nhds {f g : X → α} (h : f =ᶠ[𝓝 x] g) : ∀ᶠ y in 𝓝 x, f =ᶠ[𝓝 y] g := h.eventually_nhds /-- If `f x ≤ g x` in a neighbourhood of `x`, then for `y` sufficiently close to `x` we have `f x ≤ g x` in a neighbourhood of `y`. -/ theorem Filter.EventuallyLE.eventuallyLE_nhds [LE α] {f g : X → α} (h : f ≤ᶠ[𝓝 x] g) : ∀ᶠ y in 𝓝 x, f ≤ᶠ[𝓝 y] g := h.eventually_nhds theorem all_mem_nhds (x : X) (P : Set X → Prop) (hP : ∀ s t, s ⊆ t → P s → P t) : (∀ s ∈ 𝓝 x, P s) ↔ ∀ s, IsOpen s → x ∈ s → P s := ((nhds_basis_opens x).forall_iff hP).trans <| by simp only [@and_comm (x ∈ _), and_imp] theorem all_mem_nhds_filter (x : X) (f : Set X → Set α) (hf : ∀ s t, s ⊆ t → f s ⊆ f t) (l : Filter α) : (∀ s ∈ 𝓝 x, f s ∈ l) ↔ ∀ s, IsOpen s → x ∈ s → f s ∈ l := all_mem_nhds _ _ fun s t ssubt h => mem_of_superset h (hf s t ssubt) theorem tendsto_nhds {f : α → X} {l : Filter α} : Tendsto f l (𝓝 x) ↔ ∀ s, IsOpen s → x ∈ s → f ⁻¹' s ∈ l := all_mem_nhds_filter _ _ (fun _ _ h => preimage_mono h) _ theorem tendsto_atTop_nhds [Nonempty α] [SemilatticeSup α] {f : α → X} : Tendsto f atTop (𝓝 x) ↔ ∀ U : Set X, x ∈ U → IsOpen U → ∃ N, ∀ n, N ≤ n → f n ∈ U := (atTop_basis.tendsto_iff (nhds_basis_opens x)).trans <| by simp only [and_imp, true_and, mem_Ici] theorem tendsto_const_nhds {f : Filter α} : Tendsto (fun _ : α => x) f (𝓝 x) := tendsto_nhds.mpr fun _ _ ha => univ_mem' fun _ => ha theorem tendsto_atTop_of_eventually_const {ι : Type*} [Preorder ι] {u : ι → X} {i₀ : ι} (h : ∀ i ≥ i₀, u i = x) : Tendsto u atTop (𝓝 x) := Tendsto.congr' (EventuallyEq.symm ((eventually_ge_atTop i₀).mono h)) tendsto_const_nhds theorem tendsto_atBot_of_eventually_const {ι : Type*} [Preorder ι] {u : ι → X} {i₀ : ι} (h : ∀ i ≤ i₀, u i = x) : Tendsto u atBot (𝓝 x) := tendsto_atTop_of_eventually_const (ι := ιᵒᵈ) h theorem pure_le_nhds : pure ≤ (𝓝 : X → Filter X) := fun _ _ hs => mem_pure.2 <| mem_of_mem_nhds hs theorem tendsto_pure_nhds (f : α → X) (a : α) : Tendsto f (pure a) (𝓝 (f a)) := (tendsto_pure_pure f a).mono_right (pure_le_nhds _) theorem OrderTop.tendsto_atTop_nhds [PartialOrder α] [OrderTop α] (f : α → X) : Tendsto f atTop (𝓝 (f ⊤)) := (tendsto_atTop_pure f).mono_right (pure_le_nhds _) @[simp] instance nhds_neBot : NeBot (𝓝 x) := neBot_of_le (pure_le_nhds x) theorem tendsto_nhds_of_eventually_eq {l : Filter α} {f : α → X} (h : ∀ᶠ x' in l, f x' = x) : Tendsto f l (𝓝 x) := tendsto_const_nhds.congr' (.symm h) theorem Filter.EventuallyEq.tendsto {l : Filter α} {f : α → X} (hf : f =ᶠ[l] fun _ ↦ x) : Tendsto f l (𝓝 x) := tendsto_nhds_of_eventually_eq hf /-! ### Interior, closure and frontier in terms of neighborhoods -/ theorem interior_eq_nhds' : interior s = { x | s ∈ 𝓝 x } := Set.ext fun x => by simp only [mem_interior, mem_nhds_iff, mem_setOf_eq] theorem interior_eq_nhds : interior s = { x | 𝓝 x ≤ 𝓟 s } := interior_eq_nhds'.trans <| by simp only [le_principal_iff] @[simp] theorem interior_mem_nhds : interior s ∈ 𝓝 x ↔ s ∈ 𝓝 x := ⟨fun h => mem_of_superset h interior_subset, fun h => IsOpen.mem_nhds isOpen_interior (mem_interior_iff_mem_nhds.2 h)⟩ theorem interior_setOf_eq {p : X → Prop} : interior { x | p x } = { x | ∀ᶠ y in 𝓝 x, p y } := interior_eq_nhds' theorem isOpen_setOf_eventually_nhds {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝 x, p y } := by simp only [← interior_setOf_eq, isOpen_interior] theorem subset_interior_iff_nhds {V : Set X} : s ⊆ interior V ↔ ∀ x ∈ s, V ∈ 𝓝 x := by simp_rw [subset_def, mem_interior_iff_mem_nhds] theorem isOpen_iff_nhds : IsOpen s ↔ ∀ x ∈ s, 𝓝 x ≤ 𝓟 s := calc IsOpen s ↔ s ⊆ interior s := subset_interior_iff_isOpen.symm _ ↔ ∀ x ∈ s, 𝓝 x ≤ 𝓟 s := by simp_rw [interior_eq_nhds, subset_def, mem_setOf] theorem TopologicalSpace.ext_iff_nhds {X} {t t' : TopologicalSpace X} : t = t' ↔ ∀ x, @nhds _ t x = @nhds _ t' x := ⟨fun H _ ↦ congrFun (congrArg _ H) _, fun H ↦ by ext; simp_rw [@isOpen_iff_nhds _ _ _, H]⟩ alias ⟨_, TopologicalSpace.ext_nhds⟩ := TopologicalSpace.ext_iff_nhds theorem isOpen_iff_mem_nhds : IsOpen s ↔ ∀ x ∈ s, s ∈ 𝓝 x := isOpen_iff_nhds.trans <| forall_congr' fun _ => imp_congr_right fun _ => le_principal_iff /-- A set `s` is open iff for every point `x` in `s` and every `y` close to `x`, `y` is in `s`. -/ theorem isOpen_iff_eventually : IsOpen s ↔ ∀ x, x ∈ s → ∀ᶠ y in 𝓝 x, y ∈ s := isOpen_iff_mem_nhds theorem isOpen_singleton_iff_nhds_eq_pure (x : X) : IsOpen ({x} : Set X) ↔ 𝓝 x = pure x := by simp [← (pure_le_nhds _).ge_iff_eq', isOpen_iff_mem_nhds] theorem isOpen_singleton_iff_punctured_nhds (x : X) : IsOpen ({x} : Set X) ↔ 𝓝[≠] x = ⊥ := by rw [isOpen_singleton_iff_nhds_eq_pure, nhdsWithin, ← mem_iff_inf_principal_compl, le_antisymm_iff] simp [pure_le_nhds x] theorem mem_closure_iff_frequently : x ∈ closure s ↔ ∃ᶠ x in 𝓝 x, x ∈ s := by rw [Filter.Frequently, Filter.Eventually, ← mem_interior_iff_mem_nhds, closure_eq_compl_interior_compl, mem_compl_iff, compl_def] alias ⟨_, Filter.Frequently.mem_closure⟩ := mem_closure_iff_frequently /-- A set `s` is closed iff for every point `x`, if there is a point `y` close to `x` that belongs to `s` then `x` is in `s`. -/ theorem isClosed_iff_frequently : IsClosed s ↔ ∀ x, (∃ᶠ y in 𝓝 x, y ∈ s) → x ∈ s := by rw [← closure_subset_iff_isClosed] refine forall_congr' fun x => ?_ rw [mem_closure_iff_frequently] lemma nhdsWithin_neBot : (𝓝[s] x).NeBot ↔ ∀ ⦃t⦄, t ∈ 𝓝 x → (t ∩ s).Nonempty := by rw [nhdsWithin, inf_neBot_iff] exact forall₂_congr fun U _ ↦ ⟨fun h ↦ h (mem_principal_self _), fun h u hsu ↦ h.mono <| inter_subset_inter_right _ hsu⟩ @[gcongr] theorem nhdsWithin_mono (x : X) {s t : Set X} (h : s ⊆ t) : 𝓝[s] x ≤ 𝓝[t] x := inf_le_inf_left _ (principal_mono.mpr h) theorem IsClosed.interior_union_left (_ : IsClosed s) : interior (s ∪ t) ⊆ s ∪ interior t := fun a ⟨u, ⟨⟨hu₁, hu₂⟩, ha⟩⟩ => (Classical.em (a ∈ s)).imp_right fun h => mem_interior.mpr ⟨u ∩ sᶜ, fun _x hx => (hu₂ hx.1).resolve_left hx.2, IsOpen.inter hu₁ IsClosed.isOpen_compl, ⟨ha, h⟩⟩ theorem IsClosed.interior_union_right (h : IsClosed t) : interior (s ∪ t) ⊆ interior s ∪ t := by simpa only [union_comm _ t] using h.interior_union_left theorem IsOpen.inter_closure (h : IsOpen s) : s ∩ closure t ⊆ closure (s ∩ t) := compl_subset_compl.mp <| by simpa only [← interior_compl, compl_inter] using IsClosed.interior_union_left h.isClosed_compl theorem IsOpen.closure_inter (h : IsOpen t) : closure s ∩ t ⊆ closure (s ∩ t) := by simpa only [inter_comm t] using h.inter_closure theorem Dense.open_subset_closure_inter (hs : Dense s) (ht : IsOpen t) : t ⊆ closure (t ∩ s) := calc t = t ∩ closure s := by rw [hs.closure_eq, inter_univ] _ ⊆ closure (t ∩ s) := ht.inter_closure /-- The intersection of an open dense set with a dense set is a dense set. -/ theorem Dense.inter_of_isOpen_left (hs : Dense s) (ht : Dense t) (hso : IsOpen s) : Dense (s ∩ t) := fun x => closure_minimal hso.inter_closure isClosed_closure <| by simp [hs.closure_eq, ht.closure_eq] /-- The intersection of a dense set with an open dense set is a dense set. -/ theorem Dense.inter_of_isOpen_right (hs : Dense s) (ht : Dense t) (hto : IsOpen t) : Dense (s ∩ t) := inter_comm t s ▸ ht.inter_of_isOpen_left hs hto theorem Dense.inter_nhds_nonempty (hs : Dense s) (ht : t ∈ 𝓝 x) : (s ∩ t).Nonempty := let ⟨U, hsub, ho, hx⟩ := mem_nhds_iff.1 ht (hs.inter_open_nonempty U ho ⟨x, hx⟩).mono fun _y hy => ⟨hy.2, hsub hy.1⟩ theorem closure_diff : closure s \ closure t ⊆ closure (s \ t) := calc closure s \ closure t = (closure t)ᶜ ∩ closure s := by simp only [diff_eq, inter_comm] _ ⊆ closure ((closure t)ᶜ ∩ s) := (isOpen_compl_iff.mpr <| isClosed_closure).inter_closure _ = closure (s \ closure t) := by simp only [diff_eq, inter_comm] _ ⊆ closure (s \ t) := closure_mono <| diff_subset_diff (Subset.refl s) subset_closure theorem Filter.Frequently.mem_of_closed (h : ∃ᶠ x in 𝓝 x, x ∈ s) (hs : IsClosed s) : x ∈ s := hs.closure_subset h.mem_closure theorem IsClosed.mem_of_frequently_of_tendsto {f : α → X} {b : Filter α} (hs : IsClosed s) (h : ∃ᶠ x in b, f x ∈ s) (hf : Tendsto f b (𝓝 x)) : x ∈ s := (hf.frequently <| show ∃ᶠ x in b, (fun y => y ∈ s) (f x) from h).mem_of_closed hs theorem IsClosed.mem_of_tendsto {f : α → X} {b : Filter α} [NeBot b] (hs : IsClosed s) (hf : Tendsto f b (𝓝 x)) (h : ∀ᶠ x in b, f x ∈ s) : x ∈ s := hs.mem_of_frequently_of_tendsto h.frequently hf theorem mem_closure_of_frequently_of_tendsto {f : α → X} {b : Filter α} (h : ∃ᶠ x in b, f x ∈ s) (hf : Tendsto f b (𝓝 x)) : x ∈ closure s := (hf.frequently h).mem_closure theorem mem_closure_of_tendsto {f : α → X} {b : Filter α} [NeBot b] (hf : Tendsto f b (𝓝 x)) (h : ∀ᶠ x in b, f x ∈ s) : x ∈ closure s := mem_closure_of_frequently_of_tendsto h.frequently hf /-- Suppose that `f` sends the complement to `s` to a single point `x`, and `l` is some filter. Then `f` tends to `x` along `l` restricted to `s` if and only if it tends to `x` along `l`. -/ theorem tendsto_inf_principal_nhds_iff_of_forall_eq {f : α → X} {l : Filter α} {s : Set α} (h : ∀ a ∉ s, f a = x) : Tendsto f (l ⊓ 𝓟 s) (𝓝 x) ↔ Tendsto f l (𝓝 x) := by rw [tendsto_iff_comap, tendsto_iff_comap] replace h : 𝓟 sᶜ ≤ comap f (𝓝 x) := by rintro U ⟨t, ht, htU⟩ x hx have : f x ∈ t := (h x hx).symm ▸ mem_of_mem_nhds ht exact htU this refine ⟨fun h' => ?_, le_trans inf_le_left⟩ have := sup_le h' h rw [sup_inf_right, sup_principal, union_compl_self, principal_univ, inf_top_eq, sup_le_iff] at this exact this.1
.lake/packages/mathlib/Mathlib/Topology/Basic.lean
import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Set.Finite.Range import Mathlib.Data.Set.Lattice import Mathlib.Topology.Defs.Filter /-! # Openness and closedness of a set This file provides lemmas relating to the predicates `IsOpen` and `IsClosed` of a set endowed with a topology. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space -/ open Set Filter Topology universe u v /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy section TopologicalSpace variable {X : Type u} {ι : Sort v} {α : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl @[ext (iff := false)] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) (h : ∀ t ∈ s, IsOpen t) : IsOpen (⋂₀ s) := by induction s, hs using Set.Finite.induction_on with | empty => rw [sInter_empty]; exact isOpen_univ | insert _ _ ih => simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h @[simp] theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ theorem TopologicalSpace.ext_iff_isClosed {X} {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const lemma IsOpen.isLocallyClosed (hs : IsOpen s) : IsLocallyClosed s := ⟨_, _, hs, isClosed_univ, (inter_univ _).symm⟩ lemma IsClosed.isLocallyClosed (hs : IsClosed s) : IsLocallyClosed s := ⟨_, _, isOpen_univ, hs, (univ_inter _).symm⟩ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) := isClosed_sInter <| forall_mem_range.2 h theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋂ i ∈ s, f i) := isClosed_iInter fun i => isClosed_iInter <| h i @[simp] theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by rw [← isOpen_compl_iff, compl_compl] alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) := IsOpen.inter h₁ h₂.isOpen_compl theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by rw [← isOpen_compl_iff] at * rw [compl_inter] exact IsOpen.union h₁ h₂ theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) := IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂) theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact hs.isOpen_biInter h lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := s.finite_toSet.isClosed_biUnion h theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) : IsClosed (⋃ i, s i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact isOpen_iInter_of_finite h theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) : IsClosed { x | p x → q x } := by simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } := isOpen_compl_iff.mpr theorem IsClosed.and : IsClosed { x | p₁ x } → IsClosed { x | p₂ x } → IsClosed { x | p₁ x ∧ p₂ x } := IsClosed.inter /-! ### Limits of filters in topological spaces In this section we define functions that return a limit of a filter (or of a function along a filter), if it exists, and a random point otherwise. These functions are rarely used in Mathlib, most of the theorems are written using `Filter.Tendsto`. One of the reasons is that `Filter.limUnder f g = x` is not equivalent to `Filter.Tendsto g f (𝓝 x)` unless the codomain is a Hausdorff space and `g` has a limit along `f`. -/ section lim /-- If a filter `f` is majorated by some `𝓝 x`, then it is majorated by `𝓝 (Filter.lim f)`. We formulate this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for types without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify this instance with any other instance. -/ theorem le_nhds_lim {f : Filter X} (h : ∃ x, f ≤ 𝓝 x) : f ≤ 𝓝 (@lim _ _ h.nonempty f) := Classical.epsilon_spec h /-- If `g` tends to some `𝓝 x` along `f`, then it tends to `𝓝 (Filter.limUnder f g)`. We formulate this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for types without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify this instance with any other instance. -/ theorem tendsto_nhds_limUnder {f : Filter α} {g : α → X} (h : ∃ x, Tendsto g f (𝓝 x)) : Tendsto g f (𝓝 (@limUnder _ _ _ h.nonempty f g)) := le_nhds_lim h theorem limUnder_of_not_tendsto [hX : Nonempty X] {f : Filter α} {g : α → X} (h : ¬ ∃ x, Tendsto g f (𝓝 x)) : limUnder f g = Classical.choice hX := by simp_rw [Tendsto] at h simp_rw [limUnder, lim, Classical.epsilon, Classical.strongIndefiniteDescription, dif_neg h] end lim end TopologicalSpace
.lake/packages/mathlib/Mathlib/Topology/AlexandrovDiscrete.lean
import Mathlib.Data.Set.Image import Mathlib.Topology.Bases import Mathlib.Topology.Inseparable import Mathlib.Topology.Compactness.NhdsKer /-! # Alexandrov-discrete topological spaces This file defines Alexandrov-discrete spaces, aka finitely generated spaces. A space is Alexandrov-discrete if the (arbitrary) intersection of open sets is open. As such, the intersection of all neighborhoods of a set is a neighborhood itself. Hence every set has a minimal neighborhood, which we call the *neighborhoods kernel* of the set. ## Main declarations * `AlexandrovDiscrete`: Prop-valued typeclass for a topological space to be Alexandrov-discrete ## Tags Alexandroff, discrete, finitely generated, fg space -/ open Filter Set TopologicalSpace Topology /-- A topological space is **Alexandrov-discrete** or **finitely generated** if the intersection of a family of open sets is open. -/ @[mk_iff] class AlexandrovDiscrete (α : Type*) [TopologicalSpace α] : Prop where /-- The intersection of a family of open sets is an open set. Use `isOpen_sInter` in the root namespace instead. -/ protected isOpen_sInter : ∀ S : Set (Set α), (∀ s ∈ S, IsOpen s) → IsOpen (⋂₀ S) variable {ι : Sort*} {κ : ι → Sort*} {α β : Type*} section variable [TopologicalSpace α] [TopologicalSpace β] lemma alexandrovDiscrete_iff_isClosed : AlexandrovDiscrete α ↔ ∀ S : Set (Set α), (∀ s ∈ S, IsClosed s) → IsClosed (⋃₀ S) := by conv_lhs => tactic => simp_rw +singlePass [alexandrovDiscrete_iff, compl_surjective.image_surjective.forall, forall_mem_image, ← compl_sUnion, isOpen_compl_iff] instance DiscreteTopology.toAlexandrovDiscrete [DiscreteTopology α] : AlexandrovDiscrete α where isOpen_sInter _ _ := isOpen_discrete _ instance Finite.toAlexandrovDiscrete [Finite α] : AlexandrovDiscrete α where isOpen_sInter S := (toFinite S).isOpen_sInter section AlexandrovDiscrete variable [AlexandrovDiscrete α] {S : Set (Set α)} {f : ι → Set α} lemma isOpen_sInter : (∀ s ∈ S, IsOpen s) → IsOpen (⋂₀ S) := AlexandrovDiscrete.isOpen_sInter _ lemma isOpen_iInter (hf : ∀ i, IsOpen (f i)) : IsOpen (⋂ i, f i) := isOpen_sInter <| forall_mem_range.2 hf lemma isOpen_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsOpen (f i j)) : IsOpen (⋂ i, ⋂ j, f i j) := isOpen_iInter fun _ ↦ isOpen_iInter <| hf _ lemma isClosed_sUnion (hS : ∀ s ∈ S, IsClosed s) : IsClosed (⋃₀ S) := alexandrovDiscrete_iff_isClosed.mp inferInstance S hS lemma isClosed_iUnion (hf : ∀ i, IsClosed (f i)) : IsClosed (⋃ i, f i) := isClosed_sUnion <| forall_mem_range.2 hf lemma isClosed_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsClosed (f i j)) : IsClosed (⋃ i, ⋃ j, f i j) := isClosed_iUnion fun _ ↦ isClosed_iUnion <| hf _ lemma isClopen_sInter (hS : ∀ s ∈ S, IsClopen s) : IsClopen (⋂₀ S) := ⟨isClosed_sInter fun s hs ↦ (hS s hs).1, isOpen_sInter fun s hs ↦ (hS s hs).2⟩ lemma isClopen_iInter (hf : ∀ i, IsClopen (f i)) : IsClopen (⋂ i, f i) := ⟨isClosed_iInter fun i ↦ (hf i).1, isOpen_iInter fun i ↦ (hf i).2⟩ lemma isClopen_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsClopen (f i j)) : IsClopen (⋂ i, ⋂ j, f i j) := isClopen_iInter fun _ ↦ isClopen_iInter <| hf _ lemma isClopen_sUnion (hS : ∀ s ∈ S, IsClopen s) : IsClopen (⋃₀ S) := ⟨isClosed_sUnion fun s hs ↦ (hS s hs).1, isOpen_sUnion fun s hs ↦ (hS s hs).2⟩ lemma isClopen_iUnion (hf : ∀ i, IsClopen (f i)) : IsClopen (⋃ i, f i) := ⟨isClosed_iUnion fun i ↦ (hf i).1, isOpen_iUnion fun i ↦ (hf i).2⟩ lemma isClopen_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsClopen (f i j)) : IsClopen (⋃ i, ⋃ j, f i j) := isClopen_iUnion fun _ ↦ isClopen_iUnion <| hf _ lemma interior_iInter (f : ι → Set α) : interior (⋂ i, f i) = ⋂ i, interior (f i) := (interior_maximal (iInter_mono fun _ ↦ interior_subset) <| isOpen_iInter fun _ ↦ isOpen_interior).antisymm' <| subset_iInter fun _ ↦ interior_mono <| iInter_subset _ _ lemma interior_sInter (S : Set (Set α)) : interior (⋂₀ S) = ⋂ s ∈ S, interior s := by simp_rw [sInter_eq_biInter, interior_iInter] lemma closure_iUnion (f : ι → Set α) : closure (⋃ i, f i) = ⋃ i, closure (f i) := compl_injective <| by simpa only [← interior_compl, compl_iUnion] using interior_iInter fun i ↦ (f i)ᶜ lemma closure_sUnion (S : Set (Set α)) : closure (⋃₀ S) = ⋃ s ∈ S, closure s := by simp_rw [sUnion_eq_biUnion, closure_iUnion] end AlexandrovDiscrete lemma Topology.IsInducing.alexandrovDiscrete [AlexandrovDiscrete α] {f : β → α} (h : IsInducing f) : AlexandrovDiscrete β where isOpen_sInter S hS := by simp_rw [h.isOpen_iff] at hS ⊢ choose U hU htU using hS refine ⟨_, isOpen_iInter₂ hU, ?_⟩ simp_rw [preimage_iInter, htU, sInter_eq_biInter] end lemma AlexandrovDiscrete.sup {t₁ t₂ : TopologicalSpace α} (_ : @AlexandrovDiscrete α t₁) (_ : @AlexandrovDiscrete α t₂) : @AlexandrovDiscrete α (t₁ ⊔ t₂) := @AlexandrovDiscrete.mk α (t₁ ⊔ t₂) fun _S hS ↦ ⟨@isOpen_sInter _ t₁ _ _ fun _s hs ↦ (hS _ hs).1, isOpen_sInter fun _s hs ↦ (hS _ hs).2⟩ lemma alexandrovDiscrete_iSup {t : ι → TopologicalSpace α} (_ : ∀ i, @AlexandrovDiscrete α (t i)) : @AlexandrovDiscrete α (⨆ i, t i) := @AlexandrovDiscrete.mk α (⨆ i, t i) fun _S hS ↦ isOpen_iSup_iff.2 fun i ↦ @isOpen_sInter _ (t i) _ _ fun _s hs ↦ isOpen_iSup_iff.1 (hS _ hs) _ section variable [TopologicalSpace α] [TopologicalSpace β] [AlexandrovDiscrete α] [AlexandrovDiscrete β] {s t : Set α} {a : α} @[simp] lemma isOpen_nhdsKer : IsOpen (nhdsKer s) := by rw [nhdsKer_def]; exact isOpen_sInter fun _ ↦ And.left @[deprecated (since := "2025-07-09")] alias isOpen_exterior := isOpen_nhdsKer lemma nhdsKer_mem_nhdsSet : nhdsKer s ∈ 𝓝ˢ s := isOpen_nhdsKer.mem_nhdsSet.2 subset_nhdsKer @[deprecated (since := "2025-07-09")] alias exterior_mem_nhdsSet := nhdsKer_mem_nhdsSet @[simp] lemma nhdsKer_eq_iff_isOpen : nhdsKer s = s ↔ IsOpen s := ⟨fun h ↦ h ▸ isOpen_nhdsKer, IsOpen.nhdsKer_eq⟩ @[deprecated (since := "2025-07-09")] alias exterior_eq_iff_isOpen := nhdsKer_eq_iff_isOpen @[simp] lemma nhdsKer_subset_iff_isOpen : nhdsKer s ⊆ s ↔ IsOpen s := by simp only [nhdsKer_eq_iff_isOpen.symm, Subset.antisymm_iff, subset_nhdsKer, and_true] @[deprecated (since := "2025-07-09")] alias exterior_subset_iff_isOpen := nhdsKer_subset_iff_isOpen lemma nhdsKer_subset_iff : nhdsKer s ⊆ t ↔ ∃ U, IsOpen U ∧ s ⊆ U ∧ U ⊆ t := ⟨fun h ↦ ⟨nhdsKer s, isOpen_nhdsKer, subset_nhdsKer, h⟩, fun ⟨_U, hU, hsU, hUt⟩ ↦ (nhdsKer_minimal hsU hU).trans hUt⟩ @[deprecated (since := "2025-07-09")] alias exterior_subset_iff := nhdsKer_subset_iff lemma nhdsKer_subset_iff_mem_nhdsSet : nhdsKer s ⊆ t ↔ t ∈ 𝓝ˢ s := nhdsKer_subset_iff.trans mem_nhdsSet_iff_exists.symm @[deprecated (since := "2025-07-09")] alias exterior_subset_iff_mem_nhdsSet := nhdsKer_subset_iff_mem_nhdsSet lemma nhdsKer_singleton_subset_iff_mem_nhds : nhdsKer {a} ⊆ t ↔ t ∈ 𝓝 a := by simp [nhdsKer_subset_iff_mem_nhdsSet] @[deprecated (since := "2025-07-09")] alias exterior_singleton_subset_iff_mem_nhds := nhdsKer_singleton_subset_iff_mem_nhds lemma gc_nhdsKer_interior : GaloisConnection (nhdsKer : Set α → Set α) interior := fun s t ↦ by simp [nhdsKer_subset_iff, subset_interior_iff] @[deprecated (since := "2025-07-09")] alias gc_exterior_interior := gc_nhdsKer_interior @[simp] lemma principal_nhdsKer (s : Set α) : 𝓟 (nhdsKer s) = 𝓝ˢ s := by rw [← nhdsSet_nhdsKer, isOpen_nhdsKer.nhdsSet_eq] @[deprecated (since := "2025-07-09")] alias principal_exterior := principal_nhdsKer lemma principal_nhdsKer_singleton (a : α) : 𝓟 (nhdsKer {a}) = 𝓝 a := by rw [principal_nhdsKer, nhdsSet_singleton] lemma nhdsSet_basis_nhdsKer (s : Set α) : (𝓝ˢ s).HasBasis (fun _ : Unit => True) (fun _ => nhdsKer s) := principal_nhdsKer s ▸ hasBasis_principal (nhdsKer s) lemma nhds_basis_nhdsKer_singleton (a : α) : (𝓝 a).HasBasis (fun _ : Unit => True) (fun _ => nhdsKer {a}) := principal_nhdsKer_singleton a ▸ hasBasis_principal (nhdsKer {a}) lemma isOpen_iff_forall_specializes : IsOpen s ↔ ∀ x y, x ⤳ y → y ∈ s → x ∈ s := by simp only [← nhdsKer_subset_iff_isOpen, Set.subset_def, mem_nhdsKer_iff_specializes, exists_imp, and_imp, @forall_swap (_ ⤳ _)] omit [AlexandrovDiscrete α] in lemma alexandrovDiscrete_iff_nhds : AlexandrovDiscrete α ↔ (∀ a : α, 𝓝 a = 𝓟 (nhdsKer {a})) where mp _ a := principal_nhdsKer_singleton a |>.symm mpr hα := by simp only [alexandrovDiscrete_iff_isClosed, isClosed_iff_clusterPt, ClusterPt, funext hα, inf_principal, principal_neBot_iff] intro S hS a ha rw [sUnion_eq_biUnion, inter_iUnion₂, nonempty_biUnion] at ha obtain ⟨s, hs, has⟩ := ha specialize hS s hs a has exact mem_sUnion_of_mem hS hs lemma alexandrovDiscrete_coinduced {β : Type*} {f : α → β} : @AlexandrovDiscrete β (coinduced f ‹_›) := @AlexandrovDiscrete.mk β (coinduced f ‹_›) fun S hS ↦ by rw [isOpen_coinduced, preimage_sInter]; exact isOpen_iInter₂ hS instance AlexandrovDiscrete.toFirstCountable : FirstCountableTopology α where nhds_generated_countable a := ⟨{nhdsKer {a}}, countable_singleton _, by simp⟩ instance AlexandrovDiscrete.toLocallyCompactSpace : LocallyCompactSpace α where local_compact_nhds a _U hU := ⟨nhdsKer {a}, isOpen_nhdsKer.mem_nhds <| subset_nhdsKer <| mem_singleton _, nhdsKer_singleton_subset_iff_mem_nhds.2 hU, isCompact_singleton.nhdsKer⟩ instance Subtype.instAlexandrovDiscrete {p : α → Prop} : AlexandrovDiscrete {a // p a} := IsInducing.subtypeVal.alexandrovDiscrete instance Quotient.instAlexandrovDiscrete {s : Setoid α} : AlexandrovDiscrete (Quotient s) := alexandrovDiscrete_coinduced instance Sum.instAlexandrovDiscrete : AlexandrovDiscrete (α ⊕ β) := alexandrovDiscrete_coinduced.sup alexandrovDiscrete_coinduced instance Sigma.instAlexandrovDiscrete {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, AlexandrovDiscrete (X i)] : AlexandrovDiscrete (Σ i, X i) := alexandrovDiscrete_iSup fun _ ↦ alexandrovDiscrete_coinduced instance Prod.instAlexandrovDiscrete : AlexandrovDiscrete (α × β) := by simp_rw [alexandrovDiscrete_iff_nhds, Prod.forall, nhds_prod_eq, ← principal_nhdsKer_singleton, prod_principal_principal, nhdsKer_pair, forall_true_iff] instance Pi.instAlexandrovDiscreteOfFinite {ι : Type*} [Finite ι] {X : ι → Type*} [Π i, TopologicalSpace (X i)] [∀ i, AlexandrovDiscrete (X i)] : AlexandrovDiscrete (Π i, X i) := by simp_rw [alexandrovDiscrete_iff_nhds, nhds_pi, ← principal_nhdsKer_singleton, pi_principal, nhdsKer_singleton_pi, forall_true_iff] end
.lake/packages/mathlib/Mathlib/Topology/Gluing.lean
import Mathlib.CategoryTheory.GlueData import Mathlib.Topology.Category.TopCat.Limits.Pullbacks import Mathlib.Topology.Category.TopCat.Opens import Mathlib.Tactic.Generalize import Mathlib.CategoryTheory.Elementwise import Mathlib.CategoryTheory.Limits.Types.Coequalizers import Mathlib.CategoryTheory.ConcreteCategory.EpiMono /-! # Gluing Topological spaces Given a family of gluing data (see `Mathlib/CategoryTheory/GlueData.lean`), we can then glue them together. The construction should be "sealed" and considered as a black box, while only using the API provided. ## Main definitions * `TopCat.GlueData`: A structure containing the family of gluing data. * `CategoryTheory.GlueData.glued`: The glued topological space. This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API can be used. * `CategoryTheory.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : ι`. * `TopCat.GlueData.Rel`: A relation on `Σ i, D.U i` defined by `⟨i, x⟩ ~ ⟨j, y⟩` iff `⟨i, x⟩ = ⟨j, y⟩` or `t i j x = y`. See `TopCat.GlueData.ι_eq_iff_rel`. * `TopCat.GlueData.mk`: A constructor of `GlueData` whose conditions are stated in terms of elements rather than subobjects and pullbacks. * `TopCat.GlueData.ofOpenSubsets`: Given a family of open sets, we may glue them into a new topological space. This new space embeds into the original space, and is homeomorphic to it if the given family is an open cover (`TopCat.GlueData.openCoverGlueHomeo`). ## Main results * `TopCat.GlueData.isOpen_iff`: A set in `glued` is open iff its preimage along each `ι i` is open. * `TopCat.GlueData.ι_jointly_surjective`: The `ι i`s are jointly surjective. * `TopCat.GlueData.rel_equiv`: `Rel` is an equivalence relation. * `TopCat.GlueData.ι_eq_iff_rel`: `ι i x = ι j y ↔ ⟨i, x⟩ ~ ⟨j, y⟩`. * `TopCat.GlueData.image_inter`: The intersection of the images of `U i` and `U j` in `glued` is `V i j`. * `TopCat.GlueData.preimage_range`: The preimage of the image of `U i` in `U j` is `V i j`. * `TopCat.GlueData.preimage_image_eq_image`: The preimage of the image of some `U ⊆ U i` is given by XXX. * `TopCat.GlueData.ι_isOpenEmbedding`: Each of the `ι i`s are open embeddings. -/ noncomputable section open CategoryTheory TopologicalSpace Topology universe v u open CategoryTheory.Limits namespace TopCat /-- A family of gluing data consists of 1. An index type `J` 2. An object `U i` for each `i : J`. 3. An object `V i j` for each `i j : J`. (Note that this is `J × J → TopCat` rather than `J → J → TopCat` to connect to the limits library easier.) 4. An open embedding `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. (This merely means that `V i j ∩ V i k ⊆ t i j ⁻¹' (V j i ∩ V j k)`.) 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the topological spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. Most of the times it would be easier to use the constructor `TopCat.GlueData.mk'` where the conditions are stated in a less categorical way. -/ structure GlueData extends CategoryTheory.GlueData TopCat where f_open : ∀ i j, IsOpenEmbedding (f i j) f_mono i j := (TopCat.mono_iff_injective _).mpr (f_open i j).isEmbedding.injective namespace GlueData variable (D : GlueData.{u}) local notation "𝖣" => D.toGlueData theorem π_surjective : Function.Surjective 𝖣.π := (TopCat.epi_iff_surjective 𝖣.π).mp inferInstance theorem isOpen_iff (U : Set 𝖣.glued) : IsOpen U ↔ ∀ i, IsOpen (𝖣.ι i ⁻¹' U) := by delta CategoryTheory.GlueData.ι simp_rw [← Multicoequalizer.ι_sigmaπ 𝖣.diagram] rw [← (homeoOfIso (Multicoequalizer.isoCoequalizer 𝖣.diagram).symm).isOpen_preimage] rw [coequalizer_isOpen_iff, colimit_isOpen_iff.{u}] tauto theorem ι_jointly_surjective (x : 𝖣.glued) : ∃ (i : _) (y : D.U i), 𝖣.ι i y = x := 𝖣.ι_jointly_surjective (forget TopCat) x /-- An equivalence relation on `Σ i, D.U i` that holds iff `𝖣.ι i x = 𝖣.ι j y`. See `TopCat.GlueData.ι_eq_iff_rel`. -/ def Rel (a b : Σ i, ((D.U i : TopCat) : Type _)) : Prop := ∃ x : D.V (a.1, b.1), D.f _ _ x = a.2 ∧ D.f _ _ (D.t _ _ x) = b.2 theorem rel_equiv : Equivalence D.Rel := ⟨fun x => ⟨inv (D.f _ _) x.2, IsIso.inv_hom_id_apply (D.f x.fst x.fst) _, -- Use `elementwise_of%` elaborator instead of `IsIso.inv_hom_id_apply` to work around -- `ConcreteCategory`/`HasForget` mismatch: by simp [elementwise_of% IsIso.inv_hom_id (D.f x.fst x.fst)]⟩, by rintro a b ⟨x, e₁, e₂⟩ exact ⟨D.t _ _ x, e₂, by rw [← e₁, D.t_inv_apply]⟩, by rintro ⟨i, a⟩ ⟨j, b⟩ ⟨k, c⟩ ⟨x, e₁, e₂⟩ rintro ⟨y, e₃, e₄⟩ let z := (pullbackIsoProdSubtype (D.f j i) (D.f j k)).inv ⟨⟨_, _⟩, e₂.trans e₃.symm⟩ have eq₁ : (D.t j i) ((pullback.fst _ _ : _ /-(D.f j k)-/ ⟶ D.V (j, i)) z) = x := by dsimp only [coe_of, z] rw [pullbackIsoProdSubtype_inv_fst_apply, D.t_inv_apply] have eq₂ : (pullback.snd _ _ : _ ⟶ D.V _) z = y := pullbackIsoProdSubtype_inv_snd_apply _ _ _ clear_value z use (pullback.fst _ _ : _ ⟶ D.V (i, k)) (D.t' _ _ _ z) dsimp only at * substs eq₁ eq₂ e₁ e₃ e₄ have h₁ : D.t' j i k ≫ pullback.fst _ _ ≫ D.f i k = pullback.fst _ _ ≫ D.t j i ≫ D.f i j := by rw [← 𝖣.t_fac_assoc]; congr 1; exact pullback.condition have h₂ : D.t' j i k ≫ pullback.fst _ _ ≫ D.t i k ≫ D.f k i = pullback.snd _ _ ≫ D.t j k ≫ D.f k j := by rw [← 𝖣.t_fac_assoc] apply @Epi.left_cancellation _ _ _ _ (D.t' k j i) rw [𝖣.cocycle_assoc, 𝖣.t_fac_assoc, 𝖣.t_inv_assoc] exact pullback.condition.symm exact ⟨CategoryTheory.congr_fun h₁ z, CategoryTheory.congr_fun h₂ z⟩⟩ open CategoryTheory.Limits.WalkingParallelPair theorem eqvGen_of_π_eq {x y : ↑(∐ D.U)} (h : 𝖣.π x = 𝖣.π y) : Relation.EqvGen (Function.Coequalizer.Rel 𝖣.diagram.fstSigmaMap 𝖣.diagram.sndSigmaMap) x y := by delta GlueData.π Multicoequalizer.sigmaπ at h replace h : coequalizer.π D.diagram.fstSigmaMap D.diagram.sndSigmaMap x = coequalizer.π D.diagram.fstSigmaMap D.diagram.sndSigmaMap y := (TopCat.mono_iff_injective (Multicoequalizer.isoCoequalizer 𝖣.diagram).inv).mp inferInstance h let diagram := parallelPair 𝖣.diagram.fstSigmaMap 𝖣.diagram.sndSigmaMap ⋙ forget _ have : colimit.ι diagram one x = colimit.ι diagram one y := by dsimp only [coequalizer.π] at h rw [← ι_preservesColimitIso_hom, ConcreteCategory.forget_map_eq_coe, types_comp_apply] simp_all have : (colimit.ι diagram _ ≫ colim.map _ ≫ (colimit.isoColimitCocone _).hom) _ = (colimit.ι diagram _ ≫ colim.map _ ≫ (colimit.isoColimitCocone _).hom) _ := (congr_arg (colim.map (diagramIsoParallelPair diagram).hom ≫ (colimit.isoColimitCocone (Types.coequalizerColimit _ _)).hom) this : _) simp only [eqToHom_refl, colimit.ι_map_assoc, diagramIsoParallelPair_hom_app, colimit.isoColimitCocone_ι_hom, Category.id_comp] at this exact Quot.eq.1 this theorem ι_eq_iff_rel (i j : D.J) (x : D.U i) (y : D.U j) : 𝖣.ι i x = 𝖣.ι j y ↔ D.Rel ⟨i, x⟩ ⟨j, y⟩ := by constructor · delta GlueData.ι simp_rw [← Multicoequalizer.ι_sigmaπ] intro h rw [← show _ = Sigma.mk i x from ConcreteCategory.congr_hom (sigmaIsoSigma.{_, u} D.U).inv_hom_id _] rw [← show _ = Sigma.mk j y from ConcreteCategory.congr_hom (sigmaIsoSigma.{_, u} D.U).inv_hom_id _] change InvImage D.Rel (sigmaIsoSigma.{_, u} D.U).hom _ _ rw [← (InvImage.equivalence _ _ D.rel_equiv).eqvGen_iff] refine Relation.EqvGen.mono ?_ (D.eqvGen_of_π_eq h :) rintro _ _ ⟨x⟩ obtain ⟨⟨⟨i, j⟩, y⟩, rfl⟩ := (ConcreteCategory.bijective_of_isIso (sigmaIsoSigma.{u, u} _).inv).2 x unfold InvImage MultispanIndex.fstSigmaMap MultispanIndex.sndSigmaMap rw [sigmaIsoSigma_inv_apply] -- `rw [← ConcreteCategory.comp_apply]` succeeds but rewrites the wrong expression erw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, colimit.ι_desc_assoc, ← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, colimit.ι_desc_assoc] -- previous line now `erw` after https://github.com/leanprover-community/mathlib4/pull/13170 erw [sigmaIsoSigma_hom_ι_apply, sigmaIsoSigma_hom_ι_apply] exact ⟨y, ⟨rfl, rfl⟩⟩ · rintro ⟨z, e₁, e₂⟩ dsimp only at * -- Porting note: there were `subst e₁` and `subst e₂`, instead of the `rw` rw [← e₁, ← e₂] at * rw [D.glue_condition_apply] theorem ι_injective (i : D.J) : Function.Injective (𝖣.ι i) := by intro x y h rcases (D.ι_eq_iff_rel _ _ _ _).mp h with ⟨_, e₁, e₂⟩ · dsimp only at * -- Porting note: there were `cases e₁` and `cases e₂`, instead of the `rw` rw [← e₁, ← e₂] simp instance ι_mono (i : D.J) : Mono (𝖣.ι i) := (TopCat.mono_iff_injective _).mpr (D.ι_injective _) theorem image_inter (i j : D.J) : Set.range (𝖣.ι i) ∩ Set.range (𝖣.ι j) = Set.range (D.f i j ≫ 𝖣.ι _) := by ext x constructor · rintro ⟨⟨x₁, eq₁⟩, ⟨x₂, eq₂⟩⟩ obtain ⟨y, e₁, -⟩ := (D.ι_eq_iff_rel _ _ _ _).mp (eq₁.trans eq₂.symm) · substs eq₁ exact ⟨y, by simp [e₁]⟩ · rintro ⟨x, hx⟩ refine ⟨⟨D.f i j x, hx⟩, ⟨D.f j i (D.t _ _ x), ?_⟩⟩ rw [D.glue_condition_apply] exact hx theorem preimage_range (i j : D.J) : 𝖣.ι j ⁻¹' Set.range (𝖣.ι i) = Set.range (D.f j i) := by rw [← Set.preimage_image_eq (Set.range (D.f j i)) (D.ι_injective j), ← Set.image_univ, ← Set.image_univ, ← Set.image_comp, ← coe_comp, Set.image_univ, Set.image_univ, ← image_inter, Set.preimage_range_inter] theorem preimage_image_eq_image (i j : D.J) (U : Set (𝖣.U i)) : 𝖣.ι j ⁻¹' (𝖣.ι i '' U) = D.f _ _ '' ((D.t j i ≫ D.f _ _) ⁻¹' U) := by have : D.f _ _ ⁻¹' (𝖣.ι j ⁻¹' (𝖣.ι i '' U)) = (D.t j i ≫ D.f _ _) ⁻¹' U := by ext x conv_rhs => rw [← Set.preimage_image_eq U (D.ι_injective _)] simp rw [← this, Set.image_preimage_eq_inter_range] symm apply Set.inter_eq_self_of_subset_left rw [← D.preimage_range i j] exact Set.preimage_mono (Set.image_subset_range _ _) theorem preimage_image_eq_image' (i j : D.J) (U : Set (𝖣.U i)) : 𝖣.ι j ⁻¹' (𝖣.ι i '' U) = (D.t i j ≫ D.f _ _) '' (D.f _ _ ⁻¹' U) := by convert D.preimage_image_eq_image i j U using 1 rw [coe_comp, coe_comp, Set.image_comp] congr! 1 rw [← Set.eq_preimage_iff_image_eq, Set.preimage_preimage] · change _ = (D.t i j ≫ D.t j i ≫ _) ⁻¹' _ rw [𝖣.t_inv_assoc] rw [← isIso_iff_bijective] apply (forget TopCat).map_isIso theorem open_image_open (i : D.J) (U : Opens (𝖣.U i)) : IsOpen (𝖣.ι i '' U) := by rw [isOpen_iff] intro j rw [preimage_image_eq_image] apply (D.f_open _ _).isOpenMap apply (D.t j i ≫ D.f i j).hom.continuous_toFun.isOpen_preimage exact U.isOpen theorem ι_isOpenEmbedding (i : D.J) : IsOpenEmbedding (𝖣.ι i) := .of_continuous_injective_isOpenMap (𝖣.ι i).hom.continuous_toFun (D.ι_injective i) fun U h => D.open_image_open i ⟨U, h⟩ /-- A family of gluing data consists of 1. An index type `J` 2. A bundled topological space `U i` for each `i : J`. 3. An open set `V i j ⊆ U i` for each `i j : J`. 4. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `V i i = U i`. 7. `t i i` is the identity. 8. For each `x ∈ V i j ∩ V i k`, `t i j x ∈ V j k`. 9. `t j k (t i j x) = t i k x`. We can then glue the topological spaces `U i` together by identifying `V i j` with `V j i`. -/ structure MkCore where /-- The index type `J` -/ {J : Type u} /-- For each `i : J`, a bundled topological space `U i` -/ U : J → TopCat.{u} /-- For each `i j : J`, an open set `V i j ⊆ U i` -/ V : ∀ i, J → Opens (U i) /-- For each `i j : ι`, a transition map `t i j : V i j ⟶ V j i` -/ t : ∀ i j, (Opens.toTopCat _).obj (V i j) ⟶ (Opens.toTopCat _).obj (V j i) V_id : ∀ i, V i i = ⊤ t_id : ∀ i, ⇑(t i i) = id t_inter : ∀ ⦃i j⦄ (k) (x : V i j), ↑x ∈ V i k → (((↑) : (V j i) → (U j)) (t i j x)) ∈ V j k cocycle : ∀ (i j k) (x : V i j) (h : ↑x ∈ V i k), (((↑) : (V k j) → (U k)) (t j k ⟨_, t_inter k x h⟩)) = ((↑) : (V k i) → (U k)) (t i k ⟨x, h⟩) theorem MkCore.t_inv (h : MkCore) (i j : h.J) (x : h.V j i) : h.t i j ((h.t j i) x) = x := by have := h.cocycle j i j x ?_ · rw [h.t_id] at this · convert Subtype.eq this rw [h.V_id] trivial instance (h : MkCore.{u}) (i j : h.J) : IsIso (h.t i j) := by use h.t j i; constructor <;> ext1; exacts [h.t_inv _ _ _, h.t_inv _ _ _] /-- (Implementation) the restricted transition map to be fed into `TopCat.GlueData`. -/ def MkCore.t' (h : MkCore.{u}) (i j k : h.J) : pullback (h.V i j).inclusion' (h.V i k).inclusion' ⟶ pullback (h.V j k).inclusion' (h.V j i).inclusion' := by refine (pullbackIsoProdSubtype _ _).hom ≫ ofHom ⟨?_, ?_⟩ ≫ (pullbackIsoProdSubtype _ _).inv · intro x refine ⟨⟨⟨(h.t i j x.1.1).1, ?_⟩, h.t i j x.1.1⟩, rfl⟩ rcases x with ⟨⟨⟨x, hx⟩, ⟨x', hx'⟩⟩, rfl : x = x'⟩ exact h.t_inter _ ⟨x, hx⟩ hx' fun_prop /-- This is a constructor of `TopCat.GlueData` whose arguments are in terms of elements and intersections rather than subobjects and pullbacks. Please refer to `TopCat.GlueData.MkCore` for details. -/ def mk' (h : MkCore.{u}) : TopCat.GlueData where J := h.J U := h.U V i := (Opens.toTopCat _).obj (h.V i.1 i.2) f i j := (h.V i j).inclusion' f_id i := (h.V_id i).symm ▸ (Opens.inclusionTopIso (h.U i)).isIso_hom f_open := fun i j : h.J => (h.V i j).isOpenEmbedding t := h.t t_id i := by ext; rw [h.t_id]; rfl t' := h.t' t_fac i j k := by delta MkCore.t' rw [Category.assoc, Category.assoc, pullbackIsoProdSubtype_inv_snd, ← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_fst_assoc] ext ⟨⟨⟨x, hx⟩, ⟨x', hx'⟩⟩, rfl : x = x'⟩ rfl cocycle i j k := by delta MkCore.t' simp_rw [← Category.assoc] rw [Iso.comp_inv_eq] simp only [Iso.inv_hom_id_assoc, Category.assoc, Category.id_comp] rw [← Iso.eq_inv_comp, Iso.inv_hom_id] ext1 ⟨⟨⟨x, hx⟩, ⟨x', hx'⟩⟩, rfl : x = x'⟩ dsimp only [Opens.coe_inclusion', hom_comp, hom_ofHom, ContinuousMap.comp_assoc, ContinuousMap.comp_apply, ContinuousMap.coe_mk, hom_id, ContinuousMap.id_apply] rw [Subtype.mk_eq_mk, Prod.mk_inj, Subtype.mk_eq_mk, Subtype.ext_iff, and_self_iff] convert congr_arg Subtype.val (h.t_inv k i ⟨x, hx'⟩) using 3 refine Subtype.ext ?_ exact h.cocycle i j k ⟨x, hx⟩ hx' f_mono _ _ := (TopCat.mono_iff_injective _).mpr fun _ _ h => Subtype.ext h variable {α : Type u} [TopologicalSpace α] {J : Type u} (U : J → Opens α) /-- We may construct a glue data from a family of open sets. -/ @[simps! toGlueData_J toGlueData_U toGlueData_V toGlueData_t toGlueData_f] def ofOpenSubsets : TopCat.GlueData.{u} := mk'.{u} { J U := fun i => (Opens.toTopCat <| TopCat.of α).obj (U i) V := fun _ j => (Opens.map <| Opens.inclusion' _).obj (U j) t := fun i j => ofHom ⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, by fun_prop⟩ V_id := fun i => by simp t_id := fun i => by ext; rfl t_inter := fun _ _ _ _ hx => hx cocycle := fun _ _ _ _ _ => rfl } /-- The canonical map from the glue of a family of open subsets `α` into `α`. This map is an open embedding (`fromOpenSubsetsGlue_isOpenEmbedding`), and its range is `⋃ i, (U i : Set α)` (`range_fromOpenSubsetsGlue`). -/ def fromOpenSubsetsGlue : (ofOpenSubsets U).toGlueData.glued ⟶ TopCat.of α := Multicoequalizer.desc _ _ (fun _ => Opens.inclusion' _) (by rintro ⟨i, j⟩; ext x; rfl) @[simp, elementwise nosimp] theorem ι_fromOpenSubsetsGlue (i : J) : (ofOpenSubsets U).toGlueData.ι i ≫ fromOpenSubsetsGlue U = Opens.inclusion' _ := Multicoequalizer.π_desc _ _ _ _ _ theorem fromOpenSubsetsGlue_injective : Function.Injective (fromOpenSubsetsGlue U) := by intro x y e obtain ⟨i, ⟨x, hx⟩, rfl⟩ := (ofOpenSubsets U).ι_jointly_surjective x obtain ⟨j, ⟨y, hy⟩, rfl⟩ := (ofOpenSubsets U).ι_jointly_surjective y rw [ι_fromOpenSubsetsGlue_apply, ι_fromOpenSubsetsGlue_apply] at e subst e rw [(ofOpenSubsets U).ι_eq_iff_rel] exact ⟨⟨⟨x, hx⟩, hy⟩, rfl, rfl⟩ theorem fromOpenSubsetsGlue_isOpenMap : IsOpenMap (fromOpenSubsetsGlue U) := by intro s hs rw [(ofOpenSubsets U).isOpen_iff] at hs rw [isOpen_iff_forall_mem_open] rintro _ ⟨x, hx, rfl⟩ obtain ⟨i, ⟨x, hx'⟩, rfl⟩ := (ofOpenSubsets U).ι_jointly_surjective x use fromOpenSubsetsGlue U '' s ∩ Set.range (@Opens.inclusion' (TopCat.of α) (U i)) use Set.inter_subset_left constructor · rw [← Set.image_preimage_eq_inter_range] apply (Opens.isOpenEmbedding (X := TopCat.of α) (U i)).isOpenMap convert hs i using 1 rw [← ι_fromOpenSubsetsGlue, coe_comp, Set.preimage_comp] congr! 1 exact Set.preimage_image_eq _ (fromOpenSubsetsGlue_injective U) · refine ⟨Set.mem_image_of_mem _ hx, ?_⟩ rw [ι_fromOpenSubsetsGlue_apply] exact Set.mem_range_self (f := (Opens.inclusion' _).hom) ⟨x, hx'⟩ theorem fromOpenSubsetsGlue_isOpenEmbedding : IsOpenEmbedding (fromOpenSubsetsGlue U) := .of_continuous_injective_isOpenMap (ContinuousMap.continuous_toFun _) (fromOpenSubsetsGlue_injective U) (fromOpenSubsetsGlue_isOpenMap U) theorem range_fromOpenSubsetsGlue : Set.range (fromOpenSubsetsGlue U) = ⋃ i, (U i : Set α) := by ext constructor · rintro ⟨x, rfl⟩ obtain ⟨i, ⟨x, hx'⟩, rfl⟩ := (ofOpenSubsets U).ι_jointly_surjective x rw [ι_fromOpenSubsetsGlue_apply] exact Set.subset_iUnion _ i hx' · rintro ⟨_, ⟨i, rfl⟩, hx⟩ rename_i x exact ⟨(ofOpenSubsets U).toGlueData.ι i ⟨x, hx⟩, ι_fromOpenSubsetsGlue_apply _ _ _⟩ /-- The gluing of an open cover is homeomorphic to the original space. -/ def openCoverGlueHomeo (h : ⋃ i, (U i : Set α) = Set.univ) : (ofOpenSubsets U).toGlueData.glued ≃ₜ α := Equiv.toHomeomorphOfContinuousOpen (Equiv.ofBijective (fromOpenSubsetsGlue U) ⟨fromOpenSubsetsGlue_injective U, Set.range_eq_univ.mp ((range_fromOpenSubsetsGlue U).symm ▸ h)⟩) (fromOpenSubsetsGlue U).hom.2 (fromOpenSubsetsGlue_isOpenMap U) end GlueData end TopCat
.lake/packages/mathlib/Mathlib/Topology/Semicontinuous.lean
import Mathlib.Algebra.GroupWithZero.Indicator import Mathlib.Topology.Piecewise import Mathlib.Topology.Instances.ENNReal.Lemmas /-! # Semicontinuous maps A function `f` from a topological space `α` to an ordered space `β` is lower semicontinuous at a point `x` if, for any `y < f x`, for any `x'` close enough to `x`, one has `f x' > y`. In other words, `f` can jump up, but it cannot jump down. Upper semicontinuous functions are defined similarly. This file introduces these notions, and a basic API around them mimicking the API for continuous functions. ## Main definitions and results We introduce 4 definitions related to lower semicontinuity: * `LowerSemicontinuousWithinAt f s x` * `LowerSemicontinuousAt f x` * `LowerSemicontinuousOn f s` * `LowerSemicontinuous f` We build a basic API using dot notation around these notions, and we prove that * constant functions are lower semicontinuous; * `indicator s (fun _ ↦ y)` is lower semicontinuous when `s` is open and `0 ≤ y`, or when `s` is closed and `y ≤ 0`; * continuous functions are lower semicontinuous; * left composition with a continuous monotone functions maps lower semicontinuous functions to lower semicontinuous functions. If the function is anti-monotone, it instead maps lower semicontinuous functions to upper semicontinuous functions; * right composition with continuous functions preserves lower and upper semicontinuity; * a sum of two (or finitely many) lower semicontinuous functions is lower semicontinuous; * a supremum of a family of lower semicontinuous functions is lower semicontinuous; * An infinite sum of `ℝ≥0∞`-valued lower semicontinuous functions is lower semicontinuous. Similar results are stated and proved for upper semicontinuity. We also prove that a function is continuous if and only if it is both lower and upper semicontinuous. We have some equivalent definitions of lower- and upper-semicontinuity (under certain restrictions on the order on the codomain): * `lowerSemicontinuous_iff_isOpen_preimage` in a linear order; * `lowerSemicontinuous_iff_isClosed_preimage` in a linear order; * `lowerSemicontinuousAt_iff_le_liminf` in a complete linear order; * `lowerSemicontinuous_iff_isClosed_epigraph` in a linear order with the order topology. ## Implementation details All the nontrivial results for upper semicontinuous functions are deduced from the corresponding ones for lower semicontinuous functions using `OrderDual`. ## References * <https://en.wikipedia.org/wiki/Closed_convex_function> * <https://en.wikipedia.org/wiki/Semi-continuity> -/ open Topology ENNReal open Set Function Filter variable {α : Type*} [TopologicalSpace α] {β : Type*} [Preorder β] {f g : α → β} {x : α} {s t : Set α} {y z : β} /-! ### Main definitions -/ /-- A real function `f` is lower semicontinuous at `x` within a set `s` if, for any `ε > 0`, for all `x'` close enough to `x` in `s`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def LowerSemicontinuousWithinAt (f : α → β) (s : Set α) (x : α) := ∀ y < f x, ∀ᶠ x' in 𝓝[s] x, y < f x' /-- A real function `f` is lower semicontinuous on a set `s` if, for any `ε > 0`, for any `x ∈ s`, for all `x'` close enough to `x` in `s`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def LowerSemicontinuousOn (f : α → β) (s : Set α) := ∀ x ∈ s, LowerSemicontinuousWithinAt f s x /-- A real function `f` is lower semicontinuous at `x` if, for any `ε > 0`, for all `x'` close enough to `x`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def LowerSemicontinuousAt (f : α → β) (x : α) := ∀ y < f x, ∀ᶠ x' in 𝓝 x, y < f x' /-- A real function `f` is lower semicontinuous if, for any `ε > 0`, for any `x`, for all `x'` close enough to `x`, then `f x'` is at least `f x - ε`. We formulate this in a general preordered space, using an arbitrary `y < f x` instead of `f x - ε`. -/ def LowerSemicontinuous (f : α → β) := ∀ x, LowerSemicontinuousAt f x /-- A real function `f` is upper semicontinuous at `x` within a set `s` if, for any `ε > 0`, for all `x'` close enough to `x` in `s`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/ def UpperSemicontinuousWithinAt (f : α → β) (s : Set α) (x : α) := ∀ y, f x < y → ∀ᶠ x' in 𝓝[s] x, f x' < y /-- A real function `f` is upper semicontinuous on a set `s` if, for any `ε > 0`, for any `x ∈ s`, for all `x'` close enough to `x` in `s`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/ def UpperSemicontinuousOn (f : α → β) (s : Set α) := ∀ x ∈ s, UpperSemicontinuousWithinAt f s x /-- A real function `f` is upper semicontinuous at `x` if, for any `ε > 0`, for all `x'` close enough to `x`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/ def UpperSemicontinuousAt (f : α → β) (x : α) := ∀ y, f x < y → ∀ᶠ x' in 𝓝 x, f x' < y /-- A real function `f` is upper semicontinuous if, for any `ε > 0`, for any `x`, for all `x'` close enough to `x`, then `f x'` is at most `f x + ε`. We formulate this in a general preordered space, using an arbitrary `y > f x` instead of `f x + ε`. -/ def UpperSemicontinuous (f : α → β) := ∀ x, UpperSemicontinuousAt f x /-! ### Lower semicontinuous functions -/ /-! #### Basic dot notation interface for lower semicontinuity -/ theorem LowerSemicontinuousWithinAt.mono (h : LowerSemicontinuousWithinAt f s x) (hst : t ⊆ s) : LowerSemicontinuousWithinAt f t x := fun y hy => Filter.Eventually.filter_mono (nhdsWithin_mono _ hst) (h y hy) theorem LowerSemicontinuousWithinAt.congr_of_eventuallyEq {a : α} (h : LowerSemicontinuousWithinAt f s a) (has : a ∈ s) (hfg : ∀ᶠ x in nhdsWithin a s, f x = g x) : LowerSemicontinuousWithinAt g s a := by intro b hb rw [← Filter.EventuallyEq.eq_of_nhdsWithin hfg has] at hb exact EventuallyEq.rw hfg _ (h b hb) theorem lowerSemicontinuousWithinAt_univ_iff : LowerSemicontinuousWithinAt f univ x ↔ LowerSemicontinuousAt f x := by simp [LowerSemicontinuousWithinAt, LowerSemicontinuousAt, nhdsWithin_univ] theorem LowerSemicontinuousAt.lowerSemicontinuousWithinAt (s : Set α) (h : LowerSemicontinuousAt f x) : LowerSemicontinuousWithinAt f s x := fun y hy => Filter.Eventually.filter_mono nhdsWithin_le_nhds (h y hy) theorem LowerSemicontinuousOn.lowerSemicontinuousWithinAt (h : LowerSemicontinuousOn f s) (hx : x ∈ s) : LowerSemicontinuousWithinAt f s x := h x hx theorem LowerSemicontinuousOn.mono (h : LowerSemicontinuousOn f s) (hst : t ⊆ s) : LowerSemicontinuousOn f t := fun x hx => (h x (hst hx)).mono hst theorem lowerSemicontinuousOn_univ_iff : LowerSemicontinuousOn f univ ↔ LowerSemicontinuous f := by simp [LowerSemicontinuousOn, LowerSemicontinuous, lowerSemicontinuousWithinAt_univ_iff] @[simp] theorem lowerSemicontinuous_restrict_iff : LowerSemicontinuous (s.restrict f) ↔ LowerSemicontinuousOn f s := by rw [LowerSemicontinuousOn, LowerSemicontinuous, SetCoe.forall] refine forall₂_congr fun a ha ↦ forall₂_congr fun b _ ↦ ?_ simp only [nhdsWithin_eq_map_subtype_coe ha, eventually_map, restrict] theorem LowerSemicontinuous.lowerSemicontinuousAt (h : LowerSemicontinuous f) (x : α) : LowerSemicontinuousAt f x := h x theorem LowerSemicontinuous.lowerSemicontinuousWithinAt (h : LowerSemicontinuous f) (s : Set α) (x : α) : LowerSemicontinuousWithinAt f s x := (h x).lowerSemicontinuousWithinAt s theorem LowerSemicontinuous.lowerSemicontinuousOn (h : LowerSemicontinuous f) (s : Set α) : LowerSemicontinuousOn f s := fun x _hx => h.lowerSemicontinuousWithinAt s x /-! #### Constants -/ theorem lowerSemicontinuousWithinAt_const : LowerSemicontinuousWithinAt (fun _x => z) s x := fun _y hy => Filter.Eventually.of_forall fun _x => hy theorem lowerSemicontinuousAt_const : LowerSemicontinuousAt (fun _x => z) x := fun _y hy => Filter.Eventually.of_forall fun _x => hy theorem lowerSemicontinuousOn_const : LowerSemicontinuousOn (fun _x => z) s := fun _x _hx => lowerSemicontinuousWithinAt_const theorem lowerSemicontinuous_const : LowerSemicontinuous fun _x : α => z := fun _x => lowerSemicontinuousAt_const /-! ### lower bounds -/ section variable {α : Type*} [TopologicalSpace α] {β : Type*} [LinearOrder β] {f : α → β} {s : Set α} /-- A lower semicontinuous function attains its lower bound on a nonempty compact set. -/ theorem LowerSemicontinuousOn.exists_isMinOn {s : Set α} (ne_s : s.Nonempty) (hs : IsCompact s) (hf : LowerSemicontinuousOn f s) : ∃ a ∈ s, IsMinOn f s a := by -- hf.exists_forall_le_of_isCompact ne_s hs simp only [isMinOn_iff] have _ : Nonempty α := Exists.nonempty ne_s have _ : Nonempty s := Nonempty.to_subtype ne_s let φ : β → Filter α := fun b ↦ 𝓟 (s ∩ f ⁻¹' Iic b) let ℱ : Filter α := ⨅ a : s, φ (f a) have : ℱ.NeBot := by apply iInf_neBot_of_directed _ _ · change Directed GE.ge (fun x ↦ (φ ∘ (fun (a : s) ↦ f ↑a)) x) exact Directed.mono_comp GE.ge (fun x y hxy ↦ principal_mono.mpr (inter_subset_inter_right _ (preimage_mono <| Iic_subset_Iic.mpr hxy)) ) (IsTotal.directed _) · intro x have : (pure x : Filter α) ≤ φ (f x) := le_principal_iff.mpr ⟨x.2, le_refl (f x)⟩ exact neBot_of_le this have hℱs : ℱ ≤ 𝓟 s := iInf_le_of_le (Classical.choice inferInstance) (principal_mono.mpr <| inter_subset_left) have hℱ (x) (hx : x ∈ s) : ∀ᶠ y in ℱ, f y ≤ f x := mem_iInf_of_mem ⟨x, hx⟩ (by apply inter_subset_right) obtain ⟨a, ha, h⟩ := hs hℱs refine ⟨a, ha, fun x hx ↦ le_of_not_gt fun hxa ↦ ?_⟩ let _ : (𝓝 a ⊓ ℱ).NeBot := h suffices ∀ᶠ _ in 𝓝 a ⊓ ℱ, False by rwa [eventually_const] at this filter_upwards [(hf a ha (f x) hxa).filter_mono (inf_le_inf_left _ hℱs), (hℱ x hx).filter_mono (inf_le_right : 𝓝 a ⊓ ℱ ≤ ℱ)] using fun y h₁ h₂ ↦ not_le_of_gt h₁ h₂ /-- A lower semicontinuous function is bounded below on a compact set. -/ theorem LowerSemicontinuousOn.bddBelow_of_isCompact [Nonempty β] {s : Set α} (hs : IsCompact s) (hf : LowerSemicontinuousOn f s) : BddBelow (f '' s) := by cases s.eq_empty_or_nonempty with | inl h => simp only [h, Set.image_empty] exact bddBelow_empty | inr h => obtain ⟨a, _, has⟩ := LowerSemicontinuousOn.exists_isMinOn h hs hf exact has.bddBelow end /-! #### Indicators -/ section variable [Zero β] theorem IsOpen.lowerSemicontinuous_indicator (hs : IsOpen s) (hy : 0 ≤ y) : LowerSemicontinuous (indicator s fun _x => y) := by intro x z hz by_cases h : x ∈ s <;> simp [h] at hz · filter_upwards [hs.mem_nhds h] simp +contextual [hz] · refine Filter.Eventually.of_forall fun x' => ?_ by_cases h' : x' ∈ s <;> simp [h', hz.trans_le hy, hz] theorem IsOpen.lowerSemicontinuousOn_indicator (hs : IsOpen s) (hy : 0 ≤ y) : LowerSemicontinuousOn (indicator s fun _x => y) t := (hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousOn t theorem IsOpen.lowerSemicontinuousAt_indicator (hs : IsOpen s) (hy : 0 ≤ y) : LowerSemicontinuousAt (indicator s fun _x => y) x := (hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousAt x theorem IsOpen.lowerSemicontinuousWithinAt_indicator (hs : IsOpen s) (hy : 0 ≤ y) : LowerSemicontinuousWithinAt (indicator s fun _x => y) t x := (hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousWithinAt t x theorem IsClosed.lowerSemicontinuous_indicator (hs : IsClosed s) (hy : y ≤ 0) : LowerSemicontinuous (indicator s fun _x => y) := by intro x z hz by_cases h : x ∈ s <;> simp [h] at hz · refine Filter.Eventually.of_forall fun x' => ?_ by_cases h' : x' ∈ s <;> simp [h', hz, hz.trans_le hy] · filter_upwards [hs.isOpen_compl.mem_nhds h] simp +contextual [hz] theorem IsClosed.lowerSemicontinuousOn_indicator (hs : IsClosed s) (hy : y ≤ 0) : LowerSemicontinuousOn (indicator s fun _x => y) t := (hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousOn t theorem IsClosed.lowerSemicontinuousAt_indicator (hs : IsClosed s) (hy : y ≤ 0) : LowerSemicontinuousAt (indicator s fun _x => y) x := (hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousAt x theorem IsClosed.lowerSemicontinuousWithinAt_indicator (hs : IsClosed s) (hy : y ≤ 0) : LowerSemicontinuousWithinAt (indicator s fun _x => y) t x := (hs.lowerSemicontinuous_indicator hy).lowerSemicontinuousWithinAt t x end /-! #### Relationship with continuity -/ theorem lowerSemicontinuous_iff_isOpen_preimage : LowerSemicontinuous f ↔ ∀ y, IsOpen (f ⁻¹' Ioi y) := ⟨fun H y => isOpen_iff_mem_nhds.2 fun x hx => H x y hx, fun H _x y y_lt => IsOpen.mem_nhds (H y) y_lt⟩ theorem LowerSemicontinuous.isOpen_preimage (hf : LowerSemicontinuous f) (y : β) : IsOpen (f ⁻¹' Ioi y) := lowerSemicontinuous_iff_isOpen_preimage.1 hf y theorem lowerSemicontinuousOn_iff_preimage_Ioi : LowerSemicontinuousOn f s ↔ ∀ b, ∃ u, IsOpen u ∧ s ∩ f ⁻¹' Set.Ioi b = s ∩ u := by simp only [← lowerSemicontinuous_restrict_iff, restrict_eq, lowerSemicontinuous_iff_isOpen_preimage, preimage_comp, isOpen_induced_iff, Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm] section variable {γ : Type*} [LinearOrder γ] theorem lowerSemicontinuous_iff_isClosed_preimage {f : α → γ} : LowerSemicontinuous f ↔ ∀ y, IsClosed (f ⁻¹' Iic y) := by rw [lowerSemicontinuous_iff_isOpen_preimage] simp only [← isOpen_compl_iff, ← preimage_compl, compl_Iic] theorem LowerSemicontinuous.isClosed_preimage {f : α → γ} (hf : LowerSemicontinuous f) (y : γ) : IsClosed (f ⁻¹' Iic y) := lowerSemicontinuous_iff_isClosed_preimage.1 hf y theorem lowerSemicontinuousOn_iff_preimage_Iic {f : α → γ} : LowerSemicontinuousOn f s ↔ ∀ b, ∃ v, IsClosed v ∧ s ∩ f ⁻¹' Set.Iic b = s ∩ v := by simp only [← lowerSemicontinuous_restrict_iff, restrict_eq, lowerSemicontinuous_iff_isClosed_preimage, preimage_comp, isClosed_induced_iff, Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm] variable [TopologicalSpace γ] [OrderTopology γ] theorem ContinuousWithinAt.lowerSemicontinuousWithinAt {f : α → γ} (h : ContinuousWithinAt f s x) : LowerSemicontinuousWithinAt f s x := fun _y hy => h (Ioi_mem_nhds hy) theorem ContinuousAt.lowerSemicontinuousAt {f : α → γ} (h : ContinuousAt f x) : LowerSemicontinuousAt f x := fun _y hy => h (Ioi_mem_nhds hy) theorem ContinuousOn.lowerSemicontinuousOn {f : α → γ} (h : ContinuousOn f s) : LowerSemicontinuousOn f s := fun x hx => (h x hx).lowerSemicontinuousWithinAt theorem Continuous.lowerSemicontinuous {f : α → γ} (h : Continuous f) : LowerSemicontinuous f := fun _x => h.continuousAt.lowerSemicontinuousAt end /-! #### Equivalent definitions -/ section variable {γ : Type*} [CompleteLinearOrder γ] theorem lowerSemicontinuousWithinAt_iff_le_liminf {f : α → γ} : LowerSemicontinuousWithinAt f s x ↔ f x ≤ liminf f (𝓝[s] x) := by constructor · intro hf; unfold LowerSemicontinuousWithinAt at hf contrapose! hf obtain ⟨z, ltz, y, ylt, h₁⟩ := hf.exists_disjoint_Iio_Ioi; use y exact ⟨ylt, fun h => ltz.not_ge (le_liminf_of_le (by isBoundedDefault) (h.mono fun _ h₂ => le_of_not_gt fun h₃ => (h₁ _ h₃ _ h₂).false))⟩ exact fun hf y ylt => eventually_lt_of_lt_liminf (ylt.trans_le hf) alias ⟨LowerSemicontinuousWithinAt.le_liminf, _⟩ := lowerSemicontinuousWithinAt_iff_le_liminf theorem lowerSemicontinuousAt_iff_le_liminf {f : α → γ} : LowerSemicontinuousAt f x ↔ f x ≤ liminf f (𝓝 x) := by rw [← lowerSemicontinuousWithinAt_univ_iff, lowerSemicontinuousWithinAt_iff_le_liminf, ← nhdsWithin_univ] alias ⟨LowerSemicontinuousAt.le_liminf, _⟩ := lowerSemicontinuousAt_iff_le_liminf theorem lowerSemicontinuous_iff_le_liminf {f : α → γ} : LowerSemicontinuous f ↔ ∀ x, f x ≤ liminf f (𝓝 x) := by simp only [← lowerSemicontinuousAt_iff_le_liminf, LowerSemicontinuous] alias ⟨LowerSemicontinuous.le_liminf, _⟩ := lowerSemicontinuous_iff_le_liminf theorem lowerSemicontinuousOn_iff_le_liminf {f : α → γ} : LowerSemicontinuousOn f s ↔ ∀ x ∈ s, f x ≤ liminf f (𝓝[s] x) := by simp only [← lowerSemicontinuousWithinAt_iff_le_liminf, LowerSemicontinuousOn] alias ⟨LowerSemicontinuousOn.le_liminf, _⟩ := lowerSemicontinuousOn_iff_le_liminf end section variable {γ : Type*} [LinearOrder γ] [TopologicalSpace γ] [ClosedIciTopology γ] theorem lowerSemicontinuousOn_iff_isClosed_epigraph {f : α → γ} {s : Set α} (hs : IsClosed s) : LowerSemicontinuousOn f s ↔ IsClosed {p : α × γ | p.1 ∈ s ∧ f p.1 ≤ p.2} := by simp_rw [LowerSemicontinuousOn, LowerSemicontinuousWithinAt, eventually_nhdsWithin_iff, ← isOpen_compl_iff, compl_setOf, isOpen_iff_eventually, mem_setOf, not_and, not_le] constructor · intro hf ⟨x, y⟩ h by_cases hx : x ∈ s · have ⟨y', hy', z, hz, h₁⟩ := (h hx).exists_disjoint_Iio_Ioi filter_upwards [(hf x hx z hz).prodMk_nhds (eventually_lt_nhds hy')] with _ ⟨h₂, h₃⟩ h₄ using h₁ _ h₃ _ <| h₂ h₄ · filter_upwards [(continuous_fst.tendsto _).eventually (hs.isOpen_compl.eventually_mem hx)] with _ h₁ h₂ using (h₁ h₂).elim · intro hf x _ y hy exact ((Continuous.prodMk_left y).tendsto x).eventually (hf (x, y) (fun _ => hy)) theorem lowerSemicontinuous_iff_isClosed_epigraph {f : α → γ} : LowerSemicontinuous f ↔ IsClosed {p : α × γ | f p.1 ≤ p.2} := by simp [← lowerSemicontinuousOn_univ_iff, lowerSemicontinuousOn_iff_isClosed_epigraph] alias ⟨LowerSemicontinuous.isClosed_epigraph, _⟩ := lowerSemicontinuous_iff_isClosed_epigraph end /-! ### Composition -/ section variable {α β : Type*} [Preorder β] {f g : α → β} {s : Set α} {a : α} variable [TopologicalSpace α] variable {γ : Type*} [TopologicalSpace γ] {g : γ → α} {x : γ} {t : Set γ} theorem LowerSemicontinuousWithinAt.comp (hf : LowerSemicontinuousWithinAt f s (g x)) (hg : ContinuousWithinAt g t x) (hg' : MapsTo g t s) : LowerSemicontinuousWithinAt (f ∘ g) t x := fun b hb ↦ (hg.tendsto_nhdsWithin hg').eventually (hf b hb) theorem LowerSemicontinuousAt.comp (hf : LowerSemicontinuousAt f (g x)) (hg : ContinuousAt g x) : LowerSemicontinuousAt (f ∘ g) x := fun b hb ↦ hg.eventually (hf b hb) theorem LowerSemicontinuousOn.comp (hf : LowerSemicontinuousOn f s) (hg : ContinuousOn g t) (hg' : MapsTo g t s) : LowerSemicontinuousOn (f ∘ g) t := fun x hx ↦ (hf (g x) (hg' hx)).comp (hg x hx) hg' theorem LowerSemicontinuous.comp (hf : LowerSemicontinuous f) (hg : Continuous g) : LowerSemicontinuous (f ∘ g) := fun x ↦ (hf (g x)).comp hg.continuousAt end section variable {γ : Type*} [LinearOrder γ] [TopologicalSpace γ] [OrderTopology γ] variable {δ : Type*} [LinearOrder δ] [TopologicalSpace δ] [OrderTopology δ] variable {ι : Type*} [TopologicalSpace ι] theorem ContinuousAt.comp_lowerSemicontinuousWithinAt {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousWithinAt f s x) (gmon : Monotone g) : LowerSemicontinuousWithinAt (g ∘ f) s x := by intro y hy by_cases! h : ∃ l, l < f x · obtain ⟨z, zlt, hz⟩ : ∃ z < f x, Ioc z (f x) ⊆ g ⁻¹' Ioi y := exists_Ioc_subset_of_mem_nhds (hg (Ioi_mem_nhds hy)) h filter_upwards [hf z zlt] with a ha calc y < g (min (f x) (f a)) := hz (by simp [zlt, ha]) _ ≤ g (f a) := gmon (min_le_right _ _) · exact Filter.Eventually.of_forall fun a => hy.trans_le (gmon (h (f a))) theorem ContinuousAt.comp_lowerSemicontinuousAt {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousAt f x) (gmon : Monotone g) : LowerSemicontinuousAt (g ∘ f) x := by simp only [← lowerSemicontinuousWithinAt_univ_iff] at hf ⊢ exact hg.comp_lowerSemicontinuousWithinAt hf gmon theorem Continuous.comp_lowerSemicontinuousOn {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : LowerSemicontinuousOn f s) (gmon : Monotone g) : LowerSemicontinuousOn (g ∘ f) s := fun x hx => hg.continuousAt.comp_lowerSemicontinuousWithinAt (hf x hx) gmon theorem Continuous.comp_lowerSemicontinuous {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : LowerSemicontinuous f) (gmon : Monotone g) : LowerSemicontinuous (g ∘ f) := fun x => hg.continuousAt.comp_lowerSemicontinuousAt (hf x) gmon theorem ContinuousAt.comp_lowerSemicontinuousWithinAt_antitone {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousWithinAt f s x) (gmon : Antitone g) : UpperSemicontinuousWithinAt (g ∘ f) s x := @ContinuousAt.comp_lowerSemicontinuousWithinAt α _ x s γ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon theorem ContinuousAt.comp_lowerSemicontinuousAt_antitone {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : LowerSemicontinuousAt f x) (gmon : Antitone g) : UpperSemicontinuousAt (g ∘ f) x := @ContinuousAt.comp_lowerSemicontinuousAt α _ x γ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon theorem Continuous.comp_lowerSemicontinuousOn_antitone {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : LowerSemicontinuousOn f s) (gmon : Antitone g) : UpperSemicontinuousOn (g ∘ f) s := fun x hx => hg.continuousAt.comp_lowerSemicontinuousWithinAt_antitone (hf x hx) gmon theorem Continuous.comp_lowerSemicontinuous_antitone {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : LowerSemicontinuous f) (gmon : Antitone g) : UpperSemicontinuous (g ∘ f) := fun x => hg.continuousAt.comp_lowerSemicontinuousAt_antitone (hf x) gmon theorem LowerSemicontinuousAt.comp_continuousAt {f : α → β} {g : ι → α} {x : ι} (hf : LowerSemicontinuousAt f (g x)) (hg : ContinuousAt g x) : LowerSemicontinuousAt (fun x ↦ f (g x)) x := fun _ lt ↦ hg.eventually (hf _ lt) theorem LowerSemicontinuousAt.comp_continuousAt_of_eq {f : α → β} {g : ι → α} {y : α} {x : ι} (hf : LowerSemicontinuousAt f y) (hg : ContinuousAt g x) (hy : g x = y) : LowerSemicontinuousAt (fun x ↦ f (g x)) x := by rw [← hy] at hf exact comp_continuousAt hf hg theorem LowerSemicontinuous.comp_continuous {f : α → β} {g : ι → α} (hf : LowerSemicontinuous f) (hg : Continuous g) : LowerSemicontinuous fun x ↦ f (g x) := fun x ↦ (hf (g x)).comp_continuousAt hg.continuousAt end /-! #### Addition -/ section variable {ι : Type*} {γ : Type*} [AddCommMonoid γ] [LinearOrder γ] [IsOrderedAddMonoid γ] [TopologicalSpace γ] [OrderTopology γ] /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem LowerSemicontinuousWithinAt.add' {f g : α → γ} (hf : LowerSemicontinuousWithinAt f s x) (hg : LowerSemicontinuousWithinAt g s x) (hcont : ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : LowerSemicontinuousWithinAt (fun z => f z + g z) s x := by intro y hy obtain ⟨u, v, u_open, xu, v_open, xv, h⟩ : ∃ u v : Set γ, IsOpen u ∧ f x ∈ u ∧ IsOpen v ∧ g x ∈ v ∧ u ×ˢ v ⊆ { p : γ × γ | y < p.fst + p.snd } := mem_nhds_prod_iff'.1 (hcont (isOpen_Ioi.mem_nhds hy)) by_cases hx₁ : ∃ l, l < f x · obtain ⟨z₁, z₁lt, h₁⟩ : ∃ z₁ < f x, Ioc z₁ (f x) ⊆ u := exists_Ioc_subset_of_mem_nhds (u_open.mem_nhds xu) hx₁ by_cases hx₂ : ∃ l, l < g x · obtain ⟨z₂, z₂lt, h₂⟩ : ∃ z₂ < g x, Ioc z₂ (g x) ⊆ v := exists_Ioc_subset_of_mem_nhds (v_open.mem_nhds xv) hx₂ filter_upwards [hf z₁ z₁lt, hg z₂ z₂lt] with z h₁z h₂z have A1 : min (f z) (f x) ∈ u := by by_cases! H : f z ≤ f x · simpa [H] using h₁ ⟨h₁z, H⟩ · simpa [H.le] have A2 : min (g z) (g x) ∈ v := by by_cases! H : g z ≤ g x · simpa [H] using h₂ ⟨h₂z, H⟩ · simpa [H.le] have : (min (f z) (f x), min (g z) (g x)) ∈ u ×ˢ v := ⟨A1, A2⟩ calc y < min (f z) (f x) + min (g z) (g x) := h this _ ≤ f z + g z := add_le_add (min_le_left _ _) (min_le_left _ _) · simp only [not_exists, not_lt] at hx₂ filter_upwards [hf z₁ z₁lt] with z h₁z have A1 : min (f z) (f x) ∈ u := by by_cases! H : f z ≤ f x · simpa [H] using h₁ ⟨h₁z, H⟩ · simpa [H.le] have : (min (f z) (f x), g x) ∈ u ×ˢ v := ⟨A1, xv⟩ calc y < min (f z) (f x) + g x := h this _ ≤ f z + g z := add_le_add (min_le_left _ _) (hx₂ (g z)) · simp only [not_exists, not_lt] at hx₁ by_cases hx₂ : ∃ l, l < g x · obtain ⟨z₂, z₂lt, h₂⟩ : ∃ z₂ < g x, Ioc z₂ (g x) ⊆ v := exists_Ioc_subset_of_mem_nhds (v_open.mem_nhds xv) hx₂ filter_upwards [hg z₂ z₂lt] with z h₂z have A2 : min (g z) (g x) ∈ v := by by_cases! H : g z ≤ g x · simpa [H] using h₂ ⟨h₂z, H⟩ · simpa [H.le] using h₂ ⟨z₂lt, le_rfl⟩ have : (f x, min (g z) (g x)) ∈ u ×ˢ v := ⟨xu, A2⟩ calc y < f x + min (g z) (g x) := h this _ ≤ f z + g z := add_le_add (hx₁ (f z)) (min_le_left _ _) · simp only [not_exists, not_lt] at hx₁ hx₂ apply Filter.Eventually.of_forall intro z have : (f x, g x) ∈ u ×ˢ v := ⟨xu, xv⟩ calc y < f x + g x := h this _ ≤ f z + g z := add_le_add (hx₁ (f z)) (hx₂ (g z)) /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem LowerSemicontinuousAt.add' {f g : α → γ} (hf : LowerSemicontinuousAt f x) (hg : LowerSemicontinuousAt g x) (hcont : ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : LowerSemicontinuousAt (fun z => f z + g z) x := by simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at * exact hf.add' hg hcont /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem LowerSemicontinuousOn.add' {f g : α → γ} (hf : LowerSemicontinuousOn f s) (hg : LowerSemicontinuousOn g s) (hcont : ∀ x ∈ s, ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : LowerSemicontinuousOn (fun z => f z + g z) s := fun x hx => (hf x hx).add' (hg x hx) (hcont x hx) /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem LowerSemicontinuous.add' {f g : α → γ} (hf : LowerSemicontinuous f) (hg : LowerSemicontinuous g) (hcont : ∀ x, ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : LowerSemicontinuous fun z => f z + g z := fun x => (hf x).add' (hg x) (hcont x) variable [ContinuousAdd γ] /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem LowerSemicontinuousWithinAt.add {f g : α → γ} (hf : LowerSemicontinuousWithinAt f s x) (hg : LowerSemicontinuousWithinAt g s x) : LowerSemicontinuousWithinAt (fun z => f z + g z) s x := hf.add' hg continuous_add.continuousAt /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem LowerSemicontinuousAt.add {f g : α → γ} (hf : LowerSemicontinuousAt f x) (hg : LowerSemicontinuousAt g x) : LowerSemicontinuousAt (fun z => f z + g z) x := hf.add' hg continuous_add.continuousAt /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem LowerSemicontinuousOn.add {f g : α → γ} (hf : LowerSemicontinuousOn f s) (hg : LowerSemicontinuousOn g s) : LowerSemicontinuousOn (fun z => f z + g z) s := hf.add' hg fun _x _hx => continuous_add.continuousAt /-- The sum of two lower semicontinuous functions is lower semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem LowerSemicontinuous.add {f g : α → γ} (hf : LowerSemicontinuous f) (hg : LowerSemicontinuous g) : LowerSemicontinuous fun z => f z + g z := hf.add' hg fun _x => continuous_add.continuousAt theorem lowerSemicontinuousWithinAt_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, LowerSemicontinuousWithinAt (f i) s x) : LowerSemicontinuousWithinAt (fun z => ∑ i ∈ a, f i z) s x := by classical induction a using Finset.induction_on with | empty => exact lowerSemicontinuousWithinAt_const | insert _ _ ia IH => simp only [ia, Finset.sum_insert, not_false_iff] exact LowerSemicontinuousWithinAt.add (ha _ (Finset.mem_insert_self ..)) (IH fun j ja => ha j (Finset.mem_insert_of_mem ja)) theorem lowerSemicontinuousAt_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, LowerSemicontinuousAt (f i) x) : LowerSemicontinuousAt (fun z => ∑ i ∈ a, f i z) x := by simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at * exact lowerSemicontinuousWithinAt_sum ha theorem lowerSemicontinuousOn_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, LowerSemicontinuousOn (f i) s) : LowerSemicontinuousOn (fun z => ∑ i ∈ a, f i z) s := fun x hx => lowerSemicontinuousWithinAt_sum fun i hi => ha i hi x hx theorem lowerSemicontinuous_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, LowerSemicontinuous (f i)) : LowerSemicontinuous fun z => ∑ i ∈ a, f i z := fun x => lowerSemicontinuousAt_sum fun i hi => ha i hi x end /-! #### Supremum -/ section variable {α : Type*} {β : Type*} [TopologicalSpace α] [LinearOrder β] {f g : α → β} {s : Set α} {a : α} theorem LowerSemicontinuousWithinAt.sup (hf : LowerSemicontinuousWithinAt f s a) (hg : LowerSemicontinuousWithinAt g s a) : LowerSemicontinuousWithinAt (fun x ↦ f x ⊔ g x) s a := by intro b hb simp only [lt_sup_iff] at hb ⊢ rcases hb with hb | hb · filter_upwards [hf b hb] with x using Or.intro_left _ · filter_upwards [hg b hb] with x using Or.intro_right _ theorem LowerSemicontinuousAt.sup (hf : LowerSemicontinuousAt f a) (hg : LowerSemicontinuousAt g a) : LowerSemicontinuousAt (fun x ↦ f x ⊔ g x) a := by rw [← lowerSemicontinuousWithinAt_univ_iff] at * exact hf.sup hg theorem LowerSemicontinuousOn.sup (hf : LowerSemicontinuousOn f s) (hg : LowerSemicontinuousOn g s) : LowerSemicontinuousOn (fun x ↦ f x ⊔ g x) s := fun a ha ↦ (hf a ha).sup (hg a ha) theorem LowerSemicontinuous.sup (hf : LowerSemicontinuous f) (hg : LowerSemicontinuous g) : LowerSemicontinuous fun x ↦ f x ⊔ g x := fun a ↦ (hf a).sup (hg a) theorem LowerSemicontinuousWithinAt.inf (hf : LowerSemicontinuousWithinAt f s a) (hg : LowerSemicontinuousWithinAt g s a) : LowerSemicontinuousWithinAt (fun x ↦ f x ⊓ g x) s a := by intro b hb simp only [lt_inf_iff] at hb ⊢ exact Eventually.and (hf b hb.1) (hg b hb.2) theorem LowerSemicontinuousAt.inf (hf : LowerSemicontinuousAt f a) (hg : LowerSemicontinuousAt g a) : LowerSemicontinuousAt (fun x ↦ f x ⊓ g x) a := by rw [← lowerSemicontinuousWithinAt_univ_iff] at * exact hf.inf hg theorem LowerSemicontinuousOn.inf (hf : LowerSemicontinuousOn f s) (hg : LowerSemicontinuousOn g s) : LowerSemicontinuousOn (fun x ↦ f x ⊓ g x) s := fun a ha ↦ (hf a ha).inf (hg a ha) theorem LowerSemicontinuous.inf (hf : LowerSemicontinuous f) (hg : LowerSemicontinuous g) : LowerSemicontinuous fun x ↦ f x ⊓ g x := fun a ↦ (hf a).inf (hg a) variable {ι : Type*} {f : ι → α → β} {a : α} {I : Set ι} end section variable {ι : Sort*} {δ δ' : Type*} [CompleteLinearOrder δ] [ConditionallyCompleteLinearOrder δ'] theorem lowerSemicontinuousWithinAt_ciSup {f : ι → α → δ'} (bdd : ∀ᶠ y in 𝓝[s] x, BddAbove (range fun i => f i y)) (h : ∀ i, LowerSemicontinuousWithinAt (f i) s x) : LowerSemicontinuousWithinAt (fun x' => ⨆ i, f i x') s x := by cases isEmpty_or_nonempty ι · simpa only [iSup_of_empty'] using lowerSemicontinuousWithinAt_const · intro y hy rcases exists_lt_of_lt_ciSup hy with ⟨i, hi⟩ filter_upwards [h i y hi, bdd] with y hy hy' using hy.trans_le (le_ciSup hy' i) theorem lowerSemicontinuousWithinAt_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuousWithinAt (f i) s x) : LowerSemicontinuousWithinAt (fun x' => ⨆ i, f i x') s x := lowerSemicontinuousWithinAt_ciSup (by simp) h theorem lowerSemicontinuousWithinAt_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, LowerSemicontinuousWithinAt (f i hi) s x) : LowerSemicontinuousWithinAt (fun x' => ⨆ (i) (hi), f i hi x') s x := lowerSemicontinuousWithinAt_iSup fun i => lowerSemicontinuousWithinAt_iSup fun hi => h i hi theorem lowerSemicontinuousAt_ciSup {f : ι → α → δ'} (bdd : ∀ᶠ y in 𝓝 x, BddAbove (range fun i => f i y)) (h : ∀ i, LowerSemicontinuousAt (f i) x) : LowerSemicontinuousAt (fun x' => ⨆ i, f i x') x := by simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at * rw [← nhdsWithin_univ] at bdd exact lowerSemicontinuousWithinAt_ciSup bdd h theorem lowerSemicontinuousAt_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuousAt (f i) x) : LowerSemicontinuousAt (fun x' => ⨆ i, f i x') x := lowerSemicontinuousAt_ciSup (by simp) h theorem lowerSemicontinuousAt_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, LowerSemicontinuousAt (f i hi) x) : LowerSemicontinuousAt (fun x' => ⨆ (i) (hi), f i hi x') x := lowerSemicontinuousAt_iSup fun i => lowerSemicontinuousAt_iSup fun hi => h i hi theorem lowerSemicontinuousOn_ciSup {f : ι → α → δ'} (bdd : ∀ x ∈ s, BddAbove (range fun i => f i x)) (h : ∀ i, LowerSemicontinuousOn (f i) s) : LowerSemicontinuousOn (fun x' => ⨆ i, f i x') s := fun x hx => lowerSemicontinuousWithinAt_ciSup (eventually_nhdsWithin_of_forall bdd) fun i => h i x hx theorem lowerSemicontinuousOn_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuousOn (f i) s) : LowerSemicontinuousOn (fun x' => ⨆ i, f i x') s := lowerSemicontinuousOn_ciSup (by simp) h theorem lowerSemicontinuousOn_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, LowerSemicontinuousOn (f i hi) s) : LowerSemicontinuousOn (fun x' => ⨆ (i) (hi), f i hi x') s := lowerSemicontinuousOn_iSup fun i => lowerSemicontinuousOn_iSup fun hi => h i hi theorem lowerSemicontinuous_ciSup {f : ι → α → δ'} (bdd : ∀ x, BddAbove (range fun i => f i x)) (h : ∀ i, LowerSemicontinuous (f i)) : LowerSemicontinuous fun x' => ⨆ i, f i x' := fun x => lowerSemicontinuousAt_ciSup (Eventually.of_forall bdd) fun i => h i x theorem lowerSemicontinuous_iSup {f : ι → α → δ} (h : ∀ i, LowerSemicontinuous (f i)) : LowerSemicontinuous fun x' => ⨆ i, f i x' := lowerSemicontinuous_ciSup (by simp) h theorem lowerSemicontinuous_biSup {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, LowerSemicontinuous (f i hi)) : LowerSemicontinuous fun x' => ⨆ (i) (hi), f i hi x' := lowerSemicontinuous_iSup fun i => lowerSemicontinuous_iSup fun hi => h i hi end /-! #### Infinite sums -/ section variable {ι : Type*} theorem lowerSemicontinuousWithinAt_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuousWithinAt (f i) s x) : LowerSemicontinuousWithinAt (fun x' => ∑' i, f i x') s x := by simp_rw [ENNReal.tsum_eq_iSup_sum] refine lowerSemicontinuousWithinAt_iSup fun b => ?_ exact lowerSemicontinuousWithinAt_sum fun i _hi => h i theorem lowerSemicontinuousAt_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuousAt (f i) x) : LowerSemicontinuousAt (fun x' => ∑' i, f i x') x := by simp_rw [← lowerSemicontinuousWithinAt_univ_iff] at * exact lowerSemicontinuousWithinAt_tsum h theorem lowerSemicontinuousOn_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuousOn (f i) s) : LowerSemicontinuousOn (fun x' => ∑' i, f i x') s := fun x hx => lowerSemicontinuousWithinAt_tsum fun i => h i x hx theorem lowerSemicontinuous_tsum {f : ι → α → ℝ≥0∞} (h : ∀ i, LowerSemicontinuous (f i)) : LowerSemicontinuous fun x' => ∑' i, f i x' := fun x => lowerSemicontinuousAt_tsum fun i => h i x end /-! ### Upper semicontinuous functions -/ /-! #### Basic dot notation interface for upper semicontinuity -/ theorem UpperSemicontinuousWithinAt.mono (h : UpperSemicontinuousWithinAt f s x) (hst : t ⊆ s) : UpperSemicontinuousWithinAt f t x := fun y hy => Filter.Eventually.filter_mono (nhdsWithin_mono _ hst) (h y hy) theorem UpperSemicontinuousWithinAt.congr_of_eventuallyEq {a : α} (h : UpperSemicontinuousWithinAt f s a) (has : a ∈ s) (hfg : ∀ᶠ x in nhdsWithin a s, f x = g x) : UpperSemicontinuousWithinAt g s a := LowerSemicontinuousWithinAt.congr_of_eventuallyEq (β := βᵒᵈ) h has hfg theorem upperSemicontinuousWithinAt_univ_iff : UpperSemicontinuousWithinAt f univ x ↔ UpperSemicontinuousAt f x := by simp [UpperSemicontinuousWithinAt, UpperSemicontinuousAt, nhdsWithin_univ] theorem UpperSemicontinuousAt.upperSemicontinuousWithinAt (s : Set α) (h : UpperSemicontinuousAt f x) : UpperSemicontinuousWithinAt f s x := fun y hy => Filter.Eventually.filter_mono nhdsWithin_le_nhds (h y hy) theorem UpperSemicontinuousOn.upperSemicontinuousWithinAt (h : UpperSemicontinuousOn f s) (hx : x ∈ s) : UpperSemicontinuousWithinAt f s x := h x hx theorem UpperSemicontinuousOn.mono (h : UpperSemicontinuousOn f s) (hst : t ⊆ s) : UpperSemicontinuousOn f t := fun x hx => (h x (hst hx)).mono hst theorem upperSemicontinuousOn_univ_iff : UpperSemicontinuousOn f univ ↔ UpperSemicontinuous f := by simp [UpperSemicontinuousOn, UpperSemicontinuous, upperSemicontinuousWithinAt_univ_iff] theorem UpperSemicontinuous.upperSemicontinuousAt (h : UpperSemicontinuous f) (x : α) : UpperSemicontinuousAt f x := h x theorem UpperSemicontinuous.upperSemicontinuousWithinAt (h : UpperSemicontinuous f) (s : Set α) (x : α) : UpperSemicontinuousWithinAt f s x := (h x).upperSemicontinuousWithinAt s theorem UpperSemicontinuous.upperSemicontinuousOn (h : UpperSemicontinuous f) (s : Set α) : UpperSemicontinuousOn f s := fun x _hx => h.upperSemicontinuousWithinAt s x /-! #### Constants -/ theorem upperSemicontinuousWithinAt_const : UpperSemicontinuousWithinAt (fun _x => z) s x := fun _y hy => Filter.Eventually.of_forall fun _x => hy theorem upperSemicontinuousAt_const : UpperSemicontinuousAt (fun _x => z) x := fun _y hy => Filter.Eventually.of_forall fun _x => hy theorem upperSemicontinuousOn_const : UpperSemicontinuousOn (fun _x => z) s := fun _x _hx => upperSemicontinuousWithinAt_const theorem upperSemicontinuous_const : UpperSemicontinuous fun _x : α => z := fun _x => upperSemicontinuousAt_const /-! ### upper bounds -/ section variable {α : Type*} [TopologicalSpace α] {β : Type*} [LinearOrder β] {f : α → β} {s : Set α} /-- An upper semicontinuous function attains its upper bound on a nonempty compact set. -/ theorem UpperSemicontinuousOn.exists_isMaxOn {s : Set α} (ne_s : s.Nonempty) (hs : IsCompact s) (hf : UpperSemicontinuousOn f s) : ∃ a ∈ s, IsMaxOn f s a := LowerSemicontinuousOn.exists_isMinOn (β := βᵒᵈ) ne_s hs hf /-- An upper semicontinuous function is bounded above on a compact set. -/ theorem UpperSemicontinuousOn.bddAbove_of_isCompact [Nonempty β] {s : Set α} (hs : IsCompact s) (hf : UpperSemicontinuousOn f s) : BddAbove (f '' s) := LowerSemicontinuousOn.bddBelow_of_isCompact (β := βᵒᵈ) hs hf end /-! #### Indicators -/ section variable [Zero β] theorem IsOpen.upperSemicontinuous_indicator (hs : IsOpen s) (hy : y ≤ 0) : UpperSemicontinuous (indicator s fun _x => y) := @IsOpen.lowerSemicontinuous_indicator α _ βᵒᵈ _ s y _ hs hy theorem IsOpen.upperSemicontinuousOn_indicator (hs : IsOpen s) (hy : y ≤ 0) : UpperSemicontinuousOn (indicator s fun _x => y) t := (hs.upperSemicontinuous_indicator hy).upperSemicontinuousOn t theorem IsOpen.upperSemicontinuousAt_indicator (hs : IsOpen s) (hy : y ≤ 0) : UpperSemicontinuousAt (indicator s fun _x => y) x := (hs.upperSemicontinuous_indicator hy).upperSemicontinuousAt x theorem IsOpen.upperSemicontinuousWithinAt_indicator (hs : IsOpen s) (hy : y ≤ 0) : UpperSemicontinuousWithinAt (indicator s fun _x => y) t x := (hs.upperSemicontinuous_indicator hy).upperSemicontinuousWithinAt t x theorem IsClosed.upperSemicontinuous_indicator (hs : IsClosed s) (hy : 0 ≤ y) : UpperSemicontinuous (indicator s fun _x => y) := @IsClosed.lowerSemicontinuous_indicator α _ βᵒᵈ _ s y _ hs hy theorem IsClosed.upperSemicontinuousOn_indicator (hs : IsClosed s) (hy : 0 ≤ y) : UpperSemicontinuousOn (indicator s fun _x => y) t := (hs.upperSemicontinuous_indicator hy).upperSemicontinuousOn t theorem IsClosed.upperSemicontinuousAt_indicator (hs : IsClosed s) (hy : 0 ≤ y) : UpperSemicontinuousAt (indicator s fun _x => y) x := (hs.upperSemicontinuous_indicator hy).upperSemicontinuousAt x theorem IsClosed.upperSemicontinuousWithinAt_indicator (hs : IsClosed s) (hy : 0 ≤ y) : UpperSemicontinuousWithinAt (indicator s fun _x => y) t x := (hs.upperSemicontinuous_indicator hy).upperSemicontinuousWithinAt t x end /-! #### Relationship with continuity -/ theorem upperSemicontinuous_iff_isOpen_preimage : UpperSemicontinuous f ↔ ∀ y, IsOpen (f ⁻¹' Iio y) := ⟨fun H y => isOpen_iff_mem_nhds.2 fun x hx => H x y hx, fun H _x y y_lt => IsOpen.mem_nhds (H y) y_lt⟩ theorem UpperSemicontinuous.isOpen_preimage (hf : UpperSemicontinuous f) (y : β) : IsOpen (f ⁻¹' Iio y) := upperSemicontinuous_iff_isOpen_preimage.1 hf y section variable {γ : Type*} [LinearOrder γ] theorem upperSemicontinuous_iff_isClosed_preimage {f : α → γ} : UpperSemicontinuous f ↔ ∀ y, IsClosed (f ⁻¹' Ici y) := by rw [upperSemicontinuous_iff_isOpen_preimage] simp only [← isOpen_compl_iff, ← preimage_compl, compl_Ici] theorem UpperSemicontinuous.isClosed_preimage {f : α → γ} (hf : UpperSemicontinuous f) (y : γ) : IsClosed (f ⁻¹' Ici y) := upperSemicontinuous_iff_isClosed_preimage.1 hf y variable [TopologicalSpace γ] [OrderTopology γ] theorem ContinuousWithinAt.upperSemicontinuousWithinAt {f : α → γ} (h : ContinuousWithinAt f s x) : UpperSemicontinuousWithinAt f s x := fun _y hy => h (Iio_mem_nhds hy) theorem ContinuousAt.upperSemicontinuousAt {f : α → γ} (h : ContinuousAt f x) : UpperSemicontinuousAt f x := fun _y hy => h (Iio_mem_nhds hy) theorem ContinuousOn.upperSemicontinuousOn {f : α → γ} (h : ContinuousOn f s) : UpperSemicontinuousOn f s := fun x hx => (h x hx).upperSemicontinuousWithinAt theorem Continuous.upperSemicontinuous {f : α → γ} (h : Continuous f) : UpperSemicontinuous f := fun _x => h.continuousAt.upperSemicontinuousAt end /-! #### Equivalent definitions -/ section variable {γ : Type*} [CompleteLinearOrder γ] theorem upperSemicontinuousWithinAt_iff_limsup_le {f : α → γ} : UpperSemicontinuousWithinAt f s x ↔ limsup f (𝓝[s] x) ≤ f x := lowerSemicontinuousWithinAt_iff_le_liminf (γ := γᵒᵈ) alias ⟨UpperSemicontinuousWithinAt.limsup_le, _⟩ := upperSemicontinuousWithinAt_iff_limsup_le theorem upperSemicontinuousAt_iff_limsup_le {f : α → γ} : UpperSemicontinuousAt f x ↔ limsup f (𝓝 x) ≤ f x := lowerSemicontinuousAt_iff_le_liminf (γ := γᵒᵈ) alias ⟨UpperSemicontinuousAt.limsup_le, _⟩ := upperSemicontinuousAt_iff_limsup_le theorem upperSemicontinuous_iff_limsup_le {f : α → γ} : UpperSemicontinuous f ↔ ∀ x, limsup f (𝓝 x) ≤ f x := lowerSemicontinuous_iff_le_liminf (γ := γᵒᵈ) alias ⟨UpperSemicontinuous.limsup_le, _⟩ := upperSemicontinuous_iff_limsup_le theorem upperSemicontinuousOn_iff_limsup_le {f : α → γ} : UpperSemicontinuousOn f s ↔ ∀ x ∈ s, limsup f (𝓝[s] x) ≤ f x := lowerSemicontinuousOn_iff_le_liminf (γ := γᵒᵈ) alias ⟨UpperSemicontinuousOn.limsup_le, _⟩ := upperSemicontinuousOn_iff_limsup_le end section variable {γ : Type*} [LinearOrder γ] [TopologicalSpace γ] [ClosedIicTopology γ] theorem upperSemicontinuousOn_iff_isClosed_hypograph {f : α → γ} (hs : IsClosed s) : UpperSemicontinuousOn f s ↔ IsClosed {p : α × γ | p.1 ∈ s ∧ p.2 ≤ f p.1} := lowerSemicontinuousOn_iff_isClosed_epigraph hs (γ := γᵒᵈ) theorem upperSemicontinuous_iff_IsClosed_hypograph {f : α → γ} : UpperSemicontinuous f ↔ IsClosed {p : α × γ | p.2 ≤ f p.1} := lowerSemicontinuous_iff_isClosed_epigraph (γ := γᵒᵈ) alias ⟨UpperSemicontinuous.IsClosed_hypograph, _⟩ := upperSemicontinuous_iff_IsClosed_hypograph end /-! ### Composition -/ section variable {α : Type*} [TopologicalSpace α] variable {β : Type*} [LinearOrder β] variable {γ : Type*} [TopologicalSpace γ] variable {f : α → β} {g : γ → α} {s : Set α} {a : α} {c : γ} {t : Set γ} theorem UpperSemicontinuousWithinAt.comp (hf : UpperSemicontinuousWithinAt f s (g c)) (hg : ContinuousWithinAt g t c) (hg' : MapsTo g t s) : UpperSemicontinuousWithinAt (f ∘ g) t c := LowerSemicontinuousWithinAt.comp (β := βᵒᵈ) hf hg hg' theorem UpperSemicontinuousAt.comp (hf : UpperSemicontinuousAt f (g c)) (hg : ContinuousAt g c) : UpperSemicontinuousAt (f ∘ g) c := LowerSemicontinuousAt.comp (β := βᵒᵈ) hf hg theorem UpperSemicontinuousOn.comp (hf : UpperSemicontinuousOn f s) (hg : ContinuousOn g t) (hg' : MapsTo g t s) : UpperSemicontinuousOn (f ∘ g) t := LowerSemicontinuousOn.comp (β := βᵒᵈ) hf hg hg' theorem UpperSemicontinuous.comp (hf : UpperSemicontinuous f) (hg : Continuous g) : UpperSemicontinuous (f ∘ g) := LowerSemicontinuous.comp (β := βᵒᵈ) hf hg @[simp] theorem upperSemicontinuousOn_iff_restrict {s : Set α} : UpperSemicontinuous (s.restrict f) ↔ UpperSemicontinuousOn f s := lowerSemicontinuous_restrict_iff (β := βᵒᵈ) theorem upperSemicontinuousOn_iff_preimage_Iio : UpperSemicontinuousOn f s ↔ ∀ b, ∃ u : Set α, IsOpen u ∧ s ∩ f ⁻¹' Set.Iio b = s ∩ u := lowerSemicontinuousOn_iff_preimage_Ioi (β := βᵒᵈ) theorem upperSemicontinuousOn_iff_preimage_Ici : UpperSemicontinuousOn f s ↔ ∀ b, ∃ v : Set α, IsClosed v ∧ s ∩ f ⁻¹' Set.Ici b = s ∩ v := lowerSemicontinuousOn_iff_preimage_Iic (γ := βᵒᵈ) end section variable {γ : Type*} [LinearOrder γ] [TopologicalSpace γ] [OrderTopology γ] variable {δ : Type*} [LinearOrder δ] [TopologicalSpace δ] [OrderTopology δ] variable {ι : Type*} [TopologicalSpace ι] theorem ContinuousAt.comp_upperSemicontinuousWithinAt {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : UpperSemicontinuousWithinAt f s x) (gmon : Monotone g) : UpperSemicontinuousWithinAt (g ∘ f) s x := @ContinuousAt.comp_lowerSemicontinuousWithinAt α _ x s γᵒᵈ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon.dual theorem ContinuousAt.comp_upperSemicontinuousAt {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : UpperSemicontinuousAt f x) (gmon : Monotone g) : UpperSemicontinuousAt (g ∘ f) x := @ContinuousAt.comp_lowerSemicontinuousAt α _ x γᵒᵈ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon.dual theorem Continuous.comp_upperSemicontinuousOn {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : UpperSemicontinuousOn f s) (gmon : Monotone g) : UpperSemicontinuousOn (g ∘ f) s := fun x hx => hg.continuousAt.comp_upperSemicontinuousWithinAt (hf x hx) gmon theorem Continuous.comp_upperSemicontinuous {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : UpperSemicontinuous f) (gmon : Monotone g) : UpperSemicontinuous (g ∘ f) := fun x => hg.continuousAt.comp_upperSemicontinuousAt (hf x) gmon theorem ContinuousAt.comp_upperSemicontinuousWithinAt_antitone {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : UpperSemicontinuousWithinAt f s x) (gmon : Antitone g) : LowerSemicontinuousWithinAt (g ∘ f) s x := @ContinuousAt.comp_upperSemicontinuousWithinAt α _ x s γ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon theorem ContinuousAt.comp_upperSemicontinuousAt_antitone {g : γ → δ} {f : α → γ} (hg : ContinuousAt g (f x)) (hf : UpperSemicontinuousAt f x) (gmon : Antitone g) : LowerSemicontinuousAt (g ∘ f) x := @ContinuousAt.comp_upperSemicontinuousAt α _ x γ _ _ _ δᵒᵈ _ _ _ g f hg hf gmon theorem Continuous.comp_upperSemicontinuousOn_antitone {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : UpperSemicontinuousOn f s) (gmon : Antitone g) : LowerSemicontinuousOn (g ∘ f) s := fun x hx => hg.continuousAt.comp_upperSemicontinuousWithinAt_antitone (hf x hx) gmon theorem Continuous.comp_upperSemicontinuous_antitone {g : γ → δ} {f : α → γ} (hg : Continuous g) (hf : UpperSemicontinuous f) (gmon : Antitone g) : LowerSemicontinuous (g ∘ f) := fun x => hg.continuousAt.comp_upperSemicontinuousAt_antitone (hf x) gmon theorem UpperSemicontinuousAt.comp_continuousAt {f : α → β} {g : ι → α} {x : ι} (hf : UpperSemicontinuousAt f (g x)) (hg : ContinuousAt g x) : UpperSemicontinuousAt (fun x ↦ f (g x)) x := fun _ lt ↦ hg.eventually (hf _ lt) theorem UpperSemicontinuousAt.comp_continuousAt_of_eq {f : α → β} {g : ι → α} {y : α} {x : ι} (hf : UpperSemicontinuousAt f y) (hg : ContinuousAt g x) (hy : g x = y) : UpperSemicontinuousAt (fun x ↦ f (g x)) x := by rw [← hy] at hf exact comp_continuousAt hf hg theorem UpperSemicontinuous.comp_continuous {f : α → β} {g : ι → α} (hf : UpperSemicontinuous f) (hg : Continuous g) : UpperSemicontinuous fun x ↦ f (g x) := fun x ↦ (hf (g x)).comp_continuousAt hg.continuousAt end /-! #### Addition -/ section variable {ι : Type*} {γ : Type*} [AddCommMonoid γ] [LinearOrder γ] [IsOrderedAddMonoid γ] [TopologicalSpace γ] [OrderTopology γ] /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem UpperSemicontinuousWithinAt.add' {f g : α → γ} (hf : UpperSemicontinuousWithinAt f s x) (hg : UpperSemicontinuousWithinAt g s x) (hcont : ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : UpperSemicontinuousWithinAt (fun z => f z + g z) s x := LowerSemicontinuousWithinAt.add' (γ := γᵒᵈ) hf hg hcont /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem UpperSemicontinuousAt.add' {f g : α → γ} (hf : UpperSemicontinuousAt f x) (hg : UpperSemicontinuousAt g x) (hcont : ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : UpperSemicontinuousAt (fun z => f z + g z) x := by simp_rw [← upperSemicontinuousWithinAt_univ_iff] at * exact hf.add' hg hcont /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem UpperSemicontinuousOn.add' {f g : α → γ} (hf : UpperSemicontinuousOn f s) (hg : UpperSemicontinuousOn g s) (hcont : ∀ x ∈ s, ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : UpperSemicontinuousOn (fun z => f z + g z) s := fun x hx => (hf x hx).add' (hg x hx) (hcont x hx) /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with an explicit continuity assumption on addition, for application to `EReal`. The unprimed version of the lemma uses `[ContinuousAdd]`. -/ theorem UpperSemicontinuous.add' {f g : α → γ} (hf : UpperSemicontinuous f) (hg : UpperSemicontinuous g) (hcont : ∀ x, ContinuousAt (fun p : γ × γ => p.1 + p.2) (f x, g x)) : UpperSemicontinuous fun z => f z + g z := fun x => (hf x).add' (hg x) (hcont x) variable [ContinuousAdd γ] /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem UpperSemicontinuousWithinAt.add {f g : α → γ} (hf : UpperSemicontinuousWithinAt f s x) (hg : UpperSemicontinuousWithinAt g s x) : UpperSemicontinuousWithinAt (fun z => f z + g z) s x := hf.add' hg continuous_add.continuousAt /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem UpperSemicontinuousAt.add {f g : α → γ} (hf : UpperSemicontinuousAt f x) (hg : UpperSemicontinuousAt g x) : UpperSemicontinuousAt (fun z => f z + g z) x := hf.add' hg continuous_add.continuousAt /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem UpperSemicontinuousOn.add {f g : α → γ} (hf : UpperSemicontinuousOn f s) (hg : UpperSemicontinuousOn g s) : UpperSemicontinuousOn (fun z => f z + g z) s := hf.add' hg fun _x _hx => continuous_add.continuousAt /-- The sum of two upper semicontinuous functions is upper semicontinuous. Formulated with `[ContinuousAdd]`. The primed version of the lemma uses an explicit continuity assumption on addition, for application to `EReal`. -/ theorem UpperSemicontinuous.add {f g : α → γ} (hf : UpperSemicontinuous f) (hg : UpperSemicontinuous g) : UpperSemicontinuous fun z => f z + g z := hf.add' hg fun _x => continuous_add.continuousAt theorem upperSemicontinuousWithinAt_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, UpperSemicontinuousWithinAt (f i) s x) : UpperSemicontinuousWithinAt (fun z => ∑ i ∈ a, f i z) s x := lowerSemicontinuousWithinAt_sum (γ := γᵒᵈ) ha theorem upperSemicontinuousAt_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, UpperSemicontinuousAt (f i) x) : UpperSemicontinuousAt (fun z => ∑ i ∈ a, f i z) x := by simp_rw [← upperSemicontinuousWithinAt_univ_iff] at * exact upperSemicontinuousWithinAt_sum ha theorem upperSemicontinuousOn_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, UpperSemicontinuousOn (f i) s) : UpperSemicontinuousOn (fun z => ∑ i ∈ a, f i z) s := fun x hx => upperSemicontinuousWithinAt_sum fun i hi => ha i hi x hx theorem upperSemicontinuous_sum {f : ι → α → γ} {a : Finset ι} (ha : ∀ i ∈ a, UpperSemicontinuous (f i)) : UpperSemicontinuous fun z => ∑ i ∈ a, f i z := fun x => upperSemicontinuousAt_sum fun i hi => ha i hi x end /-! #### Infimum -/ section variable {α : Type*} {β : Type*} [TopologicalSpace α] [LinearOrder β] {f g : α → β} {s : Set α} {a : α} theorem UpperSemicontinuousWithinAt.inf (hf : UpperSemicontinuousWithinAt f s a) (hg : UpperSemicontinuousWithinAt g s a) : UpperSemicontinuousWithinAt (fun x ↦ f x ⊓ g x) s a := LowerSemicontinuousWithinAt.sup (β := βᵒᵈ) hf hg theorem UpperSemicontinuousAt.inf (hf : UpperSemicontinuousAt f a) (hg : UpperSemicontinuousAt g a) : UpperSemicontinuousAt (fun x ↦ f x ⊓ g x) a := LowerSemicontinuousAt.sup (β := βᵒᵈ) hf hg theorem UpperSemicontinuousOn.inf (hf : UpperSemicontinuousOn f s) (hg : UpperSemicontinuousOn g s) : UpperSemicontinuousOn (fun x ↦ f x ⊓ g x) s := LowerSemicontinuousOn.sup (β := βᵒᵈ) hf hg theorem UpperSemicontinuous.inf (hf : UpperSemicontinuous f) (hg : UpperSemicontinuous g) : UpperSemicontinuous (fun x ↦ f x ⊓ g x) := LowerSemicontinuous.sup (β := βᵒᵈ) hf hg theorem UpperSemicontinuousWithinAt.sup (hf : UpperSemicontinuousWithinAt f s a) (hg : UpperSemicontinuousWithinAt g s a) : UpperSemicontinuousWithinAt (fun x ↦ f x ⊔ g x) s a := LowerSemicontinuousWithinAt.inf (β := βᵒᵈ) hf hg theorem UpperSemicontinuousAt.sup (hf : UpperSemicontinuousAt f a) (hg : UpperSemicontinuousAt g a) : UpperSemicontinuousAt (fun x ↦ f x ⊔ g x) a := LowerSemicontinuousAt.inf (β := βᵒᵈ) hf hg theorem UpperSemicontinuousOn.sup (hf : UpperSemicontinuousOn f s) (hg : UpperSemicontinuousOn g s) : UpperSemicontinuousOn (fun x ↦ f x ⊔ g x) s := LowerSemicontinuousOn.inf (β := βᵒᵈ) hf hg theorem UpperSemicontinuous.sup (hf : UpperSemicontinuous f) (hg : UpperSemicontinuous g) : UpperSemicontinuous fun x ↦ f x ⊔ g x := LowerSemicontinuous.inf (β := βᵒᵈ) hf hg end section variable {ι : Sort*} {δ δ' : Type*} [CompleteLinearOrder δ] [ConditionallyCompleteLinearOrder δ'] theorem upperSemicontinuousWithinAt_ciInf {f : ι → α → δ'} (bdd : ∀ᶠ y in 𝓝[s] x, BddBelow (range fun i => f i y)) (h : ∀ i, UpperSemicontinuousWithinAt (f i) s x) : UpperSemicontinuousWithinAt (fun x' => ⨅ i, f i x') s x := @lowerSemicontinuousWithinAt_ciSup α _ x s ι δ'ᵒᵈ _ f bdd h theorem upperSemicontinuousWithinAt_iInf {f : ι → α → δ} (h : ∀ i, UpperSemicontinuousWithinAt (f i) s x) : UpperSemicontinuousWithinAt (fun x' => ⨅ i, f i x') s x := @lowerSemicontinuousWithinAt_iSup α _ x s ι δᵒᵈ _ f h theorem upperSemicontinuousWithinAt_biInf {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, UpperSemicontinuousWithinAt (f i hi) s x) : UpperSemicontinuousWithinAt (fun x' => ⨅ (i) (hi), f i hi x') s x := upperSemicontinuousWithinAt_iInf fun i => upperSemicontinuousWithinAt_iInf fun hi => h i hi theorem upperSemicontinuousAt_ciInf {f : ι → α → δ'} (bdd : ∀ᶠ y in 𝓝 x, BddBelow (range fun i => f i y)) (h : ∀ i, UpperSemicontinuousAt (f i) x) : UpperSemicontinuousAt (fun x' => ⨅ i, f i x') x := @lowerSemicontinuousAt_ciSup α _ x ι δ'ᵒᵈ _ f bdd h theorem upperSemicontinuousAt_iInf {f : ι → α → δ} (h : ∀ i, UpperSemicontinuousAt (f i) x) : UpperSemicontinuousAt (fun x' => ⨅ i, f i x') x := @lowerSemicontinuousAt_iSup α _ x ι δᵒᵈ _ f h theorem upperSemicontinuousAt_biInf {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, UpperSemicontinuousAt (f i hi) x) : UpperSemicontinuousAt (fun x' => ⨅ (i) (hi), f i hi x') x := upperSemicontinuousAt_iInf fun i => upperSemicontinuousAt_iInf fun hi => h i hi theorem upperSemicontinuousOn_ciInf {f : ι → α → δ'} (bdd : ∀ x ∈ s, BddBelow (range fun i => f i x)) (h : ∀ i, UpperSemicontinuousOn (f i) s) : UpperSemicontinuousOn (fun x' => ⨅ i, f i x') s := fun x hx => upperSemicontinuousWithinAt_ciInf (eventually_nhdsWithin_of_forall bdd) fun i => h i x hx theorem upperSemicontinuousOn_iInf {f : ι → α → δ} (h : ∀ i, UpperSemicontinuousOn (f i) s) : UpperSemicontinuousOn (fun x' => ⨅ i, f i x') s := fun x hx => upperSemicontinuousWithinAt_iInf fun i => h i x hx theorem upperSemicontinuousOn_biInf {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, UpperSemicontinuousOn (f i hi) s) : UpperSemicontinuousOn (fun x' => ⨅ (i) (hi), f i hi x') s := upperSemicontinuousOn_iInf fun i => upperSemicontinuousOn_iInf fun hi => h i hi theorem upperSemicontinuous_ciInf {f : ι → α → δ'} (bdd : ∀ x, BddBelow (range fun i => f i x)) (h : ∀ i, UpperSemicontinuous (f i)) : UpperSemicontinuous fun x' => ⨅ i, f i x' := fun x => upperSemicontinuousAt_ciInf (Eventually.of_forall bdd) fun i => h i x theorem upperSemicontinuous_iInf {f : ι → α → δ} (h : ∀ i, UpperSemicontinuous (f i)) : UpperSemicontinuous fun x' => ⨅ i, f i x' := fun x => upperSemicontinuousAt_iInf fun i => h i x theorem upperSemicontinuous_biInf {p : ι → Prop} {f : ∀ i, p i → α → δ} (h : ∀ i hi, UpperSemicontinuous (f i hi)) : UpperSemicontinuous fun x' => ⨅ (i) (hi), f i hi x' := upperSemicontinuous_iInf fun i => upperSemicontinuous_iInf fun hi => h i hi end section variable {γ : Type*} [LinearOrder γ] [TopologicalSpace γ] [OrderTopology γ] theorem continuousWithinAt_iff_lower_upperSemicontinuousWithinAt {f : α → γ} : ContinuousWithinAt f s x ↔ LowerSemicontinuousWithinAt f s x ∧ UpperSemicontinuousWithinAt f s x := by refine ⟨fun h => ⟨h.lowerSemicontinuousWithinAt, h.upperSemicontinuousWithinAt⟩, ?_⟩ rintro ⟨h₁, h₂⟩ intro v hv simp only [Filter.mem_map] by_cases! Hl : ∃ l, l < f x · rcases exists_Ioc_subset_of_mem_nhds hv Hl with ⟨l, lfx, hl⟩ by_cases! Hu : ∃ u, f x < u · rcases exists_Ico_subset_of_mem_nhds hv Hu with ⟨u, fxu, hu⟩ filter_upwards [h₁ l lfx, h₂ u fxu] with a lfa fau rcases le_or_gt (f a) (f x) with h | h · exact hl ⟨lfa, h⟩ · exact hu ⟨le_of_lt h, fau⟩ · filter_upwards [h₁ l lfx] with a lfa using hl ⟨lfa, Hu (f a)⟩ · by_cases! Hu : ∃ u, f x < u · rcases exists_Ico_subset_of_mem_nhds hv Hu with ⟨u, fxu, hu⟩ filter_upwards [h₂ u fxu] with a lfa apply hu exact ⟨Hl (f a), lfa⟩ · apply Filter.Eventually.of_forall intro a have : f a = f x := le_antisymm (Hu _) (Hl _) rw [this] exact mem_of_mem_nhds hv theorem continuousAt_iff_lower_upperSemicontinuousAt {f : α → γ} : ContinuousAt f x ↔ LowerSemicontinuousAt f x ∧ UpperSemicontinuousAt f x := by simp_rw [← continuousWithinAt_univ, ← lowerSemicontinuousWithinAt_univ_iff, ← upperSemicontinuousWithinAt_univ_iff, continuousWithinAt_iff_lower_upperSemicontinuousWithinAt] theorem continuousOn_iff_lower_upperSemicontinuousOn {f : α → γ} : ContinuousOn f s ↔ LowerSemicontinuousOn f s ∧ UpperSemicontinuousOn f s := by simp only [ContinuousOn, continuousWithinAt_iff_lower_upperSemicontinuousWithinAt] exact ⟨fun H => ⟨fun x hx => (H x hx).1, fun x hx => (H x hx).2⟩, fun H x hx => ⟨H.1 x hx, H.2 x hx⟩⟩ theorem continuous_iff_lower_upperSemicontinuous {f : α → γ} : Continuous f ↔ LowerSemicontinuous f ∧ UpperSemicontinuous f := by simp_rw [← continuousOn_univ, continuousOn_iff_lower_upperSemicontinuousOn, lowerSemicontinuousOn_univ_iff, upperSemicontinuousOn_univ_iff] end
.lake/packages/mathlib/Mathlib/Topology/Filter.lean
import Mathlib.Order.Filter.Lift import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.Separation.Basic /-! # Topology on the set of filters on a type This file introduces a topology on `Filter α`. It is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. This topology has the following important properties. * If `X` is a topological space, then the map `𝓝 : X → Filter X` is a topology inducing map. * In particular, it is a continuous map, so `𝓝 ∘ f` tends to `𝓝 (𝓝 a)` whenever `f` tends to `𝓝 a`. * If `X` is an ordered topological space with order topology and no max element, then `𝓝 ∘ f` tends to `𝓝 Filter.atTop` whenever `f` tends to `Filter.atTop`. * It turns `Filter X` into a T₀ space and the order on `Filter X` is the dual of the `specializationOrder (Filter X)`. ## Tags filter, topological space -/ open Set Filter TopologicalSpace open Filter Topology variable {ι : Sort*} {α β X Y : Type*} namespace Filter /-- The topology on `Filter α` is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. -/ instance : TopologicalSpace (Filter α) := generateFrom <| range <| Iic ∘ 𝓟 theorem isOpen_Iic_principal {s : Set α} : IsOpen (Iic (𝓟 s)) := GenerateOpen.basic _ (mem_range_self _) theorem isOpen_setOf_mem {s : Set α} : IsOpen { l : Filter α | s ∈ l } := by simpa only [Iic_principal] using isOpen_Iic_principal theorem isTopologicalBasis_Iic_principal : IsTopologicalBasis (range (Iic ∘ 𝓟 : Set α → Set (Filter α))) := { exists_subset_inter := by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ l hl exact ⟨Iic (𝓟 s) ∩ Iic (𝓟 t), ⟨s ∩ t, by simp⟩, hl, Subset.rfl⟩ sUnion_eq := sUnion_eq_univ_iff.2 fun _ => ⟨Iic ⊤, ⟨univ, congr_arg Iic principal_univ⟩, mem_Iic.2 le_top⟩ eq_generateFrom := rfl } theorem isOpen_iff {s : Set (Filter α)} : IsOpen s ↔ ∃ T : Set (Set α), s = ⋃ t ∈ T, Iic (𝓟 t) := isTopologicalBasis_Iic_principal.open_iff_eq_sUnion.trans <| by simp only [exists_subset_range_and_iff, sUnion_image, (· ∘ ·)] theorem nhds_eq (l : Filter α) : 𝓝 l = l.lift' (Iic ∘ 𝓟) := nhds_generateFrom.trans <| by simp only [mem_setOf_eq, @and_comm (l ∈ _), iInf_and, iInf_range, Filter.lift', Filter.lift, (· ∘ ·), mem_Iic, le_principal_iff] theorem nhds_eq' (l : Filter α) : 𝓝 l = l.lift' fun s => { l' | s ∈ l' } := by simpa only [Function.comp_def, Iic_principal] using nhds_eq l protected theorem tendsto_nhds {la : Filter α} {lb : Filter β} {f : α → Filter β} : Tendsto f la (𝓝 lb) ↔ ∀ s ∈ lb, ∀ᶠ a in la, s ∈ f a := by simp only [nhds_eq', tendsto_lift', mem_setOf_eq] protected theorem HasBasis.nhds {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => Iic (𝓟 (s i)) := by rw [nhds_eq] exact h.lift' monotone_principal.Iic protected theorem tendsto_pure_self (l : Filter X) : Tendsto (pure : X → Filter X) l (𝓝 l) := by rw [Filter.tendsto_nhds] exact fun s hs ↦ Eventually.mono hs fun x ↦ id /-- Neighborhoods of a countably generated filter is a countably generated filter. -/ instance {l : Filter α} [IsCountablyGenerated l] : IsCountablyGenerated (𝓝 l) := let ⟨_b, hb⟩ := l.exists_antitone_basis HasCountableBasis.isCountablyGenerated <| ⟨hb.nhds, Set.to_countable _⟩ theorem HasBasis.nhds' {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => { l' | s i ∈ l' } := by simpa only [Iic_principal] using h.nhds protected theorem mem_nhds_iff {l : Filter α} {S : Set (Filter α)} : S ∈ 𝓝 l ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ S := l.basis_sets.nhds.mem_iff theorem mem_nhds_iff' {l : Filter α} {S : Set (Filter α)} : S ∈ 𝓝 l ↔ ∃ t ∈ l, ∀ ⦃l' : Filter α⦄, t ∈ l' → l' ∈ S := l.basis_sets.nhds'.mem_iff @[simp] theorem nhds_bot : 𝓝 (⊥ : Filter α) = pure ⊥ := by simp [nhds_eq, Function.comp_def, lift'_bot monotone_principal.Iic] @[simp] theorem nhds_top : 𝓝 (⊤ : Filter α) = ⊤ := by simp [nhds_eq] @[simp] theorem nhds_principal (s : Set α) : 𝓝 (𝓟 s) = 𝓟 (Iic (𝓟 s)) := (hasBasis_principal s).nhds.eq_of_same_basis (hasBasis_principal _) @[simp] theorem nhds_pure (x : α) : 𝓝 (pure x : Filter α) = 𝓟 {⊥, pure x} := by rw [← principal_singleton, nhds_principal, principal_singleton, Iic_pure] @[simp] protected theorem nhds_iInf (f : ι → Filter α) : 𝓝 (⨅ i, f i) = ⨅ i, 𝓝 (f i) := by simp only [nhds_eq] apply lift'_iInf_of_map_univ <;> simp @[simp] protected theorem nhds_inf (l₁ l₂ : Filter α) : 𝓝 (l₁ ⊓ l₂) = 𝓝 l₁ ⊓ 𝓝 l₂ := by simpa only [iInf_bool_eq] using Filter.nhds_iInf fun b => cond b l₁ l₂ theorem monotone_nhds : Monotone (𝓝 : Filter α → Filter (Filter α)) := Monotone.of_map_inf Filter.nhds_inf theorem sInter_nhds (l : Filter α) : ⋂₀ { s | s ∈ 𝓝 l } = Iic l := by simp_rw [nhds_eq, Function.comp_def, sInter_lift'_sets monotone_principal.Iic, Iic, le_principal_iff, ← setOf_forall, ← Filter.le_def] @[simp] theorem nhds_mono {l₁ l₂ : Filter α} : 𝓝 l₁ ≤ 𝓝 l₂ ↔ l₁ ≤ l₂ := by refine ⟨fun h => ?_, fun h => monotone_nhds h⟩ rw [← Iic_subset_Iic, ← sInter_nhds, ← sInter_nhds] exact sInter_subset_sInter h protected theorem mem_interior {s : Set (Filter α)} {l : Filter α} : l ∈ interior s ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ s := by rw [mem_interior_iff_mem_nhds, Filter.mem_nhds_iff] protected theorem mem_closure {s : Set (Filter α)} {l : Filter α} : l ∈ closure s ↔ ∀ t ∈ l, ∃ l' ∈ s, t ∈ l' := by simp only [closure_eq_compl_interior_compl, Filter.mem_interior, mem_compl_iff, not_exists, not_forall, Classical.not_not, exists_prop, not_and, and_comm, subset_def, mem_Iic, le_principal_iff] @[simp] protected theorem closure_singleton (l : Filter α) : closure {l} = Ici l := by ext l' simp [Filter.mem_closure, Filter.le_def] @[simp] theorem specializes_iff_le {l₁ l₂ : Filter α} : l₁ ⤳ l₂ ↔ l₁ ≤ l₂ := by simp only [specializes_iff_closure_subset, Filter.closure_singleton, Ici_subset_Ici] instance : T0Space (Filter α) := ⟨fun _ _ h => (specializes_iff_le.1 h.specializes).antisymm (specializes_iff_le.1 h.symm.specializes)⟩ theorem nhds_atTop [Preorder α] : 𝓝 atTop = ⨅ x : α, 𝓟 (Iic (𝓟 (Ici x))) := by simp only [atTop, Filter.nhds_iInf, nhds_principal] protected theorem tendsto_nhds_atTop_iff [Preorder β] {l : Filter α} {f : α → Filter β} : Tendsto f l (𝓝 atTop) ↔ ∀ y, ∀ᶠ a in l, Ici y ∈ f a := by simp only [nhds_atTop, tendsto_iInf, tendsto_principal, mem_Iic, le_principal_iff] theorem nhds_atBot [Preorder α] : 𝓝 atBot = ⨅ x : α, 𝓟 (Iic (𝓟 (Iic x))) := @nhds_atTop αᵒᵈ _ protected theorem tendsto_nhds_atBot_iff [Preorder β] {l : Filter α} {f : α → Filter β} : Tendsto f l (𝓝 atBot) ↔ ∀ y, ∀ᶠ a in l, Iic y ∈ f a := @Filter.tendsto_nhds_atTop_iff α βᵒᵈ _ _ _ variable [TopologicalSpace X] theorem nhds_nhds (x : X) : 𝓝 (𝓝 x) = ⨅ (s : Set X) (_ : IsOpen s) (_ : x ∈ s), 𝓟 (Iic (𝓟 s)) := by simp only [(nhds_basis_opens x).nhds.eq_biInf, iInf_and, @iInf_comm _ (_ ∈ _)] theorem isInducing_nhds : IsInducing (𝓝 : X → Filter X) := isInducing_iff_nhds.2 fun x => (nhds_def' _).trans <| by simp +contextual only [nhds_nhds, comap_iInf, comap_principal, Iic_principal, preimage_setOf_eq, ← mem_interior_iff_mem_nhds, setOf_mem_eq, IsOpen.interior_eq] @[continuity] theorem continuous_nhds : Continuous (𝓝 : X → Filter X) := isInducing_nhds.continuous protected theorem Tendsto.nhds {f : α → X} {l : Filter α} {x : X} (h : Tendsto f l (𝓝 x)) : Tendsto (𝓝 ∘ f) l (𝓝 (𝓝 x)) := (continuous_nhds.tendsto _).comp h end Filter variable [TopologicalSpace X] [TopologicalSpace Y] {f : X → Y} {x : X} {s : Set X} protected nonrec theorem ContinuousWithinAt.nhds (h : ContinuousWithinAt f s x) : ContinuousWithinAt (𝓝 ∘ f) s x := h.nhds protected nonrec theorem ContinuousAt.nhds (h : ContinuousAt f x) : ContinuousAt (𝓝 ∘ f) x := h.nhds protected nonrec theorem ContinuousOn.nhds (h : ContinuousOn f s) : ContinuousOn (𝓝 ∘ f) s := fun x hx => (h x hx).nhds protected nonrec theorem Continuous.nhds (h : Continuous f) : Continuous (𝓝 ∘ f) := Filter.continuous_nhds.comp h
.lake/packages/mathlib/Mathlib/Topology/Constructions.lean
import Mathlib.Algebra.Group.TypeTags.Basic import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Finset.Piecewise import Mathlib.Order.Filter.Cofinite import Mathlib.Order.Filter.Curry import Mathlib.Topology.Constructions.SumProd import Mathlib.Topology.NhdsSet /-! # Constructions of new topological spaces from old ones This file constructs pi types, subtypes and quotients of topological spaces and sets up their basic theory, such as criteria for maps into or out of these constructions to be continuous; descriptions of the open sets, neighborhood filters, and generators of these constructions; and their behavior with respect to embeddings and other specific classes of maps. ## Implementation note The constructed topologies are defined using induced and coinduced topologies along with the complete lattice structure on topologies. Their universal properties (for example, a map `X → Y × Z` is continuous if and only if both projections `X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of continuity. With more work we can also extract descriptions of the open sets, neighborhood filters and so on. ## Tags product, subspace, quotient space -/ noncomputable section open Topology TopologicalSpace Set Filter Function open scoped Set.Notation universe u v u' v' variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*} section Constructions instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) := coinduced (Quot.mk r) t instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] : TopologicalSpace (Quotient s) := coinduced Quotient.mk' t instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] : TopologicalSpace (Sigma X) := ⨆ i, coinduced (Sigma.mk i) (t₂ i) instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] : TopologicalSpace ((i : ι) → Y i) := ⨅ i, induced (fun f => f i) (t₂ i) instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) := t.induced ULift.down /-! ### `Additive`, `Multiplicative` The topology on those type synonyms is inherited without change. -/ section variable [TopologicalSpace X] open Additive Multiplicative instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X› instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X› instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X› instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X› instance [CompactSpace X] : CompactSpace (Additive X) := ‹CompactSpace X› instance [CompactSpace X] : CompactSpace (Multiplicative X) := ‹CompactSpace X› instance [NoncompactSpace X] : NoncompactSpace (Additive X) := ‹NoncompactSpace X› instance [NoncompactSpace X] : NoncompactSpace (Multiplicative X) := ‹NoncompactSpace X› instance [WeaklyLocallyCompactSpace X] : WeaklyLocallyCompactSpace (Additive X) := ‹WeaklyLocallyCompactSpace X› instance [WeaklyLocallyCompactSpace X] : WeaklyLocallyCompactSpace (Multiplicative X) := ‹WeaklyLocallyCompactSpace X› instance [LocallyCompactSpace X] : LocallyCompactSpace (Additive X) := ‹LocallyCompactSpace X› instance [LocallyCompactSpace X] : LocallyCompactSpace (Multiplicative X) := ‹LocallyCompactSpace X› theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl theorem nhds_toMul (x : Additive X) : 𝓝 x.toMul = map toMul (𝓝 x) := rfl theorem nhds_toAdd (x : Multiplicative X) : 𝓝 x.toAdd = map toAdd (𝓝 x) := rfl end /-! ### Order dual The topology on this type synonym is inherited without change. -/ section variable [TopologicalSpace X] open OrderDual instance OrderDual.instTopologicalSpace : TopologicalSpace Xᵒᵈ := ‹_› instance OrderDual.instDiscreteTopology [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹_› theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl variable [Preorder X] {x : X} instance OrderDual.instNeBotNhdsWithinIoi [(𝓝[<] x).NeBot] : (𝓝[>] toDual x).NeBot := ‹_› instance OrderDual.instNeBotNhdsWithinIio [(𝓝[>] x).NeBot] : (𝓝[<] toDual x).NeBot := ‹_› end theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s} {x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x := preimage_nhds_coinduced hs /-- The image of a dense set under `Quotient.mk'` is a dense set. -/ theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) : Dense (Quotient.mk' '' s) := Quotient.mk''_surjective.denseRange.dense_image continuous_coinduced_rng H /-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/ theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) : DenseRange (Quotient.mk' ∘ f) := Quotient.mk''_surjective.denseRange.comp hf continuous_coinduced_rng theorem continuous_map_of_le {α : Type*} [TopologicalSpace α] {s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) := continuous_coinduced_rng theorem continuous_map_sInf {α : Type*} [TopologicalSpace α] {S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) := continuous_coinduced_rng instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) := ⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩ instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X] [hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) := ⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩ instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) := ⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩ @[simp] lemma comap_nhdsWithin_range {α β} [TopologicalSpace β] (f : α → β) (y : β) : comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range section Top variable [TopologicalSpace X] /- The 𝓝 filter and the subspace topology. -/ theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) : t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t := mem_nhds_induced _ x t theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) := nhds_induced _ x lemma nhds_subtype_eq_comap_nhdsWithin (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝[s] (x : X)) := by rw [nhds_subtype, ← comap_nhdsWithin_range, Subtype.range_val] theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} : 𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal, nhds_induced] theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} : 𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton, Subtype.coe_injective.preimage_image] theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} : (𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff] end Top /-- A type synonym equipped with the topology whose open sets are the empty set and the sets with finite complements. -/ def CofiniteTopology (X : Type*) := X namespace CofiniteTopology /-- The identity equivalence between `` and `CofiniteTopology `. -/ def of : X ≃ CofiniteTopology X := Equiv.refl X instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default instance : TopologicalSpace (CofiniteTopology X) where IsOpen s := s.Nonempty → Set.Finite sᶜ isOpen_univ := by simp isOpen_inter s t := by rintro hs ht ⟨x, hxs, hxt⟩ rw [compl_inter] exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩) isOpen_sUnion := by rintro s h ⟨x, t, hts, hzt⟩ rw [compl_sUnion] exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩) theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite := Iff.rfl theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left] theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff] theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by ext U rw [mem_nhds_iff] constructor · rintro ⟨V, hVU, V_op, haV⟩ exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩ · rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩ exact ⟨U, Subset.rfl, fun _ => hU', hU⟩ theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} : s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq] end CofiniteTopology end Constructions section Prod variable [TopologicalSpace X] [TopologicalSpace Y] theorem MapClusterPt.curry_prodMap {α β : Type*} {f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y} (hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) : MapClusterPt (x, y) (la.curry lb) (.map f g) := by rw [mapClusterPt_iff_frequently] at hf hg rw [((𝓝 x).basis_sets.prod_nhds (𝓝 y).basis_sets).mapClusterPt_iff_frequently] rintro ⟨s, t⟩ ⟨hs, ht⟩ rw [frequently_curry_iff] exact (hf s hs).mono fun x hx ↦ (hg t ht).mono fun y hy ↦ ⟨hx, hy⟩ theorem MapClusterPt.prodMap {α β : Type*} {f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y} (hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) : MapClusterPt (x, y) (la ×ˢ lb) (.map f g) := (hf.curry_prodMap hg).mono <| map_mono curry_le_prod end Prod section Bool lemma continuous_bool_rng [TopologicalSpace X] {f : X → Bool} (b : Bool) : Continuous f ↔ IsClopen (f ⁻¹' {b}) := by rw [continuous_discrete_rng, Bool.forall_bool' b, IsClopen, ← isOpen_compl_iff, ← preimage_compl, Bool.compl_singleton, and_comm] end Bool section Subtype variable [TopologicalSpace X] [TopologicalSpace Y] {p : X → Prop} @[fun_prop] lemma Topology.IsInducing.subtypeVal {t : Set Y} : IsInducing ((↑) : t → Y) := ⟨rfl⟩ lemma Topology.IsInducing.of_codRestrict {f : X → Y} {t : Set Y} (ht : ∀ x, f x ∈ t) (h : IsInducing (t.codRestrict f ht)) : IsInducing f := subtypeVal.comp h @[fun_prop] lemma Topology.IsEmbedding.subtypeVal : IsEmbedding ((↑) : Subtype p → X) := ⟨.subtypeVal, Subtype.coe_injective⟩ @[fun_prop] theorem Topology.IsClosedEmbedding.subtypeVal (h : IsClosed {a | p a}) : IsClosedEmbedding ((↑) : Subtype p → X) := ⟨.subtypeVal, by rwa [Subtype.range_coe_subtype]⟩ @[continuity, fun_prop] theorem continuous_subtype_val : Continuous (@Subtype.val X p) := continuous_induced_dom theorem Continuous.subtype_val {f : Y → Subtype p} (hf : Continuous f) : Continuous fun x => (f x : X) := continuous_subtype_val.comp hf @[fun_prop] theorem IsOpen.isOpenEmbedding_subtypeVal {s : Set X} (hs : IsOpen s) : IsOpenEmbedding ((↑) : s → X) := ⟨.subtypeVal, (@Subtype.range_coe _ s).symm ▸ hs⟩ theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s → X) := hs.isOpenEmbedding_subtypeVal.isOpenMap theorem IsOpenMap.restrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} (hs : IsOpen s) : IsOpenMap (s.restrict f) := hf.comp hs.isOpenMap_subtype_val @[fun_prop] lemma IsClosed.isClosedEmbedding_subtypeVal {s : Set X} (hs : IsClosed s) : IsClosedEmbedding ((↑) : s → X) := .subtypeVal hs theorem IsClosed.isClosedMap_subtype_val {s : Set X} (hs : IsClosed s) : IsClosedMap ((↑) : s → X) := hs.isClosedEmbedding_subtypeVal.isClosedMap theorem IsClosedMap.restrict {f : X → Y} (hf : IsClosedMap f) {s : Set X} (hs : IsClosed s) : IsClosedMap (s.restrict f) := hf.comp hs.isClosedMap_subtype_val @[continuity, fun_prop] theorem Continuous.subtype_mk {f : Y → X} (h : Continuous f) (hp : ∀ x, p (f x)) : Continuous fun x => (⟨f x, hp x⟩ : Subtype p) := continuous_induced_rng.2 h theorem IsOpenMap.subtype_mk {f : Y → X} (hf : IsOpenMap f) (hp : ∀ x, p (f x)) : IsOpenMap fun x ↦ (⟨f x, hp x⟩ : Subtype p) := fun u hu ↦ by convert (hf u hu).preimage continuous_subtype_val exact Set.ext fun _ ↦ exists_congr fun _ ↦ and_congr_right' Subtype.ext_iff theorem IsClosedMap.subtype_mk {f : Y → X} (hf : IsClosedMap f) (hp : ∀ x, p (f x)) : IsClosedMap fun x ↦ (⟨f x, hp x⟩ : Subtype p) := fun u hu ↦ by convert (hf u hu).preimage continuous_subtype_val exact Set.ext fun _ ↦ exists_congr fun _ ↦ and_congr_right' Subtype.ext_iff @[fun_prop] theorem Continuous.subtype_coind {f : Y → X} (hf : Continuous f) (hp : ∀ x, p (f x)) : Continuous (Subtype.coind f hp) := hf.subtype_mk hp theorem IsOpenMap.subtype_coind {f : Y → X} (hf : IsOpenMap f) (hp : ∀ x, p (f x)) : IsOpenMap (Subtype.coind f hp) := hf.subtype_mk hp theorem IsClosedMap.subtype_coind {f : Y → X} (hf : IsClosedMap f) (hp : ∀ x, p (f x)) : IsClosedMap (Subtype.coind f hp) := hf.subtype_mk hp @[fun_prop] theorem Continuous.subtype_map {f : X → Y} (h : Continuous f) {q : Y → Prop} (hpq : ∀ x, p x → q (f x)) : Continuous (Subtype.map f hpq) := (h.comp continuous_subtype_val).subtype_mk _ theorem IsOpenMap.subtype_map {f : X → Y} (hf : IsOpenMap f) {s : Set X} {t : Set Y} (hs : IsOpen s) (hst : ∀ x ∈ s, f x ∈ t) : IsOpenMap (Subtype.map f hst) := (hf.comp hs.isOpenMap_subtype_val).subtype_mk _ theorem IsClosedMap.subtype_map {f : X → Y} (hf : IsClosedMap f) {s : Set X} {t : Set Y} (hs : IsClosed s) (hst : ∀ x ∈ s, f x ∈ t) : IsClosedMap (Subtype.map f hst) := (hf.comp hs.isClosedMap_subtype_val).subtype_mk _ theorem continuous_inclusion {s t : Set X} (h : s ⊆ t) : Continuous (inclusion h) := continuous_id.subtype_map h theorem IsOpen.isOpenMap_inclusion {s t : Set X} (hs : IsOpen s) (h : s ⊆ t) : IsOpenMap (inclusion h) := IsOpenMap.id.subtype_map hs h theorem IsClosed.isClosedMap_inclusion {s t : Set X} (hs : IsClosed s) (h : s ⊆ t) : IsClosedMap (inclusion h) := IsClosedMap.id.subtype_map hs h @[simp] theorem continuous_rangeFactorization_iff {f : X → Y} : Continuous (rangeFactorization f) ↔ Continuous f := IsInducing.subtypeVal.continuous_iff @[continuity, fun_prop] theorem Continuous.rangeFactorization {f : X → Y} (hf : Continuous f) : Continuous (rangeFactorization f) := continuous_rangeFactorization_iff.mpr hf theorem continuousAt_subtype_val {p : X → Prop} {x : Subtype p} : ContinuousAt ((↑) : Subtype p → X) x := continuous_subtype_val.continuousAt theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s ⊆ closure ((↑) '' t) := by rw [IsInducing.subtypeVal.dense_iff, SetCoe.forall] rfl @[simp] theorem denseRange_inclusion_iff {s t : Set X} (hst : s ⊆ t) : DenseRange (inclusion hst) ↔ t ⊆ closure s := by rw [DenseRange, Subtype.dense_iff, ← range_comp, val_comp_inclusion, Subtype.range_coe] theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s → X) (𝓝 x) = 𝓝[s] ↑x := by rw [IsInducing.subtypeVal.map_nhds_eq, Subtype.range_val] theorem map_nhds_subtype_coe_eq_nhds {x : X} (hx : p x) (h : ∀ᶠ x in 𝓝 x, p x) : map ((↑) : Subtype p → X) (𝓝 ⟨x, hx⟩) = 𝓝 x := map_nhds_induced_of_mem <| by rw [Subtype.range_val]; exact h theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) := nhds_induced _ _ theorem tendsto_subtype_rng {Y : Type*} {p : X → Prop} {l : Filter Y} {f : Y → Subtype p} : ∀ {x : Subtype p}, Tendsto f l (𝓝 x) ↔ Tendsto (fun x => (f x : X)) l (𝓝 (x : X)) | ⟨a, ha⟩ => by rw [nhds_subtype_eq_comap, tendsto_comap_iff]; rfl theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} : x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ → X) '' s) := closure_induced @[simp] theorem continuousAt_codRestrict_iff {f : X → Y} {t : Set Y} (h1 : ∀ x, f x ∈ t) {x : X} : ContinuousAt (codRestrict f t h1) x ↔ ContinuousAt f x := IsInducing.subtypeVal.continuousAt_iff alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff theorem ContinuousAt.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) {x : s} (h2 : ContinuousAt f x) : ContinuousAt (h1.restrict f s t) x := (h2.comp continuousAt_subtype_val).codRestrict _ theorem ContinuousAt.restrictPreimage {f : X → Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) : ContinuousAt (s.restrictPreimage f) x := h.restrict _ @[continuity, fun_prop] theorem Continuous.codRestrict {f : X → Y} {s : Set Y} (hf : Continuous f) (hs : ∀ a, f a ∈ s) : Continuous (s.codRestrict f hs) := hf.subtype_mk hs theorem IsOpenMap.codRestrict {f : X → Y} (hf : IsOpenMap f) {s : Set Y} (hs : ∀ a, f a ∈ s) : IsOpenMap (s.codRestrict f hs) := hf.subtype_mk hs theorem IsClosedMap.codRestrict {f : X → Y} (hf : IsClosedMap f) {s : Set Y} (hs : ∀ a, f a ∈ s) : IsClosedMap (s.codRestrict f hs) := hf.subtype_mk hs @[continuity, fun_prop] theorem Continuous.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) (h2 : Continuous f) : Continuous (h1.restrict f s t) := (h2.comp continuous_subtype_val).codRestrict _ lemma IsOpenMap.mapsToRestrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} {t : Set Y} (hs : IsOpen s) (ht : MapsTo f s t) : IsOpenMap ht.restrict := (hf.restrict hs).codRestrict _ lemma IsClosedMap.mapsToRestrict {f : X → Y} (hf : IsClosedMap f) {s : Set X} {t : Set Y} (hs : IsClosed s) (ht : MapsTo f s t) : IsClosedMap ht.restrict := (hf.restrict hs).codRestrict _ @[continuity, fun_prop] theorem Continuous.restrictPreimage {f : X → Y} {s : Set Y} (h : Continuous f) : Continuous (s.restrictPreimage f) := h.restrict _ @[fun_prop] lemma Topology.IsEmbedding.restrict {f : X → Y} (hf : IsEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) : IsEmbedding H.restrict := .of_comp (hf.continuous.restrict H) continuous_subtype_val (hf.comp .subtypeVal) @[fun_prop] lemma Topology.IsOpenEmbedding.restrict {f : X → Y} (hf : IsOpenEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) (hs : IsOpen s) : IsOpenEmbedding H.restrict := ⟨hf.isEmbedding.restrict H, (by rw [MapsTo.range_restrict] exact continuous_subtype_val.1 _ (hf.isOpenMap _ hs))⟩ theorem Topology.IsInducing.codRestrict {e : X → Y} (he : IsInducing e) {s : Set Y} (hs : ∀ x, e x ∈ s) : IsInducing (codRestrict e s hs) := he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val protected lemma Topology.IsEmbedding.codRestrict {e : X → Y} (he : IsEmbedding e) (s : Set Y) (hs : ∀ x, e x ∈ s) : IsEmbedding (codRestrict e s hs) := he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val variable {s t : Set X} @[fun_prop] protected lemma Topology.IsEmbedding.inclusion (h : s ⊆ t) : IsEmbedding (inclusion h) := IsEmbedding.subtypeVal.codRestrict _ _ @[fun_prop] protected lemma Topology.IsOpenEmbedding.inclusion (hst : s ⊆ t) (hs : IsOpen (t ↓∩ s)) : IsOpenEmbedding (inclusion hst) where toIsEmbedding := .inclusion _ isOpen_range := by rwa [range_inclusion] @[fun_prop] protected lemma Topology.IsClosedEmbedding.inclusion (hst : s ⊆ t) (hs : IsClosed (t ↓∩ s)) : IsClosedEmbedding (inclusion hst) where toIsEmbedding := .inclusion _ isClosed_range := by rwa [range_inclusion] /-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/ theorem DiscreteTopology.of_subset {X : Type*} [TopologicalSpace X] {s t : Set X} (_ : DiscreteTopology s) (ts : t ⊆ s) : DiscreteTopology t := (IsEmbedding.inclusion ts).discreteTopology /-- Let `s` be a discrete subset of a topological space. Then the preimage of `s` by a continuous injective map is also discrete. -/ theorem DiscreteTopology.preimage_of_continuous_injective {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] (s : Set Y) [DiscreteTopology s] {f : X → Y} (hc : Continuous f) (hinj : Function.Injective f) : DiscreteTopology (f ⁻¹' s) := DiscreteTopology.of_continuous_injective (β := s) (Continuous.restrict (by exact fun _ x ↦ x) hc) ((MapsTo.restrict_inj _).mpr hinj.injOn) /-- If `f : X → Y` is a quotient map, then its restriction to the preimage of an open set is a quotient map too. -/ theorem Topology.IsQuotientMap.restrictPreimage_isOpen {f : X → Y} (hf : IsQuotientMap f) {s : Set Y} (hs : IsOpen s) : IsQuotientMap (s.restrictPreimage f) := by refine isQuotientMap_iff.2 ⟨hf.surjective.restrictPreimage _, fun U ↦ ?_⟩ rw [hs.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, ← hf.isOpen_preimage, (hs.preimage hf.continuous).isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, image_val_preimage_restrictPreimage] open scoped Set.Notation in lemma isClosed_preimage_val {s t : Set X} : IsClosed (s ↓∩ t) ↔ s ∩ closure (s ∩ t) ⊆ t := by rw [← closure_eq_iff_isClosed, IsEmbedding.subtypeVal.closure_eq_preimage_closure_image, ← Subtype.val_injective.image_injective.eq_iff, Subtype.image_preimage_coe, Subtype.image_preimage_coe, subset_antisymm_iff, and_iff_left, Set.subset_inter_iff, and_iff_right] exacts [Set.inter_subset_left, Set.subset_inter Set.inter_subset_left subset_closure] theorem frontier_inter_open_inter {s t : Set X} (ht : IsOpen t) : frontier (s ∩ t) ∩ t = frontier s ∩ t := by simp only [Set.inter_comm _ t, ← Subtype.preimage_coe_eq_preimage_coe_iff, ht.isOpenMap_subtype_val.preimage_frontier_eq_frontier_preimage continuous_subtype_val, Subtype.preimage_coe_self_inter] section SetNotation open scoped Set.Notation lemma IsOpen.preimage_val {s t : Set X} (ht : IsOpen t) : IsOpen (s ↓∩ t) := ht.preimage continuous_subtype_val lemma IsClosed.preimage_val {s t : Set X} (ht : IsClosed t) : IsClosed (s ↓∩ t) := ht.preimage continuous_subtype_val @[simp] lemma IsOpen.inter_preimage_val_iff {s t : Set X} (hs : IsOpen s) : IsOpen (s ↓∩ t) ↔ IsOpen (s ∩ t) := ⟨fun h ↦ by simpa using hs.isOpenMap_subtype_val _ h, fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩ @[simp] lemma IsClosed.inter_preimage_val_iff {s t : Set X} (hs : IsClosed s) : IsClosed (s ↓∩ t) ↔ IsClosed (s ∩ t) := ⟨fun h ↦ by simpa using hs.isClosedMap_subtype_val _ h, fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩ end SetNotation end Subtype section Quotient variable [TopologicalSpace X] [TopologicalSpace Y] variable {r : X → X → Prop} {s : Setoid X} theorem isQuotientMap_quot_mk : IsQuotientMap (@Quot.mk X r) := ⟨Quot.exists_rep, rfl⟩ @[continuity, fun_prop] theorem continuous_quot_mk : Continuous (@Quot.mk X r) := continuous_coinduced_rng @[continuity, fun_prop] theorem continuous_quot_lift {f : X → Y} (hr : ∀ a b, r a b → f a = f b) (h : Continuous f) : Continuous (Quot.lift f hr : Quot r → Y) := continuous_coinduced_dom.2 h theorem isQuotientMap_quotient_mk' : IsQuotientMap (@Quotient.mk' X s) := isQuotientMap_quot_mk theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) := continuous_coinduced_rng theorem Continuous.quotient_lift {f : X → Y} (h : Continuous f) (hs : ∀ a b, a ≈ b → f a = f b) : Continuous (Quotient.lift f hs : Quotient s → Y) := continuous_coinduced_dom.2 h theorem Continuous.quotient_liftOn' {f : X → Y} (h : Continuous f) (hs : ∀ a b, s a b → f a = f b) : Continuous (fun x => Quotient.liftOn' x f hs : Quotient s → Y) := h.quotient_lift hs open scoped Relator in @[continuity, fun_prop] theorem Continuous.quotient_map' {t : Setoid Y} {f : X → Y} (hf : Continuous f) (H : (s.r ⇒ t.r) f f) : Continuous (Quotient.map' f H) := (continuous_quotient_mk'.comp hf).quotient_lift _ end Quotient section Pi variable {ι : Type*} {A B : ι → Type*} {κ : Type*} [TopologicalSpace X] [T : ∀ i, TopologicalSpace (A i)] [∀ i, TopologicalSpace (B i)] {f : X → ∀ i : ι, A i} theorem continuous_pi_iff : Continuous f ↔ ∀ i, Continuous fun a => f a i := by simp only [continuous_iInf_rng, continuous_induced_rng, comp_def] @[continuity, fun_prop] theorem continuous_pi (h : ∀ i, Continuous fun a => f a i) : Continuous f := continuous_pi_iff.2 h @[continuity, fun_prop] theorem continuous_apply (i : ι) : Continuous fun p : ∀ i, A i => p i := continuous_iInf_dom continuous_induced_dom @[continuity] theorem continuous_apply_apply {ρ : κ → ι → Type*} [∀ j i, TopologicalSpace (ρ j i)] (j : κ) (i : ι) : Continuous fun p : ∀ j, ∀ i, ρ j i => p j i := (continuous_apply i).comp (continuous_apply j) theorem continuousAt_apply (i : ι) (x : ∀ i, A i) : ContinuousAt (fun p : ∀ i, A i => p i) x := (continuous_apply i).continuousAt theorem Filter.Tendsto.apply_nhds {l : Filter Y} {f : Y → ∀ i, A i} {x : ∀ i, A i} (h : Tendsto f l (𝓝 x)) (i : ι) : Tendsto (fun a => f a i) l (𝓝 <| x i) := (continuousAt_apply i _).tendsto.comp h @[fun_prop] protected theorem Continuous.piMap {f : ∀ i, A i → B i} (hf : ∀ i, Continuous (f i)) : Continuous (Pi.map f) := continuous_pi fun i ↦ (hf i).comp (continuous_apply i) theorem nhds_pi {a : ∀ i, A i} : 𝓝 a = pi fun i => 𝓝 (a i) := by simp only [nhds_iInf, nhds_induced, Filter.pi] protected theorem IsOpenMap.piMap {f : ∀ i, A i → B i} (hfo : ∀ i, IsOpenMap (f i)) (hsurj : ∀ᶠ i in cofinite, Surjective (f i)) : IsOpenMap (Pi.map f) := by refine IsOpenMap.of_nhds_le fun x ↦ ?_ rw [nhds_pi, nhds_pi, map_piMap_pi hsurj] exact Filter.pi_mono fun i ↦ (hfo i).nhds_le _ protected theorem IsOpenQuotientMap.piMap {f : ∀ i, A i → B i} (hf : ∀ i, IsOpenQuotientMap (f i)) : IsOpenQuotientMap (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2, .piMap (fun i ↦ (hf i).3) <| .of_forall fun i ↦ (hf i).1⟩ theorem tendsto_pi_nhds {f : Y → ∀ i, A i} {g : ∀ i, A i} {u : Filter Y} : Tendsto f u (𝓝 g) ↔ ∀ x, Tendsto (fun i => f i x) u (𝓝 (g x)) := by rw [nhds_pi, Filter.tendsto_pi] theorem continuousAt_pi {f : X → ∀ i, A i} {x : X} : ContinuousAt f x ↔ ∀ i, ContinuousAt (fun y => f y i) x := tendsto_pi_nhds @[fun_prop] theorem continuousAt_pi' {f : X → ∀ i, A i} {x : X} (hf : ∀ i, ContinuousAt (fun y => f y i) x) : ContinuousAt f x := continuousAt_pi.2 hf @[fun_prop] protected theorem ContinuousAt.piMap {f : ∀ i, A i → B i} {x : ∀ i, A i} (hf : ∀ i, ContinuousAt (f i) (x i)) : ContinuousAt (Pi.map f) x := continuousAt_pi.2 fun i ↦ (hf i).comp (continuousAt_apply i x) protected lemma Topology.IsInducing.piMap {f : ∀ i, A i → B i} (hf : ∀ i, IsInducing (f i)) : IsInducing (Pi.map f) := by simp [isInducing_iff_nhds, nhds_pi, (hf _).nhds_eq_comap, Filter.pi_comap] protected lemma Topology.IsEmbedding.piMap {f : ∀ i, A i → B i} (hf : ∀ i, IsEmbedding (f i)) : IsEmbedding (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2⟩ theorem Pi.continuous_precomp' {ι' : Type*} (φ : ι' → ι) : Continuous (fun (f : (∀ i, A i)) (j : ι') ↦ f (φ j)) := continuous_pi fun j ↦ continuous_apply (φ j) theorem Pi.continuous_precomp {ι' : Type*} (φ : ι' → ι) : Continuous (· ∘ φ : (ι → X) → (ι' → X)) := Pi.continuous_precomp' φ theorem Pi.continuous_postcomp' {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {g : ∀ i, A i → X i} (hg : ∀ i, Continuous (g i)) : Continuous (fun (f : (∀ i, A i)) (i : ι) ↦ g i (f i)) := continuous_pi fun i ↦ (hg i).comp <| continuous_apply i theorem Pi.continuous_postcomp [TopologicalSpace Y] {g : X → Y} (hg : Continuous g) : Continuous (g ∘ · : (ι → X) → (ι → Y)) := Pi.continuous_postcomp' fun _ ↦ hg lemma Pi.induced_precomp' {ι' : Type*} (φ : ι' → ι) : induced (fun (f : (∀ i, A i)) (j : ι') ↦ f (φ j)) Pi.topologicalSpace = ⨅ i', induced (eval (φ i')) (T (φ i')) := by simp [Pi.topologicalSpace, induced_iInf, induced_compose, comp_def] lemma Pi.induced_precomp [TopologicalSpace Y] {ι' : Type*} (φ : ι' → ι) : induced (· ∘ φ) Pi.topologicalSpace = ⨅ i', induced (eval (φ i')) ‹TopologicalSpace Y› := induced_precomp' φ /-- Homeomorphism between `X → Y → Z` and `X × Y → Z` with product topologies. -/ @[simps] def Homeomorph.piCurry {X Y Z : Type*} [TopologicalSpace Z] : (X × Y → Z) ≃ₜ (X → Y → Z) where toFun := Function.curry invFun := Function.uncurry right_inv := congrFun rfl left_inv := congrFun rfl continuous_toFun := continuous_pi (fun i ↦ Pi.continuous_precomp (Prod.mk i)) @[continuity, fun_prop] lemma Pi.continuous_restrict (S : Set ι) : Continuous (S.restrict : (∀ i : ι, A i) → (∀ i : S, A i)) := Pi.continuous_precomp' ((↑) : S → ι) @[continuity, fun_prop] lemma Pi.continuous_restrict₂ {s t : Set ι} (hst : s ⊆ t) : Continuous (restrict₂ (π := A) hst) := continuous_pi fun _ ↦ continuous_apply _ @[continuity, fun_prop] theorem Finset.continuous_restrict (s : Finset ι) : Continuous (s.restrict (π := A)) := continuous_pi fun _ ↦ continuous_apply _ @[continuity, fun_prop] theorem Finset.continuous_restrict₂ {s t : Finset ι} (hst : s ⊆ t) : Continuous (Finset.restrict₂ (π := A) hst) := continuous_pi fun _ ↦ continuous_apply _ variable [TopologicalSpace Z] @[continuity, fun_prop] theorem Pi.continuous_restrict_apply (s : Set X) {f : X → Z} (hf : Continuous f) : Continuous (s.restrict f) := hf.comp continuous_subtype_val @[continuity, fun_prop] theorem Pi.continuous_restrict₂_apply {s t : Set X} (hst : s ⊆ t) {f : t → Z} (hf : Continuous f) : Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst) @[continuity, fun_prop] theorem Finset.continuous_restrict_apply (s : Finset X) {f : X → Z} (hf : Continuous f) : Continuous (s.restrict f) := hf.comp continuous_subtype_val @[continuity, fun_prop] theorem Finset.continuous_restrict₂_apply {s t : Finset X} (hst : s ⊆ t) {f : t → Z} (hf : Continuous f) : Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst) lemma Pi.induced_restrict (S : Set ι) : induced (S.restrict) Pi.topologicalSpace = ⨅ i ∈ S, induced (eval i) (T i) := by simp +unfoldPartialApp [← iInf_subtype'', ← induced_precomp' ((↑) : S → ι), restrict] lemma Pi.induced_restrict_sUnion (𝔖 : Set (Set ι)) : induced (⋃₀ 𝔖).restrict (Pi.topologicalSpace (Y := fun i : (⋃₀ 𝔖) ↦ A i)) = ⨅ S ∈ 𝔖, induced S.restrict Pi.topologicalSpace := by simp_rw [Pi.induced_restrict, iInf_sUnion] theorem Filter.Tendsto.update [DecidableEq ι] {l : Filter Y} {f : Y → ∀ i, A i} {x : ∀ i, A i} (hf : Tendsto f l (𝓝 x)) (i : ι) {g : Y → A i} {xi : A i} (hg : Tendsto g l (𝓝 xi)) : Tendsto (fun a => update (f a) i (g a)) l (𝓝 <| update x i xi) := tendsto_pi_nhds.2 fun j => by rcases eq_or_ne j i with (rfl | hj) <;> simp [*, hf.apply_nhds] theorem ContinuousAt.update [DecidableEq ι] {x : X} (hf : ContinuousAt f x) (i : ι) {g : X → A i} (hg : ContinuousAt g x) : ContinuousAt (fun a => update (f a) i (g a)) x := hf.tendsto.update i hg theorem Continuous.update [DecidableEq ι] (hf : Continuous f) (i : ι) {g : X → A i} (hg : Continuous g) : Continuous fun a => update (f a) i (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.update i hg.continuousAt /-- `Function.update f i x` is continuous in `(f, x)`. -/ @[continuity, fun_prop] theorem continuous_update [DecidableEq ι] (i : ι) : Continuous fun f : (∀ j, A j) × A i => update f.1 i f.2 := continuous_fst.update i continuous_snd /-- `Pi.mulSingle i x` is continuous in `x`. -/ @[to_additive (attr := continuity) /-- `Pi.single i x` is continuous in `x`. -/] theorem continuous_mulSingle [∀ i, One (A i)] [DecidableEq ι] (i : ι) : Continuous fun x => (Pi.mulSingle i x : ∀ i, A i) := continuous_const.update _ continuous_id section Fin variable {n : ℕ} {A : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (A i)] theorem Filter.Tendsto.finCons {f : Y → A 0} {g : Y → ∀ j : Fin n, A j.succ} {l : Filter Y} {x : A 0} {y : ∀ j, A (Fin.succ j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Fin.cons (f a) (g a)) l (𝓝 <| Fin.cons x y) := tendsto_pi_nhds.2 fun j => Fin.cases (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j theorem ContinuousAt.finCons {f : X → A 0} {g : X → ∀ j : Fin n, A (Fin.succ j)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Fin.cons (f a) (g a)) x := hf.tendsto.finCons hg theorem Continuous.finCons {f : X → A 0} {g : X → ∀ j : Fin n, A (Fin.succ j)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.cons (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finCons hg.continuousAt theorem Filter.Tendsto.matrixVecCons {f : Y → Z} {g : Y → Fin n → Z} {l : Filter Y} {x : Z} {y : Fin n → Z} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Matrix.vecCons (f a) (g a)) l (𝓝 <| Matrix.vecCons x y) := hf.finCons hg theorem ContinuousAt.matrixVecCons {f : X → Z} {g : X → Fin n → Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Matrix.vecCons (f a) (g a)) x := hf.finCons hg theorem Continuous.matrixVecCons {f : X → Z} {g : X → Fin n → Z} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Matrix.vecCons (f a) (g a) := hf.finCons hg theorem Filter.Tendsto.finSnoc {f : Y → ∀ j : Fin n, A j.castSucc} {g : Y → A (Fin.last _)} {l : Filter Y} {x : ∀ j, A (Fin.castSucc j)} {y : A (Fin.last _)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Fin.snoc (f a) (g a)) l (𝓝 <| Fin.snoc x y) := tendsto_pi_nhds.2 fun j => Fin.lastCases (by simpa) (by simpa using tendsto_pi_nhds.1 hf) j theorem ContinuousAt.finSnoc {f : X → ∀ j : Fin n, A j.castSucc} {g : X → A (Fin.last _)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Fin.snoc (f a) (g a)) x := hf.tendsto.finSnoc hg theorem Continuous.finSnoc {f : X → ∀ j : Fin n, A j.castSucc} {g : X → A (Fin.last _)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.snoc (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finSnoc hg.continuousAt theorem Filter.Tendsto.finInsertNth (i : Fin (n + 1)) {f : Y → A i} {g : Y → ∀ j : Fin n, A (i.succAbove j)} {l : Filter Y} {x : A i} {y : ∀ j, A (i.succAbove j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => i.insertNth (f a) (g a)) l (𝓝 <| i.insertNth x y) := tendsto_pi_nhds.2 fun j => Fin.succAboveCases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j theorem ContinuousAt.finInsertNth (i : Fin (n + 1)) {f : X → A i} {g : X → ∀ j : Fin n, A (i.succAbove j)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => i.insertNth (f a) (g a)) x := hf.tendsto.finInsertNth i hg theorem Continuous.finInsertNth (i : Fin (n + 1)) {f : X → A i} {g : X → ∀ j : Fin n, A (i.succAbove j)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => i.insertNth (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finInsertNth i hg.continuousAt theorem Filter.Tendsto.finInit {f : Y → ∀ j : Fin (n + 1), A j} {l : Filter Y} {x : ∀ j, A j} (hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.init (f a)) l (𝓝 <| Fin.init x) := tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.castSucc @[fun_prop] theorem ContinuousAt.finInit {f : X → ∀ j : Fin (n + 1), A j} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.init (f a)) x := hf.tendsto.finInit @[fun_prop] theorem Continuous.finInit {f : X → ∀ j : Fin (n + 1), A j} (hf : Continuous f) : Continuous fun a ↦ Fin.init (f a) := continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finInit theorem Filter.Tendsto.finTail {f : Y → ∀ j : Fin (n + 1), A j} {l : Filter Y} {x : ∀ j, A j} (hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.tail (f a)) l (𝓝 <| Fin.tail x) := tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.succ @[fun_prop] theorem ContinuousAt.finTail {f : X → ∀ j : Fin (n + 1), A j} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.tail (f a)) x := hf.tendsto.finTail @[fun_prop] theorem Continuous.finTail {f : X → ∀ j : Fin (n + 1), A j} (hf : Continuous f) : Continuous fun a ↦ Fin.tail (f a) := continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finTail end Fin theorem isOpen_set_pi {i : Set ι} {s : ∀ a, Set (A a)} (hi : i.Finite) (hs : ∀ a ∈ i, IsOpen (s a)) : IsOpen (pi i s) := by rw [pi_def]; exact hi.isOpen_biInter fun a ha => (hs _ ha).preimage (continuous_apply _) theorem isOpen_pi_iff {s : Set (∀ a, A a)} : IsOpen s ↔ ∀ f, f ∈ s → ∃ (I : Finset ι) (u : ∀ a, Set (A a)), (∀ a, a ∈ I → IsOpen (u a) ∧ f a ∈ u a) ∧ (I : Set ι).pi u ⊆ s := by rw [isOpen_iff_nhds] simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff] refine forall₂_congr fun a _ => ⟨?_, ?_⟩ · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨I, fun a => eval a '' (I : Set ι).pi fun a => (h1 a).choose, fun i hi => ?_, ?_⟩ · simp_rw [eval_image_pi (Finset.mem_coe.mpr hi) (pi_nonempty_iff.mpr fun i => ⟨_, fun _ => (h1 i).choose_spec.2.2⟩)] exact (h1 i).choose_spec.2 · exact Subset.trans (pi_mono fun i hi => (eval_image_pi_subset hi).trans (h1 i).choose_spec.1) h2 · rintro ⟨I, t, ⟨h1, h2⟩⟩ classical refine ⟨I, fun a => ite (a ∈ I) (t a) univ, fun i => ?_, ?_⟩ · by_cases hi : i ∈ I · use t i simp_rw [if_pos hi] exact ⟨Subset.rfl, (h1 i) hi⟩ · use univ simp_rw [if_neg hi] exact ⟨Subset.rfl, isOpen_univ, mem_univ _⟩ · rw [← univ_pi_ite] simp only [← ite_and, ← Finset.mem_coe, and_self_iff, univ_pi_ite, h2] theorem isOpen_pi_iff' [Finite ι] {s : Set (∀ a, A a)} : IsOpen s ↔ ∀ f, f ∈ s → ∃ u : ∀ a, Set (A a), (∀ a, IsOpen (u a) ∧ f a ∈ u a) ∧ univ.pi u ⊆ s := by cases nonempty_fintype ι rw [isOpen_iff_nhds] simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff] refine forall₂_congr fun a _ => ⟨?_, ?_⟩ · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨fun i => (h1 i).choose, ⟨fun i => (h1 i).choose_spec.2, (pi_mono fun i _ => (h1 i).choose_spec.1).trans (Subset.trans ?_ h2)⟩⟩ rw [← pi_inter_compl (I : Set ι)] exact inter_subset_left · exact fun ⟨u, ⟨h1, _⟩⟩ => ⟨Finset.univ, u, ⟨fun i => ⟨u i, ⟨rfl.subset, h1 i⟩⟩, by rwa [Finset.coe_univ]⟩⟩ theorem isClosed_set_pi {i : Set ι} {s : ∀ a, Set (A a)} (hs : ∀ a ∈ i, IsClosed (s a)) : IsClosed (pi i s) := by rw [pi_def]; exact isClosed_biInter fun a ha => (hs _ ha).preimage (continuous_apply _) protected lemma Topology.IsClosedEmbedding.piMap {f : ∀ i, A i → B i} (hf : ∀ i, IsClosedEmbedding (f i)) : IsClosedEmbedding (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, by simpa using isClosed_set_pi fun i _ ↦ (hf i).2⟩ protected lemma Topology.IsOpenEmbedding.piMap [Finite ι] {f : ∀ i, A i → B i} (hf : ∀ i, IsOpenEmbedding (f i)) : IsOpenEmbedding (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, by simpa using isOpen_set_pi Set.finite_univ fun i _ ↦ (hf i).2⟩ theorem mem_nhds_of_pi_mem_nhds {I : Set ι} {s : ∀ i, Set (A i)} (a : ∀ i, A i) (hs : I.pi s ∈ 𝓝 a) {i : ι} (hi : i ∈ I) : s i ∈ 𝓝 (a i) := by rw [nhds_pi] at hs; exact mem_of_pi_mem_pi hs hi theorem set_pi_mem_nhds {i : Set ι} {s : ∀ a, Set (A a)} {x : ∀ a, A a} (hi : i.Finite) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by rw [pi_def, biInter_mem hi] exact fun a ha => (continuous_apply a).continuousAt (hs a ha) theorem set_pi_mem_nhds_iff {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (A i)} (a : ∀ i, A i) : I.pi s ∈ 𝓝 a ↔ ∀ i : ι, i ∈ I → s i ∈ 𝓝 (a i) := by rw [nhds_pi, pi_mem_pi_iff hI] theorem interior_pi_set {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (A i)} : interior (pi I s) = I.pi fun i => interior (s i) := by ext a simp only [Set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI] theorem exists_finset_piecewise_mem_of_mem_nhds [DecidableEq ι] {s : Set (∀ a, A a)} {x : ∀ a, A a} (hs : s ∈ 𝓝 x) (y : ∀ a, A a) : ∃ I : Finset ι, I.piecewise x y ∈ s := by simp only [nhds_pi, Filter.mem_pi'] at hs rcases hs with ⟨I, t, htx, hts⟩ refine ⟨I, hts fun i hi => ?_⟩ simpa [Finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i) theorem pi_generateFrom_eq {A : ι → Type*} {g : ∀ a, Set (Set (A a))} : (@Pi.topologicalSpace ι A fun a => generateFrom (g a)) = generateFrom { t | ∃ (s : ∀ a, Set (A a)) (i : Finset ι), (∀ a ∈ i, s a ∈ g a) ∧ t = pi (↑i) s } := by refine le_antisymm ?_ ?_ · apply le_generateFrom rintro _ ⟨s, i, hi, rfl⟩ letI := fun a => generateFrom (g a) exact isOpen_set_pi i.finite_toSet (fun a ha => GenerateOpen.basic _ (hi a ha)) · classical refine le_iInf fun i => coinduced_le_iff_le_induced.1 <| le_generateFrom fun s hs => ?_ refine GenerateOpen.basic _ ⟨update (fun i => univ) i s, {i}, ?_⟩ simp [hs] theorem pi_eq_generateFrom : Pi.topologicalSpace = generateFrom { g | ∃ (s : ∀ a, Set (A a)) (i : Finset ι), (∀ a ∈ i, IsOpen (s a)) ∧ g = pi (↑i) s } := calc Pi.topologicalSpace _ = @Pi.topologicalSpace ι A fun _ => generateFrom { s | IsOpen s } := by simp only [generateFrom_setOf_isOpen] _ = _ := pi_generateFrom_eq theorem pi_generateFrom_eq_finite {X : ι → Type*} {g : ∀ a, Set (Set (X a))} [Finite ι] (hg : ∀ a, ⋃₀ g a = univ) : (@Pi.topologicalSpace ι X fun a => generateFrom (g a)) = generateFrom { t | ∃ s : ∀ a, Set (X a), (∀ a, s a ∈ g a) ∧ t = pi univ s } := by cases nonempty_fintype ι rw [pi_generateFrom_eq] refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_) · exact fun s ⟨t, ht, Eq⟩ => ⟨t, Finset.univ, by simp [ht, Eq]⟩ · rintro s ⟨t, i, ht, rfl⟩ letI := generateFrom { t | ∃ s : ∀ a, Set (X a), (∀ a, s a ∈ g a) ∧ t = pi univ s } refine isOpen_iff_forall_mem_open.2 fun f hf => ?_ choose c hcg hfc using fun a => sUnion_eq_univ_iff.1 (hg a) (f a) refine ⟨pi i t ∩ pi ((↑i)ᶜ : Set ι) c, inter_subset_left, ?_, ⟨hf, fun a _ => hfc a⟩⟩ classical rw [← univ_pi_piecewise] refine GenerateOpen.basic _ ⟨_, fun a => ?_, rfl⟩ by_cases a ∈ i <;> simp [*] theorem induced_to_pi {X : Type*} (f : X → ∀ i, A i) : induced f Pi.topologicalSpace = ⨅ i, induced (f · i) inferInstance := by simp_rw [Pi.topologicalSpace, induced_iInf, induced_compose, Function.comp_def] /-- Suppose `A i` is a family of topological spaces indexed by `i : ι`, and `X` is a type endowed with a family of maps `f i : X → A i` for every `i : ι`, hence inducing a map `g : X → Π i, A i`. This lemma shows that infimum of the topologies on `X` induced by the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, A i` where `Π i, A i` is endowed with the usual product topology. -/ theorem inducing_iInf_to_pi {X : Type*} (f : ∀ i, X → A i) : @IsInducing X (∀ i, A i) (⨅ i, induced (f i) inferInstance) _ fun x i => f i x := letI := ⨅ i, induced (f i) inferInstance; ⟨(induced_to_pi _).symm⟩ variable [Finite ι] [∀ i, DiscreteTopology (A i)] /-- A finite product of discrete spaces is discrete. -/ instance Pi.discreteTopology : DiscreteTopology (∀ i, A i) := discreteTopology_iff_isOpen_singleton.mpr fun x => by rw [← univ_pi_singleton] exact isOpen_set_pi finite_univ fun i _ => (isOpen_discrete {x i}) lemma Function.Surjective.isEmbedding_comp {n m : Type*} (f : m → n) (hf : Function.Surjective f) : IsEmbedding ((· ∘ f) : (n → X) → (m → X)) := by refine ⟨isInducing_iff_nhds.mpr fun x ↦ ?_, hf.injective_comp_right⟩ simp only [nhds_pi, Filter.pi, Filter.comap_iInf, ← hf.iInf_congr, Filter.comap_comap, Function.comp_def] end Pi section Sigma variable {ι κ : Type*} {σ : ι → Type*} {τ : κ → Type*} [∀ i, TopologicalSpace (σ i)] [∀ k, TopologicalSpace (τ k)] [TopologicalSpace X] @[continuity, fun_prop] theorem continuous_sigmaMk {i : ι} : Continuous (@Sigma.mk ι σ i) := continuous_iSup_rng continuous_coinduced_rng theorem isOpen_sigma_iff {s : Set (Sigma σ)} : IsOpen s ↔ ∀ i, IsOpen (Sigma.mk i ⁻¹' s) := by rw [isOpen_iSup_iff] rfl theorem isClosed_sigma_iff {s : Set (Sigma σ)} : IsClosed s ↔ ∀ i, IsClosed (Sigma.mk i ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_sigma_iff, preimage_compl] theorem isOpenMap_sigmaMk {i : ι} : IsOpenMap (@Sigma.mk ι σ i) := by intro s hs rw [isOpen_sigma_iff] intro j rcases eq_or_ne j i with (rfl | hne) · rwa [preimage_image_eq _ sigma_mk_injective] · rw [preimage_image_sigmaMk_of_ne hne] exact isOpen_empty theorem isOpen_range_sigmaMk {i : ι} : IsOpen (range (@Sigma.mk ι σ i)) := isOpenMap_sigmaMk.isOpen_range theorem isClosedMap_sigmaMk {i : ι} : IsClosedMap (@Sigma.mk ι σ i) := by intro s hs rw [isClosed_sigma_iff] intro j rcases eq_or_ne j i with (rfl | hne) · rwa [preimage_image_eq _ sigma_mk_injective] · rw [preimage_image_sigmaMk_of_ne hne] exact isClosed_empty theorem isClosed_range_sigmaMk {i : ι} : IsClosed (range (@Sigma.mk ι σ i)) := isClosedMap_sigmaMk.isClosed_range lemma Topology.IsOpenEmbedding.sigmaMk {i : ι} : IsOpenEmbedding (@Sigma.mk ι σ i) := .of_continuous_injective_isOpenMap continuous_sigmaMk sigma_mk_injective isOpenMap_sigmaMk lemma Topology.IsClosedEmbedding.sigmaMk {i : ι} : IsClosedEmbedding (@Sigma.mk ι σ i) := .of_continuous_injective_isClosedMap continuous_sigmaMk sigma_mk_injective isClosedMap_sigmaMk lemma Topology.IsEmbedding.sigmaMk {i : ι} : IsEmbedding (@Sigma.mk ι σ i) := IsClosedEmbedding.sigmaMk.1 theorem Sigma.nhds_mk (i : ι) (x : σ i) : 𝓝 (⟨i, x⟩ : Sigma σ) = Filter.map (Sigma.mk i) (𝓝 x) := (IsOpenEmbedding.sigmaMk.map_nhds_eq x).symm theorem Sigma.nhds_eq (x : Sigma σ) : 𝓝 x = Filter.map (Sigma.mk x.1) (𝓝 x.2) := by cases x apply Sigma.nhds_mk theorem comap_sigmaMk_nhds (i : ι) (x : σ i) : comap (Sigma.mk i) (𝓝 ⟨i, x⟩) = 𝓝 x := (IsEmbedding.sigmaMk.nhds_eq_comap _).symm theorem isOpen_sigma_fst_preimage (s : Set ι) : IsOpen (Sigma.fst ⁻¹' s : Set (Σ a, σ a)) := by rw [← biUnion_of_singleton s, preimage_iUnion₂] simp only [← range_sigmaMk] exact isOpen_biUnion fun _ _ => isOpen_range_sigmaMk /-- A map out of a sum type is continuous iff its restriction to each summand is. -/ @[simp] theorem continuous_sigma_iff {f : Sigma σ → X} : Continuous f ↔ ∀ i, Continuous fun a => f ⟨i, a⟩ := by delta instTopologicalSpaceSigma rw [continuous_iSup_dom] exact forall_congr' fun _ => continuous_coinduced_dom /-- A map out of a sum type is continuous if its restriction to each summand is. -/ @[continuity, fun_prop] theorem continuous_sigma {f : Sigma σ → X} (hf : ∀ i, Continuous fun a => f ⟨i, a⟩) : Continuous f := continuous_sigma_iff.2 hf /-- A map defined on a sigma type (a.k.a. the disjoint union of an indexed family of topological spaces) is inducing iff its restriction to each component is inducing and each the image of each component under `f` can be separated from the images of all other components by an open set. -/ theorem inducing_sigma {f : Sigma σ → X} : IsInducing f ↔ (∀ i, IsInducing (f ∘ Sigma.mk i)) ∧ (∀ i, ∃ U, IsOpen U ∧ ∀ x, f x ∈ U ↔ x.1 = i) := by refine ⟨fun h ↦ ⟨fun i ↦ h.comp IsEmbedding.sigmaMk.1, fun i ↦ ?_⟩, ?_⟩ · rcases h.isOpen_iff.1 (isOpen_range_sigmaMk (i := i)) with ⟨U, hUo, hU⟩ refine ⟨U, hUo, ?_⟩ simpa [Set.ext_iff] using hU · refine fun ⟨h₁, h₂⟩ ↦ isInducing_iff_nhds.2 fun ⟨i, x⟩ ↦ ?_ rw [Sigma.nhds_mk, (h₁ i).nhds_eq_comap, comp_apply, ← comap_comap, map_comap_of_mem] rcases h₂ i with ⟨U, hUo, hU⟩ filter_upwards [preimage_mem_comap <| hUo.mem_nhds <| (hU _).2 rfl] with y hy simpa [hU] using hy @[simp 1100] theorem continuous_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} : Continuous (Sigma.map f₁ f₂) ↔ ∀ i, Continuous (f₂ i) := continuous_sigma_iff.trans <| by simp only [Sigma.map, IsEmbedding.sigmaMk.continuous_iff, comp_def] @[continuity, fun_prop] theorem Continuous.sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (hf : ∀ i, Continuous (f₂ i)) : Continuous (Sigma.map f₁ f₂) := continuous_sigma_map.2 hf theorem isOpenMap_sigma {f : Sigma σ → X} : IsOpenMap f ↔ ∀ i, IsOpenMap fun a => f ⟨i, a⟩ := by simp only [isOpenMap_iff_nhds_le, Sigma.forall, Sigma.nhds_eq, map_map, comp_def] theorem isOpenMap_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} : IsOpenMap (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenMap (f₂ i) := isOpenMap_sigma.trans <| forall_congr' fun i => (@IsOpenEmbedding.sigmaMk _ _ _ (f₁ i)).isOpenMap_iff.symm lemma Topology.isInducing_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h₁ : Injective f₁) : IsInducing (Sigma.map f₁ f₂) ↔ ∀ i, IsInducing (f₂ i) := by simp only [isInducing_iff_nhds, Sigma.forall, Sigma.nhds_mk, Sigma.map_mk, ← map_sigma_mk_comap h₁, map_inj sigma_mk_injective] lemma Topology.isEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) : IsEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsEmbedding (f₂ i) := by simp only [isEmbedding_iff, isInducing_sigmaMap h, forall_and, h.sigma_map_iff] lemma Topology.isOpenEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) : IsOpenEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenEmbedding (f₂ i) := by simp only [isOpenEmbedding_iff_isEmbedding_isOpenMap, isOpenMap_sigma_map, isEmbedding_sigmaMap h, forall_and] end Sigma section ULift theorem ULift.isOpen_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} : IsOpen s ↔ IsOpen (ULift.up ⁻¹' s) := by rw [ULift.topologicalSpace, ← Equiv.ulift_apply, ← Equiv.ulift.coinduced_symm, ← isOpen_coinduced] theorem ULift.isClosed_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} : IsClosed s ↔ IsClosed (ULift.up ⁻¹' s) := by rw [← isOpen_compl_iff, ← isOpen_compl_iff, isOpen_iff, preimage_compl] @[continuity, fun_prop] theorem continuous_uliftDown [TopologicalSpace X] : Continuous (ULift.down : ULift.{v, u} X → X) := continuous_induced_dom @[continuity, fun_prop] theorem continuous_uliftUp [TopologicalSpace X] : Continuous (ULift.up : X → ULift.{v, u} X) := continuous_induced_rng.2 continuous_id @[continuity, fun_prop] theorem continuous_uliftMap [TopologicalSpace X] [TopologicalSpace Y] (f : X → Y) (hf : Continuous f) : Continuous (ULift.map f : ULift.{u'} X → ULift.{v'} Y) := by change Continuous (ULift.up ∘ f ∘ ULift.down) fun_prop @[fun_prop] lemma Topology.IsEmbedding.uliftDown [TopologicalSpace X] : IsEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨⟨rfl⟩, ULift.down_injective⟩ @[fun_prop] lemma Topology.IsClosedEmbedding.uliftDown [TopologicalSpace X] : IsClosedEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨.uliftDown, by simp only [ULift.down_surjective.range_eq, isClosed_univ]⟩ instance [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (ULift X) := IsEmbedding.uliftDown.discreteTopology end ULift section Monad variable [TopologicalSpace X] {s : Set X} {t : Set s} theorem IsOpen.trans (ht : IsOpen t) (hs : IsOpen s) : IsOpen (t : Set X) := by rcases isOpen_induced_iff.mp ht with ⟨s', hs', rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hs' theorem IsClosed.trans (ht : IsClosed t) (hs : IsClosed s) : IsClosed (t : Set X) := by rcases isClosed_induced_iff.mp ht with ⟨s', hs', rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hs' end Monad section NhdsSet variable [TopologicalSpace X] [TopologicalSpace Y] {s : Set X} {t : Set Y} /-- The product of a neighborhood of `s` and a neighborhood of `t` is a neighborhood of `s ×ˢ t`, formulated in terms of a filter inequality. -/ theorem nhdsSet_prod_le (s : Set X) (t : Set Y) : 𝓝ˢ (s ×ˢ t) ≤ 𝓝ˢ s ×ˢ 𝓝ˢ t := ((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).ge_iff.2 fun (_u, _v) ⟨⟨huo, hsu⟩, hvo, htv⟩ ↦ (huo.prod hvo).mem_nhdsSet.2 <| prod_mono hsu htv theorem Filter.eventually_nhdsSet_prod_iff {p : X × Y → Prop} : (∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q) ↔ ∀ x ∈ s, ∀ y ∈ t, ∃ px : X → Prop, (∀ᶠ x' in 𝓝 x, px x') ∧ ∃ py : Y → Prop, (∀ᶠ y' in 𝓝 y, py y') ∧ ∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y) := by simp_rw [eventually_nhdsSet_iff_forall, forall_prod_set, nhds_prod_eq, eventually_prod_iff] theorem Filter.Eventually.prod_nhdsSet {p : X × Y → Prop} {px : X → Prop} {py : Y → Prop} (hp : ∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y)) (hs : ∀ᶠ x in 𝓝ˢ s, px x) (ht : ∀ᶠ y in 𝓝ˢ t, py y) : ∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q := nhdsSet_prod_le _ _ (mem_of_superset (prod_mem_prod hs ht) fun _ ⟨hx, hy⟩ ↦ hp hx hy) end NhdsSet
.lake/packages/mathlib/Mathlib/Topology/Path.lean
import Mathlib.Topology.Order.ProjIcc import Mathlib.Topology.CompactOpen import Mathlib.Topology.UnitInterval /-! # Paths in topological spaces This file introduces continuous paths and provides API for them. ## Main definitions In this file the unit interval `[0, 1]` in `ℝ` is denoted by `I`, and `X` is a topological space. * `Path x y` is the type of paths from `x` to `y`, i.e., continuous maps from `I` to `X` mapping `0` to `x` and `1` to `y`. * `Path.refl x : Path x x` is the constant path at `x`. * `Path.symm γ : Path y x` is the reverse of a path `γ : Path x y`. * `Path.trans γ γ' : Path x z` is the concatenation of two paths `γ : Path x y`, `γ' : Path y z`. * `Path.map γ hf : Path (f x) (f y)` is the image of `γ : Path x y` under a continuous map `f`. * `Path.reparam γ f hf hf₀ hf₁ : Path x y` is the reparametrisation of `γ : Path x y` by a continuous map `f : I → I` fixing `0` and `1`. * `Path.truncate γ t₀ t₁ : Path (γ t₀) (γ t₁)` is the path that follows `γ` from `t₀` to `t₁` and stays constant otherwise. * `Path.extend γ : C(ℝ, X)` is the extension `γ` to `ℝ` that is constant before `0` and after `1`. `Path x y` is equipped with the topology induced by the compact-open topology on `C(I,X)`, and several of the above constructions are shown to be continuous. ## Implementation notes By default, all paths have `I` as their source and `X` as their target, but there is an operation `Set.IccExtend` that will extend any continuous map `γ : I → X` into a continuous map `IccExtend zero_le_one γ : ℝ → X` that is constant before `0` and after `1`. This is used to define `Path.extend` that turns `γ : Path x y` into a continuous map `γ.extend : ℝ → X` whose restriction to `I` is the original `γ`, and is equal to `x` on `(-∞, 0]` and to `y` on `[1, +∞)`. -/ noncomputable section open Topology Filter unitInterval Set Function variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {x y z : X} {ι : Type*} /-! ### Paths -/ /-- Continuous path connecting two points `x` and `y` in a topological space -/ structure Path (x y : X) extends C(I, X) where /-- The start point of a `Path`. -/ source' : toFun 0 = x /-- The end point of a `Path`. -/ target' : toFun 1 = y instance Path.instFunLike : FunLike (Path x y) I X where coe γ := ⇑γ.toContinuousMap coe_injective' γ₁ γ₂ h := by simp only [DFunLike.coe_fn_eq] at h cases γ₁; cases γ₂; congr instance Path.continuousMapClass : ContinuousMapClass (Path x y) I X where map_continuous γ := show Continuous γ.toContinuousMap by fun_prop @[ext] protected theorem Path.ext : ∀ {γ₁ γ₂ : Path x y}, (γ₁ : I → X) = γ₂ → γ₁ = γ₂ := by rintro ⟨⟨x, h11⟩, h12, h13⟩ ⟨⟨x, h21⟩, h22, h23⟩ rfl rfl namespace Path /-- A path constructed from a continuous map `f` has the same underlying function. -/ @[simp] theorem coe_mk' (f : C(I, X)) (h₁ h₂) : ⇑(mk f h₁ h₂ : Path x y) = f := rfl theorem coe_mk_mk (f : I → X) (h₁) (h₂ : f 0 = x) (h₃ : f 1 = y) : ⇑(mk ⟨f, h₁⟩ h₂ h₃ : Path x y) = f := rfl variable (γ : Path x y) @[continuity] protected theorem continuous : Continuous γ := γ.continuous_toFun @[simp] protected theorem source : γ 0 = x := γ.source' @[simp] protected theorem target : γ 1 = y := γ.target' /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def simps.apply : I → X := γ initialize_simps_projections Path (toFun → simps.apply, -toContinuousMap) @[simp] theorem coe_toContinuousMap : ⇑γ.toContinuousMap = γ := rfl /-- A special version of `ContinuousMap.coe_coe`. When you delete this deprecated lemma, please rename `Path.coe_mk'` to `Path.coe_mk`. -/ @[deprecated ContinuousMap.coe_coe (since := "2025-05-02")] theorem coe_mk : ⇑(γ : C(I, X)) = γ := rfl @[simp] theorem range_coe : range ((↑) : Path x y → C(I, X)) = {f | f 0 = x ∧ f 1 = y} := Subset.antisymm (range_subset_iff.mpr fun γ ↦ ⟨γ.source, γ.target⟩) fun f ⟨hf₀, hf₁⟩ ↦ ⟨⟨f, hf₀, hf₁⟩, rfl⟩ /-- Any function `φ : Π (a : α), Path (x a) (y a)` can be seen as a function `α × I → X`. -/ instance instHasUncurryPath {α : Type*} {x y : α → X} : HasUncurry (∀ a : α, Path (x a) (y a)) (α × I) X := ⟨fun φ p => φ p.1 p.2⟩ @[simp high] lemma source_mem_range (γ : Path x y) : x ∈ range ⇑γ := ⟨0, Path.source γ⟩ @[simp high] lemma target_mem_range (γ : Path x y) : y ∈ range ⇑γ := ⟨1, Path.target γ⟩ /-- The constant path from a point to itself -/ @[refl, simps!] def refl (x : X) : Path x x where toContinuousMap := .const I x source' := rfl target' := rfl @[simp] theorem refl_range {a : X} : range (Path.refl a) = {a} := range_const /-- The reverse of a path from `x` to `y`, as a path from `y` to `x` -/ @[symm, simps] def symm (γ : Path x y) : Path y x where toFun := γ ∘ σ continuous_toFun := by fun_prop source' := by simp target' := by simp @[simp] theorem symm_symm (γ : Path x y) : γ.symm.symm = γ := by ext t change γ (σ (σ t)) = γ t rw [unitInterval.symm_symm] theorem symm_bijective : Function.Bijective (Path.symm : Path x y → Path y x) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem refl_symm {a : X} : (Path.refl a).symm = Path.refl a := rfl @[simp] theorem symm_range {a b : X} (γ : Path a b) : range γ.symm = range γ := symm_involutive.surjective.range_comp γ /-! #### Space of paths -/ open ContinuousMap /-- The following instance defines the topology on the path space to be induced from the compact-open topology on the space `C(I,X)` of continuous maps from `I` to `X`. -/ instance instTopologicalSpace : TopologicalSpace (Path x y) := TopologicalSpace.induced ((↑) : _ → C(I, X)) ContinuousMap.compactOpen instance : ContinuousEval (Path x y) I X := .of_continuous_forget continuous_induced_dom theorem continuous_uncurry_iff {Y} [TopologicalSpace Y] {g : Y → Path x y} : Continuous ↿g ↔ Continuous g := Iff.symm <| continuous_induced_rng.trans ⟨fun h => continuous_uncurry_of_continuous ⟨_, h⟩, continuous_of_continuous_uncurry (fun (y : Y) ↦ ContinuousMap.mk (g y))⟩ /-- A continuous map extending a path to `ℝ`, constant before `0` and after `1`. -/ def extend : C(ℝ, X) where toFun := IccExtend zero_le_one γ /-- See Note [continuity lemma statement]. -/ @[continuity, fun_prop] theorem _root_.Continuous.pathExtend {γ : Y → Path x y} {f : Y → ℝ} (hγ : Continuous ↿γ) (hf : Continuous f) : Continuous fun t => (γ t).extend (f t) := Continuous.IccExtend hγ hf @[deprecated (since := "2025-05-02")] alias _root_.Continuous.path_extend := Continuous.pathExtend /-- A useful special case of `Continuous.path_extend`. -/ theorem continuous_extend : Continuous γ.extend := γ.continuous.Icc_extend' theorem _root_.Filter.Tendsto.pathExtend {l r : Y → X} {y : Y} {l₁ : Filter ℝ} {l₂ : Filter X} {γ : ∀ y, Path (l y) (r y)} (hγ : Tendsto ↿γ (𝓝 y ×ˢ l₁.map (projIcc 0 1 zero_le_one)) l₂) : Tendsto (↿fun x => ⇑(γ x).extend) (𝓝 y ×ˢ l₁) l₂ := Filter.Tendsto.IccExtend _ hγ @[deprecated (since := "2025-05-02")] alias _root_.Filter.Tendsto.path_extend := Filter.Tendsto.pathExtend theorem _root_.ContinuousAt.pathExtend {g : Y → ℝ} {l r : Y → X} (γ : ∀ y, Path (l y) (r y)) {y : Y} (hγ : ContinuousAt ↿γ (y, projIcc 0 1 zero_le_one (g y))) (hg : ContinuousAt g y) : ContinuousAt (fun i => (γ i).extend (g i)) y := hγ.IccExtend (fun x => γ x) hg @[deprecated (since := "2025-05-02")] alias _root_.ContinuousAt.path_extend := ContinuousAt.pathExtend @[simp] theorem extend_extends {a b : X} (γ : Path a b) {t : ℝ} (ht : t ∈ (Icc 0 1 : Set ℝ)) : γ.extend t = γ ⟨t, ht⟩ := IccExtend_of_mem _ γ ht theorem extend_zero : γ.extend 0 = x := by simp theorem extend_one : γ.extend 1 = y := by simp theorem extend_extends' {a b : X} (γ : Path a b) (t : (Icc 0 1 : Set ℝ)) : γ.extend t = γ t := IccExtend_val _ γ t @[simp] theorem extend_range {a b : X} (γ : Path a b) : range γ.extend = range γ := IccExtend_range _ γ theorem image_extend_of_subset (γ : Path x y) {s : Set ℝ} (h : I ⊆ s) : γ.extend '' s = range γ := (γ.extend_range ▸ image_subset_range _ _).antisymm <| range_subset_iff.mpr <| fun t ↦ ⟨t, h t.2, extend_extends' _ _⟩ theorem extend_of_le_zero {a b : X} (γ : Path a b) {t : ℝ} (ht : t ≤ 0) : γ.extend t = a := (IccExtend_of_le_left _ _ ht).trans γ.source theorem extend_of_one_le {a b : X} (γ : Path a b) {t : ℝ} (ht : 1 ≤ t) : γ.extend t = b := (IccExtend_of_right_le _ _ ht).trans γ.target @[simp] theorem refl_extend {a : X} : (Path.refl a).extend = .const ℝ a := rfl theorem extend_symm_apply (γ : Path x y) (t : ℝ) : γ.symm.extend t = γ.extend (1 - t) := congrArg γ <| symm_projIcc _ @[simp] theorem extend_symm (γ : Path x y) : γ.symm.extend = (γ.extend <| 1 - ·) := funext γ.extend_symm_apply /-- The path obtained from a map defined on `ℝ` by restriction to the unit interval. -/ def ofLine {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) : Path x y where toFun := f ∘ ((↑) : unitInterval → ℝ) continuous_toFun := hf.comp_continuous continuous_subtype_val Subtype.prop source' := h₀ target' := h₁ theorem ofLine_mem {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) : ∀ t, ofLine hf h₀ h₁ t ∈ f '' I := fun ⟨t, t_in⟩ => ⟨t, t_in, rfl⟩ @[simp] theorem ofLine_extend (γ : Path x y) : ofLine (by fun_prop) (extend_zero γ) (extend_one γ) = γ := by ext t simp [ofLine] attribute [local simp] Iic_def /-- Concatenation of two paths from `x` to `y` and from `y` to `z`, putting the first path on `[0, 1/2]` and the second one on `[1/2, 1]`. -/ @[trans] def trans (γ : Path x y) (γ' : Path y z) : Path x z where toFun := (fun t : ℝ => if t ≤ 1 / 2 then γ.extend (2 * t) else γ'.extend (2 * t - 1)) ∘ (↑) continuous_toFun := by refine (Continuous.if_le ?_ ?_ continuous_id continuous_const (by simp)).comp continuous_subtype_val <;> fun_prop source' := by simp target' := by norm_num theorem trans_apply (γ : Path x y) (γ' : Path y z) (t : I) : (γ.trans γ') t = if h : (t : ℝ) ≤ 1 / 2 then γ ⟨2 * t, (mul_pos_mem_iff zero_lt_two).2 ⟨t.2.1, h⟩⟩ else γ' ⟨2 * t - 1, two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, t.2.2⟩⟩ := show ite _ _ _ = _ by split_ifs <;> rw [extend_extends] @[simp] theorem trans_symm (γ : Path x y) (γ' : Path y z) : (γ.trans γ').symm = γ'.symm.trans γ.symm := by ext t simp only [trans_apply, symm_apply, Function.comp_apply] split_ifs with h h₁ h₂ <;> rw [coe_symm_eq] at h · have ht : (t : ℝ) = 1 / 2 := by linarith norm_num [ht] · refine congr_arg _ (Subtype.ext ?_) norm_num [sub_sub_eq_add_sub, mul_sub] · refine congr_arg _ (Subtype.ext ?_) simp only [coe_symm_eq] ring · exfalso linarith theorem extend_trans_of_le_half (γ₁ : Path x y) (γ₂ : Path y z) {t : ℝ} (ht : t ≤ 1 / 2) : (γ₁.trans γ₂).extend t = γ₁.extend (2 * t) := by obtain _ | ht₀ := le_total t 0 · repeat rw [extend_of_le_zero _ (by linarith)] · rwa [extend_extends _ ⟨ht₀, by linarith⟩, trans_apply, dif_pos, extend_extends] theorem extend_trans_of_half_le (γ₁ : Path x y) (γ₂ : Path y z) {t : ℝ} (ht : 1 / 2 ≤ t) : (γ₁.trans γ₂).extend t = γ₂.extend (2 * t - 1) := by conv_lhs => rw [← sub_sub_cancel 1 t] rw [← extend_symm_apply, trans_symm, extend_trans_of_le_half _ _ (by linarith), extend_symm_apply] congr 1 linarith @[simp] theorem refl_trans_refl {a : X} : (Path.refl a).trans (Path.refl a) = Path.refl a := by ext simp [Path.trans] theorem trans_range {a b c : X} (γ₁ : Path a b) (γ₂ : Path b c) : range (γ₁.trans γ₂) = range γ₁ ∪ range γ₂ := by rw [← extend_range, ← image_univ, ← Iic_union_Ici (a := 1 / 2), image_union, EqOn.image_eq fun t ht ↦ extend_trans_of_le_half _ _ (mem_Iic.1 ht), EqOn.image_eq fun t ht ↦ extend_trans_of_half_le _ _ (mem_Ici.1 ht), ← image_image γ₁.extend, ← image_image (γ₂.extend <| · - 1), ← image_image γ₂.extend] norm_num [image_mul_left_Ici, image_mul_left_Iic, image_extend_of_subset, Icc_subset_Iic_self, Icc_subset_Ici_self] /-- Image of a path from `x` to `y` by a map which is continuous on the path. -/ def map' (γ : Path x y) {f : X → Y} (h : ContinuousOn f (range γ)) : Path (f x) (f y) where toFun := f ∘ γ continuous_toFun := h.comp_continuous γ.continuous (fun x ↦ mem_range_self x) source' := by simp target' := by simp /-- Image of a path from `x` to `y` by a continuous map -/ def map (γ : Path x y) {f : X → Y} (h : Continuous f) : Path (f x) (f y) := γ.map' h.continuousOn @[simp] theorem map_coe (γ : Path x y) {f : X → Y} (h : Continuous f) : (γ.map h : I → Y) = f ∘ γ := by ext t rfl @[simp] theorem map_symm (γ : Path x y) {f : X → Y} (h : Continuous f) : (γ.map h).symm = γ.symm.map h := rfl @[simp] theorem map_trans (γ : Path x y) (γ' : Path y z) {f : X → Y} (h : Continuous f) : (γ.trans γ').map h = (γ.map h).trans (γ'.map h) := by ext t rw [trans_apply, map_coe, Function.comp_apply, trans_apply] split_ifs <;> rfl @[simp] theorem map_id (γ : Path x y) : γ.map continuous_id = γ := by ext rfl @[simp] theorem map_map (γ : Path x y) {Z : Type*} [TopologicalSpace Z] {f : X → Y} (hf : Continuous f) {g : Y → Z} (hg : Continuous g) : (γ.map hf).map hg = γ.map (hg.comp hf) := by ext rfl /-- Casting a path from `x` to `y` to a path from `x'` to `y'` when `x' = x` and `y' = y` -/ def cast (γ : Path x y) {x' y'} (hx : x' = x) (hy : y' = y) : Path x' y' where toFun := γ continuous_toFun := γ.continuous source' := by simp [hx] target' := by simp [hy] @[simp] theorem cast_rfl_rfl (γ : Path x y) : γ.cast rfl rfl = γ := rfl @[simp] theorem symm_cast {a₁ a₂ b₁ b₂ : X} (γ : Path a₂ b₂) (ha : a₁ = a₂) (hb : b₁ = b₂) : (γ.cast ha hb).symm = γ.symm.cast hb ha := rfl @[simp] theorem trans_cast {a₁ a₂ b₁ b₂ c₁ c₂ : X} (γ : Path a₂ b₂) (γ' : Path b₂ c₂) (ha : a₁ = a₂) (hb : b₁ = b₂) (hc : c₁ = c₂) : (γ.cast ha hb).trans (γ'.cast hb hc) = (γ.trans γ').cast ha hc := rfl @[simp] theorem extend_cast {x' y'} (γ : Path x y) (hx : x' = x) (hy : y' = y) : (γ.cast hx hy).extend = γ.extend := rfl @[simp] theorem cast_coe (γ : Path x y) {x' y'} (hx : x' = x) (hy : y' = y) : (γ.cast hx hy : I → X) = γ := rfl lemma bijective_cast {x' y' : X} (hx : x' = x) (hy : y' = y) : Bijective (Path.cast · hx hy) := by subst_vars; exact bijective_id @[congr] lemma exists_congr {x₁ x₂ y₁ y₂ : X} {p : Path x₁ y₁ → Prop} (hx : x₁ = x₂) (hy : y₁ = y₂) : (∃ γ, p γ) ↔ (∃ (γ : Path x₂ y₂), p (γ.cast hx hy)) := bijective_cast hx hy |>.surjective.exists @[continuity, fun_prop] theorem symm_continuous_family {ι : Type*} [TopologicalSpace ι] {a b : ι → X} (γ : ∀ t : ι, Path (a t) (b t)) (h : Continuous ↿γ) : Continuous ↿fun t => (γ t).symm := h.comp (continuous_id.prodMap continuous_symm) @[continuity] theorem continuous_symm : Continuous (symm : Path x y → Path y x) := continuous_uncurry_iff.mp <| symm_continuous_family _ (by fun_prop) @[continuity] theorem continuous_uncurry_extend_of_continuous_family {ι : Type*} [TopologicalSpace ι] {a b : ι → X} (γ : ∀ t : ι, Path (a t) (b t)) (h : Continuous ↿γ) : Continuous ↿fun t => ⇑(γ t).extend := by apply h.comp (continuous_id.prodMap continuous_projIcc) exact zero_le_one @[continuity] theorem trans_continuous_family {ι : Type*} [TopologicalSpace ι] {a b c : ι → X} (γ₁ : ∀ t : ι, Path (a t) (b t)) (h₁ : Continuous ↿γ₁) (γ₂ : ∀ t : ι, Path (b t) (c t)) (h₂ : Continuous ↿γ₂) : Continuous ↿fun t => (γ₁ t).trans (γ₂ t) := by have h₁' := Path.continuous_uncurry_extend_of_continuous_family γ₁ h₁ have h₂' := Path.continuous_uncurry_extend_of_continuous_family γ₂ h₂ simp only [HasUncurry.uncurry, Path.trans] refine Continuous.if_le ?_ ?_ (continuous_subtype_val.comp continuous_snd) continuous_const ?_ · change Continuous ((fun p : ι × ℝ => (γ₁ p.1).extend p.2) ∘ Prod.map id (fun x => 2 * x : I → ℝ)) exact h₁'.comp (continuous_id.prodMap <| continuous_const.mul continuous_subtype_val) · change Continuous ((fun p : ι × ℝ => (γ₂ p.1).extend p.2) ∘ Prod.map id (fun x => 2 * x - 1 : I → ℝ)) exact h₂'.comp (continuous_id.prodMap <| (continuous_const.mul continuous_subtype_val).sub continuous_const) · rintro st hst simp [hst] @[continuity, fun_prop] theorem _root_.Continuous.path_trans {f : Y → Path x y} {g : Y → Path y z} : Continuous f → Continuous g → Continuous fun t => (f t).trans (g t) := by intro hf hg apply continuous_uncurry_iff.mp exact trans_continuous_family _ (continuous_uncurry_iff.mpr hf) _ (continuous_uncurry_iff.mpr hg) @[continuity, fun_prop] theorem continuous_trans {x y z : X} : Continuous fun ρ : Path x y × Path y z => ρ.1.trans ρ.2 := by fun_prop /-! #### Product of paths -/ section Prod variable {a₁ a₂ a₃ : X} {b₁ b₂ b₃ : Y} /-- Given a path in `X` and a path in `Y`, we can take their pointwise product to get a path in `X × Y`. -/ protected def prod (γ₁ : Path a₁ a₂) (γ₂ : Path b₁ b₂) : Path (a₁, b₁) (a₂, b₂) where toContinuousMap := ContinuousMap.prodMk γ₁.toContinuousMap γ₂.toContinuousMap source' := by simp target' := by simp @[simp] theorem prod_coe (γ₁ : Path a₁ a₂) (γ₂ : Path b₁ b₂) : ⇑(γ₁.prod γ₂) = fun t => (γ₁ t, γ₂ t) := rfl /-- Path composition commutes with products -/ theorem trans_prod_eq_prod_trans (γ₁ : Path a₁ a₂) (δ₁ : Path a₂ a₃) (γ₂ : Path b₁ b₂) (δ₂ : Path b₂ b₃) : (γ₁.prod γ₂).trans (δ₁.prod δ₂) = (γ₁.trans δ₁).prod (γ₂.trans δ₂) := by ext t <;> unfold Path.trans <;> simp only [Path.coe_mk_mk, Path.prod_coe, Function.comp_apply] <;> split_ifs <;> rfl end Prod section Pi variable {χ : ι → Type*} [∀ i, TopologicalSpace (χ i)] {as bs cs : ∀ i, χ i} /-- Given a family of paths, one in each Xᵢ, we take their pointwise product to get a path in Π i, Xᵢ. -/ protected def pi (γ : ∀ i, Path (as i) (bs i)) : Path as bs where toContinuousMap := ContinuousMap.pi fun i => (γ i).toContinuousMap source' := by simp target' := by simp @[simp] theorem pi_coe (γ : ∀ i, Path (as i) (bs i)) : ⇑(Path.pi γ) = fun t i => γ i t := rfl /-- Path composition commutes with products -/ theorem trans_pi_eq_pi_trans (γ₀ : ∀ i, Path (as i) (bs i)) (γ₁ : ∀ i, Path (bs i) (cs i)) : (Path.pi γ₀).trans (Path.pi γ₁) = Path.pi fun i => (γ₀ i).trans (γ₁ i) := by ext t i unfold Path.trans simp only [Path.coe_mk_mk, Function.comp_apply, pi_coe] split_ifs <;> rfl end Pi /-! #### Pointwise operations on paths in a topological (additive) group -/ /-- Pointwise multiplication of paths in a topological group. -/ @[to_additive (attr := simps!) /-- Pointwise addition of paths in a topological additive group. -/] protected def mul [Mul X] [ContinuousMul X] {a₁ b₁ a₂ b₂ : X} (γ₁ : Path a₁ b₁) (γ₂ : Path a₂ b₂) : Path (a₁ * a₂) (b₁ * b₂) := (γ₁.prod γ₂).map continuous_mul /-- Pointwise inversion of paths in a topological group. -/ @[to_additive (attr := simps!) /-- Pointwise negation of paths in a topological group. -/] def inv {a b : X} [Inv X] [ContinuousInv X] (γ : Path a b) : Path a⁻¹ b⁻¹ := γ.map continuous_inv /-! #### Truncating a path -/ /-- `γ.truncate t₀ t₁` is the path which follows the path `γ` on the time interval `[t₀, t₁]` and stays still otherwise. -/ def truncate {X : Type*} [TopologicalSpace X] {a b : X} (γ : Path a b) (t₀ t₁ : ℝ) : Path (γ.extend <| min t₀ t₁) (γ.extend t₁) where toFun s := γ.extend (min (max s t₀) t₁) continuous_toFun := γ.continuous_extend.comp ((continuous_subtype_val.max continuous_const).min continuous_const) source' := by simp only [min_def, max_def'] split_ifs with h₁ h₂ h₃ h₄ · simp [γ.extend_of_le_zero h₁] · congr linarith · have h₄ : t₁ ≤ 0 := le_of_lt (by simpa using h₂) simp [γ.extend_of_le_zero h₄, γ.extend_of_le_zero h₁] all_goals rfl target' := by simp only [min_def, max_def'] split_ifs with h₁ h₂ h₃ · simp [γ.extend_of_one_le h₂] · rfl · have h₄ : 1 ≤ t₀ := le_of_lt (by simpa using h₁) simp [γ.extend_of_one_le h₄, γ.extend_of_one_le (h₄.trans h₃)] · rfl /-- `γ.truncateOfLE t₀ t₁ h`, where `h : t₀ ≤ t₁` is `γ.truncate t₀ t₁` casted as a path from `γ.extend t₀` to `γ.extend t₁`. -/ def truncateOfLE {X : Type*} [TopologicalSpace X] {a b : X} (γ : Path a b) {t₀ t₁ : ℝ} (h : t₀ ≤ t₁) : Path (γ.extend t₀) (γ.extend t₁) := (γ.truncate t₀ t₁).cast (by rw [min_eq_left h]) rfl theorem truncate_range {a b : X} (γ : Path a b) {t₀ t₁ : ℝ} : range (γ.truncate t₀ t₁) ⊆ range γ := by rw [← γ.extend_range] simp only [range_subset_iff, SetCoe.forall] intro x _hx simp only [DFunLike.coe, Path.truncate, mem_range_self] /-- For a path `γ`, `γ.truncate` gives a "continuous family of paths", by which we mean the uncurried function which maps `(t₀, t₁, s)` to `γ.truncate t₀ t₁ s` is continuous. -/ @[continuity] theorem truncate_continuous_family {a b : X} (γ : Path a b) : Continuous (fun x => γ.truncate x.1 x.2.1 x.2.2 : ℝ × ℝ × I → X) := γ.continuous_extend.comp (((continuous_subtype_val.comp (continuous_snd.comp continuous_snd)).max continuous_fst).min (continuous_fst.comp continuous_snd)) @[continuity] theorem truncate_const_continuous_family {a b : X} (γ : Path a b) (t : ℝ) : Continuous ↿(γ.truncate t) := by have key : Continuous (fun x => (t, x) : ℝ × I → ℝ × ℝ × I) := by fun_prop exact γ.truncate_continuous_family.comp key @[simp] theorem truncate_self {a b : X} (γ : Path a b) (t : ℝ) : γ.truncate t t = (Path.refl <| γ.extend t).cast (by rw [min_self]) rfl := by ext x by_cases hx : x ≤ t <;> simp [truncate] theorem truncate_zero_zero {a b : X} (γ : Path a b) : γ.truncate 0 0 = (Path.refl a).cast (by rw [min_self, γ.extend_zero]) γ.extend_zero := by convert γ.truncate_self 0 theorem truncate_one_one {a b : X} (γ : Path a b) : γ.truncate 1 1 = (Path.refl b).cast (by rw [min_self, γ.extend_one]) γ.extend_one := by convert γ.truncate_self 1 @[simp] theorem truncate_zero_one {a b : X} (γ : Path a b) : γ.truncate 0 1 = γ.cast (by simp) (by simp) := by ext x rw [cast_coe] have : ↑x ∈ (Icc 0 1 : Set ℝ) := x.2 rw [truncate, coe_mk_mk, max_eq_left this.1, min_eq_left this.2, extend_extends'] /-! #### Reparametrising a path -/ /-- Given a path `γ` and a function `f : I → I` where `f 0 = 0` and `f 1 = 1`, `γ.reparam f` is the path defined by `γ ∘ f`. -/ def reparam (γ : Path x y) (f : I → I) (hfcont : Continuous f) (hf₀ : f 0 = 0) (hf₁ : f 1 = 1) : Path x y where toFun := γ ∘ f continuous_toFun := by fun_prop source' := by simp [hf₀] target' := by simp [hf₁] @[simp] theorem coe_reparam (γ : Path x y) {f : I → I} (hfcont : Continuous f) (hf₀ : f 0 = 0) (hf₁ : f 1 = 1) : ⇑(γ.reparam f hfcont hf₀ hf₁) = γ ∘ f := rfl @[simp] theorem reparam_id (γ : Path x y) : γ.reparam id continuous_id rfl rfl = γ := by ext rfl theorem range_reparam (γ : Path x y) {f : I → I} (hfcont : Continuous f) (hf₀ : f 0 = 0) (hf₁ : f 1 = 1) : range (γ.reparam f hfcont hf₀ hf₁) = range γ := by change range (γ ∘ f) = range γ have : range f = univ := by rw [range_eq_univ] intro t have h₁ : Continuous (Set.IccExtend (zero_le_one' ℝ) f) := by fun_prop have := intermediate_value_Icc (zero_le_one' ℝ) h₁.continuousOn · rw [IccExtend_left, IccExtend_right, Icc.mk_zero, Icc.mk_one, hf₀, hf₁] at this rcases this t.2 with ⟨w, hw₁, hw₂⟩ rw [IccExtend_of_mem _ _ hw₁] at hw₂ exact ⟨_, hw₂⟩ rw [range_comp, this, image_univ] theorem refl_reparam {f : I → I} (hfcont : Continuous f) (hf₀ : f 0 = 0) (hf₁ : f 1 = 1) : (refl x).reparam f hfcont hf₀ hf₁ = refl x := by ext simp end Path
.lake/packages/mathlib/Mathlib/Topology/Sober.lean
import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.Sets.OpenCover import Mathlib.Algebra.HierarchyDesign /-! # Sober spaces A quasi-sober space is a topological space where every irreducible closed subset has a generic point. A sober space is a quasi-sober space where every irreducible closed subset has a *unique* generic point. This is if and only if the space is T0, and thus sober spaces can be stated via `[QuasiSober α] [T0Space α]`. ## Main definition * `IsGenericPoint` : `x` is the generic point of `S` if `S` is the closure of `x`. * `QuasiSober` : A space is quasi-sober if every irreducible closed subset has a generic point. * `genericPoints` : The set of generic points of irreducible components. -/ open Set variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] section genericPoint /-- `x` is a generic point of `S` if `S` is the closure of `x`. -/ @[stacks 004X "(1)"] def IsGenericPoint (x : α) (S : Set α) : Prop := closure ({x} : Set α) = S theorem isGenericPoint_def {x : α} {S : Set α} : IsGenericPoint x S ↔ closure ({x} : Set α) = S := Iff.rfl theorem IsGenericPoint.def {x : α} {S : Set α} (h : IsGenericPoint x S) : closure ({x} : Set α) = S := h theorem isGenericPoint_closure {x : α} : IsGenericPoint x (closure ({x} : Set α)) := refl _ variable {x y : α} {S U Z : Set α} theorem isGenericPoint_iff_specializes : IsGenericPoint x S ↔ ∀ y, x ⤳ y ↔ y ∈ S := by simp only [specializes_iff_mem_closure, IsGenericPoint, Set.ext_iff] namespace IsGenericPoint theorem specializes_iff_mem (h : IsGenericPoint x S) : x ⤳ y ↔ y ∈ S := isGenericPoint_iff_specializes.1 h y protected theorem specializes (h : IsGenericPoint x S) (h' : y ∈ S) : x ⤳ y := h.specializes_iff_mem.2 h' protected theorem mem (h : IsGenericPoint x S) : x ∈ S := h.specializes_iff_mem.1 specializes_rfl protected theorem isClosed (h : IsGenericPoint x S) : IsClosed S := h.def ▸ isClosed_closure protected theorem isIrreducible (h : IsGenericPoint x S) : IsIrreducible S := h.def ▸ isIrreducible_singleton.closure protected theorem inseparable (h : IsGenericPoint x S) (h' : IsGenericPoint y S) : Inseparable x y := (h.specializes h'.mem).antisymm (h'.specializes h.mem) /-- In a T₀ space, each set has at most one generic point. -/ protected theorem eq [T0Space α] (h : IsGenericPoint x S) (h' : IsGenericPoint y S) : x = y := (h.inseparable h').eq theorem mem_open_set_iff (h : IsGenericPoint x S) (hU : IsOpen U) : x ∈ U ↔ (S ∩ U).Nonempty := ⟨fun h' => ⟨x, h.mem, h'⟩, fun ⟨_y, hyS, hyU⟩ => (h.specializes hyS).mem_open hU hyU⟩ theorem disjoint_iff (h : IsGenericPoint x S) (hU : IsOpen U) : Disjoint S U ↔ x ∉ U := by rw [h.mem_open_set_iff hU, ← not_disjoint_iff_nonempty_inter, Classical.not_not] theorem mem_closed_set_iff (h : IsGenericPoint x S) (hZ : IsClosed Z) : x ∈ Z ↔ S ⊆ Z := by rw [← h.def, hZ.closure_subset_iff, singleton_subset_iff] protected theorem image (h : IsGenericPoint x S) {f : α → β} (hf : Continuous f) : IsGenericPoint (f x) (closure (f '' S)) := by rw [isGenericPoint_def, ← h.def, ← image_singleton, closure_image_closure hf] end IsGenericPoint theorem isGenericPoint_iff_forall_closed (hS : IsClosed S) (hxS : x ∈ S) : IsGenericPoint x S ↔ ∀ Z : Set α, IsClosed Z → x ∈ Z → S ⊆ Z := by have : closure {x} ⊆ S := closure_minimal (singleton_subset_iff.2 hxS) hS simp_rw [IsGenericPoint, subset_antisymm_iff, this, true_and, closure, subset_sInter_iff, mem_setOf_eq, and_imp, singleton_subset_iff] end genericPoint section Sober /-- A space is sober if every irreducible closed subset has a generic point. -/ @[mk_iff, stacks 004X "(3)"] class QuasiSober (α : Type*) [TopologicalSpace α] : Prop where sober : ∀ {S : Set α}, IsIrreducible S → IsClosed S → ∃ x, IsGenericPoint x S /-- A generic point of the closure of an irreducible space. -/ noncomputable def IsIrreducible.genericPoint [QuasiSober α] {S : Set α} (hS : IsIrreducible S) : α := (QuasiSober.sober hS.closure isClosed_closure).choose theorem IsIrreducible.isGenericPoint_genericPoint_closure [QuasiSober α] {S : Set α} (hS : IsIrreducible S) : IsGenericPoint hS.genericPoint (closure S) := (QuasiSober.sober hS.closure isClosed_closure).choose_spec theorem IsIrreducible.isGenericPoint_genericPoint [QuasiSober α] {S : Set α} (hS : IsIrreducible S) (hS' : IsClosed S) : IsGenericPoint hS.genericPoint S := by convert hS.isGenericPoint_genericPoint_closure; exact hS'.closure_eq.symm @[simp] theorem IsIrreducible.genericPoint_closure_eq [QuasiSober α] {S : Set α} (hS : IsIrreducible S) : closure ({hS.genericPoint} : Set α) = closure S := hS.isGenericPoint_genericPoint_closure theorem IsIrreducible.closure_genericPoint [QuasiSober α] {S : Set α} (hS : IsIrreducible S) (hS' : IsClosed S) : closure ({hS.genericPoint} : Set α) = S := hS.isGenericPoint_genericPoint_closure.trans hS'.closure_eq variable (α) /-- A generic point of a sober irreducible space. -/ noncomputable def genericPoint [QuasiSober α] [IrreducibleSpace α] : α := (IrreducibleSpace.isIrreducible_univ α).genericPoint theorem genericPoint_spec [QuasiSober α] [IrreducibleSpace α] : IsGenericPoint (genericPoint α) univ := by simpa using (IrreducibleSpace.isIrreducible_univ α).isGenericPoint_genericPoint_closure @[simp] theorem genericPoint_closure [QuasiSober α] [IrreducibleSpace α] : closure ({genericPoint α} : Set α) = univ := genericPoint_spec α variable {α} theorem genericPoint_specializes [QuasiSober α] [IrreducibleSpace α] (x : α) : genericPoint α ⤳ x := (IsIrreducible.isGenericPoint_genericPoint_closure _).specializes (by simp) attribute [local instance] specializationOrder /-- The closed irreducible subsets of a sober space bijects with the points of the space. -/ noncomputable def irreducibleSetEquivPoints [QuasiSober α] [T0Space α] : TopologicalSpace.IrreducibleCloseds α ≃o α where toFun s := s.2.genericPoint invFun x := ⟨closure ({x} : Set α), isIrreducible_singleton.closure, isClosed_closure⟩ left_inv s := by refine TopologicalSpace.IrreducibleCloseds.ext ?_ simp only [IsIrreducible.genericPoint_closure_eq, TopologicalSpace.IrreducibleCloseds.coe_mk, closure_eq_iff_isClosed.mpr s.3] rfl right_inv x := isIrreducible_singleton.closure.isGenericPoint_genericPoint_closure.eq (by rw [closure_closure]; exact isGenericPoint_closure) map_rel_iff' := by rintro ⟨s, hs, hs'⟩ ⟨t, ht, ht'⟩ refine specializes_iff_closure_subset.trans ?_ simp rfl lemma Topology.IsClosedEmbedding.quasiSober {f : α → β} (hf : IsClosedEmbedding f) [QuasiSober β] : QuasiSober α where sober hS hS' := by have hS'' := hS.image f hf.continuous.continuousOn obtain ⟨x, hx⟩ := QuasiSober.sober hS'' (hf.isClosedMap _ hS') obtain ⟨y, -, rfl⟩ := hx.mem use y apply image_injective.mpr hf.injective rw [← hx.def, ← hf.closure_image_eq, image_singleton] theorem Topology.IsOpenEmbedding.quasiSober {f : α → β} (hf : IsOpenEmbedding f) [QuasiSober β] : QuasiSober α where sober hS hS' := by have hS'' := hS.image f hf.continuous.continuousOn obtain ⟨x, hx⟩ := QuasiSober.sober hS''.closure isClosed_closure obtain ⟨T, hT, rfl⟩ := hf.isInducing.isClosed_iff.mp hS' rw [image_preimage_eq_inter_range] at hx hS'' have hxT : x ∈ T := by rw [← hT.closure_eq] exact closure_mono inter_subset_left hx.mem obtain ⟨y, rfl⟩ : x ∈ range f := by rw [hx.mem_open_set_iff hf.isOpen_range] refine Nonempty.mono ?_ hS''.1 simpa using subset_closure use y change _ = _ rw [hf.isEmbedding.closure_eq_preimage_closure_image, image_singleton, show _ = _ from hx] apply image_injective.mpr hf.injective ext z simp only [image_preimage_eq_inter_range, mem_inter_iff, and_congr_left_iff] exact fun hy => ⟨fun h => hT.closure_eq ▸ closure_mono inter_subset_left h, fun h => subset_closure ⟨h, hy⟩⟩ lemma TopologicalSpace.IsOpenCover.quasiSober_iff_forall {ι : Type*} {U : ι → Opens α} (hU : TopologicalSpace.IsOpenCover U) : QuasiSober α ↔ ∀ i, QuasiSober (U i) := by refine ⟨fun h i ↦ (U i).isOpenEmbedding'.quasiSober, fun hU' ↦ (quasiSober_iff _).mpr ?_⟩ · rintro t ⟨⟨x, hx⟩, h⟩ h' obtain ⟨i, hi⟩ := hU.exists_mem x have H : IsIrreducible ((↑) ⁻¹' t : Set (U i)) := ⟨⟨⟨x, hi⟩, hx⟩, h.preimage (U i).isOpenEmbedding'⟩ use H.genericPoint apply le_antisymm · simpa [h'.closure_subset_iff, h'.closure_eq] using continuous_subtype_val.closure_preimage_subset _ H.isGenericPoint_genericPoint_closure.mem rw [← image_singleton, ← closure_image_closure continuous_subtype_val, H.isGenericPoint_genericPoint_closure.def] refine (subset_closure_inter_of_isPreirreducible_of_isOpen h (U i).isOpen ⟨x, ⟨hx, hi⟩⟩).trans (closure_mono ?_) simpa only [inter_comm t, ← Subtype.image_preimage_coe] using Set.image_mono subset_closure lemma TopologicalSpace.IsOpenCover.quasiSober {ι : Type*} {U : ι → Opens α} (hU : TopologicalSpace.IsOpenCover U) [∀ i, QuasiSober (U i)] : QuasiSober α := hU.quasiSober_iff_forall.mpr ‹_› /-- A space is quasi-sober if it can be covered by open quasi-sober subsets. -/ theorem quasiSober_of_open_cover (S : Set (Set α)) (hS : ∀ s : S, IsOpen (s : Set α)) [∀ s : S, QuasiSober s] (hS' : ⋃₀ S = ⊤) : QuasiSober α := TopologicalSpace.IsOpenCover.quasiSober (U := fun s : S ↦ ⟨s, hS s⟩) <| by simpa [TopologicalSpace.IsOpenCover, ← SetLike.coe_set_eq, sUnion_eq_iUnion] using hS' /-- Any R1 space is a quasi-sober space because any irreducible set is contained in the closure of a singleton. -/ -- see note [lower instance priority] instance (priority := 100) R1Space.quasiSober [R1Space α] : QuasiSober α where sober h hs := by obtain ⟨x, hx⟩ := h.nonempty use x apply subset_antisymm · rw [← hs.closure_eq] exact closure_mono (singleton_subset_iff.mpr hx) · exact isPreirreducible_iff_forall_mem_subset_closure_singleton.mp h.isPreirreducible x hx end Sober section genericPoints variable (α) in /-- The set of generic points of irreducible components. -/ def genericPoints : Set α := { x | closure {x} ∈ irreducibleComponents α } namespace genericPoints /-- The irreducible component of a generic point -/ def component (x : genericPoints α) : irreducibleComponents α := ⟨closure {x.1}, x.2⟩ lemma isGenericPoint (x : genericPoints α) : IsGenericPoint x.1 (component x).1 := rfl lemma component_injective [T0Space α] : Function.Injective (component (α := α)) := fun x y e ↦ Subtype.ext ((isGenericPoint x).eq (e ▸ isGenericPoint y)) /-- The generic point of an irreducible component. -/ noncomputable def ofComponent [QuasiSober α] (x : irreducibleComponents α) : genericPoints α := ⟨x.2.1.genericPoint, show _ ∈ irreducibleComponents α from (x.2.1.isGenericPoint_genericPoint (isClosed_of_mem_irreducibleComponents x.1 x.2)).symm ▸ x.2⟩ lemma isGenericPoint_ofComponent [QuasiSober α] (x : irreducibleComponents α) : IsGenericPoint (ofComponent x).1 x := x.2.1.isGenericPoint_genericPoint (isClosed_of_mem_irreducibleComponents x.1 x.2) @[simp] lemma component_ofComponent [QuasiSober α] (x : irreducibleComponents α) : component (ofComponent x) = x := Subtype.ext (isGenericPoint_ofComponent x) @[simp] lemma ofComponent_component [T0Space α] [QuasiSober α] (x : genericPoints α) : ofComponent (component x) = x := component_injective (component_ofComponent _) lemma component_surjective [QuasiSober α] : Function.Surjective (component (α := α)) := Function.HasRightInverse.surjective ⟨ofComponent, component_ofComponent⟩ lemma finite [T0Space α] (h : (irreducibleComponents α).Finite) : (genericPoints α).Finite := @Finite.of_injective _ _ h _ component_injective /-- In a sober space, the generic points corresponds bijectively to irreducible components -/ @[simps] noncomputable def equiv [T0Space α] [QuasiSober α] : genericPoints α ≃ irreducibleComponents α := ⟨component, ofComponent, ofComponent_component, component_ofComponent⟩ lemma closure [QuasiSober α] : closure (genericPoints α) = Set.univ := by refine Set.eq_univ_iff_forall.mpr fun x ↦ Set.subset_def.mp ?_ x mem_irreducibleComponent refine (isGenericPoint_ofComponent ⟨_, irreducibleComponent_mem_irreducibleComponents x⟩).symm.trans_subset (closure_mono ?_) exact Set.singleton_subset_iff.mpr (ofComponent _).2 end genericPoints lemma genericPoints_eq_singleton [QuasiSober α] [IrreducibleSpace α] [T0Space α] : genericPoints α = {genericPoint α} := by ext x rw [genericPoints, irreducibleComponents_eq_singleton] exact ⟨((genericPoint_spec α).eq · |>.symm), (· ▸ genericPoint_spec α)⟩ end genericPoints
.lake/packages/mathlib/Mathlib/Topology/DiscreteQuotient.lean
import Mathlib.Data.Setoid.Partition import Mathlib.Topology.LocallyConstant.Basic import Mathlib.Topology.Separation.Regular import Mathlib.Topology.Connected.TotallyDisconnected /-! # Discrete quotients of a topological space. This file defines the type of discrete quotients of a topological space, denoted `DiscreteQuotient X`. To avoid quantifying over types, we model such quotients as setoids whose equivalence classes are clopen. ## Definitions 1. `DiscreteQuotient X` is the type of discrete quotients of `X`. It is endowed with a coercion to `Type`, which is defined as the quotient associated to the setoid in question, and each such quotient is endowed with the discrete topology. 2. Given `S : DiscreteQuotient X`, the projection `X → S` is denoted `S.proj`. 3. When `X` is compact and `S : DiscreteQuotient X`, the space `S` is endowed with a `Fintype` instance. ## Order structure The type `DiscreteQuotient X` is endowed with an instance of a `SemilatticeInf` with `OrderTop`. The partial ordering `A ≤ B` mathematically means that `B.proj` factors through `A.proj`. The top element `⊤` is the trivial quotient, meaning that every element of `X` is collapsed to a point. Given `h : A ≤ B`, the map `A → B` is `DiscreteQuotient.ofLE h`. Whenever `X` is a locally connected space, the type `DiscreteQuotient X` is also endowed with an instance of an `OrderBot`, where the bot element `⊥` is given by the `connectedComponentSetoid`, i.e., `x ~ y` means that `x` and `y` belong to the same connected component. In particular, if `X` is a discrete topological space, then `x ~ y` is equivalent (propositionally, not definitionally) to `x = y`. Given `f : C(X, Y)`, we define a predicate `DiscreteQuotient.LEComap f A B` for `A : DiscreteQuotient X` and `B : DiscreteQuotient Y`, asserting that `f` descends to `A → B`. If `cond : DiscreteQuotient.LEComap h A B`, the function `A → B` is obtained by `DiscreteQuotient.map f cond`. ## Theorems The two main results proved in this file are: 1. `DiscreteQuotient.eq_of_forall_proj_eq` which states that when `X` is compact, T₂, and totally disconnected, any two elements of `X` are equal if their projections in `Q` agree for all `Q : DiscreteQuotient X`. 2. `DiscreteQuotient.exists_of_compat` which states that when `X` is compact, then any system of elements of `Q` as `Q : DiscreteQuotient X` varies, which is compatible with respect to `DiscreteQuotient.ofLE`, must arise from some element of `X`. ## Remarks The constructions in this file will be used to show that any profinite space is a limit of finite discrete spaces. -/ open Set Function TopologicalSpace Topology variable {α X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] /-- The type of discrete quotients of a topological space. -/ @[ext] structure DiscreteQuotient (X : Type*) [TopologicalSpace X] extends Setoid X where /-- For every point `x`, the set `{ y | Rel x y }` is an open set. -/ protected isOpen_setOf_rel : ∀ x, IsOpen (setOf (toSetoid x)) namespace DiscreteQuotient variable (S : DiscreteQuotient X) lemma toSetoid_injective : Function.Injective (@toSetoid X _) | ⟨_, _⟩, ⟨_, _⟩, _ => by congr /-- Construct a discrete quotient from a clopen set. -/ def ofIsClopen {A : Set X} (h : IsClopen A) : DiscreteQuotient X where toSetoid := ⟨fun x y => x ∈ A ↔ y ∈ A, fun _ => Iff.rfl, Iff.symm, Iff.trans⟩ isOpen_setOf_rel x := by by_cases hx : x ∈ A <;> simp [hx, h.1, h.2, ← compl_setOf] theorem refl : ∀ x, S.toSetoid x x := S.refl' theorem symm (x y : X) : S.toSetoid x y → S.toSetoid y x := S.symm' theorem trans (x y z : X) : S.toSetoid x y → S.toSetoid y z → S.toSetoid x z := S.trans' /-- The setoid whose quotient yields the discrete quotient. -/ add_decl_doc toSetoid instance : CoeSort (DiscreteQuotient X) (Type _) := ⟨fun S => Quotient S.toSetoid⟩ instance : TopologicalSpace S := inferInstanceAs (TopologicalSpace (Quotient S.toSetoid)) /-- The projection from `X` to the given discrete quotient. -/ def proj : X → S := Quotient.mk'' theorem fiber_eq (x : X) : S.proj ⁻¹' {S.proj x} = setOf (S.toSetoid x) := Set.ext fun _ => eq_comm.trans Quotient.eq'' theorem proj_surjective : Function.Surjective S.proj := Quotient.mk''_surjective theorem proj_isQuotientMap : IsQuotientMap S.proj := isQuotientMap_quot_mk theorem proj_continuous : Continuous S.proj := S.proj_isQuotientMap.continuous instance : DiscreteTopology S := discreteTopology_iff_isOpen_singleton.2 <| S.proj_surjective.forall.2 fun x => by rw [← S.proj_isQuotientMap.isOpen_preimage, fiber_eq] exact S.isOpen_setOf_rel _ theorem proj_isLocallyConstant : IsLocallyConstant S.proj := (IsLocallyConstant.iff_continuous S.proj).2 S.proj_continuous theorem isClopen_preimage (A : Set S) : IsClopen (S.proj ⁻¹' A) := (isClopen_discrete A).preimage S.proj_continuous theorem isOpen_preimage (A : Set S) : IsOpen (S.proj ⁻¹' A) := (S.isClopen_preimage A).2 theorem isClosed_preimage (A : Set S) : IsClosed (S.proj ⁻¹' A) := (S.isClopen_preimage A).1 theorem isClopen_setOf_rel (x : X) : IsClopen (setOf (S.toSetoid x)) := by rw [← fiber_eq] apply isClopen_preimage instance : Min (DiscreteQuotient X) := ⟨fun S₁ S₂ => ⟨S₁.1 ⊓ S₂.1, fun x => (S₁.2 x).inter (S₂.2 x)⟩⟩ instance : SemilatticeInf (DiscreteQuotient X) := Injective.semilatticeInf toSetoid toSetoid_injective fun _ _ => rfl instance : OrderTop (DiscreteQuotient X) where top := ⟨⊤, fun _ => isOpen_univ⟩ le_top a := by tauto instance : Inhabited (DiscreteQuotient X) := ⟨⊤⟩ instance inhabitedQuotient [Inhabited X] : Inhabited S := ⟨S.proj default⟩ -- TODO: add instances about `Nonempty (Quot _)`/`Nonempty (Quotient _)` instance [Nonempty X] : Nonempty S := Nonempty.map S.proj ‹_› /-- The quotient by `⊤ : DiscreteQuotient X` is a `Subsingleton`. -/ instance : Subsingleton (⊤ : DiscreteQuotient X) where allEq := by rintro ⟨_⟩ ⟨_⟩; exact Quotient.sound trivial section Comap variable (g : C(Y, Z)) (f : C(X, Y)) /-- Comap a discrete quotient along a continuous map. -/ def comap (S : DiscreteQuotient Y) : DiscreteQuotient X where toSetoid := Setoid.comap f S.1 isOpen_setOf_rel _ := (S.2 _).preimage f.continuous @[simp] theorem comap_id : S.comap (ContinuousMap.id X) = S := rfl @[simp] theorem comap_comp (S : DiscreteQuotient Z) : S.comap (g.comp f) = (S.comap g).comap f := rfl @[mono] theorem comap_mono {A B : DiscreteQuotient Y} (h : A ≤ B) : A.comap f ≤ B.comap f := by tauto end Comap section OfLE variable {A B C : DiscreteQuotient X} /-- The map induced by a refinement of a discrete quotient. -/ def ofLE (h : A ≤ B) : A → B := Quotient.map' id h @[simp] theorem ofLE_refl : ofLE (le_refl A) = id := by ext ⟨⟩ rfl theorem ofLE_refl_apply (a : A) : ofLE (le_refl A) a = a := by simp @[simp] theorem ofLE_ofLE (h₁ : A ≤ B) (h₂ : B ≤ C) (x : A) : ofLE h₂ (ofLE h₁ x) = ofLE (h₁.trans h₂) x := by rcases x with ⟨⟩ rfl @[simp] theorem ofLE_comp_ofLE (h₁ : A ≤ B) (h₂ : B ≤ C) : ofLE h₂ ∘ ofLE h₁ = ofLE (le_trans h₁ h₂) := funext <| ofLE_ofLE _ _ theorem ofLE_continuous (h : A ≤ B) : Continuous (ofLE h) := continuous_of_discreteTopology @[simp] theorem ofLE_proj (h : A ≤ B) (x : X) : ofLE h (A.proj x) = B.proj x := Quotient.sound' (B.refl _) @[simp] theorem ofLE_comp_proj (h : A ≤ B) : ofLE h ∘ A.proj = B.proj := funext <| ofLE_proj _ end OfLE /-- When `X` is a locally connected space, there is an `OrderBot` instance on `DiscreteQuotient X`. The bottom element is given by `connectedComponentSetoid X` -/ instance [LocallyConnectedSpace X] : OrderBot (DiscreteQuotient X) where bot := { toSetoid := connectedComponentSetoid X isOpen_setOf_rel := fun x => by convert isOpen_connectedComponent (x := x) ext y simpa only [connectedComponentSetoid, ← connectedComponent_eq_iff_mem] using eq_comm } bot_le S := fun x y (h : connectedComponent x = connectedComponent y) => (S.isClopen_setOf_rel x).connectedComponent_subset (S.refl _) <| h.symm ▸ mem_connectedComponent @[simp] theorem proj_bot_eq [LocallyConnectedSpace X] {x y : X} : proj ⊥ x = proj ⊥ y ↔ connectedComponent x = connectedComponent y := Quotient.eq'' theorem proj_bot_inj [DiscreteTopology X] {x y : X} : proj ⊥ x = proj ⊥ y ↔ x = y := by simp theorem proj_bot_injective [DiscreteTopology X] : Injective (⊥ : DiscreteQuotient X).proj := fun _ _ => proj_bot_inj.1 theorem proj_bot_bijective [DiscreteTopology X] : Bijective (⊥ : DiscreteQuotient X).proj := ⟨proj_bot_injective, proj_surjective _⟩ section Map variable (f : C(X, Y)) (A A' : DiscreteQuotient X) (B B' : DiscreteQuotient Y) /-- Given `f : C(X, Y)`, `DiscreteQuotient.LEComap f A B` is defined as `A ≤ B.comap f`. Mathematically this means that `f` descends to a morphism `A → B`. -/ def LEComap : Prop := A ≤ B.comap f theorem leComap_id : LEComap (.id X) A A := le_rfl variable {A A' B B'} {f} {g : C(Y, Z)} {C : DiscreteQuotient Z} @[simp] theorem leComap_id_iff : LEComap (ContinuousMap.id X) A A' ↔ A ≤ A' := Iff.rfl theorem LEComap.comp : LEComap g B C → LEComap f A B → LEComap (g.comp f) A C := by tauto @[mono] theorem LEComap.mono (h : LEComap f A B) (hA : A' ≤ A) (hB : B ≤ B') : LEComap f A' B' := hA.trans <| h.trans <| comap_mono _ hB /-- Map a discrete quotient along a continuous map. -/ def map (f : C(X, Y)) (cond : LEComap f A B) : A → B := Quotient.map' f cond theorem map_continuous (cond : LEComap f A B) : Continuous (map f cond) := continuous_of_discreteTopology @[simp] theorem map_comp_proj (cond : LEComap f A B) : map f cond ∘ A.proj = B.proj ∘ f := rfl @[simp] theorem map_proj (cond : LEComap f A B) (x : X) : map f cond (A.proj x) = B.proj (f x) := rfl @[simp] theorem map_id : map _ (leComap_id A) = id := by ext ⟨⟩; rfl /- This can't be a `@[simp]` lemma since `h1` and `h2` can't be found by unification in a Prop. -/ theorem map_comp (h1 : LEComap g B C) (h2 : LEComap f A B) : map (g.comp f) (h1.comp h2) = map g h1 ∘ map f h2 := by ext ⟨⟩ rfl @[simp] theorem ofLE_map (cond : LEComap f A B) (h : B ≤ B') (a : A) : ofLE h (map f cond a) = map f (cond.mono le_rfl h) a := by rcases a with ⟨⟩ rfl @[simp] theorem ofLE_comp_map (cond : LEComap f A B) (h : B ≤ B') : ofLE h ∘ map f cond = map f (cond.mono le_rfl h) := funext <| ofLE_map cond h @[simp] theorem map_ofLE (cond : LEComap f A B) (h : A' ≤ A) (c : A') : map f cond (ofLE h c) = map f (cond.mono h le_rfl) c := by rcases c with ⟨⟩ rfl @[simp] theorem map_comp_ofLE (cond : LEComap f A B) (h : A' ≤ A) : map f cond ∘ ofLE h = map f (cond.mono h le_rfl) := funext <| map_ofLE cond h end Map theorem eq_of_forall_proj_eq [T2Space X] [CompactSpace X] [disc : TotallyDisconnectedSpace X] {x y : X} (h : ∀ Q : DiscreteQuotient X, Q.proj x = Q.proj y) : x = y := by rw [← mem_singleton_iff, ← connectedComponent_eq_singleton, connectedComponent_eq_iInter_isClopen, mem_iInter] rintro ⟨U, hU1, hU2⟩ exact (Quotient.exact' (h (ofIsClopen hU1))).mpr hU2 theorem fiber_subset_ofLE {A B : DiscreteQuotient X} (h : A ≤ B) (a : A) : A.proj ⁻¹' {a} ⊆ B.proj ⁻¹' {ofLE h a} := by rcases A.proj_surjective a with ⟨a, rfl⟩ rw [fiber_eq, ofLE_proj, fiber_eq] exact fun _ h' => h h' theorem exists_of_compat [CompactSpace X] (Qs : (Q : DiscreteQuotient X) → Q) (compat : ∀ (A B : DiscreteQuotient X) (h : A ≤ B), ofLE h (Qs _) = Qs _) : ∃ x : X, ∀ Q : DiscreteQuotient X, Q.proj x = Qs _ := by have H₁ : ∀ Q₁ Q₂, Q₁ ≤ Q₂ → proj Q₁ ⁻¹' {Qs Q₁} ⊆ proj Q₂ ⁻¹' {Qs Q₂} := fun _ _ h => by rw [← compat _ _ h] exact fiber_subset_ofLE _ _ obtain ⟨x, hx⟩ : Set.Nonempty (⋂ Q, proj Q ⁻¹' {Qs Q}) := IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed (fun Q : DiscreteQuotient X => Q.proj ⁻¹' {Qs _}) (directed_of_isDirected_ge H₁) (fun Q => (singleton_nonempty _).preimage Q.proj_surjective) (fun Q => (Q.isClosed_preimage {Qs _}).isCompact) fun Q => Q.isClosed_preimage _ exact ⟨x, mem_iInter.1 hx⟩ /-- If `X` is a compact space, then any discrete quotient of `X` is finite. -/ instance [CompactSpace X] : Finite S := by have : CompactSpace S := Quotient.compactSpace rwa [← isCompact_univ_iff, isCompact_iff_finite, finite_univ_iff] at this variable (X) open Classical in /-- If `X` is a compact space, then we associate to any discrete quotient on `X` a finite set of clopen subsets of `X`, given by the fibers of `proj`. TODO: prove that these form a partition of `X` -/ noncomputable def finsetClopens [CompactSpace X] (d : DiscreteQuotient X) : Finset (Clopens X) := have : Fintype d := Fintype.ofFinite _ (Set.range (fun (x : d) ↦ ⟨_, d.isClopen_preimage {x}⟩) : Set (Clopens X)).toFinset /-- A helper lemma to prove that `finsetClopens X` is injective, see `finsetClopens_inj`. -/ lemma comp_finsetClopens [CompactSpace X] : (Set.image (fun (t : Clopens X) ↦ t.carrier) ∘ (↑)) ∘ finsetClopens X = fun ⟨f, _⟩ ↦ f.classes := by ext d simp only [Setoid.classes, Set.mem_setOf_eq, Function.comp_apply, finsetClopens, Set.coe_toFinset, Set.mem_image, Set.mem_range, exists_exists_eq_and] constructor · refine fun ⟨y, h⟩ ↦ ⟨Quotient.out (s := d.toSetoid) y, ?_⟩ ext simpa [← h] using Quotient.mk_eq_iff_out (s := d.toSetoid) · exact fun ⟨y, h⟩ ↦ ⟨d.proj y, by ext; simp [h, proj]⟩ /-- `finsetClopens X` is injective. -/ theorem finsetClopens_inj [CompactSpace X] : (finsetClopens X).Injective := by apply Function.Injective.of_comp (f := Set.image (fun (t : Clopens X) ↦ t.carrier) ∘ (↑)) rw [comp_finsetClopens] intro ⟨_, _⟩ ⟨_, _⟩ h congr rw [Setoid.classes_inj] exact h /-- The discrete quotients of a compact space are in bijection with a subtype of the type of `Finset (Clopens X)`. TODO: show that this is precisely those finsets of clopens which form a partition of `X`. -/ noncomputable def equivFinsetClopens [CompactSpace X] := Equiv.ofInjective _ (finsetClopens_inj X) variable {X} end DiscreteQuotient namespace LocallyConstant variable (f : LocallyConstant X α) /-- Any locally constant function induces a discrete quotient. -/ def discreteQuotient : DiscreteQuotient X where toSetoid := .comap f ⊥ isOpen_setOf_rel _ := f.isLocallyConstant _ /-- The (locally constant) function from the discrete quotient associated to a locally constant function. -/ def lift : LocallyConstant f.discreteQuotient α := ⟨fun a => Quotient.liftOn' a f fun _ _ => id, fun _ => isOpen_discrete _⟩ @[simp] theorem lift_comp_proj : f.lift ∘ f.discreteQuotient.proj = f := rfl end LocallyConstant
.lake/packages/mathlib/Mathlib/Topology/NhdsKer.lean
import Mathlib.Topology.NhdsSet import Mathlib.Topology.Inseparable /-! # Neighborhoods kernel of a set In `Mathlib/Topology/Defs/Filter.lean`, `nhdsKer s` is defined to be the intersection of all neighborhoods of `s`. Note that this construction has no standard name in the literature. In this file we prove basic properties of this operation. -/ open Set Filter open scoped Topology variable {ι : Sort*} {X : Type*} [TopologicalSpace X] {s t : Set X} {x y : X} lemma nhdsKer_singleton_eq_ker_nhds (x : X) : nhdsKer {x} = (𝓝 x).ker := by simp [nhdsKer] @[deprecated (since := "2025-07-09")] alias exterior_singleton_eq_ker_nhds := nhdsKer_singleton_eq_ker_nhds @[simp] theorem mem_nhdsKer_singleton : x ∈ nhdsKer {y} ↔ x ⤳ y := by rw [nhdsKer_singleton_eq_ker_nhds, ker_nhds_eq_specializes, mem_setOf] @[deprecated (since := "2025-07-09")] alias mem_exterior_singleton := mem_nhdsKer_singleton lemma nhdsKer_def (s : Set X) : nhdsKer s = ⋂₀ {t : Set X | IsOpen t ∧ s ⊆ t} := (hasBasis_nhdsSet _).ker.trans sInter_eq_biInter.symm @[deprecated (since := "2025-07-09")] alias exterior_def := nhdsKer_def lemma mem_nhdsKer : x ∈ nhdsKer s ↔ ∀ U, IsOpen U → s ⊆ U → x ∈ U := by simp [nhdsKer_def] @[deprecated (since := "2025-07-09")] alias mem_exterior := mem_nhdsKer lemma subset_nhdsKer_iff : s ⊆ nhdsKer t ↔ ∀ U, IsOpen U → t ⊆ U → s ⊆ U := by simp [nhdsKer_def] @[deprecated (since := "2025-07-09")] alias subset_exterior_iff := subset_nhdsKer_iff lemma subset_nhdsKer : s ⊆ nhdsKer s := subset_nhdsKer_iff.2 fun _ _ ↦ id @[deprecated (since := "2025-07-09")] alias subset_exterior := subset_nhdsKer lemma nhdsKer_minimal (h₁ : s ⊆ t) (h₂ : IsOpen t) : nhdsKer s ⊆ t := by rw [nhdsKer_def]; exact sInter_subset_of_mem ⟨h₂, h₁⟩ @[deprecated (since := "2025-07-09")] alias exterior_minimal := nhdsKer_minimal lemma IsOpen.nhdsKer_eq (h : IsOpen s) : nhdsKer s = s := (nhdsKer_minimal Subset.rfl h).antisymm subset_nhdsKer @[deprecated (since := "2025-07-09")] alias IsOpen.exterior_eq := IsOpen.nhdsKer_eq lemma IsOpen.nhdsKer_subset (ht : IsOpen t) : nhdsKer s ⊆ t ↔ s ⊆ t := ⟨subset_nhdsKer.trans, fun h ↦ nhdsKer_minimal h ht⟩ @[deprecated (since := "2025-07-09")] alias IsOpen.exterior_subset := IsOpen.nhdsKer_subset @[simp] theorem nhdsKer_iUnion (s : ι → Set X) : nhdsKer (⋃ i, s i) = ⋃ i, nhdsKer (s i) := by simp only [nhdsKer, nhdsSet_iUnion, ker_iSup] @[deprecated (since := "2025-07-09")] alias exterior_iUnion := nhdsKer_iUnion theorem nhdsKer_biUnion {ι : Type*} (s : Set ι) (t : ι → Set X) : nhdsKer (⋃ i ∈ s, t i) = ⋃ i ∈ s, nhdsKer (t i) := by simp only [nhdsKer_iUnion] @[simp] theorem nhdsKer_union (s t : Set X) : nhdsKer (s ∪ t) = nhdsKer s ∪ nhdsKer t := by simp only [nhdsKer, nhdsSet_union, ker_sup] @[deprecated (since := "2025-07-09")] alias exterior_union := nhdsKer_union @[simp] theorem nhdsKer_sUnion (S : Set (Set X)) : nhdsKer (⋃₀ S) = ⋃ s ∈ S, nhdsKer s := by simp only [sUnion_eq_biUnion, nhdsKer_iUnion] @[deprecated (since := "2025-07-09")] alias exterior_sUnion := nhdsKer_sUnion theorem mem_nhdsKer_iff_specializes : x ∈ nhdsKer s ↔ ∃ y ∈ s, x ⤳ y := calc x ∈ nhdsKer s ↔ x ∈ nhdsKer (⋃ y ∈ s, {y}) := by simp _ ↔ ∃ y ∈ s, x ⤳ y := by simp only [nhdsKer_iUnion, mem_nhdsKer_singleton, mem_iUnion₂, exists_prop] @[deprecated (since := "2025-07-09")] alias mem_exterior_iff_specializes := mem_nhdsKer_iff_specializes @[mono] lemma nhdsKer_mono : Monotone (nhdsKer : Set X → Set X) := fun _s _t h ↦ ker_mono <| nhdsSet_mono h @[deprecated (since := "2025-07-09")] alias exterior_mono := nhdsKer_mono /-- This name was used to be used for the `Iff` version, see `nhdsKer_subset_nhdsKer_iff_nhdsSet`. -/ @[gcongr] lemma nhdsKer_subset_nhdsKer (h : s ⊆ t) : nhdsKer s ⊆ nhdsKer t := nhdsKer_mono h @[deprecated (since := "2025-07-09")] alias exterior_subset_exterior := nhdsKer_subset_nhdsKer @[simp] lemma nhdsKer_subset_nhdsKer_iff_nhdsSet : nhdsKer s ⊆ nhdsKer t ↔ 𝓝ˢ s ≤ 𝓝ˢ t := by simp +contextual only [subset_nhdsKer_iff, (hasBasis_nhdsSet _).ge_iff, and_imp, IsOpen.mem_nhdsSet, IsOpen.nhdsKer_subset] @[deprecated (since := "2025-07-09")] alias exterior_subset_exterior_iff_nhdsSet := nhdsKer_subset_nhdsKer_iff_nhdsSet theorem nhdsKer_eq_nhdsKer_iff_nhdsSet : nhdsKer s = nhdsKer t ↔ 𝓝ˢ s = 𝓝ˢ t := by simp [le_antisymm_iff] @[deprecated (since := "2025-07-09")] alias exterior_eq_exterior_iff_nhdsSet := nhdsKer_eq_nhdsKer_iff_nhdsSet lemma specializes_iff_nhdsKer_subset : x ⤳ y ↔ nhdsKer {x} ⊆ nhdsKer {y} := by simp [Specializes] @[deprecated (since := "2025-07-09")] alias specializes_iff_exterior_subset := specializes_iff_nhdsKer_subset theorem nhdsKer_iInter_subset {s : ι → Set X} : nhdsKer (⋂ i, s i) ⊆ ⋂ i, nhdsKer (s i) := nhdsKer_mono.map_iInf_le @[deprecated (since := "2025-07-09")] alias exterior_iInter_subset := nhdsKer_iInter_subset theorem nhdsKer_inter_subset {s t : Set X} : nhdsKer (s ∩ t) ⊆ nhdsKer s ∩ nhdsKer t := nhdsKer_mono.map_inf_le _ _ @[deprecated (since := "2025-07-09")] alias exterior_inter_subset := nhdsKer_inter_subset theorem nhdsKer_sInter_subset {s : Set (Set X)} : nhdsKer (⋂₀ s) ⊆ ⋂ x ∈ s, nhdsKer x := nhdsKer_mono.map_sInf_le @[deprecated (since := "2025-07-09")] alias exterior_sInter_subset := nhdsKer_sInter_subset @[simp] lemma nhdsKer_empty : nhdsKer (∅ : Set X) = ∅ := isOpen_empty.nhdsKer_eq @[deprecated (since := "2025-07-09")] alias exterior_empty := nhdsKer_empty @[simp] lemma nhdsKer_univ : nhdsKer (univ : Set X) = univ := isOpen_univ.nhdsKer_eq @[deprecated (since := "2025-07-09")] alias exterior_univ := nhdsKer_univ @[simp] lemma nhdsKer_eq_empty : nhdsKer s = ∅ ↔ s = ∅ := ⟨eq_bot_mono subset_nhdsKer, by rintro rfl; exact nhdsKer_empty⟩ @[deprecated (since := "2025-07-09")] alias exterior_eq_empty := nhdsKer_eq_empty @[simp] lemma nhdsSet_nhdsKer (s : Set X) : 𝓝ˢ (nhdsKer s) = 𝓝ˢ s := by refine le_antisymm ((hasBasis_nhdsSet _).ge_iff.2 ?_) (nhdsSet_mono subset_nhdsKer) exact fun U ⟨hUo, hsU⟩ ↦ hUo.mem_nhdsSet.2 <| hUo.nhdsKer_subset.2 hsU @[deprecated (since := "2025-07-09")] alias nhdsSet_exterior := nhdsSet_nhdsKer @[simp] lemma nhdsKer_nhdsKer (s : Set X) : nhdsKer (nhdsKer s) = nhdsKer s := by simp only [nhdsKer_eq_nhdsKer_iff_nhdsSet, nhdsSet_nhdsKer] @[deprecated (since := "2025-07-09")] alias exterior_exterior := nhdsKer_nhdsKer lemma nhdsKer_pair {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] (x : X) (y : Y) : nhdsKer {(x, y)} = nhdsKer {x} ×ˢ nhdsKer {y} := by simp_rw [nhdsKer_singleton_eq_ker_nhds, nhds_prod_eq, ker_prod] lemma nhdsKer_prod {Y : Type*} [TopologicalSpace Y] (s : Set X) (t : Set Y) : nhdsKer (s ×ˢ t) = nhdsKer s ×ˢ nhdsKer t := calc _ = ⋃ (p ∈ s ×ˢ t), nhdsKer {p} := by conv_lhs => rw [← biUnion_of_singleton (s ×ˢ t), nhdsKer_biUnion] _ = ⋃ (p ∈ s ×ˢ t), nhdsKer {p.1} ×ˢ nhdsKer {p.2} := by congr! with ⟨x, y⟩ _; rw [nhdsKer_pair] _ = (⋃ x ∈ s, nhdsKer {x}) ×ˢ (⋃ y ∈ t, nhdsKer {y}) := biUnion_prod s t (fun x => nhdsKer {x}) (fun y => nhdsKer {y}) _ = nhdsKer s ×ˢ nhdsKer t := by simp_rw [← nhdsKer_biUnion, biUnion_of_singleton] lemma nhdsKer_singleton_pi {ι : Type*} {X : ι → Type*} [Π (i : ι), TopologicalSpace (X i)] (p : Π (i : ι), X i) : nhdsKer {p} = univ.pi (fun i => nhdsKer {p i}) := by simp_rw [nhdsKer_singleton_eq_ker_nhds, nhds_pi, ker_pi] lemma nhdsKer_pi {ι : Type*} {X : ι → Type*} [Π (i : ι), TopologicalSpace (X i)] (s : Π (i : ι), Set (X i)) : nhdsKer (univ.pi s) = univ.pi (fun i => nhdsKer (s i)) := calc _ = ⋃ (p ∈ univ.pi s), nhdsKer {p} := by conv_lhs => rw [← biUnion_of_singleton (univ.pi s), nhdsKer_biUnion] _ = ⋃ (p ∈ univ.pi s), univ.pi fun i => nhdsKer {p i} := by congr! with p _; rw [nhdsKer_singleton_pi] _ = univ.pi fun i => ⋃ x ∈ s i, nhdsKer {x} := biUnion_univ_pi s fun i x => nhdsKer {x} _ = univ.pi (fun i => nhdsKer (s i)) := by simp_rw [← nhdsKer_biUnion, biUnion_of_singleton]
.lake/packages/mathlib/Mathlib/Topology/NoetherianSpace.lean
import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.Closeds /-! # Noetherian space A Noetherian space is a topological space that satisfies any of the following equivalent conditions: - `WellFounded ((· > ·) : TopologicalSpace.Opens α → TopologicalSpace.Opens α → Prop)` - `WellFounded ((· < ·) : TopologicalSpace.Closeds α → TopologicalSpace.Closeds α → Prop)` - `∀ s : Set α, IsCompact s` - `∀ s : TopologicalSpace.Opens α, IsCompact s` The first is chosen as the definition, and the equivalence is shown in `TopologicalSpace.noetherianSpace_TFAE`. Many examples of Noetherian spaces come from algebraic topology. For example, the underlying space of a Noetherian scheme (e.g., the spectrum of a Noetherian ring) is Noetherian. ## Main Results - `TopologicalSpace.NoetherianSpace.set`: Every subspace of a Noetherian space is Noetherian. - `TopologicalSpace.NoetherianSpace.isCompact`: Every set in a Noetherian space is a compact set. - `TopologicalSpace.noetherianSpace_TFAE`: Describes the equivalent definitions of Noetherian spaces. - `TopologicalSpace.NoetherianSpace.range`: The image of a Noetherian space under a continuous map is Noetherian. - `TopologicalSpace.NoetherianSpace.iUnion`: The finite union of Noetherian spaces is Noetherian. - `TopologicalSpace.NoetherianSpace.discrete`: A Noetherian and Hausdorff space is discrete. - `TopologicalSpace.NoetherianSpace.exists_finset_irreducible`: Every closed subset of a Noetherian space is a finite union of irreducible closed subsets. - `TopologicalSpace.NoetherianSpace.finite_irreducibleComponents`: The number of irreducible components of a Noetherian space is finite. -/ open Topology variable (α β : Type*) [TopologicalSpace α] [TopologicalSpace β] namespace TopologicalSpace /-- Type class for Noetherian spaces. It is defined to be spaces whose open sets satisfies ACC. -/ abbrev NoetherianSpace : Prop := WellFoundedGT (Opens α) theorem noetherianSpace_iff_opens : NoetherianSpace α ↔ ∀ s : Opens α, IsCompact (s : Set α) := by rw [NoetherianSpace, CompleteLattice.wellFoundedGT_iff_isSupFiniteCompact, CompleteLattice.isSupFiniteCompact_iff_all_elements_compact] exact forall_congr' Opens.isCompactElement_iff instance (priority := 100) NoetherianSpace.compactSpace [h : NoetherianSpace α] : CompactSpace α := ⟨(noetherianSpace_iff_opens α).mp h ⊤⟩ variable {α β} /-- In a Noetherian space, all sets are compact. -/ protected theorem NoetherianSpace.isCompact [NoetherianSpace α] (s : Set α) : IsCompact s := by refine isCompact_iff_finite_subcover.2 fun U hUo hs => ?_ rcases ((noetherianSpace_iff_opens α).mp ‹_› ⟨⋃ i, U i, isOpen_iUnion hUo⟩).elim_finite_subcover U hUo Set.Subset.rfl with ⟨t, ht⟩ exact ⟨t, hs.trans ht⟩ protected theorem _root_.Topology.IsInducing.noetherianSpace [NoetherianSpace α] {i : β → α} (hi : IsInducing i) : NoetherianSpace β := (noetherianSpace_iff_opens _).2 fun _ => hi.isCompact_iff.2 (NoetherianSpace.isCompact _) @[stacks 0052 "(1)"] instance NoetherianSpace.set [NoetherianSpace α] (s : Set α) : NoetherianSpace s := IsInducing.subtypeVal.noetherianSpace variable (α) in open List in theorem noetherianSpace_TFAE : TFAE [NoetherianSpace α, WellFoundedLT (Closeds α), ∀ s : Set α, IsCompact s, ∀ s : Opens α, IsCompact (s : Set α)] := by tfae_have 1 ↔ 2 := by simp_rw [isWellFounded_iff] exact Opens.compl_bijective.2.wellFounded_iff (@OrderIso.compl (Set α)).lt_iff_lt.symm tfae_have 1 ↔ 4 := noetherianSpace_iff_opens α tfae_have 1 → 3 := @NoetherianSpace.isCompact α _ tfae_have 3 → 4 := fun h s => h s tfae_finish theorem noetherianSpace_iff_isCompact : NoetherianSpace α ↔ ∀ s : Set α, IsCompact s := (noetherianSpace_TFAE α).out 0 2 instance [NoetherianSpace α] : WellFoundedLT (Closeds α) := Iff.mp ((noetherianSpace_TFAE α).out 0 1) ‹_› instance {α} : NoetherianSpace (CofiniteTopology α) := by simp only [noetherianSpace_iff_isCompact, isCompact_iff_ultrafilter_le_nhds, CofiniteTopology.nhds_eq, Ultrafilter.le_sup_iff, Filter.le_principal_iff] intro s f hs rcases f.le_cofinite_or_eq_pure with (hf | ⟨a, rfl⟩) · rcases Filter.nonempty_of_mem hs with ⟨a, ha⟩ exact ⟨a, ha, Or.inr hf⟩ · exact ⟨a, hs, Or.inl le_rfl⟩ theorem noetherianSpace_of_surjective [NoetherianSpace α] (f : α → β) (hf : Continuous f) (hf' : Function.Surjective f) : NoetherianSpace β := noetherianSpace_iff_isCompact.2 <| (Set.image_surjective.mpr hf').forall.2 fun s => (NoetherianSpace.isCompact s).image hf theorem noetherianSpace_iff_of_homeomorph (f : α ≃ₜ β) : NoetherianSpace α ↔ NoetherianSpace β := ⟨fun _ => noetherianSpace_of_surjective f f.continuous f.surjective, fun _ => noetherianSpace_of_surjective f.symm f.symm.continuous f.symm.surjective⟩ theorem NoetherianSpace.range [NoetherianSpace α] (f : α → β) (hf : Continuous f) : NoetherianSpace (Set.range f) := noetherianSpace_of_surjective (Set.rangeFactorization f) (hf.subtype_mk _) Set.rangeFactorization_surjective theorem noetherianSpace_set_iff (s : Set α) : NoetherianSpace s ↔ ∀ t, t ⊆ s → IsCompact t := by simp only [noetherianSpace_iff_isCompact, IsEmbedding.subtypeVal.isCompact_iff, Subtype.forall_set_subtype] @[simp] theorem noetherian_univ_iff : NoetherianSpace (Set.univ : Set α) ↔ NoetherianSpace α := noetherianSpace_iff_of_homeomorph (Homeomorph.Set.univ α) theorem NoetherianSpace.iUnion {ι : Type*} (f : ι → Set α) [Finite ι] [hf : ∀ i, NoetherianSpace (f i)] : NoetherianSpace (⋃ i, f i) := by simp_rw [noetherianSpace_set_iff] at hf ⊢ intro t ht rw [← Set.inter_eq_left.mpr ht, Set.inter_iUnion] exact isCompact_iUnion fun i => hf i _ Set.inter_subset_right -- This is not an instance since it makes a loop with `t2_space_discrete`. theorem NoetherianSpace.discrete [NoetherianSpace α] [T2Space α] : DiscreteTopology α := ⟨eq_bot_iff.mpr fun _ _ => isClosed_compl_iff.mp (NoetherianSpace.isCompact _).isClosed⟩ attribute [local instance] NoetherianSpace.discrete /-- Spaces that are both Noetherian and Hausdorff are finite. -/ theorem NoetherianSpace.finite [NoetherianSpace α] [T2Space α] : Finite α := Finite.of_finite_univ (NoetherianSpace.isCompact Set.univ).finite_of_discrete instance (priority := 100) Finite.to_noetherianSpace [Finite α] : NoetherianSpace α := ⟨Finite.wellFounded_of_trans_of_irrefl _⟩ /-- In a Noetherian space, every closed set is a finite union of irreducible closed sets. -/ theorem NoetherianSpace.exists_finite_set_closeds_irreducible [NoetherianSpace α] (s : Closeds α) : ∃ S : Set (Closeds α), S.Finite ∧ (∀ t ∈ S, IsIrreducible (t : Set α)) ∧ s = sSup S := by apply wellFounded_lt.induction s; clear s intro s H rcases eq_or_ne s ⊥ with rfl | h₀ · use ∅; simp · by_cases h₁ : IsPreirreducible (s : Set α) · replace h₁ : IsIrreducible (s : Set α) := ⟨Closeds.coe_nonempty.2 h₀, h₁⟩ use {s}; simp [h₁] · simp only [isPreirreducible_iff_isClosed_union_isClosed, not_forall, not_or] at h₁ obtain ⟨z₁, z₂, hz₁, hz₂, h, hz₁', hz₂'⟩ := h₁ lift z₁ to Closeds α using hz₁ lift z₂ to Closeds α using hz₂ rcases H (s ⊓ z₁) (inf_lt_left.2 hz₁') with ⟨S₁, hSf₁, hS₁, h₁⟩ rcases H (s ⊓ z₂) (inf_lt_left.2 hz₂') with ⟨S₂, hSf₂, hS₂, h₂⟩ refine ⟨S₁ ∪ S₂, hSf₁.union hSf₂, Set.union_subset_iff.2 ⟨hS₁, hS₂⟩, ?_⟩ rwa [sSup_union, ← h₁, ← h₂, ← inf_sup_left, left_eq_inf] /-- In a Noetherian space, every closed set is a finite union of irreducible closed sets. -/ theorem NoetherianSpace.exists_finite_set_isClosed_irreducible [NoetherianSpace α] {s : Set α} (hs : IsClosed s) : ∃ S : Set (Set α), S.Finite ∧ (∀ t ∈ S, IsClosed t) ∧ (∀ t ∈ S, IsIrreducible t) ∧ s = ⋃₀ S := by lift s to Closeds α using hs rcases NoetherianSpace.exists_finite_set_closeds_irreducible s with ⟨S, hSf, hS, rfl⟩ refine ⟨(↑) '' S, hSf.image _, Set.forall_mem_image.2 fun S _ ↦ S.2, Set.forall_mem_image.2 hS, ?_⟩ lift S to Finset (Closeds α) using hSf simp [← Finset.sup_id_eq_sSup, Closeds.coe_finset_sup] /-- In a Noetherian space, every closed set is a finite union of irreducible closed sets. -/ theorem NoetherianSpace.exists_finset_irreducible [NoetherianSpace α] (s : Closeds α) : ∃ S : Finset (Closeds α), (∀ k : S, IsIrreducible (k : Set α)) ∧ s = S.sup id := by simpa [Set.exists_finite_iff_finset, Finset.sup_id_eq_sSup] using NoetherianSpace.exists_finite_set_closeds_irreducible s @[stacks 0052 "(2)"] theorem NoetherianSpace.finite_irreducibleComponents [NoetherianSpace α] : (irreducibleComponents α).Finite := by obtain ⟨S : Set (Set α), hSf, hSc, hSi, hSU⟩ := NoetherianSpace.exists_finite_set_isClosed_irreducible isClosed_univ (α := α) refine hSf.subset fun s hs => ?_ lift S to Finset (Set α) using hSf rcases isIrreducible_iff_sUnion_isClosed.1 hs.1 S hSc (hSU ▸ Set.subset_univ _) with ⟨t, htS, ht⟩ rwa [ht.antisymm (hs.2 (hSi _ htS) ht)] @[stacks 0052 "(3)"] theorem NoetherianSpace.exists_open_ne_empty_le_irreducibleComponent [NoetherianSpace α] (Z : Set α) (H : Z ∈ irreducibleComponents α) : ∃ o : Set α, IsOpen o ∧ o ≠ ∅ ∧ o ≤ Z := by classical let ι : Set (Set α) := irreducibleComponents α \ {Z} have hι : ι.Finite := NoetherianSpace.finite_irreducibleComponents.subset Set.diff_subset have hι' : Finite ι := by rwa [Set.finite_coe_iff] let U := Z \ ⋃ (x : ι), x have hU0 : U ≠ ∅ := fun r ↦ by obtain ⟨Z', hZ'⟩ := isIrreducible_iff_sUnion_isClosed.mp H.1 hι.toFinset (fun z hz ↦ by simp only [Set.Finite.mem_toFinset] at hz exact isClosed_of_mem_irreducibleComponents _ hz.1) (by rw [Set.Finite.coe_toFinset, Set.sUnion_eq_iUnion] rw [Set.diff_eq_empty] at r exact r) simp only [Set.Finite.mem_toFinset] at hZ' exact hZ'.1.2 <| le_antisymm (H.2 hZ'.1.1.1 hZ'.2) hZ'.2 have hU1 : U = (⋃ (x : ι), x.1) ᶜ := by rw [Set.compl_eq_univ_diff] refine le_antisymm (Set.diff_subset_diff le_top subset_rfl) ?_ rw [← Set.compl_eq_univ_diff] refine Set.compl_subset_iff_union.mpr (le_antisymm le_top ?_) rw [Set.union_comm, ← Set.sUnion_eq_iUnion, ← Set.sUnion_insert] rintro a - by_cases h : a ∈ U · exact ⟨U, Set.mem_insert _ _, h⟩ · rw [Set.mem_diff, Decidable.not_and_iff_not_or_not, not_not, Set.mem_iUnion] at h rcases h with (h|⟨i, hi⟩) · refine ⟨irreducibleComponent a, Or.inr ?_, mem_irreducibleComponent⟩ simp only [ι, Set.mem_diff, Set.mem_singleton_iff] refine ⟨irreducibleComponent_mem_irreducibleComponents _, ?_⟩ rintro rfl exact h mem_irreducibleComponent · exact ⟨i, Or.inr i.2, hi⟩ refine ⟨U, hU1 ▸ isOpen_compl_iff.mpr ?_, hU0, sdiff_le⟩ exact isClosed_iUnion_of_finite fun i ↦ isClosed_of_mem_irreducibleComponents i.1 i.2.1 end TopologicalSpace
.lake/packages/mathlib/Mathlib/Topology/TietzeExtension.lean
import Mathlib.Order.Interval.Set.IsoIoo import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.UrysohnsBounded /-! # Tietze extension theorem In this file we prove a few version of the Tietze extension theorem. The theorem says that a continuous function `s → ℝ` defined on a closed set in a normal topological space `Y` can be extended to a continuous function on the whole space. Moreover, if all values of the original function belong to some (finite or infinite, open or closed) interval, then the extension can be chosen so that it takes values in the same interval. In particular, if the original function is a bounded function, then there exists a bounded extension of the same norm. The proof mostly follows <https://ncatlab.org/nlab/show/Tietze+extension+theorem>. We patch a small gap in the proof for unbounded functions, see `exists_extension_forall_exists_le_ge_of_isClosedEmbedding`. In addition we provide a class `TietzeExtension` encoding the idea that a topological space satisfies the Tietze extension theorem. This allows us to get a version of the Tietze extension theorem that simultaneously applies to `ℝ`, `ℝ × ℝ`, `ℂ`, `ι → ℝ`, `ℝ≥0` et cetera. At some point in the future, it may be desirable to provide instead a more general approach via *absolute retracts*, but the current implementation covers the most common use cases easily. ## Implementation notes We first prove the theorems for a closed embedding `e : X → Y` of a topological space into a normal topological space, then specialize them to the case `X = s : Set Y`, `e = (↑)`. ## Tags Tietze extension theorem, Urysohn's lemma, normal topological space -/ open Topology /-! ### The `TietzeExtension` class -/ section TietzeExtensionClass universe u u₁ u₂ v w -- TODO: define *absolute retracts* and then prove they satisfy Tietze extension. -- Then make instances of that instead and remove this class. /-- A class encoding the concept that a space satisfies the Tietze extension property. -/ class TietzeExtension (Y : Type v) [TopologicalSpace Y] : Prop where exists_restrict_eq' {X : Type u} [TopologicalSpace X] [NormalSpace X] (s : Set X) (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f variable {X₁ : Type u₁} [TopologicalSpace X₁] variable {X : Type u} [TopologicalSpace X] [NormalSpace X] {s : Set X} variable {e : X₁ → X} variable {Y : Type v} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] /-- **Tietze extension theorem** for `TietzeExtension` spaces, a version for a closed set. Let `s` be a closed set in a normal topological space `X`. Let `f` be a continuous function on `s` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g.restrict s = f`. -/ theorem ContinuousMap.exists_restrict_eq (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f := TietzeExtension.exists_restrict_eq' s hs f /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. -/ theorem ContinuousMap.exists_extension (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g.comp ⟨e, he.continuous⟩ = f := by let e' : X₁ ≃ₜ Set.range e := he.isEmbedding.toHomeomorph obtain ⟨g, hg⟩ := (f.comp e'.symm).exists_restrict_eq he.isClosed_range exact ⟨g, by ext x; simpa using congr($(hg) ⟨e' x, x, rfl⟩)⟩ /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. This version is provided for convenience and backwards compatibility. Here the composition is phrased in terms of bare functions. -/ theorem ContinuousMap.exists_extension' (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g ∘ e = f := f.exists_extension he |>.imp fun g hg ↦ by ext x; congrm($(hg) x) /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_forall_mem_restrict_eq (hs : IsClosed s) {Y : Type v} [TopologicalSpace Y] (f : C(s, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.restrict s = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_restrict_eq hs exact ⟨comp ⟨Subtype.val, by fun_prop⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_extension_forall_mem (he : IsClosedEmbedding e) {Y : Type v} [TopologicalSpace Y] (f : C(X₁, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.comp ⟨e, he.continuous⟩ = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_extension he exact ⟨comp ⟨Subtype.val, by fun_prop⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ instance Pi.instTietzeExtension {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [∀ i, TietzeExtension.{u} (Y i)] : TietzeExtension.{u} (∀ i, Y i) where exists_restrict_eq' s hs f := by obtain ⟨g', hg'⟩ := Classical.skolem.mp <| fun i ↦ ContinuousMap.exists_restrict_eq hs (ContinuousMap.piEquiv _ _ |>.symm f i) exact ⟨ContinuousMap.piEquiv _ _ g', by ext x i; congrm($(hg' i) x)⟩ instance Prod.instTietzeExtension {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] : TietzeExtension.{u, max w v} (Y × Z) where exists_restrict_eq' s hs f := by obtain ⟨g₁, hg₁⟩ := (ContinuousMap.fst.comp f).exists_restrict_eq hs obtain ⟨g₂, hg₂⟩ := (ContinuousMap.snd.comp f).exists_restrict_eq hs exact ⟨g₁.prodMk g₂, by ext1 x; congrm(($(hg₁) x), $(hg₂) x)⟩ instance Unique.instTietzeExtension {Y : Type v} [TopologicalSpace Y] [Nonempty Y] [Subsingleton Y] : TietzeExtension.{u, v} Y where exists_restrict_eq' _ _ f := ‹Nonempty Y›.elim fun y ↦ ⟨.const _ y, by ext; subsingleton⟩ /-- Any retract of a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_retract {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (ι : C(Y, Z)) (r : C(Z, Y)) (h : r.comp ι = .id Y) : TietzeExtension.{u, v} Y where exists_restrict_eq' s hs f := by obtain ⟨g, hg⟩ := (ι.comp f).exists_restrict_eq hs use r.comp g ext1 x have := congr(r.comp $(hg)) rw [← r.comp_assoc ι, h, f.id_comp] at this congrm($this x) /-- Any homeomorphism from a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_homeo {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (e : Y ≃ₜ Z) : TietzeExtension.{u, v} Y := .of_retract (e : C(Y, Z)) (e.symm : C(Z, Y)) <| by simp end TietzeExtensionClass /-! The Tietze extension theorem for `ℝ`. -/ variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [NormalSpace Y] open Metric Set Filter open BoundedContinuousFunction Topology noncomputable section namespace BoundedContinuousFunction /-- One step in the proof of the Tietze extension theorem. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the norm `‖g‖ ≤ ‖f‖ / 3` such that the distance between `g ∘ e` and `f` is at most `(2 / 3) * ‖f‖`. -/ theorem tietze_extension_step (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ ≤ ‖f‖ / 3 ∧ dist (g.compContinuous e) f ≤ 2 / 3 * ‖f‖ := by have h3 : (0 : ℝ) < 3 := by norm_num1 have h23 : 0 < (2 / 3 : ℝ) := by norm_num1 -- In the trivial case `f = 0`, we take `g = 0` rcases eq_or_ne f 0 with (rfl | hf) · simp replace hf : 0 < ‖f‖ := norm_pos_iff.2 hf /- Otherwise, the closed sets `e '' (f ⁻¹' (Iic (-‖f‖ / 3)))` and `e '' (f ⁻¹' (Ici (‖f‖ / 3)))` are disjoint, hence by Urysohn's lemma there exists a function `g` that is equal to `-‖f‖ / 3` on the former set and is equal to `‖f‖ / 3` on the latter set. This function `g` satisfies the assertions of the lemma. -/ have hf3 : -‖f‖ / 3 < ‖f‖ / 3 := (div_lt_div_iff_of_pos_right h3).2 (Left.neg_lt_self hf) have hc₁ : IsClosed (e '' (f ⁻¹' Iic (-‖f‖ / 3))) := he.isClosedMap _ (isClosed_Iic.preimage f.continuous) have hc₂ : IsClosed (e '' (f ⁻¹' Ici (‖f‖ / 3))) := he.isClosedMap _ (isClosed_Ici.preimage f.continuous) have hd : Disjoint (e '' (f ⁻¹' Iic (-‖f‖ / 3))) (e '' (f ⁻¹' Ici (‖f‖ / 3))) := by refine disjoint_image_of_injective he.injective (Disjoint.preimage _ ?_) rwa [Iic_disjoint_Ici, not_le] rcases exists_bounded_mem_Icc_of_closed_of_le hc₁ hc₂ hd hf3.le with ⟨g, hg₁, hg₂, hgf⟩ refine ⟨g, ?_, ?_⟩ · refine (norm_le <| div_nonneg hf.le h3.le).mpr fun y => ?_ simpa [abs_le, neg_div] using hgf y · refine (dist_le <| mul_nonneg h23.le hf.le).mpr fun x => ?_ have hfx : -‖f‖ ≤ f x ∧ f x ≤ ‖f‖ := by simpa only [Real.norm_eq_abs, abs_le] using f.norm_coe_le_norm x rcases le_total (f x) (-‖f‖ / 3) with hle₁ | hle₁ · calc |g (e x) - f x| = -‖f‖ / 3 - f x := by rw [hg₁ (mem_image_of_mem _ hle₁), Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₁)] _ ≤ 2 / 3 * ‖f‖ := by linarith · rcases le_total (f x) (‖f‖ / 3) with hle₂ | hle₂ · simp only [neg_div] at * calc dist (g (e x)) (f x) ≤ |g (e x)| + |f x| := dist_le_norm_add_norm _ _ _ ≤ ‖f‖ / 3 + ‖f‖ / 3 := (add_le_add (abs_le.2 <| hgf _) (abs_le.2 ⟨hle₁, hle₂⟩)) _ = 2 / 3 * ‖f‖ := by linarith · calc |g (e x) - f x| = f x - ‖f‖ / 3 := by rw [hg₂ (mem_image_of_mem _ hle₂), abs_sub_comm, Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₂)] _ ≤ 2 / 3 * ‖f‖ := by linarith /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and bundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/ theorem exists_extension_norm_eq_of_isClosedEmbedding' (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g.compContinuous e = f := by /- For the proof, we iterate `tietze_extension_step`. Each time we apply it to the difference between the previous approximation and `f`. -/ choose F hF_norm hF_dist using fun f : X →ᵇ ℝ => tietze_extension_step f e he set g : ℕ → Y →ᵇ ℝ := fun n => (fun g => g + F (f - g.compContinuous e))^[n] 0 have g0 : g 0 = 0 := rfl have g_succ : ∀ n, g (n + 1) = g n + F (f - (g n).compContinuous e) := fun n => Function.iterate_succ_apply' _ _ _ have hgf : ∀ n, dist ((g n).compContinuous e) f ≤ (2 / 3) ^ n * ‖f‖ := by intro n induction n with | zero => simp [g0] | succ n ihn => rw [g_succ n, add_compContinuous, ← dist_sub_right, add_sub_cancel_left, pow_succ', mul_assoc] refine (hF_dist _).trans (mul_le_mul_of_nonneg_left ?_ (by norm_num1)) rwa [← dist_eq_norm'] have hg_dist : ∀ n, dist (g n) (g (n + 1)) ≤ 1 / 3 * ‖f‖ * (2 / 3) ^ n := by intro n calc dist (g n) (g (n + 1)) = ‖F (f - (g n).compContinuous e)‖ := by rw [g_succ, dist_eq_norm', add_sub_cancel_left] _ ≤ ‖f - (g n).compContinuous e‖ / 3 := hF_norm _ _ = 1 / 3 * dist ((g n).compContinuous e) f := by rw [dist_eq_norm', one_div, div_eq_inv_mul] _ ≤ 1 / 3 * ((2 / 3) ^ n * ‖f‖) := mul_le_mul_of_nonneg_left (hgf n) (by norm_num1) _ = 1 / 3 * ‖f‖ * (2 / 3) ^ n := by ac_rfl have hg_cau : CauchySeq g := cauchySeq_of_le_geometric _ _ (by norm_num1) hg_dist have : Tendsto (fun n => (g n).compContinuous e) atTop (𝓝 <| (limUnder atTop g).compContinuous e) := ((continuous_compContinuous e).tendsto _).comp hg_cau.tendsto_limUnder have hge : (limUnder atTop g).compContinuous e = f := by refine tendsto_nhds_unique this (tendsto_iff_dist_tendsto_zero.2 ?_) refine squeeze_zero (fun _ => dist_nonneg) hgf ?_ rw [← zero_mul ‖f‖] refine (tendsto_pow_atTop_nhds_zero_of_lt_one ?_ ?_).mul tendsto_const_nhds <;> norm_num1 refine ⟨limUnder atTop g, le_antisymm ?_ ?_, hge⟩ · rw [← dist_zero_left, ← g0] refine (dist_le_of_le_geometric_of_tendsto₀ _ _ (by norm_num1) hg_dist hg_cau.tendsto_limUnder).trans_eq ?_ ring · rw [← hge] exact norm_compContinuous_le _ _ /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and unbundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/ theorem exists_extension_norm_eq_of_isClosedEmbedding (f : X →ᵇ ℝ) {e : X → Y} (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g ∘ e = f := by rcases exists_extension_norm_eq_of_isClosedEmbedding' f ⟨e, he.continuous⟩ he with ⟨g, hg, rfl⟩ exact ⟨g, hg, rfl⟩ /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed set. If `f` is a bounded continuous real-valued function defined on a closed set in a normal topological space, then it can be extended to a bounded continuous function of the same norm defined on the whole space. -/ theorem exists_norm_eq_restrict_eq_of_closed {s : Set Y} (f : s →ᵇ ℝ) (hs : IsClosed s) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g.restrict s = f := exists_extension_norm_eq_of_isClosedEmbedding' f ((ContinuousMap.id _).restrict s) hs.isClosedEmbedding_subtypeVal /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed embedding and a bounded continuous function that takes values in a non-trivial closed interval. See also `exists_extension_forall_mem_of_isClosedEmbedding` for a more general statement that works for any interval (finite or infinite, open or closed). If `e : X → Y` is a closed embedding and `f : X →ᵇ ℝ` is a bounded continuous function such that `f x ∈ [a, b]` for all `x`, where `a ≤ b`, then there exists a bounded continuous function `g : Y →ᵇ ℝ` such that `g y ∈ [a, b]` for all `y` and `g ∘ e = f`. -/ theorem exists_extension_forall_mem_Icc_of_isClosedEmbedding (f : X →ᵇ ℝ) {a b : ℝ} {e : X → Y} (hf : ∀ x, f x ∈ Icc a b) (hle : a ≤ b) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, (∀ y, g y ∈ Icc a b) ∧ g ∘ e = f := by rcases exists_extension_norm_eq_of_isClosedEmbedding (f - const X ((a + b) / 2)) he with ⟨g, hgf, hge⟩ refine ⟨const Y ((a + b) / 2) + g, fun y => ?_, ?_⟩ · suffices ‖f - const X ((a + b) / 2)‖ ≤ (b - a) / 2 by simpa [Real.Icc_eq_closedBall, add_mem_closedBall_iff_norm] using (norm_coe_le_norm g y).trans (hgf.trans_le this) refine (norm_le <| div_nonneg (sub_nonneg.2 hle) zero_le_two).2 fun x => ?_ simpa only [Real.Icc_eq_closedBall] using hf x · ext x have : g (e x) = f x - (a + b) / 2 := congr_fun hge x simp [this] /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed embedding. Let `e` be a closed embedding of a nonempty topological space `X` into a normal topological space `Y`. Let `f` be a bounded continuous real-valued function on `X`. Then there exists a bounded continuous function `g : Y →ᵇ ℝ` such that `g ∘ e = f` and each value `g y` belongs to a closed interval `[f x₁, f x₂]` for some `x₁` and `x₂`. -/ theorem exists_extension_forall_exists_le_ge_of_isClosedEmbedding [Nonempty X] (f : X →ᵇ ℝ) {e : X → Y} (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, (∀ y, ∃ x₁ x₂, g y ∈ Icc (f x₁) (f x₂)) ∧ g ∘ e = f := by inhabit X -- Put `a = ⨅ x, f x` and `b = ⨆ x, f x` obtain ⟨a, ha⟩ : ∃ a, IsGLB (range f) a := ⟨_, isGLB_ciInf f.isBounded_range.bddBelow⟩ obtain ⟨b, hb⟩ : ∃ b, IsLUB (range f) b := ⟨_, isLUB_ciSup f.isBounded_range.bddAbove⟩ -- Then `f x ∈ [a, b]` for all `x` have hmem : ∀ x, f x ∈ Icc a b := fun x => ⟨ha.1 ⟨x, rfl⟩, hb.1 ⟨x, rfl⟩⟩ -- Rule out the trivial case `a = b` have hle : a ≤ b := (hmem default).1.trans (hmem default).2 rcases hle.eq_or_lt with (rfl | hlt) · have : ∀ x, f x = a := by simpa using hmem use const Y a simp [this, funext_iff] -- Put `c = (a + b) / 2`. Then `a < c < b` and `c - a = b - c`. set c := (a + b) / 2 have hac : a < c := left_lt_add_div_two.2 hlt have hcb : c < b := add_div_two_lt_right.2 hlt have hsub : c - a = b - c := by simp [c] ring /- Due to `exists_extension_forall_mem_Icc_of_isClosedEmbedding`, there exists an extension `g` such that `g y ∈ [a, b]` for all `y`. However, if `a` and/or `b` do not belong to the range of `f`, then we need to ensure that these points do not belong to the range of `g`. This is done in two almost identical steps. First we deal with the case `∀ x, f x ≠ a`. -/ obtain ⟨g, hg_mem, hgf⟩ : ∃ g : Y →ᵇ ℝ, (∀ y, ∃ x, g y ∈ Icc (f x) b) ∧ g ∘ e = f := by rcases exists_extension_forall_mem_Icc_of_isClosedEmbedding f hmem hle he with ⟨g, hg_mem, hgf⟩ -- If `a ∈ range f`, then we are done. rcases em (∃ x, f x = a) with (⟨x, rfl⟩ | ha') · exact ⟨g, fun y => ⟨x, hg_mem _⟩, hgf⟩ /- Otherwise, `g ⁻¹' {a}` is disjoint with `range e ∪ g ⁻¹' (Ici c)`, hence there exists a function `dg : Y → ℝ` such that `dg ∘ e = 0`, `dg y = 0` whenever `c ≤ g y`, `dg y = c - a` whenever `g y = a`, and `0 ≤ dg y ≤ c - a` for all `y`. -/ have hd : Disjoint (range e ∪ g ⁻¹' Ici c) (g ⁻¹' {a}) := by refine disjoint_union_left.2 ⟨?_, Disjoint.preimage _ ?_⟩ · rw [Set.disjoint_left] rintro _ ⟨x, rfl⟩ (rfl : g (e x) = a) exact ha' ⟨x, (congr_fun hgf x).symm⟩ · exact Set.disjoint_singleton_right.2 hac.not_ge rcases exists_bounded_mem_Icc_of_closed_of_le (he.isClosed_range.union <| isClosed_Ici.preimage g.continuous) (isClosed_singleton.preimage g.continuous) hd (sub_nonneg.2 hac.le) with ⟨dg, dg0, dga, dgmem⟩ replace hgf : ∀ x, (g + dg) (e x) = f x := by intro x simp [dg0 (Or.inl <| mem_range_self _), ← hgf] refine ⟨g + dg, fun y => ?_, funext hgf⟩ have hay : a < (g + dg) y := by rcases (hg_mem y).1.eq_or_lt with (rfl | hlt) · refine (lt_add_iff_pos_right _).2 ?_ calc 0 < c - g y := sub_pos.2 hac _ = dg y := (dga rfl).symm · exact hlt.trans_le (le_add_of_nonneg_right (dgmem y).1) rcases ha.exists_between hay with ⟨_, ⟨x, rfl⟩, _, hxy⟩ refine ⟨x, hxy.le, ?_⟩ rcases le_total c (g y) with hc | hc · simp [dg0 (Or.inr hc), (hg_mem y).2] · calc g y + dg y ≤ c + (c - a) := add_le_add hc (dgmem _).2 _ = b := by rw [hsub, add_sub_cancel] /- Now we deal with the case `∀ x, f x ≠ b`. The proof is the same as in the first case, with minor modifications that make it hard to deduplicate code. -/ choose xl hxl hgb using hg_mem rcases em (∃ x, f x = b) with (⟨x, rfl⟩ | hb') · exact ⟨g, fun y => ⟨xl y, x, hxl y, hgb y⟩, hgf⟩ have hd : Disjoint (range e ∪ g ⁻¹' Iic c) (g ⁻¹' {b}) := by refine disjoint_union_left.2 ⟨?_, Disjoint.preimage _ ?_⟩ · rw [Set.disjoint_left] rintro _ ⟨x, rfl⟩ (rfl : g (e x) = b) exact hb' ⟨x, (congr_fun hgf x).symm⟩ · exact Set.disjoint_singleton_right.2 hcb.not_ge rcases exists_bounded_mem_Icc_of_closed_of_le (he.isClosed_range.union <| isClosed_Iic.preimage g.continuous) (isClosed_singleton.preimage g.continuous) hd (sub_nonneg.2 hcb.le) with ⟨dg, dg0, dgb, dgmem⟩ replace hgf : ∀ x, (g - dg) (e x) = f x := by intro x simp [dg0 (Or.inl <| mem_range_self _), ← hgf] refine ⟨g - dg, fun y => ?_, funext hgf⟩ have hyb : (g - dg) y < b := by rcases (hgb y).eq_or_lt with (rfl | hlt) · refine (sub_lt_self_iff _).2 ?_ calc 0 < g y - c := sub_pos.2 hcb _ = dg y := (dgb rfl).symm · exact ((sub_le_self_iff _).2 (dgmem _).1).trans_lt hlt rcases hb.exists_between hyb with ⟨_, ⟨xu, rfl⟩, hyxu, _⟩ rcases lt_or_ge c (g y) with hc | hc · rcases em (a ∈ range f) with (⟨x, rfl⟩ | _) · refine ⟨x, xu, ?_, hyxu.le⟩ calc f x = c - (b - c) := by rw [← hsub, sub_sub_cancel] _ ≤ g y - dg y := sub_le_sub hc.le (dgmem _).2 · have hay : a < (g - dg) y := by calc a = c - (b - c) := by rw [← hsub, sub_sub_cancel] _ < g y - (b - c) := sub_lt_sub_right hc _ _ ≤ g y - dg y := sub_le_sub_left (dgmem _).2 _ rcases ha.exists_between hay with ⟨_, ⟨x, rfl⟩, _, hxy⟩ exact ⟨x, xu, hxy.le, hyxu.le⟩ · refine ⟨xl y, xu, ?_, hyxu.le⟩ simp [dg0 (Or.inr hc), hxl] /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed embedding. Let `e` be a closed embedding of a nonempty topological space `X` into a normal topological space `Y`. Let `f` be a bounded continuous real-valued function on `X`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x`. Then there exists a bounded continuous real-valued function `g : Y →ᵇ ℝ` such that `g y ∈ t` for all `y` and `g ∘ e = f`. -/ theorem exists_extension_forall_mem_of_isClosedEmbedding (f : X →ᵇ ℝ) {t : Set ℝ} {e : X → Y} [hs : OrdConnected t] (hf : ∀ x, f x ∈ t) (hne : t.Nonempty) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, (∀ y, g y ∈ t) ∧ g ∘ e = f := by cases isEmpty_or_nonempty X · rcases hne with ⟨c, hc⟩ exact ⟨const Y c, fun _ => hc, funext fun x => isEmptyElim x⟩ rcases exists_extension_forall_exists_le_ge_of_isClosedEmbedding f he with ⟨g, hg, hgf⟩ refine ⟨g, fun y => ?_, hgf⟩ rcases hg y with ⟨xl, xu, h⟩ exact hs.out (hf _) (hf _) h /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed set. Let `s` be a closed set in a normal topological space `Y`. Let `f` be a bounded continuous real-valued function on `s`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x : s`. Then there exists a bounded continuous real-valued function `g : Y →ᵇ ℝ` such that `g y ∈ t` for all `y` and `g.restrict s = f`. -/ theorem exists_forall_mem_restrict_eq_of_closed {s : Set Y} (f : s →ᵇ ℝ) (hs : IsClosed s) {t : Set ℝ} [OrdConnected t] (hf : ∀ x, f x ∈ t) (hne : t.Nonempty) : ∃ g : Y →ᵇ ℝ, (∀ y, g y ∈ t) ∧ g.restrict s = f := by obtain ⟨g, hg, hgf⟩ := exists_extension_forall_mem_of_isClosedEmbedding f hf hne hs.isClosedEmbedding_subtypeVal exact ⟨g, hg, DFunLike.coe_injective hgf⟩ end BoundedContinuousFunction namespace ContinuousMap /-- **Tietze extension theorem** for real-valued continuous maps, a version for a closed embedding. Let `e` be a closed embedding of a nonempty topological space `X` into a normal topological space `Y`. Let `f` be a continuous real-valued function on `X`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x`. Then there exists a continuous real-valued function `g : C(Y, ℝ)` such that `g y ∈ t` for all `y` and `g ∘ e = f`. -/ theorem exists_extension_forall_mem_of_isClosedEmbedding (f : C(X, ℝ)) {t : Set ℝ} {e : X → Y} [hs : OrdConnected t] (hf : ∀ x, f x ∈ t) (hne : t.Nonempty) (he : IsClosedEmbedding e) : ∃ g : C(Y, ℝ), (∀ y, g y ∈ t) ∧ g ∘ e = f := by have h : ℝ ≃o Ioo (-1 : ℝ) 1 := orderIsoIooNegOneOne ℝ let F : X →ᵇ ℝ := { toFun := (↑) ∘ h ∘ f continuous_toFun := by fun_prop map_bounded' := isBounded_range_iff.1 ((isBounded_Ioo (-1 : ℝ) 1).subset <| range_subset_iff.2 fun x => (h (f x)).2) } let t' : Set ℝ := (↑) ∘ h '' t have ht_sub : t' ⊆ Ioo (-1 : ℝ) 1 := image_subset_iff.2 fun x _ => (h x).2 have : OrdConnected t' := by constructor rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ z hz lift z to Ioo (-1 : ℝ) 1 using Icc_subset_Ioo (h x).2.1 (h y).2.2 hz change z ∈ Icc (h x) (h y) at hz rw [← h.image_Icc] at hz rcases hz with ⟨z, hz, rfl⟩ exact ⟨z, hs.out hx hy hz, rfl⟩ have hFt : ∀ x, F x ∈ t' := fun x => mem_image_of_mem _ (hf x) rcases F.exists_extension_forall_mem_of_isClosedEmbedding hFt (hne.image _) he with ⟨G, hG, hGF⟩ let g : C(Y, ℝ) := ⟨h.symm ∘ codRestrict G _ fun y => ht_sub (hG y), h.symm.continuous.comp <| G.continuous.subtype_mk _⟩ have hgG : ∀ {y a}, g y = a ↔ G y = h a := @fun y a => h.toEquiv.symm_apply_eq.trans Subtype.ext_iff refine ⟨g, fun y => ?_, ?_⟩ · rcases hG y with ⟨a, ha, hay⟩ convert ha exact hgG.2 hay.symm · ext x exact hgG.2 (congr_fun hGF _) /-- **Tietze extension theorem** for real-valued continuous maps, a version for a closed set. Let `s` be a closed set in a normal topological space `Y`. Let `f` be a continuous real-valued function on `s`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x : s`. Then there exists a continuous real-valued function `g : C(Y, ℝ)` such that `g y ∈ t` for all `y` and `g.restrict s = f`. -/ theorem exists_restrict_eq_forall_mem_of_closed {s : Set Y} (f : C(s, ℝ)) {t : Set ℝ} [OrdConnected t] (ht : ∀ x, f x ∈ t) (hne : t.Nonempty) (hs : IsClosed s) : ∃ g : C(Y, ℝ), (∀ y, g y ∈ t) ∧ g.restrict s = f := let ⟨g, hgt, hgf⟩ := exists_extension_forall_mem_of_isClosedEmbedding f ht hne hs.isClosedEmbedding_subtypeVal ⟨g, hgt, coe_injective hgf⟩ end ContinuousMap /-- **Tietze extension theorem** for real-valued continuous maps. `ℝ` is a `TietzeExtension` space. -/ instance Real.instTietzeExtension : TietzeExtension ℝ where exists_restrict_eq' _s hs f := f.exists_restrict_eq_forall_mem_of_closed (fun _ => mem_univ _) univ_nonempty hs |>.imp fun _ ↦ (And.right ·) open NNReal in /-- **Tietze extension theorem** for nonnegative real-valued continuous maps. `ℝ≥0` is a `TietzeExtension` space. -/ instance NNReal.instTietzeExtension : TietzeExtension ℝ≥0 := .of_retract ⟨((↑) : ℝ≥0 → ℝ), by continuity⟩ ⟨Real.toNNReal, continuous_real_toNNReal⟩ <| by ext; simp
.lake/packages/mathlib/Mathlib/Topology/ApproximateUnit.lean
import Mathlib.Topology.Algebra.Monoid /-! # Approximate units An *approximate unit* is a filter `l` such that multiplication on the left (or right) by `m : α` tends to `𝓝 m` along the filter, and additionally `l ≠ ⊥`. Examples of approximate units include: - The trivial approximate unit `pure 1` in a normed ring. - `𝓝 1` or `𝓝[≠] 1` in a normed ring (note that the latter is disjoint from `pure 1`). - In a C⋆-algebra, the filter generated by the sections `fun a ↦ {x | a ≤ x} ∩ closedBall 0 1`, where `a` ranges over the positive elements of norm strictly less than 1. -/ open Filter Topology /-- An *approximate unit* is a proper filter (i.e., `≠ ⊥`) such that multiplication on the left (and separately on the right) by `m : α` tends to `𝓝 m` along the filter. -/ structure Filter.IsApproximateUnit {α : Type*} [TopologicalSpace α] [Mul α] (l : Filter α) : Prop where /-- Multiplication on the left by `m` tends to `𝓝 m` along the filter. -/ tendsto_mul_left m : Tendsto (m * ·) l (𝓝 m) /-- Multiplication on the right by `m` tends to `𝓝 m` along the filter. -/ tendsto_mul_right m : Tendsto (· * m) l (𝓝 m) /-- The filter is not `⊥`. -/ protected [neBot : NeBot l] namespace Filter.IsApproximateUnit section TopologicalMonoid variable {α : Type*} [TopologicalSpace α] [MulOneClass α] variable (α) in /-- A unital magma with a topology and bornology has the trivial approximate unit `pure 1`. -/ lemma pure_one : IsApproximateUnit (pure (1 : α)) where tendsto_mul_left m := by simpa using tendsto_pure_nhds (m * ·) (1 : α) tendsto_mul_right m := by simpa using tendsto_pure_nhds (· * m) (1 : α) /-- If `l` is an approximate unit and `⊥ < l' ≤ l`, then `l'` is also an approximate unit. -/ lemma mono {l l' : Filter α} (hl : l.IsApproximateUnit) (hle : l' ≤ l) [hl' : l'.NeBot] : l'.IsApproximateUnit where tendsto_mul_left m := hl.tendsto_mul_left m |>.mono_left hle tendsto_mul_right m := hl.tendsto_mul_right m |>.mono_left hle variable (α) in /-- In a topological unital magma, `𝓝 1` is an approximate unit. -/ lemma nhds_one [ContinuousMul α] : IsApproximateUnit (𝓝 (1 : α)) where tendsto_mul_left m := by simpa using tendsto_id (x := 𝓝 1) |>.const_mul m tendsto_mul_right m := by simpa using tendsto_id (x := 𝓝 1) |>.mul_const m /-- In a topological unital magma, `𝓝 1` is the largest approximate unit. -/ lemma iff_neBot_and_le_nhds_one [ContinuousMul α] {l : Filter α} : IsApproximateUnit l ↔ l.NeBot ∧ l ≤ 𝓝 1 := ⟨fun hl ↦ ⟨hl.neBot, by simpa using hl.tendsto_mul_left 1⟩, And.elim fun _ hl ↦ nhds_one α |>.mono hl⟩ /-- In a topological unital magma, `𝓝 1` is the largest approximate unit. -/ lemma iff_le_nhds_one [ContinuousMul α] {l : Filter α} [l.NeBot] : IsApproximateUnit l ↔ l ≤ 𝓝 1 := by simpa [iff_neBot_and_le_nhds_one] using fun _ ↦ ‹_› end TopologicalMonoid end Filter.IsApproximateUnit
.lake/packages/mathlib/Mathlib/Topology/Ultrafilter.lean
import Mathlib.Order.Filter.Ultrafilter.Basic import Mathlib.Topology.Continuous /-! # Characterization of basic topological properties in terms of ultrafilters -/ open Set Filter Topology universe u v w x variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} [TopologicalSpace X] [TopologicalSpace Y] {F : Filter α} {u : α → X} theorem Ultrafilter.clusterPt_iff {f : Ultrafilter X} : ClusterPt x f ↔ ↑f ≤ 𝓝 x := ⟨f.le_of_inf_neBot', fun h => ClusterPt.of_le_nhds h⟩ theorem clusterPt_iff_ultrafilter {f : Filter X} : ClusterPt x f ↔ ∃ u : Ultrafilter X, u ≤ f ∧ u ≤ 𝓝 x := by simp_rw [ClusterPt, ← le_inf_iff, exists_ultrafilter_iff, inf_comm] theorem mapClusterPt_iff_ultrafilter : MapClusterPt x F u ↔ ∃ U : Ultrafilter α, U ≤ F ∧ Tendsto u U (𝓝 x) := by simp_rw [MapClusterPt, ClusterPt, ← Filter.push_pull', map_neBot_iff, tendsto_iff_comap, ← le_inf_iff, exists_ultrafilter_iff, inf_comm] theorem isOpen_iff_ultrafilter : IsOpen s ↔ ∀ x ∈ s, ∀ (l : Ultrafilter X), ↑l ≤ 𝓝 x → s ∈ l := by simp_rw [isOpen_iff_mem_nhds, ← mem_iff_ultrafilter] /-- `x` belongs to the closure of `s` if and only if some ultrafilter supported on `s` converges to `x`. -/ theorem mem_closure_iff_ultrafilter : x ∈ closure s ↔ ∃ u : Ultrafilter X, s ∈ u ∧ ↑u ≤ 𝓝 x := by simp [closure_eq_cluster_pts, ClusterPt, ← exists_ultrafilter_iff, and_comm] theorem isClosed_iff_ultrafilter : IsClosed s ↔ ∀ x, ∀ u : Ultrafilter X, ↑u ≤ 𝓝 x → s ∈ u → x ∈ s := by simp [isClosed_iff_clusterPt, ClusterPt, ← exists_ultrafilter_iff] variable {f : X → Y} theorem continuousAt_iff_ultrafilter : ContinuousAt f x ↔ ∀ g : Ultrafilter X, ↑g ≤ 𝓝 x → Tendsto f g (𝓝 (f x)) := tendsto_iff_ultrafilter f (𝓝 x) (𝓝 (f x)) theorem continuous_iff_ultrafilter : Continuous f ↔ ∀ (x) (g : Ultrafilter X), ↑g ≤ 𝓝 x → Tendsto f g (𝓝 (f x)) := by simp only [continuous_iff_continuousAt, continuousAt_iff_ultrafilter]
.lake/packages/mathlib/Mathlib/Topology/ClopenBox.lean
import Mathlib.Topology.Compactness.Bases import Mathlib.Topology.CompactOpen import Mathlib.Topology.Separation.Profinite import Mathlib.Topology.Sets.Closeds /-! # Clopen subsets in Cartesian products In general, a clopen subset in a Cartesian product of topological spaces cannot be written as a union of "clopen boxes", i.e. products of clopen subsets of the components (see [buzyakovaClopenBox] for counterexamples). However, when one of the factors is compact, a clopen subset can be written as such a union. Our argument in `TopologicalSpace.Clopens.exists_prod_subset` follows the one given in [buzyakovaClopenBox]. We deduce that in a product of compact spaces, a clopen subset is a finite union of clopen boxes, and use that to prove that the property of having countably many clopens is preserved by taking Cartesian products of compact spaces (this is relevant to the theory of light profinite sets). ## References - [buzyakovaClopenBox]: *On clopen sets in Cartesian products*, 2001. - [engelking1989]: *General Topology*, 1989. -/ open Function Set Filter TopologicalSpace open scoped Topology variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [CompactSpace Y] namespace TopologicalSpace.Clopens theorem exists_prod_subset (W : Clopens (X × Y)) {a : X × Y} (h : a ∈ W) : ∃ U : Clopens X, a.1 ∈ U ∧ ∃ V : Clopens Y, a.2 ∈ V ∧ U ×ˢ V ≤ W := by have hp : Continuous (fun y : Y ↦ (a.1, y)) := .prodMk_right _ let V : Set Y := {y | (a.1, y) ∈ W} have hV : IsCompact V := (W.2.1.preimage hp).isCompact let U : Set X := {x | MapsTo (Prod.mk x) V W} have hUV : U ×ˢ V ⊆ W := fun ⟨_, _⟩ hw ↦ hw.1 hw.2 exact ⟨⟨U, (ContinuousMap.isClopen_setOf_mapsTo hV W.2).preimage (ContinuousMap.id (X × Y)).curry.2⟩, by simp [U, V, MapsTo], ⟨V, W.2.preimage hp⟩, h, hUV⟩ variable [CompactSpace X] /-- Every clopen set in a product of two compact spaces is a union of finitely many clopen boxes. -/ theorem exists_finset_eq_sup_prod (W : Clopens (X × Y)) : ∃ (I : Finset (Clopens X × Clopens Y)), W = I.sup fun i ↦ i.1 ×ˢ i.2 := by choose! U hxU V hxV hUV using fun x ↦ W.exists_prod_subset (a := x) rcases W.2.1.isCompact.elim_nhds_subcover (fun x ↦ U x ×ˢ V x) (fun x hx ↦ (U x ×ˢ V x).2.isOpen.mem_nhds ⟨hxU x hx, hxV x hx⟩) with ⟨I, hIW, hWI⟩ classical use I.image fun x ↦ (U x, V x) rw [Finset.sup_image] refine le_antisymm (fun x hx ↦ ?_) (Finset.sup_le fun x hx ↦ ?_) · rcases Set.mem_iUnion₂.1 (hWI hx) with ⟨i, hi, hxi⟩ exact SetLike.le_def.1 (Finset.le_sup hi) hxi · exact hUV _ <| hIW _ hx lemma surjective_finset_sup_prod : Surjective fun I : Finset (Clopens X × Clopens Y) ↦ I.sup fun i ↦ i.1 ×ˢ i.2 := fun W ↦ let ⟨I, hI⟩ := W.exists_finset_eq_sup_prod; ⟨I, hI.symm⟩ instance countable_prod [Countable (Clopens X)] [Countable (Clopens Y)] : Countable (Clopens (X × Y)) := surjective_finset_sup_prod.countable instance finite_prod [Finite (Clopens X)] [Finite (Clopens Y)] : Finite (Clopens (X × Y)) := by cases nonempty_fintype (Clopens X) cases nonempty_fintype (Clopens Y) exact .of_surjective _ surjective_finset_sup_prod lemma countable_iff_secondCountable [T2Space X] [TotallyDisconnectedSpace X] : Countable (Clopens X) ↔ SecondCountableTopology X := by refine ⟨fun h ↦ ⟨{s : Set X | IsClopen s}, ?_, ?_⟩, fun h ↦ ?_⟩ · let f : {s : Set X | IsClopen s} → Clopens X := fun s ↦ ⟨s.1, s.2⟩ exact (injective_of_le_imp_le f fun a ↦ a).countable · apply IsTopologicalBasis.eq_generateFrom exact loc_compact_Haus_tot_disc_of_zero_dim · have : ∀ (s : Clopens X), ∃ (t : Finset (countableBasis X)), s.1 = (SetLike.coe t).sUnion := fun s ↦ eq_sUnion_finset_of_isTopologicalBasis_of_isCompact_open _ (isBasis_countableBasis X) s.1 s.2.1.isCompact s.2.2 let f : Clopens X → Finset (countableBasis X) := fun s ↦ (this s).choose have hf : f.Injective := by intro s t (h : Exists.choose _ = Exists.choose _) ext1; change s.carrier = t.carrier rw [(this s).choose_spec, (this t).choose_spec, h] exact hf.countable end TopologicalSpace.Clopens
.lake/packages/mathlib/Mathlib/Topology/StoneCech.lean
import Mathlib.Topology.Compactification.StoneCech deprecated_module (since := "2025-06-07")
.lake/packages/mathlib/Mathlib/Topology/KrullDimension.lean
import Mathlib.Order.KrullDimension import Mathlib.Topology.Irreducible import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.Closeds /-! # The Krull dimension of a topological space The Krull dimension of a topological space is the order-theoretic Krull dimension applied to the collection of all its subsets that are closed and irreducible. Unfolding this definition, it is the length of longest series of closed irreducible subsets ordered by inclusion. ## Main results - `topologicalKrullDim_subspace_le`: For any subspace Y ⊆ X, we have dim(Y) ≤ dim(X) ## Implementation notes The proofs use order-preserving maps between posets of irreducible closed sets to establish dimension inequalities. -/ open Set Function Order TopologicalSpace Topology TopologicalSpace.IrreducibleCloseds /-- The Krull dimension of a topological space is the supremum of lengths of chains of closed irreducible sets. -/ noncomputable def topologicalKrullDim (T : Type*) [TopologicalSpace T] : WithBot ℕ∞ := krullDim (IrreducibleCloseds T) variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] /-! ### Main dimension theorems -/ /-- If `f : Y → X` is inducing, then `dim(Y) ≤ dim(X)`. -/ theorem IsInducing.topologicalKrullDim_le {f : Y → X} (hf : IsInducing f) : topologicalKrullDim Y ≤ topologicalKrullDim X := krullDim_le_of_strictMono _ (map_strictMono_of_isInducing hf) @[deprecated (since := "2025-10-19")] alias IsClosedEmbedding.topologicalKrullDim_le := IsInducing.topologicalKrullDim_le /-- The topological Krull dimension is invariant under homeomorphisms -/ theorem IsHomeomorph.topologicalKrullDim_eq (f : X → Y) (h : IsHomeomorph f) : topologicalKrullDim X = topologicalKrullDim Y := have fwd : topologicalKrullDim X ≤ topologicalKrullDim Y := IsInducing.topologicalKrullDim_le h.isClosedEmbedding.toIsInducing have bwd : topologicalKrullDim Y ≤ topologicalKrullDim X := IsInducing.topologicalKrullDim_le (h.homeomorph f).symm.isClosedEmbedding.toIsInducing le_antisymm fwd bwd /-- The topological Krull dimension of any subspace is at most the dimension of the ambient space. -/ theorem topologicalKrullDim_subspace_le (X : Type*) [TopologicalSpace X] (Y : Set X) : topologicalKrullDim Y ≤ topologicalKrullDim X := IsInducing.topologicalKrullDim_le IsInducing.subtypeVal
.lake/packages/mathlib/Mathlib/Topology/NatEmbedding.lean
import Mathlib.Topology.Homeomorph.Lemmas /-! # Infinite Hausdorff topological spaces In this file we prove several properties of infinite Hausdorff topological spaces. - `exists_seq_infinite_isOpen_pairwise_disjoint`: there exists a sequence of pairwise disjoint infinite open sets; - `exists_topology_isEmbedding_nat`: there exista a topological embedding of `ℕ` into the space; - `exists_infinite_discreteTopology`: there exists an infinite subset with discrete topology. -/ open Function Filter Set Topology variable (X : Type*) [TopologicalSpace X] [T2Space X] [Infinite X] /-- In an infinite Hausdorff topological space, there exists a sequence of pairwise disjoint infinite open sets. -/ theorem exists_seq_infinite_isOpen_pairwise_disjoint : ∃ U : ℕ → Set X, (∀ n, (U n).Infinite) ∧ (∀ n, IsOpen (U n)) ∧ Pairwise (Disjoint on U) := by suffices ∃ U : ℕ → Set X, (∀ n, (U n).Nonempty) ∧ (∀ n, IsOpen (U n)) ∧ Pairwise (Disjoint on U) by rcases this with ⟨U, hne, ho, hd⟩ refine ⟨fun n ↦ ⋃ m, U (.pair n m), ?_, fun _ ↦ isOpen_iUnion fun _ ↦ ho _, ?_⟩ · refine fun n ↦ infinite_iUnion fun i j hij ↦ ?_ suffices n.pair i = n.pair j by simpa apply hd.eq simpa [hij, onFun] using (hne _).ne_empty · refine fun n n' hne ↦ disjoint_iUnion_left.2 fun m ↦ disjoint_iUnion_right.2 fun m' ↦ hd ?_ simp [hne] by_cases h : DiscreteTopology X · refine ⟨fun n ↦ {Infinite.natEmbedding X n}, fun _ ↦ singleton_nonempty _, fun _ ↦ isOpen_discrete _, fun _ _ h ↦ ?_⟩ simpa using h · simp only [discreteTopology_iff_nhds_ne, not_forall, ← ne_eq, ← neBot_iff] at h rcases h with ⟨x, hx⟩ suffices ∃ U : ℕ → Set X, (∀ n, (U n).Nonempty ∧ IsOpen (U n) ∧ (U n)ᶜ ∈ 𝓝 x) ∧ Pairwise (Disjoint on U) by rcases this with ⟨U, hU, hd⟩ exact ⟨U, fun n ↦ (hU n).1, fun n ↦ (hU n).2.1, hd⟩ have : IsSymm (Set X) Disjoint := ⟨fun _ _ h ↦ h.symm⟩ refine exists_seq_of_forall_finset_exists' (fun U : Set X ↦ U.Nonempty ∧ IsOpen U ∧ Uᶜ ∈ 𝓝 x) Disjoint fun S hS ↦ ?_ have : (⋂ U ∈ S, interior (Uᶜ)) \ {x} ∈ 𝓝[≠] x := inter_mem_inf ((biInter_finset_mem _).2 fun U hU ↦ interior_mem_nhds.2 (hS _ hU).2.2) (mem_principal_self _) rcases hx.nonempty_of_mem this with ⟨y, hyU, hyx : y ≠ x⟩ rcases t2_separation hyx with ⟨V, W, hVo, hWo, hyV, hxW, hVW⟩ refine ⟨V ∩ ⋂ U ∈ S, interior (Uᶜ), ⟨⟨y, hyV, hyU⟩, ?_, ?_⟩, fun U hU ↦ ?_⟩ · exact hVo.inter (isOpen_biInter_finset fun _ _ ↦ isOpen_interior) · refine mem_of_superset (hWo.mem_nhds hxW) fun z hzW ⟨hzV, _⟩ ↦ ?_ exact disjoint_left.1 hVW hzV hzW · exact disjoint_left.2 fun z hzU ⟨_, hzU'⟩ ↦ interior_subset (mem_iInter₂.1 hzU' U hU) hzU /-- If `X` is an infinite Hausdorff topological space, then there exists a topological embedding `f : ℕ → X`. Note: this theorem is true for an infinite KC-space but the proof in that case is different. -/ theorem exists_topology_isEmbedding_nat : ∃ f : ℕ → X, IsEmbedding f := by rcases exists_seq_infinite_isOpen_pairwise_disjoint X with ⟨U, hUi, hUo, hd⟩ choose f hf using fun n ↦ (hUi n).nonempty refine ⟨f, IsInducing.isEmbedding ⟨Eq.symm (eq_bot_of_singletons_open fun n ↦ ⟨U n, hUo n, ?_⟩)⟩⟩ refine eq_singleton_iff_unique_mem.2 ⟨hf _, fun m hm ↦ ?_⟩ exact hd.eq (not_disjoint_iff.2 ⟨f m, hf _, hm⟩) /-- If `X` is an infinite Hausdorff topological space, then there exists an infinite set `s : Set X` that has the induced topology is the discrete topology. -/ theorem exists_infinite_discreteTopology : ∃ s : Set X, s.Infinite ∧ DiscreteTopology s := by rcases exists_topology_isEmbedding_nat X with ⟨f, hf⟩ refine ⟨range f, infinite_range_of_injective hf.injective, ?_⟩ exact hf.toHomeomorph.symm.isEmbedding.discreteTopology
.lake/packages/mathlib/Mathlib/Topology/ContinuousOn.lean
import Mathlib.Topology.NhdsWithin /-! # Neighborhoods and continuity relative to a subset This file develops API on the relative versions * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` related to continuity, which are defined in previous definition files. Their basic properties studied in this file include the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. -/ open Set Filter Function Topology variable {α β γ δ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] {f g : α → β} {s s' s₁ t : Set α} {x : α} /-! ## `ContinuousWithinAt` -/ /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as `ContinuousWithinAt.comp` will have a different meaning. -/ theorem ContinuousWithinAt.tendsto (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝 (f x)) := h theorem continuousWithinAt_univ (f : α → β) (x : α) : ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] @[simp] theorem continuousOn_univ {f : α → β} : ContinuousOn f univ ↔ Continuous f := by simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] @[deprecated (since := "2025-07-04")] alias continuous_iff_continuousOn_univ := continuousOn_univ theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ := tendsto_nhdsWithin_iff_subtype h f _ theorem ContinuousWithinAt.tendsto_nhdsWithin {t : Set β} (h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) := tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩ theorem ContinuousWithinAt.tendsto_nhdsWithin_image (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) := h.tendsto_nhdsWithin (mapsTo_image _ _) theorem nhdsWithin_le_comap (ctsf : ContinuousWithinAt f s x) : 𝓝[s] x ≤ comap f (𝓝[f '' s] f x) := ctsf.tendsto_nhdsWithin_image.le_comap theorem ContinuousWithinAt.preimage_mem_nhdsWithin {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h ht theorem ContinuousWithinAt.preimage_mem_nhdsWithin' {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝[f '' s] f x) : f ⁻¹' t ∈ 𝓝[s] x := h.tendsto_nhdsWithin (mapsTo_image _ _) ht theorem ContinuousWithinAt.preimage_mem_nhdsWithin'' {y : β} {s t : Set β} (h : ContinuousWithinAt f (f ⁻¹' s) x) (ht : t ∈ 𝓝[s] y) (hxy : y = f x) : f ⁻¹' t ∈ 𝓝[f ⁻¹' s] x := by rw [hxy] at ht exact h.preimage_mem_nhdsWithin' (nhdsWithin_mono _ (image_preimage_subset f s) ht) theorem continuousWithinAt_of_notMem_closure (hx : x ∉ closure s) : ContinuousWithinAt f s x := by rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] at hx rw [ContinuousWithinAt, hx] exact tendsto_bot @[deprecated (since := "2025-05-23")] alias continuousWithinAt_of_not_mem_closure := continuousWithinAt_of_notMem_closure /-! ## `ContinuousOn` -/ theorem continuousOn_iff : ContinuousOn f s ↔ ∀ x ∈ s, ∀ t : Set β, IsOpen t → f x ∈ t → ∃ u, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [ContinuousOn, ContinuousWithinAt, tendsto_nhds, mem_nhdsWithin] theorem ContinuousOn.continuousWithinAt (hf : ContinuousOn f s) (hx : x ∈ s) : ContinuousWithinAt f s x := hf x hx theorem continuousOn_iff_continuous_restrict : ContinuousOn f s ↔ Continuous (s.restrict f) := by rw [ContinuousOn, continuous_iff_continuousAt]; constructor · rintro h ⟨x, xs⟩ exact (continuousWithinAt_iff_continuousAt_restrict f xs).mp (h x xs) intro h x xs exact (continuousWithinAt_iff_continuousAt_restrict f xs).mpr (h ⟨x, xs⟩) alias ⟨ContinuousOn.restrict, _⟩ := continuousOn_iff_continuous_restrict theorem ContinuousOn.mapsToRestrict {t : Set β} (hf : ContinuousOn f s) (ht : MapsTo f s t) : Continuous (ht.restrict f s t) := hf.restrict.codRestrict _ @[deprecated (since := "05-09-2025")] alias ContinuousOn.restrict_mapsTo := ContinuousOn.mapsToRestrict theorem continuousOn_iff' : ContinuousOn f s ↔ ∀ t : Set β, IsOpen t → ∃ u, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsOpen (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isOpen_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff] constructor <;> · rintro ⟨u, ou, useq⟩ exact ⟨u, ou, by simpa only [Set.inter_comm, eq_comm] using useq⟩ rw [continuousOn_iff_continuous_restrict, continuous_def]; simp only [this] /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any finer topology on the source space. -/ theorem ContinuousOn.mono_dom {α β : Type*} {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₃ f s) : @ContinuousOn α β t₂ t₃ f s := fun x hx _u hu => map_mono (inf_le_inf_right _ <| nhds_mono h₁) (h₂ x hx hu) /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any coarser topology on the target space. -/ theorem ContinuousOn.mono_rng {α β : Type*} {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₂ f s) : @ContinuousOn α β t₁ t₃ f s := fun x hx _u hu => h₂ x hx <| nhds_mono h₁ hu theorem continuousOn_iff_isClosed : ContinuousOn f s ↔ ∀ t : Set β, IsClosed t → ∃ u, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsClosed (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isClosed_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm, Set.inter_comm s] rw [continuousOn_iff_continuous_restrict, continuous_iff_isClosed]; simp only [this] theorem continuous_of_cover_nhds {ι : Sort*} {s : ι → Set α} (hs : ∀ x : α, ∃ i, s i ∈ 𝓝 x) (hf : ∀ i, ContinuousOn f (s i)) : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ let ⟨i, hi⟩ := hs x; by rw [ContinuousAt, ← nhdsWithin_eq_nhds.2 hi] exact hf _ _ (mem_of_mem_nhds hi) @[simp] theorem continuousOn_empty (f : α → β) : ContinuousOn f ∅ := fun _ => False.elim @[simp] theorem continuousOn_singleton (f : α → β) (a : α) : ContinuousOn f {a} := forall_eq.2 <| by simpa only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_left] using fun s => mem_of_mem_nhds theorem Set.Subsingleton.continuousOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : ContinuousOn f s := hs.induction_on (continuousOn_empty f) (continuousOn_singleton f) theorem continuousOn_open_iff (hs : IsOpen s) : ContinuousOn f s ↔ ∀ t, IsOpen t → IsOpen (s ∩ f ⁻¹' t) := by rw [continuousOn_iff'] constructor · intro h t ht rcases h t ht with ⟨u, u_open, hu⟩ rw [inter_comm, hu] apply IsOpen.inter u_open hs · intro h t ht refine ⟨s ∩ f ⁻¹' t, h t ht, ?_⟩ rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] theorem ContinuousOn.isOpen_inter_preimage {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ∩ f ⁻¹' t) := (continuousOn_open_iff hs).1 hf t ht theorem ContinuousOn.isOpen_preimage {t : Set β} (h : ContinuousOn f s) (hs : IsOpen s) (hp : f ⁻¹' t ⊆ s) (ht : IsOpen t) : IsOpen (f ⁻¹' t) := by convert (continuousOn_open_iff hs).mp h t ht rw [inter_comm, inter_eq_self_of_subset_left hp] theorem ContinuousOn.preimage_isClosed_of_isClosed {t : Set β} (hf : ContinuousOn f s) (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s ∩ f ⁻¹' t) := by rcases continuousOn_iff_isClosed.1 hf t ht with ⟨u, hu⟩ rw [inter_comm, hu.2] apply IsClosed.inter hu.1 hs theorem ContinuousOn.preimage_interior_subset_interior_preimage {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) : s ∩ f ⁻¹' interior t ⊆ s ∩ interior (f ⁻¹' t) := calc s ∩ f ⁻¹' interior t ⊆ interior (s ∩ f ⁻¹' t) := interior_maximal (inter_subset_inter (Subset.refl _) (preimage_mono interior_subset)) (hf.isOpen_inter_preimage hs isOpen_interior) _ = s ∩ interior (f ⁻¹' t) := by rw [interior_inter, hs.interior_eq] theorem continuousOn_of_locally_continuousOn (h : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ContinuousOn f (s ∩ t)) : ContinuousOn f s := by intro x xs rcases h x xs with ⟨t, open_t, xt, ct⟩ have := ct x ⟨xs, xt⟩ rwa [ContinuousWithinAt, ← nhdsWithin_restrict _ xt open_t] at this theorem continuousOn_to_generateFrom_iff {β : Type*} {T : Set (Set β)} {f : α → β} : @ContinuousOn α β _ (.generateFrom T) f s ↔ ∀ x ∈ s, ∀ t ∈ T, f x ∈ t → f ⁻¹' t ∈ 𝓝[s] x := forall₂_congr fun x _ => by delta ContinuousWithinAt simp only [TopologicalSpace.nhds_generateFrom, tendsto_iInf, tendsto_principal, mem_setOf_eq, and_imp] exact forall_congr' fun t => forall_swap theorem continuousOn_isOpen_of_generateFrom {β : Type*} {s : Set α} {T : Set (Set β)} {f : α → β} (h : ∀ t ∈ T, IsOpen (s ∩ f ⁻¹' t)) : @ContinuousOn α β _ (.generateFrom T) f s := continuousOn_to_generateFrom_iff.2 fun _x hx t ht hxt => mem_nhdsWithin.2 ⟨_, h t ht, ⟨hx, hxt⟩, fun _y hy => hy.1.2⟩ /-! ## Congruence and monotonicity properties with respect to sets -/ theorem ContinuousWithinAt.mono (h : ContinuousWithinAt f t x) (hs : s ⊆ t) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_mono x hs) theorem ContinuousWithinAt.mono_of_mem_nhdsWithin (h : ContinuousWithinAt f t x) (hs : t ∈ 𝓝[s] x) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_le_of_mem hs) /-- If two sets coincide around `x`, then being continuous within one or the other at `x` is equivalent. See also `continuousWithinAt_congr_set'` which requires that the sets coincide locally away from a point `y`, in a T1 space. -/ theorem continuousWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : ContinuousWithinAt f s x ↔ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_eq_iff_eventuallyEq.mpr h] theorem ContinuousWithinAt.congr_set (hf : ContinuousWithinAt f s x) (h : s =ᶠ[𝓝 x] t) : ContinuousWithinAt f t x := (continuousWithinAt_congr_set h).1 hf theorem continuousWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict'' s h] theorem continuousWithinAt_inter (h : t ∈ 𝓝 x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict' s h] theorem continuousWithinAt_union : ContinuousWithinAt f (s ∪ t) x ↔ ContinuousWithinAt f s x ∧ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_union, tendsto_sup] theorem ContinuousWithinAt.union (hs : ContinuousWithinAt f s x) (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s ∪ t) x := continuousWithinAt_union.2 ⟨hs, ht⟩ @[simp] theorem continuousWithinAt_singleton : ContinuousWithinAt f {x} x := by simp only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_nhds] @[simp] theorem continuousWithinAt_insert_self : ContinuousWithinAt f (insert x s) x ↔ ContinuousWithinAt f s x := by simp only [← singleton_union, continuousWithinAt_union, continuousWithinAt_singleton, true_and] protected alias ⟨_, ContinuousWithinAt.insert⟩ := continuousWithinAt_insert_self /- `continuousWithinAt_insert` gives the same equivalence but at a point `y` possibly different from `x`. As this requires the space to be T1, and this property is not available in this file, this is found in another file although it is part of the basic API for `continuousWithinAt`. -/ theorem ContinuousWithinAt.diff_iff (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s \ t) x ↔ ContinuousWithinAt f s x := ⟨fun h => (h.union ht).mono <| by simp only [diff_union_self, subset_union_left], fun h => h.mono diff_subset⟩ /-- See also `continuousWithinAt_diff_singleton` for the case of `s \ {y}`, but requiring `T1Space α. -/ @[simp] theorem continuousWithinAt_diff_self : ContinuousWithinAt f (s \ {x}) x ↔ ContinuousWithinAt f s x := continuousWithinAt_singleton.diff_iff @[simp] theorem continuousWithinAt_compl_self : ContinuousWithinAt f {x}ᶜ x ↔ ContinuousAt f x := by rw [compl_eq_univ_diff, continuousWithinAt_diff_self, continuousWithinAt_univ] theorem ContinuousOn.mono (hf : ContinuousOn f s) (h : t ⊆ s) : ContinuousOn f t := fun x hx => (hf x (h hx)).mono_left (nhdsWithin_mono _ h) theorem antitone_continuousOn {f : α → β} : Antitone (ContinuousOn f) := fun _s _t hst hf => hf.mono hst /-! ## Relation between `ContinuousAt` and `ContinuousWithinAt` -/ @[fun_prop] theorem ContinuousAt.continuousWithinAt (h : ContinuousAt f x) : ContinuousWithinAt f s x := ContinuousWithinAt.mono ((continuousWithinAt_univ f x).2 h) (subset_univ _) theorem continuousWithinAt_iff_continuousAt (h : s ∈ 𝓝 x) : ContinuousWithinAt f s x ↔ ContinuousAt f x := by rw [← univ_inter s, continuousWithinAt_inter h, continuousWithinAt_univ] theorem ContinuousWithinAt.continuousAt (h : ContinuousWithinAt f s x) (hs : s ∈ 𝓝 x) : ContinuousAt f x := (continuousWithinAt_iff_continuousAt hs).mp h theorem IsOpen.continuousOn_iff (hs : IsOpen s) : ContinuousOn f s ↔ ∀ ⦃a⦄, a ∈ s → ContinuousAt f a := forall₂_congr fun _ => continuousWithinAt_iff_continuousAt ∘ hs.mem_nhds theorem ContinuousOn.continuousAt (h : ContinuousOn f s) (hx : s ∈ 𝓝 x) : ContinuousAt f x := (h x (mem_of_mem_nhds hx)).continuousAt hx theorem continuousOn_of_forall_continuousAt (hcont : ∀ x ∈ s, ContinuousAt f x) : ContinuousOn f s := fun x hx => (hcont x hx).continuousWithinAt @[fun_prop] theorem Continuous.continuousOn (h : Continuous f) : ContinuousOn f s := by rw [← continuousOn_univ] at h exact h.mono (subset_univ _) @[fun_prop] theorem Continuous.continuousWithinAt (h : Continuous f) : ContinuousWithinAt f s x := h.continuousAt.continuousWithinAt /-! ## Congruence properties with respect to functions -/ theorem ContinuousOn.congr_mono (h : ContinuousOn f s) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) : ContinuousOn g s₁ := by intro x hx unfold ContinuousWithinAt have A := (h x (h₁ hx)).mono h₁ unfold ContinuousWithinAt at A rw [← h' hx] at A exact A.congr' h'.eventuallyEq_nhdsWithin.symm theorem ContinuousOn.congr (h : ContinuousOn f s) (h' : EqOn g f s) : ContinuousOn g s := h.congr_mono h' (Subset.refl _) theorem continuousOn_congr (h' : EqOn g f s) : ContinuousOn g s ↔ ContinuousOn f s := ⟨fun h => ContinuousOn.congr h h'.symm, fun h => h.congr h'⟩ theorem Filter.EventuallyEq.congr_continuousWithinAt (h : f =ᶠ[𝓝[s] x] g) (hx : f x = g x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := by rw [ContinuousWithinAt, hx, tendsto_congr' h, ContinuousWithinAt] theorem ContinuousWithinAt.congr_of_eventuallyEq (h : ContinuousWithinAt f s x) (h₁ : g =ᶠ[𝓝[s] x] f) (hx : g x = f x) : ContinuousWithinAt g s x := (h₁.congr_continuousWithinAt hx).2 h theorem ContinuousWithinAt.congr_of_eventuallyEq_of_mem (h : ContinuousWithinAt f s x) (h₁ : g =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContinuousWithinAt g s x := h.congr_of_eventuallyEq h₁ (mem_of_mem_nhdsWithin hx h₁ :) theorem Filter.EventuallyEq.congr_continuousWithinAt_of_mem (h : f =ᶠ[𝓝[s] x] g) (hx : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := ⟨fun h' ↦ h'.congr_of_eventuallyEq_of_mem h.symm hx, fun h' ↦ h'.congr_of_eventuallyEq_of_mem h hx⟩ theorem ContinuousWithinAt.congr_of_eventuallyEq_insert (h : ContinuousWithinAt f s x) (h₁ : g =ᶠ[𝓝[insert x s] x] f) : ContinuousWithinAt g s x := h.congr_of_eventuallyEq (nhdsWithin_mono _ (subset_insert _ _) h₁) (mem_of_mem_nhdsWithin (mem_insert _ _) h₁ :) theorem Filter.EventuallyEq.congr_continuousWithinAt_of_insert (h : f =ᶠ[𝓝[insert x s] x] g) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := ⟨fun h' ↦ h'.congr_of_eventuallyEq_insert h.symm, fun h' ↦ h'.congr_of_eventuallyEq_insert h⟩ theorem ContinuousWithinAt.congr (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, g y = f y) (hx : g x = f x) : ContinuousWithinAt g s x := h.congr_of_eventuallyEq (mem_of_superset self_mem_nhdsWithin h₁) hx theorem continuousWithinAt_congr (h₁ : ∀ y ∈ s, g y = f y) (hx : g x = f x) : ContinuousWithinAt g s x ↔ ContinuousWithinAt f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContinuousWithinAt.congr_of_mem (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, g y = f y) (hx : x ∈ s) : ContinuousWithinAt g s x := h.congr h₁ (h₁ x hx) theorem continuousWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, g y = f y) (hx : x ∈ s) : ContinuousWithinAt g s x ↔ ContinuousWithinAt f s x := continuousWithinAt_congr h₁ (h₁ x hx) theorem ContinuousWithinAt.congr_of_insert (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ insert x s, g y = f y) : ContinuousWithinAt g s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem continuousWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, g y = f y) : ContinuousWithinAt g s x ↔ ContinuousWithinAt f s x := continuousWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContinuousWithinAt.congr_mono (h : ContinuousWithinAt f s x) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x) : ContinuousWithinAt g s₁ x := (h.mono h₁).congr h' hx theorem ContinuousAt.congr_of_eventuallyEq (h : ContinuousAt f x) (hg : g =ᶠ[𝓝 x] f) : ContinuousAt g x := congr h (EventuallyEq.symm hg) /-! ## Composition -/ theorem ContinuousWithinAt.comp {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (hf.tendsto_nhdsWithin h) theorem ContinuousWithinAt.comp_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp hf h theorem ContinuousWithinAt.comp_inter {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp (hf.mono inter_subset_left) inter_subset_right theorem ContinuousWithinAt.comp_inter_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (hy : f x = y) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := by subst hy; exact hg.comp_inter hf theorem ContinuousWithinAt.comp_of_preimage_mem_nhdsWithin {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : f ⁻¹' t ∈ 𝓝[s] x) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within f hf h) theorem ContinuousWithinAt.comp_of_preimage_mem_nhdsWithin_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (h : f ⁻¹' t ∈ 𝓝[s] x) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp_of_preimage_mem_nhdsWithin hf h theorem ContinuousWithinAt.comp_of_mem_nhdsWithin_image {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (hs : t ∈ 𝓝[f '' s] f x) : ContinuousWithinAt (g ∘ f) s x := (hg.mono_of_mem_nhdsWithin hs).comp hf (mapsTo_image f s) theorem ContinuousWithinAt.comp_of_mem_nhdsWithin_image_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (hs : t ∈ 𝓝[f '' s] y) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp_of_mem_nhdsWithin_image hf hs theorem ContinuousAt.comp_continuousWithinAt {g : β → γ} (hg : ContinuousAt g (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) s x := hg.continuousWithinAt.comp hf (mapsTo_univ _ _) theorem ContinuousAt.comp_continuousWithinAt_of_eq {g : β → γ} {y : β} (hg : ContinuousAt g y) (hf : ContinuousWithinAt f s x) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp_continuousWithinAt hf /-- See also `ContinuousOn.comp'` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ theorem ContinuousOn.comp {g : β → γ} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : MapsTo f s t) : ContinuousOn (g ∘ f) s := fun x hx => ContinuousWithinAt.comp (hg _ (h hx)) (hf x hx) h /-- Variant of `ContinuousOn.comp` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ @[fun_prop] theorem ContinuousOn.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : Set.MapsTo f s t) : ContinuousOn (fun x => g (f x)) s := ContinuousOn.comp hg hf h @[fun_prop] theorem ContinuousOn.comp_inter {g : β → γ} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right /-- See also `Continuous.comp_continuousOn'` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ theorem Continuous.comp_continuousOn {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) s := hg.continuousOn.comp hf (mapsTo_univ _ _) /-- Variant of `Continuous.comp_continuousOn` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ @[fun_prop] theorem Continuous.comp_continuousOn' {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ g (f x)) s := hg.comp_continuousOn hf theorem ContinuousOn.comp_continuous {g : β → γ} {f : α → β} {s : Set β} (hg : ContinuousOn g s) (hf : Continuous f) (hs : ∀ x, f x ∈ s) : Continuous (g ∘ f) := by rw [← continuousOn_univ] at * exact hg.comp hf fun x _ => hs x theorem ContinuousOn.image_comp_continuous {g : β → γ} {f : α → β} {s : Set α} (hg : ContinuousOn g (f '' s)) (hf : Continuous f) : ContinuousOn (g ∘ f) s := hg.comp hf.continuousOn (s.mapsTo_image f) theorem ContinuousAt.comp₂_continuousWithinAt {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := ContinuousAt.comp_continuousWithinAt hf (hg.prodMk_nhds hh) theorem ContinuousAt.comp₂_continuousWithinAt_of_eq {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} {y : β × γ} (hf : ContinuousAt f y) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) (e : (g x, h x) = y) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := by rw [← e] at hf exact hf.comp₂_continuousWithinAt hg hh /-! ## Image -/ theorem ContinuousWithinAt.mem_closure_image (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := haveI := mem_closure_iff_nhdsWithin_neBot.1 hx mem_closure_of_tendsto h <| mem_of_superset self_mem_nhdsWithin (subset_preimage_image f s) theorem ContinuousWithinAt.mem_closure {t : Set β} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) (ht : MapsTo f s t) : f x ∈ closure t := closure_mono (image_subset_iff.2 ht) (h.mem_closure_image hx) theorem Set.MapsTo.closure_of_continuousWithinAt {t : Set β} (h : MapsTo f s t) (hc : ∀ x ∈ closure s, ContinuousWithinAt f s x) : MapsTo f (closure s) (closure t) := fun x hx => (hc x hx).mem_closure hx h theorem Set.MapsTo.closure_of_continuousOn {t : Set β} (h : MapsTo f s t) (hc : ContinuousOn f (closure s)) : MapsTo f (closure s) (closure t) := h.closure_of_continuousWithinAt fun x hx => (hc x hx).mono subset_closure theorem ContinuousWithinAt.image_closure (hf : ∀ x ∈ closure s, ContinuousWithinAt f s x) : f '' closure s ⊆ closure (f '' s) := ((mapsTo_image f s).closure_of_continuousWithinAt hf).image_subset theorem ContinuousOn.image_closure (hf : ContinuousOn f (closure s)) : f '' closure s ⊆ closure (f '' s) := ContinuousWithinAt.image_closure fun x hx => (hf x hx).mono subset_closure /-! ## Product -/ theorem ContinuousWithinAt.prodMk {f : α → β} {g : α → γ} {s : Set α} {x : α} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) : ContinuousWithinAt (fun x => (f x, g x)) s x := hf.prodMk_nhds hg @[fun_prop] theorem ContinuousOn.prodMk {f : α → β} {g : α → γ} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk (hg x hx) theorem continuousOn_fst {s : Set (α × β)} : ContinuousOn Prod.fst s := continuous_fst.continuousOn theorem continuousWithinAt_fst {s : Set (α × β)} {p : α × β} : ContinuousWithinAt Prod.fst s p := continuous_fst.continuousWithinAt @[fun_prop] theorem ContinuousOn.fst {f : α → β × γ} {s : Set α} (hf : ContinuousOn f s) : ContinuousOn (fun x => (f x).1) s := continuous_fst.comp_continuousOn hf theorem ContinuousWithinAt.fst {f : α → β × γ} {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => (f x).fst) s a := continuousAt_fst.comp_continuousWithinAt h theorem continuousOn_snd {s : Set (α × β)} : ContinuousOn Prod.snd s := continuous_snd.continuousOn theorem continuousWithinAt_snd {s : Set (α × β)} {p : α × β} : ContinuousWithinAt Prod.snd s p := continuous_snd.continuousWithinAt @[fun_prop] theorem ContinuousOn.snd {f : α → β × γ} {s : Set α} (hf : ContinuousOn f s) : ContinuousOn (fun x => (f x).2) s := continuous_snd.comp_continuousOn hf theorem ContinuousWithinAt.snd {f : α → β × γ} {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => (f x).snd) s a := continuousAt_snd.comp_continuousWithinAt h theorem continuousWithinAt_prod_iff {f : α → β × γ} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (Prod.fst ∘ f) s x ∧ ContinuousWithinAt (Prod.snd ∘ f) s x := ⟨fun h => ⟨h.fst, h.snd⟩, fun ⟨h1, h2⟩ => h1.prodMk h2⟩ theorem ContinuousWithinAt.prodMap {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) : ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := .prodMk (hf.comp continuousWithinAt_fst mapsTo_fst_prod) (hg.comp continuousWithinAt_snd mapsTo_snd_prod) theorem ContinuousOn.prodMap {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hg : ContinuousOn g t) : ContinuousOn (Prod.map f g) (s ×ˢ t) := fun ⟨x, y⟩ ⟨hx, hy⟩ => (hf x hx).prodMap (hg y hy) theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod, ← map_inf_principal_preimage]; rfl theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure, ← map_inf_principal_preimage]; rfl theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl theorem continuousOn_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ b, ContinuousOn (f ⟨·, b⟩) {a | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_right]; apply forall_swap /-- If a function `f a b` is such that `y ↦ f a b` is continuous for all `a`, and `a` lives in a discrete space, then `f` is continuous, and vice versa. -/ theorem continuous_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : Continuous f ↔ ∀ a, Continuous (f ⟨a, ·⟩) := by simp_rw [← continuousOn_univ]; exact continuousOn_prod_of_discrete_left theorem continuous_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : Continuous f ↔ ∀ b, Continuous (f ⟨·, b⟩) := by simp_rw [← continuousOn_univ]; exact continuousOn_prod_of_discrete_right theorem isOpenMap_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : IsOpenMap f ↔ ∀ a, IsOpenMap (f ⟨a, ·⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, nhds_prod_eq, nhds_discrete, pure_prod, map_map] rfl theorem isOpenMap_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : IsOpenMap f ↔ ∀ b, IsOpenMap (f ⟨·, b⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, forall_swap (α := α) (β := β), nhds_prod_eq, nhds_discrete, prod_pure, map_map]; rfl theorem ContinuousOn.uncurry_left {f : α → β → γ} {sα : Set α} {sβ : Set β} (a : α) (ha : a ∈ sα) (h : ContinuousOn f.uncurry (sα ×ˢ sβ)) : ContinuousOn (f a) sβ := by let g : β → γ := f.uncurry ∘ (fun b => (a, b)) refine ContinuousOn.congr (f := g) ?_ (fun y => by simp [g]) exact ContinuousOn.comp h (by fun_prop) (by grind [Set.MapsTo]) theorem ContinuousOn.uncurry_right {f : α → β → γ} {sα : Set α} {sβ : Set β} (b : β) (ha : b ∈ sβ) (h : ContinuousOn f.uncurry (sα ×ˢ sβ)) : ContinuousOn (fun a => f a b) sα := by let g : α → γ := f.uncurry ∘ (fun a => (a, b)) refine ContinuousOn.congr (f := g) ?_ (fun y => by simp [g]) exact ContinuousOn.comp h (by fun_prop) (by grind [Set.MapsTo]) /-! ## Pi -/ theorem continuousWithinAt_pi {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {f : α → ∀ i, X i} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ∀ i, ContinuousWithinAt (fun y => f y i) s x := tendsto_pi_nhds theorem continuousOn_pi {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {f : α → ∀ i, X i} {s : Set α} : ContinuousOn f s ↔ ∀ i, ContinuousOn (fun y => f y i) s := ⟨fun h i x hx => tendsto_pi_nhds.1 (h x hx) i, fun h x hx => tendsto_pi_nhds.2 fun i => h i x hx⟩ @[fun_prop] theorem continuousOn_pi' {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {f : α → ∀ i, X i} {s : Set α} (hf : ∀ i, ContinuousOn (fun y => f y i) s) : ContinuousOn f s := continuousOn_pi.2 hf @[fun_prop] theorem continuousOn_apply {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] (i : ι) (s) : ContinuousOn (fun p : ∀ i, X i => p i) s := Continuous.continuousOn (continuous_apply i) /-! ## Specific functions -/ @[fun_prop] theorem continuousOn_const {s : Set α} {c : β} : ContinuousOn (fun _ => c) s := continuous_const.continuousOn theorem continuousWithinAt_const {b : β} {s : Set α} {x : α} : ContinuousWithinAt (fun _ : α => b) s x := continuous_const.continuousWithinAt theorem continuousOn_id {s : Set α} : ContinuousOn id s := continuous_id.continuousOn @[fun_prop] theorem continuousOn_id' (s : Set α) : ContinuousOn (fun x : α => x) s := continuousOn_id theorem continuousWithinAt_id {s : Set α} {x : α} : ContinuousWithinAt id s x := continuous_id.continuousWithinAt protected theorem ContinuousOn.iterate {f : α → α} {s : Set α} (hcont : ContinuousOn f s) (hmaps : MapsTo f s s) : ∀ n, ContinuousOn (f^[n]) s | 0 => continuousOn_id | (n + 1) => (hcont.iterate hmaps n).comp hcont hmaps section Fin variable {n : ℕ} {X : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (X i)] theorem ContinuousWithinAt.finCons {f : α → X 0} {g : α → ∀ j : Fin n, X (Fin.succ j)} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => Fin.cons (f a) (g a)) s a := hf.tendsto.finCons hg theorem ContinuousOn.finCons {f : α → X 0} {s : Set α} {g : α → ∀ j : Fin n, X (Fin.succ j)} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => Fin.cons (f a) (g a)) s := fun a ha => (hf a ha).finCons (hg a ha) theorem ContinuousWithinAt.matrixVecCons {f : α → β} {g : α → Fin n → β} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => Matrix.vecCons (f a) (g a)) s a := hf.tendsto.matrixVecCons hg theorem ContinuousOn.matrixVecCons {f : α → β} {g : α → Fin n → β} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => Matrix.vecCons (f a) (g a)) s := fun a ha => (hf a ha).matrixVecCons (hg a ha) theorem ContinuousWithinAt.finSnoc {f : α → ∀ j : Fin n, X (Fin.castSucc j)} {g : α → X (Fin.last _)} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => Fin.snoc (f a) (g a)) s a := hf.tendsto.finSnoc hg theorem ContinuousOn.finSnoc {f : α → ∀ j : Fin n, X (Fin.castSucc j)} {g : α → X (Fin.last _)} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => Fin.snoc (f a) (g a)) s := fun a ha => (hf a ha).finSnoc (hg a ha) theorem ContinuousWithinAt.finInsertNth (i : Fin (n + 1)) {f : α → X i} {g : α → ∀ j : Fin n, X (i.succAbove j)} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => i.insertNth (f a) (g a)) s a := hf.tendsto.finInsertNth i hg theorem ContinuousOn.finInsertNth (i : Fin (n + 1)) {f : α → X i} {g : α → ∀ j : Fin n, X (i.succAbove j)} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => i.insertNth (f a) (g a)) s := fun a ha => (hf a ha).finInsertNth i (hg a ha) end Fin theorem Set.LeftInvOn.map_nhdsWithin_eq {f : α → β} {g : β → α} {x : β} {s : Set β} (h : LeftInvOn f g s) (hx : f (g x) = x) (hf : ContinuousWithinAt f (g '' s) (g x)) (hg : ContinuousWithinAt g s x) : map g (𝓝[s] x) = 𝓝[g '' s] g x := by apply le_antisymm · exact hg.tendsto_nhdsWithin (mapsTo_image _ _) · have A : g ∘ f =ᶠ[𝓝[g '' s] g x] id := h.rightInvOn_image.eqOn.eventuallyEq_of_mem self_mem_nhdsWithin refine le_map_of_right_inverse A ?_ simpa only [hx] using hf.tendsto_nhdsWithin (h.mapsTo (surjOn_image _ _)) theorem Function.LeftInverse.map_nhds_eq {f : α → β} {g : β → α} {x : β} (h : Function.LeftInverse f g) (hf : ContinuousWithinAt f (range g) (g x)) (hg : ContinuousAt g x) : map g (𝓝 x) = 𝓝[range g] g x := by simpa only [nhdsWithin_univ, image_univ] using (h.leftInvOn univ).map_nhdsWithin_eq (h x) (by rwa [image_univ]) hg.continuousWithinAt lemma Topology.IsInducing.continuousWithinAt_iff {f : α → β} {g : β → γ} (hg : IsInducing g) {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (g ∘ f) s x := by simp_rw [ContinuousWithinAt, hg.tendsto_nhds_iff]; rfl lemma Topology.IsInducing.continuousOn_iff {f : α → β} {g : β → γ} (hg : IsInducing g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := by simp_rw [ContinuousOn, hg.continuousWithinAt_iff] lemma Topology.IsInducing.map_nhdsWithin_eq {f : α → β} (hf : IsInducing f) (s : Set α) (x : α) : map f (𝓝[s] x) = 𝓝[f '' s] f x := by ext; simp +contextual [mem_nhdsWithin_iff_eventually, hf.nhds_eq_comap, forall_comm (α := _ ∈ _)] lemma Topology.IsInducing.continuousOn_image_iff {g : β → γ} {s : Set α} (hf : IsInducing f) : ContinuousOn g (f '' s) ↔ ContinuousOn (g ∘ f) s := by simp [ContinuousOn, ContinuousWithinAt, ← hf.map_nhdsWithin_eq] lemma Topology.IsEmbedding.continuousOn_iff {f : α → β} {g : β → γ} (hg : IsEmbedding g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := hg.isInducing.continuousOn_iff lemma Topology.IsEmbedding.map_nhdsWithin_eq {f : α → β} (hf : IsEmbedding f) (s : Set α) (x : α) : map f (𝓝[s] x) = 𝓝[f '' s] f x := hf.isInducing.map_nhdsWithin_eq s x theorem Topology.IsOpenEmbedding.map_nhdsWithin_preimage_eq {f : α → β} (hf : IsOpenEmbedding f) (s : Set β) (x : α) : map f (𝓝[f ⁻¹' s] x) = 𝓝[s] f x := by rw [hf.isEmbedding.map_nhdsWithin_eq, image_preimage_eq_inter_range] apply nhdsWithin_eq_nhdsWithin (mem_range_self _) hf.isOpen_range rw [inter_assoc, inter_self] theorem Topology.IsQuotientMap.continuousOn_isOpen_iff {f : α → β} {g : β → γ} (h : IsQuotientMap f) {s : Set β} (hs : IsOpen s) : ContinuousOn g s ↔ ContinuousOn (g ∘ f) (f ⁻¹' s) := by simp only [continuousOn_iff_continuous_restrict, (h.restrictPreimage_isOpen hs).continuous_iff] rfl theorem IsOpenMap.continuousOn_image_of_leftInvOn {f : α → β} {s : Set α} (h : IsOpenMap (s.restrict f)) {finv : β → α} (hleft : LeftInvOn finv f s) : ContinuousOn finv (f '' s) := by refine continuousOn_iff'.2 fun t ht => ⟨f '' (t ∩ s), ?_, ?_⟩ · rw [← image_restrict] exact h _ (ht.preimage continuous_subtype_val) · rw [inter_eq_self_of_subset_left (image_mono inter_subset_right), hleft.image_inter'] theorem IsOpenMap.continuousOn_range_of_leftInverse {f : α → β} (hf : IsOpenMap f) {finv : β → α} (hleft : Function.LeftInverse finv f) : ContinuousOn finv (range f) := by rw [← image_univ] exact (hf.restrict isOpen_univ).continuousOn_image_of_leftInvOn fun x _ => hleft x /-- If `f` is continuous on an open set `s` and continuous at each point of another set `t` then `f` is continuous on `s ∪ t`. -/ lemma ContinuousOn.union_continuousAt {f : α → β} (s_op : IsOpen s) (hs : ContinuousOn f s) (ht : ∀ x ∈ t, ContinuousAt f x) : ContinuousOn f (s ∪ t) := continuousOn_of_forall_continuousAt <| fun _ hx => hx.elim (fun h => ContinuousWithinAt.continuousAt (continuousWithinAt hs h) <| IsOpen.mem_nhds s_op h) (ht _) open Classical in /-- If a function is continuous on two closed sets, it is also continuous on their union. -/ theorem ContinuousOn.union_of_isClosed {f : α → β} (hfs : ContinuousOn f s) (hft : ContinuousOn f t) (hs : IsClosed s) (ht : IsClosed t) : ContinuousOn f (s ∪ t) := by refine fun x hx ↦ .union ?_ ?_ · refine if hx : x ∈ s then hfs x hx else continuousWithinAt_of_notMem_closure ?_ rwa [hs.closure_eq] · refine if hx : x ∈ t then hft x hx else continuousWithinAt_of_notMem_closure ?_ rwa [ht.closure_eq] /-- A function is continuous on two closed sets iff it is also continuous on their union. -/ theorem continouousOn_union_iff_of_isClosed {f : α → β} (hs : IsClosed s) (ht : IsClosed t) : ContinuousOn f (s ∪ t) ↔ ContinuousOn f s ∧ ContinuousOn f t := ⟨fun h ↦ ⟨h.mono s.subset_union_left, h.mono s.subset_union_right⟩, fun h ↦ h.left.union_of_isClosed h.right hs ht⟩ /-- If a function is continuous on two open sets, it is also continuous on their union. -/ theorem ContinuousOn.union_of_isOpen {f : α → β} (hfs : ContinuousOn f s) (hft : ContinuousOn f t) (hs : IsOpen s) (ht : IsOpen t) : ContinuousOn f (s ∪ t) := union_continuousAt hs hfs fun _ hx ↦ ht.continuousOn_iff.mp hft hx /-- A function is continuous on two open sets iff it is also continuous on their union. -/ theorem continouousOn_union_iff_of_isOpen {f : α → β} (hs : IsOpen s) (ht : IsOpen t) : ContinuousOn f (s ∪ t) ↔ ContinuousOn f s ∧ ContinuousOn f t := ⟨fun h ↦ ⟨h.mono s.subset_union_left, h.mono s.subset_union_right⟩, fun h ↦ h.left.union_of_isOpen h.right hs ht⟩ /-- If a function is continuous on open sets `s i`, it is continuous on their union -/ lemma ContinuousOn.iUnion_of_isOpen {ι : Type*} {s : ι → Set α} (hf : ∀ i : ι, ContinuousOn f (s i)) (hs : ∀ i, IsOpen (s i)) : ContinuousOn f (⋃ i, s i) := by rintro x ⟨si, ⟨i, rfl⟩, hxsi⟩ exact (hf i).continuousAt ((hs i).mem_nhds hxsi) |>.continuousWithinAt /-- A function is continuous on a union of open sets `s i` iff it is continuous on each `s i`. -/ lemma continuousOn_iUnion_iff_of_isOpen {ι : Type*} {s : ι → Set α} (hs : ∀ i, IsOpen (s i)) : ContinuousOn f (⋃ i, s i) ↔ ∀ i : ι, ContinuousOn f (s i) := ⟨fun h i ↦ h.mono <| subset_iUnion_of_subset i fun _ a ↦ a, fun h ↦ ContinuousOn.iUnion_of_isOpen h hs⟩ lemma continuous_of_continuousOn_iUnion_of_isOpen {ι : Type*} {s : ι → Set α} (hf : ∀ i : ι, ContinuousOn f (s i)) (hs : ∀ i, IsOpen (s i)) (hs' : ⋃ i, s i = univ) : Continuous f := by rw [← continuousOn_univ, ← hs'] exact ContinuousOn.iUnion_of_isOpen hf hs /-- If `f` is continuous on some neighbourhood `s'` of `s` and `f` maps `s` to `t`, the preimage of a set neighbourhood of `t` is a set neighbourhood of `s`. -/ -- See `Continuous.tendsto_nhdsSet` for a special case. theorem ContinuousOn.tendsto_nhdsSet {f : α → β} {s s' : Set α} {t : Set β} (hf : ContinuousOn f s') (hs' : s' ∈ 𝓝ˢ s) (hst : MapsTo f s t) : Tendsto f (𝓝ˢ s) (𝓝ˢ t) := by obtain ⟨V, hV, hsV, hVs'⟩ := mem_nhdsSet_iff_exists.mp hs' refine ((hasBasis_nhdsSet s).tendsto_iff (hasBasis_nhdsSet t)).mpr fun U hU ↦ ⟨V ∩ f ⁻¹' U, ?_, fun _ ↦ ?_⟩ · exact ⟨(hf.mono hVs').isOpen_inter_preimage hV hU.1, subset_inter hsV (hst.mono Subset.rfl hU.2)⟩ · intro h rw [← mem_preimage] exact mem_of_mem_inter_right h /-- Preimage of a set neighborhood of `t` under a continuous map `f` is a set neighborhood of `s` provided that `f` maps `s` to `t`. -/ theorem Continuous.tendsto_nhdsSet {f : α → β} {t : Set β} (hf : Continuous f) (hst : MapsTo f s t) : Tendsto f (𝓝ˢ s) (𝓝ˢ t) := hf.continuousOn.tendsto_nhdsSet univ_mem hst lemma Continuous.tendsto_nhdsSet_nhds {b : β} {f : α → β} (h : Continuous f) (h' : EqOn f (fun _ ↦ b) s) : Tendsto f (𝓝ˢ s) (𝓝 b) := by rw [← nhdsSet_singleton] exact h.tendsto_nhdsSet h'
.lake/packages/mathlib/Mathlib/Topology/ShrinkingLemma.lean
import Mathlib.Topology.Separation.Regular /-! # The shrinking lemma In this file we prove a few versions of the shrinking lemma. The lemma says that in a normal topological space a point finite open covering can be “shrunk”: for a point finite open covering `u : ι → Set X` there exists a refinement `v : ι → Set X` such that `closure (v i) ⊆ u i`. For finite or countable coverings this lemma can be proved without the axiom of choice, see [ncatlab](https://ncatlab.org/nlab/show/shrinking+lemma) for details. We only formalize the most general result that works for any covering but needs the axiom of choice. We prove two versions of the lemma: * `exists_subset_iUnion_closure_subset` deals with a covering of a closed set in a normal space; * `exists_iUnion_eq_closure_subset` deals with a covering of the whole space. ## Tags normal space, shrinking lemma -/ open Set Function noncomputable section variable {ι X : Type*} [TopologicalSpace X] namespace ShrinkingLemma -- the trivial refinement needs `u` to be a covering /-- Auxiliary definition for the proof of the shrinking lemma. A partial refinement of a covering `⋃ i, u i` of a set `s` is a map `v : ι → Set X` and a set `carrier : Set ι` such that * `s ⊆ ⋃ i, v i`; * all `v i` are open; * if `i ∈ carrier v`, then `closure (v i) ⊆ u i`; * if `i ∉ carrier`, then `v i = u i`. This type is equipped with the following partial order: `v ≤ v'` if `v.carrier ⊆ v'.carrier` and `v i = v' i` for `i ∈ v.carrier`. We will use Zorn's lemma to prove that this type has a maximal element, then show that the maximal element must have `carrier = univ`. -/ @[ext] structure PartialRefinement (u : ι → Set X) (s : Set X) (p : Set X → Prop) where /-- A family of sets that form a partial refinement of `u`. -/ toFun : ι → Set X /-- The set of indexes `i` such that `i`-th set is already shrunk. -/ carrier : Set ι /-- Each set from the partially refined family is open. -/ protected isOpen : ∀ i, IsOpen (toFun i) /-- The partially refined family still covers the set. -/ subset_iUnion : s ⊆ ⋃ i, toFun i /-- For each `i ∈ carrier`, the original set includes the closure of the refined set. -/ closure_subset : ∀ {i}, i ∈ carrier → closure (toFun i) ⊆ u i /-- For each `i ∈ carrier`, the refined set satisfies `p`. -/ pred_of_mem {i} (hi : i ∈ carrier) : p (toFun i) /-- Sets that correspond to `i ∉ carrier` are not modified. -/ apply_eq : ∀ {i}, i ∉ carrier → toFun i = u i namespace PartialRefinement variable {u : ι → Set X} {s : Set X} {p : Set X → Prop} instance : CoeFun (PartialRefinement u s p) fun _ => ι → Set X := ⟨toFun⟩ protected theorem subset (v : PartialRefinement u s p) (i : ι) : v i ⊆ u i := by classical exact if h : i ∈ v.carrier then subset_closure.trans (v.closure_subset h) else (v.apply_eq h).le open Classical in instance : PartialOrder (PartialRefinement u s p) where le v₁ v₂ := v₁.carrier ⊆ v₂.carrier ∧ ∀ i ∈ v₁.carrier, v₁ i = v₂ i le_refl _ := ⟨Subset.refl _, fun _ _ => rfl⟩ le_trans _ _ _ h₁₂ h₂₃ := ⟨Subset.trans h₁₂.1 h₂₃.1, fun i hi => (h₁₂.2 i hi).trans (h₂₃.2 i <| h₁₂.1 hi)⟩ le_antisymm v₁ v₂ h₁₂ h₂₁ := have hc : v₁.carrier = v₂.carrier := Subset.antisymm h₁₂.1 h₂₁.1 PartialRefinement.ext (funext fun x => if hx : x ∈ v₁.carrier then h₁₂.2 _ hx else (v₁.apply_eq hx).trans (Eq.symm <| v₂.apply_eq <| hc ▸ hx)) hc /-- If two partial refinements `v₁`, `v₂` belong to a chain (hence, they are comparable) and `i` belongs to the carriers of both partial refinements, then `v₁ i = v₂ i`. -/ theorem apply_eq_of_chain {c : Set (PartialRefinement u s p)} (hc : IsChain (· ≤ ·) c) {v₁ v₂} (h₁ : v₁ ∈ c) (h₂ : v₂ ∈ c) {i} (hi₁ : i ∈ v₁.carrier) (hi₂ : i ∈ v₂.carrier) : v₁ i = v₂ i := (hc.total h₁ h₂).elim (fun hle => hle.2 _ hi₁) (fun hle => (hle.2 _ hi₂).symm) /-- The carrier of the least upper bound of a non-empty chain of partial refinements is the union of their carriers. -/ def chainSupCarrier (c : Set (PartialRefinement u s p)) : Set ι := ⋃ v ∈ c, carrier v open Classical in /-- Choice of an element of a nonempty chain of partial refinements. If `i` belongs to one of `carrier v`, `v ∈ c`, then `find c ne i` is one of these partial refinements. -/ def find (c : Set (PartialRefinement u s p)) (ne : c.Nonempty) (i : ι) : PartialRefinement u s p := if hi : ∃ v ∈ c, i ∈ carrier v then hi.choose else ne.some theorem find_mem {c : Set (PartialRefinement u s p)} (i : ι) (ne : c.Nonempty) : find c ne i ∈ c := by rw [find] split_ifs with h exacts [h.choose_spec.1, ne.some_mem] theorem mem_find_carrier_iff {c : Set (PartialRefinement u s p)} {i : ι} (ne : c.Nonempty) : i ∈ (find c ne i).carrier ↔ i ∈ chainSupCarrier c := by rw [find] split_ifs with h · have := h.choose_spec exact iff_of_true this.2 (mem_iUnion₂.2 ⟨_, this.1, this.2⟩) · push_neg at h refine iff_of_false (h _ ne.some_mem) ?_ simpa only [chainSupCarrier, mem_iUnion₂, not_exists] theorem find_apply_of_mem {c : Set (PartialRefinement u s p)} (hc : IsChain (· ≤ ·) c) (ne : c.Nonempty) {i v} (hv : v ∈ c) (hi : i ∈ carrier v) : find c ne i i = v i := apply_eq_of_chain hc (find_mem _ _) hv ((mem_find_carrier_iff _).2 <| mem_iUnion₂.2 ⟨v, hv, hi⟩) hi /-- Least upper bound of a nonempty chain of partial refinements. -/ def chainSup (c : Set (PartialRefinement u s p)) (hc : IsChain (· ≤ ·) c) (ne : c.Nonempty) (hfin : ∀ x ∈ s, { i | x ∈ u i }.Finite) (hU : s ⊆ ⋃ i, u i) : PartialRefinement u s p where toFun i := find c ne i i carrier := chainSupCarrier c isOpen i := (find _ _ _).isOpen i subset_iUnion x hxs := mem_iUnion.2 <| by rcases em (∃ i, i ∉ chainSupCarrier c ∧ x ∈ u i) with (⟨i, hi, hxi⟩ | hx) · use i simpa only [(find c ne i).apply_eq (mt (mem_find_carrier_iff _).1 hi)] · simp_rw [not_exists, not_and, not_imp_not, chainSupCarrier, mem_iUnion₂] at hx haveI : Nonempty (PartialRefinement u s p) := ⟨ne.some⟩ choose! v hvc hiv using hx rcases (hfin x hxs).exists_maximalFor v _ (mem_iUnion.1 (hU hxs)) with ⟨i, hxi : x ∈ u i, hmax : ∀ j, x ∈ u j → v i ≤ v j → v j ≤ v i⟩ rcases mem_iUnion.1 ((v i).subset_iUnion hxs) with ⟨j, hj⟩ use j have hj' : x ∈ u j := (v i).subset _ hj have : v j ≤ v i := (hc.total (hvc _ hxi) (hvc _ hj')).elim (hmax j hj') id simpa only [find_apply_of_mem hc ne (hvc _ hxi) (this.1 <| hiv _ hj')] closure_subset hi := (find c ne _).closure_subset ((mem_find_carrier_iff _).2 hi) pred_of_mem {i} hi := by obtain ⟨v, hv⟩ := Set.mem_iUnion.mp hi simp only [mem_iUnion, exists_prop] at hv rw [find_apply_of_mem hc ne hv.1 hv.2] exact v.pred_of_mem hv.2 apply_eq hi := (find c ne _).apply_eq (mt (mem_find_carrier_iff _).1 hi) /-- `chainSup hu c hc ne hfin hU` is an upper bound of the chain `c`. -/ theorem le_chainSup {c : Set (PartialRefinement u s p)} (hc : IsChain (· ≤ ·) c) (ne : c.Nonempty) (hfin : ∀ x ∈ s, { i | x ∈ u i }.Finite) (hU : s ⊆ ⋃ i, u i) {v} (hv : v ∈ c) : v ≤ chainSup c hc ne hfin hU := ⟨fun _ hi => mem_biUnion hv hi, fun _ hi => (find_apply_of_mem hc _ hv hi).symm⟩ /-- If `s` is a closed set, `v` is a partial refinement, and `i` is an index such that `i ∉ v.carrier`, then there exists a partial refinement that is strictly greater than `v`. -/ theorem exists_gt [NormalSpace X] (v : PartialRefinement u s ⊤) (hs : IsClosed s) (i : ι) (hi : i ∉ v.carrier) : ∃ v' : PartialRefinement u s ⊤, v < v' := by have I : (s ∩ ⋂ (j) (_ : j ≠ i), (v j)ᶜ) ⊆ v i := by simp only [subset_def, mem_inter_iff, mem_iInter, and_imp] intro x hxs H rcases mem_iUnion.1 (v.subset_iUnion hxs) with ⟨j, hj⟩ exact (em (j = i)).elim (fun h => h ▸ hj) fun h => (H j h hj).elim have C : IsClosed (s ∩ ⋂ (j) (_ : j ≠ i), (v j)ᶜ) := IsClosed.inter hs (isClosed_biInter fun _ _ => isClosed_compl_iff.2 <| v.isOpen _) rcases normal_exists_closure_subset C (v.isOpen i) I with ⟨vi, ovi, hvi, cvi⟩ classical refine ⟨⟨update v i vi, insert i v.carrier, ?_, ?_, ?_, ?_, ?_⟩, ?_, ?_⟩ · intro j rcases eq_or_ne j i with (rfl | hne) <;> simp [*, v.isOpen] · refine fun x hx => mem_iUnion.2 ?_ by_cases! h : ∃ j ≠ i, x ∈ v j · rcases h with ⟨j, hji, hj⟩ use j rwa [update_of_ne hji] · use i rw [update_self] exact hvi ⟨hx, mem_biInter h⟩ · rintro j (rfl | hj) · rwa [update_self, ← v.apply_eq hi] · rw [update_of_ne (ne_of_mem_of_not_mem hj hi)] exact v.closure_subset hj · exact fun _ => trivial · intro j hj rw [mem_insert_iff, not_or] at hj rw [update_of_ne hj.1, v.apply_eq hj.2] · refine ⟨subset_insert _ _, fun j hj => ?_⟩ exact (update_of_ne (ne_of_mem_of_not_mem hj hi) _ _).symm · exact fun hle => hi (hle.1 <| mem_insert _ _) end PartialRefinement end ShrinkingLemma section NormalSpace open ShrinkingLemma variable {u : ι → Set X} {s : Set X} [NormalSpace X] /-- **Shrinking lemma**. A point-finite open cover of a closed subset of a normal space can be "shrunk" to a new open cover so that the closure of each new open set is contained in the corresponding original open set. -/ theorem exists_subset_iUnion_closure_subset (hs : IsClosed s) (uo : ∀ i, IsOpen (u i)) (uf : ∀ x ∈ s, { i | x ∈ u i }.Finite) (us : s ⊆ ⋃ i, u i) : ∃ v : ι → Set X, s ⊆ iUnion v ∧ (∀ i, IsOpen (v i)) ∧ ∀ i, closure (v i) ⊆ u i := by haveI : Nonempty (PartialRefinement u s ⊤) := ⟨⟨u, ∅, uo, us, False.elim, False.elim, fun _ => rfl⟩⟩ have : ∀ c : Set (PartialRefinement u s ⊤), IsChain (· ≤ ·) c → c.Nonempty → ∃ ub, ∀ v ∈ c, v ≤ ub := fun c hc ne => ⟨.chainSup c hc ne uf us, fun v hv => PartialRefinement.le_chainSup _ _ _ _ hv⟩ rcases zorn_le_nonempty this with ⟨v, hv⟩ suffices ∀ i, i ∈ v.carrier from ⟨v, v.subset_iUnion, fun i => v.isOpen _, fun i => v.closure_subset (this i)⟩ refine fun i ↦ by_contra fun hi ↦ ?_ rcases v.exists_gt hs i hi with ⟨v', hlt⟩ exact hv.not_lt hlt /-- **Shrinking lemma**. A point-finite open cover of a closed subset of a normal space can be "shrunk" to a new closed cover so that each new closed set is contained in the corresponding original open set. See also `exists_subset_iUnion_closure_subset` for a stronger statement. -/ theorem exists_subset_iUnion_closed_subset (hs : IsClosed s) (uo : ∀ i, IsOpen (u i)) (uf : ∀ x ∈ s, { i | x ∈ u i }.Finite) (us : s ⊆ ⋃ i, u i) : ∃ v : ι → Set X, s ⊆ iUnion v ∧ (∀ i, IsClosed (v i)) ∧ ∀ i, v i ⊆ u i := let ⟨v, hsv, _, hv⟩ := exists_subset_iUnion_closure_subset hs uo uf us ⟨fun i => closure (v i), Subset.trans hsv (iUnion_mono fun _ => subset_closure), fun _ => isClosed_closure, hv⟩ /-- Shrinking lemma. A point-finite open cover of a closed subset of a normal space can be "shrunk" to a new open cover so that the closure of each new open set is contained in the corresponding original open set. -/ theorem exists_iUnion_eq_closure_subset (uo : ∀ i, IsOpen (u i)) (uf : ∀ x, { i | x ∈ u i }.Finite) (uU : ⋃ i, u i = univ) : ∃ v : ι → Set X, iUnion v = univ ∧ (∀ i, IsOpen (v i)) ∧ ∀ i, closure (v i) ⊆ u i := let ⟨v, vU, hv⟩ := exists_subset_iUnion_closure_subset isClosed_univ uo (fun x _ => uf x) uU.ge ⟨v, univ_subset_iff.1 vU, hv⟩ /-- Shrinking lemma. A point-finite open cover of a closed subset of a normal space can be "shrunk" to a new closed cover so that each of the new closed sets is contained in the corresponding original open set. See also `exists_iUnion_eq_closure_subset` for a stronger statement. -/ theorem exists_iUnion_eq_closed_subset (uo : ∀ i, IsOpen (u i)) (uf : ∀ x, { i | x ∈ u i }.Finite) (uU : ⋃ i, u i = univ) : ∃ v : ι → Set X, iUnion v = univ ∧ (∀ i, IsClosed (v i)) ∧ ∀ i, v i ⊆ u i := let ⟨v, vU, hv⟩ := exists_subset_iUnion_closed_subset isClosed_univ uo (fun x _ => uf x) uU.ge ⟨v, univ_subset_iff.1 vU, hv⟩ end NormalSpace section T2LocallyCompactSpace open ShrinkingLemma variable {u : ι → Set X} {s : Set X} [T2Space X] [LocallyCompactSpace X] /-- In a locally compact Hausdorff space `X`, if `s` is a compact set, `v` is a partial refinement, and `i` is an index such that `i ∉ v.carrier`, then there exists a partial refinement that is strictly greater than `v`. -/ theorem exists_gt_t2space (v : PartialRefinement u s (fun w => IsCompact (closure w))) (hs : IsCompact s) (i : ι) (hi : i ∉ v.carrier) : ∃ v' : PartialRefinement u s (fun w => IsCompact (closure w)), v < v' ∧ IsCompact (closure (v' i)) := by -- take `v i` such that `closure (v i)` is compact set si := s ∩ (⋃ j ≠ i, v j)ᶜ with hsi simp only [ne_eq, compl_iUnion] at hsi have hsic : IsCompact si := by apply IsCompact.of_isClosed_subset hs _ Set.inter_subset_left · have : IsOpen (⋃ j ≠ i, v j) := by apply isOpen_biUnion intro j _ exact v.isOpen j exact IsClosed.inter (IsCompact.isClosed hs) (IsOpen.isClosed_compl this) have : si ⊆ v i := by intro x hx have (j) (hj : j ≠ i) : x ∉ v j := by rw [hsi] at hx apply Set.notMem_of_mem_compl have hsi' : x ∈ (⋂ i_1, ⋂ (_ : ¬i_1 = i), (v.toFun i_1)ᶜ) := Set.mem_of_mem_inter_right hx rw [ne_eq] at hj rw [Set.mem_iInter₂] at hsi' exact hsi' j hj obtain ⟨j, hj⟩ := Set.mem_iUnion.mp (v.subset_iUnion (Set.mem_of_mem_inter_left hx)) obtain rfl : j = i := by by_contra! h exact this j h hj exact hj obtain ⟨vi, hvi⟩ := exists_open_between_and_isCompact_closure hsic (v.isOpen i) this classical refine ⟨⟨update v i vi, insert i v.carrier, ?_, ?_, ?_, ?_, ?_⟩, ⟨?_, ?_⟩, ?_⟩ · intro j rcases eq_or_ne j i with (rfl | hne) <;> simp [*, v.isOpen] · refine fun x hx => mem_iUnion.2 ?_ by_cases! h : ∃ j ≠ i, x ∈ v j · rcases h with ⟨j, hji, hj⟩ use j rwa [update_of_ne hji] · use i rw [update_self] apply hvi.2.1 rw [hsi] exact ⟨hx, mem_iInter₂_of_mem h⟩ · rintro j (rfl | hj) · rw [update_self] exact subset_trans hvi.2.2.1 <| PartialRefinement.subset v j · rw [update_of_ne (ne_of_mem_of_not_mem hj hi)] exact v.closure_subset hj · intro j hj rw [mem_insert_iff] at hj by_cases h : j = i · rw [← h] simp only [update_self] exact hvi.2.2.2 · apply hj.elim · intro hji exact False.elim (h hji) · intro hjmemv rw [update_of_ne h] exact v.pred_of_mem hjmemv · intro j hj rw [mem_insert_iff, not_or] at hj rw [update_of_ne hj.1, v.apply_eq hj.2] · refine ⟨subset_insert _ _, fun j hj => ?_⟩ exact (update_of_ne (ne_of_mem_of_not_mem hj hi) _ _).symm · exact fun hle => hi (hle.1 <| mem_insert _ _) · simp only [update_self] exact hvi.2.2.2 /-- **Shrinking lemma** . A point-finite open cover of a compact subset of a `T2Space` `LocallyCompactSpace` can be "shrunk" to a new open cover so that the closure of each new open set is contained in the corresponding original open set. -/ theorem exists_subset_iUnion_closure_subset_t2space (hs : IsCompact s) (uo : ∀ i, IsOpen (u i)) (uf : ∀ x ∈ s, { i | x ∈ u i }.Finite) (us : s ⊆ ⋃ i, u i) : ∃ v : ι → Set X, s ⊆ iUnion v ∧ (∀ i, IsOpen (v i)) ∧ (∀ i, closure (v i) ⊆ u i) ∧ (∀ i, IsCompact (closure (v i))) := by haveI : Nonempty (PartialRefinement u s (fun w => IsCompact (closure w))) := ⟨⟨u, ∅, uo, us, False.elim, False.elim, fun _ => rfl⟩⟩ have : ∀ c : Set (PartialRefinement u s (fun w => IsCompact (closure w))), IsChain (· ≤ ·) c → c.Nonempty → ∃ ub, ∀ v ∈ c, v ≤ ub := fun c hc ne => ⟨.chainSup c hc ne uf us, fun v hv => PartialRefinement.le_chainSup _ _ _ _ hv⟩ rcases zorn_le_nonempty this with ⟨v, hv⟩ suffices ∀ i, i ∈ v.carrier from ⟨v, v.subset_iUnion, fun i => v.isOpen _, fun i => v.closure_subset (this i), ?_⟩ · intro i exact v.pred_of_mem (this i) · intro i by_contra! hi rcases exists_gt_t2space v hs i hi with ⟨v', hlt, _⟩ exact hv.not_lt hlt /-- **Shrinking lemma**. A point-finite open cover of a compact subset of a locally compact T2 space can be "shrunk" to a new closed cover so that each new closed set is contained in the corresponding original open set. See also `exists_subset_iUnion_closure_subset_t2space` for a stronger statement. -/ theorem exists_subset_iUnion_compact_subset_t2space (hs : IsCompact s) (uo : ∀ i, IsOpen (u i)) (uf : ∀ x ∈ s, { i | x ∈ u i }.Finite) (us : s ⊆ ⋃ i, u i) : ∃ v : ι → Set X, s ⊆ iUnion v ∧ (∀ i, IsClosed (v i)) ∧ (∀ i, v i ⊆ u i) ∧ ∀ i, IsCompact (v i) := by let ⟨v, hsv, _, hv⟩ := exists_subset_iUnion_closure_subset_t2space hs uo uf us use fun i => closure (v i) refine ⟨?_, ?_, hv⟩ · exact Subset.trans hsv (iUnion_mono fun _ => subset_closure) · simp only [isClosed_closure, implies_true] end T2LocallyCompactSpace
.lake/packages/mathlib/Mathlib/Topology/NhdsWithin.lean
import Mathlib.Topology.Constructions /-! # Neighborhoods relative to a subset This file develops API on the relative version `nhdsWithin` of `nhds`, which is defined in previous definition files. Their basic properties studied in this file include the relationship between neighborhood filters relative to a set and neighborhood filters in the corresponding subtype, and are in later files used to develop relativ versions `ContinuousOn` and `ContinuousWithinAt` of `Continuous` and `ContinuousAt`. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology variable {α β γ δ : Type*} [TopologicalSpace α] /-! ## Properties of the neighborhood-within filter -/ @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] @[simp] theorem eventually_eventually_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs @[simp] theorem eventually_mem_nhdsWithin_iff {x : α} {s t : Set α} : (∀ᶠ x' in 𝓝[s] x, t ∈ 𝓝[s] x') ↔ t ∈ 𝓝[s] x := eventually_eventually_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf @[simp] lemma nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] theorem nhdsWithin_hasBasis {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] lemma mem_nhdsWithin_inter_self {s t : Set α} {x : α} : t ∈ 𝓝[s ∩ t] x := mem_nhdsWithin_iff_eventuallyEq.mpr <| by simp [inter_assoc] lemma mem_nhdsWithin_self_inter {s t : Set α} {x : α} : s ∈ 𝓝[s ∩ t] x := mem_nhdsWithin_iff_eventuallyEq.mpr <| by simp [inter_comm s t, inter_assoc] theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal theorem preimage_nhdsWithin_coinduced' {X : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => X x) inferInstance) (X a)) : X ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => X x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha theorem preimage_nhds_within_coinduced {X : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => X x) inferInstance) (X a)) : X ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] theorem nhds_eq_nhdsWithin_sup_nhdsWithin (b : α) {I₁ I₂ : Set α} (hI : Set.univ = I₁ ∪ I₂) : nhds b = nhdsWithin b I₁ ⊔ nhdsWithin b I₂ := by rw [← nhdsWithin_univ b, hI, nhdsWithin_union] /-- If `L` and `R` are neighborhoods of `b` within sets whose union is `Set.univ`, then `L ∪ R` is a neighborhood of `b`. -/ theorem union_mem_nhds_of_mem_nhdsWithin {b : α} {I₁ I₂ : Set α} (h : Set.univ = I₁ ∪ I₂) {L : Set α} (hL : L ∈ nhdsWithin b I₁) {R : Set α} (hR : R ∈ nhdsWithin b I₂) : L ∪ R ∈ nhds b := by rw [← nhdsWithin_univ b, h, nhdsWithin_union] exact ⟨mem_of_superset hL (by simp), mem_of_superset hR (by simp)⟩ /-- Writing a punctured neighborhood filter as a sup of left and right filters. -/ lemma punctured_nhds_eq_nhdsWithin_sup_nhdsWithin [LinearOrder α] {x : α} : 𝓝[≠] x = 𝓝[<] x ⊔ 𝓝[>] x := by rw [← Iio_union_Ioi, nhdsWithin_union] /-- Obtain a "predictably-sided" neighborhood of `b` from two one-sided neighborhoods. -/ theorem nhds_of_Ici_Iic [LinearOrder α] {b : α} {L : Set α} (hL : L ∈ 𝓝[≤] b) {R : Set α} (hR : R ∈ 𝓝[≥] b) : L ∩ Iic b ∪ R ∩ Ici b ∈ 𝓝 b := union_mem_nhds_of_mem_nhdsWithin Iic_union_Ici.symm (inter_mem hL self_mem_nhdsWithin) (inter_mem hR self_mem_nhdsWithin) theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := by induction I, hI using Set.Finite.induction_on with | empty => simp | insert _ _ hT => simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] @[simp] theorem nhdsNE_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] @[simp] theorem pure_sup_nhdsNE (a : α) : pure a ⊔ 𝓝[≠] a = 𝓝 a := by rw [← sup_comm, nhdsNE_sup_pure] lemma continuousAt_iff_punctured_nhds [TopologicalSpace β] {f : α → β} {a : α} : ContinuousAt f a ↔ Tendsto f (𝓝[≠] a) (𝓝 (f a)) := by simp [ContinuousAt, - pure_sup_nhdsNE, ← pure_sup_nhdsNE a, tendsto_pure_nhds] theorem nhdsWithin_prod [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv lemma Filter.EventuallyEq.mem_interior {x : α} {s t : Set α} (hst : s =ᶠ[𝓝 x] t) (h : x ∈ interior s) : x ∈ interior t := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst simpa [mem_interior_iff_mem_nhds, ← nhdsWithin_eq_nhds, hst] using h lemma Filter.EventuallyEq.mem_interior_iff {x : α} {s t : Set α} (hst : s =ᶠ[𝓝 x] t) : x ∈ interior s ↔ x ∈ interior t := ⟨fun h ↦ hst.mem_interior h, fun h ↦ hst.symm.mem_interior h⟩ section Pi variable {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] theorem nhdsWithin_pi_eq' {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (X i)) (x : ∀ i, X i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] theorem nhdsWithin_pi_eq {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (X i)) (x : ∀ i, X i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] theorem nhdsWithin_pi_univ_eq [Finite ι] (s : ∀ i, Set (X i)) (x : ∀ i, X i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x theorem nhdsWithin_pi_eq_bot {I : Set ι} {s : ∀ i, Set (X i)} {x : ∀ i, X i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] theorem nhdsWithin_pi_neBot {I : Set ι} {s : ∀ i, Set (X i)} {x : ∀ i, X i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] instance instNeBotNhdsWithinUnivPi {s : ∀ i, Set (X i)} {x : ∀ i, X i} [∀ i, (𝓝[s i] x i).NeBot] : (𝓝[pi univ s] x).NeBot := by simpa [nhdsWithin_pi_neBot] instance Pi.instNeBotNhdsWithinIio [Nonempty ι] [∀ i, Preorder (X i)] {x : ∀ i, X i} [∀ i, (𝓝[<] x i).NeBot] : (𝓝[<] x).NeBot := have : (𝓝[pi univ fun i ↦ Iio (x i)] x).NeBot := inferInstance this.mono <| nhdsWithin_mono _ fun _y hy ↦ lt_of_strongLT fun i ↦ hy i trivial instance Pi.instNeBotNhdsWithinIoi [Nonempty ι] [∀ i, Preorder (X i)] {x : ∀ i, X i} [∀ i, (𝓝[>] x i).NeBot] : (𝓝[>] x).NeBot := Pi.instNeBotNhdsWithinIio (X := fun i ↦ (X i)ᵒᵈ) (x := fun i ↦ OrderDual.toDual (x i)) end Pi theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] theorem DenseRange.piMap {ι : Type*} {X Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : (i : ι) → (X i) → (Y i)} (hf : ∀ i, DenseRange (f i)) : DenseRange (Pi.map f) := by rw [DenseRange, Set.range_piMap] exact dense_pi Set.univ (fun i _ => hf i) theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal /-- Two functions agree on a neighborhood of `x` if they agree at `x` and in a punctured neighborhood. -/ theorem eventuallyEq_nhds_of_eventuallyEq_nhdsNE {f g : α → β} {a : α} (h₁ : f =ᶠ[𝓝[≠] a] g) (h₂ : f a = g a) : f =ᶠ[𝓝 a] g := by filter_upwards [eventually_nhdsWithin_iff.1 h₁] intro x hx by_cases h₂x : x = a · simp [h₂x, h₂] · tauto theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_of_right h theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := eventuallyEq_nhdsWithin_of_eqOn h theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l := (tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_of_right h theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α} (f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} : Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s := ⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h => tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩ @[simp] theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} : Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => h.mono_right inf_le_left, fun h => tendsto_inf.2 ⟨h, tendsto_principal.2 <| Eventually.of_forall mem_range_self⟩⟩ theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhdsWithin hmem theorem eventually_nhdsWithin_of_eventually_nhds {s : Set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhdsWithin_of_mem_nhds h lemma Set.MapsTo.preimage_mem_nhdsWithin {f : α → β} {s : Set α} {t : Set β} {x : α} (hst : MapsTo f s t) : f ⁻¹' t ∈ 𝓝[s] x := Filter.mem_of_superset self_mem_nhdsWithin hst /-! ### `nhdsWithin` and subtypes -/ theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} : t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin] theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) : 𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) := Filter.ext fun _ => mem_nhdsWithin_subtype theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) := (map_nhds_subtype_val ⟨a, h⟩).symm theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} : t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective] theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by rw [← map_nhds_subtype_val, mem_map] theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x := preimage_coe_mem_nhds_subtype theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x := eventually_nhds_subtype_iff s a (¬ P ·) |>.not theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) : Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl
.lake/packages/mathlib/Mathlib/Topology/Continuous.lean
import Mathlib.Topology.ClusterPt /-! # Continuity in topological spaces For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Tags continuity, continuous function -/ open Set Filter Topology variable {X Y Z : Type*} open TopologicalSpace -- The curly braces are intentional, so this definition works well with simp -- when topologies are not those provided by instances. theorem continuous_def {_ : TopologicalSpace X} {_ : TopologicalSpace Y} {f : X → Y} : Continuous f ↔ ∀ s, IsOpen s → IsOpen (f ⁻¹' s) := ⟨fun hf => hf.1, fun h => ⟨h⟩⟩ variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] variable {f : X → Y} {s : Set X} {x : X} {y : Y} theorem IsOpen.preimage (hf : Continuous f) {t : Set Y} (h : IsOpen t) : IsOpen (f ⁻¹' t) := hf.isOpen_preimage t h lemma Equiv.continuous_symm_iff (e : X ≃ Y) : Continuous e.symm ↔ IsOpenMap e := by simp_rw [continuous_def, ← Equiv.image_eq_preimage_symm, IsOpenMap] lemma Equiv.isOpenMap_symm_iff (e : X ≃ Y) : IsOpenMap e.symm ↔ Continuous e := by simp_rw [← Equiv.continuous_symm_iff, Equiv.symm_symm] theorem continuous_congr {g : X → Y} (h : ∀ x, f x = g x) : Continuous f ↔ Continuous g := .of_eq <| congrArg _ <| funext h theorem Continuous.congr {g : X → Y} (h : Continuous f) (h' : ∀ x, f x = g x) : Continuous g := continuous_congr h' |>.mp h theorem ContinuousAt.tendsto (h : ContinuousAt f x) : Tendsto f (𝓝 x) (𝓝 (f x)) := h theorem continuousAt_def : ContinuousAt f x ↔ ∀ A ∈ 𝓝 (f x), f ⁻¹' A ∈ 𝓝 x := Iff.rfl theorem continuousAt_congr {g : X → Y} (h : f =ᶠ[𝓝 x] g) : ContinuousAt f x ↔ ContinuousAt g x := by simp only [ContinuousAt, tendsto_congr' h, h.eq_of_nhds] theorem ContinuousAt.congr {g : X → Y} (hf : ContinuousAt f x) (h : f =ᶠ[𝓝 x] g) : ContinuousAt g x := (continuousAt_congr h).1 hf theorem ContinuousAt.preimage_mem_nhds {t : Set Y} (h : ContinuousAt f x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝 x := h ht /-- If `f x ∈ s ∈ 𝓝 (f x)` for continuous `f`, then `f y ∈ s` near `x`. This is essentially `Filter.Tendsto.eventually_mem`, but infers in more cases when applied. -/ theorem ContinuousAt.eventually_mem {f : X → Y} {x : X} (hf : ContinuousAt f x) {s : Set Y} (hs : s ∈ 𝓝 (f x)) : ∀ᶠ y in 𝓝 x, f y ∈ s := hf hs /-- If a function `f` tends to somewhere other than `𝓝 (f x)` at `x`, then `f` is not continuous at `x` -/ lemma not_continuousAt_of_tendsto {f : X → Y} {l₁ : Filter X} {l₂ : Filter Y} {x : X} (hf : Tendsto f l₁ l₂) [l₁.NeBot] (hl₁ : l₁ ≤ 𝓝 x) (hl₂ : Disjoint (𝓝 (f x)) l₂) : ¬ ContinuousAt f x := fun cont ↦ (cont.mono_left hl₁).not_tendsto hl₂ hf theorem ClusterPt.map {lx : Filter X} {ly : Filter Y} (H : ClusterPt x lx) (hfc : ContinuousAt f x) (hf : Tendsto f lx ly) : ClusterPt (f x) ly := (NeBot.map H f).mono <| hfc.tendsto.inf hf /-- See also `interior_preimage_subset_preimage_interior`. -/ theorem preimage_interior_subset_interior_preimage {t : Set Y} (hf : Continuous f) : f ⁻¹' interior t ⊆ interior (f ⁻¹' t) := interior_maximal (preimage_mono interior_subset) (isOpen_interior.preimage hf) @[continuity] theorem continuous_id : Continuous (id : X → X) := continuous_def.2 fun _ => id -- This is needed due to reducibility issues with the `continuity` tactic. @[continuity, fun_prop] theorem continuous_id' : Continuous (fun (x : X) => x) := continuous_id theorem Continuous.comp {g : Y → Z} (hg : Continuous g) (hf : Continuous f) : Continuous (g ∘ f) := continuous_def.2 fun _ h => (h.preimage hg).preimage hf -- This is needed due to reducibility issues with the `continuity` tactic. @[continuity, fun_prop] theorem Continuous.comp' {g : Y → Z} (hg : Continuous g) (hf : Continuous f) : Continuous (fun x => g (f x)) := hg.comp hf @[fun_prop] theorem Continuous.iterate {f : X → X} (h : Continuous f) (n : ℕ) : Continuous f^[n] := Nat.recOn n continuous_id fun _ ihn => ihn.comp h nonrec theorem ContinuousAt.comp {g : Y → Z} (hg : ContinuousAt g (f x)) (hf : ContinuousAt f x) : ContinuousAt (g ∘ f) x := hg.comp hf @[fun_prop] theorem ContinuousAt.comp' {g : Y → Z} {x : X} (hg : ContinuousAt g (f x)) (hf : ContinuousAt f x) : ContinuousAt (fun x => g (f x)) x := ContinuousAt.comp hg hf /-- See note [comp_of_eq lemmas] -/ theorem ContinuousAt.comp_of_eq {g : Y → Z} (hg : ContinuousAt g y) (hf : ContinuousAt f x) (hy : f x = y) : ContinuousAt (g ∘ f) x := by subst hy; exact hg.comp hf theorem Continuous.tendsto (hf : Continuous f) (x) : Tendsto f (𝓝 x) (𝓝 (f x)) := ((nhds_basis_opens x).tendsto_iff <| nhds_basis_opens <| f x).2 fun t ⟨hxt, ht⟩ => ⟨f ⁻¹' t, ⟨hxt, ht.preimage hf⟩, Subset.rfl⟩ /-- A version of `Continuous.tendsto` that allows one to specify a simpler form of the limit. E.g., one can write `continuous_exp.tendsto' 0 1 exp_zero`. -/ theorem Continuous.tendsto' (hf : Continuous f) (x : X) (y : Y) (h : f x = y) : Tendsto f (𝓝 x) (𝓝 y) := h ▸ hf.tendsto x @[fun_prop] theorem Continuous.continuousAt (h : Continuous f) : ContinuousAt f x := h.tendsto x theorem continuous_iff_continuousAt : Continuous f ↔ ∀ x, ContinuousAt f x := ⟨Continuous.tendsto, fun hf => continuous_def.2 fun _U hU => isOpen_iff_mem_nhds.2 fun x hx => hf x <| hU.mem_nhds hx⟩ @[fun_prop] theorem continuousAt_const : ContinuousAt (fun _ : X => y) x := tendsto_const_nhds @[continuity, fun_prop] theorem continuous_const : Continuous fun _ : X => y := continuous_iff_continuousAt.mpr fun _ => continuousAt_const theorem Filter.EventuallyEq.continuousAt (h : f =ᶠ[𝓝 x] fun _ => y) : ContinuousAt f x := (continuousAt_congr h).2 tendsto_const_nhds theorem continuous_of_const (h : ∀ x y, f x = f y) : Continuous f := continuous_iff_continuousAt.mpr fun x => Filter.EventuallyEq.continuousAt <| Eventually.of_forall fun y => h y x theorem continuousAt_id : ContinuousAt id x := continuous_id.continuousAt @[fun_prop] theorem continuousAt_id' (y) : ContinuousAt (fun x : X => x) y := continuousAt_id theorem ContinuousAt.iterate {f : X → X} (hf : ContinuousAt f x) (hx : f x = x) (n : ℕ) : ContinuousAt f^[n] x := Nat.recOn n continuousAt_id fun _n ihn ↦ ihn.comp_of_eq hf hx theorem continuous_iff_isClosed : Continuous f ↔ ∀ s, IsClosed s → IsClosed (f ⁻¹' s) := continuous_def.trans <| compl_surjective.forall.trans <| by simp only [isOpen_compl_iff, preimage_compl] theorem IsClosed.preimage (hf : Continuous f) {t : Set Y} (h : IsClosed t) : IsClosed (f ⁻¹' t) := continuous_iff_isClosed.mp hf t h theorem mem_closure_image (hf : ContinuousAt f x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := mem_closure_of_frequently_of_tendsto ((mem_closure_iff_frequently.1 hx).mono fun _ => mem_image_of_mem _) hf theorem Continuous.closure_preimage_subset (hf : Continuous f) (t : Set Y) : closure (f ⁻¹' t) ⊆ f ⁻¹' closure t := by rw [← (isClosed_closure.preimage hf).closure_eq] exact closure_mono (preimage_mono subset_closure) theorem Continuous.frontier_preimage_subset (hf : Continuous f) (t : Set Y) : frontier (f ⁻¹' t) ⊆ f ⁻¹' frontier t := diff_subset_diff (hf.closure_preimage_subset t) (preimage_interior_subset_interior_preimage hf) /-- If a continuous map `f` maps `s` to `t`, then it maps `closure s` to `closure t`. -/ protected theorem Set.MapsTo.closure {t : Set Y} (h : MapsTo f s t) (hc : Continuous f) : MapsTo f (closure s) (closure t) := by simp only [MapsTo, mem_closure_iff_clusterPt] exact fun x hx => hx.map hc.continuousAt (tendsto_principal_principal.2 h) /-- See also `IsClosedMap.closure_image_eq_of_continuous`. -/ theorem image_closure_subset_closure_image (h : Continuous f) : f '' closure s ⊆ closure (f '' s) := ((mapsTo_image f s).closure h).image_subset theorem closure_image_closure (h : Continuous f) : closure (f '' closure s) = closure (f '' s) := Subset.antisymm (closure_minimal (image_closure_subset_closure_image h) isClosed_closure) (closure_mono <| image_mono subset_closure) theorem closure_subset_preimage_closure_image (h : Continuous f) : closure s ⊆ f ⁻¹' closure (f '' s) := (mapsTo_image _ _).closure h theorem map_mem_closure {t : Set Y} (hf : Continuous f) (hx : x ∈ closure s) (ht : MapsTo f s t) : f x ∈ closure t := ht.closure hf hx /-- If a continuous map `f` maps `s` to a closed set `t`, then it maps `closure s` to `t`. -/ theorem Set.MapsTo.closure_left {t : Set Y} (h : MapsTo f s t) (hc : Continuous f) (ht : IsClosed t) : MapsTo f (closure s) t := ht.closure_eq ▸ h.closure hc theorem Filter.Tendsto.lift'_closure (hf : Continuous f) {l l'} (h : Tendsto f l l') : Tendsto f (l.lift' closure) (l'.lift' closure) := tendsto_lift'.2 fun s hs ↦ by filter_upwards [mem_lift' (h hs)] using (mapsTo_preimage _ _).closure hf theorem tendsto_lift'_closure_nhds (hf : Continuous f) (x : X) : Tendsto f ((𝓝 x).lift' closure) ((𝓝 (f x)).lift' closure) := (hf.tendsto x).lift'_closure hf /-! ### Function with dense range -/ section DenseRange variable {α ι : Type*} (f : α → X) (g : X → Y) variable {f : α → X} {s : Set X} /-- A surjective map has dense range. -/ theorem Function.Surjective.denseRange (hf : Function.Surjective f) : DenseRange f := fun x => by simp [hf.range_eq] theorem denseRange_id : DenseRange (id : X → X) := Function.Surjective.denseRange Function.surjective_id theorem denseRange_iff_closure_range : DenseRange f ↔ closure (range f) = univ := dense_iff_closure_eq theorem DenseRange.closure_range (h : DenseRange f) : closure (range f) = univ := h.closure_eq @[simp] lemma denseRange_subtype_val {p : X → Prop} : DenseRange (@Subtype.val _ p) ↔ Dense {x | p x} := by simp [DenseRange] theorem Dense.denseRange_val (h : Dense s) : DenseRange ((↑) : s → X) := denseRange_subtype_val.2 h theorem Continuous.range_subset_closure_image_dense {f : X → Y} (hf : Continuous f) (hs : Dense s) : range f ⊆ closure (f '' s) := by rw [← image_univ, ← hs.closure_eq] exact image_closure_subset_closure_image hf /-- The image of a dense set under a continuous map with dense range is a dense set. -/ theorem DenseRange.dense_image {f : X → Y} (hf' : DenseRange f) (hf : Continuous f) (hs : Dense s) : Dense (f '' s) := (hf'.mono <| hf.range_subset_closure_image_dense hs).of_closure /-- If `f` has dense range and `s` is an open set in the codomain of `f`, then the image of the preimage of `s` under `f` is dense in `s`. -/ theorem DenseRange.subset_closure_image_preimage_of_isOpen (hf : DenseRange f) (hs : IsOpen s) : s ⊆ closure (f '' (f ⁻¹' s)) := by rw [image_preimage_eq_inter_range] exact hf.open_subset_closure_inter hs /-- If a continuous map with dense range maps a dense set to a subset of `t`, then `t` is a dense set. -/ theorem DenseRange.dense_of_mapsTo {f : X → Y} (hf' : DenseRange f) (hf : Continuous f) (hs : Dense s) {t : Set Y} (ht : MapsTo f s t) : Dense t := (hf'.dense_image hf hs).mono ht.image_subset /-- Composition of a continuous map with dense range and a function with dense range has dense range. -/ theorem DenseRange.comp {g : Y → Z} {f : α → Y} (hg : DenseRange g) (hf : DenseRange f) (cg : Continuous g) : DenseRange (g ∘ f) := by rw [DenseRange, range_comp] exact hg.dense_image cg hf nonrec theorem DenseRange.nonempty_iff (hf : DenseRange f) : Nonempty α ↔ Nonempty X := range_nonempty_iff_nonempty.symm.trans hf.nonempty_iff theorem DenseRange.nonempty [h : Nonempty X] (hf : DenseRange f) : Nonempty α := hf.nonempty_iff.mpr h /-- Given a function `f : X → Y` with dense range and `y : Y`, returns some `x : X`. -/ noncomputable def DenseRange.some (hf : DenseRange f) (x : X) : α := Classical.choice <| hf.nonempty_iff.mpr ⟨x⟩ nonrec theorem DenseRange.exists_mem_open (hf : DenseRange f) (ho : IsOpen s) (hs : s.Nonempty) : ∃ a, f a ∈ s := exists_range_iff.1 <| hf.exists_mem_open ho hs theorem DenseRange.mem_nhds (h : DenseRange f) (hs : s ∈ 𝓝 x) : ∃ a, f a ∈ s := let ⟨a, ha⟩ := h.exists_mem_open isOpen_interior ⟨x, mem_interior_iff_mem_nhds.2 hs⟩ ⟨a, interior_subset ha⟩ end DenseRange library_note2 «continuity lemma statement» /-- The library contains many lemmas stating that functions/operations are continuous. There are many ways to formulate the continuity of operations. Some are more convenient than others. Note: for the most part this note also applies to other properties (`Measurable`, `Differentiable`, `ContinuousOn`, ...). ### The traditional way As an example, let's look at addition `(+) : M → M → M`. We can state that this is continuous in different definitionally equal ways (omitting some typing information) * `Continuous (fun p ↦ p.1 + p.2)`; * `Continuous (Function.uncurry (+))`; * `Continuous ↿(+)`. (`↿` is notation for recursively uncurrying a function) However, lemmas with this conclusion are not nice to use in practice because 1. They confuse the elaborator. The following example fails, because of limitations in the elaboration process. ``` variable {M : Type*} [Add M] [TopologicalSpace M] [ContinuousAdd M] example : Continuous (fun x : M ↦ x + x) := continuous_add.comp _ -- This example used to fail, but would be accepted if you wrote is as -- `continuous_add.comp (continuous_id.prodMk continuous_id :)`. example : Continuous (fun x : M ↦ x + x) := continuous_add.comp (continuous_id.prodMk continuous_id) ``` 2. If the operation has more than 2 arguments, they are impractical to use, because in your application the arguments in the domain might be in a different order or associated differently. ### The convenient way A much more convenient way to write continuity lemmas is like `Continuous.add`: ``` Continuous.add {f g : X → M} (hf : Continuous f) (hg : Continuous g) : Continuous (f + g) ``` The conclusion can be `Continuous (fun x ↦ f x + g x)`, which is definitionally equal. This has the following advantages * It supports projection notation, so is shorter to write. * `Continuous.add _ _` is recognized correctly by the elaborator and gives useful new goals. * It works generally, since the domain is a variable. (Having a domain `Y × Z` would be less convenient in general.) As an example for a unary operation, we have `Continuous.neg`. ``` Continuous.neg {f : X → G} (hf : Continuous f) : Continuous (-f) ``` For unary functions, the elaborator is not confused when applying the traditional lemma (like `continuous_neg`), but it's still convenient to have the short version available (compare `hf.neg.neg.neg` with `continuous_neg.comp <| continuous_neg.comp <| continuous_neg.comp hf`). As a harder example, consider an operation of the following type: ``` def strans {x : F} (γ γ' : Path x x) (t₀ : I) : Path x x ``` The precise definition is not important, only its type. The correct continuity principle for this operation is something like this: ``` {f : X → F} {γ γ' : ∀ x, Path (f x) (f x)} {t₀ s : X → I} (hγ : Continuous ↿γ) (hγ' : Continuous ↿γ') (ht : Continuous t₀) (hs : Continuous s) : Continuous (fun x ↦ strans (γ x) (γ' x) (t x) (s x)) ``` Note that *all* arguments of `strans` are indexed over `X`, even the basepoint `x`, and the last argument `s` that arises since `Path x x` has a coercion to `I → F`. The paths `γ` and `γ'` (which are unary functions from `I`) become binary functions in the continuity lemma. ### Summary * Make sure that your continuity lemmas are stated in the most general way, and in a convenient form. That means that: - The conclusion has a variable `X` as domain (not something like `Y × Z`); - Wherever possible, all point arguments `c : Y` are replaced by functions `c : X → Y`; - All `n`-ary function arguments are replaced by `n+1`-ary functions (`f : Y → Z` becomes `f : X → Y → Z`); - All (relevant) arguments have continuity assumptions, and perhaps there are additional assumptions needed to make the operation continuous; - The function in the conclusion is fully applied. * These remarks are mostly about the format of the *conclusion* of a continuity lemma. In assumptions it's fine to state that a function with more than 1 argument is continuous using `↿` or `Function.uncurry`. ### Functions with discontinuities In some cases, you want to work with discontinuous functions, and in certain expressions they are still continuous. For example, consider the fractional part of a number, `Int.fract : ℝ → ℝ`. In this case, you want to add conditions to when a function involving `fract` is continuous, so you get something like this: (assumption `hf` could be weakened, but the important thing is the shape of the conclusion) ``` lemma ContinuousOn.comp_fract {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {f : X → ℝ → Y} {g : X → ℝ} (hf : Continuous ↿f) (hg : Continuous g) (h : ∀ s, f s 0 = f s 1) : Continuous (fun x ↦ f x (fract (g x))) ``` With `ContinuousAt` you can be even more precise about what to prove in case of discontinuities, see e.g. `ContinuousAt.comp_div_cases`. -/ library_note2 «comp_of_eq lemmas» /-- Lean's elaborator has trouble elaborating applications of lemmas that state that the composition of two functions satisfy some property at a point, like `ContinuousAt.comp` / `ContDiffAt.comp` and `ContMDiffWithinAt.comp`. The reason is that a lemma like this looks like `ContinuousAt g (f x) → ContinuousAt f x → ContinuousAt (g ∘ f) x`. Since Lean's elaborator elaborates the arguments from left-to-right, when you write `hg.comp hf`, the elaborator will try to figure out *both* `f` and `g` from the type of `hg`. It tries to figure out `f` just from the point where `g` is continuous. For example, if `hg : ContinuousAt g (a, x)` then the elaborator will assign `f` to the function `Prod.mk a`, since in that case `f x = (a, x)`. This is undesirable in most cases where `f` is not a variable. There are some ways to work around this, for example by giving `f` explicitly, or to force Lean to elaborate `hf` before elaborating `hg`, but this is annoying. Another better solution is to reformulate composition lemmas to have the following shape `ContinuousAt g y → ContinuousAt f x → f x = y → ContinuousAt (g ∘ f) x`. This is even useful if the proof of `f x = y` is `rfl`. The reason that this works better is because the type of `hg` doesn't mention `f`. Only after elaborating the two `ContinuousAt` arguments, Lean will try to unify `f x` with `y`, which is often easy after having chosen the correct functions for `f` and `g`. Here is an example that shows the difference: ``` example [TopologicalSpace X] [TopologicalSpace Y] {x₀ : X} (f : X → X → Y) (hf : ContinuousAt (Function.uncurry f) (x₀, x₀)) : ContinuousAt (fun x ↦ f x x) x₀ := -- hf.comp (continuousAt_id.prod continuousAt_id) -- type mismatch -- hf.comp_of_eq (continuousAt_id.prod continuousAt_id) rfl -- works ``` -/
.lake/packages/mathlib/Mathlib/Topology/LocallyFinsupp.lean
import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Group.Support import Mathlib.Algebra.Order.Group.PosPart import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Algebra.Order.Pi import Mathlib.Topology.DiscreteSubset import Mathlib.Topology.Separation.Hausdorff /-! # Type of functions with locally finite support This file defines functions with locally finite support, provides supporting API. For suitable targets, it establishes functions with locally finite support as an instance of a lattice ordered commutative group. Throughout the present file, `X` denotes a topologically space and `U` a subset of `X`. -/ open Filter Function Set Topology variable {X : Type*} [TopologicalSpace X] {U : Set X} {Y : Type*} /-! ## Definition, coercion to functions and basic extensionality lemmas A function with locally finite support within `U` is a function `X → Y` whose support is locally finite within `U` and entirely contained in `U`. For T1-spaces, the theorem `supportDiscreteWithin_iff_locallyFiniteWithin` shows that the first condition is equivalent to the condition that the support `f` is discrete within `U`. -/ variable (U Y) in /-- A function with locally finite support within `U` is a triple as specified below. -/ structure Function.locallyFinsuppWithin [Zero Y] where /-- A function `X → Y` -/ toFun : X → Y /-- A proof that the support of `toFun` is contained in `U` -/ supportWithinDomain' : toFun.support ⊆ U /-- A proof that the support is locally finite within `U` -/ supportLocallyFiniteWithinDomain' : ∀ z ∈ U, ∃ t ∈ 𝓝 z, Set.Finite (t ∩ toFun.support) variable (X Y) in /-- A function with locally finite support is a function with locally finite support within `⊤ : Set X`. -/ def Function.locallyFinsupp [Zero Y] := locallyFinsuppWithin (⊤ : Set X) Y /-- For T1 spaces, the condition `supportLocallyFiniteWithinDomain'` is equivalent to saying that the support is codiscrete within `U`. -/ theorem supportDiscreteWithin_iff_locallyFiniteWithin [T1Space X] [Zero Y] {f : X → Y} (h : f.support ⊆ U) : f =ᶠ[codiscreteWithin U] 0 ↔ ∀ z ∈ U, ∃ t ∈ 𝓝 z, Set.Finite (t ∩ f.support) := by have : f.support = (U \ {x | f x = (0 : X → Y) x}) := by ext x simp only [mem_support, ne_eq, Pi.zero_apply, mem_diff, mem_setOf_eq, iff_and_self] exact (h ·) rw [EventuallyEq, Filter.Eventually, codiscreteWithin_iff_locallyFiniteComplementWithin, this] namespace Function.locallyFinsuppWithin /-- Functions with locally finite support within `U` are `FunLike`: the coercion to functions is injective. -/ instance [Zero Y] : FunLike (locallyFinsuppWithin U Y) X Y where coe D := D.toFun coe_injective' := fun ⟨_, _, _⟩ ⟨_, _, _⟩ ↦ by simp /-- This allows writing `D.support` instead of `Function.support D` -/ abbrev support [Zero Y] (D : locallyFinsuppWithin U Y) := Function.support D lemma supportWithinDomain [Zero Y] (D : locallyFinsuppWithin U Y) : D.support ⊆ U := D.supportWithinDomain' lemma supportLocallyFiniteWithinDomain [Zero Y] (D : locallyFinsuppWithin U Y) : ∀ z ∈ U, ∃ t ∈ 𝓝 z, Set.Finite (t ∩ D.support) := D.supportLocallyFiniteWithinDomain' @[ext] lemma ext [Zero Y] {D₁ D₂ : locallyFinsuppWithin U Y} (h : ∀ a, D₁ a = D₂ a) : D₁ = D₂ := DFunLike.ext _ _ h lemma coe_injective [Zero Y] : Injective (· : locallyFinsuppWithin U Y → X → Y) := DFunLike.coe_injective /-! ## Elementary properties of the support -/ /-- Simplifier lemma: Functions with locally finite support within `U` evaluate to zero outside of `U`. -/ @[simp] lemma apply_eq_zero_of_notMem [Zero Y] {z : X} (D : locallyFinsuppWithin U Y) (hz : z ∉ U) : D z = 0 := notMem_support.mp fun a ↦ hz (D.supportWithinDomain a) @[deprecated (since := "2025-05-23")] alias apply_eq_zero_of_not_mem := apply_eq_zero_of_notMem /-- On a T1 space, the support of a function with locally finite support within `U` is discrete within `U`. -/ theorem eq_zero_codiscreteWithin [Zero Y] [T1Space X] (D : locallyFinsuppWithin U Y) : D =ᶠ[Filter.codiscreteWithin U] 0 := by apply codiscreteWithin_iff_locallyFiniteComplementWithin.2 have : D.support = (U \ {x | D x = (0 : X → Y) x}) := by ext x simp only [mem_support, ne_eq, Pi.zero_apply, Set.mem_diff, Set.mem_setOf_eq, iff_and_self] exact (support_subset_iff.1 D.supportWithinDomain) x rw [← this] exact D.supportLocallyFiniteWithinDomain /-- On a T1 space, the support of a functions with locally finite support within `U` is discrete. -/ theorem discreteSupport [Zero Y] [T1Space X] (D : locallyFinsuppWithin U Y) : DiscreteTopology D.support := by have : D.support = {x | D x = 0}ᶜ ∩ U := by ext x constructor · exact fun hx ↦ ⟨by tauto, D.supportWithinDomain hx⟩ · intro hx rw [mem_inter_iff, mem_compl_iff, mem_setOf_eq] at hx tauto rw [this] apply discreteTopology_of_codiscreteWithin apply (supportDiscreteWithin_iff_locallyFiniteWithin D.supportWithinDomain).2 exact D.supportLocallyFiniteWithinDomain /-- If `X` is T1 and if `U` is closed, then the support of support of a function with locally finite support within `U` is also closed. -/ theorem closedSupport [T1Space X] [Zero Y] (D : locallyFinsuppWithin U Y) (hU : IsClosed U) : IsClosed D.support := by convert isClosed_sdiff_of_codiscreteWithin ((supportDiscreteWithin_iff_locallyFiniteWithin D.supportWithinDomain).2 D.supportLocallyFiniteWithinDomain) hU ext x constructor <;> intro hx · simp_all [D.supportWithinDomain hx] · simp_all /-- If `X` is T2 and if `U` is compact, then the support of a function with locally finite support within `U` is finite. -/ theorem finiteSupport [T2Space X] [Zero Y] (D : locallyFinsuppWithin U Y) (hU : IsCompact U) : Set.Finite D.support := (hU.of_isClosed_subset (D.closedSupport hU.isClosed) D.supportWithinDomain).finite D.discreteSupport /-! ## Lattice ordered group structure If `X` is a suitable instance, this section equips functions with locally finite support within `U` with the standard structure of a lattice ordered group, where addition, comparison, min and max are defined pointwise. -/ variable (U) in /-- Functions with locally finite support within `U` form an additive subgroup of functions X → Y. -/ protected def addSubgroup [AddCommGroup Y] : AddSubgroup (X → Y) where carrier := {f | f.support ⊆ U ∧ ∀ z ∈ U, ∃ t ∈ 𝓝 z, Set.Finite (t ∩ f.support)} zero_mem' := by simp only [support_subset_iff, ne_eq, mem_setOf_eq, Pi.zero_apply, not_true_eq_false, IsEmpty.forall_iff, implies_true, support_zero, inter_empty, finite_empty, and_true, true_and] exact fun _ _ ↦ ⟨⊤, univ_mem⟩ add_mem' {f g} hf hg := by constructor · intro x hx contrapose! hx simp [notMem_support.1 fun a ↦ hx (hf.1 a), notMem_support.1 fun a ↦ hx (hg.1 a)] · intro z hz obtain ⟨t₁, ht₁⟩ := hf.2 z hz obtain ⟨t₂, ht₂⟩ := hg.2 z hz use t₁ ∩ t₂, inter_mem ht₁.1 ht₂.1 apply Set.Finite.subset (s := (t₁ ∩ f.support) ∪ (t₂ ∩ g.support)) (ht₁.2.union ht₂.2) intro a ha simp_all only [support_subset_iff, ne_eq, mem_setOf_eq, mem_inter_iff, mem_support, Pi.add_apply, mem_union, true_and] by_contra! hCon simp_all neg_mem' {f} hf := by simp_all protected lemma memAddSubgroup [AddCommGroup Y] (D : locallyFinsuppWithin U Y) : (D : X → Y) ∈ locallyFinsuppWithin.addSubgroup U := ⟨D.supportWithinDomain, D.supportLocallyFiniteWithinDomain⟩ /-- Assign a function with locally finite support within `U` to a function in the subgroup. -/ @[simps] def mk_of_mem [AddCommGroup Y] (f : X → Y) (hf : f ∈ locallyFinsuppWithin.addSubgroup U) : locallyFinsuppWithin U Y := ⟨f, hf.1, hf.2⟩ instance [AddCommGroup Y] : Zero (locallyFinsuppWithin U Y) where zero := mk_of_mem 0 <| zero_mem _ instance [AddCommGroup Y] : Add (locallyFinsuppWithin U Y) where add D₁ D₂ := mk_of_mem (D₁ + D₂) <| add_mem D₁.memAddSubgroup D₂.memAddSubgroup instance [AddCommGroup Y] : Neg (locallyFinsuppWithin U Y) where neg D := mk_of_mem (-D) <| neg_mem D.memAddSubgroup instance [AddCommGroup Y] : Sub (locallyFinsuppWithin U Y) where sub D₁ D₂ := mk_of_mem (D₁ - D₂) <| sub_mem D₁.memAddSubgroup D₂.memAddSubgroup instance [AddCommGroup Y] : SMul ℕ (locallyFinsuppWithin U Y) where smul n D := mk_of_mem (n • D) <| nsmul_mem D.memAddSubgroup n instance [AddCommGroup Y] : SMul ℤ (locallyFinsuppWithin U Y) where smul n D := mk_of_mem (n • D) <| zsmul_mem D.memAddSubgroup n @[simp] lemma coe_zero [AddCommGroup Y] : ((0 : locallyFinsuppWithin U Y) : X → Y) = 0 := rfl @[simp] lemma coe_add [AddCommGroup Y] (D₁ D₂ : locallyFinsuppWithin U Y) : (↑(D₁ + D₂) : X → Y) = D₁ + D₂ := rfl @[simp] lemma coe_neg [AddCommGroup Y] (D : locallyFinsuppWithin U Y) : (↑(-D) : X → Y) = -(D : X → Y) := rfl @[simp] lemma coe_sub [AddCommGroup Y] (D₁ D₂ : locallyFinsuppWithin U Y) : (↑(D₁ - D₂) : X → Y) = D₁ - D₂ := rfl @[simp] lemma coe_nsmul [AddCommGroup Y] (D : locallyFinsuppWithin U Y) (n : ℕ) : (↑(n • D) : X → Y) = n • (D : X → Y) := rfl @[simp] lemma coe_zsmul [AddCommGroup Y] (D : locallyFinsuppWithin U Y) (n : ℤ) : (↑(n • D) : X → Y) = n • (D : X → Y) := rfl instance [AddCommGroup Y] : AddCommGroup (locallyFinsuppWithin U Y) := Injective.addCommGroup (M₁ := locallyFinsuppWithin U Y) (M₂ := X → Y) _ coe_injective coe_zero coe_add coe_neg coe_sub coe_nsmul coe_zsmul instance [LE Y] [Zero Y] : LE (locallyFinsuppWithin U Y) where le := fun D₁ D₂ ↦ (D₁ : X → Y) ≤ D₂ lemma le_def [LE Y] [Zero Y] {D₁ D₂ : locallyFinsuppWithin U Y} : D₁ ≤ D₂ ↔ (D₁ : X → Y) ≤ (D₂ : X → Y) := ⟨(·),(·)⟩ instance [Preorder Y] [Zero Y] : LT (locallyFinsuppWithin U Y) where lt := fun D₁ D₂ ↦ (D₁ : X → Y) < D₂ lemma lt_def [Preorder Y] [Zero Y] {D₁ D₂ : locallyFinsuppWithin U Y} : D₁ < D₂ ↔ (D₁ : X → Y) < (D₂ : X → Y) := ⟨(·),(·)⟩ instance [SemilatticeSup Y] [Zero Y] : Max (locallyFinsuppWithin U Y) where max D₁ D₂ := { toFun z := max (D₁ z) (D₂ z) supportWithinDomain' := by intro x contrapose intro hx simp [notMem_support.1 fun a ↦ hx (D₁.supportWithinDomain a), notMem_support.1 fun a ↦ hx (D₂.supportWithinDomain a)] supportLocallyFiniteWithinDomain' := by intro z hz obtain ⟨t₁, ht₁⟩ := D₁.supportLocallyFiniteWithinDomain z hz obtain ⟨t₂, ht₂⟩ := D₂.supportLocallyFiniteWithinDomain z hz use t₁ ∩ t₂, inter_mem ht₁.1 ht₂.1 apply Set.Finite.subset (s := (t₁ ∩ D₁.support) ∪ (t₂ ∩ D₂.support)) (ht₁.2.union ht₂.2) intro a ha simp_all only [mem_inter_iff, mem_support, ne_eq, mem_union, true_and] by_contra! hCon simp_all } @[simp] lemma max_apply [SemilatticeSup Y] [Zero Y] {D₁ D₂ : locallyFinsuppWithin U Y} {x : X} : max D₁ D₂ x = max (D₁ x) (D₂ x) := rfl instance [SemilatticeInf Y] [Zero Y] : Min (locallyFinsuppWithin U Y) where min D₁ D₂ := { toFun z := min (D₁ z) (D₂ z) supportWithinDomain' := by intro x contrapose intro hx simp [notMem_support.1 fun a ↦ hx (D₁.supportWithinDomain a), notMem_support.1 fun a ↦ hx (D₂.supportWithinDomain a)] supportLocallyFiniteWithinDomain' := by intro z hz obtain ⟨t₁, ht₁⟩ := D₁.supportLocallyFiniteWithinDomain z hz obtain ⟨t₂, ht₂⟩ := D₂.supportLocallyFiniteWithinDomain z hz use t₁ ∩ t₂, inter_mem ht₁.1 ht₂.1 apply Set.Finite.subset (s := (t₁ ∩ D₁.support) ∪ (t₂ ∩ D₂.support)) (ht₁.2.union ht₂.2) intro a ha simp_all only [mem_inter_iff, mem_support, ne_eq, mem_union, true_and] by_contra! hCon simp_all } @[simp] lemma min_apply [SemilatticeInf Y] [Zero Y] {D₁ D₂ : locallyFinsuppWithin U Y} {x : X} : min D₁ D₂ x = min (D₁ x) (D₂ x) := rfl section Lattice variable [Lattice Y] instance [Zero Y] : Lattice (locallyFinsuppWithin U Y) where le_refl := by simp [le_def] le_trans D₁ D₂ D₃ h₁₂ h₂₃ := fun x ↦ (h₁₂ x).trans (h₂₃ x) le_antisymm D₁ D₂ h₁₂ h₂₁ := by ext x exact le_antisymm (h₁₂ x) (h₂₁ x) sup := max le_sup_left D₁ D₂ := fun x ↦ by simp le_sup_right D₁ D₂ := fun x ↦ by simp sup_le D₁ D₂ D₃ h₁₃ h₂₃ := fun x ↦ by simp [h₁₃ x, h₂₃ x] inf := min inf_le_left D₁ D₂ := fun x ↦ by simp inf_le_right D₁ D₂ := fun x ↦ by simp le_inf D₁ D₂ D₃ h₁₃ h₂₃ := fun x ↦ by simp [h₁₃ x, h₂₃ x] variable [AddCommGroup Y] @[simp] lemma posPart_apply (a : locallyFinsuppWithin U Y) (x : X) : a⁺ x = (a x)⁺ := rfl @[simp] lemma negPart_apply (a : locallyFinsuppWithin U Y) (x : X) : a⁻ x = (a x)⁻ := rfl end Lattice section LinearOrder variable [AddCommGroup Y] [LinearOrder Y] [IsOrderedAddMonoid Y] /-- Functions with locally finite support within `U` form an ordered commutative group. -/ instance : IsOrderedAddMonoid (locallyFinsuppWithin U Y) where add_le_add_left := fun _ _ _ _ ↦ by simpa [le_def] /-- The positive part of a sum is less than or equal to the sum of the positive parts. -/ theorem posPart_add (f₁ f₂ : Function.locallyFinsuppWithin U Y) : (f₁ + f₂)⁺ ≤ f₁⁺ + f₂⁺ := by repeat rw [posPart_def] intro x simp only [Function.locallyFinsuppWithin.max_apply, Function.locallyFinsuppWithin.coe_add, Pi.add_apply, Function.locallyFinsuppWithin.coe_zero, Pi.zero_apply, sup_le_iff] constructor · simp [add_le_add] · simp [add_nonneg] /-- The negative part of a sum is less than or equal to the sum of the negative parts. -/ theorem negPart_add (f₁ f₂ : Function.locallyFinsuppWithin U Y) : (f₁ + f₂)⁻ ≤ f₁⁻ + f₂⁻ := by repeat rw [negPart_def] intro x simp only [neg_add_rev, Function.locallyFinsuppWithin.max_apply, Function.locallyFinsuppWithin.coe_add, Function.locallyFinsuppWithin.coe_neg, Pi.add_apply, Pi.neg_apply, Function.locallyFinsuppWithin.coe_zero, Pi.zero_apply, sup_le_iff] constructor · simp [add_comm, add_le_add] · simp [add_nonneg] /-- Taking the positive part of a function with locally finite support commutes with scalar multiplication by a natural number. -/ @[simp] theorem nsmul_posPart (n : ℕ) (f : locallyFinsuppWithin U Y) : (n • f)⁺ = n • f⁺ := by ext x simp only [posPart, max_apply, coe_nsmul, Pi.smul_apply, coe_zero, Pi.zero_apply] by_cases h : f x < 0 · simpa [max_eq_right_of_lt h] using nsmul_le_nsmul_right h.le n · simpa [not_lt.1 h] using nsmul_nonneg (not_lt.1 h) n /-- Taking the negative part of a function with locally finite support commutes with scalar multiplication by a natural number. -/ @[simp] theorem nsmul_negPart (n : ℕ) (f : locallyFinsuppWithin U Y) : (n • f)⁻ = n • f⁻ := by ext x simp only [negPart, max_apply, coe_neg, coe_nsmul, Pi.neg_apply, Pi.smul_apply, coe_zero, Pi.zero_apply] by_cases h : -f x < 0 · simpa [max_eq_right_of_lt h] using nsmul_le_nsmul_right h.le n · simpa [not_lt.1 h] using nsmul_nonneg (not_lt.1 h) n end LinearOrder /-! ## Restriction -/ /-- If `V` is a subset of `U`, then functions with locally finite support within `U` restrict to functions with locally finite support within `V`, by setting their values to zero outside of `V`. -/ noncomputable def restrict [Zero Y] {V : Set X} (D : locallyFinsuppWithin U Y) (h : V ⊆ U) : locallyFinsuppWithin V Y where toFun := by classical exact fun z ↦ if hz : z ∈ V then D z else 0 supportWithinDomain' := by intro x hx simp_rw [dite_eq_ite, mem_support, ne_eq, ite_eq_right_iff, Classical.not_imp] at hx exact hx.1 supportLocallyFiniteWithinDomain' := by intro z hz obtain ⟨t, ht⟩ := D.supportLocallyFiniteWithinDomain z (h hz) use t, ht.1 apply Set.Finite.subset (s := t ∩ D.support) ht.2 intro _ _ simp_all open Classical in lemma restrict_apply [Zero Y] {V : Set X} (D : locallyFinsuppWithin U Y) (h : V ⊆ U) (z : X) : (D.restrict h) z = if z ∈ V then D z else 0 := rfl lemma restrict_eqOn [Zero Y] {V : Set X} (D : locallyFinsuppWithin U Y) (h : V ⊆ U) : Set.EqOn (D.restrict h) D V := by intro _ _ simp_all [restrict_apply] lemma restrict_eqOn_compl [Zero Y] {V : Set X} (D : locallyFinsuppWithin U Y) (h : V ⊆ U) : Set.EqOn (D.restrict h) 0 Vᶜ := by intro _ hx simp_all /-- Restriction as a group morphism -/ noncomputable def restrictMonoidHom [AddCommGroup Y] {V : Set X} (h : V ⊆ U) : locallyFinsuppWithin U Y →+ locallyFinsuppWithin V Y where toFun D := D.restrict h map_zero' := by ext x simp [restrict_apply] map_add' D₁ D₂ := by ext x by_cases hx : x ∈ V <;> simp [restrict_apply, hx] @[simp] lemma restrictMonoidHom_apply [AddCommGroup Y] {V : Set X} (D : locallyFinsuppWithin U Y) (h : V ⊆ U) : restrictMonoidHom h D = D.restrict h := by rfl /-- Restriction as a lattice morphism -/ noncomputable def restrictLatticeHom [AddCommGroup Y] [Lattice Y] {V : Set X} (h : V ⊆ U) : LatticeHom (locallyFinsuppWithin U Y) (locallyFinsuppWithin V Y) where toFun D := D.restrict h map_sup' D₁ D₂ := by ext x by_cases hx : x ∈ V <;> simp [locallyFinsuppWithin.restrict_apply, hx] map_inf' D₁ D₂ := by ext x by_cases hx : x ∈ V <;> simp [locallyFinsuppWithin.restrict_apply, hx] @[simp] lemma restrictLatticeHom_apply [AddCommGroup Y] [Lattice Y] {V : Set X} (D : locallyFinsuppWithin U Y) (h : V ⊆ U) : restrictLatticeHom h D = D.restrict h := by rfl end Function.locallyFinsuppWithin
.lake/packages/mathlib/Mathlib/Topology/PreorderRestrict.lean
import Mathlib.Order.Restriction import Mathlib.Topology.Constructions /-! # Continuity of the restriction function for functions indexed by a preorder We prove that the map which restricts a function `f : (i : α) → X i` to elements `≤ a` is continuous. -/ namespace Preorder variable {α : Type*} [Preorder α] {X : α → Type*} [∀ i, TopologicalSpace (X i)] @[continuity, fun_prop] theorem continuous_restrictLe (a : α) : Continuous (restrictLe (π := X) a) := Pi.continuous_restrict _ @[continuity, fun_prop] theorem continuous_restrictLe₂ {a b : α} (hab : a ≤ b) : Continuous (restrictLe₂ (π := X) hab) := Pi.continuous_restrict₂ _ variable [LocallyFiniteOrderBot α] @[continuity, fun_prop] theorem continuous_frestrictLe (a : α) : Continuous (frestrictLe (π := X) a) := Finset.continuous_restrict _ @[continuity, fun_prop] theorem continuous_frestrictLe₂ {a b : α} (hab : a ≤ b) : Continuous (frestrictLe₂ (π := X) hab) := Finset.continuous_restrict₂ _ end Preorder
.lake/packages/mathlib/Mathlib/Topology/OmegaCompletePartialOrder.lean
import Mathlib.Order.OmegaCompletePartialOrder import Mathlib.Topology.Order.ScottTopology /-! # Scott Topological Spaces A type of topological spaces whose notion of continuity is equivalent to continuity in ωCPOs. ## Reference * https://ncatlab.org/nlab/show/Scott+topology -/ open Set OmegaCompletePartialOrder Topology universe u open Topology.IsScott in @[simp] lemma Topology.IsScott.ωScottContinuous_iff_continuous {α : Type*} [OmegaCompletePartialOrder α] [TopologicalSpace α] [Topology.IsScott α (Set.range fun c : Chain α => Set.range c)] {f : α → Prop} : ωScottContinuous f ↔ Continuous f := by rw [ωScottContinuous, scottContinuousOn_iff_continuous (fun a b hab => by use Chain.pair a b hab; exact OmegaCompletePartialOrder.Chain.range_pair a b hab)] @[deprecated (since := "2025-07-02")] alias Topology.IsScott.ωscottContinuous_iff_continuous := Topology.IsScott.ωScottContinuous_iff_continuous namespace Scott /-- `x` is an `ω`-Sup of a chain `c` if it is the least upper bound of the range of `c`. -/ def IsωSup {α : Type u} [Preorder α] (c : Chain α) (x : α) : Prop := (∀ i, c i ≤ x) ∧ ∀ y, (∀ i, c i ≤ y) → x ≤ y theorem isωSup_iff_isLUB {α : Type u} [Preorder α] {c : Chain α} {x : α} : IsωSup c x ↔ IsLUB (range c) x := by simp [IsωSup, IsLUB, IsLeast, upperBounds, lowerBounds] variable (α : Type u) [OmegaCompletePartialOrder α] /-- The characteristic function of open sets is monotone and preserves the limits of chains. -/ def IsOpen (s : Set α) : Prop := ωScottContinuous fun x ↦ x ∈ s theorem isOpen_univ : IsOpen α univ := @CompleteLattice.ωScottContinuous.top α Prop _ _ theorem IsOpen.inter (s t : Set α) : IsOpen α s → IsOpen α t → IsOpen α (s ∩ t) := CompleteLattice.ωScottContinuous.inf theorem isOpen_sUnion (s : Set (Set α)) (hs : ∀ t ∈ s, IsOpen α t) : IsOpen α (⋃₀ s) := by simp only [IsOpen] at hs ⊢ convert CompleteLattice.ωScottContinuous.sSup hs aesop theorem IsOpen.isUpperSet {s : Set α} (hs : IsOpen α s) : IsUpperSet s := hs.monotone end Scott /-- A Scott topological space is defined on preorders such that their open sets, seen as a function `α → Prop`, preserves the joins of ω-chains. -/ @[deprecated WithScott (since := "2025-07-02")] abbrev Scott (α : Type u) := α set_option linter.deprecated false in /-- Deprecated, use `WithScott`. -/ @[deprecated Topology.WithScott.instTopologicalSpace (since := "2025-07-02")] abbrev Scott.topologicalSpace (α : Type u) [OmegaCompletePartialOrder α] : TopologicalSpace (Scott α) where IsOpen := Scott.IsOpen α isOpen_univ := Scott.isOpen_univ α isOpen_inter := Scott.IsOpen.inter α isOpen_sUnion := Scott.isOpen_sUnion α attribute [local instance] Scott.topologicalSpace set_option linter.deprecated false in @[deprecated isOpen_iff_continuous_mem (since := "2025-07-02")] lemma isOpen_iff_ωScottContinuous_mem {α} [OmegaCompletePartialOrder α] {s : Set (Scott α)} : IsOpen s ↔ ωScottContinuous fun x ↦ x ∈ s := by rfl set_option linter.deprecated false in @[deprecated "Use `WithScott` API" (since := "2025-07-02")] lemma scott_eq_Scott {α} [OmegaCompletePartialOrder α] : Topology.scott α (Set.range fun c : Chain α => Set.range c) = Scott.topologicalSpace α := by ext U letI := Topology.scott α (Set.range fun c : Chain α => Set.range c) rw [isOpen_iff_ωScottContinuous_mem, @isOpen_iff_continuous_mem, @Topology.IsScott.ωscottContinuous_iff_continuous _ _ (Topology.scott α (Set.range fun c : Chain α => Set.range c)) ({ topology_eq_scott := rfl })] section notBelow variable {α : Type*} [OmegaCompletePartialOrder α] set_option linter.deprecated false in /-- `notBelow` is an open set in `Scott α` used to prove the monotonicity of continuous functions -/ def notBelow (y : Scott α) := { x | ¬x ≤ y } set_option linter.deprecated false in @[deprecated isClosed_Iic (since := "2025-07-02")] theorem notBelow_isOpen (y : Scott α) : IsOpen (notBelow y) := by have h : Monotone (notBelow y) := fun x z hle ↦ mt hle.trans dsimp only [IsOpen, TopologicalSpace.IsOpen, Scott.IsOpen] rw [ωScottContinuous_iff_monotone_map_ωSup] refine ⟨h, fun c ↦ eq_of_forall_ge_iff fun z ↦ ?_⟩ simp only [ωSup_le_iff, notBelow, mem_setOf_eq, le_Prop_eq, OrderHom.coe_mk, Chain.map_coe, Function.comp_apply, exists_imp, not_forall] end notBelow open Scott hiding IsOpen IsOpen.isUpperSet theorem isωSup_ωSup {α} [OmegaCompletePartialOrder α] (c : Chain α) : IsωSup c (ωSup c) := by constructor · apply le_ωSup · apply ωSup_le set_option linter.deprecated false in @[deprecated Topology.IsScott.ωscottContinuous_iff_continuous (since := "2025-07-02")] theorem scottContinuous_of_continuous {α β} [OmegaCompletePartialOrder α] [OmegaCompletePartialOrder β] (f : Scott α → Scott β) (hf : _root_.Continuous f) : OmegaCompletePartialOrder.ωScottContinuous f := by rw [ωScottContinuous_iff_monotone_map_ωSup] have h : Monotone f := fun x y h ↦ by have hf : IsUpperSet {x | ¬f x ≤ f y} := ((notBelow_isOpen (f y)).preimage hf).isUpperSet simpa only [mem_setOf_eq, le_refl, not_true, imp_false, not_not] using hf h refine ⟨h, fun c ↦ eq_of_forall_ge_iff fun z ↦ ?_⟩ rcases (notBelow_isOpen z).preimage hf with hf'' let hf' := hf''.monotone_map_ωSup.2 specialize hf' c simp only [mem_preimage, notBelow, mem_setOf_eq] at hf' rw [← not_iff_not] simp only [ωSup_le_iff, hf', ωSup, iSup, sSup, mem_range, Chain.map_coe, Function.comp_apply, eq_iff_iff, not_forall, OrderHom.coe_mk] tauto set_option linter.deprecated false in @[deprecated Topology.IsScott.ωscottContinuous_iff_continuous (since := "2025-07-02")] theorem continuous_of_scottContinuous {α β} [OmegaCompletePartialOrder α] [OmegaCompletePartialOrder β] (f : Scott α → Scott β) (hf : ωScottContinuous f) : Continuous f := by rw [continuous_def]; exact fun s hs ↦ hs.comp hf