path
stringlengths
11
71
content
stringlengths
75
124k
Topology\UniformSpace\AbsoluteValue.lean
/- Copyright (c) 2019 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Field.Basic import Mathlib.Topology.UniformSpace.Basic /-! # 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*} [LinearOrderedField š•œ] 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 x y z => (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
Topology\UniformSpace\AbstractCompletion.lean
/- Copyright (c) 2019 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ 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 attribute [local instance] Classical.propDecidable open Filter Set Function universe u /-- A completion of `α` is the data of a complete separated uniform space (from the same universe) and a map from `α` with dense range and inducing the original uniform structure on `α`. -/ structure AbstractCompletion (α : Type u) [UniformSpace α] where /-- The underlying space of the completion. -/ space : Type u /-- 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. -/ uniformInducing : UniformInducing coe /-- The map into the completion has dense range. -/ dense : DenseRange coe attribute [local instance] AbstractCompletion.uniformStruct AbstractCompletion.complete AbstractCompletion.separation namespace AbstractCompletion variable {α : Type*} [UniformSpace α] (pkg : AbstractCompletion α) 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 uniformInducing_id denseRange_id theorem closure_range : closure (range ι) = univ := pkg.dense.closure_range theorem denseInducing : DenseInducing ι := ⟨pkg.uniformInducing.inducing, pkg.dense⟩ theorem uniformContinuous_coe : UniformContinuous ι := UniformInducing.uniformContinuous pkg.uniformInducing 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*} 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α → β := if UniformContinuous f then pkg.denseInducing.extend f else fun x => f (pkg.dense.some x) variable {f : α → β} theorem extend_def (hf : UniformContinuous f) : pkg.extend f = pkg.denseInducing.extend f := if_pos hf theorem extend_coe [T2Space β] (hf : UniformContinuous f) (a : α) : (pkg.extend f) (ι a) = f a := by rw [pkg.extend_def hf] exact pkg.denseInducing.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.uniformInducing pkg.dense hf Ā· change UniformContinuous (ite _ _ _) 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 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 β) 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 [(Ā· ∘ Ā·), 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*} [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 γ) 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 end MapSec section Compare -- We can now compare two completion packages for the same uniform space variable (pkg' : AbstractCompletion α) /-- 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*) [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.denseInducing.extend f) a))) → pkg.denseInducing.extend f ∘ pkg'.compare pkg = pkg'.denseInducing.extend f := by let _ := pkg'.uniformStruct let _ := pkg.uniformStruct intro h have (x : α) : (pkg.denseInducing.extend f ∘ pkg'.compare pkg) (pkg'.coe x) = f x := by simp only [Function.comp_apply, compare_coe, DenseInducing.extend_eq _ cont_f, implies_true] apply (DenseInducing.extend_unique (AbstractCompletion.denseInducing _) this (Continuous.comp _ (uniformContinuous_compare pkg' pkg).continuous )).symm apply DenseInducing.continuous_extend exact fun a ↦ ⟨(pkg.denseInducing.extend f) a, h a⟩ end Compare section Prod variable (pkg' : AbstractCompletion β) 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 uniformInducing := UniformInducing.prod pkg.uniformInducing pkg'.uniformInducing dense := DenseRange.prod_map pkg.dense pkg'.dense end Prod section Extensionā‚‚ variable (pkg' : AbstractCompletion β) local notation "hatβ" => pkg'.space local notation "ι'" => pkg'.coe variable {γ : Type*} [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*} [UniformSpace γ] (pkg'' : AbstractCompletion γ) 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 (Continuous.prod_mk 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
Topology\UniformSpace\Ascoli.lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ 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 subsetes 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 `UniformInducing`: `Equicontinuous.uniformInducing_uniformFun_iff_pi` - in terms of `Inducing`: `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 `UniformInducing`: `EquicontinuousOn.uniformInducing_uniformOnFun_iff_pi'` - in terms of `Inducing`: `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 thouroughly. * 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 criterions 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 Y α β : Type*} [TopologicalSpace X] [UniformSpace α] [UniformSpace β] variable {F : ι → X → α} {G : ι → β → α} /-- 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.uniformInducing_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. change comap _ _ ≤ comap _ _ simp_rw [Pi.uniformity, Filter.comap_iInf, comap_comap, Function.comp] 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 (prod_mk_mem_compRel (prod_mk_mem_compRel (Vsymm.mk_mem_comm.mp (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 `UniformInducing` for convenuence. -/ lemma Equicontinuous.uniformInducing_uniformFun_iff_pi [UniformSpace ι] [CompactSpace X] (F_eqcont : Equicontinuous F) : UniformInducing (UniformFun.ofFun ∘ F) ↔ UniformInducing F := by rw [uniformInducing_iff_uniformSpace, uniformInducing_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 `Inducing` for convenuence. -/ lemma Equicontinuous.inducing_uniformFun_iff_pi [TopologicalSpace ι] [CompactSpace X] (F_eqcont : Equicontinuous F) : Inducing (UniformFun.ofFun ∘ F) ↔ Inducing F := by rw [inducing_iff, inducing_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 : Inducing (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.uniformInducing_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, 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 `UniformInducing` for convenuence. -/ lemma EquicontinuousOn.uniformInducing_uniformOnFun_iff_pi' [UniformSpace ι] {š”– : Set (Set X)} (š”–_compact : āˆ€ K ∈ š”–, IsCompact K) (F_eqcont : āˆ€ K ∈ š”–, EquicontinuousOn F K) : UniformInducing (UniformOnFun.ofFun š”– ∘ F) ↔ UniformInducing ((ā‹ƒā‚€ š”–).restrict ∘ F) := by rw [uniformInducing_iff_uniformSpace, uniformInducing_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.uniformInducing_uniformOnFun_iff_pi'` to the case where `š”–` covers `X`. -/ lemma EquicontinuousOn.uniformInducing_uniformOnFun_iff_pi [UniformSpace ι] {š”– : Set (Set X)} (š”–_covers : ā‹ƒā‚€ š”– = univ) (š”–_compact : āˆ€ K ∈ š”–, IsCompact K) (F_eqcont : āˆ€ K ∈ š”–, EquicontinuousOn F K) : UniformInducing (UniformOnFun.ofFun š”– ∘ F) ↔ UniformInducing 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.uniformInducing_uniformOnFun_iff_pi' š”–_compact F_eqcont, show restrict (ā‹ƒā‚€ š”–) ∘ F = φ.symm ∘ F by rfl] exact ⟨fun H ↦ φ.uniformInducing.comp H, fun H ↦ φ.symm.uniformInducing.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 `Inducing` for convenuence. -/ lemma EquicontinuousOn.inducing_uniformOnFun_iff_pi' [TopologicalSpace ι] {š”– : Set (Set X)} (š”–_compact : āˆ€ K ∈ š”–, IsCompact K) (F_eqcont : āˆ€ K ∈ š”–, EquicontinuousOn F K) : Inducing (UniformOnFun.ofFun š”– ∘ F) ↔ Inducing ((ā‹ƒā‚€ š”–).restrict ∘ F) := by rw [inducing_iff, inducing_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.inducing_uniformOnFun_iff_pi [TopologicalSpace ι] {š”– : Set (Set X)} (š”–_covers : ā‹ƒā‚€ š”– = univ) (š”–_compact : āˆ€ K ∈ š”–, IsCompact K) (F_eqcont : āˆ€ K ∈ š”–, EquicontinuousOn F K) : Inducing (UniformOnFun.ofFun š”– ∘ F) ↔ Inducing 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 ↦ φ.inducing.comp H, fun H ↦ φ.symm.inducing.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 š”– (Ļ€ := 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.inducing.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 : Inducing (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 : Inducing (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_closedEmbedding [TopologicalSpace ι] {š”– : Set (Set X)} (š”–_compact : āˆ€ K ∈ š”–, IsCompact K) (F_clemb : ClosedEmbedding (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.toInducing 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_closedEmbedding [TopologicalSpace ι] [T2Space α] {š”– : Set (Set X)} (š”–_compact : āˆ€ K ∈ š”–, IsCompact K) (F_clemb : ClosedEmbedding (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_closedEmbedding` 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_closedEmbedding š”–_compact (F_clemb.comp isClosed_closure.closedEmbedding_subtype_val) 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 : Inducing (Equiv.Set.image (↑) S DFunLike.coe_injective) by rw [isCompact_iff_compactSpace] at hS1 ⊢ exact (Equiv.toHomeomorphOfInducing _ h).symm.compactSpace rw [← inducing_subtype_val.of_comp_iff, ← EquicontinuousOn.inducing_uniformOnFun_iff_pi _ _ _] Ā· exact ContinuousMap.uniformEmbedding_toUniformOnFunIsCompact.inducing.comp inducing_subtype_val Ā· 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
Topology\UniformSpace\Basic.lean
/- Copyright (c) 2017 Johannes Hƶlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hƶlzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Order.Filter.SmallSets import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Compactness.Compact import Mathlib.Topology.NhdsSet import Mathlib.Algebra.Group.Defs /-! # 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 `UniformEmbedding.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` In this file we also 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. ## Notations 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)`. ## Implementation notes There is already a theory of relations in `Data/Rel.lean` where the main definition is `def Rel (α β : Type*) := α → β → Prop`. The relations used in the current file involve only one type, but this is not the reason why we don't reuse `Data/Rel.lean`. We use `Set (α Ɨ α)` instead of `Rel α α` because we really need sets to use the filter library, and elements of filters on `α Ɨ α` have type `Set (α Ɨ α)`. 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 `Set (α Ɨ α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {Ī“ : Type ud} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ def idRel {α : Type*} := { p : α Ɨ α | p.1 = p.2 } @[simp] theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b := Iff.rfl @[simp] theorem idRel_subset {s : Set (α Ɨ α)} : idRel āŠ† s ↔ āˆ€ a, (a, a) ∈ s := by simp [subset_def] /-- The composition of relations -/ def compRel (r₁ rā‚‚ : Set (α Ɨ α)) := { p : α Ɨ α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ rā‚‚ } @[inherit_doc] scoped[Uniformity] infixl:62 " ā—‹ " => compRel open Uniformity @[simp] theorem mem_compRel {α : Type u} {r₁ rā‚‚ : Set (α Ɨ α)} {x y : α} : (x, y) ∈ r₁ ā—‹ rā‚‚ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ rā‚‚ := Iff.rfl @[simp] theorem swap_idRel : Prod.swap '' idRel = @idRel α := Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm theorem Monotone.compRel [Preorder β] {f g : β → Set (α Ɨ α)} (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ā‚‚āŸ© @[mono, gcongr] theorem compRel_mono {f g h k : Set (α Ɨ α)} (h₁ : f āŠ† h) (hā‚‚ : g āŠ† k) : f ā—‹ g āŠ† h ā—‹ k := fun _ ⟨z, h, h'⟩ => ⟨z, h₁ h, hā‚‚ h'⟩ theorem prod_mk_mem_compRel {a b c : α} {s t : Set (α Ɨ α)} (h₁ : (a, c) ∈ s) (hā‚‚ : (c, b) ∈ t) : (a, b) ∈ s ā—‹ t := ⟨c, h₁, hā‚‚āŸ© @[simp] theorem id_compRel {r : Set (α Ɨ α)} : idRel ā—‹ r = r := Set.ext fun ⟨a, b⟩ => by simp theorem compRel_assoc {r s t : Set (α Ɨ α)} : r ā—‹ s ā—‹ t = r ā—‹ (s ā—‹ t) := by ext ⟨a, b⟩; simp only [mem_compRel]; tauto theorem left_subset_compRel {s t : Set (α Ɨ α)} (h : idRel āŠ† t) : s āŠ† s ā—‹ t := fun ⟨_x, y⟩ xy_in => ⟨y, xy_in, h <| rfl⟩ theorem right_subset_compRel {s t : Set (α Ɨ α)} (h : idRel āŠ† s) : t āŠ† s ā—‹ t := fun ⟨x, _y⟩ xy_in => ⟨x, h <| rfl, xy_in⟩ theorem subset_comp_self {s : Set (α Ɨ α)} (h : idRel āŠ† s) : s āŠ† s ā—‹ s := left_subset_compRel h theorem subset_iterate_compRel {s t : Set (α Ɨ α)} (h : idRel āŠ† s) (n : ā„•) : t āŠ† (s ā—‹ Ā·)^[n] t := by induction' n with n ihn generalizing t exacts [Subset.rfl, (right_subset_compRel h).trans ihn] /-- The relation is invariant under swapping factors. -/ def SymmetricRel (V : Set (α Ɨ α)) : Prop := Prod.swap ⁻¹' V = V /-- The maximal symmetric relation contained in a given relation. -/ def symmetrizeRel (V : Set (α Ɨ α)) : Set (α Ɨ α) := V ∩ Prod.swap ⁻¹' V theorem symmetric_symmetrizeRel (V : Set (α Ɨ α)) : SymmetricRel (symmetrizeRel V) := by simp [SymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp] theorem symmetrizeRel_subset_self (V : Set (α Ɨ α)) : symmetrizeRel V āŠ† V := sep_subset _ _ @[mono] theorem symmetrize_mono {V W : Set (α Ɨ α)} (h : V āŠ† W) : symmetrizeRel V āŠ† symmetrizeRel W := inter_subset_inter h <| preimage_mono h theorem SymmetricRel.mk_mem_comm {V : Set (α Ɨ α)} (hV : SymmetricRel V) {x y : α} : (x, y) ∈ V ↔ (y, x) ∈ V := Set.ext_iff.1 hV (y, x) theorem SymmetricRel.eq {U : Set (α Ɨ α)} (hU : SymmetricRel U) : Prod.swap ⁻¹' U = U := hU theorem SymmetricRel.inter {U V : Set (α Ɨ α)} (hU : SymmetricRel U) (hV : SymmetricRel V) : SymmetricRel (U ∩ V) := by rw [SymmetricRel, preimage_inter, hU.eq, hV.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 : š“Ÿ idRel ≤ 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 : Set (α Ɨ α)} (hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ā—‹ t āŠ† s := (mem_lift'_sets <| monotone_id.compRel 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 α := ⟨U, fun _r ru => idRel_subset.2 (refl _ ru), symm, fun _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 => idRel_subset.2 <| refl _ ru symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm comp := (HasBasis.le_basis_iff (B.hasBasis.lift' (monotone_id.compRel monotone_id)) 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] -- Porting note (#11215): TODO: should we drop the `uniformity` def? scoped[Uniformity] notation "š“¤" => 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] /-- Build a `UniformSpace` from a `UniformSpace.Core` and a compatible topology. Use `UniformSpace.mk` instead to avoid proving the unnecessary assumption `UniformSpace.Core.refl`. The main constructor used to use a different compatibility assumption. This definition was created as a step towards porting to a new definition. Now the main definition is ported, so this constructor will be removed in a few months. -/ @[deprecated UniformSpace.mk (since := "2024-03-20")] def UniformSpace.ofNhdsEqComap (u : UniformSpace.Core α) (_t : TopologicalSpace α) (h : āˆ€ x, š“ x = u.uniformity.comap (Prod.mk x)) : UniformSpace α where __ := u nhds_eq_comap_uniformity := h @[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 -- Porting note: rfc: use `UniformSpace.Core.mkOfBasis`? This will change defeq here and there /-- 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 UniformSpace.ofFun {α : Type u} {β : Type v} [OrderedAddCommMonoid β] (d : α → α → β) (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 : β), ∃ Ī“ > (0 : β), āˆ€ x < Ī“, āˆ€ y < Ī“, x + y < ε) : UniformSpace α := .ofCore { uniformity := ⨅ r > 0, š“Ÿ { x | d x.1 x.2 < r } refl := le_iInfā‚‚ fun r hr => principal_mono.2 <| idRel_subset.2 fun x => by simpa [refl] 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 UniformSpace.hasBasis_ofFun {α : Type u} {β : Type v} [LinearOrderedAddCommMonoid β] (hā‚€ : ∃ x : β, 0 < x) (d : α → α → β) (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 : β), ∃ Ī“ > (0 : β), āˆ€ x < Ī“, āˆ€ y < Ī“, x + y < ε) : š“¤[.ofFun d refl symm triangle half].HasBasis ((0 : β) < Ā·) (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ā‚€ 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_prod_mk] theorem refl_le_uniformity : š“Ÿ idRel ≤ š“¤ α := (@UniformSpace.toCore α _).refl instance uniformity.neBot [Nonempty α] : NeBot (š“¤ α) := diagonal_nonempty.principal_neBot.mono refl_le_uniformity theorem refl_mem_uniformity {x : α} {s : Set (α Ɨ α)} (h : s ∈ š“¤ α) : (x, x) ∈ s := refl_le_uniformity h rfl theorem mem_uniformity_of_eq {x y : α} {s : Set (α Ɨ α)} (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 : Set (α Ɨ α) => s ā—‹ s) ≤ š“¤ α := UniformSpace.comp theorem lift'_comp_uniformity : ((š“¤ α).lift' fun s : Set (α Ɨ α) => s ā—‹ s) = š“¤ α := comp_le_uniformity.antisymm <| le_lift'.2 fun _s hs ↦ mem_of_superset hs <| subset_comp_self <| idRel_subset.2 fun _ ↦ refl_mem_uniformity hs theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (š“¤ α) (š“¤ α) := symm_le_uniformity theorem comp_mem_uniformity_sets {s : Set (α Ɨ α)} (hs : s ∈ š“¤ α) : ∃ t ∈ š“¤ α, t ā—‹ t āŠ† s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| comp_le_uniformity hs /-- 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 : Set (α Ɨ α)} (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 with n ihn generalizing s Ā· simpa rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono 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 : Set (α Ɨ α)} (hs : s ∈ š“¤ α) : āˆ€į¶  t in (š“¤ α).smallSets, t ā—‹ t āŠ† s := eventually_uniformity_iterate_comp_subset hs 1 /-- 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 : Set (α Ɨ α)} (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 : Set (α Ɨ α)} (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.compRel monotone_id ht'ā‚‚) htā‚‚āŸ© theorem uniformity_le_symm : š“¤ α ≤ @Prod.swap α α <$> š“¤ α := by rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap theorem uniformity_eq_symm : š“¤ α = @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 : Set (α Ɨ α)} (h : V ∈ š“¤ α) : symmetrizeRel V ∈ š“¤ α := by apply (š“¤ α).inter_sets h rw [← image_swap_eq_preimage_swap, uniformity_eq_symm] exact image_mem_map h /-- Symmetric entourages form a basis of `š“¤ α` -/ theorem UniformSpace.hasBasis_symmetric : (š“¤ α).HasBasis (fun s : Set (α Ɨ α) => s ∈ š“¤ α ∧ SymmetricRel s) id := hasBasis_self.2 fun t t_in => ⟨symmetrizeRel t, symmetrize_mem_uniformity t_in, symmetric_symmetrizeRel t, symmetrizeRel_subset_self t⟩ theorem uniformity_lift_le_swap {g : Set (α Ɨ α) → 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 : Set (α Ɨ α) → Filter β} (h : Monotone f) : ((š“¤ α).lift fun s => f (s ā—‹ s)) ≤ (š“¤ α).lift f := calc ((š“¤ α).lift fun s => f (s ā—‹ s)) = ((š“¤ α).lift' fun s : Set (α Ɨ α) => s ā—‹ s).lift f := by rw [lift_lift'_assoc] Ā· exact monotone_id.compRel monotone_id Ā· exact h _ ≤ (š“¤ α).lift f := lift_mono comp_le_uniformity le_rfl theorem comp3_mem_uniformity {s : Set (α Ɨ α)} (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' ⟨t, ht, (compRel_mono ((subset_comp_self (refl_le_uniformity ht)).trans htt') htt').trans ht's⟩ /-- See also `comp3_mem_uniformity`. -/ theorem comp_le_uniformity3 : ((š“¤ α).lift' fun s : Set (α Ɨ α) => 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 : Set (α Ɨ α)} (hs : s ∈ š“¤ α) : ∃ t ∈ š“¤ α, SymmetricRel t ∧ t ā—‹ t āŠ† s := by obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ š“¤ α, w ā—‹ w āŠ† s := comp_mem_uniformity_sets hs use symmetrizeRel w, symmetrize_mem_uniformity w_in, symmetric_symmetrizeRel w have : symmetrizeRel w āŠ† w := symmetrizeRel_subset_self w calc symmetrizeRel w ā—‹ symmetrizeRel w _ āŠ† w ā—‹ w := by gcongr _ āŠ† s := w_sub theorem subset_comp_self_of_mem_uniformity {s : Set (α Ɨ α)} (h : s ∈ š“¤ α) : s āŠ† s ā—‹ s := subset_comp_self (refl_le_uniformity h) theorem comp_comp_symm_mem_uniformity_sets {s : Set (α Ɨ α)} (hs : s ∈ š“¤ α) : ∃ t ∈ š“¤ α, SymmetricRel 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 -- Porting note: Needed the following `have`s to make `mono` work have ht := Subset.refl t have hw := Subset.refl w calc t ā—‹ t ā—‹ t āŠ† w ā—‹ t := by mono _ āŠ† w ā—‹ (t ā—‹ t) := by mono _ āŠ† w ā—‹ w := by mono _ āŠ† s := w_sub /-! ### Balls in uniform spaces -/ /-- 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 UniformSpace.ball (x : β) (V : Set (β Ɨ β)) : Set β := Prod.mk x ⁻¹' V open UniformSpace (ball) theorem UniformSpace.mem_ball_self (x : α) {V : Set (α Ɨ α)} (hV : V ∈ š“¤ α) : x ∈ ball x V := refl_mem_uniformity hV /-- 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) := prod_mk_mem_compRel 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 mem_ball_symmetry {V : Set (β Ɨ β)} (hV : SymmetricRel V) {x y} : x ∈ ball y V ↔ y ∈ ball x V := show (x, y) ∈ Prod.swap ⁻¹' V ↔ (x, y) ∈ V by unfold SymmetricRel at hV rw [hV] theorem ball_eq_of_symmetry {V : Set (β Ɨ β)} (hV : SymmetricRel V) {x} : ball x V = { y | (y, x) ∈ V } := by ext y rw [mem_ball_symmetry hV] exact Iff.rfl theorem mem_comp_of_mem_ball {V W : Set (β Ɨ β)} {x y z : β} (hV : SymmetricRel V) (hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ā—‹ W := by rw [mem_ball_symmetry hV] at hx exact ⟨z, hx, hy⟩ theorem UniformSpace.isOpen_ball (x : α) {V : Set (α Ɨ α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| continuous_const.prod_mk continuous_id theorem UniformSpace.isClosed_ball (x : α) {V : Set (α Ɨ α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| continuous_const.prod_mk continuous_id theorem mem_comp_comp {V W M : Set (β Ɨ β)} (hW' : SymmetricRel W) {p : β Ɨ β} : p ∈ V ā—‹ M ā—‹ W ↔ (ball p.1 V Ć—Ė¢ ball p.2 W ∩ M).Nonempty := by cases' p with x y constructor Ā· rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩ exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry hW']⟩, hwz⟩ Ā· rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩ rw [mem_ball_symmetry hW'] at z_in exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩ /-! ### Neighborhoods in uniform spaces -/ 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_prod_mk] 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 [map_def, 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_open_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 : ι → Set (α Ɨ α)} (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 : ι → Set (α Ɨ α)} (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 : Set (α Ɨ α)⦄ (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 : Set (α Ɨ α)⦄ (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 ∈ š“¤ α, SymmetricRel V ∧ ball x V āŠ† s := by rw [UniformSpace.mem_nhds_iff] constructor Ā· rintro ⟨V, V_in, V_sub⟩ use symmetrizeRel V, symmetrize_mem_uniformity V_in, symmetric_symmetrizeRel V exact Subset.trans (ball_mono (symmetrizeRel_subset_self V) x) V_sub Ā· rintro ⟨V, V_in, _, V_sub⟩ exact ⟨V, V_in, V_sub⟩ theorem UniformSpace.hasBasis_nhds (x : α) : HasBasis (š“ x) (fun s : Set (α Ɨ α) => s ∈ š“¤ α ∧ SymmetricRel 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 ∈ š“¤ α → SymmetricRel 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 UniformSpace.hasBasis_nhds_prod (x y : α) : HasBasis (š“ (x, y)) (fun s => s ∈ š“¤ α ∧ SymmetricRel 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, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ 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 : Set (α Ɨ α)} (h : s ∈ š“¤ α) : { y : α | (x, y) ∈ s } ∈ š“ x := ball_mem_nhds x h theorem mem_nhds_right (y : α) {s : Set (α Ɨ α)} (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 : Set (α Ɨ α) => g (ball x s) := by rw [nhds_eq_comap_uniformity, comap_lift_eq2 hg] simp_rw [ball, Function.comp] theorem lift_nhds_right {x : α} {g : Set α → Filter β} (hg : Monotone g) : (š“ x).lift g = (š“¤ α).lift fun s : Set (α Ɨ α) => g { y | (y, x) ∈ s } := by rw [nhds_eq_comap_uniformity', comap_lift_eq2 hg] simp_rw [Function.comp, preimage] theorem nhds_nhds_eq_uniformity_uniformity_prod {a b : α} : š“ a Ć—Ė¢ š“ b = (š“¤ α).lift fun s : Set (α Ɨ α) => (š“¤ α).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 nhds_eq_uniformity_prod {a b : α} : š“ (a, b) = (š“¤ α).lift' fun s : Set (α Ɨ α) => { 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 : Set (α Ɨ α)} (s : Set (α Ɨ α)) (hd : d ∈ š“¤ α) : ∃ t : Set (α Ɨ α), 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 : Set (α Ɨ α)), 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 w_symm 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 /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α Ɨ α) : closure s = ā‹‚ V ∈ { V | V ∈ š“¤ α ∧ SymmetricRel V }, V ā—‹ s ā—‹ V := by ext ⟨x, y⟩ simp (config := { contextual := true }) only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (š“¤ α) (fun V : Set (α Ɨ α) => 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 : ι → Set (α Ɨ α)} (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 : Set (α Ɨ α) => V ∈ š“¤ α) closure := (š“¤ α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α Ɨ α)} : closure t = ā‹‚ d ∈ š“¤ α, d ā—‹ (t ā—‹ d) := calc closure t = ā‹‚ (V) (_ : V ∈ š“¤ α ∧ SymmetricRel V), V ā—‹ t ā—‹ V := closure_eq_uniformity t _ = ā‹‚ V ∈ š“¤ α, V ā—‹ t ā—‹ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun V₁ Vā‚‚ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ā‹‚ V ∈ š“¤ α, V ā—‹ (t ā—‹ V) := by simp only [compRel_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 s hs => ((š“¤ α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α Ɨ α)} (hs : s ∈ š“¤ α) : interior s ∈ š“¤ α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α Ɨ α)} (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_open_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 : Set (α Ɨ α)} (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 : Set (α Ɨ α)} (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 : Set (α Ɨ α) => 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 : β → Set (α Ɨ α)} (h : (š“¤ α).HasBasis p s) {t : Set (α Ɨ α)} : 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 : Set (α Ɨ α)` of `š“¤ α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `š“¤ α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (š“¤ α) (fun V : Set (α Ɨ α) => V ∈ š“¤ α ∧ IsOpen V ∧ SymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α Ɨ α)} (hs : s ∈ š“¤ α) : ∃ t ∈ š“¤ α, IsOpen t ∧ SymmetricRel 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ā‚ƒ, (compRel_mono huā‚„ huā‚„).trans htā‚‚āŸ© section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| š“¤ α] : ∃ V : ā„• → Set (α Ɨ α), HasAntitoneBasis (š“¤ α) V ∧ āˆ€ n, SymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end theorem Filter.HasBasis.biInter_biUnion_ball {p : ι → Prop} {U : ι → Set (α Ɨ α)} (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)) ⁻¹' idRel = 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, univ_mem]) 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 : ι → Set (α Ɨ α)} (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 : ι → Set (α Ɨ α)} (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 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 := š“Ÿ idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊄; have := discreteTopology_bot α simp [idRel] }⟩ instance : Inf (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 α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ hā‚‚ => UniformSpace.sInf_le ⟨h₁, hā‚‚āŸ© inf := (Ā· āŠ“ Ā·) le_inf := fun a _ _ h₁ hā‚‚ => show a.uniformity ≤ _ from le_inf h₁ hā‚‚ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊄ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | āˆ€ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ 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 α)] = š“Ÿ idRel := 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 [idRel, ← 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, Prod.swap, (Ā· ∘ Ā·)] 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.compRel 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] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : š“¤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (š“¤ β) := rfl @[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 = ⊄ ↔ idRel ∈ š“¤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α Ɨ α)} {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 theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› section UniformContinuousInfi -- Porting note: renamed for dot notation; 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ā‚‚āŸ© -- Porting note: renamed for dot notation 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 -- Porting note: renamed for dot notation 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 α = š“Ÿ idRel) : 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_prod_map, 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 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 /- 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 dsimp [SProd.sprod] rw [uniformity_prod, Filter.prod, comap_inf, comap_comap, comap_comap]; rfl 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 : Set (β Ɨ β)} {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⟩⟩ theorem mem_uniform_prod [t₁ : UniformSpace α] [tā‚‚ : UniformSpace β] {a : Set (α Ɨ α)} {b : Set (β Ɨ β)} (ha : a ∈ š“¤ α) (hb : b ∈ š“¤ β) : { p : (α Ɨ β) Ɨ α Ɨ β | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ š“¤ (α Ɨ β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap ha) (preimage_mem_comap hb) 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.prod_mk {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.prod_mk_left {f : α Ɨ β → γ} (h : UniformContinuous f) (b) : UniformContinuous fun a => f (a, b) := h.comp (uniformContinuous_id.prod_mk uniformContinuous_const) theorem UniformContinuous.prod_mk_right {f : α Ɨ β → γ} (h : UniformContinuous f) (a) : UniformContinuous fun b => f (a, b) := h.comp (uniformContinuous_const.prod_mk uniformContinuous_id) theorem UniformContinuous.prod_map [UniformSpace Ī“] {f : α → γ} {g : β → Ī“} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) := (hf.comp uniformContinuous_fst).prod_mk (hg.comp uniformContinuous_snd) 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.prod_map _ _ _ _ (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.prod_map _ _ _ _ (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.prod_map _ _ _ _ (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.prod_map 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 s 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] @[reducible, deprecated (since := "2024-02-15")] alias Sum.uniformSpace := Sum.instUniformSpace /-- 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 : Set (α Ɨ α)} (ha : a ∈ š“¤ α) {b : Set (β Ɨ β)} (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 /-! ### Compact sets in uniform spaces -/ section Compact open UniformSpace 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.compRel 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⟩⟩ /-- 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 /-- 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 hVsymm] at hxa hxb exact hUAB (mem_iUnionā‚‚_of_mem ha <| hVU <| mem_comp_of_mem_ball hVsymm 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⟩ end Compact /-! ### 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.prod_map' H) (nhds_le_uniformity _), fun H => continuousAt_iff'_left.2 <| H.comp <| tendsto_id.prod_mk_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 : Set (α Ɨ α)} {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 := (htsymm.mk_mem_comm).2 (hu hy).1 have I2 : (g x, g y) ∈ t := (hu hy).2 rw [hfg hx] at I1 exact htr (prod_mk_mem_compRel 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⟩
Topology\UniformSpace\Cauchy.lean
/- Copyright (c) 2017 Johannes Hƶlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hƶlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Topology.UniformSpace.Basic /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity 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 : ι → Set (α Ɨ α)} (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, id, 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 (prod_mk_mem_compRel 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 : Set (α Ɨ α)} (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 [(Ā· ∘ Ā·), f.apply_symm_apply] using H.comp_injective f.symm.injective theorem CauchySeq.subseq_subseq_mem {V : ā„• → Set (α Ɨ α)} (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.prod_map {γ Ī“} [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.prod {γ} [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.prod_mk le_rfl le_rfl) theorem CauchySeq.eventually_eventually [SemilatticeSup β] {u : β → α} (hu : CauchySeq u) {V : Set (α Ɨ α)} (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 : ā„• → Set (α Ɨ α)} (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 <| lt_add_one n).le⟩ theorem Filter.Tendsto.subseq_mem_entourage {V : ā„• → Set (α Ɨ α)} (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 (mapClusterPt_of_comp hf ha) /-- 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 : γ → Set (α Ɨ α)} (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 [exists_prop, true_and_iff, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq, mem_setOf_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≤ _) β] theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α Ɨ α)} (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 : β → Set (α Ɨ α)) (hU : āˆ€ s ∈ š“¤ α, ∃ n, U n āŠ† s) {f : β → α} (hf : āˆ€ ⦃N m n : β⦄, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : CauchySeq f := -- Porting note: changed to semi-implicit arguments cauchySeq_iff_tendsto.2 (by intro s hs rw [mem_map, mem_atTop_sets] cases' hU s hs with N hN refine ⟨(N, N), fun mn hmn => ?_⟩ cases' mn with m n 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 : Set (α Ɨ α)} (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 cases' cauchy_iff.1 hl with hl_ne 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⟩ /-- 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 : Set (α Ɨ α)} (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 <| mem_compRel.2 ⟨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 : ι → Set (α Ɨ α)} (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_symm {s : Set α} (h : āˆ€ V ∈ š“¤ α, SymmetricRel V → ∃ t : Set α, Set.Finite t ∧ s āŠ† ā‹ƒ y ∈ t, ball y V) : TotallyBounded s := UniformSpace.hasBasis_symmetric.totallyBounded_iff.2 fun V hV => by simpa only [ball_eq_of_symmetry hV.2] using h V hV.1 hV.2 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ā‚‚āŸ© @[deprecated (since := "2024-06-01")] alias totallyBounded_subset := TotallyBounded.subset /-- 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 (continuous_id.prod_mk continuous_const)⟩ @[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] simp? [subset_def] at hct says simp only [mem_setOf_eq, subset_def, mem_iUnion, exists_prop] at hct intro x hx; simp exact 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' } āŠ† compRel 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 _ ↦ nonempty_diff.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 isCompact_of_totallyBounded_isClosed [CompleteSpace α] {s : Set α} (ht : TotallyBounded s) (hc : IsClosed s) : IsCompact s := (@isCompact_iff_totallyBounded_isComplete α _ s).2 ⟨ht, hc.isComplete⟩ /-- Every Cauchy sequence over `ā„•` is totally bounded. -/ theorem CauchySeq.totallyBounded_range {s : ā„• → α} (hs : CauchySeq s) : TotallyBounded (range s) := by intro a ha cases' cauchySeq_iff.1 hs a ha with n hn 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⟩] /-! ### 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 : ā„• → Set (α Ɨ α)} (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 } := -- Porting note: changed `∃ _ : s ∈ f, ..` to `s ∈ f ∧ ..` 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 : ā„• → Set (α Ɨ α)) (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 (α) -- Porting note (#11215): 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 `š“¤ α`. We do not register this as an instance, as there is already an instance going in the other direction from second countable spaces to separable spaces, and we want to avoid loops. -/ theorem secondCountable_of_separable [SeparableSpace α] : SecondCountableTopology α := by rcases exists_countable_dense α with ⟨s, hsc, hsd⟩ obtain ⟨t : ā„• → Set (α Ɨ α), hto : āˆ€ i : ā„•, t i ∈ (š“¤ α).sets ∧ IsOpen (t i) ∧ SymmetricRel (t i), 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⟩, (hts k).subset hxy, fun z hz => ?_⟩ exact hUV (ball_subset_of_comp_subset (hk hxy) hUU' (hk hz)) end UniformSpace
Topology\UniformSpace\Compact.lean
/- Copyright (c) 2020 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Yury Kudryashov -/ import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.Equicontinuity import Mathlib.Topology.Separation import Mathlib.Topology.Support /-! # Compact separated uniform spaces ## Main statements * `compactSpace_uniformity`: On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. * `uniformSpace_of_compact_t2`: every compact T2 topological structure is induced by a uniform structure. This uniform structure is described in the previous item. * **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`. ## Implementation notes The construction `uniformSpace_of_compact_t2` is not declared as an instance, as it would badly loop. ## Tags uniform space, uniform continuity, compact space -/ open scoped Classical open Uniformity Topology Filter UniformSpace Set variable {α β γ : Type*} [UniformSpace α] [UniformSpace β] /-! ### Uniformity on compact spaces -/ /-- 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'] /-- The unique uniform structure inducing a given compact topological structure. -/ def uniformSpaceOfCompactT2 [TopologicalSpace γ] [CompactSpace γ] [T2Space γ] : UniformSpace γ where uniformity := š“Ė¢ (diagonal γ) symm := continuous_swap.tendsto_nhdsSet fun x => 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, -- and a fortiori not in Ī”, so x ≠ y have clV : ClusterPt (x, y) (š“Ÿ <| Vᶜ) := hxy.of_inf_right have : (x, y) āˆ‰ interior V := by have : (x, y) ∈ closure Vᶜ := by rwa [mem_closure_iff_clusterPt] rwa [closure_compl] at this have diag_subset : diagonal γ āŠ† interior V := subset_interior_iff_mem_nhdsSet.2 V_in have x_ne_y : x ≠ y := mt (@diag_subset (x, y)) this -- 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 x_ne_y -- 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'⟩ (rfl : z = z') refine IsOpen.mem_nhds ?_ ?_ Ā· apply_rules [IsOpen.union, IsOpen.prod] Ā· simp only [W, mem_union, mem_prod, and_self_iff] exact (_root_.em _).imp_left fun h => union_subset_union VU₁ VUā‚‚ h -- So W ā—‹ W ∈ F by definition of F have : W ā—‹ W ∈ F := @mem_lift' _ _ _ (fun s => s ā—‹ s) _ W_in -- Porting note: was `by simpa only using 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) ≠ āˆ… -- However the construction of W implies (V₁ Ć—Ė¢ Vā‚‚) ∩ (W ā—‹ W) = āˆ…. -- Indeed assume for contradiction there is some (u, v) in the intersection. obtain ⟨⟨u, v⟩, ⟨u_in, v_in⟩, w, huw, hwv⟩ := clusterPt_iff.mp hxy.of_inf_left hV₁₂ this -- So u ∈ V₁, v ∈ Vā‚‚, and there exists some w such that (u, w) ∈ W and (w ,v) ∈ W. -- Because u is in V₁ which is disjoint from Uā‚‚ and Uā‚ƒ, (u, w) ∈ W forces (u, w) ∈ U₁ Ć—Ė¢ U₁. have uw_in : (u, w) ∈ U₁ Ć—Ė¢ U₁ := (huw.resolve_right fun h => h.1 <| Or.inl u_in).resolve_right fun h => hU₁₂.le_bot ⟨VU₁ u_in, h.1⟩ -- Similarly, because v ∈ Vā‚‚, (w ,v) ∈ W forces (w, v) ∈ Uā‚‚ Ć—Ė¢ Uā‚‚. have wv_in : (w, v) ∈ Uā‚‚ Ć—Ė¢ Uā‚‚ := (hwv.resolve_right fun h => h.2 <| Or.inr v_in).resolve_left fun h => hU₁₂.le_bot ⟨h.2, VUā‚‚ v_in⟩ -- Hence w ∈ U₁ ∩ Uā‚‚ which is empty. -- So we have a contradiction exact hU₁₂.le_bot ⟨uw_in.2, wv_in.1⟩ nhds_eq_comap_uniformity x := by simp_rw [nhdsSet_diagonal, comap_iSup, nhds_prod_eq, comap_prod, (Ā· ∘ Ā·), comap_id'] rw [iSup_split_single _ x, comap_const_of_mem fun V => mem_of_mem_nhds] suffices āˆ€ y ≠ x, comap (fun _ : γ ↦ x) (š“ y) āŠ“ š“ y ≤ š“ x by simpa intro y hxy simp [comap_const_of_not_mem (compl_singleton_mem_nhds hxy) (not_not_intro rfl)] /-! ###Ā 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.prod_map h).tendsto_nhdsSet mapsTo_prod_map_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, htsymm.mk_mem_comm.1 (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, htsymm.mk_mem_comm.1 (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' (prod_mk_mem_compRel (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
Topology\UniformSpace\CompactConvergence.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash, Yury Kudryashov -/ import Mathlib.Topology.CompactOpen import Mathlib.Topology.LocallyFinite import Mathlib.Topology.Maps.Proper.Basic 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_compact_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_compact_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(α, β)`. -/ universe u₁ uā‚‚ uā‚ƒ open scoped Uniformity Topology UniformConvergence open UniformSpace Set Filter 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_compact_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, hVsymm.mk_mem_comm.2 <| 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 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_compact_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_compact_tendstoUniformlyOn, nhds_induced, tendsto_comap_iff, UniformOnFun.tendsto_iff_tendstoUniformlyOn] rfl theorem uniformEmbedding_toUniformOnFunIsCompact : UniformEmbedding (toUniformOnFunIsCompact : C(α, β) → α →ᵤ[{K | IsCompact K}] β) where comap_uniformity := rfl inj := DFunLike.coe_injective -- 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 [← uniformEmbedding_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_compact_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_compact_tendstoUniformlyOn] at h obtain ⟨n, hn₁, hnā‚‚āŸ© := exists_compact_mem_nhds x exact ⟨n, hnā‚‚, h n hn₁ V hV⟩ @[deprecated tendsto_iff_tendstoLocallyUniformly (since := "2023-09-03")] theorem tendstoLocallyUniformly_of_tendsto [WeaklyLocallyCompactSpace α] (h : Tendsto F p (š“ f)) : TendstoLocallyUniformly (fun i a => F i a) f p := tendsto_iff_tendstoLocallyUniformly.1 h section Functorial variable {γ Ī“ : Type*} [TopologicalSpace γ] [UniformSpace Ī“] theorem uniformContinuous_comp (g : C(β, Ī“)) (hg : UniformContinuous g) : UniformContinuous (ContinuousMap.comp g : C(α, β) → C(α, Ī“)) := uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.postcomp_uniformContinuous hg |>.comp uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous theorem uniformInducing_comp (g : C(β, Ī“)) (hg : UniformInducing g) : UniformInducing (ContinuousMap.comp g : C(α, β) → C(α, Ī“)) := uniformEmbedding_toUniformOnFunIsCompact.toUniformInducing.of_comp_iff.mp <| UniformOnFun.postcomp_uniformInducing hg |>.comp uniformEmbedding_toUniformOnFunIsCompact.toUniformInducing theorem uniformEmbedding_comp (g : C(β, Ī“)) (hg : UniformEmbedding g) : UniformEmbedding (ContinuousMap.comp g : C(α, β) → C(α, Ī“)) := uniformEmbedding_toUniformOnFunIsCompact.of_comp_iff.mp <| UniformOnFun.postcomp_uniformEmbedding hg |>.comp uniformEmbedding_toUniformOnFunIsCompact theorem uniformContinuous_comp_left (g : C(α, γ)) : UniformContinuous (fun f ↦ f.comp g : C(γ, β) → C(α, β)) := uniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.precomp_uniformContinuous (fun _ hK ↦ hK.image g.continuous) |>.comp uniformEmbedding_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)⟩ /-- 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 rw [tendsto_iff_forall_compact_tendstoUniformlyOn, ← tendstoUniformlyOn_univ] exact ⟨fun h => h univ isCompact_univ, fun h K _hK => h.mono (subset_univ K)⟩ end CompactDomain 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 [compactConvergenceUniformSpace, replaceTopology_eq, inferInstanceAs, inferInstance, 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 [compactConvergenceUniformSpace, replaceTopology_eq, inferInstanceAs, inferInstance, UniformOnFun.uniformSpace_eq_iInf_precomp_of_cover _ _ _ h_image h_preimage h_cover', UniformSpace.comap_iInf, ← UniformSpace.comap_comap] rfl end ContinuousMap
Topology\UniformSpace\CompareReals.lean
/- Copyright (c) 2019 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.UniformSpace.AbsoluteValue import Mathlib.Topology.Instances.Real import Mathlib.Topology.Instances.Rat 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) (uniformInducing := by rw [Rat.uniformSpace_eq] exact Rat.uniformEmbedding_coe_real.toUniformInducing) (dense := Rat.denseEmbedding_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
Topology\UniformSpace\CompleteSeparated.lean
/- Copyright (c) 2019 SĆ©bastien GouĆ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SĆ©bastien GouĆ«zel -/ import Mathlib.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 UniformEmbedding.toClosedEmbedding [UniformSpace α] [UniformSpace β] [CompleteSpace α] [T0Space β] {f : α → β} (hf : UniformEmbedding f) : ClosedEmbedding f := ⟨hf.embedding, hf.toUniformInducing.isComplete_range.isClosed⟩ namespace DenseInducing open Filter variable [TopologicalSpace α] {β : Type*} [TopologicalSpace β] variable {γ : Type*} [UniformSpace γ] [CompleteSpace γ] [T0Space γ] theorem continuous_extend_of_cauchy {e : α → β} {f : α → γ} (de : DenseInducing e) (h : āˆ€ b : β, Cauchy (map f (comap e <| š“ b))) : Continuous (de.extend f) := de.continuous_extend fun b => CompleteSpace.complete (h b) end DenseInducing
Topology\UniformSpace\Completion.lean
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hƶlzl -/ 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 (ie. 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 universe u v w x open scoped Classical open Uniformity Topology Filter /-- 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 : Set (α Ɨ α)) : Set (CauchyFilter α Ɨ CauchyFilter α) := { p | s ∈ p.1.val Ć—Ė¢ p.2.val } theorem monotone_gen : Monotone (gen : Set (α Ɨ α) → _) := 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 : Set (α Ɨ α) => { p : CauchyFilter α Ɨ CauchyFilter α | s ∈ (p.2.val Ć—Ė¢ p.1.val : Filter (α Ɨ α)) } have h₁ : map Prod.swap ((š“¤ α).lift' gen) = (š“¤ α).lift' f := by delta gen simp [map_lift'_eq, monotone_setOf, Filter.monotone_mem, Function.comp, 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 compRel_gen_gen_subset_gen_compRel {s t : Set (α Ɨ α)} : compRel (gen s) (gen t) āŠ† (gen (compRel s t) : Set (CauchyFilter α Ɨ CauchyFilter α)) := 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 => compRel s s) ≤ (š“¤ α).lift' gen := calc (((š“¤ α).lift' gen).lift' fun s => compRel s s) = (š“¤ α).lift' fun s => compRel (gen s) (gen s) := by rw [lift'_lift'_assoc] Ā· exact monotone_gen Ā· exact monotone_id.compRel monotone_id _ ≤ (š“¤ α).lift' fun s => gen <| compRel s s := lift'_mono' fun s _hs => compRel_gen_gen_subset_gen_compRel _ = ((š“¤ α).lift' fun s : Set (α Ɨ α) => compRel s s).lift' gen := by rw [lift'_lift'_assoc] Ā· exact monotone_id.compRel 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 : ι → Set (α Ɨ α)} (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 uniformInducing_pureCauchy : UniformInducing (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, prod_principal_principal] 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 uniformEmbedding_pureCauchy : UniformEmbedding (pureCauchy : α → CauchyFilter α) := { uniformInducing_pureCauchy with inj := fun _a₁ _aā‚‚ h => pure_injective <| Subtype.ext_iff_val.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'ā‚‚ <| prod_mk_mem_compRel (@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 denseInducing_pureCauchy : DenseInducing (pureCauchy : α → CauchyFilter α) := uniformInducing_pureCauchy.denseInducing denseRange_pureCauchy theorem denseEmbedding_pureCauchy : DenseEmbedding (pureCauchy : α → CauchyFilter α) := uniformEmbedding_pureCauchy.denseEmbedding denseRange_pureCauchy theorem nonempty_cauchyFilter_iff : Nonempty (CauchyFilter α) ↔ Nonempty α := by constructor <;> rintro ⟨c⟩ Ā· have := eq_univ_iff_forall.1 denseEmbedding_pureCauchy.toDenseInducing.closure_range c obtain ⟨_, ⟨_, a, _⟩⟩ := mem_closure_iff.1 this _ isOpen_univ trivial exact ⟨a⟩ Ā· exact ⟨pureCauchy c⟩ section -- Porting note: I commented this -- set_option eqn_compiler.zeta true instance : CompleteSpace (CauchyFilter α) := completeSpace_extension uniformInducing_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 s hs => let ⟨t, ht₁, (htā‚‚ : gen t āŠ† s)⟩ := (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 /-- 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 denseInducing_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 uniformInducing_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 uniformInducing_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 /-- The map from a uniform space to its completion. porting note: this was added to create a target for the `@[coe]` attribute. -/ @[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 uniformInducing_coe : UniformInducing ((↑) : α → Completion α) := SeparationQuotient.uniformInducing_mk.comp uniformInducing_pureCauchy theorem comap_coe_eq_uniformity : ((š“¤ _).comap fun p : α Ɨ α => ((p.1 : Completion α), (p.2 : Completion α))) = š“¤ α := (uniformInducing_coe _).1 variable {α} theorem denseRange_coe : DenseRange ((↑) : α → Completion α) := SeparationQuotient.surjective_mk.denseRange.comp denseRange_pureCauchy SeparationQuotient.continuous_mk variable (α) /-- The Haudorff 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 uniformInducing := Completion.uniformInducing_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 uniformEmbedding_coe [T0Space α] : UniformEmbedding ((↑) : α → Completion α) := { comap_uniformity := comap_coe_eq_uniformity α inj := separated_pureCauchy_injective } theorem coe_injective [T0Space α] : Function.Injective ((↑) : α → Completion α) := UniformEmbedding.inj (uniformEmbedding_coe _) variable {α} theorem denseInducing_coe : DenseInducing ((↑) : α → Completion α) := { (uniformInducing_coe α).inducing 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.denseInducing_coe.separableSpace theorem denseEmbedding_coe [T0Space α] : DenseEmbedding ((↑) : α → Completion α) := { denseInducing_coe with inj := separated_pureCauchy_injective } theorem denseRange_coeā‚‚ : DenseRange fun x : α Ɨ β => ((x.1 : Completion α), (x.2 : Completion β)) := denseRange_coe.prod_map denseRange_coe theorem denseRange_coeā‚ƒ : DenseRange fun x : α Ɨ β Ɨ γ => ((x.1 : Completion α), ((x.2.1 : Completion β), (x.2.2 : Completion γ))) := denseRange_coe.prod_map 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 /- porting note: removed `@[simp]` because this lemma doesn't even trigger on itself in Lean 3 or Lean 4 unless the user manually supplies the `hf` argument, so it is useless as a `simp` lemma. -/ theorem extension_coe [T0Space β] (hf : UniformContinuous f) (a : α) : (Completion.extension f) a = f a := cPkg.extend_coe hf a 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 /- porting note: removed `@[simp]` because this lemma doesn't even trigger on itself in Lean 3 or Lean 4 unless the user manually supplies the `hf` argument, so it is useless as a `simp` lemma. -/ 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 intro a -- Porting note: this is not provable by simp [hf, hg, hf.comp hg, map_coe, extension_coe], -- but should be? rw [extension_coe (hf.comp hg), Function.comp_apply, map_coe hg, extension_coe hf, Function.comp_apply] 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 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} /- porting note: removed `@[simp]` because this lemma doesn't even trigger on itself in Lean 3 or Lean 4 unless the user manually supplies the `hf` argument, so it is useless as a `simp` lemma. -/ 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
Topology\UniformSpace\Equicontinuity.lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ 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. ## Notations 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 Z α α' β β' γ š“• : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [tZ : TopologicalSpace Z] [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_prod_map, ← 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 (prod_mk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (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 developping 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 developping 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 developping 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 developping 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 developping 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 developping 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 [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 UniformInducing.equicontinuousAt_iff {F : ι → X → α} {xā‚€ : X} {u : α → β} (hu : UniformInducing u) : EquicontinuousAt F xā‚€ ↔ EquicontinuousAt ((u ∘ Ā·) ∘ F) xā‚€ := by have := (UniformFun.postcomp_uniformInducing (α := ι) hu).inducing 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`. -/ theorem UniformInducing.equicontinuousWithinAt_iff {F : ι → X → α} {S : Set X} {xā‚€ : X} {u : α → β} (hu : UniformInducing u) : EquicontinuousWithinAt F S xā‚€ ↔ EquicontinuousWithinAt ((u ∘ Ā·) ∘ F) S xā‚€ := by have := (UniformFun.postcomp_uniformInducing (α := ι) hu).inducing 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. -/ theorem UniformInducing.equicontinuous_iff {F : ι → X → α} {u : α → β} (hu : UniformInducing 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 UniformInducing.equicontinuousOn_iff {F : ι → X → α} {S : Set X} {u : α → β} (hu : UniformInducing 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 UniformInducing.uniformEquicontinuous_iff {F : ι → β → α} {u : α → γ} (hu : UniformInducing u) : UniformEquicontinuous F ↔ UniformEquicontinuous ((u ∘ Ā·) ∘ F) := by have := UniformFun.postcomp_uniformInducing (α := ι) 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 UniformInducing.uniformEquicontinuousOn_iff {F : ι → β → α} {S : Set β} {u : α → γ} (hu : UniformInducing u) : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((u ∘ Ā·) ∘ F) S := by have := UniformFun.postcomp_uniformInducing (α := ι) 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 whith 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ā‚‚.prod_mk ?_).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 whith 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 whith 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 whith 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 whith 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 <| .prod_mk ?_ ?_).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 whith 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ā‚‚.prod_mk_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).prod_mk_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 hVs).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
Topology\UniformSpace\Equiv.lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hƶlzl, Patrick Massot, SĆ©bastien GouĆ«zel, Zhouhang Zhou, Reid Barton, Anatole Dedecker -/ import Mathlib.Topology.Homeomorph 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 `β` -/ --@[nolint has_nonempty_instance] -- Porting note(#5171): linter not yet ported 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 := fun h => h.toEquiv inv := fun h => h.toEquiv.symm left_inv := fun h => h.left_inv right_inv := fun h => h.right_inv coe_injective' := fun _ _ 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! (config := .asFn) 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. -/ -- @[simps] -- Porting note: removed, `simps?` produced no `simp` lemmas 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 -- @[simp] -- Porting note (#10618): `simp` can prove this `simp only [Equiv.range_eq_univ]` theorem range_coe (h : α ā‰ƒįµ¤ β) : range h = univ := h.surjective.range_eq theorem image_symm (h : α ā‰ƒįµ¤ β) : image h.symm = preimage h := funext h.symm.toEquiv.image_eq_preimage theorem preimage_symm (h : α ā‰ƒįµ¤ β) : preimage h.symm = image h := (funext h.toEquiv.image_eq_preimage).symm -- @[simp] -- Porting note (#10618): `simp` can prove this `simp only [Equiv.image_preimage]` theorem image_preimage (h : α ā‰ƒįµ¤ β) (s : Set β) : h '' (h ⁻¹' s) = s := h.toEquiv.image_preimage s --@[simp] -- Porting note (#10618): `simp` can prove this `simp only [Equiv.preimage_image]` theorem preimage_image (h : α ā‰ƒįµ¤ β) (s : Set α) : h ⁻¹' (h '' s) = s := h.toEquiv.preimage_image s protected theorem uniformInducing (h : α ā‰ƒįµ¤ β) : UniformInducing h := uniformInducing_of_compose h.uniformContinuous h.symm.uniformContinuous <| by simp only [symm_comp_self, uniformInducing_id] theorem comap_eq (h : α ā‰ƒįµ¤ β) : UniformSpace.comap h ‹_› = ‹_› := h.uniformInducing.comap_uniformSpace protected theorem uniformEmbedding (h : α ā‰ƒįµ¤ β) : UniformEmbedding h := ⟨h.uniformInducing, h.injective⟩ theorem completeSpace_iff (h : α ā‰ƒįµ¤ β) : CompleteSpace α ↔ CompleteSpace β := completeSpace_congr h.uniformEmbedding /-- Uniform equiv given a uniform embedding. -/ noncomputable def ofUniformEmbedding (f : α → β) (hf : UniformEmbedding f) : α ā‰ƒįµ¤ Set.range f where uniformContinuous_toFun := hf.toUniformInducing.uniformContinuous.subtype_mk _ uniformContinuous_invFun := by rw [hf.toUniformInducing.uniformContinuous_iff, Equiv.invFun_as_coe, Equiv.self_comp_ofInjective_symm] exact uniformContinuous_subtype_val toEquiv := Equiv.ofInjective f hf.inj /-- 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).prod_mk (hā‚‚.uniformContinuous.comp uniformContinuous_snd) uniformContinuous_invFun := (h₁.symm.uniformContinuous.comp uniformContinuous_fst).prod_mk (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.prod_mk uniformContinuous_fst uniformContinuous_invFun := uniformContinuous_snd.prod_mk 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).prod_mk ((uniformContinuous_snd.comp uniformContinuous_fst).prod_mk uniformContinuous_snd) uniformContinuous_invFun := by -- Porting note: the `rw` was not necessary in Lean 3 rw [Equiv.invFun, Equiv.prodAssoc] exact (uniformContinuous_fst.prod_mk (uniformContinuous_fst.comp uniformContinuous_snd)).prod_mk (uniformContinuous_snd.comp uniformContinuous_snd) toEquiv := Equiv.prodAssoc α β γ /-- `α Ɨ {*}` is uniformly isomorphic to `α`. -/ @[simps! (config := .asFn) apply] def prodPunit : α Ɨ PUnit ā‰ƒįµ¤ α where toEquiv := Equiv.prodPUnit α uniformContinuous_toFun := uniformContinuous_fst uniformContinuous_invFun := uniformContinuous_id.prod_mk 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! apply toEquiv] 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 /-- `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 /-- `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 : UniformInducing (@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! (config := .asFn)] 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! (config := .asFn)] def piFinTwo (α : Fin 2 → Type u) [āˆ€ i, UniformSpace (α i)] : (āˆ€ i, α i) ā‰ƒįµ¤ α 0 Ɨ α 1 where toEquiv := piFinTwoEquiv α uniformContinuous_toFun := (Pi.uniformContinuous_proj _ 0).prod_mk (Pi.uniformContinuous_proj _ 1) uniformContinuous_invFun := uniformContinuous_pi.mpr <| Fin.forall_fin_two.2 ⟨uniformContinuous_fst, uniformContinuous_snd⟩ /-- Uniform isomorphism between `α² = Fin 2 → α` and `α Ɨ α`. -/ -- Porting note: made `α` explicit @[simps! (config := .asFn)] 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 end UniformEquiv /-- A uniform inducing equiv between uniform spaces is a uniform isomorphism. -/ -- @[simps] -- Porting note: removed, `simps?` produced no `simp` lemmas def Equiv.toUniformEquivOfUniformInducing [UniformSpace α] [UniformSpace β] (f : α ā‰ƒ β) (hf : UniformInducing f) : α ā‰ƒįµ¤ β := { f with uniformContinuous_toFun := hf.uniformContinuous uniformContinuous_invFun := hf.uniformContinuous_iff.2 <| by simpa using uniformContinuous_id }
Topology\UniformSpace\Matrix.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Heather Macbeth -/ import Mathlib.Topology.Algebra.UniformGroup import Mathlib.Topology.UniformSpace.Pi import Mathlib.Data.Matrix.Basic /-! # 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 instUniformAddGroup [AddGroup š•œ] [UniformAddGroup š•œ] : UniformAddGroup (Matrix m n š•œ) := inferInstanceAs <| UniformAddGroup (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
Topology\UniformSpace\Pi.lean
/- Copyright (c) 2019 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ 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 -- Porting note: required `Function.comp` to close simp only [UniformContinuous, Pi.uniformity, tendsto_iInf, tendsto_comap_iff, Function.comp] 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] 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 (config := { unfoldPartialApp := true }) [← 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 : @UniformInducing X (ι → X) (⨅ i, u i) (Pi.uniformSpace (U := u)) (const ι) := by simp_rw [uniformInducing_iff, iInf_uniformity, Pi.uniformity, Filter.comap_iInf, Filter.comap_comap, (Ā· ∘ Ā·), 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 _)
Topology\UniformSpace\Separation.lean
/- Copyright (c) 2017 Johannes Hƶlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hƶlzl, Patrick Massot, Yury Kudryashov -/ import Mathlib.Tactic.ApplyFun import Mathlib.Topology.UniformSpace.Basic import Mathlib.Topology.Separation /-! # 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 files 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 geneeralizations to topological spaces. In #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 #10644 to keep it reasonably sized. ## Keywords uniform space, separated space, Hausdorff space, separation quotient -/ open Filter Set Function Topology Uniformity UniformSpace open scoped Classical 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, id] 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 ∈ š“¤ α → SymmetricRel 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.prod_mk_nhds hb).mono_right h.nhds_le_uniformity, fun h ↦ ?_⟩ rw [inseparable_iff_clusterPt_uniformity] exact (ClusterPt.of_le_nhds (ha.prod_mk_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 V₁_symm (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, mem_compRel, 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, 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 /-- 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, map_mk, hf, hg]).symm end SeparationQuotient
Topology\UniformSpace\UniformConvergence.lean
/- Copyright (c) 2020 SĆ©bastien GouĆ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SĆ©bastien GouĆ«zel -/ import Mathlib.Topology.Separation import Mathlib.Topology.UniformSpace.Basic 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`. We also define notions where the convergence is locally uniform, called `TendstoLocallyUniformlyOn F f p s` and `TendstoLocallyUniformly F f p`. The previous theorems all have corresponding versions under locally uniform convergence. 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`. 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 Set universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} [UniformSpace β] variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α} {g : ι → α} /-! ### Different notions of uniform convergence We define uniform convergence and locally 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 {F : ι → α → β} {f : α → β} {p : Filter ι} {s : Set α} : 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 -- Porting note: moved from below 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 /-- 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 {F : ι → α → β} {f : α → β} {p : Filter ι} : 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 converence 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 converence implies pointwise convergence. -/ theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) {x : α} (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 converence 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 -- Porting note: tendstoUniformlyOn_univ moved up 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 {s' : Set α} (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] 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.prod_map 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.prod_map {ι' α' β' : 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] convert h.prod_map h' -- seems to be faster than `exact` here theorem TendstoUniformlyOn.prod_map {ι' α' β' : 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.prod_map h' theorem TendstoUniformly.prod_map {ι' α' β' : 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.prod_map h' theorem TendstoUniformlyOnFilter.prod {ι' β' : 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.prod_map h') u hu).diag_of_prod_right theorem TendstoUniformlyOn.prod {ι' β' : 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.prod p') s := (congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a)) theorem TendstoUniformly.prod {ι' β' : 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.prod_map 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 [mem_prod_principal, 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 γ] {x : α} {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, SProd.sprod, Filter.prod, comap_inf, inf_assoc, comap_principal, inf_principal] refine hF.comp (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.prod_mk (tendsto_diag_uniformity _ _) theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {x : α} {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) {x : α} : TendstoUniformly f (f x) (š“ x) := UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ] /-- 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 Set.mem_of_mem_of_subset (prod_mk_mem_compRel (htsymm hl) hr) htmem /-- 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 [NeBot p] (hF : UniformCauchySeqOnFilter F p p') (hF' : āˆ€į¶  x : α in p', Tendsto (fun n => F n x) p (š“ (f x))) : TendstoUniformlyOnFilter F f p p' := by -- 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 (mem_compRel.mpr ?_) 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 [NeBot p] (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' := by intro u hu have := (hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp)) exact this.mono (by simp) 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 {s' : Set α} (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.prod_map {ι' α' β' : 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.prod_map 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.prod_map 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_iff] 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 `UniformCauchSeqOn.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.prod_mk 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).prod_mk 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 variable [TopologicalSpace α] /-- 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 rw [mem_map, mem_prod_iff_right]; rfl 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 x _ => ⟨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 x => ⟨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⟩ -- Porting note: generalized from `Type` to `Sort` 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 {s₁ sā‚‚ : Set α} (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 [*] -- Porting note: tendstoLocallyUniformlyOn_univ moved up 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, Subtype.coe_mk] 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 [continuous_iff_continuousOn_univ] at cg exact h.comp _ (mapsTo_univ _ _) cg 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 Ā· rintro h K hK1 hK2 exact (tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK2).mp (h.mono hK1) tfae_have 2 → 3 Ā· rintro h x hx 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 Ā· rintro h u hu x hx 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 /-! ### Uniform approximation In this section, 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`. -/ /-- 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₂₁ (prod_mk_mem_compRel hy.1 hy.2) have : (F x, f x) ∈ u₁ := u₂₁ (prod_mk_mem_compRel (refl_mem_uniformity hā‚‚) (hsymm (A.self_of_nhdsWithin hx))) exact C.mono fun y hy => u₁₀ (prod_mk_mem_compRel 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 := continuous_iff_continuousOn_univ.mpr <| continuousOn_of_uniform_approx_of_continuousOn <| by simpa [continuous_iff_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 := continuous_iff_continuousOn_univ.mpr <| 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₁₀ (prod_mk_mem_compRel 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
Topology\UniformSpace\UniformConvergenceTopology.lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.Equiv import Mathlib.Topology.RestrictGenTopology /-! # Topology and uniform structure of uniform convergence This files 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_uniformInducing`: 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 scoped Topology Uniformity open Set Filter 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 {s s' : Set α} {x : α} {p : Filter ι} {g : ι → α} /-- 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: error message suggested to do this /- 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_refl _⟩ /-- 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. -/ protected theorem postcomp_uniformInducing [UniformSpace γ] {f : γ → β} (hf : UniformInducing f) : UniformInducing (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_uniformEmbedding [UniformSpace γ] {f : γ → β} (hf : UniformEmbedding f) : UniformEmbedding (ofFun ∘ (f ∘ Ā·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) where toUniformInducing := UniformFun.postcomp_uniformInducing hf.toUniformInducing inj _ _ H := funext fun _ ↦ hf.inj (congrFun H _) -- Porting note: had to add a type annotation at `((f ∘ Ā·) : ((α → γ) → (α → β)))` /-- 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_uniformInducing (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 ?_ exact (UniformFun.mono (uniformContinuous_iff.mp hf)).trans_eq UniformFun.comap_eq -- Porting note: the original calc proof below gives a deterministic timeout --calc -- š’°(α, γ, _) ≤ š’°(α, γ, ‹UniformSpace β›.comap f) := -- UniformFun.mono (uniformContinuous_iff.mp hf) -- _ = š’°(α, β, _).comap (f ∘ Ā·) := @UniformFun.comap_eq α β γ _ f /-- 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.toUniformEquivOfUniformInducing (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.toUniformEquivOfUniformInducing _ _ š’°(α, āˆ€ i, Ī“ i, Pi.uniformSpace Ī“) (@Pi.uniformSpace ι (fun i => α → Ī“ i) fun i => š’°(α, Ī“ i, _)) (Equiv.piComm _) <| by refine @UniformInducing.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 Filter.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 s' : Set α} {x : α} {p : Filter ι} {g : ι → α} 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 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 left_inv _ := rfl right_inv _ := rfl 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 _ _ /-- 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. -/ protected theorem postcomp_uniformInducing [UniformSpace γ] {f : γ → β} (hf : UniformInducing f) : UniformInducing (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_uniformEmbedding [UniformSpace γ] {f : γ → β} (hf : UniformEmbedding f) : UniformEmbedding (ofFun š”– ∘ (f ∘ Ā·) ∘ toFun š”–) where toUniformInducing := UniformOnFun.postcomp_uniformInducing hf.toUniformInducing inj _ _ H := funext fun _ ↦ hf.inj (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 [← preimage_equiv_eq_image_symm] 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 /-- 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_apply, 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⟩).prod_mk_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 š”–)).toUniformEquivOfUniformInducing <| 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.toUniformEquivOfUniformInducing (α →ᵤ[š”–] ((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 : RestrictGenTopology š”–) : 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 /-- 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 `š”–`. -/ @[deprecated isClosed_setOf_continuous (since := "2024-06-29")] theorem isClosed_setOf_continuous_of_le [t : TopologicalSpace α] (h : t ≤ ⨆ s ∈ š”–, .coinduced (Subtype.val : s → α) inferInstance) : IsClosed {f : α →ᵤ[š”–] β | Continuous (toFun š”– f)} := isClosed_setOf_continuous ⟨fun u hu ↦ h _ <| by simpa only [isOpen_iSup_iff, isOpen_coinduced]⟩ 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.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.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
Topology\UniformSpace\UniformEmbedding.lean
/- Copyright (c) 2017 Johannes Hƶlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hƶlzl, SĆ©bastien GouĆ«zel, Patrick Massot -/ 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 section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} [UniformSpace α] [UniformSpace β] [UniformSpace γ] /-! ### 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 `UniformEmbedding`. -/ @[mk_iff] structure UniformInducing (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 uniformInducing_iff_uniformSpace {f : α → β} : UniformInducing f ↔ ‹UniformSpace β›.comap f = ‹UniformSpace α› := by rw [uniformInducing_iff, UniformSpace.ext_iff, Filter.ext_iff] rfl protected alias ⟨UniformInducing.comap_uniformSpace, _⟩ := uniformInducing_iff_uniformSpace lemma uniformInducing_iff' {f : α → β} : UniformInducing f ↔ UniformContinuous f ∧ comap (Prod.map f f) (š“¤ β) ≤ š“¤ α := by rw [uniformInducing_iff, UniformContinuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; rfl protected lemma Filter.HasBasis.uniformInducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (š“¤ α).HasBasis p s) (h' : (š“¤ β).HasBasis p' s') {f : α → β} : UniformInducing 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 [uniformInducing_iff', h.uniformContinuous_iff h', (h'.comap _).le_basis_iff h, subset_def] theorem UniformInducing.mk' {f : α → β} (h : āˆ€ s, s ∈ š“¤ α ↔ ∃ t ∈ š“¤ β, āˆ€ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : UniformInducing f := ⟨by simp [eq_comm, Filter.ext_iff, subset_def, h]⟩ theorem uniformInducing_id : UniformInducing (@id α) := ⟨by rw [← Prod.map_def, Prod.map_id, comap_id]⟩ theorem UniformInducing.comp {g : β → γ} (hg : UniformInducing g) {f : α → β} (hf : UniformInducing f) : UniformInducing (g ∘ f) := ⟨by rw [← hf.1, ← hg.1, comap_comap]; rfl⟩ theorem UniformInducing.of_comp_iff {g : β → γ} (hg : UniformInducing g) {f : α → β} : UniformInducing (g ∘ f) ↔ UniformInducing f := by refine ⟨fun h ↦ ?_, hg.comp⟩ rw [uniformInducing_iff, ← hg.comap_uniformity, comap_comap, ← h.comap_uniformity, Function.comp, Function.comp] theorem UniformInducing.basis_uniformity {f : α → β} (hf : UniformInducing 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 UniformInducing.cauchy_map_iff {f : α → β} (hf : UniformInducing 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 uniformInducing_of_compose {f : α → β} {g : β → γ} (hf : UniformContinuous f) (hg : UniformContinuous g) (hgf : UniformInducing (g ∘ f)) : UniformInducing 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 UniformInducing.uniformContinuous {f : α → β} (hf : UniformInducing f) : UniformContinuous f := (uniformInducing_iff'.1 hf).1 theorem UniformInducing.uniformContinuous_iff {f : α → β} {g : β → γ} (hg : UniformInducing 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 UniformInducing.uniformInducing_comp_iff {f : α → β} {g : β → γ} (hg : UniformInducing g) : UniformInducing (g ∘ f) ↔ UniformInducing f := by simp only [uniformInducing_iff, ← hg.comap_uniformity, comap_comap, Function.comp_def] theorem UniformInducing.uniformContinuousOn_iff {f : α → β} {g : β → γ} {S : Set α} (hg : UniformInducing 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 UniformInducing.inducing {f : α → β} (h : UniformInducing f) : Inducing f := by obtain rfl := h.comap_uniformSpace exact inducing_induced f theorem UniformInducing.prod {α' : Type*} {β' : Type*} [UniformSpace α'] [UniformSpace β'] {e₁ : α → α'} {eā‚‚ : β → β'} (h₁ : UniformInducing e₁) (hā‚‚ : UniformInducing eā‚‚) : UniformInducing fun p : α Ɨ β => (e₁ p.1, eā‚‚ p.2) := ⟨by simp [(Ā· ∘ Ā·), uniformity_prod, ← h₁.1, ← hā‚‚.1, comap_inf, comap_comap]⟩ theorem UniformInducing.denseInducing {f : α → β} (h : UniformInducing f) (hd : DenseRange f) : DenseInducing f := { dense := hd induced := h.inducing.induced } theorem SeparationQuotient.uniformInducing_mk : UniformInducing (mk : α → SeparationQuotient α) := ⟨comap_mk_uniformity⟩ protected theorem UniformInducing.injective [T0Space α] {f : α → β} (h : UniformInducing f) : Injective f := h.inducing.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 UniformEmbedding (f : α → β) extends UniformInducing f : Prop where /-- A uniform embedding is injective. -/ inj : Function.Injective f theorem uniformEmbedding_iff' {f : α → β} : UniformEmbedding f ↔ Injective f ∧ UniformContinuous f ∧ comap (Prod.map f f) (š“¤ β) ≤ š“¤ α := by rw [uniformEmbedding_iff, and_comm, uniformInducing_iff'] theorem Filter.HasBasis.uniformEmbedding_iff' {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (š“¤ α).HasBasis p s) (h' : (š“¤ β).HasBasis p' s') {f : α → β} : UniformEmbedding 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 [uniformEmbedding_iff, and_comm, h.uniformInducing_iff h'] theorem Filter.HasBasis.uniformEmbedding_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (š“¤ α).HasBasis p s) (h' : (š“¤ β).HasBasis p' s') {f : α → β} : UniformEmbedding 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.uniformEmbedding_iff' h', h.uniformContinuous_iff h'] theorem uniformEmbedding_subtype_val {p : α → Prop} : UniformEmbedding (Subtype.val : Subtype p → α) := { comap_uniformity := rfl inj := Subtype.val_injective } theorem uniformEmbedding_set_inclusion {s t : Set α} (hst : s āŠ† t) : UniformEmbedding (inclusion hst) where comap_uniformity := by rw [uniformity_subtype, uniformity_subtype, comap_comap]; rfl inj := inclusion_injective hst theorem UniformEmbedding.comp {g : β → γ} (hg : UniformEmbedding g) {f : α → β} (hf : UniformEmbedding f) : UniformEmbedding (g ∘ f) := { hg.toUniformInducing.comp hf.toUniformInducing with inj := hg.inj.comp hf.inj } theorem UniformEmbedding.of_comp_iff {g : β → γ} (hg : UniformEmbedding g) {f : α → β} : UniformEmbedding (g ∘ f) ↔ UniformEmbedding f := by simp_rw [uniformEmbedding_iff, hg.toUniformInducing.of_comp_iff, hg.inj.of_comp_iff f] theorem Equiv.uniformEmbedding {α β : Type*} [UniformSpace α] [UniformSpace β] (f : α ā‰ƒ β) (h₁ : UniformContinuous f) (hā‚‚ : UniformContinuous f.symm) : UniformEmbedding f := uniformEmbedding_iff'.2 ⟨f.injective, h₁, by rwa [← Equiv.prodCongr_apply, ← map_equiv_symm]⟩ theorem uniformEmbedding_inl : UniformEmbedding (Sum.inl : α → α āŠ• β) := uniformEmbedding_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 uniformEmbedding_inr : UniformEmbedding (Sum.inr : β → α āŠ• β) := uniformEmbedding_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 `UniformInducing` map `f` is a Tā‚€ space, then `f` is injective, hence it is a `UniformEmbedding`. -/ protected theorem UniformInducing.uniformEmbedding [T0Space α] {f : α → β} (hf : UniformInducing f) : UniformEmbedding f := ⟨hf, hf.inducing.injective⟩ theorem uniformEmbedding_iff_uniformInducing [T0Space α] {f : α → β} : UniformEmbedding f ↔ UniformInducing f := ⟨UniformEmbedding.toUniformInducing, UniformInducing.uniformEmbedding⟩ /-- 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) (š“¤ β) = š“Ÿ idRel := 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 _ ≤ š“Ÿ idRel := 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 uniformEmbedding_of_spaced_out {α} {f : α → β} {s : Set (β Ɨ β)} (hs : s ∈ š“¤ β) (hf : Pairwise fun x y => (f x, f y) āˆ‰ s) : @UniformEmbedding α β ⊄ ‹_› f := by let _ : UniformSpace α := ⊄; have := discreteTopology_bot α exact UniformInducing.uniformEmbedding ⟨comap_uniformity_of_spaced_out hs hf⟩ protected theorem UniformEmbedding.embedding {f : α → β} (h : UniformEmbedding f) : Embedding f := { toInducing := h.toUniformInducing.inducing inj := h.inj } theorem UniformEmbedding.denseEmbedding {f : α → β} (h : UniformEmbedding f) (hd : DenseRange f) : DenseEmbedding f := { h.embedding with dense := hd } theorem closedEmbedding_of_spaced_out {α} [TopologicalSpace α] [DiscreteTopology α] [T0Space β] {f : α → β} {s : Set (β Ɨ β)} (hs : s ∈ š“¤ β) (hf : Pairwise fun x y => (f x, f y) āˆ‰ s) : ClosedEmbedding f := by rcases @DiscreteTopology.eq_bot α _ _ with rfl; let _ : UniformSpace α := ⊄ exact { (uniformEmbedding_of_spaced_out hs hf).embedding with isClosed_range := isClosed_range_of_spaced_out hs hf } theorem closure_image_mem_nhds_of_uniformInducing {s : Set (α Ɨ α)} {e : α → β} (b : β) (he₁ : UniformInducing e) (heā‚‚ : DenseInducing e) (hs : s ∈ š“¤ α) : ∃ a, closure (e '' { a' | (a, a') ∈ s }) ∈ š“ b := by obtain ⟨U, ⟨hU, hUo, hsymm⟩, hs⟩ : ∃ U, (U ∈ š“¤ β ∧ IsOpen U ∧ SymmetricRel 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_subset _ <| 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 <| (mem_ball_symmetry hsymm).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 uniformEmbedding_subtypeEmb (p : α → Prop) {e : α → β} (ue : UniformEmbedding e) (de : DenseEmbedding e) : UniformEmbedding (DenseEmbedding.subtypeEmb p e) := { comap_uniformity := by simp [comap_comap, (Ā· ∘ Ā·), DenseEmbedding.subtypeEmb, uniformity_subtype, ue.comap_uniformity.symm] inj := (de.subtype p).inj } theorem UniformEmbedding.prod {α' : Type*} {β' : Type*} [UniformSpace α'] [UniformSpace β'] {e₁ : α → α'} {eā‚‚ : β → β'} (h₁ : UniformEmbedding e₁) (hā‚‚ : UniformEmbedding eā‚‚) : UniformEmbedding fun p : α Ɨ β => (e₁ p.1, eā‚‚ p.2) := { h₁.toUniformInducing.prod hā‚‚.toUniformInducing with inj := h₁.inj.prodMap hā‚‚.inj } /-- A set is complete iff its image under a uniform inducing map is complete. -/ theorem isComplete_image_iff {m : α → β} {s : Set α} (hm : UniformInducing 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.inducing.nhds_eq_comap] alias ⟨isComplete_of_complete_image, _⟩ := isComplete_image_iff theorem completeSpace_iff_isComplete_range {f : α → β} (hf : UniformInducing f) : CompleteSpace α ↔ IsComplete (range f) := by rw [completeSpace_iff_isComplete_univ, ← isComplete_image_iff hf, image_univ] theorem UniformInducing.isComplete_range [CompleteSpace α] {f : α → β} (hf : UniformInducing f) : IsComplete (range f) := (completeSpace_iff_isComplete_range hf).1 ‹_› theorem SeparationQuotient.completeSpace_iff : CompleteSpace (SeparationQuotient α) ↔ CompleteSpace α := by rw [completeSpace_iff_isComplete_univ, ← range_mk, ← completeSpace_iff_isComplete_range uniformInducing_mk] instance SeparationQuotient.instCompleteSpace [CompleteSpace α] : CompleteSpace (SeparationQuotient α) := completeSpace_iff.2 ‹_› theorem completeSpace_congr {e : α ā‰ƒ β} (he : UniformEmbedding e) : CompleteSpace α ↔ CompleteSpace β := by rw [completeSpace_iff_isComplete_range he.toUniformInducing, e.range_eq_univ, completeSpace_iff_isComplete_univ] theorem completeSpace_coe_iff_isComplete {s : Set α} : CompleteSpace s ↔ IsComplete s := (completeSpace_iff_isComplete_range uniformEmbedding_subtype_val.toUniformInducing).trans <| by rw [Subtype.range_coe] alias ⟨_, IsComplete.completeSpace_coe⟩ := completeSpace_coe_iff_isComplete theorem IsClosed.completeSpace_coe [CompleteSpace α] {s : Set α} (hs : IsClosed s) : CompleteSpace s := hs.isComplete.completeSpace_coe /-- The lift of a complete space to another universe is still complete. -/ instance ULift.completeSpace [h : CompleteSpace α] : CompleteSpace (ULift α) := haveI : UniformEmbedding (@Equiv.ulift α) := ⟨⟨rfl⟩, ULift.down_injective⟩ (completeSpace_congr this).2 h theorem completeSpace_extension {m : β → α} (hm : UniformInducing 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 a b h t s ⟨x, xs, xa⟩ => ⟨x, xs, h xa⟩ have mp₁ : āˆ€ {s}, Monotone (p s) := fun h x ⟨y, ya, yxs⟩ => ⟨y, h ya, yxs⟩ have : f ≤ g := le_iInfā‚‚ fun s hs => le_iInfā‚‚ fun t 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 t ht => let ⟨t', ht', ht_mem⟩ := (mem_lift_sets <| monotone_lift' monotone_const mpā‚€).mp ht let ⟨t'', ht'', ht'_sub⟩ := (mem_lift'_sets mp₁).mp ht_mem let ⟨x, (hx : x ∈ t'')⟩ := 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 ⟨y, xyt', b, b_eq⟩ := hā‚€.nonempty_of_mem this ⟨b, b_eq.symm ā–ø ht'_sub ⟨x, hx, xyt'⟩⟩ have : Cauchy g := āŸØā€¹NeBot g›, fun s hs => let ⟨s₁, hs₁, (comp_s₁ : compRel s₁ s₁ āŠ† s)⟩ := comp_mem_uniformity_sets hs let ⟨sā‚‚, hsā‚‚, (comp_sā‚‚ : compRel sā‚‚ sā‚‚ āŠ† 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 ⟨a, b⟩ ⟨⟨c₁, c₁t, hcā‚āŸ©, ⟨cā‚‚, cā‚‚t, hcā‚‚āŸ©āŸ© => have : (c₁, cā‚‚) ∈ t Ć—Ė¢ t := ⟨c₁t, cā‚‚t⟩ comp_s₁ <| prod_mk_mem_compRel hc₁ <| comp_sā‚‚ <| prod_mk_mem_compRel (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 : UniformInducing 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 : UniformInducing 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 uniformEmbedding_inl.toUniformInducing.isComplete_range.union uniformEmbedding_inr.toUniformInducing.isComplete_range end theorem uniformEmbedding_comap {α : Type*} {β : Type*} {f : α → β} [u : UniformSpace β] (hf : Function.Injective f) : @UniformEmbedding α β (UniformSpace.comap f u) u f := @UniformEmbedding.mk _ _ (UniformSpace.comap f u) _ _ (@UniformInducing.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 Embedding.comapUniformSpace {α β} [TopologicalSpace α] [u : UniformSpace β] (f : α → β) (h : Embedding f) : UniformSpace α := (u.comap f).replaceTopology h.induced theorem Embedding.to_uniformEmbedding {α β} [TopologicalSpace α] [u : UniformSpace β] (f : α → β) (h : Embedding f) : @UniformEmbedding α β (h.comapUniformSpace f) u f := let _ := h.comapUniformSpace f { comap_uniformity := rfl inj := h.inj } section UniformExtension variable {α : Type*} {β : Type*} {γ : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] {e : β → α} (h_e : UniformInducing e) (h_dense : DenseRange e) {f : β → γ} (h_f : UniformContinuous f) local notation "ψ" => DenseInducing.extend (UniformInducing.denseInducing h_e h_dense) f theorem uniformly_extend_exists [CompleteSpace γ] (a : α) : ∃ c, Tendsto f (comap e (š“ a)) (š“ c) := let de := h_e.denseInducing 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 : UniformEmbedding 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 : DenseEmbedding e := he.denseEmbedding hd have de' : DenseEmbedding (DenseEmbedding.subtypeEmb p e) := de.subtype p have ue' : UniformEmbedding (DenseEmbedding.subtypeEmb p e) := uniformEmbedding_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'.toUniformInducing 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, DenseEmbedding.subtypeEmb_coe] using hc refine ⟨c, (tendsto_comap'_iff ?_).1 hc⟩ rw [Subtype.range_coe_subtype] exact ⟨_, hb, by rwa [← de.toInducing.closure_eq_preimage_closure_image, hs.closure_eq]⟩ theorem uniformly_extend_spec [CompleteSpace γ] (a : α) : Tendsto f (comap e (š“ a)) (š“ (ψ a)) := by simpa only [DenseInducing.extend] using tendsto_nhds_limUnder (uniformly_extend_exists h_e ‹_› h_f _) 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.denseInducing 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 γ] theorem uniformly_extend_of_ind (b : β) : ψ (e b) = f b := DenseInducing.extend_eq_at _ h_f.continuous.continuousAt theorem uniformly_extend_unique {g : α → γ} (hg : āˆ€ b, g (e b) = f b) (hc : Continuous g) : ψ = g := DenseInducing.extend_unique _ hg hc end UniformExtension
Topology\VectorBundle\Basic.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sebastien Gouezel, Heather Macbeth, Patrick Massot, Floris van Doorn -/ 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`. ## Tags Vector bundle -/ noncomputable section open scoped Classical open Bundle Set open scoped 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_not_mem 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 (config := .asFn)] 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 /-- 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} 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] 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_not_mem (e : Pretrivialization F (Ļ€ F E)) [e.IsLinear R] {b : B} (hb : b āˆ‰ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb 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) /-- 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 variable {R} theorem coe_symmā‚— (e : Trivialization F (Ļ€ F E)) [e.IsLinear R] (b : B) : ⇑(e.symmā‚— R b) = e.symm b := rfl variable (R) /-- 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 variable {R} 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] 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_not_mem (e : Trivialization F (Ļ€ F E)) [e.IsLinear R] {b : B} (hb : b āˆ‰ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb 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) /-- 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.Prod.mk 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.Prod.mk 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 } variable {R} 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).symm_toLinearEquiv, 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.toPartialHomeomorph.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.toPartialHomeomorph.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 (config := .asFn) 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 dsimp rw [e.coe_linearMapAt b] refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_inducing F E b).continuous fun x => e.mem_source.mpr hb).snd } /-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/ @[simps (config := .asFn) 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_inducing F E b).continuous_iff] exact e.continuousOn_symm.comp_continuous (continuous_const.prod_mk continuous_id) fun x ↦ mk_mem_prod hb (mem_univ x) Ā· refine continuous_zero.congr fun x => (e.symm_apply_of_not_mem 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 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 (config := .asFn) 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_inducing F E b).continuous fun _ => e.mem_source.mpr hb).snd continuous_invFun := (e.symmL R b).continuous } variable {R} 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 [coe_coe, 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.toPartialHomeomorph.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 (config := mfld_cfg)] 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).prod_map continuousOn_id) } -- Porting note (#11215): 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] -- Porting note(#5171): was `nolint has_nonempty_instance` 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] -- Porting note(#5171): was `nolint has_nonempty_instance` def Fiber : B → Type _ := Z.toFiberBundleCore.Fiber instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) := Z.toFiberBundleCore.topologicalSpaceFiber x -- Porting note: fixed: used to assume both `[NormedAddCommGroup F]` and `[AddCommGrp F]` 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 : ι) : PartialHomeomorph (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 -- Porting note: moved from below to fix the next instance @[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).toPartialHomeomorph.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.baseSet i) (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.baseSet i ∩ Z.baseSet j) (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 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.baseSet i) : (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.baseSet i) : (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 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`. -/ -- Porting note(#5171): was @[nolint has_nonempty_instance] 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_inducing : āˆ€ b : B, Inducing (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).prod_map continuousOn_id) rw [e.target_inter_preimage_symm_source_eq e', inter_comm] refine (continuousOn_fst.prod 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 -- Porting note: help `rw` find instances 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 {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
Topology\VectorBundle\Constructions.lean
/- Copyright (c) 2022 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, SĆ©bastien GouĆ«zel, Heather Macbeth, Floris van Doorn -/ import Mathlib.Topology.FiberBundle.Constructions import Mathlib.Topology.VectorBundle.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.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 scoped Classical 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 {š•œ} 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 _⟩] variable (š•œ) 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 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₁.prod eā‚‚).baseSet ∩ (e₁'.prod 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ā‚‚āŸ© show (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 [baseSet_prod, mfld_simps] Ā· mfld_set_tac Ā· mfld_set_tac Ā· rintro b hb rw [ContinuousLinearMap.ext_iff] rintro ⟨v₁, vā‚‚āŸ© show (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] -- Porting note: changed arguments to make `simpNF` happy: merged `hx₁` and `hxā‚‚` into `hx` 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).prod (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 show ((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
Topology\VectorBundle\Hom.lean
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Floris van Doorn -/ 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 `Bundle.ContinuousLinearMap σ F₁ E₁ Fā‚‚ Eā‚‚ x` to be a type synonym for `fun x ↦ 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. ## Main Definitions * `Bundle.ContinuousLinearMap.vectorBundle`: continuous semilinear maps between vector bundles form a vector bundle. -/ noncomputable section open scoped Bundle open Bundle Set ContinuousLinearMap variable {š•œā‚ : Type*} [NontriviallyNormedField š•œā‚] {š•œā‚‚ : Type*} [NontriviallyNormedField š•œā‚‚] (σ : š•œā‚ →+* š•œā‚‚) [iσ : RingHomIsometric σ] 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. For some reason, it helps with instance search. Porting note: after the port is done, we may want to remove this definition. -/ protected abbrev Bundle.ContinuousLinearMap [āˆ€ x, TopologicalSpace (E₁ x)] [āˆ€ x, TopologicalSpace (Eā‚‚ x)] : B → Type _ := fun x => E₁ x →SL[σ] Eā‚‚ x -- Porting note: possibly remove after the port instance Bundle.ContinuousLinearMap.module [āˆ€ x, TopologicalSpace (E₁ x)] [āˆ€ x, TopologicalSpace (Eā‚‚ x)] [āˆ€ x, TopologicalAddGroup (Eā‚‚ x)] [āˆ€ x, ContinuousConstSMul š•œā‚‚ (Eā‚‚ x)] : āˆ€ x, Module š•œā‚‚ (Bundle.ContinuousLinearMap σ E₁ Eā‚‚ x) := fun _ => inferInstance 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 `Bundle.ContinuousLinearMap`. -/ 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)] [ita : āˆ€ x, TopologicalAddGroup (Eā‚‚ x)] [FiberBundle Fā‚‚ Eā‚‚] theorem continuousOn_continuousLinearMapCoordChange [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 -- Porting note: was -- simp only [continuousLinearMapCoordChange, ContinuousLinearEquiv.coe_coe, -- ContinuousLinearEquiv.arrowCongrₛₗ_apply, LinearEquiv.toFun_eq_coe, coe_comp', -- ContinuousLinearEquiv.arrowCongrSL_apply, comp_apply, Function.comp, compSL_apply, -- flip_apply, ContinuousLinearEquiv.symm_symm] -- Now `simp` fails to use `ContinuousLinearMap.comp_apply` in this case dsimp [continuousLinearMapCoordChange] rw [ContinuousLinearEquiv.symm_symm] 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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚)) 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 ⟨x, L⟩ h => ⟨h, Set.mem_univ _⟩ map_target' := fun ⟨x, f⟩ 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_inj_left] 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 (#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, TopologicalAddGroup (Eā‚‚ x)] [āˆ€ x, ContinuousSMul š•œā‚‚ (Eā‚‚ x)] /-- 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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚) 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_inducing := 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 : Inducing fun x => (b, φ x) := inducing_const_prod.mpr φ.toHomeomorph.inducing 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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚)) := (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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚) := (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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚)) := VectorPrebundle.trivializationOfMemPretrivializationAtlas _ ⟨e₁, eā‚‚, he₁, heā‚‚, rfl⟩ instance Bundle.ContinuousLinearMap.memTrivializationAtlas : MemTrivializationAtlas (e₁.continuousLinearMap σ eā‚‚ : Trivialization (F₁ →SL[σ] Fā‚‚) (Ļ€ (F₁ →SL[σ] Fā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚))) 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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚)) : 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_apply (xā‚€ : B) (x : TotalSpace (F₁ →SL[σ] Fā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚)) : 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ā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚) xā‚€).source = Ļ€ (F₁ →SL[σ] Fā‚‚) (Bundle.ContinuousLinearMap σ E₁ Eā‚‚) ⁻¹' ((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
Util\AddRelatedDecl.lean
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Floris van Doorn -/ import Lean.Elab.DeclarationRange import Lean.Elab.Term /-! # `addRelatedDecl` -/ open Lean Meta Elab namespace Mathlib.Tactic /-- A helper function for constructing a related declaration from an existing one. This is currently used by the attributes `reassoc` and `elementwise`, and has been factored out to avoid code duplication. Feel free to add features as needed for other applications. This helper: * calls `addDeclarationRanges`, so jump-to-definition works, * copies the `protected` status of the existing declaration, and * supports copying attributes. Arguments: * `src : Name` is the existing declaration that we are modifying. * `suffix : String` will be appended to `src` to form the name of the new declaration. * `ref : Syntax` is the syntax where the user requested the related declaration. * `construct type value levels : MetaM (Expr Ɨ List Name)` given the type, value, and universe variables of the original declaration, should construct the value of the new declaration, along with the names of its universe variables. * `attrs` is the attributes that should be applied to both the new and the original declaration, e.g. in the usage `@[reassoc (attr := simp)]`. We apply it to both declarations, to have the same behavior as `to_additive`, and to shorten some attribute commands. Note that `@[elementwise (attr := simp), reassoc (attr := simp)]` will try to apply `simp` twice to the current declaration, but that causes no issues. -/ def addRelatedDecl (src : Name) (suffix : String) (ref : Syntax) (attrs? : Option (Syntax.TSepArray `Lean.Parser.Term.attrInstance ",")) (construct : Expr → Expr → List Name → MetaM (Expr Ɨ List Name)) : MetaM Unit := do let tgt := match src with | Name.str n s => Name.mkStr n <| s ++ suffix | x => x addDeclarationRanges tgt { range := ← getDeclarationRange (← getRef) selectionRange := ← getDeclarationRange ref } let info ← getConstInfo src let (newValue, newLevels) ← construct info.type info.value! info.levelParams let newValue ← instantiateMVars newValue let newType ← instantiateMVars (← inferType newValue) match info with | ConstantInfo.thmInfo info => addAndCompile <| .thmDecl { info with levelParams := newLevels, type := newType, name := tgt, value := newValue } | ConstantInfo.defnInfo info => -- Structure fields are created using `def`, even when they are propositional, -- so we don't rely on this to decided whether we should be constructing a `theorem` or a `def`. addAndCompile <| if ← isProp newType then .thmDecl { info with levelParams := newLevels, type := newType, name := tgt, value := newValue } else .defnDecl { info with levelParams := newLevels, type := newType, name := tgt, value := newValue } | _ => throwError "Constant {src} is not a theorem or definition." if isProtected (← getEnv) src then setEnv <| addProtected (← getEnv) tgt let attrs := match attrs? with | some attrs => attrs | none => #[] _ ← Term.TermElabM.run' <| do let attrs ← elabAttrs attrs Term.applyAttributes src attrs Term.applyAttributes tgt attrs
Util\AssertExists.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Scott Morrison -/ import Lean.Elab.Command /-! # User commands for assert the (non-)existence of declaration or instances. These commands are used to enforce the independence of different parts of mathlib. ## TODO Potentially after the port reimplement the mathlib 3 linters to check that declarations asserted about do eventually exist. Implement `assert_instance` and `assert_no_instance` -/ section open Lean Elab Meta Command /-- `assert_exists n` is a user command that asserts that a declaration named `n` exists in the current import scope. Be careful to use names (e.g. `Rat`) rather than notations (e.g. `ā„š`). -/ elab "assert_exists " n:ident : command => do -- this throws an error if the user types something ambiguous or -- something that doesn't exist, otherwise succeeds let _ ← liftCoreM <| realizeGlobalConstNoOverloadWithInfo n /-- `assert_not_exists n` is a user command that asserts that a declaration named `n` *does not exist* in the current import scope. Be careful to use names (e.g. `Rat`) rather than notations (e.g. `ā„š`). It may be used (sparingly!) in mathlib to enforce plans that certain files are independent of each other. If you encounter an error on an `assert_not_exists` command while developing mathlib, it is probably because you have introduced new import dependencies to a file. In this case, you should refactor your work (for example by creating new files rather than adding imports to existing files). You should *not* delete the `assert_not_exists` statement without careful discussion ahead of time. -/ elab "assert_not_exists " n:ident : command => do let decl ← try liftCoreM <| realizeGlobalConstNoOverloadWithInfo n catch _ => return let env ← getEnv let c ← mkConstWithLevelParams decl let msg ← (do let mut some idx := env.getModuleIdxFor? decl | pure m!"Declaration {c} is defined in this file." let mut msg := m!"Declaration {c} is not allowed to be imported by this file.\n\ It is defined in {env.header.moduleNames[idx.toNat]!}," for i in [idx.toNat+1:env.header.moduleData.size] do if env.header.moduleData[i]!.imports.any (Ā·.module == env.header.moduleNames[idx.toNat]!) then idx := i msg := msg ++ m!"\n which is imported by {env.header.moduleNames[i]!}," pure <| msg ++ m!"\n which is imported by this file.") throw <| .error n m!"{msg}\n\n\ These invariants are maintained by `assert_not_exists` statements, \ and exist in order to ensure that \"complicated\" parts of the library \ are not accidentally introduced as dependencies of \"simple\" parts of the library."
Util\AssertNoSorry.lean
/- Copyright (c) 2023 David Renshaw. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Renshaw -/ import Lean.Util.CollectAxioms import Lean.Elab.Command /-! # Defines the `assert_no_sorry` command. Throws an error if the given identifier uses sorryAx. -/ open Lean Meta Elab Command /-- Throws an error if the given identifier uses sorryAx. -/ elab "assert_no_sorry " n:ident : command => do let name ← liftCoreM <| Lean.Elab.realizeGlobalConstNoOverloadWithInfo n let axioms ← Lean.collectAxioms name if axioms.contains ``sorryAx then throwError "{n} contains sorry"
Util\AtomM.lean
/- Copyright (c) 2023 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Lean.Meta.Tactic.Simp.Types /-! # A monad for tracking and deduplicating atoms This monad is used by tactics like `ring` and `abel` to keep uninterpreted atoms in a consistent order, and also to allow unifying atoms up to a specified transparency mode. -/ namespace Mathlib.Tactic open Lean Meta /-- The context (read-only state) of the `AtomM` monad. -/ structure AtomM.Context := /-- The reducibility setting for definitional equality of atoms -/ red : TransparencyMode /-- A simplification to apply to atomic expressions when they are encountered, before interning them in the atom list. -/ evalAtom : Expr → MetaM Simp.Result := fun e ↦ pure { expr := e } deriving Inhabited /-- The mutable state of the `AtomM` monad. -/ structure AtomM.State := /-- The list of atoms-up-to-defeq encountered thus far, used for atom sorting. -/ atoms : Array Expr := #[] /-- The monad that `ring` works in. This is only used for collecting atoms. -/ abbrev AtomM := ReaderT AtomM.Context <| StateRefT AtomM.State MetaM /-- Run a computation in the `AtomM` monad. -/ def AtomM.run {α : Type} (red : TransparencyMode) (m : AtomM α) (evalAtom : Expr → MetaM Simp.Result := fun e ↦ pure { expr := e }) : MetaM α := (m { red, evalAtom }).run' {} /-- Get the index corresponding to an atomic expression, if it has already been encountered, or put it in the list of atoms and return the new index, otherwise. -/ def AtomM.addAtom (e : Expr) : AtomM Nat := do let c ← get for h : i in [:c.atoms.size] do if ← withTransparency (← read).red <| isDefEq e c.atoms[i] then return i modifyGet fun c ↦ (c.atoms.size, { c with atoms := c.atoms.push e })
Util\CompileInductive.lean
/- Copyright (c) 2023 Parth Shastri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parth Shastri, Gabriel Ebner, Mario Carneiro -/ import Lean.Elab.Command import Lean.Compiler.CSimpAttr import Lean.Util.FoldConsts /-! # Define the `compile_inductive%` command. The command `compile_inductive% Foo` adds compiled code for the recursor `Foo.rec`, working around a bug in the core Lean compiler which does not support recursors. For technical reasons, the recursor code generated by `compile_inductive%` unfortunately evaluates the base cases eagerly. That is, `List.rec (unreachable!) (fun _ _ _ => 42) [42]` will panic. Similarly, `compile_def% Foo.foo` adds compiled code for definitions when missing. This can be the case for type class projections, or definitions like `List._sizeOf_1`. -/ namespace Mathlib.Util open Lean Meta private def replaceConst (repl : AssocList Name Name) (e : Expr) : Expr := e.replace fun | .const n us => repl.find? n |>.map (.const Ā· us) | _ => none /-- Returns the names of the recursors for a nested or mutual inductive, using the `all` and `numMotives` arguments from `RecursorVal`. -/ def mkRecNames (all : List Name) (numMotives : Nat) : List Name := if numMotives ≤ all.length then all.map mkRecName else let main := all[0]! all.map mkRecName ++ (List.range (numMotives - all.length)).map (fun i => main.str s!"rec_{i+1}") private def addAndCompile' (decl : Declaration) : CoreM Unit := do try addAndCompile decl catch e => match decl with | .defnDecl val => throwError "while compiling {val.name}: {e.toMessageData}" | .mutualDefnDecl val => throwError "while compiling {val.map (Ā·.name)}: {e.toMessageData}" | _ => unreachable! /-- Compile the definition `dv` by adding a second definition `dvāœ` with the same body, and registering a `csimp`-lemma `dv = dvāœ`. -/ def compileDefn (dv : DefinitionVal) : MetaM Unit := do if ((← getEnv).getModuleIdxFor? dv.name).isNone then -- If it's in the same module then we can safely just call `compileDecl` -- on the original definition return ← compileDecl <| .defnDecl dv let name ← mkFreshUserName dv.name addAndCompile' <| .defnDecl { dv with name } let levels := dv.levelParams.map .param let old := .const dv.name levels let new := .const name levels let name ← mkFreshUserName <| dv.name.str "eq" addDecl <| .thmDecl { name levelParams := dv.levelParams type := ← mkEq old new value := ← mkEqRefl old } Compiler.CSimp.add name .global open Elab /-- Returns true if the given declaration has already been compiled, either directly or via a `@[csimp]` lemma. -/ def isCompiled (env : Environment) (n : Name) : Bool := env.contains (n.str "_cstage2") || (Compiler.CSimp.ext.getState env).map.contains n /-- `compile_def% Foo.foo` adds compiled code for the definition `Foo.foo`. This can be used for type class projections or definitions like `List._sizeOf_1`, for which Lean does not generate compiled code by default (since it is not used 99% of the time). -/ elab tk:"compile_def% " i:ident : command => Command.liftTermElabM do let n ← realizeGlobalConstNoOverloadWithInfo i if isCompiled (← getEnv) n then logWarningAt tk m!"already compiled {n}" return let dv ← withRef i <| getConstInfoDefn n withRef tk <| compileDefn dv private def compileStructOnly (iv : InductiveVal) (rv : RecursorVal) : MetaM Unit := do let value ← forallTelescope rv.type fun xs _ => let val := xs[rv.getFirstMinorIdx]! let val := mkAppN val ⟨.map (xs[rv.getMajorIdx]!.proj iv.name) <| .range rv.rules[0]!.nfields⟩ mkLambdaFVars xs val go value where go value := do let name ← mkFreshUserName rv.name addAndCompile' <| .defnDecl { rv with name value hints := .abbrev safety := .safe } let levels := rv.levelParams.map .param let old := .const rv.name levels let new := .const name levels let name ← mkFreshUserName <| rv.name.str "eq" addDecl <| .mutualDefnDecl [{ name levelParams := rv.levelParams type := ← mkEq old new value := .const name levels hints := .opaque safety := .partial }] Compiler.CSimp.add name .global compileDefn <| ← getConstInfoDefn <| mkRecOnName iv.name /-- Generate compiled code for the recursor for `iv`, excluding the `sizeOf` function. -/ def compileInductiveOnly (iv : InductiveVal) (warn := true) : MetaM Unit := do let rv ← getConstInfoRec <| mkRecName iv.name if ← isProp rv.type then if warn then logWarning m!"not compiling {rv.name}" return if isCompiled (← getEnv) rv.name then if warn then logWarning m!"already compiled {rv.name}" return if !iv.isRec && rv.numMotives == 1 && iv.numCtors == 1 && iv.numIndices == 0 then compileStructOnly iv rv return let levels := rv.levelParams.map .param let rvs ← if rv.numMotives == 1 then pure [rv] else mkRecNames iv.all rv.numMotives |>.mapM getConstInfoRec let rvs ← rvs.mapM fun rv => return (rv, ← mkFreshUserName rv.name) let repl := rvs.foldl (fun l (rv, name) => .cons rv.name name l) .nil addAndCompile' <| .mutualDefnDecl <|← rvs.mapM fun (rv, name) => do pure { rv with name value := ← forallTelescope rv.type fun xs body => do let major := xs[rv.getMajorIdx]! (← whnfD <| ← inferType major).withApp fun head args => do let .const iv levels' := head | throwError "not an inductive" let iv ← getConstInfoInduct iv let rv' ← getConstInfoRec <| mkRecName iv.name if !iv.isRec && rv'.numMotives == 1 && iv.numCtors == 1 && iv.numIndices == 0 then let rule := rv.rules[0]! let val := .beta (replaceConst repl rule.rhs) xs[:rv.getFirstIndexIdx] let val := .beta val ⟨.map (major.proj iv.name) <| .range rule.nfields⟩ mkLambdaFVars xs val else let val := .const (mkCasesOnName iv.name) (.param rv.levelParams.head! :: levels') let val := mkAppN val args[:rv'.numParams] let val := .app val <| ← mkLambdaFVars xs[rv.getFirstIndexIdx:] body let val := mkAppN val xs[rv.getFirstIndexIdx:] let val := mkAppN val <| rv.rules.toArray.map fun rule => .beta (replaceConst repl rule.rhs) xs[:rv.getFirstIndexIdx] mkLambdaFVars xs val hints := .opaque safety := .partial } for (rv, name) in rvs do let old := .const rv.name levels let new := .const name levels let name ← mkFreshUserName <| rv.name.str "eq" addDecl <| .mutualDefnDecl [{ name levelParams := rv.levelParams type := ← mkEq old new value := .const name levels hints := .opaque safety := .partial }] Compiler.CSimp.add name .global for name in iv.all do for aux in [mkRecOnName name, mkBRecOnName name] do if let some (.defnInfo dv) := (← getEnv).find? aux then compileDefn dv mutual /-- Generate compiled code for the recursor for `iv`. -/ partial def compileInductive (iv : InductiveVal) (warn := true) : MetaM Unit := do compileInductiveOnly iv warn compileSizeOf iv /-- Compiles the `sizeOf` auxiliary functions. It also recursively compiles any inductives required to compile the `sizeOf` definition (because `sizeOf` definitions depend on `T.rec`). -/ partial def compileSizeOf (iv : InductiveVal) : MetaM Unit := do let go aux := do if let some (.defnInfo dv) := (← getEnv).find? aux then if !isCompiled (← getEnv) aux then let deps : NameSet := dv.value.foldConsts āˆ… fun c arr => if let .str name "_sizeOf_inst" := c then arr.insert name else arr for i in deps do if let some (.inductInfo iv) := (← getEnv).find? i then compileInductive iv (warn := false) compileDefn dv let rv ← getConstInfoRec <| mkRecName iv.name for name in iv.all do for i in [:rv.numMotives] do go <| name.str s!"_sizeOf_{i+1}" go <| name.str "_sizeOf_inst" end /-- `compile_inductive% Foo` creates compiled code for the recursor `Foo.rec`, so that `Foo.rec` can be used in a definition without having to mark the definition as `noncomputable`. -/ elab tk:"compile_inductive% " i:ident : command => Command.liftTermElabM do let n ← realizeGlobalConstNoOverloadWithInfo i let iv ← withRef i <| getConstInfoInduct n withRef tk <| compileInductive iv end Mathlib.Util -- `Nat.rec` already has a `@[csimp]` lemma in Lean. compile_def% Nat.recOn compile_def% Nat.brecOn compile_inductive% Prod compile_inductive% List compile_inductive% PUnit compile_inductive% PEmpty compile_inductive% Sum compile_inductive% PSum compile_inductive% And compile_inductive% False compile_inductive% Empty compile_inductive% Bool compile_inductive% Sigma -- In addition to the manual implementation below, we also have to override the `Float.val` and -- `Float.mk` functions because these also have no implementation in core lean. -- Because `floatSpec.float` is an opaque type, the identity function is as good an implementation -- as any. private unsafe def Float.valUnsafe : Float → floatSpec.float := unsafeCast private unsafe def Float.mkUnsafe : floatSpec.float → Float := unsafeCast @[implemented_by Float.valUnsafe] private def Float.valImpl (x : Float) : floatSpec.float := x.1 @[implemented_by Float.mkUnsafe] private def Float.mkImpl (x : floatSpec.float) : Float := ⟨x⟩ @[csimp] private theorem Float.val_eq : @Float.val = Float.valImpl := rfl @[csimp] private theorem Float.mk_eq : @Float.mk = Float.mkImpl := rfl -- These types need manual implementations because the default implementation in `compileStruct` -- uses `Expr.proj` which has an invalid IR type. open Lean Meta Elab Mathlib.Util in run_cmd Command.liftTermElabM do for n in [``UInt8, ``UInt16, ``UInt32, ``UInt64, ``USize, ``Float] do let iv ← getConstInfoInduct n let rv ← getConstInfoRec <| mkRecName n let value ← Elab.Term.elabTerm (← `(fun H t => H t.1)) (← inferType (.const rv.name (rv.levelParams.map .param))) compileStructOnly.go iv rv value compileSizeOf iv -- These need special handling because `Lean.Name.sizeOf` and `Lean.instSizeOfName` -- were manually implemented as `noncomputable` compile_inductive% String compile_inductive% Lean.Name compile_def% Lean.Name.sizeOf compile_def% Lean.instSizeOfName
Util\CountHeartbeats.lean
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Lean.Util.Heartbeats import Lean.Meta.Tactic.TryThis /-! Defines a command wrapper that prints the number of heartbeats used in the enclosed command. For example ``` count_heartbeats in theorem foo : 42 = 6 * 7 := rfl ``` will produce an info message containing a number around 51. If this number is above the current `maxHeartbeats`, we also print a `Try this:` suggestion. -/ open Lean Elab Command Meta namespace Mathlib.CountHeartbeats open Tactic /-- Run a tactic, optionally restoring the original state, and report just the number of heartbeats. -/ def runTacForHeartbeats (tac : TSyntax `Lean.Parser.Tactic.tacticSeq) (revert : Bool := true) : TacticM Nat := do let start ← IO.getNumHeartbeats let s ← saveState evalTactic tac if revert then restoreState s return (← IO.getNumHeartbeats) - start /-- Given a `List Nat`, return the minimum, maximum, and standard deviation. -/ def variation (counts : List Nat) : List Nat := let min := counts.minimum?.getD 0 let max := counts.maximum?.getD 0 let toFloat (n : Nat) := n.toUInt64.toFloat let toNat (f : Float) := f.toUInt64.toNat let counts' := counts.map toFloat let μ : Float := counts'.foldl (Ā· + Ā·) 0 / toFloat counts.length let stddev : Float := Float.sqrt <| ((counts'.map fun i => (i - μ)^2).foldl (Ā· + Ā·) 0) / toFloat counts.length [min, max, toNat stddev] /-- Given a `List Nat`, log an info message with the minimum, maximum, and standard deviation. -/ def logVariation {m} [Monad m] [MonadLog m] [AddMessageContext m] [MonadOptions m] (counts : List Nat) : m Unit := do if let [min, max, stddev] := variation counts then -- convert `[min, max, stddev]` to user-facing heartbeats logInfo s!"Min: {min / 1000} Max: {max / 1000} StdDev: {stddev / 10}%" /-- Count the heartbeats used by a tactic, e.g.: `count_heartbeats simp`. -/ elab "count_heartbeats " tac:tacticSeq : tactic => do logInfo s!"{← runTacForHeartbeats tac (revert := false)}" /-- `count_heartbeats! in tac` runs a tactic 10 times, counting the heartbeats used, and logs the range and standard deviation. The tactic `count_heartbeats! n in tac` runs it `n` times instead. -/ elab "count_heartbeats! " n:(num)? "in" ppLine tac:tacticSeq : tactic => do let n := match n with | some j => j.getNat | none => 10 -- First run the tactic `n-1` times, reverting the state. let counts ← (List.range (n - 1)).mapM fun _ => runTacForHeartbeats tac -- Then run once more, keeping the state. let counts := (← runTacForHeartbeats tac (revert := false)) :: counts logVariation counts /-- Count the heartbeats used in the enclosed command. This is most useful for setting sufficient but reasonable limits via `set_option maxHeartbeats` for long running declarations. If you do so, please resist the temptation to set the limit as low as possible. As the `simp` set and other features of the library evolve, other contributors will find that their (likely unrelated) changes have pushed the declaration over the limit. `count_heartbearts in` will automatically suggest a `set_option maxHeartbeats` via "Try this:" using the least number of the form `2^k * 200000` that suffices. Note that that internal heartbeat counter accessible via `IO.getNumHeartbeats` has granularity 1000 times finer that the limits set by `set_option maxHeartbeats`. As this is intended as a user command, we divide by 1000. -/ elab "count_heartbeats " "in" ppLine cmd:command : command => do let start ← IO.getNumHeartbeats try elabCommand (← `(command| set_option maxHeartbeats 0 in $cmd)) finally let finish ← IO.getNumHeartbeats let elapsed := (finish - start) / 1000 let max := (← Command.liftCoreM getMaxHeartbeats) / 1000 if elapsed < max then logInfo m!"Used {elapsed} heartbeats, which is less than the current maximum of {max}." else let mut max' := max while max' < elapsed do max' := 2 * max' logInfo m!"Used {elapsed} heartbeats, which is greater than the current maximum of {max}." let m : TSyntax `num := quote max' Command.liftCoreM <| MetaM.run' do Lean.Meta.Tactic.TryThis.addSuggestion (← getRef) (← set_option hygiene false in `(command| set_option maxHeartbeats $m in $cmd)) /-- Run a command, optionally restoring the original state, and report just the number of heartbeats. -/ def elabForHeartbeats (cmd : TSyntax `command) (revert : Bool := true) : CommandElabM Nat := do let start ← IO.getNumHeartbeats let s ← get elabCommand (← `(command| set_option maxHeartbeats 0 in $cmd)) if revert then set s return (← IO.getNumHeartbeats) - start /-- `count_heartbeats! in cmd` runs a command `10` times, reporting the range in heartbeats, and the standard deviation. The command `count_heartbeats! n in cmd` runs it `n` times instead. Example usage: ``` count_heartbeats! in def f := 37 ``` displays the info message `Min: 7 Max: 8 StdDev: 14%`. -/ elab "count_heartbeats! " n:(num)? "in" ppLine cmd:command : command => do let n := match n with | some j => j.getNat | none => 10 -- First run the command `n-1` times, reverting the state. let counts ← (List.range (n - 1)).mapM fun _ => elabForHeartbeats cmd -- Then run once more, keeping the state. let counts := (← elabForHeartbeats cmd (revert := false)) :: counts logVariation counts
Util\Delaborators.lean
/- Copyright (c) 2023 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Lean.PrettyPrinter.Delaborator.Builtins /-! # Pi type notation Provides the `Ī  x : α, β x` notation as an alternative to Lean 4's built-in `(x : α) → β x` notation. To get all non-`āˆ€` pi types to pretty print this way then do `open scoped PiNotation`. The notation also accepts extended binders, like `Ī  x ∈ s, β x` for `Ī  x, x ∈ s → β x`. -/ namespace PiNotation open Lean.Parser Term open Lean.PrettyPrinter.Delaborator /-- Dependent function type (a "pi type"). The notation `Ī  x : α, β x` can also be written as `(x : α) → β x`. -/ -- A direct copy of forall notation but with `Ī `/`Pi` instead of `āˆ€`/`Forall`. @[term_parser] def piNotation := leading_parser:leadPrec unicodeSymbol "Ī " "PiType" >> many1 (ppSpace >> (binderIdent <|> bracketedBinder)) >> optType >> ", " >> termParser /-- Dependent function type (a "pi type"). The notation `Ī  x ∈ s, β x` is short for `Ī  x, x ∈ s → β x`. -/ -- A copy of forall notation from `Batteries.Util.ExtendedBinder` for pi notation syntax "Ī  " binderIdent binderPred ", " term : term macro_rules | `(Ī  $x:ident $pred:binderPred, $p) => `(Ī  $x:ident, satisfies_binder_pred% $x $pred → $p) | `(Ī  _ $pred:binderPred, $p) => `(Ī  x, satisfies_binder_pred% x $pred → $p) /-- Since pi notation and forall notation are interchangeable, we can parse it by simply using the pre-existing forall parser. -/ @[macro PiNotation.piNotation] def replacePiNotation : Lean.Macro | .node info _ args => return .node info ``Lean.Parser.Term.forall args | _ => Lean.Macro.throwUnsupported /-- Override the Lean 4 pi notation delaborator with one that prints cute binders such as `āˆ€ ε > 0`. -/ @[delab forallE] def delabPi : Delab := whenPPOption Lean.getPPNotation do let stx ← delabForall match stx with | `(āˆ€ ($i:ident : $_), $j:ident ∈ $s → $body) => if i == j then `(āˆ€ $i:ident ∈ $s, $body) else pure stx | `(āˆ€ ($x:ident : $_), $y:ident > $z → $body) => if x == y then `(āˆ€ $x:ident > $z, $body) else pure stx | `(āˆ€ ($x:ident : $_), $y:ident < $z → $body) => if x == y then `(āˆ€ $x:ident < $z, $body) else pure stx | `(āˆ€ ($x:ident : $_), $y:ident ≄ $z → $body) => if x == y then `(āˆ€ $x:ident ≄ $z, $body) else pure stx | `(āˆ€ ($x:ident : $_), $y:ident ≤ $z → $body) => if x == y then `(āˆ€ $x:ident ≤ $z, $body) else pure stx | `(Ī  ($i:ident : $_), $j:ident ∈ $s → $body) => if i == j then `(Ī  $i:ident ∈ $s, $body) else pure stx | `(āˆ€ ($i:ident : $_), $j:ident āˆ‰ $s → $body) => if i == j then `(āˆ€ $i:ident āˆ‰ $s, $body) else pure stx | `(āˆ€ ($i:ident : $_), $j:ident āŠ† $s → $body) => if i == j then `(āˆ€ $i:ident āŠ† $s, $body) else pure stx | `(āˆ€ ($i:ident : $_), $j:ident āŠ‚ $s → $body) => if i == j then `(āˆ€ $i:ident āŠ‚ $s, $body) else pure stx | `(āˆ€ ($i:ident : $_), $j:ident āŠ‡ $s → $body) => if i == j then `(āˆ€ $i:ident āŠ‡ $s, $body) else pure stx | `(āˆ€ ($i:ident : $_), $j:ident ⊃ $s → $body) => if i == j then `(āˆ€ $i:ident ⊃ $s, $body) else pure stx | _ => pure stx /-- Override the Lean 4 pi notation delaborator with one that uses `Ī ` and prints cute binders such as `āˆ€ ε > 0`. Note that this takes advantage of the fact that `(x : α) → p x` notation is never used for propositions, so we can match on this result and rewrite it. -/ @[scoped delab forallE] def delabPi' : Delab := whenPPOption Lean.getPPNotation do let stx ← delabPi -- Replacements let stx : Term ← match stx with | `($group:bracketedBinder → $body) => `(Ī  $group:bracketedBinder, $body) | _ => pure stx -- Merging match stx with | `(Ī  $group, Ī  $groups*, $body) => `(Ī  $group $groups*, $body) | _ => pure stx end PiNotation section existential open Lean Parser Term PrettyPrinter Delaborator /-- Delaborator for existential quantifier, including extended binders. -/ -- TODO: reduce the duplication in this code @[delab app.Exists] def exists_delab : Delab := whenPPOption Lean.getPPNotation do let #[ι, f] := (← SubExpr.getExpr).getAppArgs | failure unless f.isLambda do failure let prop ← Meta.isProp ι let dep := f.bindingBody!.hasLooseBVar 0 let ppTypes ← getPPOption getPPFunBinderTypes let stx ← SubExpr.withAppArg do let dom ← SubExpr.withBindingDomain delab withBindingBodyUnusedName fun x => do let x : TSyntax `ident := .mk x let body ← delab if prop && !dep then `(∃ (_ : $dom), $body) else if prop || ppTypes then `(∃ ($x:ident : $dom), $body) else `(∃ $x:ident, $body) -- Cute binders let stx : Term ← match stx with | `(∃ $i:ident, $j:ident ∈ $s ∧ $body) | `(∃ ($i:ident : $_), $j:ident ∈ $s ∧ $body) => if i == j then `(∃ $i:ident ∈ $s, $body) else pure stx | `(∃ $x:ident, $y:ident > $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident > $z ∧ $body) => if x == y then `(∃ $x:ident > $z, $body) else pure stx | `(∃ $x:ident, $y:ident < $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident < $z ∧ $body) => if x == y then `(∃ $x:ident < $z, $body) else pure stx | `(∃ $x:ident, $y:ident ≄ $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident ≄ $z ∧ $body) => if x == y then `(∃ $x:ident ≄ $z, $body) else pure stx | `(∃ $x:ident, $y:ident ≤ $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident ≤ $z ∧ $body) => if x == y then `(∃ $x:ident ≤ $z, $body) else pure stx | `(∃ $x:ident, $y:ident āˆ‰ $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident āˆ‰ $z ∧ $body) => do if x == y then `(∃ $x:ident āˆ‰ $z, $body) else pure stx | `(∃ $x:ident, $y:ident āŠ† $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident āŠ† $z ∧ $body) => if x == y then `(∃ $x:ident āŠ† $z, $body) else pure stx | `(∃ $x:ident, $y:ident āŠ‚ $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident āŠ‚ $z ∧ $body) => if x == y then `(∃ $x:ident āŠ‚ $z, $body) else pure stx | `(∃ $x:ident, $y:ident āŠ‡ $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident āŠ‡ $z ∧ $body) => if x == y then `(∃ $x:ident āŠ‡ $z, $body) else pure stx | `(∃ $x:ident, $y:ident ⊃ $z ∧ $body) | `(∃ ($x:ident : $_), $y:ident ⊃ $z ∧ $body) => if x == y then `(∃ $x:ident ⊃ $z, $body) else pure stx | _ => pure stx match stx with | `(∃ $group:bracketedExplicitBinders, ∃ $[$groups:bracketedExplicitBinders]*, $body) => `(∃ $group $groups*, $body) | `(∃ $b:binderIdent, ∃ $[$bs:binderIdent]*, $body) => `(∃ $b:binderIdent $[$bs]*, $body) | _ => pure stx end existential open Lean Lean.PrettyPrinter.Delaborator /-- Delaborator for `āˆ‰`. -/ @[delab app.Not] def delab_not_in := whenPPOption Lean.getPPNotation do let #[f] := (← SubExpr.getExpr).getAppArgs | failure guard <| f.isAppOfArity ``Membership.mem 5 let stx₁ ← SubExpr.withAppArg <| SubExpr.withNaryArg 3 delab let stxā‚‚ ← SubExpr.withAppArg <| SubExpr.withNaryArg 4 delab return ← `($stx₁ āˆ‰ $stxā‚‚)
Util\DischargerAsTactic.lean
/- Copyright (c) 2023 Alex J. Best. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best -/ import Lean.Elab.Tactic.Basic import Lean.Meta.Tactic.Simp.Rewrite import Batteries.Tactic.Exact /-! ## Dischargers for `simp` to tactics This file defines a wrapper for `Simp.Discharger`s as regular tactics, that allows them to be used via the tactic frontend of `simp` via `simp (discharger := wrapSimpDischarger my_discharger)`. -/ open Lean Meta Elab Tactic /-- Wrap an simp discharger (a function `Expr → SimpM (Option Expr)`) as a tactic, so that it can be passed as an argument to `simp (discharger := foo)`. This is inverse to `mkDischargeWrapper`. -/ def wrapSimpDischarger (dis : Simp.Discharge) : TacticM Unit := do let eS : Lean.Meta.Simp.State := {} let eC : Lean.Meta.Simp.Context := {} let eM : Lean.Meta.Simp.Methods := {} let (some a, _) ← liftM <| StateRefT'.run (ReaderT.run (ReaderT.run (dis <| ← getMainTarget) eM.toMethodsRef) eC) eS | failure (← getMainGoal).assignIfDefeq a
Util\Export.lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Lean.CoreM import Lean.Util.FoldConsts /-! A rudimentary export format, adapted from <https://github.com/leanprover-community/lean/blob/master/doc/export_format.md> with support for lean 4 kernel primitives. -/ open Lean (HashMap HashSet) namespace Lean namespace Export /- References -/ private opaque MethodsRefPointed : NonemptyType.{0} private def MethodsRef : Type := MethodsRefPointed.type inductive Entry | name (n : Name) | level (n : Level) | expr (n : Expr) | defn (n : Name) deriving Inhabited instance : Coe Name Entry := ⟨Entry.name⟩ instance : Coe Level Entry := ⟨Entry.level⟩ instance : Coe Expr Entry := ⟨Entry.expr⟩ structure Alloc (α) [BEq α] [Hashable α] where map : HashMap α Nat next : Nat deriving Inhabited structure State where names : Alloc Name := ⟨HashMap.empty.insert Name.anonymous 0, 1⟩ levels : Alloc Level := ⟨HashMap.empty.insert levelZero 0, 1⟩ exprs : Alloc Expr defs : HashSet Name stk : Array (Bool Ɨ Entry) deriving Inhabited class OfState (α : Type) [BEq α] [Hashable α] where get : State → Alloc α modify : (Alloc α → Alloc α) → State → State instance : OfState Name where get s := s.names modify f s := { s with names := f s.names } instance : OfState Level where get s := s.levels modify f s := { s with levels := f s.levels } instance : OfState Expr where get s := s.exprs modify f s := { s with exprs := f s.exprs } end Export abbrev ExportM := StateT Export.State CoreM namespace Export def alloc {α} [BEq α] [Hashable α] [OfState α] (a : α) : ExportM Nat := do let n := (OfState.get (α := α) (← get)).next modify <| OfState.modify (α := α) fun s ↦ {map := s.map.insert a n, next := n+1} pure n def exportName (n : Name) : ExportM Nat := do match (← get).names.map.find? n with | some i => pure i | none => match n with | .anonymous => pure 0 | .num p a => let i ← alloc n; IO.println s!"{i} #NI {← exportName p} {a}"; pure i | .str p s => let i ← alloc n; IO.println s!"{i} #NS {← exportName p} {s}"; pure i def exportLevel (L : Level) : ExportM Nat := do match (← get).levels.map.find? L with | some i => pure i | none => match L with | .zero => pure 0 | .succ l => let i ← alloc L; IO.println s!"{i} #US {← exportLevel l}"; pure i | .max l₁ lā‚‚ => let i ← alloc L; IO.println s!"{i} #UM {← exportLevel l₁} {← exportLevel lā‚‚}"; pure i | .imax l₁ lā‚‚ => let i ← alloc L; IO.println s!"{i} #UIM {← exportLevel l₁} {← exportLevel lā‚‚}"; pure i | .param n => let i ← alloc L; IO.println s!"{i} #UP {← exportName n}"; pure i | .mvar _ => unreachable! def biStr : BinderInfo → String | BinderInfo.default => "#BD" | BinderInfo.implicit => "#BI" | BinderInfo.strictImplicit => "#BS" | BinderInfo.instImplicit => "#BC" open ConstantInfo in mutual partial def exportExpr (E : Expr) : ExportM Nat := do match (← get).exprs.map.find? E with | some i => pure i | none => match E with | .bvar n => let i ← alloc E; IO.println s!"{i} #EV {n}"; pure i | .fvar _ => unreachable! | .mvar _ => unreachable! | .sort l => let i ← alloc E; IO.println s!"{i} #ES {← exportLevel l}"; pure i | .const n ls => exportDef n let i ← alloc E let mut s := s!"{i} #EC {← exportName n}" for l in ls do s := s ++ s!" {← exportLevel l}" IO.println s; pure i | .app e₁ eā‚‚ => let i ← alloc E; IO.println s!"{i} #EA {← exportExpr e₁} {← exportExpr eā‚‚}"; pure i | .lam _ e₁ eā‚‚ d => let i ← alloc E IO.println s!"{i} #EL {biStr d} {← exportExpr e₁} {← exportExpr eā‚‚}"; pure i | .forallE _ e₁ eā‚‚ d => let i ← alloc E IO.println s!"{i} #EP {biStr d} {← exportExpr e₁} {← exportExpr eā‚‚}"; pure i | .letE _ e₁ eā‚‚ eā‚ƒ _ => let i ← alloc E IO.println s!"{i} #EP {← exportExpr e₁} {← exportExpr eā‚‚} {← exportExpr eā‚ƒ}"; pure i | .lit (.natVal n) => let i ← alloc E; IO.println s!"{i} #EN {n}"; pure i | .lit (.strVal s) => let i ← alloc E; IO.println s!"{i} #ET {s}"; pure i | .mdata _ _ => unreachable! | .proj n k e => let i ← alloc E; IO.println s!"{i} #EJ {← exportName n} {k} {← exportExpr e}"; pure i partial def exportDef (n : Name) : ExportM Unit := do if (← get).defs.contains n then return let ci ← getConstInfo n for c in ci.value!.getUsedConstants do unless (← get).defs.contains c do exportDef c match ci with | axiomInfo val => axdef "#AX" val.name val.type val.levelParams | defnInfo val => defn "#DEF" val.name val.type val.value val.levelParams | thmInfo val => defn "#THM" val.name val.type val.value val.levelParams | opaqueInfo val => defn "#CN" val.name val.type val.value val.levelParams | quotInfo _ => IO.println "#QUOT" for n in [``Quot, ``Quot.mk, ``Quot.lift, ``Quot.ind] do insert n | inductInfo val => ind val.all | ctorInfo val => ind (← getConstInfoInduct val.induct).all | recInfo val => ind val.all where insert (n : Name) : ExportM Unit := modify fun s ↦ { s with defs := s.defs.insert n } defn (ty : String) (n : Name) (t e : Expr) (ls : List Name) : ExportM Unit := do let mut s := s!"{ty} {← exportName n} {← exportExpr t} {← exportExpr e}" for l in ls do s := s ++ s!" {← exportName l}" IO.println s insert n axdef (ty : String) (n : Name) (t : Expr) (ls : List Name) : ExportM Unit := do let mut s := s!"{ty} {← exportName n} {← exportExpr t}" for l in ls do s := s ++ s!" {← exportName l}" IO.println s insert n ind : List Name → ExportM Unit | [] => unreachable! | is@(i::_) => do let val ← getConstInfoInduct i let mut s := match is.length with | 1 => s!"#IND {val.numParams}" | n => s!"#MUT {val.numParams} {n}" for j in is do insert j; insert (mkRecName j) for j in is do let val ← getConstInfoInduct j s := s ++ s!" {← exportName val.name} {← exportExpr val.type} {val.ctors.length}" for c in val.ctors do insert c s := s ++ s!" {← exportName c} {← exportExpr (← getConstInfoCtor c).type}" for j in is do s ← indbody j s for l in val.levelParams do s := s ++ s!" {← exportName l}" IO.println s indbody (ind : Name) (s : String) : ExportM String := do let val ← getConstInfoInduct ind let mut s := s ++ s!" {← exportName ind} {← exportExpr val.type} {val.ctors.length}" for c in val.ctors do s := s ++ s!" {← exportName c} {← exportExpr (← getConstInfoCtor c).type}" pure s end def runExportM {α : Type} (m : ExportM α) : CoreM α := m.run' default -- #eval runExportM (exportDef `Lean.Expr) end Export end Lean
Util\FormatTable.lean
/- Copyright (c) 2024 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey -/ import Mathlib.Data.String.Defs /-! # Format Table This file provides a simple function for formatting a two-dimensional array of `String`s into a markdown-compliant table. -/ /-- Possible alignment modes for each table item: left-aligned, right-aligned and centered. -/ inductive Alignment where | left | right | center deriving Inhabited, BEq /-- Align a `String` `s` to the left, right, or center within a field of width `width`. -/ def String.justify (s : String) (a : Alignment) (width : Nat) : String := match a with | Alignment.left => s.rightpad width | Alignment.right => s.leftpad width | Alignment.center => let pad := (width - s.length) / 2 String.replicate pad ' ' ++ s ++ String.replicate (width - s.length - pad) ' ' /-- Render a two-dimensional array of `String`s` into a markdown-compliant table. `headers` is a list of column headers, `table` is a 2D array of cell contents, `alignments` describes how to align each table column (default: left-aligned) -/ def formatTable (headers : Array String) (table : Array (Array String)) (alignments : Option (Array Alignment) := none) : String := Id.run do -- If no alignments are provided, default to left alignment for all columns. let alignments := alignments.getD (Array.mkArray headers.size Alignment.left) -- Compute the maximum width of each column. let mut widths := headers.map (·.length) for row in table do for i in [0:widths.size] do widths := widths.set! i (max widths[i]! ((row[i]?.map (·.length)).getD 0)) -- Pad each cell with spaces to match the column width. let paddedHeaders := headers.mapIdx fun i h => h.rightpad widths[i]! let paddedTable := table.map fun row => row.mapIdx fun i cell => cell.justify alignments[i]! widths[i]! -- Construct the lines of the table let headerLine := "| " ++ String.intercalate " | " (paddedHeaders.toList) ++ " |" -- Construct the separator line, with colons to indicate alignment let separatorLine := "| " ++ String.intercalate " | " (((widths.zip alignments).map fun ⟨w, a⟩ => match a with | Alignment.left => ":" ++ String.replicate (w-1) '-' | Alignment.right => String.replicate (w-1) '-' ++ ":" | Alignment.center => ":" ++ String.replicate (w-2) '-' ++ ":" ).toList) ++ " |" let rowLines := paddedTable.map (fun row => "| " ++ String.intercalate " | " (row.toList) ++ " |") -- Return the table return String.intercalate "\n" (headerLine :: separatorLine :: rowLines.toList)
Util\GetAllModules.lean
/- Copyright (c) 2024 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison, Damiano Testa -/ import Lean.Util.Path /-! # Utility functions for finding all `.lean` files or modules in a project. TODO: `getLeanLibs` contains a hard-coded choice of which dependencies should be built and which ones should not. Could this be made more structural and robust, possibly with extra `Lake` support? -/ open Lean System.FilePath /-- `getAllFiles git ml` takes all `.lean` files in the directory `ml` (recursing into sub-directories) and returns the `Array` of `String`s ``` #[file₁, ..., fileā‚™] ``` of all their file names. These are not sorted in general. The input `git` is a `Bool`ean flag: * `true` means that the command uses `git ls-files` to find the relevant files; * `false` means that the command recursively scans all dirs searching for `.lean` files. -/ def getAllFiles (git : Bool) (ml : String) : IO (Array System.FilePath) := do let ml.lean := addExtension ⟨ml⟩ "lean" -- for example, `Mathlib.lean` let allModules : Array System.FilePath ← (do if git then let mlDir := ml.push pathSeparator -- for example, `Mathlib/` let allLean ← IO.Process.run { cmd := "git", args := #["ls-files", mlDir ++ "*.lean"] } return (((allLean.dropRightWhile (Ā· == '\n')).splitOn "\n").map (⟨·⟩)).toArray else do let all ← walkDir ml return all.filter (Ā·.extension == some "lean")) -- Filter out all files which do not exist. -- This check is helpful in case the `git` option is on and a local file has been removed. return ← (allModules.erase ml.lean).filterMapM (fun f ↦ do if ← pathExists f then pure (some f) else pure none ) /-- Like `getAllFiles`, but return an array of *module* names instead, i.e. names of the form `Mathlib.Algebra.Algebra.Basic`. In addition, these names are sorted in a platform-independent order. -/ def getAllModulesSorted (git : Bool) (ml : String) : IO (Array String) := do let files ← getAllFiles git ml let names := ← files.mapM fun f => do return (← moduleNameOfFileName f none).toString return names.qsort (Ā· < Ā·)
Util\IncludeStr.lean
/- Copyright (c) 2021 Henrik Bƶving. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Henrik Bƶving, Xubai Wang -/ import Lean /-! # Defines the `include_str` macro. -/ namespace Mathlib.Util /-- A term macro that includes the content of a file, as a string. -/ elab (name := includeStr) "include_str " str:str : term => do let some str := str.1.isStrLit? | Lean.Elab.throwUnsupportedSyntax let srcPath := System.FilePath.mk (← Lean.MonadLog.getFileName) let some srcDir := srcPath.parent | throwError "{srcPath} not in a valid directory" let path := srcDir / str Lean.mkStrLit <$> IO.FS.readFile path
Util\LongNames.lean
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Lean.Name import Mathlib.Lean.Expr.Basic /-! # Commands `#long_names` and `#long_instances` For finding declarations with excessively long names. -/ open Lean Meta Elab /-- Helper function for `#long_names` and `#long_instances`. -/ def printNameHashMap (h : Std.HashMap Name (Array Name)) : IO Unit := for (m, names) in h.toList do IO.println "----" IO.println <| m.toString ++ ":" for n in names do IO.println n /-- Lists all declarations with a long name, gathered according to the module they are defined in. Use as `#long_names` or `#long_names 100` to specify the length. -/ elab "#long_names " N:(num)? : command => Command.runTermElabM fun _ => do let N := N.map TSyntax.getNat |>.getD 50 let namesByModule ← allNamesByModule (fun n => n.toString.length > N) let namesByModule := namesByModule.filter fun m _ => m.getRoot.toString = "Mathlib" printNameHashMap namesByModule /-- Lists all instances with a long name beginning with `inst`, gathered according to the module they are defined in. This is useful for finding automatically named instances with absurd names. Use as `#long_names` or `#long_names 100` to specify the length. -/ elab "#long_instances " N:(num)?: command => Command.runTermElabM fun _ => do let N := N.map TSyntax.getNat |>.getD 50 let namesByModule ← allNamesByModule (fun n => n.lastComponentAsString.startsWith "inst" && n.lastComponentAsString.length > N) let namesByModule := namesByModule.filter fun m _ => m.getRoot.toString = "Mathlib" printNameHashMap namesByModule
Util\MemoFix.lean
/- Copyright (c) 2022 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, E.W.Ayers -/ import Lean.Data.HashMap /-! # Fixpoint function with memoisation -/ universe u v open ShareCommon private unsafe abbrev ObjectMap := @Lean.HashMap Object Object ⟨Object.ptrEq⟩ ⟨Object.hash⟩ private unsafe def memoFixImplObj (f : (Object → Object) → (Object → Object)) (a : Object) : Object := unsafeBaseIO do let cache : IO.Ref ObjectMap ← ST.mkRef āˆ… let rec fix (a) := unsafeBaseIO do if let some b := (← cache.get).find? a then return b let b := f fix a cache.modify (Ā·.insert a b) pure b pure <| fix a private unsafe def memoFixImpl {α : Type u} {β : Type v} [Nonempty β] : (f : (α → β) → (α → β)) → (a : α) → β := unsafeCast memoFixImplObj /-- Takes the fixpoint of `f` with caching of values that have been seen before. Hashing makes use of a pointer hash. This is useful for implementing tree traversal functions where subtrees may be referenced in multiple places. -/ @[implemented_by memoFixImpl] opaque memoFix {α : Type u} {β : Type v} [Nonempty β] (f : (α → β) → (α → β)) : α → β
Util\Qq.lean
/- Copyright (c) 2023 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Alex J. Best -/ import Qq /-! # Extra `Qq` helpers This file contains some additional functions for using the quote4 library more conveniently. -/ open Lean Elab Tactic Meta namespace Qq /-- Variant of `inferTypeQ` that yields a type in `Type u` rather than `Sort u`. Throws an error if the type is a `Prop` or if it's otherwise not possible to represent the universe as `Type u` (for example due to universe level metavariables). -/ -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Using.20.60QQ.60.20when.20you.20only.20have.20an.20.60Expr.60/near/303349037 def inferTypeQ' (e : Expr) : MetaM ((u : Level) Ɨ (α : Q(Type $u)) Ɨ Q($α)) := do let α ← inferType e let .sort u ← whnf (← inferType α) | throwError "not a type{indentExpr α}" let some v := (← instantiateLevelMVars u).dec | throwError "not a Type{indentExpr e}" pure ⟨v, α, e⟩ theorem QuotedDefEq.rfl {u : Level} {α : Q(Sort u)} {a : Q($α)} : @QuotedDefEq u α a a := ⟨⟩ end Qq
Util\SleepHeartbeats.lean
/- Copyright (c) 2023 Alex J. Best. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best -/ import Lean.Elab.Tactic.Basic /-! # Defines `sleep_heartbeats` tactic. This is useful for testing / debugging long running commands or elaboration in a somewhat precise manner. -/ open Lean Elab /-- A low level command to sleep for at least a given number of heartbeats by running in a loop until the desired number of heartbeats is hit. Warning: this function relies on interpreter / compiler behaviour that is not guaranteed to function in the way that is relied upon here. As such this function is not to be considered reliable, especially after future updates to Lean. This should be used with caution and basically only for demo / testing purposes and not in compiled code without further testing. -/ def sleepAtLeastHeartbeats (n : Nat) : IO Unit := do let i ← IO.getNumHeartbeats while (← IO.getNumHeartbeats) < i + n do continue /-- do nothing for at least n heartbeats -/ elab "sleep_heartbeats " n:num : tactic => do match Syntax.isNatLit? n with | none => throwIllFormedSyntax /- as this is a user facing command we multiply the user input by 1000 to match the maxHeartbeats option -/ | some m => sleepAtLeastHeartbeats (m * 1000) example : 1 = 1 := by sleep_heartbeats 1000 rfl
Util\Superscript.lean
/- Copyright (c) 2023 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Tactic.Lint /-! # A parser for superscripts and subscripts This is intended for use in local notations. Basic usage is: ``` local syntax:arg term:max superscript(term) : term local macro_rules | `($a:term $b:superscript) => `($a ^ $b) ``` where `superscript(term)` indicates that it will parse a superscript, and the `$b:superscript` antiquotation binds the `term` argument of the superscript. Given a notation like this, the expression `2⁶⁓` parses and expands to `2 ^ 64`. The superscript body is considered to be the longest contiguous sequence of superscript tokens and whitespace, so no additional bracketing is required (unless you want to separate two superscripts). However, note that Unicode has a rather restricted character set for superscripts and subscripts (see `Mapping.superscript` and `Mapping.subscript` in this file), so you should not use this parser for complex expressions. -/ universe u namespace Mathlib.Tactic open Lean Parser PrettyPrinter namespace Superscript instance : Hashable Char := ⟨fun c => hash c.1⟩ /-- A bidirectional character mapping. -/ structure Mapping where /-- Map from "special" (e.g. superscript) characters to "normal" characters. -/ toNormal : HashMap Char Char := {} /-- Map from "normal" text to "special" (e.g. superscript) characters. -/ toSpecial : HashMap Char Char := {} deriving Inhabited /-- Constructs a mapping (intended for compile time use). Panics on violated invariants. -/ def mkMapping (s₁ sā‚‚ : String) : Mapping := Id.run do let mut toNormal := {} let mut toSpecial := {} assert! s₁.length == sā‚‚.length for sp in s₁.toSubstring, nm in sā‚‚ do assert! !toNormal.contains sp assert! !toSpecial.contains nm toNormal := toNormal.insert sp nm toSpecial := toSpecial.insert nm sp pure { toNormal, toSpecial } /-- A mapping from superscripts to and from regular text. -/ def Mapping.superscript := mkMapping "ā°Ā¹Ā²Ā³ā“āµā¶ā·āøā¹įµƒįµ‡į¶œįµˆįµ‰į¶ įµŹ°ā±Ź²įµĖ”įµāæįµ’įµ–šž„Ź³Ė¢įµ—įµ˜įµ›Ź·Ė£Źøį¶»į“¬į“®į“°į“±į“³į““į“µį“¶į“·į“øį“¹į“ŗį“¼į“¾źŸ“į“æįµ€įµā±½įµ‚įµįµžįµŸįµ‹į¶æį¶„į¶¹įµ įµ”āŗā»ā¼ā½ā¾" "0123456789abcdefghijklmnopqrstuvwxyzABDEGHIJKLMNOPQRTUVWβγΓεθιυφχ+-=()" /-- A mapping from subscripts to and from regular text. -/ def Mapping.subscript := mkMapping "ā‚€ā‚ā‚‚ā‚ƒā‚„ā‚…ā‚†ā‚‡ā‚ˆā‚‰ā‚ā‚‘ā‚•įµ¢ā±¼ā‚–ā‚—ā‚˜ā‚™ā‚’ā‚šįµ£ā‚›ā‚œįµ¤įµ„ā‚“į“€Ź™į“„į“…į“‡źœ°É¢ŹœÉŖį“Šį“‹ŹŸį“É“į“į“˜źžÆŹ€źœ±į“›į“œį“ į“”Źį“¢įµ¦įµ§įµØįµ©įµŖā‚Šā‚‹ā‚Œā‚ā‚Ž" "0123456789aehijklmnoprstuvxABCDEFGHIJKLMNOPQRSTUVWYZβγρφχ+-=()" /-- Collects runs of text satisfying `p` followed by whitespace. Fails if the first character does not satisfy `p`. If `many` is true, it will parse 1 or more many whitespace-separated runs, otherwise it will parse only 1. If successful, it passes the result to `k` as an array `(a, b, c)` where `a..b` is a token and `b..c` is whitespace. -/ partial def satisfyTokensFn (p : Char → Bool) (errorMsg : String) (many := true) (k : Array (String.Pos Ɨ String.Pos Ɨ String.Pos) → ParserState → ParserState) : ParserFn := fun c s => let start := s.pos let s := takeWhile1Fn p errorMsg c s if s.hasError then s else let stop := s.pos let s := whitespace c s let toks := #[(start, stop, s.pos)] if many then let rec /-- Loop body of `satisfyTokensFn` -/ loop (toks) (s : ParserState) : ParserState := let start := s.pos let s := takeWhileFn p c s if s.pos == start then k toks s else let stop := s.pos let s := whitespace c s let toks := toks.push (start, stop, s.pos) loop toks s loop toks s else k toks s variable {α : Type u} [Inhabited α] (as : Array α) (leftOfPartition : α → Bool) in /-- Given a predicate `leftOfPartition` which is true for indexes `< i` and false for `≄ i`, returns `i`, by binary search. -/ @[specialize] partial def partitionPoint (lo := 0) (hi := as.size) : Nat := if lo < hi then let m := (lo + hi)/2 let a := as.get! m if leftOfPartition a then partitionPoint (m+1) hi else partitionPoint lo m else lo /-- The core function for super/subscript parsing. It consists of three stages: 1. Parse a run of superscripted characters, skipping whitespace and stopping when we hit a non-superscript character. 2. Un-superscript the text and pass the body to the inner parser (usually `term`). 3. Take the resulting `Syntax` object and align all the positions to fit back into the original text (which as a side effect also rewrites all the substrings to be in subscript text). If `many` is false, then whitespace (and comments) are not allowed inside the superscript. -/ partial def scriptFnNoAntiquot (m : Mapping) (errorMsg : String) (p : ParserFn) (many := true) : ParserFn := fun c s => let start := s.pos satisfyTokensFn m.toNormal.contains errorMsg many c s (k := fun toks s => Id.run do let input := c.input let mut newStr := "" -- This consists of a sorted array of `(from, to)` pairs, where indexes `from+i` in `newStr` -- such that `from+i < from'` for the next element of the array, are mapped to `to+i`. let mut aligns := #[((0 : String.Pos), start)] for (start, stopTk, stopWs) in toks do let mut pos := start while pos < stopTk do let c := input.get pos let c' := m.toNormal.find! c newStr := newStr.push c' pos := pos + c if c.utf8Size != c'.utf8Size then aligns := aligns.push (newStr.endPos, pos) newStr := newStr.push ' ' if stopWs.1 - stopTk.1 != 1 then aligns := aligns.push (newStr.endPos, stopWs) let ictx := mkInputContext newStr "<superscript>" let s' := p.run ictx c.toParserModuleContext c.tokens (mkParserState newStr) let rec /-- Applies the alignment mapping to a position. -/ align (pos : String.Pos) := let i := partitionPoint aligns (Ā·.1 ≤ pos) let (a, b) := aligns[i - 1]! pos - a + b let s := { s with pos := align s'.pos, errorMsg := s'.errorMsg } if s.hasError then return s let rec /-- Applies the alignment mapping to a `Substring`. -/ alignSubstr : Substring → Substring | ⟨_newStr, start, stop⟩ => ⟨input, align start, align stop⟩, /-- Applies the alignment mapping to a `SourceInfo`. -/ alignInfo : SourceInfo → SourceInfo | .original leading pos trailing endPos => -- Marking these as original breaks semantic highlighting, -- marking them as canonical breaks the unused variables linter. :( .original (alignSubstr leading) (align pos) (alignSubstr trailing) (align endPos) | .synthetic pos endPos canonical => .synthetic (align pos) (align endPos) canonical | .none => .none, /-- Applies the alignment mapping to a `Syntax`. -/ alignSyntax : Syntax → Syntax | .missing => .missing | .node info kind args => .node (alignInfo info) kind (args.map alignSyntax) | .atom info val => -- We have to preserve the unsubscripted `val` even though it breaks `Syntax.reprint` -- because basic parsers like `num` read the `val` directly .atom (alignInfo info) val | .ident info rawVal val preresolved => .ident (alignInfo info) (alignSubstr rawVal) val preresolved s.pushSyntax (alignSyntax s'.stxStack.back) ) /-- The super/subscript parser. * `m`: the character mapping * `antiquotName`: the name to use for antiquotation bindings `$a:antiquotName`. Note that the actual syntax kind bound will be the body kind (parsed by `p`), not `kind`. * `errorMsg`: shown when the parser does not match * `p`: the inner parser (usually `term`), to be called on the body of the superscript * `many`: if false, whitespace is not allowed inside the superscript * `kind`: the term will be wrapped in a node with this kind -/ def scriptParser (m : Mapping) (antiquotName errorMsg : String) (p : Parser) (many := true) (kind : SyntaxNodeKind := by exact decl_name%) : Parser := let tokens := "$" :: (m.toNormal.toArray.map (Ā·.1.toString) |>.qsort (Ā·<Ā·)).toList let antiquotP := mkAntiquot antiquotName `term (isPseudoKind := true) let p := Superscript.scriptFnNoAntiquot m errorMsg p.fn many node kind { info.firstTokens := .tokens tokens info.collectTokens := (tokens ++ Ā·) fn := withAntiquotFn antiquotP.fn p (isCatAntiquot := true) } /-- Parenthesizer for the script parser. -/ def scriptParser.parenthesizer (k : SyntaxNodeKind) (p : Parenthesizer) : Parenthesizer := Parenthesizer.node.parenthesizer k p /-- Map over the strings in a `Format`. -/ def _root_.Std.Format.mapStringsM {m} [Monad m] (f : Format) (f' : String → m String) : m Format := match f with | .group f b => (.group Ā· b) <$> Std.Format.mapStringsM f f' | .tag t g => .tag t <$> Std.Format.mapStringsM g f' | .append f g => .append <$> Std.Format.mapStringsM f f' <*> Std.Format.mapStringsM g f' | .nest n f => .nest n <$> Std.Format.mapStringsM f f' | .text s => .text <$> f' s | .align _ | .line | .nil => pure f /-- Formatter for the script parser. -/ def scriptParser.formatter (name : String) (m : Mapping) (k : SyntaxNodeKind) (p : Formatter) : Formatter := do let stack ← modifyGet fun s => (s.stack, {s with stack := #[]}) Formatter.node.formatter k p let st ← get let transformed : Except String _ := st.stack.mapM (Ā·.mapStringsM fun s => do let .some s := s.toList.mapM (m.toSpecial.insert ' ' ' ').find? | .error s .ok ⟨s⟩) match transformed with | .error err => -- TODO: this only appears if the caller explicitly calls the pretty-printer Lean.logErrorAt (← get).stxTrav.cur s!"Not a {name}: '{err}'" set { st with stack := stack ++ st.stack } | .ok newStack => set { st with stack := stack ++ newStack } end Superscript /-- The parser `superscript(term)` parses a superscript. Basic usage is: ``` local syntax:arg term:max superscript(term) : term local macro_rules | `($a:term $b:superscript) => `($a ^ $b) ``` Given a notation like this, the expression `2⁶⁓` parses and expands to `2 ^ 64`. Note that because of Unicode limitations, not many characters can actually be typed inside the superscript, so this should not be used for complex expressions. Legal superscript characters: ``` ā°Ā¹Ā²Ā³ā“āµā¶ā·āøā¹įµƒįµ‡į¶œįµˆįµ‰į¶ įµŹ°ā±Ź²įµĖ”įµāæįµ’įµ–šž„Ź³Ė¢įµ—įµ˜įµ›Ź·Ė£Źøį¶»į“¬į“®į“°į“±į“³į““į“µį“¶į“·į“øį“¹į“ŗį“¼į“¾źŸ“į“æįµ€įµā±½įµ‚įµįµžįµŸįµ‹į¶æį¶„į¶¹įµ įµ”āŗā»ā¼ā½ā¾ ``` -/ def superscript (p : Parser) : Parser := Superscript.scriptParser .superscript "superscript" "expected superscript character" p /-- Formatter for the superscript parser. -/ @[combinator_parenthesizer superscript] def superscript.parenthesizer := Superscript.scriptParser.parenthesizer ``superscript /-- Formatter for the superscript parser. -/ @[combinator_formatter superscript] def superscript.formatter := Superscript.scriptParser.formatter "superscript" .superscript ``superscript /-- The parser `subscript(term)` parses a subscript. Basic usage is: ``` local syntax:arg term:max subscript(term) : term local macro_rules | `($a:term $i:subscript) => `($a $i) ``` Given a notation like this, the expression `(a)įµ¢` parses and expands to `a i`. (Either parentheses or a whitespace as in `a įµ¢` is required, because `aįµ¢` is considered as an identifier.) Note that because of Unicode limitations, not many characters can actually be typed inside the subscript, so this should not be used for complex expressions. Legal subscript characters: ``` ā‚€ā‚ā‚‚ā‚ƒā‚„ā‚…ā‚†ā‚‡ā‚ˆā‚‰ā‚ā‚‘ā‚•įµ¢ā±¼ā‚–ā‚—ā‚˜ā‚™ā‚’ā‚šįµ£ā‚›ā‚œįµ¤įµ„ā‚“į“€Ź™į“„į“…į“‡źœ°É¢ŹœÉŖį“Šį“‹ŹŸį“É“į“į“˜źžÆŹ€źœ±į“›į“œį“ į“”Źį“¢įµ¦įµ§įµØįµ©įµŖā‚Šā‚‹ā‚Œā‚ā‚Ž ``` -/ def subscript (p : Parser) : Parser := Superscript.scriptParser .subscript "subscript" "expected subscript character" p /-- Formatter for the subscript parser. -/ @[combinator_parenthesizer subscript] def subscript.parenthesizer := Superscript.scriptParser.parenthesizer ``subscript /-- Formatter for the subscript parser. -/ @[combinator_formatter subscript] def subscript.formatter := Superscript.scriptParser.formatter "subscript" .subscript ``subscript initialize registerAlias `superscript ``superscript superscript registerAliasCore Formatter.formatterAliasesRef `superscript superscript.formatter registerAliasCore Parenthesizer.parenthesizerAliasesRef `superscript superscript.parenthesizer registerAlias `subscript ``subscript subscript registerAliasCore Formatter.formatterAliasesRef `subscript subscript.formatter registerAliasCore Parenthesizer.parenthesizerAliasesRef `subscript subscript.parenthesizer
Util\SynthesizeUsing.lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Lean.Elab.Tactic.Basic import Qq /-! # `SynthesizeUsing` This is a slight simplification of the `solve_aux` tactic in Lean3. -/ open Lean Elab Tactic Meta Qq /-- `synthesizeUsing type tac` synthesizes an element of type `type` using tactic `tac`. The tactic `tac` is allowed to leave goals open, and these remain as metavariables in the returned expression. -/ -- In Lean3 this was called `solve_aux`, -- and took a `TacticM α` and captured the produced value in `α`. -- As this was barely used, we've simplified here. def synthesizeUsing {u : Level} (type : Q(Sort u)) (tac : TacticM Unit) : MetaM (List MVarId Ɨ Q($type)) := do let m ← mkFreshExprMVar type let goals ← (Term.withoutErrToSorry <| run m.mvarId! tac).run' return (goals, ← instantiateMVars m) /-- `synthesizeUsing type tac` synthesizes an element of type `type` using tactic `tac`. The tactic must solve for all goals, in contrast to `synthesizeUsing`. -/ def synthesizeUsing' {u : Level} (type : Q(Sort u)) (tac : TacticM Unit) : MetaM Q($type) := do let (goals, e) ← synthesizeUsing type tac -- Note: doesn't use `tac *> Tactic.done` since that just adds a message -- rather than raising an error. unless goals.isEmpty do throwError m!"synthesizeUsing': unsolved goals\n{goalsToMessageData goals}" return e /-- `synthesizeUsing type tacticSyntax` synthesizes an element of type `type` by evaluating the given tactic syntax. Example: ```lean let (gs, e) ← synthesizeUsingTactic ty (← `(tactic| congr!)) ``` The tactic `tac` is allowed to leave goals open, and these remain as metavariables in the returned expression. -/ def synthesizeUsingTactic {u : Level} (type : Q(Sort u)) (tac : Syntax) : MetaM (List MVarId Ɨ Q($type)) := do synthesizeUsing type (do evalTactic tac) /-- `synthesizeUsing' type tacticSyntax` synthesizes an element of type `type` by evaluating the given tactic syntax. Example: ```lean let e ← synthesizeUsingTactic' ty (← `(tactic| norm_num)) ``` The tactic must solve for all goals, in contrast to `synthesizeUsingTactic`. If you need to insert expressions into a tactic proof, then you might use `synthesizeUsing'` directly, since the `TacticM` monad has access to the `TermElabM` monad. For example, here is a term elaborator that wraps the `simp at ...` tactic: ``` def simpTerm (e : Expr) : MetaM Expr := do let mvar ← Meta.mkFreshTypeMVar let e' ← synthesizeUsing' mvar (do evalTactic (← `(tactic| have h := $(← Term.exprToSyntax e); simp at h; exact h))) -- Note: `simp` does not always insert type hints, so to ensure that we get a term -- with the simplified type (as opposed to one that is merely defeq), we should add -- a type hint ourselves. Meta.mkExpectedTypeHint e' mvar elab "simpTerm% " t:term : term => do simpTerm (← Term.elabTerm t none) ``` -/ def synthesizeUsingTactic' {u : Level} (type : Q(Sort u)) (tac : Syntax) : MetaM Q($type) := do synthesizeUsing' type (do evalTactic tac)
Util\Tactic.lean
/- Copyright (c) 2022 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino, Jannis Limperg -/ import Lean.MetavarContext /-! # Miscellaneous helper functions for tactics. [TODO] Ideally we would find good homes for everything in this file, eventually removing it. -/ namespace Mathlib.Tactic open Lean Meta Tactic variable {m : Type → Type} [Monad m] /-- `modifyMetavarDecl mvarId f` updates the `MetavarDecl` for `mvarId` with `f`. Conditions on `f`: - The target of `f mdecl` is defeq to the target of `mdecl`. - The local context of `f mdecl` must contain the same fvars as the local context of `mdecl`. For each fvar in the local context of `f mdecl`, the type (and value, if any) of the fvar must be defeq to the corresponding fvar in the local context of `mdecl`. If `mvarId` does not refer to a declared metavariable, nothing happens. -/ def modifyMetavarDecl [MonadMCtx m] (mvarId : MVarId) (f : MetavarDecl → MetavarDecl) : m Unit := do modifyMCtx fun mctx ↦ match mctx.decls.find? mvarId with | none => mctx | some mdecl => { mctx with decls := mctx.decls.insert mvarId (f mdecl) } /-- `modifyTarget mvarId f` updates the target of the metavariable `mvarId` with `f`. For any `e`, `f e` must be defeq to `e`. If `mvarId` does not refer to a declared metavariable, nothing happens. -/ def modifyTarget [MonadMCtx m] (mvarId : MVarId) (f : Expr → Expr) : m Unit := modifyMetavarDecl mvarId fun mdecl ↦ { mdecl with type := f mdecl.type } /-- `modifyLocalContext mvarId f` updates the local context of the metavariable `mvarId` with `f`. The new local context must contain the same fvars as the old local context and the types (and values, if any) of the fvars in the new local context must be defeq to their equivalents in the old local context. If `mvarId` does not refer to a declared metavariable, nothing happens. -/ def modifyLocalContext [MonadMCtx m] (mvarId : MVarId) (f : LocalContext → LocalContext) : m Unit := modifyMetavarDecl mvarId fun mdecl ↦ { mdecl with lctx := f mdecl.lctx } /-- `modifyLocalDecl mvarId fvarId f` updates the local decl `fvarId` in the local context of `mvarId` with `f`. `f` must leave the `fvarId` and `index` of the `LocalDecl` unchanged. The type of the new `LocalDecl` must be defeq to the type of the old `LocalDecl` (and the same applies to the value of the `LocalDecl`, if any). If `mvarId` does not refer to a declared metavariable or if `fvarId` does not exist in the local context of `mvarId`, nothing happens. -/ def modifyLocalDecl [MonadMCtx m] (mvarId : MVarId) (fvarId : FVarId) (f : LocalDecl → LocalDecl) : m Unit := modifyLocalContext mvarId fun lctx ↦ lctx.modifyLocalDecl fvarId f
Util\TermBeta.lean
/- Copyright (c) 2023 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Lean.Elab.Term /-! `beta%` term elaborator The `beta% f x1 ... xn` term elaborator elaborates the expression `f x1 ... xn` and then does one level of beta reduction. That is, if `f` is a lambda then it will substitute its arguments. The purpose of this is to support substitutions in notations such as `āˆ€ i, beta% p i` so that `p i` gets beta reduced when `p` is a lambda. -/ namespace Mathlib.Util.TermBeta open Lean Elab Term /-- `beta% t` elaborates `t` and then if the result is in the form `f x1 ... xn` where `f` is a (nested) lambda expression, it will substitute all of its arguments by beta reduction. This does not recursively do beta reduction, nor will it do beta reduction of subexpressions. In particular, `t` is elaborated, its metavariables are instantiated, and then `Lean.Expr.headBeta` is applied. -/ syntax (name := betaStx) "beta% " term : term @[term_elab betaStx, inherit_doc betaStx] def elabBeta : TermElab := fun stx expectedType? => match stx with | `(beta% $t) => do let e ← elabTerm t expectedType? return (← instantiateMVars e).headBeta | _ => throwUnsupportedSyntax
Util\Time.lean
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Lean /-! # Defines `#time` command. Time the elaboration of a command, and print the result (in milliseconds). -/ section open Lean Elab Command syntax (name := timeCmd) "#time " command : command /-- Time the elaboration of a command, and print the result (in milliseconds). Example usage: ``` set_option maxRecDepth 100000 in #time example : (List.range 500).length = 500 := rfl ``` -/ @[command_elab timeCmd] def timeCmdElab : CommandElab | `(#time%$tk $stx:command) => do let start ← IO.monoMsNow elabCommand stx logInfoAt tk m!"time: {(← IO.monoMsNow) - start}ms" | _ => throwUnsupportedSyntax end
Util\WhatsNew.lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ import Lean /-! Defines a command wrapper that prints the changes the command makes to the environment. ``` whatsnew in theorem foo : 42 = 6 * 7 := rfl ``` -/ open Lean Elab Command namespace Mathlib.WhatsNew private def throwUnknownId (id : Name) : CommandElabM Unit := throwError "unknown identifier '{mkConst id}'" private def levelParamsToMessageData (levelParams : List Name) : MessageData := match levelParams with | [] => "" | u::us => Id.run <| do let mut m := m!".\{{u}" for u in us do m := m ++ ", " ++ toMessageData u return m ++ "}" private def mkHeader (kind : String) (id : Name) (levelParams : List Name) (type : Expr) (safety : DefinitionSafety) : CoreM MessageData := do let m : MessageData := match safety with | DefinitionSafety.unsafe => "unsafe " | DefinitionSafety.partial => "partial " | DefinitionSafety.safe => "" let m := if isProtected (← getEnv) id then m ++ "protected " else m let (m, id) := match privateToUserName? id with | some id => (m ++ "private ", id) | none => (m, id) let m := m ++ kind ++ " " ++ id ++ levelParamsToMessageData levelParams ++ " : " ++ type pure m private def mkHeader' (kind : String) (id : Name) (levelParams : List Name) (type : Expr) (isUnsafe : Bool) : CoreM MessageData := mkHeader kind id levelParams type (if isUnsafe then DefinitionSafety.unsafe else DefinitionSafety.safe) private def printDefLike (kind : String) (id : Name) (levelParams : List Name) (type : Expr) (value : Expr) (safety := DefinitionSafety.safe) : CoreM MessageData := return (← mkHeader kind id levelParams type safety) ++ " :=" ++ Format.line ++ value private def printInduct (id : Name) (levelParams : List Name) (_numParams : Nat) (_numIndices : Nat) (type : Expr) (ctors : List Name) (isUnsafe : Bool) : CoreM MessageData := do let mut m ← mkHeader' "inductive" id levelParams type isUnsafe m := m ++ Format.line ++ "constructors:" for ctor in ctors do let cinfo ← getConstInfo ctor m := m ++ Format.line ++ ctor ++ " : " ++ cinfo.type pure m private def printIdCore (id : Name) : ConstantInfo → CoreM MessageData | ConstantInfo.axiomInfo { levelParams := us, type := t, isUnsafe := u, .. } => mkHeader' "axiom" id us t u | ConstantInfo.defnInfo { levelParams := us, type := t, value := v, safety := s, .. } => printDefLike "def" id us t v s | ConstantInfo.thmInfo { levelParams := us, type := t, value := v, .. } => printDefLike "theorem" id us t v | ConstantInfo.opaqueInfo { levelParams := us, type := t, isUnsafe := u, .. } => mkHeader' "constant" id us t u | ConstantInfo.quotInfo { levelParams := us, type := t, .. } => mkHeader' "Quotient primitive" id us t false | ConstantInfo.ctorInfo { levelParams := us, type := t, isUnsafe := u, .. } => mkHeader' "constructor" id us t u | ConstantInfo.recInfo { levelParams := us, type := t, isUnsafe := u, .. } => mkHeader' "recursor" id us t u | ConstantInfo.inductInfo { levelParams := us, numParams, numIndices, type := t, ctors, isUnsafe := u, .. } => printInduct id us numParams numIndices t ctors u def diffExtension (old new : Environment) (ext : PersistentEnvExtension EnvExtensionEntry EnvExtensionEntry EnvExtensionState) : CoreM (Option MessageData) := unsafe do let oldSt := ext.toEnvExtension.getState old let newSt := ext.toEnvExtension.getState new if ptrAddrUnsafe oldSt == ptrAddrUnsafe newSt then return none let oldEntries := ext.exportEntriesFn oldSt.state let newEntries := ext.exportEntriesFn newSt.state pure m!"-- {ext.name} extension: {(newEntries.size - oldEntries.size : Int)} new entries" def whatsNew (old new : Environment) : CoreM MessageData := do let mut diffs := #[] for (c, i) in new.constants.mapā‚‚.toList do unless old.constants.mapā‚‚.contains c do diffs := diffs.push (← printIdCore c i) for ext in ← persistentEnvExtensionsRef.get do if let some diff := ← diffExtension old new ext then diffs := diffs.push diff if diffs.isEmpty then return "no new constants" pure <| MessageData.joinSep diffs.toList "\n\n" /-- `whatsnew in $command` executes the command and then prints the declarations that were added to the environment. -/ elab "whatsnew " "in" ppLine cmd:command : command => do let oldEnv ← getEnv try elabCommand cmd finally let newEnv ← getEnv logInfo (← liftCoreM <| whatsNew oldEnv newEnv)
Util\WithWeakNamespace.lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Daniel Selsam, Gabriel Ebner -/ import Lean /-! # Defines `with_weak_namespace` command. Changes the current namespace without causing scoped things to go out of scope. -/ namespace Lean.Elab.Command /-- Adds the name to the namespace, `_root_`-aware. ``` resolveNamespace `A `B.b == `A.B.b resolveNamespace `A `_root_.B.c == `B.c ``` -/ def resolveNamespace (ns : Name) : Name → Name | `_root_ => Name.anonymous | Name.str n s .. => Name.mkStr (resolveNamespace ns n) s | Name.num n i .. => Name.mkNum (resolveNamespace ns n) i | Name.anonymous => ns /-- Changes the current namespace without causing scoped things to go out of scope -/ def withWeakNamespace {α : Type} (ns : Name) (m : CommandElabM α) : CommandElabM α := do let old ← getCurrNamespace let ns := resolveNamespace old ns modify fun s ↦ { s with env := s.env.registerNamespace ns } modifyScope ({ Ā· with currNamespace := ns }) try m finally modifyScope ({ Ā· with currNamespace := old }) /-- Changes the current namespace without causing scoped things to go out of scope -/ elab "with_weak_namespace " ns:ident cmd:command : command => withWeakNamespace ns.getId (elabCommand cmd)