source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Dilation.lean
import Mathlib.Topology.MetricSpace.Antilipschitz import Mathlib.Topology.MetricSpace.Isometry import Mathlib.Topology.MetricSpace.Lipschitz import Mathlib.Data.FunLike.Basic /-! # Dilations We define dilations, i.e., maps between emetric spaces that satisfy `edist (f x) (f y) = r * edist x y` for some `r ∉ {0, ∞}`. The value `r = 0` is not allowed because we want dilations of (e)metric spaces to be automatically injective. The value `r = ∞` is not allowed because this way we can define `Dilation.ratio f : ℝ≥0`, not `Dilation.ratio f : ℝ≥0∞`. Also, we do not often need maps sending distinct points to points at infinite distance. ## Main definitions * `Dilation.ratio f : ℝ≥0`: the value of `r` in the relation above, defaulting to 1 in the case where it is not well-defined. ## Notation - `α →ᵈ β`: notation for `Dilation α β`. ## Implementation notes The type of dilations defined in this file are also referred to as "similarities" or "similitudes" by other authors. The name `Dilation` was chosen to match the Wikipedia name. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `PseudoEMetricSpace` and we specialize to `PseudoMetricSpace` and `MetricSpace` when needed. ## TODO - Introduce dilation equivs. - Refactor the `Isometry` API to match the `*HomClass` API below. ## References - https://en.wikipedia.org/wiki/Dilation_(metric_space) - [Marcel Berger, *Geometry*][berger1987] -/ noncomputable section open Bornology Function Set Topology open scoped ENNReal NNReal section Defs variable (α : Type*) (β : Type*) [PseudoEMetricSpace α] [PseudoEMetricSpace β] /-- A dilation is a map that uniformly scales the edistance between any two points. -/ structure Dilation where /-- The underlying function. Do NOT use directly. Use the coercion instead. -/ toFun : α → β edist_eq' : ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, edist (toFun x) (toFun y) = r * edist x y @[inherit_doc] infixl:25 " →ᵈ " => Dilation /-- `DilationClass F α β r` states that `F` is a type of `r`-dilations. You should extend this typeclass when you extend `Dilation`. -/ class DilationClass (F : Type*) (α β : outParam Type*) [PseudoEMetricSpace α] [PseudoEMetricSpace β] [FunLike F α β] : Prop where edist_eq' : ∀ f : F, ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, edist (f x) (f y) = r * edist x y end Defs namespace Dilation variable {α : Type*} {β : Type*} {γ : Type*} {F : Type*} section Setup variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] instance funLike : FunLike (α →ᵈ β) α β where coe := toFun coe_injective' f g h := by cases f; cases g; congr instance toDilationClass : DilationClass (α →ᵈ β) α β where edist_eq' f := edist_eq' f @[simp] theorem toFun_eq_coe {f : α →ᵈ β} : f.toFun = (f : α → β) := rfl @[simp] theorem coe_mk (f : α → β) (h) : ⇑(⟨f, h⟩ : α →ᵈ β) = f := rfl protected theorem congr_fun {f g : α →ᵈ β} (h : f = g) (x : α) : f x = g x := DFunLike.congr_fun h x protected theorem congr_arg (f : α →ᵈ β) {x y : α} (h : x = y) : f x = f y := DFunLike.congr_arg f h @[ext] theorem ext {f g : α →ᵈ β} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[simp] theorem mk_coe (f : α →ᵈ β) (h) : Dilation.mk f h = f := ext fun _ => rfl /-- Copy of a `Dilation` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[simps -fullyApplied] protected def copy (f : α →ᵈ β) (f' : α → β) (h : f' = ⇑f) : α →ᵈ β where toFun := f' edist_eq' := h.symm ▸ f.edist_eq' theorem copy_eq_self (f : α →ᵈ β) {f' : α → β} (h : f' = f) : f.copy f' h = f := DFunLike.ext' h variable [FunLike F α β] open Classical in /-- The ratio of a dilation `f`. If the ratio is undefined (i.e., the distance between any two points in `α` is either zero or infinity), then we choose one as the ratio. -/ def ratio [DilationClass F α β] (f : F) : ℝ≥0 := if ∀ x y : α, edist x y = 0 ∨ edist x y = ⊤ then 1 else (DilationClass.edist_eq' f).choose theorem ratio_of_trivial [DilationClass F α β] (f : F) (h : ∀ x y : α, edist x y = 0 ∨ edist x y = ∞) : ratio f = 1 := if_pos h @[nontriviality] theorem ratio_of_subsingleton [Subsingleton α] [DilationClass F α β] (f : F) : ratio f = 1 := if_pos fun x y ↦ by simp [Subsingleton.elim x y] theorem ratio_ne_zero [DilationClass F α β] (f : F) : ratio f ≠ 0 := by rw [ratio]; split_ifs · exact one_ne_zero exact (DilationClass.edist_eq' f).choose_spec.1 theorem ratio_pos [DilationClass F α β] (f : F) : 0 < ratio f := (ratio_ne_zero f).bot_lt @[simp] theorem edist_eq [DilationClass F α β] (f : F) (x y : α) : edist (f x) (f y) = ratio f * edist x y := by rw [ratio]; split_ifs with key · rcases DilationClass.edist_eq' f with ⟨r, hne, hr⟩ replace hr := hr x y rcases key x y with h | h · simp only [hr, h, mul_zero] · simp [hr, h, hne] exact (DilationClass.edist_eq' f).choose_spec.2 x y @[simp] theorem nndist_eq {α β F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β] [DilationClass F α β] (f : F) (x y : α) : nndist (f x) (f y) = ratio f * nndist x y := by simp only [← ENNReal.coe_inj, ← edist_nndist, ENNReal.coe_mul, edist_eq] @[simp] theorem dist_eq {α β F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β] [DilationClass F α β] (f : F) (x y : α) : dist (f x) (f y) = ratio f * dist x y := by simp only [dist_nndist, nndist_eq, NNReal.coe_mul] /-- The `ratio` is equal to the distance ratio for any two points with nonzero finite distance. `dist` and `nndist` versions below -/ theorem ratio_unique [DilationClass F α β] {f : F} {x y : α} {r : ℝ≥0} (h₀ : edist x y ≠ 0) (htop : edist x y ≠ ⊤) (hr : edist (f x) (f y) = r * edist x y) : r = ratio f := by simpa only [hr, ENNReal.mul_left_inj h₀ htop, ENNReal.coe_inj] using edist_eq f x y /-- The `ratio` is equal to the distance ratio for any two points with nonzero finite distance; `nndist` version -/ theorem ratio_unique_of_nndist_ne_zero {α β F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β] [DilationClass F α β] {f : F} {x y : α} {r : ℝ≥0} (hxy : nndist x y ≠ 0) (hr : nndist (f x) (f y) = r * nndist x y) : r = ratio f := ratio_unique (by rwa [edist_nndist, ENNReal.coe_ne_zero]) (edist_ne_top x y) (by rw [edist_nndist, edist_nndist, hr, ENNReal.coe_mul]) /-- The `ratio` is equal to the distance ratio for any two points with nonzero finite distance; `dist` version -/ theorem ratio_unique_of_dist_ne_zero {α β} {F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β] [DilationClass F α β] {f : F} {x y : α} {r : ℝ≥0} (hxy : dist x y ≠ 0) (hr : dist (f x) (f y) = r * dist x y) : r = ratio f := ratio_unique_of_nndist_ne_zero (NNReal.coe_ne_zero.1 hxy) <| NNReal.eq <| by rw [coe_nndist, hr, NNReal.coe_mul, coe_nndist] /-- Alternative `Dilation` constructor when the distance hypothesis is over `nndist` -/ def mkOfNNDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) (h : ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, nndist (f x) (f y) = r * nndist x y) : α →ᵈ β where toFun := f edist_eq' := by rcases h with ⟨r, hne, h⟩ refine ⟨r, hne, fun x y => ?_⟩ rw [edist_nndist, edist_nndist, ← ENNReal.coe_mul, h x y] @[simp] theorem coe_mkOfNNDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) (h) : ⇑(mkOfNNDistEq f h : α →ᵈ β) = f := rfl @[simp] theorem mk_coe_of_nndist_eq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α →ᵈ β) (h) : Dilation.mkOfNNDistEq f h = f := ext fun _ => rfl /-- Alternative `Dilation` constructor when the distance hypothesis is over `dist` -/ def mkOfDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) (h : ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, dist (f x) (f y) = r * dist x y) : α →ᵈ β := mkOfNNDistEq f <| h.imp fun r hr => ⟨hr.1, fun x y => NNReal.eq <| by rw [coe_nndist, hr.2, NNReal.coe_mul, coe_nndist]⟩ @[simp] theorem coe_mkOfDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) (h) : ⇑(mkOfDistEq f h : α →ᵈ β) = f := rfl @[simp] theorem mk_coe_of_dist_eq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α →ᵈ β) (h) : Dilation.mkOfDistEq f h = f := ext fun _ => rfl end Setup section PseudoEmetricDilation variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable [FunLike F α β] [DilationClass F α β] variable (f : F) /-- Every isometry is a dilation of ratio `1`. -/ @[simps] def _root_.Isometry.toDilation (f : α → β) (hf : Isometry f) : α →ᵈ β where toFun := f edist_eq' := ⟨1, one_ne_zero, by simpa using hf⟩ @[simp] lemma _root_.Isometry.toDilation_ratio {f : α → β} {hf : Isometry f} : ratio hf.toDilation = 1 := by by_cases! h : ∀ x y : α, edist x y = 0 ∨ edist x y = ⊤ · exact ratio_of_trivial hf.toDilation h · obtain ⟨x, y, h₁, h₂⟩ := h exact ratio_unique h₁ h₂ (by simp [hf x y]) |>.symm theorem lipschitz : LipschitzWith (ratio f) (f : α → β) := fun x y => (edist_eq f x y).le theorem antilipschitz : AntilipschitzWith (ratio f)⁻¹ (f : α → β) := fun x y => by have hr : ratio f ≠ 0 := ratio_ne_zero f exact mod_cast (ENNReal.mul_le_iff_le_inv (ENNReal.coe_ne_zero.2 hr) ENNReal.coe_ne_top).1 (edist_eq f x y).ge /-- A dilation from an emetric space is injective -/ protected theorem injective {α : Type*} [EMetricSpace α] [FunLike F α β] [DilationClass F α β] (f : F) : Injective f := (antilipschitz f).injective /-- The identity is a dilation -/ protected def id (α) [PseudoEMetricSpace α] : α →ᵈ α where toFun := id edist_eq' := ⟨1, one_ne_zero, fun x y => by simp only [id, ENNReal.coe_one, one_mul]⟩ instance : Inhabited (α →ᵈ α) := ⟨Dilation.id α⟩ @[simp] protected theorem coe_id : ⇑(Dilation.id α) = id := rfl theorem ratio_id : ratio (Dilation.id α) = 1 := by by_cases! h : ∀ x y : α, edist x y = 0 ∨ edist x y = ∞ · rw [ratio, if_pos h] · rcases h with ⟨x, y, hne⟩ refine (ratio_unique hne.1 hne.2 ?_).symm simp /-- The composition of dilations is a dilation -/ def comp (g : β →ᵈ γ) (f : α →ᵈ β) : α →ᵈ γ where toFun := g ∘ f edist_eq' := ⟨ratio g * ratio f, mul_ne_zero (ratio_ne_zero g) (ratio_ne_zero f), fun x y => by simp_rw [Function.comp, edist_eq, ENNReal.coe_mul, mul_assoc]⟩ theorem comp_assoc {δ : Type*} [PseudoEMetricSpace δ] (f : α →ᵈ β) (g : β →ᵈ γ) (h : γ →ᵈ δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[simp] theorem coe_comp (g : β →ᵈ γ) (f : α →ᵈ β) : (g.comp f : α → γ) = g ∘ f := rfl theorem comp_apply (g : β →ᵈ γ) (f : α →ᵈ β) (x : α) : (g.comp f : α → γ) x = g (f x) := rfl /-- Ratio of the composition `g.comp f` of two dilations is the product of their ratios. We assume that there exist two points in `α` at extended distance neither `0` nor `∞` because otherwise `Dilation.ratio (g.comp f) = Dilation.ratio f = 1` while `Dilation.ratio g` can be any number. This version works for most general spaces, see also `Dilation.ratio_comp` for a version assuming that `α` is a nontrivial metric space. -/ theorem ratio_comp' {g : β →ᵈ γ} {f : α →ᵈ β} (hne : ∃ x y : α, edist x y ≠ 0 ∧ edist x y ≠ ⊤) : ratio (g.comp f) = ratio g * ratio f := by rcases hne with ⟨x, y, hα⟩ have hgf := (edist_eq (g.comp f) x y).symm simp_rw [coe_comp, Function.comp, edist_eq, ← mul_assoc, ENNReal.mul_left_inj hα.1 hα.2] at hgf rwa [← ENNReal.coe_inj, ENNReal.coe_mul] @[simp] theorem comp_id (f : α →ᵈ β) : f.comp (Dilation.id α) = f := ext fun _ => rfl @[simp] theorem id_comp (f : α →ᵈ β) : (Dilation.id β).comp f = f := ext fun _ => rfl instance : Monoid (α →ᵈ α) where one := Dilation.id α mul := comp mul_one := comp_id one_mul := id_comp mul_assoc _ _ _ := comp_assoc _ _ _ theorem one_def : (1 : α →ᵈ α) = Dilation.id α := rfl theorem mul_def (f g : α →ᵈ α) : f * g = f.comp g := rfl @[simp] theorem coe_one : ⇑(1 : α →ᵈ α) = id := rfl @[simp] theorem coe_mul (f g : α →ᵈ α) : ⇑(f * g) = f ∘ g := rfl @[simp] theorem ratio_one : ratio (1 : α →ᵈ α) = 1 := ratio_id @[simp] theorem ratio_mul (f g : α →ᵈ α) : ratio (f * g) = ratio f * ratio g := by by_cases! h : ∀ x y : α, edist x y = 0 ∨ edist x y = ∞ · simp [ratio_of_trivial, h] exact ratio_comp' h /-- `Dilation.ratio` as a monoid homomorphism from `α →ᵈ α` to `ℝ≥0`. -/ @[simps] def ratioHom : (α →ᵈ α) →* ℝ≥0 := ⟨⟨ratio, ratio_one⟩, ratio_mul⟩ @[simp] theorem ratio_pow (f : α →ᵈ α) (n : ℕ) : ratio (f ^ n) = ratio f ^ n := ratioHom.map_pow _ _ @[simp] theorem cancel_right {g₁ g₂ : β →ᵈ γ} {f : α →ᵈ β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => Dilation.ext <| hf.forall.2 (Dilation.ext_iff.1 h), fun h => h ▸ rfl⟩ @[simp] theorem cancel_left {g : β →ᵈ γ} {f₁ f₂ : α →ᵈ β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => Dilation.ext fun x => hg <| by rw [← comp_apply, h, comp_apply], fun h => h ▸ rfl⟩ /-- A dilation from a metric space is a uniform inducing map -/ theorem isUniformInducing : IsUniformInducing (f : α → β) := (antilipschitz f).isUniformInducing (lipschitz f).uniformContinuous theorem tendsto_nhds_iff {ι : Type*} {g : ι → α} {a : Filter ι} {b : α} : Filter.Tendsto g a (𝓝 b) ↔ Filter.Tendsto ((f : α → β) ∘ g) a (𝓝 (f b)) := (Dilation.isUniformInducing f).isInducing.tendsto_nhds_iff /-- A dilation is continuous. -/ theorem toContinuous : Continuous (f : α → β) := (lipschitz f).continuous /-- Dilations scale the diameter by `ratio f` in pseudoemetric spaces. -/ theorem ediam_image (s : Set α) : EMetric.diam ((f : α → β) '' s) = ratio f * EMetric.diam s := by refine ((lipschitz f).ediam_image_le s).antisymm ?_ apply ENNReal.mul_le_of_le_div' rw [div_eq_mul_inv, mul_comm, ← ENNReal.coe_inv] exacts [(antilipschitz f).le_mul_ediam_image s, ratio_ne_zero f] /-- A dilation scales the diameter of the range by `ratio f`. -/ theorem ediam_range : EMetric.diam (range (f : α → β)) = ratio f * EMetric.diam (univ : Set α) := by rw [← image_univ]; exact ediam_image f univ /-- A dilation maps balls to balls and scales the radius by `ratio f`. -/ theorem mapsTo_emetric_ball (x : α) (r : ℝ≥0∞) : MapsTo (f : α → β) (EMetric.ball x r) (EMetric.ball (f x) (ratio f * r)) := fun y hy => (edist_eq f y x).trans_lt <| (ENNReal.mul_lt_mul_left (ENNReal.coe_ne_zero.2 <| ratio_ne_zero f) ENNReal.coe_ne_top).2 hy /-- A dilation maps closed balls to closed balls and scales the radius by `ratio f`. -/ theorem mapsTo_emetric_closedBall (x : α) (r' : ℝ≥0∞) : MapsTo (f : α → β) (EMetric.closedBall x r') (EMetric.closedBall (f x) (ratio f * r')) := fun y hy => (edist_eq f y x).trans_le <| by gcongr; exact hy theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] {g : γ → α} {s : Set γ} : ContinuousOn ((f : α → β) ∘ g) s ↔ ContinuousOn g s := (Dilation.isUniformInducing f).isInducing.continuousOn_iff.symm theorem comp_continuous_iff {γ} [TopologicalSpace γ] {g : γ → α} : Continuous ((f : α → β) ∘ g) ↔ Continuous g := (Dilation.isUniformInducing f).isInducing.continuous_iff.symm end PseudoEmetricDilation section EmetricDilation variable [EMetricSpace α] variable [FunLike F α β] /-- A dilation from a metric space is a uniform embedding -/ lemma isUniformEmbedding [PseudoEMetricSpace β] [DilationClass F α β] (f : F) : IsUniformEmbedding f := (antilipschitz f).isUniformEmbedding (lipschitz f).uniformContinuous /-- A dilation from a metric space is an embedding -/ theorem isEmbedding [PseudoEMetricSpace β] [DilationClass F α β] (f : F) : IsEmbedding (f : α → β) := (Dilation.isUniformEmbedding f).isEmbedding /-- A dilation from a complete emetric space is a closed embedding -/ lemma isClosedEmbedding [CompleteSpace α] [EMetricSpace β] [DilationClass F α β] (f : F) : IsClosedEmbedding f := (antilipschitz f).isClosedEmbedding (lipschitz f).uniformContinuous end EmetricDilation /-- Ratio of the composition `g.comp f` of two dilations is the product of their ratios. We assume that the domain `α` of `f` is a nontrivial metric space, otherwise `Dilation.ratio f = Dilation.ratio (g.comp f) = 1` but `Dilation.ratio g` may have any value. See also `Dilation.ratio_comp'` for a version that works for more general spaces. -/ @[simp] theorem ratio_comp [MetricSpace α] [Nontrivial α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] {g : β →ᵈ γ} {f : α →ᵈ β} : ratio (g.comp f) = ratio g * ratio f := ratio_comp' <| let ⟨x, y, hne⟩ := exists_pair_ne α; ⟨x, y, mt edist_eq_zero.1 hne, edist_ne_top _ _⟩ section PseudoMetricDilation variable [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β] [DilationClass F α β] (f : F) /-- A dilation scales the diameter by `ratio f` in pseudometric spaces. -/ theorem diam_image (s : Set α) : Metric.diam ((f : α → β) '' s) = ratio f * Metric.diam s := by simp [Metric.diam, ediam_image, ENNReal.toReal_mul] theorem diam_range : Metric.diam (range (f : α → β)) = ratio f * Metric.diam (univ : Set α) := by rw [← image_univ, diam_image] /-- A dilation maps balls to balls and scales the radius by `ratio f`. -/ theorem mapsTo_ball (x : α) (r' : ℝ) : MapsTo (f : α → β) (Metric.ball x r') (Metric.ball (f x) (ratio f * r')) := fun y hy => (dist_eq f y x).trans_lt <| by gcongr; exacts [ratio_pos _, hy] /-- A dilation maps spheres to spheres and scales the radius by `ratio f`. -/ theorem mapsTo_sphere (x : α) (r' : ℝ) : MapsTo (f : α → β) (Metric.sphere x r') (Metric.sphere (f x) (ratio f * r')) := fun y hy => Metric.mem_sphere.mp hy ▸ dist_eq f y x /-- A dilation maps closed balls to closed balls and scales the radius by `ratio f`. -/ theorem mapsTo_closedBall (x : α) (r' : ℝ) : MapsTo (f : α → β) (Metric.closedBall x r') (Metric.closedBall (f x) (ratio f * r')) := fun y hy => (dist_eq f y x).trans_le <| mul_le_mul_of_nonneg_left hy (NNReal.coe_nonneg _) lemma tendsto_cobounded : Filter.Tendsto f (cobounded α) (cobounded β) := (Dilation.antilipschitz f).tendsto_cobounded @[simp] lemma comap_cobounded : Filter.comap f (cobounded β) = cobounded α := le_antisymm (lipschitz f).comap_cobounded_le (tendsto_cobounded f).le_comap end PseudoMetricDilation end Dilation
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/ThickenedIndicator.lean
import Mathlib.Data.ENNReal.Lemmas import Mathlib.Topology.MetricSpace.Thickening import Mathlib.Topology.ContinuousMap.Bounded.Basic /-! # Thickened indicators This file is about thickened indicators of sets in (pseudo e)metric spaces. For a decreasing sequence of thickening radii tending to 0, the thickened indicators of a closed set form a decreasing pointwise converging approximation of the indicator function of the set, where the members of the approximating sequence are nonnegative bounded continuous functions. ## Main definitions * `thickenedIndicatorAux δ E`: The `δ`-thickened indicator of a set `E` as an unbundled `ℝ≥0∞`-valued function. * `thickenedIndicator δ E`: The `δ`-thickened indicator of a set `E` as a bundled bounded continuous `ℝ≥0`-valued function. ## Main results * For a sequence of thickening radii tending to 0, the `δ`-thickened indicators of a set `E` tend pointwise to the indicator of `closure E`. - `thickenedIndicatorAux_tendsto_indicator_closure`: The version is for the unbundled `ℝ≥0∞`-valued functions. - `thickenedIndicator_tendsto_indicator_closure`: The version is for the bundled `ℝ≥0`-valued bounded continuous functions. -/ open NNReal ENNReal Topology BoundedContinuousFunction Set Metric EMetric Filter noncomputable section thickenedIndicator variable {α : Type*} [PseudoEMetricSpace α] /-- The `δ`-thickened indicator of a set `E` is the function that equals `1` on `E` and `0` outside a `δ`-thickening of `E` and interpolates (continuously) between these values using `infEdist _ E`. `thickenedIndicatorAux` is the unbundled `ℝ≥0∞`-valued function. See `thickenedIndicator` for the (bundled) bounded continuous function with `ℝ≥0`-values. -/ def thickenedIndicatorAux (δ : ℝ) (E : Set α) : α → ℝ≥0∞ := fun x : α => (1 : ℝ≥0∞) - infEdist x E / ENNReal.ofReal δ theorem continuous_thickenedIndicatorAux {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : Continuous (thickenedIndicatorAux δ E) := by unfold thickenedIndicatorAux let f := fun x : α => (⟨1, infEdist x E / ENNReal.ofReal δ⟩ : ℝ≥0 × ℝ≥0∞) let sub := fun p : ℝ≥0 × ℝ≥0∞ => (p.1 : ℝ≥0∞) - p.2 rw [show (fun x : α => (1 : ℝ≥0∞) - infEdist x E / ENNReal.ofReal δ) = sub ∘ f by rfl] apply (@ENNReal.continuous_nnreal_sub 1).comp apply (ENNReal.continuous_div_const (ENNReal.ofReal δ) _).comp continuous_infEdist norm_num [δ_pos] theorem thickenedIndicatorAux_le_one (δ : ℝ) (E : Set α) (x : α) : thickenedIndicatorAux δ E x ≤ 1 := by apply tsub_le_self (α := ℝ≥0∞) @[aesop safe (rule_sets := [finiteness])] theorem thickenedIndicatorAux_lt_top {δ : ℝ} {E : Set α} {x : α} : thickenedIndicatorAux δ E x < ∞ := lt_of_le_of_lt (thickenedIndicatorAux_le_one _ _ _) one_lt_top theorem thickenedIndicatorAux_closure_eq (δ : ℝ) (E : Set α) : thickenedIndicatorAux δ (closure E) = thickenedIndicatorAux δ E := by simp +unfoldPartialApp only [thickenedIndicatorAux, infEdist_closure] theorem thickenedIndicatorAux_one (δ : ℝ) (E : Set α) {x : α} (x_in_E : x ∈ E) : thickenedIndicatorAux δ E x = 1 := by simp [thickenedIndicatorAux, infEdist_zero_of_mem x_in_E, tsub_zero] theorem thickenedIndicatorAux_one_of_mem_closure (δ : ℝ) (E : Set α) {x : α} (x_mem : x ∈ closure E) : thickenedIndicatorAux δ E x = 1 := by rw [← thickenedIndicatorAux_closure_eq, thickenedIndicatorAux_one δ (closure E) x_mem] theorem thickenedIndicatorAux_zero {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_out : x ∉ thickening δ E) : thickenedIndicatorAux δ E x = 0 := by rw [thickening, mem_setOf_eq, not_lt] at x_out unfold thickenedIndicatorAux apply le_antisymm _ bot_le have key := tsub_le_tsub (@rfl _ (1 : ℝ≥0∞)).le (ENNReal.div_le_div x_out (@rfl _ (ENNReal.ofReal δ : ℝ≥0∞)).le) rw [ENNReal.div_self (ne_of_gt (ENNReal.ofReal_pos.mpr δ_pos)) ofReal_ne_top] at key simpa [tsub_self] using key theorem thickenedIndicatorAux_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickenedIndicatorAux δ₁ E ≤ thickenedIndicatorAux δ₂ E := fun _ => tsub_le_tsub (@rfl ℝ≥0∞ 1).le (ENNReal.div_le_div rfl.le (ofReal_le_ofReal hle)) theorem indicator_le_thickenedIndicatorAux (δ : ℝ) (E : Set α) : (E.indicator fun _ => (1 : ℝ≥0∞)) ≤ thickenedIndicatorAux δ E := by intro a by_cases h : a ∈ E · simp only [h, indicator_of_mem, thickenedIndicatorAux_one δ E h, le_refl] · simp only [h, indicator_of_notMem, not_false_iff, zero_le] theorem thickenedIndicatorAux_subset (δ : ℝ) {E₁ E₂ : Set α} (subset : E₁ ⊆ E₂) : thickenedIndicatorAux δ E₁ ≤ thickenedIndicatorAux δ E₂ := fun _ => tsub_le_tsub (@rfl ℝ≥0∞ 1).le (ENNReal.div_le_div (infEdist_anti subset) rfl.le) lemma thickenedIndicatorAux_mono_infEdist (δ : ℝ) {E : Set α} {x y : α} (h : infEdist x E ≤ infEdist y E) : thickenedIndicatorAux δ E y ≤ thickenedIndicatorAux δ E x := by simp only [thickenedIndicatorAux] rcases le_total (infEdist x E / ENNReal.ofReal δ) 1 with hle | hle · rw [ENNReal.sub_le_sub_iff_left hle (by simp)] gcongr · rw [tsub_eq_zero_of_le hle, tsub_eq_zero_of_le] exact hle.trans (by gcongr) /-- As the thickening radius δ tends to 0, the δ-thickened indicator of a set E (in α) tends pointwise (i.e., w.r.t. the product topology on `α → ℝ≥0∞`) to the indicator function of the closure of E. This statement is for the unbundled `ℝ≥0∞`-valued functions `thickenedIndicatorAux δ E`, see `thickenedIndicator_tendsto_indicator_closure` for the version for bundled `ℝ≥0`-valued bounded continuous functions. -/ theorem thickenedIndicatorAux_tendsto_indicator_closure {δseq : ℕ → ℝ} (δseq_lim : Tendsto δseq atTop (𝓝 0)) (E : Set α) : Tendsto (fun n => thickenedIndicatorAux (δseq n) E) atTop (𝓝 (indicator (closure E) fun _ => (1 : ℝ≥0∞))) := by rw [tendsto_pi_nhds] intro x by_cases x_mem_closure : x ∈ closure E · simp_rw [thickenedIndicatorAux_one_of_mem_closure _ E x_mem_closure] rw [show (indicator (closure E) fun _ => (1 : ℝ≥0∞)) x = 1 by simp only [x_mem_closure, indicator_of_mem]] exact tendsto_const_nhds · rw [show (closure E).indicator (fun _ => (1 : ℝ≥0∞)) x = 0 by simp only [x_mem_closure, indicator_of_notMem, not_false_iff]] rcases exists_real_pos_lt_infEdist_of_notMem_closure x_mem_closure with ⟨ε, ⟨ε_pos, ε_lt⟩⟩ rw [Metric.tendsto_nhds] at δseq_lim specialize δseq_lim ε ε_pos simp only [dist_zero_right, Real.norm_eq_abs, eventually_atTop] at δseq_lim rcases δseq_lim with ⟨N, hN⟩ apply tendsto_atTop_of_eventually_const (i₀ := N) intro n n_large have key : x ∉ thickening ε E := by simpa only [thickening, mem_setOf_eq, not_lt] using ε_lt.le refine le_antisymm ?_ bot_le apply (thickenedIndicatorAux_mono (lt_of_abs_lt (hN n n_large)).le E x).trans exact (thickenedIndicatorAux_zero ε_pos E key).le /-- The `δ`-thickened indicator of a set `E` is the function that equals `1` on `E` and `0` outside a `δ`-thickening of `E` and interpolates (continuously) between these values using `infEdist _ E`. `thickenedIndicator` is the (bundled) bounded continuous function with `ℝ≥0`-values. See `thickenedIndicatorAux` for the unbundled `ℝ≥0∞`-valued function. -/ @[simps] def thickenedIndicator {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : α →ᵇ ℝ≥0 where toFun := fun x : α => (thickenedIndicatorAux δ E x).toNNReal continuous_toFun := by apply ContinuousOn.comp_continuous continuousOn_toNNReal (continuous_thickenedIndicatorAux δ_pos E) intro x exact (lt_of_le_of_lt (@thickenedIndicatorAux_le_one _ _ δ E x) one_lt_top).ne map_bounded' := by use 2 intro x y rw [NNReal.dist_eq] apply (abs_sub _ _).trans rw [NNReal.abs_eq, NNReal.abs_eq, ← one_add_one_eq_two] have key := @thickenedIndicatorAux_le_one _ _ δ E apply add_le_add <;> · norm_cast exact (toNNReal_le_toNNReal (lt_of_le_of_lt (key _) one_lt_top).ne one_ne_top).mpr (key _) theorem thickenedIndicator.coeFn_eq_comp {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : ⇑(thickenedIndicator δ_pos E) = ENNReal.toNNReal ∘ thickenedIndicatorAux δ E := rfl theorem thickenedIndicator_le_one {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) (x : α) : thickenedIndicator δ_pos E x ≤ 1 := by rw [thickenedIndicator.coeFn_eq_comp] simpa using (toNNReal_le_toNNReal (by finiteness) one_ne_top).mpr (thickenedIndicatorAux_le_one δ E x) theorem thickenedIndicator_one_of_mem_closure {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_mem : x ∈ closure E) : thickenedIndicator δ_pos E x = 1 := by rw [thickenedIndicator_apply, thickenedIndicatorAux_one_of_mem_closure δ E x_mem, toNNReal_one] lemma one_le_thickenedIndicator_apply' {X : Type _} [PseudoEMetricSpace X] {δ : ℝ} (δ_pos : 0 < δ) {F : Set X} {x : X} (hxF : x ∈ closure F) : 1 ≤ thickenedIndicator δ_pos F x := by rw [thickenedIndicator_one_of_mem_closure δ_pos F hxF] lemma one_le_thickenedIndicator_apply (X : Type _) [PseudoEMetricSpace X] {δ : ℝ} (δ_pos : 0 < δ) {F : Set X} {x : X} (hxF : x ∈ F) : 1 ≤ thickenedIndicator δ_pos F x := one_le_thickenedIndicator_apply' δ_pos (subset_closure hxF) theorem thickenedIndicator_one {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_in_E : x ∈ E) : thickenedIndicator δ_pos E x = 1 := thickenedIndicator_one_of_mem_closure _ _ (subset_closure x_in_E) theorem thickenedIndicator_zero {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) {x : α} (x_out : x ∉ thickening δ E) : thickenedIndicator δ_pos E x = 0 := by rw [thickenedIndicator_apply, thickenedIndicatorAux_zero δ_pos E x_out, toNNReal_zero] theorem indicator_le_thickenedIndicator {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : (E.indicator fun _ => (1 : ℝ≥0)) ≤ thickenedIndicator δ_pos E := by intro a by_cases h : a ∈ E · simp only [h, indicator_of_mem, thickenedIndicator_one δ_pos E h, le_refl] · simp only [h, indicator_of_notMem, not_false_iff, zero_le] theorem thickenedIndicator_mono {δ₁ δ₂ : ℝ} (δ₁_pos : 0 < δ₁) (δ₂_pos : 0 < δ₂) (hle : δ₁ ≤ δ₂) (E : Set α) : ⇑(thickenedIndicator δ₁_pos E) ≤ thickenedIndicator δ₂_pos E := by intro x apply (toNNReal_le_toNNReal (by finiteness) (by finiteness)).mpr apply thickenedIndicatorAux_mono hle theorem thickenedIndicator_subset {δ : ℝ} (δ_pos : 0 < δ) {E₁ E₂ : Set α} (subset : E₁ ⊆ E₂) : ⇑(thickenedIndicator δ_pos E₁) ≤ thickenedIndicator δ_pos E₂ := fun x => (toNNReal_le_toNNReal (by finiteness) (by finiteness)).mpr (thickenedIndicatorAux_subset δ subset x) @[gcongr] lemma thickenedIndicator_mono_infEdist {δ : ℝ} (δ_pos : 0 < δ) {E : Set α} {x y : α} (h : infEdist x E ≤ infEdist y E) : thickenedIndicator δ_pos E y ≤ thickenedIndicator δ_pos E x := by simp only [thickenedIndicator_apply] gcongr · finiteness · exact thickenedIndicatorAux_mono_infEdist δ h /-- As the thickening radius δ tends to 0, the δ-thickened indicator of a set E (in α) tends pointwise to the indicator function of the closure of E. Note: This version is for the bundled bounded continuous functions, but the topology is not the topology on `α →ᵇ ℝ≥0`. Coercions to functions `α → ℝ≥0` are done first, so the topology instance is the product topology (the topology of pointwise convergence). -/ theorem thickenedIndicator_tendsto_indicator_closure {δseq : ℕ → ℝ} (δseq_pos : ∀ n, 0 < δseq n) (δseq_lim : Tendsto δseq atTop (𝓝 0)) (E : Set α) : Tendsto (fun n : ℕ => ((↑) : (α →ᵇ ℝ≥0) → α → ℝ≥0) (thickenedIndicator (δseq_pos n) E)) atTop (𝓝 (indicator (closure E) fun _ => (1 : ℝ≥0))) := by have key := thickenedIndicatorAux_tendsto_indicator_closure δseq_lim E rw [tendsto_pi_nhds] at * intro x rw [show indicator (closure E) (fun _ => (1 : ℝ≥0)) x = (indicator (closure E) (fun _ => (1 : ℝ≥0∞)) x).toNNReal by refine (congr_fun (comp_indicator_const 1 ENNReal.toNNReal toNNReal_zero) x).symm] refine Tendsto.comp (tendsto_toNNReal ?_) (key x) by_cases x_mem : x ∈ closure E <;> simp [x_mem] lemma lipschitzWith_thickenedIndicator {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : LipschitzWith δ.toNNReal⁻¹ (thickenedIndicator δ_pos E) := by intro x y wlog h : infEdist x E ≤ infEdist y E generalizing x y · specialize this y x (le_of_not_ge h) rwa [edist_comm, edist_comm x] simp_rw [edist_dist, NNReal.dist_eq, thickenedIndicator_apply, coe_toNNReal_eq_toReal] rw [← ENNReal.toReal_sub_of_le (thickenedIndicatorAux_mono_infEdist _ h) (by finiteness)] simp only [thickenedIndicatorAux, abs_toReal, ne_eq, sub_eq_top_iff, one_ne_top, false_and, not_false_eq_true, and_true, ofReal_toReal] rw [ENNReal.coe_inv (by simp [δ_pos]), ENNReal.ofReal, div_eq_mul_inv, div_eq_mul_inv] by_cases h_le : infEdist y E * (↑δ.toNNReal)⁻¹ ≤ 1 · calc 1 - infEdist x E * (↑δ.toNNReal)⁻¹ - (1 - infEdist y E * (↑δ.toNNReal)⁻¹) _ ≤ infEdist y E * (↑δ.toNNReal)⁻¹ - infEdist x E * (↑δ.toNNReal)⁻¹ := by rw [ENNReal.sub_sub_sub_cancel_left (by finiteness) h_le] _ ≤ (↑δ.toNNReal)⁻¹ * edist x y := by rw [← ENNReal.sub_mul (by simp [δ_pos]), mul_comm, edist_comm] gcongr simp only [tsub_le_iff_right] exact infEdist_le_edist_add_infEdist · simp only [tsub_le_iff_right] rw [tsub_eq_zero_of_le (not_le.mp h_le).le, add_zero, mul_comm] calc 1 _ ≤ infEdist y E * (↑δ.toNNReal)⁻¹ := (not_le.mp h_le).le _ ≤ edist x y * (↑δ.toNNReal)⁻¹ + infEdist x E * (↑δ.toNNReal)⁻¹ := by rw [← add_mul, edist_comm] gcongr exact infEdist_le_edist_add_infEdist end thickenedIndicator section indicator variable {α : Type*} [PseudoEMetricSpace α] {β : Type*} [One β] /-- Pointwise, the multiplicative indicators of δ-thickenings of a set eventually coincide with the multiplicative indicator of the set as δ>0 tends to zero. -/ @[to_additive /-- Pointwise, the indicators of δ-thickenings of a set eventually coincide with the indicator of the set as δ>0 tends to zero. -/] lemma mulIndicator_thickening_eventually_eq_mulIndicator_closure (f : α → β) (E : Set α) (x : α) : ∀ᶠ δ in 𝓝[>] (0 : ℝ), (Metric.thickening δ E).mulIndicator f x = (closure E).mulIndicator f x := by by_cases x_mem_closure : x ∈ closure E · filter_upwards [self_mem_nhdsWithin] with δ δ_pos simp only [closure_subset_thickening δ_pos E x_mem_closure, mulIndicator_of_mem, x_mem_closure] · have obs := eventually_notMem_thickening_of_infEdist_pos x_mem_closure filter_upwards [mem_nhdsWithin_of_mem_nhds obs, self_mem_nhdsWithin] with δ x_notin_thE _ simp only [x_notin_thE, not_false_eq_true, mulIndicator_of_notMem, x_mem_closure] /-- Pointwise, the multiplicative indicators of closed δ-thickenings of a set eventually coincide with the multiplicative indicator of the set as δ tends to zero. -/ @[to_additive /-- Pointwise, the indicators of closed δ-thickenings of a set eventually coincide with the indicator of the set as δ tends to zero. -/] lemma mulIndicator_cthickening_eventually_eq_mulIndicator_closure (f : α → β) (E : Set α) (x : α) : ∀ᶠ δ in 𝓝 (0 : ℝ), (Metric.cthickening δ E).mulIndicator f x = (closure E).mulIndicator f x := by by_cases x_mem_closure : x ∈ closure E · filter_upwards [univ_mem] with δ _ have obs : x ∈ cthickening δ E := closure_subset_cthickening δ E x_mem_closure rw [mulIndicator_of_mem obs f, mulIndicator_of_mem x_mem_closure f] · filter_upwards [eventually_notMem_cthickening_of_infEdist_pos x_mem_closure] with δ hδ simp only [hδ, not_false_eq_true, mulIndicator_of_notMem, x_mem_closure] variable [TopologicalSpace β] /-- The multiplicative indicators of δ-thickenings of a set tend pointwise to the multiplicative indicator of the set, as δ>0 tends to zero. -/ @[to_additive /-- The indicators of δ-thickenings of a set tend pointwise to the indicator of the set, as δ>0 tends to zero. -/] lemma tendsto_mulIndicator_thickening_mulIndicator_closure (f : α → β) (E : Set α) : Tendsto (fun δ ↦ (Metric.thickening δ E).mulIndicator f) (𝓝[>] 0) (𝓝 ((closure E).mulIndicator f)) := by rw [tendsto_pi_nhds] intro x rw [tendsto_congr' (mulIndicator_thickening_eventually_eq_mulIndicator_closure f E x)] apply tendsto_const_nhds /-- The multiplicative indicators of closed δ-thickenings of a set tend pointwise to the multiplicative indicator of the set, as δ tends to zero. -/ @[to_additive /-- The indicators of closed δ-thickenings of a set tend pointwise to the indicator of the set, as δ tends to zero. -/] lemma tendsto_mulIndicator_cthickening_mulIndicator_closure (f : α → β) (E : Set α) : Tendsto (fun δ ↦ (Metric.cthickening δ E).mulIndicator f) (𝓝 0) (𝓝 ((closure E).mulIndicator f)) := by rw [tendsto_pi_nhds] intro x rw [tendsto_congr' (mulIndicator_cthickening_eventually_eq_mulIndicator_closure f E x)] apply tendsto_const_nhds end indicator
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Infsep.lean
import Mathlib.Topology.MetricSpace.Basic /-! # Infimum separation This file defines the extended infimum separation of a set. This is approximately dual to the diameter of a set, but where the extended diameter of a set is the supremum of the extended distance between elements of the set, the extended infimum separation is the infimum of the (extended) distance between *distinct* elements in the set. We also define the infimum separation as the cast of the extended infimum separation to the reals. This is the infimum of the distance between distinct elements of the set when in a pseudometric space. All lemmas and definitions are in the `Set` namespace to give access to dot notation. ## Main definitions * `Set.einfsep`: Extended infimum separation of a set. * `Set.infsep`: Infimum separation of a set (when in a pseudometric space). -/ variable {α β : Type*} namespace Set section Einfsep open ENNReal open Function /-- The "extended infimum separation" of a set with an edist function. -/ noncomputable def einfsep [EDist α] (s : Set α) : ℝ≥0∞ := ⨅ (x ∈ s) (y ∈ s) (_ : x ≠ y), edist x y section EDist variable [EDist α] {x y : α} {s t : Set α} theorem le_einfsep_iff {d} : d ≤ s.einfsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y := by simp_rw [einfsep, le_iInf_iff] theorem einfsep_zero : s.einfsep = 0 ↔ ∀ C > 0, ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < C := by simp_rw [einfsep, ← _root_.bot_eq_zero, iInf_eq_bot, iInf_lt_iff, exists_prop] theorem einfsep_pos : 0 < s.einfsep ↔ ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by rw [pos_iff_ne_zero, Ne, einfsep_zero] simp only [not_forall, not_exists, not_lt, exists_prop, not_and] theorem einfsep_top : s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by simp_rw [einfsep, iInf_eq_top] theorem einfsep_lt_top : s.einfsep < ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < ∞ := by simp_rw [einfsep, iInf_lt_iff, exists_prop] theorem einfsep_ne_top : s.einfsep ≠ ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y ≠ ∞ := by simp_rw [← lt_top_iff_ne_top, einfsep_lt_top] theorem einfsep_lt_iff {d} : s.einfsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < d := by simp_rw [einfsep, iInf_lt_iff, exists_prop] theorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.Nontrivial := by rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩ exact ⟨_, hx, _, hy, hxy⟩ theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial := nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs) theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by rw [einfsep_top] exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim theorem le_einfsep_image_iff {d} {f : β → α} {s : Set β} : d ≤ einfsep (f '' s) ↔ ∀ x ∈ s, ∀ y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) := by simp_rw [le_einfsep_iff, forall_mem_image] theorem le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hd : d ≤ s.einfsep) : d ≤ edist x y := le_einfsep_iff.1 hd x hx y hy hxy theorem einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) : s.einfsep ≤ edist x y := le_edist_of_le_einfsep hx hy hxy le_rfl theorem einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hxy' : edist x y ≤ d) : s.einfsep ≤ d := le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy' theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep := le_einfsep_iff.2 h @[simp] theorem einfsep_empty : (∅ : Set α).einfsep = ∞ := subsingleton_empty.einfsep @[simp] theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ := subsingleton_singleton.einfsep theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) : (⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp theorem einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep := le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy) theorem einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (_ : x ≠ y), edist x y := by simp_rw [le_iInf_iff] exact fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy theorem le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : Set α).einfsep := by simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff] rintro a (rfl | rfl) b (rfl | rfl) hab <;> (try simp only [le_refl, true_or, or_true]) <;> contradiction theorem einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist x y := einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy theorem einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist y x := by rw [pair_comm]; exact einfsep_pair_le_left hxy.symm theorem einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y ⊓ edist y x := le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair theorem einfsep_eq_iInf : s.einfsep = ⨅ d : s.offDiag, (uncurry edist) (d : α × α) := by refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, le_iInf_iff, imp_forall_iff, SetCoe.forall, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] theorem einfsep_of_fintype [DecidableEq α] [Fintype s] : s.einfsep = s.offDiag.toFinset.inf (uncurry edist) := by refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] theorem Finite.einfsep (hs : s.Finite) : s.einfsep = hs.offDiag.toFinset.inf (uncurry edist) := by refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, Finite.mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] theorem Finset.coe_einfsep [DecidableEq α] {s : Finset α} : (s : Set α).einfsep = s.offDiag.inf (uncurry edist) := by simp_rw [einfsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe] theorem Nontrivial.einfsep_exists_of_finite [Finite s] (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y := by classical cases nonempty_fintype s simp_rw [einfsep_of_fintype] rcases Finset.exists_mem_eq_inf s.offDiag.toFinset (by simpa) (uncurry edist) with ⟨w, hxy, hed⟩ simp_rw [mem_toFinset] at hxy exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩ theorem Finite.einfsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y := letI := hsf.fintype hs.einfsep_exists_of_finite end EDist section PseudoEMetricSpace variable [PseudoEMetricSpace α] {x y z : α} {s : Set α} theorem einfsep_pair (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y := by nth_rw 1 [← min_self (edist x y)] convert einfsep_pair_eq_inf hxy using 2 rw [edist_comm] theorem einfsep_insert : einfsep (insert x s) = (⨅ (y ∈ s) (_ : x ≠ y), edist x y) ⊓ s.einfsep := by refine le_antisymm (le_min einfsep_insert_le (einfsep_anti (subset_insert _ _))) ?_ simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff] rintro y (rfl | hy) z (rfl | hz) hyz · exact False.elim (hyz rfl) · exact Or.inl (iInf_le_of_le _ (iInf₂_le hz hyz)) · rw [edist_comm] exact Or.inl (iInf_le_of_le _ (iInf₂_le hy hyz.symm)) · exact Or.inr (einfsep_le_edist_of_mem hy hz hyz) theorem einfsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) : einfsep ({x, y, z} : Set α) = edist x y ⊓ edist x z ⊓ edist y z := by simp_rw [einfsep_insert, iInf_insert, iInf_singleton, einfsep_singleton, inf_top_eq, ciInf_pos hxy, ciInf_pos hyz, ciInf_pos hxz] theorem le_einfsep_pi_of_le {X : β → Type*} [Fintype β] [∀ b, PseudoEMetricSpace (X b)] {s : ∀ b : β, Set (X b)} {c : ℝ≥0∞} (h : ∀ b, c ≤ einfsep (s b)) : c ≤ einfsep (Set.pi univ s) := by refine le_einfsep fun x hx y hy hxy => ?_ rw [mem_univ_pi] at hx hy rcases Function.ne_iff.mp hxy with ⟨i, hi⟩ exact le_trans (le_einfsep_iff.1 (h i) _ (hx _) _ (hy _) hi) (edist_le_pi_edist _ _ i) end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] {s : Set α} theorem subsingleton_of_einfsep_eq_top (hs : s.einfsep = ∞) : s.Subsingleton := by rw [einfsep_top] at hs exact fun _ hx _ hy => of_not_not fun hxy => edist_ne_top _ _ (hs _ hx _ hy hxy) theorem einfsep_eq_top_iff : s.einfsep = ∞ ↔ s.Subsingleton := ⟨subsingleton_of_einfsep_eq_top, Subsingleton.einfsep⟩ theorem Nontrivial.einfsep_ne_top (hs : s.Nontrivial) : s.einfsep ≠ ∞ := by contrapose! hs exact subsingleton_of_einfsep_eq_top hs theorem Nontrivial.einfsep_lt_top (hs : s.Nontrivial) : s.einfsep < ∞ := by rw [lt_top_iff_ne_top] exact hs.einfsep_ne_top theorem einfsep_lt_top_iff : s.einfsep < ∞ ↔ s.Nontrivial := ⟨nontrivial_of_einfsep_lt_top, Nontrivial.einfsep_lt_top⟩ theorem einfsep_ne_top_iff : s.einfsep ≠ ∞ ↔ s.Nontrivial := ⟨nontrivial_of_einfsep_ne_top, Nontrivial.einfsep_ne_top⟩ theorem le_einfsep_of_forall_dist_le {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y) : ENNReal.ofReal d ≤ s.einfsep := le_einfsep fun x hx y hy hxy => (edist_dist x y).symm ▸ ENNReal.ofReal_le_ofReal (h x hx y hy hxy) end PseudoMetricSpace section EMetricSpace variable [EMetricSpace α] {s : Set α} theorem einfsep_pos_of_finite [Finite s] : 0 < s.einfsep := by cases nonempty_fintype s by_cases hs : s.Nontrivial · rcases hs.einfsep_exists_of_finite with ⟨x, _hx, y, _hy, hxy, hxy'⟩ exact hxy'.symm ▸ edist_pos.2 hxy · rw [not_nontrivial_iff] at hs exact hs.einfsep.symm ▸ WithTop.top_pos theorem relatively_discrete_of_finite [Finite s] : ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by rw [← einfsep_pos] exact einfsep_pos_of_finite theorem Finite.einfsep_pos (hs : s.Finite) : 0 < s.einfsep := letI := hs.fintype einfsep_pos_of_finite theorem Finite.relatively_discrete (hs : s.Finite) : ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := letI := hs.fintype relatively_discrete_of_finite end EMetricSpace end Einfsep section Infsep open ENNReal open Set Function /-- The "infimum separation" of a set with an edist function. -/ noncomputable def infsep [EDist α] (s : Set α) : ℝ := ENNReal.toReal s.einfsep section EDist variable [EDist α] {x y : α} {s : Set α} theorem infsep_zero : s.infsep = 0 ↔ s.einfsep = 0 ∨ s.einfsep = ∞ := by rw [infsep, ENNReal.toReal_eq_zero_iff] theorem infsep_nonneg : 0 ≤ s.infsep := ENNReal.toReal_nonneg theorem infsep_pos : 0 < s.infsep ↔ 0 < s.einfsep ∧ s.einfsep < ∞ := by simp_rw [infsep, ENNReal.toReal_pos_iff] theorem Subsingleton.infsep_zero (hs : s.Subsingleton) : s.infsep = 0 := Set.infsep_zero.mpr <| Or.inr hs.einfsep theorem nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.Nontrivial := by contrapose hs rw [not_nontrivial_iff] at hs exact hs.infsep_zero ▸ lt_irrefl _ theorem infsep_empty : (∅ : Set α).infsep = 0 := subsingleton_empty.infsep_zero theorem infsep_singleton : ({x} : Set α).infsep = 0 := subsingleton_singleton.infsep_zero theorem infsep_pair_le_toReal_inf (hxy : x ≠ y) : ({x, y} : Set α).infsep ≤ (edist x y ⊓ edist y x).toReal := by simp_rw [infsep, einfsep_pair_eq_inf hxy] simp end EDist section PseudoEMetricSpace variable [PseudoEMetricSpace α] {x y : α} theorem infsep_pair_eq_toReal : ({x, y} : Set α).infsep = (edist x y).toReal := by by_cases hxy : x = y · rw [hxy] simp only [infsep_singleton, pair_eq_singleton, edist_self, ENNReal.toReal_zero] · rw [infsep, einfsep_pair hxy] end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] {x y z : α} {s t : Set α} theorem Nontrivial.le_infsep_iff {d} (hs : s.Nontrivial) : d ≤ s.infsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y := by simp_rw [infsep, ← ENNReal.ofReal_le_iff_le_toReal hs.einfsep_ne_top, le_einfsep_iff, edist_dist, ENNReal.ofReal_le_ofReal_iff dist_nonneg] theorem Nontrivial.infsep_lt_iff {d} (hs : s.Nontrivial) : s.infsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ dist x y < d := by rw [← not_iff_not] push_neg exact hs.le_infsep_iff theorem Nontrivial.le_infsep {d} (hs : s.Nontrivial) (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y) : d ≤ s.infsep := hs.le_infsep_iff.2 h theorem le_edist_of_le_infsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hd : d ≤ s.infsep) : d ≤ dist x y := by by_cases hs : s.Nontrivial · exact hs.le_infsep_iff.1 hd x hx y hy hxy · rw [not_nontrivial_iff] at hs rw [hs.infsep_zero] at hd exact le_trans hd dist_nonneg theorem infsep_le_dist_of_mem (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : s.infsep ≤ dist x y := le_edist_of_le_infsep hx hy hxy le_rfl theorem infsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hxy' : dist x y ≤ d) : s.infsep ≤ d := le_trans (infsep_le_dist_of_mem hx hy hxy) hxy' theorem infsep_pair : ({x, y} : Set α).infsep = dist x y := by rw [infsep_pair_eq_toReal, edist_dist] exact ENNReal.toReal_ofReal dist_nonneg theorem infsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) : ({x, y, z} : Set α).infsep = dist x y ⊓ dist x z ⊓ dist y z := by simp only [infsep, einfsep_triple hxy hyz hxz, ENNReal.toReal_inf, edist_ne_top x y, edist_ne_top x z, edist_ne_top y z, dist_edist, Ne, inf_eq_top_iff, and_self_iff, not_false_iff] theorem Nontrivial.infsep_anti (hs : s.Nontrivial) (hst : s ⊆ t) : t.infsep ≤ s.infsep := ENNReal.toReal_mono hs.einfsep_ne_top (einfsep_anti hst) theorem infsep_eq_iInf [Decidable s.Nontrivial] : s.infsep = if s.Nontrivial then ⨅ d : s.offDiag, (uncurry dist) (d : α × α) else 0 := by split_ifs with hs · have hb : BddBelow (uncurry dist '' s.offDiag) := by refine ⟨0, fun d h => ?_⟩ simp_rw [mem_image, Prod.exists, uncurry_apply_pair] at h rcases h with ⟨_, _, _, rfl⟩ exact dist_nonneg refine eq_of_forall_le_iff fun _ => ?_ simp_rw [hs.le_infsep_iff, le_ciInf_set_iff (offDiag_nonempty.mpr hs) hb, imp_forall_iff, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] · exact (not_nontrivial_iff.mp hs).infsep_zero theorem Nontrivial.infsep_eq_iInf (hs : s.Nontrivial) : s.infsep = ⨅ d : s.offDiag, (uncurry dist) (d : α × α) := by classical rw [Set.infsep_eq_iInf, if_pos hs] theorem infsep_of_fintype [Decidable s.Nontrivial] [DecidableEq α] [Fintype s] : s.infsep = if hs : s.Nontrivial then s.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by split_ifs with hs · refine eq_of_forall_le_iff fun _ => ?_ simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] · rw [not_nontrivial_iff] at hs exact hs.infsep_zero theorem Nontrivial.infsep_of_fintype [DecidableEq α] [Fintype s] (hs : s.Nontrivial) : s.infsep = s.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by classical rw [Set.infsep_of_fintype, dif_pos hs] theorem Finite.infsep [Decidable s.Nontrivial] (hsf : s.Finite) : s.infsep = if hs : s.Nontrivial then hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by split_ifs with hs · refine eq_of_forall_le_iff fun _ => ?_ simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, Finite.mem_toFinset, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp] · rw [not_nontrivial_iff] at hs exact hs.infsep_zero theorem Finite.infsep_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) : s.infsep = hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by classical simp_rw [hsf.infsep, dif_pos hs] theorem _root_.Finset.coe_infsep [DecidableEq α] (s : Finset α) : (s : Set α).infsep = if hs : s.offDiag.Nonempty then s.offDiag.inf' hs (uncurry dist) else 0 := by have H : (s : Set α).Nontrivial ↔ s.offDiag.Nonempty := by rw [← Set.offDiag_nonempty, ← Finset.coe_offDiag, Finset.coe_nonempty] split_ifs with hs · simp_rw [(H.mpr hs).infsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe] · exact (not_nontrivial_iff.mp (H.mp.mt hs)).infsep_zero theorem _root_.Finset.coe_infsep_of_offDiag_nonempty [DecidableEq α] {s : Finset α} (hs : s.offDiag.Nonempty) : (s : Set α).infsep = s.offDiag.inf' hs (uncurry dist) := by rw [Finset.coe_infsep, dif_pos hs] theorem _root_.Finset.coe_infsep_of_offDiag_empty [DecidableEq α] {s : Finset α} (hs : s.offDiag = ∅) : (s : Set α).infsep = 0 := by rw [← Finset.not_nonempty_iff_eq_empty] at hs rw [Finset.coe_infsep, dif_neg hs] theorem Nontrivial.infsep_exists_of_finite [Finite s] (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.infsep = dist x y := by classical cases nonempty_fintype s simp_rw [hs.infsep_of_fintype] rcases Finset.exists_mem_eq_inf' (s := s.offDiag.toFinset) (by simpa) (uncurry dist) with ⟨w, hxy, hed⟩ simp_rw [mem_toFinset] at hxy exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩ theorem Finite.infsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.infsep = dist x y := letI := hsf.fintype hs.infsep_exists_of_finite end PseudoMetricSpace section MetricSpace variable [MetricSpace α] {s : Set α} theorem infsep_zero_iff_subsingleton_of_finite [Finite s] : s.infsep = 0 ↔ s.Subsingleton := by rw [infsep_zero, einfsep_eq_top_iff, or_iff_right_iff_imp] exact fun H => (einfsep_pos_of_finite.ne' H).elim theorem infsep_pos_iff_nontrivial_of_finite [Finite s] : 0 < s.infsep ↔ s.Nontrivial := by rw [infsep_pos, einfsep_lt_top_iff, and_iff_right_iff_imp] exact fun _ => einfsep_pos_of_finite theorem Finite.infsep_zero_iff_subsingleton (hs : s.Finite) : s.infsep = 0 ↔ s.Subsingleton := letI := hs.fintype infsep_zero_iff_subsingleton_of_finite theorem Finite.infsep_pos_iff_nontrivial (hs : s.Finite) : 0 < s.infsep ↔ s.Nontrivial := letI := hs.fintype infsep_pos_iff_nontrivial_of_finite theorem _root_.Finset.infsep_zero_iff_subsingleton (s : Finset α) : (s : Set α).infsep = 0 ↔ (s : Set α).Subsingleton := infsep_zero_iff_subsingleton_of_finite theorem _root_.Finset.infsep_pos_iff_nontrivial (s : Finset α) : 0 < (s : Set α).infsep ↔ (s : Set α).Nontrivial := infsep_pos_iff_nontrivial_of_finite end MetricSpace end Infsep end Set
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/HolderNorm.lean
import Mathlib.Topology.MetricSpace.Holder /-! # Hölder norm This file defines the Hölder (semi-)norm for Hölder functions alongside some basic properties. The `r`-Hölder norm of a function `f : X → Y` between two metric spaces is the least non-negative real number `C` for which `f` is `r`-Hölder continuous with constant `C`, i.e. it is the least `C` for which `WithHolder C r f` is true. ## Main definitions * `eHolderNorm r f`: `r`-Hölder (semi-)norm in `ℝ≥0∞` of a function `f`. * `nnHolderNorm r f`: `r`-Hölder (semi-)norm in `ℝ≥0` of a function `f`. * `MemHolder r f`: Predicate for a function `f` being `r`-Hölder continuous. ## Main results * `eHolderNorm_eq_zero`: the Hölder norm of a function is zero if and only if it is constant. * `MemHolder.holderWith`: The Hölder norm of a Hölder function `f` is a Hölder constant of `f`. ## Tags Hölder norm, Hoelder norm, Holder norm -/ variable {X Y : Type*} open Filter Set open NNReal ENNReal Topology section PseudoEMetricSpace variable [PseudoEMetricSpace X] [PseudoEMetricSpace Y] {r : ℝ≥0} {f : X → Y} /-- The `r`-Hölder (semi-)norm in `ℝ≥0∞` of a function `f` is the least non-negative real number `C` for which `f` is `r`-Hölder continuous with constant `C`. This is `∞` if no such non-negative real exists. -/ noncomputable def eHolderNorm (r : ℝ≥0) (f : X → Y) : ℝ≥0∞ := ⨅ (C) (_ : HolderWith C r f), C /-- The `r`-Hölder (semi)norm in `ℝ≥0`. -/ noncomputable def nnHolderNorm (r : ℝ≥0) (f : X → Y) : ℝ≥0 := (eHolderNorm r f).toNNReal /-- A function `f` is `MemHolder r f` if it is Hölder continuous. Namely, `f` has a finite `r`-Hölder constant. This is equivalent to `f` having finite Hölder norm. c.f. `memHolder_iff`. -/ def MemHolder (r : ℝ≥0) (f : X → Y) : Prop := ∃ C, HolderWith C r f lemma HolderWith.memHolder {C : ℝ≥0} (hf : HolderWith C r f) : MemHolder r f := ⟨C, hf⟩ @[simp] lemma eHolderNorm_lt_top : eHolderNorm r f < ∞ ↔ MemHolder r f := by refine ⟨fun h => ?_, fun hf => let ⟨C, hC⟩ := hf; iInf_lt_top.2 ⟨C, iInf_lt_top.2 ⟨hC, coe_lt_top⟩⟩⟩ simp_rw [eHolderNorm, iInf_lt_top] at h let ⟨C, hC, _⟩ := h exact ⟨C, hC⟩ lemma eHolderNorm_ne_top : eHolderNorm r f ≠ ∞ ↔ MemHolder r f := by rw [← eHolderNorm_lt_top, lt_top_iff_ne_top] @[simp] lemma eHolderNorm_eq_top : eHolderNorm r f = ∞ ↔ ¬ MemHolder r f := by rw [← eHolderNorm_ne_top, not_not] protected alias ⟨_, MemHolder.eHolderNorm_lt_top⟩ := eHolderNorm_lt_top protected alias ⟨_, MemHolder.eHolderNorm_ne_top⟩ := eHolderNorm_ne_top lemma coe_nnHolderNorm_le_eHolderNorm {r : ℝ≥0} {f : X → Y} : (nnHolderNorm r f : ℝ≥0∞) ≤ eHolderNorm r f := coe_toNNReal_le_self variable (X) in @[simp] lemma eHolderNorm_const (r : ℝ≥0) (c : Y) : eHolderNorm r (Function.const X c) = 0 := by rw [eHolderNorm, ← ENNReal.bot_eq_zero, iInf₂_eq_bot] exact fun C' hC' => ⟨0, .const, hC'⟩ variable (X) in @[simp] lemma eHolderNorm_zero [Zero Y] (r : ℝ≥0) : eHolderNorm r (0 : X → Y) = 0 := eHolderNorm_const X r 0 variable (X) in @[simp] lemma nnHolderNorm_const (r : ℝ≥0) (c : Y) : nnHolderNorm r (Function.const X c) = 0 := by refine le_antisymm (ENNReal.coe_le_coe.1 <| le_trans coe_nnHolderNorm_le_eHolderNorm ?_) (zero_le _) rw [eHolderNorm_const, ENNReal.coe_zero] variable (X) in @[simp] lemma nnHolderNorm_zero [Zero Y] (r : ℝ≥0) : nnHolderNorm r (0 : X → Y) = 0 := nnHolderNorm_const X r 0 attribute [simp] eHolderNorm_const eHolderNorm_zero lemma eHolderNorm_of_isEmpty [hX : IsEmpty X] : eHolderNorm r f = 0 := by rw [eHolderNorm, ← ENNReal.bot_eq_zero, iInf₂_eq_bot] exact fun ε hε => ⟨0, .of_isEmpty, hε⟩ lemma HolderWith.eHolderNorm_le {C : ℝ≥0} (hf : HolderWith C r f) : eHolderNorm r f ≤ C := iInf₂_le C hf /-- See also `memHolder_const` for the version with the spelling `fun _ ↦ c`. -/ @[simp] lemma memHolder_const {c : Y} : MemHolder r (Function.const X c) := (HolderWith.const (C := 0)).memHolder /-- Version of `memHolder_const` with the spelling `fun _ ↦ c` for the constant function. -/ @[simp] lemma memHolder_const' {c : Y} : MemHolder r (fun _ ↦ c : X → Y) := memHolder_const @[simp] lemma memHolder_zero [Zero Y] : MemHolder r (0 : X → Y) := memHolder_const end PseudoEMetricSpace section MetricSpace variable [MetricSpace X] [EMetricSpace Y] lemma eHolderNorm_eq_zero {r : ℝ≥0} {f : X → Y} : eHolderNorm r f = 0 ↔ ∀ x₁ x₂, f x₁ = f x₂ := by constructor · refine fun h x₁ x₂ => ?_ by_cases hx : x₁ = x₂ · rw [hx] · rw [eHolderNorm, ← ENNReal.bot_eq_zero, iInf₂_eq_bot] at h rw [← edist_eq_zero, ← le_zero_iff] refine le_of_forall_gt fun b hb => ?_ obtain ⟨C, hC, hC'⟩ := h (b / edist x₁ x₂ ^ (r : ℝ)) (ENNReal.div_pos hb.ne.symm (ENNReal.rpow_lt_top_of_nonneg zero_le_coe (edist_lt_top x₁ x₂).ne).ne) exact lt_of_le_of_lt (hC x₁ x₂) <| ENNReal.mul_lt_of_lt_div hC' · intro h rcases isEmpty_or_nonempty X with hX | hX · exact eHolderNorm_of_isEmpty · rw [← eHolderNorm_const X r (f hX.some)] congr simp [funext_iff, h _ hX.some] lemma MemHolder.holderWith {r : ℝ≥0} {f : X → Y} (hf : MemHolder r f) : HolderWith (nnHolderNorm r f) r f := by intro x₁ x₂ by_cases hx : x₁ = x₂ · simp only [hx, edist_self, zero_le] rw [nnHolderNorm, eHolderNorm, coe_toNNReal] on_goal 2 => exact hf.eHolderNorm_lt_top.ne have h₁ : edist x₁ x₂ ^ (r : ℝ) ≠ 0 := (Ne.symm <| ne_of_lt <| ENNReal.rpow_pos (edist_pos.2 hx) (edist_lt_top x₁ x₂).ne) have h₂ : edist x₁ x₂ ^ (r : ℝ) ≠ ∞ := by simp [(edist_lt_top x₁ x₂).ne] rw [← ENNReal.div_le_iff h₁ h₂] refine le_iInf₂ fun C hC => ?_ rw [ENNReal.div_le_iff h₁ h₂] exact hC x₁ x₂ lemma memHolder_iff_holderWith {r : ℝ≥0} {f : X → Y} : MemHolder r f ↔ HolderWith (nnHolderNorm r f) r f := ⟨MemHolder.holderWith, HolderWith.memHolder⟩ lemma MemHolder.coe_nnHolderNorm_eq_eHolderNorm {r : ℝ≥0} {f : X → Y} (hf : MemHolder r f) : (nnHolderNorm r f : ℝ≥0∞) = eHolderNorm r f := by rw [nnHolderNorm, coe_toNNReal] exact ne_of_lt <| lt_of_le_of_lt hf.holderWith.eHolderNorm_le <| coe_lt_top lemma HolderWith.nnholderNorm_le {C r : ℝ≥0} {f : X → Y} (hf : HolderWith C r f) : nnHolderNorm r f ≤ C := by rw [← ENNReal.coe_le_coe, hf.memHolder.coe_nnHolderNorm_eq_eHolderNorm] exact hf.eHolderNorm_le lemma MemHolder.comp {r s : ℝ≥0} {Z : Type*} [MetricSpace Z] {f : Z → X} {g : X → Y} (hf : MemHolder r f) (hg : MemHolder s g) : MemHolder (s * r) (g ∘ f) := (hg.holderWith.comp hf.holderWith).memHolder lemma MemHolder.nnHolderNorm_eq_zero {r : ℝ≥0} {f : X → Y} (hf : MemHolder r f) : nnHolderNorm r f = 0 ↔ ∀ x₁ x₂, f x₁ = f x₂ := by rw [← ENNReal.coe_eq_zero, hf.coe_nnHolderNorm_eq_eHolderNorm, eHolderNorm_eq_zero] end MetricSpace section SeminormedAddCommGroup variable [MetricSpace X] [NormedAddCommGroup Y] variable {r : ℝ≥0} {f g : X → Y} lemma MemHolder.add (hf : MemHolder r f) (hg : MemHolder r g) : MemHolder r (f + g) := (hf.holderWith.add hg.holderWith).memHolder lemma MemHolder.smul {𝕜} [SeminormedRing 𝕜] [Module 𝕜 Y] [IsBoundedSMul 𝕜 Y] {c : 𝕜} (hf : MemHolder r f) : MemHolder r (c • f) := (hf.holderWith.smul c).memHolder lemma MemHolder.smul_iff {𝕜} [SeminormedRing 𝕜] [Module 𝕜 Y] [NormSMulClass 𝕜 Y] {c : 𝕜} (hc : ‖c‖₊ ≠ 0) : MemHolder r (c • f) ↔ MemHolder r f := by refine ⟨fun ⟨h, hh⟩ => ⟨h * ‖c‖₊⁻¹, ?_⟩, .smul⟩ rw [← HolderWith.smul_iff _ hc, inv_mul_cancel_right₀ hc] exact hh lemma MemHolder.nsmul [NormedSpace ℝ Y] (n : ℕ) (hf : MemHolder r f) : MemHolder r (n • f) := by simp [← Nat.cast_smul_eq_nsmul (R := ℝ), hf.smul] lemma MemHolder.nnHolderNorm_add_le (hf : MemHolder r f) (hg : MemHolder r g) : nnHolderNorm r (f + g) ≤ nnHolderNorm r f + nnHolderNorm r g := (hf.add hg).holderWith.nnholderNorm_le.trans (hf.holderWith.add hg.holderWith).nnholderNorm_le lemma eHolderNorm_add_le : eHolderNorm r (f + g) ≤ eHolderNorm r f + eHolderNorm r g := by by_cases hfg : MemHolder r f ∧ MemHolder r g · obtain ⟨hf, hg⟩ := hfg rw [← hf.coe_nnHolderNorm_eq_eHolderNorm, ← hg.coe_nnHolderNorm_eq_eHolderNorm, ← (hf.add hg).coe_nnHolderNorm_eq_eHolderNorm, ← coe_add, ENNReal.coe_le_coe] exact hf.nnHolderNorm_add_le hg · rw [Classical.not_and_iff_not_or_not, ← eHolderNorm_eq_top, ← eHolderNorm_eq_top] at hfg obtain (h | h) := hfg all_goals simp [h] lemma eHolderNorm_smul {α} [NormedRing α] [Module α Y] [NormSMulClass α Y] (c : α) : eHolderNorm r (c • f) = ‖c‖₊ * eHolderNorm r f := by by_cases hc : ‖c‖₊ = 0 · rw [nnnorm_eq_zero] at hc simp [hc] by_cases hf : MemHolder r f · refine le_antisymm ((hf.holderWith.smul c).eHolderNorm_le.trans ?_) <| mul_le_of_le_div' ?_ · rw [coe_mul, hf.coe_nnHolderNorm_eq_eHolderNorm, mul_comm] · rw [← (hf.holderWith.smul c).memHolder.coe_nnHolderNorm_eq_eHolderNorm, ← coe_div hc] refine HolderWith.eHolderNorm_le fun x₁ x₂ => ?_ rw [coe_div hc, ← ENNReal.mul_div_right_comm, ENNReal.le_div_iff_mul_le (Or.inl <| coe_ne_zero.2 hc) <| Or.inl coe_ne_top, mul_comm, ← smul_eq_mul, ← ENNReal.smul_def, ← edist_smul₀, ← Pi.smul_apply, ← Pi.smul_apply] exact hf.smul.holderWith x₁ x₂ · rw [← eHolderNorm_eq_top] at hf rw [hf, mul_top <| coe_ne_zero.2 hc, eHolderNorm_eq_top, MemHolder.smul_iff hc] rw [nnnorm_eq_zero] at hc intro h exact h.eHolderNorm_lt_top.ne hf lemma MemHolder.nnHolderNorm_smul {α} [NormedRing α] [Module α Y] [NormSMulClass α Y] (hf : MemHolder r f) (c : α) : nnHolderNorm r (c • f) = ‖c‖₊ * nnHolderNorm r f := by rw [← ENNReal.coe_inj, coe_mul, hf.coe_nnHolderNorm_eq_eHolderNorm, hf.smul.coe_nnHolderNorm_eq_eHolderNorm, eHolderNorm_smul] lemma eHolderNorm_nsmul [NormedSpace ℝ Y] (n : ℕ) : eHolderNorm r (n • f) = n • eHolderNorm r f := by simp [← Nat.cast_smul_eq_nsmul (R := ℝ), eHolderNorm_smul] lemma MemHolder.nnHolderNorm_nsmul [NormedSpace ℝ Y] (n : ℕ) (hf : MemHolder r f) : nnHolderNorm r (n • f) = n • nnHolderNorm r f := by simp [← Nat.cast_smul_eq_nsmul (R := ℝ), hf.nnHolderNorm_smul] end SeminormedAddCommGroup
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Bilipschitz.lean
import Mathlib.Topology.MetricSpace.Antilipschitz import Mathlib.Topology.MetricSpace.Lipschitz /-! # Bilipschitz equivalence A common pattern in Mathlib is to replace the topology, uniformity and bornology on a type synonym with those of the underlying type. The most common way to do this is to activate a local instance for something which puts a `PseudoMetricSpace` structure on the type synonym, prove that this metric is bilipschitz equivalent to the metric on the underlying type, and then use this to show that the uniformities and bornologies agree, which can then be used with `PseudoMetricSpace.replaceUniformity` or `PseudoMetricSpace.replaceBornology`. With the tooling outside this file, this can be a bit cumbersome, especially when it occurs repeatedly, and moreover it can lend itself to abuse of the definitional equality inherent in the type synonym. In this file, we make this pattern more convenient by providing lemmas which take directly the conditions that the map is bilipschitz, and then prove the relevant equalities. Moreover, because there are no type synonyms here, it is necessary to phrase these equalities in terms of the induced uniformity and bornology, which means users will need to do the same if they choose to use these convenience lemmas. This encourages good hygiene in the development of type synonyms. -/ open NNReal section Uniformity open Uniformity variable {α β : Type*} [PseudoEMetricSpace α] [PseudoEMetricSpace β] variable {K₁ K₂ : ℝ≥0} {f : α → β} /-- If `f : α → β` is bilipschitz, then the pullback of the uniformity on `β` through `f` agrees with the uniformity on `α`. This can be used to provide the replacement equality when applying `PseudoMetricSpace.replaceUniformity`, which can be useful when following the forgetful inheritance pattern when creating type synonyms. Important Note: if `α` is some synonym of a type `β` (at default transparency), and `f : α ≃ β` is some bilipschitz equivalence, then instead of writing: ``` instance : UniformSpace α := inferInstanceAs (UniformSpace β) ``` Users should instead write something like: ``` instance : UniformSpace α := (inferInstance : UniformSpace β).comap f ``` in order to avoid abuse of the definitional equality `α := β`. -/ lemma uniformity_eq_of_bilipschitz (hf₁ : AntilipschitzWith K₁ f) (hf₂ : LipschitzWith K₂ f) : 𝓤[(inferInstance : UniformSpace β).comap f] = 𝓤 α := hf₁.isUniformInducing hf₂.uniformContinuous |>.comap_uniformity end Uniformity section Bornology open Bornology Filter variable {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] variable {K₁ K₂ : ℝ≥0} {f : α → β} /-- If `f : α → β` is bilipschitz, then the pullback of the bornology on `β` through `f` agrees with the bornology on `α`. -/ lemma bornology_eq_of_bilipschitz (hf₁ : AntilipschitzWith K₁ f) (hf₂ : LipschitzWith K₂ f) : @cobounded _ (induced f) = cobounded α := le_antisymm hf₂.comap_cobounded_le hf₁.tendsto_cobounded.le_comap /-- If `f : α → β` is bilipschitz, then the pullback of the bornology on `β` through `f` agrees with the bornology on `α`. This can be used to provide the replacement equality when applying `PseudoMetricSpace.replaceBornology`, which can be useful when following the forgetful inheritance pattern when creating type synonyms. Important Note: if `α` is some synonym of a type `β` (at default transparency), and `f : α ≃ β` is some bilipschitz equivalence, then instead of writing: ``` instance : Bornology α := inferInstanceAs (Bornology β) ``` Users should instead write something like: ``` instance : Bornology α := Bornology.induced (f : α → β) ``` in order to avoid abuse of the definitional equality `α := β`. -/ lemma isBounded_iff_of_bilipschitz (hf₁ : AntilipschitzWith K₁ f) (hf₂ : LipschitzWith K₂ f) (s : Set α) : @IsBounded _ (induced f) s ↔ Bornology.IsBounded s := Filter.ext_iff.1 (bornology_eq_of_bilipschitz hf₁ hf₂) (sᶜ) end Bornology
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Isometry.lean
import Mathlib.Data.Fintype.Lattice import Mathlib.Data.Fintype.Sum import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.MetricSpace.Antilipschitz /-! # Isometries We define isometries, i.e., maps between emetric spaces that preserve the edistance (on metric spaces, these are exactly the maps that preserve distances), and prove their basic properties. We also introduce isometric bijections. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `PseudoMetricSpace` and we specialize to `MetricSpace` when needed. -/ open Topology noncomputable section universe u v w variable {F ι : Type*} {α : Type u} {β : Type v} {γ : Type w} open Function Set open scoped Topology ENNReal /-- An isometry (also known as isometric embedding) is a map preserving the edistance between pseudoemetric spaces, or equivalently the distance between pseudometric space. -/ def Isometry [PseudoEMetricSpace α] [PseudoEMetricSpace β] (f : α → β) : Prop := ∀ x1 x2 : α, edist (f x1) (f x2) = edist x1 x2 /-- On pseudometric spaces, a map is an isometry if and only if it preserves nonnegative distances. -/ theorem isometry_iff_nndist_eq [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} : Isometry f ↔ ∀ x y, nndist (f x) (f y) = nndist x y := by simp only [Isometry, edist_nndist, ENNReal.coe_inj] /-- On pseudometric spaces, a map is an isometry if and only if it preserves distances. -/ theorem isometry_iff_dist_eq [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} : Isometry f ↔ ∀ x y, dist (f x) (f y) = dist x y := by simp only [isometry_iff_nndist_eq, ← coe_nndist, NNReal.coe_inj] /-- An isometry preserves distances. -/ alias ⟨Isometry.dist_eq, _⟩ := isometry_iff_dist_eq /-- A map that preserves distances is an isometry -/ alias ⟨_, Isometry.of_dist_eq⟩ := isometry_iff_dist_eq /-- An isometry preserves non-negative distances. -/ alias ⟨Isometry.nndist_eq, _⟩ := isometry_iff_nndist_eq /-- A map that preserves non-negative distances is an isometry. -/ alias ⟨_, Isometry.of_nndist_eq⟩ := isometry_iff_nndist_eq namespace Isometry section PseudoEmetricIsometry variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {f : α → β} {x : α} /-- An isometry preserves edistances. -/ theorem edist_eq (hf : Isometry f) (x y : α) : edist (f x) (f y) = edist x y := hf x y theorem lipschitz (h : Isometry f) : LipschitzWith 1 f := LipschitzWith.of_edist_le fun x y => (h x y).le theorem antilipschitz (h : Isometry f) : AntilipschitzWith 1 f := fun x y => by simp only [h x y, ENNReal.coe_one, one_mul, le_refl] /-- Any map on a subsingleton is an isometry -/ @[nontriviality] theorem _root_.isometry_subsingleton [Subsingleton α] : Isometry f := fun x y => by rw [Subsingleton.elim x y]; simp /-- The identity is an isometry -/ theorem _root_.isometry_id : Isometry (id : α → α) := fun _ _ => rfl theorem prodMap {δ} [PseudoEMetricSpace δ] {f : α → β} {g : γ → δ} (hf : Isometry f) (hg : Isometry g) : Isometry (Prod.map f g) := fun x y => by simp only [Prod.edist_eq, Prod.map_fst, hf.edist_eq, Prod.map_snd, hg.edist_eq] protected theorem piMap {ι} [Fintype ι] {α β : ι → Type*} [∀ i, PseudoEMetricSpace (α i)] [∀ i, PseudoEMetricSpace (β i)] (f : ∀ i, α i → β i) (hf : ∀ i, Isometry (f i)) : Isometry (Pi.map f) := fun x y => by simp only [edist_pi_def, (hf _).edist_eq, Pi.map_apply] protected lemma single [Fintype ι] [DecidableEq ι] {E : ι → Type*} [∀ i, PseudoEMetricSpace (E i)] [∀ i, Zero (E i)] (i : ι) : Isometry (Pi.single (M := E) i) := by intro x y rw [edist_pi_def] refine le_antisymm (Finset.sup_le fun j ↦ ?_) (Finset.le_sup_of_le (Finset.mem_univ i) (by simp)) obtain rfl | h := eq_or_ne i j · simp · simp [h] protected lemma inl [AddZeroClass α] [AddZeroClass β] : Isometry (AddMonoidHom.inl α β) := by intro x y rw [Prod.edist_eq] simp protected lemma inr [AddZeroClass α] [AddZeroClass β] : Isometry (AddMonoidHom.inr α β) := by intro x y rw [Prod.edist_eq] simp /-- The composition of isometries is an isometry. -/ theorem comp {g : β → γ} {f : α → β} (hg : Isometry g) (hf : Isometry f) : Isometry (g ∘ f) := fun _ _ => (hg _ _).trans (hf _ _) /-- An isometry from a metric space is a uniform continuous map -/ protected theorem uniformContinuous (hf : Isometry f) : UniformContinuous f := hf.lipschitz.uniformContinuous /-- An isometry from a metric space is a uniform inducing map -/ theorem isUniformInducing (hf : Isometry f) : IsUniformInducing f := hf.antilipschitz.isUniformInducing hf.uniformContinuous theorem tendsto_nhds_iff {ι : Type*} {f : α → β} {g : ι → α} {a : Filter ι} {b : α} (hf : Isometry f) : Filter.Tendsto g a (𝓝 b) ↔ Filter.Tendsto (f ∘ g) a (𝓝 (f b)) := hf.isUniformInducing.isInducing.tendsto_nhds_iff /-- An isometry is continuous. -/ protected theorem continuous (hf : Isometry f) : Continuous f := hf.lipschitz.continuous /-- The right inverse of an isometry is an isometry. -/ theorem right_inv {f : α → β} {g : β → α} (h : Isometry f) (hg : RightInverse g f) : Isometry g := fun x y => by rw [← h, hg _, hg _] theorem preimage_emetric_closedBall (h : Isometry f) (x : α) (r : ℝ≥0∞) : f ⁻¹' EMetric.closedBall (f x) r = EMetric.closedBall x r := by ext y simp [h.edist_eq] theorem preimage_emetric_ball (h : Isometry f) (x : α) (r : ℝ≥0∞) : f ⁻¹' EMetric.ball (f x) r = EMetric.ball x r := by ext y simp [h.edist_eq] /-- Isometries preserve the diameter in pseudoemetric spaces. -/ theorem ediam_image (hf : Isometry f) (s : Set α) : EMetric.diam (f '' s) = EMetric.diam s := eq_of_forall_ge_iff fun d => by simp only [EMetric.diam_le_iff, forall_mem_image, hf.edist_eq] theorem ediam_range (hf : Isometry f) : EMetric.diam (range f) = EMetric.diam (univ : Set α) := by rw [← image_univ] exact hf.ediam_image univ theorem mapsTo_emetric_ball (hf : Isometry f) (x : α) (r : ℝ≥0∞) : MapsTo f (EMetric.ball x r) (EMetric.ball (f x) r) := (hf.preimage_emetric_ball x r).ge theorem mapsTo_emetric_closedBall (hf : Isometry f) (x : α) (r : ℝ≥0∞) : MapsTo f (EMetric.closedBall x r) (EMetric.closedBall (f x) r) := (hf.preimage_emetric_closedBall x r).ge /-- The injection from a subtype is an isometry -/ theorem _root_.isometry_subtype_coe {s : Set α} : Isometry ((↑) : s → α) := fun _ _ => rfl theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] (hf : Isometry f) {g : γ → α} {s : Set γ} : ContinuousOn (f ∘ g) s ↔ ContinuousOn g s := hf.isUniformInducing.isInducing.continuousOn_iff.symm theorem comp_continuous_iff {γ} [TopologicalSpace γ] (hf : Isometry f) {g : γ → α} : Continuous (f ∘ g) ↔ Continuous g := hf.isUniformInducing.isInducing.continuous_iff.symm end PseudoEmetricIsometry --section section EmetricIsometry variable [EMetricSpace α] [PseudoEMetricSpace β] {f : α → β} /-- An isometry from an emetric space is injective -/ protected theorem injective (h : Isometry f) : Injective f := h.antilipschitz.injective /-- An isometry from an emetric space is a uniform embedding -/ lemma isUniformEmbedding (hf : Isometry f) : IsUniformEmbedding f := hf.antilipschitz.isUniformEmbedding hf.lipschitz.uniformContinuous /-- An isometry from an emetric space is an embedding -/ theorem isEmbedding (hf : Isometry f) : IsEmbedding f := hf.isUniformEmbedding.isEmbedding /-- An isometry from a complete emetric space is a closed embedding -/ theorem isClosedEmbedding [CompleteSpace α] [EMetricSpace γ] {f : α → γ} (hf : Isometry f) : IsClosedEmbedding f := hf.antilipschitz.isClosedEmbedding hf.lipschitz.uniformContinuous end EmetricIsometry --section section PseudoMetricIsometry variable [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} /-- An isometry preserves the diameter in pseudometric spaces. -/ theorem diam_image (hf : Isometry f) (s : Set α) : Metric.diam (f '' s) = Metric.diam s := by rw [Metric.diam, Metric.diam, hf.ediam_image] theorem diam_range (hf : Isometry f) : Metric.diam (range f) = Metric.diam (univ : Set α) := by rw [← image_univ] exact hf.diam_image univ theorem preimage_setOf_dist (hf : Isometry f) (x : α) (p : ℝ → Prop) : f ⁻¹' { y | p (dist y (f x)) } = { y | p (dist y x) } := by simp [hf.dist_eq] theorem preimage_closedBall (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.closedBall (f x) r = Metric.closedBall x r := hf.preimage_setOf_dist x (· ≤ r) theorem preimage_ball (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.ball (f x) r = Metric.ball x r := hf.preimage_setOf_dist x (· < r) theorem preimage_sphere (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.sphere (f x) r = Metric.sphere x r := hf.preimage_setOf_dist x (· = r) theorem mapsTo_ball (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.ball x r) (Metric.ball (f x) r) := (hf.preimage_ball x r).ge theorem mapsTo_sphere (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.sphere x r) (Metric.sphere (f x) r) := (hf.preimage_sphere x r).ge theorem mapsTo_closedBall (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) r) := (hf.preimage_closedBall x r).ge end PseudoMetricIsometry -- section end Isometry -- namespace /-- A uniform embedding from a uniform space to a metric space is an isometry with respect to the induced metric space structure on the source space. -/ theorem IsUniformEmbedding.to_isometry {α β} [UniformSpace α] [MetricSpace β] {f : α → β} (h : IsUniformEmbedding f) : (letI := h.comapMetricSpace f; Isometry f) := let _ := h.comapMetricSpace f Isometry.of_dist_eq fun _ _ => rfl /-- An embedding from a topological space to a metric space is an isometry with respect to the induced metric space structure on the source space. -/ theorem Topology.IsEmbedding.to_isometry {α β} [TopologicalSpace α] [MetricSpace β] {f : α → β} (h : IsEmbedding f) : (letI := h.comapMetricSpace f; Isometry f) := let _ := h.comapMetricSpace f Isometry.of_dist_eq fun _ _ => rfl theorem PseudoEMetricSpace.isometry_induced (f : α → β) [m : PseudoEMetricSpace β] : letI := m.induced f; Isometry f := fun _ _ ↦ rfl theorem PseudoMetricSpace.isometry_induced (f : α → β) [m : PseudoMetricSpace β] : letI := m.induced f; Isometry f := fun _ _ ↦ rfl @[deprecated (since := "2025-07-27")] alias PsuedoMetricSpace.isometry_induced := PseudoMetricSpace.isometry_induced theorem EMetricSpace.isometry_induced (f : α → β) (hf : f.Injective) [m : EMetricSpace β] : letI := m.induced f hf; Isometry f := fun _ _ ↦ rfl theorem MetricSpace.isometry_induced (f : α → β) (hf : f.Injective) [m : MetricSpace β] : letI := m.induced f hf; Isometry f := fun _ _ ↦ rfl /-- `IsometryClass F α β` states that `F` is a type of isometries. -/ class IsometryClass (F : Type*) (α β : outParam Type*) [PseudoEMetricSpace α] [PseudoEMetricSpace β] [FunLike F α β] : Prop where protected isometry (f : F) : Isometry f namespace IsometryClass section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] section variable [FunLike F α β] [IsometryClass F α β] (f : F) protected theorem edist_eq (x y : α) : edist (f x) (f y) = edist x y := (IsometryClass.isometry f).edist_eq x y protected theorem continuous : Continuous f := (IsometryClass.isometry f).continuous protected theorem lipschitz : LipschitzWith 1 f := (IsometryClass.isometry f).lipschitz protected theorem antilipschitz : AntilipschitzWith 1 f := (IsometryClass.isometry f).antilipschitz theorem ediam_image (s : Set α) : EMetric.diam (f '' s) = EMetric.diam s := (IsometryClass.isometry f).ediam_image s theorem ediam_range : EMetric.diam (range f) = EMetric.diam (univ : Set α) := (IsometryClass.isometry f).ediam_range instance toContinuousMapClass : ContinuousMapClass F α β where map_continuous := IsometryClass.continuous end instance toHomeomorphClass [EquivLike F α β] [IsometryClass F α β] : HomeomorphClass F α β where map_continuous := IsometryClass.continuous inv_continuous f := ((IsometryClass.isometry f).right_inv (EquivLike.right_inv f)).continuous end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β] [IsometryClass F α β] (f : F) protected theorem dist_eq (x y : α) : dist (f x) (f y) = dist x y := (IsometryClass.isometry f).dist_eq x y protected theorem nndist_eq (x y : α) : nndist (f x) (f y) = nndist x y := (IsometryClass.isometry f).nndist_eq x y theorem diam_image (s : Set α) : Metric.diam (f '' s) = Metric.diam s := (IsometryClass.isometry f).diam_image s theorem diam_range : Metric.diam (range f) = Metric.diam (univ : Set α) := (IsometryClass.isometry f).diam_range end PseudoMetricSpace end IsometryClass -- such a bijection need not exist /-- `α` and `β` are isometric if there is an isometric bijection between them. -/ structure IsometryEquiv (α : Type u) (β : Type v) [PseudoEMetricSpace α] [PseudoEMetricSpace β] extends α ≃ β where isometry_toFun : Isometry toFun @[inherit_doc] infixl:25 " ≃ᵢ " => IsometryEquiv namespace IsometryEquiv section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] theorem toEquiv_injective : Injective (toEquiv : (α ≃ᵢ β) → (α ≃ β)) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl @[simp] theorem toEquiv_inj {e₁ e₂ : α ≃ᵢ β} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff instance : EquivLike (α ≃ᵢ β) α β where coe e := e.toEquiv inv e := e.toEquiv.symm left_inv e := e.left_inv right_inv e := e.right_inv coe_injective' _ _ h _ := toEquiv_injective <| DFunLike.ext' h instance : IsometryClass (IsometryEquiv α β) α β where isometry := isometry_toFun theorem coe_eq_toEquiv (h : α ≃ᵢ β) (a : α) : h a = h.toEquiv a := rfl @[simp] theorem coe_toEquiv (h : α ≃ᵢ β) : ⇑h.toEquiv = h := rfl @[simp] theorem coe_mk (e : α ≃ β) (h) : ⇑(mk e h) = e := rfl protected theorem isometry (h : α ≃ᵢ β) : Isometry h := h.isometry_toFun protected theorem bijective (h : α ≃ᵢ β) : Bijective h := h.toEquiv.bijective protected theorem injective (h : α ≃ᵢ β) : Injective h := h.toEquiv.injective protected theorem surjective (h : α ≃ᵢ β) : Surjective h := h.toEquiv.surjective protected theorem edist_eq (h : α ≃ᵢ β) (x y : α) : edist (h x) (h y) = edist x y := h.isometry.edist_eq x y protected theorem dist_eq {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) (x y : α) : dist (h x) (h y) = dist x y := h.isometry.dist_eq x y protected theorem nndist_eq {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) (x y : α) : nndist (h x) (h y) = nndist x y := h.isometry.nndist_eq x y protected theorem continuous (h : α ≃ᵢ β) : Continuous h := h.isometry.continuous @[simp] theorem ediam_image (h : α ≃ᵢ β) (s : Set α) : EMetric.diam (h '' s) = EMetric.diam s := h.isometry.ediam_image s @[ext] theorem ext ⦃h₁ h₂ : α ≃ᵢ β⦄ (H : ∀ x, h₁ x = h₂ x) : h₁ = h₂ := DFunLike.ext _ _ H /-- Alternative constructor for isometric bijections, taking as input an isometry, and a right inverse. -/ def mk' {α : Type u} [EMetricSpace α] (f : α → β) (g : β → α) (hfg : ∀ x, f (g x) = x) (hf : Isometry f) : α ≃ᵢ β where toFun := f invFun := g left_inv _ := hf.injective <| hfg _ right_inv := hfg isometry_toFun := hf /-- The identity isometry of a space. -/ protected def refl (α : Type*) [PseudoEMetricSpace α] : α ≃ᵢ α := { Equiv.refl α with isometry_toFun := isometry_id } /-- The composition of two isometric isomorphisms, as an isometric isomorphism. -/ protected def trans (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) : α ≃ᵢ γ := { Equiv.trans h₁.toEquiv h₂.toEquiv with isometry_toFun := h₂.isometry_toFun.comp h₁.isometry_toFun } @[simp] theorem trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : α) : h₁.trans h₂ x = h₂ (h₁ x) := rfl /-- The inverse of an isometric isomorphism, as an isometric isomorphism. -/ protected def symm (h : α ≃ᵢ β) : β ≃ᵢ α where isometry_toFun := h.isometry.right_inv h.right_inv toEquiv := h.toEquiv.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (h : α ≃ᵢ β) : α → β := h /-- See Note [custom simps projection] -/ def Simps.symm_apply (h : α ≃ᵢ β) : β → α := h.symm initialize_simps_projections IsometryEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem symm_symm (h : α ≃ᵢ β) : h.symm.symm = h := rfl theorem symm_bijective : Bijective (IsometryEquiv.symm : (α ≃ᵢ β) → β ≃ᵢ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (h : α ≃ᵢ β) (y : β) : h (h.symm y) = y := h.toEquiv.apply_symm_apply y @[simp] theorem symm_apply_apply (h : α ≃ᵢ β) (x : α) : h.symm (h x) = x := h.toEquiv.symm_apply_apply x theorem symm_apply_eq (h : α ≃ᵢ β) {x : α} {y : β} : h.symm y = x ↔ y = h x := h.toEquiv.symm_apply_eq theorem eq_symm_apply (h : α ≃ᵢ β) {x : α} {y : β} : x = h.symm y ↔ h x = y := h.toEquiv.eq_symm_apply theorem symm_comp_self (h : α ≃ᵢ β) : (h.symm : β → α) ∘ h = id := funext h.left_inv theorem self_comp_symm (h : α ≃ᵢ β) : (h : α → β) ∘ h.symm = id := funext h.right_inv theorem range_eq_univ (h : α ≃ᵢ β) : range h = univ := by simp theorem image_symm (h : α ≃ᵢ β) : image h.symm = preimage h := image_eq_preimage_of_inverse h.symm.toEquiv.left_inv h.symm.toEquiv.right_inv theorem preimage_symm (h : α ≃ᵢ β) : preimage h.symm = image h := (image_eq_preimage_of_inverse h.toEquiv.left_inv h.toEquiv.right_inv).symm @[simp] theorem symm_trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : γ) : (h₁.trans h₂).symm x = h₁.symm (h₂.symm x) := rfl theorem ediam_univ (h : α ≃ᵢ β) : EMetric.diam (univ : Set α) = EMetric.diam (univ : Set β) := by rw [← h.range_eq_univ, h.isometry.ediam_range] @[simp] theorem ediam_preimage (h : α ≃ᵢ β) (s : Set β) : EMetric.diam (h ⁻¹' s) = EMetric.diam s := by rw [← image_symm, ediam_image] @[simp] theorem preimage_emetric_ball (h : α ≃ᵢ β) (x : β) (r : ℝ≥0∞) : h ⁻¹' EMetric.ball x r = EMetric.ball (h.symm x) r := by rw [← h.isometry.preimage_emetric_ball (h.symm x) r, h.apply_symm_apply] @[simp] theorem preimage_emetric_closedBall (h : α ≃ᵢ β) (x : β) (r : ℝ≥0∞) : h ⁻¹' EMetric.closedBall x r = EMetric.closedBall (h.symm x) r := by rw [← h.isometry.preimage_emetric_closedBall (h.symm x) r, h.apply_symm_apply] @[simp] theorem image_emetric_ball (h : α ≃ᵢ β) (x : α) (r : ℝ≥0∞) : h '' EMetric.ball x r = EMetric.ball (h x) r := by rw [← h.preimage_symm, h.symm.preimage_emetric_ball, symm_symm] @[simp] theorem image_emetric_closedBall (h : α ≃ᵢ β) (x : α) (r : ℝ≥0∞) : h '' EMetric.closedBall x r = EMetric.closedBall (h x) r := by rw [← h.preimage_symm, h.symm.preimage_emetric_closedBall, symm_symm] /-- The (bundled) homeomorphism associated to an isometric isomorphism. -/ @[simps toEquiv] protected def toHomeomorph (h : α ≃ᵢ β) : α ≃ₜ β where continuous_toFun := h.continuous continuous_invFun := h.symm.continuous toEquiv := h.toEquiv @[simp] theorem coe_toHomeomorph (h : α ≃ᵢ β) : ⇑h.toHomeomorph = h := rfl @[simp] theorem coe_toHomeomorph_symm (h : α ≃ᵢ β) : ⇑h.toHomeomorph.symm = h.symm := rfl @[simp] theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : γ → α} {s : Set γ} : ContinuousOn (h ∘ f) s ↔ ContinuousOn f s := h.toHomeomorph.comp_continuousOn_iff _ _ @[simp] theorem comp_continuous_iff {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : γ → α} : Continuous (h ∘ f) ↔ Continuous f := h.toHomeomorph.comp_continuous_iff @[simp] theorem comp_continuous_iff' {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : β → γ} : Continuous (f ∘ h) ↔ Continuous f := h.toHomeomorph.comp_continuous_iff' /-- The group of isometries. -/ instance : Group (α ≃ᵢ α) where one := IsometryEquiv.refl _ mul e₁ e₂ := e₂.trans e₁ inv := IsometryEquiv.symm mul_assoc _ _ _ := rfl one_mul _ := ext fun _ => rfl mul_one _ := ext fun _ => rfl inv_mul_cancel e := ext e.symm_apply_apply @[simp] theorem coe_one : ⇑(1 : α ≃ᵢ α) = id := rfl @[simp] theorem coe_mul (e₁ e₂ : α ≃ᵢ α) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl theorem mul_apply (e₁ e₂ : α ≃ᵢ α) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) := rfl @[simp] theorem inv_apply_self (e : α ≃ᵢ α) (x : α) : e⁻¹ (e x) = x := e.symm_apply_apply x @[simp] theorem apply_inv_self (e : α ≃ᵢ α) (x : α) : e (e⁻¹ x) = x := e.apply_symm_apply x theorem completeSpace_iff (e : α ≃ᵢ β) : CompleteSpace α ↔ CompleteSpace β := by simp only [completeSpace_iff_isComplete_univ, ← e.range_eq_univ, ← image_univ, isComplete_image_iff e.isometry.isUniformInducing] protected theorem completeSpace [CompleteSpace β] (e : α ≃ᵢ β) : CompleteSpace α := e.completeSpace_iff.2 ‹_› /-- The natural isometry `∀ i, Y i ≃ᵢ ∀ j, Y (e.symm j)` obtained from a bijection `ι ≃ ι'` of fintypes. `Equiv.piCongrLeft'` as an `IsometryEquiv`. -/ @[simps!] def piCongrLeft' {ι' : Type*} [Fintype ι] [Fintype ι'] {Y : ι → Type*} [∀ j, PseudoEMetricSpace (Y j)] (e : ι ≃ ι') : (∀ i, Y i) ≃ᵢ ∀ j, Y (e.symm j) where toEquiv := Equiv.piCongrLeft' _ e isometry_toFun x1 x2 := by simp_rw [edist_pi_def, Finset.sup_univ_eq_iSup] exact (Equiv.iSup_comp (g := fun b ↦ edist (x1 b) (x2 b)) e.symm) /-- The natural isometry `∀ i, Y (e i) ≃ᵢ ∀ j, Y j` obtained from a bijection `ι ≃ ι'` of fintypes. `Equiv.piCongrLeft` as an `IsometryEquiv`. -/ @[simps!] def piCongrLeft {ι' : Type*} [Fintype ι] [Fintype ι'] {Y : ι' → Type*} [∀ j, PseudoEMetricSpace (Y j)] (e : ι ≃ ι') : (∀ i, Y (e i)) ≃ᵢ ∀ j, Y j := (piCongrLeft' e.symm).symm /-- The natural isometry `(α ⊕ β → γ) ≃ᵢ (α → γ) × (β → γ)` between the type of maps on a sum of fintypes `α ⊕ β` and the pairs of functions on the types `α` and `β`. `Equiv.sumArrowEquivProdArrow` as an `IsometryEquiv`. -/ @[simps!] def sumArrowIsometryEquivProdArrow [Fintype α] [Fintype β] : (α ⊕ β → γ) ≃ᵢ (α → γ) × (β → γ) where toEquiv := Equiv.sumArrowEquivProdArrow _ _ _ isometry_toFun _ _ := by simp [Prod.edist_eq, edist_pi_def, Finset.sup_univ_eq_iSup, iSup_sum] @[simp] theorem sumArrowIsometryEquivProdArrow_toHomeomorph {α β : Type*} [Fintype α] [Fintype β] : sumArrowIsometryEquivProdArrow.toHomeomorph = Homeomorph.sumArrowHomeomorphProdArrow (ι := α) (ι' := β) (X := γ) := rfl theorem _root_.Fin.edist_append_eq_max_edist (m n : ℕ) {x x2 : Fin m → α} {y y2 : Fin n → α} : edist (Fin.append x y) (Fin.append x2 y2) = max (edist x x2) (edist y y2) := by simp [edist_pi_def, Finset.sup_univ_eq_iSup, ← Equiv.iSup_comp (e := finSumFinEquiv), iSup_sum] /-- The natural `IsometryEquiv` between `(Fin m → α) × (Fin n → α)` and `Fin (m + n) → α`. `Fin.appendEquiv` as an `IsometryEquiv`. -/ @[simps!] def _root_.Fin.appendIsometry (m n : ℕ) : (Fin m → α) × (Fin n → α) ≃ᵢ (Fin (m + n) → α) where toEquiv := Fin.appendEquiv _ _ isometry_toFun _ _ := by simp_rw [Fin.appendEquiv, Fin.edist_append_eq_max_edist, Prod.edist_eq] @[simp] theorem _root_.Fin.appendIsometry_toHomeomorph (m n : ℕ) : (Fin.appendIsometry m n).toHomeomorph = Fin.appendHomeomorph (X := α) m n := rfl /-- The natural `IsometryEquiv` `(Fin m → ℝ) × (Fin l → ℝ) ≃ᵢ (Fin n → ℝ)` when `m + l = n`. -/ @[simps!] def _root_.Fin.appendIsometryOfEq {n m l : ℕ} (hmln : m + l = n) : (Fin m → α) × (Fin l → α) ≃ᵢ (Fin n → α) := (Fin.appendIsometry m l).trans (IsometryEquiv.piCongrLeft (Y := fun _ ↦ α) (finCongr hmln)) variable (ι α) /-- `Equiv.funUnique` as an `IsometryEquiv`. -/ @[simps!] def funUnique [Unique ι] [Fintype ι] : (ι → α) ≃ᵢ α where toEquiv := Equiv.funUnique ι α isometry_toFun x hx := by simp [edist_pi_def, Finset.univ_unique, Finset.sup_singleton] /-- `piFinTwoEquiv` as an `IsometryEquiv`. -/ @[simps!] def piFinTwo (α : Fin 2 → Type*) [∀ i, PseudoEMetricSpace (α i)] : (∀ i, α i) ≃ᵢ α 0 × α 1 where toEquiv := piFinTwoEquiv α isometry_toFun x hx := by simp [edist_pi_def, Fin.univ_succ, Prod.edist_eq] end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) @[simp] theorem diam_image (s : Set α) : Metric.diam (h '' s) = Metric.diam s := h.isometry.diam_image s @[simp] theorem diam_preimage (s : Set β) : Metric.diam (h ⁻¹' s) = Metric.diam s := by rw [← image_symm, diam_image] include h in theorem diam_univ : Metric.diam (univ : Set α) = Metric.diam (univ : Set β) := congr_arg ENNReal.toReal h.ediam_univ @[simp] theorem preimage_ball (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.ball x r = Metric.ball (h.symm x) r := by rw [← h.isometry.preimage_ball (h.symm x) r, h.apply_symm_apply] @[simp] theorem preimage_sphere (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.sphere x r = Metric.sphere (h.symm x) r := by rw [← h.isometry.preimage_sphere (h.symm x) r, h.apply_symm_apply] @[simp] theorem preimage_closedBall (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.closedBall x r = Metric.closedBall (h.symm x) r := by rw [← h.isometry.preimage_closedBall (h.symm x) r, h.apply_symm_apply] @[simp] theorem image_ball (h : α ≃ᵢ β) (x : α) (r : ℝ) : h '' Metric.ball x r = Metric.ball (h x) r := by rw [← h.preimage_symm, h.symm.preimage_ball, symm_symm] @[simp] theorem image_sphere (h : α ≃ᵢ β) (x : α) (r : ℝ) : h '' Metric.sphere x r = Metric.sphere (h x) r := by rw [← h.preimage_symm, h.symm.preimage_sphere, symm_symm] @[simp] theorem image_closedBall (h : α ≃ᵢ β) (x : α) (r : ℝ) : h '' Metric.closedBall x r = Metric.closedBall (h x) r := by rw [← h.preimage_symm, h.symm.preimage_closedBall, symm_symm] end PseudoMetricSpace end IsometryEquiv /-- An isometry induces an isometric isomorphism between the source space and the range of the isometry. -/ @[simps! +simpRhs toEquiv apply] def Isometry.isometryEquivOnRange [EMetricSpace α] [PseudoEMetricSpace β] {f : α → β} (h : Isometry f) : α ≃ᵢ range f where isometry_toFun := h toEquiv := Equiv.ofInjective f h.injective open NNReal in /-- Post-composition by an isometry does not change the Lipschitz-property of a function. -/ lemma Isometry.lipschitzWith_iff {α β γ : Type*} [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] {f : α → β} {g : β → γ} (K : ℝ≥0) (h : Isometry g) : LipschitzWith K (g ∘ f) ↔ LipschitzWith K f := by simp [LipschitzWith, h.edist_eq] namespace IsometryClass variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [EquivLike F α β] [IsometryClass F α β] /-- Turn an element of a type `F` satisfying `EquivLike F α β` and `IsometryClass F α β` into an actual `IsometryEquiv`. This is declared as the default coercion from `F` to `α ≃ᵢ β`. -/ @[coe] def toIsometryEquiv (f : F) : α ≃ᵢ β := { (f : α ≃ β) with isometry_toFun := IsometryClass.isometry f } @[simp] theorem coe_coe (f : F) : ⇑(toIsometryEquiv f) = ⇑f := rfl instance : CoeOut F (α ≃ᵢ β) := ⟨toIsometryEquiv⟩ theorem toIsometryEquiv_injective : Function.Injective ((↑) : F → α ≃ᵢ β) := fun _ _ e ↦ DFunLike.ext _ _ fun a ↦ DFunLike.congr_fun e a end IsometryClass
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Perfect.lean
import Mathlib.Topology.Perfect import Mathlib.Topology.MetricSpace.Polish import Mathlib.Topology.MetricSpace.CantorScheme import Mathlib.Topology.Metrizable.Real /-! # Perfect Sets In this file we define properties of `Perfect` subsets of a metric space, including a version of the Cantor-Bendixson Theorem. ## Main Statements * `Perfect.exists_nat_bool_injection`: A perfect nonempty set in a complete metric space admits an embedding from the Cantor space. ## References * [kechris1995] (Chapters 6-7) ## Tags accumulation point, perfect set, cantor-bendixson. -/ open Set Filter section CantorInjMetric open Function ENNReal variable {α : Type*} [MetricSpace α] {C : Set α} {ε : ℝ≥0∞} private theorem Perfect.small_diam_aux (hC : Perfect C) (ε_pos : 0 < ε) {x : α} (xC : x ∈ C) : let D := closure (EMetric.ball x (ε / 2) ∩ C) Perfect D ∧ D.Nonempty ∧ D ⊆ C ∧ EMetric.diam D ≤ ε := by have : x ∈ EMetric.ball x (ε / 2) := by apply EMetric.mem_ball_self rw [ENNReal.div_pos_iff] exact ⟨ne_of_gt ε_pos, by simp⟩ have := hC.closure_nhds_inter x xC this EMetric.isOpen_ball refine ⟨this.1, this.2, ?_, ?_⟩ · rw [IsClosed.closure_subset_iff hC.closed] apply inter_subset_right rw [EMetric.diam_closure] apply le_trans (EMetric.diam_mono inter_subset_left) convert EMetric.diam_ball (x := x) rw [mul_comm, ENNReal.div_mul_cancel] <;> norm_num /-- A refinement of `Perfect.splitting` for metric spaces, where we also control the diameter of the new perfect sets. -/ theorem Perfect.small_diam_splitting (hC : Perfect C) (hnonempty : C.Nonempty) (ε_pos : 0 < ε) : ∃ C₀ C₁ : Set α, (Perfect C₀ ∧ C₀.Nonempty ∧ C₀ ⊆ C ∧ EMetric.diam C₀ ≤ ε) ∧ (Perfect C₁ ∧ C₁.Nonempty ∧ C₁ ⊆ C ∧ EMetric.diam C₁ ≤ ε) ∧ Disjoint C₀ C₁ := by rcases hC.splitting hnonempty with ⟨D₀, D₁, ⟨perf0, non0, sub0⟩, ⟨perf1, non1, sub1⟩, hdisj⟩ obtain ⟨x₀, hx₀⟩ := non0 obtain ⟨x₁, hx₁⟩ := non1 rcases perf0.small_diam_aux ε_pos hx₀ with ⟨perf0', non0', sub0', diam0⟩ rcases perf1.small_diam_aux ε_pos hx₁ with ⟨perf1', non1', sub1', diam1⟩ refine ⟨closure (EMetric.ball x₀ (ε / 2) ∩ D₀), closure (EMetric.ball x₁ (ε / 2) ∩ D₁), ⟨perf0', non0', sub0'.trans sub0, diam0⟩, ⟨perf1', non1', sub1'.trans sub1, diam1⟩, ?_⟩ apply Disjoint.mono _ _ hdisj <;> assumption open CantorScheme /-- Any nonempty perfect set in a complete metric space admits a continuous injection from the Cantor space, `ℕ → Bool`. -/ theorem Perfect.exists_nat_bool_injection (hC : Perfect C) (hnonempty : C.Nonempty) [CompleteSpace α] : ∃ f : (ℕ → Bool) → α, range f ⊆ C ∧ Continuous f ∧ Injective f := by obtain ⟨u, -, upos', hu⟩ := exists_seq_strictAnti_tendsto' (zero_lt_one' ℝ≥0∞) have upos := fun n => (upos' n).1 let P := Subtype fun E : Set α => Perfect E ∧ E.Nonempty choose C0 C1 h0 h1 hdisj using fun {C : Set α} (hC : Perfect C) (hnonempty : C.Nonempty) {ε : ℝ≥0∞} (hε : 0 < ε) => hC.small_diam_splitting hnonempty hε let DP : List Bool → P := fun l => by induction l with | nil => exact ⟨C, ⟨hC, hnonempty⟩⟩ | cons a l ih => cases a · use C0 ih.property.1 ih.property.2 (upos (l.length + 1)) exact ⟨(h0 _ _ _).1, (h0 _ _ _).2.1⟩ use C1 ih.property.1 ih.property.2 (upos (l.length + 1)) exact ⟨(h1 _ _ _).1, (h1 _ _ _).2.1⟩ let D : List Bool → Set α := fun l => (DP l).val have hanti : ClosureAntitone D := by refine Antitone.closureAntitone ?_ fun l => (DP l).property.1.closed intro l a cases a · exact (h0 _ _ _).2.2.1 exact (h1 _ _ _).2.2.1 have hdiam : VanishingDiam D := by intro x apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hu · simp rw [eventually_atTop] refine ⟨1, fun m (hm : 1 ≤ m) => ?_⟩ rw [Nat.one_le_iff_ne_zero] at hm rcases Nat.exists_eq_succ_of_ne_zero hm with ⟨n, rfl⟩ dsimp cases x n · convert (h0 _ _ _).2.2.2 rw [PiNat.res_length] convert (h1 _ _ _).2.2.2 rw [PiNat.res_length] have hdisj' : CantorScheme.Disjoint D := by rintro l (a | a) (b | b) hab <;> try contradiction · exact hdisj _ _ _ exact (hdisj _ _ _).symm have hdom : ∀ {x : ℕ → Bool}, x ∈ (inducedMap D).1 := fun {x} => by rw [hanti.map_of_vanishingDiam hdiam fun l => (DP l).property.2] apply mem_univ refine ⟨fun x => (inducedMap D).2 ⟨x, hdom⟩, ?_, ?_, ?_⟩ · rintro y ⟨x, rfl⟩ exact map_mem ⟨_, hdom⟩ 0 · apply hdiam.map_continuous.comp fun_prop intro x y hxy simpa only [← Subtype.val_inj] using hdisj'.map_injective hxy end CantorInjMetric /-- Any closed uncountable subset of a Polish space admits a continuous injection from the Cantor space `ℕ → Bool`. -/ theorem IsClosed.exists_nat_bool_injection_of_not_countable {α : Type*} [TopologicalSpace α] [PolishSpace α] {C : Set α} (hC : IsClosed C) (hunc : ¬C.Countable) : ∃ f : (ℕ → Bool) → α, range f ⊆ C ∧ Continuous f ∧ Function.Injective f := by letI := TopologicalSpace.upgradeIsCompletelyMetrizable α obtain ⟨D, hD, Dnonempty, hDC⟩ := exists_perfect_nonempty_of_isClosed_of_not_countable hC hunc obtain ⟨f, hfD, hf⟩ := hD.exists_nat_bool_injection Dnonempty exact ⟨f, hfD.trans hDC, hf⟩
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Kuratowski.lean
import Mathlib.Analysis.Normed.Lp.lpSpace import Mathlib.Topology.Sets.Compacts /-! # The Kuratowski embedding Any separable metric space can be embedded isometrically in `ℓ^∞(ℕ, ℝ)`. Any partially defined Lipschitz map into `ℓ^∞` can be extended to the whole space. -/ noncomputable section open Set Metric TopologicalSpace NNReal ENNReal lp Function universe u variable {α : Type u} namespace KuratowskiEmbedding /-! ### Any separable metric space can be embedded isometrically in ℓ^∞(ℕ, ℝ) -/ variable {n : ℕ} [MetricSpace α] (x : ℕ → α) (a : α) /-- A metric space can be embedded in `l^∞(ℝ)` via the distances to points in a fixed countable set, if this set is dense. This map is given in `kuratowskiEmbedding`, without density assumptions. -/ def embeddingOfSubset : ℓ^∞(ℕ) := ⟨fun n => dist a (x n) - dist (x 0) (x n), by apply memℓp_infty use dist a (x 0) rintro - ⟨n, rfl⟩ exact abs_dist_sub_le _ _ _⟩ theorem embeddingOfSubset_coe : embeddingOfSubset x a n = dist a (x n) - dist (x 0) (x n) := rfl /-- The embedding map is always a semi-contraction. -/ theorem embeddingOfSubset_dist_le (a b : α) : dist (embeddingOfSubset x a) (embeddingOfSubset x b) ≤ dist a b := by refine lp.norm_le_of_forall_le dist_nonneg fun n => ?_ simp only [lp.coeFn_sub, Pi.sub_apply, embeddingOfSubset_coe] convert abs_dist_sub_le a b (x n) using 2 ring /-- When the reference set is dense, the embedding map is an isometry on its image. -/ theorem embeddingOfSubset_isometry (H : DenseRange x) : Isometry (embeddingOfSubset x) := by refine Isometry.of_dist_eq fun a b => ?_ refine (embeddingOfSubset_dist_le x a b).antisymm (le_of_forall_pos_le_add fun e epos => ?_) -- First step: find n with dist a (x n) < e rcases Metric.mem_closure_range_iff.1 (H a) (e / 2) (half_pos epos) with ⟨n, hn⟩ -- Second step: use the norm control at index n to conclude have C : dist b (x n) - dist a (x n) = embeddingOfSubset x b n - embeddingOfSubset x a n := by simp only [embeddingOfSubset_coe, sub_sub_sub_cancel_right] have := calc dist a b ≤ dist a (x n) + dist (x n) b := dist_triangle _ _ _ _ = 2 * dist a (x n) + (dist b (x n) - dist a (x n)) := by simp [dist_comm]; ring _ ≤ 2 * dist a (x n) + |dist b (x n) - dist a (x n)| := by grw [← le_abs_self] _ ≤ 2 * (e / 2) + |embeddingOfSubset x b n - embeddingOfSubset x a n| := by rw [C] gcongr _ ≤ 2 * (e / 2) + dist (embeddingOfSubset x b) (embeddingOfSubset x a) := by gcongr simp only [dist_eq_norm] exact lp.norm_apply_le_norm ENNReal.top_ne_zero (embeddingOfSubset x b - embeddingOfSubset x a) n _ = dist (embeddingOfSubset x b) (embeddingOfSubset x a) + e := by ring simpa [dist_comm] using this /-- Every separable metric space embeds isometrically in `ℓ^∞(ℕ)`. -/ theorem exists_isometric_embedding (α : Type u) [MetricSpace α] [SeparableSpace α] : ∃ f : α → ℓ^∞(ℕ), Isometry f := by rcases (univ : Set α).eq_empty_or_nonempty with h | h · use fun _ => 0; intro x; exact absurd h (Nonempty.ne_empty ⟨x, mem_univ x⟩) · -- We construct a map x : ℕ → α with dense image rcases h with ⟨basepoint⟩ haveI : Inhabited α := ⟨basepoint⟩ have : ∃ s : Set α, s.Countable ∧ Dense s := exists_countable_dense α rcases this with ⟨S, ⟨S_countable, S_dense⟩⟩ rcases Set.countable_iff_exists_subset_range.1 S_countable with ⟨x, x_range⟩ -- Use embeddingOfSubset to construct the desired isometry exact ⟨embeddingOfSubset x, embeddingOfSubset_isometry x (S_dense.mono x_range)⟩ end KuratowskiEmbedding open KuratowskiEmbedding /-- The Kuratowski embedding is an isometric embedding of a separable metric space in `ℓ^∞(ℕ, ℝ)`. -/ def kuratowskiEmbedding (α : Type u) [MetricSpace α] [SeparableSpace α] : α → ℓ^∞(ℕ) := Classical.choose (KuratowskiEmbedding.exists_isometric_embedding α) /-- The Kuratowski embedding is an isometry. Theorem 2.1 of [Assaf Naor, *Metric Embeddings and Lipschitz Extensions*][Naor-2015]. -/ protected theorem kuratowskiEmbedding.isometry (α : Type u) [MetricSpace α] [SeparableSpace α] : Isometry (kuratowskiEmbedding α) := Classical.choose_spec (exists_isometric_embedding α) /-- Version of the Kuratowski embedding for nonempty compacts -/ nonrec def NonemptyCompacts.kuratowskiEmbedding (α : Type u) [MetricSpace α] [CompactSpace α] [Nonempty α] : NonemptyCompacts ℓ^∞(ℕ) where carrier := range (kuratowskiEmbedding α) isCompact' := isCompact_range (kuratowskiEmbedding.isometry α).continuous nonempty' := range_nonempty _ /-- A function `f : α → ℓ^∞(ι, ℝ)` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension to the whole space. Theorem 2.2 of [Assaf Naor, *Metric Embeddings and Lipschitz Extensions*][Naor-2015] The same result for the case of a finite type `ι` is implemented in `LipschitzOnWith.extend_pi`. -/ theorem LipschitzOnWith.extend_lp_infty [PseudoMetricSpace α] {s : Set α} {ι : Type*} {f : α → ℓ^∞(ι)} {K : ℝ≥0} (hfl : LipschitzOnWith K f s) : ∃ g : α → ℓ^∞(ι), LipschitzWith K g ∧ EqOn f g s := by -- Construct the coordinate-wise extensions rw [LipschitzOnWith.coordinate] at hfl have (i : ι) : ∃ g : α → ℝ, LipschitzWith K g ∧ EqOn (fun x => f x i) g s := LipschitzOnWith.extend_real (hfl i) -- use the nonlinear Hahn-Banach theorem here! choose g hgl hgeq using this rcases s.eq_empty_or_nonempty with rfl | ⟨a₀, ha₀_in_s⟩ · exact ⟨0, LipschitzWith.const' 0, by simp⟩ · -- Show that the extensions are uniformly bounded have hf_extb : ∀ a : α, Memℓp (swap g a) ∞ := by apply LipschitzWith.uniformly_bounded (swap g) hgl a₀ use ‖f a₀‖ rintro - ⟨i, rfl⟩ simp_rw [← hgeq i ha₀_in_s] exact lp.norm_apply_le_norm top_ne_zero (f a₀) i -- Construct witness by bundling the function with its certificate of membership in ℓ^∞ let f_ext' : α → ℓ^∞(ι) := fun i ↦ ⟨swap g i, hf_extb i⟩ refine ⟨f_ext', ?_, ?_⟩ · rw [LipschitzWith.coordinate] exact hgl · intro a hyp ext i exact (hgeq i) hyp
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Cauchy.lean
import Mathlib.Topology.MetricSpace.Pseudo.Lemmas import Mathlib.Topology.EMetricSpace.Basic /-! ## Cauchy sequences in (pseudo-)metric spaces Various results on Cauchy sequences in (pseudo-)metric spaces, including * `Metric.complete_of_cauchySeq_tendsto` A pseudo-metric space is complete iff each Cauchy sequences converges to some limit point. * `cauchySeq_bdd`: a Cauchy sequence on the natural numbers is bounded * various characterisation of Cauchy and uniformly Cauchy sequences ## Tags metric, pseudo_metric, Cauchy sequence -/ open Filter open scoped Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} variable [PseudoMetricSpace α] /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem Metric.complete_of_convergent_controlled_sequences (B : ℕ → Real) (hB : ∀ n, 0 < B n) (H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) : CompleteSpace α := UniformSpace.complete_of_convergent_controlled_sequences (fun n => { p : α × α | dist p.1 p.2 < B n }) (fun n => dist_mem_uniformity <| hB n) H /-- A pseudo-metric space is complete iff every Cauchy sequence converges. -/ theorem Metric.complete_of_cauchySeq_tendsto : (∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α := EMetric.complete_of_cauchySeq_tendsto section CauchySeq variable [Nonempty β] [SemilatticeSup β] /-- In a pseudometric space, Cauchy sequences are characterized by the fact that, eventually, the distance between its elements is arbitrarily small -/ theorem Metric.cauchySeq_iff {u : β → α} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m ≥ N, ∀ n ≥ N, dist (u m) (u n) < ε := uniformity_basis_dist.cauchySeq_iff /-- A variation around the pseudometric characterization of Cauchy sequences -/ theorem Metric.cauchySeq_iff' {u : β → α} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, dist (u n) (u N) < ε := uniformity_basis_dist.cauchySeq_iff' -- see Note [nolint_ge] /-- In a pseudometric space, uniform Cauchy sequences are characterized by the fact that, eventually, the distance between all its elements is uniformly, arbitrarily small. -/ theorem Metric.uniformCauchySeqOn_iff {γ : Type*} {F : β → γ → α} {s : Set γ} : UniformCauchySeqOn F atTop s ↔ ∀ ε > (0 : ℝ), ∃ N : β, ∀ m ≥ N, ∀ n ≥ N, ∀ x ∈ s, dist (F m x) (F n x) < ε := by constructor · intro h ε hε let u := { a : α × α | dist a.fst a.snd < ε } have hu : u ∈ 𝓤 α := Metric.mem_uniformity_dist.mpr ⟨ε, hε, by simp [u]⟩ rw [← Filter.eventually_atTop_prod_self' (p := fun m => ∀ x ∈ s, dist (F m.fst x) (F m.snd x) < ε)] specialize h u hu rw [prod_atTop_atTop_eq] at h exact h.mono fun n h x hx => h x hx · intro h u hu rcases Metric.mem_uniformity_dist.mp hu with ⟨ε, hε, hab⟩ rcases h ε hε with ⟨N, hN⟩ rw [prod_atTop_atTop_eq, eventually_atTop] use (N, N) intro b hb x hx rcases hb with ⟨hbl, hbr⟩ exact hab (hN b.fst hbl.ge b.snd hbr.ge x hx) /-- If the distance between `s n` and `s m`, `n ≤ m` is bounded above by `b n` and `b` converges to zero, then `s` is a Cauchy sequence. -/ theorem cauchySeq_of_le_tendsto_0' {s : β → α} (b : β → ℝ) (h : ∀ n m : β, n ≤ m → dist (s n) (s m) ≤ b n) (h₀ : Tendsto b atTop (𝓝 0)) : CauchySeq s := Metric.cauchySeq_iff'.2 fun ε ε0 => (h₀.eventually (gt_mem_nhds ε0)).exists.imp fun N hN n hn => calc dist (s n) (s N) = dist (s N) (s n) := dist_comm _ _ _ ≤ b N := h _ _ hn _ < ε := hN /-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N` and `b` converges to zero, then `s` is a Cauchy sequence. -/ theorem cauchySeq_of_le_tendsto_0 {s : β → α} (b : β → ℝ) (h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : Tendsto b atTop (𝓝 0)) : CauchySeq s := cauchySeq_of_le_tendsto_0' b (fun _n _m hnm => h _ _ _ le_rfl hnm) h₀ /-- A Cauchy sequence on the natural numbers is bounded. -/ theorem cauchySeq_bdd {u : ℕ → α} (hu : CauchySeq u) : ∃ R > 0, ∀ m n, dist (u m) (u n) < R := by rcases Metric.cauchySeq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩ rsuffices ⟨R, R0, H⟩ : ∃ R > 0, ∀ n, dist (u n) (u N) < R · exact ⟨_, add_pos R0 R0, fun m n => lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ let R := Finset.sup (Finset.range N) fun n => nndist (u n) (u N) refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, fun n => ?_⟩ rcases le_or_gt N n with h | h · exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) · have : _ ≤ R := Finset.le_sup (Finset.mem_range.2 h) exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the most efficient. -/ theorem cauchySeq_iff_le_tendsto_0 {s : ℕ → α} : CauchySeq s ↔ ∃ b : ℕ → ℝ, (∀ n, 0 ≤ b n) ∧ (∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧ Tendsto b atTop (𝓝 0) := ⟨fun hs => by /- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking the supremum of the distances between `s n` and `s m` for `n m ≥ N`. First, we prove that all these distances are bounded, as otherwise the Sup would not make sense. -/ let S N := (fun p : ℕ × ℕ => dist (s p.1) (s p.2)) '' { p | p.1 ≥ N ∧ p.2 ≥ N } have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x := by rcases cauchySeq_bdd hs with ⟨R, -, hR⟩ refine fun N => ⟨R, ?_⟩ rintro _ ⟨⟨m, n⟩, _, rfl⟩ exact le_of_lt (hR m n) -- Prove that it bounds the distances of points in the Cauchy sequence have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ sSup (S N) := fun m n N hm hn => le_csSup (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩ have S0m : ∀ n, (0 : ℝ) ∈ S n := fun n => ⟨⟨n, n⟩, ⟨le_rfl, le_rfl⟩, dist_self _⟩ have S0 := fun n => le_csSup (hS n) (S0m n) -- Prove that it tends to `0`, by using the Cauchy property of `s` refine ⟨fun N => sSup (S N), S0, ub, Metric.tendsto_atTop.2 fun ε ε0 => ?_⟩ refine (Metric.cauchySeq_iff.1 hs (ε / 2) (half_pos ε0)).imp fun N hN n hn => ?_ rw [Real.dist_0_eq_abs, abs_of_nonneg (S0 n)] refine lt_of_le_of_lt (csSup_le ⟨_, S0m _⟩ ?_) (half_lt_self ε0) rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩ exact le_of_lt (hN _ (le_trans hn hm') _ (le_trans hn hn')), fun ⟨b, _, b_bound, b_lim⟩ => cauchySeq_of_le_tendsto_0 b b_bound b_lim⟩ lemma Metric.exists_subseq_bounded_of_cauchySeq (u : ℕ → α) (hu : CauchySeq u) (b : ℕ → ℝ) (hb : ∀ n, 0 < b n) : ∃ f : ℕ → ℕ, StrictMono f ∧ ∀ n, ∀ m ≥ f n, dist (u m) (u (f n)) < b n := by rw [cauchySeq_iff] at hu have hu' : ∀ k, ∀ᶠ (n : ℕ) in atTop, ∀ m ≥ n, dist (u m) (u n) < b k := by intro k rw [eventually_atTop] obtain ⟨N, hN⟩ := hu (b k) (hb k) exact ⟨N, fun m hm r hr => hN r (hm.trans hr) m hm⟩ exact Filter.extraction_forall_of_eventually hu' end CauchySeq
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Holder.lean
import Mathlib.Topology.MetricSpace.Lipschitz import Mathlib.Analysis.SpecialFunctions.Pow.Continuity /-! # Hölder continuous functions In this file we define Hölder continuity on a set and on the whole space. We also prove some basic properties of Hölder continuous functions. ## Main definitions * `HolderOnWith`: `f : X → Y` is said to be *Hölder continuous* with constant `C : ℝ≥0` and exponent `r : ℝ≥0` on a set `s`, if `edist (f x) (f y) ≤ C * edist x y ^ r` for all `x y ∈ s`; * `HolderWith`: `f : X → Y` is said to be *Hölder continuous* with constant `C : ℝ≥0` and exponent `r : ℝ≥0`, if `edist (f x) (f y) ≤ C * edist x y ^ r` for all `x y : X`. ## Implementation notes We use the type `ℝ≥0` (a.k.a. `NNReal`) for `C` because this type has coercion both to `ℝ` and `ℝ≥0∞`, so it can be easily used both in inequalities about `dist` and `edist`. We also use `ℝ≥0` for `r` to ensure that `d ^ r` is monotone in `d`. It might be a good idea to use `ℝ>0` for `r` but we don't have this type in `mathlib` (yet). ## Tags Hölder continuity, Lipschitz continuity -/ variable {X Y Z : Type*} open Filter Set open NNReal ENNReal Topology section Emetric variable [PseudoEMetricSpace X] [PseudoEMetricSpace Y] [PseudoEMetricSpace Z] /-- A function `f : X → Y` between two `PseudoEMetricSpace`s is Hölder continuous with constant `C : ℝ≥0` and exponent `r : ℝ≥0`, if `edist (f x) (f y) ≤ C * edist x y ^ r` for all `x y : X`. -/ def HolderWith (C r : ℝ≥0) (f : X → Y) : Prop := ∀ x y, edist (f x) (f y) ≤ (C : ℝ≥0∞) * edist x y ^ (r : ℝ) /-- A function `f : X → Y` between two `PseudoEMetricSpace`s is Hölder continuous with constant `C : ℝ≥0` and exponent `r : ℝ≥0` on a set `s : Set X`, if `edist (f x) (f y) ≤ C * edist x y ^ r` for all `x y ∈ s`. -/ def HolderOnWith (C r : ℝ≥0) (f : X → Y) (s : Set X) : Prop := ∀ x ∈ s, ∀ y ∈ s, edist (f x) (f y) ≤ (C : ℝ≥0∞) * edist x y ^ (r : ℝ) @[simp] theorem holderOnWith_empty (C r : ℝ≥0) (f : X → Y) : HolderOnWith C r f ∅ := fun _ hx => hx.elim @[simp] theorem holderOnWith_singleton (C r : ℝ≥0) (f : X → Y) (x : X) : HolderOnWith C r f {x} := by rintro a (rfl : a = x) b (rfl : b = a) rw [edist_self] exact zero_le _ theorem Set.Subsingleton.holderOnWith {s : Set X} (hs : s.Subsingleton) (C r : ℝ≥0) (f : X → Y) : HolderOnWith C r f s := hs.induction_on (holderOnWith_empty C r f) (holderOnWith_singleton C r f) theorem holderOnWith_univ {C r : ℝ≥0} {f : X → Y} : HolderOnWith C r f univ ↔ HolderWith C r f := by simp only [HolderOnWith, HolderWith, mem_univ, true_imp_iff] @[simp] theorem holderOnWith_one {C : ℝ≥0} {f : X → Y} {s : Set X} : HolderOnWith C 1 f s ↔ LipschitzOnWith C f s := by simp only [HolderOnWith, LipschitzOnWith, NNReal.coe_one, ENNReal.rpow_one] alias ⟨_, LipschitzOnWith.holderOnWith⟩ := holderOnWith_one @[simp] theorem holderWith_one {C : ℝ≥0} {f : X → Y} : HolderWith C 1 f ↔ LipschitzWith C f := holderOnWith_univ.symm.trans <| holderOnWith_one.trans lipschitzOnWith_univ alias ⟨_, LipschitzWith.holderWith⟩ := holderWith_one theorem holderWith_id : HolderWith 1 1 (id : X → X) := LipschitzWith.id.holderWith protected theorem HolderWith.holderOnWith {C r : ℝ≥0} {f : X → Y} (h : HolderWith C r f) (s : Set X) : HolderOnWith C r f s := fun x _ y _ => h x y namespace HolderOnWith variable {C r : ℝ≥0} {f : X → Y} {s t : Set X} theorem edist_le (h : HolderOnWith C r f s) {x y : X} (hx : x ∈ s) (hy : y ∈ s) : edist (f x) (f y) ≤ (C : ℝ≥0∞) * edist x y ^ (r : ℝ) := h x hx y hy theorem edist_le_of_le (h : HolderOnWith C r f s) {x y : X} (hx : x ∈ s) (hy : y ∈ s) {d : ℝ≥0∞} (hd : edist x y ≤ d) : edist (f x) (f y) ≤ (C : ℝ≥0∞) * d ^ (r : ℝ) := (h.edist_le hx hy).trans <| by gcongr theorem comp {Cg rg : ℝ≥0} {g : Y → Z} {t : Set Y} (hg : HolderOnWith Cg rg g t) {Cf rf : ℝ≥0} {f : X → Y} (hf : HolderOnWith Cf rf f s) (hst : MapsTo f s t) : HolderOnWith (Cg * Cf ^ (rg : ℝ)) (rg * rf) (g ∘ f) s := by intro x hx y hy rw [ENNReal.coe_mul, mul_comm rg, NNReal.coe_mul, ENNReal.rpow_mul, mul_assoc, ENNReal.coe_rpow_of_nonneg _ rg.coe_nonneg, ← ENNReal.mul_rpow_of_nonneg _ _ rg.coe_nonneg] exact hg.edist_le_of_le (hst hx) (hst hy) (hf.edist_le hx hy) theorem comp_holderWith {Cg rg : ℝ≥0} {g : Y → Z} {t : Set Y} (hg : HolderOnWith Cg rg g t) {Cf rf : ℝ≥0} {f : X → Y} (hf : HolderWith Cf rf f) (ht : ∀ x, f x ∈ t) : HolderWith (Cg * Cf ^ (rg : ℝ)) (rg * rf) (g ∘ f) := holderOnWith_univ.mp <| hg.comp (hf.holderOnWith univ) fun x _ => ht x /-- A Hölder continuous function is uniformly continuous -/ protected theorem uniformContinuousOn (hf : HolderOnWith C r f s) (h0 : 0 < r) : UniformContinuousOn f s := by refine EMetric.uniformContinuousOn_iff.2 fun ε εpos => ?_ have : Tendsto (fun d : ℝ≥0∞ => (C : ℝ≥0∞) * d ^ (r : ℝ)) (𝓝 0) (𝓝 0) := ENNReal.tendsto_const_mul_rpow_nhds_zero_of_pos ENNReal.coe_ne_top h0 rcases ENNReal.nhds_zero_basis.mem_iff.1 (this (gt_mem_nhds εpos)) with ⟨δ, δ0, H⟩ exact ⟨δ, δ0, fun hx y hy h => (hf.edist_le hx hy).trans_lt (H h)⟩ protected theorem continuousOn (hf : HolderOnWith C r f s) (h0 : 0 < r) : ContinuousOn f s := (hf.uniformContinuousOn h0).continuousOn protected theorem mono (hf : HolderOnWith C r f s) (ht : t ⊆ s) : HolderOnWith C r f t := fun _ hx _ hy => hf.edist_le (ht hx) (ht hy) theorem ediam_image_le_of_le (hf : HolderOnWith C r f s) {d : ℝ≥0∞} (hd : EMetric.diam s ≤ d) : EMetric.diam (f '' s) ≤ (C : ℝ≥0∞) * d ^ (r : ℝ) := EMetric.diam_image_le_iff.2 fun _ hx _ hy => hf.edist_le_of_le hx hy <| (EMetric.edist_le_diam_of_mem hx hy).trans hd theorem ediam_image_le (hf : HolderOnWith C r f s) : EMetric.diam (f '' s) ≤ (C : ℝ≥0∞) * EMetric.diam s ^ (r : ℝ) := hf.ediam_image_le_of_le le_rfl theorem ediam_image_le_of_subset (hf : HolderOnWith C r f s) (ht : t ⊆ s) : EMetric.diam (f '' t) ≤ (C : ℝ≥0∞) * EMetric.diam t ^ (r : ℝ) := (hf.mono ht).ediam_image_le theorem ediam_image_le_of_subset_of_le (hf : HolderOnWith C r f s) (ht : t ⊆ s) {d : ℝ≥0∞} (hd : EMetric.diam t ≤ d) : EMetric.diam (f '' t) ≤ (C : ℝ≥0∞) * d ^ (r : ℝ) := (hf.mono ht).ediam_image_le_of_le hd theorem ediam_image_inter_le_of_le (hf : HolderOnWith C r f s) {d : ℝ≥0∞} (hd : EMetric.diam t ≤ d) : EMetric.diam (f '' (t ∩ s)) ≤ (C : ℝ≥0∞) * d ^ (r : ℝ) := hf.ediam_image_le_of_subset_of_le inter_subset_right <| (EMetric.diam_mono inter_subset_left).trans hd theorem ediam_image_inter_le (hf : HolderOnWith C r f s) (t : Set X) : EMetric.diam (f '' (t ∩ s)) ≤ (C : ℝ≥0∞) * EMetric.diam t ^ (r : ℝ) := hf.ediam_image_inter_le_of_le le_rfl end HolderOnWith namespace HolderWith variable {C r : ℝ≥0} {f : X → Y} theorem restrict_iff {s : Set X} : HolderWith C r (s.restrict f) ↔ HolderOnWith C r f s := by simp [HolderWith, HolderOnWith] protected alias ⟨_, _root_.HolderOnWith.holderWith⟩ := restrict_iff theorem edist_le (h : HolderWith C r f) (x y : X) : edist (f x) (f y) ≤ (C : ℝ≥0∞) * edist x y ^ (r : ℝ) := h x y theorem edist_le_of_le (h : HolderWith C r f) {x y : X} {d : ℝ≥0∞} (hd : edist x y ≤ d) : edist (f x) (f y) ≤ (C : ℝ≥0∞) * d ^ (r : ℝ) := (h.holderOnWith univ).edist_le_of_le trivial trivial hd theorem comp {Cg rg : ℝ≥0} {g : Y → Z} (hg : HolderWith Cg rg g) {Cf rf : ℝ≥0} {f : X → Y} (hf : HolderWith Cf rf f) : HolderWith (Cg * Cf ^ (rg : ℝ)) (rg * rf) (g ∘ f) := (hg.holderOnWith univ).comp_holderWith hf fun _ => trivial theorem comp_holderOnWith {Cg rg : ℝ≥0} {g : Y → Z} (hg : HolderWith Cg rg g) {Cf rf : ℝ≥0} {f : X → Y} {s : Set X} (hf : HolderOnWith Cf rf f s) : HolderOnWith (Cg * Cf ^ (rg : ℝ)) (rg * rf) (g ∘ f) s := (hg.holderOnWith univ).comp hf fun _ _ => trivial /-- A Hölder continuous function is uniformly continuous -/ protected theorem uniformContinuous (hf : HolderWith C r f) (h0 : 0 < r) : UniformContinuous f := uniformContinuousOn_univ.mp <| (hf.holderOnWith univ).uniformContinuousOn h0 protected theorem continuous (hf : HolderWith C r f) (h0 : 0 < r) : Continuous f := (hf.uniformContinuous h0).continuous theorem ediam_image_le (hf : HolderWith C r f) (s : Set X) : EMetric.diam (f '' s) ≤ (C : ℝ≥0∞) * EMetric.diam s ^ (r : ℝ) := EMetric.diam_image_le_iff.2 fun _ hx _ hy => hf.edist_le_of_le <| EMetric.edist_le_diam_of_mem hx hy lemma const {y : Y} : HolderWith C r (Function.const X y) := fun x₁ x₂ => by simp only [Function.const_apply, edist_self, zero_le] lemma zero [Zero Y] : HolderWith C r (0 : X → Y) := .const lemma of_isEmpty [IsEmpty X] : HolderWith C r f := isEmptyElim lemma mono {C' : ℝ≥0} (hf : HolderWith C r f) (h : C ≤ C') : HolderWith C' r f := fun x₁ x₂ ↦ (hf x₁ x₂).trans (by gcongr) end HolderWith end Emetric section PseudoMetric variable [PseudoMetricSpace X] [PseudoMetricSpace Y] {C r : ℝ≥0} {f : X → Y} {s : Set X} {x y : X} namespace HolderOnWith theorem nndist_le_of_le (hf : HolderOnWith C r f s) (hx : x ∈ s) (hy : y ∈ s) {d : ℝ≥0} (hd : nndist x y ≤ d) : nndist (f x) (f y) ≤ C * d ^ (r : ℝ) := by rw [← ENNReal.coe_le_coe, ← edist_nndist, ENNReal.coe_mul, ENNReal.coe_rpow_of_nonneg _ r.coe_nonneg] apply hf.edist_le_of_le hx hy rwa [edist_nndist, ENNReal.coe_le_coe] theorem nndist_le (hf : HolderOnWith C r f s) (hx : x ∈ s) (hy : y ∈ s) : nndist (f x) (f y) ≤ C * nndist x y ^ (r : ℝ) := hf.nndist_le_of_le hx hy le_rfl theorem dist_le_of_le (hf : HolderOnWith C r f s) (hx : x ∈ s) (hy : y ∈ s) {d : ℝ} (hd : dist x y ≤ d) : dist (f x) (f y) ≤ C * d ^ (r : ℝ) := by lift d to ℝ≥0 using dist_nonneg.trans hd rw [dist_nndist] at hd ⊢ norm_cast at hd ⊢ exact hf.nndist_le_of_le hx hy hd theorem dist_le (hf : HolderOnWith C r f s) (hx : x ∈ s) (hy : y ∈ s) : dist (f x) (f y) ≤ C * dist x y ^ (r : ℝ) := hf.dist_le_of_le hx hy le_rfl end HolderOnWith namespace HolderWith theorem nndist_le_of_le (hf : HolderWith C r f) {x y : X} {d : ℝ≥0} (hd : nndist x y ≤ d) : nndist (f x) (f y) ≤ C * d ^ (r : ℝ) := (hf.holderOnWith univ).nndist_le_of_le (mem_univ x) (mem_univ y) hd theorem nndist_le (hf : HolderWith C r f) (x y : X) : nndist (f x) (f y) ≤ C * nndist x y ^ (r : ℝ) := hf.nndist_le_of_le le_rfl theorem dist_le_of_le (hf : HolderWith C r f) {x y : X} {d : ℝ} (hd : dist x y ≤ d) : dist (f x) (f y) ≤ C * d ^ (r : ℝ) := (hf.holderOnWith univ).dist_le_of_le (mem_univ x) (mem_univ y) hd theorem dist_le (hf : HolderWith C r f) (x y : X) : dist (f x) (f y) ≤ C * dist x y ^ (r : ℝ) := hf.dist_le_of_le le_rfl end HolderWith end PseudoMetric section Metric variable [PseudoMetricSpace X] [MetricSpace Y] {r : ℝ≥0} {f : X → Y} @[simp] lemma holderWith_zero_iff : HolderWith 0 r f ↔ ∀ x₁ x₂, f x₁ = f x₂ := by refine ⟨fun h x₁ x₂ => ?_, fun h x₁ x₂ => h x₁ x₂ ▸ ?_⟩ · specialize h x₁ x₂ simp [ENNReal.coe_zero, zero_mul, nonpos_iff_eq_zero, edist_eq_zero] at h assumption · simp only [edist_self, ENNReal.coe_zero, zero_mul, le_refl] end Metric section SeminormedAddCommGroup variable [PseudoMetricSpace X] [SeminormedAddCommGroup Y] {C C' r : ℝ≥0} {f g : X → Y} namespace HolderWith lemma add (hf : HolderWith C r f) (hg : HolderWith C' r g) : HolderWith (C + C') r (f + g) := by intro x₁ x₂ simp only [Pi.add_apply, coe_add] grw [edist_add_add_le, hf x₁ x₂, hg x₁ x₂] rw [add_mul] lemma smul {α} [SeminormedAddCommGroup α] [SMulZeroClass α Y] [IsBoundedSMul α Y] (a : α) (hf : HolderWith C r f) : HolderWith (C * ‖a‖₊) r (a • f) := fun x₁ x₂ => by refine edist_smul_le _ _ _ |>.trans ?_ rw [coe_mul, ENNReal.smul_def, smul_eq_mul, mul_comm (C : ℝ≥0∞), mul_assoc] gcongr exact hf x₁ x₂ lemma smul_iff {α} [SeminormedRing α] [Module α Y] [NormSMulClass α Y] (a : α) (ha : ‖a‖₊ ≠ 0) : HolderWith (C * ‖a‖₊) r (a • f) ↔ HolderWith C r f := by simp_rw [HolderWith, coe_mul, Pi.smul_apply, edist_smul₀, ENNReal.smul_def, smul_eq_mul, mul_comm (C : ℝ≥0∞), mul_assoc, ENNReal.mul_le_mul_left (ENNReal.coe_ne_zero.mpr ha) ENNReal.coe_ne_top, mul_comm] end HolderWith end SeminormedAddCommGroup
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Completion.lean
import Mathlib.Topology.Algebra.GroupCompletion import Mathlib.Topology.Algebra.Ring.Real import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.Isometry import Mathlib.Topology.MetricSpace.Lipschitz import Mathlib.Topology.UniformSpace.Completion /-! # The completion of a metric space Completion of uniform spaces are already defined in `Topology.UniformSpace.Completion`. We show here that the uniform space completion of a metric space inherits a metric space structure, by extending the distance to the completion and checking that it is indeed a distance, and that it defines the same uniformity as the already defined uniform structure on the completion -/ open Set Filter UniformSpace Metric open Filter Topology Uniformity noncomputable section universe u v variable {α : Type u} {β : Type v} [PseudoMetricSpace α] namespace UniformSpace.Completion /-- The distance on the completion is obtained by extending the distance on the original space, by uniform continuity. -/ instance : Dist (Completion α) := ⟨Completion.extension₂ dist⟩ /-- The new distance is uniformly continuous. -/ protected theorem uniformContinuous_dist : UniformContinuous fun p : Completion α × Completion α ↦ dist p.1 p.2 := uniformContinuous_extension₂ dist /-- The new distance is continuous. -/ protected theorem continuous_dist [TopologicalSpace β] {f g : β → Completion α} (hf : Continuous f) (hg : Continuous g) : Continuous fun x ↦ dist (f x) (g x) := Completion.uniformContinuous_dist.continuous.comp (hf.prodMk hg :) /-- The new distance is an extension of the original distance. -/ @[simp] protected theorem dist_eq (x y : α) : dist (x : Completion α) y = dist x y := Completion.extension₂_coe_coe uniformContinuous_dist _ _ /- Let us check that the new distance satisfies the axioms of a distance, by starting from the properties on α and extending them to `Completion α` by continuity. -/ protected theorem dist_self (x : Completion α) : dist x x = 0 := by refine induction_on x ?_ ?_ · refine isClosed_eq ?_ continuous_const exact Completion.continuous_dist continuous_id continuous_id · intro a rw [Completion.dist_eq, dist_self] protected theorem dist_comm (x y : Completion α) : dist x y = dist y x := by refine induction_on₂ x y ?_ ?_ · exact isClosed_eq (Completion.continuous_dist continuous_fst continuous_snd) (Completion.continuous_dist continuous_snd continuous_fst) · intro a b rw [Completion.dist_eq, Completion.dist_eq, dist_comm] protected theorem dist_triangle (x y z : Completion α) : dist x z ≤ dist x y + dist y z := by refine induction_on₃ x y z ?_ ?_ · refine isClosed_le ?_ (Continuous.add ?_ ?_) <;> apply_rules [Completion.continuous_dist, Continuous.fst, Continuous.snd, continuous_id] · intro a b c rw [Completion.dist_eq, Completion.dist_eq, Completion.dist_eq] exact dist_triangle a b c /-- Elements of the uniformity (defined generally for completions) can be characterized in terms of the distance. -/ protected theorem mem_uniformity_dist (s : Set (Completion α × Completion α)) : s ∈ 𝓤 (Completion α) ↔ ∃ ε > 0, ∀ {a b}, dist a b < ε → (a, b) ∈ s := by constructor · /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in `α` is an entourage, so it contains an `ε`-neighborhood of the diagonal by definition of the entourages in metric spaces. Then `t` contains an `ε`-neighborhood of the diagonal in `Completion α`, as closed properties pass to the completion. -/ intro hs rcases mem_uniformity_isClosed hs with ⟨t, ht, ⟨tclosed, ts⟩⟩ have A : { x : α × α | (↑x.1, ↑x.2) ∈ t } ∈ uniformity α := uniformContinuous_def.1 (uniformContinuous_coe α) t ht rcases mem_uniformity_dist.1 A with ⟨ε, εpos, hε⟩ refine ⟨ε, εpos, @fun x y hxy ↦ ?_⟩ have : ε ≤ dist x y ∨ (x, y) ∈ t := by refine induction_on₂ x y ?_ ?_ · have : { x : Completion α × Completion α | ε ≤ dist x.fst x.snd ∨ (x.fst, x.snd) ∈ t } = { p : Completion α × Completion α | ε ≤ dist p.1 p.2 } ∪ t := by ext; simp rw [this] apply IsClosed.union _ tclosed exact isClosed_le continuous_const Completion.uniformContinuous_dist.continuous · intro x y rw [Completion.dist_eq] by_cases! h : ε ≤ dist x y · exact Or.inl h · have Z := hε h simp only [Set.mem_setOf_eq] at Z exact Or.inr Z simp only [not_le.mpr hxy, false_or] at this exact ts this · /- Start from a set `s` containing an ε-neighborhood of the diagonal in `Completion α`. To show that it is an entourage, we use the fact that `dist` is uniformly continuous on `Completion α × Completion α` (this is a general property of the extension of uniformly continuous functions). Therefore, the preimage of the ε-neighborhood of the diagonal in ℝ is an entourage in `Completion α × Completion α`. Massaging this property, it follows that the ε-neighborhood of the diagonal is an entourage in `Completion α`, and therefore this is also the case of `s`. -/ rintro ⟨ε, εpos, hε⟩ let r : Set (ℝ × ℝ) := { p | dist p.1 p.2 < ε } have : r ∈ uniformity ℝ := Metric.dist_mem_uniformity εpos have T := uniformContinuous_def.1 (@Completion.uniformContinuous_dist α _) r this simp only [uniformity_prod_eq_prod, mem_prod_iff, Filter.mem_map] at T rcases T with ⟨t1, ht1, t2, ht2, ht⟩ refine mem_of_superset ht1 ?_ have A : ∀ a b : Completion α, (a, b) ∈ t1 → dist a b < ε := by intro a b hab have : ((a, b), (a, a)) ∈ t1 ×ˢ t2 := ⟨hab, refl_mem_uniformity ht2⟩ exact lt_of_le_of_lt (le_abs_self _) (by simpa [r, Completion.dist_self, Real.dist_eq, Completion.dist_comm] using ht this) grind /-- Reformulate `Completion.mem_uniformity_dist` in terms that are suitable for the definition of the metric space structure. -/ protected theorem uniformity_dist' : 𝓤 (Completion α) = ⨅ ε : { ε : ℝ // 0 < ε }, 𝓟 { p | dist p.1 p.2 < ε.val } := by ext s; rw [mem_iInf_of_directed] · simp [Completion.mem_uniformity_dist, subset_def] · rintro ⟨r, hr⟩ ⟨p, hp⟩ use ⟨min r p, lt_min hr hp⟩ simp +contextual protected theorem uniformity_dist : 𝓤 (Completion α) = ⨅ ε > 0, 𝓟 { p | dist p.1 p.2 < ε } := by simpa [iInf_subtype] using @Completion.uniformity_dist' α _ /-- Metric space structure on the completion of a pseudo_metric space. -/ instance instMetricSpace : MetricSpace (Completion α) := @MetricSpace.ofT0PseudoMetricSpace _ { dist_self := Completion.dist_self dist_comm := Completion.dist_comm dist_triangle := Completion.dist_triangle dist := dist toUniformSpace := inferInstance uniformity_dist := Completion.uniformity_dist } _ /-- The embedding of a metric space in its completion is an isometry. -/ theorem coe_isometry : Isometry ((↑) : α → Completion α) := Isometry.of_dist_eq Completion.dist_eq @[simp] protected theorem edist_eq (x y : α) : edist (x : Completion α) y = edist x y := coe_isometry x y instance {M} [Zero M] [Zero α] [SMul M α] [PseudoMetricSpace M] [IsBoundedSMul M α] : IsBoundedSMul M (Completion α) where dist_smul_pair' c x₁ x₂ := by induction x₁, x₂ using induction_on₂ with | hp => exact isClosed_le ((continuous_fst.const_smul _).dist (continuous_snd.const_smul _)) (continuous_const.mul (continuous_fst.dist continuous_snd)) | ih x₁ x₂ => rw [← coe_smul, ← coe_smul, Completion.dist_eq, Completion.dist_eq] exact dist_smul_pair c x₁ x₂ dist_pair_smul' c₁ c₂ x := by induction x using induction_on with | hp => exact isClosed_le ((continuous_const_smul _).dist (continuous_const_smul _)) (continuous_const.mul (continuous_id.dist continuous_const)) | ih x => rw [← coe_smul, ← coe_smul, Completion.dist_eq, ← coe_zero, Completion.dist_eq] exact dist_pair_smul c₁ c₂ x end UniformSpace.Completion open UniformSpace Completion NNReal theorem LipschitzWith.completion_extension [MetricSpace β] [CompleteSpace β] {f : α → β} {K : ℝ≥0} (h : LipschitzWith K f) : LipschitzWith K (Completion.extension f) := LipschitzWith.of_dist_le_mul fun x y => induction_on₂ x y (isClosed_le (by fun_prop) (by fun_prop)) <| by simpa only [extension_coe h.uniformContinuous, Completion.dist_eq] using h.dist_le_mul theorem LipschitzWith.completion_map [PseudoMetricSpace β] {f : α → β} {K : ℝ≥0} (h : LipschitzWith K f) : LipschitzWith K (Completion.map f) := one_mul K ▸ (coe_isometry.lipschitz.comp h).completion_extension theorem Isometry.completion_extension [MetricSpace β] [CompleteSpace β] {f : α → β} (h : Isometry f) : Isometry (Completion.extension f) := Isometry.of_dist_eq fun x y => induction_on₂ x y (isClosed_eq (by fun_prop) (by fun_prop)) fun _ _ ↦ by simp only [extension_coe h.uniformContinuous, Completion.dist_eq, h.dist_eq] theorem Isometry.completion_map [PseudoMetricSpace β] {f : α → β} (h : Isometry f) : Isometry (Completion.map f) := (coe_isometry.comp h).completion_extension
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Cover.lean
import Mathlib.Data.Rel.Cover import Mathlib.Topology.MetricSpace.MetricSeparated import Mathlib.Topology.MetricSpace.Thickening /-! # Covers in a metric space This file defines covers, aka nets, which are a quantitative notion of compactness in a metric space. A `ε`-cover of a set `s` is a set `N` such that every element of `s` is at distance at most `ε` to some element of `N`. In a proper metric space, sets admitting a finite cover are precisely the relatively compact sets. ## References [R. Vershynin, *High Dimensional Probability*][vershynin2018high], Section 4.2. -/ open Set open scoped NNReal namespace Metric variable {X : Type*} section PseudoEMetricSpace variable [PseudoEMetricSpace X] {ε δ : ℝ≥0} {s t N N₁ N₂ : Set X} {x : X} instance : SetRel.IsRefl {(x, y) : X × X | edist x y ≤ ε} where refl := by simp instance : SetRel.IsSymm {(x, y) : X × X | edist x y ≤ ε} where symm := by simp [edist_comm] /-- A set `N` is an *`ε`-cover* of a set `s` if every point of `s` lies at distance at most `ε` of some point of `N`. This is also called an *`ε`-net* in the literature. [R. Vershynin, *High Dimensional Probability*][vershynin2018high], 4.2.1. -/ def IsCover (ε : ℝ≥0) (s N : Set X) : Prop := SetRel.IsCover {(x, y) | edist x y ≤ ε} s N @[simp] protected nonrec lemma IsCover.empty : IsCover ε ∅ N := .empty @[simp] lemma isCover_empty_right : IsCover ε s ∅ ↔ s = ∅ := SetRel.isCover_empty_right protected nonrec lemma IsCover.nonempty (hsN : IsCover ε s N) (hs : s.Nonempty) : N.Nonempty := hsN.nonempty hs @[simp] lemma IsCover.refl (ε : ℝ≥0) (s : Set X) : IsCover ε s s := .rfl lemma IsCover.rfl {ε : ℝ≥0} {s : Set X} : IsCover ε s s := refl ε s nonrec lemma IsCover.mono (hN : N₁ ⊆ N₂) (h₁ : IsCover ε s N₁) : IsCover ε s N₂ := h₁.mono hN nonrec lemma IsCover.anti (hst : s ⊆ t) (ht : IsCover ε t N) : IsCover ε s N := ht.anti hst lemma IsCover.mono_radius (hεδ : ε ≤ δ) (hε : IsCover ε s N) : IsCover δ s N := hε.mono_entourage fun xy hxy ↦ by dsimp at *; exact le_trans hxy <| mod_cast hεδ lemma IsCover.singleton_of_ediam_le (hA : EMetric.diam s ≤ ε) (hx : x ∈ s) : IsCover ε s ({x} : Set X) := fun _ h_mem ↦ ⟨x, by simp, (EMetric.edist_le_diam_of_mem h_mem hx).trans hA⟩ lemma isCover_iff_subset_iUnion_emetricClosedBall : IsCover ε s N ↔ s ⊆ ⋃ y ∈ N, EMetric.closedBall y ε := by simp [IsCover, SetRel.IsCover, subset_def] /-- A maximal `ε`-separated subset of a set `s` is an `ε`-cover of `s`. [R. Vershynin, *High Dimensional Probability*][vershynin2018high], 4.2.6. -/ nonrec lemma IsCover.of_maximal_isSeparated (hN : Maximal (fun N ↦ N ⊆ s ∧ IsSeparated ε N) N) : IsCover ε s N := .of_maximal_isSeparated <| by simpa [isSeparated_iff_setRelIsSeparated] using hN /-- A totally bounded set has finite `ε`-covers for all `ε > 0`. -/ lemma exists_finite_isCover_of_totallyBounded (hε : ε ≠ 0) (hs : TotallyBounded s) : ∃ N ⊆ s, N.Finite ∧ IsCover ε s N := by rw [EMetric.totallyBounded_iff'] at hs obtain ⟨N, hNA, hN_finite, hN⟩ := hs ε (mod_cast hε.bot_lt) simp only [isCover_iff_subset_iUnion_emetricClosedBall] refine ⟨N, by simpa, by simpa, ?_⟩ · refine hN.trans fun x hx ↦ ?_ simp only [Set.mem_iUnion, EMetric.mem_ball, exists_prop, EMetric.mem_closedBall] at hx ⊢ obtain ⟨y, hyN, hy⟩ := hx exact ⟨y, hyN, hy.le⟩ /-- A relatively compact set admits a finite cover. -/ lemma exists_finite_isCover_of_isCompact_closure (hε : ε ≠ 0) (hs : IsCompact (closure s)) : ∃ N ⊆ s, N.Finite ∧ IsCover ε s N := exists_finite_isCover_of_totallyBounded hε (hs.totallyBounded.subset subset_closure) /-- A compact set admits a finite cover. -/ lemma exists_finite_isCover_of_isCompact (hε : ε ≠ 0) (hs : IsCompact s) : ∃ N ⊆ s, N.Finite ∧ IsCover ε s N := exists_finite_isCover_of_totallyBounded hε hs.totallyBounded end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace X] {ε : ℝ≥0} {s N : Set X} lemma isCover_iff_subset_iUnion_closedBall : IsCover ε s N ↔ s ⊆ ⋃ y ∈ N, closedBall y ε := by simp [IsCover, SetRel.IsCover, subset_def] alias ⟨IsCover.subset_iUnion_closedBall, IsCover.of_subset_iUnion_closedBall⟩ := isCover_iff_subset_iUnion_closedBall lemma IsCover.of_subset_cthickening_of_lt {δ : ℝ≥0} (hsN : s ⊆ cthickening ε N) (hεδ : ε < δ) : IsCover δ s N := .of_subset_iUnion_closedBall <| hsN.trans (cthickening_subset_iUnion_closedBall_of_lt _ (NNReal.zero_le_coe.trans_lt hεδ) hεδ) variable [ProperSpace X] lemma isCover_iff_subset_cthickening (hN : IsClosed N) : IsCover ε s N ↔ s ⊆ cthickening ε N := by rw [isCover_iff_subset_iUnion_closedBall, hN.cthickening_eq_biUnion_closedBall ε.zero_le_coe] alias ⟨IsCover.subset_cthickening, IsCover.of_subset_cthickening⟩ := isCover_iff_subset_cthickening @[simp] lemma isCover_closure (hN : IsClosed N) : IsCover ε (closure s) N ↔ IsCover ε s N := by simpa [isCover_iff_subset_cthickening hN] using (isClosed_cthickening (E := N)).closure_subset_iff protected alias ⟨_, IsCover.closure⟩ := isCover_closure end PseudoMetricSpace section EMetricSpace variable [EMetricSpace X] {ε : ℝ≥0} {s N : Set X} {x : X} @[simp] lemma isCover_zero : IsCover 0 s N ↔ s ⊆ N := by simp [isCover_iff_subset_iUnion_emetricClosedBall] end EMetricSpace section MetricSpace variable [MetricSpace X] [ProperSpace X] {ε : ℝ≥0} {s t N N₁ N₂ : Set X} {x : X} /-- A closed set in a proper metric space which admits a compact cover is compact. -/ lemma IsCover.isCompact (hsN : IsCover ε s N) (hs : IsClosed s) (hN : IsCompact N) : IsCompact s := .of_isClosed_subset hN.cthickening hs <| hsN.subset_cthickening hN.isClosed /-- A set in a proper metric space which admits a compact cover is relatively compact. -/ lemma IsCover.isCompact_closure (hsN : IsCover ε s N) (hN : IsCompact N) : IsCompact (closure s) := (hsN.closure hN.isClosed).isCompact isClosed_closure hN /-- A set in a proper metric space admits a finite cover iff it is relatively compact. [R. Vershynin, *High Dimensional Probability*][vershynin2018high], 4.2.3. Note that the print edition incorrectly claims that this holds without the `ProperSpace X` assumption. -/ lemma isCompact_closure_iff_exists_finite_isCover (hε : ε ≠ 0) : IsCompact (closure s) ↔ ∃ N ⊆ s, N.Finite ∧ IsCover ε s N where mp := exists_finite_isCover_of_isCompact_closure hε mpr := fun ⟨_N, _, hN, hsN⟩ ↦ hsN.isCompact_closure hN.isCompact end MetricSpace end Metric
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/BundledFun.lean
import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Data.Finset.Lattice.Fold import Mathlib.Data.Rel /-! # Pseudometrics as bundled functions This file defines a pseudometric as a bundled function. This allows one to define a semilattice on them, and to construct families of pseudometrics. ## Implementation notes The `PseudoMetric` definition is made as general as possible without any required axioms for the codomain. The axioms come into play only in proofs and further constructions like the `SemilatticeSup` instance. This allows one to talk about functions mapping into something like `{ fuel: ℕ, time: ℕ }` even though there is no linear order. In most cases, the codomain will be a linear ordered additive monoid like `ℝ`, `ℝ≥0`, `ℝ≥0∞`, in which all of the axioms below are satisfied. -/ variable {X R : Type*} variable (X R) in /-- A pseudometric as a bundled function. -/ @[ext] structure PseudoMetric [Zero R] [Add R] [LE R] where /-- The underlying binary function mapping into a linearly ordered additive monoid. -/ toFun : X → X → R /-- A pseudometric must take identical elements to 0. -/ refl' x : toFun x x = 0 /-- A pseudometric must be symmetric. -/ symm' x y : toFun x y = toFun y x /-- A pseudometric must respect the triangle inequality. -/ triangle' x y z : toFun x z ≤ toFun x y + toFun y z namespace PseudoMetric section Basic variable [Zero R] [Add R] [LE R] (d : PseudoMetric X R) instance : FunLike (PseudoMetric X R) X (X → R) where coe := PseudoMetric.toFun coe_injective' _ := by aesop @[simp, norm_cast] lemma coe_mk (d : X → X → R) (refl symm triangle) : mk d refl symm triangle = d := rfl lemma mk_apply (d : X → X → R) (refl symm triangle) (x y : X) : mk d refl symm triangle x y = d x y := rfl @[simp] protected lemma refl (x : X) : d x x = 0 := d.refl' x protected lemma symm (x y : X) : d x y = d y x := d.symm' x y protected lemma triangle (x y z : X) : d x z ≤ d x y + d y z := d.triangle' x y z instance : LE (PseudoMetric X R) := ⟨fun d d' ↦ ⇑d ≤ d'⟩ @[simp, norm_cast] protected lemma coe_le_coe {d d' : PseudoMetric X R} : (d : X → X → R) ≤ d' ↔ d ≤ d' := Iff.rfl end Basic instance [Zero R] [Add R] [PartialOrder R] : PartialOrder (PseudoMetric X R) := .lift _ DFunLike.coe_injective instance [AddZeroClass R] [Preorder R] : Bot (PseudoMetric X R) where bot.toFun := 0 bot.refl' _ := rfl bot.symm' _ _ := rfl bot.triangle' _ _ _ := by simp @[simp, norm_cast] lemma coe_bot [AddZeroClass R] [Preorder R] : ⇑(⊥ : PseudoMetric X R) = 0 := rfl @[simp] protected lemma bot_apply [AddZeroClass R] [Preorder R] (x y : X) : (⊥ : PseudoMetric X R) x y = 0 := rfl instance [AddZeroClass R] [SemilatticeSup R] [AddLeftMono R] [AddRightMono R] : Max (PseudoMetric X R) where max d d' := { toFun := fun x y ↦ (d x y) ⊔ (d' x y) refl' _ := by simp symm' x y := by simp [d.symm, d'.symm] triangle' := by intro x y z simp only [sup_le_iff] refine ⟨(d.triangle x y z).trans ?_, (d'.triangle x y z).trans ?_⟩ <;> apply add_le_add <;> simp } @[simp, push_cast] lemma coe_sup [AddZeroClass R] [SemilatticeSup R] [AddLeftMono R] [AddRightMono R] (d d' : PseudoMetric X R) : ((d ⊔ d' : PseudoMetric X R) : X → X → R) = (d : X → X → R) ⊔ d' := rfl @[simp] protected lemma sup_apply [AddZeroClass R] [SemilatticeSup R] [AddLeftMono R] [AddRightMono R] (d d' : PseudoMetric X R) (x y : X) : (d ⊔ d') x y = d x y ⊔ d' x y := rfl instance [AddZeroClass R] [SemilatticeSup R] [AddLeftMono R] [AddRightMono R] : SemilatticeSup (PseudoMetric X R) where sup := max le_sup_left := by simp [← PseudoMetric.coe_le_coe] le_sup_right := by simp [← PseudoMetric.coe_le_coe] sup_le _ _ _ := fun h h' _ _ ↦ sup_le (h _ _) (h' _ _) section OrderBot variable [AddCommMonoid R] [LinearOrder R] [AddLeftStrictMono R] protected lemma nonneg (d : PseudoMetric X R) (x y : X) : 0 ≤ d x y := by by_contra! H have : d x x < 0 := by calc d x x ≤ d x y + d y x := d.triangle' x y x _ < 0 + 0 := by refine add_lt_add H (d.symm x y ▸ H) _ = 0 := by simp exact this.ne (d.refl x) instance : OrderBot (PseudoMetric X R) where bot_le f _ _ := f.nonneg _ _ @[simp, push_cast] lemma coe_finsetSup [IsOrderedAddMonoid R] {Y : Type*} {f : Y → PseudoMetric X R} {s : Finset Y} (hs : s.Nonempty) : ⇑(s.sup f) = s.sup' hs (f ·) := by induction hs using Finset.Nonempty.cons_induction with | singleton i => simp | cons a s ha hs ih => simp [hs, ih] lemma finsetSup_apply [IsOrderedAddMonoid R] {Y : Type*} {f : Y → PseudoMetric X R} {s : Finset Y} (hs : s.Nonempty) (x y : X) : s.sup f x y = s.sup' hs fun i ↦ f i x y := by induction hs using Finset.Nonempty.cons_induction with | singleton i => simp | cons a s ha hs ih => simp [hs, ih] end OrderBot section IsUltra /-- A pseudometric can be nonarchimedean (or ultrametric), with a stronger triangle inequality such that `d x z ≤ max (d x y) (d y z)`. -/ class IsUltra [Zero R] [Add R] [LE R] [Max R] (d : PseudoMetric X R) : Prop where /-- Strong triangle inequality of an ultrametric. -/ le_sup' : ∀ x y z, d x z ≤ d x y ⊔ d y z lemma IsUltra.le_sup [Zero R] [Add R] [LE R] [Max R] {d : PseudoMetric X R} [hd : IsUltra d] {x y z : X} : d x z ≤ d x y ⊔ d y z := hd.le_sup' x y z instance IsUltra.bot [AddZeroClass R] [SemilatticeSup R] : IsUltra (⊥ : PseudoMetric X R) where le_sup' := by simp instance IsUltra.sup [AddZeroClass R] [SemilatticeSup R] [AddLeftMono R] [AddRightMono R] {d d' : PseudoMetric X R} [IsUltra d] [IsUltra d'] : IsUltra (d ⊔ d') := by constructor intro x y z simp only [PseudoMetric.sup_apply] calc d x z ⊔ d' x z ≤ d x y ⊔ d y z ⊔ (d' x y ⊔ d' y z) := sup_le_sup le_sup le_sup _ ≤ d x y ⊔ d' x y ⊔ (d y z ⊔ d' y z) := by simp [sup_comm, sup_left_comm] lemma IsUltra.finsetSup {Y : Type*} [AddCommMonoid R] [LinearOrder R] [AddLeftStrictMono R] [IsOrderedAddMonoid R] {f : Y → PseudoMetric X R} {s : Finset Y} (h : ∀ d ∈ s, IsUltra (f d)) : IsUltra (s.sup f) := by constructor intro x y z rcases s.eq_empty_or_nonempty with rfl | hs · simp simp_rw [finsetSup_apply hs] apply Finset.sup'_le simp only [le_sup_iff, Finset.le_sup'_iff] intro i hi have h := (h i hi).le_sup' x y z simp only [le_sup_iff] at h refine h.imp ?_ ?_ <;> intro H <;> exact ⟨i, hi, H⟩ end IsUltra section ball instance isSymm_ball [Add R] [Zero R] [Preorder R] (d : PseudoMetric X R) {ε : R} : SetRel.IsSymm {xy | d xy.1 xy.2 < ε} where symm := by simp [d.symm] @[deprecated (since := "2025-10-17")] alias isSymmetricRel_ball := isSymm_ball instance isSymm_closedBall [Add R] [Zero R] [LE R] (d : PseudoMetric X R) {ε : R} : SetRel.IsSymm {xy | d xy.1 xy.2 ≤ ε} where symm := by simp [d.symm] @[deprecated (since := "2025-10-17")] alias isSymmetricRel_closedBall := isSymm_closedBall instance IsUltra.isTrans_ball [Add R] [Zero R] [LinearOrder R] (d : PseudoMetric X R) [d.IsUltra] {ε : R} : SetRel.IsTrans {xy | d xy.1 xy.2 < ε} where trans _ _ _ hxy hyz := le_sup.trans_lt (max_lt hxy hyz) @[deprecated (since := "2025-10-17")] alias IsUltra.isTransitiveRel_ball := IsUltra.isTrans_ball instance IsUltra.isTrans_closedBall [Add R] [Zero R] [SemilatticeSup R] (d : PseudoMetric X R) [d.IsUltra] {ε : R} : SetRel.IsTrans {xy | d xy.1 xy.2 ≤ ε} where trans _ _ _ hxy hyz := le_sup.trans (sup_le hxy hyz) @[deprecated (since := "2025-10-17")] alias IsUltra.isTransitiveRel_closedBall := IsUltra.isTrans_closedBall end ball end PseudoMetric
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Closeds.lean
import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.HausdorffDistance import Mathlib.Topology.Sets.Compacts /-! # Closed subsets This file defines the metric and emetric space structure on the types of closed subsets and nonempty compact subsets of a metric or emetric space. The Hausdorff distance induces an emetric space structure on the type of closed subsets of an emetric space, called `Closeds`. Its completeness, resp. compactness, resp. second-countability, follow from the corresponding properties of the original space. In a metric space, the type of nonempty compact subsets (called `NonemptyCompacts`) also inherits a metric space structure from the Hausdorff distance, as the Hausdorff edistance is always finite in this context. -/ noncomputable section open Set Function TopologicalSpace Filter Topology ENNReal namespace EMetric section variable {α β : Type*} [EMetricSpace α] [EMetricSpace β] {s : Set α} /-- In emetric spaces, the Hausdorff edistance defines an emetric space structure on the type of closed subsets -/ instance Closeds.emetricSpace : EMetricSpace (Closeds α) where edist s t := hausdorffEdist (s : Set α) t edist_self _ := hausdorffEdist_self edist_comm _ _ := hausdorffEdist_comm edist_triangle _ _ _ := hausdorffEdist_triangle eq_of_edist_eq_zero {s t} h := Closeds.ext <| (hausdorffEdist_zero_iff_eq_of_closed s.isClosed t.isClosed).1 h /-- The edistance to a closed set depends continuously on the point and the set -/ theorem continuous_infEdist_hausdorffEdist : Continuous fun p : α × Closeds α => infEdist p.1 p.2 := by refine continuous_of_le_add_edist 2 (by simp) ?_ rintro ⟨x, s⟩ ⟨y, t⟩ calc infEdist x s ≤ infEdist x t + hausdorffEdist (t : Set α) s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ infEdist y t + edist x y + hausdorffEdist (t : Set α) s := by gcongr; apply infEdist_le_infEdist_add_edist _ = infEdist y t + (edist x y + hausdorffEdist (s : Set α) t) := by rw [add_assoc, hausdorffEdist_comm] _ ≤ infEdist y t + (edist (x, s) (y, t) + edist (x, s) (y, t)) := by gcongr <;> apply_rules [le_max_left, le_max_right] _ = infEdist y t + 2 * edist (x, s) (y, t) := by rw [← mul_two, mul_comm] /-- Subsets of a given closed subset form a closed set -/ theorem Closeds.isClosed_subsets_of_isClosed (hs : IsClosed s) : IsClosed { t : Closeds α | (t : Set α) ⊆ s } := by refine isClosed_of_closure_subset fun (t : Closeds α) (ht : t ∈ closure {t : Closeds α | (t : Set α) ⊆ s}) (x : α) (hx : x ∈ t) => ?_ have : x ∈ closure s := by refine mem_closure_iff.2 fun ε εpos => ?_ obtain ⟨u : Closeds α, hu : u ∈ {t : Closeds α | (t : Set α) ⊆ s}, Dtu : edist t u < ε⟩ := mem_closure_iff.1 ht ε εpos obtain ⟨y : α, hy : y ∈ u, Dxy : edist x y < ε⟩ := exists_edist_lt_of_hausdorffEdist_lt hx Dtu exact ⟨y, hu hy, Dxy⟩ rwa [hs.closure_eq] at this @[deprecated (since := "2025-08-20")] alias isClosed_subsets_of_isClosed := Closeds.isClosed_subsets_of_isClosed /-- By definition, the edistance on `Closeds α` is given by the Hausdorff edistance -/ theorem Closeds.edist_eq {s t : Closeds α} : edist s t = hausdorffEdist (s : Set α) t := rfl /-- In a complete space, the type of closed subsets is complete for the Hausdorff edistance. -/ instance Closeds.completeSpace [CompleteSpace α] : CompleteSpace (Closeds α) := by /- We will show that, if a sequence of sets `s n` satisfies `edist (s n) (s (n+1)) < 2^{-n}`, then it converges. This is enough to guarantee completeness, by a standard completeness criterion. We use the shorthand `B n = 2^{-n}` in ennreal. -/ let B : ℕ → ℝ≥0∞ := fun n => 2⁻¹ ^ n have B_pos : ∀ n, (0 : ℝ≥0∞) < B n := by simp [B, ENNReal.pow_pos] have B_ne_top : ∀ n, B n ≠ ⊤ := by finiteness /- Consider a sequence of closed sets `s n` with `edist (s n) (s (n+1)) < B n`. We will show that it converges. The limit set is `t0 = ⋂n, closure (⋃m≥n, s m)`. We will have to show that a point in `s n` is close to a point in `t0`, and a point in `t0` is close to a point in `s n`. The completeness then follows from a standard criterion. -/ refine complete_of_convergent_controlled_sequences B B_pos fun s hs => ?_ let t0 := ⋂ n, closure (⋃ m ≥ n, s m : Set α) let t : Closeds α := ⟨t0, isClosed_iInter fun _ => isClosed_closure⟩ use t -- The inequality is written this way to agree with `edist_le_of_edist_le_geometric_of_tendsto₀` have I1 : ∀ n, ∀ x ∈ s n, ∃ y ∈ t0, edist x y ≤ 2 * B n := by /- This is the main difficulty of the proof. Starting from `x ∈ s n`, we want to find a point in `t0` which is close to `x`. Define inductively a sequence of points `z m` with `z n = x` and `z m ∈ s m` and `edist (z m) (z (m+1)) ≤ B m`. This is possible since the Hausdorff distance between `s m` and `s (m+1)` is at most `B m`. This sequence is a Cauchy sequence, therefore converging as the space is complete, to a limit which satisfies the required properties. -/ intro n x hx obtain ⟨z, hz₀, hz⟩ : ∃ z : ∀ l, s (n + l), (z 0 : α) = x ∧ ∀ k, edist (z k : α) (z (k + 1) : α) ≤ B n / 2 ^ k := by -- We prove existence of the sequence by induction. have : ∀ (l) (z : s (n + l)), ∃ z' : s (n + l + 1), edist (z : α) z' ≤ B n / 2 ^ l := by intro l z obtain ⟨z', z'_mem, hz'⟩ : ∃ z' ∈ s (n + l + 1), edist (z : α) z' < B n / 2 ^ l := by refine exists_edist_lt_of_hausdorffEdist_lt (s := s (n + l)) z.2 ?_ simp only [ENNReal.inv_pow, div_eq_mul_inv] rw [← pow_add] apply hs <;> simp exact ⟨⟨z', z'_mem⟩, le_of_lt hz'⟩ use fun k => Nat.recOn k ⟨x, hx⟩ fun l z => (this l z).choose simp only [Nat.add_zero, Nat.rec_zero, true_and] exact fun k => (this k _).choose_spec -- it follows from the previous bound that `z` is a Cauchy sequence have : CauchySeq fun k => (z k : α) := cauchySeq_of_edist_le_geometric_two (B n) (B_ne_top n) hz -- therefore, it converges rcases cauchySeq_tendsto_of_complete this with ⟨y, y_lim⟩ use y -- the limit point `y` will be the desired point, in `t0` and close to our initial point `x`. -- First, we check it belongs to `t0`. have : y ∈ t0 := mem_iInter.2 fun k => mem_closure_of_tendsto y_lim (by simp only [exists_prop, Set.mem_iUnion, Filter.eventually_atTop] exact ⟨k, fun m hm => ⟨n + m, by cutsat, (z m).2⟩⟩) use this -- Then, we check that `y` is close to `x = z n`. This follows from the fact that `y` -- is the limit of `z k`, and the distance between `z n` and `z k` has already been estimated. rw [← hz₀] exact edist_le_of_edist_le_geometric_two_of_tendsto₀ (B n) hz y_lim have I2 : ∀ n, ∀ x ∈ t0, ∃ y ∈ s n, edist x y ≤ 2 * B n := by /- For the (much easier) reverse inequality, we start from a point `x ∈ t0` and we want to find a point `y ∈ s n` which is close to `x`. `x` belongs to `t0`, the intersection of the closures. In particular, it is well approximated by a point `z` in `⋃m≥n, s m`, say in `s m`. Since `s m` and `s n` are close, this point is itself well approximated by a point `y` in `s n`, as required. -/ intro n x xt0 have : x ∈ closure (⋃ m ≥ n, s m : Set α) := by apply mem_iInter.1 xt0 n obtain ⟨z : α, hz, Dxz : edist x z < B n⟩ := mem_closure_iff.1 this (B n) (B_pos n) simp only [exists_prop, Set.mem_iUnion] at hz obtain ⟨m : ℕ, m_ge_n : m ≥ n, hm : z ∈ (s m : Set α)⟩ := hz have : hausdorffEdist (s m : Set α) (s n) < B n := hs n m n m_ge_n (le_refl n) obtain ⟨y : α, hy : y ∈ (s n : Set α), Dzy : edist z y < B n⟩ := exists_edist_lt_of_hausdorffEdist_lt hm this exact ⟨y, hy, calc edist x y ≤ edist x z + edist z y := edist_triangle _ _ _ _ ≤ B n + B n := by gcongr _ = 2 * B n := (two_mul _).symm ⟩ -- Deduce from the above inequalities that the distance between `s n` and `t0` is at most `2 B n`. have main : ∀ n : ℕ, edist (s n) t ≤ 2 * B n := fun n => hausdorffEdist_le_of_mem_edist (I1 n) (I2 n) -- from this, the convergence of `s n` to `t0` follows. refine tendsto_atTop.2 fun ε εpos => ?_ have : Tendsto (fun n => 2 * B n) atTop (𝓝 (2 * 0)) := ENNReal.Tendsto.const_mul (ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one <| by simp) (Or.inr <| by simp) rw [mul_zero] at this obtain ⟨N, hN⟩ : ∃ N, ∀ b ≥ N, ε > 2 * B b := ((tendsto_order.1 this).2 ε εpos).exists_forall_of_atTop exact ⟨N, fun n hn => lt_of_le_of_lt (main n) (hN n hn)⟩ /-- In a compact space, the type of closed subsets is compact. -/ instance Closeds.compactSpace [CompactSpace α] : CompactSpace (Closeds α) := ⟨by /- by completeness, it suffices to show that it is totally bounded, i.e., for all ε>0, there is a finite set which is ε-dense. start from a set `s` which is ε-dense in α. Then the subsets of `s` are finitely many, and ε-dense for the Hausdorff distance. -/ refine (EMetric.totallyBounded_iff.2 fun ε εpos => ?_).isCompact_of_isClosed isClosed_univ rcases exists_between εpos with ⟨δ, δpos, δlt⟩ obtain ⟨s : Set α, fs : s.Finite, hs : univ ⊆ ⋃ y ∈ s, ball y δ⟩ := EMetric.totallyBounded_iff.1 (isCompact_iff_totallyBounded_isComplete.1 (@isCompact_univ α _ _)).1 δ δpos -- we first show that any set is well approximated by a subset of `s`. have main : ∀ u : Set α, ∃ v ⊆ s, hausdorffEdist u v ≤ δ := by intro u let v := { x : α | x ∈ s ∧ ∃ y ∈ u, edist x y < δ } exists v, (fun x hx => hx.1 : v ⊆ s) refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro x hx have : x ∈ ⋃ y ∈ s, ball y δ := hs (by simp) rcases mem_iUnion₂.1 this with ⟨y, ys, dy⟩ have : edist y x < δ := by simpa [edist_comm] exact ⟨y, ⟨ys, ⟨x, hx, this⟩⟩, le_of_lt dy⟩ · rintro x ⟨_, ⟨y, yu, hy⟩⟩ exact ⟨y, yu, le_of_lt hy⟩ -- introduce the set F of all subsets of `s` (seen as members of `Closeds α`). let F := { f : Closeds α | (f : Set α) ⊆ s } refine ⟨F, ?_, fun u _ => ?_⟩ -- `F` is finite · apply @Finite.of_finite_image _ _ F _ · apply fs.finite_subsets.subset fun b => _ · exact fun s => (s : Set α) simp only [F, and_imp, Set.mem_image, Set.mem_setOf_eq, exists_imp] intro _ x hx hx' rwa [hx'] at hx · exact SetLike.coe_injective.injOn -- `F` is ε-dense · obtain ⟨t0, t0s, Dut0⟩ := main u have : IsClosed t0 := (fs.subset t0s).isCompact.isClosed let t : Closeds α := ⟨t0, this⟩ have : t ∈ F := t0s have : edist u t < ε := lt_of_le_of_lt Dut0 δlt apply mem_iUnion₂.2 exact ⟨t, ‹t ∈ F›, this⟩⟩ theorem Closeds.isometry_singleton : Isometry (Closeds.singleton (α := α)) := fun _ _ => hausdorffEdist_singleton theorem Closeds.lipschitz_sup : LipschitzWith 1 fun p : Closeds α × Closeds α => p.1 ⊔ p.2 := .of_edist_le fun _ _ => hausdorffEdist_union_le namespace NonemptyCompacts /-- In an emetric space, the type of non-empty compact subsets is an emetric space, where the edistance is the Hausdorff edistance -/ instance emetricSpace : EMetricSpace (NonemptyCompacts α) where edist s t := hausdorffEdist (s : Set α) t edist_self _ := hausdorffEdist_self edist_comm _ _ := hausdorffEdist_comm edist_triangle _ _ _ := hausdorffEdist_triangle eq_of_edist_eq_zero {s t} h := NonemptyCompacts.ext <| by have : closure (s : Set α) = closure t := hausdorffEdist_zero_iff_closure_eq_closure.1 h rwa [s.isCompact.isClosed.closure_eq, t.isCompact.isClosed.closure_eq] at this /-- `NonemptyCompacts.toCloseds` is an isometry -/ theorem isometry_toCloseds : Isometry (@NonemptyCompacts.toCloseds α _ _) := fun _ _ => rfl /-- `NonemptyCompacts.toCloseds` is a uniform embedding (as it is an isometry) -/ theorem isUniformEmbedding_toCloseds : IsUniformEmbedding (@NonemptyCompacts.toCloseds α _ _) := isometry_toCloseds.isUniformEmbedding @[deprecated (since := "2025-08-20")] alias ToCloseds.isUniformEmbedding := isUniformEmbedding_toCloseds /-- `NonemptyCompacts.toCloseds` is continuous (as it is an isometry) -/ @[fun_prop] theorem continuous_toCloseds : Continuous (@NonemptyCompacts.toCloseds α _ _) := isometry_toCloseds.continuous lemma isClosed_subsets_of_isClosed (hs : IsClosed s) : IsClosed {A : NonemptyCompacts α | (A : Set α) ⊆ s} := (Closeds.isClosed_subsets_of_isClosed hs).preimage continuous_toCloseds /-- The range of `NonemptyCompacts.toCloseds` is closed in a complete space -/ theorem isClosed_in_closeds [CompleteSpace α] : IsClosed (range <| @NonemptyCompacts.toCloseds α _ _) := by have : range NonemptyCompacts.toCloseds = { s : Closeds α | (s : Set α).Nonempty ∧ IsCompact (s : Set α) } := by ext s refine ⟨?_, fun h => ⟨⟨⟨s, h.2⟩, h.1⟩, Closeds.ext rfl⟩⟩ rintro ⟨s, hs, rfl⟩ exact ⟨s.nonempty, s.isCompact⟩ rw [this] refine isClosed_of_closure_subset fun s hs => ⟨?_, ?_⟩ · -- take a set t which is nonempty and at a finite distance of s rcases mem_closure_iff.1 hs ⊤ ENNReal.coe_lt_top with ⟨t, ht, Dst⟩ rw [edist_comm] at Dst -- since `t` is nonempty, so is `s` exact nonempty_of_hausdorffEdist_ne_top ht.1 (ne_of_lt Dst) · refine isCompact_iff_totallyBounded_isComplete.2 ⟨?_, s.isClosed.isComplete⟩ refine totallyBounded_iff.2 fun ε (εpos : 0 < ε) => ?_ -- we have to show that s is covered by finitely many eballs of radius ε -- pick a nonempty compact set t at distance at most ε/2 of s rcases mem_closure_iff.1 hs (ε / 2) (ENNReal.half_pos εpos.ne') with ⟨t, ht, Dst⟩ -- cover this space with finitely many balls of radius ε/2 rcases totallyBounded_iff.1 (isCompact_iff_totallyBounded_isComplete.1 ht.2).1 (ε / 2) (ENNReal.half_pos εpos.ne') with ⟨u, fu, ut⟩ refine ⟨u, ⟨fu, fun x hx => ?_⟩⟩ -- u : set α, fu : u.finite, ut : t ⊆ ⋃ (y : α) (H : y ∈ u), eball y (ε / 2) -- then s is covered by the union of the balls centered at u of radius ε rcases exists_edist_lt_of_hausdorffEdist_lt hx Dst with ⟨z, hz, Dxz⟩ rcases mem_iUnion₂.1 (ut hz) with ⟨y, hy, Dzy⟩ have : edist x y < ε := calc edist x y ≤ edist x z + edist z y := edist_triangle _ _ _ _ < ε / 2 + ε / 2 := ENNReal.add_lt_add Dxz Dzy _ = ε := ENNReal.add_halves _ exact mem_biUnion hy this /-- In a complete space, the type of nonempty compact subsets is complete. This follows from the same statement for closed subsets -/ instance completeSpace [CompleteSpace α] : CompleteSpace (NonemptyCompacts α) := (completeSpace_iff_isComplete_range isometry_toCloseds.isUniformInducing).2 <| isClosed_in_closeds.isComplete /-- In a compact space, the type of nonempty compact subsets is compact. This follows from the same statement for closed subsets -/ instance compactSpace [CompactSpace α] : CompactSpace (NonemptyCompacts α) := ⟨by rw [isometry_toCloseds.isEmbedding.isCompact_iff, image_univ] exact isClosed_in_closeds.isCompact⟩ /-- In a second countable space, the type of nonempty compact subsets is second countable -/ instance secondCountableTopology [SecondCountableTopology α] : SecondCountableTopology (NonemptyCompacts α) := haveI : SeparableSpace (NonemptyCompacts α) := by /- To obtain a countable dense subset of `NonemptyCompacts α`, start from a countable dense subset `s` of α, and then consider all its finite nonempty subsets. This set is countable and made of nonempty compact sets. It turns out to be dense: by total boundedness, any compact set `t` can be covered by finitely many small balls, and approximations in `s` of the centers of these balls give the required finite approximation of `t`. -/ rcases exists_countable_dense α with ⟨s, cs, s_dense⟩ let v0 := { t : Set α | t.Finite ∧ t ⊆ s } let v : Set (NonemptyCompacts α) := { t : NonemptyCompacts α | (t : Set α) ∈ v0 } refine ⟨⟨v, ?_, ?_⟩⟩ · have : v0.Countable := countable_setOf_finite_subset cs exact this.preimage SetLike.coe_injective · refine fun t => mem_closure_iff.2 fun ε εpos => ?_ -- t is a compact nonempty set, that we have to approximate uniformly by a a set in `v`. rcases exists_between εpos with ⟨δ, δpos, δlt⟩ have δpos' : 0 < δ / 2 := ENNReal.half_pos δpos.ne' -- construct a map F associating to a point in α an approximating point in s, up to δ/2. have Exy : ∀ x, ∃ y, y ∈ s ∧ edist x y < δ / 2 := by intro x rcases mem_closure_iff.1 (s_dense x) (δ / 2) δpos' with ⟨y, ys, hy⟩ exact ⟨y, ⟨ys, hy⟩⟩ let F x := (Exy x).choose have Fspec : ∀ x, F x ∈ s ∧ edist x (F x) < δ / 2 := fun x => (Exy x).choose_spec -- cover `t` with finitely many balls. Their centers form a set `a` have : TotallyBounded (t : Set α) := t.isCompact.totallyBounded obtain ⟨a : Set α, af : Set.Finite a, ta : (t : Set α) ⊆ ⋃ y ∈ a, ball y (δ / 2)⟩ := totallyBounded_iff.1 this (δ / 2) δpos' -- replace each center by a nearby approximation in `s`, giving a new set `b` let b := F '' a have : b.Finite := af.image _ have tb : ∀ x ∈ t, ∃ y ∈ b, edist x y < δ := by intro x hx rcases mem_iUnion₂.1 (ta hx) with ⟨z, za, Dxz⟩ exists F z, mem_image_of_mem _ za calc edist x (F z) ≤ edist x z + edist z (F z) := edist_triangle _ _ _ _ < δ / 2 + δ / 2 := ENNReal.add_lt_add Dxz (Fspec z).2 _ = δ := ENNReal.add_halves _ -- keep only the points in `b` that are close to point in `t`, yielding a new set `c` let c := { y ∈ b | ∃ x ∈ t, edist x y < δ } have : c.Finite := ‹b.Finite›.subset fun x hx => hx.1 -- points in `t` are well approximated by points in `c` have tc : ∀ x ∈ t, ∃ y ∈ c, edist x y ≤ δ := by intro x hx rcases tb x hx with ⟨y, yv, Dxy⟩ have : y ∈ c := by simpa [c, -mem_image] using ⟨yv, ⟨x, hx, Dxy⟩⟩ exact ⟨y, this, le_of_lt Dxy⟩ -- points in `c` are well approximated by points in `t` have ct : ∀ y ∈ c, ∃ x ∈ t, edist y x ≤ δ := by rintro y ⟨_, x, xt, Dyx⟩ have : edist y x ≤ δ := calc edist y x = edist x y := edist_comm _ _ _ ≤ δ := le_of_lt Dyx exact ⟨x, xt, this⟩ -- it follows that their Hausdorff distance is small have : hausdorffEdist (t : Set α) c ≤ δ := hausdorffEdist_le_of_mem_edist tc ct have Dtc : hausdorffEdist (t : Set α) c < ε := this.trans_lt δlt -- the set `c` is not empty, as it is well approximated by a nonempty set have hc : c.Nonempty := nonempty_of_hausdorffEdist_ne_top t.nonempty (ne_top_of_lt Dtc) -- let `d` be the version of `c` in the type `NonemptyCompacts α` let d : NonemptyCompacts α := ⟨⟨c, ‹c.Finite›.isCompact⟩, hc⟩ have : c ⊆ s := by intro x hx rcases (mem_image _ _ _).1 hx.1 with ⟨y, ⟨_, yx⟩⟩ rw [← yx] exact (Fspec y).1 have : d ∈ v := ⟨‹c.Finite›, this⟩ -- we have proved that `d` is a good approximation of `t` as requested exact ⟨d, ‹d ∈ v›, Dtc⟩ UniformSpace.secondCountable_of_separable (NonemptyCompacts α) theorem isometry_singleton : Isometry ({·} : α → NonemptyCompacts α) := fun _ _ => hausdorffEdist_singleton theorem lipschitz_sup : LipschitzWith 1 fun p : NonemptyCompacts α × NonemptyCompacts α => p.1 ⊔ p.2 := .of_edist_le fun _ _ => hausdorffEdist_union_le theorem lipschitz_prod : LipschitzWith 1 fun p : NonemptyCompacts α × NonemptyCompacts β => p.1.prod p.2 := .of_edist_le fun _ _ => hausdorffEdist_prod_le end NonemptyCompacts end --section end EMetric --namespace namespace Metric section variable {α : Type*} [MetricSpace α] /-- `NonemptyCompacts α` inherits a metric space structure, as the Hausdorff edistance between two such sets is finite. -/ instance NonemptyCompacts.metricSpace : MetricSpace (NonemptyCompacts α) := EMetricSpace.toMetricSpace fun x y => hausdorffEdist_ne_top_of_nonempty_of_bounded x.nonempty y.nonempty x.isCompact.isBounded y.isCompact.isBounded /-- The distance on `NonemptyCompacts α` is the Hausdorff distance, by construction -/ theorem NonemptyCompacts.dist_eq {x y : NonemptyCompacts α} : dist x y = hausdorffDist (x : Set α) y := rfl theorem lipschitz_infDist_set (x : α) : LipschitzWith 1 fun s : NonemptyCompacts α => infDist x s := LipschitzWith.of_le_add fun s t => by rw [dist_comm] exact infDist_le_infDist_add_hausdorffDist (edist_ne_top t s) theorem lipschitz_infDist : LipschitzWith 2 fun p : α × NonemptyCompacts α => infDist p.1 p.2 := by rw [← one_add_one_eq_two] exact LipschitzWith.uncurry (fun s : NonemptyCompacts α => lipschitz_infDist_pt (s : Set α)) lipschitz_infDist_set theorem uniformContinuous_infDist_Hausdorff_dist : UniformContinuous fun p : α × NonemptyCompacts α => infDist p.1 p.2 := lipschitz_infDist.uniformContinuous end --section end Metric --namespace
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Contracting.lean
import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.Setoid.Basic import Mathlib.Dynamics.FixedPoints.Topology import Mathlib.Topology.MetricSpace.Lipschitz /-! # Contracting maps A Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*. In this file we prove the Banach fixed point theorem, some explicit estimates on the rate of convergence, and some properties of the map sending a contracting map to its fixed point. ## Main definitions * `ContractingWith K f` : a Lipschitz continuous self-map with `K < 1`; * `efixedPoint` : given a contracting map `f` on a complete emetric space and a point `x` such that `edist x (f x) ≠ ∞`, `efixedPoint f hf x hx` is the unique fixed point of `f` in `EMetric.ball x ∞`; * `fixedPoint` : the unique fixed point of a contracting map on a complete nonempty metric space. ## Tags contracting map, fixed point, Banach fixed point theorem -/ open NNReal Topology ENNReal Filter Function variable {α : Type*} /-- A map is said to be `ContractingWith K`, if `K < 1` and `f` is `LipschitzWith K`. -/ def ContractingWith [EMetricSpace α] (K : ℝ≥0) (f : α → α) := K < 1 ∧ LipschitzWith K f namespace ContractingWith variable [EMetricSpace α] {K : ℝ≥0} {f : α → α} open EMetric Set theorem toLipschitzWith (hf : ContractingWith K f) : LipschitzWith K f := hf.2 theorem one_sub_K_pos' (hf : ContractingWith K f) : (0 : ℝ≥0∞) < 1 - K := by simp [hf.1] theorem one_sub_K_ne_zero (hf : ContractingWith K f) : (1 : ℝ≥0∞) - K ≠ 0 := ne_of_gt hf.one_sub_K_pos' theorem one_sub_K_ne_top : (1 : ℝ≥0∞) - K ≠ ∞ := by norm_cast exact ENNReal.coe_ne_top theorem edist_inequality (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) : edist x y ≤ (edist x (f x) + edist y (f y)) / (1 - K) := suffices edist x y ≤ edist x (f x) + edist y (f y) + K * edist x y by rwa [ENNReal.le_div_iff_mul_le (Or.inl hf.one_sub_K_ne_zero) (Or.inl one_sub_K_ne_top), mul_comm, ENNReal.sub_mul fun _ _ ↦ h, one_mul, tsub_le_iff_right] calc edist x y ≤ edist x (f x) + edist (f x) (f y) + edist (f y) y := edist_triangle4 _ _ _ _ _ = edist x (f x) + edist y (f y) + edist (f x) (f y) := by rw [edist_comm y, add_right_comm] _ ≤ edist x (f x) + edist y (f y) + K * edist x y := add_le_add le_rfl (hf.2 _ _) theorem edist_le_of_fixedPoint (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) (hy : IsFixedPt f y) : edist x y ≤ edist x (f x) / (1 - K) := by simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h theorem eq_or_edist_eq_top_of_fixedPoints (hf : ContractingWith K f) {x y} (hx : IsFixedPt f x) (hy : IsFixedPt f y) : x = y ∨ edist x y = ∞ := by refine or_iff_not_imp_right.2 fun h ↦ edist_le_zero.1 ?_ simpa only [hx.eq, edist_self, add_zero, ENNReal.zero_div] using hf.edist_le_of_fixedPoint h hy /-- If a map `f` is `ContractingWith K`, and `s` is a forward-invariant set, then restriction of `f` to `s` is `ContractingWith K` as well. -/ theorem restrict (hf : ContractingWith K f) {s : Set α} (hs : MapsTo f s s) : ContractingWith K (hs.restrict f s s) := ⟨hf.1, fun x y ↦ hf.2 x y⟩ section variable [CompleteSpace α] /-- Banach fixed-point theorem, contraction mapping theorem, `EMetricSpace` version. A contracting map on a complete metric space has a fixed point. We include more conclusions in this theorem to avoid proving them again later. The main API for this theorem are the functions `efixedPoint` and `fixedPoint`, and lemmas about these functions. -/ theorem exists_fixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) : ∃ y, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧ ∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := have : CauchySeq fun n ↦ f^[n] x := cauchySeq_of_edist_le_geometric K (edist x (f x)) (ENNReal.coe_lt_one_iff.2 hf.1) hx (hf.toLipschitzWith.edist_iterate_succ_le_geometric x) let ⟨y, hy⟩ := cauchySeq_tendsto_of_complete this ⟨y, isFixedPt_of_tendsto_iterate hy hf.2.continuous.continuousAt, hy, edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x)) (hf.toLipschitzWith.edist_iterate_succ_le_geometric x) hy⟩ variable (f) in -- avoid `efixedPoint _` in pretty printer /-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map, and `edist x (f x) ≠ ∞`. Then `efixedPoint` is the unique fixed point of `f` in `EMetric.ball x ∞`. -/ noncomputable def efixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) : α := Classical.choose <| hf.exists_fixedPoint x hx theorem efixedPoint_isFixedPt (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : IsFixedPt f (efixedPoint f hf x hx) := (Classical.choose_spec <| hf.exists_fixedPoint x hx).1 theorem tendsto_iterate_efixedPoint (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint f hf x hx) := (Classical.choose_spec <| hf.exists_fixedPoint x hx).2.1 theorem apriori_edist_iterate_efixedPoint_le (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) (n : ℕ) : edist (f^[n] x) (efixedPoint f hf x hx) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := (Classical.choose_spec <| hf.exists_fixedPoint x hx).2.2 n theorem edist_efixedPoint_le (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint f hf x hx) ≤ edist x (f x) / (1 - K) := by convert hf.apriori_edist_iterate_efixedPoint_le hx 0 simp only [pow_zero, mul_one] theorem edist_efixedPoint_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint f hf x hx) < ∞ := (hf.edist_efixedPoint_le hx).trans_lt (ENNReal.mul_ne_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero).lt_top theorem efixedPoint_eq_of_edist_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) {y : α} (hy : edist y (f y) ≠ ∞) (h : edist x y ≠ ∞) : efixedPoint f hf x hx = efixedPoint f hf y hy := by refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h') <;> try apply efixedPoint_isFixedPt change edistLtTopSetoid _ _ trans x · apply Setoid.symm' exact hf.edist_efixedPoint_lt_top hx trans y exacts [lt_top_iff_ne_top.2 h, hf.edist_efixedPoint_lt_top hy] end /-- Banach fixed-point theorem for maps contracting on a complete subset. -/ theorem exists_fixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : ∃ y ∈ s, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧ ∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := by haveI := hsc.completeSpace_coe rcases hf.exists_fixedPoint ⟨x, hxs⟩ hx with ⟨y, hfy, h_tendsto, hle⟩ refine ⟨y, y.2, Subtype.ext_iff.1 hfy, ?_, fun n ↦ ?_⟩ · convert (continuous_subtype_val.tendsto _).comp h_tendsto simp only [(· ∘ ·), MapsTo.iterate_restrict, MapsTo.val_restrict_apply] · convert hle n rw [MapsTo.iterate_restrict] rfl variable (f) in -- avoid `efixedPoint _` in pretty printer /-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s` and `x ∈ s` satisfies `edist x (f x) ≠ ∞`, then `efixedPoint'` is the unique fixed point of the restriction of `f` to `s ∩ EMetric.ball x ∞`. -/ noncomputable def efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) (x : α) (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : α := Classical.choose <| hf.exists_fixedPoint' hsc hsf hxs hx theorem efixedPoint_mem' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : efixedPoint' f hsc hsf hf x hxs hx ∈ s := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).1 theorem efixedPoint_isFixedPt' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : IsFixedPt f (efixedPoint' f hsc hsf hf x hxs hx) := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.1 theorem tendsto_iterate_efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint' f hsc hsf hf x hxs hx) := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.1 theorem apriori_edist_iterate_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) (n : ℕ) : edist (f^[n] x) (efixedPoint' f hsc hsf hf x hxs hx) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.2 n theorem edist_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint' f hsc hsf hf x hxs hx) ≤ edist x (f x) / (1 - K) := by convert hf.apriori_edist_iterate_efixedPoint_le' hsc hsf hxs hx 0 rw [pow_zero, mul_one] theorem edist_efixedPoint_lt_top' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint' f hsc hsf hf x hxs hx) < ∞ := (hf.edist_efixedPoint_le' hsc hsf hxs hx).trans_lt (ENNReal.mul_ne_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero).lt_top /-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`, and `x ∈ s` is at a finite distance from `y ∈ t`, then the `efixedPoint'` constructed by `x` is the same as the `efixedPoint'` constructed by `y`. This lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way it can be used to prove the desired equality with non-trivial proofs of these facts. -/ theorem efixedPoint_eq_of_edist_lt_top' (hf : ContractingWith K f) {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hfs : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) {t : Set α} (htc : IsComplete t) (htf : MapsTo f t t) (hft : ContractingWith K <| htf.restrict f t t) {y : α} (hyt : y ∈ t) (hy : edist y (f y) ≠ ∞) (hxy : edist x y ≠ ∞) : efixedPoint' f hsc hsf hfs x hxs hx = efixedPoint' f htc htf hft y hyt hy := by refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h') <;> try apply efixedPoint_isFixedPt' change edistLtTopSetoid _ _ trans x · apply Setoid.symm' apply edist_efixedPoint_lt_top' trans y · exact lt_top_iff_ne_top.2 hxy · apply edist_efixedPoint_lt_top' end ContractingWith namespace ContractingWith variable [MetricSpace α] {K : ℝ≥0} {f : α → α} theorem one_sub_K_pos (hf : ContractingWith K f) : (0 : ℝ) < 1 - K := sub_pos.2 hf.1 section variable (hf : ContractingWith K f) include hf theorem dist_le_mul (x y : α) : dist (f x) (f y) ≤ K * dist x y := hf.toLipschitzWith.dist_le_mul x y theorem dist_inequality (x y) : dist x y ≤ (dist x (f x) + dist y (f y)) / (1 - K) := suffices dist x y ≤ dist x (f x) + dist y (f y) + K * dist x y by rwa [le_div_iff₀ hf.one_sub_K_pos, mul_comm, _root_.sub_mul, one_mul, sub_le_iff_le_add] calc dist x y ≤ dist x (f x) + dist y (f y) + dist (f x) (f y) := dist_triangle4_right _ _ _ _ _ ≤ dist x (f x) + dist y (f y) + K * dist x y := by grw [hf.dist_le_mul] theorem dist_le_of_fixedPoint (x) {y} (hy : IsFixedPt f y) : dist x y ≤ dist x (f x) / (1 - K) := by simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y theorem fixedPoint_unique' {x y} (hx : IsFixedPt f x) (hy : IsFixedPt f y) : x = y := (hf.eq_or_edist_eq_top_of_fixedPoints hx hy).resolve_right (edist_ne_top _ _) /-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly `C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y ≤ C / (1 - K)`. -/ theorem dist_fixedPoint_fixedPoint_of_dist_le' (g : α → α) {x y} (hx : IsFixedPt f x) (hy : IsFixedPt g y) {C} (hfg : ∀ z, dist (f z) (g z) ≤ C) : dist x y ≤ C / (1 - K) := calc dist x y = dist y x := dist_comm x y _ ≤ dist y (f y) / (1 - K) := hf.dist_le_of_fixedPoint y hx _ = dist (f y) (g y) / (1 - K) := by rw [hy.eq, dist_comm] _ ≤ C / (1 - K) := (div_le_div_iff_of_pos_right hf.one_sub_K_pos).2 (hfg y) variable [Nonempty α] [CompleteSpace α] variable (f) in /-- The unique fixed point of a contracting map in a nonempty complete metric space. -/ noncomputable def fixedPoint : α := efixedPoint f hf _ (edist_ne_top (Classical.choice ‹Nonempty α›) _) /-- The point provided by `ContractingWith.fixedPoint` is actually a fixed point. -/ theorem fixedPoint_isFixedPt : IsFixedPt f (fixedPoint f hf) := hf.efixedPoint_isFixedPt _ theorem fixedPoint_unique {x} (hx : IsFixedPt f x) : x = fixedPoint f hf := hf.fixedPoint_unique' hx hf.fixedPoint_isFixedPt theorem dist_fixedPoint_le (x) : dist x (fixedPoint f hf) ≤ dist x (f x) / (1 - K) := hf.dist_le_of_fixedPoint x hf.fixedPoint_isFixedPt /-- A posteriori estimates on the convergence of iterates to the fixed point. -/ theorem aposteriori_dist_iterate_fixedPoint_le (x n) : dist (f^[n] x) (fixedPoint f hf) ≤ dist (f^[n] x) (f^[n+1] x) / (1 - K) := by rw [iterate_succ'] apply hf.dist_fixedPoint_le theorem apriori_dist_iterate_fixedPoint_le (x n) : dist (f^[n] x) (fixedPoint f hf) ≤ dist x (f x) * (K : ℝ) ^ n / (1 - K) := calc _ ≤ dist (f^[n] x) (f^[n+1] x) / (1 - K) := hf.aposteriori_dist_iterate_fixedPoint_le x n _ ≤ _ := by gcongr; exacts [hf.one_sub_K_pos.le, hf.toLipschitzWith.dist_iterate_succ_le_geometric x n] theorem tendsto_iterate_fixedPoint (x) : Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| fixedPoint f hf) := by convert tendsto_iterate_efixedPoint hf (edist_ne_top x _) refine (fixedPoint_unique _ ?_).symm apply efixedPoint_isFixedPt theorem fixedPoint_lipschitz_in_map {g : α → α} (hg : ContractingWith K g) {C} (hfg : ∀ z, dist (f z) (g z) ≤ C) : dist (fixedPoint f hf) (fixedPoint g hg) ≤ C / (1 - K) := hf.dist_fixedPoint_fixedPoint_of_dist_le' g hf.fixedPoint_isFixedPt hg.fixedPoint_isFixedPt hfg end variable [Nonempty α] [CompleteSpace α] /-- If a map `f` has a contracting iterate `f^[n]`, then the fixed point of `f^[n]` is also a fixed point of `f`. -/ theorem isFixedPt_fixedPoint_iterate {n : ℕ} (hf : ContractingWith K f^[n]) : IsFixedPt f (hf.fixedPoint f^[n]) := by set x := hf.fixedPoint f^[n] have hx : f^[n] x = x := hf.fixedPoint_isFixedPt have := hf.toLipschitzWith.dist_le_mul x (f x) rw [← iterate_succ_apply, iterate_succ_apply', hx] at this contrapose! this simpa using mul_lt_mul_of_pos_right (NNReal.coe_lt_one.2 hf.left) <| dist_pos.2 (Ne.symm this) end ContractingWith
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/MetricSeparated.lean
import Mathlib.Data.Rel.Separated import Mathlib.Topology.EMetricSpace.Defs /-! # Metric separation This file defines a few notions of separations of sets in a metric space. The first notion (`Metric.IsSeparated`) is quantitative and about a single set: A set `s` is `ε`-separated if its elements are pairwise at distance at least `ε` from each other. The second notion (`Metric.AreSeparated`) is qualitative and about two sets: Two sets `s` and `t` are separated if the distance between `x ∈ s` and `y ∈ t` is bounded from below by a positive constant. -/ open EMetric Set open scoped ENNReal noncomputable section namespace Metric variable {X : Type*} [PseudoEMetricSpace X] {s t : Set X} {ε δ : ℝ≥0∞} {x : X} /-! ### Metric-separated sets In this section we define the predicate `Metric.IsSeparated` for `ε`-separated sets. -/ /-- A set `s` is `ε`-separated if its elements are pairwise at distance at least `ε` from each other. -/ def IsSeparated (ε : ℝ≥0∞) (s : Set X) : Prop := s.Pairwise (ε < edist · ·) lemma isSeparated_iff_setRelIsSeparated : IsSeparated ε s ↔ SetRel.IsSeparated {(x, y) | edist x y ≤ ε} s := by simp [IsSeparated, SetRel.IsSeparated] protected lemma IsSeparated.empty : IsSeparated ε (∅ : Set X) := pairwise_empty _ protected lemma IsSeparated.singleton : IsSeparated ε {x} := pairwise_singleton .. @[simp] lemma IsSeparated.of_subsingleton (hs : s.Subsingleton) : IsSeparated ε s := hs.pairwise _ alias _root_.Set.Subsingleton.isSeparated := IsSeparated.of_subsingleton nonrec lemma IsSeparated.anti (hεδ : ε ≤ δ) (hs : IsSeparated δ s) : IsSeparated ε s := hs.mono' fun _ _ ↦ hεδ.trans_lt lemma IsSeparated.subset (hst : s ⊆ t) (hs : IsSeparated ε t) : IsSeparated ε s := hs.mono hst lemma isSeparated_insert : IsSeparated ε (insert x s) ↔ IsSeparated ε s ∧ ∀ y ∈ s, x ≠ y → ε < edist x y := pairwise_insert_of_symmetric fun _ _ ↦ by simp [edist_comm] lemma isSeparated_insert_of_notMem (hx : x ∉ s) : IsSeparated ε (insert x s) ↔ IsSeparated ε s ∧ ∀ y ∈ s, ε < edist x y := pairwise_insert_of_symmetric_of_notMem (fun _ _ ↦ by simp [edist_comm]) hx @[deprecated (since := "2025-05-23")] alias isSeparated_insert_of_not_mem := isSeparated_insert_of_notMem protected lemma IsSeparated.insert (hs : IsSeparated ε s) (h : ∀ y ∈ s, x ≠ y → ε < edist x y) : IsSeparated ε (insert x s) := isSeparated_insert.2 ⟨hs, h⟩ /-! ### Metric separated pairs of sets In this section we define the predicate `Metric.AreSeparated`. We say that two sets in an (extended) metric space are *metric separated* if the (extended) distance between `x ∈ s` and `y ∈ t` is bounded from below by a positive constant. This notion is useful, e.g., to define metric outer measures. -/ /-- Two sets in an (extended) metric space are called *metric separated* if the (extended) distance between `x ∈ s` and `y ∈ t` is bounded from below by a positive constant. -/ def AreSeparated (s t : Set X) := ∃ r, r ≠ 0 ∧ ∀ x ∈ s, ∀ y ∈ t, r ≤ edist x y namespace AreSeparated @[symm] theorem symm (h : AreSeparated s t) : AreSeparated t s := let ⟨r, r0, hr⟩ := h ⟨r, r0, fun y hy x hx => edist_comm x y ▸ hr x hx y hy⟩ theorem comm : AreSeparated s t ↔ AreSeparated t s := ⟨symm, symm⟩ @[simp] theorem empty_left (s : Set X) : AreSeparated ∅ s := ⟨1, one_ne_zero, fun _x => False.elim⟩ @[simp] theorem empty_right (s : Set X) : AreSeparated s ∅ := (empty_left s).symm protected theorem disjoint (h : AreSeparated s t) : Disjoint s t := let ⟨r, r0, hr⟩ := h Set.disjoint_left.mpr fun x hx1 hx2 => r0 <| by simpa using hr x hx1 x hx2 theorem subset_compl_right (h : AreSeparated s t) : s ⊆ tᶜ := fun _ hs ht => h.disjoint.le_bot ⟨hs, ht⟩ @[mono] theorem mono {s' t'} (hs : s ⊆ s') (ht : t ⊆ t') : AreSeparated s' t' → AreSeparated s t := fun ⟨r, r0, hr⟩ => ⟨r, r0, fun x hx y hy => hr x (hs hx) y (ht hy)⟩ theorem mono_left {s'} (h' : AreSeparated s' t) (hs : s ⊆ s') : AreSeparated s t := h'.mono hs Subset.rfl theorem mono_right {t'} (h' : AreSeparated s t') (ht : t ⊆ t') : AreSeparated s t := h'.mono Subset.rfl ht theorem union_left {s'} (h : AreSeparated s t) (h' : AreSeparated s' t) : AreSeparated (s ∪ s') t := by rcases h, h' with ⟨⟨r, r0, hr⟩, ⟨r', r0', hr'⟩⟩ refine ⟨min r r', ?_, fun x hx y hy => hx.elim ?_ ?_⟩ · rw [← pos_iff_ne_zero] at r0 r0' ⊢ exact lt_min r0 r0' · exact fun hx => (min_le_left _ _).trans (hr _ hx _ hy) · exact fun hx => (min_le_right _ _).trans (hr' _ hx _ hy) @[simp] theorem union_left_iff {s'} : AreSeparated (s ∪ s') t ↔ AreSeparated s t ∧ AreSeparated s' t := ⟨fun h => ⟨h.mono_left subset_union_left, h.mono_left subset_union_right⟩, fun h => h.1.union_left h.2⟩ theorem union_right {t'} (h : AreSeparated s t) (h' : AreSeparated s t') : AreSeparated s (t ∪ t') := (h.symm.union_left h'.symm).symm @[simp] theorem union_right_iff {t'} : AreSeparated s (t ∪ t') ↔ AreSeparated s t ∧ AreSeparated s t' := comm.trans <| union_left_iff.trans <| and_congr comm comm theorem finite_iUnion_left_iff {ι : Type*} {I : Set ι} (hI : I.Finite) {s : ι → Set X} {t : Set X} : AreSeparated (⋃ i ∈ I, s i) t ↔ ∀ i ∈ I, AreSeparated (s i) t := by induction I, hI using Set.Finite.induction_on with | empty => simp | insert _ _ hI => rw [biUnion_insert, forall_mem_insert, union_left_iff, hI] alias ⟨_, finite_iUnion_left⟩ := finite_iUnion_left_iff theorem finite_iUnion_right_iff {ι : Type*} {I : Set ι} (hI : I.Finite) {s : Set X} {t : ι → Set X} : AreSeparated s (⋃ i ∈ I, t i) ↔ ∀ i ∈ I, AreSeparated s (t i) := by simpa only [@comm _ _ s] using finite_iUnion_left_iff hI @[simp] theorem finset_iUnion_left_iff {ι : Type*} {I : Finset ι} {s : ι → Set X} {t : Set X} : AreSeparated (⋃ i ∈ I, s i) t ↔ ∀ i ∈ I, AreSeparated (s i) t := finite_iUnion_left_iff I.finite_toSet alias ⟨_, finset_iUnion_left⟩ := finset_iUnion_left_iff @[simp] theorem finset_iUnion_right_iff {ι : Type*} {I : Finset ι} {s : Set X} {t : ι → Set X} : AreSeparated s (⋃ i ∈ I, t i) ↔ ∀ i ∈ I, AreSeparated s (t i) := finite_iUnion_right_iff I.finite_toSet alias ⟨_, finset_iUnion_right⟩ := finset_iUnion_right_iff end Metric.AreSeparated
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Basic.lean
import Mathlib.Topology.MetricSpace.Pseudo.Basic import Mathlib.Topology.MetricSpace.Pseudo.Lemmas import Mathlib.Topology.MetricSpace.Pseudo.Pi import Mathlib.Topology.MetricSpace.Defs /-! # Basic properties of metric spaces, and instances. -/ open Set Filter Bornology Topology open scoped NNReal Uniformity universe u v w variable {α : Type u} {β : Type v} {X : Type*} variable [PseudoMetricSpace α] variable {γ : Type w} [MetricSpace γ] namespace Metric variable {x : γ} {s : Set γ} -- see Note [lower instance priority] instance (priority := 100) _root_.MetricSpace.instT0Space : T0Space γ where t0 _ _ h := eq_of_dist_eq_zero <| Metric.inseparable_iff.1 h /-- A map between metric spaces is a uniform embedding if and only if the distance between `f x` and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/ theorem isUniformEmbedding_iff' [PseudoMetricSpace β] {f : γ → β} : IsUniformEmbedding f ↔ (∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, dist a b < δ → dist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, dist (f a) (f b) < ε → dist a b < δ := by rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff] /-- If a `PseudoMetricSpace` is a T₀ space, then it is a `MetricSpace`. -/ abbrev _root_.MetricSpace.ofT0PseudoMetricSpace (α : Type*) [PseudoMetricSpace α] [T0Space α] : MetricSpace α where toPseudoMetricSpace := ‹_› eq_of_dist_eq_zero hdist := (Metric.inseparable_iff.2 hdist).eq -- see Note [lower instance priority] /-- A metric space induces an emetric space -/ instance (priority := 100) _root_.MetricSpace.toEMetricSpace : EMetricSpace γ := .ofT0PseudoEMetricSpace γ theorem isClosed_of_pairwise_le_dist {s : Set γ} {ε : ℝ} (hε : 0 < ε) (hs : s.Pairwise fun x y => ε ≤ dist x y) : IsClosed s := isClosed_of_spaced_out (dist_mem_uniformity hε) <| by simpa using hs theorem isClosedEmbedding_of_pairwise_le_dist {α : Type*} [TopologicalSpace α] [DiscreteTopology α] {ε : ℝ} (hε : 0 < ε) {f : α → γ} (hf : Pairwise fun x y => ε ≤ dist (f x) (f y)) : IsClosedEmbedding f := isClosedEmbedding_of_spaced_out (dist_mem_uniformity hε) <| by simpa using hf /-- If `f : β → α` sends any two distinct points to points at distance at least `ε > 0`, then `f` is a uniform embedding with respect to the discrete uniformity on `β`. -/ theorem isUniformEmbedding_bot_of_pairwise_le_dist {β : Type*} {ε : ℝ} (hε : 0 < ε) {f : β → α} (hf : Pairwise fun x y => ε ≤ dist (f x) (f y)) : @IsUniformEmbedding _ _ ⊥ (by infer_instance) f := isUniformEmbedding_of_spaced_out (dist_mem_uniformity hε) <| by simpa using hf end Metric /-- One gets a metric space from an emetric space if the edistance is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the uniformity are defeq in the metric space and the emetric space. In this definition, the distance is given separately, to be able to prescribe some expression which is not defeq to the push-forward of the edistance to reals. -/ abbrev EMetricSpace.toMetricSpaceOfDist {α : Type u} [EMetricSpace α] (dist : α → α → ℝ) (dist_nonneg : ∀ x y, 0 ≤ dist x y) (h : ∀ x y, edist x y = .ofReal (dist x y)) : MetricSpace α := letI := PseudoEMetricSpace.toPseudoMetricSpaceOfDist dist dist_nonneg h MetricSpace.ofT0PseudoMetricSpace _ /-- One gets a metric space from an emetric space if the edistance is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the uniformity are defeq in the metric space and the emetric space. -/ abbrev EMetricSpace.toMetricSpace {α : Type u} [EMetricSpace α] (h : ∀ x y : α, edist x y ≠ ⊤) : MetricSpace α := EMetricSpace.toMetricSpaceOfDist (ENNReal.toReal <| edist · ·) (by simp) (by simp [h]) /-- Metric space structure pulled back by an injective function. Injectivity is necessary to ensure that `dist x y = 0` only if `x = y`. -/ abbrev MetricSpace.induced {γ β} (f : γ → β) (hf : Function.Injective f) (m : MetricSpace β) : MetricSpace γ := { PseudoMetricSpace.induced f m.toPseudoMetricSpace with eq_of_dist_eq_zero := fun h => hf (dist_eq_zero.1 h) } /-- Pull back a metric space structure by a uniform embedding. This is a version of `MetricSpace.induced` useful in case if the domain already has a `UniformSpace` structure. -/ abbrev IsUniformEmbedding.comapMetricSpace {α β} [UniformSpace α] [m : MetricSpace β] (f : α → β) (h : IsUniformEmbedding f) : MetricSpace α := .replaceUniformity (.induced f h.injective m) h.comap_uniformity.symm /-- Pull back a metric space structure by an embedding. This is a version of `MetricSpace.induced` useful in case if the domain already has a `TopologicalSpace` structure. -/ abbrev Topology.IsEmbedding.comapMetricSpace {α β} [TopologicalSpace α] [m : MetricSpace β] (f : α → β) (h : IsEmbedding f) : MetricSpace α := .replaceTopology (.induced f h.injective m) h.eq_induced instance Subtype.metricSpace {α : Type*} {p : α → Prop} [MetricSpace α] : MetricSpace (Subtype p) := .induced Subtype.val Subtype.coe_injective ‹_› @[to_additive] instance MulOpposite.instMetricSpace {α : Type*} [MetricSpace α] : MetricSpace αᵐᵒᵖ := MetricSpace.induced MulOpposite.unop MulOpposite.unop_injective ‹_› section Real /-- Instantiate the reals as a metric space. -/ instance Real.metricSpace : MetricSpace ℝ := .ofT0PseudoMetricSpace ℝ end Real section NNReal instance : MetricSpace ℝ≥0 := Subtype.metricSpace end NNReal instance [MetricSpace β] : MetricSpace (ULift β) := MetricSpace.induced ULift.down ULift.down_injective ‹_› section Prod instance Prod.metricSpaceMax [MetricSpace β] : MetricSpace (γ × β) := .ofT0PseudoMetricSpace _ end Prod section Pi open Finset variable {X : β → Type*} [Fintype β] [∀ b, MetricSpace (X b)] /-- A finite product of metric spaces is a metric space, with the sup distance. -/ instance metricSpacePi : MetricSpace (∀ b, X b) := .ofT0PseudoMetricSpace _ end Pi namespace Metric section SecondCountable open TopologicalSpace -- TODO: use `Countable` instead of `Encodable` /-- A metric space is second countable if one can reconstruct up to any `ε>0` any element of the space from countably many data. -/ theorem secondCountable_of_countable_discretization {α : Type u} [PseudoMetricSpace α] (H : ∀ ε > (0 : ℝ), ∃ (β : Type*) (_ : Encodable β) (F : α → β), ∀ x y, F x = F y → dist x y ≤ ε) : SecondCountableTopology α := by refine secondCountable_of_almost_dense_set fun ε ε0 => ?_ rcases H ε ε0 with ⟨β, fβ, F, hF⟩ let Finv := rangeSplitting F refine ⟨range Finv, ⟨countable_range _, fun x => ?_⟩⟩ let x' := Finv ⟨F x, mem_range_self _⟩ have : F x' = F x := apply_rangeSplitting F _ exact ⟨x', mem_range_self _, hF _ _ this.symm⟩ end SecondCountable end Metric section EqRel -- TODO: add `dist_congr` similar to `edist_congr`? instance SeparationQuotient.instDist {α : Type u} [PseudoMetricSpace α] : Dist (SeparationQuotient α) where dist := lift₂ dist fun x y x' y' hx hy ↦ by rw [dist_edist, dist_edist, ← edist_mk x, ← edist_mk x', mk_eq_mk.2 hx, mk_eq_mk.2 hy] theorem SeparationQuotient.dist_mk {α : Type u} [PseudoMetricSpace α] (p q : α) : dist (mk p) (mk q) = dist p q := rfl instance SeparationQuotient.instMetricSpace {α : Type u} [PseudoMetricSpace α] : MetricSpace (SeparationQuotient α) := EMetricSpace.toMetricSpaceOfDist dist (surjective_mk.forall₂.2 fun _ _ ↦ dist_nonneg) <| surjective_mk.forall₂.2 edist_dist end EqRel namespace PseudoEMetricSpace open ENNReal variable {X : Type*} (m : PseudoEMetricSpace X) (d : X → X → ℝ≥0∞) (hd : d = edist) /-- Build new pseudoemetric space from an old one where the edistance is provably (but typically non-definitionally) equal to some given edistance. We also provide convenience versions for PseudoMetric, Emetric and Metric spaces. -/ -- See note [forgetful inheritance] -- See note [reducible non-instances] abbrev replaceEDist : PseudoEMetricSpace X where edist := d edist_self := by simp [hd] edist_comm := by simp [hd, edist_comm] edist_triangle := by simp [hd, edist_triangle] uniformity_edist := by simp [hd, uniformity_edist] __ := m lemma replaceEDist_eq : m.replaceEDist d hd = m := by ext : 2; exact hd -- Check uniformity is unchanged example : (replaceEDist m d hd).toUniformSpace = m.toUniformSpace := by with_reducible dsimp [replaceEDist] end PseudoEMetricSpace namespace PseudoMetricSpace variable {X : Type*} (m : PseudoMetricSpace X) (d : X → X → ℝ) (hd : d = dist) /-- Build new pseudometric space from an old one where the distance is provably (but typically non-definitionally) equal to some given distance. We also provide convenience versions for PseudoEMetric, Emetric and Metric spaces. -/ -- See note [forgetful inheritance] -- See note [reducible non-instances] abbrev replaceDist : PseudoMetricSpace X where dist := d dist_self := by simp [hd] dist_comm := by simp [hd, dist_comm] dist_triangle := by simp [hd, dist_triangle] edist_dist := by simp [hd, edist_dist] uniformity_dist := by simp [hd, uniformity_dist] cobounded_sets := by simp [hd, cobounded_sets] __ := m lemma replaceDist_eq : m.replaceDist d hd = m := by ext : 2; exact hd -- Check uniformity is unchanged example : (replaceDist m d hd).toUniformSpace = m.toUniformSpace := by with_reducible dsimp [replaceDist] -- Check Bornology is unchanged example : (replaceDist m d hd).toBornology = m.toBornology := by with_reducible dsimp [replaceDist] end PseudoMetricSpace namespace EMetricSpace open ENNReal variable {X : Type*} (m : EMetricSpace X) (d : X → X → ℝ≥0∞) (hd : d = edist) /-- Build new emetric space from an old one where the edistance is provably (but typically non-definitionally) equal to some given edistance. We also provide convenience versions for PseudoEMetric, PseudoMetric and Metric spaces. -/ -- See note [forgetful inheritance] -- See note [reducible non-instances] abbrev replaceEDist : EMetricSpace X where edist := d edist_self := by simp [hd] edist_comm := by simp [hd, edist_comm] edist_triangle := by simp [hd, edist_triangle] eq_of_edist_eq_zero := by simp [hd] lemma replaceEDist_eq : m.replaceEDist d hd = m := by ext : 2; exact hd -- Check uniformity is unchanged example : (replaceEDist m d hd).toUniformSpace = m.toUniformSpace := by with_reducible simp [replaceEDist_eq] end EMetricSpace namespace MetricSpace variable {X : Type*} (m : MetricSpace X) (d : X → X → ℝ) (hd : d = dist) /-- Build new metric space from an old one where the distance is provably (but typically non-definitionally) equal to some given distance. We also provide convenience versions for PseudoEMetric, PseudoMatric and EMetric spaces. -/ -- See note [forgetful inheritance] -- See note [reducible non-instances] abbrev replaceDist : MetricSpace X where dist := d dist_self := by simp [hd] dist_comm := by simp [hd, dist_comm] dist_triangle := by simp [hd, dist_triangle] eq_of_dist_eq_zero := by simp [hd] lemma replaceDist_eq : m.replaceDist d hd = m := by ext : 2; exact hd -- Check uniformity is unchanged example : (replaceDist m d hd).toUniformSpace = m.toUniformSpace := by with_reducible simp [replaceDist_eq] -- Check Bornology is unchanged example : (replaceDist m d hd).toBornology = m.toBornology := by with_reducible simp [replaceDist_eq] end MetricSpace
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/UniformConvergence.lean
import Mathlib.Order.CompleteLattice.Group import Mathlib.Topology.ContinuousMap.Bounded.Basic import Mathlib.Topology.ContinuousMap.Compact import Mathlib.Topology.MetricSpace.Lipschitz import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Metric structure on `α →ᵤ β` and `α →ᵤ[𝔖] β` for finite `𝔖` When `β` is a (pseudo, extended) metric space it is a uniform space, and therefore we may consider the type `α →ᵤ β` of functions equipped with the topology of uniform convergence. The natural (pseudo, extended) metric on this space is given by `fun f g ↦ ⨆ x, edist (f x) (g x)`, and this induces the existing uniformity. Unless `β` is a bounded space, this will not be a (pseudo) metric space (except in the trivial case where `α` is empty). When `𝔖 : Set (Set α)` is a collection of subsets, we may equip the space of functions with the (pseudo, extended) metric `fun f g ↦ ⨆ x ∈ ⋃₀ 𝔖, edist (f x) (g x)`. *However*, this only induces the pre-existing uniformity on `α →ᵤ[𝔖] β` if `𝔖` is finite, and hence we only have an instance in that case. Nevertheless, this still covers the most important case, such as when `𝔖` is a singleton. Furthermore, we note that this is essentially a mathematical obstruction, not a technical one: indeed, the uniformity of `α →ᵤ[𝔖] β` is countably generated only when there is a sequence `t : ℕ → Finset (Set α)` such that, for each `n`, `t n ⊆ 𝔖`, `fun n ↦ Finset.sup (t n)` is monotone and for every `s ∈ 𝔖`, there is some `n` such that `s ⊆ Finset.sup (t n)` (see `UniformOnFun.isCountablyGenerated_uniformity`). So, while the `𝔖` for which `α →ᵤ[𝔖] β` is metrizable include some non-finite `𝔖`, there are some `𝔖` which are not metrizable, and moreover, it is only when `𝔖` is finite that `⨆ x ∈ ⋃₀ 𝔖, edist (f x) (g x)` is a metric which induces the uniformity. There are a few advantages of equipping this space with this metric structure. 1. A function `f : X → α →ᵤ β` is Lipschitz in this metric if and only if for every `a : α` it is Lipschitz in the first variable with the same Lipschitz constant. 2. It provides a natural setting in which one can talk about the metrics on `α →ᵇ β` or, when `α` is compact, `C(α, β)`, relative to their underlying bare functions. -/ variable {α β γ : Type*} [PseudoEMetricSpace γ] open scoped UniformConvergence NNReal ENNReal open Filter Topology Uniformity namespace UniformFun section EMetric variable [PseudoEMetricSpace β] noncomputable instance : EDist (α →ᵤ β) where edist f g := ⨆ x, edist (toFun f x) (toFun g x) lemma edist_def (f g : α →ᵤ β) : edist f g = ⨆ x, edist (toFun f x) (toFun g x) := rfl lemma edist_le {f g : α →ᵤ β} {C : ℝ≥0∞} : edist f g ≤ C ↔ ∀ x, edist (toFun f x) (toFun g x) ≤ C := iSup_le_iff /-- The natural `EMetric` structure on `α →ᵤ β` given by `edist f g = ⨆ x, edist (f x) (g x)`. -/ noncomputable instance : PseudoEMetricSpace (α →ᵤ β) where edist_self := by simp [edist_def] edist_comm := by simp [edist_def, edist_comm] edist_triangle f₁ f₂ f₃ := calc ⨆ x, edist (f₁ x) (f₃ x) ≤ ⨆ x, edist (f₁ x) (f₂ x) + edist (f₂ x) (f₃ x) := iSup_mono fun _ ↦ edist_triangle _ _ _ _ ≤ (⨆ x, edist (f₁ x) (f₂ x)) + (⨆ x, edist (f₂ x) (f₃ x)) := iSup_add_le _ _ toUniformSpace := inferInstance uniformity_edist := by suffices 𝓤 (α →ᵤ β) = comap (fun x ↦ edist x.1 x.2) (𝓝 0) by simp [this, ENNReal.nhds_zero_basis.comap _ |>.eq_biInf, Set.Iio] rw [ENNReal.nhds_zero_basis_Iic.comap _ |>.eq_biInf] rw [UniformFun.hasBasis_uniformity_of_basis α β uniformity_basis_edist_le |>.eq_biInf] simp [UniformFun.gen, edist_le, Set.Iic] noncomputable instance {β : Type*} [EMetricSpace β] : EMetricSpace (α →ᵤ β) := .ofT0PseudoEMetricSpace _ lemma lipschitzWith_iff {f : γ → α →ᵤ β} {K : ℝ≥0} : LipschitzWith K f ↔ ∀ c, LipschitzWith K (fun x ↦ toFun (f x) c) := by simp [LipschitzWith, edist_le, forall_comm (α := α)] lemma lipschitzWith_ofFun_iff {f : γ → α → β} {K : ℝ≥0} : LipschitzWith K (fun x ↦ ofFun (f x)) ↔ ∀ c, LipschitzWith K (f · c) := lipschitzWith_iff /-- If `f : α → γ → β` is a family of a functions, all of which are Lipschitz with the same constant, then the family is uniformly equicontinuous. -/ lemma _root_.LipschitzWith.uniformEquicontinuous (f : α → γ → β) (K : ℝ≥0) (h : ∀ c, LipschitzWith K (f c)) : UniformEquicontinuous f := by rw [uniformEquicontinuous_iff_uniformContinuous] rw [← lipschitzWith_ofFun_iff] at h exact h.uniformContinuous lemma lipschitzOnWith_iff {f : γ → α →ᵤ β} {K : ℝ≥0} {s : Set γ} : LipschitzOnWith K f s ↔ ∀ c, LipschitzOnWith K (fun x ↦ toFun (f x) c) s := by simp [lipschitzOnWith_iff_restrict, lipschitzWith_iff] rfl lemma lipschitzOnWith_ofFun_iff {f : γ → α → β} {K : ℝ≥0} {s : Set γ} : LipschitzOnWith K (fun x ↦ ofFun (f x)) s ↔ ∀ c, LipschitzOnWith K (f · c) s := lipschitzOnWith_iff /-- If `f : α → γ → β` is a family of a functions, all of which are Lipschitz on `s` with the same constant, then the family is uniformly equicontinuous on `s`. -/ lemma _root_.LipschitzOnWith.uniformEquicontinuousOn (f : α → γ → β) (K : ℝ≥0) {s : Set γ} (h : ∀ c, LipschitzOnWith K (f c) s) : UniformEquicontinuousOn f s := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn] rw [← lipschitzOnWith_ofFun_iff] at h exact h.uniformContinuousOn lemma edist_eval_le {f g : α →ᵤ β} {x : α} : edist (toFun f x) (toFun g x) ≤ edist f g := edist_le.mp le_rfl x lemma lipschitzWith_eval (x : α) : LipschitzWith 1 (fun f : α →ᵤ β ↦ toFun f x) := by intro f g simpa using edist_eval_le end EMetric section Metric variable [PseudoMetricSpace β] noncomputable instance [BoundedSpace β] : PseudoMetricSpace (α →ᵤ β) := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun f g ↦ ⨆ x, dist (toFun f x) (toFun g x)) (fun _ _ ↦ Real.iSup_nonneg fun i ↦ dist_nonneg) fun f g ↦ by cases isEmpty_or_nonempty α · simp [edist_def] have : BddAbove <| .range fun x ↦ dist (toFun f x) (toFun g x) := by use (EMetric.diam (.univ : Set β)).toReal simp +contextual [mem_upperBounds, eq_comm (a := dist _ _), ← edist_dist, ← ENNReal.ofReal_le_iff_le_toReal BoundedSpace.bounded_univ.ediam_ne_top, EMetric.edist_le_diam_of_mem] exact ENNReal.eq_of_forall_le_nnreal_iff fun r ↦ by simp [edist_def, ciSup_le_iff this] lemma dist_def [BoundedSpace β] (f g : α →ᵤ β) : dist f g = ⨆ x, dist (toFun f x) (toFun g x) := rfl lemma dist_le [BoundedSpace β] {f g : α →ᵤ β} {C : ℝ} (hC : 0 ≤ C) : dist f g ≤ C ↔ ∀ x, dist (toFun f x) (toFun g x) ≤ C := by simp_rw [dist_edist, ← ENNReal.le_ofReal_iff_toReal_le (edist_ne_top _ _) hC, edist_le] noncomputable instance [BoundedSpace β] : BoundedSpace (α →ᵤ β) where bounded_univ := by rw [Metric.isBounded_iff_ediam_ne_top, ← lt_top_iff_ne_top] refine lt_of_le_of_lt ?_ <| BoundedSpace.bounded_univ (α := β) |>.ediam_ne_top.lt_top simp only [EMetric.diam_le_iff, Set.mem_univ, edist_le, forall_const] exact fun f g x ↦ EMetric.edist_le_diam_of_mem (Set.mem_univ _) (Set.mem_univ _) noncomputable instance {β : Type*} [MetricSpace β] [BoundedSpace β] : MetricSpace (α →ᵤ β) := .ofT0PseudoMetricSpace _ open BoundedContinuousFunction in lemma isometry_ofFun_boundedContinuousFunction [TopologicalSpace α] : Isometry (ofFun ∘ DFunLike.coe : (α →ᵇ β) → α →ᵤ β) := by simp [Isometry, edist_def, edist_eq_iSup] lemma isometry_ofFun_continuousMap [TopologicalSpace α] [CompactSpace α] : Isometry (ofFun ∘ DFunLike.coe : C(α, β) → α →ᵤ β) := isometry_ofFun_boundedContinuousFunction.comp <| ContinuousMap.isometryEquivBoundedOfCompact α β |>.isometry lemma edist_continuousMapMk [TopologicalSpace α] [CompactSpace α] {f g : α →ᵤ β} (hf : Continuous (toFun f)) (hg : Continuous (toFun g)) : edist (⟨_, hf⟩ : C(α, β)) ⟨_, hg⟩ = edist f g := by simp [← isometry_ofFun_continuousMap.edist_eq] end Metric end UniformFun namespace UniformOnFun variable {𝔖 𝔗 : Set (Set α)} section EMetric variable [PseudoEMetricSpace β] /-- Let `f : γ → α →ᵤ[𝔖] β`. If for every `s ∈ 𝔖` and for every `c ∈ s`, the function `fun x ↦ f x c` is Lipschitz (with Lipschitz constant depending on `s`), then `f` is continuous. -/ lemma continuous_of_forall_lipschitzWith {f : γ → α →ᵤ[𝔖] β} (K : Set α → ℝ≥0) (h : ∀ s ∈ 𝔖, ∀ c ∈ s, LipschitzWith (K s) (fun x ↦ toFun 𝔖 (f x) c)) : Continuous f := by rw [UniformOnFun.continuous_rng_iff] refine fun s hs ↦ LipschitzWith.continuous (K := K s) ?_ rw [UniformFun.lipschitzWith_iff] rintro ⟨y, hy⟩ exact h s hs y hy @[nolint unusedArguments] noncomputable instance [Finite 𝔖] : EDist (α →ᵤ[𝔖] β) where edist f g := ⨆ x ∈ ⋃₀ 𝔖, edist (toFun 𝔖 f x) (toFun 𝔖 g x) lemma edist_def [Finite 𝔖] (f g : α →ᵤ[𝔖] β) : edist f g = ⨆ x ∈ ⋃₀ 𝔖, edist (toFun 𝔖 f x) (toFun 𝔖 g x) := rfl lemma edist_def' [Finite 𝔖] (f g : α →ᵤ[𝔖] β) : edist f g = ⨆ s ∈ 𝔖, ⨆ x ∈ s, edist (toFun 𝔖 f x) (toFun 𝔖 g x) := by simp [edist_def, iSup_and, iSup_comm (ι := α)] lemma edist_eq_restrict_sUnion [Finite 𝔖] {f g : α →ᵤ[𝔖] β} : edist f g = edist (UniformFun.ofFun ((⋃₀ 𝔖).restrict (toFun 𝔖 f))) (UniformFun.ofFun ((⋃₀ 𝔖).restrict (toFun 𝔖 g))) := iSup_subtype' lemma edist_eq_pi_restrict [Fintype 𝔖] {f g : α →ᵤ[𝔖] β} : edist f g = edist (fun s : 𝔖 ↦ UniformFun.ofFun ((s : Set α).restrict (toFun 𝔖 f))) (fun s : 𝔖 ↦ UniformFun.ofFun ((s : Set α).restrict (toFun 𝔖 g))) := by simp_rw [edist_def', iSup_subtype', edist_pi_def, Finset.sup_univ_eq_iSup] rfl variable [Finite 𝔖] /-- The natural `EMetric` structure on `α →ᵤ[𝔖] β` when `𝔖` is finite given by `edist f g = ⨆ x ∈ ⋃₀ 𝔖, edist (f x) (g x)`. -/ noncomputable instance : PseudoEMetricSpace (α →ᵤ[𝔖] β) where edist_self f := by simp [edist_eq_restrict_sUnion] edist_comm := by simp [edist_eq_restrict_sUnion, edist_comm] edist_triangle f₁ f₂ f₃ := by simp [edist_eq_restrict_sUnion, edist_triangle] toUniformSpace := inferInstance uniformity_edist := by let _ := Fintype.ofFinite 𝔖; simp_rw [← isUniformInducing_pi_restrict.comap_uniformity, PseudoEMetricSpace.uniformity_edist, comap_iInf, comap_principal, edist_eq_pi_restrict, Set.preimage_setOf_eq] lemma edist_le {f g : α →ᵤ[𝔖] β} {C : ℝ≥0∞} : edist f g ≤ C ↔ ∀ x ∈ ⋃₀ 𝔖, edist (toFun 𝔖 f x) (toFun 𝔖 g x) ≤ C := by simp_rw [edist_def, iSup₂_le_iff] lemma lipschitzWith_iff {f : γ → α →ᵤ[𝔖] β} {K : ℝ≥0} : LipschitzWith K f ↔ ∀ c ∈ ⋃₀ 𝔖, LipschitzWith K (fun x ↦ toFun 𝔖 (f x) c) := by simp [LipschitzWith, edist_le] tauto lemma lipschitzOnWith_iff {f : γ → α →ᵤ[𝔖] β} {K : ℝ≥0} {s : Set γ} : LipschitzOnWith K f s ↔ ∀ c ∈ ⋃₀ 𝔖, LipschitzOnWith K (fun x ↦ toFun 𝔖 (f x) c) s := by simp [lipschitzOnWith_iff_restrict, lipschitzWith_iff] rfl lemma edist_eval_le {f g : α →ᵤ[𝔖] β} {x : α} (hx : x ∈ ⋃₀ 𝔖) : edist (toFun 𝔖 f x) (toFun 𝔖 g x) ≤ edist f g := edist_le.mp le_rfl x hx lemma lipschitzWith_eval {x : α} (hx : x ∈ ⋃₀ 𝔖) : LipschitzWith 1 (fun f : α →ᵤ[𝔖] β ↦ toFun 𝔖 f x) := by intro f g simpa only [ENNReal.coe_one, one_mul] using edist_eval_le hx lemma lipschitzWith_one_ofFun_toFun : LipschitzWith 1 (ofFun 𝔖 ∘ UniformFun.toFun : (α →ᵤ β) → (α →ᵤ[𝔖] β)) := lipschitzWith_iff.mpr fun _ _ ↦ UniformFun.lipschitzWith_eval _ lemma lipschitzWith_one_ofFun_toFun' [Finite 𝔗] (h : ⋃₀ 𝔖 ⊆ ⋃₀ 𝔗) : LipschitzWith 1 (ofFun 𝔖 ∘ toFun 𝔗 : (α →ᵤ[𝔗] β) → (α →ᵤ[𝔖] β)) := lipschitzWith_iff.mpr fun _x hx ↦ lipschitzWith_eval (h hx) lemma lipschitzWith_restrict (s : Set α) (hs : s ∈ 𝔖) : LipschitzWith 1 (UniformFun.ofFun ∘ s.restrict ∘ toFun 𝔖 : (α →ᵤ[𝔖] β) → (s →ᵤ β)) := UniformFun.lipschitzWith_iff.mpr fun x ↦ lipschitzWith_eval ⟨s, hs, x.2⟩ lemma isometry_restrict (s : Set α) : Isometry (UniformFun.ofFun ∘ s.restrict ∘ toFun {s} : (α →ᵤ[{s}] β) → (s →ᵤ β)) := by simp [Isometry, edist_def, UniformFun.edist_def, iSup_subtype] end EMetric section Metric variable [Finite 𝔖] [PseudoMetricSpace β] noncomputable instance [BoundedSpace β] : PseudoMetricSpace (α →ᵤ[𝔖] β) := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun f g ↦ ⨆ x : ⋃₀ 𝔖, dist (toFun 𝔖 f x) (toFun 𝔖 g x)) (fun _ _ ↦ Real.iSup_nonneg fun i ↦ dist_nonneg) fun f g ↦ by cases isEmpty_or_nonempty (⋃₀ 𝔖) · simp_all [edist_def] have : BddAbove (.range fun x : ⋃₀ 𝔖 ↦ dist (toFun 𝔖 f x) (toFun 𝔖 g x)) := by use (EMetric.diam (.univ : Set β)).toReal simp +contextual [mem_upperBounds, eq_comm (a := dist _ _), ← edist_dist, ← ENNReal.ofReal_le_iff_le_toReal BoundedSpace.bounded_univ.ediam_ne_top, EMetric.edist_le_diam_of_mem] refine ENNReal.eq_of_forall_le_nnreal_iff fun r ↦ ?_ simp [edist_def, ciSup_le_iff this] noncomputable instance [BoundedSpace β] : BoundedSpace (α →ᵤ[𝔖] β) where bounded_univ := by convert lipschitzWith_one_ofFun_toFun (𝔖 := 𝔖) (β := β) |>.isBounded_image (.all Set.univ) ext f simp only [Set.mem_univ, Function.comp_apply, Set.image_univ, Set.mem_range, true_iff] exact ⟨UniformFun.ofFun (toFun 𝔖 f), by simp⟩ lemma edist_continuousRestrict [TopologicalSpace α] {f g : α →ᵤ[𝔖] β} [CompactSpace (⋃₀ 𝔖)] (hf : ContinuousOn (toFun 𝔖 f) (⋃₀ 𝔖)) (hg : ContinuousOn (toFun 𝔖 g) (⋃₀ 𝔖)) : edist (⟨_, hf.restrict⟩ : C(⋃₀ 𝔖, β)) ⟨_, hg.restrict⟩ = edist f g := by simp [ContinuousMap.edist_eq_iSup, iSup_subtype, edist_def] lemma edist_continuousRestrict_of_singleton [TopologicalSpace α] {s : Set α} {f g : α →ᵤ[{s}] β} [CompactSpace s] (hf : ContinuousOn (toFun {s} f) s) (hg : ContinuousOn (toFun {s} g) s) : edist (⟨_, hf.restrict⟩ : C(s, β)) ⟨_, hg.restrict⟩ = edist f g := by simp [ContinuousMap.edist_eq_iSup, iSup_subtype, edist_def] end Metric end UniformOnFun
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/CauSeqFilter.lean
import Mathlib.Analysis.Normed.Field.Basic import Mathlib.Topology.MetricSpace.Cauchy /-! # Completeness in terms of `Cauchy` filters vs `isCauSeq` sequences In this file we apply `Metric.complete_of_cauchySeq_tendsto` to prove that a `NormedRing` is complete in terms of `Cauchy` filter if and only if it is complete in terms of `CauSeq` Cauchy sequences. -/ universe u v open Set Filter Topology variable {β : Type v} theorem CauSeq.tendsto_limit [NormedRing β] [hn : IsAbsoluteValue (norm : β → ℝ)] (f : CauSeq β norm) [CauSeq.IsComplete β norm] : Tendsto f atTop (𝓝 f.lim) := tendsto_nhds.mpr (by intro s os lfs suffices ∃ a : ℕ, ∀ b : ℕ, b ≥ a → f b ∈ s by simpa using this rcases Metric.isOpen_iff.1 os _ lfs with ⟨ε, ⟨hε, hεs⟩⟩ obtain ⟨N, hN⟩ := Setoid.symm (CauSeq.equiv_lim f) _ hε exists N intro b hb apply hεs dsimp [Metric.ball] rw [dist_comm, dist_eq_norm] solve_by_elim) variable [NormedField β] /- This section shows that if we have a uniform space generated by an absolute value, topological completeness and Cauchy sequence completeness coincide. The problem is that there isn't a good notion of "uniform space generated by an absolute value", so right now this is specific to norm. Furthermore, norm only instantiates IsAbsoluteValue on NormedDivisionRing. This needs to be fixed, since it prevents showing that ℤ_[hp] is complete. -/ open Metric theorem CauchySeq.isCauSeq {f : ℕ → β} (hf : CauchySeq f) : IsCauSeq norm f := by obtain ⟨hf1, hf2⟩ := cauchy_iff.1 hf intro ε hε rcases hf2 { x | dist x.1 x.2 < ε } (dist_mem_uniformity hε) with ⟨t, ⟨ht, htsub⟩⟩ simp only [mem_map, mem_atTop_sets, mem_preimage] at ht; obtain ⟨N, hN⟩ := ht exists N intro j hj rw [← dist_eq_norm] apply @htsub (f j, f N) apply Set.mk_mem_prod <;> solve_by_elim [le_refl] theorem CauSeq.cauchySeq (f : CauSeq β norm) : CauchySeq f := by refine cauchy_iff.2 ⟨by infer_instance, fun s hs => ?_⟩ rcases mem_uniformity_dist.1 hs with ⟨ε, ⟨hε, hεs⟩⟩ obtain ⟨N, hN⟩ := CauSeq.cauchy₂ f hε exists { n | n ≥ N }.image f simp only [mem_atTop_sets, mem_map] constructor · exists N intro b hb exists b · rintro ⟨a, b⟩ ⟨⟨a', ⟨ha'1, ha'2⟩⟩, ⟨b', ⟨hb'1, hb'2⟩⟩⟩ dsimp at ha'1 ha'2 hb'1 hb'2 rw [← ha'2, ← hb'2] apply hεs rw [dist_eq_norm] apply hN <;> assumption /-- In a normed field, `CauSeq` coincides with the usual notion of Cauchy sequences. -/ theorem isCauSeq_iff_cauchySeq {α : Type u} [NormedField α] {u : ℕ → α} : IsCauSeq norm u ↔ CauchySeq u := ⟨fun h => CauSeq.cauchySeq ⟨u, h⟩, fun h => h.isCauSeq⟩ -- see Note [lower instance priority] /-- A complete normed field is complete as a metric space, as Cauchy sequences converge by assumption and this suffices to characterize completeness. -/ instance (priority := 100) completeSpace_of_cauSeq_isComplete [CauSeq.IsComplete β norm] : CompleteSpace β := by apply complete_of_cauchySeq_tendsto intro u hu have C : IsCauSeq norm u := isCauSeq_iff_cauchySeq.2 hu exists CauSeq.lim ⟨u, C⟩ rw [Metric.tendsto_atTop] intro ε εpos obtain ⟨N, hN⟩ := (CauSeq.equiv_lim ⟨u, C⟩) _ εpos exists N simpa [dist_eq_norm] using hN
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Similarity.lean
import Mathlib.Topology.MetricSpace.Congruence /-! # Similarities This file defines `Similar`, i.e., the equivalence between indexed sets of points in a metric space where all corresponding pairwise distances have the same ratio. The motivating example is triangles in the plane. ## Implementation notes For more details see the [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Euclidean.20Geometry). ## Notation Let `P₁` and `P₂` be metric spaces, let `ι` be an index set, and let `v₁ : ι → P₁` and `v₂ : ι → P₂` be indexed families of points. * `(v₁ ∼ v₂ : Prop)` represents that `(v₁ : ι → P₁)` and `(v₂ : ι → P₂)` are similar. -/ open scoped NNReal variable {ι ι' : Type*} {P₁ P₂ P₃ : Type*} {v₁ : ι → P₁} {v₂ : ι → P₂} {v₃ : ι → P₃} section PseudoEMetricSpace variable [PseudoEMetricSpace P₁] [PseudoEMetricSpace P₂] [PseudoEMetricSpace P₃] /-- Similarity between indexed sets of vertices v₁ and v₂. Use `open scoped Similar` to access the `v₁ ∼ v₂` notation. -/ def Similar (v₁ : ι → P₁) (v₂ : ι → P₂) : Prop := ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (edist (v₁ i₁) (v₁ i₂) = r * edist (v₂ i₁) (v₂ i₂)) @[inherit_doc] scoped[Similar] infixl:25 " ∼ " => Similar /-- Similarity holds if and only if all extended distances are proportional. -/ lemma similar_iff_exists_edist_eq : Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (edist (v₁ i₁) (v₁ i₂) = r * edist (v₂ i₁) (v₂ i₂))) := Iff.rfl /-- Similarity holds if and only if all extended distances between points with different indices are proportional. -/ lemma similar_iff_exists_pairwise_edist_eq : Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ Pairwise fun i₁ i₂ ↦ (edist (v₁ i₁) (v₁ i₂) = r * edist (v₂ i₁) (v₂ i₂))) := by rw [similar_iff_exists_edist_eq] refine ⟨?_, ?_⟩ <;> rintro ⟨r, hr, h⟩ <;> refine ⟨r, hr, fun i₁ i₂ ↦ ?_⟩ · exact fun _ ↦ h i₁ i₂ · by_cases hi : i₁ = i₂ · simp [hi] · exact h hi lemma Congruent.similar {v₁ : ι → P₁} {v₂ : ι → P₂} (h : Congruent v₁ v₂) : Similar v₁ v₂ := ⟨1, one_ne_zero, fun i₁ i₂ ↦ by simpa using h i₁ i₂⟩ namespace Similar /-- A similarity scales extended distance. Forward direction of `similar_iff_exists_edist_eq`. -/ alias ⟨exists_edist_eq, _⟩ := similar_iff_exists_edist_eq /-- Similarity follows from scaled extended distance. Backward direction of `similar_iff_exists_edist_eq`. -/ alias ⟨_, of_exists_edist_eq⟩ := similar_iff_exists_edist_eq /-- A similarity pairwise scales extended distance. Forward direction of `similar_iff_exists_pairwise_edist_eq`. -/ alias ⟨exists_pairwise_edist_eq, _⟩ := similar_iff_exists_pairwise_edist_eq /-- Similarity follows from pairwise scaled extended distance. Backward direction of `similar_iff_exists_pairwise_edist_eq`. -/ alias ⟨_, of_exists_pairwise_edist_eq⟩ := similar_iff_exists_pairwise_edist_eq @[refl] protected lemma refl (v₁ : ι → P₁) : v₁ ∼ v₁ := ⟨1, one_ne_zero, fun _ _ => by {norm_cast; rw [one_mul]}⟩ @[symm] protected lemma symm (h : v₁ ∼ v₂) : v₂ ∼ v₁ := by rcases h with ⟨r, hr, h⟩ refine ⟨r⁻¹, inv_ne_zero hr, fun _ _ => ?_⟩ rw [ENNReal.coe_inv hr, ← ENNReal.div_eq_inv_mul, ENNReal.eq_div_iff _ ENNReal.coe_ne_top, h] norm_cast lemma _root_.similar_comm : v₁ ∼ v₂ ↔ v₂ ∼ v₁ := ⟨Similar.symm, Similar.symm⟩ @[trans] protected lemma trans (h₁ : v₁ ∼ v₂) (h₂ : v₂ ∼ v₃) : v₁ ∼ v₃ := by rcases h₁ with ⟨r₁, hr₁, h₁⟩; rcases h₂ with ⟨r₂, hr₂, h₂⟩ refine ⟨r₁ * r₂, mul_ne_zero hr₁ hr₂, fun _ _ => ?_⟩ rw [ENNReal.coe_mul, mul_assoc, h₁, h₂] /-- Change the index set ι to an index ι' that maps to ι. -/ lemma index_map (h : v₁ ∼ v₂) (f : ι' → ι) : (v₁ ∘ f) ∼ (v₂ ∘ f) := by rcases h with ⟨r, hr, h⟩ refine ⟨r, hr, fun _ _ => ?_⟩ apply h /-- Change between equivalent index sets ι and ι'. -/ @[simp] lemma index_equiv (f : ι' ≃ ι) (v₁ : ι → P₁) (v₂ : ι → P₂) : v₁ ∘ f ∼ v₂ ∘ f ↔ v₁ ∼ v₂ := by refine ⟨fun h => ?_, fun h => Similar.index_map h f⟩ rcases h with ⟨r, hr, h⟩ refine ⟨r, hr, fun i₁ i₂ => ?_⟩ simpa [f.right_inv i₁, f.right_inv i₂] using h (f.symm i₁) (f.symm i₂) end Similar end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace P₁] [PseudoMetricSpace P₂] /-- Similarity holds if and only if all non-negative distances are proportional. -/ lemma similar_iff_exists_nndist_eq : Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (nndist (v₁ i₁) (v₁ i₂) = r * nndist (v₂ i₁) (v₂ i₂))) := exists_congr <| fun _ => and_congr Iff.rfl <| forall₂_congr <| fun _ _ => by { rw [edist_nndist, edist_nndist]; norm_cast } /-- Similarity holds if and only if all non-negative distances between points with different indices are proportional. -/ lemma similar_iff_exists_pairwise_nndist_eq : Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ Pairwise fun i₁ i₂ ↦ (nndist (v₁ i₁) (v₁ i₂) = r * nndist (v₂ i₁) (v₂ i₂))) := by simp_rw [similar_iff_exists_pairwise_edist_eq, edist_nndist] exact_mod_cast Iff.rfl /-- Similarity holds if and only if all distances are proportional. -/ lemma similar_iff_exists_dist_eq : Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (dist (v₁ i₁) (v₁ i₂) = r * dist (v₂ i₁) (v₂ i₂))) := similar_iff_exists_nndist_eq.trans (exists_congr <| fun _ => and_congr Iff.rfl <| forall₂_congr <| fun _ _ => by { rw [dist_nndist, dist_nndist]; norm_cast }) /-- Similarity holds if and only if all distances between points with different indices are proportional. -/ lemma similar_iff_exists_pairwise_dist_eq : Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ Pairwise fun i₁ i₂ ↦ (dist (v₁ i₁) (v₁ i₂) = r * dist (v₂ i₁) (v₂ i₂))) := by simp_rw [similar_iff_exists_pairwise_nndist_eq, dist_nndist] exact_mod_cast Iff.rfl namespace Similar /-- A similarity scales non-negative distance. Forward direction of `similar_iff_exists_nndist_eq`. -/ alias ⟨exists_nndist_eq, _⟩ := similar_iff_exists_nndist_eq /-- Similarity follows from scaled non-negative distance. Backward direction of `similar_iff_exists_nndist_eq`. -/ alias ⟨_, of_exists_nndist_eq⟩ := similar_iff_exists_nndist_eq /-- A similarity scales distance. Forward direction of `similar_iff_exists_dist_eq`. -/ alias ⟨exists_dist_eq, _⟩ := similar_iff_exists_dist_eq /-- Similarity follows from scaled distance. Backward direction of `similar_iff_exists_dist_eq`. -/ alias ⟨_, of_exists_dist_eq⟩ := similar_iff_exists_dist_eq /-- A similarity pairwise scales non-negative distance. Forward direction of `similar_iff_exists_pairwise_nndist_eq`. -/ alias ⟨exists_pairwise_nndist_eq, _⟩ := similar_iff_exists_pairwise_nndist_eq /-- Similarity follows from pairwise scaled non-negative distance. Backward direction of `similar_iff_exists_pairwise_nndist_eq`. -/ alias ⟨_, of_exists_pairwise_nndist_eq⟩ := similar_iff_exists_pairwise_nndist_eq /-- A similarity pairwise scales distance. Forward direction of `similar_iff_exists_pairwise_dist_eq`. -/ alias ⟨exists_pairwise_dist_eq, _⟩ := similar_iff_exists_pairwise_dist_eq /-- Similarity follows from pairwise scaled distance. Backward direction of `similar_iff_exists_pairwise_dist_eq`. -/ alias ⟨_, of_exists_pairwise_dist_eq⟩ := similar_iff_exists_pairwise_dist_eq end Similar end PseudoMetricSpace
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Antilipschitz.lean
import Mathlib.Topology.UniformSpace.CompleteSeparated import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded /-! # Antilipschitz functions We say that a map `f : α → β` between two (extended) metric spaces is `AntilipschitzWith K`, `K ≥ 0`, if for all `x, y` we have `edist x y ≤ K * edist (f x) (f y)`. For a metric space, the latter inequality is equivalent to `dist x y ≤ K * dist (f x) (f y)`. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. We do not require `0 < K` in the definition, mostly because we do not have a `posreal` type. -/ open Bornology Filter Set Topology open scoped NNReal ENNReal Uniformity variable {α β γ : Type*} /-- We say that `f : α → β` is `AntilipschitzWith K` if for any two points `x`, `y` we have `edist x y ≤ K * edist (f x) (f y)`. -/ def AntilipschitzWith [PseudoEMetricSpace α] [PseudoEMetricSpace β] (K : ℝ≥0) (f : α → β) := ∀ x y, edist x y ≤ K * edist (f x) (f y) protected lemma AntilipschitzWith.edist_lt_top [PseudoEMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} (h : AntilipschitzWith K f) (x y : α) : edist x y < ⊤ := (h x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_lt_top (edist_lt_top _ _) theorem AntilipschitzWith.edist_ne_top [PseudoEMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} (h : AntilipschitzWith K f) (x y : α) : edist x y ≠ ⊤ := (h.edist_lt_top x y).ne section Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} theorem antilipschitzWith_iff_le_mul_nndist : AntilipschitzWith K f ↔ ∀ x y, nndist x y ≤ K * nndist (f x) (f y) := by simp only [AntilipschitzWith, edist_nndist] norm_cast alias ⟨AntilipschitzWith.le_mul_nndist, AntilipschitzWith.of_le_mul_nndist⟩ := antilipschitzWith_iff_le_mul_nndist theorem antilipschitzWith_iff_le_mul_dist : AntilipschitzWith K f ↔ ∀ x y, dist x y ≤ K * dist (f x) (f y) := by simp only [antilipschitzWith_iff_le_mul_nndist, dist_nndist] norm_cast alias ⟨AntilipschitzWith.le_mul_dist, AntilipschitzWith.of_le_mul_dist⟩ := antilipschitzWith_iff_le_mul_dist namespace AntilipschitzWith theorem mul_le_nndist (hf : AntilipschitzWith K f) (x y : α) : K⁻¹ * nndist x y ≤ nndist (f x) (f y) := by simpa only [div_eq_inv_mul] using NNReal.div_le_of_le_mul' (hf.le_mul_nndist x y) theorem mul_le_dist (hf : AntilipschitzWith K f) (x y : α) : (K⁻¹ * dist x y : ℝ) ≤ dist (f x) (f y) := mod_cast hf.mul_le_nndist x y end AntilipschitzWith end Metric namespace AntilipschitzWith variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {K : ℝ≥0} {f : α → β} open EMetric -- uses neither `f` nor `hf` /-- Extract the constant from `hf : AntilipschitzWith K f`. This is useful, e.g., if `K` is given by a long formula, and we want to reuse this value. -/ @[nolint unusedArguments] protected def k (_hf : AntilipschitzWith K f) : ℝ≥0 := K protected theorem injective {α : Type*} {β : Type*} [EMetricSpace α] [PseudoEMetricSpace β] {K : ℝ≥0} {f : α → β} (hf : AntilipschitzWith K f) : Function.Injective f := fun x y h => by simpa only [h, edist_self, mul_zero, edist_le_zero] using hf x y theorem mul_le_edist (hf : AntilipschitzWith K f) (x y : α) : (K : ℝ≥0∞)⁻¹ * edist x y ≤ edist (f x) (f y) := by rw [mul_comm, ← div_eq_mul_inv] exact ENNReal.div_le_of_le_mul' (hf x y) theorem ediam_preimage_le (hf : AntilipschitzWith K f) (s : Set β) : diam (f ⁻¹' s) ≤ K * diam s := diam_le fun x hx y hy => by grw [hf x y, edist_le_diam_of_mem (mem_preimage.1 hx) hy] theorem le_mul_ediam_image (hf : AntilipschitzWith K f) (s : Set α) : diam s ≤ K * diam (f '' s) := (diam_mono (subset_preimage_image _ _)).trans (hf.ediam_preimage_le (f '' s)) protected theorem id : AntilipschitzWith 1 (id : α → α) := fun x y => by simp only [ENNReal.coe_one, one_mul, id, le_refl] theorem comp {Kg : ℝ≥0} {g : β → γ} (hg : AntilipschitzWith Kg g) {Kf : ℝ≥0} {f : α → β} (hf : AntilipschitzWith Kf f) : AntilipschitzWith (Kf * Kg) (g ∘ f) := fun x y => calc edist x y ≤ Kf * edist (f x) (f y) := hf x y _ ≤ Kf * (Kg * edist (g (f x)) (g (f y))) := mul_right_mono (hg _ _) _ = _ := by rw [ENNReal.coe_mul, mul_assoc]; rfl theorem restrict (hf : AntilipschitzWith K f) (s : Set α) : AntilipschitzWith K (s.restrict f) := fun x y => hf x y theorem codRestrict (hf : AntilipschitzWith K f) {s : Set β} (hs : ∀ x, f x ∈ s) : AntilipschitzWith K (s.codRestrict f hs) := fun x y => hf x y theorem to_rightInvOn' {s : Set α} (hf : AntilipschitzWith K (s.restrict f)) {g : β → α} {t : Set β} (g_maps : MapsTo g t s) (g_inv : RightInvOn g f t) : LipschitzWith K (t.restrict g) := fun x y => by simpa only [restrict_apply, g_inv x.mem, g_inv y.mem, Subtype.edist_mk_mk] using hf ⟨g x, g_maps x.mem⟩ ⟨g y, g_maps y.mem⟩ theorem to_rightInvOn (hf : AntilipschitzWith K f) {g : β → α} {t : Set β} (h : RightInvOn g f t) : LipschitzWith K (t.restrict g) := (hf.restrict univ).to_rightInvOn' (mapsTo_univ g t) h theorem to_rightInverse (hf : AntilipschitzWith K f) {g : β → α} (hg : Function.RightInverse g f) : LipschitzWith K g := by intro x y have := hf (g x) (g y) rwa [hg x, hg y] at this theorem comap_uniformity_le (hf : AntilipschitzWith K f) : (𝓤 β).comap (Prod.map f f) ≤ 𝓤 α := by refine ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).2 fun ε h₀ => ?_ refine ⟨(↑K)⁻¹ * ε, ENNReal.mul_pos (ENNReal.inv_ne_zero.2 ENNReal.coe_ne_top) h₀.ne', ?_⟩ refine fun x hx => (hf x.1 x.2).trans_lt ?_ rw [mul_comm, ← div_eq_mul_inv] at hx rw [mul_comm] exact ENNReal.mul_lt_of_lt_div hx theorem isUniformInducing (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) : IsUniformInducing f := ⟨le_antisymm hf.comap_uniformity_le hfc.le_comap⟩ lemma isUniformEmbedding {α β : Type*} [EMetricSpace α] [PseudoEMetricSpace β] {K : ℝ≥0} {f : α → β} (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) : IsUniformEmbedding f := ⟨hf.isUniformInducing hfc, hf.injective⟩ theorem isComplete_range [CompleteSpace α] (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) : IsComplete (range f) := (hf.isUniformInducing hfc).isComplete_range theorem isClosed_range {α β : Type*} [PseudoEMetricSpace α] [EMetricSpace β] [CompleteSpace α] {f : α → β} {K : ℝ≥0} (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) : IsClosed (range f) := (hf.isComplete_range hfc).isClosed theorem isClosedEmbedding {α : Type*} {β : Type*} [EMetricSpace α] [EMetricSpace β] {K : ℝ≥0} {f : α → β} [CompleteSpace α] (hf : AntilipschitzWith K f) (hfc : UniformContinuous f) : IsClosedEmbedding f := { (hf.isUniformEmbedding hfc).isEmbedding with isClosed_range := hf.isClosed_range hfc } theorem subtype_coe (s : Set α) : AntilipschitzWith 1 ((↑) : s → α) := AntilipschitzWith.id.restrict s @[nontriviality] theorem of_subsingleton [Subsingleton α] {K : ℝ≥0} : AntilipschitzWith K f := fun x y => by simp only [Subsingleton.elim x y, edist_self, zero_le] /-- If `f : α → β` is `0`-antilipschitz, then `α` is a `subsingleton`. -/ protected theorem subsingleton {α β} [EMetricSpace α] [PseudoEMetricSpace β] {f : α → β} (h : AntilipschitzWith 0 f) : Subsingleton α := ⟨fun x y => edist_le_zero.1 <| (h x y).trans_eq <| zero_mul _⟩ end AntilipschitzWith namespace AntilipschitzWith open Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] variable {K : ℝ≥0} {f : α → β} theorem isBounded_preimage (hf : AntilipschitzWith K f) {s : Set β} (hs : IsBounded s) : IsBounded (f ⁻¹' s) := isBounded_iff_ediam_ne_top.2 <| ne_top_of_le_ne_top (ENNReal.mul_ne_top ENNReal.coe_ne_top hs.ediam_ne_top) (hf.ediam_preimage_le _) theorem tendsto_cobounded (hf : AntilipschitzWith K f) : Tendsto f (cobounded α) (cobounded β) := compl_surjective.forall.2 fun _ ↦ hf.isBounded_preimage /-- The image of a proper space under an expanding onto map is proper. -/ protected theorem properSpace {α : Type*} [MetricSpace α] {K : ℝ≥0} {f : α → β} [ProperSpace α] (hK : AntilipschitzWith K f) (f_cont : Continuous f) (hf : Function.Surjective f) : ProperSpace β := by refine ⟨fun x₀ r => ?_⟩ let K := f ⁻¹' closedBall x₀ r have A : IsClosed K := isClosed_closedBall.preimage f_cont have B : IsBounded K := hK.isBounded_preimage isBounded_closedBall have : IsCompact K := isCompact_iff_isClosed_bounded.2 ⟨A, B⟩ convert this.image f_cont exact (hf.image_preimage _).symm theorem isBounded_of_image2_left (f : α → β → γ) {K₁ : ℝ≥0} (hf : ∀ b, AntilipschitzWith K₁ fun a => f a b) {s : Set α} {t : Set β} (hst : IsBounded (Set.image2 f s t)) : IsBounded s ∨ IsBounded t := by contrapose! hst obtain ⟨b, hb⟩ : t.Nonempty := nonempty_of_not_isBounded hst.2 have : ¬IsBounded (Set.image2 f s {b}) := by intro h apply hst.1 rw [Set.image2_singleton_right] at h replace h := (hf b).isBounded_preimage h exact h.subset (subset_preimage_image _ _) exact mt (IsBounded.subset · (image2_subset subset_rfl (singleton_subset_iff.mpr hb))) this theorem isBounded_of_image2_right {f : α → β → γ} {K₂ : ℝ≥0} (hf : ∀ a, AntilipschitzWith K₂ (f a)) {s : Set α} {t : Set β} (hst : IsBounded (Set.image2 f s t)) : IsBounded s ∨ IsBounded t := Or.symm <| isBounded_of_image2_left (flip f) hf <| image2_swap f s t ▸ hst end AntilipschitzWith theorem LipschitzWith.to_rightInverse [PseudoEMetricSpace α] [PseudoEMetricSpace β] {K : ℝ≥0} {f : α → β} (hf : LipschitzWith K f) {g : β → α} (hg : Function.RightInverse g f) : AntilipschitzWith K g := fun x y => by simpa only [hg _] using hf (g x) (g y)
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Gluing.lean
import Mathlib.Order.ConditionallyCompleteLattice.Group import Mathlib.Topology.MetricSpace.Isometry /-! # Metric space gluing Gluing two metric spaces along a common subset. Formally, we are given ``` Φ Z ---> X | |Ψ v Y ``` where `hΦ : Isometry Φ` and `hΨ : Isometry Ψ`. We want to complete the square by a space `GlueSpacescan hΦ hΨ` and two isometries `toGlueL hΦ hΨ` and `toGlueR hΦ hΨ` that make the square commute. We start by defining a predistance on the disjoint union `X ⊕ Y`, for which points `Φ p` and `Ψ p` are at distance 0. The (quotient) metric space associated to this predistance is the desired space. This is an instance of a more general construction, where `Φ` and `Ψ` do not have to be isometries, but the distances in the image almost coincide, up to `2ε` say. Then one can almost glue the two spaces so that the images of a point under `Φ` and `Ψ` are `ε`-close. If `ε > 0`, this yields a metric space structure on `X ⊕ Y`, without the need to take a quotient. In particular, this gives a natural metric space structure on `X ⊕ Y`, where the basepoints are at distance 1, say, and the distances between other points are obtained by going through the two basepoints. (We also register the same metric space structure on a general disjoint union `Σ i, E i`). We also define the inductive limit of metric spaces. Given ``` f 0 f 1 f 2 f 3 X 0 -----> X 1 -----> X 2 -----> X 3 -----> ... ``` where the `X n` are metric spaces and `f n` isometric embeddings, we define the inductive limit of the `X n`, also known as the increasing union of the `X n` in this context, if we identify `X n` and `X (n+1)` through `f n`. This is a metric space in which all `X n` embed isometrically and in a way compatible with `f n`. -/ noncomputable section universe u v w open Function Set Uniformity Topology namespace Metric section ApproxGluing variable {X : Type u} {Y : Type v} {Z : Type w} variable [MetricSpace X] [MetricSpace Y] {Φ : Z → X} {Ψ : Z → Y} {ε : ℝ} /-- Define a predistance on `X ⊕ Y`, for which `Φ p` and `Ψ p` are at distance `ε` -/ def glueDist (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : X ⊕ Y → X ⊕ Y → ℝ | .inl x, .inl y => dist x y | .inr x, .inr y => dist x y | .inl x, .inr y => (⨅ p, dist x (Φ p) + dist y (Ψ p)) + ε | .inr x, .inl y => (⨅ p, dist y (Φ p) + dist x (Ψ p)) + ε private theorem glueDist_self (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : ∀ x, glueDist Φ Ψ ε x x = 0 | .inl _ => dist_self _ | .inr _ => dist_self _ theorem glueDist_glued_points [Nonempty Z] (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (p : Z) : glueDist Φ Ψ ε (.inl (Φ p)) (.inr (Ψ p)) = ε := by have : ⨅ q, dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) = 0 := by have A : ∀ q, 0 ≤ dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) := fun _ => by positivity refine le_antisymm ?_ (le_ciInf A) have : 0 = dist (Φ p) (Φ p) + dist (Ψ p) (Ψ p) := by simp rw [this] exact ciInf_le ⟨0, forall_mem_range.2 A⟩ p simp only [glueDist, this, zero_add] private theorem glueDist_comm (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : ∀ x y, glueDist Φ Ψ ε x y = glueDist Φ Ψ ε y x | .inl _, .inl _ => dist_comm _ _ | .inr _, .inr _ => dist_comm _ _ | .inl _, .inr _ => rfl | .inr _, .inl _ => rfl theorem glueDist_swap (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : ∀ x y, glueDist Ψ Φ ε x.swap y.swap = glueDist Φ Ψ ε x y | .inl _, .inl _ => rfl | .inr _, .inr _ => rfl | .inl _, .inr _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, add_comm] | .inr _, .inl _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, add_comm] theorem le_glueDist_inl_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) : ε ≤ glueDist Φ Ψ ε (.inl x) (.inr y) := le_add_of_nonneg_left <| Real.iInf_nonneg fun _ => by positivity theorem le_glueDist_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) : ε ≤ glueDist Φ Ψ ε (.inr x) (.inl y) := by rw [glueDist_comm]; apply le_glueDist_inl_inr section variable [Nonempty Z] private theorem glueDist_triangle_inl_inr_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x : X) (y z : Y) : glueDist Φ Ψ ε (.inl x) (.inr z) ≤ glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inr z) := by simp only [glueDist] rw [add_right_comm, add_le_add_iff_right] refine le_ciInf_add fun p => ciInf_le_of_le ⟨0, ?_⟩ p ?_ · exact forall_mem_range.2 fun _ => by positivity · linarith [dist_triangle_left z (Ψ p) y] private theorem glueDist_triangle_inl_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) (x : X) (y : Y) (z : X) : glueDist Φ Ψ ε (.inl x) (.inl z) ≤ glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inl z) := by simp_rw [glueDist, add_add_add_comm _ ε, add_assoc] refine le_ciInf_add fun p => ?_ rw [add_left_comm, add_assoc, ← two_mul] refine le_ciInf_add fun q => ?_ rw [dist_comm z] linarith [dist_triangle4 x (Φ p) (Φ q) z, dist_triangle_left (Ψ p) (Ψ q) y, (abs_le.1 (H p q)).2] private theorem glueDist_triangle (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) : ∀ x y z, glueDist Φ Ψ ε x z ≤ glueDist Φ Ψ ε x y + glueDist Φ Ψ ε y z | .inl _, .inl _, .inl _ => dist_triangle _ _ _ | .inr _, .inr _, .inr _ => dist_triangle _ _ _ | .inr x, .inl y, .inl z => by simp only [← glueDist_swap Φ] apply glueDist_triangle_inl_inr_inr | .inr x, .inr y, .inl z => by simpa only [glueDist_comm, add_comm] using glueDist_triangle_inl_inr_inr _ _ _ z y x | .inl x, .inl y, .inr z => by simpa only [← glueDist_swap Φ, glueDist_comm, add_comm, Sum.swap_inl, Sum.swap_inr] using glueDist_triangle_inl_inr_inr Ψ Φ ε z y x | .inl _, .inr _, .inr _ => glueDist_triangle_inl_inr_inr .. | .inl x, .inr y, .inl z => glueDist_triangle_inl_inr_inl Φ Ψ ε H x y z | .inr x, .inl y, .inr z => by simp only [← glueDist_swap Φ] apply glueDist_triangle_inl_inr_inl simpa only [abs_sub_comm] end private theorem eq_of_glueDist_eq_zero (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (ε0 : 0 < ε) : ∀ p q : X ⊕ Y, glueDist Φ Ψ ε p q = 0 → p = q | .inl x, .inl y, h => by rw [eq_of_dist_eq_zero h] | .inl x, .inr y, h => by exfalso; linarith [le_glueDist_inl_inr Φ Ψ ε x y] | .inr x, .inl y, h => by exfalso; linarith [le_glueDist_inr_inl Φ Ψ ε x y] | .inr x, .inr y, h => by rw [eq_of_dist_eq_zero h] theorem Sum.mem_uniformity_iff_glueDist (hε : 0 < ε) (s : Set ((X ⊕ Y) × (X ⊕ Y))) : s ∈ 𝓤 (X ⊕ Y) ↔ ∃ δ > 0, ∀ a b, glueDist Φ Ψ ε a b < δ → (a, b) ∈ s := by simp only [Sum.uniformity, Filter.mem_sup, Filter.mem_map, mem_uniformity_dist, mem_preimage] constructor · rintro ⟨⟨δX, δX0, hX⟩, δY, δY0, hY⟩ refine ⟨min (min δX δY) ε, lt_min (lt_min δX0 δY0) hε, ?_⟩ rintro (a | a) (b | b) h <;> simp only [lt_min_iff] at h · exact hX h.1.1 · exact absurd h.2 (le_glueDist_inl_inr _ _ _ _ _).not_gt · exact absurd h.2 (le_glueDist_inr_inl _ _ _ _ _).not_gt · exact hY h.1.2 · rintro ⟨ε, ε0, H⟩ constructor <;> exact ⟨ε, ε0, fun _ _ h => H _ _ h⟩ /-- Given two maps `Φ` and `Ψ` intro metric spaces `X` and `Y` such that the distances between `Φ p` and `Φ q`, and between `Ψ p` and `Ψ q`, coincide up to `2 ε` where `ε > 0`, one can almost glue the two spaces `X` and `Y` along the images of `Φ` and `Ψ`, so that `Φ p` and `Ψ p` are at distance `ε`. -/ def glueMetricApprox [Nonempty Z] (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (ε0 : 0 < ε) (H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) : MetricSpace (X ⊕ Y) where dist := glueDist Φ Ψ ε dist_self := glueDist_self Φ Ψ ε dist_comm := glueDist_comm Φ Ψ ε dist_triangle := glueDist_triangle Φ Ψ ε H eq_of_dist_eq_zero := eq_of_glueDist_eq_zero Φ Ψ ε ε0 _ _ toUniformSpace := Sum.instUniformSpace uniformity_dist := uniformity_dist_of_mem_uniformity _ _ <| Sum.mem_uniformity_iff_glueDist ε0 end ApproxGluing section Sum /-! ### Metric on `X ⊕ Y` A particular case of the previous construction is when one uses basepoints in `X` and `Y` and one glues only along the basepoints, putting them at distance 1. We give a direct definition of the distance, without `iInf`, as it is easier to use in applications, and show that it is equal to the gluing distance defined above to take advantage of the lemmas we have already proved. -/ variable {X : Type u} {Y : Type v} {Z : Type w} variable [MetricSpace X] [MetricSpace Y] /-- Distance on a disjoint union. There are many (noncanonical) ways to put a distance compatible with each factor. If the two spaces are bounded, one can say for instance that each point in the first is at distance `diam X + diam Y + 1` of each point in the second. Instead, we choose a construction that works for unbounded spaces, but requires basepoints, chosen arbitrarily. We embed isometrically each factor, set the basepoints at distance 1, arbitrarily, and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to their respective basepoints, plus the distance 1 between the basepoints. Since there is an arbitrary choice in this construction, it is not an instance by default. -/ protected def Sum.dist : X ⊕ Y → X ⊕ Y → ℝ | .inl a, .inl a' => dist a a' | .inr b, .inr b' => dist b b' | .inl a, .inr b => dist a (Nonempty.some ⟨a⟩) + 1 + dist (Nonempty.some ⟨b⟩) b | .inr b, .inl a => dist b (Nonempty.some ⟨b⟩) + 1 + dist (Nonempty.some ⟨a⟩) a theorem Sum.dist_eq_glueDist {p q : X ⊕ Y} (x : X) (y : Y) : Sum.dist p q = glueDist (fun _ : Unit => Nonempty.some ⟨x⟩) (fun _ : Unit => Nonempty.some ⟨y⟩) 1 p q := by cases p <;> cases q <;> first |rfl|simp [Sum.dist, glueDist, dist_comm, add_comm, add_left_comm, add_assoc] private theorem Sum.dist_comm (x y : X ⊕ Y) : Sum.dist x y = Sum.dist y x := by cases x <;> cases y <;> simp [Sum.dist, _root_.dist_comm, add_comm, add_left_comm] theorem Sum.one_le_dist_inl_inr {x : X} {y : Y} : 1 ≤ Sum.dist (.inl x) (.inr y) := by grw [Sum.dist, ← le_add_of_nonneg_right dist_nonneg, ← le_add_of_nonneg_left dist_nonneg] theorem Sum.one_le_dist_inr_inl {x : X} {y : Y} : 1 ≤ Sum.dist (.inr y) (.inl x) := by rw [Sum.dist_comm]; exact Sum.one_le_dist_inl_inr private theorem Sum.mem_uniformity (s : Set ((X ⊕ Y) × (X ⊕ Y))) : s ∈ 𝓤 (X ⊕ Y) ↔ ∃ ε > 0, ∀ a b, Sum.dist a b < ε → (a, b) ∈ s := by constructor · rintro ⟨hsX, hsY⟩ rcases mem_uniformity_dist.1 hsX with ⟨εX, εX0, hX⟩ rcases mem_uniformity_dist.1 hsY with ⟨εY, εY0, hY⟩ refine ⟨min (min εX εY) 1, lt_min (lt_min εX0 εY0) zero_lt_one, ?_⟩ rintro (a | a) (b | b) h · exact hX (lt_of_lt_of_le h (le_trans (min_le_left _ _) (min_le_left _ _))) · cases not_le_of_gt (lt_of_lt_of_le h (min_le_right _ _)) Sum.one_le_dist_inl_inr · cases not_le_of_gt (lt_of_lt_of_le h (min_le_right _ _)) Sum.one_le_dist_inr_inl · exact hY (lt_of_lt_of_le h (le_trans (min_le_left _ _) (min_le_right _ _))) · rintro ⟨ε, ε0, H⟩ constructor <;> rw [Filter.mem_map, mem_uniformity_dist] <;> exact ⟨ε, ε0, fun _ _ h => H _ _ h⟩ /-- The distance on the disjoint union indeed defines a metric space. All the distance properties follow from our choice of the distance. The harder work is to show that the uniform structure defined by the distance coincides with the disjoint union uniform structure. -/ def metricSpaceSum : MetricSpace (X ⊕ Y) where dist := Sum.dist dist_self x := by cases x <;> simp only [Sum.dist, dist_self] dist_comm := Sum.dist_comm dist_triangle | .inl p, .inl q, .inl r => dist_triangle p q r | .inl p, .inr q, _ => by simp only [Sum.dist_eq_glueDist p q] exact glueDist_triangle _ _ _ (by simp) _ _ _ | _, .inl q, .inr r => by simp only [Sum.dist_eq_glueDist q r] exact glueDist_triangle _ _ _ (by simp) _ _ _ | .inr p, _, .inl r => by simp only [Sum.dist_eq_glueDist r p] exact glueDist_triangle _ _ _ (by simp) _ _ _ | .inr p, .inr q, .inr r => dist_triangle p q r eq_of_dist_eq_zero {p q} h := by rcases p with p | p <;> rcases q with q | q · rw [eq_of_dist_eq_zero h] · exact eq_of_glueDist_eq_zero _ _ _ one_pos _ _ ((Sum.dist_eq_glueDist p q).symm.trans h) · exact eq_of_glueDist_eq_zero _ _ _ one_pos _ _ ((Sum.dist_eq_glueDist q p).symm.trans h) · rw [eq_of_dist_eq_zero h] toUniformSpace := Sum.instUniformSpace uniformity_dist := uniformity_dist_of_mem_uniformity _ _ Sum.mem_uniformity attribute [local instance] metricSpaceSum theorem Sum.dist_eq {x y : X ⊕ Y} : dist x y = Sum.dist x y := rfl /-- The left injection of a space in a disjoint union is an isometry -/ theorem isometry_inl : Isometry (Sum.inl : X → X ⊕ Y) := Isometry.of_dist_eq fun _ _ => rfl /-- The right injection of a space in a disjoint union is an isometry -/ theorem isometry_inr : Isometry (Sum.inr : Y → X ⊕ Y) := Isometry.of_dist_eq fun _ _ => rfl end Sum namespace Sigma /- Copy of the previous paragraph, but for arbitrary disjoint unions instead of the disjoint union of two spaces. I.e., work with sigma types instead of sum types. -/ variable {ι : Type*} {E : ι → Type*} [∀ i, MetricSpace (E i)] open Classical in /-- Distance on a disjoint union. There are many (noncanonical) ways to put a distance compatible with each factor. We choose a construction that works for unbounded spaces, but requires basepoints, chosen arbitrarily. We embed isometrically each factor, set the basepoints at distance 1, arbitrarily, and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to their respective basepoints, plus the distance 1 between the basepoints. Since there is an arbitrary choice in this construction, it is not an instance by default. -/ protected def dist : (Σ i, E i) → (Σ i, E i) → ℝ | ⟨i, x⟩, ⟨j, y⟩ => if h : i = j then haveI : E j = E i := by rw [h] Dist.dist x (cast this y) else Dist.dist x (Nonempty.some ⟨x⟩) + 1 + Dist.dist (Nonempty.some ⟨y⟩) y /-- A `Dist` instance on the disjoint union `Σ i, E i`. We embed isometrically each factor, set the basepoints at distance 1, arbitrarily, and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to their respective basepoints, plus the distance 1 between the basepoints. Since there is an arbitrary choice in this construction, it is not an instance by default. -/ def instDist : Dist (Σ i, E i) := ⟨Sigma.dist⟩ attribute [local instance] Sigma.instDist @[simp] theorem dist_same (i : ι) (x y : E i) : dist (Sigma.mk i x) ⟨i, y⟩ = dist x y := by simp [Dist.dist, Sigma.dist] @[simp] theorem dist_ne {i j : ι} (h : i ≠ j) (x : E i) (y : E j) : dist (⟨i, x⟩ : Σ k, E k) ⟨j, y⟩ = dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨y⟩) y := dif_neg h theorem one_le_dist_of_ne {i j : ι} (h : i ≠ j) (x : E i) (y : E j) : 1 ≤ dist (⟨i, x⟩ : Σ k, E k) ⟨j, y⟩ := by rw [Sigma.dist_ne h x y] linarith [@dist_nonneg _ _ x (Nonempty.some ⟨x⟩), @dist_nonneg _ _ (Nonempty.some ⟨y⟩) y] theorem fst_eq_of_dist_lt_one (x y : Σ i, E i) (h : dist x y < 1) : x.1 = y.1 := by cases x; cases y contrapose! h apply one_le_dist_of_ne h protected theorem dist_triangle (x y z : Σ i, E i) : dist x z ≤ dist x y + dist y z := by rcases x with ⟨i, x⟩; rcases y with ⟨j, y⟩; rcases z with ⟨k, z⟩ rcases eq_or_ne i k with (rfl | hik) · rcases eq_or_ne i j with (rfl | hij) · simpa using dist_triangle x y z · simp only [Sigma.dist_same, Sigma.dist_ne hij, Sigma.dist_ne hij.symm] calc dist x z ≤ dist x (Nonempty.some ⟨x⟩) + 0 + 0 + (0 + 0 + dist (Nonempty.some ⟨z⟩) z) := by simpa only [zero_add, add_zero] using dist_triangle _ _ _ _ ≤ _ := by apply_rules [add_le_add, le_rfl, dist_nonneg, zero_le_one] · rcases eq_or_ne i j with (rfl | hij) · simp only [Sigma.dist_ne hik, Sigma.dist_same] calc dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨z⟩) z ≤ dist x y + dist y (Nonempty.some ⟨y⟩) + 1 + dist (Nonempty.some ⟨z⟩) z := by apply_rules [add_le_add, le_rfl, dist_triangle] _ = _ := by abel · rcases eq_or_ne j k with (rfl | hjk) · simp only [Sigma.dist_ne hij, Sigma.dist_same] calc dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨z⟩) z ≤ dist x (Nonempty.some ⟨x⟩) + 1 + (dist (Nonempty.some ⟨z⟩) y + dist y z) := by apply_rules [add_le_add, le_rfl, dist_triangle] _ = _ := by abel · simp only [hik, hij, hjk, Sigma.dist_ne, Ne, not_false_iff] calc dist x (Nonempty.some ⟨x⟩) + 1 + dist (Nonempty.some ⟨z⟩) z = dist x (Nonempty.some ⟨x⟩) + 1 + 0 + (0 + 0 + dist (Nonempty.some ⟨z⟩) z) := by simp only [add_zero, zero_add] _ ≤ _ := by apply_rules [add_le_add, zero_le_one, dist_nonneg, le_rfl] protected theorem isOpen_iff (s : Set (Σ i, E i)) : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s := by constructor · rintro hs ⟨i, x⟩ hx obtain ⟨ε, εpos, hε⟩ : ∃ ε > 0, ball x ε ⊆ Sigma.mk i ⁻¹' s := Metric.isOpen_iff.1 (isOpen_sigma_iff.1 hs i) x hx refine ⟨min ε 1, lt_min εpos zero_lt_one, ?_⟩ rintro ⟨j, y⟩ hy rcases eq_or_ne i j with (rfl | hij) · simp only [Sigma.dist_same, lt_min_iff] at hy exact hε (mem_ball'.2 hy.1) · apply (lt_irrefl (1 : ℝ) _).elim calc 1 ≤ Sigma.dist ⟨i, x⟩ ⟨j, y⟩ := Sigma.one_le_dist_of_ne hij _ _ _ < 1 := hy.trans_le (min_le_right _ _) · refine fun H => isOpen_sigma_iff.2 fun i => Metric.isOpen_iff.2 fun x hx => ?_ obtain ⟨ε, εpos, hε⟩ : ∃ ε > 0, ∀ y, dist (⟨i, x⟩ : Σ j, E j) y < ε → y ∈ s := H ⟨i, x⟩ hx refine ⟨ε, εpos, fun y hy => ?_⟩ apply hε ⟨i, y⟩ rw [Sigma.dist_same] exact mem_ball'.1 hy /-- A metric space structure on the disjoint union `Σ i, E i`. We embed isometrically each factor, set the basepoints at distance 1, arbitrarily, and say that the distance from `a` to `b` is the sum of the distances of `a` and `b` to their respective basepoints, plus the distance 1 between the basepoints. Since there is an arbitrary choice in this construction, it is not an instance by default. -/ protected def metricSpace : MetricSpace (Σ i, E i) := by refine MetricSpace.ofDistTopology Sigma.dist ?_ ?_ Sigma.dist_triangle Sigma.isOpen_iff ?_ · rintro ⟨i, x⟩ simp [Sigma.dist] · rintro ⟨i, x⟩ ⟨j, y⟩ rcases eq_or_ne i j with (rfl | h) · simp [Sigma.dist, dist_comm] · simp only [Sigma.dist, dist_comm, h, h.symm, not_false_iff, dif_neg] abel · rintro ⟨i, x⟩ ⟨j, y⟩ rcases eq_or_ne i j with (rfl | hij) · simp [Sigma.dist] · intro h apply (lt_irrefl (1 : ℝ) _).elim calc 1 ≤ Sigma.dist (⟨i, x⟩ : Σ k, E k) ⟨j, y⟩ := Sigma.one_le_dist_of_ne hij _ _ _ < 1 := by rw [h]; exact zero_lt_one attribute [local instance] Sigma.metricSpace open Topology open Filter /-- The injection of a space in a disjoint union is an isometry -/ theorem isometry_mk (i : ι) : Isometry (Sigma.mk i : E i → Σ k, E k) := Isometry.of_dist_eq fun x y => by simp /-- A disjoint union of complete metric spaces is complete. -/ protected theorem completeSpace [∀ i, CompleteSpace (E i)] : CompleteSpace (Σ i, E i) := by set s : ι → Set (Σ i, E i) := fun i => Sigma.fst ⁻¹' {i} set U := { p : (Σ k, E k) × Σ k, E k | dist p.1 p.2 < 1 } have hc : ∀ i, IsComplete (s i) := fun i => by simp only [s, ← range_sigmaMk] exact (isometry_mk i).isUniformInducing.isComplete_range have hd : ∀ (i j), ∀ x ∈ s i, ∀ y ∈ s j, (x, y) ∈ U → i = j := fun i j x hx y hy hxy => (Eq.symm hx).trans ((fst_eq_of_dist_lt_one _ _ hxy).trans hy) refine completeSpace_of_isComplete_univ ?_ convert isComplete_iUnion_separated hc (dist_mem_uniformity zero_lt_one) hd simp only [s, ← preimage_iUnion, iUnion_of_singleton, preimage_univ] end Sigma section Gluing -- Exact gluing of two metric spaces along isometric subsets. variable {X : Type u} {Y : Type v} {Z : Type w} variable [Nonempty Z] [MetricSpace Z] [MetricSpace X] [MetricSpace Y] {Φ : Z → X} {Ψ : Z → Y} {ε : ℝ} /-- Given two isometric embeddings `Φ : Z → X` and `Ψ : Z → Y`, we define a pseudo metric space structure on `X ⊕ Y` by declaring that `Φ x` and `Ψ x` are at distance `0`. -/ def gluePremetric (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : PseudoMetricSpace (X ⊕ Y) where dist := glueDist Φ Ψ 0 dist_self := glueDist_self Φ Ψ 0 dist_comm := glueDist_comm Φ Ψ 0 dist_triangle := glueDist_triangle Φ Ψ 0 fun p q => by rw [hΦ.dist_eq, hΨ.dist_eq]; simp /-- Given two isometric embeddings `Φ : Z → X` and `Ψ : Z → Y`, we define a space `GlueSpace hΦ hΨ` by identifying in `X ⊕ Y` the points `Φ x` and `Ψ x`. -/ def GlueSpace (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : Type _ := @SeparationQuotient _ (gluePremetric hΦ hΨ).toUniformSpace.toTopologicalSpace instance (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : MetricSpace (GlueSpace hΦ hΨ) := inferInstanceAs <| MetricSpace <| @SeparationQuotient _ (gluePremetric hΦ hΨ).toUniformSpace.toTopologicalSpace /-- The canonical map from `X` to the space obtained by gluing isometric subsets in `X` and `Y`. -/ def toGlueL (hΦ : Isometry Φ) (hΨ : Isometry Ψ) (x : X) : GlueSpace hΦ hΨ := Quotient.mk'' (.inl x) /-- The canonical map from `Y` to the space obtained by gluing isometric subsets in `X` and `Y`. -/ def toGlueR (hΦ : Isometry Φ) (hΨ : Isometry Ψ) (y : Y) : GlueSpace hΦ hΨ := Quotient.mk'' (.inr y) instance inhabitedLeft (hΦ : Isometry Φ) (hΨ : Isometry Ψ) [Inhabited X] : Inhabited (GlueSpace hΦ hΨ) := ⟨toGlueL _ _ default⟩ instance inhabitedRight (hΦ : Isometry Φ) (hΨ : Isometry Ψ) [Inhabited Y] : Inhabited (GlueSpace hΦ hΨ) := ⟨toGlueR _ _ default⟩ theorem toGlue_commute (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : toGlueL hΦ hΨ ∘ Φ = toGlueR hΦ hΨ ∘ Ψ := by let i : PseudoMetricSpace (X ⊕ Y) := gluePremetric hΦ hΨ let _ := i.toUniformSpace.toTopologicalSpace funext simp only [comp, toGlueL, toGlueR] refine SeparationQuotient.mk_eq_mk.2 (Metric.inseparable_iff.2 ?_) exact glueDist_glued_points Φ Ψ 0 _ theorem toGlueL_isometry (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : Isometry (toGlueL hΦ hΨ) := Isometry.of_dist_eq fun _ _ => rfl theorem toGlueR_isometry (hΦ : Isometry Φ) (hΨ : Isometry Ψ) : Isometry (toGlueR hΦ hΨ) := Isometry.of_dist_eq fun _ _ => rfl end Gluing --section section InductiveLimit /-! ### Inductive limit of metric spaces In this section, we define the inductive limit of ``` f 0 f 1 f 2 f 3 X 0 -----> X 1 -----> X 2 -----> X 3 -----> ... ``` where the `X n` are metric spaces and f n isometric embeddings. We do it by defining a premetric space structure on `Σ n, X n`, where the predistance `dist x y` is obtained by pushing `x` and `y` in a common `X k` using composition by the `f n`, and taking the distance there. This does not depend on the choice of `k` as the `f n` are isometries. The metric space associated to this premetric space is the desired inductive limit. -/ open Nat variable {X : ℕ → Type u} [∀ n, MetricSpace (X n)] {f : ∀ n, X n → X (n + 1)} /-- Predistance on the disjoint union `Σ n, X n`. -/ def inductiveLimitDist (f : ∀ n, X n → X (n + 1)) (x y : Σ n, X n) : ℝ := dist (leRecOn (le_max_left x.1 y.1) (f _) x.2 : X (max x.1 y.1)) (leRecOn (le_max_right x.1 y.1) (f _) y.2 : X (max x.1 y.1)) /-- The predistance on the disjoint union `Σ n, X n` can be computed in any `X k` for large enough `k`. -/ theorem inductiveLimitDist_eq_dist (I : ∀ n, Isometry (f n)) (x y : Σ n, X n) : ∀ m (hx : x.1 ≤ m) (hy : y.1 ≤ m), inductiveLimitDist f x y = dist (leRecOn hx (f _) x.2 : X m) (leRecOn hy (f _) y.2 : X m) | 0, hx, hy => by obtain ⟨i, x⟩ := x; obtain ⟨j, y⟩ := y obtain rfl : i = 0 := nonpos_iff_eq_zero.1 hx obtain rfl : j = 0 := nonpos_iff_eq_zero.1 hy rfl | (m + 1), hx, hy => by by_cases h : max x.1 y.1 = (m + 1) · generalize m + 1 = m' at * subst m' rfl · have : max x.1 y.1 ≤ succ m := by simp [hx, hy] have : max x.1 y.1 ≤ m := by simpa [h] using of_le_succ this have xm : x.1 ≤ m := le_trans (le_max_left _ _) this have ym : y.1 ≤ m := le_trans (le_max_right _ _) this rw [leRecOn_succ xm, leRecOn_succ ym, (I m).dist_eq] exact inductiveLimitDist_eq_dist I x y m xm ym /-- Premetric space structure on `Σ n, X n`. -/ def inductivePremetric (I : ∀ n, Isometry (f n)) : PseudoMetricSpace (Σ n, X n) where dist := inductiveLimitDist f dist_self x := by simp [inductiveLimitDist] dist_comm x y := by let m := max x.1 y.1 have hx : x.1 ≤ m := le_max_left _ _ have hy : y.1 ≤ m := le_max_right _ _ rw [inductiveLimitDist_eq_dist I x y m hx hy, inductiveLimitDist_eq_dist I y x m hy hx, dist_comm] dist_triangle x y z := by let m := max (max x.1 y.1) z.1 have hx : x.1 ≤ m := le_trans (le_max_left _ _) (le_max_left _ _) have hy : y.1 ≤ m := le_trans (le_max_right _ _) (le_max_left _ _) have hz : z.1 ≤ m := le_max_right _ _ calc inductiveLimitDist f x z = dist (leRecOn hx (f _) x.2 : X m) (leRecOn hz (f _) z.2 : X m) := inductiveLimitDist_eq_dist I x z m hx hz _ ≤ dist (leRecOn hx (f _) x.2 : X m) (leRecOn hy (f _) y.2 : X m) + dist (leRecOn hy (f _) y.2 : X m) (leRecOn hz (f _) z.2 : X m) := (dist_triangle _ _ _) _ = inductiveLimitDist f x y + inductiveLimitDist f y z := by rw [inductiveLimitDist_eq_dist I x y m hx hy, inductiveLimitDist_eq_dist I y z m hy hz] attribute [local instance] inductivePremetric /-- The type giving the inductive limit in a metric space context. -/ def InductiveLimit (I : ∀ n, Isometry (f n)) : Type _ := @SeparationQuotient _ (inductivePremetric I).toUniformSpace.toTopologicalSpace instance {I : ∀ (n : ℕ), Isometry (f n)} : MetricSpace (InductiveLimit (f := f) I) := inferInstanceAs <| MetricSpace <| @SeparationQuotient _ (inductivePremetric I).toUniformSpace.toTopologicalSpace /-- Mapping each `X n` to the inductive limit. -/ def toInductiveLimit (I : ∀ n, Isometry (f n)) (n : ℕ) (x : X n) : Metric.InductiveLimit I := Quotient.mk'' (Sigma.mk n x) instance (I : ∀ n, Isometry (f n)) [Inhabited (X 0)] : Inhabited (InductiveLimit I) := ⟨toInductiveLimit _ 0 default⟩ /-- The map `toInductiveLimit n` mapping `X n` to the inductive limit is an isometry. -/ theorem toInductiveLimit_isometry (I : ∀ n, Isometry (f n)) (n : ℕ) : Isometry (toInductiveLimit I n) := Isometry.of_dist_eq fun x y => by change inductiveLimitDist f ⟨n, x⟩ ⟨n, y⟩ = dist x y rw [inductiveLimitDist_eq_dist I ⟨n, x⟩ ⟨n, y⟩ n (le_refl n) (le_refl n), leRecOn_self, leRecOn_self] /-- The maps `toInductiveLimit n` are compatible with the maps `f n`. -/ theorem toInductiveLimit_commute (I : ∀ n, Isometry (f n)) (n : ℕ) : toInductiveLimit I n.succ ∘ f n = toInductiveLimit I n := by let h := inductivePremetric I let _ := h.toUniformSpace.toTopologicalSpace funext x simp only [comp, toInductiveLimit] refine SeparationQuotient.mk_eq_mk.2 (Metric.inseparable_iff.2 ?_) change inductiveLimitDist f ⟨n.succ, f n x⟩ ⟨n, x⟩ = 0 rw [inductiveLimitDist_eq_dist I ⟨n.succ, f n x⟩ ⟨n, x⟩ n.succ, leRecOn_self, leRecOn_succ, leRecOn_self, dist_self] · rfl · rfl · exact le_succ _ theorem dense_iUnion_range_toInductiveLimit {X : ℕ → Type u} [(n : ℕ) → MetricSpace (X n)] {f : (n : ℕ) → X n → X (n + 1)} (I : ∀ (n : ℕ), Isometry (f n)) : Dense (⋃ i, range (toInductiveLimit I i)) := by refine dense_univ.mono ?_ rintro ⟨n, x⟩ _ refine mem_iUnion.2 ⟨n, mem_range.2 ⟨x, rfl⟩⟩ theorem separableSpaceInductiveLimit_of_separableSpace {X : ℕ → Type u} [(n : ℕ) → MetricSpace (X n)] [hs : (n : ℕ) → TopologicalSpace.SeparableSpace (X n)] {f : (n : ℕ) → X n → X (n + 1)} (I : ∀ (n : ℕ), Isometry (f n)) : TopologicalSpace.SeparableSpace (Metric.InductiveLimit I) := by choose hsX hcX hdX using (fun n ↦ TopologicalSpace.exists_countable_dense (X n)) let s := ⋃ (i : ℕ), (toInductiveLimit I i '' (hsX i)) refine ⟨s, countable_iUnion (fun n => (hcX n).image _), ?_⟩ refine .of_closure <| (dense_iUnion_range_toInductiveLimit I).mono <| iUnion_subset fun i ↦ ?_ calc range (toInductiveLimit I i) ⊆ closure (toInductiveLimit I i '' (hsX i)) := (toInductiveLimit_isometry I i |>.continuous).range_subset_closure_image_dense (hdX i) _ ⊆ closure s := closure_mono <| subset_iUnion (fun j ↦ toInductiveLimit I j '' hsX j) i end InductiveLimit --section end Metric --namespace
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Defs.lean
import Mathlib.Topology.MetricSpace.Pseudo.Defs /-! # Metric spaces This file defines metric spaces and shows some of their basic properties. Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and topological spaces. This includes open and closed sets, compactness, completeness, continuity and uniform continuity. TODO (anyone): Add "Main results" section. ## Implementation notes A lot of elementary properties don't require `eq_of_dist_eq_zero`, hence are stated and proven for `PseudoMetricSpace`s in `PseudoMetric.lean`. ## Tags metric, pseudo_metric, dist -/ assert_not_exists Finset.sum open Set Filter Bornology open scoped NNReal Uniformity universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} variable [PseudoMetricSpace α] /-- A metric space is a type endowed with a `ℝ`-valued distance `dist` satisfying `dist x y = 0 ↔ x = y`, commutativity `dist x y = dist y x`, and the triangle inequality `dist x z ≤ dist x y + dist y z`. See pseudometric spaces (`PseudoMetricSpace`) for the similar class with the `dist x y = 0 ↔ x = y` assumption weakened to `dist x x = 0`. Any metric space is a T1 topological space and a uniform space (see `TopologicalSpace`, `T1Space`, `UniformSpace`), where the topology and uniformity come from the metric. We make the uniformity/topology part of the data instead of deriving it from the metric. This e.g. ensures that we do not get a diamond when doing `[MetricSpace α] [MetricSpace β] : TopologicalSpace (α × β)`: The product metric and product topology agree, but not definitionally so. See Note [forgetful inheritance]. -/ class MetricSpace (α : Type u) : Type u extends PseudoMetricSpace α where eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y /-- Two metric space structures with the same distance coincide. -/ @[ext] theorem MetricSpace.ext {α : Type*} {m m' : MetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by cases m; cases m'; congr; ext1; assumption /-- Construct a metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def MetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) (eq_of_dist_eq_zero : ∀ x y : α, dist x y = 0 → x = y) : MetricSpace α := { PseudoMetricSpace.ofDistTopology dist dist_self dist_comm dist_triangle H with eq_of_dist_eq_zero := eq_of_dist_eq_zero _ _ } variable {γ : Type w} [MetricSpace γ] theorem eq_of_dist_eq_zero {x y : γ} : dist x y = 0 → x = y := MetricSpace.eq_of_dist_eq_zero @[simp] theorem dist_eq_zero {x y : γ} : dist x y = 0 ↔ x = y := Iff.intro eq_of_dist_eq_zero fun this => this ▸ dist_self _ @[simp] theorem zero_eq_dist {x y : γ} : 0 = dist x y ↔ x = y := by rw [eq_comm, dist_eq_zero] theorem dist_ne_zero {x y : γ} : dist x y ≠ 0 ↔ x ≠ y := by simpa only [not_iff_not] using dist_eq_zero @[simp] theorem dist_le_zero {x y : γ} : dist x y ≤ 0 ↔ x = y := by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y @[simp] theorem dist_pos {x y : γ} : 0 < dist x y ↔ x ≠ y := by simpa only [not_le] using not_congr dist_le_zero theorem eq_of_forall_dist_le {x y : γ} (h : ∀ ε > 0, dist x y ≤ ε) : x = y := eq_of_dist_eq_zero (eq_of_le_of_forall_lt_imp_le_of_dense dist_nonneg h) /-- Deduce the equality of points from the vanishing of the nonnegative distance -/ theorem eq_of_nndist_eq_zero {x y : γ} : nndist x y = 0 → x = y := by simp only [NNReal.eq_iff, ← dist_nndist, imp_self, NNReal.coe_zero, dist_eq_zero] /-- Characterize the equality of points as the vanishing of the nonnegative distance -/ @[simp] theorem nndist_eq_zero {x y : γ} : nndist x y = 0 ↔ x = y := by simp only [NNReal.eq_iff, ← dist_nndist, NNReal.coe_zero, dist_eq_zero] @[simp] theorem zero_eq_nndist {x y : γ} : 0 = nndist x y ↔ x = y := by simp only [NNReal.eq_iff, ← dist_nndist, NNReal.coe_zero, zero_eq_dist] namespace Metric variable {x : γ} {s : Set γ} @[simp] theorem closedBall_zero : closedBall x 0 = {x} := Set.ext fun _ => dist_le_zero @[simp] theorem sphere_zero : sphere x 0 = {x} := Set.ext fun _ => dist_eq_zero theorem subsingleton_closedBall (x : γ) {r : ℝ} (hr : r ≤ 0) : (closedBall x r).Subsingleton := by rcases hr.lt_or_eq with (hr | rfl) · rw [closedBall_eq_empty.2 hr] exact subsingleton_empty · rw [closedBall_zero] exact subsingleton_singleton theorem subsingleton_sphere (x : γ) {r : ℝ} (hr : r ≤ 0) : (sphere x r).Subsingleton := (subsingleton_closedBall x hr).anti sphere_subset_closedBall end Metric /-- Build a new metric space from an old one where the bundled uniform structure is provably (but typically non-definitionaly) equal to some given uniform structure. See Note [forgetful inheritance]. See Note [reducible non-instances]. -/ abbrev MetricSpace.replaceUniformity {γ} [U : UniformSpace γ] (m : MetricSpace γ) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : MetricSpace γ where toPseudoMetricSpace := PseudoMetricSpace.replaceUniformity m.toPseudoMetricSpace H eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _ theorem MetricSpace.replaceUniformity_eq {γ} [U : UniformSpace γ] (m : MetricSpace γ) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : m.replaceUniformity H = m := by ext; rfl /-- Build a new metric space from an old one where the bundled topological structure is provably (but typically non-definitionaly) equal to some given topological structure. See Note [forgetful inheritance]. See Note [reducible non-instances]. -/ abbrev MetricSpace.replaceTopology {γ} [U : TopologicalSpace γ] (m : MetricSpace γ) (H : U = m.toPseudoMetricSpace.toUniformSpace.toTopologicalSpace) : MetricSpace γ := @MetricSpace.replaceUniformity γ (m.toUniformSpace.replaceTopology H) m rfl theorem MetricSpace.replaceTopology_eq {γ} [U : TopologicalSpace γ] (m : MetricSpace γ) (H : U = m.toPseudoMetricSpace.toUniformSpace.toTopologicalSpace) : m.replaceTopology H = m := by ext; rfl /-- Build a new metric space from an old one where the bundled bornology structure is provably (but typically non-definitionaly) equal to some given bornology structure. See Note [forgetful inheritance]. See Note [reducible non-instances]. -/ abbrev MetricSpace.replaceBornology {α} [B : Bornology α] (m : MetricSpace α) (H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) : MetricSpace α := { PseudoMetricSpace.replaceBornology _ H, m with toBornology := B } theorem MetricSpace.replaceBornology_eq {α} [m : MetricSpace α] [B : Bornology α] (H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) : MetricSpace.replaceBornology _ H = m := by ext rfl instance : MetricSpace Empty where dist _ _ := 0 dist_self _ := rfl dist_comm _ _ := rfl edist _ _ := 0 eq_of_dist_eq_zero _ := Subsingleton.elim _ _ dist_triangle _ _ _ := show (0 : ℝ) ≤ 0 + 0 by rw [add_zero] toUniformSpace := inferInstance uniformity_dist := Subsingleton.elim _ _ instance : MetricSpace PUnit.{u + 1} where dist _ _ := 0 dist_self _ := rfl dist_comm _ _ := rfl edist _ _ := 0 eq_of_dist_eq_zero _ := Subsingleton.elim _ _ dist_triangle _ _ _ := show (0 : ℝ) ≤ 0 + 0 by rw [add_zero] toUniformSpace := inferInstance uniformity_dist := by simp +contextual [principal_univ, eq_top_of_neBot (𝓤 PUnit)] /-! ### `Additive`, `Multiplicative` The distance on those type synonyms is inherited without change. -/ open Additive Multiplicative section variable [Dist X] instance : Dist (Additive X) := ‹Dist X› instance : Dist (Multiplicative X) := ‹Dist X› @[simp] theorem dist_ofMul (a b : X) : dist (ofMul a) (ofMul b) = dist a b := rfl @[simp] theorem dist_ofAdd (a b : X) : dist (ofAdd a) (ofAdd b) = dist a b := rfl @[simp] theorem dist_toMul (a b : Additive X) : dist a.toMul b.toMul = dist a b := rfl @[simp] theorem dist_toAdd (a b : Multiplicative X) : dist a.toAdd b.toAdd = dist a b := rfl end instance [MetricSpace X] : MetricSpace (Additive X) := ‹MetricSpace X› instance [MetricSpace X] : MetricSpace (Multiplicative X) := ‹MetricSpace X› /-! ### Order dual The distance on this type synonym is inherited without change. -/ open OrderDual section variable [Dist X] instance : Dist Xᵒᵈ := ‹Dist X› @[simp] theorem dist_toDual (a b : X) : dist (toDual a) (toDual b) = dist a b := rfl @[simp] theorem dist_ofDual (a b : Xᵒᵈ) : dist (ofDual a) (ofDual b) = dist a b := rfl end instance [MetricSpace X] : MetricSpace Xᵒᵈ := ‹MetricSpace X›
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/IsometricSMul.lean
import Mathlib.Algebra.GroupWithZero.Pointwise.Set.Basic import Mathlib.Algebra.Ring.Pointwise.Set import Mathlib.Topology.Algebra.ConstMulAction import Mathlib.Topology.MetricSpace.Isometry import Mathlib.Topology.MetricSpace.Lipschitz /-! # Group actions by isometries In this file we define two typeclasses: - `IsIsometricSMul M X` says that `M` multiplicatively acts on a (pseudo extended) metric space `X` by isometries; - `IsIsometricVAdd` is an additive version of `IsIsometricSMul`. We also prove basic facts about isometric actions and define bundled isometries `IsometryEquiv.constSMul`, `IsometryEquiv.mulLeft`, `IsometryEquiv.mulRight`, `IsometryEquiv.divLeft`, `IsometryEquiv.divRight`, and `IsometryEquiv.inv`, as well as their additive versions. If `G` is a group, then `IsIsometricSMul G G` means that `G` has a left-invariant metric while `IsIsometricSMul Gᵐᵒᵖ G` means that `G` has a right-invariant metric. For a commutative group, these two notions are equivalent. A group with a right-invariant metric can be also represented as a `NormedGroup`. -/ open Set open ENNReal Pointwise universe u v w variable (M : Type u) (G : Type v) (X : Type w) /-- An additive action is isometric if each map `x ↦ c +ᵥ x` is an isometry. -/ class IsIsometricVAdd (X : Type w) [PseudoEMetricSpace X] [VAdd M X] : Prop where isometry_vadd (X) : ∀ c : M, Isometry ((c +ᵥ ·) : X → X) /-- A multiplicative action is isometric if each map `x ↦ c • x` is an isometry. -/ @[to_additive] class IsIsometricSMul (X : Type w) [PseudoEMetricSpace X] [SMul M X] : Prop where isometry_smul (X) : ∀ c : M, Isometry ((c • ·) : X → X) export IsIsometricSMul (isometry_smul) export IsIsometricVAdd (isometry_vadd) @[to_additive] instance (priority := 100) IsIsometricSMul.to_continuousConstSMul [PseudoEMetricSpace X] [SMul M X] [IsIsometricSMul M X] : ContinuousConstSMul M X := ⟨fun c => (isometry_smul X c).continuous⟩ @[to_additive] instance (priority := 100) IsIsometricSMul.opposite_of_comm [PseudoEMetricSpace X] [SMul M X] [SMul Mᵐᵒᵖ X] [IsCentralScalar M X] [IsIsometricSMul M X] : IsIsometricSMul Mᵐᵒᵖ X := ⟨fun c x y => by simpa only [← op_smul_eq_smul] using isometry_smul X c.unop x y⟩ variable {M G X} section EMetric variable [PseudoEMetricSpace X] [Group G] [MulAction G X] [IsIsometricSMul G X] @[to_additive (attr := simp)] theorem edist_smul_left [SMul M X] [IsIsometricSMul M X] (c : M) (x y : X) : edist (c • x) (c • y) = edist x y := isometry_smul X c x y @[to_additive (attr := simp)] theorem ediam_smul [SMul M X] [IsIsometricSMul M X] (c : M) (s : Set X) : EMetric.diam (c • s) = EMetric.diam s := (isometry_smul _ _).ediam_image s @[to_additive] theorem isometry_mul_left [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul M M] (a : M) : Isometry (a * ·) := isometry_smul M a @[to_additive (attr := simp)] theorem edist_mul_left [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul M M] (a b c : M) : edist (a * b) (a * c) = edist b c := isometry_mul_left a b c @[to_additive] theorem isometry_mul_right [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a : M) : Isometry fun x => x * a := isometry_smul M (MulOpposite.op a) @[to_additive (attr := simp)] theorem edist_mul_right [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : edist (a * c) (b * c) = edist a b := isometry_mul_right c a b @[to_additive (attr := simp)] theorem edist_div_right [DivInvMonoid M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : edist (a / c) (b / c) = edist a b := by simp only [div_eq_mul_inv, edist_mul_right] @[to_additive (attr := simp)] theorem edist_inv_inv [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) : edist a⁻¹ b⁻¹ = edist a b := by rw [← edist_mul_left a, ← edist_mul_right _ _ b, mul_inv_cancel, one_mul, inv_mul_cancel_right, edist_comm] @[to_additive] theorem isometry_inv [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] : Isometry (Inv.inv : G → G) := edist_inv_inv @[to_additive] theorem edist_inv [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (x y : G) : edist x⁻¹ y = edist x y⁻¹ := by rw [← edist_inv_inv, inv_inv] @[to_additive (attr := simp)] theorem edist_div_left [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b c : G) : edist (a / b) (a / c) = edist b c := by rw [div_eq_mul_inv, div_eq_mul_inv, edist_mul_left, edist_inv_inv] namespace IsometryEquiv /-- If a group `G` acts on `X` by isometries, then `IsometryEquiv.constSMul` is the isometry of `X` given by multiplication of a constant element of the group. -/ @[to_additive (attr := simps! toEquiv apply) /-- If an additive group `G` acts on `X` by isometries, then `IsometryEquiv.constVAdd` is the isometry of `X` given by addition of a constant element of the group. -/] def constSMul (c : G) : X ≃ᵢ X where toEquiv := MulAction.toPerm c isometry_toFun := isometry_smul X c @[to_additive (attr := simp)] theorem constSMul_symm (c : G) : (constSMul c : X ≃ᵢ X).symm = constSMul c⁻¹ := ext fun _ => rfl variable [PseudoEMetricSpace G] /-- Multiplication `y ↦ x * y` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) /-- Addition `y ↦ x + y` as an `IsometryEquiv`. -/] def mulLeft [IsIsometricSMul G G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.mulLeft c isometry_toFun := edist_mul_left c @[to_additive (attr := simp)] theorem mulLeft_symm [IsIsometricSMul G G] (x : G) : (mulLeft x).symm = IsometryEquiv.mulLeft x⁻¹ := constSMul_symm x /-- Multiplication `y ↦ y * x` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) /-- Addition `y ↦ y + x` as an `IsometryEquiv`. -/] def mulRight [IsIsometricSMul Gᵐᵒᵖ G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.mulRight c isometry_toFun a b := edist_mul_right a b c @[to_additive (attr := simp)] theorem mulRight_symm [IsIsometricSMul Gᵐᵒᵖ G] (x : G) : (mulRight x).symm = mulRight x⁻¹ := ext fun _ => rfl /-- Division `y ↦ y / x` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) /-- Subtraction `y ↦ y - x` as an `IsometryEquiv`. -/] def divRight [IsIsometricSMul Gᵐᵒᵖ G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.divRight c isometry_toFun a b := edist_div_right a b c @[to_additive (attr := simp)] theorem divRight_symm [IsIsometricSMul Gᵐᵒᵖ G] (c : G) : (divRight c).symm = mulRight c := ext fun _ => rfl variable [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] /-- Division `y ↦ x / y` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply symm_apply toEquiv) /-- Subtraction `y ↦ x - y` as an `IsometryEquiv`. -/] def divLeft (c : G) : G ≃ᵢ G where toEquiv := Equiv.divLeft c isometry_toFun := edist_div_left c variable (G) /-- Inversion `x ↦ x⁻¹` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) /-- Negation `x ↦ -x` as an `IsometryEquiv`. -/] def inv : G ≃ᵢ G where toEquiv := Equiv.inv G isometry_toFun := edist_inv_inv @[to_additive (attr := simp)] theorem inv_symm : (inv G).symm = inv G := rfl end IsometryEquiv namespace EMetric @[to_additive (attr := simp)] theorem smul_ball (c : G) (x : X) (r : ℝ≥0∞) : c • ball x r = ball (c • x) r := (IsometryEquiv.constSMul c).image_emetric_ball _ _ @[to_additive (attr := simp)] theorem preimage_smul_ball (c : G) (x : X) (r : ℝ≥0∞) : (c • ·) ⁻¹' ball x r = ball (c⁻¹ • x) r := by rw [preimage_smul, smul_ball] @[to_additive (attr := simp)] theorem smul_closedBall (c : G) (x : X) (r : ℝ≥0∞) : c • closedBall x r = closedBall (c • x) r := (IsometryEquiv.constSMul c).image_emetric_closedBall _ _ @[to_additive (attr := simp)] theorem preimage_smul_closedBall (c : G) (x : X) (r : ℝ≥0∞) : (c • ·) ⁻¹' closedBall x r = closedBall (c⁻¹ • x) r := by rw [preimage_smul, smul_closedBall] variable [PseudoEMetricSpace G] @[to_additive (attr := simp)] theorem preimage_mul_left_ball [IsIsometricSMul G G] (a b : G) (r : ℝ≥0∞) : (a * ·) ⁻¹' ball b r = ball (a⁻¹ * b) r := preimage_smul_ball a b r @[to_additive (attr := simp)] theorem preimage_mul_right_ball [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ≥0∞) : (fun x => x * a) ⁻¹' ball b r = ball (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_ball (MulOpposite.op a) b r @[to_additive (attr := simp)] theorem preimage_mul_left_closedBall [IsIsometricSMul G G] (a b : G) (r : ℝ≥0∞) : (a * ·) ⁻¹' closedBall b r = closedBall (a⁻¹ * b) r := preimage_smul_closedBall a b r @[to_additive (attr := simp)] theorem preimage_mul_right_closedBall [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ≥0∞) : (fun x => x * a) ⁻¹' closedBall b r = closedBall (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_closedBall (MulOpposite.op a) b r end EMetric end EMetric @[to_additive (attr := simp)] theorem dist_smul [PseudoMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) (x y : X) : dist (c • x) (c • y) = dist x y := (isometry_smul X c).dist_eq x y @[to_additive (attr := simp)] theorem nndist_smul [PseudoMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) (x y : X) : nndist (c • x) (c • y) = nndist x y := (isometry_smul X c).nndist_eq x y @[to_additive (attr := simp)] theorem diam_smul [PseudoMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) (s : Set X) : Metric.diam (c • s) = Metric.diam s := (isometry_smul _ _).diam_image s @[to_additive (attr := simp)] theorem dist_mul_left [PseudoMetricSpace M] [Mul M] [IsIsometricSMul M M] (a b c : M) : dist (a * b) (a * c) = dist b c := dist_smul a b c @[to_additive (attr := simp)] theorem nndist_mul_left [PseudoMetricSpace M] [Mul M] [IsIsometricSMul M M] (a b c : M) : nndist (a * b) (a * c) = nndist b c := nndist_smul a b c @[to_additive (attr := simp)] theorem dist_mul_right [Mul M] [PseudoMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : dist (a * c) (b * c) = dist a b := dist_smul (MulOpposite.op c) a b @[to_additive (attr := simp)] theorem nndist_mul_right [PseudoMetricSpace M] [Mul M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : nndist (a * c) (b * c) = nndist a b := nndist_smul (MulOpposite.op c) a b @[to_additive (attr := simp)] theorem dist_div_right [DivInvMonoid M] [PseudoMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : dist (a / c) (b / c) = dist a b := by simp only [div_eq_mul_inv, dist_mul_right] @[to_additive (attr := simp)] theorem nndist_div_right [DivInvMonoid M] [PseudoMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : nndist (a / c) (b / c) = nndist a b := by simp only [div_eq_mul_inv, nndist_mul_right] @[to_additive (attr := simp)] theorem dist_inv_inv [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) : dist a⁻¹ b⁻¹ = dist a b := (IsometryEquiv.inv G).dist_eq a b @[to_additive (attr := simp)] theorem nndist_inv_inv [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) : nndist a⁻¹ b⁻¹ = nndist a b := (IsometryEquiv.inv G).nndist_eq a b @[to_additive (attr := simp)] theorem dist_div_left [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b c : G) : dist (a / b) (a / c) = dist b c := by simp [div_eq_mul_inv] @[to_additive (attr := simp)] theorem nndist_div_left [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b c : G) : nndist (a / b) (a / c) = nndist b c := by simp [div_eq_mul_inv] /-- If `G` acts isometrically on `X`, then the image of a bounded set in `X` under scalar multiplication by `c : G` is bounded. See also `Bornology.IsBounded.smul₀` for a similar lemma about normed spaces. -/ @[to_additive /-- Given an additive isometric action of `G` on `X`, the image of a bounded set in `X` under translation by `c : G` is bounded. -/] theorem Bornology.IsBounded.smul [PseudoMetricSpace X] [SMul G X] [IsIsometricSMul G X] {s : Set X} (hs : IsBounded s) (c : G) : IsBounded (c • s) := (isometry_smul X c).lipschitz.isBounded_image hs namespace Metric variable [PseudoMetricSpace X] [Group G] [MulAction G X] [IsIsometricSMul G X] @[to_additive (attr := simp)] theorem smul_ball (c : G) (x : X) (r : ℝ) : c • ball x r = ball (c • x) r := (IsometryEquiv.constSMul c).image_ball _ _ @[to_additive (attr := simp)] theorem preimage_smul_ball (c : G) (x : X) (r : ℝ) : (c • ·) ⁻¹' ball x r = ball (c⁻¹ • x) r := by rw [preimage_smul, smul_ball] @[to_additive (attr := simp)] theorem smul_closedBall (c : G) (x : X) (r : ℝ) : c • closedBall x r = closedBall (c • x) r := (IsometryEquiv.constSMul c).image_closedBall _ _ @[to_additive (attr := simp)] theorem preimage_smul_closedBall (c : G) (x : X) (r : ℝ) : (c • ·) ⁻¹' closedBall x r = closedBall (c⁻¹ • x) r := by rw [preimage_smul, smul_closedBall] @[to_additive (attr := simp)] theorem smul_sphere (c : G) (x : X) (r : ℝ) : c • sphere x r = sphere (c • x) r := (IsometryEquiv.constSMul c).image_sphere _ _ @[to_additive (attr := simp)] theorem preimage_smul_sphere (c : G) (x : X) (r : ℝ) : (c • ·) ⁻¹' sphere x r = sphere (c⁻¹ • x) r := by rw [preimage_smul, smul_sphere] variable [PseudoMetricSpace G] @[to_additive (attr := simp)] theorem preimage_mul_left_ball [IsIsometricSMul G G] (a b : G) (r : ℝ) : (a * ·) ⁻¹' ball b r = ball (a⁻¹ * b) r := preimage_smul_ball a b r @[to_additive (attr := simp)] theorem preimage_mul_right_ball [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ) : (fun x => x * a) ⁻¹' ball b r = ball (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_ball (MulOpposite.op a) b r @[to_additive (attr := simp)] theorem preimage_mul_left_closedBall [IsIsometricSMul G G] (a b : G) (r : ℝ) : (a * ·) ⁻¹' closedBall b r = closedBall (a⁻¹ * b) r := preimage_smul_closedBall a b r @[to_additive (attr := simp)] theorem preimage_mul_right_closedBall [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ) : (fun x => x * a) ⁻¹' closedBall b r = closedBall (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_closedBall (MulOpposite.op a) b r end Metric section Instances variable {Y : Type*} [PseudoEMetricSpace X] [PseudoEMetricSpace Y] [SMul M X] [IsIsometricSMul M X] @[to_additive] instance Prod.instIsIsometricSMul [SMul M Y] [IsIsometricSMul M Y] : IsIsometricSMul M (X × Y) := ⟨fun c => (isometry_smul X c).prodMap (isometry_smul Y c)⟩ @[to_additive] instance Prod.isIsometricSMul' {N} [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul M M] [Mul N] [PseudoEMetricSpace N] [IsIsometricSMul N N] : IsIsometricSMul (M × N) (M × N) := ⟨fun c => (isometry_smul M c.1).prodMap (isometry_smul N c.2)⟩ @[to_additive] instance Prod.isIsometricSMul'' {N} [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] [Mul N] [PseudoEMetricSpace N] [IsIsometricSMul Nᵐᵒᵖ N] : IsIsometricSMul (M × N)ᵐᵒᵖ (M × N) := ⟨fun c => (isometry_mul_right c.unop.1).prodMap (isometry_mul_right c.unop.2)⟩ @[to_additive] instance Units.isIsometricSMul [Monoid M] : IsIsometricSMul Mˣ X := ⟨fun c => isometry_smul X (c : M)⟩ @[to_additive] instance : IsIsometricSMul M Xᵐᵒᵖ := ⟨fun c x y => by simpa only using edist_smul_left c x.unop y.unop⟩ @[to_additive] instance ULift.isIsometricSMul : IsIsometricSMul (ULift M) X := ⟨fun c => by simpa only using isometry_smul X c.down⟩ @[to_additive] instance ULift.isIsometricSMul' : IsIsometricSMul M (ULift X) := ⟨fun c x y => by simpa only using edist_smul_left c x.1 y.1⟩ @[to_additive] instance {ι} {X : ι → Type*} [Fintype ι] [∀ i, SMul M (X i)] [∀ i, PseudoEMetricSpace (X i)] [∀ i, IsIsometricSMul M (X i)] : IsIsometricSMul M (∀ i, X i) := ⟨fun c => .piMap (fun _ => (c • ·)) fun i => isometry_smul (X i) c⟩ @[to_additive] instance Pi.isIsometricSMul' {ι} {M X : ι → Type*} [Fintype ι] [∀ i, SMul (M i) (X i)] [∀ i, PseudoEMetricSpace (X i)] [∀ i, IsIsometricSMul (M i) (X i)] : IsIsometricSMul (∀ i, M i) (∀ i, X i) := ⟨fun c => .piMap (fun i => (c i • ·)) fun _ => isometry_smul _ _⟩ @[to_additive] instance Pi.isIsometricSMul'' {ι} {M : ι → Type*} [Fintype ι] [∀ i, Mul (M i)] [∀ i, PseudoEMetricSpace (M i)] [∀ i, IsIsometricSMul (M i)ᵐᵒᵖ (M i)] : IsIsometricSMul (∀ i, M i)ᵐᵒᵖ (∀ i, M i) := ⟨fun c => .piMap (fun i (x : M i) => x * c.unop i) fun _ => isometry_mul_right _⟩ instance Additive.isIsIsometricVAdd : IsIsometricVAdd (Additive M) X := ⟨fun c => isometry_smul X c.toMul⟩ instance Additive.isIsIsometricVAdd' [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul M M] : IsIsometricVAdd (Additive M) (Additive M) := ⟨fun c x y => edist_smul_left c.toMul x.toMul y.toMul⟩ instance Additive.isIsIsometricVAdd'' [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] : IsIsometricVAdd (Additive M)ᵃᵒᵖ (Additive M) := ⟨fun c x y => edist_smul_left (MulOpposite.op c.unop.toMul) x.toMul y.toMul⟩ instance Multiplicative.isIsometricSMul {M X} [VAdd M X] [PseudoEMetricSpace X] [IsIsometricVAdd M X] : IsIsometricSMul (Multiplicative M) X := ⟨fun c => isometry_vadd X c.toAdd⟩ instance Multiplicative.isIsometricSMul' [Add M] [PseudoEMetricSpace M] [IsIsometricVAdd M M] : IsIsometricSMul (Multiplicative M) (Multiplicative M) := ⟨fun c x y => edist_vadd_left c.toAdd x.toAdd y.toAdd⟩ instance Multiplicative.isIsIsometricVAdd'' [Add M] [PseudoEMetricSpace M] [IsIsometricVAdd Mᵃᵒᵖ M] : IsIsometricSMul (Multiplicative M)ᵐᵒᵖ (Multiplicative M) := ⟨fun c x y => edist_vadd_left (AddOpposite.op c.unop.toAdd) x.toAdd y.toAdd⟩ end Instances
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Polish.lean
import Mathlib.Topology.MetricSpace.PiNat import Mathlib.Topology.Metrizable.CompletelyMetrizable import Mathlib.Topology.Sets.Opens /-! # Polish spaces A topological space is Polish if its topology is second-countable and there exists a compatible complete metric. This is the class of spaces that is well-behaved with respect to measure theory. In this file, we establish the basic properties of Polish spaces. ## Main definitions and results * `PolishSpace α` is a mixin typeclass on a topological space, requiring that the topology is second-countable and compatible with a complete metric. To endow the space with such a metric, use in a proof `letI := upgradeIsCompletelyMetrizable α`. * `IsClosed.polishSpace`: a closed subset of a Polish space is Polish. * `IsOpen.polishSpace`: an open subset of a Polish space is Polish. * `exists_nat_nat_continuous_surjective`: any nonempty Polish space is the continuous image of the fundamental Polish space `ℕ → ℕ`. A fundamental property of Polish spaces is that one can put finer topologies, still Polish, with additional properties: * `exists_polishSpace_forall_le`: on a topological space, consider countably many topologies `t n`, all Polish and finer than the original topology. Then there exists another Polish topology which is finer than all the `t n`. * `IsClopenable s` is a property of a subset `s` of a topological space, requiring that there exists a finer topology, which is Polish, for which `s` becomes open and closed. We show that this property is satisfied for open sets, closed sets, for complements, and for countable unions. Once Borel-measurable sets are defined in later files, it will follow that any Borel-measurable set is clopenable. Once the Lusin-Souslin theorem is proved using analytic sets, we will even show that a set is clopenable if and only if it is Borel-measurable, see `isClopenable_iff_measurableSet`. -/ noncomputable section open Filter Function Metric TopologicalSpace Set Topology open scoped Uniformity variable {α : Type*} {β : Type*} /-! ### Basic properties of Polish spaces -/ /-- A Polish space is a topological space with second countable topology, that can be endowed with a metric for which it is complete. To endow a Polish space with a complete metric space structure, do `letI := upgradeIsCompletelyMetrizable α`. -/ class PolishSpace (α : Type*) [h : TopologicalSpace α] : Prop extends SecondCountableTopology α, IsCompletelyMetrizableSpace α instance [TopologicalSpace α] [SeparableSpace α] [IsCompletelyMetrizableSpace α] : PolishSpace α := by letI := upgradeIsCompletelyMetrizable α haveI := UniformSpace.secondCountable_of_separable α constructor namespace PolishSpace /-- Any nonempty Polish space is the continuous image of the fundamental space `ℕ → ℕ`. -/ theorem exists_nat_nat_continuous_surjective (α : Type*) [TopologicalSpace α] [PolishSpace α] [Nonempty α] : ∃ f : (ℕ → ℕ) → α, Continuous f ∧ Surjective f := letI := upgradeIsCompletelyMetrizable α exists_nat_nat_continuous_surjective_of_completeSpace α /-- Given a closed embedding into a Polish space, the source space is also Polish. -/ theorem _root_.Topology.IsClosedEmbedding.polishSpace [TopologicalSpace α] [TopologicalSpace β] [PolishSpace β] {f : α → β} (hf : IsClosedEmbedding f) : PolishSpace α := by letI := upgradeIsCompletelyMetrizable β letI : MetricSpace α := hf.isEmbedding.comapMetricSpace f haveI : SecondCountableTopology α := hf.isEmbedding.secondCountableTopology have : CompleteSpace α := by rw [completeSpace_iff_isComplete_range hf.isEmbedding.to_isometry.isUniformInducing] exact hf.isClosed_range.isComplete infer_instance /-- Pulling back a Polish topology under an equiv gives again a Polish topology. -/ theorem _root_.Equiv.polishSpace_induced [t : TopologicalSpace β] [PolishSpace β] (f : α ≃ β) : @PolishSpace α (t.induced f) := letI : TopologicalSpace α := t.induced f (f.toHomeomorphOfIsInducing ⟨rfl⟩).isClosedEmbedding.polishSpace /-- A closed subset of a Polish space is also Polish. -/ theorem _root_.IsClosed.polishSpace [TopologicalSpace α] [PolishSpace α] {s : Set α} (hs : IsClosed s) : PolishSpace s := hs.isClosedEmbedding_subtypeVal.polishSpace protected theorem _root_.CompletePseudometrizable.iInf {ι : Type*} [Countable ι] {t : ι → TopologicalSpace α} (ht₀ : ∃ t₀, @T2Space α t₀ ∧ ∀ i, t i ≤ t₀) (ht : ∀ i, ∃ u : UniformSpace α, CompleteSpace α ∧ 𝓤[u].IsCountablyGenerated ∧ u.toTopologicalSpace = t i) : ∃ u : UniformSpace α, CompleteSpace α ∧ 𝓤[u].IsCountablyGenerated ∧ u.toTopologicalSpace = ⨅ i, t i := by choose u hcomp hcount hut using ht obtain rfl : t = fun i ↦ (u i).toTopologicalSpace := (funext hut).symm refine ⟨⨅ i, u i, .iInf hcomp ht₀, ?_, UniformSpace.toTopologicalSpace_iInf⟩ rw [iInf_uniformity] infer_instance protected theorem iInf {ι : Type*} [Countable ι] {t : ι → TopologicalSpace α} (ht₀ : ∃ i₀, ∀ i, t i ≤ t i₀) (ht : ∀ i, @PolishSpace α (t i)) : @PolishSpace α (⨅ i, t i) := by rcases ht₀ with ⟨i₀, hi₀⟩ rcases CompletePseudometrizable.iInf ⟨t i₀, letI := t i₀; haveI := ht i₀; inferInstance, hi₀⟩ fun i ↦ letI := t i; haveI := ht i; letI := upgradeIsCompletelyMetrizable α ⟨inferInstance, inferInstance, inferInstance, rfl⟩ with ⟨u, hcomp, hcount, htop⟩ rw [← htop] have : @SecondCountableTopology α u.toTopologicalSpace := htop.symm ▸ secondCountableTopology_iInf fun i ↦ letI := t i; (ht i).toSecondCountableTopology have : @T1Space α u.toTopologicalSpace := htop.symm ▸ t1Space_antitone (iInf_le _ i₀) (by letI := t i₀; haveI := ht i₀; infer_instance) infer_instance /-- Given a Polish space, and countably many finer Polish topologies, there exists another Polish topology which is finer than all of them. -/ theorem exists_polishSpace_forall_le {ι : Type*} [Countable ι] [t : TopologicalSpace α] [p : PolishSpace α] (m : ι → TopologicalSpace α) (hm : ∀ n, m n ≤ t) (h'm : ∀ n, @PolishSpace α (m n)) : ∃ t' : TopologicalSpace α, (∀ n, t' ≤ m n) ∧ t' ≤ t ∧ @PolishSpace α t' := ⟨⨅ i : Option ι, i.elim t m, fun i ↦ iInf_le _ (some i), iInf_le _ none, .iInf ⟨none, Option.forall.2 ⟨le_rfl, hm⟩⟩ <| Option.forall.2 ⟨p, h'm⟩⟩ instance : PolishSpace ENNReal := ENNReal.orderIsoUnitIntervalBirational.toHomeomorph.isClosedEmbedding.polishSpace end PolishSpace /-! ### An open subset of a Polish space is Polish To prove this fact, one needs to construct another metric, giving rise to the same topology, for which the open subset is complete. This is not obvious, as for instance `(0,1) ⊆ ℝ` is not complete for the usual metric of `ℝ`: one should build a new metric that blows up close to the boundary. -/ namespace TopologicalSpace.Opens variable [MetricSpace α] {s : Opens α} /-- A type synonym for a subset `s` of a metric space, on which we will construct another metric for which it will be complete. -/ def CompleteCopy {α : Type*} [MetricSpace α] (s : Opens α) : Type _ := s namespace CompleteCopy /-- A distance on an open subset `s` of a metric space, designed to make it complete. It is given by `dist' x y = dist x y + |1 / dist x sᶜ - 1 / dist y sᶜ|`, where the second term blows up close to the boundary to ensure that Cauchy sequences for `dist'` remain well inside `s`. -/ instance instDist : Dist (CompleteCopy s) where dist x y := dist x.1 y.1 + abs (1 / infDist x.1 sᶜ - 1 / infDist y.1 sᶜ) theorem dist_eq (x y : CompleteCopy s) : dist x y = dist x.1 y.1 + abs (1 / infDist x.1 sᶜ - 1 / infDist y.1 sᶜ) := rfl theorem dist_val_le_dist (x y : CompleteCopy s) : dist x.1 y.1 ≤ dist x y := le_add_of_nonneg_right (abs_nonneg _) instance : TopologicalSpace (CompleteCopy s) := inferInstanceAs (TopologicalSpace s) instance [SecondCountableTopology α] : SecondCountableTopology (CompleteCopy s) := inferInstanceAs (SecondCountableTopology s) instance : T0Space (CompleteCopy s) := inferInstanceAs (T0Space s) /-- A metric space structure on a subset `s` of a metric space, designed to make it complete if `s` is open. It is given by `dist' x y = dist x y + |1 / dist x sᶜ - 1 / dist y sᶜ|`, where the second term blows up close to the boundary to ensure that Cauchy sequences for `dist'` remain well inside `s`. This definition ensures the `TopologicalSpace` structure on `TopologicalSpace.Opens.CompleteCopy s` is definitionally equal to the original one. -/ instance instMetricSpace : MetricSpace (CompleteCopy s) := by refine @MetricSpace.ofT0PseudoMetricSpace (CompleteCopy s) (.ofDistTopology dist (fun _ ↦ ?_) (fun _ _ ↦ ?_) (fun x y z ↦ ?_) fun t ↦ ?_) _ · simp only [dist_eq, dist_self, one_div, sub_self, abs_zero, add_zero] · simp only [dist_eq, dist_comm, abs_sub_comm] · calc dist x z = dist x.1 z.1 + |1 / infDist x.1 sᶜ - 1 / infDist z.1 sᶜ| := rfl _ ≤ dist x.1 y.1 + dist y.1 z.1 + (|1 / infDist x.1 sᶜ - 1 / infDist y.1 sᶜ| + |1 / infDist y.1 sᶜ - 1 / infDist z.1 sᶜ|) := add_le_add (dist_triangle _ _ _) (dist_triangle (1 / infDist _ _) _ _) _ = dist x y + dist y z := add_add_add_comm .. · refine ⟨fun h x hx ↦ ?_, fun h ↦ isOpen_iff_mem_nhds.2 fun x hx ↦ ?_⟩ · rcases (Metric.isOpen_iff (α := s)).1 h x hx with ⟨ε, ε0, hε⟩ exact ⟨ε, ε0, fun y hy ↦ hε <| (dist_comm _ _).trans_lt <| (dist_val_le_dist _ _).trans_lt hy⟩ · rcases h x hx with ⟨ε, ε0, hε⟩ simp only [dist_eq, one_div] at hε have : Tendsto (fun y : s ↦ dist x.1 y.1 + |(infDist x.1 sᶜ)⁻¹ - (infDist y.1 sᶜ)⁻¹|) (𝓝 x) (𝓝 (dist x.1 x.1 + |(infDist x.1 sᶜ)⁻¹ - (infDist x.1 sᶜ)⁻¹|)) := by refine (tendsto_const_nhds.dist continuous_subtype_val.continuousAt).add (tendsto_const_nhds.sub <| ?_).abs refine (continuousAt_inv_infDist_pt ?_).comp continuous_subtype_val.continuousAt rw [s.isOpen.isClosed_compl.closure_eq, mem_compl_iff, not_not] exact x.2 simp only [dist_self, sub_self, abs_zero, zero_add] at this exact mem_of_superset (this <| gt_mem_nhds ε0) hε instance instCompleteSpace [CompleteSpace α] : CompleteSpace (CompleteCopy s) := by refine Metric.complete_of_convergent_controlled_sequences ((1 / 2) ^ ·) (by simp) fun u hu ↦ ?_ have A : CauchySeq fun n => (u n).1 := by refine cauchySeq_of_le_tendsto_0 (fun n : ℕ => (1 / 2) ^ n) (fun n m N hNn hNm => ?_) ?_ · exact (dist_val_le_dist (u n) (u m)).trans (hu N n m hNn hNm).le · exact tendsto_pow_atTop_nhds_zero_of_lt_one (by simp) (by norm_num) obtain ⟨x, xlim⟩ : ∃ x, Tendsto (fun n => (u n).1) atTop (𝓝 x) := cauchySeq_tendsto_of_complete A by_cases xs : x ∈ s · exact ⟨⟨x, xs⟩, tendsto_subtype_rng.2 xlim⟩ obtain ⟨C, hC⟩ : ∃ C, ∀ n, 1 / infDist (u n).1 sᶜ < C := by refine ⟨(1 / 2) ^ 0 + 1 / infDist (u 0).1 sᶜ, fun n ↦ ?_⟩ rw [← sub_lt_iff_lt_add] calc _ ≤ |1 / infDist (u n).1 sᶜ - 1 / infDist (u 0).1 sᶜ| := le_abs_self _ _ = |1 / infDist (u 0).1 sᶜ - 1 / infDist (u n).1 sᶜ| := abs_sub_comm _ _ _ ≤ dist (u 0) (u n) := le_add_of_nonneg_left dist_nonneg _ < (1 / 2) ^ 0 := hu 0 0 n le_rfl n.zero_le have Cpos : 0 < C := lt_of_le_of_lt (div_nonneg zero_le_one infDist_nonneg) (hC 0) have Hmem : ∀ {y}, y ∈ s ↔ 0 < infDist y sᶜ := fun {y} ↦ by rw [← s.isOpen.isClosed_compl.notMem_iff_infDist_pos ⟨x, xs⟩]; exact not_not.symm have I : ∀ n, 1 / C ≤ infDist (u n).1 sᶜ := fun n ↦ by have : 0 < infDist (u n).1 sᶜ := Hmem.1 (u n).2 rw [div_le_iff₀' Cpos] exact (div_le_iff₀ this).1 (hC n).le have I' : 1 / C ≤ infDist x sᶜ := have : Tendsto (fun n => infDist (u n).1 sᶜ) atTop (𝓝 (infDist x sᶜ)) := ((continuous_infDist_pt (sᶜ : Set α)).tendsto x).comp xlim ge_of_tendsto' this I exact absurd (Hmem.2 <| lt_of_lt_of_le (div_pos one_pos Cpos) I') xs /-- An open subset of a Polish space is also Polish. -/ theorem _root_.IsOpen.polishSpace {α : Type*} [TopologicalSpace α] [PolishSpace α] {s : Set α} (hs : IsOpen s) : PolishSpace s := by letI := upgradeIsCompletelyMetrizable α lift s to Opens α using hs exact inferInstanceAs (PolishSpace s.CompleteCopy) end CompleteCopy end TopologicalSpace.Opens namespace PolishSpace /-! ### Clopenable sets in Polish spaces -/ /-- A set in a topological space is clopenable if there exists a finer Polish topology for which this set is open and closed. It turns out that this notion is equivalent to being Borel-measurable, but this is nontrivial (see `isClopenable_iff_measurableSet`). -/ def IsClopenable [t : TopologicalSpace α] (s : Set α) : Prop := ∃ t' : TopologicalSpace α, t' ≤ t ∧ @PolishSpace α t' ∧ IsClosed[t'] s ∧ IsOpen[t'] s /-- Given a closed set `s` in a Polish space, one can construct a finer Polish topology for which `s` is both open and closed. -/ theorem _root_.IsClosed.isClopenable [TopologicalSpace α] [PolishSpace α] {s : Set α} (hs : IsClosed s) : IsClopenable s := by /- Both sets `s` and `sᶜ` admit a Polish topology. So does their disjoint union `s ⊕ sᶜ`. Pulling back this topology by the canonical bijection with `α` gives the desired Polish topology in which `s` is both open and closed. -/ classical haveI : PolishSpace s := hs.polishSpace let t : Set α := sᶜ haveI : PolishSpace t := hs.isOpen_compl.polishSpace let f : s ⊕ t ≃ α := Equiv.Set.sumCompl s have hle : TopologicalSpace.coinduced f instTopologicalSpaceSum ≤ ‹_› := by simp only [instTopologicalSpaceSum, coinduced_sup, coinduced_compose, sup_le_iff, ← continuous_iff_coinduced_le] exact ⟨continuous_subtype_val, continuous_subtype_val⟩ refine ⟨.coinduced f instTopologicalSpaceSum, hle, ?_, hs.mono hle, ?_⟩ · rw [← f.induced_symm] exact f.symm.polishSpace_induced · rw [isOpen_coinduced, isOpen_sum_iff] simp only [preimage_preimage, f] have inl (x : s) : (Equiv.Set.sumCompl s) (Sum.inl x) = x := Equiv.Set.sumCompl_apply_inl .. have inr (x : ↑sᶜ) : (Equiv.Set.sumCompl s) (Sum.inr x) = x := Equiv.Set.sumCompl_apply_inr .. simp_rw [t, inl, inr, Subtype.coe_preimage_self] simp only [isOpen_univ, true_and] rw [Subtype.preimage_coe_compl'] simp theorem IsClopenable.compl [TopologicalSpace α] {s : Set α} (hs : IsClopenable s) : IsClopenable sᶜ := by rcases hs with ⟨t, t_le, t_polish, h, h'⟩ exact ⟨t, t_le, t_polish, @IsOpen.isClosed_compl α t s h', @IsClosed.isOpen_compl α t s h⟩ theorem _root_.IsOpen.isClopenable [TopologicalSpace α] [PolishSpace α] {s : Set α} (hs : IsOpen s) : IsClopenable s := by simpa using hs.isClosed_compl.isClopenable.compl -- TODO: generalize for free to `[Countable ι] {s : ι → Set α}` theorem IsClopenable.iUnion [t : TopologicalSpace α] [PolishSpace α] {s : ℕ → Set α} (hs : ∀ n, IsClopenable (s n)) : IsClopenable (⋃ n, s n) := by choose m mt m_polish _ m_open using hs obtain ⟨t', t'm, -, t'_polish⟩ : ∃ t' : TopologicalSpace α, (∀ n : ℕ, t' ≤ m n) ∧ t' ≤ t ∧ @PolishSpace α t' := exists_polishSpace_forall_le m mt m_polish have A : IsOpen[t'] (⋃ n, s n) := by apply isOpen_iUnion intro n apply t'm n exact m_open n obtain ⟨t'', t''_le, t''_polish, h1, h2⟩ : ∃ t'' : TopologicalSpace α, t'' ≤ t' ∧ @PolishSpace α t'' ∧ IsClosed[t''] (⋃ n, s n) ∧ IsOpen[t''] (⋃ n, s n) := @IsOpen.isClopenable α t' t'_polish _ A exact ⟨t'', t''_le.trans ((t'm 0).trans (mt 0)), t''_polish, h1, h2⟩ end PolishSpace
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/DilationEquiv.lean
import Mathlib.Topology.MetricSpace.Dilation /-! # Dilation equivalence In this file we define `DilationEquiv X Y`, a type of bundled equivalences between `X` and Y` such that `edist (f x) (f y) = r * edist x y` for some `r : ℝ≥0`, `r ≠ 0`. We also develop basic API about these equivalences. ## TODO - Add missing lemmas (compare to other `*Equiv` structures). - [after-port] Add `DilationEquivInstance` for `IsometryEquiv`. -/ open scoped NNReal ENNReal open Function Set Filter Bornology open Dilation (ratio ratio_ne_zero ratio_pos edist_eq) section Class variable (F : Type*) (X Y : outParam Type*) [PseudoEMetricSpace X] [PseudoEMetricSpace Y] /-- Typeclass saying that `F` is a type of bundled equivalences such that all `e : F` are dilations. -/ class DilationEquivClass [EquivLike F X Y] : Prop where edist_eq' : ∀ f : F, ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : X, edist (f x) (f y) = r * edist x y instance (priority := 100) [EquivLike F X Y] [DilationEquivClass F X Y] : DilationClass F X Y := { inferInstanceAs (FunLike F X Y), ‹DilationEquivClass F X Y› with } end Class /-- Type of equivalences `X ≃ Y` such that `∀ x y, edist (f x) (f y) = r * edist x y` for some `r : ℝ≥0`, `r ≠ 0`. -/ structure DilationEquiv (X Y : Type*) [PseudoEMetricSpace X] [PseudoEMetricSpace Y] extends X ≃ Y, Dilation X Y @[inherit_doc] infixl:25 " ≃ᵈ " => DilationEquiv namespace DilationEquiv section PseudoEMetricSpace variable {X Y Z : Type*} [PseudoEMetricSpace X] [PseudoEMetricSpace Y] [PseudoEMetricSpace Z] instance : EquivLike (X ≃ᵈ Y) X Y where coe f := f.1 inv f := f.1.symm left_inv f := f.left_inv' right_inv f := f.right_inv' coe_injective' := by rintro ⟨⟩ ⟨⟩ h -; congr; exact DFunLike.ext' h instance : DilationEquivClass (X ≃ᵈ Y) X Y where edist_eq' f := f.edist_eq' @[simp] theorem coe_toEquiv (e : X ≃ᵈ Y) : ⇑e.toEquiv = e := rfl @[ext] protected theorem ext {e e' : X ≃ᵈ Y} (h : ∀ x, e x = e' x) : e = e' := DFunLike.ext _ _ h /-- Inverse `DilationEquiv`. -/ def symm (e : X ≃ᵈ Y) : Y ≃ᵈ X where toEquiv := e.1.symm edist_eq' := by refine ⟨(ratio e)⁻¹, inv_ne_zero <| ratio_ne_zero e, e.surjective.forall₂.2 fun x y ↦ ?_⟩ simp_rw [Equiv.toFun_as_coe, Equiv.symm_apply_apply, coe_toEquiv, edist_eq] rw [← mul_assoc, ← ENNReal.coe_mul, inv_mul_cancel₀ (ratio_ne_zero e), ENNReal.coe_one, one_mul] @[simp] theorem symm_symm (e : X ≃ᵈ Y) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (DilationEquiv.symm : (X ≃ᵈ Y) → Y ≃ᵈ X) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (e : X ≃ᵈ Y) (x : Y) : e (e.symm x) = x := e.right_inv x @[simp] theorem symm_apply_apply (e : X ≃ᵈ Y) (x : X) : e.symm (e x) = x := e.left_inv x /-- See Note [custom simps projection]. -/ def Simps.symm_apply (e : X ≃ᵈ Y) : Y → X := e.symm initialize_simps_projections DilationEquiv (toFun → apply, invFun → symm_apply) lemma ratio_toDilation (e : X ≃ᵈ Y) : ratio e.toDilation = ratio e := rfl /-- Identity map as a `DilationEquiv`. -/ @[simps! -fullyApplied apply] def refl (X : Type*) [PseudoEMetricSpace X] : X ≃ᵈ X where toEquiv := .refl X edist_eq' := ⟨1, one_ne_zero, fun _ _ ↦ by simp⟩ @[simp] theorem refl_symm : (refl X).symm = refl X := rfl @[simp] theorem ratio_refl : ratio (refl X) = 1 := Dilation.ratio_id /-- Composition of `DilationEquiv`s. -/ @[simps! -fullyApplied apply] def trans (e₁ : X ≃ᵈ Y) (e₂ : Y ≃ᵈ Z) : X ≃ᵈ Z where toEquiv := e₁.1.trans e₂.1 __ := e₂.toDilation.comp e₁.toDilation @[simp] theorem refl_trans (e : X ≃ᵈ Y) : (refl X).trans e = e := rfl @[simp] theorem trans_refl (e : X ≃ᵈ Y) : e.trans (refl Y) = e := rfl @[simp] theorem symm_trans_self (e : X ≃ᵈ Y) : e.symm.trans e = refl Y := DilationEquiv.ext e.apply_symm_apply @[simp] theorem self_trans_symm (e : X ≃ᵈ Y) : e.trans e.symm = refl X := DilationEquiv.ext e.symm_apply_apply protected theorem surjective (e : X ≃ᵈ Y) : Surjective e := e.1.surjective protected theorem bijective (e : X ≃ᵈ Y) : Bijective e := e.1.bijective protected theorem injective (e : X ≃ᵈ Y) : Injective e := e.1.injective @[simp] theorem ratio_trans (e : X ≃ᵈ Y) (e' : Y ≃ᵈ Z) : ratio (e.trans e') = ratio e * ratio e' := by -- If `X` is trivial, then so is `Y`, otherwise we apply `Dilation.ratio_comp'` by_cases! hX : ∀ x y : X, edist x y = 0 ∨ edist x y = ∞ · have hY : ∀ x y : Y, edist x y = 0 ∨ edist x y = ∞ := e.surjective.forall₂.2 fun x y ↦ by refine (hX x y).imp (fun h ↦ ?_) fun h ↦ ?_ <;> simp [*, Dilation.ratio_ne_zero] simp [Dilation.ratio_of_trivial, *] exact (Dilation.ratio_comp' (g := e'.toDilation) (f := e.toDilation) hX).trans (mul_comm _ _) @[simp] theorem ratio_symm (e : X ≃ᵈ Y) : ratio e.symm = (ratio e)⁻¹ := eq_inv_of_mul_eq_one_left <| by rw [← ratio_trans, symm_trans_self, ratio_refl] instance : Group (X ≃ᵈ X) where mul e e' := e'.trans e mul_assoc _ _ _ := rfl one := refl _ one_mul _ := rfl mul_one _ := rfl inv := symm inv_mul_cancel := self_trans_symm theorem mul_def (e e' : X ≃ᵈ X) : e * e' = e'.trans e := rfl theorem one_def : (1 : X ≃ᵈ X) = refl X := rfl theorem inv_def (e : X ≃ᵈ X) : e⁻¹ = e.symm := rfl @[simp] theorem coe_mul (e e' : X ≃ᵈ X) : ⇑(e * e') = e ∘ e' := rfl @[simp] theorem coe_one : ⇑(1 : X ≃ᵈ X) = id := rfl theorem coe_inv (e : X ≃ᵈ X) : ⇑(e⁻¹) = e.symm := rfl /-- `Dilation.ratio` as a monoid homomorphism. -/ noncomputable def ratioHom : (X ≃ᵈ X) →* ℝ≥0 where toFun := Dilation.ratio map_one' := ratio_refl map_mul' _ _ := (ratio_trans _ _).trans (mul_comm _ _) @[simp] theorem ratio_inv (e : X ≃ᵈ X) : ratio (e⁻¹) = (ratio e)⁻¹ := ratio_symm e @[simp] theorem ratio_pow (e : X ≃ᵈ X) (n : ℕ) : ratio (e ^ n) = ratio e ^ n := ratioHom.map_pow _ _ @[simp] theorem ratio_zpow (e : X ≃ᵈ X) (n : ℤ) : ratio (e ^ n) = ratio e ^ n := ratioHom.map_zpow _ _ /-- `DilationEquiv.toEquiv` as a monoid homomorphism. -/ @[simps] def toPerm : (X ≃ᵈ X) →* Equiv.Perm X where toFun e := e.1 map_mul' _ _ := rfl map_one' := rfl @[norm_cast] theorem coe_pow (e : X ≃ᵈ X) (n : ℕ) : ⇑(e ^ n) = e^[n] := by rw [← coe_toEquiv, ← toPerm_apply, map_pow, Equiv.Perm.coe_pow]; rfl -- TODO: Once `IsometryEquiv` follows the `*EquivClass` pattern, replace this with an instance -- of `DilationEquivClass` assuming `IsometryEquivClass`. /-- Every isometry equivalence is a dilation equivalence of ratio `1`. -/ def _root_.IsometryEquiv.toDilationEquiv (e : X ≃ᵢ Y) : X ≃ᵈ Y where edist_eq' := ⟨1, one_ne_zero, by simpa using e.isometry⟩ __ := e.toEquiv @[simp] lemma _root_.IsometryEquiv.toDilationEquiv_apply (e : X ≃ᵢ Y) (x : X) : e.toDilationEquiv x = e x := rfl @[simp] lemma _root_.IsometryEquiv.toDilationEquiv_symm (e : X ≃ᵢ Y) : e.symm.toDilationEquiv = e.toDilationEquiv.symm := rfl @[simp] lemma _root_.IsometryEquiv.coe_toDilationEquiv (e : X ≃ᵢ Y) : ⇑e.toDilationEquiv = e := rfl @[simp] lemma _root_.IsometryEquiv.coe_symm_toDilationEquiv (e : X ≃ᵢ Y) : ⇑e.toDilationEquiv.symm = e.symm := rfl @[simp] lemma _root_.IsometryEquiv.toDilationEquiv_toDilation (e : X ≃ᵢ Y) : (e.toDilationEquiv.toDilation : X →ᵈ Y) = e.isometry.toDilation := rfl @[simp] lemma _root_.IsometryEquiv.toDilationEquiv_ratio (e : X ≃ᵢ Y) : ratio e.toDilationEquiv = 1 := by rw [← ratio_toDilation, IsometryEquiv.toDilationEquiv_toDilation, Isometry.toDilation_ratio] /-- Reinterpret a `DilationEquiv` as a homeomorphism. -/ def toHomeomorph (e : X ≃ᵈ Y) : X ≃ₜ Y where continuous_toFun := Dilation.toContinuous e continuous_invFun := Dilation.toContinuous e.symm __ := e.toEquiv @[simp] lemma toHomeomorph_symm (e : X ≃ᵈ Y) : e.symm.toHomeomorph = e.toHomeomorph.symm := rfl @[simp] lemma coe_toHomeomorph (e : X ≃ᵈ Y) : ⇑e.toHomeomorph = e := rfl @[simp] lemma coe_symm_toHomeomorph (e : X ≃ᵈ Y) : ⇑e.toHomeomorph.symm = e.symm := rfl end PseudoEMetricSpace section PseudoMetricSpace variable {X Y F : Type*} [PseudoMetricSpace X] [PseudoMetricSpace Y] variable [EquivLike F X Y] [DilationEquivClass F X Y] @[simp] lemma map_cobounded (e : F) : map e (cobounded X) = cobounded Y := by rw [← Dilation.comap_cobounded e, map_comap_of_surjective (EquivLike.surjective e)] end PseudoMetricSpace end DilationEquiv
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Lipschitz.lean
import Mathlib.Order.Interval.Set.ProjIcc import Mathlib.Topology.Bornology.Hom import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Maps.Proper.Basic import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we specialize various facts about Lipschitz continuous maps to the case of (pseudo) metric spaces. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ assert_not_exists Module.Basis Ideal ContinuousMul universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} theorem lipschitzWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} : LipschitzWith K f ↔ ∀ x y, dist (f x) (f y) ≤ K * dist x y := by simp only [LipschitzWith, edist_nndist, dist_nndist] norm_cast alias ⟨LipschitzWith.dist_le_mul, LipschitzWith.of_dist_le_mul⟩ := lipschitzWith_iff_dist_le_mul theorem lipschitzOnWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {s : Set α} {f : α → β} : LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y := by simp only [LipschitzOnWith, edist_nndist, dist_nndist] norm_cast alias ⟨LipschitzOnWith.dist_le_mul, LipschitzOnWith.of_dist_le_mul⟩ := lipschitzOnWith_iff_dist_le_mul namespace LipschitzWith section Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ} protected theorem of_dist_le' {K : ℝ} (h : ∀ x y, dist (f x) (f y) ≤ K * dist x y) : LipschitzWith (Real.toNNReal K) f := of_dist_le_mul fun x y => le_trans (h x y) <| by gcongr; apply Real.le_coe_toNNReal protected theorem mk_one (h : ∀ x y, dist (f x) (f y) ≤ dist x y) : LipschitzWith 1 f := of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version doesn't assume `0≤K`. -/ protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ x y, f x ≤ f y + K * dist x y) : LipschitzWith (Real.toNNReal K) f := have I : ∀ x y, f x - f y ≤ K * dist x y := fun x y => sub_le_iff_le_add'.2 (h x y) LipschitzWith.of_dist_le' fun x y => abs_sub_le_iff.2 ⟨I x y, dist_comm y x ▸ I y x⟩ /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version assumes `0≤K`. -/ protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ x y, f x ≤ f y + K * dist x y) : LipschitzWith K f := by simpa only [Real.toNNReal_coe] using LipschitzWith.of_le_add_mul' K h protected theorem of_le_add {f : α → ℝ} (h : ∀ x y, f x ≤ f y + dist x y) : LipschitzWith 1 f := LipschitzWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul] protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzWith K f) (x y) : f x ≤ f y + K * dist x y := sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x y protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} : LipschitzWith K f ↔ ∀ x y, f x ≤ f y + K * dist x y := ⟨LipschitzWith.le_add_mul, LipschitzWith.of_le_add_mul K⟩ theorem nndist_le (hf : LipschitzWith K f) (x y : α) : nndist (f x) (f y) ≤ K * nndist x y := hf.dist_le_mul x y theorem dist_le_mul_of_le (hf : LipschitzWith K f) (hr : dist x y ≤ r) : dist (f x) (f y) ≤ K * r := (hf.dist_le_mul x y).trans <| by gcongr theorem mapsTo_closedBall (hf : LipschitzWith K f) (x : α) (r : ℝ) : MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) (K * r)) := fun _y hy => hf.dist_le_mul_of_le hy theorem dist_lt_mul_of_lt (hf : LipschitzWith K f) (hK : K ≠ 0) (hr : dist x y < r) : dist (f x) (f y) < K * r := (hf.dist_le_mul x y).trans_lt <| by gcongr theorem mapsTo_ball (hf : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ) : MapsTo f (Metric.ball x r) (Metric.ball (f x) (K * r)) := fun _y hy => hf.dist_lt_mul_of_lt hK hy /-- A Lipschitz continuous map is a locally bounded map. -/ def toLocallyBoundedMap (f : α → β) (hf : LipschitzWith K f) : LocallyBoundedMap α β := LocallyBoundedMap.ofMapBounded f fun _s hs => let ⟨C, hC⟩ := Metric.isBounded_iff.1 hs Metric.isBounded_iff.2 ⟨K * C, forall_mem_image.2 fun _x hx => forall_mem_image.2 fun _y hy => hf.dist_le_mul_of_le (hC hx hy)⟩ @[simp] theorem coe_toLocallyBoundedMap (hf : LipschitzWith K f) : ⇑(hf.toLocallyBoundedMap f) = f := rfl theorem comap_cobounded_le (hf : LipschitzWith K f) : comap f (Bornology.cobounded β) ≤ Bornology.cobounded α := (hf.toLocallyBoundedMap f).2 /-- The image of a bounded set under a Lipschitz map is bounded. -/ theorem isBounded_image (hf : LipschitzWith K f) {s : Set α} (hs : IsBounded s) : IsBounded (f '' s) := hs.image (toLocallyBoundedMap f hf) theorem diam_image_le (hf : LipschitzWith K f) (s : Set α) (hs : IsBounded s) : Metric.diam (f '' s) ≤ K * Metric.diam s := Metric.diam_le_of_forall_dist_le (mul_nonneg K.coe_nonneg Metric.diam_nonneg) <| forall_mem_image.2 fun _x hx => forall_mem_image.2 fun _y hy => hf.dist_le_mul_of_le <| Metric.dist_le_diam_of_mem hs hx hy protected theorem dist_left (y : α) : LipschitzWith 1 (dist · y) := LipschitzWith.mk_one fun _ _ => dist_dist_dist_le_left _ _ _ protected theorem dist_right (x : α) : LipschitzWith 1 (dist x) := LipschitzWith.of_le_add fun _ _ => dist_triangle_right _ _ _ protected theorem dist : LipschitzWith 2 (Function.uncurry <| @dist α _) := by rw [← one_add_one_eq_two] exact LipschitzWith.uncurry LipschitzWith.dist_left LipschitzWith.dist_right theorem dist_iterate_succ_le_geometric {f : α → α} (hf : LipschitzWith K f) (x n) : dist (f^[n] x) (f^[n+1] x) ≤ dist x (f x) * (K : ℝ) ^ n := by rw [iterate_succ, mul_comm] simpa only [NNReal.coe_pow] using (hf.iterate n).dist_le_mul x (f x) theorem _root_.lipschitzWith_max : LipschitzWith 1 fun p : ℝ × ℝ => max p.1 p.2 := LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <| (le_abs_self _).trans (abs_max_sub_max_le_max _ _ _ _) theorem _root_.lipschitzWith_min : LipschitzWith 1 fun p : ℝ × ℝ => min p.1 p.2 := LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <| (le_abs_self _).trans (abs_min_sub_min_le_max _ _ _ _) lemma _root_.Real.lipschitzWith_toNNReal : LipschitzWith 1 Real.toNNReal := by refine lipschitzWith_iff_dist_le_mul.mpr (fun x y ↦ ?_) simpa only [NNReal.coe_one, dist_prod_same_right, one_mul, Real.dist_eq] using lipschitzWith_iff_dist_le_mul.mp lipschitzWith_max (x, 0) (y, 0) end Metric section EMetric variable [PseudoEMetricSpace α] {f g : α → ℝ} {Kf Kg : ℝ≥0} protected theorem max (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => max (f x) (g x) := by simpa only [(· ∘ ·), one_mul] using lipschitzWith_max.comp (hf.prodMk hg) protected theorem min (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => min (f x) (g x) := by simpa only [(· ∘ ·), one_mul] using lipschitzWith_min.comp (hf.prodMk hg) theorem max_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max (f x) a := by simpa only [max_eq_left (zero_le Kf)] using hf.max (LipschitzWith.const a) theorem const_max (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max a (f x) := by simpa only [max_comm] using hf.max_const a theorem min_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min (f x) a := by simpa only [max_eq_left (zero_le Kf)] using hf.min (LipschitzWith.const a) theorem const_min (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min a (f x) := by simpa only [min_comm] using hf.min_const a end EMetric protected theorem projIcc {a b : ℝ} (h : a ≤ b) : LipschitzWith 1 (projIcc a b h) := ((LipschitzWith.id.const_min _).const_max _).subtype_mk _ end LipschitzWith /-- The preimage of a proper space under a Lipschitz proper map is proper. -/ lemma LipschitzWith.properSpace {X Y : Type*} [PseudoMetricSpace X] [PseudoMetricSpace Y] [ProperSpace Y] {f : X → Y} (hf : IsProperMap f) {K : ℝ≥0} (hf' : LipschitzWith K f) : ProperSpace X := ⟨fun x r ↦ (hf.isCompact_preimage (isCompact_closedBall (f x) (K * r))).of_isClosed_subset Metric.isClosed_closedBall (hf'.mapsTo_closedBall x r).subset_preimage⟩ namespace Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s : Set α} {t : Set β} end Metric namespace LipschitzOnWith section Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] variable {K : ℝ≥0} {s : Set α} {f : α → β} protected theorem of_dist_le' {K : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y) : LipschitzOnWith (Real.toNNReal K) f s := of_dist_le_mul fun x hx y hy => le_trans (h x hx y hy) <| by gcongr; apply Real.le_coe_toNNReal protected theorem mk_one (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ dist x y) : LipschitzOnWith 1 f s := of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version doesn't assume `0≤K`. -/ protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y) : LipschitzOnWith (Real.toNNReal K) f s := have I : ∀ x ∈ s, ∀ y ∈ s, f x - f y ≤ K * dist x y := fun x hx y hy => sub_le_iff_le_add'.2 (h x hx y hy) LipschitzOnWith.of_dist_le' fun x hx y hy => abs_sub_le_iff.2 ⟨I x hx y hy, dist_comm y x ▸ I y hy x hx⟩ /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version assumes `0≤K`. -/ protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y) : LipschitzOnWith K f s := by simpa only [Real.toNNReal_coe] using LipschitzOnWith.of_le_add_mul' K h protected theorem of_le_add {f : α → ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + dist x y) : LipschitzOnWith 1 f s := LipschitzOnWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul] protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzOnWith K f s) {x : α} (hx : x ∈ s) {y : α} (hy : y ∈ s) : f x ≤ f y + K * dist x y := sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x hx y hy protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} : LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y := ⟨LipschitzOnWith.le_add_mul, LipschitzOnWith.of_le_add_mul K⟩ theorem isBounded_image2 (f : α → β → γ) {K₁ K₂ : ℝ≥0} {s : Set α} {t : Set β} (hs : Bornology.IsBounded s) (ht : Bornology.IsBounded t) (hf₁ : ∀ b ∈ t, LipschitzOnWith K₁ (fun a => f a b) s) (hf₂ : ∀ a ∈ s, LipschitzOnWith K₂ (f a) t) : Bornology.IsBounded (Set.image2 f s t) := Metric.isBounded_iff_ediam_ne_top.2 <| ne_top_of_le_ne_top (ENNReal.add_ne_top.mpr ⟨ENNReal.mul_ne_top ENNReal.coe_ne_top hs.ediam_ne_top, ENNReal.mul_ne_top ENNReal.coe_ne_top ht.ediam_ne_top⟩) (ediam_image2_le _ _ _ hf₁ hf₂) end Metric end LipschitzOnWith namespace LocallyLipschitz section Real variable [PseudoEMetricSpace α] {f g : α → ℝ} /-- The minimum of locally Lipschitz functions is locally Lipschitz. -/ protected lemma min (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) : LocallyLipschitz (fun x => min (f x) (g x)) := lipschitzWith_min.locallyLipschitz.comp (hf.prodMk hg) /-- The maximum of locally Lipschitz functions is locally Lipschitz. -/ protected lemma max (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) : LocallyLipschitz (fun x => max (f x) (g x)) := lipschitzWith_max.locallyLipschitz.comp (hf.prodMk hg) theorem max_const (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => max (f x) a := hf.max (LocallyLipschitz.const a) theorem const_max (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => max a (f x) := by simpa [max_comm] using (hf.max_const a) theorem min_const (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => min (f x) a := hf.min (LocallyLipschitz.const a) theorem const_min (hf : LocallyLipschitz f) (a : ℝ) : LocallyLipschitz fun x => min a (f x) := by simpa [min_comm] using (hf.min_const a) end Real end LocallyLipschitz open Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} /-- A function `f : α → ℝ` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension to the whole space. -/ theorem LipschitzOnWith.extend_real {f : α → ℝ} {s : Set α} {K : ℝ≥0} (hf : LipschitzOnWith K f s) : ∃ g : α → ℝ, LipschitzWith K g ∧ EqOn f g s := by /- An extension is given by `g y = Inf {f x + K * dist y x | x ∈ s}`. Taking `x = y`, one has `g y ≤ f y` for `y ∈ s`, and the other inequality holds because `f` is `K`-Lipschitz, so that it cannot counterbalance the growth of `K * dist y x`. One readily checks from the formula that the extended function is also `K`-Lipschitz. -/ rcases eq_empty_or_nonempty s with (rfl | hs) · exact ⟨fun _ => 0, (LipschitzWith.const _).weaken (zero_le _), eqOn_empty _ _⟩ have : Nonempty s := by simp only [hs, nonempty_coe_sort] let g := fun y : α => iInf fun x : s => f x + K * dist y x have B : ∀ y : α, BddBelow (range fun x : s => f x + K * dist y x) := fun y => by rcases hs with ⟨z, hz⟩ refine ⟨f z - K * dist y z, ?_⟩ rintro w ⟨t, rfl⟩ dsimp rw [sub_le_iff_le_add, add_assoc, ← mul_add, add_comm (dist y t)] calc f z ≤ f t + K * dist z t := hf.le_add_mul hz t.2 _ ≤ f t + K * (dist y z + dist y t) := by gcongr; apply dist_triangle_left have E : EqOn f g s := fun x hx => by refine le_antisymm (le_ciInf fun y => hf.le_add_mul hx y.2) ?_ simpa only [add_zero, Subtype.coe_mk, mul_zero, dist_self] using ciInf_le (B x) ⟨x, hx⟩ refine ⟨g, LipschitzWith.of_le_add_mul K fun x y => ?_, E⟩ rw [← sub_le_iff_le_add] refine le_ciInf fun z => ?_ rw [sub_le_iff_le_add] calc g x ≤ f z + K * dist x z := ciInf_le (B x) _ _ ≤ f z + K * dist y z + K * dist x y := by rw [add_assoc, ← mul_add, add_comm (dist y z)] gcongr apply dist_triangle /-- A function `f : α → (ι → ℝ)` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension to the whole space. The same result for the space `ℓ^∞ (ι, ℝ)` over a possibly infinite type `ι` is implemented in `LipschitzOnWith.extend_lp_infty`. -/ theorem LipschitzOnWith.extend_pi [Fintype ι] {f : α → ι → ℝ} {s : Set α} {K : ℝ≥0} (hf : LipschitzOnWith K f s) : ∃ g : α → ι → ℝ, LipschitzWith K g ∧ EqOn f g s := by have : ∀ i, ∃ g : α → ℝ, LipschitzWith K g ∧ EqOn (fun x => f x i) g s := fun i => by have : LipschitzOnWith K (fun x : α => f x i) s := LipschitzOnWith.of_dist_le_mul fun x hx y hy => (dist_le_pi_dist _ _ i).trans (hf.dist_le_mul x hx y hy) exact this.extend_real choose g hg using this refine ⟨fun x i => g i x, LipschitzWith.of_dist_le_mul fun x y => ?_, fun x hx ↦ ?_⟩ · exact (dist_pi_le_iff (mul_nonneg K.2 dist_nonneg)).2 fun i => (hg i).1.dist_le_mul x y · ext1 i exact (hg i).2 hx
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/GromovHausdorffRealized.lean
import Mathlib.Topology.ContinuousMap.Bounded.ArzelaAscoli import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.MetricSpace.Gluing import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # The Gromov-Hausdorff distance is realized In this file, we construct of a good coupling between nonempty compact metric spaces, minimizing their Hausdorff distance. This construction is instrumental to study the Gromov-Hausdorff distance between nonempty compact metric spaces. Given two nonempty compact metric spaces `X` and `Y`, we define `OptimalGHCoupling X Y` as a compact metric space, together with two isometric embeddings `optimalGHInjl` and `optimalGHInjr` respectively of `X` and `Y` into `OptimalGHCoupling X Y`. The main property of the optimal coupling is that the Hausdorff distance between `X` and `Y` in `OptimalGHCoupling X Y` is smaller than the corresponding distance in any other coupling. We do not prove completely this fact in this file, but we show a good enough approximation of this fact in `hausdorffDist_optimal_le_HD`, that will suffice to obtain the full statement once the Gromov-Hausdorff distance is properly defined, in `hausdorffDist_optimal`. The key point in the construction is that the set of possible distances coming from isometric embeddings of `X` and `Y` in metric spaces is a set of equicontinuous functions. By Arzela-Ascoli, it is compact, and one can find such a distance which is minimal. This distance defines a premetric space structure on `X ⊕ Y`. The corresponding metric quotient is `OptimalGHCoupling X Y`. -/ noncomputable section universe u v w open Topology NNReal Set Function TopologicalSpace Filter Metric Quotient BoundedContinuousFunction open Sum (inl inr) attribute [local instance] metricSpaceSum namespace GromovHausdorff section GromovHausdorffRealized /-! This section shows that the Gromov-Hausdorff distance is realized. For this, we consider candidate distances on the disjoint union `X ⊕ Y` of two compact nonempty metric spaces, almost realizing the Gromov-Hausdorff distance, and show that they form a compact family by applying Arzela-Ascoli theorem. The existence of a minimizer follows. -/ section Definitions variable (X : Type u) (Y : Type v) [MetricSpace X] [MetricSpace Y] private abbrev ProdSpaceFun : Type _ := (X ⊕ Y) × (X ⊕ Y) → ℝ private abbrev Cb : Type _ := BoundedContinuousFunction ((X ⊕ Y) × (X ⊕ Y)) ℝ private def maxVar : ℝ≥0 := 2 * ⟨diam (univ : Set X), diam_nonneg⟩ + 1 + 2 * ⟨diam (univ : Set Y), diam_nonneg⟩ private theorem one_le_maxVar : 1 ≤ maxVar X Y := calc (1 : Real) = 2 * 0 + 1 + 2 * 0 := by simp _ ≤ 2 * diam (univ : Set X) + 1 + 2 * diam (univ : Set Y) := by gcongr <;> positivity /-- The set of functions on `X ⊕ Y` that are candidates distances to realize the minimum of the Hausdorff distances between `X` and `Y` in a coupling. -/ def candidates : Set (ProdSpaceFun X Y) := { f | (((((∀ x y : X, f (Sum.inl x, Sum.inl y) = dist x y) ∧ ∀ x y : Y, f (Sum.inr x, Sum.inr y) = dist x y) ∧ ∀ x y, f (x, y) = f (y, x)) ∧ ∀ x y z, f (x, z) ≤ f (x, y) + f (y, z)) ∧ ∀ x, f (x, x) = 0) ∧ ∀ x y, f (x, y) ≤ maxVar X Y } /-- Version of the set of candidates in bounded_continuous_functions, to apply Arzela-Ascoli. -/ private def candidatesB : Set (Cb X Y) := { f : Cb X Y | (f : _ → ℝ) ∈ candidates X Y } end Definitions section Constructions variable {X : Type u} {Y : Type v} [MetricSpace X] [MetricSpace Y] {f : ProdSpaceFun X Y} {x y z t : X ⊕ Y} attribute [local instance 10] Classical.inhabited_of_nonempty' private theorem maxVar_bound [CompactSpace X] [Nonempty X] [CompactSpace Y] [Nonempty Y] : dist x y ≤ maxVar X Y := calc dist x y ≤ diam (univ : Set (X ⊕ Y)) := dist_le_diam_of_mem isBounded_of_compactSpace (mem_univ _) (mem_univ _) _ = diam (range inl ∪ range inr : Set (X ⊕ Y)) := by rw [range_inl_union_range_inr] _ ≤ diam (range inl : Set (X ⊕ Y)) + dist (inl default) (inr default) + diam (range inr : Set (X ⊕ Y)) := (diam_union (mem_range_self _) (mem_range_self _)) _ = diam (univ : Set X) + (dist (α := X) default default + 1 + dist (α := Y) default default) + diam (univ : Set Y) := by rw [isometry_inl.diam_range, isometry_inr.diam_range] rfl _ = 1 * diam (univ : Set X) + 1 + 1 * diam (univ : Set Y) := by simp _ ≤ 2 * diam (univ : Set X) + 1 + 2 * diam (univ : Set Y) := by gcongr <;> norm_num private theorem candidates_symm (fA : f ∈ candidates X Y) : f (x, y) = f (y, x) := fA.1.1.1.2 x y private theorem candidates_triangle (fA : f ∈ candidates X Y) : f (x, z) ≤ f (x, y) + f (y, z) := fA.1.1.2 x y z private theorem candidates_refl (fA : f ∈ candidates X Y) : f (x, x) = 0 := fA.1.2 x private theorem candidates_nonneg (fA : f ∈ candidates X Y) : 0 ≤ f (x, y) := by have : 0 ≤ 2 * f (x, y) := calc 0 = f (x, x) := (candidates_refl fA).symm _ ≤ f (x, y) + f (y, x) := candidates_triangle fA _ = f (x, y) + f (x, y) := by rw [candidates_symm fA] _ = 2 * f (x, y) := by ring linarith private theorem candidates_dist_inl (fA : f ∈ candidates X Y) (x y : X) : f (inl x, inl y) = dist x y := fA.1.1.1.1.1 x y private theorem candidates_dist_inr (fA : f ∈ candidates X Y) (x y : Y) : f (inr x, inr y) = dist x y := fA.1.1.1.1.2 x y private theorem candidates_le_maxVar (fA : f ∈ candidates X Y) : f (x, y) ≤ maxVar X Y := fA.2 x y /-- candidates are bounded by `maxVar X Y` -/ private theorem candidates_dist_bound (fA : f ∈ candidates X Y) : ∀ {x y : X ⊕ Y}, f (x, y) ≤ maxVar X Y * dist x y | inl x, inl y => calc f (inl x, inl y) = dist x y := candidates_dist_inl fA x y _ = dist (α := X ⊕ Y) (inl x) (inl y) := by rw [@Sum.dist_eq X Y] rfl _ = 1 * dist (α := X ⊕ Y) (inl x) (inl y) := by ring _ ≤ maxVar X Y * dist (inl x) (inl y) := by gcongr; exact one_le_maxVar X Y | inl x, inr y => calc f (inl x, inr y) ≤ maxVar X Y := candidates_le_maxVar fA _ = maxVar X Y * 1 := by simp _ ≤ maxVar X Y * dist (inl x) (inr y) := by gcongr; apply Sum.one_le_dist_inl_inr | inr x, inl y => calc f (inr x, inl y) ≤ maxVar X Y := candidates_le_maxVar fA _ = maxVar X Y * 1 := by simp _ ≤ maxVar X Y * dist (inl x) (inr y) := by gcongr; apply Sum.one_le_dist_inl_inr | inr x, inr y => calc f (inr x, inr y) = dist x y := candidates_dist_inr fA x y _ = dist (α := X ⊕ Y) (inr x) (inr y) := by rw [@Sum.dist_eq X Y] rfl _ = 1 * dist (α := X ⊕ Y) (inr x) (inr y) := by ring _ ≤ maxVar X Y * dist (inr x) (inr y) := by gcongr; exact one_le_maxVar X Y /-- Technical lemma to prove that candidates are Lipschitz -/ private theorem candidates_lipschitz_aux (fA : f ∈ candidates X Y) : f (x, y) - f (z, t) ≤ 2 * maxVar X Y * dist (x, y) (z, t) := calc f (x, y) - f (z, t) ≤ f (x, t) + f (t, y) - f (z, t) := by gcongr; exact candidates_triangle fA _ ≤ f (x, z) + f (z, t) + f (t, y) - f (z, t) := by gcongr; exact candidates_triangle fA _ = f (x, z) + f (t, y) := by simp [sub_eq_add_neg, add_assoc] _ ≤ maxVar X Y * dist x z + maxVar X Y * dist t y := by gcongr <;> apply candidates_dist_bound fA _ ≤ maxVar X Y * max (dist x z) (dist t y) + maxVar X Y * max (dist x z) (dist t y) := by gcongr · apply le_max_left · apply le_max_right _ = 2 * maxVar X Y * max (dist x z) (dist y t) := by rw [dist_comm t y] ring _ = 2 * maxVar X Y * dist (x, y) (z, t) := rfl /-- Candidates are Lipschitz -/ private theorem candidates_lipschitz (fA : f ∈ candidates X Y) : LipschitzWith (2 * maxVar X Y) f := by apply LipschitzWith.of_dist_le_mul rintro ⟨x, y⟩ ⟨z, t⟩ rw [Real.dist_eq, abs_sub_le_iff] use candidates_lipschitz_aux fA rw [dist_comm] exact candidates_lipschitz_aux fA /-- To apply Arzela-Ascoli, we need to check that the set of candidates is closed and equicontinuous. Equicontinuity follows from the Lipschitz control, we check closedness. -/ private theorem closed_candidatesB : IsClosed (candidatesB X Y) := by have I1 : ∀ x y, IsClosed { f : Cb X Y | f (inl x, inl y) = dist x y } := fun x y => isClosed_eq continuous_eval_const continuous_const have I2 : ∀ x y, IsClosed { f : Cb X Y | f (inr x, inr y) = dist x y } := fun x y => isClosed_eq continuous_eval_const continuous_const have I3 : ∀ x y, IsClosed { f : Cb X Y | f (x, y) = f (y, x) } := fun x y => isClosed_eq continuous_eval_const continuous_eval_const have I4 : ∀ x y z, IsClosed { f : Cb X Y | f (x, z) ≤ f (x, y) + f (y, z) } := fun x y z => isClosed_le continuous_eval_const (continuous_eval_const.add continuous_eval_const) have I5 : ∀ x, IsClosed { f : Cb X Y | f (x, x) = 0 } := fun x => isClosed_eq continuous_eval_const continuous_const have I6 : ∀ x y, IsClosed { f : Cb X Y | f (x, y) ≤ maxVar X Y } := fun x y => isClosed_le continuous_eval_const continuous_const have : candidatesB X Y = (((((⋂ (x) (y), { f : Cb X Y | f (@inl X Y x, @inl X Y y) = dist x y }) ∩ ⋂ (x) (y), { f : Cb X Y | f (@inr X Y x, @inr X Y y) = dist x y }) ∩ ⋂ (x) (y), { f : Cb X Y | f (x, y) = f (y, x) }) ∩ ⋂ (x) (y) (z), { f : Cb X Y | f (x, z) ≤ f (x, y) + f (y, z) }) ∩ ⋂ x, { f : Cb X Y | f (x, x) = 0 }) ∩ ⋂ (x) (y), { f : Cb X Y | f (x, y) ≤ maxVar X Y } := by ext simp only [candidatesB, candidates, mem_inter_iff, mem_iInter, mem_setOf_eq] rw [this] repeat' first | apply IsClosed.inter _ _ | apply isClosed_iInter _ | apply I1 _ _ | apply I2 _ _ | apply I3 _ _ | apply I4 _ _ _ | apply I5 _ | apply I6 _ _ | intro x /-- We will then choose the candidate minimizing the Hausdorff distance. Except that we are not in a metric space setting, so we need to define our custom version of Hausdorff distance, called `HD`, and prove its basic properties. -/ def HD (f : Cb X Y) := max (⨆ x, ⨅ y, f (inl x, inr y)) (⨆ y, ⨅ x, f (inl x, inr y)) /- We will show that `HD` is continuous on `BoundedContinuousFunction`s, to deduce that its minimum on the compact set `candidatesB` is attained. Since it is defined in terms of infimum and supremum on `ℝ`, which is only conditionally complete, we will need all the time to check that the defining sets are bounded below or above. This is done in the next few technical lemmas. -/ theorem HD_below_aux1 {f : Cb X Y} (C : ℝ) {x : X} : BddBelow (range fun y : Y => f (inl x, inr y) + C) := let ⟨cf, hcf⟩ := f.isBounded_range.bddBelow ⟨cf + C, forall_mem_range.2 fun _ => by grw [hcf (mem_range_self _)]⟩ private theorem HD_bound_aux1 [Nonempty Y] (f : Cb X Y) (C : ℝ) : BddAbove (range fun x : X => ⨅ y, f (inl x, inr y) + C) := by obtain ⟨Cf, hCf⟩ := f.isBounded_range.bddAbove refine ⟨Cf + C, forall_mem_range.2 fun x => ?_⟩ calc ⨅ y, f (inl x, inr y) + C ≤ f (inl x, inr default) + C := ciInf_le (HD_below_aux1 C) default _ ≤ Cf + C := add_le_add ((fun x => hCf (mem_range_self x)) _) le_rfl theorem HD_below_aux2 {f : Cb X Y} (C : ℝ) {y : Y} : BddBelow (range fun x : X => f (inl x, inr y) + C) := let ⟨cf, hcf⟩ := f.isBounded_range.bddBelow ⟨cf + C, forall_mem_range.2 fun _ => by grw [hcf (mem_range_self _)]⟩ private theorem HD_bound_aux2 [Nonempty X] (f : Cb X Y) (C : ℝ) : BddAbove (range fun y : Y => ⨅ x, f (inl x, inr y) + C) := by obtain ⟨Cf, hCf⟩ := f.isBounded_range.bddAbove refine ⟨Cf + C, forall_mem_range.2 fun y => ?_⟩ calc ⨅ x, f (inl x, inr y) + C ≤ f (inl default, inr y) + C := ciInf_le (HD_below_aux2 C) default _ ≤ Cf + C := add_le_add ((fun x => hCf (mem_range_self x)) _) le_rfl section Nonempty variable [Nonempty X] [Nonempty Y] /- To check that `HD` is continuous, we check that it is Lipschitz. As `HD` is a max, we prove separately inequalities controlling the two terms (relying too heavily on copy-paste...) -/ private theorem HD_lipschitz_aux1 (f g : Cb X Y) : (⨆ x, ⨅ y, f (inl x, inr y)) ≤ (⨆ x, ⨅ y, g (inl x, inr y)) + dist f g := by obtain ⟨cg, hcg⟩ := g.isBounded_range.bddBelow have Hcg : ∀ x, cg ≤ g x := fun x => hcg (mem_range_self x) obtain ⟨cf, hcf⟩ := f.isBounded_range.bddBelow have Hcf : ∀ x, cf ≤ f x := fun x => hcf (mem_range_self x) -- prove the inequality but with `dist f g` inside, by using inequalities comparing -- iSup to iSup and iInf to iInf have Z : (⨆ x, ⨅ y, f (inl x, inr y)) ≤ ⨆ x, ⨅ y, g (inl x, inr y) + dist f g := ciSup_mono (HD_bound_aux1 _ (dist f g)) fun x => ciInf_mono ⟨cf, forall_mem_range.2 fun i => Hcf _⟩ fun y => coe_le_coe_add_dist -- move the `dist f g` out of the infimum and the supremum, arguing that continuous monotone maps -- (here the addition of `dist f g`) preserve infimum and supremum have E1 : ∀ x, (⨅ y, g (inl x, inr y)) + dist f g = ⨅ y, g (inl x, inr y) + dist f g := by intro x refine Monotone.map_ciInf_of_continuousAt (continuousAt_id.add continuousAt_const) ?_ ?_ · intro x y hx simpa · change BddBelow (range fun y : Y => g (inl x, inr y)) exact ⟨cg, forall_mem_range.2 fun i => Hcg _⟩ have E2 : (⨆ x, ⨅ y, g (inl x, inr y)) + dist f g = ⨆ x, (⨅ y, g (inl x, inr y)) + dist f g := by refine Monotone.map_ciSup_of_continuousAt (continuousAt_id.add continuousAt_const) ?_ ?_ · intro x y hx simpa · simpa using HD_bound_aux1 _ 0 -- deduce the result from the above two steps simpa [E2, E1, Function.comp] private theorem HD_lipschitz_aux2 (f g : Cb X Y) : (⨆ y, ⨅ x, f (inl x, inr y)) ≤ (⨆ y, ⨅ x, g (inl x, inr y)) + dist f g := by obtain ⟨cg, hcg⟩ := g.isBounded_range.bddBelow have Hcg : ∀ x, cg ≤ g x := fun x => hcg (mem_range_self x) obtain ⟨cf, hcf⟩ := f.isBounded_range.bddBelow have Hcf : ∀ x, cf ≤ f x := fun x => hcf (mem_range_self x) -- prove the inequality but with `dist f g` inside, by using inequalities comparing -- iSup to iSup and iInf to iInf have Z : (⨆ y, ⨅ x, f (inl x, inr y)) ≤ ⨆ y, ⨅ x, g (inl x, inr y) + dist f g := ciSup_mono (HD_bound_aux2 _ (dist f g)) fun y => ciInf_mono ⟨cf, forall_mem_range.2 fun i => Hcf _⟩ fun y => coe_le_coe_add_dist -- move the `dist f g` out of the infimum and the supremum, arguing that continuous monotone maps -- (here the addition of `dist f g`) preserve infimum and supremum have E1 : ∀ y, (⨅ x, g (inl x, inr y)) + dist f g = ⨅ x, g (inl x, inr y) + dist f g := by intro y refine Monotone.map_ciInf_of_continuousAt (continuousAt_id.add continuousAt_const) ?_ ?_ · intro x y hx simpa · change BddBelow (range fun x : X => g (inl x, inr y)) exact ⟨cg, forall_mem_range.2 fun i => Hcg _⟩ have E2 : (⨆ y, ⨅ x, g (inl x, inr y)) + dist f g = ⨆ y, (⨅ x, g (inl x, inr y)) + dist f g := by refine Monotone.map_ciSup_of_continuousAt (continuousAt_id.add continuousAt_const) ?_ ?_ · intro x y hx simpa · simpa using HD_bound_aux2 _ 0 -- deduce the result from the above two steps simpa [E2, E1] private theorem HD_lipschitz_aux3 (f g : Cb X Y) : HD f ≤ HD g + dist f g := max_le (by grw [HD_lipschitz_aux1 f g, HD, ← le_max_left]) (by grw [HD_lipschitz_aux2 f g, HD, ← le_max_right]) /-- Conclude that `HD`, being Lipschitz, is continuous -/ private theorem HD_continuous : Continuous (HD : Cb X Y → ℝ) := LipschitzWith.continuous (LipschitzWith.of_le_add HD_lipschitz_aux3) end Nonempty variable [CompactSpace X] [CompactSpace Y] /-- Compactness of candidates (in `BoundedContinuousFunction`s) follows. -/ private theorem isCompact_candidatesB : IsCompact (candidatesB X Y) := by refine arzela_ascoli₂ (Icc 0 (maxVar X Y) : Set ℝ) isCompact_Icc (candidatesB X Y) closed_candidatesB ?_ ?_ · rintro f ⟨x1, x2⟩ hf simp only [Set.mem_Icc] exact ⟨candidates_nonneg hf, candidates_le_maxVar hf⟩ · refine equicontinuous_of_continuity_modulus (fun t => 2 * maxVar X Y * t) ?_ _ ?_ · have : Tendsto (fun t : ℝ => 2 * (maxVar X Y : ℝ) * t) (𝓝 0) (𝓝 (2 * maxVar X Y * 0)) := tendsto_const_nhds.mul tendsto_id simpa using this · rintro x y ⟨f, hf⟩ exact (candidates_lipschitz hf).dist_le_mul _ _ /-- candidates give rise to elements of `BoundedContinuousFunction`s -/ def candidatesBOfCandidates (f : ProdSpaceFun X Y) (fA : f ∈ candidates X Y) : Cb X Y := BoundedContinuousFunction.mkOfCompact ⟨f, (candidates_lipschitz fA).continuous⟩ theorem candidatesBOfCandidates_mem (f : ProdSpaceFun X Y) (fA : f ∈ candidates X Y) : candidatesBOfCandidates f fA ∈ candidatesB X Y := fA variable [Nonempty X] [Nonempty Y] /-- The distance on `X ⊕ Y` is a candidate -/ private theorem dist_mem_candidates : (fun p : (X ⊕ Y) × (X ⊕ Y) => dist p.1 p.2) ∈ candidates X Y := by simp_rw [candidates, Set.mem_setOf_eq, dist_comm, dist_triangle, dist_self, maxVar_bound, forall_const, and_true] exact ⟨fun x y => rfl, fun x y => rfl⟩ /-- The distance on `X ⊕ Y` as a candidate -/ def candidatesBDist (X : Type u) (Y : Type v) [MetricSpace X] [CompactSpace X] [Nonempty X] [MetricSpace Y] [CompactSpace Y] [Nonempty Y] : Cb X Y := candidatesBOfCandidates _ dist_mem_candidates theorem candidatesBDist_mem_candidatesB : candidatesBDist X Y ∈ candidatesB X Y := candidatesBOfCandidates_mem _ _ private theorem candidatesB_nonempty : (candidatesB X Y).Nonempty := ⟨_, candidatesBDist_mem_candidatesB⟩ /-- Explicit bound on `HD (dist)`. This means that when looking for minimizers it will be sufficient to look for functions with `HD(f)` bounded by this bound. -/ theorem HD_candidatesBDist_le : HD (candidatesBDist X Y) ≤ diam (univ : Set X) + 1 + diam (univ : Set Y) := by refine max_le (ciSup_le fun x => ?_) (ciSup_le fun y => ?_) · have A : ⨅ y, candidatesBDist X Y (inl x, inr y) ≤ candidatesBDist X Y (inl x, inr default) := ciInf_le (by simpa using HD_below_aux1 0) default have B : dist (inl x) (inr default) ≤ diam (univ : Set X) + 1 + diam (univ : Set Y) := calc dist (inl x) (inr (default : Y)) = dist x (default : X) + 1 + dist default default := rfl _ ≤ diam (univ : Set X) + 1 + diam (univ : Set Y) := by gcongr <;> exact dist_le_diam_of_mem isBounded_of_compactSpace (mem_univ _) (mem_univ _) exact le_trans A B · have A : ⨅ x, candidatesBDist X Y (inl x, inr y) ≤ candidatesBDist X Y (inl default, inr y) := ciInf_le (by simpa using HD_below_aux2 0) default have B : dist (inl default) (inr y) ≤ diam (univ : Set X) + 1 + diam (univ : Set Y) := calc dist (inl (default : X)) (inr y) = dist default default + 1 + dist default y := rfl _ ≤ diam (univ : Set X) + 1 + diam (univ : Set Y) := by gcongr <;> exact dist_le_diam_of_mem isBounded_of_compactSpace (mem_univ _) (mem_univ _) exact le_trans A B end Constructions section Consequences variable (X : Type u) (Y : Type v) [MetricSpace X] [CompactSpace X] [Nonempty X] [MetricSpace Y] [CompactSpace Y] [Nonempty Y] /- Now that we have proved that the set of candidates is compact, and that `HD` is continuous, we can finally select a candidate minimizing `HD`. This will be the candidate realizing the optimal coupling. -/ private theorem exists_minimizer : ∃ f ∈ candidatesB X Y, ∀ g ∈ candidatesB X Y, HD f ≤ HD g := isCompact_candidatesB.exists_isMinOn candidatesB_nonempty HD_continuous.continuousOn private def optimalGHDist : Cb X Y := Classical.choose (exists_minimizer X Y) private theorem optimalGHDist_mem_candidatesB : optimalGHDist X Y ∈ candidatesB X Y := by cases Classical.choose_spec (exists_minimizer X Y) assumption private theorem HD_optimalGHDist_le (g : Cb X Y) (hg : g ∈ candidatesB X Y) : HD (optimalGHDist X Y) ≤ HD g := let ⟨_, Z2⟩ := Classical.choose_spec (exists_minimizer X Y) Z2 g hg /-- With the optimal candidate, construct a premetric space structure on `X ⊕ Y`, on which the predistance is given by the candidate. Then, we will identify points at `0` predistance to obtain a genuine metric space. -/ def premetricOptimalGHDist : PseudoMetricSpace (X ⊕ Y) where dist p q := optimalGHDist X Y (p, q) dist_self _ := candidates_refl (optimalGHDist_mem_candidatesB X Y) dist_comm _ _ := candidates_symm (optimalGHDist_mem_candidatesB X Y) dist_triangle _ _ _ := candidates_triangle (optimalGHDist_mem_candidatesB X Y) attribute [local instance] premetricOptimalGHDist /-- A metric space which realizes the optimal coupling between `X` and `Y` -/ def OptimalGHCoupling : Type _ := @SeparationQuotient (X ⊕ Y) (premetricOptimalGHDist X Y).toUniformSpace.toTopologicalSpace instance : MetricSpace (OptimalGHCoupling X Y) := by unfold OptimalGHCoupling infer_instance /-- Injection of `X` in the optimal coupling between `X` and `Y` -/ def optimalGHInjl (x : X) : OptimalGHCoupling X Y := Quotient.mk'' (inl x) /-- The injection of `X` in the optimal coupling between `X` and `Y` is an isometry. -/ theorem isometry_optimalGHInjl : Isometry (optimalGHInjl X Y) := Isometry.of_dist_eq fun _ _ => candidates_dist_inl (optimalGHDist_mem_candidatesB X Y) _ _ /-- Injection of `Y` in the optimal coupling between `X` and `Y` -/ def optimalGHInjr (y : Y) : OptimalGHCoupling X Y := Quotient.mk'' (inr y) /-- The injection of `Y` in the optimal coupling between `X` and `Y` is an isometry. -/ theorem isometry_optimalGHInjr : Isometry (optimalGHInjr X Y) := Isometry.of_dist_eq fun _ _ => candidates_dist_inr (optimalGHDist_mem_candidatesB X Y) _ _ /-- The optimal coupling between two compact spaces `X` and `Y` is still a compact space -/ instance compactSpace_optimalGHCoupling : CompactSpace (OptimalGHCoupling X Y) := ⟨by rw [← range_quotient_mk'] exact isCompact_range (continuous_sum_dom.2 ⟨(isometry_optimalGHInjl X Y).continuous, (isometry_optimalGHInjr X Y).continuous⟩)⟩ /-- For any candidate `f`, `HD(f)` is larger than or equal to the Hausdorff distance in the optimal coupling. This follows from the fact that `HD` of the optimal candidate is exactly the Hausdorff distance in the optimal coupling, although we only prove here the inequality we need. -/ theorem hausdorffDist_optimal_le_HD {f} (h : f ∈ candidatesB X Y) : hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) ≤ HD f := by refine le_trans (le_of_forall_gt_imp_ge_of_dense fun r hr => ?_) (HD_optimalGHDist_le X Y f h) have A : ∀ x ∈ range (optimalGHInjl X Y), ∃ y ∈ range (optimalGHInjr X Y), dist x y ≤ r := by rintro _ ⟨z, rfl⟩ have I1 : (⨆ x, ⨅ y, optimalGHDist X Y (inl x, inr y)) < r := lt_of_le_of_lt (le_max_left _ _) hr have I2 : ⨅ y, optimalGHDist X Y (inl z, inr y) ≤ ⨆ x, ⨅ y, optimalGHDist X Y (inl x, inr y) := le_csSup (by simpa using HD_bound_aux1 _ 0) (mem_range_self _) have I : ⨅ y, optimalGHDist X Y (inl z, inr y) < r := lt_of_le_of_lt I2 I1 rcases exists_lt_of_csInf_lt (range_nonempty _) I with ⟨r', ⟨z', rfl⟩, hr'⟩ exact ⟨optimalGHInjr X Y z', mem_range_self _, le_of_lt hr'⟩ refine hausdorffDist_le_of_mem_dist ?_ A ?_ · inhabit X rcases A _ (mem_range_self default) with ⟨y, -, hy⟩ exact le_trans dist_nonneg hy · rintro _ ⟨z, rfl⟩ have I1 : (⨆ y, ⨅ x, optimalGHDist X Y (inl x, inr y)) < r := lt_of_le_of_lt (le_max_right _ _) hr have I2 : ⨅ x, optimalGHDist X Y (inl x, inr z) ≤ ⨆ y, ⨅ x, optimalGHDist X Y (inl x, inr y) := le_csSup (by simpa using HD_bound_aux2 _ 0) (mem_range_self _) have I : ⨅ x, optimalGHDist X Y (inl x, inr z) < r := lt_of_le_of_lt I2 I1 rcases exists_lt_of_csInf_lt (range_nonempty _) I with ⟨r', ⟨z', rfl⟩, hr'⟩ refine ⟨optimalGHInjl X Y z', mem_range_self _, le_of_lt ?_⟩ rwa [dist_comm] end Consequences -- We are done with the construction of the optimal coupling end GromovHausdorffRealized end GromovHausdorff
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/ShrinkingLemma.lean
import Mathlib.Topology.EMetricSpace.Paracompact import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas import Mathlib.Topology.ShrinkingLemma /-! # Shrinking lemma in a proper metric space In this file we prove a few versions of the shrinking lemma for coverings by balls in a proper (pseudo) metric space. ## Tags shrinking lemma, metric space -/ universe u v open Set Metric open Topology variable {α : Type u} {ι : Type v} [MetricSpace α] [ProperSpace α] {c : ι → α} variable {s : Set α} /-- **Shrinking lemma** for coverings by open balls in a proper metric space. A point-finite open cover of a closed subset of a proper metric space by open balls can be shrunk to a new cover by open balls so that each of the new balls has strictly smaller radius than the old one. This version assumes that `fun x ↦ ball (c i) (r i)` is a locally finite covering and provides a covering indexed by the same type. -/ theorem exists_subset_iUnion_ball_radius_lt {r : ι → ℝ} (hs : IsClosed s) (uf : ∀ x ∈ s, { i | x ∈ ball (c i) (r i) }.Finite) (us : s ⊆ ⋃ i, ball (c i) (r i)) : ∃ r' : ι → ℝ, (s ⊆ ⋃ i, ball (c i) (r' i)) ∧ ∀ i, r' i < r i := by rcases exists_subset_iUnion_closed_subset hs (fun i => @isOpen_ball _ _ (c i) (r i)) uf us with ⟨v, hsv, hvc, hcv⟩ have := fun i => exists_lt_subset_ball (hvc i) (hcv i) choose r' hlt hsub using this exact ⟨r', hsv.trans <| iUnion_mono <| hsub, hlt⟩ /-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover of a proper metric space by open balls can be shrunk to a new cover by open balls so that each of the new balls has strictly smaller radius than the old one. -/ theorem exists_iUnion_ball_eq_radius_lt {r : ι → ℝ} (uf : ∀ x, { i | x ∈ ball (c i) (r i) }.Finite) (uU : ⋃ i, ball (c i) (r i) = univ) : ∃ r' : ι → ℝ, ⋃ i, ball (c i) (r' i) = univ ∧ ∀ i, r' i < r i := let ⟨r', hU, hv⟩ := exists_subset_iUnion_ball_radius_lt isClosed_univ (fun x _ => uf x) uU.ge ⟨r', univ_subset_iff.1 hU, hv⟩ /-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover of a closed subset of a proper metric space by nonempty open balls can be shrunk to a new cover by nonempty open balls so that each of the new balls has strictly smaller radius than the old one. -/ theorem exists_subset_iUnion_ball_radius_pos_lt {r : ι → ℝ} (hr : ∀ i, 0 < r i) (hs : IsClosed s) (uf : ∀ x ∈ s, { i | x ∈ ball (c i) (r i) }.Finite) (us : s ⊆ ⋃ i, ball (c i) (r i)) : ∃ r' : ι → ℝ, (s ⊆ ⋃ i, ball (c i) (r' i)) ∧ ∀ i, r' i ∈ Ioo 0 (r i) := by rcases exists_subset_iUnion_closed_subset hs (fun i => @isOpen_ball _ _ (c i) (r i)) uf us with ⟨v, hsv, hvc, hcv⟩ have := fun i => exists_pos_lt_subset_ball (hr i) (hvc i) (hcv i) choose r' hlt hsub using this exact ⟨r', hsv.trans <| iUnion_mono hsub, hlt⟩ /-- Shrinking lemma for coverings by open balls in a proper metric space. A point-finite open cover of a proper metric space by nonempty open balls can be shrunk to a new cover by nonempty open balls so that each of the new balls has strictly smaller radius than the old one. -/ theorem exists_iUnion_ball_eq_radius_pos_lt {r : ι → ℝ} (hr : ∀ i, 0 < r i) (uf : ∀ x, { i | x ∈ ball (c i) (r i) }.Finite) (uU : ⋃ i, ball (c i) (r i) = univ) : ∃ r' : ι → ℝ, ⋃ i, ball (c i) (r' i) = univ ∧ ∀ i, r' i ∈ Ioo 0 (r i) := let ⟨r', hU, hv⟩ := exists_subset_iUnion_ball_radius_pos_lt hr isClosed_univ (fun x _ => uf x) uU.ge ⟨r', univ_subset_iff.1 hU, hv⟩ /-- Let `R : α → ℝ` be a (possibly discontinuous) function on a proper metric space. Let `s` be a closed set in `α` such that `R` is positive on `s`. Then there exists a collection of pairs of balls `Metric.ball (c i) (r i)`, `Metric.ball (c i) (r' i)` such that * all centers belong to `s`; * for all `i` we have `0 < r i < r' i < R (c i)`; * the family of balls `Metric.ball (c i) (r' i)` is locally finite; * the balls `Metric.ball (c i) (r i)` cover `s`. This is a simple corollary of `refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set` and `exists_subset_iUnion_ball_radius_pos_lt`. -/ theorem exists_locallyFinite_subset_iUnion_ball_radius_lt (hs : IsClosed s) {R : α → ℝ} (hR : ∀ x ∈ s, 0 < R x) : ∃ (ι : Type u) (c : ι → α) (r r' : ι → ℝ), (∀ i, c i ∈ s ∧ 0 < r i ∧ r i < r' i ∧ r' i < R (c i)) ∧ (LocallyFinite fun i => ball (c i) (r' i)) ∧ s ⊆ ⋃ i, ball (c i) (r i) := by have : ∀ x ∈ s, (𝓝 x).HasBasis (fun r : ℝ => 0 < r ∧ r < R x) fun r => ball x r := fun x hx => nhds_basis_uniformity (uniformity_basis_dist_lt (hR x hx)) rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set hs this with ⟨ι, c, r', hr', hsub', hfin⟩ rcases exists_subset_iUnion_ball_radius_pos_lt (fun i => (hr' i).2.1) hs (fun x _ => hfin.point_finite x) hsub' with ⟨r, hsub, hlt⟩ exact ⟨ι, c, r, r', fun i => ⟨(hr' i).1, (hlt i).1, (hlt i).2, (hr' i).2.2⟩, hfin, hsub⟩ /-- Let `R : α → ℝ` be a (possibly discontinuous) positive function on a proper metric space. Then there exists a collection of pairs of balls `Metric.ball (c i) (r i)`, `Metric.ball (c i) (r' i)` such that * for all `i` we have `0 < r i < r' i < R (c i)`; * the family of balls `Metric.ball (c i) (r' i)` is locally finite; * the balls `Metric.ball (c i) (r i)` cover the whole space. This is a simple corollary of `refinement_of_locallyCompact_sigmaCompact_of_nhds_basis` and `exists_iUnion_ball_eq_radius_pos_lt` or `exists_locallyFinite_subset_iUnion_ball_radius_lt`. -/ theorem exists_locallyFinite_iUnion_eq_ball_radius_lt {R : α → ℝ} (hR : ∀ x, 0 < R x) : ∃ (ι : Type u) (c : ι → α) (r r' : ι → ℝ), (∀ i, 0 < r i ∧ r i < r' i ∧ r' i < R (c i)) ∧ (LocallyFinite fun i => ball (c i) (r' i)) ∧ ⋃ i, ball (c i) (r i) = univ := let ⟨ι, c, r, r', hlt, hfin, hsub⟩ := exists_locallyFinite_subset_iUnion_ball_radius_lt isClosed_univ fun x _ => hR x ⟨ι, c, r, r', fun i => (hlt i).2, hfin, univ_subset_iff.1 hsub⟩
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/CantorScheme.lean
import Mathlib.Topology.MetricSpace.PiNat /-! # (Topological) Schemes and their induced maps In topology, and especially descriptive set theory, one often constructs functions `(ℕ → β) → α`, where α is some topological space and β is a discrete space, as an appropriate limit of some map `List β → Set α`. We call the latter type of map a "`β`-scheme on `α`". This file develops the basic, abstract theory of these schemes and the functions they induce. ## Main Definitions * `CantorScheme.inducedMap A` : The aforementioned "limit" of a scheme `A : List β → Set α`. This is a partial function from `ℕ → β` to `a`, implemented here as an object of type `Σ s : Set (ℕ → β), s → α`. That is, `(inducedMap A).1` is the domain and `(inducedMap A).2` is the function. ## Implementation Notes We consider end-appending to be the fundamental way to build lists (say on `β`) inductively, as this interacts better with the topology on `ℕ → β`. As a result, functions like `List.get?` or `Stream'.take` do not have their intended meaning in this file. See instead `PiNat.res`. ## References * [kechris1995] (Chapters 6-7) ## Tags scheme, cantor scheme, lusin scheme, approximation. -/ namespace CantorScheme open List Function Filter Set PiNat Topology variable {β α : Type*} (A : List β → Set α) /-- From a `β`-scheme on `α` `A`, we define a partial function from `(ℕ → β)` to `α` which sends each infinite sequence `x` to an element of the intersection along the branch corresponding to `x`, if it exists. We call this the map induced by the scheme. -/ noncomputable def inducedMap : Σ s : Set (ℕ → β), s → α := ⟨fun x => Set.Nonempty (⋂ n : ℕ, A (res x n)), fun x => x.property.some⟩ section Topology /-- A scheme is antitone if each set contains its children. -/ protected def Antitone : Prop := ∀ l : List β, ∀ a : β, A (a :: l) ⊆ A l /-- A useful strengthening of being antitone is to require that each set contains the closure of each of its children. -/ def ClosureAntitone [TopologicalSpace α] : Prop := ∀ l : List β, ∀ a : β, closure (A (a :: l)) ⊆ A l /-- A scheme is disjoint if the children of each set of pairwise disjoint. -/ protected def Disjoint : Prop := ∀ l : List β, Pairwise fun a b => Disjoint (A (a :: l)) (A (b :: l)) variable {A} /-- If `x` is in the domain of the induced map of a scheme `A`, its image under this map is in each set along the corresponding branch. -/ theorem map_mem (x : (inducedMap A).1) (n : ℕ) : (inducedMap A).2 x ∈ A (res x n) := by have := x.property.some_mem rw [mem_iInter] at this exact this n protected theorem ClosureAntitone.antitone [TopologicalSpace α] (hA : ClosureAntitone A) : CantorScheme.Antitone A := fun l a => subset_closure.trans (hA l a) protected theorem Antitone.closureAntitone [TopologicalSpace α] (hanti : CantorScheme.Antitone A) (hclosed : ∀ l, IsClosed (A l)) : ClosureAntitone A := fun _ _ => (hclosed _).closure_eq.subset.trans (hanti _ _) /-- A scheme where the children of each set are pairwise disjoint induces an injective map. -/ theorem Disjoint.map_injective (hA : CantorScheme.Disjoint A) : Injective (inducedMap A).2 := by rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy refine Subtype.coe_injective (res_injective ?_) dsimp ext n : 1 induction n with | zero => simp | succ n ih => simp only [res_succ, cons.injEq] refine ⟨?_, ih⟩ contrapose hA simp only [CantorScheme.Disjoint, _root_.Pairwise, Ne, not_forall, exists_prop] refine ⟨res x n, _, _, hA, ?_⟩ rw [not_disjoint_iff] refine ⟨(inducedMap A).2 ⟨x, hx⟩, ?_, ?_⟩ · rw [← res_succ] apply map_mem rw [hxy, ih, ← res_succ] apply map_mem end Topology section Metric variable [PseudoMetricSpace α] /-- A scheme on a metric space has vanishing diameter if diameter approaches 0 along each branch. -/ def VanishingDiam : Prop := ∀ x : ℕ → β, Tendsto (fun n : ℕ => EMetric.diam (A (res x n))) atTop (𝓝 0) variable {A} theorem VanishingDiam.dist_lt (hA : VanishingDiam A) (ε : ℝ) (ε_pos : 0 < ε) (x : ℕ → β) : ∃ n : ℕ, ∀ (y) (_ : y ∈ A (res x n)) (z) (_ : z ∈ A (res x n)), dist y z < ε := by specialize hA x rw [ENNReal.tendsto_atTop_zero] at hA obtain ⟨n, hn⟩ := hA (ENNReal.ofReal (ε / 2)) (by simp only [gt_iff_lt, ENNReal.ofReal_pos]; linarith) use n intro y hy z hz rw [← ENNReal.ofReal_lt_ofReal_iff ε_pos, ← edist_dist] apply lt_of_le_of_lt (EMetric.edist_le_diam_of_mem hy hz) apply lt_of_le_of_lt (hn _ (le_refl _)) rw [ENNReal.ofReal_lt_ofReal_iff ε_pos] linarith /-- A scheme with vanishing diameter along each branch induces a continuous map. -/ theorem VanishingDiam.map_continuous [TopologicalSpace β] [DiscreteTopology β] (hA : VanishingDiam A) : Continuous (inducedMap A).2 := by rw [Metric.continuous_iff'] rintro ⟨x, hx⟩ ε ε_pos obtain ⟨n, hn⟩ := hA.dist_lt _ ε_pos x rw [_root_.eventually_nhds_iff] refine ⟨(↑)⁻¹' cylinder x n, ?_, ?_, by simp⟩ · rintro ⟨y, hy⟩ hyx rw [mem_preimage, Subtype.coe_mk, cylinder_eq_res, mem_setOf] at hyx apply hn · rw [← hyx] apply map_mem apply map_mem apply continuous_subtype_val.isOpen_preimage apply isOpen_cylinder /-- A scheme on a complete space with vanishing diameter such that each set contains the closure of its children induces a total map. -/ theorem ClosureAntitone.map_of_vanishingDiam [CompleteSpace α] (hdiam : VanishingDiam A) (hanti : ClosureAntitone A) (hnonempty : ∀ l, (A l).Nonempty) : (inducedMap A).1 = univ := by rw [eq_univ_iff_forall] intro x choose u hu using fun n => hnonempty (res x n) have umem : ∀ n m : ℕ, n ≤ m → u m ∈ A (res x n) := by have : Antitone fun n : ℕ => A (res x n) := by refine antitone_nat_of_succ_le ?_ intro n apply hanti.antitone intro n m hnm exact this hnm (hu _) have : CauchySeq u := by rw [Metric.cauchySeq_iff] intro ε ε_pos obtain ⟨n, hn⟩ := hdiam.dist_lt _ ε_pos x use n intro m₀ hm₀ m₁ hm₁ apply hn <;> apply umem <;> assumption obtain ⟨y, hy⟩ := cauchySeq_tendsto_of_complete this use y rw [mem_iInter] intro n apply hanti _ (x n) apply mem_closure_of_tendsto hy rw [eventually_atTop] exact ⟨n.succ, umem _⟩ end Metric end CantorScheme
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Bounded.lean
import Mathlib.Topology.Order.Bornology import Mathlib.Topology.Order.Compact import Mathlib.Topology.MetricSpace.ProperSpace import Mathlib.Topology.MetricSpace.Cauchy import Mathlib.Topology.MetricSpace.Defs import Mathlib.Topology.EMetricSpace.Diam /-! ## Boundedness in (pseudo)-metric spaces This file contains one definition, and various results on boundedness in pseudo-metric spaces. * `Metric.diam s` : The `iSup` of the distances of members of `s`. Defined in terms of `EMetric.diam`, for better handling of the case when it should be infinite. * `isBounded_iff_subset_closedBall`: a non-empty set is bounded if and only if it is included in some closed ball * describing the cobounded filter, relating to the cocompact filter * `IsCompact.isBounded`: compact sets are bounded * `TotallyBounded.isBounded`: totally bounded sets are bounded * `isCompact_iff_isClosed_bounded`, the **Heine–Borel theorem**: in a proper space, a set is compact if and only if it is closed and bounded. * `cobounded_eq_cocompact`: in a proper space, cobounded and compact sets are the same diameter of a subset, and its relation to boundedness ## Tags metric, pseudo_metric, bounded, diameter, Heine-Borel theorem -/ assert_not_exists Module.Basis open Set Filter Bornology open scoped ENNReal Uniformity Topology Pointwise universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} section UniformSpace variable [UniformSpace α] [Preorder α] [CompactIccSpace α] lemma totallyBounded_Icc (a b : α) : TotallyBounded (Icc a b) := isCompact_Icc.totallyBounded lemma totallyBounded_Ico (a b : α) : TotallyBounded (Ico a b) := (totallyBounded_Icc a b).subset Ico_subset_Icc_self lemma totallyBounded_Ioc (a b : α) : TotallyBounded (Ioc a b) := (totallyBounded_Icc a b).subset Ioc_subset_Icc_self lemma totallyBounded_Ioo (a b : α) : TotallyBounded (Ioo a b) := (totallyBounded_Icc a b).subset Ioo_subset_Icc_self end UniformSpace namespace Metric section Bounded variable {x : α} {s t : Set α} {r : ℝ} variable [PseudoMetricSpace α] /-- Closed balls are bounded -/ theorem isBounded_closedBall : IsBounded (closedBall x r) := isBounded_iff.2 ⟨r + r, fun y hy z hz => calc dist y z ≤ dist y x + dist z x := dist_triangle_right _ _ _ _ ≤ r + r := add_le_add hy hz⟩ /-- Open balls are bounded -/ theorem isBounded_ball : IsBounded (ball x r) := isBounded_closedBall.subset ball_subset_closedBall /-- Spheres are bounded -/ theorem isBounded_sphere : IsBounded (sphere x r) := isBounded_closedBall.subset sphere_subset_closedBall /-- Given a point, a bounded subset is included in some ball around this point -/ theorem isBounded_iff_subset_closedBall (c : α) : IsBounded s ↔ ∃ r, s ⊆ closedBall c r := ⟨fun h ↦ (isBounded_iff.1 (h.insert c)).imp fun _r hr _x hx ↦ hr (.inr hx) (mem_insert _ _), fun ⟨_r, hr⟩ ↦ isBounded_closedBall.subset hr⟩ theorem _root_.Bornology.IsBounded.subset_closedBall (h : IsBounded s) (c : α) : ∃ r, s ⊆ closedBall c r := (isBounded_iff_subset_closedBall c).1 h theorem _root_.Bornology.IsBounded.subset_ball_lt (h : IsBounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ ball c r := let ⟨r, hr⟩ := h.subset_closedBall c ⟨max r a + 1, (le_max_right _ _).trans_lt (lt_add_one _), hr.trans <| closedBall_subset_ball <| (le_max_left _ _).trans_lt (lt_add_one _)⟩ theorem _root_.Bornology.IsBounded.subset_ball (h : IsBounded s) (c : α) : ∃ r, s ⊆ ball c r := (h.subset_ball_lt 0 c).imp fun _ ↦ And.right theorem isBounded_iff_subset_ball (c : α) : IsBounded s ↔ ∃ r, s ⊆ ball c r := ⟨(IsBounded.subset_ball · c), fun ⟨_r, hr⟩ ↦ isBounded_ball.subset hr⟩ theorem _root_.Bornology.IsBounded.subset_closedBall_lt (h : IsBounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ closedBall c r := let ⟨r, har, hr⟩ := h.subset_ball_lt a c ⟨r, har, hr.trans ball_subset_closedBall⟩ theorem isBounded_closure_of_isBounded (h : IsBounded s) : IsBounded (closure s) := let ⟨C, h⟩ := isBounded_iff.1 h isBounded_iff.2 ⟨C, fun _a ha _b hb => isClosed_Iic.closure_subset <| map_mem_closure₂ continuous_dist ha hb h⟩ protected theorem _root_.Bornology.IsBounded.closure (h : IsBounded s) : IsBounded (closure s) := isBounded_closure_of_isBounded h @[simp] theorem isBounded_closure_iff : IsBounded (closure s) ↔ IsBounded s := ⟨fun h => h.subset subset_closure, fun h => h.closure⟩ theorem hasBasis_cobounded_compl_closedBall (c : α) : (cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (closedBall c r)ᶜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_closedBall c).trans <| by simp⟩ theorem hasAntitoneBasis_cobounded_compl_closedBall (c : α) : (cobounded α).HasAntitoneBasis (fun r ↦ (closedBall c r)ᶜ) := ⟨Metric.hasBasis_cobounded_compl_closedBall _, fun _ _ hr _ ↦ by simpa using hr.trans_lt⟩ theorem hasBasis_cobounded_compl_ball (c : α) : (cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (ball c r)ᶜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_ball c).trans <| by simp⟩ theorem hasAntitoneBasis_cobounded_compl_ball (c : α) : (cobounded α).HasAntitoneBasis (fun r ↦ (ball c r)ᶜ) := ⟨Metric.hasBasis_cobounded_compl_ball _, fun _ _ hr _ ↦ by simpa using hr.trans⟩ @[simp] theorem comap_dist_right_atTop (c : α) : comap (dist · c) atTop = cobounded α := (atTop_basis.comap _).eq_of_same_basis <| by simpa only [compl_def, mem_ball, not_lt] using hasBasis_cobounded_compl_ball c @[simp] theorem comap_dist_left_atTop (c : α) : comap (dist c) atTop = cobounded α := by simpa only [dist_comm _ c] using comap_dist_right_atTop c @[simp] theorem tendsto_dist_right_atTop_iff (c : α) {f : β → α} {l : Filter β} : Tendsto (fun x ↦ dist (f x) c) l atTop ↔ Tendsto f l (cobounded α) := by rw [← comap_dist_right_atTop c, tendsto_comap_iff, Function.comp_def] @[simp] theorem tendsto_dist_left_atTop_iff (c : α) {f : β → α} {l : Filter β} : Tendsto (fun x ↦ dist c (f x)) l atTop ↔ Tendsto f l (cobounded α) := by simp only [dist_comm c, tendsto_dist_right_atTop_iff] theorem tendsto_dist_right_cobounded_atTop (c : α) : Tendsto (dist · c) (cobounded α) atTop := tendsto_iff_comap.2 (comap_dist_right_atTop c).ge theorem tendsto_dist_left_cobounded_atTop (c : α) : Tendsto (dist c) (cobounded α) atTop := tendsto_iff_comap.2 (comap_dist_left_atTop c).ge /-- A totally bounded set is bounded -/ theorem _root_.TotallyBounded.isBounded {s : Set α} (h : TotallyBounded s) : IsBounded s := -- We cover the totally bounded set by finitely many balls of radius 1, -- and then argue that a finite union of bounded sets is bounded let ⟨_t, fint, subs⟩ := (totallyBounded_iff.mp h) 1 zero_lt_one ((isBounded_biUnion fint).2 fun _ _ => isBounded_ball).subset subs /-- A compact set is bounded -/ @[aesop 50% apply, grind ←] theorem _root_.IsCompact.isBounded {s : Set α} (h : IsCompact s) : IsBounded s := -- A compact set is totally bounded, thus bounded h.totallyBounded.isBounded theorem cobounded_le_cocompact : cobounded α ≤ cocompact α := hasBasis_cocompact.ge_iff.2 fun _s hs ↦ hs.isBounded theorem isCobounded_iff_closedBall_compl_subset {s : Set α} (c : α) : IsCobounded s ↔ ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := by rw [← isBounded_compl_iff, isBounded_iff_subset_closedBall c] apply exists_congr intro r rw [compl_subset_comm] theorem _root_.Bornology.IsCobounded.closedBall_compl_subset {s : Set α} (hs : IsCobounded s) (c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := (isCobounded_iff_closedBall_compl_subset c).mp hs theorem closedBall_compl_subset_of_mem_cocompact {s : Set α} (hs : s ∈ cocompact α) (c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := IsCobounded.closedBall_compl_subset (cobounded_le_cocompact hs) c theorem mem_cocompact_of_closedBall_compl_subset [ProperSpace α] (c : α) (h : ∃ r, (closedBall c r)ᶜ ⊆ s) : s ∈ cocompact α := by rcases h with ⟨r, h⟩ rw [Filter.mem_cocompact] exact ⟨closedBall c r, isCompact_closedBall c r, h⟩ theorem mem_cocompact_iff_closedBall_compl_subset [ProperSpace α] (c : α) : s ∈ cocompact α ↔ ∃ r, (closedBall c r)ᶜ ⊆ s := ⟨(closedBall_compl_subset_of_mem_cocompact · _), mem_cocompact_of_closedBall_compl_subset _⟩ /-- Characterization of the boundedness of the range of a function -/ theorem isBounded_range_iff {f : β → α} : IsBounded (range f) ↔ ∃ C, ∀ x y, dist (f x) (f y) ≤ C := isBounded_iff.trans <| by simp only [forall_mem_range] theorem isBounded_image_iff {f : β → α} {s : Set β} : IsBounded (f '' s) ↔ ∃ C, ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ C := isBounded_iff.trans <| by simp only [forall_mem_image] theorem isBounded_range_of_tendsto_cofinite_uniformity {f : β → α} (hf : Tendsto (Prod.map f f) (.cofinite ×ˢ .cofinite) (𝓤 α)) : IsBounded (range f) := by rcases (hasBasis_cofinite.prod_self.tendsto_iff uniformity_basis_dist).1 hf 1 zero_lt_one with ⟨s, hsf, hs1⟩ rw [← image_union_image_compl_eq_range] refine (hsf.image f).isBounded.union (isBounded_image_iff.2 ⟨1, fun x hx y hy ↦ ?_⟩) exact le_of_lt (hs1 (x, y) ⟨hx, hy⟩) theorem isBounded_range_of_cauchy_map_cofinite {f : β → α} (hf : Cauchy (map f cofinite)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (cauchy_map_iff.1 hf).2 theorem _root_.CauchySeq.isBounded_range {f : ℕ → α} (hf : CauchySeq f) : IsBounded (range f) := isBounded_range_of_cauchy_map_cofinite <| by rwa [Nat.cofinite_eq_atTop] theorem isBounded_range_of_tendsto_cofinite {f : β → α} {a : α} (hf : Tendsto f cofinite (𝓝 a)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (hf.prodMap hf).mono_right <| nhds_prod_eq.symm.trans_le (nhds_le_uniformity a) /-- In a compact space, all sets are bounded -/ theorem isBounded_of_compactSpace [CompactSpace α] : IsBounded s := isCompact_univ.isBounded.subset (subset_univ _) theorem isBounded_range_of_tendsto (u : ℕ → α) {x : α} (hu : Tendsto u atTop (𝓝 x)) : IsBounded (range u) := hu.cauchySeq.isBounded_range theorem disjoint_nhds_cobounded (x : α) : Disjoint (𝓝 x) (cobounded α) := disjoint_of_disjoint_of_mem disjoint_compl_right (ball_mem_nhds _ one_pos) isBounded_ball theorem disjoint_cobounded_nhds (x : α) : Disjoint (cobounded α) (𝓝 x) := (disjoint_nhds_cobounded x).symm theorem disjoint_nhdsSet_cobounded {s : Set α} (hs : IsCompact s) : Disjoint (𝓝ˢ s) (cobounded α) := hs.disjoint_nhdsSet_left.2 fun _ _ ↦ disjoint_nhds_cobounded _ theorem disjoint_cobounded_nhdsSet {s : Set α} (hs : IsCompact s) : Disjoint (cobounded α) (𝓝ˢ s) := (disjoint_nhdsSet_cobounded hs).symm theorem exists_isBounded_image_of_tendsto {α β : Type*} [PseudoMetricSpace β] {l : Filter α} {f : α → β} {x : β} (hf : Tendsto f l (𝓝 x)) : ∃ s ∈ l, IsBounded (f '' s) := (l.basis_sets.map f).disjoint_iff_left.mp <| (disjoint_nhds_cobounded x).mono_left hf /-- If a function is continuous within a set `s` at every point of a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousWithinAt f s x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := by have : Disjoint (𝓝ˢ k ⊓ 𝓟 s) (comap f (cobounded α)) := by rw [disjoint_assoc, inf_comm, hk.disjoint_nhdsSet_left] exact fun x hx ↦ disjoint_left_comm.2 <| tendsto_comap.disjoint (disjoint_cobounded_nhds _) (hf x hx) rcases ((((hasBasis_nhdsSet _).inf_principal _)).disjoint_iff ((basis_sets _).comap _)).1 this with ⟨U, ⟨hUo, hkU⟩, t, ht, hd⟩ refine ⟨U, hkU, hUo, (isBounded_compl_iff.2 ht).subset ?_⟩ rwa [image_subset_iff, preimage_compl, subset_compl_iff_disjoint_right] /-- If a function is continuous at every point of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/ theorem exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt [TopologicalSpace β] {k : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousAt f x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) := by simp_rw [← continuousWithinAt_univ] at hf simpa only [inter_univ] using exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk hf /-- If a function is continuous on a set `s` containing a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_continuousOn [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hks : k ⊆ s) (hf : ContinuousOn f s) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk fun x hx => hf x (hks hx) /-- If a function is continuous on a neighborhood of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/ theorem exists_isOpen_isBounded_image_of_isCompact_of_continuousOn [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hs : IsOpen s) (hks : k ⊆ s) (hf : ContinuousOn f s) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) := exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt hk fun _x hx => hf.continuousAt (hs.mem_nhds (hks hx)) /-- The **Heine–Borel theorem**: In a proper space, a closed bounded set is compact. -/ theorem isCompact_of_isClosed_isBounded [ProperSpace α] (hc : IsClosed s) (hb : IsBounded s) : IsCompact s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, -⟩) · exact isCompact_empty · rcases hb.subset_closedBall x with ⟨r, hr⟩ exact (isCompact_closedBall x r).of_isClosed_subset hc hr /-- The **Heine–Borel theorem**: In a proper space, the closure of a bounded set is compact. -/ theorem _root_.Bornology.IsBounded.isCompact_closure [ProperSpace α] (h : IsBounded s) : IsCompact (closure s) := isCompact_of_isClosed_isBounded isClosed_closure h.closure -- TODO: assume `[MetricSpace α]` instead of `[PseudoMetricSpace α] [T2Space α]` /-- The **Heine–Borel theorem**: In a proper Hausdorff space, a set is compact if and only if it is closed and bounded. -/ theorem isCompact_iff_isClosed_bounded [T2Space α] [ProperSpace α] : IsCompact s ↔ IsClosed s ∧ IsBounded s := ⟨fun h => ⟨h.isClosed, h.isBounded⟩, fun h => isCompact_of_isClosed_isBounded h.1 h.2⟩ theorem compactSpace_iff_isBounded_univ [ProperSpace α] : CompactSpace α ↔ IsBounded (univ : Set α) := ⟨@isBounded_of_compactSpace α _ _, fun hb => ⟨isCompact_of_isClosed_isBounded isClosed_univ hb⟩⟩ section CompactIccSpace variable [Preorder α] [CompactIccSpace α] theorem isBounded_Icc (a b : α) : IsBounded (Icc a b) := (totallyBounded_Icc a b).isBounded theorem isBounded_Ico (a b : α) : IsBounded (Ico a b) := (totallyBounded_Ico a b).isBounded theorem isBounded_Ioc (a b : α) : IsBounded (Ioc a b) := (totallyBounded_Ioc a b).isBounded theorem isBounded_Ioo (a b : α) : IsBounded (Ioo a b) := (totallyBounded_Ioo a b).isBounded /-- In a pseudo metric space with a conditionally complete linear order such that the order and the metric structure give the same topology, any order-bounded set is metric-bounded. -/ theorem isBounded_of_bddAbove_of_bddBelow {s : Set α} (h₁ : BddAbove s) (h₂ : BddBelow s) : IsBounded s := let ⟨u, hu⟩ := h₁ let ⟨l, hl⟩ := h₂ (isBounded_Icc l u).subset (fun _x hx => mem_Icc.mpr ⟨hl hx, hu hx⟩) open Metric in lemma _root_.IsOrderBornology.of_isCompactIcc (x : α) (bddBelow_ball : ∀ r, BddBelow (closedBall x r)) (bddAbove_ball : ∀ r, BddAbove (closedBall x r)) : IsOrderBornology α where isBounded_iff_bddBelow_bddAbove s := by refine ⟨?_, fun hs ↦ Metric.isBounded_of_bddAbove_of_bddBelow hs.2 hs.1⟩ rw [Metric.isBounded_iff_subset_closedBall x] rintro ⟨r, hr⟩ exact ⟨(bddBelow_ball _).mono hr, (bddAbove_ball _).mono hr⟩ end CompactIccSpace section CompactIccSpace_abs variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [PseudoMetricSpace α] [CompactIccSpace α] lemma isBounded_of_abs_le (C : α) : Bornology.IsBounded {x : α | |x| ≤ C} := by convert Metric.isBounded_Icc (-C) C ext1 x simp [abs_le] lemma isBounded_of_abs_lt (C : α) : Bornology.IsBounded {x : α | |x| < C} := by convert Metric.isBounded_Ioo (-C) C ext1 x simp [abs_lt] end CompactIccSpace_abs end Bounded section Diam variable {s : Set α} {x y z : α} section PseudoMetricSpace variable [PseudoMetricSpace α] /-- The diameter of a set in a metric space. To get controllable behavior even when the diameter should be infinite, we express it in terms of the `EMetric.diam` -/ noncomputable def diam (s : Set α) : ℝ := ENNReal.toReal (EMetric.diam s) /-- The diameter of a set is always nonnegative -/ theorem diam_nonneg : 0 ≤ diam s := ENNReal.toReal_nonneg theorem diam_subsingleton (hs : s.Subsingleton) : diam s = 0 := by simp only [diam, EMetric.diam_subsingleton hs, ENNReal.toReal_zero] /-- The empty set has zero diameter -/ @[simp] theorem diam_empty : diam (∅ : Set α) = 0 := diam_subsingleton subsingleton_empty /-- A singleton has zero diameter -/ @[simp] theorem diam_singleton : diam ({x} : Set α) = 0 := diam_subsingleton subsingleton_singleton @[to_additive (attr := simp)] theorem diam_one [One α] : diam (1 : Set α) = 0 := diam_singleton -- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x}) theorem diam_pair : diam ({x, y} : Set α) = dist x y := by simp only [diam, EMetric.diam_pair, dist_edist] -- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x})) theorem diam_triple : Metric.diam ({x, y, z} : Set α) = max (max (dist x y) (dist x z)) (dist y z) := by simp only [Metric.diam, EMetric.diam_triple, dist_edist] rw [ENNReal.toReal_max, ENNReal.toReal_max] <;> apply_rules [ne_of_lt, edist_lt_top, max_lt] /-- If the distance between any two points in a set is bounded by some constant `C`, then `ENNReal.ofReal C` bounds the emetric diameter of this set. -/ theorem ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : EMetric.diam s ≤ ENNReal.ofReal C := EMetric.diam_le fun x hx y hy => (edist_dist x y).symm ▸ ENNReal.ofReal_le_ofReal (h x hx y hy) /-- If the distance between any two points in a set is bounded by some non-negative constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : diam s ≤ C := ENNReal.toReal_le_of_le_ofReal h₀ (ediam_le_of_forall_dist_le h) /-- If the distance between any two points in a nonempty set is bounded by some constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le_of_nonempty (hs : s.Nonempty) {C : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : diam s ≤ C := have h₀ : 0 ≤ C := let ⟨x, hx⟩ := hs le_trans dist_nonneg (h x hx x hx) diam_le_of_forall_dist_le h₀ h /-- The distance between two points in a set is controlled by the diameter of the set. -/ theorem dist_le_diam_of_mem' (h : EMetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s := by rw [diam, dist_edist] exact ENNReal.toReal_mono h <| EMetric.edist_le_diam_of_mem hx hy /-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/ theorem isBounded_iff_ediam_ne_top : IsBounded s ↔ EMetric.diam s ≠ ⊤ := isBounded_iff.trans <| Iff.intro (fun ⟨_C, hC⟩ => ne_top_of_le_ne_top ENNReal.ofReal_ne_top <| ediam_le_of_forall_dist_le hC) fun h => ⟨diam s, fun _x hx _y hy => dist_le_diam_of_mem' h hx hy⟩ alias ⟨_root_.Bornology.IsBounded.ediam_ne_top, _⟩ := isBounded_iff_ediam_ne_top theorem ediam_eq_top_iff_unbounded : EMetric.diam s = ⊤ ↔ ¬IsBounded s := isBounded_iff_ediam_ne_top.not_left.symm theorem ediam_univ_eq_top_iff_noncompact [ProperSpace α] : EMetric.diam (univ : Set α) = ∞ ↔ NoncompactSpace α := by rw [← not_compactSpace_iff, compactSpace_iff_isBounded_univ, isBounded_iff_ediam_ne_top, Classical.not_not] @[simp] theorem ediam_univ_of_noncompact [ProperSpace α] [NoncompactSpace α] : EMetric.diam (univ : Set α) = ∞ := ediam_univ_eq_top_iff_noncompact.mpr ‹_› @[simp] theorem diam_univ_of_noncompact [ProperSpace α] [NoncompactSpace α] : diam (univ : Set α) = 0 := by simp [diam] /-- The distance between two points in a set is controlled by the diameter of the set. -/ theorem dist_le_diam_of_mem (h : IsBounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s := dist_le_diam_of_mem' h.ediam_ne_top hx hy theorem ediam_of_unbounded (h : ¬IsBounded s) : EMetric.diam s = ∞ := ediam_eq_top_iff_unbounded.2 h /-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `EMetric.diam`. This lemma makes it possible to avoid side conditions in some situations -/ theorem diam_eq_zero_of_unbounded (h : ¬IsBounded s) : diam s = 0 := by rw [diam, ediam_of_unbounded h, ENNReal.toReal_top] /-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/ theorem diam_mono {s t : Set α} (h : s ⊆ t) (ht : IsBounded t) : diam s ≤ diam t := ENNReal.toReal_mono ht.ediam_ne_top <| EMetric.diam_mono h /-- The diameter of a union is controlled by the sum of the diameters, and the distance between any two points in each of the sets. This lemma is true without any side condition, since it is obviously true if `s ∪ t` is unbounded. -/ theorem diam_union {t : Set α} (xs : x ∈ s) (yt : y ∈ t) : diam (s ∪ t) ≤ diam s + dist x y + diam t := by simp only [diam, dist_edist] grw [ENNReal.toReal_le_add' (EMetric.diam_union xs yt), ENNReal.toReal_add_le] · simp only [ENNReal.add_eq_top, edist_ne_top, or_false] exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono subset_union_left · exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono subset_union_right /-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/ theorem diam_union' {t : Set α} (h : (s ∩ t).Nonempty) : diam (s ∪ t) ≤ diam s + diam t := by rcases h with ⟨x, ⟨xs, xt⟩⟩ simpa using diam_union xs xt theorem diam_le_of_subset_closedBall {r : ℝ} (hr : 0 ≤ r) (h : s ⊆ closedBall x r) : diam s ≤ 2 * r := diam_le_of_forall_dist_le (mul_nonneg zero_le_two hr) fun a ha b hb => calc dist a b ≤ dist a x + dist b x := dist_triangle_right _ _ _ _ ≤ r + r := add_le_add (h ha) (h hb) _ = 2 * r := by simp [mul_two, mul_comm] /-- The diameter of a closed ball of radius `r` is at most `2 r`. -/ theorem diam_closedBall {r : ℝ} (h : 0 ≤ r) : diam (closedBall x r) ≤ 2 * r := diam_le_of_subset_closedBall h Subset.rfl /-- The diameter of a ball of radius `r` is at most `2 r`. -/ theorem diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r := diam_le_of_subset_closedBall h ball_subset_closedBall /-- If a family of complete sets with diameter tending to `0` is such that each finite intersection is nonempty, then the total intersection is also nonempty. -/ theorem _root_.IsComplete.nonempty_iInter_of_nonempty_biInter {s : ℕ → Set α} (h0 : IsComplete (s 0)) (hs : ∀ n, IsClosed (s n)) (h's : ∀ n, IsBounded (s n)) (h : ∀ N, (⋂ n ≤ N, s n).Nonempty) (h' : Tendsto (fun n => diam (s n)) atTop (𝓝 0)) : (⋂ n, s n).Nonempty := by let u N := (h N).some have I : ∀ n N, n ≤ N → u N ∈ s n := by intro n N hn apply mem_of_subset_of_mem _ (h N).choose_spec intro x hx simp only [mem_iInter] at hx exact hx n hn have : CauchySeq u := by apply cauchySeq_of_le_tendsto_0 _ _ h' intro m n N hm hn exact dist_le_diam_of_mem (h's N) (I _ _ hm) (I _ _ hn) obtain ⟨x, -, xlim⟩ : ∃ x ∈ s 0, Tendsto (fun n : ℕ => u n) atTop (𝓝 x) := cauchySeq_tendsto_of_isComplete h0 (fun n => I 0 n (zero_le _)) this refine ⟨x, mem_iInter.2 fun n => ?_⟩ apply (hs n).mem_of_tendsto xlim filter_upwards [Ici_mem_atTop n] with p hp exact I n p hp /-- In a complete space, if a family of closed sets with diameter tending to `0` is such that each finite intersection is nonempty, then the total intersection is also nonempty. -/ theorem nonempty_iInter_of_nonempty_biInter [CompleteSpace α] {s : ℕ → Set α} (hs : ∀ n, IsClosed (s n)) (h's : ∀ n, IsBounded (s n)) (h : ∀ N, (⋂ n ≤ N, s n).Nonempty) (h' : Tendsto (fun n => diam (s n)) atTop (𝓝 0)) : (⋂ n, s n).Nonempty := (hs 0).isComplete.nonempty_iInter_of_nonempty_biInter hs h's h h' end PseudoMetricSpace section MetricSpace theorem diam_pos [MetricSpace α] (hs1 : s.Nontrivial) (hs2 : IsBounded s) : 0 < diam s := by rcases hs1 with ⟨x, hx, y, hy, hxy⟩ exact (dist_pos.mpr hxy).trans_le <| Metric.dist_le_diam_of_mem hs2 hx hy end MetricSpace end Diam end Metric namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: the diameter of a set is always nonnegative. -/ @[positivity Metric.diam _] def evalDiam : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Metric.diam _ $inst $s) => assertInstancesCommute pure (.nonnegative q(Metric.diam_nonneg)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity section open Metric variable [PseudoMetricSpace α] theorem Metric.cobounded_eq_cocompact [ProperSpace α] : cobounded α = cocompact α := by nontriviality α; inhabit α exact cobounded_le_cocompact.antisymm <| (hasBasis_cobounded_compl_closedBall default).ge_iff.2 fun _ _ ↦ (isCompact_closedBall _ _).compl_mem_cocompact theorem tendsto_dist_right_cocompact_atTop [ProperSpace α] (x : α) : Tendsto (dist · x) (cocompact α) atTop := (tendsto_dist_right_cobounded_atTop x).mono_left cobounded_eq_cocompact.ge theorem tendsto_dist_left_cocompact_atTop [ProperSpace α] (x : α) : Tendsto (dist x) (cocompact α) atTop := (tendsto_dist_left_cobounded_atTop x).mono_left cobounded_eq_cocompact.ge theorem comap_dist_left_atTop_eq_cocompact [ProperSpace α] (x : α) : comap (dist x) atTop = cocompact α := by simp [cobounded_eq_cocompact] theorem tendsto_cocompact_of_tendsto_dist_comp_atTop {f : β → α} {l : Filter β} (x : α) (h : Tendsto (fun y => dist (f y) x) l atTop) : Tendsto f l (cocompact α) := ((tendsto_dist_right_atTop_iff _).1 h).mono_right cobounded_le_cocompact theorem Metric.finite_isBounded_inter_isClosed [ProperSpace α] {K s : Set α} [DiscreteTopology s] (hK : IsBounded K) (hs : IsClosed s) : Set.Finite (K ∩ s) := by refine Set.Finite.subset (IsCompact.finite ?_ ?_) (Set.inter_subset_inter_left s subset_closure) · exact hK.isCompact_closure.inter_right hs · exact DiscreteTopology.of_subset inferInstance Set.inter_subset_right end namespace Continuous variable {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [PseudoMetricSpace β] [ProperSpace β] /-- A version of the **Extreme Value Theorem**: if the set where a continuous function `f` into a linearly ordered space takes values `≤ f x₀` is bounded for some `x₀`, then `f` has a global minimum (under suitable topological assumptions). This is a convenient combination of `Continuous.exists_forall_le'` and `Metric.isCompact_of_isClosed_isBounded`. -/ theorem exists_forall_le_of_isBounded {f : β → α} (hf : Continuous f) (x₀ : β) (h : Bornology.IsBounded {x : β | f x ≤ f x₀}) : ∃ x, ∀ y, f x ≤ f y := by refine hf.exists_forall_le' (x₀ := x₀) ?_ have hU : {x : β | f x₀ < f x} ∈ Filter.cocompact β := by refine Filter.mem_cocompact'.mpr ⟨_, ?_, fun ⦃_⦄ a ↦ a⟩ simp only [Set.compl_setOf, not_lt] exact Metric.isCompact_of_isClosed_isBounded (isClosed_le (by fun_prop) (by fun_prop)) h filter_upwards [hU] with x hx using hx.le /-- A version of the **Extreme Value Theorem**: if the set where a continuous function `f` into a linearly ordered space takes values `≥ f x₀` is bounded for some `x₀`, then `f` has a global maximum (under suitable topological assumptions). This is a convenient combination of `Continuous.exists_forall_ge'` and `Metric.isCompact_of_isClosed_isBounded`. -/ theorem exists_forall_ge_of_isBounded {f : β → α} (hf : Continuous f) (x₀ : β) (h : Bornology.IsBounded {x : β | f x₀ ≤ f x}) : ∃ x, ∀ y, f y ≤ f x := hf.exists_forall_le_of_isBounded (α := αᵒᵈ) x₀ h end Continuous
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Equicontinuity.lean
import Mathlib.Topology.UniformSpace.Equicontinuity import Mathlib.Topology.MetricSpace.Pseudo.Lemmas /-! # Equicontinuity in metric spaces This file contains various facts about (uniform) equicontinuity in metric spaces. Most importantly, we prove the usual characterization of equicontinuity of `F` at `x₀` in the case of (pseudo) metric spaces: `∀ ε > 0, ∃ δ > 0, ∀ x, dist x x₀ < δ → ∀ i, dist (F i x₀) (F i x) < ε`, and we prove that functions sharing a common (local or global) continuity modulus are (locally or uniformly) equicontinuous. ## Main statements * `Metric.equicontinuousAt_iff`: characterization of equicontinuity for families of functions between (pseudo) metric spaces. * `Metric.equicontinuousAt_of_continuity_modulus`: convenient way to prove equicontinuity at a point of a family of functions to a (pseudo) metric space by showing that they share a common *local* continuity modulus. * `Metric.uniformEquicontinuous_of_continuity_modulus`: convenient way to prove uniform equicontinuity of a family of functions to a (pseudo) metric space by showing that they share a common *global* continuity modulus. ## Tags equicontinuity, continuity modulus -/ open Filter Topology Uniformity variable {α β ι : Type*} [PseudoMetricSpace α] namespace Metric /-- Characterization of equicontinuity for families of functions taking values in a (pseudo) metric space. -/ theorem equicontinuousAt_iff_right {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {x₀ : β} : EquicontinuousAt F x₀ ↔ ∀ ε > 0, ∀ᶠ x in 𝓝 x₀, ∀ i, dist (F i x₀) (F i x) < ε := uniformity_basis_dist.equicontinuousAt_iff_right /-- Characterization of equicontinuity for families of functions between (pseudo) metric spaces. -/ theorem equicontinuousAt_iff {ι : Type*} [PseudoMetricSpace β] {F : ι → β → α} {x₀ : β} : EquicontinuousAt F x₀ ↔ ∀ ε > 0, ∃ δ > 0, ∀ x, dist x x₀ < δ → ∀ i, dist (F i x₀) (F i x) < ε := nhds_basis_ball.equicontinuousAt_iff uniformity_basis_dist /-- Reformulation of `equicontinuousAt_iff_pair` for families of functions taking values in a (pseudo) metric space. -/ protected theorem equicontinuousAt_iff_pair {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {x₀ : β} : EquicontinuousAt F x₀ ↔ ∀ ε > 0, ∃ U ∈ 𝓝 x₀, ∀ x ∈ U, ∀ x' ∈ U, ∀ i, dist (F i x) (F i x') < ε := by rw [equicontinuousAt_iff_pair] constructor <;> intro H · intro ε hε exact H _ (dist_mem_uniformity hε) · intro U hU rcases mem_uniformity_dist.mp hU with ⟨ε, hε, hεU⟩ refine Exists.imp (fun V => And.imp_right fun h => ?_) (H _ hε) exact fun x hx x' hx' i => hεU (h _ hx _ hx' i) /-- Characterization of uniform equicontinuity for families of functions taking values in a (pseudo) metric space. -/ theorem uniformEquicontinuous_iff_right {ι : Type*} [UniformSpace β] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ ε > 0, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, dist (F i xy.1) (F i xy.2) < ε := uniformity_basis_dist.uniformEquicontinuous_iff_right /-- Characterization of uniform equicontinuity for families of functions between (pseudo) metric spaces. -/ theorem uniformEquicontinuous_iff {ι : Type*} [PseudoMetricSpace β] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ ε > 0, ∃ δ > 0, ∀ x y, dist x y < δ → ∀ i, dist (F i x) (F i y) < ε := uniformity_basis_dist.uniformEquicontinuous_iff uniformity_basis_dist /-- For a family of functions to a (pseudo) metric spaces, a convenient way to prove equicontinuity at a point is to show that all of the functions share a common *local* continuity modulus. -/ theorem equicontinuousAt_of_continuity_modulus {ι : Type*} [TopologicalSpace β] {x₀ : β} (b : β → ℝ) (b_lim : Tendsto b (𝓝 x₀) (𝓝 0)) (F : ι → β → α) (H : ∀ᶠ x in 𝓝 x₀, ∀ i, dist (F i x₀) (F i x) ≤ b x) : EquicontinuousAt F x₀ := by rw [Metric.equicontinuousAt_iff_right] intro ε ε0 filter_upwards [b_lim (Iio_mem_nhds ε0), H] using fun x hx₁ hx₂ i => (hx₂ i).trans_lt hx₁ /-- For a family of functions between (pseudo) metric spaces, a convenient way to prove uniform equicontinuity is to show that all of the functions share a common *global* continuity modulus. -/ theorem uniformEquicontinuous_of_continuity_modulus {ι : Type*} [PseudoMetricSpace β] (b : ℝ → ℝ) (b_lim : Tendsto b (𝓝 0) (𝓝 0)) (F : ι → β → α) (H : ∀ (x y : β) (i), dist (F i x) (F i y) ≤ b (dist x y)) : UniformEquicontinuous F := by rw [Metric.uniformEquicontinuous_iff] intro ε ε0 rcases tendsto_nhds_nhds.1 b_lim ε ε0 with ⟨δ, δ0, hδ⟩ refine ⟨δ, δ0, fun x y hxy i => ?_⟩ calc dist (F i x) (F i y) ≤ b (dist x y) := H x y i _ ≤ |b (dist x y)| := le_abs_self _ _ = dist (b (dist x y)) 0 := by simp [Real.dist_eq] _ < ε := hδ (by simpa only [Real.dist_eq, tsub_zero, abs_dist] using hxy) /-- For a family of functions between (pseudo) metric spaces, a convenient way to prove equicontinuity is to show that all of the functions share a common *global* continuity modulus. -/ theorem equicontinuous_of_continuity_modulus {ι : Type*} [PseudoMetricSpace β] (b : ℝ → ℝ) (b_lim : Tendsto b (𝓝 0) (𝓝 0)) (F : ι → β → α) (H : ∀ (x y : β) (i), dist (F i x) (F i y) ≤ b (dist x y)) : Equicontinuous F := (uniformEquicontinuous_of_continuity_modulus b b_lim F H).equicontinuous end Metric
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/HausdorffDistance.lean
import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Tactic.Finiteness /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point of `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This file introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β} /-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : α) (s : Set α) : ℝ≥0∞ := ⨅ y ∈ s, edist x y @[simp] theorem infEdist_empty : infEdist x ∅ = ∞ := iInf_emptyset theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by simp only [infEdist, le_iInf_iff] /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t := iInf_union @[simp] theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) := iInf_iUnion f _ lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) : infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y := iInf₂_le y h /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h /-- The edist is antitone with respect to inclusion. -/ @[gcongr] theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s := iInf_le_iInf_of_subset h /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y := calc ⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y := iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInf₂ fun i hi => ?_ calc edist x y ≤ edist x i + edist i y := edist_triangle _ _ _ _ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) /-- The edist to a set depends continuously on the point -/ @[continuity, fun_prop] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff] /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_ have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 := ENNReal.lt_add_right h.ne ε0.ne' obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0 calc infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves] /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩ /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_notMem_closure {x : α} {E : Set α} : 0 < infEdist x E ↔ x ∉ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] @[deprecated (since := "2025-05-23")] alias infEdist_pos_iff_not_mem_closure := infEdist_pos_iff_notMem_closure theorem infEdist_closure_pos_iff_notMem_closure {x : α} {E : Set α} : 0 < infEdist x (closure E) ↔ x ∉ closure E := by rw [infEdist_closure, infEdist_pos_iff_notMem_closure] @[deprecated (since := "2025-05-23")] alias infEdist_closure_pos_iff_not_mem_closure := infEdist_closure_pos_iff_notMem_closure theorem exists_real_pos_lt_infEdist_of_notMem_closure {x : α} {E : Set α} (h : x ∉ closure E) : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by rw [← infEdist_pos_iff_notMem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩ exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩ @[deprecated (since := "2025-05-23")] alias exists_real_pos_lt_infEdist_of_not_mem_closure := exists_real_pos_lt_infEdist_of_notMem_closure theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y _ ≤ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΦ.edist_eq] @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) : infEdist (c • x) (c • s) = infEdist x s := infEdist_image (isometry_smul _ _) theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) : ∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n) have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by by_contra h have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ · show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : x ∉ Uᶜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊢ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : ∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) · use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩ exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ theorem infEdist_prod (x : α × β) (s : Set α) (t : Set β) : infEdist x (s ×ˢ t) = max (infEdist x.1 s) (infEdist x.2 t) := by simp_rw +singlePass [infEdist, Prod.edist_eq, iInf_prod, Set.mem_prod, iInf_and, iInf_sup_eq, sup_iInf_eq, iInf_sup_eq, sup_iInf_eq] end InfEdist /-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ := (⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s section HausdorffEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t u : Set α} {Φ : α → β} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx /-- The Hausdorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r) (H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) · rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy · rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSup₂ (α := ℝ≥0∞) x h /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : ∃ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≤ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun ε εpos h => by have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos have : infEdist x s < infEdist x s + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0 obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0 obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + ε := by simp [ENNReal.add_halves, add_comm, add_left_comm] /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Φ) : hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ · intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor · change ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≤ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist s t + hausdorffEdist t u := by grw [infEdist_le_hausdorffEdist_of_mem xs] · change ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≤ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist u t + hausdorffEdist t s := by grw [infEdist_le_hausdorffEdist_of_mem xu] _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.max_eq_zero_iff, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ · calc _ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] · calc _ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] /-- The Hausdorff edistance between sets or their closures is the same. -/ theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/ theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq] /-- The Hausdorff edistance to the empty set is infinite. -/ theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by rcases ne with ⟨x, xs⟩ have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs simpa using this /-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/ theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) : t.Nonempty := t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs) theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) : (s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by rcases s.eq_empty_or_nonempty with hs | hs · rcases t.eq_empty_or_nonempty with ht | ht · exact Or.inl ⟨hs, ht⟩ · rw [hausdorffEdist_comm] at fin exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩ · exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩ @[simp] theorem hausdorffEdist_singleton : hausdorffEdist {x} {y} = edist x y := by simp_rw [hausdorffEdist, iSup_singleton, infEdist_singleton] nth_rw 2 [edist_comm] exact max_self _ theorem hausdorffEdist_iUnion_le {ι : Sort*} {s t : ι → Set α} : hausdorffEdist (⋃ i, s i) (⋃ i, t i) ≤ ⨆ i, hausdorffEdist (s i) (t i) := by simp_rw [hausdorffEdist, max_le_iff, iSup_iUnion, iSup_le_iff, infEdist_iUnion] constructor <;> refine fun i x hx => (iInf_le _ i).trans <| le_iSup_of_le i ?_ · exact le_max_of_le_left <| le_iSup₂_of_le x hx le_rfl · exact le_max_of_le_right <| le_iSup₂_of_le x hx le_rfl theorem hausdorffEdist_union_le {s₁ s₂ t₁ t₂ : Set α} : hausdorffEdist (s₁ ∪ s₂) (t₁ ∪ t₂) ≤ max (hausdorffEdist s₁ t₁) (hausdorffEdist s₂ t₂) := by simp_rw [union_eq_iUnion, sup_eq_iSup] convert hausdorffEdist_iUnion_le with (_ | _) theorem hausdorffEdist_prod_le {s₁ t₁ : Set α} {s₂ t₂ : Set β} : hausdorffEdist (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) ≤ max (hausdorffEdist s₁ t₁) (hausdorffEdist s₂ t₂) := by refine le_of_forall_ge fun _ _ => ?_ simp_all only [hausdorffEdist, infEdist_prod, max_le_iff, iSup_le_iff, mem_prod, true_and, implies_true] end HausdorffEdist -- section end EMetric /-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to `sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞` formulated in terms of the edistance, and coerce them to `ℝ`. Then their properties follow readily from the corresponding properties in `ℝ≥0∞`, modulo some tedious rewriting of inequalities from one to the other. -/ --namespace namespace Metric section variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β} open EMetric /-! ### Distance of a point to a set as a function into `ℝ`. -/ /-- The minimal distance of a point to a set -/ def infDist (x : α) (s : Set α) : ℝ := ENNReal.toReal (infEdist x s) theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf] · simp only [dist_edist] · finiteness /-- The minimal distance is always nonnegative -/ theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg /-- The minimal distance to the empty set is 0 (if you want to have the more reasonable value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/ @[simp] theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist] lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x ·) '' s) (infDist x s) := by simpa [infDist_eq_iInf, sInf_image'] using isGLB_csInf (hs.image _) ⟨0, by simp [lowerBounds]⟩ /-- In a metric space, the minimal edistance to a nonempty set is finite. -/ theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by rcases h with ⟨y, hy⟩ exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy) @[simp] theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top] /-- The minimal distance of a point to a set containing it vanishes. -/ theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by simp [infEdist_zero_of_mem h, infDist] /-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/ @[simp] theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist] /-- The minimal distance to a set is bounded by the distance to any point in this set. -/ theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by rw [dist_edist, infDist] exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h) /-- The minimal distance is monotone with respect to inclusion. -/ theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s := ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h) lemma le_infDist {r : ℝ} (hs : s.Nonempty) : r ≤ infDist x s ↔ ∀ ⦃y⦄, y ∈ s → r ≤ dist x y := by simp_rw [infDist, ← ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist, ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), ← dist_edist] /-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/ theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by simp [← not_le, le_infDist hs] /-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo the distance between `x` and `y`. -/ theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by rw [infDist, infDist, dist_edist] refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _)) simp only [infEdist_eq_top_iff, imp_self] theorem notMem_of_dist_lt_infDist (h : dist x y < infDist x s) : y ∉ s := fun hy => h.not_ge <| infDist_le_dist_of_mem hy @[deprecated (since := "2025-05-23")] alias not_mem_of_dist_lt_infDist := notMem_of_dist_lt_infDist theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s := disjoint_left.2 fun _y hy => notMem_of_dist_lt_infDist <| mem_ball'.1 hy theorem ball_infDist_subset_compl : ball x (infDist x s) ⊆ sᶜ := (disjoint_ball_infDist (s := s)).subset_compl_right theorem ball_infDist_compl_subset : ball x (infDist x sᶜ) ⊆ s := ball_infDist_subset_compl.trans_eq (compl_compl s) theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) : Disjoint (closedBall x r) s := disjoint_ball_infDist.mono_left <| closedBall_subset_ball h theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) : dist x y ≤ infDist x s + diam s := by rw [infDist, diam, dist_edist] exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top variable (s) /-- The minimal distance to a set is Lipschitz in point with constant 1 -/ theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist · s) := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set is uniformly continuous in point -/ theorem uniformContinuous_infDist_pt : UniformContinuous (infDist · s) := (lipschitz_infDist_pt s).uniformContinuous /-- The minimal distance to a set is continuous in point -/ @[continuity, fun_prop] theorem continuous_infDist_pt : Continuous (infDist · s) := (uniformContinuous_infDist_pt s).continuous variable {s} /-- The minimal distances to a set and its closure coincide. -/ theorem infDist_closure : infDist x (closure s) = infDist x s := by simp [infDist, infEdist_closure] /-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero. The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/ theorem infDist_zero_of_mem_closure (hx : x ∈ closure s) : infDist x s = 0 := by rw [← infDist_closure] exact infDist_zero_of_mem hx /-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes. -/ theorem mem_closure_iff_infDist_zero (h : s.Nonempty) : x ∈ closure s ↔ infDist x s = 0 := by simp [mem_closure_iff_infEdist_zero, infDist, ENNReal.toReal_eq_zero_iff, infEdist_ne_top h] theorem infDist_pos_iff_notMem_closure (hs : s.Nonempty) : x ∉ closure s ↔ 0 < infDist x s := (mem_closure_iff_infDist_zero hs).not.trans infDist_nonneg.lt_iff_ne'.symm @[deprecated (since := "2025-05-23")] alias infDist_pos_iff_not_mem_closure := infDist_pos_iff_notMem_closure /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/ theorem _root_.IsClosed.mem_iff_infDist_zero (h : IsClosed s) (hs : s.Nonempty) : x ∈ s ↔ infDist x s = 0 := by rw [← mem_closure_iff_infDist_zero hs, h.closure_eq] /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes. -/ theorem _root_.IsClosed.notMem_iff_infDist_pos (h : IsClosed s) (hs : s.Nonempty) : x ∉ s ↔ 0 < infDist x s := by simp [h.mem_iff_infDist_zero hs, infDist_nonneg.lt_iff_ne'] @[deprecated (since := "2025-05-23")] alias _root_.IsClosed.not_mem_iff_infDist_pos := _root_.IsClosed.notMem_iff_infDist_pos theorem continuousAt_inv_infDist_pt (h : x ∉ closure s) : ContinuousAt (fun x ↦ (infDist x s)⁻¹) x := by rcases s.eq_empty_or_nonempty with (rfl | hs) · simp only [infDist_empty, continuousAt_const] · refine (continuous_infDist_pt s).continuousAt.inv₀ ?_ rwa [Ne, ← mem_closure_iff_infDist_zero hs] /-- The infimum distance is invariant under isometries. -/ theorem infDist_image (hΦ : Isometry Φ) : infDist (Φ x) (Φ '' t) = infDist x t := by simp [infDist, infEdist_image hΦ] theorem infDist_inter_closedBall_of_mem (h : y ∈ s) : infDist x (s ∩ closedBall x (dist y x)) = infDist x s := by replace h : y ∈ s ∩ closedBall x (dist y x) := ⟨h, mem_closedBall.2 le_rfl⟩ refine le_antisymm ?_ (infDist_le_infDist_of_subset inter_subset_left ⟨y, h⟩) refine not_lt.1 fun hlt => ?_ rcases (infDist_lt_iff ⟨y, h.1⟩).mp hlt with ⟨z, hzs, hz⟩ rcases le_or_gt (dist z x) (dist y x) with hle | hlt · exact hz.not_ge (infDist_le_dist_of_mem ⟨hzs, hle⟩) · rw [dist_comm z, dist_comm y] at hlt exact (hlt.trans hz).not_ge (infDist_le_dist_of_mem h) theorem _root_.IsCompact.exists_infDist_eq_dist (h : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := let ⟨y, hys, hy⟩ := h.exists_infEdist_eq_edist hne x ⟨y, hys, by rw [infDist, dist_edist, hy]⟩ theorem _root_.IsClosed.exists_infDist_eq_dist [ProperSpace α] (h : IsClosed s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := by rcases hne with ⟨z, hz⟩ rw [← infDist_inter_closedBall_of_mem hz] set t := s ∩ closedBall x (dist z x) have htc : IsCompact t := (isCompact_closedBall x (dist z x)).inter_left h have htne : t.Nonempty := ⟨z, hz, mem_closedBall.2 le_rfl⟩ obtain ⟨y, ⟨hys, -⟩, hyd⟩ : ∃ y ∈ t, infDist x t = dist x y := htc.exists_infDist_eq_dist htne x exact ⟨y, hys, hyd⟩ theorem exists_mem_closure_infDist_eq_dist [ProperSpace α] (hne : s.Nonempty) (x : α) : ∃ y ∈ closure s, infDist x s = dist x y := by simpa only [infDist_closure] using isClosed_closure.exists_infDist_eq_dist hne.closure x /-! ### Distance of a point to a set as a function into `ℝ≥0`. -/ /-- The minimal distance of a point to a set as a `ℝ≥0` -/ def infNndist (x : α) (s : Set α) : ℝ≥0 := ENNReal.toNNReal (infEdist x s) @[simp] theorem coe_infNndist : (infNndist x s : ℝ) = infDist x s := rfl /-- The minimal distance to a set (as `ℝ≥0`) is Lipschitz in point with constant 1 -/ theorem lipschitz_infNndist_pt (s : Set α) : LipschitzWith 1 fun x => infNndist x s := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set (as `ℝ≥0`) is uniformly continuous in point -/ theorem uniformContinuous_infNndist_pt (s : Set α) : UniformContinuous fun x => infNndist x s := (lipschitz_infNndist_pt s).uniformContinuous /-- The minimal distance to a set (as `ℝ≥0`) is continuous in point -/ @[continuity, fun_prop] theorem continuous_infNndist_pt (s : Set α) : Continuous fun x => infNndist x s := (uniformContinuous_infNndist_pt s).continuous /-! ### The Hausdorff distance as a function into `ℝ`. -/ /-- The Hausdorff distance between two sets is the smallest nonnegative `r` such that each set is included in the `r`-neighborhood of the other. If there is no such `r`, it is defined to be `0`, arbitrarily. -/ def hausdorffDist (s t : Set α) : ℝ := ENNReal.toReal (hausdorffEdist s t) /-- The Hausdorff distance is nonnegative. -/ theorem hausdorffDist_nonneg : 0 ≤ hausdorffDist s t := by simp [hausdorffDist] /-- If two sets are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. -/ theorem hausdorffEdist_ne_top_of_nonempty_of_bounded (hs : s.Nonempty) (ht : t.Nonempty) (bs : IsBounded s) (bt : IsBounded t) : hausdorffEdist s t ≠ ⊤ := by rcases hs with ⟨cs, hcs⟩ rcases ht with ⟨ct, hct⟩ rcases bs.subset_closedBall ct with ⟨rs, hrs⟩ rcases bt.subset_closedBall cs with ⟨rt, hrt⟩ have : hausdorffEdist s t ≤ ENNReal.ofReal (max rs rt) := by apply hausdorffEdist_le_of_mem_edist · intro x xs exists ct, hct have : dist x ct ≤ max rs rt := le_trans (hrs xs) (le_max_left _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this · intro x xt exists cs, hcs have : dist x cs ≤ max rs rt := le_trans (hrt xt) (le_max_right _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this exact ne_top_of_le_ne_top ENNReal.ofReal_ne_top this /-- The Hausdorff distance between a set and itself is zero. -/ @[simp] theorem hausdorffDist_self_zero : hausdorffDist s s = 0 := by simp [hausdorffDist] /-- The Hausdorff distances from `s` to `t` and from `t` to `s` coincide. -/ theorem hausdorffDist_comm : hausdorffDist s t = hausdorffDist t s := by simp [hausdorffDist, hausdorffEdist_comm] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝ≥0∞`). -/ @[simp] theorem hausdorffDist_empty : hausdorffDist s ∅ = 0 := by rcases s.eq_empty_or_nonempty with h | h · simp [h] · simp [hausdorffDist, hausdorffEdist_empty h] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝ≥0∞`). -/ @[simp] theorem hausdorffDist_empty' : hausdorffDist ∅ s = 0 := by simp [hausdorffDist_comm] /-- Bounding the Hausdorff distance by bounding the distance of any point in each set to the other set -/ theorem hausdorffDist_le_of_infDist {r : ℝ} (hr : 0 ≤ r) (H1 : ∀ x ∈ s, infDist x t ≤ r) (H2 : ∀ x ∈ t, infDist x s ≤ r) : hausdorffDist s t ≤ r := by rcases s.eq_empty_or_nonempty with hs | hs · rwa [hs, hausdorffDist_empty'] rcases t.eq_empty_or_nonempty with ht | ht · rwa [ht, hausdorffDist_empty] have : hausdorffEdist s t ≤ ENNReal.ofReal r := by apply hausdorffEdist_le_of_infEdist _ _ · simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top ht) hr] using H1 · simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top hs) hr] using H2 exact ENNReal.toReal_le_of_le_ofReal hr this /-- Bounding the Hausdorff distance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffDist_le_of_mem_dist {r : ℝ} (hr : 0 ≤ r) (H1 : ∀ x ∈ s, ∃ y ∈ t, dist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, dist x y ≤ r) : hausdorffDist s t ≤ r := by apply hausdorffDist_le_of_infDist hr · intro x xs rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infDist_le_dist_of_mem yt) hy · intro x xt rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infDist_le_dist_of_mem ys) hy /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffDist_le_diam (hs : s.Nonempty) (bs : IsBounded s) (ht : t.Nonempty) (bt : IsBounded t) : hausdorffDist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffDist_le_of_mem_dist diam_nonneg ?_ ?_ · exact fun z hz => ⟨y, yt, dist_le_diam_of_mem (bs.union bt) (subset_union_left hz) (subset_union_right yt)⟩ · exact fun z hz => ⟨x, xs, dist_le_diam_of_mem (bs.union bt) (subset_union_right hz) (subset_union_left xs)⟩ /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infDist_le_hausdorffDist_of_mem (hx : x ∈ s) (fin : hausdorffEdist s t ≠ ⊤) : infDist x t ≤ hausdorffDist s t := toReal_mono fin (infEdist_le_hausdorffEdist_of_mem hx) /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt {r : ℝ} (h : x ∈ s) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t ≠ ⊤) : ∃ y ∈ t, dist x y < r := by have r0 : 0 < r := lt_of_le_of_lt hausdorffDist_nonneg H have : hausdorffEdist s t < ENNReal.ofReal r := by rwa [hausdorffDist, ← ENNReal.toReal_ofReal (le_of_lt r0), ENNReal.toReal_lt_toReal fin ENNReal.ofReal_ne_top] at H rcases exists_edist_lt_of_hausdorffEdist_lt h this with ⟨y, hy, yr⟩ rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff r0] at yr exact ⟨y, hy, yr⟩ /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt' {r : ℝ} (h : y ∈ t) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t ≠ ⊤) : ∃ x ∈ s, dist x y < r := by rw [hausdorffDist_comm] at H rw [hausdorffEdist_comm] at fin simpa [dist_comm] using exists_dist_lt_of_hausdorffDist_lt h H fin /-- The infimum distance to `s` and `t` are the same, up to the Hausdorff distance between `s` and `t` -/ theorem infDist_le_infDist_add_hausdorffDist (fin : hausdorffEdist s t ≠ ⊤) : infDist x t ≤ infDist x s + hausdorffDist s t := by refine toReal_le_add' infEdist_le_infEdist_add_hausdorffEdist (fun h ↦ ?_) (flip absurd fin) rw [infEdist_eq_top_iff, ← not_nonempty_iff_eq_empty] at h ⊢ rw [hausdorffEdist_comm] at fin exact mt (nonempty_of_hausdorffEdist_ne_top · fin) h /-- The Hausdorff distance is invariant under isometries. -/ theorem hausdorffDist_image (h : Isometry Φ) : hausdorffDist (Φ '' s) (Φ '' t) = hausdorffDist s t := by simp [hausdorffDist, hausdorffEdist_image h] /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffDist_triangle (fin : hausdorffEdist s t ≠ ⊤) : hausdorffDist s u ≤ hausdorffDist s t + hausdorffDist t u := by refine toReal_le_add' hausdorffEdist_triangle (flip absurd fin) (not_imp_not.1 fun h ↦ ?_) rw [hausdorffEdist_comm] at fin exact ne_top_of_le_ne_top (add_ne_top.2 ⟨fin, h⟩) hausdorffEdist_triangle /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffDist_triangle' (fin : hausdorffEdist t u ≠ ⊤) : hausdorffDist s u ≤ hausdorffDist s t + hausdorffDist t u := by rw [hausdorffEdist_comm] at fin have I : hausdorffDist u s ≤ hausdorffDist u t + hausdorffDist t s := hausdorffDist_triangle fin simpa [add_comm, hausdorffDist_comm] using I /-- The Hausdorff distance between a set and its closure vanishes. -/ @[simp] theorem hausdorffDist_self_closure : hausdorffDist s (closure s) = 0 := by simp [hausdorffDist] /-- Replacing a set by its closure does not change the Hausdorff distance. -/ @[simp] theorem hausdorffDist_closure₁ : hausdorffDist (closure s) t = hausdorffDist s t := by simp [hausdorffDist] /-- Replacing a set by its closure does not change the Hausdorff distance. -/ @[simp] theorem hausdorffDist_closure₂ : hausdorffDist s (closure t) = hausdorffDist s t := by simp [hausdorffDist] /-- The Hausdorff distances between two sets and their closures coincide. -/ theorem hausdorffDist_closure : hausdorffDist (closure s) (closure t) = hausdorffDist s t := by simp [hausdorffDist] /-- Two sets are at zero Hausdorff distance if and only if they have the same closures. -/ theorem hausdorffDist_zero_iff_closure_eq_closure (fin : hausdorffEdist s t ≠ ⊤) : hausdorffDist s t = 0 ↔ closure s = closure t := by simp [← hausdorffEdist_zero_iff_closure_eq_closure, hausdorffDist, ENNReal.toReal_eq_zero_iff, fin] /-- Two closed sets are at zero Hausdorff distance if and only if they coincide. -/ theorem _root_.IsClosed.hausdorffDist_zero_iff_eq (hs : IsClosed s) (ht : IsClosed t) (fin : hausdorffEdist s t ≠ ⊤) : hausdorffDist s t = 0 ↔ s = t := by simp [← hausdorffEdist_zero_iff_eq_of_closed hs ht, hausdorffDist, ENNReal.toReal_eq_zero_iff, fin] @[simp] theorem hausdorffDist_singleton : hausdorffDist {x} {y} = dist x y := by rw [hausdorffDist, hausdorffEdist_singleton, dist_edist] end end Metric
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Congruence.lean
import Mathlib.Topology.MetricSpace.Pseudo.Defs /-! # Congruences This file defines `Congruent`, i.e., the equivalence between indexed families of points in a metric space where all corresponding pairwise distances are the same. The motivating example are triangles in the plane. ## Implementation notes After considering two possible approaches to defining congruence — either based on equal pairwise distances or the existence of an isometric equivalence — we have opted for the broader concept of equal pairwise distances. This notion is commonly employed in the literature across various metric spaces that lack an isometric equivalence. For more details see the [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Euclidean.20Geometry). ## Notation * `v₁ ≅ v₂`: for `Congruent v₁ v₂`. -/ variable {ι ι' : Type*} {P₁ P₂ P₃ : Type*} {v₁ : ι → P₁} {v₂ : ι → P₂} {v₃ : ι → P₃} section PseudoEMetricSpace variable [PseudoEMetricSpace P₁] [PseudoEMetricSpace P₂] [PseudoEMetricSpace P₃] /-- A congruence between indexed sets of vertices v₁ and v₂. Use `open scoped Congruent` to access the `v₁ ≅ v₂` notation. -/ def Congruent (v₁ : ι → P₁) (v₂ : ι → P₂) : Prop := ∀ i₁ i₂, edist (v₁ i₁) (v₁ i₂) = edist (v₂ i₁) (v₂ i₂) @[inherit_doc] scoped[Congruent] infixl:25 " ≅ " => Congruent /-- Congruence holds if and only if all extended distances are the same. -/ lemma congruent_iff_edist_eq : Congruent v₁ v₂ ↔ ∀ i₁ i₂, edist (v₁ i₁) (v₁ i₂) = edist (v₂ i₁) (v₂ i₂) := Iff.rfl /-- Congruence holds if and only if all extended distances between points with different indices are the same. -/ lemma congruent_iff_pairwise_edist_eq : Congruent v₁ v₂ ↔ Pairwise fun i₁ i₂ ↦ edist (v₁ i₁) (v₁ i₂) = edist (v₂ i₁) (v₂ i₂) := by refine ⟨fun h ↦ fun _ _ _ ↦ h _ _, fun h ↦ fun i₁ i₂ ↦ ?_⟩ by_cases hi : i₁ = i₂ · simp [hi] · exact h hi namespace Congruent /-- A congruence preserves extended distance. Forward direction of `congruent_iff_edist_eq`. -/ alias ⟨edist_eq, _⟩ := congruent_iff_edist_eq /-- Congruence follows from preserved extended distance. Backward direction of `congruent_iff_edist_eq`. -/ alias ⟨_, of_edist_eq⟩ := congruent_iff_edist_eq /-- A congruence pairwise preserves extended distance. Forward direction of `congruent_iff_pairwise_edist_eq`. -/ alias ⟨pairwise_edist_eq, _⟩ := congruent_iff_pairwise_edist_eq /-- Congruence follows from pairwise preserved extended distance. Backward direction of `congruent_iff_pairwise_edist_eq`. -/ alias ⟨_, of_pairwise_edist_eq⟩ := congruent_iff_pairwise_edist_eq @[refl] protected lemma refl (v₁ : ι → P₁) : v₁ ≅ v₁ := fun _ _ ↦ rfl @[symm] protected lemma symm (h : v₁ ≅ v₂) : v₂ ≅ v₁ := fun i₁ i₂ ↦ (h i₁ i₂).symm lemma _root_.congruent_comm : v₁ ≅ v₂ ↔ v₂ ≅ v₁ := ⟨Congruent.symm, Congruent.symm⟩ @[trans] protected lemma trans (h₁₂ : v₁ ≅ v₂) (h₂₃ : v₂ ≅ v₃) : v₁ ≅ v₃ := fun i₁ i₂ ↦ (h₁₂ i₁ i₂).trans (h₂₃ i₁ i₂) /-- Change the index set ι to an index ι' that maps to ι. -/ lemma index_map (h : v₁ ≅ v₂) (f : ι' → ι) : (v₁ ∘ f) ≅ (v₂ ∘ f) := fun i₁ i₂ ↦ edist_eq h (f i₁) (f i₂) /-- Change between equivalent index sets ι and ι'. -/ @[simp] lemma index_equiv {E : Type*} [EquivLike E ι' ι] (f : E) (v₁ : ι → P₁) (v₂ : ι → P₂) : v₁ ∘ f ≅ v₂ ∘ f ↔ v₁ ≅ v₂ := by refine ⟨fun h i₁ i₂ ↦ ?_, fun h ↦ index_map h f⟩ simpa [(EquivLike.toEquiv f).right_inv i₁, (EquivLike.toEquiv f).right_inv i₂] using edist_eq h ((EquivLike.toEquiv f).symm i₁) ((EquivLike.toEquiv f).symm i₂) end Congruent end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace P₁] [PseudoMetricSpace P₂] /-- Congruence holds if and only if all non-negative distances are the same. -/ lemma congruent_iff_nndist_eq : Congruent v₁ v₂ ↔ ∀ i₁ i₂, nndist (v₁ i₁) (v₁ i₂) = nndist (v₂ i₁) (v₂ i₂) := forall₂_congr (fun _ _ ↦ by rw [edist_nndist, edist_nndist]; norm_cast) /-- Congruence holds if and only if all non-negative distances between points with different indices are the same. -/ lemma congruent_iff_pairwise_nndist_eq : Congruent v₁ v₂ ↔ Pairwise fun i₁ i₂ ↦ nndist (v₁ i₁) (v₁ i₂) = nndist (v₂ i₁) (v₂ i₂) := by simp_rw [congruent_iff_pairwise_edist_eq, edist_nndist] exact_mod_cast Iff.rfl /-- Congruence holds if and only if all distances are the same. -/ lemma congruent_iff_dist_eq : Congruent v₁ v₂ ↔ ∀ i₁ i₂, dist (v₁ i₁) (v₁ i₂) = dist (v₂ i₁) (v₂ i₂) := congruent_iff_nndist_eq.trans (forall₂_congr (fun _ _ ↦ by rw [dist_nndist, dist_nndist]; norm_cast)) /-- Congruence holds if and only if all non-negative distances between points with different indices are the same. -/ lemma congruent_iff_pairwise_dist_eq : Congruent v₁ v₂ ↔ Pairwise fun i₁ i₂ ↦ dist (v₁ i₁) (v₁ i₂) = dist (v₂ i₁) (v₂ i₂) := by simp_rw [congruent_iff_pairwise_nndist_eq, dist_nndist] exact_mod_cast Iff.rfl namespace Congruent /-- A congruence preserves non-negative distance. Forward direction of `congruent_iff_nndist_eq`. -/ alias ⟨nndist_eq, _⟩ := congruent_iff_nndist_eq /-- Congruence follows from preserved non-negative distance. Backward direction of `congruent_iff_nndist_eq`. -/ alias ⟨_, of_nndist_eq⟩ := congruent_iff_nndist_eq /-- A congruence preserves distance. Forward direction of `congruent_iff_dist_eq`. -/ alias ⟨dist_eq, _⟩ := congruent_iff_dist_eq /-- Congruence follows from preserved distance. Backward direction of `congruent_iff_dist_eq`. -/ alias ⟨_, of_dist_eq⟩ := congruent_iff_dist_eq /-- A congruence pairwise preserves non-negative distance. Forward direction of `congruent_iff_pairwise_nndist_eq`. -/ alias ⟨pairwise_nndist_eq, _⟩ := congruent_iff_pairwise_nndist_eq /-- Congruence follows from pairwise preserved non-negative distance. Backward direction of `congruent_iff_pairwise_nndist_eq`. -/ alias ⟨_, of_pairwise_nndist_eq⟩ := congruent_iff_pairwise_nndist_eq /-- A congruence pairwise preserves distance. Forward direction of `congruent_iff_pairwise_dist_eq`. -/ alias ⟨pairwise_dist_eq, _⟩ := congruent_iff_pairwise_dist_eq /-- Congruence follows from pairwise preserved distance. Backward direction of `congruent_iff_pairwise_dist_eq`. -/ alias ⟨_, of_pairwise_dist_eq⟩ := congruent_iff_pairwise_dist_eq end Congruent end PseudoMetricSpace
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Algebra.lean
import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.Algebra.Order.Field import Mathlib.Topology.Algebra.SeparationQuotient.Basic import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.MetricSpace.Lipschitz /-! # Compatibility of algebraic operations with metric space structures In this file we define mixin typeclasses `LipschitzMul`, `LipschitzAdd`, `IsBoundedSMul` expressing compatibility of multiplication, addition and scalar-multiplication operations with an underlying metric space structure. The intended use case is to abstract certain properties shared by normed groups and by `R≥0`. ## Implementation notes We deduce a `ContinuousMul` instance from `LipschitzMul`, etc. In principle there should be an intermediate typeclass for uniform spaces, but the algebraic hierarchy there (see `IsUniformGroup`) is structured differently. -/ open NNReal noncomputable section variable (α β : Type*) [PseudoMetricSpace α] [PseudoMetricSpace β] section LipschitzMul /-- Class `LipschitzAdd M` says that the addition `(+) : X × X → X` is Lipschitz jointly in the two arguments. -/ class LipschitzAdd [AddMonoid β] : Prop where lipschitz_add : ∃ C, LipschitzWith C fun p : β × β => p.1 + p.2 /-- Class `LipschitzMul M` says that the multiplication `(*) : X × X → X` is Lipschitz jointly in the two arguments. -/ @[to_additive] class LipschitzMul [Monoid β] : Prop where lipschitz_mul : ∃ C, LipschitzWith C fun p : β × β => p.1 * p.2 variable [Monoid β] /-- The Lipschitz constant of a monoid `β` satisfying `LipschitzMul` -/ @[to_additive /-- The Lipschitz constant of an `AddMonoid` `β` satisfying `LipschitzAdd` -/] def LipschitzMul.C [_i : LipschitzMul β] : ℝ≥0 := Classical.choose _i.lipschitz_mul variable {β} @[to_additive] theorem lipschitzWith_lipschitz_const_mul_edist [_i : LipschitzMul β] : LipschitzWith (LipschitzMul.C β) fun p : β × β => p.1 * p.2 := Classical.choose_spec _i.lipschitz_mul variable [LipschitzMul β] @[to_additive] theorem lipschitz_with_lipschitz_const_mul : ∀ p q : β × β, dist (p.1 * p.2) (q.1 * q.2) ≤ LipschitzMul.C β * dist p q := by rw [← lipschitzWith_iff_dist_le_mul] exact lipschitzWith_lipschitz_const_mul_edist -- see Note [lower instance priority] @[to_additive] instance (priority := 100) LipschitzMul.continuousMul : ContinuousMul β := ⟨lipschitzWith_lipschitz_const_mul_edist.continuous⟩ @[to_additive] instance Submonoid.lipschitzMul (s : Submonoid β) : LipschitzMul s where lipschitz_mul := ⟨LipschitzMul.C β, by rintro ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ convert lipschitzWith_lipschitz_const_mul_edist ⟨(x₁ : β), x₂⟩ ⟨y₁, y₂⟩ using 1⟩ @[to_additive] instance MulOpposite.lipschitzMul : LipschitzMul βᵐᵒᵖ where lipschitz_mul := ⟨LipschitzMul.C β, fun ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ => (lipschitzWith_lipschitz_const_mul_edist ⟨x₂.unop, x₁.unop⟩ ⟨y₂.unop, y₁.unop⟩).trans_eq (congr_arg _ <| max_comm _ _)⟩ -- this instance could be deduced from `NormedAddCommGroup.lipschitzAdd`, but we prove it -- separately here so that it is available earlier in the hierarchy instance Real.hasLipschitzAdd : LipschitzAdd ℝ where lipschitz_add := ⟨2, LipschitzWith.of_dist_le_mul fun p q => by simp only [Real.dist_eq, Prod.dist_eq, NNReal.coe_ofNat, add_sub_add_comm, two_mul] refine le_trans (abs_add_le (p.1 - q.1) (p.2 - q.2)) ?_ exact add_le_add (le_max_left _ _) (le_max_right _ _)⟩ -- this instance has the same proof as `AddSubmonoid.lipschitzAdd`, but the former can't -- directly be applied here since `ℝ≥0` is a subtype of `ℝ`, not an additive submonoid. instance NNReal.hasLipschitzAdd : LipschitzAdd ℝ≥0 where lipschitz_add := ⟨LipschitzAdd.C ℝ, by rintro ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ exact lipschitzWith_lipschitz_const_add_edist ⟨(x₁ : ℝ), x₂⟩ ⟨y₁, y₂⟩⟩ end LipschitzMul section IsBoundedSMul variable [Zero α] [Zero β] [SMul α β] /-- Mixin typeclass on a scalar action of a metric space `α` on a metric space `β` both with distinguished points `0`, requiring compatibility of the action in the sense that `dist (x • y₁) (x • y₂) ≤ dist x 0 * dist y₁ y₂` and `dist (x₁ • y) (x₂ • y) ≤ dist x₁ x₂ * dist y 0`. If `[NormedDivisionRing α] [SeminormedAddCommGroup β] [Module α β]` are assumed, then prefer writing `[NormSMulClass α β]` instead of using `[IsBoundedSMul α β]`, since while equivalent, typeclass search can only infer the latter from the former and not vice versa. -/ class IsBoundedSMul : Prop where dist_smul_pair' : ∀ x : α, ∀ y₁ y₂ : β, dist (x • y₁) (x • y₂) ≤ dist x 0 * dist y₁ y₂ dist_pair_smul' : ∀ x₁ x₂ : α, ∀ y : β, dist (x₁ • y) (x₂ • y) ≤ dist x₁ x₂ * dist y 0 variable {α β} variable [IsBoundedSMul α β] theorem dist_smul_pair (x : α) (y₁ y₂ : β) : dist (x • y₁) (x • y₂) ≤ dist x 0 * dist y₁ y₂ := IsBoundedSMul.dist_smul_pair' x y₁ y₂ theorem dist_pair_smul (x₁ x₂ : α) (y : β) : dist (x₁ • y) (x₂ • y) ≤ dist x₁ x₂ * dist y 0 := IsBoundedSMul.dist_pair_smul' x₁ x₂ y -- see Note [lower instance priority] /-- The typeclass `IsBoundedSMul` on a metric-space scalar action implies continuity of the action. -/ instance (priority := 100) IsBoundedSMul.continuousSMul : ContinuousSMul α β where continuous_smul := by rw [Metric.continuous_iff] rintro ⟨a, b⟩ ε ε0 obtain ⟨δ, δ0, hδε⟩ : ∃ δ > 0, δ * (δ + dist b 0) + dist a 0 * δ < ε := by have : Continuous fun δ ↦ δ * (δ + dist b 0) + dist a 0 * δ := by fun_prop refine ((this.tendsto' _ _ ?_).eventually (gt_mem_nhds ε0)).exists_gt simp refine ⟨δ, δ0, fun (a', b') hab' => ?_⟩ obtain ⟨ha, hb⟩ := max_lt_iff.1 hab' calc dist (a' • b') (a • b) ≤ dist (a' • b') (a • b') + dist (a • b') (a • b) := dist_triangle .. _ ≤ dist a' a * dist b' 0 + dist a 0 * dist b' b := add_le_add (dist_pair_smul _ _ _) (dist_smul_pair _ _ _) _ ≤ δ * (δ + dist b 0) + dist a 0 * δ := by gcongr; grw [dist_triangle b' b 0, hb] _ < ε := hδε instance (priority := 100) IsBoundedSMul.toUniformContinuousConstSMul : UniformContinuousConstSMul α β := ⟨fun c => ((lipschitzWith_iff_dist_le_mul (K := nndist c 0)).2 fun _ _ => dist_smul_pair c _ _).uniformContinuous⟩ -- this instance could be deduced from `NormedSpace.isBoundedSMul`, but we prove it separately -- here so that it is available earlier in the hierarchy instance Real.isBoundedSMul : IsBoundedSMul ℝ ℝ where dist_smul_pair' x y₁ y₂ := by simpa [Real.dist_eq, mul_sub] using (abs_mul x (y₁ - y₂)).le dist_pair_smul' x₁ x₂ y := by simpa [Real.dist_eq, sub_mul] using (abs_mul (x₁ - x₂) y).le instance NNReal.isBoundedSMul : IsBoundedSMul ℝ≥0 ℝ≥0 where dist_smul_pair' x y₁ y₂ := by convert dist_smul_pair (x : ℝ) (y₁ : ℝ) y₂ using 1 dist_pair_smul' x₁ x₂ y := by convert dist_pair_smul (x₁ : ℝ) x₂ (y : ℝ) using 1 /-- If a scalar is central, then its right action is bounded when its left action is. -/ instance IsBoundedSMul.op [SMul αᵐᵒᵖ β] [IsCentralScalar α β] : IsBoundedSMul αᵐᵒᵖ β where dist_smul_pair' := MulOpposite.rec' fun x y₁ y₂ => by simpa only [op_smul_eq_smul] using dist_smul_pair x y₁ y₂ dist_pair_smul' := MulOpposite.rec' fun x₁ => MulOpposite.rec' fun x₂ y => by simpa only [op_smul_eq_smul] using dist_pair_smul x₁ x₂ y end IsBoundedSMul instance [Monoid α] [LipschitzMul α] : LipschitzAdd (Additive α) := ⟨@LipschitzMul.lipschitz_mul α _ _ _⟩ instance [AddMonoid α] [LipschitzAdd α] : LipschitzMul (Multiplicative α) := ⟨@LipschitzAdd.lipschitz_add α _ _ _⟩ @[to_additive] instance [Monoid α] [LipschitzMul α] : LipschitzMul αᵒᵈ := ‹LipschitzMul α› variable {ι : Type*} [Fintype ι] instance Pi.instIsBoundedSMul {α : Type*} {β : ι → Type*} [PseudoMetricSpace α] [∀ i, PseudoMetricSpace (β i)] [Zero α] [∀ i, Zero (β i)] [∀ i, SMul α (β i)] [∀ i, IsBoundedSMul α (β i)] : IsBoundedSMul α (∀ i, β i) where dist_smul_pair' x y₁ y₂ := (dist_pi_le_iff <| by positivity).2 fun _ ↦ (dist_smul_pair _ _ _).trans <| mul_le_mul_of_nonneg_left (dist_le_pi_dist _ _ _) dist_nonneg dist_pair_smul' x₁ x₂ y := (dist_pi_le_iff <| by positivity).2 fun _ ↦ (dist_pair_smul _ _ _).trans <| mul_le_mul_of_nonneg_left (dist_le_pi_dist _ 0 _) dist_nonneg instance Pi.instIsBoundedSMul' {α β : ι → Type*} [∀ i, PseudoMetricSpace (α i)] [∀ i, PseudoMetricSpace (β i)] [∀ i, Zero (α i)] [∀ i, Zero (β i)] [∀ i, SMul (α i) (β i)] [∀ i, IsBoundedSMul (α i) (β i)] : IsBoundedSMul (∀ i, α i) (∀ i, β i) where dist_smul_pair' x y₁ y₂ := (dist_pi_le_iff <| by positivity).2 fun _ ↦ (dist_smul_pair _ _ _).trans <| mul_le_mul (dist_le_pi_dist _ 0 _) (dist_le_pi_dist _ _ _) dist_nonneg dist_nonneg dist_pair_smul' x₁ x₂ y := (dist_pi_le_iff <| by positivity).2 fun _ ↦ (dist_pair_smul _ _ _).trans <| mul_le_mul (dist_le_pi_dist _ _ _) (dist_le_pi_dist _ 0 _) dist_nonneg dist_nonneg instance Prod.instIsBoundedSMul {α β γ : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] [Zero α] [Zero β] [Zero γ] [SMul α β] [SMul α γ] [IsBoundedSMul α β] [IsBoundedSMul α γ] : IsBoundedSMul α (β × γ) where dist_smul_pair' _x _y₁ _y₂ := max_le ((dist_smul_pair _ _ _).trans <| mul_le_mul_of_nonneg_left (le_max_left _ _) dist_nonneg) ((dist_smul_pair _ _ _).trans <| mul_le_mul_of_nonneg_left (le_max_right _ _) dist_nonneg) dist_pair_smul' _x₁ _x₂ _y := max_le ((dist_pair_smul _ _ _).trans <| mul_le_mul_of_nonneg_left (le_max_left _ _) dist_nonneg) ((dist_pair_smul _ _ _).trans <| mul_le_mul_of_nonneg_left (le_max_right _ _) dist_nonneg) instance {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [Zero α] [Zero β] [SMul α β] [IsBoundedSMul α β] : IsBoundedSMul α (SeparationQuotient β) where dist_smul_pair' _ := Quotient.ind₂ <| dist_smul_pair _ dist_pair_smul' _ _ := Quotient.ind <| dist_pair_smul _ _ -- We don't have the `SMul α γ → SMul β δ → SMul (α × β) (γ × δ)` instance, but if we did, then -- `IsBoundedSMul α γ → IsBoundedSMul β δ → IsBoundedSMul (α × β) (γ × δ)` would hold
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/PartitionOfUnity.lean
import Mathlib.Topology.EMetricSpace.Paracompact import Mathlib.Topology.Instances.ENNReal.Lemmas import Mathlib.Analysis.Convex.PartitionOfUnity /-! # Lemmas about (e)metric spaces that need partition of unity The main lemma in this file (see `Metric.exists_continuous_real_forall_closedBall_subset`) says the following. Let `X` be a metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, → ℝ)` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. We also formulate versions of this lemma for extended metric spaces and for different codomains (`ℝ`, `ℝ≥0`, and `ℝ≥0∞`). We also prove a few auxiliary lemmas to be used later in a proof of the smooth version of this lemma. ## Tags metric space, partition of unity, locally finite -/ open Topology ENNReal NNReal Filter Set Function TopologicalSpace variable {ι X : Type*} namespace EMetric variable [EMetricSpace X] {K : ι → Set X} {U : ι → Set X} /-- Let `K : ι → Set X` be a locally finite family of closed sets in an emetric space. Let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then for any point `x : X`, for sufficiently small `r : ℝ≥0∞` and for `y` sufficiently close to `x`, for all `i`, if `y ∈ K i`, then `EMetric.closedBall y r ⊆ U i`. -/ theorem eventually_nhds_zero_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) (x : X) : ∀ᶠ p : ℝ≥0∞ × X in 𝓝 0 ×ˢ 𝓝 x, ∀ i, p.2 ∈ K i → closedBall p.2 p.1 ⊆ U i := by suffices ∀ i, x ∈ K i → ∀ᶠ p : ℝ≥0∞ × X in 𝓝 0 ×ˢ 𝓝 x, closedBall p.2 p.1 ⊆ U i by apply mp_mem ((eventually_all_finite (hfin.point_finite x)).2 this) (mp_mem (@tendsto_snd ℝ≥0∞ _ (𝓝 0) _ _ (hfin.iInter_compl_mem_nhds hK x)) _) apply univ_mem' rintro ⟨r, y⟩ hxy hyU i hi simp only [mem_iInter, mem_compl_iff, not_imp_not, mem_preimage] at hxy exact hyU _ (hxy _ hi) intro i hi rcases nhds_basis_closed_eball.mem_iff.1 ((hU i).mem_nhds <| hKU i hi) with ⟨R, hR₀, hR⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.mp hR₀ with ⟨r, hr₀, hrR⟩ filter_upwards [prod_mem_prod (eventually_lt_nhds hr₀) (closedBall_mem_nhds x (tsub_pos_iff_lt.2 hrR))] with p hp z hz apply hR calc edist z x ≤ edist z p.2 + edist p.2 x := edist_triangle _ _ _ _ ≤ p.1 + (R - p.1) := add_le_add hz <| le_trans hp.2 <| tsub_le_tsub_left hp.1.out.le _ _ = R := add_tsub_cancel_of_le (lt_trans (by exact hp.1) hrR).le theorem exists_forall_closedBall_subset_aux₁ (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) (x : X) : ∃ r : ℝ, ∀ᶠ y in 𝓝 x, r ∈ Ioi (0 : ℝ) ∩ ENNReal.ofReal ⁻¹' ⋂ (i) (_ : y ∈ K i), { r | closedBall y r ⊆ U i } := by have := (ENNReal.continuous_ofReal.tendsto' 0 0 ENNReal.ofReal_zero).eventually (eventually_nhds_zero_forall_closedBall_subset hK hU hKU hfin x).curry rcases this.exists_gt with ⟨r, hr0, hr⟩ refine ⟨r, hr.mono fun y hy => ⟨hr0, ?_⟩⟩ rwa [mem_preimage, mem_iInter₂] theorem exists_forall_closedBall_subset_aux₂ (y : X) : Convex ℝ (Ioi (0 : ℝ) ∩ ENNReal.ofReal ⁻¹' ⋂ (i) (_ : y ∈ K i), { r | closedBall y r ⊆ U i }) := (convex_Ioi _).inter <| OrdConnected.convex <| OrdConnected.preimage_ennreal_ofReal <| ordConnected_iInter fun i => ordConnected_iInter fun (_ : y ∈ K i) => ordConnected_setOf_closedBall_subset y (U i) /-- Let `X` be an extended metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ)` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (ENNReal.ofReal (δ x)) ⊆ U i`. -/ theorem exists_continuous_real_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (ENNReal.ofReal <| δ x) ⊆ U i := by simpa only [mem_inter_iff, forall_and, mem_preimage, mem_iInter, @forall_swap ι X] using exists_continuous_forall_mem_convex_of_local_const exists_forall_closedBall_subset_aux₂ (exists_forall_closedBall_subset_aux₁ hK hU hKU hfin) /-- Let `X` be an extended metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ≥0)` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_nnreal_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ≥0), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := by rcases exists_continuous_real_forall_closedBall_subset hK hU hKU hfin with ⟨δ, hδ₀, hδ⟩ lift δ to C(X, ℝ≥0) using fun x => (hδ₀ x).le refine ⟨δ, hδ₀, fun i x hi => ?_⟩ simpa only [← ENNReal.ofReal_coe_nnreal] using hδ i x hi /-- Let `X` be an extended metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ≥0∞)` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_eNNReal_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ≥0∞), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := let ⟨δ, hδ₀, hδ⟩ := exists_continuous_nnreal_forall_closedBall_subset hK hU hKU hfin ⟨ContinuousMap.comp ⟨Coe.coe, ENNReal.continuous_coe⟩ δ, fun x => ENNReal.coe_pos.2 (hδ₀ x), hδ⟩ end EMetric namespace Metric variable [MetricSpace X] {K : ι → Set X} {U : ι → Set X} /-- Let `X` be a metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ≥0)` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_nnreal_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ≥0), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := by rcases EMetric.exists_continuous_nnreal_forall_closedBall_subset hK hU hKU hfin with ⟨δ, hδ0, hδ⟩ refine ⟨δ, hδ0, fun i x hx => ?_⟩ rw [← emetric_closedBall_nnreal] exact hδ i x hx /-- Let `X` be a metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ)` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_real_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := let ⟨δ, hδ₀, hδ⟩ := exists_continuous_nnreal_forall_closedBall_subset hK hU hKU hfin ⟨ContinuousMap.comp ⟨Coe.coe, NNReal.continuous_coe⟩ δ, hδ₀, hδ⟩ end Metric
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/PiNat.lean
import Mathlib.Analysis.Normed.Group.FunctionSeries import Mathlib.Topology.Algebra.MetricSpace.Lipschitz import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Topological study of spaces `Π (n : ℕ), E n` When `E n` are topological spaces, the space `Π (n : ℕ), E n` is naturally a topological space (with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure. However, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one can put a noncanonical metric space structure (or rather, several of them). This is done in this file. ## Main definitions and results One can define a combinatorial distance on `Π (n : ℕ), E n`, as follows: * `PiNat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`. * `PiNat.firstDiff x y` is the first index at which `x i ≠ y i`. * `PiNat.dist x y` is equal to `(1/2) ^ (firstDiff x y)`. It defines a distance on `Π (n : ℕ), E n`, compatible with the topology when the `E n` have the discrete topology. * `PiNat.metricSpace`: the metric space structure, given by this distance. Not registered as an instance. This space is a complete metric space. * `PiNat.metricSpaceOfDiscreteUniformity`: the same metric space structure, but adjusting the uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an instance * `PiNat.metricSpaceNatNat`: the particular case of `ℕ → ℕ`, not registered as an instance. These results are used to construct continuous functions on `Π n, E n`: * `PiNat.exists_retraction_of_isClosed`: given a nonempty closed subset `s` of `Π (n : ℕ), E n`, there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s` restricting to the identity on `s`. * `exists_nat_nat_continuous_surjective_of_completeSpace`: given any nonempty complete metric space with second-countable topology, there exists a continuous surjection from `ℕ → ℕ` onto this space. One can also put distances on `Π (i : ι), E i` when the spaces `E i` are metric spaces (not discrete in general), and `ι` is countable. * `PiCountable.dist` is the distance on `Π i, E i` given by `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. * `PiCountable.metricSpace` is the corresponding metric space structure, adjusted so that the uniformity is definitionally the product uniformity. Not registered as an instance. * `PiNatEmbed` gives an equivalence between a space and itself in a sequence of spaces * `Metric.PiNatEmbed.metricSpace` proves that a topological `X` separated by countably many continuous functions to metric spaces, can be embedded inside their product. -/ noncomputable section open Topology TopologicalSpace Set Metric Filter Function attribute [local simp] pow_le_pow_iff_right₀ one_lt_two inv_le_inv₀ zero_le_two zero_lt_two variable {E : ℕ → Type*} namespace PiNat /-! ### The firstDiff function -/ open Classical in /-- In a product space `Π n, E n`, then `firstDiff x y` is the first index at which `x` and `y` differ. If `x = y`, then by convention we set `firstDiff x x = 0`. -/ irreducible_def firstDiff (x y : ∀ n, E n) : ℕ := if h : x ≠ y then Nat.find (ne_iff.1 h) else 0 theorem apply_firstDiff_ne {x y : ∀ n, E n} (h : x ≠ y) : x (firstDiff x y) ≠ y (firstDiff x y) := by rw [firstDiff_def, dif_pos h] classical exact Nat.find_spec (ne_iff.1 h) theorem apply_eq_of_lt_firstDiff {x y : ∀ n, E n} {n : ℕ} (hn : n < firstDiff x y) : x n = y n := by rw [firstDiff_def] at hn split_ifs at hn with h · convert Nat.find_min (ne_iff.1 h) hn simp · exact (not_lt_zero' hn).elim theorem firstDiff_comm (x y : ∀ n, E n) : firstDiff x y = firstDiff y x := by classical simp only [firstDiff_def, ne_comm] theorem min_firstDiff_le (x y z : ∀ n, E n) (h : x ≠ z) : min (firstDiff x y) (firstDiff y z) ≤ firstDiff x z := by by_contra! H rw [lt_min_iff] at H refine apply_firstDiff_ne h ?_ calc x (firstDiff x z) = y (firstDiff x z) := apply_eq_of_lt_firstDiff H.1 _ = z (firstDiff x z) := apply_eq_of_lt_firstDiff H.2 /-! ### Cylinders -/ /-- In a product space `Π n, E n`, the cylinder set of length `n` around `x`, denoted `cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e., such that `y i = x i` for all `i < n`. -/ def cylinder (x : ∀ n, E n) (n : ℕ) : Set (∀ n, E n) := { y | ∀ i, i < n → y i = x i } theorem cylinder_eq_pi (x : ∀ n, E n) (n : ℕ) : cylinder x n = Set.pi (Finset.range n : Set ℕ) fun i : ℕ => {x i} := by ext y simp [cylinder] @[simp] theorem cylinder_zero (x : ∀ n, E n) : cylinder x 0 = univ := by simp [cylinder_eq_pi] theorem cylinder_anti (x : ∀ n, E n) {m n : ℕ} (h : m ≤ n) : cylinder x n ⊆ cylinder x m := fun _y hy i hi => hy i (hi.trans_le h) @[simp] theorem mem_cylinder_iff {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ ∀ i < n, y i = x i := Iff.rfl theorem self_mem_cylinder (x : ∀ n, E n) (n : ℕ) : x ∈ cylinder x n := by simp theorem mem_cylinder_iff_eq {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ cylinder y n = cylinder x n := by constructor · intro hy apply Subset.antisymm · intro z hz i hi rw [← hy i hi] exact hz i hi · intro z hz i hi rw [hy i hi] exact hz i hi · intro h rw [← h] exact self_mem_cylinder _ _ theorem mem_cylinder_comm (x y : ∀ n, E n) (n : ℕ) : y ∈ cylinder x n ↔ x ∈ cylinder y n := by simp [eq_comm] theorem mem_cylinder_iff_le_firstDiff {x y : ∀ n, E n} (hne : x ≠ y) (i : ℕ) : x ∈ cylinder y i ↔ i ≤ firstDiff x y := by constructor · intro h by_contra! exact apply_firstDiff_ne hne (h _ this) · intro hi j hj exact apply_eq_of_lt_firstDiff (hj.trans_le hi) theorem mem_cylinder_firstDiff (x y : ∀ n, E n) : x ∈ cylinder y (firstDiff x y) := fun _i hi => apply_eq_of_lt_firstDiff hi theorem cylinder_eq_cylinder_of_le_firstDiff (x y : ∀ n, E n) {n : ℕ} (hn : n ≤ firstDiff x y) : cylinder x n = cylinder y n := by rw [← mem_cylinder_iff_eq] intro i hi exact apply_eq_of_lt_firstDiff (hi.trans_le hn) theorem iUnion_cylinder_update (x : ∀ n, E n) (n : ℕ) : ⋃ k, cylinder (update x n k) (n + 1) = cylinder x n := by ext y simp only [mem_cylinder_iff, mem_iUnion] constructor · rintro ⟨k, hk⟩ i hi simpa [hi.ne] using hk i (Nat.lt_succ_of_lt hi) · intro H refine ⟨y n, fun i hi => ?_⟩ rcases Nat.lt_succ_iff_lt_or_eq.1 hi with (h'i | rfl) · simp [H i h'i, h'i.ne] · simp theorem update_mem_cylinder (x : ∀ n, E n) (n : ℕ) (y : E n) : update x n y ∈ cylinder x n := mem_cylinder_iff.2 fun i hi => by simp [hi.ne] section Res variable {α : Type*} open List /-- In the case where `E` has constant value `α`, the cylinder `cylinder x n` can be identified with the element of `List α` consisting of the first `n` entries of `x`. See `cylinder_eq_res`. We call this list `res x n`, the restriction of `x` to `n`. -/ def res (x : ℕ → α) : ℕ → List α | 0 => nil | Nat.succ n => x n :: res x n @[simp] theorem res_zero (x : ℕ → α) : res x 0 = @nil α := rfl @[simp] theorem res_succ (x : ℕ → α) (n : ℕ) : res x n.succ = x n :: res x n := rfl @[simp] theorem res_length (x : ℕ → α) (n : ℕ) : (res x n).length = n := by induction n <;> simp [*] /-- The restrictions of `x` and `y` to `n` are equal if and only if `x m = y m` for all `m < n`. -/ theorem res_eq_res {x y : ℕ → α} {n : ℕ} : res x n = res y n ↔ ∀ ⦃m⦄, m < n → x m = y m := by constructor <;> intro h · induction n with | zero => simp | succ n ih => intro m hm rw [Nat.lt_succ_iff_lt_or_eq] at hm simp only [res_succ, cons.injEq] at h rcases hm with hm | hm · exact ih h.2 hm rw [hm] exact h.1 · induction n with | zero => simp | succ n ih => simp only [res_succ, cons.injEq] refine ⟨h (Nat.lt_succ_self _), ih fun m hm => ?_⟩ exact h (hm.trans (Nat.lt_succ_self _)) theorem res_injective : Injective (@res α) := by intro x y h ext n apply res_eq_res.mp _ (Nat.lt_succ_self _) rw [h] /-- `cylinder x n` is equal to the set of sequences `y` with the same restriction to `n` as `x`. -/ theorem cylinder_eq_res (x : ℕ → α) (n : ℕ) : cylinder x n = { y | res y n = res x n } := by ext y dsimp [cylinder] rw [res_eq_res] end Res /-! ### A distance function on `Π n, E n` We define a distance function on `Π n, E n`, given by `dist x y = (1/2)^n` where `n` is the first index at which `x` and `y` differ. When each `E n` has the discrete topology, this distance will define the right topology on the product space. We do not record a global `Dist` instance nor a `MetricSpace` instance, as other distances may be used on these spaces, but we register them as local instances in this section. -/ open Classical in /-- The distance function on a product space `Π n, E n`, given by `dist x y = (1/2)^n` where `n` is the first index at which `x` and `y` differ. -/ protected def dist : Dist (∀ n, E n) := ⟨fun x y => if x ≠ y then (1 / 2 : ℝ) ^ firstDiff x y else 0⟩ attribute [local instance] PiNat.dist theorem dist_eq_of_ne {x y : ∀ n, E n} (h : x ≠ y) : dist x y = (1 / 2 : ℝ) ^ firstDiff x y := by simp [dist, h] protected theorem dist_self (x : ∀ n, E n) : dist x x = 0 := by simp [dist] protected theorem dist_comm (x y : ∀ n, E n) : dist x y = dist y x := by classical simp [dist, @eq_comm _ x y, firstDiff_comm] protected theorem dist_nonneg (x y : ∀ n, E n) : 0 ≤ dist x y := by rcases eq_or_ne x y with (rfl | h) · simp [dist] · simp [dist, h] theorem dist_triangle_nonarch (x y z : ∀ n, E n) : dist x z ≤ max (dist x y) (dist y z) := by rcases eq_or_ne x z with (rfl | hxz) · simp [PiNat.dist_self x, PiNat.dist_nonneg] rcases eq_or_ne x y with (rfl | hxy) · simp rcases eq_or_ne y z with (rfl | hyz) · simp simp only [dist_eq_of_ne, hxz, hxy, hyz, inv_le_inv₀, one_div, inv_pow, zero_lt_two, Ne, not_false_iff, le_max_iff, pow_le_pow_iff_right₀, one_lt_two, pow_pos, min_le_iff.1 (min_firstDiff_le x y z hxz)] protected theorem dist_triangle (x y z : ∀ n, E n) : dist x z ≤ dist x y + dist y z := calc dist x z ≤ max (dist x y) (dist y z) := dist_triangle_nonarch x y z _ ≤ dist x y + dist y z := max_le_add_of_nonneg (PiNat.dist_nonneg _ _) (PiNat.dist_nonneg _ _) protected theorem eq_of_dist_eq_zero (x y : ∀ n, E n) (hxy : dist x y = 0) : x = y := by rcases eq_or_ne x y with (rfl | h); · rfl simp [dist_eq_of_ne h] at hxy theorem mem_cylinder_iff_dist_le {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ dist y x ≤ (1 / 2) ^ n := by rcases eq_or_ne y x with (rfl | hne) · simp [PiNat.dist_self] suffices (∀ i : ℕ, i < n → y i = x i) ↔ n ≤ firstDiff y x by simpa [dist_eq_of_ne hne] constructor · intro hy by_contra! H exact apply_firstDiff_ne hne (hy _ H) · intro h i hi exact apply_eq_of_lt_firstDiff (hi.trans_le h) theorem apply_eq_of_dist_lt {x y : ∀ n, E n} {n : ℕ} (h : dist x y < (1 / 2) ^ n) {i : ℕ} (hi : i ≤ n) : x i = y i := by rcases eq_or_ne x y with (rfl | hne) · rfl have : n < firstDiff x y := by simpa [dist_eq_of_ne hne, inv_lt_inv₀, pow_lt_pow_iff_right₀, one_lt_two] using h exact apply_eq_of_lt_firstDiff (hi.trans_lt this) /-- A function to a pseudo-metric-space is `1`-Lipschitz if and only if points in the same cylinder of length `n` are sent to points within distance `(1/2)^n`. Not expressed using `LipschitzWith` as we don't have a metric space structure -/ theorem lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder {α : Type*} [PseudoMetricSpace α] {f : (∀ n, E n) → α} : (∀ x y : ∀ n, E n, dist (f x) (f y) ≤ dist x y) ↔ ∀ x y n, y ∈ cylinder x n → dist (f x) (f y) ≤ (1 / 2) ^ n := by constructor · intro H x y n hxy apply (H x y).trans rw [PiNat.dist_comm] exact mem_cylinder_iff_dist_le.1 hxy · intro H x y rcases eq_or_ne x y with (rfl | hne) · simp [PiNat.dist_nonneg] rw [dist_eq_of_ne hne] apply H x y (firstDiff x y) rw [firstDiff_comm] exact mem_cylinder_firstDiff _ _ variable (E) variable [∀ n, TopologicalSpace (E n)] [∀ n, DiscreteTopology (E n)] theorem isOpen_cylinder (x : ∀ n, E n) (n : ℕ) : IsOpen (cylinder x n) := by rw [PiNat.cylinder_eq_pi] exact isOpen_set_pi (Finset.range n).finite_toSet fun a _ => isOpen_discrete _ theorem isTopologicalBasis_cylinders : IsTopologicalBasis { s : Set (∀ n, E n) | ∃ (x : ∀ n, E n) (n : ℕ), s = cylinder x n } := by apply isTopologicalBasis_of_isOpen_of_nhds · rintro u ⟨x, n, rfl⟩ apply isOpen_cylinder · intro x u hx u_open obtain ⟨v, ⟨U, F, -, rfl⟩, xU, Uu⟩ : ∃ v ∈ { S : Set (∀ i : ℕ, E i) | ∃ (U : ∀ i : ℕ, Set (E i)) (F : Finset ℕ), (∀ i : ℕ, i ∈ F → U i ∈ { s : Set (E i) | IsOpen s }) ∧ S = (F : Set ℕ).pi U }, x ∈ v ∧ v ⊆ u := (isTopologicalBasis_pi fun n : ℕ => isTopologicalBasis_opens).exists_subset_of_mem_open hx u_open rcases Finset.bddAbove F with ⟨n, hn⟩ refine ⟨cylinder x (n + 1), ⟨x, n + 1, rfl⟩, self_mem_cylinder _ _, Subset.trans ?_ Uu⟩ intro y hy suffices ∀ i : ℕ, i ∈ F → y i ∈ U i by simpa intro i hi have : y i = x i := mem_cylinder_iff.1 hy i ((hn hi).trans_lt (lt_add_one n)) rw [this] simp only [Set.mem_pi, Finset.mem_coe] at xU exact xU i hi variable {E} theorem isOpen_iff_dist (s : Set (∀ n, E n)) : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s := by constructor · intro hs x hx obtain ⟨v, ⟨y, n, rfl⟩, h'x, h's⟩ : ∃ v ∈ { s | ∃ (x : ∀ n : ℕ, E n) (n : ℕ), s = cylinder x n }, x ∈ v ∧ v ⊆ s := (isTopologicalBasis_cylinders E).exists_subset_of_mem_open hx hs rw [← mem_cylinder_iff_eq.1 h'x] at h's exact ⟨(1 / 2 : ℝ) ^ n, by simp, fun y hy => h's fun i hi => (apply_eq_of_dist_lt hy hi.le).symm⟩ · intro h refine (isTopologicalBasis_cylinders E).isOpen_iff.2 fun x hx => ?_ rcases h x hx with ⟨ε, εpos, hε⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2 : ℝ) ^ n < ε := exists_pow_lt_of_lt_one εpos one_half_lt_one refine ⟨cylinder x n, ⟨x, n, rfl⟩, self_mem_cylinder x n, fun y hy => hε y ?_⟩ rw [PiNat.dist_comm] exact (mem_cylinder_iff_dist_le.1 hy).trans_lt hn /-- Metric space structure on `Π (n : ℕ), E n` when the spaces `E n` have the discrete topology, where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and `y` differ. Not registered as a global instance by default. Warning: this definition makes sure that the topology is defeq to the original product topology, but it does not take care of a possible uniformity. If the `E n` have a uniform structure, then there will be two non-defeq uniform structures on `Π n, E n`, the product one and the one coming from the metric structure. In this case, use `metricSpaceOfDiscreteUniformity` instead. -/ protected def metricSpace : MetricSpace (∀ n, E n) := MetricSpace.ofDistTopology dist PiNat.dist_self PiNat.dist_comm PiNat.dist_triangle isOpen_iff_dist PiNat.eq_of_dist_eq_zero /-- Metric space structure on `Π (n : ℕ), E n` when the spaces `E n` have the discrete uniformity, where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and `y` differ. Not registered as a global instance by default. -/ protected def metricSpaceOfDiscreteUniformity {E : ℕ → Type*} [∀ n, UniformSpace (E n)] (h : ∀ n, uniformity (E n) = 𝓟 SetRel.id) : MetricSpace (∀ n, E n) := haveI : ∀ n, DiscreteTopology (E n) := fun n => discreteTopology_of_discrete_uniformity (h n) { dist_triangle := PiNat.dist_triangle dist_comm := PiNat.dist_comm dist_self := PiNat.dist_self eq_of_dist_eq_zero := PiNat.eq_of_dist_eq_zero _ _ toUniformSpace := Pi.uniformSpace _ uniformity_dist := by simp only [Pi.uniformity, h, SetRel.id, comap_principal, preimage_setOf_eq] apply le_antisymm · simp only [le_iInf_iff, le_principal_iff] intro ε εpos obtain ⟨n, hn⟩ : ∃ n, (1 / 2 : ℝ) ^ n < ε := exists_pow_lt_of_lt_one εpos (by norm_num) apply @mem_iInf_of_iInter _ _ _ _ _ (Finset.range n).finite_toSet fun i => { p : (∀ n : ℕ, E n) × ∀ n : ℕ, E n | p.fst i = p.snd i } · simp only [mem_principal, setOf_subset_setOf, imp_self, imp_true_iff] · rintro ⟨x, y⟩ hxy simp only [Finset.mem_coe, Finset.mem_range, iInter_coe_set, mem_iInter, mem_setOf_eq] at hxy apply lt_of_le_of_lt _ hn rw [← mem_cylinder_iff_dist_le, mem_cylinder_iff] exact hxy · simp only [le_iInf_iff, le_principal_iff] intro n refine mem_iInf_of_mem ((1 / 2) ^ n : ℝ) ?_ refine mem_iInf_of_mem (by positivity) ?_ simp only [mem_principal, setOf_subset_setOf, Prod.forall] intro x y hxy exact apply_eq_of_dist_lt hxy le_rfl } /-- Metric space structure on `ℕ → ℕ` where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and `y` differ. Not registered as a global instance by default. -/ def metricSpaceNatNat : MetricSpace (ℕ → ℕ) := PiNat.metricSpaceOfDiscreteUniformity fun _ => rfl attribute [local instance] PiNat.metricSpace protected theorem completeSpace : CompleteSpace (∀ n, E n) := by refine Metric.complete_of_convergent_controlled_sequences (fun n => (1 / 2) ^ n) (by simp) ?_ intro u hu refine ⟨fun n => u n n, tendsto_pi_nhds.2 fun i => ?_⟩ refine tendsto_const_nhds.congr' ?_ filter_upwards [Filter.Ici_mem_atTop i] with n hn exact apply_eq_of_dist_lt (hu i i n le_rfl hn) le_rfl /-! ### Retractions inside product spaces We show that, in a space `Π (n : ℕ), E n` where each `E n` is discrete, there is a retraction on any closed nonempty subset `s`, i.e., a continuous map `f` from the whole space to `s` restricting to the identity on `s`. The map `f` is defined as follows. For `x ∈ s`, let `f x = x`. Otherwise, consider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element of `s` starting with `w`. -/ theorem exists_disjoint_cylinder {s : Set (∀ n, E n)} (hs : IsClosed s) {x : ∀ n, E n} (hx : x ∉ s) : ∃ n, Disjoint s (cylinder x n) := by rcases eq_empty_or_nonempty s with (rfl | hne) · exact ⟨0, by simp⟩ have A : 0 < infDist x s := (hs.notMem_iff_infDist_pos hne).1 hx obtain ⟨n, hn⟩ : ∃ n, (1 / 2 : ℝ) ^ n < infDist x s := exists_pow_lt_of_lt_one A one_half_lt_one refine ⟨n, disjoint_left.2 fun y ys hy => ?_⟩ apply lt_irrefl (infDist x s) calc infDist x s ≤ dist x y := infDist_le_dist_of_mem ys _ ≤ (1 / 2) ^ n := by rw [mem_cylinder_comm] at hy exact mem_cylinder_iff_dist_le.1 hy _ < infDist x s := hn open Classical in /-- Given a point `x` in a product space `Π (n : ℕ), E n`, and `s` a subset of this space, then `shortestPrefixDiff x s` if the smallest `n` for which there is no element of `s` having the same prefix of length `n` as `x`. If there is no such `n`, then use `0` by convention. -/ def shortestPrefixDiff {E : ℕ → Type*} (x : ∀ n, E n) (s : Set (∀ n, E n)) : ℕ := if h : ∃ n, Disjoint s (cylinder x n) then Nat.find h else 0 theorem firstDiff_lt_shortestPrefixDiff {s : Set (∀ n, E n)} (hs : IsClosed s) {x y : ∀ n, E n} (hx : x ∉ s) (hy : y ∈ s) : firstDiff x y < shortestPrefixDiff x s := by have A := exists_disjoint_cylinder hs hx rw [shortestPrefixDiff, dif_pos A] classical have B := Nat.find_spec A contrapose! B rw [not_disjoint_iff_nonempty_inter] refine ⟨y, hy, ?_⟩ rw [mem_cylinder_comm] exact cylinder_anti y B (mem_cylinder_firstDiff x y) theorem shortestPrefixDiff_pos {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) {x : ∀ n, E n} (hx : x ∉ s) : 0 < shortestPrefixDiff x s := by rcases hne with ⟨y, hy⟩ exact (zero_le _).trans_lt (firstDiff_lt_shortestPrefixDiff hs hx hy) /-- Given a point `x` in a product space `Π (n : ℕ), E n`, and `s` a subset of this space, then `longestPrefix x s` if the largest `n` for which there is an element of `s` having the same prefix of length `n` as `x`. If there is no such `n`, use `0` by convention. -/ def longestPrefix {E : ℕ → Type*} (x : ∀ n, E n) (s : Set (∀ n, E n)) : ℕ := shortestPrefixDiff x s - 1 theorem firstDiff_le_longestPrefix {s : Set (∀ n, E n)} (hs : IsClosed s) {x y : ∀ n, E n} (hx : x ∉ s) (hy : y ∈ s) : firstDiff x y ≤ longestPrefix x s := by rw [longestPrefix, le_tsub_iff_right] · exact firstDiff_lt_shortestPrefixDiff hs hx hy · exact shortestPrefixDiff_pos hs ⟨y, hy⟩ hx theorem inter_cylinder_longestPrefix_nonempty {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) (x : ∀ n, E n) : (s ∩ cylinder x (longestPrefix x s)).Nonempty := by by_cases hx : x ∈ s · exact ⟨x, hx, self_mem_cylinder _ _⟩ have A := exists_disjoint_cylinder hs hx have B : longestPrefix x s < shortestPrefixDiff x s := Nat.pred_lt (shortestPrefixDiff_pos hs hne hx).ne' rw [longestPrefix, shortestPrefixDiff, dif_pos A] at B ⊢ classical obtain ⟨y, ys, hy⟩ : ∃ y : ∀ n : ℕ, E n, y ∈ s ∧ x ∈ cylinder y (Nat.find A - 1) := by simpa only [not_disjoint_iff, mem_cylinder_comm] using Nat.find_min A B refine ⟨y, ys, ?_⟩ rw [mem_cylinder_iff_eq] at hy ⊢ rw [hy] theorem disjoint_cylinder_of_longestPrefix_lt {s : Set (∀ n, E n)} (hs : IsClosed s) {x : ∀ n, E n} (hx : x ∉ s) {n : ℕ} (hn : longestPrefix x s < n) : Disjoint s (cylinder x n) := by contrapose! hn rcases not_disjoint_iff_nonempty_inter.1 hn with ⟨y, ys, hy⟩ apply le_trans _ (firstDiff_le_longestPrefix hs hx ys) apply (mem_cylinder_iff_le_firstDiff (ne_of_mem_of_not_mem ys hx).symm _).1 rwa [mem_cylinder_comm] /-- If two points `x, y` coincide up to length `n`, and the longest common prefix of `x` with `s` is strictly shorter than `n`, then the longest common prefix of `y` with `s` is the same, and both cylinders of this length based at `x` and `y` coincide. -/ theorem cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff {x y : ∀ n, E n} {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) (H : longestPrefix x s < firstDiff x y) (xs : x ∉ s) (ys : y ∉ s) : cylinder x (longestPrefix x s) = cylinder y (longestPrefix y s) := by have l_eq : longestPrefix y s = longestPrefix x s := by rcases lt_trichotomy (longestPrefix y s) (longestPrefix x s) with (L | L | L) · have Ax : (s ∩ cylinder x (longestPrefix x s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne x have Z := disjoint_cylinder_of_longestPrefix_lt hs ys L rw [firstDiff_comm] at H rw [cylinder_eq_cylinder_of_le_firstDiff _ _ H.le] at Z exact (Ax.not_disjoint Z).elim · exact L · have Ay : (s ∩ cylinder y (longestPrefix y s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne y have A'y : (s ∩ cylinder y (longestPrefix x s).succ).Nonempty := Ay.mono (inter_subset_inter_right s (cylinder_anti _ L)) have Z := disjoint_cylinder_of_longestPrefix_lt hs xs (Nat.lt_succ_self _) rw [cylinder_eq_cylinder_of_le_firstDiff _ _ H] at Z exact (A'y.not_disjoint Z).elim rw [l_eq, ← mem_cylinder_iff_eq] exact cylinder_anti y H.le (mem_cylinder_firstDiff x y) /-- Given a closed nonempty subset `s` of `Π (n : ℕ), E n`, there exists a Lipschitz retraction onto this set, i.e., a Lipschitz map with range equal to `s`, equal to the identity on `s`. -/ theorem exists_lipschitz_retraction_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) : ∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ LipschitzWith 1 f := by /- The map `f` is defined as follows. For `x ∈ s`, let `f x = x`. Otherwise, consider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element of `s` starting with `w`. All the desired properties are clear, except the fact that `f` is `1`-Lipschitz: if two points `x, y` belong to a common cylinder of length `n`, one should show that their images also belong to a common cylinder of length `n`. This is a case analysis: * if both `x, y ∈ s`, then this is clear. * if `x ∈ s` but `y ∉ s`, then the longest prefix `w` of `y` shared by an element of `s` is of length at least `n` (because of `x`), and then `f y` starts with `w` and therefore stays in the same length `n` cylinder. * if `x ∉ s`, `y ∉ s`, let `w` be the longest prefix of `x` shared by an element of `s`. If its length is `< n`, then it is also the longest prefix of `y`, and we get `f x = f y = z_w`. Otherwise, `f x` remains in the same `n`-cylinder as `x`. Similarly for `y`. Finally, `f x` and `f y` are again in the same `n`-cylinder, as desired. -/ classical set f := fun x => if x ∈ s then x else (inter_cylinder_longestPrefix_nonempty hs hne x).some have fs : ∀ x ∈ s, f x = x := fun x xs => by simp [f, xs] refine ⟨f, fs, ?_, ?_⟩ -- check that the range of `f` is `s`. · apply Subset.antisymm · rintro x ⟨y, rfl⟩ by_cases hy : y ∈ s · rwa [fs y hy] simpa [f, if_neg hy] using (inter_cylinder_longestPrefix_nonempty hs hne y).choose_spec.1 · intro x hx rw [← fs x hx] exact mem_range_self _ -- check that `f` is `1`-Lipschitz, by a case analysis. · refine LipschitzWith.mk_one fun x y => ?_ -- exclude the trivial cases where `x = y`, or `f x = f y`. rcases eq_or_ne x y with (rfl | hxy) · simp rcases eq_or_ne (f x) (f y) with (h' | hfxfy) · simp [h'] have I2 : cylinder x (firstDiff x y) = cylinder y (firstDiff x y) := by rw [← mem_cylinder_iff_eq] apply mem_cylinder_firstDiff suffices firstDiff x y ≤ firstDiff (f x) (f y) by simpa [dist_eq_of_ne hxy, dist_eq_of_ne hfxfy] -- case where `x ∈ s` by_cases xs : x ∈ s · rw [fs x xs] at hfxfy ⊢ -- case where `y ∈ s`, trivial by_cases ys : y ∈ s · rw [fs y ys] -- case where `y ∉ s` have A : (s ∩ cylinder y (longestPrefix y s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne y have fy : f y = A.some := by simp_rw [f, if_neg ys] have I : cylinder A.some (firstDiff x y) = cylinder y (firstDiff x y) := by rw [← mem_cylinder_iff_eq, firstDiff_comm] apply cylinder_anti y _ A.some_mem.2 exact firstDiff_le_longestPrefix hs ys xs rwa [← fy, ← I2, ← mem_cylinder_iff_eq, mem_cylinder_iff_le_firstDiff hfxfy.symm, firstDiff_comm _ x] at I -- case where `x ∉ s` · by_cases ys : y ∈ s -- case where `y ∈ s` (similar to the above) · have A : (s ∩ cylinder x (longestPrefix x s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne x have fx : f x = A.some := by simp_rw [f, if_neg xs] have I : cylinder A.some (firstDiff x y) = cylinder x (firstDiff x y) := by rw [← mem_cylinder_iff_eq] apply cylinder_anti x _ A.some_mem.2 apply firstDiff_le_longestPrefix hs xs ys rw [fs y ys] at hfxfy ⊢ rwa [← fx, I2, ← mem_cylinder_iff_eq, mem_cylinder_iff_le_firstDiff hfxfy] at I -- case where `y ∉ s` · have Ax : (s ∩ cylinder x (longestPrefix x s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne x have fx : f x = Ax.some := by simp_rw [f, if_neg xs] have Ay : (s ∩ cylinder y (longestPrefix y s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne y have fy : f y = Ay.some := by simp_rw [f, if_neg ys] -- case where the common prefix to `x` and `s`, or `y` and `s`, is shorter than the -- common part to `x` and `y` -- then `f x = f y`. by_cases! H : longestPrefix x s < firstDiff x y ∨ longestPrefix y s < firstDiff x y · have : cylinder x (longestPrefix x s) = cylinder y (longestPrefix y s) := by rcases H with H | H · exact cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff hs hne H xs ys · symm rw [firstDiff_comm] at H exact cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff hs hne H ys xs rw [fx, fy] at hfxfy apply (hfxfy _).elim congr -- case where the common prefix to `x` and `s` is long, as well as the common prefix to -- `y` and `s`. Then all points remain in the same cylinders. · have I1 : cylinder Ax.some (firstDiff x y) = cylinder x (firstDiff x y) := by rw [← mem_cylinder_iff_eq] exact cylinder_anti x H.1 Ax.some_mem.2 have I3 : cylinder y (firstDiff x y) = cylinder Ay.some (firstDiff x y) := by rw [eq_comm, ← mem_cylinder_iff_eq] exact cylinder_anti y H.2 Ay.some_mem.2 have : cylinder Ax.some (firstDiff x y) = cylinder Ay.some (firstDiff x y) := by rw [I1, I2, I3] rw [← fx, ← fy, ← mem_cylinder_iff_eq, mem_cylinder_iff_le_firstDiff hfxfy] at this exact this /-- Given a closed nonempty subset `s` of `Π (n : ℕ), E n`, there exists a retraction onto this set, i.e., a continuous map with range equal to `s`, equal to the identity on `s`. -/ theorem exists_retraction_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) : ∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ Continuous f := by rcases exists_lipschitz_retraction_of_isClosed hs hne with ⟨f, fs, frange, hf⟩ exact ⟨f, fs, frange, hf.continuous⟩ theorem exists_retraction_subtype_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) : ∃ f : (∀ n, E n) → s, (∀ x : s, f x = x) ∧ Surjective f ∧ Continuous f := by obtain ⟨f, fs, rfl, f_cont⟩ : ∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ Continuous f := exists_retraction_of_isClosed hs hne have A : ∀ x : range f, rangeFactorization f x = x := fun x ↦ Subtype.eq <| fs x x.2 exact ⟨rangeFactorization f, A, fun x => ⟨x, A x⟩, f_cont.subtype_mk _⟩ end PiNat open PiNat /-- Any nonempty complete second countable metric space is the continuous image of the fundamental space `ℕ → ℕ`. For a version of this theorem in the context of Polish spaces, see `exists_nat_nat_continuous_surjective_of_polishSpace`. -/ theorem exists_nat_nat_continuous_surjective_of_completeSpace (α : Type*) [MetricSpace α] [CompleteSpace α] [SecondCountableTopology α] [Nonempty α] : ∃ f : (ℕ → ℕ) → α, Continuous f ∧ Surjective f := by /- First, we define a surjective map from a closed subset `s` of `ℕ → ℕ`. Then, we compose this map with a retraction of `ℕ → ℕ` onto `s` to obtain the desired map. Let us consider a dense sequence `u` in `α`. Then `s` is the set of sequences `xₙ` such that the balls `closedBall (u xₙ) (1/2^n)` have a nonempty intersection. This set is closed, and we define `f x` there to be the unique point in the intersection. This function is continuous and surjective by design. -/ letI : MetricSpace (ℕ → ℕ) := PiNat.metricSpaceNatNat have I0 : (0 : ℝ) < 1 / 2 := by simp have I1 : (1 / 2 : ℝ) < 1 := by norm_num rcases exists_dense_seq α with ⟨u, hu⟩ let s : Set (ℕ → ℕ) := { x | (⋂ n : ℕ, closedBall (u (x n)) ((1 / 2) ^ n)).Nonempty } let g : s → α := fun x => x.2.some have A : ∀ (x : s) (n : ℕ), dist (g x) (u ((x : ℕ → ℕ) n)) ≤ (1 / 2) ^ n := fun x n => (mem_iInter.1 x.2.some_mem n :) have g_cont : Continuous g := by refine continuous_iff_continuousAt.2 fun y => ?_ refine continuousAt_of_locally_lipschitz zero_lt_one 4 fun x hxy => ?_ rcases eq_or_ne x y with (rfl | hne) · simp have hne' : x.1 ≠ y.1 := Subtype.coe_injective.ne hne have dist' : dist x y = dist x.1 y.1 := rfl let n := firstDiff x.1 y.1 - 1 have diff_pos : 0 < firstDiff x.1 y.1 := by by_contra! h apply apply_firstDiff_ne hne' rw [Nat.le_zero.1 h] apply apply_eq_of_dist_lt _ le_rfl rw [pow_zero] exact hxy have hn : firstDiff x.1 y.1 = n + 1 := (Nat.succ_pred_eq_of_pos diff_pos).symm rw [dist', dist_eq_of_ne hne', hn] have B : x.1 n = y.1 n := mem_cylinder_firstDiff x.1 y.1 n (Nat.pred_lt diff_pos.ne') calc dist (g x) (g y) ≤ dist (g x) (u (x.1 n)) + dist (g y) (u (x.1 n)) := dist_triangle_right _ _ _ _ = dist (g x) (u (x.1 n)) + dist (g y) (u (y.1 n)) := by rw [← B] _ ≤ (1 / 2) ^ n + (1 / 2) ^ n := add_le_add (A x n) (A y n) _ = 4 * (1 / 2) ^ (n + 1) := by ring have g_surj : Surjective g := fun y ↦ by have : ∀ n : ℕ, ∃ j, y ∈ closedBall (u j) ((1 / 2) ^ n) := fun n ↦ by rcases hu.exists_dist_lt y (by simp : (0 : ℝ) < (1 / 2) ^ n) with ⟨j, hj⟩ exact ⟨j, hj.le⟩ choose x hx using this have I : (⋂ n : ℕ, closedBall (u (x n)) ((1 / 2) ^ n)).Nonempty := ⟨y, mem_iInter.2 hx⟩ refine ⟨⟨x, I⟩, ?_⟩ refine dist_le_zero.1 ?_ have J : ∀ n : ℕ, dist (g ⟨x, I⟩) y ≤ (1 / 2) ^ n + (1 / 2) ^ n := fun n => calc dist (g ⟨x, I⟩) y ≤ dist (g ⟨x, I⟩) (u (x n)) + dist y (u (x n)) := dist_triangle_right _ _ _ _ ≤ (1 / 2) ^ n + (1 / 2) ^ n := add_le_add (A ⟨x, I⟩ n) (hx n) have L : Tendsto (fun n : ℕ => (1 / 2 : ℝ) ^ n + (1 / 2) ^ n) atTop (𝓝 (0 + 0)) := (tendsto_pow_atTop_nhds_zero_of_lt_one I0.le I1).add (tendsto_pow_atTop_nhds_zero_of_lt_one I0.le I1) rw [add_zero] at L exact ge_of_tendsto' L J have s_closed : IsClosed s := by refine isClosed_iff_clusterPt.mpr fun x hx ↦ ?_ have L : Tendsto (fun n : ℕ => diam (closedBall (u (x n)) ((1 / 2) ^ n))) atTop (𝓝 0) := by have : Tendsto (fun n : ℕ => (2 : ℝ) * (1 / 2) ^ n) atTop (𝓝 (2 * 0)) := (tendsto_pow_atTop_nhds_zero_of_lt_one I0.le I1).const_mul _ rw [mul_zero] at this exact squeeze_zero (fun n => diam_nonneg) (fun n => diam_closedBall (pow_nonneg I0.le _)) this refine nonempty_iInter_of_nonempty_biInter (fun n => isClosed_closedBall) (fun n => isBounded_closedBall) (fun N ↦ ?_) L obtain ⟨y, hxy, ys⟩ : ∃ y, y ∈ ball x ((1 / 2) ^ N) ∩ s := clusterPt_principal_iff.1 hx _ (ball_mem_nhds x (pow_pos I0 N)) have E : ⋂ (n : ℕ) (H : n ≤ N), closedBall (u (x n)) ((1 / 2) ^ n) = ⋂ (n : ℕ) (H : n ≤ N), closedBall (u (y n)) ((1 / 2) ^ n) := by refine iInter_congr fun n ↦ iInter_congr fun hn ↦ ?_ have : x n = y n := apply_eq_of_dist_lt (mem_ball'.1 hxy) hn rw [this] rw [E] apply Nonempty.mono _ ys apply iInter_subset_iInter₂ obtain ⟨f, -, f_surj, f_cont⟩ : ∃ f : (ℕ → ℕ) → s, (∀ x : s, f x = x) ∧ Surjective f ∧ Continuous f := by apply exists_retraction_subtype_of_isClosed s_closed simpa only [nonempty_coe_sort] using g_surj.nonempty exact ⟨g ∘ f, g_cont.comp f_cont, g_surj.comp f_surj⟩ open Encodable ENNReal namespace PiCountable /-! ### Products of (possibly non-discrete) metric spaces -/ variable {ι : Type*} [Encodable ι] {F : ι → Type*} section EDist variable [∀ i, EDist (F i)] {x y : ∀ i, F i} {i : ι} {r : ℝ≥0∞} /-- Given a countable family of extended metric spaces, one may put an extended distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `edist x y = ∑' i, min (1/2)^(encode i) (edist (x i) (y i))`. -/ protected def edist : EDist (∀ i, F i) where edist x y := ∑' i, min (2⁻¹ ^ encode i) (edist (x i) (y i)) attribute [scoped instance] PiCountable.edist lemma edist_eq_tsum (x y : ∀ i, F i) : edist x y = ∑' i, min (2⁻¹ ^ encode i) (edist (x i) (y i)) := rfl lemma min_edist_le_edist_pi (x y : ∀ i, F i) (i : ι) : min (2⁻¹ ^ encode i) (edist (x i) (y i)) ≤ edist x y := ENNReal.le_tsum _ lemma edist_le_two : edist x y ≤ 2 := (ENNReal.tsum_geometric_two_encode_le_two).trans' <| by rw [edist_eq_tsum]; gcongr; exact min_le_left .. lemma edist_lt_top : edist x y < ∞ := edist_le_two.trans_lt (by simp) lemma edist_le_edist_pi_of_edist_lt (h : edist x y < 2⁻¹ ^ encode i) : edist (x i) (y i) ≤ edist x y := by simpa only [not_le.2 h, false_or] using min_le_iff.1 (min_edist_le_edist_pi x y i) end EDist attribute [scoped instance] PiCountable.edist section PseudoEMetricSpace variable [∀ i, PseudoEMetricSpace (F i)] /-- Given a countable family of extended pseudo metric spaces, one may put an extended distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `edist x y = ∑' i, min (1/2)^(encode i) (edist (x i) (y i))`. -/ protected def pseudoEMetricSpace : PseudoEMetricSpace (∀ i, F i) where edist_self x := by simp [edist_eq_tsum] edist_comm x y := by simp [edist_eq_tsum, edist_comm] edist_triangle x y z := calc ∑' i, min (2⁻¹ ^ encode i) (edist (x i) (z i)) _ ≤ ∑' i, (min (2⁻¹ ^ encode i) (edist (x i) (y i)) + min (2⁻¹ ^ encode i) (edist (y i) (z i))) := by gcongr with n; grw [edist_triangle _ (y n), min_add_distrib, min_le_right] _ = _ := ENNReal.tsum_add .. toUniformSpace := Pi.uniformSpace _ uniformity_edist := by simp only [Pi.uniformity, comap_iInf, gt_iff_lt, preimage_setOf_eq, comap_principal, PseudoEMetricSpace.uniformity_edist, le_antisymm_iff, le_iInf_iff, le_principal_iff] constructor · intro ε hε classical obtain ⟨K, hK⟩ : ∃ K : Finset ι, ∑' i : {j // j ∉ K}, 2⁻¹ ^ encode (i : ι) < ε / 2 := ((tendsto_order.1 <| ENNReal.tendsto_tsum_compl_atTop_zero (tsum_geometric_encode_lt_top ENNReal.one_half_lt_one).ne).2 _ <| by simpa using hε.ne').exists obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ δ * K.card < ε / 2 := ENNReal.exists_pos_mul_lt (by simp) (by simpa using hε.ne') apply @mem_iInf_of_iInter _ _ _ _ _ K.finite_toSet fun i => {p : (∀ i : ι, F i) × ∀ i : ι, F i | edist (p.fst i) (p.snd i) < δ} · rintro ⟨i, hi⟩ refine mem_iInf_of_mem δ (mem_iInf_of_mem δpos ?_) simp only [mem_principal, Subset.rfl] · rintro ⟨x, y⟩ hxy simp only [mem_iInter, mem_setOf_eq, SetCoe.forall, Finset.mem_coe] at hxy calc edist x y = ∑' i : ι, min (2⁻¹ ^ encode i) (edist (x i) (y i)) := rfl _ = ∑ i ∈ K, min (2⁻¹ ^ encode i) (edist (x i) (y i)) + ∑' i : ↑(K : Set ι)ᶜ, min (2⁻¹ ^ encode (i : ι)) (edist (x i) (y i)) := (ENNReal.sum_add_tsum_compl ..).symm _ ≤ ∑ i ∈ K, edist (x i) (y i) + ∑' i : ↑(K : Set ι)ᶜ, 2⁻¹ ^ encode (i : ι) := by gcongr · apply min_le_right · apply min_le_left _ < ∑ _i ∈ K, δ + ε / 2 := by refine ENNReal.add_lt_add_of_le_of_lt (by simpa using fun i hi ↦ (hxy i hi).ne_top) ?_ hK gcongr with i hi exact (hxy i hi).le _ ≤ ε / 2 + ε / 2 := by gcongr; simpa [mul_comm] using hδ.le _ = ε := ENNReal.add_halves _ · intro i ε hε₀ have : (0 : ℝ≥0∞) < 2⁻¹ ^ encode i := ENNReal.pow_pos (by norm_num) _ refine mem_iInf_of_mem (min (2⁻¹ ^ encode i) ε) <| mem_iInf_of_mem (by positivity) ?_ simp only [and_imp, Prod.forall, setOf_subset_setOf, lt_min_iff, mem_principal] intro x y hn exact (edist_le_edist_pi_of_edist_lt hn).trans_lt end PseudoEMetricSpace attribute [scoped instance] PiCountable.pseudoEMetricSpace section EMetricSpace variable [∀ i, EMetricSpace (F i)] /-- Given a countable family of extended metric spaces, one may put an extended distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `edist x y = ∑' i, min (1/2)^(encode i) (edist (x i) (y i))`. -/ protected def emetricSpace : EMetricSpace (∀ i, F i) where eq_of_edist_eq_zero := by simp [edist_eq_tsum, funext_iff] end EMetricSpace attribute [scoped instance] PiCountable.emetricSpace section PseudoMetricSpace variable [∀ i, PseudoMetricSpace (F i)] {x y : ∀ i, F i} {i : ι} /-- Given a countable family of metric spaces, one may put a distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. -/ protected def dist : Dist (∀ i, F i) where dist x y := ∑' i, min (2⁻¹ ^ encode i) (dist (x i) (y i)) attribute [scoped instance] PiCountable.dist lemma dist_eq_tsum (x y : ∀ i, F i) : dist x y = ∑' i, min (2⁻¹ ^ encode i) (dist (x i) (y i)) := rfl lemma dist_summable (x y : ∀ i, F i) : Summable fun i ↦ min (2⁻¹ ^ encode i) (dist (x i) (y i)) := by refine .of_nonneg_of_le (fun i => ?_) (fun i => min_le_left _ _) <| by simpa [one_div] using summable_geometric_two_encode exact le_min (by positivity) dist_nonneg lemma min_dist_le_dist_pi (x y : ∀ i, F i) (i : ι) : min (2⁻¹ ^ encode i) (dist (x i) (y i)) ≤ dist x y := (dist_summable x y).le_tsum i fun j _ => le_min (by simp) dist_nonneg lemma dist_le_dist_pi_of_dist_lt (h : dist x y < 2⁻¹ ^ encode i) : dist (x i) (y i) ≤ dist x y := by simpa only [not_le.2 h, false_or] using min_le_iff.1 (min_dist_le_dist_pi x y i) /-- Given a countable family of metric spaces, one may put a distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. -/ protected def pseudoMetricSpace : PseudoMetricSpace (∀ i, F i) := PseudoEMetricSpace.toPseudoMetricSpaceOfDist dist (fun x y ↦ by simp [dist_eq_tsum]; positivity) fun x y ↦ by rw [edist_eq_tsum, dist_eq_tsum, ENNReal.ofReal_tsum_of_nonneg (fun _ ↦ by positivity) (dist_summable ..)] simp [edist, ENNReal.inv_pow] congr! with a exact PseudoMetricSpace.edist_dist (x a) (y a) end PseudoMetricSpace attribute [scoped instance] PiCountable.pseudoMetricSpace section MetricSpace variable [∀ i, MetricSpace (F i)] /-- Given a countable family of metric spaces, one may put a distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is edist x y = ∑' i, min (1/2)^(encode i) (edist (x i) (y i))`. -/ protected def metricSpace : MetricSpace (∀ i, F i) := EMetricSpace.toMetricSpaceOfDist dist (by simp) (by simp [edist_dist]) end MetricSpace end PiCountable /-! ### Embedding a countably separated space inside a space of sequences -/ namespace Metric open scoped PiCountable variable {ι X : Type*} {Y : ι → Type*} {f : ∀ i, X → Y i} include f in variable (X Y f) in /-- Given a type `X` and a sequence `Y` of metric spaces and a sequence `f : : ∀ i, X → Y i` of separating functions, `PiNatEmbed X Y f` is a type synonym for `X` seen as a subset of `∀ i, Y i`. -/ structure PiNatEmbed (X : Type*) (Y : ι → Type*) (f : ∀ i, X → Y i) where /-- The map from `X` to the subset of `∀ i, Y i`. -/ toPiNat :: /-- The map from the subset of `∀ i, Y i` to `X`. -/ ofPiNat : X namespace PiNatEmbed @[ext] lemma ext {x y : PiNatEmbed X Y f} (hxy : x.ofPiNat = y.ofPiNat) : x = y := by cases x; congr! variable (X Y f) in /-- Equivalence between `X` and its embedding into `∀ i, Y i`. -/ @[simps] def toPiNatEquiv : X ≃ PiNatEmbed X Y f where toFun := toPiNat invFun := ofPiNat left_inv _ := rfl right_inv _ := rfl @[simp] lemma ofPiNat_inj {x y : PiNatEmbed X Y f} : x.ofPiNat = y.ofPiNat ↔ x = y := (toPiNatEquiv X Y f).symm.injective.eq_iff @[simp] lemma «forall» {P : PiNatEmbed X Y f → Prop} : (∀ x, P x) ↔ ∀ x, P (toPiNat x) := (toPiNatEquiv X Y f).symm.forall_congr_left variable (X Y f) in /-- `X` equipped with the distance coming from `∀ i, Y i` embeds in `∀ i, Y i`. -/ noncomputable def embed : PiNatEmbed X Y f → ∀ i, Y i := fun x i ↦ f i x.ofPiNat lemma embed_injective (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : Injective (embed X Y f) := by simpa [Pairwise, not_imp_comm (a := _ = _), funext_iff, Function.Injective] using separating_f variable [Encodable ι] section PseudoEMetricSpace variable [∀ i, PseudoEMetricSpace (Y i)] noncomputable instance : PseudoEMetricSpace (PiNatEmbed X Y f) := .induced (embed X Y f) PiCountable.pseudoEMetricSpace lemma edist_def (x y : PiNatEmbed X Y f) : edist x y = ∑' i, min (2⁻¹ ^ encode i) (edist (f i x.ofPiNat) (f i y.ofPiNat)) := rfl lemma isometry_embed : Isometry (embed X Y f) := PseudoEMetricSpace.isometry_induced _ end PseudoEMetricSpace section PseudoMetricSpace variable [∀ i, PseudoMetricSpace (Y i)] noncomputable instance : PseudoMetricSpace (PiNatEmbed X Y f) := .induced (embed X Y f) PiCountable.pseudoMetricSpace lemma dist_def (x y : PiNatEmbed X Y f) : dist x y = ∑' i, min (2⁻¹ ^ encode i) (dist (f i x.ofPiNat) (f i y.ofPiNat)) := rfl variable [TopologicalSpace X] lemma continuous_toPiNat (continuous_f : ∀ i, Continuous (f i)) : Continuous (toPiNat : X → PiNatEmbed X Y f) := by rw [continuous_iff_continuous_dist] simp only [dist_def] apply continuous_tsum (by fun_prop) summable_geometric_two_encode <| by simp [abs_of_nonneg] end PseudoMetricSpace section EMetricSpace variable [∀ i, EMetricSpace (Y i)] /-- If the functions `f i : X → Y i` separate points of `X`, then `X` can be embedded into `∀ i, Y i`. -/ noncomputable abbrev emetricSpace (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : EMetricSpace (PiNatEmbed X Y f) := .induced (embed X Y f) (embed_injective separating_f) PiCountable.emetricSpace lemma isUniformEmbedding_embed (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : IsUniformEmbedding (embed X Y f) := let := emetricSpace separating_f; isometry_embed.isUniformEmbedding end EMetricSpace section MetricSpace variable [∀ i, MetricSpace (Y i)] /-- If the functions `f i : X → Y i` separate points of `X`, then `X` can be embedded into `∀ i, Y i`. -/ noncomputable abbrev metricSpace (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : MetricSpace (PiNatEmbed X Y f) := (emetricSpace separating_f).toMetricSpace fun x y ↦ by simp [edist_dist] section CompactSpace variable [TopologicalSpace X] [CompactSpace X] lemma isHomeomorph_toPiNat (continuous_f : ∀ i, Continuous (f i)) (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : IsHomeomorph (toPiNat : X → PiNatEmbed X Y f) := by letI := emetricSpace separating_f rw [isHomeomorph_iff_continuous_bijective] exact ⟨continuous_toPiNat continuous_f, (toPiNatEquiv X Y f).bijective⟩ variable (X Y f) in /-- Homeomorphism between `X` and its embedding into `∀ i, Y i` induced by a separating family of continuous functions `f i : X → Y i`. -/ @[simps!] noncomputable def toPiNatHomeo (continuous_f : ∀ i, Continuous (f i)) (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : X ≃ₜ PiNatEmbed X Y f := (toPiNatEquiv X Y f).toHomeomorphOfIsInducing (isHomeomorph_toPiNat continuous_f separating_f).isInducing /-- If `X` is compact, and there exists a sequence of continuous functions `f i : X → Y i` to metric spaces `Y i` that separate points on `X`, then `X` is metrizable. -/ lemma TopologicalSpace.MetrizableSpace.of_countable_separating (f : ∀ i, X → Y i) (continuous_f : ∀ i, Continuous (f i)) (separating_f : Pairwise fun x y ↦ ∃ i, f i x ≠ f i y) : MetrizableSpace X := letI := Metric.PiNatEmbed.metricSpace separating_f (Metric.PiNatEmbed.toPiNatHomeo X Y f continuous_f separating_f).isEmbedding.metrizableSpace end CompactSpace end MetricSpace end PiNatEmbed end Metric
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Sequences.lean
import Mathlib.Topology.Sequences import Mathlib.Topology.MetricSpace.Bounded /-! # Sequential compacts in metric spaces In this file we prove 2 versions of Bolzano-Weierstrass theorem for proper metric spaces. -/ open Filter Bornology Metric open scoped Topology variable {X : Type*} [PseudoMetricSpace X] variable [ProperSpace X] {s : Set X} /-- A version of **Bolzano-Weierstrass**: in a proper metric space (e.g. $ℝ^n$), every bounded sequence has a converging subsequence. This version assumes only that the sequence is frequently in some bounded set. -/ theorem tendsto_subseq_of_frequently_bounded (hs : IsBounded s) {x : ℕ → X} (hx : ∃ᶠ n in atTop, x n ∈ s) : ∃ a ∈ closure s, ∃ φ : ℕ → ℕ, StrictMono φ ∧ Tendsto (x ∘ φ) atTop (𝓝 a) := have hcs : IsSeqCompact (closure s) := hs.isCompact_closure.isSeqCompact have hu' : ∃ᶠ n in atTop, x n ∈ closure s := hx.mono fun _n hn => subset_closure hn hcs.subseq_of_frequently_in hu' /-- A version of **Bolzano-Weierstrass**: in a proper metric space (e.g. $ℝ^n$), every bounded sequence has a converging subsequence. -/ theorem tendsto_subseq_of_bounded (hs : IsBounded s) {x : ℕ → X} (hx : ∀ n, x n ∈ s) : ∃ a ∈ closure s, ∃ φ : ℕ → ℕ, StrictMono φ ∧ Tendsto (x ∘ φ) atTop (𝓝 a) := tendsto_subseq_of_frequently_bounded hs <| Frequently.of_forall hx
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/HausdorffAlexandroff.lean
import Mathlib.Topology.Compactness.HilbertCubeEmbedding import Mathlib.Topology.Instances.CantorSet import Mathlib.Topology.MetricSpace.PiNat /-! # Hausdorff–Alexandroff Theorem In this file, we prove the Hausdorff–Alexandroff theorem, which states that every nonempty compact metric space is a continuous image of the Cantor set. ## Main theorems * `exists_nat_bool_continuous_surjective_of_compact`: Hausdorff–Alexandroff Theorem. ## Proof Outline First, note that the Cantor set is homeomorphic to `ℕ → Bool`, as shown in `cantorSetHomeomorphNatToBool`. Therefore, in this file, we work only with the space `ℕ → Bool` and refer to it as the "Cantor space". The proof consists of three steps. Let `X` be a compact metric space. 1. Every compact metric space is homeomorphic to a closed subset of the Hilbert cube. This is already proved in `exists_closed_embedding_to_hilbert_cube`. Using this result, we may assume that `X` is a closed subset of the Hilbert cube. 2. We construct a continuous surjection `cantorToHilbert` from the Cantor space to the Hilbert cube. 3. Taking the preimage of `X` under this surjection, it remains to prove that any closed subset of the Cantor space is the continuous image of the Cantor space. -/ namespace Real /-- Convert a sequence of binary digits to a real number from `unitInterval`. -/ noncomputable def fromBinary : (ℕ → Bool) → unitInterval := let φ : (ℕ → Bool) ≃ₜ (ℕ → Fin 2) := Homeomorph.piCongrRight (fun _ ↦ finTwoEquiv.toHomeomorphOfDiscrete.symm) Subtype.coind (ofDigits ∘ φ) (fun _ ↦ ⟨ofDigits_nonneg _, ofDigits_le_one _⟩) theorem fromBinary_continuous : Continuous fromBinary := Continuous.subtype_mk (continuous_ofDigits.comp' (Homeomorph.continuous _)) _ theorem fromBinary_surjective : fromBinary.Surjective := by refine Subtype.coind_surjective _ ((ofDigits_SurjOn (by norm_num)).comp ?_) simp only [Set.surjOn_univ, Homeomorph.surjective _] end Real open Real /-- A continuous surjection from the Cantor space to the Hilbert cube. -/ noncomputable def cantorToHilbert (x : ℕ → Bool) : ℕ → unitInterval := Pi.map (fun _ b ↦ fromBinary b) (cantorSpaceHomeomorphNatToCantorSpace x) theorem cantorToHilbert_continuous : Continuous cantorToHilbert := continuous_pi (fun _ ↦ fromBinary_continuous.comp (by fun_prop)) theorem cantorToHilbert_surjective : cantorToHilbert.Surjective := (Function.Surjective.piMap (fun _ ↦ fromBinary_surjective)).comp cantorSpaceHomeomorphNatToCantorSpace.surjective attribute [local instance] PiNat.metricSpace in theorem exists_retractionCantorSet {X : Set (ℕ → Bool)} (h_closed : IsClosed X) (h_nonempty : X.Nonempty) : ∃ f : (ℕ → Bool) → (ℕ → Bool), Continuous f ∧ Set.range f = X := by obtain ⟨f, fs, frange, hf⟩ := PiNat.exists_lipschitz_retraction_of_isClosed h_closed h_nonempty exact ⟨f, hf.continuous, frange⟩ /-- **Hausdorff–Alexandroff theorem**: every nonempty compact metric space is a continuous image of the Cantor set. -/ theorem exists_nat_bool_continuous_surjective_of_compact (X : Type*) [Nonempty X] [MetricSpace X] [CompactSpace X] : ∃ f : (ℕ → Bool) → X, Continuous f ∧ Function.Surjective f := by -- `X` is homeomorphic to a closed subset `KH` of the Hilbert cube. obtain ⟨emb, h_emb⟩ := exists_closed_embedding_to_hilbert_cube X let KH : Set (ℕ → unitInterval) := Set.range emb let g : X ≃ₜ KH := h_emb.toIsEmbedding.toHomeomorph -- `KC` is the closed preimage of `KH` under the continuous surjection `cantorToHilbert`. let KC : Set (ℕ → Bool) := cantorToHilbert ⁻¹' KH have hKC_closed : IsClosed KC := IsClosed.preimage cantorToHilbert_continuous (Topology.IsClosedEmbedding.isClosed_range h_emb) have hKC_nonempty : KC.Nonempty := Set.Nonempty.preimage (Set.range_nonempty emb) cantorToHilbert_surjective -- Take a retraction `f'` from the Cantor space to `KC`. obtain ⟨f, hf_continuous, hf_surjective⟩ := exists_retractionCantorSet hKC_closed hKC_nonempty let f' : (ℕ → Bool) → KC := Subtype.coind f (by simp [← hf_surjective]) have hf'_continuous : Continuous f' := Continuous.subtype_mk hf_continuous _ have hf'_surjective : Function.Surjective f' := Subtype.coind_surjective _ (by grind [Set.SurjOn]) -- Let `h` be the restriction of `cantorToHilbert` to `KC → KH`. let h : KC → KH := KH.restrictPreimage cantorToHilbert have hh_continuous : Continuous h := Continuous.restrictPreimage cantorToHilbert_continuous have hh_surjective : Function.Surjective h := Set.restrictPreimage_surjective _ cantorToHilbert_surjective -- Take the composition `g.symm ∘ h ∘ f'` as the desired continuous surjection from the Cantor -- space to `X`. exact ⟨g.symm ∘ h ∘ f', by fun_prop, g.symm.surjective.comp <| hh_surjective.comp hf'_surjective⟩
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/ProperSpace/Lemmas.lean
import Mathlib.Topology.Order.Compact import Mathlib.Topology.MetricSpace.ProperSpace import Mathlib.Topology.Order.IntermediateValue import Mathlib.Topology.Order.LocalExtr /-! # Proper spaces This file contains some more involved results about `ProperSpace`s. ## Main definitions and results * `exists_pos_lt_subset_ball` * `exists_lt_subset_ball` * `Metric.exists_isLocalMin_mem_ball` -/ open Set Metric variable {α : Type*} {β : Type*} [PseudoMetricSpace α] [ProperSpace α] {x : α} {r : ℝ} {s : Set α} /-- If a nonempty ball in a proper space includes a closed set `s`, then there exists a nonempty ball with the same center and a strictly smaller radius that includes `s`. -/ theorem exists_pos_lt_subset_ball (hr : 0 < r) (hs : IsClosed s) (h : s ⊆ ball x r) : ∃ r' ∈ Ioo 0 r, s ⊆ ball x r' := by rcases eq_empty_or_nonempty s with (rfl | hne) · exact ⟨r / 2, ⟨half_pos hr, half_lt_self hr⟩, empty_subset _⟩ have : IsCompact s := (isCompact_closedBall x r).of_isClosed_subset hs (h.trans ball_subset_closedBall) obtain ⟨y, hys, hy⟩ : ∃ y ∈ s, s ⊆ closedBall x (dist y x) := this.exists_isMaxOn (β := α) (α := ℝ) hne (continuous_id.dist continuous_const).continuousOn have hyr : dist y x < r := h hys rcases exists_between hyr with ⟨r', hyr', hrr'⟩ exact ⟨r', ⟨dist_nonneg.trans_lt hyr', hrr'⟩, hy.trans <| closedBall_subset_ball hyr'⟩ /-- If a ball in a proper space includes a closed set `s`, then there exists a ball with the same center and a strictly smaller radius that includes `s`. -/ theorem exists_lt_subset_ball (hs : IsClosed s) (h : s ⊆ ball x r) : ∃ r' < r, s ⊆ ball x r' := by rcases le_or_gt r 0 with hr | hr · rw [ball_eq_empty.2 hr, subset_empty_iff] at h subst s exact (exists_lt r).imp fun r' hr' => ⟨hr', empty_subset _⟩ · exact (exists_pos_lt_subset_ball hr hs h).imp fun r' hr' => ⟨hr'.1.2, hr'.2⟩ theorem Metric.exists_isLocalMin_mem_ball [TopologicalSpace β] [ConditionallyCompleteLinearOrder β] [OrderTopology β] {f : α → β} {a z : α} {r : ℝ} (hf : ContinuousOn f (closedBall a r)) (hz : z ∈ closedBall a r) (hf1 : ∀ z' ∈ sphere a r, f z < f z') : ∃ z ∈ ball a r, IsLocalMin f z := by simp_rw [← closedBall_diff_ball] at hf1 exact (isCompact_closedBall a r).exists_isLocalMin_mem_open ball_subset_closedBall hf hz hf1 isOpen_ball
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/ProperSpace/Real.lean
import Mathlib.Data.Rat.Encodable import Mathlib.Topology.MetricSpace.Isometry import Mathlib.Topology.MetricSpace.ProperSpace import Mathlib.Topology.Order.Compact import Mathlib.Topology.Order.MonotoneContinuity import Mathlib.Topology.Order.Real import Mathlib.Topology.UniformSpace.Real /-! # Second countability of the reals We prove that `ℝ`, `EReal`, `ℝ≥0` and `ℝ≥0∞` are second countable. In the process, we also provide instances `ProperSpace ℝ` and `ProperSpace ℝ≥0`. -/ assert_not_exists IsTopologicalRing UniformContinuousConstSMul UniformOnFun noncomputable section open Set Topology TopologicalSpace instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper namespace EReal instance : SecondCountableTopology EReal := have : SeparableSpace EReal := ⟨⟨_, countable_range _, denseRange_ratCast⟩⟩ .of_separableSpace_orderTopology _ end EReal namespace NNReal /-! Instances for `ℝ≥0` are inherited from the corresponding structures on the reals. -/ instance : SecondCountableTopology ℝ≥0 := inferInstanceAs (SecondCountableTopology { x : ℝ | 0 ≤ x }) instance instProperSpace : ProperSpace ℝ≥0 where isCompact_closedBall x r := by have emb : IsClosedEmbedding ((↑) : ℝ≥0 → ℝ) := Isometry.isClosedEmbedding fun _ ↦ congrFun rfl exact emb.isCompact_preimage (K := Metric.closedBall x r) (isCompact_closedBall _ _) end NNReal namespace ENNReal instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.isEmbedding.secondCountableTopology end ENNReal
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Ultra/ContinuousMaps.lean
import Mathlib.Topology.ContinuousMap.Compact import Mathlib.Topology.MetricSpace.Ultra.Basic /-! # Ultrametric structure on continuous maps -/ /-- Continuous maps from a compact space to an ultrametric space are an ultrametric space. -/ instance ContinuousMap.isUltrametricDist {X Y : Type*} [TopologicalSpace X] [CompactSpace X] [MetricSpace Y] [IsUltrametricDist Y] : IsUltrametricDist C(X, Y) := by constructor intro f g h rw [ContinuousMap.dist_le (by positivity)] refine fun x ↦ (dist_triangle_max (f x) (g x) (h x)).trans (max_le_max ?_ ?_) <;> exact ContinuousMap.dist_apply_le_dist x
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Ultra/Pi.lean
import Mathlib.Topology.MetricSpace.Pseudo.Pi import Mathlib.Topology.MetricSpace.Ultra.Basic /-! # Ultrametric distances on pi types This file contains results on the behavior of ultrametrics in products of ultrametric spaces. ## Main results * `Pi.instIsUltrametricDist`: a product of ultrametric spaces is ultrametric. ultrametric, nonarchimedean -/ instance Pi.instIsUltrametricDist {ι : Type*} {X : ι → Type*} [Fintype ι] [(i : ι) → PseudoMetricSpace (X i)] [(i : ι) → IsUltrametricDist (X i)] : IsUltrametricDist ((i : ι) → X i) := by constructor intro f g h simp only [dist_pi_def, ← NNReal.coe_max, NNReal.coe_le_coe, ← Finset.sup_sup] exact Finset.sup_mono_fun fun i _ ↦ IsUltrametricDist.dist_triangle_max (f i) (g i) (h i)
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Ultra/Basic.lean
import Mathlib.Topology.MetricSpace.Pseudo.Lemmas /-! ## Ultrametric spaces This file defines ultrametric spaces, implemented as a mixin on the `Dist`, so that it can apply on pseudometric spaces as well. ## Main definitions * `IsUltrametricDist X`: Annotates `dist : X → X → ℝ` as respecting the ultrametric inequality of `dist(x, z) ≤ max {dist(x,y), dist(y,z)}` ## Implementation details The mixin could have been defined as a hypothesis to be carried around, instead of relying on typeclass synthesis. However, since we declare a (pseudo)metric space on a type using typeclass arguments, one can declare the ultrametricity at the same time. For example, one could say `[Norm K] [Fact (IsNonarchimedean (norm : K → ℝ))]`, The file imports a later file in the hierarchy of pseudometric spaces, since `Metric.isClosed_closedBall` and `Metric.isClosed_sphere` is proven in a later file using more conceptual results. TODO: Generalize to ultrametric uniformities ## Tags ultrametric, nonarchimedean -/ variable {X : Type*} /-- The `dist : X → X → ℝ` respects the ultrametric inequality of `dist(x, z) ≤ max (dist(x,y)) (dist(y,z))`. -/ class IsUltrametricDist (X : Type*) [Dist X] : Prop where dist_triangle_max : ∀ x y z : X, dist x z ≤ max (dist x y) (dist y z) open Metric variable [PseudoMetricSpace X] [IsUltrametricDist X] (x y z : X) (r s : ℝ) lemma dist_triangle_max : dist x z ≤ max (dist x y) (dist y z) := IsUltrametricDist.dist_triangle_max x y z namespace IsUltrametricDist /-- All triangles are isosceles in an ultrametric space. -/ lemma dist_eq_max_of_dist_ne_dist (h : dist x y ≠ dist y z) : dist x z = max (dist x y) (dist y z) := by apply le_antisymm (dist_triangle_max x y z) rcases h.lt_or_gt with h | h · rw [max_eq_right h.le] apply (le_max_iff.mp <| dist_triangle_max y x z).resolve_left simpa only [not_le, dist_comm x y] using h · rw [max_eq_left h.le, dist_comm x y, dist_comm x z] apply (le_max_iff.mp <| dist_triangle_max y z x).resolve_left simpa only [not_le, dist_comm x y] using h instance subtype (p : X → Prop) : IsUltrametricDist (Subtype p) := ⟨fun _ _ _ ↦ by simpa [Subtype.dist_eq] using dist_triangle_max _ _ _⟩ lemma ball_eq_of_mem {x y : X} {r : ℝ} (h : y ∈ ball x r) : ball x r = ball y r := by ext a simp_rw [mem_ball] at h ⊢ constructor <;> intro h' <;> exact (dist_triangle_max _ _ _).trans_lt (max_lt h' (dist_comm x _ ▸ h)) @[deprecated (since := "2025-08-16")] alias mem_ball_iff := mem_ball_comm lemma ball_subset_trichotomy : ball x r ⊆ ball y s ∨ ball y s ⊆ ball x r ∨ Disjoint (ball x r) (ball y s) := by wlog hrs : r ≤ s generalizing x y r s · rw [disjoint_comm, ← or_assoc, or_comm (b := _ ⊆ _), or_assoc] exact this y x s r (lt_of_not_ge hrs).le · refine Set.disjoint_or_nonempty_inter (ball x r) (ball y s) |>.symm.imp (fun h ↦ ?_) (Or.inr ·) obtain ⟨hxz, hyz⟩ := (Set.mem_inter_iff _ _ _).mp h.some_mem have hx := ball_subset_ball hrs (x := x) rwa [ball_eq_of_mem hyz |>.trans (ball_eq_of_mem <| hx hxz).symm] lemma ball_eq_or_disjoint : ball x r = ball y r ∨ Disjoint (ball x r) (ball y r) := by refine Set.disjoint_or_nonempty_inter (ball x r) (ball y r) |>.symm.imp (fun h ↦ ?_) id have h₁ := ball_eq_of_mem <| Set.inter_subset_left h.some_mem have h₂ := ball_eq_of_mem <| Set.inter_subset_right h.some_mem exact h₁.trans h₂.symm lemma closedBall_eq_of_mem {x y : X} {r : ℝ} (h : y ∈ closedBall x r) : closedBall x r = closedBall y r := by ext simp_rw [mem_closedBall] at h ⊢ constructor <;> intro h' <;> exact (dist_triangle_max _ _ _).trans (max_le h' (dist_comm x _ ▸ h)) @[deprecated (since := "2025-08-16")] alias mem_closedBall_iff := mem_closedBall_comm lemma closedBall_subset_trichotomy : closedBall x r ⊆ closedBall y s ∨ closedBall y s ⊆ closedBall x r ∨ Disjoint (closedBall x r) (closedBall y s) := by wlog hrs : r ≤ s generalizing x y r s · rw [disjoint_comm, ← or_assoc, or_comm (b := _ ⊆ _), or_assoc] exact this y x s r (lt_of_not_ge hrs).le · refine Set.disjoint_or_nonempty_inter (closedBall x r) (closedBall y s) |>.symm.imp (fun h ↦ ?_) (Or.inr ·) obtain ⟨hxz, hyz⟩ := (Set.mem_inter_iff _ _ _).mp h.some_mem have hx := closedBall_subset_closedBall hrs (x := x) rwa [closedBall_eq_of_mem hyz |>.trans (closedBall_eq_of_mem <| hx hxz).symm] lemma isClosed_ball (x : X) (r : ℝ) : IsClosed (ball x r) := by cases le_or_gt r 0 with | inl hr => simp [ball_eq_empty.mpr hr] | inr h => rw [← isOpen_compl_iff, isOpen_iff] simp only [Set.mem_compl_iff, gt_iff_lt] intro y hy cases ball_eq_or_disjoint x y r with | inl hd => rw [hd] at hy simp [h.not_ge] at hy | inr hd => use r simp [h, ← Set.le_iff_subset, le_compl_iff_disjoint_left, hd] lemma isClopen_ball : IsClopen (ball x r) := ⟨isClosed_ball x r, isOpen_ball⟩ lemma frontier_ball_eq_empty : frontier (ball x r) = ∅ := isClopen_iff_frontier_eq_empty.mp (isClopen_ball x r) lemma closedBall_eq_or_disjoint : closedBall x r = closedBall y r ∨ Disjoint (closedBall x r) (closedBall y r) := by refine Set.disjoint_or_nonempty_inter (closedBall x r) (closedBall y r) |>.symm.imp (fun h ↦ ?_) id have h₁ := closedBall_eq_of_mem <| Set.inter_subset_left h.some_mem have h₂ := closedBall_eq_of_mem <| Set.inter_subset_right h.some_mem exact h₁.trans h₂.symm lemma isOpen_closedBall {r : ℝ} (hr : r ≠ 0) : IsOpen (closedBall x r) := by cases lt_or_gt_of_ne hr with | inl h => simp [closedBall_eq_empty.mpr h] | inr h => rw [isOpen_iff] simp only [gt_iff_lt] intro y hy cases closedBall_eq_or_disjoint x y r with | inl hd => use r simp [h, hd, ball_subset_closedBall] | inr hd => simp [closedBall_eq_of_mem hy, h.not_gt] at hd lemma isClopen_closedBall {r : ℝ} (hr : r ≠ 0) : IsClopen (closedBall x r) := ⟨Metric.isClosed_closedBall, isOpen_closedBall x hr⟩ lemma frontier_closedBall_eq_empty {r : ℝ} (hr : r ≠ 0) : frontier (closedBall x r) = ∅ := isClopen_iff_frontier_eq_empty.mp (isClopen_closedBall x hr) lemma isOpen_sphere {r : ℝ} (hr : r ≠ 0) : IsOpen (sphere x r) := by rw [← closedBall_diff_ball, sdiff_eq] exact (isOpen_closedBall x hr).inter (isClosed_ball x r).isOpen_compl lemma isClopen_sphere {r : ℝ} (hr : r ≠ 0) : IsClopen (sphere x r) := ⟨Metric.isClosed_sphere, isOpen_sphere x hr⟩ end IsUltrametricDist
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Ultra/TotallySeparated.lean
import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.MetricSpace.Defs import Mathlib.Topology.MetricSpace.Ultra.Basic /-! # Ultrametric spaces are totally separated In a metric space with an ultrametric, the space is totally separated, hence totally disconnected. ## Tags ultrametric, nonarchimedean, totally separated, totally disconnected -/ open Metric IsUltrametricDist instance {X : Type*} [MetricSpace X] [IsUltrametricDist X] : TotallySeparatedSpace X := totallySeparatedSpace_iff_exists_isClopen.mpr fun x y h ↦ by obtain ⟨r, hr, hr'⟩ := exists_between (dist_pos.mpr h) refine ⟨_, IsUltrametricDist.isClopen_ball x r, ?_, ?_⟩ · simp only [mem_ball, dist_self, hr] · simp only [Set.mem_compl, mem_ball, dist_comm, not_lt, hr'.le] example {X : Type*} [MetricSpace X] [IsUltrametricDist X] : TotallyDisconnectedSpace X := inferInstance
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Pseudo/Lemmas.lean
import Mathlib.Topology.MetricSpace.Pseudo.Constructions import Mathlib.Topology.Order.DenselyOrdered import Mathlib.Topology.UniformSpace.Compact /-! # Extra lemmas about pseudo-metric spaces -/ open Bornology Filter Metric Set open scoped NNReal Topology variable {ι α : Type*} [PseudoMetricSpace α] instance : OrderTopology ℝ := orderTopology_of_nhds_abs fun x => by simp only [nhds_basis_ball.eq_biInf, ball, Real.dist_eq, abs_sub_comm] lemma Real.singleton_eq_inter_Icc (b : ℝ) : {b} = ⋂ (r > 0), Icc (b - r) (b + r) := by simp [Icc_eq_closedBall, biInter_basis_nhds Metric.nhds_basis_closedBall] /-- Special case of the sandwich lemma; see `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/ lemma squeeze_zero' {α} {f g : α → ℝ} {t₀ : Filter α} (hf : ∀ᶠ t in t₀, 0 ≤ f t) (hft : ∀ᶠ t in t₀, f t ≤ g t) (g0 : Tendsto g t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 0) := tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds g0 hf hft /-- Special case of the sandwich lemma; see `tendsto_of_tendsto_of_tendsto_of_le_of_le` and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/ lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : Filter α} (hf : ∀ t, 0 ≤ f t) (hft : ∀ t, f t ≤ g t) (g0 : Tendsto g t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 0) := squeeze_zero' (Eventually.of_forall hf) (Eventually.of_forall hft) g0 /-- If `u` is a neighborhood of `x`, then for small enough `r`, the closed ball `Metric.closedBall x r` is contained in `u`. -/ lemma eventually_closedBall_subset {x : α} {u : Set α} (hu : u ∈ 𝓝 x) : ∀ᶠ r in 𝓝 (0 : ℝ), closedBall x r ⊆ u := by obtain ⟨ε, εpos, hε⟩ : ∃ ε, 0 < ε ∧ closedBall x ε ⊆ u := nhds_basis_closedBall.mem_iff.1 hu have : Iic ε ∈ 𝓝 (0 : ℝ) := Iic_mem_nhds εpos filter_upwards [this] with _ hr using Subset.trans (closedBall_subset_closedBall hr) hε lemma tendsto_closedBall_smallSets (x : α) : Tendsto (closedBall x) (𝓝 0) (𝓝 x).smallSets := tendsto_smallSets_iff.2 fun _ ↦ eventually_closedBall_subset namespace Metric variable {x y z : α} {ε ε₁ ε₂ : ℝ} {s : Set α} lemma isClosed_closedBall : IsClosed (closedBall x ε) := isClosed_le (continuous_id.dist continuous_const) continuous_const lemma isClosed_sphere : IsClosed (sphere x ε) := isClosed_eq (continuous_id.dist continuous_const) continuous_const @[simp] lemma closure_closedBall : closure (closedBall x ε) = closedBall x ε := isClosed_closedBall.closure_eq @[simp] lemma closure_sphere : closure (sphere x ε) = sphere x ε := isClosed_sphere.closure_eq lemma closure_ball_subset_closedBall : closure (ball x ε) ⊆ closedBall x ε := closure_minimal ball_subset_closedBall isClosed_closedBall lemma frontier_ball_subset_sphere : frontier (ball x ε) ⊆ sphere x ε := frontier_lt_subset_eq (continuous_id.dist continuous_const) continuous_const lemma frontier_closedBall_subset_sphere : frontier (closedBall x ε) ⊆ sphere x ε := frontier_le_subset_eq (continuous_id.dist continuous_const) continuous_const lemma closedBall_zero' (x : α) : closedBall x 0 = closure {x} := Subset.antisymm (fun _y hy => mem_closure_iff.2 fun _ε ε0 => ⟨x, mem_singleton x, (mem_closedBall.1 hy).trans_lt ε0⟩) (closure_minimal (singleton_subset_iff.2 (dist_self x).le) isClosed_closedBall) lemma eventually_isCompact_closedBall [WeaklyLocallyCompactSpace α] (x : α) : ∀ᶠ r in 𝓝 (0 : ℝ), IsCompact (closedBall x r) := by rcases exists_compact_mem_nhds x with ⟨s, s_compact, hs⟩ filter_upwards [eventually_closedBall_subset hs] with r hr exact IsCompact.of_isClosed_subset s_compact isClosed_closedBall hr lemma exists_isCompact_closedBall [WeaklyLocallyCompactSpace α] (x : α) : ∃ r, 0 < r ∧ IsCompact (closedBall x r) := by have : ∀ᶠ r in 𝓝[>] 0, IsCompact (closedBall x r) := eventually_nhdsWithin_of_eventually_nhds (eventually_isCompact_closedBall x) simpa only [and_comm] using (this.and self_mem_nhdsWithin).exists theorem biInter_gt_closedBall (x : α) (r : ℝ) : ⋂ r' > r, closedBall x r' = closedBall x r := by ext simp [forall_gt_imp_ge_iff_le_of_dense] theorem biInter_gt_ball (x : α) (r : ℝ) : ⋂ r' > r, ball x r' = closedBall x r := by ext simp [forall_gt_iff_le] theorem biUnion_lt_ball (x : α) (r : ℝ) : ⋃ r' < r, ball x r' = ball x r := by ext rw [← not_iff_not] simp [forall_lt_imp_le_iff_le_of_dense] theorem biUnion_lt_closedBall (x : α) (r : ℝ) : ⋃ r' < r, closedBall x r' = ball x r := by ext rw [← not_iff_not] simp [forall_lt_iff_le] end Metric theorem lebesgue_number_lemma_of_metric {s : Set α} {ι : Sort*} {c : ι → Set α} (hs : IsCompact s) (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, dist_comm] using uniformity_basis_dist.lebesgue_number_lemma hs hc₁ hc₂ theorem lebesgue_number_lemma_of_metric_sUnion {s : Set α} {c : Set (Set α)} (hs : IsCompact s) (hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t := by rw [sUnion_eq_iUnion] at hc₂; simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Pseudo/Pi.lean
import Mathlib.Data.ENNReal.Lemmas import Mathlib.Topology.Bornology.Constructions import Mathlib.Topology.EMetricSpace.Pi import Mathlib.Topology.MetricSpace.Pseudo.Defs /-! # Product of pseudometric spaces This file constructs the infinity distance on finite products of pseudometric spaces. -/ open Bornology Filter Metric Set open scoped NNReal Topology variable {α β : Type*} [PseudoMetricSpace α] open Finset variable {X : β → Type*} [Fintype β] [∀ b, PseudoMetricSpace (X b)] /-- A finite product of pseudometric spaces is a pseudometric space, with the sup distance. -/ instance pseudoMetricSpacePi : PseudoMetricSpace (∀ b, X b) := by /- we construct the instance from the pseudoemetric space instance to avoid checking again that the uniformity is the same as the product uniformity, but we register nevertheless a nice formula for the distance -/ let i := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun f g : ∀ b, X b => ((sup univ fun b => nndist (f b) (g b) : ℝ≥0) : ℝ)) (fun f g => NNReal.zero_le_coe) (fun f g => by simp [edist_pi_def]) refine i.replaceBornology fun s => ?_ simp only [isBounded_iff_eventually, ← forall_isBounded_image_eval_iff, forall_mem_image, ← Filter.eventually_all, @dist_nndist (X _)] refine eventually_congr ((eventually_ge_atTop 0).mono fun C hC ↦ ?_) lift C to ℝ≥0 using hC refine ⟨fun H x hx y hy ↦ NNReal.coe_le_coe.2 <| Finset.sup_le fun b _ ↦ H b hx hy, fun H b x hx y hy ↦ NNReal.coe_le_coe.2 ?_⟩ simpa only using Finset.sup_le_iff.1 (NNReal.coe_le_coe.1 <| H hx hy) b (Finset.mem_univ b) lemma nndist_pi_def (f g : ∀ b, X b) : nndist f g = sup univ fun b => nndist (f b) (g b) := rfl lemma dist_pi_def (f g : ∀ b, X b) : dist f g = (sup univ fun b => nndist (f b) (g b) : ℝ≥0) := rfl lemma nndist_pi_le_iff {f g : ∀ b, X b} {r : ℝ≥0} : nndist f g ≤ r ↔ ∀ b, nndist (f b) (g b) ≤ r := by simp [nndist_pi_def] lemma nndist_pi_lt_iff {f g : ∀ b, X b} {r : ℝ≥0} (hr : 0 < r) : nndist f g < r ↔ ∀ b, nndist (f b) (g b) < r := by simp [nndist_pi_def, Finset.sup_lt_iff hr] lemma nndist_pi_eq_iff {f g : ∀ b, X b} {r : ℝ≥0} (hr : 0 < r) : nndist f g = r ↔ (∃ i, nndist (f i) (g i) = r) ∧ ∀ b, nndist (f b) (g b) ≤ r := by rw [eq_iff_le_not_lt, nndist_pi_lt_iff hr, nndist_pi_le_iff, not_forall, and_comm] simp_rw [not_lt, and_congr_left_iff, le_antisymm_iff] intro h refine exists_congr fun b => ?_ apply (and_iff_right <| h _).symm lemma dist_pi_lt_iff {f g : ∀ b, X b} {r : ℝ} (hr : 0 < r) : dist f g < r ↔ ∀ b, dist (f b) (g b) < r := by lift r to ℝ≥0 using hr.le exact nndist_pi_lt_iff hr lemma dist_pi_le_iff {f g : ∀ b, X b} {r : ℝ} (hr : 0 ≤ r) : dist f g ≤ r ↔ ∀ b, dist (f b) (g b) ≤ r := by lift r to ℝ≥0 using hr exact nndist_pi_le_iff lemma dist_pi_eq_iff {f g : ∀ b, X b} {r : ℝ} (hr : 0 < r) : dist f g = r ↔ (∃ i, dist (f i) (g i) = r) ∧ ∀ b, dist (f b) (g b) ≤ r := by lift r to ℝ≥0 using hr.le simp_rw [← coe_nndist, NNReal.coe_inj, nndist_pi_eq_iff hr, NNReal.coe_le_coe] lemma dist_pi_le_iff' [Nonempty β] {f g : ∀ b, X b} {r : ℝ} : dist f g ≤ r ↔ ∀ b, dist (f b) (g b) ≤ r := by by_cases hr : 0 ≤ r · exact dist_pi_le_iff hr · exact iff_of_false (fun h => hr <| dist_nonneg.trans h) fun h => hr <| dist_nonneg.trans <| h <| Classical.arbitrary _ lemma dist_pi_const_le (a b : α) : (dist (fun _ : β => a) fun _ => b) ≤ dist a b := (dist_pi_le_iff dist_nonneg).2 fun _ => le_rfl lemma nndist_pi_const_le (a b : α) : (nndist (fun _ : β => a) fun _ => b) ≤ nndist a b := nndist_pi_le_iff.2 fun _ => le_rfl @[simp] lemma dist_pi_const [Nonempty β] (a b : α) : (dist (fun _ : β => a) fun _ => b) = dist a b := by simpa only [dist_edist] using congr_arg ENNReal.toReal (edist_pi_const a b) @[simp] lemma nndist_pi_const [Nonempty β] (a b : α) : (nndist (fun _ : β => a) fun _ => b) = nndist a b := NNReal.eq <| dist_pi_const a b lemma nndist_le_pi_nndist (f g : ∀ b, X b) (b : β) : nndist (f b) (g b) ≤ nndist f g := by rw [← ENNReal.coe_le_coe, ← edist_nndist, ← edist_nndist] exact edist_le_pi_edist f g b lemma dist_le_pi_dist (f g : ∀ b, X b) (b : β) : dist (f b) (g b) ≤ dist f g := by simp only [dist_nndist, NNReal.coe_le_coe, nndist_le_pi_nndist f g b] /-- An open ball in a product space is a product of open balls. See also `ball_pi'` for a version assuming `Nonempty β` instead of `0 < r`. -/ lemma ball_pi (x : ∀ b, X b) {r : ℝ} (hr : 0 < r) : ball x r = Set.pi univ fun b => ball (x b) r := by ext p simp [dist_pi_lt_iff hr] /-- An open ball in a product space is a product of open balls. See also `ball_pi` for a version assuming `0 < r` instead of `Nonempty β`. -/ lemma ball_pi' [Nonempty β] (x : ∀ b, X b) (r : ℝ) : ball x r = Set.pi univ fun b => ball (x b) r := (lt_or_ge 0 r).elim (ball_pi x) fun hr => by simp [ball_eq_empty.2 hr] /-- A closed ball in a product space is a product of closed balls. See also `closedBall_pi'` for a version assuming `Nonempty β` instead of `0 ≤ r`. -/ lemma closedBall_pi (x : ∀ b, X b) {r : ℝ} (hr : 0 ≤ r) : closedBall x r = Set.pi univ fun b => closedBall (x b) r := by ext p simp [dist_pi_le_iff hr] /-- A closed ball in a product space is a product of closed balls. See also `closedBall_pi` for a version assuming `0 ≤ r` instead of `Nonempty β`. -/ lemma closedBall_pi' [Nonempty β] (x : ∀ b, X b) (r : ℝ) : closedBall x r = Set.pi univ fun b => closedBall (x b) r := (le_or_gt 0 r).elim (closedBall_pi x) fun hr => by simp [closedBall_eq_empty.2 hr] /-- A sphere in a product space is a union of spheres on each component restricted to the closed ball. -/ lemma sphere_pi (x : ∀ b, X b) {r : ℝ} (h : 0 < r ∨ Nonempty β) : sphere x r = (⋃ i : β, Function.eval i ⁻¹' sphere (x i) r) ∩ closedBall x r := by obtain hr | rfl | hr := lt_trichotomy r 0 · simp [hr] · rw [closedBall_eq_sphere_of_nonpos le_rfl, eq_comm, Set.inter_eq_right] letI := h.resolve_left (lt_irrefl _) inhabit β refine subset_iUnion_of_subset default ?_ intro x hx replace hx := hx.le rw [dist_pi_le_iff le_rfl] at hx exact le_antisymm (hx default) dist_nonneg · ext simp [dist_pi_eq_iff hr, dist_pi_le_iff hr.le] @[simp] lemma Fin.nndist_insertNth_insertNth {n : ℕ} {α : Fin (n + 1) → Type*} [∀ i, PseudoMetricSpace (α i)] (i : Fin (n + 1)) (x y : α i) (f g : ∀ j, α (i.succAbove j)) : nndist (i.insertNth x f) (i.insertNth y g) = max (nndist x y) (nndist f g) := eq_of_forall_ge_iff fun c => by simp [nndist_pi_le_iff, i.forall_iff_succAbove] @[simp] lemma Fin.dist_insertNth_insertNth {n : ℕ} {α : Fin (n + 1) → Type*} [∀ i, PseudoMetricSpace (α i)] (i : Fin (n + 1)) (x y : α i) (f g : ∀ j, α (i.succAbove j)) : dist (i.insertNth x f) (i.insertNth y g) = max (dist x y) (dist f g) := by simp only [dist_nndist, Fin.nndist_insertNth_insertNth, NNReal.coe_max]
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Pseudo/Basic.lean
import Mathlib.Data.ENNReal.Real import Mathlib.Tactic.Bound.Attribute import Mathlib.Topology.EMetricSpace.Basic import Mathlib.Topology.MetricSpace.Pseudo.Defs /-! ## Pseudo-metric spaces Further results about pseudo-metric spaces. -/ open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v variable {α : Type u} {β : Type v} {ι : Type*} variable [PseudoMetricSpace α] /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, dist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, dist_self] | succ n hle ihn => calc dist (f m) (f (n + 1)) ≤ dist (f m) (f n) + dist (f n) (f (n + 1)) := dist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by rw [← Finset.insert_Ico_right_eq_Ico_add_one hle, Finset.sum_insert, add_comm]; simp /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, dist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_dist f (Nat.zero_le n) /-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (dist_le_Ico_sum_dist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 /-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_of_dist_le (zero_le n) fun _ => hd namespace Metric -- instantiate pseudometric space as a topology nonrec theorem isUniformInducing_iff [PseudoMetricSpace β] {f : α → β} : IsUniformInducing f ↔ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ := isUniformInducing_iff'.trans <| Iff.rfl.and <| ((uniformity_basis_dist.comap _).le_basis_iff uniformity_basis_dist).trans <| by simp only [subset_def, Prod.forall, gt_iff_lt, preimage_setOf_eq, Prod.map_apply, mem_setOf] nonrec theorem isUniformEmbedding_iff [PseudoMetricSpace β] {f : α → β} : IsUniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ := by rw [isUniformEmbedding_iff, and_comm, isUniformInducing_iff] /-- If a map between pseudometric spaces is a uniform embedding then the distance between `f x` and `f y` is controlled in terms of the distance between `x` and `y`. -/ theorem controlled_of_isUniformEmbedding [PseudoMetricSpace β] {f : α → β} (h : IsUniformEmbedding f) : (∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ := ⟨uniformContinuous_iff.1 h.uniformContinuous, (isUniformEmbedding_iff.1 h).2.2⟩ theorem totallyBounded_iff {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε := uniformity_basis_dist.totallyBounded_iff /-- A pseudometric space is totally bounded if one can reconstruct up to any ε>0 any element of the space from finitely many data. -/ theorem totallyBounded_of_finite_discretization {s : Set α} (H : ∀ ε > (0 : ℝ), ∃ (β : Type u) (_ : Fintype β) (F : s → β), ∀ x y, F x = F y → dist (x : α) y < ε) : TotallyBounded s := by rcases s.eq_empty_or_nonempty with hs | hs · rw [hs] exact totallyBounded_empty rcases hs with ⟨x0, hx0⟩ haveI : Inhabited s := ⟨⟨x0, hx0⟩⟩ refine totallyBounded_iff.2 fun ε ε0 => ?_ rcases H ε ε0 with ⟨β, fβ, F, hF⟩ let Finv := Function.invFun F refine ⟨range (Subtype.val ∘ Finv), finite_range _, fun x xs => ?_⟩ let x' := Finv (F ⟨x, xs⟩) have : F x' = F ⟨x, xs⟩ := Function.invFun_eq ⟨⟨x, xs⟩, rfl⟩ simp only [Set.mem_iUnion, Set.mem_range] exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩ theorem finite_approx_of_totallyBounded {s : Set α} (hs : TotallyBounded s) : ∀ ε > 0, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε := by intro ε ε_pos rw [totallyBounded_iff_subset] at hs exact hs _ (dist_mem_uniformity ε_pos) /-- Expressing uniform convergence using `dist` -/ theorem tendstoUniformlyOnFilter_iff {F : ι → β → α} {f : β → α} {p : Filter ι} {p' : Filter β} : TendstoUniformlyOnFilter F f p p' ↔ ∀ ε > 0, ∀ᶠ n : ι × β in p ×ˢ p', dist (f n.snd) (F n.fst n.snd) < ε := by refine ⟨fun H ε hε => H _ (dist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩ exact (H ε εpos).mono fun n hn => hε hn /-- Expressing locally uniform convergence on a set using `dist`. -/ theorem tendstoLocallyUniformlyOn_iff [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoLocallyUniformlyOn F f p s ↔ ∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε := by refine ⟨fun H ε hε => H _ (dist_mem_uniformity hε), fun H u hu x hx => ?_⟩ rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩ rcases H ε εpos x hx with ⟨t, ht, Ht⟩ exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩ /-- Expressing uniform convergence on a set using `dist`. -/ theorem tendstoUniformlyOn_iff {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, dist (f x) (F n x) < ε := by refine ⟨fun H ε hε => H _ (dist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩ exact (H ε εpos).mono fun n hs x hx => hε (hs x hx) /-- Expressing locally uniform convergence using `dist`. -/ theorem tendstoLocallyUniformly_iff [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoLocallyUniformly F f p ↔ ∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, nhdsWithin_univ, mem_univ, forall_const] /-- Expressing uniform convergence using `dist`. -/ theorem tendstoUniformly_iff {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, dist (f x) (F n x) < ε := by rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff] simp protected theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, dist x y < ε := uniformity_basis_dist.cauchy_iff variable {s : Set α} /-- Given a point `x` in a discrete subset `s` of a pseudometric space, there is an open ball centered at `x` and intersecting `s` only at `x`. -/ theorem exists_ball_inter_eq_singleton_of_mem_discrete [DiscreteTopology s] {x : α} (hx : x ∈ s) : ∃ ε > 0, Metric.ball x ε ∩ s = {x} := nhds_basis_ball.exists_inter_eq_singleton_of_mem_discrete hx /-- Given a point `x` in a discrete subset `s` of a pseudometric space, there is a closed ball of positive radius centered at `x` and intersecting `s` only at `x`. -/ theorem exists_closedBall_inter_eq_singleton_of_discrete [DiscreteTopology s] {x : α} (hx : x ∈ s) : ∃ ε > 0, Metric.closedBall x ε ∩ s = {x} := nhds_basis_closedBall.exists_inter_eq_singleton_of_mem_discrete hx end Metric open Metric theorem Metric.inseparable_iff_nndist {x y : α} : Inseparable x y ↔ nndist x y = 0 := by rw [EMetric.inseparable_iff, edist_nndist, ENNReal.coe_eq_zero] alias ⟨Inseparable.nndist_eq_zero, _⟩ := Metric.inseparable_iff_nndist theorem Metric.inseparable_iff {x y : α} : Inseparable x y ↔ dist x y = 0 := by rw [Metric.inseparable_iff_nndist, dist_nndist, NNReal.coe_eq_zero] alias ⟨Inseparable.dist_eq_zero, _⟩ := Metric.inseparable_iff /-- A weaker version of `tendsto_nhds_unique` for `PseudoMetricSpace`. -/ theorem tendsto_nhds_unique_dist {f : β → α} {l : Filter β} {x y : α} [NeBot l] (ha : Tendsto f l (𝓝 x)) (hb : Tendsto f l (𝓝 y)) : dist x y = 0 := (tendsto_nhds_unique_inseparable ha hb).dist_eq_zero section Real theorem cauchySeq_iff_tendsto_dist_atTop_0 [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ Tendsto (fun n : β × β => dist (u n.1) (u n.2)) atTop (𝓝 0) := by rw [cauchySeq_iff_tendsto, Metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff, Function.comp_def] simp_rw [Prod.map_fst, Prod.map_snd] end Real namespace Topology /-- The preimage of a separable set by an inducing map is separable. -/ protected lemma IsInducing.isSeparable_preimage {f : β → α} [TopologicalSpace β] (hf : IsInducing f) {s : Set α} (hs : IsSeparable s) : IsSeparable (f ⁻¹' s) := by have : SeparableSpace s := hs.separableSpace have : SecondCountableTopology s := UniformSpace.secondCountable_of_separable _ have : IsInducing ((mapsTo_preimage f s).restrict _ _ _) := (hf.comp IsInducing.subtypeVal).codRestrict _ have := this.secondCountableTopology exact .of_subtype _ protected theorem IsEmbedding.isSeparable_preimage {f : β → α} [TopologicalSpace β] (hf : IsEmbedding f) {s : Set α} (hs : IsSeparable s) : IsSeparable (f ⁻¹' s) := hf.isInducing.isSeparable_preimage hs end Topology /-- A compact set is separable. -/ theorem IsCompact.isSeparable {s : Set α} (hs : IsCompact s) : IsSeparable s := haveI : CompactSpace s := isCompact_iff_compactSpace.mp hs .of_subtype s namespace Metric section SecondCountable open TopologicalSpace /-- A pseudometric space is second countable if, for every `ε > 0`, there is a countable set which is `ε`-dense. -/ theorem secondCountable_of_almost_dense_set (H : ∀ ε > (0 : ℝ), ∃ s : Set α, s.Countable ∧ ∀ x, ∃ y ∈ s, dist x y ≤ ε) : SecondCountableTopology α := by refine EMetric.secondCountable_of_almost_dense_set fun ε ε0 => ?_ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 ε0 with ⟨ε', ε'0, ε'ε⟩ choose s hsc y hys hyx using H ε' (mod_cast ε'0) refine ⟨s, hsc, iUnion₂_eq_univ_iff.2 fun x => ⟨y x, hys _, le_trans ?_ ε'ε.le⟩⟩ exact mod_cast hyx x end SecondCountable end Metric section Compact variable {X : Type*} [PseudoMetricSpace X] {s : Set X} {ε : ℝ} /-- Any compact set in a pseudometric space can be covered by finitely many balls of a given positive radius -/ theorem finite_cover_balls_of_compact (hs : IsCompact s) {e : ℝ} (he : 0 < e) : ∃ t ⊆ s, t.Finite ∧ s ⊆ ⋃ x ∈ t, ball x e := let ⟨t, hts, ht⟩ := hs.elim_nhds_subcover _ (fun x _ => ball_mem_nhds x he) ⟨t, hts, t.finite_toSet, ht⟩ alias IsCompact.finite_cover_balls := finite_cover_balls_of_compact /-- Any relatively compact set in a pseudometric space can be covered by finitely many balls of a given positive radius. -/ lemma exists_finite_cover_balls_of_isCompact_closure (hs : IsCompact (closure s)) (hε : 0 < ε) : ∃ t ⊆ s, t.Finite ∧ s ⊆ ⋃ x ∈ t, ball x ε := by obtain ⟨t, hst⟩ := hs.elim_finite_subcover (fun x : s ↦ ball x ε) (fun _ ↦ isOpen_ball) fun x hx ↦ let ⟨y, hy, hxy⟩ := Metric.mem_closure_iff.1 hx _ hε; mem_iUnion.2 ⟨⟨y, hy⟩, hxy⟩ refine ⟨t.map ⟨Subtype.val, Subtype.val_injective⟩, by simp, Finset.finite_toSet _, ?_⟩ simpa using subset_closure.trans hst end Compact /-- If a map is continuous on a separable set `s`, then the image of `s` is also separable. -/ theorem ContinuousOn.isSeparable_image [TopologicalSpace β] {f : α → β} {s : Set α} (hf : ContinuousOn f s) (hs : IsSeparable s) : IsSeparable (f '' s) := by rw [image_eq_range, ← image_univ] exact (isSeparable_univ_iff.2 hs.separableSpace).image hf.restrict
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean
import Mathlib.Topology.Bornology.Constructions import Mathlib.Topology.MetricSpace.Pseudo.Defs import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Products of pseudometric spaces and other constructions This file constructs the supremum distance on binary products of pseudometric spaces and provides instances for type synonyms. -/ open Bornology Filter Metric Set Topology open scoped NNReal variable {α β : Type*} [PseudoMetricSpace α] /-- Pseudometric space structure pulled back by a function. -/ abbrev PseudoMetricSpace.induced {α β} (f : α → β) (m : PseudoMetricSpace β) : PseudoMetricSpace α where dist x y := dist (f x) (f y) dist_self _ := dist_self _ dist_comm _ _ := dist_comm _ _ dist_triangle _ _ _ := dist_triangle _ _ _ edist x y := edist (f x) (f y) edist_dist _ _ := edist_dist _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf toBornology := Bornology.induced f cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by simp only [← isBounded_def, isBounded_iff, forall_mem_image, mem_setOf] /-- Pull back a pseudometric space structure by an inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace` structure. -/ def Topology.IsInducing.comapPseudoMetricSpace {α β : Type*} [TopologicalSpace α] [m : PseudoMetricSpace β] {f : α → β} (hf : IsInducing f) : PseudoMetricSpace α := .replaceTopology (.induced f m) hf.eq_induced /-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace` structure. -/ def IsUniformInducing.comapPseudoMetricSpace {α β} [UniformSpace α] [m : PseudoMetricSpace β] (f : α → β) (h : IsUniformInducing f) : PseudoMetricSpace α := .replaceUniformity (.induced f m) h.comap_uniformity.symm instance Subtype.pseudoMetricSpace {p : α → Prop} : PseudoMetricSpace (Subtype p) := PseudoMetricSpace.induced Subtype.val ‹_› lemma Subtype.dist_eq {p : α → Prop} (x y : Subtype p) : dist x y = dist (x : α) y := rfl lemma Subtype.nndist_eq {p : α → Prop} (x y : Subtype p) : nndist x y = nndist (x : α) y := rfl namespace MulOpposite @[to_additive] instance instPseudoMetricSpace : PseudoMetricSpace αᵐᵒᵖ := PseudoMetricSpace.induced MulOpposite.unop ‹_› @[to_additive (attr := simp)] lemma dist_unop (x y : αᵐᵒᵖ) : dist (unop x) (unop y) = dist x y := rfl @[to_additive (attr := simp)] lemma dist_op (x y : α) : dist (op x) (op y) = dist x y := rfl @[to_additive (attr := simp)] lemma nndist_unop (x y : αᵐᵒᵖ) : nndist (unop x) (unop y) = nndist x y := rfl @[to_additive (attr := simp)] lemma nndist_op (x y : α) : nndist (op x) (op y) = nndist x y := rfl end MulOpposite section NNReal instance : PseudoMetricSpace ℝ≥0 := Subtype.pseudoMetricSpace lemma NNReal.dist_eq (a b : ℝ≥0) : dist a b = |(a : ℝ) - b| := rfl lemma NNReal.nndist_eq (a b : ℝ≥0) : nndist a b = max (a - b) (b - a) := eq_of_forall_ge_iff fun _ => by simp only [max_le_iff, tsub_le_iff_right (α := ℝ≥0)] simp only [← NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff, tsub_le_iff_right, NNReal.coe_add] @[simp] lemma NNReal.nndist_zero_eq_val (z : ℝ≥0) : nndist 0 z = z := by simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le'] @[simp] lemma NNReal.nndist_zero_eq_val' (z : ℝ≥0) : nndist z 0 = z := by rw [nndist_comm] exact NNReal.nndist_zero_eq_val z lemma NNReal.le_add_nndist (a b : ℝ≥0) : a ≤ b + nndist a b := by suffices (a : ℝ) ≤ (b : ℝ) + dist a b by rwa [← NNReal.coe_le_coe, NNReal.coe_add, coe_nndist] rw [← sub_le_iff_le_add'] exact le_of_abs_le (dist_eq a b).ge lemma NNReal.ball_zero_eq_Ico' (c : ℝ≥0) : Metric.ball (0 : ℝ≥0) c.toReal = Set.Ico 0 c := by ext x; simp lemma NNReal.ball_zero_eq_Ico (c : ℝ) : Metric.ball (0 : ℝ≥0) c = Set.Ico 0 c.toNNReal := by by_cases! c_pos : 0 < c · convert NNReal.ball_zero_eq_Ico' ⟨c, c_pos.le⟩ simp [Real.toNNReal, c_pos.le] simp [c_pos] lemma NNReal.closedBall_zero_eq_Icc' (c : ℝ≥0) : Metric.closedBall (0 : ℝ≥0) c.toReal = Set.Icc 0 c := by ext x; simp lemma NNReal.closedBall_zero_eq_Icc {c : ℝ} (c_nn : 0 ≤ c) : Metric.closedBall (0 : ℝ≥0) c = Set.Icc 0 c.toNNReal := by convert NNReal.closedBall_zero_eq_Icc' ⟨c, c_nn⟩ simp [Real.toNNReal, c_nn] end NNReal namespace ULift variable [PseudoMetricSpace β] instance : PseudoMetricSpace (ULift β) := PseudoMetricSpace.induced ULift.down ‹_› lemma dist_eq (x y : ULift β) : dist x y = dist x.down y.down := rfl lemma nndist_eq (x y : ULift β) : nndist x y = nndist x.down y.down := rfl @[simp] lemma dist_up_up (x y : β) : dist (ULift.up x) (ULift.up y) = dist x y := rfl @[simp] lemma nndist_up_up (x y : β) : nndist (ULift.up x) (ULift.up y) = nndist x y := rfl end ULift section Prod variable [PseudoMetricSpace β] instance Prod.pseudoMetricSpaceMax : PseudoMetricSpace (α × β) := let i := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun x y : α × β => dist x.1 y.1 ⊔ dist x.2 y.2) (fun x y ↦ by positivity) fun x y => by simp only [ENNReal.ofReal_max, Prod.edist_eq, edist_dist] i.replaceBornology fun s => by simp only [← isBounded_image_fst_and_snd, isBounded_iff_eventually, forall_mem_image, ← eventually_and, ← forall_and, ← max_le_iff] rfl lemma Prod.dist_eq {x y : α × β} : dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl @[simp] lemma dist_prod_same_left {x : α} {y₁ y₂ : β} : dist (x, y₁) (x, y₂) = dist y₁ y₂ := by simp [Prod.dist_eq] @[simp] lemma dist_prod_same_right {x₁ x₂ : α} {y : β} : dist (x₁, y) (x₂, y) = dist x₁ x₂ := by simp [Prod.dist_eq] lemma ball_prod_same (x : α) (y : β) (r : ℝ) : ball x r ×ˢ ball y r = ball (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma closedBall_prod_same (x : α) (y : β) (r : ℝ) : closedBall x r ×ˢ closedBall y r = closedBall (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma sphere_prod (x : α × β) (r : ℝ) : sphere x r = sphere x.1 r ×ˢ closedBall x.2 r ∪ closedBall x.1 r ×ˢ sphere x.2 r := by obtain hr | rfl | hr := lt_trichotomy r 0 · simp [hr] · cases x simp_rw [← closedBall_eq_sphere_of_nonpos le_rfl, union_self, closedBall_prod_same] · ext ⟨x', y'⟩ simp_rw [Set.mem_union, Set.mem_prod, Metric.mem_closedBall, Metric.mem_sphere, Prod.dist_eq, max_eq_iff] refine or_congr (and_congr_right ?_) (and_comm.trans (and_congr_left ?_)) all_goals rintro rfl; rfl end Prod lemma uniformContinuous_dist : UniformContinuous fun p : α × α => dist p.1 p.2 := Metric.uniformContinuous_iff.2 fun ε ε0 => ⟨ε / 2, half_pos ε0, fun {a b} h => calc dist (dist a.1 a.2) (dist b.1 b.2) ≤ dist a.1 b.1 + dist a.2 b.2 := dist_dist_dist_le _ _ _ _ _ ≤ dist a b + dist a b := add_le_add (le_max_left _ _) (le_max_right _ _) _ < ε / 2 + ε / 2 := add_lt_add h h _ = ε := add_halves ε⟩ protected lemma UniformContinuous.dist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun b => dist (f b) (g b) := uniformContinuous_dist.comp (hf.prodMk hg) @[continuity] lemma continuous_dist : Continuous fun p : α × α ↦ dist p.1 p.2 := uniformContinuous_dist.continuous @[continuity, fun_prop] protected lemma Continuous.dist [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => dist (f b) (g b) := continuous_dist.comp₂ hf hg protected lemma Filter.Tendsto.dist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a)) (hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => dist (f x) (g x)) x (𝓝 (dist a b)) := (continuous_dist.tendsto (a, b)).comp (hf.prodMk_nhds hg) lemma continuous_iff_continuous_dist [TopologicalSpace β] {f : β → α} : Continuous f ↔ Continuous fun x : β × β => dist (f x.1) (f x.2) := ⟨fun h => h.fst'.dist h.snd', fun h => continuous_iff_continuousAt.2 fun _ => tendsto_iff_dist_tendsto_zero.2 <| (h.comp (.prodMk_left _)).tendsto' _ _ <| dist_self _⟩ lemma uniformContinuous_nndist : UniformContinuous fun p : α × α => nndist p.1 p.2 := uniformContinuous_dist.subtype_mk _ protected lemma UniformContinuous.nndist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous fun b => nndist (f b) (g b) := uniformContinuous_nndist.comp (hf.prodMk hg) lemma continuous_nndist : Continuous fun p : α × α => nndist p.1 p.2 := uniformContinuous_nndist.continuous @[fun_prop] protected lemma Continuous.nndist [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : Continuous fun b => nndist (f b) (g b) := continuous_nndist.comp₂ hf hg protected lemma Filter.Tendsto.nndist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a)) (hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => nndist (f x) (g x)) x (𝓝 (nndist a b)) := (continuous_nndist.tendsto (a, b)).comp (hf.prodMk_nhds hg)
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Pseudo/Defs.lean
import Mathlib.Data.ENNReal.Real import Mathlib.Tactic.Bound.Attribute import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.EMetricSpace.Defs import Mathlib.Topology.UniformSpace.Basic /-! ## Pseudo-metric spaces This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the condition `dist x y = 0 → x = y`. Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. ## Main definitions * `Dist α`: Endows a space `α` with a function `dist a b`. * `PseudoMetricSpace α`: A space endowed with a distance function, which can be zero even if the two elements are non-equal. * `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`. * `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded. * `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`. Additional useful definitions: * `nndist a b`: `dist` as a function to the non-negative reals. * `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`. * `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`. TODO (anyone): Add "Main results" section. ## Tags pseudo_metric, dist -/ assert_not_exists compactSpace_uniformity open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε := ⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩ /-- Construct a uniform structure from a distance function and metric space axioms -/ def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α := .ofFun dist dist_self dist_comm dist_triangle ofDist_aux /-- Construct a bornology from a distance function and metric space axioms. -/ abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x) (dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α := Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C } ⟨0, fun _ hx _ => hx.elim⟩ (fun _ ⟨c, hc⟩ _ h => ⟨c, fun _ hx _ hy => hc (h hx) (h hy)⟩) (fun s hs t ht => by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · rwa [empty_union] rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩ · rwa [union_empty] rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C · refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩ simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb) rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩ refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim (fun hz => (hs hx hz).trans (le_max_left _ _)) (fun hz => (dist_triangle x y z).trans <| (add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩) fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩ /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ @[ext] class Dist (α : Type*) where /-- Distance between two points -/ dist : α → α → ℝ export Dist (dist) -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/ private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y := have : 0 ≤ 2 * dist x y := calc 0 = dist x x := (dist_self _).symm _ ≤ dist x y + dist y x := dist_triangle _ _ _ _ = 2 * dist x y := by rw [two_mul, dist_comm] nonneg_of_mul_nonneg_right this two_pos /-- A pseudometric space is a type endowed with a `ℝ`-valued distance `dist` satisfying reflexivity `dist x x = 0`, commutativity `dist x y = dist y x`, and the triangle inequality `dist x z ≤ dist x y + dist y z`. Note that we do not require `dist x y = 0 → x = y`. See metric spaces (`MetricSpace`) for the similar class with that stronger assumption. Any pseudometric space is a topological space and a uniform space (see `TopologicalSpace`, `UniformSpace`), where the topology and uniformity come from the metric. Note that a T1 pseudometric space is just a metric space. We make the uniformity/topology part of the data instead of deriving it from the metric. This e.g. ensures that we do not get a diamond when doing `[PseudoMetricSpace α] [PseudoMetricSpace β] : TopologicalSpace (α × β)`: The product metric and product topology agree, but not definitionally so. See Note [forgetful inheritance]. -/ class PseudoMetricSpace (α : Type u) : Type u extends Dist α where dist_self : ∀ x : α, dist x x = 0 dist_comm : ∀ x y : α, dist x y = dist y x dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z /-- Extended distance between two points -/ edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩ edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) := by intro x y; exact ENNReal.coe_nnreal_eq _ toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets : (Bornology.cobounded α).sets = { s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl /-- Two pseudo metric space structures with the same distance function coincide. -/ @[ext] theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by let d := m.toDist obtain ⟨_, _, _, _, hed, _, hU, _, hB⟩ := m let d' := m'.toDist obtain ⟨_, _, _, _, hed', _, hU', _, hB'⟩ := m' obtain rfl : d = d' := h congr · ext x y : 2 rw [hed, hed'] · exact UniformSpace.ext (hU.trans hU'.symm) · ext : 2 rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB'] variable [PseudoMetricSpace α] attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology -- see Note [lower instance priority] instance (priority := 200) PseudoMetricSpace.toEDist : EDist α := ⟨PseudoMetricSpace.edist⟩ /-- Construct a pseudo-metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) : PseudoMetricSpace α := { dist := dist dist_self := dist_self dist_comm := dist_comm dist_triangle := dist_triangle toUniformSpace := (UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <| TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦ ((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm uniformity_dist := rfl toBornology := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets := rfl } @[simp] theorem dist_self (x : α) : dist x x = 0 := PseudoMetricSpace.dist_self x theorem dist_comm (x y : α) : dist x y = dist y x := PseudoMetricSpace.dist_comm x y theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) := PseudoMetricSpace.edist_dist x y @[bound] theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle x y z theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by rw [dist_comm z]; apply dist_triangle theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by rw [dist_comm y]; apply dist_triangle theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w := calc dist x w ≤ dist x z + dist z w := dist_triangle x z w _ ≤ dist x y + dist y z + dist z w := by gcongr; apply dist_triangle x y z theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by rw [add_left_comm, dist_comm x₁, ← add_assoc] apply dist_triangle4 theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by rw [add_right_comm, dist_comm y₁] apply dist_triangle4 theorem dist_triangle8 (a b c d e f g h : α) : dist a h ≤ dist a b + dist b c + dist c d + dist d e + dist e f + dist f g + dist g h := by apply le_trans (dist_triangle4 a f g h) gcongr apply le_trans (dist_triangle4 a d e f) gcongr exact dist_triangle4 a b c d theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _ theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y := abs_sub_le_iff.2 ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩ @[simp, bound] theorem dist_nonneg {x y : α} : 0 ≤ dist x y := dist_nonneg' dist dist_self dist_comm dist_triangle namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: distances are nonnegative. -/ @[positivity Dist.dist _ _] def evalDist : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) => let _inst ← synthInstanceQ q(PseudoMetricSpace $β) assertInstancesCommute pure (.nonnegative q(dist_nonneg)) | _, _, _ => throwError "not dist" end Mathlib.Meta.Positivity example {x y : α} : 0 ≤ dist x y := by positivity @[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg /-- A version of `Dist` that takes value in `ℝ≥0`. -/ class NNDist (α : Type*) where /-- Nonnegative distance between two points -/ nndist : α → α → ℝ≥0 export NNDist (nndist) -- see Note [lower instance priority] /-- Distance as a nonnegative real number. -/ instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α := ⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩ /-- Express `dist` in terms of `nndist` -/ theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl @[simp, norm_cast] theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl /-- Express `edist` in terms of `nndist` -/ theorem edist_nndist (x y : α) : edist x y = nndist x y := by rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal] /-- Express `nndist` in terms of `edist` -/ theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by simp [edist_nndist] @[simp, norm_cast] theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y := (edist_nndist x y).symm @[simp, norm_cast] theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by rw [edist_nndist, ENNReal.coe_lt_coe] @[simp, norm_cast] theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by rw [edist_nndist, ENNReal.coe_le_coe] /-- In a pseudometric space, the extended distance is always finite -/ theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ := (edist_dist x y).symm ▸ ENNReal.ofReal_lt_top /-- In a pseudometric space, the extended distance is always finite -/ @[aesop (rule_sets := [finiteness]) safe apply] theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ := (edist_lt_top x y).ne /-- `nndist x x` vanishes -/ @[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a) @[simp, norm_cast] theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c := Iff.rfl @[simp, norm_cast] theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c := Iff.rfl @[simp] theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg] @[simp] theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) : edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr] /-- Express `nndist` in terms of `dist` -/ theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by rw [dist_nndist, Real.toNNReal_coe] theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y /-- Triangle inequality for the nonnegative distance -/ theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle _ _ _ theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left _ _ _ theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right _ _ _ /-- Express `dist` in terms of `edist` -/ theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg] namespace Metric -- instantiate pseudometric space as a topology variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α} /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/ def ball (x : α) (ε : ℝ) : Set α := { y | dist y x < ε } @[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := Iff.rfl theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball] theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε := dist_nonneg.trans_lt hy theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by rwa [mem_ball, dist_self] @[simp] theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε := ⟨fun ⟨_x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩ @[simp] theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt] @[simp] theorem ball_zero : ball x 0 = ∅ := by rw [ball_eq_empty] /-- If a point belongs to an open ball, then there is a strictly smaller radius whose ball also contains it. See also `exists_lt_subset_ball`. -/ theorem exists_lt_mem_ball_of_mem_ball (h : x ∈ ball y ε) : ∃ ε' < ε, x ∈ ball y ε' := by simp only [mem_ball] at h ⊢ exact ⟨(dist x y + ε) / 2, by linarith, by linarith⟩ theorem ball_eq_ball (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.2 p.1 < ε } = Metric.ball x ε := rfl theorem ball_eq_ball' (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.1 p.2 < ε } = Metric.ball x ε := by ext simp [dist_comm, UniformSpace.ball] @[simp] theorem iUnion_ball_nat (x : α) : ⋃ n : ℕ, ball x n = univ := iUnion_eq_univ_iff.2 fun y => exists_nat_gt (dist y x) @[simp] theorem iUnion_ball_nat_succ (x : α) : ⋃ n : ℕ, ball x (n + 1) = univ := iUnion_eq_univ_iff.2 fun y => (exists_nat_gt (dist y x)).imp fun _ h => h.trans (lt_add_one _) /-- `closedBall x ε` is the set of all points `y` with `dist y x ≤ ε` -/ def closedBall (x : α) (ε : ℝ) := { y | dist y x ≤ ε } @[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ dist y x ≤ ε := Iff.rfl theorem mem_closedBall' : y ∈ closedBall x ε ↔ dist x y ≤ ε := by rw [dist_comm, mem_closedBall] /-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/ def sphere (x : α) (ε : ℝ) := { y | dist y x = ε } @[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := Iff.rfl theorem mem_sphere' : y ∈ sphere x ε ↔ dist x y = ε := by rw [dist_comm, mem_sphere] theorem ne_of_mem_sphere (h : y ∈ sphere x ε) (hε : ε ≠ 0) : y ≠ x := ne_of_mem_of_not_mem h <| by simpa using hε.symm theorem nonneg_of_mem_sphere (hy : y ∈ sphere x ε) : 0 ≤ ε := dist_nonneg.trans_eq hy @[simp] theorem sphere_eq_empty_of_neg (hε : ε < 0) : sphere x ε = ∅ := Set.eq_empty_iff_forall_notMem.mpr fun _y hy => (nonneg_of_mem_sphere hy).not_gt hε theorem sphere_eq_empty_of_subsingleton [Subsingleton α] (hε : ε ≠ 0) : sphere x ε = ∅ := Set.eq_empty_iff_forall_notMem.mpr fun _ h => ne_of_mem_sphere h hε (Subsingleton.elim _ _) instance sphere_isEmpty_of_subsingleton [Subsingleton α] [NeZero ε] : IsEmpty (sphere x ε) := by rw [sphere_eq_empty_of_subsingleton (NeZero.ne ε)]; infer_instance theorem closedBall_eq_singleton_of_subsingleton [Subsingleton α] (h : 0 ≤ ε) : closedBall x ε = {x} := by ext x' simpa [Subsingleton.allEq x x'] theorem ball_eq_singleton_of_subsingleton [Subsingleton α] (h : 0 < ε) : ball x ε = {x} := by ext x' simpa [Subsingleton.allEq x x'] theorem mem_closedBall_self (h : 0 ≤ ε) : x ∈ closedBall x ε := by rwa [mem_closedBall, dist_self] @[simp] theorem nonempty_closedBall : (closedBall x ε).Nonempty ↔ 0 ≤ ε := ⟨fun ⟨_x, hx⟩ => dist_nonneg.trans hx, fun h => ⟨x, mem_closedBall_self h⟩⟩ @[simp] theorem closedBall_eq_empty : closedBall x ε = ∅ ↔ ε < 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_closedBall, not_le] @[simp] alias ⟨_, closedBall_of_neg⟩ := closedBall_eq_empty /-- Closed balls and spheres coincide when the radius is non-positive -/ theorem closedBall_eq_sphere_of_nonpos (hε : ε ≤ 0) : closedBall x ε = sphere x ε := Set.ext fun _ => (hε.trans dist_nonneg).ge_iff_eq' theorem ball_subset_closedBall : ball x ε ⊆ closedBall x ε := fun _y hy => mem_closedBall.2 (le_of_lt hy) theorem sphere_subset_closedBall : sphere x ε ⊆ closedBall x ε := fun _ => le_of_eq lemma sphere_subset_ball {r R : ℝ} (h : r < R) : sphere x r ⊆ ball x R := fun _x hx ↦ (mem_sphere.1 hx).trans_lt h theorem closedBall_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (closedBall x δ) (ball y ε) := Set.disjoint_left.mpr fun _a ha1 ha2 => (h.trans <| dist_triangle_left _ _ _).not_gt <| add_lt_add_of_le_of_lt ha1 ha2 theorem ball_disjoint_closedBall (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (closedBall y ε) := (closedBall_disjoint_ball <| by rwa [add_comm, dist_comm]).symm theorem ball_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (ball y ε) := (closedBall_disjoint_ball h).mono_left ball_subset_closedBall theorem closedBall_disjoint_closedBall (h : δ + ε < dist x y) : Disjoint (closedBall x δ) (closedBall y ε) := Set.disjoint_left.mpr fun _a ha1 ha2 => h.not_ge <| (dist_triangle_left _ _ _).trans <| add_le_add ha1 ha2 theorem sphere_disjoint_ball : Disjoint (sphere x ε) (ball x ε) := Set.disjoint_left.mpr fun _y hy₁ hy₂ => absurd hy₁ <| ne_of_lt hy₂ @[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closedBall x ε := Set.ext fun _y => (@le_iff_lt_or_eq ℝ _ _ _).symm @[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closedBall x ε := by rw [union_comm, ball_union_sphere] @[simp] theorem closedBall_diff_sphere : closedBall x ε \ sphere x ε = ball x ε := by rw [← ball_union_sphere, Set.union_diff_cancel_right sphere_disjoint_ball.symm.le_bot] @[simp] theorem closedBall_diff_ball : closedBall x ε \ ball x ε = sphere x ε := by rw [← ball_union_sphere, Set.union_diff_cancel_left sphere_disjoint_ball.symm.le_bot] theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε := by rw [mem_ball', mem_ball] theorem mem_closedBall_comm : x ∈ closedBall y ε ↔ y ∈ closedBall x ε := by rw [mem_closedBall', mem_closedBall] theorem mem_sphere_comm : x ∈ sphere y ε ↔ y ∈ sphere x ε := by rw [mem_sphere', mem_sphere] @[gcongr] theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ := fun _y yx => lt_of_lt_of_le (mem_ball.1 yx) h theorem closedBall_eq_bInter_ball : closedBall x ε = ⋂ δ > ε, ball x δ := by ext y; rw [mem_closedBall, ← forall_gt_iff_le, mem_iInter₂]; rfl theorem ball_subset_ball' (h : ε₁ + dist x y ≤ ε₂) : ball x ε₁ ⊆ ball y ε₂ := fun z hz => calc dist z y ≤ dist z x + dist x y := dist_triangle _ _ _ _ < ε₁ + dist x y := by gcongr; exact hz _ ≤ ε₂ := h @[gcongr] theorem closedBall_subset_closedBall (h : ε₁ ≤ ε₂) : closedBall x ε₁ ⊆ closedBall x ε₂ := fun _y (yx : _ ≤ ε₁) => le_trans yx h theorem closedBall_subset_closedBall' (h : ε₁ + dist x y ≤ ε₂) : closedBall x ε₁ ⊆ closedBall y ε₂ := fun z hz => calc dist z y ≤ dist z x + dist x y := dist_triangle _ _ _ _ ≤ ε₁ + dist x y := by gcongr; exact hz _ ≤ ε₂ := h theorem closedBall_subset_ball (h : ε₁ < ε₂) : closedBall x ε₁ ⊆ ball x ε₂ := fun y (yh : dist y x ≤ ε₁) => lt_of_le_of_lt yh h theorem closedBall_subset_ball' (h : ε₁ + dist x y < ε₂) : closedBall x ε₁ ⊆ ball y ε₂ := fun z hz => calc dist z y ≤ dist z x + dist x y := dist_triangle _ _ _ _ ≤ ε₁ + dist x y := by gcongr; exact hz _ < ε₂ := h theorem dist_le_add_of_nonempty_closedBall_inter_closedBall (h : (closedBall x ε₁ ∩ closedBall y ε₂).Nonempty) : dist x y ≤ ε₁ + ε₂ := let ⟨z, hz⟩ := h calc dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _ _ ≤ ε₁ + ε₂ := add_le_add hz.1 hz.2 theorem dist_lt_add_of_nonempty_closedBall_inter_ball (h : (closedBall x ε₁ ∩ ball y ε₂).Nonempty) : dist x y < ε₁ + ε₂ := let ⟨z, hz⟩ := h calc dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _ _ < ε₁ + ε₂ := add_lt_add_of_le_of_lt hz.1 hz.2 theorem dist_lt_add_of_nonempty_ball_inter_closedBall (h : (ball x ε₁ ∩ closedBall y ε₂).Nonempty) : dist x y < ε₁ + ε₂ := by rw [inter_comm] at h rw [add_comm, dist_comm] exact dist_lt_add_of_nonempty_closedBall_inter_ball h theorem dist_lt_add_of_nonempty_ball_inter_ball (h : (ball x ε₁ ∩ ball y ε₂).Nonempty) : dist x y < ε₁ + ε₂ := dist_lt_add_of_nonempty_closedBall_inter_ball <| h.mono (inter_subset_inter ball_subset_closedBall Subset.rfl) @[simp] theorem iUnion_closedBall_nat (x : α) : ⋃ n : ℕ, closedBall x n = univ := iUnion_eq_univ_iff.2 fun y => exists_nat_ge (dist y x) theorem iUnion_inter_closedBall_nat (s : Set α) (x : α) : ⋃ n : ℕ, s ∩ closedBall x n = s := by rw [← inter_iUnion, iUnion_closedBall_nat, inter_univ] theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ := fun z zx => by rw [← add_sub_cancel ε₁ ε₂] exact lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h) theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε := ball_subset <| by rw [sub_self_div_two]; exact le_of_lt h theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε := ⟨_, sub_pos.2 h, ball_subset <| by rw [sub_sub_self]⟩ /-- If a property holds for all points in closed balls of arbitrarily large radii, then it holds for all points. -/ theorem forall_of_forall_mem_closedBall (p : α → Prop) (x : α) (H : ∃ᶠ R : ℝ in atTop, ∀ y ∈ closedBall x R, p y) (y : α) : p y := by obtain ⟨R, hR, h⟩ : ∃ R ≥ dist y x, ∀ z : α, z ∈ closedBall x R → p z := frequently_iff.1 H (Ici_mem_atTop (dist y x)) exact h _ hR /-- If a property holds for all points in balls of arbitrarily large radii, then it holds for all points. -/ theorem forall_of_forall_mem_ball (p : α → Prop) (x : α) (H : ∃ᶠ R : ℝ in atTop, ∀ y ∈ ball x R, p y) (y : α) : p y := by obtain ⟨R, hR, h⟩ : ∃ R > dist y x, ∀ z : α, z ∈ ball x R → p z := frequently_iff.1 H (Ioi_mem_atTop (dist y x)) exact h _ hR theorem isBounded_iff {s : Set α} : IsBounded s ↔ ∃ C : ℝ, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := by rw [isBounded_def, ← Filter.mem_sets, @PseudoMetricSpace.cobounded_sets α, mem_setOf_eq, compl_compl] lemma boundedSpace_iff : BoundedSpace α ↔ ∃ C, ∀ a b : α, dist a b ≤ C := by rw [← isBounded_univ, Metric.isBounded_iff] simp theorem isBounded_iff_eventually {s : Set α} : IsBounded s ↔ ∀ᶠ C in atTop, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := isBounded_iff.trans ⟨fun ⟨C, h⟩ => eventually_atTop.2 ⟨C, fun _C' hC' _x hx _y hy => (h hx hy).trans hC'⟩, Eventually.exists⟩ theorem isBounded_iff_exists_ge {s : Set α} (c : ℝ) : IsBounded s ↔ ∃ C, c ≤ C ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := ⟨fun h => ((eventually_ge_atTop c).and (isBounded_iff_eventually.1 h)).exists, fun h => isBounded_iff.2 <| h.imp fun _ => And.right⟩ theorem isBounded_iff_nndist {s : Set α} : IsBounded s ↔ ∃ C : ℝ≥0, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → nndist x y ≤ C := by simp only [isBounded_iff_exists_ge 0, NNReal.exists, ← NNReal.coe_le_coe, ← dist_nndist, NNReal.coe_mk, exists_prop] lemma boundedSpace_iff_nndist : BoundedSpace α ↔ ∃ C, ∀ a b : α, nndist a b ≤ C := by rw [← isBounded_univ, Metric.isBounded_iff_nndist] simp lemma boundedSpace_iff_edist : BoundedSpace α ↔ ∃ C : ℝ≥0, ∀ a b : α, edist a b ≤ C := by simp [Metric.boundedSpace_iff_nndist] theorem toUniformSpace_eq : ‹PseudoMetricSpace α›.toUniformSpace = .ofDist dist dist_self dist_comm dist_triangle := UniformSpace.ext PseudoMetricSpace.uniformity_dist theorem uniformity_basis_dist : (𝓤 α).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : α × α | dist p.1 p.2 < ε } := by rw [toUniformSpace_eq] exact UniformSpace.hasBasis_ofFun (exists_gt _) _ _ _ _ _ /-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`, and `uniformity_basis_dist_inv_nat_pos`. -/ protected theorem mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ} (hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ i, p i ∧ f i ≤ ε) : (𝓤 α).HasBasis p fun i => { p : α × α | dist p.1 p.2 < f i } := by refine ⟨fun s => uniformity_basis_dist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases hf ε₀ with ⟨i, hi, H⟩ exact ⟨i, hi, fun x (hx : _ < _) => hε <| lt_of_lt_of_le hx H⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, H⟩ theorem uniformity_basis_dist_rat : (𝓤 α).HasBasis (fun r : ℚ => 0 < r) fun r => { p : α × α | dist p.1 p.2 < r } := Metric.mk_uniformity_basis (fun _ => Rat.cast_pos.2) fun _ε hε => let ⟨r, hr0, hrε⟩ := exists_rat_btwn hε ⟨r, Rat.cast_pos.1 hr0, hrε.le⟩ theorem uniformity_basis_dist_inv_nat_succ : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 < 1 / (↑n + 1) } := Metric.mk_uniformity_basis (fun n _ => div_pos zero_lt_one <| Nat.cast_add_one_pos n) fun _ε ε0 => (exists_nat_one_div_lt ε0).imp fun _n hn => ⟨trivial, le_of_lt hn⟩ theorem uniformity_basis_dist_inv_nat_pos : (𝓤 α).HasBasis (fun n : ℕ => 0 < n) fun n : ℕ => { p : α × α | dist p.1 p.2 < 1 / ↑n } := Metric.mk_uniformity_basis (fun _ hn => div_pos zero_lt_one <| Nat.cast_pos.2 hn) fun _ ε0 => let ⟨n, hn⟩ := exists_nat_one_div_lt ε0 ⟨n + 1, Nat.succ_pos n, mod_cast hn.le⟩ theorem uniformity_basis_dist_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓤 α).HasBasis (fun _ : ℕ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 < r ^ n } := Metric.mk_uniformity_basis (fun _ _ => pow_pos h0 _) fun _ε ε0 => let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1 ⟨n, trivial, hn.le⟩ theorem uniformity_basis_dist_lt {R : ℝ} (hR : 0 < R) : (𝓤 α).HasBasis (fun r : ℝ => 0 < r ∧ r < R) fun r => { p : α × α | dist p.1 p.2 < r } := Metric.mk_uniformity_basis (fun _ => And.left) fun r hr => ⟨min r (R / 2), ⟨lt_min hr (half_pos hR), min_lt_iff.2 <| Or.inr (half_lt_self hR)⟩, min_le_left _ _⟩ /-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}` form a basis of `𝓤 α`. Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor. More can be easily added if needed in the future. -/ protected theorem mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | dist p.1 p.2 ≤ f x } := by refine ⟨fun s => uniformity_basis_dist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases exists_between ε₀ with ⟨ε', hε'⟩ rcases hf ε' hε'.1 with ⟨i, hi, H⟩ exact ⟨i, hi, fun x (hx : _ ≤ _) => hε <| lt_of_le_of_lt (le_trans hx H) hε'.2⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, fun x (hx : _ < _) => H (mem_setOf.2 hx.le)⟩ /-- Constant size closed neighborhoods of the diagonal form a basis of the uniformity filter. -/ theorem uniformity_basis_dist_le : (𝓤 α).HasBasis ((0 : ℝ) < ·) fun ε => { p : α × α | dist p.1 p.2 ≤ ε } := Metric.mk_uniformity_basis_le (fun _ => id) fun ε ε₀ => ⟨ε, ε₀, le_refl ε⟩ theorem uniformity_basis_dist_le_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓤 α).HasBasis (fun _ : ℕ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 ≤ r ^ n } := Metric.mk_uniformity_basis_le (fun _ _ => pow_pos h0 _) fun _ε ε0 => let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1 ⟨n, trivial, hn.le⟩ theorem mem_uniformity_dist {s : Set (α × α)} : s ∈ 𝓤 α ↔ ∃ ε > 0, ∀ ⦃a b : α⦄, dist a b < ε → (a, b) ∈ s := uniformity_basis_dist.mem_uniformity_iff /-- A constant size neighborhood of the diagonal is an entourage. -/ theorem dist_mem_uniformity {ε : ℝ} (ε0 : 0 < ε) : { p : α × α | dist p.1 p.2 < ε } ∈ 𝓤 α := mem_uniformity_dist.2 ⟨ε, ε0, fun _ _ ↦ id⟩ theorem uniformContinuous_iff [PseudoMetricSpace β] {f : α → β} : UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃a b : α⦄, dist a b < δ → dist (f a) (f b) < ε := uniformity_basis_dist.uniformContinuous_iff uniformity_basis_dist theorem uniformContinuousOn_iff [PseudoMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x ∈ s, ∀ y ∈ s, dist x y < δ → dist (f x) (f y) < ε := uniformity_basis_dist.uniformContinuousOn_iff uniformity_basis_dist theorem uniformContinuous_iff_le [PseudoMetricSpace β] {f : α → β} : UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃a b : α⦄, dist a b ≤ δ → dist (f a) (f b) ≤ ε := uniformity_basis_dist_le.uniformContinuous_iff uniformity_basis_dist_le theorem uniformContinuousOn_iff_le [PseudoMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ δ → dist (f x) (f y) ≤ ε := uniformity_basis_dist_le.uniformContinuousOn_iff uniformity_basis_dist_le theorem nhds_basis_ball : (𝓝 x).HasBasis (0 < ·) (ball x) := nhds_basis_uniformity uniformity_basis_dist theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ ε > 0, ball x ε ⊆ s := nhds_basis_ball.mem_iff theorem eventually_nhds_iff {p : α → Prop} : (∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε > 0, ∀ ⦃y⦄, dist y x < ε → p y := mem_nhds_iff theorem eventually_nhds_iff_ball {p : α → Prop} : (∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε > 0, ∀ y ∈ ball x ε, p y := mem_nhds_iff /-- A version of `Filter.eventually_prod_iff` where the first filter consists of neighborhoods in a pseudo-metric space. -/ theorem eventually_nhds_prod_iff {f : Filter ι} {x₀ : α} {p : α × ι → Prop} : (∀ᶠ x in 𝓝 x₀ ×ˢ f, p x) ↔ ∃ ε > (0 : ℝ), ∃ pa : ι → Prop, (∀ᶠ i in f, pa i) ∧ ∀ ⦃x⦄, dist x x₀ < ε → ∀ ⦃i⦄, pa i → p (x, i) := by refine (nhds_basis_ball.prod f.basis_sets).eventually_iff.trans ?_ simp only [Prod.exists, forall_prod_set, id, mem_ball, and_assoc, exists_and_left] rfl /-- A version of `Filter.eventually_prod_iff` where the second filter consists of neighborhoods in a pseudo-metric space. -/ theorem eventually_prod_nhds_iff {f : Filter ι} {x₀ : α} {p : ι × α → Prop} : (∀ᶠ x in f ×ˢ 𝓝 x₀, p x) ↔ ∃ pa : ι → Prop, (∀ᶠ i in f, pa i) ∧ ∃ ε > 0, ∀ ⦃i⦄, pa i → ∀ ⦃x⦄, dist x x₀ < ε → p (i, x) := by rw [eventually_swap_iff, Metric.eventually_nhds_prod_iff] constructor <;> · rintro ⟨a1, a2, a3, a4, a5⟩ exact ⟨a3, a4, a1, a2, fun _ b1 b2 b3 => a5 b3 b1⟩ theorem nhds_basis_closedBall : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) (closedBall x) := nhds_basis_uniformity uniformity_basis_dist_le theorem nhds_basis_ball_inv_nat_succ : (𝓝 x).HasBasis (fun _ => True) fun n : ℕ => ball x (1 / (↑n + 1)) := nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ theorem nhds_basis_ball_inv_nat_pos : (𝓝 x).HasBasis (fun n => 0 < n) fun n : ℕ => ball x (1 / ↑n) := nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos theorem nhds_basis_ball_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓝 x).HasBasis (fun _ => True) fun n : ℕ => ball x (r ^ n) := nhds_basis_uniformity (uniformity_basis_dist_pow h0 h1) theorem nhds_basis_closedBall_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓝 x).HasBasis (fun _ => True) fun n : ℕ => closedBall x (r ^ n) := nhds_basis_uniformity (uniformity_basis_dist_le_pow h0 h1) theorem isOpen_iff : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ball x ε ⊆ s := by simp only [isOpen_iff_mem_nhds, mem_nhds_iff] @[simp] theorem isOpen_ball : IsOpen (ball x ε) := isOpen_iff.2 fun _ => exists_ball_subset_ball theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x := isOpen_ball.mem_nhds (mem_ball_self ε0) theorem closedBall_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : closedBall x ε ∈ 𝓝 x := mem_of_superset (ball_mem_nhds x ε0) ball_subset_closedBall theorem closedBall_mem_nhds_of_mem {x c : α} {ε : ℝ} (h : x ∈ ball c ε) : closedBall c ε ∈ 𝓝 x := mem_of_superset (isOpen_ball.mem_nhds h) ball_subset_closedBall theorem nhdsWithin_basis_ball {s : Set α} : (𝓝[s] x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => ball x ε ∩ s := nhdsWithin_hasBasis nhds_basis_ball s theorem mem_nhdsWithin_iff {t : Set α} : s ∈ 𝓝[t] x ↔ ∃ ε > 0, ball x ε ∩ t ⊆ s := nhdsWithin_basis_ball.mem_iff theorem tendsto_nhdsWithin_nhdsWithin [PseudoMetricSpace β] {t : Set β} {f : α → β} {a b} : Tendsto f (𝓝[s] a) (𝓝[t] b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε := (nhdsWithin_basis_ball.tendsto_iff nhdsWithin_basis_ball).trans <| by simp only [inter_comm _ s, inter_comm _ t, mem_inter_iff, and_imp, gt_iff_lt, mem_ball] theorem tendsto_nhdsWithin_nhds [PseudoMetricSpace β] {f : α → β} {a b} : Tendsto f (𝓝[s] a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, x ∈ s → dist x a < δ → dist (f x) b < ε := by rw [← nhdsWithin_univ b, tendsto_nhdsWithin_nhdsWithin] simp only [mem_univ, true_and] theorem tendsto_nhds_nhds [PseudoMetricSpace β] {f : α → β} {a b} : Tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, dist x a < δ → dist (f x) b < ε := nhds_basis_ball.tendsto_iff nhds_basis_ball theorem continuousAt_iff [PseudoMetricSpace β] {f : α → β} {a : α} : ContinuousAt f a ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, dist x a < δ → dist (f x) (f a) < ε := by rw [ContinuousAt, tendsto_nhds_nhds] theorem continuousWithinAt_iff [PseudoMetricSpace β] {f : α → β} {a : α} {s : Set α} : ContinuousWithinAt f s a ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, x ∈ s → dist x a < δ → dist (f x) (f a) < ε := by rw [ContinuousWithinAt, tendsto_nhdsWithin_nhds] theorem continuousOn_iff [PseudoMetricSpace β] {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ b ∈ s, ∀ ε > 0, ∃ δ > 0, ∀ a ∈ s, dist a b < δ → dist (f a) (f b) < ε := by simp [ContinuousOn, continuousWithinAt_iff] theorem continuous_iff [PseudoMetricSpace β] {f : α → β} : Continuous f ↔ ∀ b, ∀ ε > 0, ∃ δ > 0, ∀ a, dist a b < δ → dist (f a) (f b) < ε := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_nhds theorem tendsto_nhds {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε := nhds_basis_ball.tendsto_right_iff theorem continuousAt_iff' [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ ∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε := by rw [ContinuousAt, tendsto_nhds] theorem continuousWithinAt_iff' [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ ∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε := by rw [ContinuousWithinAt, tendsto_nhds] theorem continuousOn_iff' [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, ∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε := by simp [ContinuousOn, continuousWithinAt_iff'] theorem continuous_iff' [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ (a), ∀ ε > 0, ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {u : β → α} {a : α} : Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, dist (u n) a < ε := (atTop_basis.tendsto_iff nhds_basis_ball).trans <| by simp only [true_and, mem_ball, mem_Ici] /-- A variant of `tendsto_atTop` that uses `∃ N, ∀ n > N, ...` rather than `∃ N, ∀ n ≥ N, ...` -/ theorem tendsto_atTop' [Nonempty β] [SemilatticeSup β] [NoMaxOrder β] {u : β → α} {a : α} : Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n > N, dist (u n) a < ε := (atTop_basis_Ioi.tendsto_iff nhds_basis_ball).trans <| by simp only [true_and, gt_iff_lt, mem_Ioi, mem_ball] theorem isOpen_singleton_iff {α : Type*} [PseudoMetricSpace α] {x : α} : IsOpen ({x} : Set α) ↔ ∃ ε > 0, ∀ y, dist y x < ε → y = x := by simp [isOpen_iff, subset_singleton_iff, mem_ball] theorem _root_.Dense.exists_dist_lt {s : Set α} (hs : Dense s) (x : α) {ε : ℝ} (hε : 0 < ε) : ∃ y ∈ s, dist x y < ε := by have : (ball x ε).Nonempty := by simp [hε] simpa only [mem_ball'] using hs.exists_mem_open isOpen_ball this nonrec theorem _root_.DenseRange.exists_dist_lt {β : Type*} {f : β → α} (hf : DenseRange f) (x : α) {ε : ℝ} (hε : 0 < ε) : ∃ y, dist x (f y) < ε := exists_range_iff.1 (hf.exists_dist_lt x hε) /-- (Pseudo) metric space has discrete `UniformSpace` structure iff the distances between distinct points are uniformly bounded away from zero. -/ protected lemma uniformSpace_eq_bot : ‹PseudoMetricSpace α›.toUniformSpace = ⊥ ↔ ∃ r : ℝ, 0 < r ∧ Pairwise (r ≤ dist · · : α → α → Prop) := by simp only [uniformity_basis_dist.uniformSpace_eq_bot, mem_setOf_eq, not_lt] end Metric open Metric /-- If the distances between distinct points in a (pseudo) metric space are uniformly bounded away from zero, then the space has discrete topology. -/ lemma DiscreteTopology.of_forall_le_dist {α} [PseudoMetricSpace α] {r : ℝ} (hpos : 0 < r) (hr : Pairwise (r ≤ dist · · : α → α → Prop)) : DiscreteTopology α := ⟨by rw [Metric.uniformSpace_eq_bot.2 ⟨r, hpos, hr⟩, UniformSpace.toTopologicalSpace_bot]⟩ /- Instantiate a pseudometric space as a pseudoemetric space. Before we can state the instance, we need to show that the uniform structure coming from the edistance and the distance coincide. -/ theorem Metric.uniformity_edist_aux {α} (d : α → α → ℝ≥0) : ⨅ ε > (0 : ℝ), 𝓟 { p : α × α | ↑(d p.1 p.2) < ε } = ⨅ ε > (0 : ℝ≥0∞), 𝓟 { p : α × α | ↑(d p.1 p.2) < ε } := by simp only [le_antisymm_iff, le_iInf_iff, le_principal_iff] refine ⟨fun ε hε => ?_, fun ε hε => ?_⟩ · rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hε with ⟨ε', ε'0, ε'ε⟩ refine mem_iInf_of_mem (ε' : ℝ) (mem_iInf_of_mem (ENNReal.coe_pos.1 ε'0) ?_) exact fun x hx => lt_trans (ENNReal.coe_lt_coe.2 hx) ε'ε · lift ε to ℝ≥0 using le_of_lt hε refine mem_iInf_of_mem (ε : ℝ≥0∞) (mem_iInf_of_mem (ENNReal.coe_pos.2 hε) ?_) exact fun _ => ENNReal.coe_lt_coe.1 theorem Metric.uniformity_edist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := by simp only [PseudoMetricSpace.uniformity_dist, dist_nndist, edist_nndist, Metric.uniformity_edist_aux] -- see Note [lower instance priority] /-- A pseudometric space induces a pseudoemetric space -/ instance (priority := 100) PseudoMetricSpace.toPseudoEMetricSpace : PseudoEMetricSpace α := { ‹PseudoMetricSpace α› with edist_self := by simp [edist_dist] edist_comm := fun _ _ => by simp only [edist_dist, dist_comm] edist_triangle := fun x y z => by simp only [edist_dist, ← ENNReal.ofReal_add, dist_nonneg] rw [ENNReal.ofReal_le_ofReal_iff _] · exact dist_triangle _ _ _ · simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg uniformity_edist := Metric.uniformity_edist } /-- In a pseudometric space, an open ball of infinite radius is the whole space -/ theorem Metric.eball_top_eq_univ (x : α) : EMetric.ball x ∞ = Set.univ := Set.eq_univ_iff_forall.mpr fun y => edist_lt_top y x /-- Balls defined using the distance or the edistance coincide -/ @[simp] theorem Metric.emetric_ball {x : α} {ε : ℝ} : EMetric.ball x (ENNReal.ofReal ε) = ball x ε := by ext y simp only [EMetric.mem_ball, mem_ball, edist_dist] exact ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg /-- Balls defined using the distance or the edistance coincide -/ @[simp] theorem Metric.emetric_ball_nnreal {x : α} {ε : ℝ≥0} : EMetric.ball x ε = ball x ε := by rw [← Metric.emetric_ball] simp /-- Closed balls defined using the distance or the edistance coincide -/ theorem Metric.emetric_closedBall {x : α} {ε : ℝ} (h : 0 ≤ ε) : EMetric.closedBall x (ENNReal.ofReal ε) = closedBall x ε := by ext y; simp [edist_le_ofReal h] /-- Closed balls defined using the distance or the edistance coincide -/ @[simp] theorem Metric.emetric_closedBall_nnreal {x : α} {ε : ℝ≥0} : EMetric.closedBall x ε = closedBall x ε := by rw [← Metric.emetric_closedBall ε.coe_nonneg, ENNReal.ofReal_coe_nnreal] @[simp] theorem Metric.emetric_ball_top (x : α) : EMetric.ball x ⊤ = univ := eq_univ_of_forall fun _ => edist_lt_top _ _ /-- Build a new pseudometric space from an old one where the bundled uniform structure is provably (but typically non-definitionaly) equal to some given uniform structure. See Note [forgetful inheritance]. See Note [reducible non-instances]. -/ abbrev PseudoMetricSpace.replaceUniformity {α} [U : UniformSpace α] (m : PseudoMetricSpace α) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : PseudoMetricSpace α := { m with toUniformSpace := U uniformity_dist := H.trans PseudoMetricSpace.uniformity_dist } theorem PseudoMetricSpace.replaceUniformity_eq {α} [U : UniformSpace α] (m : PseudoMetricSpace α) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : m.replaceUniformity H = m := by ext rfl -- ensure that the bornology is unchanged when replacing the uniformity. example {α} [U : UniformSpace α] (m : PseudoMetricSpace α) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : (PseudoMetricSpace.replaceUniformity m H).toBornology = m.toBornology := by with_reducible_and_instances rfl /-- Build a new pseudo metric space from an old one where the bundled topological structure is provably (but typically non-definitionaly) equal to some given topological structure. See Note [forgetful inheritance]. See Note [reducible non-instances]. -/ abbrev PseudoMetricSpace.replaceTopology {γ} [U : TopologicalSpace γ] (m : PseudoMetricSpace γ) (H : U = m.toUniformSpace.toTopologicalSpace) : PseudoMetricSpace γ := @PseudoMetricSpace.replaceUniformity γ (m.toUniformSpace.replaceTopology H) m rfl theorem PseudoMetricSpace.replaceTopology_eq {γ} [U : TopologicalSpace γ] (m : PseudoMetricSpace γ) (H : U = m.toUniformSpace.toTopologicalSpace) : m.replaceTopology H = m := by ext rfl /-- One gets a pseudometric space from an emetric space if the edistance is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the uniformity are defeq in the pseudometric space and the pseudoemetric space. In this definition, the distance is given separately, to be able to prescribe some expression which is not defeq to the push-forward of the edistance to reals. See note [reducible non-instances]. -/ abbrev PseudoEMetricSpace.toPseudoMetricSpaceOfDist {X : Type*} [e : PseudoEMetricSpace X] (dist : X → X → ℝ) (dist_nonneg : ∀ x y, 0 ≤ dist x y) (h : ∀ x y, edist x y = .ofReal (dist x y)) : PseudoMetricSpace X where dist := dist dist_self x := by simpa [h, (dist_nonneg _ _).ge_iff_eq', -edist_self] using edist_self x dist_comm x y := by simpa [h, dist_nonneg] using edist_comm x y dist_triangle x y z := by simpa [h, dist_nonneg, add_nonneg, ← ENNReal.ofReal_add] using edist_triangle x y z edist := edist edist_dist _ _ := by simp only [h] toUniformSpace := PseudoEMetricSpace.toUniformSpace uniformity_dist := e.uniformity_edist.trans <| by simpa [h, dist_nonneg, ENNReal.coe_toNNReal_eq_toReal] using (Metric.uniformity_edist_aux fun x y : X => (edist x y).toNNReal).symm /-- One gets a pseudometric space from an emetric space if the edistance is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the uniformity are defeq in the pseudometric space and the emetric space. -/ abbrev PseudoEMetricSpace.toPseudoMetricSpace {α : Type u} [PseudoEMetricSpace α] (h : ∀ x y : α, edist x y ≠ ⊤) : PseudoMetricSpace α := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (ENNReal.toReal <| edist · ·) (by simp) (by simp [h]) /-- Build a new pseudometric space from an old one where the bundled bornology structure is provably (but typically non-definitionaly) equal to some given bornology structure. See Note [forgetful inheritance]. See Note [reducible non-instances]. -/ abbrev PseudoMetricSpace.replaceBornology {α} [B : Bornology α] (m : PseudoMetricSpace α) (H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) : PseudoMetricSpace α := { m with toBornology := B cobounded_sets := Set.ext <| compl_surjective.forall.2 fun s => (H s).trans <| by rw [isBounded_iff, mem_setOf_eq, compl_compl] } theorem PseudoMetricSpace.replaceBornology_eq {α} [m : PseudoMetricSpace α] [B : Bornology α] (H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) : PseudoMetricSpace.replaceBornology _ H = m := by ext rfl -- ensure that the uniformity is unchanged when replacing the bornology. example {α} [B : Bornology α] (m : PseudoMetricSpace α) (H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) : (PseudoMetricSpace.replaceBornology m H).toUniformSpace = m.toUniformSpace := by with_reducible_and_instances rfl section Real /-- Instantiate the reals as a pseudometric space. -/ instance Real.pseudoMetricSpace : PseudoMetricSpace ℝ where dist x y := |x - y| dist_self := by simp [abs_zero] dist_comm _ _ := abs_sub_comm _ _ dist_triangle _ _ _ := abs_sub_le _ _ _ theorem Real.dist_eq (x y : ℝ) : dist x y = |x - y| := rfl theorem Real.nndist_eq (x y : ℝ) : nndist x y = Real.nnabs (x - y) := rfl theorem Real.nndist_eq' (x y : ℝ) : nndist x y = Real.nnabs (y - x) := nndist_comm _ _ theorem Real.dist_0_eq_abs (x : ℝ) : dist x 0 = |x| := by simp [Real.dist_eq] theorem Real.sub_le_dist (x y : ℝ) : x - y ≤ dist x y := by rw [Real.dist_eq, le_abs] exact Or.inl (le_refl _) theorem Real.ball_eq_Ioo (x r : ℝ) : ball x r = Ioo (x - r) (x + r) := Set.ext fun y => by rw [mem_ball, dist_comm, Real.dist_eq, abs_sub_lt_iff, mem_Ioo, ← sub_lt_iff_lt_add', sub_lt_comm] theorem Real.closedBall_eq_Icc {x r : ℝ} : closedBall x r = Icc (x - r) (x + r) := by ext y rw [mem_closedBall, dist_comm, Real.dist_eq, abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le_comm] theorem Real.Ioo_eq_ball (x y : ℝ) : Ioo x y = ball ((x + y) / 2) ((y - x) / 2) := by rw [Real.ball_eq_Ioo, ← sub_div, add_comm, ← sub_add, add_sub_cancel_left, add_self_div_two, ← add_div, add_assoc, add_sub_cancel, add_self_div_two] theorem Real.Icc_eq_closedBall (x y : ℝ) : Icc x y = closedBall ((x + y) / 2) ((y - x) / 2) := by rw [Real.closedBall_eq_Icc, ← sub_div, add_comm, ← sub_add, add_sub_cancel_left, add_self_div_two, ← add_div, add_assoc, add_sub_cancel, add_self_div_two] theorem Metric.uniformity_eq_comap_nhds_zero : 𝓤 α = comap (fun p : α × α => dist p.1 p.2) (𝓝 (0 : ℝ)) := by ext s simp only [mem_uniformity_dist, (nhds_basis_ball.comap _).mem_iff] simp [subset_def, Real.dist_0_eq_abs] theorem tendsto_uniformity_iff_dist_tendsto_zero {f : ι → α × α} {p : Filter ι} : Tendsto f p (𝓤 α) ↔ Tendsto (fun x => dist (f x).1 (f x).2) p (𝓝 0) := by rw [Metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff, Function.comp_def] theorem Filter.Tendsto.congr_dist {f₁ f₂ : ι → α} {p : Filter ι} {a : α} (h₁ : Tendsto f₁ p (𝓝 a)) (h : Tendsto (fun x => dist (f₁ x) (f₂ x)) p (𝓝 0)) : Tendsto f₂ p (𝓝 a) := h₁.congr_uniformity <| tendsto_uniformity_iff_dist_tendsto_zero.2 h alias tendsto_of_tendsto_of_dist := Filter.Tendsto.congr_dist theorem tendsto_iff_of_dist {f₁ f₂ : ι → α} {p : Filter ι} {a : α} (h : Tendsto (fun x => dist (f₁ x) (f₂ x)) p (𝓝 0)) : Tendsto f₁ p (𝓝 a) ↔ Tendsto f₂ p (𝓝 a) := Uniform.tendsto_congr <| tendsto_uniformity_iff_dist_tendsto_zero.2 h end Real theorem PseudoMetricSpace.dist_eq_of_dist_zero (x : α) {y z : α} (h : dist y z = 0) : dist x y = dist x z := dist_comm y x ▸ dist_comm z x ▸ sub_eq_zero.1 (abs_nonpos_iff.1 (h ▸ abs_dist_sub_le y z x)) theorem dist_dist_dist_le_left (x y z : α) : dist (dist x z) (dist y z) ≤ dist x y := abs_dist_sub_le .. theorem dist_dist_dist_le_right (x y z : α) : dist (dist x y) (dist x z) ≤ dist y z := by simpa only [dist_comm x] using dist_dist_dist_le_left y z x theorem dist_dist_dist_le (x y x' y' : α) : dist (dist x y) (dist x' y') ≤ dist x x' + dist y y' := (dist_triangle _ _ _).trans <| add_le_add (dist_dist_dist_le_left _ _ _) (dist_dist_dist_le_right _ _ _) theorem nhds_comap_dist (a : α) : ((𝓝 (0 : ℝ)).comap (dist · a)) = 𝓝 a := by simp only [@nhds_eq_comap_uniformity α, Metric.uniformity_eq_comap_nhds_zero, comap_comap, Function.comp_def, dist_comm] theorem tendsto_iff_dist_tendsto_zero {f : β → α} {x : Filter β} {a : α} : Tendsto f x (𝓝 a) ↔ Tendsto (fun b => dist (f b) a) x (𝓝 0) := by rw [← nhds_comap_dist a, tendsto_comap_iff, Function.comp_def] namespace Metric variable {x y z : α} {ε ε₁ ε₂ : ℝ} {s : Set α} theorem ball_subset_interior_closedBall : ball x ε ⊆ interior (closedBall x ε) := interior_maximal ball_subset_closedBall isOpen_ball /-- ε-characterization of the closure in pseudometric spaces -/ theorem mem_closure_iff {s : Set α} {a : α} : a ∈ closure s ↔ ∀ ε > 0, ∃ b ∈ s, dist a b < ε := (mem_closure_iff_nhds_basis nhds_basis_ball).trans <| by simp only [mem_ball, dist_comm] theorem mem_closure_range_iff {e : β → α} {a : α} : a ∈ closure (range e) ↔ ∀ ε > 0, ∃ k : β, dist a (e k) < ε := by simp only [mem_closure_iff, exists_range_iff] theorem mem_closure_range_iff_nat {e : β → α} {a : α} : a ∈ closure (range e) ↔ ∀ n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) := (mem_closure_iff_nhds_basis nhds_basis_ball_inv_nat_succ).trans <| by simp only [mem_ball, dist_comm, exists_range_iff, forall_const] theorem mem_of_closed' {s : Set α} (hs : IsClosed s) {a : α} : a ∈ s ↔ ∀ ε > 0, ∃ b ∈ s, dist a b < ε := by simpa only [hs.closure_eq] using @mem_closure_iff _ _ s a theorem dense_iff {s : Set α} : Dense s ↔ ∀ x, ∀ r > 0, (ball x r ∩ s).Nonempty := forall_congr' fun x => by simp only [mem_closure_iff, Set.Nonempty, mem_inter_iff, mem_ball', and_comm] theorem dense_iff_iUnion_ball (s : Set α) : Dense s ↔ ∀ r > 0, ⋃ c ∈ s, ball c r = univ := by simp_rw [eq_univ_iff_forall, mem_iUnion, exists_prop, mem_ball, Dense, mem_closure_iff, forall_comm (α := α)] theorem denseRange_iff {f : β → α} : DenseRange f ↔ ∀ x, ∀ r > 0, ∃ y, dist x (f y) < r := forall_congr' fun x => by simp only [mem_closure_iff, exists_range_iff] end Metric open Additive Multiplicative instance : PseudoMetricSpace (Additive α) := ‹_› instance : PseudoMetricSpace (Multiplicative α) := ‹_› section variable [PseudoMetricSpace X] @[simp] theorem nndist_ofMul (a b : X) : nndist (ofMul a) (ofMul b) = nndist a b := rfl @[simp] theorem nndist_ofAdd (a b : X) : nndist (ofAdd a) (ofAdd b) = nndist a b := rfl @[simp] theorem nndist_toMul (a b : Additive X) : nndist a.toMul b.toMul = nndist a b := rfl @[simp] theorem nndist_toAdd (a b : Multiplicative X) : nndist a.toAdd b.toAdd = nndist a b := rfl end open OrderDual instance : PseudoMetricSpace αᵒᵈ := ‹_› section variable [PseudoMetricSpace X] @[simp] theorem nndist_toDual (a b : X) : nndist (toDual a) (toDual b) = nndist a b := rfl @[simp] theorem nndist_ofDual (a b : Xᵒᵈ) : nndist (ofDual a) (ofDual b) = nndist a b := rfl end
.lake/packages/mathlib/Mathlib/Topology/MetricSpace/Pseudo/Real.lean
import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.Topology.MetricSpace.Pseudo.Pi /-! # Lemmas about distances between points in intervals in `ℝ`. -/ open Bornology Filter Metric Set open scoped NNReal Topology namespace Real variable {ι : Type*} lemma dist_left_le_of_mem_uIcc {x y z : ℝ} (h : y ∈ uIcc x z) : dist x y ≤ dist x z := by simpa only [dist_comm x] using abs_sub_left_of_mem_uIcc h lemma dist_right_le_of_mem_uIcc {x y z : ℝ} (h : y ∈ uIcc x z) : dist y z ≤ dist x z := by simpa only [dist_comm _ z] using abs_sub_right_of_mem_uIcc h lemma dist_le_of_mem_uIcc {x y x' y' : ℝ} (hx : x ∈ uIcc x' y') (hy : y ∈ uIcc x' y') : dist x y ≤ dist x' y' := abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc (by rwa [uIcc_comm]) (by rwa [uIcc_comm]) lemma dist_le_of_mem_Icc {x y x' y' : ℝ} (hx : x ∈ Icc x' y') (hy : y ∈ Icc x' y') : dist x y ≤ y' - x' := by simpa only [Real.dist_eq, abs_of_nonpos (sub_nonpos.2 <| hx.1.trans hx.2), neg_sub] using Real.dist_le_of_mem_uIcc (Icc_subset_uIcc hx) (Icc_subset_uIcc hy) lemma dist_le_of_mem_Icc_01 {x y : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) (hy : y ∈ Icc (0 : ℝ) 1) : dist x y ≤ 1 := by simpa only [sub_zero] using Real.dist_le_of_mem_Icc hx hy variable [Fintype ι] {x y x' y' : ι → ℝ} lemma dist_le_of_mem_pi_Icc (hx : x ∈ Icc x' y') (hy : y ∈ Icc x' y') : dist x y ≤ dist x' y' := by refine (dist_pi_le_iff dist_nonneg).2 fun b => (Real.dist_le_of_mem_uIcc ?_ ?_).trans (dist_le_pi_dist x' y' b) <;> refine Icc_subset_uIcc ?_ exacts [⟨hx.1 _, hx.2 _⟩, ⟨hy.1 _, hy.2 _⟩] end Real
.lake/packages/mathlib/Mathlib/Topology/VectorBundle/Riemannian.lean
import Mathlib.Analysis.InnerProductSpace.LinearMap import Mathlib.Topology.VectorBundle.Constructions import Mathlib.Topology.VectorBundle.Hom /-! # Riemannian vector bundles Given a real vector bundle over a topological space whose fibers are all endowed with an inner product, we say that this bundle is Riemannian if the inner product depends continuously on the base point. We introduce a typeclass `[IsContinuousRiemannianBundle F E]` registering this property. Under this assumption, we show that the inner product of two continuous maps into the same fibers of the bundle is a continuous function. If one wants to endow an existing vector bundle with a Riemannian metric, there is a subtlety: the inner product space structure on the fibers should give rise to a topology on the fibers which is defeq to the original one, to avoid diamonds. To do this, we introduce a class `[RiemannianBundle E]` containing the data of an inner product on the fibers defining the same topology as the original one. Given this class, we can construct `NormedAddCommGroup` and `InnerProductSpace` instances on the fibers, compatible in a defeq way with the initial topology. If the data used to register the instance `RiemannianBundle E` depends continuously on the base point, we register automatically an instance of `[IsContinuousRiemannianBundle F E]` (and similarly if the data is smooth). The general theory should be built assuming `[IsContinuousRiemannianBundle F E]`, while the `[RiemannianBundle E]` mechanism is only to build data in specific situations. As instances related to Riemannian bundles are both costly and quite specific, they are scoped to the `Bundle` namespace. ## Keywords Vector bundle, Riemannian metric -/ open Bundle ContinuousLinearMap Filter open scoped Topology variable {B : Type*} [TopologicalSpace B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℝ (E x)] [FiberBundle F E] [VectorBundle ℝ F E] local notation "⟪" x ", " y "⟫" => inner ℝ x y variable (F E) in /-- Consider a real vector bundle in which each fiber is endowed with an inner product. We say that the bundle is *Riemannian* if the inner product depends continuously on the base point. This assumption is spelled `IsContinuousRiemannianBundle F E` where `F` is the model fiber, and `E : B → Type*` is the bundle. -/ class IsContinuousRiemannianBundle : Prop where /-- There exists a bilinear form, depending continuously on the basepoint and defining the inner product in the fibers. This is expressed as an existence statement so that it is Prop-valued in terms of existing data, the inner product on the fibers and the fiber bundle structure. -/ exists_continuous : ∃ g : (Π x, E x →L[ℝ] E x →L[ℝ] ℝ), Continuous (fun (x : B) ↦ TotalSpace.mk' (F →L[ℝ] F →L[ℝ] ℝ) x (g x)) ∧ ∀ (x : B) (v w : E x), ⟪v, w⟫ = g x v w section Trivial variable {F₁ : Type*} [NormedAddCommGroup F₁] [InnerProductSpace ℝ F₁] /-- A trivial vector bundle, in which the model fiber has a inner product, is a Riemannian bundle. -/ instance : IsContinuousRiemannianBundle F₁ (Bundle.Trivial B F₁) := by refine ⟨fun x ↦ innerSL ℝ, ?_, fun x v w ↦ rfl⟩ rw [continuous_iff_continuousAt] intro x rw [FiberBundle.continuousAt_totalSpace] refine ⟨continuousAt_id, ?_⟩ convert continuousAt_const (y := innerSL ℝ) ext v w simp [hom_trivializationAt_apply, inCoordinates, Trivialization.linearMapAt_apply] end Trivial section Continuous variable {M : Type*} [TopologicalSpace M] [h : IsContinuousRiemannianBundle F E] {b : M → B} {v w : ∀ x, E (b x)} {s : Set M} {x : M} /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. Version with `ContinuousWithinAt`. -/ lemma ContinuousWithinAt.inner_bundle (hv : ContinuousWithinAt (fun m ↦ (v m : TotalSpace F E)) s x) (hw : ContinuousWithinAt (fun m ↦ (w m : TotalSpace F E)) s x) : ContinuousWithinAt (fun m ↦ ⟪v m, w m⟫) s x := by rcases h.exists_continuous with ⟨g, g_cont, hg⟩ have hf : ContinuousWithinAt b s x := by simp only [FiberBundle.continuousWithinAt_totalSpace] at hv exact hv.1 simp only [hg] have : ContinuousWithinAt (fun m ↦ TotalSpace.mk' ℝ (E := Bundle.Trivial B ℝ) (b m) (g (b m) (v m) (w m))) s x := (g_cont.continuousAt.comp_continuousWithinAt hf).clm_bundle_apply₂ (F₁ := F) (F₂ := F) hv hw simp only [FiberBundle.continuousWithinAt_totalSpace] at this exact this.2 /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. Version with `ContinuousAt`. -/ lemma ContinuousAt.inner_bundle (hv : ContinuousAt (fun m ↦ (v m : TotalSpace F E)) x) (hw : ContinuousAt (fun m ↦ (w m : TotalSpace F E)) x) : ContinuousAt (fun b ↦ ⟪v b, w b⟫) x := by simp only [← continuousWithinAt_univ] at hv hw ⊢ exact ContinuousWithinAt.inner_bundle hv hw /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. Version with `ContinuousOn`. -/ lemma ContinuousOn.inner_bundle (hv : ContinuousOn (fun m ↦ (v m : TotalSpace F E)) s) (hw : ContinuousOn (fun m ↦ (w m : TotalSpace F E)) s) : ContinuousOn (fun b ↦ ⟪v b, w b⟫) s := fun x hx ↦ (hv x hx).inner_bundle (hw x hx) /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. -/ lemma Continuous.inner_bundle (hv : Continuous (fun m ↦ (v m : TotalSpace F E))) (hw : Continuous (fun m ↦ (w m : TotalSpace F E))) : Continuous (fun b ↦ ⟪v b, w b⟫) := by simp only [continuous_iff_continuousAt] at hv hw ⊢ exact fun x ↦ (hv x).inner_bundle (hw x) variable (F E) /-- In a continuous Riemannian bundle, local changes of coordinates given by the trivialization at a point distort the norm by a factor arbitrarily close to 1. -/ lemma eventually_norm_symmL_trivializationAt_self_comp_lt (x : B) {r : ℝ} (hr : 1 < r) : ∀ᶠ y in 𝓝 x, ‖((trivializationAt F E x).symmL ℝ x) ∘L ((trivializationAt F E x).continuousLinearMapAt ℝ y)‖ < r := by /- We will expand the definition of continuity of the inner product structure, in the chart. Denote `g' x` the metric in the fiber of `x`, read in the chart. For `y` close to `x`, then `g' y` and `g' x` are close. The inequality we have to prove reduces to comparing `g' y w w` and `g' x w w`, where `w` is the image in the chart of a tangent vector `v` at `y`. Their difference is controlled by `δ ‖w‖ ^ 2` for any small `δ > 0`. To conclude, we argue that `‖w‖` is comparable to the norm inside the fiber over `x`, i.e., `g' x w w`, because there is a continuous linear equivalence between these two spaces by definition of vector bundles. -/ obtain ⟨r', hr', r'r⟩ : ∃ r', 1 < r' ∧ r' < r := exists_between hr have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x let G := (trivializationAt F E x).continuousLinearEquivAt ℝ x h'x let C := (‖(G : E x →L[ℝ] F)‖) ^ 2 -- choose `δ` small enough that the computation below works when the metrics at `x` and `y` -- are `δ` close. When writing this proof, I have followed my nose in the computation, and -- recorded only in the end how small `δ` needs to be. The reader should skip the precise -- condition for now, as it doesn't give any useful insight. obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ (r' ^ 2)⁻¹ < 1 - δ * C := by have A : ∀ᶠ δ in 𝓝[>] (0 : ℝ), 0 < δ := self_mem_nhdsWithin have B : Tendsto (fun δ ↦ 1 - δ * C) (𝓝[>] 0) (𝓝 (1 - 0 * C)) := by apply tendsto_inf_left exact tendsto_const_nhds.sub (tendsto_id.mul tendsto_const_nhds) have B' : ∀ᶠ δ in 𝓝[>] 0, (r' ^ 2)⁻¹ < 1 - δ * C := by apply (tendsto_order.1 B).1 simpa using inv_lt_one_of_one_lt₀ (by nlinarith) exact (A.and B').exists rcases h.exists_continuous with ⟨g, g_cont, hg⟩ let g' : B → F →L[ℝ] F →L[ℝ] ℝ := fun y ↦ inCoordinates F E (F →L[ℝ] ℝ) (fun x ↦ E x →L[ℝ] ℝ) x y x y (g y) have hg' : ContinuousAt g' x := by have W := g_cont.continuousAt (x := x) simp only [continuousAt_hom_bundle] at W exact W.2 have : ∀ᶠ y in 𝓝 x, dist (g' y) (g' x) < δ := by rw [Metric.continuousAt_iff'] at hg' apply hg' _ δpos filter_upwards [this, (trivializationAt F E x).open_baseSet.mem_nhds h'x] with y hy h'y have : ‖g' x - g' y‖ ≤ δ := by rw [← dist_eq_norm']; exact hy.le -- To show that the norm of the composition is bounded by `r'`, we start from a vector -- `‖v‖`. We will show that its image has a controlled norm. apply (opNorm_le_bound _ (by linarith) (fun v ↦ ?_)).trans_lt r'r -- rewrite the norm of `‖v‖` and of its image in terms of norms in the model space let w := (trivializationAt F E x).continuousLinearMapAt ℝ y v suffices ‖((trivializationAt F E x).symmL ℝ x) w‖ ^ 2 ≤ r' ^ 2 * ‖v‖ ^ 2 from le_of_sq_le_sq (by simpa [mul_pow]) (by positivity) simp only [Trivialization.symmL_apply, ← real_inner_self_eq_norm_sq, hg] have hgy : g y v v = g' y w w := by rw [inCoordinates_apply_eq₂ h'y h'y (Set.mem_univ _)] have A : ((trivializationAt F E x).symm y) ((trivializationAt F E x).linearMapAt ℝ y v) = v := by convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'y).symm_apply_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'y] rfl simp [A, w] have hgx : g x ((trivializationAt F E x).symm x w) ((trivializationAt F E x).symm x w) = g' x w w := by rw [inCoordinates_apply_eq₂ h'x h'x (Set.mem_univ _)] simp rw [hgx, hgy] -- get a good control for the norms of `w` in the model space, using continuity have : g' x w w ≤ δ * C * g' x w w + g' y w w := calc g' x w w _ = (g' x - g' y) w w + g' y w w := by simp _ ≤ ‖g' x - g' y‖ * ‖w‖ * ‖w‖ + g' y w w := by grw [← le_opNorm₂, ← Real.le_norm_self] _ ≤ δ * ‖w‖ ^ 2 + g' y w w := by rw [pow_two, mul_assoc]; gcongr _ ≤ δ * (‖(G : E x →L[ℝ] F)‖ * ‖G.symm w‖) ^ 2 + g' y w w := by grw [← le_opNorm] simp _ = δ * C * ‖G.symm w‖^2 + g' y w w := by ring _ = δ * C * g x (G.symm w) (G.symm w) + g' y w w := by simp [← hg] _ = δ * C * g' x w w + g' y w w := by rw [← hgx]; rfl have : (1 - δ * C) * g' x w w ≤ g' y w w := by linarith rw [← (le_div_iff₀' (lt_of_le_of_lt (by positivity) hδ )), div_eq_inv_mul] at this grw [this] gcongr · rw [← hgy, ← hg,real_inner_self_eq_norm_sq] positivity · exact inv_le_of_inv_le₀ (by positivity) hδ.le /-- In a continuous Riemannian bundle, the trivialization at a point is locally bounded in norm. -/ lemma eventually_norm_trivializationAt_lt (x : B) : ∃ C > 0, ∀ᶠ y in 𝓝 x, ‖(trivializationAt F E x).continuousLinearMapAt ℝ y‖ < C := by refine ⟨(1 + ‖(trivializationAt F E x).continuousLinearMapAt ℝ x‖) * 2, by positivity, ?_⟩ filter_upwards [eventually_norm_symmL_trivializationAt_self_comp_lt F E x one_lt_two] with y hy have A : ((trivializationAt F E x).continuousLinearMapAt ℝ x) ∘L ((trivializationAt F E x).symmL ℝ x) = ContinuousLinearMap.id _ _ := by ext v have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x simp only [coe_comp', Trivialization.continuousLinearMapAt_apply, Trivialization.symmL_apply, Function.comp_apply, coe_id', id_eq] convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'x).apply_symm_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'x] rfl have : (trivializationAt F E x).continuousLinearMapAt ℝ y = (ContinuousLinearMap.id _ _) ∘L ((trivializationAt F E x).continuousLinearMapAt ℝ y) := by simp grw [this, ← A, comp_assoc, opNorm_comp_le] gcongr linarith /-- In a continuous Riemannian bundle, local changes of coordinates given by the trivialization at a point distort the norm by a factor arbitrarily close to 1. -/ lemma eventually_norm_symmL_trivializationAt_comp_self_lt (x : B) {r : ℝ} (hr : 1 < r) : ∀ᶠ y in 𝓝 x, ‖((trivializationAt F E x).symmL ℝ y) ∘L ((trivializationAt F E x).continuousLinearMapAt ℝ x)‖ < r := by /- We will expand the definition of continuity of the inner product structure, in the chart. Denote `g' x` the metric in the fiber of `x`, read in the chart. For `y` close to `x`, then `g' y` and `g' x` are close. The inequality we have to prove reduces to comparing `g' y w w` and `g' x w w`, where `w` is the image in the chart of a tangent vector `v` at `x`. Their difference is controlled by `δ ‖w‖ ^ 2` for any small `δ > 0`. To conclude, we argue that `‖w‖` is comparable to the norm inside the fiber over `x`, i.e., `g' x w w`, because there is a continuous linear equivalence between these two spaces by definition of vector bundles. -/ obtain ⟨r', hr', r'r⟩ : ∃ r', 1 < r' ∧ r' < r := exists_between hr have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x let G := (trivializationAt F E x).continuousLinearEquivAt ℝ x h'x let C := (‖(G : E x →L[ℝ] F)‖) ^ 2 -- choose `δ` small enough that the computation below works when the metrics at `x` and `y` -- are `δ` close. When writing this proof, I have followed my nose in the computation, and -- recorded only in the end how small `δ` needs to be. The reader should skip the precise -- condition for now, as it doesn't give any useful insight. obtain ⟨δ, δpos, h'δ⟩ : ∃ δ, 0 < δ ∧ (1 + δ * C) < r' ^ 2 := by have A : ∀ᶠ δ in 𝓝[>] (0 : ℝ), 0 < δ := self_mem_nhdsWithin have B : Tendsto (fun δ ↦ 1 + δ * C) (𝓝[>] 0) (𝓝 (1 + 0 * C)) := by apply tendsto_inf_left exact tendsto_const_nhds.add (tendsto_id.mul tendsto_const_nhds) have B' : ∀ᶠ δ in 𝓝[>] 0, 1 + δ * C < r' ^ 2 := by apply (tendsto_order.1 B).2 simpa using hr'.trans_le (le_abs_self _) exact (A.and B').exists rcases h.exists_continuous with ⟨g, g_cont, hg⟩ let g' : B → F →L[ℝ] F →L[ℝ] ℝ := fun y ↦ inCoordinates F E (F →L[ℝ] ℝ) (fun x ↦ E x →L[ℝ] ℝ) x y x y (g y) have hg' : ContinuousAt g' x := by have W := g_cont.continuousAt (x := x) simp only [continuousAt_hom_bundle] at W exact W.2 have : ∀ᶠ y in 𝓝 x, dist (g' y) (g' x) < δ := by rw [Metric.continuousAt_iff'] at hg' apply hg' _ δpos filter_upwards [this, (trivializationAt F E x).open_baseSet.mem_nhds h'x] with y hy h'y have : ‖g' y - g' x‖ ≤ δ := by rw [← dist_eq_norm]; exact hy.le -- To show that the norm of the composition is bounded by `r'`, we start from a vector -- `‖v‖`. We will show that its image has a controlled norm. apply (opNorm_le_bound _ (by linarith) (fun v ↦ ?_)).trans_lt r'r -- rewrite the norm of `‖v‖` and of its image in terms of norms in the model space let w := (trivializationAt F E x).continuousLinearMapAt ℝ x v suffices ‖((trivializationAt F E x).symmL ℝ y) w‖ ^ 2 ≤ r' ^ 2 * ‖v‖ ^ 2 from le_of_sq_le_sq (by simpa [mul_pow]) (by positivity) simp only [Trivialization.symmL_apply, ← real_inner_self_eq_norm_sq, hg] have hgx : g x v v = g' x w w := by rw [inCoordinates_apply_eq₂ h'x h'x (Set.mem_univ _)] have A : ((trivializationAt F E x).symm x) ((trivializationAt F E x).linearMapAt ℝ x v) = v := by convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'x).symm_apply_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'x] rfl simp [A, w] have hgy : g y ((trivializationAt F E x).symm y w) ((trivializationAt F E x).symm y w) = g' y w w := by rw [inCoordinates_apply_eq₂ h'y h'y (Set.mem_univ _)] simp rw [hgx, hgy] -- get a good control for the norms of `w` in the model space, using continuity calc g' y w w _ = (g' y - g' x) w w + g' x w w := by simp _ ≤ ‖g' y - g' x‖ * ‖w‖ * ‖w‖ + g' x w w := by grw [← le_opNorm₂, ← Real.le_norm_self] _ ≤ δ * ‖w‖ ^ 2 + g' x w w := by rw [pow_two, mul_assoc]; gcongr _ ≤ δ * (‖(G : E x →L[ℝ] F)‖ * ‖G.symm w‖) ^ 2 + g' x w w := by grw [← le_opNorm] simp _ = δ * C * ‖G.symm w‖^2 + g' x w w := by ring _ = δ * C * g x (G.symm w) (G.symm w) + g' x w w := by simp [← hg] _ = δ * C * g' x w w + g' x w w := by congr rw [inCoordinates_apply_eq₂ h'x h'x (Set.mem_univ _)] simp only [Trivial.fiberBundle_trivializationAt', Trivial.linearMapAt_trivialization, LinearMap.id_coe, id_eq, w] rfl _ = (1 + δ * C) * g' x w w := by ring _ ≤ r' ^ 2 * g' x w w := by gcongr rw [← hgx, ← hg,real_inner_self_eq_norm_sq] positivity /-- In a continuous Riemannian bundle, the inverse of the trivialization at a point is locally bounded in norm. -/ lemma eventually_norm_symmL_trivializationAt_lt (x : B) : ∃ C > 0, ∀ᶠ y in 𝓝 x, ‖(trivializationAt F E x).symmL ℝ y‖ < C := by refine ⟨2 * (1 + ‖(trivializationAt F E x).symmL ℝ x‖), by positivity, ?_⟩ filter_upwards [eventually_norm_symmL_trivializationAt_comp_self_lt F E x one_lt_two] with y hy have A : ((trivializationAt F E x).continuousLinearMapAt ℝ x) ∘L ((trivializationAt F E x).symmL ℝ x) = ContinuousLinearMap.id _ _ := by ext v have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x simp only [coe_comp', Trivialization.continuousLinearMapAt_apply, Trivialization.symmL_apply, Function.comp_apply, coe_id', id_eq] convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'x).apply_symm_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'x] rfl have : (trivializationAt F E x).symmL ℝ y = ((trivializationAt F E x).symmL ℝ y) ∘L (ContinuousLinearMap.id _ _) := by simp grw [this, ← A, ← comp_assoc, opNorm_comp_le] gcongr linarith end Continuous namespace Bundle section Construction variable {B : Type*} [TopologicalSpace B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ b, TopologicalSpace (E b)] [∀ b, AddCommGroup (E b)] [∀ b, Module ℝ (E b)] [∀ b, IsTopologicalAddGroup (E b)] [∀ b, ContinuousConstSMul ℝ (E b)] [FiberBundle F E] [VectorBundle ℝ F E] open Bornology variable (E) in /-- A family of inner product space structures on the fibers of a fiber bundle, defining the same topology as the already existing one. This family is not assumed to be continuous or smooth: to guarantee continuity, resp. smoothness, of the inner product as a function of the base point, use `ContinuousRiemannianMetric` or `ContMDiffRiemannianMetric`. This structure is used through `RiemannianBundle` for typeclass inference, to register the inner product space structure on the fibers without creating diamonds. -/ structure RiemannianMetric where /-- The inner product along the fibers of the bundle. -/ inner (b : B) : E b →L[ℝ] E b →L[ℝ] ℝ symm (b : B) (v w : E b) : inner b v w = inner b w v pos (b : B) (v : E b) (hv : v ≠ 0) : 0 < inner b v v /-- The continuity at `0` is automatic when `E b` is isomorphic to a normed space, but since we are not making this assumption here we have to include it. -/ continuousAt (b : B) : ContinuousAt (fun (v : E b) ↦ inner b v v) 0 isVonNBounded (b : B) : IsVonNBounded ℝ {v : E b | inner b v v < 1} /-- `Core structure associated to a family of inner products on the fibers of a fiber bundle. This is an auxiliary construction to endow the fibers with an inner product space structure without creating diamonds. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ @[reducible] noncomputable def RiemannianMetric.toCore (g : RiemannianMetric E) (b : B) : InnerProductSpace.Core ℝ (E b) where inner v w := g.inner b v w conj_inner_symm v w := g.symm b w v re_inner_nonneg v := by rcases eq_or_ne v 0 with rfl | hv · simp · simpa using (g.pos b v hv).le add_left v w x := by simp smul_left c v := by simp definite v h := by contrapose! h; exact (g.pos b v h).ne' variable (E) in /-- Class used to create an inner product structure space on the fibers of a fiber bundle, without creating diamonds. Use as follows: * `instance : RiemannianBundle E := ⟨g⟩` where `g : RiemannianMetric E` registers the inner product space on the fibers; * `instance : RiemannianBundle E := ⟨g.toRiemannianMetric⟩` where `g : ContinuousRiemannianMetric F E` registers the inner product space on the fibers, and the fact that it varies continuously (i.e., a `[IsContinuousRiemannianBundle]` instance). * `instance : RiemannianBundle E := ⟨g.toRiemannianMetric⟩` where `g : ContMDiffRiemannianMetric IB n F E` registers the inner product space on the fibers, and the fact that it varies smoothly (and continuously), i.e., `[IsContMDiffRiemannianBundle]` and `[IsContinuousRiemannianBundle]` instances. -/ class RiemannianBundle where /-- The family of inner products on the fibers -/ g : RiemannianMetric E /-- A fiber in a bundle satisfying the `[RiemannianBundle E]` typeclass inherits a `NormedAddCommGroup` structure. The normal priority for an instance which always applies like this one should be 100. We use 80 as this is rather specialized, so we want other paths to be tried first typically. As this instance is quite specific and very costly because of higher-order unification, we also scope it to the `Bundle` namespace. -/ noncomputable scoped instance (priority := 80) [h : RiemannianBundle E] (b : B) : NormedAddCommGroup (E b) := (h.g.toCore b).toNormedAddCommGroupOfTopology (h.g.continuousAt b) (h.g.isVonNBounded b) /-- A fiber in a bundle satisfying the `[RiemannianBundle E]` typeclass inherits an `InnerProductSpace ℝ` structure. The normal priority for an instance which always applies like this one should be 100. We use 80 as this is rather specialized, so we want other paths to be tried first typically. As this instance is quite specific and very costly because of higher-order unification, we also scope it to the `Bundle` namespace. -/ noncomputable scoped instance (priority := 80) [h : RiemannianBundle E] (b : B) : InnerProductSpace ℝ (E b) := .ofCoreOfTopology (h.g.toCore b) (h.g.continuousAt b) (h.g.isVonNBounded b) variable (F E) in /-- A family of inner product space structures on the fibers of a fiber bundle, defining the same topology as the already existing one, and varying continuously with the base point. See also `ContMDiffRiemannianMetric` for a smooth version. This structure is used through `RiemannianBundle` for typeclass inference, to register the inner product space structure on the fibers without creating diamonds. -/ structure ContinuousRiemannianMetric where /-- The inner product along the fibers of the bundle. -/ inner (b : B) : E b →L[ℝ] E b →L[ℝ] ℝ symm (b : B) (v w : E b) : inner b v w = inner b w v pos (b : B) (v : E b) (hv : v ≠ 0) : 0 < inner b v v isVonNBounded (b : B) : IsVonNBounded ℝ {v : E b | inner b v v < 1} continuous : Continuous (fun (b : B) ↦ TotalSpace.mk' (F →L[ℝ] F →L[ℝ] ℝ) b (inner b)) /-- A continuous Riemannian metric is in particular a Riemannian metric. -/ def ContinuousRiemannianMetric.toRiemannianMetric (g : ContinuousRiemannianMetric F E) : RiemannianMetric E where inner := g.inner symm := g.symm pos := g.pos isVonNBounded := g.isVonNBounded continuousAt b := by -- Continuity of bilinear maps is only true on normed spaces. As `F` is a normed space by -- assumption, we transfer everything to `F` and argue there. let e : E b ≃L[ℝ] F := Trivialization.continuousLinearEquivAt ℝ (trivializationAt F E b) _ (FiberBundle.mem_baseSet_trivializationAt' b) let m : (E b →L[ℝ] E b →L[ℝ] ℝ) ≃L[ℝ] (F →L[ℝ] F →L[ℝ] ℝ) := e.arrowCongr (e.arrowCongr (ContinuousLinearEquiv.refl ℝ ℝ )) have A (v : E b) : g.inner b v v = ((fun w ↦ m (g.inner b) w w) ∘ e) v := by simp [m] simp only [A] fun_prop /-- If a Riemannian bundle structure is defined using `g.toRiemannianMetric` where `g` is a `ContinuousRiemannianMetric`, then we make sure typeclass inference can infer automatically that the bundle is a continuous Riemannian bundle. -/ instance (g : ContinuousRiemannianMetric F E) : letI : RiemannianBundle E := ⟨g.toRiemannianMetric⟩; IsContinuousRiemannianBundle F E := by letI : RiemannianBundle E := ⟨g.toRiemannianMetric⟩ exact ⟨⟨g.inner, g.continuous, fun b v w ↦ rfl⟩⟩ end Construction end Bundle
.lake/packages/mathlib/Mathlib/Topology/VectorBundle/Basic.lean
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps import Mathlib.Topology.FiberBundle.Basic /-! # Vector bundles In this file we define (topological) vector bundles. Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let `E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a topological vector space over `R`. To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the following properties: * The bundle trivializations in the trivialization atlas should be continuous linear equivs in the fibers; * For any two trivializations `e`, `e'` in the atlas the transition function considered as a map from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator norm topology on `F →L[R] F`. If these conditions are satisfied, we register the typeclass `VectorBundle R F E`. We define constructions on vector bundles like pullbacks and direct sums in other files. ## Main Definitions * `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base set. * `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the (continuous) linear fiberwise equivalences a trivialization induces. * They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt` and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined everywhere, since they are extended using the zero function. * `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only makes sense on the intersection of their base sets, but is extended outside it using the identity. * Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous (semi)linear map between the chosen fibers of those bundles. ## Implementation notes The implementation choices in the vector bundle definition are discussed in the "Implementation notes" section of `Mathlib/Topology/FiberBundle/Basic.lean`. ## Tags Vector bundle -/ noncomputable section open Bundle Set Topology variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*) section TopologicalVectorSpace variable {F E} variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B] /-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Pretrivialization variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 := Pretrivialization.IsLinear.linear b hb variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A fiberwise linear inverse to `e`. -/ @[simps!] protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by refine IsLinearMap.mk' (e.symm b) ?_ by_cases hb : b ∈ e.baseSet · exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦ congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear · rw [e.coe_symm_of_notMem hb] exact (0 : F →ₗ[R] E b).isLinear /-- A pretrivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ @[simps -fullyApplied] def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F where toFun y := (e ⟨b, y⟩).2 invFun := e.symm b left_inv := e.symm_apply_apply_mk hb right_inv v := by simp_rw [e.apply_mk_symm hb v] map_add' v w := (e.linear R hb).map_add v w map_smul' c v := (e.linear R hb).map_smul c v open Classical in /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0 variable {R} open Classical in theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [Pretrivialization.linearMapAt] split_ifs <;> rfl theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] open Classical in theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb theorem linearMapAt_def_of_notMem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb @[deprecated (since := "2025-05-23")] alias linearMapAt_def_of_not_mem := linearMapAt_def_of_notMem theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).left_inv y theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).right_inv y end Pretrivialization variable [TopologicalSpace (TotalSpace F E)] /-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Trivialization variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 := Trivialization.IsLinear.linear b hb instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R := { (‹_› : e.IsLinear R) with } variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A trivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F := e.toPretrivialization.linearEquivAt R b hb variable {R} @[simp] theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 := rfl @[simp] theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v := rfl variable (R) in /-- A fiberwise linear inverse to `e`. -/ protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := e.toPretrivialization.symmₗ R b theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.symmₗ R b) = e.symm b := rfl variable (R) in /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := e.toPretrivialization.linearMapAt R b open Classical in theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := e.toPretrivialization.coe_linearMapAt b theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] open Classical in theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb theorem linearMapAt_def_of_notMem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb @[deprecated (since := "2025-05-23")] alias linearMapAt_def_of_not_mem := linearMapAt_def_of_notMem theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := e.toPretrivialization.symmₗ_linearMapAt hb y theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := e.toPretrivialization.linearMapAt_symmₗ hb y variable (R) in open Classical in /-- A coordinate change function between two trivializations, as a continuous linear equivalence. Defined to be the identity when `b` does not lie in the base set of both trivializations. -/ def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) : F ≃L[R] F := { toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet then (e.linearEquivAt R b (hb.1 :)).symm.trans (e'.linearEquivAt R b hb.2) else LinearEquiv.refl R F continuous_toFun := by by_cases hb : b ∈ e.baseSet ∩ e'.baseSet · rw [dif_pos hb] refine (e'.continuousOn.comp_continuous ?_ ?_).snd · exact e.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y => mk_mem_prod hb.1 (mem_univ y) · exact fun y => e'.mem_source.mpr hb.2 · rw [dif_neg hb] exact continuous_id continuous_invFun := by by_cases hb : b ∈ e.baseSet ∩ e'.baseSet · rw [dif_pos hb] refine (e.continuousOn.comp_continuous ?_ ?_).snd · exact e'.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y => mk_mem_prod hb.2 (mem_univ y) exact fun y => e.mem_source.mpr hb.1 · rw [dif_neg hb] exact continuous_id } theorem coe_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : ⇑(coordChangeL R e e' b) = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) := congr_arg (fun f : F ≃ₗ[R] F ↦ ⇑f) (dif_pos hb) theorem coe_coordChangeL' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : (coordChangeL R e e' b).toLinearEquiv = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) := LinearEquiv.coe_injective (coe_coordChangeL _ _ hb) theorem symm_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e'.baseSet ∩ e.baseSet) : (e.coordChangeL R e' b).symm = e'.coordChangeL R e b := by apply ContinuousLinearEquiv.toLinearEquiv_injective rw [coe_coordChangeL' e' e hb, (coordChangeL R e e' b).toLinearEquiv_symm, coe_coordChangeL' e e' hb.symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm] theorem coordChangeL_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : coordChangeL R e e' b y = (e' ⟨b, e.symm b y⟩).2 := congr_fun (coe_coordChangeL e e' hb) y theorem mk_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : (b, coordChangeL R e e' b y) = e' ⟨b, e.symm b y⟩ := by ext · rw [e.mk_symm hb.1 y, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1] exact hb.2 · exact e.coordChangeL_apply e' hb y theorem apply_symm_apply_eq_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : e' (e.toOpenPartialHomeomorph.symm (b, v)) = (b, e.coordChangeL R e' b v) := by rw [e.mk_coordChangeL e' hb, e.mk_symm hb.1] /-- A version of `Trivialization.coordChangeL_apply` that fully unfolds `coordChange`. The right-hand side is ugly, but has good definitional properties for specifically defined trivializations. -/ theorem coordChangeL_apply' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : coordChangeL R e e' b y = (e' (e.toOpenPartialHomeomorph.symm (b, y))).2 := by rw [e.coordChangeL_apply e' hb, e.mk_symm hb.1] theorem coordChangeL_symm_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : ⇑(coordChangeL R e e' b).symm = (e'.linearEquivAt R b hb.2).symm.trans (e.linearEquivAt R b hb.1) := congr_arg LinearEquiv.invFun (dif_pos hb) end Trivialization end TopologicalVectorSpace section namespace Bundle /-- The zero section of a vector bundle -/ def zeroSection [∀ x, Zero (E x)] : B → TotalSpace F E := (⟨·, 0⟩) @[simp, mfld_simps] theorem zeroSection_proj [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).proj = x := rfl @[simp, mfld_simps] theorem zeroSection_snd [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).2 = 0 := rfl end Bundle open Bundle variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] [FiberBundle F E] /-- The space `Bundle.TotalSpace F E` (for `E : B → Type*` such that each `E x` is a topological vector space) has a topological vector space structure with fiber `F` (denoted with `VectorBundle R F E`) if around every point there is a fiber bundle trivialization which is linear in the fibers. -/ class VectorBundle : Prop where trivialization_linear' : ∀ (e : Trivialization F (π F E)) [MemTrivializationAtlas e], e.IsLinear R continuousOn_coordChange' : ∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'], ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F) (e.baseSet ∩ e'.baseSet) variable {F E} instance (priority := 100) trivialization_linear [VectorBundle R F E] (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : e.IsLinear R := VectorBundle.trivialization_linear' e theorem continuousOn_coordChange [VectorBundle R F E] (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'] : ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F) (e.baseSet ∩ e'.baseSet) := VectorBundle.continuousOn_coordChange' e e' namespace Trivialization /-- Forward map of `Trivialization.continuousLinearEquivAt` (only propositionally equal), defined everywhere (`0` outside domain). -/ @[simps -fullyApplied apply] def continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →L[R] F := { e.linearMapAt R b with toFun := e.linearMapAt R b -- given explicitly to help `simps` cont := by rw [e.coe_linearMapAt b] classical refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_isInducing F E b).continuous fun x => e.mem_source.mpr hb).snd } /-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/ @[simps -fullyApplied apply] def symmL (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →L[R] E b := { e.symmₗ R b with toFun := e.symm b -- given explicitly to help `simps` cont := by by_cases hb : b ∈ e.baseSet · rw [(FiberBundle.totalSpaceMk_isInducing F E b).continuous_iff] exact e.continuousOn_symm.comp_continuous (.prodMk_right _) fun x ↦ mk_mem_prod hb (mem_univ x) · refine continuous_zero.congr fun x => (e.symm_apply_of_notMem hb x).symm } variable {R} theorem symmL_continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmL R b (e.continuousLinearMapAt R b y) = y := e.symmₗ_linearMapAt hb y theorem continuousLinearMapAt_symmL (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.continuousLinearMapAt R b (e.symmL R b y) = y := e.linearMapAt_symmₗ hb y variable (R) in /-- In a vector bundle, a trivialization in the fiber (which is a priori only linear) is in fact a continuous linear equiv between the fibers and the model fiber. -/ @[simps -fullyApplied apply symm_apply] def continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃L[R] F := { e.toPretrivialization.linearEquivAt R b hb with toFun := fun y => (e ⟨b, y⟩).2 -- given explicitly to help `simps` invFun := e.symm b -- given explicitly to help `simps` continuous_toFun := (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_isInducing F E b).continuous fun _ => e.mem_source.mpr hb).snd continuous_invFun := (e.symmL R b).continuous } theorem coe_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : (e.continuousLinearEquivAt R b hb : E b → F) = e.continuousLinearMapAt R b := (e.coe_linearMapAt_of_mem hb).symm theorem symm_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ((e.continuousLinearEquivAt R b hb).symm : F → E b) = e.symmL R b := rfl @[simp] theorem continuousLinearEquivAt_apply' (e : Trivialization F (π F E)) [e.IsLinear R] (x : TotalSpace F E) (hx : x ∈ e.source) : e.continuousLinearEquivAt R x.proj (e.mem_source.1 hx) x.2 = (e x).2 := rfl variable (R) theorem apply_eq_prod_continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (z : E b) : e ⟨b, z⟩ = (b, e.continuousLinearEquivAt R b hb z) := by ext · refine e.coe_fst ?_ rw [e.source_eq] exact hb · simp only [continuousLinearEquivAt_apply] protected theorem zeroSection (e : Trivialization F (π F E)) [e.IsLinear R] {x : B} (hx : x ∈ e.baseSet) : e (zeroSection F E x) = (x, 0) := by simp_rw [zeroSection, e.apply_eq_prod_continuousLinearEquivAt R x hx 0, map_zero] variable {R} theorem symm_apply_eq_mk_continuousLinearEquivAt_symm (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (z : F) : e.toOpenPartialHomeomorph.symm ⟨b, z⟩ = ⟨b, (e.continuousLinearEquivAt R b hb).symm z⟩ := by have h : (b, z) ∈ e.target := by rw [e.target_eq] exact ⟨hb, mem_univ _⟩ apply e.injOn (e.map_target h) · simpa only [e.source_eq, mem_preimage] · simp_rw [e.right_inv h, coe_coe, e.apply_eq_prod_continuousLinearEquivAt R b hb, ContinuousLinearEquiv.apply_symm_apply] theorem comp_continuousLinearEquivAt_eq_coord_change (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : (e.continuousLinearEquivAt R b hb.1).symm.trans (e'.continuousLinearEquivAt R b hb.2) = coordChangeL R e e' b := by ext v rw [coordChangeL_apply e e' hb] rfl end Trivialization /-! ### Constructing vector bundles -/ variable (B F) /-- Analogous construction of `FiberBundleCore` for vector bundles. This construction gives a way to construct vector bundles from a structure registering how trivialization changes act on fibers. -/ structure VectorBundleCore (ι : Type*) where baseSet : ι → Set B isOpen_baseSet : ∀ i, IsOpen (baseSet i) indexAt : B → ι mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x) coordChange : ι → ι → B → F →L[R] F coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v continuousOn_coordChange : ∀ i j, ContinuousOn (coordChange i j) (baseSet i ∩ baseSet j) coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v, (coordChange j k x) (coordChange i j x v) = coordChange i k x v /-- The trivial vector bundle core, in which all the changes of coordinates are the identity. -/ def trivialVectorBundleCore (ι : Type*) [Inhabited ι] : VectorBundleCore R B F ι where baseSet _ := univ isOpen_baseSet _ := isOpen_univ indexAt := default mem_baseSet_at x := mem_univ x coordChange _ _ _ := ContinuousLinearMap.id R F coordChange_self _ _ _ _ := rfl coordChange_comp _ _ _ _ _ _ := rfl continuousOn_coordChange _ _ := continuousOn_const instance (ι : Type*) [Inhabited ι] : Inhabited (VectorBundleCore R B F ι) := ⟨trivialVectorBundleCore R B F ι⟩ namespace VectorBundleCore variable {R B F} {ι : Type*} variable (Z : VectorBundleCore R B F ι) /-- Natural identification to a `FiberBundleCore`. -/ @[simps (attr := mfld_simps) -fullyApplied] def toFiberBundleCore : FiberBundleCore ι B F := { Z with coordChange := fun i j b => Z.coordChange i j b continuousOn_coordChange := fun i j => isBoundedBilinearMap_apply.continuous.comp_continuousOn ((Z.continuousOn_coordChange i j).prodMap continuousOn_id) } -- TODO: restore coercion? -- instance toFiberBundleCoreCoe : Coe (VectorBundleCore R B F ι) (FiberBundleCore ι B F) := -- ⟨toFiberBundleCore⟩ theorem coordChange_linear_comp (i j k : ι) : ∀ x ∈ Z.baseSet i ∩ Z.baseSet j ∩ Z.baseSet k, (Z.coordChange j k x).comp (Z.coordChange i j x) = Z.coordChange i k x := fun x hx => by ext v exact Z.coordChange_comp i j k x hx v /-- The index set of a vector bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments] def Index := ι /-- The base space of a vector bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments, reducible] def Base := B /-- The fiber of a vector bundle core, as a convenience function for dot notation and typeclass inference -/ @[nolint unusedArguments] def Fiber : B → Type _ := Z.toFiberBundleCore.Fiber instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) := Z.toFiberBundleCore.topologicalSpaceFiber x instance addCommGroupFiber (x : B) : AddCommGroup (Z.Fiber x) := inferInstanceAs (AddCommGroup F) instance moduleFiber (x : B) : Module R (Z.Fiber x) := inferInstanceAs (Module R F) /-- The projection from the total space of a fiber bundle core, on its base. -/ @[reducible, simp, mfld_simps] protected def proj : TotalSpace F Z.Fiber → B := TotalSpace.proj /-- The total space of the vector bundle, as a convenience function for dot notation. It is by definition equal to `Bundle.TotalSpace F Z.Fiber`. -/ @[nolint unusedArguments, reducible] protected def TotalSpace := Bundle.TotalSpace F Z.Fiber /-- Local homeomorphism version of the trivialization change. -/ def trivChange (i j : ι) : OpenPartialHomeomorph (B × F) (B × F) := Z.toFiberBundleCore.trivChange i j @[simp, mfld_simps] theorem mem_trivChange_source (i j : ι) (p : B × F) : p ∈ (Z.trivChange i j).source ↔ p.1 ∈ Z.baseSet i ∩ Z.baseSet j := Z.toFiberBundleCore.mem_trivChange_source i j p /-- Topological structure on the total space of a vector bundle created from core, designed so that all the local trivialization are continuous. -/ instance toTopologicalSpace : TopologicalSpace Z.TotalSpace := Z.toFiberBundleCore.toTopologicalSpace variable (b : B) (a : F) @[simp, mfld_simps] theorem coe_coordChange (i j : ι) : Z.toFiberBundleCore.coordChange i j b = Z.coordChange i j b := rfl /-- One of the standard local trivializations of a vector bundle constructed from core, taken by considering this in particular as a fiber bundle constructed from core. -/ def localTriv (i : ι) : Trivialization F (π F Z.Fiber) := Z.toFiberBundleCore.localTriv i @[simp, mfld_simps] theorem localTriv_apply {i : ι} (p : Z.TotalSpace) : (Z.localTriv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ := rfl /-- The standard local trivializations of a vector bundle constructed from core are linear. -/ instance localTriv.isLinear (i : ι) : (Z.localTriv i).IsLinear R where linear x _ := { map_add := fun _ _ => by simp only [map_add, localTriv_apply, mfld_simps] map_smul := fun _ _ => by simp only [map_smul, localTriv_apply, mfld_simps] } variable (i j : ι) @[simp, mfld_simps] theorem mem_localTriv_source (p : Z.TotalSpace) : p ∈ (Z.localTriv i).source ↔ p.1 ∈ Z.baseSet i := Iff.rfl @[simp, mfld_simps] theorem baseSet_at : Z.baseSet i = (Z.localTriv i).baseSet := rfl @[simp, mfld_simps] theorem mem_localTriv_target (p : B × F) : p ∈ (Z.localTriv i).target ↔ p.1 ∈ (Z.localTriv i).baseSet := Z.toFiberBundleCore.mem_localTriv_target i p @[simp, mfld_simps] theorem localTriv_symm_fst (p : B × F) : (Z.localTriv i).toOpenPartialHomeomorph.symm p = ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ := rfl @[simp, mfld_simps] theorem localTriv_symm_apply {b : B} (hb : b ∈ (Z.localTriv i).baseSet) (v : F) : (Z.localTriv i).symm b v = Z.coordChange i (Z.indexAt b) b v := by apply (Z.localTriv i).symm_apply hb v @[simp, mfld_simps] theorem localTriv_coordChange_eq {b : B} (hb : b ∈ (Z.localTriv i).baseSet ∧ b ∈ (Z.localTriv j).baseSet) (v : F) : (Z.localTriv i).coordChangeL R (Z.localTriv j) b v = Z.coordChange i j b v := by rw [Trivialization.coordChangeL_apply', localTriv_symm_fst, localTriv_apply, coordChange_comp] exacts [⟨⟨hb.1, Z.mem_baseSet_at b⟩, hb.2⟩, hb] /-- Preferred local trivialization of a vector bundle constructed from core, at a given point, as a bundle trivialization -/ def localTrivAt (b : B) : Trivialization F (π F Z.Fiber) := Z.localTriv (Z.indexAt b) @[simp, mfld_simps] theorem localTrivAt_def : Z.localTriv (Z.indexAt b) = Z.localTrivAt b := rfl @[simp, mfld_simps] theorem mem_source_at : (⟨b, a⟩ : Z.TotalSpace) ∈ (Z.localTrivAt b).source := by rw [localTrivAt, mem_localTriv_source] exact Z.mem_baseSet_at b @[simp, mfld_simps] theorem localTrivAt_apply (p : Z.TotalSpace) : Z.localTrivAt p.1 p = ⟨p.1, p.2⟩ := Z.toFiberBundleCore.localTrivAt_apply p @[simp, mfld_simps] theorem localTrivAt_apply_mk (b : B) (a : F) : Z.localTrivAt b ⟨b, a⟩ = ⟨b, a⟩ := Z.localTrivAt_apply _ @[simp, mfld_simps] theorem mem_localTrivAt_baseSet : b ∈ (Z.localTrivAt b).baseSet := Z.toFiberBundleCore.mem_localTrivAt_baseSet b instance fiberBundle : FiberBundle F Z.Fiber := Z.toFiberBundleCore.fiberBundle protected lemma trivializationAt : trivializationAt F Z.Fiber b = Z.localTrivAt b := rfl instance vectorBundle : VectorBundle R F Z.Fiber where trivialization_linear' := by rintro _ ⟨i, rfl⟩ apply localTriv.isLinear continuousOn_coordChange' := by rintro _ _ ⟨i, rfl⟩ ⟨i', rfl⟩ refine (Z.continuousOn_coordChange i i').congr fun b hb => ?_ ext v exact Z.localTriv_coordChange_eq i i' hb v /-- The projection on the base of a vector bundle created from core is continuous -/ @[continuity] theorem continuous_proj : Continuous Z.proj := Z.toFiberBundleCore.continuous_proj /-- The projection on the base of a vector bundle created from core is an open map -/ theorem isOpenMap_proj : IsOpenMap Z.proj := Z.toFiberBundleCore.isOpenMap_proj variable {i j} @[simp, mfld_simps] theorem localTriv_continuousLinearMapAt {b : B} (hb : b ∈ (Z.localTriv i).baseSet) : (Z.localTriv i).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) i b := by ext1 v rw [(Z.localTriv i).continuousLinearMapAt_apply R, (Z.localTriv i).coe_linearMapAt_of_mem] exacts [rfl, hb] @[simp, mfld_simps] theorem trivializationAt_continuousLinearMapAt {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) : (trivializationAt F Z.Fiber b₀).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) (Z.indexAt b₀) b := Z.localTriv_continuousLinearMapAt hb @[simp, mfld_simps] theorem localTriv_symmL {b : B} (hb : b ∈ (Z.localTriv i).baseSet) : (Z.localTriv i).symmL R b = Z.coordChange i (Z.indexAt b) b := by ext1 v rw [(Z.localTriv i).symmL_apply R, (Z.localTriv i).symm_apply] exacts [rfl, hb] @[simp, mfld_simps] theorem trivializationAt_symmL {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) : (trivializationAt F Z.Fiber b₀).symmL R b = Z.coordChange (Z.indexAt b₀) (Z.indexAt b) b := Z.localTriv_symmL hb @[simp, mfld_simps] theorem trivializationAt_coordChange_eq {b₀ b₁ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet ∩ (trivializationAt F Z.Fiber b₁).baseSet) (v : F) : (trivializationAt F Z.Fiber b₀).coordChangeL R (trivializationAt F Z.Fiber b₁) b v = Z.coordChange (Z.indexAt b₀) (Z.indexAt b₁) b v := Z.localTriv_coordChange_eq _ _ hb v end VectorBundleCore end /-! ### Vector prebundle -/ section variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [∀ x, TopologicalSpace (E x)] open TopologicalSpace open VectorBundle /-- This structure permits to define a vector bundle when trivializations are given as local equivalences but there is not yet a topology on the total space or the fibers. The total space is hence given a topology in such a way that there is a fiber bundle structure for which the partial equivalences are also open partial homeomorphisms and hence vector bundle trivializations. The topology on the fibers is induced from the one on the total space. The field `exists_coordChange` is stated as an existential statement (instead of 3 separate fields), since it depends on propositional information (namely `e e' ∈ pretrivializationAtlas`). This makes it inconvenient to explicitly define a `coordChange` function when constructing a `VectorPrebundle`. -/ structure VectorPrebundle where pretrivializationAtlas : Set (Pretrivialization F (π F E)) pretrivialization_linear' : ∀ e, e ∈ pretrivializationAtlas → e.IsLinear R pretrivializationAt : B → Pretrivialization F (π F E) mem_base_pretrivializationAt : ∀ x : B, x ∈ (pretrivializationAt x).baseSet pretrivialization_mem_atlas : ∀ x : B, pretrivializationAt x ∈ pretrivializationAtlas exists_coordChange : ∀ᵉ (e ∈ pretrivializationAtlas) (e' ∈ pretrivializationAtlas), ∃ f : B → F →L[R] F, ContinuousOn f (e.baseSet ∩ e'.baseSet) ∧ ∀ᵉ (b ∈ e.baseSet ∩ e'.baseSet) (v : F), f b v = (e' ⟨b, e.symm b v⟩).2 totalSpaceMk_isInducing : ∀ b : B, IsInducing (pretrivializationAt b ∘ .mk b) namespace VectorPrebundle variable {R E F} /-- A randomly chosen coordinate change on a `VectorPrebundle`, given by the field `exists_coordChange`. -/ def coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) (b : B) : F →L[R] F := Classical.choose (a.exists_coordChange e he e' he') b theorem continuousOn_coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) : ContinuousOn (a.coordChange he he') (e.baseSet ∩ e'.baseSet) := (Classical.choose_spec (a.exists_coordChange e he e' he')).1 theorem coordChange_apply (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : a.coordChange he he' b v = (e' ⟨b, e.symm b v⟩).2 := (Classical.choose_spec (a.exists_coordChange e he e' he')).2 b hb v theorem mk_coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : (b, a.coordChange he he' b v) = e' ⟨b, e.symm b v⟩ := by ext · rw [e.mk_symm hb.1 v, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1] exact hb.2 · exact a.coordChange_apply he he' hb v /-- Natural identification of `VectorPrebundle` as a `FiberPrebundle`. -/ def toFiberPrebundle (a : VectorPrebundle R F E) : FiberPrebundle F E := { a with continuous_trivChange := fun e he e' he' ↦ by have : ContinuousOn (fun x : B × F ↦ a.coordChange he' he x.1 x.2) ((e'.baseSet ∩ e.baseSet) ×ˢ univ) := isBoundedBilinearMap_apply.continuous.comp_continuousOn ((a.continuousOn_coordChange he' he).prodMap continuousOn_id) rw [e.target_inter_preimage_symm_source_eq e', inter_comm] refine (continuousOn_fst.prodMk this).congr ?_ rintro ⟨b, f⟩ ⟨hb, -⟩ dsimp only [Function.comp_def, Prod.map] rw [a.mk_coordChange _ _ hb, e'.mk_symm hb.1] } /-- Topology on the total space that will make the prebundle into a bundle. -/ def totalSpaceTopology (a : VectorPrebundle R F E) : TopologicalSpace (TotalSpace F E) := a.toFiberPrebundle.totalSpaceTopology /-- Promotion from a `Pretrivialization` in the `pretrivializationAtlas` of a `VectorPrebundle` to a `Trivialization`. -/ def trivializationOfMemPretrivializationAtlas (a : VectorPrebundle R F E) {e : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) : @Trivialization B F _ _ _ a.totalSpaceTopology (π F E) := a.toFiberPrebundle.trivializationOfMemPretrivializationAtlas he theorem linear_trivializationOfMemPretrivializationAtlas (a : VectorPrebundle R F E) {e : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) : letI := a.totalSpaceTopology Trivialization.IsLinear R (trivializationOfMemPretrivializationAtlas a he) := letI := a.totalSpaceTopology { linear := (a.pretrivialization_linear' e he).linear } variable (a : VectorPrebundle R F E) theorem mem_trivialization_at_source (b : B) (x : E b) : ⟨b, x⟩ ∈ (a.pretrivializationAt b).source := a.toFiberPrebundle.mem_pretrivializationAt_source b x @[simp] theorem totalSpaceMk_preimage_source (b : B) : .mk b ⁻¹' (a.pretrivializationAt b).source = univ := a.toFiberPrebundle.totalSpaceMk_preimage_source b @[continuity] theorem continuous_totalSpaceMk (b : B) : Continuous[_, a.totalSpaceTopology] (.mk b) := a.toFiberPrebundle.continuous_totalSpaceMk b /-- Make a `FiberBundle` from a `VectorPrebundle`; auxiliary construction for `VectorPrebundle.toVectorBundle`. -/ def toFiberBundle : @FiberBundle B F _ _ _ a.totalSpaceTopology _ := a.toFiberPrebundle.toFiberBundle /-- Make a `VectorBundle` from a `VectorPrebundle`. Concretely this means that, given a `VectorPrebundle` structure for a sigma-type `E` -- which consists of a number of "pretrivializations" identifying parts of `E` with product spaces `U × F` -- one establishes that for the topology constructed on the sigma-type using `VectorPrebundle.totalSpaceTopology`, these "pretrivializations" are actually "trivializations" (i.e., homeomorphisms with respect to the constructed topology). -/ theorem toVectorBundle : @VectorBundle R _ F E _ _ _ _ _ _ a.totalSpaceTopology _ a.toFiberBundle := letI := a.totalSpaceTopology; letI := a.toFiberBundle { trivialization_linear' := by rintro _ ⟨e, he, rfl⟩ apply linear_trivializationOfMemPretrivializationAtlas continuousOn_coordChange' := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine (a.continuousOn_coordChange he he').congr fun b hb ↦ ?_ ext v haveI h₁ := a.linear_trivializationOfMemPretrivializationAtlas he haveI h₂ := a.linear_trivializationOfMemPretrivializationAtlas he' rw [trivializationOfMemPretrivializationAtlas] at h₁ h₂ rw [a.coordChange_apply he he' hb v, ContinuousLinearEquiv.coe_coe, Trivialization.coordChangeL_apply] exacts [rfl, hb] } end VectorPrebundle namespace ContinuousLinearMap variable {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁] [NontriviallyNormedField 𝕜₂] variable {σ : 𝕜₁ →+* 𝕜₂} variable {B' : Type*} [TopologicalSpace B'] variable [NormedSpace 𝕜₁ F] [∀ x, Module 𝕜₁ (E x)] [TopologicalSpace (TotalSpace F E)] variable {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜₂ F'] {E' : B' → Type*} [∀ x, AddCommMonoid (E' x)] [∀ x, Module 𝕜₂ (E' x)] [TopologicalSpace (TotalSpace F' E')] variable [FiberBundle F E] [VectorBundle 𝕜₁ F E] variable [∀ x, TopologicalSpace (E' x)] [FiberBundle F' E'] [VectorBundle 𝕜₂ F' E'] variable (F' E') /-- When `ϕ` is a continuous (semi)linear map between the fibers `E x` and `E' y` of two vector bundles `E` and `E'`, `ContinuousLinearMap.inCoordinates F E F' E' x₀ x y₀ y ϕ` is a coordinate change of this continuous linear map w.r.t. the chart around `x₀` and the chart around `y₀`. It is defined by composing `ϕ` with appropriate coordinate changes given by the vector bundles `E` and `E'`. We use the operations `Trivialization.continuousLinearMapAt` and `Trivialization.symmL` in the definition, instead of `Trivialization.continuousLinearEquivAt`, so that `ContinuousLinearMap.inCoordinates` is defined everywhere (but see `ContinuousLinearMap.inCoordinates_eq`). This is the (second component of the) underlying function of a trivialization of the hom-bundle (see `hom_trivializationAt_apply`). However, note that `ContinuousLinearMap.inCoordinates` is defined even when `x` and `y` live in different base sets. Therefore, it is also convenient when working with the hom-bundle between pulled back bundles. -/ def inCoordinates (x₀ x : B) (y₀ y : B') (ϕ : E x →SL[σ] E' y) : F →SL[σ] F' := ((trivializationAt F' E' y₀).continuousLinearMapAt 𝕜₂ y).comp <| ϕ.comp <| (trivializationAt F E x₀).symmL 𝕜₁ x variable {E E' F F'} /-- Rewrite `ContinuousLinearMap.inCoordinates` using continuous linear equivalences. -/ theorem inCoordinates_eq {x₀ x : B} {y₀ y : B'} {ϕ : E x →SL[σ] E' y} (hx : x ∈ (trivializationAt F E x₀).baseSet) (hy : y ∈ (trivializationAt F' E' y₀).baseSet) : inCoordinates F E F' E' x₀ x y₀ y ϕ = ((trivializationAt F' E' y₀).continuousLinearEquivAt 𝕜₂ y hy : E' y →L[𝕜₂] F').comp (ϕ.comp <| (((trivializationAt F E x₀).continuousLinearEquivAt 𝕜₁ x hx).symm : F →L[𝕜₁] E x)) := by ext simp_rw [inCoordinates, ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, Trivialization.coe_continuousLinearEquivAt_eq, Trivialization.symm_continuousLinearEquivAt_eq] /-- Rewrite `ContinuousLinearMap.inCoordinates` in a `VectorBundleCore`. -/ protected theorem _root_.VectorBundleCore.inCoordinates_eq {ι ι'} (Z : VectorBundleCore 𝕜₁ B F ι) (Z' : VectorBundleCore 𝕜₂ B' F' ι') {x₀ x : B} {y₀ y : B'} (ϕ : F →SL[σ] F') (hx : x ∈ Z.baseSet (Z.indexAt x₀)) (hy : y ∈ Z'.baseSet (Z'.indexAt y₀)) : inCoordinates F Z.Fiber F' Z'.Fiber x₀ x y₀ y ϕ = (Z'.coordChange (Z'.indexAt y) (Z'.indexAt y₀) y).comp (ϕ.comp <| Z.coordChange (Z.indexAt x₀) (Z.indexAt x) x) := by simp_rw [inCoordinates, Z'.trivializationAt_continuousLinearMapAt hy, Z.trivializationAt_symmL hx] end ContinuousLinearMap end
.lake/packages/mathlib/Mathlib/Topology/VectorBundle/Constructions.lean
import Mathlib.Topology.FiberBundle.Constructions import Mathlib.Topology.VectorBundle.Basic import Mathlib.Analysis.Normed.Operator.Prod /-! # Standard constructions on vector bundles This file contains several standard constructions on vector bundles: * `Bundle.Trivial.vectorBundle 𝕜 B F`: the trivial vector bundle with scalar field `𝕜` and model fiber `F` over the base `B` * `VectorBundle.prod`: for vector bundles `E₁` and `E₂` with scalar field `𝕜` over a common base, a vector bundle structure on their direct sum `E₁ ×ᵇ E₂` (the notation stands for `fun x ↦ E₁ x × E₂ x`). * `VectorBundle.pullback`: for a vector bundle `E` over `B`, a vector bundle structure on its pullback `f *ᵖ E` by a map `f : B' → B` (the notation is a type synonym for `E ∘ f`). ## Tags Vector bundle, direct sum, pullback -/ noncomputable section open Bundle Set FiberBundle /-! ### The trivial vector bundle -/ namespace Bundle.Trivial variable (𝕜 : Type*) (B : Type*) (F : Type*) [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace B] instance trivialization.isLinear : (trivialization B F).IsLinear 𝕜 where linear _ _ := ⟨fun _ _ => rfl, fun _ _ => rfl⟩ variable {𝕜} in theorem trivialization.coordChangeL (b : B) : (trivialization B F).coordChangeL 𝕜 (trivialization B F) b = ContinuousLinearEquiv.refl 𝕜 F := by ext v rw [Trivialization.coordChangeL_apply'] exacts [rfl, ⟨mem_univ _, mem_univ _⟩] instance vectorBundle : VectorBundle 𝕜 F (Bundle.Trivial B F) where trivialization_linear' e he := by rw [eq_trivialization B F e] infer_instance continuousOn_coordChange' e e' he he' := by obtain rfl := eq_trivialization B F e obtain rfl := eq_trivialization B F e' simp only [trivialization.coordChangeL] exact continuous_const.continuousOn @[simp] lemma linearMapAt_trivialization (x : B) : (trivialization B F).linearMapAt 𝕜 x = LinearMap.id := by ext v rw [Trivialization.coe_linearMapAt_of_mem _ (by simp)] rfl @[simp] lemma continuousLinearMapAt_trivialization (x : B) : (trivialization B F).continuousLinearMapAt 𝕜 x = ContinuousLinearMap.id 𝕜 F := by ext; simp @[simp] lemma symmₗ_trivialization (x : B) : (trivialization B F).symmₗ 𝕜 x = LinearMap.id := by ext; simp [Trivialization.coe_symmₗ, trivialization_symm_apply B F] @[simp] lemma symmL_trivialization (x : B) : (trivialization B F).symmL 𝕜 x = ContinuousLinearMap.id 𝕜 F := by ext; simp [trivialization_symm_apply B F] @[simp] lemma continuousLinearEquivAt_trivialization (x : B) : (trivialization B F).continuousLinearEquivAt 𝕜 x (mem_univ _) = ContinuousLinearEquiv.refl 𝕜 F := by ext; simp end Bundle.Trivial /-! ### Direct sum of two vector bundles -/ section variable (𝕜 : Type*) {B : Type*} [NontriviallyNormedField 𝕜] [TopologicalSpace B] (F₁ : Type*) [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] (E₁ : B → Type*) [TopologicalSpace (TotalSpace F₁ E₁)] (F₂ : Type*) [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] (E₂ : B → Type*) [TopologicalSpace (TotalSpace F₂ E₂)] namespace Trivialization variable {F₁ E₁ F₂ E₂} variable [∀ x, AddCommMonoid (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [∀ x, AddCommMonoid (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] (e₁ e₁' : Trivialization F₁ (π F₁ E₁)) (e₂ e₂' : Trivialization F₂ (π F₂ E₂)) instance prod.isLinear [e₁.IsLinear 𝕜] [e₂.IsLinear 𝕜] : (e₁.prod e₂).IsLinear 𝕜 where linear := fun _ ⟨h₁, h₂⟩ => (((e₁.linear 𝕜 h₁).mk' _).prodMap ((e₂.linear 𝕜 h₂).mk' _)).isLinear @[simp] theorem coordChangeL_prod [e₁.IsLinear 𝕜] [e₁'.IsLinear 𝕜] [e₂.IsLinear 𝕜] [e₂'.IsLinear 𝕜] ⦃b⦄ (hb : (b ∈ e₁.baseSet ∧ b ∈ e₂.baseSet) ∧ b ∈ e₁'.baseSet ∧ b ∈ e₂'.baseSet) : ((e₁.prod e₂).coordChangeL 𝕜 (e₁'.prod e₂') b : F₁ × F₂ →L[𝕜] F₁ × F₂) = (e₁.coordChangeL 𝕜 e₁' b : F₁ →L[𝕜] F₁).prodMap (e₂.coordChangeL 𝕜 e₂' b) := by rw [ContinuousLinearMap.ext_iff, ContinuousLinearMap.coe_prodMap'] rintro ⟨v₁, v₂⟩ change (e₁.prod e₂).coordChangeL 𝕜 (e₁'.prod e₂') b (v₁, v₂) = (e₁.coordChangeL 𝕜 e₁' b v₁, e₂.coordChangeL 𝕜 e₂' b v₂) rw [e₁.coordChangeL_apply e₁', e₂.coordChangeL_apply e₂', (e₁.prod e₂).coordChangeL_apply'] exacts [rfl, hb, ⟨hb.1.2, hb.2.2⟩, ⟨hb.1.1, hb.2.1⟩] variable {e₁ e₂} [∀ x : B, TopologicalSpace (E₁ x)] [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₁ E₁] [FiberBundle F₂ E₂] theorem prod_apply' [e₁.IsLinear 𝕜] [e₂.IsLinear 𝕜] {x : B} (hx₁ : x ∈ e₁.baseSet) (hx₂ : x ∈ e₂.baseSet) (v₁ : E₁ x) (v₂ : E₂ x) : prod e₁ e₂ ⟨x, (v₁, v₂)⟩ = ⟨x, e₁.continuousLinearEquivAt 𝕜 x hx₁ v₁, e₂.continuousLinearEquivAt 𝕜 x hx₂ v₂⟩ := rfl end Trivialization open Trivialization variable [∀ x, AddCommMonoid (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [∀ x, AddCommMonoid (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [∀ x : B, TopologicalSpace (E₁ x)] [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₁ E₁] [FiberBundle F₂ E₂] /-- The product of two vector bundles is a vector bundle. -/ instance VectorBundle.prod [VectorBundle 𝕜 F₁ E₁] [VectorBundle 𝕜 F₂ E₂] : VectorBundle 𝕜 (F₁ × F₂) (E₁ ×ᵇ E₂) where trivialization_linear' := by rintro _ ⟨e₁, e₂, he₁, he₂, rfl⟩ infer_instance continuousOn_coordChange' := by rintro _ _ ⟨e₁, e₂, he₁, he₂, rfl⟩ ⟨e₁', e₂', he₁', he₂', rfl⟩ refine (((continuousOn_coordChange 𝕜 e₁ e₁').mono ?_).prod_mapL 𝕜 ((continuousOn_coordChange 𝕜 e₂ e₂').mono ?_)).congr ?_ <;> dsimp only [prod_baseSet, mfld_simps] · mfld_set_tac · mfld_set_tac · rintro b hb rw [ContinuousLinearMap.ext_iff] rintro ⟨v₁, v₂⟩ change (e₁.prod e₂).coordChangeL 𝕜 (e₁'.prod e₂') b (v₁, v₂) = (e₁.coordChangeL 𝕜 e₁' b v₁, e₂.coordChangeL 𝕜 e₂' b v₂) rw [e₁.coordChangeL_apply e₁', e₂.coordChangeL_apply e₂', (e₁.prod e₂).coordChangeL_apply'] exacts [rfl, hb, ⟨hb.1.2, hb.2.2⟩, ⟨hb.1.1, hb.2.1⟩] variable {𝕜 F₁ E₁ F₂ E₂} @[simp] theorem Trivialization.continuousLinearEquivAt_prod {e₁ : Trivialization F₁ (π F₁ E₁)} {e₂ : Trivialization F₂ (π F₂ E₂)} [e₁.IsLinear 𝕜] [e₂.IsLinear 𝕜] {x : B} (hx : x ∈ (e₁.prod e₂).baseSet) : (e₁.prod e₂).continuousLinearEquivAt 𝕜 x hx = (e₁.continuousLinearEquivAt 𝕜 x hx.1).prodCongr (e₂.continuousLinearEquivAt 𝕜 x hx.2) := by ext v : 2 obtain ⟨v₁, v₂⟩ := v rw [(e₁.prod e₂).continuousLinearEquivAt_apply 𝕜, Trivialization.prod] exact (congr_arg Prod.snd (prod_apply' 𝕜 hx.1 hx.2 v₁ v₂) :) end /-! ### Pullbacks of vector bundles -/ section variable (R 𝕜 : Type*) {B : Type*} (F : Type*) (E : B → Type*) {B' : Type*} (f : B' → B) instance [i : ∀ x : B, AddCommMonoid (E x)] (x : B') : AddCommMonoid ((f *ᵖ E) x) := i _ instance [Semiring R] [∀ x : B, AddCommMonoid (E x)] [i : ∀ x, Module R (E x)] (x : B') : Module R ((f *ᵖ E) x) := i _ variable {E F} [TopologicalSpace B'] [TopologicalSpace (TotalSpace F E)] [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace B] [∀ x, AddCommMonoid (E x)] [∀ x, Module 𝕜 (E x)] {K : Type*} [FunLike K B' B] [ContinuousMapClass K B' B] instance Trivialization.pullback_linear (e : Trivialization F (π F E)) [e.IsLinear 𝕜] (f : K) : (Trivialization.pullback (B' := B') e f).IsLinear 𝕜 where linear _ h := e.linear 𝕜 h instance VectorBundle.pullback [∀ x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle 𝕜 F E] (f : K) : VectorBundle 𝕜 F ((f : B' → B) *ᵖ E) where trivialization_linear' := by rintro _ ⟨e, he, rfl⟩ infer_instance continuousOn_coordChange' := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine ((continuousOn_coordChange 𝕜 e e').comp (map_continuous f).continuousOn fun b hb => hb).congr ?_ rintro b (hb : f b ∈ e.baseSet ∩ e'.baseSet); ext v change ((e.pullback f).coordChangeL 𝕜 (e'.pullback f) b) v = (e.coordChangeL 𝕜 e' (f b)) v rw [e.coordChangeL_apply e' hb, (e.pullback f).coordChangeL_apply' _] exacts [rfl, hb] end
.lake/packages/mathlib/Mathlib/Topology/VectorBundle/Hom.lean
import Mathlib.Topology.VectorBundle.Basic /-! # The vector bundle of continuous (semi)linear maps We define the (topological) vector bundle of continuous (semi)linear maps between two vector bundles over the same base. Given bundles `E₁ E₂ : B → Type*`, normed spaces `F₁` and `F₂`, and a ring-homomorphism `σ` between their respective scalar fields, we define a vector bundle with fiber `E₁ x →SL[σ] E₂ x`. If the `E₁` and `E₂` are vector bundles with model fibers `F₁` and `F₂`, then this will be a vector bundle with fiber `F₁ →SL[σ] F₂`. The topology on the total space is constructed from the trivializations for `E₁` and `E₂` and the norm-topology on the model fiber `F₁ →SL[𝕜] F₂` using the `VectorPrebundle` construction. This is a bit awkward because it introduces a dependence on the normed space structure of the model fibers, rather than just their topological vector space structure; it is not clear whether this is necessary. Similar constructions should be possible (but are yet to be formalized) for tensor products of topological vector bundles, exterior algebras, and so on, where again the topology can be defined using a norm on the fiber model if this helps. -/ noncomputable section open Bundle Set ContinuousLinearMap Topology open scoped Bundle variable {𝕜₁ : Type*} [NontriviallyNormedField 𝕜₁] {𝕜₂ : Type*} [NontriviallyNormedField 𝕜₂] (σ : 𝕜₁ →+* 𝕜₂) variable {B : Type*} variable {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜₁ F₁] (E₁ : B → Type*) [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜₁ (E₁ x)] [TopologicalSpace (TotalSpace F₁ E₁)] variable {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜₂ F₂] (E₂ : B → Type*) [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜₂ (E₂ x)] [TopologicalSpace (TotalSpace F₂ E₂)] /-- A reducible type synonym for the bundle of continuous (semi)linear maps. -/ @[deprecated "Use the plain bundle syntax `fun (b : B) ↦ E₁ b →SL[σ] E₂ b` or `fun (b : B) ↦ E₁ b →L[𝕜] E₂ b` instead" (since := "2025-06-12")] protected abbrev Bundle.ContinuousLinearMap [∀ x, TopologicalSpace (E₁ x)] [∀ x, TopologicalSpace (E₂ x)] : B → Type _ := fun x ↦ E₁ x →SL[σ] E₂ x variable {E₁ E₂} variable [TopologicalSpace B] (e₁ e₁' : Trivialization F₁ (π F₁ E₁)) (e₂ e₂' : Trivialization F₂ (π F₂ E₂)) namespace Pretrivialization /-- Assume `eᵢ` and `eᵢ'` are trivializations of the bundles `Eᵢ` over base `B` with fiber `Fᵢ` (`i ∈ {1,2}`), then `Pretrivialization.continuousLinearMapCoordChange σ e₁ e₁' e₂ e₂'` is the coordinate change function between the two induced (pre)trivializations `Pretrivialization.continuousLinearMap σ e₁ e₂` and `Pretrivialization.continuousLinearMap σ e₁' e₂'` of the bundle of continuous linear maps. -/ def continuousLinearMapCoordChange [e₁.IsLinear 𝕜₁] [e₁'.IsLinear 𝕜₁] [e₂.IsLinear 𝕜₂] [e₂'.IsLinear 𝕜₂] (b : B) : (F₁ →SL[σ] F₂) →L[𝕜₂] F₁ →SL[σ] F₂ := ((e₁'.coordChangeL 𝕜₁ e₁ b).symm.arrowCongrSL (e₂.coordChangeL 𝕜₂ e₂' b) : (F₁ →SL[σ] F₂) ≃L[𝕜₂] F₁ →SL[σ] F₂) variable {σ e₁ e₁' e₂ e₂'} variable [∀ x, TopologicalSpace (E₁ x)] [FiberBundle F₁ E₁] variable [∀ x, TopologicalSpace (E₂ x)] [FiberBundle F₂ E₂] theorem continuousOn_continuousLinearMapCoordChange [RingHomIsometric σ] [VectorBundle 𝕜₁ F₁ E₁] [VectorBundle 𝕜₂ F₂ E₂] [MemTrivializationAtlas e₁] [MemTrivializationAtlas e₁'] [MemTrivializationAtlas e₂] [MemTrivializationAtlas e₂'] : ContinuousOn (continuousLinearMapCoordChange σ e₁ e₁' e₂ e₂') (e₁.baseSet ∩ e₂.baseSet ∩ (e₁'.baseSet ∩ e₂'.baseSet)) := by have h₁ := (compSL F₁ F₂ F₂ σ (RingHom.id 𝕜₂)).continuous have h₂ := (ContinuousLinearMap.flip (compSL F₁ F₁ F₂ (RingHom.id 𝕜₁) σ)).continuous have h₃ := continuousOn_coordChange 𝕜₁ e₁' e₁ have h₄ := continuousOn_coordChange 𝕜₂ e₂ e₂' refine ((h₁.comp_continuousOn (h₄.mono ?_)).clm_comp (h₂.comp_continuousOn (h₃.mono ?_))).congr ?_ · mfld_set_tac · mfld_set_tac · intro b _ ext L v dsimp [continuousLinearMapCoordChange] variable (σ e₁ e₁' e₂ e₂') variable [e₁.IsLinear 𝕜₁] [e₁'.IsLinear 𝕜₁] [e₂.IsLinear 𝕜₂] [e₂'.IsLinear 𝕜₂] /-- Given trivializations `e₁`, `e₂` for vector bundles `E₁`, `E₂` over a base `B`, `Pretrivialization.continuousLinearMap σ e₁ e₂` is the induced pretrivialization for the continuous `σ`-semilinear maps from `E₁` to `E₂`. That is, the map which will later become a trivialization, after the bundle of continuous semilinear maps is equipped with the right topological vector bundle structure. -/ def continuousLinearMap : Pretrivialization (F₁ →SL[σ] F₂) (π (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) where toFun p := ⟨p.1, .comp (e₂.continuousLinearMapAt 𝕜₂ p.1) (p.2.comp (e₁.symmL 𝕜₁ p.1))⟩ invFun p := ⟨p.1, .comp (e₂.symmL 𝕜₂ p.1) (p.2.comp (e₁.continuousLinearMapAt 𝕜₁ p.1))⟩ source := Bundle.TotalSpace.proj ⁻¹' (e₁.baseSet ∩ e₂.baseSet) target := (e₁.baseSet ∩ e₂.baseSet) ×ˢ Set.univ map_source' := fun ⟨_, _⟩ h ↦ ⟨h, Set.mem_univ _⟩ map_target' := fun ⟨_, _⟩ h ↦ h.1 left_inv' := fun ⟨x, L⟩ ⟨h₁, h₂⟩ ↦ by simp only [TotalSpace.mk_inj] ext (v : E₁ x) dsimp only [comp_apply] rw [Trivialization.symmL_continuousLinearMapAt, Trivialization.symmL_continuousLinearMapAt] exacts [h₁, h₂] right_inv' := fun ⟨x, f⟩ ⟨⟨h₁, h₂⟩, _⟩ ↦ by simp only [Prod.mk_right_inj] ext v dsimp only [comp_apply] rw [Trivialization.continuousLinearMapAt_symmL, Trivialization.continuousLinearMapAt_symmL] exacts [h₁, h₂] open_target := (e₁.open_baseSet.inter e₂.open_baseSet).prod isOpen_univ baseSet := e₁.baseSet ∩ e₂.baseSet open_baseSet := e₁.open_baseSet.inter e₂.open_baseSet source_eq := rfl target_eq := rfl proj_toFun _ _ := rfl -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): -- TODO: see if Lean 4 can generate this instance without a hint instance continuousLinearMap.isLinear [∀ x, ContinuousAdd (E₂ x)] [∀ x, ContinuousSMul 𝕜₂ (E₂ x)] : (Pretrivialization.continuousLinearMap σ e₁ e₂).IsLinear 𝕜₂ where linear x _ := { map_add := fun L L' ↦ show (e₂.continuousLinearMapAt 𝕜₂ x).comp ((L + L').comp (e₁.symmL 𝕜₁ x)) = _ by simp_rw [add_comp, comp_add] rfl map_smul := fun c L ↦ show (e₂.continuousLinearMapAt 𝕜₂ x).comp ((c • L).comp (e₁.symmL 𝕜₁ x)) = _ by simp_rw [smul_comp, comp_smulₛₗ, RingHom.id_apply] rfl } theorem continuousLinearMap_apply (p : TotalSpace (F₁ →SL[σ] F₂) fun x ↦ E₁ x →SL[σ] E₂ x) : (continuousLinearMap σ e₁ e₂) p = ⟨p.1, .comp (e₂.continuousLinearMapAt 𝕜₂ p.1) (p.2.comp (e₁.symmL 𝕜₁ p.1))⟩ := rfl theorem continuousLinearMap_symm_apply (p : B × (F₁ →SL[σ] F₂)) : (continuousLinearMap σ e₁ e₂).toPartialEquiv.symm p = ⟨p.1, .comp (e₂.symmL 𝕜₂ p.1) (p.2.comp (e₁.continuousLinearMapAt 𝕜₁ p.1))⟩ := rfl theorem continuousLinearMap_symm_apply' {b : B} (hb : b ∈ e₁.baseSet ∩ e₂.baseSet) (L : F₁ →SL[σ] F₂) : (continuousLinearMap σ e₁ e₂).symm b L = (e₂.symmL 𝕜₂ b).comp (L.comp <| e₁.continuousLinearMapAt 𝕜₁ b) := by rw [symm_apply] · rfl · exact hb theorem continuousLinearMapCoordChange_apply (b : B) (hb : b ∈ e₁.baseSet ∩ e₂.baseSet ∩ (e₁'.baseSet ∩ e₂'.baseSet)) (L : F₁ →SL[σ] F₂) : continuousLinearMapCoordChange σ e₁ e₁' e₂ e₂' b L = (continuousLinearMap σ e₁' e₂' ⟨b, (continuousLinearMap σ e₁ e₂).symm b L⟩).2 := by ext v simp_rw [continuousLinearMapCoordChange, ContinuousLinearEquiv.coe_coe, ContinuousLinearEquiv.arrowCongrSL_apply, continuousLinearMap_apply, continuousLinearMap_symm_apply' σ e₁ e₂ hb.1, comp_apply, ContinuousLinearEquiv.coe_coe, ContinuousLinearEquiv.symm_symm, Trivialization.continuousLinearMapAt_apply, Trivialization.symmL_apply] rw [e₂.coordChangeL_apply e₂', e₁'.coordChangeL_apply e₁, e₁.coe_linearMapAt_of_mem hb.1.1, e₂'.coe_linearMapAt_of_mem hb.2.2] exacts [⟨hb.2.1, hb.1.1⟩, ⟨hb.1.2, hb.2.2⟩] end Pretrivialization open Pretrivialization variable (F₁ E₁ F₂ E₂) variable [∀ x : B, TopologicalSpace (E₁ x)] [FiberBundle F₁ E₁] [VectorBundle 𝕜₁ F₁ E₁] variable [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₂ E₂] [VectorBundle 𝕜₂ F₂ E₂] variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜₂ (E₂ x)] variable [RingHomIsometric σ] /-- The continuous `σ`-semilinear maps between two topological vector bundles form a `VectorPrebundle` (this is an auxiliary construction for the `VectorBundle` instance, in which the pretrivializations are collated but no topology on the total space is yet provided). -/ def Bundle.ContinuousLinearMap.vectorPrebundle : VectorPrebundle 𝕜₂ (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) where pretrivializationAtlas := {e | ∃ (e₁ : Trivialization F₁ (π F₁ E₁)) (e₂ : Trivialization F₂ (π F₂ E₂)) (_ : MemTrivializationAtlas e₁) (_ : MemTrivializationAtlas e₂), e = Pretrivialization.continuousLinearMap σ e₁ e₂} pretrivialization_linear' := by rintro _ ⟨e₁, he₁, e₂, he₂, rfl⟩ infer_instance pretrivializationAt x := Pretrivialization.continuousLinearMap σ (trivializationAt F₁ E₁ x) (trivializationAt F₂ E₂ x) mem_base_pretrivializationAt x := ⟨mem_baseSet_trivializationAt F₁ E₁ x, mem_baseSet_trivializationAt F₂ E₂ x⟩ pretrivialization_mem_atlas x := ⟨trivializationAt F₁ E₁ x, trivializationAt F₂ E₂ x, inferInstance, inferInstance, rfl⟩ exists_coordChange := by rintro _ ⟨e₁, e₂, he₁, he₂, rfl⟩ _ ⟨e₁', e₂', he₁', he₂', rfl⟩ exact ⟨continuousLinearMapCoordChange σ e₁ e₁' e₂ e₂', continuousOn_continuousLinearMapCoordChange, continuousLinearMapCoordChange_apply σ e₁ e₁' e₂ e₂'⟩ totalSpaceMk_isInducing := by intro b let L₁ : E₁ b ≃L[𝕜₁] F₁ := (trivializationAt F₁ E₁ b).continuousLinearEquivAt 𝕜₁ b (mem_baseSet_trivializationAt _ _ _) let L₂ : E₂ b ≃L[𝕜₂] F₂ := (trivializationAt F₂ E₂ b).continuousLinearEquivAt 𝕜₂ b (mem_baseSet_trivializationAt _ _ _) let φ : (E₁ b →SL[σ] E₂ b) ≃L[𝕜₂] F₁ →SL[σ] F₂ := L₁.arrowCongrSL L₂ have : IsInducing fun x ↦ (b, φ x) := isInducing_const_prod.mpr φ.toHomeomorph.isInducing convert this ext f dsimp [Pretrivialization.continuousLinearMap_apply] rw [Trivialization.linearMapAt_def_of_mem _ (mem_baseSet_trivializationAt _ _ _)] rfl /-- Topology on the total space of the continuous `σ`-semilinear maps between two "normable" vector bundles over the same base. -/ instance Bundle.ContinuousLinearMap.topologicalSpaceTotalSpace : TopologicalSpace (TotalSpace (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) := (Bundle.ContinuousLinearMap.vectorPrebundle σ F₁ E₁ F₂ E₂).totalSpaceTopology /-- The continuous `σ`-semilinear maps between two vector bundles form a fiber bundle. -/ instance Bundle.ContinuousLinearMap.fiberBundle : FiberBundle (F₁ →SL[σ] F₂) fun x ↦ E₁ x →SL[σ] E₂ x := (Bundle.ContinuousLinearMap.vectorPrebundle σ F₁ E₁ F₂ E₂).toFiberBundle /-- The continuous `σ`-semilinear maps between two vector bundles form a vector bundle. -/ instance Bundle.ContinuousLinearMap.vectorBundle : VectorBundle 𝕜₂ (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) := (Bundle.ContinuousLinearMap.vectorPrebundle σ F₁ E₁ F₂ E₂).toVectorBundle variable [he₁ : MemTrivializationAtlas e₁] [he₂ : MemTrivializationAtlas e₂] {F₁ E₁ F₂ E₂} /-- Given trivializations `e₁`, `e₂` in the atlas for vector bundles `E₁`, `E₂` over a base `B`, the induced trivialization for the continuous `σ`-semilinear maps from `E₁` to `E₂`, whose base set is `e₁.baseSet ∩ e₂.baseSet`. -/ def Trivialization.continuousLinearMap : Trivialization (F₁ →SL[σ] F₂) (π (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) := VectorPrebundle.trivializationOfMemPretrivializationAtlas _ ⟨e₁, e₂, he₁, he₂, rfl⟩ instance Bundle.ContinuousLinearMap.memTrivializationAtlas : MemTrivializationAtlas (e₁.continuousLinearMap σ e₂ : Trivialization (F₁ →SL[σ] F₂) (π (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x))) where out := ⟨_, ⟨e₁, e₂, by infer_instance, by infer_instance, rfl⟩, rfl⟩ variable {e₁ e₂} @[simp] theorem Trivialization.baseSet_continuousLinearMap : (e₁.continuousLinearMap σ e₂).baseSet = e₁.baseSet ∩ e₂.baseSet := rfl theorem Trivialization.continuousLinearMap_apply (p : TotalSpace (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) : e₁.continuousLinearMap σ e₂ p = ⟨p.1, (e₂.continuousLinearMapAt 𝕜₂ p.1 : _ →L[𝕜₂] _).comp (p.2.comp (e₁.symmL 𝕜₁ p.1 : F₁ →L[𝕜₁] E₁ p.1) : F₁ →SL[σ] E₂ p.1)⟩ := rfl theorem hom_trivializationAt (x₀ : B) : trivializationAt (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) x₀ = (trivializationAt F₁ E₁ x₀).continuousLinearMap σ (trivializationAt F₂ E₂ x₀) := rfl theorem hom_trivializationAt_apply (x₀ : B) (x : TotalSpace (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) : trivializationAt (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) x₀ x = ⟨x.1, inCoordinates F₁ E₁ F₂ E₂ x₀ x.1 x₀ x.1 x.2⟩ := rfl @[simp, mfld_simps] theorem hom_trivializationAt_source (x₀ : B) : (trivializationAt (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) x₀).source = π (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) ⁻¹' ((trivializationAt F₁ E₁ x₀).baseSet ∩ (trivializationAt F₂ E₂ x₀).baseSet) := rfl @[simp, mfld_simps] theorem hom_trivializationAt_target (x₀ : B) : (trivializationAt (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) x₀).target = ((trivializationAt F₁ E₁ x₀).baseSet ∩ (trivializationAt F₂ E₂ x₀).baseSet) ×ˢ Set.univ := rfl @[simp] theorem hom_trivializationAt_baseSet (x₀ : B) : (trivializationAt (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x) x₀).baseSet = ((trivializationAt F₁ E₁ x₀).baseSet ∩ (trivializationAt F₂ E₂ x₀).baseSet) := rfl theorem continuousWithinAt_hom_bundle {M : Type*} [TopologicalSpace M] (f : M → TotalSpace (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) {s : Set M} {x₀ : M} : ContinuousWithinAt f s x₀ ↔ ContinuousWithinAt (fun x ↦ (f x).1) s x₀ ∧ ContinuousWithinAt (fun x ↦ inCoordinates F₁ E₁ F₂ E₂ (f x₀).1 (f x).1 (f x₀).1 (f x).1 (f x).2) s x₀ := FiberBundle.continuousWithinAt_totalSpace .. theorem continuousAt_hom_bundle {M : Type*} [TopologicalSpace M] (f : M → TotalSpace (F₁ →SL[σ] F₂) (fun x ↦ E₁ x →SL[σ] E₂ x)) {x₀ : M} : ContinuousAt f x₀ ↔ ContinuousAt (fun x ↦ (f x).1) x₀ ∧ ContinuousAt (fun x ↦ inCoordinates F₁ E₁ F₂ E₂ (f x₀).1 (f x).1 (f x₀).1 (f x).1 (f x).2) x₀ := FiberBundle.continuousAt_totalSpace .. section /- Declare two bases spaces `B₁` and `B₂` and two vector bundles `E₁` and `E₂` respectively over `B₁` and `B₂` (with model fibers `F₁` and `F₂`). Also a third space `M`, which will be the source of all our maps. -/ variable {𝕜 F₁ F₂ B₁ B₂ M : Type*} {E₁ : B₁ → Type*} {E₂ : B₂ → Type*} [NontriviallyNormedField 𝕜] [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, TopologicalSpace (E₁ x)] [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, TopologicalSpace (E₂ x)] [TopologicalSpace B₁] [TopologicalSpace B₂] [TopologicalSpace M] {n : WithTop ℕ∞} [FiberBundle F₁ E₁] [VectorBundle 𝕜 F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₂ E₂] {b₁ : M → B₁} {b₂ : M → B₂} {m₀ : M} {ϕ : Π (m : M), E₁ (b₁ m) →L[𝕜] E₂ (b₂ m)} {v : Π (m : M), E₁ (b₁ m)} {s : Set M} /-- Consider a continuous map `v : M → E₁` to a vector bundle, over a base map `b₁ : M → B₁`, and another basemap `b₂ : M → B₂`. Given linear maps `ϕ m : E₁ (b₁ m) → E₂ (b₂ m)` depending continuously on `m`, one can apply `ϕ m` to `g m`, and the resulting map is continuous. Note that the continuity of `ϕ` cannot be always be stated as continuity of a map into a bundle, as the pullback bundles `b₁ *ᵖ E₁` and `b₂ *ᵖ E₂` only have a nice topology when `b₁` and `b₂` are globally continuous, but we want to apply this lemma with only local information. Therefore, we formulate it using continuity of `ϕ` read in coordinates. Version for `ContinuousWithinAt`. We also give a version for `ContinuousAt`, but no version for `ContinuousOn` or `Continuous` as our assumption, written in coordinates, only makes sense around a point. For a version with `B₁ = B₂` and `b₁ = b₂`, in which continuity can be expressed without `inCoordinates`, see `ContinuousWithinAt.clm_bundle_apply` -/ lemma ContinuousWithinAt.clm_apply_of_inCoordinates (hϕ : ContinuousWithinAt (fun m ↦ inCoordinates F₁ E₁ F₂ E₂ (b₁ m₀) (b₁ m) (b₂ m₀) (b₂ m) (ϕ m)) s m₀) (hv : ContinuousWithinAt (fun m ↦ (v m : TotalSpace F₁ E₁)) s m₀) (hb₂ : ContinuousWithinAt b₂ s m₀) : ContinuousWithinAt (fun m ↦ (ϕ m (v m) : TotalSpace F₂ E₂)) s m₀ := by rw [← continuousWithinAt_insert_self] at hϕ hv hb₂ ⊢ rw [FiberBundle.continuousWithinAt_totalSpace] at hv ⊢ refine ⟨hb₂, ?_⟩ apply (ContinuousWithinAt.clm_apply hϕ hv.2).congr_of_eventuallyEq_of_mem ?_ (mem_insert m₀ s) have A : ∀ᶠ m in 𝓝[insert m₀ s] m₀, b₁ m ∈ (trivializationAt F₁ E₁ (b₁ m₀)).baseSet := by apply hv.1 apply (trivializationAt F₁ E₁ (b₁ m₀)).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' (b₁ m₀) have A' : ∀ᶠ m in 𝓝[insert m₀ s] m₀, b₂ m ∈ (trivializationAt F₂ E₂ (b₂ m₀)).baseSet := by apply hb₂ apply (trivializationAt F₂ E₂ (b₂ m₀)).open_baseSet.mem_nhds exact FiberBundle.mem_baseSet_trivializationAt' (b₂ m₀) filter_upwards [A, A'] with m hm h'm simp [inCoordinates_eq hm h'm, Trivialization.symm_apply_apply_mk (trivializationAt F₁ E₁ (b₁ m₀)) hm (v m)] /-- Consider a continuous map `v : M → E₁` to a vector bundle, over a base map `b₁ : M → B₁`, and another basemap `b₂ : M → B₂`. Given linear maps `ϕ m : E₁ (b₁ m) → E₂ (b₂ m)` depending continuously on `m`, one can apply `ϕ m` to `g m`, and the resulting map is continuous. Note that the continuity of `ϕ` cannot be always be stated as continuity of a map into a bundle, as the pullback bundles `b₁ *ᵖ E₁` and `b₂ *ᵖ E₂` only have a nice topology when `b₁` and `b₂` are globally continuous, but we want to apply this lemma with only local information. Therefore, we formulate it using continuity of `ϕ` read in coordinates. Version for `ContinuousAt`. We also give a version for `ContinuousWithinAt`, but no version for `ContinuousOn` or `Continuous` as our assumption, written in coordinates, only makes sense around a point. For a version with `B₁ = B₂` and `b₁ = b₂`, in which continuity can be expressed without `inCoordinates`, see `ContinuousWithinAt.clm_bundle_apply` -/ lemma ContinuousAt.clm_apply_of_inCoordinates (hϕ : ContinuousAt (fun m ↦ inCoordinates F₁ E₁ F₂ E₂ (b₁ m₀) (b₁ m) (b₂ m₀) (b₂ m) (ϕ m)) m₀) (hv : ContinuousAt (fun m ↦ (v m : TotalSpace F₁ E₁)) m₀) (hb₂ : ContinuousAt b₂ m₀) : ContinuousAt (fun m ↦ (ϕ m (v m) : TotalSpace F₂ E₂)) m₀ := by rw [← continuousWithinAt_univ] at hϕ hv hb₂ ⊢ exact hϕ.clm_apply_of_inCoordinates hv hb₂ end section /- Declare a base space `B` and three vector bundles `E₁`, `E₂` and `E₃` over `B` (with model fibers `F₁`, `F₂` and `F₃`). Also a second space `M`, which will be the source of all our maps. -/ variable {𝕜 B F₁ F₂ F₃ M : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞} {E₁ : B → Type*} [∀ x, AddCommGroup (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] [TopologicalSpace (TotalSpace F₁ E₁)] [∀ x, TopologicalSpace (E₁ x)] {E₂ : B → Type*} [∀ x, AddCommGroup (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] [TopologicalSpace (TotalSpace F₂ E₂)] [∀ x, TopologicalSpace (E₂ x)] {E₃ : B → Type*} [∀ x, AddCommGroup (E₃ x)] [∀ x, Module 𝕜 (E₃ x)] [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] [TopologicalSpace (TotalSpace F₃ E₃)] [∀ x, TopologicalSpace (E₃ x)] [TopologicalSpace B] [TopologicalSpace M] [FiberBundle F₁ E₁] [VectorBundle 𝕜 F₁ E₁] [FiberBundle F₂ E₂] [VectorBundle 𝕜 F₂ E₂] [FiberBundle F₃ E₃] [VectorBundle 𝕜 F₃ E₃] {b : M → B} {v : ∀ x, E₁ (b x)} {s : Set M} {x : M} section OneVariable variable [∀ x, IsTopologicalAddGroup (E₂ x)] [∀ x, ContinuousSMul 𝕜 (E₂ x)] {ϕ : ∀ x, (E₁ (b x) →L[𝕜] E₂ (b x))} /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a basemap `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. -/ lemma ContinuousWithinAt.clm_bundle_apply (hϕ : ContinuousWithinAt (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) s x) (hv : ContinuousWithinAt (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s x) : ContinuousWithinAt (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) s x := by simp only [continuousWithinAt_hom_bundle] at hϕ exact hϕ.2.clm_apply_of_inCoordinates hv hϕ.1 /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a basemap `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. -/ lemma ContinuousAt.clm_bundle_apply (hϕ : ContinuousAt (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) x) (hv : ContinuousAt (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) x) : ContinuousAt (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) x := by simp only [← continuousWithinAt_univ] at hϕ hv ⊢ exact hϕ.clm_bundle_apply hv /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a basemap `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. -/ lemma ContinuousOn.clm_bundle_apply (hϕ : ContinuousOn (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m)) s) (hv : ContinuousOn (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s) : ContinuousOn (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) s := fun x hx ↦ (hϕ x hx).clm_bundle_apply (hv x hx) /-- Consider a `C^n` map `v : M → E₁` to a vector bundle, over a basemap `b : M → B`, and linear maps `ϕ m : E₁ (b m) → E₂ (b m)` depending smoothly on `m`. One can apply `ϕ m` to `v m`, and the resulting map is `C^n`. -/ lemma Continuous.clm_bundle_apply (hϕ : Continuous (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x)) (b m) (ϕ m))) (hv : Continuous (fun m ↦ TotalSpace.mk' F₁ (b m) (v m))) : Continuous (fun m ↦ TotalSpace.mk' F₂ (b m) (ϕ m (v m))) := by simp only [← continuousOn_univ] at hϕ hv ⊢ exact hϕ.clm_bundle_apply hv end OneVariable section TwoVariables variable [∀ x, IsTopologicalAddGroup (E₃ x)] [∀ x, ContinuousSMul 𝕜 (E₃ x)] {ψ : ∀ x, (E₁ (b x) →L[𝕜] E₂ (b x) →L[𝕜] E₃ (b x))} {w : ∀ x, E₂ (b x)} /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a basemap `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. -/ lemma ContinuousWithinAt.clm_bundle_apply₂ (hψ : ContinuousWithinAt (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) s x) (hv : ContinuousWithinAt (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s x) (hw : ContinuousWithinAt (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) s x) : ContinuousWithinAt (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) s x := (hψ.clm_bundle_apply hv).clm_bundle_apply hw /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a basemap `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. -/ lemma ContinuousAt.clm_bundle_apply₂ (hψ : ContinuousAt (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) x) (hv : ContinuousAt (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) x) (hw : ContinuousAt (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) x) : ContinuousAt (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) x := (hψ.clm_bundle_apply hv).clm_bundle_apply hw /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a basemap `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. -/ lemma ContinuousOn.clm_bundle_apply₂ (hψ : ContinuousOn (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m)) s) (hv : ContinuousOn (fun m ↦ TotalSpace.mk' F₁ (b m) (v m)) s) (hw : ContinuousOn (fun m ↦ TotalSpace.mk' F₂ (b m) (w m)) s) : ContinuousOn (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) s := fun x hx ↦ (hψ x hx).clm_bundle_apply₂ (hv x hx) (hw x hx) /-- Consider `C^n` maps `v : M → E₁` and `v : M → E₂` to vector bundles, over a basemap `b : M → B`, and bilinear maps `ψ m : E₁ (b m) → E₂ (b m) → E₃ (b m)` depending smoothly on `m`. One can apply `ψ m` to `v m` and `w m`, and the resulting map is `C^n`. -/ lemma Continuous.clm_bundle_apply₂ (hψ : Continuous (fun m ↦ TotalSpace.mk' (F₁ →L[𝕜] F₂ →L[𝕜] F₃) (E := fun (x : B) ↦ (E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x)) (b m) (ψ m))) (hv : Continuous (fun m ↦ TotalSpace.mk' F₁ (b m) (v m))) (hw : Continuous (fun m ↦ TotalSpace.mk' F₂ (b m) (w m))) : Continuous (fun m ↦ TotalSpace.mk' F₃ (b m) (ψ m (v m) (w m))) := by simp only [← continuousOn_univ] at hψ hv hw ⊢ exact hψ.clm_bundle_apply₂ hv hw /-- Rewrite `ContinuousLinearMap.inCoordinates` using continuous linear equivalences, in the bundle of bilinear maps. -/ theorem inCoordinates_apply_eq₂ {x₀ x : B} {ϕ : E₁ x →L[𝕜] E₂ x →L[𝕜] E₃ x} {v : F₁} {w : F₂} (h₁x : x ∈ (trivializationAt F₁ E₁ x₀).baseSet) (h₂x : x ∈ (trivializationAt F₂ E₂ x₀).baseSet) (h₃x : x ∈ (trivializationAt F₃ E₃ x₀).baseSet) : inCoordinates F₁ E₁ (F₂ →L[𝕜] F₃) (fun x ↦ E₂ x →L[𝕜] E₃ x) x₀ x x₀ x ϕ v w = (trivializationAt F₃ E₃ x₀).linearMapAt 𝕜 x (ϕ ((trivializationAt F₁ E₁ x₀).symm x v) ((trivializationAt F₂ E₂ x₀).symm x w)) := by rw [inCoordinates_eq h₁x (by simp [h₂x, h₃x])] simp [hom_trivializationAt, Trivialization.continuousLinearMap_apply] end TwoVariables end
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Matrix.lean
import Mathlib.LinearAlgebra.Matrix.Defs import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.Algebra.IsUniformGroup.Constructions /-! # Uniform space structure on matrices -/ open Uniformity Topology variable (m n 𝕜 : Type*) [UniformSpace 𝕜] namespace Matrix instance instUniformSpace : UniformSpace (Matrix m n 𝕜) := (by infer_instance : UniformSpace (m → n → 𝕜)) instance instIsUniformAddGroup [AddGroup 𝕜] [IsUniformAddGroup 𝕜] : IsUniformAddGroup (Matrix m n 𝕜) := inferInstanceAs <| IsUniformAddGroup (m → n → 𝕜) theorem uniformity : 𝓤 (Matrix m n 𝕜) = ⨅ (i : m) (j : n), (𝓤 𝕜).comap fun a => (a.1 i j, a.2 i j) := by erw [Pi.uniformity] simp_rw [Pi.uniformity, Filter.comap_iInf, Filter.comap_comap] rfl theorem uniformContinuous {β : Type*} [UniformSpace β] {f : β → Matrix m n 𝕜} : UniformContinuous f ↔ ∀ i j, UniformContinuous fun x => f x i j := by simp only [UniformContinuous, Matrix.uniformity, Filter.tendsto_iInf, Filter.tendsto_comap_iff] apply Iff.intro <;> intro a <;> apply a instance [CompleteSpace 𝕜] : CompleteSpace (Matrix m n 𝕜) := (by infer_instance : CompleteSpace (m → n → 𝕜)) instance [T0Space 𝕜] : T0Space (Matrix m n 𝕜) := inferInstanceAs (T0Space (m → n → 𝕜)) end Matrix
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/OfCompactT2.lean
import Mathlib.Topology.Separation.Regular import Mathlib.Topology.UniformSpace.Defs import Mathlib.Tactic.TautoSet /-! # Compact separated uniform spaces ## Main statement * `uniformSpaceOfCompactR1`: every compact R1 topological structure is induced by a uniform structure. This uniform structure is described by `compactSpace_uniformity`. ## Implementation notes The construction `uniformSpaceOfCompactR1` is not declared as an instance, as it would badly loop. ## Tags uniform space, uniform continuity, compact space -/ open Topology Filter UniformSpace Set open scoped SetRel variable {γ : Type*} /-! ### Uniformity on compact spaces -/ /-- The unique uniform structure inducing a given compact topological structure. -/ def uniformSpaceOfCompactR1 [TopologicalSpace γ] [CompactSpace γ] [R1Space γ] : UniformSpace γ where uniformity := 𝓝ˢ (diagonal γ) symm := continuous_swap.tendsto_nhdsSet fun _ => Eq.symm comp := by /- This is the difficult part of the proof. We need to prove that, for each neighborhood `W` of the diagonal `Δ`, there exists a smaller neighborhood `V` such that `V ○ V ⊆ W`. -/ set 𝓝Δ := 𝓝ˢ (diagonal γ) -- The filter of neighborhoods of Δ set F := 𝓝Δ.lift' fun s : Set (γ × γ) => s ○ s -- Compositions of neighborhoods of Δ -- If this weren't true, then there would be V ∈ 𝓝Δ such that F ⊓ 𝓟 Vᶜ ≠ ⊥ rw [le_iff_forall_inf_principal_compl] intro V V_in by_contra H haveI : NeBot (F ⊓ 𝓟 Vᶜ) := ⟨H⟩ -- Hence compactness would give us a cluster point (x, y) for F ⊓ 𝓟 Vᶜ obtain ⟨⟨x, y⟩, hxy⟩ : ∃ p : γ × γ, ClusterPt p (F ⊓ 𝓟 Vᶜ) := exists_clusterPt_of_compactSpace _ -- In particular (x, y) is a cluster point of 𝓟 Vᶜ, hence is not in the interior of V, -- so x and y are inseparable have clV : ClusterPt (x, y) (𝓟 <| Vᶜ) := hxy.of_inf_right have ninsep_xy : ¬Inseparable x y := by intro h rw [← mem_closure_iff_clusterPt, (h.prod .rfl).mem_closed_iff isClosed_closure, closure_compl] at clV apply clV rw [mem_interior_iff_mem_nhds] exact nhds_le_nhdsSet (mem_diagonal y) V_in -- Since γ is compact and Hausdorff, it is T₄, hence T₃. -- So there are closed neighborhoods V₁ and V₂ of x and y contained in -- disjoint open neighborhoods U₁ and U₂. obtain ⟨U₁, -, V₁, V₁_in, U₂, -, V₂, V₂_in, V₁_cl, V₂_cl, U₁_op, U₂_op, VU₁, VU₂, hU₁₂⟩ := disjoint_nested_nhds_of_not_inseparable ninsep_xy -- We set U₃ := (V₁ ∪ V₂)ᶜ so that W := U₁ ×ˢ U₁ ∪ U₂ ×ˢ U₂ ∪ U₃ ×ˢ U₃ is an open -- neighborhood of Δ. let U₃ := (V₁ ∪ V₂)ᶜ have U₃_op : IsOpen U₃ := (V₁_cl.union V₂_cl).isOpen_compl let W := U₁ ×ˢ U₁ ∪ U₂ ×ˢ U₂ ∪ U₃ ×ˢ U₃ have W_in : W ∈ 𝓝Δ := by rw [mem_nhdsSet_iff_forall] rintro ⟨z, z'⟩ hzz' refine IsOpen.mem_nhds ?_ ?_ · apply_rules [IsOpen.union, IsOpen.prod] · cases hzz' simp only [W, U₃, mem_union, mem_prod] tauto_set -- So W ○ W ∈ F by definition of F have : W ○ W ∈ F := mem_lift' W_in -- And V₁ ×ˢ V₂ ∈ 𝓝 (x, y) have hV₁₂ : V₁ ×ˢ V₂ ∈ 𝓝 (x, y) := prod_mem_nhds V₁_in V₂_in -- But (x, y) is also a cluster point of F so (V₁ ×ˢ V₂) ∩ (W ○ W) ≠ ∅ obtain ⟨⟨u, v⟩, ⟨u_in, v_in⟩, w, huw, hwv⟩ := clusterPt_iff_nonempty.mp hxy.of_inf_left hV₁₂ this -- However the construction of W implies (V₁ ×ˢ V₂) ∩ (W ○ W) = ∅. simp only [W, U₃, mem_union, mem_prod] at huw hwv tauto_set nhds_eq_comap_uniformity x := by simp_rw [nhdsSet_diagonal, comap_iSup, nhds_prod_eq, comap_prod, Function.comp_def, comap_id'] rw [iSup_split _ (Inseparable x)] conv_rhs => congr · enter [1, i, 1, hi] rw [← hi.nhds_eq, comap_const_of_mem fun V => mem_of_mem_nhds] · enter [1, i, 1, hi] rw [(not_specializes_iff_exists_open.1 (mt Specializes.inseparable hi)).elim fun S hS => comap_const_of_notMem (hS.1.mem_nhds hS.2.1) hS.2.2] rw [iSup_subtype', @iSup_const _ _ _ _ ⟨⟨x, .rfl⟩⟩] simp
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Compact.lean
import Mathlib.Topology.UniformSpace.Basic import Mathlib.Topology.Compactness.Compact /-! # Compact sets in uniform spaces * `compactSpace_uniformity`: On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. -/ universe u v ua ub uc ud variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} section Compact open Uniformity Set Filter UniformSpace open scoped SetRel Topology variable [UniformSpace α] {K : Set α} /-- Let `c : ι → Set α` be an open cover of a compact set `s`. Then there exists an entourage `n` such that for each `x ∈ s` its `n`-neighborhood is contained in some `c i`. -/ theorem lebesgue_number_lemma {ι : Sort*} {U : ι → Set α} (hK : IsCompact K) (hopen : ∀ i, IsOpen (U i)) (hcover : K ⊆ ⋃ i, U i) : ∃ V ∈ 𝓤 α, ∀ x ∈ K, ∃ i, ball x V ⊆ U i := by have : ∀ x ∈ K, ∃ i, ∃ V ∈ 𝓤 α, ball x (V ○ V) ⊆ U i := fun x hx ↦ by obtain ⟨i, hi⟩ := mem_iUnion.1 (hcover hx) rw [← (hopen i).mem_nhds_iff, nhds_eq_comap_uniformity, ← lift'_comp_uniformity] at hi exact ⟨i, (((basis_sets _).lift' <| monotone_id.relComp monotone_id).comap _).mem_iff.1 hi⟩ choose ind W hW hWU using this rcases hK.elim_nhds_subcover' (fun x hx ↦ ball x (W x hx)) (fun x hx ↦ ball_mem_nhds _ (hW x hx)) with ⟨t, ht⟩ refine ⟨⋂ x ∈ t, W x x.2, (biInter_finset_mem _).2 fun x _ ↦ hW x x.2, fun x hx ↦ ?_⟩ rcases mem_iUnion₂.1 (ht hx) with ⟨y, hyt, hxy⟩ exact ⟨ind y y.2, fun z hz ↦ hWU _ _ ⟨x, hxy, mem_iInter₂.1 hz _ hyt⟩⟩ theorem lebesgue_number_lemma_nhds' {U : (x : α) → x ∈ K → Set α} (hK : IsCompact K) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ V ∈ 𝓤 α, ∀ x ∈ K, ∃ y : K, ball x V ⊆ U y y.2 := by rcases lebesgue_number_lemma (U := fun x : K => interior (U x x.2)) hK (fun _ => isOpen_interior) (fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 (hU x hx)⟩) with ⟨V, V_uni, hV⟩ exact ⟨V, V_uni, fun x hx => (hV x hx).imp fun _ hy => hy.trans interior_subset⟩ theorem lebesgue_number_lemma_nhds {U : α → Set α} (hK : IsCompact K) (hU : ∀ x ∈ K, U x ∈ 𝓝 x) : ∃ V ∈ 𝓤 α, ∀ x ∈ K, ∃ y, ball x V ⊆ U y := by rcases lebesgue_number_lemma (U := fun x => interior (U x)) hK (fun _ => isOpen_interior) (fun x hx => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x hx)⟩) with ⟨V, V_uni, hV⟩ exact ⟨V, V_uni, fun x hx => (hV x hx).imp fun _ hy => hy.trans interior_subset⟩ theorem lebesgue_number_lemma_nhdsWithin' {U : (x : α) → x ∈ K → Set α} (hK : IsCompact K) (hU : ∀ x hx, U x hx ∈ 𝓝[K] x) : ∃ V ∈ 𝓤 α, ∀ x ∈ K, ∃ y : K, ball x V ∩ K ⊆ U y y.2 := (lebesgue_number_lemma_nhds' hK (fun x hx => Filter.mem_inf_principal'.1 (hU x hx))).imp fun _ ⟨V_uni, hV⟩ => ⟨V_uni, fun x hx => (hV x hx).imp fun _ hy => (inter_subset _ _ _).2 hy⟩ theorem lebesgue_number_lemma_nhdsWithin {U : α → Set α} (hK : IsCompact K) (hU : ∀ x ∈ K, U x ∈ 𝓝[K] x) : ∃ V ∈ 𝓤 α, ∀ x ∈ K, ∃ y, ball x V ∩ K ⊆ U y := (lebesgue_number_lemma_nhds hK (fun x hx => Filter.mem_inf_principal'.1 (hU x hx))).imp fun _ ⟨V_uni, hV⟩ => ⟨V_uni, fun x hx => (hV x hx).imp fun _ hy => (inter_subset _ _ _).2 hy⟩ /-- Let `U : ι → Set α` be an open cover of a compact set `K`. Then there exists an entourage `V` such that for each `x ∈ K` its `V`-neighborhood is included in some `U i`. Moreover, one can choose an entourage from a given basis. -/ protected theorem Filter.HasBasis.lebesgue_number_lemma {ι' ι : Sort*} {p : ι' → Prop} {V : ι' → Set (α × α)} {U : ι → Set α} (hbasis : (𝓤 α).HasBasis p V) (hK : IsCompact K) (hopen : ∀ j, IsOpen (U j)) (hcover : K ⊆ ⋃ j, U j) : ∃ i, p i ∧ ∀ x ∈ K, ∃ j, ball x (V i) ⊆ U j := by refine (hbasis.exists_iff ?_).1 (lebesgue_number_lemma hK hopen hcover) exact fun s t hst ht x hx ↦ (ht x hx).imp fun i hi ↦ Subset.trans (ball_mono hst _) hi protected theorem Filter.HasBasis.lebesgue_number_lemma_nhds' {ι' : Sort*} {p : ι' → Prop} {V : ι' → Set (α × α)} {U : (x : α) → x ∈ K → Set α} (hbasis : (𝓤 α).HasBasis p V) (hK : IsCompact K) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ i, p i ∧ ∀ x ∈ K, ∃ y : K, ball x (V i) ⊆ U y y.2 := by refine (hbasis.exists_iff ?_).1 (lebesgue_number_lemma_nhds' hK hU) exact fun s t hst ht x hx ↦ (ht x hx).imp fun y hy ↦ Subset.trans (ball_mono hst _) hy protected theorem Filter.HasBasis.lebesgue_number_lemma_nhds {ι' : Sort*} {p : ι' → Prop} {V : ι' → Set (α × α)} {U : α → Set α} (hbasis : (𝓤 α).HasBasis p V) (hK : IsCompact K) (hU : ∀ x ∈ K, U x ∈ 𝓝 x) : ∃ i, p i ∧ ∀ x ∈ K, ∃ y, ball x (V i) ⊆ U y := by refine (hbasis.exists_iff ?_).1 (lebesgue_number_lemma_nhds hK hU) exact fun s t hst ht x hx ↦ (ht x hx).imp fun y hy ↦ Subset.trans (ball_mono hst _) hy protected theorem Filter.HasBasis.lebesgue_number_lemma_nhdsWithin' {ι' : Sort*} {p : ι' → Prop} {V : ι' → Set (α × α)} {U : (x : α) → x ∈ K → Set α} (hbasis : (𝓤 α).HasBasis p V) (hK : IsCompact K) (hU : ∀ x hx, U x hx ∈ 𝓝[K] x) : ∃ i, p i ∧ ∀ x ∈ K, ∃ y : K, ball x (V i) ∩ K ⊆ U y y.2 := by refine (hbasis.exists_iff ?_).1 (lebesgue_number_lemma_nhdsWithin' hK hU) exact fun s t hst ht x hx ↦ (ht x hx).imp fun y hy ↦ Subset.trans (Set.inter_subset_inter_left K (ball_mono hst _)) hy protected theorem Filter.HasBasis.lebesgue_number_lemma_nhdsWithin {ι' : Sort*} {p : ι' → Prop} {V : ι' → Set (α × α)} {U : α → Set α} (hbasis : (𝓤 α).HasBasis p V) (hK : IsCompact K) (hU : ∀ x ∈ K, U x ∈ 𝓝[K] x) : ∃ i, p i ∧ ∀ x ∈ K, ∃ y, ball x (V i) ∩ K ⊆ U y := by refine (hbasis.exists_iff ?_).1 (lebesgue_number_lemma_nhdsWithin hK hU) exact fun s t hst ht x hx ↦ (ht x hx).imp fun y hy ↦ Subset.trans (Set.inter_subset_inter_left K (ball_mono hst _)) hy /-- Let `c : Set (Set α)` be an open cover of a compact set `s`. Then there exists an entourage `n` such that for each `x ∈ s` its `n`-neighborhood is contained in some `t ∈ c`. -/ theorem lebesgue_number_lemma_sUnion {S : Set (Set α)} (hK : IsCompact K) (hopen : ∀ s ∈ S, IsOpen s) (hcover : K ⊆ ⋃₀ S) : ∃ V ∈ 𝓤 α, ∀ x ∈ K, ∃ s ∈ S, ball x V ⊆ s := by rw [sUnion_eq_iUnion] at hcover simpa using lebesgue_number_lemma hK (by simpa) hcover /-- If `K` is a compact set in a uniform space and `{V i | p i}` is a basis of entourages, then `{⋃ x ∈ K, UniformSpace.ball x (V i) | p i}` is a basis of `𝓝ˢ K`. Here "`{s i | p i}` is a basis of a filter `l`" means `Filter.HasBasis l p s`. -/ theorem IsCompact.nhdsSet_basis_uniformity {p : ι → Prop} {V : ι → Set (α × α)} (hbasis : (𝓤 α).HasBasis p V) (hK : IsCompact K) : (𝓝ˢ K).HasBasis p fun i => ⋃ x ∈ K, ball x (V i) where mem_iff' U := by constructor · intro H have HKU : K ⊆ ⋃ _ : Unit, interior U := by simpa only [iUnion_const, subset_interior_iff_mem_nhdsSet] using H obtain ⟨i, hpi, hi⟩ : ∃ i, p i ∧ ⋃ x ∈ K, ball x (V i) ⊆ interior U := by simpa using hbasis.lebesgue_number_lemma hK (fun _ ↦ isOpen_interior) HKU exact ⟨i, hpi, hi.trans interior_subset⟩ · rintro ⟨i, hpi, hi⟩ refine mem_of_superset (bUnion_mem_nhdsSet fun x _ ↦ ?_) hi exact ball_mem_nhds _ <| hbasis.mem_of_mem hpi -- TODO: move to a separate file, golf using the regularity of a uniform space. theorem Disjoint.exists_uniform_thickening {A B : Set α} (hA : IsCompact A) (hB : IsClosed B) (h : Disjoint A B) : ∃ V ∈ 𝓤 α, Disjoint (⋃ x ∈ A, ball x V) (⋃ x ∈ B, ball x V) := by have : Bᶜ ∈ 𝓝ˢ A := hB.isOpen_compl.mem_nhdsSet.mpr h.le_compl_right rw [(hA.nhdsSet_basis_uniformity (Filter.basis_sets _)).mem_iff] at this rcases this with ⟨U, hU, hUAB⟩ rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨V, hV, Set.disjoint_left.mpr fun x => ?_⟩ simp only [mem_iUnion₂] rintro ⟨a, ha, hxa⟩ ⟨b, hb, hxb⟩ rw [mem_ball_symmetry] at hxa hxb exact hUAB (mem_iUnion₂_of_mem ha <| hVU <| mem_comp_of_mem_ball hxa hxb) hb theorem Disjoint.exists_uniform_thickening_of_basis {p : ι → Prop} {s : ι → Set (α × α)} (hU : (𝓤 α).HasBasis p s) {A B : Set α} (hA : IsCompact A) (hB : IsClosed B) (h : Disjoint A B) : ∃ i, p i ∧ Disjoint (⋃ x ∈ A, ball x (s i)) (⋃ x ∈ B, ball x (s i)) := by rcases h.exists_uniform_thickening hA hB with ⟨V, hV, hVAB⟩ rcases hU.mem_iff.1 hV with ⟨i, hi, hiV⟩ exact ⟨i, hi, hVAB.mono (iUnion₂_mono fun a _ => ball_mono hiV a) (iUnion₂_mono fun b _ => ball_mono hiV b)⟩ /-- A useful consequence of the Lebesgue number lemma: given any compact set `K` contained in an open set `U`, we can find an (open) entourage `V` such that the ball of size `V` about any point of `K` is contained in `U`. -/ theorem lebesgue_number_of_compact_open {K U : Set α} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓤 α, IsOpen V ∧ ∀ x ∈ K, UniformSpace.ball x V ⊆ U := let ⟨V, ⟨hV, hVo⟩, hVU⟩ := (hK.nhdsSet_basis_uniformity uniformity_hasBasis_open).mem_iff.1 (hU.mem_nhdsSet.2 hKU) ⟨V, hV, hVo, iUnion₂_subset_iff.1 hVU⟩ /-- On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_eq_uniformity [CompactSpace α] : 𝓝ˢ (diagonal α) = 𝓤 α := by refine nhdsSet_diagonal_le_uniformity.antisymm ?_ have : (𝓤 (α × α)).HasBasis (fun U => U ∈ 𝓤 α) fun U => (fun p : (α × α) × α × α => ((p.1.1, p.2.1), p.1.2, p.2.2)) ⁻¹' U ×ˢ U := by rw [uniformity_prod_eq_comap_prod] exact (𝓤 α).basis_sets.prod_self.comap _ refine (isCompact_diagonal.nhdsSet_basis_uniformity this).ge_iff.2 fun U hU => ?_ exact mem_of_superset hU fun ⟨x, y⟩ hxy => mem_iUnion₂.2 ⟨(x, x), rfl, refl_mem_uniformity hU, hxy⟩ /-- On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. -/ theorem compactSpace_uniformity [CompactSpace α] : 𝓤 α = ⨆ x, 𝓝 (x, x) := nhdsSet_diagonal_eq_uniformity.symm.trans (nhdsSet_diagonal _) theorem unique_uniformity_of_compact [t : TopologicalSpace γ] [CompactSpace γ] {u u' : UniformSpace γ} (h : u.toTopologicalSpace = t) (h' : u'.toTopologicalSpace = t) : u = u' := by refine UniformSpace.ext ?_ have : @CompactSpace γ u.toTopologicalSpace := by rwa [h] have : @CompactSpace γ u'.toTopologicalSpace := by rwa [h'] rw [@compactSpace_uniformity _ u, compactSpace_uniformity, h, h'] end Compact
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/OfFun.lean
import Mathlib.Topology.UniformSpace.Defs /-! # Construct a `UniformSpace` from a `dist`-like function In this file we provide a constructor for `UniformSpace` given a `dist`-like function ## TODO RFC: use `UniformSpace.Core.mkOfBasis`? This will change defeq here and there -/ open Filter Set open scoped Uniformity variable {X M : Type*} namespace UniformSpace /-- Define a `UniformSpace` using a "distance" function. The function can be, e.g., the distance in a (usual or extended) metric space or an absolute value on a ring. -/ def ofFun [AddCommMonoid M] [PartialOrder M] (d : X → X → M) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : M), ∃ δ > (0 : M), ∀ x < δ, ∀ y < δ, x + y < ε) : UniformSpace X := .ofCore { uniformity := ⨅ r > 0, 𝓟 { x | d x.1 x.2 < r } refl := le_iInf₂ fun r hr => principal_mono.2 <| by simp [Set.subset_def, *] symm := tendsto_iInf_iInf fun r => tendsto_iInf_iInf fun _ => tendsto_principal_principal.2 fun x hx => by rwa [mem_setOf, symm] comp := le_iInf₂ fun r hr => let ⟨δ, h0, hδr⟩ := half r hr; le_principal_iff.2 <| mem_of_superset (mem_lift' <| mem_iInf_of_mem δ <| mem_iInf_of_mem h0 <| mem_principal_self _) fun (x, z) ⟨y, h₁, h₂⟩ => (triangle _ _ _).trans_lt (hδr _ h₁ _ h₂) } theorem hasBasis_ofFun [AddCommMonoid M] [LinearOrder M] (h₀ : ∃ x : M, 0 < x) (d : X → X → M) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : M), ∃ δ > (0 : M), ∀ x < δ, ∀ y < δ, x + y < ε) : 𝓤[.ofFun d refl symm triangle half].HasBasis ((0 : M) < ·) (fun ε => { x | d x.1 x.2 < ε }) := hasBasis_biInf_principal' (fun ε₁ h₁ ε₂ h₂ => ⟨min ε₁ ε₂, lt_min h₁ h₂, fun _x hx => lt_of_lt_of_le hx (min_le_left _ _), fun _x hx => lt_of_lt_of_le hx (min_le_right _ _)⟩) h₀ open scoped Topology in /-- Define a `UniformSpace` using a "distance" function. The function can be, e.g., the distance in a (usual or extended) metric space or an absolute value on a ring. We assume that there is a preexisting topology, for which the neighborhoods can be expressed using the "distance", and we make sure that the uniform space structure we construct has a topology which is defeq to the original one. -/ def ofFunOfHasBasis [t : TopologicalSpace X] [AddCommMonoid M] [LinearOrder M] (d : X → X → M) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : M), ∃ δ > (0 : M), ∀ x < δ, ∀ y < δ, x + y < ε) (basis : ∀ x, (𝓝 x).HasBasis (fun ε ↦ 0 < ε) (fun ε ↦ {y | d x y < ε})) : UniformSpace X where toTopologicalSpace := t nhds_eq_comap_uniformity x := (basis x).eq_of_same_basis <| (hasBasis_ofFun (basis x).ex_mem d refl symm triangle half).comap (Prod.mk x) __ := ofFun d refl symm triangle half end UniformSpace
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Ascoli.lean
import Mathlib.Topology.UniformSpace.CompactConvergence import Mathlib.Topology.UniformSpace.Equicontinuity import Mathlib.Topology.UniformSpace.Equiv /-! # Ascoli Theorem In this file, we prove the general **Arzela-Ascoli theorem**, and various related statements about the topology of equicontinuous subsets of `X →ᵤ[𝔖] α`, where `X` is a topological space, `𝔖` is a family of compact subsets of `X`, and `α` is a uniform space. ## Main statements * If `X` is a compact space, then the uniform structures of uniform convergence and pointwise convergence coincide on equicontinuous subsets. This is the key fact that makes equicontinuity important in functional analysis. We state various versions of it: - as an equality of `UniformSpace`s: `Equicontinuous.comap_uniformFun_eq` - in terms of `IsUniformInducing`: `Equicontinuous.isUniformInducing_uniformFun_iff_pi` - in terms of `IsInducing`: `Equicontinuous.inducing_uniformFun_iff_pi` - in terms of convergence along a filter: `Equicontinuous.tendsto_uniformFun_iff_pi` * As a consequence, if `𝔖` is a family of compact subsets of `X`, then the uniform structures of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` coincide on equicontinuous subsets. Again, we prove multiple variations: - as an equality of `UniformSpace`s: `EquicontinuousOn.comap_uniformOnFun_eq` - in terms of `IsUniformInducing`: `EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi'` - in terms of `IsInducing`: `EquicontinuousOn.inducing_uniformOnFun_iff_pi'` - in terms of convergence along a filter: `EquicontinuousOn.tendsto_uniformOnFun_iff_pi'` * The **Arzela-Ascoli theorem** follows from the previous fact and Tykhonov's theorem. All of its variations can be found under the `ArzelaAscoli` namespace. ## Implementation details * The statements in this file may be a bit daunting because we prove everything for families and embeddings instead of subspaces with the subspace topology. This is done because, in practice, one would rarely work with `X →ᵤ[𝔖] α` directly, so we need to provide API for bringing back the statements to various other types, such as `C(X, Y)` or `E →L[𝕜] F`. To counteract this, all statements (as well as most proofs!) are documented quite thoroughly. * A lot of statements assume `∀ K ∈ 𝔖, EquicontinuousOn F K` instead of the more natural `EquicontinuousOn F (⋃₀ 𝔖)`. This is in order to keep the most generality, as the first statement is strictly weaker. * In Bourbaki, the usual Arzela-Ascoli compactness theorem follows from a similar total boundedness result. Here we go directly for the compactness result, which is the most useful in practice, but this will be an easy addition/refactor if we ever need it. ## TODO * Prove that, on an equicontinuous family, pointwise convergence and pointwise convergence on a dense subset coincide, and deduce metrizability criteria for equicontinuous subsets. * Prove the total boundedness version of the theorem * Prove the converse statement: if a subset of `X →ᵤ[𝔖] α` is compact, then it is equicontinuous on each `K ∈ 𝔖`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ open Set Filter Uniformity Topology Function UniformConvergence variable {ι X α : Type*} [TopologicalSpace X] [UniformSpace α] {F : ι → X → α} /-- Let `X` be a compact topological space, `α` a uniform space, and `F : ι → (X → α)` an equicontinuous family. Then, the uniform structures of uniform convergence and pointwise convergence induce the same uniform structure on `ι`. In other words, pointwise convergence and uniform convergence coincide on an equicontinuous subset of `X → α`. Consider using `Equicontinuous.isUniformInducing_uniformFun_iff_pi` and `Equicontinuous.inducing_uniformFun_iff_pi` instead, to avoid rewriting instances. -/ theorem Equicontinuous.comap_uniformFun_eq [CompactSpace X] (F_eqcont : Equicontinuous F) : (UniformFun.uniformSpace X α).comap F = (Pi.uniformSpace _).comap F := by -- The `≤` inequality is trivial refine le_antisymm (UniformSpace.comap_mono UniformFun.uniformContinuous_toFun) ?_ -- A bit of rewriting to get a nice intermediate statement. simp_rw [UniformSpace.comap, UniformSpace.le_def, uniformity_comap, Pi.uniformity, Filter.comap_iInf, comap_comap, Function.comp_def] refine ((UniformFun.hasBasis_uniformity X α).comap (Prod.map F F)).ge_iff.mpr ?_ -- Core of the proof: we need to show that, for any entourage `U` in `α`, -- the set `𝐓(U) := {(i,j) : ι × ι | ∀ x : X, (F i x, F j x) ∈ U}` belongs to the filter -- `⨅ x, comap ((i,j) ↦ (F i x, F j x)) (𝓤 α)`. -- In other words, we have to show that it contains a finite intersection of -- sets of the form `𝐒(V, x) := {(i,j) : ι × ι | (F i x, F j x) ∈ V}` for some -- `x : X` and `V ∈ 𝓤 α`. intro U hU -- We will do an `ε/3` argument, so we start by choosing a symmetric entourage `V ∈ 𝓤 α` -- such that `V ○ V ○ V ⊆ U`. rcases comp_comp_symm_mem_uniformity_sets hU with ⟨V, hV, Vsymm, hVU⟩ -- Set `Ω x := {y | ∀ i, (F i x, F i y) ∈ V}`. The equicontinuity of `F` guarantees that -- each `Ω x` is a neighborhood of `x`. let Ω x : Set X := {y | ∀ i, (F i x, F i y) ∈ V} -- Hence, by compactness of `X`, we can find some `A ⊆ X` finite such that the `Ω a`s for `a ∈ A` -- still cover `X`. rcases CompactSpace.elim_nhds_subcover Ω (fun x ↦ F_eqcont x V hV) with ⟨A, Acover⟩ -- We now claim that `⋂ a ∈ A, 𝐒(V, a) ⊆ 𝐓(U)`. have : (⋂ a ∈ A, {ij : ι × ι | (F ij.1 a, F ij.2 a) ∈ V}) ⊆ (Prod.map F F) ⁻¹' UniformFun.gen X α U := by -- Given `(i, j) ∈ ⋂ a ∈ A, 𝐒(V, a)` and `x : X`, we have to prove that `(F i x, F j x) ∈ U`. rintro ⟨i, j⟩ hij x rw [mem_iInter₂] at hij -- We know that `x ∈ Ω a` for some `a ∈ A`, so that both `(F i x, F i a)` and `(F j a, F j x)` -- are in `V`. rcases mem_iUnion₂.mp (Acover.symm.subset <| mem_univ x) with ⟨a, ha, hax⟩ -- Since `(i, j) ∈ 𝐒(V, a)` we also have `(F i a, F j a) ∈ V`, and finally we get -- `(F i x, F j x) ∈ V ○ V ○ V ⊆ U`. exact hVU <| SetRel.prodMk_mem_comp (SetRel.prodMk_mem_comp (SetRel.symm V <| hax i) (hij a ha)) (hax j) -- This completes the proof. exact mem_of_superset (A.iInter_mem_sets.mpr fun x _ ↦ mem_iInf_of_mem x <| preimage_mem_comap hV) this /-- Let `X` be a compact topological space, `α` a uniform space, and `F : ι → (X → α)` an equicontinuous family. Then, the uniform structures of uniform convergence and pointwise convergence induce the same uniform structure on `ι`. In other words, pointwise convergence and uniform convergence coincide on an equicontinuous subset of `X → α`. This is a version of `Equicontinuous.comap_uniformFun_eq` stated in terms of `IsUniformInducing` for convenience. -/ lemma Equicontinuous.isUniformInducing_uniformFun_iff_pi [UniformSpace ι] [CompactSpace X] (F_eqcont : Equicontinuous F) : IsUniformInducing (UniformFun.ofFun ∘ F) ↔ IsUniformInducing F := by rw [isUniformInducing_iff_uniformSpace, isUniformInducing_iff_uniformSpace, ← F_eqcont.comap_uniformFun_eq] rfl /-- Let `X` be a compact topological space, `α` a uniform space, and `F : ι → (X → α)` an equicontinuous family. Then, the topologies of uniform convergence and pointwise convergence induce the same topology on `ι`. In other words, pointwise convergence and uniform convergence coincide on an equicontinuous subset of `X → α`. This is a consequence of `Equicontinuous.comap_uniformFun_eq`, stated in terms of `IsInducing` for convenience. -/ lemma Equicontinuous.inducing_uniformFun_iff_pi [TopologicalSpace ι] [CompactSpace X] (F_eqcont : Equicontinuous F) : IsInducing (UniformFun.ofFun ∘ F) ↔ IsInducing F := by rw [isInducing_iff, isInducing_iff] change (_ = (UniformFun.uniformSpace X α |>.comap F |>.toTopologicalSpace)) ↔ (_ = (Pi.uniformSpace _ |>.comap F |>.toTopologicalSpace)) rw [F_eqcont.comap_uniformFun_eq] /-- Let `X` be a compact topological space, `α` a uniform space, `F : ι → (X → α)` an equicontinuous family, and `ℱ` a filter on `ι`. Then, `F` tends *uniformly* to `f : X → α` along `ℱ` iff it tends to `f` *pointwise* along `ℱ`. -/ theorem Equicontinuous.tendsto_uniformFun_iff_pi [CompactSpace X] (F_eqcont : Equicontinuous F) (ℱ : Filter ι) (f : X → α) : Tendsto (UniformFun.ofFun ∘ F) ℱ (𝓝 <| UniformFun.ofFun f) ↔ Tendsto F ℱ (𝓝 f) := by -- Assume `ℱ` is non-trivial. rcases ℱ.eq_or_neBot with rfl | ℱ_ne · simp constructor <;> intro H -- The forward direction is always true, the interesting part is the converse. · exact UniformFun.uniformContinuous_toFun.continuous.tendsto _ |>.comp H -- To prove it, assume that `F` tends to `f` *pointwise* along `ℱ`. · set S : Set (X → α) := closure (range F) set 𝒢 : Filter S := comap (↑) (map F ℱ) -- We would like to use `Equicontinuous.comap_uniformFun_eq`, but applying it to `F` is not -- enough since `f` has no reason to be in the range of `F`. -- Instead, we will apply it to the inclusion `(↑) : S → (X → α)` where `S` is the closure of -- the range of `F` *for the product topology*. -- We know that `S` is still equicontinuous... have hS : S.Equicontinuous := closure' (by rwa [equicontinuous_iff_range] at F_eqcont) continuous_id -- ... hence, as announced, the product topology and uniform convergence topology -- coincide on `S`. have ind : IsInducing (UniformFun.ofFun ∘ (↑) : S → X →ᵤ α) := hS.inducing_uniformFun_iff_pi.mpr ⟨rfl⟩ -- By construction, `f` is in `S`. have f_mem : f ∈ S := mem_closure_of_tendsto H range_mem_map -- To conclude, we just have to translate our hypothesis and goal as statements about -- `S`, on which we know the two topologies at play coincide. -- For this, we define a filter on `S` by `𝒢 := comap (↑) (map F ℱ)`, and note that -- it satisfies `map (↑) 𝒢 = map F ℱ`. Thus, both our hypothesis and our goal -- can be rewritten as `𝒢 ≤ 𝓝 f`, where the neighborhood filter in the RHS corresponds -- to one of the two topologies at play on `S`. Since they coincide, we are done. have h𝒢ℱ : map (↑) 𝒢 = map F ℱ := Filter.map_comap_of_mem (Subtype.range_coe ▸ mem_of_superset range_mem_map subset_closure) have H' : Tendsto id 𝒢 (𝓝 ⟨f, f_mem⟩) := by rwa [tendsto_id', nhds_induced, ← map_le_iff_le_comap, h𝒢ℱ] rwa [ind.tendsto_nhds_iff, comp_id, ← tendsto_map'_iff, h𝒢ℱ] at H' /-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space, and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the uniform structures of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` induce the same uniform structure on `ι`. In particular, pointwise convergence and compact convergence coincide on an equicontinuous subset of `X → α`. Consider using `EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi'` and `EquicontinuousOn.inducing_uniformOnFun_iff_pi'` instead to avoid rewriting instances, as well as their unprimed versions in case `𝔖` covers `X`. -/ theorem EquicontinuousOn.comap_uniformOnFun_eq {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) : (UniformOnFun.uniformSpace X α 𝔖).comap F = (Pi.uniformSpace _).comap ((⋃₀ 𝔖).restrict ∘ F) := by -- Recall that the uniform structure on `X →ᵤ[𝔖] α` is the one induced by all the maps -- `K.restrict : (X →ᵤ[𝔖] α) → (K →ᵤ α)` for `K ∈ 𝔖`. Its pullback along `F`, which is -- the LHS of our goal, is thus the uniform structure induced by the maps -- `K.restrict ∘ F : ι → (K →ᵤ α)` for `K ∈ 𝔖`. have H1 : (UniformOnFun.uniformSpace X α 𝔖).comap F = ⨅ (K ∈ 𝔖), (UniformFun.uniformSpace _ _).comap (K.restrict ∘ F) := by simp_rw [UniformOnFun.uniformSpace, UniformSpace.comap_iInf, ← UniformSpace.comap_comap, UniformFun.ofFun, Equiv.coe_fn_mk, UniformOnFun.toFun, UniformOnFun.ofFun, Function.comp_def, UniformFun, Equiv.coe_fn_symm_mk] -- Now, note that a similar fact is true for the uniform structure on `X → α` induced by -- the map `(⋃₀ 𝔖).restrict : (X → α) → ((⋃₀ 𝔖) → α)`: it is equal to the one induced by -- all maps `K.restrict : (X → α) → (K → α)` for `K ∈ 𝔖`, which means that the RHS of our -- goal is the uniform structure induced by the maps `K.restrict ∘ F : ι → (K → α)` for `K ∈ 𝔖`. have H2 : (Pi.uniformSpace _).comap ((⋃₀ 𝔖).restrict ∘ F) = ⨅ (K ∈ 𝔖), (Pi.uniformSpace _).comap (K.restrict ∘ F) := by simp_rw [UniformSpace.comap_comap, Pi.uniformSpace_comap_restrict_sUnion (fun _ ↦ α) 𝔖, UniformSpace.comap_iInf] -- But, for `K ∈ 𝔖` fixed, we know that the uniform structures of `K →ᵤ α` and `K → α` -- induce, via the equicontinuous family `K.restrict ∘ F`, the same uniform structure on `ι`. have H3 : ∀ K ∈ 𝔖, (UniformFun.uniformSpace K α).comap (K.restrict ∘ F) = (Pi.uniformSpace _).comap (K.restrict ∘ F) := fun K hK ↦ by have : CompactSpace K := isCompact_iff_compactSpace.mp (𝔖_compact K hK) exact (equicontinuous_restrict_iff _ |>.mpr <| F_eqcont K hK).comap_uniformFun_eq -- Combining these three facts completes the proof. simp_rw [H1, H2, iInf_congr fun K ↦ iInf_congr fun hK ↦ H3 K hK] /-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space, and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the uniform structures of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` induce the same uniform structure on `ι`. In particular, pointwise convergence and compact convergence coincide on an equicontinuous subset of `X → α`. This is a version of `EquicontinuousOn.comap_uniformOnFun_eq` stated in terms of `IsUniformInducing` for convenience. -/ lemma EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi' [UniformSpace ι] {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) : IsUniformInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔ IsUniformInducing ((⋃₀ 𝔖).restrict ∘ F) := by rw [isUniformInducing_iff_uniformSpace, isUniformInducing_iff_uniformSpace, ← EquicontinuousOn.comap_uniformOnFun_eq 𝔖_compact F_eqcont] rfl /-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, `α` a uniform space, and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the uniform structures of uniform convergence on `𝔖` and pointwise convergence induce the same uniform structure on `ι`. This is a specialization of `EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi'` to the case where `𝔖` covers `X`. -/ lemma EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi [UniformSpace ι] {𝔖 : Set (Set X)} (𝔖_covers : ⋃₀ 𝔖 = univ) (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) : IsUniformInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔ IsUniformInducing F := by rw [eq_univ_iff_forall] at 𝔖_covers -- This obviously follows from the previous lemma, we formalize it by going through the -- isomorphism of uniform spaces between `(⋃₀ 𝔖) → α` and `X → α`. let φ : ((⋃₀ 𝔖) → α) ≃ᵤ (X → α) := UniformEquiv.piCongrLeft (β := fun _ ↦ α) (Equiv.subtypeUnivEquiv 𝔖_covers) rw [EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi' 𝔖_compact F_eqcont, show restrict (⋃₀ 𝔖) ∘ F = φ.symm ∘ F by rfl] exact ⟨fun H ↦ φ.isUniformInducing.comp H, fun H ↦ φ.symm.isUniformInducing.comp H⟩ /-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space, and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the topologies of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` induce the same topology on `ι`. In particular, pointwise convergence and compact convergence coincide on an equicontinuous subset of `X → α`. This is a consequence of `EquicontinuousOn.comap_uniformOnFun_eq` stated in terms of `IsInducing` for convenience. -/ lemma EquicontinuousOn.inducing_uniformOnFun_iff_pi' [TopologicalSpace ι] {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) : IsInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔ IsInducing ((⋃₀ 𝔖).restrict ∘ F) := by rw [isInducing_iff, isInducing_iff] change (_ = ((UniformOnFun.uniformSpace X α 𝔖).comap F).toTopologicalSpace) ↔ (_ = ((Pi.uniformSpace _).comap ((⋃₀ 𝔖).restrict ∘ F)).toTopologicalSpace) rw [← EquicontinuousOn.comap_uniformOnFun_eq 𝔖_compact F_eqcont] /-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, `α` a uniform space, and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the topologies of uniform convergence on `𝔖` and pointwise convergence induce the same topology on `ι`. This is a specialization of `EquicontinuousOn.inducing_uniformOnFun_iff_pi'` to the case where `𝔖` covers `X`. -/ lemma EquicontinuousOn.isInducing_uniformOnFun_iff_pi [TopologicalSpace ι] {𝔖 : Set (Set X)} (𝔖_covers : ⋃₀ 𝔖 = univ) (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) : IsInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔ IsInducing F := by rw [eq_univ_iff_forall] at 𝔖_covers -- This obviously follows from the previous lemma, we formalize it by going through the -- homeomorphism between `(⋃₀ 𝔖) → α` and `X → α`. let φ : ((⋃₀ 𝔖) → α) ≃ₜ (X → α) := Homeomorph.piCongrLeft (Y := fun _ ↦ α) (Equiv.subtypeUnivEquiv 𝔖_covers) rw [EquicontinuousOn.inducing_uniformOnFun_iff_pi' 𝔖_compact F_eqcont, show restrict (⋃₀ 𝔖) ∘ F = φ.symm ∘ F by rfl] exact ⟨fun H ↦ φ.isInducing.comp H, fun H ↦ φ.symm.isInducing.comp H⟩ -- TODO: find a way to factor common elements of this proof and the proof of -- `EquicontinuousOn.comap_uniformOnFun_eq` /-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space, `F : ι → (X → α)` a family equicontinuous on each `K ∈ 𝔖`, and `ℱ` a filter on `ι`. Then, `F` tends to `f : X → α` along `ℱ` *uniformly on each `K ∈ 𝔖`* iff it tends to `f` *pointwise on `⋃₀ 𝔖`* along `ℱ`. -/ theorem EquicontinuousOn.tendsto_uniformOnFun_iff_pi' {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (ℱ : Filter ι) (f : X → α) : Tendsto (UniformOnFun.ofFun 𝔖 ∘ F) ℱ (𝓝 <| UniformOnFun.ofFun 𝔖 f) ↔ Tendsto ((⋃₀ 𝔖).restrict ∘ F) ℱ (𝓝 <| (⋃₀ 𝔖).restrict f) := by -- Recall that the uniform structure on `X →ᵤ[𝔖] α` is the one induced by all the maps -- `K.restrict : (X →ᵤ[𝔖] α) → (K →ᵤ α)` for `K ∈ 𝔖`. -- Similarly, the uniform structure on `X → α` induced by the map -- `(⋃₀ 𝔖).restrict : (X → α) → ((⋃₀ 𝔖) → α)` is equal to the one induced by -- all maps `K.restrict : (X → α) → (K → α)` for `K ∈ 𝔖` -- Thus, we just have to compare the two sides of our goal when restricted to some -- `K ∈ 𝔖`, where we can apply `Equicontinuous.tendsto_uniformFun_iff_pi`. rw [← Filter.tendsto_comap_iff (g := (⋃₀ 𝔖).restrict), ← nhds_induced] simp_rw [UniformOnFun.topologicalSpace_eq, Pi.induced_restrict_sUnion 𝔖 (A := fun _ ↦ α), _root_.nhds_iInf, nhds_induced, tendsto_iInf, tendsto_comap_iff] congrm ∀ K (hK : K ∈ 𝔖), ?_ have : CompactSpace K := isCompact_iff_compactSpace.mp (𝔖_compact K hK) rw [← (equicontinuous_restrict_iff _ |>.mpr <| F_eqcont K hK).tendsto_uniformFun_iff_pi] rfl /-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, `α` a uniform space, `F : ι → (X → α)` a family equicontinuous on each `K ∈ 𝔖`, and `ℱ` a filter on `ι`. Then, `F` tends to `f : X → α` along `ℱ` *uniformly on each `K ∈ 𝔖`* iff it tends to `f` *pointwise* along `ℱ`. This is a specialization of `EquicontinuousOn.tendsto_uniformOnFun_iff_pi'` to the case where `𝔖` covers `X`. -/ theorem EquicontinuousOn.tendsto_uniformOnFun_iff_pi {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (𝔖_covers : ⋃₀ 𝔖 = univ) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (ℱ : Filter ι) (f : X → α) : Tendsto (UniformOnFun.ofFun 𝔖 ∘ F) ℱ (𝓝 <| UniformOnFun.ofFun 𝔖 f) ↔ Tendsto F ℱ (𝓝 f) := by rw [eq_univ_iff_forall] at 𝔖_covers let φ : ((⋃₀ 𝔖) → α) ≃ₜ (X → α) := Homeomorph.piCongrLeft (Y := fun _ ↦ α) (Equiv.subtypeUnivEquiv 𝔖_covers) rw [EquicontinuousOn.tendsto_uniformOnFun_iff_pi' 𝔖_compact F_eqcont, show restrict (⋃₀ 𝔖) ∘ F = φ.symm ∘ F by rfl, show restrict (⋃₀ 𝔖) f = φ.symm f by rfl, φ.symm.isInducing.tendsto_nhds_iff] /-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X` and `α` a uniform space. An equicontinuous subset of `X → α` is closed in the topology of uniform convergence on all `K ∈ 𝔖` iff it is closed in the topology of pointwise convergence on `⋃₀ 𝔖`. -/ theorem EquicontinuousOn.isClosed_range_pi_of_uniformOnFun' {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (H : IsClosed (range <| UniformOnFun.ofFun 𝔖 ∘ F)) : IsClosed (range <| (⋃₀ 𝔖).restrict ∘ F) := by -- Do we have no equivalent of `nontriviality`? rcases isEmpty_or_nonempty α with _ | _ · simp [isClosed_discrete] -- This follows from the previous lemmas and the characterization of the closure using filters. simp_rw [isClosed_iff_clusterPt, ← Filter.map_top, ← mapClusterPt_def, mapClusterPt_iff_ultrafilter, range_comp, Subtype.coe_injective.surjective_comp_right.forall, ← restrict_eq, ← EquicontinuousOn.tendsto_uniformOnFun_iff_pi' 𝔖_compact F_eqcont] exact fun f ⟨u, _, hu⟩ ↦ mem_image_of_mem _ <| H.mem_of_tendsto hu <| Eventually.of_forall mem_range_self /-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, and `α` a uniform space. An equicontinuous subset of `X → α` is closed in the topology of uniform convergence on all `K ∈ 𝔖` iff it is closed in the topology of pointwise convergence. This is a specialization of `EquicontinuousOn.isClosed_range_pi_of_uniformOnFun'` to the case where `𝔖` covers `X`. -/ theorem EquicontinuousOn.isClosed_range_uniformOnFun_iff_pi {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (𝔖_covers : ⋃₀ 𝔖 = univ) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) : IsClosed (range <| UniformOnFun.ofFun 𝔖 ∘ F) ↔ IsClosed (range F) := by -- This follows from the previous lemmas and the characterization of the closure using filters. simp_rw [isClosed_iff_clusterPt, ← Filter.map_top, ← mapClusterPt_def, mapClusterPt_iff_ultrafilter, range_comp, (UniformOnFun.ofFun 𝔖).surjective.forall, ← EquicontinuousOn.tendsto_uniformOnFun_iff_pi 𝔖_compact 𝔖_covers F_eqcont, (UniformOnFun.ofFun 𝔖).injective.mem_set_image] alias ⟨EquicontinuousOn.isClosed_range_pi_of_uniformOnFun, _⟩ := EquicontinuousOn.isClosed_range_uniformOnFun_iff_pi /-- A version of the **Arzela-Ascoli theorem**. Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space, and `F : ι → (X → α)`. Assume that: * `F`, viewed as a function `ι → (X →ᵤ[𝔖] α)`, is closed and inducing * `F` is equicontinuous on each `K ∈ 𝔖` * For all `x ∈ ⋃₀ 𝔖`, the range of `i ↦ F i x` is contained in some fixed compact subset. Then `ι` is compact. -/ theorem ArzelaAscoli.compactSpace_of_closed_inducing' [TopologicalSpace ι] {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_ind : IsInducing (UniformOnFun.ofFun 𝔖 ∘ F)) (F_cl : IsClosed <| range <| UniformOnFun.ofFun 𝔖 ∘ F) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (F_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i, F i x ∈ Q) : CompactSpace ι := by -- By equicontinuity, we know that the topology on `ι` is also the one induced by -- `restrict (⋃₀ 𝔖) ∘ F`. have : IsInducing (restrict (⋃₀ 𝔖) ∘ F) := by rwa [EquicontinuousOn.inducing_uniformOnFun_iff_pi' 𝔖_compact F_eqcont] at F_ind -- Thus, we just have to check that the range of this map is compact. rw [← isCompact_univ_iff, this.isCompact_iff, image_univ] -- But then we are working in a product space, where compactness can easily be proven using -- Tykhonov's theorem! More precisely, for each `x ∈ ⋃₀ 𝔖`, choose a compact set `Q x` -- containing all `F i x`s. rw [← forall_sUnion] at F_pointwiseCompact choose! Q Q_compact F_in_Q using F_pointwiseCompact -- Notice that, since the range of `F` is closed in `X →ᵤ[𝔖] α`, equicontinuity ensures that -- the range of `(⋃₀ 𝔖).restrict ∘ F` is still closed in the product topology. -- But it's contained in the product of the `Q x`s, which is compact by Tykhonov, hence -- it is compact as well. refine IsCompact.of_isClosed_subset (isCompact_univ_pi fun x ↦ Q_compact x x.2) (EquicontinuousOn.isClosed_range_pi_of_uniformOnFun' 𝔖_compact F_eqcont F_cl) (range_subset_iff.mpr fun i x _ ↦ F_in_Q x x.2 i) /-- A version of the **Arzela-Ascoli theorem**. Let `X, ι` be topological spaces, `𝔖` a covering of `X` by compact subsets, `α` a uniform space, and `F : ι → (X → α)`. Assume that: * `F`, viewed as a function `ι → (X →ᵤ[𝔖] α)`, is a closed embedding (in other words, `ι` identifies to a closed subset of `X →ᵤ[𝔖] α` through `F`) * `F` is equicontinuous on each `K ∈ 𝔖` * For all `x`, the range of `i ↦ F i x` is contained in some fixed compact subset. Then `ι` is compact. -/ theorem ArzelaAscoli.compactSpace_of_isClosedEmbedding [TopologicalSpace ι] {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_clemb : IsClosedEmbedding (UniformOnFun.ofFun 𝔖 ∘ F)) (F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (F_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i, F i x ∈ Q) : CompactSpace ι := compactSpace_of_closed_inducing' 𝔖_compact F_clemb.isInducing F_clemb.isClosed_range F_eqcont F_pointwiseCompact /-- A version of the **Arzela-Ascoli theorem**. Let `X, ι` be topological spaces, `𝔖` a covering of `X` by compact subsets, `α` a T2 uniform space, `F : ι → (X → α)`, and `s` a subset of `ι`. Assume that: * `F`, viewed as a function `ι → (X →ᵤ[𝔖] α)`, is a closed embedding (in other words, `ι` identifies to a closed subset of `X →ᵤ[𝔖] α` through `F`) * `F '' s` is equicontinuous on each `K ∈ 𝔖` * For all `x ∈ ⋃₀ 𝔖`, the image of `s` under `i ↦ F i x` is contained in some fixed compact subset. Then `s` has compact closure in `ι`. -/ theorem ArzelaAscoli.isCompact_closure_of_isClosedEmbedding [TopologicalSpace ι] [T2Space α] {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_clemb : IsClosedEmbedding (UniformOnFun.ofFun 𝔖 ∘ F)) {s : Set ι} (s_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn (F ∘ ((↑) : s → ι)) K) (s_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i ∈ s, F i x ∈ Q) : IsCompact (closure s) := by -- We apply `ArzelaAscoli.compactSpace_of_isClosedEmbedding` to the map -- `F ∘ (↑) : closure s → (X → α)`, for which all the hypotheses are easily verified. rw [isCompact_iff_compactSpace] have : ∀ K ∈ 𝔖, ∀ x ∈ K, Continuous (eval x ∘ F) := fun K hK x hx ↦ UniformOnFun.uniformContinuous_eval_of_mem _ _ hx hK |>.continuous.comp F_clemb.continuous have cls_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn (F ∘ ((↑) : closure s → ι)) K := fun K hK ↦ (s_eqcont K hK).closure' <| show Continuous (K.restrict ∘ F) from continuous_pi fun ⟨x, hx⟩ ↦ this K hK x hx have cls_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i ∈ closure s, F i x ∈ Q := fun K hK x hx ↦ (s_pointwiseCompact K hK x hx).imp fun Q hQ ↦ ⟨hQ.1, closure_minimal hQ.2 <| hQ.1.isClosed.preimage (this K hK x hx)⟩ exact ArzelaAscoli.compactSpace_of_isClosedEmbedding 𝔖_compact (F_clemb.comp isClosed_closure.isClosedEmbedding_subtypeVal) cls_eqcont fun K hK x hx ↦ (cls_pointwiseCompact K hK x hx).imp fun Q hQ ↦ ⟨hQ.1, by simpa using hQ.2⟩ /-- A version of the **Arzela-Ascoli theorem**. If an equicontinuous family of continuous functions is compact in the pointwise topology, then it is compact in the compact open topology. -/ theorem ArzelaAscoli.isCompact_of_equicontinuous (S : Set C(X, α)) (hS1 : IsCompact (ContinuousMap.toFun '' S)) (hS2 : Equicontinuous ((↑) : S → X → α)) : IsCompact S := by suffices h : IsInducing (Equiv.Set.image _ S DFunLike.coe_injective) by rw [isCompact_iff_compactSpace] at hS1 ⊢ exact (Equiv.toHomeomorphOfIsInducing _ h).symm.compactSpace rw [← IsInducing.subtypeVal.of_comp_iff, ← EquicontinuousOn.isInducing_uniformOnFun_iff_pi _ _ _] · exact ContinuousMap.isUniformEmbedding_toUniformOnFunIsCompact.isInducing.comp .subtypeVal · exact eq_univ_iff_forall.mpr (fun x ↦ mem_sUnion_of_mem (mem_singleton x) isCompact_singleton) · exact fun _ ↦ id · exact fun K _ ↦ hS2.equicontinuousOn K
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Cauchy.lean
import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Algebra.Order.Group.Nat import Mathlib.Topology.UniformSpace.DiscreteUniformity /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity open scoped SetRel variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter α) := NeBot f ∧ f ×ˢ f ≤ 𝓤 α /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set α) := ∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → SetRel α α} (h : (𝓤 α).HasBasis p s) {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] theorem cauchy_iff' {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s := (𝓤 α).basis_sets.cauchy_iff theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, forall_mem_comm] lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] : Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ theorem cauchy_map_iff {l : Filter β} {f : β → α} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} : Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := cauchy_map_iff.trans <| and_iff_right hl theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g := h_c.mono h_le theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ theorem cauchy_pure {a : α} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} : Cauchy (uniformSpace := u ⊓ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β} {l : Filter β} : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β} {l : Filter β} [l.NeBot] : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace β} {α} {f : α → β} {l : Filter α} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f ×ˢ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact fun z hz => hU (SetRel.prodMk_mem_comp hxy (ht <| mk_mem_prod hy hz)) rfl /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) : f ≤ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq _ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right _ ≤ 𝓤 β := hm⟩ nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] : Cauchy (comap m f) := ⟨‹_›, calc comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq _ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right _ ≤ 𝓤 α := hm⟩ theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder β] (u : β → α) := Cauchy (atTop.map u) theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓤 α) := by simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β := @nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1 theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u) {V : SetRel α α} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by haveI := h.nonempty have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x} (hx : Tendsto f atTop (𝓝 x)) : CauchySeq f := hx.cauchy_map theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x := tendsto_const_nhds.cauchySeq theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) := cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def] theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α} (hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) := ⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩ theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α} (hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) := hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) : CauchySeq (u ∘ f) ↔ CauchySeq u := by refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩ lift f to ℕ ≃ ℕ using hf simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective theorem CauchySeq.subseq_subseq_mem {V : ℕ → SetRel α α} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by rw [cauchySeq_iff_tendsto] at hu exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV -- todo: generalize this and other lemmas to a nonempty semilattice theorem cauchySeq_iff' {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V := cauchySeq_iff_tendsto theorem cauchySeq_iff {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply] theorem CauchySeq.prodMap {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv theorem CauchySeq.prodMk {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) := haveI := hu.1.of_map (Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map) theorem CauchySeq.eventually_eventually [Preorder β] {u : β → α} (hu : CauchySeq u) {V : SetRel α α} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V := eventually_atTop_curry <| hu.tendsto_uniformity hV theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β} (hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) := hu.map hf theorem CauchySeq.subseq_mem {V : ℕ → SetRel α α} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by rw [cauchySeq_iff] at hu rcases hu _ (hV n) with ⟨N, H⟩ exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩ obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ := extraction_forall_of_eventually' this exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| Nat.lt_add_one n).le⟩ theorem Filter.Tendsto.subseq_mem_entourage {V : ℕ → SetRel α α} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} {a : α} (hu : Tendsto u atTop (𝓝 a)) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (u (φ 0), a) ∈ V 0 ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V (n + 1) := by rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩ rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with ⟨φ, φ_mono, hφV⟩ exact ⟨fun k => φ k + n, φ_mono.add_const _, hn _ le_add_self, hφV⟩ /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder β] {u : β → α} (hu : CauchySeq u) {ι : Type*} {f : ι → β} {p : Filter ι} [NeBot p] (hf : Tendsto f p atTop) {a : α} (ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) := le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf) /-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/ theorem cauchySeq_shift {u : ℕ → α} (k : ℕ) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by constructor <;> intro h · rw [cauchySeq_iff] at h ⊢ intro V mV obtain ⟨N, h⟩ := h V mV use N + k intro a ha b hb convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega · exact h.comp_tendsto (tendsto_add_atTop_nat k) theorem Filter.HasBasis.cauchySeq_iff {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → SetRel α α} (h : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → (u m, u n) ∈ s i := by rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq] refine (atTop_basis.prod_self.tendsto_iff h).trans ?_ simp only [true_and, Prod.forall, mem_prod_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≤ _) β] theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → SetRel α α} (H : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ n ≥ N, (u n, u N) ∈ s i := by refine H.cauchySeq_iff.trans ⟨fun h i hi => ?_, fun h i hi => ?_⟩ · exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl · rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩ rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩ refine (h j hj).imp fun N hN m hm n hn => hts ⟨u N, hjt ?_, ht' <| hjt ?_⟩ exacts [hN m hm, hN n hn] theorem cauchySeq_of_controlled [SemilatticeSup β] [Nonempty β] (U : β → SetRel α α) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) {f : β → α} (hf : ∀ ⦃N m n : β⦄, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : CauchySeq f := cauchySeq_iff_tendsto.2 (by intro s hs rw [mem_map, mem_atTop_sets] obtain ⟨N, hN⟩ := hU s hs refine ⟨(N, N), fun mn hmn => ?_⟩ obtain ⟨m, n⟩ := mn exact hN (hf hmn.1 hmn.2)) theorem isComplete_iff_clusterPt {s : Set α} : IsComplete s ↔ ∀ l, Cauchy l → l ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x l := forall₃_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ => le_nhds_iff_adhp_of_cauchy hl theorem isComplete_iff_ultrafilter {s : Set α} : IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ↑l ≤ 𝓟 s → ∃ x ∈ s, ↑l ≤ 𝓝 x := by refine ⟨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_⟩ haveI := hl.1 rcases H (Ultrafilter.of l) hl.ultrafilter_of ((Ultrafilter.of_le l).trans hls) with ⟨x, hxs, hxl⟩ exact ⟨x, hxs, (ClusterPt.of_le_nhds hxl).mono (Ultrafilter.of_le l)⟩ theorem isComplete_iff_ultrafilter' {s : Set α} : IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → s ∈ l → ∃ x ∈ s, ↑l ≤ 𝓝 x := isComplete_iff_ultrafilter.trans <| by simp only [le_principal_iff, Ultrafilter.mem_coe] protected theorem IsComplete.union {s t : Set α} (hs : IsComplete s) (ht : IsComplete t) : IsComplete (s ∪ t) := by simp only [isComplete_iff_ultrafilter', Ultrafilter.union_mem_iff, or_imp] at * exact fun l hl => ⟨fun hsl => (hs l hl hsl).imp fun x hx => ⟨Or.inl hx.1, hx.2⟩, fun htl => (ht l hl htl).imp fun x hx => ⟨Or.inr hx.1, hx.2⟩⟩ theorem isComplete_iUnion_separated {ι : Sort*} {s : ι → Set α} (hs : ∀ i, IsComplete (s i)) {U : SetRel α α} (hU : U ∈ 𝓤 α) (hd : ∀ (i j : ι), ∀ x ∈ s i, ∀ y ∈ s j, (x, y) ∈ U → i = j) : IsComplete (⋃ i, s i) := by set S := ⋃ i, s i intro l hl hls rw [le_principal_iff] at hls obtain ⟨hl_ne, hl'⟩ := cauchy_iff.1 hl obtain ⟨t, htS, htl, htU⟩ : ∃ t, t ⊆ S ∧ t ∈ l ∧ t ×ˢ t ⊆ U := by rcases hl' U hU with ⟨t, htl, htU⟩ refine ⟨t ∩ S, inter_subset_right, inter_mem htl hls, Subset.trans ?_ htU⟩ gcongr <;> apply inter_subset_left obtain ⟨i, hi⟩ : ∃ i, t ⊆ s i := by rcases Filter.nonempty_of_mem htl with ⟨x, hx⟩ rcases mem_iUnion.1 (htS hx) with ⟨i, hi⟩ refine ⟨i, fun y hy => ?_⟩ rcases mem_iUnion.1 (htS hy) with ⟨j, hj⟩ rwa [hd i j x hi y hj (htU <| mk_mem_prod hx hy)] rcases hs i l hl (le_principal_iff.2 <| mem_of_superset htl hi) with ⟨x, hxs, hlx⟩ exact ⟨x, mem_iUnion.2 ⟨i, hxs⟩, hlx⟩ /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class CompleteSpace (α : Type u) [UniformSpace α] : Prop where /-- In a complete uniform space, every Cauchy filter converges. -/ complete : ∀ {f : Filter α}, Cauchy f → ∃ x, f ≤ 𝓝 x theorem complete_univ {α : Type u} [UniformSpace α] [CompleteSpace α] : IsComplete (univ : Set α) := fun f hf _ => by rcases CompleteSpace.complete hf with ⟨x, hx⟩ exact ⟨x, mem_univ x, hx⟩ instance CompleteSpace.prod [UniformSpace β] [CompleteSpace α] [CompleteSpace β] : CompleteSpace (α × β) where complete hf := let ⟨x1, hx1⟩ := CompleteSpace.complete <| hf.map uniformContinuous_fst let ⟨x2, hx2⟩ := CompleteSpace.complete <| hf.map uniformContinuous_snd ⟨(x1, x2), by rw [nhds_prod_eq, le_prod]; constructor <;> assumption⟩ lemma CompleteSpace.fst_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty β] : CompleteSpace α where complete hf := let ⟨y⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| hf.prod <| cauchy_pure (a := y) ⟨a, by simpa only [map_fst_prod, nhds_prod_eq] using map_mono (m := Prod.fst) hab⟩ lemma CompleteSpace.snd_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty α] : CompleteSpace β where complete hf := let ⟨x⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| (cauchy_pure (a := x)).prod hf ⟨b, by simpa only [map_snd_prod, nhds_prod_eq] using map_mono (m := Prod.snd) hab⟩ lemma completeSpace_prod_of_nonempty [UniformSpace β] [Nonempty α] [Nonempty β] : CompleteSpace (α × β) ↔ CompleteSpace α ∧ CompleteSpace β := ⟨fun _ ↦ ⟨.fst_of_prod (β := β), .snd_of_prod (α := α)⟩, fun ⟨_, _⟩ ↦ .prod⟩ @[to_additive] instance CompleteSpace.mulOpposite [CompleteSpace α] : CompleteSpace αᵐᵒᵖ where complete hf := MulOpposite.op_surjective.exists.mpr <| let ⟨x, hx⟩ := CompleteSpace.complete (hf.map MulOpposite.uniformContinuous_unop) ⟨x, (map_le_iff_le_comap.mp hx).trans_eq <| MulOpposite.comap_unop_nhds _⟩ /-- If `univ` is complete, the space is a complete space -/ theorem completeSpace_of_isComplete_univ (h : IsComplete (univ : Set α)) : CompleteSpace α := ⟨fun hf => let ⟨x, _, hx⟩ := h _ hf ((@principal_univ α).symm ▸ le_top); ⟨x, hx⟩⟩ theorem completeSpace_iff_isComplete_univ : CompleteSpace α ↔ IsComplete (univ : Set α) := ⟨@complete_univ α _, completeSpace_of_isComplete_univ⟩ theorem completeSpace_iff_ultrafilter : CompleteSpace α ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ∃ x : α, ↑l ≤ 𝓝 x := by simp [completeSpace_iff_isComplete_univ, isComplete_iff_ultrafilter] theorem cauchy_iff_exists_le_nhds [CompleteSpace α] {l : Filter α} [NeBot l] : Cauchy l ↔ ∃ x, l ≤ 𝓝 x := ⟨CompleteSpace.complete, fun ⟨_, hx⟩ => cauchy_nhds.mono hx⟩ theorem cauchy_map_iff_exists_tendsto [CompleteSpace α] {l : Filter β} {f : β → α} [NeBot l] : Cauchy (l.map f) ↔ ∃ x, Tendsto f l (𝓝 x) := cauchy_iff_exists_le_nhds /-- A Cauchy sequence in a complete space converges -/ theorem cauchySeq_tendsto_of_complete [Preorder β] [CompleteSpace α] {u : β → α} (H : CauchySeq u) : ∃ x, Tendsto u atTop (𝓝 x) := CompleteSpace.complete H /-- If `K` is a complete subset, then any Cauchy sequence in `K` converges to a point in `K` -/ theorem cauchySeq_tendsto_of_isComplete [Preorder β] {K : Set α} (h₁ : IsComplete K) {u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : CauchySeq u) : ∃ v ∈ K, Tendsto u atTop (𝓝 v) := h₁ _ h₃ <| le_principal_iff.2 <| mem_map_iff_exists_image.2 ⟨univ, univ_mem, by rwa [image_univ, range_subset_iff]⟩ theorem Cauchy.le_nhds_lim [CompleteSpace α] {f : Filter α} (hf : Cauchy f) : haveI := hf.1.nonempty; f ≤ 𝓝 (lim f) := _root_.le_nhds_lim (CompleteSpace.complete hf) theorem CauchySeq.tendsto_limUnder [Preorder β] [CompleteSpace α] {u : β → α} (h : CauchySeq u) : haveI := h.1.nonempty; Tendsto u atTop (𝓝 <| limUnder atTop u) := h.le_nhds_lim theorem IsClosed.isComplete [CompleteSpace α] {s : Set α} (h : IsClosed s) : IsComplete s := fun _ cf fs => let ⟨x, hx⟩ := CompleteSpace.complete cf ⟨x, isClosed_iff_clusterPt.mp h x (cf.left.mono (le_inf hx fs)), hx⟩ namespace DiscreteUniformity variable [DiscreteUniformity α] /-- A Cauchy filter in a discrete uniform space is contained in the principal filter of a point. -/ theorem eq_pure_of_cauchy {f : Filter α} (hf : Cauchy f) : ∃ x : α, f = pure x := by rcases hf with ⟨f_ne_bot, f_le⟩ simp only [DiscreteUniformity.eq_principal_relId, le_principal_iff, mem_prod_iff] at f_le obtain ⟨S, hS, T, hT, H⟩ := f_le obtain ⟨x, rfl, _, _, _⟩ := SetRel.exists_eq_singleton_of_prod_subset_id (f_ne_bot.nonempty_of_mem hS) (f_ne_bot.nonempty_of_mem hT) H exact ⟨x, f_ne_bot.le_pure_iff.mp <| le_pure_iff.mpr hS⟩ /-- The discrete uniformity makes a space complete. -/ instance : CompleteSpace α where complete {f} hf := by obtain ⟨x, rfl⟩ := eq_pure_of_cauchy hf exact ⟨x, pure_le_nhds x⟩ variable {X} /-- A constant to which a Cauchy filter in a discrete uniform space converges. -/ noncomputable def cauchyConst {f : Filter α} (hf : Cauchy f) : α := (eq_pure_of_cauchy hf).choose theorem eq_pure_cauchyConst {f : Filter α} (hf : Cauchy f) : f = pure (cauchyConst hf) := (eq_pure_of_cauchy hf).choose_spec end DiscreteUniformity /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def TotallyBounded (s : Set α) : Prop := ∀ d ∈ 𝓤 α, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d } theorem TotallyBounded.exists_subset {s : Set α} (hs : TotallyBounded s) {U : SetRel α α} (hU : U ∈ 𝓤 α) : ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U } := by rcases comp_symm_of_uniformity hU with ⟨r, hr, rs, rU⟩ rcases hs r hr with ⟨k, fk, ks⟩ let u := k ∩ { y | ∃ x ∈ s, (x, y) ∈ r } choose f hfs hfr using fun x : u => x.coe_prop.2 refine ⟨range f, ?_, ?_, ?_⟩ · exact range_subset_iff.2 hfs · haveI : Fintype u := (fk.inter_of_left _).fintype exact finite_range f · intro x xs obtain ⟨y, hy, xy⟩ := mem_iUnion₂.1 (ks xs) rw [biUnion_range, mem_iUnion] set z : ↥u := ⟨y, hy, ⟨x, xs, xy⟩⟩ exact ⟨z, rU ⟨y, xy, rs (hfr z)⟩⟩ theorem totallyBounded_iff_subset {s : Set α} : TotallyBounded s ↔ ∀ d ∈ 𝓤 α, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d } := ⟨fun H _ hd ↦ H.exists_subset hd, fun H d hd ↦ let ⟨t, _, ht⟩ := H d hd; ⟨t, ht⟩⟩ theorem Filter.HasBasis.totallyBounded_iff {ι} {p : ι → Prop} {U : ι → SetRel α α} (H : (𝓤 α).HasBasis p U) {s : Set α} : TotallyBounded s ↔ ∀ i, p i → ∃ t : Set α, Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U i } := H.forall_iff fun _ _ hUV h => h.imp fun _ ht => ⟨ht.1, ht.2.trans <| iUnion₂_mono fun _ _ _ hy => hUV hy⟩ theorem totallyBounded_of_forall_isSymm {s : Set α} (h : ∀ V ∈ 𝓤 α, SetRel.IsSymm V → ∃ t : Set α, Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y V) : TotallyBounded s := UniformSpace.hasBasis_symmetric.totallyBounded_iff.2 fun V ⟨_, _⟩ => by simpa only [ball_eq_of_symmetry] using h V ‹_› ‹_› theorem TotallyBounded.subset {s₁ s₂ : Set α} (hs : s₁ ⊆ s₂) (h : TotallyBounded s₂) : TotallyBounded s₁ := fun d hd => let ⟨t, ht₁, ht₂⟩ := h d hd ⟨t, ht₁, Subset.trans hs ht₂⟩ /-- The closure of a totally bounded set is totally bounded. -/ theorem TotallyBounded.closure {s : Set α} (h : TotallyBounded s) : TotallyBounded (closure s) := uniformity_hasBasis_closed.totallyBounded_iff.2 fun V hV => let ⟨t, htf, hst⟩ := h V hV.1 ⟨t, htf, closure_minimal hst <| htf.isClosed_biUnion fun _ _ => hV.2.preimage (.prodMk_left _)⟩ @[simp] lemma totallyBounded_closure {s : Set α} : TotallyBounded (closure s) ↔ TotallyBounded s := ⟨fun h ↦ h.subset subset_closure, TotallyBounded.closure⟩ /-- A finite indexed union is totally bounded if and only if each set of the family is totally bounded. -/ @[simp] lemma totallyBounded_iUnion {ι : Sort*} [Finite ι] {s : ι → Set α} : TotallyBounded (⋃ i, s i) ↔ ∀ i, TotallyBounded (s i) := by refine ⟨fun h i ↦ h.subset (subset_iUnion _ _), fun h U hU ↦ ?_⟩ choose t htf ht using (h · U hU) refine ⟨⋃ i, t i, finite_iUnion htf, ?_⟩ rw [biUnion_iUnion] gcongr; apply ht /-- A union indexed by a finite set is totally bounded if and only if each set of the family is totally bounded. -/ lemma totallyBounded_biUnion {ι : Type*} {I : Set ι} (hI : I.Finite) {s : ι → Set α} : TotallyBounded (⋃ i ∈ I, s i) ↔ ∀ i ∈ I, TotallyBounded (s i) := by have := hI.to_subtype rw [biUnion_eq_iUnion, totallyBounded_iUnion, Subtype.forall] /-- A union of a finite family of sets is totally bounded if and only if each set of the family is totally bounded. -/ lemma totallyBounded_sUnion {S : Set (Set α)} (hS : S.Finite) : TotallyBounded (⋃₀ S) ↔ ∀ s ∈ S, TotallyBounded s := by rw [sUnion_eq_biUnion, totallyBounded_biUnion hS] /-- A finite set is totally bounded. -/ lemma Set.Finite.totallyBounded {s : Set α} (hs : s.Finite) : TotallyBounded s := fun _U hU ↦ ⟨s, hs, fun _x hx ↦ mem_biUnion hx <| refl_mem_uniformity hU⟩ /-- A subsingleton is totally bounded. -/ lemma Set.Subsingleton.totallyBounded {s : Set α} (hs : s.Subsingleton) : TotallyBounded s := hs.finite.totallyBounded @[simp] lemma totallyBounded_singleton (a : α) : TotallyBounded {a} := (finite_singleton a).totallyBounded @[simp] theorem totallyBounded_empty : TotallyBounded (∅ : Set α) := finite_empty.totallyBounded /-- The union of two sets is totally bounded if and only if each of the two sets is totally bounded. -/ @[simp] lemma totallyBounded_union {s t : Set α} : TotallyBounded (s ∪ t) ↔ TotallyBounded s ∧ TotallyBounded t := by rw [union_eq_iUnion, totallyBounded_iUnion] simp [and_comm] /-- The union of two totally bounded sets is totally bounded. -/ protected lemma TotallyBounded.union {s t : Set α} (hs : TotallyBounded s) (ht : TotallyBounded t) : TotallyBounded (s ∪ t) := totallyBounded_union.2 ⟨hs, ht⟩ @[simp] lemma totallyBounded_insert (a : α) {s : Set α} : TotallyBounded (insert a s) ↔ TotallyBounded s := by simp_rw [← singleton_union, totallyBounded_union, totallyBounded_singleton, true_and] protected alias ⟨_, TotallyBounded.insert⟩ := totallyBounded_insert /-- The image of a totally bounded set under a uniformly continuous map is totally bounded. -/ theorem TotallyBounded.image [UniformSpace β] {f : α → β} {s : Set α} (hs : TotallyBounded s) (hf : UniformContinuous f) : TotallyBounded (f '' s) := fun t ht => have : { p : α × α | (f p.1, f p.2) ∈ t } ∈ 𝓤 α := hf ht let ⟨c, hfc, hct⟩ := hs _ this ⟨f '' c, hfc.image f, by simp only [mem_image, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, image_subset_iff, preimage_iUnion, preimage_setOf_eq] have hct : ∀ x ∈ s, ∃ i ∈ c, (f x, f i) ∈ t := by simpa [subset_def] using hct intro x hx simpa using hct x hx⟩ theorem Ultrafilter.cauchy_of_totallyBounded {s : Set α} (f : Ultrafilter α) (hs : TotallyBounded s) (h : ↑f ≤ 𝓟 s) : Cauchy (f : Filter α) := ⟨f.neBot', fun _ ht => let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht let ⟨i, hi, hs_union⟩ := hs t' ht'₁ have : (⋃ y ∈ i, { x | (x, y) ∈ t' }) ∈ f := mem_of_superset (le_principal_iff.mp h) hs_union have : ∃ y ∈ i, { x | (x, y) ∈ t' } ∈ f := (Ultrafilter.finite_biUnion_mem_iff hi).1 this let ⟨y, _, hif⟩ := this have : {x | (x, y) ∈ t'} ×ˢ {x | (x, y) ∈ t'} ⊆ t' ○ t' := fun ⟨_, _⟩ ⟨(h₁ : (_, y) ∈ t'), (h₂ : (_, y) ∈ t')⟩ => ⟨y, h₁, ht'_symm h₂⟩ mem_of_superset (prod_mem_prod hif hif) (Subset.trans this ht'_t)⟩ theorem totallyBounded_iff_filter {s : Set α} : TotallyBounded s ↔ ∀ f, NeBot f → f ≤ 𝓟 s → ∃ c ≤ f, Cauchy c := by constructor · exact fun H f hf hfs => ⟨Ultrafilter.of f, Ultrafilter.of_le f, (Ultrafilter.of f).cauchy_of_totallyBounded H ((Ultrafilter.of_le f).trans hfs)⟩ · intro H d hd contrapose! H with hd_cover set f := ⨅ t : Finset α, 𝓟 (s \ ⋃ y ∈ t, { x | (x, y) ∈ d }) have hb : HasAntitoneBasis f fun t : Finset α ↦ s \ ⋃ y ∈ t, { x | (x, y) ∈ d } := .iInf_principal fun _ _ ↦ diff_subset_diff_right ∘ biUnion_subset_biUnion_left have : Filter.NeBot f := hb.1.neBot_iff.2 fun _ ↦ diff_nonempty.2 <| hd_cover _ (Finset.finite_toSet _) have : f ≤ 𝓟 s := iInf_le_of_le ∅ (by simp) refine ⟨f, ‹_›, ‹_›, fun c hcf hc => ?_⟩ rcases mem_prod_same_iff.1 (hc.2 hd) with ⟨m, hm, hmd⟩ rcases hc.1.nonempty_of_mem hm with ⟨y, hym⟩ have : s \ {x | (x, y) ∈ d} ∈ c := by simpa using hcf (hb.mem {y}) rcases hc.1.nonempty_of_mem (inter_mem hm this) with ⟨z, hzm, -, hyz⟩ exact hyz (hmd ⟨hzm, hym⟩) theorem totallyBounded_iff_ultrafilter {s : Set α} : TotallyBounded s ↔ ∀ f : Ultrafilter α, ↑f ≤ 𝓟 s → Cauchy (f : Filter α) := by refine ⟨fun hs f => f.cauchy_of_totallyBounded hs, fun H => totallyBounded_iff_filter.2 ?_⟩ intro f hf hfs exact ⟨Ultrafilter.of f, Ultrafilter.of_le f, H _ ((Ultrafilter.of_le f).trans hfs)⟩ theorem isCompact_iff_totallyBounded_isComplete {s : Set α} : IsCompact s ↔ TotallyBounded s ∧ IsComplete s := ⟨fun hs => ⟨totallyBounded_iff_ultrafilter.2 fun f hf => let ⟨_, _, fx⟩ := isCompact_iff_ultrafilter_le_nhds.1 hs f hf cauchy_nhds.mono fx, fun f fc fs => let ⟨a, as, fa⟩ := @hs f fc.1 fs ⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩, fun ⟨ht, hc⟩ => isCompact_iff_ultrafilter_le_nhds.2 fun f hf => hc _ (totallyBounded_iff_ultrafilter.1 ht f hf) hf⟩ protected theorem IsCompact.totallyBounded {s : Set α} (h : IsCompact s) : TotallyBounded s := (isCompact_iff_totallyBounded_isComplete.1 h).1 protected theorem IsCompact.isComplete {s : Set α} (h : IsCompact s) : IsComplete s := (isCompact_iff_totallyBounded_isComplete.1 h).2 -- see Note [lower instance priority] instance (priority := 100) complete_of_compact {α : Type u} [UniformSpace α] [CompactSpace α] : CompleteSpace α := ⟨fun hf => by simpa using (isCompact_iff_totallyBounded_isComplete.1 isCompact_univ).2 _ hf⟩ theorem TotallyBounded.isCompact_of_isComplete {s : Set α} (ht : TotallyBounded s) (hc : IsComplete s) : IsCompact s := isCompact_iff_totallyBounded_isComplete.mpr ⟨ht, hc⟩ theorem TotallyBounded.isCompact_of_isClosed [CompleteSpace α] {s : Set α} (ht : TotallyBounded s) (hc : IsClosed s) : IsCompact s := ht.isCompact_of_isComplete hc.isComplete @[deprecated (since := "2025-08-30")] alias isCompact_of_totallyBounded_isClosed := TotallyBounded.isCompact_of_isClosed /-- Every Cauchy sequence over `ℕ` is totally bounded. -/ theorem CauchySeq.totallyBounded_range {s : ℕ → α} (hs : CauchySeq s) : TotallyBounded (range s) := by intro a ha obtain ⟨n, hn⟩ := cauchySeq_iff.1 hs a ha refine ⟨s '' { k | k ≤ n }, (finite_le_nat _).image _, ?_⟩ rw [range_subset_iff, biUnion_image] intro m rw [mem_iUnion₂] rcases le_total m n with hm | hm exacts [⟨m, hm, refl_mem_uniformity ha⟩, ⟨n, le_refl n, hn m hm n le_rfl⟩] /-- Given a family of points `xs n`, a family of entourages `V n` of the diagonal and a family of natural numbers `u n`, the intersection over `n` of the `V n`-neighborhood of `xs 1, ..., xs (u n)`. Designed to be relatively compact when `V n` tends to the diagonal. -/ def interUnionBalls (xs : ℕ → α) (u : ℕ → ℕ) (V : ℕ → SetRel α α) : Set α := ⋂ n, ⋃ m ≤ u n, UniformSpace.ball (xs m) (Prod.swap ⁻¹' V n) lemma totallyBounded_interUnionBalls {p : ℕ → Prop} {U : ℕ → SetRel α α} (H : (uniformity α).HasBasis p U) (xs : ℕ → α) (u : ℕ → ℕ) : TotallyBounded (interUnionBalls xs u U) := by rw [Filter.HasBasis.totallyBounded_iff H] intro i _ have h_subset : interUnionBalls xs u U ⊆ ⋃ m ≤ u i, UniformSpace.ball (xs m) (Prod.swap ⁻¹' U i) := fun x hx ↦ Set.mem_iInter.1 hx i classical refine ⟨Finset.image xs (Finset.range (u i + 1)), Finset.finite_toSet _, fun x hx ↦ ?_⟩ simp only [Finset.coe_image, Finset.coe_range, mem_image, mem_Iio, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, Nat.lt_succ_iff] exact h_subset hx /-- The construction `interUnionBalls` is used to have a relatively compact set. -/ theorem isCompact_closure_interUnionBalls {p : ℕ → Prop} {U : ℕ → SetRel α α} (H : (uniformity α).HasBasis p U) [CompleteSpace α] (xs : ℕ → α) (u : ℕ → ℕ) : IsCompact (closure (interUnionBalls xs u U)) := by rw [isCompact_iff_totallyBounded_isComplete] refine ⟨TotallyBounded.closure ?_, isClosed_closure.isComplete⟩ exact totallyBounded_interUnionBalls H xs u /-! ### Sequentially complete space In this section we prove that a uniform space is complete provided that it is sequentially complete (i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set. In particular, this applies to (e)metric spaces, see the files `Topology/MetricSpace/EmetricSpace` and `Topology/MetricSpace/Basic`. More precisely, we assume that there is a sequence of entourages `U_n` such that any other entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/ namespace SequentiallyComplete variable {f : Filter α} (hf : Cauchy f) {U : ℕ → SetRel α α} (U_mem : ∀ n, U n ∈ 𝓤 α) open Set Finset noncomputable section /-- An auxiliary sequence of sets approximating a Cauchy filter. -/ def setSeqAux (n : ℕ) : { s : Set α // s ∈ f ∧ s ×ˢ s ⊆ U n } := Classical.indefiniteDescription _ <| (cauchy_iff.1 hf).2 (U n) (U_mem n) /-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides an antitone sequence of sets `s n ∈ f` such that `s n ×ˢ s n ⊆ U`. -/ def setSeq (n : ℕ) : Set α := ⋂ m ∈ Set.Iic n, (setSeqAux hf U_mem m).val theorem setSeq_mem (n : ℕ) : setSeq hf U_mem n ∈ f := (biInter_mem (finite_le_nat n)).2 fun m _ => (setSeqAux hf U_mem m).2.1 theorem setSeq_mono ⦃m n : ℕ⦄ (h : m ≤ n) : setSeq hf U_mem n ⊆ setSeq hf U_mem m := biInter_subset_biInter_left <| Iic_subset_Iic.2 h theorem setSeq_sub_aux (n : ℕ) : setSeq hf U_mem n ⊆ setSeqAux hf U_mem n := biInter_subset_of_mem right_mem_Iic theorem setSeq_prod_subset {N m n} (hm : N ≤ m) (hn : N ≤ n) : setSeq hf U_mem m ×ˢ setSeq hf U_mem n ⊆ U N := fun p hp => by refine (setSeqAux hf U_mem N).2.2 ⟨?_, ?_⟩ <;> apply setSeq_sub_aux · exact setSeq_mono hf U_mem hm hp.1 · exact setSeq_mono hf U_mem hn hp.2 /-- A sequence of points such that `seq n ∈ setSeq n`. Here `setSeq` is an antitone sequence of sets `setSeq n ∈ f` with diameters controlled by a given sequence of entourages. -/ def seq (n : ℕ) : α := (hf.1.nonempty_of_mem (setSeq_mem hf U_mem n)).choose theorem seq_mem (n : ℕ) : seq hf U_mem n ∈ setSeq hf U_mem n := (hf.1.nonempty_of_mem (setSeq_mem hf U_mem n)).choose_spec theorem seq_pair_mem ⦃N m n : ℕ⦄ (hm : N ≤ m) (hn : N ≤ n) : (seq hf U_mem m, seq hf U_mem n) ∈ U N := setSeq_prod_subset hf U_mem hm hn ⟨seq_mem hf U_mem m, seq_mem hf U_mem n⟩ theorem seq_is_cauchySeq (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) : CauchySeq <| seq hf U_mem := cauchySeq_of_controlled U U_le <| seq_pair_mem hf U_mem /-- If the sequence `SequentiallyComplete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/ theorem le_nhds_of_seq_tendsto_nhds (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) ⦃a : α⦄ (ha : Tendsto (seq hf U_mem) atTop (𝓝 a)) : f ≤ 𝓝 a := le_nhds_of_cauchy_adhp_aux (fun s hs => by rcases U_le s hs with ⟨m, hm⟩ rcases tendsto_atTop'.1 ha _ (mem_nhds_left a (U_mem m)) with ⟨n, hn⟩ refine ⟨setSeq hf U_mem (max m n), setSeq_mem hf U_mem _, ?_, seq hf U_mem (max m n), ?_, seq_mem hf U_mem _⟩ · have := le_max_left m n exact Set.Subset.trans (setSeq_prod_subset hf U_mem this this) hm · exact hm (hn _ <| le_max_right m n)) end end SequentiallyComplete namespace UniformSpace open SequentiallyComplete variable [IsCountablyGenerated (𝓤 α)] /-- A uniform space is complete provided that (a) its uniformity filter has a countable basis; (b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/ theorem complete_of_convergent_controlled_sequences (U : ℕ → SetRel α α) (U_mem : ∀ n, U n ∈ 𝓤 α) (HU : ∀ u : ℕ → α, (∀ N m n, N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ a, Tendsto u atTop (𝓝 a)) : CompleteSpace α := by obtain ⟨U', -, hU'⟩ := (𝓤 α).exists_antitone_seq have Hmem : ∀ n, U n ∩ U' n ∈ 𝓤 α := fun n => inter_mem (U_mem n) (hU'.2 ⟨n, Subset.refl _⟩) refine ⟨fun hf => (HU (seq hf Hmem) fun N m n hm hn => ?_).imp <| le_nhds_of_seq_tendsto_nhds _ _ fun s hs => ?_⟩ · exact inter_subset_left (seq_pair_mem hf Hmem hm hn) · rcases hU'.1 hs with ⟨N, hN⟩ exact ⟨N, Subset.trans inter_subset_right hN⟩ /-- A sequentially complete uniform space with a countable basis of the uniformity filter is complete. -/ theorem complete_of_cauchySeq_tendsto (H' : ∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) : CompleteSpace α := let ⟨U', _, hU'⟩ := (𝓤 α).exists_antitone_seq complete_of_convergent_controlled_sequences U' (fun n => hU'.2 ⟨n, Subset.refl _⟩) fun u hu => H' u <| cauchySeq_of_controlled U' (fun _ hs => hU'.1 hs) hu variable (α) -- TODO: move to `Topology.UniformSpace.Basic` instance (priority := 100) firstCountableTopology : FirstCountableTopology α := ⟨fun a => by rw [nhds_eq_comap_uniformity]; infer_instance⟩ /-- A separable uniform space with countably generated uniformity filter is second countable: one obtains a countable basis by taking the balls centered at points in a dense subset, and with rational "radii" from a countable open symmetric antitone basis of `𝓤 α`. -/ instance secondCountable_of_separable [SeparableSpace α] : SecondCountableTopology α := by rcases exists_countable_dense α with ⟨s, hsc, hsd⟩ obtain ⟨t : ℕ → SetRel α α, hto : ∀ i : ℕ, t i ∈ (𝓤 α).sets ∧ IsOpen (t i) ∧ (t i).IsSymm, h_basis : (𝓤 α).HasAntitoneBasis t⟩ := (@uniformity_hasBasis_open_symmetric α _).exists_antitone_subbasis choose ht_mem hto hts using hto refine ⟨⟨⋃ x ∈ s, range fun k => ball x (t k), hsc.biUnion fun x _ => countable_range _, ?_⟩⟩ refine (isTopologicalBasis_of_isOpen_of_nhds ?_ ?_).eq_generateFrom · simp only [mem_iUnion₂, mem_range] rintro _ ⟨x, _, k, rfl⟩ exact isOpen_ball x (hto k) · intro x V hxV hVo simp only [mem_iUnion₂, mem_range, exists_prop] rcases UniformSpace.mem_nhds_iff.1 (IsOpen.mem_nhds hVo hxV) with ⟨U, hU, hUV⟩ rcases comp_symm_of_uniformity hU with ⟨U', hU', _, hUU'⟩ rcases h_basis.toHasBasis.mem_iff.1 hU' with ⟨k, -, hk⟩ rcases hsd.inter_open_nonempty (ball x <| t k) (isOpen_ball x (hto k)) ⟨x, UniformSpace.mem_ball_self _ (ht_mem k)⟩ with ⟨y, hxy, hys⟩ refine ⟨_, ⟨y, hys, k, rfl⟩, (t k).symm hxy, fun z hz => ?_⟩ exact hUV (ball_subset_of_comp_subset (hk hxy) hUU' (hk hz)) end UniformSpace
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Completion.lean
import Mathlib.Topology.UniformSpace.AbstractCompletion /-! # Hausdorff completions of uniform spaces The goal is to construct a left-adjoint to the inclusion of complete Hausdorff uniform spaces into all uniform spaces. Any uniform space `α` gets a completion `Completion α` and a morphism (i.e. uniformly continuous map) `(↑) : α → Completion α` which solves the universal mapping problem of factorizing morphisms from `α` to any complete Hausdorff uniform space `β`. It means any uniformly continuous `f : α → β` gives rise to a unique morphism `Completion.extension f : Completion α → β` such that `f = Completion.extension f ∘ (↑)`. Actually `Completion.extension f` is defined for all maps from `α` to `β` but it has the desired properties only if `f` is uniformly continuous. Beware that `(↑)` is not injective if `α` is not Hausdorff. But its image is always dense. The adjoint functor acting on morphisms is then constructed by the usual abstract nonsense. For every uniform spaces `α` and `β`, it turns `f : α → β` into a morphism `Completion.map f : Completion α → Completion β` such that `(↑) ∘ f = (Completion.map f) ∘ (↑)` provided `f` is uniformly continuous. This construction is compatible with composition. In this file we introduce the following concepts: * `CauchyFilter α` the uniform completion of the uniform space `α` (using Cauchy filters). These are not minimal filters. * `Completion α := Quotient (separationSetoid (CauchyFilter α))` the Hausdorff completion. ## References This formalization is mostly based on N. Bourbaki: General Topology I. M. James: Topologies and Uniformities From a slightly different perspective in order to reuse material in `Topology.UniformSpace.Basic`. -/ noncomputable section open Filter Set open scoped SetRel Uniformity Topology universe u v w /-- Space of Cauchy filters This is essentially the completion of a uniform space. The embeddings are the neighbourhood filters. This space is not minimal, the separated uniform space (i.e. quotiented on the intersection of all entourages) is necessary for this. -/ def CauchyFilter (α : Type u) [UniformSpace α] : Type u := { f : Filter α // Cauchy f } namespace CauchyFilter section variable {α : Type u} [UniformSpace α] variable {β : Type v} {γ : Type w} variable [UniformSpace β] [UniformSpace γ] instance (f : CauchyFilter α) : NeBot f.1 := f.2.1 /-- The pairs of Cauchy filters generated by a set. -/ def gen (s : SetRel α α) : SetRel (CauchyFilter α) (CauchyFilter α) := { p | s ∈ p.1.val ×ˢ p.2.val } theorem monotone_gen : Monotone (gen : SetRel α α → _) := monotone_setOf fun p => @Filter.monotone_mem _ (p.1.val ×ˢ p.2.val) -- Porting note: this was a calc proof, but I could not make it work private theorem symm_gen : map Prod.swap ((𝓤 α).lift' gen) ≤ (𝓤 α).lift' gen := by let f := fun s : SetRel α α => { p : CauchyFilter α × CauchyFilter α | s ∈ (p.2.val ×ˢ p.1.val : Filter (α × α)) } have h₁ : map Prod.swap ((𝓤 α).lift' gen) = (𝓤 α).lift' f := by delta gen simp [f, map_lift'_eq, monotone_setOf, Filter.monotone_mem, Function.comp_def, image_swap_eq_preimage_swap] have h₂ : (𝓤 α).lift' f ≤ (𝓤 α).lift' gen := uniformity_lift_le_swap (monotone_principal.comp (monotone_setOf fun p => @Filter.monotone_mem _ (p.2.val ×ˢ p.1.val))) (by have h := fun p : CauchyFilter α × CauchyFilter α => @Filter.prod_comm _ _ p.2.val p.1.val simp only [Function.comp, h, mem_map, f] exact le_rfl) exact h₁.trans_le h₂ private theorem subset_gen_relComp {s t : SetRel α α} : gen s ○ gen t ⊆ gen (s ○ t) := fun ⟨f, g⟩ ⟨h, h₁, h₂⟩ => let ⟨t₁, (ht₁ : t₁ ∈ f.val), t₂, (ht₂ : t₂ ∈ h.val), (h₁ : t₁ ×ˢ t₂ ⊆ s)⟩ := mem_prod_iff.mp h₁ let ⟨t₃, (ht₃ : t₃ ∈ h.val), t₄, (ht₄ : t₄ ∈ g.val), (h₂ : t₃ ×ˢ t₄ ⊆ t)⟩ := mem_prod_iff.mp h₂ have : t₂ ∩ t₃ ∈ h.val := inter_mem ht₂ ht₃ let ⟨x, xt₂, xt₃⟩ := h.property.left.nonempty_of_mem this (f.val ×ˢ g.val).sets_of_superset (prod_mem_prod ht₁ ht₄) fun ⟨a, b⟩ ⟨(ha : a ∈ t₁), (hb : b ∈ t₄)⟩ => ⟨x, h₁ (show (a, x) ∈ t₁ ×ˢ t₂ from ⟨ha, xt₂⟩), h₂ (show (x, b) ∈ t₃ ×ˢ t₄ from ⟨xt₃, hb⟩)⟩ private theorem comp_gen : ((𝓤 α).lift' gen).lift' (fun s ↦ s ○ s) ≤ (𝓤 α).lift' gen := calc ((𝓤 α).lift' gen).lift' (fun s ↦ s ○ s) _ = (𝓤 α).lift' fun s ↦ gen s ○ gen s := by rw [lift'_lift'_assoc] · exact monotone_gen · exact monotone_id.relComp monotone_id _ ≤ (𝓤 α).lift' fun s ↦ gen <| s ○ s := lift'_mono' fun _ _hs => subset_gen_relComp _ = ((𝓤 α).lift' fun s : SetRel α α => s ○ s).lift' gen := by rw [lift'_lift'_assoc] · exact monotone_id.relComp monotone_id · exact monotone_gen _ ≤ (𝓤 α).lift' gen := lift'_mono comp_le_uniformity le_rfl instance : UniformSpace (CauchyFilter α) := UniformSpace.ofCore { uniformity := (𝓤 α).lift' gen refl := principal_le_lift'.2 fun _s hs ⟨a, b⟩ => fun (a_eq_b : a = b) => a_eq_b ▸ a.property.right hs symm := symm_gen comp := comp_gen } theorem mem_uniformity {s : Set (CauchyFilter α × CauchyFilter α)} : s ∈ 𝓤 (CauchyFilter α) ↔ ∃ t ∈ 𝓤 α, gen t ⊆ s := mem_lift'_sets monotone_gen theorem basis_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → SetRel α α} (h : (𝓤 α).HasBasis p s) : (𝓤 (CauchyFilter α)).HasBasis p (gen ∘ s) := h.lift' monotone_gen theorem mem_uniformity' {s : Set (CauchyFilter α × CauchyFilter α)} : s ∈ 𝓤 (CauchyFilter α) ↔ ∃ t ∈ 𝓤 α, ∀ f g : CauchyFilter α, t ∈ f.1 ×ˢ g.1 → (f, g) ∈ s := by refine mem_uniformity.trans (exists_congr (fun t => and_congr_right_iff.mpr (fun _h => ?_))) exact ⟨fun h _f _g ht => h ht, fun h _p hp => h _ _ hp⟩ /-- Embedding of `α` into its completion `CauchyFilter α` -/ def pureCauchy (a : α) : CauchyFilter α := ⟨pure a, cauchy_pure⟩ theorem isUniformInducing_pureCauchy : IsUniformInducing (pureCauchy : α → CauchyFilter α) := ⟨have : (preimage fun x : α × α => (pureCauchy x.fst, pureCauchy x.snd)) ∘ gen = id := funext fun s => Set.ext fun ⟨a₁, a₂⟩ => by simp [preimage, gen, pureCauchy] calc comap (fun x : α × α => (pureCauchy x.fst, pureCauchy x.snd)) ((𝓤 α).lift' gen) = (𝓤 α).lift' ((preimage fun x : α × α => (pureCauchy x.fst, pureCauchy x.snd)) ∘ gen) := comap_lift'_eq _ = 𝓤 α := by simp [this] ⟩ theorem isUniformEmbedding_pureCauchy : IsUniformEmbedding (pureCauchy : α → CauchyFilter α) where __ := isUniformInducing_pureCauchy injective _a₁ _a₂ h := pure_injective <| Subtype.ext_iff.1 h theorem denseRange_pureCauchy : DenseRange (pureCauchy : α → CauchyFilter α) := fun f => by have h_ex : ∀ s ∈ 𝓤 (CauchyFilter α), ∃ y : α, (f, pureCauchy y) ∈ s := fun s hs => let ⟨t'', ht''₁, (ht''₂ : gen t'' ⊆ s)⟩ := (mem_lift'_sets monotone_gen).mp hs let ⟨t', ht'₁, ht'₂⟩ := comp_mem_uniformity_sets ht''₁ have : t' ∈ f.val ×ˢ f.val := f.property.right ht'₁ let ⟨t, ht, (h : t ×ˢ t ⊆ t')⟩ := mem_prod_same_iff.mp this let ⟨x, (hx : x ∈ t)⟩ := f.property.left.nonempty_of_mem ht have : t'' ∈ f.val ×ˢ pure x := mem_prod_iff.mpr ⟨t, ht, { y : α | (x, y) ∈ t' }, h <| mk_mem_prod hx hx, fun ⟨a, b⟩ ⟨(h₁ : a ∈ t), (h₂ : (x, b) ∈ t')⟩ => ht'₂ <| SetRel.prodMk_mem_comp (@h (a, x) ⟨h₁, hx⟩) h₂⟩ ⟨x, ht''₂ <| by dsimp [gen]; exact this⟩ simp only [closure_eq_cluster_pts, ClusterPt, nhds_eq_uniformity, lift'_inf_principal_eq, Set.inter_comm _ (range pureCauchy), mem_setOf_eq] refine (lift'_neBot_iff ?_).mpr (fun s hs => ?_) · exact monotone_const.inter monotone_preimage · let ⟨y, hy⟩ := h_ex s hs have : pureCauchy y ∈ range pureCauchy ∩ { y : CauchyFilter α | (f, y) ∈ s } := ⟨mem_range_self y, hy⟩ exact ⟨_, this⟩ theorem isDenseInducing_pureCauchy : IsDenseInducing (pureCauchy : α → CauchyFilter α) := isUniformInducing_pureCauchy.isDenseInducing denseRange_pureCauchy theorem isDenseEmbedding_pureCauchy : IsDenseEmbedding (pureCauchy : α → CauchyFilter α) := isUniformEmbedding_pureCauchy.isDenseEmbedding denseRange_pureCauchy theorem nonempty_cauchyFilter_iff : Nonempty (CauchyFilter α) ↔ Nonempty α := by constructor <;> rintro ⟨c⟩ · have := eq_univ_iff_forall.1 isDenseEmbedding_pureCauchy.isDenseInducing.closure_range c obtain ⟨_, ⟨_, a, _⟩⟩ := mem_closure_iff.1 this _ isOpen_univ trivial exact ⟨a⟩ · exact ⟨pureCauchy c⟩ section instance : CompleteSpace (CauchyFilter α) := completeSpace_extension isUniformInducing_pureCauchy denseRange_pureCauchy fun f hf => let f' : CauchyFilter α := ⟨f, hf⟩ have : map pureCauchy f ≤ (𝓤 <| CauchyFilter α).lift' (preimage (Prod.mk f')) := le_lift'.2 fun _ hs => let ⟨t, ht₁, ht₂⟩ := (mem_lift'_sets monotone_gen).mp hs let ⟨t', ht', (h : t' ×ˢ t' ⊆ t)⟩ := mem_prod_same_iff.mp (hf.right ht₁) have : t' ⊆ { y : α | (f', pureCauchy y) ∈ gen t } := fun x hx => (f ×ˢ pure x).sets_of_superset (prod_mem_prod ht' hx) h f.sets_of_superset ht' <| Subset.trans this (preimage_mono ht₂) ⟨f', by simpa [nhds_eq_uniformity]⟩ end instance [Inhabited α] : Inhabited (CauchyFilter α) := ⟨pureCauchy default⟩ instance [h : Nonempty α] : Nonempty (CauchyFilter α) := h.recOn fun a => Nonempty.intro <| CauchyFilter.pureCauchy a section Extend open Classical in /-- Extend a uniformly continuous function `α → β` to a function `CauchyFilter α → β`. Outputs junk when `f` is not uniformly continuous. -/ def extend (f : α → β) : CauchyFilter α → β := if UniformContinuous f then isDenseInducing_pureCauchy.extend f else fun x => f (nonempty_cauchyFilter_iff.1 ⟨x⟩).some section T0Space variable [T0Space β] theorem extend_pureCauchy {f : α → β} (hf : UniformContinuous f) (a : α) : extend f (pureCauchy a) = f a := by rw [extend, if_pos hf] exact uniformly_extend_of_ind isUniformInducing_pureCauchy denseRange_pureCauchy hf _ end T0Space variable [CompleteSpace β] theorem uniformContinuous_extend {f : α → β} : UniformContinuous (extend f) := by by_cases hf : UniformContinuous f · rw [extend, if_pos hf] exact uniformContinuous_uniformly_extend isUniformInducing_pureCauchy denseRange_pureCauchy hf · rw [extend, if_neg hf] exact uniformContinuous_of_const fun a _b => by congr end Extend theorem inseparable_iff {f g : CauchyFilter α} : Inseparable f g ↔ f.1 ×ˢ g.1 ≤ 𝓤 α := (basis_uniformity (basis_sets _)).inseparable_iff_uniformity theorem inseparable_iff_of_le_nhds {f g : CauchyFilter α} {a b : α} (ha : f.1 ≤ 𝓝 a) (hb : g.1 ≤ 𝓝 b) : Inseparable a b ↔ Inseparable f g := by rw [← tendsto_id'] at ha hb rw [inseparable_iff, (ha.comp tendsto_fst).inseparable_iff_uniformity (hb.comp tendsto_snd)] simp only [Function.comp_apply, id_eq, Prod.mk.eta, ← Function.id_def, tendsto_id'] theorem inseparable_lim_iff [CompleteSpace α] {f g : CauchyFilter α} : haveI := f.2.1.nonempty; Inseparable (lim f.1) (lim g.1) ↔ Inseparable f g := inseparable_iff_of_le_nhds f.2.le_nhds_lim g.2.le_nhds_lim end theorem cauchyFilter_eq {α : Type*} [UniformSpace α] [CompleteSpace α] [T0Space α] {f g : CauchyFilter α} : haveI := f.2.1.nonempty; lim f.1 = lim g.1 ↔ Inseparable f g := by rw [← inseparable_iff_eq, inseparable_lim_iff] section theorem separated_pureCauchy_injective {α : Type*} [UniformSpace α] [T0Space α] : Function.Injective fun a : α => SeparationQuotient.mk (pureCauchy a) := fun a b h ↦ Inseparable.eq <| (inseparable_iff_of_le_nhds (pure_le_nhds a) (pure_le_nhds b)).2 <| SeparationQuotient.mk_eq_mk.1 h end end CauchyFilter open CauchyFilter Set namespace UniformSpace variable (α : Type*) [UniformSpace α] variable {β : Type*} [UniformSpace β] variable {γ : Type*} [UniformSpace γ] /-- Hausdorff completion of `α` -/ def Completion := SeparationQuotient (CauchyFilter α) namespace Completion instance inhabited [Inhabited α] : Inhabited (Completion α) := inferInstanceAs <| Inhabited (Quotient _) instance uniformSpace : UniformSpace (Completion α) := SeparationQuotient.instUniformSpace instance completeSpace : CompleteSpace (Completion α) := SeparationQuotient.instCompleteSpace instance t0Space : T0Space (Completion α) := SeparationQuotient.instT0Space variable {α} in /-- The map from a uniform space to its completion. -/ @[coe] def coe' : α → Completion α := SeparationQuotient.mk ∘ pureCauchy /-- Automatic coercion from `α` to its completion. Not always injective. -/ instance : Coe α (Completion α) := ⟨coe'⟩ -- note [use has_coe_t] protected theorem coe_eq : ((↑) : α → Completion α) = SeparationQuotient.mk ∘ pureCauchy := rfl theorem isUniformInducing_coe : IsUniformInducing ((↑) : α → Completion α) := SeparationQuotient.isUniformInducing_mk.comp isUniformInducing_pureCauchy theorem comap_coe_eq_uniformity : ((𝓤 _).comap fun p : α × α => ((p.1 : Completion α), (p.2 : Completion α))) = 𝓤 α := (isUniformInducing_coe _).1 variable {α} in theorem denseRange_coe : DenseRange ((↑) : α → Completion α) := SeparationQuotient.surjective_mk.denseRange.comp denseRange_pureCauchy SeparationQuotient.continuous_mk /-- The Hausdorff completion as an abstract completion. -/ def cPkg {α : Type*} [UniformSpace α] : AbstractCompletion α where space := Completion α coe := (↑) uniformStruct := by infer_instance complete := by infer_instance separation := by infer_instance isUniformInducing := Completion.isUniformInducing_coe α dense := Completion.denseRange_coe instance AbstractCompletion.inhabited : Inhabited (AbstractCompletion α) := ⟨cPkg⟩ attribute [local instance] AbstractCompletion.uniformStruct AbstractCompletion.complete AbstractCompletion.separation theorem nonempty_completion_iff : Nonempty (Completion α) ↔ Nonempty α := cPkg.dense.nonempty_iff.symm theorem uniformContinuous_coe : UniformContinuous ((↑) : α → Completion α) := cPkg.uniformContinuous_coe theorem continuous_coe : Continuous ((↑) : α → Completion α) := cPkg.continuous_coe theorem isUniformEmbedding_coe [T0Space α] : IsUniformEmbedding ((↑) : α → Completion α) := { comap_uniformity := comap_coe_eq_uniformity α injective := separated_pureCauchy_injective } theorem coe_injective [T0Space α] : Function.Injective ((↑) : α → Completion α) := IsUniformEmbedding.injective (isUniformEmbedding_coe _) variable {α} @[simp] lemma coe_inj [T0Space α] {a b : α} : (a : Completion α) = b ↔ a = b := (coe_injective _).eq_iff theorem isDenseInducing_coe : IsDenseInducing ((↑) : α → Completion α) := { (isUniformInducing_coe α).isInducing with dense := denseRange_coe } /-- The uniform bijection between a complete space and its uniform completion. -/ def UniformCompletion.completeEquivSelf [CompleteSpace α] [T0Space α] : Completion α ≃ᵤ α := AbstractCompletion.compareEquiv Completion.cPkg AbstractCompletion.ofComplete open TopologicalSpace instance separableSpace_completion [SeparableSpace α] : SeparableSpace (Completion α) := Completion.isDenseInducing_coe.separableSpace theorem isDenseEmbedding_coe [T0Space α] : IsDenseEmbedding ((↑) : α → Completion α) := { isDenseInducing_coe with injective := separated_pureCauchy_injective } theorem denseRange_coe₂ : DenseRange fun x : α × β => ((x.1 : Completion α), (x.2 : Completion β)) := denseRange_coe.prodMap denseRange_coe theorem denseRange_coe₃ : DenseRange fun x : α × β × γ => ((x.1 : Completion α), ((x.2.1 : Completion β), (x.2.2 : Completion γ))) := denseRange_coe.prodMap denseRange_coe₂ @[elab_as_elim] theorem induction_on {p : Completion α → Prop} (a : Completion α) (hp : IsClosed { a | p a }) (ih : ∀ a : α, p a) : p a := isClosed_property denseRange_coe hp ih a @[elab_as_elim] theorem induction_on₂ {p : Completion α → Completion β → Prop} (a : Completion α) (b : Completion β) (hp : IsClosed { x : Completion α × Completion β | p x.1 x.2 }) (ih : ∀ (a : α) (b : β), p a b) : p a b := have : ∀ x : Completion α × Completion β, p x.1 x.2 := isClosed_property denseRange_coe₂ hp fun ⟨a, b⟩ => ih a b this (a, b) @[elab_as_elim] theorem induction_on₃ {p : Completion α → Completion β → Completion γ → Prop} (a : Completion α) (b : Completion β) (c : Completion γ) (hp : IsClosed { x : Completion α × Completion β × Completion γ | p x.1 x.2.1 x.2.2 }) (ih : ∀ (a : α) (b : β) (c : γ), p a b c) : p a b c := have : ∀ x : Completion α × Completion β × Completion γ, p x.1 x.2.1 x.2.2 := isClosed_property denseRange_coe₃ hp fun ⟨a, b, c⟩ => ih a b c this (a, b, c) theorem ext {Y : Type*} [TopologicalSpace Y] [T2Space Y] {f g : Completion α → Y} (hf : Continuous f) (hg : Continuous g) (h : ∀ a : α, f a = g a) : f = g := cPkg.funext hf hg h theorem ext' {Y : Type*} [TopologicalSpace Y] [T2Space Y] {f g : Completion α → Y} (hf : Continuous f) (hg : Continuous g) (h : ∀ a : α, f a = g a) (a : Completion α) : f a = g a := congr_fun (ext hf hg h) a section Extension variable {f : α → β} /-- "Extension" to the completion. It is defined for any map `f` but returns an arbitrary constant value if `f` is not uniformly continuous -/ protected def extension (f : α → β) : Completion α → β := cPkg.extend f section CompleteSpace variable [CompleteSpace β] theorem uniformContinuous_extension : UniformContinuous (Completion.extension f) := cPkg.uniformContinuous_extend @[continuity, fun_prop] theorem continuous_extension : Continuous (Completion.extension f) := cPkg.continuous_extend end CompleteSpace theorem extension_coe [T0Space β] (hf : UniformContinuous f) (a : α) : (Completion.extension f) a = f a := cPkg.extend_coe hf a theorem inseparable_extension_coe (hf : UniformContinuous f) (x : α) : Inseparable (Completion.extension f x) (f x) := cPkg.inseparable_extend_coe hf x lemma isUniformInducing_extension [CompleteSpace β] (h : IsUniformInducing f) : IsUniformInducing (Completion.extension f) := cPkg.isUniformInducing_extend h variable [T0Space β] [CompleteSpace β] theorem extension_unique (hf : UniformContinuous f) {g : Completion α → β} (hg : UniformContinuous g) (h : ∀ a : α, f a = g (a : Completion α)) : Completion.extension f = g := cPkg.extend_unique hf hg h @[simp] theorem extension_comp_coe {f : Completion α → β} (hf : UniformContinuous f) : Completion.extension (f ∘ (↑)) = f := cPkg.extend_comp_coe hf end Extension section Map variable {f : α → β} /-- Completion functor acting on morphisms -/ protected def map (f : α → β) : Completion α → Completion β := cPkg.map cPkg f theorem uniformContinuous_map : UniformContinuous (Completion.map f) := cPkg.uniformContinuous_map cPkg f @[continuity] theorem continuous_map : Continuous (Completion.map f) := cPkg.continuous_map cPkg f theorem map_coe (hf : UniformContinuous f) (a : α) : (Completion.map f) a = f a := cPkg.map_coe cPkg hf a theorem map_unique {f : α → β} {g : Completion α → Completion β} (hg : UniformContinuous g) (h : ∀ a : α, ↑(f a) = g a) : Completion.map f = g := cPkg.map_unique cPkg hg h @[simp] theorem map_id : Completion.map (@id α) = id := cPkg.map_id theorem extension_map [CompleteSpace γ] [T0Space γ] {f : β → γ} {g : α → β} (hf : UniformContinuous f) (hg : UniformContinuous g) : Completion.extension f ∘ Completion.map g = Completion.extension (f ∘ g) := Completion.ext (continuous_extension.comp continuous_map) continuous_extension <| by simp [hf, hg, hf.comp hg, map_coe, extension_coe] theorem map_comp {g : β → γ} {f : α → β} (hg : UniformContinuous g) (hf : UniformContinuous f) : Completion.map g ∘ Completion.map f = Completion.map (g ∘ f) := extension_map ((uniformContinuous_coe _).comp hg) hf /-- The uniform isomorphism between two completions of isomorphic uniform spaces. -/ def mapEquiv (e : α ≃ᵤ β) : Completion α ≃ᵤ Completion β := cPkg.mapEquiv cPkg e @[simp] theorem mapEquiv_symm (e : α ≃ᵤ β) : (mapEquiv e).symm = mapEquiv e.symm := cPkg.mapEquiv_symm cPkg e @[simp] theorem mapEquiv_coe (e : α ≃ᵤ β) (a : α) : mapEquiv e a = (e a) := cPkg.mapEquiv_coe cPkg e a end Map /- In this section we construct isomorphisms between the completion of a uniform space and the completion of its separation quotient -/ section SeparationQuotientCompletion open SeparationQuotient in /-- The isomorphism between the completion of a uniform space and the completion of its separation quotient. -/ def completionSeparationQuotientEquiv (α : Type u) [UniformSpace α] : Completion (SeparationQuotient α) ≃ Completion α := by refine ⟨Completion.extension (lift' ((↑) : α → Completion α)), Completion.map SeparationQuotient.mk, fun a ↦ ?_, fun a ↦ ?_⟩ · refine induction_on a (isClosed_eq (continuous_map.comp continuous_extension) continuous_id) ?_ refine SeparationQuotient.surjective_mk.forall.2 fun a ↦ ?_ rw [extension_coe (uniformContinuous_lift' _), lift'_mk (uniformContinuous_coe α), map_coe uniformContinuous_mk] · refine induction_on a (isClosed_eq (continuous_extension.comp continuous_map) continuous_id) fun a ↦ ?_ rw [map_coe uniformContinuous_mk, extension_coe (uniformContinuous_lift' _), lift'_mk (uniformContinuous_coe _)] theorem uniformContinuous_completionSeparationQuotientEquiv : UniformContinuous (completionSeparationQuotientEquiv α) := uniformContinuous_extension theorem uniformContinuous_completionSeparationQuotientEquiv_symm : UniformContinuous (completionSeparationQuotientEquiv α).symm := uniformContinuous_map end SeparationQuotientCompletion section Extension₂ variable (f : α → β → γ) open Function /-- Extend a two variable map to the Hausdorff completions. -/ protected def extension₂ (f : α → β → γ) : Completion α → Completion β → γ := cPkg.extend₂ cPkg f section T0Space variable [T0Space γ] {f} theorem extension₂_coe_coe (hf : UniformContinuous₂ f) (a : α) (b : β) : Completion.extension₂ f a b = f a b := cPkg.extension₂_coe_coe cPkg hf a b end T0Space variable [CompleteSpace γ] theorem uniformContinuous_extension₂ : UniformContinuous₂ (Completion.extension₂ f) := cPkg.uniformContinuous_extension₂ cPkg f end Extension₂ section Map₂ open Function /-- Lift a two variable map to the Hausdorff completions. -/ protected def map₂ (f : α → β → γ) : Completion α → Completion β → Completion γ := cPkg.map₂ cPkg cPkg f theorem uniformContinuous_map₂ (f : α → β → γ) : UniformContinuous₂ (Completion.map₂ f) := cPkg.uniformContinuous_map₂ cPkg cPkg f theorem continuous_map₂ {δ} [TopologicalSpace δ] {f : α → β → γ} {a : δ → Completion α} {b : δ → Completion β} (ha : Continuous a) (hb : Continuous b) : Continuous fun d : δ => Completion.map₂ f (a d) (b d) := cPkg.continuous_map₂ cPkg cPkg ha hb theorem map₂_coe_coe (a : α) (b : β) (f : α → β → γ) (hf : UniformContinuous₂ f) : Completion.map₂ f (a : Completion α) (b : Completion β) = f a b := cPkg.map₂_coe_coe cPkg cPkg a b f hf end Map₂ end Completion end UniformSpace
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/CompactConvergence.lean
import Mathlib.Topology.CompactOpen import Mathlib.Topology.Compactness.CompactlyCoherentSpace import Mathlib.Topology.Maps.Proper.Basic import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Compact convergence (uniform convergence on compact sets) Given a topological space `α` and a uniform space `β` (e.g., a metric space or a topological group), the space of continuous maps `C(α, β)` carries a natural uniform space structure. We define this uniform space structure in this file and also prove its basic properties. ## Main definitions - `ContinuousMap.toUniformOnFunIsCompact`: natural embedding of `C(α, β)` into the space `α →ᵤ[{K | IsCompact K}] β` of all maps `α → β` with the uniform space structure of uniform convergence on compacts. - `ContinuousMap.compactConvergenceUniformSpace`: the `UniformSpace` structure on `C(α, β)` induced by the map above. ## Main results * `ContinuousMap.mem_compactConvergence_entourage_iff`: a characterisation of the entourages of `C(α, β)`. The entourages are generated by the following sets. Given `K : Set α` and `V : Set (β × β)`, let `E(K, V) : Set (C(α, β) × C(α, β))` be the set of pairs of continuous functions `α → β` which are `V`-close on `K`: $$ E(K, V) = \{ (f, g) | ∀ (x ∈ K), (f x, g x) ∈ V \}. $$ Then the sets `E(K, V)` for all compact sets `K` and all entourages `V` form a basis of entourages of `C(α, β)`. As usual, this basis of entourages provides a basis of neighbourhoods by fixing `f`, see `nhds_basis_uniformity'`. * `Filter.HasBasis.compactConvergenceUniformity`: a similar statement that uses a basis of entourages of `β` instead of all entourages. It is useful, e.g., if `β` is a metric space. * `ContinuousMap.tendsto_iff_forall_isCompact_tendstoUniformlyOn`: a sequence of functions `Fₙ` in `C(α, β)` converges in the compact-open topology to some `f` iff `Fₙ` converges to `f` uniformly on each compact subset `K` of `α`. * Topology induced by the uniformity described above agrees with the compact-open topology. This is essentially the same as `ContinuousMap.tendsto_iff_forall_isCompact_tendstoUniformlyOn`. This fact is not available as a separate theorem. Instead, we override the projection of `ContinuousMap.compactConvergenceUniformity` to `TopologicalSpace` to be `ContinuousMap.compactOpen` and prove that they agree, see Note [forgetful inheritance] and implementation notes below. * `ContinuousMap.tendsto_iff_tendstoLocallyUniformly`: on a weakly locally compact space, a sequence of functions `Fₙ` in `C(α, β)` converges to some `f` iff `Fₙ` converges to `f` locally uniformly. * `ContinuousMap.tendsto_iff_tendstoUniformly`: on a compact space, a sequence of functions `Fₙ` in `C(α, β)` converges to some `f` iff `Fₙ` converges to `f` uniformly. ## Implementation details For technical reasons (see Note [forgetful inheritance]), instead of defining a `UniformSpace C(α, β)` structure and proving in a theorem that it agrees with the compact-open topology, we override the projection right in the definition, so that the resulting instance uses the compact-open topology. ## TODO * Results about uniformly continuous functions `γ → C(α, β)` and uniform limits of sequences `ι → γ → C(α, β)`. -/ open Filter Set Topology UniformSpace open scoped Uniformity UniformConvergence universe u₁ u₂ u₃ variable {α : Type u₁} {β : Type u₂} [TopologicalSpace α] [UniformSpace β] variable (K : Set α) (V : Set (β × β)) (f : C(α, β)) namespace ContinuousMap /-- Compact-open topology on `C(α, β)` agrees with the topology of uniform convergence on compacts: a family of continuous functions `F i` tends to `f` in the compact-open topology if and only if the `F i` tends to `f` uniformly on all compact sets. -/ theorem tendsto_iff_forall_isCompact_tendstoUniformlyOn {ι : Type u₃} {p : Filter ι} {F : ι → C(α, β)} {f} : Tendsto F p (𝓝 f) ↔ ∀ K, IsCompact K → TendstoUniformlyOn (fun i a => F i a) f p K := by rw [tendsto_nhds_compactOpen] constructor · -- Let us prove that convergence in the compact-open topology -- implies uniform convergence on compacts. -- Consider a compact set `K` intro h K hK -- Since `K` is compact, it suffices to prove locally uniform convergence rw [← tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK] -- Now choose an entourage `U` in the codomain and a point `x ∈ K`. intro U hU x _ -- Choose an open symmetric entourage `V` such that `V ○ V ⊆ U`. rcases comp_open_symm_mem_uniformity_sets hU with ⟨V, hV, hVo, hVsymm, hVU⟩ -- Then choose a closed entourage `W ⊆ V` rcases mem_uniformity_isClosed hV with ⟨W, hW, hWc, hWU⟩ -- Consider `s = {y ∈ K | (f x, f y) ∈ W}` set s := K ∩ f ⁻¹' ball (f x) W -- This is a neighbourhood of `x` within `K`, because `W` is an entourage. have hnhds : s ∈ 𝓝[K] x := inter_mem_nhdsWithin _ <| f.continuousAt _ (ball_mem_nhds _ hW) -- This set is compact because it is an intersection of `K` -- with a closed set `{y | (f x, f y) ∈ W} = f ⁻¹' UniformSpace.ball (f x) W` have hcomp : IsCompact s := hK.inter_right <| (isClosed_ball _ hWc).preimage f.continuous -- `f` maps `s` to the open set `ball (f x) V = {z | (f x, z) ∈ V}` have hmaps : MapsTo f s (ball (f x) V) := fun x hx ↦ hWU hx.2 use s, hnhds -- Continuous maps `F i` in a neighbourhood of `f` map `s` to `ball (f x) V` as well. refine (h s hcomp _ (isOpen_ball _ hVo) hmaps).mono fun g hg y hy ↦ ?_ -- Then for `y ∈ s` we have `(f y, f x) ∈ V` and `(f x, F i y) ∈ V`, thus `(f y, F i y) ∈ U` exact hVU ⟨f x, SetRel.symm V <| hmaps hy, hg hy⟩ · -- Now we prove that uniform convergence on compacts -- implies convergence in the compact-open topology -- Consider a compact set `K`, an open set `U`, and a continuous map `f` that maps `K` to `U` intro h K hK U hU hf -- Due to Lebesgue number lemma, there exists an entourage `V` -- such that `U` includes the `V`-thickening of `f '' K`. rcases lebesgue_number_of_compact_open (hK.image (map_continuous f)) hU hf.image_subset with ⟨V, hV, -, hVf⟩ -- Then any continuous map that is uniformly `V`-close to `f` on `K` -- maps `K` to `U` as well filter_upwards [h K hK V hV] with g hg x hx using hVf _ (mem_image_of_mem f hx) (hg x hx) /-- Interpret a bundled continuous map as an element of `α →ᵤ[{K | IsCompact K}] β`. We use this map to induce the `UniformSpace` structure on `C(α, β)`. -/ def toUniformOnFunIsCompact (f : C(α, β)) : α →ᵤ[{K | IsCompact K}] β := UniformOnFun.ofFun {K | IsCompact K} f @[simp] theorem toUniformOnFun_toFun (f : C(α, β)) : UniformOnFun.toFun _ f.toUniformOnFunIsCompact = f := rfl theorem range_toUniformOnFunIsCompact : range (toUniformOnFunIsCompact) = {f : UniformOnFun α β {K | IsCompact K} | Continuous f} := Set.ext fun f ↦ ⟨fun g ↦ g.choose_spec ▸ g.choose.2, fun hf ↦ ⟨⟨f, hf⟩, rfl⟩⟩ open UniformSpace in /-- Uniform space structure on `C(α, β)`. The uniformity comes from `α →ᵤ[{K | IsCompact K}] β` (i.e., `UniformOnFun α β {K | IsCompact K}`) which defines topology of uniform convergence on compact sets. We use `ContinuousMap.tendsto_iff_forall_isCompact_tendstoUniformlyOn` to show that the induced topology agrees with the compact-open topology and replace the topology with `compactOpen` to avoid non-defeq diamonds, see Note [forgetful inheritance]. -/ instance compactConvergenceUniformSpace : UniformSpace C(α, β) := .replaceTopology (.comap toUniformOnFunIsCompact inferInstance) <| by refine TopologicalSpace.ext_nhds fun f ↦ eq_of_forall_le_iff fun l ↦ ?_ simp_rw [← tendsto_id', tendsto_iff_forall_isCompact_tendstoUniformlyOn, nhds_induced, tendsto_comap_iff, UniformOnFun.tendsto_iff_tendstoUniformlyOn] rfl theorem isUniformEmbedding_toUniformOnFunIsCompact : IsUniformEmbedding (toUniformOnFunIsCompact : C(α, β) → α →ᵤ[{K | IsCompact K}] β) where comap_uniformity := rfl injective := DFunLike.coe_injective open UniformOnFun in /-- `f : X → C(α, β)` is continuous if any only if it is continuous when reinterpreted as a map `f : X → α →ᵤ[{K | IsCompact K}] β`. -/ theorem continuous_iff_continuous_uniformOnFun {X : Type*} [TopologicalSpace X] (f : X → C(α, β)) : Continuous f ↔ Continuous (fun x ↦ ofFun {K | IsCompact K} (f x)) := isUniformEmbedding_toUniformOnFunIsCompact.isInducing.continuous_iff -- The following definitions and theorems -- used to be a part of the construction of the `UniformSpace C(α, β)` structure -- before it was migrated to `UniformOnFun` theorem _root_.Filter.HasBasis.compactConvergenceUniformity {ι : Type*} {pi : ι → Prop} {s : ι → Set (β × β)} (h : (𝓤 β).HasBasis pi s) : HasBasis (𝓤 C(α, β)) (fun p : Set α × ι => IsCompact p.1 ∧ pi p.2) fun p => { fg : C(α, β) × C(α, β) | ∀ x ∈ p.1, (fg.1 x, fg.2 x) ∈ s p.2 } := by rw [← isUniformEmbedding_toUniformOnFunIsCompact.comap_uniformity] exact .comap _ <| UniformOnFun.hasBasis_uniformity_of_basis _ _ {K | IsCompact K} ⟨∅, isCompact_empty⟩ (directedOn_of_sup_mem fun _ _ ↦ IsCompact.union) h theorem hasBasis_compactConvergenceUniformity : HasBasis (𝓤 C(α, β)) (fun p : Set α × Set (β × β) => IsCompact p.1 ∧ p.2 ∈ 𝓤 β) fun p => { fg : C(α, β) × C(α, β) | ∀ x ∈ p.1, (fg.1 x, fg.2 x) ∈ p.2 } := (basis_sets _).compactConvergenceUniformity theorem mem_compactConvergence_entourage_iff (X : Set (C(α, β) × C(α, β))) : X ∈ 𝓤 C(α, β) ↔ ∃ (K : Set α) (V : Set (β × β)), IsCompact K ∧ V ∈ 𝓤 β ∧ { fg : C(α, β) × C(α, β) | ∀ x ∈ K, (fg.1 x, fg.2 x) ∈ V } ⊆ X := by simp [hasBasis_compactConvergenceUniformity.mem_iff, and_assoc] /-- If `K` is a compact exhaustion of `α` and `V i` bounded by `p i` is a basis of entourages of `β`, then `fun (n, i) ↦ {(f, g) | ∀ x ∈ K n, (f x, g x) ∈ V i}` bounded by `p i` is a basis of entourages of `C(α, β)`. -/ theorem _root_.CompactExhaustion.hasBasis_compactConvergenceUniformity {ι : Type*} {p : ι → Prop} {V : ι → Set (β × β)} (K : CompactExhaustion α) (hb : (𝓤 β).HasBasis p V) : HasBasis (𝓤 C(α, β)) (fun i : ℕ × ι ↦ p i.2) fun i ↦ {fg | ∀ x ∈ K i.1, (fg.1 x, fg.2 x) ∈ V i.2} := (UniformOnFun.hasBasis_uniformity_of_covering_of_basis {K | IsCompact K} K.isCompact (Monotone.directed_le K.subset) (fun _ ↦ K.exists_superset_of_isCompact) hb).comap _ theorem _root_.CompactExhaustion.hasAntitoneBasis_compactConvergenceUniformity {V : ℕ → Set (β × β)} (K : CompactExhaustion α) (hb : (𝓤 β).HasAntitoneBasis V) : HasAntitoneBasis (𝓤 C(α, β)) fun n ↦ {fg | ∀ x ∈ K n, (fg.1 x, fg.2 x) ∈ V n} := (UniformOnFun.hasAntitoneBasis_uniformity {K | IsCompact K} K.isCompact K.subset (fun _ ↦ K.exists_superset_of_isCompact) hb).comap _ /-- If `α` is a weakly locally compact σ-compact space (e.g., a proper pseudometric space or a compact spaces) and the uniformity on `β` is pseudometrizable, then the uniformity on `C(α, β)` is pseudometrizable too. -/ instance [WeaklyLocallyCompactSpace α] [SigmaCompactSpace α] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (C(α, β))) := let ⟨_V, hV⟩ := exists_antitone_basis (𝓤 β) ((CompactExhaustion.choice α).hasAntitoneBasis_compactConvergenceUniformity hV).isCountablyGenerated variable {ι : Type u₃} {p : Filter ι} {F : ι → C(α, β)} {f} /-- Locally uniform convergence implies convergence in the compact-open topology. -/ theorem tendsto_of_tendstoLocallyUniformly (h : TendstoLocallyUniformly (fun i a => F i a) f p) : Tendsto F p (𝓝 f) := by rw [tendsto_iff_forall_isCompact_tendstoUniformlyOn] intro K hK rw [← tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK] exact h.tendstoLocallyUniformlyOn /-- In a weakly locally compact space, convergence in the compact-open topology is the same as locally uniform convergence. The right-to-left implication holds in any topological space, see `ContinuousMap.tendsto_of_tendstoLocallyUniformly`. -/ theorem tendsto_iff_tendstoLocallyUniformly [WeaklyLocallyCompactSpace α] : Tendsto F p (𝓝 f) ↔ TendstoLocallyUniformly (fun i a => F i a) f p := by refine ⟨fun h V hV x ↦ ?_, tendsto_of_tendstoLocallyUniformly⟩ rw [tendsto_iff_forall_isCompact_tendstoUniformlyOn] at h obtain ⟨n, hn₁, hn₂⟩ := exists_compact_mem_nhds x exact ⟨n, hn₂, h n hn₁ V hV⟩ section Functorial variable {γ δ : Type*} [TopologicalSpace γ] [UniformSpace δ] theorem uniformContinuous_comp (g : C(β, δ)) (hg : UniformContinuous g) : UniformContinuous (ContinuousMap.comp g : C(α, β) → C(α, δ)) := isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.postcomp_uniformContinuous hg |>.comp isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous theorem isUniformInducing_comp (g : C(β, δ)) (hg : IsUniformInducing g) : IsUniformInducing (ContinuousMap.comp g : C(α, β) → C(α, δ)) := isUniformEmbedding_toUniformOnFunIsCompact.isUniformInducing.of_comp_iff.mp <| UniformOnFun.postcomp_isUniformInducing hg |>.comp isUniformEmbedding_toUniformOnFunIsCompact.isUniformInducing theorem isUniformEmbedding_comp (g : C(β, δ)) (hg : IsUniformEmbedding g) : IsUniformEmbedding (ContinuousMap.comp g : C(α, β) → C(α, δ)) := isUniformEmbedding_toUniformOnFunIsCompact.of_comp_iff.mp <| UniformOnFun.postcomp_isUniformEmbedding hg |>.comp isUniformEmbedding_toUniformOnFunIsCompact theorem uniformContinuous_comp_left (g : C(α, γ)) : UniformContinuous (fun f ↦ f.comp g : C(γ, β) → C(α, β)) := isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.precomp_uniformContinuous (fun _ hK ↦ hK.image g.continuous) |>.comp isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous /-- Any pair of a homeomorphism `X ≃ₜ Z` and an isomorphism `Y ≃ᵤ T` of uniform spaces gives rise to an isomorphism `C(X, Y) ≃ᵤ C(Z, T)`. -/ protected def _root_.UniformEquiv.arrowCongr (φ : α ≃ₜ γ) (ψ : β ≃ᵤ δ) : C(α, β) ≃ᵤ C(γ, δ) where toFun f := .comp ψ.toHomeomorph <| f.comp φ.symm invFun f := .comp ψ.symm.toHomeomorph <| 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 _ uniformContinuous_toFun := uniformContinuous_comp _ ψ.uniformContinuous |>.comp <| uniformContinuous_comp_left _ uniformContinuous_invFun := uniformContinuous_comp _ ψ.symm.uniformContinuous |>.comp <| uniformContinuous_comp_left _ end Functorial section CompactDomain variable [CompactSpace α] theorem hasBasis_compactConvergenceUniformity_of_compact : HasBasis (𝓤 C(α, β)) (fun V : Set (β × β) => V ∈ 𝓤 β) fun V ↦ {fg : C(α, β) × C(α, β) | ∀ x, (fg.1 x, fg.2 x) ∈ V} := hasBasis_compactConvergenceUniformity.to_hasBasis (fun p hp => ⟨p.2, hp.2, fun _fg hfg x _hx => hfg x⟩) fun V hV ↦ ⟨⟨univ, V⟩, ⟨isCompact_univ, hV⟩, fun _fg hfg x => hfg x (mem_univ x)⟩ theorem _root_.Filter.HasBasis.compactConvergenceUniformity_of_compact {ι : Sort*} {p : ι → Prop} {V : ι → Set (β × β)} (h : (𝓤 β).HasBasis p V) : HasBasis (𝓤 C(α, β)) p fun i ↦ {fg : C(α, β) × C(α, β) | ∀ x, (fg.1 x, fg.2 x) ∈ V i} := hasBasis_compactConvergenceUniformity_of_compact.to_hasBasis (fun _U hU ↦ (h.mem_iff.mp hU).imp fun _i ⟨hpi, hi⟩ ↦ ⟨hpi, fun _ h a ↦ hi <| h a⟩) fun i hi ↦ ⟨V i, h.mem_of_mem hi, .rfl⟩ open UniformFun in theorem isUniformEmbedding_uniformFunOfFun : IsUniformEmbedding ((ofFun ·) : C(α, β) → α →ᵤ β) where comap_uniformity := UniformOnFun.uniformEquivUniformFun β _ isCompact_univ |>.isUniformEmbedding.comp isUniformEmbedding_toUniformOnFunIsCompact |>.comap_uniformity injective := DFunLike.coe_injective /-- Convergence in the compact-open topology is the same as uniform convergence for sequences of continuous functions on a compact space. -/ theorem tendsto_iff_tendstoUniformly : Tendsto F p (𝓝 f) ↔ TendstoUniformly (fun i a => F i a) f p := by simp [isUniformEmbedding_uniformFunOfFun.isInducing.tendsto_nhds_iff, UniformFun.tendsto_iff_tendstoUniformly, Function.comp_def] open UniformFun in /-- When `α` is compact, `f : X → C(α, β)` is continuous if any only if it is continuous when reinterpreted as a map `f : X → α →ᵤ β`. -/ theorem continuous_iff_continuous_uniformFun {X : Type*} [TopologicalSpace X] (f : X → C(α, β)) : Continuous f ↔ Continuous (fun x ↦ ofFun (f x)) := isUniformEmbedding_uniformFunOfFun.isInducing.continuous_iff end CompactDomain section ContinuousOnRestrict /-- Given functions `F i, f` which are continuous on a compact set `s`, `F` tends to `f` uniformly on `s` if and only if the restrictions (as elements of `C(s, β)`) converge. -/ theorem _root_.ContinuousOn.tendsto_restrict_iff_tendstoUniformlyOn {s : Set α} [CompactSpace s] {f : α → β} (hf : ContinuousOn f s) {ι : Type*} {p : Filter ι} {F : ι → α → β} (hF : ∀ i, ContinuousOn (F i) s) : Tendsto (fun i ↦ ⟨_, (hF i).restrict⟩ : ι → C(s, β)) p (𝓝 ⟨_, hf.restrict⟩) ↔ TendstoUniformlyOn F f p s := by rw [ContinuousMap.tendsto_iff_tendstoUniformly, tendstoUniformlyOn_iff_tendstoUniformly_comp_coe] congr! open UniformOnFun in /-- A family `f : X → α → β`, each of which is continuous on a compact set `s : Set α` is continuous in the topology `X → α →ᵤ[{s}] β` if and only if the family of continuous restrictions `X → C(s, β)` is continuous. -/ theorem _root_.ContinuousOn.continuous_restrict_iff_continuous_uniformOnFun {X : Type*} [TopologicalSpace X] {f : X → α → β} {s : Set α} (hf : ∀ x, ContinuousOn (f x) s) [CompactSpace s] : Continuous (fun x ↦ ⟨_, (hf x).restrict⟩ : X → C(s, β)) ↔ Continuous (fun x ↦ ofFun {s} (f x)) := by rw [ContinuousMap.continuous_iff_continuous_uniformFun, UniformOnFun.continuous_rng_iff] simp [Function.comp_def] end ContinuousOnRestrict theorem uniformSpace_eq_inf_precomp_of_cover {δ₁ δ₂ : Type*} [TopologicalSpace δ₁] [TopologicalSpace δ₂] (φ₁ : C(δ₁, α)) (φ₂ : C(δ₂, α)) (h_proper₁ : IsProperMap φ₁) (h_proper₂ : IsProperMap φ₂) (h_cover : range φ₁ ∪ range φ₂ = univ) : (inferInstanceAs <| UniformSpace C(α, β)) = .comap (comp · φ₁) inferInstance ⊓ .comap (comp · φ₂) inferInstance := by -- We check the analogous result for `UniformOnFun` using -- `UniformOnFun.uniformSpace_eq_inf_precomp_of_cover`... set 𝔖 : Set (Set α) := {K | IsCompact K} set 𝔗₁ : Set (Set δ₁) := {K | IsCompact K} set 𝔗₂ : Set (Set δ₂) := {K | IsCompact K} have h_image₁ : MapsTo (φ₁ '' ·) 𝔗₁ 𝔖 := fun K hK ↦ hK.image φ₁.continuous have h_image₂ : MapsTo (φ₂ '' ·) 𝔗₂ 𝔖 := fun K hK ↦ hK.image φ₂.continuous have h_preimage₁ : MapsTo (φ₁ ⁻¹' ·) 𝔖 𝔗₁ := fun K ↦ h_proper₁.isCompact_preimage have h_preimage₂ : MapsTo (φ₂ ⁻¹' ·) 𝔖 𝔗₂ := fun K ↦ h_proper₂.isCompact_preimage have h_cover' : ∀ S ∈ 𝔖, S ⊆ range φ₁ ∪ range φ₂ := fun S _ ↦ h_cover ▸ subset_univ _ -- ... and we just pull it back. simp_rw +zetaDelta [compactConvergenceUniformSpace, replaceTopology_eq, UniformOnFun.uniformSpace_eq_inf_precomp_of_cover _ _ _ _ _ h_image₁ h_image₂ h_preimage₁ h_preimage₂ h_cover', UniformSpace.comap_inf, ← UniformSpace.comap_comap] rfl theorem uniformSpace_eq_iInf_precomp_of_cover {δ : ι → Type*} [∀ i, TopologicalSpace (δ i)] (φ : Π i, C(δ i, α)) (h_proper : ∀ i, IsProperMap (φ i)) (h_lf : LocallyFinite fun i ↦ range (φ i)) (h_cover : ⋃ i, range (φ i) = univ) : (inferInstanceAs <| UniformSpace C(α, β)) = ⨅ i, .comap (comp · (φ i)) inferInstance := by -- We check the analogous result for `UniformOnFun` using -- `UniformOnFun.uniformSpace_eq_iInf_precomp_of_cover`... set 𝔖 : Set (Set α) := {K | IsCompact K} set 𝔗 : Π i, Set (Set (δ i)) := fun i ↦ {K | IsCompact K} have h_image : ∀ i, MapsTo (φ i '' ·) (𝔗 i) 𝔖 := fun i K hK ↦ hK.image (φ i).continuous have h_preimage : ∀ i, MapsTo (φ i ⁻¹' ·) 𝔖 (𝔗 i) := fun i K ↦ (h_proper i).isCompact_preimage have h_cover' : ∀ S ∈ 𝔖, ∃ I : Set ι, I.Finite ∧ S ⊆ ⋃ i ∈ I, range (φ i) := fun S hS ↦ by refine ⟨{i | (range (φ i) ∩ S).Nonempty}, h_lf.finite_nonempty_inter_compact hS, inter_eq_right.mp ?_⟩ simp_rw [iUnion₂_inter, mem_setOf, iUnion_nonempty_self, ← iUnion_inter, h_cover, univ_inter] -- ... and we just pull it back. simp_rw +zetaDelta [compactConvergenceUniformSpace, replaceTopology_eq, UniformOnFun.uniformSpace_eq_iInf_precomp_of_cover _ _ _ h_image h_preimage h_cover', UniformSpace.comap_iInf, ← UniformSpace.comap_comap] rfl section CompleteSpace variable [CompleteSpace β] /-- If the topology on `α` is generated by its restrictions to compact sets, then the space of continuous maps `C(α, β)` is complete (w.r.t. the compact convergence uniformity). Sufficient conditions on `α` to satisfy this condition are (weak) local compactness and sequential compactness. -/ instance instCompleteSpaceOfCompactlyCoherentSpace [CompactlyCoherentSpace α] : CompleteSpace C(α, β) := by rw [completeSpace_iff_isComplete_range isUniformEmbedding_toUniformOnFunIsCompact.isUniformInducing, range_toUniformOnFunIsCompact, ← completeSpace_coe_iff_isComplete] exact (UniformOnFun.isClosed_setOf_continuous CompactlyCoherentSpace.isCoherentWith).completeSpace_coe @[deprecated (since := "2025-06-03")] alias completeSpace_of_isCoherentWith := instCompleteSpaceOfCompactlyCoherentSpace end CompleteSpace /-- If `C(α, β)` is a complete space, then for any (possibly, discontinuous) function `f` and any set `s`, the set of functions `g : C(α, β)` that are equal to `f` on `s` is a complete set. Note that this set does not have to be a closed set when `β` is not T0. This lemma is useful to prove that, e.g., the space of paths between two points and the space of homotopies between two continuous maps are complete spaces, without assuming that the codomain is a Hausdorff space. -/ theorem isComplete_setOf_eqOn [CompleteSpace C(α, β)] (f : α → β) (s : Set α) : IsComplete {g : C(α, β) | EqOn g f s} := by classical intro l hlc hlf rcases CompleteSpace.complete hlc with ⟨f', hf'⟩ have := hlc.1 have H₁ : ∀ x ∈ s, Inseparable (f x) (f' x) := fun x hx ↦ by refine tendsto_nhds_unique_inseparable ?_ ((continuous_eval_const x).continuousAt.mono_left hf') refine tendsto_const_nhds.congr' <| .filter_mono ?_ hlf exact fun _ h ↦ (h hx).symm have H₂ (x) : Inseparable (s.piecewise f f' x) (f' x) := by by_cases hx : x ∈ s <;> simp [hx, H₁, Inseparable.refl] set g : C(α, β) := ⟨s.piecewise f f', (continuous_congr_of_inseparable H₂).mpr <| map_continuous f'⟩ refine ⟨g, Set.piecewise_eqOn _ _ _, hf'.trans_eq ?_⟩ rwa [eq_comm, ← Inseparable, ← inseparable_coe, inseparable_pi] end ContinuousMap
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Pi.lean
import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Indexed product of uniform spaces -/ noncomputable section open scoped Uniformity Topology open Filter UniformSpace Function Set universe u variable {ι ι' β : Type*} (α : ι → Type u) [U : ∀ i, UniformSpace (α i)] [UniformSpace β] instance Pi.uniformSpace : UniformSpace (∀ i, α i) := UniformSpace.ofCoreEq (⨅ i, UniformSpace.comap (eval i) (U i)).toCore Pi.topologicalSpace <| Eq.symm toTopologicalSpace_iInf lemma Pi.uniformSpace_eq : Pi.uniformSpace α = ⨅ i, UniformSpace.comap (eval i) (U i) := by ext : 1; rfl theorem Pi.uniformity : 𝓤 (∀ i, α i) = ⨅ i : ι, (Filter.comap fun a => (a.1 i, a.2 i)) (𝓤 (α i)) := iInf_uniformity variable {α} instance [Countable ι] [∀ i, IsCountablyGenerated (𝓤 (α i))] : IsCountablyGenerated (𝓤 (∀ i, α i)) := by rw [Pi.uniformity] infer_instance theorem uniformContinuous_pi {β : Type*} [UniformSpace β] {f : β → ∀ i, α i} : UniformContinuous f ↔ ∀ i, UniformContinuous fun x => f x i := by simp only [UniformContinuous, Pi.uniformity, tendsto_iInf, tendsto_comap_iff, Function.comp_def] variable (α) theorem Pi.uniformContinuous_proj (i : ι) : UniformContinuous fun a : ∀ i : ι, α i => a i := uniformContinuous_pi.1 uniformContinuous_id i theorem Pi.uniformContinuous_precomp' (φ : ι' → ι) : UniformContinuous (fun (f : (∀ i, α i)) (j : ι') ↦ f (φ j)) := uniformContinuous_pi.mpr fun j ↦ uniformContinuous_proj α (φ j) theorem Pi.uniformContinuous_precomp (φ : ι' → ι) : UniformContinuous (· ∘ φ : (ι → β) → (ι' → β)) := Pi.uniformContinuous_precomp' _ φ theorem Pi.uniformContinuous_postcomp' {β : ι → Type*} [∀ i, UniformSpace (β i)] {g : ∀ i, α i → β i} (hg : ∀ i, UniformContinuous (g i)) : UniformContinuous (fun (f : (∀ i, α i)) (i : ι) ↦ g i (f i)) := uniformContinuous_pi.mpr fun i ↦ (hg i).comp <| uniformContinuous_proj α i theorem Pi.uniformContinuous_postcomp {α : Type*} [UniformSpace α] {g : α → β} (hg : UniformContinuous g) : UniformContinuous (g ∘ · : (ι → α) → (ι → β)) := Pi.uniformContinuous_postcomp' _ fun _ ↦ hg lemma Pi.uniformSpace_comap_precomp' (φ : ι' → ι) : UniformSpace.comap (fun g i' ↦ g (φ i')) (Pi.uniformSpace (fun i' ↦ α (φ i'))) = ⨅ i', UniformSpace.comap (eval (φ i')) (U (φ i')) := by simp [Pi.uniformSpace_eq, UniformSpace.comap_iInf, ← UniformSpace.comap_comap, comp_def] lemma Pi.uniformSpace_comap_precomp (φ : ι' → ι) : UniformSpace.comap (· ∘ φ) (Pi.uniformSpace (fun _ ↦ β)) = ⨅ i', UniformSpace.comap (eval (φ i')) ‹UniformSpace β› := uniformSpace_comap_precomp' (fun _ ↦ β) φ lemma Pi.uniformContinuous_restrict (S : Set ι) : UniformContinuous (S.restrict : (∀ i : ι, α i) → (∀ i : S, α i)) := Pi.uniformContinuous_precomp' _ ((↑) : S → ι) lemma Pi.uniformSpace_comap_restrict (S : Set ι) : UniformSpace.comap (S.restrict) (Pi.uniformSpace (fun i : S ↦ α i)) = ⨅ i ∈ S, UniformSpace.comap (eval i) (U i) := by simp +unfoldPartialApp [← iInf_subtype'', ← uniformSpace_comap_precomp' _ ((↑) : S → ι), Set.restrict] lemma cauchy_pi_iff [Nonempty ι] {l : Filter (∀ i, α i)} : Cauchy l ↔ ∀ i, Cauchy (map (eval i) l) := by simp_rw [Pi.uniformSpace_eq, cauchy_iInf_uniformSpace, cauchy_comap_uniformSpace] lemma cauchy_pi_iff' {l : Filter (∀ i, α i)} [l.NeBot] : Cauchy l ↔ ∀ i, Cauchy (map (eval i) l) := by simp_rw [Pi.uniformSpace_eq, cauchy_iInf_uniformSpace', cauchy_comap_uniformSpace] lemma Cauchy.pi [Nonempty ι] {l : ∀ i, Filter (α i)} (hl : ∀ i, Cauchy (l i)) : Cauchy (Filter.pi l) := by have := fun i ↦ (hl i).1 simpa [cauchy_pi_iff] instance Pi.complete [∀ i, CompleteSpace (α i)] : CompleteSpace (∀ i, α i) where complete {f} hf := by have := hf.1 simp_rw [cauchy_pi_iff', cauchy_iff_exists_le_nhds] at hf choose x hx using hf use x rwa [nhds_pi, le_pi] lemma Pi.uniformSpace_comap_restrict_sUnion (𝔖 : Set (Set ι)) : UniformSpace.comap (⋃₀ 𝔖).restrict (Pi.uniformSpace (fun i : (⋃₀ 𝔖) ↦ α i)) = ⨅ S ∈ 𝔖, UniformSpace.comap S.restrict (Pi.uniformSpace (fun i : S ↦ α i)) := by simp_rw [Pi.uniformSpace_comap_restrict α, iInf_sUnion] /- An infimum of complete uniformities is complete, as long as the whole family is bounded by some common T2 topology. -/ protected theorem CompleteSpace.iInf {ι X : Type*} {u : ι → UniformSpace X} (hu : ∀ i, @CompleteSpace X (u i)) (ht : ∃ t, @T2Space X t ∧ ∀ i, (u i).toTopologicalSpace ≤ t) : @CompleteSpace X (⨅ i, u i) := by -- We can assume `X` is nonempty. nontriviality X rcases ht with ⟨t, ht, hut⟩ -- The diagonal map `(X, ⨅ i, u i) → ∀ i, (X, u i)` is a uniform embedding. have : @IsUniformInducing X (ι → X) (⨅ i, u i) (Pi.uniformSpace (U := u)) (const ι) := by simp_rw [isUniformInducing_iff, iInf_uniformity, Pi.uniformity, Filter.comap_iInf, Filter.comap_comap, comp_def, const, Prod.eta, comap_id'] -- Hence, it suffices to show that its range, the diagonal, is closed in `Π i, (X, u i)`. simp_rw [@completeSpace_iff_isComplete_range _ _ (_) (_) _ this, range_const_eq_diagonal, setOf_forall] -- The separation of `t` ensures that this is the case in `Π i, (X, t)`, hence the result -- since the topology associated to each `u i` is finer than `t`. have : Pi.topologicalSpace (t₂ := fun i ↦ (u i).toTopologicalSpace) ≤ Pi.topologicalSpace (t₂ := fun _ ↦ t) := iInf_mono fun i ↦ induced_mono <| hut i refine IsClosed.isComplete <| .mono ?_ this exact isClosed_iInter fun i ↦ isClosed_iInter fun j ↦ isClosed_eq (continuous_apply _) (continuous_apply _)
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/ProdApproximation.lean
import Mathlib.Topology.Algebra.Indicator import Mathlib.Topology.ContinuousMap.Algebra import Mathlib.Topology.Separation.DisjointCover /-! # Uniform approximation by products We show that if `X, Y` are compact Hausdorff spaces with `X` profinite, then any continuous function on `X × Y` valued in a ring (with a uniform structure) can be uniformly approximated by finite sums of functions of the form `f x * g y`. -/ open UniformSpace open scoped Uniformity namespace ContinuousMap variable {X Y R V : Type*} [TopologicalSpace X] [TotallyDisconnectedSpace X] [T2Space X] [CompactSpace X] [TopologicalSpace Y] [CompactSpace Y] [AddCommGroup V] [UniformSpace V] [IsUniformAddGroup V] {S : Set (V × V)} /-- A continuous function on `X × Y`, taking values in an `R`-module with a uniform structure, can be uniformly approximated by sums of functions of the form `(x, y) ↦ f x • g y`. Note that no continuity properties are assumed either for multiplication on `R`, or for the scalar multiplication of `R` on `V`. -/ lemma exists_finite_sum_smul_approximation_of_mem_uniformity [TopologicalSpace R] [MonoidWithZero R] [MulActionWithZero R V] (f : C(X × Y, V)) (hS : S ∈ 𝓤 V) : ∃ (n : ℕ) (g : Fin n → C(X, R)) (h : Fin n → C(Y, V)), ∀ x y, (f (x, y), ∑ i, g i x • h i y) ∈ S := by have hS' : {(f, g) | ∀ y, (f y, g y) ∈ S} ∈ 𝓤 C(Y, V) := (mem_compactConvergence_entourage_iff _).mpr ⟨_, _, isCompact_univ, hS, by simp only [Set.mem_univ, true_implies, subset_refl]⟩ obtain ⟨n, U, v, hv⟩ := exists_finite_sum_const_indicator_approximation_of_mem_nhds_diagonal f.curry (nhdsSet_diagonal_le_uniformity hS') refine ⟨n, fun i ↦ ⟨_, (U i).isClopen.continuous_indicator <| continuous_const (y := 1)⟩, v, fun x y ↦ ?_⟩ convert hv x y using 2 simp only [sum_apply] congr 1 with i by_cases hi : x ∈ U i <;> simp [hi] /-- A continuous function on `X × Y`, taking values in a ring `R` equipped with a uniformity compatible with addition, can be uniformly approximated by sums of functions of the form `(x, y) ↦ f x * g y`. Note that no assumption is needed relating the multiplication on `R` to the uniformity. -/ lemma exists_finite_sum_mul_approximation_of_mem_uniformity [Ring R] [UniformSpace R] [IsUniformAddGroup R] (f : C(X × Y, R)) {S : Set (R × R)} (hS : S ∈ 𝓤 R) : ∃ (n : ℕ) (g : Fin n → C(X, R)) (h : Fin n → C(Y, R)), ∀ x y, (f (x, y), ∑ i, g i x * h i y) ∈ S := exists_finite_sum_smul_approximation_of_mem_uniformity f hS end ContinuousMap
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/UniformApproximation.lean
import Mathlib.Topology.UniformSpace.LocallyUniformConvergence /-! # Uniform approximation In this file, we give lemmas ensuring that a function is continuous if it can be approximated uniformly by continuous functions. We give various versions, within a set or the whole space, at a single point or at all points, with locally uniform approximation or uniform approximation. All the statements are derived from a statement about locally uniform approximation within a set at a point, called `continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt`. ## Implementation notes Most results hold under weaker assumptions of locally uniform approximation. In a first section, we prove the results under these weaker assumptions. Then, we derive the results on uniform convergence from them. ## Tags Uniform limit, uniform convergence, tends uniformly to -/ noncomputable section open Topology Uniformity Filter SetRel Set Uniform variable {α β ι : Type*} [TopologicalSpace α] [UniformSpace β] variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {g : ι → α} /-- A function which can be locally uniformly approximated by functions which are continuous within a set at a point is continuous within this set at this point. -/ theorem continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt (hx : x ∈ s) (L : ∀ u ∈ 𝓤 β, ∃ t ∈ 𝓝[s] x, ∃ F : α → β, ContinuousWithinAt F s x ∧ ∀ y ∈ t, (f y, F y) ∈ u) : ContinuousWithinAt f s x := by refine Uniform.continuousWithinAt_iff'_left.2 fun u₀ hu₀ => ?_ obtain ⟨u₁, h₁, u₁₀⟩ : ∃ u ∈ 𝓤 β, u ○ u ⊆ u₀ := comp_mem_uniformity_sets hu₀ obtain ⟨u₂, h₂, hsymm, u₂₁⟩ : ∃ u ∈ 𝓤 β, (∀ {a b}, (a, b) ∈ u → (b, a) ∈ u) ∧ u ○ u ⊆ u₁ := comp_symm_of_uniformity h₁ rcases L u₂ h₂ with ⟨t, tx, F, hFc, hF⟩ have A : ∀ᶠ y in 𝓝[s] x, (f y, F y) ∈ u₂ := Eventually.mono tx hF have B : ∀ᶠ y in 𝓝[s] x, (F y, F x) ∈ u₂ := Uniform.continuousWithinAt_iff'_left.1 hFc h₂ have C : ∀ᶠ y in 𝓝[s] x, (f y, F x) ∈ u₁ := (A.and B).mono fun y hy => u₂₁ (prodMk_mem_comp hy.1 hy.2) have : (F x, f x) ∈ u₁ := u₂₁ (prodMk_mem_comp (refl_mem_uniformity h₂) (hsymm (A.self_of_nhdsWithin hx))) exact C.mono fun y hy => u₁₀ <| prodMk_mem_comp hy this /-- A function which can be locally uniformly approximated by functions which are continuous at a point is continuous at this point. -/ theorem continuousAt_of_locally_uniform_approx_of_continuousAt (L : ∀ u ∈ 𝓤 β, ∃ t ∈ 𝓝 x, ∃ F, ContinuousAt F x ∧ ∀ y ∈ t, (f y, F y) ∈ u) : ContinuousAt f x := by rw [← continuousWithinAt_univ] apply continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt (mem_univ _) _ simpa only [exists_prop, nhdsWithin_univ, continuousWithinAt_univ] using L /-- A function which can be locally uniformly approximated by functions which are continuous on a set is continuous on this set. -/ theorem continuousOn_of_locally_uniform_approx_of_continuousWithinAt (L : ∀ x ∈ s, ∀ u ∈ 𝓤 β, ∃ t ∈ 𝓝[s] x, ∃ F, ContinuousWithinAt F s x ∧ ∀ y ∈ t, (f y, F y) ∈ u) : ContinuousOn f s := fun x hx => continuousWithinAt_of_locally_uniform_approx_of_continuousWithinAt hx (L x hx) /-- A function which can be uniformly approximated by functions which are continuous on a set is continuous on this set. -/ theorem continuousOn_of_uniform_approx_of_continuousOn (L : ∀ u ∈ 𝓤 β, ∃ F, ContinuousOn F s ∧ ∀ y ∈ s, (f y, F y) ∈ u) : ContinuousOn f s := continuousOn_of_locally_uniform_approx_of_continuousWithinAt fun _x hx u hu => ⟨s, self_mem_nhdsWithin, (L u hu).imp fun _F hF => ⟨hF.1.continuousWithinAt hx, hF.2⟩⟩ /-- A function which can be locally uniformly approximated by continuous functions is continuous. -/ theorem continuous_of_locally_uniform_approx_of_continuousAt (L : ∀ x : α, ∀ u ∈ 𝓤 β, ∃ t ∈ 𝓝 x, ∃ F, ContinuousAt F x ∧ ∀ y ∈ t, (f y, F y) ∈ u) : Continuous f := continuous_iff_continuousAt.2 fun x => continuousAt_of_locally_uniform_approx_of_continuousAt (L x) /-- A function which can be uniformly approximated by continuous functions is continuous. -/ theorem continuous_of_uniform_approx_of_continuous (L : ∀ u ∈ 𝓤 β, ∃ F, Continuous F ∧ ∀ y, (f y, F y) ∈ u) : Continuous f := continuousOn_univ.mp <| continuousOn_of_uniform_approx_of_continuousOn <| by simpa [continuousOn_univ] using L /-! ### Uniform limits From the previous statements on uniform approximation, we deduce continuity results for uniform limits. -/ /-- A locally uniform limit on a set of functions which are continuous on this set is itself continuous on this set. -/ protected theorem TendstoLocallyUniformlyOn.continuousOn (h : TendstoLocallyUniformlyOn F f p s) (hc : ∀ᶠ n in p, ContinuousOn (F n) s) [NeBot p] : ContinuousOn f s := by refine continuousOn_of_locally_uniform_approx_of_continuousWithinAt fun x hx u hu => ?_ rcases h u hu x hx with ⟨t, ht, H⟩ rcases (hc.and H).exists with ⟨n, hFc, hF⟩ exact ⟨t, ht, ⟨F n, hFc.continuousWithinAt hx, hF⟩⟩ /-- A uniform limit on a set of functions which are continuous on this set is itself continuous on this set. -/ protected theorem TendstoUniformlyOn.continuousOn (h : TendstoUniformlyOn F f p s) (hc : ∀ᶠ n in p, ContinuousOn (F n) s) [NeBot p] : ContinuousOn f s := h.tendstoLocallyUniformlyOn.continuousOn hc /-- A locally uniform limit of continuous functions is continuous. -/ protected theorem TendstoLocallyUniformly.continuous (h : TendstoLocallyUniformly F f p) (hc : ∀ᶠ n in p, Continuous (F n)) [NeBot p] : Continuous f := continuousOn_univ.mp <| h.tendstoLocallyUniformlyOn.continuousOn <| hc.mono fun _n hn => hn.continuousOn /-- A uniform limit of continuous functions is continuous. -/ protected theorem TendstoUniformly.continuous (h : TendstoUniformly F f p) (hc : ∀ᶠ n in p, Continuous (F n)) [NeBot p] : Continuous f := h.tendstoLocallyUniformly.continuous hc /-! ### Composing limits under uniform convergence In general, if `Fₙ` converges pointwise to a function `f`, and `gₙ` tends to `x`, it is not true that `Fₙ gₙ` tends to `f x`. It is true however if the convergence of `Fₙ` to `f` is uniform. In this paragraph, we prove variations around this statement. -/ /-- If `Fₙ` converges locally uniformly on a neighborhood of `x` within a set `s` to a function `f` which is continuous at `x` within `s`, and `gₙ` tends to `x` within `s`, then `Fₙ (gₙ)` tends to `f x`. -/ theorem tendsto_comp_of_locally_uniform_limit_within (h : ContinuousWithinAt f s x) (hg : Tendsto g p (𝓝[s] x)) (hunif : ∀ u ∈ 𝓤 β, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u) : Tendsto (fun n => F n (g n)) p (𝓝 (f x)) := by refine Uniform.tendsto_nhds_right.2 fun u₀ hu₀ => ?_ obtain ⟨u₁, h₁, u₁₀⟩ : ∃ u ∈ 𝓤 β, u ○ u ⊆ u₀ := comp_mem_uniformity_sets hu₀ rcases hunif u₁ h₁ with ⟨s, sx, hs⟩ have A : ∀ᶠ n in p, g n ∈ s := hg sx have B : ∀ᶠ n in p, (f x, f (g n)) ∈ u₁ := hg (Uniform.continuousWithinAt_iff'_right.1 h h₁) exact B.mp <| A.mp <| hs.mono fun y H1 H2 H3 => u₁₀ <| prodMk_mem_comp H3 <| H1 _ H2 /-- If `Fₙ` converges locally uniformly on a neighborhood of `x` to a function `f` which is continuous at `x`, and `gₙ` tends to `x`, then `Fₙ (gₙ)` tends to `f x`. -/ theorem tendsto_comp_of_locally_uniform_limit (h : ContinuousAt f x) (hg : Tendsto g p (𝓝 x)) (hunif : ∀ u ∈ 𝓤 β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u) : Tendsto (fun n => F n (g n)) p (𝓝 (f x)) := by rw [← continuousWithinAt_univ] at h rw [← nhdsWithin_univ] at hunif hg exact tendsto_comp_of_locally_uniform_limit_within h hg hunif /-- If `Fₙ` tends locally uniformly to `f` on a set `s`, and `gₙ` tends to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s` and `x ∈ s`. -/ theorem TendstoLocallyUniformlyOn.tendsto_comp (h : TendstoLocallyUniformlyOn F f p s) (hf : ContinuousWithinAt f s x) (hx : x ∈ s) (hg : Tendsto g p (𝓝[s] x)) : Tendsto (fun n => F n (g n)) p (𝓝 (f x)) := tendsto_comp_of_locally_uniform_limit_within hf hg fun u hu => h u hu x hx /-- If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`. -/ theorem TendstoUniformlyOn.tendsto_comp (h : TendstoUniformlyOn F f p s) (hf : ContinuousWithinAt f s x) (hg : Tendsto g p (𝓝[s] x)) : Tendsto (fun n => F n (g n)) p (𝓝 (f x)) := tendsto_comp_of_locally_uniform_limit_within hf hg fun u hu => ⟨s, self_mem_nhdsWithin, h u hu⟩ /-- If `Fₙ` tends locally uniformly to `f`, and `gₙ` tends to `x`, then `Fₙ gₙ` tends to `f x`. -/ theorem TendstoLocallyUniformly.tendsto_comp (h : TendstoLocallyUniformly F f p) (hf : ContinuousAt f x) (hg : Tendsto g p (𝓝 x)) : Tendsto (fun n => F n (g n)) p (𝓝 (f x)) := tendsto_comp_of_locally_uniform_limit hf hg fun u hu => h u hu x /-- If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then `Fₙ gₙ` tends to `f x`. -/ theorem TendstoUniformly.tendsto_comp (h : TendstoUniformly F f p) (hf : ContinuousAt f x) (hg : Tendsto g p (𝓝 x)) : Tendsto (fun n => F n (g n)) p (𝓝 (f x)) := h.tendstoLocallyUniformly.tendsto_comp hf hg
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Basic.lean
import Mathlib.Data.Rel import Mathlib.Order.Filter.SmallSets import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notation Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology open scoped SetRel Uniformity universe u v ua ub uc ud /-! ### Relations, seen as `SetRel α α` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} open scoped SetRel in lemma IsOpen.relComp [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {s : SetRel α β} {t : SetRel β γ} (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ○ t) := by conv => arg 1; equals ⋃ b, (fun p => (p.1, b)) ⁻¹' s ∩ (fun p => (b, p.2)) ⁻¹' t => ext ⟨_, _⟩; simp exact isOpen_iUnion fun a ↦ hs.preimage (by fun_prop) |>.inter <| ht.preimage (by fun_prop) lemma IsOpen.relInv [TopologicalSpace α] [TopologicalSpace β] {s : SetRel α β} (hs : IsOpen s) : IsOpen s.inv := hs.preimage continuous_swap lemma IsOpen.relImage [TopologicalSpace α] [TopologicalSpace β] {s : SetRel α β} (hs : IsOpen s) {t : Set α} : IsOpen (s.image t) := by simp_rw [SetRel.image, ← exists_prop, Set.setOf_exists] exact isOpen_biUnion fun _ _ => hs.preimage <| .prodMk_right _ lemma IsOpen.relPreimage [TopologicalSpace α] [TopologicalSpace β] {s : SetRel α β} (hs : IsOpen s) {t : Set β} : IsOpen (s.preimage t) := hs.relInv.relImage section UniformSpace variable [UniformSpace α] /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : SetRel α α} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction n generalizing s with | zero => simpa | succ _ ihn => rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] have : SetRel.IsRefl t := SetRel.id_subset_iff.1 <| refl_le_uniformity htU exact ⟨hU.1.trans <| SetRel.left_subset_comp.trans hts, (SetRel.comp_subset_comp hU.1 hU.2).trans hts⟩ /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : SetRel α α} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : SetRel α α} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ SetRel.IsSymm s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, inferInstance⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : SetRel α α => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : SetRel α α} (s : SetRel α α) (hd : d ∈ 𝓤 α) : ∃ t : SetRel α α, IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : SetRel α α), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → SetRel α α, HasAntitoneBasis (𝓤 α) V ∧ ∀ n, SetRel.IsSymm (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ {V | V ∈ 𝓤 α ∧ SetRel.IsSymm V}, V ○ s ○ V := by ext ⟨x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : SetRel α α => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → SetRel α α} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : SetRel α α => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : SetRel α α} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ SetRel.IsSymm V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => by dsimp at *; gcongr _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp [SetRel.comp_assoc] theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : SetRel α α} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : SetRel α α} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : SetRel α α} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : SetRel α α} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : SetRel α α => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → SetRel α α} (h : (𝓤 α).HasBasis p s) {t : SetRel α α} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : SetRel α α` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : SetRel α α => V ∈ 𝓤 α ∧ IsOpen V ∧ SetRel.IsSymm V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨SetRel.symmetrize s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, inferInstance, SetRel.symmetrize_subset_self⟩ theorem comp_open_symm_mem_uniformity_sets {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ SetRel.IsSymm t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (SetRel.comp_subset_comp hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 SetRel.id symm := by simp [Tendsto, SetRel.id] comp := lift'_le (mem_principal_self _) <| principal_mono.2 (SetRel.id_comp _).subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [SetRel.id] }⟩ instance : Min (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) where sup a b := sInf { x | a ≤ x ∧ b ≤ x } le_sup_left _ _ := UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right _ _ := UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le _ _ _ h₁ h₂ := UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf a _ _ h₁ h₂ := show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left a _ := show _ ≤ a.uniformity from inf_le_left inf_le_right _ b := show _ ≤ b.uniformity from inf_le_right le_top a := show a.uniformity ≤ ⊤ from le_top bot_le u := u.toCore.refl sSup tt := sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup _ _ h := UniformSpace.le_sInf fun _ h' => h' _ h sSup_le _ _ h := UniformSpace.sInf_le h le_sInf _ _ hs := UniformSpace.le_sInf hs sInf_le _ _ ha := UniformSpace.sInf_le ha theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 SetRel.id := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [SetRel.id, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.relComp monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl lemma ball_preimage {f : α → β} {U : SetRel β β} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ SetRel.id ∈ 𝓤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → SetRel α α} {u : UniformSpace α} (h : 𝓤[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace section variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] {f : α → β} {s t : Set α} theorem UniformContinuous.continuous (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf lemma UniformContinuous.uniformContinuousOn (hf : UniformContinuous f) : UniformContinuousOn f s := tendsto_inf_left hf lemma UniformContinuousOn.mono (hf : UniformContinuousOn f s) (ht : t ⊆ s) : UniformContinuousOn f t := Tendsto.mono_left hf (inf_le_inf le_rfl (by simp [ht])) lemma UniformContinuousOn.congr {f g : α → β} {s : Set α} (hf : UniformContinuousOn f s) (h : EqOn f g s) : UniformContinuousOn g s := by apply hf.congr' apply EventuallyEq.filter_mono _ inf_le_right filter_upwards [mem_principal_self _] with ⟨a, b⟩ ⟨ha, hb⟩ using by simp [h ha, h hb] lemma UniformContinuousOn.comp {g : β → γ} {t : Set β} (hg : UniformContinuousOn g t) (hf : UniformContinuousOn f s) (hst : MapsTo f s t) : UniformContinuousOn (g ∘ f) s := by change Tendsto ((fun x ↦ (g x.1, g x.2)) ∘ (fun x ↦ (f x.1, f x.2))) (𝓤 α ⊓ 𝓟 (s ×ˢ s)) (𝓤 γ) apply Tendsto.comp hg refine tendsto_inf.2 ⟨hf, tendsto_inf_right ?_⟩ simp only [tendsto_principal, mem_prod, eventually_principal, and_imp, Prod.forall] exact fun a b ha hb ↦ ⟨hst ha, hst hb⟩ lemma UniformContinuous.comp_uniformContinuousOn {g : β → γ} (hg : UniformContinuous g) (hf : UniformContinuousOn f s) : UniformContinuousOn (g ∘ f) s := (hg.uniformContinuousOn (s := univ)).comp hf (mapsTo_univ _ _) end /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 SetRel.id) : DiscreteTopology α := ⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace ℤ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem UniformContinuous.subtype_map [UniformSpace α] [UniformSpace β] {p : α → Prop} {q : β → Prop} {f : α → β} (hf : UniformContinuous f) (h : ∀ x, p x → q (f x)) : UniformContinuous (Subtype.map f h) := (hf.comp uniformContinuous_subtype_val).subtype_mk _ theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = ((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)] [UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : SetRel β β} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩ exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : SetRel α α) (v : SetRel β β) : SetRel (α × β) (α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : SetRel α α} {v : SetRel β β} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : SetRel α α} {v : SetRel β β} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) : entourageProd u v ∈ 𝓤 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : SetRel α α) (v : SetRel β β) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] instance IsSymm_entourageProd {u : SetRel α α} {v : SetRel β β} [u.IsSymm] [v.IsSymm] : (entourageProd u v).IsSymm where symm _ _ := .imp u.symm v.symm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β] {pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → SetRel α α} {sb : ιb → SetRel β β} (ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) : (𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2) (fun i ↦ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) : ∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩ use w.1, hw.1.1, w.2, hw.1.2, hw.2 theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) := le_trans (map_mono inf_le_left) map_comap_le theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) := le_trans (map_mono inf_le_right) map_comap_le theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.1 := tendsto_prod_uniformity_fst theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.2 := tendsto_prod_uniformity_snd variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] theorem UniformContinuous.prodMk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁) (h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by rw [UniformContinuous, uniformity_prod] exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ theorem UniformContinuous.prodMk_left {f : α × β → γ} (h : UniformContinuous f) (b) : UniformContinuous fun a => f (a, b) := h.comp (uniformContinuous_id.prodMk uniformContinuous_const) theorem UniformContinuous.prodMk_right {f : α × β → γ} (h : UniformContinuous f) (a) : UniformContinuous fun b => f (a, b) := h.comp (uniformContinuous_const.prodMk uniformContinuous_id) theorem UniformContinuous.prodMap [UniformSpace δ] {f : α → γ} {g : β → δ} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) := (hf.comp uniformContinuous_fst).prodMk (hg.comp uniformContinuous_snd) lemma uniformContinuous_swap : UniformContinuous (Prod.swap : α × β → β × α) := uniformContinuous_snd.prodMk uniformContinuous_fst theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] : @UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd = @instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace := rfl /-- A version of `UniformContinuous.inf_dom_left` for binary functions -/ theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_left₂` have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `UniformContinuous.inf_dom_right` for binary functions -/ theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_right₂` have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `uniformContinuous_sInf_dom` for binary functions -/ theorem uniformContinuous_sInf_dom₂ {α β γ} {f : α → β → γ} {uas : Set (UniformSpace α)} {ubs : Set (UniformSpace β)} {ua : UniformSpace α} {ub : UniformSpace β} {uc : UniformSpace γ} (ha : ua ∈ uas) (hb : ub ∈ ubs) (hf : UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := sInf uas; haveI := sInf ubs exact @UniformContinuous _ _ _ uc fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_sInf_dom` let _ : UniformSpace (α × β) := instUniformSpaceProd have ha := uniformContinuous_sInf_dom ha uniformContinuous_id have hb := uniformContinuous_sInf_dom hb uniformContinuous_id have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (sInf uas) (sInf ubs) ua ub _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ hf h_unif_cont_id end Prod section open UniformSpace Function variable {δ' : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace δ] [UniformSpace δ'] local notation f " ∘₂ " g => Function.bicompr f g /-- Uniform continuity for functions of two variables. -/ def UniformContinuous₂ (f : α → β → γ) := UniformContinuous (uncurry f) theorem uniformContinuous₂_def (f : α → β → γ) : UniformContinuous₂ f ↔ UniformContinuous (uncurry f) := Iff.rfl theorem UniformContinuous₂.uniformContinuous {f : α → β → γ} (h : UniformContinuous₂ f) : UniformContinuous (uncurry f) := h theorem uniformContinuous₂_curry (f : α × β → γ) : UniformContinuous₂ (Function.curry f) ↔ UniformContinuous f := by rw [UniformContinuous₂, uncurry_curry] theorem UniformContinuous₂.comp {f : α → β → γ} {g : γ → δ} (hg : UniformContinuous g) (hf : UniformContinuous₂ f) : UniformContinuous₂ (g ∘₂ f) := hg.comp hf theorem UniformContinuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β} (hf : UniformContinuous₂ f) (hga : UniformContinuous ga) (hgb : UniformContinuous gb) : UniformContinuous₂ (bicompl f ga gb) := hf.uniformContinuous.comp (hga.prodMap hgb) end theorem toTopologicalSpace_subtype [u : UniformSpace α] {p : α → Prop} : @UniformSpace.toTopologicalSpace (Subtype p) instUniformSpaceSubtype = @instTopologicalSpaceSubtype α p u.toTopologicalSpace := rfl section Sum variable [UniformSpace α] [UniformSpace β] open Sum -- Obsolete auxiliary definitions and lemmas /-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained by taking independently an entourage of the diagonal in the first part, and an entourage of the diagonal in the second part. -/ instance Sum.instUniformSpace : UniformSpace (α ⊕ β) where uniformity := map (fun p : α × α => (inl p.1, inl p.2)) (𝓤 α) ⊔ map (fun p : β × β => (inr p.1, inr p.2)) (𝓤 β) symm := fun _ hs ↦ ⟨symm_le_uniformity hs.1, symm_le_uniformity hs.2⟩ comp := fun s hs ↦ by rcases comp_mem_uniformity_sets hs.1 with ⟨tα, htα, Htα⟩ rcases comp_mem_uniformity_sets hs.2 with ⟨tβ, htβ, Htβ⟩ filter_upwards [mem_lift' (union_mem_sup (image_mem_map htα) (image_mem_map htβ))] rintro ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩ exacts [@Htα (_, _) ⟨b, hab, hbc⟩, @Htβ (_, _) ⟨b, hab, hbc⟩] nhds_eq_comap_uniformity x := by ext cases x <;> simp [mem_comap', -mem_comap, nhds_inl, nhds_inr, nhds_eq_comap_uniformity, Prod.ext_iff] /-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage of the diagonal. -/ theorem union_mem_uniformity_sum {a : SetRel α α} (ha : a ∈ 𝓤 α) {b : SetRel β β} (hb : b ∈ 𝓤 β) : Prod.map inl inl '' a ∪ Prod.map inr inr '' b ∈ 𝓤 (α ⊕ β) := union_mem_sup (image_mem_map ha) (image_mem_map hb) theorem Sum.uniformity : 𝓤 (α ⊕ β) = map (Prod.map inl inl) (𝓤 α) ⊔ map (Prod.map inr inr) (𝓤 β) := rfl lemma uniformContinuous_inl : UniformContinuous (Sum.inl : α → α ⊕ β) := le_sup_left lemma uniformContinuous_inr : UniformContinuous (Sum.inr : β → α ⊕ β) := le_sup_right instance [IsCountablyGenerated (𝓤 α)] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α ⊕ β)) := by rw [Sum.uniformity] infer_instance end Sum end Constructions /-! ### Expressing continuity properties in uniform spaces We reformulate the various continuity properties of functions taking values in a uniform space in terms of the uniformity in the target. Since the same lemmas (essentially with the same names) also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or the edistance in the target), we put them in a namespace `Uniform` here. In the metric and emetric space setting, there are also similar lemmas where one assumes that both the source and the target are metric spaces, reformulating things in terms of the distance on both sides. These lemmas are generally written without primes, and the versions where only the target is a metric space is primed. We follow the same convention here, thus giving lemmas with primes. -/ namespace Uniform variable [UniformSpace α] theorem tendsto_nhds_right {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (a, u x)) f (𝓤 α) := by rw [nhds_eq_comap_uniformity, tendsto_comap_iff]; rfl theorem tendsto_nhds_left {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (u x, a)) f (𝓤 α) := by rw [nhds_eq_comap_uniformity', tendsto_comap_iff]; rfl theorem continuousAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := by rw [ContinuousAt, tendsto_nhds_right] theorem continuousAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := by rw [ContinuousAt, tendsto_nhds_left] theorem continuousAt_iff_prod [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x : β × β => (f x.1, f x.2)) (𝓝 (b, b)) (𝓤 α) := ⟨fun H => le_trans (H.prodMap' H) (nhds_le_uniformity _), fun H => continuousAt_iff'_left.2 <| H.comp <| tendsto_id.prodMk_nhds tendsto_const_nhds⟩ theorem continuousWithinAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by rw [ContinuousWithinAt, tendsto_nhds_right] theorem continuousWithinAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by rw [ContinuousWithinAt, tendsto_nhds_left] theorem continuousOn_iff'_right [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by simp [ContinuousOn, continuousWithinAt_iff'_right] theorem continuousOn_iff'_left [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by simp [ContinuousOn, continuousWithinAt_iff'_left] theorem continuous_iff'_right [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ b, Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_right theorem continuous_iff'_left [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ b, Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_left /-- Consider two functions `f` and `g` which coincide on a set `s` and are continuous there. Then there is an open neighborhood of `s` on which `f` and `g` are uniformly close. -/ lemma exists_is_open_mem_uniformity_of_forall_mem_eq [TopologicalSpace β] {r : SetRel α α} {s : Set β} {f g : β → α} (hf : ∀ x ∈ s, ContinuousAt f x) (hg : ∀ x ∈ s, ContinuousAt g x) (hfg : s.EqOn f g) (hr : r ∈ 𝓤 α) : ∃ t, IsOpen t ∧ s ⊆ t ∧ ∀ x ∈ t, (f x, g x) ∈ r := by have A : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ∀ z ∈ t, (f z, g z) ∈ r := by intro x hx obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr have A : {z | (f x, f z) ∈ t} ∈ 𝓝 x := (hf x hx).preimage_mem_nhds (mem_nhds_left (f x) ht) have B : {z | (g x, g z) ∈ t} ∈ 𝓝 x := (hg x hx).preimage_mem_nhds (mem_nhds_left (g x) ht) rcases _root_.mem_nhds_iff.1 (inter_mem A B) with ⟨u, hu, u_open, xu⟩ refine ⟨u, u_open, xu, fun y hy ↦ ?_⟩ have I1 : (f y, f x) ∈ t := SetRel.symm t (hu hy).1 have I2 : (g x, g y) ∈ t := (hu hy).2 rw [hfg hx] at I1 exact htr (SetRel.prodMk_mem_comp I1 I2) choose! t t_open xt ht using A refine ⟨⋃ x ∈ s, t x, isOpen_biUnion t_open, fun x hx ↦ mem_biUnion hx (xt x hx), ?_⟩ rintro x hx simp only [mem_iUnion, exists_prop] at hx rcases hx with ⟨y, ys, hy⟩ exact ht y ys x hy end Uniform theorem Filter.Tendsto.congr_uniformity {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β} (hf : Tendsto f l (𝓝 b)) (hg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto g l (𝓝 b) := Uniform.tendsto_nhds_right.2 <| (Uniform.tendsto_nhds_right.1 hf).uniformity_trans hg theorem Uniform.tendsto_congr {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β} (hfg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto f l (𝓝 b) ↔ Tendsto g l (𝓝 b) := ⟨fun h => h.congr_uniformity hfg, fun h => h.congr_uniformity hfg.uniformity_symm⟩
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/UniformConvergence.lean
import Mathlib.Topology.UniformSpace.Cauchy /-! # Uniform convergence A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality `dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit, most notably continuity. We prove this in the file, defining the notion of uniform convergence in the more general setting of uniform spaces, and with respect to an arbitrary indexing set endowed with a filter (instead of just `ℕ` with `atTop`). ## Main results Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β` (where the index `n` belongs to an indexing type `ι` endowed with a filter `p`). * `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has `(f y, Fₙ y) ∈ u` for all `y ∈ s`. * `TendstoUniformly F f p`: same notion with `s = univ`. * `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous on this set is itself continuous on this set. * `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous. * `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`. * `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then `Fₙ gₙ` tends to `f x`. Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform convergence what a Cauchy sequence is to the usual notion of convergence. ## Implementation notes We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`. This definition in and of itself can sometimes be useful, e.g., when studying the local behavior of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`. Still, while this may be the "correct" definition (see `tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`. ## Tags Uniform limit, uniform convergence, tends uniformly to -/ noncomputable section open Topology Uniformity Filter Set Uniform variable {α β γ ι : Type*} [UniformSpace β] variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α} /-! ### Different notions of uniform convergence We define uniform convergence, on a set or in the whole space. -/ /-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` with respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/ def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) := ∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u /-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`. -/ theorem tendstoUniformlyOnFilter_iff_tendsto : TendstoUniformlyOnFilter F f p p' ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) := Iff.rfl /-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually `(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/ def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) := ∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter : TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter] apply forall₂_congr simp_rw [eventually_prod_principal_iff] simp alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter /-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`. -/ theorem tendstoUniformlyOn_iff_tendsto : TendstoUniformlyOn F f p s ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto] /-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually `(f x, Fₙ x) ∈ u` for all `x`. -/ def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) := ∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by simp [TendstoUniformlyOn, TendstoUniformly] theorem tendstoUniformly_iff_tendstoUniformlyOnFilter : TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ] theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) : TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter] theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe : TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p := forall₂_congr fun u _ => by simp lemma tendstoUniformlyOn_iff_restrict {K : Set α} : TendstoUniformlyOn F f p K ↔ TendstoUniformly (fun n : ι => K.restrict (F n)) (K.restrict f) p := tendstoUniformlyOn_iff_tendstoUniformly_comp_coe /-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit. -/ theorem tendstoUniformly_iff_tendsto : TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto] /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p') (hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_ filter_upwards [(h u hu).curry] intro i h simpa using h.filter_mono hx /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x ∈ s) : Tendsto (fun n => F n x) p <| 𝓝 (f x) := h.tendstoUniformlyOnFilter.tendsto_at (le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx) /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : α) : Tendsto (fun n => F n x) p <| 𝓝 (f x) := h.tendstoUniformlyOnFilter.tendsto_at le_top theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ι} (h : TendstoUniformlyOnFilter F f p p') (hp : p'' ≤ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu => (h u hu).filter_mono (p'.prod_mono_left hp) theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter α} (h : TendstoUniformlyOnFilter F f p p') (hp : p'' ≤ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu => (h u hu).filter_mono (p.prod_mono_right hp) theorem TendstoUniformlyOn.mono (h : TendstoUniformlyOn F f p s) (h' : s' ⊆ s) : TendstoUniformlyOn F f p s' := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h')) theorem TendstoUniformlyOnFilter.congr {F' : ι → α → β} (hf : TendstoUniformlyOnFilter F f p p') (hff' : ∀ᶠ n : ι × α in p ×ˢ p', F n.fst n.snd = F' n.fst n.snd) : TendstoUniformlyOnFilter F' f p p' := by refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_ rw [← h.right] exact h.left theorem TendstoUniformlyOn.congr {F' : ι → α → β} (hf : TendstoUniformlyOn F f p s) (hff' : ∀ᶠ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊢ refine hf.congr ?_ rw [eventually_iff] at hff' ⊢ simp only [Set.EqOn] at hff' simp only [mem_prod_principal, hff', mem_setOf_eq] lemma tendstoUniformly_congr {F' : ι → α → β} (hF : F =ᶠ[p] F') : TendstoUniformly F f p ↔ TendstoUniformly F' f p := by simp_rw [← tendstoUniformlyOn_univ] at * have HF := EventuallyEq.exists_mem hF exact ⟨fun h => h.congr (by aesop), fun h => h.congr (by simp_rw [eqOn_comm]; aesop)⟩ theorem TendstoUniformlyOn.congr_right {g : α → β} (hf : TendstoUniformlyOn F f p s) (hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by filter_upwards [hf u hu] with i hi a ha using hfg ha ▸ hi a ha protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) : TendstoUniformlyOn F f p s := (tendstoUniformlyOn_univ.2 h).mono (subset_univ s) /-- Composing on the right by a function preserves uniform convergence on a filter -/ theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : γ → α) : TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊢ exact h.comp (tendsto_id.prodMap tendsto_comap) /-- Composing on the right by a function preserves uniform convergence on a set -/ theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : γ → α) : TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊢ simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g /-- Composing on the right by a function preserves uniform convergence -/ theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : γ → α) : TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊢ simpa [principal_univ, comap_principal] using h.comp g /-- Composing on the left by a uniformly continuous function preserves uniform convergence on a filter -/ theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') : TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu) /-- Composing on the left by a uniformly continuous function preserves uniform convergence on a set -/ theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) : TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu) /-- Composing on the left by a uniformly continuous function preserves uniform convergence -/ theorem UniformContinuous.comp_tendstoUniformly [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (h : TendstoUniformly F f p) : TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu) theorem TendstoUniformlyOnFilter.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {f' : α' → β'} {q : Filter ι'} {q' : Filter α'} (h : TendstoUniformlyOnFilter F f p p') (h' : TendstoUniformlyOnFilter F' f' q q') : TendstoUniformlyOnFilter (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ q) (p' ×ˢ q') := by rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊢ rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff] simpa using h.prodMap h' theorem TendstoUniformlyOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {f' : α' → β'} {p' : Filter ι'} {s' : Set α'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s') : TendstoUniformlyOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') (s ×ˢ s') := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊢ simpa only [prod_principal_principal] using h.prodMap h' theorem TendstoUniformly.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {f' : α' → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') : TendstoUniformly (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') := by rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at * exact h.prodMap h' theorem TendstoUniformlyOnFilter.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'} {q : Filter ι'} (h : TendstoUniformlyOnFilter F f p p') (h' : TendstoUniformlyOnFilter F' f' q p') : TendstoUniformlyOnFilter (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ q) p' := fun u hu => ((h.prodMap h') u hu).diag_of_prod_right protected theorem TendstoUniformlyOn.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'} {p' : Filter ι'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s) : TendstoUniformlyOn (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p') s := (congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a)) theorem TendstoUniformly.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') : TendstoUniformly (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p') := (h.prodMap h').comp fun a => (a, a) /-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in `p ×ˢ p'`. -/ theorem tendsto_prod_filter_iff {c : β} : Tendsto ↿F (p ×ˢ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff] rfl /-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in `p ×ˢ 𝓟 s`. -/ theorem tendsto_prod_principal_iff {c : β} : Tendsto ↿F (p ×ˢ 𝓟 s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] exact tendsto_prod_filter_iff /-- Uniform convergence to a constant function is equivalent to convergence in `p ×ˢ ⊤`. -/ theorem tendsto_prod_top_iff {c : β} : Tendsto ↿F (p ×ˢ ⊤) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] exact tendsto_prod_filter_iff /-- Uniform convergence on the empty set is vacuously true -/ theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p ∅ := fun u _ => by simp /-- Uniform convergence on a singleton is equivalent to regular convergence -/ theorem tendstoUniformlyOn_singleton_iff_tendsto : TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ι => F n x) p (𝓝 (f x)) := by simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def] exact forall₂_congr fun u _ => by simp [preimage] /-- If a sequence `g` converges to some `b`, then the sequence of constant functions `fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/ theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b)) (p' : Filter α) : TendstoUniformlyOnFilter (fun n : ι => fun _ : α => g n) (fun _ : α => b) p p' := by simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p')) /-- If a sequence `g` converges to some `b`, then the sequence of constant functions `fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/ theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b)) (s : Set α) : TendstoUniformlyOn (fun n : ι => fun _ : α => g n) (fun _ : α => b) p s := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (𝓟 s)) theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace α] [UniformSpace γ] {U : Set α} {V : Set β} {F : α → β → γ} (hF : UniformContinuousOn ↿F (U ×ˢ V)) (hU : x ∈ U) : TendstoUniformlyOn F (F x) (𝓝[U] x) V := by set φ := fun q : α × β => ((x, q.2), q) rw [tendstoUniformlyOn_iff_tendsto] change Tendsto (Prod.map ↿F ↿F ∘ φ) (𝓝[U] x ×ˢ 𝓟 V) (𝓤 γ) simp only [nhdsWithin, Filter.prod_eq_inf, comap_inf, inf_assoc, comap_principal, inf_principal] refine Tendsto.comp hF (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩) simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, nhds_eq_comap_uniformity, comap_comap] exact tendsto_comap.prodMk (tendsto_diag_uniformity _ _) theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {U : Set α} (hU : U ∈ 𝓝 x) {F : α → β → γ} (hF : UniformContinuousOn ↿F (U ×ˢ (univ : Set β))) : TendstoUniformly F (F x) (𝓝 x) := by simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU] using hF.tendstoUniformlyOn (mem_of_mem_nhds hU) theorem UniformContinuous₂.tendstoUniformly [UniformSpace α] [UniformSpace γ] {f : α → β → γ} (h : UniformContinuous₂ f) : TendstoUniformly f (f x) (𝓝 x) := UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ] namespace Filter.HasBasis variable {X ιX ια ιβ : Type*} /-- An analogue of `Filter.HasBasis.tendsto_right_iff` for `TendstoUniformlyOnFilter`. -/ lemma tendstoUniformlyOnFilter_iff_of_uniformity {F : X → α → β} {f : α → β} {l : Filter X} {l' : Filter α} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hβ : (uniformity β).HasBasis pβ sβ) : TendstoUniformlyOnFilter F f l l' ↔ (∀ i, pβ i → ∀ᶠ n in l ×ˢ l', (f n.2, F n.1 n.2) ∈ sβ i) := by rw [tendstoUniformlyOnFilter_iff_tendsto, hβ.tendsto_right_iff] /-- An analogue of `Filter.HasBasis.tendsto_iff` for `TendstoUniformlyOnFilter`. -/ lemma tendstoUniformlyOnFilter_iff {F : X → α → β} {f : α → β} {l : Filter X} {l' : Filter α} {pX : ιX → Prop} {sX : ιX → Set X} {pα : ια → Prop} {sα : ια → Set α} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hl : l.HasBasis pX sX) (hl' : l'.HasBasis pα sα) (hβ : (uniformity β).HasBasis pβ sβ) : TendstoUniformlyOnFilter F f l l' ↔ (∀ i, pβ i → ∃ j k, (pX j ∧ pα k) ∧ ∀ x a, x ∈ sX j → a ∈ sα k → (f a, F x a) ∈ sβ i) := by simp [hβ.tendstoUniformlyOnFilter_iff_of_uniformity, (hl.prod hl').eventually_iff] /-- An analogue of `Filter.HasBasis.tendsto_right_iff` for `TendstoUniformlyOn`. -/ lemma tendstoUniformlyOn_iff_of_uniformity {F : X → α → β} {f : α → β} {l : Filter X} {s : Set α} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hβ : (uniformity β).HasBasis pβ sβ) : TendstoUniformlyOn F f l s ↔ (∀ i, pβ i → ∀ᶠ n in l, ∀ x ∈ s, (f x, F n x) ∈ sβ i) := by simp_rw [tendstoUniformlyOn_iff_tendsto, hβ.tendsto_right_iff, eventually_prod_principal_iff] /-- An analogue of `Filter.HasBasis.tendsto_iff` for `TendstoUniformlyOn`. -/ lemma tendstoUniformlyOn_iff {F : X → α → β} {f : α → β} {l : Filter X} {s : Set α} {pX : ιX → Prop} {sX : ιX → Set X} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hl : l.HasBasis pX sX) (hβ : (uniformity β).HasBasis pβ sβ) : TendstoUniformlyOn F f l s ↔ (∀ i, pβ i → ∃ j, pX j ∧ ∀ ⦃x⦄, x ∈ sX j → ∀ a ∈ s, (f a, F x a) ∈ sβ i) := by simp [hβ.tendstoUniformlyOn_iff_of_uniformity, hl.eventually_iff] /-- An analogue of `Filter.HasBasis.tendsto_right_iff` for `TendstoUniformly`. -/ lemma tendstoUniformly_iff_of_uniformity {F : X → α → β} {f : α → β} {l : Filter X} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hβ : (uniformity β).HasBasis pβ sβ) : TendstoUniformly F f l ↔ (∀ i, pβ i → ∀ᶠ n in l, ∀ x, (f x, F n x) ∈ sβ i) := by simp_rw [← tendstoUniformlyOn_univ, hβ.tendstoUniformlyOn_iff_of_uniformity, mem_univ, true_imp_iff] /-- An analogue of `Filter.HasBasis.tendsto_iff` for `TendstoUniformly`. -/ lemma tendstoUniformly_iff {F : X → α → β} {f : α → β} {l : Filter X} {pX : ιX → Prop} {sX : ιX → Set X} (hl : l.HasBasis pX sX) {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hβ : (uniformity β).HasBasis pβ sβ) : TendstoUniformly F f l ↔ (∀ i, pβ i → ∃ j, pX j ∧ ∀ ⦃x⦄, x ∈ sX j → ∀ a, (f a, F x a) ∈ sβ i) := by simp only [hβ.tendstoUniformly_iff_of_uniformity, hl.eventually_iff] end Filter.HasBasis /-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are uniformly bounded -/ def UniformCauchySeqOnFilter (F : ι → α → β) (p : Filter ι) (p' : Filter α) : Prop := ∀ u ∈ 𝓤 β, ∀ᶠ m : (ι × ι) × α in (p ×ˢ p) ×ˢ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u /-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are uniformly bounded -/ def UniformCauchySeqOn (F : ι → α → β) (p : Filter ι) (s : Set α) : Prop := ∀ u ∈ 𝓤 β, ∀ᶠ m : ι × ι in p ×ˢ p, ∀ x : α, x ∈ s → (F m.fst x, F m.snd x) ∈ u theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter : UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (𝓟 s) := by simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter] refine forall₂_congr fun u hu => ?_ rw [eventually_prod_principal_iff] theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) : UniformCauchySeqOnFilter F p (𝓟 s) := by rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] /-- A sequence that converges uniformly is also uniformly Cauchy -/ theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') : UniformCauchySeqOnFilter F p p' := by intro u hu rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩ have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht)) apply this.diag_of_prod_right.mono simp only [and_imp, Prod.forall] intro n1 n2 x hl hr exact htmem <| SetRel.prodMk_mem_comp (htsymm hl) hr /-- A sequence that converges uniformly is also uniformly Cauchy -/ theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) : UniformCauchySeqOn F p s := uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter /-- A uniformly Cauchy sequence converges uniformly to its limit -/ theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto (hF : UniformCauchySeqOnFilter F p p') (hF' : ∀ᶠ x : α in p', Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOnFilter F f p p' := by rcases p.eq_or_neBot with rfl | _ · simp only [TendstoUniformlyOnFilter, bot_prod, eventually_bot, implies_true] -- Proof idea: |f_n(x) - f(x)| ≤ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n` -- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m ≥ n`. Then for -- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small. intro u hu rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩ -- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF' -- But we need to promote hF' to the full product filter to use it have hmc : ∀ᶠ x in (p ×ˢ p) ×ˢ p', Tendsto (fun n : ι => F n x.snd) p (𝓝 (f x.snd)) := by rw [eventually_prod_iff] exact ⟨fun _ => True, by simp, _, hF', by simp⟩ -- To apply filter operations we'll need to do some order manipulation rw [Filter.eventually_swap_iff] have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc)) apply this.curry.mono simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap, and_imp, Prod.forall] -- Complete the proof intro x n hx hm' refine Set.mem_of_mem_of_subset ?_ htmem rw [Uniform.tendsto_nhds_right] at hm' have := hx.and (hm' ht) obtain ⟨m, hm⟩ := this.exists exact ⟨F m x, ⟨hm.2, htsymm hm.1⟩⟩ /-- A uniformly Cauchy sequence converges uniformly to its limit -/ theorem UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto (hF : UniformCauchySeqOn F p s) (hF' : ∀ x : α, x ∈ s → Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOn F f p s := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hF.uniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto hF') theorem UniformCauchySeqOnFilter.mono_left {p'' : Filter ι} (hf : UniformCauchySeqOnFilter F p p') (hp : p'' ≤ p) : UniformCauchySeqOnFilter F p'' p' := fun u hu => (hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp)) theorem UniformCauchySeqOnFilter.mono_right {p'' : Filter α} (hf : UniformCauchySeqOnFilter F p p') (hp : p'' ≤ p') : UniformCauchySeqOnFilter F p p'' := fun u hu => have := (hf u hu).filter_mono ((p ×ˢ p).prod_mono_right hp) this.mono (by simp) theorem UniformCauchySeqOn.mono (hf : UniformCauchySeqOn F p s) (hss' : s' ⊆ s) : UniformCauchySeqOn F p s' := by rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢ exact hf.mono_right (le_principal_iff.mpr <| mem_principal.mpr hss') /-- Composing on the right by a function preserves uniform Cauchy sequences -/ theorem UniformCauchySeqOnFilter.comp {γ : Type*} (hf : UniformCauchySeqOnFilter F p p') (g : γ → α) : UniformCauchySeqOnFilter (fun n => F n ∘ g) p (p'.comap g) := fun u hu => by obtain ⟨pa, hpa, pb, hpb, hpapb⟩ := eventually_prod_iff.mp (hf u hu) rw [eventually_prod_iff] refine ⟨pa, hpa, pb ∘ g, ?_, fun hx _ hy => hpapb hx hy⟩ exact eventually_comap.mpr (hpb.mono fun x hx y hy => by simp only [hx, hy, Function.comp_apply]) /-- Composing on the right by a function preserves uniform Cauchy sequences -/ theorem UniformCauchySeqOn.comp {γ : Type*} (hf : UniformCauchySeqOn F p s) (g : γ → α) : UniformCauchySeqOn (fun n => F n ∘ g) p (g ⁻¹' s) := by rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢ simpa only [UniformCauchySeqOn, comap_principal] using hf.comp g /-- Composing on the left by a uniformly continuous function preserves uniform Cauchy sequences -/ theorem UniformContinuous.comp_uniformCauchySeqOn [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (hf : UniformCauchySeqOn F p s) : UniformCauchySeqOn (fun n => g ∘ F n) p s := fun _u hu => hf _ (hg hu) theorem UniformCauchySeqOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {p' : Filter ι'} {s' : Set α'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s') : UniformCauchySeqOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (p ×ˢ p') (s ×ˢ s') := by intro u hu rw [uniformity_prod_eq_prod, mem_map, mem_prod_iff] at hu obtain ⟨v, hv, w, hw, hvw⟩ := hu simp_rw [mem_prod, and_imp, Prod.forall, Prod.map_apply] rw [← Set.image_subset_iff] at hvw apply (tendsto_swap4_prod.eventually ((h v hv).prod_mk (h' w hw))).mono intro x hx a b ha hb exact hvw ⟨_, mk_mem_prod (hx.1 a ha) (hx.2 b hb), rfl⟩ theorem UniformCauchySeqOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {p' : Filter ι'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s) : UniformCauchySeqOn (fun (i : ι × ι') a => (F i.fst a, F' i.snd a)) (p ×ˢ p') s := (congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a)) theorem UniformCauchySeqOn.prod' {β' : Type*} [UniformSpace β'] {F' : ι → α → β'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p s) : UniformCauchySeqOn (fun (i : ι) a => (F i a, F' i a)) p s := fun u hu => have hh : Tendsto (fun x : ι => (x, x)) p (p ×ˢ p) := tendsto_diag (hh.prodMap hh).eventually ((h.prod h') u hu) /-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form a Cauchy sequence. -/ theorem UniformCauchySeqOn.cauchy_map [hp : NeBot p] (hf : UniformCauchySeqOn F p s) (hx : x ∈ s) : Cauchy (map (fun i => F i x) p) := by simp only [cauchy_map_iff, hp, true_and] intro u hu rw [mem_map] filter_upwards [hf u hu] with p hp using hp x hx /-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form a Cauchy sequence. See `UniformCauchySeqOn.cauchy_map` for the non-`atTop` case. -/ theorem UniformCauchySeqOn.cauchySeq [Nonempty ι] [SemilatticeSup ι] (hf : UniformCauchySeqOn F atTop s) (hx : x ∈ s) : CauchySeq fun i ↦ F i x := hf.cauchy_map (hp := atTop_neBot) hx section SeqTendsto theorem tendstoUniformlyOn_of_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated] (h : ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s) : TendstoUniformlyOn F f l s := by rw [tendstoUniformlyOn_iff_tendsto, tendsto_iff_seq_tendsto] intro u hu rw [tendsto_prod_iff'] at hu specialize h (fun n => (u n).fst) hu.1 rw [tendstoUniformlyOn_iff_tendsto] at h exact h.comp (tendsto_id.prodMk hu.2) theorem TendstoUniformlyOn.seq_tendstoUniformlyOn {l : Filter ι} (h : TendstoUniformlyOn F f l s) (u : ℕ → ι) (hu : Tendsto u atTop l) : TendstoUniformlyOn (fun n => F (u n)) f atTop s := by rw [tendstoUniformlyOn_iff_tendsto] at h ⊢ exact h.comp ((hu.comp tendsto_fst).prodMk tendsto_snd) theorem tendstoUniformlyOn_iff_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated] : TendstoUniformlyOn F f l s ↔ ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s := ⟨TendstoUniformlyOn.seq_tendstoUniformlyOn, tendstoUniformlyOn_of_seq_tendstoUniformlyOn⟩ theorem tendstoUniformly_iff_seq_tendstoUniformly {l : Filter ι} [l.IsCountablyGenerated] : TendstoUniformly F f l ↔ ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformly (fun n => F (u n)) f atTop := by simp_rw [← tendstoUniformlyOn_univ] exact tendstoUniformlyOn_iff_seq_tendstoUniformlyOn end SeqTendsto section variable [NeBot p] {L : ι → β} {ℓ : β} theorem TendstoUniformlyOnFilter.tendsto_of_eventually_tendsto (h1 : TendstoUniformlyOnFilter F f p p') (h2 : ∀ᶠ i in p, Tendsto (F i) p' (𝓝 (L i))) (h3 : Tendsto L p (𝓝 ℓ)) : Tendsto f p' (𝓝 ℓ) := by rw [tendsto_nhds_left] intro s hs rw [mem_map, Set.preimage, ← eventually_iff] obtain ⟨t, ht, hts⟩ := comp3_mem_uniformity hs have p1 : ∀ᶠ i in p, (L i, ℓ) ∈ t := tendsto_nhds_left.mp h3 ht have p2 : ∀ᶠ i in p, ∀ᶠ x in p', (F i x, L i) ∈ t := by filter_upwards [h2] with i h2 using tendsto_nhds_left.mp h2 ht have p3 : ∀ᶠ i in p, ∀ᶠ x in p', (f x, F i x) ∈ t := (h1 t ht).curry obtain ⟨i, p4, p5, p6⟩ := (p1.and (p2.and p3)).exists filter_upwards [p5, p6] with x p5 p6 using hts ⟨F i x, p6, L i, p5, p4⟩ theorem TendstoUniformly.tendsto_of_eventually_tendsto (h1 : TendstoUniformly F f p) (h2 : ∀ᶠ i in p, Tendsto (F i) p' (𝓝 (L i))) (h3 : Tendsto L p (𝓝 ℓ)) : Tendsto f p' (𝓝 ℓ) := (h1.tendstoUniformlyOnFilter.mono_right le_top).tendsto_of_eventually_tendsto h2 h3 end
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Path.lean
import Mathlib.Topology.Path import Mathlib.Topology.UniformSpace.CompactConvergence import Mathlib.Topology.UniformSpace.HeineCantor import Mathlib.Topology.MetricSpace.Lipschitz import Mathlib.Topology.ContinuousMap.Interval /-! # Paths in uniform spaces In this file we define a `UniformSpace` structure on `Path`s between two points in a uniform space and prove that various functions associated with `Path`s are uniformly continuous. The uniform space structure is induced from the space of continuous maps `C(I, X)`, and corresponds to uniform convergence of paths on `I`, see `Path.hasBasis_uniformity`. -/ open scoped unitInterval Topology Uniformity variable {X : Type*} [UniformSpace X] {x y z : X} namespace Path instance instUniformSpace : UniformSpace (Path x y) := .comap ((↑) : _ → C(I, X)) ContinuousMap.compactConvergenceUniformSpace theorem isUniformEmbedding_coe : IsUniformEmbedding ((↑) : Path x y → C(I, X)) where comap_uniformity := rfl injective := ContinuousMap.coe_injective' theorem uniformContinuous (γ : Path x y) : UniformContinuous γ := CompactSpace.uniformContinuous_of_continuous <| map_continuous _ /-- Given a path `γ`, it extension to the real line `γ.extend : C(ℝ, X)` is a uniformly continuous function. -/ theorem uniformContinuous_extend (γ : Path x y) : UniformContinuous γ.extend := γ.uniformContinuous.comp <| LipschitzWith.projIcc _ |>.uniformContinuous /-- The function sending a path `γ` to its extension `γ.extend : ℝ → X` is uniformly continuous in `γ`. -/ theorem uniformContinuous_extend_left : UniformContinuous (Path.extend : Path x y → C(ℝ, X)) := ContinuousMap.projIccCM.uniformContinuous_comp_left.comp isUniformEmbedding_coe.uniformContinuous /-- If `{U i | p i}` form a basis of entourages of `X`, then the entourages `{V i | p i}`, `V i = {(γ₁, γ₂) | ∀ t, (γ₁ t, γ₂ t) ∈ U i}`, form a basis of entourages of paths between `x` and `y`. -/ theorem _root_.Filter.HasBasis.uniformityPath {ι : Sort*} {p : ι → Prop} {U : ι → Set (X × X)} (hU : (𝓤 X).HasBasis p U) : (𝓤 (Path x y)).HasBasis p fun i ↦ {γ | ∀ t, (γ.1 t, γ.2 t) ∈ U i} := hU.compactConvergenceUniformity_of_compact.comap _ theorem hasBasis_uniformity : (𝓤 (Path x y)).HasBasis (· ∈ 𝓤 X) ({γ | ∀ t, (γ.1 t, γ.2 t) ∈ ·}) := (𝓤 X).basis_sets.uniformityPath theorem uniformContinuous_symm : UniformContinuous (Path.symm : Path x y → Path y x) := hasBasis_uniformity.uniformContinuous_iff hasBasis_uniformity |>.mpr fun U hU ↦ ⟨U, hU, fun _ _ h x ↦ h (σ x)⟩ /-- The function `Path.trans` that concatenates two paths `γ₁ : Path x y` and `γ₂ : Path y z` is uniformly continuous in `(γ₁, γ₂)`. -/ theorem uniformContinuous_trans : UniformContinuous (Path.trans : Path x y → Path y z → Path x z).uncurry := hasBasis_uniformity.uniformity_prod hasBasis_uniformity |>.uniformContinuous_iff hasBasis_uniformity |>.mpr fun U hU ↦ ⟨(U, U), ⟨hU, hU⟩, fun ⟨_, _⟩ ⟨_, _⟩ ⟨h₁, h₂⟩ t ↦ by by_cases ht : (t : ℝ) ≤ 2⁻¹ <;> simp [Path.trans_apply, ht, h₁ _, h₂ _]⟩ /-- The space of paths between two points in a complete uniform space is a complete uniform space. -/ instance instCompleteSpace [CompleteSpace X] : CompleteSpace (Path x y) := isUniformEmbedding_coe.completeSpace <| by simpa [Set.EqOn, range_coe] using ContinuousMap.isComplete_setOf_eqOn (Function.update (fun _ : I ↦ y) 0 x) {0, 1} end Path
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Defs.lean
import Mathlib.Data.Rel import Mathlib.Topology.Order /-! # Uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * uniform continuity (in this file) * completeness (in `Cauchy.lean`) * extension of uniform continuous functions to complete spaces (in `IsUniformEmbedding.lean`) * totally bounded sets (in `Cauchy.lean`) * totally bounded complete sets are compact (in `Cauchy.lean`) A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means "for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages of `X`. The two main examples are: * If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V` * If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V` Those examples are generalizations in two different directions of the elementary example where `X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological group structure on `ℝ` and its metric space structure. Each uniform structure on `X` induces a topology on `X` characterized by > `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (Prod.mk x) (𝓤 X)` where `Prod.mk x : X → X × X := (fun y ↦ (x, y))` is the partial evaluation of the product constructor. The dictionary with metric spaces includes: * an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X` * a ball `ball x r` roughly corresponds to `UniformSpace.ball x V := {y | (x, y) ∈ V}` for some `V ∈ 𝓤 X`, but the later is more general (it includes in particular both open and closed balls for suitable `V`). In particular we have: `isOpen_iff_ball_subset {s : Set X} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s` The triangle inequality is abstracted to a statement involving the composition of relations in `X`. First note that the triangle inequality in a metric space is equivalent to `∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`. Then, for any `V` and `W` with type `Set (X × X)`, the composition `V ○ W : Set (X × X)` is defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`. In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }` then the triangle inequality, as reformulated above, says `V ○ W` is contained in `{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`. In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`. Note that this discussion does not depend on any axiom imposed on the uniformity filter, it is simply captured by the definition of composition. The uniform space axioms ask the filter `𝓤 X` to satisfy the following: * every `V ∈ 𝓤 X` contains the diagonal `idRel = { p | p.1 = p.2 }`. This abstracts the fact that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that `x - x` belongs to every neighborhood of zero in the topological group case. * `V ∈ 𝓤 X → Prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x` in a metric space, and to continuity of negation in the topological group case. * `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds to cutting the radius of a ball in half and applying the triangle inequality. In the topological group case, it comes from continuity of addition at `(0, 0)`. These three axioms are stated more abstractly in the definition below, in terms of operations on filters, without directly manipulating entourages. ## Main definitions * `UniformSpace X` is a uniform space structure on a type `X` * `UniformContinuous f` is a predicate saying a function `f : α → β` between uniform spaces is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r` ## Notation Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`. This file also uses a lot the notation `○` for composition of relations, seen as terms with type `SetRel X X`. This notation (defined in the file `Mathlib/Data/Rel.lean`) is localized in `SetRel`. ## Implementation notes We use the theory of relations as sets developed in `Mathlib/Data/Rel.lean`. The relevant definition is `SetRel X X := Set (X × X)`, which is the type of elements of the uniformity filter `𝓤 X : Filter (X × X)`. The structure `UniformSpace X` bundles a uniform structure on `X`, a topology on `X` and an assumption saying those are compatible. This may not seem mathematically reasonable at first, but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance] below. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `SetRel α α` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ @[deprecated SetRel.id (since := "2025-10-17")] def idRel {α : Type*} := { p : α × α | p.1 = p.2 } set_option linter.deprecated false in @[deprecated SetRel.mem_id (since := "2025-10-17")] theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b := Iff.rfl set_option linter.deprecated false in @[deprecated SetRel.id_subset_iff (since := "2025-10-17")] theorem idRel_subset {s : SetRel α α} : idRel ⊆ s ↔ ∀ a, (a, a) ∈ s := by simp [subset_def, mem_idRel] set_option linter.deprecated false in @[deprecated SetRel.exists_eq_singleton_of_prod_subset_id (since := "2025-10-17")] theorem eq_singleton_left_of_prod_subset_idRel {X : Type*} {S T : Set X} (hS : S.Nonempty) (hT : T.Nonempty) (h_diag : S ×ˢ T ⊆ SetRel.id) : ∃ x, S = {x} := by obtain ⟨x, hx, -⟩ := SetRel.exists_eq_singleton_of_prod_subset_id hS hT h_diag; exact ⟨x, hx⟩ set_option linter.deprecated false in @[deprecated SetRel.exists_eq_singleton_of_prod_subset_id (since := "2025-10-17")] theorem eq_singleton_right_prod_subset_idRel {X : Type*} {S T : Set X} (hS : S.Nonempty) (hT : T.Nonempty) (h_diag : S ×ˢ T ⊆ SetRel.id) : ∃ x, T = {x} := by obtain ⟨x, -, hx⟩ := SetRel.exists_eq_singleton_of_prod_subset_id hS hT h_diag; exact ⟨x, hx⟩ @[deprecated (since := "2025-10-17")] alias eq_singleton_prod_subset_idRel := SetRel.exists_eq_singleton_of_prod_subset_id set_option linter.deprecated false in /-- The composition of relations -/ @[deprecated SetRel.comp (since := "2025-10-17")] def compRel (r₁ r₂ : SetRel α α) := { p : α × α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂ } open scoped SetRel set_option linter.deprecated false in @[deprecated SetRel.mem_comp (since := "2025-10-17")] theorem mem_compRel {α : Type u} {r₁ r₂ : SetRel α α} {x y : α} : (x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := Iff.rfl set_option linter.deprecated false in @[deprecated SetRel.inv_id (since := "2025-10-17")] theorem swap_idRel : Prod.swap '' idRel = @idRel α := Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm set_option linter.deprecated false in @[deprecated Monotone.relComp (since := "2025-10-17")] theorem Monotone.compRel [Preorder β] {f g : β → SetRel α α} (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ○ g x := fun _ _ h _ ⟨z, h₁, h₂⟩ => ⟨z, hf h h₁, hg h h₂⟩ @[deprecated (since := "2025-10-17")] alias compRel_mono := SetRel.comp_subset_comp @[deprecated (since := "2025-10-17")] alias compRel_left_mono := SetRel.comp_subset_comp_left @[deprecated (since := "2025-10-17")] alias compRel_right_mono := SetRel.comp_subset_comp_right @[deprecated (since := "2025-10-17")] alias prodMk_mem_compRel := SetRel.prodMk_mem_comp @[deprecated (since := "2025-03-10")] alias prod_mk_mem_compRel := SetRel.prodMk_mem_comp set_option linter.deprecated false in @[deprecated SetRel.id_comp (since := "2025-10-17")] theorem id_compRel {r : SetRel α α} : idRel ○ r = r := SetRel.id_comp _ @[deprecated SetRel.comp_assoc (since := "2025-10-17")] theorem compRel_assoc {r s t : SetRel α α} : r ○ s ○ t = r ○ (s ○ t) := by apply SetRel.comp_assoc set_option linter.deprecated false in @[deprecated SetRel.left_subset_comp (since := "2025-10-17")] theorem left_subset_compRel {s t : SetRel α α} (h : idRel ⊆ t) : s ⊆ s ○ t := fun ⟨_x, y⟩ xy_in => ⟨y, xy_in, h <| rfl⟩ set_option linter.deprecated false in @[deprecated SetRel.right_subset_comp (since := "2025-10-17")] theorem right_subset_compRel {s t : SetRel α α} (h : idRel ⊆ s) : t ⊆ s ○ t := fun ⟨x, _y⟩ xy_in => ⟨x, h <| rfl, xy_in⟩ set_option linter.deprecated false in @[deprecated SetRel.left_subset_comp (since := "2025-10-17")] theorem subset_comp_self {s : SetRel α α} (h : idRel ⊆ s) : s ⊆ s ○ s := left_subset_compRel h set_option linter.deprecated false in @[deprecated SetRel.subset_iterate_comp (since := "2025-10-17")] theorem subset_iterate_compRel {s t : SetRel α α} (h : idRel ⊆ s) (n : ℕ) : t ⊆ (s ○ ·)^[n] t := by induction n generalizing t with | zero => exact Subset.rfl | succ n ihn => exact (right_subset_compRel h).trans ihn /-- The relation is invariant under swapping factors. -/ @[deprecated SetRel.IsSymm (since := "2025-10-17")] def IsSymmetricRel (V : SetRel α α) : Prop := Prod.swap ⁻¹' V = V /-- The maximal symmetric relation contained in a given relation. -/ @[deprecated SetRel.symmetrize (since := "2025-10-17")] def symmetrizeRel (V : SetRel α α) : SetRel α α := V ∩ Prod.swap ⁻¹' V set_option linter.deprecated false in @[deprecated SetRel.isSymm_symmetrize (since := "2025-10-17")] theorem symmetric_symmetrizeRel (V : SetRel α α) : IsSymmetricRel (symmetrizeRel V) := by simp [IsSymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp] set_option linter.deprecated false in @[deprecated SetRel.symmetrize_subset_self (since := "2025-10-17")] theorem symmetrizeRel_subset_self (V : SetRel α α) : symmetrizeRel V ⊆ V := sep_subset _ _ set_option linter.deprecated false in @[deprecated SetRel.symmetrize_mono (since := "2025-10-17")] theorem symmetrize_mono {V W : SetRel α α} (h : V ⊆ W) : symmetrizeRel V ⊆ symmetrizeRel W := inter_subset_inter h <| preimage_mono h set_option linter.deprecated false in @[deprecated SetRel.comm (since := "2025-10-17")] theorem IsSymmetricRel.mk_mem_comm {V : SetRel α α} (hV : IsSymmetricRel V) {x y : α} : (x, y) ∈ V ↔ (y, x) ∈ V := Set.ext_iff.1 hV (y, x) set_option linter.deprecated false in @[deprecated SetRel.inv_eq_self (since := "2025-10-17")] theorem IsSymmetricRel.eq {U : SetRel α α} (hU : IsSymmetricRel U) : Prod.swap ⁻¹' U = U := hU set_option linter.deprecated false in @[deprecated SetRel.isSymm_inter (since := "2025-10-17")] theorem IsSymmetricRel.inter {U V : SetRel α α} (hU : IsSymmetricRel U) (hV : IsSymmetricRel V) : IsSymmetricRel (U ∩ V) := by rw [IsSymmetricRel, preimage_inter, hU.eq, hV.eq] set_option linter.deprecated false in @[deprecated SetRel.isSymm_iInter (since := "2025-10-17")] theorem IsSymmetricRel.iInter {U : (i : ι) → SetRel α α} (hU : ∀ i, IsSymmetricRel (U i)) : IsSymmetricRel (⋂ i, U i) := by simp_rw [IsSymmetricRel, preimage_iInter, (hU _).eq] set_option linter.deprecated false in @[deprecated SetRel.IsSymm.sInter (since := "2025-10-17")] lemma IsSymmetricRel.sInter {s : Set (SetRel α α)} (h : ∀ i ∈ s, IsSymmetricRel i) : IsSymmetricRel (⋂₀ s) := by rw [sInter_eq_iInter] exact IsSymmetricRel.iInter (by simpa) set_option linter.deprecated false in @[deprecated SetRel.isSymm_id (since := "2025-10-17")] lemma isSymmetricRel_idRel : IsSymmetricRel (idRel : Set (α × α)) := by simp [IsSymmetricRel, idRel, eq_comm] set_option linter.deprecated false in @[deprecated SetRel.isSymm_univ (since := "2025-10-17")] lemma isSymmetricRel_univ : IsSymmetricRel (Set.univ : Set (α × α)) := by simp [IsSymmetricRel] set_option linter.deprecated false in @[deprecated SetRel.isSymm_preimage (since := "2025-10-17")] lemma IsSymmetricRel.preimage_prodMap {U : Set (β × β)} (ht : IsSymmetricRel U) (f : α → β) : IsSymmetricRel (Prod.map f f ⁻¹' U) := Set.ext fun _ ↦ ht.mk_mem_comm set_option linter.deprecated false in @[deprecated SetRel.isSymm_image (since := "2025-10-17")] lemma IsSymmetricRel.image_prodMap {U : Set (α × α)} (ht : IsSymmetricRel U) (f : α → β) : IsSymmetricRel (Prod.map f f '' U) := by rw [IsSymmetricRel, ← image_swap_eq_preimage_swap, ← image_comp, ← Prod.map_comp_swap, image_comp, image_swap_eq_preimage_swap, ht] set_option linter.deprecated false in @[deprecated SetRel.prod_subset_comm (since := "2025-10-17")] lemma IsSymmetricRel.prod_subset_comm {s : Set (α × α)} {t u : Set α} (hs : IsSymmetricRel s) : t ×ˢ u ⊆ s ↔ u ×ˢ t ⊆ s := by rw [← hs.eq, ← image_subset_iff, image_swap_prod, hs.eq] lemma SetRel.mem_filter_prod_comm (R : SetRel α α) {f g : Filter α} [R.IsSymm] : R ∈ f ×ˢ g ↔ R ∈ g ×ˢ f := by rw [← R.inv_eq_self, SetRel.inv, ← mem_map, ← prod_comm, ← SetRel.inv, R.inv_eq_self] set_option linter.deprecated false in @[deprecated SetRel.mem_filter_prod_comm (since := "2025-10-17")] lemma IsSymmetricRel.mem_filter_prod_comm {s : Set (α × α)} {f g : Filter α} (hs : IsSymmetricRel s) : s ∈ f ×ˢ g ↔ s ∈ g ×ˢ f := by rw [← hs.eq, ← mem_map, ← prod_comm, hs.eq] /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure UniformSpace.Core (α : Type u) where /-- The uniformity filter. Once `UniformSpace` is defined, `𝓤 α` (`_root_.uniformity`) becomes the normal form. -/ uniformity : Filter (α × α) /-- Every set in the uniformity filter includes the diagonal. -/ refl : 𝓟 SetRel.id ≤ uniformity /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity protected theorem UniformSpace.Core.comp_mem_uniformity_sets {c : Core α} {s : SetRel α α} (hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.relComp monotone_id).mp <| c.comp hs /-- An alternative constructor for `UniformSpace.Core`. This version unfolds various `Filter`-related definitions. -/ def UniformSpace.Core.mk' {α : Type u} (U : Filter (α × α)) (refl : ∀ r ∈ U, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ U, Prod.swap ⁻¹' r ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) : UniformSpace.Core α where uniformity := U refl _r ru := SetRel.id_subset_iff.2 ⟨refl _ ru⟩ symm comp _r ru := let ⟨_s, hs, hsr⟩ := comp _ ru; mem_of_superset (mem_lift' hs) hsr /-- Defining a `UniformSpace.Core` from a filter basis satisfying some uniformity-like axioms. -/ def UniformSpace.Core.mkOfBasis {α : Type u} (B : FilterBasis (α × α)) (refl : ∀ r ∈ B, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ Prod.swap ⁻¹' r) (comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : UniformSpace.Core α where uniformity := B.filter refl := B.hasBasis.ge_iff.mpr fun _r ru => SetRel.id_subset_iff.2 ⟨refl _ ru⟩ symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm comp := ((B.hasBasis.lift' (monotone_id.relComp monotone_id)).le_basis_iff B.hasBasis).2 comp /-- A uniform space generates a topological space -/ def UniformSpace.Core.toTopologicalSpace {α : Type u} (u : UniformSpace.Core α) : TopologicalSpace α := .mkOfNhds fun x ↦ .comap (Prod.mk x) u.uniformity theorem UniformSpace.Core.ext : ∀ {u₁ u₂ : UniformSpace.Core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl theorem UniformSpace.Core.nhds_toTopologicalSpace {α : Type u} (u : Core α) (x : α) : @nhds α u.toTopologicalSpace x = comap (Prod.mk x) u.uniformity := by apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun _ ↦ (basis_sets _).comap _) · exact fun a U hU ↦ u.refl hU rfl · intro a U hU rcases u.comp_mem_uniformity_sets hU with ⟨V, hV, hVU⟩ filter_upwards [preimage_mem_comap hV] with b hb filter_upwards [preimage_mem_comap hV] with c hc exact hVU ⟨b, hb, hc⟩ -- the topological structure is embedded in the uniform structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `α × α` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class UniformSpace (α : Type u) extends TopologicalSpace α where /-- The uniformity filter. -/ protected uniformity : Filter (α × α) /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ protected symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ protected comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity /-- The uniformity agrees with the topology: the neighborhoods filter of each point `x` is equal to `Filter.comap (Prod.mk x) (𝓤 α)`. -/ protected nhds_eq_comap_uniformity (x : α) : 𝓝 x = comap (Prod.mk x) uniformity /-- The uniformity is a filter on α × α (inferred from an ambient uniform space structure on α). -/ def uniformity (α : Type u) [UniformSpace α] : Filter (α × α) := @UniformSpace.uniformity α _ /-- Notation for the uniformity filter with respect to a non-standard `UniformSpace` instance. -/ scoped[Uniformity] notation "𝓤[" u "]" => @uniformity _ u @[inherit_doc] scoped[Uniformity] notation "𝓤" => uniformity open scoped Uniformity /-- Construct a `UniformSpace` from a `u : UniformSpace.Core` and a `TopologicalSpace` structure that is equal to `u.toTopologicalSpace`. -/ abbrev UniformSpace.ofCoreEq {α : Type u} (u : UniformSpace.Core α) (t : TopologicalSpace α) (h : t = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := t nhds_eq_comap_uniformity x := by rw [h, u.nhds_toTopologicalSpace] /-- Construct a `UniformSpace` from a `UniformSpace.Core`. -/ abbrev UniformSpace.ofCore {α : Type u} (u : UniformSpace.Core α) : UniformSpace α := .ofCoreEq u _ rfl /-- Construct a `UniformSpace.Core` from a `UniformSpace`. -/ abbrev UniformSpace.toCore (u : UniformSpace α) : UniformSpace.Core α where __ := u refl := by rintro U hU ⟨x, y⟩ (rfl : x = y) have : Prod.mk x ⁻¹' U ∈ 𝓝 x := by rw [UniformSpace.nhds_eq_comap_uniformity] exact preimage_mem_comap hU convert mem_of_mem_nhds this theorem UniformSpace.toCore_toTopologicalSpace (u : UniformSpace α) : u.toCore.toTopologicalSpace = u.toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by rw [u.nhds_eq_comap_uniformity, u.toCore.nhds_toTopologicalSpace] lemma UniformSpace.mem_uniformity_ofCore_iff {u : UniformSpace.Core α} {s : SetRel α α} : s ∈ 𝓤[.ofCore u] ↔ s ∈ u.uniformity := Iff.rfl @[ext (iff := false)] protected theorem UniformSpace.ext {u₁ u₂ : UniformSpace α} (h : 𝓤[u₁] = 𝓤[u₂]) : u₁ = u₂ := by have : u₁.toTopologicalSpace = u₂.toTopologicalSpace := TopologicalSpace.ext_nhds fun x ↦ by rw [u₁.nhds_eq_comap_uniformity, u₂.nhds_eq_comap_uniformity] exact congr_arg (comap _) h cases u₁; cases u₂; congr protected theorem UniformSpace.ext_iff {u₁ u₂ : UniformSpace α} : u₁ = u₂ ↔ ∀ s, s ∈ 𝓤[u₁] ↔ s ∈ 𝓤[u₂] := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem UniformSpace.ofCoreEq_toCore (u : UniformSpace α) (t : TopologicalSpace α) (h : t = u.toCore.toTopologicalSpace) : .ofCoreEq u.toCore t h = u := UniformSpace.ext rfl /-- Replace topology in a `UniformSpace` instance with a propositionally (but possibly not definitionally) equal one. -/ abbrev UniformSpace.replaceTopology {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := i nhds_eq_comap_uniformity x := by rw [h, u.nhds_eq_comap_uniformity] theorem UniformSpace.replaceTopology_eq {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : u.replaceTopology h = u := UniformSpace.ext rfl section UniformSpace variable [UniformSpace α] theorem nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (Prod.mk x) := UniformSpace.nhds_eq_comap_uniformity x theorem isOpen_uniformity {s : Set α} : IsOpen s ↔ ∀ x ∈ s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap_prodMk] theorem refl_le_uniformity : 𝓟 SetRel.id ≤ 𝓤 α := (@UniformSpace.toCore α _).refl instance uniformity.neBot [Nonempty α] : NeBot (𝓤 α) := diagonal_nonempty.principal_neBot.mono refl_le_uniformity theorem refl_mem_uniformity {x : α} {s : SetRel α α} (h : s ∈ 𝓤 α) : (x, x) ∈ s := refl_le_uniformity h rfl theorem mem_uniformity_of_eq {x y : α} {s : SetRel α α} (h : s ∈ 𝓤 α) (hx : x = y) : (x, y) ∈ s := refl_le_uniformity h hx theorem symm_le_uniformity : map (@Prod.swap α α) (𝓤 _) ≤ 𝓤 _ := UniformSpace.symm theorem comp_le_uniformity : ((𝓤 α).lift' fun s : SetRel α α => s ○ s) ≤ 𝓤 α := UniformSpace.comp theorem lift'_comp_uniformity : ((𝓤 α).lift' fun s : SetRel α α => s ○ s) = 𝓤 α := comp_le_uniformity.antisymm <| le_lift'.2 fun s hs ↦ mem_of_superset hs <| have : SetRel.IsRefl s := ⟨fun _ ↦ refl_mem_uniformity hs⟩; SetRel.left_subset_comp theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (𝓤 α) (𝓤 α) := symm_le_uniformity theorem comp_mem_uniformity_sets {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.relComp monotone_id).mp <| comp_le_uniformity hs /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is transitive. -/ theorem Filter.Tendsto.uniformity_trans {l : Filter β} {f₁ f₂ f₃ : β → α} (h₁₂ : Tendsto (fun x => (f₁ x, f₂ x)) l (𝓤 α)) (h₂₃ : Tendsto (fun x => (f₂ x, f₃ x)) l (𝓤 α)) : Tendsto (fun x => (f₁ x, f₃ x)) l (𝓤 α) := by refine le_trans (le_lift'.2 fun s hs => mem_map.2 ?_) comp_le_uniformity filter_upwards [mem_map.1 (h₁₂ hs), mem_map.1 (h₂₃ hs)] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩ /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is symmetric. -/ theorem Filter.Tendsto.uniformity_symm {l : Filter β} {f : β → α × α} (h : Tendsto f l (𝓤 α)) : Tendsto (fun x => ((f x).2, (f x).1)) l (𝓤 α) := tendsto_swap_uniformity.comp h /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is reflexive. -/ theorem tendsto_diag_uniformity (f : β → α) (l : Filter β) : Tendsto (fun x => (f x, f x)) l (𝓤 α) := fun _s hs => mem_map.2 <| univ_mem' fun _ => refl_mem_uniformity hs theorem tendsto_const_uniformity {a : α} {f : Filter β} : Tendsto (fun _ => (a, a)) f (𝓤 α) := tendsto_diag_uniformity (fun _ => a) f theorem symm_of_uniformity {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s := have : preimage Prod.swap s ∈ 𝓤 α := symm_le_uniformity hs ⟨s ∩ preimage Prod.swap s, inter_mem hs this, fun _ _ ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩, inter_subset_left⟩ theorem comp_symm_of_uniformity {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ {a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s := let ⟨_t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ ⟨t', ht', ht'₁ _ _, Subset.trans (monotone_id.relComp monotone_id ht'₂) ht₂⟩ theorem uniformity_le_symm : 𝓤 α ≤ map Prod.swap (𝓤 α) := by rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap theorem uniformity_eq_symm : 𝓤 α = map Prod.swap (𝓤 α) := le_antisymm uniformity_le_symm symm_le_uniformity @[simp] theorem comap_swap_uniformity : comap (@Prod.swap α α) (𝓤 α) = 𝓤 α := (congr_arg _ uniformity_eq_symm).trans <| comap_map Prod.swap_injective theorem symmetrize_mem_uniformity {V : SetRel α α} (h : V ∈ 𝓤 α) : SetRel.symmetrize V ∈ 𝓤 α := by apply (𝓤 α).inter_sets h rw [← comap_swap_uniformity] exact preimage_mem_comap h /-- Symmetric entourages form a basis of `𝓤 α` -/ theorem UniformSpace.hasBasis_symmetric : (𝓤 α).HasBasis (fun s : SetRel α α => s ∈ 𝓤 α ∧ SetRel.IsSymm s) id := hasBasis_self.2 fun t t_in => ⟨SetRel.symmetrize t, symmetrize_mem_uniformity t_in, inferInstance, SetRel.symmetrize_subset_self⟩ theorem uniformity_lift_le_swap {g : SetRel α α → Filter β} {f : Filter β} (hg : Monotone g) (h : ((𝓤 α).lift fun s => g (preimage Prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f := calc (𝓤 α).lift g ≤ (Filter.map (@Prod.swap α α) <| 𝓤 α).lift g := lift_mono uniformity_le_symm le_rfl _ ≤ _ := by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h theorem uniformity_lift_le_comp {f : SetRel α α → Filter β} (h : Monotone f) : ((𝓤 α).lift fun s => f (s ○ s)) ≤ (𝓤 α).lift f := calc ((𝓤 α).lift fun s => f (s ○ s)) = ((𝓤 α).lift' fun s : SetRel α α => s ○ s).lift f := by rw [lift_lift'_assoc] · exact monotone_id.relComp monotone_id · exact h _ ≤ (𝓤 α).lift f := lift_mono comp_le_uniformity le_rfl theorem comp3_mem_uniformity {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ (t ○ t) ⊆ s := let ⟨_t', ht', ht's⟩ := comp_mem_uniformity_sets hs let ⟨t, ht, htt'⟩ := comp_mem_uniformity_sets ht' have : SetRel.IsRefl t := SetRel.id_subset_iff.1 <| refl_le_uniformity ht ⟨t, ht, (SetRel.comp_subset_comp (SetRel.left_subset_comp.trans htt') htt').trans ht's⟩ /-- See also `comp3_mem_uniformity`. -/ theorem comp_le_uniformity3 : ((𝓤 α).lift' fun s : SetRel α α => s ○ (s ○ s)) ≤ 𝓤 α := fun _ h => let ⟨_t, htU, ht⟩ := comp3_mem_uniformity h mem_of_superset (mem_lift' htU) ht /-- See also `comp_open_symm_mem_uniformity_sets`. -/ theorem comp_symm_mem_uniformity_sets {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, SetRel.IsSymm t ∧ t ○ t ⊆ s := by obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs use SetRel.symmetrize w, symmetrize_mem_uniformity w_in, inferInstance have : SetRel.symmetrize w ⊆ w := SetRel.symmetrize_subset_self calc SetRel.symmetrize w ○ SetRel.symmetrize w _ ⊆ w ○ w := by gcongr _ ⊆ s := w_sub theorem subset_comp_self_of_mem_uniformity {s : SetRel α α} (h : s ∈ 𝓤 α) : s ⊆ s ○ s := have : SetRel.IsRefl s := SetRel.id_subset_iff.1 <| refl_le_uniformity h; SetRel.left_subset_comp theorem comp_comp_symm_mem_uniformity_sets {s : SetRel α α} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, SetRel.IsSymm t ∧ t ○ t ○ t ⊆ s := by rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, _, w_sub⟩ rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩ use t, t_in, t_symm have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in calc t ○ t ○ t ⊆ w ○ (t ○ t) := by gcongr _ ⊆ w ○ w := by gcongr _ ⊆ s := w_sub /-! ### Balls in uniform spaces -/ namespace UniformSpace /-- The ball around `(x : β)` with respect to `(V : Set (β × β))`. Intended to be used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/ def ball (x : β) (V : Set (β × β)) : Set β := Prod.mk x ⁻¹' V open UniformSpace (ball) lemma mem_ball_self (x : α) {V : SetRel α α} : V ∈ 𝓤 α → x ∈ ball x V := refl_mem_uniformity /-- The triangle inequality for `UniformSpace.ball` -/ theorem mem_ball_comp {V W : Set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W) := SetRel.prodMk_mem_comp h h' theorem ball_subset_of_comp_subset {V W : Set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) : ball x W ⊆ ball y V := fun _z z_in => h' (mem_ball_comp h z_in) theorem ball_mono {V W : Set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W := preimage_mono h theorem ball_inter (x : β) (V W : Set (β × β)) : ball x (V ∩ W) = ball x V ∩ ball x W := preimage_inter theorem ball_inter_left (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x V := ball_mono inter_subset_left x theorem ball_inter_right (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x W := ball_mono inter_subset_right x theorem ball_iInter {x : β} {V : ι → Set (β × β)} : ball x (⋂ i, V i) = ⋂ i, ball x (V i) := preimage_iInter theorem mem_ball_symmetry {V : SetRel β β} [V.IsSymm] {x y} : x ∈ ball y V ↔ y ∈ ball x V := V.comm theorem ball_eq_of_symmetry {V : SetRel β β} [V.IsSymm] {x} : ball x V = { y | (y, x) ∈ V } := by ext y rw [mem_ball_symmetry] exact Iff.rfl theorem mem_comp_of_mem_ball {V W : SetRel β β} {x y z : β} [V.IsSymm] (hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W := by rw [mem_ball_symmetry] at hx exact ⟨z, hx, hy⟩ theorem mem_comp_comp {V W M : SetRel β β} [W.IsSymm] {p : β × β} : p ∈ V ○ M ○ W ↔ (ball p.1 V ×ˢ ball p.2 W ∩ M).Nonempty := by obtain ⟨x, y⟩ := p constructor · rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩ exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry]⟩, hwz⟩ · rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩ rw [mem_ball_symmetry] at z_in exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩ end UniformSpace /-! ### Neighborhoods in uniform spaces -/ open UniformSpace theorem mem_nhds_uniformity_iff_right {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [nhds_eq_comap_uniformity, mem_comap_prodMk] theorem mem_nhds_uniformity_iff_left {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.2 = x → p.1 ∈ s } ∈ 𝓤 α := by rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right] simp only [mem_map, preimage_setOf_eq, Prod.snd_swap, Prod.fst_swap] theorem nhdsWithin_eq_comap_uniformity_of_mem {x : α} {T : Set α} (hx : x ∈ T) (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (T ×ˢ S)).comap (Prod.mk x) := by simp [nhdsWithin, nhds_eq_comap_uniformity, hx] theorem nhdsWithin_eq_comap_uniformity {x : α} (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (univ ×ˢ S)).comap (Prod.mk x) := nhdsWithin_eq_comap_uniformity_of_mem (mem_univ _) S /-- See also `isOpen_iff_isOpen_ball_subset`. -/ theorem isOpen_iff_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s := by simp_rw [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap, ball] theorem nhds_basis_uniformity' {p : ι → Prop} {s : ι → SetRel α α} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => ball x (s i) := by rw [nhds_eq_comap_uniformity] exact h.comap (Prod.mk x) theorem nhds_basis_uniformity {p : ι → Prop} {s : ι → SetRel α α} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => { y | (y, x) ∈ s i } := by replace h := h.comap Prod.swap rw [comap_swap_uniformity] at h exact nhds_basis_uniformity' h theorem nhds_eq_comap_uniformity' {x : α} : 𝓝 x = (𝓤 α).comap fun y => (y, x) := (nhds_basis_uniformity (𝓤 α).basis_sets).eq_of_same_basis <| (𝓤 α).basis_sets.comap _ theorem UniformSpace.mem_nhds_iff {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, ball x V ⊆ s := by rw [nhds_eq_comap_uniformity, mem_comap] simp_rw [ball] theorem UniformSpace.ball_mem_nhds (x : α) ⦃V : SetRel α α⦄ (V_in : V ∈ 𝓤 α) : ball x V ∈ 𝓝 x := by rw [UniformSpace.mem_nhds_iff] exact ⟨V, V_in, Subset.rfl⟩ theorem UniformSpace.ball_mem_nhdsWithin {x : α} {S : Set α} ⦃V : SetRel α α⦄ (x_in : x ∈ S) (V_in : V ∈ 𝓤 α ⊓ 𝓟 (S ×ˢ S)) : ball x V ∈ 𝓝[S] x := by rw [nhdsWithin_eq_comap_uniformity_of_mem x_in, mem_comap] exact ⟨V, V_in, Subset.rfl⟩ theorem UniformSpace.mem_nhds_iff_symm {x : α} {s : Set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, SetRel.IsSymm V ∧ ball x V ⊆ s := by rw [UniformSpace.mem_nhds_iff] constructor · rintro ⟨V, V_in, V_sub⟩ use SetRel.symmetrize V, symmetrize_mem_uniformity V_in, inferInstance exact Subset.trans (ball_mono SetRel.symmetrize_subset_self x) V_sub · rintro ⟨V, V_in, _, V_sub⟩ exact ⟨V, V_in, V_sub⟩ theorem UniformSpace.hasBasis_nhds (x : α) : HasBasis (𝓝 x) (fun s : SetRel α α => s ∈ 𝓤 α ∧ SetRel.IsSymm s) fun s => ball x s := ⟨fun t => by simp [UniformSpace.mem_nhds_iff_symm, and_assoc]⟩ open UniformSpace theorem UniformSpace.mem_closure_iff_symm_ball {s : Set α} {x} : x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → SetRel.IsSymm V → (s ∩ ball x V).Nonempty := by simp [mem_closure_iff_nhds_basis (hasBasis_nhds x), Set.Nonempty] theorem UniformSpace.mem_closure_iff_ball {s : Set α} {x} : x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → (ball x V ∩ s).Nonempty := by simp [mem_closure_iff_nhds_basis' (nhds_basis_uniformity' (𝓤 α).basis_sets)] theorem nhds_eq_uniformity {x : α} : 𝓝 x = (𝓤 α).lift' (ball x) := (nhds_basis_uniformity' (𝓤 α).basis_sets).eq_biInf theorem nhds_eq_uniformity' {x : α} : 𝓝 x = (𝓤 α).lift' fun s => { y | (y, x) ∈ s } := (nhds_basis_uniformity (𝓤 α).basis_sets).eq_biInf theorem mem_nhds_left (x : α) {s : SetRel α α} (h : s ∈ 𝓤 α) : { y : α | (x, y) ∈ s } ∈ 𝓝 x := ball_mem_nhds x h theorem mem_nhds_right (y : α) {s : SetRel α α} (h : s ∈ 𝓤 α) : { x : α | (x, y) ∈ s } ∈ 𝓝 y := mem_nhds_left _ (symm_le_uniformity h) theorem exists_mem_nhds_ball_subset_of_mem_nhds {a : α} {U : Set α} (h : U ∈ 𝓝 a) : ∃ V ∈ 𝓝 a, ∃ t ∈ 𝓤 α, ∀ a' ∈ V, UniformSpace.ball a' t ⊆ U := let ⟨t, ht, htU⟩ := comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 h) ⟨_, mem_nhds_left a ht, t, ht, fun a₁ h₁ a₂ h₂ => @htU (a, a₂) ⟨a₁, h₁, h₂⟩ rfl⟩ theorem tendsto_right_nhds_uniformity {a : α} : Tendsto (fun a' => (a', a)) (𝓝 a) (𝓤 α) := fun _ => mem_nhds_right a theorem tendsto_left_nhds_uniformity {a : α} : Tendsto (fun a' => (a, a')) (𝓝 a) (𝓤 α) := fun _ => mem_nhds_left a theorem lift_nhds_left {x : α} {g : Set α → Filter β} (hg : Monotone g) : (𝓝 x).lift g = (𝓤 α).lift fun s : SetRel α α => g (ball x s) := by rw [nhds_eq_comap_uniformity, comap_lift_eq2 hg] simp_rw [ball, Function.comp_def] theorem lift_nhds_right {x : α} {g : Set α → Filter β} (hg : Monotone g) : (𝓝 x).lift g = (𝓤 α).lift fun s : SetRel α α => g { y | (y, x) ∈ s } := by rw [nhds_eq_comap_uniformity', comap_lift_eq2 hg] simp_rw [Function.comp_def, preimage] theorem nhds_nhds_eq_uniformity_uniformity_prod {a b : α} : 𝓝 a ×ˢ 𝓝 b = (𝓤 α).lift fun s : SetRel α α => (𝓤 α).lift' fun t => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ t } := by rw [nhds_eq_uniformity', nhds_eq_uniformity, prod_lift'_lift'] exacts [rfl, monotone_preimage, monotone_preimage] theorem Filter.HasBasis.biInter_biUnion_ball {p : ι → Prop} {U : ι → SetRel α α} (h : HasBasis (𝓤 α) p U) (s : Set α) : (⋂ (i) (_ : p i), ⋃ x ∈ s, ball x (U i)) = closure s := by ext x simp [mem_closure_iff_nhds_basis (nhds_basis_uniformity h), ball] /-! ### Uniform continuity -/ /-- A function `f : α → β` is *uniformly continuous* if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `α`. -/ def UniformContinuous [UniformSpace β] (f : α → β) := Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α) (𝓤 β) /-- Notation for uniform continuity with respect to non-standard `UniformSpace` instances. -/ scoped[Uniformity] notation "UniformContinuous[" u₁ ", " u₂ "]" => @UniformContinuous _ _ u₁ u₂ /-- A function `f : α → β` is *uniformly continuous* on `s : Set α` if `(f x, f y)` tends to the diagonal as `(x, y)` tends to the diagonal while remaining in `s ×ˢ s`. In other words, if `x` is sufficiently close to `y`, then `f x` is close to `f y` no matter where `x` and `y` are located in `s`. -/ def UniformContinuousOn [UniformSpace β] (f : α → β) (s : Set α) : Prop := Tendsto (fun x : α × α => (f x.1, f x.2)) (𝓤 α ⊓ 𝓟 (s ×ˢ s)) (𝓤 β) theorem uniformContinuous_def [UniformSpace β] {f : α → β} : UniformContinuous f ↔ ∀ r ∈ 𝓤 β, { x : α × α | (f x.1, f x.2) ∈ r } ∈ 𝓤 α := Iff.rfl theorem uniformContinuous_iff_eventually [UniformSpace β] {f : α → β} : UniformContinuous f ↔ ∀ r ∈ 𝓤 β, ∀ᶠ x : α × α in 𝓤 α, (f x.1, f x.2) ∈ r := Iff.rfl theorem uniformContinuousOn_univ [UniformSpace β] {f : α → β} : UniformContinuousOn f univ ↔ UniformContinuous f := by rw [UniformContinuousOn, UniformContinuous, univ_prod_univ, principal_univ, inf_top_eq] theorem uniformContinuous_of_const [UniformSpace β] {c : α → β} (h : ∀ a b, c a = c b) : UniformContinuous c := have : (fun x : α × α => (c x.fst, c x.snd)) ⁻¹' SetRel.id = univ := eq_univ_iff_forall.2 fun ⟨a, b⟩ => h a b le_trans (map_le_iff_le_comap.2 <| by simp [comap_principal, this]) refl_le_uniformity theorem uniformContinuous_id : UniformContinuous (@id α) := tendsto_id theorem uniformContinuous_const [UniformSpace β] {b : β} : UniformContinuous fun _ : α => b := uniformContinuous_of_const fun _ _ => rfl nonrec theorem UniformContinuous.comp [UniformSpace β] [UniformSpace γ] {g : β → γ} {f : α → β} (hg : UniformContinuous g) (hf : UniformContinuous f) : UniformContinuous (g ∘ f) := hg.comp hf /-- If a function `T` is uniformly continuous in a uniform space `β`, then its `n`-th iterate `T^[n]` is also uniformly continuous. -/ theorem UniformContinuous.iterate [UniformSpace β] (T : β → β) (n : ℕ) (h : UniformContinuous T) : UniformContinuous T^[n] := by induction n with | zero => exact uniformContinuous_id | succ n hn => exact Function.iterate_succ _ _ ▸ UniformContinuous.comp hn h theorem Filter.HasBasis.uniformContinuous_iff {ι'} [UniformSpace β] {p : ι → Prop} {s : ι → SetRel α α} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)} (hb : (𝓤 β).HasBasis q t) {f : α → β} : UniformContinuous f ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ t i := (ha.tendsto_iff hb).trans <| by simp only [Prod.forall] theorem Filter.HasBasis.uniformContinuousOn_iff {ι'} [UniformSpace β] {p : ι → Prop} {s : ι → SetRel α α} (ha : (𝓤 α).HasBasis p s) {q : ι' → Prop} {t : ι' → Set (β × β)} (hb : (𝓤 β).HasBasis q t) {f : α → β} {S : Set α} : UniformContinuousOn f S ↔ ∀ i, q i → ∃ j, p j ∧ ∀ x, x ∈ S → ∀ y, y ∈ S → (x, y) ∈ s j → (f x, f y) ∈ t i := ((ha.inf_principal (S ×ˢ S)).tendsto_iff hb).trans <| by simp_rw [Prod.forall, Set.inter_comm (s _), forall_mem_comm, mem_inter_iff, mem_prod, and_imp] end UniformSpace
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/UniformEmbedding.lean
import Mathlib.Topology.UniformSpace.Cauchy import Mathlib.Topology.UniformSpace.Separation import Mathlib.Topology.DenseEmbedding /-! # Uniform embeddings of uniform spaces. Extension of uniform continuous functions. -/ open Filter Function Set Uniformity Topology open scoped SetRel section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} [UniformSpace α] [UniformSpace β] [UniformSpace γ] {f : α → β} /-! ### Uniform inducing maps -/ /-- A map `f : α → β` between uniform spaces is called *uniform inducing* if the uniformity filter on `α` is the pullback of the uniformity filter on `β` under `Prod.map f f`. If `α` is a separated space, then this implies that `f` is injective, hence it is a `IsUniformEmbedding`. -/ @[mk_iff] structure IsUniformInducing (f : α → β) : Prop where /-- The uniformity filter on the domain is the pullback of the uniformity filter on the codomain under `Prod.map f f`. -/ comap_uniformity : comap (fun x : α × α => (f x.1, f x.2)) (𝓤 β) = 𝓤 α lemma isUniformInducing_iff_uniformSpace {f : α → β} : IsUniformInducing f ↔ ‹UniformSpace β›.comap f = ‹UniformSpace α› := by rw [isUniformInducing_iff, UniformSpace.ext_iff, Filter.ext_iff] rfl protected alias ⟨IsUniformInducing.comap_uniformSpace, _⟩ := isUniformInducing_iff_uniformSpace lemma isUniformInducing_iff' {f : α → β} : IsUniformInducing f ↔ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by rw [isUniformInducing_iff, UniformContinuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; rfl protected lemma Filter.HasBasis.isUniformInducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : IsUniformInducing f ↔ (∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by simp [isUniformInducing_iff', h.uniformContinuous_iff h', (h'.comap _).le_basis_iff h, subset_def] theorem IsUniformInducing.mk' {f : α → β} (h : ∀ s, s ∈ 𝓤 α ↔ ∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : IsUniformInducing f := ⟨by simp [eq_comm, Filter.ext_iff, subset_def, h]⟩ theorem IsUniformInducing.id : IsUniformInducing (@id α) := ⟨by rw [← Prod.map_def, Prod.map_id, comap_id]⟩ theorem IsUniformInducing.comp {g : β → γ} (hg : IsUniformInducing g) {f : α → β} (hf : IsUniformInducing f) : IsUniformInducing (g ∘ f) := ⟨by rw [← hf.1, ← hg.1, comap_comap]; rfl⟩ theorem IsUniformInducing.of_comp_iff {g : β → γ} (hg : IsUniformInducing g) {f : α → β} : IsUniformInducing (g ∘ f) ↔ IsUniformInducing f := by refine ⟨fun h ↦ ?_, hg.comp⟩ rw [isUniformInducing_iff, ← hg.comap_uniformity, comap_comap, ← h.comap_uniformity, Function.comp_def, Function.comp_def] theorem IsUniformInducing.basis_uniformity {f : α → β} (hf : IsUniformInducing f) {ι : Sort*} {p : ι → Prop} {s : ι → Set (β × β)} (H : (𝓤 β).HasBasis p s) : (𝓤 α).HasBasis p fun i => Prod.map f f ⁻¹' s i := hf.1 ▸ H.comap _ theorem IsUniformInducing.cauchy_map_iff {f : α → β} (hf : IsUniformInducing f) {F : Filter α} : Cauchy (map f F) ↔ Cauchy F := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap, ← hf.comap_uniformity] theorem IsUniformInducing.of_comp {f : α → β} {g : β → γ} (hf : UniformContinuous f) (hg : UniformContinuous g) (hgf : IsUniformInducing (g ∘ f)) : IsUniformInducing f := by refine ⟨le_antisymm ?_ hf.le_comap⟩ rw [← hgf.1, ← Prod.map_def, ← Prod.map_def, ← Prod.map_comp_map f f g g, ← comap_comap] exact comap_mono hg.le_comap theorem IsUniformInducing.uniformContinuous {f : α → β} (hf : IsUniformInducing f) : UniformContinuous f := (isUniformInducing_iff'.1 hf).1 theorem IsUniformInducing.uniformContinuous_iff {f : α → β} {g : β → γ} (hg : IsUniformInducing g) : UniformContinuous f ↔ UniformContinuous (g ∘ f) := by dsimp only [UniformContinuous, Tendsto] simp only [← hg.comap_uniformity, ← map_le_iff_le_comap, Filter.map_map, Function.comp_def] protected theorem IsUniformInducing.isUniformInducing_comp_iff {f : α → β} {g : β → γ} (hg : IsUniformInducing g) : IsUniformInducing (g ∘ f) ↔ IsUniformInducing f := by simp only [isUniformInducing_iff, ← hg.comap_uniformity, comap_comap, Function.comp_def] theorem IsUniformInducing.uniformContinuousOn_iff {f : α → β} {g : β → γ} {S : Set α} (hg : IsUniformInducing g) : UniformContinuousOn f S ↔ UniformContinuousOn (g ∘ f) S := by dsimp only [UniformContinuousOn, Tendsto] rw [← hg.comap_uniformity, ← map_le_iff_le_comap, Filter.map_map, comp_def, comp_def] theorem IsUniformInducing.isInducing {f : α → β} (h : IsUniformInducing f) : IsInducing f := by obtain rfl := h.comap_uniformSpace exact .induced f theorem IsUniformInducing.prod {α' : Type*} {β' : Type*} [UniformSpace α'] [UniformSpace β'] {e₁ : α → α'} {e₂ : β → β'} (h₁ : IsUniformInducing e₁) (h₂ : IsUniformInducing e₂) : IsUniformInducing fun p : α × β => (e₁ p.1, e₂ p.2) := ⟨by simp [Function.comp_def, uniformity_prod, ← h₁.1, ← h₂.1, comap_inf, comap_comap]⟩ lemma IsUniformInducing.isDenseInducing (h : IsUniformInducing f) (hd : DenseRange f) : IsDenseInducing f where toIsInducing := h.isInducing dense := hd lemma SeparationQuotient.isUniformInducing_mk : IsUniformInducing (mk : α → SeparationQuotient α) := ⟨comap_mk_uniformity⟩ protected theorem IsUniformInducing.injective [T0Space α] {f : α → β} (h : IsUniformInducing f) : Injective f := h.isInducing.injective /-! ### Uniform embeddings -/ /-- A map `f : α → β` between uniform spaces is a *uniform embedding* if it is uniform inducing and injective. If `α` is a separated space, then the latter assumption follows from the former. -/ @[mk_iff] structure IsUniformEmbedding (f : α → β) : Prop extends IsUniformInducing f where /-- A uniform embedding is injective. -/ injective : Function.Injective f lemma IsUniformEmbedding.isUniformInducing (hf : IsUniformEmbedding f) : IsUniformInducing f := hf.toIsUniformInducing theorem isUniformEmbedding_iff' {f : α → β} : IsUniformEmbedding f ↔ Injective f ∧ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by rw [isUniformEmbedding_iff, and_comm, isUniformInducing_iff'] theorem Filter.HasBasis.isUniformEmbedding_iff' {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : IsUniformEmbedding f ↔ Injective f ∧ (∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by rw [isUniformEmbedding_iff, and_comm, h.isUniformInducing_iff h'] theorem Filter.HasBasis.isUniformEmbedding_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : IsUniformEmbedding f ↔ Injective f ∧ UniformContinuous f ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by simp only [h.isUniformEmbedding_iff' h', h.uniformContinuous_iff h'] theorem isUniformEmbedding_subtype_val {p : α → Prop} : IsUniformEmbedding (Subtype.val : Subtype p → α) := { comap_uniformity := rfl injective := Subtype.val_injective } theorem isUniformEmbedding_set_inclusion {s t : Set α} (hst : s ⊆ t) : IsUniformEmbedding (inclusion hst) where comap_uniformity := by rw [uniformity_subtype, uniformity_subtype, comap_comap]; rfl injective := inclusion_injective hst theorem IsUniformEmbedding.comp {g : β → γ} (hg : IsUniformEmbedding g) {f : α → β} (hf : IsUniformEmbedding f) : IsUniformEmbedding (g ∘ f) where toIsUniformInducing := hg.isUniformInducing.comp hf.isUniformInducing injective := hg.injective.comp hf.injective theorem IsUniformEmbedding.of_comp_iff {g : β → γ} (hg : IsUniformEmbedding g) {f : α → β} : IsUniformEmbedding (g ∘ f) ↔ IsUniformEmbedding f := by simp_rw [isUniformEmbedding_iff, hg.isUniformInducing.of_comp_iff, hg.injective.of_comp_iff f] theorem Equiv.isUniformEmbedding {α β : Type*} [UniformSpace α] [UniformSpace β] (f : α ≃ β) (h₁ : UniformContinuous f) (h₂ : UniformContinuous f.symm) : IsUniformEmbedding f := isUniformEmbedding_iff'.2 ⟨f.injective, h₁, by rwa [← Equiv.prodCongr_apply, ← map_equiv_symm]⟩ theorem isUniformEmbedding_inl : IsUniformEmbedding (Sum.inl : α → α ⊕ β) := isUniformEmbedding_iff'.2 ⟨Sum.inl_injective, uniformContinuous_inl, fun s hs => ⟨Prod.map Sum.inl Sum.inl '' s ∪ range (Prod.map Sum.inr Sum.inr), union_mem_sup (image_mem_map hs) range_mem_map, fun x h => by simpa [Prod.map_apply'] using h⟩⟩ theorem isUniformEmbedding_inr : IsUniformEmbedding (Sum.inr : β → α ⊕ β) := isUniformEmbedding_iff'.2 ⟨Sum.inr_injective, uniformContinuous_inr, fun s hs => ⟨range (Prod.map Sum.inl Sum.inl) ∪ Prod.map Sum.inr Sum.inr '' s, union_mem_sup range_mem_map (image_mem_map hs), fun x h => by simpa [Prod.map_apply'] using h⟩⟩ /-- If the domain of a `IsUniformInducing` map `f` is a T₀ space, then `f` is injective, hence it is a `IsUniformEmbedding`. -/ protected theorem IsUniformInducing.isUniformEmbedding [T0Space α] {f : α → β} (hf : IsUniformInducing f) : IsUniformEmbedding f := ⟨hf, hf.isInducing.injective⟩ theorem isUniformEmbedding_iff_isUniformInducing [T0Space α] {f : α → β} : IsUniformEmbedding f ↔ IsUniformInducing f := ⟨IsUniformEmbedding.isUniformInducing, IsUniformInducing.isUniformEmbedding⟩ /-- If a map `f : α → β` sends any two distinct points to point that are **not** related by a fixed `s ∈ 𝓤 β`, then `f` is uniform inducing with respect to the discrete uniformity on `α`: the preimage of `𝓤 β` under `Prod.map f f` is the principal filter generated by the diagonal in `α × α`. -/ theorem comap_uniformity_of_spaced_out {α} {f : α → β} {s : Set (β × β)} (hs : s ∈ 𝓤 β) (hf : Pairwise fun x y => (f x, f y) ∉ s) : comap (Prod.map f f) (𝓤 β) = 𝓟 SetRel.id := by refine le_antisymm ?_ (@refl_le_uniformity α (UniformSpace.comap f _)) calc comap (Prod.map f f) (𝓤 β) ≤ comap (Prod.map f f) (𝓟 s) := comap_mono (le_principal_iff.2 hs) _ = 𝓟 (Prod.map f f ⁻¹' s) := comap_principal _ ≤ 𝓟 SetRel.id := principal_mono.2 ?_ rintro ⟨x, y⟩; simpa [not_imp_not] using @hf x y /-- If a map `f : α → β` sends any two distinct points to point that are **not** related by a fixed `s ∈ 𝓤 β`, then `f` is a uniform embedding with respect to the discrete uniformity on `α`. -/ theorem isUniformEmbedding_of_spaced_out {α} {f : α → β} {s : Set (β × β)} (hs : s ∈ 𝓤 β) (hf : Pairwise fun x y => (f x, f y) ∉ s) : @IsUniformEmbedding α β ⊥ ‹_› f := by let _ : UniformSpace α := ⊥; have := discreteTopology_bot α exact IsUniformInducing.isUniformEmbedding ⟨comap_uniformity_of_spaced_out hs hf⟩ protected lemma IsUniformEmbedding.isEmbedding {f : α → β} (h : IsUniformEmbedding f) : IsEmbedding f where toIsInducing := h.toIsUniformInducing.isInducing injective := h.injective theorem IsUniformEmbedding.isDenseEmbedding {f : α → β} (h : IsUniformEmbedding f) (hd : DenseRange f) : IsDenseEmbedding f := { h.isEmbedding with dense := hd } theorem isClosedEmbedding_of_spaced_out {α} [TopologicalSpace α] [DiscreteTopology α] [T0Space β] {f : α → β} {s : Set (β × β)} (hs : s ∈ 𝓤 β) (hf : Pairwise fun x y => (f x, f y) ∉ s) : IsClosedEmbedding f := by rcases @DiscreteTopology.eq_bot α _ _ with rfl; let _ : UniformSpace α := ⊥ exact { (isUniformEmbedding_of_spaced_out hs hf).isEmbedding with isClosed_range := isClosed_range_of_spaced_out hs hf } theorem closure_image_mem_nhds_of_isUniformInducing {s : Set (α × α)} {e : α → β} (b : β) (he₁ : IsUniformInducing e) (he₂ : IsDenseInducing e) (hs : s ∈ 𝓤 α) : ∃ a, closure (e '' { a' | (a, a') ∈ s }) ∈ 𝓝 b := by obtain ⟨U, ⟨hU, hUo, hsymm⟩, hs⟩ : ∃ U, (U ∈ 𝓤 β ∧ IsOpen U ∧ SetRel.IsSymm U) ∧ Prod.map e e ⁻¹' U ⊆ s := by rwa [← he₁.comap_uniformity, (uniformity_hasBasis_open_symmetric.comap _).mem_iff] at hs rcases he₂.dense.mem_nhds (UniformSpace.ball_mem_nhds b hU) with ⟨a, ha⟩ refine ⟨a, mem_of_superset ?_ (closure_mono <| image_mono <| UniformSpace.ball_mono hs a)⟩ have ho : IsOpen (UniformSpace.ball (e a) U) := UniformSpace.isOpen_ball (e a) hUo refine mem_of_superset (ho.mem_nhds <| UniformSpace.mem_ball_symmetry.2 ha) fun y hy => ?_ refine mem_closure_iff_nhds.2 fun V hV => ?_ rcases he₂.dense.mem_nhds (inter_mem hV (ho.mem_nhds hy)) with ⟨x, hxV, hxU⟩ exact ⟨e x, hxV, mem_image_of_mem e hxU⟩ theorem isUniformEmbedding_subtypeEmb (p : α → Prop) {e : α → β} (ue : IsUniformEmbedding e) (de : IsDenseEmbedding e) : IsUniformEmbedding (IsDenseEmbedding.subtypeEmb p e) := { comap_uniformity := by simp [comap_comap, Function.comp_def, IsDenseEmbedding.subtypeEmb, uniformity_subtype, ue.comap_uniformity.symm] injective := (de.subtype p).injective } theorem IsUniformEmbedding.prod {α' : Type*} {β' : Type*} [UniformSpace α'] [UniformSpace β'] {e₁ : α → α'} {e₂ : β → β'} (h₁ : IsUniformEmbedding e₁) (h₂ : IsUniformEmbedding e₂) : IsUniformEmbedding fun p : α × β => (e₁ p.1, e₂ p.2) where toIsUniformInducing := h₁.isUniformInducing.prod h₂.isUniformInducing injective := h₁.injective.prodMap h₂.injective /-- A set is complete iff its image under a uniform inducing map is complete. -/ theorem isComplete_image_iff {m : α → β} {s : Set α} (hm : IsUniformInducing m) : IsComplete (m '' s) ↔ IsComplete s := by have fact1 : SurjOn (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 <| m '' s) := surjOn_image .. |>.filter_map_Iic have fact2 : MapsTo (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 <| m '' s) := mapsTo_image .. |>.filter_map_Iic simp_rw [IsComplete, imp.swap (a := Cauchy _), ← mem_Iic (b := 𝓟 _), fact1.forall fact2, hm.cauchy_map_iff, exists_mem_image, map_le_iff_le_comap, hm.isInducing.nhds_eq_comap] /-- If `f : X → Y` is an `IsUniformInducing` map, the image `f '' s` of a set `s` is complete if and only if `s` is complete. -/ theorem IsUniformInducing.isComplete_iff {f : α → β} {s : Set α} (hf : IsUniformInducing f) : IsComplete (f '' s) ↔ IsComplete s := isComplete_image_iff hf /-- If `f : X → Y` is an `IsUniformEmbedding`, the image `f '' s` of a set `s` is complete if and only if `s` is complete. -/ theorem IsUniformEmbedding.isComplete_iff {f : α → β} {s : Set α} (hf : IsUniformEmbedding f) : IsComplete (f '' s) ↔ IsComplete s := hf.isUniformInducing.isComplete_iff /-- Sets of a subtype are complete iff their image under the coercion is complete. -/ theorem Subtype.isComplete_iff {p : α → Prop} {s : Set { x // p x }} : IsComplete s ↔ IsComplete ((↑) '' s : Set α) := isUniformEmbedding_subtype_val.isComplete_iff.symm alias ⟨isComplete_of_complete_image, _⟩ := isComplete_image_iff theorem completeSpace_iff_isComplete_range {f : α → β} (hf : IsUniformInducing f) : CompleteSpace α ↔ IsComplete (range f) := by rw [completeSpace_iff_isComplete_univ, ← isComplete_image_iff hf, image_univ] alias ⟨_, IsUniformInducing.completeSpace⟩ := completeSpace_iff_isComplete_range lemma IsUniformInducing.isComplete_range [CompleteSpace α] (hf : IsUniformInducing f) : IsComplete (range f) := (completeSpace_iff_isComplete_range hf).1 ‹_› /-- If `f` is a surjective uniform inducing map, then its domain is a complete space iff its codomain is a complete space. See also `_root_.completeSpace_congr` for a version that assumes `f` to be an equivalence. -/ theorem IsUniformInducing.completeSpace_congr {f : α → β} (hf : IsUniformInducing f) (hsurj : f.Surjective) : CompleteSpace α ↔ CompleteSpace β := by rw [completeSpace_iff_isComplete_range hf, hsurj.range_eq, completeSpace_iff_isComplete_univ] theorem SeparationQuotient.completeSpace_iff : CompleteSpace (SeparationQuotient α) ↔ CompleteSpace α := .symm <| isUniformInducing_mk.completeSpace_congr surjective_mk instance SeparationQuotient.instCompleteSpace [CompleteSpace α] : CompleteSpace (SeparationQuotient α) := completeSpace_iff.2 ‹_› /-- See also `IsUniformInducing.completeSpace_congr` for a version that works for non-injective maps. -/ theorem completeSpace_congr {e : α ≃ β} (he : IsUniformEmbedding e) : CompleteSpace α ↔ CompleteSpace β := he.completeSpace_congr e.surjective theorem completeSpace_coe_iff_isComplete {s : Set α} : CompleteSpace s ↔ IsComplete s := by rw [completeSpace_iff_isComplete_range isUniformEmbedding_subtype_val.isUniformInducing, Subtype.range_coe] alias ⟨_, IsComplete.completeSpace_coe⟩ := completeSpace_coe_iff_isComplete instance IsClosed.completeSpace_coe [CompleteSpace α] {s : Set α} [hs : IsClosed s] : CompleteSpace s := hs.isComplete.completeSpace_coe theorem completeSpace_ulift_iff : CompleteSpace (ULift α) ↔ CompleteSpace α := IsUniformInducing.completeSpace_congr ⟨rfl⟩ ULift.down_surjective /-- The lift of a complete space to another universe is still complete. -/ instance ULift.instCompleteSpace [CompleteSpace α] : CompleteSpace (ULift α) := completeSpace_ulift_iff.2 ‹_› theorem completeSpace_extension {m : β → α} (hm : IsUniformInducing m) (dense : DenseRange m) (h : ∀ f : Filter β, Cauchy f → ∃ x : α, map m f ≤ 𝓝 x) : CompleteSpace α := ⟨fun {f : Filter α} (hf : Cauchy f) => let p : Set (α × α) → Set α → Set α := fun s t => { y : α | ∃ x : α, x ∈ t ∧ (x, y) ∈ s } let g := (𝓤 α).lift fun s => f.lift' (p s) have mp₀ : Monotone p := fun _ _ h _ _ ⟨x, xs, xa⟩ => ⟨x, xs, h xa⟩ have mp₁ : ∀ {s}, Monotone (p s) := fun h _ ⟨y, ya, yxs⟩ => ⟨y, h ya, yxs⟩ have : f ≤ g := le_iInf₂ fun _ hs => le_iInf₂ fun _ ht => le_principal_iff.mpr <| mem_of_superset ht fun x hx => ⟨x, hx, refl_mem_uniformity hs⟩ have : NeBot g := hf.left.mono this have : NeBot (comap m g) := comap_neBot fun _ ht => let ⟨t', ht', ht_mem⟩ := (mem_lift_sets <| monotone_lift' monotone_const mp₀).mp ht let ⟨_, ht'', ht'_sub⟩ := (mem_lift'_sets mp₁).mp ht_mem let ⟨x, hx⟩ := hf.left.nonempty_of_mem ht'' have h₀ : NeBot (𝓝[range m] x) := dense.nhdsWithin_neBot x have h₁ : { y | (x, y) ∈ t' } ∈ 𝓝[range m] x := @mem_inf_of_left α (𝓝 x) (𝓟 (range m)) _ <| mem_nhds_left x ht' have h₂ : range m ∈ 𝓝[range m] x := @mem_inf_of_right α (𝓝 x) (𝓟 (range m)) _ <| Subset.refl _ have : { y | (x, y) ∈ t' } ∩ range m ∈ 𝓝[range m] x := @inter_mem α (𝓝[range m] x) _ _ h₁ h₂ let ⟨_, xyt', b, b_eq⟩ := h₀.nonempty_of_mem this ⟨b, b_eq.symm ▸ ht'_sub ⟨x, hx, xyt'⟩⟩ have : Cauchy g := ⟨‹NeBot g›, fun _ hs => let ⟨s₁, hs₁, comp_s₁⟩ := comp_mem_uniformity_sets hs let ⟨s₂, hs₂, comp_s₂⟩ := comp_mem_uniformity_sets hs₁ let ⟨t, ht, (prod_t : t ×ˢ t ⊆ s₂)⟩ := mem_prod_same_iff.mp (hf.right hs₂) have hg₁ : p (preimage Prod.swap s₁) t ∈ g := mem_lift (symm_le_uniformity hs₁) <| @mem_lift' α α f _ t ht have hg₂ : p s₂ t ∈ g := mem_lift hs₂ <| @mem_lift' α α f _ t ht have hg : p (Prod.swap ⁻¹' s₁) t ×ˢ p s₂ t ∈ g ×ˢ g := @prod_mem_prod α α _ _ g g hg₁ hg₂ (g ×ˢ g).sets_of_superset hg fun ⟨_, _⟩ ⟨⟨c₁, c₁t, hc₁⟩, ⟨c₂, c₂t, hc₂⟩⟩ => have : (c₁, c₂) ∈ t ×ˢ t := ⟨c₁t, c₂t⟩ comp_s₁ <| SetRel.prodMk_mem_comp hc₁ <| comp_s₂ <| SetRel.prodMk_mem_comp (prod_t this) hc₂⟩ have : Cauchy (Filter.comap m g) := ‹Cauchy g›.comap' (le_of_eq hm.comap_uniformity) ‹_› let ⟨x, (hx : map m (Filter.comap m g) ≤ 𝓝 x)⟩ := h _ this have : ClusterPt x (map m (Filter.comap m g)) := (le_nhds_iff_adhp_of_cauchy (this.map hm.uniformContinuous)).mp hx have : ClusterPt x g := this.mono map_comap_le ⟨x, calc f ≤ g := by assumption _ ≤ 𝓝 x := le_nhds_of_cauchy_adhp ‹Cauchy g› this ⟩⟩ lemma totallyBounded_image_iff {f : α → β} {s : Set α} (hf : IsUniformInducing f) : TotallyBounded (f '' s) ↔ TotallyBounded s := by refine ⟨fun hs ↦ ?_, fun h ↦ h.image hf.uniformContinuous⟩ simp_rw [(hf.basis_uniformity (basis_sets _)).totallyBounded_iff] intro t ht rcases exists_subset_image_finite_and.1 (hs.exists_subset ht) with ⟨u, -, hfin, h⟩ use u, hfin rwa [biUnion_image, image_subset_iff, preimage_iUnion₂] at h theorem totallyBounded_preimage {f : α → β} {s : Set β} (hf : IsUniformInducing f) (hs : TotallyBounded s) : TotallyBounded (f ⁻¹' s) := (totallyBounded_image_iff hf).1 <| hs.subset <| image_preimage_subset .. instance CompleteSpace.sum [CompleteSpace α] [CompleteSpace β] : CompleteSpace (α ⊕ β) := by rw [completeSpace_iff_isComplete_univ, ← range_inl_union_range_inr] exact isUniformEmbedding_inl.isUniformInducing.isComplete_range.union isUniformEmbedding_inr.isUniformInducing.isComplete_range end theorem isUniformEmbedding_comap {α : Type*} {β : Type*} {f : α → β} [u : UniformSpace β] (hf : Function.Injective f) : @IsUniformEmbedding α β (UniformSpace.comap f u) u f := @IsUniformEmbedding.mk _ _ (UniformSpace.comap f u) _ _ (@IsUniformInducing.mk _ _ (UniformSpace.comap f u) _ _ rfl) hf /-- Pull back a uniform space structure by an embedding, adjusting the new uniform structure to make sure that its topology is defeq to the original one. -/ def Topology.IsEmbedding.comapUniformSpace {α β} [TopologicalSpace α] [u : UniformSpace β] (f : α → β) (h : IsEmbedding f) : UniformSpace α := (u.comap f).replaceTopology h.eq_induced theorem Embedding.to_isUniformEmbedding {α β} [TopologicalSpace α] [u : UniformSpace β] (f : α → β) (h : IsEmbedding f) : @IsUniformEmbedding α β (h.comapUniformSpace f) u f := let _ := h.comapUniformSpace f { comap_uniformity := rfl injective := h.injective } section UniformExtension variable {α : Type*} {β : Type*} {γ : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] {e : β → α} (h_e : IsUniformInducing e) (h_dense : DenseRange e) {f : β → γ} (h_f : UniformContinuous f) local notation "ψ" => IsDenseInducing.extend (IsUniformInducing.isDenseInducing h_e h_dense) f include h_e h_dense h_f in theorem uniformly_extend_exists [CompleteSpace γ] (a : α) : ∃ c, Tendsto f (comap e (𝓝 a)) (𝓝 c) := let de := h_e.isDenseInducing h_dense have : Cauchy (𝓝 a) := cauchy_nhds have : Cauchy (comap e (𝓝 a)) := this.comap' (le_of_eq h_e.comap_uniformity) (de.comap_nhds_neBot _) have : Cauchy (map f (comap e (𝓝 a))) := this.map h_f CompleteSpace.complete this theorem uniform_extend_subtype [CompleteSpace γ] {p : α → Prop} {e : α → β} {f : α → γ} {b : β} {s : Set α} (hf : UniformContinuous fun x : Subtype p => f x.val) (he : IsUniformEmbedding e) (hd : ∀ x : β, x ∈ closure (range e)) (hb : closure (e '' s) ∈ 𝓝 b) (hs : IsClosed s) (hp : ∀ x ∈ s, p x) : ∃ c, Tendsto f (comap e (𝓝 b)) (𝓝 c) := by have de : IsDenseEmbedding e := he.isDenseEmbedding hd have de' : IsDenseEmbedding (IsDenseEmbedding.subtypeEmb p e) := de.subtype p have ue' : IsUniformEmbedding (IsDenseEmbedding.subtypeEmb p e) := isUniformEmbedding_subtypeEmb _ he de have : b ∈ closure (e '' { x | p x }) := (closure_mono <| monotone_image <| hp) (mem_of_mem_nhds hb) let ⟨c, hc⟩ := uniformly_extend_exists ue'.isUniformInducing de'.dense hf ⟨b, this⟩ replace hc : Tendsto (f ∘ Subtype.val (p := p)) (((𝓝 b).comap e).comap Subtype.val) (𝓝 c) := by simpa only [nhds_subtype_eq_comap, comap_comap, IsDenseEmbedding.subtypeEmb_coe] using hc refine ⟨c, (tendsto_comap'_iff ?_).1 hc⟩ rw [Subtype.range_coe_subtype] exact ⟨_, hb, by rwa [← de.isInducing.closure_eq_preimage_closure_image, hs.closure_eq]⟩ include h_e h_f in theorem uniformly_extend_spec [CompleteSpace γ] (a : α) : Tendsto f (comap e (𝓝 a)) (𝓝 (ψ a)) := by simpa only [IsDenseInducing.extend] using tendsto_nhds_limUnder (uniformly_extend_exists h_e ‹_› h_f _) include h_f in theorem uniformContinuous_uniformly_extend [CompleteSpace γ] : UniformContinuous ψ := fun d hd => let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd have h_pnt : ∀ {a m}, m ∈ 𝓝 a → ∃ c ∈ f '' (e ⁻¹' m), (c, ψ a) ∈ s ∧ (ψ a, c) ∈ s := fun {a m} hm => have nb : NeBot (map f (comap e (𝓝 a))) := ((h_e.isDenseInducing h_dense).comap_nhds_neBot _).map _ have : f '' (e ⁻¹' m) ∩ ({ c | (c, ψ a) ∈ s } ∩ { c | (ψ a, c) ∈ s }) ∈ map f (comap e (𝓝 a)) := inter_mem (image_mem_map <| preimage_mem_comap <| hm) (uniformly_extend_spec h_e h_dense h_f _ (inter_mem (mem_nhds_right _ hs) (mem_nhds_left _ hs))) nb.nonempty_of_mem this have : (Prod.map f f) ⁻¹' s ∈ 𝓤 β := h_f hs have : (Prod.map f f) ⁻¹' s ∈ comap (Prod.map e e) (𝓤 α) := by rwa [← h_e.comap_uniformity] at this let ⟨t, ht, ts⟩ := this show (Prod.map ψ ψ) ⁻¹' d ∈ 𝓤 α from mem_of_superset (interior_mem_uniformity ht) fun ⟨x₁, x₂⟩ hx_t => by have : interior t ∈ 𝓝 (x₁, x₂) := isOpen_interior.mem_nhds hx_t let ⟨m₁, hm₁, m₂, hm₂, (hm : m₁ ×ˢ m₂ ⊆ interior t)⟩ := mem_nhds_prod_iff.mp this obtain ⟨_, ⟨a, ha₁, rfl⟩, _, ha₂⟩ := h_pnt hm₁ obtain ⟨_, ⟨b, hb₁, rfl⟩, hb₂, _⟩ := h_pnt hm₂ have : Prod.map f f (a, b) ∈ s := ts <| mem_preimage.2 <| interior_subset (@hm (e a, e b) ⟨ha₁, hb₁⟩) exact hs_comp ⟨f a, ha₂, ⟨f b, this, hb₂⟩⟩ variable [T0Space γ] include h_f in theorem uniformly_extend_of_ind (b : β) : ψ (e b) = f b := IsDenseInducing.extend_eq_at _ h_f.continuous.continuousAt theorem uniformly_extend_unique {g : α → γ} (hg : ∀ b, g (e b) = f b) (hc : Continuous g) : ψ = g := IsDenseInducing.extend_unique _ hg hc end UniformExtension section DenseExtension variable {α β : Type*} [UniformSpace α] [UniformSpace β] theorem isUniformInducing_val (s : Set α) : IsUniformInducing (@Subtype.val α s) := ⟨uniformity_setCoe⟩ @[simp] theorem uniformContinuous_rangeFactorization_iff {f : α → β} : UniformContinuous (rangeFactorization f) ↔ UniformContinuous f := (isUniformInducing_val _).uniformContinuous_iff theorem UniformContinuous.rangeFactorization {f : α → β} (hf : UniformContinuous f) : UniformContinuous (rangeFactorization f) := uniformContinuous_rangeFactorization_iff.mpr hf @[simp] theorem isUniformInducing_rangeFactorization_iff {f : α → β} : IsUniformInducing (rangeFactorization f) ↔ IsUniformInducing f := (isUniformInducing_val (range f)).isUniformInducing_comp_iff.symm theorem IsUniformInducing.rangeFactorization {f : α → β} (hf : IsUniformInducing f) : IsUniformInducing (rangeFactorization f) := isUniformInducing_rangeFactorization_iff.2 hf namespace Dense variable {s : Set α} {f : s → β} theorem extend_exists [CompleteSpace β] (hs : Dense s) (hf : UniformContinuous f) (a : α) : ∃ b, Tendsto f (comap (↑) (𝓝 a)) (𝓝 b) := uniformly_extend_exists (isUniformInducing_val s) hs.denseRange_val hf a theorem extend_spec [CompleteSpace β] (hs : Dense s) (hf : UniformContinuous f) (a : α) : Tendsto f (comap (↑) (𝓝 a)) (𝓝 (hs.extend f a)) := uniformly_extend_spec (isUniformInducing_val s) hs.denseRange_val hf a theorem uniformContinuous_extend [CompleteSpace β] (hs : Dense s) (hf : UniformContinuous f) : UniformContinuous (hs.extend f) := uniformContinuous_uniformly_extend (isUniformInducing_val s) hs.denseRange_val hf variable [T0Space β] theorem extend_of_ind (hs : Dense s) (hf : UniformContinuous f) (x : s) : hs.extend f x = f x := IsDenseInducing.extend_eq_at _ hf.continuous.continuousAt end Dense lemma IsDenseInducing.isUniformInducing_extend {γ : Type*} [UniformSpace γ] [CompleteSpace β] [CompleteSpace γ] {i : α → β} {f : α → γ} (hid : IsDenseInducing i) (hi : IsUniformInducing i) (h : IsUniformInducing f) : IsUniformInducing (hid.extend f) := by let sf := SeparationQuotient.mk ∘ f have : CompleteSpace (closure (range sf)) := isClosed_closure.isComplete.completeSpace_coe let ff : α → closure (range sf) := inclusion subset_closure ∘ rangeFactorization sf have hgu : IsUniformInducing ff := (isUniformEmbedding_set_inclusion subset_closure).isUniformInducing.comp (SeparationQuotient.isUniformInducing_mk.comp h).rangeFactorization have hgd : DenseRange ff := ((denseRange_inclusion_iff subset_closure).2 subset_rfl).comp rangeFactorization_surjective.denseRange (continuous_inclusion subset_closure) have hg : IsDenseInducing ff := hgu.isDenseInducing hgd let fwd := hid.extend ff have hfwd : UniformContinuous fwd := uniformContinuous_uniformly_extend hi hid.dense hgu.uniformContinuous have hg' : UniformContinuous (hg.extend i) := uniformContinuous_uniformly_extend hgu hgd hi.uniformContinuous have key : SeparationQuotient.mk ∘ hg.extend i ∘ fwd = SeparationQuotient.mk := by ext x induction x using isClosed_property hid.dense · exact isClosed_eq (SeparationQuotient.continuous_mk.comp (hg'.comp hfwd).continuous) SeparationQuotient.continuous_mk · simpa [fwd, hid.extend_eq hgu.uniformContinuous.continuous] using hg.inseparable_extend hi.uniformContinuous.continuous.continuousAt have hfu : IsUniformInducing fwd := by refine IsUniformInducing.of_comp hfwd (SeparationQuotient.uniformContinuous_mk.comp hg') ?_ rw [Function.comp_assoc, key] exact SeparationQuotient.isUniformInducing_mk have hrr : range (SeparationQuotient.mk ∘ hid.extend f) ⊆ closure (range (SeparationQuotient.mk ∘ f)) := by refine ((SeparationQuotient.continuous_mk.comp (uniformContinuous_uniformly_extend hi hid.dense h.uniformContinuous).continuous).range_subset_closure_image_dense hid.dense).trans (closure_mono (subset_of_eq ?_)) rw [← range_comp] apply congrArg range funext x simpa using (hid.inseparable_extend h.uniformContinuous.continuous.continuousAt) suffices Subtype.val ∘ fwd = SeparationQuotient.mk ∘ hid.extend f by rw [← SeparationQuotient.isUniformInducing_mk.isUniformInducing_comp_iff, ← this] exact (isUniformInducing_val _).comp hfu rw [← coe_comp_rangeFactorization (SeparationQuotient.mk ∘ hid.extend f), ← val_comp_inclusion hrr, Function.comp_assoc, Subtype.val_injective.comp_left.eq_iff] refine hid.extend_unique ?_ ?_ · simp [ff, hid.inseparable_extend h.uniformContinuous.continuous.continuousAt, sf] · exact (continuous_inclusion hrr).comp (SeparationQuotient.continuous_mk.comp (uniformContinuous_uniformly_extend hi hid.dense h.uniformContinuous).continuous).rangeFactorization end DenseExtension
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Separation.lean
import Mathlib.Tactic.ApplyFun import Mathlib.Topology.Separation.Regular import Mathlib.Topology.UniformSpace.Basic /-! # Hausdorff properties of uniform spaces. Separation quotient. Two points of a topological space are called `Inseparable`, if their neighborhoods filter are equal. Equivalently, `Inseparable x y` means that any open set that contains `x` must contain `y` and vice versa. In a uniform space, points `x` and `y` are inseparable if and only if `(x, y)` belongs to all entourages, see `inseparable_iff_ker_uniformity`. A uniform space is a regular topological space, hence separation axioms `T0Space`, `T1Space`, `T2Space`, and `T3Space` are equivalent for uniform spaces, and Lean typeclass search can automatically convert from one assumption to another. We say that a uniform space is *separated*, if it satisfies these axioms. If you need an `Iff` statement (e.g., to rewrite), then see `R1Space.t0Space_iff_t2Space` and `RegularSpace.t0Space_iff_t3Space`. In this file we prove several facts that relate `Inseparable` and `Specializes` to the uniformity filter. Most of them are simple corollaries of `Filter.HasBasis.inseparable_iff_uniformity` for different filter bases of `𝓤 α`. Then we study the Kolmogorov quotient `SeparationQuotient X` of a uniform space. For a general topological space, this quotient is defined as the quotient by `Inseparable` equivalence relation. It is the maximal T₀ quotient of a topological space. In case of a uniform space, we equip this quotient with a `UniformSpace` structure that agrees with the quotient topology. We also prove that the quotient map induces uniformity on the original space. Finally, we turn `SeparationQuotient` into a functor (not in terms of `CategoryTheory.Functor` to avoid extra imports) by defining `SeparationQuotient.lift'` and `SeparationQuotient.map` operations. ## Main definitions * `SeparationQuotient.instUniformSpace`: uniform space structure on `SeparationQuotient α`, where `α` is a uniform space; * `SeparationQuotient.lift'`: given a map `f : α → β` from a uniform space to a separated uniform space, lift it to a map `SeparationQuotient α → β`; if the original map is not uniformly continuous, then returns a constant map. * `SeparationQuotient.map`: given a map `f : α → β` between uniform spaces, returns a map `SeparationQuotient α → SeparationQuotient β`. If the original map is not uniformly continuous, then returns a constant map. Otherwise, `SeparationQuotient.map f (SeparationQuotient.mk x) = SeparationQuotient.mk (f x)`. ## Main results * `SeparationQuotient.uniformity_eq`: the uniformity filter on `SeparationQuotient α` is the push forward of the uniformity filter on `α`. * `SeparationQuotient.comap_mk_uniformity`: the quotient map `α → SeparationQuotient α` induces uniform space structure on the original space. * `SeparationQuotient.uniformContinuous_lift'`: factoring a uniformly continuous map through the separation quotient gives a uniformly continuous map. * `SeparationQuotient.uniformContinuous_map`: maps induced between separation quotients are uniformly continuous. ## Implementation notes This file used to contain definitions of `separationRel α` and `UniformSpace.SeparationQuotient α`. These definitions were equal (but not definitionally equal) to `{x : α × α | Inseparable x.1 x.2}` and `SeparationQuotient α`, respectively, and were added to the library before their generalizations to topological spaces. In https://github.com/leanprover-community/mathlib4/pull/10644, we migrated from these definitions to more general `Inseparable` and `SeparationQuotient`. ## TODO Definitions `SeparationQuotient.lift'` and `SeparationQuotient.map` rely on `UniformSpace` structures in the domain and in the codomain. We should generalize them to topological spaces. This generalization will drop `UniformContinuous` assumptions in some lemmas, and add these assumptions in other lemmas, so it was not done in https://github.com/leanprover-community/mathlib4/pull/10644 to keep it reasonably sized. ## Keywords uniform space, separated space, Hausdorff space, separation quotient -/ open Filter Set Function Topology Uniformity UniformSpace noncomputable section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] /-! ### Separated uniform spaces -/ instance (priority := 100) UniformSpace.to_regularSpace : RegularSpace α := .of_hasBasis (fun _ ↦ nhds_basis_uniformity' uniformity_hasBasis_closed) fun a _V hV ↦ isClosed_ball a hV.2 theorem Filter.HasBasis.specializes_iff_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x y : α} : x ⤳ y ↔ ∀ i, p i → (x, y) ∈ s i := (nhds_basis_uniformity h).specializes_iff theorem Filter.HasBasis.inseparable_iff_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x y : α} : Inseparable x y ↔ ∀ i, p i → (x, y) ∈ s i := specializes_iff_inseparable.symm.trans h.specializes_iff_uniformity theorem inseparable_iff_ker_uniformity {x y : α} : Inseparable x y ↔ (x, y) ∈ (𝓤 α).ker := (𝓤 α).basis_sets.inseparable_iff_uniformity protected theorem Inseparable.nhds_le_uniformity {x y : α} (h : Inseparable x y) : 𝓝 (x, y) ≤ 𝓤 α := by rw [h.prod rfl] apply nhds_le_uniformity theorem inseparable_iff_clusterPt_uniformity {x y : α} : Inseparable x y ↔ ClusterPt (x, y) (𝓤 α) := by refine ⟨fun h ↦ .of_nhds_le h.nhds_le_uniformity, fun h ↦ ?_⟩ simp_rw [uniformity_hasBasis_closed.inseparable_iff_uniformity, isClosed_iff_clusterPt] exact fun U ⟨hU, hUc⟩ ↦ hUc _ <| h.mono <| le_principal_iff.2 hU theorem t0Space_iff_uniformity : T0Space α ↔ ∀ x y, (∀ r ∈ 𝓤 α, (x, y) ∈ r) → x = y := by simp only [t0Space_iff_inseparable, inseparable_iff_ker_uniformity, mem_ker] theorem t0Space_iff_uniformity' : T0Space α ↔ Pairwise fun x y ↦ ∃ r ∈ 𝓤 α, (x, y) ∉ r := by simp [t0Space_iff_not_inseparable, inseparable_iff_ker_uniformity] theorem t0Space_iff_ker_uniformity : T0Space α ↔ (𝓤 α).ker = diagonal α := by simp_rw [t0Space_iff_uniformity, subset_antisymm_iff, diagonal_subset_iff, subset_def, Prod.forall, Filter.mem_ker, mem_diagonal_iff, iff_self_and] exact fun _ x s hs ↦ refl_mem_uniformity hs theorem eq_of_uniformity {α : Type*} [UniformSpace α] [T0Space α] {x y : α} (h : ∀ {V}, V ∈ 𝓤 α → (x, y) ∈ V) : x = y := t0Space_iff_uniformity.mp ‹T0Space α› x y @h theorem eq_of_uniformity_basis {α : Type*} [UniformSpace α] [T0Space α] {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (hs : (𝓤 α).HasBasis p s) {x y : α} (h : ∀ {i}, p i → (x, y) ∈ s i) : x = y := (hs.inseparable_iff_uniformity.2 @h).eq theorem eq_of_forall_symmetric {α : Type*} [UniformSpace α] [T0Space α] {x y : α} (h : ∀ {V}, V ∈ 𝓤 α → SetRel.IsSymm V → (x, y) ∈ V) : x = y := eq_of_uniformity_basis hasBasis_symmetric (by simpa) theorem eq_of_clusterPt_uniformity [T0Space α] {x y : α} (h : ClusterPt (x, y) (𝓤 α)) : x = y := (inseparable_iff_clusterPt_uniformity.2 h).eq theorem Filter.Tendsto.inseparable_iff_uniformity {β} {l : Filter β} [NeBot l] {f g : β → α} {a b : α} (ha : Tendsto f l (𝓝 a)) (hb : Tendsto g l (𝓝 b)) : Inseparable a b ↔ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α) := by refine ⟨fun h ↦ (ha.prodMk_nhds hb).mono_right h.nhds_le_uniformity, fun h ↦ ?_⟩ rw [inseparable_iff_clusterPt_uniformity] exact (ClusterPt.of_le_nhds (ha.prodMk_nhds hb)).mono h theorem isClosed_of_spaced_out [T0Space α] {V₀ : Set (α × α)} (V₀_in : V₀ ∈ 𝓤 α) {s : Set α} (hs : s.Pairwise fun x y => (x, y) ∉ V₀) : IsClosed s := by rcases comp_symm_mem_uniformity_sets V₀_in with ⟨V₁, V₁_in, V₁_symm, h_comp⟩ apply isClosed_of_closure_subset intro x hx rw [mem_closure_iff_ball] at hx rcases hx V₁_in with ⟨y, hy, hy'⟩ suffices x = y by rwa [this] apply eq_of_forall_symmetric intro V V_in _ rcases hx (inter_mem V₁_in V_in) with ⟨z, hz, hz'⟩ obtain rfl : z = y := by by_contra hzy exact hs hz' hy' hzy (h_comp <| mem_comp_of_mem_ball (ball_inter_left x _ _ hz) hy) exact ball_inter_right x _ _ hz theorem isClosed_range_of_spaced_out {ι} [T0Space α] {V₀ : Set (α × α)} (V₀_in : V₀ ∈ 𝓤 α) {f : ι → α} (hf : Pairwise fun x y => (f x, f y) ∉ V₀) : IsClosed (range f) := isClosed_of_spaced_out V₀_in <| by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ h exact hf (ne_of_apply_ne f h) /-! ### Separation quotient -/ namespace SeparationQuotient theorem comap_map_mk_uniformity : comap (Prod.map mk mk) (map (Prod.map mk mk) (𝓤 α)) = 𝓤 α := by refine le_antisymm ?_ le_comap_map refine ((((𝓤 α).basis_sets.map _).comap _).le_basis_iff uniformity_hasBasis_open).2 fun U hU ↦ ?_ refine ⟨U, hU.1, fun (x₁, x₂) ⟨(y₁, y₂), hyU, hxy⟩ ↦ ?_⟩ simp only [Prod.map, Prod.ext_iff, mk_eq_mk] at hxy exact ((hxy.1.prod hxy.2).mem_open_iff hU.2).1 hyU instance instUniformSpace : UniformSpace (SeparationQuotient α) where uniformity := map (Prod.map mk mk) (𝓤 α) symm := tendsto_map' <| tendsto_map.comp tendsto_swap_uniformity comp := fun t ht ↦ by rcases comp_open_symm_mem_uniformity_sets ht with ⟨U, hU, hUo, -, hUt⟩ refine mem_of_superset (mem_lift' <| image_mem_map hU) ?_ simp only [subset_def, Prod.forall, SetRel.mem_comp, mem_image, Prod.ext_iff] rintro _ _ ⟨_, ⟨⟨x, y⟩, hxyU, rfl, rfl⟩, ⟨⟨y', z⟩, hyzU, hy, rfl⟩⟩ have : y' ⤳ y := (mk_eq_mk.1 hy).specializes exact @hUt (x, z) ⟨y', this.mem_open (UniformSpace.isOpen_ball _ hUo) hxyU, hyzU⟩ nhds_eq_comap_uniformity := surjective_mk.forall.2 fun x ↦ comap_injective surjective_mk <| by conv_lhs => rw [comap_mk_nhds_mk, nhds_eq_comap_uniformity, ← comap_map_mk_uniformity] simp only [Filter.comap_comap, Function.comp_def, Prod.map_apply] theorem uniformity_eq : 𝓤 (SeparationQuotient α) = (𝓤 α).map (Prod.map mk mk) := rfl theorem uniformContinuous_mk : UniformContinuous (mk : α → SeparationQuotient α) := le_rfl theorem uniformContinuous_dom {f : SeparationQuotient α → β} : UniformContinuous f ↔ UniformContinuous (f ∘ mk) := .rfl theorem uniformContinuous_dom₂ {f : SeparationQuotient α × SeparationQuotient β → γ} : UniformContinuous f ↔ UniformContinuous fun p : α × β ↦ f (mk p.1, mk p.2) := by simp only [UniformContinuous, uniformity_prod_eq_prod, uniformity_eq, prod_map_map_eq, tendsto_map'_iff] rfl theorem uniformContinuous_lift {f : α → β} (h : ∀ a b, Inseparable a b → f a = f b) : UniformContinuous (lift f h) ↔ UniformContinuous f := .rfl theorem uniformContinuous_uncurry_lift₂ {f : α → β → γ} (h : ∀ a c b d, Inseparable a b → Inseparable c d → f a c = f b d) : UniformContinuous (uncurry <| lift₂ f h) ↔ UniformContinuous (uncurry f) := uniformContinuous_dom₂ theorem comap_mk_uniformity : (𝓤 (SeparationQuotient α)).comap (Prod.map mk mk) = 𝓤 α := comap_map_mk_uniformity open Classical in /-- Factoring functions to a separated space through the separation quotient. TODO: unify with `SeparationQuotient.lift`. -/ def lift' [T0Space β] (f : α → β) : SeparationQuotient α → β := if hc : UniformContinuous f then lift f fun _ _ h => (h.map hc.continuous).eq else fun x => f (Nonempty.some ⟨x.out⟩) theorem lift'_mk [T0Space β] {f : α → β} (h : UniformContinuous f) (a : α) : lift' f (mk a) = f a := by rw [lift', dif_pos h, lift_mk] theorem uniformContinuous_lift' [T0Space β] (f : α → β) : UniformContinuous (lift' f) := by by_cases hf : UniformContinuous f · rwa [lift', dif_pos hf, uniformContinuous_lift] · rw [lift', dif_neg hf] exact uniformContinuous_of_const fun a _ => rfl /-- The separation quotient functor acting on functions. -/ def map (f : α → β) : SeparationQuotient α → SeparationQuotient β := lift' (mk ∘ f) theorem map_mk {f : α → β} (h : UniformContinuous f) (a : α) : map f (mk a) = mk (f a) := by rw [map, lift'_mk (uniformContinuous_mk.comp h)]; rfl theorem uniformContinuous_map (f : α → β) : UniformContinuous (map f) := uniformContinuous_lift' _ theorem map_unique {f : α → β} (hf : UniformContinuous f) {g : SeparationQuotient α → SeparationQuotient β} (comm : mk ∘ f = g ∘ mk) : map f = g := by ext ⟨a⟩ calc map f ⟦a⟧ = ⟦f a⟧ := map_mk hf a _ = g ⟦a⟧ := congr_fun comm a @[simp] theorem map_id : map (@id α) = id := map_unique uniformContinuous_id rfl theorem map_comp {f : α → β} {g : β → γ} (hf : UniformContinuous f) (hg : UniformContinuous g) : map g ∘ map f = map (g ∘ f) := (map_unique (hg.comp hf) <| by simp only [Function.comp_def, map_mk, hf, hg]).symm end SeparationQuotient
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/CompareReals.lean
import Mathlib.Topology.Instances.Rat import Mathlib.Topology.UniformSpace.AbsoluteValue import Mathlib.Topology.UniformSpace.Completion /-! # Comparison of Cauchy reals and Bourbaki reals In `Data.Real.Basic` real numbers are defined using the so called Cauchy construction (although it is due to Georg Cantor). More precisely, this construction applies to commutative rings equipped with an absolute value with values in a linear ordered field. On the other hand, in the `UniformSpace` folder, we construct completions of general uniform spaces, which allows to construct the Bourbaki real numbers. In this file we build uniformly continuous bijections from Cauchy reals to Bourbaki reals and back. This is a cross sanity check of both constructions. Of course those two constructions are variations on the completion idea, simply with different level of generality. Comparing with Dedekind cuts or quasi-morphisms would be of a completely different nature. Note that `MetricSpace/cau_seq_filter` also relates the notions of Cauchy sequences in metric spaces and Cauchy filters in general uniform spaces, and `MetricSpace/Completion` makes sure the completion (as a uniform space) of a metric space is a metric space. Historical note: mathlib used to define real numbers in an intermediate way, using completion of uniform spaces but extending multiplication in an ad-hoc way. TODO: * Upgrade this isomorphism to a topological ring isomorphism. * Do the same comparison for p-adic numbers ## Implementation notes The heavy work is done in `Topology/UniformSpace/AbstractCompletion` which provides an abstract characterization of completions of uniform spaces, and isomorphisms between them. The only work left here is to prove the uniform space structure coming from the absolute value on ℚ (with values in ℚ, not referring to ℝ) coincides with the one coming from the metric space structure (which of course does use ℝ). ## References * [N. Bourbaki, *Topologie générale*][bourbaki1966] ## Tags real numbers, completion, uniform spaces -/ open Set Function Filter CauSeq UniformSpace /-- The metric space uniform structure on ℚ (which presupposes the existence of real numbers) agrees with the one coming directly from (abs : ℚ → ℚ). -/ theorem Rat.uniformSpace_eq : (AbsoluteValue.abs : AbsoluteValue ℚ ℚ).uniformSpace = PseudoMetricSpace.toUniformSpace := by ext s rw [(AbsoluteValue.hasBasis_uniformity _).mem_iff, Metric.uniformity_basis_dist_rat.mem_iff] simp only [Rat.dist_eq, AbsoluteValue.abs_apply, ← Rat.cast_sub, ← Rat.cast_abs, Rat.cast_lt, abs_sub_comm] /-- Cauchy reals packaged as a completion of ℚ using the absolute value route. -/ def rationalCauSeqPkg : @AbstractCompletion ℚ <| (@AbsoluteValue.abs ℚ _).uniformSpace := @AbstractCompletion.mk (space := ℝ) (coe := ((↑) : ℚ → ℝ)) (uniformStruct := by infer_instance) (complete := by infer_instance) (separation := by infer_instance) (isUniformInducing := by rw [Rat.uniformSpace_eq] exact Rat.isUniformEmbedding_coe_real.isUniformInducing) (dense := Rat.isDenseEmbedding_coe_real.dense) namespace CompareReals /-- Type wrapper around ℚ to make sure the absolute value uniform space instance is picked up instead of the metric space one. We proved in `Rat.uniformSpace_eq` that they are equal, but they are not definitionaly equal, so it would confuse the type class system (and probably also human readers). -/ def Q := ℚ deriving CommRing, Inhabited instance uniformSpace : UniformSpace Q := (@AbsoluteValue.abs ℚ _).uniformSpace /-- Real numbers constructed as in Bourbaki. -/ def Bourbakiℝ : Type := Completion Q deriving Inhabited instance Bourbaki.uniformSpace : UniformSpace Bourbakiℝ := Completion.uniformSpace Q /-- Bourbaki reals packaged as a completion of Q using the general theory. -/ def bourbakiPkg : AbstractCompletion Q := Completion.cPkg /-- The uniform bijection between Bourbaki and Cauchy reals. -/ noncomputable def compareEquiv : Bourbakiℝ ≃ᵤ ℝ := bourbakiPkg.compareEquiv rationalCauSeqPkg theorem compare_uc : UniformContinuous compareEquiv := bourbakiPkg.uniformContinuous_compareEquiv rationalCauSeqPkg theorem compare_uc_symm : UniformContinuous compareEquiv.symm := bourbakiPkg.uniformContinuous_compareEquiv_symm rationalCauSeqPkg end CompareReals
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Equiv.lean
import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Topology.UniformSpace.Pi /-! # Uniform isomorphisms This file defines uniform isomorphisms between two uniform spaces. They are bijections with both directions uniformly continuous. We denote uniform isomorphisms with the notation `≃ᵤ`. ## Main definitions * `UniformEquiv α β`: The type of uniform isomorphisms from `α` to `β`. This type can be denoted using the following notation: `α ≃ᵤ β`. -/ open Set Filter universe u v variable {α : Type u} {β : Type*} {γ : Type*} {δ : Type*} -- not all spaces are homeomorphic to each other /-- Uniform isomorphism between `α` and `β` -/ structure UniformEquiv (α : Type*) (β : Type*) [UniformSpace α] [UniformSpace β] extends α ≃ β where /-- Uniform continuity of the function -/ uniformContinuous_toFun : UniformContinuous toFun /-- Uniform continuity of the inverse -/ uniformContinuous_invFun : UniformContinuous invFun /-- Uniform isomorphism between `α` and `β` -/ infixl:25 " ≃ᵤ " => UniformEquiv namespace UniformEquiv variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace δ] theorem toEquiv_injective : Function.Injective (toEquiv : α ≃ᵤ β → α ≃ β) | ⟨e, h₁, h₂⟩, ⟨e', h₁', h₂'⟩, h => by simpa only [mk.injEq] instance : EquivLike (α ≃ᵤ β) α β where coe h := h.toEquiv inv h := h.toEquiv.symm left_inv h := h.left_inv right_inv h := h.right_inv coe_injective' _ _ H _ := toEquiv_injective <| DFunLike.ext' H @[simp] theorem uniformEquiv_mk_coe (a : Equiv α β) (b c) : (UniformEquiv.mk a b c : α → β) = a := rfl /-- Inverse of a uniform isomorphism. -/ protected def symm (h : α ≃ᵤ β) : β ≃ᵤ α where uniformContinuous_toFun := h.uniformContinuous_invFun uniformContinuous_invFun := h.uniformContinuous_toFun toEquiv := h.toEquiv.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (h : α ≃ᵤ β) : α → β := h /-- See Note [custom simps projection] -/ def Simps.symm_apply (h : α ≃ᵤ β) : β → α := h.symm initialize_simps_projections UniformEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem coe_toEquiv (h : α ≃ᵤ β) : ⇑h.toEquiv = h := rfl @[simp] theorem coe_symm_toEquiv (h : α ≃ᵤ β) : ⇑h.toEquiv.symm = h.symm := rfl @[ext] theorem ext {h h' : α ≃ᵤ β} (H : ∀ x, h x = h' x) : h = h' := toEquiv_injective <| Equiv.ext H /-- Identity map as a uniform isomorphism. -/ @[simps! -fullyApplied apply] protected def refl (α : Type*) [UniformSpace α] : α ≃ᵤ α where uniformContinuous_toFun := uniformContinuous_id uniformContinuous_invFun := uniformContinuous_id toEquiv := Equiv.refl α /-- Composition of two uniform isomorphisms. -/ protected def trans (h₁ : α ≃ᵤ β) (h₂ : β ≃ᵤ γ) : α ≃ᵤ γ where uniformContinuous_toFun := h₂.uniformContinuous_toFun.comp h₁.uniformContinuous_toFun uniformContinuous_invFun := h₁.uniformContinuous_invFun.comp h₂.uniformContinuous_invFun toEquiv := Equiv.trans h₁.toEquiv h₂.toEquiv @[simp] theorem trans_apply (h₁ : α ≃ᵤ β) (h₂ : β ≃ᵤ γ) (a : α) : h₁.trans h₂ a = h₂ (h₁ a) := rfl @[simp] theorem uniformEquiv_mk_coe_symm (a : Equiv α β) (b c) : ((UniformEquiv.mk a b c).symm : β → α) = a.symm := rfl @[simp] theorem refl_symm : (UniformEquiv.refl α).symm = UniformEquiv.refl α := rfl protected theorem uniformContinuous (h : α ≃ᵤ β) : UniformContinuous h := h.uniformContinuous_toFun @[continuity] protected theorem continuous (h : α ≃ᵤ β) : Continuous h := h.uniformContinuous.continuous protected theorem uniformContinuous_symm (h : α ≃ᵤ β) : UniformContinuous h.symm := h.uniformContinuous_invFun -- otherwise `by continuity` can't prove continuity of `h.to_equiv.symm` @[continuity] protected theorem continuous_symm (h : α ≃ᵤ β) : Continuous h.symm := h.uniformContinuous_symm.continuous /-- A uniform isomorphism as a homeomorphism. -/ protected def toHomeomorph (e : α ≃ᵤ β) : α ≃ₜ β := { e.toEquiv with continuous_toFun := e.continuous continuous_invFun := e.continuous_symm } lemma toHomeomorph_apply (e : α ≃ᵤ β) : (e.toHomeomorph : α → β) = e := rfl lemma toHomeomorph_symm_apply (e : α ≃ᵤ β) : (e.toHomeomorph.symm : β → α) = e.symm := rfl @[simp] theorem apply_symm_apply (h : α ≃ᵤ β) (x : β) : h (h.symm x) = x := h.toEquiv.apply_symm_apply x @[simp] theorem symm_apply_apply (h : α ≃ᵤ β) (x : α) : h.symm (h x) = x := h.toEquiv.symm_apply_apply x protected theorem bijective (h : α ≃ᵤ β) : Function.Bijective h := h.toEquiv.bijective protected theorem injective (h : α ≃ᵤ β) : Function.Injective h := h.toEquiv.injective protected theorem surjective (h : α ≃ᵤ β) : Function.Surjective h := h.toEquiv.surjective /-- Change the uniform equiv `f` to make the inverse function definitionally equal to `g`. -/ def changeInv (f : α ≃ᵤ β) (g : β → α) (hg : Function.RightInverse g f) : α ≃ᵤ β := have : g = f.symm := funext fun x => calc g x = f.symm (f (g x)) := (f.left_inv (g x)).symm _ = f.symm x := by rw [hg x] { toFun := f invFun := g left_inv := by convert f.left_inv right_inv := by convert f.right_inv using 1 uniformContinuous_toFun := f.uniformContinuous uniformContinuous_invFun := by convert f.symm.uniformContinuous } @[simp] theorem symm_comp_self (h : α ≃ᵤ β) : (h.symm : β → α) ∘ h = id := funext h.symm_apply_apply @[simp] theorem self_comp_symm (h : α ≃ᵤ β) : (h : α → β) ∘ h.symm = id := funext h.apply_symm_apply theorem range_coe (h : α ≃ᵤ β) : range h = univ := by simp theorem image_symm (h : α ≃ᵤ β) : image h.symm = preimage h := funext h.symm.toEquiv.image_eq_preimage_symm theorem preimage_symm (h : α ≃ᵤ β) : preimage h.symm = image h := (funext h.toEquiv.image_eq_preimage_symm).symm @[simp] theorem image_preimage (h : α ≃ᵤ β) (s : Set β) : h '' (h ⁻¹' s) = s := h.toEquiv.image_preimage s @[simp] theorem preimage_image (h : α ≃ᵤ β) (s : Set α) : h ⁻¹' (h '' s) = s := h.toEquiv.preimage_image s theorem isUniformInducing (h : α ≃ᵤ β) : IsUniformInducing h := IsUniformInducing.of_comp h.uniformContinuous h.symm.uniformContinuous <| by simp only [symm_comp_self, IsUniformInducing.id] theorem comap_eq (h : α ≃ᵤ β) : UniformSpace.comap h ‹_› = ‹_› := h.isUniformInducing.comap_uniformSpace lemma isUniformEmbedding (h : α ≃ᵤ β) : IsUniformEmbedding h := ⟨h.isUniformInducing, h.injective⟩ theorem completeSpace_iff (h : α ≃ᵤ β) : CompleteSpace α ↔ CompleteSpace β := completeSpace_congr h.isUniformEmbedding /-- Uniform equiv given a uniform embedding. -/ noncomputable def ofIsUniformEmbedding (f : α → β) (hf : IsUniformEmbedding f) : α ≃ᵤ Set.range f where uniformContinuous_toFun := hf.isUniformInducing.uniformContinuous.subtype_mk _ uniformContinuous_invFun := by rw [hf.isUniformInducing.uniformContinuous_iff, Equiv.invFun_as_coe, Equiv.self_comp_ofInjective_symm] exact uniformContinuous_subtype_val toEquiv := Equiv.ofInjective f hf.injective /-- If two sets are equal, then they are uniformly equivalent. -/ def setCongr {s t : Set α} (h : s = t) : s ≃ᵤ t where uniformContinuous_toFun := uniformContinuous_subtype_val.subtype_mk _ uniformContinuous_invFun := uniformContinuous_subtype_val.subtype_mk _ toEquiv := Equiv.setCongr h /-- Product of two uniform isomorphisms. -/ def prodCongr (h₁ : α ≃ᵤ β) (h₂ : γ ≃ᵤ δ) : α × γ ≃ᵤ β × δ where uniformContinuous_toFun := (h₁.uniformContinuous.comp uniformContinuous_fst).prodMk (h₂.uniformContinuous.comp uniformContinuous_snd) uniformContinuous_invFun := (h₁.symm.uniformContinuous.comp uniformContinuous_fst).prodMk (h₂.symm.uniformContinuous.comp uniformContinuous_snd) toEquiv := h₁.toEquiv.prodCongr h₂.toEquiv @[simp] theorem prodCongr_symm (h₁ : α ≃ᵤ β) (h₂ : γ ≃ᵤ δ) : (h₁.prodCongr h₂).symm = h₁.symm.prodCongr h₂.symm := rfl @[simp] theorem coe_prodCongr (h₁ : α ≃ᵤ β) (h₂ : γ ≃ᵤ δ) : ⇑(h₁.prodCongr h₂) = Prod.map h₁ h₂ := rfl section variable (α β γ) /-- `α × β` is uniformly isomorphic to `β × α`. -/ def prodComm : α × β ≃ᵤ β × α where uniformContinuous_toFun := uniformContinuous_snd.prodMk uniformContinuous_fst uniformContinuous_invFun := uniformContinuous_snd.prodMk uniformContinuous_fst toEquiv := Equiv.prodComm α β @[simp] theorem prodComm_symm : (prodComm α β).symm = prodComm β α := rfl @[simp] theorem coe_prodComm : ⇑(prodComm α β) = Prod.swap := rfl /-- `(α × β) × γ` is uniformly isomorphic to `α × (β × γ)`. -/ def prodAssoc : (α × β) × γ ≃ᵤ α × β × γ where uniformContinuous_toFun := (uniformContinuous_fst.comp uniformContinuous_fst).prodMk ((uniformContinuous_snd.comp uniformContinuous_fst).prodMk uniformContinuous_snd) uniformContinuous_invFun := (uniformContinuous_fst.prodMk (uniformContinuous_fst.comp uniformContinuous_snd)).prodMk (uniformContinuous_snd.comp uniformContinuous_snd) toEquiv := Equiv.prodAssoc α β γ /-- `α × {*}` is uniformly isomorphic to `α`. -/ @[simps! -fullyApplied apply] def prodPunit : α × PUnit ≃ᵤ α where toEquiv := Equiv.prodPUnit α uniformContinuous_toFun := uniformContinuous_fst uniformContinuous_invFun := uniformContinuous_id.prodMk uniformContinuous_const /-- `{*} × α` is uniformly isomorphic to `α`. -/ def punitProd : PUnit × α ≃ᵤ α := (prodComm _ _).trans (prodPunit _) @[simp] theorem coe_punitProd : ⇑(punitProd α) = Prod.snd := rfl /-- `Equiv.piCongrLeft` as a uniform isomorphism: this is the natural isomorphism `Π i, β (e i) ≃ᵤ Π j, β j` obtained from a bijection `ι ≃ ι'`. -/ @[simps toEquiv, simps! -isSimp apply] def piCongrLeft {ι ι' : Type*} {β : ι' → Type*} [∀ j, UniformSpace (β j)] (e : ι ≃ ι') : (∀ i, β (e i)) ≃ᵤ ∀ j, β j where uniformContinuous_toFun := uniformContinuous_pi.mpr <| e.forall_congr_right.mp fun i ↦ by simpa only [Equiv.toFun_as_coe, Equiv.piCongrLeft_apply_apply] using Pi.uniformContinuous_proj _ i uniformContinuous_invFun := Pi.uniformContinuous_precomp' _ e toEquiv := Equiv.piCongrLeft _ e @[simp] lemma piCongrLeft_refl {ι : Type*} {X : ι → Type*} [∀ i, UniformSpace (X i)] : piCongrLeft (.refl ι) = .refl (∀ i, X i) := rfl @[simp] lemma piCongrLeft_symm_apply {ι ι' : Type*} {X : ι' → Type*} [∀ j, UniformSpace (X j)] (e : ι ≃ ι') : ⇑(piCongrLeft (β := X) e).symm = (· <| e ·) := rfl @[simp] lemma piCongrLeft_apply_apply {ι ι' : Type*} {X : ι' → Type*} [∀ j, UniformSpace (X j)] (e : ι ≃ ι') (x : ∀ i, X (e i)) i : piCongrLeft e x (e i) = x i := Equiv.piCongrLeft_apply_apply .. /-- `Equiv.piCongrRight` as a uniform isomorphism: this is the natural isomorphism `Π i, β₁ i ≃ᵤ Π j, β₂ i` obtained from uniform isomorphisms `β₁ i ≃ᵤ β₂ i` for each `i`. -/ @[simps! apply toEquiv] def piCongrRight {ι : Type*} {β₁ β₂ : ι → Type*} [∀ i, UniformSpace (β₁ i)] [∀ i, UniformSpace (β₂ i)] (F : ∀ i, β₁ i ≃ᵤ β₂ i) : (∀ i, β₁ i) ≃ᵤ ∀ i, β₂ i where uniformContinuous_toFun := Pi.uniformContinuous_postcomp' _ fun i ↦ (F i).uniformContinuous uniformContinuous_invFun := Pi.uniformContinuous_postcomp' _ fun i ↦ (F i).symm.uniformContinuous toEquiv := Equiv.piCongrRight fun i => (F i).toEquiv @[simp] theorem piCongrRight_symm {ι : Type*} {β₁ β₂ : ι → Type*} [∀ i, UniformSpace (β₁ i)] [∀ i, UniformSpace (β₂ i)] (F : ∀ i, β₁ i ≃ᵤ β₂ i) : (piCongrRight F).symm = piCongrRight fun i => (F i).symm := rfl @[simp] theorem piCongrRight_refl {ι : Type*} {X : ι → Type*} [∀ i, UniformSpace (X i)] : piCongrRight (fun i ↦ .refl (X i)) = .refl (∀ i, X i) := rfl /-- `Equiv.piCongr` as a uniform isomorphism: this is the natural isomorphism `Π i₁, β₁ i ≃ᵤ Π i₂, β₂ i₂` obtained from a bijection `ι₁ ≃ ι₂` and isomorphisms `β₁ i₁ ≃ᵤ β₂ (e i₁)` for each `i₁ : ι₁`. -/ @[simps! apply toEquiv] def piCongr {ι₁ ι₂ : Type*} {β₁ : ι₁ → Type*} {β₂ : ι₂ → Type*} [∀ i₁, UniformSpace (β₁ i₁)] [∀ i₂, UniformSpace (β₂ i₂)] (e : ι₁ ≃ ι₂) (F : ∀ i₁, β₁ i₁ ≃ᵤ β₂ (e i₁)) : (∀ i₁, β₁ i₁) ≃ᵤ ∀ i₂, β₂ i₂ := (UniformEquiv.piCongrRight F).trans (UniformEquiv.piCongrLeft e) /-- Uniform equivalence between `ULift α` and `α`. -/ def ulift : ULift.{v, u} α ≃ᵤ α := { Equiv.ulift with uniformContinuous_toFun := uniformContinuous_comap uniformContinuous_invFun := by have hf : IsUniformInducing (@Equiv.ulift.{v, u} α).toFun := ⟨rfl⟩ simp_rw [hf.uniformContinuous_iff] exact uniformContinuous_id } end /-- If `ι` has a unique element, then `ι → α` is uniformly isomorphic to `α`. -/ @[simps! -fullyApplied] def funUnique (ι α : Type*) [Unique ι] [UniformSpace α] : (ι → α) ≃ᵤ α where toEquiv := Equiv.funUnique ι α uniformContinuous_toFun := Pi.uniformContinuous_proj _ _ uniformContinuous_invFun := uniformContinuous_pi.mpr fun _ => uniformContinuous_id /-- Uniform isomorphism between dependent functions `Π i : Fin 2, α i` and `α 0 × α 1`. -/ @[simps! -fullyApplied] def piFinTwo (α : Fin 2 → Type u) [∀ i, UniformSpace (α i)] : (∀ i, α i) ≃ᵤ α 0 × α 1 where toEquiv := piFinTwoEquiv α uniformContinuous_toFun := (Pi.uniformContinuous_proj _ 0).prodMk (Pi.uniformContinuous_proj _ 1) uniformContinuous_invFun := uniformContinuous_pi.mpr <| Fin.forall_fin_two.2 ⟨uniformContinuous_fst, uniformContinuous_snd⟩ /-- Uniform isomorphism between `α² = Fin 2 → α` and `α × α`. -/ @[simps! -fullyApplied] def finTwoArrow (α : Type*) [UniformSpace α] : (Fin 2 → α) ≃ᵤ α × α := { piFinTwo fun _ => α with toEquiv := finTwoArrowEquiv α } /-- A subset of a uniform space is uniformly isomorphic to its image under a uniform isomorphism. -/ def image (e : α ≃ᵤ β) (s : Set α) : s ≃ᵤ e '' s where uniformContinuous_toFun := (e.uniformContinuous.comp uniformContinuous_subtype_val).subtype_mk _ uniformContinuous_invFun := (e.symm.uniformContinuous.comp uniformContinuous_subtype_val).subtype_mk _ toEquiv := e.toEquiv.image s /-- A uniform isomorphism `e : α ≃ᵤ β` lifts to subtypes `{ a : α // p a } ≃ᵤ { b : β // q b }` provided `p = q ∘ e`. -/ @[simps!] def subtype {p : α → Prop} {q : β → Prop} (e : α ≃ᵤ β) (h : ∀ a, p a ↔ q (e a)) : { a : α // p a } ≃ᵤ { b : β // q b } where uniformContinuous_toFun := by simpa [Equiv.coe_subtypeEquiv_eq_map] using e.uniformContinuous.subtype_map _ uniformContinuous_invFun := by simpa [Equiv.coe_subtypeEquiv_eq_map] using e.symm.uniformContinuous.subtype_map _ __ := e.subtypeEquiv h end UniformEquiv /-- A uniform inducing equiv between uniform spaces is a uniform isomorphism. -/ def Equiv.toUniformEquivOfIsUniformInducing [UniformSpace α] [UniformSpace β] (f : α ≃ β) (hf : IsUniformInducing f) : α ≃ᵤ β := { f with uniformContinuous_toFun := hf.uniformContinuous uniformContinuous_invFun := hf.uniformContinuous_iff.2 <| by simpa using uniformContinuous_id }
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Dini.lean
import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.Topology.ContinuousMap.Ordered import Mathlib.Topology.UniformSpace.CompactConvergence /-! # Dini's Theorem This file proves Dini's theorem, which states that if `F n` is a monotone increasing sequence of continuous real-valued functions on a compact set `s` converging pointwise to a continuous function `f`, then `F n` converges uniformly to `f`. We generalize the codomain from `ℝ` to a normed lattice additive commutative group `G`. This theorem is true in a different generality as well: when `G` is a linearly ordered topological group with the order topology. This weakens the norm assumption, in exchange for strengthening to a linear order. This separate generality is not included in this file, but that generality was included in initial drafts of the original https://github.com/leanprover-community/mathlib4/pull/19068 and can be recovered if necessary. The key idea of the proof is to use a particular basis of `𝓝 0` which consists of open sets that are somehow monotone in the sense that if `s` is in the basis, and `0 ≤ x ≤ y`, then `y ∈ s → x ∈ s`, and so the proof would work on any topological ordered group possessing such a basis. In the case of a linearly ordered topological group with the order topology, this basis is `nhds_basis_Ioo`. In the case of a normed lattice additive commutative group, this basis is `nhds_basis_ball`, and the fact that this basis satisfies the monotonicity criterion corresponds to `HasSolidNorm`. -/ open Filter Topology variable {ι α G : Type*} [Preorder ι] [TopologicalSpace α] [NormedAddCommGroup G] [Lattice G] [HasSolidNorm G] [IsOrderedAddMonoid G] section Unbundled open Metric variable {F : ι → α → G} {f : α → G} namespace Monotone /-- **Dini's theorem**: if `F n` is a monotone increasing collection of continuous functions converging pointwise to a continuous function `f`, then `F n` converges locally uniformly to `f`. -/ lemma tendstoLocallyUniformly_of_forall_tendsto (hF_cont : ∀ i, Continuous (F i)) (hF_mono : Monotone F) (hf : Continuous f) (h_tendsto : ∀ x, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoLocallyUniformly F f atTop := by refine (atTop : Filter ι).eq_or_neBot.elim (fun h ↦ ?eq_bot) (fun _ ↦ ?_) case eq_bot => simp [h, tendstoLocallyUniformly_iff_forall_tendsto] have F_le_f (x : α) (n : ι) : F n x ≤ f x := by refine ge_of_tendsto (h_tendsto x) ?_ filter_upwards [Ici_mem_atTop n] with m hnm exact hF_mono hnm x simp_rw [Metric.tendstoLocallyUniformly_iff, dist_eq_norm'] intro ε ε_pos x simp_rw +singlePass [tendsto_iff_norm_sub_tendsto_zero] at h_tendsto obtain ⟨n, hn⟩ := (h_tendsto x).eventually (eventually_lt_nhds ε_pos) |>.exists refine ⟨{y | ‖F n y - f y‖ < ε}, ⟨isOpen_lt (by fun_prop) continuous_const |>.mem_nhds hn, ?_⟩⟩ filter_upwards [eventually_ge_atTop n] with m hnm z hz refine norm_le_norm_of_abs_le_abs ?_ |>.trans_lt hz simp only [abs_of_nonpos (sub_nonpos_of_le (F_le_f _ _)), neg_sub, sub_le_sub_iff_left] exact hF_mono hnm z /-- **Dini's theorem**: if `F n` is a monotone increasing collection of continuous functions on a set `s` converging pointwise to a continuous function `f`, then `F n` converges locally uniformly to `f`. -/ lemma tendstoLocallyUniformlyOn_of_forall_tendsto {s : Set α} (hF_cont : ∀ i, ContinuousOn (F i) s) (hF_mono : ∀ x ∈ s, Monotone (F · x)) (hf : ContinuousOn f s) (h_tendsto : ∀ x ∈ s, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoLocallyUniformlyOn F f atTop s := by rw [tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe] exact tendstoLocallyUniformly_of_forall_tendsto (hF_cont · |>.restrict) (fun _ _ h x ↦ hF_mono _ x.2 h) hf.restrict (fun x ↦ h_tendsto x x.2) /-- **Dini's theorem**: if `F n` is a monotone increasing collection of continuous functions on a compact space converging pointwise to a continuous function `f`, then `F n` converges uniformly to `f`. -/ lemma tendstoUniformly_of_forall_tendsto [CompactSpace α] (hF_cont : ∀ i, Continuous (F i)) (hF_mono : Monotone F) (hf : Continuous f) (h_tendsto : ∀ x, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoUniformly F f atTop := tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace.mp <| tendstoLocallyUniformly_of_forall_tendsto hF_cont hF_mono hf h_tendsto /-- **Dini's theorem**: if `F n` is a monotone increasing collection of continuous functions on a compact set `s` converging pointwise to a continuous function `f`, then `F n` converges uniformly to `f`. -/ lemma tendstoUniformlyOn_of_forall_tendsto {s : Set α} (hs : IsCompact s) (hF_cont : ∀ i, ContinuousOn (F i) s) (hF_mono : ∀ x ∈ s, Monotone (F · x)) (hf : ContinuousOn f s) (h_tendsto : ∀ x ∈ s, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoUniformlyOn F f atTop s := tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hs |>.mp <| tendstoLocallyUniformlyOn_of_forall_tendsto hF_cont hF_mono hf h_tendsto end Monotone namespace Antitone /-- **Dini's theorem**: if `F n` is a monotone decreasing collection of continuous functions on a converging pointwise to a continuous function `f`, then `F n` converges locally uniformly to `f`. -/ lemma tendstoLocallyUniformly_of_forall_tendsto (hF_cont : ∀ i, Continuous (F i)) (hF_anti : Antitone F) (hf : Continuous f) (h_tendsto : ∀ x, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoLocallyUniformly F f atTop := Monotone.tendstoLocallyUniformly_of_forall_tendsto (G := Gᵒᵈ) hF_cont hF_anti hf h_tendsto /-- **Dini's theorem**: if `F n` is a monotone decreasing collection of continuous functions on a set `s` converging pointwise to a continuous function `f`, then `F n` converges locally uniformly to `f`. -/ lemma tendstoLocallyUniformlyOn_of_forall_tendsto {s : Set α} (hF_cont : ∀ i, ContinuousOn (F i) s) (hF_anti : ∀ x ∈ s, Antitone (F · x)) (hf : ContinuousOn f s) (h_tendsto : ∀ x ∈ s, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoLocallyUniformlyOn F f atTop s := Monotone.tendstoLocallyUniformlyOn_of_forall_tendsto (G := Gᵒᵈ) hF_cont hF_anti hf h_tendsto /-- **Dini's theorem**: if `F n` is a monotone decreasing collection of continuous functions on a compact space converging pointwise to a continuous function `f`, then `F n` converges uniformly to `f`. -/ lemma tendstoUniformly_of_forall_tendsto [CompactSpace α] (hF_cont : ∀ i, Continuous (F i)) (hF_anti : Antitone F) (hf : Continuous f) (h_tendsto : ∀ x, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoUniformly F f atTop := Monotone.tendstoUniformly_of_forall_tendsto (G := Gᵒᵈ) hF_cont hF_anti hf h_tendsto /-- **Dini's theorem**: if `F n` is a monotone decreasing collection of continuous functions on a compact set `s` converging pointwise to a continuous `f`, then `F n` converges uniformly to `f`. -/ lemma tendstoUniformlyOn_of_forall_tendsto {s : Set α} (hs : IsCompact s) (hF_cont : ∀ i, ContinuousOn (F i) s) (hF_anti : ∀ x ∈ s, Antitone (F · x)) (hf : ContinuousOn f s) (h_tendsto : ∀ x ∈ s, Tendsto (F · x) atTop (𝓝 (f x))) : TendstoUniformlyOn F f atTop s := Monotone.tendstoUniformlyOn_of_forall_tendsto (G := Gᵒᵈ) hs hF_cont hF_anti hf h_tendsto end Antitone end Unbundled namespace ContinuousMap variable {F : ι → C(α, G)} {f : C(α, G)} /-- **Dini's theorem**: if `F n` is a monotone increasing collection of continuous functions converging pointwise to a continuous function `f`, then `F n` converges to `f` in the compact-open topology. -/ lemma tendsto_of_monotone_of_pointwise (hF_mono : Monotone F) (h_tendsto : ∀ x, Tendsto (F · x) atTop (𝓝 (f x))) : Tendsto F atTop (𝓝 f) := tendsto_of_tendstoLocallyUniformly <| hF_mono.tendstoLocallyUniformly_of_forall_tendsto (F · |>.continuous) f.continuous h_tendsto /-- **Dini's theorem**: if `F n` is a monotone decreasing collection of continuous functions converging pointwise to a continuous function `f`, then `F n` converges to `f` in the compact-open topology. -/ lemma tendsto_of_antitone_of_pointwise (hF_anti : Antitone F) (h_tendsto : ∀ x, Tendsto (F · x) atTop (𝓝 (f x))) : Tendsto F atTop (𝓝 f) := tendsto_of_monotone_of_pointwise (G := Gᵒᵈ) hF_anti h_tendsto end ContinuousMap
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/HeineCantor.lean
import Mathlib.Topology.Algebra.Support import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.UniformSpace.Equicontinuity /-! # Compact separated uniform spaces ## Main statement * **Heine-Cantor** theorem: continuous functions on compact uniform spaces with values in uniform spaces are automatically uniformly continuous. There are several variations, the main one is `CompactSpace.uniformContinuous_of_continuous`. ## Tags uniform space, uniform continuity, compact space -/ open Uniformity Topology Filter UniformSpace Set variable {α β γ : Type*} [UniformSpace α] [UniformSpace β] /-! ### Heine-Cantor theorem -/ /-- Heine-Cantor: a continuous function on a compact uniform space is uniformly continuous. -/ theorem CompactSpace.uniformContinuous_of_continuous [CompactSpace α] {f : α → β} (h : Continuous f) : UniformContinuous f := calc map (Prod.map f f) (𝓤 α) = map (Prod.map f f) (𝓝ˢ (diagonal α)) := by rw [nhdsSet_diagonal_eq_uniformity] _ ≤ 𝓝ˢ (diagonal β) := (h.prodMap h).tendsto_nhdsSet mapsTo_prodMap_diagonal _ ≤ 𝓤 β := nhdsSet_diagonal_le_uniformity /-- Heine-Cantor: a continuous function on a compact set of a uniform space is uniformly continuous. -/ theorem IsCompact.uniformContinuousOn_of_continuous {s : Set α} {f : α → β} (hs : IsCompact s) (hf : ContinuousOn f s) : UniformContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] rw [isCompact_iff_compactSpace] at hs rw [continuousOn_iff_continuous_restrict] at hf exact CompactSpace.uniformContinuous_of_continuous hf /-- If `s` is compact and `f` is continuous at all points of `s`, then `f` is "uniformly continuous at the set `s`", i.e. `f x` is close to `f y` whenever `x ∈ s` and `y` is close to `x` (even if `y` is not itself in `s`, so this is a stronger assertion than `UniformContinuousOn s`). -/ theorem IsCompact.uniformContinuousAt_of_continuousAt {r : Set (β × β)} {s : Set α} (hs : IsCompact s) (f : α → β) (hf : ∀ a ∈ s, ContinuousAt f a) (hr : r ∈ 𝓤 β) : { x : α × α | x.1 ∈ s → (f x.1, f x.2) ∈ r } ∈ 𝓤 α := by obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr choose U hU T hT hb using fun a ha => exists_mem_nhds_ball_subset_of_mem_nhds ((hf a ha).preimage_mem_nhds <| mem_nhds_left _ ht) obtain ⟨fs, hsU⟩ := hs.elim_nhds_subcover' U hU apply mem_of_superset ((biInter_finset_mem fs).2 fun a _ => hT a a.2) rintro ⟨a₁, a₂⟩ h h₁ obtain ⟨a, ha, haU⟩ := Set.mem_iUnion₂.1 (hsU h₁) apply htr refine ⟨f a, SetRel.symm t <| hb _ _ _ haU ?_, hb _ _ _ haU ?_⟩ exacts [mem_ball_self _ (hT a a.2), mem_iInter₂.1 h a ha] theorem Continuous.uniformContinuous_of_tendsto_cocompact {f : α → β} {x : β} (h_cont : Continuous f) (hx : Tendsto f (cocompact α) (𝓝 x)) : UniformContinuous f := uniformContinuous_def.2 fun r hr => by obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr obtain ⟨s, hs, hst⟩ := mem_cocompact.1 (hx <| mem_nhds_left _ ht) apply mem_of_superset (symmetrize_mem_uniformity <| (hs.uniformContinuousAt_of_continuousAt f fun _ _ => h_cont.continuousAt) <| symmetrize_mem_uniformity hr) rintro ⟨b₁, b₂⟩ h by_cases h₁ : b₁ ∈ s; · exact (h.1 h₁).1 by_cases h₂ : b₂ ∈ s; · exact (h.2 h₂).2 apply htr exact ⟨x, SetRel.symm t <| hst h₁, hst h₂⟩ @[to_additive] theorem HasCompactMulSupport.uniformContinuous_of_continuous {f : α → β} [One β] (h1 : HasCompactMulSupport f) (h2 : Continuous f) : UniformContinuous f := h2.uniformContinuous_of_tendsto_cocompact h1.is_one_at_infty /-- A family of functions `α → β → γ` tends uniformly to its value at `x` if `α` is locally compact, `β` is compact and `f` is continuous on `U × (univ : Set β)` for some neighborhood `U` of `x`. -/ theorem ContinuousOn.tendstoUniformly [LocallyCompactSpace α] [CompactSpace β] [UniformSpace γ] {f : α → β → γ} {x : α} {U : Set α} (hxU : U ∈ 𝓝 x) (h : ContinuousOn ↿f (U ×ˢ univ)) : TendstoUniformly f (f x) (𝓝 x) := by rcases LocallyCompactSpace.local_compact_nhds _ _ hxU with ⟨K, hxK, hKU, hK⟩ have : UniformContinuousOn ↿f (K ×ˢ univ) := IsCompact.uniformContinuousOn_of_continuous (hK.prod isCompact_univ) (h.mono <| prod_mono hKU Subset.rfl) exact this.tendstoUniformly hxK /-- A continuous family of functions `α → β → γ` tends uniformly to its value at `x` if `α` is weakly locally compact and `β` is compact. -/ theorem Continuous.tendstoUniformly [WeaklyLocallyCompactSpace α] [CompactSpace β] [UniformSpace γ] (f : α → β → γ) (h : Continuous ↿f) (x : α) : TendstoUniformly f (f x) (𝓝 x) := let ⟨K, hK, hxK⟩ := exists_compact_mem_nhds x have : UniformContinuousOn ↿f (K ×ˢ univ) := IsCompact.uniformContinuousOn_of_continuous (hK.prod isCompact_univ) h.continuousOn this.tendstoUniformly hxK /-- In a product space `α × β`, assume that a function `f` is continuous on `s × k` where `k` is compact. Then, along the fiber above any `q ∈ s`, `f` is transversely uniformly continuous, i.e., if `p ∈ s` is close enough to `q`, then `f p x` is uniformly close to `f q x` for all `x ∈ k`. -/ lemma IsCompact.mem_uniformity_of_prod {α β E : Type*} [TopologicalSpace α] [TopologicalSpace β] [UniformSpace E] {f : α → β → E} {s : Set α} {k : Set β} {q : α} {u : Set (E × E)} (hk : IsCompact k) (hf : ContinuousOn f.uncurry (s ×ˢ k)) (hq : q ∈ s) (hu : u ∈ 𝓤 E) : ∃ v ∈ 𝓝[s] q, ∀ p ∈ v, ∀ x ∈ k, (f p x, f q x) ∈ u := by apply hk.induction_on (p := fun t ↦ ∃ v ∈ 𝓝[s] q, ∀ p ∈ v, ∀ x ∈ t, (f p x, f q x) ∈ u) · exact ⟨univ, univ_mem, by simp⟩ · intro t' t ht't ⟨v, v_mem, hv⟩ exact ⟨v, v_mem, fun p hp x hx ↦ hv p hp x (ht't hx)⟩ · intro t t' ⟨v, v_mem, hv⟩ ⟨v', v'_mem, hv'⟩ refine ⟨v ∩ v', inter_mem v_mem v'_mem, fun p hp x hx ↦ ?_⟩ rcases hx with h'x|h'x · exact hv p hp.1 x h'x · exact hv' p hp.2 x h'x · rcases comp_symm_of_uniformity hu with ⟨u', u'_mem, u'_symm, hu'⟩ intro x hx obtain ⟨v, hv, w, hw, hvw⟩ : ∃ v ∈ 𝓝[s] q, ∃ w ∈ 𝓝[k] x, v ×ˢ w ⊆ f.uncurry ⁻¹' {z | (f q x, z) ∈ u'} := mem_nhdsWithin_prod_iff.1 (hf (q, x) ⟨hq, hx⟩ (mem_nhds_left (f q x) u'_mem)) refine ⟨w, hw, v, hv, fun p hp y hy ↦ ?_⟩ have A : (f q x, f p y) ∈ u' := hvw (⟨hp, hy⟩ : (p, y) ∈ v ×ˢ w) have B : (f q x, f q y) ∈ u' := hvw (⟨mem_of_mem_nhdsWithin hq hv, hy⟩ : (q, y) ∈ v ×ˢ w) exact hu' <| SetRel.prodMk_mem_comp (u'_symm A) B section UniformConvergence /-- An equicontinuous family of functions defined on a compact uniform space is automatically uniformly equicontinuous. -/ theorem CompactSpace.uniformEquicontinuous_of_equicontinuous {ι : Type*} {F : ι → β → α} [CompactSpace β] (h : Equicontinuous F) : UniformEquicontinuous F := by rw [equicontinuous_iff_continuous] at h rw [uniformEquicontinuous_iff_uniformContinuous] exact CompactSpace.uniformContinuous_of_continuous h end UniformConvergence
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Equicontinuity.lean
import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notation Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (SetRel.prodMk_mem_comp ?_ (hy i))⟩ exact SetRel.symm V (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function `swap 𝓕 : β → ι → α` is uniformly continuous on `S` *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔ ∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace] unfold ContinuousWithinAt rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf] theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {x₀ : X} : EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng] theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} : Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace] rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng] theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} : EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ] theorem uniformEquicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} : UniformEquicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, UniformEquicontinuous (uα := u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uα := _)] rw [UniformFun.iInf_eq, uniformContinuous_iInf_rng] theorem uniformEquicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} {S : Set β} : UniformEquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, UniformEquicontinuousOn (uα := u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uα := _)] unfold UniformContinuousOn rw [UniformFun.iInf_eq, iInf_uniformity, tendsto_iInf] theorem equicontinuousWithinAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {S : Set X'} {x₀ : X'} {k : κ} (hk : EquicontinuousWithinAt (tX := t k) F S x₀) : EquicontinuousWithinAt (tX := ⨅ k, t k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (tX := _)] at hk ⊢ unfold ContinuousWithinAt nhdsWithin at hk ⊢ rw [nhds_iInf] exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k theorem equicontinuousAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {x₀ : X'} {k : κ} (hk : EquicontinuousAt (tX := t k) F x₀) : EquicontinuousAt (tX := ⨅ k, t k) F x₀ := by rw [← equicontinuousWithinAt_univ (tX := _)] at hk ⊢ exact equicontinuousWithinAt_iInf_dom hk theorem equicontinuous_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {k : κ} (hk : Equicontinuous (tX := t k) F) : Equicontinuous (tX := ⨅ k, t k) F := fun x ↦ equicontinuousAt_iInf_dom (hk x) theorem equicontinuousOn_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α} {S : Set X'} {k : κ} (hk : EquicontinuousOn (tX := t k) F S) : EquicontinuousOn (tX := ⨅ k, t k) F S := fun x hx ↦ equicontinuousWithinAt_iInf_dom (hk x hx) theorem uniformEquicontinuous_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α} {k : κ} (hk : UniformEquicontinuous (uβ := u k) F) : UniformEquicontinuous (uβ := ⨅ k, u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uβ := _)] at hk ⊢ exact uniformContinuous_iInf_dom hk theorem uniformEquicontinuousOn_iInf_dom {u : κ → UniformSpace β'} {F : ι → β' → α} {S : Set β'} {k : κ} (hk : UniformEquicontinuousOn (uβ := u k) F S) : UniformEquicontinuousOn (uβ := ⨅ k, u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uβ := _)] at hk ⊢ unfold UniformContinuousOn rw [iInf_uniformity] exact hk.mono_left <| inf_le_inf_right _ <| iInf_le _ k theorem Filter.HasBasis.equicontinuousAt_iff_left {p : κ → Prop} {s : κ → Set X} {F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p s) : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by rw [equicontinuousAt_iff_continuousAt, ContinuousAt, hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)] rfl theorem Filter.HasBasis.equicontinuousWithinAt_iff_left {p : κ → Prop} {s : κ → Set X} {F : ι → X → α} {S : Set X} {x₀ : X} (hX : (𝓝[S] x₀).HasBasis p s) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x ∈ s k, ∀ i, (F i x₀, F i x) ∈ U := by rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt, hX.tendsto_iff (UniformFun.hasBasis_nhds ι α _)] rfl theorem Filter.HasBasis.equicontinuousAt_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → X → α} {x₀ : X} (hα : (𝓤 α).HasBasis p s) : EquicontinuousAt F x₀ ↔ ∀ k, p k → ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ s k := by rw [equicontinuousAt_iff_continuousAt, ContinuousAt, (UniformFun.hasBasis_nhds_of_basis ι α _ hα).tendsto_right_iff] rfl theorem Filter.HasBasis.equicontinuousWithinAt_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → X → α} {S : Set X} {x₀ : X} (hα : (𝓤 α).HasBasis p s) : EquicontinuousWithinAt F S x₀ ↔ ∀ k, p k → ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ s k := by rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt, (UniformFun.hasBasis_nhds_of_basis ι α _ hα).tendsto_right_iff] rfl theorem Filter.HasBasis.equicontinuousAt_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set X} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → X → α} {x₀ : X} (hX : (𝓝 x₀).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : EquicontinuousAt F x₀ ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x ∈ s₁ k₁, ∀ i, (F i x₀, F i x) ∈ s₂ k₂ := by rw [equicontinuousAt_iff_continuousAt, ContinuousAt, hX.tendsto_iff (UniformFun.hasBasis_nhds_of_basis ι α _ hα)] rfl theorem Filter.HasBasis.equicontinuousWithinAt_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set X} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → X → α} {S : Set X} {x₀ : X} (hX : (𝓝[S] x₀).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : EquicontinuousWithinAt F S x₀ ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x ∈ s₁ k₁, ∀ i, (F i x₀, F i x) ∈ s₂ k₂ := by rw [equicontinuousWithinAt_iff_continuousWithinAt, ContinuousWithinAt, hX.tendsto_iff (UniformFun.hasBasis_nhds_of_basis ι α _ hα)] rfl theorem Filter.HasBasis.uniformEquicontinuous_iff_left {p : κ → Prop} {s : κ → Set (β × β)} {F : ι → β → α} (hβ : (𝓤 β).HasBasis p s) : UniformEquicontinuous F ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x y, (x, y) ∈ s k → ∀ i, (F i x, F i y) ∈ U := by rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous, hβ.tendsto_iff (UniformFun.hasBasis_uniformity ι α)] simp only [Prod.forall] rfl theorem Filter.HasBasis.uniformEquicontinuousOn_iff_left {p : κ → Prop} {s : κ → Set (β × β)} {F : ι → β → α} {S : Set β} (hβ : (𝓤 β ⊓ 𝓟 (S ×ˢ S)).HasBasis p s) : UniformEquicontinuousOn F S ↔ ∀ U ∈ 𝓤 α, ∃ k, p k ∧ ∀ x y, (x, y) ∈ s k → ∀ i, (F i x, F i y) ∈ U := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn, UniformContinuousOn, hβ.tendsto_iff (UniformFun.hasBasis_uniformity ι α)] simp only [Prod.forall] rfl theorem Filter.HasBasis.uniformEquicontinuous_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → β → α} (hα : (𝓤 α).HasBasis p s) : UniformEquicontinuous F ↔ ∀ k, p k → ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ s k := by rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous, (UniformFun.hasBasis_uniformity_of_basis ι α hα).tendsto_right_iff] rfl theorem Filter.HasBasis.uniformEquicontinuousOn_iff_right {p : κ → Prop} {s : κ → Set (α × α)} {F : ι → β → α} {S : Set β} (hα : (𝓤 α).HasBasis p s) : UniformEquicontinuousOn F S ↔ ∀ k, p k → ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ s k := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn, UniformContinuousOn, (UniformFun.hasBasis_uniformity_of_basis ι α hα).tendsto_right_iff] rfl theorem Filter.HasBasis.uniformEquicontinuous_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set (β × β)} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → β → α} (hβ : (𝓤 β).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : UniformEquicontinuous F ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x y, (x, y) ∈ s₁ k₁ → ∀ i, (F i x, F i y) ∈ s₂ k₂ := by rw [uniformEquicontinuous_iff_uniformContinuous, UniformContinuous, hβ.tendsto_iff (UniformFun.hasBasis_uniformity_of_basis ι α hα)] simp only [Prod.forall] rfl theorem Filter.HasBasis.uniformEquicontinuousOn_iff {κ₁ κ₂ : Type*} {p₁ : κ₁ → Prop} {s₁ : κ₁ → Set (β × β)} {p₂ : κ₂ → Prop} {s₂ : κ₂ → Set (α × α)} {F : ι → β → α} {S : Set β} (hβ : (𝓤 β ⊓ 𝓟 (S ×ˢ S)).HasBasis p₁ s₁) (hα : (𝓤 α).HasBasis p₂ s₂) : UniformEquicontinuousOn F S ↔ ∀ k₂, p₂ k₂ → ∃ k₁, p₁ k₁ ∧ ∀ x y, (x, y) ∈ s₁ k₁ → ∀ i, (F i x, F i y) ∈ s₂ k₂ := by rw [uniformEquicontinuousOn_iff_uniformContinuousOn, UniformContinuousOn, hβ.tendsto_iff (UniformFun.hasBasis_uniformity_of_basis ι α hα)] simp only [Prod.forall] rfl /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous at a point `x₀ : X` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous at `x₀`. -/ theorem IsUniformInducing.equicontinuousAt_iff {F : ι → X → α} {x₀ : X} {u : α → β} (hu : IsUniformInducing u) : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((u ∘ ·) ∘ F) x₀ := by have := (UniformFun.postcomp_isUniformInducing (α := ι) hu).isInducing rw [equicontinuousAt_iff_continuousAt, equicontinuousAt_iff_continuousAt, this.continuousAt_iff] rfl /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous at a point `x₀ : X` within a subset `S : Set X` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous at `x₀` within `S`. -/ lemma IsUniformInducing.equicontinuousWithinAt_iff {F : ι → X → α} {S : Set X} {x₀ : X} {u : α → β} (hu : IsUniformInducing u) : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((u ∘ ·) ∘ F) S x₀ := by have := (UniformFun.postcomp_isUniformInducing (α := ι) hu).isInducing simp only [equicontinuousWithinAt_iff_continuousWithinAt, this.continuousWithinAt_iff] rfl /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous. -/ lemma IsUniformInducing.equicontinuous_iff {F : ι → X → α} {u : α → β} (hu : IsUniformInducing u) : Equicontinuous F ↔ Equicontinuous ((u ∘ ·) ∘ F) := by congrm ∀ x, ?_ rw [hu.equicontinuousAt_iff] /-- Given `u : α → β` a uniform inducing map, a family `𝓕 : ι → X → α` is equicontinuous on a subset `S : Set X` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is equicontinuous on `S`. -/ theorem IsUniformInducing.equicontinuousOn_iff {F : ι → X → α} {S : Set X} {u : α → β} (hu : IsUniformInducing u) : EquicontinuousOn F S ↔ EquicontinuousOn ((u ∘ ·) ∘ F) S := by congrm ∀ x ∈ S, ?_ rw [hu.equicontinuousWithinAt_iff] /-- Given `u : α → γ` a uniform inducing map, a family `𝓕 : ι → β → α` is uniformly equicontinuous iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is uniformly equicontinuous. -/ theorem IsUniformInducing.uniformEquicontinuous_iff {F : ι → β → α} {u : α → γ} (hu : IsUniformInducing u) : UniformEquicontinuous F ↔ UniformEquicontinuous ((u ∘ ·) ∘ F) := by have := UniformFun.postcomp_isUniformInducing (α := ι) hu simp only [uniformEquicontinuous_iff_uniformContinuous, this.uniformContinuous_iff] rfl /-- Given `u : α → γ` a uniform inducing map, a family `𝓕 : ι → β → α` is uniformly equicontinuous on a subset `S : Set β` iff the family `𝓕'`, obtained by composing each function of `𝓕` by `u`, is uniformly equicontinuous on `S`. -/ theorem IsUniformInducing.uniformEquicontinuousOn_iff {F : ι → β → α} {S : Set β} {u : α → γ} (hu : IsUniformInducing u) : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((u ∘ ·) ∘ F) S := by have := UniformFun.postcomp_isUniformInducing (α := ι) hu simp only [uniformEquicontinuousOn_iff_uniformContinuousOn, this.uniformContinuousOn_iff] rfl /-- If a set of functions is equicontinuous at some `x₀` within a set `S`, the same is true for its closure in *any* topology for which evaluation at any `x ∈ S ∪ {x₀}` is continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map to `X → α` satisfying the right continuity conditions. See also `Set.EquicontinuousWithinAt.closure` for a more familiar (but weaker) statement. Note: This could *technically* be called `EquicontinuousWithinAt.closure` without name clashes with `Set.EquicontinuousWithinAt.closure`, but we don't do it because, even with a `protected` marker, it would introduce ambiguities while working in namespace `Set` (e.g, in the proof of any theorem called `Set.something`). -/ theorem EquicontinuousWithinAt.closure' {A : Set Y} {u : Y → X → α} {S : Set X} {x₀ : X} (hA : EquicontinuousWithinAt (u ∘ (↑) : A → X → α) S x₀) (hu₁ : Continuous (S.restrict ∘ u)) (hu₂ : Continuous (eval x₀ ∘ u)) : EquicontinuousWithinAt (u ∘ (↑) : closure A → X → α) S x₀ := by intro U hU rcases mem_uniformity_isClosed hU with ⟨V, hV, hVclosed, hVU⟩ filter_upwards [hA V hV, eventually_mem_nhdsWithin] with x hx hxS rw [SetCoe.forall] at * change A ⊆ (fun f => (u f x₀, u f x)) ⁻¹' V at hx refine (closure_minimal hx <| hVclosed.preimage <| hu₂.prodMk ?_).trans (preimage_mono hVU) exact (continuous_apply ⟨x, hxS⟩).comp hu₁ /-- If a set of functions is equicontinuous at some `x₀`, the same is true for its closure in *any* topology for which evaluation at any point is continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map to `X → α` satisfying the right continuity conditions. See also `Set.EquicontinuousAt.closure` for a more familiar statement. -/ theorem EquicontinuousAt.closure' {A : Set Y} {u : Y → X → α} {x₀ : X} (hA : EquicontinuousAt (u ∘ (↑) : A → X → α) x₀) (hu : Continuous u) : EquicontinuousAt (u ∘ (↑) : closure A → X → α) x₀ := by rw [← equicontinuousWithinAt_univ] at hA ⊢ exact hA.closure' (Pi.continuous_restrict _ |>.comp hu) (continuous_apply x₀ |>.comp hu) /-- If a set of functions is equicontinuous at some `x₀`, its closure for the product topology is also equicontinuous at `x₀`. -/ protected theorem Set.EquicontinuousAt.closure {A : Set (X → α)} {x₀ : X} (hA : A.EquicontinuousAt x₀) : (closure A).EquicontinuousAt x₀ := hA.closure' (u := id) continuous_id /-- If a set of functions is equicontinuous at some `x₀` within a set `S`, its closure for the product topology is also equicontinuous at `x₀` within `S`. This would also be true for the coarser topology of pointwise convergence on `S ∪ {x₀}`, see `Set.EquicontinuousWithinAt.closure'`. -/ protected theorem Set.EquicontinuousWithinAt.closure {A : Set (X → α)} {S : Set X} {x₀ : X} (hA : A.EquicontinuousWithinAt S x₀) : (closure A).EquicontinuousWithinAt S x₀ := hA.closure' (u := id) (Pi.continuous_restrict _) (continuous_apply _) /-- If a set of functions is equicontinuous, the same is true for its closure in *any* topology for which evaluation at any point is continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map to `X → α` satisfying the right continuity conditions. See also `Set.Equicontinuous.closure` for a more familiar statement. -/ theorem Equicontinuous.closure' {A : Set Y} {u : Y → X → α} (hA : Equicontinuous (u ∘ (↑) : A → X → α)) (hu : Continuous u) : Equicontinuous (u ∘ (↑) : closure A → X → α) := fun x ↦ (hA x).closure' hu /-- If a set of functions is equicontinuous on a set `S`, the same is true for its closure in *any* topology for which evaluation at any `x ∈ S` is continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map to `X → α` satisfying the right continuity conditions. See also `Set.EquicontinuousOn.closure` for a more familiar (but weaker) statement. -/ theorem EquicontinuousOn.closure' {A : Set Y} {u : Y → X → α} {S : Set X} (hA : EquicontinuousOn (u ∘ (↑) : A → X → α) S) (hu : Continuous (S.restrict ∘ u)) : EquicontinuousOn (u ∘ (↑) : closure A → X → α) S := fun x hx ↦ (hA x hx).closure' hu <| by exact continuous_apply ⟨x, hx⟩ |>.comp hu /-- If a set of functions is equicontinuous, its closure for the product topology is also equicontinuous. -/ protected theorem Set.Equicontinuous.closure {A : Set <| X → α} (hA : A.Equicontinuous) : (closure A).Equicontinuous := fun x ↦ Set.EquicontinuousAt.closure (hA x) /-- If a set of functions is equicontinuous, its closure for the product topology is also equicontinuous. This would also be true for the coarser topology of pointwise convergence on `S`, see `EquicontinuousOn.closure'`. -/ protected theorem Set.EquicontinuousOn.closure {A : Set <| X → α} {S : Set X} (hA : A.EquicontinuousOn S) : (closure A).EquicontinuousOn S := fun x hx ↦ Set.EquicontinuousWithinAt.closure (hA x hx) /-- If a set of functions is uniformly equicontinuous on a set `S`, the same is true for its closure in *any* topology for which evaluation at any `x ∈ S` i continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map to `β → α` satisfying the right continuity conditions. See also `Set.UniformEquicontinuousOn.closure` for a more familiar (but weaker) statement. -/ theorem UniformEquicontinuousOn.closure' {A : Set Y} {u : Y → β → α} {S : Set β} (hA : UniformEquicontinuousOn (u ∘ (↑) : A → β → α) S) (hu : Continuous (S.restrict ∘ u)) : UniformEquicontinuousOn (u ∘ (↑) : closure A → β → α) S := by intro U hU rcases mem_uniformity_isClosed hU with ⟨V, hV, hVclosed, hVU⟩ filter_upwards [hA V hV, mem_inf_of_right (mem_principal_self _)] rintro ⟨x, y⟩ hxy ⟨hxS, hyS⟩ rw [SetCoe.forall] at * change A ⊆ (fun f => (u f x, u f y)) ⁻¹' V at hxy refine (closure_minimal hxy <| hVclosed.preimage <| .prodMk ?_ ?_).trans (preimage_mono hVU) · exact (continuous_apply ⟨x, hxS⟩).comp hu · exact (continuous_apply ⟨y, hyS⟩).comp hu /-- If a set of functions is uniformly equicontinuous, the same is true for its closure in *any* topology for which evaluation at any point is continuous. Since this will be applied to `DFunLike` types, we state it for any topological space with a map to `β → α` satisfying the right continuity conditions. See also `Set.UniformEquicontinuous.closure` for a more familiar statement. -/ theorem UniformEquicontinuous.closure' {A : Set Y} {u : Y → β → α} (hA : UniformEquicontinuous (u ∘ (↑) : A → β → α)) (hu : Continuous u) : UniformEquicontinuous (u ∘ (↑) : closure A → β → α) := by rw [← uniformEquicontinuousOn_univ] at hA ⊢ exact hA.closure' (Pi.continuous_restrict _ |>.comp hu) /-- If a set of functions is uniformly equicontinuous, its closure for the product topology is also uniformly equicontinuous. -/ protected theorem Set.UniformEquicontinuous.closure {A : Set <| β → α} (hA : A.UniformEquicontinuous) : (closure A).UniformEquicontinuous := UniformEquicontinuous.closure' (u := id) hA continuous_id /-- If a set of functions is uniformly equicontinuous on a set `S`, its closure for the product topology is also uniformly equicontinuous. This would also be true for the coarser topology of pointwise convergence on `S`, see `UniformEquicontinuousOn.closure'`. -/ protected theorem Set.UniformEquicontinuousOn.closure {A : Set <| β → α} {S : Set β} (hA : A.UniformEquicontinuousOn S) : (closure A).UniformEquicontinuousOn S := UniformEquicontinuousOn.closure' (u := id) hA (Pi.continuous_restrict _) /- Implementation note: The following lemma (as well as all the following variations) could theoretically be deduced from the "closure" statements above. For example, we could do: ```lean theorem Filter.Tendsto.continuousAt_of_equicontinuousAt {l : Filter ι} [l.NeBot] {F : ι → X → α} {f : X → α} {x₀ : X} (h₁ : Tendsto F l (𝓝 f)) (h₂ : EquicontinuousAt F x₀) : ContinuousAt f x₀ := (equicontinuousAt_iff_range.mp h₂).closure.continuousAt ⟨f, mem_closure_of_tendsto h₁ <| Eventually.of_forall mem_range_self⟩ theorem Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous {l : Filter ι} [l.NeBot] {F : ι → β → α} {f : β → α} (h₁ : Tendsto F l (𝓝 f)) (h₂ : UniformEquicontinuous F) : UniformContinuous f := (uniformEquicontinuous_iff_range.mp h₂).closure.uniformContinuous ⟨f, mem_closure_of_tendsto h₁ <| Eventually.of_forall mem_range_self⟩ ``` Unfortunately, the proofs get painful when dealing with the relative case as one needs to change the ambient topology. So it turns out to be easier to re-do the proof by hand. -/ /-- If `𝓕 : ι → X → α` tends to `f : X → α` *pointwise on `S ∪ {x₀} : Set X`* along some nontrivial filter, and if the family `𝓕` is equicontinuous at `x₀ : X` within `S`, then the limit is continuous at `x₀` within `S`. -/ theorem Filter.Tendsto.continuousWithinAt_of_equicontinuousWithinAt {l : Filter ι} [l.NeBot] {F : ι → X → α} {f : X → α} {S : Set X} {x₀ : X} (h₁ : ∀ x ∈ S, Tendsto (F · x) l (𝓝 (f x))) (h₂ : Tendsto (F · x₀) l (𝓝 (f x₀))) (h₃ : EquicontinuousWithinAt F S x₀) : ContinuousWithinAt f S x₀ := by intro U hU; rw [mem_map] rcases UniformSpace.mem_nhds_iff.mp hU with ⟨V, hV, hVU⟩ rcases mem_uniformity_isClosed hV with ⟨W, hW, hWclosed, hWV⟩ filter_upwards [h₃ W hW, eventually_mem_nhdsWithin] with x hx hxS using hVU <| ball_mono hWV (f x₀) <| hWclosed.mem_of_tendsto (h₂.prodMk_nhds (h₁ x hxS)) <| Eventually.of_forall hx /-- If `𝓕 : ι → X → α` tends to `f : X → α` *pointwise* along some nontrivial filter, and if the family `𝓕` is equicontinuous at some `x₀ : X`, then the limit is continuous at `x₀`. -/ theorem Filter.Tendsto.continuousAt_of_equicontinuousAt {l : Filter ι} [l.NeBot] {F : ι → X → α} {f : X → α} {x₀ : X} (h₁ : Tendsto F l (𝓝 f)) (h₂ : EquicontinuousAt F x₀) : ContinuousAt f x₀ := by rw [← continuousWithinAt_univ, ← equicontinuousWithinAt_univ, tendsto_pi_nhds] at * exact continuousWithinAt_of_equicontinuousWithinAt (fun x _ ↦ h₁ x) (h₁ x₀) h₂ /-- If `𝓕 : ι → X → α` tends to `f : X → α` *pointwise* along some nontrivial filter, and if the family `𝓕` is equicontinuous, then the limit is continuous. -/ theorem Filter.Tendsto.continuous_of_equicontinuous {l : Filter ι} [l.NeBot] {F : ι → X → α} {f : X → α} (h₁ : Tendsto F l (𝓝 f)) (h₂ : Equicontinuous F) : Continuous f := continuous_iff_continuousAt.mpr fun x => h₁.continuousAt_of_equicontinuousAt (h₂ x) /-- If `𝓕 : ι → X → α` tends to `f : X → α` *pointwise on `S : Set X`* along some nontrivial filter, and if the family `𝓕` is equicontinuous, then the limit is continuous on `S`. -/ theorem Filter.Tendsto.continuousOn_of_equicontinuousOn {l : Filter ι} [l.NeBot] {F : ι → X → α} {f : X → α} {S : Set X} (h₁ : ∀ x ∈ S, Tendsto (F · x) l (𝓝 (f x))) (h₂ : EquicontinuousOn F S) : ContinuousOn f S := fun x hx ↦ Filter.Tendsto.continuousWithinAt_of_equicontinuousWithinAt h₁ (h₁ x hx) (h₂ x hx) /-- If `𝓕 : ι → β → α` tends to `f : β → α` *pointwise on `S : Set β`* along some nontrivial filter, and if the family `𝓕` is uniformly equicontinuous on `S`, then the limit is uniformly continuous on `S`. -/ theorem Filter.Tendsto.uniformContinuousOn_of_uniformEquicontinuousOn {l : Filter ι} [l.NeBot] {F : ι → β → α} {f : β → α} {S : Set β} (h₁ : ∀ x ∈ S, Tendsto (F · x) l (𝓝 (f x))) (h₂ : UniformEquicontinuousOn F S) : UniformContinuousOn f S := by intro U hU; rw [mem_map] rcases mem_uniformity_isClosed hU with ⟨V, hV, hVclosed, hVU⟩ filter_upwards [h₂ V hV, mem_inf_of_right (mem_principal_self _)] rintro ⟨x, y⟩ hxy ⟨hxS, hyS⟩ exact hVU <| hVclosed.mem_of_tendsto ((h₁ x hxS).prodMk_nhds (h₁ y hyS)) <| Eventually.of_forall hxy /-- If `𝓕 : ι → β → α` tends to `f : β → α` *pointwise* along some nontrivial filter, and if the family `𝓕` is uniformly equicontinuous, then the limit is uniformly continuous. -/ theorem Filter.Tendsto.uniformContinuous_of_uniformEquicontinuous {l : Filter ι} [l.NeBot] {F : ι → β → α} {f : β → α} (h₁ : Tendsto F l (𝓝 f)) (h₂ : UniformEquicontinuous F) : UniformContinuous f := by rw [← uniformContinuousOn_univ, ← uniformEquicontinuousOn_univ, tendsto_pi_nhds] at * exact uniformContinuousOn_of_uniformEquicontinuousOn (fun x _ ↦ h₁ x) h₂ /-- If `F : ι → X → α` is a family of functions equicontinuous at `x`, it tends to `f y` along a filter `l` for any `y ∈ s`, the limit function `f` tends to `z` along `𝓝[s] x`, and `x ∈ closure s`, then `(F · x)` tends to `z` along `l`. In some sense, this is a converse of `EquicontinuousAt.closure`. -/ theorem EquicontinuousAt.tendsto_of_mem_closure {l : Filter ι} {F : ι → X → α} {f : X → α} {s : Set X} {x : X} {z : α} (hF : EquicontinuousAt F x) (hf : Tendsto f (𝓝[s] x) (𝓝 z)) (hs : ∀ y ∈ s, Tendsto (F · y) l (𝓝 (f y))) (hx : x ∈ closure s) : Tendsto (F · x) l (𝓝 z) := by rw [(nhds_basis_uniformity (𝓤 α).basis_sets).tendsto_right_iff] at hf ⊢ intro U hU rcases comp_comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVs, hVU⟩ rw [mem_closure_iff_nhdsWithin_neBot] at hx have : ∀ᶠ y in 𝓝[s] x, y ∈ s ∧ (∀ i, (F i x, F i y) ∈ V) ∧ (f y, z) ∈ V := eventually_mem_nhdsWithin.and <| ((hF V hV).filter_mono nhdsWithin_le_nhds).and (hf V hV) rcases this.exists with ⟨y, hys, hFy, hfy⟩ filter_upwards [hs y hys (ball_mem_nhds _ hV)] with i hi exact hVU ⟨_, ⟨_, hFy i, mem_ball_symmetry.2 hi⟩, hfy⟩ /-- If `F : ι → X → α` is an equicontinuous family of functions, `f : X → α` is a continuous function, and `l` is a filter on `ι`, then `{x | Filter.Tendsto (F · x) l (𝓝 (f x))}` is a closed set. -/ theorem Equicontinuous.isClosed_setOf_tendsto {l : Filter ι} {F : ι → X → α} {f : X → α} (hF : Equicontinuous F) (hf : Continuous f) : IsClosed {x | Tendsto (F · x) l (𝓝 (f x))} := closure_subset_iff_isClosed.mp fun x hx ↦ (hF x).tendsto_of_mem_closure (hf.continuousAt.mono_left inf_le_left) (fun _ ↦ id) hx end end
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/UniformConvergenceTopology.lean
import Mathlib.Topology.Coherent import Mathlib.Topology.UniformSpace.Equiv import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.UniformApproximation /-! # Topology and uniform structure of uniform convergence This file endows `α → β` with the topologies / uniform structures of - uniform convergence on `α` - uniform convergence on a specified family `𝔖` of sets of `α`, also called `𝔖`-convergence Since `α → β` is already endowed with the topologies and uniform structures of pointwise convergence, we introduce type aliases `UniformFun α β` (denoted `α →ᵤ β`) and `UniformOnFun α β 𝔖` (denoted `α →ᵤ[𝔖] β`) and we actually endow *these* with the structures of uniform and `𝔖`-convergence respectively. Usual examples of the second construction include: - the topology of compact convergence, when `𝔖` is the set of compacts of `α` - the strong topology on the dual of a topological vector space (TVS) `E`, when `𝔖` is the set of Von Neumann bounded subsets of `E` - the weak-* topology on the dual of a TVS `E`, when `𝔖` is the set of singletons of `E`. This file contains a lot of technical facts, so it is heavily commented, proofs included! ## Main definitions * `UniformFun.gen`: basis sets for the uniformity of uniform convergence. These are sets of the form `S(V) := {(f, g) | ∀ x : α, (f x, g x) ∈ V}` for some `V : Set (β × β)` * `UniformFun.uniformSpace`: uniform structure of uniform convergence. This is the `UniformSpace` on `α →ᵤ β` whose uniformity is generated by the sets `S(V)` for `V ∈ 𝓤 β`. We will denote this uniform space as `𝒰(α, β, uβ)`, both in the comments and as a local notation in the Lean code, where `uβ` is the uniform space structure on `β`. This is declared as an instance on `α →ᵤ β`. * `UniformOnFun.uniformSpace`: uniform structure of `𝔖`-convergence, where `𝔖 : Set (Set α)`. This is the infimum, for `S ∈ 𝔖`, of the pullback of `𝒰 S β` by the map of restriction to `S`. We will denote it `𝒱(α, β, 𝔖, uβ)`, where `uβ` is the uniform space structure on `β`. This is declared as an instance on `α →ᵤ[𝔖] β`. ## Main statements ### Basic properties * `UniformFun.uniformContinuous_eval`: evaluation is uniformly continuous on `α →ᵤ β`. * `UniformFun.t2Space`: the topology of uniform convergence on `α →ᵤ β` is T₂ if `β` is T₂. * `UniformFun.tendsto_iff_tendstoUniformly`: `𝒰(α, β, uβ)` is indeed the uniform structure of uniform convergence * `UniformOnFun.uniformContinuous_eval_of_mem`: evaluation at a point contained in a set of `𝔖` is uniformly continuous on `α →ᵤ[𝔖] β` * `UniformOnFun.t2Space_of_covering`: the topology of `𝔖`-convergence on `α →ᵤ[𝔖] β` is T₂ if `β` is T₂ and `𝔖` covers `α` * `UniformOnFun.tendsto_iff_tendstoUniformlyOn`: `𝒱(α, β, 𝔖, uβ)` is indeed the uniform structure of `𝔖`-convergence ### Functoriality and compatibility with product of uniform spaces In order to avoid the need for filter bases as much as possible when using these definitions, we develop an extensive API for manipulating these structures abstractly. As usual in the topology section of mathlib, we first state results about the complete lattices of `UniformSpace`s on fixed types, and then we use these to deduce categorical-like results about maps between two uniform spaces. We only describe these in the harder case of `𝔖`-convergence, as the names of the corresponding results for uniform convergence can easily be guessed. #### Order statements * `UniformOnFun.mono`: let `u₁`, `u₂` be two uniform structures on `γ` and `𝔖₁ 𝔖₂ : Set (Set α)`. If `u₁ ≤ u₂` and `𝔖₂ ⊆ 𝔖₁` then `𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂)`. * `UniformOnFun.iInf_eq`: if `u` is a family of uniform structures on `γ`, then `𝒱(α, γ, 𝔖, (⨅ i, u i)) = ⨅ i, 𝒱(α, γ, 𝔖, u i)`. * `UniformOnFun.comap_eq`: if `u` is a uniform structures on `β` and `f : γ → β`, then `𝒱(α, γ, 𝔖, comap f u) = comap (fun g ↦ f ∘ g) 𝒱(α, γ, 𝔖, u₁)`. An interesting note about these statements is that they are proved without ever unfolding the basis definition of the uniform structure of uniform convergence! Instead, we build a (not very interesting) Galois connection `UniformFun.gc` and then rely on the Galois connection API to do most of the work. #### Morphism statements (unbundled) * `UniformOnFun.postcomp_uniformContinuous`: if `f : γ → β` is uniformly continuous, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is uniformly continuous. * `UniformOnFun.postcomp_isUniformInducing`: if `f : γ → β` is a uniform inducing, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is a uniform inducing. * `UniformOnFun.precomp_uniformContinuous`: let `f : γ → α`, `𝔖 : Set (Set α)`, `𝔗 : Set (Set γ)`, and assume that `∀ T ∈ 𝔗, f '' T ∈ 𝔖`. Then, the function `(fun g ↦ g ∘ f) : (α →ᵤ[𝔖] β) → (γ →ᵤ[𝔗] β)` is uniformly continuous. #### Isomorphism statements (bundled) * `UniformOnFun.congrRight`: turn a uniform isomorphism `γ ≃ᵤ β` into a uniform isomorphism `(α →ᵤ[𝔖] γ) ≃ᵤ (α →ᵤ[𝔖] β)` by post-composing. * `UniformOnFun.congrLeft`: turn a bijection `e : γ ≃ α` such that we have both `∀ T ∈ 𝔗, e '' T ∈ 𝔖` and `∀ S ∈ 𝔖, e ⁻¹' S ∈ 𝔗` into a uniform isomorphism `(γ →ᵤ[𝔗] β) ≃ᵤ (α →ᵤ[𝔖] β)` by pre-composing. * `UniformOnFun.uniformEquivPiComm`: the natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `α →ᵤ[𝔖] (Π i, δ i)` and `Π i, α →ᵤ[𝔖] δ i`. #### Important use cases * If `G` is a uniform group, then `α →ᵤ[𝔖] G` is a uniform group: since `(/) : G × G → G` is uniformly continuous, `UniformOnFun.postcomp_uniformContinuous` tells us that `((/) ∘ —) : (α →ᵤ[𝔖] G × G) → (α →ᵤ[𝔖] G)` is uniformly continuous. By precomposing with `UniformOnFun.uniformEquivProdArrow`, this gives that `(/) : (α →ᵤ[𝔖] G) × (α →ᵤ[𝔖] G) → (α →ᵤ[𝔖] G)` is also uniformly continuous * The transpose of a continuous linear map is continuous for the strong topologies: since continuous linear maps are uniformly continuous and map bounded sets to bounded sets, this is just a special case of `UniformOnFun.precomp_uniformContinuous`. ## TODO * Show that the uniform structure of `𝔖`-convergence is exactly the structure of `𝔖'`-convergence, where `𝔖'` is the ***noncovering*** bornology (i.e ***not*** what `Bornology` currently refers to in mathlib) generated by `𝔖`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags uniform convergence -/ noncomputable section open Filter Set Topology open scoped Uniformity section TypeAlias /-- The type of functions from `α` to `β` equipped with the uniform structure and topology of uniform convergence. We denote it `α →ᵤ β`. -/ def UniformFun (α β : Type*) := α → β /-- The type of functions from `α` to `β` equipped with the uniform structure and topology of uniform convergence on some family `𝔖` of subsets of `α`. We denote it `α →ᵤ[𝔖] β`. -/ @[nolint unusedArguments] def UniformOnFun (α β : Type*) (_ : Set (Set α)) := α → β @[inherit_doc] scoped[UniformConvergence] notation:25 α " →ᵤ " β:0 => UniformFun α β @[inherit_doc] scoped[UniformConvergence] notation:25 α " →ᵤ[" 𝔖 "] " β:0 => UniformOnFun α β 𝔖 open UniformConvergence variable {α β : Type*} {𝔖 : Set (Set α)} instance [Nonempty β] : Nonempty (α →ᵤ β) := Pi.instNonempty instance [Nonempty β] : Nonempty (α →ᵤ[𝔖] β) := Pi.instNonempty instance [Subsingleton β] : Subsingleton (α →ᵤ β) := inferInstanceAs <| Subsingleton <| α → β instance [Subsingleton β] : Subsingleton (α →ᵤ[𝔖] β) := inferInstanceAs <| Subsingleton <| α → β /-- Reinterpret `f : α → β` as an element of `α →ᵤ β`. -/ def UniformFun.ofFun : (α → β) ≃ (α →ᵤ β) := ⟨fun x => x, fun x => x, fun _ => rfl, fun _ => rfl⟩ /-- Reinterpret `f : α → β` as an element of `α →ᵤ[𝔖] β`. -/ def UniformOnFun.ofFun (𝔖) : (α → β) ≃ (α →ᵤ[𝔖] β) := ⟨fun x => x, fun x => x, fun _ => rfl, fun _ => rfl⟩ /-- Reinterpret `f : α →ᵤ β` as an element of `α → β`. -/ def UniformFun.toFun : (α →ᵤ β) ≃ (α → β) := UniformFun.ofFun.symm /-- Reinterpret `f : α →ᵤ[𝔖] β` as an element of `α → β`. -/ def UniformOnFun.toFun (𝔖) : (α →ᵤ[𝔖] β) ≃ (α → β) := (UniformOnFun.ofFun 𝔖).symm @[simp] lemma UniformFun.toFun_ofFun (f : α → β) : toFun (ofFun f) = f := rfl @[simp] lemma UniformFun.ofFun_toFun (f : α →ᵤ β) : ofFun (toFun f) = f := rfl @[simp] lemma UniformOnFun.toFun_ofFun (f : α → β) : toFun 𝔖 (ofFun 𝔖 f) = f := rfl @[simp] lemma UniformOnFun.ofFun_toFun (f : α →ᵤ[𝔖] β) : ofFun 𝔖 (toFun 𝔖 f) = f := rfl -- Note: we don't declare a `CoeFun` instance because Lean wouldn't insert it when writing -- `f x` (because of definitional equality with `α → β`). end TypeAlias open UniformConvergence namespace UniformFun variable (α β : Type*) {γ ι : Type*} variable {p : Filter ι} /-- Basis sets for the uniformity of uniform convergence: `gen α β V` is the set of pairs `(f, g)` of functions `α →ᵤ β` such that `∀ x, (f x, g x) ∈ V`. -/ protected def gen (V : Set (β × β)) : Set ((α →ᵤ β) × (α →ᵤ β)) := { uv : (α →ᵤ β) × (α →ᵤ β) | ∀ x, (toFun uv.1 x, toFun uv.2 x) ∈ V } /-- If `𝓕` is a filter on `β × β`, then the set of all `UniformFun.gen α β V` for `V ∈ 𝓕` is a filter basis on `(α →ᵤ β) × (α →ᵤ β)`. This will only be applied to `𝓕 = 𝓤 β` when `β` is equipped with a `UniformSpace` structure, but it is useful to define it for any filter in order to be able to state that it has a lower adjoint (see `UniformFun.gc`). -/ protected theorem isBasis_gen (𝓑 : Filter <| β × β) : IsBasis (fun V : Set (β × β) => V ∈ 𝓑) (UniformFun.gen α β) := ⟨⟨univ, univ_mem⟩, @fun U V hU hV => ⟨U ∩ V, inter_mem hU hV, fun _ huv => ⟨fun x => (huv x).left, fun x => (huv x).right⟩⟩⟩ /-- For `𝓕 : Filter (β × β)`, this is the set of all `UniformFun.gen α β V` for `V ∈ 𝓕` as a bundled `FilterBasis` over `(α →ᵤ β) × (α →ᵤ β)`. This will only be applied to `𝓕 = 𝓤 β` when `β` is equipped with a `UniformSpace` structure, but it is useful to define it for any filter in order to be able to state that it has a lower adjoint (see `UniformFun.gc`). -/ protected def basis (𝓕 : Filter <| β × β) : FilterBasis ((α →ᵤ β) × (α →ᵤ β)) := (UniformFun.isBasis_gen α β 𝓕).filterBasis /-- For `𝓕 : Filter (β × β)`, this is the filter generated by the filter basis `UniformFun.basis α β 𝓕`. For `𝓕 = 𝓤 β`, this will be the uniformity of uniform convergence on `α`. -/ protected def filter (𝓕 : Filter <| β × β) : Filter ((α →ᵤ β) × (α →ᵤ β)) := (UniformFun.basis α β 𝓕).filter --local notation "Φ" => fun (α β : Type*) (uvx : ((α →ᵤ β) × (α →ᵤ β)) × α) => --(uvx.fst.fst uvx.2, uvx.1.2 uvx.2) protected def phi (α β : Type*) (uvx : ((α →ᵤ β) × (α →ᵤ β)) × α) : β × β := (uvx.fst.fst uvx.2, uvx.1.2 uvx.2) set_option quotPrecheck false -- Porting note: we need a `[quot_precheck]` instance on fbinop% /- This is a lower adjoint to `UniformFun.filter` (see `UniformFun.gc`). The exact definition of the lower adjoint `l` is not interesting; we will only use that it exists (in `UniformFun.mono` and `UniformFun.iInf_eq`) and that `l (Filter.map (Prod.map f f) 𝓕) = Filter.map (Prod.map ((∘) f) ((∘) f)) (l 𝓕)` for each `𝓕 : Filter (γ × γ)` and `f : γ → α` (in `UniformFun.comap_eq`). -/ local notation "lowerAdjoint" => fun 𝓐 => map (UniformFun.phi α β) (𝓐 ×ˢ ⊤) /-- The function `UniformFun.filter α β : Filter (β × β) → Filter ((α →ᵤ β) × (α →ᵤ β))` has a lower adjoint `l` (in the sense of `GaloisConnection`). The exact definition of `l` is not interesting; we will only use that it exists (in `UniformFun.mono` and `UniformFun.iInf_eq`) and that `l (Filter.map (Prod.map f f) 𝓕) = Filter.map (Prod.map ((∘) f) ((∘) f)) (l 𝓕)` for each `𝓕 : Filter (γ × γ)` and `f : γ → α` (in `UniformFun.comap_eq`). -/ protected theorem gc : GaloisConnection lowerAdjoint fun 𝓕 => UniformFun.filter α β 𝓕 := by intro 𝓐 𝓕 symm calc 𝓐 ≤ UniformFun.filter α β 𝓕 ↔ (UniformFun.basis α β 𝓕).sets ⊆ 𝓐.sets := by rw [UniformFun.filter, ← FilterBasis.generate, le_generate_iff] _ ↔ ∀ U ∈ 𝓕, UniformFun.gen α β U ∈ 𝓐 := image_subset_iff _ ↔ ∀ U ∈ 𝓕, { uv | ∀ x, (uv, x) ∈ { t : ((α →ᵤ β) × (α →ᵤ β)) × α | (t.1.1 t.2, t.1.2 t.2) ∈ U } } ∈ 𝓐 := Iff.rfl _ ↔ ∀ U ∈ 𝓕, { uvx : ((α →ᵤ β) × (α →ᵤ β)) × α | (uvx.1.1 uvx.2, uvx.1.2 uvx.2) ∈ U } ∈ 𝓐 ×ˢ (⊤ : Filter α) := forall₂_congr fun U _hU => mem_prod_top.symm _ ↔ lowerAdjoint 𝓐 ≤ 𝓕 := Iff.rfl variable [UniformSpace β] /-- Core of the uniform structure of uniform convergence. -/ protected def uniformCore : UniformSpace.Core (α →ᵤ β) := UniformSpace.Core.mkOfBasis (UniformFun.basis α β (𝓤 β)) (fun _ ⟨_, hV, hVU⟩ _ => hVU ▸ fun _ => refl_mem_uniformity hV) (fun _ ⟨V, hV, hVU⟩ => hVU ▸ ⟨UniformFun.gen α β (Prod.swap ⁻¹' V), ⟨Prod.swap ⁻¹' V, tendsto_swap_uniformity hV, rfl⟩, fun _ huv x => huv x⟩) fun _ ⟨_, hV, hVU⟩ => hVU ▸ let ⟨W, hW, hWV⟩ := comp_mem_uniformity_sets hV ⟨UniformFun.gen α β W, ⟨W, hW, rfl⟩, fun _ ⟨w, huw, hwv⟩ x => hWV ⟨w x, ⟨huw x, hwv x⟩⟩⟩ /-- Uniform structure of uniform convergence, declared as an instance on `α →ᵤ β`. We will denote it `𝒰(α, β, uβ)` in the rest of this file. -/ instance uniformSpace : UniformSpace (α →ᵤ β) := UniformSpace.ofCore (UniformFun.uniformCore α β) /-- Topology of uniform convergence, declared as an instance on `α →ᵤ β`. -/ instance topologicalSpace : TopologicalSpace (α →ᵤ β) := inferInstance local notation "𝒰(" α ", " β ", " u ")" => @UniformFun.uniformSpace α β u /-- By definition, the uniformity of `α →ᵤ β` admits the family `{(f, g) | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_uniformity : (𝓤 (α →ᵤ β)).HasBasis (· ∈ 𝓤 β) (UniformFun.gen α β) := (UniformFun.isBasis_gen α β (𝓤 β)).hasBasis /-- The uniformity of `α →ᵤ β` admits the family `{(f, g) | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓑` as a filter basis, for any basis `𝓑` of `𝓤 β` (in the case `𝓑 = (𝓤 β).as_basis` this is true by definition). -/ protected theorem hasBasis_uniformity_of_basis {ι : Sort*} {p : ι → Prop} {s : ι → Set (β × β)} (h : (𝓤 β).HasBasis p s) : (𝓤 (α →ᵤ β)).HasBasis p (UniformFun.gen α β ∘ s) := (UniformFun.hasBasis_uniformity α β).to_hasBasis (fun _ hU => let ⟨i, hi, hiU⟩ := h.mem_iff.mp hU ⟨i, hi, fun _ huv x => hiU (huv x)⟩) fun i hi => ⟨s i, h.mem_of_mem hi, subset_rfl⟩ /-- For `f : α →ᵤ β`, `𝓝 f` admits the family `{g | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓑` as a filter basis, for any basis `𝓑` of `𝓤 β`. -/ protected theorem hasBasis_nhds_of_basis (f) {p : ι → Prop} {s : ι → Set (β × β)} (h : HasBasis (𝓤 β) p s) : (𝓝 f).HasBasis p fun i => { g | (f, g) ∈ UniformFun.gen α β (s i) } := nhds_basis_uniformity' (UniformFun.hasBasis_uniformity_of_basis α β h) /-- For `f : α →ᵤ β`, `𝓝 f` admits the family `{g | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_nhds (f) : (𝓝 f).HasBasis (fun V => V ∈ 𝓤 β) fun V => { g | (f, g) ∈ UniformFun.gen α β V } := UniformFun.hasBasis_nhds_of_basis α β f (Filter.basis_sets _) variable {α} /-- Evaluation at a fixed point is uniformly continuous on `α →ᵤ β`. -/ theorem uniformContinuous_eval (x : α) : UniformContinuous (Function.eval x ∘ toFun : (α →ᵤ β) → β) := by change _ ≤ _ rw [map_le_iff_le_comap, (UniformFun.hasBasis_uniformity α β).le_basis_iff ((𝓤 _).basis_sets.comap _)] exact fun U hU => ⟨U, hU, fun uv huv => huv x⟩ variable {β} @[simp] protected lemma mem_gen {β} {f g : α →ᵤ β} {V : Set (β × β)} : (f, g) ∈ UniformFun.gen α β V ↔ ∀ x, (toFun f x, toFun g x) ∈ V := .rfl /-- If `u₁` and `u₂` are two uniform structures on `γ` and `u₁ ≤ u₂`, then `𝒰(α, γ, u₁) ≤ 𝒰(α, γ, u₂)`. -/ protected theorem mono : Monotone (@UniformFun.uniformSpace α γ) := fun _ _ hu => (UniformFun.gc α γ).monotone_u hu /-- If `u` is a family of uniform structures on `γ`, then `𝒰(α, γ, (⨅ i, u i)) = ⨅ i, 𝒰(α, γ, u i)`. -/ protected theorem iInf_eq {u : ι → UniformSpace γ} : 𝒰(α, γ, (⨅ i, u i)) = ⨅ i, 𝒰(α, γ, u i) := by -- This follows directly from the fact that the upper adjoint in a Galois connection maps -- infimas to infimas. ext : 1 change UniformFun.filter α γ 𝓤[⨅ i, u i] = 𝓤[⨅ i, 𝒰(α, γ, u i)] rw [iInf_uniformity, iInf_uniformity] exact (UniformFun.gc α γ).u_iInf /-- If `u₁` and `u₂` are two uniform structures on `γ`, then `𝒰(α, γ, u₁ ⊓ u₂) = 𝒰(α, γ, u₁) ⊓ 𝒰(α, γ, u₂)`. -/ protected theorem inf_eq {u₁ u₂ : UniformSpace γ} : 𝒰(α, γ, u₁ ⊓ u₂) = 𝒰(α, γ, u₁) ⊓ 𝒰(α, γ, u₂) := by -- This follows directly from the fact that the upper adjoint in a Galois connection maps -- infimas to infimas. rw [inf_eq_iInf, inf_eq_iInf, UniformFun.iInf_eq] refine iInf_congr fun i => ?_ cases i <;> rfl /-- Post-composition by a uniform inducing function is a uniform inducing function for the uniform structures of uniform convergence. More precisely, if `f : γ → β` is uniform inducing, then `(f ∘ ·) : (α →ᵤ γ) → (α →ᵤ β)` is uniform inducing. -/ lemma postcomp_isUniformInducing [UniformSpace γ] {f : γ → β} (hf : IsUniformInducing f) : IsUniformInducing (ofFun ∘ (f ∘ ·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) := ⟨((UniformFun.hasBasis_uniformity _ _).comap _).eq_of_same_basis <| UniformFun.hasBasis_uniformity_of_basis _ _ (hf.basis_uniformity (𝓤 β).basis_sets)⟩ /-- Post-composition by a uniform embedding is a uniform embedding for the uniform structures of uniform convergence. More precisely, if `f : γ → β` is a uniform embedding, then `(f ∘ ·) : (α →ᵤ γ) → (α →ᵤ β)` is a uniform embedding. -/ protected theorem postcomp_isUniformEmbedding [UniformSpace γ] {f : γ → β} (hf : IsUniformEmbedding f) : IsUniformEmbedding (ofFun ∘ (f ∘ ·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) where toIsUniformInducing := UniformFun.postcomp_isUniformInducing hf.isUniformInducing injective _ _ H := funext fun _ ↦ hf.injective (congrFun H _) /-- If `u` is a uniform structures on `β` and `f : γ → β`, then `𝒰(α, γ, comap f u) = comap (fun g ↦ f ∘ g) 𝒰(α, γ, u₁)`. -/ protected theorem comap_eq {f : γ → β} : 𝒰(α, γ, ‹UniformSpace β›.comap f) = 𝒰(α, β, _).comap (f ∘ ·) := by letI : UniformSpace γ := .comap f ‹_› exact (UniformFun.postcomp_isUniformInducing (f := f) ⟨rfl⟩).comap_uniformSpace.symm /-- Post-composition by a uniformly continuous function is uniformly continuous on `α →ᵤ β`. More precisely, if `f : γ → β` is uniformly continuous, then `(fun g ↦ f ∘ g) : (α →ᵤ γ) → (α →ᵤ β)` is uniformly continuous. -/ protected theorem postcomp_uniformContinuous [UniformSpace γ] {f : γ → β} (hf : UniformContinuous f) : UniformContinuous (ofFun ∘ (f ∘ ·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) := by -- This is a direct consequence of `UniformFun.comap_eq` refine uniformContinuous_iff.mpr ?_ calc 𝒰(α, γ, _) ≤ 𝒰(α, γ, ‹UniformSpace β›.comap f) := UniformFun.mono (uniformContinuous_iff.mp hf) _ = 𝒰(α, β, _).comap (f ∘ ·) := by exact UniformFun.comap_eq /-- Turn a uniform isomorphism `γ ≃ᵤ β` into a uniform isomorphism `(α →ᵤ γ) ≃ᵤ (α →ᵤ β)` by post-composing. -/ protected def congrRight [UniformSpace γ] (e : γ ≃ᵤ β) : (α →ᵤ γ) ≃ᵤ (α →ᵤ β) := { Equiv.piCongrRight fun _ => e.toEquiv with uniformContinuous_toFun := UniformFun.postcomp_uniformContinuous e.uniformContinuous uniformContinuous_invFun := UniformFun.postcomp_uniformContinuous e.symm.uniformContinuous } /-- Pre-composition by any function is uniformly continuous for the uniform structures of uniform convergence. More precisely, for any `f : γ → α`, the function `(· ∘ f) : (α →ᵤ β) → (γ →ᵤ β)` is uniformly continuous. -/ protected theorem precomp_uniformContinuous {f : γ → α} : UniformContinuous fun g : α →ᵤ β => ofFun (toFun g ∘ f) := by -- Here we simply go back to filter bases. rw [UniformContinuous, (UniformFun.hasBasis_uniformity α β).tendsto_iff (UniformFun.hasBasis_uniformity γ β)] exact fun U hU => ⟨U, hU, fun uv huv x => huv (f x)⟩ /-- Turn a bijection `γ ≃ α` into a uniform isomorphism `(γ →ᵤ β) ≃ᵤ (α →ᵤ β)` by pre-composing. -/ protected def congrLeft (e : γ ≃ α) : (γ →ᵤ β) ≃ᵤ (α →ᵤ β) where toEquiv := e.arrowCongr (.refl _) uniformContinuous_toFun := UniformFun.precomp_uniformContinuous uniformContinuous_invFun := UniformFun.precomp_uniformContinuous /-- The natural map `UniformFun.toFun` from `α →ᵤ β` to `α → β` is uniformly continuous. In other words, the uniform structure of uniform convergence is finer than that of pointwise convergence, aka the product uniform structure. -/ protected theorem uniformContinuous_toFun : UniformContinuous (toFun : (α →ᵤ β) → α → β) := by -- By definition of the product uniform structure, this is just `uniform_continuous_eval`. rw [uniformContinuous_pi] intro x exact uniformContinuous_eval β x /-- The topology of uniform convergence is T₂. -/ instance [T2Space β] : T2Space (α →ᵤ β) := .of_injective_continuous toFun.injective UniformFun.uniformContinuous_toFun.continuous /-- The topology of uniform convergence indeed gives the same notion of convergence as `TendstoUniformly`. -/ protected theorem tendsto_iff_tendstoUniformly {F : ι → α →ᵤ β} {f : α →ᵤ β} : Tendsto F p (𝓝 f) ↔ TendstoUniformly (toFun ∘ F) (toFun f) p := by rw [(UniformFun.hasBasis_nhds α β f).tendsto_right_iff, TendstoUniformly] simp only [mem_setOf, UniformFun.gen, Function.comp_def] /-- The natural bijection between `α → β × γ` and `(α → β) × (α → γ)`, upgraded to a uniform isomorphism between `α →ᵤ β × γ` and `(α →ᵤ β) × (α →ᵤ γ)`. -/ protected def uniformEquivProdArrow [UniformSpace γ] : (α →ᵤ β × γ) ≃ᵤ (α →ᵤ β) × (α →ᵤ γ) := -- Denote `φ` this bijection. We want to show that -- `comap φ (𝒰(α, β, uβ) × 𝒰(α, γ, uγ)) = 𝒰(α, β × γ, uβ × uγ)`. -- But `uβ × uγ` is defined as `comap fst uβ ⊓ comap snd uγ`, so we just have to apply -- `UniformFun.inf_eq` and `UniformFun.comap_eq`, which leaves us to check -- that some square commutes. Equiv.toUniformEquivOfIsUniformInducing (Equiv.arrowProdEquivProdArrow _ _ _) <| by constructor change comap (Prod.map (Equiv.arrowProdEquivProdArrow _ _ _) (Equiv.arrowProdEquivProdArrow _ _ _)) _ = _ simp_rw [UniformFun] rw [← uniformity_comap] congr unfold instUniformSpaceProd rw [UniformSpace.comap_inf, ← UniformSpace.comap_comap, ← UniformSpace.comap_comap] have := (@UniformFun.inf_eq α (β × γ) (UniformSpace.comap Prod.fst ‹_›) (UniformSpace.comap Prod.snd ‹_›)).symm rwa [UniformFun.comap_eq, UniformFun.comap_eq] at this -- the relevant diagram commutes by definition variable (α) (δ : ι → Type*) [∀ i, UniformSpace (δ i)] /-- The natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `α →ᵤ (Π i, δ i)` and `Π i, α →ᵤ δ i`. -/ protected def uniformEquivPiComm : UniformEquiv (α →ᵤ ∀ i, δ i) (∀ i, α →ᵤ δ i) := -- Denote `φ` this bijection. We want to show that -- `comap φ (Π i, 𝒰(α, δ i, uδ i)) = 𝒰(α, (Π i, δ i), (Π i, uδ i))`. -- But `Π i, uδ i` is defined as `⨅ i, comap (eval i) (uδ i)`, so we just have to apply -- `UniformFun.iInf_eq` and `UniformFun.comap_eq`, which leaves us to check -- that some square commutes. @Equiv.toUniformEquivOfIsUniformInducing _ _ 𝒰(α, ∀ i, δ i, Pi.uniformSpace δ) (@Pi.uniformSpace ι (fun i => α → δ i) fun i => 𝒰(α, δ i, _)) (Equiv.piComm _) <| by refine @IsUniformInducing.mk ?_ ?_ ?_ ?_ ?_ ?_ change comap (Prod.map Function.swap Function.swap) _ = _ rw [← uniformity_comap] congr unfold Pi.uniformSpace rw [UniformSpace.ofCoreEq_toCore, UniformSpace.ofCoreEq_toCore, UniformSpace.comap_iInf, UniformFun.iInf_eq] refine iInf_congr fun i => ?_ rw [← UniformSpace.comap_comap, UniformFun.comap_eq] rfl -- Like in the previous lemma, the diagram actually commutes by definition /-- The set of continuous functions is closed in the uniform convergence topology. This is a simple wrapper over `TendstoUniformly.continuous`. -/ theorem isClosed_setOf_continuous [TopologicalSpace α] : IsClosed {f : α →ᵤ β | Continuous (toFun f)} := by refine isClosed_iff_forall_filter.2 fun f u _ hu huf ↦ ?_ rw [← tendsto_id', UniformFun.tendsto_iff_tendstoUniformly] at huf exact huf.continuous (le_principal_iff.mp hu) variable {α} (β) in theorem uniformSpace_eq_inf_precomp_of_cover {δ₁ δ₂ : Type*} (φ₁ : δ₁ → α) (φ₂ : δ₂ → α) (h_cover : range φ₁ ∪ range φ₂ = univ) : 𝒰(α, β, _) = .comap (ofFun ∘ (· ∘ φ₁) ∘ toFun) 𝒰(δ₁, β, _) ⊓ .comap (ofFun ∘ (· ∘ φ₂) ∘ toFun) 𝒰(δ₂, β, _) := by ext : 1 refine le_antisymm (le_inf ?_ ?_) ?_ · exact tendsto_iff_comap.mp UniformFun.precomp_uniformContinuous · exact tendsto_iff_comap.mp UniformFun.precomp_uniformContinuous · refine (UniformFun.hasBasis_uniformity δ₁ β |>.comap _).inf (UniformFun.hasBasis_uniformity δ₂ β |>.comap _) |>.le_basis_iff (UniformFun.hasBasis_uniformity α β) |>.mpr fun U hU ↦ ⟨⟨U, U⟩, ⟨hU, hU⟩, fun ⟨f, g⟩ hfg x ↦ ?_⟩ rcases h_cover.ge <| mem_univ x with (⟨y, rfl⟩|⟨y, rfl⟩) · exact hfg.1 y · exact hfg.2 y variable {α} (β) in theorem uniformSpace_eq_iInf_precomp_of_cover {δ : ι → Type*} (φ : Π i, δ i → α) (h_cover : ∃ I : Set ι, I.Finite ∧ ⋃ i ∈ I, range (φ i) = univ) : 𝒰(α, β, _) = ⨅ i, .comap (ofFun ∘ (· ∘ φ i) ∘ toFun) 𝒰(δ i, β, _) := by ext : 1 simp_rw [iInf_uniformity, uniformity_comap] refine le_antisymm (le_iInf fun i ↦ tendsto_iff_comap.mp UniformFun.precomp_uniformContinuous) ?_ rcases h_cover with ⟨I, I_finite, I_cover⟩ refine HasBasis.iInf (fun i : ι ↦ UniformFun.hasBasis_uniformity (δ i) β |>.comap _) |>.le_basis_iff (UniformFun.hasBasis_uniformity α β) |>.mpr fun U hU ↦ ⟨⟨I, fun _ ↦ U⟩, ⟨I_finite, fun _ ↦ hU⟩, fun ⟨f, g⟩ hfg x ↦ ?_⟩ rcases mem_iUnion₂.mp <| I_cover.ge <| mem_univ x with ⟨i, hi, y, rfl⟩ exact mem_iInter.mp hfg ⟨i, hi⟩ y end UniformFun namespace UniformOnFun variable {α β : Type*} {γ ι : Type*} variable {s : Set α} {p : Filter ι} local notation "𝒰(" α ", " β ", " u ")" => @UniformFun.uniformSpace α β u /-- Basis sets for the uniformity of `𝔖`-convergence: for `S : Set α` and `V : Set (β × β)`, `gen 𝔖 S V` is the set of pairs `(f, g)` of functions `α →ᵤ[𝔖] β` such that `∀ x ∈ S, (f x, g x) ∈ V`. Note that the family `𝔖 : Set (Set α)` is only used to specify which type alias of `α → β` to use here. -/ protected def gen (𝔖) (S : Set α) (V : Set (β × β)) : Set ((α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] β)) := { uv : (α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] β) | ∀ x ∈ S, (toFun 𝔖 uv.1 x, toFun 𝔖 uv.2 x) ∈ V } /-- For `S : Set α` and `V : Set (β × β)`, we have `UniformOnFun.gen 𝔖 S V = (S.restrict × S.restrict) ⁻¹' (UniformFun.gen S β V)`. This is the crucial fact for proving that the family `UniformOnFun.gen S V` for `S ∈ 𝔖` and `V ∈ 𝓤 β` is indeed a basis for the uniformity `α →ᵤ[𝔖] β` endowed with `𝒱(α, β, 𝔖, uβ)` the uniform structure of `𝔖`-convergence, as defined in `UniformOnFun.uniformSpace`. -/ protected theorem gen_eq_preimage_restrict {𝔖} (S : Set α) (V : Set (β × β)) : UniformOnFun.gen 𝔖 S V = Prod.map (S.restrict ∘ UniformFun.toFun) (S.restrict ∘ UniformFun.toFun) ⁻¹' UniformFun.gen S β V := by ext uv exact ⟨fun h ⟨x, hx⟩ => h x hx, fun h x hx => h ⟨x, hx⟩⟩ /-- `UniformOnFun.gen` is antitone in the first argument and monotone in the second. -/ protected theorem gen_mono {𝔖} {S S' : Set α} {V V' : Set (β × β)} (hS : S' ⊆ S) (hV : V ⊆ V') : UniformOnFun.gen 𝔖 S V ⊆ UniformOnFun.gen 𝔖 S' V' := fun _uv h x hx => hV (h x <| hS hx) /-- If `𝔖 : Set (Set α)` is nonempty and directed and `𝓑` is a filter basis on `β × β`, then the family `UniformOnFun.gen 𝔖 S V` for `S ∈ 𝔖` and `V ∈ 𝓑` is a filter basis on `(α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] β)`. We will show in `has_basis_uniformity_of_basis` that, if `𝓑` is a basis for `𝓤 β`, then the corresponding filter is the uniformity of `α →ᵤ[𝔖] β`. -/ protected theorem isBasis_gen (𝔖 : Set (Set α)) (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) (𝓑 : FilterBasis <| β × β) : IsBasis (fun SV : Set α × Set (β × β) => SV.1 ∈ 𝔖 ∧ SV.2 ∈ 𝓑) fun SV => UniformOnFun.gen 𝔖 SV.1 SV.2 := ⟨h.prod 𝓑.nonempty, fun {U₁V₁ U₂V₂} h₁ h₂ => let ⟨U₃, hU₃, hU₁₃, hU₂₃⟩ := h' U₁V₁.1 h₁.1 U₂V₂.1 h₂.1 let ⟨V₃, hV₃, hV₁₂₃⟩ := 𝓑.inter_sets h₁.2 h₂.2 ⟨⟨U₃, V₃⟩, ⟨⟨hU₃, hV₃⟩, fun _ H => ⟨fun x hx => (hV₁₂₃ <| H x <| hU₁₃ hx).1, fun x hx => (hV₁₂₃ <| H x <| hU₂₃ hx).2⟩⟩⟩⟩ variable (α β) [UniformSpace β] (𝔖 : Set (Set α)) /-- Uniform structure of `𝔖`-convergence, i.e uniform convergence on the elements of `𝔖`, declared as an instance on `α →ᵤ[𝔖] β`. It is defined as the infimum, for `S ∈ 𝔖`, of the pullback by `S.restrict`, the map of restriction to `S`, of the uniform structure `𝒰(s, β, uβ)` on `↥S →ᵤ β`. We will denote it `𝒱(α, β, 𝔖, uβ)`, where `uβ` is the uniform structure on `β`. -/ instance uniformSpace : UniformSpace (α →ᵤ[𝔖] β) := ⨅ (s : Set α) (_ : s ∈ 𝔖), .comap (UniformFun.ofFun ∘ s.restrict ∘ UniformOnFun.toFun 𝔖) 𝒰(s, β, _) local notation "𝒱(" α ", " β ", " 𝔖 ", " u ")" => @UniformOnFun.uniformSpace α β u 𝔖 /-- Topology of `𝔖`-convergence, i.e uniform convergence on the elements of `𝔖`, declared as an instance on `α →ᵤ[𝔖] β`. -/ instance topologicalSpace : TopologicalSpace (α →ᵤ[𝔖] β) := 𝒱(α, β, 𝔖, _).toTopologicalSpace /-- The topology of `𝔖`-convergence is the infimum, for `S ∈ 𝔖`, of topology induced by the map of `S.restrict : (α →ᵤ[𝔖] β) → (↥S →ᵤ β)` of restriction to `S`, where `↥S →ᵤ β` is endowed with the topology of uniform convergence. -/ protected theorem topologicalSpace_eq : UniformOnFun.topologicalSpace α β 𝔖 = ⨅ (s : Set α) (_ : s ∈ 𝔖), TopologicalSpace.induced (UniformFun.ofFun ∘ s.restrict ∘ toFun 𝔖) (UniformFun.topologicalSpace s β) := by simp only [UniformOnFun.topologicalSpace, UniformSpace.toTopologicalSpace_iInf] rfl protected theorem hasBasis_uniformity_of_basis_aux₁ {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) (S : Set α) : (@uniformity (α →ᵤ[𝔖] β) ((UniformFun.uniformSpace S β).comap S.restrict)).HasBasis p fun i => UniformOnFun.gen 𝔖 S (s i) := by simp_rw [UniformOnFun.gen_eq_preimage_restrict, uniformity_comap] exact (UniformFun.hasBasis_uniformity_of_basis S β hb).comap _ protected theorem hasBasis_uniformity_of_basis_aux₂ (h : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) : DirectedOn ((fun s : Set α => (UniformFun.uniformSpace s β).comap (s.restrict : (α →ᵤ β) → s →ᵤ β)) ⁻¹'o GE.ge) 𝔖 := h.mono fun _ _ hst => ((UniformOnFun.hasBasis_uniformity_of_basis_aux₁ α β 𝔖 hb _).le_basis_iff (UniformOnFun.hasBasis_uniformity_of_basis_aux₁ α β 𝔖 hb _)).mpr fun V hV => ⟨V, hV, UniformOnFun.gen_mono hst subset_rfl⟩ /-- If `𝔖 : Set (Set α)` is nonempty and directed and `𝓑` is a filter basis of `𝓤 β`, then the uniformity of `α →ᵤ[𝔖] β` admits the family `{(f, g) | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓑` as a filter basis. -/ protected theorem hasBasis_uniformity_of_basis (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) : (𝓤 (α →ᵤ[𝔖] β)).HasBasis (fun Si : Set α × ι => Si.1 ∈ 𝔖 ∧ p Si.2) fun Si => UniformOnFun.gen 𝔖 Si.1 (s Si.2) := by simp only [iInf_uniformity] exact hasBasis_biInf_of_directed h (fun S => UniformOnFun.gen 𝔖 S ∘ s) _ (fun S _hS => UniformOnFun.hasBasis_uniformity_of_basis_aux₁ α β 𝔖 hb S) (UniformOnFun.hasBasis_uniformity_of_basis_aux₂ α β 𝔖 h' hb) /-- If `𝔖 : Set (Set α)` is nonempty and directed, then the uniformity of `α →ᵤ[𝔖] β` admits the family `{(f, g) | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_uniformity (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) : (𝓤 (α →ᵤ[𝔖] β)).HasBasis (fun SV : Set α × Set (β × β) => SV.1 ∈ 𝔖 ∧ SV.2 ∈ 𝓤 β) fun SV => UniformOnFun.gen 𝔖 SV.1 SV.2 := UniformOnFun.hasBasis_uniformity_of_basis α β 𝔖 h h' (𝓤 β).basis_sets variable {α β} /-- Let `t i` be a nonempty directed subfamily of `𝔖` such that every `s ∈ 𝔖` is included in some `t i`. Let `V` bounded by `p` be a basis of entourages of `β`. Then `UniformOnFun.gen 𝔖 (t i) (V j)` bounded by `p j` is a basis of entourages of `α →ᵤ[𝔖] β`. -/ protected theorem hasBasis_uniformity_of_covering_of_basis {ι ι' : Type*} [Nonempty ι] {t : ι → Set α} {p : ι' → Prop} {V : ι' → Set (β × β)} (ht : ∀ i, t i ∈ 𝔖) (hdir : Directed (· ⊆ ·) t) (hex : ∀ s ∈ 𝔖, ∃ i, s ⊆ t i) (hb : HasBasis (𝓤 β) p V) : (𝓤 (α →ᵤ[𝔖] β)).HasBasis (fun i : ι × ι' ↦ p i.2) fun i ↦ UniformOnFun.gen 𝔖 (t i.1) (V i.2) := by have hne : 𝔖.Nonempty := (range_nonempty t).mono (range_subset_iff.2 ht) have hd : DirectedOn (· ⊆ ·) 𝔖 := fun s₁ hs₁ s₂ hs₂ ↦ by rcases hex s₁ hs₁, hex s₂ hs₂ with ⟨⟨i₁, his₁⟩, i₂, his₂⟩ rcases hdir i₁ i₂ with ⟨i, hi₁, hi₂⟩ exact ⟨t i, ht _, his₁.trans hi₁, his₂.trans hi₂⟩ refine (UniformOnFun.hasBasis_uniformity_of_basis α β 𝔖 hne hd hb).to_hasBasis (fun ⟨s, i'⟩ ⟨hs, hi'⟩ ↦ ?_) fun ⟨i, i'⟩ hi' ↦ ⟨(t i, i'), ⟨ht i, hi'⟩, Subset.rfl⟩ rcases hex s hs with ⟨i, hi⟩ exact ⟨(i, i'), hi', UniformOnFun.gen_mono hi Subset.rfl⟩ /-- If `t n` is a monotone sequence of sets in `𝔖` such that each `s ∈ 𝔖` is included in some `t n` and `V n` is an antitone basis of entourages of `β`, then `UniformOnFun.gen 𝔖 (t n) (V n)` is an antitone basis of entourages of `α →ᵤ[𝔖] β`. -/ protected theorem hasAntitoneBasis_uniformity {ι : Type*} [Preorder ι] [IsDirected ι (· ≤ ·)] {t : ι → Set α} {V : ι → Set (β × β)} (ht : ∀ n, t n ∈ 𝔖) (hmono : Monotone t) (hex : ∀ s ∈ 𝔖, ∃ n, s ⊆ t n) (hb : HasAntitoneBasis (𝓤 β) V) : (𝓤 (α →ᵤ[𝔖] β)).HasAntitoneBasis fun n ↦ UniformOnFun.gen 𝔖 (t n) (V n) := by have := hb.nonempty refine ⟨(UniformOnFun.hasBasis_uniformity_of_covering_of_basis 𝔖 ht hmono.directed_le hex hb.1).to_hasBasis ?_ fun i _ ↦ ⟨(i, i), trivial, Subset.rfl⟩, ?_⟩ · rintro ⟨k, l⟩ - rcases directed_of (· ≤ ·) k l with ⟨n, hkn, hln⟩ exact ⟨n, trivial, UniformOnFun.gen_mono (hmono hkn) (hb.2 <| hln)⟩ · exact fun k l h ↦ UniformOnFun.gen_mono (hmono h) (hb.2 h) protected theorem isCountablyGenerated_uniformity [IsCountablyGenerated (𝓤 β)] {t : ℕ → Set α} (ht : ∀ n, t n ∈ 𝔖) (hmono : Monotone t) (hex : ∀ s ∈ 𝔖, ∃ n, s ⊆ t n) : IsCountablyGenerated (𝓤 (α →ᵤ[𝔖] β)) := let ⟨_V, hV⟩ := exists_antitone_basis (𝓤 β) (UniformOnFun.hasAntitoneBasis_uniformity 𝔖 ht hmono hex hV).isCountablyGenerated variable (α β) /-- For `f : α →ᵤ[𝔖] β`, where `𝔖 : Set (Set α)` is nonempty and directed, `𝓝 f` admits the family `{g | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓑` as a filter basis, for any basis `𝓑` of `𝓤 β`. -/ protected theorem hasBasis_nhds_of_basis (f : α →ᵤ[𝔖] β) (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) : (𝓝 f).HasBasis (fun Si : Set α × ι => Si.1 ∈ 𝔖 ∧ p Si.2) fun Si => { g | (g, f) ∈ UniformOnFun.gen 𝔖 Si.1 (s Si.2) } := letI : UniformSpace (α → β) := UniformOnFun.uniformSpace α β 𝔖 nhds_basis_uniformity (UniformOnFun.hasBasis_uniformity_of_basis α β 𝔖 h h' hb) /-- For `f : α →ᵤ[𝔖] β`, where `𝔖 : Set (Set α)` is nonempty and directed, `𝓝 f` admits the family `{g | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_nhds (f : α →ᵤ[𝔖] β) (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) : (𝓝 f).HasBasis (fun SV : Set α × Set (β × β) => SV.1 ∈ 𝔖 ∧ SV.2 ∈ 𝓤 β) fun SV => { g | (g, f) ∈ UniformOnFun.gen 𝔖 SV.1 SV.2 } := UniformOnFun.hasBasis_nhds_of_basis α β 𝔖 f h h' (Filter.basis_sets _) /-- If `S ∈ 𝔖`, then the restriction to `S` is a uniformly continuous map from `α →ᵤ[𝔖] β` to `↥S →ᵤ β`. -/ protected theorem uniformContinuous_restrict (h : s ∈ 𝔖) : UniformContinuous (UniformFun.ofFun ∘ (s.restrict : (α → β) → s → β) ∘ toFun 𝔖) := by change _ ≤ _ simp only [UniformOnFun.uniformSpace, map_le_iff_le_comap, iInf_uniformity] exact iInf₂_le s h theorem isUniformEmbedding_toFun_finite : IsUniformEmbedding (toFun _ : (α →ᵤ[{s | s.Finite}] β) → (α → β)) := by refine ⟨⟨?_⟩, Function.injective_id⟩ simp_rw [Pi.uniformity, comap_iInf, comap_comap] refine HasBasis.ext (HasBasis.iInf' fun i ↦ (basis_sets _).comap _) (UniformOnFun.hasBasis_uniformity α β _ ⟨∅, finite_empty⟩ (directedOn_of_sup_mem fun _ _ ↦ .union)) (fun ⟨S, U⟩ ⟨hS, hU⟩ ↦ ⟨⟨S, ⋂ x ∈ S, U x⟩, ⟨⟨hS, biInter_mem hS |>.mpr hU⟩, fun f hf ↦ mem_iInter₂.mpr fun x hx ↦ mem_iInter₂.mp (hf x hx) x hx⟩⟩) (fun ⟨S, U⟩ ⟨hS, hU⟩ ↦ ⟨⟨S, fun _ ↦ U⟩, ⟨hS, fun _ _ ↦ hU⟩, fun f hf x hx ↦ mem_iInter₂.mp hf x hx⟩) theorem isEmbedding_toFun_finite : IsEmbedding (toFun _ : (α →ᵤ[{s | s.Finite}] β) → (α → β)) := (isUniformEmbedding_toFun_finite α β).isEmbedding variable {α} /-- A version of `UniformOnFun.hasBasis_uniformity_of_basis` with weaker conclusion and weaker assumptions. We make no assumptions about the set `𝔖` but conclude only that the uniformity is equal to some indexed infimum. -/ protected theorem uniformity_eq_of_basis {ι : Sort*} {p : ι → Prop} {V : ι → Set (β × β)} (h : (𝓤 β).HasBasis p V) : 𝓤 (α →ᵤ[𝔖] β) = ⨅ s ∈ 𝔖, ⨅ (i) (_ : p i), 𝓟 (UniformOnFun.gen 𝔖 s (V i)) := by simp_rw [iInf_uniformity, uniformity_comap, (UniformFun.hasBasis_uniformity_of_basis _ _ h).eq_biInf, comap_iInf, comap_principal, Function.comp_apply, UniformFun.gen, Subtype.forall, UniformOnFun.gen, preimage_setOf_eq, Prod.map_fst, Prod.map_snd, Function.comp_apply, UniformFun.toFun_ofFun, restrict_apply] protected theorem uniformity_eq : 𝓤 (α →ᵤ[𝔖] β) = ⨅ s ∈ 𝔖, ⨅ V ∈ 𝓤 β, 𝓟 (UniformOnFun.gen 𝔖 s V) := UniformOnFun.uniformity_eq_of_basis _ _ (𝓤 β).basis_sets protected theorem gen_mem_uniformity (hs : s ∈ 𝔖) {V : Set (β × β)} (hV : V ∈ 𝓤 β) : UniformOnFun.gen 𝔖 s V ∈ 𝓤 (α →ᵤ[𝔖] β) := by rw [UniformOnFun.uniformity_eq] apply_rules [mem_iInf_of_mem, mem_principal_self] /-- A version of `UniformOnFun.hasBasis_nhds_of_basis` with weaker conclusion and weaker assumptions. We make no assumptions about the set `𝔖` but conclude only that the neighbourhoods filter is equal to some indexed infimum. -/ protected theorem nhds_eq_of_basis {ι : Sort*} {p : ι → Prop} {V : ι → Set (β × β)} (h : (𝓤 β).HasBasis p V) (f : α →ᵤ[𝔖] β) : 𝓝 f = ⨅ s ∈ 𝔖, ⨅ (i) (_ : p i), 𝓟 {g | ∀ x ∈ s, (toFun 𝔖 f x, toFun 𝔖 g x) ∈ V i} := by simp_rw [nhds_eq_comap_uniformity, UniformOnFun.uniformity_eq_of_basis _ _ h, comap_iInf, comap_principal, UniformOnFun.gen, preimage_setOf_eq] protected theorem nhds_eq (f : α →ᵤ[𝔖] β) : 𝓝 f = ⨅ s ∈ 𝔖, ⨅ V ∈ 𝓤 β, 𝓟 {g | ∀ x ∈ s, (toFun 𝔖 f x, toFun 𝔖 g x) ∈ V} := UniformOnFun.nhds_eq_of_basis _ _ (𝓤 β).basis_sets f protected theorem gen_mem_nhds (f : α →ᵤ[𝔖] β) (hs : s ∈ 𝔖) {V : Set (β × β)} (hV : V ∈ 𝓤 β) : {g | ∀ x ∈ s, (toFun 𝔖 f x, toFun 𝔖 g x) ∈ V} ∈ 𝓝 f := by rw [UniformOnFun.nhds_eq] apply_rules [mem_iInf_of_mem, mem_principal_self] theorem uniformContinuous_ofUniformFun : UniformContinuous fun f : α →ᵤ β ↦ ofFun 𝔖 (UniformFun.toFun f) := by simp only [UniformContinuous, UniformOnFun.uniformity_eq, tendsto_iInf, tendsto_principal, (UniformFun.hasBasis_uniformity _ _).eventually_iff] exact fun _ _ U hU ↦ ⟨U, hU, fun f hf x _ ↦ hf x⟩ /-- The uniformity on `α →ᵤ[𝔖] β` is the same as the uniformity on `α →ᵤ β`, provided that `Set.univ ∈ 𝔖`. Here we formulate it as a `UniformEquiv`. -/ def uniformEquivUniformFun (h : univ ∈ 𝔖) : (α →ᵤ[𝔖] β) ≃ᵤ (α →ᵤ β) where toFun f := UniformFun.ofFun <| toFun _ f invFun f := ofFun _ <| UniformFun.toFun f uniformContinuous_toFun := by simp only [UniformContinuous, (UniformFun.hasBasis_uniformity _ _).tendsto_right_iff] intro U hU filter_upwards [UniformOnFun.gen_mem_uniformity _ _ h hU] with f hf x using hf x (mem_univ _) uniformContinuous_invFun := uniformContinuous_ofUniformFun _ _ /-- If `𝔖` and `𝔗` are families of sets in `α`, then the identity map `(α →ᵤ[𝔗] β) → (α →ᵤ[𝔖] β)` is uniformly continuous if every `s ∈ 𝔖` is contained in a finite union of elements of `𝔗`. With more API around `Order.Ideal`, this could be phrased in that language instead. -/ lemma uniformContinuous_ofFun_toFun (𝔗 : Set (Set α)) (h : ∀ s ∈ 𝔖, ∃ T ⊆ 𝔗, T.Finite ∧ s ⊆ ⋃₀ T) : UniformContinuous (ofFun 𝔗 ∘ toFun 𝔖 : (α →ᵤ[𝔗] β) → α →ᵤ[𝔖] β) := by simp only [UniformContinuous, UniformOnFun.uniformity_eq, iInf₂_comm (ι₂ := Set (β × β))] refine tendsto_iInf_iInf fun V ↦ tendsto_iInf_iInf fun hV ↦ ?_ simp only [tendsto_iInf, tendsto_principal, Filter.Eventually, mem_biInf_principal] intro s hs obtain ⟨T, hT𝔗, hT, hsT⟩ := h s hs refine ⟨T, hT, hT𝔗, fun f hf ↦ ?_⟩ simp only [UniformOnFun.gen, Set.mem_iInter, Set.mem_setOf_eq, Function.comp_apply] at hf ⊢ intro x hx obtain ⟨t, ht, hxt⟩ := Set.mem_sUnion.mp <| hsT hx exact hf t ht x hxt /-- Let `u₁`, `u₂` be two uniform structures on `γ` and `𝔖₁ 𝔖₂ : Set (Set α)`. If `u₁ ≤ u₂` and `𝔖₂ ⊆ 𝔖₁` then `𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂)`. -/ protected theorem mono ⦃u₁ u₂ : UniformSpace γ⦄ (hu : u₁ ≤ u₂) ⦃𝔖₁ 𝔖₂ : Set (Set α)⦄ (h𝔖 : 𝔖₂ ⊆ 𝔖₁) : 𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂) := calc 𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₁) := iInf_le_iInf_of_subset h𝔖 _ ≤ 𝒱(α, γ, 𝔖₂, u₂) := iInf₂_mono fun _i _hi => UniformSpace.comap_mono <| UniformFun.mono hu /-- If `x : α` is in some `S ∈ 𝔖`, then evaluation at `x` is uniformly continuous on `α →ᵤ[𝔖] β`. -/ theorem uniformContinuous_eval_of_mem {x : α} (hxs : x ∈ s) (hs : s ∈ 𝔖) : UniformContinuous ((Function.eval x : (α → β) → β) ∘ toFun 𝔖) := (UniformFun.uniformContinuous_eval β (⟨x, hxs⟩ : s)).comp (UniformOnFun.uniformContinuous_restrict α β 𝔖 hs) theorem uniformContinuous_eval_of_mem_sUnion {x : α} (hx : x ∈ ⋃₀ 𝔖) : UniformContinuous ((Function.eval x : (α → β) → β) ∘ toFun 𝔖) := let ⟨_s, hs, hxs⟩ := hx uniformContinuous_eval_of_mem _ _ hxs hs variable {β} {𝔖} theorem uniformContinuous_eval (h : ⋃₀ 𝔖 = univ) (x : α) : UniformContinuous ((Function.eval x : (α → β) → β) ∘ toFun 𝔖) := uniformContinuous_eval_of_mem_sUnion _ _ <| h.symm ▸ mem_univ _ /-- If `u` is a family of uniform structures on `γ`, then `𝒱(α, γ, 𝔖, (⨅ i, u i)) = ⨅ i, 𝒱(α, γ, 𝔖, u i)`. -/ protected theorem iInf_eq {u : ι → UniformSpace γ} : 𝒱(α, γ, 𝔖, ⨅ i, u i) = ⨅ i, 𝒱(α, γ, 𝔖, u i) := by simp_rw [UniformOnFun.uniformSpace, UniformFun.iInf_eq, UniformSpace.comap_iInf] rw [iInf_comm] exact iInf_congr fun s => iInf_comm /-- If `u₁` and `u₂` are two uniform structures on `γ`, then `𝒱(α, γ, 𝔖, u₁ ⊓ u₂) = 𝒱(α, γ, 𝔖, u₁) ⊓ 𝒱(α, γ, 𝔖, u₂)`. -/ protected theorem inf_eq {u₁ u₂ : UniformSpace γ} : 𝒱(α, γ, 𝔖, u₁ ⊓ u₂) = 𝒱(α, γ, 𝔖, u₁) ⊓ 𝒱(α, γ, 𝔖, u₂) := by rw [inf_eq_iInf, inf_eq_iInf, UniformOnFun.iInf_eq] refine iInf_congr fun i => ?_ cases i <;> rfl /-- If `u` is a uniform structure on `β` and `f : γ → β`, then `𝒱(α, γ, 𝔖, comap f u) = comap (fun g ↦ f ∘ g) 𝒱(α, γ, 𝔖, u₁)`. -/ protected theorem comap_eq {f : γ → β} : 𝒱(α, γ, 𝔖, ‹UniformSpace β›.comap f) = 𝒱(α, β, 𝔖, _).comap (f ∘ ·) := by -- We reduce this to `UniformFun.comap_eq` using the fact that `comap` distributes -- on `iInf`. simp_rw [UniformOnFun.uniformSpace, UniformSpace.comap_iInf, UniformFun.comap_eq, ← UniformSpace.comap_comap] -- By definition, `∀ S ∈ 𝔖, (f ∘ —) ∘ S.restrict = S.restrict ∘ (f ∘ —)`. rfl /-- Post-composition by a uniformly continuous function is uniformly continuous for the uniform structures of `𝔖`-convergence. More precisely, if `f : γ → β` is uniformly continuous, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is uniformly continuous. -/ protected theorem postcomp_uniformContinuous [UniformSpace γ] {f : γ → β} (hf : UniformContinuous f) : UniformContinuous (ofFun 𝔖 ∘ (f ∘ ·) ∘ toFun 𝔖) := by -- This is a direct consequence of `UniformOnFun.comap_eq` rw [uniformContinuous_iff] exact (UniformOnFun.mono (uniformContinuous_iff.mp hf) subset_rfl).trans_eq UniformOnFun.comap_eq /-- Post-composition by a uniform inducing is a uniform inducing for the uniform structures of `𝔖`-convergence. More precisely, if `f : γ → β` is a uniform inducing, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is a uniform inducing. -/ lemma postcomp_isUniformInducing [UniformSpace γ] {f : γ → β} (hf : IsUniformInducing f) : IsUniformInducing (ofFun 𝔖 ∘ (f ∘ ·) ∘ toFun 𝔖) := by -- This is a direct consequence of `UniformOnFun.comap_eq` constructor replace hf : (𝓤 β).comap (Prod.map f f) = _ := hf.comap_uniformity change comap (Prod.map (ofFun 𝔖 ∘ (f ∘ ·) ∘ toFun 𝔖) (ofFun 𝔖 ∘ (f ∘ ·) ∘ toFun 𝔖)) _ = _ rw [← uniformity_comap] at hf ⊢ congr rw [← UniformSpace.ext hf, UniformOnFun.comap_eq] rfl /-- Post-composition by a uniform embedding is a uniform embedding for the uniform structures of `𝔖`-convergence. More precisely, if `f : γ → β` is a uniform embedding, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is a uniform embedding. -/ protected theorem postcomp_isUniformEmbedding [UniformSpace γ] {f : γ → β} (hf : IsUniformEmbedding f) : IsUniformEmbedding (ofFun 𝔖 ∘ (f ∘ ·) ∘ toFun 𝔖) where toIsUniformInducing := UniformOnFun.postcomp_isUniformInducing hf.isUniformInducing injective _ _ H := funext fun _ ↦ hf.injective (congrFun H _) /-- Turn a uniform isomorphism `γ ≃ᵤ β` into a uniform isomorphism `(α →ᵤ[𝔖] γ) ≃ᵤ (α →ᵤ[𝔖] β)` by post-composing. -/ protected def congrRight [UniformSpace γ] (e : γ ≃ᵤ β) : (α →ᵤ[𝔖] γ) ≃ᵤ (α →ᵤ[𝔖] β) := { Equiv.piCongrRight fun _a => e.toEquiv with uniformContinuous_toFun := UniformOnFun.postcomp_uniformContinuous e.uniformContinuous uniformContinuous_invFun := UniformOnFun.postcomp_uniformContinuous e.symm.uniformContinuous } /-- Let `f : γ → α`, `𝔖 : Set (Set α)`, `𝔗 : Set (Set γ)`, and assume that `∀ T ∈ 𝔗, f '' T ∈ 𝔖`. Then, the function `(fun g ↦ g ∘ f) : (α →ᵤ[𝔖] β) → (γ →ᵤ[𝔗] β)` is uniformly continuous. Note that one can easily see that assuming `∀ T ∈ 𝔗, ∃ S ∈ 𝔖, f '' T ⊆ S` would work too, but we will get this for free when we prove that `𝒱(α, β, 𝔖, uβ) = 𝒱(α, β, 𝔖', uβ)` where `𝔖'` is the ***noncovering*** bornology generated by `𝔖`. -/ protected theorem precomp_uniformContinuous {𝔗 : Set (Set γ)} {f : γ → α} (hf : MapsTo (f '' ·) 𝔗 𝔖) : UniformContinuous fun g : α →ᵤ[𝔖] β => ofFun 𝔗 (toFun 𝔖 g ∘ f) := by -- This follows from the fact that `(· ∘ f) × (· ∘ f)` maps `gen (f '' t) V` to `gen t V`. simp_rw [UniformContinuous, UniformOnFun.uniformity_eq, tendsto_iInf] refine fun t ht V hV ↦ tendsto_iInf' (f '' t) <| tendsto_iInf' (hf ht) <| tendsto_iInf' V <| tendsto_iInf' hV ?_ simpa only [tendsto_principal_principal, UniformOnFun.gen] using fun _ ↦ forall_mem_image.1 /-- Turn a bijection `e : γ ≃ α` such that we have both `∀ T ∈ 𝔗, e '' T ∈ 𝔖` and `∀ S ∈ 𝔖, e ⁻¹' S ∈ 𝔗` into a uniform isomorphism `(γ →ᵤ[𝔗] β) ≃ᵤ (α →ᵤ[𝔖] β)` by pre-composing. -/ protected def congrLeft {𝔗 : Set (Set γ)} (e : γ ≃ α) (he : 𝔗 ⊆ image e ⁻¹' 𝔖) (he' : 𝔖 ⊆ preimage e ⁻¹' 𝔗) : (γ →ᵤ[𝔗] β) ≃ᵤ (α →ᵤ[𝔖] β) := { Equiv.arrowCongr e (Equiv.refl _) with uniformContinuous_toFun := UniformOnFun.precomp_uniformContinuous fun s hs ↦ by change e.symm '' s ∈ 𝔗 rw [Equiv.image_symm_eq_preimage] exact he' hs uniformContinuous_invFun := UniformOnFun.precomp_uniformContinuous he } /-- If `𝔖` covers `α`, then the topology of `𝔖`-convergence is T₂. -/ theorem t2Space_of_covering [T2Space β] (h : ⋃₀ 𝔖 = univ) : T2Space (α →ᵤ[𝔖] β) where t2 f g hfg := by obtain ⟨x, hx⟩ := not_forall.mp (mt funext hfg) obtain ⟨s, hs, hxs⟩ : ∃ s ∈ 𝔖, x ∈ s := mem_sUnion.mp (h.symm ▸ True.intro) exact separated_by_continuous (uniformContinuous_eval_of_mem β 𝔖 hxs hs).continuous hx /-- The restriction map from `α →ᵤ[𝔖] β` to `⋃₀ 𝔖 → β` is uniformly continuous. -/ theorem uniformContinuous_restrict_toFun : UniformContinuous ((⋃₀ 𝔖).restrict ∘ toFun 𝔖 : (α →ᵤ[𝔖] β) → ⋃₀ 𝔖 → β) := by rw [uniformContinuous_pi] intro ⟨x, hx⟩ obtain ⟨s : Set α, hs : s ∈ 𝔖, hxs : x ∈ s⟩ := mem_sUnion.mpr hx exact uniformContinuous_eval_of_mem β 𝔖 hxs hs /-- The map sending a function `f : α →ᵤ[𝔖] β` to the family of restrictions of `f` to each `s ∈ 𝔖` (each coordinate equipped with its respective uniform structure `s →ᵤ β`) induces the uniformity on `α →ᵤ[𝔖] β`. -/ lemma isUniformInducing_pi_restrict : IsUniformInducing (fun f : α →ᵤ[𝔖] β ↦ fun s : 𝔖 ↦ UniformFun.ofFun ((s : Set α).restrict (toFun 𝔖 f))) := by simp_rw [isUniformInducing_iff_uniformSpace, Pi.uniformSpace_eq, UniformSpace.comap_iInf, ← UniformSpace.comap_comap, iInf_subtype] rfl /-- If `𝔖` covers `α`, the natural map `UniformOnFun.toFun` from `α →ᵤ[𝔖] β` to `α → β` is uniformly continuous. In other words, if `𝔖` covers `α`, then the uniform structure of `𝔖`-convergence is finer than that of pointwise convergence. -/ protected theorem uniformContinuous_toFun (h : ⋃₀ 𝔖 = univ) : UniformContinuous (toFun 𝔖 : (α →ᵤ[𝔖] β) → α → β) := by rw [uniformContinuous_pi] exact uniformContinuous_eval h /-- If `f : α →ᵤ[𝔖] β` is continuous at `x` and `x` admits a neighbourhood `V ∈ 𝔖`, then evaluation of `g : α →ᵤ[𝔖] β` at `y : α` is continuous in `(g, y)` at `(f, x)`. -/ protected theorem continuousAt_eval₂ [TopologicalSpace α] {f : α →ᵤ[𝔖] β} {x : α} (h𝔖 : ∃ V ∈ 𝔖, V ∈ 𝓝 x) (hc : ContinuousAt (toFun 𝔖 f) x) : ContinuousAt (fun fx : (α →ᵤ[𝔖] β) × α ↦ toFun 𝔖 fx.1 fx.2) (f, x) := by rw [ContinuousAt, nhds_eq_comap_uniformity, tendsto_comap_iff, ← lift'_comp_uniformity, tendsto_lift'] intro U hU rcases h𝔖 with ⟨V, hV, hVx⟩ filter_upwards [prod_mem_nhds (UniformOnFun.gen_mem_nhds _ _ _ hV hU) (inter_mem hVx <| hc <| UniformSpace.ball_mem_nhds _ hU)] with ⟨g, y⟩ ⟨hg, hyV, hy⟩ using ⟨toFun 𝔖 f y, hy, hg y hyV⟩ /-- If each point of `α` admits a neighbourhood `V ∈ 𝔖`, then the evaluation of `f : α →ᵤ[𝔖] β` at `x : α` is continuous in `(f, x)` on the set of `(f, x)` such that `f` is continuous at `x`. -/ protected theorem continuousOn_eval₂ [TopologicalSpace α] (h𝔖 : ∀ x, ∃ V ∈ 𝔖, V ∈ 𝓝 x) : ContinuousOn (fun fx : (α →ᵤ[𝔖] β) × α ↦ toFun 𝔖 fx.1 fx.2) {fx | ContinuousAt (toFun 𝔖 fx.1) fx.2} := fun (_f, x) hc ↦ (UniformOnFun.continuousAt_eval₂ (h𝔖 x) hc).continuousWithinAt /-- Convergence in the topology of `𝔖`-convergence means uniform convergence on `S` (in the sense of `TendstoUniformlyOn`) for all `S ∈ 𝔖`. -/ protected theorem tendsto_iff_tendstoUniformlyOn {F : ι → α →ᵤ[𝔖] β} {f : α →ᵤ[𝔖] β} : Tendsto F p (𝓝 f) ↔ ∀ s ∈ 𝔖, TendstoUniformlyOn (toFun 𝔖 ∘ F) (toFun 𝔖 f) p s := by simp only [UniformOnFun.nhds_eq, tendsto_iInf, tendsto_principal, TendstoUniformlyOn, Function.comp_apply, mem_setOf] protected lemma continuous_rng_iff {X : Type*} [TopologicalSpace X] {f : X → (α →ᵤ[𝔖] β)} : Continuous f ↔ ∀ s ∈ 𝔖, Continuous (UniformFun.ofFun ∘ s.restrict ∘ UniformOnFun.toFun 𝔖 ∘ f) := by simp only [continuous_iff_continuousAt, ContinuousAt, UniformOnFun.tendsto_iff_tendstoUniformlyOn, UniformFun.tendsto_iff_tendstoUniformly, tendstoUniformlyOn_iff_tendstoUniformly_comp_coe, @forall_swap X, Function.comp_def, restrict_eq, UniformFun.toFun_ofFun] instance [CompleteSpace β] : CompleteSpace (α →ᵤ[𝔖] β) := by rcases isEmpty_or_nonempty β · infer_instance · refine ⟨fun {F} hF ↦ ?_⟩ have := hF.1 have : ∀ x ∈ ⋃₀ 𝔖, ∃ y : β, Tendsto (toFun 𝔖 · x) F (𝓝 y) := fun x hx ↦ CompleteSpace.complete (hF.map (uniformContinuous_eval_of_mem_sUnion _ _ hx)) choose! g hg using this use ofFun 𝔖 g simp_rw [UniformOnFun.nhds_eq_of_basis _ _ uniformity_hasBasis_closed, le_iInf₂_iff, le_principal_iff] intro s hs U ⟨hU, hUc⟩ rcases cauchy_iff.mp hF |>.2 _ <| UniformOnFun.gen_mem_uniformity _ _ hs hU with ⟨V, hV, hVU⟩ filter_upwards [hV] with f hf x hx refine hUc.mem_of_tendsto ((hg x ⟨s, hs, hx⟩).prodMk_nhds tendsto_const_nhds) ?_ filter_upwards [hV] with g' hg' using hVU (mk_mem_prod hg' hf) _ hx /-- The natural bijection between `α → β × γ` and `(α → β) × (α → γ)`, upgraded to a uniform isomorphism between `α →ᵤ[𝔖] β × γ` and `(α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] γ)`. -/ protected def uniformEquivProdArrow [UniformSpace γ] : (α →ᵤ[𝔖] β × γ) ≃ᵤ (α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] γ) := -- Denote `φ` this bijection. We want to show that -- `comap φ (𝒱(α, β, 𝔖, uβ) × 𝒱(α, γ, 𝔖, uγ)) = 𝒱(α, β × γ, 𝔖, uβ × uγ)`. -- But `uβ × uγ` is defined as `comap fst uβ ⊓ comap snd uγ`, so we just have to apply -- `UniformOnFun.inf_eq` and `UniformOnFun.comap_eq`, -- which leaves us to check that some square commutes. -- We could also deduce this from `UniformFun.uniformEquivProdArrow`, -- but it turns out to be more annoying. ((UniformOnFun.ofFun 𝔖).symm.trans <| (Equiv.arrowProdEquivProdArrow _ _ _).trans <| (UniformOnFun.ofFun 𝔖).prodCongr (UniformOnFun.ofFun 𝔖)).toUniformEquivOfIsUniformInducing <| by constructor rw [uniformity_prod, comap_inf, comap_comap, comap_comap] have H := @UniformOnFun.inf_eq α (β × γ) 𝔖 (UniformSpace.comap Prod.fst ‹_›) (UniformSpace.comap Prod.snd ‹_›) apply_fun (fun u ↦ @uniformity (α →ᵤ[𝔖] β × γ) u) at H convert H.symm using 1 rw [UniformOnFun.comap_eq, UniformOnFun.comap_eq] erw [inf_uniformity] rw [uniformity_comap, uniformity_comap] rfl -- the relevant diagram commutes by definition variable (𝔖) (δ : ι → Type*) [∀ i, UniformSpace (δ i)] in /-- The natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `α →ᵤ[𝔖] (Π i, δ i)` and `Π i, α →ᵤ[𝔖] δ i`. -/ protected def uniformEquivPiComm : (α →ᵤ[𝔖] ((i : ι) → δ i)) ≃ᵤ ((i : ι) → α →ᵤ[𝔖] δ i) := -- Denote `φ` this bijection. We want to show that -- `comap φ (Π i, 𝒱(α, δ i, 𝔖, uδ i)) = 𝒱(α, (Π i, δ i), 𝔖, (Π i, uδ i))`. -- But `Π i, uδ i` is defined as `⨅ i, comap (eval i) (uδ i)`, so we just have to apply -- `UniformOnFun.iInf_eq` and `UniformOnFun.comap_eq`, -- which leaves us to check that some square commutes. -- We could also deduce this from `UniformFun.uniformEquivPiComm`, but it turns out -- to be more annoying. @Equiv.toUniformEquivOfIsUniformInducing (α →ᵤ[𝔖] ((i : ι) → δ i)) ((i : ι) → α →ᵤ[𝔖] δ i) _ _ (Equiv.piComm _) <| by constructor change comap (Prod.map Function.swap Function.swap) _ = _ erw [← uniformity_comap] congr rw [Pi.uniformSpace, UniformSpace.ofCoreEq_toCore, Pi.uniformSpace, UniformSpace.ofCoreEq_toCore, UniformSpace.comap_iInf, UniformOnFun.iInf_eq] refine iInf_congr fun i => ?_ rw [← UniformSpace.comap_comap, UniformOnFun.comap_eq] rfl -- Like in the previous lemma, the diagram actually commutes by definition /-- Suppose that the topology on `α` is defined by its restrictions to the sets of `𝔖`. Then the set of continuous functions is closed in the topology of uniform convergence on the sets of `𝔖`. -/ theorem isClosed_setOf_continuous [TopologicalSpace α] (h : IsCoherentWith 𝔖) : IsClosed {f : α →ᵤ[𝔖] β | Continuous (toFun 𝔖 f)} := by refine isClosed_iff_forall_filter.2 fun f u _ hu huf ↦ h.continuous_iff.2 fun s hs ↦ ?_ rw [← tendsto_id', UniformOnFun.tendsto_iff_tendstoUniformlyOn] at huf exact (huf s hs).continuousOn <| hu fun _ ↦ Continuous.continuousOn variable (𝔖) in theorem uniformSpace_eq_inf_precomp_of_cover {δ₁ δ₂ : Type*} (φ₁ : δ₁ → α) (φ₂ : δ₂ → α) (𝔗₁ : Set (Set δ₁)) (𝔗₂ : Set (Set δ₂)) (h_image₁ : MapsTo (φ₁ '' ·) 𝔗₁ 𝔖) (h_image₂ : MapsTo (φ₂ '' ·) 𝔗₂ 𝔖) (h_preimage₁ : MapsTo (φ₁ ⁻¹' ·) 𝔖 𝔗₁) (h_preimage₂ : MapsTo (φ₂ ⁻¹' ·) 𝔖 𝔗₂) (h_cover : ∀ S ∈ 𝔖, S ⊆ range φ₁ ∪ range φ₂) : 𝒱(α, β, 𝔖, _) = .comap (ofFun 𝔗₁ ∘ (· ∘ φ₁) ∘ toFun 𝔖) 𝒱(δ₁, β, 𝔗₁, _) ⊓ .comap (ofFun 𝔗₂ ∘ (· ∘ φ₂) ∘ toFun 𝔖) 𝒱(δ₂, β, 𝔗₂, _) := by set ψ₁ : Π S : Set α, φ₁ ⁻¹' S → S := fun S ↦ S.restrictPreimage φ₁ set ψ₂ : Π S : Set α, φ₂ ⁻¹' S → S := fun S ↦ S.restrictPreimage φ₂ have : ∀ S ∈ 𝔖, 𝒰(S, β, _) = .comap (· ∘ ψ₁ S) 𝒰(_, β, _) ⊓ .comap (· ∘ ψ₂ S) 𝒰(_, β, _) := by refine fun S hS ↦ UniformFun.uniformSpace_eq_inf_precomp_of_cover β _ _ ?_ simpa only [← univ_subset_iff, ψ₁, ψ₂, range_restrictPreimage, ← preimage_union, ← image_subset_iff, image_univ, Subtype.range_val] using h_cover S hS refine le_antisymm (le_inf ?_ ?_) (le_iInf₂ fun S hS ↦ ?_) · rw [← uniformContinuous_iff] exact UniformOnFun.precomp_uniformContinuous h_image₁ · rw [← uniformContinuous_iff] exact UniformOnFun.precomp_uniformContinuous h_image₂ · simp_rw [this S hS, uniformSpace, UniformSpace.comap_iInf, UniformSpace.comap_inf, ← UniformSpace.comap_comap] exact inf_le_inf (iInf₂_le_of_le _ (h_preimage₁ hS) le_rfl) (iInf₂_le_of_le _ (h_preimage₂ hS) le_rfl) variable (𝔖) in theorem uniformSpace_eq_iInf_precomp_of_cover {δ : ι → Type*} (φ : Π i, δ i → α) (𝔗 : ∀ i, Set (Set (δ i))) (h_image : ∀ i, MapsTo (φ i '' ·) (𝔗 i) 𝔖) (h_preimage : ∀ i, MapsTo (φ i ⁻¹' ·) 𝔖 (𝔗 i)) (h_cover : ∀ S ∈ 𝔖, ∃ I : Set ι, I.Finite ∧ S ⊆ ⋃ i ∈ I, range (φ i)) : 𝒱(α, β, 𝔖, _) = ⨅ i, .comap (ofFun (𝔗 i) ∘ (· ∘ φ i) ∘ toFun 𝔖) 𝒱(δ i, β, 𝔗 i, _) := by set ψ : Π S : Set α, Π i : ι, (φ i) ⁻¹' S → S := fun S i ↦ S.restrictPreimage (φ i) have : ∀ S ∈ 𝔖, 𝒰(S, β, _) = ⨅ i, .comap (· ∘ ψ S i) 𝒰(_, β, _) := fun S hS ↦ by rcases h_cover S hS with ⟨I, I_finite, I_cover⟩ refine UniformFun.uniformSpace_eq_iInf_precomp_of_cover β _ ⟨I, I_finite, ?_⟩ simpa only [← univ_subset_iff, ψ, range_restrictPreimage, ← preimage_iUnion₂, ← image_subset_iff, image_univ, Subtype.range_val] using I_cover -- With a better theory of ideals we may be able to simplify the following by replacing `𝔗 i` -- by `(φ i ⁻¹' ·) '' 𝔖`. refine le_antisymm (le_iInf fun i ↦ ?_) (le_iInf₂ fun S hS ↦ ?_) · rw [← uniformContinuous_iff] exact UniformOnFun.precomp_uniformContinuous (h_image i) · simp_rw [this S hS, uniformSpace, UniformSpace.comap_iInf, ← UniformSpace.comap_comap] exact iInf_mono fun i ↦ iInf₂_le_of_le _ (h_preimage i hS) le_rfl end UniformOnFun namespace UniformFun instance {α β : Type*} [UniformSpace β] [CompleteSpace β] : CompleteSpace (α →ᵤ β) := (UniformOnFun.uniformEquivUniformFun β {univ} (mem_singleton _)).completeSpace_iff.1 inferInstance end UniformFun section UniformComposition variable {α β γ ι : Type*} [UniformSpace β] [UniformSpace γ] {p : Filter ι} {s : Set β} {F : ι → α → β} {f : α → β} {g : β → γ} /-- Composing on the left by a uniformly continuous function preserves uniform convergence -/ theorem UniformContinuousOn.comp_tendstoUniformly (hF : ∀ i x, F i x ∈ s) (hf : ∀ x, f x ∈ s) (hg : UniformContinuousOn g s) (h : TendstoUniformly F f p) : TendstoUniformly (fun i x => g (F i x)) (fun x => g (f x)) p := by rw [uniformContinuousOn_iff_restrict] at hg lift F to ι → α → s using hF with F' hF' lift f to α → s using hf with f' hf' rw [tendstoUniformly_iff_tendsto] at h have : Tendsto (fun q ↦ (f' q.2, F' q.1 q.2)) (p ×ˢ ⊤) (𝓤 s) := h.of_tendsto_comp isUniformEmbedding_subtype_val.comap_uniformity.le apply UniformContinuous.comp_tendstoUniformly hg ?_ rwa [← tendstoUniformly_iff_tendsto] at this theorem UniformContinuousOn.comp_tendstoUniformly_eventually (hF : ∀ᶠ i in p, ∀ x, F i x ∈ s) (hf : ∀ x, f x ∈ s) (hg : UniformContinuousOn g s) (h : TendstoUniformly F f p) : TendstoUniformly (fun i x ↦ g (F i x)) (fun x ↦ g (f x)) p := by classical obtain ⟨s', hs', hs⟩ := eventually_iff_exists_mem.mp hF let F' : ι → α → β := fun i x => if i ∈ s' then F i x else f x have hF : F =ᶠ[p] F' := by rw [eventuallyEq_iff_exists_mem] refine ⟨s', hs', fun y hy => by aesop⟩ have h' : TendstoUniformly F' f p := by rwa [tendstoUniformly_congr hF] at h apply (tendstoUniformly_congr _).mpr (UniformContinuousOn.comp_tendstoUniformly (by aesop) hf hg h') rw [eventuallyEq_iff_exists_mem] refine ⟨s', hs', fun i hi => by aesop⟩ theorem UniformContinuousOn.comp_tendstoUniformlyOn_eventually {t : Set α} (hF : ∀ᶠ i in p, ∀ x ∈ t, F i x ∈ s) (hf : ∀ x ∈ t, f x ∈ s) {g : β → γ} (hg : UniformContinuousOn g s) (h : TendstoUniformlyOn F f p t) : TendstoUniformlyOn (fun i x ↦ g (F i x)) (fun x => g (f x)) p t := by rw [tendstoUniformlyOn_iff_restrict] apply UniformContinuousOn.comp_tendstoUniformly_eventually (by simpa using hF) (by simpa using hf) hg (tendstoUniformlyOn_iff_restrict.mp h) end UniformComposition
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/AbstractCompletion.lean
import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Topology.UniformSpace.Equiv /-! # Abstract theory of Hausdorff completions of uniform spaces This file characterizes Hausdorff completions of a uniform space α as complete Hausdorff spaces equipped with a map from α which has dense image and induce the original uniform structure on α. Assuming these properties we "extend" uniformly continuous maps from α to complete Hausdorff spaces to the completions of α. This is the universal property expected from a completion. It is then used to extend uniformly continuous maps from α to α' to maps between completions of α and α'. This file does not construct any such completion, it only study consequences of their existence. The first advantage is that formal properties are clearly highlighted without interference from construction details. The second advantage is that this framework can then be used to compare different completion constructions. See `Topology/UniformSpace/CompareReals` for an example. Of course the comparison comes from the universal property as usual. A general explicit construction of completions is done in `UniformSpace/Completion`, leading to a functor from uniform spaces to complete Hausdorff uniform spaces that is left adjoint to the inclusion, see `UniformSpace/UniformSpaceCat` for the category packaging. ## Implementation notes A tiny technical advantage of using a characteristic predicate such as the properties listed in `AbstractCompletion` instead of stating the universal property is that the universal property derived from the predicate is more universe polymorphic. ## References We don't know any traditional text discussing this. Real world mathematics simply silently identify the results of any two constructions that lead to something one could reasonably call a completion. ## Tags uniform spaces, completion, universal property -/ noncomputable section open Filter Set Function /-- A completion of `α` is the data of a complete separated uniform space and a map from `α` with dense range and inducing the original uniform structure on `α`. -/ @[pp_with_univ] structure AbstractCompletion.{v, u} (α : Type u) [UniformSpace α] where /-- The underlying space of the completion. -/ space : Type v /-- A map from a space to its completion. -/ coe : α → space /-- The completion carries a uniform structure. -/ uniformStruct : UniformSpace space /-- The completion is complete. -/ complete : CompleteSpace space /-- The completion is a T₀ space. -/ separation : T0Space space /-- The map into the completion is uniform-inducing. -/ isUniformInducing : IsUniformInducing coe /-- The map into the completion has dense range. -/ dense : DenseRange coe attribute [local instance] AbstractCompletion.uniformStruct AbstractCompletion.complete AbstractCompletion.separation namespace AbstractCompletion universe uα vα vα' uβ vβ uγ vγ variable {α : Type uα} [UniformSpace α] (pkg : AbstractCompletion.{vα} α) local notation "hatα" => pkg.space local notation "ι" => pkg.coe /-- If `α` is complete, then it is an abstract completion of itself. -/ def ofComplete [T0Space α] [CompleteSpace α] : AbstractCompletion α := mk α id inferInstance inferInstance inferInstance .id denseRange_id theorem closure_range : closure (range ι) = univ := pkg.dense.closure_range theorem isDenseInducing : IsDenseInducing ι := ⟨pkg.isUniformInducing.isInducing, pkg.dense⟩ theorem uniformContinuous_coe : UniformContinuous ι := IsUniformInducing.uniformContinuous pkg.isUniformInducing theorem continuous_coe : Continuous ι := pkg.uniformContinuous_coe.continuous @[elab_as_elim] theorem induction_on {p : hatα → Prop} (a : hatα) (hp : IsClosed { a | p a }) (ih : ∀ a, p (ι a)) : p a := isClosed_property pkg.dense hp ih a variable {β : Type uβ} protected theorem funext [TopologicalSpace β] [T2Space β] {f g : hatα → β} (hf : Continuous f) (hg : Continuous g) (h : ∀ a, f (ι a) = g (ι a)) : f = g := funext fun a => pkg.induction_on a (isClosed_eq hf hg) h variable [UniformSpace β] section Extend /-- Extension of maps to completions -/ protected def extend (f : α → β) : hatα → β := open scoped Classical in if UniformContinuous f then pkg.isDenseInducing.extend f else fun x => f (pkg.dense.some x) variable {f : α → β} theorem extend_def (hf : UniformContinuous f) : pkg.extend f = pkg.isDenseInducing.extend f := if_pos hf theorem inseparable_extend_coe (hf : UniformContinuous f) (x : α) : Inseparable (pkg.extend f (ι x)) (f x) := by rw [extend_def _ hf] exact pkg.isDenseInducing.inseparable_extend hf.continuous.continuousAt theorem extend_coe [T2Space β] (hf : UniformContinuous f) (a : α) : (pkg.extend f) (ι a) = f a := by rw [pkg.extend_def hf] exact pkg.isDenseInducing.extend_eq hf.continuous a variable [CompleteSpace β] theorem uniformContinuous_extend : UniformContinuous (pkg.extend f) := by by_cases hf : UniformContinuous f · rw [pkg.extend_def hf] exact uniformContinuous_uniformly_extend pkg.isUniformInducing pkg.dense hf · unfold AbstractCompletion.extend rw [if_neg hf] exact uniformContinuous_of_const fun a b => by congr 1 theorem continuous_extend : Continuous (pkg.extend f) := pkg.uniformContinuous_extend.continuous lemma isUniformInducing_extend (h : IsUniformInducing f) : IsUniformInducing (pkg.extend f) := by rw [extend_def _ h.uniformContinuous] exact pkg.isDenseInducing.isUniformInducing_extend pkg.isUniformInducing h variable [T0Space β] theorem extend_unique (hf : UniformContinuous f) {g : hatα → β} (hg : UniformContinuous g) (h : ∀ a : α, f a = g (ι a)) : pkg.extend f = g := by apply pkg.funext pkg.continuous_extend hg.continuous simpa only [pkg.extend_coe hf] using h @[simp] theorem extend_comp_coe {f : hatα → β} (hf : UniformContinuous f) : pkg.extend (f ∘ ι) = f := funext fun x => pkg.induction_on x (isClosed_eq pkg.continuous_extend hf.continuous) fun y => pkg.extend_coe (hf.comp <| pkg.uniformContinuous_coe) y end Extend section MapSec variable (pkg' : AbstractCompletion.{vβ} β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe /-- Lifting maps to completions -/ protected def map (f : α → β) : hatα → hatβ := pkg.extend (ι' ∘ f) local notation "map" => pkg.map pkg' variable (f : α → β) theorem uniformContinuous_map : UniformContinuous (map f) := pkg.uniformContinuous_extend @[continuity] theorem continuous_map : Continuous (map f) := pkg.continuous_extend variable {f} @[simp] theorem map_coe (hf : UniformContinuous f) (a : α) : map f (ι a) = ι' (f a) := pkg.extend_coe (pkg'.uniformContinuous_coe.comp hf) a theorem map_unique {f : α → β} {g : hatα → hatβ} (hg : UniformContinuous g) (h : ∀ a, ι' (f a) = g (ι a)) : map f = g := pkg.funext (pkg.continuous_map _ _) hg.continuous <| by intro a change pkg.extend (ι' ∘ f) _ = _ simp_rw [Function.comp_def, h, ← comp_apply (f := g)] rw [pkg.extend_coe (hg.comp pkg.uniformContinuous_coe)] @[simp] theorem map_id : pkg.map pkg id = id := pkg.map_unique pkg uniformContinuous_id fun _ => rfl variable {γ : Type uγ} [UniformSpace γ] theorem extend_map [CompleteSpace γ] [T0Space γ] {f : β → γ} {g : α → β} (hf : UniformContinuous f) (hg : UniformContinuous g) : pkg'.extend f ∘ map g = pkg.extend (f ∘ g) := pkg.funext (pkg'.continuous_extend.comp (pkg.continuous_map pkg' _)) pkg.continuous_extend fun a => by rw [pkg.extend_coe (hf.comp hg), comp_apply, pkg.map_coe pkg' hg, pkg'.extend_coe hf] rfl variable (pkg'' : AbstractCompletion.{vγ} γ) theorem map_comp {g : β → γ} {f : α → β} (hg : UniformContinuous g) (hf : UniformContinuous f) : pkg'.map pkg'' g ∘ pkg.map pkg' f = pkg.map pkg'' (g ∘ f) := pkg.extend_map pkg' (pkg''.uniformContinuous_coe.comp hg) hf /-- The uniform isomorphism between two completions of isomorphic uniform spaces. -/ def mapEquiv (e : α ≃ᵤ β) : hatα ≃ᵤ hatβ where toFun := pkg.map pkg' e invFun := pkg'.map pkg e.symm uniformContinuous_toFun := uniformContinuous_map .. uniformContinuous_invFun := uniformContinuous_map .. left_inv := Function.leftInverse_iff_comp.2 <| by simp [map_comp _ _ _ e.symm.uniformContinuous e.uniformContinuous] right_inv := Function.rightInverse_iff_comp.2 <| by simp [map_comp _ _ _ e.uniformContinuous e.symm.uniformContinuous] @[simp] theorem mapEquiv_symm (e : α ≃ᵤ β) : (pkg.mapEquiv pkg' e).symm = pkg'.mapEquiv pkg e.symm := rfl @[simp] theorem mapEquiv_coe (e : α ≃ᵤ β) (a : α) : pkg.mapEquiv pkg' e (ι a) = ι' (e a) := pkg.map_coe pkg' e.uniformContinuous _ end MapSec section Compare -- We can now compare two completion packages for the same uniform space variable (pkg' : AbstractCompletion.{vα'} α) /-- The comparison map between two completions of the same uniform space. -/ def compare : pkg.space → pkg'.space := pkg.extend pkg'.coe theorem uniformContinuous_compare : UniformContinuous (pkg.compare pkg') := pkg.uniformContinuous_extend theorem compare_coe (a : α) : pkg.compare pkg' (pkg.coe a) = pkg'.coe a := pkg.extend_coe pkg'.uniformContinuous_coe a theorem inverse_compare : pkg.compare pkg' ∘ pkg'.compare pkg = id := by have uc := pkg.uniformContinuous_compare pkg' have uc' := pkg'.uniformContinuous_compare pkg apply pkg'.funext (uc.comp uc').continuous continuous_id intro a rw [comp_apply, pkg'.compare_coe pkg, pkg.compare_coe pkg'] rfl /-- The uniform bijection between two completions of the same uniform space. -/ def compareEquiv : pkg.space ≃ᵤ pkg'.space where toFun := pkg.compare pkg' invFun := pkg'.compare pkg left_inv := congr_fun (pkg'.inverse_compare pkg) right_inv := congr_fun (pkg.inverse_compare pkg') uniformContinuous_toFun := uniformContinuous_compare _ _ uniformContinuous_invFun := uniformContinuous_compare _ _ theorem uniformContinuous_compareEquiv : UniformContinuous (pkg.compareEquiv pkg') := pkg.uniformContinuous_compare pkg' theorem uniformContinuous_compareEquiv_symm : UniformContinuous (pkg.compareEquiv pkg').symm := pkg'.uniformContinuous_compare pkg open scoped Topology /-Let `f : α → γ` be a continuous function between a uniform space `α` and a regular topological space `γ`, and let `pkg, pkg'` be two abstract completions of `α`. Then if for every point `a : pkg` the filter `f.map (coe⁻¹ (𝓝 a))` obtained by pushing forward with `f` the preimage in `α` of `𝓝 a` tends to `𝓝 (f.extend a : β)`, then the comparison map between `pkg` and `pkg'` composed with the extension of `f` to `pkg`` coincides with the extension of `f` to `pkg'`. The situation is described in the following diagram, where the two diagonal arrows are the extensions of `f` to the two different completions `pkg` and `pkg'`; the statement of `compare_comp_eq_compare` is the commutativity of the right triangle. ``` `α^`=`pkg` ≅ `α^'`=`pkg'` *here `≅` is `compare`* ∧ \ / | \ / | \ / | V ∨ α ---f---> γ ``` -/ theorem compare_comp_eq_compare (γ : Type uγ) [TopologicalSpace γ] [T3Space γ] {f : α → γ} (cont_f : Continuous f) : letI := pkg.uniformStruct.toTopologicalSpace letI := pkg'.uniformStruct.toTopologicalSpace (∀ a : pkg.space, Filter.Tendsto f (Filter.comap pkg.coe (𝓝 a)) (𝓝 ((pkg.isDenseInducing.extend f) a))) → pkg.isDenseInducing.extend f ∘ pkg'.compare pkg = pkg'.isDenseInducing.extend f := by let _ := pkg'.uniformStruct let _ := pkg.uniformStruct intro h have (x : α) : (pkg.isDenseInducing.extend f ∘ pkg'.compare pkg) (pkg'.coe x) = f x := by simp only [Function.comp_apply, compare_coe, IsDenseInducing.extend_eq _ cont_f] apply (IsDenseInducing.extend_unique (AbstractCompletion.isDenseInducing _) this (Continuous.comp _ (uniformContinuous_compare pkg' pkg).continuous )).symm apply IsDenseInducing.continuous_extend exact fun a ↦ ⟨(pkg.isDenseInducing.extend f) a, h a⟩ end Compare section Prod variable (pkg' : AbstractCompletion.{vβ} β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe /-- Products of completions -/ protected def prod : AbstractCompletion (α × β) where space := hatα × hatβ coe p := ⟨ι p.1, ι' p.2⟩ uniformStruct := inferInstance complete := inferInstance separation := inferInstance isUniformInducing := IsUniformInducing.prod pkg.isUniformInducing pkg'.isUniformInducing dense := pkg.dense.prodMap pkg'.dense end Prod section Extension₂ variable (pkg' : AbstractCompletion.{vβ} β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe variable {γ : Type uγ} [UniformSpace γ] open Function /-- Extend two variable map to completions. -/ protected def extend₂ (f : α → β → γ) : hatα → hatβ → γ := curry <| (pkg.prod pkg').extend (uncurry f) section T0Space variable [T0Space γ] {f : α → β → γ} theorem extension₂_coe_coe (hf : UniformContinuous <| uncurry f) (a : α) (b : β) : pkg.extend₂ pkg' f (ι a) (ι' b) = f a b := show (pkg.prod pkg').extend (uncurry f) ((pkg.prod pkg').coe (a, b)) = uncurry f (a, b) from (pkg.prod pkg').extend_coe hf _ end T0Space variable {f : α → β → γ} variable [CompleteSpace γ] (f) theorem uniformContinuous_extension₂ : UniformContinuous₂ (pkg.extend₂ pkg' f) := by rw [uniformContinuous₂_def, AbstractCompletion.extend₂, uncurry_curry] apply uniformContinuous_extend end Extension₂ section Map₂ variable (pkg' : AbstractCompletion β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe variable {γ : Type uγ} [UniformSpace γ] (pkg'' : AbstractCompletion.{vγ} γ) local notation "hatγ" => pkg''.space local notation "ι''" => pkg''.coe local notation f " ∘₂ " g => bicompr f g /-- Lift two variable maps to completions. -/ protected def map₂ (f : α → β → γ) : hatα → hatβ → hatγ := pkg.extend₂ pkg' (pkg''.coe ∘₂ f) theorem uniformContinuous_map₂ (f : α → β → γ) : UniformContinuous₂ (pkg.map₂ pkg' pkg'' f) := AbstractCompletion.uniformContinuous_extension₂ pkg pkg' _ theorem continuous_map₂ {δ} [TopologicalSpace δ] {f : α → β → γ} {a : δ → hatα} {b : δ → hatβ} (ha : Continuous a) (hb : Continuous b) : Continuous fun d : δ => pkg.map₂ pkg' pkg'' f (a d) (b d) := (pkg.uniformContinuous_map₂ pkg' pkg'' f).continuous.comp₂ ha hb theorem map₂_coe_coe (a : α) (b : β) (f : α → β → γ) (hf : UniformContinuous₂ f) : pkg.map₂ pkg' pkg'' f (ι a) (ι' b) = ι'' (f a b) := pkg.extension₂_coe_coe (f := pkg''.coe ∘₂ f) pkg' (pkg''.uniformContinuous_coe.comp hf) a b end Map₂ end AbstractCompletion
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/LocallyUniformConvergence.lean
import Mathlib.Topology.UniformSpace.UniformConvergence /-! # Locally uniform convergence We define a sequence of functions `Fₙ` to *converge locally uniformly* to a limiting function `f` with respect to a filter `p`, spelled `TendstoLocallyUniformly F f p`, if for any `x ∈ s` and any entourage of the diagonal `u`, there is a neighbourhood `v` of `x` such that `p`-eventually we have `(f y, Fₙ y) ∈ u` for all `y ∈ v`. It is important to note that this definition is somewhat non-standard; it is **not** in general equivalent to "every point has a neighborhood on which the convergence is uniform", which is the definition more commonly encountered in the literature. The reason is that in our definition the neighborhood `v` of `x` can depend on the entourage `u`; so our condition is *a priori* weaker than the usual one, although the two conditions are equivalent if the domain is locally compact. See `tendstoLocallyUniformlyOn_of_forall_exists_nhds` for the one-way implication; the equivalence assuming local compactness is part of `tendstoLocallyUniformlyOn_TFAE`. We adopt this weaker condition because it is more general but appears to be sufficient for the standard applications of locally-uniform convergence (in particular, for proving that a locally-uniform limit of continuous functions is continuous). We also define variants for locally uniform convergence on a subset, called `TendstoLocallyUniformlyOn F f p s`. ## Tags Uniform limit, uniform convergence, tends uniformly to -/ noncomputable section open Topology Uniformity Filter Set Uniform variable {α β γ ι : Type*} [TopologicalSpace α] [UniformSpace β] variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} /-- A sequence of functions `Fₙ` converges locally uniformly on a set `s` to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, for any `x ∈ s`, one has `p`-eventually `(f y, Fₙ y) ∈ u` for all `y` in a neighborhood of `x` in `s`. -/ def TendstoLocallyUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) := ∀ u ∈ 𝓤 β, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u /-- A sequence of functions `Fₙ` converges locally uniformly to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, for any `x`, one has `p`-eventually `(f y, Fₙ y) ∈ u` for all `y` in a neighborhood of `x`. -/ def TendstoLocallyUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) := ∀ u ∈ 𝓤 β, ∀ x : α, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u theorem tendstoLocallyUniformlyOn_univ : TendstoLocallyUniformlyOn F f p univ ↔ TendstoLocallyUniformly F f p := by simp [TendstoLocallyUniformlyOn, TendstoLocallyUniformly, nhdsWithin_univ] theorem tendstoLocallyUniformlyOn_iff_forall_tendsto : TendstoLocallyUniformlyOn F f p s ↔ ∀ x ∈ s, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝[s] x) (𝓤 β) := forall₂_swap.trans <| forall₄_congr fun _ _ _ _ => by simp_rw [mem_map, mem_prod_iff_right, mem_preimage] nonrec theorem IsOpen.tendstoLocallyUniformlyOn_iff_forall_tendsto (hs : IsOpen s) : TendstoLocallyUniformlyOn F f p s ↔ ∀ x ∈ s, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝 x) (𝓤 β) := tendstoLocallyUniformlyOn_iff_forall_tendsto.trans <| forall₂_congr fun x hx => by rw [hs.nhdsWithin_eq hx] theorem tendstoLocallyUniformly_iff_forall_tendsto : TendstoLocallyUniformly F f p ↔ ∀ x, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝 x) (𝓤 β) := by simp [← tendstoLocallyUniformlyOn_univ, isOpen_univ.tendstoLocallyUniformlyOn_iff_forall_tendsto] theorem tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe : TendstoLocallyUniformlyOn F f p s ↔ TendstoLocallyUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p := by simp only [tendstoLocallyUniformly_iff_forall_tendsto, Subtype.forall', tendsto_map'_iff, tendstoLocallyUniformlyOn_iff_forall_tendsto, ← map_nhds_subtype_val, prod_map_right]; rfl protected theorem TendstoUniformlyOn.tendstoLocallyUniformlyOn (h : TendstoUniformlyOn F f p s) : TendstoLocallyUniformlyOn F f p s := fun u hu _ _ => ⟨s, self_mem_nhdsWithin, by simpa using h u hu⟩ protected theorem TendstoUniformly.tendstoLocallyUniformly (h : TendstoUniformly F f p) : TendstoLocallyUniformly F f p := fun u hu _ => ⟨univ, univ_mem, by simpa using h u hu⟩ theorem TendstoLocallyUniformlyOn.mono (h : TendstoLocallyUniformlyOn F f p s) (h' : s' ⊆ s) : TendstoLocallyUniformlyOn F f p s' := by intro u hu x hx rcases h u hu x (h' hx) with ⟨t, ht, H⟩ exact ⟨t, nhdsWithin_mono x h' ht, H.mono fun n => id⟩ theorem tendstoLocallyUniformlyOn_iUnion {ι' : Sort*} {S : ι' → Set α} (hS : ∀ i, IsOpen (S i)) (h : ∀ i, TendstoLocallyUniformlyOn F f p (S i)) : TendstoLocallyUniformlyOn F f p (⋃ i, S i) := (isOpen_iUnion hS).tendstoLocallyUniformlyOn_iff_forall_tendsto.2 fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 hx (hS i).tendstoLocallyUniformlyOn_iff_forall_tendsto.1 (h i) _ hi theorem tendstoLocallyUniformlyOn_biUnion {s : Set γ} {S : γ → Set α} (hS : ∀ i ∈ s, IsOpen (S i)) (h : ∀ i ∈ s, TendstoLocallyUniformlyOn F f p (S i)) : TendstoLocallyUniformlyOn F f p (⋃ i ∈ s, S i) := tendstoLocallyUniformlyOn_iUnion (fun i => isOpen_iUnion (hS i)) fun i ↦ tendstoLocallyUniformlyOn_iUnion (hS i) (h i) theorem tendstoLocallyUniformlyOn_sUnion (S : Set (Set α)) (hS : ∀ s ∈ S, IsOpen s) (h : ∀ s ∈ S, TendstoLocallyUniformlyOn F f p s) : TendstoLocallyUniformlyOn F f p (⋃₀ S) := by rw [sUnion_eq_biUnion] exact tendstoLocallyUniformlyOn_biUnion hS h theorem TendstoLocallyUniformlyOn.union (hs₁ : IsOpen s) (hs₂ : IsOpen s') (h₁ : TendstoLocallyUniformlyOn F f p s) (h₂ : TendstoLocallyUniformlyOn F f p s') : TendstoLocallyUniformlyOn F f p (s ∪ s') := by rw [← sUnion_pair] refine tendstoLocallyUniformlyOn_sUnion _ ?_ ?_ <;> simp [*] protected theorem TendstoLocallyUniformly.tendstoLocallyUniformlyOn (h : TendstoLocallyUniformly F f p) : TendstoLocallyUniformlyOn F f p s := (tendstoLocallyUniformlyOn_univ.mpr h).mono (subset_univ _) /-- On a compact space, locally uniform convergence is just uniform convergence. -/ theorem tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace [CompactSpace α] : TendstoLocallyUniformly F f p ↔ TendstoUniformly F f p := by refine ⟨fun h V hV => ?_, TendstoUniformly.tendstoLocallyUniformly⟩ choose U hU using h V hV obtain ⟨t, ht⟩ := isCompact_univ.elim_nhds_subcover' (fun k _ => U k) fun k _ => (hU k).1 replace hU := fun x : t => (hU x).2 rw [← eventually_all] at hU refine hU.mono fun i hi x => ?_ specialize ht (mem_univ x) simp only [exists_prop, mem_iUnion, SetCoe.exists, exists_and_right] at ht obtain ⟨y, ⟨hy₁, hy₂⟩, hy₃⟩ := ht exact hi ⟨⟨y, hy₁⟩, hy₂⟩ x hy₃ /-- For a compact set `s`, locally uniform convergence on `s` is just uniform convergence on `s`. -/ theorem tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact (hs : IsCompact s) : TendstoLocallyUniformlyOn F f p s ↔ TendstoUniformlyOn F f p s := by haveI : CompactSpace s := isCompact_iff_compactSpace.mp hs refine ⟨fun h => ?_, TendstoUniformlyOn.tendstoLocallyUniformlyOn⟩ rwa [tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe, tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace, ← tendstoUniformlyOn_iff_tendstoUniformly_comp_coe] at h theorem TendstoLocallyUniformlyOn.comp [TopologicalSpace γ] {t : Set γ} (h : TendstoLocallyUniformlyOn F f p s) (g : γ → α) (hg : MapsTo g t s) (cg : ContinuousOn g t) : TendstoLocallyUniformlyOn (fun n => F n ∘ g) (f ∘ g) p t := by intro u hu x hx rcases h u hu (g x) (hg hx) with ⟨a, ha, H⟩ have : g ⁻¹' a ∈ 𝓝[t] x := (cg x hx).preimage_mem_nhdsWithin' (nhdsWithin_mono (g x) hg.image_subset ha) exact ⟨g ⁻¹' a, this, H.mono fun n hn y hy => hn _ hy⟩ theorem TendstoLocallyUniformly.comp [TopologicalSpace γ] (h : TendstoLocallyUniformly F f p) (g : γ → α) (cg : Continuous g) : TendstoLocallyUniformly (fun n => F n ∘ g) (f ∘ g) p := by rw [← tendstoLocallyUniformlyOn_univ] at h ⊢ rw [← continuousOn_univ] at cg exact h.comp _ (mapsTo_univ _ _) cg /-- If every `x ∈ s` has a neighbourhood within `s` on which `F i` tends uniformly to `f`, then `F i` tends locally uniformly on `s` to `f`. Note this is **not** a tautology, since our definition of `TendstoLocallyUniformlyOn` is slightly more general (although the conditions are equivalent if `β` is locally compact and `s` is open, see `tendstoLocallyUniformlyOn_TFAE`). -/ lemma tendstoLocallyUniformlyOn_of_forall_exists_nhds (h : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, TendstoUniformlyOn F f p t) : TendstoLocallyUniformlyOn F f p s := by refine tendstoLocallyUniformlyOn_iff_forall_tendsto.mpr fun x hx ↦ ?_ obtain ⟨t, ht, htr⟩ := h x hx rw [tendstoUniformlyOn_iff_tendsto] at htr exact htr.mono_left <| prod_mono_right _ <| le_principal_iff.mpr ht @[deprecated (since := "2025-05-22")] alias tendstoLocallyUniformlyOn_of_forall_exists_nhd := tendstoLocallyUniformlyOn_of_forall_exists_nhds /-- If every `x` has a neighbourhood on which `F i` tends uniformly to `f`, then `F i` tends locally uniformly to `f`. (Special case of `tendstoLocallyUniformlyOn_of_forall_exists_nhds` where `s = univ`.) -/ lemma tendstoLocallyUniformly_of_forall_exists_nhds (h : ∀ x, ∃ t ∈ 𝓝 x, TendstoUniformlyOn F f p t) : TendstoLocallyUniformly F f p := tendstoLocallyUniformlyOn_univ.mp <| tendstoLocallyUniformlyOn_of_forall_exists_nhds (by simpa using h) @[deprecated (since := "2025-05-22")] alias tendstoLocallyUniformly_of_forall_exists_nhd := tendstoLocallyUniformly_of_forall_exists_nhds theorem tendstoLocallyUniformlyOn_TFAE [LocallyCompactSpace α] (G : ι → α → β) (g : α → β) (p : Filter ι) (hs : IsOpen s) : List.TFAE [ TendstoLocallyUniformlyOn G g p s, ∀ K, K ⊆ s → IsCompact K → TendstoUniformlyOn G g p K, ∀ x ∈ s, ∃ v ∈ 𝓝[s] x, TendstoUniformlyOn G g p v] := by tfae_have 1 → 2 | h, K, hK1, hK2 => (tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK2).mp (h.mono hK1) tfae_have 2 → 3 | h, x, hx => by obtain ⟨K, ⟨hK1, hK2⟩, hK3⟩ := (compact_basis_nhds x).mem_iff.mp (hs.mem_nhds hx) exact ⟨K, nhdsWithin_le_nhds hK1, h K hK3 hK2⟩ tfae_have 3 → 1 | h, u, hu, x, hx => by obtain ⟨v, hv1, hv2⟩ := h x hx exact ⟨v, hv1, hv2 u hu⟩ tfae_finish theorem tendstoLocallyUniformlyOn_iff_forall_isCompact [LocallyCompactSpace α] (hs : IsOpen s) : TendstoLocallyUniformlyOn F f p s ↔ ∀ K, K ⊆ s → IsCompact K → TendstoUniformlyOn F f p K := (tendstoLocallyUniformlyOn_TFAE F f p hs).out 0 1 lemma tendstoLocallyUniformly_iff_forall_isCompact [LocallyCompactSpace α] : TendstoLocallyUniformly F f p ↔ ∀ K : Set α, IsCompact K → TendstoUniformlyOn F f p K := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff_forall_isCompact isOpen_univ, Set.subset_univ, forall_true_left] theorem tendstoLocallyUniformlyOn_iff_filter : TendstoLocallyUniformlyOn F f p s ↔ ∀ x ∈ s, TendstoUniformlyOnFilter F f p (𝓝[s] x) := by simp only [TendstoUniformlyOnFilter, eventually_prod_iff] constructor · rintro h x hx u hu obtain ⟨s, hs1, hs2⟩ := h u hu x hx exact ⟨_, hs2, _, eventually_of_mem hs1 fun x => id, fun hi y hy => hi y hy⟩ · rintro h u hu x hx obtain ⟨pa, hpa, pb, hpb, h⟩ := h x hx u hu exact ⟨pb, hpb, eventually_of_mem hpa fun i hi y hy => h hi hy⟩ theorem tendstoLocallyUniformly_iff_filter : TendstoLocallyUniformly F f p ↔ ∀ x, TendstoUniformlyOnFilter F f p (𝓝 x) := by simpa [← tendstoLocallyUniformlyOn_univ, ← nhdsWithin_univ] using @tendstoLocallyUniformlyOn_iff_filter _ _ _ _ _ F f univ p theorem TendstoLocallyUniformlyOn.tendsto_at (hf : TendstoLocallyUniformlyOn F f p s) {a : α} (ha : a ∈ s) : Tendsto (fun i => F i a) p (𝓝 (f a)) := by refine ((tendstoLocallyUniformlyOn_iff_filter.mp hf) a ha).tendsto_at ?_ simpa only [Filter.principal_singleton] using pure_le_nhdsWithin ha theorem TendstoLocallyUniformlyOn.unique [p.NeBot] [T2Space β] {g : α → β} (hf : TendstoLocallyUniformlyOn F f p s) (hg : TendstoLocallyUniformlyOn F g p s) : s.EqOn f g := fun _a ha => tendsto_nhds_unique (hf.tendsto_at ha) (hg.tendsto_at ha) theorem TendstoLocallyUniformlyOn.congr {G : ι → α → β} (hf : TendstoLocallyUniformlyOn F f p s) (hg : ∀ n, s.EqOn (F n) (G n)) : TendstoLocallyUniformlyOn G f p s := by rintro u hu x hx obtain ⟨t, ht, h⟩ := hf u hu x hx refine ⟨s ∩ t, inter_mem self_mem_nhdsWithin ht, ?_⟩ filter_upwards [h] with i hi y hy using hg i hy.1 ▸ hi y hy.2 theorem TendstoLocallyUniformlyOn.congr_right {g : α → β} (hf : TendstoLocallyUniformlyOn F f p s) (hg : s.EqOn f g) : TendstoLocallyUniformlyOn F g p s := by rintro u hu x hx obtain ⟨t, ht, h⟩ := hf u hu x hx refine ⟨s ∩ t, inter_mem self_mem_nhdsWithin ht, ?_⟩ filter_upwards [h] with i hi y hy using hg hy.1 ▸ hi y hy.2
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/DiscreteUniformity.lean
import Mathlib.Topology.UniformSpace.Basic /-! # Discrete uniformity The discrete uniformity is the smallest possible uniformity, the one for which the diagonal is an entourage of itself. It induces the discrete topology. It is complete. -/ open Filter UniformSpace /-- The discrete uniformity -/ @[mk_iff discreteUniformity_iff_eq_bot] class DiscreteUniformity (X : Type*) [u : UniformSpace X] : Prop where eq_bot : u = ⊥ namespace DiscreteUniformity /-- The bot uniformity is the discrete uniformity. -/ instance (X : Type*) : @DiscreteUniformity X ⊥ := @DiscreteUniformity.mk X ⊥ rfl variable (X : Type*) [u : UniformSpace X] [DiscreteUniformity X] theorem _root_.discreteUniformity_iff_eq_principal_relId {X : Type*} [UniformSpace X] : DiscreteUniformity X ↔ uniformity X = 𝓟 SetRel.id := by rw [discreteUniformity_iff_eq_bot, UniformSpace.ext_iff, Filter.ext_iff, bot_uniformity] @[deprecated (since := "2025-10-17")] alias _root_.discreteUniformity_iff_eq_principal_idRel := discreteUniformity_iff_eq_principal_relId theorem eq_principal_relId : uniformity X = 𝓟 SetRel.id := discreteUniformity_iff_eq_principal_relId.mp inferInstance @[deprecated (since := "2025-10-17")] alias eq_principal_idRel := eq_principal_relId /-- The discrete uniformity induces the discrete topology. -/ instance : DiscreteTopology X where eq_bot := by rw [DiscreteUniformity.eq_bot (X := X), UniformSpace.toTopologicalSpace_bot] theorem _root_.discreteUniformity_iff_relId_mem_uniformity {X : Type*} [UniformSpace X] : DiscreteUniformity X ↔ SetRel.id ∈ uniformity X := by rw [← uniformSpace_eq_bot, discreteUniformity_iff_eq_bot] @[deprecated (since := "2025-10-17")] alias _root_.discreteUniformity_iff_idRel_mem_uniformity := discreteUniformity_iff_relId_mem_uniformity theorem relId_mem_uniformity : SetRel.id ∈ uniformity X := discreteUniformity_iff_relId_mem_uniformity.mp inferInstance @[deprecated (since := "2025-10-17")] alias idRel_mem_uniformity := relId_mem_uniformity variable {X} in /-- A product of spaces with discrete uniformity has a discrete uniformity. -/ instance {Y : Type*} [UniformSpace Y] [DiscreteUniformity Y] : DiscreteUniformity (X × Y) := by simp [discreteUniformity_iff_eq_principal_relId, uniformity_prod_eq_comap_prod, eq_principal_relId, SetRel.id, Set.prod_eq, Prod.ext_iff, Set.setOf_and] variable {x} in /-- On a space with a discrete uniformity, any function is uniformly continuous. -/ theorem uniformContinuous {Y : Type*} [UniformSpace Y] (f : X → Y) : UniformContinuous f := by simp only [uniformContinuous_iff, DiscreteUniformity.eq_bot, bot_le] end DiscreteUniformity
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/CompleteSeparated.lean
import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Theory of complete separated uniform spaces. This file is for elementary lemmas that depend on both Cauchy filters and separation. -/ open Filter open Topology Filter variable {α β : Type*} /-- In a separated space, a complete set is closed. -/ theorem IsComplete.isClosed [UniformSpace α] [T0Space α] {s : Set α} (h : IsComplete s) : IsClosed s := isClosed_iff_clusterPt.2 fun a ha => by let f := 𝓝[s] a have : Cauchy f := cauchy_nhds.mono' ha inf_le_left rcases h f this inf_le_right with ⟨y, ys, fy⟩ rwa [(tendsto_nhds_unique' ha inf_le_left fy : a = y)] theorem IsUniformEmbedding.isClosedEmbedding [UniformSpace α] [UniformSpace β] [CompleteSpace α] [T0Space β] {f : α → β} (hf : IsUniformEmbedding f) : IsClosedEmbedding f := ⟨hf.isEmbedding, hf.isUniformInducing.isComplete_range.isClosed⟩ namespace IsDenseInducing open Filter variable [TopologicalSpace α] {β : Type*} [TopologicalSpace β] variable {γ : Type*} [UniformSpace γ] [CompleteSpace γ] [T0Space γ] theorem continuous_extend_of_cauchy {e : α → β} {f : α → γ} (de : IsDenseInducing e) (h : ∀ b : β, Cauchy (map f (comap e <| 𝓝 b))) : Continuous (de.extend f) := de.continuous_extend fun b => CompleteSpace.complete (h b) end IsDenseInducing
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/AbsoluteValue.lean
import Mathlib.Algebra.Order.AbsoluteValue.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Topology.UniformSpace.OfFun /-! # Uniform structure induced by an absolute value We build a uniform space structure on a commutative ring `R` equipped with an absolute value into a linear ordered field `𝕜`. Of course in the case `R` is `ℚ`, `ℝ` or `ℂ` and `𝕜 = ℝ`, we get the same thing as the metric space construction, and the general construction follows exactly the same path. ## References * [N. Bourbaki, *Topologie générale*][bourbaki1966] ## Tags absolute value, uniform spaces -/ open Set Function Filter Uniformity namespace AbsoluteValue variable {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] variable {R : Type*} [CommRing R] (abv : AbsoluteValue R 𝕜) /-- The uniform structure coming from an absolute value. -/ def uniformSpace : UniformSpace R := .ofFun (fun x y => abv (y - x)) (by simp) (fun x y => abv.map_sub y x) (fun _ _ _ => (abv.sub_le _ _ _).trans_eq (add_comm _ _)) fun ε ε0 => ⟨ε / 2, half_pos ε0, fun _ h₁ _ h₂ => (add_lt_add h₁ h₂).trans_eq (add_halves ε)⟩ theorem hasBasis_uniformity : 𝓤[abv.uniformSpace].HasBasis ((0 : 𝕜) < ·) fun ε => { p : R × R | abv (p.2 - p.1) < ε } := UniformSpace.hasBasis_ofFun (exists_gt _) _ _ _ _ _ end AbsoluteValue
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Real.lean
import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Topology.MetricSpace.Cauchy /-! # The reals are complete This file provides the instances `CompleteSpace ℝ` and `CompleteSpace ℝ≥0`. Along the way, we add a shortcut instance for the natural topology on `ℝ≥0` (the one induced from `ℝ`), and add some basic API. -/ assert_not_exists IsTopologicalRing UniformContinuousConstSMul UniformOnFun noncomputable section open Filter Metric Set instance Real.instCompleteSpace : CompleteSpace ℝ := by apply complete_of_cauchySeq_tendsto intro u hu let c : CauSeq ℝ abs := ⟨u, Metric.cauchySeq_iff'.1 hu⟩ refine ⟨c.lim, fun s h => ?_⟩ rcases Metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩ have := c.equiv_lim ε ε0 simp only [mem_map, mem_atTop_sets] exact this.imp fun N hN n hn => hε (hN n hn) namespace NNReal /-! ### Topology on `ℝ≥0` All the instances are inherited from the corresponding structures on the reals. -/ instance : TopologicalSpace ℝ≥0 := inferInstance instance : CompleteSpace ℝ≥0 := isClosed_Ici.completeSpace_coe @[fun_prop] theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ) := continuous_subtype_val /-- Embedding of `ℝ≥0` to `ℝ` as a bundled continuous map. -/ @[simps -fullyApplied] def _root_.ContinuousMap.coeNNRealReal : C(ℝ≥0, ℝ) := ⟨(↑), continuous_coe⟩ @[simp] lemma coeNNRealReal_zero : ContinuousMap.coeNNRealReal 0 = 0 := rfl instance ContinuousMap.canLift {X : Type*} [TopologicalSpace X] : CanLift C(X, ℝ) C(X, ℝ≥0) ContinuousMap.coeNNRealReal.comp fun f => ∀ x, 0 ≤ f x where prf f hf := ⟨⟨fun x => ⟨f x, hf x⟩, f.2.subtype_mk _⟩, DFunLike.ext' rfl⟩ end NNReal
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Ultra/Completion.lean
import Mathlib.Topology.UniformSpace.Completion import Mathlib.Topology.UniformSpace.Ultra.Basic import Mathlib.Topology.UniformSpace.Ultra.Constructions /-! # Completions of ultrametric (nonarchimedean) uniform spaces ## Main results * `IsUltraUniformity.completion_iff`: a Hausdorff completion has a nonarchimedean uniformity iff the underlying space has a nonarchimedean uniformity. -/ variable {X Y : Type*} [UniformSpace X] [UniformSpace Y] open Filter Set Topology Uniformity lemma IsUniformInducing.isUltraUniformity [IsUltraUniformity Y] {f : X → Y} (hf : IsUniformInducing f) : IsUltraUniformity X := hf.comap_uniformSpace ▸ .comap inferInstance f instance CauchyFilter.isSymm_gen {s : SetRel X X} [s.IsSymm] : (gen s).IsSymm where symm _ := by simp [CauchyFilter.gen, s.mem_filter_prod_comm] @[deprecated (since := "2025-10-17")] alias IsSymmetricRel.cauchyFilter_gen := CauchyFilter.isSymm_gen instance CauchyFilter.isTrans_gen {s : SetRel X X} [s.IsTrans] : (gen s).IsTrans where trans _ _ _ := IsTransitiveRel.mem_filter_prod_trans @[deprecated (since := "2025-10-17")] alias IsTransitiveRel.cauchyFilter_gen := CauchyFilter.isTrans_gen instance IsUltraUniformity.cauchyFilter [IsUltraUniformity X] : IsUltraUniformity (CauchyFilter X) := by apply mk_of_hasBasis (CauchyFilter.basis_uniformity IsUltraUniformity.hasBasis) · exact fun _ ⟨_, hU, _⟩ ↦ by simp; infer_instance · exact fun _ ⟨_, _, hU⟩ ↦ by simp; infer_instance @[simp] lemma IsUltraUniformity.cauchyFilter_iff : IsUltraUniformity (CauchyFilter X) ↔ IsUltraUniformity X := ⟨fun _ ↦ CauchyFilter.isUniformInducing_pureCauchy.isUltraUniformity, fun _ ↦ inferInstance⟩ instance IsUltraUniformity.separationQuotient [IsUltraUniformity X] : IsUltraUniformity (SeparationQuotient X) := by have := IsUltraUniformity.hasBasis.map (Prod.map SeparationQuotient.mk (SeparationQuotient.mk (X := X))) rw [← SeparationQuotient.uniformity_eq] at this apply mk_of_hasBasis this · exact fun _ ⟨_, hU, _⟩ ↦ by simp; infer_instance · rintro U ⟨hU', _, hU⟩ constructor rintro x y z simp only [id_eq, Set.mem_image, Prod.exists, Prod.map_apply, Prod.mk.injEq, forall_exists_index, and_imp] rintro a b hab rfl rfl c d hcd hc rfl have hbc : (b, c) ∈ U := by rw [eq_comm, SeparationQuotient.mk_eq_mk, inseparable_iff_ker_uniformity, Filter.mem_ker] at hc exact hc _ hU' exact ⟨a, d, U.trans (U.trans hab hbc) hcd, by simp, by simp⟩ @[simp] lemma IsUltraUniformity.separationQuotient_iff : IsUltraUniformity (SeparationQuotient X) ↔ IsUltraUniformity X := ⟨fun _ ↦ SeparationQuotient.isUniformInducing_mk.isUltraUniformity, fun _ ↦ inferInstance⟩ @[simp] lemma IsUltraUniformity.completion_iff : IsUltraUniformity (UniformSpace.Completion X) ↔ IsUltraUniformity X := by rw [iff_comm, ← cauchyFilter_iff, ← separationQuotient_iff] exact Iff.rfl instance IsUltraUniformity.completion [IsUltraUniformity X] : IsUltraUniformity (UniformSpace.Completion X) := completion_iff.2 inferInstance
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Ultra/Basic.lean
import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.Bases /-! # Ultrametric (nonarchimedean) uniform spaces Ultrametric (nonarchimedean) uniform spaces are ones that generalize ultrametric spaces by having a uniformity based on equivalence relations. ## Main definitions In this file we define `IsUltraUniformity`, a Prop mixin typeclass. ## Main results * `TopologicalSpace.isTopologicalBasis_clopens`: a uniform space with a nonarchimedean uniformity has a topological basis of clopen sets in the topology, meaning that it is topologically zero-dimensional. ## Implementation notes As in the `Mathlib/Topology/UniformSpace/Defs.lean` file, we do not reuse `Mathlib/Data/SetRel.lean` but rather extend the relation properties as needed. ## TODOs * Prove that `IsUltraUniformity` iff metrizable by `IsUltrametricDist` on a `PseudoMetricSpace` under a countable system/basis condition * Generalize `IsUltrametricDist` to `IsUltrametricUniformity` * Provide `IsUltraUniformity` for the uniformity in a `Valued` ring * Generalize results about open/closed balls and spheres in `IsUltraUniformity` to combine applications for `MetricSpace.ball` and valued "balls" * Use `IsUltraUniformity` to work with profinite/totally separated spaces ## References * [D. Windisch, *Equivalent characterizations of non-Archimedean uniform spaces*][windisch2021] * [A. C. M. van Rooij, *Non-Archimedean uniformities*][vanrooij1970] -/ open Set Filter Topology open scoped SetRel Uniformity variable {X : Type*} /-- The relation is transitive. -/ @[deprecated SetRel.IsTrans (since := "2025-10-17")] def IsTransitiveRel (V : SetRel X X) : Prop := ∀ ⦃x y z⦄, (x, y) ∈ V → (y, z) ∈ V → (x, z) ∈ V set_option linter.deprecated false in @[deprecated SetRel.comp_subset_self (since := "2025-10-17")] lemma IsTransitiveRel.comp_subset_self {s : SetRel X X} (h : IsTransitiveRel s) : s ○ s ⊆ s := fun ⟨_, _⟩ ⟨_, hxz, hzy⟩ ↦ h hxz hzy set_option linter.deprecated false in @[deprecated SetRel.isTrans_iff_comp_subset_self (since := "2025-10-17")] lemma isTransitiveRel_iff_comp_subset_self {s : SetRel X X} : IsTransitiveRel s ↔ s ○ s ⊆ s := ⟨IsTransitiveRel.comp_subset_self, fun h _ _ _ hx hy ↦ h ⟨_, hx, hy⟩⟩ set_option linter.deprecated false in @[deprecated SetRel.isTrans_empty (since := "2025-10-17")] lemma isTransitiveRel_empty : IsTransitiveRel (X := X) ∅ := by simp [IsTransitiveRel] set_option linter.deprecated false in @[deprecated SetRel.isTrans_univ (since := "2025-10-17")] lemma isTransitiveRel_univ : IsTransitiveRel (X := X) Set.univ := by simp [IsTransitiveRel] set_option linter.deprecated false in @[deprecated SetRel.isTrans_singleton (since := "2025-10-17")] lemma isTransitiveRel_singleton (x y : X) : IsTransitiveRel {(x, y)} := by simp +contextual [IsTransitiveRel] set_option linter.deprecated false in @[deprecated SetRel.isTrans_inter (since := "2025-10-17")] lemma IsTransitiveRel.inter {s t : SetRel X X} (hs : IsTransitiveRel s) (ht : IsTransitiveRel t) : IsTransitiveRel (s ∩ t) := fun _ _ _ h h' ↦ ⟨hs h.left h'.left, ht h.right h'.right⟩ set_option linter.deprecated false in @[deprecated SetRel.isTrans_iInter (since := "2025-10-17")] lemma IsTransitiveRel.iInter {ι : Type*} {U : (i : ι) → SetRel X X} (hU : ∀ i, IsTransitiveRel (U i)) : IsTransitiveRel (⋂ i, U i) := by intro _ _ _ h h' simp only [mem_iInter] at h h' ⊢ intro i exact hU i (h i) (h' i) set_option linter.deprecated false in @[deprecated SetRel.IsTrans.sInter (since := "2025-10-17")] lemma IsTransitiveRel.sInter {s : Set (SetRel X X)} (h : ∀ i ∈ s, IsTransitiveRel i) : IsTransitiveRel (⋂₀ s) := by rw [sInter_eq_iInter] exact IsTransitiveRel.iInter (by simpa) set_option linter.deprecated false in @[deprecated SetRel.isTrans_preimage (since := "2025-10-17")] lemma IsTransitiveRel.preimage_prodMap {Y : Type*} {t : Set (Y × Y)} (ht : IsTransitiveRel t) (f : X → Y) : IsTransitiveRel (Prod.map f f ⁻¹' t) := fun _ _ _ h h' ↦ ht h h' set_option linter.deprecated false in @[deprecated SetRel.isTrans_symmetrize (since := "2025-10-17")] lemma IsTransitiveRel.symmetrizeRel {s : SetRel X X} (h : IsTransitiveRel s) : IsTransitiveRel (SetRel.symmetrize s) := fun _ _ _ hxy hyz ↦ ⟨h hxy.1 hyz.1, h hyz.2 hxy.2⟩ set_option linter.deprecated false in @[deprecated SetRel.comp_eq_self (since := "2025-10-17")] lemma IsTransitiveRel.comp_eq_of_idRel_subset {s : SetRel X X} (h : IsTransitiveRel s) (h' : idRel ⊆ s) : s ○ s = s := le_antisymm h.comp_subset_self (subset_comp_self h') lemma IsTransitiveRel.prod_subset_trans {s : SetRel X X} {t u v : Set X} [s.IsTrans] (htu : t ×ˢ u ⊆ s) (huv : u ×ˢ v ⊆ s) (hu : u.Nonempty) : t ×ˢ v ⊆ s := by rintro ⟨a, b⟩ hab simp only [mem_prod] at hab obtain ⟨x, hx⟩ := hu exact s.trans (@htu ⟨a, x⟩ ⟨hab.left, hx⟩) (@huv ⟨x, b⟩ ⟨hx, hab.right⟩) lemma IsTransitiveRel.mem_filter_prod_trans {s : SetRel X X} {f g h : Filter X} [g.NeBot] [s.IsTrans] (hfg : s ∈ f ×ˢ g) (hgh : s ∈ g ×ˢ h) : s ∈ f ×ˢ h := Eventually.trans_prod (p := (fun x y ↦ (x, y) ∈ s)) (q := (fun x y ↦ (x, y) ∈ s)) (r := (fun x y ↦ (x, y) ∈ s)) hfg hgh fun _ _ _ ↦ s.trans @[deprecated (since := "2025-10-08")] alias IsTransitiveRel.mem_filter_prod_comm := IsTransitiveRel.mem_filter_prod_trans open UniformSpace lemma ball_subset_of_mem {V : SetRel X X} [V.IsTrans] {x y : X} (hy : y ∈ ball x V) : ball y V ⊆ ball x V := ball_subset_of_comp_subset hy SetRel.comp_subset_self lemma ball_eq_of_mem {V : SetRel X X} [V.IsSymm] [V.IsTrans] {x y : X} (hy : y ∈ ball x V) : ball x V = ball y V := by refine le_antisymm (ball_subset_of_mem ?_) (ball_subset_of_mem hy) rwa [← mem_ball_symmetry] variable [UniformSpace X] variable (X) in /-- A uniform space is ultrametric if the uniformity `𝓤 X` has a basis of equivalence relations. -/ class IsUltraUniformity : Prop where hasBasis : (𝓤 X).HasBasis (fun s : SetRel X X => s ∈ 𝓤 X ∧ SetRel.IsSymm s ∧ SetRel.IsTrans s) id lemma IsUltraUniformity.mk_of_hasBasis {ι : Type*} {p : ι → Prop} {s : ι → SetRel X X} (h_basis : (𝓤 X).HasBasis p s) (h_symm : ∀ i, p i → SetRel.IsSymm (s i)) (h_trans : ∀ i, p i → SetRel.IsTrans (s i)) : IsUltraUniformity X where hasBasis := h_basis.to_hasBasis' (fun i hi ↦ ⟨s i, ⟨h_basis.mem_of_mem hi, h_symm i hi, h_trans i hi⟩, subset_rfl⟩) (fun _ hs ↦ hs.1) lemma IsUltraUniformity.mem_nhds_iff_symm_trans [IsUltraUniformity X] {x : X} {s : Set X} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 X, SetRel.IsSymm V ∧ SetRel.IsTrans V ∧ UniformSpace.ball x V ⊆ s := by rw [UniformSpace.mem_nhds_iff] constructor · rintro ⟨V, V_in, V_sub⟩ rw [IsUltraUniformity.hasBasis.mem_iff'] at V_in obtain ⟨U, ⟨U_in, U_sym, U_trans⟩, U_sub⟩ := V_in refine ⟨U, U_in, U_sym, U_trans, (UniformSpace.ball_mono U_sub _).trans V_sub⟩ · rintro ⟨V, V_in, _, _, V_sub⟩ exact ⟨V, V_in, V_sub⟩ namespace UniformSpace lemma isOpen_ball_of_mem_uniformity (x : X) {V : SetRel X X} [V.IsTrans] (h' : V ∈ 𝓤 X) : IsOpen (ball x V) := by rw [isOpen_iff_ball_subset] intro y hy exact ⟨V, h', ball_subset_of_mem hy⟩ lemma isClosed_ball_of_isSymm_of_isTrans_of_mem_uniformity (x : X) {V : SetRel X X} [V.IsSymm] [V.IsTrans] (h' : V ∈ 𝓤 X) : IsClosed (ball x V) := by rw [← isOpen_compl_iff, isOpen_iff_ball_subset] exact fun y hy ↦ ⟨V, h', fun z hyz hxz ↦ hy <| V.trans hxz <| V.symm hyz⟩ @[deprecated (since := "2025-10-17")] alias isClosed_ball_of_isSymmetricRel_of_isTransitiveRel_of_mem_uniformity := isClosed_ball_of_isSymm_of_isTrans_of_mem_uniformity lemma isClopen_ball_of_isSymm_of_isTrans_of_mem_uniformity (x : X) {V : SetRel X X} [V.IsSymm] [V.IsTrans] (h' : V ∈ 𝓤 X) : IsClopen (ball x V) := ⟨isClosed_ball_of_isSymm_of_isTrans_of_mem_uniformity _ ‹_›, isOpen_ball_of_mem_uniformity _ ‹_›⟩ variable [IsUltraUniformity X] lemma nhds_basis_clopens (x : X) : (𝓝 x).HasBasis (fun s : Set X => x ∈ s ∧ IsClopen s) id := by refine (nhds_basis_uniformity' (IsUltraUniformity.hasBasis)).to_hasBasis' ?_ ?_ · intro V ⟨hV, h_symm, h_trans⟩ exact ⟨ball x V, ⟨mem_ball_self _ hV, isClopen_ball_of_isSymm_of_isTrans_of_mem_uniformity _ hV⟩, le_rfl⟩ · rintro u ⟨hx, hu⟩ simp [hu.right.mem_nhds_iff, hx] /-- A uniform space with a nonarchimedean uniformity is zero-dimensional. -/ lemma _root_.TopologicalSpace.isTopologicalBasis_clopens : TopologicalSpace.IsTopologicalBasis {s : Set X | IsClopen s} := .of_hasBasis_nhds fun x ↦ by simpa [and_comm] using nhds_basis_clopens x end UniformSpace
.lake/packages/mathlib/Mathlib/Topology/UniformSpace/Ultra/Constructions.lean
import Mathlib.Topology.UniformSpace.DiscreteUniformity import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.Ultra.Basic /-! # Products of ultrametric (nonarchimedean) uniform spaces ## Main results * `IsUltraUniformity.prod`: a product of uniform spaces with nonarchimedean uniformities has a nonarchimedean uniformity. * `IsUltraUniformity.pi`: an indexed product of uniform spaces with nonarchimedean uniformities has a nonarchimedean uniformity. ## Implementation details This file can be split to separate imports to have the `Prod` and `Pi` instances separately, but would be somewhat unnatural since they are closely related. The `Prod` instance only requires `Mathlib/Topology/UniformSpace/Basic.lean`. -/ variable {X Y : Type*} instance SetRel.isTrans_entourageProd {s : SetRel X X} {t : SetRel Y Y} [s.IsTrans] [t.IsTrans] : (entourageProd s t).IsTrans where trans _ _ _ h h' := ⟨s.trans h.left h'.left, t.trans h.right h'.right⟩ @[deprecated (since := "2025-10-17")] alias IsTransitiveRel.entourageProd := SetRel.isTrans_entourageProd lemma IsUltraUniformity.comap {u : UniformSpace Y} (h : IsUltraUniformity Y) (f : X → Y) : @IsUltraUniformity _ (u.comap f) := by letI := u.comap f refine .mk_of_hasBasis (h.hasBasis.comap (Prod.map f f)) ?_ ?_ <;> · dsimp rintro _ ⟨_, _, _⟩ infer_instance lemma IsUltraUniformity.inf {u u' : UniformSpace X} (h : @IsUltraUniformity _ u) (h' : @IsUltraUniformity _ u') : @IsUltraUniformity _ (u ⊓ u') := by letI := u ⊓ u' refine .mk_of_hasBasis (h.hasBasis.inf h'.hasBasis) ?_ ?_ <;> · dsimp rintro _ ⟨⟨_, _, _⟩, _, _, _⟩ infer_instance /-- The product of uniform spaces with nonarchimedean uniformities has a nonarchimedean uniformity. -/ instance IsUltraUniformity.prod [UniformSpace X] [UniformSpace Y] [IsUltraUniformity X] [IsUltraUniformity Y] : IsUltraUniformity (X × Y) := .inf (.comap ‹_› _) (.comap ‹_› _) lemma IsUltraUniformity.iInf {ι : Type*} {U : (i : ι) → UniformSpace X} (hU : ∀ i, @IsUltraUniformity X (U i)) : @IsUltraUniformity _ (⨅ i, U i : UniformSpace X) := by letI : UniformSpace X := ⨅ i, U i refine .mk_of_hasBasis (iInf_uniformity ▸ Filter.HasBasis.iInf fun i ↦ (hU i).hasBasis) ?_ ?_ <;> · simp [forall_and] rintro _ _ _ _ _ infer_instance /-- The indexed product of uniform spaces with nonarchimedean uniformities has a nonarchimedean uniformity. -/ instance IsUltraUniformity.pi {ι : Type*} {X : ι → Type*} [U : Π i, UniformSpace (X i)] [h : ∀ i, IsUltraUniformity (X i)] : IsUltraUniformity (Π i, X i) := by suffices @IsUltraUniformity _ (⨅ i, UniformSpace.comap (Function.eval i) (U i)) by simpa [Pi.uniformSpace_eq _] using this exact .iInf fun i ↦ .comap (h i) (Function.eval i) instance IsUltraUniformity.bot [UniformSpace X] [DiscreteUniformity X] : IsUltraUniformity X := by have := Filter.hasBasis_principal (SetRel.id (α := X)) rw [← DiscreteUniformity.eq_principal_relId] at this apply mk_of_hasBasis this <;> { simp; infer_instance } lemma IsUltraUniformity.top : @IsUltraUniformity X (⊤ : UniformSpace X) := by letI : UniformSpace X := ⊤ have := Filter.hasBasis_top (α := (X × X)) rw [← top_uniformity] at this apply mk_of_hasBasis this <;> { simp; infer_instance }
.lake/packages/mathlib/Mathlib/Topology/Sets/OpenCover.lean
import Mathlib.Topology.Sets.Opens /-! # Open covers We define `IsOpenCover` as a predicate on indexed families of open sets in a topological space `X`, asserting that their union is `X`. This is an example of a declaration whose name is actually longer than its content; but giving it a name serves as a way of standardizing API. -/ open Set Topology namespace TopologicalSpace /-- An indexed family of open sets whose union is `X`. -/ def IsOpenCover {ι X : Type*} [TopologicalSpace X] (u : ι → Opens X) : Prop := iSup u = ⊤ variable {ι κ X Y : Type*} [TopologicalSpace X] {u : ι → Opens X} [TopologicalSpace Y] {v : κ → Opens Y} namespace IsOpenCover lemma mk (h : iSup u = ⊤) : IsOpenCover u := h lemma of_sets {v : ι → Set X} (h_open : ∀ i, IsOpen (v i)) (h_iUnion : ⋃ i, v i = univ) : IsOpenCover (fun i ↦ ⟨v i, h_open i⟩) := by simp [IsOpenCover, h_iUnion] lemma iSup_eq_top (hu : IsOpenCover u) : ⨆ i, u i = ⊤ := hu lemma iSup_set_eq_univ (hu : IsOpenCover u) : ⋃ i, (u i : Set X) = univ := by simpa [← SetLike.coe_set_eq] using hu.iSup_eq_top /-- Pullback of a covering of `Y` by a continuous map `X → Y`, giving a covering of `X` with the same index type. -/ lemma comap (hv : IsOpenCover v) (f : C(X, Y)) : IsOpenCover fun k ↦ (v k).comap f := by simp [IsOpenCover, ← preimage_iUnion, hv.iSup_set_eq_univ] lemma exists_mem (hu : IsOpenCover u) (a : X) : ∃ i, a ∈ u i := by simpa [← hu.iSup_set_eq_univ] using mem_univ a lemma exists_mem_nhds (hu : IsOpenCover u) (a : X) : ∃ i, (u i : Set X) ∈ 𝓝 a := match hu.exists_mem a with | ⟨i, hi⟩ => ⟨i, (u i).isOpen.mem_nhds hi⟩ lemma iUnion_inter (hu : IsOpenCover u) (s : Set X) : ⋃ i, s ∩ u i = s := by simp [← inter_iUnion, hu.iSup_set_eq_univ] lemma isTopologicalBasis (hu : IsOpenCover u) {B : ∀ i, Set (Set (u i))} (hB : ∀ i, IsTopologicalBasis (B i)) : IsTopologicalBasis (⋃ i, (Subtype.val '' ·) '' B i) := isTopologicalBasis_of_cover (fun i ↦ (u i).2) hu.iSup_set_eq_univ hB end IsOpenCover end TopologicalSpace
.lake/packages/mathlib/Mathlib/Topology/Sets/Opens.lean
import Mathlib.Order.Hom.CompleteLattice import Mathlib.Topology.Compactness.Bases import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.Copy /-! # Open sets ## Summary We define the subtype of open sets in a topological space. ## Main Definitions ### Bundled open sets - `TopologicalSpace.Opens α` is the type of open subsets of a topological space `α`. - `TopologicalSpace.Opens.IsBasis` is a predicate saying that a set of `Opens`s form a topological basis. - `TopologicalSpace.Opens.comap`: preimage of an open set under a continuous map as a `FrameHom`. - `Homeomorph.opensCongr`: order-preserving equivalence between open sets in the domain and the codomain of a homeomorphism. ### Bundled open neighborhoods - `TopologicalSpace.OpenNhdsOf x` is the type of open subsets of a topological space `α` containing `x : α`. - `TopologicalSpace.OpenNhdsOf.comap f x U` is the preimage of open neighborhood `U` of `f x` under `f : C(α, β)`. ## Main results We define order structures on both `Opens α` (`CompleteLattice`, `Frame`) and `OpenNhdsOf x` (`OrderTop`, `DistribLattice`). ## TODO - Rename `TopologicalSpace.Opens` to `Open`? - Port the `auto_cases` tactic version (as a plugin if the ported `auto_cases` will allow plugins). -/ open Filter Function Order Set open Topology variable {ι α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] namespace TopologicalSpace variable (α) in /-- The type of open subsets of a topological space. -/ structure Opens where /-- The underlying set of a bundled `TopologicalSpace.Opens` object. -/ carrier : Set α /-- The `TopologicalSpace.Opens.carrier _` is an open set. -/ is_open' : IsOpen carrier namespace Opens instance : SetLike (Opens α) α where coe := Opens.carrier coe_injective' := fun ⟨_, _⟩ ⟨_, _⟩ _ => by congr instance : CanLift (Set α) (Opens α) (↑) IsOpen := ⟨fun s h => ⟨⟨s, h⟩, rfl⟩⟩ instance instSecondCountableOpens [SecondCountableTopology α] (U : Opens α) : SecondCountableTopology U := inferInstanceAs (SecondCountableTopology U.1) theorem «forall» {p : Opens α → Prop} : (∀ U, p U) ↔ ∀ (U : Set α) (hU : IsOpen U), p ⟨U, hU⟩ := ⟨fun h _ _ => h _, fun h _ => h _ _⟩ @[simp] theorem carrier_eq_coe (U : Opens α) : U.1 = ↑U := rfl /-- the coercion `Opens α → Set α` applied to a pair is the same as taking the first component -/ @[simp] theorem coe_mk {U : Set α} {hU : IsOpen U} : ↑(⟨U, hU⟩ : Opens α) = U := rfl @[simp] theorem mem_mk {x : α} {U : Set α} {h : IsOpen U} : x ∈ mk U h ↔ x ∈ U := Iff.rfl protected theorem nonempty_coeSort {U : Opens α} : Nonempty U ↔ (U : Set α).Nonempty := Set.nonempty_coe_sort -- TODO: should this theorem be proved for a `SetLike`? protected theorem nonempty_coe {U : Opens α} : (U : Set α).Nonempty ↔ ∃ x, x ∈ U := Iff.rfl @[ext] -- TODO: replace with `∀ x, x ∈ U ↔ x ∈ V`? theorem ext {U V : Opens α} (h : (U : Set α) = V) : U = V := SetLike.coe_injective h theorem coe_inj {U V : Opens α} : (U : Set α) = V ↔ U = V := SetLike.ext'_iff.symm /-- A version of `Set.inclusion` not requiring definitional abuse -/ abbrev inclusion {U V : Opens α} (h : U ≤ V) : U → V := Set.inclusion h protected theorem isOpen (U : Opens α) : IsOpen (U : Set α) := U.is_open' @[simp] theorem mk_coe (U : Opens α) : mk (↑U) U.isOpen = U := rfl /-- See Note [custom simps projection]. -/ def Simps.coe (U : Opens α) : Set α := U initialize_simps_projections Opens (carrier → coe, as_prefix coe) /-- The interior of a set, as an element of `Opens`. -/ @[simps] protected def interior (s : Set α) : Opens α := ⟨interior s, isOpen_interior⟩ @[simp] theorem mem_interior {s : Set α} {x : α} : x ∈ Opens.interior s ↔ x ∈ _root_.interior s := .rfl theorem gc : GaloisConnection ((↑) : Opens α → Set α) Opens.interior := fun U _ => ⟨fun h => interior_maximal h U.isOpen, fun h => le_trans h interior_subset⟩ /-- The Galois coinsertion between sets and opens. -/ def gi : GaloisCoinsertion (↑) (@Opens.interior α _) where choice s hs := ⟨s, interior_eq_iff_isOpen.mp <| le_antisymm interior_subset hs⟩ gc := gc u_l_le _ := interior_subset choice_eq _s hs := le_antisymm hs interior_subset instance : CompleteLattice (Opens α) := CompleteLattice.copy (GaloisCoinsertion.liftCompleteLattice gi) -- le (fun U V => (U : Set α) ⊆ V) rfl -- top ⟨univ, isOpen_univ⟩ (ext interior_univ.symm) -- bot ⟨∅, isOpen_empty⟩ rfl -- sup (fun U V => ⟨↑U ∪ ↑V, U.2.union V.2⟩) rfl -- inf (fun U V => ⟨↑U ∩ ↑V, U.2.inter V.2⟩) (funext₂ fun U V => ext (U.2.inter V.2).interior_eq.symm) -- sSup (fun S => ⟨⋃ s ∈ S, ↑s, isOpen_biUnion fun s _ => s.2⟩) (funext fun _ => ext sSup_image.symm) -- sInf _ rfl @[simp] theorem mk_inf_mk {U V : Set α} {hU : IsOpen U} {hV : IsOpen V} : (⟨U, hU⟩ ⊓ ⟨V, hV⟩ : Opens α) = ⟨U ⊓ V, IsOpen.inter hU hV⟩ := rfl @[simp, norm_cast] theorem coe_inf (s t : Opens α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t := rfl @[simp] lemma mem_inf {s t : Opens α} {x : α} : x ∈ s ⊓ t ↔ x ∈ s ∧ x ∈ t := Iff.rfl @[simp, norm_cast] theorem coe_sup (s t : Opens α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : Opens α) : Set α) = ∅ := rfl @[simp] lemma mem_bot {x : α} : x ∈ (⊥ : Opens α) ↔ False := Iff.rfl @[simp] theorem mk_empty : (⟨∅, isOpen_empty⟩ : Opens α) = ⊥ := rfl @[simp, norm_cast] theorem coe_eq_empty {U : Opens α} : (U : Set α) = ∅ ↔ U = ⊥ := SetLike.coe_injective.eq_iff' rfl @[simp] lemma mem_top (x : α) : x ∈ (⊤ : Opens α) := trivial @[simp, norm_cast] theorem coe_top : ((⊤ : Opens α) : Set α) = Set.univ := rfl @[simp] theorem mk_univ : (⟨univ, isOpen_univ⟩ : Opens α) = ⊤ := rfl @[simp, norm_cast] theorem coe_eq_univ {U : Opens α} : (U : Set α) = univ ↔ U = ⊤ := SetLike.coe_injective.eq_iff' rfl @[simp, norm_cast] theorem coe_sSup {S : Set (Opens α)} : (↑(sSup S) : Set α) = ⋃ i ∈ S, ↑i := rfl @[simp, norm_cast] theorem coe_finset_sup (f : ι → Opens α) (s : Finset ι) : (↑(s.sup f) : Set α) = s.sup ((↑) ∘ f) := map_finset_sup (⟨⟨(↑), coe_sup⟩, coe_bot⟩ : SupBotHom (Opens α) (Set α)) _ _ @[simp, norm_cast] theorem coe_finset_inf (f : ι → Opens α) (s : Finset ι) : (↑(s.inf f) : Set α) = s.inf ((↑) ∘ f) := map_finset_inf (⟨⟨(↑), coe_inf⟩, coe_top⟩ : InfTopHom (Opens α) (Set α)) _ _ instance : Inhabited (Opens α) := ⟨⊥⟩ instance [IsEmpty α] : Unique (Opens α) where uniq _ := ext <| Subsingleton.elim _ _ instance [Nonempty α] : Nontrivial (Opens α) where exists_pair_ne := ⟨⊥, ⊤, mt coe_inj.2 empty_ne_univ⟩ @[simp, norm_cast] theorem coe_iSup {ι} (s : ι → Opens α) : ((⨆ i, s i : Opens α) : Set α) = ⋃ i, s i := by simp [iSup] theorem iSup_def {ι} (s : ι → Opens α) : ⨆ i, s i = ⟨⋃ i, s i, isOpen_iUnion fun i => (s i).2⟩ := ext <| coe_iSup s @[simp] theorem iSup_mk {ι} (s : ι → Set α) (h : ∀ i, IsOpen (s i)) : (⨆ i, ⟨s i, h i⟩ : Opens α) = ⟨⋃ i, s i, isOpen_iUnion h⟩ := iSup_def _ @[simp] theorem mem_iSup {ι} {x : α} {s : ι → Opens α} : x ∈ iSup s ↔ ∃ i, x ∈ s i := by rw [← SetLike.mem_coe] simp @[simp] theorem mem_sSup {Us : Set (Opens α)} {x : α} : x ∈ sSup Us ↔ ∃ u ∈ Us, x ∈ u := by simp_rw [sSup_eq_iSup, mem_iSup, exists_prop] /-- Open sets in a topological space form a frame. -/ def frameMinimalAxioms : Frame.MinimalAxioms (Opens α) where inf_sSup_le_iSup_inf a s := (ext <| by simp only [coe_inf, coe_iSup, coe_sSup, Set.inter_iUnion₂]).le instance instFrame : Frame (Opens α) := .ofMinimalAxioms frameMinimalAxioms theorem isOpenEmbedding' (U : Opens α) : IsOpenEmbedding (Subtype.val : U → α) := U.isOpen.isOpenEmbedding_subtypeVal theorem isOpenEmbedding_of_le {U V : Opens α} (i : U ≤ V) : IsOpenEmbedding (Set.inclusion <| SetLike.coe_subset_coe.2 i) where toIsEmbedding := .inclusion i isOpen_range := by rw [Set.range_inclusion i] exact U.isOpen.preimage continuous_subtype_val theorem not_nonempty_iff_eq_bot (U : Opens α) : ¬Set.Nonempty (U : Set α) ↔ U = ⊥ := by rw [← coe_inj, coe_bot, ← Set.not_nonempty_iff_eq_empty] theorem ne_bot_iff_nonempty (U : Opens α) : U ≠ ⊥ ↔ Set.Nonempty (U : Set α) := by rw [Ne, ← not_nonempty_iff_eq_bot, not_not] /-- An open set in the indiscrete topology is either empty or the whole space. -/ theorem eq_bot_or_top {α} [t : TopologicalSpace α] (h : t = ⊤) (U : Opens α) : U = ⊥ ∨ U = ⊤ := by subst h; letI : TopologicalSpace α := ⊤ rw [← coe_eq_empty, ← coe_eq_univ, ← isOpen_top_iff] exact U.2 instance [Nonempty α] [Subsingleton α] : IsSimpleOrder (Opens α) where eq_bot_or_eq_top := eq_bot_or_top <| Subsingleton.elim _ _ /-- A set of `opens α` is a basis if the set of corresponding sets is a topological basis. -/ def IsBasis (B : Set (Opens α)) : Prop := IsTopologicalBasis (((↑) : _ → Set α) '' B) theorem isBasis_iff_nbhd {B : Set (Opens α)} : IsBasis B ↔ ∀ {U : Opens α} {x}, x ∈ U → ∃ U' ∈ B, x ∈ U' ∧ U' ≤ U := by constructor <;> intro h · rintro ⟨sU, hU⟩ x hx rcases h.mem_nhds_iff.mp (IsOpen.mem_nhds hU hx) with ⟨sV, ⟨⟨V, H₁, H₂⟩, hsV⟩⟩ refine ⟨V, H₁, ?_⟩ cases V dsimp at H₂ subst H₂ exact hsV · refine isTopologicalBasis_of_isOpen_of_nhds ?_ ?_ · rintro sU ⟨U, -, rfl⟩ exact U.2 · intro x sU hx hsU rcases @h ⟨sU, hsU⟩ x hx with ⟨V, hV, H⟩ exact ⟨V, ⟨V, hV, rfl⟩, H⟩ theorem isBasis_iff_cover {B : Set (Opens α)} : IsBasis B ↔ ∀ U : Opens α, ∃ Us, Us ⊆ B ∧ U = sSup Us := by constructor · intro hB U refine ⟨{ V : Opens α | V ∈ B ∧ V ≤ U }, fun U hU => hU.left, ext ?_⟩ rw [coe_sSup, hB.open_eq_sUnion' U.isOpen] simp_rw [sUnion_eq_biUnion, iUnion, mem_setOf_eq, iSup_and, iSup_image] rfl · intro h rw [isBasis_iff_nbhd] intro U x hx rcases h U with ⟨Us, hUs, rfl⟩ rcases mem_sSup.1 hx with ⟨U, Us, xU⟩ exact ⟨U, hUs Us, xU, le_sSup Us⟩ /-- If `α` has a basis consisting of compact opens, then an open set in `α` is compact open iff it is a finite union of some elements in the basis -/ theorem IsBasis.isCompact_open_iff_eq_finite_iUnion {ι : Type*} (b : ι → Opens α) (hb : IsBasis (Set.range b)) (hb' : ∀ i, IsCompact (b i : Set α)) (U : Set α) : IsCompact U ∧ IsOpen U ↔ ∃ s : Set ι, s.Finite ∧ U = ⋃ i ∈ s, b i := by apply isCompact_open_iff_eq_finite_iUnion_of_isTopologicalBasis fun i : ι => (b i).1 · convert (config := {transparency := .default}) hb ext simp · exact hb' lemma IsBasis.exists_finite_of_isCompact {B : Set (Opens α)} (hB : IsBasis B) {U : Opens α} (hU : IsCompact U.1) : ∃ Us ⊆ B, Us.Finite ∧ U = sSup Us := by classical obtain ⟨Us', hsub, hsup⟩ := isBasis_iff_cover.mp hB U obtain ⟨t, ht⟩ := hU.elim_finite_subcover (fun s : Us' ↦ s.1) (fun s ↦ s.1.2) (by simp [hsup]) refine ⟨Finset.image Subtype.val t, subset_trans (by simp) hsub, Finset.finite_toSet _, ?_⟩ exact le_antisymm (subset_trans ht (by simp)) (le_trans (sSup_le_sSup (by simp)) hsup.ge) lemma IsBasis.le_iff {α} {t₁ t₂ : TopologicalSpace α} {Us : Set (Opens α)} (hUs : @IsBasis α t₂ Us) : t₁ ≤ t₂ ↔ ∀ U ∈ Us, IsOpen[t₁] U := by conv_lhs => rw [hUs.eq_generateFrom] simp [Set.subset_def, le_generateFrom_iff_subset_isOpen] lemma isBasis_sigma {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {B : ∀ i, Set (Opens (α i))} (hB : ∀ i, IsBasis (B i)) : IsBasis (⋃ i : ι, (fun U ↦ ⟨Sigma.mk i '' U.1, isOpenMap_sigmaMk _ U.2⟩) '' B i) := by convert TopologicalSpace.IsTopologicalBasis.sigma hB simp only [IsBasis, Set.image_iUnion, ← Set.image_comp] simp lemma IsBasis.of_isInducing {B : Set (Opens β)} (H : IsBasis B) {f : α → β} (h : IsInducing f) : IsBasis { ⟨f ⁻¹' U, U.2.preimage h.continuous⟩ | U ∈ B } := by simp only [IsBasis] at H ⊢ convert H.isInducing h ext; simp @[simp] theorem isCompactElement_iff (s : Opens α) : CompleteLattice.IsCompactElement s ↔ IsCompact (s : Set α) := by rw [isCompact_iff_finite_subcover, CompleteLattice.isCompactElement_iff] refine ⟨?_, fun H ι U hU => ?_⟩ · introv H hU hU' obtain ⟨t, ht⟩ := H ι (fun i => ⟨U i, hU i⟩) (by simpa) refine ⟨t, Set.Subset.trans ht ?_⟩ rw [coe_finset_sup, Finset.sup_eq_iSup] rfl · obtain ⟨t, ht⟩ := H (fun i => U i) (fun i => (U i).isOpen) (by simpa using show (s : Set α) ⊆ ↑(iSup U) from hU) refine ⟨t, Set.Subset.trans ht ?_⟩ simp only [Set.iUnion_subset_iff] change ∀ i ∈ t, U i ≤ t.sup U exact fun i => Finset.le_sup /-- The preimage of an open set, as an open set. -/ def comap (f : C(α, β)) : FrameHom (Opens β) (Opens α) where toFun s := ⟨f ⁻¹' s, s.2.preimage f.continuous⟩ map_sSup' s := ext <| by simp only [coe_sSup, preimage_iUnion, biUnion_image, coe_mk] map_inf' _ _ := rfl map_top' := rfl @[simp] theorem comap_id : comap (ContinuousMap.id α) = FrameHom.id _ := FrameHom.ext fun _ => ext rfl theorem comap_mono (f : C(α, β)) {s t : Opens β} (h : s ≤ t) : comap f s ≤ comap f t := OrderHomClass.mono (comap f) h @[simp] theorem coe_comap (f : C(α, β)) (U : Opens β) : ↑(comap f U) = f ⁻¹' U := rfl @[simp] theorem mem_comap {f : C(α, β)} {U : Opens β} {x : α} : x ∈ comap f U ↔ f x ∈ U := .rfl protected theorem comap_comp (g : C(β, γ)) (f : C(α, β)) : comap (g.comp f) = (comap f).comp (comap g) := rfl protected theorem comap_comap (g : C(β, γ)) (f : C(α, β)) (U : Opens γ) : comap f (comap g U) = comap (g.comp f) U := rfl theorem comap_injective [T0Space β] : Injective (comap : C(α, β) → FrameHom (Opens β) (Opens α)) := fun f g h => ContinuousMap.ext fun a => Inseparable.eq <| inseparable_iff_forall_isOpen.2 fun s hs => have : comap f ⟨s, hs⟩ = comap g ⟨s, hs⟩ := DFunLike.congr_fun h ⟨_, hs⟩ show a ∈ f ⁻¹' s ↔ a ∈ g ⁻¹' s from Set.ext_iff.1 (coe_inj.2 this) a /-- A homeomorphism induces an order-preserving equivalence on open sets, by taking comaps. -/ @[simps -fullyApplied apply] def _root_.Homeomorph.opensCongr (f : α ≃ₜ β) : Opens α ≃o Opens β where toFun := Opens.comap (f.symm : C(β, α)) invFun := Opens.comap (f : C(α, β)) left_inv _ := ext <| f.toEquiv.preimage_symm_preimage _ right_inv _ := ext <| f.toEquiv.symm_preimage_preimage _ map_rel_iff' := by simp only [← SetLike.coe_subset_coe]; exact f.symm.surjective.preimage_subset_preimage_iff @[simp] theorem _root_.Homeomorph.opensCongr_symm (f : α ≃ₜ β) : f.opensCongr.symm = f.symm.opensCongr := rfl instance [Finite α] : Finite (Opens α) := Finite.of_injective _ SetLike.coe_injective end Opens /-- The open neighborhoods of a point. See also `Opens` or `nhds`. -/ structure OpenNhdsOf (x : α) extends Opens α where /-- The point `x` belongs to every `U : TopologicalSpace.OpenNhdsOf x`. -/ mem' : x ∈ carrier namespace OpenNhdsOf variable {x : α} theorem toOpens_injective : Injective (toOpens : OpenNhdsOf x → Opens α) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl instance : SetLike (OpenNhdsOf x) α where coe U := U.1 coe_injective' := SetLike.coe_injective.comp toOpens_injective instance canLiftSet : CanLift (Set α) (OpenNhdsOf x) (↑) fun s => IsOpen s ∧ x ∈ s := ⟨fun s hs => ⟨⟨⟨s, hs.1⟩, hs.2⟩, rfl⟩⟩ protected theorem mem (U : OpenNhdsOf x) : x ∈ U := U.mem' protected theorem isOpen (U : OpenNhdsOf x) : IsOpen (U : Set α) := U.is_open' instance : OrderTop (OpenNhdsOf x) where top := ⟨⊤, Set.mem_univ _⟩ le_top _ := subset_univ _ instance : Inhabited (OpenNhdsOf x) := ⟨⊤⟩ instance : Min (OpenNhdsOf x) := ⟨fun U V => ⟨U.1 ⊓ V.1, U.2, V.2⟩⟩ instance : Max (OpenNhdsOf x) := ⟨fun U V => ⟨U.1 ⊔ V.1, Or.inl U.2⟩⟩ instance [Subsingleton α] : Unique (OpenNhdsOf x) where uniq U := SetLike.ext' <| Subsingleton.eq_univ_of_nonempty ⟨x, U.mem⟩ instance : DistribLattice (OpenNhdsOf x) := toOpens_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl theorem basis_nhds : (𝓝 x).HasBasis (fun _ : OpenNhdsOf x => True) (↑) := (nhds_basis_opens x).to_hasBasis (fun U hU => ⟨⟨⟨U, hU.2⟩, hU.1⟩, trivial, Subset.rfl⟩) fun U _ => ⟨U, ⟨⟨U.mem, U.isOpen⟩, Subset.rfl⟩⟩ /-- Preimage of an open neighborhood of `f x` under a continuous map `f` as a `LatticeHom`. -/ def comap (f : C(α, β)) (x : α) : LatticeHom (OpenNhdsOf (f x)) (OpenNhdsOf x) where toFun U := ⟨Opens.comap f U.1, U.mem⟩ map_sup' _ _ := rfl map_inf' _ _ := rfl end OpenNhdsOf end TopologicalSpace -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: once we port `auto_cases`, port this -- namespace Tactic -- namespace AutoCases -- /-- Find an `auto_cases_tac` which matches `TopologicalSpace.Opens`. -/ -- unsafe def opens_find_tac : expr → Option auto_cases_tac -- | q(TopologicalSpace.Opens _) => tac_cases -- | _ => none -- end AutoCases -- /-- A version of `tactic.auto_cases` that works for `TopologicalSpace.Opens`. -/ -- @[hint_tactic] -- unsafe def auto_cases_opens : tactic String := -- auto_cases tactic.auto_cases.opens_find_tac -- end Tactic
.lake/packages/mathlib/Mathlib/Topology/Sets/CompactOpenCovered.lean
import Mathlib.Data.Finite.Sigma import Mathlib.Topology.Spectral.Prespectral /-! # Compact open covered sets In this file we define the notion of a compact-open covered set with respect to a family of maps `fᵢ : X i → S`. A set `U` is compact-open covered by the family `fᵢ` if it is the finite union of images of compact open sets in the `X i`. This notion is not interesting, if the `fᵢ` are open maps (see `IsCompactOpenCovered.of_isOpenMap`). This is used to define the fpqc topology of schemes, there a cover is given by a family of flat morphisms such that every compact open is compact-open covered. ## Main results - `IsCompactOpenCovered.of_isOpenMap`: If all the `fᵢ` are open maps, then every compact open of `S` is compact-open covered. -/ open TopologicalSpace Opens /-- A set `U` is compact-open covered by the family `fᵢ : X i → S`, if `U` is the finite union of images of compact open sets in the `X i`. -/ def IsCompactOpenCovered {S ι : Type*} {X : ι → Type*} (f : ∀ i, X i → S) [∀ i, TopologicalSpace (X i)] (U : Set S) : Prop := ∃ (s : Set ι) (_ : s.Finite) (V : ∀ i ∈ s, Opens (X i)), (∀ (i : ι) (h : i ∈ s), IsCompact (V i h).1) ∧ ⋃ (i : ι) (h : i ∈ s), (f i) '' (V i h) = U namespace IsCompactOpenCovered variable {S ι : Type*} {X : ι → Type*} {f : ∀ i, X i → S} [∀ i, TopologicalSpace (X i)] {U : Set S} lemma empty : IsCompactOpenCovered f ∅ := ⟨∅, Set.finite_empty, fun _ _ ↦ ⟨∅, isOpen_empty⟩, fun _ _ ↦ isCompact_empty, by simp⟩ lemma iff_of_unique [Unique ι] : IsCompactOpenCovered f U ↔ ∃ (V : Opens (X default)), IsCompact V.1 ∧ f default '' V.1 = U := by refine ⟨fun ⟨s, hs, V, hc, hcov⟩ ↦ ?_, fun ⟨V, hc, h⟩ ↦ ?_⟩ · by_cases h : s = ∅ · aesop · obtain rfl : s = {default} := by rw [← Set.univ_unique, Subsingleton.eq_univ_of_nonempty (Set.nonempty_iff_ne_empty.mpr h)] aesop · refine ⟨{default}, Set.finite_singleton _, fun i h ↦ h ▸ V, fun i ↦ ?_, by simpa⟩ rintro rfl simpa lemma id_iff_isOpen_and_isCompact [TopologicalSpace S] : IsCompactOpenCovered (fun _ : Unit ↦ id) U ↔ IsOpen U ∧ IsCompact U := by rw [iff_of_unique] refine ⟨fun ⟨V, hV, heq⟩ ↦ ?_, fun ⟨ho, hc⟩ ↦ ⟨⟨U, ho⟩, hc, by simp⟩⟩ simp only [id_eq, Set.image_id', carrier_eq_coe, ← heq] at heq ⊢ exact ⟨V.2, hV⟩ lemma iff_isCompactOpenCovered_sigmaMk : IsCompactOpenCovered f U ↔ IsCompactOpenCovered (fun (_ : Unit) (p : Σ i : ι, X i) ↦ f p.1 p.2) U := by classical rw [iff_of_unique (ι := Unit)] refine ⟨fun ⟨s, hs, V, hc, hU⟩ ↦ ?_, fun ⟨V, hc, heq⟩ ↦ ?_⟩ · refine ⟨⟨s.sigma fun i ↦ if h : i ∈ s then V i h else ∅, isOpen_sigma_iff.mpr ?_⟩, ?_, ?_⟩ · intro i by_cases h : i ∈ s · simpa [h] using (V _ _).2 · simp [h] · dsimp only exact Set.isCompact_sigma hs fun i ↦ (by simp_all) · aesop · obtain ⟨s, t, hs, hc, heq'⟩ := hc.sigma_exists_finite_sigma_eq have (i : ι) (hi : i ∈ s) : IsOpen (t i) := by rw [← Set.mk_preimage_sigma (t := t) hi] exact isOpen_sigma_iff.mp (heq' ▸ V.2) i refine ⟨s, hs, fun i hi ↦ ⟨t i, this i hi⟩, fun i _ ↦ hc i, ?_⟩ simp_rw [coe_mk, ← heq, ← heq', Set.image_sigma_eq_iUnion, Function.comp_apply] lemma of_iUnion_eq_of_finite (s : Set (Set S)) (hs : ⋃ t ∈ s, t = U) (hf : s.Finite) (H : ∀ t ∈ s, IsCompactOpenCovered f t) : IsCompactOpenCovered f U := by rw [iff_isCompactOpenCovered_sigmaMk, iff_of_unique] have (t) (h : t ∈ s) : ∃ (V : Opens (Σ i, X i)), IsCompact V.1 ∧ (fun p ↦ f p.fst p.snd) '' V.carrier = t := by have := H t h rwa [iff_isCompactOpenCovered_sigmaMk, iff_of_unique] at this choose V hVeq hVc using this refine ⟨⨆ (t : s), V t t.2, ?_, ?_⟩ · simp only [Opens.iSup_mk, Opens.carrier_eq_coe, Opens.coe_mk] have : Finite s := hf exact isCompact_iUnion (fun _ ↦ hVeq _ _) · simp [Set.image_iUnion, ← hs] simp_all /-- If `U` is compact-open covered and the `X i` have a basis of compact opens, `U` can be written as the union of images of elements of the basis. -/ lemma exists_mem_of_isBasis {B : ∀ i, Set (Opens (X i))} (hB : ∀ i, IsBasis (B i)) (hBc : ∀ (i : ι), ∀ U ∈ B i, IsCompact U.1) {U : Set S} (hU : IsCompactOpenCovered f U) : ∃ (n : ℕ) (a : Fin n → ι) (V : ∀ i, Opens (X (a i))), (∀ i, V i ∈ B (a i)) ∧ ⋃ i, f (a i) '' V i = U := by suffices h : ∃ (κ : Type _) (_ : Finite κ) (a : κ → ι) (V : ∀ i, Opens (X (a i))), (∀ i, V i ∈ B (a i)) ∧ (∀ i, IsCompact (V i).1) ∧ ⋃ i, f (a i) '' V i = U by obtain ⟨κ, _, a, V, hB, hc, hU⟩ := h cases nonempty_fintype κ refine ⟨Fintype.card κ, a ∘ (Fintype.equivFin κ).symm, fun i ↦ V _, fun i ↦ hB _, ?_⟩ simp [← hU, ← (Fintype.equivFin κ).symm.surjective.iUnion_comp, Function.comp_apply] obtain ⟨s, hs, V, hc, hunion⟩ := hU choose Us UsB hUsf hUs using fun i : s ↦ (hB i.1).exists_finite_of_isCompact (hc i i.2) let σ := Σ i : s, Us i have : Finite s := hs have (i : _) : Finite (Us i) := hUsf i refine ⟨σ, inferInstance, fun i ↦ i.1.1, fun i ↦ i.2.1, fun i ↦ UsB _ (by simp), fun _ ↦ hBc _ _ (UsB _ (by simp)), ?_⟩ rw [← hunion] ext x simp_rw [Set.mem_iUnion] refine ⟨fun ⟨i, hi, o, ho⟩ ↦ by aesop, fun ⟨i, hi, h, hmem, heq⟩ ↦ ?_⟩ rw [hUs ⟨i, hi⟩, coe_sSup, Set.mem_iUnion] at hmem obtain ⟨a, ha⟩ := hmem simp only [Set.mem_iUnion, SetLike.mem_coe, exists_prop] at ha use ⟨⟨i, hi⟩, ⟨a, ha.1⟩⟩, h, ha.2, heq lemma of_isOpenMap [TopologicalSpace S] [∀ i, PrespectralSpace (X i)] (hfc : ∀ i, Continuous (f i)) (h : ∀ i, IsOpenMap (f i)) {U : Set S} (hs : ∀ x ∈ U, ∃ i y, f i y = x) (hU : IsOpen U) (hc : IsCompact U) : IsCompactOpenCovered f U := by rw [iff_isCompactOpenCovered_sigmaMk, iff_of_unique] refine (isOpenMap_sigma.mpr h).exists_opens_image_eq_of_prespectralSpace (continuous_sigma_iff.mpr hfc) (fun x hx ↦ ?_) hU hc simpa using hs x hx end IsCompactOpenCovered
.lake/packages/mathlib/Mathlib/Topology/Sets/Order.lean
import Mathlib.Topology.Sets.Closeds /-! # Clopen upper sets In this file we define the type of clopen upper sets. -/ open Set TopologicalSpace variable {α : Type*} [TopologicalSpace α] [LE α] /-! ### Compact open sets -/ /-- The type of clopen upper sets of a topological space. -/ structure ClopenUpperSet (α : Type*) [TopologicalSpace α] [LE α] extends Clopens α where upper' : IsUpperSet carrier namespace ClopenUpperSet instance : SetLike (ClopenUpperSet α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : ClopenUpperSet α) : Set α := s initialize_simps_projections ClopenUpperSet (carrier → coe, as_prefix coe) theorem upper (s : ClopenUpperSet α) : IsUpperSet (s : Set α) := s.upper' theorem isClopen (s : ClopenUpperSet α) : IsClopen (s : Set α) := s.isClopen' /-- Reinterpret an upper clopen as an upper set. -/ @[simps] def toUpperSet (s : ClopenUpperSet α) : UpperSet α := ⟨s, s.upper⟩ @[ext] protected theorem ext {s t : ClopenUpperSet α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Clopens α) (h) : (mk s h : Set α) = s := rfl instance : Max (ClopenUpperSet α) := ⟨fun s t => ⟨s.toClopens ⊔ t.toClopens, s.upper.union t.upper⟩⟩ instance : Min (ClopenUpperSet α) := ⟨fun s t => ⟨s.toClopens ⊓ t.toClopens, s.upper.inter t.upper⟩⟩ instance : Top (ClopenUpperSet α) := ⟨⟨⊤, isUpperSet_univ⟩⟩ instance : Bot (ClopenUpperSet α) := ⟨⟨⊥, isUpperSet_empty⟩⟩ instance : Lattice (ClopenUpperSet α) := SetLike.coe_injective.lattice _ (fun _ _ => rfl) fun _ _ => rfl instance : BoundedOrder (ClopenUpperSet α) := BoundedOrder.lift ((↑) : _ → Set α) (fun _ _ => id) rfl rfl @[simp] theorem coe_sup (s t : ClopenUpperSet α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := rfl @[simp] theorem coe_inf (s t : ClopenUpperSet α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t := rfl @[simp] theorem coe_top : (↑(⊤ : ClopenUpperSet α) : Set α) = univ := rfl @[simp] theorem coe_bot : (↑(⊥ : ClopenUpperSet α) : Set α) = ∅ := rfl instance : Inhabited (ClopenUpperSet α) := ⟨⊥⟩ end ClopenUpperSet
.lake/packages/mathlib/Mathlib/Topology/Sets/Compacts.lean
import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.QuasiSeparated /-! # Compact sets We define a few types of compact sets in a topological space. ## Main Definitions For a topological space `α`, * `TopologicalSpace.Compacts α`: The type of compact sets. * `TopologicalSpace.NonemptyCompacts α`: The type of non-empty compact sets. * `TopologicalSpace.PositiveCompacts α`: The type of compact sets with non-empty interior. * `TopologicalSpace.CompactOpens α`: The type of compact open sets. This is a central object in the study of spectral spaces. -/ open Set variable {α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] namespace TopologicalSpace /-! ### Compact sets -/ /-- The type of compact sets of a topological space. -/ structure Compacts (α : Type*) [TopologicalSpace α] where /-- the carrier set, i.e. the points in this set -/ carrier : Set α isCompact' : IsCompact carrier namespace Compacts instance : SetLike (Compacts α) α where coe := Compacts.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : Compacts α) : Set α := s initialize_simps_projections Compacts (carrier → coe, as_prefix coe) protected theorem isCompact (s : Compacts α) : IsCompact (s : Set α) := s.isCompact' instance (K : Compacts α) : CompactSpace K := isCompact_iff_compactSpace.1 K.isCompact /-- Reinterpret a compact as a closed set. -/ @[simps] def toCloseds [T2Space α] (s : Compacts α) : Closeds α := ⟨s, s.isCompact.isClosed⟩ @[simp] theorem mem_toCloseds [T2Space α] {x : α} {s : Compacts α} : x ∈ s.toCloseds ↔ x ∈ s := Iff.rfl instance : CanLift (Set α) (Compacts α) (↑) IsCompact where prf K hK := ⟨⟨K, hK⟩, rfl⟩ @[ext] protected theorem ext {s t : Compacts α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Set α) (h) : (mk s h : Set α) = s := rfl @[simp] theorem carrier_eq_coe (s : Compacts α) : s.carrier = s := rfl instance : Max (Compacts α) := ⟨fun s t => ⟨s ∪ t, s.isCompact.union t.isCompact⟩⟩ instance [T2Space α] : Min (Compacts α) := ⟨fun s t => ⟨s ∩ t, s.isCompact.inter t.isCompact⟩⟩ instance [CompactSpace α] : Top (Compacts α) := ⟨⟨univ, isCompact_univ⟩⟩ instance : Bot (Compacts α) := ⟨⟨∅, isCompact_empty⟩⟩ instance : SemilatticeSup (Compacts α) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [T2Space α] : DistribLattice (Compacts α) := SetLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl instance : OrderBot (Compacts α) := OrderBot.lift ((↑) : _ → Set α) (fun _ _ => id) rfl instance [CompactSpace α] : BoundedOrder (Compacts α) := BoundedOrder.lift ((↑) : _ → Set α) (fun _ _ => id) rfl rfl /-- The type of compact sets is inhabited, with default element the empty set. -/ instance : Inhabited (Compacts α) := ⟨⊥⟩ instance [IsEmpty α] : Unique (Compacts α) where uniq _ := Compacts.ext (Subsingleton.elim _ _) @[simp] theorem coe_sup (s t : Compacts α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := rfl @[simp] theorem coe_inf [T2Space α] (s t : Compacts α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t := rfl @[simp] theorem coe_top [CompactSpace α] : (↑(⊤ : Compacts α) : Set α) = univ := rfl @[simp] theorem coe_bot : (↑(⊥ : Compacts α) : Set α) = ∅ := rfl @[simp] theorem coe_finset_sup {ι : Type*} {s : Finset ι} {f : ι → Compacts α} : (↑(s.sup f) : Set α) = s.sup fun i => ↑(f i) := by refine Finset.cons_induction_on s rfl fun a s _ h => ?_ simp_rw [Finset.sup_cons, coe_sup, sup_eq_union] congr @[simps] instance : Singleton α (Compacts α) where singleton x := ⟨{x}, isCompact_singleton⟩ @[simp] theorem mem_singleton (x y : α) : x ∈ ({y} : Compacts α) ↔ x = y := Iff.rfl @[simp] theorem toCloseds_singleton [T2Space α] (x : α) : toCloseds {x} = Closeds.singleton x := rfl theorem singleton_injective : Function.Injective ({·} : α → Compacts α) := .of_comp (f := SetLike.coe) Set.singleton_injective @[simp] theorem singleton_inj {x y : α} : ({x} : Compacts α) = {y} ↔ x = y := singleton_injective.eq_iff instance [Nonempty α] : Nontrivial (Compacts α) := by constructor obtain ⟨x⟩ := ‹Nonempty α› exact ⟨⊥, {x}, ne_of_apply_ne SetLike.coe (Set.empty_ne_singleton x)⟩ @[simp] theorem subsingleton_iff : Subsingleton (Compacts α) ↔ IsEmpty α := by refine ⟨fun h => ?_, fun _ => inferInstance⟩ contrapose! h infer_instance @[simp] theorem nontrivial_iff : Nontrivial (Compacts α) ↔ Nonempty α := by rw [← not_subsingleton_iff_nontrivial, subsingleton_iff, not_isEmpty_iff] /-- The image of a compact set under a continuous function. -/ protected def map (f : α → β) (hf : Continuous f) (K : Compacts α) : Compacts β := ⟨f '' K.1, K.2.image hf⟩ @[simp, norm_cast] theorem coe_map {f : α → β} (hf : Continuous f) (s : Compacts α) : (s.map f hf : Set β) = f '' s := rfl @[simp] theorem map_id (K : Compacts α) : K.map id continuous_id = K := Compacts.ext <| Set.image_id _ theorem map_comp (f : β → γ) (g : α → β) (hf : Continuous f) (hg : Continuous g) (K : Compacts α) : K.map (f ∘ g) (hf.comp hg) = (K.map g hg).map f hf := Compacts.ext <| Set.image_comp _ _ _ theorem map_injective {f : α → β} (hf : Continuous f) (hf' : Function.Injective f) : Function.Injective (Compacts.map f hf) := .of_comp (f := SetLike.coe) <| hf'.image_injective.comp SetLike.coe_injective @[simp] theorem map_singleton {f : α → β} (hf : Continuous f) (x : α) : Compacts.map f hf {x} = {f x} := Compacts.ext Set.image_singleton @[simp] theorem map_injective_iff {f : α → β} (hf : Continuous f) : Function.Injective (Compacts.map f hf) ↔ Function.Injective f := by refine ⟨fun h => .of_comp (f := ({·} : β → Compacts β)) ?_, map_injective hf⟩ simp_rw [Function.comp_def, ← map_singleton hf] exact h.comp singleton_injective /-- A homeomorphism induces an equivalence on compact sets, by taking the image. -/ @[simps] protected def equiv (f : α ≃ₜ β) : Compacts α ≃ Compacts β where toFun := Compacts.map f f.continuous invFun := Compacts.map _ f.symm.continuous left_inv s := by ext1 simp only [coe_map, ← image_comp, f.symm_comp_self, image_id] right_inv s := by ext1 simp only [coe_map, ← image_comp, f.self_comp_symm, image_id] @[simp] theorem equiv_refl : Compacts.equiv (Homeomorph.refl α) = Equiv.refl _ := Equiv.ext map_id @[simp] theorem equiv_trans (f : α ≃ₜ β) (g : β ≃ₜ γ) : Compacts.equiv (f.trans g) = (Compacts.equiv f).trans (Compacts.equiv g) := Equiv.ext <| map_comp g f g.continuous f.continuous @[simp] theorem equiv_symm (f : α ≃ₜ β) : Compacts.equiv f.symm = (Compacts.equiv f).symm := rfl /-- The image of a compact set under a homeomorphism can also be expressed as a preimage. -/ theorem coe_equiv_apply_eq_preimage (f : α ≃ₜ β) (K : Compacts α) : (Compacts.equiv f K : Set β) = f.symm ⁻¹' (K : Set α) := f.toEquiv.image_eq_preimage_symm K /-- The product of two `TopologicalSpace.Compacts`, as a `TopologicalSpace.Compacts` in the product space. -/ protected def prod (K : Compacts α) (L : Compacts β) : Compacts (α × β) where carrier := K ×ˢ L isCompact' := IsCompact.prod K.2 L.2 @[simp] theorem coe_prod (K : Compacts α) (L : Compacts β) : (K.prod L : Set (α × β)) = (K : Set α) ×ˢ (L : Set β) := rfl @[simp] theorem singleton_prod_singleton (x : α) (y : β) : Compacts.prod {x} {y} = {(x, y)} := Compacts.ext Set.singleton_prod_singleton -- todo: add `pi` end Compacts /-! ### Nonempty compact sets -/ /-- The type of nonempty compact sets of a topological space. -/ structure NonemptyCompacts (α : Type*) [TopologicalSpace α] extends Compacts α where nonempty' : carrier.Nonempty namespace NonemptyCompacts instance : SetLike (NonemptyCompacts α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : NonemptyCompacts α) : Set α := s initialize_simps_projections NonemptyCompacts (carrier → coe, as_prefix coe) protected theorem isCompact (s : NonemptyCompacts α) : IsCompact (s : Set α) := s.isCompact' protected theorem nonempty (s : NonemptyCompacts α) : (s : Set α).Nonempty := s.nonempty' /-- Reinterpret a nonempty compact as a closed set. -/ @[simps] def toCloseds [T2Space α] (s : NonemptyCompacts α) : Closeds α := ⟨s, s.isCompact.isClosed⟩ @[simp] theorem toCloseds_toCompacts [T2Space α] (s : NonemptyCompacts α) : s.toCompacts.toCloseds = s.toCloseds := rfl @[simp] theorem mem_toCloseds [T2Space α] {x : α} {s : NonemptyCompacts α} : x ∈ s.toCloseds ↔ x ∈ s := Iff.rfl @[ext] protected theorem ext {s t : NonemptyCompacts α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Compacts α) (h) : (mk s h : Set α) = s := rfl theorem carrier_eq_coe (s : NonemptyCompacts α) : s.carrier = s := rfl @[simp] theorem coe_toCompacts (s : NonemptyCompacts α) : (s.toCompacts : Set α) = s := rfl @[simp] theorem mem_toCompacts {x : α} {s : NonemptyCompacts α} : x ∈ s.toCompacts ↔ x ∈ s := Iff.rfl instance : Max (NonemptyCompacts α) := ⟨fun s t => ⟨s.toCompacts ⊔ t.toCompacts, s.nonempty.mono subset_union_left⟩⟩ instance [CompactSpace α] [Nonempty α] : Top (NonemptyCompacts α) := ⟨⟨⊤, univ_nonempty⟩⟩ instance : SemilatticeSup (NonemptyCompacts α) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace α] [Nonempty α] : OrderTop (NonemptyCompacts α) := OrderTop.lift ((↑) : _ → Set α) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : NonemptyCompacts α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := rfl @[simp] theorem coe_top [CompactSpace α] [Nonempty α] : (↑(⊤ : NonemptyCompacts α) : Set α) = univ := rfl @[simps!] instance : Singleton α (NonemptyCompacts α) where singleton x := ⟨{x}, singleton_nonempty x⟩ @[simp] theorem mem_singleton (x y : α) : x ∈ ({y} : NonemptyCompacts α) ↔ x = y := Iff.rfl @[simp] theorem toCompacts_singleton (x : α) : toCompacts {x} = {x} := rfl @[simp] theorem toCloseds_singleton [T2Space α] (x : α) : toCloseds {x} = Closeds.singleton x := rfl theorem singleton_injective : Function.Injective ({·} : α → NonemptyCompacts α) := .of_comp (f := SetLike.coe) Set.singleton_injective @[simp] theorem singleton_inj {x y : α} : ({x} : NonemptyCompacts α) = {y} ↔ x = y := singleton_injective.eq_iff /-- In an inhabited space, the type of nonempty compact subsets is also inhabited, with default element the singleton set containing the default element. -/ instance [Inhabited α] : Inhabited (NonemptyCompacts α) := ⟨{default}⟩ instance [IsEmpty α] : IsEmpty (NonemptyCompacts α) := ⟨fun K => not_isEmpty_iff.mpr K.nonempty.to_type ‹_›⟩ @[simp] theorem isEmpty_iff : IsEmpty (NonemptyCompacts α) ↔ IsEmpty α := ⟨fun _ => Function.isEmpty ({·} : α → NonemptyCompacts α), fun _ => inferInstance⟩ instance [Nonempty α] : Nonempty (NonemptyCompacts α) := .map ({·}) ‹_› @[simp] theorem nonempty_iff : Nonempty (NonemptyCompacts α) ↔ Nonempty α := by simp_rw [← not_isEmpty_iff, isEmpty_iff] instance [Subsingleton α] : Subsingleton (NonemptyCompacts α) := by refine ⟨fun K L => NonemptyCompacts.ext ?_⟩ rw [Subsingleton.eq_univ_of_nonempty K.nonempty, Subsingleton.eq_univ_of_nonempty L.nonempty] @[simp] theorem subsingleton_iff : Subsingleton (NonemptyCompacts α) ↔ Subsingleton α := ⟨fun _ => singleton_injective.subsingleton, fun _ => inferInstance⟩ instance [Unique α] : Unique (NonemptyCompacts α) := .mk' _ instance [Nontrivial α] : Nontrivial (NonemptyCompacts α) := singleton_injective.nontrivial @[simp] theorem nontrivial_iff : Nontrivial (NonemptyCompacts α) ↔ Nontrivial α := by simp_rw [← not_subsingleton_iff_nontrivial, subsingleton_iff] instance toCompactSpace {s : NonemptyCompacts α} : CompactSpace s := isCompact_iff_compactSpace.1 s.isCompact instance toNonempty {s : NonemptyCompacts α} : Nonempty s := s.nonempty.to_subtype /-- The product of two `TopologicalSpace.NonemptyCompacts`, as a `TopologicalSpace.NonemptyCompacts` in the product space. -/ protected def prod (K : NonemptyCompacts α) (L : NonemptyCompacts β) : NonemptyCompacts (α × β) := { K.toCompacts.prod L.toCompacts with nonempty' := K.nonempty.prod L.nonempty } @[simp] theorem coe_prod (K : NonemptyCompacts α) (L : NonemptyCompacts β) : (K.prod L : Set (α × β)) = (K : Set α) ×ˢ (L : Set β) := rfl @[simp] theorem singleton_prod_singleton (x : α) (y : β) : NonemptyCompacts.prod {x} {y} = {(x, y)} := NonemptyCompacts.ext Set.singleton_prod_singleton end NonemptyCompacts /-! ### Positive compact sets -/ /-- The type of compact sets with nonempty interior of a topological space. See also `TopologicalSpace.Compacts` and `TopologicalSpace.NonemptyCompacts`. -/ structure PositiveCompacts (α : Type*) [TopologicalSpace α] extends Compacts α where interior_nonempty' : (interior carrier).Nonempty namespace PositiveCompacts instance : SetLike (PositiveCompacts α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : PositiveCompacts α) : Set α := s initialize_simps_projections PositiveCompacts (carrier → coe, as_prefix coe) protected theorem isCompact (s : PositiveCompacts α) : IsCompact (s : Set α) := s.isCompact' theorem interior_nonempty (s : PositiveCompacts α) : (interior (s : Set α)).Nonempty := s.interior_nonempty' protected theorem nonempty (s : PositiveCompacts α) : (s : Set α).Nonempty := s.interior_nonempty.mono interior_subset /-- Reinterpret a positive compact as a nonempty compact. -/ def toNonemptyCompacts (s : PositiveCompacts α) : NonemptyCompacts α := ⟨s.toCompacts, s.nonempty⟩ @[ext] protected theorem ext {s t : PositiveCompacts α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Compacts α) (h) : (mk s h : Set α) = s := rfl theorem carrier_eq_coe (s : PositiveCompacts α) : s.carrier = s := rfl @[simp] theorem coe_toCompacts (s : PositiveCompacts α) : (s.toCompacts : Set α) = s := rfl instance : Max (PositiveCompacts α) := ⟨fun s t => ⟨s.toCompacts ⊔ t.toCompacts, s.interior_nonempty.mono <| interior_mono subset_union_left⟩⟩ instance [CompactSpace α] [Nonempty α] : Top (PositiveCompacts α) := ⟨⟨⊤, interior_univ.symm.subst univ_nonempty⟩⟩ instance : SemilatticeSup (PositiveCompacts α) := SetLike.coe_injective.semilatticeSup _ fun _ _ => rfl instance [CompactSpace α] [Nonempty α] : OrderTop (PositiveCompacts α) := OrderTop.lift ((↑) : _ → Set α) (fun _ _ => id) rfl @[simp] theorem coe_sup (s t : PositiveCompacts α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := rfl @[simp] theorem coe_top [CompactSpace α] [Nonempty α] : (↑(⊤ : PositiveCompacts α) : Set α) = univ := rfl /-- The image of a positive compact set under a continuous open map. -/ protected def map (f : α → β) (hf : Continuous f) (hf' : IsOpenMap f) (K : PositiveCompacts α) : PositiveCompacts β := { Compacts.map f hf K.toCompacts with interior_nonempty' := (K.interior_nonempty'.image _).mono (hf'.image_interior_subset K.toCompacts) } @[simp, norm_cast] theorem coe_map {f : α → β} (hf : Continuous f) (hf' : IsOpenMap f) (s : PositiveCompacts α) : (s.map f hf hf' : Set β) = f '' s := rfl @[simp] theorem map_id (K : PositiveCompacts α) : K.map id continuous_id IsOpenMap.id = K := PositiveCompacts.ext <| Set.image_id _ theorem map_comp (f : β → γ) (g : α → β) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : PositiveCompacts α) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := PositiveCompacts.ext <| Set.image_comp _ _ _ theorem _root_.exists_positiveCompacts_subset [LocallyCompactSpace α] {U : Set α} (ho : IsOpen U) (hn : U.Nonempty) : ∃ K : PositiveCompacts α, ↑K ⊆ U := let ⟨x, hx⟩ := hn let ⟨K, hKc, hxK, hKU⟩ := exists_compact_subset ho hx ⟨⟨⟨K, hKc⟩, ⟨x, hxK⟩⟩, hKU⟩ theorem _root_.IsOpen.exists_positiveCompacts_closure_subset [R1Space α] [LocallyCompactSpace α] {U : Set α} (ho : IsOpen U) (hn : U.Nonempty) : ∃ K : PositiveCompacts α, closure ↑K ⊆ U := let ⟨K, hKU⟩ := exists_positiveCompacts_subset ho hn ⟨K, K.isCompact.closure_subset_of_isOpen ho hKU⟩ instance [CompactSpace α] [Nonempty α] : Inhabited (PositiveCompacts α) := ⟨⊤⟩ /-- In a nonempty locally compact space, there exists a compact set with nonempty interior. -/ instance nonempty' [WeaklyLocallyCompactSpace α] [Nonempty α] : Nonempty (PositiveCompacts α) := by inhabit α rcases exists_compact_mem_nhds (default : α) with ⟨K, hKc, hK⟩ exact ⟨⟨K, hKc⟩, _, mem_interior_iff_mem_nhds.2 hK⟩ /-- The product of two `TopologicalSpace.PositiveCompacts`, as a `TopologicalSpace.PositiveCompacts` in the product space. -/ protected def prod (K : PositiveCompacts α) (L : PositiveCompacts β) : PositiveCompacts (α × β) where toCompacts := K.toCompacts.prod L.toCompacts interior_nonempty' := by simp only [Compacts.carrier_eq_coe, Compacts.coe_prod, interior_prod_eq] exact K.interior_nonempty.prod L.interior_nonempty @[simp] theorem coe_prod (K : PositiveCompacts α) (L : PositiveCompacts β) : (K.prod L : Set (α × β)) = (K : Set α) ×ˢ (L : Set β) := rfl end PositiveCompacts /-! ### Compact open sets -/ /-- The type of compact open sets of a topological space. This is useful in non-Hausdorff contexts, in particular spectral spaces. -/ structure CompactOpens (α : Type*) [TopologicalSpace α] extends Compacts α where isOpen' : IsOpen carrier namespace CompactOpens instance : SetLike (CompactOpens α) α where coe s := s.carrier coe_injective' s t h := by obtain ⟨⟨_, _⟩, _⟩ := s obtain ⟨⟨_, _⟩, _⟩ := t congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : CompactOpens α) : Set α := s initialize_simps_projections CompactOpens (carrier → coe, as_prefix coe) protected theorem isCompact (s : CompactOpens α) : IsCompact (s : Set α) := s.isCompact' protected theorem isOpen (s : CompactOpens α) : IsOpen (s : Set α) := s.isOpen' /-- Reinterpret a compact open as an open. -/ @[simps] def toOpens (s : CompactOpens α) : Opens α := ⟨s, s.isOpen⟩ /-- Reinterpret a compact open as a clopen. -/ @[simps] def toClopens [T2Space α] (s : CompactOpens α) : Clopens α := ⟨s, s.isCompact.isClosed, s.isOpen⟩ @[ext] protected theorem ext {s t : CompactOpens α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Compacts α) (h) : (mk s h : Set α) = s := rfl instance : Max (CompactOpens α) := ⟨fun s t => ⟨s.toCompacts ⊔ t.toCompacts, s.isOpen.union t.isOpen⟩⟩ instance : Bot (CompactOpens α) where bot := ⟨⊥, isOpen_empty⟩ @[simp, norm_cast] lemma coe_sup (s t : CompactOpens α) : ↑(s ⊔ t) = (s ∪ t : Set α) := rfl @[simp, norm_cast] lemma coe_bot : ↑(⊥ : CompactOpens α) = (∅ : Set α) := rfl instance : SemilatticeSup (CompactOpens α) := SetLike.coe_injective.semilatticeSup _ coe_sup instance : OrderBot (CompactOpens α) := OrderBot.lift ((↑) : _ → Set α) (fun _ _ => id) coe_bot @[simp] lemma coe_finsetSup {ι : Type*} {f : ι → CompactOpens α} {s : Finset ι} : (↑(s.sup f) : Set α) = ⋃ i ∈ s, f i := by classical induction s using Finset.induction_on <;> simp [*] instance : Inhabited (CompactOpens α) := ⟨⊥⟩ section Inf variable [QuasiSeparatedSpace α] instance instInf : Min (CompactOpens α) where min U V := ⟨⟨U ∩ V, QuasiSeparatedSpace.inter_isCompact U.1.1 V.1.1 U.2 U.1.2 V.2 V.1.2⟩, U.2.inter V.2⟩ @[simp, norm_cast] lemma coe_inf (s t : CompactOpens α) : ↑(s ⊓ t) = (s ∩ t : Set α) := rfl instance instSemilatticeInf : SemilatticeInf (CompactOpens α) := SetLike.coe_injective.semilatticeInf _ coe_inf end Inf section SDiff variable [T2Space α] instance instSDiff : SDiff (CompactOpens α) where sdiff s t := ⟨⟨s \ t, s.isCompact.diff t.isOpen⟩, s.isOpen.sdiff t.isCompact.isClosed⟩ @[simp, norm_cast] lemma coe_sdiff (s t : CompactOpens α) : ↑(s \ t) = (s \ t : Set α) := rfl instance instGeneralizedBooleanAlgebra : GeneralizedBooleanAlgebra (CompactOpens α) := SetLike.coe_injective.generalizedBooleanAlgebra _ coe_sup coe_inf coe_bot coe_sdiff end SDiff section Top variable [CompactSpace α] instance instTop : Top (CompactOpens α) where top := ⟨⊤, isOpen_univ⟩ @[simp, norm_cast] lemma coe_top : ↑(⊤ : CompactOpens α) = (univ : Set α) := rfl instance instBoundedOrder : BoundedOrder (CompactOpens α) := BoundedOrder.lift ((↑) : _ → Set α) (fun _ _ => id) coe_top coe_bot section Compl variable [T2Space α] instance instHasCompl : HasCompl (CompactOpens α) where compl s := ⟨⟨sᶜ, s.isOpen.isClosed_compl.isCompact⟩, s.isCompact.isClosed.isOpen_compl⟩ instance instHImp : HImp (CompactOpens α) where himp s t := ⟨⟨s ⇨ t, IsClosed.isCompact (by simpa [himp_eq] using t.isCompact.isClosed.union s.isOpen.isClosed_compl)⟩, by simpa [himp_eq] using t.isOpen.union s.isCompact.isClosed.isOpen_compl⟩ @[simp, norm_cast] lemma coe_compl (s : CompactOpens α) : ↑sᶜ = (sᶜ : Set α) := rfl @[simp, norm_cast] lemma coe_himp (s t : CompactOpens α) : ↑(s ⇨ t) = (s ⇨ t : Set α) := rfl instance instBooleanAlgebra : BooleanAlgebra (CompactOpens α) := SetLike.coe_injective.booleanAlgebra _ coe_sup coe_inf coe_top coe_bot coe_compl coe_sdiff coe_himp end Top.Compl /-- The image of a compact open under a continuous open map. -/ @[simps toCompacts] def map (f : α → β) (hf : Continuous f) (hf' : IsOpenMap f) (s : CompactOpens α) : CompactOpens β := ⟨s.toCompacts.map f hf, hf' _ s.isOpen⟩ @[simp, norm_cast] theorem coe_map {f : α → β} (hf : Continuous f) (hf' : IsOpenMap f) (s : CompactOpens α) : (s.map f hf hf' : Set β) = f '' s := rfl @[simp] theorem map_id (K : CompactOpens α) : K.map id continuous_id IsOpenMap.id = K := CompactOpens.ext <| Set.image_id _ theorem map_comp (f : β → γ) (g : α → β) (hf : Continuous f) (hg : Continuous g) (hf' : IsOpenMap f) (hg' : IsOpenMap g) (K : CompactOpens α) : K.map (f ∘ g) (hf.comp hg) (hf'.comp hg') = (K.map g hg hg').map f hf hf' := CompactOpens.ext <| Set.image_comp _ _ _ /-- The product of two `TopologicalSpace.CompactOpens`, as a `TopologicalSpace.CompactOpens` in the product space. -/ protected def prod (K : CompactOpens α) (L : CompactOpens β) : CompactOpens (α × β) := { K.toCompacts.prod L.toCompacts with isOpen' := K.isOpen.prod L.isOpen } @[simp] theorem coe_prod (K : CompactOpens α) (L : CompactOpens β) : (K.prod L : Set (α × β)) = (K : Set α) ×ˢ (L : Set β) := rfl end CompactOpens end TopologicalSpace
.lake/packages/mathlib/Mathlib/Topology/Sets/Closeds.lean
import Mathlib.Topology.Sets.Opens import Mathlib.Topology.Clopen /-! # Closed sets We define a few types of closed sets in a topological space. ## Main Definitions For a topological space `α`, * `TopologicalSpace.Closeds α`: The type of closed sets. * `TopologicalSpace.Clopens α`: The type of clopen sets. -/ open Order OrderDual Set Topology variable {ι α β : Type*} [TopologicalSpace α] [TopologicalSpace β] namespace TopologicalSpace /-! ### Closed sets -/ /-- The type of closed subsets of a topological space. -/ structure Closeds (α : Type*) [TopologicalSpace α] where /-- the carrier set, i.e. the points in this set -/ carrier : Set α isClosed' : IsClosed carrier namespace Closeds instance : SetLike (Closeds α) α where coe := Closeds.carrier coe_injective' s t h := by cases s; cases t; congr instance : CanLift (Set α) (Closeds α) (↑) IsClosed where prf s hs := ⟨⟨s, hs⟩, rfl⟩ theorem isClosed (s : Closeds α) : IsClosed (s : Set α) := s.isClosed' /-- See Note [custom simps projection]. -/ def Simps.coe (s : Closeds α) : Set α := s initialize_simps_projections Closeds (carrier → coe, as_prefix coe) @[simp] lemma carrier_eq_coe (s : Closeds α) : s.carrier = (s : Set α) := rfl @[ext] protected theorem ext {s t : Closeds α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Set α) (h) : (mk s h : Set α) = s := rfl @[simp] lemma mem_mk {s : Set α} {hs : IsClosed s} {x : α} : x ∈ (⟨s, hs⟩ : Closeds α) ↔ x ∈ s := .rfl /-- The closure of a set, as an element of `TopologicalSpace.Closeds`. -/ @[simps] protected def closure (s : Set α) : Closeds α := ⟨closure s, isClosed_closure⟩ @[simp] theorem mem_closure {s : Set α} {x : α} : x ∈ Closeds.closure s ↔ x ∈ closure s := .rfl theorem gc : GaloisConnection Closeds.closure ((↑) : Closeds α → Set α) := fun _ U => ⟨subset_closure.trans, fun h => closure_minimal h U.isClosed⟩ @[simp] lemma closure_le {s : Set α} {t : Closeds α} : .closure s ≤ t ↔ s ⊆ t := t.isClosed.closure_subset_iff /-- The Galois insertion between sets and closeds. -/ def gi : GaloisInsertion (@Closeds.closure α _) (↑) where choice s hs := ⟨s, closure_eq_iff_isClosed.1 <| hs.antisymm subset_closure⟩ gc := gc le_l_u _ := subset_closure choice_eq _s hs := SetLike.coe_injective <| subset_closure.antisymm hs instance instCompleteLattice : CompleteLattice (Closeds α) := CompleteLattice.copy (GaloisInsertion.liftCompleteLattice gi) -- le _ rfl -- top ⟨univ, isClosed_univ⟩ rfl -- bot ⟨∅, isClosed_empty⟩ (SetLike.coe_injective closure_empty.symm) -- sup (fun s t => ⟨s ∪ t, s.2.union t.2⟩) (funext fun s => funext fun t => SetLike.coe_injective (s.2.union t.2).closure_eq.symm) -- inf (fun s t => ⟨s ∩ t, s.2.inter t.2⟩) rfl -- sSup _ rfl -- sInf (fun S => ⟨⋂ s ∈ S, ↑s, isClosed_biInter fun s _ => s.2⟩) (funext fun _ => SetLike.coe_injective sInf_image.symm) /-- The type of closed sets is inhabited, with default element the empty set. -/ instance : Inhabited (Closeds α) := ⟨⊥⟩ @[simp, norm_cast] theorem coe_sup (s t : Closeds α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := by rfl @[simp, norm_cast] theorem coe_inf (s t : Closeds α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t := rfl @[simp, norm_cast] theorem coe_top : (↑(⊤ : Closeds α) : Set α) = univ := rfl @[simp, norm_cast] theorem coe_eq_univ {s : Closeds α} : (s : Set α) = univ ↔ s = ⊤ := SetLike.coe_injective.eq_iff' rfl @[simp, norm_cast] theorem coe_bot : (↑(⊥ : Closeds α) : Set α) = ∅ := rfl @[simp, norm_cast] theorem coe_eq_empty {s : Closeds α} : (s : Set α) = ∅ ↔ s = ⊥ := SetLike.coe_injective.eq_iff' rfl theorem coe_nonempty {s : Closeds α} : (s : Set α).Nonempty ↔ s ≠ ⊥ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sInf {S : Set (Closeds α)} : (↑(sInf S) : Set α) = ⋂ i ∈ S, ↑i := rfl @[simp] lemma coe_sSup {S : Set (Closeds α)} : ((sSup S : Closeds α) : Set α) = closure (⋃₀ ((↑) '' S)) := by rfl @[simp, norm_cast] theorem coe_finset_sup (f : ι → Closeds α) (s : Finset ι) : (↑(s.sup f) : Set α) = s.sup ((↑) ∘ f) := map_finset_sup (⟨⟨(↑), coe_sup⟩, coe_bot⟩ : SupBotHom (Closeds α) (Set α)) _ _ @[simp, norm_cast] theorem coe_finset_inf (f : ι → Closeds α) (s : Finset ι) : (↑(s.inf f) : Set α) = s.inf ((↑) ∘ f) := map_finset_inf (⟨⟨(↑), coe_inf⟩, coe_top⟩ : InfTopHom (Closeds α) (Set α)) _ _ @[simp] theorem mem_sInf {S : Set (Closeds α)} {x : α} : x ∈ sInf S ↔ ∀ s ∈ S, x ∈ s := mem_iInter₂ @[simp] theorem mem_iInf {ι} {x : α} {s : ι → Closeds α} : x ∈ iInf s ↔ ∀ i, x ∈ s i := by simp [iInf] @[simp, norm_cast] theorem coe_iInf {ι} (s : ι → Closeds α) : ((⨅ i, s i : Closeds α) : Set α) = ⋂ i, s i := by ext; simp theorem iInf_def {ι} (s : ι → Closeds α) : ⨅ i, s i = ⟨⋂ i, s i, isClosed_iInter fun i => (s i).2⟩ := by ext1; simp @[simp] theorem iInf_mk {ι} (s : ι → Set α) (h : ∀ i, IsClosed (s i)) : (⨅ i, ⟨s i, h i⟩ : Closeds α) = ⟨⋂ i, s i, isClosed_iInter h⟩ := iInf_def _ /-- Closed sets in a topological space form a coframe. -/ def coframeMinimalAxioms : Coframe.MinimalAxioms (Closeds α) where iInf_sup_le_sup_sInf a s := (SetLike.coe_injective <| by simp only [coe_sup, coe_iInf, coe_sInf, Set.union_iInter₂]).le instance instCoframe : Coframe (Closeds α) := .ofMinimalAxioms coframeMinimalAxioms /-- The term of `TopologicalSpace.Closeds α` corresponding to a singleton. -/ @[simps] def singleton [T1Space α] (x : α) : Closeds α := ⟨{x}, isClosed_singleton⟩ @[simp] lemma mem_singleton [T1Space α] {a b : α} : a ∈ singleton b ↔ a = b := Iff.rfl theorem singleton_injective [T1Space α] : Function.Injective (singleton (α := α)) := .of_comp (f := SetLike.coe) Set.singleton_injective @[simp] theorem singleton_inj [T1Space α] {x y : α} : singleton x = singleton y ↔ x = y := singleton_injective.eq_iff /-- The preimage of a closed set under a continuous map. -/ @[simps] def preimage (s : Closeds β) {f : α → β} (hf : Continuous f) : Closeds α := ⟨f ⁻¹' s, s.isClosed.preimage hf⟩ end Closeds /-- The complement of a closed set as an open set. -/ @[simps] def Closeds.compl (s : Closeds α) : Opens α := ⟨sᶜ, s.2.isOpen_compl⟩ /-- The complement of an open set as a closed set. -/ @[simps] def Opens.compl (s : Opens α) : Closeds α := ⟨sᶜ, s.2.isClosed_compl⟩ nonrec theorem Closeds.compl_compl (s : Closeds α) : s.compl.compl = s := Closeds.ext (compl_compl (s : Set α)) nonrec theorem Opens.compl_compl (s : Opens α) : s.compl.compl = s := Opens.ext (compl_compl (s : Set α)) theorem Closeds.compl_bijective : Function.Bijective (@Closeds.compl α _) := Function.bijective_iff_has_inverse.mpr ⟨Opens.compl, Closeds.compl_compl, Opens.compl_compl⟩ theorem Opens.compl_bijective : Function.Bijective (@Opens.compl α _) := Function.bijective_iff_has_inverse.mpr ⟨Closeds.compl, Opens.compl_compl, Closeds.compl_compl⟩ variable (α) /-- `TopologicalSpace.Closeds.compl` as an `OrderIso` to the order dual of `TopologicalSpace.Opens α`. -/ @[simps] def Closeds.complOrderIso : Closeds α ≃o (Opens α)ᵒᵈ where toFun := OrderDual.toDual ∘ Closeds.compl invFun := Opens.compl ∘ OrderDual.ofDual left_inv s := by simp [Closeds.compl_compl] right_inv s := by simp [Opens.compl_compl] map_rel_iff' := (@OrderDual.toDual_le_toDual (Opens α)).trans compl_subset_compl /-- `TopologicalSpace.Opens.compl` as an `OrderIso` to the order dual of `TopologicalSpace.Closeds α`. -/ @[simps] def Opens.complOrderIso : Opens α ≃o (Closeds α)ᵒᵈ where toFun := OrderDual.toDual ∘ Opens.compl invFun := Closeds.compl ∘ OrderDual.ofDual left_inv s := by simp [Opens.compl_compl] right_inv s := by simp [Closeds.compl_compl] map_rel_iff' := (@OrderDual.toDual_le_toDual (Closeds α)).trans compl_subset_compl variable {α} lemma Closeds.coe_eq_singleton_of_isAtom [T0Space α] {s : Closeds α} (hs : IsAtom s) : ∃ a, (s : Set α) = {a} := by refine minimal_nonempty_closed_eq_singleton s.2 (coe_nonempty.2 hs.1) fun t hts ht ht' ↦ ?_ lift t to Closeds α using ht' exact SetLike.coe_injective.eq_iff.2 <| (hs.le_iff_eq <| coe_nonempty.1 ht).1 hts @[simp, norm_cast] lemma Closeds.isAtom_coe [T1Space α] {s : Closeds α} : IsAtom (s : Set α) ↔ IsAtom s := Closeds.gi.isAtom_iff' rfl (fun t ht ↦ by obtain ⟨x, rfl⟩ := Set.isAtom_iff.1 ht; exact closure_singleton) s /-- in a `T1Space`, atoms of `TopologicalSpace.Closeds α` are precisely the `TopologicalSpace.Closeds.singleton`s. -/ theorem Closeds.isAtom_iff [T1Space α] {s : Closeds α} : IsAtom s ↔ ∃ x, s = Closeds.singleton x := by simp [← Closeds.isAtom_coe, Set.isAtom_iff, SetLike.ext_iff, Set.ext_iff] /-- in a `T1Space`, coatoms of `TopologicalSpace.Opens α` are precisely complements of singletons: `(TopologicalSpace.Closeds.singleton x).compl`. -/ theorem Opens.isCoatom_iff [T1Space α] {s : Opens α} : IsCoatom s ↔ ∃ x, s = (Closeds.singleton x).compl := by rw [← s.compl_compl, ← isAtom_dual_iff_isCoatom] change IsAtom (Closeds.complOrderIso α s.compl) ↔ _ simp only [(Closeds.complOrderIso α).isAtom_iff, Closeds.isAtom_iff, Closeds.compl_bijective.injective.eq_iff] /-! ### Clopen sets -/ /-- The type of clopen sets of a topological space. -/ structure Clopens (α : Type*) [TopologicalSpace α] where /-- the carrier set, i.e. the points in this set -/ carrier : Set α isClopen' : IsClopen carrier namespace Clopens instance : SetLike (Clopens α) α where coe s := s.carrier coe_injective' s t h := by cases s; cases t; congr theorem isClopen (s : Clopens α) : IsClopen (s : Set α) := s.isClopen' lemma isOpen (s : Clopens α) : IsOpen (s : Set α) := s.isClopen.isOpen lemma isClosed (s : Clopens α) : IsClosed (s : Set α) := s.isClopen.isClosed /-- See Note [custom simps projection]. -/ def Simps.coe (s : Clopens α) : Set α := s initialize_simps_projections Clopens (carrier → coe, as_prefix coe) /-- Reinterpret a clopen as an open. -/ @[simps] def toOpens (s : Clopens α) : Opens α := ⟨s, s.isOpen⟩ /-- Reinterpret a clopen as a closed. -/ @[simps] def toCloseds (s : Clopens α) : Closeds α := ⟨s, s.isClosed⟩ @[ext] protected theorem ext {s t : Clopens α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Set α) (h) : (mk s h : Set α) = s := rfl @[simp] lemma mem_mk {s : Set α} {x h} : x ∈ mk s h ↔ x ∈ s := .rfl instance : Max (Clopens α) := ⟨fun s t => ⟨s ∪ t, s.isClopen.union t.isClopen⟩⟩ instance : Min (Clopens α) := ⟨fun s t => ⟨s ∩ t, s.isClopen.inter t.isClopen⟩⟩ instance : Top (Clopens α) := ⟨⟨⊤, isClopen_univ⟩⟩ instance : Bot (Clopens α) := ⟨⟨⊥, isClopen_empty⟩⟩ instance : SDiff (Clopens α) := ⟨fun s t => ⟨s \ t, s.isClopen.diff t.isClopen⟩⟩ instance : HImp (Clopens α) where himp s t := ⟨s ⇨ t, s.isClopen.himp t.isClopen⟩ instance : HasCompl (Clopens α) := ⟨fun s => ⟨sᶜ, s.isClopen.compl⟩⟩ @[simp, norm_cast] lemma coe_sup (s t : Clopens α) : ↑(s ⊔ t) = (s ∪ t : Set α) := rfl @[simp, norm_cast] lemma coe_inf (s t : Clopens α) : ↑(s ⊓ t) = (s ∩ t : Set α) := rfl @[simp, norm_cast] lemma coe_top : (↑(⊤ : Clopens α) : Set α) = univ := rfl @[simp, norm_cast] lemma coe_bot : (↑(⊥ : Clopens α) : Set α) = ∅ := rfl @[simp, norm_cast] lemma coe_sdiff (s t : Clopens α) : ↑(s \ t) = (s \ t : Set α) := rfl @[simp, norm_cast] lemma coe_himp (s t : Clopens α) : ↑(s ⇨ t) = (s ⇨ t : Set α) := rfl @[simp, norm_cast] lemma coe_compl (s : Clopens α) : (↑sᶜ : Set α) = (↑s)ᶜ := rfl instance : BooleanAlgebra (Clopens α) := SetLike.coe_injective.booleanAlgebra _ coe_sup coe_inf coe_top coe_bot coe_compl coe_sdiff coe_himp instance : Inhabited (Clopens α) := ⟨⊥⟩ instance : SProd (Clopens α) (Clopens β) (Clopens (α × β)) where sprod s t := ⟨s ×ˢ t, s.2.prod t.2⟩ @[simp] protected lemma mem_prod {s : Clopens α} {t : Clopens β} {x : α × β} : x ∈ s ×ˢ t ↔ x.1 ∈ s ∧ x.2 ∈ t := .rfl @[simp] lemma coe_finset_sup (s : Finset ι) (U : ι → Clopens α) : (↑(s.sup U) : Set α) = ⋃ i ∈ s, U i := by classical induction s using Finset.induction_on with | empty => simp | insert _ _ _ IH => simp [IH] @[simp, norm_cast] lemma coe_disjoint {s t : Clopens α} : Disjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, ← SetLike.coe_set_eq] end Clopens /-! ### Irreducible closed sets -/ /-- The type of irreducible closed subsets of a topological space. -/ structure IrreducibleCloseds (α : Type*) [TopologicalSpace α] where /-- the carrier set, i.e. the points in this set -/ carrier : Set α isIrreducible' : IsIrreducible carrier isClosed' : IsClosed carrier namespace IrreducibleCloseds instance : SetLike (IrreducibleCloseds α) α where coe := IrreducibleCloseds.carrier coe_injective' s t h := by cases s; cases t; congr instance : CanLift (Set α) (IrreducibleCloseds α) (↑) (fun s ↦ IsIrreducible s ∧ IsClosed s) where prf s hs := ⟨⟨s, hs.1, hs.2⟩, rfl⟩ theorem isIrreducible (s : IrreducibleCloseds α) : IsIrreducible (s : Set α) := s.isIrreducible' @[deprecated (since := "2025-10-14")] alias is_irreducible' := isIrreducible theorem isClosed (s : IrreducibleCloseds α) : IsClosed (s : Set α) := s.isClosed' @[deprecated (since := "2025-10-14")] alias is_closed' := isClosed /-- See Note [custom simps projection]. -/ def Simps.coe (s : IrreducibleCloseds α) : Set α := s initialize_simps_projections IrreducibleCloseds (carrier → coe, as_prefix coe) @[ext] protected theorem ext {s t : IrreducibleCloseds α} (h : (s : Set α) = t) : s = t := SetLike.ext' h @[simp] theorem coe_mk (s : Set α) (h : IsIrreducible s) (h' : IsClosed s) : (mk s h h' : Set α) = s := rfl /-- The term of `TopologicalSpace.IrreducibleCloseds α` corresponding to a singleton. -/ @[simps] def singleton [T1Space α] (x : α) : IrreducibleCloseds α := ⟨{x}, isIrreducible_singleton, isClosed_singleton⟩ @[simp] lemma mem_singleton [T1Space α] {a b : α} : a ∈ singleton b ↔ a = b := Iff.rfl theorem singleton_injective [T1Space α] : Function.Injective (singleton (α := α)) := .of_comp (f := SetLike.coe) Set.singleton_injective @[simp] theorem singleton_inj [T1Space α] {x y : α} : singleton x = singleton y ↔ x = y := singleton_injective.eq_iff /-- The equivalence between `IrreducibleCloseds α` and `{x : Set α // IsIrreducible x ∧ IsClosed x }`. -/ @[simps apply symm_apply] def equivSubtype : IrreducibleCloseds α ≃ { x : Set α // IsIrreducible x ∧ IsClosed x } where toFun a := ⟨a.1, a.2, a.3⟩ invFun a := ⟨a.1, a.2.1, a.2.2⟩ /-- The equivalence between `IrreducibleCloseds α` and `{x : Set α // IsClosed x ∧ IsIrreducible x }`. -/ @[simps apply symm_apply] def equivSubtype' : IrreducibleCloseds α ≃ { x : Set α // IsClosed x ∧ IsIrreducible x } where toFun a := ⟨a.1, a.3, a.2⟩ invFun a := ⟨a.1, a.2.2, a.2.1⟩ variable (α) in /-- The equivalence `IrreducibleCloseds α ≃ { x : Set α // IsIrreducible x ∧ IsClosed x }` is an order isomorphism. -/ def orderIsoSubtype : IrreducibleCloseds α ≃o { x : Set α // IsIrreducible x ∧ IsClosed x } := equivSubtype.toOrderIso (fun _ _ h ↦ h) (fun _ _ h ↦ h) variable (α) in /-- The equivalence `IrreducibleCloseds α ≃ { x : Set α // IsClosed x ∧ IsIrreducible x }` is an order isomorphism. -/ def orderIsoSubtype' : IrreducibleCloseds α ≃o { x : Set α // IsClosed x ∧ IsIrreducible x } := equivSubtype'.toOrderIso (fun _ _ h ↦ h) (fun _ _ h ↦ h) /-! ### Partial order structure on irreducible closed sets and maps thereof.-/ /-- The map on irreducible closed sets induced by a continuous map `f`. -/ def map (f : β → α) (hf : Continuous f) (c : IrreducibleCloseds β) : IrreducibleCloseds α where carrier := closure (f '' c) isIrreducible' := c.isIrreducible.image f hf.continuousOn |>.closure isClosed' := isClosed_closure @[simp] lemma coe_map (f : β → α) (hf : Continuous f) (s : IrreducibleCloseds β) : (map f hf s : Set α) = closure (f '' s) := rfl lemma map_mono {f : β → α} (hf : Continuous f) : Monotone (map f hf) := fun _ _ h_le => closure_mono <| Set.image_mono h_le /-- The map `IrreducibleCloseds.map` is injective when `f` is inducing. This relies on the property of embeddings that a closed set in the domain is the preimage of the closure of its image. -/ lemma map_injective_of_isInducing {f : β → α} (hf : IsInducing f) : Function.Injective (map f hf.continuous) := by intro A B h_images_eq apply SetLike.coe_injective replace h_images_eq : closure (f '' A) = closure (f '' B) := congr($h_images_eq) rw [← A.isClosed.closure_eq, hf.closure_eq_preimage_closure_image, h_images_eq, ← hf.closure_eq_preimage_closure_image, B.isClosed.closure_eq] /-- The map `IrreducibleCloseds.map` is strictly monotone when `f` is inducing. -/ lemma map_strictMono_of_isInducing {f : β → α} (hf : IsInducing f) : StrictMono (map f hf.continuous) := Monotone.strictMono_of_injective (map_mono hf.continuous) (map_injective_of_isInducing hf) end IrreducibleCloseds end TopologicalSpace
.lake/packages/mathlib/Mathlib/Topology/GDelta/Basic.lean
import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Closure /-! # `Gδ` sets In this file we define `Gδ` sets and prove their basic properties. ## Main definitions * `IsGδ`: a set `s` is a `Gδ` set if it can be represented as an intersection of countably many open sets; * `residual`: the σ-filter of residual sets. A set `s` is called *residual* if it includes a countable intersection of dense open sets. * `IsNowhereDense`: a set is called *nowhere dense* iff its closure has empty interior * `IsMeagre`: a set `s` is called *meagre* iff its complement is residual ## Main results We prove that finite or countable intersections of Gδ sets are Gδ sets. - `isClosed_isNowhereDense_iff_compl`: a closed set is nowhere dense iff its complement is open and dense - `isMeagre_iff_countable_union_isNowhereDense`: a set is meagre iff it is contained in a countable union of nowhere dense sets - subsets of meagre sets are meagre; countable unions of meagre sets are meagre See `Mathlib/Topology/GDelta/MetrizableSpace.lean` for the proof that continuity set of a function from a topological space to a metrizable space is a Gδ set. ## Tags Gδ set, residual set, nowhere dense set, meagre set -/ assert_not_exists UniformSpace noncomputable section open Topology TopologicalSpace Filter Encodable Set variable {X Y ι : Type*} {ι' : Sort*} section IsGδ variable [TopologicalSpace X] /-- A Gδ set is a countable intersection of open sets. -/ def IsGδ (s : Set X) : Prop := ∃ T : Set (Set X), (∀ t ∈ T, IsOpen t) ∧ T.Countable ∧ s = ⋂₀ T /-- An open set is a Gδ set. -/ theorem IsOpen.isGδ {s : Set X} (h : IsOpen s) : IsGδ s := ⟨{s}, by simp [h], countable_singleton _, (Set.sInter_singleton _).symm⟩ @[simp] protected theorem IsGδ.empty : IsGδ (∅ : Set X) := isOpen_empty.isGδ @[simp] protected theorem IsGδ.univ : IsGδ (univ : Set X) := isOpen_univ.isGδ theorem IsGδ.biInter_of_isOpen {I : Set ι} (hI : I.Countable) {f : ι → Set X} (hf : ∀ i ∈ I, IsOpen (f i)) : IsGδ (⋂ i ∈ I, f i) := ⟨f '' I, by rwa [forall_mem_image], hI.image _, by rw [sInter_image]⟩ theorem IsGδ.iInter_of_isOpen [Countable ι'] {f : ι' → Set X} (hf : ∀ i, IsOpen (f i)) : IsGδ (⋂ i, f i) := ⟨range f, by rwa [forall_mem_range], countable_range _, by rw [sInter_range]⟩ lemma isGδ_iff_eq_iInter_nat {s : Set X} : IsGδ s ↔ ∃ (f : ℕ → Set X), (∀ n, IsOpen (f n)) ∧ s = ⋂ n, f n := by refine ⟨?_, ?_⟩ · rintro ⟨T, hT, T_count, rfl⟩ rcases Set.eq_empty_or_nonempty T with rfl | hT · exact ⟨fun _n ↦ univ, fun _n ↦ isOpen_univ, by simp⟩ · obtain ⟨f, hf⟩ : ∃ (f : ℕ → Set X), T = range f := Countable.exists_eq_range T_count hT exact ⟨f, by simp_all, by simp [hf]⟩ · rintro ⟨f, hf, rfl⟩ exact .iInter_of_isOpen hf alias ⟨IsGδ.eq_iInter_nat, _⟩ := isGδ_iff_eq_iInter_nat /-- The intersection of an encodable family of Gδ sets is a Gδ set. -/ protected theorem IsGδ.iInter [Countable ι'] {s : ι' → Set X} (hs : ∀ i, IsGδ (s i)) : IsGδ (⋂ i, s i) := by choose T hTo hTc hTs using hs obtain rfl : s = fun i => ⋂₀ T i := funext hTs refine ⟨⋃ i, T i, ?_, countable_iUnion hTc, (sInter_iUnion _).symm⟩ simpa [@forall_swap ι'] using hTo theorem IsGδ.biInter {s : Set ι} (hs : s.Countable) {t : ∀ i ∈ s, Set X} (ht : ∀ (i) (hi : i ∈ s), IsGδ (t i hi)) : IsGδ (⋂ i ∈ s, t i ‹_›) := by rw [biInter_eq_iInter] haveI := hs.to_subtype exact .iInter fun x => ht x x.2 /-- A countable intersection of Gδ sets is a Gδ set. -/ theorem IsGδ.sInter {S : Set (Set X)} (h : ∀ s ∈ S, IsGδ s) (hS : S.Countable) : IsGδ (⋂₀ S) := by simpa only [sInter_eq_biInter] using IsGδ.biInter hS h theorem IsGδ.inter {s t : Set X} (hs : IsGδ s) (ht : IsGδ t) : IsGδ (s ∩ t) := by rw [inter_eq_iInter] exact .iInter (Bool.forall_bool.2 ⟨ht, hs⟩) /-- The union of two Gδ sets is a Gδ set. -/ theorem IsGδ.union {s t : Set X} (hs : IsGδ s) (ht : IsGδ t) : IsGδ (s ∪ t) := by rcases hs with ⟨S, Sopen, Scount, rfl⟩ rcases ht with ⟨T, Topen, Tcount, rfl⟩ rw [sInter_union_sInter] refine .biInter_of_isOpen (Scount.prod Tcount) ?_ rintro ⟨a, b⟩ ⟨ha, hb⟩ exact (Sopen a ha).union (Topen b hb) /-- The union of finitely many Gδ sets is a Gδ set, `Set.sUnion` version. -/ theorem IsGδ.sUnion {S : Set (Set X)} (hS : S.Finite) (h : ∀ s ∈ S, IsGδ s) : IsGδ (⋃₀ S) := by induction S, hS using Set.Finite.induction_on with | empty => simp | insert _ _ ih => simp only [forall_mem_insert, sUnion_insert] at * exact h.1.union (ih h.2) /-- The union of finitely many Gδ sets is a Gδ set, bounded indexed union version. -/ theorem IsGδ.biUnion {s : Set ι} (hs : s.Finite) {f : ι → Set X} (h : ∀ i ∈ s, IsGδ (f i)) : IsGδ (⋃ i ∈ s, f i) := by rw [← sUnion_image] exact .sUnion (hs.image _) (forall_mem_image.2 h) /-- The union of finitely many Gδ sets is a Gδ set, bounded indexed union version. -/ theorem IsGδ.iUnion [Finite ι'] {f : ι' → Set X} (h : ∀ i, IsGδ (f i)) : IsGδ (⋃ i, f i) := .sUnion (finite_range _) <| forall_mem_range.2 h end IsGδ section residual variable [TopologicalSpace X] /-- A set `s` is called *residual* if it includes a countable intersection of dense open sets. -/ def residual (X : Type*) [TopologicalSpace X] : Filter X := Filter.countableGenerate { t | IsOpen t ∧ Dense t } instance countableInterFilter_residual : CountableInterFilter (residual X) := by rw [residual]; infer_instance /-- Dense open sets are residual. -/ theorem residual_of_dense_open {s : Set X} (ho : IsOpen s) (hd : Dense s) : s ∈ residual X := CountableGenerateSets.basic ⟨ho, hd⟩ /-- Dense Gδ sets are residual. -/ theorem residual_of_dense_Gδ {s : Set X} (ho : IsGδ s) (hd : Dense s) : s ∈ residual X := by rcases ho with ⟨T, To, Tct, rfl⟩ exact (countable_sInter_mem Tct).mpr fun t tT => residual_of_dense_open (To t tT) (hd.mono (sInter_subset_of_mem tT)) /-- A set is residual iff it includes a countable intersection of dense open sets. -/ theorem mem_residual_iff {s : Set X} : s ∈ residual X ↔ ∃ S : Set (Set X), (∀ t ∈ S, IsOpen t) ∧ (∀ t ∈ S, Dense t) ∧ S.Countable ∧ ⋂₀ S ⊆ s := mem_countableGenerate_iff.trans <| by simp_rw [subset_def, mem_setOf, forall_and, and_assoc] end residual section IsMeagre open Function TopologicalSpace Set variable {X : Type*} [TopologicalSpace X] /-- A set is called **nowhere dense** iff its closure has empty interior. -/ def IsNowhereDense (s : Set X) := interior (closure s) = ∅ /-- The empty set is nowhere dense. -/ @[simp] lemma isNowhereDense_empty : IsNowhereDense (∅ : Set X) := by rw [IsNowhereDense, closure_empty, interior_empty] /-- A closed set is nowhere dense iff its interior is empty. -/ lemma IsClosed.isNowhereDense_iff {s : Set X} (hs : IsClosed s) : IsNowhereDense s ↔ interior s = ∅ := by rw [IsNowhereDense, IsClosed.closure_eq hs] /-- If a set `s` is nowhere dense, so is its closure. -/ protected lemma IsNowhereDense.closure {s : Set X} (hs : IsNowhereDense s) : IsNowhereDense (closure s) := by rwa [IsNowhereDense, closure_closure] /-- A nowhere dense set `s` is contained in a closed nowhere dense set (namely, its closure). -/ lemma IsNowhereDense.subset_of_closed_isNowhereDense {s : Set X} (hs : IsNowhereDense s) : ∃ t : Set X, s ⊆ t ∧ IsNowhereDense t ∧ IsClosed t := ⟨closure s, subset_closure, ⟨hs.closure, isClosed_closure⟩⟩ /-- A set `s` is closed and nowhere dense iff its complement `sᶜ` is open and dense. -/ lemma isClosed_isNowhereDense_iff_compl {s : Set X} : IsClosed s ∧ IsNowhereDense s ↔ IsOpen sᶜ ∧ Dense sᶜ := by rw [and_congr_right IsClosed.isNowhereDense_iff, isOpen_compl_iff, interior_eq_empty_iff_dense_compl] /-- A set is called **meagre** iff its complement is a residual (or comeagre) set. -/ def IsMeagre (s : Set X) := sᶜ ∈ residual X /-- The empty set is meagre. -/ lemma IsMeagre.empty : IsMeagre (∅ : Set X) := by rw [IsMeagre, compl_empty] exact Filter.univ_mem /-- Subsets of meagre sets are meagre. -/ lemma IsMeagre.mono {s t : Set X} (hs : IsMeagre s) (hts : t ⊆ s) : IsMeagre t := Filter.mem_of_superset hs (compl_subset_compl.mpr hts) /-- An intersection with a meagre set is meagre. -/ lemma IsMeagre.inter {s t : Set X} (hs : IsMeagre s) : IsMeagre (s ∩ t) := hs.mono inter_subset_left /-- A union of two meagre sets is meagre. -/ lemma IsMeagre.union {s t : Set X} (hs : IsMeagre s) (ht : IsMeagre t) : IsMeagre (s ∪ t) := by rw [IsMeagre, compl_union] exact inter_mem hs ht /-- A countable union of meagre sets is meagre. -/ lemma isMeagre_iUnion [Countable ι'] {f : ι' → Set X} (hs : ∀ i, IsMeagre (f i)) : IsMeagre (⋃ i, f i) := by rw [IsMeagre, compl_iUnion] exact countable_iInter_mem.mpr hs /-- A set is meagre iff it is contained in a countable union of nowhere dense sets. -/ lemma isMeagre_iff_countable_union_isNowhereDense {s : Set X} : IsMeagre s ↔ ∃ S : Set (Set X), (∀ t ∈ S, IsNowhereDense t) ∧ S.Countable ∧ s ⊆ ⋃₀ S := by rw [IsMeagre, mem_residual_iff, compl_bijective.surjective.image_surjective.exists] simp_rw [← and_assoc, ← forall_and, forall_mem_image, ← isClosed_isNowhereDense_iff_compl, sInter_image, ← compl_iUnion₂, compl_subset_compl, ← sUnion_eq_biUnion, and_assoc] refine ⟨fun ⟨S, hS, hc, hsub⟩ ↦ ⟨S, fun s hs ↦ (hS hs).2, ?_, hsub⟩, ?_⟩ · rw [← compl_compl_image S]; exact hc.image _ · intro ⟨S, hS, hc, hsub⟩ use closure '' S rw [forall_mem_image] exact ⟨fun s hs ↦ ⟨isClosed_closure, (hS s hs).closure⟩, (hc.image _).image _, hsub.trans (sUnion_mono_subsets fun s ↦ subset_closure)⟩ /-- A set of second category (i.e. non-meagre) is nonempty. -/ lemma nonempty_of_not_isMeagre {s : Set X} (hs : ¬IsMeagre s) : s.Nonempty := by contrapose! hs simpa [hs] using IsMeagre.empty end IsMeagre
.lake/packages/mathlib/Mathlib/Topology/GDelta/UniformSpace.lean
import Mathlib.Topology.GDelta.MetrizableSpace import Mathlib.Topology.Separation.GDelta deprecated_module (since := "2025-05-07")
.lake/packages/mathlib/Mathlib/Topology/GDelta/MetrizableSpace.lean
import Mathlib.Topology.MetricSpace.HausdorffDistance import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Separation.GDelta /-! # `Gδ` sets and metrizable spaces ## Main results We prove that metrizable spaces are T6. We prove that the continuity set of a function from a topological space to a metrizable space is a Gδ set. -/ variable {X : Type*} [TopologicalSpace X] open TopologicalSpace Metric Set section Metrizable instance (priority := 100) [PseudoMetrizableSpace X] : NormalSpace X where normal s t hs ht hst := by let _ := pseudoMetrizableSpacePseudoMetric X by_cases hee : s = ∅ ∨ t = ∅ · obtain rfl | rfl := hee <;> simp simp only [not_or, ← ne_eq, ← nonempty_iff_ne_empty] at hee obtain ⟨hse, hte⟩ := hee let g (p : X) := infDist p t - infDist p s have hg : Continuous g := by fun_prop refine ⟨g ⁻¹' (Ioi 0), g ⁻¹' (Iio 0), isOpen_Ioi.preimage hg, isOpen_Iio.preimage hg, fun x hx ↦ ?_, fun x hx ↦ ?_, Ioi_disjoint_Iio_same.preimage g⟩ · simp [g, infDist_zero_of_mem hx, (ht.notMem_iff_infDist_pos hte).mp (hst.notMem_of_mem_left hx)] · simp [g, infDist_zero_of_mem hx, (hs.notMem_iff_infDist_pos hse).mp (hst.notMem_of_mem_right hx)] instance (priority := 500) [PseudoMetrizableSpace X] : PerfectlyNormalSpace X where closed_gdelta s hs := by let _ := pseudoMetrizableSpacePseudoMetric X rcases (@uniformity_hasBasis_open X _).exists_antitone_subbasis with ⟨U, hUo, hU, -⟩ rw [← hs.closure_eq, ← hU.biInter_biUnion_ball] refine .biInter (to_countable _) fun n _ => IsOpen.isGδ ?_ exact isOpen_biUnion fun x _ => UniformSpace.isOpen_ball _ (hUo _).2 instance (priority := 100) [MetrizableSpace X] : T4Space X where instance (priority := 500) [MetrizableSpace X] : T6Space X where end Metrizable section ContinuousAt variable {Y : Type*} [TopologicalSpace Y] theorem IsGδ.setOf_continuousAt [PseudoMetrizableSpace Y] (f : X → Y) : IsGδ { x | ContinuousAt f x } := by let _ := pseudoMetrizableSpacePseudoMetric Y obtain ⟨U, _, hU⟩ := (@uniformity_hasBasis_open_symmetric Y _).exists_antitone_subbasis simp only [Uniform.continuousAt_iff_prod, nhds_prod_eq] simp only [(nhds_basis_opens _).prod_self.tendsto_iff hU.toHasBasis, forall_prop_of_true, setOf_forall] refine .iInter fun k ↦ IsOpen.isGδ <| isOpen_iff_mem_nhds.2 fun x ↦ ?_ rintro ⟨s, ⟨hsx, hso⟩, hsU⟩ filter_upwards [IsOpen.mem_nhds hso hsx] with _ hy using ⟨s, ⟨hy, hso⟩, hsU⟩ end ContinuousAt
.lake/packages/mathlib/Mathlib/Topology/Separation/SeparatedNhds.lean
import Mathlib.Topology.Continuous import Mathlib.Topology.NhdsSet /-! # Separated neighbourhoods This file defines the predicates `SeparatedNhds` and `HasSeparatingCover`, which are used in formulating separation axioms for topological spaces. ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `HasSeparatingCover`: A set has a countable cover that can be used with `hasSeparatingCovers_iff_separatedNhds` to witness when two `Set`s have `SeparatedNhds`. ## References * <https://en.wikipedia.org/wiki/Separation_axiom> * [Willard's *General Topology*][zbMATH02107988] -/ open Function Set Filter Topology TopologicalSpace universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, ← exists_and_left, and_assoc, and_comm, and_left_comm] alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint /-- `HasSeparatingCover`s can be useful witnesses for `SeparatedNhds`. -/ def HasSeparatingCover : Set X → Set X → Prop := fun s t ↦ ∃ u : ℕ → Set X, s ⊆ ⋃ n, u n ∧ ∀ n, IsOpen (u n) ∧ Disjoint (closure (u n)) t /-- Used to prove that a regular topological space with Lindelöf topology is a normal space, and a perfectly normal space is a completely normal space. -/ theorem hasSeparatingCovers_iff_separatedNhds {s t : Set X} : HasSeparatingCover s t ∧ HasSeparatingCover t s ↔ SeparatedNhds s t := by constructor · rintro ⟨⟨u, u_cov, u_props⟩, ⟨v, v_cov, v_props⟩⟩ have open_lemma : ∀ (u₀ a : ℕ → Set X), (∀ n, IsOpen (u₀ n)) → IsOpen (⋃ n, u₀ n \ closure (a n)) := fun _ _ u₀i_open ↦ isOpen_iUnion fun i ↦ (u₀i_open i).sdiff isClosed_closure have cover_lemma : ∀ (h₀ : Set X) (u₀ v₀ : ℕ → Set X), (h₀ ⊆ ⋃ n, u₀ n) → (∀ n, Disjoint (closure (v₀ n)) h₀) → (h₀ ⊆ ⋃ n, u₀ n \ closure (⋃ m ≤ n, v₀ m)) := fun h₀ u₀ v₀ h₀_cov dis x xinh ↦ by rcases h₀_cov xinh with ⟨un, ⟨n, rfl⟩, xinun⟩ simp only [mem_iUnion] refine ⟨n, xinun, ?_⟩ simp_all only [closure_iUnion₂_le_nat, disjoint_right, mem_iUnion, exists_false, not_false_eq_true] refine ⟨⋃ n : ℕ, u n \ (closure (⋃ m ≤ n, v m)), ⋃ n : ℕ, v n \ (closure (⋃ m ≤ n, u m)), open_lemma u (fun n ↦ ⋃ m ≤ n, v m) (fun n ↦ (u_props n).1), open_lemma v (fun n ↦ ⋃ m ≤ n, u m) (fun n ↦ (v_props n).1), cover_lemma s u v u_cov (fun n ↦ (v_props n).2), cover_lemma t v u v_cov (fun n ↦ (u_props n).2), ?_⟩ rw [Set.disjoint_left] rintro x ⟨un, ⟨n, rfl⟩, xinun⟩ suffices ∀ (m : ℕ), x ∈ v m → x ∈ closure (⋃ m' ∈ {m' | m' ≤ m}, u m') by simpa intro m xinvm have n_le_m : n ≤ m := by by_contra m_gt_n exact xinun.2 (subset_closure (mem_biUnion (le_of_lt (not_le.mp m_gt_n)) xinvm)) exact subset_closure (mem_biUnion n_le_m xinun.1) · rintro ⟨U, V, U_open, V_open, h_sub_U, k_sub_V, UV_dis⟩ exact ⟨⟨fun _ ↦ U, h_sub_U.trans (iUnion_const U).symm.subset, fun _ ↦ ⟨U_open, disjoint_of_subset (fun ⦃a⦄ a ↦ a) k_sub_V (UV_dis.closure_left V_open)⟩⟩, ⟨fun _ ↦ V, k_sub_V.trans (iUnion_const V).symm.subset, fun _ ↦ ⟨V_open, disjoint_of_subset (fun ⦃a⦄ a ↦ a) h_sub_U (UV_dis.closure_right U_open).symm⟩⟩⟩ theorem Set.hasSeparatingCover_empty_left (s : Set X) : HasSeparatingCover ∅ s := ⟨fun _ ↦ ∅, empty_subset (⋃ _, ∅), fun _ ↦ ⟨isOpen_empty, by simp only [closure_empty, empty_disjoint]⟩⟩ theorem Set.hasSeparatingCover_empty_right (s : Set X) : HasSeparatingCover s ∅ := ⟨fun _ ↦ univ, (subset_univ s).trans univ.iUnion_const.symm.subset, fun _ ↦ ⟨isOpen_univ, by apply disjoint_empty⟩⟩ theorem HasSeparatingCover.mono {s₁ s₂ t₁ t₂ : Set X} (sc_st : HasSeparatingCover s₂ t₂) (s_sub : s₁ ⊆ s₂) (t_sub : t₁ ⊆ t₂) : HasSeparatingCover s₁ t₁ := by obtain ⟨u, u_cov, u_props⟩ := sc_st exact ⟨u, s_sub.trans u_cov, fun n ↦ ⟨(u_props n).1, disjoint_of_subset (fun ⦃_⦄ a ↦ a) t_sub (u_props n).2⟩⟩ namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm lemma isOpen_left_of_isOpen_union (hst : SeparatedNhds s t) (hst' : IsOpen (s ∪ t)) : IsOpen s := by obtain ⟨u, v, hu, hv, hsu, htv, huv⟩ := hst suffices s = (s ∪ t) ∩ u from this ▸ hst'.inter hu rw [union_inter_distrib_right, (huv.symm.mono_left htv).inter_eq, union_empty, inter_eq_left.2 hsu] lemma isOpen_right_of_isOpen_union (hst : SeparatedNhds s t) (hst' : IsOpen (s ∪ t)) : IsOpen t := hst.symm.isOpen_left_of_isOpen_union (union_comm _ _ ▸ hst') lemma isOpen_union_iff (hst : SeparatedNhds s t) : IsOpen (s ∪ t) ↔ IsOpen s ∧ IsOpen t := ⟨fun h ↦ ⟨hst.isOpen_left_of_isOpen_union h, hst.isOpen_right_of_isOpen_union h⟩, fun ⟨h1, h2⟩ ↦ h1.union h2⟩ lemma isClosed_left_of_isClosed_union (hst : SeparatedNhds s t) (hst' : IsClosed (s ∪ t)) : IsClosed s := by obtain ⟨u, v, hu, hv, hsu, htv, huv⟩ := hst rw [← isOpen_compl_iff] at hst' ⊢ suffices sᶜ = (s ∪ t)ᶜ ∪ v from this ▸ hst'.union hv rw [← compl_inj_iff, Set.compl_union, compl_compl, compl_compl, union_inter_distrib_right, (disjoint_compl_right.mono_left htv).inter_eq, union_empty, left_eq_inter, subset_compl_comm] exact (huv.mono_left hsu).subset_compl_left lemma isClosed_right_of_isClosed_union (hst : SeparatedNhds s t) (hst' : IsClosed (s ∪ t)) : IsClosed t := hst.symm.isClosed_left_of_isClosed_union (union_comm _ _ ▸ hst') lemma isClosed_union_iff (hst : SeparatedNhds s t) : IsClosed (s ∪ t) ↔ IsClosed s ∧ IsClosed t := ⟨fun h ↦ ⟨hst.isClosed_left_of_isClosed_union h, hst.isClosed_right_of_isClosed_union h⟩, fun ⟨h1, h2⟩ ↦ h1.union h2⟩ end SeparatedNhds end Separation
.lake/packages/mathlib/Mathlib/Topology/Separation/CountableSeparatingOn.lean
import Mathlib.Order.Filter.CountableSeparatingOn import Mathlib.Topology.Separation.Basic /-! # Countable separating families of sets in topological spaces In this file we show that a T₀ topological space with second countable topology has a countable family of open (or closed) sets separating the points. -/ variable {X : Type*} open Set TopologicalSpace /-- If `X` is a topological space, `s` is a set in `X` such that the induced topology is T₀ and is second countable, then there exists a countable family of open sets in `X` that separates points of `s`. -/ instance [TopologicalSpace X] {s : Set X} [T0Space s] [SecondCountableTopology s] : HasCountableSeparatingOn X IsOpen s := by suffices HasCountableSeparatingOn s IsOpen univ from .of_subtype fun _ ↦ isOpen_induced_iff.1 refine ⟨⟨countableBasis s, countable_countableBasis _, fun _ ↦ isOpen_of_mem_countableBasis, fun x _ y _ h ↦ ?_⟩⟩ exact ((isBasis_countableBasis _).inseparable_iff.2 h).eq /-- If there exists a countable family of open sets separating points of `s`, then there exists a countable family of closed sets separating points of `s`. -/ instance [TopologicalSpace X] {s : Set X} [h : HasCountableSeparatingOn X IsOpen s] : HasCountableSeparatingOn X IsClosed s := let ⟨S, hSc, hSo, hS⟩ := h.1 ⟨compl '' S, hSc.image _, forall_mem_image.2 fun U hU ↦ (hSo U hU).isClosed_compl, fun x hx y hy h ↦ hS x hx y hy fun _U hU ↦ not_iff_not.1 <| h _ (mem_image_of_mem _ hU)⟩
.lake/packages/mathlib/Mathlib/Topology/Separation/Regular.lean
import Mathlib.Tactic.StacksAttribute import Mathlib.Topology.Compactness.Lindelof import Mathlib.Topology.Separation.Hausdorff import Mathlib.Topology.Connected.Clopen /-! # Regular, normal, T₃, T₄ and T₅ spaces This file continues the study of separation properties of topological spaces, focusing on conditions strictly stronger than T₂. ## Main definitions * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. See `Mathlib/Topology/Separation/GDelta.lean` for the definitions of `PerfectlyNormalSpace` and `T6Space`. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### Regular spaces If the space is also Lindelöf: * `NormalSpace.of_regularSpace_lindelofSpace`: every regular Lindelöf space is normal. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References * <https://en.wikipedia.org/wiki/Separation_axiom> * <https://en.wikipedia.org/wiki/Normal_space> * [Willard's *General Topology*][zbMATH02107988] -/ assert_not_exists UniformSpace open Function Set Filter Topology TopologicalSpace universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section RegularSpace /-- A topological space is called a *regular space* if for any closed set `s` and `a ∉ s`, there exist disjoint open sets `U ⊇ s` and `V ∋ a`. We formulate this condition in terms of `Disjoint`ness of filters `𝓝ˢ s` and `𝓝 a`. -/ @[mk_iff] class RegularSpace (X : Type u) [TopologicalSpace X] : Prop where /-- If `a` is a point that does not belong to a closed set `s`, then `a` and `s` admit disjoint neighborhoods. -/ regular : ∀ {s : Set X} {a}, IsClosed s → a ∉ s → Disjoint (𝓝ˢ s) (𝓝 a) theorem regularSpace_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [RegularSpace X, ∀ (s : Set X) x, x ∉ closure s → Disjoint (𝓝ˢ s) (𝓝 x), ∀ (x : X) (s : Set X), Disjoint (𝓝ˢ s) (𝓝 x) ↔ x ∉ closure s, ∀ (x : X) (s : Set X), s ∈ 𝓝 x → ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s, ∀ x : X, (𝓝 x).lift' closure ≤ 𝓝 x, ∀ x : X, (𝓝 x).lift' closure = 𝓝 x] := by tfae_have 1 ↔ 5 := by rw [regularSpace_iff, (@compl_surjective (Set X) _).forall, forall_swap] simp only [isClosed_compl_iff, mem_compl_iff, Classical.not_not, @and_comm (_ ∈ _), (nhds_basis_opens _).lift'_closure.le_basis_iff (nhds_basis_opens _), and_imp, (nhds_basis_opens _).disjoint_iff_right, ← subset_interior_iff_mem_nhdsSet, interior_compl, compl_subset_compl] tfae_have 5 → 6 := fun h a => (h a).antisymm (𝓝 _).le_lift'_closure tfae_have 6 → 4 | H, a, s, hs => by rw [← H] at hs rcases (𝓝 a).basis_sets.lift'_closure.mem_iff.mp hs with ⟨U, hU, hUs⟩ exact ⟨closure U, mem_of_superset hU subset_closure, isClosed_closure, hUs⟩ tfae_have 4 → 2 | H, s, a, ha => by have ha' : sᶜ ∈ 𝓝 a := by rwa [← mem_interior_iff_mem_nhds, interior_compl] rcases H _ _ ha' with ⟨U, hU, hUc, hUs⟩ refine disjoint_of_disjoint_of_mem disjoint_compl_left ?_ hU rwa [← subset_interior_iff_mem_nhdsSet, hUc.isOpen_compl.interior_eq, subset_compl_comm] tfae_have 2 → 3 := by refine fun H a s => ⟨fun hd has => mem_closure_iff_nhds_ne_bot.mp has ?_, H s a⟩ exact (hd.symm.mono_right <| @principal_le_nhdsSet _ _ s).eq_bot tfae_have 3 → 1 := fun H => ⟨fun hs ha => (H _ _).mpr <| hs.closure_eq.symm ▸ ha⟩ tfae_finish theorem RegularSpace.of_lift'_closure_le (h : ∀ x : X, (𝓝 x).lift' closure ≤ 𝓝 x) : RegularSpace X := Iff.mpr ((regularSpace_TFAE X).out 0 4) h theorem RegularSpace.of_lift'_closure (h : ∀ x : X, (𝓝 x).lift' closure = 𝓝 x) : RegularSpace X := Iff.mpr ((regularSpace_TFAE X).out 0 5) h theorem RegularSpace.of_hasBasis {ι : X → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set X} (h₁ : ∀ a, (𝓝 a).HasBasis (p a) (s a)) (h₂ : ∀ a i, p a i → IsClosed (s a i)) : RegularSpace X := .of_lift'_closure fun a => (h₁ a).lift'_closure_eq_self (h₂ a) theorem RegularSpace.of_exists_mem_nhds_isClosed_subset (h : ∀ (x : X), ∀ s ∈ 𝓝 x, ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s) : RegularSpace X := Iff.mpr ((regularSpace_TFAE X).out 0 3) h /-- A weakly locally compact R₁ space is regular. -/ instance (priority := 100) [WeaklyLocallyCompactSpace X] [R1Space X] : RegularSpace X := .of_hasBasis isCompact_isClosed_basis_nhds fun _ _ ⟨_, _, h⟩ ↦ h /-- Given a subbasis `s`, it is enough to check the condition of regularity for complements of sets in `s`. -/ theorem regularSpace_generateFrom {s : Set (Set X)} (h : ‹_› = generateFrom s) : RegularSpace X ↔ ∀ t ∈ s, ∀ a ∈ t, Disjoint (𝓝ˢ tᶜ) (𝓝 a) := by refine ⟨fun _ t ht a ha => RegularSpace.regular (h ▸ isOpen_generateFrom_of_mem ht).isClosed_compl (Set.notMem_compl_iff.mpr ha), fun h' => ⟨fun {t a} ht ha => ?_⟩⟩ obtain ⟨t, rfl⟩ := compl_involutive.surjective t rw [isClosed_compl_iff, h] at ht rw [Set.notMem_compl_iff] at ha induction ht with | basic t ht => exact h' t ht a ha | univ => simp | inter t₁ t₂ _ _ ih₁ ih₂ => grind [compl_inter, nhdsSet_union, disjoint_sup_left] | sUnion S _ ih => obtain ⟨t, ht, ha⟩ := ha grw [compl_sUnion, sInter_image, iInter₂_subset t ht] exact ih t ht ha section variable [RegularSpace X] {x : X} {s : Set X} theorem disjoint_nhdsSet_nhds : Disjoint (𝓝ˢ s) (𝓝 x) ↔ x ∉ closure s := by have h := (regularSpace_TFAE X).out 0 2 exact h.mp ‹_› _ _ theorem disjoint_nhds_nhdsSet : Disjoint (𝓝 x) (𝓝ˢ s) ↔ x ∉ closure s := disjoint_comm.trans disjoint_nhdsSet_nhds /-- A regular space is R₁. -/ instance (priority := 100) : R1Space X where specializes_or_disjoint_nhds _ _ := or_iff_not_imp_left.2 fun h ↦ by rwa [← nhdsSet_singleton, disjoint_nhdsSet_nhds, ← specializes_iff_mem_closure] theorem exists_mem_nhds_isClosed_subset {x : X} {s : Set X} (h : s ∈ 𝓝 x) : ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s := by have h' := (regularSpace_TFAE X).out 0 3 exact h'.mp ‹_› _ _ h theorem closed_nhds_basis (x : X) : (𝓝 x).HasBasis (fun s : Set X => s ∈ 𝓝 x ∧ IsClosed s) id := hasBasis_self.2 fun _ => exists_mem_nhds_isClosed_subset theorem lift'_nhds_closure (x : X) : (𝓝 x).lift' closure = 𝓝 x := (closed_nhds_basis x).lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.nhds_closure {ι : Sort*} {x : X} {p : ι → Prop} {s : ι → Set X} (h : (𝓝 x).HasBasis p s) : (𝓝 x).HasBasis p fun i => closure (s i) := lift'_nhds_closure x ▸ h.lift'_closure theorem hasBasis_nhds_closure (x : X) : (𝓝 x).HasBasis (fun s => s ∈ 𝓝 x) closure := (𝓝 x).basis_sets.nhds_closure theorem hasBasis_opens_closure (x : X) : (𝓝 x).HasBasis (fun s => x ∈ s ∧ IsOpen s) closure := (nhds_basis_opens x).nhds_closure theorem IsCompact.exists_isOpen_closure_subset {K U : Set X} (hK : IsCompact K) (hU : U ∈ 𝓝ˢ K) : ∃ V, IsOpen V ∧ K ⊆ V ∧ closure V ⊆ U := by have hd : Disjoint (𝓝ˢ K) (𝓝ˢ Uᶜ) := by simpa [hK.disjoint_nhdsSet_left, disjoint_nhds_nhdsSet, ← subset_interior_iff_mem_nhdsSet] using hU rcases ((hasBasis_nhdsSet _).disjoint_iff (hasBasis_nhdsSet _)).1 hd with ⟨V, ⟨hVo, hKV⟩, W, ⟨hW, hUW⟩, hVW⟩ refine ⟨V, hVo, hKV, Subset.trans ?_ (compl_subset_comm.1 hUW)⟩ exact closure_minimal hVW.subset_compl_right hW.isClosed_compl theorem IsCompact.lift'_closure_nhdsSet {K : Set X} (hK : IsCompact K) : (𝓝ˢ K).lift' closure = 𝓝ˢ K := by refine le_antisymm (fun U hU ↦ ?_) (le_lift'_closure _) rcases hK.exists_isOpen_closure_subset hU with ⟨V, hVo, hKV, hVU⟩ exact mem_of_superset (mem_lift' <| hVo.mem_nhdsSet.2 hKV) hVU theorem TopologicalSpace.IsTopologicalBasis.nhds_basis_closure {B : Set (Set X)} (hB : IsTopologicalBasis B) (x : X) : (𝓝 x).HasBasis (fun s : Set X => x ∈ s ∧ s ∈ B) closure := by simpa only [and_comm] using hB.nhds_hasBasis.nhds_closure theorem TopologicalSpace.IsTopologicalBasis.exists_closure_subset {B : Set (Set X)} (hB : IsTopologicalBasis B) {x : X} {s : Set X} (h : s ∈ 𝓝 x) : ∃ t ∈ B, x ∈ t ∧ closure t ⊆ s := by simpa only [exists_prop, and_assoc] using hB.nhds_hasBasis.nhds_closure.mem_iff.mp h protected theorem Topology.IsInducing.regularSpace [TopologicalSpace Y] {f : Y → X} (hf : IsInducing f) : RegularSpace Y := .of_hasBasis (fun b => by rw [hf.nhds_eq_comap b]; exact (closed_nhds_basis _).comap _) fun b s hs => by exact hs.2.preimage hf.continuous theorem regularSpace_induced (f : Y → X) : @RegularSpace Y (induced f ‹_›) := letI := induced f ‹_› (IsInducing.induced f).regularSpace theorem regularSpace_sInf {X} {T : Set (TopologicalSpace X)} (h : ∀ t ∈ T, @RegularSpace X t) : @RegularSpace X (sInf T) := by let _ := sInf T have : ∀ a, (𝓝 a).HasBasis (fun If : Σ I : Set T, I → Set X => If.1.Finite ∧ ∀ i : If.1, If.2 i ∈ @nhds X i a ∧ @IsClosed X i (If.2 i)) fun If => ⋂ i : If.1, If.snd i := fun a ↦ by rw [nhds_sInf, ← iInf_subtype''] exact .iInf fun t : T => @closed_nhds_basis X t (h t t.2) a refine .of_hasBasis this fun a If hIf => isClosed_iInter fun i => ?_ exact (hIf.2 i).2.mono (sInf_le (i : T).2) theorem regularSpace_iInf {ι X} {t : ι → TopologicalSpace X} (h : ∀ i, @RegularSpace X (t i)) : @RegularSpace X (iInf t) := regularSpace_sInf <| forall_mem_range.mpr h theorem RegularSpace.inf {X} {t₁ t₂ : TopologicalSpace X} (h₁ : @RegularSpace X t₁) (h₂ : @RegularSpace X t₂) : @RegularSpace X (t₁ ⊓ t₂) := by rw [inf_eq_iInf] exact regularSpace_iInf (Bool.forall_bool.2 ⟨h₂, h₁⟩) instance {p : X → Prop} : RegularSpace (Subtype p) := IsEmbedding.subtypeVal.isInducing.regularSpace instance [TopologicalSpace Y] [RegularSpace Y] : RegularSpace (X × Y) := (regularSpace_induced (@Prod.fst X Y)).inf (regularSpace_induced (@Prod.snd X Y)) instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, RegularSpace (X i)] : RegularSpace (∀ i, X i) := regularSpace_iInf fun _ => regularSpace_induced _ /-- In a regular space, if a compact set and a closed set are disjoint, then they have disjoint neighborhoods. -/ lemma SeparatedNhds.of_isCompact_isClosed {s t : Set X} (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : SeparatedNhds s t := by simpa only [separatedNhds_iff_disjoint, hs.disjoint_nhdsSet_left, disjoint_nhds_nhdsSet, ht.closure_eq, disjoint_left] using hst end /-- This technique to witness `HasSeparatingCover` in regular Lindelöf topological spaces will be used to prove regular Lindelöf spaces are normal. -/ lemma IsClosed.HasSeparatingCover {s t : Set X} [LindelofSpace X] [RegularSpace X] (s_cl : IsClosed s) (t_cl : IsClosed t) (st_dis : Disjoint s t) : HasSeparatingCover s t := by -- `IsLindelof.indexed_countable_subcover` requires the space be Nonempty rcases isEmpty_or_nonempty X with empty_X | nonempty_X · rw [subset_eq_empty (t := s) (fun ⦃_⦄ _ ↦ trivial) (univ_eq_empty_iff.mpr empty_X)] exact hasSeparatingCovers_iff_separatedNhds.mpr (SeparatedNhds.empty_left t) |>.1 -- This is almost `HasSeparatingCover`, but is not countable. We define for all `a : X` for use -- with `IsLindelof.indexed_countable_subcover` momentarily. have (a : X) : ∃ n : Set X, IsOpen n ∧ Disjoint (closure n) t ∧ (a ∈ s → a ∈ n) := by wlog ains : a ∈ s · exact ⟨∅, isOpen_empty, SeparatedNhds.empty_left t |>.disjoint_closure_left, fun a ↦ ains a⟩ obtain ⟨n, nna, ncl, nsubkc⟩ := ((regularSpace_TFAE X).out 0 3 :).mp ‹RegularSpace X› a tᶜ <| t_cl.compl_mem_nhds (disjoint_left.mp st_dis ains) exact ⟨interior n, isOpen_interior, disjoint_left.mpr fun ⦃_⦄ ain ↦ nsubkc <| (IsClosed.closure_subset_iff ncl).mpr interior_subset ain, fun _ ↦ mem_interior_iff_mem_nhds.mpr nna⟩ -- By Lindelöf, we may obtain a countable subcover witnessing `HasSeparatingCover` choose u u_open u_dis u_nhds using this obtain ⟨f, f_cov⟩ := s_cl.isLindelof.indexed_countable_subcover u u_open (fun a ainh ↦ mem_iUnion.mpr ⟨a, u_nhds a ainh⟩) exact ⟨u ∘ f, f_cov, fun n ↦ ⟨u_open (f n), u_dis (f n)⟩⟩ /-- Given two separable points `x` and `y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. -/ theorem disjoint_nested_nhds_of_not_inseparable [RegularSpace X] {x y : X} (h : ¬Inseparable x y) : ∃ U₁ ∈ 𝓝 x, ∃ V₁ ∈ 𝓝 x, ∃ U₂ ∈ 𝓝 y, ∃ V₂ ∈ 𝓝 y, IsClosed V₁ ∧ IsClosed V₂ ∧ IsOpen U₁ ∧ IsOpen U₂ ∧ V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ Disjoint U₁ U₂ := by rcases r1_separation h with ⟨U₁, U₂, U₁_op, U₂_op, x_in, y_in, H⟩ rcases exists_mem_nhds_isClosed_subset (U₁_op.mem_nhds x_in) with ⟨V₁, V₁_in, V₁_closed, h₁⟩ rcases exists_mem_nhds_isClosed_subset (U₂_op.mem_nhds y_in) with ⟨V₂, V₂_in, V₂_closed, h₂⟩ exact ⟨U₁, mem_of_superset V₁_in h₁, V₁, V₁_in, U₂, mem_of_superset V₂_in h₂, V₂, V₂_in, V₁_closed, V₂_closed, U₁_op, U₂_op, h₁, h₂, H⟩ end RegularSpace section LocallyCompactRegularSpace /-- In a (possibly non-Hausdorff) locally compact regular space, for every containment `K ⊆ U` of a compact set `K` in an open set `U`, there is a compact closed neighborhood `L` such that `K ⊆ L ⊆ U`: equivalently, there is a compact closed set `L` such that `K ⊆ interior L` and `L ⊆ U`. -/ theorem exists_compact_closed_between [LocallyCompactSpace X] [RegularSpace X] {K U : Set X} (hK : IsCompact K) (hU : IsOpen U) (h_KU : K ⊆ U) : ∃ L, IsCompact L ∧ IsClosed L ∧ K ⊆ interior L ∧ L ⊆ U := let ⟨L, L_comp, KL, LU⟩ := exists_compact_between hK hU h_KU ⟨closure L, L_comp.closure, isClosed_closure, KL.trans <| interior_mono subset_closure, L_comp.closure_subset_of_isOpen hU LU⟩ /-- In a locally compact regular space, given a compact set `K` inside an open set `U`, we can find an open set `V` between these sets with compact closure: `K ⊆ V` and the closure of `V` is inside `U`. -/ theorem exists_open_between_and_isCompact_closure [LocallyCompactSpace X] [RegularSpace X] {K U : Set X} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V, IsOpen V ∧ K ⊆ V ∧ closure V ⊆ U ∧ IsCompact (closure V) := by rcases exists_compact_closed_between hK hU hKU with ⟨L, L_compact, L_closed, KL, LU⟩ have A : closure (interior L) ⊆ L := by apply (closure_mono interior_subset).trans (le_of_eq L_closed.closure_eq) refine ⟨interior L, isOpen_interior, KL, A.trans LU, ?_⟩ exact L_compact.closure_of_subset interior_subset lemma IsCompact.closure_eq_nhdsKer [RegularSpace X] {s : Set X} (hs : IsCompact s) : closure s = nhdsKer s := by apply subset_antisymm · rw [nhdsKer, ← hs.lift'_closure_nhdsSet] simp +contextual [Filter.lift', Filter.lift, closure_mono, subset_of_mem_nhdsSet] · intro y hy by_contra! hy' rw [← _root_.disjoint_nhdsSet_nhds, Filter.disjoint_iff] at hy' obtain ⟨t, hts, t', ht'y, H⟩ := hy' exact Set.disjoint_iff.mp H ⟨hy t hts, mem_of_mem_nhds ht'y⟩ end LocallyCompactRegularSpace section T25 /-- A T₂.₅ space, also known as a Urysohn space, is a topological space where for every pair `x ≠ y`, there are two open sets, with the intersection of closures empty, one containing `x` and the other `y` . -/ class T25Space (X : Type u) [TopologicalSpace X] : Prop where /-- Given two distinct points in a T₂.₅ space, their filters of closed neighborhoods are disjoint. -/ t2_5 : ∀ ⦃x y : X⦄, x ≠ y → Disjoint ((𝓝 x).lift' closure) ((𝓝 y).lift' closure) @[simp] theorem disjoint_lift'_closure_nhds [T25Space X] {x y : X} : Disjoint ((𝓝 x).lift' closure) ((𝓝 y).lift' closure) ↔ x ≠ y := ⟨fun h hxy => by simp [hxy, nhds_neBot.ne] at h, fun h => T25Space.t2_5 h⟩ -- see Note [lower instance priority] instance (priority := 100) T25Space.t2Space [T25Space X] : T2Space X := t2Space_iff_disjoint_nhds.2 fun _ _ hne => (disjoint_lift'_closure_nhds.2 hne).mono (le_lift'_closure _) (le_lift'_closure _) theorem exists_nhds_disjoint_closure [T25Space X] {x y : X} (h : x ≠ y) : ∃ s ∈ 𝓝 x, ∃ t ∈ 𝓝 y, Disjoint (closure s) (closure t) := ((𝓝 x).basis_sets.lift'_closure.disjoint_iff (𝓝 y).basis_sets.lift'_closure).1 <| disjoint_lift'_closure_nhds.2 h theorem exists_open_nhds_disjoint_closure [T25Space X] {x y : X} (h : x ≠ y) : ∃ u : Set X, x ∈ u ∧ IsOpen u ∧ ∃ v : Set X, y ∈ v ∧ IsOpen v ∧ Disjoint (closure u) (closure v) := by simpa only [exists_prop, and_assoc] using ((nhds_basis_opens x).lift'_closure.disjoint_iff (nhds_basis_opens y).lift'_closure).1 (disjoint_lift'_closure_nhds.2 h) theorem T25Space.of_injective_continuous [TopologicalSpace Y] [T25Space Y] {f : X → Y} (hinj : Injective f) (hcont : Continuous f) : T25Space X where t2_5 x y hne := (tendsto_lift'_closure_nhds hcont x).disjoint (t2_5 <| hinj.ne hne) (tendsto_lift'_closure_nhds hcont y) theorem Topology.IsEmbedding.t25Space [TopologicalSpace Y] [T25Space Y] {f : X → Y} (hf : IsEmbedding f) : T25Space X := .of_injective_continuous hf.injective hf.continuous protected theorem Homeomorph.t25Space [TopologicalSpace Y] [T25Space X] (h : X ≃ₜ Y) : T25Space Y := h.symm.isEmbedding.t25Space instance Subtype.instT25Space [T25Space X] {p : X → Prop} : T25Space {x // p x} := IsEmbedding.subtypeVal.t25Space end T25 section T3 /-- A T₃ space is a T₀ space which is a regular space. Any T₃ space is a T₁ space, a T₂ space, and a T₂.₅ space. -/ class T3Space (X : Type u) [TopologicalSpace X] : Prop extends T0Space X, RegularSpace X instance (priority := 90) instT3Space [T0Space X] [RegularSpace X] : T3Space X := ⟨⟩ theorem RegularSpace.t3Space_iff_t0Space [RegularSpace X] : T3Space X ↔ T0Space X := by constructor <;> intro <;> infer_instance -- see Note [lower instance priority] instance (priority := 100) T3Space.t25Space [T3Space X] : T25Space X := by refine ⟨fun x y hne => ?_⟩ rw [lift'_nhds_closure, lift'_nhds_closure] have : x ∉ closure {y} ∨ y ∉ closure {x} := (t0Space_iff_or_notMem_closure X).mp inferInstance hne simp only [← disjoint_nhds_nhdsSet, nhdsSet_singleton] at this exact this.elim id fun h => h.symm protected theorem Topology.IsEmbedding.t3Space [TopologicalSpace Y] [T3Space Y] {f : X → Y} (hf : IsEmbedding f) : T3Space X := { toT0Space := hf.t0Space toRegularSpace := hf.isInducing.regularSpace } protected theorem Homeomorph.t3Space [TopologicalSpace Y] [T3Space X] (h : X ≃ₜ Y) : T3Space Y := h.symm.isEmbedding.t3Space instance Subtype.t3Space [T3Space X] {p : X → Prop} : T3Space (Subtype p) := IsEmbedding.subtypeVal.t3Space instance ULift.instT3Space [T3Space X] : T3Space (ULift X) := IsEmbedding.uliftDown.t3Space instance [TopologicalSpace Y] [T3Space X] [T3Space Y] : T3Space (X × Y) := ⟨⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T3Space (X i)] : T3Space (∀ i, X i) := ⟨⟩ /-- Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. -/ theorem disjoint_nested_nhds [T3Space X] {x y : X} (h : x ≠ y) : ∃ U₁ ∈ 𝓝 x, ∃ V₁ ∈ 𝓝 x, ∃ U₂ ∈ 𝓝 y, ∃ V₂ ∈ 𝓝 y, IsClosed V₁ ∧ IsClosed V₂ ∧ IsOpen U₁ ∧ IsOpen U₂ ∧ V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ Disjoint U₁ U₂ := disjoint_nested_nhds_of_not_inseparable (mt Inseparable.eq h) open SeparationQuotient /-- The `SeparationQuotient` of a regular space is a T₃ space. -/ instance [RegularSpace X] : T3Space (SeparationQuotient X) where regular {s a} hs ha := by rcases surjective_mk a with ⟨a, rfl⟩ rw [← disjoint_comap_iff surjective_mk, comap_mk_nhds_mk, comap_mk_nhdsSet] exact RegularSpace.regular (hs.preimage continuous_mk) ha end T3 section NormalSpace /-- A topological space is said to be a *normal space* if any two disjoint closed sets have disjoint open neighborhoods. -/ class NormalSpace (X : Type u) [TopologicalSpace X] : Prop where /-- Two disjoint sets in a normal space admit disjoint neighbourhoods. -/ normal : ∀ s t : Set X, IsClosed s → IsClosed t → Disjoint s t → SeparatedNhds s t theorem normal_separation [NormalSpace X] {s t : Set X} (H1 : IsClosed s) (H2 : IsClosed t) (H3 : Disjoint s t) : SeparatedNhds s t := NormalSpace.normal s t H1 H2 H3 theorem disjoint_nhdsSet_nhdsSet [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : Disjoint (𝓝ˢ s) (𝓝ˢ t) := (normal_separation hs ht hd).disjoint_nhdsSet theorem normal_exists_closure_subset [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ u, IsOpen u ∧ s ⊆ u ∧ closure u ⊆ t := by have : Disjoint s tᶜ := Set.disjoint_left.mpr fun x hxs hxt => hxt (hst hxs) rcases normal_separation hs (isClosed_compl_iff.2 ht) this with ⟨s', t', hs', ht', hss', htt', hs't'⟩ refine ⟨s', hs', hss', Subset.trans (closure_minimal ?_ (isClosed_compl_iff.2 ht')) (compl_subset_comm.1 htt')⟩ exact fun x hxs hxt => hs't'.le_bot ⟨hxs, hxt⟩ /-- If the codomain of a closed embedding is a normal space, then so is the domain. -/ protected theorem Topology.IsClosedEmbedding.normalSpace [TopologicalSpace Y] [NormalSpace Y] {f : X → Y} (hf : IsClosedEmbedding f) : NormalSpace X where normal s t hs ht hst := by have H : SeparatedNhds (f '' s) (f '' t) := NormalSpace.normal (f '' s) (f '' t) (hf.isClosedMap s hs) (hf.isClosedMap t ht) (disjoint_image_of_injective hf.injective hst) exact (H.preimage hf.continuous).mono (subset_preimage_image _ _) (subset_preimage_image _ _) protected theorem Homeomorph.normalSpace [TopologicalSpace Y] [NormalSpace X] (h : X ≃ₜ Y) : NormalSpace Y := h.symm.isClosedEmbedding.normalSpace instance (priority := 100) NormalSpace.of_compactSpace_r1Space [CompactSpace X] [R1Space X] : NormalSpace X where normal _s _t hs ht := .of_isCompact_isCompact_isClosed hs.isCompact ht.isCompact ht /-- A regular topological space with a Lindelöf topology is a normal space. A consequence of e.g. Corollaries 20.8 and 20.10 of [Willard's *General Topology*][zbMATH02107988] (without the assumption of Hausdorff). -/ instance (priority := 100) NormalSpace.of_regularSpace_lindelofSpace [RegularSpace X] [LindelofSpace X] : NormalSpace X where normal _ _ hcl kcl hkdis := hasSeparatingCovers_iff_separatedNhds.mp ⟨hcl.HasSeparatingCover kcl hkdis, kcl.HasSeparatingCover hcl (Disjoint.symm hkdis)⟩ instance (priority := 100) NormalSpace.of_regularSpace_secondCountableTopology [RegularSpace X] [SecondCountableTopology X] : NormalSpace X := of_regularSpace_lindelofSpace end NormalSpace section Normality /-- A T₄ space is a normal T₁ space. -/ class T4Space (X : Type u) [TopologicalSpace X] : Prop extends T1Space X, NormalSpace X instance (priority := 100) [T1Space X] [NormalSpace X] : T4Space X := ⟨⟩ -- see Note [lower instance priority] instance (priority := 100) T4Space.t3Space [T4Space X] : T3Space X where regular hs hxs := by simpa only [nhdsSet_singleton] using (normal_separation hs isClosed_singleton (disjoint_singleton_right.mpr hxs)).disjoint_nhdsSet /-- If the codomain of a closed embedding is a T₄ space, then so is the domain. -/ protected theorem Topology.IsClosedEmbedding.t4Space [TopologicalSpace Y] [T4Space Y] {f : X → Y} (hf : IsClosedEmbedding f) : T4Space X where toT1Space := hf.isEmbedding.t1Space toNormalSpace := hf.normalSpace protected theorem Homeomorph.t4Space [TopologicalSpace Y] [T4Space X] (h : X ≃ₜ Y) : T4Space Y := h.symm.isClosedEmbedding.t4Space instance ULift.instT4Space [T4Space X] : T4Space (ULift X) := IsClosedEmbedding.uliftDown.t4Space namespace SeparationQuotient /-- The `SeparationQuotient` of a normal space is a normal space. -/ instance [NormalSpace X] : NormalSpace (SeparationQuotient X) where normal s t hs ht hd := separatedNhds_iff_disjoint.2 <| by rw [← disjoint_comap_iff surjective_mk, comap_mk_nhdsSet, comap_mk_nhdsSet] exact disjoint_nhdsSet_nhdsSet (hs.preimage continuous_mk) (ht.preimage continuous_mk) (hd.preimage mk) end SeparationQuotient variable (X) end Normality section CompletelyNormal /-- A topological space `X` is a *completely normal space* provided that for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. -/ class CompletelyNormalSpace (X : Type u) [TopologicalSpace X] : Prop where /-- If `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then `s` and `t` admit disjoint neighbourhoods. -/ completely_normal : ∀ ⦃s t : Set X⦄, Disjoint (closure s) t → Disjoint s (closure t) → Disjoint (𝓝ˢ s) (𝓝ˢ t) export CompletelyNormalSpace (completely_normal) -- see Note [lower instance priority] /-- A completely normal space is a normal space. -/ instance (priority := 100) CompletelyNormalSpace.toNormalSpace [CompletelyNormalSpace X] : NormalSpace X where normal s t hs ht hd := separatedNhds_iff_disjoint.2 <| completely_normal (by rwa [hs.closure_eq]) (by rwa [ht.closure_eq]) theorem Topology.IsEmbedding.completelyNormalSpace [TopologicalSpace Y] [CompletelyNormalSpace Y] {e : X → Y} (he : IsEmbedding e) : CompletelyNormalSpace X := by refine ⟨fun s t hd₁ hd₂ => ?_⟩ simp only [he.isInducing.nhdsSet_eq_comap] refine disjoint_comap (completely_normal ?_ ?_) · rwa [← subset_compl_iff_disjoint_left, image_subset_iff, preimage_compl, ← he.closure_eq_preimage_closure_image, subset_compl_iff_disjoint_left] · rwa [← subset_compl_iff_disjoint_right, image_subset_iff, preimage_compl, ← he.closure_eq_preimage_closure_image, subset_compl_iff_disjoint_right] /-- A subspace of a completely normal space is a completely normal space. -/ instance [CompletelyNormalSpace X] {p : X → Prop} : CompletelyNormalSpace { x // p x } := IsEmbedding.subtypeVal.completelyNormalSpace instance ULift.instCompletelyNormalSpace [CompletelyNormalSpace X] : CompletelyNormalSpace (ULift X) := IsEmbedding.uliftDown.completelyNormalSpace /-- A T₅ space is a completely normal T₁ space. -/ class T5Space (X : Type u) [TopologicalSpace X] : Prop extends T1Space X, CompletelyNormalSpace X theorem Topology.IsEmbedding.t5Space [TopologicalSpace Y] [T5Space Y] {e : X → Y} (he : IsEmbedding e) : T5Space X where __ := he.t1Space completely_normal := by have := he.completelyNormalSpace exact completely_normal protected theorem Homeomorph.t5Space [TopologicalSpace Y] [T5Space X] (h : X ≃ₜ Y) : T5Space Y := h.symm.isClosedEmbedding.t5Space -- see Note [lower instance priority] /-- A `T₅` space is a `T₄` space. -/ instance (priority := 100) T5Space.toT4Space [T5Space X] : T4Space X where -- follows from type-class inference /-- A subspace of a T₅ space is a T₅ space. -/ instance [T5Space X] {p : X → Prop} : T5Space { x // p x } := IsEmbedding.subtypeVal.t5Space instance ULift.instT5Space [T5Space X] : T5Space (ULift X) := IsEmbedding.uliftDown.t5Space open SeparationQuotient /-- The `SeparationQuotient` of a completely normal R₀ space is a T₅ space. -/ instance [CompletelyNormalSpace X] [R0Space X] : T5Space (SeparationQuotient X) where t1 := by rwa [((t1Space_TFAE (SeparationQuotient X)).out 1 0 :), SeparationQuotient.t1Space_iff] completely_normal s t hd₁ hd₂ := by rw [← disjoint_comap_iff surjective_mk, comap_mk_nhdsSet, comap_mk_nhdsSet] apply completely_normal <;> rw [← preimage_mk_closure] exacts [hd₁.preimage mk, hd₂.preimage mk] end CompletelyNormal /-- In a compact T₂ space, the connected component of a point equals the intersection of all its clopen neighbourhoods. -/ theorem connectedComponent_eq_iInter_isClopen [T2Space X] [CompactSpace X] (x : X) : connectedComponent x = ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, s := by apply Subset.antisymm connectedComponent_subset_iInter_isClopen -- Reduce to showing that the clopen intersection is connected. refine IsPreconnected.subset_connectedComponent ?_ (mem_iInter.2 fun s => s.2.2) -- We do this by showing that any disjoint cover by two closed sets implies -- that one of these closed sets must contain our whole thing. -- To reduce to the case where the cover is disjoint on all of `X` we need that `s` is closed have hs : @IsClosed X _ (⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, s) := isClosed_iInter fun s => s.2.1.1 rw [isPreconnected_iff_subset_of_fully_disjoint_closed hs] intro a b ha hb hab ab_disj -- Since our space is normal, we get two larger disjoint open sets containing the disjoint -- closed sets. If we can show that our intersection is a subset of any of these we can then -- "descend" this to show that it is a subset of either a or b. rcases normal_separation ha hb ab_disj with ⟨u, v, hu, hv, hau, hbv, huv⟩ obtain ⟨s, H⟩ : ∃ s : Set X, IsClopen s ∧ x ∈ s ∧ s ⊆ u ∪ v := by /- Now we find a clopen set `s` around `x`, contained in `u ∪ v`. We utilize the fact that `X \ u ∪ v` will be compact, so there must be some finite intersection of clopen neighbourhoods of `X` disjoint to it, but a finite intersection of clopen sets is clopen, so we let this be our `s`. -/ have H1 := (hu.union hv).isClosed_compl.isCompact.inter_iInter_nonempty (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s) fun s => s.2.1.1 rw [← not_disjoint_iff_nonempty_inter, imp_not_comm, not_forall] at H1 obtain ⟨si, H2⟩ := H1 (disjoint_compl_left_iff_subset.2 <| hab.trans <| union_subset_union hau hbv) refine ⟨⋂ U ∈ si, Subtype.val U, ?_, ?_, ?_⟩ · exact isClopen_biInter_finset fun s _ => s.2.1 · exact mem_iInter₂.2 fun s _ => s.2.2 · rwa [← disjoint_compl_left_iff_subset, disjoint_iff_inter_eq_empty, ← not_nonempty_iff_eq_empty] -- So, we get a disjoint decomposition `s = s ∩ u ∪ s ∩ v` of clopen sets. The intersection of all -- clopen neighbourhoods will then lie in whichever of u or v x lies in and hence will be a subset -- of either a or b. · have H1 := isClopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv rw [union_comm] at H have H2 := isClopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu huv.symm by_cases hxu : x ∈ u <;> [left; right] -- The x ∈ u case. · suffices ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, ↑s ⊆ u from Disjoint.left_le_of_le_sup_right hab (huv.mono this hbv) · apply Subset.trans _ s.inter_subset_right exact iInter_subset (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s.1) ⟨s ∩ u, H1, mem_inter H.2.1 hxu⟩ -- If x ∉ u, we get x ∈ v since x ∈ u ∪ v. The rest is then like the x ∈ u case. · have h1 : x ∈ v := (hab.trans (union_subset_union hau hbv) (mem_iInter.2 fun i => i.2.2)).resolve_left hxu suffices ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, ↑s ⊆ v from (huv.symm.mono this hau).left_le_of_le_sup_left hab · refine Subset.trans ?_ s.inter_subset_right exact iInter_subset (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s.1) ⟨s ∩ v, H2, mem_inter H.2.1 h1⟩ /-- `ConnectedComponents X` is Hausdorff when `X` is Hausdorff and compact -/ @[stacks 0900 "The Stacks entry proves profiniteness."] instance ConnectedComponents.t2 [T2Space X] [CompactSpace X] : T2Space (ConnectedComponents X) := by -- Fix 2 distinct connected components, with points a and b refine ⟨ConnectedComponents.surjective_coe.forall₂.2 fun a b ne => ?_⟩ rw [ConnectedComponents.coe_ne_coe] at ne have h := connectedComponent_disjoint ne -- write ↑b as the intersection of all clopen subsets containing it rw [connectedComponent_eq_iInter_isClopen b, disjoint_iff_inter_eq_empty] at h -- Now we show that this can be reduced to some clopen containing `↑b` being disjoint to `↑a` obtain ⟨U, V, hU, ha, hb, rfl⟩ : ∃ (U : Set X) (V : Set (ConnectedComponents X)), IsClopen U ∧ connectedComponent a ∩ U = ∅ ∧ connectedComponent b ⊆ U ∧ (↑) ⁻¹' V = U := by have h := (isClosed_connectedComponent (α := X)).isCompact.elim_finite_subfamily_closed _ (fun s : { s : Set X // IsClopen s ∧ b ∈ s } => s.2.1.1) h obtain ⟨fin_a, ha⟩ := h -- This clopen and its complement will separate the connected components of `a` and `b` set U : Set X := ⋂ (i : { s // IsClopen s ∧ b ∈ s }) (_ : i ∈ fin_a), i have hU : IsClopen U := isClopen_biInter_finset fun i _ => i.2.1 exact ⟨U, (↑) '' U, hU, ha, subset_iInter₂ fun s _ => s.2.1.connectedComponent_subset s.2.2, (connectedComponents_preimage_image U).symm ▸ hU.biUnion_connectedComponent_eq⟩ rw [ConnectedComponents.isQuotientMap_coe.isClopen_preimage] at hU refine ⟨Vᶜ, V, hU.compl.isOpen, hU.isOpen, ?_, hb mem_connectedComponent, disjoint_compl_left⟩ exact fun h => flip Set.Nonempty.ne_empty ha ⟨a, mem_connectedComponent, h⟩
.lake/packages/mathlib/Mathlib/Topology/Separation/GDelta.lean
import Mathlib.Topology.Compactness.Lindelof import Mathlib.Topology.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable import Mathlib.Topology.Separation.Regular import Mathlib.Topology.GDelta.Basic /-! # Separation properties of topological spaces. ## Main definitions * `PerfectlyNormalSpace`: A perfectly normal space is a normal space such that closed sets are Gδ. * `T6Space`: A T₆ space is a perfectly normal T₀ space. T₆ implies T₅. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. -/ open Function Set Filter Topology TopologicalSpace universe u variable {X : Type*} [TopologicalSpace X] section Separation theorem IsGδ.compl_singleton (x : X) [T1Space X] : IsGδ ({x}ᶜ : Set X) := isOpen_compl_singleton.isGδ theorem Set.Countable.isGδ_compl {s : Set X} [T1Space X] (hs : s.Countable) : IsGδ sᶜ := by rw [← biUnion_of_singleton s, compl_iUnion₂] exact .biInter hs fun x _ => .compl_singleton x theorem Set.Finite.isGδ_compl {s : Set X} [T1Space X] (hs : s.Finite) : IsGδ sᶜ := hs.countable.isGδ_compl theorem Set.Subsingleton.isGδ_compl {s : Set X} [T1Space X] (hs : s.Subsingleton) : IsGδ sᶜ := hs.finite.isGδ_compl theorem Finset.isGδ_compl [T1Space X] (s : Finset X) : IsGδ (sᶜ : Set X) := s.finite_toSet.isGδ_compl protected theorem IsGδ.singleton [FirstCountableTopology X] [T1Space X] (x : X) : IsGδ ({x} : Set X) := by rcases (nhds_basis_opens x).exists_antitone_subbasis with ⟨U, hU, h_basis⟩ rw [← biInter_basis_nhds h_basis.toHasBasis] exact .biInter (to_countable _) fun n _ => (hU n).2.isGδ theorem Set.Finite.isGδ [FirstCountableTopology X] {s : Set X} [T1Space X] (hs : s.Finite) : IsGδ s := Finite.induction_on _ hs .empty fun _ _ ↦ .union (.singleton _) section PerfectlyNormal /-- A topological space `X` is a *perfectly normal space* provided it is normal and closed sets are Gδ. -/ class PerfectlyNormalSpace (X : Type u) [TopologicalSpace X] : Prop extends NormalSpace X where closed_gdelta : ∀ ⦃h : Set X⦄, IsClosed h → IsGδ h /-- Lemma that allows the easy conclusion that perfectly normal spaces are completely normal. -/ theorem Disjoint.hasSeparatingCover_closed_gdelta_right {s t : Set X} [NormalSpace X] (st_dis : Disjoint s t) (t_cl : IsClosed t) (t_gd : IsGδ t) : HasSeparatingCover s t := by obtain ⟨T, T_open, T_count, T_int⟩ := t_gd rcases T.eq_empty_or_nonempty with rfl | T_nonempty · rw [T_int, sInter_empty] at st_dis rw [(s.disjoint_univ).mp st_dis] exact t.hasSeparatingCover_empty_left obtain ⟨g, g_surj⟩ := T_count.exists_surjective T_nonempty choose g' g'_open clt_sub_g' clg'_sub_g using fun n ↦ by apply normal_exists_closure_subset t_cl (T_open (g n).1 (g n).2) rw [T_int] exact sInter_subset_of_mem (g n).2 have clg'_int : t = ⋂ i, closure (g' i) := by apply (subset_iInter fun n ↦ (clt_sub_g' n).trans subset_closure).antisymm rw [T_int] refine subset_sInter fun t tinT ↦ ?_ obtain ⟨n, gn⟩ := g_surj ⟨t, tinT⟩ refine iInter_subset_of_subset n <| (clg'_sub_g n).trans ?_ rw [gn] use fun n ↦ (closure (g' n))ᶜ constructor · rw [← compl_iInter, subset_compl_comm, ← clg'_int] exact st_dis.subset_compl_left · refine fun n ↦ ⟨isOpen_compl_iff.mpr isClosed_closure, ?_⟩ simp only [closure_compl, disjoint_compl_left_iff_subset] rw [← closure_eq_iff_isClosed.mpr t_cl] at clt_sub_g' exact subset_closure.trans <| (clt_sub_g' n).trans <| (g'_open n).subset_interior_closure instance (priority := 100) PerfectlyNormalSpace.toCompletelyNormalSpace [PerfectlyNormalSpace X] : CompletelyNormalSpace X where completely_normal _ _ hd₁ hd₂ := separatedNhds_iff_disjoint.mp <| hasSeparatingCovers_iff_separatedNhds.mp ⟨(hd₂.hasSeparatingCover_closed_gdelta_right isClosed_closure <| closed_gdelta isClosed_closure).mono (fun ⦃_⦄ a ↦ a) subset_closure, ((Disjoint.symm hd₁).hasSeparatingCover_closed_gdelta_right isClosed_closure <| closed_gdelta isClosed_closure).mono (fun ⦃_⦄ a ↦ a) subset_closure⟩ /-- In a perfectly normal space, all closed sets are Gδ. -/ theorem IsClosed.isGδ [PerfectlyNormalSpace X] {s : Set X} (hs : IsClosed s) : IsGδ s := PerfectlyNormalSpace.closed_gdelta hs instance (priority := 100) [PerfectlyNormalSpace X] : R0Space X where specializes_symmetric x y hxy := by rw [specializes_iff_forall_closed] intro K hK hyK apply IsClosed.isGδ at hK obtain ⟨Ts, hoTs, -, rfl⟩ := hK rw [mem_sInter] at hyK ⊢ intros solve_by_elim [hxy.mem_open] /-- A T₆ space is a perfectly normal T₀ space. -/ class T6Space (X : Type u) [TopologicalSpace X] : Prop extends T0Space X, PerfectlyNormalSpace X -- see Note [lower instance priority] /-- A `T₆` space is a `T₅` space. -/ instance (priority := 100) T6Space.toT5Space [T6Space X] : T5Space X where end PerfectlyNormal end Separation